cpu: lower AVX conversions, compares, flag tests, and aligned/streaming moves #387

Merged
Vonsek merged 5 commits from upstream-pr/393 into main 2026-11-23 19:07:33 +00:00
Vonsek commented 2026-11-22 00:13:21 +00:00 (Migrated from github.com)

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


Change

  • Lower 28 VEX 128-bit and 256-bit AVX conversion, compare, flag-test, and aligned/streaming move instructions in tools/ffx_version_query.py:
    • Packed conversions: vcvtdq2ps, vcvtdq2pd, vcvtps2dq, vcvtpd2dq, vcvttps2dq, vcvttpd2dq, vcvtps2pd, vcvtpd2ps
    • Scalar conversions: vcvtsi2ss, vcvtsi2sd, vcvtss2sd, vcvtsd2ss, vcvtss2si, vcvttss2si, vcvtsd2si, vcvttsd2si (with 32-bit and 64-bit integer-indefinite clamping)
    • Packed and scalar FP compares (all 32 AVX predicate encodings): vcmpps, vcmppd, vcmpss, vcmpsd
    • Vector flag tests (updating ZF and CF): vptest, vtestps, vtestpd
    • Aligned and streaming moves: vmovaps, vmovapd, vmovdqa, vlddqu, vmovntdqa
  • Restrict lowering to EncodingKind.VEX (rejecting EVEX encodings) 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_cvt_cmp_test.{asm,def,py}, CMake target cpu_avx_cvt_cmp_test_lifted, CTest cpu_aot_avx_cvt_cmp_test, 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_cvt_cmp_test_lifted:
    ValueError: unsupported query operation at 0x1000: vmovdqa ymm1,ymmword ptr [rcx]
  • Built and tested on Windows 11 x64 (VS 2022 Build Tools):
    • cmake --build --preset dev --target cpu_avx_cvt_cmp_test_lifted succeeded with 0 warnings
    • ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_cvt_cmp_test|cpu_aot_bmi1)$" -V: 2/2 passed (33 AVX conversion/compare/test/move cases matched native and translated DLLs + EVEX vcvtdq2ps 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:6536202421 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/393). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-22T00:13:21Z. --- ## Change - Lower 28 VEX 128-bit and 256-bit AVX conversion, compare, flag-test, and aligned/streaming move instructions in `tools/ffx_version_query.py`: - Packed conversions: `vcvtdq2ps`, `vcvtdq2pd`, `vcvtps2dq`, `vcvtpd2dq`, `vcvttps2dq`, `vcvttpd2dq`, `vcvtps2pd`, `vcvtpd2ps` - Scalar conversions: `vcvtsi2ss`, `vcvtsi2sd`, `vcvtss2sd`, `vcvtsd2ss`, `vcvtss2si`, `vcvttss2si`, `vcvtsd2si`, `vcvttsd2si` (with 32-bit and 64-bit integer-indefinite clamping) - Packed and scalar FP compares (all 32 AVX predicate encodings): `vcmpps`, `vcmppd`, `vcmpss`, `vcmpsd` - Vector flag tests (updating ZF and CF): `vptest`, `vtestps`, `vtestpd` - Aligned and streaming moves: `vmovaps`, `vmovapd`, `vmovdqa`, `vlddqu`, `vmovntdqa` - Restrict lowering to `EncodingKind.VEX` (rejecting EVEX encodings) 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_cvt_cmp_test.{asm,def,py}`, CMake target `cpu_avx_cvt_cmp_test_lifted`, CTest `cpu_aot_avx_cvt_cmp_test`, 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_cvt_cmp_test_lifted`: `ValueError: unsupported query operation at 0x1000: vmovdqa ymm1,ymmword ptr [rcx]` - Built and tested on Windows 11 x64 (VS 2022 Build Tools): - `cmake --build --preset dev --target cpu_avx_cvt_cmp_test_lifted` succeeded with 0 warnings - `ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_cvt_cmp_test|cpu_aot_bmi1)$" -V`: 2/2 passed (`33 AVX conversion/compare/test/move cases matched native and translated DLLs` + EVEX `vcvtdq2ps` 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:48 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:42:49 +00:00 (Migrated from github.com)

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

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eb126f7db1

ℹ️ 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:6009165215 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/393#pullrequestreview-6009165215). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-22T00:25:32Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `eb126f7db1` <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:14 +00:00 (Migrated from github.com)

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


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:25:34.712146Z eb126f7 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:7071473656 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/393#issuecomment-7071473656). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-22T00:19:37Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"eb126f7db1e109b0050dbf59f0bd22ea4621a8bf","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:25:34.712146Z">2026-11-22T00:25:34.712146Z</relative-time> | `eb126f7` | 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:28 +00:00 (Migrated from github.com)

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


I updated this branch after #407 landed and kept both test fixtures. The conversion paths use Windows intrinsics for MXCSR-controlled rounding, and the compare path uses all five predicate bits. The original vs generated fixture exercises all four rounding modes and verifies that the signaling predicate sets the masked invalid flag. The streaming VMOVNTDQA form stays outside this patch; the VLDDQU case remains covered.

On Windows with MSVC 19.51, the Release AVX conversion/compare, scalar FP, and shuffle/blend CTests all ran and passed (3/3). The branch is ready for Windows CI.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7110125751 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/393#issuecomment-7110125751). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T18:24:44Z. --- I updated this branch after #407 landed and kept both test fixtures. The conversion paths use Windows intrinsics for MXCSR-controlled rounding, and the compare path uses all five predicate bits. The original vs generated fixture exercises all four rounding modes and verifies that the signaling predicate sets the masked invalid flag. The streaming VMOVNTDQA form stays outside this patch; the VLDDQU case remains covered. On Windows with MSVC 19.51, the Release AVX conversion/compare, scalar FP, and shuffle/blend CTests all ran and passed (3/3). The branch is ready for Windows CI.
R0Y00 commented 2026-11-24 06:49:29 +00:00 (Migrated from github.com)

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


The Windows failures were two stale rejection assertions. The original VEX.128 store now checks that its misalignment branch precedes the write, and the conversion test rejects a masked EVEX form while the new AVX fixture still compares supported YMM conversions against native execution. The unsupported legacy cases are still tested. All three affected Windows Release CTests now pass locally. The new head needs both Windows jobs again.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7110501061 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/393#issuecomment-7110501061). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T18:40:46Z. --- The Windows failures were two stale rejection assertions. The original VEX.128 store now checks that its misalignment branch precedes the write, and the conversion test rejects a masked EVEX form while the new AVX fixture still compares supported YMM conversions against native execution. The unsupported legacy cases are still tested. All three affected Windows Release CTests now pass locally. The new head needs both Windows jobs again.
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:25:32Z.

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

@@ -30,6 +31,23 @@
 template<class T> void store(word address, T v) {
     memcpy(reinterpret_cast<void*>(address), &v, sizeof v);
 }
+static inline double round_even_or_trunc(double x, bool trunc) {
+    if (trunc) return std::trunc(x);
+    const double f = std::floor(x), d = x - f;
+    return (d < 0.5) ? f : ((d > 0.5) ? (f + 1.0) : (std::fmod(f, 2.0) == 0.0 ? f : (f + 1.0)));

P2 Badge Honor MXCSR rounding for non-truncating conversions

When the caller selects a non-default MXCSR rounding mode, this helper still rounds every non-truncating conversion to nearest/even. In a standalone Linux/x64 check using this header, round-toward-zero made native vcvtsd2si convert 1.75 to 1, while cvt_to_i32 and cvt_to_i64 returned 2. The same helper backs vcvtps2dq, vcvtpd2dq, vcvtss2si, and vcvtsd2si, so these instructions silently produce incorrect numeric results outside the default rounding mode. Honor MXCSR.RC and add differential cases for the other rounding modes.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4655753312 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/393#discussion_r4655753312). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-22T00:25:32Z. **Code review location:** `tools/ffx_version_query.py`; line 37 ~~~~diff @@ -30,6 +31,23 @@ template<class T> void store(word address, T v) { memcpy(reinterpret_cast<void*>(address), &v, sizeof v); } +static inline double round_even_or_trunc(double x, bool trunc) { + if (trunc) return std::trunc(x); + const double f = std::floor(x), d = x - f; + return (d < 0.5) ? f : ((d > 0.5) ? (f + 1.0) : (std::fmod(f, 2.0) == 0.0 ? f : (f + 1.0))); ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Honor MXCSR rounding for non-truncating conversions** When the caller selects a non-default MXCSR rounding mode, this helper still rounds every non-truncating conversion to nearest/even. In a standalone Linux/x64 check using this header, round-toward-zero made native `vcvtsd2si` convert `1.75` to `1`, while `cvt_to_i32` and `cvt_to_i64` returned `2`. The same helper backs `vcvtps2dq`, `vcvtpd2dq`, `vcvtss2si`, and `vcvtsd2si`, so these instructions silently produce incorrect numeric results outside the default rounding mode. Honor MXCSR.RC and add differential cases for the other rounding modes. 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:25:32Z.

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

@@ -210,6 +237,122 @@ 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 in (M.VMOVAPS, M.VMOVAPD, M.VMOVDQA) and i.encoding == EncodingKind.VEX and has_wide:
+            if i.op0_kind == K.REGISTER and i.op0_register in wide_any and i.op1_kind == K.MEMORY:
+                dst = wide_any[i.op0_register]
+                nbytes = 32 if i.op0_register in wide else 16
+                stmt = f"{dst} = {{}}; memcpy({dst}.data(), reinterpret_cast<const void*>({address()}), {nbytes});"
+            elif i.op0_kind == K.MEMORY and i.op1_kind == K.REGISTER and i.op1_register in wide_any:
+                src = wide_any[i.op1_register]
+                nbytes = 32 if i.op1_register in wide else 16
+                stmt = f"memcpy(reinterpret_cast<void*>({address()}), {src}.data(), {nbytes});"
+            elif i.op0_kind == K.REGISTER and i.op0_register in wide_any and i.op1_kind == K.REGISTER and i.op1_register in wide_any:
+                dst, src = wide_any[i.op0_register], wide_any[i.op1_register]
+                nbytes = 32 if i.op0_register in wide else 16
+                stmt = f"{{ auto t = {src}; {dst} = {{}}; memcpy({dst}.data(), t.data(), {nbytes}); }}"
+            else:
+                raise ValueError(f"unsupported {op} form at {i.ip:#x}: {i}")
+        elif op in (M.VLDDQU, M.VMOVNTDQA) and i.encoding == EncodingKind.VEX and has_wide and i.op0_kind == K.REGISTER and i.op0_register in wide_any and i.op1_kind == K.MEMORY:
+            dst = wide_any[i.op0_register]
+            nbytes = 32 if i.op0_register in wide else 16
+            stmt = f"{dst} = {{}}; memcpy({dst}.data(), reinterpret_cast<const void*>({address()}), {nbytes});"
+        elif op in (M.VCVTSS2SI, M.VCVTTSS2SI, M.VCVTSD2SI, M.VCVTTSD2SI) and i.encoding == EncodingKind.VEX and has_wide:
+            is_sd = op in (M.VCVTSD2SI, M.VCVTTSD2SI)
+            ftype, nbytes = ("double", 8) if is_sd else ("float", 4)
+            tr = "true" if op in (M.VCVTTSS2SI, M.VCVTTSD2SI) else "false"
+            fn = "cvt_to_i64" if RegisterExt.size(i.op0_register) == 8 else "cvt_to_i32"
+            s_init = (f"{ftype} x; memcpy(&x, {wide_xmm[i.op1_register]}.data(), {nbytes});" if i.op1_kind == K.REGISTER
+                      else f"{ftype} x = load<{ftype}>({address()});")
+            stmt = f"{{ {s_init} const auto v = {fn}(double(x), {tr}); {write('v')} }}"
+        elif op in (M.VPTEST, M.VTESTPS, M.VTESTPD) and i.encoding == EncodingKind.VEX and has_wide and i.op0_register in wide_any:
+            src1 = wide_any[i.op0_register]
+            nbytes = 32 if i.op0_register in wide else 16
+            s2_init = (f"auto s2 = {wide_any[i.op1_register]};" if i.op1_kind == K.REGISTER
+                       else f"std::array<uint8_t,32> s2{{}}; memcpy(s2.data(), reinterpret_cast<const void*>({address()}), {nbytes});")
+            if op == M.VPTEST:
+                stmt = (f"{{ {s2_init} uint8_t z = 0, c = 0; for (size_t n=0; n<{nbytes}; ++n) {{ "
+                        f"z |= ({src1}[n] & s2[n]); c |= (static_cast<uint8_t>(~{src1}[n]) & s2[n]); }} "
+                        f"zero = z == 0; carry = c == 0; }}")
+            else:
+                lane_size = 4 if op == M.VTESTPS else 8
+                lanes = nbytes // lane_size
+                stmt = (f"{{ {s2_init} uint8_t z = 0, c = 0; for (size_t k=0; k<{lanes}; ++k) {{ "
+                        f"const uint8_t a = {src1}[(k + 1) * {lane_size} - 1] & 0x80u, b = s2[(k + 1) * {lane_size} - 1] & 0x80u; "
+                        f"z |= (a & b); c |= (static_cast<uint8_t>(~a) & b); }} zero = z == 0; carry = c == 0; }}")
+        elif (op in avx_cvt_ops and op not in (M.VMOVAPS, M.VMOVAPD, M.VMOVDQA, M.VLDDQU, M.VMOVNTDQA,
+                                               M.VCVTSS2SI, M.VCVTTSS2SI, M.VCVTSD2SI, M.VCVTTSD2SI,
+                                               M.VPTEST, M.VTESTPS, M.VTESTPD)
+              and i.encoding == EncodingKind.VEX and has_wide and i.op0_register in wide_any):
+            dst = wide_any[i.op0_register]
+            dst_bytes = 32 if i.op0_register in wide else 16
+            zero_hi = f" memset({dst}.data()+16, 0, 16);" if dst_bytes == 16 else ""
+            if op in (M.VCVTSI2SS, M.VCVTSI2SD):
+                src1 = wide_xmm[i.op1_register]
+                ftype, lsize = ("float", 4) if op == M.VCVTSI2SS else ("double", 8)
+                stype = "int64_t" if (MemorySizeExt.size(i.memory_size) if i.op2_kind == K.MEMORY else RegisterExt.size(i.op2_register)) == 8 else "int32_t"
+                stmt = (f"{{ auto t = {src1}; const {ftype} v = static_cast<{ftype}>(static_cast<{stype}>({operand(2)})); "
+                        f"memcpy(t.data(), &v, {lsize}); {dst} = {{}}; memcpy({dst}.data(), t.data(), 16); }}")
+            elif op in (M.VCVTSS2SD, M.VCVTSD2SS):
+                src1 = wide_xmm[i.op1_register]
+                in_t, in_sz, out_t, out_sz = ("float", 4, "double", 8) if op == M.VCVTSS2SD else ("double", 8, "float", 4)
+                s2 = (f"{in_t} x; memcpy(&x, {wide_xmm[i.op2_register]}.data(), {in_sz});" if i.op2_kind == K.REGISTER
+                      else f"{in_t} x = load<{in_t}>({address()});")
+                stmt = (f"{{ auto t = {src1}; {s2} const {out_t} v = static_cast<{out_t}>(x); "
+                        f"memcpy(t.data(), &v, {out_sz}); {dst} = {{}}; memcpy({dst}.data(), t.data(), 16); }}")
+            elif op in (M.VCMPPS, M.VCMPPD, M.VCMPSS, M.VCMPSD):
+                src1 = wide_any[i.op1_register]
+                pred = i.immediate(3) & 15

P2 Badge Preserve the signaling distinction in AVX compare predicates

For NaN operands, predicate bit 4 distinguishes quiet and signaling comparisons even when their result masks are identical. For example, vcmpps with immediate 31 (TRUE_US) must set MXCSR's invalid-operation status and raise an exception if it is unmasked, but masking with 15 selects the literal true, so the generated code performs no floating-point comparison. A standalone Linux/x64 check with quiet NaNs produced native exception status 0x01 versus lowered status 0x00, despite matching result masks. Preserve the signaling behavior, or reject predicates whose exception semantics are not implemented.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4655753316 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/393#discussion_r4655753316). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-22T00:25:32Z. **Code review location:** `tools/ffx_version_query.py`; line 304 ~~~~diff @@ -210,6 +237,122 @@ 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 in (M.VMOVAPS, M.VMOVAPD, M.VMOVDQA) and i.encoding == EncodingKind.VEX and has_wide: + if i.op0_kind == K.REGISTER and i.op0_register in wide_any and i.op1_kind == K.MEMORY: + dst = wide_any[i.op0_register] + nbytes = 32 if i.op0_register in wide else 16 + stmt = f"{dst} = {{}}; memcpy({dst}.data(), reinterpret_cast<const void*>({address()}), {nbytes});" + elif i.op0_kind == K.MEMORY and i.op1_kind == K.REGISTER and i.op1_register in wide_any: + src = wide_any[i.op1_register] + nbytes = 32 if i.op1_register in wide else 16 + stmt = f"memcpy(reinterpret_cast<void*>({address()}), {src}.data(), {nbytes});" + elif i.op0_kind == K.REGISTER and i.op0_register in wide_any and i.op1_kind == K.REGISTER and i.op1_register in wide_any: + dst, src = wide_any[i.op0_register], wide_any[i.op1_register] + nbytes = 32 if i.op0_register in wide else 16 + stmt = f"{{ auto t = {src}; {dst} = {{}}; memcpy({dst}.data(), t.data(), {nbytes}); }}" + else: + raise ValueError(f"unsupported {op} form at {i.ip:#x}: {i}") + elif op in (M.VLDDQU, M.VMOVNTDQA) and i.encoding == EncodingKind.VEX and has_wide and i.op0_kind == K.REGISTER and i.op0_register in wide_any and i.op1_kind == K.MEMORY: + dst = wide_any[i.op0_register] + nbytes = 32 if i.op0_register in wide else 16 + stmt = f"{dst} = {{}}; memcpy({dst}.data(), reinterpret_cast<const void*>({address()}), {nbytes});" + elif op in (M.VCVTSS2SI, M.VCVTTSS2SI, M.VCVTSD2SI, M.VCVTTSD2SI) and i.encoding == EncodingKind.VEX and has_wide: + is_sd = op in (M.VCVTSD2SI, M.VCVTTSD2SI) + ftype, nbytes = ("double", 8) if is_sd else ("float", 4) + tr = "true" if op in (M.VCVTTSS2SI, M.VCVTTSD2SI) else "false" + fn = "cvt_to_i64" if RegisterExt.size(i.op0_register) == 8 else "cvt_to_i32" + s_init = (f"{ftype} x; memcpy(&x, {wide_xmm[i.op1_register]}.data(), {nbytes});" if i.op1_kind == K.REGISTER + else f"{ftype} x = load<{ftype}>({address()});") + stmt = f"{{ {s_init} const auto v = {fn}(double(x), {tr}); {write('v')} }}" + elif op in (M.VPTEST, M.VTESTPS, M.VTESTPD) and i.encoding == EncodingKind.VEX and has_wide and i.op0_register in wide_any: + src1 = wide_any[i.op0_register] + nbytes = 32 if i.op0_register in wide else 16 + s2_init = (f"auto s2 = {wide_any[i.op1_register]};" if i.op1_kind == K.REGISTER + else f"std::array<uint8_t,32> s2{{}}; memcpy(s2.data(), reinterpret_cast<const void*>({address()}), {nbytes});") + if op == M.VPTEST: + stmt = (f"{{ {s2_init} uint8_t z = 0, c = 0; for (size_t n=0; n<{nbytes}; ++n) {{ " + f"z |= ({src1}[n] & s2[n]); c |= (static_cast<uint8_t>(~{src1}[n]) & s2[n]); }} " + f"zero = z == 0; carry = c == 0; }}") + else: + lane_size = 4 if op == M.VTESTPS else 8 + lanes = nbytes // lane_size + stmt = (f"{{ {s2_init} uint8_t z = 0, c = 0; for (size_t k=0; k<{lanes}; ++k) {{ " + f"const uint8_t a = {src1}[(k + 1) * {lane_size} - 1] & 0x80u, b = s2[(k + 1) * {lane_size} - 1] & 0x80u; " + f"z |= (a & b); c |= (static_cast<uint8_t>(~a) & b); }} zero = z == 0; carry = c == 0; }}") + elif (op in avx_cvt_ops and op not in (M.VMOVAPS, M.VMOVAPD, M.VMOVDQA, M.VLDDQU, M.VMOVNTDQA, + M.VCVTSS2SI, M.VCVTTSS2SI, M.VCVTSD2SI, M.VCVTTSD2SI, + M.VPTEST, M.VTESTPS, M.VTESTPD) + and i.encoding == EncodingKind.VEX and has_wide and i.op0_register in wide_any): + dst = wide_any[i.op0_register] + dst_bytes = 32 if i.op0_register in wide else 16 + zero_hi = f" memset({dst}.data()+16, 0, 16);" if dst_bytes == 16 else "" + if op in (M.VCVTSI2SS, M.VCVTSI2SD): + src1 = wide_xmm[i.op1_register] + ftype, lsize = ("float", 4) if op == M.VCVTSI2SS else ("double", 8) + stype = "int64_t" if (MemorySizeExt.size(i.memory_size) if i.op2_kind == K.MEMORY else RegisterExt.size(i.op2_register)) == 8 else "int32_t" + stmt = (f"{{ auto t = {src1}; const {ftype} v = static_cast<{ftype}>(static_cast<{stype}>({operand(2)})); " + f"memcpy(t.data(), &v, {lsize}); {dst} = {{}}; memcpy({dst}.data(), t.data(), 16); }}") + elif op in (M.VCVTSS2SD, M.VCVTSD2SS): + src1 = wide_xmm[i.op1_register] + in_t, in_sz, out_t, out_sz = ("float", 4, "double", 8) if op == M.VCVTSS2SD else ("double", 8, "float", 4) + s2 = (f"{in_t} x; memcpy(&x, {wide_xmm[i.op2_register]}.data(), {in_sz});" if i.op2_kind == K.REGISTER + else f"{in_t} x = load<{in_t}>({address()});") + stmt = (f"{{ auto t = {src1}; {s2} const {out_t} v = static_cast<{out_t}>(x); " + f"memcpy(t.data(), &v, {out_sz}); {dst} = {{}}; memcpy({dst}.data(), t.data(), 16); }}") + elif op in (M.VCMPPS, M.VCMPPD, M.VCMPSS, M.VCMPSD): + src1 = wide_any[i.op1_register] + pred = i.immediate(3) & 15 ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Preserve the signaling distinction in AVX compare predicates** For NaN operands, predicate bit 4 distinguishes quiet and signaling comparisons even when their result masks are identical. For example, `vcmpps` with immediate 31 (`TRUE_US`) must set MXCSR's invalid-operation status and raise an exception if it is unmasked, but masking with 15 selects the literal `true`, so the generated code performs no floating-point comparison. A standalone Linux/x64 check with quiet NaNs produced native exception status `0x01` versus lowered status `0x00`, despite matching result masks. Preserve the signaling behavior, or reject predicates whose exception semantics are not implemented. 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!387
No description provided.