Skip to content

AArch64 JIT backend#895

Open
bmdhacks wants to merge 9 commits intoHaxeFoundation:masterfrom
bmdhacks:aarch64-jit
Open

AArch64 JIT backend#895
bmdhacks wants to merge 9 commits intoHaxeFoundation:masterfrom
bmdhacks:aarch64-jit

Conversation

@bmdhacks
Copy link

Enable HashLink VM on AArch64 (Apple Silicon, ARM Linux servers, etc.) by adding a new JIT backend alongside the existing x86/x64 one.

  • Rename jit.c to jit_x86.c, extract shared code into jit_common.h/jit_shared.c
  • Add jit_aarch64.c/jit_aarch64_emit.c for ARM64 instruction selection and encoding
  • Add jit_elf.c for GDB JIT debug interface
  • Architecture-aware JIT selection in Makefile and CMakeLists.txt
  • Add aarch64 support in hl.h, profile.c, hlmodule.h, module.c

@bmdhacks
Copy link
Author

Just some background on this submission. I created this backend for some work on the PortMaster project of running classic PC games on cheap arm linux handhelds. It was developed entirely with claude code, so if you have an aversion to LLM development, this is severely tainted. It's been tested on haxe unit.hl as well as running Dead Cells on my M2 Asahi Linux machine.

It's not super fancy, the register allocation scheme is pretty basic. We do try to utilize callee and caller-saved registers when we can. Still, it runs well enough for my needs.

Copy link
Member

@tobil4sk tobil4sk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this looks quite exciting! :) Just a few general comments, which will hopefully help clean things up a bit. I haven't looked at the actual jit implementation, hopefully someone else might be able to.

@ncannasse
Copy link
Member

Interesting but a lot of changes. One question: does your implementation passes Haxe compiler unit tests? That would be a requirement before any merge.

@bmdhacks
Copy link
Author

bmdhacks commented Feb 27, 2026

Interesting but a lot of changes. One question: does your implementation passes Haxe compiler unit tests? That would be a requirement before any merge.

Yes all but three related to stack trace formatting.

bmdhacks and others added 7 commits February 27, 2026 16:30
Enable HashLink VM on AArch64 (Apple Silicon, ARM Linux servers, etc.)
by adding a new JIT backend alongside the existing x86/x64 one.

- Rename jit.c to jit_x86.c, extract shared code into jit_common.h/jit_shared.c
- Add jit_aarch64.c/jit_aarch64_emit.c for ARM64 instruction selection and encoding
- Add jit_elf.c for GDB JIT debug interface
- Architecture-aware JIT selection in Makefile and CMakeLists.txt
- Add aarch64 support in hl.h, profile.c, hlmodule.h, module.c
Copy link
Member

@tobil4sk tobil4sk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also this place in CI that should be updated for arm64 support:

if [[ ${{ matrix.architecture }} != arm64 ]]; then

Also wonder if jit_common.h and jit_shared.c make more sense to be named the same thing?

bmdhacks and others added 2 commits February 27, 2026 18:53
- Exception type filtering: OTrap now looks ahead at catch handler
  opcodes to set tcheck for typed exception catches, matching x86
- hl_jit_free: properly clean up all allocator state and support
  can_reset for hot reload, fixing memory leaks
- OAssert: use correct LDR+BLR+B+literal pool pattern instead of
  broken literal+BL sequence that was never patched
- OSwitch: replace O(n) linear CMP/B.EQ scan with O(1) branch table
  using ADR+ADD+BR
- Size encoding: large-offset paths in op_get_mem/op_set_mem now
  correctly handle 1-byte and 2-byte access sizes

Inspired by review of HaxeFoundation#857.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…hared

- Remove --export-dynamic from Makefile LFLAGS (was accidentally
  reintroduced during merge; removed upstream in fec624c)
- Restore BOM and no-trailing-newline in hl.vcxproj.filters for
  Visual Studio compatibility
- Rename jit_shared.c to jit_common.c to match jit_common.h

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Simn
Copy link
Member

Simn commented Feb 28, 2026

Since call stacks were mentioned and we're currently investigating a platform-specific HL problem related to that, could you try running https://github.com/HaxeFoundation/hxcoro/blob/master/callstack-tests/build-hl.hxml and let me know how that goes?

@bmdhacks
Copy link
Author

Since call stacks were mentioned and we're currently investigating a platform-specific HL problem related to that, could you try running https://github.com/HaxeFoundation/hxcoro/blob/master/callstack-tests/build-hl.hxml and let me know how that goes?

$ hl callstack-tests/bin/test.hl
PASS asyncscope
PASS awaitcontinuation
PASS awaittask
PASS cancellation
PASS catchrethrow
PASS directthrow
PASS foobarbaz
PASS implicitlazy
PASS lazytask
PASS nestedplainthrow
PASS scopetask
PASS siblingcancellation
PASS supervisortask
PASS timeout
PASS toprecursion

Results: 15 passed, 0 failed

@Simn
Copy link
Member

Simn commented Feb 28, 2026

Nice! That means #892 really is a problem with the x86 jit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants