From b26424165aa5ae75099792232eca9ea08e09d5a1 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Mon, 16 Apr 2018 17:31:27 +0200 Subject: MPPA - added PRNG generator in the tests --- test/mppa/lib/prng.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/mppa/lib/prng.c (limited to 'test/mppa/lib/prng.c') diff --git a/test/mppa/lib/prng.c b/test/mppa/lib/prng.c new file mode 100644 index 00000000..5846038c --- /dev/null +++ b/test/mppa/lib/prng.c @@ -0,0 +1,40 @@ +// https://en.wikipedia.org/wiki/Linear_congruential_generator -> MMIX Donald Knuth +// modulo 2^64 = no need to do it explicitly + +#define MULTIPLIER 6364136223846793005LL +#define INCREMENT 1442695040888963407LL + +static unsigned long long current; + +void srand(long long seed){ + seed = current; +} + +unsigned long long randlong(void){ + return (current = MULTIPLIER * current + INCREMENT); +} + +#ifdef __UNIT_TEST__ +char bytewise_sum(unsigned long long to_check){ + char sum = 0; + + for (int i = 0 ; i < 8 ; i++) + sum += (to_check & (unsigned long long)(0xFFULL << i*8)) >> i*8; + + return sum; +} + +int main(void){ + srand(42); + + if (bytewise_sum(0xdeadbeefb00b1355ULL) != 91) + return 1; + + for (int i = 0 ; i < 1000 ; i++) + randlong(); + + unsigned long long last = randlong(); + + return !((unsigned char)bytewise_sum(last) == 251); +} +#endif // __UNIT_TEST__ -- cgit