Commit f21c11a7f7

Andrew Kelley <andrew@ziglang.org>
2022-05-05 00:22:41
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
Changed files (3)
lib
src
test
behavior
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,
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;
 }
 
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,