fix: ARM64 JIT crashes, visual corruption, and 64-bit pointer safety (#1766)#1824
Merged
fix: ARM64 JIT crashes, visual corruption, and 64-bit pointer safety (#1766)#1824
Conversation
…1766) Fix 12 root-cause bugs in the ARM64 JIT compiler that caused crashes, visual corruption, and stalls across various Amiga configurations. Crashes & stalls: - Inter-block dont_care_flags: flush_flags() before dont_care_flags() to prevent stale NZCV on interpreter fallback path - FBcc branch target truncation: avoid set_const() for 64-bit host pointers on non-PC_P registers in FPU conditional branches - BSR.L/Bcc.L sign extension: cast comp_get_ilong() to (uae_s32) for 32-bit displacements in 32 branch handlers + generator - Bus error recovery: setjmp/longjmp in m68k_run_jit() with SIGBUS handler integration for JIT code accessing unmapped memory Visual corruption (A4000 AGA wallpaper): - ADDX_b/w MOVN_xi initialization: move register init outside the FLAG_Z guard since it serves dual purpose (Z-flag base AND byte-packing padding for ADCS carry chain) - ADDX/SUBX Z-flag semantics: implement M68K "only clears" behavior with proper sticky-Z via UBFX/CMP/SET_xxZflag/CSEL/AND 64-bit pointer safety: - arm_ADD_l/arm_ADD_l_ri: sign-extend 32-bit M68K displacements when destination is PC_P (the only 64-bit virtual register) - set_const: mask non-PC_P registers to 32 bits - All pc_p store/load paths use 64-bit operations - MOVE16: use ADD_xxx (64-bit) for natmem pointer arithmetic Memory subsystem: - natmem_reserved_size upgraded to size_t (was uae_u32, overflowed) - ARM64 gets 4GB natmem reservation - commit_natmem_gaps() fills unmapped regions with read-only pages Performance optimizations: - Two-pass liveflags: use successor block needed_flags for better flag elimination (+2.3% with R_REGSTRUCT range optimization) - R_REGSTRUCT range-based offset: regflags uses fast 1-instruction STR_wXi instead of 4-5 instruction LOAD_U64 path - ADDX/SUBX Z-flag skip: wrap Z handling in needed_flags check - Guard infrastructure fully removed (was diagnostic-only) - setjmp placed outside inner dispatch loop (~2% cost) Tested: Lightwave-NoRAM.uae (boots), Lightwave.uae (app stable), A4000.uae (clean AGA wallpaper), SysInfo.uae (~7391 MIPS).
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d0499f03b7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…rm zero-fill skip - sigsegv_handler.cpp: longjmp value 3 (address error) → 2 (bus error) for unmapped memory faults from unrecognized JIT instructions - amiberry_mem.cpp: remove #ifndef _WIN32 guard around zero-fill skip since Windows VirtualAlloc(MEM_COMMIT) also zero-fills pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes 12 root-cause bugs in the ARM64 JIT compiler that caused crashes, visual corruption, and stalls across various Amiga configurations. All fixes are root-cause — no guards or bandaids.
dont_care_flags()stale flag bug, FBcc 64-bit branch target truncation, BSR.L/Bcc.L sign extension for backward branches, bus error recovery viasetjmp/longjmpMOVN_xidual-purpose bug), ADDX/SUBX Z-flag M68K "only clears" semanticsarm_ADD_l/arm_ADD_l_risign extension,set_const32-bit masking, 64-bitpc_pstore/load paths, MOVE16 pointer arithmeticsize_tfor natmem sizes, 4GB ARM64 reservation,commit_natmem_gaps()read-only gap pagesTest Results
Files Changed (16 source + 3 skill docs)
JIT Core (6 files)
compemu_support_arm.cpp— Inter-block fix, two-pass liveflags, cleanupcodegen_arm64.cpp— R_REGSTRUCT range optimization, 64-bit pc_p pathscompemu_midfunc_arm64.cpp— Sign-extension fixes, set_const maskingcompemu_midfunc_arm64_2.cpp— ADDX/SUBX Z-flag + MOVN_xi fix, MOVE16compemu_fpp_arm.cpp— FBcc branch target truncation fixcompemu.h—jit_in_compiled_codeexternRuntime (4 files)
newcpu.cpp— setjmp/bus error recovery, dispatch loopsigsegv_handler.cpp— SIGBUS/longjmp handlerm68k.h— FLAGBIT_X=0, SET_XFLG/GET_XFLG bit 0Memory (6 files)
amiberry_mem.cpp—commit_natmem_gaps(), 4GB ARM64, size_tmemory.cpp/memory.h— Gap commit call, size_t declarationsvm.h/vm.cpp— size_t function signatures throughoutmain.cpp,ram.cpp,expansion.cpp— size_t, cleanupCloses #1766