-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimize DivRem #1173
optimize DivRem #1173
Conversation
@Hecate2 please fix conflict |
methodConvert.Push(2); | ||
methodConvert.AddInstruction(OpCode.PICK);// r, l, l, r | ||
methodConvert.AddInstruction(OpCode.DIV); // r, l, l/r | ||
// TODO: for types that is restricted by range, check l/r <= MaxValue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you going to work on this todo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. I think we can just allow overflow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this be the same as C# behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, but only when DivRem(int.MinValue, -1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then can you please explain this as comment where others can learn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then can you please explain this as comment where others can learn.
Done
…to fix-divRem # Conflicts: # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Integer.cs
Using MOD instead of l-l/r*r
Original implementation check and throw when the remainder overflows. However it is impossible for the remainder to overflow, because
Therefore I cancelled the check.
But it is possible for the quotient to overflow in a single case, when the allowed range is [-128, 127] and I call DivRem(-128, -1). I did not check and throw in this case, because it is rare and expensive, and the original implementation did not check it.