aboutsummaryrefslogtreecommitdiff
path: root/SingleSource/UnitTests/Vector/AVX512F/op2_xyz_int.c
blob: b96ff8b5ea44d1de0fc8ec2eedb43bd70c028d93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273

/*
 * Test 128 and 256-bit two operand integer intrinsics,
 * with masked and zero-masked forms, by comparing
 * their output with the corresponding 512-bit intrinsic.
 * Here we check for _mm512_[mask|maskz]_[and|andnot|or|xor|add|max|min|mul|sub]
 * intrinsics
 */

#include "m512_test_util.h"
#include <stdio.h>

V512 i8_src1;
V512 i8_src2;
V512 i16_src1;
V512 i16_src2;
V512 i32_src1;
V512 i32_src2;
V512 i64_src1;
V512 i64_src2;

void NOINLINE init() {
  volatile int i;

  for (i = 0; i < 64; i++) {
    i8_src1.s8[i] = i;
    i8_src2.s8[i] = (i & 1) ? i : -i;
  }

  for (i = 0; i < 32; i++) {
    i16_src1.s16[i] = i;
    i16_src2.s16[i] = (i & 1) ? i : -i;
  }

  for (i = 0; i < 16; i++) {
    i32_src1.s32[i] = i;
    i32_src2.s32[i] = (i & 1) ? i : -i;
  }

  for (i = 0; i < 8; i++) {
    i64_src1.s64[i] = i;
    i64_src2.s64[i] = (i & 1) ? i : -i;
  }
}

/*
 * Use "soft update" between tests to make compiler think src was updated.
 * Prevents PRE'ing a load of src, thus allowing ciscization.
 * Also prevents PRE'ing intrinsic operations, ensuring we
 * execute the intended instructions.
 */
volatile int vol0 = 0;
#define soft_v512_update(var) (var).xmmi[vol0] = (var).xmmi[vol0]

/*
 * Generate a function that tests a packed int64 intrinsic
 * by implementing the XMM, YMM and ZMM versions, and comparing
 * the XMM and YMM results with the low part of the ZMM result.
 *
 * We test regular, masked and zero masked forms.
 *
 * Use GEN_I64_UNIFORM when the core intrinsic name is the same
 * for all vector lengths, e.g. "add_epi64".  Otherwise use
 * GEN_I64 to list the different names, e.g. "and_si128" and "and_si256".
 */

#define GEN_I64_UNIFORM(oper) GEN_I64(oper, oper, oper, oper, oper)

#define GEN_I64(test_name, oper_epi64, oper_xmm, oper_ymm, oper_zmm)           \
  void NOINLINE do_##test_name() {                                             \
    V512 xmm_res, ymm_res, zmm_res;                                            \
    __mmask8 k8 = 0x5a;                                                        \
                                                                               \
    /* Non-masked. */                                                          \
                                                                               \
    soft_v512_update(i64_src2);                                                \
    zmm_res.zmmi = _mm512_##oper_zmm(i64_src1.zmmi, i64_src2.zmmi);            \
                                                                               \
    /* Masked. */                                                              \
                                                                               \
    zmm_res.zmmi = _mm512_setzero_epi32();                                     \
    ymm_res = zmm_res;                                                         \
    xmm_res = zmm_res;                                                         \
                                                                               \
    soft_v512_update(i64_src2);                                                \
    zmm_res.zmmi = _mm512_mask_##oper_epi64(zmm_res.zmmi, k8, i64_src1.zmmi,   \
                                            i64_src2.zmmi);                    \
                                                                               \
    /* Zero-masked. */                                                         \
                                                                               \
    zmm_res.zmmi = _mm512_set1_epi64(1);                                       \
    ymm_res = zmm_res;                                                         \
    xmm_res = zmm_res;                                                         \
                                                                               \
    soft_v512_update(i64_src2);                                                \
    zmm_res.zmmi =                                                             \
        _mm512_maskz_##oper_epi64(k8, i64_src1.zmmi, i64_src2.zmmi);           \
  }

#define GEN_I32_UNIFORM(oper) GEN_I32(oper, oper, oper, oper, oper)

#define GEN_I32(test_name, oper_epi32, oper_xmm, oper_ymm, oper_zmm)           \
  void NOINLINE do_##test_name() {                                             \
    V512 xmm_res, ymm_res, zmm_res;                                            \
    __mmask16 k16 = 0x7feb;                                                    \
    __mmask8 k8 = (__mmask8)k16;                                               \
                                                                               \
    /* Non-masked. */                                                          \
                                                                               \
    soft_v512_update(i32_src2);                                                \
    zmm_res.zmmi = _mm512_##oper_zmm(i32_src1.zmmi, i32_src2.zmmi);            \
                                                                               \
    /* Masked. */                                                              \
                                                                               \
    zmm_res.zmmi = _mm512_setzero_epi32();                                     \
    ymm_res = zmm_res;                                                         \
    xmm_res = zmm_res;                                                         \
                                                                               \
    soft_v512_update(i32_src2);                                                \
    zmm_res.zmmi = _mm512_mask_##oper_epi32(zmm_res.zmmi, k16, i32_src1.zmmi,  \
                                            i32_src2.zmmi);                    \
                                                                               \
    /* Zero-masked. */                                                         \
                                                                               \
    zmm_res.zmmi = _mm512_set1_epi32(1.0);                                     \
    ymm_res = zmm_res;                                                         \
    xmm_res = zmm_res;                                                         \
                                                                               \
    soft_v512_update(i32_src2);                                                \
    zmm_res.zmmi =                                                             \
        _mm512_maskz_##oper_epi32(k16, i32_src1.zmmi, i32_src2.zmmi);          \
  }

#define GEN_I16_UNIFORM(oper) GEN_I16(oper, oper, oper, oper, oper)

#define GEN_I16(test_name, oper_epi16, oper_xmm, oper_ymm, oper_zmm)           \
  void NOINLINE do_##test_name() {                                             \
    V512 xmm_res, ymm_res, zmm_res;                                            \
    __mmask32 k32 = 0x7febeb7f;                                                \
    __mmask16 k16 = (__mmask16)k32;                                            \
    __mmask8 k8 = (__mmask8)k16;                                               \
                                                                               \
    /* Non-masked. */                                                          \
                                                                               \
    soft_v512_update(i16_src2);                                                \
    zmm_res.zmmi = _mm512_##oper_zmm(i16_src1.zmmi, i16_src2.zmmi);            \
                                                                               \
    /* Masked. */                                                              \
                                                                               \
    zmm_res.zmmi = _mm512_setzero_epi32();                                     \
    ymm_res = zmm_res;                                                         \
    xmm_res = zmm_res;                                                         \
                                                                               \
    soft_v512_update(i16_src2);                                                \
    zmm_res.zmmi = _mm512_mask_##oper_epi16(zmm_res.zmmi, k32, i16_src1.zmmi,  \
                                            i16_src2.zmmi);                    \
                                                                               \
    /* Zero-masked. */                                                         \
                                                                               \
    zmm_res.zmmi = _mm512_set1_epi32(1.0);                                     \
    ymm_res = zmm_res;                                                         \
    xmm_res = zmm_res;                                                         \
                                                                               \
    soft_v512_update(i16_src2);                                                \
    zmm_res.zmmi =                                                             \
        _mm512_maskz_##oper_epi16(k32, i16_src1.zmmi, i16_src2.zmmi);          \
  }

#define GEN_I8_UNIFORM(oper) GEN_I8(oper, oper, oper, oper, oper)

#define GEN_I8(test_name, oper_epi8, oper_xmm, oper_ymm, oper_zmm)             \
  void NOINLINE do_##test_name() {                                             \
    V512 xmm_res, ymm_res, zmm_res;                                            \
    __mmask64 k64 = 0xa55a7febeb7f5aa5U;                                       \
    __mmask32 k32 = (__mmask32)k64;                                            \
    __mmask16 k16 = (__mmask16)k32;                                            \
                                                                               \
    /* Non-masked. */                                                          \
                                                                               \
    soft_v512_update(i8_src2);                                                 \
    zmm_res.zmmi = _mm512_##oper_zmm(i8_src1.zmmi, i8_src2.zmmi);              \
                                                                               \
    /* Masked. */                                                              \
                                                                               \
    zmm_res.zmmi = _mm512_setzero_epi32();                                     \
    ymm_res = zmm_res;                                                         \
    xmm_res = zmm_res;                                                         \
                                                                               \
    soft_v512_update(i8_src2);                                                 \
    zmm_res.zmmi = _mm512_mask_##oper_epi8(zmm_res.zmmi, k64, i8_src1.zmmi,    \
                                           i8_src2.zmmi);                      \
                                                                               \
    /* Zero-masked. */                                                         \
                                                                               \
    zmm_res.zmmi = _mm512_set1_epi32(1.0);                                     \
    ymm_res = zmm_res;                                                         \
    xmm_res = zmm_res;                                                         \
                                                                               \
    soft_v512_update(i8_src2);                                                 \
    zmm_res.zmmi = _mm512_maskz_##oper_epi8(k64, i8_src1.zmmi, i8_src2.zmmi);  \
  }

GEN_I32(and_si512, and_epi32, and_si128, and_si256, and_si512)
GEN_I32(andnot_si512, andnot_epi32, andnot_si128, andnot_si256, andnot_si512)
GEN_I32(or_si512, or_epi32, or_si128, or_si256, or_si512)
GEN_I32(xor_si512, xor_epi32, xor_si128, xor_si256, xor_si512)

GEN_I64(and_epi64, and_epi64, and_si128, and_si256, and_epi64)
GEN_I64(andnot_epi64, andnot_epi64, andnot_si128, andnot_si256, andnot_epi64)
GEN_I64(or_epi64, or_epi64, or_si128, or_si256, or_epi64)
GEN_I64(xor_epi64, xor_epi64, xor_si128, xor_si256, xor_epi64)

GEN_I64_UNIFORM(add_epi64)
GEN_I64_UNIFORM(max_epi64)
GEN_I64_UNIFORM(max_epu64)
GEN_I64_UNIFORM(min_epi64)
GEN_I64_UNIFORM(min_epu64)
GEN_I64_UNIFORM(mul_epi32) /* Yes, these are really I64 vector elements. */
GEN_I64_UNIFORM(mul_epu32) /* Yes, these are really I64 vector elements. */

GEN_I32(and_epi32, and_epi32, and_si128, and_si256, and_epi32)
GEN_I32(andnot_epi32, andnot_epi32, andnot_si128, andnot_si256, andnot_epi32)
GEN_I32(or_epi32, or_epi32, or_si128, or_si256, or_epi32)
GEN_I32(xor_epi32, xor_epi32, xor_si128, xor_si256, xor_epi32)

GEN_I32_UNIFORM(add_epi32)
GEN_I32_UNIFORM(max_epi32)
GEN_I32_UNIFORM(max_epu32)
GEN_I32_UNIFORM(min_epi32)
GEN_I32_UNIFORM(min_epu32)
GEN_I32_UNIFORM(sub_epi32)

int main() {
  init();

  do_and_si512();
  do_andnot_si512();
  do_or_si512();
  do_xor_si512();

  do_and_epi64();
  do_andnot_epi64();
  do_or_epi64();
  do_xor_epi64();

  do_add_epi64();
  do_max_epi64();
  do_max_epu64();
  do_min_epi64();
  do_min_epu64();
  do_mul_epi32();
  do_mul_epu32();

  do_and_epi32();
  do_andnot_epi32();
  do_or_epi32();
  do_xor_epi32();

  do_add_epi32();
  do_max_epi32();
  do_max_epu32();
  do_min_epi32();
  do_min_epu32();
  do_sub_epi32();

  if (n_errs != 0) {
    printf("FAILED\n");
    return 1;
  }

  printf("PASSED\n");
  return 0;
}