core/stdarch/crates/core_arch/src/x86_64/
sse2.rs1use crate::core_arch::x86::*;
4
5#[cfg(test)]
6use stdarch_test::assert_instr;
7
8#[allow(improper_ctypes)]
9unsafe extern "C" {
10 #[link_name = "llvm.x86.sse2.cvtsd2si64"]
11 fn cvtsd2si64(a: __m128d) -> i64;
12 #[link_name = "llvm.x86.sse2.cvttsd2si64"]
13 fn cvttsd2si64(a: __m128d) -> i64;
14}
15
16#[inline]
21#[target_feature(enable = "sse2")]
22#[cfg_attr(test, assert_instr(cvtsd2si))]
23#[stable(feature = "simd_x86", since = "1.27.0")]
24pub fn _mm_cvtsd_si64(a: __m128d) -> i64 {
25 unsafe { cvtsd2si64(a) }
26}
27
28#[inline]
32#[target_feature(enable = "sse2")]
33#[cfg_attr(test, assert_instr(cvtsd2si))]
34#[stable(feature = "simd_x86", since = "1.27.0")]
35pub fn _mm_cvtsd_si64x(a: __m128d) -> i64 {
36 _mm_cvtsd_si64(a)
37}
38
39#[inline]
44#[target_feature(enable = "sse2")]
45#[cfg_attr(test, assert_instr(cvttsd2si))]
46#[stable(feature = "simd_x86", since = "1.27.0")]
47pub fn _mm_cvttsd_si64(a: __m128d) -> i64 {
48 unsafe { cvttsd2si64(a) }
49}
50
51#[inline]
55#[target_feature(enable = "sse2")]
56#[cfg_attr(test, assert_instr(cvttsd2si))]
57#[stable(feature = "simd_x86", since = "1.27.0")]
58pub fn _mm_cvttsd_si64x(a: __m128d) -> i64 {
59 _mm_cvttsd_si64(a)
60}
61
62#[inline]
77#[target_feature(enable = "sse2")]
78#[cfg_attr(test, assert_instr(movnti))]
79#[stable(feature = "simd_x86", since = "1.27.0")]
80pub unsafe fn _mm_stream_si64(mem_addr: *mut i64, a: i64) {
81 crate::arch::asm!(
82 vps!("movnti", ",{a}"),
83 p = in(reg) mem_addr,
84 a = in(reg) a,
85 options(nostack, preserves_flags),
86 );
87}
88
89#[inline]
94#[target_feature(enable = "sse2")]
95#[cfg_attr(all(test, not(target_env = "msvc")), assert_instr(movq))]
96#[stable(feature = "simd_x86", since = "1.27.0")]
97pub fn _mm_cvtsi64_si128(a: i64) -> __m128i {
98 _mm_set_epi64x(0, a)
99}
100
101#[inline]
106#[target_feature(enable = "sse2")]
107#[cfg_attr(all(test, not(target_env = "msvc")), assert_instr(movq))]
108#[stable(feature = "simd_x86", since = "1.27.0")]
109pub fn _mm_cvtsi64x_si128(a: i64) -> __m128i {
110 _mm_cvtsi64_si128(a)
111}
112
113#[inline]
117#[target_feature(enable = "sse2")]
118#[cfg_attr(all(test, not(target_env = "msvc")), assert_instr(movq))]
119#[stable(feature = "simd_x86", since = "1.27.0")]
120pub fn _mm_cvtsi128_si64(a: __m128i) -> i64 {
121 unsafe { simd_extract!(a.as_i64x2(), 0) }
122}
123
124#[inline]
128#[target_feature(enable = "sse2")]
129#[cfg_attr(all(test, not(target_env = "msvc")), assert_instr(movq))]
130#[stable(feature = "simd_x86", since = "1.27.0")]
131pub fn _mm_cvtsi128_si64x(a: __m128i) -> i64 {
132 _mm_cvtsi128_si64(a)
133}
134
135#[inline]
140#[target_feature(enable = "sse2")]
141#[cfg_attr(test, assert_instr(cvtsi2sd))]
142#[stable(feature = "simd_x86", since = "1.27.0")]
143pub fn _mm_cvtsi64_sd(a: __m128d, b: i64) -> __m128d {
144 unsafe { simd_insert!(a, 0, b as f64) }
145}
146
147#[inline]
152#[target_feature(enable = "sse2")]
153#[cfg_attr(test, assert_instr(cvtsi2sd))]
154#[stable(feature = "simd_x86", since = "1.27.0")]
155pub fn _mm_cvtsi64x_sd(a: __m128d, b: i64) -> __m128d {
156 _mm_cvtsi64_sd(a, b)
157}
158
159#[cfg(test)]
160mod tests {
161 use crate::core_arch::arch::x86_64::*;
162 use std::boxed;
163 use std::ptr;
164 use stdarch_test::simd_test;
165
166 #[simd_test(enable = "sse2")]
167 unsafe fn test_mm_cvtsd_si64() {
168 let r = _mm_cvtsd_si64(_mm_setr_pd(-2.0, 5.0));
169 assert_eq!(r, -2_i64);
170
171 let r = _mm_cvtsd_si64(_mm_setr_pd(f64::MAX, f64::MIN));
172 assert_eq!(r, i64::MIN);
173 }
174
175 #[simd_test(enable = "sse2")]
176 unsafe fn test_mm_cvtsd_si64x() {
177 let r = _mm_cvtsd_si64x(_mm_setr_pd(f64::NAN, f64::NAN));
178 assert_eq!(r, i64::MIN);
179 }
180
181 #[simd_test(enable = "sse2")]
182 unsafe fn test_mm_cvttsd_si64() {
183 let a = _mm_setr_pd(-1.1, 2.2);
184 let r = _mm_cvttsd_si64(a);
185 assert_eq!(r, -1_i64);
186 }
187
188 #[simd_test(enable = "sse2")]
189 unsafe fn test_mm_cvttsd_si64x() {
190 let a = _mm_setr_pd(f64::NEG_INFINITY, f64::NAN);
191 let r = _mm_cvttsd_si64x(a);
192 assert_eq!(r, i64::MIN);
193 }
194
195 #[simd_test(enable = "sse2")]
196 #[cfg_attr(miri, ignore)]
199 unsafe fn test_mm_stream_si64() {
200 let a: i64 = 7;
201 let mut mem = boxed::Box::<i64>::new(-1);
202 _mm_stream_si64(ptr::addr_of_mut!(*mem), a);
203 assert_eq!(a, *mem);
204 }
205
206 #[simd_test(enable = "sse2")]
207 unsafe fn test_mm_cvtsi64_si128() {
208 let r = _mm_cvtsi64_si128(5);
209 assert_eq_m128i(r, _mm_setr_epi64x(5, 0));
210 }
211
212 #[simd_test(enable = "sse2")]
213 unsafe fn test_mm_cvtsi128_si64() {
214 let r = _mm_cvtsi128_si64(_mm_setr_epi64x(5, 0));
215 assert_eq!(r, 5);
216 }
217
218 #[simd_test(enable = "sse2")]
219 unsafe fn test_mm_cvtsi64_sd() {
220 let a = _mm_set1_pd(3.5);
221 let r = _mm_cvtsi64_sd(a, 5);
222 assert_eq_m128d(r, _mm_setr_pd(5.0, 3.5));
223 }
224}