Repository navigation
Make RISC-V bit manipulation intrinsics match C API #2247
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
Merged
+339
−271
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
| //! RISC-V RV32 specific intrinsics | ||
|
|
||
| mod zb; | ||
| mod zk; | ||
|
|
||
| #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] | ||
| pub use zb::*; | ||
|
|
||
| #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] | ||
| pub use zk::*; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| #[cfg(test)] | ||
| use stdarch_test::assert_instr; | ||
|
|
||
| unsafe extern "llvm-intrinsic" { | ||
| #[link_name = "llvm.riscv.xperm8.i32"] | ||
| fn _xperm8_32(rs1: u32, rs2: u32) -> u32; | ||
|
|
||
| #[link_name = "llvm.riscv.xperm4.i32"] | ||
| fn _xperm4_32(rs1: u32, rs2: u32) -> u32; | ||
|
|
||
| #[link_name = "llvm.riscv.clmulh.i32"] | ||
| fn _clmulh_32(rs1: u32, rs2: u32) -> u32; | ||
|
|
||
| #[link_name = "llvm.riscv.clmulr.i32"] | ||
| fn _clmulr_32(rs1: u32, rs2: u32) -> u32; | ||
|
|
||
| #[link_name = "llvm.riscv.zip.i32"] | ||
| fn _zip_32(rs1: u32) -> u32; | ||
|
|
||
| #[link_name = "llvm.riscv.unzip.i32"] | ||
| fn _unzip_32(rs1: u32) -> u32; | ||
| } | ||
|
|
||
| /// Byte-wise lookup of indices into a vector in registers. | ||
| /// | ||
| /// The xperm8 instruction operates on bytes. The rs1 register contains a vector of 4 | ||
| /// 8-bit elements. The rs2 register contains a vector of 4 8-bit indexes. The result is | ||
| /// each element in rs2 replaced by the indexed element in rs1, or zero if the index into rs2 | ||
| /// is out of bounds. | ||
| /// | ||
| /// Source: RISC-V Cryptography Extensions Volume I: Scalar & Entropy Source Instructions | ||
| /// | ||
| /// Version: v1.0.1 | ||
| /// | ||
| /// Section: 3.47 | ||
| #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] | ||
| #[target_feature(enable = "zbkx")] | ||
| #[cfg_attr(test, assert_instr(xperm8))] | ||
| #[inline] | ||
| pub fn xperm8_32(rs1: u32, rs2: u32) -> u32 { | ||
| unsafe { _xperm8_32(rs1, rs2) } | ||
| } | ||
|
|
||
| /// Nibble-wise lookup of indices into a vector. | ||
| /// | ||
| /// The xperm4 instruction operates on nibbles. The rs1 register contains a vector of 8 | ||
| /// 4-bit elements. The rs2 register contains a vector of 8 4-bit indexes. The result is | ||
| /// each element in rs2 replaced by the indexed element in rs1, or zero if the index into rs2 | ||
| /// is out of bounds. | ||
| /// | ||
| /// Source: RISC-V Cryptography Extensions Volume I: Scalar & Entropy Source Instructions | ||
| /// | ||
| /// Version: v1.0.1 | ||
| /// | ||
| /// Section: 3.48 | ||
| #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] | ||
| #[target_feature(enable = "zbkx")] | ||
| #[cfg_attr(test, assert_instr(xperm4))] | ||
| #[inline] | ||
| pub fn xperm4_32(rs1: u32, rs2: u32) -> u32 { | ||
| unsafe { _xperm4_32(rs1, rs2) } | ||
| } | ||
|
|
||
| /// Carry-less multiply (high-part) | ||
| /// | ||
| /// clmulh produces the upper half of the 64-bit carry-less product. | ||
| /// | ||
| /// Source: RISC-V Bit-Manipulation ISA-extensions | ||
| /// | ||
| /// Version: v1.0.0 | ||
| /// | ||
| /// Section: 2.12 | ||
| #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] | ||
| #[target_feature(enable = "zbkc")] | ||
| #[cfg_attr(test, assert_instr(clmulh))] | ||
| #[inline] | ||
| pub fn clmulh_32(rs1: u32, rs2: u32) -> u32 { | ||
| unsafe { _clmulh_32(rs1, rs2) } | ||
| } | ||
|
|
||
| /// Carry-less multiply (reversed) | ||
| /// | ||
| /// clmulr produces bits 62:31 of the 64-bit carry-less product. | ||
| /// | ||
| /// Source: RISC-V Bit-Manipulation ISA-extensions | ||
| /// | ||
| /// Version: v1.0.0 | ||
| /// | ||
| /// Section: 2.13 | ||
| #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] | ||
| #[target_feature(enable = "zbc")] | ||
| #[cfg_attr(test, assert_instr(clmulr))] | ||
| #[inline] | ||
| pub fn clmulr_32(rs1: u32, rs2: u32) -> u32 { | ||
| unsafe { _clmulr_32(rs1, rs2) } | ||
| } | ||
|
|
||
| /// Place upper/lower halves of the source register into odd/even bits of the destination | ||
| /// respectivley. | ||
| /// | ||
| /// This instruction places bits in the low half of the source register into the even bit | ||
| /// positions of the destination, and bits in the high half of the source register into the odd | ||
| /// bit positions of the destination. It is the inverse of the unzip instruction. This | ||
| /// instruction is available only on RV32. | ||
| /// | ||
| /// Source: RISC-V Cryptography Extensions Volume I: Scalar & Entropy Source Instructions | ||
| /// | ||
| /// Version: v1.0.1 | ||
| /// | ||
| /// Section: 3.49 | ||
| #[target_feature(enable = "zbkb")] | ||
| // See #1464 | ||
| // #[cfg_attr(test, assert_instr(zip))] | ||
| #[inline] | ||
| #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] | ||
| pub fn zip_32(rs: u32) -> u32 { | ||
| unsafe { _zip_32(rs) } | ||
| } | ||
|
|
||
| /// Place odd and even bits of the source word into upper/lower halves of the destination. | ||
| /// | ||
| /// This instruction places the even bits of the source register into the low half of the | ||
| /// destination, and the odd bits of the source into the high bits of the destination. It is | ||
| /// the inverse of the zip instruction. This instruction is available only on RV32. | ||
| /// | ||
| /// Source: RISC-V Cryptography Extensions Volume I: Scalar & Entropy Source Instructions | ||
| /// | ||
| /// Version: v1.0.1 | ||
| /// | ||
| /// Section: 3.45 | ||
| #[target_feature(enable = "zbkb")] | ||
| #[cfg_attr(test, assert_instr(unzip))] | ||
| #[inline] | ||
| #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] | ||
| pub fn unzip_32(rs: u32) -> u32 { | ||
| unsafe { _unzip_32(rs) } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.