Skip to content

Add little-endian PowerPC (ppc64le) support to VM JIT compiler#860

Open
runlevel5 wants to merge 2 commits intoioquake:mainfrom
runlevel5:ppc64le-jit-support
Open

Add little-endian PowerPC (ppc64le) support to VM JIT compiler#860
runlevel5 wants to merge 2 commits intoioquake:mainfrom
runlevel5:ppc64le-jit-support

Conversation

@runlevel5
Copy link
Copy Markdown

@runlevel5 runlevel5 commented Feb 9, 2026

Summary

The PowerPC JIT compiler (vm_powerpc.c) was written for big-endian ppc/ppc64 only. This patch adds support for little-endian ppc64le (ELFv2 ABI).

It would also address #300

Changes

Endianness fixes

  • Add SE/HI16/LO16/FPRHI/FPRLO macros for endian-independent access to union half-words and FPR double-word halves in memory
  • Replace big-endian byte-reversal trick for immediate decoding with portable shift-based approach (matching vm_x86.c)
  • Fix all union short[2] accesses and FPR store/load offsets for OP_CVIF and OP_CVFI

ELFv2 ABI support

  • Add ELFV1/ELFV2 detection macros using _CALL_ELF
  • Make OPD (Official Procedure Descriptor) conditional on ELFv1 only; ELFv2 uses direct code addresses for function pointers
  • Set r12 = target address before indirect calls (bctrl) as required by the ELFv2 global entry point convention
  • Fix entry point selection to use direct code address on ELFv2

Bug fixes (affect all PowerPC platforms)

  • Remove incorrect Z_Free of Hunk_Alloc'd instructionPointers, which caused Z_Free: freed a pointer without ZONEID crash
  • Add __builtin___clear_cache() before mprotect() to synchronize split D/I caches after writing generated code

Testing

Tested on ppc64le (Fedora 43, GCC 15.2.1) with full retail Quake III Arena assets:

Test Duration Bots Map Mode Result
JIT basic (vm_game 2) 60s 0 q3dm1 FFA Pass
JIT + 1 bot 30s 1 q3dm1 FFA Pass
JIT + 3 bots 30s 3 q3dm7 FFA Pass
Interpreter (vm_game 1) 30s 4 q3dm6 FFA Pass
FFA 8 bots 2 min 8 q3tourney6 FFA Pass
CTF 8 bots 2 min 8 q3ctf1 CTF Pass
Team Arena CTF 1 min 6 mpq3ctf1 CTF Pass
Stress test 5 min 8 q3dm17 FFA Pass
Stress test 5 min 6 q3dm17 FFA Pass

Full gameplay verified: rocket/railgun kills, flag captures/returns, Quad Damage, bot team coordination, voice commands, falling deaths, bot chat. All clean shutdowns, no crashes.

Notes

  • All changes are confined to code/qcommon/vm_powerpc.c
  • The endianness macros follow the existing SL()/SA() pattern in the file
  • The Z_Free bug and missing I-cache flush affect big-endian PowerPC too, though they may have been masked by specific allocator/cache behavior on those platforms

@runlevel5
Copy link
Copy Markdown
Author

@classilla @MPC7500 I would really appreciate if you could help review this PR for me. Great thanks in advance

The PowerPC JIT (vm_powerpc.c) was written for big-endian ppc/ppc64 only.
This adds support for little-endian ppc64le (ELFv2 ABI) with the following
changes:

Endianness fixes:
- Add SE/HI16/LO16/FPRHI/FPRLO macros for endian-independent access to
  union half-words and FPR double-word halves in memory
- Replace big-endian byte-reversal trick for immediate decoding with
  portable shift-based approach (matching vm_x86.c)
- Fix all union short[2] accesses and FPR store/load offsets for OP_CVIF
  and OP_CVFI

ELFv2 ABI support:
- Add ELFV1/ELFV2 detection macros using _CALL_ELF
- Make OPD (Official Procedure Descriptor) conditional on ELFv1 only;
  ELFv2 uses direct code addresses for function pointers
- Set r12 = target address before indirect calls (bctrl) as required by
  the ELFv2 global entry point convention
- Fix entry point selection to use direct code address on ELFv2

Bug fixes (affect all PowerPC platforms):
- Remove incorrect Z_Free of Hunk_Alloc'd instructionPointers, which
  caused 'Z_Free: freed a pointer without ZONEID' crash
- Add __builtin___clear_cache() before mprotect() to synchronize split
  D/I caches after writing generated code

Tested on ppc64le (Fedora 43, GCC 15.2.1) with full retail Quake III
Arena assets: FFA, CTF, and Team Arena modes with up to 8 bots across
multiple maps including 5-minute stress tests.
@runlevel5 runlevel5 force-pushed the ppc64le-jit-support branch from b8c22fe to 9278443 Compare March 31, 2026 10:01
- Add VSX VectorArrayNormalize
- Fix renderer
- Fix sound
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.

1 participant