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 | 143 ++++++++++-------- src/type.zig | 363 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 358 insertions(+), 148 deletions(-) diff --git a/lib/std/target.zig b/lib/std/target.zig index d791e3b0350ab19bf762b8d52f08730015b41876..99a137b4b9fd5b47b527631055e3fb371d194e55 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)) { + 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, } - 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(); - }, - - .riscv64, - .aarch64_be, - .aarch64_32, - .s390x, - .mips64, - .mips64el, - .sparc, - .sparc64, - .sparcel, - .powerpc, - .powerpcle, - .powerpc64, - .powerpc64le, - .wasm32, - .wasm64, - => true, - - else => false, - }, - f80 => switch (target.cpu.arch) { - .x86_64, .i386 => true, - else => false, - }, - f64 => switch (target.cpu.arch) { - .aarch64 => target.isDarwin(), - - .x86_64, - .i386, - .riscv64, - .aarch64_be, - .aarch64_32, - .s390x, - .mips64, - .mips64el, - .sparc, - .sparc64, - .sparcel, - .powerpc, - .powerpcle, - .powerpc64, - .powerpc64le, - => false, - - else => true, - }, - else => false, - }; } 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 a2f0bb9e8f2f96b3249e0500c0dc4a43de37a1a3..bcb8969484de140d1e012e18483448104dafd67e 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, + }, + ); + } }; -- 2.54.0 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 99a137b4b9fd5b47b527631055e3fb371d194e55..7121c1c3e269eca68b5e69df5993a7111ec4425e 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 b0d1588007f8bcb42fb5ae11f68b981e4556cabc..68e969f9e7ab9a45dc8b7611ae6cd1fbcdd80fdf 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, }; } -- 2.54.0 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 bcb8969484de140d1e012e18483448104dafd67e..51b326e18e548a49bc2c65e5d1312dafea3cf89f 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, -- 2.54.0 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 2a22493ded3112cf36180fb92313a29c5e6d134c..15c450e193d5e70e94c79ba4310870c4da14f4b8 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 406f61fbb969f80d695577b58a75fd81f7222dd5..6622546501047775a9594de60f1b592e920b77de 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 00263f943a3b44eed3a8d75995bea4888ca38cd2..98137e3dfcdb4a115cf998c61e6936f84b9788c6 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 311d9271688fcb5a481acc895d9e44a80ddc1e84..664f6550a4ed431a14c5d17ca5c197c75ac7ca20 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 b6cabeab91aaf4dc539f1c0e60f7fa3d47fd33ea..736068e81977c74c5a84997eb4a57b72f783e5a0 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 f34f226be4593eeff20e55424149405ab064d1fe..7dfac7328ca817215b421f5714aa1cbaf3e23fe6 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 e89a918501426e0575ab91155becbd86f49d175d..daca339baecc1de078a06f0152274c0a01720110 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 21e497b3a43f1701d890d2aa332cfd09f0026679..3005987530795d9635a2a58936bc3136701622b5 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 acdc0d586d75f255bbba17a35c9056811ffb9d17..68b07470423a61b5130e20df5bcd0d755bb1c3dc 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 fd3a58a9b756346886101bde063b54c68ff71baf..e9ce98bb7aa292eef3d010a15abe3cb2974f4969 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 9cc9835352acee665189c9b4ab11a084754e1890..f9a32828f18c04c6e423eb3ba5937de6afbd033f 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 f46208f02b9eff8001cda20445918b5f0620a6b7..0f5e3924ae3d12d0bd41039618e96f85657347b7 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 0657bf20c17e06849a30ecfb6abf25fb01aeadb3..fb9ff5b330382d2f7629dcce14c5639d8feda728 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 70725ddf3802bea64b6d6f5bcc487efc46b640b1..79cacbe34062a28435c857eb606b272b4d710760 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 731c6d8d865276320fac3501cbcd10826bfb86cb..1f651b817b53a381d7b85bb8d3d6911c1135cc26 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 0954199170e13673c109aa32cbc608292a9d35d3..20473fa1d03a813c846ca17e1f4cef5b002f6533 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 1eda21891d07338b71aac798a04eda57a277f842..9236f4705f1fda1805b39240822daa8007ffc60b 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 bee656c8016f18d26d84028c728ccef130850c4f..af454e1e028d555ef07a14aa0923648525ba57bf 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 eb5d7037e9be26a416055aace21c622e51a1217e..ee386bc96ba520de95df08eee1ac2025eaf4b072 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 ef02786eb47925c54f09a8fc9357fa5ded42a251..afdc825f9f8353d7cfaf22dac6bc9b6ce7fcbcd9 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 aa37276ac3cacb85507ad19dc62cf5c4ac95f3bd..4bde30f50f16f7ef23799c82d59bdba812305e10 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 5fb87e0183d89b8fcf60ab5cc5d7ac3162aed809..df7c4a7f2e9e8fa0e2e8480e8a16900092ed24b8 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 cc2fd7b3ac5bd272bb4633b11afdaffc897f6c19..7565f3a572db967ea1e52c0758da20403c3b4745 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 22b20438cc3a4b8317a6e3c4d8f0d26465a53694..e276b9988476699f863eac2dc26ed954ed6a54fc 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 8d9d39c1f9b9a2a63c12d77c5d6d07cf4d996030..831736250fd161fe747a1f8e86b77014a7a432cb 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 90a38ba3818c61240138fdebd18cf533478ffe8a..5e7085a41bd81c79ab49cbe5b92b4f68d0a87a1d 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 406eb8d0c1dd908a0a4a5c8f0d79284ef2496fe6..54638cc6458f27cff16a14d9c67b50a342401bd7 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 6f6c07212a3f69267a1aebdd01e209f5890e68f2..8298c3dbe3251c520bfe3e0d9c27b2d8398c163b 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 d4449ab72e56c9f9f92280c889840aa2068f9910..878cd5c4ac614f6b9fad68e6743334b1c96a3630 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 acd26d882328549e7cdcfd7aafd6446d52f8eca7..8f4b3903613eb26973038289df69f48c5a56131a 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 1b93aab948a2a73f75a5caaf9312a71be6009e33..b6d388bf0adee473f9f5ec149a30ef77d845f3b2 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 c839356a360fb65b21b4450dd779006a661aa7e5..30a2b55d959c2c3b96dcbc1b3743a0ae06f6972b 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 01b09213fed2e07749c43d56cf3faee2a6f9d351..924a8dc9f95dc2377b77f5bb24d5d59d146bf9cb 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 9477f96917a0a2a141fa7fc69dabe54b8548f0d4..4a0d833f57adbd4e6b1519729520537323bf6bed 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 9ced5bc92cddd2dfbe83771fe959435f99c03457..f600dff61f1942fa18297333677c645a551b5447 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 e084d63d8836f31adafa8f26ce0116e621e6d049..02be252856a9fcceec29332680d1e2686a9133d9 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 0fcd5e1e086819c1768476876ef3cb4c17505526..88a3668a93f48b01e676799806cd7b2161e9cc2d 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 41d1d7008eb3a482b169d088e1bd7797689dd157..e00d9cc6d14d2d33ca84048bf74c5d039f189b96 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); -} -- 2.54.0 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 51b326e18e548a49bc2c65e5d1312dafea3cf89f..d78e2909b5ea98c86385c460b3e1c75094214724 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, + }, + ); + } }; -- 2.54.0 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 d78e2909b5ea98c86385c460b3e1c75094214724..8f2cd7c54d44ab14cc157332e87a9a164a7054f1 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, }, }, -- 2.54.0