From ddbdb83c865b1124487b3a00747fc5c1a67e5770 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Fri, 21 Oct 2022 18:56:18 -0700 Subject: [PATCH 1/6] stage 2: Update C types' size/alignment These updates were made by testing against the `sizeof/_Alignof` reported by Clang for all supported arch-OS-ABI combinations and correcting any discrepancies. This is bound to have a few errors (the recent long double fix for i386 Android is one example), but Clang is certainly not a bad place to start, especially for our most popular targets. --- lib/std/target.zig | 137 +++++++++-------- src/type.zig | 363 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 355 insertions(+), 145 deletions(-) diff --git a/lib/std/target.zig b/lib/std/target.zig index d791e3b035..99a137b4b9 100644 --- a/lib/std/target.zig +++ b/lib/std/target.zig @@ -1781,68 +1781,89 @@ pub const Target = struct { } pub inline fn longDoubleIs(target: Target, comptime F: type) bool { - if (target.abi == .msvc or (target.abi == .android and target.cpu.arch == .i386)) { - return F == f64; - } - return switch (F) { - f128 => switch (target.cpu.arch) { - .aarch64 => { - // According to Apple's official guide: - // > The long double type is a double precision IEEE754 binary floating-point type, - // > which makes it identical to the double type. This behavior contrasts to the - // > standard specification, in which a long double is a quad-precision, IEEE754 - // > binary, floating-point type. - // https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms - return !target.isDarwin(); + switch (target.os.tag) { + .windows, .uefi => switch (target.abi) { + .gnu, .gnuilp32, .cygnus => switch (target.cpu.arch) { + .i386 => return F == f80, + .x86_64 => return F == f128, + else => return F == f64, }, - - .riscv64, - .aarch64_be, - .aarch64_32, - .s390x, - .mips64, - .mips64el, - .sparc, - .sparc64, - .sparcel, - .powerpc, - .powerpcle, - .powerpc64, - .powerpc64le, - .wasm32, - .wasm64, - => true, - - else => false, + else => return F == f64, }, - f80 => switch (target.cpu.arch) { - .x86_64, .i386 => true, - else => false, - }, - f64 => switch (target.cpu.arch) { - .aarch64 => target.isDarwin(), + else => {}, + } - .x86_64, - .i386, - .riscv64, - .aarch64_be, - .aarch64_32, - .s390x, - .mips64, - .mips64el, - .sparc, - .sparc64, - .sparcel, - .powerpc, - .powerpcle, - .powerpc64, - .powerpc64le, - => false, + if (target.abi == .android and target.cpu.arch == .i386) + return F == f64; - else => true, + switch (target.cpu.arch) { + .aarch64, + .aarch64_be, + .aarch64_32, + => switch (target.os.tag) { + // According to Apple's official guide: + // > The long double type is a double precision IEEE754 binary floating-point type, + // > which makes it identical to the double type. This behavior contrasts to the + // > standard specification, in which a long double is a quad-precision, IEEE754 + // > binary, floating-point type. + // https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms + .ios, .macos, .watchos, .tvos => return F == f64, + .windows, .uefi => return F == f64, + else => return F == f128, }, - else => false, - }; + + .i386 => return F == f80, + .x86_64 => return F == f80, + + .mips64, + .mips64el, + => switch (target.os.tag) { + .freebsd => return F == f64, + else => return F == f128, + }, + + .powerpc, + .powerpcle, + => switch (target.abi) { + .musl, + .musleabi, + .musleabihf, + .muslx32, + => return F == f64, + else => switch (target.os.tag) { + .freebsd, .netbsd, .openbsd => return F == f64, + else => return F == f128, + }, + }, + + .powerpc64, + .powerpc64le, + => switch (target.abi) { + .musl, + .musleabi, + .musleabihf, + .muslx32, + => return F == f64, + else => switch (target.os.tag) { + .freebsd, .openbsd => return F == f64, + else => return F == f128, + }, + }, + + .riscv32, + .riscv64, + .s390x, + .sparc, + .sparc64, + .sparcel, + .wasm32, + .wasm64, + => return F == f128, + + .avr, .tce, .tcele => return F == f32, + + else => return F == f64, + } } pub inline fn maxIntAlignment(target: Target) u16 { @@ -1872,7 +1893,7 @@ pub const Target = struct { => 8, .i386 => return switch (target.os.tag) { - .windows => 8, + .windows, .uefi => 8, else => 4, }, diff --git a/src/type.zig b/src/type.zig index a2f0bb9e8f..bcb8969484 100644 --- a/src/type.zig +++ b/src/type.zig @@ -2892,41 +2892,24 @@ pub const Type = extern union { .anyframe_T, => return AbiAlignmentAdvanced{ .scalar = @divExact(target.cpu.arch.ptrBitWidth(), 8) }, - .c_short => return AbiAlignmentAdvanced{ .scalar = @divExact(CType.short.sizeInBits(target), 8) }, - .c_ushort => return AbiAlignmentAdvanced{ .scalar = @divExact(CType.ushort.sizeInBits(target), 8) }, - .c_int => return AbiAlignmentAdvanced{ .scalar = @divExact(CType.int.sizeInBits(target), 8) }, - .c_uint => return AbiAlignmentAdvanced{ .scalar = @divExact(CType.uint.sizeInBits(target), 8) }, - .c_long => return AbiAlignmentAdvanced{ .scalar = @divExact(CType.long.sizeInBits(target), 8) }, - .c_ulong => return AbiAlignmentAdvanced{ .scalar = @divExact(CType.ulong.sizeInBits(target), 8) }, - .c_longlong => switch (target.cpu.arch) { - .i386 => switch (target.os.tag) { - .windows, .uefi => return AbiAlignmentAdvanced{ .scalar = 8 }, - else => return AbiAlignmentAdvanced{ .scalar = 4 }, - }, - else => return AbiAlignmentAdvanced{ .scalar = @divExact(CType.longlong.sizeInBits(target), 8) }, - }, - .c_ulonglong => switch (target.cpu.arch) { - .i386 => switch (target.os.tag) { - .windows, .uefi => return AbiAlignmentAdvanced{ .scalar = 8 }, - else => return AbiAlignmentAdvanced{ .scalar = 4 }, - }, - else => return AbiAlignmentAdvanced{ .scalar = @divExact(CType.ulonglong.sizeInBits(target), 8) }, - }, + .c_short => return AbiAlignmentAdvanced{ .scalar = CType.short.alignment(target) }, + .c_ushort => return AbiAlignmentAdvanced{ .scalar = CType.ushort.alignment(target) }, + .c_int => return AbiAlignmentAdvanced{ .scalar = CType.int.alignment(target) }, + .c_uint => return AbiAlignmentAdvanced{ .scalar = CType.uint.alignment(target) }, + .c_long => return AbiAlignmentAdvanced{ .scalar = CType.long.alignment(target) }, + .c_ulong => return AbiAlignmentAdvanced{ .scalar = CType.ulong.alignment(target) }, + .c_longlong => return AbiAlignmentAdvanced{ .scalar = CType.longlong.alignment(target) }, + .c_ulonglong => return AbiAlignmentAdvanced{ .scalar = CType.ulonglong.alignment(target) }, + .c_longdouble => return AbiAlignmentAdvanced{ .scalar = CType.longdouble.alignment(target) }, .f16 => return AbiAlignmentAdvanced{ .scalar = 2 }, - .f32 => return AbiAlignmentAdvanced{ .scalar = 4 }, - .f64 => switch (target.cpu.arch) { - .i386 => switch (target.os.tag) { - .windows, .uefi => return AbiAlignmentAdvanced{ .scalar = 8 }, - else => return AbiAlignmentAdvanced{ .scalar = 4 }, - }, + .f32 => return AbiAlignmentAdvanced{ .scalar = CType.float.alignment(target) }, + .f64 => switch (CType.double.sizeInBits(target)) { + 64 => return AbiAlignmentAdvanced{ .scalar = CType.double.alignment(target) }, else => return AbiAlignmentAdvanced{ .scalar = 8 }, }, - .f128 => return AbiAlignmentAdvanced{ .scalar = 16 }, - - .f80 => switch (target.cpu.arch) { - .i386 => return AbiAlignmentAdvanced{ .scalar = 4 }, - .x86_64 => return AbiAlignmentAdvanced{ .scalar = 16 }, + .f80 => switch (CType.longdouble.sizeInBits(target)) { + 80 => return AbiAlignmentAdvanced{ .scalar = CType.longdouble.alignment(target) }, else => { var payload: Payload.Bits = .{ .base = .{ .tag = .int_unsigned }, @@ -2936,17 +2919,7 @@ pub const Type = extern union { return AbiAlignmentAdvanced{ .scalar = abiAlignment(u80_ty, target) }; }, }, - .c_longdouble => switch (CType.longdouble.sizeInBits(target)) { - 16 => return AbiAlignmentAdvanced{ .scalar = abiAlignment(Type.f16, target) }, - 32 => return AbiAlignmentAdvanced{ .scalar = abiAlignment(Type.f32, target) }, - 64 => return AbiAlignmentAdvanced{ .scalar = abiAlignment(Type.f64, target) }, - 80 => if (target.cpu.arch == .i386 and target.isMinGW()) - return AbiAlignmentAdvanced{ .scalar = 4 } - else - return AbiAlignmentAdvanced{ .scalar = abiAlignment(Type.f80, target) }, - 128 => return AbiAlignmentAdvanced{ .scalar = abiAlignment(Type.f128, target) }, - else => unreachable, - }, + .f128 => return AbiAlignmentAdvanced{ .scalar = 16 }, // TODO revisit this when we have the concept of the error tag type .anyerror_void_error_union, @@ -3411,16 +3384,8 @@ pub const Type = extern union { .f32 => return AbiSizeAdvanced{ .scalar = 4 }, .f64 => return AbiSizeAdvanced{ .scalar = 8 }, .f128 => return AbiSizeAdvanced{ .scalar = 16 }, - - .f80 => switch (target.cpu.arch) { - .i386 => switch (target.os.tag) { - .windows => switch (target.abi) { - .msvc => return AbiSizeAdvanced{ .scalar = 16 }, - else => return AbiSizeAdvanced{ .scalar = 12 }, - }, - else => return AbiSizeAdvanced{ .scalar = 12 }, - }, - .x86_64 => return AbiSizeAdvanced{ .scalar = 16 }, + .f80 => switch (CType.longdouble.sizeInBits(target)) { + 80 => return AbiSizeAdvanced{ .scalar = std.mem.alignForward(10, CType.longdouble.alignment(target)) }, else => { var payload: Payload.Bits = .{ .base = .{ .tag = .int_unsigned }, @@ -6654,45 +6619,80 @@ pub const CType = enum { ulonglong, longdouble, + // We don't have a `c_float`/`c_double` type in Zig, but these + // are useful for querying target-correct alignment and checking + // whether C's double is f64 or f32 + float, + double, + pub fn sizeInBits(self: CType, target: Target) u16 { switch (target.os.tag) { .freestanding, .other => switch (target.cpu.arch) { .msp430 => switch (self) { .short, .ushort, .int, .uint => return 16, - .long, .ulong => return 32, - .longlong, .ulonglong, .longdouble => return 64, + .float, .long, .ulong => return 32, + .longlong, .ulonglong, .double, .longdouble => return 64, }, .avr => switch (self) { .short, .ushort, .int, .uint => return 16, - .long, .ulong, .longdouble => return 32, + .long, .ulong, .float, .double, .longdouble => return 32, .longlong, .ulonglong => return 64, }, + .tce, .tcele => switch (self) { + .short, .ushort => return 16, + .int, .uint, .long, .ulong, .longlong, .ulonglong => return 32, + .float, .double, .longdouble => return 32, + }, + .mips64, .mips64el => switch (self) { + .short, .ushort => return 16, + .int, .uint, .float => return 32, + .long, .ulong => return if (target.abi != .gnuabin32) 64 else 32, + .longlong, .ulonglong, .double => return 64, + .longdouble => return 128, + }, + .x86_64 => switch (self) { + .short, .ushort => return 16, + .int, .uint, .float => return 32, + .long, .ulong => switch (target.abi) { + .gnux32, .muslx32 => return 32, + else => return 64, + }, + .longlong, .ulonglong, .double => return 64, + .longdouble => return 80, + }, else => switch (self) { .short, .ushort => return 16, - .int, .uint => return 32, + .int, .uint, .float => return 32, .long, .ulong => return target.cpu.arch.ptrBitWidth(), - .longlong, .ulonglong => return 64, + .longlong, .ulonglong, .double => return 64, .longdouble => switch (target.cpu.arch) { .i386 => switch (target.abi) { .android => return 64, else => return 80, }, - .x86_64 => return 80, + .powerpc, + .powerpcle, + .powerpc64, + .powerpc64le, + => switch (target.abi) { + .musl, + .musleabi, + .musleabihf, + .muslx32, + => return 64, + else => return 128, + }, + + .riscv32, .riscv64, .aarch64, .aarch64_be, .aarch64_32, .s390x, - .mips64, - .mips64el, .sparc, .sparc64, .sparcel, - .powerpc, - .powerpcle, - .powerpc64, - .powerpc64le, .wasm32, .wasm64, => return 128, @@ -6716,23 +6716,78 @@ pub const CType = enum { .fuchsia, .minix, => switch (target.cpu.arch) { + .msp430 => switch (self) { + .short, .ushort, .int, .uint => return 16, + .long, .ulong, .float => return 32, + .longlong, .ulonglong, .double, .longdouble => return 64, + }, .avr => switch (self) { .short, .ushort, .int, .uint => return 16, - .long, .ulong, .longdouble => return 32, + .long, .ulong, .float, .double, .longdouble => return 32, .longlong, .ulonglong => return 64, }, + .tce, .tcele => switch (self) { + .short, .ushort => return 16, + .int, .uint, .long, .ulong, .longlong, .ulonglong => return 32, + .float, .double, .longdouble => return 32, + }, + .mips64, .mips64el => switch (self) { + .short, .ushort => return 16, + .int, .uint, .float => return 32, + .long, .ulong => return if (target.abi != .gnuabin32) 64 else 32, + .longlong, .ulonglong, .double => return 64, + .longdouble => if (target.os.tag == .freebsd) return 64 else return 128, + }, + .x86_64 => switch (self) { + .short, .ushort => return 16, + .int, .uint, .float => return 32, + .long, .ulong => switch (target.abi) { + .gnux32, .muslx32 => return 32, + else => return 64, + }, + .longlong, .ulonglong, .double => return 64, + .longdouble => return 80, + }, else => switch (self) { .short, .ushort => return 16, - .int, .uint => return 32, + .int, .uint, .float => return 32, .long, .ulong => return target.cpu.arch.ptrBitWidth(), - .longlong, .ulonglong => return 64, + .longlong, .ulonglong, .double => return 64, .longdouble => switch (target.cpu.arch) { .i386 => switch (target.abi) { .android => return 64, else => return 80, }, - .x86_64 => return 80, + .powerpc, + .powerpcle, + => switch (target.abi) { + .musl, + .musleabi, + .musleabihf, + .muslx32, + => return 64, + else => switch (target.os.tag) { + .freebsd, .netbsd, .openbsd => return 64, + else => return 128, + }, + }, + + .powerpc64, + .powerpc64le, + => switch (target.abi) { + .musl, + .musleabi, + .musleabihf, + .muslx32, + => return 64, + else => switch (target.os.tag) { + .freebsd, .openbsd => return 64, + else => return 128, + }, + }, + + .riscv32, .riscv64, .aarch64, .aarch64_be, @@ -6743,10 +6798,6 @@ pub const CType = enum { .sparc, .sparc64, .sparcel, - .powerpc, - .powerpcle, - .powerpc64, - .powerpc64le, .wasm32, .wasm64, => return 128, @@ -6756,37 +6807,65 @@ pub const CType = enum { }, }, - .windows, .uefi => switch (self) { - .short, .ushort => return 16, - .int, .uint, .long, .ulong => return 32, - .longlong, .ulonglong => return 64, - .longdouble => switch (target.cpu.arch) { - .i386 => switch (target.abi) { - .gnu => return 80, + .windows, .uefi => switch (target.cpu.arch) { + .i386 => switch (self) { + .short, .ushort => return 16, + .int, .uint, .float => return 32, + .long, .ulong => return 32, + .longlong, .ulonglong, .double => return 64, + .longdouble => switch (target.abi) { + .gnu, .gnuilp32, .cygnus => return 80, else => return 64, }, - .x86_64 => switch (target.abi) { - .gnu => return 80, + }, + .x86_64 => switch (self) { + .short, .ushort => return 16, + .int, .uint, .float => return 32, + .long, .ulong => switch (target.abi) { + .cygnus => return 64, + else => return 32, + }, + .longlong, .ulonglong, .double => return 64, + .longdouble => switch (target.abi) { + .gnu, .gnuilp32, .cygnus => return 128, else => return 64, }, - else => return 64, + }, + else => switch (self) { + .short, .ushort => return 16, + .int, .uint, .float => return 32, + .long, .ulong => return 32, + .longlong, .ulonglong, .double => return 64, + .longdouble => return 64, }, }, .macos, .ios, .tvos, .watchos => switch (self) { .short, .ushort => return 16, - .int, .uint => return 32, - .long, .ulong, .longlong, .ulonglong => return 64, + .int, .uint, .float => return 32, + .long, .ulong => switch (target.cpu.arch) { + .i386, .arm, .aarch64_32 => return 32, + .x86_64 => switch (target.abi) { + .gnux32, .muslx32 => return 32, + else => return 64, + }, + else => return 64, + }, + .longlong, .ulonglong, .double => return 64, .longdouble => switch (target.cpu.arch) { - .i386, .x86_64 => return 80, + .i386 => switch (target.abi) { + .android => return 64, + else => return 80, + }, + .x86_64 => return 80, else => return 64, }, }, .amdhsa, .amdpal => switch (self) { .short, .ushort => return 16, - .int, .uint => return 32, - .long, .ulong, .longlong, .ulonglong => return 64, + .int, .uint, .float => return 32, + .long, .ulong, .longlong, .ulonglong, .double => return 64, .longdouble => return 128, }, @@ -6814,4 +6893,114 @@ pub const CType = enum { => @panic("TODO specify the C integer and float type sizes for this OS"), } } + + pub fn alignment(self: CType, target: Target) u16 { + + // Overrides for unusual alignments + switch (target.cpu.arch) { + .avr => switch (self) { + .short, .ushort => return 2, + else => return 1, + }, + .i386 => switch (target.os.tag) { + .windows, .uefi => switch (self) { + .longlong, .ulonglong, .double => return 8, + .longdouble => switch (target.abi) { + .gnu, .gnuilp32, .cygnus => return 4, + else => return 8, + }, + else => {}, + }, + else => {}, + }, + else => {}, + } + + // Self-aligned, up to a maximum. + return @min( + std.math.ceilPowerOfTwoAssert(u16, (self.sizeInBits(target) + 7) / 8), + switch (target.cpu.arch) { + .arm, .armeb, .thumb, .thumbeb => switch (target.os.tag) { + .netbsd => switch (target.abi) { + .gnueabi, + .gnueabihf, + .eabi, + .eabihf, + .android, + .musleabi, + .musleabihf, + => 8, + + else => @as(u16, 4), + }, + .ios, .tvos, .watchos => 4, + else => 8, + }, + + .msp430, + .avr, + => 2, + + .arc, + .csky, + .i386, + .xcore, + .dxil, + .loongarch32, + .tce, + .tcele, + .le32, + .amdil, + .hsail, + .spir, + .spirv32, + .kalimba, + .shave, + .renderscript32, + .ve, + .spu_2, + => 4, + + .aarch64_32, + .amdgcn, + .amdil64, + .bpfel, + .bpfeb, + .hexagon, + .hsail64, + .loongarch64, + .m68k, + .mips, + .mipsel, + .sparc, + .sparcel, + .sparc64, + .lanai, + .le64, + .nvptx, + .nvptx64, + .r600, + .s390x, + .spir64, + .spirv64, + .renderscript64, + => 8, + + .aarch64, + .aarch64_be, + .mips64, + .mips64el, + .powerpc, + .powerpcle, + .powerpc64, + .powerpc64le, + .riscv32, + .riscv64, + .x86_64, + .wasm32, + .wasm64, + => 16, + }, + ); + } }; From f0e66ac4d0e6347bf1b5a00b309fafb5da84191b Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Fri, 21 Oct 2022 19:20:58 -0700 Subject: [PATCH 2/6] std.Target: Remove `longDoubleIs` This function is redundant with CType.sizeInBits(), and until the previous commit they disagreed about the correct long double type for several targets. Although they're all synced up now, it's much simpler just to have a single source of truth. --- lib/std/target.zig | 86 -------------------------------------------- src/codegen/llvm.zig | 4 +-- 2 files changed, 2 insertions(+), 88 deletions(-) diff --git a/lib/std/target.zig b/lib/std/target.zig index 99a137b4b9..7121c1c3e2 100644 --- a/lib/std/target.zig +++ b/lib/std/target.zig @@ -1780,92 +1780,6 @@ pub const Target = struct { }; } - pub inline fn longDoubleIs(target: Target, comptime F: type) bool { - switch (target.os.tag) { - .windows, .uefi => switch (target.abi) { - .gnu, .gnuilp32, .cygnus => switch (target.cpu.arch) { - .i386 => return F == f80, - .x86_64 => return F == f128, - else => return F == f64, - }, - else => return F == f64, - }, - else => {}, - } - - if (target.abi == .android and target.cpu.arch == .i386) - return F == f64; - - switch (target.cpu.arch) { - .aarch64, - .aarch64_be, - .aarch64_32, - => switch (target.os.tag) { - // According to Apple's official guide: - // > The long double type is a double precision IEEE754 binary floating-point type, - // > which makes it identical to the double type. This behavior contrasts to the - // > standard specification, in which a long double is a quad-precision, IEEE754 - // > binary, floating-point type. - // https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms - .ios, .macos, .watchos, .tvos => return F == f64, - .windows, .uefi => return F == f64, - else => return F == f128, - }, - - .i386 => return F == f80, - .x86_64 => return F == f80, - - .mips64, - .mips64el, - => switch (target.os.tag) { - .freebsd => return F == f64, - else => return F == f128, - }, - - .powerpc, - .powerpcle, - => switch (target.abi) { - .musl, - .musleabi, - .musleabihf, - .muslx32, - => return F == f64, - else => switch (target.os.tag) { - .freebsd, .netbsd, .openbsd => return F == f64, - else => return F == f128, - }, - }, - - .powerpc64, - .powerpc64le, - => switch (target.abi) { - .musl, - .musleabi, - .musleabihf, - .muslx32, - => return F == f64, - else => switch (target.os.tag) { - .freebsd, .openbsd => return F == f64, - else => return F == f128, - }, - }, - - .riscv32, - .riscv64, - .s390x, - .sparc, - .sparc64, - .sparcel, - .wasm32, - .wasm64, - => return F == f128, - - .avr, .tce, .tcele => return F == f32, - - else => return F == f64, - } - } - pub inline fn maxIntAlignment(target: Target) u16 { return switch (target.cpu.arch) { .avr => 1, diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index b0d1588007..68e969f9e7 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -10615,8 +10615,8 @@ fn backendSupportsF128(target: std.Target) bool { fn intrinsicsAllowed(scalar_ty: Type, target: std.Target) bool { return switch (scalar_ty.tag()) { .f16 => backendSupportsF16(target), - .f80 => target.longDoubleIs(f80) and backendSupportsF80(target), - .f128 => target.longDoubleIs(f128) and backendSupportsF128(target), + .f80 => (CType.longdouble.sizeInBits(target) == 80) and backendSupportsF80(target), + .f128 => (CType.longdouble.sizeInBits(target) == 128) and backendSupportsF128(target), else => true, }; } From 94945864b9d8ffa7b707432fb877ae42e383db68 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Fri, 21 Oct 2022 20:16:00 -0700 Subject: [PATCH 3/6] Type.zig: Add `nvcl`/`cuda` CType definitions --- src/type.zig | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/type.zig b/src/type.zig index bcb8969484..51b326e18e 100644 --- a/src/type.zig +++ b/src/type.zig @@ -6862,6 +6862,18 @@ pub const CType = enum { }, }, + .nvcl, .cuda => switch (self) { + .short, .ushort => return 16, + .int, .uint, .float => return 32, + .long, .ulong => switch (target.cpu.arch) { + .nvptx => return 32, + .nvptx64 => return 64, + else => return 64, + }, + .longlong, .ulonglong, .double => return 64, + .longdouble => return 64, + }, + .amdhsa, .amdpal => switch (self) { .short, .ushort => return 16, .int, .uint, .float => return 32, @@ -6876,8 +6888,6 @@ pub const CType = enum { .rtems, .nacl, .aix, - .cuda, - .nvcl, .ps4, .ps5, .elfiamcu, From c50f33b1118f2e81597bd9ef5976fcb3eb961dee Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Sat, 22 Oct 2022 13:31:09 -0700 Subject: [PATCH 4/6] compiler_rt: Always export "standard" symbol names The Zig LLVM backend emits calls to softfloat methods with the "standard compiler-rt" names. Rather than add complexity to the backend and have to synchronize the naming scheme across all targets, the simplest fix is just to export these symbols under both the "standard" and the platform-specific naming convention. --- lib/compiler_rt/addtf3.zig | 9 ++------- lib/compiler_rt/ceil.zig | 6 ++++-- lib/compiler_rt/cmptf2.zig | 35 +++++++++------------------------ lib/compiler_rt/cos.zig | 6 ++++-- lib/compiler_rt/divtf3.zig | 10 +++------- lib/compiler_rt/exp.zig | 6 ++++-- lib/compiler_rt/exp2.zig | 6 ++++-- lib/compiler_rt/extenddftf2.zig | 9 ++------- lib/compiler_rt/extendsftf2.zig | 9 ++------- lib/compiler_rt/fabs.zig | 6 ++++-- lib/compiler_rt/fixtfdi.zig | 9 ++------- lib/compiler_rt/fixtfsi.zig | 9 ++------- lib/compiler_rt/fixunstfdi.zig | 9 ++------- lib/compiler_rt/fixunstfsi.zig | 9 ++------- lib/compiler_rt/floatditf.zig | 9 ++------- lib/compiler_rt/floatsitf.zig | 9 ++------- lib/compiler_rt/floatunditf.zig | 9 ++------- lib/compiler_rt/floatunsitf.zig | 9 ++------- lib/compiler_rt/floatuntitf.zig | 9 +++++---- lib/compiler_rt/floor.zig | 6 ++++-- lib/compiler_rt/fma.zig | 6 ++++-- lib/compiler_rt/fmax.zig | 6 ++++-- lib/compiler_rt/fmin.zig | 6 ++++-- lib/compiler_rt/fmod.zig | 6 ++++-- lib/compiler_rt/getf2.zig | 17 ++++------------ lib/compiler_rt/log.zig | 6 ++++-- lib/compiler_rt/log10.zig | 6 ++++-- lib/compiler_rt/log2.zig | 6 ++++-- lib/compiler_rt/multf3.zig | 9 ++------- lib/compiler_rt/round.zig | 6 ++++-- lib/compiler_rt/sin.zig | 6 ++++-- lib/compiler_rt/sincos.zig | 6 ++++-- lib/compiler_rt/sqrt.zig | 6 ++++-- lib/compiler_rt/subtf3.zig | 9 ++------- lib/compiler_rt/trunc.zig | 6 ++++-- lib/compiler_rt/trunctfdf2.zig | 9 ++------- lib/compiler_rt/trunctfsf2.zig | 9 ++------- lib/compiler_rt/unordtf2.zig | 9 ++------- 38 files changed, 125 insertions(+), 198 deletions(-) diff --git a/lib/compiler_rt/addtf3.zig b/lib/compiler_rt/addtf3.zig index 2a22493ded..15c450e193 100644 --- a/lib/compiler_rt/addtf3.zig +++ b/lib/compiler_rt/addtf3.zig @@ -5,22 +5,17 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__addkf3, .{ .name = "__addkf3", .linkage = common.linkage }); + @export(__addtf3, .{ .name = "__addkf3", .linkage = common.linkage }); } else if (common.want_sparc_abi) { @export(_Qp_add, .{ .name = "_Qp_add", .linkage = common.linkage }); - } else { - @export(__addtf3, .{ .name = "__addtf3", .linkage = common.linkage }); } + @export(__addtf3, .{ .name = "__addtf3", .linkage = common.linkage }); } pub fn __addtf3(a: f128, b: f128) callconv(.C) f128 { return addf3(f128, a, b); } -fn __addkf3(a: f128, b: f128) callconv(.C) f128 { - return addf3(f128, a, b); -} - fn _Qp_add(c: *f128, a: *f128, b: *f128) callconv(.C) void { c.* = addf3(f128, a.*, b.*); } diff --git a/lib/compiler_rt/ceil.zig b/lib/compiler_rt/ceil.zig index 406f61fbb9..6622546501 100644 --- a/lib/compiler_rt/ceil.zig +++ b/lib/compiler_rt/ceil.zig @@ -18,8 +18,10 @@ comptime { @export(ceilf, .{ .name = "ceilf", .linkage = common.linkage }); @export(ceil, .{ .name = "ceil", .linkage = common.linkage }); @export(__ceilx, .{ .name = "__ceilx", .linkage = common.linkage }); - const ceilq_sym_name = if (common.want_ppc_abi) "ceilf128" else "ceilq"; - @export(ceilq, .{ .name = ceilq_sym_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(ceilq, .{ .name = "ceilf128", .linkage = common.linkage }); + } + @export(ceilq, .{ .name = "ceilq", .linkage = common.linkage }); @export(ceill, .{ .name = "ceill", .linkage = common.linkage }); } diff --git a/lib/compiler_rt/cmptf2.zig b/lib/compiler_rt/cmptf2.zig index 00263f943a..98137e3dfc 100644 --- a/lib/compiler_rt/cmptf2.zig +++ b/lib/compiler_rt/cmptf2.zig @@ -7,10 +7,10 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__eqkf2, .{ .name = "__eqkf2", .linkage = common.linkage }); - @export(__nekf2, .{ .name = "__nekf2", .linkage = common.linkage }); - @export(__ltkf2, .{ .name = "__ltkf2", .linkage = common.linkage }); - @export(__lekf2, .{ .name = "__lekf2", .linkage = common.linkage }); + @export(__eqtf2, .{ .name = "__eqkf2", .linkage = common.linkage }); + @export(__netf2, .{ .name = "__nekf2", .linkage = common.linkage }); + @export(__lttf2, .{ .name = "__ltkf2", .linkage = common.linkage }); + @export(__letf2, .{ .name = "__lekf2", .linkage = common.linkage }); } else if (common.want_sparc_abi) { @export(_Qp_cmp, .{ .name = "_Qp_cmp", .linkage = common.linkage }); @export(_Qp_feq, .{ .name = "_Qp_feq", .linkage = common.linkage }); @@ -19,13 +19,12 @@ comptime { @export(_Qp_fle, .{ .name = "_Qp_fle", .linkage = common.linkage }); @export(_Qp_fgt, .{ .name = "_Qp_fgt", .linkage = common.linkage }); @export(_Qp_fge, .{ .name = "_Qp_fge", .linkage = common.linkage }); - } else { - @export(__eqtf2, .{ .name = "__eqtf2", .linkage = common.linkage }); - @export(__netf2, .{ .name = "__netf2", .linkage = common.linkage }); - @export(__letf2, .{ .name = "__letf2", .linkage = common.linkage }); - @export(__cmptf2, .{ .name = "__cmptf2", .linkage = common.linkage }); - @export(__lttf2, .{ .name = "__lttf2", .linkage = common.linkage }); } + @export(__eqtf2, .{ .name = "__eqtf2", .linkage = common.linkage }); + @export(__netf2, .{ .name = "__netf2", .linkage = common.linkage }); + @export(__letf2, .{ .name = "__letf2", .linkage = common.linkage }); + @export(__cmptf2, .{ .name = "__cmptf2", .linkage = common.linkage }); + @export(__lttf2, .{ .name = "__lttf2", .linkage = common.linkage }); } /// "These functions calculate a <=> b. That is, if a is less than b, they return -1; @@ -64,22 +63,6 @@ fn __lttf2(a: f128, b: f128) callconv(.C) i32 { return __cmptf2(a, b); } -fn __eqkf2(a: f128, b: f128) callconv(.C) i32 { - return __cmptf2(a, b); -} - -fn __nekf2(a: f128, b: f128) callconv(.C) i32 { - return __cmptf2(a, b); -} - -fn __ltkf2(a: f128, b: f128) callconv(.C) i32 { - return __cmptf2(a, b); -} - -fn __lekf2(a: f128, b: f128) callconv(.C) i32 { - return __cmptf2(a, b); -} - const SparcFCMP = enum(i32) { Equal = 0, Less = 1, diff --git a/lib/compiler_rt/cos.zig b/lib/compiler_rt/cos.zig index 311d927168..664f6550a4 100644 --- a/lib/compiler_rt/cos.zig +++ b/lib/compiler_rt/cos.zig @@ -16,8 +16,10 @@ comptime { @export(cosf, .{ .name = "cosf", .linkage = common.linkage }); @export(cos, .{ .name = "cos", .linkage = common.linkage }); @export(__cosx, .{ .name = "__cosx", .linkage = common.linkage }); - const cosq_sym_name = if (common.want_ppc_abi) "cosf128" else "cosq"; - @export(cosq, .{ .name = cosq_sym_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(cosq, .{ .name = "cosf128", .linkage = common.linkage }); + } + @export(cosq, .{ .name = "cosq", .linkage = common.linkage }); @export(cosl, .{ .name = "cosl", .linkage = common.linkage }); } diff --git a/lib/compiler_rt/divtf3.zig b/lib/compiler_rt/divtf3.zig index b6cabeab91..736068e819 100644 --- a/lib/compiler_rt/divtf3.zig +++ b/lib/compiler_rt/divtf3.zig @@ -9,22 +9,18 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__divkf3, .{ .name = "__divkf3", .linkage = common.linkage }); + // TODO: why did this not error? + @export(__divtf3, .{ .name = "__divkf3", .linkage = common.linkage }); } else if (common.want_sparc_abi) { @export(_Qp_div, .{ .name = "_Qp_div", .linkage = common.linkage }); - } else { - @export(__divtf3, .{ .name = "__divtf3", .linkage = common.linkage }); } + @export(__divtf3, .{ .name = "__divtf3", .linkage = common.linkage }); } pub fn __divtf3(a: f128, b: f128) callconv(.C) f128 { return div(a, b); } -fn __divkf3(a: f128, b: f128) callconv(.C) f128 { - return div(a, b); -} - fn _Qp_div(c: *f128, a: *const f128, b: *const f128) callconv(.C) void { c.* = div(a.*, b.*); } diff --git a/lib/compiler_rt/exp.zig b/lib/compiler_rt/exp.zig index f34f226be4..7dfac7328c 100644 --- a/lib/compiler_rt/exp.zig +++ b/lib/compiler_rt/exp.zig @@ -18,8 +18,10 @@ comptime { @export(expf, .{ .name = "expf", .linkage = common.linkage }); @export(exp, .{ .name = "exp", .linkage = common.linkage }); @export(__expx, .{ .name = "__expx", .linkage = common.linkage }); - const expq_sym_name = if (common.want_ppc_abi) "expf128" else "expq"; - @export(expq, .{ .name = expq_sym_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(expq, .{ .name = "expf128", .linkage = common.linkage }); + } + @export(expq, .{ .name = "expq", .linkage = common.linkage }); @export(expl, .{ .name = "expl", .linkage = common.linkage }); } diff --git a/lib/compiler_rt/exp2.zig b/lib/compiler_rt/exp2.zig index e89a918501..daca339bae 100644 --- a/lib/compiler_rt/exp2.zig +++ b/lib/compiler_rt/exp2.zig @@ -18,8 +18,10 @@ comptime { @export(exp2f, .{ .name = "exp2f", .linkage = common.linkage }); @export(exp2, .{ .name = "exp2", .linkage = common.linkage }); @export(__exp2x, .{ .name = "__exp2x", .linkage = common.linkage }); - const exp2q_sym_name = if (common.want_ppc_abi) "exp2f128" else "exp2q"; - @export(exp2q, .{ .name = exp2q_sym_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(exp2q, .{ .name = "exp2f128", .linkage = common.linkage }); + } + @export(exp2q, .{ .name = "exp2q", .linkage = common.linkage }); @export(exp2l, .{ .name = "exp2l", .linkage = common.linkage }); } diff --git a/lib/compiler_rt/extenddftf2.zig b/lib/compiler_rt/extenddftf2.zig index 21e497b3a4..3005987530 100644 --- a/lib/compiler_rt/extenddftf2.zig +++ b/lib/compiler_rt/extenddftf2.zig @@ -5,22 +5,17 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__extenddfkf2, .{ .name = "__extenddfkf2", .linkage = common.linkage }); + @export(__extenddftf2, .{ .name = "__extenddfkf2", .linkage = common.linkage }); } else if (common.want_sparc_abi) { @export(_Qp_dtoq, .{ .name = "_Qp_dtoq", .linkage = common.linkage }); - } else { - @export(__extenddftf2, .{ .name = "__extenddftf2", .linkage = common.linkage }); } + @export(__extenddftf2, .{ .name = "__extenddftf2", .linkage = common.linkage }); } pub fn __extenddftf2(a: f64) callconv(.C) f128 { return extendf(f128, f64, @bitCast(u64, a)); } -fn __extenddfkf2(a: f64) callconv(.C) f128 { - return extendf(f128, f64, @bitCast(u64, a)); -} - fn _Qp_dtoq(c: *f128, a: f64) callconv(.C) void { c.* = extendf(f128, f64, @bitCast(u64, a)); } diff --git a/lib/compiler_rt/extendsftf2.zig b/lib/compiler_rt/extendsftf2.zig index acdc0d586d..68b0747042 100644 --- a/lib/compiler_rt/extendsftf2.zig +++ b/lib/compiler_rt/extendsftf2.zig @@ -5,22 +5,17 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__extendsfkf2, .{ .name = "__extendsfkf2", .linkage = common.linkage }); + @export(__extendsftf2, .{ .name = "__extendsfkf2", .linkage = common.linkage }); } else if (common.want_sparc_abi) { @export(_Qp_stoq, .{ .name = "_Qp_stoq", .linkage = common.linkage }); - } else { - @export(__extendsftf2, .{ .name = "__extendsftf2", .linkage = common.linkage }); } + @export(__extendsftf2, .{ .name = "__extendsftf2", .linkage = common.linkage }); } pub fn __extendsftf2(a: f32) callconv(.C) f128 { return extendf(f128, f32, @bitCast(u32, a)); } -fn __extendsfkf2(a: f32) callconv(.C) f128 { - return extendf(f128, f32, @bitCast(u32, a)); -} - fn _Qp_stoq(c: *f128, a: f32) callconv(.C) void { c.* = extendf(f128, f32, @bitCast(u32, a)); } diff --git a/lib/compiler_rt/fabs.zig b/lib/compiler_rt/fabs.zig index fd3a58a9b7..e9ce98bb7a 100644 --- a/lib/compiler_rt/fabs.zig +++ b/lib/compiler_rt/fabs.zig @@ -10,8 +10,10 @@ comptime { @export(fabsf, .{ .name = "fabsf", .linkage = common.linkage }); @export(fabs, .{ .name = "fabs", .linkage = common.linkage }); @export(__fabsx, .{ .name = "__fabsx", .linkage = common.linkage }); - const fabsq_sym_name = if (common.want_ppc_abi) "fabsf128" else "fabsq"; - @export(fabsq, .{ .name = fabsq_sym_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(fabsq, .{ .name = "fabsf128", .linkage = common.linkage }); + } + @export(fabsq, .{ .name = "fabsq", .linkage = common.linkage }); @export(fabsl, .{ .name = "fabsl", .linkage = common.linkage }); } diff --git a/lib/compiler_rt/fixtfdi.zig b/lib/compiler_rt/fixtfdi.zig index 9cc9835352..f9a32828f1 100644 --- a/lib/compiler_rt/fixtfdi.zig +++ b/lib/compiler_rt/fixtfdi.zig @@ -5,22 +5,17 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__fixkfdi, .{ .name = "__fixkfdi", .linkage = common.linkage }); + @export(__fixtfdi, .{ .name = "__fixkfdi", .linkage = common.linkage }); } else if (common.want_sparc_abi) { @export(_Qp_qtox, .{ .name = "_Qp_qtox", .linkage = common.linkage }); - } else { - @export(__fixtfdi, .{ .name = "__fixtfdi", .linkage = common.linkage }); } + @export(__fixtfdi, .{ .name = "__fixtfdi", .linkage = common.linkage }); } pub fn __fixtfdi(a: f128) callconv(.C) i64 { return floatToInt(i64, a); } -fn __fixkfdi(a: f128) callconv(.C) i64 { - return floatToInt(i64, a); -} - fn _Qp_qtox(a: *const f128) callconv(.C) i64 { return floatToInt(i64, a.*); } diff --git a/lib/compiler_rt/fixtfsi.zig b/lib/compiler_rt/fixtfsi.zig index f46208f02b..0f5e3924ae 100644 --- a/lib/compiler_rt/fixtfsi.zig +++ b/lib/compiler_rt/fixtfsi.zig @@ -5,22 +5,17 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__fixkfsi, .{ .name = "__fixkfsi", .linkage = common.linkage }); + @export(__fixtfsi, .{ .name = "__fixkfsi", .linkage = common.linkage }); } else if (common.want_sparc_abi) { @export(_Qp_qtoi, .{ .name = "_Qp_qtoi", .linkage = common.linkage }); - } else { - @export(__fixtfsi, .{ .name = "__fixtfsi", .linkage = common.linkage }); } + @export(__fixtfsi, .{ .name = "__fixtfsi", .linkage = common.linkage }); } pub fn __fixtfsi(a: f128) callconv(.C) i32 { return floatToInt(i32, a); } -fn __fixkfsi(a: f128) callconv(.C) i32 { - return floatToInt(i32, a); -} - fn _Qp_qtoi(a: *const f128) callconv(.C) i32 { return floatToInt(i32, a.*); } diff --git a/lib/compiler_rt/fixunstfdi.zig b/lib/compiler_rt/fixunstfdi.zig index 0657bf20c1..fb9ff5b330 100644 --- a/lib/compiler_rt/fixunstfdi.zig +++ b/lib/compiler_rt/fixunstfdi.zig @@ -5,22 +5,17 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__fixunskfdi, .{ .name = "__fixunskfdi", .linkage = common.linkage }); + @export(__fixunstfdi, .{ .name = "__fixunskfdi", .linkage = common.linkage }); } else if (common.want_sparc_abi) { @export(_Qp_qtoux, .{ .name = "_Qp_qtoux", .linkage = common.linkage }); - } else { - @export(__fixunstfdi, .{ .name = "__fixunstfdi", .linkage = common.linkage }); } + @export(__fixunstfdi, .{ .name = "__fixunstfdi", .linkage = common.linkage }); } pub fn __fixunstfdi(a: f128) callconv(.C) u64 { return floatToInt(u64, a); } -fn __fixunskfdi(a: f128) callconv(.C) u64 { - return floatToInt(u64, a); -} - fn _Qp_qtoux(a: *const f128) callconv(.C) u64 { return floatToInt(u64, a.*); } diff --git a/lib/compiler_rt/fixunstfsi.zig b/lib/compiler_rt/fixunstfsi.zig index 70725ddf38..79cacbe340 100644 --- a/lib/compiler_rt/fixunstfsi.zig +++ b/lib/compiler_rt/fixunstfsi.zig @@ -5,22 +5,17 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__fixunskfsi, .{ .name = "__fixunskfsi", .linkage = common.linkage }); + @export(__fixunstfsi, .{ .name = "__fixunskfsi", .linkage = common.linkage }); } else if (common.want_sparc_abi) { @export(_Qp_qtoui, .{ .name = "_Qp_qtoui", .linkage = common.linkage }); - } else { - @export(__fixunstfsi, .{ .name = "__fixunstfsi", .linkage = common.linkage }); } + @export(__fixunstfsi, .{ .name = "__fixunstfsi", .linkage = common.linkage }); } pub fn __fixunstfsi(a: f128) callconv(.C) u32 { return floatToInt(u32, a); } -fn __fixunskfsi(a: f128) callconv(.C) u32 { - return floatToInt(u32, a); -} - fn _Qp_qtoui(a: *const f128) callconv(.C) u32 { return floatToInt(u32, a.*); } diff --git a/lib/compiler_rt/floatditf.zig b/lib/compiler_rt/floatditf.zig index 731c6d8d86..1f651b817b 100644 --- a/lib/compiler_rt/floatditf.zig +++ b/lib/compiler_rt/floatditf.zig @@ -5,22 +5,17 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__floatdikf, .{ .name = "__floatdikf", .linkage = common.linkage }); + @export(__floatditf, .{ .name = "__floatdikf", .linkage = common.linkage }); } else if (common.want_sparc_abi) { @export(_Qp_xtoq, .{ .name = "_Qp_xtoq", .linkage = common.linkage }); - } else { - @export(__floatditf, .{ .name = "__floatditf", .linkage = common.linkage }); } + @export(__floatditf, .{ .name = "__floatditf", .linkage = common.linkage }); } pub fn __floatditf(a: i64) callconv(.C) f128 { return intToFloat(f128, a); } -fn __floatdikf(a: i64) callconv(.C) f128 { - return intToFloat(f128, a); -} - fn _Qp_xtoq(c: *f128, a: i64) callconv(.C) void { c.* = intToFloat(f128, a); } diff --git a/lib/compiler_rt/floatsitf.zig b/lib/compiler_rt/floatsitf.zig index 0954199170..20473fa1d0 100644 --- a/lib/compiler_rt/floatsitf.zig +++ b/lib/compiler_rt/floatsitf.zig @@ -5,22 +5,17 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__floatsikf, .{ .name = "__floatsikf", .linkage = common.linkage }); + @export(__floatsitf, .{ .name = "__floatsikf", .linkage = common.linkage }); } else if (common.want_sparc_abi) { @export(_Qp_itoq, .{ .name = "_Qp_itoq", .linkage = common.linkage }); - } else { - @export(__floatsitf, .{ .name = "__floatsitf", .linkage = common.linkage }); } + @export(__floatsitf, .{ .name = "__floatsitf", .linkage = common.linkage }); } pub fn __floatsitf(a: i32) callconv(.C) f128 { return intToFloat(f128, a); } -fn __floatsikf(a: i32) callconv(.C) f128 { - return intToFloat(f128, a); -} - fn _Qp_itoq(c: *f128, a: i32) callconv(.C) void { c.* = intToFloat(f128, a); } diff --git a/lib/compiler_rt/floatunditf.zig b/lib/compiler_rt/floatunditf.zig index 1eda21891d..9236f4705f 100644 --- a/lib/compiler_rt/floatunditf.zig +++ b/lib/compiler_rt/floatunditf.zig @@ -5,22 +5,17 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__floatundikf, .{ .name = "__floatundikf", .linkage = common.linkage }); + @export(__floatunditf, .{ .name = "__floatundikf", .linkage = common.linkage }); } else if (common.want_sparc_abi) { @export(_Qp_uxtoq, .{ .name = "_Qp_uxtoq", .linkage = common.linkage }); - } else { - @export(__floatunditf, .{ .name = "__floatunditf", .linkage = common.linkage }); } + @export(__floatunditf, .{ .name = "__floatunditf", .linkage = common.linkage }); } pub fn __floatunditf(a: u64) callconv(.C) f128 { return intToFloat(f128, a); } -fn __floatundikf(a: u64) callconv(.C) f128 { - return intToFloat(f128, a); -} - fn _Qp_uxtoq(c: *f128, a: u64) callconv(.C) void { c.* = intToFloat(f128, a); } diff --git a/lib/compiler_rt/floatunsitf.zig b/lib/compiler_rt/floatunsitf.zig index bee656c801..af454e1e02 100644 --- a/lib/compiler_rt/floatunsitf.zig +++ b/lib/compiler_rt/floatunsitf.zig @@ -5,22 +5,17 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__floatunsikf, .{ .name = "__floatunsikf", .linkage = common.linkage }); + @export(__floatunsitf, .{ .name = "__floatunsikf", .linkage = common.linkage }); } else if (common.want_sparc_abi) { @export(_Qp_uitoq, .{ .name = "_Qp_uitoq", .linkage = common.linkage }); - } else { - @export(__floatunsitf, .{ .name = "__floatunsitf", .linkage = common.linkage }); } + @export(__floatunsitf, .{ .name = "__floatunsitf", .linkage = common.linkage }); } pub fn __floatunsitf(a: u32) callconv(.C) f128 { return intToFloat(f128, a); } -fn __floatunsikf(a: u32) callconv(.C) f128 { - return intToFloat(f128, a); -} - fn _Qp_uitoq(c: *f128, a: u32) callconv(.C) void { c.* = intToFloat(f128, a); } diff --git a/lib/compiler_rt/floatuntitf.zig b/lib/compiler_rt/floatuntitf.zig index eb5d7037e9..ee386bc96b 100644 --- a/lib/compiler_rt/floatuntitf.zig +++ b/lib/compiler_rt/floatuntitf.zig @@ -5,12 +5,13 @@ const intToFloat = @import("./int_to_float.zig").intToFloat; pub const panic = common.panic; comptime { - const symbol_name = if (common.want_ppc_abi) "__floatuntikf" else "__floatuntitf"; - if (common.want_windows_v2u64_abi) { - @export(__floatuntitf_windows_x86_64, .{ .name = symbol_name, .linkage = common.linkage }); + @export(__floatuntitf_windows_x86_64, .{ .name = "__floatuntitf", .linkage = common.linkage }); } else { - @export(__floatuntitf, .{ .name = symbol_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(__floatuntitf, .{ .name = "__floatuntikf", .linkage = common.linkage }); + } + @export(__floatuntitf, .{ .name = "__floatuntitf", .linkage = common.linkage }); } } diff --git a/lib/compiler_rt/floor.zig b/lib/compiler_rt/floor.zig index ef02786eb4..afdc825f9f 100644 --- a/lib/compiler_rt/floor.zig +++ b/lib/compiler_rt/floor.zig @@ -18,8 +18,10 @@ comptime { @export(floorf, .{ .name = "floorf", .linkage = common.linkage }); @export(floor, .{ .name = "floor", .linkage = common.linkage }); @export(__floorx, .{ .name = "__floorx", .linkage = common.linkage }); - const floorq_sym_name = if (common.want_ppc_abi) "floorf128" else "floorq"; - @export(floorq, .{ .name = floorq_sym_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(floorq, .{ .name = "floorf128", .linkage = common.linkage }); + } + @export(floorq, .{ .name = "floorq", .linkage = common.linkage }); @export(floorl, .{ .name = "floorl", .linkage = common.linkage }); } diff --git a/lib/compiler_rt/fma.zig b/lib/compiler_rt/fma.zig index aa37276ac3..4bde30f50f 100644 --- a/lib/compiler_rt/fma.zig +++ b/lib/compiler_rt/fma.zig @@ -19,8 +19,10 @@ comptime { @export(fmaf, .{ .name = "fmaf", .linkage = common.linkage }); @export(fma, .{ .name = "fma", .linkage = common.linkage }); @export(__fmax, .{ .name = "__fmax", .linkage = common.linkage }); - const fmaq_sym_name = if (common.want_ppc_abi) "fmaf128" else "fmaq"; - @export(fmaq, .{ .name = fmaq_sym_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(fmaq, .{ .name = "fmaf128", .linkage = common.linkage }); + } + @export(fmaq, .{ .name = "fmaq", .linkage = common.linkage }); @export(fmal, .{ .name = "fmal", .linkage = common.linkage }); } diff --git a/lib/compiler_rt/fmax.zig b/lib/compiler_rt/fmax.zig index 5fb87e0183..df7c4a7f2e 100644 --- a/lib/compiler_rt/fmax.zig +++ b/lib/compiler_rt/fmax.zig @@ -11,8 +11,10 @@ comptime { @export(fmaxf, .{ .name = "fmaxf", .linkage = common.linkage }); @export(fmax, .{ .name = "fmax", .linkage = common.linkage }); @export(__fmaxx, .{ .name = "__fmaxx", .linkage = common.linkage }); - const fmaxq_sym_name = if (common.want_ppc_abi) "fmaxf128" else "fmaxq"; - @export(fmaxq, .{ .name = fmaxq_sym_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(fmaxq, .{ .name = "fmaxf128", .linkage = common.linkage }); + } + @export(fmaxq, .{ .name = "fmaxq", .linkage = common.linkage }); @export(fmaxl, .{ .name = "fmaxl", .linkage = common.linkage }); } diff --git a/lib/compiler_rt/fmin.zig b/lib/compiler_rt/fmin.zig index cc2fd7b3ac..7565f3a572 100644 --- a/lib/compiler_rt/fmin.zig +++ b/lib/compiler_rt/fmin.zig @@ -11,8 +11,10 @@ comptime { @export(fminf, .{ .name = "fminf", .linkage = common.linkage }); @export(fmin, .{ .name = "fmin", .linkage = common.linkage }); @export(__fminx, .{ .name = "__fminx", .linkage = common.linkage }); - const fminq_sym_name = if (common.want_ppc_abi) "fminf128" else "fminq"; - @export(fminq, .{ .name = fminq_sym_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(fminq, .{ .name = "fminf128", .linkage = common.linkage }); + } + @export(fminq, .{ .name = "fminq", .linkage = common.linkage }); @export(fminl, .{ .name = "fminl", .linkage = common.linkage }); } diff --git a/lib/compiler_rt/fmod.zig b/lib/compiler_rt/fmod.zig index 22b20438cc..e276b99884 100644 --- a/lib/compiler_rt/fmod.zig +++ b/lib/compiler_rt/fmod.zig @@ -13,8 +13,10 @@ comptime { @export(fmodf, .{ .name = "fmodf", .linkage = common.linkage }); @export(fmod, .{ .name = "fmod", .linkage = common.linkage }); @export(__fmodx, .{ .name = "__fmodx", .linkage = common.linkage }); - const fmodq_sym_name = if (common.want_ppc_abi) "fmodf128" else "fmodq"; - @export(fmodq, .{ .name = fmodq_sym_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(fmodq, .{ .name = "fmodf128", .linkage = common.linkage }); + } + @export(fmodq, .{ .name = "fmodq", .linkage = common.linkage }); @export(fmodl, .{ .name = "fmodl", .linkage = common.linkage }); } diff --git a/lib/compiler_rt/getf2.zig b/lib/compiler_rt/getf2.zig index 8d9d39c1f9..831736250f 100644 --- a/lib/compiler_rt/getf2.zig +++ b/lib/compiler_rt/getf2.zig @@ -7,15 +7,14 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__gekf2, .{ .name = "__gekf2", .linkage = common.linkage }); - @export(__gtkf2, .{ .name = "__gtkf2", .linkage = common.linkage }); + @export(__getf2, .{ .name = "__gekf2", .linkage = common.linkage }); + @export(__gttf2, .{ .name = "__gtkf2", .linkage = common.linkage }); } else if (common.want_sparc_abi) { // These exports are handled in cmptf2.zig because gt and ge on sparc // are based on calling _Qp_cmp. - } else { - @export(__getf2, .{ .name = "__getf2", .linkage = common.linkage }); - @export(__gttf2, .{ .name = "__gttf2", .linkage = common.linkage }); } + @export(__getf2, .{ .name = "__getf2", .linkage = common.linkage }); + @export(__gttf2, .{ .name = "__gttf2", .linkage = common.linkage }); } /// "These functions return a value greater than or equal to zero if neither @@ -29,11 +28,3 @@ fn __getf2(a: f128, b: f128) callconv(.C) i32 { fn __gttf2(a: f128, b: f128) callconv(.C) i32 { return __getf2(a, b); } - -fn __gekf2(a: f128, b: f128) callconv(.C) i32 { - return __getf2(a, b); -} - -fn __gtkf2(a: f128, b: f128) callconv(.C) i32 { - return __getf2(a, b); -} diff --git a/lib/compiler_rt/log.zig b/lib/compiler_rt/log.zig index 90a38ba381..5e7085a41b 100644 --- a/lib/compiler_rt/log.zig +++ b/lib/compiler_rt/log.zig @@ -18,8 +18,10 @@ comptime { @export(logf, .{ .name = "logf", .linkage = common.linkage }); @export(log, .{ .name = "log", .linkage = common.linkage }); @export(__logx, .{ .name = "__logx", .linkage = common.linkage }); - const logq_sym_name = if (common.want_ppc_abi) "logf128" else "logq"; - @export(logq, .{ .name = logq_sym_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(logq, .{ .name = "logf128", .linkage = common.linkage }); + } + @export(logq, .{ .name = "logq", .linkage = common.linkage }); @export(logl, .{ .name = "logl", .linkage = common.linkage }); } diff --git a/lib/compiler_rt/log10.zig b/lib/compiler_rt/log10.zig index 406eb8d0c1..54638cc645 100644 --- a/lib/compiler_rt/log10.zig +++ b/lib/compiler_rt/log10.zig @@ -19,8 +19,10 @@ comptime { @export(log10f, .{ .name = "log10f", .linkage = common.linkage }); @export(log10, .{ .name = "log10", .linkage = common.linkage }); @export(__log10x, .{ .name = "__log10x", .linkage = common.linkage }); - const log10q_sym_name = if (common.want_ppc_abi) "log10f128" else "log10q"; - @export(log10q, .{ .name = log10q_sym_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(log10q, .{ .name = "log10f128", .linkage = common.linkage }); + } + @export(log10q, .{ .name = "log10q", .linkage = common.linkage }); @export(log10l, .{ .name = "log10l", .linkage = common.linkage }); } diff --git a/lib/compiler_rt/log2.zig b/lib/compiler_rt/log2.zig index 6f6c07212a..8298c3dbe3 100644 --- a/lib/compiler_rt/log2.zig +++ b/lib/compiler_rt/log2.zig @@ -19,8 +19,10 @@ comptime { @export(log2f, .{ .name = "log2f", .linkage = common.linkage }); @export(log2, .{ .name = "log2", .linkage = common.linkage }); @export(__log2x, .{ .name = "__log2x", .linkage = common.linkage }); - const log2q_sym_name = if (common.want_ppc_abi) "log2f128" else "log2q"; - @export(log2q, .{ .name = log2q_sym_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(log2q, .{ .name = "log2f128", .linkage = common.linkage }); + } + @export(log2q, .{ .name = "log2q", .linkage = common.linkage }); @export(log2l, .{ .name = "log2l", .linkage = common.linkage }); } diff --git a/lib/compiler_rt/multf3.zig b/lib/compiler_rt/multf3.zig index d4449ab72e..878cd5c4ac 100644 --- a/lib/compiler_rt/multf3.zig +++ b/lib/compiler_rt/multf3.zig @@ -5,22 +5,17 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__mulkf3, .{ .name = "__mulkf3", .linkage = common.linkage }); + @export(__multf3, .{ .name = "__mulkf3", .linkage = common.linkage }); } else if (common.want_sparc_abi) { @export(_Qp_mul, .{ .name = "_Qp_mul", .linkage = common.linkage }); - } else { - @export(__multf3, .{ .name = "__multf3", .linkage = common.linkage }); } + @export(__multf3, .{ .name = "__multf3", .linkage = common.linkage }); } pub fn __multf3(a: f128, b: f128) callconv(.C) f128 { return mulf3(f128, a, b); } -fn __mulkf3(a: f128, b: f128) callconv(.C) f128 { - return mulf3(f128, a, b); -} - fn _Qp_mul(c: *f128, a: *const f128, b: *const f128) callconv(.C) void { c.* = mulf3(f128, a.*, b.*); } diff --git a/lib/compiler_rt/round.zig b/lib/compiler_rt/round.zig index acd26d8823..8f4b390361 100644 --- a/lib/compiler_rt/round.zig +++ b/lib/compiler_rt/round.zig @@ -18,8 +18,10 @@ comptime { @export(roundf, .{ .name = "roundf", .linkage = common.linkage }); @export(round, .{ .name = "round", .linkage = common.linkage }); @export(__roundx, .{ .name = "__roundx", .linkage = common.linkage }); - const roundq_sym_name = if (common.want_ppc_abi) "roundf128" else "roundq"; - @export(roundq, .{ .name = roundq_sym_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(roundq, .{ .name = "roundf128", .linkage = common.linkage }); + } + @export(roundq, .{ .name = "roundq", .linkage = common.linkage }); @export(roundl, .{ .name = "roundl", .linkage = common.linkage }); } diff --git a/lib/compiler_rt/sin.zig b/lib/compiler_rt/sin.zig index 1b93aab948..b6d388bf0a 100644 --- a/lib/compiler_rt/sin.zig +++ b/lib/compiler_rt/sin.zig @@ -22,8 +22,10 @@ comptime { @export(sinf, .{ .name = "sinf", .linkage = common.linkage }); @export(sin, .{ .name = "sin", .linkage = common.linkage }); @export(__sinx, .{ .name = "__sinx", .linkage = common.linkage }); - const sinq_sym_name = if (common.want_ppc_abi) "sinf128" else "sinq"; - @export(sinq, .{ .name = sinq_sym_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(sinq, .{ .name = "sinf128", .linkage = common.linkage }); + } + @export(sinq, .{ .name = "sinq", .linkage = common.linkage }); @export(sinl, .{ .name = "sinl", .linkage = common.linkage }); } diff --git a/lib/compiler_rt/sincos.zig b/lib/compiler_rt/sincos.zig index c839356a36..30a2b55d95 100644 --- a/lib/compiler_rt/sincos.zig +++ b/lib/compiler_rt/sincos.zig @@ -14,8 +14,10 @@ comptime { @export(sincosf, .{ .name = "sincosf", .linkage = common.linkage }); @export(sincos, .{ .name = "sincos", .linkage = common.linkage }); @export(__sincosx, .{ .name = "__sincosx", .linkage = common.linkage }); - const sincosq_sym_name = if (common.want_ppc_abi) "sincosf128" else "sincosq"; - @export(sincosq, .{ .name = sincosq_sym_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(sincosq, .{ .name = "sincosf128", .linkage = common.linkage }); + } + @export(sincosq, .{ .name = "sincosq", .linkage = common.linkage }); @export(sincosl, .{ .name = "sincosl", .linkage = common.linkage }); } diff --git a/lib/compiler_rt/sqrt.zig b/lib/compiler_rt/sqrt.zig index 01b09213fe..924a8dc9f9 100644 --- a/lib/compiler_rt/sqrt.zig +++ b/lib/compiler_rt/sqrt.zig @@ -11,8 +11,10 @@ comptime { @export(sqrtf, .{ .name = "sqrtf", .linkage = common.linkage }); @export(sqrt, .{ .name = "sqrt", .linkage = common.linkage }); @export(__sqrtx, .{ .name = "__sqrtx", .linkage = common.linkage }); - const sqrtq_sym_name = if (common.want_ppc_abi) "sqrtf128" else "sqrtq"; - @export(sqrtq, .{ .name = sqrtq_sym_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(sqrtq, .{ .name = "sqrtf128", .linkage = common.linkage }); + } + @export(sqrtq, .{ .name = "sqrtq", .linkage = common.linkage }); @export(sqrtl, .{ .name = "sqrtl", .linkage = common.linkage }); } diff --git a/lib/compiler_rt/subtf3.zig b/lib/compiler_rt/subtf3.zig index 9477f96917..4a0d833f57 100644 --- a/lib/compiler_rt/subtf3.zig +++ b/lib/compiler_rt/subtf3.zig @@ -4,22 +4,17 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__subkf3, .{ .name = "__subkf3", .linkage = common.linkage }); + @export(__subtf3, .{ .name = "__subkf3", .linkage = common.linkage }); } else if (common.want_sparc_abi) { @export(_Qp_sub, .{ .name = "_Qp_sub", .linkage = common.linkage }); - } else { - @export(__subtf3, .{ .name = "__subtf3", .linkage = common.linkage }); } + @export(__subtf3, .{ .name = "__subtf3", .linkage = common.linkage }); } pub fn __subtf3(a: f128, b: f128) callconv(.C) f128 { return sub(a, b); } -fn __subkf3(a: f128, b: f128) callconv(.C) f128 { - return sub(a, b); -} - fn _Qp_sub(c: *f128, a: *const f128, b: *const f128) callconv(.C) void { c.* = sub(a.*, b.*); } diff --git a/lib/compiler_rt/trunc.zig b/lib/compiler_rt/trunc.zig index 9ced5bc92c..f600dff61f 100644 --- a/lib/compiler_rt/trunc.zig +++ b/lib/compiler_rt/trunc.zig @@ -18,8 +18,10 @@ comptime { @export(truncf, .{ .name = "truncf", .linkage = common.linkage }); @export(trunc, .{ .name = "trunc", .linkage = common.linkage }); @export(__truncx, .{ .name = "__truncx", .linkage = common.linkage }); - const truncq_sym_name = if (common.want_ppc_abi) "truncf128" else "truncq"; - @export(truncq, .{ .name = truncq_sym_name, .linkage = common.linkage }); + if (common.want_ppc_abi) { + @export(truncq, .{ .name = "truncf128", .linkage = common.linkage }); + } + @export(truncq, .{ .name = "truncq", .linkage = common.linkage }); @export(truncl, .{ .name = "truncl", .linkage = common.linkage }); } diff --git a/lib/compiler_rt/trunctfdf2.zig b/lib/compiler_rt/trunctfdf2.zig index e084d63d88..02be252856 100644 --- a/lib/compiler_rt/trunctfdf2.zig +++ b/lib/compiler_rt/trunctfdf2.zig @@ -5,22 +5,17 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__trunckfdf2, .{ .name = "__trunckfdf2", .linkage = common.linkage }); + @export(__trunctfdf2, .{ .name = "__trunckfdf2", .linkage = common.linkage }); } else if (common.want_sparc_abi) { @export(_Qp_qtod, .{ .name = "_Qp_qtod", .linkage = common.linkage }); - } else { - @export(__trunctfdf2, .{ .name = "__trunctfdf2", .linkage = common.linkage }); } + @export(__trunctfdf2, .{ .name = "__trunctfdf2", .linkage = common.linkage }); } pub fn __trunctfdf2(a: f128) callconv(.C) f64 { return truncf(f64, f128, a); } -fn __trunckfdf2(a: f128) callconv(.C) f64 { - return truncf(f64, f128, a); -} - fn _Qp_qtod(a: *const f128) callconv(.C) f64 { return truncf(f64, f128, a.*); } diff --git a/lib/compiler_rt/trunctfsf2.zig b/lib/compiler_rt/trunctfsf2.zig index 0fcd5e1e08..88a3668a93 100644 --- a/lib/compiler_rt/trunctfsf2.zig +++ b/lib/compiler_rt/trunctfsf2.zig @@ -5,22 +5,17 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__trunckfsf2, .{ .name = "__trunckfsf2", .linkage = common.linkage }); + @export(__trunctfsf2, .{ .name = "__trunckfsf2", .linkage = common.linkage }); } else if (common.want_sparc_abi) { @export(_Qp_qtos, .{ .name = "_Qp_qtos", .linkage = common.linkage }); - } else { - @export(__trunctfsf2, .{ .name = "__trunctfsf2", .linkage = common.linkage }); } + @export(__trunctfsf2, .{ .name = "__trunctfsf2", .linkage = common.linkage }); } pub fn __trunctfsf2(a: f128) callconv(.C) f32 { return truncf(f32, f128, a); } -fn __trunckfsf2(a: f128) callconv(.C) f32 { - return truncf(f32, f128, a); -} - fn _Qp_qtos(a: *const f128) callconv(.C) f32 { return truncf(f32, f128, a.*); } diff --git a/lib/compiler_rt/unordtf2.zig b/lib/compiler_rt/unordtf2.zig index 41d1d7008e..e00d9cc6d1 100644 --- a/lib/compiler_rt/unordtf2.zig +++ b/lib/compiler_rt/unordtf2.zig @@ -5,19 +5,14 @@ pub const panic = common.panic; comptime { if (common.want_ppc_abi) { - @export(__unordkf2, .{ .name = "__unordkf2", .linkage = common.linkage }); + @export(__unordtf2, .{ .name = "__unordkf2", .linkage = common.linkage }); } else if (common.want_sparc_abi) { // These exports are handled in cmptf2.zig because unordered comparisons // are based on calling _Qp_cmp. - } else { - @export(__unordtf2, .{ .name = "__unordtf2", .linkage = common.linkage }); } + @export(__unordtf2, .{ .name = "__unordtf2", .linkage = common.linkage }); } fn __unordtf2(a: f128, b: f128) callconv(.C) i32 { return comparef.unordcmp(f128, a, b); } - -fn __unordkf2(a: f128, b: f128) callconv(.C) i32 { - return comparef.unordcmp(f128, a, b); -} From c96f85852ed2e1d5b2ecb43770a3c41d7f38f284 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Sat, 22 Oct 2022 17:25:02 -0700 Subject: [PATCH 5/6] CType: Add `preferredAlignment` This value corresponds to clang/gcc's `__alignof` (rather than `_Alignof` which reports the minimum alignment). We don't use this information yet, but it might be useful for implementing ABIs so it is included here. --- src/type.zig | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 127 insertions(+), 1 deletion(-) diff --git a/src/type.zig b/src/type.zig index 51b326e18e..d78e2909b5 100644 --- a/src/type.zig +++ b/src/type.zig @@ -6926,7 +6926,7 @@ pub const CType = enum { else => {}, } - // Self-aligned, up to a maximum. + // Next-power-of-two-aligned, up to a maximum. return @min( std.math.ceilPowerOfTwoAssert(u16, (self.sizeInBits(target) + 7) / 8), switch (target.cpu.arch) { @@ -7013,4 +7013,130 @@ pub const CType = enum { }, ); } + + pub fn preferredAlignment(self: CType, target: Target) u16 { + + // Overrides for unusual alignments + switch (target.cpu.arch) { + .arm, .armeb, .thumb, .thumbeb => switch (target.os.tag) { + .netbsd => switch (target.abi) { + .gnueabi, + .gnueabihf, + .eabi, + .eabihf, + .android, + .musleabi, + .musleabihf, + => {}, + + else => switch (self) { + .longdouble => return 4, + else => {}, + }, + }, + .ios, .tvos, .watchos => switch (self) { + .longdouble => return 4, + else => {}, + }, + else => {}, + }, + .arc => switch (self) { + .longdouble => return 4, + else => {}, + }, + .avr => switch (self) { + .int, .uint, .long, .ulong, .float, .longdouble => return 1, + .short, .ushort => return 2, + .double => return 4, + .longlong, .ulonglong => return 8, + }, + .i386 => switch (target.os.tag) { + .windows, .uefi => switch (self) { + .longdouble => switch (target.abi) { + .gnu, .gnuilp32, .cygnus => return 4, + else => return 8, + }, + else => {}, + }, + else => switch (self) { + .longdouble => return 4, + else => {}, + }, + }, + else => {}, + } + + // Next-power-of-two-aligned, up to a maximum. + return @min( + std.math.ceilPowerOfTwoAssert(u16, (self.sizeInBits(target) + 7) / 8), + switch (target.cpu.arch) { + .msp430 => @as(u16, 2), + + .csky, + .xcore, + .dxil, + .loongarch32, + .tce, + .tcele, + .le32, + .amdil, + .hsail, + .spir, + .spirv32, + .kalimba, + .shave, + .renderscript32, + .ve, + .spu_2, + => 4, + + .arc, + .arm, + .armeb, + .avr, + .thumb, + .thumbeb, + .aarch64_32, + .amdgcn, + .amdil64, + .bpfel, + .bpfeb, + .hexagon, + .hsail64, + .i386, + .loongarch64, + .m68k, + .mips, + .mipsel, + .sparc, + .sparcel, + .sparc64, + .lanai, + .le64, + .nvptx, + .nvptx64, + .r600, + .s390x, + .spir64, + .spirv64, + .renderscript64, + => 8, + + .aarch64, + .aarch64_be, + .mips64, + .mips64el, + .powerpc, + .powerpcle, + .powerpc64, + .powerpc64le, + .riscv32, + .riscv64, + .x86_64, + .wasm32, + .wasm64, + => 16, + }, + ); + } }; From 4ecc384f99e5f4c5a320714484866fb48699245f Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Sun, 23 Oct 2022 23:17:23 -0700 Subject: [PATCH 6/6] Fix long double on x86_64-windows The larger alignment on this platform means that long double reports a sizeof 16 bytes, but it's underlying size is really just the 10 bytes of `f80` C doesn't give us a way to see the "underlying" size of a type, so this has to be caught by hand or by monitoring runtime memory. Luckily, x86 and x86-64 are the only platforms that seem to use a non-power-of-two type like this. --- src/type.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/type.zig b/src/type.zig index d78e2909b5..8f2cd7c54d 100644 --- a/src/type.zig +++ b/src/type.zig @@ -6827,7 +6827,7 @@ pub const CType = enum { }, .longlong, .ulonglong, .double => return 64, .longdouble => switch (target.abi) { - .gnu, .gnuilp32, .cygnus => return 128, + .gnu, .gnuilp32, .cygnus => return 80, else => return 64, }, },