Skip to content

Commit 718e627

Browse files
pythoneeralexcrichton
authored andcommitted
added _mm_cvttps_epi32 (rust-lang#89)
1 parent e811963 commit 718e627

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Diff for: src/x86/sse2.rs

+25
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,16 @@ pub unsafe fn _mm_cvttsd_si32(a: f64x2) -> i32 {
17801780
cvttsd2si(a)
17811781
}
17821782

1783+
/// Convert packed single-precision (32-bit) floating-point elements in `a` to packed 32-bit
1784+
/// integers with truncation
1785+
#[inline(always)]
1786+
#[target_feature = "+sse2"]
1787+
#[cfg_attr(test, assert_instr(cvttps2dq))]
1788+
pub unsafe fn _mm_cvttps_epi32(a: f32x4) -> i32x4 {
1789+
cvttps2dq(a)
1790+
}
1791+
1792+
17831793
/// Return a mask of the most significant bit of each element in `a`.
17841794
///
17851795
/// The mask is stored in the 2 least significant bits of the return value.
@@ -1967,6 +1977,8 @@ extern {
19671977
fn cvttpd2dq(a: f64x2) -> i32x4;
19681978
#[link_name = "llvm.x86.sse2.cvttsd2si"]
19691979
fn cvttsd2si(a: f64x2) -> i32;
1980+
#[link_name = "llvm.x86.sse2.cvttps2dq"]
1981+
fn cvttps2dq(a: f32x4) -> i32x4;
19701982
}
19711983

19721984
#[cfg(test)]
@@ -3605,6 +3617,19 @@ mod tests {
36053617
assert_eq!(r, i32::MIN);
36063618
}
36073619

3620+
#[simd_test = "sse2"]
3621+
unsafe fn _mm_cvttps_epi32() {
3622+
use std::{f32, i32};
3623+
3624+
let a = f32x4::new(-1.1, 2.2, -3.3, 6.6);
3625+
let r = sse2::_mm_cvttps_epi32(a);
3626+
assert_eq!(r, i32x4::new(-1, 2, -3, 6));
3627+
3628+
let a = f32x4::new(f32::NEG_INFINITY, f32::INFINITY, f32::MIN, f32::MAX);
3629+
let r = sse2::_mm_cvttps_epi32(a);
3630+
assert_eq!(r, i32x4::new(i32::MIN, i32::MIN, i32::MIN, i32::MIN));
3631+
}
3632+
36083633
#[simd_test = "sse2"]
36093634
unsafe fn _mm_load1_pd() {
36103635
let d = -5.0;

0 commit comments

Comments
 (0)