Pin pcmpstr length-15 boundaries, unsigned singleton ranges and scale-1 indexing #975

Merged
Leyukaka merged 2 commits from upstream-pr/982 into main 2026-11-23 20:04:39 +00:00
Leyukaka commented 2026-11-23 19:47:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-23T19:47:24Z.


Change

This adds four inputs to tests/cpu/avx_pcmpstr.py that close five gaps in the test coverage of tools/cpu_avx_pcmpstr_aot.py. Each gap is a small mutation of the translator that passes cpu_aot_avx_pcmpstr on main. The native fixture DLL stays the reference; the translator does not change.

New input What it reaches for the first time Mutation it covers
Explicit lengths (1, 15) a second-operand length of 15 for the byte exports saturation mag < limit -> mag < limit - 1u
Byte pair "A" * 15 + "\x00" on both sides an implicit-length terminator in the last lane (len1 = len2 = 15) the implicit length scan stopping one lane early; SF computed as len1 < limit - 1u
Word pair with the range [10, 10] and first B word 10 an equal-bounds range in the unsigned ranges export (vpcmpistrm_uw_ranges_mpos_bit) a translator that skips unsigned ranges with equal bounds
vpcmpistri xmm1, [rdx+rcx*1], 0 an index register with scale 1 the index rejection narrowed so that scale 1 is accepted

The singleton range only catches a translator that special-cases equal bounds in unsigned ranges: inclusive bounds were already pinned by the existing word pairs, and the signed-byte ranges export already meets an equal-bounds range. The scale-1 control takes the same rejection branch as the existing [rdx+rcx*4] control; it guards against a future change that would accept scale 1. With the new inputs, the check runs 1,274 differential cases and 32 unit rejection controls; docs/experiments.md is updated to those counts (it said 1,028 and 30).

Verification

On d62e61f (based on main at 23d2e93), Windows 11 build 26300, MSVC 14.44.35207, Python 3.14:

ctest --preset dev --no-tests=error -R '^cpu_aot_avx_pcmpstr$' -V
python -B tests/docs_links_check.py

The test passes and prints 1274 VEX.128 AVX packed string compare cases across 22 exports matched native and reference and 32 unit rejection controls and 5 PE-patched rejection controls passed. The docs check passes.

Each mutation was applied to tools/cpu_avx_pcmpstr_aot.py one at a time, the project was rebuilt so the translation was regenerated, and cpu_aot_avx_pcmpstr was run with the main and the branch versions of avx_pcmpstr.py. With the unmutated translator both pass. On main, the test passed under all five mutations; on this branch it fails under each of them.

The five edits to tools/cpu_avx_pcmpstr_aot.py:

  1. return mag < limit ? mag : limit; -> return mag < limit - 1u ? mag : limit;
  2. while (len2 < limit && pcmp_elem(b, len2, is_word, is_signed) != 0) ++len2; -> while (len2 < limit - 1u && ...) ++len2; followed by if (len2 == limit - 1u) ++len2;
  3. before the range bound compare, if (!is_signed && pcmp_elem(a, j, ...) == pcmp_elem(a, j + 1u, ...)) continue;
  4. len1 < limit -> len1 < limit - 1u in the Flags initializer (SF)
  5. or ins.memory_index != R.NONE -> or (ins.memory_index != R.NONE and ins.memory_index_scale != 1)

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed. (Counts only.)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6567466639 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/982). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-23T19:47:24Z. --- ## Change This adds four inputs to `tests/cpu/avx_pcmpstr.py` that close five gaps in the test coverage of `tools/cpu_avx_pcmpstr_aot.py`. Each gap is a small mutation of the translator that passes `cpu_aot_avx_pcmpstr` on `main`. The native fixture DLL stays the reference; the translator does not change. | New input | What it reaches for the first time | Mutation it covers | |---|---|---| | Explicit lengths `(1, 15)` | a second-operand length of 15 for the byte exports | saturation `mag < limit` -> `mag < limit - 1u` | | Byte pair `"A" * 15 + "\x00"` on both sides | an implicit-length terminator in the last lane (len1 = len2 = 15) | the implicit length scan stopping one lane early; SF computed as `len1 < limit - 1u` | | Word pair with the range `[10, 10]` and first B word 10 | an equal-bounds range in the unsigned ranges export (`vpcmpistrm_uw_ranges_mpos_bit`) | a translator that skips unsigned ranges with equal bounds | | `vpcmpistri xmm1, [rdx+rcx*1], 0` | an index register with scale 1 | the index rejection narrowed so that scale 1 is accepted | The singleton range only catches a translator that special-cases equal bounds in unsigned ranges: inclusive bounds were already pinned by the existing word pairs, and the signed-byte ranges export already meets an equal-bounds range. The scale-1 control takes the same rejection branch as the existing `[rdx+rcx*4]` control; it guards against a future change that would accept scale 1. With the new inputs, the check runs 1,274 differential cases and 32 unit rejection controls; `docs/experiments.md` is updated to those counts (it said 1,028 and 30). ## Verification On `d62e61f` (based on `main` at `23d2e93`), Windows 11 build 26300, MSVC 14.44.35207, Python 3.14: ```text ctest --preset dev --no-tests=error -R '^cpu_aot_avx_pcmpstr$' -V python -B tests/docs_links_check.py ``` The test passes and prints `1274 VEX.128 AVX packed string compare cases across 22 exports matched native and reference` and `32 unit rejection controls and 5 PE-patched rejection controls passed`. The docs check passes. Each mutation was applied to `tools/cpu_avx_pcmpstr_aot.py` one at a time, the project was rebuilt so the translation was regenerated, and `cpu_aot_avx_pcmpstr` was run with the `main` and the branch versions of `avx_pcmpstr.py`. With the unmutated translator both pass. On `main`, the test passed under all five mutations; on this branch it fails under each of them. The five edits to `tools/cpu_avx_pcmpstr_aot.py`: 1. `return mag < limit ? mag : limit;` -> `return mag < limit - 1u ? mag : limit;` 2. `while (len2 < limit && pcmp_elem(b, len2, is_word, is_signed) != 0) ++len2;` -> `while (len2 < limit - 1u && ...) ++len2;` followed by `if (len2 == limit - 1u) ++len2;` 3. before the range bound compare, `if (!is_signed && pcmp_elem(a, j, ...) == pcmp_elem(a, j + 1u, ...)) continue;` 4. `len1 < limit` -> `len1 < limit - 1u` in the `Flags` initializer (SF) 5. `or ins.memory_index != R.NONE` -> `or (ins.memory_index != R.NONE and ins.memory_index_scale != 1)` ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. (Counts only.) - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
upstream-sync closed this pull request 2026-11-24 06:45:42 +00:00
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!975
No description provided.