cpu: add dedicated cpu_adx_aot lifter for 32-bit and 64-bit ADCX and ADOX #2890
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2890
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2890"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Ammmae0x on GitHub · 2026-11-26 16:39 UTC · original
Ammmae0x:cpu/adx-aot→main· +1823 −0 · 6 files · 3 commits · merged 2026-11-28 11:47 UTCChange
Add a dedicated standalone AOT lifter (
tools/cpu_adx_aot.py), source-built MASM fixture (tests/cpu/adx_aot.asm,tests/cpu/adx_aot.def), differential/mutant/rejection check suite (tests/cpu/adx_aot_check.py), and CTest registration (tests/cmake/cpu_adx_aot.cmake) for 32-bit and 64-bitADCXandADOX(docs/coverage/x64_zen2.tsvgroupBMI/ADX).Why a separate lifter alongside
cpu_aot_adx(tools/ffx_version_query.py):cpu_aot_adxcovers the shared query translator's 5 register-only exports; this slice provides a standalone flat-memory bounded leaf lifter and test harness (matching sibling dedicated leaf lifterscpu_bmi1_aot,cpu_bmi2_bit_aot,cpu_aes_pclmul_aot) adding differential memory-sourceADCX/ADOXcoverage,ALTER_ADXbuild divergence controls, 14 oracle-quirk controls, and/O2discarded-read NULL fault verification.ADCX r32, r/m32,ADCX r64, r/m64,ADOX r32, r/m32, andADOX r64, r/m64with exact dual-carry flag isolation (ADCXreads/writes onlyCF;ADOXreads/writes onlyOF; other flags preserved), 32-bit zero-extension into bits[63:32](pinned directly inop_adcx32_c0,op_adox32_o0,op_adcx32_flags, andop_adox32_flagsviamov rax, rcx), and unconditionalload_always<>()flat[rcx|rdx|r8]memory reads so/O2preserves faulting discarded loads.CF/OF/flag reads,ADC/SBB/VEX/EVEX/XOP, nonvolatile and high-byte GPRs, writes to argument GPRs (rcx/rdx/r8), displaced/indexed/RIP-relative memory operands, stores outside[r8],lock/rep/repne/segment prefixes, branches/calls, and missing/trailingret.CPUID.07H.00H:EBX[19]) runs portable lifted,/O2,ALTER_ADX, mutant, and rejection checks unconditionally before skipping native differential with exit77on hosts without ADX.Verification
Commit:
362cede4(merged withupstream/main7e5c378d, Windows x64, MSVC 14.50):cmake --build --preset dev --target cpu_adx_aot_original cpu_adx_aot_original_lifted cpu_adx_aot_altered cpu_adx_aot_altered_lifted cpu_adx cpu_adx_lifted-> exit 0.ctest --preset dev --no-tests=error --output-on-failure -R '^cpu_aot_adx(_dedicated)?$' -V-> 2/2 Passed (cpu_aot_adx: 1144 cases;cpu_aot_adx_dedicated:rejections passed: 3 alt + 35 IR + 4 raw + 12 PE-patched + CLI;1497 native + 1497 lifted + 1497 /O2 cases across 22 exports; ALTER_ADX checked on 12 exports + 14 mutants caught).cmake --build --preset release --target cpu_adx_aot_original cpu_adx_aot_original_lifted cpu_adx_aot_altered cpu_adx_aot_altered_lifted cpu_adx cpu_adx_lifted-> exit 0.ctest --preset release --no-tests=error --output-on-failure -R '^cpu_aot_adx(_dedicated)?$' -V-> 2/2 Passed (0 skips).out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py,tests\docs_links_check.py(154 md / 677 links),tests\bidi_controls_check.py(2542 files) -> all exit 0.Evidence and follow-up
All fixtures are original source-built MASM leaf functions (
tests/cpu/adx_aot.asm, MIT-licensed) with deterministic synthetic inputs,ALTER_ADXbuild divergence controls, 14 oracle-quirk controls, and/O2discarded-read NULL fault verification; zero external or game files are used.Checklist
AI-assisted.
@pigalot on GitHub · 2026-11-27 19:58 UTC · original · reviewed
I reviewed
4f7b8544merged intomain454fc0ed(tree93c1b101, clean merge).What I ran. I built the four
cpu_adx_aot_*targets indev, then ran:ctest --test-dir out/build/dev --no-tests=error -j 1 -V -R '^cpu_aot_adx(_dedicated)?$'cpu_aot_adx_dedicatedreports1497 native + 1497 lifted + 1497 /O2 cases across 22 exports; ALTER_ADX checked on 12 exports + 14 mutants caught.git diff --checkis clean.The host has ADX (RTX 5090 machine, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10), so neither test skipped.
mainalready lowers these four forms.tools/ffx_version_query.pylowersADCX/ADOXr32 and r64, including memory sources throughoperand(1). That arrived in #335 (2620000f).tests/cpu/adx.asmis the fixture for it. Its header is; coverage: source cpu_aot_adx, soform_coveragealready countsadcxandadoxas covered. This PR adds no new forms tox64_zen2.tsv'sBMI/ADXgroup.I ran
main'sffx_version_query.loweron this PR's builtcpu_adx_aot_original.dll. It lowers all of the following without refusal:op_adcx32_mem,op_adcx64_mem,op_adox32_mem,op_adox64_mem;op_adcx64_mem_flags,op_adox64_mem_flags;op_adx_dst_alias,op_adx_discarded_read,op_adx_dual64_adcx.That shows translation only. I didn't run those lowered bodies differentially.
So the body doesn't say what this lifter adds over
cpu_aot_adx. It also covers less: flat[rcx|rdx|r8]addressing only.What this PR does have that
mainlacks. Differential cases for memory-source ADX,/O2builds, and theALTER_ADXmutants. Those look worth keeping. A smaller change could add them totests/cpu/adx.asmandtests/cpu/adx.py, so they test the lifter the runtime uses, without adding 693 lines of a second ADX lowering that will need to be kept in step with the first.Verdict: comment on
4f7b8544. The code works as described. Whether a second, dedicated ADX lifter is wanted is the maintainer's call. If it is, please add a line to the body saying whycpu_aot_adxisn't enough.CI: all required checks pass on
4f7b8544. There are no reviews or threads.This reply was AI-assisted.
@JohnConnorNPC on GitHub · 2026-11-28 08:17 UTC · original
I reviewed
4f7b8544without building it. The lowering looks correct to me, and nothing here should block a merge. If a dedicated ADX lifter is wanted, I'd merge it once the first item below is fixed.What I checked
main(1f07b2c1) is clean:git merge-tree --write-tree origin/main pr/2890→ rc=0. Thecpu_leaf_aot.pyhelpers this PR imports,bounded_codeandexport_rva, have the same AST on both bases.op_adcx64/op_adox64issum < dst || (cin != 0 && sum == dst), which is the formulamainalready uses (tools/ffx_version_query.py:{flag} = v < a || ({flag} && v == a)).ref_adxalso writes only CF foradcxand only OF foradox.ctest --preset pr(100% tests passed out of 40), andgrep -ci adxon that job log gives0. Socpu_aot_adx_dedicatedhas only been run locally so far.Suggestions
mov rax, -1and thenmov eax, ecxright before the ADX instruction (git show pr/2890:tests/cpu/adx_aot.asm | grep -c 'mov eax, ecx'→8). Thatmovalready clears bits [63:32]. So a lowering that kept the destination's upper half would still pass the native, lifted and/O2checks, andno_zext32would still be caught. Usingmov rax, rcxin at least one ADCX r32 and one ADOX r32 export would pin it: 48 of the 60 test pairs have a nonzero upper half ina, and the expected values don't change.cpu_aot_adxisn't enough. The body doesn't have it yet (grep -c -E 'cpu_aot_adx\b|ffx_version_query'→0).docs/.cpu_aot_adxhas a paragraph indocs/experiments.md, so a short one for this test would help. Also, the body says prefixes are rejected, but only lock, rep and segment prefixes are; a redundant66before ADCX is accepted. That's harmless, but the wording could be narrower.This comment was AI-assisted.
@Ammmae0x on GitHub · 2026-11-28 11:15 UTC · original
Addressed all items from pigalot and JohnConnorNPC in
362cede4(merged withupstream/main7e5c378d):tests/cpu/adx_aot.asm): replacedmov rax, -1; mov eax, ecxwithmov rax, rcxinop_adcx32_c0,op_adox32_o0,op_adcx32_flags, andop_adox32_flagsso nonzero upper bits inrcx[63:32]reachadcx eax, edx/adox eax, edxdirectly and only 32-bit zero-extension clears bits[63:32].docs/experiments.md): added thecpu_aot_adx_dedicatedparagraph alongsidecpu_aot_adxwith reproduction commands and measured counts.cpu_adx_aotleaf lifter alongsidecpu_aot_adx, narrowed the rejected-prefix wording tolock/rep/repne/segment prefixes, and updated the verification receipt.Verified in both
devandrelease(/O2):cpu_aot_adxandcpu_aot_adx_dedicatedboth pass (1497native/lifted//O2cases across 22 exports, 14 mutants, 54+ rejections), andform_coverage_check.py/docs_links_check.py/bidi_controls_check.pyexit 0.AI-assisted.
@pigalot on GitHub · 2026-11-28 11:47 UTC · original · approved these changes
Retested
362cede4integrated overmain24fcd0b5(treef32478ac, clean merge). This follows my comment review on4f7b8544.Earlier points
cpu_aot_adxcovers the shared translator's five register-only exports, and this one is a bounded leaf lifter in the same style ascpu_bmi1_aot,cpu_bmi2_bit_aotandcpu_aes_pclmul_aot, whichmainalready carries. That answers my question, so I'm dropping it.op_adcx32_c0,op_adox32_o0,op_adcx32_flagsandop_adox32_flagsnow usemov rax, rcx, so the upper half reaches the instruction. I checked it with a lifter mutant that keeps the destination's bits [63:32] for the 32-bit forms:lifted op_adcx32_c0(0xffffffffffffffff, 0x0): got 0xffffffffffffffff != exp 0xffffffff;tests/cpu/adx_aot.asmput back to its4f7b8544version, the same mutant passes all 1497 + 1497 + 1497 cases. So the old fixture could not see it and the new one does.docs/experiments.mdhas thecpu_aot_adx_dedicatedparagraph, and the body now nameslock/rep/repne/segment prefixes only.What I ran
Built
cpu_adx_aot_original,cpu_adx_aot_original_lifted,cpu_adx_aot_altered,cpu_adx_aot_altered_lifted,cpu_adxandcpu_adx_liftedindevandrelease, thenctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^cpu_aot_adx(_dedicated)?$':/O2, no skips (the host has ADX).cpu_aot_adx_dedicated:rejections passed: 3 alt + 35 IR + 4 raw + 12 PE-patched + CLIand1497 native + 1497 lifted + 1497 /O2 cases across 22 exports; ALTER_ADX checked on 12 exports + 14 mutants caught.cpu_aot_adx: 1144 cases, unchanged.main24fcd0b5the test is not registered (the PR only adds files, plus two lines indocs/experiments.md).After a full
devbuild, the^cpu_family plusform_coverage,coverage_svgand the coverage CLI checks: 320 non-hardware tests passed and 1 skipped (cpu_aot_sysdesc, a capability skip that this PR does not touch).tests/form_coverage_check.py,tests/docs_links_check.py(155 files, 677 links) andtests/bidi_controls_check.pyexit 0.git diff --cached --check origin/mainis clean.Lifter mutants (each applied to
tools/cpu_adx_aot.py, lifted DLLs rebuilt,cpu_aot_adx_dedicatedrerun indev)Killed, 14:
sum == dstcarry term inop_adcx64, and the same inop_adox64(op_adcx64_flags/op_adox64_flagsat(0xffffffffffffffff, 0xffffffffffffffff));op_adcx32(op_adcx32_c1(0x0, 0x0): got 0x0 != exp 0x1);op_adox32writes CF instead of OF;ADOX r32to theadcxhelper;seto;volatilefromload_always(lifted_o2 op_adx_discarded_read(NULL) dropped faulting m64 read, so the/O2control is real);r8, displaced operands, segment prefixes, writes to argument registers, an undefined flag read by ADX, and OF as defined aftershlby more than 1.Equivalent, 1: removing the memory-size check in
flat_address. The decoder fixes the operand size from the instruction code for every form the lifter accepts, so that branch cannot fire. Fine as a guard.Survived: none.
Notes, none blocking
cpu_aot_adx_dedicatedis not in theprpreset, so CI on this head has not run it; the results above are local.mainalready uses for these forms intools/ffx_version_query.py: the destination and the one carry flag are written, the other flags are left alone, and 32-bit destinations are zero-extended.Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; ADX-capable host. No GPU tests are part of this result.
CI:
Build and test on Windowspasses on362cede4.Approving
362cede4.This reply was AI-assisted.