Skip to content

Commit 839c9ec

Browse files
coastalwhiteAmanieu
authored andcommitted
Fix: #1464 for rv64 zk
1 parent e658393 commit 839c9ec

File tree

5 files changed

+30
-44
lines changed

5 files changed

+30
-44
lines changed

ci/docker/riscv64gc-unknown-linux-gnu/Dockerfile

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ FROM ubuntu:23.04
22

33
RUN apt-get update && apt-get install -y --no-install-recommends \
44
gcc libc6-dev qemu-user ca-certificates \
5-
gcc-riscv64-linux-gnu libc6-dev-riscv64-cross
5+
gcc-riscv64-linux-gnu libc6-dev-riscv64-cross \
6+
llvm
67

78
ENV CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER=riscv64-linux-gnu-gcc \
8-
CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_RUNNER="qemu-riscv64 -L /usr/riscv64-linux-gnu -cpu rv64,zk=true,zbb=true,zbc=true" \
9-
OBJDUMP=riscv64-linux-gnu-objdump
9+
CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_RUNNER="qemu-riscv64 \
10+
-L /usr/riscv64-linux-gnu \
11+
-cpu rv64,zk=true,zks=true,zbb=true,zbc=true \
12+
" \
13+
OBJDUMP=llvm-objdump

ci/run.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ case ${TARGET} in
4747
# Some of our test dependencies use the deprecated `gcc` crates which
4848
# doesn't detect RISC-V compilers automatically, so do it manually here.
4949
riscv64*)
50-
export RUSTFLAGS="${RUSTFLAGS} -Ctarget-feature=+zk,+zbb,+zbc"
50+
export RUSTFLAGS="${RUSTFLAGS} -Ctarget-feature=+zk,+zks,+zbb,+zbc"
5151
export TARGET_CC="riscv64-linux-gnu-gcc"
5252
;;
5353
esac

crates/core_arch/src/riscv64/zk.rs

+10-20
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ extern "unadjusted" {
5050
///
5151
/// This function is safe to use if the `zkne` target feature is present.
5252
#[target_feature(enable = "zkne")]
53-
// See #1464
54-
// #[cfg_attr(test, assert_instr(aes64es))]
53+
#[cfg_attr(test, assert_instr(aes64es))]
5554
#[inline]
5655
pub unsafe fn aes64es(rs1: u64, rs2: u64) -> u64 {
5756
_aes64es(rs1 as i64, rs2 as i64) as u64
@@ -74,8 +73,7 @@ pub unsafe fn aes64es(rs1: u64, rs2: u64) -> u64 {
7473
///
7574
/// This function is safe to use if the `zkne` target feature is present.
7675
#[target_feature(enable = "zkne")]
77-
// See #1464
78-
// #[cfg_attr(test, assert_instr(aes64esm))]
76+
#[cfg_attr(test, assert_instr(aes64esm))]
7977
#[inline]
8078
pub unsafe fn aes64esm(rs1: u64, rs2: u64) -> u64 {
8179
_aes64esm(rs1 as i64, rs2 as i64) as u64
@@ -98,8 +96,7 @@ pub unsafe fn aes64esm(rs1: u64, rs2: u64) -> u64 {
9896
///
9997
/// This function is safe to use if the `zknd` target feature is present.
10098
#[target_feature(enable = "zknd")]
101-
// See #1464
102-
// #[cfg_attr(test, assert_instr(aes64ds))]
99+
#[cfg_attr(test, assert_instr(aes64ds))]
103100
#[inline]
104101
pub unsafe fn aes64ds(rs1: u64, rs2: u64) -> u64 {
105102
_aes64ds(rs1 as i64, rs2 as i64) as u64
@@ -122,8 +119,7 @@ pub unsafe fn aes64ds(rs1: u64, rs2: u64) -> u64 {
122119
///
123120
/// This function is safe to use if the `zknd` target feature is present.
124121
#[target_feature(enable = "zknd")]
125-
// See #1464
126-
// #[cfg_attr(test, assert_instr(aes64dsm))]
122+
#[cfg_attr(test, assert_instr(aes64dsm))]
127123
#[inline]
128124
pub unsafe fn aes64dsm(rs1: u64, rs2: u64) -> u64 {
129125
_aes64dsm(rs1 as i64, rs2 as i64) as u64
@@ -152,8 +148,7 @@ pub unsafe fn aes64dsm(rs1: u64, rs2: u64) -> u64 {
152148
/// This function is safe to use if the `zkne` or `zknd` target feature is present.
153149
#[target_feature(enable = "zkne", enable = "zknd")]
154150
#[rustc_legacy_const_generics(1)]
155-
// See #1464
156-
// #[cfg_attr(test, assert_instr(aes64ks1i, RNUM = 0))]
151+
#[cfg_attr(test, assert_instr(aes64ks1i, RNUM = 0))]
157152
#[inline]
158153
pub unsafe fn aes64ks1i<const RNUM: u8>(rs1: u64) -> u64 {
159154
static_assert!(RNUM <= 10);
@@ -177,8 +172,7 @@ pub unsafe fn aes64ks1i<const RNUM: u8>(rs1: u64) -> u64 {
177172
///
178173
/// This function is safe to use if the `zkne` or `zknd` target feature is present.
179174
#[target_feature(enable = "zkne", enable = "zknd")]
180-
// See #1464
181-
// #[cfg_attr(test, assert_instr(aes64ks2))]
175+
#[cfg_attr(test, assert_instr(aes64ks2))]
182176
#[inline]
183177
pub unsafe fn aes64ks2(rs1: u64, rs2: u64) -> u64 {
184178
_aes64ks2(rs1 as i64, rs2 as i64) as u64
@@ -201,8 +195,7 @@ pub unsafe fn aes64ks2(rs1: u64, rs2: u64) -> u64 {
201195
///
202196
/// This function is safe to use if the `zknh` target feature is present.
203197
#[target_feature(enable = "zknh")]
204-
// See #1464
205-
// #[cfg_attr(test, assert_instr(sha512sig0))]
198+
#[cfg_attr(test, assert_instr(sha512sig0))]
206199
#[inline]
207200
pub unsafe fn sha512sig0(rs1: u64) -> u64 {
208201
_sha512sig0(rs1 as i64) as u64
@@ -225,8 +218,7 @@ pub unsafe fn sha512sig0(rs1: u64) -> u64 {
225218
///
226219
/// This function is safe to use if the `zknh` target feature is present.
227220
#[target_feature(enable = "zknh")]
228-
// See #1464
229-
// #[cfg_attr(test, assert_instr(sha512sig1))]
221+
#[cfg_attr(test, assert_instr(sha512sig1))]
230222
#[inline]
231223
pub unsafe fn sha512sig1(rs1: u64) -> u64 {
232224
_sha512sig1(rs1 as i64) as u64
@@ -249,8 +241,7 @@ pub unsafe fn sha512sig1(rs1: u64) -> u64 {
249241
///
250242
/// This function is safe to use if the `zknh` target feature is present.
251243
#[target_feature(enable = "zknh")]
252-
// See #1464
253-
// #[cfg_attr(test, assert_instr(sha512sum0))]
244+
#[cfg_attr(test, assert_instr(sha512sum0))]
254245
#[inline]
255246
pub unsafe fn sha512sum0(rs1: u64) -> u64 {
256247
_sha512sum0(rs1 as i64) as u64
@@ -273,8 +264,7 @@ pub unsafe fn sha512sum0(rs1: u64) -> u64 {
273264
///
274265
/// This function is safe to use if the `zknh` target feature is present.
275266
#[target_feature(enable = "zknh")]
276-
// See #1464
277-
// #[cfg_attr(test, assert_instr(sha512sum1))]
267+
#[cfg_attr(test, assert_instr(sha512sum1))]
278268
#[inline]
279269
pub unsafe fn sha512sum1(rs1: u64) -> u64 {
280270
_sha512sum1(rs1 as i64) as u64

crates/core_arch/src/riscv_shared/zk.rs

+10-20
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ extern "unadjusted" {
6262
///
6363
/// This function is safe to use if the `zbkx` target feature is present.
6464
#[target_feature(enable = "zbkx")]
65-
// See #1464
66-
// #[cfg_attr(test, assert_instr(xperm8))]
65+
#[cfg_attr(test, assert_instr(xperm8))]
6766
#[inline]
6867
pub unsafe fn xperm8(rs1: usize, rs2: usize) -> usize {
6968
#[cfg(target_arch = "riscv32")]
@@ -94,8 +93,7 @@ pub unsafe fn xperm8(rs1: usize, rs2: usize) -> usize {
9493
///
9594
/// This function is safe to use if the `zbkx` target feature is present.
9695
#[target_feature(enable = "zbkx")]
97-
// See #1464
98-
// #[cfg_attr(test, assert_instr(xperm4))]
96+
#[cfg_attr(test, assert_instr(xperm4))]
9997
#[inline]
10098
pub unsafe fn xperm4(rs1: usize, rs2: usize) -> usize {
10199
#[cfg(target_arch = "riscv32")]
@@ -129,8 +127,7 @@ pub unsafe fn xperm4(rs1: usize, rs2: usize) -> usize {
129127
///
130128
/// This function is safe to use if the `zknh` target feature is present.
131129
#[target_feature(enable = "zknh")]
132-
// See #1464
133-
// #[cfg_attr(test, assert_instr(sha256sig0))]
130+
#[cfg_attr(test, assert_instr(sha256sig0))]
134131
#[inline]
135132
pub unsafe fn sha256sig0(rs1: u32) -> u32 {
136133
_sha256sig0(rs1 as i32) as u32
@@ -156,8 +153,7 @@ pub unsafe fn sha256sig0(rs1: u32) -> u32 {
156153
///
157154
/// This function is safe to use if the `zknh` target feature is present.
158155
#[target_feature(enable = "zknh")]
159-
// See #1464
160-
// #[cfg_attr(test, assert_instr(sha256sig1))]
156+
#[cfg_attr(test, assert_instr(sha256sig1))]
161157
#[inline]
162158
pub unsafe fn sha256sig1(rs1: u32) -> u32 {
163159
_sha256sig1(rs1 as i32) as u32
@@ -183,8 +179,7 @@ pub unsafe fn sha256sig1(rs1: u32) -> u32 {
183179
///
184180
/// This function is safe to use if the `zknh` target feature is present.
185181
#[target_feature(enable = "zknh")]
186-
// See #1464
187-
// #[cfg_attr(test, assert_instr(sha256sum0))]
182+
#[cfg_attr(test, assert_instr(sha256sum0))]
188183
#[inline]
189184
pub unsafe fn sha256sum0(rs1: u32) -> u32 {
190185
_sha256sum0(rs1 as i32) as u32
@@ -210,8 +205,7 @@ pub unsafe fn sha256sum0(rs1: u32) -> u32 {
210205
///
211206
/// This function is safe to use if the `zknh` target feature is present.
212207
#[target_feature(enable = "zknh")]
213-
// See #1464
214-
// #[cfg_attr(test, assert_instr(sha256sum1))]
208+
#[cfg_attr(test, assert_instr(sha256sum1))]
215209
#[inline]
216210
pub unsafe fn sha256sum1(rs1: u32) -> u32 {
217211
_sha256sum1(rs1 as i32) as u32
@@ -288,8 +282,7 @@ pub unsafe fn sha256sum1(rs1: u32) -> u32 {
288282
/// ```
289283
#[target_feature(enable = "zksed")]
290284
#[rustc_legacy_const_generics(2)]
291-
// See #1464
292-
// #[cfg_attr(test, assert_instr(sm4ed, BS = 0))]
285+
#[cfg_attr(test, assert_instr(sm4ed, BS = 0))]
293286
#[inline]
294287
pub unsafe fn sm4ed<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
295288
static_assert!(BS < 4);
@@ -368,8 +361,7 @@ pub unsafe fn sm4ed<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
368361
/// ```
369362
#[target_feature(enable = "zksed")]
370363
#[rustc_legacy_const_generics(2)]
371-
// See #1464
372-
// #[cfg_attr(test, assert_instr(sm4ks, BS = 0))]
364+
#[cfg_attr(test, assert_instr(sm4ks, BS = 0))]
373365
#[inline]
374366
pub unsafe fn sm4ks<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
375367
static_assert!(BS < 4);
@@ -409,8 +401,7 @@ pub unsafe fn sm4ks<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
409401
/// compression function `CF` uses the intermediate value `TT2` to calculate
410402
/// the variable `E` in one iteration for subsequent processes.
411403
#[target_feature(enable = "zksh")]
412-
// See #1464
413-
// #[cfg_attr(test, assert_instr(sm3p0))]
404+
#[cfg_attr(test, assert_instr(sm3p0))]
414405
#[inline]
415406
pub unsafe fn sm3p0(rs1: u32) -> u32 {
416407
_sm3p0(rs1 as i32) as u32
@@ -454,8 +445,7 @@ pub unsafe fn sm3p0(rs1: u32) -> u32 {
454445
/// ENDFOR
455446
/// ```
456447
#[target_feature(enable = "zksh")]
457-
// See #1464
458-
// #[cfg_attr(test, assert_instr(sm3p1))]
448+
#[cfg_attr(test, assert_instr(sm3p1))]
459449
#[inline]
460450
pub unsafe fn sm3p1(rs1: u32) -> u32 {
461451
_sm3p1(rs1 as i32) as u32

crates/stdarch-test/src/disassembly.rs

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ pub(crate) fn disassemble_myself() -> HashSet<Function> {
8181
let add_args = if cfg!(target_os = "macos") && cfg!(target_arch = "aarch64") {
8282
// Target features need to be enabled for LLVM objdump on Macos ARM64
8383
vec!["--mattr=+v8.6a,+crypto,+tme"]
84+
} else if cfg!(target_arch = "riscv64") {
85+
vec!["--mattr=+zk,+zks"]
8486
} else {
8587
vec![]
8688
};

0 commit comments

Comments
 (0)