Skip to content

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