Skip to content

jit: accept x86 R15 as a valid register mapping target - #104

Merged
GloriousTacoo merged 2 commits into
pound-emu:mainfrom
GabrielGonHo:register/fix-r15-valid-range
Oct 28, 2026
Merged

GloriousTacoo merged 2 commits into
pound-emu:mainfrom
GabrielGonHo:register/fix-r15-valid-range

Conversation

@GabrielGonHo

Copy link
Copy Markdown
Contributor

Description

�llocate_x86_register() cached a mapping to BAL_X86_R15 and then rejected it:

c if (BAL_UNLIKELY(cached_x86_register < 0 || cached_x86_register >= (int8_t)BAL_X86_R15))

BAL_X86_R15 is 15, and 15 is in SCRATCH_REGISTERS (the pool ends with BAL_X86_R15), so a cached mapping to r15 is legitimate. The >= turns it into "corrupted": �rm_to_x86 is reset, the entry returns BAL_X86_INVALID, and compiler->status becomes BAL_ERROR_REGISTER_ALLOCATOR_CORRUPTED, failing the whole block. The log message itself documents the intended range as "0-r15", contradicting the code.

The check now uses > so r15 is accepted. This only triggers when at least 9 ARM GPRs are simultaneously live (pool exhaustion backs one of them with r15), which is common in function prologues and STM/LDM-style sequences.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Testing

  • Compiled src/backend/x86/bal_x86_tier1_compiler.c with Clang (zig cc) on the Linux (x86_64-linux-gnu) and Windows (x86_64-windows-gnu) targets using the project's warning set: no warnings or errors.
  • The unit test suite can't be built on this machine (Linux toolchain not available). The fix is a single comparison operator; the existing "valid range is 0-r15" log message documents the intended bound.

GabrielGonHo and others added 2 commits October 25, 2026 16:54
allocate_x86_register() rejected a cached mapping to BAL_X86_R15 with cached_x86_register >= BAL_X86_R15. R15 is a valid scratch register (it is in SCRATCH_REGISTERS and the evict path documents [0, 15] as valid), so any ARM register backed by R15 tripped the corruption check and failed the whole block the next time that mapping was reused.

Signed-off-by: GabrielGonHo <195778548+GabrielGonHo@users.noreply.github.com>
@GloriousTacoo
GloriousTacoo merged commit a78e70d into pound-emu:main Oct 28, 2026
1 check passed
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.

2 participants