aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/division/compare_timings.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/monniaux/division/compare_timings.c')
-rw-r--r--test/monniaux/division/compare_timings.c67
1 files changed, 67 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);
+}