revert "compiler: packed structs cache bit offsets"

This is mostly a revert of a7088fd9a3.
Measurement revealed the commit actually regressed performance.
This commit is contained in:
Andrew Kelley
2023-09-24 14:37:36 -07:00
parent a7088fd9a3
commit c08c0fc6ed
9 changed files with 52 additions and 67 deletions

View File

@@ -6649,3 +6649,26 @@ pub fn structFieldAlignmentExtern(mod: *Module, field_ty: Type) Alignment {
return ty_abi_align;
}
/// https://github.com/ziglang/zig/issues/17178 explored storing these bit offsets
/// into the packed struct InternPool data rather than computing this on the
/// fly, however it was found to perform worse when measured on real world
/// projects.
pub fn structPackedFieldBitOffset(
mod: *Module,
struct_type: InternPool.Key.StructType,
field_index: u32,
) u16 {
const ip = &mod.intern_pool;
assert(struct_type.layout == .Packed);
assert(struct_type.haveLayout(ip));
var bit_sum: u64 = 0;
for (0..struct_type.field_types.len) |i| {
if (i == field_index) {
return @intCast(bit_sum);
}
const field_ty = struct_type.field_types.get(ip)[i].toType();
bit_sum += field_ty.bitSize(mod);
}
unreachable; // index out of bounds
}