cpu: lower signed condition codes, Jcc, CMOVcc, SETcc, NEG and CWD #799
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/805"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by agilesh08 on 2026-11-23T06:14:06Z.
Change
Extends
tools/ffx_version_query.pyinteger lowering to support:l,ge,le,g)s,ns)o,no)CMOVcc(cmovl,cmovge,cmovle,cmovg,cmovs,cmovns,cmovo,cmovnoin 32-bit and 64-bit),SETcc(setl,setge,setle,setg,sets,setns,seto,setno), andJcc(jl,jge,jle,jg,js,jns,jo,jno)negin 32-bit and 64-bit forms) with accurate CF, OF, SF, ZF flag trackingcwd, preserving upper bits 16..63 of RDX)The lowering tracks the sign flag
SFacross arithmetic (ADD,ADC,SUB,SBB,INC,DEC,AND,OR,XOR), comparisons (CMP,TEST), shifts (SHL,SHR,SAR), and negation (NEG). Signed conditions are gated on non-x87 contexts (x87_depth is None) to preserve x87 instruction rejection semantics.Adds a source-built MASM differential fixture (
tests/cpu/signed_conds.asm,tests/cpu/signed_conds.def,tests/cpu/signed_conds.py) registered ascpu_aot_signed_condsinCMakeLists.txt, classified intools/form_coverage.py, and documented indocs/experiments.md.Verification
Commit under test:
d463b9fpython -B -c "import sys; sys.path.insert(0, 'tools'); sys.path.insert(0, 'tests/cpu'); import signed_conds; signed_conds.check_negative_controls()"signed_conds negative controls PASSED!(verifies unconditional memory reads and UD2 rejections)python -B -c "import sys; sys.path.insert(0, 'tools'); sys.path.insert(0, 'tests/cpu'); import x87_compare; x87_compare.check_rejections()"rejected 19 sequences outside the profile: fucomi and inc eax, then jp; ... fucomi then js; fucomi then jl; fucomi then cmovs; ... check_rejections PASSED!tests/script_state_check.py(Ran 15 tests: OK)tests/resource_root_check.py(Ran 4 tests: OK)tests/bcpack_check.py(Ran 9 tests: OK)tests/bcpack_symbols_check.py(Ran 10 tests: OK)tests/bc7_blocks_check.py(Ran 10 tests: OK)tests/bc7_tiles_check.py(Ran 6 tests: OK)tests/form_coverage_check.py(form coverage checks passed)tests/resource_ranges_check.py(Ran 20 tests: OK)tests/awc_metadata_check.py(Ran 13 tests: OK)tests/sgd5_effects_check.py(Ran 3 tests: OK)tests/dxcontainer_part_offsets_check.py(Ran 7 tests: OK)tests/layout_chunks_check.py(layout chunk summary ok)tests/dependency_paths_check.py(dependency paths ok)tests/intake/paths_check.py(paths ok)tests/shader_probe_check.py(controls ok)tests/shader_census_check.py(Ran 7 tests: OK)tests/dxil_retarget_check.py(pure-python dxil_retarget controls: ok)tests/rdna2_tools_check.py(Ran 64 tests: OK)tests/pso_readiness_check.py(PSO census, evidence states, and native hash control passed)tests/xmem_attribute_scan_check.py(decoding: 13 cases passed)tests/docs_links_check.py(Checked 13 Markdown files and 154 links: OK)tests/bidi_controls_check.py(Checked 654 tracked source, script and build/CI files: no bidirectional controls)tests/hardware_reports_check.py(Ran 11 tests: OK)git -c core.whitespace=cr-at-eol diff --check upstream/main: clean exit 0Evidence and follow-up
The fixture
tests/cpu/signed_conds.asmis 100% source-built and synthetic, containing no game dumps or copyrighted materials. It defines 35 exported functions exercising signed conditions, flag extraction, zero-extensions on 32-bit destinations, and upper register bit preservation.This change was AI-assisted.
Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T06:39:01Z.
The signed predicates expose a stale SF in mixed blocks. The new
signlocal is updated by the basic arithmetic, CMP and TEST paths, but supportedXADDstill updates ZF/CF/OF only. For example, a source-builtXADDwith a negative result followed bySETSshould return 1 even if prior SF was clear. Please preserve SF for all supported producers that the new consumers can observe, or reject paths where its current value cannot be established. A native/AOT mixed-producer control (XADD→ signed or sign test, with the prior SF chosen to differ) would catch this. Also check that the new 32/64-bit CMOV guard preserves any existing accepted CMOV forms.Imported from R0Y00/Xbox2Windows. Originally posted by MatyEjsr on 2026-11-23T06:41:18Z.
Verdict: Request changes (static/ISA and Python review of head
d463b9faf72cb316d4e405b39e68f1d8406cf0b2, compared againstmainab5d3a5).Verification
Environment: Windows 11 x64, Python 3.12.10. Zero-GPU static/ISA and Python review (native MSVC DLL build/execution was not run locally; Windows
devandrelease/O2CI jobs on this head both passed).Checks on
d463b9f:python -B tests/docs_links_check.py(13 files, 154 links) andpython -B tests/bidi_controls_check.py(654 files): both passed.git merge-tree --write-tree main d463b9f: clean againstab5d3a5(exit 0).tools/ffx_version_query.py.What looks solid:
L/GE/LE/G/S/NS/O/NO) acrossJcc,CMOVcc, andSETccmatch x86-64 semantics (sign != overflow,zero || (sign != overflow), etc.).NEG(carry = a != 0,overflow = a == (1 << sign_shift),zero,sign, withLOCKalready rejected globally at line 523) andCWD(sign-extendingAXintoDXwhile preserving bits 16–63 ofRDX) are accurate.CMP,TEST,ADD/ADC/SUB/SBB/INC/DEC/AND/OR/XOR,SAHF, and non-zero immediateSHL/SHR/SARall updatesignproperly.Issue to address
Existing
SF-defining instructions intools/ffx_version_query.pyleavesignstale:Now that
lower()trackssignand lowers signedJcc/CMOVcc/SETccin the shared lowering, every instruction inlower()that architecturally definesSFmust updatesign— otherwise a signed branch/move/set following one of these instructions reads a stalesignfrom an earlier operation:XADDandCMPXCHG(tools/ffx_version_query.py:900–921):XADDsetsSFfrom the sumv(((v >> (8 * size - 1)) & 1) != 0), matchingADD.CMPXCHGsetsSFfrom the comparison differencestatic_cast<width>(acc - d)(((diff >> (8 * size - 1)) & 1) != 0), matchingCMP.SHLDandSHRD(tools/ffx_version_query.py:799–814):if (c != 0u), both setSFfrom the resultv(((v >> (bits - 1)) & 1) != 0), matchingSHL/SHR/SAR(and leavesignunchanged whenc == 0).ANDN,BLSI,BLSMSK,BLSR,BZHI(tools/ffx_version_query.py:722–745,819–822):SFas the MSB of the destination resultv(((v >> (bits - 1)) & 1) != 0).POPCNTandPTEST(tools/ffx_version_query.py:758–760,1350–1354):SF(sign = false;) alongsideOF = 0.PCMPESTRI/PCMPESTRM/PCMPISTRI/PCMPISTRM(tools/ffx_version_query.py:1367–1382):SF(indicating whether the first source operand contains a null/end-of-string element). Either populater.signinPcmpResult/pcmp_str()and assignsign = r.sign;, or document/guard if out of scope.(Also note cross-PR coordination with #807: if both land,
RDRAND/RDSEEDwill also needsign = false;.)Adding
signupdates for those producers (plus at least a targeted regression case for e.g.XADD/CMPXCHG/SHLD/ANDN/POPCNTfollowed bysets/jlafter a prior negative result) will keepSFconsistent across the shared lowering.AI-assisted review (static code/ISA inspection and local Python checks executed locally).
Imported from R0Y00/Xbox2Windows. Originally posted by agilesh08 on 2026-11-23T07:15:30Z.
Updated head to \
1901dd2\ with all reviewer feedback addressed:(v >> (8 * size - 1)) & 1) != 0.(diff >> (8 * size - 1)) & 1) != 0..sign = len1 < limit\ in \PcmpResult\ / \pcmp_str\ and assign \sign = r.sign;.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T08:11:32Z.
I pushed
5a8333dto check CPUID before the native BMI1, BMI2 and POPCNT cases. The Release run passed 14,217 native/AOT cases, including the new flag-producer cases. With the capability probe forced to report all three features missing, the fixture ran 14,072 baseline cases, avoided the optional calls and returned 77. Awaiting CI for the updated commit.