2007-06-02 H.J. Lu <hongjiu.lu@intel.com>
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / sse4_2-popcnt.h
blobce06ba1b8d02efcaa8daaeb97d6703a3feda52e5
1 #include "sse4_2-check.h"
3 #include <nmmintrin.h>
5 #define NUM 1024
7 static int
8 compute_popcnt (TYPE v)
10 int ret;
11 int i;
13 ret = 0;
14 for (i = 0; i < sizeof(v) * 8; i++)
15 if ((v & ((TYPE)1 << (TYPE) i)))
16 ret++;
18 return ret;
21 static void
22 sse4_2_test (void)
24 int i;
25 TYPE vals[NUM];
26 TYPE res;
28 for (i = 0; i < NUM; i++)
30 vals[i] = rand ();
31 if (sizeof (TYPE) > 4)
32 vals[i] |= (TYPE)rand() << (TYPE)(sizeof (TYPE) * 4);
35 for (i=0; i < NUM; i++)
37 res = POPCNT (vals[i]);
38 if (res != compute_popcnt (vals[i]))
39 abort ();