cpu: ScalarLifter in cpu_sse_aot.py omits NEG flag producers and crashes on SETcc/CMOVcc GPR instructions #737

Closed
opened 2026-11-23 00:26:08 +00:00 by Ammmae0x · 1 comment
Ammmae0x commented 2026-11-23 00:26:08 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-23T00:26:08Z.


Commit or build

fd2486f (upstream/main)

Reproduction

Run with the repo Python environment (iced-x86 and pefile) against a temporary copy of the source-built fixture out/build/dev/cpu_reloc_original.dll:

out\pe-env\Scripts\python.exe -B -c '
import sys; sys.path.insert(0, "tools")
import cpu_sse_aot, pefile
from iced_x86 import Code, Encoder, Instruction, Register

def asm(insns, base):
    e = Encoder(64); out = bytearray()
    for i in insns: e.encode(i, base + len(out)); out.extend(e.take_buffer())
    return bytes(out)

with pefile.PE("out/build/dev/cpu_reloc_original.dll", fast_load=True) as pe:
    for label, insns in [
        ("NEG+JE", [
            Instruction.create_reg(Code.NEG_RM32, Register.ECX),
            Instruction.create_branch(Code.JE_REL8_64, 0x1010),
            Instruction.create_reg_i32(Code.MOV_R32_IMM32, Register.EAX, 1),
            Instruction.create(Code.RETNQ),
            Instruction.create_reg_i32(Code.MOV_R32_IMM32, Register.EAX, 2),
            Instruction.create(Code.RETNQ),
        ]),
        ("CMP+SETE", [
            Instruction.create_reg_reg(Code.CMP_RM32_R32, Register.ECX, Register.EDX),
            Instruction.create_reg(Code.SETE_RM8, Register.AL),
            Instruction.create(Code.RETNQ),
        ]),
        ("CMP+CMOVE", [
            Instruction.create_reg_reg(Code.CMP_RM32_R32, Register.ECX, Register.EDX),
            Instruction.create_reg_reg(Code.CMOVE_R32_RM32, Register.EAX, Register.ECX),
            Instruction.create(Code.RETNQ),
        ]),
    ]:
        pe.set_bytes_at_rva(0x1006, asm(insns, 0x1006))
        try:
            cpu_sse_aot.translate_pe(pe, ["call_mix=q:qq"])
        except Exception as exc:
            print(label, type(exc).__name__, exc)
'

Expected behavior

  1. ScalarLifter / condition() in tools/cpu_sse_aot.py should support NEG as a flag producer (M.NEG is already in FLAG_PRODUCERS and Lifter.condition() in tools/cpu_switch_aot.py:195, 931-956), lowering neg ecx; je ... cleanly instead of raising ValueError.
  2. When ScalarLifter.statement() (tools/cpu_sse_aot.py:119-120) delegates non-scalar GPR instructions to super().statement(...), cpu_sse_aot.lift() / ScalarLifter should either track the flag producer for SETcc/CMOVcc (setting sets_flags when the consumer is SETcc/CMOVcc and passing producer to super().statement(ins, sets_flags, producer)) or reject SETcc/CMOVcc with an explicit ValueError, rather than crashing with an unhandled AttributeError.

Acceptance criteria:

  • Update tools/cpu_sse_aot.py:115-123, 229-233, and 258 so M.NEG is accepted as an integer flag producer and SETcc/CMOVcc either resolve their preceding flag producer cleanly or fail with a clear ValueError.
  • Add NEG + Jcc, CMP + SETcc, and CMP + CMOVcc coverage in tests/cpu/scalar_float_check.py.

Observed behavior

In tools/cpu_sse_aot.py:

  • condition() (tools/cpu_sse_aot.py:231) restricts integer flag producers to (*ALU, M.CMP, M.TEST, M.INC, M.DEC), omitting M.NEG.
  • ScalarLifter.statement() (tools/cpu_sse_aot.py:119-120) calls super().statement(ins, next_ins is not None and next_ins.flow_control == FlowControl.CONDITIONAL_BRANCH) without passing producer, and lift() (tools/cpu_sse_aot.py:258) does not resolve flag producers for SETcc/CMOVcc instructions. Inside Lifter.lower() (tools/cpu_switch_aot.py:965-975), SETcc/CMOVcc accesses producer.op0_kind on None.

Running the reproduction prints:

NEG+JE ValueError unsupported flag producer at RVA 0x1006
CMP+SETE AttributeError 'NoneType' object has no attribute 'op0_kind'
CMP+CMOVE AttributeError 'NoneType' object has no attribute 'op0_kind'

Environment

Windows 10 Pro 24H2 (build 26100.7623), Python 3.12.8 (out\pe-env\Scripts\python.exe).

Checklist

  • I reproduced this on a source-built input.
  • I did not include game files, dumps, distribution links or credentials.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6549772419 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/743). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-23T00:26:08Z. --- ### Commit or build `fd2486f` (`upstream/main`) ### Reproduction Run with the repo Python environment (`iced-x86` and `pefile`) against a temporary copy of the source-built fixture `out/build/dev/cpu_reloc_original.dll`: ```powershell out\pe-env\Scripts\python.exe -B -c ' import sys; sys.path.insert(0, "tools") import cpu_sse_aot, pefile from iced_x86 import Code, Encoder, Instruction, Register def asm(insns, base): e = Encoder(64); out = bytearray() for i in insns: e.encode(i, base + len(out)); out.extend(e.take_buffer()) return bytes(out) with pefile.PE("out/build/dev/cpu_reloc_original.dll", fast_load=True) as pe: for label, insns in [ ("NEG+JE", [ Instruction.create_reg(Code.NEG_RM32, Register.ECX), Instruction.create_branch(Code.JE_REL8_64, 0x1010), Instruction.create_reg_i32(Code.MOV_R32_IMM32, Register.EAX, 1), Instruction.create(Code.RETNQ), Instruction.create_reg_i32(Code.MOV_R32_IMM32, Register.EAX, 2), Instruction.create(Code.RETNQ), ]), ("CMP+SETE", [ Instruction.create_reg_reg(Code.CMP_RM32_R32, Register.ECX, Register.EDX), Instruction.create_reg(Code.SETE_RM8, Register.AL), Instruction.create(Code.RETNQ), ]), ("CMP+CMOVE", [ Instruction.create_reg_reg(Code.CMP_RM32_R32, Register.ECX, Register.EDX), Instruction.create_reg_reg(Code.CMOVE_R32_RM32, Register.EAX, Register.ECX), Instruction.create(Code.RETNQ), ]), ]: pe.set_bytes_at_rva(0x1006, asm(insns, 0x1006)) try: cpu_sse_aot.translate_pe(pe, ["call_mix=q:qq"]) except Exception as exc: print(label, type(exc).__name__, exc) ' ``` ### Expected behavior 1. `ScalarLifter` / `condition()` in `tools/cpu_sse_aot.py` should support `NEG` as a flag producer (`M.NEG` is already in `FLAG_PRODUCERS` and `Lifter.condition()` in `tools/cpu_switch_aot.py:195, 931-956`), lowering `neg ecx; je ...` cleanly instead of raising `ValueError`. 2. When `ScalarLifter.statement()` (`tools/cpu_sse_aot.py:119-120`) delegates non-scalar GPR instructions to `super().statement(...)`, `cpu_sse_aot.lift()` / `ScalarLifter` should either track the flag producer for `SETcc`/`CMOVcc` (setting `sets_flags` when the consumer is `SETcc`/`CMOVcc` and passing `producer` to `super().statement(ins, sets_flags, producer)`) or reject `SETcc`/`CMOVcc` with an explicit `ValueError`, rather than crashing with an unhandled `AttributeError`. **Acceptance criteria:** - Update `tools/cpu_sse_aot.py:115-123`, `229-233`, and `258` so `M.NEG` is accepted as an integer flag producer and `SETcc`/`CMOVcc` either resolve their preceding flag producer cleanly or fail with a clear `ValueError`. - Add `NEG` + `Jcc`, `CMP` + `SETcc`, and `CMP` + `CMOVcc` coverage in `tests/cpu/scalar_float_check.py`. ### Observed behavior In `tools/cpu_sse_aot.py`: - `condition()` (`tools/cpu_sse_aot.py:231`) restricts integer flag producers to `(*ALU, M.CMP, M.TEST, M.INC, M.DEC)`, omitting `M.NEG`. - `ScalarLifter.statement()` (`tools/cpu_sse_aot.py:119-120`) calls `super().statement(ins, next_ins is not None and next_ins.flow_control == FlowControl.CONDITIONAL_BRANCH)` without passing `producer`, and `lift()` (`tools/cpu_sse_aot.py:258`) does not resolve flag producers for `SETcc`/`CMOVcc` instructions. Inside `Lifter.lower()` (`tools/cpu_switch_aot.py:965-975`), `SETcc`/`CMOVcc` accesses `producer.op0_kind` on `None`. Running the reproduction prints: ```text NEG+JE ValueError unsupported flag producer at RVA 0x1006 CMP+SETE AttributeError 'NoneType' object has no attribute 'op0_kind' CMP+CMOVE AttributeError 'NoneType' object has no attribute 'op0_kind' ``` ### Environment Windows 10 Pro 24H2 (build 26100.7623), Python 3.12.8 (`out\pe-env\Scripts\python.exe`). ### Checklist - [x] I reproduced this on a source-built input. - [x] I did not include game files, dumps, distribution links or credentials. AI-assisted.
R0Y00 commented 2026-11-24 06:48:55 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T01:08:57Z.


Please reuse the verified #731 flag rules where the ScalarLifter supports the same operand. Unsupported producers or operands should give the normal lowering diagnostic. Add source-built SETcc and CMOVcc controls with both condition outcomes and verify 8-bit preservation and 32-bit zero-extension where applicable.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7088912885 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/743#issuecomment-7088912885). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T01:08:57Z. --- Please reuse the verified #731 flag rules where the ScalarLifter supports the same operand. Unsupported producers or operands should give the normal lowering diagnostic. Add source-built SETcc and CMOVcc controls with both condition outcomes and verify 8-bit preservation and 32-bit zero-extension where applicable.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows#737
No description provided.