From 6acf23cf37285e16050b44370be6cbe7dd3e0dc5 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Sat, 16 Jun 2018 15:23:04 +0200 Subject: Some refactoring of Chip API (prep for chipdb refactoring) Signed-off-by: Clifford Wolf --- ice40/chip.h | 58 ++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 18 deletions(-) (limited to 'ice40/chip.h') diff --git a/ice40/chip.h b/ice40/chip.h index e2b54cdf..7460d3b2 100644 --- a/ice40/chip.h +++ b/ice40/chip.h @@ -26,13 +26,15 @@ NEXTPNR_NAMESPACE_BEGIN +typedef int delay_t; + struct DelayInfo { - float delay = 0; + delay_t delay = 0; - float raiseDelay() const { return delay; } - float fallDelay() const { return delay; } - float avgDelay() const { return delay; } + delay_t raiseDelay() const { return delay; } + delay_t fallDelay() const { return delay; } + delay_t avgDelay() const { return delay; } DelayInfo operator+(const DelayInfo &other) const { @@ -44,7 +46,7 @@ struct DelayInfo // ----------------------------------------------------------------------- -enum BelType +enum BelType : int32_t { TYPE_NONE, TYPE_ICESTORM_LC, @@ -56,7 +58,7 @@ enum BelType IdString belTypeToId(BelType type); BelType belTypeFromId(IdString id); -enum PortPin +enum PortPin : int32_t { PIN_NONE, #define X(t) PIN_##t, @@ -70,6 +72,26 @@ PortPin portPinFromId(IdString id); // ----------------------------------------------------------------------- +#if 0 +template +struct RelPtr { + int offset; + + // RelPtr(T *ptr) : offset(reinterpret_cast(ptr) - + // reinterpret_cast(this)) {} + + T&operator*() { + return *reinterpret_cast(reinterpret_cast(this) + offset); + } + + T*operator->() { + return reinterpret_cast(reinterpret_cast(this) + offset); + } +}; +#else +template using RelPtr = T *; +#endif + struct BelWirePOD { int32_t wire_index; @@ -78,10 +100,10 @@ struct BelWirePOD struct BelInfoPOD { - const char *name; + RelPtr name; BelType type; - int num_bel_wires; - BelWirePOD *bel_wires; + int32_t num_bel_wires; + RelPtr bel_wires; int8_t x, y, z; }; @@ -94,7 +116,7 @@ struct BelPortPOD struct PipInfoPOD { int32_t src, dst; - float delay; + int32_t delay; int8_t x, y; int16_t switch_mask; int32_t switch_index; @@ -102,15 +124,15 @@ struct PipInfoPOD struct WireInfoPOD { - const char *name; - int num_uphill, num_downhill; - int *pips_uphill, *pips_downhill; + RelPtr name; + int32_t num_uphill, num_downhill; + RelPtr pips_uphill, pips_downhill; - int num_bels_downhill; + int32_t num_bels_downhill; BelPortPOD bel_uphill; - BelPortPOD *bels_downhill; + RelPtr bels_downhill; - float x, y; + int8_t x, y; }; struct PackagePinPOD @@ -694,8 +716,8 @@ struct Chip // ------------------------------------------------- - bool estimatePosition(BelId bel, float &x, float &y) const; - float estimateDelay(WireId src, WireId dst) const; + bool estimatePosition(BelId bel, int &x, int &y) const; + delay_t estimateDelay(WireId src, WireId dst) const; // ------------------------------------------------- -- cgit v1.2.3