@@ -1477,10 +1477,10 @@ library Lib512MathArithmetic {
14771477 // Extract the upper 6 bits of `M` to be used as a table index. `M >> 250 < 16` is
14781478 // invalid (that would imply M<½), so our lookup table only needs to handle only 16
14791479 // through 63.
1480- let i := shr (0xfa , M)
1480+ let Mbucket := shr (0xfa , M)
14811481 // We can't fit 48 seeds into a single word, so we split the table in 2 and use `c`
14821482 // to select which table we index.
1483- let c := lt (0x27 , i )
1483+ let c := lt (0x27 , Mbucket )
14841484
14851485 // Each entry is 10 bits and the entries are ordered from lowest `i` to
14861486 // highest. The seed is the value for `Y` for the midpoint of the bucket, rounded
@@ -1490,13 +1490,13 @@ library Lib512MathArithmetic {
14901490 let table := xor (table_hi, mul (xor (table_lo, table_hi), c))
14911491
14921492 // Index the table to obtain the initial seed of `Y`.
1493- let shift := add (0x186 , mul (0x0a , sub (mul (0x18 , c), i )))
1494- // We begin the Newton-Raphson iteraitons with `Y` in Q247.9 format.
1493+ let shift := add (0x186 , mul (0x0a , sub (mul (0x18 , c), Mbucket )))
1494+ // We begin the Newton-Raphson iterations with `Y` in Q247.9 format.
14951495 Y := and (0x3ff , shr (shift, table))
14961496
1497- // The worst-case seed for `Y` occurs when `i = 16`. For monotone quadratic
1497+ // The worst-case seed for `Y` occurs when `Mbucket = 16`. For monotone quadratic
14981498 // convergence, we desire that 1/√3 < Y·√M < √(5/3). At the boundaries (worst case)
1499- // of the `i = 16` bucket , we are 0.407351 (41.3680%) from the lower bound and
1499+ // of the `Mbucket = 16` range , we are 0.407351 (41.3680%) from the lower bound and
15001500 // 0.275987 (27.1906%) from the higher bound.
15011501 }
15021502
@@ -1539,18 +1539,18 @@ library Lib512MathArithmetic {
15391539 // For small `e` (lower values of `x`), we can skip the 5th N-R iteration. The
15401540 // correct bits that this iteration would obtain are shifted away during the
15411541 // denormalization step. This branch is net gas-optimizing.
1542- uint256 Y2 = Y * Y; // scale: 2²⁵⁴
1543- uint256 MY2 = _inaccurateMulHi (M, Y2); // scale: 2²⁵⁴
1544- uint256 T = 1.5 * 2 ** 254 - MY2; // scale: 2²⁵⁴
1545- Y = _inaccurateMulHi (Y << 2 , T); // scale: 2¹²⁷
1542+ uint256 Y2 = Y * Y; // scale: 2²⁵⁴
1543+ uint256 MY2 = _inaccurateMulHi (M, Y2); // scale: 2²⁵⁴
1544+ uint256 T = 1.5 * 2 ** 254 - MY2; // scale: 2²⁵⁴
1545+ Y = _inaccurateMulHi (Y << 2 , T); // scale: 2¹²⁷
15461546 }
15471547 // `Y` is Q129.127
15481548 {
1549- uint256 Y2 = Y * Y; // scale: 2²⁵⁴
1550- uint256 MY2 = _inaccurateMulHi (M, Y2); // scale: 2²⁵⁴
1551- uint256 T = 1.5 * 2 ** 254 - MY2; // scale: 2²⁵⁴
1552- Y = _inaccurateMulHi (Y << 128 , T); // scale: 2²⁵³
1553- Y <<= 2 ; // scale: 2²⁵⁵ (Q1.255 format; effectively Q1.253)
1549+ uint256 Y2 = Y * Y; // scale: 2²⁵⁴
1550+ uint256 MY2 = _inaccurateMulHi (M, Y2); // scale: 2²⁵⁴
1551+ uint256 T = 1.5 * 2 ** 254 - MY2; // scale: 2²⁵⁴
1552+ Y = _inaccurateMulHi (Y << 128 , T); // scale: 2²⁵³
1553+ Y <<= 2 ; // scale: 2²⁵⁵ (Q1.255 format; effectively Q1.253)
15541554 }
15551555 // `Y` is Q1.255
15561556
0 commit comments