Skip to content

[SPU LLVM] Refactor SELB to improve readability - #19002

Merged
elad335 merged 2 commits into
RPCS3:masterfrom
WalterKruger:selb-refactor
Jul 10, 2026
Merged

elad335 merged 2 commits into
RPCS3:masterfrom
WalterKruger:selb-refactor

Conversation

@WalterKruger

Copy link
Copy Markdown
Contributor

The current SELB implementation is difficult to understand due to its "division accuracy correction" pattern match being implemented using nested if statements for every match element. This patch replaces it with a equivalent version that reduces nesting, adds more clarifying comments, and uses more descriptive variable names.

Also, replaced the duplicated granularity check loops with single loop which determines its byte granularity as an integer. I removed the integer width specific selects with a single 8-bit select as LLVM should be able to widen when needed (as the condition is a constant).

Refactors SELB by changing "division accuracy correction" pattern match to reduce nesting, include more comments, and use more descriptive variable names. Also replaced duplicated granularity-check loops with single loop which determines byte granularity as a integer.

@arshkumarsingh arshkumarsingh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tested with LLVM 19.1.7: the new 8-bit select path generates the same asm as the old 16-bit path for word masks (pblendw/vpblendw), so yeah this looks fine

@elad335
elad335 self-requested a review July 7, 2026 16:51
@elad335
elad335 enabled auto-merge (rebase) July 10, 2026 16:12
set_vr(op.rt4, select(noncast<s32[4]>(c) != 0, get_vr<f32[4]>(op.rb), get_vr<f32[4]>(op.ra)));
return;
// Fraction of 16 check
byte_granularity = (16 % equals_run) ? 1 : std::min(byte_granularity, equals_run);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice simple algorithm, I believe SHUFB masks analysis can also be simplified using this method.

@elad335
elad335 merged commit 700ca26 into RPCS3:master Jul 10, 2026
10 checks passed
@RPCS3 RPCS3 deleted a comment from rahimibanon1103-eng Jul 11, 2026
@WalterKruger
WalterKruger deleted the selb-refactor branch July 16, 2026 11:13
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.

3 participants