Repository navigation
memset: load the registers and loop in one asm statement, as wmemset - #90
Merged
Merged
Conversation
Member
Author
|
Cc: @bebbo |
reinauer
reviewed
Nov 4, 2026
There was a problem hiding this comment.
Looks good, with the same one-character fix as #88. m needs an early clobber, "+&d" (m), so that gcc can't put it and c in the same register when it knows both values (see #88). In memset() that takes equal constants for c and n / 32, so it's even less likely than in wmemset(), but it's free.
Otherwise, the rest:
- The byte and word stores before the loop and the long and byte loops after it now take
"+a"/"d"with"memory", so nothing depends onregister ... asm()pinning any more. c = (unsigned char) _creplaces the oldc &= 0xff, now for every length and not only above 18. The byte loop usedd2directly, so it already stored the right low byte; your0x1a5test covers that.- GitHub shows it conflicting now. That's probably
test/Makefile, where #89 addedmultibytenext to where this addsmemset, so it needs a rebase.
At -Og gcc reused the registers between loading them and the movem. The stores now take their operands rather than naming d2 and relying on pinning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
As in wmemset: without it gcc may give the count and the fill value one register when it knows both are equal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
reinauer
approved these changes
Nov 4, 2026
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.
Follow-up to #88, which fixed the same pattern in
wmemset(): @reinauer found thatmemset()has it too (#88 (review)).The
move.l %0,d5statements before themovemloop only clobbered d5-d7, a1-a3 and a6, so nothing kept those registers intact until themovem, which also had no"memory"clobber. At-Oggcc reuses them in between, and the fill goes wrong.The registers are now loaded and the loop run in one asm statement, as in #88. The rest keeps its structure: align, 32 bytes at a time with
movem, then longs, then bytes. Every store now takes its operands as"+a"/"d"with a"memory"clobber. Before, the byte loop namedd2directly, and-(%0)relied onregister ... asm("a0")pinning to get an address register. The stores stay in asm so that gcc can't turn the loops back into a call tomemset().Tested
test/memset.cis new, inmake check-target: every length from 0 to 150 at four alignments, guards on both sides, and a value with high bits set (0x1a5). Under volamos, withmemset.cbuilt at each level and the test at-O2 -fno-builtin, failures out of 604:-O0-Og-O0 -m68020-O1-O2-O3-Os-O2 -fomit-frame-pointer-O2 -fbaserel-Os -m68020-O2 -m68060 -fomit-frame-pointerAt
-O2, the level libnix builds the string functions at, it goes from 168 to 156 bytes. The inner loop is the samemovem.las before.🤖 Generated with Claude Code