mac static method

(Uint64, Uint64) mac(
  1. Uint64 a,
  2. Uint64 b,
  3. Uint64 c,
  4. Uint64 carry,
)

Multiply-accumulate: a + b*c + carry as a full 128-bit value. Returns (result, carryOut) — the standard building block of Comba multiplication / Montgomery reduction inner loops.

Implementation

static (Uint64 result, Uint64 carryOut) mac(
  Uint64 a,
  Uint64 b,
  Uint64 c,
  Uint64 carry,
) {
  final (hi0, lo0) = widenMul(b, c);
  final lo1 = lo0 + a;
  final c1 = lo1 < lo0 ? Uint64.one : Uint64.zero;
  // final hi1 = hi0 + c1;
  final lo2 = lo1 + carry;
  final c2 = lo2 < lo1 ? Uint64.one : Uint64.zero;
  // final hi2 = hi1 + c2;
  return (lo2, hi0 + c1 + c2);
  // return (lo2, hi2);
}