-
Notifications
You must be signed in to change notification settings - Fork 12
/
rotate.s
40 lines (39 loc) · 843 Bytes
/
rotate.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Collection of rotation examples
#
# Shows how to bit-rotate registers in the absence of RISC-V Bitmanip ("B")
# extension.
#
# As of 2020, the "B" extension has draft status. However, it already
# includes the ror/rol/rori/rorw/rolw/roriw instructions.
#
# cf. https://stackoverflow.com/a/60138854/427158
#
# 2020, Georg Sauthoff <mail@gms.tf>
.text
.balign 4
.global rotl3
rotl3:
slli a2, a0, 3
srli a3, a0, (-3 & 63) # & 31 for RV32G
or a0, a2, a3
ret
.global rotr3
rotr3:
srli a2, a0, 3
slli a3, a0, (-3 & 63) # & 31 for RV32G
or a0, a2, a3
ret
.global rotl
rotl:
sll a2, a0, a1
sub a4, zero, a1
srl a3, a0, a4
or a0, a2, a3
ret
.global rotr
rotr:
srl a2, a0, a1
sub a4, zero, a1
sll a3, a0, a4
or a0, a2, a3
ret