Skip to content

Commit

Permalink
Sse2 (rust-lang#116)
Browse files Browse the repository at this point in the history
* added _mm_cvtsd_si64

* added _mm_cvttsd_si64; target_arch to _mm_cvtsd_si64 test
  • Loading branch information
pythoneer authored and alexcrichton committed Oct 14, 2017
1 parent f7cc842 commit 3e83d38
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/x86/sse2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,15 @@ pub unsafe fn _mm_cvtsd_si32(a: f64x2) -> i32 {
cvtsd2si(a)
}

/// Convert the lower double-precision (64-bit) floating-point element in a to a 64-bit integer.
#[cfg(target_arch = "x86_64")]
#[inline(always)]
#[target_feature = "+sse2"]
#[cfg_attr(test, assert_instr(cvtsd2si))]
pub unsafe fn _mm_cvtsd_si64(a: f64x2) -> i64 {
cvtsd2si64(a)
}

/// Convert the lower double-precision (64-bit) floating-point element in `b` to a
/// single-precision (32-bit) floating-point element, store the result in the lower element
/// of the return value, and copy the upper element from `a` to the upper element the return value.
Expand Down Expand Up @@ -1780,6 +1789,16 @@ pub unsafe fn _mm_cvttsd_si32(a: f64x2) -> i32 {
cvttsd2si(a)
}

/// Convert the lower double-precision (64-bit) floating-point element in `a` to a 64-bit integer
/// with truncation.
#[cfg(target_arch = "x86_64")]
#[inline(always)]
#[target_feature = "+sse2"]
#[cfg_attr(test, assert_instr(cvttsd2si))]
pub unsafe fn _mm_cvttsd_si64(a: f64x2) -> i64 {
cvttsd2si64(a)
}

/// Convert packed single-precision (32-bit) floating-point elements in `a` to packed 32-bit
/// integers with truncation
#[inline(always)]
Expand Down Expand Up @@ -1976,6 +1995,8 @@ extern {
fn cvtpd2dq(a: f64x2) -> i32x4;
#[link_name = "llvm.x86.sse2.cvtsd2si"]
fn cvtsd2si(a: f64x2) -> i32;
#[link_name = "llvm.x86.sse2.cvtsd2si64"]
fn cvtsd2si64(a: f64x2) -> i64;
#[link_name = "llvm.x86.sse2.cvtsd2ss"]
fn cvtsd2ss(a: f32x4, b: f64x2) -> f32x4;
#[link_name = "llvm.x86.sse2.cvtss2sd"]
Expand All @@ -1984,6 +2005,8 @@ extern {
fn cvttpd2dq(a: f64x2) -> i32x4;
#[link_name = "llvm.x86.sse2.cvttsd2si"]
fn cvttsd2si(a: f64x2) -> i32;
#[link_name = "llvm.x86.sse2.cvttsd2si64"]
fn cvttsd2si64(a: f64x2) -> i64;
#[link_name = "llvm.x86.sse2.cvttps2dq"]
fn cvttps2dq(a: f32x4) -> i32x4;
}
Expand Down Expand Up @@ -3562,6 +3585,21 @@ mod tests {
assert_eq!(r, i32::MIN);
}

#[cfg(target_arch = "x86_64")]
#[simd_test = "sse2"]
unsafe fn _mm_cvtsd_si64() {
use std::{f64, i64};

let r = sse2::_mm_cvtsd_si64(f64x2::new(-2.0, 5.0));
assert_eq!(r, -2_i64);

let r = sse2::_mm_cvtsd_si64(f64x2::new(f64::MAX, f64::MIN));
assert_eq!(r, i64::MIN);

let r = sse2::_mm_cvtsd_si64(f64x2::new(f64::NAN, f64::NAN));
assert_eq!(r, i64::MIN);
}

#[simd_test = "sse2"]
unsafe fn _mm_cvtsd_ss() {
use std::{f64, f32};
Expand Down Expand Up @@ -3624,6 +3662,20 @@ mod tests {
assert_eq!(r, i32::MIN);
}

#[cfg(target_arch = "x86_64")]
#[simd_test = "sse2"]
unsafe fn _mm_cvttsd_si64() {
use std::{f64, i64};

let a = f64x2::new(-1.1, 2.2);
let r = sse2::_mm_cvttsd_si64(a);
assert_eq!(r, -1_i64);

let a = f64x2::new(f64::NEG_INFINITY, f64::NAN);
let r = sse2::_mm_cvttsd_si64(a);
assert_eq!(r, i64::MIN);
}

#[simd_test = "sse2"]
unsafe fn _mm_cvttps_epi32() {
use std::{f32, i32};
Expand Down

0 comments on commit 3e83d38

Please sign in to comment.