1/* { dg-do run } */
2/* { dg-options "-O2 -mavx512bw" } */
3/* { dg-require-effective-target avx512bw } */
4
5#define AVX512BW
6#include "avx512f-helper.h"
7
8#include <math.h>
9#define SIZE (AVX512F_LEN / 16)
10#include "avx512f-mask-type.h"
11
12#if AVX512F_LEN == 512
13#undef CMP
14#define CMP(imm, rel)					\
15    dst_ref = 0;					\
16    for (i = 0; i < 32; i++)				\
17    {							\
18      dst_ref = ((rel) << i) | dst_ref;			\
19    }							\
20    source1.x = _mm512_loadu_si512 (s1);		\
21    source2.x = _mm512_loadu_si512 (s2);		\
22    dst1 = _mm512_cmp_epu16_mask (source1.x, source2.x, imm);\
23    dst2 = _mm512_mask_cmp_epu16_mask (mask, source1.x, source2.x, imm);\
24    if (dst_ref != dst1) abort();			\
25    if ((mask & dst_ref) != dst2) abort();
26#endif
27
28#if AVX512F_LEN == 256
29#undef CMP
30#define CMP(imm, rel)					\
31    dst_ref = 0;					\
32    for (i = 0; i < 16; i++)				\
33    {							\
34      dst_ref = ((rel) << i) | dst_ref;			\
35    }							\
36    source1.x = _mm256_loadu_si256 ((__m256i*)s1);	\
37    source2.x = _mm256_loadu_si256 ((__m256i*)s2);	\
38    dst1 = _mm256_cmp_epu16_mask (source1.x, source2.x, imm);\
39    dst2 = _mm256_mask_cmp_epu16_mask (mask, source1.x, source2.x, imm);\
40    if (dst_ref != dst1) abort();			\
41    if ((mask & dst_ref) != dst2) abort();
42#endif
43
44#if AVX512F_LEN == 128
45#undef CMP
46#define CMP(imm, rel)					\
47    dst_ref = 0;					\
48    for (i = 0; i < 8; i++)				\
49    {							\
50      dst_ref = ((rel) << i) | dst_ref;			\
51    }							\
52    source1.x = _mm_loadu_si128 ((__m128i*)s1);		\
53    source2.x = _mm_loadu_si128 ((__m128i*)s2);		\
54    dst1 = _mm_cmp_epu16_mask (source1.x, source2.x, imm);\
55    dst2 = _mm_mask_cmp_epu16_mask (mask, source1.x, source2.x, imm);\
56    if (dst_ref != dst1) abort();			\
57    if ((mask & dst_ref) != dst2) abort();
58#endif
59
60void
61TEST ()
62{
63    unsigned short s1[32] = {2134,  6678,  453, 54646,
64			    231, 5674,  111, 23241,
65			    12314,  145,  671, 7575,
66			    23455,  166, 5321, 5673,
67			    2134,  6678,  453, 54646,
68			    231, 5674,  111, 23241,
69			    12314,  145,  671, 7575,
70			    23455,  166, 5321, 5673};
71    unsigned short s2[32] = {41124, 6678, 8653,   856,
72			    231, 4646,  111,   124,
73			    2745, 4567, 3676,   123,
74			    714, 3589, 5683,  5673,
75			    41124, 6678, 8653,   856,
76			    231, 4646,  111,   124,
77			    2745, 4567, 3676,   123,
78			    714, 3589, 5683,  5673};
79    UNION_TYPE (AVX512F_LEN, i_w) source1, source2;
80    MASK_TYPE dst1, dst2, dst_ref;
81    MASK_TYPE mask = MASK_VALUE;
82    int i;
83
84    CMP(0x00, s1[i] == s2[i]);
85    CMP(0x01, s1[i] < s2[i]);
86    CMP(0x02, s1[i] <= s2[i]);
87    CMP(0x03, 0);
88    CMP(0x04, s1[i] != s2[i]);
89    CMP(0x05, s1[i] >= s2[i]);
90    CMP(0x06, s1[i] > s2[i]);
91    CMP(0x07, 1);
92}
93