mul64 static method

(BigInt, BigInt) mul64(
  1. BigInt x,
  2. BigInt y
)

Mul64 returns the 128-bit product of x and y: (hi, lo) = x * y with the product bits' upper half returned in hi and the lower half returned in lo.

This function's execution time does not depend on the inputs.

Implementation

static (BigInt high, BigInt low) mul64(BigInt x, BigInt y) {
  final BigInt x0 = x & _mask32;
  final BigInt x1 = x >> 32;
  final BigInt y0 = y & _mask32;
  final BigInt y1 = y >> 32;
  final BigInt w0 = x0 * y0;
  final BigInt t = x1 * y0 + (w0 >> 32);
  BigInt w1 = t & _mask32;
  final BigInt w2 = t >> 32;
  w1 += x0 * y1;
  final BigInt high =
      ((x1 * y1) & BigInt.from(0xFFFFFFFFFFFFFFFF)) + w2 + ((w1 >> 32));
  final BigInt low = (x * y) & _mask64;
  return (high, low);
}