Skip to content

Commit 3e83d38

Browse files
pythoneeralexcrichton
authored andcommitted
Sse2 (#116)
* added _mm_cvtsd_si64 * added _mm_cvttsd_si64; target_arch to _mm_cvtsd_si64 test
1 parent f7cc842 commit 3e83d38

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/x86/sse2.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,15 @@ pub unsafe fn _mm_cvtsd_si32(a: f64x2) -> i32 {
17421742
cvtsd2si(a)
17431743
}
17441744

1745+
/// Convert the lower double-precision (64-bit) floating-point element in a to a 64-bit integer.
1746+
#[cfg(target_arch = "x86_64")]
1747+
#[inline(always)]
1748+
#[target_feature = "+sse2"]
1749+
#[cfg_attr(test, assert_instr(cvtsd2si))]
1750+
pub unsafe fn _mm_cvtsd_si64(a: f64x2) -> i64 {
1751+
cvtsd2si64(a)
1752+
}
1753+
17451754
/// Convert the lower double-precision (64-bit) floating-point element in `b` to a
17461755
/// single-precision (32-bit) floating-point element, store the result in the lower element
17471756
/// of the return value, and copy the upper element from `a` to the upper element the return value.
@@ -1780,6 +1789,16 @@ pub unsafe fn _mm_cvttsd_si32(a: f64x2) -> i32 {
17801789
cvttsd2si(a)
17811790
}
17821791

1792+
/// Convert the lower double-precision (64-bit) floating-point element in `a` to a 64-bit integer
1793+
/// with truncation.
1794+
#[cfg(target_arch = "x86_64")]
1795+
#[inline(always)]
1796+
#[target_feature = "+sse2"]
1797+
#[cfg_attr(test, assert_instr(cvttsd2si))]
1798+
pub unsafe fn _mm_cvttsd_si64(a: f64x2) -> i64 {
1799+
cvttsd2si64(a)
1800+
}
1801+
17831802
/// Convert packed single-precision (32-bit) floating-point elements in `a` to packed 32-bit
17841803
/// integers with truncation
17851804
#[inline(always)]
@@ -1976,6 +1995,8 @@ extern {
19761995
fn cvtpd2dq(a: f64x2) -> i32x4;
19771996
#[link_name = "llvm.x86.sse2.cvtsd2si"]
19781997
fn cvtsd2si(a: f64x2) -> i32;
1998+
#[link_name = "llvm.x86.sse2.cvtsd2si64"]
1999+
fn cvtsd2si64(a: f64x2) -> i64;
19792000
#[link_name = "llvm.x86.sse2.cvtsd2ss"]
19802001
fn cvtsd2ss(a: f32x4, b: f64x2) -> f32x4;
19812002
#[link_name = "llvm.x86.sse2.cvtss2sd"]
@@ -1984,6 +2005,8 @@ extern {
19842005
fn cvttpd2dq(a: f64x2) -> i32x4;
19852006
#[link_name = "llvm.x86.sse2.cvttsd2si"]
19862007
fn cvttsd2si(a: f64x2) -> i32;
2008+
#[link_name = "llvm.x86.sse2.cvttsd2si64"]
2009+
fn cvttsd2si64(a: f64x2) -> i64;
19872010
#[link_name = "llvm.x86.sse2.cvttps2dq"]
19882011
fn cvttps2dq(a: f32x4) -> i32x4;
19892012
}
@@ -3562,6 +3585,21 @@ mod tests {
35623585
assert_eq!(r, i32::MIN);
35633586
}
35643587

3588+
#[cfg(target_arch = "x86_64")]
3589+
#[simd_test = "sse2"]
3590+
unsafe fn _mm_cvtsd_si64() {
3591+
use std::{f64, i64};
3592+
3593+
let r = sse2::_mm_cvtsd_si64(f64x2::new(-2.0, 5.0));
3594+
assert_eq!(r, -2_i64);
3595+
3596+
let r = sse2::_mm_cvtsd_si64(f64x2::new(f64::MAX, f64::MIN));
3597+
assert_eq!(r, i64::MIN);
3598+
3599+
let r = sse2::_mm_cvtsd_si64(f64x2::new(f64::NAN, f64::NAN));
3600+
assert_eq!(r, i64::MIN);
3601+
}
3602+
35653603
#[simd_test = "sse2"]
35663604
unsafe fn _mm_cvtsd_ss() {
35673605
use std::{f64, f32};
@@ -3624,6 +3662,20 @@ mod tests {
36243662
assert_eq!(r, i32::MIN);
36253663
}
36263664

3665+
#[cfg(target_arch = "x86_64")]
3666+
#[simd_test = "sse2"]
3667+
unsafe fn _mm_cvttsd_si64() {
3668+
use std::{f64, i64};
3669+
3670+
let a = f64x2::new(-1.1, 2.2);
3671+
let r = sse2::_mm_cvttsd_si64(a);
3672+
assert_eq!(r, -1_i64);
3673+
3674+
let a = f64x2::new(f64::NEG_INFINITY, f64::NAN);
3675+
let r = sse2::_mm_cvttsd_si64(a);
3676+
assert_eq!(r, i64::MIN);
3677+
}
3678+
36273679
#[simd_test = "sse2"]
36283680
unsafe fn _mm_cvttps_epi32() {
36293681
use std::{f32, i32};

0 commit comments

Comments
 (0)