aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/volatile
diff options
context:
space:
mode:
authorDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-03-09 20:01:58 +0100
committerDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-03-09 20:01:58 +0100
commit7029dd7e4c65ad40ea71bc385e4415fb4d1a4839 (patch)
treeb364025d3f3548f6103b8d2d17ce89d4c4c7ce82 /test/monniaux/volatile
parent3e40a17befddbdf9f96d7f7299d31f88376093dc (diff)
downloadcompcert-kvx-7029dd7e4c65ad40ea71bc385e4415fb4d1a4839.tar.gz
compcert-kvx-7029dd7e4c65ad40ea71bc385e4415fb4d1a4839.zip
demo for volatile
Diffstat (limited to 'test/monniaux/volatile')
-rw-r--r--test/monniaux/volatile/Makefile18
-rw-r--r--test/monniaux/volatile/volatile.c19
2 files changed, 28 insertions, 9 deletions
diff --git a/test/monniaux/volatile/Makefile b/test/monniaux/volatile/Makefile
new file mode 100644
index 00000000..59c8b459
--- /dev/null
+++ b/test/monniaux/volatile/Makefile
@@ -0,0 +1,18 @@
+all: volatile.ccomp.k1c volatile.gcc.k1c
+
+volatile.ccomp.k1c : volatile.ccomp.k1c.s
+ k1-cos-gcc $< -o $@
+
+volatile.gcc.k1c : volatile.gcc.k1c.s
+ k1-cos-gcc $< -o $@
+
+volatile.ccomp.k1c.s : volatile.c
+ ../../../ccomp -Dvolatile= -O2 -Wall -Wno-c11-extensions -S $< -o $@
+
+volatile.gcc.k1c.s : volatile.c
+ k1-cos-gcc -O2 -Wall -Werror=implicit -std=gnu99 -S $< -o $@
+
+clean:
+ -rm -f *.k1c *.s
+
+.PHONY: clean
diff --git a/test/monniaux/volatile/volatile.c b/test/monniaux/volatile/volatile.c
index 75f8ce3b..442ccff4 100644
--- a/test/monniaux/volatile/volatile.c
+++ b/test/monniaux/volatile/volatile.c
@@ -1,32 +1,33 @@
-#include <pthread.h>
#include <stdio.h>
#include <time.h>
-#define VOLATILE volatile
+int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
+ void *(*start_routine) (void *), void *arg);
+int pthread_join(pthread_t thread, void **retval);
typedef unsigned data;
-static data powm(data x, unsigned e, data m) {
+static inline data powM(data x, unsigned e) {
data y = 1;
for(unsigned i=0; i<e; i++) {
- y = (y * x) % m;
+ y = (y * x) % 65537;
}
return y;
}
void* second_thread_entry(void *ptr) {
- *((data*) ptr) = powm(3, 65536, 65537);
+ *((data*) ptr) = powM(3, 65536);
return NULL;
}
int main() {
pthread_t second_thread_id;
- VOLATILE data value;
+ volatile data value;
pthread_create(&second_thread_id, NULL,
second_thread_entry, (void*) &value);
- value = 0;
- data correct = powm(3, 65536*4, 65537);;
+ value = 69;
+ data correct = powM(3, 65536*2);
data read = value;
pthread_join(second_thread_id, NULL);
- printf("%u %u\n", correct, read);
+ printf("%u %u %s\n", read, correct, read == correct ? "OK" : "FAIL");
}