Skip to content

Commit 6c5ff3b

Browse files
coastalwhiteAmanieu
authored andcommitted
Fix: Add constant for assert_instr
1 parent 41da692 commit 6c5ff3b

File tree

3 files changed

+14
-41
lines changed

3 files changed

+14
-41
lines changed

crates/core_arch/src/riscv32/zk.rs

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
#[cfg(test)]
22
use stdarch_test::assert_instr;
33

4-
macro_rules! static_assert_imm2 {
5-
($imm:ident) => {
6-
static_assert!(
7-
$imm < 4,
8-
"Immediate value allowed to be a constant from 0 up to including 3"
9-
)
10-
};
11-
}
12-
134
extern "unadjusted" {
145
#[link_name = "llvm.riscv.aes32esi"]
156
fn _aes32esi(rs1: i32, rs2: i32, bs: i32) -> i32;
@@ -71,10 +62,10 @@ extern "unadjusted" {
7162
/// This function is safe to use if the `zkne` target feature is present.
7263
#[target_feature(enable = "zkne")]
7364
#[rustc_legacy_const_generics(2)]
74-
#[cfg_attr(test, assert_instr(aes32esi))]
65+
#[cfg_attr(test, assert_instr(aes32esi, BS = 0))]
7566
#[inline]
7667
pub unsafe fn aes32esi<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
77-
static_assert_imm2!(BS);
68+
static_assert!(BS < 4);
7869

7970
_aes32esi(rs1 as i32, rs2 as i32, BS as i32) as u32
8071
}
@@ -102,10 +93,10 @@ pub unsafe fn aes32esi<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
10293
/// This function is safe to use if the `zkne` target feature is present.
10394
#[target_feature(enable = "zkne")]
10495
#[rustc_legacy_const_generics(2)]
105-
#[cfg_attr(test, assert_instr(aes32esmi))]
96+
#[cfg_attr(test, assert_instr(aes32esmi, BS = 0))]
10697
#[inline]
10798
pub unsafe fn aes32esmi<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
108-
static_assert_imm2!(BS);
99+
static_assert!(BS < 4);
109100

110101
_aes32esmi(rs1 as i32, rs2 as i32, BS as i32) as u32
111102
}
@@ -132,10 +123,10 @@ pub unsafe fn aes32esmi<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
132123
/// This function is safe to use if the `zknd` target feature is present.
133124
#[target_feature(enable = "zknd")]
134125
#[rustc_legacy_const_generics(2)]
135-
#[cfg_attr(test, assert_instr(aes32dsi))]
126+
#[cfg_attr(test, assert_instr(aes32dsi, BS = 0))]
136127
#[inline]
137128
pub unsafe fn aes32dsi<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
138-
static_assert_imm2!(BS);
129+
static_assert!(BS < 4);
139130

140131
_aes32dsi(rs1 as i32, rs2 as i32, BS as i32) as u32
141132
}
@@ -163,10 +154,10 @@ pub unsafe fn aes32dsi<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
163154
/// This function is safe to use if the `zknd` target feature is present.
164155
#[target_feature(enable = "zknd")]
165156
#[rustc_legacy_const_generics(2)]
166-
#[cfg_attr(test, assert_instr(aes32dsmi))]
157+
#[cfg_attr(test, assert_instr(aes32dsmi, BS = 0))]
167158
#[inline]
168159
pub unsafe fn aes32dsmi<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
169-
static_assert_imm2!(BS);
160+
static_assert!(BS < 4);
170161

171162
_aes32dsmi(rs1 as i32, rs2 as i32, BS as i32) as u32
172163
}

crates/core_arch/src/riscv64/zk.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
#[cfg(test)]
22
use stdarch_test::assert_instr;
33

4-
macro_rules! static_assert_imm_0_until_10 {
5-
($imm:ident) => {
6-
static_assert!(
7-
$imm <= 10,
8-
"Immediate value allowed to be a constant from 0 up to including 10"
9-
)
10-
};
11-
}
12-
134
extern "unadjusted" {
145
#[link_name = "llvm.riscv.aes64es"]
156
fn _aes64es(rs1: i64, rs2: i64) -> i64;
@@ -157,10 +148,10 @@ pub unsafe fn aes64dsm(rs1: u64, rs2: u64) -> u64 {
157148
/// This function is safe to use if the `zkne` or `zknd` target feature is present.
158149
#[target_feature(enable = "zkne", enable = "zknd")]
159150
#[rustc_legacy_const_generics(1)]
160-
#[cfg_attr(test, assert_instr(aes64ks1i))]
151+
#[cfg_attr(test, assert_instr(aes64ks1i, RNUM = 0))]
161152
#[inline]
162153
pub unsafe fn aes64ks1i<const RNUM: u8>(rs1: u64) -> u64 {
163-
static_assert_imm_0_until_10!(RNUM);
154+
static_assert!(RNUM <= 10);
164155

165156
_aes64ks1i(rs1 as i64, RNUM as i32) as u64
166157
}

crates/core_arch/src/riscv_shared/zk.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
#[cfg(test)]
22
use stdarch_test::assert_instr;
33

4-
macro_rules! static_assert_imm2 {
5-
($imm:ident) => {
6-
static_assert!(
7-
$imm < 4,
8-
"Immediate value allowed to be a constant from 0 up to including 3"
9-
)
10-
};
11-
}
12-
134
extern "unadjusted" {
145
#[link_name = "llvm.riscv.sm4ed"]
156
fn _sm4ed(rs1: i32, rs2: i32, bs: i32) -> i32;
@@ -291,10 +282,10 @@ pub unsafe fn sha256sum1(rs1: u32) -> u32 {
291282
/// ```
292283
#[target_feature(enable = "zksed")]
293284
#[rustc_legacy_const_generics(2)]
294-
#[cfg_attr(test, assert_instr(sm4ed))]
285+
#[cfg_attr(test, assert_instr(sm4ed, BS = 0))]
295286
#[inline]
296287
pub unsafe fn sm4ed<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
297-
static_assert_imm2!(BS);
288+
static_assert!(BS < 4);
298289

299290
_sm4ed(rs1 as i32, rs2 as i32, BS as i32) as u32
300291
}
@@ -370,10 +361,10 @@ pub unsafe fn sm4ed<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
370361
/// ```
371362
#[target_feature(enable = "zksed")]
372363
#[rustc_legacy_const_generics(2)]
373-
#[cfg_attr(test, assert_instr(sm4ks))]
364+
#[cfg_attr(test, assert_instr(sm4ks, BS = 0))]
374365
#[inline]
375366
pub unsafe fn sm4ks<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
376-
static_assert_imm2!(BS);
367+
static_assert!(BS < 4);
377368

378369
_sm4ks(rs1 as i32, rs2 as i32, BS as i32) as u32
379370
}

0 commit comments

Comments
 (0)