From f21c11a7f7fb84db4289a6f735dea012387606d6 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 4 May 2022 15:22:41 -0700 Subject: [PATCH] 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. --- lib/std/target.zig | 7 ++++++- src/target.zig | 9 +-------- test/behavior/align.zig | 5 ++++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/std/target.zig b/lib/std/target.zig index 777b0f0ec0420840ed1c5f15a562c6b8ad7fc6e7..aab9d5acccb230e9215a234f52398d7aa3871cd6 100644 --- a/lib/std/target.zig +++ b/lib/std/target.zig @@ -1784,7 +1784,6 @@ pub const Target = struct { .armeb, .thumb, .thumbeb, - .x86_64, .hexagon, .mips, .mipsel, @@ -1811,6 +1810,12 @@ pub const Target = struct { .windows => 8, else => 4, }, + + // For x86_64, LLVMABIAlignmentOfType(i128) reports 8. However I think 16 + // is a better number because of two reasons: + // 1. Better machine code when loading into SIMD register. + // 2. The C ABI wants 16 for extern structs. + .x86_64, .aarch64, .aarch64_be, .aarch64_32, diff --git a/src/target.zig b/src/target.zig index 7818d496eb8fa856041dc5b104bb7a07be6c2f11..9249ed1b606fb767b036e8f70768cdad2607e7d4 100644 --- a/src/target.zig +++ b/src/target.zig @@ -555,7 +555,7 @@ pub const AtomicPtrAlignmentDiagnostics = struct { max_bits: u16 = undefined, }; -/// If ABI alignment of `ty` is OK for atomic operations, returs 0. +/// If ABI alignment of `ty` is OK for atomic operations, returns 0. /// Otherwise returns the alignment required on a pointer for the target /// to perform atomic operations. pub fn atomicPtrAlignment( @@ -645,9 +645,6 @@ pub fn atomicPtrAlignment( }; return error.FloatTooBig; } - if (target.cpu.arch == .x86_64 and bit_count > 64) { - return 16; - } return 0; }, .Bool => return 0, @@ -666,10 +663,6 @@ pub fn atomicPtrAlignment( return error.IntTooBig; } - if (target.cpu.arch == .x86_64 and bit_count > 64) { - return 16; - } - return 0; } diff --git a/test/behavior/align.zig b/test/behavior/align.zig index 9d7ca9958a8332efc9cde22b05af95f80a67ad41..393908d5bd73191cb0a1b80acc02246c3f99b7cf 100644 --- a/test/behavior/align.zig +++ b/test/behavior/align.zig @@ -55,6 +55,9 @@ test "alignment of struct with pointer has same alignment as usize" { } test "alignment and size of structs with 128-bit fields" { + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + const A = struct { x: u128, }; @@ -67,7 +70,6 @@ test "alignment and size of structs with 128-bit fields" { .armeb, .thumb, .thumbeb, - .x86_64, .hexagon, .mips, .mipsel, @@ -128,6 +130,7 @@ test "alignment and size of structs with 128-bit fields" { }, }, + .x86_64, .aarch64, .aarch64_be, .aarch64_32, -- 2.54.0