diff options
author | Clifford Wolf <clifford@clifford.at> | 2018-06-13 13:46:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-13 13:46:18 +0200 |
commit | bb0307a5ab6118356669b9de1961ca4c4c816789 (patch) | |
tree | dc6fdca9af63ff97c9303ca40bf41213eea51246 | |
parent | 25cda32bb8d46f733d4e3a52a88879672949e09d (diff) | |
parent | 4943748512447ff360e07f227040315a6fb79337 (diff) | |
download | icestorm-bb0307a5ab6118356669b9de1961ca4c4c816789.tar.gz icestorm-bb0307a5ab6118356669b9de1961ca4c4c816789.tar.bz2 icestorm-bb0307a5ab6118356669b9de1961ca4c4c816789.zip |
Merge pull request #149 from tomverbeure/seed
icebram: add option to specify seed for repeatable outcomes.
-rw-r--r-- | icebram/icebram.cc | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/icebram/icebram.cc b/icebram/icebram.cc index a796f92..f585fcf 100644 --- a/icebram/icebram.cc +++ b/icebram/icebram.cc @@ -94,7 +94,7 @@ void help(const char *cmd) { printf("\n"); printf("Usage: %s [options] <from_hexfile> <to_hexfile>\n", cmd); - printf(" %s [options] -g <width> <depth>\n", cmd); + printf(" %s [options] -g [-s <seed>] <width> <depth>\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 <from_hexfile> later.\n"); printf("\n"); + printf(" -s <seed>\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(); |