Skip to content

Commit

Permalink
Create std::mt19937 only once
Browse files Browse the repository at this point in the history
  • Loading branch information
RCoeurjoly committed Jun 27, 2024
1 parent ba62108 commit bebdd88
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions tests/functional/single_cells/vcd_harness.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ struct Dump {
};

template<size_t n>
Signal<n> random_signal() {
std::random_device rd; // Random device for seeding
std::mt19937 gen(rd()); // Mersenne Twister engine
Signal<n> random_signal(std::mt19937 &gen) {
std::uniform_int_distribution<uint32_t> dist;
std::array<uint32_t, (n+31)/32> words;
for(auto &w : words)
Expand All @@ -52,9 +50,12 @@ struct Reset {
};

struct Randomize {
std::mt19937 &gen;
Randomize(std::mt19937 &gen) : gen(gen) {}

template <size_t n>
void operator()(const char *, Signal<n> &signal) {
signal = random_signal<n>();
signal = random_signal<n>(gen);
}
};

Expand Down Expand Up @@ -89,19 +90,23 @@ int main(int argc, char **argv)
vcd_file << "#0\n";
// Set all signals to false
inputs.visit(Reset());

gold::eval(inputs, outputs, state, next_state);
{
Dump d(vcd_file);
inputs.visit(d);
outputs.visit(d);
state.visit(d);
}


// Initialize random number generator once
std::random_device rd;
std::mt19937 gen(rd());

for (int step = 0; step < steps; ++step) {
// Functional backend cxx
vcd_file << "#" << (step + 1) << "\n";
inputs.visit(Randomize());
inputs.visit(Randomize(gen));

gold::eval(inputs, outputs, state, next_state);
{
Expand All @@ -110,7 +115,7 @@ int main(int argc, char **argv)
outputs.visit(d);
state.visit(d);
}

state = next_state;
}

Expand Down

0 comments on commit bebdd88

Please sign in to comment.