11#[ cfg( test) ]
22use stdarch_test:: assert_instr;
33
4+ use crate :: arch:: asm;
5+
46unsafe extern "unadjusted" {
57 #[ link_name = "llvm.riscv.aes64es" ]
68 fn _aes64es ( rs1 : i64 , rs2 : i64 ) -> i64 ;
@@ -14,12 +16,6 @@ unsafe extern "unadjusted" {
1416 #[ link_name = "llvm.riscv.aes64dsm" ]
1517 fn _aes64dsm ( rs1 : i64 , rs2 : i64 ) -> i64 ;
1618
17- #[ link_name = "llvm.riscv.aes64ks1i" ]
18- fn _aes64ks1i ( rs1 : i64 , rnum : i32 ) -> i64 ;
19-
20- #[ link_name = "llvm.riscv.aes64ks2" ]
21- fn _aes64ks2 ( rs1 : i64 , rs2 : i64 ) -> i64 ;
22-
2319 #[ link_name = "llvm.riscv.aes64im" ]
2420 fn _aes64im ( rs1 : i64 ) -> i64 ;
2521
@@ -133,15 +129,26 @@ pub fn aes64dsm(rs1: u64, rs2: u64) -> u64 {
133129/// # Note
134130///
135131/// The `RNUM` parameter is expected to be a constant value inside the range of `0..=10`.
136- #[ target_feature( enable = "zkne" , enable = "zknd ") ]
132+ #[ target_feature( enable = "zkne_or_zknd " ) ]
137133#[ rustc_legacy_const_generics( 1 ) ]
138- #[ cfg_attr( test, assert_instr( aes64ks1i, RNUM = 0 ) ) ]
139134#[ inline]
140135#[ unstable( feature = "riscv_ext_intrinsics" , issue = "114544" ) ]
141136pub fn aes64ks1i < const RNUM : u8 > ( rs1 : u64 ) -> u64 {
142137 static_assert ! ( RNUM <= 10 ) ;
143-
144- unsafe { _aes64ks1i ( rs1 as i64 , RNUM as i32 ) as u64 }
138+ unsafe {
139+ let rd: u64 ;
140+ asm ! (
141+ ".option push" ,
142+ ".option arch, +zkne" ,
143+ "aes64ks1i {}, {}, {}" ,
144+ ".option pop" ,
145+ lateout( reg) rd,
146+ in( reg) rs1,
147+ const RNUM ,
148+ options( pure, nomem, nostack, preserves_flags)
149+ ) ;
150+ rd
151+ }
145152}
146153
147154/// This instruction implements part of the KeySchedule operation for the AES Block cipher.
@@ -155,12 +162,24 @@ pub fn aes64ks1i<const RNUM: u8>(rs1: u64) -> u64 {
155162/// Version: v1.0.1
156163///
157164/// Section: 3.11
158- #[ target_feature( enable = "zkne" , enable = "zknd" ) ]
159- #[ cfg_attr( test, assert_instr( aes64ks2) ) ]
165+ #[ target_feature( enable = "zkne_or_zknd" ) ]
160166#[ inline]
161167#[ unstable( feature = "riscv_ext_intrinsics" , issue = "114544" ) ]
162168pub fn aes64ks2 ( rs1 : u64 , rs2 : u64 ) -> u64 {
163- unsafe { _aes64ks2 ( rs1 as i64 , rs2 as i64 ) as u64 }
169+ unsafe {
170+ let rd: u64 ;
171+ asm ! (
172+ ".option push" ,
173+ ".option arch, +zkne" ,
174+ "aes64ks2 {}, {}, {}" ,
175+ ".option pop" ,
176+ lateout( reg) rd,
177+ in( reg) rs1,
178+ in( reg) rs2,
179+ options( pure, nomem, nostack, preserves_flags)
180+ ) ;
181+ rd
182+ }
164183}
165184
166185/// This instruction accelerates the inverse MixColumns step of the AES Block Cipher, and is used to aid creation of
0 commit comments