Skip to content

Commit

Permalink
Reduce stack operations in mulDiv
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed Jul 31, 2023
1 parent d6b63a4 commit 65033cc
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions contracts/utils/math/Math.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,10 @@ library Math {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}

Expand Down

0 comments on commit 65033cc

Please sign in to comment.