mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
math.big: stronger asserts to reduce risks of aliasing
This commit is contained in:
parent
73e82332d0
commit
688af04725
1 changed files with 7 additions and 0 deletions
|
|
@ -3630,6 +3630,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;
|
||||
|
|
@ -3699,6 +3700,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;
|
||||
}
|
||||
|
|
@ -3761,6 +3764,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;
|
||||
|
|
@ -3792,6 +3797,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