Broader CPU/OS Portability, Acceleration Tiers & Release CI Plan
Status: Future / Proposed Design Plan (Tier 3) — Not yet implemented. Builds on the completed 3-tier Zen 4 AVX-512 & portable engine (
docs/cpu-acceleration-plan.md,docs/emulator/core-and-acceleration.md). Seedocs/ROADMAP.mdfor overall sequencing.
Target Emulator: C11 XL1200 Emulator (emu/)
Priority Ordering Inside This Plan:
- Primary (Phase 1): Generic x86-64 fast assembly tier (for non-AVX-512 Intel/AMD CPUs) + automated Linux & Windows Release CI.
- Second Tier (Phase 2): ARM64 (
aarch64Linux) native builds, CI, and optional NEON/ARM64 assembly fast loop. - Lowest Priority (Phase 3): macOS portability ideas & requirements (documented for future reference; Intel
x86_64-darwin/ 2019 MBP and Apple Silicon).
1. Executive Summary & Motivation
Currently, ISA_MODE=runtime selects between:
- Tier 0 (
portable): Pure C11/GNU C computed-goto engine (~65–73 MIPS on Zen 4; runs on every 64-bit little-endian CPU). - Tier 1 / Tier 2 (
avx512_c/avx512): Zen 4 AVX-512 page decoder/PHT + OS-independent SysV/Win64 hot assembly loop (emu/src/cpu_zen4_loop.S, ~150 MIPS on AMD Zen 4).
However, most beta testers on Intel 12th–14th Gen (Alder/Raptor/Arrow Lake), AMD Zen 1–3, or laptops without AVX-512 fall straight back to Tier 0 (~65 MIPS) even though cpu_zen4_loop.S itself uses zero ZMM registers inside its hot threaded loop (only baseline x86-64 GPRs + BMI1/2 rorx/bzhi)!
This plan unlocks fast execution for the vast majority of desktop CPUs, automates Linux & Windows release bundles, charts a second-tier aarch64 path, and records concrete macOS requirements without over-investing prematurely.
flowchart LR
CPUID["Stateless Runtime Dispatch<br/>ivory_host_select_tier()"]
T0["Tier 0: portable64<br/>Pure C11/GNU C threaded<br/>(All 64-bit LE arches)"]
TX["Tier 1B (NEW): x64_asm<br/>Baseline x86-64 / BMI2 ASM<br/>(Intel 12th-14th, Zen 1-3, MBP)"]
TZ["Tier 2: avx512 (Existing)<br/>Zen 4 ASM + AVX-512 VBMI/PHT"]
TA["Tier 2A (Second Tier): arm64_asm<br/>ARM64 31-GPR Loop + NEON Decode"]
CPUID --> T0
CPUID -->|"x86_64 (no AVX-512)"| TX
CPUID -->|"x86_64 + AVX-512 VBMI"| TZ
CPUID -->|"aarch64"| TA2. Phase 1 (Primary): Generic x86-64 Fast Assembly Tier & Linux/Windows Release CI
2.1 Generic x86-64 Threaded Assembly Tier (TIER_X64_ASM)
- Key Insight:
emu/src/cpu_zen4_loop.Salready pins all hot Ivory CPU state in universal SysV + Win64 callee-saved GPRs (%rbx,%rbp,%r12..%r15) and uses zeroXMM/ZMMregisters! The only AVX-512/Zen-4-specific dependency is:BMI2instructions (rorx,bzhi,shrx) — easily gated or replaced with standardshr/andshifts in a baselinex86-64-v2/x86-64build variant (or shared.Smacro#ifdef IVORY_ASM_BMI2), and- Calling the scalar
ivory_decode_page_scalar()/ 15-opivory_pht_hash()instead ofcpu_zen4_avx512.cwhenAVX512_VBMIis absent.
- Expected Result: ~120–140+ MIPS (~2× speedup over Tier 0) on Intel Core 12th–14th gen, AMD Zen 1–3, and Intel macOS machines with ~30 lines of macro gating in
cpu_zen4_loop.S(renamed/aliased cleanly or compiled twice with-DIVORY_ASM_GENERIC_X64intocpu_x64_loop.o), zero ABI changes, and zero new.data/.bss. - Runtime Override: Extend
IVORY_ACCEL=auto|portable|x64_asm|avx512_c|avx512for deterministic lockstep A/B testing on any x86-64 host.
2.2 Automated Linux & Windows Release CI
Build a reproducible CI pipeline (GitHub Actions / Nix flakes) running on every PR and tagged release:
| Job | Runner / Environment | Steps & Artifacts |
|---|---|---|
linux-x86_64 | Nix (nix develop / nix build .#default) | make -C emu clean all test (15/15 suites, ROM-optional exit 77 = SKIP); ELF hygiene (readelf -WS 0 .data/.bss, nm -D sole export ivory_core_get_api, GNU_STACK RW, SDL_DECOUPLED=OK); package ivory-xl1200-linux-x86_64.tar.gz (+ optional AppImage). |
windows-x86_64 | Nix .#mingw (nix build .#windows) | make -C emu TARGET_OS=windows -j all dist-win test-win under Wine 11 (15/15 .exe suites); verify PE exports (objdump -p libivory_core.dll) and zero stray DLL dependencies; package ivory-xl1200-windows-x86_64.zip from build-win/dist/. |
portable-c11 | Nix (ISA_MODE=portable) | make -C emu clean all test ISA_MODE=portable confirming pure C11 baseline builds with zero x86 intrinsics/assembly. |
| Lockstep Gate | test_cpu_core + test_snapshot_reload | Verify bit-exact parity across IVORY_ACCEL=portable, x64_asm, avx512_c, and avx512 (when host supports AVX-512). |
3. Phase 2 (Second Tier): ARM64 (aarch64) Linux Support & Acceleration
ARM64 (aarch64) is an important second-tier target (ARM64 Linux servers, SBCs, and ARM64 laptops/VMs):
- Stage 2a — Native
aarch64-linuxBuild & CI (ISA_MODE=portable/runtime):- Audit
emu/Makefilesouname -m=aarch64/arm64cleanly skips x86-64 ASM/AVX-512 objects underISA_MODE=runtimeand compiles Tier 0 (portable64) with-std=c11 -Wall -Wextra -Werror. - Verify
emu/include/ivory_hw.h(_Static_assertlittle-endian bitfields,sizeof(IvoryCpu) == 4096U,sizeof(IvoryMem) == 32768U,sizeof(MerlinBoard) == 278528U) andemu/include/emu_os.hatomics (__atomic_*acquire/release — critical on weakly ordered ARM64 memory models forvram_dirty,Xl1200SerialRing, andEmuRuntime.ctl_waiters!). - Add
aarch64-linuxcross-compile / QEMU-user or native ARM64 CI build check.
- Audit
- Stage 2b — Optional ARM64 Threaded Assembly & NEON Decoder (
cpu_arm64_loop.S,cpu_arm64_neon.c):- ARM64 has 31 general-purpose 64-bit registers (
x19..x28callee-saved = 10 pinned registers!), allowingcpu,ip,tos,sp,fp,lp,disp_table,rem_budget,stack_cache, andl0_icacheto stay register-resident simultaneously without stack spills. ubfx/bfimap 1-to-1 to IvoryOP_LDB/OP_DPBand 40-bit tag/pointer extraction (ubfx x0, x12, #32, #6), and NEONvqtbl4q_u8accelerates 256-word page decoding cleanly.
- ARM64 has 31 general-purpose 64-bit registers (
4. Phase 3 (Lowest Priority): macOS Portability Ideas & Requirements
Documented for future reference (noting available test hardware is an Intel x86_64 2019 MacBook Pro; no Apple Silicon hardware is currently on hand):
- Shared-Library Hot Reload (
.dylib):- Update
emu/MakefileforDarwin: emitlibivory_core.dylib(-dynamiclib -install_name @rpath/libivory_core.dylib), use-Wl,-exported_symbol,_ivory_core_get_apifor strict symbol visibility, and verify withotool -L/nm -gUinstead ofldd/readelf. emu/src/core_loader.c: default library filenamelibivory_core.dylibon__APPLE__.
- Update
- Host Portability Audit:
emu_os.h/emu_io.h/emu_ipc.h:clock_gettime(CLOCK_MONOTONIC)and POSIXpread/pwrite/AF_UNIXwork natively on macOS>= 10.12; guard Linux-onlymadvise(MADV_DONTNEED)semantics (MADV_FREEvsmmapre-map) and ensureeth_tap_linux.ccompiles cleanly to stubs (already#ifdef __linux__).- x86-64 Mach-O Assembly: On Intel
x86_64-darwin, C symbols carry a leading underscore (_ivory_cpu_run_zen4_asm) and ELF.type/.size/.note.GNU-stackdirectives are unsupported — extendemu/src/asm_abi.hwith#ifdef __APPLE__symbol prefix and Mach-O section macros so Tier 1B (x64_asm) runs natively on Intel Macs!
- SDL3 & Packaging:
- SDL3 Cocoa backend (
SDL_ShowOpenFileDialog/SDL_ShowSaveFileDialogmap toNSOpenPanel/NSSavePanelnatively, strictly on the Main Thread — already satisfied byui_workbench.c!). - Keymap note: macOS Command (
⌘) / Option (⌥) ergonomics already have a dedicatedmac-ext([MAC]) profile inemu/src/keymap.c. - Packaging:
flake.nixDarwin target or Homebrew formula +.appbundle wrappingivory-xl1200+libivory_core.dylib+SDL3.framework.
- SDL3 Cocoa backend (
5. Verification & Acceptance Criteria
| Phase | Verification Gate |
|---|---|
| Phase 1: Generic x86-64 ASM + CI | IVORY_ACCEL=x64_asm passes 10M-step + 45M-step bit-exact lockstep vs portable on Linux & Wine; readelf -WS (0 .data/.bss) & GNU_STACK RW; GitHub Actions / Nix CI produces verified Linux .tar.gz and Windows .zip bundles cleanly. |
Phase 2: ARM64 (aarch64) | All 15 unit test suites pass on aarch64-linux (verifying acquire/release atomics on weak memory ordering); if Stage 2b lands, arm64_asm passes 10M-step lockstep vs portable. |
| Phase 3: macOS (Future) | make -C emu all test passes on x86_64-darwin with libivory_core.dylib hot-reload (test_snapshot_reload), SDL_VIDEODRIVER=dummy (test_ui_workbench), and zero libSDL3 linkage in otool -L build/libivory_core.dylib. |
6. File Impact Summary
| File | Action | Purpose |
|---|---|---|
emu/src/cpu_zen4_loop.S, emu/src/asm_abi.h, emu/src/cpu_zen4_avx512.c | Edit | Macro-gate BMI2 for generic x64_asm tier, extend IVORY_ACCEL runtime selection |
emu/Makefile, flake.nix | Edit | Build x64_asm object, aarch64 runtime detection, optional Darwin .dylib rules |
.github/workflows/ci.yml (or Nix CI script) | New | Automated Linux + Windows MinGW/Wine CI & release archive packaging |
emu/src/cpu_arm64_loop.S, emu/src/cpu_arm64_neon.c (Phase 2b) | New | Second-tier ARM64 threaded loop & NEON 256-word page decoder |