blob: a82231ac0251f912f51c16e236b7c3b9c4d62fe5 [file] [log] [blame]
Damjan Marionc5766222018-04-16 00:18:34 +02001/*
2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef included_vector_avx512_h
17#define included_vector_avx512_h
18
19#include <vppinfra/clib.h>
20#include <x86intrin.h>
21
Damjan Mariona52e1662018-05-19 00:04:23 +020022/* *INDENT-OFF* */
Damjan Marionc5766222018-04-16 00:18:34 +020023#define foreach_avx512_vec512i \
24 _(i,8,64,epi8) _(i,16,32,epi16) _(i,32,16,epi32) _(i,64,8,epi64)
25#define foreach_avx512_vec512u \
26 _(u,8,64,epi8) _(u,16,32,epi16) _(u,32,16,epi32) _(u,64,8,epi64)
27#define foreach_avx512_vec512f \
28 _(f,32,8,ps) _(f,64,4,pd)
29
Damjan Mariona52e1662018-05-19 00:04:23 +020030/* splat, load_unaligned, store_unaligned, is_all_zero, is_equal,
Damjan Marion1cf9a162018-05-23 20:21:51 +020031 is_all_equal, is_zero_mask */
Damjan Marionc5766222018-04-16 00:18:34 +020032#define _(t, s, c, i) \
33static_always_inline t##s##x##c \
34t##s##x##c##_splat (t##s x) \
35{ return (t##s##x##c) _mm512_set1_##i (x); } \
36\
37static_always_inline t##s##x##c \
Zhiyong Yang0c7aa7a2020-03-28 08:40:25 +000038t##s##x##c##_load_aligned (void *p) \
39{ return (t##s##x##c) _mm512_load_si512 (p); } \
40\
41static_always_inline void \
42t##s##x##c##_store_aligned (t##s##x##c v, void *p) \
43{ _mm512_store_si512 ((__m512i *) p, (__m512i) v); } \
44\
45static_always_inline t##s##x##c \
Damjan Marionc5766222018-04-16 00:18:34 +020046t##s##x##c##_load_unaligned (void *p) \
47{ return (t##s##x##c) _mm512_loadu_si512 (p); } \
48\
49static_always_inline void \
50t##s##x##c##_store_unaligned (t##s##x##c v, void *p) \
51{ _mm512_storeu_si512 ((__m512i *) p, (__m512i) v); } \
52\
Damjan Mariona52e1662018-05-19 00:04:23 +020053static_always_inline int \
54t##s##x##c##_is_all_zero (t##s##x##c v) \
55{ return (_mm512_test_epi64_mask ((__m512i) v, (__m512i) v) == 0); } \
56\
57static_always_inline int \
58t##s##x##c##_is_equal (t##s##x##c a, t##s##x##c b) \
Damjan Marion14864772018-05-22 14:07:47 +020059{ return t##s##x##c##_is_all_zero (a ^ b); } \
Damjan Mariona52e1662018-05-19 00:04:23 +020060\
61static_always_inline int \
62t##s##x##c##_is_all_equal (t##s##x##c v, t##s x) \
63{ return t##s##x##c##_is_equal (v, t##s##x##c##_splat (x)); } \
Damjan Marion1cf9a162018-05-23 20:21:51 +020064\
65static_always_inline u##c \
66t##s##x##c##_is_zero_mask (t##s##x##c v) \
67{ return _mm512_test_##i##_mask ((__m512i) v, (__m512i) v); } \
Damjan Marion2cd8ad42019-04-17 16:05:54 +020068\
69static_always_inline t##s##x##c \
70t##s##x##c##_interleave_lo (t##s##x##c a, t##s##x##c b) \
71{ return (t##s##x##c) _mm512_unpacklo_##i ((__m512i) a, (__m512i) b); } \
72\
73static_always_inline t##s##x##c \
74t##s##x##c##_interleave_hi (t##s##x##c a, t##s##x##c b) \
75{ return (t##s##x##c) _mm512_unpackhi_##i ((__m512i) a, (__m512i) b); } \
Damjan Marion1cf9a162018-05-23 20:21:51 +020076
Damjan Marionc5766222018-04-16 00:18:34 +020077
78foreach_avx512_vec512i foreach_avx512_vec512u
79#undef _
Damjan Marion8c3f8a22018-05-17 21:12:13 +020080/* *INDENT-ON* */
81
82static_always_inline u32
83u16x32_msb_mask (u16x32 v)
84{
85 return (u32) _mm512_movepi16_mask ((__m512i) v);
86}
87
Damjan Marion7d14aad2021-05-05 19:31:41 +020088/* 512-bit packs */
89#define _(f, t, fn) \
90 always_inline t t##_pack (f lo, f hi) \
91 { \
92 return (t) fn ((__m512i) lo, (__m512i) hi); \
93 }
94
95_ (i16x32, i8x64, _mm512_packs_epi16)
96_ (i16x32, u8x64, _mm512_packus_epi16)
97_ (i32x16, i16x32, _mm512_packs_epi32)
98_ (i32x16, u16x32, _mm512_packus_epi32)
99#undef _
100
Damjan Marionc899dac2019-04-16 18:41:01 +0200101static_always_inline u32x16
102u32x16_byte_swap (u32x16 v)
103{
104 u8x64 swap = {
105 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12,
106 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12,
107 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12,
108 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12
109 };
110 return (u32x16) _mm512_shuffle_epi8 ((__m512i) v, (__m512i) swap);
111}
112
113static_always_inline u16x32
114u16x32_byte_swap (u16x32 v)
115{
116 u8x64 swap = {
117 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14,
118 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14,
119 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14,
120 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14
121 };
122 return (u16x32) _mm512_shuffle_epi8 ((__m512i) v, (__m512i) swap);
123}
124
Damjan Marion09aeee62021-04-20 21:28:45 +0200125#define _(f, t) \
126 static_always_inline t f##_extract_lo (f v) \
127 { \
128 return (t) _mm512_extracti64x4_epi64 ((__m512i) v, 0); \
129 } \
130 static_always_inline t f##_extract_hi (f v) \
131 { \
132 return (t) _mm512_extracti64x4_epi64 ((__m512i) v, 1); \
133 }
Damjan Marionc899dac2019-04-16 18:41:01 +0200134
Damjan Marion09aeee62021-04-20 21:28:45 +0200135_ (u64x8, u64x4)
136_ (u32x16, u32x8)
137_ (u16x32, u16x16)
138_ (u8x64, u8x32)
139#undef _
Damjan Marion627fb6a2020-02-16 13:07:13 +0100140
Damjan Marionc899dac2019-04-16 18:41:01 +0200141static_always_inline u32
142u32x16_min_scalar (u32x16 v)
143{
144 return u32x8_min_scalar (u32x8_min (u32x16_extract_lo (v),
145 u32x16_extract_hi (v)));
146}
147
Damjan Marion2cd8ad42019-04-17 16:05:54 +0200148static_always_inline u32x16
149u32x16_insert_lo (u32x16 r, u32x8 v)
150{
151 return (u32x16) _mm512_inserti64x4 ((__m512i) r, (__m256i) v, 0);
152}
153
154static_always_inline u32x16
155u32x16_insert_hi (u32x16 r, u32x8 v)
156{
157 return (u32x16) _mm512_inserti64x4 ((__m512i) r, (__m256i) v, 1);
158}
159
160static_always_inline u64x8
161u64x8_permute (u64x8 a, u64x8 b, u64x8 mask)
162{
163 return (u64x8) _mm512_permutex2var_epi64 ((__m512i) a, (__m512i) mask,
164 (__m512i) b);
165}
166
Damjan Marionc899dac2019-04-16 18:41:01 +0200167
168#define u32x16_ternary_logic(a, b, c, d) \
169 (u32x16) _mm512_ternarylogic_epi32 ((__m512i) a, (__m512i) b, (__m512i) c, d)
Damjan Marion4e083162019-04-12 17:44:35 +0200170
Damjan Marione84e9d72020-02-13 13:11:02 +0100171#define u8x64_insert_u8x16(a, b, n) \
172 (u8x64) _mm512_inserti64x2 ((__m512i) (a), (__m128i) (b), n)
173
174#define u8x64_extract_u8x16(a, n) \
175 (u8x16) _mm512_extracti64x2_epi64 ((__m512i) (a), n)
176
Damjan Marion627fb6a2020-02-16 13:07:13 +0100177#define u8x64_word_shift_left(a,n) (u8x64) _mm512_bslli_epi128((__m512i) a, n)
178#define u8x64_word_shift_right(a,n) (u8x64) _mm512_bsrli_epi128((__m512i) a, n)
179
Damjan Marionf75defa2020-02-13 18:14:06 +0100180static_always_inline u8x64
181u8x64_xor3 (u8x64 a, u8x64 b, u8x64 c)
182{
183 return (u8x64) _mm512_ternarylogic_epi32 ((__m512i) a, (__m512i) b,
184 (__m512i) c, 0x96);
185}
186
Damjan Marion47d8f5d2020-02-25 11:51:48 +0100187static_always_inline u8x64
188u8x64_reflect_u8x16 (u8x64 x)
189{
190 static const u8x64 mask = {
191 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
192 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
193 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
194 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
195 };
196 return (u8x64) _mm512_shuffle_epi8 ((__m512i) x, (__m512i) mask);
197}
198
199static_always_inline u8x64
Damjan Marion94dbf952020-07-15 20:18:39 +0200200u8x64_shuffle (u8x64 v, u8x64 m)
201{
202 return (u8x64) _mm512_shuffle_epi8 ((__m512i) v, (__m512i) m);
203}
204
205#define u8x64_align_right(a, b, imm) \
206 (u8x64) _mm512_alignr_epi8 ((__m512i) a, (__m512i) b, imm)
207
Damjan Marion4dc098f2021-09-22 15:28:29 +0200208#define u64x8_align_right(a, b, imm) \
209 (u64x8) _mm512_alignr_epi64 ((__m512i) a, (__m512i) b, imm)
210
Damjan Marion94dbf952020-07-15 20:18:39 +0200211static_always_inline u32
212u32x16_sum_elts (u32x16 sum16)
213{
214 u32x8 sum8;
215 sum16 += (u32x16) u8x64_align_right (sum16, sum16, 8);
216 sum16 += (u32x16) u8x64_align_right (sum16, sum16, 4);
217 sum8 = u32x16_extract_hi (sum16) + u32x16_extract_lo (sum16);
218 return sum8[0] + sum8[4];
219}
220
Damjan Marione9848312021-04-25 10:51:51 +0200221#define _(t, m, p, i, e) \
222 static_always_inline t t##_mask_load (t a, void *p, m mask) \
223 { \
224 return (t) p##_mask_loadu_##e ((i) a, mask, p); \
225 } \
226 static_always_inline t t##_mask_load_zero (void *p, m mask) \
227 { \
228 return (t) p##_maskz_loadu_##e (mask, p); \
229 } \
230 static_always_inline void t##_mask_store (t a, void *p, m mask) \
231 { \
232 p##_mask_storeu_##e (p, mask, (i) a); \
233 }
Damjan Marion47d8f5d2020-02-25 11:51:48 +0100234
Damjan Marione9848312021-04-25 10:51:51 +0200235_ (u8x64, u64, _mm512, __m512i, epi8)
236_ (u8x32, u32, _mm256, __m256i, epi8)
237_ (u8x16, u16, _mm, __m128i, epi8)
238_ (u16x32, u32, _mm512, __m512i, epi16)
239_ (u16x16, u16, _mm256, __m256i, epi16)
240_ (u16x8, u8, _mm, __m128i, epi16)
241_ (u32x16, u16, _mm512, __m512i, epi32)
242_ (u32x8, u8, _mm256, __m256i, epi32)
243_ (u32x4, u8, _mm, __m128i, epi32)
244_ (u64x8, u8, _mm512, __m512i, epi64)
245_ (u64x4, u8, _mm256, __m256i, epi64)
246_ (u64x2, u8, _mm, __m128i, epi64)
247#undef _
248
249#ifdef CLIB_HAVE_VEC512
250#define CLIB_HAVE_VEC512_MASK_LOAD_STORE
251#endif
252#ifdef CLIB_HAVE_VEC256
253#define CLIB_HAVE_VEC256_MASK_LOAD_STORE
254#endif
255#ifdef CLIB_HAVE_VEC128
256#define CLIB_HAVE_VEC128_MASK_LOAD_STORE
257#endif
Damjan Marion47d8f5d2020-02-25 11:51:48 +0100258
259static_always_inline u8x64
260u8x64_splat_u8x16 (u8x16 a)
261{
262 return (u8x64) _mm512_broadcast_i64x2 ((__m128i) a);
263}
264
265static_always_inline u32x16
266u32x16_splat_u32x4 (u32x4 a)
267{
268 return (u32x16) _mm512_broadcast_i64x2 ((__m128i) a);
269}
270
271static_always_inline u32x16
272u32x16_mask_blend (u32x16 a, u32x16 b, u16 mask)
273{
274 return (u32x16) _mm512_mask_blend_epi32 (mask, (__m512i) a, (__m512i) b);
275}
276
277static_always_inline u8x64
278u8x64_mask_blend (u8x64 a, u8x64 b, u64 mask)
279{
280 return (u8x64) _mm512_mask_blend_epi8 (mask, (__m512i) a, (__m512i) b);
281}
282
Damjan Marion09aeee62021-04-20 21:28:45 +0200283#define _(t, m, e, p, it) \
284 static_always_inline m t##_is_equal_mask (t a, t b) \
285 { \
286 return p##_cmpeq_##e##_mask ((it) a, (it) b); \
287 }
288_ (u8x16, u16, epu8, _mm, __m128i)
289_ (u16x8, u8, epu16, _mm, __m128i)
290_ (u32x4, u8, epu32, _mm, __m128i)
291_ (u64x2, u8, epu64, _mm, __m128i)
292
293_ (u8x32, u32, epu8, _mm256, __m256i)
294_ (u16x16, u16, epu16, _mm256, __m256i)
295_ (u32x8, u8, epu32, _mm256, __m256i)
296_ (u64x4, u8, epu64, _mm256, __m256i)
297
298_ (u8x64, u64, epu8, _mm512, __m512i)
299_ (u16x32, u32, epu16, _mm512, __m512i)
300_ (u32x16, u16, epu32, _mm512, __m512i)
301_ (u64x8, u8, epu64, _mm512, __m512i)
302#undef _
303
304#define _(f, t, fn, it) \
305 static_always_inline t t##_from_##f (f x) { return (t) fn ((it) x); }
306_ (u16x16, u32x16, _mm512_cvtepi16_epi32, __m256i)
307_ (u32x16, u16x16, _mm512_cvtusepi32_epi16, __m512i)
308_ (u32x8, u16x8, _mm256_cvtusepi32_epi16, __m256i)
Damjan Marion54208852021-04-21 15:25:47 +0200309_ (u32x8, u64x8, _mm512_cvtepu32_epi64, __m256i)
Damjan Marion09aeee62021-04-20 21:28:45 +0200310#undef _
311
Damjan Marione9848312021-04-25 10:51:51 +0200312#define _(vt, mt, p, it, epi) \
Damjan Marion09aeee62021-04-20 21:28:45 +0200313 static_always_inline vt vt##_compress (vt a, mt mask) \
314 { \
Damjan Marione9848312021-04-25 10:51:51 +0200315 return (vt) p##_maskz_compress_##epi (mask, (it) a); \
Damjan Marion09aeee62021-04-20 21:28:45 +0200316 } \
317 static_always_inline vt vt##_expand (vt a, mt mask) \
318 { \
Damjan Marione9848312021-04-25 10:51:51 +0200319 return (vt) p##_maskz_expand_##epi (mask, (it) a); \
320 } \
321 static_always_inline void vt##_compress_store (vt v, mt mask, void *p) \
322 { \
323 p##_mask_compressstoreu_##epi (p, mask, (it) v); \
Damjan Marion09aeee62021-04-20 21:28:45 +0200324 }
325
Damjan Marione9848312021-04-25 10:51:51 +0200326_ (u64x8, u8, _mm512, __m512i, epi64)
327_ (u32x16, u16, _mm512, __m512i, epi32)
328_ (u64x4, u8, _mm256, __m256i, epi64)
329_ (u32x8, u8, _mm256, __m256i, epi32)
330_ (u64x2, u8, _mm, __m128i, epi64)
331_ (u32x4, u8, _mm, __m128i, epi32)
Damjan Marion09aeee62021-04-20 21:28:45 +0200332#ifdef __AVX512VBMI2__
Damjan Marione9848312021-04-25 10:51:51 +0200333_ (u16x32, u32, _mm512, __m512i, epi16)
334_ (u8x64, u64, _mm512, __m512i, epi8)
335_ (u16x16, u16, _mm256, __m256i, epi16)
336_ (u8x32, u32, _mm256, __m256i, epi8)
337_ (u16x8, u8, _mm, __m128i, epi16)
338_ (u8x16, u16, _mm, __m128i, epi8)
Damjan Marion09aeee62021-04-20 21:28:45 +0200339#endif
340#undef _
341
Damjan Marionef0bac72021-04-22 18:08:28 +0200342#ifdef CLIB_HAVE_VEC256
Damjan Marion09aeee62021-04-20 21:28:45 +0200343#define CLIB_HAVE_VEC256_COMPRESS
Mohsin Kazmi7da9b5b2021-08-27 18:57:16 +0200344#ifdef __AVX512VBMI2__
345#define CLIB_HAVE_VEC256_COMPRESS_U8_U16
346#endif
347
Damjan Marionef0bac72021-04-22 18:08:28 +0200348#endif
349#ifdef CLIB_HAVE_VEC512
Damjan Marion09aeee62021-04-20 21:28:45 +0200350#define CLIB_HAVE_VEC512_COMPRESS
Mohsin Kazmi7da9b5b2021-08-27 18:57:16 +0200351#ifdef __AVX512VBMI2__
352#define CLIB_HAVE_VEC512_COMPRESS_U8_U16
353#endif
354
Damjan Marionef0bac72021-04-22 18:08:28 +0200355#endif
Damjan Marion09aeee62021-04-20 21:28:45 +0200356
357#ifndef __AVX512VBMI2__
358static_always_inline u16x16
359u16x16_compress (u16x16 v, u16 mask)
Zhiyong Yang5e524172020-07-08 20:28:36 +0000360{
Damjan Marion09aeee62021-04-20 21:28:45 +0200361 return u16x16_from_u32x16 (u32x16_compress (u32x16_from_u16x16 (v), mask));
Zhiyong Yang5e524172020-07-08 20:28:36 +0000362}
363
Damjan Marion09aeee62021-04-20 21:28:45 +0200364static_always_inline u16x8
365u16x8_compress (u16x8 v, u8 mask)
366{
367 return u16x8_from_u32x8 (u32x8_compress (u32x8_from_u16x8 (v), mask));
368}
369#endif
370
Damjan Marion4e083162019-04-12 17:44:35 +0200371static_always_inline void
372u32x16_transpose (u32x16 m[16])
373{
374 __m512i r[16], a, b, c, d, x, y;
375
376 /* *INDENT-OFF* */
377 __m512i pm1 = (__m512i) (u64x8) { 0, 1, 8, 9, 4, 5, 12, 13};
378 __m512i pm2 = (__m512i) (u64x8) { 2, 3, 10, 11, 6, 7, 14, 15};
379 __m512i pm3 = (__m512i) (u64x8) { 0, 1, 2, 3, 8, 9, 10, 11};
380 __m512i pm4 = (__m512i) (u64x8) { 4, 5, 6, 7, 12, 13, 14, 15};
381 /* *INDENT-ON* */
382
383 r[0] = _mm512_unpacklo_epi32 ((__m512i) m[0], (__m512i) m[1]);
384 r[1] = _mm512_unpacklo_epi32 ((__m512i) m[2], (__m512i) m[3]);
385 r[2] = _mm512_unpacklo_epi32 ((__m512i) m[4], (__m512i) m[5]);
386 r[3] = _mm512_unpacklo_epi32 ((__m512i) m[6], (__m512i) m[7]);
387 r[4] = _mm512_unpacklo_epi32 ((__m512i) m[8], (__m512i) m[9]);
388 r[5] = _mm512_unpacklo_epi32 ((__m512i) m[10], (__m512i) m[11]);
389 r[6] = _mm512_unpacklo_epi32 ((__m512i) m[12], (__m512i) m[13]);
390 r[7] = _mm512_unpacklo_epi32 ((__m512i) m[14], (__m512i) m[15]);
391
392 r[8] = _mm512_unpackhi_epi32 ((__m512i) m[0], (__m512i) m[1]);
393 r[9] = _mm512_unpackhi_epi32 ((__m512i) m[2], (__m512i) m[3]);
394 r[10] = _mm512_unpackhi_epi32 ((__m512i) m[4], (__m512i) m[5]);
395 r[11] = _mm512_unpackhi_epi32 ((__m512i) m[6], (__m512i) m[7]);
396 r[12] = _mm512_unpackhi_epi32 ((__m512i) m[8], (__m512i) m[9]);
397 r[13] = _mm512_unpackhi_epi32 ((__m512i) m[10], (__m512i) m[11]);
398 r[14] = _mm512_unpackhi_epi32 ((__m512i) m[12], (__m512i) m[13]);
399 r[15] = _mm512_unpackhi_epi32 ((__m512i) m[14], (__m512i) m[15]);
400
401 a = _mm512_unpacklo_epi64 (r[0], r[1]);
402 b = _mm512_unpacklo_epi64 (r[2], r[3]);
403 c = _mm512_unpacklo_epi64 (r[4], r[5]);
404 d = _mm512_unpacklo_epi64 (r[6], r[7]);
405 x = _mm512_permutex2var_epi64 (a, pm1, b);
406 y = _mm512_permutex2var_epi64 (c, pm1, d);
407 m[0] = (u32x16) _mm512_permutex2var_epi64 (x, pm3, y);
408 m[8] = (u32x16) _mm512_permutex2var_epi64 (x, pm4, y);
409 x = _mm512_permutex2var_epi64 (a, pm2, b);
410 y = _mm512_permutex2var_epi64 (c, pm2, d);
411 m[4] = (u32x16) _mm512_permutex2var_epi64 (x, pm3, y);
412 m[12] = (u32x16) _mm512_permutex2var_epi64 (x, pm4, y);
413
414 a = _mm512_unpacklo_epi64 (r[8], r[9]);
415 b = _mm512_unpacklo_epi64 (r[10], r[11]);
416 c = _mm512_unpacklo_epi64 (r[12], r[13]);
417 d = _mm512_unpacklo_epi64 (r[14], r[15]);
418 x = _mm512_permutex2var_epi64 (a, pm1, b);
419 y = _mm512_permutex2var_epi64 (c, pm1, d);
420 m[2] = (u32x16) _mm512_permutex2var_epi64 (x, pm3, y);
421 m[10] = (u32x16) _mm512_permutex2var_epi64 (x, pm4, y);
422 x = _mm512_permutex2var_epi64 (a, pm2, b);
423 y = _mm512_permutex2var_epi64 (c, pm2, d);
424 m[6] = (u32x16) _mm512_permutex2var_epi64 (x, pm3, y);
425 m[14] = (u32x16) _mm512_permutex2var_epi64 (x, pm4, y);
426
427 a = _mm512_unpackhi_epi64 (r[0], r[1]);
428 b = _mm512_unpackhi_epi64 (r[2], r[3]);
429 c = _mm512_unpackhi_epi64 (r[4], r[5]);
430 d = _mm512_unpackhi_epi64 (r[6], r[7]);
431 x = _mm512_permutex2var_epi64 (a, pm1, b);
432 y = _mm512_permutex2var_epi64 (c, pm1, d);
433 m[1] = (u32x16) _mm512_permutex2var_epi64 (x, pm3, y);
434 m[9] = (u32x16) _mm512_permutex2var_epi64 (x, pm4, y);
435 x = _mm512_permutex2var_epi64 (a, pm2, b);
436 y = _mm512_permutex2var_epi64 (c, pm2, d);
437 m[5] = (u32x16) _mm512_permutex2var_epi64 (x, pm3, y);
438 m[13] = (u32x16) _mm512_permutex2var_epi64 (x, pm4, y);
439
440 a = _mm512_unpackhi_epi64 (r[8], r[9]);
441 b = _mm512_unpackhi_epi64 (r[10], r[11]);
442 c = _mm512_unpackhi_epi64 (r[12], r[13]);
443 d = _mm512_unpackhi_epi64 (r[14], r[15]);
444 x = _mm512_permutex2var_epi64 (a, pm1, b);
445 y = _mm512_permutex2var_epi64 (c, pm1, d);
446 m[3] = (u32x16) _mm512_permutex2var_epi64 (x, pm3, y);
447 m[11] = (u32x16) _mm512_permutex2var_epi64 (x, pm4, y);
448 x = _mm512_permutex2var_epi64 (a, pm2, b);
449 y = _mm512_permutex2var_epi64 (c, pm2, d);
450 m[7] = (u32x16) _mm512_permutex2var_epi64 (x, pm3, y);
451 m[15] = (u32x16) _mm512_permutex2var_epi64 (x, pm4, y);
452}
453
454
455
456static_always_inline void
457u64x8_transpose (u64x8 m[8])
458{
459 __m512i r[8], x, y;
460
461 /* *INDENT-OFF* */
462 __m512i pm1 = (__m512i) (u64x8) { 0, 1, 8, 9, 4, 5, 12, 13};
463 __m512i pm2 = (__m512i) (u64x8) { 2, 3, 10, 11, 6, 7, 14, 15};
464 __m512i pm3 = (__m512i) (u64x8) { 0, 1, 2, 3, 8, 9, 10, 11};
465 __m512i pm4 = (__m512i) (u64x8) { 4, 5, 6, 7, 12, 13, 14, 15};
466 /* *INDENT-ON* */
467
468 r[0] = _mm512_unpacklo_epi64 ((__m512i) m[0], (__m512i) m[1]);
469 r[1] = _mm512_unpacklo_epi64 ((__m512i) m[2], (__m512i) m[3]);
470 r[2] = _mm512_unpacklo_epi64 ((__m512i) m[4], (__m512i) m[5]);
471 r[3] = _mm512_unpacklo_epi64 ((__m512i) m[6], (__m512i) m[7]);
472 r[4] = _mm512_unpackhi_epi64 ((__m512i) m[0], (__m512i) m[1]);
473 r[5] = _mm512_unpackhi_epi64 ((__m512i) m[2], (__m512i) m[3]);
474 r[6] = _mm512_unpackhi_epi64 ((__m512i) m[4], (__m512i) m[5]);
475 r[7] = _mm512_unpackhi_epi64 ((__m512i) m[6], (__m512i) m[7]);
476
477 x = _mm512_permutex2var_epi64 (r[0], pm1, r[1]);
478 y = _mm512_permutex2var_epi64 (r[2], pm1, r[3]);
479 m[0] = (u64x8) _mm512_permutex2var_epi64 (x, pm3, y);
480 m[4] = (u64x8) _mm512_permutex2var_epi64 (x, pm4, y);
481 x = _mm512_permutex2var_epi64 (r[0], pm2, r[1]);
482 y = _mm512_permutex2var_epi64 (r[2], pm2, r[3]);
483 m[2] = (u64x8) _mm512_permutex2var_epi64 (x, pm3, y);
484 m[6] = (u64x8) _mm512_permutex2var_epi64 (x, pm4, y);
485
486 x = _mm512_permutex2var_epi64 (r[4], pm1, r[5]);
487 y = _mm512_permutex2var_epi64 (r[6], pm1, r[7]);
488 m[1] = (u64x8) _mm512_permutex2var_epi64 (x, pm3, y);
489 m[5] = (u64x8) _mm512_permutex2var_epi64 (x, pm4, y);
490 x = _mm512_permutex2var_epi64 (r[4], pm2, r[5]);
491 y = _mm512_permutex2var_epi64 (r[6], pm2, r[7]);
492 m[3] = (u64x8) _mm512_permutex2var_epi64 (x, pm3, y);
493 m[7] = (u64x8) _mm512_permutex2var_epi64 (x, pm4, y);
494}
495
Damjan Marion8c3f8a22018-05-17 21:12:13 +0200496#endif /* included_vector_avx512_h */
Damjan Marionc5766222018-04-16 00:18:34 +0200497/*
498 * fd.io coding-style-patch-verification: ON
499 *
500 * Local Variables:
501 * eval: (c-set-style "gnu")
502 * End:
503 */