#include #include #include #include using namespace std; #include "MOA.h" #include int main(int argc, char **argv) { int print; int simd; int bytes; int i; uint16_t *buf1; __m128i a, b, x, *c; /* usage: odd_shorts_time bytes SIMD(Y|N|none) seed print(Y|N) */ if (argc != 5 || (strcmp(argv[2], "Y") != 0 && strcmp(argv[2], "N") != 0 && strcmp(argv[2], "none") != 0)) { fprintf(stderr, "usage: odd_shorts_time bytes SIMD(Y|N|none) seed print(Y|N)\n"); exit(1); } /* Set the variables from the command line */ bytes = atoi(argv[1]); if (bytes % 16 != 0) { fprintf(stderr, "bytes mod 16 must = 0\n"); exit(1); } simd = argv[2][0]; print = (argv[4][0] == 'Y'); MOA_Seed(atoi(argv[3])); /* Allocate the buffer. */ buf1 = (uint16_t *) malloc(bytes); /* Use MOA.c to fill buf1 and buf2 with random bytes */ MOA_Fill_Random_Region (buf1, bytes); if (print) { for (i = 0; i < bytes/2; i++) { printf(" %04x", buf1[i]); if (i % 8 == 7) printf("\n"); } printf("\n"); } /* This lets you access the buffer a SIMD vector. */ c = (__m128i *) buf1; /* Use SIMD to isolate the odd shorts. */ if (simd == 'Y') { for (i = 0; i < bytes; i += 16) { b = *c; x = _mm_set1_epi16(1); a = _mm_and_si128(x, b); x = _mm_setzero_si128(); a = _mm_sub_epi16(x, a); b = _mm_and_si128(a, b); *c = b; c++; } /* Use regular code to isolate the odd shorts. */ } else if (simd == 'N') { for (i = 0; i < bytes/2; i++) { if (buf1[i] % 2 == 0) buf1[i] = 0; } } /* Print everything out. */ if (print) { for (i = 0; i < bytes/2; i++) { printf(" %04x", buf1[i]); if (i % 8 == 7) printf("\n"); } } return 0; }