Knuth 4.3.1, Algorithm M.
r = r (op) a * b r MUST NOT alias any of a or b.
The result is computed modulo r.len. When r.len >= a.len + b.len, no overflow occurs.
fn llmulacc(comptime op: AccOp, opt_allocator: ?Allocator, r: []Limb, a: []const Limb, b: []const Limb) void
fn llmulacc(comptime op: AccOp, opt_allocator: ?Allocator, r: []Limb, a: []const Limb, b: []const Limb) void {
assert(r.len >= a.len);
assert(r.len >= b.len);
assert(!slicesOverlap(r, a));
assert(!slicesOverlap(r, b));
// Order greatest first.
var x = a;
var y = b;
if (a.len < b.len) {
x = b;
y = a;
}
k_mul: {
if (y.len > 48) {
if (opt_allocator) |allocator| {
llmulaccKaratsuba(op, allocator, r, x, y) catch |err| switch (err) {
error.OutOfMemory => break :k_mul, // handled below
};
return;
}
}
}
llmulaccLong(op, r, x, y);
}