Skip to content

Commit fc585d4

Browse files
olofjpaul-walmsley-sifive
authored andcommitted
riscv: Less inefficient gcc tishift helpers (and export their symbols)
The existing __lshrti3 was really inefficient, and the other two helpers are also needed to compile some modules. Add the missing versions, and export all of the symbols like arm64 already does. This code is based on the assembly generated by libgcc builds. This fixes a build break triggered by ubsan: riscv64-unknown-linux-gnu-ld: lib/ubsan.o: in function `.L2': ubsan.c:(.text.unlikely+0x38): undefined reference to `__ashlti3' riscv64-unknown-linux-gnu-ld: ubsan.c:(.text.unlikely+0x42): undefined reference to `__ashrti3' Signed-off-by: Olof Johansson <[email protected]> [[email protected]: use SYM_FUNC_{START,END} instead of ENTRY/ENDPROC; note libgcc origin] Signed-off-by: Paul Walmsley <[email protected]>
1 parent 95f4d9c commit fc585d4

File tree

2 files changed

+61
-18
lines changed

2 files changed

+61
-18
lines changed

arch/riscv/include/asm/asm-prototypes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@
55
#include <linux/ftrace.h>
66
#include <asm-generic/asm-prototypes.h>
77

8+
long long __lshrti3(long long a, int b);
9+
long long __ashrti3(long long a, int b);
10+
long long __ashlti3(long long a, int b);
11+
812
#endif /* _ASM_RISCV_PROTOTYPES_H */

arch/riscv/lib/tishift.S

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,73 @@
44
*/
55

66
#include <linux/linkage.h>
7+
#include <asm-generic/export.h>
78

8-
ENTRY(__lshrti3)
9+
SYM_FUNC_START(__lshrti3)
910
beqz a2, .L1
1011
li a5,64
1112
sub a5,a5,a2
12-
addi sp,sp,-16
1313
sext.w a4,a5
1414
blez a5, .L2
1515
sext.w a2,a2
16-
sll a4,a1,a4
1716
srl a0,a0,a2
18-
srl a1,a1,a2
17+
sll a4,a1,a4
18+
srl a2,a1,a2
1919
or a0,a0,a4
20-
sd a1,8(sp)
21-
sd a0,0(sp)
22-
ld a0,0(sp)
23-
ld a1,8(sp)
24-
addi sp,sp,16
25-
ret
20+
mv a1,a2
2621
.L1:
2722
ret
2823
.L2:
29-
negw a4,a4
30-
srl a1,a1,a4
31-
sd a1,0(sp)
32-
sd zero,8(sp)
33-
ld a0,0(sp)
34-
ld a1,8(sp)
35-
addi sp,sp,16
24+
negw a0,a4
25+
li a2,0
26+
srl a0,a1,a0
27+
mv a1,a2
28+
ret
29+
SYM_FUNC_END(__lshrti3)
30+
EXPORT_SYMBOL(__lshrti3)
31+
32+
SYM_FUNC_START(__ashrti3)
33+
beqz a2, .L3
34+
li a5,64
35+
sub a5,a5,a2
36+
sext.w a4,a5
37+
blez a5, .L4
38+
sext.w a2,a2
39+
srl a0,a0,a2
40+
sll a4,a1,a4
41+
sra a2,a1,a2
42+
or a0,a0,a4
43+
mv a1,a2
44+
.L3:
45+
ret
46+
.L4:
47+
negw a0,a4
48+
srai a2,a1,0x3f
49+
sra a0,a1,a0
50+
mv a1,a2
51+
ret
52+
SYM_FUNC_END(__ashrti3)
53+
EXPORT_SYMBOL(__ashrti3)
54+
55+
SYM_FUNC_START(__ashlti3)
56+
beqz a2, .L5
57+
li a5,64
58+
sub a5,a5,a2
59+
sext.w a4,a5
60+
blez a5, .L6
61+
sext.w a2,a2
62+
sll a1,a1,a2
63+
srl a4,a0,a4
64+
sll a2,a0,a2
65+
or a1,a1,a4
66+
mv a0,a2
67+
.L5:
68+
ret
69+
.L6:
70+
negw a1,a4
71+
li a2,0
72+
sll a1,a0,a1
73+
mv a0,a2
3674
ret
37-
ENDPROC(__lshrti3)
75+
SYM_FUNC_END(__ashlti3)
76+
EXPORT_SYMBOL(__ashlti3)

0 commit comments

Comments
 (0)