#include #include #include #include #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[ARRAY_ELEMENTS], b[ARRAY_ELEMENTS], c[ARRAY_ELEMENTS]; uint64_t l1, l2; 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; srand(time(NULL)); for (i = 0; i < ARRAY_ELEMENTS; i++) { a[i] = rand(); } clock_gettime(CLOCK_MONOTONIC, &cix_start); for (j = 0; j < ITERATIONS; j++) { for (i = 0; i < ARRAY_ELEMENTS; i++) { l1 = a[i]; l2 = 1 << (64 - __ctlz(l1)); b[i] = l2; } } clock_gettime(CLOCK_MONOTONIC, &cix_end); clock_gettime(CLOCK_MONOTONIC, &noncix_start); for (j = 0; j < ITERATIONS; j++) { for (i = 0; i < ARRAY_ELEMENTS; i++) { l1 = a[i]; while (l1 != 0) { l1 >>= 1; count += 1; } l2 = 1 << count; c[i] = l2; count = 0; } } clock_gettime(CLOCK_MONOTONIC, &noncix_end); 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, ARRAY_SIZE) == 0) { printf("%s:\n", argv[0]); 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."); } return 0; }