From 9c275d0a653b11f2a494321be2ab66678117db2d Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Tue, 12 Jun 2018 15:50:33 +0200 Subject: Add fast IdString <-> PortPin conversion Signed-off-by: Clifford Wolf --- ice40/chip.cc | 26 ++++++++++++-------------- ice40/chip.h | 1 + 2 files changed, 13 insertions(+), 14 deletions(-) (limited to 'ice40') 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); -- cgit v1.2.3