authorgravatar for der.teufel.mail@gmail.comKrzysztof Wolicki <der.teufel.mail@gmail.com> 2024-10-12 12:55:35+02:00
committergravatar for der.teufel.mail@gmail.comKrzysztof Wolicki <der.teufel.mail@gmail.com> 2024-10-12 12:55:35+02:00
logb1eaed6c8d439f5e5cbd69af5186af68f1e65e34
tree4e365a647602c8fca343fa56ecee3f4beb96a184
parent278eb06b988db69062d864632a24b444b2b45bc6

Remove packed_int_array usage from WasmPageAllocator and BigInt


2 files changed, 10 insertions(+), 13 deletions(-)

lib/std/heap/WasmPageAllocator.zig+4-6
...@@ -28,8 +28,6 @@ const PageStatus = enum(u1) {...@@ -28,8 +28,6 @@ const PageStatus = enum(u1) {
28const FreeBlock = struct {28const FreeBlock = struct {
29 data: []u128,29 data: []u128,
3030
31 const Io = std.packed_int_array.PackedIntIo(u1, .little);
32
33 fn totalPages(self: FreeBlock) usize {31 fn totalPages(self: FreeBlock) usize {
34 return self.data.len * 128;32 return self.data.len * 128;
35 }33 }
...@@ -39,15 +37,15 @@ const FreeBlock = struct {...@@ -39,15 +37,15 @@ const FreeBlock = struct {
39 }37 }
4038
41 fn getBit(self: FreeBlock, idx: usize) PageStatus {39 fn getBit(self: FreeBlock, idx: usize) PageStatus {
42 const bit_offset = 0;40 const bit = mem.readPackedInt(u1, mem.sliceAsBytes(self.data), 8 * idx, .little);
43 return @as(PageStatus, @enumFromInt(Io.get(mem.sliceAsBytes(self.data), idx, bit_offset)));41 return @as(PageStatus, @enumFromInt(bit));
44 }42 }
4543
46 fn setBits(self: FreeBlock, start_idx: usize, len: usize, val: PageStatus) void {44 fn setBits(self: FreeBlock, start_idx: usize, len: usize, val: PageStatus) void {
47 const bit_offset = 0;
48 var i: usize = 0;45 var i: usize = 0;
46 const bytes = mem.sliceAsBytes(self.data);
49 while (i < len) : (i += 1) {47 while (i < len) : (i += 1) {
50 Io.set(mem.sliceAsBytes(self.data), start_idx + i, bit_offset, @intFromEnum(val));48 mem.writePackedInt(u1, bytes, 8 * (start_idx + i), @intFromEnum(val), .little);
51 }49 }
52 }50 }
5351
lib/std/math/big/int.zig+6-7
...@@ -795,7 +795,6 @@ pub const Mutable = struct {...@@ -795,7 +795,6 @@ pub const Mutable = struct {
795 const endian_mask: usize = (@sizeOf(Limb) - 1) << 3;795 const endian_mask: usize = (@sizeOf(Limb) - 1) << 3;
796796
797 const bytes = std.mem.sliceAsBytes(r.limbs);797 const bytes = std.mem.sliceAsBytes(r.limbs);
798 var bits = std.packed_int_array.PackedIntSliceEndian(u1, .little).init(bytes, limbs_required * @bitSizeOf(Limb));
799798
800 var k: usize = 0;799 var k: usize = 0;
801 while (k < ((bit_count + 1) / 2)) : (k += 1) {800 while (k < ((bit_count + 1) / 2)) : (k += 1) {
...@@ -809,17 +808,17 @@ pub const Mutable = struct {...@@ -809,17 +808,17 @@ pub const Mutable = struct {
809 rev_i ^= endian_mask;808 rev_i ^= endian_mask;
810 }809 }
811810
812 const bit_i = bits.get(i);811 const bit_i = std.mem.readPackedInt(u1, bytes, i, .little);
813 const bit_rev_i = bits.get(rev_i);812 const bit_rev_i = std.mem.readPackedInt(u1, bytes, rev_i, .little);
814 bits.set(i, bit_rev_i);813 std.mem.writePackedInt(u1, bytes, i, bit_rev_i, .little);
815 bits.set(rev_i, bit_i);814 std.mem.writePackedInt(u1, bytes, rev_i, bit_i, .little);
816 }815 }
817816
818 // Calculate signed-magnitude representation for output817 // Calculate signed-magnitude representation for output
819 if (signedness == .signed) {818 if (signedness == .signed) {
820 const last_bit = switch (native_endian) {819 const last_bit = switch (native_endian) {
821 .little => bits.get(bit_count - 1),820 .little => std.mem.readPackedInt(u1, bytes, bit_count - 1, .little),
822 .big => bits.get((bit_count - 1) ^ endian_mask),821 .big => std.mem.readPackedInt(u1, bytes, (bit_count - 1) ^ endian_mask, .little),
823 };822 };
824 if (last_bit == 1) {823 if (last_bit == 1) {
825 r.bitNotWrap(r.toConst(), .unsigned, bit_count); // Bitwise NOT.824 r.bitNotWrap(r.toConst(), .unsigned, bit_count); // Bitwise NOT.