authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-08-07 01:38:46+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-11 20:28:29-07:00
log25096ed8936bb09e20589dda2bddeb09a24cfbaa
treecbe5f68dcb6977d745fd206bafaec2770aaf3c93
parent8161e61548135dcbc2c3563a61b75c08c8f7cb2c

std.Target: Some corrections and additions to stackAlignment().

Sourced from LLVM and GCC backends and ABI documents.

1 files changed, 32 insertions(+), 24 deletions(-)

lib/std/Target.zig+32-24
......@@ -1930,45 +1930,53 @@ pub fn ptrBitWidth(target: Target) u16 {
19301930}
19311931
19321932pub fn stackAlignment(target: Target) u16 {
1933 return switch (target.cpu.arch) {
1934 .m68k => 2,
1935 .amdgcn => 4,
1936 .x86 => switch (target.os.tag) {
1937 .windows, .uefi => 4,
1938 else => 16,
1939 },
1940 .arm,
1941 .armeb,
1942 .thumb,
1943 .thumbeb,
1933 // Overrides for when the stack alignment is not equal to the pointer width.
1934 switch (target.cpu.arch) {
1935 .m68k,
1936 => return 2,
1937 .amdgcn,
1938 => return 4,
1939 .lanai,
19441940 .mips,
19451941 .mipsel,
19461942 .sparc,
1947 => 8,
1943 => return 8,
19481944 .aarch64,
19491945 .aarch64_be,
19501946 .bpfeb,
19511947 .bpfel,
1948 .loongarch32,
1949 .loongarch64,
19521950 .mips64,
19531951 .mips64el,
1954 .riscv64,
19551952 .sparc64,
1956 .x86_64,
19571953 .ve,
19581954 .wasm32,
19591955 .wasm64,
1960 .loongarch64,
1961 => 16,
1962 .riscv32,
1963 => if (Target.riscv.featureSetHas(target.cpu.features, .e)) 4 else 16,
1964 .powerpc64,
1965 .powerpc64le,
1956 => return 16,
1957 // Some of the following prongs should really be testing the ABI (e.g. for Arm, it's APCS vs
1958 // AAPCS16 vs AAPCS). But our current Abi enum is not able to handle that level of nuance.
1959 .arm,
1960 .armeb,
1961 .thumb,
1962 .thumbeb,
19661963 => switch (target.os.tag) {
1967 else => 8,
1968 .linux => 16,
1964 .netbsd => {},
1965 .watchos => return 16,
1966 else => return 8,
19691967 },
1970 else => @divExact(target.ptrBitWidth(), 8),
1971 };
1968 .powerpc64,
1969 .powerpc64le,
1970 => if (target.os.tag == .linux or target.os.tag == .aix) return 16,
1971 .riscv32,
1972 .riscv64,
1973 => if (!Target.riscv.featureSetHas(target.cpu.features, .e)) return 16,
1974 .x86 => if (target.os.tag != .windows and target.os.tag != .uefi) return 16,
1975 .x86_64 => return if (target.os.tag == .elfiamcu) 4 else 16,
1976 else => {},
1977 }
1978
1979 return @divExact(target.ptrBitWidth(), 8);
19721980}
19731981
19741982/// Default signedness of `char` for the native C compiler for this target