cpu: lower VEX AVX scalar FP, half-register moves, vinsertps/vextractps, and vcomis* #401

Merged
Vonsek merged 4 commits from upstream-pr/407 into main 2026-11-23 18:23:32 +00:00
Vonsek commented 2026-11-22 00:33:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-22T00:33:43Z.


Change

  • Lower 28 VEX AVX scalar floating-point, half-register move, vinsertps/vextractps, and scalar compare instructions in tools/ffx_version_query.py:
    • Scalar arithmetic, square root, min/max, and round: vaddss, vsubss, vmulss, vdivss, vsqrtss, vminss, vmaxss, vroundss, vaddsd, vsubsd, vmulsd, vdivsd, vsqrtsd, vminsd, vmaxsd, vroundsd
    • Scalar and half-register moves: vmovss, vmovhlps, vmovlhps, vmovlps, vmovhps, vmovlpd
    • Extract/insert and scalar compares (updating ZF and CF): vinsertps, vextractps, vcomiss, vucomiss, vcomisd, vucomisd
  • Restrict lowering to EncodingKind.VEX (rejecting EVEX encodings and MXCSR rounding mode) and zero upper YMM bytes for 128-bit XMM destinations.
  • Probe CPUID leaf 1 ECX bits 27 (OSXSAVE) and 28 (AVX) plus XCR0 XMM/YMM state before invoking the native fixture (exiting 77 with SKIP_RETURN_CODE 77 on hosts without AVX).
  • Add source-built MASM differential fixture tests/cpu/avx_scalar_fp.{asm,def,py}, CMake target cpu_avx_scalar_fp_lifted, CTest cpu_aot_avx_scalar_fp, coverage mapping in tools/form_coverage.py, and documentation in docs/experiments.md.

Verification

  • Confirmed pre-fix failure on cmake --build --preset dev --target cpu_avx_scalar_fp_lifted:
    ValueError: unsupported query operation at 0x1008: vaddss xmm0,xmm1,xmm2
  • Built and tested on Windows 11 x64 (VS 2022 Build Tools):
    • cmake --build --preset dev --target cpu_avx_scalar_fp_lifted succeeded with 0 warnings
    • ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_scalar_fp|cpu_aot_bmi1)$" -V: 2/2 passed (39 VEX AVX scalar FP/move/extract/insert/compare cases matched native and translated DLLs + EVEX vaddss rejection control)
    • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: form coverage checks passed

Evidence and follow-up

  • Covers 28 AVX-grouped mnemonics in docs/coverage/x64_zen2.tsv using source-built fixtures, gated by a runtime CPUID/XCR0 check.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6536375655 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/407). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-22T00:33:43Z. --- ## Change - Lower 28 VEX AVX scalar floating-point, half-register move, `vinsertps`/`vextractps`, and scalar compare instructions in `tools/ffx_version_query.py`: - Scalar arithmetic, square root, min/max, and round: `vaddss`, `vsubss`, `vmulss`, `vdivss`, `vsqrtss`, `vminss`, `vmaxss`, `vroundss`, `vaddsd`, `vsubsd`, `vmulsd`, `vdivsd`, `vsqrtsd`, `vminsd`, `vmaxsd`, `vroundsd` - Scalar and half-register moves: `vmovss`, `vmovhlps`, `vmovlhps`, `vmovlps`, `vmovhps`, `vmovlpd` - Extract/insert and scalar compares (updating ZF and CF): `vinsertps`, `vextractps`, `vcomiss`, `vucomiss`, `vcomisd`, `vucomisd` - Restrict lowering to `EncodingKind.VEX` (rejecting EVEX encodings and MXCSR rounding mode) and zero upper YMM bytes for 128-bit XMM destinations. - Probe CPUID leaf 1 ECX bits 27 (`OSXSAVE`) and 28 (`AVX`) plus XCR0 XMM/YMM state before invoking the native fixture (exiting 77 with `SKIP_RETURN_CODE 77` on hosts without AVX). - Add source-built MASM differential fixture `tests/cpu/avx_scalar_fp.{asm,def,py}`, CMake target `cpu_avx_scalar_fp_lifted`, CTest `cpu_aot_avx_scalar_fp`, coverage mapping in `tools/form_coverage.py`, and documentation in `docs/experiments.md`. ## Verification - Confirmed pre-fix failure on `cmake --build --preset dev --target cpu_avx_scalar_fp_lifted`: `ValueError: unsupported query operation at 0x1008: vaddss xmm0,xmm1,xmm2` - Built and tested on Windows 11 x64 (VS 2022 Build Tools): - `cmake --build --preset dev --target cpu_avx_scalar_fp_lifted` succeeded with 0 warnings - `ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_scalar_fp|cpu_aot_bmi1)$" -V`: 2/2 passed (`39 VEX AVX scalar FP/move/extract/insert/compare cases matched native and translated DLLs` + EVEX `vaddss` rejection control) - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`: `form coverage checks passed` ## Evidence and follow-up - Covers 28 `AVX`-grouped mnemonics in `docs/coverage/x64_zen2.tsv` using source-built fixtures, gated by a runtime CPUID/XCR0 check.
upstream-sync closed this pull request 2026-11-24 06:42:53 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:42:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-22T00:44:37Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f7932cb562

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6009222425 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/407#pullrequestreview-6009222425). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-22T00:44:37Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `f7932cb562` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
chatgpt-codex-connector[bot commented 2026-11-24 06:48:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-22T00:37:38Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T00:44:40.099498Z f7932cb Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7071675019 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/407#issuecomment-7071675019). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-22T00:37:38Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"f7932cb562c01859de5c5d6635f688deede3d20e","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-22T00:44:40.099498Z">2026-11-22T00:44:40.099498Z</relative-time> | `f7932cb` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
R0Y00 commented 2026-11-24 06:49:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T17:50:59Z.


I integrated main and repaired the scalar FP findings. Round now quiets signaling NaNs with the original payload, MIN/MAX and directed rounding honor DAZ, and the COMI/UCOMI controls distinguish the masked invalid flag for quiet and signaling NaNs. The 39 original scalar cases, new MXCSR controls and existing shuffle cases passed in both Windows presets. Fresh CI is running.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7109272547 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/407#issuecomment-7109272547). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T17:50:59Z. --- I integrated main and repaired the scalar FP findings. Round now quiets signaling NaNs with the original payload, MIN/MAX and directed rounding honor DAZ, and the COMI/UCOMI controls distinguish the masked invalid flag for quiet and signaling NaNs. The 39 original scalar cases, new MXCSR controls and existing shuffle cases passed in both Windows presets. Fresh CI is running.
R0Y00 commented 2026-11-24 06:49:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T18:06:02Z.


The /O2 log showed one stale SSE test expecting rejection of VEX VEXTRACTPS with XMM0, which this PR now verifies against native execution. I changed that negative case to an untracked XMM3 source. SSE3/4.1, AVX scalar and AVX shuffle passed 3/3 in both Windows presets. CI is rerunning on the new head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7109651321 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/407#issuecomment-7109651321). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T18:06:02Z. --- The /O2 log showed one stale SSE test expecting rejection of VEX VEXTRACTPS with XMM0, which this PR now verifies against native execution. I changed that negative case to an untracked XMM3 source. SSE3/4.1, AVX scalar and AVX shuffle passed 3/3 in both Windows presets. CI is rerunning on the new head.
chatgpt-codex-connector[bot commented 2026-11-24 06:50:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-22T00:44:37Z.

Code review location: tools/ffx_version_query.py; line 35

@@ -30,6 +31,15 @@
 template<class T> void store(word address, T v) {
     memcpy(reinterpret_cast<void*>(address), &v, sizeof v);
 }
+template<class T> T round_x86(T x, unsigned mode) {
+    if (!std::isfinite(x) || x == T(0)) return x;

P2 Badge Quiet signaling NaNs before returning from round_x86

With a signaling-NaN source and masked invalid exceptions, VROUNDSS/VROUNDSD must return a quiet NaN, but this non-finite fast path returns the original signaling bit pattern. In a Linux/x64 native probe of this exact header with default MXCSR, vroundss with immediate 0x08 converts input bits 0x7f800001 to 0x7fc00001, while round_x86<float>(x, 0) returns 0x7f800001; the double version has the corresponding mismatch. Thus the newly accepted instructions can store different scalar bits from native execution. Handle NaNs separately from infinities and add signaling-NaN differential cases.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4655805625 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/407#discussion_r4655805625). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-22T00:44:37Z. **Code review location:** `tools/ffx_version_query.py`; line 35 ~~~~diff @@ -30,6 +31,15 @@ template<class T> void store(word address, T v) { memcpy(reinterpret_cast<void*>(address), &v, sizeof v); } +template<class T> T round_x86(T x, unsigned mode) { + if (!std::isfinite(x) || x == T(0)) return x; ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Quiet signaling NaNs before returning from round_x86** With a signaling-NaN source and masked invalid exceptions, `VROUNDSS`/`VROUNDSD` must return a quiet NaN, but this non-finite fast path returns the original signaling bit pattern. In a Linux/x64 native probe of this exact header with default MXCSR, `vroundss` with immediate `0x08` converts input bits `0x7f800001` to `0x7fc00001`, while `round_x86<float>(x, 0)` returns `0x7f800001`; the double version has the corresponding mismatch. Thus the newly accepted instructions can store different scalar bits from native execution. Handle NaNs separately from infinities and add signaling-NaN differential cases. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-24 06:50:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-22T00:44:37Z.

Code review location: tools/ffx_version_query.py; line 293

@@ -210,6 +227,73 @@ def write(expr):
             stmt = (f"{{ auto input = {src}; {dst} = {{}}; for (size_t n=0; n<16; n+=4) {{ "
                     f"auto v = load<uint32_t>(reinterpret_cast<word>(input.data()+n)) {operation}; "
                     f"memcpy({dst}.data()+n, &v, 4); }} }}")
+        elif op == M.VEXTRACTPS and i.encoding == EncodingKind.VEX and has_wide and i.op1_register in wide_xmm:
+            lane = i.immediate(2) & 3
+            stmt = f"{{ uint32_t v; memcpy(&v, {wide_xmm[i.op1_register]}.data()+{4 * lane}, 4); {write('v')} }}"
+        elif op in (M.VCOMISS, M.VUCOMISS, M.VCOMISD, M.VUCOMISD) and i.encoding == EncodingKind.VEX and has_wide and i.op0_register in wide_xmm:
+            ftype, sz = ("float", 4) if op in (M.VCOMISS, M.VUCOMISS) else ("double", 8)
+            s2 = (f"{ftype} b; memcpy(&b, {wide_xmm[i.op1_register]}.data(), {sz});" if i.op1_kind == K.REGISTER
+                  else f"{ftype} b = load<{ftype}>({address()});")
+            stmt = (f"{{ {ftype} a; memcpy(&a, {wide_xmm[i.op0_register]}.data(), {sz}); {s2} "
+                    f"const bool u = std::isnan(a) || std::isnan(b); zero = u || (a == b); carry = u || (a < b); }}")
+        elif op == M.VMOVSS and i.encoding == EncodingKind.VEX and has_wide:
+            if i.op_count == 2 and i.op0_kind == K.REGISTER and i.op0_register in wide_xmm and i.op1_kind == K.MEMORY:
+                dst = wide_xmm[i.op0_register]
+                stmt = f"{dst} = {{}}; memcpy({dst}.data(), reinterpret_cast<const void*>({address()}), 4);"
+            elif i.op_count == 2 and i.op0_kind == K.MEMORY and i.op1_kind == K.REGISTER and i.op1_register in wide_xmm:
+                stmt = f"memcpy(reinterpret_cast<void*>({address()}), {wide_xmm[i.op1_register]}.data(), 4);"
+            elif i.op_count == 3 and i.op0_register in wide_xmm and i.op1_register in wide_xmm and i.op2_register in wide_xmm:
+                dst, s1, s2 = wide_xmm[i.op0_register], wide_xmm[i.op1_register], wide_xmm[i.op2_register]
+                stmt = f"{{ auto t = {s1}; uint8_t lo[4]; memcpy(lo, {s2}.data(), 4); {dst} = {{}}; memcpy({dst}.data(), t.data(), 16); memcpy({dst}.data(), lo, 4); }}"
+            else:
+                raise ValueError(f"unsupported VMOVSS form at {i.ip:#x}: {i}")
+        elif op in (M.VMOVLPS, M.VMOVHPS, M.VMOVLPD) and i.encoding == EncodingKind.VEX and has_wide:
+            off = 8 if op == M.VMOVHPS else 0
+            if i.op_count == 2 and i.op0_kind == K.MEMORY and i.op1_register in wide_xmm:
+                stmt = f"memcpy(reinterpret_cast<void*>({address()}), {wide_xmm[i.op1_register]}.data()+{off}, 8);"
+            elif i.op_count == 3 and i.op0_register in wide_xmm and i.op1_register in wide_xmm and i.op2_kind == K.MEMORY:
+                dst, s1 = wide_xmm[i.op0_register], wide_xmm[i.op1_register]
+                stmt = f"{{ auto t = {s1}; {dst} = {{}}; memcpy({dst}.data(), t.data(), 16); memcpy({dst}.data()+{off}, reinterpret_cast<const void*>({address()}), 8); }}"
+            else:
+                raise ValueError(f"unsupported {op} form at {i.ip:#x}: {i}")
+        elif op in (M.VMOVHLPS, M.VMOVLHPS) and i.encoding == EncodingKind.VEX and has_wide and i.op0_register in wide_xmm:
+            dst, s1, s2 = wide_xmm[i.op0_register], wide_xmm[i.op1_register], wide_xmm[i.op2_register]
+            if op == M.VMOVHLPS:
+                stmt = f"{{ auto a = {s1}, b = {s2}; {dst} = {{}}; memcpy({dst}.data(), b.data()+8, 8); memcpy({dst}.data()+8, a.data()+8, 8); }}"
+            else:
+                stmt = f"{{ auto a = {s1}, b = {s2}; {dst} = {{}}; memcpy({dst}.data(), a.data(), 8); memcpy({dst}.data()+8, b.data(), 8); }}"
+        elif op == M.VINSERTPS and i.encoding == EncodingKind.VEX and has_wide and i.op0_register in wide_xmm:
+            dst, s1 = wide_xmm[i.op0_register], wide_xmm[i.op1_register]
+            imm = i.immediate(3)
+            cs, cd, zm = (imm >> 6) & 3, (imm >> 4) & 3, imm & 0xf
+            s2_val = (f"uint8_t v[4]; memcpy(v, {wide_xmm[i.op2_register]}.data()+{4*cs}, 4);" if i.op2_kind == K.REGISTER
+                      else f"uint8_t v[4]; memcpy(v, reinterpret_cast<const void*>({address()}), 4);")
+            zeros = " ".join(f"memset({dst}.data()+{4*k}, 0, 4);" for k in range(4) if (zm >> k) & 1)
+            stmt = f"{{ auto t = {s1}; {s2_val} {dst} = {{}}; memcpy({dst}.data(), t.data(), 16); memcpy({dst}.data()+{4*cd}, v, 4); {zeros} }}"
+        elif (op in (M.VADDSS, M.VSUBSS, M.VMULSS, M.VDIVSS, M.VSQRTSS, M.VMINSS, M.VMAXSS, M.VROUNDSS,
+                     M.VADDSD, M.VSUBSD, M.VMULSD, M.VDIVSD, M.VSQRTSD, M.VMINSD, M.VMAXSD, M.VROUNDSD)
+              and i.encoding == EncodingKind.VEX and has_wide and i.op0_register in wide_xmm):
+            dst, s1 = wide_xmm[i.op0_register], wide_xmm[i.op1_register]
+            is_ss = op in (M.VADDSS, M.VSUBSS, M.VMULSS, M.VDIVSS, M.VSQRTSS, M.VMINSS, M.VMAXSS, M.VROUNDSS)
+            ftype, sz = ("float", 4) if is_ss else ("double", 8)
+            s2 = (f"{ftype} b; memcpy(&b, {wide_xmm[i.op2_register]}.data(), {sz});" if i.op2_kind == K.REGISTER
+                  else f"{ftype} b = load<{ftype}>({address()});")
+            if op in (M.VROUNDSS, M.VROUNDSD):
+                imm = i.immediate(3)
+                if imm & 4:
+                    raise ValueError(f"unsupported MXCSR rounding mode in {op} at {i.ip:#x}: {i}")
+                expr = f"round_x86(b, {imm & 3}u)"
+            elif op in (M.VSQRTSS, M.VSQRTSD):
+                expr = "std::sqrt(b)"
+            else:
+                expr = {
+                    M.VADDSS: "a + b", M.VADDSD: "a + b", M.VSUBSS: "a - b", M.VSUBSD: "a - b",
+                    M.VMULSS: "a * b", M.VMULSD: "a * b", M.VDIVSS: "a / b", M.VDIVSD: "a / b",
+                    M.VMINSS: "(a < b) ? a : b", M.VMINSD: "(a < b) ? a : b",
+                    M.VMAXSS: "(a > b) ? a : b", M.VMAXSD: "(a > b) ? a : b",

P2 Badge Apply DAZ normalization before selecting min/max results

When MXCSR.DAZ is enabled, these comparisons treat subnormal operands as zero but can copy their original nonzero bits into the result. In an unoptimized Linux/x64 GCC probe with MXCSR 0x1fc0, a=1.0f and b containing float bits 0x00000001, native vminss returns 0x00000000, whereas this expression returns 0x00000001; max and double forms have the same normalization problem. The round_x86 zero fast path likewise returns an unchanged subnormal under DAZ. Normalize DAZ inputs explicitly or use equivalent scalar intrinsics, and add DAZ-enabled differential cases rather than relying on an optimizer to replace the conditional with a native min/max instruction.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4655805629 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/407#discussion_r4655805629). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-22T00:44:37Z. **Code review location:** `tools/ffx_version_query.py`; line 293 ~~~~diff @@ -210,6 +227,73 @@ def write(expr): stmt = (f"{{ auto input = {src}; {dst} = {{}}; for (size_t n=0; n<16; n+=4) {{ " f"auto v = load<uint32_t>(reinterpret_cast<word>(input.data()+n)) {operation}; " f"memcpy({dst}.data()+n, &v, 4); }} }}") + elif op == M.VEXTRACTPS and i.encoding == EncodingKind.VEX and has_wide and i.op1_register in wide_xmm: + lane = i.immediate(2) & 3 + stmt = f"{{ uint32_t v; memcpy(&v, {wide_xmm[i.op1_register]}.data()+{4 * lane}, 4); {write('v')} }}" + elif op in (M.VCOMISS, M.VUCOMISS, M.VCOMISD, M.VUCOMISD) and i.encoding == EncodingKind.VEX and has_wide and i.op0_register in wide_xmm: + ftype, sz = ("float", 4) if op in (M.VCOMISS, M.VUCOMISS) else ("double", 8) + s2 = (f"{ftype} b; memcpy(&b, {wide_xmm[i.op1_register]}.data(), {sz});" if i.op1_kind == K.REGISTER + else f"{ftype} b = load<{ftype}>({address()});") + stmt = (f"{{ {ftype} a; memcpy(&a, {wide_xmm[i.op0_register]}.data(), {sz}); {s2} " + f"const bool u = std::isnan(a) || std::isnan(b); zero = u || (a == b); carry = u || (a < b); }}") + elif op == M.VMOVSS and i.encoding == EncodingKind.VEX and has_wide: + if i.op_count == 2 and i.op0_kind == K.REGISTER and i.op0_register in wide_xmm and i.op1_kind == K.MEMORY: + dst = wide_xmm[i.op0_register] + stmt = f"{dst} = {{}}; memcpy({dst}.data(), reinterpret_cast<const void*>({address()}), 4);" + elif i.op_count == 2 and i.op0_kind == K.MEMORY and i.op1_kind == K.REGISTER and i.op1_register in wide_xmm: + stmt = f"memcpy(reinterpret_cast<void*>({address()}), {wide_xmm[i.op1_register]}.data(), 4);" + elif i.op_count == 3 and i.op0_register in wide_xmm and i.op1_register in wide_xmm and i.op2_register in wide_xmm: + dst, s1, s2 = wide_xmm[i.op0_register], wide_xmm[i.op1_register], wide_xmm[i.op2_register] + stmt = f"{{ auto t = {s1}; uint8_t lo[4]; memcpy(lo, {s2}.data(), 4); {dst} = {{}}; memcpy({dst}.data(), t.data(), 16); memcpy({dst}.data(), lo, 4); }}" + else: + raise ValueError(f"unsupported VMOVSS form at {i.ip:#x}: {i}") + elif op in (M.VMOVLPS, M.VMOVHPS, M.VMOVLPD) and i.encoding == EncodingKind.VEX and has_wide: + off = 8 if op == M.VMOVHPS else 0 + if i.op_count == 2 and i.op0_kind == K.MEMORY and i.op1_register in wide_xmm: + stmt = f"memcpy(reinterpret_cast<void*>({address()}), {wide_xmm[i.op1_register]}.data()+{off}, 8);" + elif i.op_count == 3 and i.op0_register in wide_xmm and i.op1_register in wide_xmm and i.op2_kind == K.MEMORY: + dst, s1 = wide_xmm[i.op0_register], wide_xmm[i.op1_register] + stmt = f"{{ auto t = {s1}; {dst} = {{}}; memcpy({dst}.data(), t.data(), 16); memcpy({dst}.data()+{off}, reinterpret_cast<const void*>({address()}), 8); }}" + else: + raise ValueError(f"unsupported {op} form at {i.ip:#x}: {i}") + elif op in (M.VMOVHLPS, M.VMOVLHPS) and i.encoding == EncodingKind.VEX and has_wide and i.op0_register in wide_xmm: + dst, s1, s2 = wide_xmm[i.op0_register], wide_xmm[i.op1_register], wide_xmm[i.op2_register] + if op == M.VMOVHLPS: + stmt = f"{{ auto a = {s1}, b = {s2}; {dst} = {{}}; memcpy({dst}.data(), b.data()+8, 8); memcpy({dst}.data()+8, a.data()+8, 8); }}" + else: + stmt = f"{{ auto a = {s1}, b = {s2}; {dst} = {{}}; memcpy({dst}.data(), a.data(), 8); memcpy({dst}.data()+8, b.data(), 8); }}" + elif op == M.VINSERTPS and i.encoding == EncodingKind.VEX and has_wide and i.op0_register in wide_xmm: + dst, s1 = wide_xmm[i.op0_register], wide_xmm[i.op1_register] + imm = i.immediate(3) + cs, cd, zm = (imm >> 6) & 3, (imm >> 4) & 3, imm & 0xf + s2_val = (f"uint8_t v[4]; memcpy(v, {wide_xmm[i.op2_register]}.data()+{4*cs}, 4);" if i.op2_kind == K.REGISTER + else f"uint8_t v[4]; memcpy(v, reinterpret_cast<const void*>({address()}), 4);") + zeros = " ".join(f"memset({dst}.data()+{4*k}, 0, 4);" for k in range(4) if (zm >> k) & 1) + stmt = f"{{ auto t = {s1}; {s2_val} {dst} = {{}}; memcpy({dst}.data(), t.data(), 16); memcpy({dst}.data()+{4*cd}, v, 4); {zeros} }}" + elif (op in (M.VADDSS, M.VSUBSS, M.VMULSS, M.VDIVSS, M.VSQRTSS, M.VMINSS, M.VMAXSS, M.VROUNDSS, + M.VADDSD, M.VSUBSD, M.VMULSD, M.VDIVSD, M.VSQRTSD, M.VMINSD, M.VMAXSD, M.VROUNDSD) + and i.encoding == EncodingKind.VEX and has_wide and i.op0_register in wide_xmm): + dst, s1 = wide_xmm[i.op0_register], wide_xmm[i.op1_register] + is_ss = op in (M.VADDSS, M.VSUBSS, M.VMULSS, M.VDIVSS, M.VSQRTSS, M.VMINSS, M.VMAXSS, M.VROUNDSS) + ftype, sz = ("float", 4) if is_ss else ("double", 8) + s2 = (f"{ftype} b; memcpy(&b, {wide_xmm[i.op2_register]}.data(), {sz});" if i.op2_kind == K.REGISTER + else f"{ftype} b = load<{ftype}>({address()});") + if op in (M.VROUNDSS, M.VROUNDSD): + imm = i.immediate(3) + if imm & 4: + raise ValueError(f"unsupported MXCSR rounding mode in {op} at {i.ip:#x}: {i}") + expr = f"round_x86(b, {imm & 3}u)" + elif op in (M.VSQRTSS, M.VSQRTSD): + expr = "std::sqrt(b)" + else: + expr = { + M.VADDSS: "a + b", M.VADDSD: "a + b", M.VSUBSS: "a - b", M.VSUBSD: "a - b", + M.VMULSS: "a * b", M.VMULSD: "a * b", M.VDIVSS: "a / b", M.VDIVSD: "a / b", + M.VMINSS: "(a < b) ? a : b", M.VMINSD: "(a < b) ? a : b", + M.VMAXSS: "(a > b) ? a : b", M.VMAXSD: "(a > b) ? a : b", ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Apply DAZ normalization before selecting min/max results** When MXCSR.DAZ is enabled, these comparisons treat subnormal operands as zero but can copy their original nonzero bits into the result. In an unoptimized Linux/x64 GCC probe with MXCSR `0x1fc0`, `a=1.0f` and `b` containing float bits `0x00000001`, native `vminss` returns `0x00000000`, whereas this expression returns `0x00000001`; max and double forms have the same normalization problem. The `round_x86` zero fast path likewise returns an unchanged subnormal under DAZ. Normalize DAZ inputs explicitly or use equivalent scalar intrinsics, and add DAZ-enabled differential cases rather than relying on an optimizer to replace the conditional with a native min/max instruction. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Sign in to join this conversation.
No reviewers
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!401
No description provided.