1
- use core:: arch:: asm;
1
+ #[ cfg( test) ]
2
+ use stdarch_test:: assert_instr;
2
3
3
4
macro_rules! static_assert_imm2 {
4
5
( $imm: ident) => {
@@ -21,6 +22,30 @@ extern "unadjusted" {
21
22
22
23
#[ link_name = "llvm.riscv.aes32dsmi" ]
23
24
fn _aes32dsmi ( rs1 : i32 , rs2 : i32 , bs : i32 ) -> i32 ;
25
+
26
+ #[ link_name = "llvm.riscv.zip.i32" ]
27
+ fn _zip ( rs1 : i32 ) -> i32 ;
28
+
29
+ #[ link_name = "llvm.riscv.unzip.i32" ]
30
+ fn _unzip ( rs1 : i32 ) -> i32 ;
31
+
32
+ #[ link_name = "llvm.riscv.sha512sig0h" ]
33
+ fn _sha512sig0h ( rs1 : i32 , rs2 : i32 ) -> i32 ;
34
+
35
+ #[ link_name = "llvm.riscv.sha512sig0l" ]
36
+ fn _sha512sig0l ( rs1 : i32 , rs2 : i32 ) -> i32 ;
37
+
38
+ #[ link_name = "llvm.riscv.sha512sig1h" ]
39
+ fn _sha512sig1h ( rs1 : i32 , rs2 : i32 ) -> i32 ;
40
+
41
+ #[ link_name = "llvm.riscv.sha512sig1l" ]
42
+ fn _sha512sig1l ( rs1 : i32 , rs2 : i32 ) -> i32 ;
43
+
44
+ #[ link_name = "llvm.riscv.sha512sum0r" ]
45
+ fn _sha512sum0r ( rs1 : i32 , rs2 : i32 ) -> i32 ;
46
+
47
+ #[ link_name = "llvm.riscv.sha512sum1r" ]
48
+ fn _sha512sum1r ( rs1 : i32 , rs2 : i32 ) -> i32 ;
24
49
}
25
50
26
51
/// AES final round encryption instruction for RV32.
@@ -166,17 +191,8 @@ pub unsafe fn aes32dsmi<const BS: u8>(rs1: u32, rs2: u32) -> u32 {
166
191
#[ target_feature( enable = "zbkb" ) ]
167
192
#[ cfg_attr( test, assert_instr( zip) ) ]
168
193
#[ inline]
169
- pub unsafe fn zip ( rs : usize ) -> usize {
170
- let value: usize ;
171
- unsafe {
172
- asm ! (
173
- "zip {rd},{rs}" ,
174
- rd = lateout( reg) value,
175
- rs = in( reg) rs,
176
- options( pure, nomem, nostack) ,
177
- )
178
- }
179
- value
194
+ pub unsafe fn zip ( rs : u32 ) -> u32 {
195
+ _zip ( rs as i32 ) as u32
180
196
}
181
197
182
198
/// Place odd and even bits of the source word into upper/lower halves of the destination.
@@ -197,17 +213,8 @@ pub unsafe fn zip(rs: usize) -> usize {
197
213
#[ target_feature( enable = "zbkb" ) ]
198
214
#[ cfg_attr( test, assert_instr( unzip) ) ]
199
215
#[ inline]
200
- pub unsafe fn unzip ( rs : usize ) -> usize {
201
- let value: usize ;
202
- unsafe {
203
- asm ! (
204
- "unzip {rd},{rs}" ,
205
- rd = lateout( reg) value,
206
- rs = in( reg) rs,
207
- options( pure, nomem, nostack) ,
208
- )
209
- }
210
- value
216
+ pub unsafe fn unzip ( rs : u32 ) -> u32 {
217
+ _unzip ( rs as i32 ) as u32
211
218
}
212
219
213
220
/// Implements the high half of the Sigma0 transformation, as used in the SHA2-512 hash
@@ -232,17 +239,7 @@ pub unsafe fn unzip(rs: usize) -> usize {
232
239
#[ cfg_attr( test, assert_instr( sha512sig0h) ) ]
233
240
#[ inline]
234
241
pub unsafe fn sha512sig0h ( rs1 : u32 , rs2 : u32 ) -> u32 {
235
- let value: u32 ;
236
- unsafe {
237
- asm ! (
238
- "sha512sig0h {rd},{rs1},{rs2}" ,
239
- rd = lateout( reg) value,
240
- rs1 = in( reg) rs1,
241
- rs2 = in( reg) rs2,
242
- options( pure, nomem, nostack) ,
243
- )
244
- }
245
- value
242
+ _sha512sig0h ( rs1 as i32 , rs2 as i32 ) as u32
246
243
}
247
244
248
245
/// Implements the low half of the Sigma0 transformation, as used in the SHA2-512 hash function
@@ -267,17 +264,7 @@ pub unsafe fn sha512sig0h(rs1: u32, rs2: u32) -> u32 {
267
264
#[ cfg_attr( test, assert_instr( sha512sig0l) ) ]
268
265
#[ inline]
269
266
pub unsafe fn sha512sig0l ( rs1 : u32 , rs2 : u32 ) -> u32 {
270
- let value: u32 ;
271
- unsafe {
272
- asm ! (
273
- "sha512sig0l {rd},{rs1},{rs2}" ,
274
- rd = lateout( reg) value,
275
- rs1 = in( reg) rs1,
276
- rs2 = in( reg) rs2,
277
- options( pure, nomem, nostack) ,
278
- )
279
- }
280
- value
267
+ _sha512sig0l ( rs1 as i32 , rs2 as i32 ) as u32
281
268
}
282
269
283
270
/// Implements the high half of the Sigma1 transformation, as used in the SHA2-512 hash
@@ -302,17 +289,7 @@ pub unsafe fn sha512sig0l(rs1: u32, rs2: u32) -> u32 {
302
289
#[ cfg_attr( test, assert_instr( sha512sig1h) ) ]
303
290
#[ inline]
304
291
pub unsafe fn sha512sig1h ( rs1 : u32 , rs2 : u32 ) -> u32 {
305
- let value: u32 ;
306
- unsafe {
307
- asm ! (
308
- "sha512sig1h {rd},{rs1},{rs2}" ,
309
- rd = lateout( reg) value,
310
- rs1 = in( reg) rs1,
311
- rs2 = in( reg) rs2,
312
- options( pure, nomem, nostack) ,
313
- )
314
- }
315
- value
292
+ _sha512sig1h ( rs1 as i32 , rs2 as i32 ) as u32
316
293
}
317
294
318
295
/// Implements the low half of the Sigma1 transformation, as used in the SHA2-512 hash function
@@ -337,17 +314,7 @@ pub unsafe fn sha512sig1h(rs1: u32, rs2: u32) -> u32 {
337
314
#[ cfg_attr( test, assert_instr( sha512sig1l) ) ]
338
315
#[ inline]
339
316
pub unsafe fn sha512sig1l ( rs1 : u32 , rs2 : u32 ) -> u32 {
340
- let value: u32 ;
341
- unsafe {
342
- asm ! (
343
- "sha512sig1l {rd},{rs1},{rs2}" ,
344
- rd = lateout( reg) value,
345
- rs1 = in( reg) rs1,
346
- rs2 = in( reg) rs2,
347
- options( pure, nomem, nostack) ,
348
- )
349
- }
350
- value
317
+ _sha512sig1l ( rs1 as i32 , rs2 as i32 ) as u32
351
318
}
352
319
353
320
/// Implements the Sum0 transformation, as used in the SHA2-512 hash function \[49\] (Section
@@ -371,17 +338,7 @@ pub unsafe fn sha512sig1l(rs1: u32, rs2: u32) -> u32 {
371
338
#[ cfg_attr( test, assert_instr( sha512sum0r) ) ]
372
339
#[ inline]
373
340
pub unsafe fn sha512sum0r ( rs1 : u32 , rs2 : u32 ) -> u32 {
374
- let value: u32 ;
375
- unsafe {
376
- asm ! (
377
- "sha512sum0r {rd},{rs1},{rs2}" ,
378
- rd = lateout( reg) value,
379
- rs1 = in( reg) rs1,
380
- rs2 = in( reg) rs2,
381
- options( pure, nomem, nostack) ,
382
- )
383
- }
384
- value
341
+ _sha512sum0r ( rs1 as i32 , rs2 as i32 ) as u32
385
342
}
386
343
387
344
/// Implements the Sum1 transformation, as used in the SHA2-512 hash function \[49\] (Section
@@ -405,15 +362,5 @@ pub unsafe fn sha512sum0r(rs1: u32, rs2: u32) -> u32 {
405
362
#[ cfg_attr( test, assert_instr( sha512sum1r) ) ]
406
363
#[ inline]
407
364
pub unsafe fn sha512sum1r ( rs1 : u32 , rs2 : u32 ) -> u32 {
408
- let value: u32 ;
409
- unsafe {
410
- asm ! (
411
- "sha512sum1r {rd},{rs1},{rs2}" ,
412
- rd = lateout( reg) value,
413
- rs1 = in( reg) rs1,
414
- rs2 = in( reg) rs2,
415
- options( pure, nomem, nostack) ,
416
- )
417
- }
418
- value
365
+ _sha512sum1r ( rs1 as i32 , rs2 as i32 ) as u32
419
366
}
0 commit comments