Skip to content
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 HandleMathClamp #1160

Merged
merged 6 commits into from
Sep 10, 2024
Merged

optimize HandleMathClamp #1160

merged 6 commits into from
Sep 10, 2024

Conversation

Hecate2
Copy link
Contributor

@Hecate2 Hecate2 commented Sep 5, 2024

It's not only a performance optimization. max == min should be allowed. This is the same as the behavior of C# https://github.com/dotnet/runtime/blob/5535e31a712343a63f5d7d796cd874e563e5ac14/src/libraries/System.Private.CoreLib/src/System/Math.cs#L636C13-L650C26

@Hecate2
Copy link
Contributor Author

Hecate2 commented Sep 5, 2024

OpCode.THROW also exists in many other files, mainly for checking value overflows.

@Hecate2 Hecate2 marked this pull request as draft September 5, 2024 07:56
@Jim8y
Copy link
Contributor

Jim8y commented Sep 5, 2024

you can disable the gasassert for this pr

methodConvert.AddInstruction(OpCode.DROP);
methodConvert.Jump(OpCode.JMP, endTarget);
endTarget.Instruction = methodConvert.AddInstruction(OpCode.NOP);
methodConvert.AddInstruction(OpCode.REVERSE3); // 10 0 5
Copy link
Contributor Author

@Hecate2 Hecate2 Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//We may not use MAX and MIN after REVERSE3 because it's more expensive. MAX&MIN costs 1<<3 each. See the commented codes for a cheaper but larger solution.

…to optimize-clamp

# Conflicts:
#	tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Integer.cs
#	tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Math.cs
@Hecate2 Hecate2 marked this pull request as ready for review September 9, 2024 01:48
@shargon shargon merged commit 17715fe into neo-project:master Sep 10, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants