rust-lang / rustc_codegen_cranelift

Cranelift based backend for rustc
Apache License 2.0
1.52k stars 94 forks source link

Unimplemented intrinsic `_mm_clmulepi64_si128` #1415

Closed afonso360 closed 7 months ago

afonso360 commented 8 months ago

👋 Hey,

I tried to run simd-json with cranelift as a backend and the testsuite fails with the following error:

running 276 tests
trap at Instance { def: Item(DefId(2:14922 ~ core[53bd]::core_arch::x86::pclmulqdq::_mm_clmulepi64_si128)), args: [0_i32] } (_ZN4core9core_arch3x869pclmulqdq20_mm_clmulepi64_si12817h746cb06518f50faaE): llvm.x86.pclmulqdq
error: test failed, to rerun pass `--lib`

It looks like we are missing the _mm_clmulepi64_si128 intrinsic.

I'd like to give it a go at implementing this intrinsic but it looks like its complicated enough (pseudocode) that it would probably warrant a libcall equivalent. Do we have a way of defining our own functions that we could inject into the final binary in a similar way to libcall's?

I think it's possible to implement this entirely in cranelift, but It doesn't look like the best way to go about it.

I should also note that simd-json compiles and passes its testsuite cleanly when disabling runtime feature detection. So that is an option for anyone wanting to use this library.

bjorn3 commented 7 months ago

I'd like to give it a go at implementing this intrinsic but it looks like its complicated enough (pseudocode) that it would probably warrant a libcall equivalent. Do we have a way of defining our own functions that we could inject into the final binary in a similar way to libcall's?

We don't have a way to define libcalls. I've just been producing incredibly bloated code with all loops unrolled in the generated clif ir for simd intrinsics right now :)

bjorn3 commented 7 months ago

I'm currently implementing this.

bjorn3 commented 7 months ago

Done in https://github.com/rust-lang/rustc_codegen_cranelift/pull/1417