Repository navigation
Explain and reproduce ps2eeas's nops before div.s (opt-in @divpad) - #204
Merged
Merged
Conversation
Retail's nops before div.s come from ps2eeas's divide-unit erratum padding, measured on ps2eeas 1.9.25 with -Wdivbug-on: div.s, sqrt.s, rsqrt.s, vdiv, vsqrt and vrsqrt 0 or 1 instruction after a label or after a B-type branch's delay slot get 2 minus that distance nops. The labels are mostly -g's line labels: retail was compiled with -g there and stripped, so a div.s that starts a source line has two nops. - ps2eeas_nops.py: rule 4 (--div), measured in the first-pass object, whose labels cc.sh now keeps with -Wa,-L; stabs lines no longer hide an mtc1 hazard from rule 3. - ps2eeas_stabs.py: drops -g's stabs directives and keeps its labels. - cc.sh: the @divpad cflags token compiles with -g and runs rule 4. Opt-in: some retail objects have no such nops (func_L00_00590698). -g leaves the code unchanged: a full build has the same .text in all 8687 compared objects. With these tools and no file using @divpad, the 9358 objects of a full build have the same .text as with the old tools. With @divpad, func_00502B10, func_L00_006D57A0, func_L00_0077FA58 and func_L01_004C3660 (division moved to its own line) match on PAL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ps2eeas measures the distance to the barrier after its own padding: retail has `nop nop div.s div.s` 20 times and `nop nop div.s nop div.s` never, and on ps2eeas a label followed by two div.s pads only the first. Rule 4 now adds the nops it gave earlier ops between the barrier and the current one to the distance. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
move_sites() dropped the pending mtc1/li.s register at any directive, so `li.s; .p2align 3; $Lloop: <reader>` -- a form retail has -- counted one site fewer in the source than in the object and the tool refused the file. Alignment emits nothing there; when it does pad, the object has no adjacent pair and the counts still disagree, so the tool keeps refusing rather than guessing. A full build gives the same .text in all 9471 objects. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rabbitizer's R5900 table has no sqrt.s: it decodes a word such as
0x46000104 (sqrt.s $f4,$f0) as a bare `c1`. The object side of rule 4 then
saw one DIV op fewer than the source and refused the file ("object has 1 DIV
ops, source has 2"). Such a word is now decoded again with the plain MIPS
table. A test covers a sqrt.s after a label; it fails without the change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ByteMatch progress reportSCUS_974.65
No function changes. SCES_532.85
No function changes. Commit 15cca03 · Ratchet: Deadlocked on ByteMatch |
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.
Explains the nops retail has before
div.s(the "Not explained yet" paragraph ofdocs/build/toolchain.md) and reproduces them for files that opt in with/* cflags: @divpad */. No existing file changes: with this branch's tools, all 9358 objects of a full build have the same.textas with main's tools.What ps2eeas does
Measured on
Ps2EeAs.exe1.9.25 (SN 3.01 mirror), on an x86 machine, with-Wdivbug-on, which prints a warning for every pad:div.s,sqrt.s,rsqrt.s,vdiv,vsqrtandvrsqrt. It does not paddiv,divu,div1,mult,mul.sormadd.s.b,beq…,bal,bc1*, the likely forms; notj,jr,jal,jalr) gets 2 minus that distance nops. The kind of instructions in between does not matter.-divbug-onis rejected as an unknown option; the baredivbug-onstring in the binary is probably what the parser compares after-W.tools/ps2eeas_nops.pyis probably a stack overflow. The PE header reserves 1 MiB of stack, and a copy with a 256 MiB reserve assembles the inputs that crashed it under Wine.Where the labels come from:
-gMost of retail's padded
div.shave no label or branch near them in the compiler's output. They do with-g: GCC then writes a line label ($LM<n>:) at the start of every source line. Retail was compiled with-gthere and stripped afterwards, so adiv.sthat starts a source line has two nops, and one inside a line has none.This also explains the old statistics (the nops look as if they depended on what writes the operands): what decides is whether the
div.sstarts a source line.-gdoes not change the code: a full build with and without it has the same.textin all 8687 compared objects.Changes
tools/ps2eeas_nops.py:--div), measured in the first-pass object like rules 1–3.cc.shnow assembles that object with-Wa,-L, so the compiler's local labels are in its symbol table; the output object is unchanged.sqrt.s(it decodes0x46000104as a barec1), so rule 4 decodes such a word again with the plain MIPS table. Without this, a file whose source has asqrt.swas refused ("object has 1 DIV ops, source has 2").mtc1hazard when a.stabnline, or a loop label's.p2align(a form retail has:li.s; .p2align 3; $Lloop: <reader>), sits between the two instructions. Before, such a file was refused ("refusing to guess"). If the alignment does pad, the object has no adjacent pair and the tool still refuses.tools/ps2eeas_stabs.py(new): drops-g's.stabs/.stabn/.stabddirectives and keeps the labels, so objects carry no debug sections.tools/cc.sh: the@divpadcflags token compiles with-g, runsps2eeas_stabs.pyand passes--div. It works like@lit4.tools/test_ps2eeas_nops.py: five tests: label thendiv.sgives 2 nops, branch and one instruction thendiv.sgives 1, further away gives 0; the nops already inserted count (label,div.s,div.spads only the first, as ps2eeas does and as retail's 20nop nop div.s div.sshow); the rule is opt-in; stabs lines do not hide anmtc1hazard. A fifth covers asqrt.safter a label.docs/build/toolchain.md: the paragraph now explains the nops and how to use@divpad.Why opt-in
Retail is not uniform.
func_L00_00590698starts with a barediv.s, which ps2eeas would have padded whatever the source layout.func_004A9CE0's matched C would get two nops it does not have, because its division is on its own line. Applied to every file, the rule would break at least these two of the 58 objects that contain a DIV op.Checks
python -m unittest test_ps2eeas_nops(fromtools/): 12 tests pass.tools/build.shon x86: 9358 objects,.textidentical to main's tools, norefusing to guess. Rechecked after the.p2alignchange on a tree with my match PR's files and the isolated profiles installed: 9471 objects, same.text.@divpad, four PAL near misses match incheck_func.py --version pal:func_00502B10,func_L00_006D57A0,func_L00_0077FA58, andfunc_L01_004C3660with its division on its own line. They are in my match PR, which builds on this one.match_map.py --writeneeds the US dump, so there was no map-wide comparison. The object-level.textcomparison above covers the "no change without@divpad" claim.🤖 Generated with Claude Code