optimize f_pow when base is int - #41
Open
GGrush-Doudizhu wants to merge 1 commit into
Open
Conversation
armoha
requested changes
Aug 5, 2026
armoha
left a comment
Owner
There was a problem hiding this comment.
Unlike _pow, this generates multiple triggers on every call sites.
(1) _pow(0, EUDVariable) case is uncommon and not that slow to avoid using it.
(2) pow(int, EUDVariable) branch has unnecessary copies.
When a is not a power of 2, _pow(odd_part, b) is called anyway. The cost of _pow(a, b) depends on the 1-bits in b so _pow(odd_part, b) has same cost as original _pow(a, b).
(3) When a is a power of 2, the _constmul (full 32 bits multiplication) + f_bitlshift replacement isn't clearly better than _pow. f_bitlshift(1, EUDVariable) is not specialized and it rather fallbacks to f_bitlshift(EUDVariable, EUDVariable)` in current implementation.
armoha
force-pushed
the
main
branch
3 times, most recently
from
August 29, 2026 01:56
c98c3c9 to
cc0caaa
Compare
armoha
force-pushed
the
main
branch
3 times, most recently
from
September 7, 2026 13:20
d8c2375 to
a99250d
Compare
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.
Optimize
f_powwhen the base isintand the exponent isEUDVariable.0and1.a**b = odd_part**b << (trailing_zeros * b)._powpath for unsupported cases.