A library of modern, hyper-optimized, and extensible Huff contracts with extensive testing and documentation built by Huff maintainers.
430
stars
55
forks
source link
Optimization (Trigonometry): remove unnecessary iszero iszero sequence #143
Open
joaonevess opened 4 weeks ago
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 anotheriszero
instruction. https://github.com/huff-language/huffmate/blob/4e2c9bd3412ab8cc65f6ceadafc01a1ff1815796/src/math/Trigonometry.huff#L155-L156Thus, 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.