authorgravatar for git.litmus427@passinbox.comunplanned <git.litmus427@passinbox.com> 2025-12-04 01:05:17+01:00
committergravatar for git.litmus427@passinbox.comunplanned <git.litmus427@passinbox.com> 2025-12-04 10:28:42+01:00
log688af047255790d9aec4a1152eaa525f7dd5b46d
tree11c42abfc8f133dd6072e0ab084d9a5e0dd8c233
parent73e82332d02e42a8b95f5c30652d4b7d0db7bea6

math.big: stronger asserts to reduce risks of aliasing


1 files changed, 7 insertions(+), 0 deletions(-)

lib/std/math/big/int.zig+7
......@@ -3630,6 +3630,7 @@ fn llmulaccKaratsuba(
36303630/// r = r (op) a.
36313631/// The result is computed modulo `r.len`.
36323632fn llaccum(comptime op: AccOp, r: []Limb, a: []const Limb) void {
3633 assert(!slicesOverlap(r, a) or @intFromPtr(r.ptr) <= @intFromPtr(a.ptr));
36333634 if (op == .sub) {
36343635 _ = llsubcarry(r, r, a);
36353636 return;
......@@ -3699,6 +3700,8 @@ fn llmulaccLong(comptime op: AccOp, r: []Limb, a: []const Limb, b: []const Limb)
36993700/// The result is computed modulo `r.len`.
37003701/// Returns whether the operation overflowed.
37013702fn llmulLimb(comptime op: AccOp, acc: []Limb, y: []const Limb, xi: Limb) bool {
3703 assert(!slicesOverlap(acc, y) or @intFromPtr(acc.ptr) <= @intFromPtr(y.ptr));
3704
37023705 if (xi == 0) {
37033706 return false;
37043707 }
......@@ -3761,6 +3764,8 @@ fn llsubcarry(r: []Limb, a: []const Limb, b: []const Limb) Limb {
37613764 assert(a.len != 0 and b.len != 0);
37623765 assert(a.len >= b.len);
37633766 assert(r.len >= a.len);
3767 assert(!slicesOverlap(r, a) or @intFromPtr(r.ptr) <= @intFromPtr(a.ptr));
3768 assert(!slicesOverlap(r, b) or @intFromPtr(r.ptr) <= @intFromPtr(b.ptr));
37643769
37653770 var i: usize = 0;
37663771 var borrow: Limb = 0;
......@@ -3792,6 +3797,8 @@ fn lladdcarry(r: []Limb, a: []const Limb, b: []const Limb) Limb {
37923797 assert(a.len != 0 and b.len != 0);
37933798 assert(a.len >= b.len);
37943799 assert(r.len >= a.len);
3800 assert(!slicesOverlap(r, a) or @intFromPtr(r.ptr) <= @intFromPtr(a.ptr));
3801 assert(!slicesOverlap(r, b) or @intFromPtr(r.ptr) <= @intFromPtr(b.ptr));
37953802
37963803 var i: usize = 0;
37973804 var carry: Limb = 0;