Skip to content

Commit 6147f16

Browse files
committed
Add _mm_cmpord_ss
1 parent bc78ea3 commit 6147f16

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/x86/sse.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,17 @@ pub unsafe fn _mm_cmpnge_ss(a: f32x4, b: f32x4) -> f32x4 {
320320
simd_shuffle4(a, cmpss(b, a, 6), [4, 1, 2, 3])
321321
}
322322

323+
/// Check if the lowest `f32` of both inputs are ordered. The lowest 32 bits of
324+
/// the result will be `0xffffffff` if neither of `a.extract(0)` or
325+
/// `b.extract(0)` is a NaN, or `0` otherwise. The upper 96 bits of the result
326+
/// are the upper 96 bits of `a`.
327+
#[inline(always)]
328+
#[target_feature = "+sse"]
329+
#[cfg_attr(test, assert_instr(cmpordss))]
330+
pub unsafe fn _mm_cmpord_ss(a: f32x4, b: f32x4) -> f32x4 {
331+
cmpss(a, b, 7)
332+
}
333+
323334
/// Construct a `f32x4` with the lowest element set to `a` and the rest set to
324335
/// zero.
325336
#[inline(always)]
@@ -1522,6 +1533,36 @@ mod tests {
15221533
assert_eq!(rd, ed);
15231534
}
15241535

1536+
#[simd_test = "sse"]
1537+
unsafe fn _mm_cmpord_ss() {
1538+
// TODO: This test is exactly the same as for _mm_cmplt_ss, but there
1539+
// must be a difference. It may have to do with behavior in the presence
1540+
// of NaNs (signaling or quiet). If so, we should add tests for those.
1541+
use std::mem::transmute;
1542+
use std::f32::NAN;
1543+
1544+
let a = f32x4::new(1.0, 2.0, 3.0, 4.0);
1545+
let b = f32x4::new(0.0, 5.0, 6.0, 7.0);
1546+
let c = f32x4::new(NAN, 5.0, 6.0, 7.0);
1547+
let d = f32x4::new(2.0, 5.0, 6.0, 7.0);
1548+
1549+
let b1 = !0u32; // a.extract(0) ord b.extract(0)
1550+
let c1 = 0u32; // a.extract(0) ord c.extract(0)
1551+
let d1 = !0u32; // a.extract(0) ord d.extract(0)
1552+
1553+
let rb: u32x4 = transmute(sse::_mm_cmpord_ss(a, b));
1554+
let eb: u32x4 = transmute(f32x4::new(transmute(b1), 2.0, 3.0, 4.0));
1555+
assert_eq!(rb, eb);
1556+
1557+
let rc: u32x4 = transmute(sse::_mm_cmpord_ss(a, c));
1558+
let ec: u32x4 = transmute(f32x4::new(transmute(c1), 2.0, 3.0, 4.0));
1559+
assert_eq!(rc, ec);
1560+
1561+
let rd: u32x4 = transmute(sse::_mm_cmpord_ss(a, d));
1562+
let ed: u32x4 = transmute(f32x4::new(transmute(d1), 2.0, 3.0, 4.0));
1563+
assert_eq!(rd, ed);
1564+
}
1565+
15251566
#[simd_test = "sse"]
15261567
unsafe fn _mm_set_ss() {
15271568
let r = sse::_mm_set_ss(black_box(4.25));

0 commit comments

Comments
 (0)