Skip to content

Commit

Permalink
Merge pull request #21682 from der-teufel-programming/remove-packedin…
Browse files Browse the repository at this point in the history
…tarray

Remove PackedIntArray
  • Loading branch information
andrewrk authored Oct 14, 2024
2 parents ba569bb + 04c1822 commit 3bf89f5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 737 deletions.
44 changes: 22 additions & 22 deletions lib/compiler/aro/aro/Preprocessor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
try pp.ensureTotalTokenCapacity(pp.tokens.len + estimated_token_count);

var if_level: u8 = 0;
var if_kind = std.PackedIntArray(u2, 256).init([1]u2{0} ** 256);
var if_kind: [64]u8 = .{0} ** 64;
const until_else = 0;
const until_endif = 1;
const until_endif_seen_else = 2;
Expand Down Expand Up @@ -430,12 +430,12 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
if_level = sum;

if (try pp.expr(&tokenizer)) {
if_kind.set(if_level, until_endif);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif);
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #if", .{});
}
} else {
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #if", .{});
Expand All @@ -451,12 +451,12 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue;
try pp.expectNl(&tokenizer);
if (pp.defines.get(macro_name) != null) {
if_kind.set(if_level, until_endif);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif);
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #ifdef", .{});
}
} else {
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #ifdef", .{});
Expand All @@ -472,23 +472,23 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue;
try pp.expectNl(&tokenizer);
if (pp.defines.get(macro_name) == null) {
if_kind.set(if_level, until_endif);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif);
} else {
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
}
},
.keyword_elif => {
if (if_level == 0) {
try pp.err(directive, .elif_without_if);
if_level += 1;
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
} else if (if_level == 1) {
guard_name = null;
}
switch (if_kind.get(if_level)) {
switch (std.mem.readPackedIntNative(u2, &if_kind, if_level * 2)) {
until_else => if (try pp.expr(&tokenizer)) {
if_kind.set(if_level, until_endif);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif);
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #elif", .{});
}
Expand All @@ -510,28 +510,28 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
if (if_level == 0) {
try pp.err(directive, .elifdef_without_if);
if_level += 1;
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
} else if (if_level == 1) {
guard_name = null;
}
switch (if_kind.get(if_level)) {
switch (std.mem.readPackedIntNative(u2, &if_kind, if_level * 2)) {
until_else => {
const macro_name = try pp.expectMacroName(&tokenizer);
if (macro_name == null) {
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #elifdef", .{});
}
} else {
try pp.expectNl(&tokenizer);
if (pp.defines.get(macro_name.?) != null) {
if_kind.set(if_level, until_endif);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif);
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #elifdef", .{});
}
} else {
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #elifdef", .{});
Expand All @@ -551,28 +551,28 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
if (if_level == 0) {
try pp.err(directive, .elifdef_without_if);
if_level += 1;
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
} else if (if_level == 1) {
guard_name = null;
}
switch (if_kind.get(if_level)) {
switch (std.mem.readPackedIntNative(u2, &if_kind, if_level * 2)) {
until_else => {
const macro_name = try pp.expectMacroName(&tokenizer);
if (macro_name == null) {
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #elifndef", .{});
}
} else {
try pp.expectNl(&tokenizer);
if (pp.defines.get(macro_name.?) == null) {
if_kind.set(if_level, until_endif);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif);
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #elifndef", .{});
}
} else {
if_kind.set(if_level, until_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #elifndef", .{});
Expand All @@ -596,9 +596,9 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
} else if (if_level == 1) {
guard_name = null;
}
switch (if_kind.get(if_level)) {
switch (std.mem.readPackedIntNative(u2, &if_kind, if_level * 2)) {
until_else => {
if_kind.set(if_level, until_endif_seen_else);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif_seen_else);
if (pp.verbose) {
pp.verboseLog(directive, "#else branch here", .{});
}
Expand Down
10 changes: 4 additions & 6 deletions lib/std/heap/WasmPageAllocator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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), 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, start_idx + i, @intFromEnum(val), .little);
}
}

Expand Down
13 changes: 6 additions & 7 deletions lib/std/math/big/int.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.
Expand Down
Loading

0 comments on commit 3bf89f5

Please sign in to comment.