From b1eaed6c8d439f5e5cbd69af5186af68f1e65e34 Mon Sep 17 00:00:00 2001 From: Krzysztof Wolicki Date: Sat, 12 Oct 2024 12:55:35 +0200 Subject: [PATCH] Remove packed_int_array usage from WasmPageAllocator and BigInt --- lib/std/heap/WasmPageAllocator.zig | 10 ++++------ lib/std/math/big/int.zig | 13 ++++++------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/std/heap/WasmPageAllocator.zig b/lib/std/heap/WasmPageAllocator.zig index 7cb85561d8..461b0f9fc5 100644 --- a/lib/std/heap/WasmPageAllocator.zig +++ b/lib/std/heap/WasmPageAllocator.zig @@ -28,8 +28,6 @@ const PageStatus = enum(u1) { const FreeBlock = struct { data: []u128, - const Io = std.packed_int_array.PackedIntIo(u1, .little); - fn totalPages(self: FreeBlock) usize { return self.data.len * 128; } @@ -39,15 +37,15 @@ const FreeBlock = struct { } fn getBit(self: FreeBlock, idx: usize) PageStatus { - const bit_offset = 0; - return @as(PageStatus, @enumFromInt(Io.get(mem.sliceAsBytes(self.data), idx, bit_offset))); + const bit = mem.readPackedInt(u1, mem.sliceAsBytes(self.data), 8 * idx, .little); + return @as(PageStatus, @enumFromInt(bit)); } fn setBits(self: FreeBlock, start_idx: usize, len: usize, val: PageStatus) void { - const bit_offset = 0; var i: usize = 0; + const bytes = mem.sliceAsBytes(self.data); while (i < len) : (i += 1) { - Io.set(mem.sliceAsBytes(self.data), start_idx + i, bit_offset, @intFromEnum(val)); + mem.writePackedInt(u1, bytes, 8 * (start_idx + i), @intFromEnum(val), .little); } } diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig index 2d38517661..691ae02280 100644 --- a/lib/std/math/big/int.zig +++ b/lib/std/math/big/int.zig @@ -795,7 +795,6 @@ pub const Mutable = struct { const endian_mask: usize = (@sizeOf(Limb) - 1) << 3; const bytes = std.mem.sliceAsBytes(r.limbs); - var bits = std.packed_int_array.PackedIntSliceEndian(u1, .little).init(bytes, limbs_required * @bitSizeOf(Limb)); var k: usize = 0; while (k < ((bit_count + 1) / 2)) : (k += 1) { @@ -809,17 +808,17 @@ pub const Mutable = struct { rev_i ^= endian_mask; } - const bit_i = bits.get(i); - const bit_rev_i = bits.get(rev_i); - bits.set(i, bit_rev_i); - bits.set(rev_i, bit_i); + const bit_i = std.mem.readPackedInt(u1, bytes, i, .little); + const bit_rev_i = std.mem.readPackedInt(u1, bytes, rev_i, .little); + std.mem.writePackedInt(u1, bytes, i, bit_rev_i, .little); + std.mem.writePackedInt(u1, bytes, rev_i, bit_i, .little); } // Calculate signed-magnitude representation for output if (signedness == .signed) { const last_bit = switch (native_endian) { - .little => bits.get(bit_count - 1), - .big => bits.get((bit_count - 1) ^ endian_mask), + .little => std.mem.readPackedInt(u1, bytes, bit_count - 1, .little), + .big => std.mem.readPackedInt(u1, bytes, (bit_count - 1) ^ endian_mask, .little), }; if (last_bit == 1) { r.bitNotWrap(r.toConst(), .unsigned, bit_count); // Bitwise NOT.