From e234ee01106640d8fb618d9ca7e161b6da48c9c0 Mon Sep 17 00:00:00 2001 From: Tom Verbeure Date: Sat, 2 Jun 2018 19:01:08 -0700 Subject: Add option to specify seed for repeatable outcomes. --- icebram/icebram.cc | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/icebram/icebram.cc b/icebram/icebram.cc index a796f92..9d85067 100644 --- a/icebram/icebram.cc +++ b/icebram/icebram.cc @@ -94,7 +94,7 @@ void help(const char *cmd) { printf("\n"); printf("Usage: %s [options] \n", cmd); - printf(" %s [options] -g \n", cmd); + printf(" %s [options] -g [-s ] \n", cmd); printf("\n"); printf("Replace BRAM initialization data in a .asc file. This can be used\n"); printf("for example to replace firmware images without re-running synthesis\n"); @@ -105,6 +105,9 @@ void help(const char *cmd) printf(" use this to generate the hex file used during synthesis, then\n"); printf(" use the same file as later.\n"); printf("\n"); + printf(" -s \n"); + printf(" seed random generator with fixed value.\n"); + printf("\n"); printf(" -v\n"); printf(" verbose output\n"); printf("\n"); @@ -127,9 +130,11 @@ int main(int argc, char **argv) bool verbose = false; bool generate = false; + bool seed = false; + uint32_t seed_nr = getpid(); int opt; - while ((opt = getopt(argc, argv, "vg")) != -1) + while ((opt = getopt(argc, argv, "vgs:")) != -1) { switch (opt) { @@ -139,6 +144,10 @@ int main(int argc, char **argv) case 'g': generate = true; break; + case 's': + seed = true; + seed_nr = atoi(optarg); + break; default: help(argv[0]); } @@ -162,7 +171,10 @@ int main(int argc, char **argv) exit(1); } - x = uint64_t(getpid()) << 32; + if (verbose && seed) + fprintf(stderr, "Seed: %d\n", seed_nr); + + x = uint64_t(seed_nr) << 32; x ^= uint64_t(depth) << 16; x ^= uint64_t(width) << 10; @@ -170,10 +182,16 @@ int main(int argc, char **argv) xorshift64star(); xorshift64star(); - struct timeval tv; - gettimeofday(&tv, NULL); - x ^= uint64_t(tv.tv_sec) << 20; - x ^= uint64_t(tv.tv_usec); + if (!seed){ + struct timeval tv; + gettimeofday(&tv, NULL); + x ^= uint64_t(tv.tv_sec) << 20; + x ^= uint64_t(tv.tv_usec); + } + else { + x ^= uint64_t(seed) << 20; + x ^= uint64_t(seed); + } xorshift64star(); xorshift64star(); -- cgit v1.2.3