From 5117e7e647d2f380a883661571e441ce603220a9 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Mon, 12 May 2008 19:55:21 +0000 Subject: import testsuite git-svn-id: svn://mattst88.com/svn/alpha_mmintrin/trunk@3 f7d56953-e76f-4e43-a77e-20d50f6c004e --- testsuite/ctlz.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 testsuite/ctlz.c (limited to 'testsuite/ctlz.c') diff --git a/testsuite/ctlz.c b/testsuite/ctlz.c new file mode 100644 index 0000000..1fc0cf1 --- /dev/null +++ b/testsuite/ctlz.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include + +#include "../alpha_mmintrin.h" + +#define ITERATIONS 10000 + +int main(int argc, char ** argv) { + uint64_t a[512], b[512], c[512]; + uint64_t l1, l2; + uint64_t start, end, overhead; + uint64_t cix_total = 0, noncix_total = 0; + int i, j, count = 0; + + start = __rpcc(); + end = __rpcc(); + overhead = end - start; + + srand(time(NULL)); + + for (i = 0; i < 512; i++) { + a[i] = rand(); + } + + for (j = 0; j < ITERATIONS; j++) { + start = __rpcc(); + + for (i = 0; i < 512; i++) { + l1 = a[i]; + + l2 = 1 << (64 - __ctlz(l1)); + + b[i] = l2; + } + + end = __rpcc(); + cix_total += end - start - overhead; + memset(b, 4096, 0); + } + + for (j = 0; j < ITERATIONS; j++) { + start = __rpcc(); + + for (i = 0; i < 512; i++) { + l1 = a[i]; + while (l1 != 0) { + l1 >>= 1; + count += 1; + } + 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, 4096, 0); + } + + noncix_total /= ITERATIONS; + cix_total /= ITERATIONS; + + if (memcmp(b, c, 4096) == 0) { + printf("%s:\n", argv[0]); + printf(" CIX time: %9lu nanoseconds\n non-CIX time: %9lu nanoseconds\n", cix_total, noncix_total); + } else { + puts("Final arrays are not equal. Something happened."); + } + + return 0; +} -- cgit v1.2.3