aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/ternary
diff options
context:
space:
mode:
authorDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-03-24 18:00:19 +0100
committerDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-03-24 18:00:19 +0100
commit52aeb8026a9d9d2675eebf965d4ff3f87a0e2346 (patch)
treea38dca1ac9a56114a6a3788efa76b1c93141b90e /test/monniaux/ternary
parentee49464e9745ed7da517b74791c7c85296184fd3 (diff)
downloadcompcert-kvx-52aeb8026a9d9d2675eebf965d4ff3f87a0e2346.tar.gz
compcert-kvx-52aeb8026a9d9d2675eebf965d4ff3f87a0e2346.zip
demo ternary op
Diffstat (limited to 'test/monniaux/ternary')
-rw-r--r--test/monniaux/ternary/Makefile26
-rw-r--r--test/monniaux/ternary/ternary.c23
2 files changed, 49 insertions, 0 deletions
diff --git a/test/monniaux/ternary/Makefile b/test/monniaux/ternary/Makefile
new file mode 100644
index 00000000..b051b397
--- /dev/null
+++ b/test/monniaux/ternary/Makefile
@@ -0,0 +1,26 @@
+include ../rules.mk
+
+PRODUCTS=ternary.gcc.host.out ternary.ccomp.host.out \
+ ternary.gcc.k1c.out ternary.ccomp.k1c.out \
+ ternary.gcc.k1c.s ternary.ccomp.k1c.s
+
+all: $(PRODUCTS)
+
+ternary.gcc.host.s ternary.ccomp.host.s ternary.gcc.k1c.s ternary.ccomp.k1c.s : ../clock.h
+
+ternary.ccomp.host: ternary.ccomp.host.o ../clock.gcc.host.o
+ $(CCOMP) $(CCOMPFLAGS) $+ -o $@
+
+ternary.gcc.host: ternary.gcc.host.o ../clock.gcc.host.o
+ $(CC) $(CFLAGS) $+ -o $@
+
+ternary.gcc.k1c: ternary.gcc.k1c.o ../clock.gcc.k1c.o
+ $(K1C_CC) $(K1C_CFLAGS) $+ -o $@
+
+ternary.ccomp.k1c: ternary.ccomp.k1c.o ../clock.gcc.k1c.o
+ $(K1C_CCOMP) $(K1C_CCOMPFLAGS) $+ -o $@
+
+clean:
+ -rm -f *.o *.s *.k1c
+
+.PHONY: clean
diff --git a/test/monniaux/ternary/ternary.c b/test/monniaux/ternary/ternary.c
new file mode 100644
index 00000000..45201ff8
--- /dev/null
+++ b/test/monniaux/ternary/ternary.c
@@ -0,0 +1,23 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <inttypes.h>
+#include "../clock.h"
+
+typedef uint32_t data;
+
+data silly_computation(void) {
+ data x = 1;
+ for(int i=0; i<10000; i++) {
+ x = x * (((x & 0x100) != 0) ? 45561U : 337777U);
+ }
+ return x;
+}
+
+int main() {
+ clock_prepare();
+ clock_start();
+ data result = silly_computation();
+ clock_stop();
+ printf("result=%" PRIu32 "\ncycles=%" PRIu64 "\n", result, get_total_clock());
+ return 0;
+}