I tried this code:
https://rust.godbolt.org/z/hq1s1voWP
#![feature(portable_simd)]
use std::simd::prelude::*;
type Elm = i8;
const N: usize = 64;
#[unsafe(no_mangle)]
pub fn mask_lt(a: u64, b: u64) -> u64 {
let a = Mask::<Elm, N>::from_bitmask(a);
let b = Mask::<Elm, N>::from_bitmask(b);
a.simd_lt(b).to_bitmask()
}
#[unsafe(no_mangle)]
pub fn bool_lt(a: u64, b: u64) -> u64 {
let a = Mask::<Elm, N>::from_bitmask(a);
let b = Mask::<Elm, N>::from_bitmask(b);
Mask::<Elm, N>::from_array(std::array::from_fn(|i| a.test(i) < b.test(i))).to_bitmask()
}
I expected to see this happen: bool_lt and mask_lt give identical results
Instead, this happened: mask_lt(a, b) acts like bool_lt(b, a) because Mask::simd_lt compares the mask elements as signed integers which doesn't match what I'd expect (I expect basically Simd<bool, N>).
Meta
rustc version:
rustc 1.95.0
crate version:
version included in 1.95.0
I tried this code:
https://rust.godbolt.org/z/hq1s1voWP
I expected to see this happen:
bool_ltandmask_ltgive identical resultsInstead, this happened:
mask_lt(a, b)acts likebool_lt(b, a)becauseMask::simd_ltcompares the mask elements as signed integers which doesn't match what I'd expect (I expect basicallySimd<bool, N>).Meta
rustc version:
rustc 1.95.0
crate version:
version included in 1.95.0