authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-07 16:29:42-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:42:29-07:00
log2f9b7dc1023e9ff21574b559e22265db65e00d2d
treedf09a315169c8e9485057349ee4a007a9a2af2b8
parent4fe0c583be8890b1cb8059c2daff3bd82c53d2e9

InternPool: add an int_u8 value encoding

On a simple input file, this had a total savings of 21% in the InternPool: Before: int_positive: 427 occurrences, 8975 total bytes After: int_positive: 258 occurrences, 5426 total bytes int_u8: 169 occurrences, 845 total bytes

1 files changed, 24 insertions(+), 0 deletions(-)

src/InternPool.zig+24
......@@ -721,6 +721,9 @@ pub const Tag = enum(u8) {
721721 /// only an enum tag, but will be presented via the API with a different Key.
722722 /// data is SimpleInternal enum value.
723723 simple_internal,
724 /// Type: u8
725 /// data is integer value
726 int_u8,
724727 /// Type: u16
725728 /// data is integer value
726729 int_u16,
......@@ -1056,6 +1059,10 @@ pub fn indexToKey(ip: InternPool, index: Index) Key {
10561059 .type_error_union => @panic("TODO"),
10571060 .type_enum_simple => @panic("TODO"),
10581061 .simple_internal => @panic("TODO"),
1062 .int_u8 => .{ .int = .{
1063 .ty = .u8_type,
1064 .storage = .{ .u64 = data },
1065 } },
10591066 .int_u16 => .{ .int = .{
10601067 .ty = .u16_type,
10611068 .storage = .{ .u64 = data },
......@@ -1226,6 +1233,22 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
12261233 .int => |int| b: {
12271234 switch (int.ty) {
12281235 .none => unreachable,
1236 .u8_type => switch (int.storage) {
1237 .big_int => |big_int| {
1238 ip.items.appendAssumeCapacity(.{
1239 .tag = .int_u8,
1240 .data = big_int.to(u8) catch unreachable,
1241 });
1242 break :b;
1243 },
1244 inline .u64, .i64 => |x| {
1245 ip.items.appendAssumeCapacity(.{
1246 .tag = .int_u8,
1247 .data = @intCast(u8, x),
1248 });
1249 break :b;
1250 },
1251 },
12291252 .u16_type => switch (int.storage) {
12301253 .big_int => |big_int| {
12311254 if (big_int.to(u32)) |casted| {
......@@ -1678,6 +1701,7 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void {
16781701 .simple_type => 0,
16791702 .simple_value => 0,
16801703 .simple_internal => 0,
1704 .int_u8 => 0,
16811705 .int_u16 => 0,
16821706 .int_u32 => 0,
16831707 .int_i32 => 0,