Skip to content

Conversation

SuperSamus
Copy link
Contributor

DEC uses one less byte than SUB.
The only difference is that it doesn't affect the carry flag, which doesn't matter since it's the zero flag that is checked.

Tested in the disassembler that DEC is indeed used (and uses 6 bytes instead of 7), and tested that some games work.

I guess that INC and DEC could be used for PPC's add and sub too if the second argument is the immediate 1... but maybe Dolphin has some optimizations I don't know about that involve merging it with a conditional jump that uses the carry flag somewhere. I'm not risking it.

DEC uses one less byte than SUB.
The only difference is that it doesn't affect the carry flag, which doesn't matter since it's the zero flag that is checked.
@JosJuice
Copy link
Member

JosJuice commented Oct 8, 2025

I guess that INC and DEC could be used for PPC's add and sub too if the second argument is the immediate 1... but maybe Dolphin has some optimizations I don't know about that involve merging it with a conditional jump that uses the carry flag somewhere. I'm not risking it.

There are such optimizations. You can spot them by CanMergeNextInstructions being called. But look carefully, because instructions can call CanMergeNextInstructions through other helper functions, such as FinalizeCarry. Probably best left for another PR if you want to do it, though.

@Tilka
Copy link
Member

Tilka commented Oct 9, 2025

Check perf. Idk about current CPUs but in the past it made sense to avoid inc/dec because of the partial flag update.

@SuperSamus
Copy link
Contributor Author

Check perf

Tested the same scene as #13932 (not applied), but it's really hard to see a difference.
Even loading from the same save state on the same build, the performance isn't consistent.
Still, I did see the same random "highs" and "lows" from both master and PR, so it doesn't seem like dec is worse.

Idk about current CPUs but in the past it made sense to avoid inc/dec because of the partial flag update.

Compilers nowadays use dec for loop counters.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants