Repository navigation
Conversation
Collaborator
|
In my experiments this helped with many use cases but regressed a few. I'll investigate this in more detail later this week hopefully. |
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.
Fixes mypyc/mypyc#1254.
CPyTagged_IsMultiplyOverflow()compared the tagged operands with unsigned comparisons, so every negative short int looked too big.x * ywith a negative operand always boxed both operands and calledPyNumber_Multiply(), which is more than 10 times slower than the inline multiplication.Now each tagged operand has to fit in a signed integer of half the width of
CPyTagged(int32_ton 64-bit platforms,int16_ton 32-bit ones), checked with a round trip through that type. Non-negative operands have the same limit as before, and negative operands get the same magnitudes. For two such operands the tagged product2a * bhas|2ab| <= 2**(N-3), where N is the number of bits inCPyTagged, so it can't overflow and it's a valid short int.Negative operands never reached the inline multiplication before, so the new run test multiplies every combination of signs and magnitudes around the limits on 32-bit and 64-bit platforms (214 and 230 for the inline multiplication, 230 and 262 for short ints). It does that with two variable operands, and with constant operands, where the C compiler folds the check of the constant.
Performance
Compiled loops with 10**6 iterations:
total += i * k,k = -3total += i * -3total += i * k,k = 3total += i * 3