Skip to content

Commit a8b4c74

Browse files
authored
Merge pull request #61 from nature-lang/feature/arm64_debug
feat: arm64 test pass
2 parents 36061e4 + 6d58dc1 commit a8b4c74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+3745
-3129
lines changed

CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ if (CMAKE_BUILD_TYPE MATCHES Debug)
2828
# add_compile_definitions(NATURE_DEBUG)
2929
add_compile_definitions(DEBUG_LIR)
3030
add_compile_definitions(DEBUG_ASM)
31-
add_compile_definitions(DEBUG_PARSER)
31+
# add_compile_definitions(DEBUG_PARSER)
32+
# add_compile_definitions(DEBUG_INTERVAL)
3233
# add_compile_definitions(DEBUG_INTERVAL)
3334
# add_compile_definitions(DEBUG_MACHO)
3435
add_compile_definitions(ASSERT_ERROR)

cmake/linux-amd64-toolchain.cmake

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
set(CMAKE_C_COMPILER x86_64-linux-musl-gcc)
2-
set(CMAKE_CXX_COMPILER x86_64-linux-musl-g++)
1+
find_program(CMAKE_C_COMPILER
2+
NAMES
3+
x86_64-linux-musl-gcc
4+
musl-gcc
5+
cc
6+
REQUIRED
7+
)
8+
39
set(CMAKE_EXE_LINKER_FLAGS "-static")
410

511
set(CMAKE_SYSTEM_NAME linux)

cmake/linux-arm64-toolchain.cmake

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
set(CMAKE_C_COMPILER aarch64-linux-musl-gcc)
2-
set(CMAKE_CXX_COMPILER aarch64-linux-musl-g++)
1+
# 按优先级查找可用的编译器
2+
find_program(CMAKE_C_COMPILER
3+
NAMES
4+
aarch64-linux-musl-gcc
5+
musl-gcc
6+
cc
7+
REQUIRED
8+
)
39
set(CMAKE_EXE_LINKER_FLAGS "-static")
410
#set(CMAKE_FIND_LIBRARY_SUFFIXES "")
511

include/uv.h

+65-7
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@ typedef struct uv_metrics_s uv_metrics_t;
260260

261261
typedef enum {
262262
UV_LOOP_BLOCK_SIGNAL = 0,
263-
UV_METRICS_IDLE_TIME
263+
UV_METRICS_IDLE_TIME,
264+
UV_LOOP_USE_IO_URING_SQPOLL
265+
#define UV_LOOP_USE_IO_URING_SQPOLL UV_LOOP_USE_IO_URING_SQPOLL
264266
} uv_loop_option;
265267

266268
typedef enum {
@@ -604,7 +606,18 @@ UV_EXTERN int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable);
604606

605607
enum uv_tcp_flags {
606608
/* Used with uv_tcp_bind, when an IPv6 address is used. */
607-
UV_TCP_IPV6ONLY = 1
609+
UV_TCP_IPV6ONLY = 1,
610+
611+
/* Enable SO_REUSEPORT socket option when binding the handle.
612+
* This allows completely duplicate bindings by multiple processes
613+
* or threads if they all set SO_REUSEPORT before binding the port.
614+
* Incoming connections are distributed across the participating
615+
* listener sockets.
616+
*
617+
* This flag is available only on Linux 3.9+, DragonFlyBSD 3.6+,
618+
* FreeBSD 12.0+, Solaris 11.4, and AIX 7.2.5+ for now.
619+
*/
620+
UV_TCP_REUSEPORT = 2,
608621
};
609622

610623
UV_EXTERN int uv_tcp_bind(uv_tcp_t* handle,
@@ -645,10 +658,13 @@ enum uv_udp_flags {
645658
UV_UDP_PARTIAL = 2,
646659
/*
647660
* Indicates if SO_REUSEADDR will be set when binding the handle.
648-
* This sets the SO_REUSEPORT socket flag on the BSDs and OS X. On other
649-
* Unix platforms, it sets the SO_REUSEADDR flag. What that means is that
650-
* multiple threads or processes can bind to the same address without error
651-
* (provided they all set the flag) but only the last one to bind will receive
661+
* This sets the SO_REUSEPORT socket flag on the BSDs (except for
662+
* DragonFlyBSD), OS X, and other platforms where SO_REUSEPORTs don't
663+
* have the capability of load balancing, as the opposite of what
664+
* UV_UDP_REUSEPORT would do. On other Unix platforms, it sets the
665+
* SO_REUSEADDR flag. What that means is that multiple threads or
666+
* processes can bind to the same address without error (provided
667+
* they all set the flag) but only the last one to bind will receive
652668
* any traffic, in effect "stealing" the port from the previous listener.
653669
*/
654670
UV_UDP_REUSEADDR = 4,
@@ -671,6 +687,18 @@ enum uv_udp_flags {
671687
* This flag is no-op on platforms other than Linux.
672688
*/
673689
UV_UDP_LINUX_RECVERR = 32,
690+
/*
691+
* Indicates if SO_REUSEPORT will be set when binding the handle.
692+
* This sets the SO_REUSEPORT socket option on supported platforms.
693+
* Unlike UV_UDP_REUSEADDR, this flag will make multiple threads or
694+
* processes that are binding to the same address and port "share"
695+
* the port, which means incoming datagrams are distributed across
696+
* the receiving sockets among threads or processes.
697+
*
698+
* This flag is available only on Linux 3.9+, DragonFlyBSD 3.6+,
699+
* FreeBSD 12.0+, Solaris 11.4, and AIX 7.2.5+ for now.
700+
*/
701+
UV_UDP_REUSEPORT = 64,
674702
/*
675703
* Indicates that recvmmsg should be used, if available.
676704
*/
@@ -1106,7 +1134,14 @@ enum uv_process_flags {
11061134
* option is only meaningful on Windows systems. On Unix it is silently
11071135
* ignored.
11081136
*/
1109-
UV_PROCESS_WINDOWS_HIDE_GUI = (1 << 6)
1137+
UV_PROCESS_WINDOWS_HIDE_GUI = (1 << 6),
1138+
/*
1139+
* On Windows, if the path to the program to execute, specified in
1140+
* uv_process_options_t's file field, has a directory component,
1141+
* search for the exact file name before trying variants with
1142+
* extensions like '.exe' or '.cmd'.
1143+
*/
1144+
UV_PROCESS_WINDOWS_FILE_PATH_EXACT_NAME = (1 << 7)
11101145
};
11111146

11121147
/*
@@ -1284,6 +1319,17 @@ UV_EXTERN uv_pid_t uv_os_getppid(void);
12841319
UV_EXTERN int uv_os_getpriority(uv_pid_t pid, int* priority);
12851320
UV_EXTERN int uv_os_setpriority(uv_pid_t pid, int priority);
12861321

1322+
enum {
1323+
UV_THREAD_PRIORITY_HIGHEST = 2,
1324+
UV_THREAD_PRIORITY_ABOVE_NORMAL = 1,
1325+
UV_THREAD_PRIORITY_NORMAL = 0,
1326+
UV_THREAD_PRIORITY_BELOW_NORMAL = -1,
1327+
UV_THREAD_PRIORITY_LOWEST = -2,
1328+
};
1329+
1330+
UV_EXTERN int uv_thread_getpriority(uv_thread_t tid, int* priority);
1331+
UV_EXTERN int uv_thread_setpriority(uv_thread_t tid, int priority);
1332+
12871333
UV_EXTERN unsigned int uv_available_parallelism(void);
12881334
UV_EXTERN int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count);
12891335
UV_EXTERN void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count);
@@ -1885,6 +1931,18 @@ struct uv_loop_s {
18851931
UV_EXTERN void* uv_loop_get_data(const uv_loop_t*);
18861932
UV_EXTERN void uv_loop_set_data(uv_loop_t*, void* data);
18871933

1934+
/* Unicode utilities needed for dealing with Windows. */
1935+
UV_EXTERN size_t uv_utf16_length_as_wtf8(const uint16_t* utf16,
1936+
ssize_t utf16_len);
1937+
UV_EXTERN int uv_utf16_to_wtf8(const uint16_t* utf16,
1938+
ssize_t utf16_len,
1939+
char** wtf8_ptr,
1940+
size_t* wtf8_len_ptr);
1941+
UV_EXTERN ssize_t uv_wtf8_length_as_utf16(const char* wtf8);
1942+
UV_EXTERN void uv_wtf8_to_utf16(const char* wtf8,
1943+
uint16_t* utf16,
1944+
size_t utf16_len);
1945+
18881946
/* Don't export the private CPP symbols. */
18891947
#undef UV_HANDLE_TYPE_PRIVATE
18901948
#undef UV_REQ_TYPE_PRIVATE

include/uv/darwin.h

-61
This file was deleted.

include/uv/unix.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,10 @@ typedef struct {
328328

329329
#define UV_TIMER_PRIVATE_FIELDS \
330330
uv_timer_cb timer_cb; \
331-
void* heap_node[3]; \
331+
union { \
332+
void* heap[3]; \
333+
struct uv__queue queue; \
334+
} node; \
332335
uint64_t timeout; \
333336
uint64_t repeat; \
334337
uint64_t start_id;

include/uv/version.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
*/
3232

3333
#define UV_VERSION_MAJOR 1
34-
#define UV_VERSION_MINOR 46
35-
#define UV_VERSION_PATCH 1
36-
#define UV_VERSION_IS_RELEASE 0
37-
#define UV_VERSION_SUFFIX "dev"
34+
#define UV_VERSION_MINOR 49
35+
#define UV_VERSION_PATCH 2
36+
#define UV_VERSION_IS_RELEASE 1
37+
#define UV_VERSION_SUFFIX ""
3838

3939
#define UV_VERSION_HEX ((UV_VERSION_MAJOR << 16) | \
4040
(UV_VERSION_MINOR << 8) | \

lib/linux_arm64/crt1.o

8 Bytes
Binary file not shown.

lib/linux_arm64/libc.a

655 KB
Binary file not shown.

lib/linux_arm64/libuv.a

-186 KB
Binary file not shown.

lib/linux_arm64/main.o

-1.54 KB
Binary file not shown.

runtime/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ include(../cmake/cross.cmake)
1111

1212
set(CMAKE_C_STANDARD 11)
1313

14+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static")
15+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
16+
1417
add_compile_definitions(RUNTIME)
1518
message("add compile def RUNTIME")
1619

runtime/aco/aco.c

+10-13
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
static uint64_t share_stack_base = MMAP_SHARE_STACK_BASE;
2424

2525
void aco_runtime_test(void) {
26-
#ifdef __x86_64__
26+
#if defined(__x86_64__) || defined(__aarch64__)
2727
assert(sizeof(void *) == 8 && "require 'sizeof(void*) == 8'");
2828
assert(sizeof(__uint128_t) == 16 && "require 'sizeof(__uint128_t) == 16'");
29-
#elif defined(__aarch64__)
30-
assert(sizeof(void *) == 8 && "require 'sizeof(void*) == 8'");
3129
#else
3230
#error "platform no support yet"
3331
#endif
@@ -169,12 +167,6 @@ uv_key_t aco_gtls_co;
169167

170168
uv_key_t aco_gtls_last_word_fp;
171169

172-
// static __thread void* aco_gtls_fpucw_mxcsr[2];
173-
// #elif __x86_64__
174-
// static __thread void *aco_gtls_fpucw_mxcsr[1];
175-
// #else
176-
// #error "platform no support yet"
177-
// #endif
178170
uv_key_t aco_gtls_fpucw_mxcsr;
179171
pthread_mutex_t share_stack_lock;
180172

@@ -281,7 +273,14 @@ void *aco_share_stack_init(aco_share_stack_t *p, size_t sz) {
281273
uintptr_t u_p = (uintptr_t) (p->sz - (sizeof(void *) << 1) + (uintptr_t) p->ptr);
282274
u_p = (u_p >> 4) << 4;
283275
p->align_highptr = (void *) u_p;
284-
p->align_retptr = (void *) (u_p - sizeof(void *));
276+
277+
#ifdef __aarch64__
278+
// aarch64 hardware-enforces 16 byte stack alignment
279+
p->align_retptr = (void*)(u_p - 16);
280+
#else
281+
p->align_retptr = (void*)(u_p - sizeof(void*));
282+
#endif
283+
285284
*((void **) (p->align_retptr)) = (void *) (aco_funcp_protector_asm);
286285
assert(p->sz > (16 + (sizeof(void *) << 1) + sizeof(void *)));
287286
p->align_limit = p->sz - 16 - (sizeof(void *) << 1);
@@ -314,10 +313,8 @@ void aco_create_init(aco_t *aco, aco_t *main_co, aco_share_stack_t *share_stack,
314313
aco->reg[ACO_REG_IDX_SP] = aco->share_stack->align_retptr;
315314
aco->reg[ACO_REG_IDX_FPU] = uv_key_get(&aco_gtls_fpucw_mxcsr);
316315
#elif defined(__aarch64__)
317-
aco->reg[ACO_REG_IDX_RETADDR] = (void *) fp;
316+
aco->reg[ACO_REG_IDX_RETADDR] = (void*)fp;
318317
aco->reg[ACO_REG_IDX_SP] = aco->share_stack->align_retptr;
319-
aco->reg[ACO_REG_IDX_BP] = aco->share_stack->align_retptr;
320-
// ARM64 不需要保存 FPU 状态,因为它使用独立的 NEON/FP 寄存器
321318
#else
322319
#error "platform no support yet"
323320
#endif

runtime/aco/aco.h

+12-5
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
#define ACO_REG_IDX_BP 7
4545
#define ACO_REG_IDX_FPU 8
4646
#elif defined(__aarch64__)
47-
#define ACO_REG_IDX_RETADDR 0
48-
#define ACO_REG_IDX_SP 1
49-
#define ACO_REG_IDX_BP 2
50-
#define ACO_REG_IDX_FPU 3
47+
#define ACO_REG_IDX_RETADDR 13
48+
#define ACO_REG_IDX_SP 14
49+
#define ACO_REG_IDX_BP 12
50+
#define ACO_REG_IDX_FPU 15
5151
#else
5252
#error "platform no support yet"
5353
#endif
@@ -75,7 +75,7 @@ typedef struct {
7575
void *ptr;
7676
size_t sz;
7777
void *align_highptr;
78-
void *align_retptr; // 最大值
78+
void *align_retptr;
7979
size_t align_validsz;
8080
size_t align_limit;
8181
aco_t *owner;
@@ -93,7 +93,14 @@ typedef struct {
9393
typedef void (*aco_cofuncp_t)(void);
9494

9595
struct aco_s {
96+
#ifdef __X86_64__
9697
void *reg[9]; // amd64 试用
98+
#elif __aarch64__
99+
void* reg[16];
100+
#else
101+
#error "platform no support yet"
102+
#endif
103+
97104

98105
aco_t *main_co;
99106
void *arg;

0 commit comments

Comments
 (0)