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

Sign extension issue #4

Merged
merged 2 commits into from
Jun 8, 2020
Merged

Sign extension issue #4

merged 2 commits into from
Jun 8, 2020

Conversation

AdrianCX
Copy link
Contributor

@AdrianCX AdrianCX commented Jun 8, 2020

Function from: https://doc.rust-lang.org/beta/src/core/up/stdarch/crates/core_arch/src/x86/sse2.rs.html#1377-1379

pub unsafe fn _mm_extract_epi16(a: __m128i, imm8: i32) -> i32 {
    simd_extract::<_, i16>(a.as_i16x8(), (imm8 & 7) as u32) as i32
}

Extracts as i16 and then converts i16 to i32... which does sign extension - instead of getting 0xffff we get 0xffffffff

This is contrary to intel documentation:
https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_extract_epi16&expand=2426

Cargo.toml Outdated Show resolved Hide resolved
src/decode/avx2.rs Outdated Show resolved Hide resolved
src/decode/mod.rs Outdated Show resolved Hide resolved
@jethrogb
Copy link
Member

jethrogb commented Jun 8, 2020

Please add some tests that cover the changes you made

@AdrianCX AdrianCX force-pushed the acruceru/sign-extension-bug branch 2 times, most recently from 1fa096e to 6427ca3 Compare June 8, 2020 17:04
Copy link
Member

@jethrogb jethrogb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please bump patch version in Cargo.toml

src/decode/avx2.rs Show resolved Hide resolved
@AdrianCX AdrianCX force-pushed the acruceru/sign-extension-bug branch from 6427ca3 to 91e5104 Compare June 8, 2020 17:33
https://doc.rust-lang.org/beta/src/core/up/stdarch/crates/core_arch/src/x86/sse2.rs.html#1377-1379
pub unsafe fn _mm_extract_epi16(a: __m128i, imm8: i32) -> i32 {
    simd_extract::<_, i16>(a.as_i16x8(), (imm8 & 7) as u32) as i32
}

It extracts as i16 and then converts i16 to i32... which does sign extension.

Which means we cannot use the function directly - we need to cast to u16 first then to u32 - otherwise we get 0xffffffff instead of 0xffff
@AdrianCX AdrianCX force-pushed the acruceru/sign-extension-bug branch from 91e5104 to b4acfb7 Compare June 8, 2020 17:35
@AdrianCX AdrianCX merged commit 056dc96 into master Jun 8, 2020
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

Successfully merging this pull request may close these issues.

2 participants