Skip to content

Commit 19b2aed

Browse files
p32blognzlbg
authored andcommitted
Add _mm_test_all_zeros, _mm_test_all_ones and _mm_test_mix_ones_zeros
1 parent c8a5739 commit 19b2aed

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

src/x86/sse41.rs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,63 @@ pub unsafe fn _mm_testnzc_si128(a: i64x2, mask: i64x2) -> i32 {
469469
ptestnzc(a, mask)
470470
}
471471

472+
/// Tests whether the specified bits in a 128-bit integer vector are all
473+
/// zeros.
474+
///
475+
/// Arguments:
476+
///
477+
/// * `a` - A 128-bit integer vector containing the bits to be tested.
478+
/// * `mask` - A 128-bit integer vector selecting which bits to test in operand `a`.
479+
///
480+
/// Returns:
481+
///
482+
/// * `1` - if the specified bits are all zeros,
483+
/// * `0` - otherwise.
484+
#[inline(always)]
485+
#[target_feature = "+sse4.1"]
486+
#[cfg_attr(test, assert_instr(ptest))]
487+
pub unsafe fn _mm_test_all_zeros(a: i64x2, mask: i64x2) -> i32 {
488+
_mm_testz_si128(a, mask)
489+
}
490+
491+
/// Tests whether the specified bits in `a` 128-bit integer vector are all
492+
/// ones.
493+
///
494+
/// Argument:
495+
///
496+
/// * `a` - A 128-bit integer vector containing the bits to be tested.
497+
///
498+
/// Returns:
499+
///
500+
/// * `1` - if the bits specified in the operand are all set to 1,
501+
/// * `0` - otherwise.
502+
#[inline(always)]
503+
#[target_feature = "+sse4.1"]
504+
#[cfg_attr(test, assert_instr(pcmpeqd))]
505+
#[cfg_attr(test, assert_instr(ptest))]
506+
pub unsafe fn _mm_test_all_ones(a: i64x2) -> i32 {
507+
_mm_testc_si128(a, i64x2::splat(-1))
508+
}
509+
510+
/// Tests whether the specified bits in a 128-bit integer vector are
511+
/// neither all zeros nor all ones.
512+
///
513+
/// Arguments:
514+
///
515+
/// * `a` - A 128-bit integer vector containing the bits to be tested.
516+
/// * `mask` - A 128-bit integer vector selecting which bits to test in operand `a`.
517+
///
518+
/// Returns:
519+
///
520+
/// * `1` - if the specified bits are neither all zeros nor all ones,
521+
/// * `0` - otherwise.
522+
#[inline(always)]
523+
#[target_feature = "+sse4.1"]
524+
#[cfg_attr(test, assert_instr(ptest))]
525+
pub unsafe fn _mm_test_mix_ones_zeros(a: i64x2, mask: i64x2) -> i32 {
526+
_mm_testnzc_si128(a, mask)
527+
}
528+
472529
/// Returns the dot product of two f64x2 vectors.
473530
///
474531
/// `imm8[1:0]` is the broadcast mask, and `imm8[5:4]` is the condition mask.
@@ -1290,6 +1347,52 @@ mod tests {
12901347
assert_eq!(r, 0);
12911348
}
12921349

1350+
#[simd_test = "sse4.1"]
1351+
unsafe fn _mm_test_all_zeros() {
1352+
let a = i64x2::splat(1);
1353+
let mask = i64x2::splat(0);
1354+
let r = sse41::_mm_test_all_zeros(a, mask);
1355+
assert_eq!(r, 1);
1356+
let a = i64x2::splat(0b101);
1357+
let mask = i64x2::splat(0b110);
1358+
let r = sse41::_mm_test_all_zeros(a, mask);
1359+
assert_eq!(r, 0);
1360+
let a = i64x2::splat(0b011);
1361+
let mask = i64x2::splat(0b100);
1362+
let r = sse41::_mm_test_all_zeros(a, mask);
1363+
assert_eq!(r, 1);
1364+
}
1365+
1366+
#[simd_test = "sse4.1"]
1367+
unsafe fn _mm_test_all_ones() {
1368+
let a = i64x2::splat(-1);
1369+
let r = sse41::_mm_test_all_ones(a);
1370+
assert_eq!(r, 1);
1371+
let a = i64x2::splat(0b101);
1372+
let r = sse41::_mm_test_all_ones(a);
1373+
assert_eq!(r, 0);
1374+
}
1375+
1376+
#[simd_test = "sse4.1"]
1377+
unsafe fn _mm_test_mix_ones_zeros() {
1378+
let a = i64x2::splat(0);
1379+
let mask = i64x2::splat(1);
1380+
let r = sse41::_mm_test_mix_ones_zeros(a, mask);
1381+
assert_eq!(r, 0);
1382+
let a = i64x2::splat(-1);
1383+
let mask = i64x2::splat(0);
1384+
let r = sse41::_mm_test_mix_ones_zeros(a, mask);
1385+
assert_eq!(r, 0);
1386+
let a = i64x2::splat(0b101);
1387+
let mask = i64x2::splat(0b110);
1388+
let r = sse41::_mm_test_mix_ones_zeros(a, mask);
1389+
assert_eq!(r, 1);
1390+
let a = i64x2::splat(0b101);
1391+
let mask = i64x2::splat(0b101);
1392+
let r = sse41::_mm_test_mix_ones_zeros(a, mask);
1393+
assert_eq!(r, 0);
1394+
}
1395+
12931396
#[simd_test = "sse4.1"]
12941397
unsafe fn _mm_dp_pd() {
12951398
let a = f64x2::new(2.0, 3.0);

0 commit comments

Comments
 (0)