1 /* This file is used to reduce a number of runtime tests for AVX512F
2    and AVX512VL instructions.  Idea is to create one file per instruction -
3    avx512f-insn-2.c - using defines from this file instead of intrinsic
4    name, vector length etc.  Then dg-options are set with appropriate
5    -Dwhatever options in that .c file producing tests for specific
6    length.  */
7 
8 #ifndef AVX512F_HELPER_INCLUDED
9 #define AVX512F_HELPER_INCLUDED
10 
11 #include "avx512-check.h"
12 
13 /* Macros expansion.  */
14 #define CONCAT(a,b,c) a ## b ## c
15 #define EVAL(a,b,c) CONCAT(a,b,c)
16 
17 /* Value to be written into destination.
18    We have one value for all types so it must be small enough
19    to fit into signed char.  */
20 #ifndef DEFAULT_VALUE
21 #define DEFAULT_VALUE 117
22 #endif
23 
24 #define MAKE_MASK_MERGE(NAME, TYPE)				      \
25 static void							      \
26 __attribute__((noinline, unused))				      \
27 merge_masking_##NAME (TYPE *arr, unsigned long long mask, int size)   \
28 {								      \
29   int i;							      \
30   for (i = 0; i < size; i++)					      \
31     {								      \
32       arr[i] = (mask & (1LL << i)) ? arr[i] : DEFAULT_VALUE;	      \
33     }								      \
34 }
35 
36 MAKE_MASK_MERGE(i_b, char)
37 MAKE_MASK_MERGE(i_w, short)
38 MAKE_MASK_MERGE(i_d, int)
39 MAKE_MASK_MERGE(i_q, long long)
40 MAKE_MASK_MERGE(, float)
41 MAKE_MASK_MERGE(d, double)
42 MAKE_MASK_MERGE(i_ub, unsigned char)
43 MAKE_MASK_MERGE(i_uw, unsigned short)
44 MAKE_MASK_MERGE(i_ud, unsigned int)
45 MAKE_MASK_MERGE(i_uq, unsigned long long)
46 
47 #define MASK_MERGE(TYPE) merge_masking_##TYPE
48 
49 #define MAKE_MASK_ZERO(NAME, TYPE)				      \
50 static void							      \
51 __attribute__((noinline, unused))				      \
52 zero_masking_##NAME (TYPE *arr, unsigned long long mask, int size)    \
53 {								      \
54   int i;							      \
55   for (i = 0; i < size; i++)					      \
56     {								      \
57       arr[i] = (mask & (1LL << i)) ? arr[i] : 0;		      \
58     }								      \
59 }
60 
61 MAKE_MASK_ZERO(i_b, char)
62 MAKE_MASK_ZERO(i_w, short)
63 MAKE_MASK_ZERO(i_d, int)
64 MAKE_MASK_ZERO(i_q, long long)
65 MAKE_MASK_ZERO(, float)
66 MAKE_MASK_ZERO(d, double)
67 MAKE_MASK_ZERO(i_ub, unsigned char)
68 MAKE_MASK_ZERO(i_uw, unsigned short)
69 MAKE_MASK_ZERO(i_ud, unsigned int)
70 MAKE_MASK_ZERO(i_uq, unsigned long long)
71 
72 
73 #define MASK_ZERO(TYPE) zero_masking_##TYPE
74 
75 
76 /* Unions used for testing (for example union512d, union256d etc.).  */
77 #define UNION_TYPE(SIZE, NAME) EVAL(union, SIZE, NAME)
78 /* Corresponding union check.  */
79 #define UNION_CHECK(SIZE, NAME) EVAL(check_union, SIZE, NAME)
80 /* Corresponding fp union check.  */
81 #define UNION_FP_CHECK(SIZE, NAME) EVAL(check_fp_union, SIZE, NAME)
82 /* Corresponding rough union check.  */
83 #define UNION_ROUGH_CHECK(SIZE, NAME) \
84   EVAL(check_rough_union, SIZE, NAME)
85 /* Function which tests intrinsic for given length.  */
86 #define TEST EVAL(test_, AVX512F_LEN,)
87 /* Function which calculates result.  */
88 #define CALC EVAL(calc_, AVX512F_LEN,)
89 
90 #ifndef AVX512VL
91 #define AVX512F_LEN 512
92 #define AVX512F_LEN_HALF 256
93 #endif
94 
95 #endif /* AVX512F_HELPER_INCLUDED */
96 
97 /* Intrinsic being tested. It has different deffinitions,
98    depending on AVX512F_LEN, so it's outside include guards
99    and in undefed away to silence warnings.  */
100 #if defined INTRINSIC
101 #undef INTRINSIC
102 #endif
103 
104 #if AVX512F_LEN != 128
105 #define INTRINSIC(NAME) EVAL(_mm, AVX512F_LEN, NAME)
106 #else
107 #define INTRINSIC(NAME) _mm ## NAME
108 #endif
109