mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
math.big: stronger asserts to reduce risks of aliasing
This commit is contained in:
parent
c785964cd0
commit
f13ee9a68c
1 changed files with 7 additions and 0 deletions
|
|
@ -3632,6 +3632,7 @@ fn llmulaccKaratsuba(
|
|||
/// r = r (op) a.
|
||||
/// The result is computed modulo `r.len`.
|
||||
fn llaccum(comptime op: AccOp, r: []Limb, a: []const Limb) void {
|
||||
assert(!slicesOverlap(r, a) or @intFromPtr(r.ptr) <= @intFromPtr(a.ptr));
|
||||
if (op == .sub) {
|
||||
_ = llsubcarry(r, r, a);
|
||||
return;
|
||||
|
|
@ -3701,6 +3702,8 @@ fn llmulaccLong(comptime op: AccOp, r: []Limb, a: []const Limb, b: []const Limb)
|
|||
/// The result is computed modulo `r.len`.
|
||||
/// Returns whether the operation overflowed.
|
||||
fn llmulLimb(comptime op: AccOp, acc: []Limb, y: []const Limb, xi: Limb) bool {
|
||||
assert(!slicesOverlap(acc, y) or @intFromPtr(acc.ptr) <= @intFromPtr(y.ptr));
|
||||
|
||||
if (xi == 0) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -3763,6 +3766,8 @@ fn llsubcarry(r: []Limb, a: []const Limb, b: []const Limb) Limb {
|
|||
assert(a.len != 0 and b.len != 0);
|
||||
assert(a.len >= b.len);
|
||||
assert(r.len >= a.len);
|
||||
assert(!slicesOverlap(r, a) or @intFromPtr(r.ptr) <= @intFromPtr(a.ptr));
|
||||
assert(!slicesOverlap(r, b) or @intFromPtr(r.ptr) <= @intFromPtr(b.ptr));
|
||||
|
||||
var i: usize = 0;
|
||||
var borrow: Limb = 0;
|
||||
|
|
@ -3794,6 +3799,8 @@ fn lladdcarry(r: []Limb, a: []const Limb, b: []const Limb) Limb {
|
|||
assert(a.len != 0 and b.len != 0);
|
||||
assert(a.len >= b.len);
|
||||
assert(r.len >= a.len);
|
||||
assert(!slicesOverlap(r, a) or @intFromPtr(r.ptr) <= @intFromPtr(a.ptr));
|
||||
assert(!slicesOverlap(r, b) or @intFromPtr(r.ptr) <= @intFromPtr(b.ptr));
|
||||
|
||||
var i: usize = 0;
|
||||
var carry: Limb = 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue