PR target/80969 - Fix ICE with -mabi=ms -mavx512f, reduce wasted space when realignin...
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / avx512bw-vpackuswb-2.c
blobca31d8e26a4e0604ad0f77f0a751b548757b6dd9
1 /* { dg-do run } */
2 /* { dg-options "-O2 -mavx512bw" } */
3 /* { dg-require-effective-target avx512bw } */
5 #define AVX512BW
6 #include "avx512f-helper.h"
8 #define DST_SIZE (AVX512F_LEN / 8)
9 #define SRC_SIZE (AVX512F_LEN / 16)
11 #include "limits.h"
13 #include "avx512f-mask-type.h"
15 static unsigned char
16 EVAL(short_to_uchar, AVX512F_LEN,) (short iVal)
18 unsigned char sVal;
20 if (iVal < 0)
21 sVal = 0;
22 else if (iVal > UCHAR_MAX)
23 sVal = UCHAR_MAX;
24 else
25 sVal = iVal;
27 return sVal;
30 void
31 CALC (short *src1, short *src2, unsigned char *dst)
33 int i;
34 short *ptr;
36 for (i = 0; i < DST_SIZE; i++)
38 ptr = (i / 8) % 2 ? src2 : src1;
39 dst[i] = EVAL(short_to_uchar, AVX512F_LEN,) (ptr[i % 8 + (i / 16) * 8]);
43 void
44 TEST (void)
46 UNION_TYPE (AVX512F_LEN, i_w) s1, s2;
47 UNION_TYPE (AVX512F_LEN, i_b) res1, res2, res3;
48 MASK_TYPE mask = MASK_VALUE;
49 unsigned char dst_ref[DST_SIZE];
50 int i;
52 for (i = 0; i < DST_SIZE; i++)
53 res2.a[i] = DEFAULT_VALUE;
55 for (i = 0; i < SRC_SIZE; i++)
57 s1.a[i] = i + 10;
58 s2.a[i] = i + 15;
61 res1.x = INTRINSIC (_packus_epi16) (s1.x, s2.x);
62 res2.x = INTRINSIC (_mask_packus_epi16) (res2.x, mask, s1.x, s2.x);
63 res3.x = INTRINSIC (_maskz_packus_epi16) (mask, s1.x, s2.x);
65 CALC (s1.a, s2.a, dst_ref);
67 if (UNION_CHECK (AVX512F_LEN, i_b) (res1, dst_ref))
68 abort ();
70 MASK_MERGE (i_b) (dst_ref, mask, DST_SIZE);
71 if (UNION_CHECK (AVX512F_LEN, i_b) (res2, dst_ref))
72 abort ();
74 MASK_ZERO (i_b) (dst_ref, mask, DST_SIZE);
75 if (UNION_CHECK (AVX512F_LEN, i_b) (res3, dst_ref))
76 abort ();