Optimize Skipping of 0-bits In mulmuladd #50
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When investigating the
mulmuladd
issue, I noticed that at the start of the function, we have a loop to skipindex
for leading 0s in bothu
andv
.Currently, it was computing the a value
0bXY
(whereX
bit being set indicates thatv{index}
is set, andY
bit indicates thatu{index}
is set) and storing it to a temporary variable (T4
) for checking if the leading bit was 0 or not. This PR changes the logic to store it directly to thezz
variable instead of having it be recomputed after the loop finishes.At first, this was implemented by changing the condition of the loop to "is either
v{index}
oru{index}
set?" but computingzz
directly should be slightly better on average (if we assume even bit distribution, there is only a 25% chance this will save gas).Also,
eq(X, 0) -> iszero(X)
for slightly smaller code and less gas used.What is the best way to benchmark the difference?