Skip to main content

core/stdarch/crates/core_arch/src/riscv64/
zb.rs

1#[cfg(test)]
2use stdarch_test::assert_instr;
3
4unsafe extern "llvm-intrinsic" {
5    #[link_name = "llvm.riscv.xperm8.i64"]
6    fn _xperm8_64(rs1: u64, rs2: u64) -> u64;
7
8    #[link_name = "llvm.riscv.xperm4.i64"]
9    fn _xperm4_64(rs1: u64, rs2: u64) -> u64;
10
11    #[link_name = "llvm.riscv.orc.b.i64"]
12    fn _orc_b_64(rs: u64) -> u64;
13
14    #[link_name = "llvm.riscv.clmul.i64"]
15    fn _clmul_64(rs1: u64, rs2: u64) -> u64;
16
17    #[link_name = "llvm.riscv.clmulh.i64"]
18    fn _clmulh_64(rs1: u64, rs2: u64) -> u64;
19
20    #[link_name = "llvm.riscv.clmulr.i64"]
21    fn _clmulr_64(rs1: u64, rs2: u64) -> u64;
22}
23
24/// Byte-wise lookup of indices into a vector in registers.
25///
26/// The xperm8 instruction operates on bytes. The rs1 register contains a vector of 8
27/// 8-bit elements. The rs2 register contains a vector of 8 8-bit indexes. The result is
28/// each element in rs2 replaced by the indexed element in rs1, or zero if the index into rs2
29/// is out of bounds.
30///
31/// Source: RISC-V Cryptography Extensions Volume I: Scalar & Entropy Source Instructions
32///
33/// Version: v1.0.1
34///
35/// Section: 3.47
36#[unstable(feature = "riscv_ext_intrinsics", issue = "114544")]
37#[target_feature(enable = "zbkx")]
38#[cfg_attr(test, assert_instr(xperm8))]
39#[inline]
40pub fn xperm8_64(rs1: u64, rs2: u64) -> u64 {
41    unsafe { _xperm8_64(rs1, rs2) }
42}
43
44/// Nibble-wise lookup of indices into a vector.
45///
46/// The xperm4 instruction operates on nibbles. The rs1 register contains a vector of 16
47/// 4-bit elements. The rs2 register contains a vector of 16 4-bit indexes. The result is
48/// each element in rs2 replaced by the indexed element in rs1, or zero if the index into rs2
49/// is out of bounds.
50///
51/// Source: RISC-V Cryptography Extensions Volume I: Scalar & Entropy Source Instructions
52///
53/// Version: v1.0.1
54///
55/// Section: 3.48
56#[unstable(feature = "riscv_ext_intrinsics", issue = "114544")]
57#[target_feature(enable = "zbkx")]
58#[cfg_attr(test, assert_instr(xperm4))]
59#[inline]
60pub fn xperm4_64(rs1: u64, rs2: u64) -> u64 {
61    unsafe { _xperm4_64(rs1, rs2) }
62}
63
64/// Bitwise OR-Combine, byte granule
65///
66/// Combines the bits within every byte through a reciprocal bitwise logical OR. This sets the bits of each byte in
67/// the result rd to all zeros if no bit within the respective byte of rs is set, or to all ones if any bit within the
68/// respective byte of rs is set.
69///
70/// Source: RISC-V Bit-Manipulation ISA-extensions
71///
72/// Version: v1.0.0
73///
74/// Section: 2.24
75#[unstable(feature = "riscv_ext_intrinsics", issue = "114544")]
76#[target_feature(enable = "zbb")]
77#[cfg_attr(test, assert_instr(orc.b))]
78#[inline]
79pub fn orc_b_64(rs: u64) -> u64 {
80    unsafe { _orc_b_64(rs) }
81}
82
83/// Carry-less multiply (low-part)
84///
85/// clmul produces the lower half of the 128-bit carry-less product.
86///
87/// Source: RISC-V Bit-Manipulation ISA-extensions
88///
89/// Version: v1.0.0
90///
91/// Section: 2.11
92#[unstable(feature = "riscv_ext_intrinsics", issue = "114544")]
93#[target_feature(enable = "zbkc")]
94#[cfg_attr(test, assert_instr(clmul))]
95#[inline]
96pub fn clmul_64(rs1: u64, rs2: u64) -> u64 {
97    unsafe { _clmul_64(rs1, rs2) }
98}
99
100/// Carry-less multiply (high-part)
101///
102/// clmulh produces the upper half of the 128-bit carry-less product.
103///
104/// Source: RISC-V Bit-Manipulation ISA-extensions
105///
106/// Version: v1.0.0
107///
108/// Section: 2.12
109#[unstable(feature = "riscv_ext_intrinsics", issue = "114544")]
110#[target_feature(enable = "zbkc")]
111#[cfg_attr(test, assert_instr(clmulh))]
112#[inline]
113pub fn clmulh_64(rs1: u64, rs2: u64) -> u64 {
114    unsafe { _clmulh_64(rs1, rs2) }
115}
116
117/// Carry-less multiply (reversed)
118///
119/// clmulr produces bits 126:63 of the 128-bit carry-less product.
120///
121/// Source: RISC-V Bit-Manipulation ISA-extensions
122///
123/// Version: v1.0.0
124///
125/// Section: 2.13
126#[unstable(feature = "riscv_ext_intrinsics", issue = "114544")]
127#[target_feature(enable = "zbc")]
128#[cfg_attr(test, assert_instr(clmulr))]
129#[inline]
130pub fn clmulr_64(rs1: u64, rs2: u64) -> u64 {
131    unsafe { _clmulr_64(rs1, rs2) }
132}