From 364eef2feffa89cc3f622a8b97063ac4c2d119fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Th=C3=B6rnblad?= Date: Tue, 17 Sep 2024 13:12:06 +0200 Subject: [PATCH] Fix handling of RNG seed * 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. --- common/kernel/command.cc | 10 +++++----- common/kernel/property.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/common/kernel/command.cc b/common/kernel/command.cc index 01c556b0e6..e30424c5a9 100644 --- a/common/kernel/command.cc +++ b/common/kernel/command.cc @@ -343,7 +343,7 @@ po::options_description CommandHandler::getGeneralOptions() general.add_options()("json", po::value(), "JSON design file to ingest"); general.add_options()("write", po::value(), "JSON design file to write"); general.add_options()("top", po::value(), "name of top module"); - general.add_options()("seed", po::value(), "seed value for random number generator"); + general.add_options()("seed", po::value(), "seed value for random number generator"); general.add_options()("randomize-seed,r", "randomize seed value for random number generator"); general.add_options()( @@ -447,7 +447,7 @@ void CommandHandler::setupContext(Context *ctx) } if (vm.count("seed")) { - ctx->rngseed(vm["seed"].as()); + ctx->rngstate = vm["seed"].as(); } if (vm.count("threads")) { @@ -456,10 +456,10 @@ void CommandHandler::setupContext(Context *ctx) if (vm.count("randomize-seed")) { std::random_device randDev{}; - std::uniform_int_distribution distrib{1}; + std::uniform_int_distribution 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")) { diff --git a/common/kernel/property.h b/common/kernel/property.h index 2ff085ec1a..fd385c7ecc 100644 --- a/common/kernel/property.h +++ b/common/kernel/property.h @@ -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;