#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; }