Skip to content

SimdPartialOrd methods for Mask don't match PartialOrd methods for bool #527

Description

@programmerjake

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions