Initial support for AVX-512{VL,BW,DQ}
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / avx512bw-vpackusdw-2.c
blob2083b59a837c4fa3b935589d1c4c68dd03274ed5
1 /* { dg-do run } */
2 /* { dg-options "-O2 -mavx512bw -DAVX512BW" } */
3 /* { dg-require-effective-target avx512bw } */
5 #include "avx512f-helper.h"
7 #define DST_SIZE (AVX512F_LEN / 16)
8 #define SRC_SIZE (AVX512F_LEN / 32)
10 #include "limits.h"
12 #include "avx512f-mask-type.h"
14 static unsigned short
15 EVAL(int_to_ushort, AVX512F_LEN,) (int iVal)
17 unsigned short sVal;
19 if (iVal < 0)
20 sVal = 0;
21 else if (iVal > USHRT_MAX)
22 sVal = USHRT_MAX;
23 else
24 sVal = iVal;
26 return sVal;
29 void
30 CALC (int *src1, int *src2, unsigned short *dst)
32 int i;
33 int *ptr;
35 for (i = 0; i < DST_SIZE; i++)
37 ptr = (i / 4) % 2 ? src2 : src1;
38 dst[i] = EVAL(int_to_ushort, AVX512F_LEN,) (ptr[i % 4 + (i / 8) * 4]);
42 void
43 TEST (void)
45 UNION_TYPE (AVX512F_LEN, i_d) s1, s2;
46 UNION_TYPE (AVX512F_LEN, i_w) res1, res2, res3;
47 MASK_TYPE mask = MASK_VALUE;
48 unsigned short dst_ref[DST_SIZE];
49 int i;
51 for (i = 0; i < DST_SIZE; i++)
52 res2.a[i] = DEFAULT_VALUE;
54 for (i = 0; i < SRC_SIZE; i++)
56 s1.a[i] = i + 10;
57 s2.a[i] = i + 15;
60 res1.x = INTRINSIC (_packus_epi32) (s1.x, s2.x);
61 res2.x = INTRINSIC (_mask_packus_epi32) (res2.x, mask, s1.x, s2.x);
62 res3.x = INTRINSIC (_maskz_packus_epi32) (mask, s1.x, s2.x);
64 CALC (s1.a, s2.a, dst_ref);
66 if (UNION_CHECK (AVX512F_LEN, i_w) (res1, dst_ref))
67 abort ();
69 MASK_MERGE (i_w) (dst_ref, mask, DST_SIZE);
70 if (UNION_CHECK (AVX512F_LEN, i_w) (res2, dst_ref))
71 abort ();
73 MASK_ZERO (i_w) (dst_ref, mask, DST_SIZE);
74 if (UNION_CHECK (AVX512F_LEN, i_w) (res3, dst_ref))
75 abort ();