Skip to content

Commit

Permalink
Fix handling of RNG seed
Browse files Browse the repository at this point in the history
* Fix truncation of output seed value from 64 bits to 32 bits (int
  instead of uint64) when written to json file.

* Fix input seed value conversion when --seed option is used.

* Remove input seed value scrambling (use of rngseed()) when --seed
  or --randomize-seed option is used since the output seed value will
  be the scrambled value and not the seed that was actually supplied
  or generated.
  • Loading branch information
jthornblad committed Sep 17, 2024
1 parent 2627d4e commit 364eef2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions common/kernel/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ po::options_description CommandHandler::getGeneralOptions()
general.add_options()("json", po::value<std::string>(), "JSON design file to ingest");
general.add_options()("write", po::value<std::string>(), "JSON design file to write");
general.add_options()("top", po::value<std::string>(), "name of top module");
general.add_options()("seed", po::value<int>(), "seed value for random number generator");
general.add_options()("seed", po::value<uint64_t>(), "seed value for random number generator");
general.add_options()("randomize-seed,r", "randomize seed value for random number generator");

general.add_options()(
Expand Down Expand Up @@ -447,7 +447,7 @@ void CommandHandler::setupContext(Context *ctx)
}

if (vm.count("seed")) {
ctx->rngseed(vm["seed"].as<int>());
ctx->rngstate = vm["seed"].as<uint64_t>();
}

if (vm.count("threads")) {
Expand All @@ -456,10 +456,10 @@ void CommandHandler::setupContext(Context *ctx)

if (vm.count("randomize-seed")) {
std::random_device randDev{};
std::uniform_int_distribution<int> distrib{1};
std::uniform_int_distribution<uint64_t> distrib{1};
auto seed = distrib(randDev);
ctx->rngseed(seed);
log_info("Generated random seed: %d\n", seed);
ctx->rngstate = seed;
log_info("Generated random seed: %lu\n", seed);
}

if (vm.count("slack_redist_iter")) {
Expand Down
2 changes: 1 addition & 1 deletion common/kernel/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct Property
};

Property();
Property(int64_t intval, int width = 32);
Property(int64_t intval, int width = 64);
Property(const std::string &strval);
Property(State bit);
Property &operator=(const Property &other) = default;
Expand Down

0 comments on commit 364eef2

Please sign in to comment.