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) {...@@ -721,6 +721,9 @@ pub const Tag = enum(u8) {
721 /// only an enum tag, but will be presented via the API with a different Key.721 /// only an enum tag, but will be presented via the API with a different Key.
722 /// data is SimpleInternal enum value.722 /// data is SimpleInternal enum value.
723 simple_internal,723 simple_internal,
724 /// Type: u8
725 /// data is integer value
726 int_u8,
724 /// Type: u16727 /// Type: u16
725 /// data is integer value728 /// data is integer value
726 int_u16,729 int_u16,
...@@ -1056,6 +1059,10 @@ pub fn indexToKey(ip: InternPool, index: Index) Key {...@@ -1056,6 +1059,10 @@ pub fn indexToKey(ip: InternPool, index: Index) Key {
1056 .type_error_union => @panic("TODO"),1059 .type_error_union => @panic("TODO"),
1057 .type_enum_simple => @panic("TODO"),1060 .type_enum_simple => @panic("TODO"),
1058 .simple_internal => @panic("TODO"),1061 .simple_internal => @panic("TODO"),
1062 .int_u8 => .{ .int = .{
1063 .ty = .u8_type,
1064 .storage = .{ .u64 = data },
1065 } },
1059 .int_u16 => .{ .int = .{1066 .int_u16 => .{ .int = .{
1060 .ty = .u16_type,1067 .ty = .u16_type,
1061 .storage = .{ .u64 = data },1068 .storage = .{ .u64 = data },
...@@ -1226,6 +1233,22 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -1226,6 +1233,22 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
1226 .int => |int| b: {1233 .int => |int| b: {
1227 switch (int.ty) {1234 switch (int.ty) {
1228 .none => unreachable,1235 .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 },
1229 .u16_type => switch (int.storage) {1252 .u16_type => switch (int.storage) {
1230 .big_int => |big_int| {1253 .big_int => |big_int| {
1231 if (big_int.to(u32)) |casted| {1254 if (big_int.to(u32)) |casted| {
...@@ -1678,6 +1701,7 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void {...@@ -1678,6 +1701,7 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void {
1678 .simple_type => 0,1701 .simple_type => 0,
1679 .simple_value => 0,1702 .simple_value => 0,
1680 .simple_internal => 0,1703 .simple_internal => 0,
1704 .int_u8 => 0,
1681 .int_u16 => 0,1705 .int_u16 => 0,
1682 .int_u32 => 0,1706 .int_u32 => 0,
1683 .int_i32 => 0,1707 .int_i32 => 0,