Skip to content

Commit 0bebb68

Browse files
committed
stage2: change max int align from 8 to 16 for more ISAs
These targets now have a similar disagreement with LLVM about the alignment of 128-bit integers as x86_64: * riscv64 * powerpc64 * powerpc64le * mips64 * mips64el * sparcv9 See #2987
1 parent af7e945 commit 0bebb68

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

lib/std/target.zig

+15-15
Original file line numberDiff line numberDiff line change
@@ -1787,18 +1787,12 @@ pub const Target = struct {
17871787
.hexagon,
17881788
.mips,
17891789
.mipsel,
1790-
.mips64,
1791-
.mips64el,
17921790
.powerpc,
17931791
.powerpcle,
1794-
.powerpc64,
1795-
.powerpc64le,
17961792
.r600,
17971793
.amdgcn,
17981794
.riscv32,
1799-
.riscv64,
18001795
.sparc,
1801-
.sparcv9,
18021796
.sparcel,
18031797
.s390x,
18041798
.lanai,
@@ -1812,10 +1806,20 @@ pub const Target = struct {
18121806
},
18131807

18141808
// For x86_64, LLVMABIAlignmentOfType(i128) reports 8. However I think 16
1815-
// is a better number because of two reasons:
1809+
// is a better number for two reasons:
18161810
// 1. Better machine code when loading into SIMD register.
18171811
// 2. The C ABI wants 16 for extern structs.
1812+
// 3. 16-byte cmpxchg needs 16-byte alignment.
1813+
// Same logic for riscv64, powerpc64, mips64, sparcv9.
18181814
.x86_64,
1815+
.riscv64,
1816+
.powerpc64,
1817+
.powerpc64le,
1818+
.mips64,
1819+
.mips64el,
1820+
.sparcv9,
1821+
1822+
// Even LLVMABIAlignmentOfType(i128) agrees on these targets.
18191823
.aarch64,
18201824
.aarch64_be,
18211825
.aarch64_32,
@@ -1825,11 +1829,9 @@ pub const Target = struct {
18251829
.nvptx64,
18261830
=> 16,
18271831

1828-
// Below this comment are unverified and I have chosen a number
1829-
// based on ptrBitWidth.
1830-
1831-
.spu_2 => 2,
1832-
1832+
// Below this comment are unverified but based on the fact that C requires
1833+
// int128_t to be 16 bytes aligned, it's a safe default.
1834+
.spu_2,
18331835
.csky,
18341836
.arc,
18351837
.m68k,
@@ -1843,16 +1845,14 @@ pub const Target = struct {
18431845
.renderscript32,
18441846
.spirv32,
18451847
.shave,
1846-
=> 4,
1847-
18481848
.le64,
18491849
.amdil64,
18501850
.hsail64,
18511851
.spir64,
18521852
.renderscript64,
18531853
.ve,
18541854
.spirv64,
1855-
=> 8,
1855+
=> 16,
18561856
};
18571857
}
18581858
};

test/behavior/align.zig

+6-6
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,12 @@ test "alignment and size of structs with 128-bit fields" {
7777
.hexagon,
7878
.mips,
7979
.mipsel,
80-
.mips64,
81-
.mips64el,
8280
.powerpc,
8381
.powerpcle,
84-
.powerpc64,
85-
.powerpc64le,
8682
.r600,
8783
.amdgcn,
8884
.riscv32,
89-
.riscv64,
9085
.sparc,
91-
.sparcv9,
9286
.sparcel,
9387
.s390x,
9488
.lanai,
@@ -134,6 +128,12 @@ test "alignment and size of structs with 128-bit fields" {
134128
},
135129
},
136130

131+
.mips64,
132+
.mips64el,
133+
.powerpc64,
134+
.powerpc64le,
135+
.riscv64,
136+
.sparcv9,
137137
.x86_64,
138138
.aarch64,
139139
.aarch64_be,

0 commit comments

Comments
 (0)