Skip to content

Commit

Permalink
Fix: Add constant for assert_instr
Browse files Browse the repository at this point in the history
  • Loading branch information
coastalwhite committed Aug 29, 2023
1 parent ef892cf commit 4945aa5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 41 deletions.
25 changes: 8 additions & 17 deletions crates/core_arch/src/riscv32/zk.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#[cfg(test)]
use stdarch_test::assert_instr;

macro_rules! static_assert_imm2 {
($imm:ident) => {
static_assert!(
$imm < 4,
"Immediate value allowed to be a constant from 0 up to including 3"
)
};
}

extern "unadjusted" {
#[link_name = "llvm.riscv.aes32esi"]
fn _aes32esi(rs1: i32, rs2: i32, bs: i32) -> i32;
Expand Down Expand Up @@ -71,10 +62,10 @@ extern "unadjusted" {
/// This function is safe to use if the `zkne` target feature is present.
#[target_feature(enable = "zkne")]
#[rustc_legacy_const_generics(2)]
#[cfg_attr(test, assert_instr(aes32esi))]
#[cfg_attr(test, assert_instr(aes32esi, BS = 0))]
#[inline]
pub unsafe fn aes32esi<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
static_assert_imm2!(BS);
static_assert!(BS < 4);

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

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

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

_aes32dsmi(rs1 as i32, rs2 as i32, BS as i32) as u32
}
Expand Down
13 changes: 2 additions & 11 deletions crates/core_arch/src/riscv64/zk.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#[cfg(test)]
use stdarch_test::assert_instr;

macro_rules! static_assert_imm_0_until_10 {
($imm:ident) => {
static_assert!(
$imm <= 10,
"Immediate value allowed to be a constant from 0 up to including 10"
)
};
}

extern "unadjusted" {
#[link_name = "llvm.riscv.aes64es"]
fn _aes64es(rs1: i64, rs2: i64) -> i64;
Expand Down Expand Up @@ -157,10 +148,10 @@ pub unsafe fn aes64dsm(rs1: u64, rs2: u64) -> u64 {
/// This function is safe to use if the `zkne` or `zknd` target feature is present.
#[target_feature(enable = "zkne", enable = "zknd")]
#[rustc_legacy_const_generics(1)]
#[cfg_attr(test, assert_instr(aes64ks1i))]
#[cfg_attr(test, assert_instr(aes64ks1i, RNUM = 0))]
#[inline]
pub unsafe fn aes64ks1i<const RNUM: u8>(rs1: u64) -> u64 {
static_assert_imm_0_until_10!(RNUM);
static_assert!(RNUM <= 10);

_aes64ks1i(rs1 as i64, RNUM as i32) as u64
}
Expand Down
17 changes: 4 additions & 13 deletions crates/core_arch/src/riscv_shared/zk.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#[cfg(test)]
use stdarch_test::assert_instr;

macro_rules! static_assert_imm2 {
($imm:ident) => {
static_assert!(
$imm < 4,
"Immediate value allowed to be a constant from 0 up to including 3"
)
};
}

extern "unadjusted" {
#[link_name = "llvm.riscv.sm4ed"]
fn _sm4ed(rs1: i32, rs2: i32, bs: i32) -> i32;
Expand Down Expand Up @@ -291,10 +282,10 @@ pub unsafe fn sha256sum1(rs1: u32) -> u32 {
/// ```
#[target_feature(enable = "zksed")]
#[rustc_legacy_const_generics(2)]
#[cfg_attr(test, assert_instr(sm4ed))]
#[cfg_attr(test, assert_instr(sm4ed, BS = 0))]
#[inline]
pub unsafe fn sm4ed<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
static_assert_imm2!(BS);
static_assert!(BS < 4);

_sm4ed(rs1 as i32, rs2 as i32, BS as i32) as u32
}
Expand Down Expand Up @@ -370,10 +361,10 @@ pub unsafe fn sm4ed<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
/// ```
#[target_feature(enable = "zksed")]
#[rustc_legacy_const_generics(2)]
#[cfg_attr(test, assert_instr(sm4ks))]
#[cfg_attr(test, assert_instr(sm4ks, BS = 0))]
#[inline]
pub unsafe fn sm4ks<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
static_assert_imm2!(BS);
static_assert!(BS < 4);

_sm4ks(rs1 as i32, rs2 as i32, BS as i32) as u32
}
Expand Down

0 comments on commit 4945aa5

Please sign in to comment.