1 /* { dg-do run } */
2 /* { dg-options "-O2 -mavx512bitalg -mavx512f -mavx512bw" } */
3 /* { dg-require-effective-target avx512bitalg } */
4
5 #define AVX512BITALG
6 #define SIZE (AVX512F_LEN / 8)
7
8 #include "avx512f-helper.h"
9 #include "avx512f-mask-type.h"
10
11 #define TYPE unsigned long long
12
13 unsigned char
CALC(TYPE a,TYPE b)14 CALC (TYPE a, TYPE b)
15 {
16 unsigned char res = 0;
17 for (int i = 0; i < 8; i++)
18 {
19 unsigned char m = (b >> (64 - ((i+1)*8))) & 0x3F;
20 unsigned char bit = (a >> m) & 1;
21 res |= (bit << (8 - i - 1));
22 }
23
24 return res;
25 }
26
27 void
TEST(void)28 TEST (void)
29 {
30 UNION_TYPE (AVX512F_LEN, i_q) src1, src2;
31 MASK_TYPE mask = MASK_VALUE;
32 TYPE res1, res2;
33 TYPE res_ref = 0;
34
35 src1.x = INTRINSIC (_set1_epi8) (0x13);
36 src2.x = INTRINSIC (_set1_epi8) (0x17);
37
38 src1.a[0] = 0xff;
39 src2.a[0] = 0xff;
40
41 for (int i = 0; i < SIZE/8; i++)
42 {
43 unsigned long long bit = CALC (src1.a[i], src2.a[i]);
44 res_ref |= ((unsigned long long)(CALC (src1.a[i], src2.a[i])) << (i*8));
45 }
46
47 res1 = INTRINSIC (_bitshuffle_epi64_mask) (src1.x, src2.x);
48 res2 = INTRINSIC (_mask_bitshuffle_epi64_mask) (mask, src1.x, src2.x);
49
50 if (res1 != res_ref)
51 abort();
52
53 for (int i = 0; i < SIZE; i++)
54 {
55 if (!((mask >> i) & 1))
56 res_ref &= ~((unsigned long long)1 <<i);
57 }
58 if (res2 != res_ref)
59 abort();
60 }
61