rust-lang / rustc_codegen_cranelift

Cranelift based backend for rustc
Apache License 2.0
1.59k stars 100 forks source link

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

Closed folkertdev closed 4 months ago

folkertdev commented 4 months ago

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?

bjorn3 commented 4 months ago

Thanks!

folkertdev commented 4 months ago

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 commented 4 months ago

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