authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-04 15:22:41-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-04 17:34:17-07:00
logf21c11a7f7fb84db4289a6f735dea012387606d6
tree9d744e2487ded968fc2ff7003674fe1fe53fff09
parent5b1c0d922c1061706ae1673333fcfb1d8fdd4602

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.

3 files changed, 11 insertions(+), 10 deletions(-)

lib/std/target.zig+6-1
...@@ -1784,7 +1784,6 @@ pub const Target = struct {...@@ -1784,7 +1784,6 @@ pub const Target = struct {
1784 .armeb,1784 .armeb,
1785 .thumb,1785 .thumb,
1786 .thumbeb,1786 .thumbeb,
1787 .x86_64,
1788 .hexagon,1787 .hexagon,
1789 .mips,1788 .mips,
1790 .mipsel,1789 .mipsel,
...@@ -1811,6 +1810,12 @@ pub const Target = struct {...@@ -1811,6 +1810,12 @@ pub const Target = struct {
1811 .windows => 8,1810 .windows => 8,
1812 else => 4,1811 else => 4,
1813 },1812 },
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,
1814 .aarch64,1819 .aarch64,
1815 .aarch64_be,1820 .aarch64_be,
1816 .aarch64_32,1821 .aarch64_32,
src/target.zig+1-8
...@@ -555,7 +555,7 @@ pub const AtomicPtrAlignmentDiagnostics = struct {...@@ -555,7 +555,7 @@ pub const AtomicPtrAlignmentDiagnostics = struct {
555 max_bits: u16 = undefined,555 max_bits: u16 = undefined,
556};556};
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.
559/// Otherwise returns the alignment required on a pointer for the target559/// Otherwise returns the alignment required on a pointer for the target
560/// to perform atomic operations.560/// to perform atomic operations.
561pub fn atomicPtrAlignment(561pub fn atomicPtrAlignment(
...@@ -645,9 +645,6 @@ pub fn atomicPtrAlignment(...@@ -645,9 +645,6 @@ pub fn atomicPtrAlignment(
645 };645 };
646 return error.FloatTooBig;646 return error.FloatTooBig;
647 }647 }
648 if (target.cpu.arch == .x86_64 and bit_count > 64) {
649 return 16;
650 }
651 return 0;648 return 0;
652 },649 },
653 .Bool => return 0,650 .Bool => return 0,
...@@ -666,10 +663,6 @@ pub fn atomicPtrAlignment(...@@ -666,10 +663,6 @@ pub fn atomicPtrAlignment(
666 return error.IntTooBig;663 return error.IntTooBig;
667 }664 }
668665
669 if (target.cpu.arch == .x86_64 and bit_count > 64) {
670 return 16;
671 }
672
673 return 0;666 return 0;
674}667}
675668
test/behavior/align.zig+4-1
...@@ -55,6 +55,9 @@ test "alignment of struct with pointer has same alignment as usize" {...@@ -55,6 +55,9 @@ test "alignment of struct with pointer has same alignment as usize" {
55}55}
5656
57test "alignment and size of structs with 128-bit fields" {57test "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
58 const A = struct {61 const A = struct {
59 x: u128,62 x: u128,
60 };63 };
...@@ -67,7 +70,6 @@ test "alignment and size of structs with 128-bit fields" {...@@ -67,7 +70,6 @@ test "alignment and size of structs with 128-bit fields" {
67 .armeb,70 .armeb,
68 .thumb,71 .thumb,
69 .thumbeb,72 .thumbeb,
70 .x86_64,
71 .hexagon,73 .hexagon,
72 .mips,74 .mips,
73 .mipsel,75 .mipsel,
...@@ -128,6 +130,7 @@ test "alignment and size of structs with 128-bit fields" {...@@ -128,6 +130,7 @@ test "alignment and size of structs with 128-bit fields" {
128 },130 },
129 },131 },
130132
133 .x86_64,
131 .aarch64,134 .aarch64,
132 .aarch64_be,135 .aarch64_be,
133 .aarch64_32,136 .aarch64_32,