Skip to main content

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

1//! Streaming SIMD Extensions 2 (SSE2)
2
3#[cfg(test)]
4use stdarch_test::assert_instr;
5
6use crate::{
7    core_arch::{simd::*, x86::*},
8    intrinsics::simd::*,
9    intrinsics::sqrt,
10    mem, ptr,
11};
12
13/// Provides a hint to the processor that the code sequence is a spin-wait loop.
14///
15/// This can help improve the performance and power consumption of spin-wait
16/// loops.
17///
18/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_pause)
19#[inline]
20#[cfg_attr(all(test, target_feature = "sse2"), assert_instr(pause))]
21#[stable(feature = "simd_x86", since = "1.27.0")]
22pub fn _mm_pause() {
23    // note: `pause` is guaranteed to be interpreted as a `nop` by CPUs without
24    // the SSE2 target-feature - therefore it does not require any target features
25    unsafe { pause() }
26}
27
28/// Invalidates and flushes the cache line that contains `p` from all levels of
29/// the cache hierarchy.
30///
31/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_clflush)
32///
33/// # Safety
34///
35/// Unlike the prefetch intrinsics, `CLFLUSH` is subject to all the permission
36/// checking and faults associated with a byte load, so `p` must point to a
37/// byte that is valid for reads.
38#[inline]
39#[target_feature(enable = "sse2")]
40#[cfg_attr(test, assert_instr(clflush))]
41#[stable(feature = "simd_x86", since = "1.27.0")]
42pub unsafe fn _mm_clflush(p: *const u8) {
43    clflush(p)
44}
45
46/// Performs a serializing operation on all load-from-memory instructions
47/// that were issued prior to this instruction.
48///
49/// Guarantees that every load instruction that precedes, in program order, is
50/// globally visible before any load instruction which follows the fence in
51/// program order.
52///
53/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_lfence)
54#[inline]
55#[target_feature(enable = "sse2")]
56#[cfg_attr(test, assert_instr(lfence))]
57#[stable(feature = "simd_x86", since = "1.27.0")]
58pub fn _mm_lfence() {
59    unsafe { lfence() }
60}
61
62/// Performs a serializing operation on all load-from-memory and store-to-memory
63/// instructions that were issued prior to this instruction.
64///
65/// Guarantees that every memory access that precedes, in program order, the
66/// memory fence instruction is globally visible before any memory instruction
67/// which follows the fence in program order.
68///
69/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mfence)
70#[inline]
71#[target_feature(enable = "sse2")]
72#[cfg_attr(test, assert_instr(mfence))]
73#[stable(feature = "simd_x86", since = "1.27.0")]
74pub fn _mm_mfence() {
75    unsafe { mfence() }
76}
77
78/// Adds packed 8-bit integers in `a` and `b`.
79///
80/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_add_epi8)
81#[inline]
82#[target_feature(enable = "sse2")]
83#[cfg_attr(test, assert_instr(paddb))]
84#[stable(feature = "simd_x86", since = "1.27.0")]
85#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
86pub const fn _mm_add_epi8(a: __m128i, b: __m128i) -> __m128i {
87    unsafe { transmute(simd_add(a.as_i8x16(), b.as_i8x16())) }
88}
89
90/// Adds packed 16-bit integers in `a` and `b`.
91///
92/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_add_epi16)
93#[inline]
94#[target_feature(enable = "sse2")]
95#[cfg_attr(test, assert_instr(paddw))]
96#[stable(feature = "simd_x86", since = "1.27.0")]
97#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
98pub const fn _mm_add_epi16(a: __m128i, b: __m128i) -> __m128i {
99    unsafe { transmute(simd_add(a.as_i16x8(), b.as_i16x8())) }
100}
101
102/// Adds packed 32-bit integers in `a` and `b`.
103///
104/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_add_epi32)
105#[inline]
106#[target_feature(enable = "sse2")]
107#[cfg_attr(test, assert_instr(paddd))]
108#[stable(feature = "simd_x86", since = "1.27.0")]
109#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
110pub const fn _mm_add_epi32(a: __m128i, b: __m128i) -> __m128i {
111    unsafe { transmute(simd_add(a.as_i32x4(), b.as_i32x4())) }
112}
113
114/// Adds packed 64-bit integers in `a` and `b`.
115///
116/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_add_epi64)
117#[inline]
118#[target_feature(enable = "sse2")]
119#[cfg_attr(test, assert_instr(paddq))]
120#[stable(feature = "simd_x86", since = "1.27.0")]
121#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
122pub const fn _mm_add_epi64(a: __m128i, b: __m128i) -> __m128i {
123    unsafe { transmute(simd_add(a.as_i64x2(), b.as_i64x2())) }
124}
125
126/// Adds packed 8-bit integers in `a` and `b` using saturation.
127///
128/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_adds_epi8)
129#[inline]
130#[target_feature(enable = "sse2")]
131#[cfg_attr(test, assert_instr(paddsb))]
132#[stable(feature = "simd_x86", since = "1.27.0")]
133#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
134pub const fn _mm_adds_epi8(a: __m128i, b: __m128i) -> __m128i {
135    unsafe { transmute(simd_saturating_add(a.as_i8x16(), b.as_i8x16())) }
136}
137
138/// Adds packed 16-bit integers in `a` and `b` using saturation.
139///
140/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_adds_epi16)
141#[inline]
142#[target_feature(enable = "sse2")]
143#[cfg_attr(test, assert_instr(paddsw))]
144#[stable(feature = "simd_x86", since = "1.27.0")]
145#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
146pub const fn _mm_adds_epi16(a: __m128i, b: __m128i) -> __m128i {
147    unsafe { transmute(simd_saturating_add(a.as_i16x8(), b.as_i16x8())) }
148}
149
150/// Adds packed unsigned 8-bit integers in `a` and `b` using saturation.
151///
152/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_adds_epu8)
153#[inline]
154#[target_feature(enable = "sse2")]
155#[cfg_attr(test, assert_instr(paddusb))]
156#[stable(feature = "simd_x86", since = "1.27.0")]
157#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
158pub const fn _mm_adds_epu8(a: __m128i, b: __m128i) -> __m128i {
159    unsafe { transmute(simd_saturating_add(a.as_u8x16(), b.as_u8x16())) }
160}
161
162/// Adds packed unsigned 16-bit integers in `a` and `b` using saturation.
163///
164/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_adds_epu16)
165#[inline]
166#[target_feature(enable = "sse2")]
167#[cfg_attr(test, assert_instr(paddusw))]
168#[stable(feature = "simd_x86", since = "1.27.0")]
169#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
170pub const fn _mm_adds_epu16(a: __m128i, b: __m128i) -> __m128i {
171    unsafe { transmute(simd_saturating_add(a.as_u16x8(), b.as_u16x8())) }
172}
173
174/// Averages packed unsigned 8-bit integers in `a` and `b`.
175///
176/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_avg_epu8)
177#[inline]
178#[target_feature(enable = "sse2")]
179#[cfg_attr(test, assert_instr(pavgb))]
180#[stable(feature = "simd_x86", since = "1.27.0")]
181pub fn _mm_avg_epu8(a: __m128i, b: __m128i) -> __m128i {
182    unsafe { transmute(pavgb(a.as_u8x16(), b.as_u8x16())) }
183}
184
185/// Averages packed unsigned 16-bit integers in `a` and `b`.
186///
187/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_avg_epu16)
188#[inline]
189#[target_feature(enable = "sse2")]
190#[cfg_attr(test, assert_instr(pavgw))]
191#[stable(feature = "simd_x86", since = "1.27.0")]
192pub fn _mm_avg_epu16(a: __m128i, b: __m128i) -> __m128i {
193    unsafe { transmute(pavgw(a.as_u16x8(), b.as_u16x8())) }
194}
195
196/// Multiplies and then horizontally add signed 16 bit integers in `a` and `b`.
197///
198/// Multiplies packed signed 16-bit integers in `a` and `b`, producing
199/// intermediate signed 32-bit integers. Horizontally add adjacent pairs of
200/// intermediate 32-bit integers.
201///
202/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_madd_epi16)
203#[inline]
204#[target_feature(enable = "sse2")]
205#[cfg_attr(test, assert_instr(pmaddwd))]
206#[stable(feature = "simd_x86", since = "1.27.0")]
207pub fn _mm_madd_epi16(a: __m128i, b: __m128i) -> __m128i {
208    // It's a trick used in the Adler-32 algorithm to perform a widening addition.
209    //
210    // ```rust
211    // #[target_feature(enable = "sse2")]
212    // unsafe fn widening_add(mad: __m128i) -> __m128i {
213    //     _mm_madd_epi16(mad, _mm_set1_epi16(1))
214    // }
215    // ```
216    //
217    // If we implement this using generic vector intrinsics, the optimizer
218    // will eliminate this pattern, and `pmaddwd` will no longer be emitted.
219    // For this reason, we use x86 intrinsics.
220    unsafe { transmute(pmaddwd(a.as_i16x8(), b.as_i16x8())) }
221}
222
223/// Compares packed 16-bit integers in `a` and `b`, and returns the packed
224/// maximum values.
225///
226/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_epi16)
227#[inline]
228#[target_feature(enable = "sse2")]
229#[cfg_attr(test, assert_instr(pmaxsw))]
230#[stable(feature = "simd_x86", since = "1.27.0")]
231#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
232pub const fn _mm_max_epi16(a: __m128i, b: __m128i) -> __m128i {
233    unsafe { simd_imax(a.as_i16x8(), b.as_i16x8()).as_m128i() }
234}
235
236/// Compares packed unsigned 8-bit integers in `a` and `b`, and returns the
237/// packed maximum values.
238///
239/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_epu8)
240#[inline]
241#[target_feature(enable = "sse2")]
242#[cfg_attr(test, assert_instr(pmaxub))]
243#[stable(feature = "simd_x86", since = "1.27.0")]
244#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
245pub const fn _mm_max_epu8(a: __m128i, b: __m128i) -> __m128i {
246    unsafe { simd_imax(a.as_u8x16(), b.as_u8x16()).as_m128i() }
247}
248
249/// Compares packed 16-bit integers in `a` and `b`, and returns the packed
250/// minimum values.
251///
252/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_epi16)
253#[inline]
254#[target_feature(enable = "sse2")]
255#[cfg_attr(test, assert_instr(pminsw))]
256#[stable(feature = "simd_x86", since = "1.27.0")]
257#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
258pub const fn _mm_min_epi16(a: __m128i, b: __m128i) -> __m128i {
259    unsafe { simd_imin(a.as_i16x8(), b.as_i16x8()).as_m128i() }
260}
261
262/// Compares packed unsigned 8-bit integers in `a` and `b`, and returns the
263/// packed minimum values.
264///
265/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_epu8)
266#[inline]
267#[target_feature(enable = "sse2")]
268#[cfg_attr(test, assert_instr(pminub))]
269#[stable(feature = "simd_x86", since = "1.27.0")]
270#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
271pub const fn _mm_min_epu8(a: __m128i, b: __m128i) -> __m128i {
272    unsafe { simd_imin(a.as_u8x16(), b.as_u8x16()).as_m128i() }
273}
274
275/// Multiplies the packed 16-bit integers in `a` and `b`.
276///
277/// The multiplication produces intermediate 32-bit integers, and returns the
278/// high 16 bits of the intermediate integers.
279///
280/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mulhi_epi16)
281#[inline]
282#[target_feature(enable = "sse2")]
283#[cfg_attr(test, assert_instr(pmulhw))]
284#[stable(feature = "simd_x86", since = "1.27.0")]
285pub fn _mm_mulhi_epi16(a: __m128i, b: __m128i) -> __m128i {
286    unsafe { transmute(pmulhw(a.as_i16x8(), b.as_i16x8())) }
287}
288
289/// Multiplies the packed unsigned 16-bit integers in `a` and `b`.
290///
291/// The multiplication produces intermediate 32-bit integers, and returns the
292/// high 16 bits of the intermediate integers.
293///
294/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mulhi_epu16)
295#[inline]
296#[target_feature(enable = "sse2")]
297#[cfg_attr(test, assert_instr(pmulhuw))]
298#[stable(feature = "simd_x86", since = "1.27.0")]
299pub fn _mm_mulhi_epu16(a: __m128i, b: __m128i) -> __m128i {
300    unsafe { transmute(pmulhuw(a.as_u16x8(), b.as_u16x8())) }
301}
302
303/// Multiplies the packed 16-bit integers in `a` and `b`.
304///
305/// The multiplication produces intermediate 32-bit integers, and returns the
306/// low 16 bits of the intermediate integers.
307///
308/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mullo_epi16)
309#[inline]
310#[target_feature(enable = "sse2")]
311#[cfg_attr(test, assert_instr(pmullw))]
312#[stable(feature = "simd_x86", since = "1.27.0")]
313#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
314pub const fn _mm_mullo_epi16(a: __m128i, b: __m128i) -> __m128i {
315    unsafe { transmute(simd_mul(a.as_i16x8(), b.as_i16x8())) }
316}
317
318/// Multiplies the low unsigned 32-bit integers from each packed 64-bit element
319/// in `a` and `b`.
320///
321/// Returns the unsigned 64-bit results.
322///
323/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mul_epu32)
324#[inline]
325#[target_feature(enable = "sse2")]
326#[cfg_attr(test, assert_instr(pmuludq))]
327#[stable(feature = "simd_x86", since = "1.27.0")]
328#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
329pub const fn _mm_mul_epu32(a: __m128i, b: __m128i) -> __m128i {
330    unsafe {
331        let a = a.as_u64x2();
332        let b = b.as_u64x2();
333        let mask = u64x2::splat(u32::MAX as u64);
334        transmute(simd_mul(simd_and(a, mask), simd_and(b, mask)))
335    }
336}
337
338/// Sum the absolute differences of packed unsigned 8-bit integers.
339///
340/// Computes the absolute differences of packed unsigned 8-bit integers in `a`
341/// and `b`, then horizontally sum each consecutive 8 differences to produce
342/// two unsigned 16-bit integers, and pack these unsigned 16-bit integers in
343/// the low 16 bits of 64-bit elements returned.
344///
345/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sad_epu8)
346#[inline]
347#[target_feature(enable = "sse2")]
348#[cfg_attr(test, assert_instr(psadbw))]
349#[stable(feature = "simd_x86", since = "1.27.0")]
350pub fn _mm_sad_epu8(a: __m128i, b: __m128i) -> __m128i {
351    unsafe { transmute(psadbw(a.as_u8x16(), b.as_u8x16())) }
352}
353
354/// Subtracts packed 8-bit integers in `b` from packed 8-bit integers in `a`.
355///
356/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_epi8)
357#[inline]
358#[target_feature(enable = "sse2")]
359#[cfg_attr(test, assert_instr(psubb))]
360#[stable(feature = "simd_x86", since = "1.27.0")]
361#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
362pub const fn _mm_sub_epi8(a: __m128i, b: __m128i) -> __m128i {
363    unsafe { transmute(simd_sub(a.as_i8x16(), b.as_i8x16())) }
364}
365
366/// Subtracts packed 16-bit integers in `b` from packed 16-bit integers in `a`.
367///
368/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_epi16)
369#[inline]
370#[target_feature(enable = "sse2")]
371#[cfg_attr(test, assert_instr(psubw))]
372#[stable(feature = "simd_x86", since = "1.27.0")]
373#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
374pub const fn _mm_sub_epi16(a: __m128i, b: __m128i) -> __m128i {
375    unsafe { transmute(simd_sub(a.as_i16x8(), b.as_i16x8())) }
376}
377
378/// Subtract packed 32-bit integers in `b` from packed 32-bit integers in `a`.
379///
380/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_epi32)
381#[inline]
382#[target_feature(enable = "sse2")]
383#[cfg_attr(test, assert_instr(psubd))]
384#[stable(feature = "simd_x86", since = "1.27.0")]
385#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
386pub const fn _mm_sub_epi32(a: __m128i, b: __m128i) -> __m128i {
387    unsafe { transmute(simd_sub(a.as_i32x4(), b.as_i32x4())) }
388}
389
390/// Subtract packed 64-bit integers in `b` from packed 64-bit integers in `a`.
391///
392/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_epi64)
393#[inline]
394#[target_feature(enable = "sse2")]
395#[cfg_attr(test, assert_instr(psubq))]
396#[stable(feature = "simd_x86", since = "1.27.0")]
397#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
398pub const fn _mm_sub_epi64(a: __m128i, b: __m128i) -> __m128i {
399    unsafe { transmute(simd_sub(a.as_i64x2(), b.as_i64x2())) }
400}
401
402/// Subtract packed 8-bit integers in `b` from packed 8-bit integers in `a`
403/// using saturation.
404///
405/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_subs_epi8)
406#[inline]
407#[target_feature(enable = "sse2")]
408#[cfg_attr(test, assert_instr(psubsb))]
409#[stable(feature = "simd_x86", since = "1.27.0")]
410#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
411pub const fn _mm_subs_epi8(a: __m128i, b: __m128i) -> __m128i {
412    unsafe { transmute(simd_saturating_sub(a.as_i8x16(), b.as_i8x16())) }
413}
414
415/// Subtract packed 16-bit integers in `b` from packed 16-bit integers in `a`
416/// using saturation.
417///
418/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_subs_epi16)
419#[inline]
420#[target_feature(enable = "sse2")]
421#[cfg_attr(test, assert_instr(psubsw))]
422#[stable(feature = "simd_x86", since = "1.27.0")]
423#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
424pub const fn _mm_subs_epi16(a: __m128i, b: __m128i) -> __m128i {
425    unsafe { transmute(simd_saturating_sub(a.as_i16x8(), b.as_i16x8())) }
426}
427
428/// Subtract packed unsigned 8-bit integers in `b` from packed unsigned 8-bit
429/// integers in `a` using saturation.
430///
431/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_subs_epu8)
432#[inline]
433#[target_feature(enable = "sse2")]
434#[cfg_attr(test, assert_instr(psubusb))]
435#[stable(feature = "simd_x86", since = "1.27.0")]
436#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
437pub const fn _mm_subs_epu8(a: __m128i, b: __m128i) -> __m128i {
438    unsafe { transmute(simd_saturating_sub(a.as_u8x16(), b.as_u8x16())) }
439}
440
441/// Subtract packed unsigned 16-bit integers in `b` from packed unsigned 16-bit
442/// integers in `a` using saturation.
443///
444/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_subs_epu16)
445#[inline]
446#[target_feature(enable = "sse2")]
447#[cfg_attr(test, assert_instr(psubusw))]
448#[stable(feature = "simd_x86", since = "1.27.0")]
449#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
450pub const fn _mm_subs_epu16(a: __m128i, b: __m128i) -> __m128i {
451    unsafe { transmute(simd_saturating_sub(a.as_u16x8(), b.as_u16x8())) }
452}
453
454/// Shifts `a` left by `IMM8` bytes while shifting in zeros.
455///
456/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_slli_si128)
457#[inline]
458#[target_feature(enable = "sse2")]
459#[cfg_attr(test, assert_instr(pslldq, IMM8 = 1))]
460#[rustc_legacy_const_generics(1)]
461#[stable(feature = "simd_x86", since = "1.27.0")]
462#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
463pub const fn _mm_slli_si128<const IMM8: i32>(a: __m128i) -> __m128i {
464    static_assert_uimm_bits!(IMM8, 8);
465    unsafe { _mm_slli_si128_impl::<IMM8>(a) }
466}
467
468/// Implementation detail: converts the immediate argument of the
469/// `_mm_slli_si128` intrinsic into a compile-time constant.
470#[inline]
471#[target_feature(enable = "sse2")]
472#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
473const unsafe fn _mm_slli_si128_impl<const IMM8: i32>(a: __m128i) -> __m128i {
474    const fn mask(shift: i32, i: u32) -> u32 {
475        let shift = shift as u32 & 0xff;
476        if shift > 15 { i } else { 16 - shift + i }
477    }
478    transmute::<i8x16, _>(simd_shuffle!(
479        i8x16::ZERO,
480        a.as_i8x16(),
481        [
482            mask(IMM8, 0),
483            mask(IMM8, 1),
484            mask(IMM8, 2),
485            mask(IMM8, 3),
486            mask(IMM8, 4),
487            mask(IMM8, 5),
488            mask(IMM8, 6),
489            mask(IMM8, 7),
490            mask(IMM8, 8),
491            mask(IMM8, 9),
492            mask(IMM8, 10),
493            mask(IMM8, 11),
494            mask(IMM8, 12),
495            mask(IMM8, 13),
496            mask(IMM8, 14),
497            mask(IMM8, 15),
498        ],
499    ))
500}
501
502/// Shifts `a` left by `IMM8` bytes while shifting in zeros.
503///
504/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_bslli_si128)
505#[inline]
506#[target_feature(enable = "sse2")]
507#[cfg_attr(test, assert_instr(pslldq, IMM8 = 1))]
508#[rustc_legacy_const_generics(1)]
509#[stable(feature = "simd_x86", since = "1.27.0")]
510#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
511pub const fn _mm_bslli_si128<const IMM8: i32>(a: __m128i) -> __m128i {
512    unsafe {
513        static_assert_uimm_bits!(IMM8, 8);
514        _mm_slli_si128_impl::<IMM8>(a)
515    }
516}
517
518/// Shifts `a` right by `IMM8` bytes while shifting in zeros.
519///
520/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_bsrli_si128)
521#[inline]
522#[target_feature(enable = "sse2")]
523#[cfg_attr(test, assert_instr(psrldq, IMM8 = 1))]
524#[rustc_legacy_const_generics(1)]
525#[stable(feature = "simd_x86", since = "1.27.0")]
526#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
527pub const fn _mm_bsrli_si128<const IMM8: i32>(a: __m128i) -> __m128i {
528    unsafe {
529        static_assert_uimm_bits!(IMM8, 8);
530        _mm_srli_si128_impl::<IMM8>(a)
531    }
532}
533
534/// Shifts packed 16-bit integers in `a` left by `IMM8` while shifting in zeros.
535///
536/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_slli_epi16)
537#[inline]
538#[target_feature(enable = "sse2")]
539#[cfg_attr(test, assert_instr(psllw, IMM8 = 7))]
540#[rustc_legacy_const_generics(1)]
541#[stable(feature = "simd_x86", since = "1.27.0")]
542#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
543pub const fn _mm_slli_epi16<const IMM8: i32>(a: __m128i) -> __m128i {
544    static_assert_uimm_bits!(IMM8, 8);
545    unsafe {
546        if IMM8 >= 16 {
547            _mm_setzero_si128()
548        } else {
549            transmute(simd_shl(a.as_u16x8(), u16x8::splat(IMM8 as u16)))
550        }
551    }
552}
553
554/// Shifts packed 16-bit integers in `a` left by `count` while shifting in
555/// zeros.
556///
557/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sll_epi16)
558#[inline]
559#[target_feature(enable = "sse2")]
560#[cfg_attr(test, assert_instr(psllw))]
561#[stable(feature = "simd_x86", since = "1.27.0")]
562pub fn _mm_sll_epi16(a: __m128i, count: __m128i) -> __m128i {
563    unsafe { transmute(psllw(a.as_i16x8(), count.as_i16x8())) }
564}
565
566/// Shifts packed 32-bit integers in `a` left by `IMM8` while shifting in zeros.
567///
568/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_slli_epi32)
569#[inline]
570#[target_feature(enable = "sse2")]
571#[cfg_attr(test, assert_instr(pslld, IMM8 = 7))]
572#[rustc_legacy_const_generics(1)]
573#[stable(feature = "simd_x86", since = "1.27.0")]
574#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
575pub const fn _mm_slli_epi32<const IMM8: i32>(a: __m128i) -> __m128i {
576    static_assert_uimm_bits!(IMM8, 8);
577    unsafe {
578        if IMM8 >= 32 {
579            _mm_setzero_si128()
580        } else {
581            transmute(simd_shl(a.as_u32x4(), u32x4::splat(IMM8 as u32)))
582        }
583    }
584}
585
586/// Shifts packed 32-bit integers in `a` left by `count` while shifting in
587/// zeros.
588///
589/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sll_epi32)
590#[inline]
591#[target_feature(enable = "sse2")]
592#[cfg_attr(test, assert_instr(pslld))]
593#[stable(feature = "simd_x86", since = "1.27.0")]
594pub fn _mm_sll_epi32(a: __m128i, count: __m128i) -> __m128i {
595    unsafe { transmute(pslld(a.as_i32x4(), count.as_i32x4())) }
596}
597
598/// Shifts packed 64-bit integers in `a` left by `IMM8` while shifting in zeros.
599///
600/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_slli_epi64)
601#[inline]
602#[target_feature(enable = "sse2")]
603#[cfg_attr(test, assert_instr(psllq, IMM8 = 7))]
604#[rustc_legacy_const_generics(1)]
605#[stable(feature = "simd_x86", since = "1.27.0")]
606#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
607pub const fn _mm_slli_epi64<const IMM8: i32>(a: __m128i) -> __m128i {
608    static_assert_uimm_bits!(IMM8, 8);
609    unsafe {
610        if IMM8 >= 64 {
611            _mm_setzero_si128()
612        } else {
613            transmute(simd_shl(a.as_u64x2(), u64x2::splat(IMM8 as u64)))
614        }
615    }
616}
617
618/// Shifts packed 64-bit integers in `a` left by `count` while shifting in
619/// zeros.
620///
621/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sll_epi64)
622#[inline]
623#[target_feature(enable = "sse2")]
624#[cfg_attr(test, assert_instr(psllq))]
625#[stable(feature = "simd_x86", since = "1.27.0")]
626pub fn _mm_sll_epi64(a: __m128i, count: __m128i) -> __m128i {
627    unsafe { transmute(psllq(a.as_i64x2(), count.as_i64x2())) }
628}
629
630/// Shifts packed 16-bit integers in `a` right by `IMM8` while shifting in sign
631/// bits.
632///
633/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srai_epi16)
634#[inline]
635#[target_feature(enable = "sse2")]
636#[cfg_attr(test, assert_instr(psraw, IMM8 = 1))]
637#[rustc_legacy_const_generics(1)]
638#[stable(feature = "simd_x86", since = "1.27.0")]
639#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
640pub const fn _mm_srai_epi16<const IMM8: i32>(a: __m128i) -> __m128i {
641    static_assert_uimm_bits!(IMM8, 8);
642    unsafe { transmute(simd_shr(a.as_i16x8(), i16x8::splat(IMM8.min(15) as i16))) }
643}
644
645/// Shifts packed 16-bit integers in `a` right by `count` while shifting in sign
646/// bits.
647///
648/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sra_epi16)
649#[inline]
650#[target_feature(enable = "sse2")]
651#[cfg_attr(test, assert_instr(psraw))]
652#[stable(feature = "simd_x86", since = "1.27.0")]
653pub fn _mm_sra_epi16(a: __m128i, count: __m128i) -> __m128i {
654    unsafe { transmute(psraw(a.as_i16x8(), count.as_i16x8())) }
655}
656
657/// Shifts packed 32-bit integers in `a` right by `IMM8` while shifting in sign
658/// bits.
659///
660/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srai_epi32)
661#[inline]
662#[target_feature(enable = "sse2")]
663#[cfg_attr(test, assert_instr(psrad, IMM8 = 1))]
664#[rustc_legacy_const_generics(1)]
665#[stable(feature = "simd_x86", since = "1.27.0")]
666#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
667pub const fn _mm_srai_epi32<const IMM8: i32>(a: __m128i) -> __m128i {
668    static_assert_uimm_bits!(IMM8, 8);
669    unsafe { transmute(simd_shr(a.as_i32x4(), i32x4::splat(IMM8.min(31)))) }
670}
671
672/// Shifts packed 32-bit integers in `a` right by `count` while shifting in sign
673/// bits.
674///
675/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sra_epi32)
676#[inline]
677#[target_feature(enable = "sse2")]
678#[cfg_attr(test, assert_instr(psrad))]
679#[stable(feature = "simd_x86", since = "1.27.0")]
680pub fn _mm_sra_epi32(a: __m128i, count: __m128i) -> __m128i {
681    unsafe { transmute(psrad(a.as_i32x4(), count.as_i32x4())) }
682}
683
684/// Shifts `a` right by `IMM8` bytes while shifting in zeros.
685///
686/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srli_si128)
687#[inline]
688#[target_feature(enable = "sse2")]
689#[cfg_attr(test, assert_instr(psrldq, IMM8 = 1))]
690#[rustc_legacy_const_generics(1)]
691#[stable(feature = "simd_x86", since = "1.27.0")]
692#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
693pub const fn _mm_srli_si128<const IMM8: i32>(a: __m128i) -> __m128i {
694    static_assert_uimm_bits!(IMM8, 8);
695    unsafe { _mm_srli_si128_impl::<IMM8>(a) }
696}
697
698/// Implementation detail: converts the immediate argument of the
699/// `_mm_srli_si128` intrinsic into a compile-time constant.
700#[inline]
701#[target_feature(enable = "sse2")]
702#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
703const unsafe fn _mm_srli_si128_impl<const IMM8: i32>(a: __m128i) -> __m128i {
704    const fn mask(shift: i32, i: u32) -> u32 {
705        if (shift as u32) > 15 {
706            i + 16
707        } else {
708            i + (shift as u32)
709        }
710    }
711    let x: i8x16 = simd_shuffle!(
712        a.as_i8x16(),
713        i8x16::ZERO,
714        [
715            mask(IMM8, 0),
716            mask(IMM8, 1),
717            mask(IMM8, 2),
718            mask(IMM8, 3),
719            mask(IMM8, 4),
720            mask(IMM8, 5),
721            mask(IMM8, 6),
722            mask(IMM8, 7),
723            mask(IMM8, 8),
724            mask(IMM8, 9),
725            mask(IMM8, 10),
726            mask(IMM8, 11),
727            mask(IMM8, 12),
728            mask(IMM8, 13),
729            mask(IMM8, 14),
730            mask(IMM8, 15),
731        ],
732    );
733    transmute(x)
734}
735
736/// Shifts packed 16-bit integers in `a` right by `IMM8` while shifting in
737/// zeros.
738///
739/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srli_epi16)
740#[inline]
741#[target_feature(enable = "sse2")]
742#[cfg_attr(test, assert_instr(psrlw, IMM8 = 1))]
743#[rustc_legacy_const_generics(1)]
744#[stable(feature = "simd_x86", since = "1.27.0")]
745#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
746pub const fn _mm_srli_epi16<const IMM8: i32>(a: __m128i) -> __m128i {
747    static_assert_uimm_bits!(IMM8, 8);
748    unsafe {
749        if IMM8 >= 16 {
750            _mm_setzero_si128()
751        } else {
752            transmute(simd_shr(a.as_u16x8(), u16x8::splat(IMM8 as u16)))
753        }
754    }
755}
756
757/// Shifts packed 16-bit integers in `a` right by `count` while shifting in
758/// zeros.
759///
760/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srl_epi16)
761#[inline]
762#[target_feature(enable = "sse2")]
763#[cfg_attr(test, assert_instr(psrlw))]
764#[stable(feature = "simd_x86", since = "1.27.0")]
765pub fn _mm_srl_epi16(a: __m128i, count: __m128i) -> __m128i {
766    unsafe { transmute(psrlw(a.as_i16x8(), count.as_i16x8())) }
767}
768
769/// Shifts packed 32-bit integers in `a` right by `IMM8` while shifting in
770/// zeros.
771///
772/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srli_epi32)
773#[inline]
774#[target_feature(enable = "sse2")]
775#[cfg_attr(test, assert_instr(psrld, IMM8 = 8))]
776#[rustc_legacy_const_generics(1)]
777#[stable(feature = "simd_x86", since = "1.27.0")]
778#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
779pub const fn _mm_srli_epi32<const IMM8: i32>(a: __m128i) -> __m128i {
780    static_assert_uimm_bits!(IMM8, 8);
781    unsafe {
782        if IMM8 >= 32 {
783            _mm_setzero_si128()
784        } else {
785            transmute(simd_shr(a.as_u32x4(), u32x4::splat(IMM8 as u32)))
786        }
787    }
788}
789
790/// Shifts packed 32-bit integers in `a` right by `count` while shifting in
791/// zeros.
792///
793/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srl_epi32)
794#[inline]
795#[target_feature(enable = "sse2")]
796#[cfg_attr(test, assert_instr(psrld))]
797#[stable(feature = "simd_x86", since = "1.27.0")]
798pub fn _mm_srl_epi32(a: __m128i, count: __m128i) -> __m128i {
799    unsafe { transmute(psrld(a.as_i32x4(), count.as_i32x4())) }
800}
801
802/// Shifts packed 64-bit integers in `a` right by `IMM8` while shifting in
803/// zeros.
804///
805/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srli_epi64)
806#[inline]
807#[target_feature(enable = "sse2")]
808#[cfg_attr(test, assert_instr(psrlq, IMM8 = 1))]
809#[rustc_legacy_const_generics(1)]
810#[stable(feature = "simd_x86", since = "1.27.0")]
811#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
812pub const fn _mm_srli_epi64<const IMM8: i32>(a: __m128i) -> __m128i {
813    static_assert_uimm_bits!(IMM8, 8);
814    unsafe {
815        if IMM8 >= 64 {
816            _mm_setzero_si128()
817        } else {
818            transmute(simd_shr(a.as_u64x2(), u64x2::splat(IMM8 as u64)))
819        }
820    }
821}
822
823/// Shifts packed 64-bit integers in `a` right by `count` while shifting in
824/// zeros.
825///
826/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srl_epi64)
827#[inline]
828#[target_feature(enable = "sse2")]
829#[cfg_attr(test, assert_instr(psrlq))]
830#[stable(feature = "simd_x86", since = "1.27.0")]
831pub fn _mm_srl_epi64(a: __m128i, count: __m128i) -> __m128i {
832    unsafe { transmute(psrlq(a.as_i64x2(), count.as_i64x2())) }
833}
834
835/// Computes the bitwise AND of 128 bits (representing integer data) in `a` and
836/// `b`.
837///
838/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_and_si128)
839#[inline]
840#[target_feature(enable = "sse2")]
841#[cfg_attr(test, assert_instr(andps))]
842#[stable(feature = "simd_x86", since = "1.27.0")]
843#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
844pub const fn _mm_and_si128(a: __m128i, b: __m128i) -> __m128i {
845    unsafe { simd_and(a, b) }
846}
847
848/// Computes the bitwise NOT of 128 bits (representing integer data) in `a` and
849/// then AND with `b`.
850///
851/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_andnot_si128)
852#[inline]
853#[target_feature(enable = "sse2")]
854#[cfg_attr(test, assert_instr(andnps))]
855#[stable(feature = "simd_x86", since = "1.27.0")]
856#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
857pub const fn _mm_andnot_si128(a: __m128i, b: __m128i) -> __m128i {
858    unsafe { simd_and(simd_xor(_mm_set1_epi8(-1), a), b) }
859}
860
861/// Computes the bitwise OR of 128 bits (representing integer data) in `a` and
862/// `b`.
863///
864/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_or_si128)
865#[ferrocene::prevalidated]
866#[inline]
867#[target_feature(enable = "sse2")]
868#[cfg_attr(test, assert_instr(orps))]
869#[stable(feature = "simd_x86", since = "1.27.0")]
870#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
871pub const fn _mm_or_si128(a: __m128i, b: __m128i) -> __m128i {
872    unsafe { simd_or(a, b) }
873}
874
875/// Computes the bitwise XOR of 128 bits (representing integer data) in `a` and
876/// `b`.
877///
878/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_xor_si128)
879#[inline]
880#[target_feature(enable = "sse2")]
881#[cfg_attr(test, assert_instr(xorps))]
882#[stable(feature = "simd_x86", since = "1.27.0")]
883#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
884pub const fn _mm_xor_si128(a: __m128i, b: __m128i) -> __m128i {
885    unsafe { simd_xor(a, b) }
886}
887
888/// Compares packed 8-bit integers in `a` and `b` for equality.
889///
890/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpeq_epi8)
891#[inline]
892#[target_feature(enable = "sse2")]
893#[cfg_attr(test, assert_instr(pcmpeqb))]
894#[stable(feature = "simd_x86", since = "1.27.0")]
895#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
896pub const fn _mm_cmpeq_epi8(a: __m128i, b: __m128i) -> __m128i {
897    unsafe { transmute::<i8x16, _>(simd_eq(a.as_i8x16(), b.as_i8x16())) }
898}
899
900/// Compares packed 16-bit integers in `a` and `b` for equality.
901///
902/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpeq_epi16)
903#[inline]
904#[target_feature(enable = "sse2")]
905#[cfg_attr(test, assert_instr(pcmpeqw))]
906#[stable(feature = "simd_x86", since = "1.27.0")]
907#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
908pub const fn _mm_cmpeq_epi16(a: __m128i, b: __m128i) -> __m128i {
909    unsafe { transmute::<i16x8, _>(simd_eq(a.as_i16x8(), b.as_i16x8())) }
910}
911
912/// Compares packed 32-bit integers in `a` and `b` for equality.
913///
914/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpeq_epi32)
915#[inline]
916#[target_feature(enable = "sse2")]
917#[cfg_attr(test, assert_instr(pcmpeqd))]
918#[stable(feature = "simd_x86", since = "1.27.0")]
919#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
920pub const fn _mm_cmpeq_epi32(a: __m128i, b: __m128i) -> __m128i {
921    unsafe { transmute::<i32x4, _>(simd_eq(a.as_i32x4(), b.as_i32x4())) }
922}
923
924/// Compares packed 8-bit integers in `a` and `b` for greater-than.
925///
926/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpgt_epi8)
927#[inline]
928#[target_feature(enable = "sse2")]
929#[cfg_attr(test, assert_instr(pcmpgtb))]
930#[stable(feature = "simd_x86", since = "1.27.0")]
931#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
932pub const fn _mm_cmpgt_epi8(a: __m128i, b: __m128i) -> __m128i {
933    unsafe { transmute::<i8x16, _>(simd_gt(a.as_i8x16(), b.as_i8x16())) }
934}
935
936/// Compares packed 16-bit integers in `a` and `b` for greater-than.
937///
938/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpgt_epi16)
939#[inline]
940#[target_feature(enable = "sse2")]
941#[cfg_attr(test, assert_instr(pcmpgtw))]
942#[stable(feature = "simd_x86", since = "1.27.0")]
943#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
944pub const fn _mm_cmpgt_epi16(a: __m128i, b: __m128i) -> __m128i {
945    unsafe { transmute::<i16x8, _>(simd_gt(a.as_i16x8(), b.as_i16x8())) }
946}
947
948/// Compares packed 32-bit integers in `a` and `b` for greater-than.
949///
950/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpgt_epi32)
951#[inline]
952#[target_feature(enable = "sse2")]
953#[cfg_attr(test, assert_instr(pcmpgtd))]
954#[stable(feature = "simd_x86", since = "1.27.0")]
955#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
956pub const fn _mm_cmpgt_epi32(a: __m128i, b: __m128i) -> __m128i {
957    unsafe { transmute::<i32x4, _>(simd_gt(a.as_i32x4(), b.as_i32x4())) }
958}
959
960/// Compares packed 8-bit integers in `a` and `b` for less-than.
961///
962/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmplt_epi8)
963#[inline]
964#[target_feature(enable = "sse2")]
965#[cfg_attr(test, assert_instr(pcmpgtb))]
966#[stable(feature = "simd_x86", since = "1.27.0")]
967#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
968pub const fn _mm_cmplt_epi8(a: __m128i, b: __m128i) -> __m128i {
969    unsafe { transmute::<i8x16, _>(simd_lt(a.as_i8x16(), b.as_i8x16())) }
970}
971
972/// Compares packed 16-bit integers in `a` and `b` for less-than.
973///
974/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmplt_epi16)
975#[inline]
976#[target_feature(enable = "sse2")]
977#[cfg_attr(test, assert_instr(pcmpgtw))]
978#[stable(feature = "simd_x86", since = "1.27.0")]
979#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
980pub const fn _mm_cmplt_epi16(a: __m128i, b: __m128i) -> __m128i {
981    unsafe { transmute::<i16x8, _>(simd_lt(a.as_i16x8(), b.as_i16x8())) }
982}
983
984/// Compares packed 32-bit integers in `a` and `b` for less-than.
985///
986/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmplt_epi32)
987#[inline]
988#[target_feature(enable = "sse2")]
989#[cfg_attr(test, assert_instr(pcmpgtd))]
990#[stable(feature = "simd_x86", since = "1.27.0")]
991#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
992pub const fn _mm_cmplt_epi32(a: __m128i, b: __m128i) -> __m128i {
993    unsafe { transmute::<i32x4, _>(simd_lt(a.as_i32x4(), b.as_i32x4())) }
994}
995
996/// Converts the lower two packed 32-bit integers in `a` to packed
997/// double-precision (64-bit) floating-point elements.
998///
999/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtepi32_pd)
1000#[inline]
1001#[target_feature(enable = "sse2")]
1002#[cfg_attr(test, assert_instr(cvtdq2pd))]
1003#[stable(feature = "simd_x86", since = "1.27.0")]
1004#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1005pub const fn _mm_cvtepi32_pd(a: __m128i) -> __m128d {
1006    unsafe {
1007        let a = a.as_i32x4();
1008        simd_cast::<i32x2, __m128d>(simd_shuffle!(a, a, [0, 1]))
1009    }
1010}
1011
1012/// Returns `a` with its lower element replaced by `b` after converting it to
1013/// an `f64`.
1014///
1015/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi32_sd)
1016#[inline]
1017#[target_feature(enable = "sse2")]
1018#[cfg_attr(test, assert_instr(cvtsi2sd))]
1019#[stable(feature = "simd_x86", since = "1.27.0")]
1020#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1021pub const fn _mm_cvtsi32_sd(a: __m128d, b: i32) -> __m128d {
1022    unsafe { simd_insert!(a, 0, b as f64) }
1023}
1024
1025/// Converts packed 32-bit integers in `a` to packed single-precision (32-bit)
1026/// floating-point elements.
1027///
1028/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtepi32_ps)
1029#[inline]
1030#[target_feature(enable = "sse2")]
1031#[cfg_attr(test, assert_instr(cvtdq2ps))]
1032#[stable(feature = "simd_x86", since = "1.27.0")]
1033#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1034pub const fn _mm_cvtepi32_ps(a: __m128i) -> __m128 {
1035    unsafe { transmute(simd_cast::<_, f32x4>(a.as_i32x4())) }
1036}
1037
1038/// Converts packed single-precision (32-bit) floating-point elements in `a`
1039/// to packed 32-bit integers.
1040///
1041/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtps_epi32)
1042#[inline]
1043#[target_feature(enable = "sse2")]
1044#[cfg_attr(test, assert_instr(cvtps2dq))]
1045#[stable(feature = "simd_x86", since = "1.27.0")]
1046pub fn _mm_cvtps_epi32(a: __m128) -> __m128i {
1047    unsafe { transmute(cvtps2dq(a)) }
1048}
1049
1050/// Returns a vector whose lowest element is `a` and all higher elements are
1051/// `0`.
1052///
1053/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi32_si128)
1054#[inline]
1055#[target_feature(enable = "sse2")]
1056#[stable(feature = "simd_x86", since = "1.27.0")]
1057#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1058pub const fn _mm_cvtsi32_si128(a: i32) -> __m128i {
1059    unsafe { transmute(i32x4::new(a, 0, 0, 0)) }
1060}
1061
1062/// Returns the lowest element of `a`.
1063///
1064/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi128_si32)
1065#[inline]
1066#[target_feature(enable = "sse2")]
1067#[stable(feature = "simd_x86", since = "1.27.0")]
1068#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1069pub const fn _mm_cvtsi128_si32(a: __m128i) -> i32 {
1070    unsafe { simd_extract!(a.as_i32x4(), 0) }
1071}
1072
1073/// Sets packed 64-bit integers with the supplied values, from highest to
1074/// lowest.
1075///
1076/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_epi64x)
1077#[inline]
1078#[target_feature(enable = "sse2")]
1079// no particular instruction to test
1080#[stable(feature = "simd_x86", since = "1.27.0")]
1081#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1082pub const fn _mm_set_epi64x(e1: i64, e0: i64) -> __m128i {
1083    unsafe { transmute(i64x2::new(e0, e1)) }
1084}
1085
1086/// Sets packed 32-bit integers with the supplied values.
1087///
1088/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_epi32)
1089#[inline]
1090#[target_feature(enable = "sse2")]
1091// no particular instruction to test
1092#[stable(feature = "simd_x86", since = "1.27.0")]
1093#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1094pub const fn _mm_set_epi32(e3: i32, e2: i32, e1: i32, e0: i32) -> __m128i {
1095    unsafe { transmute(i32x4::new(e0, e1, e2, e3)) }
1096}
1097
1098/// Sets packed 16-bit integers with the supplied values.
1099///
1100/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_epi16)
1101#[inline]
1102#[target_feature(enable = "sse2")]
1103// no particular instruction to test
1104#[stable(feature = "simd_x86", since = "1.27.0")]
1105#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1106pub const fn _mm_set_epi16(
1107    e7: i16,
1108    e6: i16,
1109    e5: i16,
1110    e4: i16,
1111    e3: i16,
1112    e2: i16,
1113    e1: i16,
1114    e0: i16,
1115) -> __m128i {
1116    unsafe { transmute(i16x8::new(e0, e1, e2, e3, e4, e5, e6, e7)) }
1117}
1118
1119/// Sets packed 8-bit integers with the supplied values.
1120///
1121/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_epi8)
1122#[inline]
1123#[target_feature(enable = "sse2")]
1124// no particular instruction to test
1125#[stable(feature = "simd_x86", since = "1.27.0")]
1126#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1127pub const fn _mm_set_epi8(
1128    e15: i8,
1129    e14: i8,
1130    e13: i8,
1131    e12: i8,
1132    e11: i8,
1133    e10: i8,
1134    e9: i8,
1135    e8: i8,
1136    e7: i8,
1137    e6: i8,
1138    e5: i8,
1139    e4: i8,
1140    e3: i8,
1141    e2: i8,
1142    e1: i8,
1143    e0: i8,
1144) -> __m128i {
1145    unsafe {
1146        #[rustfmt::skip]
1147        transmute(i8x16::new(
1148            e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15,
1149        ))
1150    }
1151}
1152
1153/// Broadcasts 64-bit integer `a` to all elements.
1154///
1155/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set1_epi64x)
1156#[inline]
1157#[target_feature(enable = "sse2")]
1158// no particular instruction to test
1159#[stable(feature = "simd_x86", since = "1.27.0")]
1160#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1161pub const fn _mm_set1_epi64x(a: i64) -> __m128i {
1162    i64x2::splat(a).as_m128i()
1163}
1164
1165/// Broadcasts 32-bit integer `a` to all elements.
1166///
1167/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set1_epi32)
1168#[inline]
1169#[target_feature(enable = "sse2")]
1170// no particular instruction to test
1171#[stable(feature = "simd_x86", since = "1.27.0")]
1172#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1173pub const fn _mm_set1_epi32(a: i32) -> __m128i {
1174    i32x4::splat(a).as_m128i()
1175}
1176
1177/// Broadcasts 16-bit integer `a` to all elements.
1178///
1179/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set1_epi16)
1180#[inline]
1181#[target_feature(enable = "sse2")]
1182// no particular instruction to test
1183#[stable(feature = "simd_x86", since = "1.27.0")]
1184#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1185pub const fn _mm_set1_epi16(a: i16) -> __m128i {
1186    i16x8::splat(a).as_m128i()
1187}
1188
1189/// Broadcasts 8-bit integer `a` to all elements.
1190///
1191/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set1_epi8)
1192#[inline]
1193#[target_feature(enable = "sse2")]
1194// no particular instruction to test
1195#[stable(feature = "simd_x86", since = "1.27.0")]
1196#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1197pub const fn _mm_set1_epi8(a: i8) -> __m128i {
1198    i8x16::splat(a).as_m128i()
1199}
1200
1201/// Sets packed 32-bit integers with the supplied values in reverse order.
1202///
1203/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setr_epi32)
1204#[inline]
1205#[target_feature(enable = "sse2")]
1206// no particular instruction to test
1207#[stable(feature = "simd_x86", since = "1.27.0")]
1208#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1209pub const fn _mm_setr_epi32(e3: i32, e2: i32, e1: i32, e0: i32) -> __m128i {
1210    _mm_set_epi32(e0, e1, e2, e3)
1211}
1212
1213/// Sets packed 16-bit integers with the supplied values in reverse order.
1214///
1215/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setr_epi16)
1216#[inline]
1217#[target_feature(enable = "sse2")]
1218// no particular instruction to test
1219#[stable(feature = "simd_x86", since = "1.27.0")]
1220#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1221pub const fn _mm_setr_epi16(
1222    e7: i16,
1223    e6: i16,
1224    e5: i16,
1225    e4: i16,
1226    e3: i16,
1227    e2: i16,
1228    e1: i16,
1229    e0: i16,
1230) -> __m128i {
1231    _mm_set_epi16(e0, e1, e2, e3, e4, e5, e6, e7)
1232}
1233
1234/// Sets packed 8-bit integers with the supplied values in reverse order.
1235///
1236/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setr_epi8)
1237#[inline]
1238#[target_feature(enable = "sse2")]
1239// no particular instruction to test
1240#[stable(feature = "simd_x86", since = "1.27.0")]
1241#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1242pub const fn _mm_setr_epi8(
1243    e15: i8,
1244    e14: i8,
1245    e13: i8,
1246    e12: i8,
1247    e11: i8,
1248    e10: i8,
1249    e9: i8,
1250    e8: i8,
1251    e7: i8,
1252    e6: i8,
1253    e5: i8,
1254    e4: i8,
1255    e3: i8,
1256    e2: i8,
1257    e1: i8,
1258    e0: i8,
1259) -> __m128i {
1260    #[rustfmt::skip]
1261    _mm_set_epi8(
1262        e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15,
1263    )
1264}
1265
1266/// Returns a vector with all elements set to zero.
1267///
1268/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setzero_si128)
1269#[inline]
1270#[target_feature(enable = "sse2")]
1271#[cfg_attr(test, assert_instr(xorps))]
1272#[stable(feature = "simd_x86", since = "1.27.0")]
1273#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1274pub const fn _mm_setzero_si128() -> __m128i {
1275    const { unsafe { mem::zeroed() } }
1276}
1277
1278/// Loads 64-bit integer from memory into first element of returned vector.
1279///
1280/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadl_epi64)
1281#[inline]
1282#[target_feature(enable = "sse2")]
1283#[stable(feature = "simd_x86", since = "1.27.0")]
1284#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1285pub const unsafe fn _mm_loadl_epi64(mem_addr: *const __m128i) -> __m128i {
1286    _mm_set_epi64x(0, ptr::read_unaligned(mem_addr as *const i64))
1287}
1288
1289/// Loads 128-bits of integer data from memory into a new vector.
1290///
1291/// `mem_addr` must be aligned on a 16-byte boundary.
1292///
1293/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load_si128)
1294#[inline]
1295#[target_feature(enable = "sse2")]
1296#[cfg_attr(
1297    all(test, not(all(target_arch = "x86", target_env = "msvc"))),
1298    assert_instr(movaps)
1299)]
1300#[stable(feature = "simd_x86", since = "1.27.0")]
1301#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1302pub const unsafe fn _mm_load_si128(mem_addr: *const __m128i) -> __m128i {
1303    *mem_addr
1304}
1305
1306/// Loads 128-bits of integer data from memory into a new vector.
1307///
1308/// `mem_addr` does not need to be aligned on any particular boundary.
1309///
1310/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadu_si128)
1311#[ferrocene::prevalidated]
1312#[inline]
1313#[target_feature(enable = "sse2")]
1314#[cfg_attr(test, assert_instr(movups))]
1315#[stable(feature = "simd_x86", since = "1.27.0")]
1316#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1317pub const unsafe fn _mm_loadu_si128(mem_addr: *const __m128i) -> __m128i {
1318    let mut dst: __m128i = _mm_undefined_si128();
1319    ptr::copy_nonoverlapping(
1320        mem_addr as *const u8,
1321        ptr::addr_of_mut!(dst) as *mut u8,
1322        mem::size_of::<__m128i>(),
1323    );
1324    dst
1325}
1326
1327/// Conditionally store 8-bit integer elements from `a` into memory using
1328/// `mask` flagged as non-temporal (unlikely to be used again soon).
1329///
1330/// Elements are not stored when the highest bit is not set in the
1331/// corresponding element.
1332///
1333/// `mem_addr` should correspond to a 128-bit memory location and does not need
1334/// to be aligned on any particular boundary. The memory range starting at `mem_addr`
1335/// and going on for 16 bytes must be contained in a mutable allocation, even if `mask` is all-0.
1336///
1337/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_maskmoveu_si128)
1338///
1339/// # Safety of non-temporal stores
1340///
1341/// After using this intrinsic, but before any other access to the memory that this intrinsic
1342/// mutates, a call to [`_mm_sfence`] must be performed by the thread that used the intrinsic. In
1343/// particular, functions that call this intrinsic should generally call `_mm_sfence` before they
1344/// return.
1345///
1346/// See [`_mm_sfence`] for details.
1347#[inline]
1348#[target_feature(enable = "sse2")]
1349#[cfg_attr(test, assert_instr(maskmovdqu))]
1350#[stable(feature = "simd_x86", since = "1.27.0")]
1351pub unsafe fn _mm_maskmoveu_si128(a: __m128i, mask: __m128i, mem_addr: *mut i8) {
1352    maskmovdqu(a.as_i8x16(), mask.as_i8x16(), mem_addr)
1353}
1354
1355/// Stores 128-bits of integer data from `a` into memory.
1356///
1357/// `mem_addr` must be aligned on a 16-byte boundary.
1358///
1359/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_store_si128)
1360#[inline]
1361#[target_feature(enable = "sse2")]
1362#[cfg_attr(
1363    all(test, not(all(target_arch = "x86", target_env = "msvc"))),
1364    assert_instr(movaps)
1365)]
1366#[stable(feature = "simd_x86", since = "1.27.0")]
1367#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1368pub const unsafe fn _mm_store_si128(mem_addr: *mut __m128i, a: __m128i) {
1369    *mem_addr = a;
1370}
1371
1372/// Stores 128-bits of integer data from `a` into memory.
1373///
1374/// `mem_addr` does not need to be aligned on any particular boundary.
1375///
1376/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeu_si128)
1377#[inline]
1378#[target_feature(enable = "sse2")]
1379#[cfg_attr(test, assert_instr(movups))] // FIXME movdqu expected
1380#[stable(feature = "simd_x86", since = "1.27.0")]
1381#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1382pub const unsafe fn _mm_storeu_si128(mem_addr: *mut __m128i, a: __m128i) {
1383    mem_addr.write_unaligned(a);
1384}
1385
1386/// Stores the lower 64-bit integer `a` to a memory location.
1387///
1388/// `mem_addr` does not need to be aligned on any particular boundary.
1389///
1390/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storel_epi64)
1391#[inline]
1392#[target_feature(enable = "sse2")]
1393#[stable(feature = "simd_x86", since = "1.27.0")]
1394#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1395pub const unsafe fn _mm_storel_epi64(mem_addr: *mut __m128i, a: __m128i) {
1396    ptr::copy_nonoverlapping(ptr::addr_of!(a) as *const u8, mem_addr as *mut u8, 8);
1397}
1398
1399/// Stores a 128-bit integer vector to a 128-bit aligned memory location.
1400/// To minimize caching, the data is flagged as non-temporal (unlikely to be
1401/// used again soon).
1402///
1403/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_stream_si128)
1404///
1405/// # Safety of non-temporal stores
1406///
1407/// After using this intrinsic, but before any other access to the memory that this intrinsic
1408/// mutates, a call to [`_mm_sfence`] must be performed by the thread that used the intrinsic. In
1409/// particular, functions that call this intrinsic should generally call `_mm_sfence` before they
1410/// return.
1411///
1412/// See [`_mm_sfence`] for details.
1413#[inline]
1414#[target_feature(enable = "sse2")]
1415#[cfg_attr(test, assert_instr(movntdq))]
1416#[stable(feature = "simd_x86", since = "1.27.0")]
1417pub unsafe fn _mm_stream_si128(mem_addr: *mut __m128i, a: __m128i) {
1418    // see #1541, we should use inline asm to be sure, because LangRef isn't clear enough
1419    crate::arch::asm!(
1420        vps!("movntdq",  ",{a}"),
1421        p = in(reg) mem_addr,
1422        a = in(xmm_reg) a,
1423        options(nostack, preserves_flags),
1424    );
1425}
1426
1427/// Stores a 32-bit integer value in a 4-byte aligned memory location.
1428/// To minimize caching, the data is flagged as non-temporal (unlikely to be
1429/// used again soon).
1430///
1431/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_stream_si32)
1432///
1433/// # Safety of non-temporal stores
1434///
1435/// After using this intrinsic, but before any other access to the memory that this intrinsic
1436/// mutates, a call to [`_mm_sfence`] must be performed by the thread that used the intrinsic. In
1437/// particular, functions that call this intrinsic should generally call `_mm_sfence` before they
1438/// return.
1439///
1440/// See [`_mm_sfence`] for details.
1441#[inline]
1442#[target_feature(enable = "sse2")]
1443#[cfg_attr(test, assert_instr(movnti))]
1444#[stable(feature = "simd_x86", since = "1.27.0")]
1445pub unsafe fn _mm_stream_si32(mem_addr: *mut i32, a: i32) {
1446    // see #1541, we should use inline asm to be sure, because LangRef isn't clear enough
1447    crate::arch::asm!(
1448        vps!("movnti", ",{a:e}"), // `:e` for 32bit value
1449        p = in(reg) mem_addr,
1450        a = in(reg) a,
1451        options(nostack, preserves_flags),
1452    );
1453}
1454
1455/// Returns a vector where the low element is extracted from `a` and its upper
1456/// element is zero.
1457///
1458/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_move_epi64)
1459#[inline]
1460#[target_feature(enable = "sse2")]
1461// FIXME movd on msvc, movd on i686
1462#[cfg_attr(all(test, target_arch = "x86_64"), assert_instr(movq))]
1463#[stable(feature = "simd_x86", since = "1.27.0")]
1464#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1465pub const fn _mm_move_epi64(a: __m128i) -> __m128i {
1466    unsafe {
1467        let r: i64x2 = simd_shuffle!(a.as_i64x2(), i64x2::ZERO, [0, 2]);
1468        transmute(r)
1469    }
1470}
1471
1472/// Converts packed 16-bit integers from `a` and `b` to packed 8-bit integers
1473/// using signed saturation.
1474///
1475/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_packs_epi16)
1476#[inline]
1477#[target_feature(enable = "sse2")]
1478#[cfg_attr(test, assert_instr(packsswb, limit(5), not(pmin), not(pmax)))]
1479#[stable(feature = "simd_x86", since = "1.27.0")]
1480pub fn _mm_packs_epi16(a: __m128i, b: __m128i) -> __m128i {
1481    unsafe { transmute(packsswb(a.as_i16x8(), b.as_i16x8())) }
1482}
1483
1484/// Converts packed 32-bit integers from `a` and `b` to packed 16-bit integers
1485/// using signed saturation.
1486///
1487/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_packs_epi32)
1488#[inline]
1489#[target_feature(enable = "sse2")]
1490#[cfg_attr(test, assert_instr(packssdw, limit(5), not(pmin), not(pmax)))]
1491#[stable(feature = "simd_x86", since = "1.27.0")]
1492pub fn _mm_packs_epi32(a: __m128i, b: __m128i) -> __m128i {
1493    unsafe { transmute(packssdw(a.as_i32x4(), b.as_i32x4())) }
1494}
1495
1496/// Converts packed 16-bit integers from `a` and `b` to packed 8-bit integers
1497/// using unsigned saturation.
1498///
1499/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_packus_epi16)
1500#[inline]
1501#[target_feature(enable = "sse2")]
1502#[cfg_attr(test, assert_instr(packuswb, limit(5), not(pmin), not(pmax)))]
1503#[stable(feature = "simd_x86", since = "1.27.0")]
1504pub fn _mm_packus_epi16(a: __m128i, b: __m128i) -> __m128i {
1505    unsafe { transmute(packuswb(a.as_i16x8(), b.as_i16x8())) }
1506}
1507
1508/// Returns the `imm8` element of `a`.
1509///
1510/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_extract_epi16)
1511#[inline]
1512#[target_feature(enable = "sse2")]
1513#[cfg_attr(test, assert_instr(pextrw, IMM8 = 7))]
1514#[rustc_legacy_const_generics(1)]
1515#[stable(feature = "simd_x86", since = "1.27.0")]
1516#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1517pub const fn _mm_extract_epi16<const IMM8: i32>(a: __m128i) -> i32 {
1518    static_assert_uimm_bits!(IMM8, 3);
1519    unsafe { simd_extract!(a.as_u16x8(), IMM8 as u32, u16) as i32 }
1520}
1521
1522/// Returns a new vector where the `imm8` element of `a` is replaced with `i`.
1523///
1524/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_insert_epi16)
1525#[inline]
1526#[target_feature(enable = "sse2")]
1527#[cfg_attr(test, assert_instr(pinsrw, IMM8 = 7))]
1528#[rustc_legacy_const_generics(2)]
1529#[stable(feature = "simd_x86", since = "1.27.0")]
1530#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1531pub const fn _mm_insert_epi16<const IMM8: i32>(a: __m128i, i: i32) -> __m128i {
1532    static_assert_uimm_bits!(IMM8, 3);
1533    unsafe { transmute(simd_insert!(a.as_i16x8(), IMM8 as u32, i as i16)) }
1534}
1535
1536/// Returns a mask of the most significant bit of each element in `a`.
1537///
1538/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_movemask_epi8)
1539#[ferrocene::prevalidated]
1540#[inline]
1541#[target_feature(enable = "sse2")]
1542#[cfg_attr(test, assert_instr(pmovmskb))]
1543#[stable(feature = "simd_x86", since = "1.27.0")]
1544#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1545pub const fn _mm_movemask_epi8(a: __m128i) -> i32 {
1546    unsafe {
1547        let z = i8x16::ZERO;
1548        let m: i8x16 = simd_lt(a.as_i8x16(), z);
1549        simd_bitmask::<_, u16>(m) as u32 as i32
1550    }
1551}
1552
1553/// Shuffles 32-bit integers in `a` using the control in `IMM8`.
1554///
1555/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_shuffle_epi32)
1556#[inline]
1557#[target_feature(enable = "sse2")]
1558#[cfg_attr(test, assert_instr(pshufd, IMM8 = 9))]
1559#[rustc_legacy_const_generics(1)]
1560#[stable(feature = "simd_x86", since = "1.27.0")]
1561#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1562pub const fn _mm_shuffle_epi32<const IMM8: i32>(a: __m128i) -> __m128i {
1563    static_assert_uimm_bits!(IMM8, 8);
1564    unsafe {
1565        let a = a.as_i32x4();
1566        let x: i32x4 = simd_shuffle!(
1567            a,
1568            a,
1569            [
1570                IMM8 as u32 & 0b11,
1571                (IMM8 as u32 >> 2) & 0b11,
1572                (IMM8 as u32 >> 4) & 0b11,
1573                (IMM8 as u32 >> 6) & 0b11,
1574            ],
1575        );
1576        transmute(x)
1577    }
1578}
1579
1580/// Shuffles 16-bit integers in the high 64 bits of `a` using the control in
1581/// `IMM8`.
1582///
1583/// Put the results in the high 64 bits of the returned vector, with the low 64
1584/// bits being copied from `a`.
1585///
1586/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_shufflehi_epi16)
1587#[inline]
1588#[target_feature(enable = "sse2")]
1589#[cfg_attr(test, assert_instr(pshufhw, IMM8 = 9))]
1590#[rustc_legacy_const_generics(1)]
1591#[stable(feature = "simd_x86", since = "1.27.0")]
1592#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1593pub const fn _mm_shufflehi_epi16<const IMM8: i32>(a: __m128i) -> __m128i {
1594    static_assert_uimm_bits!(IMM8, 8);
1595    unsafe {
1596        let a = a.as_i16x8();
1597        let x: i16x8 = simd_shuffle!(
1598            a,
1599            a,
1600            [
1601                0,
1602                1,
1603                2,
1604                3,
1605                (IMM8 as u32 & 0b11) + 4,
1606                ((IMM8 as u32 >> 2) & 0b11) + 4,
1607                ((IMM8 as u32 >> 4) & 0b11) + 4,
1608                ((IMM8 as u32 >> 6) & 0b11) + 4,
1609            ],
1610        );
1611        transmute(x)
1612    }
1613}
1614
1615/// Shuffles 16-bit integers in the low 64 bits of `a` using the control in
1616/// `IMM8`.
1617///
1618/// Put the results in the low 64 bits of the returned vector, with the high 64
1619/// bits being copied from `a`.
1620///
1621/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_shufflelo_epi16)
1622#[inline]
1623#[target_feature(enable = "sse2")]
1624#[cfg_attr(test, assert_instr(pshuflw, IMM8 = 9))]
1625#[rustc_legacy_const_generics(1)]
1626#[stable(feature = "simd_x86", since = "1.27.0")]
1627#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1628pub const fn _mm_shufflelo_epi16<const IMM8: i32>(a: __m128i) -> __m128i {
1629    static_assert_uimm_bits!(IMM8, 8);
1630    unsafe {
1631        let a = a.as_i16x8();
1632        let x: i16x8 = simd_shuffle!(
1633            a,
1634            a,
1635            [
1636                IMM8 as u32 & 0b11,
1637                (IMM8 as u32 >> 2) & 0b11,
1638                (IMM8 as u32 >> 4) & 0b11,
1639                (IMM8 as u32 >> 6) & 0b11,
1640                4,
1641                5,
1642                6,
1643                7,
1644            ],
1645        );
1646        transmute(x)
1647    }
1648}
1649
1650/// Unpacks and interleave 8-bit integers from the high half of `a` and `b`.
1651///
1652/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpackhi_epi8)
1653#[inline]
1654#[target_feature(enable = "sse2")]
1655#[cfg_attr(test, assert_instr(punpckhbw))]
1656#[stable(feature = "simd_x86", since = "1.27.0")]
1657#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1658pub const fn _mm_unpackhi_epi8(a: __m128i, b: __m128i) -> __m128i {
1659    unsafe {
1660        transmute::<i8x16, _>(simd_shuffle!(
1661            a.as_i8x16(),
1662            b.as_i8x16(),
1663            [8, 24, 9, 25, 10, 26, 11, 27, 12, 28, 13, 29, 14, 30, 15, 31],
1664        ))
1665    }
1666}
1667
1668/// Unpacks and interleave 16-bit integers from the high half of `a` and `b`.
1669///
1670/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpackhi_epi16)
1671#[inline]
1672#[target_feature(enable = "sse2")]
1673#[cfg_attr(test, assert_instr(punpckhwd))]
1674#[stable(feature = "simd_x86", since = "1.27.0")]
1675#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1676pub const fn _mm_unpackhi_epi16(a: __m128i, b: __m128i) -> __m128i {
1677    unsafe {
1678        let x = simd_shuffle!(a.as_i16x8(), b.as_i16x8(), [4, 12, 5, 13, 6, 14, 7, 15]);
1679        transmute::<i16x8, _>(x)
1680    }
1681}
1682
1683/// Unpacks and interleave 32-bit integers from the high half of `a` and `b`.
1684///
1685/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpackhi_epi32)
1686#[inline]
1687#[target_feature(enable = "sse2")]
1688#[cfg_attr(test, assert_instr(unpckhps))]
1689#[stable(feature = "simd_x86", since = "1.27.0")]
1690#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1691pub const fn _mm_unpackhi_epi32(a: __m128i, b: __m128i) -> __m128i {
1692    unsafe { transmute::<i32x4, _>(simd_shuffle!(a.as_i32x4(), b.as_i32x4(), [2, 6, 3, 7])) }
1693}
1694
1695/// Unpacks and interleave 64-bit integers from the high half of `a` and `b`.
1696///
1697/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpackhi_epi64)
1698#[inline]
1699#[target_feature(enable = "sse2")]
1700#[cfg_attr(test, assert_instr(unpckhpd))]
1701#[stable(feature = "simd_x86", since = "1.27.0")]
1702#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1703pub const fn _mm_unpackhi_epi64(a: __m128i, b: __m128i) -> __m128i {
1704    unsafe { transmute::<i64x2, _>(simd_shuffle!(a.as_i64x2(), b.as_i64x2(), [1, 3])) }
1705}
1706
1707/// Unpacks and interleave 8-bit integers from the low half of `a` and `b`.
1708///
1709/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpacklo_epi8)
1710#[inline]
1711#[target_feature(enable = "sse2")]
1712#[cfg_attr(test, assert_instr(punpcklbw))]
1713#[stable(feature = "simd_x86", since = "1.27.0")]
1714#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1715pub const fn _mm_unpacklo_epi8(a: __m128i, b: __m128i) -> __m128i {
1716    unsafe {
1717        transmute::<i8x16, _>(simd_shuffle!(
1718            a.as_i8x16(),
1719            b.as_i8x16(),
1720            [0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23],
1721        ))
1722    }
1723}
1724
1725/// Unpacks and interleave 16-bit integers from the low half of `a` and `b`.
1726///
1727/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpacklo_epi16)
1728#[inline]
1729#[target_feature(enable = "sse2")]
1730#[cfg_attr(test, assert_instr(punpcklwd))]
1731#[stable(feature = "simd_x86", since = "1.27.0")]
1732#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1733pub const fn _mm_unpacklo_epi16(a: __m128i, b: __m128i) -> __m128i {
1734    unsafe {
1735        let x = simd_shuffle!(a.as_i16x8(), b.as_i16x8(), [0, 8, 1, 9, 2, 10, 3, 11]);
1736        transmute::<i16x8, _>(x)
1737    }
1738}
1739
1740/// Unpacks and interleave 32-bit integers from the low half of `a` and `b`.
1741///
1742/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpacklo_epi32)
1743#[inline]
1744#[target_feature(enable = "sse2")]
1745#[cfg_attr(test, assert_instr(unpcklps))]
1746#[stable(feature = "simd_x86", since = "1.27.0")]
1747#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1748pub const fn _mm_unpacklo_epi32(a: __m128i, b: __m128i) -> __m128i {
1749    unsafe { transmute::<i32x4, _>(simd_shuffle!(a.as_i32x4(), b.as_i32x4(), [0, 4, 1, 5])) }
1750}
1751
1752/// Unpacks and interleave 64-bit integers from the low half of `a` and `b`.
1753///
1754/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpacklo_epi64)
1755#[inline]
1756#[target_feature(enable = "sse2")]
1757#[cfg_attr(test, assert_instr(movlhps))]
1758#[stable(feature = "simd_x86", since = "1.27.0")]
1759#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1760pub const fn _mm_unpacklo_epi64(a: __m128i, b: __m128i) -> __m128i {
1761    unsafe { transmute::<i64x2, _>(simd_shuffle!(a.as_i64x2(), b.as_i64x2(), [0, 2])) }
1762}
1763
1764/// Returns a new vector with the low element of `a` replaced by the sum of the
1765/// low elements of `a` and `b`.
1766///
1767/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_add_sd)
1768#[inline]
1769#[target_feature(enable = "sse2")]
1770#[cfg_attr(test, assert_instr(addsd))]
1771#[stable(feature = "simd_x86", since = "1.27.0")]
1772#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1773pub const fn _mm_add_sd(a: __m128d, b: __m128d) -> __m128d {
1774    unsafe { simd_insert!(a, 0, _mm_cvtsd_f64(a) + _mm_cvtsd_f64(b)) }
1775}
1776
1777/// Adds packed double-precision (64-bit) floating-point elements in `a` and
1778/// `b`.
1779///
1780/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_add_pd)
1781#[inline]
1782#[target_feature(enable = "sse2")]
1783#[cfg_attr(test, assert_instr(addpd))]
1784#[stable(feature = "simd_x86", since = "1.27.0")]
1785#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1786pub const fn _mm_add_pd(a: __m128d, b: __m128d) -> __m128d {
1787    unsafe { simd_add(a, b) }
1788}
1789
1790/// Returns a new vector with the low element of `a` replaced by the result of
1791/// diving the lower element of `a` by the lower element of `b`.
1792///
1793/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_div_sd)
1794#[inline]
1795#[target_feature(enable = "sse2")]
1796#[cfg_attr(test, assert_instr(divsd))]
1797#[stable(feature = "simd_x86", since = "1.27.0")]
1798#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1799pub const fn _mm_div_sd(a: __m128d, b: __m128d) -> __m128d {
1800    unsafe { simd_insert!(a, 0, _mm_cvtsd_f64(a) / _mm_cvtsd_f64(b)) }
1801}
1802
1803/// Divide packed double-precision (64-bit) floating-point elements in `a` by
1804/// packed elements in `b`.
1805///
1806/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_div_pd)
1807#[inline]
1808#[target_feature(enable = "sse2")]
1809#[cfg_attr(test, assert_instr(divpd))]
1810#[stable(feature = "simd_x86", since = "1.27.0")]
1811#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1812pub const fn _mm_div_pd(a: __m128d, b: __m128d) -> __m128d {
1813    unsafe { simd_div(a, b) }
1814}
1815
1816/// Returns a new vector with the low element of `a` replaced by the maximum
1817/// of the lower elements of `a` and `b`.
1818///
1819/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_sd)
1820#[inline]
1821#[target_feature(enable = "sse2")]
1822#[cfg_attr(test, assert_instr(maxsd))]
1823#[stable(feature = "simd_x86", since = "1.27.0")]
1824pub fn _mm_max_sd(a: __m128d, b: __m128d) -> __m128d {
1825    unsafe { maxsd(a, b) }
1826}
1827
1828/// Returns a new vector with the maximum values from corresponding elements in
1829/// `a` and `b`.
1830///
1831/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_pd)
1832#[inline]
1833#[target_feature(enable = "sse2")]
1834#[cfg_attr(test, assert_instr(maxpd))]
1835#[stable(feature = "simd_x86", since = "1.27.0")]
1836pub fn _mm_max_pd(a: __m128d, b: __m128d) -> __m128d {
1837    unsafe { maxpd(a, b) }
1838}
1839
1840/// Returns a new vector with the low element of `a` replaced by the minimum
1841/// of the lower elements of `a` and `b`.
1842///
1843/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_sd)
1844#[inline]
1845#[target_feature(enable = "sse2")]
1846#[cfg_attr(test, assert_instr(minsd))]
1847#[stable(feature = "simd_x86", since = "1.27.0")]
1848pub fn _mm_min_sd(a: __m128d, b: __m128d) -> __m128d {
1849    unsafe { minsd(a, b) }
1850}
1851
1852/// Returns a new vector with the minimum values from corresponding elements in
1853/// `a` and `b`.
1854///
1855/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_pd)
1856#[inline]
1857#[target_feature(enable = "sse2")]
1858#[cfg_attr(test, assert_instr(minpd))]
1859#[stable(feature = "simd_x86", since = "1.27.0")]
1860pub fn _mm_min_pd(a: __m128d, b: __m128d) -> __m128d {
1861    unsafe { minpd(a, b) }
1862}
1863
1864/// Returns a new vector with the low element of `a` replaced by multiplying the
1865/// low elements of `a` and `b`.
1866///
1867/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mul_sd)
1868#[inline]
1869#[target_feature(enable = "sse2")]
1870#[cfg_attr(test, assert_instr(mulsd))]
1871#[stable(feature = "simd_x86", since = "1.27.0")]
1872#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1873pub const fn _mm_mul_sd(a: __m128d, b: __m128d) -> __m128d {
1874    unsafe { simd_insert!(a, 0, _mm_cvtsd_f64(a) * _mm_cvtsd_f64(b)) }
1875}
1876
1877/// Multiplies packed double-precision (64-bit) floating-point elements in `a`
1878/// and `b`.
1879///
1880/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mul_pd)
1881#[inline]
1882#[target_feature(enable = "sse2")]
1883#[cfg_attr(test, assert_instr(mulpd))]
1884#[stable(feature = "simd_x86", since = "1.27.0")]
1885#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1886pub const fn _mm_mul_pd(a: __m128d, b: __m128d) -> __m128d {
1887    unsafe { simd_mul(a, b) }
1888}
1889
1890/// Returns a new vector with the low element of `a` replaced by the square
1891/// root of the lower element `b`.
1892///
1893/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sqrt_sd)
1894#[inline]
1895#[target_feature(enable = "sse2")]
1896#[cfg_attr(test, assert_instr(sqrtsd))]
1897#[stable(feature = "simd_x86", since = "1.27.0")]
1898pub fn _mm_sqrt_sd(a: __m128d, b: __m128d) -> __m128d {
1899    unsafe { simd_insert!(a, 0, sqrt(_mm_cvtsd_f64(b))) }
1900}
1901
1902/// Returns a new vector with the square root of each of the values in `a`.
1903///
1904/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sqrt_pd)
1905#[inline]
1906#[target_feature(enable = "sse2")]
1907#[cfg_attr(test, assert_instr(sqrtpd))]
1908#[stable(feature = "simd_x86", since = "1.27.0")]
1909pub fn _mm_sqrt_pd(a: __m128d) -> __m128d {
1910    unsafe { simd_fsqrt(a) }
1911}
1912
1913/// Returns a new vector with the low element of `a` replaced by subtracting the
1914/// low element by `b` from the low element of `a`.
1915///
1916/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_sd)
1917#[inline]
1918#[target_feature(enable = "sse2")]
1919#[cfg_attr(test, assert_instr(subsd))]
1920#[stable(feature = "simd_x86", since = "1.27.0")]
1921#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1922pub const fn _mm_sub_sd(a: __m128d, b: __m128d) -> __m128d {
1923    unsafe { simd_insert!(a, 0, _mm_cvtsd_f64(a) - _mm_cvtsd_f64(b)) }
1924}
1925
1926/// Subtract packed double-precision (64-bit) floating-point elements in `b`
1927/// from `a`.
1928///
1929/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_pd)
1930#[inline]
1931#[target_feature(enable = "sse2")]
1932#[cfg_attr(test, assert_instr(subpd))]
1933#[stable(feature = "simd_x86", since = "1.27.0")]
1934#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1935pub const fn _mm_sub_pd(a: __m128d, b: __m128d) -> __m128d {
1936    unsafe { simd_sub(a, b) }
1937}
1938
1939/// Computes the bitwise AND of packed double-precision (64-bit) floating-point
1940/// elements in `a` and `b`.
1941///
1942/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_and_pd)
1943#[inline]
1944#[target_feature(enable = "sse2")]
1945#[cfg_attr(test, assert_instr(andps))]
1946#[stable(feature = "simd_x86", since = "1.27.0")]
1947#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1948pub const fn _mm_and_pd(a: __m128d, b: __m128d) -> __m128d {
1949    unsafe {
1950        let a: __m128i = transmute(a);
1951        let b: __m128i = transmute(b);
1952        transmute(_mm_and_si128(a, b))
1953    }
1954}
1955
1956/// Computes the bitwise NOT of `a` and then AND with `b`.
1957///
1958/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_andnot_pd)
1959#[inline]
1960#[target_feature(enable = "sse2")]
1961#[cfg_attr(test, assert_instr(andnps))]
1962#[stable(feature = "simd_x86", since = "1.27.0")]
1963#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1964pub const fn _mm_andnot_pd(a: __m128d, b: __m128d) -> __m128d {
1965    unsafe {
1966        let a: __m128i = transmute(a);
1967        let b: __m128i = transmute(b);
1968        transmute(_mm_andnot_si128(a, b))
1969    }
1970}
1971
1972/// Computes the bitwise OR of `a` and `b`.
1973///
1974/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_or_pd)
1975#[inline]
1976#[target_feature(enable = "sse2")]
1977#[cfg_attr(test, assert_instr(orps))]
1978#[stable(feature = "simd_x86", since = "1.27.0")]
1979#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1980pub const fn _mm_or_pd(a: __m128d, b: __m128d) -> __m128d {
1981    unsafe {
1982        let a: __m128i = transmute(a);
1983        let b: __m128i = transmute(b);
1984        transmute(_mm_or_si128(a, b))
1985    }
1986}
1987
1988/// Computes the bitwise XOR of `a` and `b`.
1989///
1990/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_xor_pd)
1991#[inline]
1992#[target_feature(enable = "sse2")]
1993#[cfg_attr(test, assert_instr(xorps))]
1994#[stable(feature = "simd_x86", since = "1.27.0")]
1995#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
1996pub const fn _mm_xor_pd(a: __m128d, b: __m128d) -> __m128d {
1997    unsafe {
1998        let a: __m128i = transmute(a);
1999        let b: __m128i = transmute(b);
2000        transmute(_mm_xor_si128(a, b))
2001    }
2002}
2003
2004/// Returns a new vector with the low element of `a` replaced by the equality
2005/// comparison of the lower elements of `a` and `b`.
2006///
2007/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpeq_sd)
2008#[inline]
2009#[target_feature(enable = "sse2")]
2010#[cfg_attr(test, assert_instr(cmpeqsd))]
2011#[stable(feature = "simd_x86", since = "1.27.0")]
2012pub fn _mm_cmpeq_sd(a: __m128d, b: __m128d) -> __m128d {
2013    unsafe { cmpsd(a, b, 0) }
2014}
2015
2016/// Returns a new vector with the low element of `a` replaced by the less-than
2017/// comparison of the lower elements of `a` and `b`.
2018///
2019/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmplt_sd)
2020#[inline]
2021#[target_feature(enable = "sse2")]
2022#[cfg_attr(test, assert_instr(cmpltsd))]
2023#[stable(feature = "simd_x86", since = "1.27.0")]
2024pub fn _mm_cmplt_sd(a: __m128d, b: __m128d) -> __m128d {
2025    unsafe { cmpsd(a, b, 1) }
2026}
2027
2028/// Returns a new vector with the low element of `a` replaced by the
2029/// less-than-or-equal comparison of the lower elements of `a` and `b`.
2030///
2031/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmple_sd)
2032#[inline]
2033#[target_feature(enable = "sse2")]
2034#[cfg_attr(test, assert_instr(cmplesd))]
2035#[stable(feature = "simd_x86", since = "1.27.0")]
2036pub fn _mm_cmple_sd(a: __m128d, b: __m128d) -> __m128d {
2037    unsafe { cmpsd(a, b, 2) }
2038}
2039
2040/// Returns a new vector with the low element of `a` replaced by the
2041/// greater-than comparison of the lower elements of `a` and `b`.
2042///
2043/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpgt_sd)
2044#[inline]
2045#[target_feature(enable = "sse2")]
2046#[cfg_attr(test, assert_instr(cmpltsd))]
2047#[stable(feature = "simd_x86", since = "1.27.0")]
2048pub fn _mm_cmpgt_sd(a: __m128d, b: __m128d) -> __m128d {
2049    unsafe { simd_insert!(_mm_cmplt_sd(b, a), 1, simd_extract!(a, 1, f64)) }
2050}
2051
2052/// Returns a new vector with the low element of `a` replaced by the
2053/// greater-than-or-equal comparison of the lower elements of `a` and `b`.
2054///
2055/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpge_sd)
2056#[inline]
2057#[target_feature(enable = "sse2")]
2058#[cfg_attr(test, assert_instr(cmplesd))]
2059#[stable(feature = "simd_x86", since = "1.27.0")]
2060pub fn _mm_cmpge_sd(a: __m128d, b: __m128d) -> __m128d {
2061    unsafe { simd_insert!(_mm_cmple_sd(b, a), 1, simd_extract!(a, 1, f64)) }
2062}
2063
2064/// Returns a new vector with the low element of `a` replaced by the result
2065/// of comparing both of the lower elements of `a` and `b` to `NaN`. If
2066/// neither are equal to `NaN` then `0xFFFFFFFFFFFFFFFF` is used and `0`
2067/// otherwise.
2068///
2069/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpord_sd)
2070#[inline]
2071#[target_feature(enable = "sse2")]
2072#[cfg_attr(test, assert_instr(cmpordsd))]
2073#[stable(feature = "simd_x86", since = "1.27.0")]
2074pub fn _mm_cmpord_sd(a: __m128d, b: __m128d) -> __m128d {
2075    unsafe { cmpsd(a, b, 7) }
2076}
2077
2078/// Returns a new vector with the low element of `a` replaced by the result of
2079/// comparing both of the lower elements of `a` and `b` to `NaN`. If either is
2080/// equal to `NaN` then `0xFFFFFFFFFFFFFFFF` is used and `0` otherwise.
2081///
2082/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpunord_sd)
2083#[inline]
2084#[target_feature(enable = "sse2")]
2085#[cfg_attr(test, assert_instr(cmpunordsd))]
2086#[stable(feature = "simd_x86", since = "1.27.0")]
2087pub fn _mm_cmpunord_sd(a: __m128d, b: __m128d) -> __m128d {
2088    unsafe { cmpsd(a, b, 3) }
2089}
2090
2091/// Returns a new vector with the low element of `a` replaced by the not-equal
2092/// comparison of the lower elements of `a` and `b`.
2093///
2094/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpneq_sd)
2095#[inline]
2096#[target_feature(enable = "sse2")]
2097#[cfg_attr(test, assert_instr(cmpneqsd))]
2098#[stable(feature = "simd_x86", since = "1.27.0")]
2099pub fn _mm_cmpneq_sd(a: __m128d, b: __m128d) -> __m128d {
2100    unsafe { cmpsd(a, b, 4) }
2101}
2102
2103/// Returns a new vector with the low element of `a` replaced by the
2104/// not-less-than comparison of the lower elements of `a` and `b`.
2105///
2106/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnlt_sd)
2107#[inline]
2108#[target_feature(enable = "sse2")]
2109#[cfg_attr(test, assert_instr(cmpnltsd))]
2110#[stable(feature = "simd_x86", since = "1.27.0")]
2111pub fn _mm_cmpnlt_sd(a: __m128d, b: __m128d) -> __m128d {
2112    unsafe { cmpsd(a, b, 5) }
2113}
2114
2115/// Returns a new vector with the low element of `a` replaced by the
2116/// not-less-than-or-equal comparison of the lower elements of `a` and `b`.
2117///
2118/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnle_sd)
2119#[inline]
2120#[target_feature(enable = "sse2")]
2121#[cfg_attr(test, assert_instr(cmpnlesd))]
2122#[stable(feature = "simd_x86", since = "1.27.0")]
2123pub fn _mm_cmpnle_sd(a: __m128d, b: __m128d) -> __m128d {
2124    unsafe { cmpsd(a, b, 6) }
2125}
2126
2127/// Returns a new vector with the low element of `a` replaced by the
2128/// not-greater-than comparison of the lower elements of `a` and `b`.
2129///
2130/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpngt_sd)
2131#[inline]
2132#[target_feature(enable = "sse2")]
2133#[cfg_attr(test, assert_instr(cmpnltsd))]
2134#[stable(feature = "simd_x86", since = "1.27.0")]
2135pub fn _mm_cmpngt_sd(a: __m128d, b: __m128d) -> __m128d {
2136    unsafe { simd_insert!(_mm_cmpnlt_sd(b, a), 1, simd_extract!(a, 1, f64)) }
2137}
2138
2139/// Returns a new vector with the low element of `a` replaced by the
2140/// not-greater-than-or-equal comparison of the lower elements of `a` and `b`.
2141///
2142/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnge_sd)
2143#[inline]
2144#[target_feature(enable = "sse2")]
2145#[cfg_attr(test, assert_instr(cmpnlesd))]
2146#[stable(feature = "simd_x86", since = "1.27.0")]
2147pub fn _mm_cmpnge_sd(a: __m128d, b: __m128d) -> __m128d {
2148    unsafe { simd_insert!(_mm_cmpnle_sd(b, a), 1, simd_extract!(a, 1, f64)) }
2149}
2150
2151/// Compares corresponding elements in `a` and `b` for equality.
2152///
2153/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpeq_pd)
2154#[inline]
2155#[target_feature(enable = "sse2")]
2156#[cfg_attr(test, assert_instr(cmpeqpd))]
2157#[stable(feature = "simd_x86", since = "1.27.0")]
2158pub fn _mm_cmpeq_pd(a: __m128d, b: __m128d) -> __m128d {
2159    unsafe { cmppd(a, b, 0) }
2160}
2161
2162/// Compares corresponding elements in `a` and `b` for less-than.
2163///
2164/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmplt_pd)
2165#[inline]
2166#[target_feature(enable = "sse2")]
2167#[cfg_attr(test, assert_instr(cmpltpd))]
2168#[stable(feature = "simd_x86", since = "1.27.0")]
2169pub fn _mm_cmplt_pd(a: __m128d, b: __m128d) -> __m128d {
2170    unsafe { cmppd(a, b, 1) }
2171}
2172
2173/// Compares corresponding elements in `a` and `b` for less-than-or-equal
2174///
2175/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmple_pd)
2176#[inline]
2177#[target_feature(enable = "sse2")]
2178#[cfg_attr(test, assert_instr(cmplepd))]
2179#[stable(feature = "simd_x86", since = "1.27.0")]
2180pub fn _mm_cmple_pd(a: __m128d, b: __m128d) -> __m128d {
2181    unsafe { cmppd(a, b, 2) }
2182}
2183
2184/// Compares corresponding elements in `a` and `b` for greater-than.
2185///
2186/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpgt_pd)
2187#[inline]
2188#[target_feature(enable = "sse2")]
2189#[cfg_attr(test, assert_instr(cmpltpd))]
2190#[stable(feature = "simd_x86", since = "1.27.0")]
2191pub fn _mm_cmpgt_pd(a: __m128d, b: __m128d) -> __m128d {
2192    _mm_cmplt_pd(b, a)
2193}
2194
2195/// Compares corresponding elements in `a` and `b` for greater-than-or-equal.
2196///
2197/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpge_pd)
2198#[inline]
2199#[target_feature(enable = "sse2")]
2200#[cfg_attr(test, assert_instr(cmplepd))]
2201#[stable(feature = "simd_x86", since = "1.27.0")]
2202pub fn _mm_cmpge_pd(a: __m128d, b: __m128d) -> __m128d {
2203    _mm_cmple_pd(b, a)
2204}
2205
2206/// Compares corresponding elements in `a` and `b` to see if neither is `NaN`.
2207///
2208/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpord_pd)
2209#[inline]
2210#[target_feature(enable = "sse2")]
2211#[cfg_attr(test, assert_instr(cmpordpd))]
2212#[stable(feature = "simd_x86", since = "1.27.0")]
2213pub fn _mm_cmpord_pd(a: __m128d, b: __m128d) -> __m128d {
2214    unsafe { cmppd(a, b, 7) }
2215}
2216
2217/// Compares corresponding elements in `a` and `b` to see if either is `NaN`.
2218///
2219/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpunord_pd)
2220#[inline]
2221#[target_feature(enable = "sse2")]
2222#[cfg_attr(test, assert_instr(cmpunordpd))]
2223#[stable(feature = "simd_x86", since = "1.27.0")]
2224pub fn _mm_cmpunord_pd(a: __m128d, b: __m128d) -> __m128d {
2225    unsafe { cmppd(a, b, 3) }
2226}
2227
2228/// Compares corresponding elements in `a` and `b` for not-equal.
2229///
2230/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpneq_pd)
2231#[inline]
2232#[target_feature(enable = "sse2")]
2233#[cfg_attr(test, assert_instr(cmpneqpd))]
2234#[stable(feature = "simd_x86", since = "1.27.0")]
2235pub fn _mm_cmpneq_pd(a: __m128d, b: __m128d) -> __m128d {
2236    unsafe { cmppd(a, b, 4) }
2237}
2238
2239/// Compares corresponding elements in `a` and `b` for not-less-than.
2240///
2241/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnlt_pd)
2242#[inline]
2243#[target_feature(enable = "sse2")]
2244#[cfg_attr(test, assert_instr(cmpnltpd))]
2245#[stable(feature = "simd_x86", since = "1.27.0")]
2246pub fn _mm_cmpnlt_pd(a: __m128d, b: __m128d) -> __m128d {
2247    unsafe { cmppd(a, b, 5) }
2248}
2249
2250/// Compares corresponding elements in `a` and `b` for not-less-than-or-equal.
2251///
2252/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnle_pd)
2253#[inline]
2254#[target_feature(enable = "sse2")]
2255#[cfg_attr(test, assert_instr(cmpnlepd))]
2256#[stable(feature = "simd_x86", since = "1.27.0")]
2257pub fn _mm_cmpnle_pd(a: __m128d, b: __m128d) -> __m128d {
2258    unsafe { cmppd(a, b, 6) }
2259}
2260
2261/// Compares corresponding elements in `a` and `b` for not-greater-than.
2262///
2263/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpngt_pd)
2264#[inline]
2265#[target_feature(enable = "sse2")]
2266#[cfg_attr(test, assert_instr(cmpnltpd))]
2267#[stable(feature = "simd_x86", since = "1.27.0")]
2268pub fn _mm_cmpngt_pd(a: __m128d, b: __m128d) -> __m128d {
2269    _mm_cmpnlt_pd(b, a)
2270}
2271
2272/// Compares corresponding elements in `a` and `b` for
2273/// not-greater-than-or-equal.
2274///
2275/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnge_pd)
2276#[inline]
2277#[target_feature(enable = "sse2")]
2278#[cfg_attr(test, assert_instr(cmpnlepd))]
2279#[stable(feature = "simd_x86", since = "1.27.0")]
2280pub fn _mm_cmpnge_pd(a: __m128d, b: __m128d) -> __m128d {
2281    _mm_cmpnle_pd(b, a)
2282}
2283
2284/// Compares the lower element of `a` and `b` for equality.
2285///
2286/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comieq_sd)
2287#[inline]
2288#[target_feature(enable = "sse2")]
2289#[cfg_attr(test, assert_instr(comisd))]
2290#[stable(feature = "simd_x86", since = "1.27.0")]
2291pub fn _mm_comieq_sd(a: __m128d, b: __m128d) -> i32 {
2292    unsafe { comieqsd(a, b) }
2293}
2294
2295/// Compares the lower element of `a` and `b` for less-than.
2296///
2297/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comilt_sd)
2298#[inline]
2299#[target_feature(enable = "sse2")]
2300#[cfg_attr(test, assert_instr(comisd))]
2301#[stable(feature = "simd_x86", since = "1.27.0")]
2302pub fn _mm_comilt_sd(a: __m128d, b: __m128d) -> i32 {
2303    unsafe { comiltsd(a, b) }
2304}
2305
2306/// Compares the lower element of `a` and `b` for less-than-or-equal.
2307///
2308/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comile_sd)
2309#[inline]
2310#[target_feature(enable = "sse2")]
2311#[cfg_attr(test, assert_instr(comisd))]
2312#[stable(feature = "simd_x86", since = "1.27.0")]
2313pub fn _mm_comile_sd(a: __m128d, b: __m128d) -> i32 {
2314    unsafe { comilesd(a, b) }
2315}
2316
2317/// Compares the lower element of `a` and `b` for greater-than.
2318///
2319/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comigt_sd)
2320#[inline]
2321#[target_feature(enable = "sse2")]
2322#[cfg_attr(test, assert_instr(comisd))]
2323#[stable(feature = "simd_x86", since = "1.27.0")]
2324pub fn _mm_comigt_sd(a: __m128d, b: __m128d) -> i32 {
2325    unsafe { comigtsd(a, b) }
2326}
2327
2328/// Compares the lower element of `a` and `b` for greater-than-or-equal.
2329///
2330/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comige_sd)
2331#[inline]
2332#[target_feature(enable = "sse2")]
2333#[cfg_attr(test, assert_instr(comisd))]
2334#[stable(feature = "simd_x86", since = "1.27.0")]
2335pub fn _mm_comige_sd(a: __m128d, b: __m128d) -> i32 {
2336    unsafe { comigesd(a, b) }
2337}
2338
2339/// Compares the lower element of `a` and `b` for not-equal.
2340///
2341/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comineq_sd)
2342#[inline]
2343#[target_feature(enable = "sse2")]
2344#[cfg_attr(test, assert_instr(comisd))]
2345#[stable(feature = "simd_x86", since = "1.27.0")]
2346pub fn _mm_comineq_sd(a: __m128d, b: __m128d) -> i32 {
2347    unsafe { comineqsd(a, b) }
2348}
2349
2350/// Compares the lower element of `a` and `b` for equality.
2351///
2352/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_ucomieq_sd)
2353#[inline]
2354#[target_feature(enable = "sse2")]
2355#[cfg_attr(test, assert_instr(ucomisd))]
2356#[stable(feature = "simd_x86", since = "1.27.0")]
2357pub fn _mm_ucomieq_sd(a: __m128d, b: __m128d) -> i32 {
2358    unsafe { ucomieqsd(a, b) }
2359}
2360
2361/// Compares the lower element of `a` and `b` for less-than.
2362///
2363/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_ucomilt_sd)
2364#[inline]
2365#[target_feature(enable = "sse2")]
2366#[cfg_attr(test, assert_instr(ucomisd))]
2367#[stable(feature = "simd_x86", since = "1.27.0")]
2368pub fn _mm_ucomilt_sd(a: __m128d, b: __m128d) -> i32 {
2369    unsafe { ucomiltsd(a, b) }
2370}
2371
2372/// Compares the lower element of `a` and `b` for less-than-or-equal.
2373///
2374/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_ucomile_sd)
2375#[inline]
2376#[target_feature(enable = "sse2")]
2377#[cfg_attr(test, assert_instr(ucomisd))]
2378#[stable(feature = "simd_x86", since = "1.27.0")]
2379pub fn _mm_ucomile_sd(a: __m128d, b: __m128d) -> i32 {
2380    unsafe { ucomilesd(a, b) }
2381}
2382
2383/// Compares the lower element of `a` and `b` for greater-than.
2384///
2385/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_ucomigt_sd)
2386#[inline]
2387#[target_feature(enable = "sse2")]
2388#[cfg_attr(test, assert_instr(ucomisd))]
2389#[stable(feature = "simd_x86", since = "1.27.0")]
2390pub fn _mm_ucomigt_sd(a: __m128d, b: __m128d) -> i32 {
2391    unsafe { ucomigtsd(a, b) }
2392}
2393
2394/// Compares the lower element of `a` and `b` for greater-than-or-equal.
2395///
2396/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_ucomige_sd)
2397#[inline]
2398#[target_feature(enable = "sse2")]
2399#[cfg_attr(test, assert_instr(ucomisd))]
2400#[stable(feature = "simd_x86", since = "1.27.0")]
2401pub fn _mm_ucomige_sd(a: __m128d, b: __m128d) -> i32 {
2402    unsafe { ucomigesd(a, b) }
2403}
2404
2405/// Compares the lower element of `a` and `b` for not-equal.
2406///
2407/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_ucomineq_sd)
2408#[inline]
2409#[target_feature(enable = "sse2")]
2410#[cfg_attr(test, assert_instr(ucomisd))]
2411#[stable(feature = "simd_x86", since = "1.27.0")]
2412pub fn _mm_ucomineq_sd(a: __m128d, b: __m128d) -> i32 {
2413    unsafe { ucomineqsd(a, b) }
2414}
2415
2416/// Converts packed double-precision (64-bit) floating-point elements in `a` to
2417/// packed single-precision (32-bit) floating-point elements
2418///
2419/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpd_ps)
2420#[inline]
2421#[target_feature(enable = "sse2")]
2422#[cfg_attr(test, assert_instr(cvtpd2ps))]
2423#[stable(feature = "simd_x86", since = "1.27.0")]
2424#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2425pub const fn _mm_cvtpd_ps(a: __m128d) -> __m128 {
2426    unsafe {
2427        let r = simd_cast::<_, f32x2>(a.as_f64x2());
2428        let zero = f32x2::ZERO;
2429        transmute::<f32x4, _>(simd_shuffle!(r, zero, [0, 1, 2, 3]))
2430    }
2431}
2432
2433/// Converts packed single-precision (32-bit) floating-point elements in `a` to
2434/// packed
2435/// double-precision (64-bit) floating-point elements.
2436///
2437/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtps_pd)
2438#[inline]
2439#[target_feature(enable = "sse2")]
2440#[cfg_attr(test, assert_instr(cvtps2pd))]
2441#[stable(feature = "simd_x86", since = "1.27.0")]
2442#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2443pub const fn _mm_cvtps_pd(a: __m128) -> __m128d {
2444    unsafe {
2445        let a = a.as_f32x4();
2446        transmute(simd_cast::<f32x2, f64x2>(simd_shuffle!(a, a, [0, 1])))
2447    }
2448}
2449
2450/// Converts packed double-precision (64-bit) floating-point elements in `a` to
2451/// packed 32-bit integers.
2452///
2453/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpd_epi32)
2454#[inline]
2455#[target_feature(enable = "sse2")]
2456#[cfg_attr(test, assert_instr(cvtpd2dq))]
2457#[stable(feature = "simd_x86", since = "1.27.0")]
2458pub fn _mm_cvtpd_epi32(a: __m128d) -> __m128i {
2459    unsafe { transmute(cvtpd2dq(a)) }
2460}
2461
2462/// Converts the lower double-precision (64-bit) floating-point element in a to
2463/// a 32-bit integer.
2464///
2465/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsd_si32)
2466#[inline]
2467#[target_feature(enable = "sse2")]
2468#[cfg_attr(test, assert_instr(cvtsd2si))]
2469#[stable(feature = "simd_x86", since = "1.27.0")]
2470pub fn _mm_cvtsd_si32(a: __m128d) -> i32 {
2471    unsafe { cvtsd2si(a) }
2472}
2473
2474/// Converts the lower double-precision (64-bit) floating-point element in `b`
2475/// to a single-precision (32-bit) floating-point element, store the result in
2476/// the lower element of the return value, and copies the upper element from `a`
2477/// to the upper element the return value.
2478///
2479/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsd_ss)
2480#[inline]
2481#[target_feature(enable = "sse2")]
2482#[cfg_attr(test, assert_instr(cvtsd2ss))]
2483#[stable(feature = "simd_x86", since = "1.27.0")]
2484pub fn _mm_cvtsd_ss(a: __m128, b: __m128d) -> __m128 {
2485    unsafe { cvtsd2ss(a, b) }
2486}
2487
2488/// Returns the lower double-precision (64-bit) floating-point element of `a`.
2489///
2490/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsd_f64)
2491#[inline]
2492#[target_feature(enable = "sse2")]
2493#[stable(feature = "simd_x86", since = "1.27.0")]
2494#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2495pub const fn _mm_cvtsd_f64(a: __m128d) -> f64 {
2496    unsafe { simd_extract!(a, 0) }
2497}
2498
2499/// Converts the lower single-precision (32-bit) floating-point element in `b`
2500/// to a double-precision (64-bit) floating-point element, store the result in
2501/// the lower element of the return value, and copies the upper element from `a`
2502/// to the upper element the return value.
2503///
2504/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtss_sd)
2505#[inline]
2506#[target_feature(enable = "sse2")]
2507#[cfg_attr(test, assert_instr(cvtss2sd))]
2508#[stable(feature = "simd_x86", since = "1.27.0")]
2509#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2510pub const fn _mm_cvtss_sd(a: __m128d, b: __m128) -> __m128d {
2511    unsafe {
2512        let elt: f32 = simd_extract!(b, 0);
2513        simd_insert!(a, 0, elt as f64)
2514    }
2515}
2516
2517/// Converts packed double-precision (64-bit) floating-point elements in `a` to
2518/// packed 32-bit integers with truncation.
2519///
2520/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttpd_epi32)
2521#[inline]
2522#[target_feature(enable = "sse2")]
2523#[cfg_attr(test, assert_instr(cvttpd2dq))]
2524#[stable(feature = "simd_x86", since = "1.27.0")]
2525pub fn _mm_cvttpd_epi32(a: __m128d) -> __m128i {
2526    unsafe { transmute(cvttpd2dq(a)) }
2527}
2528
2529/// Converts the lower double-precision (64-bit) floating-point element in `a`
2530/// to a 32-bit integer with truncation.
2531///
2532/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttsd_si32)
2533#[inline]
2534#[target_feature(enable = "sse2")]
2535#[cfg_attr(test, assert_instr(cvttsd2si))]
2536#[stable(feature = "simd_x86", since = "1.27.0")]
2537pub fn _mm_cvttsd_si32(a: __m128d) -> i32 {
2538    unsafe { cvttsd2si(a) }
2539}
2540
2541/// Converts packed single-precision (32-bit) floating-point elements in `a` to
2542/// packed 32-bit integers with truncation.
2543///
2544/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttps_epi32)
2545#[inline]
2546#[target_feature(enable = "sse2")]
2547#[cfg_attr(test, assert_instr(cvttps2dq))]
2548#[stable(feature = "simd_x86", since = "1.27.0")]
2549pub fn _mm_cvttps_epi32(a: __m128) -> __m128i {
2550    unsafe { transmute(cvttps2dq(a)) }
2551}
2552
2553/// Copies double-precision (64-bit) floating-point element `a` to the lower
2554/// element of the packed 64-bit return value.
2555///
2556/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_sd)
2557#[inline]
2558#[target_feature(enable = "sse2")]
2559#[stable(feature = "simd_x86", since = "1.27.0")]
2560#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2561pub const fn _mm_set_sd(a: f64) -> __m128d {
2562    _mm_set_pd(0.0, a)
2563}
2564
2565/// Broadcasts double-precision (64-bit) floating-point value a to all elements
2566/// of the return value.
2567///
2568/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set1_pd)
2569#[inline]
2570#[target_feature(enable = "sse2")]
2571#[stable(feature = "simd_x86", since = "1.27.0")]
2572#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2573pub const fn _mm_set1_pd(a: f64) -> __m128d {
2574    _mm_set_pd(a, a)
2575}
2576
2577/// Broadcasts double-precision (64-bit) floating-point value a to all elements
2578/// of the return value.
2579///
2580/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_pd1)
2581#[inline]
2582#[target_feature(enable = "sse2")]
2583#[stable(feature = "simd_x86", since = "1.27.0")]
2584#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2585pub const fn _mm_set_pd1(a: f64) -> __m128d {
2586    _mm_set_pd(a, a)
2587}
2588
2589/// Sets packed double-precision (64-bit) floating-point elements in the return
2590/// value with the supplied values.
2591///
2592/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_pd)
2593#[inline]
2594#[target_feature(enable = "sse2")]
2595#[stable(feature = "simd_x86", since = "1.27.0")]
2596#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2597pub const fn _mm_set_pd(a: f64, b: f64) -> __m128d {
2598    __m128d([b, a])
2599}
2600
2601/// Sets packed double-precision (64-bit) floating-point elements in the return
2602/// value with the supplied values in reverse order.
2603///
2604/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setr_pd)
2605#[inline]
2606#[target_feature(enable = "sse2")]
2607#[stable(feature = "simd_x86", since = "1.27.0")]
2608#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2609pub const fn _mm_setr_pd(a: f64, b: f64) -> __m128d {
2610    _mm_set_pd(b, a)
2611}
2612
2613/// Returns packed double-precision (64-bit) floating-point elements with all
2614/// zeros.
2615///
2616/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setzero_pd)
2617#[inline]
2618#[target_feature(enable = "sse2")]
2619#[cfg_attr(test, assert_instr(xorp))]
2620#[stable(feature = "simd_x86", since = "1.27.0")]
2621#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2622pub const fn _mm_setzero_pd() -> __m128d {
2623    const { unsafe { mem::zeroed() } }
2624}
2625
2626/// Returns a mask of the most significant bit of each element in `a`.
2627///
2628/// The mask is stored in the 2 least significant bits of the return value.
2629/// All other bits are set to `0`.
2630///
2631/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_movemask_pd)
2632#[inline]
2633#[target_feature(enable = "sse2")]
2634#[cfg_attr(test, assert_instr(movmskpd))]
2635#[stable(feature = "simd_x86", since = "1.27.0")]
2636#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2637pub const fn _mm_movemask_pd(a: __m128d) -> i32 {
2638    // Propagate the highest bit to the rest, because simd_bitmask
2639    // requires all-1 or all-0.
2640    unsafe {
2641        let mask: i64x2 = simd_lt(transmute(a), i64x2::ZERO);
2642        simd_bitmask::<i64x2, u8>(mask) as i32
2643    }
2644}
2645
2646/// Loads 128-bits (composed of 2 packed double-precision (64-bit)
2647/// floating-point elements) from memory into the returned vector.
2648/// `mem_addr` must be aligned on a 16-byte boundary or a general-protection
2649/// exception may be generated.
2650///
2651/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load_pd)
2652#[inline]
2653#[target_feature(enable = "sse2")]
2654#[cfg_attr(
2655    all(test, not(all(target_arch = "x86", target_env = "msvc"))),
2656    assert_instr(movaps)
2657)]
2658#[stable(feature = "simd_x86", since = "1.27.0")]
2659#[allow(clippy::cast_ptr_alignment)]
2660#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2661pub const unsafe fn _mm_load_pd(mem_addr: *const f64) -> __m128d {
2662    *(mem_addr as *const __m128d)
2663}
2664
2665/// Loads a 64-bit double-precision value to the low element of a
2666/// 128-bit integer vector and clears the upper element.
2667///
2668/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load_sd)
2669#[inline]
2670#[target_feature(enable = "sse2")]
2671#[cfg_attr(test, assert_instr(movsd))]
2672#[stable(feature = "simd_x86", since = "1.27.0")]
2673#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2674pub const unsafe fn _mm_load_sd(mem_addr: *const f64) -> __m128d {
2675    _mm_setr_pd(*mem_addr, 0.)
2676}
2677
2678/// Loads a double-precision value into the high-order bits of a 128-bit
2679/// vector of `[2 x double]`. The low-order bits are copied from the low-order
2680/// bits of the first operand.
2681///
2682/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadh_pd)
2683#[inline]
2684#[target_feature(enable = "sse2")]
2685#[cfg_attr(test, assert_instr(movhps))]
2686#[stable(feature = "simd_x86", since = "1.27.0")]
2687#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2688pub const unsafe fn _mm_loadh_pd(a: __m128d, mem_addr: *const f64) -> __m128d {
2689    _mm_setr_pd(simd_extract!(a, 0), *mem_addr)
2690}
2691
2692/// Loads a double-precision value into the low-order bits of a 128-bit
2693/// vector of `[2 x double]`. The high-order bits are copied from the
2694/// high-order bits of the first operand.
2695///
2696/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadl_pd)
2697#[inline]
2698#[target_feature(enable = "sse2")]
2699#[cfg_attr(test, assert_instr(movlps))]
2700#[stable(feature = "simd_x86", since = "1.27.0")]
2701#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2702pub const unsafe fn _mm_loadl_pd(a: __m128d, mem_addr: *const f64) -> __m128d {
2703    _mm_setr_pd(*mem_addr, simd_extract!(a, 1))
2704}
2705
2706/// Stores a 128-bit floating point vector of `[2 x double]` to a 128-bit
2707/// aligned memory location.
2708/// To minimize caching, the data is flagged as non-temporal (unlikely to be
2709/// used again soon).
2710///
2711/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_stream_pd)
2712///
2713/// # Safety of non-temporal stores
2714///
2715/// After using this intrinsic, but before any other access to the memory that this intrinsic
2716/// mutates, a call to [`_mm_sfence`] must be performed by the thread that used the intrinsic. In
2717/// particular, functions that call this intrinsic should generally call `_mm_sfence` before they
2718/// return.
2719///
2720/// See [`_mm_sfence`] for details.
2721#[inline]
2722#[target_feature(enable = "sse2")]
2723#[cfg_attr(test, assert_instr(movntpd))]
2724#[stable(feature = "simd_x86", since = "1.27.0")]
2725#[allow(clippy::cast_ptr_alignment)]
2726pub unsafe fn _mm_stream_pd(mem_addr: *mut f64, a: __m128d) {
2727    // see #1541, we should use inline asm to be sure, because LangRef isn't clear enough
2728    crate::arch::asm!(
2729        vps!("movntpd", ",{a}"),
2730        p = in(reg) mem_addr,
2731        a = in(xmm_reg) a,
2732        options(nostack, preserves_flags),
2733    );
2734}
2735
2736/// Stores the lower 64 bits of a 128-bit vector of `[2 x double]` to a
2737/// memory location.
2738///
2739/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_store_sd)
2740#[inline]
2741#[target_feature(enable = "sse2")]
2742#[cfg_attr(test, assert_instr(movlps))]
2743#[stable(feature = "simd_x86", since = "1.27.0")]
2744#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2745pub const unsafe fn _mm_store_sd(mem_addr: *mut f64, a: __m128d) {
2746    *mem_addr = simd_extract!(a, 0)
2747}
2748
2749/// Stores 128-bits (composed of 2 packed double-precision (64-bit)
2750/// floating-point elements) from `a` into memory. `mem_addr` must be aligned
2751/// on a 16-byte boundary or a general-protection exception may be generated.
2752///
2753/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_store_pd)
2754#[inline]
2755#[target_feature(enable = "sse2")]
2756#[cfg_attr(
2757    all(test, not(all(target_arch = "x86", target_env = "msvc"))),
2758    assert_instr(movaps)
2759)]
2760#[stable(feature = "simd_x86", since = "1.27.0")]
2761#[allow(clippy::cast_ptr_alignment)]
2762#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2763pub const unsafe fn _mm_store_pd(mem_addr: *mut f64, a: __m128d) {
2764    *(mem_addr as *mut __m128d) = a;
2765}
2766
2767/// Stores 128-bits (composed of 2 packed double-precision (64-bit)
2768/// floating-point elements) from `a` into memory.
2769/// `mem_addr` does not need to be aligned on any particular boundary.
2770///
2771/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeu_pd)
2772#[inline]
2773#[target_feature(enable = "sse2")]
2774#[cfg_attr(test, assert_instr(movups))] // FIXME movupd expected
2775#[stable(feature = "simd_x86", since = "1.27.0")]
2776#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2777pub const unsafe fn _mm_storeu_pd(mem_addr: *mut f64, a: __m128d) {
2778    mem_addr.cast::<__m128d>().write_unaligned(a);
2779}
2780
2781/// Store 16-bit integer from the first element of a into memory.
2782///
2783/// `mem_addr` does not need to be aligned on any particular boundary.
2784///
2785/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeu_si16)
2786#[inline]
2787#[target_feature(enable = "sse2")]
2788#[stable(feature = "simd_x86_updates", since = "1.82.0")]
2789#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2790pub const unsafe fn _mm_storeu_si16(mem_addr: *mut u8, a: __m128i) {
2791    ptr::write_unaligned(mem_addr as *mut i16, simd_extract(a.as_i16x8(), 0))
2792}
2793
2794/// Store 32-bit integer from the first element of a into memory.
2795///
2796/// `mem_addr` does not need to be aligned on any particular boundary.
2797///
2798/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeu_si32)
2799#[inline]
2800#[target_feature(enable = "sse2")]
2801#[stable(feature = "simd_x86_updates", since = "1.82.0")]
2802#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2803pub const unsafe fn _mm_storeu_si32(mem_addr: *mut u8, a: __m128i) {
2804    ptr::write_unaligned(mem_addr as *mut i32, simd_extract(a.as_i32x4(), 0))
2805}
2806
2807/// Store 64-bit integer from the first element of a into memory.
2808///
2809/// `mem_addr` does not need to be aligned on any particular boundary.
2810///
2811/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeu_si64)
2812#[inline]
2813#[target_feature(enable = "sse2")]
2814#[stable(feature = "simd_x86_updates", since = "1.82.0")]
2815#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2816pub const unsafe fn _mm_storeu_si64(mem_addr: *mut u8, a: __m128i) {
2817    ptr::write_unaligned(mem_addr as *mut i64, simd_extract(a.as_i64x2(), 0))
2818}
2819
2820/// Stores the lower double-precision (64-bit) floating-point element from `a`
2821/// into 2 contiguous elements in memory. `mem_addr` must be aligned on a
2822/// 16-byte boundary or a general-protection exception may be generated.
2823///
2824/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_store1_pd)
2825#[inline]
2826#[target_feature(enable = "sse2")]
2827#[stable(feature = "simd_x86", since = "1.27.0")]
2828#[allow(clippy::cast_ptr_alignment)]
2829#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2830pub const unsafe fn _mm_store1_pd(mem_addr: *mut f64, a: __m128d) {
2831    let b: __m128d = simd_shuffle!(a, a, [0, 0]);
2832    *(mem_addr as *mut __m128d) = b;
2833}
2834
2835/// Stores the lower double-precision (64-bit) floating-point element from `a`
2836/// into 2 contiguous elements in memory. `mem_addr` must be aligned on a
2837/// 16-byte boundary or a general-protection exception may be generated.
2838///
2839/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_store_pd1)
2840#[inline]
2841#[target_feature(enable = "sse2")]
2842#[stable(feature = "simd_x86", since = "1.27.0")]
2843#[allow(clippy::cast_ptr_alignment)]
2844#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2845pub const unsafe fn _mm_store_pd1(mem_addr: *mut f64, a: __m128d) {
2846    let b: __m128d = simd_shuffle!(a, a, [0, 0]);
2847    *(mem_addr as *mut __m128d) = b;
2848}
2849
2850/// Stores 2 double-precision (64-bit) floating-point elements from `a` into
2851/// memory in reverse order.
2852/// `mem_addr` must be aligned on a 16-byte boundary or a general-protection
2853/// exception may be generated.
2854///
2855/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storer_pd)
2856#[inline]
2857#[target_feature(enable = "sse2")]
2858#[stable(feature = "simd_x86", since = "1.27.0")]
2859#[allow(clippy::cast_ptr_alignment)]
2860#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2861pub const unsafe fn _mm_storer_pd(mem_addr: *mut f64, a: __m128d) {
2862    let b: __m128d = simd_shuffle!(a, a, [1, 0]);
2863    *(mem_addr as *mut __m128d) = b;
2864}
2865
2866/// Stores the upper 64 bits of a 128-bit vector of `[2 x double]` to a
2867/// memory location.
2868///
2869/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeh_pd)
2870#[inline]
2871#[target_feature(enable = "sse2")]
2872#[cfg_attr(test, assert_instr(movhps))]
2873#[stable(feature = "simd_x86", since = "1.27.0")]
2874#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2875pub const unsafe fn _mm_storeh_pd(mem_addr: *mut f64, a: __m128d) {
2876    *mem_addr = simd_extract!(a, 1);
2877}
2878
2879/// Stores the lower 64 bits of a 128-bit vector of `[2 x double]` to a
2880/// memory location.
2881///
2882/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storel_pd)
2883#[inline]
2884#[target_feature(enable = "sse2")]
2885#[cfg_attr(test, assert_instr(movlps))]
2886#[stable(feature = "simd_x86", since = "1.27.0")]
2887#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2888pub const unsafe fn _mm_storel_pd(mem_addr: *mut f64, a: __m128d) {
2889    *mem_addr = simd_extract!(a, 0);
2890}
2891
2892/// Loads a double-precision (64-bit) floating-point element from memory
2893/// into both elements of returned vector.
2894///
2895/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load1_pd)
2896#[inline]
2897#[target_feature(enable = "sse2")]
2898// #[cfg_attr(test, assert_instr(movapd))] // FIXME LLVM uses different codegen
2899#[stable(feature = "simd_x86", since = "1.27.0")]
2900#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2901pub const unsafe fn _mm_load1_pd(mem_addr: *const f64) -> __m128d {
2902    let d = *mem_addr;
2903    _mm_setr_pd(d, d)
2904}
2905
2906/// Loads a double-precision (64-bit) floating-point element from memory
2907/// into both elements of returned vector.
2908///
2909/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load_pd1)
2910#[inline]
2911#[target_feature(enable = "sse2")]
2912// #[cfg_attr(test, assert_instr(movapd))] // FIXME same as _mm_load1_pd
2913#[stable(feature = "simd_x86", since = "1.27.0")]
2914#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2915pub const unsafe fn _mm_load_pd1(mem_addr: *const f64) -> __m128d {
2916    _mm_load1_pd(mem_addr)
2917}
2918
2919/// Loads 2 double-precision (64-bit) floating-point elements from memory into
2920/// the returned vector in reverse order. `mem_addr` must be aligned on a
2921/// 16-byte boundary or a general-protection exception may be generated.
2922///
2923/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadr_pd)
2924#[inline]
2925#[target_feature(enable = "sse2")]
2926#[cfg_attr(
2927    all(test, not(all(target_arch = "x86", target_env = "msvc"))),
2928    assert_instr(movaps)
2929)]
2930#[stable(feature = "simd_x86", since = "1.27.0")]
2931#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2932pub const unsafe fn _mm_loadr_pd(mem_addr: *const f64) -> __m128d {
2933    let a = _mm_load_pd(mem_addr);
2934    simd_shuffle!(a, a, [1, 0])
2935}
2936
2937/// Loads 128-bits (composed of 2 packed double-precision (64-bit)
2938/// floating-point elements) from memory into the returned vector.
2939/// `mem_addr` does not need to be aligned on any particular boundary.
2940///
2941/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadu_pd)
2942#[inline]
2943#[target_feature(enable = "sse2")]
2944#[cfg_attr(test, assert_instr(movups))]
2945#[stable(feature = "simd_x86", since = "1.27.0")]
2946#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2947pub const unsafe fn _mm_loadu_pd(mem_addr: *const f64) -> __m128d {
2948    let mut dst = _mm_undefined_pd();
2949    ptr::copy_nonoverlapping(
2950        mem_addr as *const u8,
2951        ptr::addr_of_mut!(dst) as *mut u8,
2952        mem::size_of::<__m128d>(),
2953    );
2954    dst
2955}
2956
2957/// Loads unaligned 16-bits of integer data from memory into new vector.
2958///
2959/// `mem_addr` does not need to be aligned on any particular boundary.
2960///
2961/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadu_si16)
2962#[inline]
2963#[target_feature(enable = "sse2")]
2964#[stable(feature = "simd_x86_updates", since = "1.82.0")]
2965#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2966pub const unsafe fn _mm_loadu_si16(mem_addr: *const u8) -> __m128i {
2967    transmute(i16x8::new(
2968        ptr::read_unaligned(mem_addr as *const i16),
2969        0,
2970        0,
2971        0,
2972        0,
2973        0,
2974        0,
2975        0,
2976    ))
2977}
2978
2979/// Loads unaligned 32-bits of integer data from memory into new vector.
2980///
2981/// `mem_addr` does not need to be aligned on any particular boundary.
2982///
2983/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadu_si32)
2984#[inline]
2985#[target_feature(enable = "sse2")]
2986#[stable(feature = "simd_x86_updates", since = "1.82.0")]
2987#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
2988pub const unsafe fn _mm_loadu_si32(mem_addr: *const u8) -> __m128i {
2989    transmute(i32x4::new(
2990        ptr::read_unaligned(mem_addr as *const i32),
2991        0,
2992        0,
2993        0,
2994    ))
2995}
2996
2997/// Loads unaligned 64-bits of integer data from memory into new vector.
2998///
2999/// `mem_addr` does not need to be aligned on any particular boundary.
3000///
3001/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadu_si64)
3002#[inline]
3003#[target_feature(enable = "sse2")]
3004#[stable(feature = "simd_x86_mm_loadu_si64", since = "1.46.0")]
3005#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3006pub const unsafe fn _mm_loadu_si64(mem_addr: *const u8) -> __m128i {
3007    transmute(i64x2::new(ptr::read_unaligned(mem_addr as *const i64), 0))
3008}
3009
3010/// Constructs a 128-bit floating-point vector of `[2 x double]` from two
3011/// 128-bit vector parameters of `[2 x double]`, using the immediate-value
3012/// parameter as a specifier.
3013///
3014/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_shuffle_pd)
3015#[inline]
3016#[target_feature(enable = "sse2")]
3017#[cfg_attr(test, assert_instr(shufps, MASK = 2))]
3018#[rustc_legacy_const_generics(2)]
3019#[stable(feature = "simd_x86", since = "1.27.0")]
3020#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3021pub const fn _mm_shuffle_pd<const MASK: i32>(a: __m128d, b: __m128d) -> __m128d {
3022    static_assert_uimm_bits!(MASK, 8);
3023    unsafe { simd_shuffle!(a, b, [MASK as u32 & 0b1, ((MASK as u32 >> 1) & 0b1) + 2]) }
3024}
3025
3026/// Constructs a 128-bit floating-point vector of `[2 x double]`. The lower
3027/// 64 bits are set to the lower 64 bits of the second parameter. The upper
3028/// 64 bits are set to the upper 64 bits of the first parameter.
3029///
3030/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_move_sd)
3031#[inline]
3032#[target_feature(enable = "sse2")]
3033#[cfg_attr(test, assert_instr(movsd))]
3034#[stable(feature = "simd_x86", since = "1.27.0")]
3035#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3036pub const fn _mm_move_sd(a: __m128d, b: __m128d) -> __m128d {
3037    unsafe { _mm_setr_pd(simd_extract!(b, 0), simd_extract!(a, 1)) }
3038}
3039
3040/// Casts a 128-bit floating-point vector of `[2 x double]` into a 128-bit
3041/// floating-point vector of `[4 x float]`.
3042///
3043/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_castpd_ps)
3044#[inline]
3045#[target_feature(enable = "sse2")]
3046#[stable(feature = "simd_x86", since = "1.27.0")]
3047#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3048pub const fn _mm_castpd_ps(a: __m128d) -> __m128 {
3049    unsafe { transmute(a) }
3050}
3051
3052/// Casts a 128-bit floating-point vector of `[2 x double]` into a 128-bit
3053/// integer vector.
3054///
3055/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_castpd_si128)
3056#[inline]
3057#[target_feature(enable = "sse2")]
3058#[stable(feature = "simd_x86", since = "1.27.0")]
3059#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3060pub const fn _mm_castpd_si128(a: __m128d) -> __m128i {
3061    unsafe { transmute(a) }
3062}
3063
3064/// Casts a 128-bit floating-point vector of `[4 x float]` into a 128-bit
3065/// floating-point vector of `[2 x double]`.
3066///
3067/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_castps_pd)
3068#[inline]
3069#[target_feature(enable = "sse2")]
3070#[stable(feature = "simd_x86", since = "1.27.0")]
3071#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3072pub const fn _mm_castps_pd(a: __m128) -> __m128d {
3073    unsafe { transmute(a) }
3074}
3075
3076/// Casts a 128-bit floating-point vector of `[4 x float]` into a 128-bit
3077/// integer vector.
3078///
3079/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_castps_si128)
3080#[inline]
3081#[target_feature(enable = "sse2")]
3082#[stable(feature = "simd_x86", since = "1.27.0")]
3083#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3084pub const fn _mm_castps_si128(a: __m128) -> __m128i {
3085    unsafe { transmute(a) }
3086}
3087
3088/// Casts a 128-bit integer vector into a 128-bit floating-point vector
3089/// of `[2 x double]`.
3090///
3091/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_castsi128_pd)
3092#[inline]
3093#[target_feature(enable = "sse2")]
3094#[stable(feature = "simd_x86", since = "1.27.0")]
3095#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3096pub const fn _mm_castsi128_pd(a: __m128i) -> __m128d {
3097    unsafe { transmute(a) }
3098}
3099
3100/// Casts a 128-bit integer vector into a 128-bit floating-point vector
3101/// of `[4 x float]`.
3102///
3103/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_castsi128_ps)
3104#[inline]
3105#[target_feature(enable = "sse2")]
3106#[stable(feature = "simd_x86", since = "1.27.0")]
3107#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3108pub const fn _mm_castsi128_ps(a: __m128i) -> __m128 {
3109    unsafe { transmute(a) }
3110}
3111
3112/// Returns vector of type __m128d with indeterminate elements.with indetermination elements.
3113/// Despite using the word "undefined" (following Intel's naming scheme), this non-deterministically
3114/// picks some valid value and is not equivalent to [`mem::MaybeUninit`].
3115/// In practice, this is typically equivalent to [`mem::zeroed`].
3116///
3117/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_undefined_pd)
3118#[inline]
3119#[target_feature(enable = "sse2")]
3120#[stable(feature = "simd_x86", since = "1.27.0")]
3121#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3122pub const fn _mm_undefined_pd() -> __m128d {
3123    const { unsafe { mem::zeroed() } }
3124}
3125
3126/// Returns vector of type __m128i with indeterminate elements.with indetermination elements.
3127/// Despite using the word "undefined" (following Intel's naming scheme), this non-deterministically
3128/// picks some valid value and is not equivalent to [`mem::MaybeUninit`].
3129/// In practice, this is typically equivalent to [`mem::zeroed`].
3130///
3131/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_undefined_si128)
3132#[ferrocene::prevalidated]
3133#[inline]
3134#[target_feature(enable = "sse2")]
3135#[stable(feature = "simd_x86", since = "1.27.0")]
3136#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3137pub const fn _mm_undefined_si128() -> __m128i {
3138    const { unsafe { mem::zeroed() } }
3139}
3140
3141/// The resulting `__m128d` element is composed by the low-order values of
3142/// the two `__m128d` interleaved input elements, i.e.:
3143///
3144/// * The `[127:64]` bits are copied from the `[127:64]` bits of the second input
3145/// * The `[63:0]` bits are copied from the `[127:64]` bits of the first input
3146///
3147/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpackhi_pd)
3148#[inline]
3149#[target_feature(enable = "sse2")]
3150#[cfg_attr(test, assert_instr(unpckhpd))]
3151#[stable(feature = "simd_x86", since = "1.27.0")]
3152#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3153pub const fn _mm_unpackhi_pd(a: __m128d, b: __m128d) -> __m128d {
3154    unsafe { simd_shuffle!(a, b, [1, 3]) }
3155}
3156
3157/// The resulting `__m128d` element is composed by the high-order values of
3158/// the two `__m128d` interleaved input elements, i.e.:
3159///
3160/// * The `[127:64]` bits are copied from the `[63:0]` bits of the second input
3161/// * The `[63:0]` bits are copied from the `[63:0]` bits of the first input
3162///
3163/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpacklo_pd)
3164#[inline]
3165#[target_feature(enable = "sse2")]
3166#[cfg_attr(test, assert_instr(movlhps))]
3167#[stable(feature = "simd_x86", since = "1.27.0")]
3168#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
3169pub const fn _mm_unpacklo_pd(a: __m128d, b: __m128d) -> __m128d {
3170    unsafe { simd_shuffle!(a, b, [0, 2]) }
3171}
3172
3173#[allow(improper_ctypes)]
3174unsafe extern "llvm-intrinsic" {
3175    #[link_name = "llvm.x86.sse2.pause"]
3176    fn pause();
3177    #[link_name = "llvm.x86.sse2.clflush"]
3178    fn clflush(p: *const u8);
3179    #[link_name = "llvm.x86.sse2.lfence"]
3180    fn lfence();
3181    #[link_name = "llvm.x86.sse2.mfence"]
3182    fn mfence();
3183    #[link_name = "llvm.x86.sse2.pavg.b"]
3184    fn pavgb(a: u8x16, b: u8x16) -> u8x16;
3185    #[link_name = "llvm.x86.sse2.pavg.w"]
3186    fn pavgw(a: u16x8, b: u16x8) -> u16x8;
3187    #[link_name = "llvm.x86.sse2.pmadd.wd"]
3188    fn pmaddwd(a: i16x8, b: i16x8) -> i32x4;
3189    #[link_name = "llvm.x86.sse2.pmulh.w"]
3190    fn pmulhw(a: i16x8, b: i16x8) -> i16x8;
3191    #[link_name = "llvm.x86.sse2.pmulhu.w"]
3192    fn pmulhuw(a: u16x8, b: u16x8) -> u16x8;
3193    #[link_name = "llvm.x86.sse2.psad.bw"]
3194    fn psadbw(a: u8x16, b: u8x16) -> u64x2;
3195    #[link_name = "llvm.x86.sse2.psll.w"]
3196    fn psllw(a: i16x8, count: i16x8) -> i16x8;
3197    #[link_name = "llvm.x86.sse2.psll.d"]
3198    fn pslld(a: i32x4, count: i32x4) -> i32x4;
3199    #[link_name = "llvm.x86.sse2.psll.q"]
3200    fn psllq(a: i64x2, count: i64x2) -> i64x2;
3201    #[link_name = "llvm.x86.sse2.psra.w"]
3202    fn psraw(a: i16x8, count: i16x8) -> i16x8;
3203    #[link_name = "llvm.x86.sse2.psra.d"]
3204    fn psrad(a: i32x4, count: i32x4) -> i32x4;
3205    #[link_name = "llvm.x86.sse2.psrl.w"]
3206    fn psrlw(a: i16x8, count: i16x8) -> i16x8;
3207    #[link_name = "llvm.x86.sse2.psrl.d"]
3208    fn psrld(a: i32x4, count: i32x4) -> i32x4;
3209    #[link_name = "llvm.x86.sse2.psrl.q"]
3210    fn psrlq(a: i64x2, count: i64x2) -> i64x2;
3211    #[link_name = "llvm.x86.sse2.cvtps2dq"]
3212    fn cvtps2dq(a: __m128) -> i32x4;
3213    #[link_name = "llvm.x86.sse2.maskmov.dqu"]
3214    fn maskmovdqu(a: i8x16, mask: i8x16, mem_addr: *mut i8);
3215    #[link_name = "llvm.x86.sse2.packsswb.128"]
3216    fn packsswb(a: i16x8, b: i16x8) -> i8x16;
3217    #[link_name = "llvm.x86.sse2.packssdw.128"]
3218    fn packssdw(a: i32x4, b: i32x4) -> i16x8;
3219    #[link_name = "llvm.x86.sse2.packuswb.128"]
3220    fn packuswb(a: i16x8, b: i16x8) -> u8x16;
3221    #[link_name = "llvm.x86.sse2.max.sd"]
3222    fn maxsd(a: __m128d, b: __m128d) -> __m128d;
3223    #[link_name = "llvm.x86.sse2.max.pd"]
3224    fn maxpd(a: __m128d, b: __m128d) -> __m128d;
3225    #[link_name = "llvm.x86.sse2.min.sd"]
3226    fn minsd(a: __m128d, b: __m128d) -> __m128d;
3227    #[link_name = "llvm.x86.sse2.min.pd"]
3228    fn minpd(a: __m128d, b: __m128d) -> __m128d;
3229    #[link_name = "llvm.x86.sse2.cmp.sd"]
3230    fn cmpsd(a: __m128d, b: __m128d, imm8: i8) -> __m128d;
3231    #[link_name = "llvm.x86.sse2.cmp.pd"]
3232    fn cmppd(a: __m128d, b: __m128d, imm8: i8) -> __m128d;
3233    #[link_name = "llvm.x86.sse2.comieq.sd"]
3234    fn comieqsd(a: __m128d, b: __m128d) -> i32;
3235    #[link_name = "llvm.x86.sse2.comilt.sd"]
3236    fn comiltsd(a: __m128d, b: __m128d) -> i32;
3237    #[link_name = "llvm.x86.sse2.comile.sd"]
3238    fn comilesd(a: __m128d, b: __m128d) -> i32;
3239    #[link_name = "llvm.x86.sse2.comigt.sd"]
3240    fn comigtsd(a: __m128d, b: __m128d) -> i32;
3241    #[link_name = "llvm.x86.sse2.comige.sd"]
3242    fn comigesd(a: __m128d, b: __m128d) -> i32;
3243    #[link_name = "llvm.x86.sse2.comineq.sd"]
3244    fn comineqsd(a: __m128d, b: __m128d) -> i32;
3245    #[link_name = "llvm.x86.sse2.ucomieq.sd"]
3246    fn ucomieqsd(a: __m128d, b: __m128d) -> i32;
3247    #[link_name = "llvm.x86.sse2.ucomilt.sd"]
3248    fn ucomiltsd(a: __m128d, b: __m128d) -> i32;
3249    #[link_name = "llvm.x86.sse2.ucomile.sd"]
3250    fn ucomilesd(a: __m128d, b: __m128d) -> i32;
3251    #[link_name = "llvm.x86.sse2.ucomigt.sd"]
3252    fn ucomigtsd(a: __m128d, b: __m128d) -> i32;
3253    #[link_name = "llvm.x86.sse2.ucomige.sd"]
3254    fn ucomigesd(a: __m128d, b: __m128d) -> i32;
3255    #[link_name = "llvm.x86.sse2.ucomineq.sd"]
3256    fn ucomineqsd(a: __m128d, b: __m128d) -> i32;
3257    #[link_name = "llvm.x86.sse2.cvtpd2dq"]
3258    fn cvtpd2dq(a: __m128d) -> i32x4;
3259    #[link_name = "llvm.x86.sse2.cvtsd2si"]
3260    fn cvtsd2si(a: __m128d) -> i32;
3261    #[link_name = "llvm.x86.sse2.cvtsd2ss"]
3262    fn cvtsd2ss(a: __m128, b: __m128d) -> __m128;
3263    #[link_name = "llvm.x86.sse2.cvttpd2dq"]
3264    fn cvttpd2dq(a: __m128d) -> i32x4;
3265    #[link_name = "llvm.x86.sse2.cvttsd2si"]
3266    fn cvttsd2si(a: __m128d) -> i32;
3267    #[link_name = "llvm.x86.sse2.cvttps2dq"]
3268    fn cvttps2dq(a: __m128) -> i32x4;
3269}
3270
3271#[cfg(test)]
3272mod tests {
3273    use crate::core_arch::assert_eq_const as assert_eq;
3274    use crate::{
3275        core_arch::{simd::*, x86::*},
3276        hint::black_box,
3277    };
3278    use std::{boxed, mem, ptr};
3279    use stdarch_test::simd_test;
3280
3281    const NAN: f64 = f64::NAN;
3282
3283    #[test]
3284    fn test_mm_pause() {
3285        _mm_pause()
3286    }
3287
3288    #[simd_test(enable = "sse2")]
3289    fn test_mm_clflush() {
3290        let x = 0_u8;
3291        unsafe {
3292            _mm_clflush(ptr::addr_of!(x));
3293        }
3294    }
3295
3296    #[simd_test(enable = "sse2")]
3297    // Miri cannot support this until it is clear how it fits in the Rust memory model
3298    #[cfg_attr(miri, ignore)]
3299    fn test_mm_lfence() {
3300        _mm_lfence();
3301    }
3302
3303    #[simd_test(enable = "sse2")]
3304    // Miri cannot support this until it is clear how it fits in the Rust memory model
3305    #[cfg_attr(miri, ignore)]
3306    fn test_mm_mfence() {
3307        _mm_mfence();
3308    }
3309
3310    #[simd_test(enable = "sse2")]
3311    const fn test_mm_add_epi8() {
3312        let a = _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
3313        #[rustfmt::skip]
3314        let b = _mm_setr_epi8(
3315            16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
3316        );
3317        let r = _mm_add_epi8(a, b);
3318        #[rustfmt::skip]
3319        let e = _mm_setr_epi8(
3320            16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46,
3321        );
3322        assert_eq_m128i(r, e);
3323    }
3324
3325    #[simd_test(enable = "sse2")]
3326    fn test_mm_add_epi8_overflow() {
3327        let a = _mm_set1_epi8(0x7F);
3328        let b = _mm_set1_epi8(1);
3329        let r = _mm_add_epi8(a, b);
3330        assert_eq_m128i(r, _mm_set1_epi8(-128));
3331    }
3332
3333    #[simd_test(enable = "sse2")]
3334    const fn test_mm_add_epi16() {
3335        let a = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
3336        let b = _mm_setr_epi16(8, 9, 10, 11, 12, 13, 14, 15);
3337        let r = _mm_add_epi16(a, b);
3338        let e = _mm_setr_epi16(8, 10, 12, 14, 16, 18, 20, 22);
3339        assert_eq_m128i(r, e);
3340    }
3341
3342    #[simd_test(enable = "sse2")]
3343    const fn test_mm_add_epi32() {
3344        let a = _mm_setr_epi32(0, 1, 2, 3);
3345        let b = _mm_setr_epi32(4, 5, 6, 7);
3346        let r = _mm_add_epi32(a, b);
3347        let e = _mm_setr_epi32(4, 6, 8, 10);
3348        assert_eq_m128i(r, e);
3349    }
3350
3351    #[simd_test(enable = "sse2")]
3352    const fn test_mm_add_epi64() {
3353        let a = _mm_setr_epi64x(0, 1);
3354        let b = _mm_setr_epi64x(2, 3);
3355        let r = _mm_add_epi64(a, b);
3356        let e = _mm_setr_epi64x(2, 4);
3357        assert_eq_m128i(r, e);
3358    }
3359
3360    #[simd_test(enable = "sse2")]
3361    const fn test_mm_adds_epi8() {
3362        let a = _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
3363        #[rustfmt::skip]
3364        let b = _mm_setr_epi8(
3365            16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
3366        );
3367        let r = _mm_adds_epi8(a, b);
3368        #[rustfmt::skip]
3369        let e = _mm_setr_epi8(
3370            16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46,
3371        );
3372        assert_eq_m128i(r, e);
3373    }
3374
3375    #[simd_test(enable = "sse2")]
3376    fn test_mm_adds_epi8_saturate_positive() {
3377        let a = _mm_set1_epi8(0x7F);
3378        let b = _mm_set1_epi8(1);
3379        let r = _mm_adds_epi8(a, b);
3380        assert_eq_m128i(r, a);
3381    }
3382
3383    #[simd_test(enable = "sse2")]
3384    fn test_mm_adds_epi8_saturate_negative() {
3385        let a = _mm_set1_epi8(-0x80);
3386        let b = _mm_set1_epi8(-1);
3387        let r = _mm_adds_epi8(a, b);
3388        assert_eq_m128i(r, a);
3389    }
3390
3391    #[simd_test(enable = "sse2")]
3392    const fn test_mm_adds_epi16() {
3393        let a = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
3394        let b = _mm_setr_epi16(8, 9, 10, 11, 12, 13, 14, 15);
3395        let r = _mm_adds_epi16(a, b);
3396        let e = _mm_setr_epi16(8, 10, 12, 14, 16, 18, 20, 22);
3397        assert_eq_m128i(r, e);
3398    }
3399
3400    #[simd_test(enable = "sse2")]
3401    fn test_mm_adds_epi16_saturate_positive() {
3402        let a = _mm_set1_epi16(0x7FFF);
3403        let b = _mm_set1_epi16(1);
3404        let r = _mm_adds_epi16(a, b);
3405        assert_eq_m128i(r, a);
3406    }
3407
3408    #[simd_test(enable = "sse2")]
3409    fn test_mm_adds_epi16_saturate_negative() {
3410        let a = _mm_set1_epi16(-0x8000);
3411        let b = _mm_set1_epi16(-1);
3412        let r = _mm_adds_epi16(a, b);
3413        assert_eq_m128i(r, a);
3414    }
3415
3416    #[simd_test(enable = "sse2")]
3417    const fn test_mm_adds_epu8() {
3418        let a = _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
3419        #[rustfmt::skip]
3420        let b = _mm_setr_epi8(
3421            16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
3422        );
3423        let r = _mm_adds_epu8(a, b);
3424        #[rustfmt::skip]
3425        let e = _mm_setr_epi8(
3426            16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46,
3427        );
3428        assert_eq_m128i(r, e);
3429    }
3430
3431    #[simd_test(enable = "sse2")]
3432    fn test_mm_adds_epu8_saturate() {
3433        let a = _mm_set1_epi8(!0);
3434        let b = _mm_set1_epi8(1);
3435        let r = _mm_adds_epu8(a, b);
3436        assert_eq_m128i(r, a);
3437    }
3438
3439    #[simd_test(enable = "sse2")]
3440    const fn test_mm_adds_epu16() {
3441        let a = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
3442        let b = _mm_setr_epi16(8, 9, 10, 11, 12, 13, 14, 15);
3443        let r = _mm_adds_epu16(a, b);
3444        let e = _mm_setr_epi16(8, 10, 12, 14, 16, 18, 20, 22);
3445        assert_eq_m128i(r, e);
3446    }
3447
3448    #[simd_test(enable = "sse2")]
3449    fn test_mm_adds_epu16_saturate() {
3450        let a = _mm_set1_epi16(!0);
3451        let b = _mm_set1_epi16(1);
3452        let r = _mm_adds_epu16(a, b);
3453        assert_eq_m128i(r, a);
3454    }
3455
3456    #[simd_test(enable = "sse2")]
3457    fn test_mm_avg_epu8() {
3458        let (a, b) = (_mm_set1_epi8(3), _mm_set1_epi8(9));
3459        let r = _mm_avg_epu8(a, b);
3460        assert_eq_m128i(r, _mm_set1_epi8(6));
3461    }
3462
3463    #[simd_test(enable = "sse2")]
3464    fn test_mm_avg_epu16() {
3465        let (a, b) = (_mm_set1_epi16(3), _mm_set1_epi16(9));
3466        let r = _mm_avg_epu16(a, b);
3467        assert_eq_m128i(r, _mm_set1_epi16(6));
3468    }
3469
3470    #[simd_test(enable = "sse2")]
3471    fn test_mm_madd_epi16() {
3472        let a = _mm_setr_epi16(1, 2, 3, 4, 5, 6, 7, 8);
3473        let b = _mm_setr_epi16(9, 10, 11, 12, 13, 14, 15, 16);
3474        let r = _mm_madd_epi16(a, b);
3475        let e = _mm_setr_epi32(29, 81, 149, 233);
3476        assert_eq_m128i(r, e);
3477
3478        // Test large values.
3479        // MIN*MIN+MIN*MIN will overflow into i32::MIN.
3480        let a = _mm_setr_epi16(
3481            i16::MAX,
3482            i16::MAX,
3483            i16::MIN,
3484            i16::MIN,
3485            i16::MIN,
3486            i16::MAX,
3487            0,
3488            0,
3489        );
3490        let b = _mm_setr_epi16(
3491            i16::MAX,
3492            i16::MAX,
3493            i16::MIN,
3494            i16::MIN,
3495            i16::MAX,
3496            i16::MIN,
3497            0,
3498            0,
3499        );
3500        let r = _mm_madd_epi16(a, b);
3501        let e = _mm_setr_epi32(0x7FFE0002, i32::MIN, -0x7FFF0000, 0);
3502        assert_eq_m128i(r, e);
3503    }
3504
3505    #[simd_test(enable = "sse2")]
3506    const fn test_mm_max_epi16() {
3507        let a = _mm_set1_epi16(1);
3508        let b = _mm_set1_epi16(-1);
3509        let r = _mm_max_epi16(a, b);
3510        assert_eq_m128i(r, a);
3511    }
3512
3513    #[simd_test(enable = "sse2")]
3514    const fn test_mm_max_epu8() {
3515        let a = _mm_set1_epi8(1);
3516        let b = _mm_set1_epi8(!0);
3517        let r = _mm_max_epu8(a, b);
3518        assert_eq_m128i(r, b);
3519    }
3520
3521    #[simd_test(enable = "sse2")]
3522    const fn test_mm_min_epi16() {
3523        let a = _mm_set1_epi16(1);
3524        let b = _mm_set1_epi16(-1);
3525        let r = _mm_min_epi16(a, b);
3526        assert_eq_m128i(r, b);
3527    }
3528
3529    #[simd_test(enable = "sse2")]
3530    const fn test_mm_min_epu8() {
3531        let a = _mm_set1_epi8(1);
3532        let b = _mm_set1_epi8(!0);
3533        let r = _mm_min_epu8(a, b);
3534        assert_eq_m128i(r, a);
3535    }
3536
3537    #[simd_test(enable = "sse2")]
3538    fn test_mm_mulhi_epi16() {
3539        let (a, b) = (_mm_set1_epi16(1000), _mm_set1_epi16(-1001));
3540        let r = _mm_mulhi_epi16(a, b);
3541        assert_eq_m128i(r, _mm_set1_epi16(-16));
3542    }
3543
3544    #[simd_test(enable = "sse2")]
3545    fn test_mm_mulhi_epu16() {
3546        let (a, b) = (_mm_set1_epi16(1000), _mm_set1_epi16(1001));
3547        let r = _mm_mulhi_epu16(a, b);
3548        assert_eq_m128i(r, _mm_set1_epi16(15));
3549    }
3550
3551    #[simd_test(enable = "sse2")]
3552    const fn test_mm_mullo_epi16() {
3553        let (a, b) = (_mm_set1_epi16(1000), _mm_set1_epi16(-1001));
3554        let r = _mm_mullo_epi16(a, b);
3555        assert_eq_m128i(r, _mm_set1_epi16(-17960));
3556    }
3557
3558    #[simd_test(enable = "sse2")]
3559    const fn test_mm_mul_epu32() {
3560        let a = _mm_setr_epi64x(1_000_000_000, 1 << 34);
3561        let b = _mm_setr_epi64x(1_000_000_000, 1 << 35);
3562        let r = _mm_mul_epu32(a, b);
3563        let e = _mm_setr_epi64x(1_000_000_000 * 1_000_000_000, 0);
3564        assert_eq_m128i(r, e);
3565    }
3566
3567    #[simd_test(enable = "sse2")]
3568    fn test_mm_sad_epu8() {
3569        #[rustfmt::skip]
3570        let a = _mm_setr_epi8(
3571            255u8 as i8, 254u8 as i8, 253u8 as i8, 252u8 as i8,
3572            1, 2, 3, 4,
3573            155u8 as i8, 154u8 as i8, 153u8 as i8, 152u8 as i8,
3574            1, 2, 3, 4,
3575        );
3576        let b = _mm_setr_epi8(0, 0, 0, 0, 2, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2);
3577        let r = _mm_sad_epu8(a, b);
3578        let e = _mm_setr_epi64x(1020, 614);
3579        assert_eq_m128i(r, e);
3580    }
3581
3582    #[simd_test(enable = "sse2")]
3583    const fn test_mm_sub_epi8() {
3584        let (a, b) = (_mm_set1_epi8(5), _mm_set1_epi8(6));
3585        let r = _mm_sub_epi8(a, b);
3586        assert_eq_m128i(r, _mm_set1_epi8(-1));
3587    }
3588
3589    #[simd_test(enable = "sse2")]
3590    const fn test_mm_sub_epi16() {
3591        let (a, b) = (_mm_set1_epi16(5), _mm_set1_epi16(6));
3592        let r = _mm_sub_epi16(a, b);
3593        assert_eq_m128i(r, _mm_set1_epi16(-1));
3594    }
3595
3596    #[simd_test(enable = "sse2")]
3597    const fn test_mm_sub_epi32() {
3598        let (a, b) = (_mm_set1_epi32(5), _mm_set1_epi32(6));
3599        let r = _mm_sub_epi32(a, b);
3600        assert_eq_m128i(r, _mm_set1_epi32(-1));
3601    }
3602
3603    #[simd_test(enable = "sse2")]
3604    const fn test_mm_sub_epi64() {
3605        let (a, b) = (_mm_set1_epi64x(5), _mm_set1_epi64x(6));
3606        let r = _mm_sub_epi64(a, b);
3607        assert_eq_m128i(r, _mm_set1_epi64x(-1));
3608    }
3609
3610    #[simd_test(enable = "sse2")]
3611    const fn test_mm_subs_epi8() {
3612        let (a, b) = (_mm_set1_epi8(5), _mm_set1_epi8(2));
3613        let r = _mm_subs_epi8(a, b);
3614        assert_eq_m128i(r, _mm_set1_epi8(3));
3615    }
3616
3617    #[simd_test(enable = "sse2")]
3618    fn test_mm_subs_epi8_saturate_positive() {
3619        let a = _mm_set1_epi8(0x7F);
3620        let b = _mm_set1_epi8(-1);
3621        let r = _mm_subs_epi8(a, b);
3622        assert_eq_m128i(r, a);
3623    }
3624
3625    #[simd_test(enable = "sse2")]
3626    fn test_mm_subs_epi8_saturate_negative() {
3627        let a = _mm_set1_epi8(-0x80);
3628        let b = _mm_set1_epi8(1);
3629        let r = _mm_subs_epi8(a, b);
3630        assert_eq_m128i(r, a);
3631    }
3632
3633    #[simd_test(enable = "sse2")]
3634    const fn test_mm_subs_epi16() {
3635        let (a, b) = (_mm_set1_epi16(5), _mm_set1_epi16(2));
3636        let r = _mm_subs_epi16(a, b);
3637        assert_eq_m128i(r, _mm_set1_epi16(3));
3638    }
3639
3640    #[simd_test(enable = "sse2")]
3641    fn test_mm_subs_epi16_saturate_positive() {
3642        let a = _mm_set1_epi16(0x7FFF);
3643        let b = _mm_set1_epi16(-1);
3644        let r = _mm_subs_epi16(a, b);
3645        assert_eq_m128i(r, a);
3646    }
3647
3648    #[simd_test(enable = "sse2")]
3649    fn test_mm_subs_epi16_saturate_negative() {
3650        let a = _mm_set1_epi16(-0x8000);
3651        let b = _mm_set1_epi16(1);
3652        let r = _mm_subs_epi16(a, b);
3653        assert_eq_m128i(r, a);
3654    }
3655
3656    #[simd_test(enable = "sse2")]
3657    const fn test_mm_subs_epu8() {
3658        let (a, b) = (_mm_set1_epi8(5), _mm_set1_epi8(2));
3659        let r = _mm_subs_epu8(a, b);
3660        assert_eq_m128i(r, _mm_set1_epi8(3));
3661    }
3662
3663    #[simd_test(enable = "sse2")]
3664    fn test_mm_subs_epu8_saturate() {
3665        let a = _mm_set1_epi8(0);
3666        let b = _mm_set1_epi8(1);
3667        let r = _mm_subs_epu8(a, b);
3668        assert_eq_m128i(r, a);
3669    }
3670
3671    #[simd_test(enable = "sse2")]
3672    const fn test_mm_subs_epu16() {
3673        let (a, b) = (_mm_set1_epi16(5), _mm_set1_epi16(2));
3674        let r = _mm_subs_epu16(a, b);
3675        assert_eq_m128i(r, _mm_set1_epi16(3));
3676    }
3677
3678    #[simd_test(enable = "sse2")]
3679    fn test_mm_subs_epu16_saturate() {
3680        let a = _mm_set1_epi16(0);
3681        let b = _mm_set1_epi16(1);
3682        let r = _mm_subs_epu16(a, b);
3683        assert_eq_m128i(r, a);
3684    }
3685
3686    #[simd_test(enable = "sse2")]
3687    const fn test_mm_slli_si128() {
3688        #[rustfmt::skip]
3689        let a = _mm_setr_epi8(
3690            1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
3691        );
3692        let r = _mm_slli_si128::<1>(a);
3693        let e = _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
3694        assert_eq_m128i(r, e);
3695
3696        #[rustfmt::skip]
3697        let a = _mm_setr_epi8(
3698            1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
3699        );
3700        let r = _mm_slli_si128::<15>(a);
3701        let e = _mm_setr_epi8(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
3702        assert_eq_m128i(r, e);
3703
3704        #[rustfmt::skip]
3705        let a = _mm_setr_epi8(
3706            1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
3707        );
3708        let r = _mm_slli_si128::<16>(a);
3709        assert_eq_m128i(r, _mm_set1_epi8(0));
3710    }
3711
3712    #[simd_test(enable = "sse2")]
3713    const fn test_mm_slli_epi16() {
3714        let a = _mm_setr_epi16(0xCC, -0xCC, 0xDD, -0xDD, 0xEE, -0xEE, 0xFF, -0xFF);
3715        let r = _mm_slli_epi16::<4>(a);
3716        assert_eq_m128i(
3717            r,
3718            _mm_setr_epi16(0xCC0, -0xCC0, 0xDD0, -0xDD0, 0xEE0, -0xEE0, 0xFF0, -0xFF0),
3719        );
3720        let r = _mm_slli_epi16::<16>(a);
3721        assert_eq_m128i(r, _mm_set1_epi16(0));
3722    }
3723
3724    #[simd_test(enable = "sse2")]
3725    fn test_mm_sll_epi16() {
3726        let a = _mm_setr_epi16(0xCC, -0xCC, 0xDD, -0xDD, 0xEE, -0xEE, 0xFF, -0xFF);
3727        let r = _mm_sll_epi16(a, _mm_set_epi64x(0, 4));
3728        assert_eq_m128i(
3729            r,
3730            _mm_setr_epi16(0xCC0, -0xCC0, 0xDD0, -0xDD0, 0xEE0, -0xEE0, 0xFF0, -0xFF0),
3731        );
3732        let r = _mm_sll_epi16(a, _mm_set_epi64x(4, 0));
3733        assert_eq_m128i(r, a);
3734        let r = _mm_sll_epi16(a, _mm_set_epi64x(0, 16));
3735        assert_eq_m128i(r, _mm_set1_epi16(0));
3736        let r = _mm_sll_epi16(a, _mm_set_epi64x(0, i64::MAX));
3737        assert_eq_m128i(r, _mm_set1_epi16(0));
3738    }
3739
3740    #[simd_test(enable = "sse2")]
3741    const fn test_mm_slli_epi32() {
3742        let a = _mm_setr_epi32(0xEEEE, -0xEEEE, 0xFFFF, -0xFFFF);
3743        let r = _mm_slli_epi32::<4>(a);
3744        assert_eq_m128i(r, _mm_setr_epi32(0xEEEE0, -0xEEEE0, 0xFFFF0, -0xFFFF0));
3745        let r = _mm_slli_epi32::<32>(a);
3746        assert_eq_m128i(r, _mm_set1_epi32(0));
3747    }
3748
3749    #[simd_test(enable = "sse2")]
3750    fn test_mm_sll_epi32() {
3751        let a = _mm_setr_epi32(0xEEEE, -0xEEEE, 0xFFFF, -0xFFFF);
3752        let r = _mm_sll_epi32(a, _mm_set_epi64x(0, 4));
3753        assert_eq_m128i(r, _mm_setr_epi32(0xEEEE0, -0xEEEE0, 0xFFFF0, -0xFFFF0));
3754        let r = _mm_sll_epi32(a, _mm_set_epi64x(4, 0));
3755        assert_eq_m128i(r, a);
3756        let r = _mm_sll_epi32(a, _mm_set_epi64x(0, 32));
3757        assert_eq_m128i(r, _mm_set1_epi32(0));
3758        let r = _mm_sll_epi32(a, _mm_set_epi64x(0, i64::MAX));
3759        assert_eq_m128i(r, _mm_set1_epi32(0));
3760    }
3761
3762    #[simd_test(enable = "sse2")]
3763    const fn test_mm_slli_epi64() {
3764        let a = _mm_set_epi64x(0xFFFFFFFF, -0xFFFFFFFF);
3765        let r = _mm_slli_epi64::<4>(a);
3766        assert_eq_m128i(r, _mm_set_epi64x(0xFFFFFFFF0, -0xFFFFFFFF0));
3767        let r = _mm_slli_epi64::<64>(a);
3768        assert_eq_m128i(r, _mm_set1_epi64x(0));
3769    }
3770
3771    #[simd_test(enable = "sse2")]
3772    fn test_mm_sll_epi64() {
3773        let a = _mm_set_epi64x(0xFFFFFFFF, -0xFFFFFFFF);
3774        let r = _mm_sll_epi64(a, _mm_set_epi64x(0, 4));
3775        assert_eq_m128i(r, _mm_set_epi64x(0xFFFFFFFF0, -0xFFFFFFFF0));
3776        let r = _mm_sll_epi64(a, _mm_set_epi64x(4, 0));
3777        assert_eq_m128i(r, a);
3778        let r = _mm_sll_epi64(a, _mm_set_epi64x(0, 64));
3779        assert_eq_m128i(r, _mm_set1_epi64x(0));
3780        let r = _mm_sll_epi64(a, _mm_set_epi64x(0, i64::MAX));
3781        assert_eq_m128i(r, _mm_set1_epi64x(0));
3782    }
3783
3784    #[simd_test(enable = "sse2")]
3785    const fn test_mm_srai_epi16() {
3786        let a = _mm_setr_epi16(0xCC, -0xCC, 0xDD, -0xDD, 0xEE, -0xEE, 0xFF, -0xFF);
3787        let r = _mm_srai_epi16::<4>(a);
3788        assert_eq_m128i(
3789            r,
3790            _mm_setr_epi16(0xC, -0xD, 0xD, -0xE, 0xE, -0xF, 0xF, -0x10),
3791        );
3792        let r = _mm_srai_epi16::<16>(a);
3793        assert_eq_m128i(r, _mm_setr_epi16(0, -1, 0, -1, 0, -1, 0, -1));
3794    }
3795
3796    #[simd_test(enable = "sse2")]
3797    fn test_mm_sra_epi16() {
3798        let a = _mm_setr_epi16(0xCC, -0xCC, 0xDD, -0xDD, 0xEE, -0xEE, 0xFF, -0xFF);
3799        let r = _mm_sra_epi16(a, _mm_set_epi64x(0, 4));
3800        assert_eq_m128i(
3801            r,
3802            _mm_setr_epi16(0xC, -0xD, 0xD, -0xE, 0xE, -0xF, 0xF, -0x10),
3803        );
3804        let r = _mm_sra_epi16(a, _mm_set_epi64x(4, 0));
3805        assert_eq_m128i(r, a);
3806        let r = _mm_sra_epi16(a, _mm_set_epi64x(0, 16));
3807        assert_eq_m128i(r, _mm_setr_epi16(0, -1, 0, -1, 0, -1, 0, -1));
3808        let r = _mm_sra_epi16(a, _mm_set_epi64x(0, i64::MAX));
3809        assert_eq_m128i(r, _mm_setr_epi16(0, -1, 0, -1, 0, -1, 0, -1));
3810    }
3811
3812    #[simd_test(enable = "sse2")]
3813    const fn test_mm_srai_epi32() {
3814        let a = _mm_setr_epi32(0xEEEE, -0xEEEE, 0xFFFF, -0xFFFF);
3815        let r = _mm_srai_epi32::<4>(a);
3816        assert_eq_m128i(r, _mm_setr_epi32(0xEEE, -0xEEF, 0xFFF, -0x1000));
3817        let r = _mm_srai_epi32::<32>(a);
3818        assert_eq_m128i(r, _mm_setr_epi32(0, -1, 0, -1));
3819    }
3820
3821    #[simd_test(enable = "sse2")]
3822    fn test_mm_sra_epi32() {
3823        let a = _mm_setr_epi32(0xEEEE, -0xEEEE, 0xFFFF, -0xFFFF);
3824        let r = _mm_sra_epi32(a, _mm_set_epi64x(0, 4));
3825        assert_eq_m128i(r, _mm_setr_epi32(0xEEE, -0xEEF, 0xFFF, -0x1000));
3826        let r = _mm_sra_epi32(a, _mm_set_epi64x(4, 0));
3827        assert_eq_m128i(r, a);
3828        let r = _mm_sra_epi32(a, _mm_set_epi64x(0, 32));
3829        assert_eq_m128i(r, _mm_setr_epi32(0, -1, 0, -1));
3830        let r = _mm_sra_epi32(a, _mm_set_epi64x(0, i64::MAX));
3831        assert_eq_m128i(r, _mm_setr_epi32(0, -1, 0, -1));
3832    }
3833
3834    #[simd_test(enable = "sse2")]
3835    const fn test_mm_srli_si128() {
3836        #[rustfmt::skip]
3837        let a = _mm_setr_epi8(
3838            1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
3839        );
3840        let r = _mm_srli_si128::<1>(a);
3841        #[rustfmt::skip]
3842        let e = _mm_setr_epi8(
3843            2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0,
3844        );
3845        assert_eq_m128i(r, e);
3846
3847        #[rustfmt::skip]
3848        let a = _mm_setr_epi8(
3849            1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
3850        );
3851        let r = _mm_srli_si128::<15>(a);
3852        let e = _mm_setr_epi8(16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
3853        assert_eq_m128i(r, e);
3854
3855        #[rustfmt::skip]
3856        let a = _mm_setr_epi8(
3857            1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
3858        );
3859        let r = _mm_srli_si128::<16>(a);
3860        assert_eq_m128i(r, _mm_set1_epi8(0));
3861    }
3862
3863    #[simd_test(enable = "sse2")]
3864    const fn test_mm_srli_epi16() {
3865        let a = _mm_setr_epi16(0xCC, -0xCC, 0xDD, -0xDD, 0xEE, -0xEE, 0xFF, -0xFF);
3866        let r = _mm_srli_epi16::<4>(a);
3867        assert_eq_m128i(
3868            r,
3869            _mm_setr_epi16(0xC, 0xFF3, 0xD, 0xFF2, 0xE, 0xFF1, 0xF, 0xFF0),
3870        );
3871        let r = _mm_srli_epi16::<16>(a);
3872        assert_eq_m128i(r, _mm_set1_epi16(0));
3873    }
3874
3875    #[simd_test(enable = "sse2")]
3876    fn test_mm_srl_epi16() {
3877        let a = _mm_setr_epi16(0xCC, -0xCC, 0xDD, -0xDD, 0xEE, -0xEE, 0xFF, -0xFF);
3878        let r = _mm_srl_epi16(a, _mm_set_epi64x(0, 4));
3879        assert_eq_m128i(
3880            r,
3881            _mm_setr_epi16(0xC, 0xFF3, 0xD, 0xFF2, 0xE, 0xFF1, 0xF, 0xFF0),
3882        );
3883        let r = _mm_srl_epi16(a, _mm_set_epi64x(4, 0));
3884        assert_eq_m128i(r, a);
3885        let r = _mm_srl_epi16(a, _mm_set_epi64x(0, 16));
3886        assert_eq_m128i(r, _mm_set1_epi16(0));
3887        let r = _mm_srl_epi16(a, _mm_set_epi64x(0, i64::MAX));
3888        assert_eq_m128i(r, _mm_set1_epi16(0));
3889    }
3890
3891    #[simd_test(enable = "sse2")]
3892    const fn test_mm_srli_epi32() {
3893        let a = _mm_setr_epi32(0xEEEE, -0xEEEE, 0xFFFF, -0xFFFF);
3894        let r = _mm_srli_epi32::<4>(a);
3895        assert_eq_m128i(r, _mm_setr_epi32(0xEEE, 0xFFFF111, 0xFFF, 0xFFFF000));
3896        let r = _mm_srli_epi32::<32>(a);
3897        assert_eq_m128i(r, _mm_set1_epi32(0));
3898    }
3899
3900    #[simd_test(enable = "sse2")]
3901    fn test_mm_srl_epi32() {
3902        let a = _mm_setr_epi32(0xEEEE, -0xEEEE, 0xFFFF, -0xFFFF);
3903        let r = _mm_srl_epi32(a, _mm_set_epi64x(0, 4));
3904        assert_eq_m128i(r, _mm_setr_epi32(0xEEE, 0xFFFF111, 0xFFF, 0xFFFF000));
3905        let r = _mm_srl_epi32(a, _mm_set_epi64x(4, 0));
3906        assert_eq_m128i(r, a);
3907        let r = _mm_srl_epi32(a, _mm_set_epi64x(0, 32));
3908        assert_eq_m128i(r, _mm_set1_epi32(0));
3909        let r = _mm_srl_epi32(a, _mm_set_epi64x(0, i64::MAX));
3910        assert_eq_m128i(r, _mm_set1_epi32(0));
3911    }
3912
3913    #[simd_test(enable = "sse2")]
3914    const fn test_mm_srli_epi64() {
3915        let a = _mm_set_epi64x(0xFFFFFFFF, -0xFFFFFFFF);
3916        let r = _mm_srli_epi64::<4>(a);
3917        assert_eq_m128i(r, _mm_set_epi64x(0xFFFFFFF, 0xFFFFFFFF0000000));
3918        let r = _mm_srli_epi64::<64>(a);
3919        assert_eq_m128i(r, _mm_set1_epi64x(0));
3920    }
3921
3922    #[simd_test(enable = "sse2")]
3923    fn test_mm_srl_epi64() {
3924        let a = _mm_set_epi64x(0xFFFFFFFF, -0xFFFFFFFF);
3925        let r = _mm_srl_epi64(a, _mm_set_epi64x(0, 4));
3926        assert_eq_m128i(r, _mm_set_epi64x(0xFFFFFFF, 0xFFFFFFFF0000000));
3927        let r = _mm_srl_epi64(a, _mm_set_epi64x(4, 0));
3928        assert_eq_m128i(r, a);
3929        let r = _mm_srl_epi64(a, _mm_set_epi64x(0, 64));
3930        assert_eq_m128i(r, _mm_set1_epi64x(0));
3931        let r = _mm_srl_epi64(a, _mm_set_epi64x(0, i64::MAX));
3932        assert_eq_m128i(r, _mm_set1_epi64x(0));
3933    }
3934
3935    #[simd_test(enable = "sse2")]
3936    const fn test_mm_and_si128() {
3937        let a = _mm_set1_epi8(5);
3938        let b = _mm_set1_epi8(3);
3939        let r = _mm_and_si128(a, b);
3940        assert_eq_m128i(r, _mm_set1_epi8(1));
3941    }
3942
3943    #[simd_test(enable = "sse2")]
3944    const fn test_mm_andnot_si128() {
3945        let a = _mm_set1_epi8(5);
3946        let b = _mm_set1_epi8(3);
3947        let r = _mm_andnot_si128(a, b);
3948        assert_eq_m128i(r, _mm_set1_epi8(2));
3949    }
3950
3951    #[simd_test(enable = "sse2")]
3952    const fn test_mm_or_si128() {
3953        let a = _mm_set1_epi8(5);
3954        let b = _mm_set1_epi8(3);
3955        let r = _mm_or_si128(a, b);
3956        assert_eq_m128i(r, _mm_set1_epi8(7));
3957    }
3958
3959    #[simd_test(enable = "sse2")]
3960    const fn test_mm_xor_si128() {
3961        let a = _mm_set1_epi8(5);
3962        let b = _mm_set1_epi8(3);
3963        let r = _mm_xor_si128(a, b);
3964        assert_eq_m128i(r, _mm_set1_epi8(6));
3965    }
3966
3967    #[simd_test(enable = "sse2")]
3968    const fn test_mm_cmpeq_epi8() {
3969        let a = _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
3970        let b = _mm_setr_epi8(15, 14, 2, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
3971        let r = _mm_cmpeq_epi8(a, b);
3972        #[rustfmt::skip]
3973        assert_eq_m128i(
3974            r,
3975            _mm_setr_epi8(
3976                0, 0, 0xFFu8 as i8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
3977            )
3978        );
3979    }
3980
3981    #[simd_test(enable = "sse2")]
3982    const fn test_mm_cmpeq_epi16() {
3983        let a = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
3984        let b = _mm_setr_epi16(7, 6, 2, 4, 3, 2, 1, 0);
3985        let r = _mm_cmpeq_epi16(a, b);
3986        assert_eq_m128i(r, _mm_setr_epi16(0, 0, !0, 0, 0, 0, 0, 0));
3987    }
3988
3989    #[simd_test(enable = "sse2")]
3990    const fn test_mm_cmpeq_epi32() {
3991        let a = _mm_setr_epi32(0, 1, 2, 3);
3992        let b = _mm_setr_epi32(3, 2, 2, 0);
3993        let r = _mm_cmpeq_epi32(a, b);
3994        assert_eq_m128i(r, _mm_setr_epi32(0, 0, !0, 0));
3995    }
3996
3997    #[simd_test(enable = "sse2")]
3998    const fn test_mm_cmpgt_epi8() {
3999        let a = _mm_set_epi8(5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
4000        let b = _mm_set1_epi8(0);
4001        let r = _mm_cmpgt_epi8(a, b);
4002        let e = _mm_set_epi8(!0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
4003        assert_eq_m128i(r, e);
4004    }
4005
4006    #[simd_test(enable = "sse2")]
4007    const fn test_mm_cmpgt_epi16() {
4008        let a = _mm_set_epi16(5, 0, 0, 0, 0, 0, 0, 0);
4009        let b = _mm_set1_epi16(0);
4010        let r = _mm_cmpgt_epi16(a, b);
4011        let e = _mm_set_epi16(!0, 0, 0, 0, 0, 0, 0, 0);
4012        assert_eq_m128i(r, e);
4013    }
4014
4015    #[simd_test(enable = "sse2")]
4016    const fn test_mm_cmpgt_epi32() {
4017        let a = _mm_set_epi32(5, 0, 0, 0);
4018        let b = _mm_set1_epi32(0);
4019        let r = _mm_cmpgt_epi32(a, b);
4020        assert_eq_m128i(r, _mm_set_epi32(!0, 0, 0, 0));
4021    }
4022
4023    #[simd_test(enable = "sse2")]
4024    const fn test_mm_cmplt_epi8() {
4025        let a = _mm_set1_epi8(0);
4026        let b = _mm_set_epi8(5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
4027        let r = _mm_cmplt_epi8(a, b);
4028        let e = _mm_set_epi8(!0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
4029        assert_eq_m128i(r, e);
4030    }
4031
4032    #[simd_test(enable = "sse2")]
4033    const fn test_mm_cmplt_epi16() {
4034        let a = _mm_set1_epi16(0);
4035        let b = _mm_set_epi16(5, 0, 0, 0, 0, 0, 0, 0);
4036        let r = _mm_cmplt_epi16(a, b);
4037        let e = _mm_set_epi16(!0, 0, 0, 0, 0, 0, 0, 0);
4038        assert_eq_m128i(r, e);
4039    }
4040
4041    #[simd_test(enable = "sse2")]
4042    const fn test_mm_cmplt_epi32() {
4043        let a = _mm_set1_epi32(0);
4044        let b = _mm_set_epi32(5, 0, 0, 0);
4045        let r = _mm_cmplt_epi32(a, b);
4046        assert_eq_m128i(r, _mm_set_epi32(!0, 0, 0, 0));
4047    }
4048
4049    #[simd_test(enable = "sse2")]
4050    const fn test_mm_cvtepi32_pd() {
4051        let a = _mm_set_epi32(35, 25, 15, 5);
4052        let r = _mm_cvtepi32_pd(a);
4053        assert_eq_m128d(r, _mm_setr_pd(5.0, 15.0));
4054    }
4055
4056    #[simd_test(enable = "sse2")]
4057    const fn test_mm_cvtsi32_sd() {
4058        let a = _mm_set1_pd(3.5);
4059        let r = _mm_cvtsi32_sd(a, 5);
4060        assert_eq_m128d(r, _mm_setr_pd(5.0, 3.5));
4061    }
4062
4063    #[simd_test(enable = "sse2")]
4064    const fn test_mm_cvtepi32_ps() {
4065        let a = _mm_setr_epi32(1, 2, 3, 4);
4066        let r = _mm_cvtepi32_ps(a);
4067        assert_eq_m128(r, _mm_setr_ps(1.0, 2.0, 3.0, 4.0));
4068    }
4069
4070    #[simd_test(enable = "sse2")]
4071    fn test_mm_cvtps_epi32() {
4072        let a = _mm_setr_ps(1.0, 2.0, 3.0, 4.0);
4073        let r = _mm_cvtps_epi32(a);
4074        assert_eq_m128i(r, _mm_setr_epi32(1, 2, 3, 4));
4075    }
4076
4077    #[simd_test(enable = "sse2")]
4078    const fn test_mm_cvtsi32_si128() {
4079        let r = _mm_cvtsi32_si128(5);
4080        assert_eq_m128i(r, _mm_setr_epi32(5, 0, 0, 0));
4081    }
4082
4083    #[simd_test(enable = "sse2")]
4084    const fn test_mm_cvtsi128_si32() {
4085        let r = _mm_cvtsi128_si32(_mm_setr_epi32(5, 0, 0, 0));
4086        assert_eq!(r, 5);
4087    }
4088
4089    #[simd_test(enable = "sse2")]
4090    const fn test_mm_set_epi64x() {
4091        let r = _mm_set_epi64x(0, 1);
4092        assert_eq_m128i(r, _mm_setr_epi64x(1, 0));
4093    }
4094
4095    #[simd_test(enable = "sse2")]
4096    const fn test_mm_set_epi32() {
4097        let r = _mm_set_epi32(0, 1, 2, 3);
4098        assert_eq_m128i(r, _mm_setr_epi32(3, 2, 1, 0));
4099    }
4100
4101    #[simd_test(enable = "sse2")]
4102    const fn test_mm_set_epi16() {
4103        let r = _mm_set_epi16(0, 1, 2, 3, 4, 5, 6, 7);
4104        assert_eq_m128i(r, _mm_setr_epi16(7, 6, 5, 4, 3, 2, 1, 0));
4105    }
4106
4107    #[simd_test(enable = "sse2")]
4108    const fn test_mm_set_epi8() {
4109        #[rustfmt::skip]
4110        let r = _mm_set_epi8(
4111            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
4112        );
4113        #[rustfmt::skip]
4114        let e = _mm_setr_epi8(
4115            15, 14, 13, 12, 11, 10, 9, 8,
4116            7, 6, 5, 4, 3, 2, 1, 0,
4117        );
4118        assert_eq_m128i(r, e);
4119    }
4120
4121    #[simd_test(enable = "sse2")]
4122    const fn test_mm_set1_epi64x() {
4123        let r = _mm_set1_epi64x(1);
4124        assert_eq_m128i(r, _mm_set1_epi64x(1));
4125    }
4126
4127    #[simd_test(enable = "sse2")]
4128    const fn test_mm_set1_epi32() {
4129        let r = _mm_set1_epi32(1);
4130        assert_eq_m128i(r, _mm_set1_epi32(1));
4131    }
4132
4133    #[simd_test(enable = "sse2")]
4134    const fn test_mm_set1_epi16() {
4135        let r = _mm_set1_epi16(1);
4136        assert_eq_m128i(r, _mm_set1_epi16(1));
4137    }
4138
4139    #[simd_test(enable = "sse2")]
4140    const fn test_mm_set1_epi8() {
4141        let r = _mm_set1_epi8(1);
4142        assert_eq_m128i(r, _mm_set1_epi8(1));
4143    }
4144
4145    #[simd_test(enable = "sse2")]
4146    const fn test_mm_setr_epi32() {
4147        let r = _mm_setr_epi32(0, 1, 2, 3);
4148        assert_eq_m128i(r, _mm_setr_epi32(0, 1, 2, 3));
4149    }
4150
4151    #[simd_test(enable = "sse2")]
4152    const fn test_mm_setr_epi16() {
4153        let r = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
4154        assert_eq_m128i(r, _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7));
4155    }
4156
4157    #[simd_test(enable = "sse2")]
4158    const fn test_mm_setr_epi8() {
4159        #[rustfmt::skip]
4160        let r = _mm_setr_epi8(
4161            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
4162        );
4163        #[rustfmt::skip]
4164        let e = _mm_setr_epi8(
4165            0, 1, 2, 3, 4, 5, 6, 7,
4166            8, 9, 10, 11, 12, 13, 14, 15,
4167        );
4168        assert_eq_m128i(r, e);
4169    }
4170
4171    #[simd_test(enable = "sse2")]
4172    const fn test_mm_setzero_si128() {
4173        let r = _mm_setzero_si128();
4174        assert_eq_m128i(r, _mm_set1_epi64x(0));
4175    }
4176
4177    #[simd_test(enable = "sse2")]
4178    const fn test_mm_loadl_epi64() {
4179        let a = _mm_setr_epi64x(6, 5);
4180        let r = unsafe { _mm_loadl_epi64(ptr::addr_of!(a)) };
4181        assert_eq_m128i(r, _mm_setr_epi64x(6, 0));
4182    }
4183
4184    #[simd_test(enable = "sse2")]
4185    const fn test_mm_load_si128() {
4186        let a = _mm_set_epi64x(5, 6);
4187        let r = unsafe { _mm_load_si128(ptr::addr_of!(a) as *const _) };
4188        assert_eq_m128i(a, r);
4189    }
4190
4191    #[simd_test(enable = "sse2")]
4192    const fn test_mm_loadu_si128() {
4193        let a = _mm_set_epi64x(5, 6);
4194        let r = unsafe { _mm_loadu_si128(ptr::addr_of!(a) as *const _) };
4195        assert_eq_m128i(a, r);
4196    }
4197
4198    #[simd_test(enable = "sse2")]
4199    // Miri cannot support this until it is clear how it fits in the Rust memory model
4200    // (non-temporal store)
4201    #[cfg_attr(miri, ignore)]
4202    fn test_mm_maskmoveu_si128() {
4203        let a = _mm_set1_epi8(9);
4204        #[rustfmt::skip]
4205        let mask = _mm_set_epi8(
4206            0, 0, 0x80u8 as i8, 0, 0, 0, 0, 0,
4207            0, 0, 0, 0, 0, 0, 0, 0,
4208        );
4209        let mut r = _mm_set1_epi8(0);
4210        unsafe {
4211            _mm_maskmoveu_si128(a, mask, ptr::addr_of_mut!(r) as *mut i8);
4212        }
4213        _mm_sfence();
4214        let e = _mm_set_epi8(0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
4215        assert_eq_m128i(r, e);
4216    }
4217
4218    #[simd_test(enable = "sse2")]
4219    const fn test_mm_store_si128() {
4220        let a = _mm_set1_epi8(9);
4221        let mut r = _mm_set1_epi8(0);
4222        unsafe {
4223            _mm_store_si128(&mut r, a);
4224        }
4225        assert_eq_m128i(r, a);
4226    }
4227
4228    #[simd_test(enable = "sse2")]
4229    const fn test_mm_storeu_si128() {
4230        let a = _mm_set1_epi8(9);
4231        let mut r = _mm_set1_epi8(0);
4232        unsafe {
4233            _mm_storeu_si128(&mut r, a);
4234        }
4235        assert_eq_m128i(r, a);
4236    }
4237
4238    #[simd_test(enable = "sse2")]
4239    const fn test_mm_storel_epi64() {
4240        let a = _mm_setr_epi64x(2, 9);
4241        let mut r = _mm_set1_epi8(0);
4242        unsafe {
4243            _mm_storel_epi64(&mut r, a);
4244        }
4245        assert_eq_m128i(r, _mm_setr_epi64x(2, 0));
4246    }
4247
4248    #[simd_test(enable = "sse2")]
4249    // Miri cannot support this until it is clear how it fits in the Rust memory model
4250    // (non-temporal store)
4251    #[cfg_attr(miri, ignore)]
4252    fn test_mm_stream_si128() {
4253        let a = _mm_setr_epi32(1, 2, 3, 4);
4254        let mut r = _mm_undefined_si128();
4255        unsafe {
4256            _mm_stream_si128(ptr::addr_of_mut!(r), a);
4257        }
4258        _mm_sfence();
4259        assert_eq_m128i(r, a);
4260    }
4261
4262    #[simd_test(enable = "sse2")]
4263    // Miri cannot support this until it is clear how it fits in the Rust memory model
4264    // (non-temporal store)
4265    #[cfg_attr(miri, ignore)]
4266    fn test_mm_stream_si32() {
4267        let a: i32 = 7;
4268        let mut mem = boxed::Box::<i32>::new(-1);
4269        unsafe {
4270            _mm_stream_si32(ptr::addr_of_mut!(*mem), a);
4271        }
4272        _mm_sfence();
4273        assert_eq!(a, *mem);
4274    }
4275
4276    #[simd_test(enable = "sse2")]
4277    const fn test_mm_move_epi64() {
4278        let a = _mm_setr_epi64x(5, 6);
4279        let r = _mm_move_epi64(a);
4280        assert_eq_m128i(r, _mm_setr_epi64x(5, 0));
4281    }
4282
4283    #[simd_test(enable = "sse2")]
4284    fn test_mm_packs_epi16() {
4285        let a = _mm_setr_epi16(0x80, -0x81, 0, 0, 0, 0, 0, 0);
4286        let b = _mm_setr_epi16(0, 0, 0, 0, 0, 0, -0x81, 0x80);
4287        let r = _mm_packs_epi16(a, b);
4288        #[rustfmt::skip]
4289        assert_eq_m128i(
4290            r,
4291            _mm_setr_epi8(
4292                0x7F, -0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0x80, 0x7F
4293            )
4294        );
4295    }
4296
4297    #[simd_test(enable = "sse2")]
4298    fn test_mm_packs_epi32() {
4299        let a = _mm_setr_epi32(0x8000, -0x8001, 0, 0);
4300        let b = _mm_setr_epi32(0, 0, -0x8001, 0x8000);
4301        let r = _mm_packs_epi32(a, b);
4302        assert_eq_m128i(
4303            r,
4304            _mm_setr_epi16(0x7FFF, -0x8000, 0, 0, 0, 0, -0x8000, 0x7FFF),
4305        );
4306    }
4307
4308    #[simd_test(enable = "sse2")]
4309    fn test_mm_packus_epi16() {
4310        let a = _mm_setr_epi16(0x100, -1, 0, 0, 0, 0, 0, 0);
4311        let b = _mm_setr_epi16(0, 0, 0, 0, 0, 0, -1, 0x100);
4312        let r = _mm_packus_epi16(a, b);
4313        assert_eq_m128i(
4314            r,
4315            _mm_setr_epi8(!0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, !0),
4316        );
4317    }
4318
4319    #[simd_test(enable = "sse2")]
4320    const fn test_mm_extract_epi16() {
4321        let a = _mm_setr_epi16(-1, 1, 2, 3, 4, 5, 6, 7);
4322        let r1 = _mm_extract_epi16::<0>(a);
4323        let r2 = _mm_extract_epi16::<3>(a);
4324        assert_eq!(r1, 0xFFFF);
4325        assert_eq!(r2, 3);
4326    }
4327
4328    #[simd_test(enable = "sse2")]
4329    const fn test_mm_insert_epi16() {
4330        let a = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
4331        let r = _mm_insert_epi16::<0>(a, 9);
4332        let e = _mm_setr_epi16(9, 1, 2, 3, 4, 5, 6, 7);
4333        assert_eq_m128i(r, e);
4334    }
4335
4336    #[simd_test(enable = "sse2")]
4337    const fn test_mm_movemask_epi8() {
4338        #[rustfmt::skip]
4339        let a = _mm_setr_epi8(
4340            0b1000_0000u8 as i8, 0b0, 0b1000_0000u8 as i8, 0b01,
4341            0b0101, 0b1111_0000u8 as i8, 0, 0,
4342            0, 0b1011_0101u8 as i8, 0b1111_0000u8 as i8, 0b0101,
4343            0b01, 0b1000_0000u8 as i8, 0b0, 0b1000_0000u8 as i8,
4344        );
4345        let r = _mm_movemask_epi8(a);
4346        assert_eq!(r, 0b10100110_00100101);
4347    }
4348
4349    #[simd_test(enable = "sse2")]
4350    const fn test_mm_shuffle_epi32() {
4351        let a = _mm_setr_epi32(5, 10, 15, 20);
4352        let r = _mm_shuffle_epi32::<0b00_01_01_11>(a);
4353        let e = _mm_setr_epi32(20, 10, 10, 5);
4354        assert_eq_m128i(r, e);
4355    }
4356
4357    #[simd_test(enable = "sse2")]
4358    const fn test_mm_shufflehi_epi16() {
4359        let a = _mm_setr_epi16(1, 2, 3, 4, 5, 10, 15, 20);
4360        let r = _mm_shufflehi_epi16::<0b00_01_01_11>(a);
4361        let e = _mm_setr_epi16(1, 2, 3, 4, 20, 10, 10, 5);
4362        assert_eq_m128i(r, e);
4363    }
4364
4365    #[simd_test(enable = "sse2")]
4366    const fn test_mm_shufflelo_epi16() {
4367        let a = _mm_setr_epi16(5, 10, 15, 20, 1, 2, 3, 4);
4368        let r = _mm_shufflelo_epi16::<0b00_01_01_11>(a);
4369        let e = _mm_setr_epi16(20, 10, 10, 5, 1, 2, 3, 4);
4370        assert_eq_m128i(r, e);
4371    }
4372
4373    #[simd_test(enable = "sse2")]
4374    const fn test_mm_unpackhi_epi8() {
4375        #[rustfmt::skip]
4376        let a = _mm_setr_epi8(
4377            0, 1, 2, 3, 4, 5, 6, 7,
4378            8, 9, 10, 11, 12, 13, 14, 15,
4379        );
4380        #[rustfmt::skip]
4381        let b = _mm_setr_epi8(
4382            16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
4383        );
4384        let r = _mm_unpackhi_epi8(a, b);
4385        #[rustfmt::skip]
4386        let e = _mm_setr_epi8(
4387            8, 24, 9, 25, 10, 26, 11, 27, 12, 28, 13, 29, 14, 30, 15, 31,
4388        );
4389        assert_eq_m128i(r, e);
4390    }
4391
4392    #[simd_test(enable = "sse2")]
4393    const fn test_mm_unpackhi_epi16() {
4394        let a = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
4395        let b = _mm_setr_epi16(8, 9, 10, 11, 12, 13, 14, 15);
4396        let r = _mm_unpackhi_epi16(a, b);
4397        let e = _mm_setr_epi16(4, 12, 5, 13, 6, 14, 7, 15);
4398        assert_eq_m128i(r, e);
4399    }
4400
4401    #[simd_test(enable = "sse2")]
4402    const fn test_mm_unpackhi_epi32() {
4403        let a = _mm_setr_epi32(0, 1, 2, 3);
4404        let b = _mm_setr_epi32(4, 5, 6, 7);
4405        let r = _mm_unpackhi_epi32(a, b);
4406        let e = _mm_setr_epi32(2, 6, 3, 7);
4407        assert_eq_m128i(r, e);
4408    }
4409
4410    #[simd_test(enable = "sse2")]
4411    const fn test_mm_unpackhi_epi64() {
4412        let a = _mm_setr_epi64x(0, 1);
4413        let b = _mm_setr_epi64x(2, 3);
4414        let r = _mm_unpackhi_epi64(a, b);
4415        let e = _mm_setr_epi64x(1, 3);
4416        assert_eq_m128i(r, e);
4417    }
4418
4419    #[simd_test(enable = "sse2")]
4420    const fn test_mm_unpacklo_epi8() {
4421        #[rustfmt::skip]
4422        let a = _mm_setr_epi8(
4423            0, 1, 2, 3, 4, 5, 6, 7,
4424            8, 9, 10, 11, 12, 13, 14, 15,
4425        );
4426        #[rustfmt::skip]
4427        let b = _mm_setr_epi8(
4428            16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
4429        );
4430        let r = _mm_unpacklo_epi8(a, b);
4431        #[rustfmt::skip]
4432        let e = _mm_setr_epi8(
4433            0, 16, 1, 17, 2, 18, 3, 19,
4434            4, 20, 5, 21, 6, 22, 7, 23,
4435        );
4436        assert_eq_m128i(r, e);
4437    }
4438
4439    #[simd_test(enable = "sse2")]
4440    const fn test_mm_unpacklo_epi16() {
4441        let a = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
4442        let b = _mm_setr_epi16(8, 9, 10, 11, 12, 13, 14, 15);
4443        let r = _mm_unpacklo_epi16(a, b);
4444        let e = _mm_setr_epi16(0, 8, 1, 9, 2, 10, 3, 11);
4445        assert_eq_m128i(r, e);
4446    }
4447
4448    #[simd_test(enable = "sse2")]
4449    const fn test_mm_unpacklo_epi32() {
4450        let a = _mm_setr_epi32(0, 1, 2, 3);
4451        let b = _mm_setr_epi32(4, 5, 6, 7);
4452        let r = _mm_unpacklo_epi32(a, b);
4453        let e = _mm_setr_epi32(0, 4, 1, 5);
4454        assert_eq_m128i(r, e);
4455    }
4456
4457    #[simd_test(enable = "sse2")]
4458    const fn test_mm_unpacklo_epi64() {
4459        let a = _mm_setr_epi64x(0, 1);
4460        let b = _mm_setr_epi64x(2, 3);
4461        let r = _mm_unpacklo_epi64(a, b);
4462        let e = _mm_setr_epi64x(0, 2);
4463        assert_eq_m128i(r, e);
4464    }
4465
4466    #[simd_test(enable = "sse2")]
4467    const fn test_mm_add_sd() {
4468        let a = _mm_setr_pd(1.0, 2.0);
4469        let b = _mm_setr_pd(5.0, 10.0);
4470        let r = _mm_add_sd(a, b);
4471        assert_eq_m128d(r, _mm_setr_pd(6.0, 2.0));
4472    }
4473
4474    #[simd_test(enable = "sse2")]
4475    const fn test_mm_add_pd() {
4476        let a = _mm_setr_pd(1.0, 2.0);
4477        let b = _mm_setr_pd(5.0, 10.0);
4478        let r = _mm_add_pd(a, b);
4479        assert_eq_m128d(r, _mm_setr_pd(6.0, 12.0));
4480    }
4481
4482    #[simd_test(enable = "sse2")]
4483    const fn test_mm_div_sd() {
4484        let a = _mm_setr_pd(1.0, 2.0);
4485        let b = _mm_setr_pd(5.0, 10.0);
4486        let r = _mm_div_sd(a, b);
4487        assert_eq_m128d(r, _mm_setr_pd(0.2, 2.0));
4488    }
4489
4490    #[simd_test(enable = "sse2")]
4491    const fn test_mm_div_pd() {
4492        let a = _mm_setr_pd(1.0, 2.0);
4493        let b = _mm_setr_pd(5.0, 10.0);
4494        let r = _mm_div_pd(a, b);
4495        assert_eq_m128d(r, _mm_setr_pd(0.2, 0.2));
4496    }
4497
4498    #[simd_test(enable = "sse2")]
4499    fn test_mm_max_sd() {
4500        let a = _mm_setr_pd(1.0, 2.0);
4501        let b = _mm_setr_pd(5.0, 10.0);
4502        let r = _mm_max_sd(a, b);
4503        assert_eq_m128d(r, _mm_setr_pd(5.0, 2.0));
4504    }
4505
4506    #[simd_test(enable = "sse2")]
4507    fn test_mm_max_pd() {
4508        let a = _mm_setr_pd(1.0, 2.0);
4509        let b = _mm_setr_pd(5.0, 10.0);
4510        let r = _mm_max_pd(a, b);
4511        assert_eq_m128d(r, _mm_setr_pd(5.0, 10.0));
4512
4513        // Check SSE(2)-specific semantics for -0.0 handling.
4514        let a = _mm_setr_pd(-0.0, 0.0);
4515        let b = _mm_setr_pd(0.0, 0.0);
4516        // Cast to __m128i to compare exact bit patterns
4517        let r1 = _mm_castpd_si128(_mm_max_pd(a, b));
4518        let r2 = _mm_castpd_si128(_mm_max_pd(b, a));
4519        let a = _mm_castpd_si128(a);
4520        let b = _mm_castpd_si128(b);
4521        assert_eq_m128i(r1, b);
4522        assert_eq_m128i(r2, a);
4523        assert_ne!(a.as_u8x16(), b.as_u8x16()); // sanity check that -0.0 is actually present
4524    }
4525
4526    #[simd_test(enable = "sse2")]
4527    fn test_mm_min_sd() {
4528        let a = _mm_setr_pd(1.0, 2.0);
4529        let b = _mm_setr_pd(5.0, 10.0);
4530        let r = _mm_min_sd(a, b);
4531        assert_eq_m128d(r, _mm_setr_pd(1.0, 2.0));
4532    }
4533
4534    #[simd_test(enable = "sse2")]
4535    fn test_mm_min_pd() {
4536        let a = _mm_setr_pd(1.0, 2.0);
4537        let b = _mm_setr_pd(5.0, 10.0);
4538        let r = _mm_min_pd(a, b);
4539        assert_eq_m128d(r, _mm_setr_pd(1.0, 2.0));
4540
4541        // Check SSE(2)-specific semantics for -0.0 handling.
4542        let a = _mm_setr_pd(-0.0, 0.0);
4543        let b = _mm_setr_pd(0.0, 0.0);
4544        // Cast to __m128i to compare exact bit patterns
4545        let r1 = _mm_castpd_si128(_mm_min_pd(a, b));
4546        let r2 = _mm_castpd_si128(_mm_min_pd(b, a));
4547        let a = _mm_castpd_si128(a);
4548        let b = _mm_castpd_si128(b);
4549        assert_eq_m128i(r1, b);
4550        assert_eq_m128i(r2, a);
4551        assert_ne!(a.as_u8x16(), b.as_u8x16()); // sanity check that -0.0 is actually present
4552    }
4553
4554    #[simd_test(enable = "sse2")]
4555    const fn test_mm_mul_sd() {
4556        let a = _mm_setr_pd(1.0, 2.0);
4557        let b = _mm_setr_pd(5.0, 10.0);
4558        let r = _mm_mul_sd(a, b);
4559        assert_eq_m128d(r, _mm_setr_pd(5.0, 2.0));
4560    }
4561
4562    #[simd_test(enable = "sse2")]
4563    const fn test_mm_mul_pd() {
4564        let a = _mm_setr_pd(1.0, 2.0);
4565        let b = _mm_setr_pd(5.0, 10.0);
4566        let r = _mm_mul_pd(a, b);
4567        assert_eq_m128d(r, _mm_setr_pd(5.0, 20.0));
4568    }
4569
4570    #[simd_test(enable = "sse2")]
4571    fn test_mm_sqrt_sd() {
4572        let a = _mm_setr_pd(1.0, 2.0);
4573        let b = _mm_setr_pd(5.0, 10.0);
4574        let r = _mm_sqrt_sd(a, b);
4575        assert_eq_m128d(r, _mm_setr_pd(5.0f64.sqrt(), 2.0));
4576    }
4577
4578    #[simd_test(enable = "sse2")]
4579    fn test_mm_sqrt_pd() {
4580        let r = _mm_sqrt_pd(_mm_setr_pd(1.0, 2.0));
4581        assert_eq_m128d(r, _mm_setr_pd(1.0f64.sqrt(), 2.0f64.sqrt()));
4582    }
4583
4584    #[simd_test(enable = "sse2")]
4585    const fn test_mm_sub_sd() {
4586        let a = _mm_setr_pd(1.0, 2.0);
4587        let b = _mm_setr_pd(5.0, 10.0);
4588        let r = _mm_sub_sd(a, b);
4589        assert_eq_m128d(r, _mm_setr_pd(-4.0, 2.0));
4590    }
4591
4592    #[simd_test(enable = "sse2")]
4593    const fn test_mm_sub_pd() {
4594        let a = _mm_setr_pd(1.0, 2.0);
4595        let b = _mm_setr_pd(5.0, 10.0);
4596        let r = _mm_sub_pd(a, b);
4597        assert_eq_m128d(r, _mm_setr_pd(-4.0, -8.0));
4598    }
4599
4600    #[simd_test(enable = "sse2")]
4601    const fn test_mm_and_pd() {
4602        let a = f64x2::from_bits(u64x2::splat(5)).as_m128d();
4603        let b = f64x2::from_bits(u64x2::splat(3)).as_m128d();
4604        let r = _mm_and_pd(a, b);
4605        let e = f64x2::from_bits(u64x2::splat(1)).as_m128d();
4606        assert_eq_m128d(r, e);
4607    }
4608
4609    #[simd_test(enable = "sse2")]
4610    const fn test_mm_andnot_pd() {
4611        let a = f64x2::from_bits(u64x2::splat(5)).as_m128d();
4612        let b = f64x2::from_bits(u64x2::splat(3)).as_m128d();
4613        let r = _mm_andnot_pd(a, b);
4614        let e = f64x2::from_bits(u64x2::splat(2)).as_m128d();
4615        assert_eq_m128d(r, e);
4616    }
4617
4618    #[simd_test(enable = "sse2")]
4619    const fn test_mm_or_pd() {
4620        let a = f64x2::from_bits(u64x2::splat(5)).as_m128d();
4621        let b = f64x2::from_bits(u64x2::splat(3)).as_m128d();
4622        let r = _mm_or_pd(a, b);
4623        let e = f64x2::from_bits(u64x2::splat(7)).as_m128d();
4624        assert_eq_m128d(r, e);
4625    }
4626
4627    #[simd_test(enable = "sse2")]
4628    const fn test_mm_xor_pd() {
4629        let a = f64x2::from_bits(u64x2::splat(5)).as_m128d();
4630        let b = f64x2::from_bits(u64x2::splat(3)).as_m128d();
4631        let r = _mm_xor_pd(a, b);
4632        let e = f64x2::from_bits(u64x2::splat(6)).as_m128d();
4633        assert_eq_m128d(r, e);
4634    }
4635
4636    #[simd_test(enable = "sse2")]
4637    fn test_mm_cmpeq_sd() {
4638        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4639        let e = _mm_setr_epi64x(!0, 2.0f64.to_bits() as i64);
4640        let r = _mm_castpd_si128(_mm_cmpeq_sd(a, b));
4641        assert_eq_m128i(r, e);
4642    }
4643
4644    #[simd_test(enable = "sse2")]
4645    fn test_mm_cmplt_sd() {
4646        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(5.0, 3.0));
4647        let e = _mm_setr_epi64x(!0, 2.0f64.to_bits() as i64);
4648        let r = _mm_castpd_si128(_mm_cmplt_sd(a, b));
4649        assert_eq_m128i(r, e);
4650    }
4651
4652    #[simd_test(enable = "sse2")]
4653    fn test_mm_cmple_sd() {
4654        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4655        let e = _mm_setr_epi64x(!0, 2.0f64.to_bits() as i64);
4656        let r = _mm_castpd_si128(_mm_cmple_sd(a, b));
4657        assert_eq_m128i(r, e);
4658    }
4659
4660    #[simd_test(enable = "sse2")]
4661    fn test_mm_cmpgt_sd() {
4662        let (a, b) = (_mm_setr_pd(5.0, 2.0), _mm_setr_pd(1.0, 3.0));
4663        let e = _mm_setr_epi64x(!0, 2.0f64.to_bits() as i64);
4664        let r = _mm_castpd_si128(_mm_cmpgt_sd(a, b));
4665        assert_eq_m128i(r, e);
4666    }
4667
4668    #[simd_test(enable = "sse2")]
4669    fn test_mm_cmpge_sd() {
4670        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4671        let e = _mm_setr_epi64x(!0, 2.0f64.to_bits() as i64);
4672        let r = _mm_castpd_si128(_mm_cmpge_sd(a, b));
4673        assert_eq_m128i(r, e);
4674    }
4675
4676    #[simd_test(enable = "sse2")]
4677    fn test_mm_cmpord_sd() {
4678        let (a, b) = (_mm_setr_pd(NAN, 2.0), _mm_setr_pd(5.0, 3.0));
4679        let e = _mm_setr_epi64x(0, 2.0f64.to_bits() as i64);
4680        let r = _mm_castpd_si128(_mm_cmpord_sd(a, b));
4681        assert_eq_m128i(r, e);
4682    }
4683
4684    #[simd_test(enable = "sse2")]
4685    fn test_mm_cmpunord_sd() {
4686        let (a, b) = (_mm_setr_pd(NAN, 2.0), _mm_setr_pd(5.0, 3.0));
4687        let e = _mm_setr_epi64x(!0, 2.0f64.to_bits() as i64);
4688        let r = _mm_castpd_si128(_mm_cmpunord_sd(a, b));
4689        assert_eq_m128i(r, e);
4690    }
4691
4692    #[simd_test(enable = "sse2")]
4693    fn test_mm_cmpneq_sd() {
4694        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(5.0, 3.0));
4695        let e = _mm_setr_epi64x(!0, 2.0f64.to_bits() as i64);
4696        let r = _mm_castpd_si128(_mm_cmpneq_sd(a, b));
4697        assert_eq_m128i(r, e);
4698    }
4699
4700    #[simd_test(enable = "sse2")]
4701    fn test_mm_cmpnlt_sd() {
4702        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(5.0, 3.0));
4703        let e = _mm_setr_epi64x(0, 2.0f64.to_bits() as i64);
4704        let r = _mm_castpd_si128(_mm_cmpnlt_sd(a, b));
4705        assert_eq_m128i(r, e);
4706    }
4707
4708    #[simd_test(enable = "sse2")]
4709    fn test_mm_cmpnle_sd() {
4710        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4711        let e = _mm_setr_epi64x(0, 2.0f64.to_bits() as i64);
4712        let r = _mm_castpd_si128(_mm_cmpnle_sd(a, b));
4713        assert_eq_m128i(r, e);
4714    }
4715
4716    #[simd_test(enable = "sse2")]
4717    fn test_mm_cmpngt_sd() {
4718        let (a, b) = (_mm_setr_pd(5.0, 2.0), _mm_setr_pd(1.0, 3.0));
4719        let e = _mm_setr_epi64x(0, 2.0f64.to_bits() as i64);
4720        let r = _mm_castpd_si128(_mm_cmpngt_sd(a, b));
4721        assert_eq_m128i(r, e);
4722    }
4723
4724    #[simd_test(enable = "sse2")]
4725    fn test_mm_cmpnge_sd() {
4726        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4727        let e = _mm_setr_epi64x(0, 2.0f64.to_bits() as i64);
4728        let r = _mm_castpd_si128(_mm_cmpnge_sd(a, b));
4729        assert_eq_m128i(r, e);
4730    }
4731
4732    #[simd_test(enable = "sse2")]
4733    fn test_mm_cmpeq_pd() {
4734        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4735        let e = _mm_setr_epi64x(!0, 0);
4736        let r = _mm_castpd_si128(_mm_cmpeq_pd(a, b));
4737        assert_eq_m128i(r, e);
4738    }
4739
4740    #[simd_test(enable = "sse2")]
4741    fn test_mm_cmplt_pd() {
4742        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4743        let e = _mm_setr_epi64x(0, !0);
4744        let r = _mm_castpd_si128(_mm_cmplt_pd(a, b));
4745        assert_eq_m128i(r, e);
4746    }
4747
4748    #[simd_test(enable = "sse2")]
4749    fn test_mm_cmple_pd() {
4750        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4751        let e = _mm_setr_epi64x(!0, !0);
4752        let r = _mm_castpd_si128(_mm_cmple_pd(a, b));
4753        assert_eq_m128i(r, e);
4754    }
4755
4756    #[simd_test(enable = "sse2")]
4757    fn test_mm_cmpgt_pd() {
4758        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4759        let e = _mm_setr_epi64x(0, 0);
4760        let r = _mm_castpd_si128(_mm_cmpgt_pd(a, b));
4761        assert_eq_m128i(r, e);
4762    }
4763
4764    #[simd_test(enable = "sse2")]
4765    fn test_mm_cmpge_pd() {
4766        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4767        let e = _mm_setr_epi64x(!0, 0);
4768        let r = _mm_castpd_si128(_mm_cmpge_pd(a, b));
4769        assert_eq_m128i(r, e);
4770    }
4771
4772    #[simd_test(enable = "sse2")]
4773    fn test_mm_cmpord_pd() {
4774        let (a, b) = (_mm_setr_pd(NAN, 2.0), _mm_setr_pd(5.0, 3.0));
4775        let e = _mm_setr_epi64x(0, !0);
4776        let r = _mm_castpd_si128(_mm_cmpord_pd(a, b));
4777        assert_eq_m128i(r, e);
4778    }
4779
4780    #[simd_test(enable = "sse2")]
4781    fn test_mm_cmpunord_pd() {
4782        let (a, b) = (_mm_setr_pd(NAN, 2.0), _mm_setr_pd(5.0, 3.0));
4783        let e = _mm_setr_epi64x(!0, 0);
4784        let r = _mm_castpd_si128(_mm_cmpunord_pd(a, b));
4785        assert_eq_m128i(r, e);
4786    }
4787
4788    #[simd_test(enable = "sse2")]
4789    fn test_mm_cmpneq_pd() {
4790        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(5.0, 3.0));
4791        let e = _mm_setr_epi64x(!0, !0);
4792        let r = _mm_castpd_si128(_mm_cmpneq_pd(a, b));
4793        assert_eq_m128i(r, e);
4794    }
4795
4796    #[simd_test(enable = "sse2")]
4797    fn test_mm_cmpnlt_pd() {
4798        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(5.0, 3.0));
4799        let e = _mm_setr_epi64x(0, 0);
4800        let r = _mm_castpd_si128(_mm_cmpnlt_pd(a, b));
4801        assert_eq_m128i(r, e);
4802    }
4803
4804    #[simd_test(enable = "sse2")]
4805    fn test_mm_cmpnle_pd() {
4806        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4807        let e = _mm_setr_epi64x(0, 0);
4808        let r = _mm_castpd_si128(_mm_cmpnle_pd(a, b));
4809        assert_eq_m128i(r, e);
4810    }
4811
4812    #[simd_test(enable = "sse2")]
4813    fn test_mm_cmpngt_pd() {
4814        let (a, b) = (_mm_setr_pd(5.0, 2.0), _mm_setr_pd(1.0, 3.0));
4815        let e = _mm_setr_epi64x(0, !0);
4816        let r = _mm_castpd_si128(_mm_cmpngt_pd(a, b));
4817        assert_eq_m128i(r, e);
4818    }
4819
4820    #[simd_test(enable = "sse2")]
4821    fn test_mm_cmpnge_pd() {
4822        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4823        let e = _mm_setr_epi64x(0, !0);
4824        let r = _mm_castpd_si128(_mm_cmpnge_pd(a, b));
4825        assert_eq_m128i(r, e);
4826    }
4827
4828    #[simd_test(enable = "sse2")]
4829    fn test_mm_comieq_sd() {
4830        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4831        assert!(_mm_comieq_sd(a, b) != 0);
4832
4833        let (a, b) = (_mm_setr_pd(NAN, 2.0), _mm_setr_pd(1.0, 3.0));
4834        assert!(_mm_comieq_sd(a, b) == 0);
4835    }
4836
4837    #[simd_test(enable = "sse2")]
4838    fn test_mm_comilt_sd() {
4839        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4840        assert!(_mm_comilt_sd(a, b) == 0);
4841    }
4842
4843    #[simd_test(enable = "sse2")]
4844    fn test_mm_comile_sd() {
4845        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4846        assert!(_mm_comile_sd(a, b) != 0);
4847    }
4848
4849    #[simd_test(enable = "sse2")]
4850    fn test_mm_comigt_sd() {
4851        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4852        assert!(_mm_comigt_sd(a, b) == 0);
4853    }
4854
4855    #[simd_test(enable = "sse2")]
4856    fn test_mm_comige_sd() {
4857        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4858        assert!(_mm_comige_sd(a, b) != 0);
4859    }
4860
4861    #[simd_test(enable = "sse2")]
4862    fn test_mm_comineq_sd() {
4863        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4864        assert!(_mm_comineq_sd(a, b) == 0);
4865    }
4866
4867    #[simd_test(enable = "sse2")]
4868    fn test_mm_ucomieq_sd() {
4869        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4870        assert!(_mm_ucomieq_sd(a, b) != 0);
4871
4872        let (a, b) = (_mm_setr_pd(NAN, 2.0), _mm_setr_pd(NAN, 3.0));
4873        assert!(_mm_ucomieq_sd(a, b) == 0);
4874    }
4875
4876    #[simd_test(enable = "sse2")]
4877    fn test_mm_ucomilt_sd() {
4878        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4879        assert!(_mm_ucomilt_sd(a, b) == 0);
4880    }
4881
4882    #[simd_test(enable = "sse2")]
4883    fn test_mm_ucomile_sd() {
4884        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4885        assert!(_mm_ucomile_sd(a, b) != 0);
4886    }
4887
4888    #[simd_test(enable = "sse2")]
4889    fn test_mm_ucomigt_sd() {
4890        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4891        assert!(_mm_ucomigt_sd(a, b) == 0);
4892    }
4893
4894    #[simd_test(enable = "sse2")]
4895    fn test_mm_ucomige_sd() {
4896        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4897        assert!(_mm_ucomige_sd(a, b) != 0);
4898    }
4899
4900    #[simd_test(enable = "sse2")]
4901    fn test_mm_ucomineq_sd() {
4902        let (a, b) = (_mm_setr_pd(1.0, 2.0), _mm_setr_pd(1.0, 3.0));
4903        assert!(_mm_ucomineq_sd(a, b) == 0);
4904    }
4905
4906    #[simd_test(enable = "sse2")]
4907    const fn test_mm_movemask_pd() {
4908        let r = _mm_movemask_pd(_mm_setr_pd(-1.0, 5.0));
4909        assert_eq!(r, 0b01);
4910
4911        let r = _mm_movemask_pd(_mm_setr_pd(-1.0, -5.0));
4912        assert_eq!(r, 0b11);
4913    }
4914
4915    #[repr(align(16))]
4916    struct Memory {
4917        data: [f64; 4],
4918    }
4919
4920    #[simd_test(enable = "sse2")]
4921    const fn test_mm_load_pd() {
4922        let mem = Memory {
4923            data: [1.0f64, 2.0, 3.0, 4.0],
4924        };
4925        let vals = &mem.data;
4926        let d = vals.as_ptr();
4927
4928        let r = unsafe { _mm_load_pd(d) };
4929        assert_eq_m128d(r, _mm_setr_pd(1.0, 2.0));
4930    }
4931
4932    #[simd_test(enable = "sse2")]
4933    const fn test_mm_load_sd() {
4934        let a = 1.;
4935        let expected = _mm_setr_pd(a, 0.);
4936        let r = unsafe { _mm_load_sd(&a) };
4937        assert_eq_m128d(r, expected);
4938    }
4939
4940    #[simd_test(enable = "sse2")]
4941    const fn test_mm_loadh_pd() {
4942        let a = _mm_setr_pd(1., 2.);
4943        let b = 3.;
4944        let expected = _mm_setr_pd(_mm_cvtsd_f64(a), 3.);
4945        let r = unsafe { _mm_loadh_pd(a, &b) };
4946        assert_eq_m128d(r, expected);
4947    }
4948
4949    #[simd_test(enable = "sse2")]
4950    const fn test_mm_loadl_pd() {
4951        let a = _mm_setr_pd(1., 2.);
4952        let b = 3.;
4953        let expected = _mm_setr_pd(3., get_m128d(a, 1));
4954        let r = unsafe { _mm_loadl_pd(a, &b) };
4955        assert_eq_m128d(r, expected);
4956    }
4957
4958    #[simd_test(enable = "sse2")]
4959    // Miri cannot support this until it is clear how it fits in the Rust memory model
4960    // (non-temporal store)
4961    #[cfg_attr(miri, ignore)]
4962    fn test_mm_stream_pd() {
4963        #[repr(align(128))]
4964        struct Memory {
4965            pub data: [f64; 2],
4966        }
4967        let a = _mm_set1_pd(7.0);
4968        let mut mem = Memory { data: [-1.0; 2] };
4969
4970        unsafe {
4971            _mm_stream_pd(ptr::addr_of_mut!(mem.data[0]), a);
4972        }
4973        _mm_sfence();
4974        for i in 0..2 {
4975            assert_eq!(mem.data[i], get_m128d(a, i));
4976        }
4977    }
4978
4979    #[simd_test(enable = "sse2")]
4980    const fn test_mm_store_sd() {
4981        let mut dest = 0.;
4982        let a = _mm_setr_pd(1., 2.);
4983        unsafe {
4984            _mm_store_sd(&mut dest, a);
4985        }
4986        assert_eq!(dest, _mm_cvtsd_f64(a));
4987    }
4988
4989    #[simd_test(enable = "sse2")]
4990    const fn test_mm_store_pd() {
4991        let mut mem = Memory { data: [0.0f64; 4] };
4992        let vals = &mut mem.data;
4993        let a = _mm_setr_pd(1.0, 2.0);
4994        let d = vals.as_mut_ptr();
4995
4996        unsafe {
4997            _mm_store_pd(d, *black_box(&a));
4998        }
4999        assert_eq!(vals[0], 1.0);
5000        assert_eq!(vals[1], 2.0);
5001    }
5002
5003    #[simd_test(enable = "sse2")]
5004    const fn test_mm_storeu_pd() {
5005        // guaranteed to be aligned to 16 bytes
5006        let mut mem = Memory { data: [0.0f64; 4] };
5007        let vals = &mut mem.data;
5008        let a = _mm_setr_pd(1.0, 2.0);
5009
5010        // so p is *not* aligned to 16 bytes
5011        unsafe {
5012            let p = vals.as_mut_ptr().offset(1);
5013            _mm_storeu_pd(p, *black_box(&a));
5014        }
5015
5016        assert_eq!(*vals, [0.0, 1.0, 2.0, 0.0]);
5017    }
5018
5019    #[simd_test(enable = "sse2")]
5020    const fn test_mm_storeu_si16() {
5021        let a = _mm_setr_epi16(1, 2, 3, 4, 5, 6, 7, 8);
5022        let mut r = _mm_setr_epi16(9, 10, 11, 12, 13, 14, 15, 16);
5023        unsafe {
5024            _mm_storeu_si16(ptr::addr_of_mut!(r).cast(), a);
5025        }
5026        let e = _mm_setr_epi16(1, 10, 11, 12, 13, 14, 15, 16);
5027        assert_eq_m128i(r, e);
5028    }
5029
5030    #[simd_test(enable = "sse2")]
5031    const fn test_mm_storeu_si32() {
5032        let a = _mm_setr_epi32(1, 2, 3, 4);
5033        let mut r = _mm_setr_epi32(5, 6, 7, 8);
5034        unsafe {
5035            _mm_storeu_si32(ptr::addr_of_mut!(r).cast(), a);
5036        }
5037        let e = _mm_setr_epi32(1, 6, 7, 8);
5038        assert_eq_m128i(r, e);
5039    }
5040
5041    #[simd_test(enable = "sse2")]
5042    const fn test_mm_storeu_si64() {
5043        let a = _mm_setr_epi64x(1, 2);
5044        let mut r = _mm_setr_epi64x(3, 4);
5045        unsafe {
5046            _mm_storeu_si64(ptr::addr_of_mut!(r).cast(), a);
5047        }
5048        let e = _mm_setr_epi64x(1, 4);
5049        assert_eq_m128i(r, e);
5050    }
5051
5052    #[simd_test(enable = "sse2")]
5053    const fn test_mm_store1_pd() {
5054        let mut mem = Memory { data: [0.0f64; 4] };
5055        let vals = &mut mem.data;
5056        let a = _mm_setr_pd(1.0, 2.0);
5057        let d = vals.as_mut_ptr();
5058
5059        unsafe {
5060            _mm_store1_pd(d, *black_box(&a));
5061        }
5062        assert_eq!(vals[0], 1.0);
5063        assert_eq!(vals[1], 1.0);
5064    }
5065
5066    #[simd_test(enable = "sse2")]
5067    const fn test_mm_store_pd1() {
5068        let mut mem = Memory { data: [0.0f64; 4] };
5069        let vals = &mut mem.data;
5070        let a = _mm_setr_pd(1.0, 2.0);
5071        let d = vals.as_mut_ptr();
5072
5073        unsafe {
5074            _mm_store_pd1(d, *black_box(&a));
5075        }
5076        assert_eq!(vals[0], 1.0);
5077        assert_eq!(vals[1], 1.0);
5078    }
5079
5080    #[simd_test(enable = "sse2")]
5081    const fn test_mm_storer_pd() {
5082        let mut mem = Memory { data: [0.0f64; 4] };
5083        let vals = &mut mem.data;
5084        let a = _mm_setr_pd(1.0, 2.0);
5085        let d = vals.as_mut_ptr();
5086
5087        unsafe {
5088            _mm_storer_pd(d, *black_box(&a));
5089        }
5090        assert_eq!(vals[0], 2.0);
5091        assert_eq!(vals[1], 1.0);
5092    }
5093
5094    #[simd_test(enable = "sse2")]
5095    const fn test_mm_storeh_pd() {
5096        let mut dest = 0.;
5097        let a = _mm_setr_pd(1., 2.);
5098        unsafe {
5099            _mm_storeh_pd(&mut dest, a);
5100        }
5101        assert_eq!(dest, get_m128d(a, 1));
5102    }
5103
5104    #[simd_test(enable = "sse2")]
5105    const fn test_mm_storel_pd() {
5106        let mut dest = 0.;
5107        let a = _mm_setr_pd(1., 2.);
5108        unsafe {
5109            _mm_storel_pd(&mut dest, a);
5110        }
5111        assert_eq!(dest, _mm_cvtsd_f64(a));
5112    }
5113
5114    #[simd_test(enable = "sse2")]
5115    const fn test_mm_loadr_pd() {
5116        let mut mem = Memory {
5117            data: [1.0f64, 2.0, 3.0, 4.0],
5118        };
5119        let vals = &mut mem.data;
5120        let d = vals.as_ptr();
5121
5122        let r = unsafe { _mm_loadr_pd(d) };
5123        assert_eq_m128d(r, _mm_setr_pd(2.0, 1.0));
5124    }
5125
5126    #[simd_test(enable = "sse2")]
5127    const fn test_mm_loadu_pd() {
5128        // guaranteed to be aligned to 16 bytes
5129        let mut mem = Memory {
5130            data: [1.0f64, 2.0, 3.0, 4.0],
5131        };
5132        let vals = &mut mem.data;
5133
5134        // so this will *not* be aligned to 16 bytes
5135        let d = unsafe { vals.as_ptr().offset(1) };
5136
5137        let r = unsafe { _mm_loadu_pd(d) };
5138        let e = _mm_setr_pd(2.0, 3.0);
5139        assert_eq_m128d(r, e);
5140    }
5141
5142    #[simd_test(enable = "sse2")]
5143    const fn test_mm_loadu_si16() {
5144        let a = _mm_setr_epi16(1, 2, 3, 4, 5, 6, 7, 8);
5145        let r = unsafe { _mm_loadu_si16(ptr::addr_of!(a) as *const _) };
5146        assert_eq_m128i(r, _mm_setr_epi16(1, 0, 0, 0, 0, 0, 0, 0));
5147    }
5148
5149    #[simd_test(enable = "sse2")]
5150    const fn test_mm_loadu_si32() {
5151        let a = _mm_setr_epi32(1, 2, 3, 4);
5152        let r = unsafe { _mm_loadu_si32(ptr::addr_of!(a) as *const _) };
5153        assert_eq_m128i(r, _mm_setr_epi32(1, 0, 0, 0));
5154    }
5155
5156    #[simd_test(enable = "sse2")]
5157    const fn test_mm_loadu_si64() {
5158        let a = _mm_setr_epi64x(5, 6);
5159        let r = unsafe { _mm_loadu_si64(ptr::addr_of!(a) as *const _) };
5160        assert_eq_m128i(r, _mm_setr_epi64x(5, 0));
5161    }
5162
5163    #[simd_test(enable = "sse2")]
5164    const fn test_mm_cvtpd_ps() {
5165        let r = _mm_cvtpd_ps(_mm_setr_pd(-1.0, 5.0));
5166        assert_eq_m128(r, _mm_setr_ps(-1.0, 5.0, 0.0, 0.0));
5167
5168        let r = _mm_cvtpd_ps(_mm_setr_pd(-1.0, -5.0));
5169        assert_eq_m128(r, _mm_setr_ps(-1.0, -5.0, 0.0, 0.0));
5170
5171        let r = _mm_cvtpd_ps(_mm_setr_pd(f64::MAX, f64::MIN));
5172        assert_eq_m128(r, _mm_setr_ps(f32::INFINITY, f32::NEG_INFINITY, 0.0, 0.0));
5173
5174        let r = _mm_cvtpd_ps(_mm_setr_pd(f32::MAX as f64, f32::MIN as f64));
5175        assert_eq_m128(r, _mm_setr_ps(f32::MAX, f32::MIN, 0.0, 0.0));
5176    }
5177
5178    #[simd_test(enable = "sse2")]
5179    const fn test_mm_cvtps_pd() {
5180        let r = _mm_cvtps_pd(_mm_setr_ps(-1.0, 2.0, -3.0, 5.0));
5181        assert_eq_m128d(r, _mm_setr_pd(-1.0, 2.0));
5182
5183        let r = _mm_cvtps_pd(_mm_setr_ps(
5184            f32::MAX,
5185            f32::INFINITY,
5186            f32::NEG_INFINITY,
5187            f32::MIN,
5188        ));
5189        assert_eq_m128d(r, _mm_setr_pd(f32::MAX as f64, f64::INFINITY));
5190    }
5191
5192    #[simd_test(enable = "sse2")]
5193    fn test_mm_cvtpd_epi32() {
5194        let r = _mm_cvtpd_epi32(_mm_setr_pd(-1.0, 5.0));
5195        assert_eq_m128i(r, _mm_setr_epi32(-1, 5, 0, 0));
5196
5197        let r = _mm_cvtpd_epi32(_mm_setr_pd(-1.0, -5.0));
5198        assert_eq_m128i(r, _mm_setr_epi32(-1, -5, 0, 0));
5199
5200        let r = _mm_cvtpd_epi32(_mm_setr_pd(f64::MAX, f64::MIN));
5201        assert_eq_m128i(r, _mm_setr_epi32(i32::MIN, i32::MIN, 0, 0));
5202
5203        let r = _mm_cvtpd_epi32(_mm_setr_pd(f64::INFINITY, f64::NEG_INFINITY));
5204        assert_eq_m128i(r, _mm_setr_epi32(i32::MIN, i32::MIN, 0, 0));
5205
5206        let r = _mm_cvtpd_epi32(_mm_setr_pd(f64::NAN, f64::NAN));
5207        assert_eq_m128i(r, _mm_setr_epi32(i32::MIN, i32::MIN, 0, 0));
5208    }
5209
5210    #[simd_test(enable = "sse2")]
5211    fn test_mm_cvtsd_si32() {
5212        let r = _mm_cvtsd_si32(_mm_setr_pd(-2.0, 5.0));
5213        assert_eq!(r, -2);
5214
5215        let r = _mm_cvtsd_si32(_mm_setr_pd(f64::MAX, f64::MIN));
5216        assert_eq!(r, i32::MIN);
5217
5218        let r = _mm_cvtsd_si32(_mm_setr_pd(f64::NAN, f64::NAN));
5219        assert_eq!(r, i32::MIN);
5220    }
5221
5222    #[simd_test(enable = "sse2")]
5223    fn test_mm_cvtsd_ss() {
5224        let a = _mm_setr_ps(-1.1, -2.2, 3.3, 4.4);
5225        let b = _mm_setr_pd(2.0, -5.0);
5226
5227        let r = _mm_cvtsd_ss(a, b);
5228
5229        assert_eq_m128(r, _mm_setr_ps(2.0, -2.2, 3.3, 4.4));
5230
5231        let a = _mm_setr_ps(-1.1, f32::NEG_INFINITY, f32::MAX, f32::NEG_INFINITY);
5232        let b = _mm_setr_pd(f64::INFINITY, -5.0);
5233
5234        let r = _mm_cvtsd_ss(a, b);
5235
5236        assert_eq_m128(
5237            r,
5238            _mm_setr_ps(
5239                f32::INFINITY,
5240                f32::NEG_INFINITY,
5241                f32::MAX,
5242                f32::NEG_INFINITY,
5243            ),
5244        );
5245    }
5246
5247    #[simd_test(enable = "sse2")]
5248    const fn test_mm_cvtsd_f64() {
5249        let r = _mm_cvtsd_f64(_mm_setr_pd(-1.1, 2.2));
5250        assert_eq!(r, -1.1);
5251    }
5252
5253    #[simd_test(enable = "sse2")]
5254    const fn test_mm_cvtss_sd() {
5255        let a = _mm_setr_pd(-1.1, 2.2);
5256        let b = _mm_setr_ps(1.0, 2.0, 3.0, 4.0);
5257
5258        let r = _mm_cvtss_sd(a, b);
5259        assert_eq_m128d(r, _mm_setr_pd(1.0, 2.2));
5260
5261        let a = _mm_setr_pd(-1.1, f64::INFINITY);
5262        let b = _mm_setr_ps(f32::NEG_INFINITY, 2.0, 3.0, 4.0);
5263
5264        let r = _mm_cvtss_sd(a, b);
5265        assert_eq_m128d(r, _mm_setr_pd(f64::NEG_INFINITY, f64::INFINITY));
5266    }
5267
5268    #[simd_test(enable = "sse2")]
5269    fn test_mm_cvttpd_epi32() {
5270        let a = _mm_setr_pd(-1.1, 2.2);
5271        let r = _mm_cvttpd_epi32(a);
5272        assert_eq_m128i(r, _mm_setr_epi32(-1, 2, 0, 0));
5273
5274        let a = _mm_setr_pd(f64::NEG_INFINITY, f64::NAN);
5275        let r = _mm_cvttpd_epi32(a);
5276        assert_eq_m128i(r, _mm_setr_epi32(i32::MIN, i32::MIN, 0, 0));
5277    }
5278
5279    #[simd_test(enable = "sse2")]
5280    fn test_mm_cvttsd_si32() {
5281        let a = _mm_setr_pd(-1.1, 2.2);
5282        let r = _mm_cvttsd_si32(a);
5283        assert_eq!(r, -1);
5284
5285        let a = _mm_setr_pd(f64::NEG_INFINITY, f64::NAN);
5286        let r = _mm_cvttsd_si32(a);
5287        assert_eq!(r, i32::MIN);
5288    }
5289
5290    #[simd_test(enable = "sse2")]
5291    fn test_mm_cvttps_epi32() {
5292        let a = _mm_setr_ps(-1.1, 2.2, -3.3, 6.6);
5293        let r = _mm_cvttps_epi32(a);
5294        assert_eq_m128i(r, _mm_setr_epi32(-1, 2, -3, 6));
5295
5296        let a = _mm_setr_ps(f32::NEG_INFINITY, f32::INFINITY, f32::MIN, f32::MAX);
5297        let r = _mm_cvttps_epi32(a);
5298        assert_eq_m128i(r, _mm_setr_epi32(i32::MIN, i32::MIN, i32::MIN, i32::MIN));
5299    }
5300
5301    #[simd_test(enable = "sse2")]
5302    const fn test_mm_set_sd() {
5303        let r = _mm_set_sd(-1.0_f64);
5304        assert_eq_m128d(r, _mm_setr_pd(-1.0_f64, 0_f64));
5305    }
5306
5307    #[simd_test(enable = "sse2")]
5308    const fn test_mm_set1_pd() {
5309        let r = _mm_set1_pd(-1.0_f64);
5310        assert_eq_m128d(r, _mm_setr_pd(-1.0_f64, -1.0_f64));
5311    }
5312
5313    #[simd_test(enable = "sse2")]
5314    const fn test_mm_set_pd1() {
5315        let r = _mm_set_pd1(-2.0_f64);
5316        assert_eq_m128d(r, _mm_setr_pd(-2.0_f64, -2.0_f64));
5317    }
5318
5319    #[simd_test(enable = "sse2")]
5320    const fn test_mm_set_pd() {
5321        let r = _mm_set_pd(1.0_f64, 5.0_f64);
5322        assert_eq_m128d(r, _mm_setr_pd(5.0_f64, 1.0_f64));
5323    }
5324
5325    #[simd_test(enable = "sse2")]
5326    const fn test_mm_setr_pd() {
5327        let r = _mm_setr_pd(1.0_f64, -5.0_f64);
5328        assert_eq_m128d(r, _mm_setr_pd(1.0_f64, -5.0_f64));
5329    }
5330
5331    #[simd_test(enable = "sse2")]
5332    const fn test_mm_setzero_pd() {
5333        let r = _mm_setzero_pd();
5334        assert_eq_m128d(r, _mm_setr_pd(0_f64, 0_f64));
5335    }
5336
5337    #[simd_test(enable = "sse2")]
5338    const fn test_mm_load1_pd() {
5339        let d = -5.0;
5340        let r = unsafe { _mm_load1_pd(&d) };
5341        assert_eq_m128d(r, _mm_setr_pd(d, d));
5342    }
5343
5344    #[simd_test(enable = "sse2")]
5345    const fn test_mm_load_pd1() {
5346        let d = -5.0;
5347        let r = unsafe { _mm_load_pd1(&d) };
5348        assert_eq_m128d(r, _mm_setr_pd(d, d));
5349    }
5350
5351    #[simd_test(enable = "sse2")]
5352    const fn test_mm_unpackhi_pd() {
5353        let a = _mm_setr_pd(1.0, 2.0);
5354        let b = _mm_setr_pd(3.0, 4.0);
5355        let r = _mm_unpackhi_pd(a, b);
5356        assert_eq_m128d(r, _mm_setr_pd(2.0, 4.0));
5357    }
5358
5359    #[simd_test(enable = "sse2")]
5360    const fn test_mm_unpacklo_pd() {
5361        let a = _mm_setr_pd(1.0, 2.0);
5362        let b = _mm_setr_pd(3.0, 4.0);
5363        let r = _mm_unpacklo_pd(a, b);
5364        assert_eq_m128d(r, _mm_setr_pd(1.0, 3.0));
5365    }
5366
5367    #[simd_test(enable = "sse2")]
5368    const fn test_mm_shuffle_pd() {
5369        let a = _mm_setr_pd(1., 2.);
5370        let b = _mm_setr_pd(3., 4.);
5371        let expected = _mm_setr_pd(1., 3.);
5372        let r = _mm_shuffle_pd::<0b00_00_00_00>(a, b);
5373        assert_eq_m128d(r, expected);
5374    }
5375
5376    #[simd_test(enable = "sse2")]
5377    const fn test_mm_move_sd() {
5378        let a = _mm_setr_pd(1., 2.);
5379        let b = _mm_setr_pd(3., 4.);
5380        let expected = _mm_setr_pd(3., 2.);
5381        let r = _mm_move_sd(a, b);
5382        assert_eq_m128d(r, expected);
5383    }
5384
5385    #[simd_test(enable = "sse2")]
5386    const fn test_mm_castpd_ps() {
5387        let a = _mm_set1_pd(0.);
5388        let expected = _mm_set1_ps(0.);
5389        let r = _mm_castpd_ps(a);
5390        assert_eq_m128(r, expected);
5391    }
5392
5393    #[simd_test(enable = "sse2")]
5394    const fn test_mm_castpd_si128() {
5395        let a = _mm_set1_pd(0.);
5396        let expected = _mm_set1_epi64x(0);
5397        let r = _mm_castpd_si128(a);
5398        assert_eq_m128i(r, expected);
5399    }
5400
5401    #[simd_test(enable = "sse2")]
5402    const fn test_mm_castps_pd() {
5403        let a = _mm_set1_ps(0.);
5404        let expected = _mm_set1_pd(0.);
5405        let r = _mm_castps_pd(a);
5406        assert_eq_m128d(r, expected);
5407    }
5408
5409    #[simd_test(enable = "sse2")]
5410    const fn test_mm_castps_si128() {
5411        let a = _mm_set1_ps(0.);
5412        let expected = _mm_set1_epi32(0);
5413        let r = _mm_castps_si128(a);
5414        assert_eq_m128i(r, expected);
5415    }
5416
5417    #[simd_test(enable = "sse2")]
5418    const fn test_mm_castsi128_pd() {
5419        let a = _mm_set1_epi64x(0);
5420        let expected = _mm_set1_pd(0.);
5421        let r = _mm_castsi128_pd(a);
5422        assert_eq_m128d(r, expected);
5423    }
5424
5425    #[simd_test(enable = "sse2")]
5426    const fn test_mm_castsi128_ps() {
5427        let a = _mm_set1_epi32(0);
5428        let expected = _mm_set1_ps(0.);
5429        let r = _mm_castsi128_ps(a);
5430        assert_eq_m128(r, expected);
5431    }
5432}