From 3205180fd93d6abd1e63f5d8b794881896f57493 Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 26 Jun 2020 10:38:41 +0000 Subject: Revert "Make icebram deterministic" This reverts commit 2679c91b8a158aa4aca49dd726955e8c63cf7bef. --- icebram/icebram.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/icebram/icebram.cc b/icebram/icebram.cc index 97e6a2c..f585fcf 100644 --- a/icebram/icebram.cc +++ b/icebram/icebram.cc @@ -106,7 +106,7 @@ void help(const char *cmd) printf(" use the same file as later.\n"); printf("\n"); printf(" -s \n"); - printf(" seed random generator with the given value.\n"); + printf(" seed random generator with fixed value.\n"); printf("\n"); printf(" -v\n"); printf(" verbose output\n"); @@ -131,7 +131,7 @@ int main(int argc, char **argv) bool verbose = false; bool generate = false; bool seed = false; - uint32_t seed_nr = 0; + uint32_t seed_nr = getpid(); int opt; while ((opt = getopt(argc, argv, "vgs:")) != -1) -- cgit v1.2.3 From f8b8ea0f3cdc4a2cf61a28c1ce44616555b62e4e Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 26 Jun 2020 10:44:40 +0000 Subject: icebram: refactor seeding logic. --- icebram/icebram.cc | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/icebram/icebram.cc b/icebram/icebram.cc index f585fcf..1bb3095 100644 --- a/icebram/icebram.cc +++ b/icebram/icebram.cc @@ -131,7 +131,7 @@ int main(int argc, char **argv) bool verbose = false; bool generate = false; bool seed = false; - uint32_t seed_nr = getpid(); + uint32_t seed_opt = 0; int opt; while ((opt = getopt(argc, argv, "vgs:")) != -1) @@ -146,7 +146,7 @@ int main(int argc, char **argv) break; case 's': seed = true; - seed_nr = atoi(optarg); + seed_opt = atoi(optarg); break; default: help(argv[0]); @@ -172,7 +172,17 @@ int main(int argc, char **argv) } if (verbose && seed) - fprintf(stderr, "Seed: %d\n", seed_nr); + fprintf(stderr, "Seed: %d\n", seed_opt); + + // If -s is provided: seed with the given value. + // If -s is not provided: seed with the PID and current time, which are unlikely + // to repeat simultaneously. + uint32_t seed_nr; + if (!seed) { + seed_nr = getpid(); + } else { + seed_nr = seed_opt; + } x = uint64_t(seed_nr) << 32; x ^= uint64_t(depth) << 16; @@ -182,16 +192,12 @@ int main(int argc, char **argv) xorshift64star(); xorshift64star(); - if (!seed){ + 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 From 7ed94f51708f7838176bbb46ae680d967aaef744 Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 26 Jun 2020 10:45:03 +0000 Subject: icebram: add WASI platform support. --- icebram/icebram.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/icebram/icebram.cc b/icebram/icebram.cc index 1bb3095..aacf00c 100644 --- a/icebram/icebram.cc +++ b/icebram/icebram.cc @@ -179,7 +179,11 @@ int main(int argc, char **argv) // to repeat simultaneously. uint32_t seed_nr; if (!seed) { +#if defined(__wasm) + seed_nr = 0; +#else seed_nr = getpid(); +#endif } else { seed_nr = seed_opt; } -- cgit v1.2.3