2 /* { dg-options "-O2 -msse2" } */
3 /* { dg-require-effective-target sse2 } */
5 #include "sse2-check.h"
15 unsigned short int t
[8];
16 unsigned long long u
[2];
20 void sse2_tests (void) __attribute__((noinline
));
21 void dump128_16 (char *, char *, vecInLong
);
22 void dump128_32 (char *, char *, vecInLong
);
23 void dump128_64 (char *, char *, vecInLong
);
24 void dump128_128 (char *, char *, vecInLong
);
25 int check (const char *, const char *[]);
28 char comparison
[8000];
29 static int errors
= 0;
31 vecInLong a128
, b128
, c128
, d128
, e128
, f128
;
32 __m128i m128_16
, m128_32
, s128
, m128_64
, m128_128
;
33 __m64 m64_16
, s64
, m64_32
, m64_64
;
35 const char *reference_sse2
[] = {
36 "_mm_srai_epi16 0012 0012 0012 0012 0012 0012 0012 0012 \n",
37 "_mm_sra_epi16 0012 0012 0012 0012 0012 0012 0012 0012 \n",
38 "_mm_srai_epi32 00123456 00123456 00123456 00123456 \n",
39 "_mm_sra_epi32 00123456 00123456 00123456 00123456 \n",
40 "_mm_srli_epi16 0012 0012 0012 0012 0012 0012 0012 0012 \n",
41 "_mm_srl_epi16 0012 0012 0012 0012 0012 0012 0012 0012 \n",
42 "_mm_srli_epi32 00123456 00123456 00123456 00123456 \n",
43 "_mm_srl_epi32 00123456 00123456 00123456 00123456 \n",
44 "_mm_srli_epi64 00123456789abcde 00123456789abcde \n",
45 "_mm_srl_epi64 00123456789abcde 00123456789abcde \n",
46 "_mm_srli_si128 (byte shift) 00000000ffeeddccbbaa998877665544\n",
47 "_mm_slli_epi16 1230 1230 1230 1230 1230 1230 1230 1230 \n",
48 "_mm_sll_epi16 1230 1230 1230 1230 1230 1230 1230 1230 \n",
49 "_mm_slli_epi32 12345670 12345670 12345670 12345670 \n",
50 "_mm_sll_epi32 12345670 12345670 12345670 12345670 \n",
51 "_mm_slli_epi64 123456789abcdef0 123456789abcdef0 \n",
52 "_mm_sll_epi64 123456789abcdef0 123456789abcdef0 \n",
53 "_mm_sll_si128 (byte shift) bbaa9988776655443322110000000000\n",
54 "_mm_shuffle_epi32 ffeeddcc bbaa9988 77665544 33221100 \n",
55 "_mm_shuffelo_epi16 7766 5544 3322 1100 9988 bbaa ddcc ffee \n",
56 "_mm_shuffehi_epi16 1100 3322 5544 7766 ffee ddcc bbaa 9988 \n",
63 a128
.s
[0] = 0x01234567;
64 a128
.s
[1] = 0x01234567;
65 a128
.s
[2] = 0x01234567;
66 a128
.s
[3] = 0x01234567;
70 d128
.u
[0] = 0x0123456789abcdefULL
;
71 d128
.u
[1] = 0x0123456789abcdefULL
;
75 /* This is the 128-bit constant 0x00112233445566778899aabbccddeeff,
76 expressed as two little-endian 64-bit words. */
77 e128
.u
[0] = 0x7766554433221100ULL
;
78 e128
.u
[1] = 0xffeeddccbbaa9988ULL
;
101 check (buf
, reference_sse2
);
103 printf ("sse2 testing:\n");
105 printf ("\ncomparison:\n");
114 void __attribute__((noinline
))
118 c128
.v
= _mm_srai_epi16 (m128_16
, SHIFT
);
119 dump128_16 (buf
, "_mm_srai_epi16", c128
);
120 c128
.v
= _mm_sra_epi16 (m128_16
, s128
);
121 dump128_16 (buf
, "_mm_sra_epi16", c128
);
124 c128
.v
= _mm_srai_epi32 (m128_32
, SHIFT
);
125 dump128_32 (buf
, "_mm_srai_epi32", c128
);
126 c128
.v
= _mm_sra_epi32 (m128_32
, s128
);
127 dump128_32 (buf
, "_mm_sra_epi32", c128
);
130 c128
.v
= _mm_srli_epi16 (m128_16
, SHIFT
);
131 dump128_16 (buf
, "_mm_srli_epi16", c128
);
132 c128
.v
= _mm_srl_epi16 (m128_16
, s128
);
133 dump128_16 (buf
, "_mm_srl_epi16", c128
);
136 c128
.v
= _mm_srli_epi32 (m128_32
, SHIFT
);
137 dump128_32 (buf
, "_mm_srli_epi32", c128
);
138 c128
.v
= _mm_srl_epi32 (m128_32
, s128
);
139 dump128_32 (buf
, "_mm_srl_epi32", c128
);
142 c128
.v
= _mm_srli_epi64 (m128_64
, SHIFT
);
143 dump128_64 (buf
, "_mm_srli_epi64", c128
);
144 c128
.v
= _mm_srl_epi64 (m128_64
, s128
);
145 dump128_64 (buf
, "_mm_srl_epi64", c128
);
148 c128
.v
= _mm_srli_si128 (m128_128
, SHIFT
);
149 dump128_128 (buf
, "_mm_srli_si128 (byte shift) ", c128
);
152 c128
.v
= _mm_slli_epi16 (m128_16
, SHIFT
);
153 dump128_16 (buf
, "_mm_slli_epi16", c128
);
154 c128
.v
= _mm_sll_epi16 (m128_16
, s128
);
155 dump128_16 (buf
, "_mm_sll_epi16", c128
);
158 c128
.v
= _mm_slli_epi32 (m128_32
, SHIFT
);
159 dump128_32 (buf
, "_mm_slli_epi32", c128
);
160 c128
.v
= _mm_sll_epi32 (m128_32
, s128
);
161 dump128_32 (buf
, "_mm_sll_epi32", c128
);
164 c128
.v
= _mm_slli_epi64 (m128_64
, SHIFT
);
165 dump128_64 (buf
, "_mm_slli_epi64", c128
);
166 c128
.v
= _mm_sll_epi64 (m128_64
, s128
);
167 dump128_64 (buf
, "_mm_sll_epi64", c128
);
170 c128
.v
= _mm_slli_si128 (m128_128
, SHIFT
);
171 dump128_128 (buf
, "_mm_sll_si128 (byte shift)", c128
);
173 /* Shuffle constant 0x1b == 0b_00_01_10_11, e.g. swap words: ABCD => DCBA. */
176 c128
.v
= _mm_shuffle_epi32 (m128_128
, 0x1b);
177 dump128_32 (buf
, "_mm_shuffle_epi32", c128
);
180 c128
.v
= _mm_shufflelo_epi16 (m128_128
, 0x1b);
181 dump128_16 (buf
, "_mm_shuffelo_epi16", c128
);
184 c128
.v
= _mm_shufflehi_epi16 (m128_128
, 0x1b);
185 dump128_16 (buf
, "_mm_shuffehi_epi16", c128
);
189 dump128_16 (char *buf
, char *name
, vecInLong x
)
192 char *p
= buf
+ strlen (buf
);
194 sprintf (p
, "%s ", name
);
199 sprintf (p
, "%4.4x ", x
.t
[i
]);
206 dump128_32 (char *buf
, char *name
, vecInLong x
)
209 char *p
= buf
+ strlen (buf
);
211 sprintf (p
, "%s ", name
);
216 sprintf (p
, "%8.8x ", x
.s
[i
]);
223 dump128_64 (char *buf
, char *name
, vecInLong x
)
226 char *p
= buf
+ strlen (buf
);
228 sprintf (p
, "%s ", name
);
233 #if defined(_WIN32) && !defined(__CYGWIN__)
234 sprintf (p
, "%16.16I64x ", x
.u
[i
]);
236 sprintf (p
, "%16.16llx ", x
.u
[i
]);
244 dump128_128 (char *buf
, char *name
, vecInLong x
)
247 char *p
= buf
+ strlen (buf
);
249 sprintf (p
, "%s ", name
);
252 for (i
=15; i
>=0; i
--)
254 /* This is cheating; we don't have a 128-bit int format code.
255 Running the loop backwards to compensate for the
256 little-endian layout. */
257 sprintf (p
, "%2.2x", x
.c
[i
]);
264 check (const char *input
, const char *reference
[])
266 int broken
, i
, j
, len
;
271 p_comparison
= &comparison
[0];
274 for (i
= 0; *reference
[i
] != '\0'; i
++)
277 len
= strlen (reference
[i
]);
278 for (j
= 0; j
< len
; j
++)
280 /* Ignore the terminating NUL characters at the end of every string in 'reference[]'. */
281 if (!broken
&& *p_input
!= reference
[i
][j
])
283 *p_comparison
= '\0';
284 strcat (p_comparison
, " >>> ");
285 p_comparison
+= strlen (p_comparison
);
289 *p_comparison
= *p_input
;
295 *p_comparison
= '\0';
296 strcat (p_comparison
, "expected:\n");
297 strcat (p_comparison
, reference
[i
]);
298 p_comparison
+= strlen (p_comparison
);
301 *p_comparison
= '\0';
302 strcat (p_comparison
, new_errors
? "failure\n\n" : "O.K.\n\n") ;
303 errors
+= new_errors
;