1 /* { dg-do run } */
2 /* { dg-options "-mavx2 -O2" } */
3 /* { dg-require-effective-target avx2 } */
4 
5 #include "avx2-check.h"
6 
7 static unsigned char
short_to_ubyte(short iVal)8 short_to_ubyte (short iVal)
9 {
10   unsigned char sVal;
11 
12   if (iVal < 0)
13     sVal = 0;
14   else if (iVal > 255)
15     sVal = 255;
16   else
17     sVal = iVal;
18 
19   return sVal;
20 }
21 
22 void static
avx2_test(void)23 avx2_test (void)
24 {
25   union256i_w s1, s2;
26   union256i_b u;
27   char e[32];
28   int i;
29 
30   s1.x = _mm256_set_epi16 (1, 2, 3, 4, 6500, 20, 30, 90,
31 			   88, 44, 33, 22, 11, 98, 78, -1000);
32 
33   s2.x = _mm256_set_epi16 (88, 44, 33, 22, 11, 98, 76, -650,
34 			   1, 2, 3, 4, 6500, 20, 30, 90);
35 
36   u.x = _mm256_packus_epi16 (s1.x, s2.x);
37 
38   for (i = 0; i < 8; i++)
39     {
40       e[i] = short_to_ubyte (s1.a[i]);
41       e[i + 8] = short_to_ubyte (s2.a[i]);
42       e[i + 16] = short_to_ubyte (s1.a[i + 8]);
43       e[i + 24] = short_to_ubyte (s2.a[i + 8]);
44     }
45 
46   if (check_union256i_b (u, e))
47     abort ();
48 }
49