Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Surprising behavior of portable SIMD integer vector max/min #94682

Closed
RalfJung opened this issue Mar 6, 2022 · 4 comments
Closed

Surprising behavior of portable SIMD integer vector max/min #94682

RalfJung opened this issue Mar 6, 2022 · 4 comments

Comments

@RalfJung
Copy link
Member

RalfJung commented Mar 6, 2022

The following code does not print what I would expect:

#![feature(portable_simd)]
use std::simd::*;

fn main() {
    let a = i32x4::splat(10);
    let b = i32x4::from_array([1, 2, 12, -4]);
    println!("{:?} {:?}", a.max(b), a.min(b));
}

I expected element-wise max/min, but I got:

[10, 10, 10, 10] [1, 2, 12, -4]

The funny thing is that portable-simd does not even define max/min on its integer SIMD types (only on the float ones). What happens is that it falls back to Ord::max, and it looks like vectors implement Ord by comparing them as arrays, which probably uses lexicographic comparison.

However this means integer and float vectors max/min methods behave very differently, so this is probably not intended?

Cc @workingjubilee

@jfrimmel
Copy link
Contributor

jfrimmel commented Mar 7, 2022

I think this is the same as rust-lang/portable-simd#247 and rust-lang/portable-simd#253.

@RalfJung
Copy link
Member Author

RalfJung commented Mar 7, 2022

Ah, it is.

Not sure which issue tracker is the preferred one for such issues.

@workingjubilee
Copy link
Member

Hello!
Yes, it is a bit peculiar and we should fix that.
We usually track library-level issues over there and integration-level issues on the Rust issue tracker.

@RalfJung
Copy link
Member Author

Fixed by rust-lang/portable-simd#260
(though clamp remains unfixed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants