aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorSerge Bazanski <serge@bazanski.pl>2018-07-14 20:33:32 +0100
committerSerge Bazanski <serge@bazanski.pl>2018-07-14 20:33:32 +0100
commit91db413c60c965b6b7cc095f53c8d03a1658566e (patch)
tree595ca53fa3567815911f2a150e5eaa95a815ad8e /common
parent59a790cd00421d14120927fbb1718da8cd77e3c4 (diff)
downloadnextpnr-91db413c60c965b6b7cc095f53c8d03a1658566e.tar.gz
nextpnr-91db413c60c965b6b7cc095f53c8d03a1658566e.tar.bz2
nextpnr-91db413c60c965b6b7cc095f53c8d03a1658566e.zip
Refactor RNG out to separate DeterministicRNG class
This well also allow for better lifecycle control over the state of the RNG in the future.
Diffstat (limited to 'common')
-rw-r--r--common/nextpnr.h124
1 files 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<IdString, std::unique_ptr<NetInfo>> nets;
- std::unordered_map<IdString, std::unique_ptr<CellInfo>> cells;
-
- BaseCtx() {}
- ~BaseCtx() {}
-
- Context *getCtx() { return reinterpret_cast<Context *>(this); }
-
- const Context *getCtx() const { return reinterpret_cast<const Context *>(this); }
-
- // --------------------------------------------------------------
-
- bool allUiReload = false;
- bool frameUiReload = false;
- std::unordered_set<BelId> belUiReload;
- std::unordered_set<WireId> wireUiReload;
- std::unordered_set<PipId> pipUiReload;
- std::unordered_set<GroupId> 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<IdString, std::unique_ptr<NetInfo>> nets;
+ std::unordered_map<IdString, std::unique_ptr<CellInfo>> cells;
+
+ BaseCtx() {}
+ ~BaseCtx() {}
+
+ Context *getCtx() { return reinterpret_cast<Context *>(this); }
+
+ const Context *getCtx() const { return reinterpret_cast<const Context *>(this); }
+
+ // --------------------------------------------------------------
+
+ bool allUiReload = false;
+ bool frameUiReload = false;
+ std::unordered_set<BelId> belUiReload;
+ std::unordered_set<WireId> wireUiReload;
+ std::unordered_set<PipId> pipUiReload;
+ std::unordered_set<GroupId> 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;