authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-10-04 03:54:13+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-10-04 11:25:29+02:00
loga1e02f33adab3ecdc85a321c4ff9c05762622c40
tree481f3dbaf2a43b133dcf258b55dfffb125aeec01
parent3dc47b8161f681baef2be776056fa9cc23a8811d

fmt


1 files changed, 12 insertions(+), 13 deletions(-)

lib/std/math/big/int.zig+12-13
...@@ -329,7 +329,7 @@ pub const Mutable = struct {...@@ -329,7 +329,7 @@ pub const Mutable = struct {
329 r: *Mutable,329 r: *Mutable,
330 limit: TwosCompIntLimit,330 limit: TwosCompIntLimit,
331 signedness: std.builtin.Signedness,331 signedness: std.builtin.Signedness,
332 bit_count: usize332 bit_count: usize,
333 ) void {333 ) void {
334 // Handle zero-bit types.334 // Handle zero-bit types.
335 if (bit_count == 0) {335 if (bit_count == 0) {
...@@ -340,7 +340,7 @@ pub const Mutable = struct {...@@ -340,7 +340,7 @@ pub const Mutable = struct {
340 const req_limbs = calcTwosCompLimbCount(bit_count);340 const req_limbs = calcTwosCompLimbCount(bit_count);
341 const bit = @truncate(Log2Limb, bit_count - 1);341 const bit = @truncate(Log2Limb, bit_count - 1);
342 const signmask = @as(Limb, 1) << bit; // 0b0..010..0 where 1 is the sign bit.342 const signmask = @as(Limb, 1) << bit; // 0b0..010..0 where 1 is the sign bit.
343 const mask = (signmask << 1) -% 1; // 0b0..011..1 where the leftmost 1 is the sign bit.343 const mask = (signmask << 1) -% 1; // 0b0..011..1 where the leftmost 1 is the sign bit.
344344
345 r.positive = true;345 r.positive = true;
346346
...@@ -349,7 +349,7 @@ pub const Mutable = struct {...@@ -349,7 +349,7 @@ pub const Mutable = struct {
349 .min => {349 .min => {
350 // Negative bound, signed = -0x80.350 // Negative bound, signed = -0x80.
351 r.len = req_limbs;351 r.len = req_limbs;
352 mem.set(Limb, r.limbs[0..r.len - 1], 0);352 mem.set(Limb, r.limbs[0 .. r.len - 1], 0);
353 r.limbs[r.len - 1] = signmask;353 r.limbs[r.len - 1] = signmask;
354 r.positive = false;354 r.positive = false;
355 },355 },
...@@ -364,11 +364,11 @@ pub const Mutable = struct {...@@ -364,11 +364,11 @@ pub const Mutable = struct {
364 } else {364 } else {
365 const new_req_limbs = calcTwosCompLimbCount(bit_count - 1);365 const new_req_limbs = calcTwosCompLimbCount(bit_count - 1);
366 const msb = @truncate(Log2Limb, bit_count - 2);366 const msb = @truncate(Log2Limb, bit_count - 2);
367 const new_signmask = @as(Limb, 1) << msb; // 0b0..010..0 where 1 is the sign bit.367 const new_signmask = @as(Limb, 1) << msb; // 0b0..010..0 where 1 is the sign bit.
368 const new_mask = (new_signmask << 1) -% 1; // 0b0..001..1 where the rightmost 0 is the sign bit.368 const new_mask = (new_signmask << 1) -% 1; // 0b0..001..1 where the rightmost 0 is the sign bit.
369369
370 r.len = new_req_limbs;370 r.len = new_req_limbs;
371 std.mem.set(Limb, r.limbs[0..r.len - 1], maxInt(Limb));371 std.mem.set(Limb, r.limbs[0 .. r.len - 1], maxInt(Limb));
372 r.limbs[r.len - 1] = new_mask;372 r.limbs[r.len - 1] = new_mask;
373 }373 }
374 },374 },
...@@ -381,7 +381,7 @@ pub const Mutable = struct {...@@ -381,7 +381,7 @@ pub const Mutable = struct {
381 .max => {381 .max => {
382 // Max bound, unsigned = 0xFF382 // Max bound, unsigned = 0xFF
383 r.len = req_limbs;383 r.len = req_limbs;
384 std.mem.set(Limb, r.limbs[0..r.len - 1], maxInt(Limb));384 std.mem.set(Limb, r.limbs[0 .. r.len - 1], maxInt(Limb));
385 r.limbs[r.len - 1] = mask;385 r.limbs[r.len - 1] = mask;
386 },386 },
387 },387 },
...@@ -2052,7 +2052,7 @@ pub const Managed = struct {...@@ -2052,7 +2052,7 @@ pub const Managed = struct {
2052 r: *Managed,2052 r: *Managed,
2053 limit: TwosCompIntLimit,2053 limit: TwosCompIntLimit,
2054 signedness: std.builtin.Signedness,2054 signedness: std.builtin.Signedness,
2055 bit_count: usize2055 bit_count: usize,
2056 ) !void {2056 ) !void {
2057 try r.ensureCapacity(calcTwosCompLimbCount(bit_count));2057 try r.ensureCapacity(calcTwosCompLimbCount(bit_count));
2058 var m = r.toMutable();2058 var m = r.toMutable();
...@@ -2599,14 +2599,14 @@ fn llmulaccKaratsuba(...@@ -2599,14 +2599,14 @@ fn llmulaccKaratsuba(
25992599
2600 mem.set(Limb, tmp[0..p2_limbs], 0);2600 mem.set(Limb, tmp[0..p2_limbs], 0);
2601 llmulacc(.add, allocator, tmp[0..p2_limbs], a1[0..math.min(a1.len, p2_limbs)], b1[0..math.min(b1.len, p2_limbs)]);2601 llmulacc(.add, allocator, tmp[0..p2_limbs], a1[0..math.min(a1.len, p2_limbs)], b1[0..math.min(b1.len, p2_limbs)]);
2602 const p2 = tmp[0 .. llnormalize(tmp[0..p2_limbs])];2602 const p2 = tmp[0..llnormalize(tmp[0..p2_limbs])];
26032603
2604 // Add p2 * B to the result.2604 // Add p2 * B to the result.
2605 llaccum(op, r[split..], p2);2605 llaccum(op, r[split..], p2);
26062606
2607 // Add p2 * B^2 to the result if required.2607 // Add p2 * B^2 to the result if required.
2608 if (limbs_after_split2 > 0) {2608 if (limbs_after_split2 > 0) {
2609 llaccum(op, r[split * 2..], p2[0..math.min(p2.len, limbs_after_split2)]);2609 llaccum(op, r[split * 2 ..], p2[0..math.min(p2.len, limbs_after_split2)]);
2610 }2610 }
26112611
2612 // Compute p0.2612 // Compute p0.
...@@ -2614,7 +2614,7 @@ fn llmulaccKaratsuba(...@@ -2614,7 +2614,7 @@ fn llmulaccKaratsuba(
2614 const p0_limbs = a0.len + b0.len;2614 const p0_limbs = a0.len + b0.len;
2615 mem.set(Limb, tmp[0..p0_limbs], 0);2615 mem.set(Limb, tmp[0..p0_limbs], 0);
2616 llmulacc(.add, allocator, tmp[0..p0_limbs], a0, b0);2616 llmulacc(.add, allocator, tmp[0..p0_limbs], a0, b0);
2617 const p0 = tmp[0 .. llnormalize(tmp[0..p0_limbs])];2617 const p0 = tmp[0..llnormalize(tmp[0..p0_limbs])];
26182618
2619 // Add p0 to the result.2619 // Add p0 to the result.
2620 llaccum(op, r, p0);2620 llaccum(op, r, p0);
...@@ -2622,7 +2622,6 @@ fn llmulaccKaratsuba(...@@ -2622,7 +2622,6 @@ fn llmulaccKaratsuba(
2622 // Add p0 * B to the result. In this case, we may not need all of it.2622 // Add p0 * B to the result. In this case, we may not need all of it.
2623 llaccum(op, r[split..], p0[0..math.min(limbs_after_split, p0.len)]);2623 llaccum(op, r[split..], p0[0..math.min(limbs_after_split, p0.len)]);
26242624
2625
2626 // Finally, compute and add p1.2625 // Finally, compute and add p1.
2627 // From now on we only need `limbs_after_split` limbs for a0 and b0, since the result of the2626 // From now on we only need `limbs_after_split` limbs for a0 and b0, since the result of the
2628 // following computation will be added * B.2627 // following computation will be added * B.
...@@ -2643,8 +2642,8 @@ fn llmulaccKaratsuba(...@@ -2643,8 +2642,8 @@ fn llmulaccKaratsuba(
2643 // Note that in this case, we again need some storage for intermediary results2642 // Note that in this case, we again need some storage for intermediary results
2644 // j0 and j1. Since we have tmp.len >= 2B, we can store both2643 // j0 and j1. Since we have tmp.len >= 2B, we can store both
2645 // intermediaries in the already allocated array.2644 // intermediaries in the already allocated array.
2646 const j0 = tmp[0..a.len - split];2645 const j0 = tmp[0 .. a.len - split];
2647 const j1 = tmp[a.len - split..];2646 const j1 = tmp[a.len - split ..];
26482647
2649 // Ensure that no subtraction overflows.2648 // Ensure that no subtraction overflows.
2650 if (j0_sign == 1) {2649 if (j0_sign == 1) {