Skip to content

Commit af58421

Browse files
committed
Apple Silicon support, miscellaneous
- small changes e.g. alternatives for windows intrinsics - build file updates
1 parent 40b603e commit af58421

File tree

9 files changed

+88
-14
lines changed

9 files changed

+88
-14
lines changed

CMakeLists.txt

+29-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ if(CC_USES_SYSTEM_ARCH_SH OR NOT CHAKRACORE_BUILD_SH)
4646
set(CC_TARGETS_AMD64_SH 1)
4747
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
4848
set(CC_TARGETS_ARM_SH 1)
49+
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
50+
set(CC_TARGETS_ARM64_SH 1)
4951
endif()
5052
unset(CC_USES_SYSTEM_ARCH_SH CACHE)
5153
endif()
@@ -56,6 +58,11 @@ elseif(CC_TARGETS_ARM_SH)
5658
set(CC_TARGETS_ARM 1)
5759
add_definitions(-D_ARM_=1)
5860
set(CMAKE_SYSTEM_PROCESSOR "armv7l")
61+
elseif(CC_TARGETS_ARM64_SH)
62+
add_definitions(-D_ARM64_=1)
63+
add_definitions(-D__arm64__=1)
64+
set(CC_TARGETS_ARM64 1)
65+
set(CMAKE_SYSTEM_PROCESSOr "arm64")
5966
elseif(CC_TARGETS_X86_SH)
6067
set(CC_TARGETS_X86 1)
6168
set(CMAKE_SYSTEM_PROCESSOR "i386")
@@ -273,8 +280,15 @@ elseif(CC_TARGETS_ARM)
273280
# reduce link time memory usage
274281
set(LINKER_REDUCED_MEMORY "-Xlinker --no-keep-memory")
275282
endif()
283+
elseif(CC_TARGETS_ARM64)
284+
add_definitions(-D__aarch64__)
285+
add_definitions(-DTARGET_64)
286+
add_definitions(-D_M_ARM32_OR_ARM64)
287+
if(CC_TARGET_OS_OSX)
288+
add_compile_options(-arch arm64)
289+
endif()
276290
else()
277-
message(FATAL_ERROR "Only AMD64, ARM and I386 are supported")
291+
message(FATAL_ERROR "Only AMD64, ARM, ARM64 and I386 are supported")
278292
endif()
279293

280294
if(CAN_BUILD_WABT)
@@ -341,7 +355,10 @@ if(CLR_CMAKE_PLATFORM_XPLAT)
341355
if(CC_TARGETS_AMD64)
342356
set(IS_64BIT_BUILD 1)
343357
add_definitions(-D_M_X64 -D_M_AMD64 -D_AMD64_)
344-
endif(CC_TARGETS_AMD64)
358+
elseif(CC_TARGETS_ARM64)
359+
set(IS_64BIT_BUILD 1)
360+
add_definitions(-D_M_ARM64 -D_ARM64_)
361+
endif()
345362

346363
add_definitions(
347364
-DUNICODE
@@ -495,6 +512,16 @@ else()
495512
set(DYN_LIB_EXT "so")
496513
endif()
497514

515+
if(CC_TARGETS_ARM64)
516+
if(CC_TARGET_OS_LINUX)
517+
message(WARNING "ARM64 linux build has not yet been tested, this build is unsupported.")
518+
endif()
519+
if(BuildJIT)
520+
message(WARNING "ARM64 Jit not yet functional on platforms other than windows.")
521+
message(WARNING "For use rather than development please build with Jit disabled --no-jit with ./build.sh or -DDISABLE_JIT=1 if using CMake directly")
522+
endif()
523+
endif()
524+
498525
################# Write-barrier check/analyze ##################
499526
if (WB_CHECK_SH OR WB_ANALYZE_SH)
500527
add_definitions(

build.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
#-------------------------------------------------------------------------------------------------------
33
# Copyright (C) Microsoft. All rights reserved.
4-
# Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved.
4+
# Copyright (c) ChakraCore Project Contributors. All rights reserved.
55
# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
66
#-------------------------------------------------------------------------------------------------------
77

@@ -122,7 +122,7 @@ WB_CHECK=
122122
WB_ANALYZE=
123123
WB_ARGS=
124124
TARGET_PATH=0
125-
VALGRIND=0
125+
VALGRIND=""
126126
# -DCMAKE_EXPORT_COMPILE_COMMANDS=ON useful for clang-query tool
127127
CMAKE_EXPORT_COMPILE_COMMANDS="-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
128128
LIBS_ONLY_BUILD=
@@ -620,6 +620,9 @@ if [[ $ARCH =~ "x86" ]]; then
620620
elif [[ $ARCH =~ "arm" ]]; then
621621
ARCH="-DCC_TARGETS_ARM_SH=1"
622622
echo "Compile Target : arm"
623+
elif [[ $ARCH =~ "arm64" ]]; then
624+
ARCH="-DCC_TARGETS_ARM64_SH=1"
625+
echo "Compile Target : arm64"
623626
elif [[ $ARCH =~ "amd64" ]]; then
624627
ARCH="-DCC_TARGETS_AMD64_SH=1"
625628
echo "Compile Target : amd64"

lib/CMakeLists.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ if (EMBED_ICU)
125125
# Declare ICU dependencies in bulk.
126126
# TODO Not the most idiomatic solution, need to understand if all of those
127127
# libraries needed to depend on it
128-
add_dependencies(Chakra.Backend ${EMBEDDED_ICU_TARGET})
129128
add_dependencies(Chakra.Jsrt ${EMBEDDED_ICU_TARGET})
130129
add_dependencies(Chakra.Jsrt.Core ${EMBEDDED_ICU_TARGET})
131130
add_dependencies(Chakra.Parser ${EMBEDDED_ICU_TARGET})
@@ -138,5 +137,10 @@ if (EMBED_ICU)
138137
add_dependencies(Chakra.Runtime.PlatformAgnostic ${EMBEDDED_ICU_TARGET})
139138
add_dependencies(Chakra.Runtime.Types ${EMBEDDED_ICU_TARGET})
140139
add_dependencies(Chakra.SCACore ${EMBEDDED_ICU_TARGET})
141-
add_dependencies(Chakra.WasmReader ${EMBEDDED_ICU_TARGET})
140+
if (BuildJIT)
141+
add_dependencies(Chakra.Backend ${EMBEDDED_ICU_TARGET})
142+
if (CC_TARGETS_AMD64)
143+
add_dependencies(Chakra.WasmReader ${EMBEDDED_ICU_TARGET})
144+
endif()
145+
endif()
142146
endif()

lib/Common/Common/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
if(CC_TARGETS_ARM)
22
set(ARCH_SOURCES arm/arm_GET_CURRENT_FRAME.S)
3+
elseif(CC_TARGETS_ARM64)
4+
set(ARCH_SOURCES arm64/arm64_GET_CURRENT_FRAME.S)
35
endif()
46

57
add_library (Chakra.Common.Common OBJECT

lib/Common/Common/NumberUtilities.inl

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//-------------------------------------------------------------------------------------------------------
22
// Copyright (C) Microsoft Corporation and contributors. All rights reserved.
3+
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
34
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
45
//-------------------------------------------------------------------------------------------------------
56

@@ -176,7 +177,7 @@ namespace Js
176177
{
177178
#if defined(_AMD64_)
178179
return _mm_cvtsi128_si64(_mm_castpd_si128(_mm_set_sd(value)));
179-
#elif defined(_M_ARM32_OR_ARM64)
180+
#elif defined(_M_ARM32_OR_ARM64) && defined(_CopyInt64FromDouble)
180181
return _CopyInt64FromDouble(value);
181182
#else
182183
return *(reinterpret_cast<uint64 *>(&value));
@@ -187,7 +188,7 @@ namespace Js
187188
{
188189
#if defined(_AMD64_) || _M_IX86_FP >= 2 || defined(__AVX__)
189190
return _mm_cvtsi128_si32(_mm_castps_si128(_mm_set_ss(value)));
190-
#elif defined(_M_ARM32_OR_ARM64)
191+
#elif defined(_M_ARM32_OR_ARM64) && defined(_CopyInt32FromFloat)
191192
return _CopyInt32FromFloat(value);
192193
#else
193194
return *(reinterpret_cast<uint32 *>(&value));
@@ -198,7 +199,7 @@ namespace Js
198199
{
199200
#if defined(_AMD64_) || _M_IX86_FP >= 2 || defined(__AVX__)
200201
return _mm_cvtss_f32(_mm_castsi128_ps(_mm_cvtsi32_si128(value)));
201-
#elif defined(_M_ARM32_OR_ARM64)
202+
#elif defined(_M_ARM32_OR_ARM64) && defined(_CopyFloatFromInt32)
202203
return _CopyFloatFromInt32(value);
203204
#else
204205
return *(reinterpret_cast<float *>(&value));
@@ -209,7 +210,7 @@ namespace Js
209210
{
210211
#if defined(_AMD64_)
211212
return _mm_cvtsd_f64(_mm_castsi128_pd(_mm_cvtsi64_si128(value)));
212-
#elif defined(_M_ARM32_OR_ARM64)
213+
#elif defined(_M_ARM32_OR_ARM64) && defined(_CopyDoubleFromInt64)
213214
return _CopyDoubleFromInt64(value);
214215
#else
215216
return *(reinterpret_cast<double *>(&value));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
4+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
5+
//-------------------------------------------------------------------------------------------------------
6+
7+
#include "unixasmmacros.inc"
8+
9+
NESTED_ENTRY arm64_GET_CURRENT_FRAME, _TEXT, NoHandler
10+
11+
mov x0,x29
12+
br lr
13+
14+
NESTED_END arm64_GET_CURRENT_FRAME

lib/Common/CommonPal.h

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//-------------------------------------------------------------------------------------------------------
22
// Copyright (C) Microsoft. All rights reserved.
3+
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
34
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
45
//-------------------------------------------------------------------------------------------------------
56
#pragma once
@@ -388,6 +389,18 @@ typedef union _SLIST_HEADER {
388389
} DUMMYSTRUCTNAME;
389390
} SLIST_HEADER, *PSLIST_HEADER;
390391

392+
#elif defined(_ARM64_)
393+
394+
typedef union _SLIST_HEADER {
395+
ULONGLONG Alignment;
396+
struct {
397+
SLIST_ENTRY Next;
398+
WORD Depth;
399+
WORD Reserved;
400+
} DUMMYSTRUCTNAME;
401+
} SLIST_HEADER, *PSLIST_HEADER;
402+
403+
391404
#endif
392405

393406
PALIMPORT VOID PALAPI InitializeSListHead(IN OUT PSLIST_HEADER ListHead);
@@ -663,7 +676,7 @@ namespace PlatformAgnostic
663676
{
664677
__forceinline unsigned char _BitTestAndSet(LONG *_BitBase, int _BitPos)
665678
{
666-
#if defined(__clang__) && !defined(_ARM_)
679+
#if defined(__clang__) && !defined(_ARM_) && !defined(_ARM64_)
667680
// Clang doesn't expand _bittestandset intrinic to bts, and it's implemention also doesn't work for _BitPos >= 32
668681
unsigned char retval = 0;
669682
asm(
@@ -681,7 +694,7 @@ namespace PlatformAgnostic
681694

682695
__forceinline unsigned char _BitTest(LONG *_BitBase, int _BitPos)
683696
{
684-
#if defined(__clang__) && !defined(_ARM_)
697+
#if defined(__clang__) && !defined(_ARM_) && !defined(_ARM64_)
685698
// Clang doesn't expand _bittest intrinic to bt, and it's implemention also doesn't work for _BitPos >= 32
686699
unsigned char retval;
687700
asm(
@@ -699,7 +712,7 @@ namespace PlatformAgnostic
699712

700713
__forceinline unsigned char _InterlockedBitTestAndSet(volatile LONG *_BitBase, int _BitPos)
701714
{
702-
#if defined(__clang__) && !defined(_ARM_)
715+
#if defined(__clang__) && !defined(_ARM_) && !defined(_ARM64_)
703716
// Clang doesn't expand _interlockedbittestandset intrinic to lock bts, and it's implemention also doesn't work for _BitPos >= 32
704717
unsigned char retval;
705718
asm(
@@ -717,7 +730,7 @@ namespace PlatformAgnostic
717730

718731
__forceinline unsigned char _InterlockedBitTestAndReset(volatile LONG *_BitBase, int _BitPos)
719732
{
720-
#if defined(__clang__) && !defined(_ARM_)
733+
#if defined(__clang__) && !defined(_ARM_) && !defined(_ARM64_)
721734
// Clang doesn't expand _interlockedbittestandset intrinic to lock btr, and it's implemention also doesn't work for _BitPos >= 32
722735
unsigned char retval;
723736
asm(

lib/Common/PlatformAgnostic/AssemblyCommon.h

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//-------------------------------------------------------------------------------------------------------
22
// Copyright (C) Microsoft. All rights reserved.
3+
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
34
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
45
//-------------------------------------------------------------------------------------------------------
56
#pragma once
@@ -24,6 +25,9 @@ void mac_fde_wrapper(const char *dataStart, mac_fde_reg_op reg_op);
2425
#define __REGISTER_FRAME(addr) __register_frame(addr)
2526
#define __DEREGISTER_FRAME(addr) __deregister_frame(addr)
2627
#endif // __APPLE__
28+
#elif defined(_M_ARM64) // _AMD64_ && !DISABLE_JIT
29+
#define __REGISTER_FRAME(addr) __register_frame(addr)
30+
#define __DEREGISTER_FRAME(addr) __deregister_frame(addr)
2731
#else
2832
#define __REGISTER_FRAME(addr)
2933
#define __DEREGISTER_FRAME(addr)

lib/Common/arm64.h

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//-------------------------------------------------------------------------------------------------------
22
// Copyright (C) Microsoft. All rights reserved.
3+
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
34
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
45
//-------------------------------------------------------------------------------------------------------
56
// ARM64-specific macro definitions
@@ -10,7 +11,12 @@
1011
#error Include arm64.h in builds of ARM64 targets only.
1112
#endif
1213

14+
#ifdef __getReg
1315
#define arm64_GET_CURRENT_FRAME() ((LPVOID)__getReg(29))
16+
#else
17+
extern "C" LPVOID arm64_GET_CURRENT_FRAME(void);
18+
#endif
19+
1420
extern "C" VOID arm64_SAVE_REGISTERS(void*);
1521

1622
/*

0 commit comments

Comments
 (0)