Repository navigation
[AUTOMATED] Keep 32-bit-address rep string loops on x86-64 - #1981
Merged
mahaloz merged 5 commits intoNov 26, 2026
Merged
Conversation
With an address-size override, rep stos/movs/cmps on x86-64 step EDI/ESI, which wrap at 4 GiB. repstring turned them into builtin_memset32/memcpy, which cannot wrap. It now declines when a stepped pointer is narrower than an address of the default data space, so the loop stays a loop. i386 and 64-bit-address forms are unchanged. Strict correctness fix, no option. Re-records docs/baseline-stages.json for the renamed and added REXPREFIX assertions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
sjkim1127
force-pushed
the
claude/fix-repstring-addr32-4ad622
branch
from
November 26, 2026 01:20
6fba38a to
6f620fb
Compare
full_width() now refuses the rewrite when the default data space is unknown instead of allowing it. kuna-rex-before-prefix.xml adds rex_cmps (f3 48 67 a6), a 32-bit-address repz cmpsb that used to become builtin_memcmp, so stos, movs and cmps are all pinned as loops. Re-records docs/baseline-stages.json for the two new assertions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the REX stage The loop assertions `*a0 = v2;` and `*a0 = *a1;` replaced builtin_memset32 and builtin_memcpy(..., n * 8), which were what pinned the dword and quadword width the prefixes decode to. Two assertions on the rex_stos and rex_movs prototypes pin it again. The wrap example in the comment now uses EDI=0xfffffffc, ECX=2. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
…inters x86:LE:64:compat32 runs 32-bit code on the 64-bit SLEIGH model, so every ESI/EDI it steps is narrower than the 8-byte data space and the width check declined all of its rep strings, although they wrap only where the program's 4 GiB address space does, as on i386. A pointer as wide as the compiler spec's pointer (4 bytes in the x86 32-bit cspecs) now also counts as full width. x86-64 cspecs have 8-byte pointers, so an address-size override there still keeps its loop. The spec also says why 16-bit code is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
5,503 assertions: main's 5,497, the four 32-bit-address loop assertions and the two width pins. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Contributor
|
[AUTOMATED] Pushed three commits on top of c449784:
|
mahaloz
marked this pull request as ready for review
November 26, 2026 02:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On x86-64, a
rep stos/rep movswith an address-size override (67) steps 32-bit EDI/ESI, which wrap at 4 GiB, butrepstringstill turns it into abuiltin_memset32/builtin_memcpy, which cannot wrap.With
EDI = 0xfffffffc, ECX = 2the CPU (checked in Unicorn) stores the second dword at0x0and leavesRDI = 0x4; the memset writes it at0x100000000.Fix
repstringdeclines a copy, fill or compare when a pointer it steps is narrower than an address of the default data space, so the instruction stays a loop over the 32-bit pointer. With--option repstring offthe output was already this loop.rep stoswthrough RDI (f3 48 66 ab) still becomesbuiltin_memset16.Tests
tests/stages/kuna-rex-before-prefix.xmlnow pinsrex_stos(f3 48 67 ab),rex_movs(48 67 f3 48 a5) andrex_cmps(f3 48 67 a6) as loops and asserts nobuiltin_memset32/builtin_memcpy/builtin_memcmp; the new assertions fail onmain.kuna-repstring.xmlandkuna-repstring-i386.xmlare unchanged, as is the full datatest corpus (675/675). No measurable speed change;decompile-allof a 3.9 MB x86-64 Rust binary prints the same code before and after.Model:
anthropic/claude-opus-5-5🤖 Generated with Claude Code