Skip to content

Commit f21c11a

Browse files
committed
stage2: change x86_64 max int alignment from 8 to 16
For x86_64, LLVMABIAlignmentOfType(i128) reports 8. However I think 16 is a better number for two reasons: 1. Better machine code when loading into SIMD register. 2. The C ABI wants 16 for extern structs.
1 parent 5b1c0d9 commit f21c11a

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

lib/std/target.zig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,6 @@ pub const Target = struct {
17841784
.armeb,
17851785
.thumb,
17861786
.thumbeb,
1787-
.x86_64,
17881787
.hexagon,
17891788
.mips,
17901789
.mipsel,
@@ -1811,6 +1810,12 @@ pub const Target = struct {
18111810
.windows => 8,
18121811
else => 4,
18131812
},
1813+
1814+
// For x86_64, LLVMABIAlignmentOfType(i128) reports 8. However I think 16
1815+
// is a better number because of two reasons:
1816+
// 1. Better machine code when loading into SIMD register.
1817+
// 2. The C ABI wants 16 for extern structs.
1818+
.x86_64,
18141819
.aarch64,
18151820
.aarch64_be,
18161821
.aarch64_32,

src/target.zig

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ pub const AtomicPtrAlignmentDiagnostics = struct {
555555
max_bits: u16 = undefined,
556556
};
557557

558-
/// If ABI alignment of `ty` is OK for atomic operations, returs 0.
558+
/// If ABI alignment of `ty` is OK for atomic operations, returns 0.
559559
/// Otherwise returns the alignment required on a pointer for the target
560560
/// to perform atomic operations.
561561
pub fn atomicPtrAlignment(
@@ -645,9 +645,6 @@ pub fn atomicPtrAlignment(
645645
};
646646
return error.FloatTooBig;
647647
}
648-
if (target.cpu.arch == .x86_64 and bit_count > 64) {
649-
return 16;
650-
}
651648
return 0;
652649
},
653650
.Bool => return 0,
@@ -666,10 +663,6 @@ pub fn atomicPtrAlignment(
666663
return error.IntTooBig;
667664
}
668665

669-
if (target.cpu.arch == .x86_64 and bit_count > 64) {
670-
return 16;
671-
}
672-
673666
return 0;
674667
}
675668

test/behavior/align.zig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ test "alignment of struct with pointer has same alignment as usize" {
5555
}
5656

5757
test "alignment and size of structs with 128-bit fields" {
58+
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
59+
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
60+
5861
const A = struct {
5962
x: u128,
6063
};
@@ -67,7 +70,6 @@ test "alignment and size of structs with 128-bit fields" {
6770
.armeb,
6871
.thumb,
6972
.thumbeb,
70-
.x86_64,
7173
.hexagon,
7274
.mips,
7375
.mipsel,
@@ -128,6 +130,7 @@ test "alignment and size of structs with 128-bit fields" {
128130
},
129131
},
130132

133+
.x86_64,
131134
.aarch64,
132135
.aarch64_be,
133136
.aarch64_32,

0 commit comments

Comments
 (0)