Commit fc585d4a authored by Olof Johansson's avatar Olof Johansson Committed by Paul Walmsley

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: default avatarOlof Johansson <olof@lixom.net>
[paul.walmsley@sifive.com: use SYM_FUNC_{START,END} instead of
 ENTRY/ENDPROC; note libgcc origin]
Signed-off-by: default avatarPaul Walmsley <paul.walmsley@sifive.com>
parent 95f4d9cc
...@@ -5,4 +5,8 @@ ...@@ -5,4 +5,8 @@
#include <linux/ftrace.h> #include <linux/ftrace.h>
#include <asm-generic/asm-prototypes.h> #include <asm-generic/asm-prototypes.h>
long long __lshrti3(long long a, int b);
long long __ashrti3(long long a, int b);
long long __ashlti3(long long a, int b);
#endif /* _ASM_RISCV_PROTOTYPES_H */ #endif /* _ASM_RISCV_PROTOTYPES_H */
...@@ -4,34 +4,73 @@ ...@@ -4,34 +4,73 @@
*/ */
#include <linux/linkage.h> #include <linux/linkage.h>
#include <asm-generic/export.h>
ENTRY(__lshrti3) SYM_FUNC_START(__lshrti3)
beqz a2, .L1 beqz a2, .L1
li a5,64 li a5,64
sub a5,a5,a2 sub a5,a5,a2
addi sp,sp,-16
sext.w a4,a5 sext.w a4,a5
blez a5, .L2 blez a5, .L2
sext.w a2,a2 sext.w a2,a2
sll a4,a1,a4
srl a0,a0,a2 srl a0,a0,a2
srl a1,a1,a2 sll a4,a1,a4
srl a2,a1,a2
or a0,a0,a4 or a0,a0,a4
sd a1,8(sp) mv a1,a2
sd a0,0(sp)
ld a0,0(sp)
ld a1,8(sp)
addi sp,sp,16
ret
.L1: .L1:
ret ret
.L2: .L2:
negw a4,a4 negw a0,a4
srl a1,a1,a4 li a2,0
sd a1,0(sp) srl a0,a1,a0
sd zero,8(sp) mv a1,a2
ld a0,0(sp) ret
ld a1,8(sp) SYM_FUNC_END(__lshrti3)
addi sp,sp,16 EXPORT_SYMBOL(__lshrti3)
SYM_FUNC_START(__ashrti3)
beqz a2, .L3
li a5,64
sub a5,a5,a2
sext.w a4,a5
blez a5, .L4
sext.w a2,a2
srl a0,a0,a2
sll a4,a1,a4
sra a2,a1,a2
or a0,a0,a4
mv a1,a2
.L3:
ret
.L4:
negw a0,a4
srai a2,a1,0x3f
sra a0,a1,a0
mv a1,a2
ret
SYM_FUNC_END(__ashrti3)
EXPORT_SYMBOL(__ashrti3)
SYM_FUNC_START(__ashlti3)
beqz a2, .L5
li a5,64
sub a5,a5,a2
sext.w a4,a5
blez a5, .L6
sext.w a2,a2
sll a1,a1,a2
srl a4,a0,a4
sll a2,a0,a2
or a1,a1,a4
mv a0,a2
.L5:
ret
.L6:
negw a1,a4
li a2,0
sll a1,a0,a1
mv a0,a2
ret ret
ENDPROC(__lshrti3) SYM_FUNC_END(__ashlti3)
EXPORT_SYMBOL(__ashlti3)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment