Skip to content

Commit

Permalink
MacOS Support from EMCC branch
Browse files Browse the repository at this point in the history
Signed-off-by: Shaw Summa <[email protected]>
  • Loading branch information
ShawSumma committed Feb 28, 2024
1 parent 4391c1c commit 9d89285
Show file tree
Hide file tree
Showing 32 changed files with 28,492 additions and 14 deletions.
5 changes: 5 additions & 0 deletions macos.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

EXTRA_SRCS = vendor/c11threads/threads_posix.c
CFLAGS := -I vendor/c11threads $(CFLAGS)

include makefile
6 changes: 3 additions & 3 deletions vendor/common/perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void cuikperf_thread_start(void) {
#if _WIN32
uint32_t tid = GetCurrentThreadId();
#else
uint32_t tid = pthread_self();
uint32_t tid = 0;
#endif

if (profiling) {
Expand Down Expand Up @@ -201,7 +201,7 @@ void cuikperf_region_start(const char* label, const char* extra) {
#if _WIN32
uint32_t tid = GetCurrentThreadId();
#else
uint32_t tid = pthread_self();
uint32_t tid = 0;
#endif

spall_buffer_begin_args(&ctx, &muh_buffer, label, strlen(label), extra, extra ? strlen(extra) : 0, nanos, tid, 0);
Expand All @@ -217,7 +217,7 @@ void cuikperf_region_end(void) {
#if _WIN32
uint32_t tid = GetCurrentThreadId();
#else
uint32_t tid = pthread_self();
uint32_t tid = 0;
#endif

spall_buffer_end_ex(&ctx, &muh_buffer, nanos, tid, 0);
Expand Down
12 changes: 10 additions & 2 deletions vendor/tb/src/builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,20 @@ static TB_MultiplyResult tb_mul64x128(uint64_t a, uint64_t b) {
}

static uint64_t tb_div128(uint64_t ahi, uint64_t alo, uint64_t b) {
// We don't want 128 bit software division
#if defined(TB_HOST_X86_64)
// // We don't want 128 bit software division
uint64_t d, e;
__asm__("divq %[b]"
: "=a"(d), "=d"(e)
: [b] "r"(b), "a"(alo), "d"(ahi)
);
return d;
#else
__uint128_t x = 0;
x += alo;
x <<= 64;
x += ahi;
x /= b;
return x;
#endif
}
#endif
2 changes: 1 addition & 1 deletion vendor/tb/src/libtb.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void* tb_jit_stack_create(void) {
return VirtualAlloc2(GetCurrentProcess(), NULL, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE, &param, 1);
}
#endif /* NTDDI_VERSION >= NTDDI_WIN10_RS4 */
#elif defined(_POSIX_C_SOURCE)
#elif defined(_POSIX_C_SOURCE) || defined(__APPLE__)
void* tb_platform_valloc(size_t size) {
return mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
}
Expand Down
2 changes: 2 additions & 0 deletions vendor/tb/src/tb.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ char* tb__arena_strdup(TB_Module* m, ptrdiff_t len, const char* src) {
TB_Module* tb_module_create_for_host(bool is_jit) {
#if defined(TB_HOST_X86_64)
TB_Arch arch = TB_ARCH_X86_64;
#elif defined(TB_HOST_ARM64)
TB_Arch arch = TB_ARCH_AARCH64;
#else
TB_Arch arch = TB_ARCH_UNKNOWN;
tb_panic("tb_module_create_for_host: cannot detect host platform");
Expand Down
Loading

0 comments on commit 9d89285

Please sign in to comment.