diff options
author | Matt Turner <mattst88@gmail.com> | 2008-05-12 19:55:21 +0000 |
---|---|---|
committer | Matt Turner <mattst88@gmail.com> | 2008-05-12 19:55:21 +0000 |
commit | 5117e7e647d2f380a883661571e441ce603220a9 (patch) | |
tree | 329caea1a1f50e4cd6d72fee8157fc80de378d3e /testsuite/ctlz.c | |
parent | f5c37567f57b4f8281a43a23a1458a5f34312662 (diff) |
import testsuite
git-svn-id: svn://mattst88.com/svn/alpha_mmintrin/trunk@3 f7d56953-e76f-4e43-a77e-20d50f6c004e
Diffstat (limited to 'testsuite/ctlz.c')
-rw-r--r-- | testsuite/ctlz.c | 74 |
1 files changed, 74 insertions, 0 deletions
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 <stdio.h> +#include <stdint.h> +#include <time.h> +#include <string.h> + +#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; +} |