Skip to content

Commit 3764ba2

Browse files
cjacekbylaws
andauthored
[compiler-rt] Add initial ARM64EC builtins support (#139279)
Use the aarch64 variants of assembly functions. Co-authored-by: Billy Laws <[email protected]>
1 parent 5b05728 commit 3764ba2

File tree

15 files changed

+44
-21
lines changed

15 files changed

+44
-21
lines changed

compiler-rt/cmake/Modules/AddCompilerRT.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ macro(set_output_name output name arch)
123123
else()
124124
if(ANDROID AND ${arch} STREQUAL "i386")
125125
set(${output} "${name}-i686${COMPILER_RT_OS_SUFFIX}")
126-
elseif("${arch}" MATCHES "^arm")
126+
elseif(NOT "${arch}" MATCHES "^arm64" AND "${arch}" MATCHES "^arm")
127127
if(COMPILER_RT_DEFAULT_TARGET_ONLY)
128128
set(triple "${COMPILER_RT_DEFAULT_TARGET_TRIPLE}")
129129
else()

compiler-rt/cmake/builtin-config-ix.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ else()
5959
endif()
6060

6161
set(AMDGPU amdgcn)
62-
set(ARM64 aarch64)
62+
set(ARM64 aarch64 arm64ec)
6363
set(ARM32 arm armhf armv4t armv5te armv6 armv6m armv7m armv7em armv7 armv7s armv7k armv8m.base armv8m.main armv8.1m.main)
6464
set(AVR avr)
6565
set(HEXAGON hexagon)

compiler-rt/lib/builtins/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ set(armv7k_SOURCES ${arm_SOURCES})
668668
set(arm64_SOURCES ${aarch64_SOURCES})
669669
set(arm64e_SOURCES ${aarch64_SOURCES})
670670
set(arm64_32_SOURCES ${aarch64_SOURCES})
671+
set(arm64ec_SOURCES ${aarch64_SOURCES})
671672

672673
# macho_embedded archs
673674
set(armv6m_SOURCES ${thumb1_SOURCES})

compiler-rt/lib/builtins/aarch64/chkstk.S

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@
1515
// bl __chkstk
1616
// sub sp, sp, x15, lsl #4
1717

18-
#ifdef __aarch64__
18+
#if defined(__aarch64__) || defined(__arm64ec__)
19+
20+
#ifdef __arm64ec__
21+
#define CHKSTK_FUNC __chkstk_arm64ec
22+
#else
23+
#define CHKSTK_FUNC __chkstk
24+
#endif
1925

2026
#define PAGE_SIZE 4096
2127

2228
.p2align 2
23-
DEFINE_COMPILERRT_FUNCTION(__chkstk)
29+
DEFINE_COMPILERRT_FUNCTION(CHKSTK_FUNC)
2430
lsl x16, x15, #4
2531
mov x17, sp
2632
1:
@@ -30,6 +36,6 @@ DEFINE_COMPILERRT_FUNCTION(__chkstk)
3036
b.gt 1b
3137

3238
ret
33-
END_COMPILERRT_FUNCTION(__chkstk)
39+
END_COMPILERRT_FUNCTION(CHKSTK_FUNC)
3440

35-
#endif // __aarch64__
41+
#endif // defined(__aarch64__) || defined(__arm64ec__)

compiler-rt/lib/builtins/aarch64/lse.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// Routines may modify temporary registers tmp0, tmp1, tmp2,
2121
// return value x0 and the flags only.
2222

23-
#ifdef __aarch64__
23+
#if defined(__aarch64__) || defined(__arm64ec__)
2424

2525
#ifdef HAS_ASM_LSE
2626
.arch armv8-a+lse
@@ -267,4 +267,4 @@ NO_EXEC_STACK_DIRECTIVE
267267
// GNU property note for BTI and PAC
268268
GNU_PROPERTY_BTI_PAC
269269

270-
#endif // __aarch64__
270+
#endif // defined(__aarch64__) || defined(__arm64ec__)

compiler-rt/lib/builtins/aarch64/sme-libc-mem-routines.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ END_COMPILERRT_FUNCTION(__arm_sc_memcpy)
235235
DEFINE_COMPILERRT_FUNCTION_ALIAS(__arm_sc_memmove, __arm_sc_memcpy)
236236

237237
// This version uses FP registers. Use this only on targets with them
238-
#if defined(__aarch64__) && __ARM_FP != 0
238+
#if (defined(__aarch64__) && __ARM_FP != 0) || defined(__arm64ec__)
239239
//
240240
// __arm_sc_memset
241241
//

compiler-rt/lib/builtins/clear_cache.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@ uintptr_t GetCurrentProcess(void);
5959
// specified range.
6060

6161
void __clear_cache(void *start, void *end) {
62-
#if __i386__ || __x86_64__ || defined(_M_IX86) || defined(_M_X64)
62+
#if defined(_WIN32) && \
63+
(defined(__arm__) || defined(__aarch64__) || defined(__arm64ec__))
64+
FlushInstructionCache(GetCurrentProcess(), start, end - start);
65+
#elif __i386__ || __x86_64__ || defined(_M_IX86) || defined(_M_X64)
6366
// Intel processors have a unified instruction and data cache
6467
// so there is nothing to do
6568
#elif defined(__s390__)
6669
// no-op
67-
#elif defined(_WIN32) && (defined(__arm__) || defined(__aarch64__))
68-
FlushInstructionCache(GetCurrentProcess(), start, end - start);
6970
#elif defined(__arm__) && !defined(__APPLE__)
7071
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
7172
struct arm_sync_icache_args arg;

compiler-rt/lib/builtins/cpu_model/aarch64.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
#include "aarch64.h"
1616

17-
#if !defined(__aarch64__) && !defined(__arm64__) && !defined(_M_ARM64)
17+
#if !defined(__aarch64__) && !defined(__arm64__) && !defined(_M_ARM64) && \
18+
!defined(__arm64ec__) && !defined(_M_ARM64EC)
1819
#error This file is intended only for aarch64-based targets
1920
#endif
2021

compiler-rt/lib/builtins/cpu_model/aarch64.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
#include "cpu_model.h"
1010

11-
#if !defined(__aarch64__) && !defined(__arm64__) && !defined(_M_ARM64)
11+
#if !defined(__aarch64__) && !defined(__arm64__) && !defined(_M_ARM64) && \
12+
!defined(__arm64ec__) && !defined(_M_ARM64EC)
1213
#error This file is intended only for aarch64-based targets
1314
#endif
1415

compiler-rt/lib/builtins/fp_compare_impl.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// functions. We need to ensure that the return value is sign-extended in the
1313
// same way as GCC expects (since otherwise GCC-generated __builtin_isinf
1414
// returns true for finite 128-bit floating-point numbers).
15-
#ifdef __aarch64__
15+
#if defined(__aarch64__) || defined(__arm64ec__)
1616
// AArch64 GCC overrides libgcc_cmp_return to use int instead of long.
1717
typedef int CMP_RESULT;
1818
#elif __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 4

compiler-rt/lib/builtins/fp_lib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ static __inline fp_t __compiler_rt_scalbn(fp_t x, int y) {
359359
return __compiler_rt_scalbnX(x, y);
360360
}
361361
static __inline fp_t __compiler_rt_fmax(fp_t x, fp_t y) {
362-
#if defined(__aarch64__)
362+
#if defined(__aarch64__) || defined(__arm64ec__)
363363
// Use __builtin_fmax which turns into an fmaxnm instruction on AArch64.
364364
return __builtin_fmax(x, y);
365365
#else

compiler-rt/lib/builtins/udivmodti4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static inline du_int udiv128by64to64default(du_int u1, du_int u0, du_int v,
8383

8484
static inline du_int udiv128by64to64(du_int u1, du_int u0, du_int v,
8585
du_int *r) {
86-
#if defined(__x86_64__)
86+
#if defined(__x86_64__) && !defined(__arm64ec__)
8787
du_int result;
8888
__asm__("divq %[v]"
8989
: "=a"(result), "=d"(*r)

compiler-rt/test/builtins/Unit/enable_execute_stack_test.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,22 @@ extern void __enable_execute_stack(void* addr);
1010

1111
typedef int (*pfunc)(void);
1212

13+
#ifdef __arm64ec__
14+
// On ARM64EC, we need the x86_64 version of this function, but the compiler
15+
// would normally generate the AArch64 variant, so we hardcode it here.
16+
static char func1[] = {
17+
0xb8, 0x01, 0x00, 0x00, 0x00, // movl $0x1, %eax
18+
0xc3 // retq
19+
};
20+
static char func2[] = {
21+
0xb8, 0x02, 0x00, 0x00, 0x00, // movl $0x2, %eax
22+
0xc3 // retq
23+
};
24+
#else
1325
// Make these static to avoid ILT jumps for incremental linking on Windows.
1426
static int func1() { return 1; }
1527
static int func2() { return 2; }
28+
#endif
1629

1730
void *__attribute__((noinline))
1831
memcpy_f(void *dst, const void *src, size_t n) {

compiler-rt/test/builtins/Unit/fixunstfdi_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <stdio.h>
66

7-
#if _ARCH_PPC || __aarch64__
7+
#if _ARCH_PPC || __aarch64__ || __arm64ec__
88

99
#include "int_lib.h"
1010

@@ -35,7 +35,7 @@ char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
3535

3636
int main()
3737
{
38-
#if _ARCH_PPC || __aarch64__
38+
#if _ARCH_PPC || __aarch64__ || __arm64ec__
3939
if (test__fixunstfdi(0.0, 0))
4040
return 1;
4141

compiler-rt/test/builtins/Unit/multc3_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <stdio.h>
66

7-
#if _ARCH_PPC || __aarch64__
7+
#if _ARCH_PPC || __aarch64__ || __arm64ec__
88

99
#include "int_lib.h"
1010
#include <math.h>
@@ -348,7 +348,7 @@ long double x[][2] =
348348

349349
int main()
350350
{
351-
#if _ARCH_PPC || __aarch64__
351+
#if _ARCH_PPC || __aarch64__ || __arm64ec__
352352
const unsigned N = sizeof(x) / sizeof(x[0]);
353353
unsigned i, j;
354354
for (i = 0; i < N; ++i)

0 commit comments

Comments
 (0)