Skip to content

Commit fb87227

Browse files
zx2c4wildea01
authored andcommitted
arm64: support __int128 on gcc 5+
Versions of gcc prior to gcc 5 emitted a __multi3 function call when dealing with TI types, resulting in failures when trying to link to libgcc, and more generally, bad performance. However, since gcc 5, the compiler supports actually emitting fast instructions, which means we can at long last enable this option and receive the speedups. The gcc commit that added proper Aarch64 support is: https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=d1ae7bb994f49316f6f63e6173f2931e837a351d This commit appears to be part of the gcc 5 release. There are still a few instructions, __ashlti3 and __ashrti3, which require libgcc, which is fine. Rather than linking to libgcc, we simply provide them ourselves, since they're not that complicated. Signed-off-by: Jason A. Donenfeld <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent ce69908 commit fb87227

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

arch/arm64/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ KBUILD_AFLAGS += $(lseinstr) $(brokengasinst)
5757
KBUILD_CFLAGS += $(call cc-option,-mabi=lp64)
5858
KBUILD_AFLAGS += $(call cc-option,-mabi=lp64)
5959

60+
KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0500, -DCONFIG_ARCH_SUPPORTS_INT128)
61+
6062
ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
6163
KBUILD_CPPFLAGS += -mbig-endian
6264
CHECKFLAGS += -D__AARCH64EB__

arch/arm64/lib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ lib-y := bitops.o clear_user.o delay.o copy_from_user.o \
22
copy_to_user.o copy_in_user.o copy_page.o \
33
clear_page.o memchr.o memcpy.o memmove.o memset.o \
44
memcmp.o strcmp.o strncmp.o strlen.o strnlen.o \
5-
strchr.o strrchr.o
5+
strchr.o strrchr.o tishift.o
66

77
# Tell the compiler to treat all general purpose registers (with the
88
# exception of the IP registers, which are already handled by the caller

arch/arm64/lib/tishift.S

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (C) 2017 Jason A. Donenfeld <[email protected]>. All Rights Reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
#include <linux/linkage.h>
18+
19+
ENTRY(__ashlti3)
20+
cbz x2, 1f
21+
mov x3, #64
22+
sub x3, x3, x2
23+
cmp x3, #0
24+
b.le 2f
25+
lsl x1, x1, x2
26+
lsr x3, x0, x3
27+
lsl x2, x0, x2
28+
orr x1, x1, x3
29+
mov x0, x2
30+
1:
31+
ret
32+
2:
33+
neg w1, w3
34+
mov x2, #0
35+
lsl x1, x0, x1
36+
mov x0, x2
37+
ret
38+
ENDPROC(__ashlti3)
39+
40+
ENTRY(__ashrti3)
41+
cbz x2, 3f
42+
mov x3, #64
43+
sub x3, x3, x2
44+
cmp x3, #0
45+
b.le 4f
46+
lsr x0, x0, x2
47+
lsl x3, x1, x3
48+
asr x2, x1, x2
49+
orr x0, x0, x3
50+
mov x1, x2
51+
3:
52+
ret
53+
4:
54+
neg w0, w3
55+
asr x2, x1, #63
56+
asr x0, x1, x0
57+
mov x1, x2
58+
ret
59+
ENDPROC(__ashrti3)

0 commit comments

Comments
 (0)