Skip to main content

Module mul_div

Module mul_div 

Source
Expand description

Recognition of the 512-bit product high word and of the full-precision mulDiv quotient.

Re-exportsยง

use super::*; ๐Ÿ”’

Constantsยง

MIN_NEWTON_STEPS ๐Ÿ”’
Newton steps that lift the (3 * d) ^ 2 seed, an inverse modulo 2**4, to 2**256.

Functionsยง

bool_word_condition ๐Ÿ”’
checked_product_guard_operands ๐Ÿ”’
Returns (x, y) when word is the overflow check x == 0 || (x * y) / x == y, which holds exactly when mul_high(x, y) == 0.
exact_product_parts ๐Ÿ”’
Returns (a, b) when low is a * b - r and high is mul_high(a, b) - lt(a * b, r) for r = mulmod(a, b, d).
exact_shifted_product_operands ๐Ÿ”’
Returns (a, b, d) when expr is the low word of (a * b - a * b % d) / twos: the exact low quotient (lo - rem) / twos joined with (high - borrow) * (2**256 / twos).
full_mul_div_operands ๐Ÿ”’
Returns (a, b, d) when expr is the 512-by-256-bit mulDiv(a, b, d) quotient.
is_increment_of ๐Ÿ”’
is_inverse_shift ๐Ÿ”’
Returns whether expr is (0 - twos) / twos + 1, which is 2**256 / twos modulo 2**256.
is_less_than ๐Ÿ”’
is_less_than_word ๐Ÿ”’
is_lowest_set_bit ๐Ÿ”’
Returns whether twos is (0 - d) & d, the lowest set bit of d.
is_mul_high_factor ๐Ÿ”’
is_mul_high_of ๐Ÿ”’
is_negation_of ๐Ÿ”’
is_product_of ๐Ÿ”’
mul_high_operands ๐Ÿ”’
Returns (a, b) when minuend - subtrahend is the high word of a * b.
newton_inverse_operand ๐Ÿ”’
Returns d when expr is at least MIN_NEWTON_STEPS of inv * (2 - d * inv) over the (3 * d) ^ 2 seed, the inverse of an odd d modulo 2**256.
normalize_mul_high_factor_cmp ๐Ÿ”’
Decides comparisons between mul_high(a, b) and one of its factors.
normalize_quotient_offset_eq ๐Ÿ”’
Rewrites q + c == k and !q == k for a word quotient q to q == k', where a division reaches MAX only as MAX / 1.
wide_product_operands ๐Ÿ”’
word_division_operands ๐Ÿ”’
Returns (n, d) for n / d, also in the ite(d == 0, 0, n / d) form of the EVM DIV.