diff options
author | Cyril SIX <cyril.six@kalray.eu> | 2018-11-14 11:49:34 +0100 |
---|---|---|
committer | Cyril SIX <cyril.six@kalray.eu> | 2018-11-14 11:49:34 +0100 |
commit | a220a09ae6ce52400a563ea6ee65aa36b2ea9dfb (patch) | |
tree | 680798b800e104d0e766a3ab7a0f39469b2671fa /test/mppa/prng/prng.c | |
parent | 0b86431038c1e874d7d7030ab41a8f56b0a9991f (diff) | |
parent | 154230f3d9cad4f8de59e8fcaa9d0fe4ae151a98 (diff) | |
download | compcert-kvx-a220a09ae6ce52400a563ea6ee65aa36b2ea9dfb.tar.gz compcert-kvx-a220a09ae6ce52400a563ea6ee65aa36b2ea9dfb.zip |
Merge branch 'mppa_asmbloc_nobreg' into mppa_k1c
Conflicts:
mppa_k1c/Asm.v
mppa_k1c/Asmexpand.ml
mppa_k1c/TargetPrinter.ml
test/mppa/Makefile
test/mppa/builtins/clzll.c
test/mppa/generate.sh
Diffstat (limited to 'test/mppa/prng/prng.c')
-rw-r--r-- | test/mppa/prng/prng.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/mppa/prng/prng.c b/test/mppa/prng/prng.c new file mode 100644 index 00000000..71de1dc3 --- /dev/null +++ b/test/mppa/prng/prng.c @@ -0,0 +1,41 @@ +// https://en.wikipedia.org/wiki/Linear_congruential_generator -> MMIX Donald Knuth +// modulo 2^64 = no need to do it explicitly + +#include "types.h" + +#define MULTIPLIER 6364136223846793005LL +#define INCREMENT 1442695040888963407LL + +static uint64_t current; + +void srand(uint64_t seed){ + current = seed; +} + +uint64_t randlong(void){ + return (current = MULTIPLIER * current + INCREMENT); +} + +#ifdef __UNIT_TEST_PRNG__ +char bytewise_sum(uint64_t to_check){ + char sum = 0; + int i; + + for (i = 0 ; i < 8 ; i++) + sum += (to_check & (uint64_t)(0xFFULL << i*8)) >> i*8; + + return sum; +} + +int main(void){ + srand(42); + int i; + + for (i = 0 ; i < 1000 ; i++) + randlong(); + + uint64_t last = randlong(); + + return !((unsigned char)bytewise_sum(last) == 155); +} +#endif // __UNIT_TEST_PRNG__ |