Skip to content

Leave the code unchanged under -c, and comment every instruction. - #5

Merged
fjtrujy merged 1 commit into
ps2dev:masterfrom
glampert:fix/emit-source
Oct 20, 2026
Merged

fjtrujy merged 1 commit into
ps2dev:masterfrom
glampert:fix/emit-source

Conversation

@glampert

Copy link
Copy Markdown

-c writes each instruction's source line above it as a ; Line N: comment. It had two problems:

1. -c changed the program. The comments went into the same list as the code, ahead of each instruction's padding. padForBranchPreBubble looks at the previous line to decide whether a branch needs a bubble. Under -c it found the comment instead of the padding that was already there, and added another nop pair. Quake II's textured_triangles got 5 more nop pairs with -c than without, and each of those branches' comment sat above the extra nop:

 ; Line 40:     ibeq   iFormat, vi00, lStrideSet
                    nop                             nop
                    nop                             ibeq VI07, VI00, lStrideSet

2. Some instructions had no comment. Instructions emitted as an upper/lower pair, or with waitq/waitp, got none: 103 of the 1001 instruction lines in textured_triangles.

The comments now live in their own list, each with the index of the code line it goes above, and write() interleaves them. Code generation only ever sees code. Each instruction line gets the comments of the source instructions on it, after any padding: both halves of a pair (upper first), an instruction issued with waitq/waitp, and a branch and its delay-slot filler. Only openvcl's own nop/waitq/waitp padding has no comment:

 ; Line 22:     sub.x fMinusOne, vf00, vf00[w]
 ; Line 13:     lq fMVP0,      0(vi00)
                    subw.x VF08, VF00, VF00w        lq VF01, 0(VI00)

The two lines that the experimental OPENVCL_USE_GENERIC_KERNEL_REWRITE path pushes directly are left as they are, since that code is being reworked on the optimizations branch.

Testing

🤖 Co-authored by Claude Code

-c writes each instruction's source line above it as a `; Line N:`
comment. The comments went into the same list as the code, ahead of the
instruction's padding, and the check for a bubble already in place before
a branch (padForBranchPreBubble) looks at the previous line. It found the
comment instead of the padding and added another nop pair, so -c changed
the program: Quake II's textured_triangles got 5 more nop pairs with -c
than without, and each of those branches had its comment above the extra
nop. Instructions emitted as an upper/lower pair, or with waitq/waitp, got
no comment at all (103 of the 1001 instruction lines there).

The comments now live in their own list, each with the index of the code
line it goes above, and write() interleaves them, so code generation only
ever sees code. Each instruction line gets the comments of the source
instructions on it, after any padding: both halves of a pair (upper
first), an instruction issued with waitq/waitp, and a branch and its
delay-slot filler. Only openvcl's own nop/waitq/waitp padding is left
without one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@fjtrujy fjtrujy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!
Cheers

@fjtrujy
fjtrujy merged commit d1a91e2 into ps2dev:master Oct 20, 2026
5 checks passed
@glampert

Copy link
Copy Markdown
Author

No worries @fjtrujy.

By the way, I also have a local ASan/UBSan setup that found the uninitialized variable issue from #4. Is that something you think would be valuable to add to the project's CI? I could send a change just with that.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants