aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Monniaux <David.Monniaux@univ-grenoble-alpes.fr>2022-02-11 14:26:28 +0100
committerDavid Monniaux <David.Monniaux@univ-grenoble-alpes.fr>2022-02-11 14:26:28 +0100
commitd9f17c66b52dc49ced37b0a792eb638d7124ffcd (patch)
tree2875daad6f5487e205261d5efffc67f4a065e1f2 /test
parent54dea0fc061f5daee5976450ec84ddb7e15c5db9 (diff)
downloadcompcert-kvx-d9f17c66b52dc49ced37b0a792eb638d7124ffcd.tar.gz
compcert-kvx-d9f17c66b52dc49ced37b0a792eb638d7124ffcd.zip
experiments in division
Diffstat (limited to 'test')
-rw-r--r--test/monniaux/division/compare_timings.c67
l---------test/monniaux/division/cycles.h1
2 files changed, 68 insertions, 0 deletions
diff --git a/test/monniaux/division/compare_timings.c b/test/monniaux/division/compare_timings.c
new file mode 100644
index 00000000..15195d3e
--- /dev/null
+++ b/test/monniaux/division/compare_timings.c
@@ -0,0 +1,67 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <inttypes.h>
+#include "cycles.h"
+
+#define CHECKS(mode, quotient) \
+void checks_##mode() { \
+ uint64_t checksum=UINT64_C(0), \
+ a=UINT64_C(0x10000000000), \
+ b=UINT64_C(0x1000); \
+ for(int i=0; i<10000; i++) { \
+ uint64_t q = (quotient); \
+ a += UINT64_C(0x36667); \
+ b += UINT64_C(0x13); \
+ checksum += q; \
+ } \
+ printf("checksum = %" PRIx64 "\n", checksum); \
+}
+
+#define CHECKS2(mode, quotient) \
+void checks2_##mode() { \
+ uint64_t checksum=UINT64_C(0), \
+ a=UINT64_C(0x10000000000), \
+ b=UINT64_C(0x1000); \
+ for(int i=0; i<5000; i++) { \
+ uint64_t q = (quotient); \
+ a += UINT64_C(0x36667); \
+ b += UINT64_C(0x13); \
+ checksum += q; \
+ q = (quotient); \
+ a += UINT64_C(0x36667); \
+ b += UINT64_C(0x13); \
+ checksum += q; \
+ } \
+ printf("checksum = %" PRIx64 "\n", checksum); \
+}
+
+CHECKS(normal, a/b)
+CHECKS(fp, __builtin_fp_udiv64(a, b))
+
+CHECKS2(normal, a/b)
+CHECKS2(fp, __builtin_fp_udiv64(a, b))
+
+int main() {
+ cycle_t start, stop;
+ cycle_count_config();
+
+ start = get_cycle();
+ checks_normal();
+ stop = get_cycle();
+ printf("normal division: %" PRcycle " cycles\n", stop-start);
+
+ start = get_cycle();
+ checks_fp();
+ stop = get_cycle();
+ printf("fp division: %" PRcycle " cycles\n", stop-start);
+
+ start = get_cycle();
+ checks2_normal();
+ stop = get_cycle();
+ printf("normal division x2: %" PRcycle " cycles\n", stop-start);
+
+ start = get_cycle();
+ checks2_fp();
+ stop = get_cycle();
+ printf("fp division x2: %" PRcycle " cycles\n", stop-start);
+}
diff --git a/test/monniaux/division/cycles.h b/test/monniaux/division/cycles.h
new file mode 120000
index 00000000..84e54d21
--- /dev/null
+++ b/test/monniaux/division/cycles.h
@@ -0,0 +1 @@
+../cycles.h \ No newline at end of file