mirror of https://github.com/YosysHQ/icestorm.git
icebram: refactor seeding logic.
This commit is contained in:
parent
3205180fd9
commit
f8b8ea0f3c
|
|
@ -131,7 +131,7 @@ int main(int argc, char **argv)
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
bool generate = false;
|
bool generate = false;
|
||||||
bool seed = false;
|
bool seed = false;
|
||||||
uint32_t seed_nr = getpid();
|
uint32_t seed_opt = 0;
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt(argc, argv, "vgs:")) != -1)
|
while ((opt = getopt(argc, argv, "vgs:")) != -1)
|
||||||
|
|
@ -146,7 +146,7 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
seed = true;
|
seed = true;
|
||||||
seed_nr = atoi(optarg);
|
seed_opt = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
help(argv[0]);
|
help(argv[0]);
|
||||||
|
|
@ -172,7 +172,17 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose && seed)
|
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(seed_nr) << 32;
|
||||||
x ^= uint64_t(depth) << 16;
|
x ^= uint64_t(depth) << 16;
|
||||||
|
|
@ -182,16 +192,12 @@ int main(int argc, char **argv)
|
||||||
xorshift64star();
|
xorshift64star();
|
||||||
xorshift64star();
|
xorshift64star();
|
||||||
|
|
||||||
if (!seed){
|
if (!seed) {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
x ^= uint64_t(tv.tv_sec) << 20;
|
x ^= uint64_t(tv.tv_sec) << 20;
|
||||||
x ^= uint64_t(tv.tv_usec);
|
x ^= uint64_t(tv.tv_usec);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
x ^= uint64_t(seed) << 20;
|
|
||||||
x ^= uint64_t(seed);
|
|
||||||
}
|
|
||||||
|
|
||||||
xorshift64star();
|
xorshift64star();
|
||||||
xorshift64star();
|
xorshift64star();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue