diff options
author | Clifford Wolf <clifford@clifford.at> | 2018-06-12 15:50:33 +0200 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2018-06-12 15:50:33 +0200 |
commit | 9c275d0a653b11f2a494321be2ab66678117db2d (patch) | |
tree | cccabe4cfbb191697527e915175b70105ac470f6 /ice40 | |
parent | 7e879953d62d486eff62a27fe94b7b5894a251b8 (diff) | |
download | nextpnr-9c275d0a653b11f2a494321be2ab66678117db2d.tar.gz nextpnr-9c275d0a653b11f2a494321be2ab66678117db2d.tar.bz2 nextpnr-9c275d0a653b11f2a494321be2ab66678117db2d.zip |
Add fast IdString <-> PortPin conversion
Signed-off-by: Clifford Wolf <clifford@clifford.at>
Diffstat (limited to 'ice40')
-rw-r--r-- | ice40/chip.cc | 26 | ||||
-rw-r--r-- | ice40/chip.h | 1 |
2 files changed, 13 insertions, 14 deletions
diff --git a/ice40/chip.cc b/ice40/chip.cc index 88fcc512..918a7fb4 100644 --- a/ice40/chip.cc +++ b/ice40/chip.cc @@ -52,27 +52,25 @@ BelType belTypeFromId(IdString id) // ----------------------------------------------------------------------- -IdString portPinToId(PortPin type) +void IdString::initialize_chip() { -#define X(t) \ - if (type == PIN_##t) \ - return #t; - +#define X(t) initialize_add(#t, PIN_##t); #include "portpins.inc" - #undef X - return IdString(); } -PortPin portPinFromId(IdString id) +IdString portPinToId(PortPin type) { -#define X(t) \ - if (id == #t) \ - return PIN_##t; - -#include "portpins.inc" + IdString ret; + if (type > 0 && type < PIN_MAXIDX) + ret.index = type; + return ret; +} -#undef X +PortPin portPinFromId(IdString id) +{ + if (id.index > 0 && id.index < PIN_MAXIDX) + return PortPin(id.index); return PIN_NONE; } diff --git a/ice40/chip.h b/ice40/chip.h index 73e8d33b..f8946610 100644 --- a/ice40/chip.h +++ b/ice40/chip.h @@ -62,6 +62,7 @@ enum PortPin #define X(t) PIN_##t, #include "portpins.inc" #undef X + PIN_MAXIDX }; IdString portPinToId(PortPin type); |