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