aboutsummaryrefslogtreecommitdiffstats
path: root/test/mppa
diff options
context:
space:
mode:
authorCyril SIX <cyril.six@kalray.eu>2018-04-16 17:31:27 +0200
committerCyril SIX <cyril.six@kalray.eu>2018-04-16 17:31:27 +0200
commitb26424165aa5ae75099792232eca9ea08e09d5a1 (patch)
tree5412932a7c9dc26831dd8707d54c96d8a7cc2996 /test/mppa
parent0ef341c554aff8d70f879411bb0918fb8349f2e4 (diff)
downloadcompcert-kvx-b26424165aa5ae75099792232eca9ea08e09d5a1.tar.gz
compcert-kvx-b26424165aa5ae75099792232eca9ea08e09d5a1.zip
MPPA - added PRNG generator in the tests
Diffstat (limited to 'test/mppa')
-rw-r--r--test/mppa/lib/Makefile18
-rw-r--r--test/mppa/lib/prng.c40
-rw-r--r--test/mppa/lib/prng.h8
3 files changed, 66 insertions, 0 deletions
diff --git a/test/mppa/lib/Makefile b/test/mppa/lib/Makefile
new file mode 100644
index 00000000..10f40f23
--- /dev/null
+++ b/test/mppa/lib/Makefile
@@ -0,0 +1,18 @@
+prng-test-x86: prng.c
+ gcc -D__UNIT_TEST__ -O2 -std=c99 $< -o $@
+
+.PHONY:
+test: test-x86
+
+.PHONY:
+test-x86: prng-test-x86
+ @if ! ./$<; then\
+ >&2 echo "ERROR: $< failed";\
+ exit;\
+ else\
+ echo "Test Succeeded";\
+ fi
+
+.PHONY:
+clean:
+ rm -f prng-test-x86
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__
diff --git a/test/mppa/lib/prng.h b/test/mppa/lib/prng.h
new file mode 100644
index 00000000..fee8c865
--- /dev/null
+++ b/test/mppa/lib/prng.h
@@ -0,0 +1,8 @@
+#ifndef __PRNG_H__
+#define __PRNG_H__
+
+void srand(long long seed);
+
+long long randlong(void);
+
+#endif // __PRNG_H__