Skip to content

SPU LLVM: Recognize ROTYQBYI and ROTQBI rotation pattern - #16409

Merged
elad335 merged 4 commits into
RPCS3:masterfrom
Whatcookie:SPU2
Dec 22, 2024
Merged

SPU LLVM: Recognize ROTYQBYI and ROTQBI rotation pattern#16409
elad335 merged 4 commits into
RPCS3:masterfrom
Whatcookie:SPU2

Conversation

@Whatcookie

Copy link
Copy Markdown
Member

ROTQBYBI shifts a vector by bytes, and ROTQBI shifts a vector by bits. We can recognize this pattern and shift by bytes and bits at the same time. Turns into just 1 instruction with AVX-512 (VPSHRDVD), but the AVX2 solution is also faster than before as well.

AVX-512
Before:
image

After:
image

AVX2
Before:
image

After:
image

@Megamouse Megamouse added CPU Optimization Optimizes existing code labels Dec 16, 2024
@digant73

Copy link
Copy Markdown
Contributor

do you have some stats about the improvements compared to current implementation?

@Whatcookie

Copy link
Copy Markdown
Member Author

do you have some stats about the improvements compared to current implementation?

It's not going to be a large improvement overall. I found the pattern while looking at hotspots in Dark Souls. Maybe some game benefits a lot.

Comment thread rpcs3/Emu/Cell/SPULLVMRecompiler.cpp Outdated
{
const auto b32 = get_vr<s32[4]>(op.rb);
// Is the rotate less than 31 bits?
if (auto k = get_known_bits(b32); !!(k.Zero & 0x60))

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.

It was checking for any of them being 0 which is wrong.

Suggested change
if (auto k = get_known_bits(b32); !!(k.Zero & 0x60))
if (auto k = get_known_bits(b32); (~k.Zero & 0x60) == 0)

@elad335
elad335 merged commit 3857106 into RPCS3:master Dec 22, 2024
@Augusto7743

This comment was marked as off-topic.

@Hamof1

This comment was marked as off-topic.

@RPCS3 RPCS3 locked as off-topic and limited conversation to collaborators Dec 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

CPU Optimization Optimizes existing code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants