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

add the llvm.x86.sse42.crc32.32.32 intrinsic #1488

Merged
merged 2 commits into from
May 11, 2024

Conversation

folkertdev
Copy link
Contributor

part of #1487

how should this be tested? I exercised the instruction by compiling and running (part of) the test suite of zlib-rs, is that sufficient?

I can add the other variations of this instruction (having a differently-sized v argument) but those are not used by zlib-rs so some dedicated testing would presumably be required for them?

Comment on lines +846 to +855
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::ax)),
_late: true,
in_value: crc,
out_place: Some(ret),
},
CInlineAsmOperand::In {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::dx)),
value: v,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is there any particular reason to choose particular register names here? this seemed to be the ordering used in some of the other examples.

Copy link
Member

Choose a reason for hiding this comment

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

There is no particular reason for the choice of registers.

Copy link
Member

@bjorn3 bjorn3 left a comment

Choose a reason for hiding this comment

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

I can add the other variations of this instruction (having a differently-sized v argument) but those are not used by zlib-rs so some dedicated testing would presumably be required for them?

Running the stdarch test suite should cover this. I can run it for you if you want add the other variants, but implementing them as needed is fine too.

how should this be tested? I exercised the instruction by compiling and running (part of) the test suite of zlib-rs, is that sufficient?

example/std_example.rs has various simd tests. You can copy the test from stdarch there and call it as regular function in test_simd.

src/intrinsics/llvm_x86.rs Outdated Show resolved Hide resolved
Comment on lines +846 to +855
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::ax)),
_late: true,
in_value: crc,
out_place: Some(ret),
},
CInlineAsmOperand::In {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::dx)),
value: v,
},
Copy link
Member

Choose a reason for hiding this comment

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

There is no particular reason for the choice of registers.

@bjorn3 bjorn3 added the A-core-arch Area: Necessary for full core::arch support label May 11, 2024
Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
@bjorn3 bjorn3 merged commit 7b50189 into rust-lang:master May 11, 2024
18 checks passed
@bjorn3
Copy link
Member

bjorn3 commented May 11, 2024

Thanks!

@bjorn3 bjorn3 mentioned this pull request May 11, 2024
2 tasks
@folkertdev
Copy link
Contributor Author

that testing approach does not quite work because

[AOT] arbitrary_self_types_pointers_and_wrappers
[BUILD] alloc_system
[AOT] alloc_example
Hello World!
[JIT] std_example
error: Inline asm is not supported in JIT mode

error: aborting due to 1 previous error

so then I guess local testing just has to suffice (for now)?

for future reference, here is the test

#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "sse4.2")]
unsafe fn test_crc32() {
    assert!(is_x86_feature_detected!("sse4.2"));

    let a = 42u32;
    let b = 0xdeadbeefu64;

    assert_eq!(_mm_crc32_u8(a, b as u8), 4135334616);
    assert_eq!(_mm_crc32_u16(a, b as u16), 1200687288);
    assert_eq!(_mm_crc32_u32(a, b as u32), 2543798776);
    assert_eq!(_mm_crc32_u64(a as u64, b as u64), 241952147);
}

@bjorn3
Copy link
Member

bjorn3 commented May 11, 2024

Adding #[cfg(not(jit))] should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core-arch Area: Necessary for full core::arch support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants