Skip to content

Commit 5125d03

Browse files
xry111chenhuacai
authored andcommitted
LoongArch: Select ARCH_SUPPORTS_INT128 if CC_HAS_INT128
This allows compiling a full 128-bit product of two 64-bit integers as a mul/mulh pair, instead of a nasty long sequence of 20+ instructions. However, after selecting ARCH_SUPPORTS_INT128, when optimizing for size the compiler generates calls to __ashlti3, __ashrti3, and __lshrti3 for shifting __int128 values, causing a link failure: loongarch64-unknown-linux-gnu-ld: kernel/sched/fair.o: in function `mul_u64_u32_shr': <PATH>/include/linux/math64.h:161:(.text+0x5e4): undefined reference to `__lshrti3' So provide the implementation of these functions if ARCH_SUPPORTS_INT128. Closes: https://lore.kernel.org/loongarch/CAAhV-H5EZ=7OF7CSiYyZ8_+wWuenpo=K2WT8-6mAT4CvzUC_4g@mail.gmail.com/ Signed-off-by: Xi Ruoyao <xry111@xry111.site> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 2cce905 commit 5125d03

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

arch/loongarch/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ config LOONGARCH
5757
select ARCH_SUPPORTS_ACPI
5858
select ARCH_SUPPORTS_ATOMIC_RMW
5959
select ARCH_SUPPORTS_HUGETLBFS
60+
select ARCH_SUPPORTS_INT128 if CC_HAS_INT128
6061
select ARCH_SUPPORTS_LTO_CLANG
6162
select ARCH_SUPPORTS_LTO_CLANG_THIN
6263
select ARCH_SUPPORTS_NUMA_BALANCING

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@
66
#include <asm/page.h>
77
#include <asm/ftrace.h>
88
#include <asm-generic/asm-prototypes.h>
9+
10+
#ifdef CONFIG_ARCH_SUPPORTS_INT128
11+
__int128_t __ashlti3(__int128_t a, int b);
12+
__int128_t __ashrti3(__int128_t a, int b);
13+
__int128_t __lshrti3(__int128_t a, int b);
14+
#endif

arch/loongarch/lib/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
lib-y += delay.o memset.o memcpy.o memmove.o \
77
clear_user.o copy_user.o csum.o dump_tlb.o unaligned.o
88

9+
obj-$(CONFIG_ARCH_SUPPORTS_INT128) += tishift.o
10+
911
obj-$(CONFIG_CPU_HAS_LSX) += xor_simd.o xor_simd_glue.o
1012

1113
obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o

arch/loongarch/lib/tishift.S

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
3+
#include <asm/asmmacro.h>
4+
#include <linux/export.h>
5+
#include <linux/linkage.h>
6+
7+
SYM_FUNC_START(__ashlti3)
8+
srli.d t2, a0, 1
9+
nor t3, zero, a2
10+
sll.d t1, a1, a2
11+
srl.d t2, t2, t3
12+
andi t0, a2, 64
13+
sll.d a0, a0, a2
14+
or t1, t2, t1
15+
maskeqz a1, a0, t0
16+
masknez a0, a0, t0
17+
masknez t0, t1, t0
18+
or a1, t0, a1
19+
jr ra
20+
SYM_FUNC_END(__ashlti3)
21+
EXPORT_SYMBOL(__ashlti3)
22+
23+
SYM_FUNC_START(__ashrti3)
24+
nor t3, zero, a2
25+
slli.d t2, a1, 1
26+
srl.d t1, a0, a2
27+
sll.d t2, t2, t3
28+
andi t0, a2, 64
29+
or t1, t2, t1
30+
sra.d a2, a1, a2
31+
srai.d a1, a1, 63
32+
maskeqz a0, a2, t0
33+
maskeqz a1, a1, t0
34+
masknez a2, a2, t0
35+
masknez t0, t1, t0
36+
or a1, a1, a2
37+
or a0, t0, a0
38+
jr ra
39+
SYM_FUNC_END(__ashrti3)
40+
EXPORT_SYMBOL(__ashrti3)
41+
42+
SYM_FUNC_START(__lshrti3)
43+
slli.d t2, a1, 1
44+
nor t3, zero, a2
45+
srl.d t1, a0, a2
46+
sll.d t2, t2, t3
47+
andi t0, a2, 64
48+
srl.d a1, a1, a2
49+
or t1, t2, t1
50+
maskeqz a0, a1, t0
51+
masknez a1, a1, t0
52+
masknez t0, t1, t0
53+
or a0, t0, a0
54+
jr ra
55+
SYM_FUNC_END(__lshrti3)
56+
EXPORT_SYMBOL(__lshrti3)

0 commit comments

Comments
 (0)