Skip to content

x86_64 simd fmadd (and other) bug (release only) #56950

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

Closed
kali opened this issue Dec 18, 2018 · 11 comments
Closed

x86_64 simd fmadd (and other) bug (release only) #56950

kali opened this issue Dec 18, 2018 · 11 comments

Comments

@kali
Copy link
Contributor

kali commented Dec 18, 2018

This bit of code falls in the assert in Release, while working in Debug.

Both stable and nightly.

https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=6f280db2aaf8241e46a080f4189e0328

use std::arch::x86_64::*;

fn main() {
        unsafe {
            let a = [2.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
            let b = -1.0f32;

            let ar = _mm256_loadu_ps(a.as_ptr());
            println!("ar: {:?}", ar);
            let br = _mm256_set1_ps(b);
            println!("br: {:?}", br);
            let mut abr = _mm256_setzero_ps();
            println!("ab: {:?}", abr);
            abr = _mm256_fmadd_ps(ar, br, abr);
            println!("ab: {:?}", abr);
            
            let mut ab = [0.0; 8];
            _mm256_storeu_ps(ab.as_mut_ptr(), abr);
            assert_eq!(ab[0], -2.0f32);
    }
}
@kali
Copy link
Contributor Author

kali commented Dec 18, 2018

might be related to #50154

@kali
Copy link
Contributor Author

kali commented Dec 18, 2018

Problem was discovered on a skylake mac, if it helps.

@peterjoel
Copy link
Contributor

Perhaps not discovered sooner because the function isn't being used much. I found it in two Github repositories:

@peterjoel
Copy link
Contributor

Problem is also present on my i7-4960HQ Mac.

@kali
Copy link
Contributor Author

kali commented Dec 18, 2018

@kali kali changed the title x86_64 simd fmadd bug (release only) x86_64 simd fmadd (and other) bug (release only) Dec 18, 2018
@lqd
Copy link
Member

lqd commented Dec 18, 2018

Yeah, it doesn't look like the problem lies with the functions themselves, like this simple 2.0 * 1.0 multiplication shows.

So it could indeed be an instance of the linked LLVM by-ref args promotion issue ?

@BurntSushi
Copy link
Member

What is the expected behavior here? From what I can tell, the given code isn't correct because you aren't using #[target_feature(enable = "avx2")]. (Alternatively, compile with RUSTFLAGS="-C target-feature=+avx2".)

I think you'll want to have a careful review of https://doc.rust-lang.org/std/arch/index.html#overview and https://doc.rust-lang.org/std/arch/index.html#dynamic-cpu-feature-detection

@hellow554
Copy link
Contributor

hellow554 commented Dec 18, 2018

@BurntSushi why avx2? According to the doc it only requires "avx"

@BurntSushi
Copy link
Member

@hellow554 I didn't check the precise requirements of each individual vendor intrinsic, and I don't have them memorized. :-) Feel free to s/avx2/avx, but I don't think my general point changes.

@lqd
Copy link
Member

lqd commented Dec 18, 2018

#[target_feature(enable = "avx")] works indeed.

@kali
Copy link
Contributor Author

kali commented Dec 18, 2018

all right... going back to hiding, thanks folks :)

@kali kali closed this as completed Dec 18, 2018
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

5 participants