| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | 1 | const std = @import("../../std.zig"); |
| 2 | const builtin = @import("builtin"); |
| 2 | 3 | const mem = std.mem; |
| 3 | 4 | const testing = std.testing; |
| 4 | 5 | const Managed = std.math.big.int.Managed; |
| ... | ... | @@ -2123,6 +2124,33 @@ test "big.int bitNotWrap signed multi" { |
| 2123 | 2124 | try testing.expect((try a.to(SignedDoubleLimb)) == -1); |
| 2124 | 2125 | } |
| 2125 | 2126 | |
| 2127 | test "big.int bitNotWrap more than two limbs" { |
| 2128 | // This test requires int sizes greater than 128 bits. |
| 2129 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 2130 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO |
| 2131 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 2132 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 2133 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 2134 | // LLVM: unexpected runtime library name: __umodei4 |
| 2135 | if (builtin.zig_backend == .stage2_llvm and comptime builtin.target.isWasm()) return error.SkipZigTest; // TODO |
| 2136 | |
| 2137 | var a = try Managed.initSet(testing.allocator, maxInt(Limb)); |
| 2138 | defer a.deinit(); |
| 2139 | |
| 2140 | var res = try Managed.init(testing.allocator); |
| 2141 | defer res.deinit(); |
| 2142 | |
| 2143 | const bits = @bitSizeOf(Limb) * 4 + 2; |
| 2144 | |
| 2145 | try res.bitNotWrap(&a, .unsigned, bits); |
| 2146 | const Unsigned = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = bits } }); |
| 2147 | try testing.expectEqual((try res.to(Unsigned)), ~@as(Unsigned, maxInt(Limb))); |
| 2148 | |
| 2149 | try res.bitNotWrap(&a, .signed, bits); |
| 2150 | const Signed = @Type(.{ .Int = .{ .signedness = .signed, .bits = bits } }); |
| 2151 | try testing.expectEqual((try res.to(Signed)), ~@as(Signed, maxInt(Limb))); |
| 2152 | } |
| 2153 | |
| 2126 | 2154 | test "big.int bitwise and simple" { |
| 2127 | 2155 | var a = try Managed.initSet(testing.allocator, 0xffffffff11111111); |
| 2128 | 2156 | defer a.deinit(); |
| ... | ... | @@ -2655,11 +2683,10 @@ test "big int popcount" { |
| 2655 | 2683 | try popCountTest(&a, limb_size * 2 - 1, limb_size); |
| 2656 | 2684 | try popCountTest(&a, limb_size * 2, limb_size + 1); |
| 2657 | 2685 | try popCountTest(&a, limb_size * 2 + 1, limb_size + 2); |
| 2658 | | // TODO: These produce incorrect pop count for Mutable |
| 2659 | | // https://github.com/ziglang/zig/issues/13571 |
| 2660 | | // try popCountTest(&a, limb_size * 2 + 2, limb_size + 3); |
| 2661 | | // try popCountTest(&a, limb_size * 2 + 3, limb_size + 4); |
| 2662 | | // try popCountTest(&a, limb_size * 2 + 4, limb_size + 5); |
| 2686 | try popCountTest(&a, limb_size * 2 + 2, limb_size + 3); |
| 2687 | try popCountTest(&a, limb_size * 2 + 3, limb_size + 4); |
| 2688 | try popCountTest(&a, limb_size * 2 + 4, limb_size + 5); |
| 2689 | try popCountTest(&a, limb_size * 4 + 2, limb_size * 3 + 3); |
| 2663 | 2690 | } |
| 2664 | 2691 | |
| 2665 | 2692 | fn popCountTest(val: *const Managed, bit_count: usize, expected: usize) !void { |