| author | |
| committer | |
| log | 7cc0e6d4cd5d699d5377cf47ee27a2e089d046bf |
| tree | bacde8ab8eb49a46301c0ce3293a58166a99933b |
| parent | 4fac5bd601da12140586115dc9ddc6a92577ff6d |
| signature | Signed by PGP key B5690EEEBB952194 |
2 files changed, 19 insertions(+), 6 deletions(-)
lib/std/math/big/int.zig+6-6| ... | ... | @@ -3776,19 +3776,19 @@ fn llshr(r: []Limb, a: []const Limb, shift: usize) void { |
| 3776 | 3776 | const limb_shift = shift / limb_bits; |
| 3777 | 3777 | const interior_limb_shift = @as(Log2Limb, @truncate(shift)); |
| 3778 | 3778 | |
| 3779 | var carry: Limb = 0; | |
| 3780 | 3779 | var i: usize = 0; |
| 3781 | 3780 | while (i < a.len - limb_shift) : (i += 1) { |
| 3782 | const src_i = a.len - i - 1; | |
| 3783 | const dst_i = src_i - limb_shift; | |
| 3781 | const dst_i = i; | |
| 3782 | const src_i = dst_i + limb_shift; | |
| 3784 | 3783 | |
| 3785 | 3784 | const src_digit = a[src_i]; |
| 3786 | r[dst_i] = carry | (src_digit >> interior_limb_shift); | |
| 3787 | carry = @call(.always_inline, math.shl, .{ | |
| 3785 | const src_digit_next = if (src_i + 1 < a.len) a[src_i + 1] else 0; | |
| 3786 | const carry = @call(.always_inline, math.shl, .{ | |
| 3788 | 3787 | Limb, |
| 3789 | src_digit, | |
| 3788 | src_digit_next, | |
| 3790 | 3789 | limb_bits - @as(Limb, @intCast(interior_limb_shift)), |
| 3791 | 3790 | }); |
| 3791 | r[dst_i] = carry | (src_digit >> interior_limb_shift); | |
| 3792 | 3792 | } |
| 3793 | 3793 | } |
| 3794 | 3794 |
lib/std/math/big/int_test.zig+13| ... | ... | @@ -2019,6 +2019,19 @@ test "shift-right multi" { |
| 2019 | 2019 | try a.shiftRight(&a, 63); |
| 2020 | 2020 | try a.shiftRight(&a, 2); |
| 2021 | 2021 | try testing.expect(a.eqlZero()); |
| 2022 | ||
| 2023 | try a.set(0xffff0000eeee1111dddd2222cccc3333000000000000000000000); | |
| 2024 | try a.shiftRight(&a, 84); | |
| 2025 | const string = try a.toString( | |
| 2026 | testing.allocator, | |
| 2027 | 16, | |
| 2028 | .lower, | |
| 2029 | ); | |
| 2030 | defer testing.allocator.free(string); | |
| 2031 | try std.testing.expectEqualStrings( | |
| 2032 | string, | |
| 2033 | "ffff0000eeee1111dddd2222cccc3333", | |
| 2034 | ); | |
| 2022 | 2035 | } |
| 2023 | 2036 | |
| 2024 | 2037 | test "shift-left single" { |