2016-12-21 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / sse4_1-ptest-1.c
blob8b57a21114d9a573ab60a9692d7af57a85a141e2
1 /* { dg-do run } */
2 /* { dg-require-effective-target sse4 } */
3 /* { dg-options "-O2 -msse4.1" } */
5 #ifndef CHECK_H
6 #define CHECK_H "sse4_1-check.h"
7 #endif
9 #ifndef TEST
10 #define TEST sse4_1_test
11 #endif
13 #include CHECK_H
15 #include <smmintrin.h>
17 static int
18 make_ptestz (__m128i m, __m128i v)
20 union
22 __m128i x;
23 unsigned char c[16];
24 } val, mask;
25 int i, z;
27 mask.x = m;
28 val.x = v;
30 z = 1;
31 for (i = 0; i < 16; i++)
32 if ((mask.c[i] & val.c[i]))
34 z = 0;
35 break;
37 return z;
40 static int
41 make_ptestc (__m128i m, __m128i v)
43 union
45 __m128i x;
46 unsigned char c[16];
47 } val, mask;
48 int i, c;
50 mask.x = m;
51 val.x = v;
53 c = 1;
54 for (i = 0; i < 16; i++)
55 if ((val.c[i] & ~mask.c[i]))
57 c = 0;
58 break;
60 return c;
63 static void
64 TEST (void)
66 union
68 __m128i x;
69 unsigned int i[4];
70 } val[4];
71 int i, j, l;
72 int res[32];
74 val[0].i[0] = 0x11111111;
75 val[0].i[1] = 0x00000000;
76 val[0].i[2] = 0x00000000;
77 val[0].i[3] = 0x11111111;
79 val[1].i[0] = 0x00000000;
80 val[1].i[1] = 0x11111111;
81 val[1].i[2] = 0x11111111;
82 val[1].i[3] = 0x00000000;
84 val[2].i[0] = 0;
85 val[2].i[1] = 0;
86 val[2].i[2] = 0;
87 val[2].i[3] = 0;
89 val[3].i[0] = 0xffffffff;
90 val[3].i[1] = 0xffffffff;
91 val[3].i[2] = 0xffffffff;
92 val[3].i[3] = 0xffffffff;
94 l = 0;
95 for(i = 0; i < 4; i++)
96 for(j = 0; j < 4; j++)
98 res[l++] = _mm_testz_si128 (val[j].x, val[i].x);
99 res[l++] = _mm_testc_si128 (val[j].x, val[i].x);
102 l = 0;
103 for(i = 0; i < 4; i++)
104 for(j = 0; j < 4; j++)
106 if (res[l++] != make_ptestz (val[j].x, val[i].x))
107 abort ();
108 if (res[l++] != make_ptestc (val[j].x, val[i].x))
109 abort ();
112 if (res[2] != _mm_testz_si128 (val[1].x, val[0].x))
113 abort ();
115 if (res[3] != _mm_testc_si128 (val[1].x, val[0].x))
116 abort ();