From 91db413c60c965b6b7cc095f53c8d03a1658566e Mon Sep 17 00:00:00 2001 From: Serge Bazanski Date: Sat, 14 Jul 2018 20:33:32 +0100 Subject: Refactor RNG out to separate DeterministicRNG class This well also allow for better lifecycle control over the state of the RNG in the future. --- common/nextpnr.h | 124 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 67 insertions(+), 57 deletions(-) diff --git a/common/nextpnr.h b/common/nextpnr.h index 87c50fe3..e53e4d01 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -265,65 +265,15 @@ class IdStringDB } }; -class BaseCtx : public IdStringDB +class DeterministicRNG { - public: - std::unordered_map> nets; - std::unordered_map> cells; - - BaseCtx() {} - ~BaseCtx() {} - - Context *getCtx() { return reinterpret_cast(this); } - - const Context *getCtx() const { return reinterpret_cast(this); } - - // -------------------------------------------------------------- - - bool allUiReload = false; - bool frameUiReload = false; - std::unordered_set belUiReload; - std::unordered_set wireUiReload; - std::unordered_set pipUiReload; - std::unordered_set groupUiReload; - - void refreshUi() { allUiReload = true; } - - void refreshUiFrame() { frameUiReload = true; } - - void refreshUiBel(BelId bel) { belUiReload.insert(bel); } - - void refreshUiWire(WireId wire) { wireUiReload.insert(wire); } - - void refreshUiPip(PipId pip) { pipUiReload.insert(pip); } - - void refreshUiGroup(GroupId group) { groupUiReload.insert(group); } -}; - -NEXTPNR_NAMESPACE_END - -#include "arch.h" - -NEXTPNR_NAMESPACE_BEGIN - -struct Context : Arch -{ - bool verbose = false; - bool debug = false; - bool force = false; - bool timing_driven = true; - float target_freq = 12e6; - - Context(ArchArgs args) : Arch(args) {} - - // -------------------------------------------------------------- - - // provided by router1.cc - bool getActualRouteDelay(WireId src_wire, WireId dst_wire, delay_t &delay); - - // -------------------------------------------------------------- + private: + uint64_t rngstate; - uint64_t rngstate = 0x3141592653589793; + public: + DeterministicRNG() : rngstate(0x3141592653589793) + { + } uint64_t rng64() { @@ -383,6 +333,66 @@ struct Context : Arch shuffle(a); } +}; + +class BaseCtx : public IdStringDB, public DeterministicRNG +{ + public: + std::unordered_map> nets; + std::unordered_map> cells; + + BaseCtx() {} + ~BaseCtx() {} + + Context *getCtx() { return reinterpret_cast(this); } + + const Context *getCtx() const { return reinterpret_cast(this); } + + // -------------------------------------------------------------- + + bool allUiReload = false; + bool frameUiReload = false; + std::unordered_set belUiReload; + std::unordered_set wireUiReload; + std::unordered_set pipUiReload; + std::unordered_set groupUiReload; + + void refreshUi() { allUiReload = true; } + + void refreshUiFrame() { frameUiReload = true; } + + void refreshUiBel(BelId bel) { belUiReload.insert(bel); } + + void refreshUiWire(WireId wire) { wireUiReload.insert(wire); } + + void refreshUiPip(PipId pip) { pipUiReload.insert(pip); } + + void refreshUiGroup(GroupId group) { groupUiReload.insert(group); } +}; + +NEXTPNR_NAMESPACE_END + +#include "arch.h" + +NEXTPNR_NAMESPACE_BEGIN + +struct Context : Arch +{ + bool verbose = false; + bool debug = false; + bool force = false; + bool timing_driven = true; + float target_freq = 12e6; + + Context(ArchArgs args) : Arch(args) {} + + // -------------------------------------------------------------- + + // provided by router1.cc + bool getActualRouteDelay(WireId src_wire, WireId dst_wire, delay_t &delay); + + // -------------------------------------------------------------- + uint32_t checksum() const; void check() const; -- cgit v1.2.3