Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GroupId related calls to Himbaechel API #1399

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion common/kernel/base_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,8 @@ template <typename R> struct BaseArch : ArchAPI<R>
}

// Routing methods
virtual void expandBoundingBox(BoundingBox &bb) const override {
virtual void expandBoundingBox(BoundingBox &bb) const override
{
bb.x0 = std::max(bb.x0 - 1, 0);
bb.y0 = std::max(bb.y0 - 1, 0);
bb.x1 = std::min(bb.x1 + 1, this->getGridDimX());
Expand Down
39 changes: 33 additions & 6 deletions himbaechel/arch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

NEXTPNR_NAMESPACE_BEGIN

static constexpr int database_version = 5;
static constexpr int database_version = 6;

static const ChipInfoPOD *get_chip_info(const RelPtr<ChipInfoPOD> *ptr) { return ptr->get(); }

Expand Down Expand Up @@ -307,6 +307,23 @@ IdStringList Arch::getPipName(PipId pip) const

IdString Arch::getPipType(PipId pip) const { return IdString(); }

GroupId Arch::getGroupByName(IdStringList name) const
{
NPNR_ASSERT(name.size() == 2);
int tile = tile_name2idx.at(name[0]);
const auto &tdata = chip_tile_info(chip_info, tile);
for (int group = 0; group < tdata.groups.ssize(); group++) {
if (IdString(tdata.groups[group].name) == name[1])
return GroupId(tile, group);
}
return GroupId();
}

IdStringList Arch::getGroupName(GroupId group) const
{
return IdStringList::concat(tile_name.at(group.tile), IdString(chip_group_info(chip_info, group).name));
}

std::string Arch::getChipName() const { return chip_info->name.get(); }

IdString Arch::archArgsToId(ArchArgs args) const
Expand Down Expand Up @@ -504,15 +521,21 @@ IdString Arch::get_tile_type(int tile) const
std::vector<GraphicElement> Arch::getDecalGraphics(DecalId decal) const
{
std::vector<GraphicElement> ret;
if (decal.type == DecalId::TYPE_BEL) {
if (decal.type == DecalId::TYPE_GROUP) {
GroupId group(decal.tile, decal.index);
Loc loc;
tile_xy(chip_info, decal.tile, loc.x, loc.y);
uarch->drawGroup(ret, getGroupType(group), loc);
} else if (decal.type == DecalId::TYPE_BEL) {
BelId bel(decal.tile, decal.index);
GraphicElement::style_t style = decal.active ? GraphicElement::STYLE_ACTIVE : GraphicElement::STYLE_INACTIVE;
uarch->drawBel(ret, style, getBelType(bel), getBelLocation(bel));
} else if (decal.type == DecalId::TYPE_WIRE) {
WireId w(decal.tile, decal.index);
for (WireId wire: get_tile_wire_range(w)) {
for (WireId wire : get_tile_wire_range(w)) {
auto wire_type = getWireType(wire);
GraphicElement::style_t style = decal.active ? GraphicElement::STYLE_ACTIVE : GraphicElement::STYLE_INACTIVE;
GraphicElement::style_t style =
decal.active ? GraphicElement::STYLE_ACTIVE : GraphicElement::STYLE_INACTIVE;
Loc loc;
tile_xy(chip_info, wire.tile, loc.x, loc.y);
int32_t tilewire = chip_wire_info(chip_info, wire).tile_wire;
Expand All @@ -526,7 +549,8 @@ std::vector<GraphicElement> Arch::getDecalGraphics(DecalId decal) const
int32_t src_id = chip_wire_info(chip_info, src_wire).tile_wire;
int32_t dst_id = chip_wire_info(chip_info, dst_wire).tile_wire;
GraphicElement::style_t style = decal.active ? GraphicElement::STYLE_ACTIVE : GraphicElement::STYLE_HIDDEN;
uarch->drawPip(ret, style, loc, src_wire, getWireType(src_wire), src_id, dst_wire, getWireType(dst_wire), dst_id);
uarch->drawPip(ret, style, loc, src_wire, getWireType(src_wire), src_id, dst_wire, getWireType(dst_wire),
dst_id);
}
return ret;
}
Expand Down Expand Up @@ -557,7 +581,10 @@ DecalXY Arch::getPipDecal(PipId pip) const

DecalXY Arch::getGroupDecal(GroupId group) const
{
return DecalXY();
DecalXY decalxy;
decalxy.decal = DecalId(group.tile, group.index, DecalId::TYPE_GROUP);
decalxy.decal.active = true;
return decalxy;
}

NEXTPNR_NAMESPACE_END
74 changes: 74 additions & 0 deletions himbaechel/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ inline const PipDataPOD &chip_pip_info(const ChipInfoPOD *chip, PipId pip)
{
return chip_tile_info(chip, pip.tile).pips[pip.index];
}
inline const GroupDataPOD &chip_group_info(const ChipInfoPOD *chip, GroupId group)
{
return chip_tile_info(chip, group.tile).groups[group.index];
}
inline const TileRoutingShapePOD &chip_tile_shape(const ChipInfoPOD *chip, int tile)
{
return chip->tile_shapes[chip->tile_insts[tile].shape];
Expand Down Expand Up @@ -332,6 +336,41 @@ template <RelSlice<int32_t> TileWireDataPOD::*ptr> struct UpDownhillPipRange

// -----------------------------------------------------------------------

template <typename Tid, RelSlice<int32_t> GroupDataPOD::*ptr> struct GroupObjIterator
{
const GroupDataPOD &group;
int tile = -1;
int cursor = -1;

GroupObjIterator(const GroupDataPOD &group, int tile, int cursor) : group(group), tile(tile), cursor(cursor) {};

void operator++() { cursor++; }

bool operator!=(const GroupObjIterator<Tid, ptr> &other) const
{
return tile != other.tile || cursor != other.cursor;
}

bool operator==(const GroupObjIterator<Tid, ptr> &other) const
{
return tile == other.tile && cursor == other.cursor;
}

Tid operator*() const { return Tid(tile, (group.*ptr)[cursor]); }
};

template <typename Tid, RelSlice<int32_t> GroupDataPOD::*ptr> struct GroupObjRange
{
using iterator = GroupObjIterator<Tid, ptr>;
GroupObjRange(const GroupDataPOD &group, int tile) : b(group, tile, 0), e(group, tile, (group.*ptr).ssize()) {}

iterator b, e;
iterator begin() const { return b; }
iterator end() const { return e; }
};

// -----------------------------------------------------------------------

struct BelPinIterator
{
const ChipInfoPOD *chip;
Expand Down Expand Up @@ -393,10 +432,16 @@ struct ArchArgs

typedef TileObjRange<BelId, BelDataPOD, &TileTypePOD::bels> BelRange;
typedef TileObjRange<PipId, PipDataPOD, &TileTypePOD::pips> AllPipRange;
typedef TileObjRange<GroupId, GroupDataPOD, &TileTypePOD::groups> GroupRange;

typedef UpDownhillPipRange<&TileWireDataPOD::pips_uphill> UphillPipRange;
typedef UpDownhillPipRange<&TileWireDataPOD::pips_downhill> DownhillPipRange;

typedef GroupObjRange<BelId, &GroupDataPOD::group_bels> GroupBelRange;
typedef GroupObjRange<WireId, &GroupDataPOD::group_wires> GroupWireRange;
typedef GroupObjRange<PipId, &GroupDataPOD::group_pips> GroupPipRange;
typedef GroupObjRange<GroupId, &GroupDataPOD::group_groups> GroupGroupRange;

struct ArchRanges : BaseArchRanges
{
using ArchArgsT = ArchArgs;
Expand All @@ -412,6 +457,12 @@ struct ArchRanges : BaseArchRanges
using WireBelPinRangeT = BelPinRange;
// Pips
using AllPipsRangeT = AllPipRange;
// Groups
using AllGroupsRangeT = GroupRange;
using GroupBelsRangeT = GroupBelRange;
using GroupWiresRangeT = GroupWireRange;
using GroupPipsRangeT = GroupPipRange;
using GroupGroupsRangeT = GroupGroupRange;
};

struct Arch : BaseArch<ArchRanges>
Expand Down Expand Up @@ -699,6 +750,29 @@ struct Arch : BaseArch<ArchRanges>
return uarch->getClusterPlacement(cluster, root_bel, placement);
}

// -------------------------------------------------
// Group methods
GroupId getGroupByName(IdStringList name) const override;
IdStringList getGroupName(GroupId group) const override;
GroupRange getGroups() const override { return GroupRange(chip_info); }
IdString getGroupType(GroupId group) const { return IdString(chip_group_info(chip_info, group).group_type); }
GroupBelRange getGroupBels(GroupId group) const override
{
return GroupBelRange(chip_group_info(chip_info, group), group.tile);
}
GroupWireRange getGroupWires(GroupId group) const override
{
return GroupWireRange(chip_group_info(chip_info, group), group.tile);
}
GroupPipRange getGroupPips(GroupId group) const override
{
return GroupPipRange(chip_group_info(chip_info, group), group.tile);
}
GroupGroupRange getGroupGroups(GroupId group) const override
{
return GroupGroupRange(chip_group_info(chip_info, group), group.tile);
}

// -------------------------------------------------
// Decal methods
std::vector<GraphicElement> getDecalGraphics(DecalId decal) const override;
Expand Down
28 changes: 25 additions & 3 deletions himbaechel/archdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,34 @@ struct DecalId
DecalId() = default;
DecalId(int32_t tile, int32_t index, DecalType type) : tile(tile), index(index), type(type) {};

bool operator==(const DecalId &other) const { return tile == other.tile && index == other.index && type == other.type; }
bool operator!=(const DecalId &other) const { return tile != other.tile || index != other.index || type != other.type; }
bool operator==(const DecalId &other) const
{
return tile == other.tile && index == other.index && type == other.type;
}
bool operator!=(const DecalId &other) const
{
return tile != other.tile || index != other.index || type != other.type;
}
unsigned int hash() const { return mkhash(tile, mkhash(index, type)); }
};

typedef IdString GroupId;
struct GroupId
{
int32_t tile = -1;
int32_t index = -1;

GroupId() = default;
GroupId(int32_t tile, int32_t index) : tile(tile), index(index) {};

bool operator==(const GroupId &other) const { return tile == other.tile && index == other.index; }
bool operator!=(const GroupId &other) const { return tile != other.tile || index != other.index; }
bool operator<(const GroupId &other) const
{
return tile < other.tile || (tile == other.tile && index < other.index);
}
unsigned int hash() const { return mkhash(tile, index); }
};

typedef IdString BelBucketId;
typedef IdString ClusterId;

Expand Down
12 changes: 12 additions & 0 deletions himbaechel/chipdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,23 @@ NPNR_PACKED_STRUCT(struct NodeShapePOD {
int32_t timing_idx;
});

NPNR_PACKED_STRUCT(struct GroupDataPOD {
int32_t name;
int32_t group_type;
RelSlice<int32_t> group_bels;
RelSlice<int32_t> group_wires;
RelSlice<int32_t> group_pips;
RelSlice<int32_t> group_groups;

RelPtr<uint8_t> extra_data;
});

NPNR_PACKED_STRUCT(struct TileTypePOD {
int32_t type_name;
RelSlice<BelDataPOD> bels;
RelSlice<TileWireDataPOD> wires;
RelSlice<PipDataPOD> pips;
RelSlice<GroupDataPOD> groups;
RelPtr<uint8_t> extra_data;
});

Expand Down
5 changes: 1 addition & 4 deletions himbaechel/himbaechel_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ bool HimbaechelAPI::getClusterPlacement(ClusterId cluster, BelId root_bel,
return ctx->BaseArch::getClusterPlacement(cluster, root_bel, placement);
}

void HimbaechelAPI::expandBoundingBox(BoundingBox &bb) const
{
ctx->BaseArch::expandBoundingBox(bb);
}
void HimbaechelAPI::expandBoundingBox(BoundingBox &bb) const { ctx->BaseArch::expandBoundingBox(bb); }

HimbaechelArch *HimbaechelArch::list_head;
HimbaechelArch::HimbaechelArch(const std::string &name) : name(name)
Expand Down
9 changes: 6 additions & 3 deletions himbaechel/himbaechel_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,13 @@ struct HimbaechelAPI
// Graphics
virtual void drawBel(std::vector<GraphicElement> &g, GraphicElement::style_t style, IdString bel_type, Loc loc) {};

virtual void drawWire(std::vector<GraphicElement> &g, GraphicElement::style_t style, Loc loc, IdString wire_type, int32_t tilewire, IdString tile_type) {};
virtual void drawWire(std::vector<GraphicElement> &g, GraphicElement::style_t style, Loc loc, IdString wire_type,
int32_t tilewire, IdString tile_type) {};

virtual void drawPip(std::vector<GraphicElement> &g,GraphicElement::style_t style, Loc loc,
WireId src, IdString src_type, int32_t src_id, WireId dst, IdString dst_type, int32_t dst_id) {};
virtual void drawPip(std::vector<GraphicElement> &g, GraphicElement::style_t style, Loc loc, WireId src,
IdString src_type, int32_t src_id, WireId dst, IdString dst_type, int32_t dst_id) {};

virtual void drawGroup(std::vector<GraphicElement> &g, IdString group_type, Loc loc) {};

// Routing methods
virtual void expandBoundingBox(BoundingBox &bb) const;
Expand Down
Loading