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

Optimization (Trigonometry): remove unnecessary iszero iszero sequence #143

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joaonevess
Copy link

We can save 6 gas units by simplifying the code.

Original definition:
is_negative_quadrant = iszero(iszero(QUADRANT_HIGH_MASK & angle))

This value is used only once, as a condition for a jumpi, after being consumed by another iszero instruction.

swap1 // [is_negative_quadrant, sine, interp, angle]
iszero cont jumpi // [sine, interp, angle]

Thus, the condition effectively becomes:
condition = iszero(iszero(iszero(QUADRANT_HIGH_MASK & angle)))
which simplifies to:
condition = iszero(QUADRANT_HIGH_MASK & angle)

This achieves the same logical outcome while reducing gas usage.

@joaonevess joaonevess closed this Jun 24, 2024
@joaonevess joaonevess deleted the optimization/trigonometry branch June 24, 2024 09:06
@joaonevess joaonevess restored the optimization/trigonometry branch June 24, 2024 09:39
@joaonevess joaonevess reopened this Jun 24, 2024
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.

1 participant