Skip to main content

core/stdarch/crates/core_arch/src/x86/
avx2.rs

1//! Advanced Vector Extensions 2 (AVX)
2//!
3//! AVX2 expands most AVX commands to 256-bit wide vector registers and
4//! adds [FMA](https://en.wikipedia.org/wiki/Fused_multiply-accumulate).
5//!
6//! The references are:
7//!
8//! - [Intel 64 and IA-32 Architectures Software Developer's Manual Volume 2:
9//!   Instruction Set Reference, A-Z][intel64_ref].
10//! - [AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and
11//!   System Instructions][amd64_ref].
12//!
13//! Wikipedia's [AVX][wiki_avx] and [FMA][wiki_fma] pages provide a quick
14//! overview of the instructions available.
15//!
16//! [intel64_ref]: https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf
17//! [amd64_ref]: https://docs.amd.com/v/u/en-US/24594_3.37
18//! [wiki_avx]: https://en.wikipedia.org/wiki/Advanced_Vector_Extensions
19//! [wiki_fma]: https://en.wikipedia.org/wiki/Fused_multiply-accumulate
20
21use crate::core_arch::{simd::*, x86::*};
22use crate::intrinsics::simd::*;
23
24#[cfg(test)]
25use stdarch_test::assert_instr;
26
27/// Computes the absolute values of packed 32-bit integers in `a`.
28///
29/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_abs_epi32)
30#[inline]
31#[target_feature(enable = "avx2")]
32#[cfg_attr(test, assert_instr(vpabsd))]
33#[stable(feature = "simd_x86", since = "1.27.0")]
34#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
35pub const fn _mm256_abs_epi32(a: __m256i) -> __m256i {
36    unsafe {
37        let a = a.as_i32x8();
38        let r = simd_select::<m32x8, _>(simd_lt(a, i32x8::ZERO), simd_neg(a), a);
39        transmute(r)
40    }
41}
42
43/// Computes the absolute values of packed 16-bit integers in `a`.
44///
45/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_abs_epi16)
46#[inline]
47#[target_feature(enable = "avx2")]
48#[cfg_attr(test, assert_instr(vpabsw))]
49#[stable(feature = "simd_x86", since = "1.27.0")]
50#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
51pub const fn _mm256_abs_epi16(a: __m256i) -> __m256i {
52    unsafe {
53        let a = a.as_i16x16();
54        let r = simd_select::<m16x16, _>(simd_lt(a, i16x16::ZERO), simd_neg(a), a);
55        transmute(r)
56    }
57}
58
59/// Computes the absolute values of packed 8-bit integers in `a`.
60///
61/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_abs_epi8)
62#[inline]
63#[target_feature(enable = "avx2")]
64#[cfg_attr(test, assert_instr(vpabsb))]
65#[stable(feature = "simd_x86", since = "1.27.0")]
66#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
67pub const fn _mm256_abs_epi8(a: __m256i) -> __m256i {
68    unsafe {
69        let a = a.as_i8x32();
70        let r = simd_select::<m8x32, _>(simd_lt(a, i8x32::ZERO), simd_neg(a), a);
71        transmute(r)
72    }
73}
74
75/// Adds packed 64-bit integers in `a` and `b`.
76///
77/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_add_epi64)
78#[inline]
79#[target_feature(enable = "avx2")]
80#[cfg_attr(test, assert_instr(vpaddq))]
81#[stable(feature = "simd_x86", since = "1.27.0")]
82#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
83pub const fn _mm256_add_epi64(a: __m256i, b: __m256i) -> __m256i {
84    unsafe { transmute(simd_add(a.as_i64x4(), b.as_i64x4())) }
85}
86
87/// Adds packed 32-bit integers in `a` and `b`.
88///
89/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_add_epi32)
90#[inline]
91#[target_feature(enable = "avx2")]
92#[cfg_attr(test, assert_instr(vpaddd))]
93#[stable(feature = "simd_x86", since = "1.27.0")]
94#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
95pub const fn _mm256_add_epi32(a: __m256i, b: __m256i) -> __m256i {
96    unsafe { transmute(simd_add(a.as_i32x8(), b.as_i32x8())) }
97}
98
99/// Adds packed 16-bit integers in `a` and `b`.
100///
101/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_add_epi16)
102#[inline]
103#[target_feature(enable = "avx2")]
104#[cfg_attr(test, assert_instr(vpaddw))]
105#[stable(feature = "simd_x86", since = "1.27.0")]
106#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
107pub const fn _mm256_add_epi16(a: __m256i, b: __m256i) -> __m256i {
108    unsafe { transmute(simd_add(a.as_i16x16(), b.as_i16x16())) }
109}
110
111/// Adds packed 8-bit integers in `a` and `b`.
112///
113/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_add_epi8)
114#[inline]
115#[target_feature(enable = "avx2")]
116#[cfg_attr(test, assert_instr(vpaddb))]
117#[stable(feature = "simd_x86", since = "1.27.0")]
118#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
119pub const fn _mm256_add_epi8(a: __m256i, b: __m256i) -> __m256i {
120    unsafe { transmute(simd_add(a.as_i8x32(), b.as_i8x32())) }
121}
122
123/// Adds packed 8-bit integers in `a` and `b` using saturation.
124///
125/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_adds_epi8)
126#[inline]
127#[target_feature(enable = "avx2")]
128#[cfg_attr(test, assert_instr(vpaddsb))]
129#[stable(feature = "simd_x86", since = "1.27.0")]
130#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
131pub const fn _mm256_adds_epi8(a: __m256i, b: __m256i) -> __m256i {
132    unsafe { transmute(simd_saturating_add(a.as_i8x32(), b.as_i8x32())) }
133}
134
135/// Adds packed 16-bit integers in `a` and `b` using saturation.
136///
137/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_adds_epi16)
138#[inline]
139#[target_feature(enable = "avx2")]
140#[cfg_attr(test, assert_instr(vpaddsw))]
141#[stable(feature = "simd_x86", since = "1.27.0")]
142#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
143pub const fn _mm256_adds_epi16(a: __m256i, b: __m256i) -> __m256i {
144    unsafe { transmute(simd_saturating_add(a.as_i16x16(), b.as_i16x16())) }
145}
146
147/// Adds packed unsigned 8-bit integers in `a` and `b` using saturation.
148///
149/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_adds_epu8)
150#[inline]
151#[target_feature(enable = "avx2")]
152#[cfg_attr(test, assert_instr(vpaddusb))]
153#[stable(feature = "simd_x86", since = "1.27.0")]
154#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
155pub const fn _mm256_adds_epu8(a: __m256i, b: __m256i) -> __m256i {
156    unsafe { transmute(simd_saturating_add(a.as_u8x32(), b.as_u8x32())) }
157}
158
159/// Adds packed unsigned 16-bit integers in `a` and `b` using saturation.
160///
161/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_adds_epu16)
162#[inline]
163#[target_feature(enable = "avx2")]
164#[cfg_attr(test, assert_instr(vpaddusw))]
165#[stable(feature = "simd_x86", since = "1.27.0")]
166#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
167pub const fn _mm256_adds_epu16(a: __m256i, b: __m256i) -> __m256i {
168    unsafe { transmute(simd_saturating_add(a.as_u16x16(), b.as_u16x16())) }
169}
170
171/// Concatenates pairs of 16-byte blocks in `a` and `b` into a 32-byte temporary
172/// result, shifts the result right by `n` bytes, and returns the low 16 bytes.
173///
174/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_alignr_epi8)
175#[inline]
176#[target_feature(enable = "avx2")]
177#[cfg_attr(test, assert_instr(vpalignr, IMM8 = 7))]
178#[rustc_legacy_const_generics(2)]
179#[stable(feature = "simd_x86", since = "1.27.0")]
180#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
181pub const fn _mm256_alignr_epi8<const IMM8: i32>(a: __m256i, b: __m256i) -> __m256i {
182    static_assert_uimm_bits!(IMM8, 8);
183
184    // If palignr is shifting the pair of vectors more than the size of two
185    // lanes, emit zero.
186    if IMM8 >= 32 {
187        return _mm256_setzero_si256();
188    }
189    // If palignr is shifting the pair of input vectors more than one lane,
190    // but less than two lanes, convert to shifting in zeroes.
191    let (a, b) = if IMM8 > 16 {
192        (_mm256_setzero_si256(), a)
193    } else {
194        (a, b)
195    };
196    unsafe {
197        if IMM8 == 16 {
198            return transmute(a);
199        }
200    }
201    const fn mask(shift: u32, i: u32) -> u32 {
202        let shift = shift % 16;
203        let mod_i = i % 16;
204        if mod_i < (16 - shift) {
205            i + shift
206        } else {
207            i + 16 + shift
208        }
209    }
210
211    unsafe {
212        let r: i8x32 = simd_shuffle!(
213            b.as_i8x32(),
214            a.as_i8x32(),
215            [
216                mask(IMM8 as u32, 0),
217                mask(IMM8 as u32, 1),
218                mask(IMM8 as u32, 2),
219                mask(IMM8 as u32, 3),
220                mask(IMM8 as u32, 4),
221                mask(IMM8 as u32, 5),
222                mask(IMM8 as u32, 6),
223                mask(IMM8 as u32, 7),
224                mask(IMM8 as u32, 8),
225                mask(IMM8 as u32, 9),
226                mask(IMM8 as u32, 10),
227                mask(IMM8 as u32, 11),
228                mask(IMM8 as u32, 12),
229                mask(IMM8 as u32, 13),
230                mask(IMM8 as u32, 14),
231                mask(IMM8 as u32, 15),
232                mask(IMM8 as u32, 16),
233                mask(IMM8 as u32, 17),
234                mask(IMM8 as u32, 18),
235                mask(IMM8 as u32, 19),
236                mask(IMM8 as u32, 20),
237                mask(IMM8 as u32, 21),
238                mask(IMM8 as u32, 22),
239                mask(IMM8 as u32, 23),
240                mask(IMM8 as u32, 24),
241                mask(IMM8 as u32, 25),
242                mask(IMM8 as u32, 26),
243                mask(IMM8 as u32, 27),
244                mask(IMM8 as u32, 28),
245                mask(IMM8 as u32, 29),
246                mask(IMM8 as u32, 30),
247                mask(IMM8 as u32, 31),
248            ],
249        );
250        transmute(r)
251    }
252}
253
254/// Computes the bitwise AND of 256 bits (representing integer data)
255/// in `a` and `b`.
256///
257/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_and_si256)
258#[inline]
259#[target_feature(enable = "avx2")]
260#[cfg_attr(test, assert_instr(vandps))]
261#[stable(feature = "simd_x86", since = "1.27.0")]
262#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
263pub const fn _mm256_and_si256(a: __m256i, b: __m256i) -> __m256i {
264    unsafe { transmute(simd_and(a.as_i64x4(), b.as_i64x4())) }
265}
266
267/// Computes the bitwise NOT of 256 bits (representing integer data)
268/// in `a` and then AND with `b`.
269///
270/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_andnot_si256)
271#[inline]
272#[target_feature(enable = "avx2")]
273#[cfg_attr(test, assert_instr(vandnps))]
274#[stable(feature = "simd_x86", since = "1.27.0")]
275#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
276pub const fn _mm256_andnot_si256(a: __m256i, b: __m256i) -> __m256i {
277    unsafe {
278        let all_ones = _mm256_set1_epi8(-1);
279        transmute(simd_and(
280            simd_xor(a.as_i64x4(), all_ones.as_i64x4()),
281            b.as_i64x4(),
282        ))
283    }
284}
285
286/// Averages packed unsigned 16-bit integers in `a` and `b`.
287///
288/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_avg_epu16)
289#[inline]
290#[target_feature(enable = "avx2")]
291#[cfg_attr(test, assert_instr(vpavgw))]
292#[stable(feature = "simd_x86", since = "1.27.0")]
293#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
294pub const fn _mm256_avg_epu16(a: __m256i, b: __m256i) -> __m256i {
295    unsafe {
296        let a = simd_cast::<_, u32x16>(a.as_u16x16());
297        let b = simd_cast::<_, u32x16>(b.as_u16x16());
298        let r = simd_shr(simd_add(simd_add(a, b), u32x16::splat(1)), u32x16::splat(1));
299        transmute(simd_cast::<_, u16x16>(r))
300    }
301}
302
303/// Averages packed unsigned 8-bit integers in `a` and `b`.
304///
305/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_avg_epu8)
306#[inline]
307#[target_feature(enable = "avx2")]
308#[cfg_attr(test, assert_instr(vpavgb))]
309#[stable(feature = "simd_x86", since = "1.27.0")]
310#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
311pub const fn _mm256_avg_epu8(a: __m256i, b: __m256i) -> __m256i {
312    unsafe {
313        let a = simd_cast::<_, u16x32>(a.as_u8x32());
314        let b = simd_cast::<_, u16x32>(b.as_u8x32());
315        let r = simd_shr(simd_add(simd_add(a, b), u16x32::splat(1)), u16x32::splat(1));
316        transmute(simd_cast::<_, u8x32>(r))
317    }
318}
319
320/// Blends packed 32-bit integers from `a` and `b` using control mask `IMM4`.
321///
322/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_blend_epi32)
323#[inline]
324#[target_feature(enable = "avx2")]
325#[cfg_attr(test, assert_instr(vblendps, IMM4 = 9))]
326#[rustc_legacy_const_generics(2)]
327#[stable(feature = "simd_x86", since = "1.27.0")]
328#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
329pub const fn _mm_blend_epi32<const IMM4: i32>(a: __m128i, b: __m128i) -> __m128i {
330    static_assert_uimm_bits!(IMM4, 4);
331    unsafe {
332        let a = a.as_i32x4();
333        let b = b.as_i32x4();
334        let r: i32x4 = simd_shuffle!(
335            a,
336            b,
337            [
338                [0, 4, 0, 4][IMM4 as usize & 0b11],
339                [1, 1, 5, 5][IMM4 as usize & 0b11],
340                [2, 6, 2, 6][(IMM4 as usize >> 2) & 0b11],
341                [3, 3, 7, 7][(IMM4 as usize >> 2) & 0b11],
342            ],
343        );
344        transmute(r)
345    }
346}
347
348/// Blends packed 32-bit integers from `a` and `b` using control mask `IMM8`.
349///
350/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_blend_epi32)
351#[inline]
352#[target_feature(enable = "avx2")]
353#[cfg_attr(test, assert_instr(vblendps, IMM8 = 9))]
354#[rustc_legacy_const_generics(2)]
355#[stable(feature = "simd_x86", since = "1.27.0")]
356#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
357pub const fn _mm256_blend_epi32<const IMM8: i32>(a: __m256i, b: __m256i) -> __m256i {
358    static_assert_uimm_bits!(IMM8, 8);
359    unsafe {
360        let a = a.as_i32x8();
361        let b = b.as_i32x8();
362        let r: i32x8 = simd_shuffle!(
363            a,
364            b,
365            [
366                [0, 8, 0, 8][IMM8 as usize & 0b11],
367                [1, 1, 9, 9][IMM8 as usize & 0b11],
368                [2, 10, 2, 10][(IMM8 as usize >> 2) & 0b11],
369                [3, 3, 11, 11][(IMM8 as usize >> 2) & 0b11],
370                [4, 12, 4, 12][(IMM8 as usize >> 4) & 0b11],
371                [5, 5, 13, 13][(IMM8 as usize >> 4) & 0b11],
372                [6, 14, 6, 14][(IMM8 as usize >> 6) & 0b11],
373                [7, 7, 15, 15][(IMM8 as usize >> 6) & 0b11],
374            ],
375        );
376        transmute(r)
377    }
378}
379
380/// Blends packed 16-bit integers from `a` and `b` using control mask `IMM8`.
381///
382/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_blend_epi16)
383#[inline]
384#[target_feature(enable = "avx2")]
385#[cfg_attr(test, assert_instr(vpblendw, IMM8 = 9))]
386#[rustc_legacy_const_generics(2)]
387#[stable(feature = "simd_x86", since = "1.27.0")]
388#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
389pub const fn _mm256_blend_epi16<const IMM8: i32>(a: __m256i, b: __m256i) -> __m256i {
390    static_assert_uimm_bits!(IMM8, 8);
391    unsafe {
392        let a = a.as_i16x16();
393        let b = b.as_i16x16();
394
395        let r: i16x16 = simd_shuffle!(
396            a,
397            b,
398            [
399                [0, 16, 0, 16][IMM8 as usize & 0b11],
400                [1, 1, 17, 17][IMM8 as usize & 0b11],
401                [2, 18, 2, 18][(IMM8 as usize >> 2) & 0b11],
402                [3, 3, 19, 19][(IMM8 as usize >> 2) & 0b11],
403                [4, 20, 4, 20][(IMM8 as usize >> 4) & 0b11],
404                [5, 5, 21, 21][(IMM8 as usize >> 4) & 0b11],
405                [6, 22, 6, 22][(IMM8 as usize >> 6) & 0b11],
406                [7, 7, 23, 23][(IMM8 as usize >> 6) & 0b11],
407                [8, 24, 8, 24][IMM8 as usize & 0b11],
408                [9, 9, 25, 25][IMM8 as usize & 0b11],
409                [10, 26, 10, 26][(IMM8 as usize >> 2) & 0b11],
410                [11, 11, 27, 27][(IMM8 as usize >> 2) & 0b11],
411                [12, 28, 12, 28][(IMM8 as usize >> 4) & 0b11],
412                [13, 13, 29, 29][(IMM8 as usize >> 4) & 0b11],
413                [14, 30, 14, 30][(IMM8 as usize >> 6) & 0b11],
414                [15, 15, 31, 31][(IMM8 as usize >> 6) & 0b11],
415            ],
416        );
417        transmute(r)
418    }
419}
420
421/// Blends packed 8-bit integers from `a` and `b` using `mask`.
422///
423/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_blendv_epi8)
424#[inline]
425#[target_feature(enable = "avx2")]
426#[cfg_attr(test, assert_instr(vpblendvb))]
427#[stable(feature = "simd_x86", since = "1.27.0")]
428#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
429pub const fn _mm256_blendv_epi8(a: __m256i, b: __m256i, mask: __m256i) -> __m256i {
430    unsafe {
431        let mask: i8x32 = simd_lt(mask.as_i8x32(), i8x32::ZERO);
432        transmute(simd_select(mask, b.as_i8x32(), a.as_i8x32()))
433    }
434}
435
436/// Broadcasts the low packed 8-bit integer from `a` to all elements of
437/// the 128-bit returned value.
438///
439/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_broadcastb_epi8)
440#[inline]
441#[target_feature(enable = "avx2")]
442#[cfg_attr(test, assert_instr(vpbroadcastb))]
443#[stable(feature = "simd_x86", since = "1.27.0")]
444#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
445pub const fn _mm_broadcastb_epi8(a: __m128i) -> __m128i {
446    unsafe {
447        let ret = simd_shuffle!(a.as_i8x16(), i8x16::ZERO, [0_u32; 16]);
448        transmute::<i8x16, _>(ret)
449    }
450}
451
452/// Broadcasts the low packed 8-bit integer from `a` to all elements of
453/// the 256-bit returned value.
454///
455/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_broadcastb_epi8)
456#[inline]
457#[target_feature(enable = "avx2")]
458#[cfg_attr(test, assert_instr(vpbroadcastb))]
459#[stable(feature = "simd_x86", since = "1.27.0")]
460#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
461pub const fn _mm256_broadcastb_epi8(a: __m128i) -> __m256i {
462    unsafe {
463        let ret = simd_shuffle!(a.as_i8x16(), i8x16::ZERO, [0_u32; 32]);
464        transmute::<i8x32, _>(ret)
465    }
466}
467
468// N.B., `simd_shuffle4` with integer data types for `a` and `b` is
469// often compiled to `vbroadcastss`.
470/// Broadcasts the low packed 32-bit integer from `a` to all elements of
471/// the 128-bit returned value.
472///
473/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_broadcastd_epi32)
474#[inline]
475#[target_feature(enable = "avx2")]
476#[cfg_attr(test, assert_instr(vbroadcastss))]
477#[stable(feature = "simd_x86", since = "1.27.0")]
478#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
479pub const fn _mm_broadcastd_epi32(a: __m128i) -> __m128i {
480    unsafe {
481        let ret = simd_shuffle!(a.as_i32x4(), i32x4::ZERO, [0_u32; 4]);
482        transmute::<i32x4, _>(ret)
483    }
484}
485
486// N.B., `simd_shuffle4`` with integer data types for `a` and `b` is
487// often compiled to `vbroadcastss`.
488/// Broadcasts the low packed 32-bit integer from `a` to all elements of
489/// the 256-bit returned value.
490///
491/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_broadcastd_epi32)
492#[inline]
493#[target_feature(enable = "avx2")]
494#[cfg_attr(test, assert_instr(vbroadcastss))]
495#[stable(feature = "simd_x86", since = "1.27.0")]
496#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
497pub const fn _mm256_broadcastd_epi32(a: __m128i) -> __m256i {
498    unsafe {
499        let ret = simd_shuffle!(a.as_i32x4(), i32x4::ZERO, [0_u32; 8]);
500        transmute::<i32x8, _>(ret)
501    }
502}
503
504/// Broadcasts the low packed 64-bit integer from `a` to all elements of
505/// the 128-bit returned value.
506///
507/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_broadcastq_epi64)
508#[inline]
509#[target_feature(enable = "avx2")]
510// Emits `vmovddup` instead of `vpbroadcastq`
511// See https://github.com/rust-lang/stdarch/issues/791
512#[cfg_attr(test, assert_instr(vmovddup))]
513#[stable(feature = "simd_x86", since = "1.27.0")]
514#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
515pub const fn _mm_broadcastq_epi64(a: __m128i) -> __m128i {
516    unsafe {
517        let ret = simd_shuffle!(a.as_i64x2(), a.as_i64x2(), [0_u32; 2]);
518        transmute::<i64x2, _>(ret)
519    }
520}
521
522/// Broadcasts the low packed 64-bit integer from `a` to all elements of
523/// the 256-bit returned value.
524///
525/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_broadcastq_epi64)
526#[inline]
527#[target_feature(enable = "avx2")]
528#[cfg_attr(test, assert_instr(vbroadcastsd))]
529#[stable(feature = "simd_x86", since = "1.27.0")]
530#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
531pub const fn _mm256_broadcastq_epi64(a: __m128i) -> __m256i {
532    unsafe {
533        let ret = simd_shuffle!(a.as_i64x2(), a.as_i64x2(), [0_u32; 4]);
534        transmute::<i64x4, _>(ret)
535    }
536}
537
538/// Broadcasts the low double-precision (64-bit) floating-point element
539/// from `a` to all elements of the 128-bit returned value.
540///
541/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_broadcastsd_pd)
542#[inline]
543#[target_feature(enable = "avx2")]
544#[cfg_attr(test, assert_instr(vmovddup))]
545#[stable(feature = "simd_x86", since = "1.27.0")]
546#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
547pub const fn _mm_broadcastsd_pd(a: __m128d) -> __m128d {
548    unsafe { simd_shuffle!(a, _mm_setzero_pd(), [0_u32; 2]) }
549}
550
551/// Broadcasts the low double-precision (64-bit) floating-point element
552/// from `a` to all elements of the 256-bit returned value.
553///
554/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_broadcastsd_pd)
555#[inline]
556#[target_feature(enable = "avx2")]
557#[cfg_attr(test, assert_instr(vbroadcastsd))]
558#[stable(feature = "simd_x86", since = "1.27.0")]
559#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
560pub const fn _mm256_broadcastsd_pd(a: __m128d) -> __m256d {
561    unsafe { simd_shuffle!(a, _mm_setzero_pd(), [0_u32; 4]) }
562}
563
564/// Broadcasts 128 bits of integer data from a to all 128-bit lanes in
565/// the 256-bit returned value.
566///
567/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_broadcastsi128_si256)
568#[inline]
569#[target_feature(enable = "avx2")]
570#[stable(feature = "simd_x86_updates", since = "1.82.0")]
571#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
572pub const fn _mm_broadcastsi128_si256(a: __m128i) -> __m256i {
573    unsafe {
574        let ret = simd_shuffle!(a.as_i64x2(), i64x2::ZERO, [0, 1, 0, 1]);
575        transmute::<i64x4, _>(ret)
576    }
577}
578
579// N.B., `broadcastsi128_si256` is often compiled to `vinsertf128` or
580// `vbroadcastf128`.
581/// Broadcasts 128 bits of integer data from a to all 128-bit lanes in
582/// the 256-bit returned value.
583///
584/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_broadcastsi128_si256)
585#[inline]
586#[target_feature(enable = "avx2")]
587#[stable(feature = "simd_x86", since = "1.27.0")]
588#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
589pub const fn _mm256_broadcastsi128_si256(a: __m128i) -> __m256i {
590    unsafe {
591        let ret = simd_shuffle!(a.as_i64x2(), i64x2::ZERO, [0, 1, 0, 1]);
592        transmute::<i64x4, _>(ret)
593    }
594}
595
596/// Broadcasts the low single-precision (32-bit) floating-point element
597/// from `a` to all elements of the 128-bit returned value.
598///
599/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_broadcastss_ps)
600#[inline]
601#[target_feature(enable = "avx2")]
602#[cfg_attr(test, assert_instr(vbroadcastss))]
603#[stable(feature = "simd_x86", since = "1.27.0")]
604#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
605pub const fn _mm_broadcastss_ps(a: __m128) -> __m128 {
606    unsafe { simd_shuffle!(a, _mm_setzero_ps(), [0_u32; 4]) }
607}
608
609/// Broadcasts the low single-precision (32-bit) floating-point element
610/// from `a` to all elements of the 256-bit returned value.
611///
612/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_broadcastss_ps)
613#[inline]
614#[target_feature(enable = "avx2")]
615#[cfg_attr(test, assert_instr(vbroadcastss))]
616#[stable(feature = "simd_x86", since = "1.27.0")]
617#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
618pub const fn _mm256_broadcastss_ps(a: __m128) -> __m256 {
619    unsafe { simd_shuffle!(a, _mm_setzero_ps(), [0_u32; 8]) }
620}
621
622/// Broadcasts the low packed 16-bit integer from a to all elements of
623/// the 128-bit returned value
624///
625/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_broadcastw_epi16)
626#[inline]
627#[target_feature(enable = "avx2")]
628#[cfg_attr(test, assert_instr(vpbroadcastw))]
629#[stable(feature = "simd_x86", since = "1.27.0")]
630#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
631pub const fn _mm_broadcastw_epi16(a: __m128i) -> __m128i {
632    unsafe {
633        let ret = simd_shuffle!(a.as_i16x8(), i16x8::ZERO, [0_u32; 8]);
634        transmute::<i16x8, _>(ret)
635    }
636}
637
638/// Broadcasts the low packed 16-bit integer from a to all elements of
639/// the 256-bit returned value
640///
641/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_broadcastw_epi16)
642#[inline]
643#[target_feature(enable = "avx2")]
644#[cfg_attr(test, assert_instr(vpbroadcastw))]
645#[stable(feature = "simd_x86", since = "1.27.0")]
646#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
647pub const fn _mm256_broadcastw_epi16(a: __m128i) -> __m256i {
648    unsafe {
649        let ret = simd_shuffle!(a.as_i16x8(), i16x8::ZERO, [0_u32; 16]);
650        transmute::<i16x16, _>(ret)
651    }
652}
653
654/// Compares packed 64-bit integers in `a` and `b` for equality.
655///
656/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cmpeq_epi64)
657#[inline]
658#[target_feature(enable = "avx2")]
659#[cfg_attr(test, assert_instr(vpcmpeqq))]
660#[stable(feature = "simd_x86", since = "1.27.0")]
661#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
662pub const fn _mm256_cmpeq_epi64(a: __m256i, b: __m256i) -> __m256i {
663    unsafe { transmute::<i64x4, _>(simd_eq(a.as_i64x4(), b.as_i64x4())) }
664}
665
666/// Compares packed 32-bit integers in `a` and `b` for equality.
667///
668/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cmpeq_epi32)
669#[inline]
670#[target_feature(enable = "avx2")]
671#[cfg_attr(test, assert_instr(vpcmpeqd))]
672#[stable(feature = "simd_x86", since = "1.27.0")]
673#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
674pub const fn _mm256_cmpeq_epi32(a: __m256i, b: __m256i) -> __m256i {
675    unsafe { transmute::<i32x8, _>(simd_eq(a.as_i32x8(), b.as_i32x8())) }
676}
677
678/// Compares packed 16-bit integers in `a` and `b` for equality.
679///
680/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cmpeq_epi16)
681#[inline]
682#[target_feature(enable = "avx2")]
683#[cfg_attr(test, assert_instr(vpcmpeqw))]
684#[stable(feature = "simd_x86", since = "1.27.0")]
685#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
686pub const fn _mm256_cmpeq_epi16(a: __m256i, b: __m256i) -> __m256i {
687    unsafe { transmute::<i16x16, _>(simd_eq(a.as_i16x16(), b.as_i16x16())) }
688}
689
690/// Compares packed 8-bit integers in `a` and `b` for equality.
691///
692/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cmpeq_epi8)
693#[inline]
694#[target_feature(enable = "avx2")]
695#[cfg_attr(test, assert_instr(vpcmpeqb))]
696#[stable(feature = "simd_x86", since = "1.27.0")]
697#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
698pub const fn _mm256_cmpeq_epi8(a: __m256i, b: __m256i) -> __m256i {
699    unsafe { transmute::<i8x32, _>(simd_eq(a.as_i8x32(), b.as_i8x32())) }
700}
701
702/// Compares packed 64-bit integers in `a` and `b` for greater-than.
703///
704/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cmpgt_epi64)
705#[inline]
706#[target_feature(enable = "avx2")]
707#[cfg_attr(test, assert_instr(vpcmpgtq))]
708#[stable(feature = "simd_x86", since = "1.27.0")]
709#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
710pub const fn _mm256_cmpgt_epi64(a: __m256i, b: __m256i) -> __m256i {
711    unsafe { transmute::<i64x4, _>(simd_gt(a.as_i64x4(), b.as_i64x4())) }
712}
713
714/// Compares packed 32-bit integers in `a` and `b` for greater-than.
715///
716/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cmpgt_epi32)
717#[inline]
718#[target_feature(enable = "avx2")]
719#[cfg_attr(test, assert_instr(vpcmpgtd))]
720#[stable(feature = "simd_x86", since = "1.27.0")]
721#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
722pub const fn _mm256_cmpgt_epi32(a: __m256i, b: __m256i) -> __m256i {
723    unsafe { transmute::<i32x8, _>(simd_gt(a.as_i32x8(), b.as_i32x8())) }
724}
725
726/// Compares packed 16-bit integers in `a` and `b` for greater-than.
727///
728/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cmpgt_epi16)
729#[inline]
730#[target_feature(enable = "avx2")]
731#[cfg_attr(test, assert_instr(vpcmpgtw))]
732#[stable(feature = "simd_x86", since = "1.27.0")]
733#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
734pub const fn _mm256_cmpgt_epi16(a: __m256i, b: __m256i) -> __m256i {
735    unsafe { transmute::<i16x16, _>(simd_gt(a.as_i16x16(), b.as_i16x16())) }
736}
737
738/// Compares packed 8-bit integers in `a` and `b` for greater-than.
739///
740/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cmpgt_epi8)
741#[inline]
742#[target_feature(enable = "avx2")]
743#[cfg_attr(test, assert_instr(vpcmpgtb))]
744#[stable(feature = "simd_x86", since = "1.27.0")]
745#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
746pub const fn _mm256_cmpgt_epi8(a: __m256i, b: __m256i) -> __m256i {
747    unsafe { transmute::<i8x32, _>(simd_gt(a.as_i8x32(), b.as_i8x32())) }
748}
749
750/// Sign-extend 16-bit integers to 32-bit integers.
751///
752/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cvtepi16_epi32)
753#[inline]
754#[target_feature(enable = "avx2")]
755#[cfg_attr(test, assert_instr(vpmovsxwd))]
756#[stable(feature = "simd_x86", since = "1.27.0")]
757#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
758pub const fn _mm256_cvtepi16_epi32(a: __m128i) -> __m256i {
759    unsafe { transmute::<i32x8, _>(simd_cast(a.as_i16x8())) }
760}
761
762/// Sign-extend 16-bit integers to 64-bit integers.
763///
764/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cvtepi16_epi64)
765#[inline]
766#[target_feature(enable = "avx2")]
767#[cfg_attr(test, assert_instr(vpmovsxwq))]
768#[stable(feature = "simd_x86", since = "1.27.0")]
769#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
770pub const fn _mm256_cvtepi16_epi64(a: __m128i) -> __m256i {
771    unsafe {
772        let a = a.as_i16x8();
773        let v64: i16x4 = simd_shuffle!(a, a, [0, 1, 2, 3]);
774        transmute::<i64x4, _>(simd_cast(v64))
775    }
776}
777
778/// Sign-extend 32-bit integers to 64-bit integers.
779///
780/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cvtepi32_epi64)
781#[inline]
782#[target_feature(enable = "avx2")]
783#[cfg_attr(test, assert_instr(vpmovsxdq))]
784#[stable(feature = "simd_x86", since = "1.27.0")]
785#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
786pub const fn _mm256_cvtepi32_epi64(a: __m128i) -> __m256i {
787    unsafe { transmute::<i64x4, _>(simd_cast(a.as_i32x4())) }
788}
789
790/// Sign-extend 8-bit integers to 16-bit integers.
791///
792/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cvtepi8_epi16)
793#[inline]
794#[target_feature(enable = "avx2")]
795#[cfg_attr(test, assert_instr(vpmovsxbw))]
796#[stable(feature = "simd_x86", since = "1.27.0")]
797#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
798pub const fn _mm256_cvtepi8_epi16(a: __m128i) -> __m256i {
799    unsafe { transmute::<i16x16, _>(simd_cast(a.as_i8x16())) }
800}
801
802/// Sign-extend 8-bit integers to 32-bit integers.
803///
804/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cvtepi8_epi32)
805#[inline]
806#[target_feature(enable = "avx2")]
807#[cfg_attr(test, assert_instr(vpmovsxbd))]
808#[stable(feature = "simd_x86", since = "1.27.0")]
809#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
810pub const fn _mm256_cvtepi8_epi32(a: __m128i) -> __m256i {
811    unsafe {
812        let a = a.as_i8x16();
813        let v64: i8x8 = simd_shuffle!(a, a, [0, 1, 2, 3, 4, 5, 6, 7]);
814        transmute::<i32x8, _>(simd_cast(v64))
815    }
816}
817
818/// Sign-extend 8-bit integers to 64-bit integers.
819///
820/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cvtepi8_epi64)
821#[inline]
822#[target_feature(enable = "avx2")]
823#[cfg_attr(test, assert_instr(vpmovsxbq))]
824#[stable(feature = "simd_x86", since = "1.27.0")]
825#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
826pub const fn _mm256_cvtepi8_epi64(a: __m128i) -> __m256i {
827    unsafe {
828        let a = a.as_i8x16();
829        let v32: i8x4 = simd_shuffle!(a, a, [0, 1, 2, 3]);
830        transmute::<i64x4, _>(simd_cast(v32))
831    }
832}
833
834/// Zeroes extend packed unsigned 16-bit integers in `a` to packed 32-bit
835/// integers, and stores the results in `dst`.
836///
837/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cvtepu16_epi32)
838#[inline]
839#[target_feature(enable = "avx2")]
840#[cfg_attr(test, assert_instr(vpmovzxwd))]
841#[stable(feature = "simd_x86", since = "1.27.0")]
842#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
843pub const fn _mm256_cvtepu16_epi32(a: __m128i) -> __m256i {
844    unsafe { transmute::<i32x8, _>(simd_cast(a.as_u16x8())) }
845}
846
847/// Zero-extend the lower four unsigned 16-bit integers in `a` to 64-bit
848/// integers. The upper four elements of `a` are unused.
849///
850/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cvtepu16_epi64)
851#[inline]
852#[target_feature(enable = "avx2")]
853#[cfg_attr(test, assert_instr(vpmovzxwq))]
854#[stable(feature = "simd_x86", since = "1.27.0")]
855#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
856pub const fn _mm256_cvtepu16_epi64(a: __m128i) -> __m256i {
857    unsafe {
858        let a = a.as_u16x8();
859        let v64: u16x4 = simd_shuffle!(a, a, [0, 1, 2, 3]);
860        transmute::<i64x4, _>(simd_cast(v64))
861    }
862}
863
864/// Zero-extend unsigned 32-bit integers in `a` to 64-bit integers.
865///
866/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cvtepu32_epi64)
867#[inline]
868#[target_feature(enable = "avx2")]
869#[cfg_attr(test, assert_instr(vpmovzxdq))]
870#[stable(feature = "simd_x86", since = "1.27.0")]
871#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
872pub const fn _mm256_cvtepu32_epi64(a: __m128i) -> __m256i {
873    unsafe { transmute::<i64x4, _>(simd_cast(a.as_u32x4())) }
874}
875
876/// Zero-extend unsigned 8-bit integers in `a` to 16-bit integers.
877///
878/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cvtepu8_epi16)
879#[inline]
880#[target_feature(enable = "avx2")]
881#[cfg_attr(test, assert_instr(vpmovzxbw))]
882#[stable(feature = "simd_x86", since = "1.27.0")]
883#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
884pub const fn _mm256_cvtepu8_epi16(a: __m128i) -> __m256i {
885    unsafe { transmute::<i16x16, _>(simd_cast(a.as_u8x16())) }
886}
887
888/// Zero-extend the lower eight unsigned 8-bit integers in `a` to 32-bit
889/// integers. The upper eight elements of `a` are unused.
890///
891/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cvtepu8_epi32)
892#[inline]
893#[target_feature(enable = "avx2")]
894#[cfg_attr(test, assert_instr(vpmovzxbd))]
895#[stable(feature = "simd_x86", since = "1.27.0")]
896#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
897pub const fn _mm256_cvtepu8_epi32(a: __m128i) -> __m256i {
898    unsafe {
899        let a = a.as_u8x16();
900        let v64: u8x8 = simd_shuffle!(a, a, [0, 1, 2, 3, 4, 5, 6, 7]);
901        transmute::<i32x8, _>(simd_cast(v64))
902    }
903}
904
905/// Zero-extend the lower four unsigned 8-bit integers in `a` to 64-bit
906/// integers. The upper twelve elements of `a` are unused.
907///
908/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_cvtepu8_epi64)
909#[inline]
910#[target_feature(enable = "avx2")]
911#[cfg_attr(test, assert_instr(vpmovzxbq))]
912#[stable(feature = "simd_x86", since = "1.27.0")]
913#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
914pub const fn _mm256_cvtepu8_epi64(a: __m128i) -> __m256i {
915    unsafe {
916        let a = a.as_u8x16();
917        let v32: u8x4 = simd_shuffle!(a, a, [0, 1, 2, 3]);
918        transmute::<i64x4, _>(simd_cast(v32))
919    }
920}
921
922/// Extracts 128 bits (of integer data) from `a` selected with `IMM1`.
923///
924/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_extracti128_si256)
925#[inline]
926#[target_feature(enable = "avx2")]
927#[cfg_attr(test, assert_instr(vextractf128, IMM1 = 1))]
928#[rustc_legacy_const_generics(1)]
929#[stable(feature = "simd_x86", since = "1.27.0")]
930#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
931pub const fn _mm256_extracti128_si256<const IMM1: i32>(a: __m256i) -> __m128i {
932    static_assert_uimm_bits!(IMM1, 1);
933    unsafe {
934        let a = a.as_i64x4();
935        let b = i64x4::ZERO;
936        let dst: i64x2 = simd_shuffle!(a, b, [[0, 1], [2, 3]][IMM1 as usize]);
937        transmute(dst)
938    }
939}
940
941/// Horizontally adds adjacent pairs of 16-bit integers in `a` and `b`.
942///
943/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_hadd_epi16)
944#[inline]
945#[target_feature(enable = "avx2")]
946#[cfg_attr(test, assert_instr(vphaddw))]
947#[stable(feature = "simd_x86", since = "1.27.0")]
948#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
949pub const fn _mm256_hadd_epi16(a: __m256i, b: __m256i) -> __m256i {
950    let a = a.as_i16x16();
951    let b = b.as_i16x16();
952    unsafe {
953        let even: i16x16 = simd_shuffle!(
954            a,
955            b,
956            [0, 2, 4, 6, 16, 18, 20, 22, 8, 10, 12, 14, 24, 26, 28, 30]
957        );
958        let odd: i16x16 = simd_shuffle!(
959            a,
960            b,
961            [1, 3, 5, 7, 17, 19, 21, 23, 9, 11, 13, 15, 25, 27, 29, 31]
962        );
963        simd_add(even, odd).as_m256i()
964    }
965}
966
967/// Horizontally adds adjacent pairs of 32-bit integers in `a` and `b`.
968///
969/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_hadd_epi32)
970#[inline]
971#[target_feature(enable = "avx2")]
972#[cfg_attr(test, assert_instr(vphaddd))]
973#[stable(feature = "simd_x86", since = "1.27.0")]
974#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
975pub const fn _mm256_hadd_epi32(a: __m256i, b: __m256i) -> __m256i {
976    let a = a.as_i32x8();
977    let b = b.as_i32x8();
978    unsafe {
979        let even: i32x8 = simd_shuffle!(a, b, [0, 2, 8, 10, 4, 6, 12, 14]);
980        let odd: i32x8 = simd_shuffle!(a, b, [1, 3, 9, 11, 5, 7, 13, 15]);
981        simd_add(even, odd).as_m256i()
982    }
983}
984
985/// Horizontally adds adjacent pairs of 16-bit integers in `a` and `b`
986/// using saturation.
987///
988/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_hadds_epi16)
989#[inline]
990#[target_feature(enable = "avx2")]
991#[cfg_attr(test, assert_instr(vphaddsw))]
992#[stable(feature = "simd_x86", since = "1.27.0")]
993pub fn _mm256_hadds_epi16(a: __m256i, b: __m256i) -> __m256i {
994    let a = a.as_i16x16();
995    let b = b.as_i16x16();
996    unsafe {
997        let even: i16x16 = simd_shuffle!(
998            a,
999            b,
1000            [0, 2, 4, 6, 16, 18, 20, 22, 8, 10, 12, 14, 24, 26, 28, 30]
1001        );
1002        let odd: i16x16 = simd_shuffle!(
1003            a,
1004            b,
1005            [1, 3, 5, 7, 17, 19, 21, 23, 9, 11, 13, 15, 25, 27, 29, 31]
1006        );
1007        simd_saturating_add(even, odd).as_m256i()
1008    }
1009}
1010
1011/// Horizontally subtract adjacent pairs of 16-bit integers in `a` and `b`.
1012///
1013/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_hsub_epi16)
1014#[inline]
1015#[target_feature(enable = "avx2")]
1016#[cfg_attr(test, assert_instr(vphsubw))]
1017#[stable(feature = "simd_x86", since = "1.27.0")]
1018#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1019pub const fn _mm256_hsub_epi16(a: __m256i, b: __m256i) -> __m256i {
1020    let a = a.as_i16x16();
1021    let b = b.as_i16x16();
1022    unsafe {
1023        let even: i16x16 = simd_shuffle!(
1024            a,
1025            b,
1026            [0, 2, 4, 6, 16, 18, 20, 22, 8, 10, 12, 14, 24, 26, 28, 30]
1027        );
1028        let odd: i16x16 = simd_shuffle!(
1029            a,
1030            b,
1031            [1, 3, 5, 7, 17, 19, 21, 23, 9, 11, 13, 15, 25, 27, 29, 31]
1032        );
1033        simd_sub(even, odd).as_m256i()
1034    }
1035}
1036
1037/// Horizontally subtract adjacent pairs of 32-bit integers in `a` and `b`.
1038///
1039/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_hsub_epi32)
1040#[inline]
1041#[target_feature(enable = "avx2")]
1042#[cfg_attr(test, assert_instr(vphsubd))]
1043#[stable(feature = "simd_x86", since = "1.27.0")]
1044#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1045pub const fn _mm256_hsub_epi32(a: __m256i, b: __m256i) -> __m256i {
1046    let a = a.as_i32x8();
1047    let b = b.as_i32x8();
1048    unsafe {
1049        let even: i32x8 = simd_shuffle!(a, b, [0, 2, 8, 10, 4, 6, 12, 14]);
1050        let odd: i32x8 = simd_shuffle!(a, b, [1, 3, 9, 11, 5, 7, 13, 15]);
1051        simd_sub(even, odd).as_m256i()
1052    }
1053}
1054
1055/// Horizontally subtract adjacent pairs of 16-bit integers in `a` and `b`
1056/// using saturation.
1057///
1058/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_hsubs_epi16)
1059#[inline]
1060#[target_feature(enable = "avx2")]
1061#[cfg_attr(test, assert_instr(vphsubsw))]
1062#[stable(feature = "simd_x86", since = "1.27.0")]
1063pub fn _mm256_hsubs_epi16(a: __m256i, b: __m256i) -> __m256i {
1064    let a = a.as_i16x16();
1065    let b = b.as_i16x16();
1066    unsafe {
1067        let even: i16x16 = simd_shuffle!(
1068            a,
1069            b,
1070            [0, 2, 4, 6, 16, 18, 20, 22, 8, 10, 12, 14, 24, 26, 28, 30]
1071        );
1072        let odd: i16x16 = simd_shuffle!(
1073            a,
1074            b,
1075            [1, 3, 5, 7, 17, 19, 21, 23, 9, 11, 13, 15, 25, 27, 29, 31]
1076        );
1077        simd_saturating_sub(even, odd).as_m256i()
1078    }
1079}
1080
1081/// Returns values from `slice` at offsets determined by `offsets * scale`,
1082/// where
1083/// `scale` should be 1, 2, 4 or 8.
1084///
1085/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_i32gather_epi32)
1086#[inline]
1087#[target_feature(enable = "avx2")]
1088#[cfg_attr(test, assert_instr(vpgatherdd, SCALE = 1))]
1089#[rustc_legacy_const_generics(2)]
1090#[stable(feature = "simd_x86", since = "1.27.0")]
1091pub unsafe fn _mm_i32gather_epi32<const SCALE: i32>(
1092    slice: *const i32,
1093    offsets: __m128i,
1094) -> __m128i {
1095    static_assert_imm8_scale!(SCALE);
1096    let zero = i32x4::ZERO;
1097    let neg_one = _mm_set1_epi32(-1).as_i32x4();
1098    let offsets = offsets.as_i32x4();
1099    let slice = slice as *const i8;
1100    let r = pgatherdd(zero, slice, offsets, neg_one, SCALE as i8);
1101    transmute(r)
1102}
1103
1104/// Returns values from `slice` at offsets determined by `offsets * scale`,
1105/// where
1106/// `scale` should be 1, 2, 4 or 8. If mask is set, load the value from `src` in
1107/// that position instead.
1108///
1109/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mask_i32gather_epi32)
1110#[inline]
1111#[target_feature(enable = "avx2")]
1112#[cfg_attr(test, assert_instr(vpgatherdd, SCALE = 1))]
1113#[rustc_legacy_const_generics(4)]
1114#[stable(feature = "simd_x86", since = "1.27.0")]
1115pub unsafe fn _mm_mask_i32gather_epi32<const SCALE: i32>(
1116    src: __m128i,
1117    slice: *const i32,
1118    offsets: __m128i,
1119    mask: __m128i,
1120) -> __m128i {
1121    static_assert_imm8_scale!(SCALE);
1122    let src = src.as_i32x4();
1123    let mask = mask.as_i32x4();
1124    let offsets = offsets.as_i32x4();
1125    let slice = slice as *const i8;
1126    let r = pgatherdd(src, slice, offsets, mask, SCALE as i8);
1127    transmute(r)
1128}
1129
1130/// Returns values from `slice` at offsets determined by `offsets * scale`,
1131/// where
1132/// `scale` should be 1, 2, 4 or 8.
1133///
1134/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_i32gather_epi32)
1135#[inline]
1136#[target_feature(enable = "avx2")]
1137#[cfg_attr(test, assert_instr(vpgatherdd, SCALE = 1))]
1138#[rustc_legacy_const_generics(2)]
1139#[stable(feature = "simd_x86", since = "1.27.0")]
1140pub unsafe fn _mm256_i32gather_epi32<const SCALE: i32>(
1141    slice: *const i32,
1142    offsets: __m256i,
1143) -> __m256i {
1144    static_assert_imm8_scale!(SCALE);
1145    let zero = i32x8::ZERO;
1146    let neg_one = _mm256_set1_epi32(-1).as_i32x8();
1147    let offsets = offsets.as_i32x8();
1148    let slice = slice as *const i8;
1149    let r = vpgatherdd(zero, slice, offsets, neg_one, SCALE as i8);
1150    transmute(r)
1151}
1152
1153/// Returns values from `slice` at offsets determined by `offsets * scale`,
1154/// where
1155/// `scale` should be 1, 2, 4 or 8. If mask is set, load the value from `src` in
1156/// that position instead.
1157///
1158/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mask_i32gather_epi32)
1159#[inline]
1160#[target_feature(enable = "avx2")]
1161#[cfg_attr(test, assert_instr(vpgatherdd, SCALE = 1))]
1162#[rustc_legacy_const_generics(4)]
1163#[stable(feature = "simd_x86", since = "1.27.0")]
1164pub unsafe fn _mm256_mask_i32gather_epi32<const SCALE: i32>(
1165    src: __m256i,
1166    slice: *const i32,
1167    offsets: __m256i,
1168    mask: __m256i,
1169) -> __m256i {
1170    static_assert_imm8_scale!(SCALE);
1171    let src = src.as_i32x8();
1172    let mask = mask.as_i32x8();
1173    let offsets = offsets.as_i32x8();
1174    let slice = slice as *const i8;
1175    let r = vpgatherdd(src, slice, offsets, mask, SCALE as i8);
1176    transmute(r)
1177}
1178
1179/// Returns values from `slice` at offsets determined by `offsets * scale`,
1180/// where
1181/// `scale` should be 1, 2, 4 or 8.
1182///
1183/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_i32gather_ps)
1184#[inline]
1185#[target_feature(enable = "avx2")]
1186#[cfg_attr(test, assert_instr(vgatherdps, SCALE = 1))]
1187#[rustc_legacy_const_generics(2)]
1188#[stable(feature = "simd_x86", since = "1.27.0")]
1189pub unsafe fn _mm_i32gather_ps<const SCALE: i32>(slice: *const f32, offsets: __m128i) -> __m128 {
1190    static_assert_imm8_scale!(SCALE);
1191    let zero = _mm_setzero_ps();
1192    let neg_one = _mm_set1_ps(-1.0);
1193    let offsets = offsets.as_i32x4();
1194    let slice = slice as *const i8;
1195    pgatherdps(zero, slice, offsets, neg_one, SCALE as i8)
1196}
1197
1198/// Returns values from `slice` at offsets determined by `offsets * scale`,
1199/// where
1200/// `scale` should be 1, 2, 4 or 8. If mask is set, load the value from `src` in
1201/// that position instead.
1202///
1203/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mask_i32gather_ps)
1204#[inline]
1205#[target_feature(enable = "avx2")]
1206#[cfg_attr(test, assert_instr(vgatherdps, SCALE = 1))]
1207#[rustc_legacy_const_generics(4)]
1208#[stable(feature = "simd_x86", since = "1.27.0")]
1209pub unsafe fn _mm_mask_i32gather_ps<const SCALE: i32>(
1210    src: __m128,
1211    slice: *const f32,
1212    offsets: __m128i,
1213    mask: __m128,
1214) -> __m128 {
1215    static_assert_imm8_scale!(SCALE);
1216    let offsets = offsets.as_i32x4();
1217    let slice = slice as *const i8;
1218    pgatherdps(src, slice, offsets, mask, SCALE as i8)
1219}
1220
1221/// Returns values from `slice` at offsets determined by `offsets * scale`,
1222/// where
1223/// `scale` should be 1, 2, 4 or 8.
1224///
1225/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_i32gather_ps)
1226#[inline]
1227#[target_feature(enable = "avx2")]
1228#[cfg_attr(test, assert_instr(vgatherdps, SCALE = 1))]
1229#[rustc_legacy_const_generics(2)]
1230#[stable(feature = "simd_x86", since = "1.27.0")]
1231pub unsafe fn _mm256_i32gather_ps<const SCALE: i32>(slice: *const f32, offsets: __m256i) -> __m256 {
1232    static_assert_imm8_scale!(SCALE);
1233    let zero = _mm256_setzero_ps();
1234    let neg_one = _mm256_set1_ps(-1.0);
1235    let offsets = offsets.as_i32x8();
1236    let slice = slice as *const i8;
1237    vpgatherdps(zero, slice, offsets, neg_one, SCALE as i8)
1238}
1239
1240/// Returns values from `slice` at offsets determined by `offsets * scale`,
1241/// where
1242/// `scale` should be 1, 2, 4 or 8. If mask is set, load the value from `src` in
1243/// that position instead.
1244///
1245/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mask_i32gather_ps)
1246#[inline]
1247#[target_feature(enable = "avx2")]
1248#[cfg_attr(test, assert_instr(vgatherdps, SCALE = 1))]
1249#[rustc_legacy_const_generics(4)]
1250#[stable(feature = "simd_x86", since = "1.27.0")]
1251pub unsafe fn _mm256_mask_i32gather_ps<const SCALE: i32>(
1252    src: __m256,
1253    slice: *const f32,
1254    offsets: __m256i,
1255    mask: __m256,
1256) -> __m256 {
1257    static_assert_imm8_scale!(SCALE);
1258    let offsets = offsets.as_i32x8();
1259    let slice = slice as *const i8;
1260    vpgatherdps(src, slice, offsets, mask, SCALE as i8)
1261}
1262
1263/// Returns values from `slice` at offsets determined by `offsets * scale`,
1264/// where
1265/// `scale` should be 1, 2, 4 or 8.
1266///
1267/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_i32gather_epi64)
1268#[inline]
1269#[target_feature(enable = "avx2")]
1270#[cfg_attr(test, assert_instr(vpgatherdq, SCALE = 1))]
1271#[rustc_legacy_const_generics(2)]
1272#[stable(feature = "simd_x86", since = "1.27.0")]
1273pub unsafe fn _mm_i32gather_epi64<const SCALE: i32>(
1274    slice: *const i64,
1275    offsets: __m128i,
1276) -> __m128i {
1277    static_assert_imm8_scale!(SCALE);
1278    let zero = i64x2::ZERO;
1279    let neg_one = _mm_set1_epi64x(-1).as_i64x2();
1280    let offsets = offsets.as_i32x4();
1281    let slice = slice as *const i8;
1282    let r = pgatherdq(zero, slice, offsets, neg_one, SCALE as i8);
1283    transmute(r)
1284}
1285
1286/// Returns values from `slice` at offsets determined by `offsets * scale`,
1287/// where
1288/// `scale` should be 1, 2, 4 or 8. If mask is set, load the value from `src` in
1289/// that position instead.
1290///
1291/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mask_i32gather_epi64)
1292#[inline]
1293#[target_feature(enable = "avx2")]
1294#[cfg_attr(test, assert_instr(vpgatherdq, SCALE = 1))]
1295#[rustc_legacy_const_generics(4)]
1296#[stable(feature = "simd_x86", since = "1.27.0")]
1297pub unsafe fn _mm_mask_i32gather_epi64<const SCALE: i32>(
1298    src: __m128i,
1299    slice: *const i64,
1300    offsets: __m128i,
1301    mask: __m128i,
1302) -> __m128i {
1303    static_assert_imm8_scale!(SCALE);
1304    let src = src.as_i64x2();
1305    let mask = mask.as_i64x2();
1306    let offsets = offsets.as_i32x4();
1307    let slice = slice as *const i8;
1308    let r = pgatherdq(src, slice, offsets, mask, SCALE as i8);
1309    transmute(r)
1310}
1311
1312/// Returns values from `slice` at offsets determined by `offsets * scale`,
1313/// where
1314/// `scale` should be 1, 2, 4 or 8.
1315///
1316/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_i32gather_epi64)
1317#[inline]
1318#[target_feature(enable = "avx2")]
1319#[cfg_attr(test, assert_instr(vpgatherdq, SCALE = 1))]
1320#[rustc_legacy_const_generics(2)]
1321#[stable(feature = "simd_x86", since = "1.27.0")]
1322pub unsafe fn _mm256_i32gather_epi64<const SCALE: i32>(
1323    slice: *const i64,
1324    offsets: __m128i,
1325) -> __m256i {
1326    static_assert_imm8_scale!(SCALE);
1327    let zero = i64x4::ZERO;
1328    let neg_one = _mm256_set1_epi64x(-1).as_i64x4();
1329    let offsets = offsets.as_i32x4();
1330    let slice = slice as *const i8;
1331    let r = vpgatherdq(zero, slice, offsets, neg_one, SCALE as i8);
1332    transmute(r)
1333}
1334
1335/// Returns values from `slice` at offsets determined by `offsets * scale`,
1336/// where
1337/// `scale` should be 1, 2, 4 or 8. If mask is set, load the value from `src` in
1338/// that position instead.
1339///
1340/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mask_i32gather_epi64)
1341#[inline]
1342#[target_feature(enable = "avx2")]
1343#[cfg_attr(test, assert_instr(vpgatherdq, SCALE = 1))]
1344#[rustc_legacy_const_generics(4)]
1345#[stable(feature = "simd_x86", since = "1.27.0")]
1346pub unsafe fn _mm256_mask_i32gather_epi64<const SCALE: i32>(
1347    src: __m256i,
1348    slice: *const i64,
1349    offsets: __m128i,
1350    mask: __m256i,
1351) -> __m256i {
1352    static_assert_imm8_scale!(SCALE);
1353    let src = src.as_i64x4();
1354    let mask = mask.as_i64x4();
1355    let offsets = offsets.as_i32x4();
1356    let slice = slice as *const i8;
1357    let r = vpgatherdq(src, slice, offsets, mask, SCALE as i8);
1358    transmute(r)
1359}
1360
1361/// Returns values from `slice` at offsets determined by `offsets * scale`,
1362/// where
1363/// `scale` should be 1, 2, 4 or 8.
1364///
1365/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_i32gather_pd)
1366#[inline]
1367#[target_feature(enable = "avx2")]
1368#[cfg_attr(test, assert_instr(vgatherdpd, SCALE = 1))]
1369#[rustc_legacy_const_generics(2)]
1370#[stable(feature = "simd_x86", since = "1.27.0")]
1371pub unsafe fn _mm_i32gather_pd<const SCALE: i32>(slice: *const f64, offsets: __m128i) -> __m128d {
1372    static_assert_imm8_scale!(SCALE);
1373    let zero = _mm_setzero_pd();
1374    let neg_one = _mm_set1_pd(-1.0);
1375    let offsets = offsets.as_i32x4();
1376    let slice = slice as *const i8;
1377    pgatherdpd(zero, slice, offsets, neg_one, SCALE as i8)
1378}
1379
1380/// Returns values from `slice` at offsets determined by `offsets * scale`,
1381/// where
1382/// `scale` should be 1, 2, 4 or 8. If mask is set, load the value from `src` in
1383/// that position instead.
1384///
1385/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mask_i32gather_pd)
1386#[inline]
1387#[target_feature(enable = "avx2")]
1388#[cfg_attr(test, assert_instr(vgatherdpd, SCALE = 1))]
1389#[rustc_legacy_const_generics(4)]
1390#[stable(feature = "simd_x86", since = "1.27.0")]
1391pub unsafe fn _mm_mask_i32gather_pd<const SCALE: i32>(
1392    src: __m128d,
1393    slice: *const f64,
1394    offsets: __m128i,
1395    mask: __m128d,
1396) -> __m128d {
1397    static_assert_imm8_scale!(SCALE);
1398    let offsets = offsets.as_i32x4();
1399    let slice = slice as *const i8;
1400    pgatherdpd(src, slice, offsets, mask, SCALE as i8)
1401}
1402
1403/// Returns values from `slice` at offsets determined by `offsets * scale`,
1404/// where
1405/// `scale` should be 1, 2, 4 or 8.
1406///
1407/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_i32gather_pd)
1408#[inline]
1409#[target_feature(enable = "avx2")]
1410#[cfg_attr(test, assert_instr(vgatherdpd, SCALE = 1))]
1411#[rustc_legacy_const_generics(2)]
1412#[stable(feature = "simd_x86", since = "1.27.0")]
1413pub unsafe fn _mm256_i32gather_pd<const SCALE: i32>(
1414    slice: *const f64,
1415    offsets: __m128i,
1416) -> __m256d {
1417    static_assert_imm8_scale!(SCALE);
1418    let zero = _mm256_setzero_pd();
1419    let neg_one = _mm256_set1_pd(-1.0);
1420    let offsets = offsets.as_i32x4();
1421    let slice = slice as *const i8;
1422    vpgatherdpd(zero, slice, offsets, neg_one, SCALE as i8)
1423}
1424
1425/// Returns values from `slice` at offsets determined by `offsets * scale`,
1426/// where
1427/// `scale` should be 1, 2, 4 or 8. If mask is set, load the value from `src` in
1428/// that position instead.
1429///
1430/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mask_i32gather_pd)
1431#[inline]
1432#[target_feature(enable = "avx2")]
1433#[cfg_attr(test, assert_instr(vgatherdpd, SCALE = 1))]
1434#[rustc_legacy_const_generics(4)]
1435#[stable(feature = "simd_x86", since = "1.27.0")]
1436pub unsafe fn _mm256_mask_i32gather_pd<const SCALE: i32>(
1437    src: __m256d,
1438    slice: *const f64,
1439    offsets: __m128i,
1440    mask: __m256d,
1441) -> __m256d {
1442    static_assert_imm8_scale!(SCALE);
1443    let offsets = offsets.as_i32x4();
1444    let slice = slice as *const i8;
1445    vpgatherdpd(src, slice, offsets, mask, SCALE as i8)
1446}
1447
1448/// Returns values from `slice` at offsets determined by `offsets * scale`,
1449/// where
1450/// `scale` should be 1, 2, 4 or 8.
1451///
1452/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_i64gather_epi32)
1453#[inline]
1454#[target_feature(enable = "avx2")]
1455#[cfg_attr(test, assert_instr(vpgatherqd, SCALE = 1))]
1456#[rustc_legacy_const_generics(2)]
1457#[stable(feature = "simd_x86", since = "1.27.0")]
1458pub unsafe fn _mm_i64gather_epi32<const SCALE: i32>(
1459    slice: *const i32,
1460    offsets: __m128i,
1461) -> __m128i {
1462    static_assert_imm8_scale!(SCALE);
1463    let zero = i32x4::ZERO;
1464    let neg_one = _mm_set1_epi64x(-1).as_i32x4();
1465    let offsets = offsets.as_i64x2();
1466    let slice = slice as *const i8;
1467    let r = pgatherqd(zero, slice, offsets, neg_one, SCALE as i8);
1468    transmute(r)
1469}
1470
1471/// Returns values from `slice` at offsets determined by `offsets * scale`,
1472/// where
1473/// `scale` should be 1, 2, 4 or 8. If mask is set, load the value from `src` in
1474/// that position instead.
1475///
1476/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mask_i64gather_epi32)
1477#[inline]
1478#[target_feature(enable = "avx2")]
1479#[cfg_attr(test, assert_instr(vpgatherqd, SCALE = 1))]
1480#[rustc_legacy_const_generics(4)]
1481#[stable(feature = "simd_x86", since = "1.27.0")]
1482pub unsafe fn _mm_mask_i64gather_epi32<const SCALE: i32>(
1483    src: __m128i,
1484    slice: *const i32,
1485    offsets: __m128i,
1486    mask: __m128i,
1487) -> __m128i {
1488    static_assert_imm8_scale!(SCALE);
1489    let src = src.as_i32x4();
1490    let mask = mask.as_i32x4();
1491    let offsets = offsets.as_i64x2();
1492    let slice = slice as *const i8;
1493    let r = pgatherqd(src, slice, offsets, mask, SCALE as i8);
1494    transmute(r)
1495}
1496
1497/// Returns values from `slice` at offsets determined by `offsets * scale`,
1498/// where
1499/// `scale` should be 1, 2, 4 or 8.
1500///
1501/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_i64gather_epi32)
1502#[inline]
1503#[target_feature(enable = "avx2")]
1504#[cfg_attr(test, assert_instr(vpgatherqd, SCALE = 1))]
1505#[rustc_legacy_const_generics(2)]
1506#[stable(feature = "simd_x86", since = "1.27.0")]
1507pub unsafe fn _mm256_i64gather_epi32<const SCALE: i32>(
1508    slice: *const i32,
1509    offsets: __m256i,
1510) -> __m128i {
1511    static_assert_imm8_scale!(SCALE);
1512    let zero = i32x4::ZERO;
1513    let neg_one = _mm_set1_epi64x(-1).as_i32x4();
1514    let offsets = offsets.as_i64x4();
1515    let slice = slice as *const i8;
1516    let r = vpgatherqd(zero, slice, offsets, neg_one, SCALE as i8);
1517    transmute(r)
1518}
1519
1520/// Returns values from `slice` at offsets determined by `offsets * scale`,
1521/// where
1522/// `scale` should be 1, 2, 4 or 8. If mask is set, load the value from `src` in
1523/// that position instead.
1524///
1525/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mask_i64gather_epi32)
1526#[inline]
1527#[target_feature(enable = "avx2")]
1528#[cfg_attr(test, assert_instr(vpgatherqd, SCALE = 1))]
1529#[rustc_legacy_const_generics(4)]
1530#[stable(feature = "simd_x86", since = "1.27.0")]
1531pub unsafe fn _mm256_mask_i64gather_epi32<const SCALE: i32>(
1532    src: __m128i,
1533    slice: *const i32,
1534    offsets: __m256i,
1535    mask: __m128i,
1536) -> __m128i {
1537    static_assert_imm8_scale!(SCALE);
1538    let src = src.as_i32x4();
1539    let mask = mask.as_i32x4();
1540    let offsets = offsets.as_i64x4();
1541    let slice = slice as *const i8;
1542    let r = vpgatherqd(src, slice, offsets, mask, SCALE as i8);
1543    transmute(r)
1544}
1545
1546/// Returns values from `slice` at offsets determined by `offsets * scale`,
1547/// where
1548/// `scale` should be 1, 2, 4 or 8.
1549///
1550/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_i64gather_ps)
1551#[inline]
1552#[target_feature(enable = "avx2")]
1553#[cfg_attr(test, assert_instr(vgatherqps, SCALE = 1))]
1554#[rustc_legacy_const_generics(2)]
1555#[stable(feature = "simd_x86", since = "1.27.0")]
1556pub unsafe fn _mm_i64gather_ps<const SCALE: i32>(slice: *const f32, offsets: __m128i) -> __m128 {
1557    static_assert_imm8_scale!(SCALE);
1558    let zero = _mm_setzero_ps();
1559    let neg_one = _mm_set1_ps(-1.0);
1560    let offsets = offsets.as_i64x2();
1561    let slice = slice as *const i8;
1562    pgatherqps(zero, slice, offsets, neg_one, SCALE as i8)
1563}
1564
1565/// Returns values from `slice` at offsets determined by `offsets * scale`,
1566/// where
1567/// `scale` should be 1, 2, 4 or 8. If mask is set, load the value from `src` in
1568/// that position instead.
1569///
1570/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mask_i64gather_ps)
1571#[inline]
1572#[target_feature(enable = "avx2")]
1573#[cfg_attr(test, assert_instr(vgatherqps, SCALE = 1))]
1574#[rustc_legacy_const_generics(4)]
1575#[stable(feature = "simd_x86", since = "1.27.0")]
1576pub unsafe fn _mm_mask_i64gather_ps<const SCALE: i32>(
1577    src: __m128,
1578    slice: *const f32,
1579    offsets: __m128i,
1580    mask: __m128,
1581) -> __m128 {
1582    static_assert_imm8_scale!(SCALE);
1583    let offsets = offsets.as_i64x2();
1584    let slice = slice as *const i8;
1585    pgatherqps(src, slice, offsets, mask, SCALE as i8)
1586}
1587
1588/// Returns values from `slice` at offsets determined by `offsets * scale`,
1589/// where
1590/// `scale` should be 1, 2, 4 or 8.
1591///
1592/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_i64gather_ps)
1593#[inline]
1594#[target_feature(enable = "avx2")]
1595#[cfg_attr(test, assert_instr(vgatherqps, SCALE = 1))]
1596#[rustc_legacy_const_generics(2)]
1597#[stable(feature = "simd_x86", since = "1.27.0")]
1598pub unsafe fn _mm256_i64gather_ps<const SCALE: i32>(slice: *const f32, offsets: __m256i) -> __m128 {
1599    static_assert_imm8_scale!(SCALE);
1600    let zero = _mm_setzero_ps();
1601    let neg_one = _mm_set1_ps(-1.0);
1602    let offsets = offsets.as_i64x4();
1603    let slice = slice as *const i8;
1604    vpgatherqps(zero, slice, offsets, neg_one, SCALE as i8)
1605}
1606
1607/// Returns values from `slice` at offsets determined by `offsets * scale`,
1608/// where
1609/// `scale` should be 1, 2, 4 or 8. If mask is set, load the value from `src` in
1610/// that position instead.
1611///
1612/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mask_i64gather_ps)
1613#[inline]
1614#[target_feature(enable = "avx2")]
1615#[cfg_attr(test, assert_instr(vgatherqps, SCALE = 1))]
1616#[rustc_legacy_const_generics(4)]
1617#[stable(feature = "simd_x86", since = "1.27.0")]
1618pub unsafe fn _mm256_mask_i64gather_ps<const SCALE: i32>(
1619    src: __m128,
1620    slice: *const f32,
1621    offsets: __m256i,
1622    mask: __m128,
1623) -> __m128 {
1624    static_assert_imm8_scale!(SCALE);
1625    let offsets = offsets.as_i64x4();
1626    let slice = slice as *const i8;
1627    vpgatherqps(src, slice, offsets, mask, SCALE as i8)
1628}
1629
1630/// Returns values from `slice` at offsets determined by `offsets * scale`,
1631/// where
1632/// `scale` should be 1, 2, 4 or 8.
1633///
1634/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_i64gather_epi64)
1635#[inline]
1636#[target_feature(enable = "avx2")]
1637#[cfg_attr(test, assert_instr(vpgatherqq, SCALE = 1))]
1638#[rustc_legacy_const_generics(2)]
1639#[stable(feature = "simd_x86", since = "1.27.0")]
1640pub unsafe fn _mm_i64gather_epi64<const SCALE: i32>(
1641    slice: *const i64,
1642    offsets: __m128i,
1643) -> __m128i {
1644    static_assert_imm8_scale!(SCALE);
1645    let zero = i64x2::ZERO;
1646    let neg_one = _mm_set1_epi64x(-1).as_i64x2();
1647    let slice = slice as *const i8;
1648    let offsets = offsets.as_i64x2();
1649    let r = pgatherqq(zero, slice, offsets, neg_one, SCALE as i8);
1650    transmute(r)
1651}
1652
1653/// Returns values from `slice` at offsets determined by `offsets * scale`,
1654/// where
1655/// `scale` should be 1, 2, 4 or 8. If mask is set, load the value from `src` in
1656/// that position instead.
1657///
1658/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mask_i64gather_epi64)
1659#[inline]
1660#[target_feature(enable = "avx2")]
1661#[cfg_attr(test, assert_instr(vpgatherqq, SCALE = 1))]
1662#[rustc_legacy_const_generics(4)]
1663#[stable(feature = "simd_x86", since = "1.27.0")]
1664pub unsafe fn _mm_mask_i64gather_epi64<const SCALE: i32>(
1665    src: __m128i,
1666    slice: *const i64,
1667    offsets: __m128i,
1668    mask: __m128i,
1669) -> __m128i {
1670    static_assert_imm8_scale!(SCALE);
1671    let src = src.as_i64x2();
1672    let mask = mask.as_i64x2();
1673    let offsets = offsets.as_i64x2();
1674    let slice = slice as *const i8;
1675    let r = pgatherqq(src, slice, offsets, mask, SCALE as i8);
1676    transmute(r)
1677}
1678
1679/// Returns values from `slice` at offsets determined by `offsets * scale`,
1680/// where
1681/// `scale` should be 1, 2, 4 or 8.
1682///
1683/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_i64gather_epi64)
1684#[inline]
1685#[target_feature(enable = "avx2")]
1686#[cfg_attr(test, assert_instr(vpgatherqq, SCALE = 1))]
1687#[rustc_legacy_const_generics(2)]
1688#[stable(feature = "simd_x86", since = "1.27.0")]
1689pub unsafe fn _mm256_i64gather_epi64<const SCALE: i32>(
1690    slice: *const i64,
1691    offsets: __m256i,
1692) -> __m256i {
1693    static_assert_imm8_scale!(SCALE);
1694    let zero = i64x4::ZERO;
1695    let neg_one = _mm256_set1_epi64x(-1).as_i64x4();
1696    let slice = slice as *const i8;
1697    let offsets = offsets.as_i64x4();
1698    let r = vpgatherqq(zero, slice, offsets, neg_one, SCALE as i8);
1699    transmute(r)
1700}
1701
1702/// Returns values from `slice` at offsets determined by `offsets * scale`,
1703/// where
1704/// `scale` should be 1, 2, 4 or 8. If mask is set, load the value from `src` in
1705/// that position instead.
1706///
1707/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mask_i64gather_epi64)
1708#[inline]
1709#[target_feature(enable = "avx2")]
1710#[cfg_attr(test, assert_instr(vpgatherqq, SCALE = 1))]
1711#[rustc_legacy_const_generics(4)]
1712#[stable(feature = "simd_x86", since = "1.27.0")]
1713pub unsafe fn _mm256_mask_i64gather_epi64<const SCALE: i32>(
1714    src: __m256i,
1715    slice: *const i64,
1716    offsets: __m256i,
1717    mask: __m256i,
1718) -> __m256i {
1719    static_assert_imm8_scale!(SCALE);
1720    let src = src.as_i64x4();
1721    let mask = mask.as_i64x4();
1722    let offsets = offsets.as_i64x4();
1723    let slice = slice as *const i8;
1724    let r = vpgatherqq(src, slice, offsets, mask, SCALE as i8);
1725    transmute(r)
1726}
1727
1728/// Returns values from `slice` at offsets determined by `offsets * scale`,
1729/// where
1730/// `scale` should be 1, 2, 4 or 8.
1731///
1732/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_i64gather_pd)
1733#[inline]
1734#[target_feature(enable = "avx2")]
1735#[cfg_attr(test, assert_instr(vgatherqpd, SCALE = 1))]
1736#[rustc_legacy_const_generics(2)]
1737#[stable(feature = "simd_x86", since = "1.27.0")]
1738pub unsafe fn _mm_i64gather_pd<const SCALE: i32>(slice: *const f64, offsets: __m128i) -> __m128d {
1739    static_assert_imm8_scale!(SCALE);
1740    let zero = _mm_setzero_pd();
1741    let neg_one = _mm_set1_pd(-1.0);
1742    let slice = slice as *const i8;
1743    let offsets = offsets.as_i64x2();
1744    pgatherqpd(zero, slice, offsets, neg_one, SCALE as i8)
1745}
1746
1747/// Returns values from `slice` at offsets determined by `offsets * scale`,
1748/// where
1749/// `scale` should be 1, 2, 4 or 8. If mask is set, load the value from `src` in
1750/// that position instead.
1751///
1752/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mask_i64gather_pd)
1753#[inline]
1754#[target_feature(enable = "avx2")]
1755#[cfg_attr(test, assert_instr(vgatherqpd, SCALE = 1))]
1756#[rustc_legacy_const_generics(4)]
1757#[stable(feature = "simd_x86", since = "1.27.0")]
1758pub unsafe fn _mm_mask_i64gather_pd<const SCALE: i32>(
1759    src: __m128d,
1760    slice: *const f64,
1761    offsets: __m128i,
1762    mask: __m128d,
1763) -> __m128d {
1764    static_assert_imm8_scale!(SCALE);
1765    let slice = slice as *const i8;
1766    let offsets = offsets.as_i64x2();
1767    pgatherqpd(src, slice, offsets, mask, SCALE as i8)
1768}
1769
1770/// Returns values from `slice` at offsets determined by `offsets * scale`,
1771/// where
1772/// `scale` should be 1, 2, 4 or 8.
1773///
1774/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_i64gather_pd)
1775#[inline]
1776#[target_feature(enable = "avx2")]
1777#[cfg_attr(test, assert_instr(vgatherqpd, SCALE = 1))]
1778#[rustc_legacy_const_generics(2)]
1779#[stable(feature = "simd_x86", since = "1.27.0")]
1780pub unsafe fn _mm256_i64gather_pd<const SCALE: i32>(
1781    slice: *const f64,
1782    offsets: __m256i,
1783) -> __m256d {
1784    static_assert_imm8_scale!(SCALE);
1785    let zero = _mm256_setzero_pd();
1786    let neg_one = _mm256_set1_pd(-1.0);
1787    let slice = slice as *const i8;
1788    let offsets = offsets.as_i64x4();
1789    vpgatherqpd(zero, slice, offsets, neg_one, SCALE as i8)
1790}
1791
1792/// Returns values from `slice` at offsets determined by `offsets * scale`,
1793/// where
1794/// `scale` should be 1, 2, 4 or 8. If mask is set, load the value from `src` in
1795/// that position instead.
1796///
1797/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mask_i64gather_pd)
1798#[inline]
1799#[target_feature(enable = "avx2")]
1800#[cfg_attr(test, assert_instr(vgatherqpd, SCALE = 1))]
1801#[rustc_legacy_const_generics(4)]
1802#[stable(feature = "simd_x86", since = "1.27.0")]
1803pub unsafe fn _mm256_mask_i64gather_pd<const SCALE: i32>(
1804    src: __m256d,
1805    slice: *const f64,
1806    offsets: __m256i,
1807    mask: __m256d,
1808) -> __m256d {
1809    static_assert_imm8_scale!(SCALE);
1810    let slice = slice as *const i8;
1811    let offsets = offsets.as_i64x4();
1812    vpgatherqpd(src, slice, offsets, mask, SCALE as i8)
1813}
1814
1815/// Copies `a` to `dst`, then insert 128 bits (of integer data) from `b` at the
1816/// location specified by `IMM1`.
1817///
1818/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_inserti128_si256)
1819#[inline]
1820#[target_feature(enable = "avx2")]
1821#[cfg_attr(test, assert_instr(vinsertf128, IMM1 = 1))]
1822#[rustc_legacy_const_generics(2)]
1823#[stable(feature = "simd_x86", since = "1.27.0")]
1824#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1825pub const fn _mm256_inserti128_si256<const IMM1: i32>(a: __m256i, b: __m128i) -> __m256i {
1826    static_assert_uimm_bits!(IMM1, 1);
1827    unsafe {
1828        let a = a.as_i64x4();
1829        let b = _mm256_castsi128_si256(b).as_i64x4();
1830        let dst: i64x4 = simd_shuffle!(a, b, [[4, 5, 2, 3], [0, 1, 4, 5]][IMM1 as usize]);
1831        transmute(dst)
1832    }
1833}
1834
1835/// Multiplies packed signed 16-bit integers in `a` and `b`, producing
1836/// intermediate signed 32-bit integers. Horizontally add adjacent pairs
1837/// of intermediate 32-bit integers.
1838///
1839/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_madd_epi16)
1840#[inline]
1841#[target_feature(enable = "avx2")]
1842#[cfg_attr(test, assert_instr(vpmaddwd))]
1843#[stable(feature = "simd_x86", since = "1.27.0")]
1844pub fn _mm256_madd_epi16(a: __m256i, b: __m256i) -> __m256i {
1845    // It's a trick used in the Adler-32 algorithm to perform a widening addition.
1846    //
1847    // ```rust
1848    // #[target_feature(enable = "avx2")]
1849    // unsafe fn widening_add(mad: __m256i) -> __m256i {
1850    //     _mm256_madd_epi16(mad, _mm256_set1_epi16(1))
1851    // }
1852    // ```
1853    //
1854    // If we implement this using generic vector intrinsics, the optimizer
1855    // will eliminate this pattern, and `vpmaddwd` will no longer be emitted.
1856    // For this reason, we use x86 intrinsics.
1857    unsafe { transmute(pmaddwd(a.as_i16x16(), b.as_i16x16())) }
1858}
1859
1860/// Vertically multiplies each unsigned 8-bit integer from `a` with the
1861/// corresponding signed 8-bit integer from `b`, producing intermediate
1862/// signed 16-bit integers. Horizontally add adjacent pairs of intermediate
1863/// signed 16-bit integers
1864///
1865/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_maddubs_epi16)
1866#[inline]
1867#[target_feature(enable = "avx2")]
1868#[cfg_attr(test, assert_instr(vpmaddubsw))]
1869#[stable(feature = "simd_x86", since = "1.27.0")]
1870pub fn _mm256_maddubs_epi16(a: __m256i, b: __m256i) -> __m256i {
1871    unsafe { transmute(pmaddubsw(a.as_u8x32(), b.as_i8x32())) }
1872}
1873
1874/// Loads packed 32-bit integers from memory pointed by `mem_addr` using `mask`
1875/// (elements are zeroed out when the highest bit is not set in the
1876/// corresponding element).
1877///
1878/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_maskload_epi32)
1879#[inline]
1880#[target_feature(enable = "avx2")]
1881#[cfg_attr(test, assert_instr(vpmaskmovd))]
1882#[stable(feature = "simd_x86", since = "1.27.0")]
1883#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1884pub const unsafe fn _mm_maskload_epi32(mem_addr: *const i32, mask: __m128i) -> __m128i {
1885    let mask = simd_shr(mask.as_i32x4(), i32x4::splat(31));
1886    simd_masked_load!(SimdAlign::Unaligned, mask, mem_addr, i32x4::ZERO).as_m128i()
1887}
1888
1889/// Loads packed 32-bit integers from memory pointed by `mem_addr` using `mask`
1890/// (elements are zeroed out when the highest bit is not set in the
1891/// corresponding element).
1892///
1893/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_maskload_epi32)
1894#[inline]
1895#[target_feature(enable = "avx2")]
1896#[cfg_attr(test, assert_instr(vpmaskmovd))]
1897#[stable(feature = "simd_x86", since = "1.27.0")]
1898#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1899pub const unsafe fn _mm256_maskload_epi32(mem_addr: *const i32, mask: __m256i) -> __m256i {
1900    let mask = simd_shr(mask.as_i32x8(), i32x8::splat(31));
1901    simd_masked_load!(SimdAlign::Unaligned, mask, mem_addr, i32x8::ZERO).as_m256i()
1902}
1903
1904/// Loads packed 64-bit integers from memory pointed by `mem_addr` using `mask`
1905/// (elements are zeroed out when the highest bit is not set in the
1906/// corresponding element).
1907///
1908/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_maskload_epi64)
1909#[inline]
1910#[target_feature(enable = "avx2")]
1911#[cfg_attr(test, assert_instr(vpmaskmovq))]
1912#[stable(feature = "simd_x86", since = "1.27.0")]
1913#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1914pub const unsafe fn _mm_maskload_epi64(mem_addr: *const i64, mask: __m128i) -> __m128i {
1915    let mask = simd_shr(mask.as_i64x2(), i64x2::splat(63));
1916    simd_masked_load!(SimdAlign::Unaligned, mask, mem_addr, i64x2::ZERO).as_m128i()
1917}
1918
1919/// Loads packed 64-bit integers from memory pointed by `mem_addr` using `mask`
1920/// (elements are zeroed out when the highest bit is not set in the
1921/// corresponding element).
1922///
1923/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_maskload_epi64)
1924#[inline]
1925#[target_feature(enable = "avx2")]
1926#[cfg_attr(test, assert_instr(vpmaskmovq))]
1927#[stable(feature = "simd_x86", since = "1.27.0")]
1928#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1929pub const unsafe fn _mm256_maskload_epi64(mem_addr: *const i64, mask: __m256i) -> __m256i {
1930    let mask = simd_shr(mask.as_i64x4(), i64x4::splat(63));
1931    simd_masked_load!(SimdAlign::Unaligned, mask, mem_addr, i64x4::ZERO).as_m256i()
1932}
1933
1934/// Stores packed 32-bit integers from `a` into memory pointed by `mem_addr`
1935/// using `mask` (elements are not stored when the highest bit is not set
1936/// in the corresponding element).
1937///
1938/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_maskstore_epi32)
1939#[inline]
1940#[target_feature(enable = "avx2")]
1941#[cfg_attr(test, assert_instr(vpmaskmovd))]
1942#[stable(feature = "simd_x86", since = "1.27.0")]
1943#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1944pub const unsafe fn _mm_maskstore_epi32(mem_addr: *mut i32, mask: __m128i, a: __m128i) {
1945    let mask = simd_shr(mask.as_i32x4(), i32x4::splat(31));
1946    simd_masked_store!(SimdAlign::Unaligned, mask, mem_addr, a.as_i32x4())
1947}
1948
1949/// Stores packed 32-bit integers from `a` into memory pointed by `mem_addr`
1950/// using `mask` (elements are not stored when the highest bit is not set
1951/// in the corresponding element).
1952///
1953/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_maskstore_epi32)
1954#[inline]
1955#[target_feature(enable = "avx2")]
1956#[cfg_attr(test, assert_instr(vpmaskmovd))]
1957#[stable(feature = "simd_x86", since = "1.27.0")]
1958#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1959pub const unsafe fn _mm256_maskstore_epi32(mem_addr: *mut i32, mask: __m256i, a: __m256i) {
1960    let mask = simd_shr(mask.as_i32x8(), i32x8::splat(31));
1961    simd_masked_store!(SimdAlign::Unaligned, mask, mem_addr, a.as_i32x8())
1962}
1963
1964/// Stores packed 64-bit integers from `a` into memory pointed by `mem_addr`
1965/// using `mask` (elements are not stored when the highest bit is not set
1966/// in the corresponding element).
1967///
1968/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_maskstore_epi64)
1969#[inline]
1970#[target_feature(enable = "avx2")]
1971#[cfg_attr(test, assert_instr(vpmaskmovq))]
1972#[stable(feature = "simd_x86", since = "1.27.0")]
1973#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1974pub const unsafe fn _mm_maskstore_epi64(mem_addr: *mut i64, mask: __m128i, a: __m128i) {
1975    let mask = simd_shr(mask.as_i64x2(), i64x2::splat(63));
1976    simd_masked_store!(SimdAlign::Unaligned, mask, mem_addr, a.as_i64x2())
1977}
1978
1979/// Stores packed 64-bit integers from `a` into memory pointed by `mem_addr`
1980/// using `mask` (elements are not stored when the highest bit is not set
1981/// in the corresponding element).
1982///
1983/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_maskstore_epi64)
1984#[inline]
1985#[target_feature(enable = "avx2")]
1986#[cfg_attr(test, assert_instr(vpmaskmovq))]
1987#[stable(feature = "simd_x86", since = "1.27.0")]
1988#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1989pub const unsafe fn _mm256_maskstore_epi64(mem_addr: *mut i64, mask: __m256i, a: __m256i) {
1990    let mask = simd_shr(mask.as_i64x4(), i64x4::splat(63));
1991    simd_masked_store!(SimdAlign::Unaligned, mask, mem_addr, a.as_i64x4())
1992}
1993
1994/// Compares packed 16-bit integers in `a` and `b`, and returns the packed
1995/// maximum values.
1996///
1997/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_max_epi16)
1998#[inline]
1999#[target_feature(enable = "avx2")]
2000#[cfg_attr(test, assert_instr(vpmaxsw))]
2001#[stable(feature = "simd_x86", since = "1.27.0")]
2002#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2003pub const fn _mm256_max_epi16(a: __m256i, b: __m256i) -> __m256i {
2004    unsafe { simd_imax(a.as_i16x16(), b.as_i16x16()).as_m256i() }
2005}
2006
2007/// Compares packed 32-bit integers in `a` and `b`, and returns the packed
2008/// maximum values.
2009///
2010/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_max_epi32)
2011#[inline]
2012#[target_feature(enable = "avx2")]
2013#[cfg_attr(test, assert_instr(vpmaxsd))]
2014#[stable(feature = "simd_x86", since = "1.27.0")]
2015#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2016pub const fn _mm256_max_epi32(a: __m256i, b: __m256i) -> __m256i {
2017    unsafe { simd_imax(a.as_i32x8(), b.as_i32x8()).as_m256i() }
2018}
2019
2020/// Compares packed 8-bit integers in `a` and `b`, and returns the packed
2021/// maximum values.
2022///
2023/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_max_epi8)
2024#[inline]
2025#[target_feature(enable = "avx2")]
2026#[cfg_attr(test, assert_instr(vpmaxsb))]
2027#[stable(feature = "simd_x86", since = "1.27.0")]
2028#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2029pub const fn _mm256_max_epi8(a: __m256i, b: __m256i) -> __m256i {
2030    unsafe { simd_imax(a.as_i8x32(), b.as_i8x32()).as_m256i() }
2031}
2032
2033/// Compares packed unsigned 16-bit integers in `a` and `b`, and returns
2034/// the packed maximum values.
2035///
2036/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_max_epu16)
2037#[inline]
2038#[target_feature(enable = "avx2")]
2039#[cfg_attr(test, assert_instr(vpmaxuw))]
2040#[stable(feature = "simd_x86", since = "1.27.0")]
2041#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2042pub const fn _mm256_max_epu16(a: __m256i, b: __m256i) -> __m256i {
2043    unsafe { simd_imax(a.as_u16x16(), b.as_u16x16()).as_m256i() }
2044}
2045
2046/// Compares packed unsigned 32-bit integers in `a` and `b`, and returns
2047/// the packed maximum values.
2048///
2049/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_max_epu32)
2050#[inline]
2051#[target_feature(enable = "avx2")]
2052#[cfg_attr(test, assert_instr(vpmaxud))]
2053#[stable(feature = "simd_x86", since = "1.27.0")]
2054#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2055pub const fn _mm256_max_epu32(a: __m256i, b: __m256i) -> __m256i {
2056    unsafe { simd_imax(a.as_u32x8(), b.as_u32x8()).as_m256i() }
2057}
2058
2059/// Compares packed unsigned 8-bit integers in `a` and `b`, and returns
2060/// the packed maximum values.
2061///
2062/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_max_epu8)
2063#[inline]
2064#[target_feature(enable = "avx2")]
2065#[cfg_attr(test, assert_instr(vpmaxub))]
2066#[stable(feature = "simd_x86", since = "1.27.0")]
2067#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2068pub const fn _mm256_max_epu8(a: __m256i, b: __m256i) -> __m256i {
2069    unsafe { simd_imax(a.as_u8x32(), b.as_u8x32()).as_m256i() }
2070}
2071
2072/// Compares packed 16-bit integers in `a` and `b`, and returns the packed
2073/// minimum values.
2074///
2075/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_min_epi16)
2076#[inline]
2077#[target_feature(enable = "avx2")]
2078#[cfg_attr(test, assert_instr(vpminsw))]
2079#[stable(feature = "simd_x86", since = "1.27.0")]
2080#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2081pub const fn _mm256_min_epi16(a: __m256i, b: __m256i) -> __m256i {
2082    unsafe { simd_imin(a.as_i16x16(), b.as_i16x16()).as_m256i() }
2083}
2084
2085/// Compares packed 32-bit integers in `a` and `b`, and returns the packed
2086/// minimum values.
2087///
2088/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_min_epi32)
2089#[inline]
2090#[target_feature(enable = "avx2")]
2091#[cfg_attr(test, assert_instr(vpminsd))]
2092#[stable(feature = "simd_x86", since = "1.27.0")]
2093#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2094pub const fn _mm256_min_epi32(a: __m256i, b: __m256i) -> __m256i {
2095    unsafe { simd_imin(a.as_i32x8(), b.as_i32x8()).as_m256i() }
2096}
2097
2098/// Compares packed 8-bit integers in `a` and `b`, and returns the packed
2099/// minimum values.
2100///
2101/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_min_epi8)
2102#[inline]
2103#[target_feature(enable = "avx2")]
2104#[cfg_attr(test, assert_instr(vpminsb))]
2105#[stable(feature = "simd_x86", since = "1.27.0")]
2106#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2107pub const fn _mm256_min_epi8(a: __m256i, b: __m256i) -> __m256i {
2108    unsafe { simd_imin(a.as_i8x32(), b.as_i8x32()).as_m256i() }
2109}
2110
2111/// Compares packed unsigned 16-bit integers in `a` and `b`, and returns
2112/// the packed minimum values.
2113///
2114/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_min_epu16)
2115#[inline]
2116#[target_feature(enable = "avx2")]
2117#[cfg_attr(test, assert_instr(vpminuw))]
2118#[stable(feature = "simd_x86", since = "1.27.0")]
2119#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2120pub const fn _mm256_min_epu16(a: __m256i, b: __m256i) -> __m256i {
2121    unsafe { simd_imin(a.as_u16x16(), b.as_u16x16()).as_m256i() }
2122}
2123
2124/// Compares packed unsigned 32-bit integers in `a` and `b`, and returns
2125/// the packed minimum values.
2126///
2127/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_min_epu32)
2128#[inline]
2129#[target_feature(enable = "avx2")]
2130#[cfg_attr(test, assert_instr(vpminud))]
2131#[stable(feature = "simd_x86", since = "1.27.0")]
2132#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2133pub const fn _mm256_min_epu32(a: __m256i, b: __m256i) -> __m256i {
2134    unsafe { simd_imin(a.as_u32x8(), b.as_u32x8()).as_m256i() }
2135}
2136
2137/// Compares packed unsigned 8-bit integers in `a` and `b`, and returns
2138/// the packed minimum values.
2139///
2140/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_min_epu8)
2141#[inline]
2142#[target_feature(enable = "avx2")]
2143#[cfg_attr(test, assert_instr(vpminub))]
2144#[stable(feature = "simd_x86", since = "1.27.0")]
2145#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2146pub const fn _mm256_min_epu8(a: __m256i, b: __m256i) -> __m256i {
2147    unsafe { simd_imin(a.as_u8x32(), b.as_u8x32()).as_m256i() }
2148}
2149
2150/// Creates mask from the most significant bit of each 8-bit element in `a`,
2151/// return the result.
2152///
2153/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_movemask_epi8)
2154#[inline]
2155#[target_feature(enable = "avx2")]
2156#[cfg_attr(test, assert_instr(vpmovmskb))]
2157#[stable(feature = "simd_x86", since = "1.27.0")]
2158#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2159pub const fn _mm256_movemask_epi8(a: __m256i) -> i32 {
2160    unsafe {
2161        let z = i8x32::ZERO;
2162        let m: i8x32 = simd_lt(a.as_i8x32(), z);
2163        simd_bitmask::<_, u32>(m) as i32
2164    }
2165}
2166
2167/// Computes the sum of absolute differences (SADs) of quadruplets of unsigned
2168/// 8-bit integers in `a` compared to those in `b`, and stores the 16-bit
2169/// results in dst. Eight SADs are performed for each 128-bit lane using one
2170/// quadruplet from `b` and eight quadruplets from `a`. One quadruplet is
2171/// selected from `b` starting at on the offset specified in `imm8`. Eight
2172/// quadruplets are formed from sequential 8-bit integers selected from `a`
2173/// starting at the offset specified in `imm8`.
2174///
2175/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mpsadbw_epu8)
2176#[inline]
2177#[target_feature(enable = "avx2")]
2178#[cfg_attr(test, assert_instr(vmpsadbw, IMM8 = 0))]
2179#[rustc_legacy_const_generics(2)]
2180#[stable(feature = "simd_x86", since = "1.27.0")]
2181pub fn _mm256_mpsadbw_epu8<const IMM8: i32>(a: __m256i, b: __m256i) -> __m256i {
2182    static_assert_uimm_bits!(IMM8, 8);
2183    unsafe { transmute(mpsadbw(a.as_u8x32(), b.as_u8x32(), IMM8 as i8)) }
2184}
2185
2186/// Multiplies the low 32-bit integers from each packed 64-bit element in
2187/// `a` and `b`
2188///
2189/// Returns the 64-bit results.
2190///
2191/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mul_epi32)
2192#[inline]
2193#[target_feature(enable = "avx2")]
2194#[cfg_attr(test, assert_instr(vpmuldq))]
2195#[stable(feature = "simd_x86", since = "1.27.0")]
2196#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2197pub const fn _mm256_mul_epi32(a: __m256i, b: __m256i) -> __m256i {
2198    unsafe {
2199        let a = simd_cast::<_, i64x4>(simd_cast::<_, i32x4>(a.as_i64x4()));
2200        let b = simd_cast::<_, i64x4>(simd_cast::<_, i32x4>(b.as_i64x4()));
2201        transmute(simd_mul(a, b))
2202    }
2203}
2204
2205/// Multiplies the low unsigned 32-bit integers from each packed 64-bit
2206/// element in `a` and `b`
2207///
2208/// Returns the unsigned 64-bit results.
2209///
2210/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mul_epu32)
2211#[inline]
2212#[target_feature(enable = "avx2")]
2213#[cfg_attr(test, assert_instr(vpmuludq))]
2214#[stable(feature = "simd_x86", since = "1.27.0")]
2215#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2216pub const fn _mm256_mul_epu32(a: __m256i, b: __m256i) -> __m256i {
2217    unsafe {
2218        let a = a.as_u64x4();
2219        let b = b.as_u64x4();
2220        let mask = u64x4::splat(u32::MAX as u64);
2221        transmute(simd_mul(simd_and(a, mask), simd_and(b, mask)))
2222    }
2223}
2224
2225/// Multiplies the packed 16-bit integers in `a` and `b`, producing
2226/// intermediate 32-bit integers and returning the high 16 bits of the
2227/// intermediate integers.
2228///
2229/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mulhi_epi16)
2230#[inline]
2231#[target_feature(enable = "avx2")]
2232#[cfg_attr(test, assert_instr(vpmulhw))]
2233#[stable(feature = "simd_x86", since = "1.27.0")]
2234#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2235pub const fn _mm256_mulhi_epi16(a: __m256i, b: __m256i) -> __m256i {
2236    unsafe {
2237        let a = simd_cast::<_, i32x16>(a.as_i16x16());
2238        let b = simd_cast::<_, i32x16>(b.as_i16x16());
2239        let r = simd_shr(simd_mul(a, b), i32x16::splat(16));
2240        transmute(simd_cast::<i32x16, i16x16>(r))
2241    }
2242}
2243
2244/// Multiplies the packed unsigned 16-bit integers in `a` and `b`, producing
2245/// intermediate 32-bit integers and returning the high 16 bits of the
2246/// intermediate integers.
2247///
2248/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mulhi_epu16)
2249#[inline]
2250#[target_feature(enable = "avx2")]
2251#[cfg_attr(test, assert_instr(vpmulhuw))]
2252#[stable(feature = "simd_x86", since = "1.27.0")]
2253#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2254pub const fn _mm256_mulhi_epu16(a: __m256i, b: __m256i) -> __m256i {
2255    unsafe {
2256        let a = simd_cast::<_, u32x16>(a.as_u16x16());
2257        let b = simd_cast::<_, u32x16>(b.as_u16x16());
2258        let r = simd_shr(simd_mul(a, b), u32x16::splat(16));
2259        transmute(simd_cast::<u32x16, u16x16>(r))
2260    }
2261}
2262
2263/// Multiplies the packed 16-bit integers in `a` and `b`, producing
2264/// intermediate 32-bit integers, and returns the low 16 bits of the
2265/// intermediate integers
2266///
2267/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mullo_epi16)
2268#[inline]
2269#[target_feature(enable = "avx2")]
2270#[cfg_attr(test, assert_instr(vpmullw))]
2271#[stable(feature = "simd_x86", since = "1.27.0")]
2272#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2273pub const fn _mm256_mullo_epi16(a: __m256i, b: __m256i) -> __m256i {
2274    unsafe { transmute(simd_mul(a.as_i16x16(), b.as_i16x16())) }
2275}
2276
2277/// Multiplies the packed 32-bit integers in `a` and `b`, producing
2278/// intermediate 64-bit integers, and returns the low 32 bits of the
2279/// intermediate integers
2280///
2281/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mullo_epi32)
2282#[inline]
2283#[target_feature(enable = "avx2")]
2284#[cfg_attr(test, assert_instr(vpmulld))]
2285#[stable(feature = "simd_x86", since = "1.27.0")]
2286#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2287pub const fn _mm256_mullo_epi32(a: __m256i, b: __m256i) -> __m256i {
2288    unsafe { transmute(simd_mul(a.as_i32x8(), b.as_i32x8())) }
2289}
2290
2291/// Multiplies packed 16-bit integers in `a` and `b`, producing
2292/// intermediate signed 32-bit integers. Truncate each intermediate
2293/// integer to the 18 most significant bits, round by adding 1, and
2294/// return bits `[16:1]`.
2295///
2296/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mulhrs_epi16)
2297#[inline]
2298#[target_feature(enable = "avx2")]
2299#[cfg_attr(test, assert_instr(vpmulhrsw))]
2300#[stable(feature = "simd_x86", since = "1.27.0")]
2301pub fn _mm256_mulhrs_epi16(a: __m256i, b: __m256i) -> __m256i {
2302    unsafe { transmute(pmulhrsw(a.as_i16x16(), b.as_i16x16())) }
2303}
2304
2305/// Computes the bitwise OR of 256 bits (representing integer data) in `a`
2306/// and `b`
2307///
2308/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_or_si256)
2309#[inline]
2310#[target_feature(enable = "avx2")]
2311#[cfg_attr(test, assert_instr(vorps))]
2312#[stable(feature = "simd_x86", since = "1.27.0")]
2313#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2314pub const fn _mm256_or_si256(a: __m256i, b: __m256i) -> __m256i {
2315    unsafe { transmute(simd_or(a.as_i32x8(), b.as_i32x8())) }
2316}
2317
2318/// Converts packed 16-bit integers from `a` and `b` to packed 8-bit integers
2319/// using signed saturation
2320///
2321/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_packs_epi16)
2322#[inline]
2323#[target_feature(enable = "avx2")]
2324#[cfg_attr(test, assert_instr(vpacksswb))]
2325#[stable(feature = "simd_x86", since = "1.27.0")]
2326pub fn _mm256_packs_epi16(a: __m256i, b: __m256i) -> __m256i {
2327    unsafe { transmute(packsswb(a.as_i16x16(), b.as_i16x16())) }
2328}
2329
2330/// Converts packed 32-bit integers from `a` and `b` to packed 16-bit integers
2331/// using signed saturation
2332///
2333/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_packs_epi32)
2334#[inline]
2335#[target_feature(enable = "avx2")]
2336#[cfg_attr(test, assert_instr(vpackssdw))]
2337#[stable(feature = "simd_x86", since = "1.27.0")]
2338pub fn _mm256_packs_epi32(a: __m256i, b: __m256i) -> __m256i {
2339    unsafe { transmute(packssdw(a.as_i32x8(), b.as_i32x8())) }
2340}
2341
2342/// Converts packed 16-bit integers from `a` and `b` to packed 8-bit integers
2343/// using unsigned saturation
2344///
2345/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_packus_epi16)
2346#[inline]
2347#[target_feature(enable = "avx2")]
2348#[cfg_attr(test, assert_instr(vpackuswb))]
2349#[stable(feature = "simd_x86", since = "1.27.0")]
2350pub fn _mm256_packus_epi16(a: __m256i, b: __m256i) -> __m256i {
2351    unsafe { transmute(packuswb(a.as_i16x16(), b.as_i16x16())) }
2352}
2353
2354/// Converts packed 32-bit integers from `a` and `b` to packed 16-bit integers
2355/// using unsigned saturation
2356///
2357/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_packus_epi32)
2358#[inline]
2359#[target_feature(enable = "avx2")]
2360#[cfg_attr(test, assert_instr(vpackusdw))]
2361#[stable(feature = "simd_x86", since = "1.27.0")]
2362pub fn _mm256_packus_epi32(a: __m256i, b: __m256i) -> __m256i {
2363    unsafe { transmute(packusdw(a.as_i32x8(), b.as_i32x8())) }
2364}
2365
2366/// Permutes packed 32-bit integers from `a` according to the content of `b`.
2367///
2368/// The last 3 bits of each integer of `b` are used as addresses into the 8
2369/// integers of `a`.
2370///
2371/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_permutevar8x32_epi32)
2372#[inline]
2373#[target_feature(enable = "avx2")]
2374#[cfg_attr(test, assert_instr(vpermps))]
2375#[stable(feature = "simd_x86", since = "1.27.0")]
2376pub fn _mm256_permutevar8x32_epi32(a: __m256i, b: __m256i) -> __m256i {
2377    unsafe { transmute(permd(a.as_u32x8(), b.as_u32x8())) }
2378}
2379
2380/// Permutes 64-bit integers from `a` using control mask `imm8`.
2381///
2382/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_permute4x64_epi64)
2383#[inline]
2384#[target_feature(enable = "avx2")]
2385#[cfg_attr(test, assert_instr(vpermpd, IMM8 = 9))]
2386#[rustc_legacy_const_generics(1)]
2387#[stable(feature = "simd_x86", since = "1.27.0")]
2388#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2389pub const fn _mm256_permute4x64_epi64<const IMM8: i32>(a: __m256i) -> __m256i {
2390    static_assert_uimm_bits!(IMM8, 8);
2391    unsafe {
2392        let zero = i64x4::ZERO;
2393        let r: i64x4 = simd_shuffle!(
2394            a.as_i64x4(),
2395            zero,
2396            [
2397                IMM8 as u32 & 0b11,
2398                (IMM8 as u32 >> 2) & 0b11,
2399                (IMM8 as u32 >> 4) & 0b11,
2400                (IMM8 as u32 >> 6) & 0b11,
2401            ],
2402        );
2403        transmute(r)
2404    }
2405}
2406
2407/// Shuffles 128-bits of integer data selected by `imm8` from `a` and `b`.
2408///
2409/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_permute2x128_si256)
2410#[inline]
2411#[target_feature(enable = "avx2")]
2412#[cfg_attr(test, assert_instr(vperm2f128, IMM8 = 9))]
2413#[rustc_legacy_const_generics(2)]
2414#[stable(feature = "simd_x86", since = "1.27.0")]
2415#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2416pub const fn _mm256_permute2x128_si256<const IMM8: i32>(a: __m256i, b: __m256i) -> __m256i {
2417    static_assert_uimm_bits!(IMM8, 8);
2418    _mm256_permute2f128_si256::<IMM8>(a, b)
2419}
2420
2421/// Shuffles 64-bit floating-point elements in `a` across lanes using the
2422/// control in `imm8`.
2423///
2424/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_permute4x64_pd)
2425#[inline]
2426#[target_feature(enable = "avx2")]
2427#[cfg_attr(test, assert_instr(vpermpd, IMM8 = 1))]
2428#[rustc_legacy_const_generics(1)]
2429#[stable(feature = "simd_x86", since = "1.27.0")]
2430#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2431pub const fn _mm256_permute4x64_pd<const IMM8: i32>(a: __m256d) -> __m256d {
2432    static_assert_uimm_bits!(IMM8, 8);
2433    unsafe {
2434        simd_shuffle!(
2435            a,
2436            _mm256_undefined_pd(),
2437            [
2438                IMM8 as u32 & 0b11,
2439                (IMM8 as u32 >> 2) & 0b11,
2440                (IMM8 as u32 >> 4) & 0b11,
2441                (IMM8 as u32 >> 6) & 0b11,
2442            ],
2443        )
2444    }
2445}
2446
2447/// Shuffles eight 32-bit floating-point elements in `a` across lanes using
2448/// the corresponding 32-bit integer index in `idx`.
2449///
2450/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_permutevar8x32_ps)
2451#[inline]
2452#[target_feature(enable = "avx2")]
2453#[cfg_attr(test, assert_instr(vpermps))]
2454#[stable(feature = "simd_x86", since = "1.27.0")]
2455pub fn _mm256_permutevar8x32_ps(a: __m256, idx: __m256i) -> __m256 {
2456    unsafe { permps(a, idx.as_i32x8()) }
2457}
2458
2459/// Computes the absolute differences of packed unsigned 8-bit integers in `a`
2460/// and `b`, then horizontally sum each consecutive 8 differences to
2461/// produce four unsigned 16-bit integers, and pack these unsigned 16-bit
2462/// integers in the low 16 bits of the 64-bit return value
2463///
2464/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_sad_epu8)
2465#[inline]
2466#[target_feature(enable = "avx2")]
2467#[cfg_attr(test, assert_instr(vpsadbw))]
2468#[stable(feature = "simd_x86", since = "1.27.0")]
2469pub fn _mm256_sad_epu8(a: __m256i, b: __m256i) -> __m256i {
2470    unsafe { transmute(psadbw(a.as_u8x32(), b.as_u8x32())) }
2471}
2472
2473/// Shuffles bytes from `a` according to the content of `b`.
2474///
2475/// For each of the 128-bit low and high halves of the vectors, the last
2476/// 4 bits of each byte of `b` are used as addresses into the respective
2477/// low or high 16 bytes of `a`. That is, the halves are shuffled separately.
2478///
2479/// In addition, if the highest significant bit of a byte of `b` is set, the
2480/// respective destination byte is set to 0.
2481///
2482/// Picturing `a` and `b` as `[u8; 32]`, `_mm256_shuffle_epi8` is logically
2483/// equivalent to:
2484///
2485/// ```
2486/// fn mm256_shuffle_epi8(a: [u8; 32], b: [u8; 32]) -> [u8; 32] {
2487///     let mut r = [0; 32];
2488///     for i in 0..16 {
2489///         // if the most significant bit of b is set,
2490///         // then the destination byte is set to 0.
2491///         if b[i] & 0x80 == 0u8 {
2492///             r[i] = a[(b[i] % 16) as usize];
2493///         }
2494///         if b[i + 16] & 0x80 == 0u8 {
2495///             r[i + 16] = a[(b[i + 16] % 16 + 16) as usize];
2496///         }
2497///     }
2498///     r
2499/// }
2500/// ```
2501///
2502/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_shuffle_epi8)
2503#[inline]
2504#[target_feature(enable = "avx2")]
2505#[cfg_attr(test, assert_instr(vpshufb))]
2506#[stable(feature = "simd_x86", since = "1.27.0")]
2507pub fn _mm256_shuffle_epi8(a: __m256i, b: __m256i) -> __m256i {
2508    unsafe { transmute(pshufb(a.as_u8x32(), b.as_u8x32())) }
2509}
2510
2511/// Shuffles 32-bit integers in 128-bit lanes of `a` using the control in
2512/// `imm8`.
2513///
2514/// ```rust
2515/// #[cfg(target_arch = "x86")]
2516/// use std::arch::x86::*;
2517/// #[cfg(target_arch = "x86_64")]
2518/// use std::arch::x86_64::*;
2519///
2520/// # fn main() {
2521/// #     if is_x86_feature_detected!("avx2") {
2522/// #         #[target_feature(enable = "avx2")]
2523/// #         unsafe fn worker() {
2524/// let a = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7);
2525///
2526/// let c1 = _mm256_shuffle_epi32(a, 0b00_11_10_01);
2527/// let c2 = _mm256_shuffle_epi32(a, 0b01_00_10_11);
2528///
2529/// let expected1 = _mm256_setr_epi32(1, 2, 3, 0, 5, 6, 7, 4);
2530/// let expected2 = _mm256_setr_epi32(3, 2, 0, 1, 7, 6, 4, 5);
2531///
2532/// assert_eq!(_mm256_movemask_epi8(_mm256_cmpeq_epi8(c1, expected1)), !0);
2533/// assert_eq!(_mm256_movemask_epi8(_mm256_cmpeq_epi8(c2, expected2)), !0);
2534/// #         }
2535/// #         unsafe { worker(); }
2536/// #     }
2537/// # }
2538/// ```
2539///
2540/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_shuffle_epi32)
2541#[inline]
2542#[target_feature(enable = "avx2")]
2543#[cfg_attr(test, assert_instr(vshufps, MASK = 9))]
2544#[rustc_legacy_const_generics(1)]
2545#[stable(feature = "simd_x86", since = "1.27.0")]
2546#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2547pub const fn _mm256_shuffle_epi32<const MASK: i32>(a: __m256i) -> __m256i {
2548    static_assert_uimm_bits!(MASK, 8);
2549    unsafe {
2550        let r: i32x8 = simd_shuffle!(
2551            a.as_i32x8(),
2552            a.as_i32x8(),
2553            [
2554                MASK as u32 & 0b11,
2555                (MASK as u32 >> 2) & 0b11,
2556                (MASK as u32 >> 4) & 0b11,
2557                (MASK as u32 >> 6) & 0b11,
2558                (MASK as u32 & 0b11) + 4,
2559                ((MASK as u32 >> 2) & 0b11) + 4,
2560                ((MASK as u32 >> 4) & 0b11) + 4,
2561                ((MASK as u32 >> 6) & 0b11) + 4,
2562            ],
2563        );
2564        transmute(r)
2565    }
2566}
2567
2568/// Shuffles 16-bit integers in the high 64 bits of 128-bit lanes of `a` using
2569/// the control in `imm8`. The low 64 bits of 128-bit lanes of `a` are copied
2570/// to the output.
2571///
2572/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_shufflehi_epi16)
2573#[inline]
2574#[target_feature(enable = "avx2")]
2575#[cfg_attr(test, assert_instr(vpshufhw, IMM8 = 9))]
2576#[rustc_legacy_const_generics(1)]
2577#[stable(feature = "simd_x86", since = "1.27.0")]
2578#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2579pub const fn _mm256_shufflehi_epi16<const IMM8: i32>(a: __m256i) -> __m256i {
2580    static_assert_uimm_bits!(IMM8, 8);
2581    unsafe {
2582        let a = a.as_i16x16();
2583        let r: i16x16 = simd_shuffle!(
2584            a,
2585            a,
2586            [
2587                0,
2588                1,
2589                2,
2590                3,
2591                4 + (IMM8 as u32 & 0b11),
2592                4 + ((IMM8 as u32 >> 2) & 0b11),
2593                4 + ((IMM8 as u32 >> 4) & 0b11),
2594                4 + ((IMM8 as u32 >> 6) & 0b11),
2595                8,
2596                9,
2597                10,
2598                11,
2599                12 + (IMM8 as u32 & 0b11),
2600                12 + ((IMM8 as u32 >> 2) & 0b11),
2601                12 + ((IMM8 as u32 >> 4) & 0b11),
2602                12 + ((IMM8 as u32 >> 6) & 0b11),
2603            ],
2604        );
2605        transmute(r)
2606    }
2607}
2608
2609/// Shuffles 16-bit integers in the low 64 bits of 128-bit lanes of `a` using
2610/// the control in `imm8`. The high 64 bits of 128-bit lanes of `a` are copied
2611/// to the output.
2612///
2613/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_shufflelo_epi16)
2614#[inline]
2615#[target_feature(enable = "avx2")]
2616#[cfg_attr(test, assert_instr(vpshuflw, IMM8 = 9))]
2617#[rustc_legacy_const_generics(1)]
2618#[stable(feature = "simd_x86", since = "1.27.0")]
2619#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2620pub const fn _mm256_shufflelo_epi16<const IMM8: i32>(a: __m256i) -> __m256i {
2621    static_assert_uimm_bits!(IMM8, 8);
2622    unsafe {
2623        let a = a.as_i16x16();
2624        let r: i16x16 = simd_shuffle!(
2625            a,
2626            a,
2627            [
2628                0 + (IMM8 as u32 & 0b11),
2629                0 + ((IMM8 as u32 >> 2) & 0b11),
2630                0 + ((IMM8 as u32 >> 4) & 0b11),
2631                0 + ((IMM8 as u32 >> 6) & 0b11),
2632                4,
2633                5,
2634                6,
2635                7,
2636                8 + (IMM8 as u32 & 0b11),
2637                8 + ((IMM8 as u32 >> 2) & 0b11),
2638                8 + ((IMM8 as u32 >> 4) & 0b11),
2639                8 + ((IMM8 as u32 >> 6) & 0b11),
2640                12,
2641                13,
2642                14,
2643                15,
2644            ],
2645        );
2646        transmute(r)
2647    }
2648}
2649
2650/// Negates packed 16-bit integers in `a` when the corresponding signed
2651/// 16-bit integer in `b` is negative, and returns the results.
2652/// Results are zeroed out when the corresponding element in `b` is zero.
2653///
2654/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_sign_epi16)
2655#[inline]
2656#[target_feature(enable = "avx2")]
2657#[cfg_attr(test, assert_instr(vpsignw))]
2658#[stable(feature = "simd_x86", since = "1.27.0")]
2659pub fn _mm256_sign_epi16(a: __m256i, b: __m256i) -> __m256i {
2660    unsafe { transmute(psignw(a.as_i16x16(), b.as_i16x16())) }
2661}
2662
2663/// Negates packed 32-bit integers in `a` when the corresponding signed
2664/// 32-bit integer in `b` is negative, and returns the results.
2665/// Results are zeroed out when the corresponding element in `b` is zero.
2666///
2667/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_sign_epi32)
2668#[inline]
2669#[target_feature(enable = "avx2")]
2670#[cfg_attr(test, assert_instr(vpsignd))]
2671#[stable(feature = "simd_x86", since = "1.27.0")]
2672pub fn _mm256_sign_epi32(a: __m256i, b: __m256i) -> __m256i {
2673    unsafe { transmute(psignd(a.as_i32x8(), b.as_i32x8())) }
2674}
2675
2676/// Negates packed 8-bit integers in `a` when the corresponding signed
2677/// 8-bit integer in `b` is negative, and returns the results.
2678/// Results are zeroed out when the corresponding element in `b` is zero.
2679///
2680/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_sign_epi8)
2681#[inline]
2682#[target_feature(enable = "avx2")]
2683#[cfg_attr(test, assert_instr(vpsignb))]
2684#[stable(feature = "simd_x86", since = "1.27.0")]
2685pub fn _mm256_sign_epi8(a: __m256i, b: __m256i) -> __m256i {
2686    unsafe { transmute(psignb(a.as_i8x32(), b.as_i8x32())) }
2687}
2688
2689/// Shifts packed 16-bit integers in `a` left by `count` while
2690/// shifting in zeros, and returns the result
2691///
2692/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_sll_epi16)
2693#[inline]
2694#[target_feature(enable = "avx2")]
2695#[cfg_attr(test, assert_instr(vpsllw))]
2696#[stable(feature = "simd_x86", since = "1.27.0")]
2697pub fn _mm256_sll_epi16(a: __m256i, count: __m128i) -> __m256i {
2698    unsafe { transmute(psllw(a.as_i16x16(), count.as_i16x8())) }
2699}
2700
2701/// Shifts packed 32-bit integers in `a` left by `count` while
2702/// shifting in zeros, and returns the result
2703///
2704/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_sll_epi32)
2705#[inline]
2706#[target_feature(enable = "avx2")]
2707#[cfg_attr(test, assert_instr(vpslld))]
2708#[stable(feature = "simd_x86", since = "1.27.0")]
2709pub fn _mm256_sll_epi32(a: __m256i, count: __m128i) -> __m256i {
2710    unsafe { transmute(pslld(a.as_i32x8(), count.as_i32x4())) }
2711}
2712
2713/// Shifts packed 64-bit integers in `a` left by `count` while
2714/// shifting in zeros, and returns the result
2715///
2716/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_sll_epi64)
2717#[inline]
2718#[target_feature(enable = "avx2")]
2719#[cfg_attr(test, assert_instr(vpsllq))]
2720#[stable(feature = "simd_x86", since = "1.27.0")]
2721pub fn _mm256_sll_epi64(a: __m256i, count: __m128i) -> __m256i {
2722    unsafe { transmute(psllq(a.as_i64x4(), count.as_i64x2())) }
2723}
2724
2725/// Shifts packed 16-bit integers in `a` left by `IMM8` while
2726/// shifting in zeros, return the results;
2727///
2728/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_slli_epi16)
2729#[inline]
2730#[target_feature(enable = "avx2")]
2731#[cfg_attr(test, assert_instr(vpsllw, IMM8 = 7))]
2732#[rustc_legacy_const_generics(1)]
2733#[stable(feature = "simd_x86", since = "1.27.0")]
2734#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2735pub const fn _mm256_slli_epi16<const IMM8: i32>(a: __m256i) -> __m256i {
2736    static_assert_uimm_bits!(IMM8, 8);
2737    unsafe {
2738        if IMM8 >= 16 {
2739            _mm256_setzero_si256()
2740        } else {
2741            transmute(simd_shl(a.as_u16x16(), u16x16::splat(IMM8 as u16)))
2742        }
2743    }
2744}
2745
2746/// Shifts packed 32-bit integers in `a` left by `IMM8` while
2747/// shifting in zeros, return the results;
2748///
2749/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_slli_epi32)
2750#[inline]
2751#[target_feature(enable = "avx2")]
2752#[cfg_attr(test, assert_instr(vpslld, IMM8 = 7))]
2753#[rustc_legacy_const_generics(1)]
2754#[stable(feature = "simd_x86", since = "1.27.0")]
2755#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2756pub const fn _mm256_slli_epi32<const IMM8: i32>(a: __m256i) -> __m256i {
2757    unsafe {
2758        static_assert_uimm_bits!(IMM8, 8);
2759        if IMM8 >= 32 {
2760            _mm256_setzero_si256()
2761        } else {
2762            transmute(simd_shl(a.as_u32x8(), u32x8::splat(IMM8 as u32)))
2763        }
2764    }
2765}
2766
2767/// Shifts packed 64-bit integers in `a` left by `IMM8` while
2768/// shifting in zeros, return the results;
2769///
2770/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_slli_epi64)
2771#[inline]
2772#[target_feature(enable = "avx2")]
2773#[cfg_attr(test, assert_instr(vpsllq, IMM8 = 7))]
2774#[rustc_legacy_const_generics(1)]
2775#[stable(feature = "simd_x86", since = "1.27.0")]
2776#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2777pub const fn _mm256_slli_epi64<const IMM8: i32>(a: __m256i) -> __m256i {
2778    unsafe {
2779        static_assert_uimm_bits!(IMM8, 8);
2780        if IMM8 >= 64 {
2781            _mm256_setzero_si256()
2782        } else {
2783            transmute(simd_shl(a.as_u64x4(), u64x4::splat(IMM8 as u64)))
2784        }
2785    }
2786}
2787
2788/// Shifts 128-bit lanes in `a` left by `imm8` bytes while shifting in zeros.
2789///
2790/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_slli_si256)
2791#[inline]
2792#[target_feature(enable = "avx2")]
2793#[cfg_attr(test, assert_instr(vpslldq, IMM8 = 3))]
2794#[rustc_legacy_const_generics(1)]
2795#[stable(feature = "simd_x86", since = "1.27.0")]
2796#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2797pub const fn _mm256_slli_si256<const IMM8: i32>(a: __m256i) -> __m256i {
2798    static_assert_uimm_bits!(IMM8, 8);
2799    _mm256_bslli_epi128::<IMM8>(a)
2800}
2801
2802/// Shifts 128-bit lanes in `a` left by `imm8` bytes while shifting in zeros.
2803///
2804/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_bslli_epi128)
2805#[inline]
2806#[target_feature(enable = "avx2")]
2807#[cfg_attr(test, assert_instr(vpslldq, IMM8 = 3))]
2808#[rustc_legacy_const_generics(1)]
2809#[stable(feature = "simd_x86", since = "1.27.0")]
2810#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2811pub const fn _mm256_bslli_epi128<const IMM8: i32>(a: __m256i) -> __m256i {
2812    static_assert_uimm_bits!(IMM8, 8);
2813    const fn mask(shift: i32, i: u32) -> u32 {
2814        let shift = shift as u32 & 0xff;
2815        if shift > 15 || i % 16 < shift {
2816            0
2817        } else {
2818            32 + (i - shift)
2819        }
2820    }
2821    unsafe {
2822        let a = a.as_i8x32();
2823        let r: i8x32 = simd_shuffle!(
2824            i8x32::ZERO,
2825            a,
2826            [
2827                mask(IMM8, 0),
2828                mask(IMM8, 1),
2829                mask(IMM8, 2),
2830                mask(IMM8, 3),
2831                mask(IMM8, 4),
2832                mask(IMM8, 5),
2833                mask(IMM8, 6),
2834                mask(IMM8, 7),
2835                mask(IMM8, 8),
2836                mask(IMM8, 9),
2837                mask(IMM8, 10),
2838                mask(IMM8, 11),
2839                mask(IMM8, 12),
2840                mask(IMM8, 13),
2841                mask(IMM8, 14),
2842                mask(IMM8, 15),
2843                mask(IMM8, 16),
2844                mask(IMM8, 17),
2845                mask(IMM8, 18),
2846                mask(IMM8, 19),
2847                mask(IMM8, 20),
2848                mask(IMM8, 21),
2849                mask(IMM8, 22),
2850                mask(IMM8, 23),
2851                mask(IMM8, 24),
2852                mask(IMM8, 25),
2853                mask(IMM8, 26),
2854                mask(IMM8, 27),
2855                mask(IMM8, 28),
2856                mask(IMM8, 29),
2857                mask(IMM8, 30),
2858                mask(IMM8, 31),
2859            ],
2860        );
2861        transmute(r)
2862    }
2863}
2864
2865/// Shifts packed 32-bit integers in `a` left by the amount
2866/// specified by the corresponding element in `count` while
2867/// shifting in zeros, and returns the result.
2868///
2869/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sllv_epi32)
2870#[inline]
2871#[target_feature(enable = "avx2")]
2872#[cfg_attr(test, assert_instr(vpsllvd))]
2873#[stable(feature = "simd_x86", since = "1.27.0")]
2874pub fn _mm_sllv_epi32(a: __m128i, count: __m128i) -> __m128i {
2875    unsafe { transmute(psllvd(a.as_i32x4(), count.as_i32x4())) }
2876}
2877
2878/// Shifts packed 32-bit integers in `a` left by the amount
2879/// specified by the corresponding element in `count` while
2880/// shifting in zeros, and returns the result.
2881///
2882/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_sllv_epi32)
2883#[inline]
2884#[target_feature(enable = "avx2")]
2885#[cfg_attr(test, assert_instr(vpsllvd))]
2886#[stable(feature = "simd_x86", since = "1.27.0")]
2887pub fn _mm256_sllv_epi32(a: __m256i, count: __m256i) -> __m256i {
2888    unsafe { transmute(psllvd256(a.as_i32x8(), count.as_i32x8())) }
2889}
2890
2891/// Shifts packed 64-bit integers in `a` left by the amount
2892/// specified by the corresponding element in `count` while
2893/// shifting in zeros, and returns the result.
2894///
2895/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sllv_epi64)
2896#[inline]
2897#[target_feature(enable = "avx2")]
2898#[cfg_attr(test, assert_instr(vpsllvq))]
2899#[stable(feature = "simd_x86", since = "1.27.0")]
2900pub fn _mm_sllv_epi64(a: __m128i, count: __m128i) -> __m128i {
2901    unsafe { transmute(psllvq(a.as_i64x2(), count.as_i64x2())) }
2902}
2903
2904/// Shifts packed 64-bit integers in `a` left by the amount
2905/// specified by the corresponding element in `count` while
2906/// shifting in zeros, and returns the result.
2907///
2908/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_sllv_epi64)
2909#[inline]
2910#[target_feature(enable = "avx2")]
2911#[cfg_attr(test, assert_instr(vpsllvq))]
2912#[stable(feature = "simd_x86", since = "1.27.0")]
2913pub fn _mm256_sllv_epi64(a: __m256i, count: __m256i) -> __m256i {
2914    unsafe { transmute(psllvq256(a.as_i64x4(), count.as_i64x4())) }
2915}
2916
2917/// Shifts packed 16-bit integers in `a` right by `count` while
2918/// shifting in sign bits.
2919///
2920/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_sra_epi16)
2921#[inline]
2922#[target_feature(enable = "avx2")]
2923#[cfg_attr(test, assert_instr(vpsraw))]
2924#[stable(feature = "simd_x86", since = "1.27.0")]
2925pub fn _mm256_sra_epi16(a: __m256i, count: __m128i) -> __m256i {
2926    unsafe { transmute(psraw(a.as_i16x16(), count.as_i16x8())) }
2927}
2928
2929/// Shifts packed 32-bit integers in `a` right by `count` while
2930/// shifting in sign bits.
2931///
2932/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_sra_epi32)
2933#[inline]
2934#[target_feature(enable = "avx2")]
2935#[cfg_attr(test, assert_instr(vpsrad))]
2936#[stable(feature = "simd_x86", since = "1.27.0")]
2937pub fn _mm256_sra_epi32(a: __m256i, count: __m128i) -> __m256i {
2938    unsafe { transmute(psrad(a.as_i32x8(), count.as_i32x4())) }
2939}
2940
2941/// Shifts packed 16-bit integers in `a` right by `IMM8` while
2942/// shifting in sign bits.
2943///
2944/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_srai_epi16)
2945#[inline]
2946#[target_feature(enable = "avx2")]
2947#[cfg_attr(test, assert_instr(vpsraw, IMM8 = 7))]
2948#[rustc_legacy_const_generics(1)]
2949#[stable(feature = "simd_x86", since = "1.27.0")]
2950#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2951pub const fn _mm256_srai_epi16<const IMM8: i32>(a: __m256i) -> __m256i {
2952    static_assert_uimm_bits!(IMM8, 8);
2953    unsafe { transmute(simd_shr(a.as_i16x16(), i16x16::splat(IMM8.min(15) as i16))) }
2954}
2955
2956/// Shifts packed 32-bit integers in `a` right by `IMM8` while
2957/// shifting in sign bits.
2958///
2959/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_srai_epi32)
2960#[inline]
2961#[target_feature(enable = "avx2")]
2962#[cfg_attr(test, assert_instr(vpsrad, IMM8 = 7))]
2963#[rustc_legacy_const_generics(1)]
2964#[stable(feature = "simd_x86", since = "1.27.0")]
2965#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2966pub const fn _mm256_srai_epi32<const IMM8: i32>(a: __m256i) -> __m256i {
2967    static_assert_uimm_bits!(IMM8, 8);
2968    unsafe { transmute(simd_shr(a.as_i32x8(), i32x8::splat(IMM8.min(31)))) }
2969}
2970
2971/// Shifts packed 32-bit integers in `a` right by the amount specified by the
2972/// corresponding element in `count` while shifting in sign bits.
2973///
2974/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srav_epi32)
2975#[inline]
2976#[target_feature(enable = "avx2")]
2977#[cfg_attr(test, assert_instr(vpsravd))]
2978#[stable(feature = "simd_x86", since = "1.27.0")]
2979pub fn _mm_srav_epi32(a: __m128i, count: __m128i) -> __m128i {
2980    unsafe { transmute(psravd(a.as_i32x4(), count.as_i32x4())) }
2981}
2982
2983/// Shifts packed 32-bit integers in `a` right by the amount specified by the
2984/// corresponding element in `count` while shifting in sign bits.
2985///
2986/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_srav_epi32)
2987#[inline]
2988#[target_feature(enable = "avx2")]
2989#[cfg_attr(test, assert_instr(vpsravd))]
2990#[stable(feature = "simd_x86", since = "1.27.0")]
2991pub fn _mm256_srav_epi32(a: __m256i, count: __m256i) -> __m256i {
2992    unsafe { transmute(psravd256(a.as_i32x8(), count.as_i32x8())) }
2993}
2994
2995/// Shifts 128-bit lanes in `a` right by `imm8` bytes while shifting in zeros.
2996///
2997/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_srli_si256)
2998#[inline]
2999#[target_feature(enable = "avx2")]
3000#[cfg_attr(test, assert_instr(vpsrldq, IMM8 = 1))]
3001#[rustc_legacy_const_generics(1)]
3002#[stable(feature = "simd_x86", since = "1.27.0")]
3003#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3004pub const fn _mm256_srli_si256<const IMM8: i32>(a: __m256i) -> __m256i {
3005    static_assert_uimm_bits!(IMM8, 8);
3006    _mm256_bsrli_epi128::<IMM8>(a)
3007}
3008
3009/// Shifts 128-bit lanes in `a` right by `imm8` bytes while shifting in zeros.
3010///
3011/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_bsrli_epi128)
3012#[inline]
3013#[target_feature(enable = "avx2")]
3014#[cfg_attr(test, assert_instr(vpsrldq, IMM8 = 1))]
3015#[rustc_legacy_const_generics(1)]
3016#[stable(feature = "simd_x86", since = "1.27.0")]
3017#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3018pub const fn _mm256_bsrli_epi128<const IMM8: i32>(a: __m256i) -> __m256i {
3019    static_assert_uimm_bits!(IMM8, 8);
3020    const fn mask(shift: i32, i: u32) -> u32 {
3021        let shift = shift as u32 & 0xff;
3022        if shift > 15 || (15 - (i % 16)) < shift {
3023            0
3024        } else {
3025            32 + (i + shift)
3026        }
3027    }
3028    unsafe {
3029        let a = a.as_i8x32();
3030        let r: i8x32 = simd_shuffle!(
3031            i8x32::ZERO,
3032            a,
3033            [
3034                mask(IMM8, 0),
3035                mask(IMM8, 1),
3036                mask(IMM8, 2),
3037                mask(IMM8, 3),
3038                mask(IMM8, 4),
3039                mask(IMM8, 5),
3040                mask(IMM8, 6),
3041                mask(IMM8, 7),
3042                mask(IMM8, 8),
3043                mask(IMM8, 9),
3044                mask(IMM8, 10),
3045                mask(IMM8, 11),
3046                mask(IMM8, 12),
3047                mask(IMM8, 13),
3048                mask(IMM8, 14),
3049                mask(IMM8, 15),
3050                mask(IMM8, 16),
3051                mask(IMM8, 17),
3052                mask(IMM8, 18),
3053                mask(IMM8, 19),
3054                mask(IMM8, 20),
3055                mask(IMM8, 21),
3056                mask(IMM8, 22),
3057                mask(IMM8, 23),
3058                mask(IMM8, 24),
3059                mask(IMM8, 25),
3060                mask(IMM8, 26),
3061                mask(IMM8, 27),
3062                mask(IMM8, 28),
3063                mask(IMM8, 29),
3064                mask(IMM8, 30),
3065                mask(IMM8, 31),
3066            ],
3067        );
3068        transmute(r)
3069    }
3070}
3071
3072/// Shifts packed 16-bit integers in `a` right by `count` while shifting in
3073/// zeros.
3074///
3075/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_srl_epi16)
3076#[inline]
3077#[target_feature(enable = "avx2")]
3078#[cfg_attr(test, assert_instr(vpsrlw))]
3079#[stable(feature = "simd_x86", since = "1.27.0")]
3080pub fn _mm256_srl_epi16(a: __m256i, count: __m128i) -> __m256i {
3081    unsafe { transmute(psrlw(a.as_i16x16(), count.as_i16x8())) }
3082}
3083
3084/// Shifts packed 32-bit integers in `a` right by `count` while shifting in
3085/// zeros.
3086///
3087/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_srl_epi32)
3088#[inline]
3089#[target_feature(enable = "avx2")]
3090#[cfg_attr(test, assert_instr(vpsrld))]
3091#[stable(feature = "simd_x86", since = "1.27.0")]
3092pub fn _mm256_srl_epi32(a: __m256i, count: __m128i) -> __m256i {
3093    unsafe { transmute(psrld(a.as_i32x8(), count.as_i32x4())) }
3094}
3095
3096/// Shifts packed 64-bit integers in `a` right by `count` while shifting in
3097/// zeros.
3098///
3099/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_srl_epi64)
3100#[inline]
3101#[target_feature(enable = "avx2")]
3102#[cfg_attr(test, assert_instr(vpsrlq))]
3103#[stable(feature = "simd_x86", since = "1.27.0")]
3104pub fn _mm256_srl_epi64(a: __m256i, count: __m128i) -> __m256i {
3105    unsafe { transmute(psrlq(a.as_i64x4(), count.as_i64x2())) }
3106}
3107
3108/// Shifts packed 16-bit integers in `a` right by `IMM8` while shifting in
3109/// zeros
3110///
3111/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_srli_epi16)
3112#[inline]
3113#[target_feature(enable = "avx2")]
3114#[cfg_attr(test, assert_instr(vpsrlw, IMM8 = 7))]
3115#[rustc_legacy_const_generics(1)]
3116#[stable(feature = "simd_x86", since = "1.27.0")]
3117#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3118pub const fn _mm256_srli_epi16<const IMM8: i32>(a: __m256i) -> __m256i {
3119    static_assert_uimm_bits!(IMM8, 8);
3120    unsafe {
3121        if IMM8 >= 16 {
3122            _mm256_setzero_si256()
3123        } else {
3124            transmute(simd_shr(a.as_u16x16(), u16x16::splat(IMM8 as u16)))
3125        }
3126    }
3127}
3128
3129/// Shifts packed 32-bit integers in `a` right by `IMM8` while shifting in
3130/// zeros
3131///
3132/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_srli_epi32)
3133#[inline]
3134#[target_feature(enable = "avx2")]
3135#[cfg_attr(test, assert_instr(vpsrld, IMM8 = 7))]
3136#[rustc_legacy_const_generics(1)]
3137#[stable(feature = "simd_x86", since = "1.27.0")]
3138#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3139pub const fn _mm256_srli_epi32<const IMM8: i32>(a: __m256i) -> __m256i {
3140    static_assert_uimm_bits!(IMM8, 8);
3141    unsafe {
3142        if IMM8 >= 32 {
3143            _mm256_setzero_si256()
3144        } else {
3145            transmute(simd_shr(a.as_u32x8(), u32x8::splat(IMM8 as u32)))
3146        }
3147    }
3148}
3149
3150/// Shifts packed 64-bit integers in `a` right by `IMM8` while shifting in
3151/// zeros
3152///
3153/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_srli_epi64)
3154#[inline]
3155#[target_feature(enable = "avx2")]
3156#[cfg_attr(test, assert_instr(vpsrlq, IMM8 = 7))]
3157#[rustc_legacy_const_generics(1)]
3158#[stable(feature = "simd_x86", since = "1.27.0")]
3159#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3160pub const fn _mm256_srli_epi64<const IMM8: i32>(a: __m256i) -> __m256i {
3161    static_assert_uimm_bits!(IMM8, 8);
3162    unsafe {
3163        if IMM8 >= 64 {
3164            _mm256_setzero_si256()
3165        } else {
3166            transmute(simd_shr(a.as_u64x4(), u64x4::splat(IMM8 as u64)))
3167        }
3168    }
3169}
3170
3171/// Shifts packed 32-bit integers in `a` right by the amount specified by
3172/// the corresponding element in `count` while shifting in zeros,
3173///
3174/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srlv_epi32)
3175#[inline]
3176#[target_feature(enable = "avx2")]
3177#[cfg_attr(test, assert_instr(vpsrlvd))]
3178#[stable(feature = "simd_x86", since = "1.27.0")]
3179pub fn _mm_srlv_epi32(a: __m128i, count: __m128i) -> __m128i {
3180    unsafe { transmute(psrlvd(a.as_i32x4(), count.as_i32x4())) }
3181}
3182
3183/// Shifts packed 32-bit integers in `a` right by the amount specified by
3184/// the corresponding element in `count` while shifting in zeros,
3185///
3186/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_srlv_epi32)
3187#[inline]
3188#[target_feature(enable = "avx2")]
3189#[cfg_attr(test, assert_instr(vpsrlvd))]
3190#[stable(feature = "simd_x86", since = "1.27.0")]
3191pub fn _mm256_srlv_epi32(a: __m256i, count: __m256i) -> __m256i {
3192    unsafe { transmute(psrlvd256(a.as_i32x8(), count.as_i32x8())) }
3193}
3194
3195/// Shifts packed 64-bit integers in `a` right by the amount specified by
3196/// the corresponding element in `count` while shifting in zeros,
3197///
3198/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srlv_epi64)
3199#[inline]
3200#[target_feature(enable = "avx2")]
3201#[cfg_attr(test, assert_instr(vpsrlvq))]
3202#[stable(feature = "simd_x86", since = "1.27.0")]
3203pub fn _mm_srlv_epi64(a: __m128i, count: __m128i) -> __m128i {
3204    unsafe { transmute(psrlvq(a.as_i64x2(), count.as_i64x2())) }
3205}
3206
3207/// Shifts packed 64-bit integers in `a` right by the amount specified by
3208/// the corresponding element in `count` while shifting in zeros,
3209///
3210/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_srlv_epi64)
3211#[inline]
3212#[target_feature(enable = "avx2")]
3213#[cfg_attr(test, assert_instr(vpsrlvq))]
3214#[stable(feature = "simd_x86", since = "1.27.0")]
3215pub fn _mm256_srlv_epi64(a: __m256i, count: __m256i) -> __m256i {
3216    unsafe { transmute(psrlvq256(a.as_i64x4(), count.as_i64x4())) }
3217}
3218
3219/// Load 256-bits of integer data from memory into dst using a non-temporal memory hint. mem_addr
3220/// must be aligned on a 32-byte boundary or a general-protection exception may be generated. To
3221/// minimize caching, the data is flagged as non-temporal (unlikely to be used again soon)
3222///
3223/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_stream_load_si256)
3224#[inline]
3225#[target_feature(enable = "avx2")]
3226#[cfg_attr(test, assert_instr(vmovntdqa))]
3227#[stable(feature = "simd_x86_updates", since = "1.82.0")]
3228pub unsafe fn _mm256_stream_load_si256(mem_addr: *const __m256i) -> __m256i {
3229    let dst: __m256i;
3230    crate::arch::asm!(
3231        vpl!("vmovntdqa {a}"),
3232        a = out(ymm_reg) dst,
3233        p = in(reg) mem_addr,
3234        options(pure, readonly, nostack, preserves_flags),
3235    );
3236    dst
3237}
3238
3239/// Subtract packed 16-bit integers in `b` from packed 16-bit integers in `a`
3240///
3241/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_sub_epi16)
3242#[inline]
3243#[target_feature(enable = "avx2")]
3244#[cfg_attr(test, assert_instr(vpsubw))]
3245#[stable(feature = "simd_x86", since = "1.27.0")]
3246#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3247pub const fn _mm256_sub_epi16(a: __m256i, b: __m256i) -> __m256i {
3248    unsafe { transmute(simd_sub(a.as_i16x16(), b.as_i16x16())) }
3249}
3250
3251/// Subtract packed 32-bit integers in `b` from packed 32-bit integers in `a`
3252///
3253/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_sub_epi32)
3254#[inline]
3255#[target_feature(enable = "avx2")]
3256#[cfg_attr(test, assert_instr(vpsubd))]
3257#[stable(feature = "simd_x86", since = "1.27.0")]
3258#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3259pub const fn _mm256_sub_epi32(a: __m256i, b: __m256i) -> __m256i {
3260    unsafe { transmute(simd_sub(a.as_i32x8(), b.as_i32x8())) }
3261}
3262
3263/// Subtract packed 64-bit integers in `b` from packed 64-bit integers in `a`
3264///
3265/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_sub_epi64)
3266#[inline]
3267#[target_feature(enable = "avx2")]
3268#[cfg_attr(test, assert_instr(vpsubq))]
3269#[stable(feature = "simd_x86", since = "1.27.0")]
3270#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3271pub const fn _mm256_sub_epi64(a: __m256i, b: __m256i) -> __m256i {
3272    unsafe { transmute(simd_sub(a.as_i64x4(), b.as_i64x4())) }
3273}
3274
3275/// Subtract packed 8-bit integers in `b` from packed 8-bit integers in `a`
3276///
3277/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_sub_epi8)
3278#[inline]
3279#[target_feature(enable = "avx2")]
3280#[cfg_attr(test, assert_instr(vpsubb))]
3281#[stable(feature = "simd_x86", since = "1.27.0")]
3282#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3283pub const fn _mm256_sub_epi8(a: __m256i, b: __m256i) -> __m256i {
3284    unsafe { transmute(simd_sub(a.as_i8x32(), b.as_i8x32())) }
3285}
3286
3287/// Subtract packed 16-bit integers in `b` from packed 16-bit integers in
3288/// `a` using saturation.
3289///
3290/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_subs_epi16)
3291#[inline]
3292#[target_feature(enable = "avx2")]
3293#[cfg_attr(test, assert_instr(vpsubsw))]
3294#[stable(feature = "simd_x86", since = "1.27.0")]
3295#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3296pub const fn _mm256_subs_epi16(a: __m256i, b: __m256i) -> __m256i {
3297    unsafe { transmute(simd_saturating_sub(a.as_i16x16(), b.as_i16x16())) }
3298}
3299
3300/// Subtract packed 8-bit integers in `b` from packed 8-bit integers in
3301/// `a` using saturation.
3302///
3303/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_subs_epi8)
3304#[inline]
3305#[target_feature(enable = "avx2")]
3306#[cfg_attr(test, assert_instr(vpsubsb))]
3307#[stable(feature = "simd_x86", since = "1.27.0")]
3308#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3309pub const fn _mm256_subs_epi8(a: __m256i, b: __m256i) -> __m256i {
3310    unsafe { transmute(simd_saturating_sub(a.as_i8x32(), b.as_i8x32())) }
3311}
3312
3313/// Subtract packed unsigned 16-bit integers in `b` from packed 16-bit
3314/// integers in `a` using saturation.
3315///
3316/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_subs_epu16)
3317#[inline]
3318#[target_feature(enable = "avx2")]
3319#[cfg_attr(test, assert_instr(vpsubusw))]
3320#[stable(feature = "simd_x86", since = "1.27.0")]
3321#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3322pub const fn _mm256_subs_epu16(a: __m256i, b: __m256i) -> __m256i {
3323    unsafe { transmute(simd_saturating_sub(a.as_u16x16(), b.as_u16x16())) }
3324}
3325
3326/// Subtract packed unsigned 8-bit integers in `b` from packed 8-bit
3327/// integers in `a` using saturation.
3328///
3329/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_subs_epu8)
3330#[inline]
3331#[target_feature(enable = "avx2")]
3332#[cfg_attr(test, assert_instr(vpsubusb))]
3333#[stable(feature = "simd_x86", since = "1.27.0")]
3334#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3335pub const fn _mm256_subs_epu8(a: __m256i, b: __m256i) -> __m256i {
3336    unsafe { transmute(simd_saturating_sub(a.as_u8x32(), b.as_u8x32())) }
3337}
3338
3339/// Unpacks and interleave 8-bit integers from the high half of each
3340/// 128-bit lane in `a` and `b`.
3341///
3342/// ```rust
3343/// #[cfg(target_arch = "x86")]
3344/// use std::arch::x86::*;
3345/// #[cfg(target_arch = "x86_64")]
3346/// use std::arch::x86_64::*;
3347///
3348/// # fn main() {
3349/// #     if is_x86_feature_detected!("avx2") {
3350/// #         #[target_feature(enable = "avx2")]
3351/// #         unsafe fn worker() {
3352/// let a = _mm256_setr_epi8(
3353///     0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
3354///     20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
3355/// );
3356/// let b = _mm256_setr_epi8(
3357///     0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15,
3358///     -16, -17, -18, -19, -20, -21, -22, -23, -24, -25, -26, -27, -28, -29,
3359///     -30, -31,
3360/// );
3361///
3362/// let c = _mm256_unpackhi_epi8(a, b);
3363///
3364/// let expected = _mm256_setr_epi8(
3365///     8, -8, 9, -9, 10, -10, 11, -11, 12, -12, 13, -13, 14, -14, 15, -15,
3366///     24, -24, 25, -25, 26, -26, 27, -27, 28, -28, 29, -29, 30, -30, 31,
3367///     -31,
3368/// );
3369/// assert_eq!(_mm256_movemask_epi8(_mm256_cmpeq_epi8(c, expected)), !0);
3370///
3371/// #         }
3372/// #         unsafe { worker(); }
3373/// #     }
3374/// # }
3375/// ```
3376///
3377/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_unpackhi_epi8)
3378#[inline]
3379#[target_feature(enable = "avx2")]
3380#[cfg_attr(test, assert_instr(vpunpckhbw))]
3381#[stable(feature = "simd_x86", since = "1.27.0")]
3382#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3383pub const fn _mm256_unpackhi_epi8(a: __m256i, b: __m256i) -> __m256i {
3384    unsafe {
3385        #[rustfmt::skip]
3386        let r: i8x32 = simd_shuffle!(a.as_i8x32(), b.as_i8x32(), [
3387                8, 40, 9, 41, 10, 42, 11, 43,
3388                12, 44, 13, 45, 14, 46, 15, 47,
3389                24, 56, 25, 57, 26, 58, 27, 59,
3390                28, 60, 29, 61, 30, 62, 31, 63,
3391        ]);
3392        transmute(r)
3393    }
3394}
3395
3396/// Unpacks and interleave 8-bit integers from the low half of each
3397/// 128-bit lane of `a` and `b`.
3398///
3399/// ```rust
3400/// #[cfg(target_arch = "x86")]
3401/// use std::arch::x86::*;
3402/// #[cfg(target_arch = "x86_64")]
3403/// use std::arch::x86_64::*;
3404///
3405/// # fn main() {
3406/// #     if is_x86_feature_detected!("avx2") {
3407/// #         #[target_feature(enable = "avx2")]
3408/// #         unsafe fn worker() {
3409/// let a = _mm256_setr_epi8(
3410///     0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
3411///     20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
3412/// );
3413/// let b = _mm256_setr_epi8(
3414///     0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15,
3415///     -16, -17, -18, -19, -20, -21, -22, -23, -24, -25, -26, -27, -28, -29,
3416///     -30, -31,
3417/// );
3418///
3419/// let c = _mm256_unpacklo_epi8(a, b);
3420///
3421/// let expected = _mm256_setr_epi8(
3422///     0, 0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 16, -16, 17,
3423///     -17, 18, -18, 19, -19, 20, -20, 21, -21, 22, -22, 23, -23,
3424/// );
3425/// assert_eq!(_mm256_movemask_epi8(_mm256_cmpeq_epi8(c, expected)), !0);
3426///
3427/// #         }
3428/// #         unsafe { worker(); }
3429/// #     }
3430/// # }
3431/// ```
3432///
3433/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_unpacklo_epi8)
3434#[inline]
3435#[target_feature(enable = "avx2")]
3436#[cfg_attr(test, assert_instr(vpunpcklbw))]
3437#[stable(feature = "simd_x86", since = "1.27.0")]
3438#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3439pub const fn _mm256_unpacklo_epi8(a: __m256i, b: __m256i) -> __m256i {
3440    unsafe {
3441        #[rustfmt::skip]
3442        let r: i8x32 = simd_shuffle!(a.as_i8x32(), b.as_i8x32(), [
3443            0, 32, 1, 33, 2, 34, 3, 35,
3444            4, 36, 5, 37, 6, 38, 7, 39,
3445            16, 48, 17, 49, 18, 50, 19, 51,
3446            20, 52, 21, 53, 22, 54, 23, 55,
3447        ]);
3448        transmute(r)
3449    }
3450}
3451
3452/// Unpacks and interleave 16-bit integers from the high half of each
3453/// 128-bit lane of `a` and `b`.
3454///
3455/// ```rust
3456/// #[cfg(target_arch = "x86")]
3457/// use std::arch::x86::*;
3458/// #[cfg(target_arch = "x86_64")]
3459/// use std::arch::x86_64::*;
3460///
3461/// # fn main() {
3462/// #     if is_x86_feature_detected!("avx2") {
3463/// #         #[target_feature(enable = "avx2")]
3464/// #         unsafe fn worker() {
3465/// let a = _mm256_setr_epi16(
3466///     0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
3467/// );
3468/// let b = _mm256_setr_epi16(
3469///     0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15,
3470/// );
3471///
3472/// let c = _mm256_unpackhi_epi16(a, b);
3473///
3474/// let expected = _mm256_setr_epi16(
3475///     4, -4, 5, -5, 6, -6, 7, -7, 12, -12, 13, -13, 14, -14, 15, -15,
3476/// );
3477/// assert_eq!(_mm256_movemask_epi8(_mm256_cmpeq_epi8(c, expected)), !0);
3478///
3479/// #         }
3480/// #         unsafe { worker(); }
3481/// #     }
3482/// # }
3483/// ```
3484///
3485/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_unpackhi_epi16)
3486#[inline]
3487#[target_feature(enable = "avx2")]
3488#[cfg_attr(test, assert_instr(vpunpckhwd))]
3489#[stable(feature = "simd_x86", since = "1.27.0")]
3490#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3491pub const fn _mm256_unpackhi_epi16(a: __m256i, b: __m256i) -> __m256i {
3492    unsafe {
3493        let r: i16x16 = simd_shuffle!(
3494            a.as_i16x16(),
3495            b.as_i16x16(),
3496            [4, 20, 5, 21, 6, 22, 7, 23, 12, 28, 13, 29, 14, 30, 15, 31],
3497        );
3498        transmute(r)
3499    }
3500}
3501
3502/// Unpacks and interleave 16-bit integers from the low half of each
3503/// 128-bit lane of `a` and `b`.
3504///
3505/// ```rust
3506/// #[cfg(target_arch = "x86")]
3507/// use std::arch::x86::*;
3508/// #[cfg(target_arch = "x86_64")]
3509/// use std::arch::x86_64::*;
3510///
3511/// # fn main() {
3512/// #     if is_x86_feature_detected!("avx2") {
3513/// #         #[target_feature(enable = "avx2")]
3514/// #         unsafe fn worker() {
3515///
3516/// let a = _mm256_setr_epi16(
3517///     0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
3518/// );
3519/// let b = _mm256_setr_epi16(
3520///     0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15,
3521/// );
3522///
3523/// let c = _mm256_unpacklo_epi16(a, b);
3524///
3525/// let expected = _mm256_setr_epi16(
3526///     0, 0, 1, -1, 2, -2, 3, -3, 8, -8, 9, -9, 10, -10, 11, -11,
3527/// );
3528/// assert_eq!(_mm256_movemask_epi8(_mm256_cmpeq_epi8(c, expected)), !0);
3529///
3530/// #         }
3531/// #         unsafe { worker(); }
3532/// #     }
3533/// # }
3534/// ```
3535///
3536/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_unpacklo_epi16)
3537#[inline]
3538#[target_feature(enable = "avx2")]
3539#[cfg_attr(test, assert_instr(vpunpcklwd))]
3540#[stable(feature = "simd_x86", since = "1.27.0")]
3541#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3542pub const fn _mm256_unpacklo_epi16(a: __m256i, b: __m256i) -> __m256i {
3543    unsafe {
3544        let r: i16x16 = simd_shuffle!(
3545            a.as_i16x16(),
3546            b.as_i16x16(),
3547            [0, 16, 1, 17, 2, 18, 3, 19, 8, 24, 9, 25, 10, 26, 11, 27],
3548        );
3549        transmute(r)
3550    }
3551}
3552
3553/// Unpacks and interleave 32-bit integers from the high half of each
3554/// 128-bit lane of `a` and `b`.
3555///
3556/// ```rust
3557/// #[cfg(target_arch = "x86")]
3558/// use std::arch::x86::*;
3559/// #[cfg(target_arch = "x86_64")]
3560/// use std::arch::x86_64::*;
3561///
3562/// # fn main() {
3563/// #     if is_x86_feature_detected!("avx2") {
3564/// #         #[target_feature(enable = "avx2")]
3565/// #         unsafe fn worker() {
3566/// let a = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7);
3567/// let b = _mm256_setr_epi32(0, -1, -2, -3, -4, -5, -6, -7);
3568///
3569/// let c = _mm256_unpackhi_epi32(a, b);
3570///
3571/// let expected = _mm256_setr_epi32(2, -2, 3, -3, 6, -6, 7, -7);
3572/// assert_eq!(_mm256_movemask_epi8(_mm256_cmpeq_epi8(c, expected)), !0);
3573///
3574/// #         }
3575/// #         unsafe { worker(); }
3576/// #     }
3577/// # }
3578/// ```
3579///
3580/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_unpackhi_epi32)
3581#[inline]
3582#[target_feature(enable = "avx2")]
3583#[cfg_attr(test, assert_instr(vunpckhps))]
3584#[stable(feature = "simd_x86", since = "1.27.0")]
3585#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3586pub const fn _mm256_unpackhi_epi32(a: __m256i, b: __m256i) -> __m256i {
3587    unsafe {
3588        let r: i32x8 = simd_shuffle!(a.as_i32x8(), b.as_i32x8(), [2, 10, 3, 11, 6, 14, 7, 15]);
3589        transmute(r)
3590    }
3591}
3592
3593/// Unpacks and interleave 32-bit integers from the low half of each
3594/// 128-bit lane of `a` and `b`.
3595///
3596/// ```rust
3597/// #[cfg(target_arch = "x86")]
3598/// use std::arch::x86::*;
3599/// #[cfg(target_arch = "x86_64")]
3600/// use std::arch::x86_64::*;
3601///
3602/// # fn main() {
3603/// #     if is_x86_feature_detected!("avx2") {
3604/// #         #[target_feature(enable = "avx2")]
3605/// #         unsafe fn worker() {
3606/// let a = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7);
3607/// let b = _mm256_setr_epi32(0, -1, -2, -3, -4, -5, -6, -7);
3608///
3609/// let c = _mm256_unpacklo_epi32(a, b);
3610///
3611/// let expected = _mm256_setr_epi32(0, 0, 1, -1, 4, -4, 5, -5);
3612/// assert_eq!(_mm256_movemask_epi8(_mm256_cmpeq_epi8(c, expected)), !0);
3613///
3614/// #         }
3615/// #         unsafe { worker(); }
3616/// #     }
3617/// # }
3618/// ```
3619///
3620/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_unpacklo_epi32)
3621#[inline]
3622#[target_feature(enable = "avx2")]
3623#[cfg_attr(test, assert_instr(vunpcklps))]
3624#[stable(feature = "simd_x86", since = "1.27.0")]
3625#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3626pub const fn _mm256_unpacklo_epi32(a: __m256i, b: __m256i) -> __m256i {
3627    unsafe {
3628        let r: i32x8 = simd_shuffle!(a.as_i32x8(), b.as_i32x8(), [0, 8, 1, 9, 4, 12, 5, 13]);
3629        transmute(r)
3630    }
3631}
3632
3633/// Unpacks and interleave 64-bit integers from the high half of each
3634/// 128-bit lane of `a` and `b`.
3635///
3636/// ```rust
3637/// #[cfg(target_arch = "x86")]
3638/// use std::arch::x86::*;
3639/// #[cfg(target_arch = "x86_64")]
3640/// use std::arch::x86_64::*;
3641///
3642/// # fn main() {
3643/// #     if is_x86_feature_detected!("avx2") {
3644/// #         #[target_feature(enable = "avx2")]
3645/// #         unsafe fn worker() {
3646/// let a = _mm256_setr_epi64x(0, 1, 2, 3);
3647/// let b = _mm256_setr_epi64x(0, -1, -2, -3);
3648///
3649/// let c = _mm256_unpackhi_epi64(a, b);
3650///
3651/// let expected = _mm256_setr_epi64x(1, -1, 3, -3);
3652/// assert_eq!(_mm256_movemask_epi8(_mm256_cmpeq_epi8(c, expected)), !0);
3653///
3654/// #         }
3655/// #         unsafe { worker(); }
3656/// #     }
3657/// # }
3658/// ```
3659///
3660/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_unpackhi_epi64)
3661#[inline]
3662#[target_feature(enable = "avx2")]
3663#[cfg_attr(test, assert_instr(vunpckhpd))]
3664#[stable(feature = "simd_x86", since = "1.27.0")]
3665#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3666pub const fn _mm256_unpackhi_epi64(a: __m256i, b: __m256i) -> __m256i {
3667    unsafe {
3668        let r: i64x4 = simd_shuffle!(a.as_i64x4(), b.as_i64x4(), [1, 5, 3, 7]);
3669        transmute(r)
3670    }
3671}
3672
3673/// Unpacks and interleave 64-bit integers from the low half of each
3674/// 128-bit lane of `a` and `b`.
3675///
3676/// ```rust
3677/// #[cfg(target_arch = "x86")]
3678/// use std::arch::x86::*;
3679/// #[cfg(target_arch = "x86_64")]
3680/// use std::arch::x86_64::*;
3681///
3682/// # fn main() {
3683/// #     if is_x86_feature_detected!("avx2") {
3684/// #         #[target_feature(enable = "avx2")]
3685/// #         unsafe fn worker() {
3686/// let a = _mm256_setr_epi64x(0, 1, 2, 3);
3687/// let b = _mm256_setr_epi64x(0, -1, -2, -3);
3688///
3689/// let c = _mm256_unpacklo_epi64(a, b);
3690///
3691/// let expected = _mm256_setr_epi64x(0, 0, 2, -2);
3692/// assert_eq!(_mm256_movemask_epi8(_mm256_cmpeq_epi8(c, expected)), !0);
3693///
3694/// #         }
3695/// #         unsafe { worker(); }
3696/// #     }
3697/// # }
3698/// ```
3699///
3700/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_unpacklo_epi64)
3701#[inline]
3702#[target_feature(enable = "avx2")]
3703#[cfg_attr(test, assert_instr(vunpcklpd))]
3704#[stable(feature = "simd_x86", since = "1.27.0")]
3705#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3706pub const fn _mm256_unpacklo_epi64(a: __m256i, b: __m256i) -> __m256i {
3707    unsafe {
3708        let r: i64x4 = simd_shuffle!(a.as_i64x4(), b.as_i64x4(), [0, 4, 2, 6]);
3709        transmute(r)
3710    }
3711}
3712
3713/// Computes the bitwise XOR of 256 bits (representing integer data)
3714/// in `a` and `b`
3715///
3716/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_xor_si256)
3717#[inline]
3718#[target_feature(enable = "avx2")]
3719#[cfg_attr(test, assert_instr(vxorps))]
3720#[stable(feature = "simd_x86", since = "1.27.0")]
3721#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3722pub const fn _mm256_xor_si256(a: __m256i, b: __m256i) -> __m256i {
3723    unsafe { transmute(simd_xor(a.as_i64x4(), b.as_i64x4())) }
3724}
3725
3726/// Extracts an 8-bit integer from `a`, selected with `INDEX`. Returns a 32-bit
3727/// integer containing the zero-extended integer data.
3728///
3729/// See [LLVM commit D20468](https://reviews.llvm.org/D20468).
3730///
3731/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_extract_epi8)
3732#[inline]
3733#[target_feature(enable = "avx2")]
3734// This intrinsic has no corresponding instruction.
3735#[rustc_legacy_const_generics(1)]
3736#[stable(feature = "simd_x86", since = "1.27.0")]
3737#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3738pub const fn _mm256_extract_epi8<const INDEX: i32>(a: __m256i) -> i32 {
3739    static_assert_uimm_bits!(INDEX, 5);
3740    unsafe { simd_extract!(a.as_u8x32(), INDEX as u32, u8) as i32 }
3741}
3742
3743/// Extracts a 16-bit integer from `a`, selected with `INDEX`. Returns a 32-bit
3744/// integer containing the zero-extended integer data.
3745///
3746/// See [LLVM commit D20468](https://reviews.llvm.org/D20468).
3747///
3748/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_extract_epi16)
3749#[inline]
3750#[target_feature(enable = "avx2")]
3751// This intrinsic has no corresponding instruction.
3752#[rustc_legacy_const_generics(1)]
3753#[stable(feature = "simd_x86", since = "1.27.0")]
3754#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3755pub const fn _mm256_extract_epi16<const INDEX: i32>(a: __m256i) -> i32 {
3756    static_assert_uimm_bits!(INDEX, 4);
3757    unsafe { simd_extract!(a.as_u16x16(), INDEX as u32, u16) as i32 }
3758}
3759
3760#[allow(improper_ctypes)]
3761unsafe extern "llvm-intrinsic" {
3762    #[link_name = "llvm.x86.avx2.pmadd.wd"]
3763    fn pmaddwd(a: i16x16, b: i16x16) -> i32x8;
3764    #[link_name = "llvm.x86.avx2.pmadd.ub.sw"]
3765    fn pmaddubsw(a: u8x32, b: i8x32) -> i16x16;
3766    #[link_name = "llvm.x86.avx2.mpsadbw"]
3767    fn mpsadbw(a: u8x32, b: u8x32, imm8: i8) -> u16x16;
3768    #[link_name = "llvm.x86.avx2.pmul.hr.sw"]
3769    fn pmulhrsw(a: i16x16, b: i16x16) -> i16x16;
3770    #[link_name = "llvm.x86.avx2.packsswb"]
3771    fn packsswb(a: i16x16, b: i16x16) -> i8x32;
3772    #[link_name = "llvm.x86.avx2.packssdw"]
3773    fn packssdw(a: i32x8, b: i32x8) -> i16x16;
3774    #[link_name = "llvm.x86.avx2.packuswb"]
3775    fn packuswb(a: i16x16, b: i16x16) -> u8x32;
3776    #[link_name = "llvm.x86.avx2.packusdw"]
3777    fn packusdw(a: i32x8, b: i32x8) -> u16x16;
3778    #[link_name = "llvm.x86.avx2.psad.bw"]
3779    fn psadbw(a: u8x32, b: u8x32) -> u64x4;
3780    #[link_name = "llvm.x86.avx2.psign.b"]
3781    fn psignb(a: i8x32, b: i8x32) -> i8x32;
3782    #[link_name = "llvm.x86.avx2.psign.w"]
3783    fn psignw(a: i16x16, b: i16x16) -> i16x16;
3784    #[link_name = "llvm.x86.avx2.psign.d"]
3785    fn psignd(a: i32x8, b: i32x8) -> i32x8;
3786    #[link_name = "llvm.x86.avx2.psll.w"]
3787    fn psllw(a: i16x16, count: i16x8) -> i16x16;
3788    #[link_name = "llvm.x86.avx2.psll.d"]
3789    fn pslld(a: i32x8, count: i32x4) -> i32x8;
3790    #[link_name = "llvm.x86.avx2.psll.q"]
3791    fn psllq(a: i64x4, count: i64x2) -> i64x4;
3792    #[link_name = "llvm.x86.avx2.psllv.d"]
3793    fn psllvd(a: i32x4, count: i32x4) -> i32x4;
3794    #[link_name = "llvm.x86.avx2.psllv.d.256"]
3795    fn psllvd256(a: i32x8, count: i32x8) -> i32x8;
3796    #[link_name = "llvm.x86.avx2.psllv.q"]
3797    fn psllvq(a: i64x2, count: i64x2) -> i64x2;
3798    #[link_name = "llvm.x86.avx2.psllv.q.256"]
3799    fn psllvq256(a: i64x4, count: i64x4) -> i64x4;
3800    #[link_name = "llvm.x86.avx2.psra.w"]
3801    fn psraw(a: i16x16, count: i16x8) -> i16x16;
3802    #[link_name = "llvm.x86.avx2.psra.d"]
3803    fn psrad(a: i32x8, count: i32x4) -> i32x8;
3804    #[link_name = "llvm.x86.avx2.psrav.d"]
3805    fn psravd(a: i32x4, count: i32x4) -> i32x4;
3806    #[link_name = "llvm.x86.avx2.psrav.d.256"]
3807    fn psravd256(a: i32x8, count: i32x8) -> i32x8;
3808    #[link_name = "llvm.x86.avx2.psrl.w"]
3809    fn psrlw(a: i16x16, count: i16x8) -> i16x16;
3810    #[link_name = "llvm.x86.avx2.psrl.d"]
3811    fn psrld(a: i32x8, count: i32x4) -> i32x8;
3812    #[link_name = "llvm.x86.avx2.psrl.q"]
3813    fn psrlq(a: i64x4, count: i64x2) -> i64x4;
3814    #[link_name = "llvm.x86.avx2.psrlv.d"]
3815    fn psrlvd(a: i32x4, count: i32x4) -> i32x4;
3816    #[link_name = "llvm.x86.avx2.psrlv.d.256"]
3817    fn psrlvd256(a: i32x8, count: i32x8) -> i32x8;
3818    #[link_name = "llvm.x86.avx2.psrlv.q"]
3819    fn psrlvq(a: i64x2, count: i64x2) -> i64x2;
3820    #[link_name = "llvm.x86.avx2.psrlv.q.256"]
3821    fn psrlvq256(a: i64x4, count: i64x4) -> i64x4;
3822    #[link_name = "llvm.x86.avx2.pshuf.b"]
3823    fn pshufb(a: u8x32, b: u8x32) -> u8x32;
3824    #[link_name = "llvm.x86.avx2.permd"]
3825    fn permd(a: u32x8, b: u32x8) -> u32x8;
3826    #[link_name = "llvm.x86.avx2.permps"]
3827    fn permps(a: __m256, b: i32x8) -> __m256;
3828    #[link_name = "llvm.x86.avx2.gather.d.d"]
3829    fn pgatherdd(src: i32x4, slice: *const i8, offsets: i32x4, mask: i32x4, scale: i8) -> i32x4;
3830    #[link_name = "llvm.x86.avx2.gather.d.d.256"]
3831    fn vpgatherdd(src: i32x8, slice: *const i8, offsets: i32x8, mask: i32x8, scale: i8) -> i32x8;
3832    #[link_name = "llvm.x86.avx2.gather.d.q"]
3833    fn pgatherdq(src: i64x2, slice: *const i8, offsets: i32x4, mask: i64x2, scale: i8) -> i64x2;
3834    #[link_name = "llvm.x86.avx2.gather.d.q.256"]
3835    fn vpgatherdq(src: i64x4, slice: *const i8, offsets: i32x4, mask: i64x4, scale: i8) -> i64x4;
3836    #[link_name = "llvm.x86.avx2.gather.q.d"]
3837    fn pgatherqd(src: i32x4, slice: *const i8, offsets: i64x2, mask: i32x4, scale: i8) -> i32x4;
3838    #[link_name = "llvm.x86.avx2.gather.q.d.256"]
3839    fn vpgatherqd(src: i32x4, slice: *const i8, offsets: i64x4, mask: i32x4, scale: i8) -> i32x4;
3840    #[link_name = "llvm.x86.avx2.gather.q.q"]
3841    fn pgatherqq(src: i64x2, slice: *const i8, offsets: i64x2, mask: i64x2, scale: i8) -> i64x2;
3842    #[link_name = "llvm.x86.avx2.gather.q.q.256"]
3843    fn vpgatherqq(src: i64x4, slice: *const i8, offsets: i64x4, mask: i64x4, scale: i8) -> i64x4;
3844    #[link_name = "llvm.x86.avx2.gather.d.pd"]
3845    fn pgatherdpd(
3846        src: __m128d,
3847        slice: *const i8,
3848        offsets: i32x4,
3849        mask: __m128d,
3850        scale: i8,
3851    ) -> __m128d;
3852    #[link_name = "llvm.x86.avx2.gather.d.pd.256"]
3853    fn vpgatherdpd(
3854        src: __m256d,
3855        slice: *const i8,
3856        offsets: i32x4,
3857        mask: __m256d,
3858        scale: i8,
3859    ) -> __m256d;
3860    #[link_name = "llvm.x86.avx2.gather.q.pd"]
3861    fn pgatherqpd(
3862        src: __m128d,
3863        slice: *const i8,
3864        offsets: i64x2,
3865        mask: __m128d,
3866        scale: i8,
3867    ) -> __m128d;
3868    #[link_name = "llvm.x86.avx2.gather.q.pd.256"]
3869    fn vpgatherqpd(
3870        src: __m256d,
3871        slice: *const i8,
3872        offsets: i64x4,
3873        mask: __m256d,
3874        scale: i8,
3875    ) -> __m256d;
3876    #[link_name = "llvm.x86.avx2.gather.d.ps"]
3877    fn pgatherdps(src: __m128, slice: *const i8, offsets: i32x4, mask: __m128, scale: i8)
3878    -> __m128;
3879    #[link_name = "llvm.x86.avx2.gather.d.ps.256"]
3880    fn vpgatherdps(
3881        src: __m256,
3882        slice: *const i8,
3883        offsets: i32x8,
3884        mask: __m256,
3885        scale: i8,
3886    ) -> __m256;
3887    #[link_name = "llvm.x86.avx2.gather.q.ps"]
3888    fn pgatherqps(src: __m128, slice: *const i8, offsets: i64x2, mask: __m128, scale: i8)
3889    -> __m128;
3890    #[link_name = "llvm.x86.avx2.gather.q.ps.256"]
3891    fn vpgatherqps(
3892        src: __m128,
3893        slice: *const i8,
3894        offsets: i64x4,
3895        mask: __m128,
3896        scale: i8,
3897    ) -> __m128;
3898}
3899
3900#[cfg(test)]
3901mod tests {
3902    use crate::core_arch::assert_eq_const as assert_eq;
3903
3904    use stdarch_test::simd_test;
3905
3906    use crate::core_arch::x86::*;
3907
3908    #[simd_test(enable = "avx2")]
3909    const fn test_mm256_abs_epi32() {
3910        #[rustfmt::skip]
3911        let a = _mm256_setr_epi32(
3912            0, 1, -1, i32::MAX,
3913            i32::MIN, 100, -100, -32,
3914        );
3915        let r = _mm256_abs_epi32(a);
3916        #[rustfmt::skip]
3917        let e = _mm256_setr_epi32(
3918            0, 1, 1, i32::MAX,
3919            i32::MAX.wrapping_add(1), 100, 100, 32,
3920        );
3921        assert_eq_m256i(r, e);
3922    }
3923
3924    #[simd_test(enable = "avx2")]
3925    const fn test_mm256_abs_epi16() {
3926        #[rustfmt::skip]
3927        let a = _mm256_setr_epi16(
3928            0,  1, -1, 2, -2, 3, -3, 4,
3929            -4, 5, -5, i16::MAX, i16::MIN, 100, -100, -32,
3930        );
3931        let r = _mm256_abs_epi16(a);
3932        #[rustfmt::skip]
3933        let e = _mm256_setr_epi16(
3934            0, 1, 1, 2, 2, 3, 3, 4,
3935            4, 5, 5, i16::MAX, i16::MAX.wrapping_add(1), 100, 100, 32,
3936        );
3937        assert_eq_m256i(r, e);
3938    }
3939
3940    #[simd_test(enable = "avx2")]
3941    const fn test_mm256_abs_epi8() {
3942        #[rustfmt::skip]
3943        let a = _mm256_setr_epi8(
3944            0, 1, -1, 2, -2, 3, -3, 4,
3945            -4, 5, -5, i8::MAX, i8::MIN, 100, -100, -32,
3946            0, 1, -1, 2, -2, 3, -3, 4,
3947            -4, 5, -5, i8::MAX, i8::MIN, 100, -100, -32,
3948        );
3949        let r = _mm256_abs_epi8(a);
3950        #[rustfmt::skip]
3951        let e = _mm256_setr_epi8(
3952            0, 1, 1, 2, 2, 3, 3, 4,
3953            4, 5, 5, i8::MAX, i8::MAX.wrapping_add(1), 100, 100, 32,
3954            0, 1, 1, 2, 2, 3, 3, 4,
3955            4, 5, 5, i8::MAX, i8::MAX.wrapping_add(1), 100, 100, 32,
3956        );
3957        assert_eq_m256i(r, e);
3958    }
3959
3960    #[simd_test(enable = "avx2")]
3961    const fn test_mm256_add_epi64() {
3962        let a = _mm256_setr_epi64x(-10, 0, 100, 1_000_000_000);
3963        let b = _mm256_setr_epi64x(-1, 0, 1, 2);
3964        let r = _mm256_add_epi64(a, b);
3965        let e = _mm256_setr_epi64x(-11, 0, 101, 1_000_000_002);
3966        assert_eq_m256i(r, e);
3967    }
3968
3969    #[simd_test(enable = "avx2")]
3970    const fn test_mm256_add_epi32() {
3971        let a = _mm256_setr_epi32(-1, 0, 1, 2, 3, 4, 5, 6);
3972        let b = _mm256_setr_epi32(1, 2, 3, 4, 5, 6, 7, 8);
3973        let r = _mm256_add_epi32(a, b);
3974        let e = _mm256_setr_epi32(0, 2, 4, 6, 8, 10, 12, 14);
3975        assert_eq_m256i(r, e);
3976    }
3977
3978    #[simd_test(enable = "avx2")]
3979    const fn test_mm256_add_epi16() {
3980        #[rustfmt::skip]
3981        let a = _mm256_setr_epi16(
3982            0, 1, 2, 3, 4, 5, 6, 7,
3983            8, 9, 10, 11, 12, 13, 14, 15,
3984        );
3985        #[rustfmt::skip]
3986        let b = _mm256_setr_epi16(
3987            0, 1, 2, 3, 4, 5, 6, 7,
3988            8, 9, 10, 11, 12, 13, 14, 15,
3989        );
3990        let r = _mm256_add_epi16(a, b);
3991        #[rustfmt::skip]
3992        let e = _mm256_setr_epi16(
3993            0, 2, 4, 6, 8, 10, 12, 14,
3994            16, 18, 20, 22, 24, 26, 28, 30,
3995        );
3996        assert_eq_m256i(r, e);
3997    }
3998
3999    #[simd_test(enable = "avx2")]
4000    const fn test_mm256_add_epi8() {
4001        #[rustfmt::skip]
4002        let a = _mm256_setr_epi8(
4003            0, 1, 2, 3, 4, 5, 6, 7,
4004            8, 9, 10, 11, 12, 13, 14, 15,
4005            16, 17, 18, 19, 20, 21, 22, 23,
4006            24, 25, 26, 27, 28, 29, 30, 31,
4007        );
4008        #[rustfmt::skip]
4009        let b = _mm256_setr_epi8(
4010            0, 1, 2, 3, 4, 5, 6, 7,
4011            8, 9, 10, 11, 12, 13, 14, 15,
4012            16, 17, 18, 19, 20, 21, 22, 23,
4013            24, 25, 26, 27, 28, 29, 30, 31,
4014        );
4015        let r = _mm256_add_epi8(a, b);
4016        #[rustfmt::skip]
4017        let e = _mm256_setr_epi8(
4018            0, 2, 4, 6, 8, 10, 12, 14,
4019            16, 18, 20, 22, 24, 26, 28, 30,
4020            32, 34, 36, 38, 40, 42, 44, 46,
4021            48, 50, 52, 54, 56, 58, 60, 62,
4022        );
4023        assert_eq_m256i(r, e);
4024    }
4025
4026    #[simd_test(enable = "avx2")]
4027    const fn test_mm256_adds_epi8() {
4028        #[rustfmt::skip]
4029        let a = _mm256_setr_epi8(
4030            0, 1, 2, 3, 4, 5, 6, 7,
4031            8, 9, 10, 11, 12, 13, 14, 15,
4032            16, 17, 18, 19, 20, 21, 22, 23,
4033            24, 25, 26, 27, 28, 29, 30, 31,
4034        );
4035        #[rustfmt::skip]
4036        let b = _mm256_setr_epi8(
4037            32, 33, 34, 35, 36, 37, 38, 39,
4038            40, 41, 42, 43, 44, 45, 46, 47,
4039            48, 49, 50, 51, 52, 53, 54, 55,
4040            56, 57, 58, 59, 60, 61, 62, 63,
4041        );
4042        let r = _mm256_adds_epi8(a, b);
4043        #[rustfmt::skip]
4044        let e = _mm256_setr_epi8(
4045            32, 34, 36, 38, 40, 42, 44, 46,
4046            48, 50, 52, 54, 56, 58, 60, 62,
4047            64, 66, 68, 70, 72, 74, 76, 78,
4048            80, 82, 84, 86, 88, 90, 92, 94,
4049        );
4050        assert_eq_m256i(r, e);
4051    }
4052
4053    #[simd_test(enable = "avx2")]
4054    fn test_mm256_adds_epi8_saturate_positive() {
4055        let a = _mm256_set1_epi8(0x7F);
4056        let b = _mm256_set1_epi8(1);
4057        let r = _mm256_adds_epi8(a, b);
4058        assert_eq_m256i(r, a);
4059    }
4060
4061    #[simd_test(enable = "avx2")]
4062    fn test_mm256_adds_epi8_saturate_negative() {
4063        let a = _mm256_set1_epi8(-0x80);
4064        let b = _mm256_set1_epi8(-1);
4065        let r = _mm256_adds_epi8(a, b);
4066        assert_eq_m256i(r, a);
4067    }
4068
4069    #[simd_test(enable = "avx2")]
4070    const fn test_mm256_adds_epi16() {
4071        #[rustfmt::skip]
4072        let a = _mm256_setr_epi16(
4073            0, 1, 2, 3, 4, 5, 6, 7,
4074            8, 9, 10, 11, 12, 13, 14, 15,
4075        );
4076        #[rustfmt::skip]
4077        let b = _mm256_setr_epi16(
4078            32, 33, 34, 35, 36, 37, 38, 39,
4079            40, 41, 42, 43, 44, 45, 46, 47,
4080        );
4081        let r = _mm256_adds_epi16(a, b);
4082        #[rustfmt::skip]
4083        let e = _mm256_setr_epi16(
4084            32, 34, 36, 38, 40, 42, 44, 46,
4085            48, 50, 52, 54, 56, 58, 60, 62,
4086        );
4087
4088        assert_eq_m256i(r, e);
4089    }
4090
4091    #[simd_test(enable = "avx2")]
4092    fn test_mm256_adds_epi16_saturate_positive() {
4093        let a = _mm256_set1_epi16(0x7FFF);
4094        let b = _mm256_set1_epi16(1);
4095        let r = _mm256_adds_epi16(a, b);
4096        assert_eq_m256i(r, a);
4097    }
4098
4099    #[simd_test(enable = "avx2")]
4100    fn test_mm256_adds_epi16_saturate_negative() {
4101        let a = _mm256_set1_epi16(-0x8000);
4102        let b = _mm256_set1_epi16(-1);
4103        let r = _mm256_adds_epi16(a, b);
4104        assert_eq_m256i(r, a);
4105    }
4106
4107    #[simd_test(enable = "avx2")]
4108    const fn test_mm256_adds_epu8() {
4109        #[rustfmt::skip]
4110        let a = _mm256_setr_epi8(
4111            0, 1, 2, 3, 4, 5, 6, 7,
4112            8, 9, 10, 11, 12, 13, 14, 15,
4113            16, 17, 18, 19, 20, 21, 22, 23,
4114            24, 25, 26, 27, 28, 29, 30, 31,
4115        );
4116        #[rustfmt::skip]
4117        let b = _mm256_setr_epi8(
4118            32, 33, 34, 35, 36, 37, 38, 39,
4119            40, 41, 42, 43, 44, 45, 46, 47,
4120            48, 49, 50, 51, 52, 53, 54, 55,
4121            56, 57, 58, 59, 60, 61, 62, 63,
4122        );
4123        let r = _mm256_adds_epu8(a, b);
4124        #[rustfmt::skip]
4125        let e = _mm256_setr_epi8(
4126            32, 34, 36, 38, 40, 42, 44, 46,
4127            48, 50, 52, 54, 56, 58, 60, 62,
4128            64, 66, 68, 70, 72, 74, 76, 78,
4129            80, 82, 84, 86, 88, 90, 92, 94,
4130        );
4131        assert_eq_m256i(r, e);
4132    }
4133
4134    #[simd_test(enable = "avx2")]
4135    fn test_mm256_adds_epu8_saturate() {
4136        let a = _mm256_set1_epi8(!0);
4137        let b = _mm256_set1_epi8(1);
4138        let r = _mm256_adds_epu8(a, b);
4139        assert_eq_m256i(r, a);
4140    }
4141
4142    #[simd_test(enable = "avx2")]
4143    const fn test_mm256_adds_epu16() {
4144        #[rustfmt::skip]
4145        let a = _mm256_setr_epi16(
4146            0, 1, 2, 3, 4, 5, 6, 7,
4147            8, 9, 10, 11, 12, 13, 14, 15,
4148        );
4149        #[rustfmt::skip]
4150        let b = _mm256_setr_epi16(
4151            32, 33, 34, 35, 36, 37, 38, 39,
4152            40, 41, 42, 43, 44, 45, 46, 47,
4153        );
4154        let r = _mm256_adds_epu16(a, b);
4155        #[rustfmt::skip]
4156        let e = _mm256_setr_epi16(
4157            32, 34, 36, 38, 40, 42, 44, 46,
4158            48, 50, 52, 54, 56, 58, 60, 62,
4159        );
4160
4161        assert_eq_m256i(r, e);
4162    }
4163
4164    #[simd_test(enable = "avx2")]
4165    fn test_mm256_adds_epu16_saturate() {
4166        let a = _mm256_set1_epi16(!0);
4167        let b = _mm256_set1_epi16(1);
4168        let r = _mm256_adds_epu16(a, b);
4169        assert_eq_m256i(r, a);
4170    }
4171
4172    #[simd_test(enable = "avx2")]
4173    const fn test_mm256_and_si256() {
4174        let a = _mm256_set1_epi8(5);
4175        let b = _mm256_set1_epi8(3);
4176        let got = _mm256_and_si256(a, b);
4177        assert_eq_m256i(got, _mm256_set1_epi8(1));
4178    }
4179
4180    #[simd_test(enable = "avx2")]
4181    const fn test_mm256_andnot_si256() {
4182        let a = _mm256_set1_epi8(5);
4183        let b = _mm256_set1_epi8(3);
4184        let got = _mm256_andnot_si256(a, b);
4185        assert_eq_m256i(got, _mm256_set1_epi8(2));
4186    }
4187
4188    #[simd_test(enable = "avx2")]
4189    const fn test_mm256_avg_epu8() {
4190        let (a, b) = (_mm256_set1_epi8(3), _mm256_set1_epi8(9));
4191        let r = _mm256_avg_epu8(a, b);
4192        assert_eq_m256i(r, _mm256_set1_epi8(6));
4193    }
4194
4195    #[simd_test(enable = "avx2")]
4196    const fn test_mm256_avg_epu16() {
4197        let (a, b) = (_mm256_set1_epi16(3), _mm256_set1_epi16(9));
4198        let r = _mm256_avg_epu16(a, b);
4199        assert_eq_m256i(r, _mm256_set1_epi16(6));
4200    }
4201
4202    #[simd_test(enable = "avx2")]
4203    const fn test_mm_blend_epi32() {
4204        let (a, b) = (_mm_set1_epi32(3), _mm_set1_epi32(9));
4205        let e = _mm_setr_epi32(9, 3, 3, 3);
4206        let r = _mm_blend_epi32::<0x01>(a, b);
4207        assert_eq_m128i(r, e);
4208
4209        let r = _mm_blend_epi32::<0x0E>(b, a);
4210        assert_eq_m128i(r, e);
4211    }
4212
4213    #[simd_test(enable = "avx2")]
4214    const fn test_mm256_blend_epi32() {
4215        let (a, b) = (_mm256_set1_epi32(3), _mm256_set1_epi32(9));
4216        let e = _mm256_setr_epi32(9, 3, 3, 3, 3, 3, 3, 3);
4217        let r = _mm256_blend_epi32::<0x01>(a, b);
4218        assert_eq_m256i(r, e);
4219
4220        let e = _mm256_setr_epi32(3, 9, 3, 3, 3, 3, 3, 9);
4221        let r = _mm256_blend_epi32::<0x82>(a, b);
4222        assert_eq_m256i(r, e);
4223
4224        let e = _mm256_setr_epi32(3, 3, 9, 9, 9, 9, 9, 3);
4225        let r = _mm256_blend_epi32::<0x7C>(a, b);
4226        assert_eq_m256i(r, e);
4227    }
4228
4229    #[simd_test(enable = "avx2")]
4230    const fn test_mm256_blend_epi16() {
4231        let (a, b) = (_mm256_set1_epi16(3), _mm256_set1_epi16(9));
4232        let e = _mm256_setr_epi16(9, 3, 3, 3, 3, 3, 3, 3, 9, 3, 3, 3, 3, 3, 3, 3);
4233        let r = _mm256_blend_epi16::<0x01>(a, b);
4234        assert_eq_m256i(r, e);
4235
4236        let r = _mm256_blend_epi16::<0xFE>(b, a);
4237        assert_eq_m256i(r, e);
4238    }
4239
4240    #[simd_test(enable = "avx2")]
4241    const fn test_mm256_blendv_epi8() {
4242        let (a, b) = (_mm256_set1_epi8(4), _mm256_set1_epi8(2));
4243        let mask = _mm256_insert_epi8::<2>(_mm256_set1_epi8(0), -1);
4244        let e = _mm256_insert_epi8::<2>(_mm256_set1_epi8(4), 2);
4245        let r = _mm256_blendv_epi8(a, b, mask);
4246        assert_eq_m256i(r, e);
4247    }
4248
4249    #[simd_test(enable = "avx2")]
4250    const fn test_mm_broadcastb_epi8() {
4251        let a = _mm_insert_epi8::<0>(_mm_set1_epi8(0x00), 0x2a);
4252        let res = _mm_broadcastb_epi8(a);
4253        assert_eq_m128i(res, _mm_set1_epi8(0x2a));
4254    }
4255
4256    #[simd_test(enable = "avx2")]
4257    const fn test_mm256_broadcastb_epi8() {
4258        let a = _mm_insert_epi8::<0>(_mm_set1_epi8(0x00), 0x2a);
4259        let res = _mm256_broadcastb_epi8(a);
4260        assert_eq_m256i(res, _mm256_set1_epi8(0x2a));
4261    }
4262
4263    #[simd_test(enable = "avx2")]
4264    const fn test_mm_broadcastd_epi32() {
4265        let a = _mm_setr_epi32(0x2a, 0x8000000, 0, 0);
4266        let res = _mm_broadcastd_epi32(a);
4267        assert_eq_m128i(res, _mm_set1_epi32(0x2a));
4268    }
4269
4270    #[simd_test(enable = "avx2")]
4271    const fn test_mm256_broadcastd_epi32() {
4272        let a = _mm_setr_epi32(0x2a, 0x8000000, 0, 0);
4273        let res = _mm256_broadcastd_epi32(a);
4274        assert_eq_m256i(res, _mm256_set1_epi32(0x2a));
4275    }
4276
4277    #[simd_test(enable = "avx2")]
4278    const fn test_mm_broadcastq_epi64() {
4279        let a = _mm_setr_epi64x(0x1ffffffff, 0);
4280        let res = _mm_broadcastq_epi64(a);
4281        assert_eq_m128i(res, _mm_set1_epi64x(0x1ffffffff));
4282    }
4283
4284    #[simd_test(enable = "avx2")]
4285    const fn test_mm256_broadcastq_epi64() {
4286        let a = _mm_setr_epi64x(0x1ffffffff, 0);
4287        let res = _mm256_broadcastq_epi64(a);
4288        assert_eq_m256i(res, _mm256_set1_epi64x(0x1ffffffff));
4289    }
4290
4291    #[simd_test(enable = "avx2")]
4292    const fn test_mm_broadcastsd_pd() {
4293        let a = _mm_setr_pd(6.88, 3.44);
4294        let res = _mm_broadcastsd_pd(a);
4295        assert_eq_m128d(res, _mm_set1_pd(6.88));
4296    }
4297
4298    #[simd_test(enable = "avx2")]
4299    const fn test_mm256_broadcastsd_pd() {
4300        let a = _mm_setr_pd(6.88, 3.44);
4301        let res = _mm256_broadcastsd_pd(a);
4302        assert_eq_m256d(res, _mm256_set1_pd(6.88f64));
4303    }
4304
4305    #[simd_test(enable = "avx2")]
4306    const fn test_mm_broadcastsi128_si256() {
4307        let a = _mm_setr_epi64x(0x0987654321012334, 0x5678909876543210);
4308        let res = _mm_broadcastsi128_si256(a);
4309        let retval = _mm256_setr_epi64x(
4310            0x0987654321012334,
4311            0x5678909876543210,
4312            0x0987654321012334,
4313            0x5678909876543210,
4314        );
4315        assert_eq_m256i(res, retval);
4316    }
4317
4318    #[simd_test(enable = "avx2")]
4319    const fn test_mm256_broadcastsi128_si256() {
4320        let a = _mm_setr_epi64x(0x0987654321012334, 0x5678909876543210);
4321        let res = _mm256_broadcastsi128_si256(a);
4322        let retval = _mm256_setr_epi64x(
4323            0x0987654321012334,
4324            0x5678909876543210,
4325            0x0987654321012334,
4326            0x5678909876543210,
4327        );
4328        assert_eq_m256i(res, retval);
4329    }
4330
4331    #[simd_test(enable = "avx2")]
4332    const fn test_mm_broadcastss_ps() {
4333        let a = _mm_setr_ps(6.88, 3.44, 0.0, 0.0);
4334        let res = _mm_broadcastss_ps(a);
4335        assert_eq_m128(res, _mm_set1_ps(6.88));
4336    }
4337
4338    #[simd_test(enable = "avx2")]
4339    const fn test_mm256_broadcastss_ps() {
4340        let a = _mm_setr_ps(6.88, 3.44, 0.0, 0.0);
4341        let res = _mm256_broadcastss_ps(a);
4342        assert_eq_m256(res, _mm256_set1_ps(6.88));
4343    }
4344
4345    #[simd_test(enable = "avx2")]
4346    const fn test_mm_broadcastw_epi16() {
4347        let a = _mm_insert_epi16::<0>(_mm_set1_epi16(0x2a), 0x22b);
4348        let res = _mm_broadcastw_epi16(a);
4349        assert_eq_m128i(res, _mm_set1_epi16(0x22b));
4350    }
4351
4352    #[simd_test(enable = "avx2")]
4353    const fn test_mm256_broadcastw_epi16() {
4354        let a = _mm_insert_epi16::<0>(_mm_set1_epi16(0x2a), 0x22b);
4355        let res = _mm256_broadcastw_epi16(a);
4356        assert_eq_m256i(res, _mm256_set1_epi16(0x22b));
4357    }
4358
4359    #[simd_test(enable = "avx2")]
4360    const fn test_mm256_cmpeq_epi8() {
4361        #[rustfmt::skip]
4362        let a = _mm256_setr_epi8(
4363            0, 1, 2, 3, 4, 5, 6, 7,
4364            8, 9, 10, 11, 12, 13, 14, 15,
4365            16, 17, 18, 19, 20, 21, 22, 23,
4366            24, 25, 26, 27, 28, 29, 30, 31,
4367        );
4368        #[rustfmt::skip]
4369        let b = _mm256_setr_epi8(
4370            31, 30, 2, 28, 27, 26, 25, 24,
4371            23, 22, 21, 20, 19, 18, 17, 16,
4372            15, 14, 13, 12, 11, 10, 9, 8,
4373            7, 6, 5, 4, 3, 2, 1, 0,
4374        );
4375        let r = _mm256_cmpeq_epi8(a, b);
4376        assert_eq_m256i(r, _mm256_insert_epi8::<2>(_mm256_set1_epi8(0), !0));
4377    }
4378
4379    #[simd_test(enable = "avx2")]
4380    const fn test_mm256_cmpeq_epi16() {
4381        #[rustfmt::skip]
4382        let a = _mm256_setr_epi16(
4383            0, 1, 2, 3, 4, 5, 6, 7,
4384            8, 9, 10, 11, 12, 13, 14, 15,
4385        );
4386        #[rustfmt::skip]
4387        let b = _mm256_setr_epi16(
4388            15, 14, 2, 12, 11, 10, 9, 8,
4389            7, 6, 5, 4, 3, 2, 1, 0,
4390        );
4391        let r = _mm256_cmpeq_epi16(a, b);
4392        assert_eq_m256i(r, _mm256_insert_epi16::<2>(_mm256_set1_epi16(0), !0));
4393    }
4394
4395    #[simd_test(enable = "avx2")]
4396    const fn test_mm256_cmpeq_epi32() {
4397        let a = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7);
4398        let b = _mm256_setr_epi32(7, 6, 2, 4, 3, 2, 1, 0);
4399        let r = _mm256_cmpeq_epi32(a, b);
4400        let e = _mm256_set1_epi32(0);
4401        let e = _mm256_insert_epi32::<2>(e, !0);
4402        assert_eq_m256i(r, e);
4403    }
4404
4405    #[simd_test(enable = "avx2")]
4406    const fn test_mm256_cmpeq_epi64() {
4407        let a = _mm256_setr_epi64x(0, 1, 2, 3);
4408        let b = _mm256_setr_epi64x(3, 2, 2, 0);
4409        let r = _mm256_cmpeq_epi64(a, b);
4410        assert_eq_m256i(r, _mm256_insert_epi64::<2>(_mm256_set1_epi64x(0), !0));
4411    }
4412
4413    #[simd_test(enable = "avx2")]
4414    const fn test_mm256_cmpgt_epi8() {
4415        let a = _mm256_insert_epi8::<0>(_mm256_set1_epi8(0), 5);
4416        let b = _mm256_set1_epi8(0);
4417        let r = _mm256_cmpgt_epi8(a, b);
4418        assert_eq_m256i(r, _mm256_insert_epi8::<0>(_mm256_set1_epi8(0), !0));
4419    }
4420
4421    #[simd_test(enable = "avx2")]
4422    const fn test_mm256_cmpgt_epi16() {
4423        let a = _mm256_insert_epi16::<0>(_mm256_set1_epi16(0), 5);
4424        let b = _mm256_set1_epi16(0);
4425        let r = _mm256_cmpgt_epi16(a, b);
4426        assert_eq_m256i(r, _mm256_insert_epi16::<0>(_mm256_set1_epi16(0), !0));
4427    }
4428
4429    #[simd_test(enable = "avx2")]
4430    const fn test_mm256_cmpgt_epi32() {
4431        let a = _mm256_insert_epi32::<0>(_mm256_set1_epi32(0), 5);
4432        let b = _mm256_set1_epi32(0);
4433        let r = _mm256_cmpgt_epi32(a, b);
4434        assert_eq_m256i(r, _mm256_insert_epi32::<0>(_mm256_set1_epi32(0), !0));
4435    }
4436
4437    #[simd_test(enable = "avx2")]
4438    const fn test_mm256_cmpgt_epi64() {
4439        let a = _mm256_insert_epi64::<0>(_mm256_set1_epi64x(0), 5);
4440        let b = _mm256_set1_epi64x(0);
4441        let r = _mm256_cmpgt_epi64(a, b);
4442        assert_eq_m256i(r, _mm256_insert_epi64::<0>(_mm256_set1_epi64x(0), !0));
4443    }
4444
4445    #[simd_test(enable = "avx2")]
4446    const fn test_mm256_cvtepi8_epi16() {
4447        #[rustfmt::skip]
4448        let a = _mm_setr_epi8(
4449            0, 0, -1, 1, -2, 2, -3, 3,
4450            -4, 4, -5, 5, -6, 6, -7, 7,
4451        );
4452        #[rustfmt::skip]
4453        let r = _mm256_setr_epi16(
4454            0, 0, -1, 1, -2, 2, -3, 3,
4455            -4, 4, -5, 5, -6, 6, -7, 7,
4456        );
4457        assert_eq_m256i(r, _mm256_cvtepi8_epi16(a));
4458    }
4459
4460    #[simd_test(enable = "avx2")]
4461    const fn test_mm256_cvtepi8_epi32() {
4462        #[rustfmt::skip]
4463        let a = _mm_setr_epi8(
4464            0, 0, -1, 1, -2, 2, -3, 3,
4465            -4, 4, -5, 5, -6, 6, -7, 7,
4466        );
4467        let r = _mm256_setr_epi32(0, 0, -1, 1, -2, 2, -3, 3);
4468        assert_eq_m256i(r, _mm256_cvtepi8_epi32(a));
4469    }
4470
4471    #[simd_test(enable = "avx2")]
4472    const fn test_mm256_cvtepi8_epi64() {
4473        #[rustfmt::skip]
4474        let a = _mm_setr_epi8(
4475            0, 0, -1, 1, -2, 2, -3, 3,
4476            -4, 4, -5, 5, -6, 6, -7, 7,
4477        );
4478        let r = _mm256_setr_epi64x(0, 0, -1, 1);
4479        assert_eq_m256i(r, _mm256_cvtepi8_epi64(a));
4480    }
4481
4482    #[simd_test(enable = "avx2")]
4483    const fn test_mm256_cvtepi16_epi32() {
4484        let a = _mm_setr_epi16(0, 0, -1, 1, -2, 2, -3, 3);
4485        let r = _mm256_setr_epi32(0, 0, -1, 1, -2, 2, -3, 3);
4486        assert_eq_m256i(r, _mm256_cvtepi16_epi32(a));
4487    }
4488
4489    #[simd_test(enable = "avx2")]
4490    const fn test_mm256_cvtepi16_epi64() {
4491        let a = _mm_setr_epi16(0, 0, -1, 1, -2, 2, -3, 3);
4492        let r = _mm256_setr_epi64x(0, 0, -1, 1);
4493        assert_eq_m256i(r, _mm256_cvtepi16_epi64(a));
4494    }
4495
4496    #[simd_test(enable = "avx2")]
4497    const fn test_mm256_cvtepi32_epi64() {
4498        let a = _mm_setr_epi32(0, 0, -1, 1);
4499        let r = _mm256_setr_epi64x(0, 0, -1, 1);
4500        assert_eq_m256i(r, _mm256_cvtepi32_epi64(a));
4501    }
4502
4503    #[simd_test(enable = "avx2")]
4504    const fn test_mm256_cvtepu16_epi32() {
4505        let a = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
4506        let r = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7);
4507        assert_eq_m256i(r, _mm256_cvtepu16_epi32(a));
4508    }
4509
4510    #[simd_test(enable = "avx2")]
4511    const fn test_mm256_cvtepu16_epi64() {
4512        let a = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
4513        let r = _mm256_setr_epi64x(0, 1, 2, 3);
4514        assert_eq_m256i(r, _mm256_cvtepu16_epi64(a));
4515    }
4516
4517    #[simd_test(enable = "avx2")]
4518    const fn test_mm256_cvtepu32_epi64() {
4519        let a = _mm_setr_epi32(0, 1, 2, 3);
4520        let r = _mm256_setr_epi64x(0, 1, 2, 3);
4521        assert_eq_m256i(r, _mm256_cvtepu32_epi64(a));
4522    }
4523
4524    #[simd_test(enable = "avx2")]
4525    const fn test_mm256_cvtepu8_epi16() {
4526        #[rustfmt::skip]
4527        let a = _mm_setr_epi8(
4528            0, 1, 2, 3, 4, 5, 6, 7,
4529            8, 9, 10, 11, 12, 13, 14, 15,
4530        );
4531        #[rustfmt::skip]
4532        let r = _mm256_setr_epi16(
4533            0, 1, 2, 3, 4, 5, 6, 7,
4534            8, 9, 10, 11, 12, 13, 14, 15,
4535        );
4536        assert_eq_m256i(r, _mm256_cvtepu8_epi16(a));
4537    }
4538
4539    #[simd_test(enable = "avx2")]
4540    const fn test_mm256_cvtepu8_epi32() {
4541        #[rustfmt::skip]
4542        let a = _mm_setr_epi8(
4543            0, 1, 2, 3, 4, 5, 6, 7,
4544            8, 9, 10, 11, 12, 13, 14, 15,
4545        );
4546        let r = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7);
4547        assert_eq_m256i(r, _mm256_cvtepu8_epi32(a));
4548    }
4549
4550    #[simd_test(enable = "avx2")]
4551    const fn test_mm256_cvtepu8_epi64() {
4552        #[rustfmt::skip]
4553        let a = _mm_setr_epi8(
4554            0, 1, 2, 3, 4, 5, 6, 7,
4555            8, 9, 10, 11, 12, 13, 14, 15,
4556        );
4557        let r = _mm256_setr_epi64x(0, 1, 2, 3);
4558        assert_eq_m256i(r, _mm256_cvtepu8_epi64(a));
4559    }
4560
4561    #[simd_test(enable = "avx2")]
4562    const fn test_mm256_extracti128_si256() {
4563        let a = _mm256_setr_epi64x(1, 2, 3, 4);
4564        let r = _mm256_extracti128_si256::<1>(a);
4565        let e = _mm_setr_epi64x(3, 4);
4566        assert_eq_m128i(r, e);
4567    }
4568
4569    #[simd_test(enable = "avx2")]
4570    const fn test_mm256_hadd_epi16() {
4571        let a = _mm256_set1_epi16(2);
4572        let b = _mm256_set1_epi16(4);
4573        let r = _mm256_hadd_epi16(a, b);
4574        let e = _mm256_setr_epi16(4, 4, 4, 4, 8, 8, 8, 8, 4, 4, 4, 4, 8, 8, 8, 8);
4575        assert_eq_m256i(r, e);
4576    }
4577
4578    #[simd_test(enable = "avx2")]
4579    const fn test_mm256_hadd_epi32() {
4580        let a = _mm256_set1_epi32(2);
4581        let b = _mm256_set1_epi32(4);
4582        let r = _mm256_hadd_epi32(a, b);
4583        let e = _mm256_setr_epi32(4, 4, 8, 8, 4, 4, 8, 8);
4584        assert_eq_m256i(r, e);
4585    }
4586
4587    #[simd_test(enable = "avx2")]
4588    fn test_mm256_hadds_epi16() {
4589        let a = _mm256_set1_epi16(2);
4590        let a = _mm256_insert_epi16::<0>(a, 0x7fff);
4591        let a = _mm256_insert_epi16::<1>(a, 1);
4592        let b = _mm256_set1_epi16(4);
4593        let r = _mm256_hadds_epi16(a, b);
4594        #[rustfmt::skip]
4595        let e = _mm256_setr_epi16(
4596            0x7FFF, 4, 4, 4, 8, 8, 8, 8,
4597            4, 4, 4, 4, 8, 8, 8, 8,
4598        );
4599        assert_eq_m256i(r, e);
4600    }
4601
4602    #[simd_test(enable = "avx2")]
4603    const fn test_mm256_hsub_epi16() {
4604        let a = _mm256_set1_epi16(2);
4605        let b = _mm256_set1_epi16(4);
4606        let r = _mm256_hsub_epi16(a, b);
4607        let e = _mm256_set1_epi16(0);
4608        assert_eq_m256i(r, e);
4609    }
4610
4611    #[simd_test(enable = "avx2")]
4612    const fn test_mm256_hsub_epi32() {
4613        let a = _mm256_set1_epi32(2);
4614        let b = _mm256_set1_epi32(4);
4615        let r = _mm256_hsub_epi32(a, b);
4616        let e = _mm256_set1_epi32(0);
4617        assert_eq_m256i(r, e);
4618    }
4619
4620    #[simd_test(enable = "avx2")]
4621    fn test_mm256_hsubs_epi16() {
4622        let a = _mm256_set1_epi16(2);
4623        let a = _mm256_insert_epi16::<0>(a, 0x7fff);
4624        let a = _mm256_insert_epi16::<1>(a, -1);
4625        let b = _mm256_set1_epi16(4);
4626        let r = _mm256_hsubs_epi16(a, b);
4627        let e = _mm256_insert_epi16::<0>(_mm256_set1_epi16(0), 0x7FFF);
4628        assert_eq_m256i(r, e);
4629    }
4630
4631    #[simd_test(enable = "avx2")]
4632    fn test_mm256_madd_epi16() {
4633        let a = _mm256_set1_epi16(2);
4634        let b = _mm256_set1_epi16(4);
4635        let r = _mm256_madd_epi16(a, b);
4636        let e = _mm256_set1_epi32(16);
4637        assert_eq_m256i(r, e);
4638    }
4639
4640    #[target_feature(enable = "avx2")]
4641    #[cfg_attr(test, assert_instr(vpmaddwd))]
4642    unsafe fn test_mm256_madd_epi16_mul_one(v: __m256i) -> __m256i {
4643        // This is a trick used in the adler32 algorithm to get a widening addition. The
4644        // multiplication by 1 is trivial, but must not be optimized out because then the vpmaddwd
4645        // instruction is no longer selected. The assert_instr verifies that this is the case.
4646        let one_v = _mm256_set1_epi16(1);
4647        _mm256_madd_epi16(v, one_v)
4648    }
4649
4650    #[target_feature(enable = "avx2")]
4651    #[cfg_attr(test, assert_instr(vpmaddwd))]
4652    unsafe fn test_mm256_madd_epi16_shl(v: __m256i) -> __m256i {
4653        // This is a trick used in the base64 algorithm to get a widening addition. Instead of a
4654        // multiplication, a vector shl is used. In LLVM 22 that breaks the pattern recognition
4655        // for the automatic optimization to vpmaddwd.
4656        let shift_value = _mm256_set1_epi32(12i32);
4657        _mm256_madd_epi16(v, shift_value)
4658    }
4659
4660    #[simd_test(enable = "avx2")]
4661    const fn test_mm256_inserti128_si256() {
4662        let a = _mm256_setr_epi64x(1, 2, 3, 4);
4663        let b = _mm_setr_epi64x(7, 8);
4664        let r = _mm256_inserti128_si256::<1>(a, b);
4665        let e = _mm256_setr_epi64x(1, 2, 7, 8);
4666        assert_eq_m256i(r, e);
4667    }
4668
4669    #[simd_test(enable = "avx2")]
4670    fn test_mm256_maddubs_epi16() {
4671        let a = _mm256_set1_epi8(2);
4672        let b = _mm256_set1_epi8(4);
4673        let r = _mm256_maddubs_epi16(a, b);
4674        let e = _mm256_set1_epi16(16);
4675        assert_eq_m256i(r, e);
4676    }
4677
4678    #[simd_test(enable = "avx2")]
4679    const fn test_mm_maskload_epi32() {
4680        let nums = [1, 2, 3, 4];
4681        let a = &nums as *const i32;
4682        let mask = _mm_setr_epi32(-1, 0, 0, -1);
4683        let r = unsafe { _mm_maskload_epi32(a, mask) };
4684        let e = _mm_setr_epi32(1, 0, 0, 4);
4685        assert_eq_m128i(r, e);
4686    }
4687
4688    #[simd_test(enable = "avx2")]
4689    const fn test_mm256_maskload_epi32() {
4690        let nums = [1, 2, 3, 4, 5, 6, 7, 8];
4691        let a = &nums as *const i32;
4692        let mask = _mm256_setr_epi32(-1, 0, 0, -1, 0, -1, -1, 0);
4693        let r = unsafe { _mm256_maskload_epi32(a, mask) };
4694        let e = _mm256_setr_epi32(1, 0, 0, 4, 0, 6, 7, 0);
4695        assert_eq_m256i(r, e);
4696    }
4697
4698    #[simd_test(enable = "avx2")]
4699    const fn test_mm_maskload_epi64() {
4700        let nums = [1_i64, 2_i64];
4701        let a = &nums as *const i64;
4702        let mask = _mm_setr_epi64x(0, -1);
4703        let r = unsafe { _mm_maskload_epi64(a, mask) };
4704        let e = _mm_setr_epi64x(0, 2);
4705        assert_eq_m128i(r, e);
4706    }
4707
4708    #[simd_test(enable = "avx2")]
4709    const fn test_mm256_maskload_epi64() {
4710        let nums = [1_i64, 2_i64, 3_i64, 4_i64];
4711        let a = &nums as *const i64;
4712        let mask = _mm256_setr_epi64x(0, -1, -1, 0);
4713        let r = unsafe { _mm256_maskload_epi64(a, mask) };
4714        let e = _mm256_setr_epi64x(0, 2, 3, 0);
4715        assert_eq_m256i(r, e);
4716    }
4717
4718    #[simd_test(enable = "avx2")]
4719    const fn test_mm_maskstore_epi32() {
4720        let a = _mm_setr_epi32(1, 2, 3, 4);
4721        let mut arr = [-1, -1, -1, -1];
4722        let mask = _mm_setr_epi32(-1, 0, 0, -1);
4723        unsafe {
4724            _mm_maskstore_epi32(arr.as_mut_ptr(), mask, a);
4725        }
4726        let e = [1, -1, -1, 4];
4727        assert_eq!(arr, e);
4728    }
4729
4730    #[simd_test(enable = "avx2")]
4731    const fn test_mm256_maskstore_epi32() {
4732        let a = _mm256_setr_epi32(1, 0x6d726f, 3, 42, 0x777161, 6, 7, 8);
4733        let mut arr = [-1, -1, -1, 0x776173, -1, 0x68657265, -1, -1];
4734        let mask = _mm256_setr_epi32(-1, 0, 0, -1, 0, -1, -1, 0);
4735        unsafe {
4736            _mm256_maskstore_epi32(arr.as_mut_ptr(), mask, a);
4737        }
4738        let e = [1, -1, -1, 42, -1, 6, 7, -1];
4739        assert_eq!(arr, e);
4740    }
4741
4742    #[simd_test(enable = "avx2")]
4743    const fn test_mm_maskstore_epi64() {
4744        let a = _mm_setr_epi64x(1_i64, 2_i64);
4745        let mut arr = [-1_i64, -1_i64];
4746        let mask = _mm_setr_epi64x(0, -1);
4747        unsafe {
4748            _mm_maskstore_epi64(arr.as_mut_ptr(), mask, a);
4749        }
4750        let e = [-1, 2];
4751        assert_eq!(arr, e);
4752    }
4753
4754    #[simd_test(enable = "avx2")]
4755    const fn test_mm256_maskstore_epi64() {
4756        let a = _mm256_setr_epi64x(1_i64, 2_i64, 3_i64, 4_i64);
4757        let mut arr = [-1_i64, -1_i64, -1_i64, -1_i64];
4758        let mask = _mm256_setr_epi64x(0, -1, -1, 0);
4759        unsafe {
4760            _mm256_maskstore_epi64(arr.as_mut_ptr(), mask, a);
4761        }
4762        let e = [-1, 2, 3, -1];
4763        assert_eq!(arr, e);
4764    }
4765
4766    #[simd_test(enable = "avx2")]
4767    const fn test_mm256_max_epi16() {
4768        let a = _mm256_set1_epi16(2);
4769        let b = _mm256_set1_epi16(4);
4770        let r = _mm256_max_epi16(a, b);
4771        assert_eq_m256i(r, b);
4772    }
4773
4774    #[simd_test(enable = "avx2")]
4775    const fn test_mm256_max_epi32() {
4776        let a = _mm256_set1_epi32(2);
4777        let b = _mm256_set1_epi32(4);
4778        let r = _mm256_max_epi32(a, b);
4779        assert_eq_m256i(r, b);
4780    }
4781
4782    #[simd_test(enable = "avx2")]
4783    const fn test_mm256_max_epi8() {
4784        let a = _mm256_set1_epi8(2);
4785        let b = _mm256_set1_epi8(4);
4786        let r = _mm256_max_epi8(a, b);
4787        assert_eq_m256i(r, b);
4788    }
4789
4790    #[simd_test(enable = "avx2")]
4791    const fn test_mm256_max_epu16() {
4792        let a = _mm256_set1_epi16(2);
4793        let b = _mm256_set1_epi16(4);
4794        let r = _mm256_max_epu16(a, b);
4795        assert_eq_m256i(r, b);
4796    }
4797
4798    #[simd_test(enable = "avx2")]
4799    const fn test_mm256_max_epu32() {
4800        let a = _mm256_set1_epi32(2);
4801        let b = _mm256_set1_epi32(4);
4802        let r = _mm256_max_epu32(a, b);
4803        assert_eq_m256i(r, b);
4804    }
4805
4806    #[simd_test(enable = "avx2")]
4807    const fn test_mm256_max_epu8() {
4808        let a = _mm256_set1_epi8(2);
4809        let b = _mm256_set1_epi8(4);
4810        let r = _mm256_max_epu8(a, b);
4811        assert_eq_m256i(r, b);
4812    }
4813
4814    #[simd_test(enable = "avx2")]
4815    const fn test_mm256_min_epi16() {
4816        let a = _mm256_set1_epi16(2);
4817        let b = _mm256_set1_epi16(4);
4818        let r = _mm256_min_epi16(a, b);
4819        assert_eq_m256i(r, a);
4820    }
4821
4822    #[simd_test(enable = "avx2")]
4823    const fn test_mm256_min_epi32() {
4824        let a = _mm256_set1_epi32(2);
4825        let b = _mm256_set1_epi32(4);
4826        let r = _mm256_min_epi32(a, b);
4827        assert_eq_m256i(r, a);
4828    }
4829
4830    #[simd_test(enable = "avx2")]
4831    const fn test_mm256_min_epi8() {
4832        let a = _mm256_set1_epi8(2);
4833        let b = _mm256_set1_epi8(4);
4834        let r = _mm256_min_epi8(a, b);
4835        assert_eq_m256i(r, a);
4836    }
4837
4838    #[simd_test(enable = "avx2")]
4839    const fn test_mm256_min_epu16() {
4840        let a = _mm256_set1_epi16(2);
4841        let b = _mm256_set1_epi16(4);
4842        let r = _mm256_min_epu16(a, b);
4843        assert_eq_m256i(r, a);
4844    }
4845
4846    #[simd_test(enable = "avx2")]
4847    const fn test_mm256_min_epu32() {
4848        let a = _mm256_set1_epi32(2);
4849        let b = _mm256_set1_epi32(4);
4850        let r = _mm256_min_epu32(a, b);
4851        assert_eq_m256i(r, a);
4852    }
4853
4854    #[simd_test(enable = "avx2")]
4855    const fn test_mm256_min_epu8() {
4856        let a = _mm256_set1_epi8(2);
4857        let b = _mm256_set1_epi8(4);
4858        let r = _mm256_min_epu8(a, b);
4859        assert_eq_m256i(r, a);
4860    }
4861
4862    #[simd_test(enable = "avx2")]
4863    const fn test_mm256_movemask_epi8() {
4864        let a = _mm256_set1_epi8(-1);
4865        let r = _mm256_movemask_epi8(a);
4866        let e = -1;
4867        assert_eq!(r, e);
4868    }
4869
4870    #[simd_test(enable = "avx2")]
4871    fn test_mm256_mpsadbw_epu8() {
4872        let a = _mm256_set1_epi8(2);
4873        let b = _mm256_set1_epi8(4);
4874        let r = _mm256_mpsadbw_epu8::<0>(a, b);
4875        let e = _mm256_set1_epi16(8);
4876        assert_eq_m256i(r, e);
4877    }
4878
4879    #[simd_test(enable = "avx2")]
4880    const fn test_mm256_mul_epi32() {
4881        let a = _mm256_setr_epi32(0, 0, 0, 0, 2, 2, 2, 2);
4882        let b = _mm256_setr_epi32(1, 2, 3, 4, 5, 6, 7, 8);
4883        let r = _mm256_mul_epi32(a, b);
4884        let e = _mm256_setr_epi64x(0, 0, 10, 14);
4885        assert_eq_m256i(r, e);
4886    }
4887
4888    #[simd_test(enable = "avx2")]
4889    const fn test_mm256_mul_epu32() {
4890        let a = _mm256_setr_epi32(0, 0, 0, 0, 2, 2, 2, 2);
4891        let b = _mm256_setr_epi32(1, 2, 3, 4, 5, 6, 7, 8);
4892        let r = _mm256_mul_epu32(a, b);
4893        let e = _mm256_setr_epi64x(0, 0, 10, 14);
4894        assert_eq_m256i(r, e);
4895    }
4896
4897    #[simd_test(enable = "avx2")]
4898    const fn test_mm256_mulhi_epi16() {
4899        let a = _mm256_set1_epi16(6535);
4900        let b = _mm256_set1_epi16(6535);
4901        let r = _mm256_mulhi_epi16(a, b);
4902        let e = _mm256_set1_epi16(651);
4903        assert_eq_m256i(r, e);
4904    }
4905
4906    #[simd_test(enable = "avx2")]
4907    const fn test_mm256_mulhi_epu16() {
4908        let a = _mm256_set1_epi16(6535);
4909        let b = _mm256_set1_epi16(6535);
4910        let r = _mm256_mulhi_epu16(a, b);
4911        let e = _mm256_set1_epi16(651);
4912        assert_eq_m256i(r, e);
4913    }
4914
4915    #[simd_test(enable = "avx2")]
4916    const fn test_mm256_mullo_epi16() {
4917        let a = _mm256_set1_epi16(2);
4918        let b = _mm256_set1_epi16(4);
4919        let r = _mm256_mullo_epi16(a, b);
4920        let e = _mm256_set1_epi16(8);
4921        assert_eq_m256i(r, e);
4922    }
4923
4924    #[simd_test(enable = "avx2")]
4925    const fn test_mm256_mullo_epi32() {
4926        let a = _mm256_set1_epi32(2);
4927        let b = _mm256_set1_epi32(4);
4928        let r = _mm256_mullo_epi32(a, b);
4929        let e = _mm256_set1_epi32(8);
4930        assert_eq_m256i(r, e);
4931    }
4932
4933    #[simd_test(enable = "avx2")]
4934    fn test_mm256_mulhrs_epi16() {
4935        let a = _mm256_set1_epi16(2);
4936        let b = _mm256_set1_epi16(4);
4937        let r = _mm256_mullo_epi16(a, b);
4938        let e = _mm256_set1_epi16(8);
4939        assert_eq_m256i(r, e);
4940    }
4941
4942    #[simd_test(enable = "avx2")]
4943    const fn test_mm256_or_si256() {
4944        let a = _mm256_set1_epi8(-1);
4945        let b = _mm256_set1_epi8(0);
4946        let r = _mm256_or_si256(a, b);
4947        assert_eq_m256i(r, a);
4948    }
4949
4950    #[simd_test(enable = "avx2")]
4951    fn test_mm256_packs_epi16() {
4952        let a = _mm256_set1_epi16(2);
4953        let b = _mm256_set1_epi16(4);
4954        let r = _mm256_packs_epi16(a, b);
4955        #[rustfmt::skip]
4956        let e = _mm256_setr_epi8(
4957            2, 2, 2, 2, 2, 2, 2, 2,
4958            4, 4, 4, 4, 4, 4, 4, 4,
4959            2, 2, 2, 2, 2, 2, 2, 2,
4960            4, 4, 4, 4, 4, 4, 4, 4,
4961        );
4962
4963        assert_eq_m256i(r, e);
4964    }
4965
4966    #[simd_test(enable = "avx2")]
4967    fn test_mm256_packs_epi32() {
4968        let a = _mm256_set1_epi32(2);
4969        let b = _mm256_set1_epi32(4);
4970        let r = _mm256_packs_epi32(a, b);
4971        let e = _mm256_setr_epi16(2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 2, 2, 4, 4, 4, 4);
4972
4973        assert_eq_m256i(r, e);
4974    }
4975
4976    #[simd_test(enable = "avx2")]
4977    fn test_mm256_packus_epi16() {
4978        let a = _mm256_set1_epi16(2);
4979        let b = _mm256_set1_epi16(4);
4980        let r = _mm256_packus_epi16(a, b);
4981        #[rustfmt::skip]
4982        let e = _mm256_setr_epi8(
4983            2, 2, 2, 2, 2, 2, 2, 2,
4984            4, 4, 4, 4, 4, 4, 4, 4,
4985            2, 2, 2, 2, 2, 2, 2, 2,
4986            4, 4, 4, 4, 4, 4, 4, 4,
4987        );
4988
4989        assert_eq_m256i(r, e);
4990    }
4991
4992    #[simd_test(enable = "avx2")]
4993    fn test_mm256_packus_epi32() {
4994        let a = _mm256_set1_epi32(2);
4995        let b = _mm256_set1_epi32(4);
4996        let r = _mm256_packus_epi32(a, b);
4997        let e = _mm256_setr_epi16(2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 2, 2, 4, 4, 4, 4);
4998
4999        assert_eq_m256i(r, e);
5000    }
5001
5002    #[simd_test(enable = "avx2")]
5003    fn test_mm256_sad_epu8() {
5004        let a = _mm256_set1_epi8(2);
5005        let b = _mm256_set1_epi8(4);
5006        let r = _mm256_sad_epu8(a, b);
5007        let e = _mm256_set1_epi64x(16);
5008        assert_eq_m256i(r, e);
5009    }
5010
5011    #[simd_test(enable = "avx2")]
5012    const fn test_mm256_shufflehi_epi16() {
5013        #[rustfmt::skip]
5014        let a = _mm256_setr_epi16(
5015            0, 1, 2, 3, 11, 22, 33, 44,
5016            4, 5, 6, 7, 55, 66, 77, 88,
5017        );
5018        #[rustfmt::skip]
5019        let e = _mm256_setr_epi16(
5020            0, 1, 2, 3, 44, 22, 22, 11,
5021            4, 5, 6, 7, 88, 66, 66, 55,
5022        );
5023        let r = _mm256_shufflehi_epi16::<0b00_01_01_11>(a);
5024        assert_eq_m256i(r, e);
5025    }
5026
5027    #[simd_test(enable = "avx2")]
5028    const fn test_mm256_shufflelo_epi16() {
5029        #[rustfmt::skip]
5030        let a = _mm256_setr_epi16(
5031            11, 22, 33, 44, 0, 1, 2, 3,
5032            55, 66, 77, 88, 4, 5, 6, 7,
5033        );
5034        #[rustfmt::skip]
5035        let e = _mm256_setr_epi16(
5036            44, 22, 22, 11, 0, 1, 2, 3,
5037            88, 66, 66, 55, 4, 5, 6, 7,
5038        );
5039        let r = _mm256_shufflelo_epi16::<0b00_01_01_11>(a);
5040        assert_eq_m256i(r, e);
5041    }
5042
5043    #[simd_test(enable = "avx2")]
5044    fn test_mm256_sign_epi16() {
5045        let a = _mm256_set1_epi16(2);
5046        let b = _mm256_set1_epi16(-1);
5047        let r = _mm256_sign_epi16(a, b);
5048        let e = _mm256_set1_epi16(-2);
5049        assert_eq_m256i(r, e);
5050    }
5051
5052    #[simd_test(enable = "avx2")]
5053    fn test_mm256_sign_epi32() {
5054        let a = _mm256_set1_epi32(2);
5055        let b = _mm256_set1_epi32(-1);
5056        let r = _mm256_sign_epi32(a, b);
5057        let e = _mm256_set1_epi32(-2);
5058        assert_eq_m256i(r, e);
5059    }
5060
5061    #[simd_test(enable = "avx2")]
5062    fn test_mm256_sign_epi8() {
5063        let a = _mm256_set1_epi8(2);
5064        let b = _mm256_set1_epi8(-1);
5065        let r = _mm256_sign_epi8(a, b);
5066        let e = _mm256_set1_epi8(-2);
5067        assert_eq_m256i(r, e);
5068    }
5069
5070    #[simd_test(enable = "avx2")]
5071    fn test_mm256_sll_epi16() {
5072        let a = _mm256_set1_epi16(0xFF);
5073        let b = _mm_insert_epi16::<0>(_mm_set1_epi16(0), 4);
5074        let r = _mm256_sll_epi16(a, b);
5075        assert_eq_m256i(r, _mm256_set1_epi16(0xFF0));
5076    }
5077
5078    #[simd_test(enable = "avx2")]
5079    fn test_mm256_sll_epi32() {
5080        let a = _mm256_set1_epi32(0xFFFF);
5081        let b = _mm_insert_epi32::<0>(_mm_set1_epi32(0), 4);
5082        let r = _mm256_sll_epi32(a, b);
5083        assert_eq_m256i(r, _mm256_set1_epi32(0xFFFF0));
5084    }
5085
5086    #[simd_test(enable = "avx2")]
5087    fn test_mm256_sll_epi64() {
5088        let a = _mm256_set1_epi64x(0xFFFFFFFF);
5089        let b = _mm_insert_epi64::<0>(_mm_set1_epi64x(0), 4);
5090        let r = _mm256_sll_epi64(a, b);
5091        assert_eq_m256i(r, _mm256_set1_epi64x(0xFFFFFFFF0));
5092    }
5093
5094    #[simd_test(enable = "avx2")]
5095    const fn test_mm256_slli_epi16() {
5096        assert_eq_m256i(
5097            _mm256_slli_epi16::<4>(_mm256_set1_epi16(0xFF)),
5098            _mm256_set1_epi16(0xFF0),
5099        );
5100    }
5101
5102    #[simd_test(enable = "avx2")]
5103    const fn test_mm256_slli_epi32() {
5104        assert_eq_m256i(
5105            _mm256_slli_epi32::<4>(_mm256_set1_epi32(0xFFFF)),
5106            _mm256_set1_epi32(0xFFFF0),
5107        );
5108    }
5109
5110    #[simd_test(enable = "avx2")]
5111    const fn test_mm256_slli_epi64() {
5112        assert_eq_m256i(
5113            _mm256_slli_epi64::<4>(_mm256_set1_epi64x(0xFFFFFFFF)),
5114            _mm256_set1_epi64x(0xFFFFFFFF0),
5115        );
5116    }
5117
5118    #[simd_test(enable = "avx2")]
5119    const fn test_mm256_slli_si256() {
5120        let a = _mm256_set1_epi64x(0xFFFFFFFF);
5121        let r = _mm256_slli_si256::<3>(a);
5122        assert_eq_m256i(r, _mm256_set1_epi64x(0xFFFFFFFF000000));
5123    }
5124
5125    #[simd_test(enable = "avx2")]
5126    fn test_mm_sllv_epi32() {
5127        let a = _mm_set1_epi32(2);
5128        let b = _mm_set1_epi32(1);
5129        let r = _mm_sllv_epi32(a, b);
5130        let e = _mm_set1_epi32(4);
5131        assert_eq_m128i(r, e);
5132    }
5133
5134    #[simd_test(enable = "avx2")]
5135    fn test_mm256_sllv_epi32() {
5136        let a = _mm256_set1_epi32(2);
5137        let b = _mm256_set1_epi32(1);
5138        let r = _mm256_sllv_epi32(a, b);
5139        let e = _mm256_set1_epi32(4);
5140        assert_eq_m256i(r, e);
5141    }
5142
5143    #[simd_test(enable = "avx2")]
5144    fn test_mm_sllv_epi64() {
5145        let a = _mm_set1_epi64x(2);
5146        let b = _mm_set1_epi64x(1);
5147        let r = _mm_sllv_epi64(a, b);
5148        let e = _mm_set1_epi64x(4);
5149        assert_eq_m128i(r, e);
5150    }
5151
5152    #[simd_test(enable = "avx2")]
5153    fn test_mm256_sllv_epi64() {
5154        let a = _mm256_set1_epi64x(2);
5155        let b = _mm256_set1_epi64x(1);
5156        let r = _mm256_sllv_epi64(a, b);
5157        let e = _mm256_set1_epi64x(4);
5158        assert_eq_m256i(r, e);
5159    }
5160
5161    #[simd_test(enable = "avx2")]
5162    fn test_mm256_sra_epi16() {
5163        let a = _mm256_set1_epi16(-1);
5164        let b = _mm_setr_epi16(1, 0, 0, 0, 0, 0, 0, 0);
5165        let r = _mm256_sra_epi16(a, b);
5166        assert_eq_m256i(r, _mm256_set1_epi16(-1));
5167    }
5168
5169    #[simd_test(enable = "avx2")]
5170    fn test_mm256_sra_epi32() {
5171        let a = _mm256_set1_epi32(-1);
5172        let b = _mm_insert_epi32::<0>(_mm_set1_epi32(0), 1);
5173        let r = _mm256_sra_epi32(a, b);
5174        assert_eq_m256i(r, _mm256_set1_epi32(-1));
5175    }
5176
5177    #[simd_test(enable = "avx2")]
5178    const fn test_mm256_srai_epi16() {
5179        assert_eq_m256i(
5180            _mm256_srai_epi16::<1>(_mm256_set1_epi16(-1)),
5181            _mm256_set1_epi16(-1),
5182        );
5183    }
5184
5185    #[simd_test(enable = "avx2")]
5186    const fn test_mm256_srai_epi32() {
5187        assert_eq_m256i(
5188            _mm256_srai_epi32::<1>(_mm256_set1_epi32(-1)),
5189            _mm256_set1_epi32(-1),
5190        );
5191    }
5192
5193    #[simd_test(enable = "avx2")]
5194    fn test_mm_srav_epi32() {
5195        let a = _mm_set1_epi32(4);
5196        let count = _mm_set1_epi32(1);
5197        let r = _mm_srav_epi32(a, count);
5198        let e = _mm_set1_epi32(2);
5199        assert_eq_m128i(r, e);
5200    }
5201
5202    #[simd_test(enable = "avx2")]
5203    fn test_mm256_srav_epi32() {
5204        let a = _mm256_set1_epi32(4);
5205        let count = _mm256_set1_epi32(1);
5206        let r = _mm256_srav_epi32(a, count);
5207        let e = _mm256_set1_epi32(2);
5208        assert_eq_m256i(r, e);
5209    }
5210
5211    #[simd_test(enable = "avx2")]
5212    const fn test_mm256_srli_si256() {
5213        #[rustfmt::skip]
5214        let a = _mm256_setr_epi8(
5215            1, 2, 3, 4, 5, 6, 7, 8,
5216            9, 10, 11, 12, 13, 14, 15, 16,
5217            17, 18, 19, 20, 21, 22, 23, 24,
5218            25, 26, 27, 28, 29, 30, 31, 32,
5219        );
5220        let r = _mm256_srli_si256::<3>(a);
5221        #[rustfmt::skip]
5222        let e = _mm256_setr_epi8(
5223            4, 5, 6, 7, 8, 9, 10, 11,
5224            12, 13, 14, 15, 16, 0, 0, 0,
5225            20, 21, 22, 23, 24, 25, 26, 27,
5226            28, 29, 30, 31, 32, 0, 0, 0,
5227        );
5228        assert_eq_m256i(r, e);
5229    }
5230
5231    #[simd_test(enable = "avx2")]
5232    fn test_mm256_srl_epi16() {
5233        let a = _mm256_set1_epi16(0xFF);
5234        let b = _mm_insert_epi16::<0>(_mm_set1_epi16(0), 4);
5235        let r = _mm256_srl_epi16(a, b);
5236        assert_eq_m256i(r, _mm256_set1_epi16(0xF));
5237    }
5238
5239    #[simd_test(enable = "avx2")]
5240    fn test_mm256_srl_epi32() {
5241        let a = _mm256_set1_epi32(0xFFFF);
5242        let b = _mm_insert_epi32::<0>(_mm_set1_epi32(0), 4);
5243        let r = _mm256_srl_epi32(a, b);
5244        assert_eq_m256i(r, _mm256_set1_epi32(0xFFF));
5245    }
5246
5247    #[simd_test(enable = "avx2")]
5248    fn test_mm256_srl_epi64() {
5249        let a = _mm256_set1_epi64x(0xFFFFFFFF);
5250        let b = _mm_setr_epi64x(4, 0);
5251        let r = _mm256_srl_epi64(a, b);
5252        assert_eq_m256i(r, _mm256_set1_epi64x(0xFFFFFFF));
5253    }
5254
5255    #[simd_test(enable = "avx2")]
5256    const fn test_mm256_srli_epi16() {
5257        assert_eq_m256i(
5258            _mm256_srli_epi16::<4>(_mm256_set1_epi16(0xFF)),
5259            _mm256_set1_epi16(0xF),
5260        );
5261    }
5262
5263    #[simd_test(enable = "avx2")]
5264    const fn test_mm256_srli_epi32() {
5265        assert_eq_m256i(
5266            _mm256_srli_epi32::<4>(_mm256_set1_epi32(0xFFFF)),
5267            _mm256_set1_epi32(0xFFF),
5268        );
5269    }
5270
5271    #[simd_test(enable = "avx2")]
5272    const fn test_mm256_srli_epi64() {
5273        assert_eq_m256i(
5274            _mm256_srli_epi64::<4>(_mm256_set1_epi64x(0xFFFFFFFF)),
5275            _mm256_set1_epi64x(0xFFFFFFF),
5276        );
5277    }
5278
5279    #[simd_test(enable = "avx2")]
5280    fn test_mm_srlv_epi32() {
5281        let a = _mm_set1_epi32(2);
5282        let count = _mm_set1_epi32(1);
5283        let r = _mm_srlv_epi32(a, count);
5284        let e = _mm_set1_epi32(1);
5285        assert_eq_m128i(r, e);
5286    }
5287
5288    #[simd_test(enable = "avx2")]
5289    fn test_mm256_srlv_epi32() {
5290        let a = _mm256_set1_epi32(2);
5291        let count = _mm256_set1_epi32(1);
5292        let r = _mm256_srlv_epi32(a, count);
5293        let e = _mm256_set1_epi32(1);
5294        assert_eq_m256i(r, e);
5295    }
5296
5297    #[simd_test(enable = "avx2")]
5298    fn test_mm_srlv_epi64() {
5299        let a = _mm_set1_epi64x(2);
5300        let count = _mm_set1_epi64x(1);
5301        let r = _mm_srlv_epi64(a, count);
5302        let e = _mm_set1_epi64x(1);
5303        assert_eq_m128i(r, e);
5304    }
5305
5306    #[simd_test(enable = "avx2")]
5307    fn test_mm256_srlv_epi64() {
5308        let a = _mm256_set1_epi64x(2);
5309        let count = _mm256_set1_epi64x(1);
5310        let r = _mm256_srlv_epi64(a, count);
5311        let e = _mm256_set1_epi64x(1);
5312        assert_eq_m256i(r, e);
5313    }
5314
5315    #[simd_test(enable = "avx2")]
5316    fn test_mm256_stream_load_si256() {
5317        let a = _mm256_set_epi64x(5, 6, 7, 8);
5318        let r = unsafe { _mm256_stream_load_si256(core::ptr::addr_of!(a) as *const _) };
5319        assert_eq_m256i(a, r);
5320    }
5321
5322    #[simd_test(enable = "avx2")]
5323    const fn test_mm256_sub_epi16() {
5324        let a = _mm256_set1_epi16(4);
5325        let b = _mm256_set1_epi16(2);
5326        let r = _mm256_sub_epi16(a, b);
5327        assert_eq_m256i(r, b);
5328    }
5329
5330    #[simd_test(enable = "avx2")]
5331    const fn test_mm256_sub_epi32() {
5332        let a = _mm256_set1_epi32(4);
5333        let b = _mm256_set1_epi32(2);
5334        let r = _mm256_sub_epi32(a, b);
5335        assert_eq_m256i(r, b);
5336    }
5337
5338    #[simd_test(enable = "avx2")]
5339    const fn test_mm256_sub_epi64() {
5340        let a = _mm256_set1_epi64x(4);
5341        let b = _mm256_set1_epi64x(2);
5342        let r = _mm256_sub_epi64(a, b);
5343        assert_eq_m256i(r, b);
5344    }
5345
5346    #[simd_test(enable = "avx2")]
5347    const fn test_mm256_sub_epi8() {
5348        let a = _mm256_set1_epi8(4);
5349        let b = _mm256_set1_epi8(2);
5350        let r = _mm256_sub_epi8(a, b);
5351        assert_eq_m256i(r, b);
5352    }
5353
5354    #[simd_test(enable = "avx2")]
5355    const fn test_mm256_subs_epi16() {
5356        let a = _mm256_set1_epi16(4);
5357        let b = _mm256_set1_epi16(2);
5358        let r = _mm256_subs_epi16(a, b);
5359        assert_eq_m256i(r, b);
5360    }
5361
5362    #[simd_test(enable = "avx2")]
5363    const fn test_mm256_subs_epi8() {
5364        let a = _mm256_set1_epi8(4);
5365        let b = _mm256_set1_epi8(2);
5366        let r = _mm256_subs_epi8(a, b);
5367        assert_eq_m256i(r, b);
5368    }
5369
5370    #[simd_test(enable = "avx2")]
5371    const fn test_mm256_subs_epu16() {
5372        let a = _mm256_set1_epi16(4);
5373        let b = _mm256_set1_epi16(2);
5374        let r = _mm256_subs_epu16(a, b);
5375        assert_eq_m256i(r, b);
5376    }
5377
5378    #[simd_test(enable = "avx2")]
5379    const fn test_mm256_subs_epu8() {
5380        let a = _mm256_set1_epi8(4);
5381        let b = _mm256_set1_epi8(2);
5382        let r = _mm256_subs_epu8(a, b);
5383        assert_eq_m256i(r, b);
5384    }
5385
5386    #[simd_test(enable = "avx2")]
5387    const fn test_mm256_xor_si256() {
5388        let a = _mm256_set1_epi8(5);
5389        let b = _mm256_set1_epi8(3);
5390        let r = _mm256_xor_si256(a, b);
5391        assert_eq_m256i(r, _mm256_set1_epi8(6));
5392    }
5393
5394    #[simd_test(enable = "avx2")]
5395    const fn test_mm256_alignr_epi8() {
5396        #[rustfmt::skip]
5397        let a = _mm256_setr_epi8(
5398            1, 2, 3, 4, 5, 6, 7, 8,
5399            9, 10, 11, 12, 13, 14, 15, 16,
5400            17, 18, 19, 20, 21, 22, 23, 24,
5401            25, 26, 27, 28, 29, 30, 31, 32,
5402        );
5403        #[rustfmt::skip]
5404        let b = _mm256_setr_epi8(
5405            -1, -2, -3, -4, -5, -6, -7, -8,
5406            -9, -10, -11, -12, -13, -14, -15, -16,
5407            -17, -18, -19, -20, -21, -22, -23, -24,
5408            -25, -26, -27, -28, -29, -30, -31, -32,
5409        );
5410        let r = _mm256_alignr_epi8::<33>(a, b);
5411        assert_eq_m256i(r, _mm256_set1_epi8(0));
5412
5413        let r = _mm256_alignr_epi8::<17>(a, b);
5414        #[rustfmt::skip]
5415        let expected = _mm256_setr_epi8(
5416            2, 3, 4, 5, 6, 7, 8, 9,
5417            10, 11, 12, 13, 14, 15, 16, 0,
5418            18, 19, 20, 21, 22, 23, 24, 25,
5419            26, 27, 28, 29, 30, 31, 32, 0,
5420        );
5421        assert_eq_m256i(r, expected);
5422
5423        let r = _mm256_alignr_epi8::<4>(a, b);
5424        #[rustfmt::skip]
5425        let expected = _mm256_setr_epi8(
5426            -5, -6, -7, -8, -9, -10, -11, -12,
5427            -13, -14, -15, -16, 1, 2, 3, 4,
5428            -21, -22, -23, -24, -25, -26, -27, -28,
5429            -29, -30, -31, -32, 17, 18, 19, 20,
5430        );
5431        assert_eq_m256i(r, expected);
5432
5433        let r = _mm256_alignr_epi8::<15>(a, b);
5434        #[rustfmt::skip]
5435        let expected = _mm256_setr_epi8(
5436            -16, 1, 2, 3, 4, 5, 6, 7,
5437            8, 9, 10, 11, 12, 13, 14, 15,
5438            -32, 17, 18, 19, 20, 21, 22, 23,
5439            24, 25, 26, 27, 28, 29, 30, 31,
5440        );
5441        assert_eq_m256i(r, expected);
5442
5443        let r = _mm256_alignr_epi8::<0>(a, b);
5444        assert_eq_m256i(r, b);
5445
5446        let r = _mm256_alignr_epi8::<16>(a, b);
5447        assert_eq_m256i(r, a);
5448    }
5449
5450    #[simd_test(enable = "avx2")]
5451    fn test_mm256_shuffle_epi8() {
5452        #[rustfmt::skip]
5453        let a = _mm256_setr_epi8(
5454            1, 2, 3, 4, 5, 6, 7, 8,
5455            9, 10, 11, 12, 13, 14, 15, 16,
5456            17, 18, 19, 20, 21, 22, 23, 24,
5457            25, 26, 27, 28, 29, 30, 31, 32,
5458        );
5459        #[rustfmt::skip]
5460        let b = _mm256_setr_epi8(
5461            4, 128u8 as i8, 4, 3, 24, 12, 6, 19,
5462            12, 5, 5, 10, 4, 1, 8, 0,
5463            4, 128u8 as i8, 4, 3, 24, 12, 6, 19,
5464            12, 5, 5, 10, 4, 1, 8, 0,
5465        );
5466        #[rustfmt::skip]
5467        let expected = _mm256_setr_epi8(
5468            5, 0, 5, 4, 9, 13, 7, 4,
5469            13, 6, 6, 11, 5, 2, 9, 1,
5470            21, 0, 21, 20, 25, 29, 23, 20,
5471            29, 22, 22, 27, 21, 18, 25, 17,
5472        );
5473        let r = _mm256_shuffle_epi8(a, b);
5474        assert_eq_m256i(r, expected);
5475    }
5476
5477    #[simd_test(enable = "avx2")]
5478    fn test_mm256_permutevar8x32_epi32() {
5479        let a = _mm256_setr_epi32(100, 200, 300, 400, 500, 600, 700, 800);
5480        let b = _mm256_setr_epi32(5, 0, 5, 1, 7, 6, 3, 4);
5481        let expected = _mm256_setr_epi32(600, 100, 600, 200, 800, 700, 400, 500);
5482        let r = _mm256_permutevar8x32_epi32(a, b);
5483        assert_eq_m256i(r, expected);
5484    }
5485
5486    #[simd_test(enable = "avx2")]
5487    const fn test_mm256_permute4x64_epi64() {
5488        let a = _mm256_setr_epi64x(100, 200, 300, 400);
5489        let expected = _mm256_setr_epi64x(400, 100, 200, 100);
5490        let r = _mm256_permute4x64_epi64::<0b00010011>(a);
5491        assert_eq_m256i(r, expected);
5492    }
5493
5494    #[simd_test(enable = "avx2")]
5495    const fn test_mm256_permute2x128_si256() {
5496        let a = _mm256_setr_epi64x(100, 200, 500, 600);
5497        let b = _mm256_setr_epi64x(300, 400, 700, 800);
5498        let r = _mm256_permute2x128_si256::<0b00_01_00_11>(a, b);
5499        let e = _mm256_setr_epi64x(700, 800, 500, 600);
5500        assert_eq_m256i(r, e);
5501    }
5502
5503    #[simd_test(enable = "avx2")]
5504    const fn test_mm256_permute4x64_pd() {
5505        let a = _mm256_setr_pd(1., 2., 3., 4.);
5506        let r = _mm256_permute4x64_pd::<0b00_01_00_11>(a);
5507        let e = _mm256_setr_pd(4., 1., 2., 1.);
5508        assert_eq_m256d(r, e);
5509    }
5510
5511    #[simd_test(enable = "avx2")]
5512    fn test_mm256_permutevar8x32_ps() {
5513        let a = _mm256_setr_ps(1., 2., 3., 4., 5., 6., 7., 8.);
5514        let b = _mm256_setr_epi32(5, 0, 5, 1, 7, 6, 3, 4);
5515        let r = _mm256_permutevar8x32_ps(a, b);
5516        let e = _mm256_setr_ps(6., 1., 6., 2., 8., 7., 4., 5.);
5517        assert_eq_m256(r, e);
5518    }
5519
5520    #[simd_test(enable = "avx2")]
5521    fn test_mm_i32gather_epi32() {
5522        let arr: [i32; 128] = core::array::from_fn(|i| i as i32);
5523        // A multiplier of 4 is word-addressing
5524        let r = unsafe { _mm_i32gather_epi32::<4>(arr.as_ptr(), _mm_setr_epi32(0, 16, 32, 48)) };
5525        assert_eq_m128i(r, _mm_setr_epi32(0, 16, 32, 48));
5526    }
5527
5528    #[simd_test(enable = "avx2")]
5529    fn test_mm_mask_i32gather_epi32() {
5530        let arr: [i32; 128] = core::array::from_fn(|i| i as i32);
5531        // A multiplier of 4 is word-addressing
5532        let r = unsafe {
5533            _mm_mask_i32gather_epi32::<4>(
5534                _mm_set1_epi32(256),
5535                arr.as_ptr(),
5536                _mm_setr_epi32(0, 16, 64, 96),
5537                _mm_setr_epi32(-1, -1, -1, 0),
5538            )
5539        };
5540        assert_eq_m128i(r, _mm_setr_epi32(0, 16, 64, 256));
5541    }
5542
5543    #[simd_test(enable = "avx2")]
5544    fn test_mm256_i32gather_epi32() {
5545        let arr: [i32; 128] = core::array::from_fn(|i| i as i32);
5546        // A multiplier of 4 is word-addressing
5547        let r = unsafe {
5548            _mm256_i32gather_epi32::<4>(arr.as_ptr(), _mm256_setr_epi32(0, 16, 32, 48, 1, 2, 3, 4))
5549        };
5550        assert_eq_m256i(r, _mm256_setr_epi32(0, 16, 32, 48, 1, 2, 3, 4));
5551    }
5552
5553    #[simd_test(enable = "avx2")]
5554    fn test_mm256_mask_i32gather_epi32() {
5555        let arr: [i32; 128] = core::array::from_fn(|i| i as i32);
5556        // A multiplier of 4 is word-addressing
5557        let r = unsafe {
5558            _mm256_mask_i32gather_epi32::<4>(
5559                _mm256_set1_epi32(256),
5560                arr.as_ptr(),
5561                _mm256_setr_epi32(0, 16, 64, 96, 0, 0, 0, 0),
5562                _mm256_setr_epi32(-1, -1, -1, 0, 0, 0, 0, 0),
5563            )
5564        };
5565        assert_eq_m256i(r, _mm256_setr_epi32(0, 16, 64, 256, 256, 256, 256, 256));
5566    }
5567
5568    #[simd_test(enable = "avx2")]
5569    fn test_mm_i32gather_ps() {
5570        let arr: [f32; 128] = core::array::from_fn(|i| i as f32);
5571        // A multiplier of 4 is word-addressing for f32s
5572        let r = unsafe { _mm_i32gather_ps::<4>(arr.as_ptr(), _mm_setr_epi32(0, 16, 32, 48)) };
5573        assert_eq_m128(r, _mm_setr_ps(0.0, 16.0, 32.0, 48.0));
5574    }
5575
5576    #[simd_test(enable = "avx2")]
5577    fn test_mm_mask_i32gather_ps() {
5578        let arr: [f32; 128] = core::array::from_fn(|i| i as f32);
5579        // A multiplier of 4 is word-addressing for f32s
5580        let r = unsafe {
5581            _mm_mask_i32gather_ps::<4>(
5582                _mm_set1_ps(256.0),
5583                arr.as_ptr(),
5584                _mm_setr_epi32(0, 16, 64, 96),
5585                _mm_setr_ps(-1.0, -1.0, -1.0, 0.0),
5586            )
5587        };
5588        assert_eq_m128(r, _mm_setr_ps(0.0, 16.0, 64.0, 256.0));
5589    }
5590
5591    #[simd_test(enable = "avx2")]
5592    fn test_mm256_i32gather_ps() {
5593        let arr: [f32; 128] = core::array::from_fn(|i| i as f32);
5594        // A multiplier of 4 is word-addressing for f32s
5595        let r = unsafe {
5596            _mm256_i32gather_ps::<4>(arr.as_ptr(), _mm256_setr_epi32(0, 16, 32, 48, 1, 2, 3, 4))
5597        };
5598        assert_eq_m256(r, _mm256_setr_ps(0.0, 16.0, 32.0, 48.0, 1.0, 2.0, 3.0, 4.0));
5599    }
5600
5601    #[simd_test(enable = "avx2")]
5602    fn test_mm256_mask_i32gather_ps() {
5603        let arr: [f32; 128] = core::array::from_fn(|i| i as f32);
5604        // A multiplier of 4 is word-addressing for f32s
5605        let r = unsafe {
5606            _mm256_mask_i32gather_ps::<4>(
5607                _mm256_set1_ps(256.0),
5608                arr.as_ptr(),
5609                _mm256_setr_epi32(0, 16, 64, 96, 0, 0, 0, 0),
5610                _mm256_setr_ps(-1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0),
5611            )
5612        };
5613        assert_eq_m256(
5614            r,
5615            _mm256_setr_ps(0.0, 16.0, 64.0, 256.0, 256.0, 256.0, 256.0, 256.0),
5616        );
5617    }
5618
5619    #[simd_test(enable = "avx2")]
5620    fn test_mm_i32gather_epi64() {
5621        let arr: [i64; 128] = core::array::from_fn(|i| i as i64);
5622        // A multiplier of 8 is word-addressing for i64s
5623        let r = unsafe { _mm_i32gather_epi64::<8>(arr.as_ptr(), _mm_setr_epi32(0, 16, 0, 0)) };
5624        assert_eq_m128i(r, _mm_setr_epi64x(0, 16));
5625    }
5626
5627    #[simd_test(enable = "avx2")]
5628    fn test_mm_mask_i32gather_epi64() {
5629        let arr: [i64; 128] = core::array::from_fn(|i| i as i64);
5630        // A multiplier of 8 is word-addressing for i64s
5631        let r = unsafe {
5632            _mm_mask_i32gather_epi64::<8>(
5633                _mm_set1_epi64x(256),
5634                arr.as_ptr(),
5635                _mm_setr_epi32(16, 16, 16, 16),
5636                _mm_setr_epi64x(-1, 0),
5637            )
5638        };
5639        assert_eq_m128i(r, _mm_setr_epi64x(16, 256));
5640    }
5641
5642    #[simd_test(enable = "avx2")]
5643    fn test_mm256_i32gather_epi64() {
5644        let arr: [i64; 128] = core::array::from_fn(|i| i as i64);
5645        // A multiplier of 8 is word-addressing for i64s
5646        let r = unsafe { _mm256_i32gather_epi64::<8>(arr.as_ptr(), _mm_setr_epi32(0, 16, 32, 48)) };
5647        assert_eq_m256i(r, _mm256_setr_epi64x(0, 16, 32, 48));
5648    }
5649
5650    #[simd_test(enable = "avx2")]
5651    fn test_mm256_mask_i32gather_epi64() {
5652        let arr: [i64; 128] = core::array::from_fn(|i| i as i64);
5653        // A multiplier of 8 is word-addressing for i64s
5654        let r = unsafe {
5655            _mm256_mask_i32gather_epi64::<8>(
5656                _mm256_set1_epi64x(256),
5657                arr.as_ptr(),
5658                _mm_setr_epi32(0, 16, 64, 96),
5659                _mm256_setr_epi64x(-1, -1, -1, 0),
5660            )
5661        };
5662        assert_eq_m256i(r, _mm256_setr_epi64x(0, 16, 64, 256));
5663    }
5664
5665    #[simd_test(enable = "avx2")]
5666    fn test_mm_i32gather_pd() {
5667        let arr: [f64; 128] = core::array::from_fn(|i| i as f64);
5668        // A multiplier of 8 is word-addressing for f64s
5669        let r = unsafe { _mm_i32gather_pd::<8>(arr.as_ptr(), _mm_setr_epi32(0, 16, 0, 0)) };
5670        assert_eq_m128d(r, _mm_setr_pd(0.0, 16.0));
5671    }
5672
5673    #[simd_test(enable = "avx2")]
5674    fn test_mm_mask_i32gather_pd() {
5675        let arr: [f64; 128] = core::array::from_fn(|i| i as f64);
5676        // A multiplier of 8 is word-addressing for f64s
5677        let r = unsafe {
5678            _mm_mask_i32gather_pd::<8>(
5679                _mm_set1_pd(256.0),
5680                arr.as_ptr(),
5681                _mm_setr_epi32(16, 16, 16, 16),
5682                _mm_setr_pd(-1.0, 0.0),
5683            )
5684        };
5685        assert_eq_m128d(r, _mm_setr_pd(16.0, 256.0));
5686    }
5687
5688    #[simd_test(enable = "avx2")]
5689    fn test_mm256_i32gather_pd() {
5690        let arr: [f64; 128] = core::array::from_fn(|i| i as f64);
5691        // A multiplier of 8 is word-addressing for f64s
5692        let r = unsafe { _mm256_i32gather_pd::<8>(arr.as_ptr(), _mm_setr_epi32(0, 16, 32, 48)) };
5693        assert_eq_m256d(r, _mm256_setr_pd(0.0, 16.0, 32.0, 48.0));
5694    }
5695
5696    #[simd_test(enable = "avx2")]
5697    fn test_mm256_mask_i32gather_pd() {
5698        let arr: [f64; 128] = core::array::from_fn(|i| i as f64);
5699        // A multiplier of 8 is word-addressing for f64s
5700        let r = unsafe {
5701            _mm256_mask_i32gather_pd::<8>(
5702                _mm256_set1_pd(256.0),
5703                arr.as_ptr(),
5704                _mm_setr_epi32(0, 16, 64, 96),
5705                _mm256_setr_pd(-1.0, -1.0, -1.0, 0.0),
5706            )
5707        };
5708        assert_eq_m256d(r, _mm256_setr_pd(0.0, 16.0, 64.0, 256.0));
5709    }
5710
5711    #[simd_test(enable = "avx2")]
5712    fn test_mm_i64gather_epi32() {
5713        let arr: [i32; 128] = core::array::from_fn(|i| i as i32);
5714        // A multiplier of 4 is word-addressing
5715        let r = unsafe { _mm_i64gather_epi32::<4>(arr.as_ptr(), _mm_setr_epi64x(0, 16)) };
5716        assert_eq_m128i(r, _mm_setr_epi32(0, 16, 0, 0));
5717    }
5718
5719    #[simd_test(enable = "avx2")]
5720    fn test_mm_mask_i64gather_epi32() {
5721        let arr: [i32; 128] = core::array::from_fn(|i| i as i32);
5722        // A multiplier of 4 is word-addressing
5723        let r = unsafe {
5724            _mm_mask_i64gather_epi32::<4>(
5725                _mm_set1_epi32(256),
5726                arr.as_ptr(),
5727                _mm_setr_epi64x(0, 16),
5728                _mm_setr_epi32(-1, 0, -1, 0),
5729            )
5730        };
5731        assert_eq_m128i(r, _mm_setr_epi32(0, 256, 0, 0));
5732    }
5733
5734    #[simd_test(enable = "avx2")]
5735    fn test_mm256_i64gather_epi32() {
5736        let arr: [i32; 128] = core::array::from_fn(|i| i as i32);
5737        // A multiplier of 4 is word-addressing
5738        let r =
5739            unsafe { _mm256_i64gather_epi32::<4>(arr.as_ptr(), _mm256_setr_epi64x(0, 16, 32, 48)) };
5740        assert_eq_m128i(r, _mm_setr_epi32(0, 16, 32, 48));
5741    }
5742
5743    #[simd_test(enable = "avx2")]
5744    fn test_mm256_mask_i64gather_epi32() {
5745        let arr: [i32; 128] = core::array::from_fn(|i| i as i32);
5746        // A multiplier of 4 is word-addressing
5747        let r = unsafe {
5748            _mm256_mask_i64gather_epi32::<4>(
5749                _mm_set1_epi32(256),
5750                arr.as_ptr(),
5751                _mm256_setr_epi64x(0, 16, 64, 96),
5752                _mm_setr_epi32(-1, -1, -1, 0),
5753            )
5754        };
5755        assert_eq_m128i(r, _mm_setr_epi32(0, 16, 64, 256));
5756    }
5757
5758    #[simd_test(enable = "avx2")]
5759    fn test_mm_i64gather_ps() {
5760        let arr: [f32; 128] = core::array::from_fn(|i| i as f32);
5761        // A multiplier of 4 is word-addressing for f32s
5762        let r = unsafe { _mm_i64gather_ps::<4>(arr.as_ptr(), _mm_setr_epi64x(0, 16)) };
5763        assert_eq_m128(r, _mm_setr_ps(0.0, 16.0, 0.0, 0.0));
5764    }
5765
5766    #[simd_test(enable = "avx2")]
5767    fn test_mm_mask_i64gather_ps() {
5768        let arr: [f32; 128] = core::array::from_fn(|i| i as f32);
5769        // A multiplier of 4 is word-addressing for f32s
5770        let r = unsafe {
5771            _mm_mask_i64gather_ps::<4>(
5772                _mm_set1_ps(256.0),
5773                arr.as_ptr(),
5774                _mm_setr_epi64x(0, 16),
5775                _mm_setr_ps(-1.0, 0.0, -1.0, 0.0),
5776            )
5777        };
5778        assert_eq_m128(r, _mm_setr_ps(0.0, 256.0, 0.0, 0.0));
5779    }
5780
5781    #[simd_test(enable = "avx2")]
5782    fn test_mm256_i64gather_ps() {
5783        let arr: [f32; 128] = core::array::from_fn(|i| i as f32);
5784        // A multiplier of 4 is word-addressing for f32s
5785        let r =
5786            unsafe { _mm256_i64gather_ps::<4>(arr.as_ptr(), _mm256_setr_epi64x(0, 16, 32, 48)) };
5787        assert_eq_m128(r, _mm_setr_ps(0.0, 16.0, 32.0, 48.0));
5788    }
5789
5790    #[simd_test(enable = "avx2")]
5791    fn test_mm256_mask_i64gather_ps() {
5792        let arr: [f32; 128] = core::array::from_fn(|i| i as f32);
5793        // A multiplier of 4 is word-addressing for f32s
5794        let r = unsafe {
5795            _mm256_mask_i64gather_ps::<4>(
5796                _mm_set1_ps(256.0),
5797                arr.as_ptr(),
5798                _mm256_setr_epi64x(0, 16, 64, 96),
5799                _mm_setr_ps(-1.0, -1.0, -1.0, 0.0),
5800            )
5801        };
5802        assert_eq_m128(r, _mm_setr_ps(0.0, 16.0, 64.0, 256.0));
5803    }
5804
5805    #[simd_test(enable = "avx2")]
5806    fn test_mm_i64gather_epi64() {
5807        let arr: [i64; 128] = core::array::from_fn(|i| i as i64);
5808        // A multiplier of 8 is word-addressing for i64s
5809        let r = unsafe { _mm_i64gather_epi64::<8>(arr.as_ptr(), _mm_setr_epi64x(0, 16)) };
5810        assert_eq_m128i(r, _mm_setr_epi64x(0, 16));
5811    }
5812
5813    #[simd_test(enable = "avx2")]
5814    fn test_mm_mask_i64gather_epi64() {
5815        let arr: [i64; 128] = core::array::from_fn(|i| i as i64);
5816        // A multiplier of 8 is word-addressing for i64s
5817        let r = unsafe {
5818            _mm_mask_i64gather_epi64::<8>(
5819                _mm_set1_epi64x(256),
5820                arr.as_ptr(),
5821                _mm_setr_epi64x(16, 16),
5822                _mm_setr_epi64x(-1, 0),
5823            )
5824        };
5825        assert_eq_m128i(r, _mm_setr_epi64x(16, 256));
5826    }
5827
5828    #[simd_test(enable = "avx2")]
5829    fn test_mm256_i64gather_epi64() {
5830        let arr: [i64; 128] = core::array::from_fn(|i| i as i64);
5831        // A multiplier of 8 is word-addressing for i64s
5832        let r =
5833            unsafe { _mm256_i64gather_epi64::<8>(arr.as_ptr(), _mm256_setr_epi64x(0, 16, 32, 48)) };
5834        assert_eq_m256i(r, _mm256_setr_epi64x(0, 16, 32, 48));
5835    }
5836
5837    #[simd_test(enable = "avx2")]
5838    fn test_mm256_mask_i64gather_epi64() {
5839        let arr: [i64; 128] = core::array::from_fn(|i| i as i64);
5840        // A multiplier of 8 is word-addressing for i64s
5841        let r = unsafe {
5842            _mm256_mask_i64gather_epi64::<8>(
5843                _mm256_set1_epi64x(256),
5844                arr.as_ptr(),
5845                _mm256_setr_epi64x(0, 16, 64, 96),
5846                _mm256_setr_epi64x(-1, -1, -1, 0),
5847            )
5848        };
5849        assert_eq_m256i(r, _mm256_setr_epi64x(0, 16, 64, 256));
5850    }
5851
5852    #[simd_test(enable = "avx2")]
5853    fn test_mm_i64gather_pd() {
5854        let arr: [f64; 128] = core::array::from_fn(|i| i as f64);
5855        // A multiplier of 8 is word-addressing for f64s
5856        let r = unsafe { _mm_i64gather_pd::<8>(arr.as_ptr(), _mm_setr_epi64x(0, 16)) };
5857        assert_eq_m128d(r, _mm_setr_pd(0.0, 16.0));
5858    }
5859
5860    #[simd_test(enable = "avx2")]
5861    fn test_mm_mask_i64gather_pd() {
5862        let arr: [f64; 128] = core::array::from_fn(|i| i as f64);
5863        // A multiplier of 8 is word-addressing for f64s
5864        let r = unsafe {
5865            _mm_mask_i64gather_pd::<8>(
5866                _mm_set1_pd(256.0),
5867                arr.as_ptr(),
5868                _mm_setr_epi64x(16, 16),
5869                _mm_setr_pd(-1.0, 0.0),
5870            )
5871        };
5872        assert_eq_m128d(r, _mm_setr_pd(16.0, 256.0));
5873    }
5874
5875    #[simd_test(enable = "avx2")]
5876    fn test_mm256_i64gather_pd() {
5877        let arr: [f64; 128] = core::array::from_fn(|i| i as f64);
5878        // A multiplier of 8 is word-addressing for f64s
5879        let r =
5880            unsafe { _mm256_i64gather_pd::<8>(arr.as_ptr(), _mm256_setr_epi64x(0, 16, 32, 48)) };
5881        assert_eq_m256d(r, _mm256_setr_pd(0.0, 16.0, 32.0, 48.0));
5882    }
5883
5884    #[simd_test(enable = "avx2")]
5885    fn test_mm256_mask_i64gather_pd() {
5886        let arr: [f64; 128] = core::array::from_fn(|i| i as f64);
5887        // A multiplier of 8 is word-addressing for f64s
5888        let r = unsafe {
5889            _mm256_mask_i64gather_pd::<8>(
5890                _mm256_set1_pd(256.0),
5891                arr.as_ptr(),
5892                _mm256_setr_epi64x(0, 16, 64, 96),
5893                _mm256_setr_pd(-1.0, -1.0, -1.0, 0.0),
5894            )
5895        };
5896        assert_eq_m256d(r, _mm256_setr_pd(0.0, 16.0, 64.0, 256.0));
5897    }
5898
5899    #[simd_test(enable = "avx2")]
5900    const fn test_mm256_extract_epi8() {
5901        #[rustfmt::skip]
5902        let a = _mm256_setr_epi8(
5903            -1, 1, 2, 3, 4, 5, 6, 7,
5904            8, 9, 10, 11, 12, 13, 14, 15,
5905            16, 17, 18, 19, 20, 21, 22, 23,
5906            24, 25, 26, 27, 28, 29, 30, 31
5907        );
5908        let r1 = _mm256_extract_epi8::<0>(a);
5909        let r2 = _mm256_extract_epi8::<3>(a);
5910        assert_eq!(r1, 0xFF);
5911        assert_eq!(r2, 3);
5912    }
5913
5914    #[simd_test(enable = "avx2")]
5915    const fn test_mm256_extract_epi16() {
5916        #[rustfmt::skip]
5917        let a = _mm256_setr_epi16(
5918            -1, 1, 2, 3, 4, 5, 6, 7,
5919            8, 9, 10, 11, 12, 13, 14, 15,
5920        );
5921        let r1 = _mm256_extract_epi16::<0>(a);
5922        let r2 = _mm256_extract_epi16::<3>(a);
5923        assert_eq!(r1, 0xFFFF);
5924        assert_eq!(r2, 3);
5925    }
5926}