Skip to content

Commit 87d0f7e

Browse files
committed
x86_64: fix alignment of bool vectors
1 parent 5290552 commit 87d0f7e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/type.zig

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -915,15 +915,19 @@ pub const Type = struct {
915915
return .{ .scalar = Alignment.fromByteUnits(alignment) };
916916
},
917917
.stage2_x86_64 => {
918-
if (vector_type.child == .bool_type) return .{ .scalar = intAbiAlignment(@intCast(vector_type.len), target) };
918+
if (vector_type.child == .bool_type) {
919+
if (vector_type.len > 256 and std.Target.x86.featureSetHas(target.cpu.features, .avx512f)) return .{ .scalar = .@"64" };
920+
if (vector_type.len > 128 and std.Target.x86.featureSetHas(target.cpu.features, .avx2)) return .{ .scalar = .@"32" };
921+
if (vector_type.len > 64) return .{ .scalar = .@"16" };
922+
const bytes = std.math.divCeil(u32, vector_type.len, 8) catch unreachable;
923+
const alignment = std.math.ceilPowerOfTwoAssert(u32, bytes);
924+
return .{ .scalar = Alignment.fromByteUnits(alignment) };
925+
}
919926
const elem_bytes: u32 = @intCast((try Type.fromInterned(vector_type.child).abiSizeAdvanced(mod, strat)).scalar);
920927
if (elem_bytes == 0) return .{ .scalar = .@"1" };
921928
const bytes = elem_bytes * vector_type.len;
922929
if (bytes > 32 and std.Target.x86.featureSetHas(target.cpu.features, .avx512f)) return .{ .scalar = .@"64" };
923-
if (bytes > 16 and std.Target.x86.featureSetHas(
924-
target.cpu.features,
925-
if (Type.fromInterned(vector_type.child).isRuntimeFloat()) .avx else .avx2,
926-
)) return .{ .scalar = .@"32" };
930+
if (bytes > 16 and std.Target.x86.featureSetHas(target.cpu.features, .avx)) return .{ .scalar = .@"32" };
927931
return .{ .scalar = .@"16" };
928932
},
929933
}

0 commit comments

Comments
 (0)