summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testsuite/ctlz.c46
1 files changed, 19 insertions, 27 deletions
diff --git a/testsuite/ctlz.c b/testsuite/ctlz.c
index 6bd91ea..eb7c96b 100644
--- a/testsuite/ctlz.c
+++ b/testsuite/ctlz.c
@@ -6,44 +6,39 @@
#include "../alpha_mmintrin.h"
#define ITERATIONS 10000
+#define ARRAY_ELEMENTS 512
+#define ARRAY_SIZE (ARRAY_ELEMENTS * sizeof(uint64_t))
int main(int argc, char ** argv) {
- uint64_t a[512], b[512], c[512];
+ uint64_t a[ARRAY_ELEMENTS], b[ARRAY_ELEMENTS], c[ARRAY_ELEMENTS];
uint64_t l1, l2;
- uint64_t start, end, overhead;
- uint64_t cix_total = 0, noncix_total = 0;
+ struct timespec cix_start, cix_end;
+ double cix_t0, cix_t1, cix_total;
+ struct timespec noncix_start, noncix_end;
+ double noncix_t0, noncix_t1, noncix_total;
int i, j, count = 0;
- start = __rpcc();
- end = __rpcc();
- overhead = end - start;
-
srand(time(NULL));
- for (i = 0; i < 512; i++) {
+ for (i = 0; i < ARRAY_ELEMENTS; i++) {
a[i] = rand();
}
+ clock_gettime(CLOCK_MONOTONIC, &cix_start);
for (j = 0; j < ITERATIONS; j++) {
- start = __rpcc();
-
- for (i = 0; i < 512; i++) {
+ for (i = 0; i < ARRAY_ELEMENTS; i++) {
l1 = a[i];
l2 = 1 << (64 - __ctlz(l1));
b[i] = l2;
}
-
- end = __rpcc();
- cix_total += end - start - overhead;
- memset(b, 0, 4096);
}
+ clock_gettime(CLOCK_MONOTONIC, &cix_end);
+ clock_gettime(CLOCK_MONOTONIC, &noncix_start);
for (j = 0; j < ITERATIONS; j++) {
- start = __rpcc();
-
- for (i = 0; i < 512; i++) {
+ for (i = 0; i < ARRAY_ELEMENTS; i++) {
l1 = a[i];
while (l1 != 0) {
l1 >>= 1;
@@ -51,21 +46,18 @@ int main(int argc, char ** argv) {
}
l2 = 1 << count;
c[i] = l2;
- // printf("nextpow2 of %lu is %lu\n", i, l2);
count = 0;
}
-
- end = __rpcc();
- noncix_total += end - start - overhead;
- memset(c, 0, 4096);
}
+ clock_gettime(CLOCK_MONOTONIC, &noncix_end);
- noncix_total /= ITERATIONS;
- cix_total /= ITERATIONS;
+ cix_total = (double)((cix_end.tv_sec - cix_start.tv_sec) + ((cix_end.tv_nsec - cix_start.tv_nsec) / 1.0e9)) / ITERATIONS;
+ noncix_total = (double)((noncix_end.tv_sec - noncix_start.tv_sec) + ((noncix_end.tv_nsec - noncix_start.tv_nsec) / 1.0e9)) / ITERATIONS;
- if (memcmp(b, c, 4096) == 0) {
+ if (memcmp(b, c, ARRAY_SIZE) == 0) {
printf("%s:\n", argv[0]);
- printf(" CIX time: %9lu nanoseconds\n non-CIX time: %9lu nanoseconds\n", cix_total, noncix_total);
+ printf(" CIX time: %.9lf seconds\n non-CIX time: %.9lf seconds\n", cix_total, noncix_total);
+ printf(" Speed-up: %lf\n", noncix_total / cix_total);
} else {
puts("Final arrays are not equal. Something happened.");
}