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 {...@@ -1930,45 +1930,53 @@ pub fn ptrBitWidth(target: Target) u16 {
1930}1930}
19311931
1932pub fn stackAlignment(target: Target) u16 {1932pub fn stackAlignment(target: Target) u16 {
1933 return switch (target.cpu.arch) {1933 // Overrides for when the stack alignment is not equal to the pointer width.
1934 .m68k => 2,1934 switch (target.cpu.arch) {
1935 .amdgcn => 4,1935 .m68k,
1936 .x86 => switch (target.os.tag) {1936 => return 2,
1937 .windows, .uefi => 4,1937 .amdgcn,
1938 else => 16,1938 => return 4,
1939 },1939 .lanai,
1940 .arm,
1941 .armeb,
1942 .thumb,
1943 .thumbeb,
1944 .mips,1940 .mips,
1945 .mipsel,1941 .mipsel,
1946 .sparc,1942 .sparc,
1947 => 8,1943 => return 8,
1948 .aarch64,1944 .aarch64,
1949 .aarch64_be,1945 .aarch64_be,
1950 .bpfeb,1946 .bpfeb,
1951 .bpfel,1947 .bpfel,
1948 .loongarch32,
1949 .loongarch64,
1952 .mips64,1950 .mips64,
1953 .mips64el,1951 .mips64el,
1954 .riscv64,
1955 .sparc64,1952 .sparc64,
1956 .x86_64,
1957 .ve,1953 .ve,
1958 .wasm32,1954 .wasm32,
1959 .wasm64,1955 .wasm64,
1960 .loongarch64,1956 => return 16,
1961 => 16,1957 // Some of the following prongs should really be testing the ABI (e.g. for Arm, it's APCS vs
1962 .riscv32,1958 // AAPCS16 vs AAPCS). But our current Abi enum is not able to handle that level of nuance.
1963 => if (Target.riscv.featureSetHas(target.cpu.features, .e)) 4 else 16,1959 .arm,
1964 .powerpc64,1960 .armeb,
1965 .powerpc64le,1961 .thumb,
1962 .thumbeb,
1966 => switch (target.os.tag) {1963 => switch (target.os.tag) {
1967 else => 8,1964 .netbsd => {},
1968 .linux => 16,1965 .watchos => return 16,
1966 else => return 8,
1969 },1967 },
1970 else => @divExact(target.ptrBitWidth(), 8),1968 .powerpc64,
1971 };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);
1972}1980}
19731981
1974/// Default signedness of `char` for the native C compiler for this target1982/// Default signedness of `char` for the native C compiler for this target