authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-03-05 07:59:58+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-04-04 06:08:10+02:00
logcf9c6f5298924f95e83f2be0e9efb50fe2f61d92
treef7e12a708869a4fd8e32a20b227adac084caa91c
parent4c5c5bcd917fe718609360793a8883fbc77f1885
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

compiler: Update max int alignments for some targets.


2 files changed, 36 insertions(+), 84 deletions(-)

src/Type.zig+23-32
......@@ -1641,69 +1641,60 @@ pub fn intAbiAlignment(bits: u16, target: Target) Alignment {
16411641pub fn maxIntAlignment(target: std.Target) u16 {
16421642 return switch (target.cpu.arch) {
16431643 .avr => 1,
1644
16441645 .msp430 => 2,
1645 .xcore => 4,
1646 .propeller => 4,
16471646
1647 .xcore,
1648 .propeller,
1649 => 4,
1650
1651 .amdgcn,
16481652 .arm,
16491653 .armeb,
16501654 .thumb,
16511655 .thumbeb,
1656 .lanai,
16521657 .hexagon,
16531658 .mips,
16541659 .mipsel,
16551660 .powerpc,
16561661 .powerpcle,
1657 .amdgcn,
16581662 .riscv32,
1659 .sparc,
16601663 .s390x,
1661 .lanai,
1662 .wasm32,
1663 .wasm64,
16641664 => 8,
16651665
1666 // For these, LLVMABIAlignmentOfType(i128) reports 8. Note that 16
1667 // is a relevant number in three cases:
1668 // 1. Different machine code instruction when loading into SIMD register.
1669 // 2. The C ABI wants 16 for extern structs.
1670 // 3. 16-byte cmpxchg needs 16-byte alignment.
1671 // Same logic for powerpc64, mips64, sparc64.
1672 .powerpc64,
1673 .powerpc64le,
1674 .mips64,
1675 .mips64el,
1676 .sparc64,
1677 => switch (target.ofmt) {
1678 .c => 16,
1679 else => 8,
1680 },
1681
1682 .x86_64 => 16,
1683
16841666 // Even LLVMABIAlignmentOfType(i128) agrees on these targets.
1685 .x86,
16861667 .aarch64,
16871668 .aarch64_be,
1688 .riscv64,
16891669 .bpfel,
16901670 .bpfeb,
1671 .mips64,
1672 .mips64el,
16911673 .nvptx,
16921674 .nvptx64,
1675 .powerpc64,
1676 .powerpc64le,
1677 .riscv64,
1678 .sparc,
1679 .sparc64,
1680 .wasm32,
1681 .wasm64,
1682 .x86,
1683 .x86_64,
16931684 => 16,
16941685
16951686 // Below this comment are unverified but based on the fact that C requires
16961687 // int128_t to be 16 bytes aligned, it's a safe default.
1697 .csky,
16981688 .arc,
1699 .m68k,
1689 .csky,
17001690 .kalimba,
1691 .loongarch32,
1692 .loongarch64,
1693 .m68k,
17011694 .spirv,
17021695 .spirv32,
1703 .ve,
17041696 .spirv64,
1705 .loongarch32,
1706 .loongarch64,
1697 .ve,
17071698 .xtensa,
17081699 => 16,
17091700 };
test/behavior/align.zig+13-52
......@@ -85,22 +85,19 @@ test "alignment and size of structs with 128-bit fields" {
8585 y: u8,
8686 };
8787 const expected = switch (builtin.cpu.arch) {
88 .amdgcn,
8889 .arm,
8990 .armeb,
9091 .thumb,
9192 .thumbeb,
9293 .hexagon,
94 .lanai,
9395 .mips,
9496 .mipsel,
9597 .powerpc,
9698 .powerpcle,
97 .amdgcn,
9899 .riscv32,
99 .sparc,
100100 .s390x,
101 .lanai,
102 .wasm32,
103 .wasm64,
104101 => .{
105102 .a_align = 8,
106103 .a_size = 16,
......@@ -114,59 +111,23 @@ test "alignment and size of structs with 128-bit fields" {
114111 .u129_size = 24,
115112 },
116113
117 .mips64,
118 .mips64el,
119 .powerpc64,
120 .powerpc64le,
121 .sparc64,
122 => switch (builtin.object_format) {
123 .c => .{
124 .a_align = 16,
125 .a_size = 16,
126
127 .b_align = 16,
128 .b_size = 32,
129
130 .u128_align = 16,
131 .u128_size = 16,
132 .u129_align = 16,
133 .u129_size = 32,
134 },
135 else => .{
136 .a_align = 8,
137 .a_size = 16,
138
139 .b_align = 16,
140 .b_size = 32,
141
142 .u128_align = 8,
143 .u128_size = 16,
144 .u129_align = 8,
145 .u129_size = 24,
146 },
147 },
148
149 .x86_64 => .{
150 .a_align = 16,
151 .a_size = 16,
152
153 .b_align = 16,
154 .b_size = 32,
155
156 .u128_align = 16,
157 .u128_size = 16,
158 .u129_align = 16,
159 .u129_size = 32,
160 },
161
162 .x86,
163114 .aarch64,
164115 .aarch64_be,
165 .riscv64,
166116 .bpfel,
167117 .bpfeb,
118 .mips64,
119 .mips64el,
168120 .nvptx,
169121 .nvptx64,
122 .powerpc64,
123 .powerpc64le,
124 .sparc,
125 .sparc64,
126 .riscv64,
127 .wasm32,
128 .wasm64,
129 .x86,
130 .x86_64,
170131 => .{
171132 .a_align = 16,
172133 .a_size = 16,