Repository navigation
Make RISC-V bit manipulation intrinsics match C API - #2247
TechnoPorg wants to merge 2 commits into
Conversation
|
Thanks for the pull request, and welcome! The Rust Project has assigned @davidtwco (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks. Why was this reviewer chosen?The reviewer was selected based on:
|
daad938 to
964ad8c
Compare
|
@rustbot label +I-libs-nominated I think this is the direction that we've heard more favor towards, but the meeting should confirm this is okay since there was a bit of back and forth and we haven't had a ton of feedback. This also serves as a heads up that it will probably be headed for stabilization in the near future, in case there's anything to discuss there. For other opinions, pinging maintainers @kito-cheng @michaelmaitland @robin-randhawa-sifive @topperc, the question is whether these should take fixed-size integers or |
|
The bitmanip C intrinsic interface in clang and gcc has uint32_t intrinsics for RV32 and RV64 and uint64_t intrinsics for RV64. This allows some source code compatibility between RV32 and RV64. I also assumed that bit manipulation code would be written with a specific number of bits in mind. Looking at this patch, it looks like u32 is RV32 only and u64 is RV64 only. Is that right? |
This matches the code that was there before, but I'll look to see whether LLVM exposes any intrinsics that let us mix and match. |
|
If RV64 supports both then that actually sounds like a nicer option. Where is this defined, though? https://github.com/riscv-non-isa/riscv-c-api-doc/blob/main/src/c-api.adoc#scalar-bit-manipulation-extension-intrinsics for example lists both |
You're right we're not completely consistent about it. I think clmulh.i32 and clmulr.i32 do work on RV64 in the LLVM backend they just didn't get exposed to frontend. __riscv_clz_32, __riscv_ctz_32, __riscv_cpop_32, __riscv_orc_b_32, __riscv_ror_32, __riscv_rol_32, __riscv_rev8_32, __riscv_brev8_32, __riscv_clmul_32 should all work for RV64. __riscv_zip_32 and __riscv_unzip_32 aren't on RV64 because the underlying zip/unzip instructions are RV32 only. __riscv_clmulh_32, __riscv_clmulr_32 aren't supported on RV64. It is doable, but requires 3-4 instructions. __riscv_xperm4_32, __riscv_xperm8_32 aren't supported on RV64 because we'd need additional instructions to modify the indices to emulate the out of bounds indices being 0 behavior. As I write this, I guess we just need to zero extend rs1? Maybe it's not so bad. |
|
Thanks for bringing that up, I think that may be a good option for us as well. I'm going to bring this up at rust-lang/rust#114544 and move the nomination label there since some other naming discussion has already happened there. |
42cd3a0 to
9dd1332
Compare
|
Would it be possible create |
Not here, but all of our risc-v API could use a review that it matches https://github.com/riscv-non-isa/riscv-c-api-doc/blob/main/src/c-api.adoc. So a separate PR updating those would be welcome once this merges. |
Also exposes the 32-bit intrinsics that are supported on RV64 in riscv_shared
5ef95b1 to
ae0ed77
Compare
|
@tgross35 any idea what's going on with the libc SYS_futex and Intel ICX errors in CI? The only thing that changed between force pushes was some doc stuff and the order of commits, so it feels unrelated. |
|
It's a T3 platform that had some syscall changes rust-lang/libc@181ab01, std will need to be updated. Also those platforms need some maintainers... |
As per rust-lang/rust#114544 and the recent libs team decision (https://hackmd.io/@rust-libs/SJFLHWcozl), this switches the RISC-V bit manipulation intrinsics to use u32/u64 instead of usize, as this aligns better with how they're actually applied.
I've also opted to move all the implemented bit manipulation intrinsics into
zb.rs, since they happen to be pulled in under theZknumbrella (https://docs.riscv.org/reference/isa/v20260120/unpriv/scalar-crypto.html, https://docs.riscv.org/reference/isa/v20260120/unpriv/b-st-ext.html) but aren't "cryptography" intrinsics in the same way.I have not touched any of the
Pextension, but I can if desired.cc @tgross35