authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-03-27 21:32:37-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-05 22:05:10-07:00
log5870ffeb82e93ab2a35f9153668d170eced25cbc
tree58f3d0567f5aee38244f50934e3c70cf6d59b79f
parent243848167b753692602609888763d47898ea4ce9

compiler_rt: change the abi of f16 on mac to depend on the other type


11 files changed, 43 insertions(+), 29 deletions(-)

lib/compiler_rt/common.zig+14-6
......@@ -81,12 +81,20 @@ pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, _: ?
8181/// need for extending them to wider fp types.
8282/// TODO remove this; do this type selection in the language rather than
8383/// here in compiler-rt.
84pub const F16T = switch (builtin.cpu.arch) {
85 .aarch64, .aarch64_be, .aarch64_32 => f16,
86 .riscv64 => if (builtin.zig_backend == .stage1) u16 else f16,
87 .x86, .x86_64 => if (builtin.target.isDarwin()) u16 else f16,
88 else => u16,
89};
84pub fn F16T(comptime other_type: type) type {
85 return switch (builtin.cpu.arch) {
86 .aarch64, .aarch64_be, .aarch64_32 => f16,
87 .riscv64 => if (builtin.zig_backend == .stage1) u16 else f16,
88 .x86, .x86_64 => if (builtin.target.isDarwin()) switch (other_type) {
89 // Starting with LLVM 16, Darwin uses different abi for f16
90 // depending on the type of the other return/argument..???
91 f32, f64 => u16,
92 f80, f128 => f16,
93 else => unreachable,
94 } else f16,
95 else => u16,
96 };
97}
9098
9199pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
92100 switch (Z) {
lib/compiler_rt/extendf_test.zig+2-2
......@@ -45,7 +45,7 @@ fn test__extenddftf2(a: f64, expected_hi: u64, expected_lo: u64) !void {
4545}
4646
4747fn test__extendhfsf2(a: u16, expected: u32) !void {
48 const x = __extendhfsf2(@bitCast(F16T, a));
48 const x = __extendhfsf2(@bitCast(F16T(f32), a));
4949 const rep = @bitCast(u32, x);
5050
5151 if (rep == expected) {
......@@ -208,7 +208,7 @@ fn makeInf32() f32 {
208208}
209209
210210fn test__extendhftf2(a: u16, expected_hi: u64, expected_lo: u64) !void {
211 const x = __extendhftf2(@bitCast(F16T, a));
211 const x = __extendhftf2(@bitCast(F16T(f128), a));
212212
213213 const rep = @bitCast(u128, x);
214214 const hi = @intCast(u64, rep >> 64);
lib/compiler_rt/extendhfdf2.zig+1-1
......@@ -7,6 +7,6 @@ comptime {
77 @export(__extendhfdf2, .{ .name = "__extendhfdf2", .linkage = common.linkage, .visibility = common.visibility });
88}
99
10pub fn __extendhfdf2(a: common.F16T) callconv(.C) f64 {
10pub fn __extendhfdf2(a: common.F16T(f64)) callconv(.C) f64 {
1111 return extendf(f64, f16, @bitCast(u16, a));
1212}
lib/compiler_rt/extendhfsf2.zig+2-2
......@@ -12,11 +12,11 @@ comptime {
1212 @export(__extendhfsf2, .{ .name = "__extendhfsf2", .linkage = common.linkage, .visibility = common.visibility });
1313}
1414
15pub fn __extendhfsf2(a: common.F16T) callconv(.C) f32 {
15pub fn __extendhfsf2(a: common.F16T(f32)) callconv(.C) f32 {
1616 return extendf(f32, f16, @bitCast(u16, a));
1717}
1818
19fn __gnu_h2f_ieee(a: common.F16T) callconv(.C) f32 {
19fn __gnu_h2f_ieee(a: common.F16T(f32)) callconv(.C) f32 {
2020 return extendf(f32, f16, @bitCast(u16, a));
2121}
2222
lib/compiler_rt/extendhftf2.zig+1-1
......@@ -7,6 +7,6 @@ comptime {
77 @export(__extendhftf2, .{ .name = "__extendhftf2", .linkage = common.linkage, .visibility = common.visibility });
88}
99
10pub fn __extendhftf2(a: common.F16T) callconv(.C) f128 {
10pub fn __extendhftf2(a: common.F16T(f128)) callconv(.C) f128 {
1111 return extendf(f128, f16, @bitCast(u16, a));
1212}
lib/compiler_rt/extendhfxf2.zig+1-1
......@@ -7,6 +7,6 @@ comptime {
77 @export(__extendhfxf2, .{ .name = "__extendhfxf2", .linkage = common.linkage, .visibility = common.visibility });
88}
99
10fn __extendhfxf2(a: common.F16T) callconv(.C) f80 {
10fn __extendhfxf2(a: common.F16T(f80)) callconv(.C) f80 {
1111 return extend_f80(f16, @bitCast(u16, a));
1212}
lib/compiler_rt/truncdfhf2.zig+3-3
......@@ -11,10 +11,10 @@ comptime {
1111 }
1212}
1313
14pub fn __truncdfhf2(a: f64) callconv(.C) common.F16T {
15 return @bitCast(common.F16T, truncf(f16, f64, a));
14pub fn __truncdfhf2(a: f64) callconv(.C) common.F16T(f64) {
15 return @bitCast(common.F16T(f64), truncf(f16, f64, a));
1616}
1717
1818fn __aeabi_d2h(a: f64) callconv(.AAPCS) u16 {
19 return @bitCast(common.F16T, truncf(f16, f64, a));
19 return @bitCast(common.F16T(f64), truncf(f16, f64, a));
2020}
lib/compiler_rt/truncsfhf2.zig+5-5
......@@ -12,14 +12,14 @@ comptime {
1212 @export(__truncsfhf2, .{ .name = "__truncsfhf2", .linkage = common.linkage, .visibility = common.visibility });
1313}
1414
15pub fn __truncsfhf2(a: f32) callconv(.C) common.F16T {
16 return @bitCast(common.F16T, truncf(f16, f32, a));
15pub fn __truncsfhf2(a: f32) callconv(.C) common.F16T(f32) {
16 return @bitCast(common.F16T(f32), truncf(f16, f32, a));
1717}
1818
19fn __gnu_f2h_ieee(a: f32) callconv(.C) common.F16T {
20 return @bitCast(common.F16T, truncf(f16, f32, a));
19fn __gnu_f2h_ieee(a: f32) callconv(.C) common.F16T(f32) {
20 return @bitCast(common.F16T(f32), truncf(f16, f32, a));
2121}
2222
2323fn __aeabi_f2h(a: f32) callconv(.AAPCS) u16 {
24 return @bitCast(common.F16T, truncf(f16, f32, a));
24 return @bitCast(common.F16T(f32), truncf(f16, f32, a));
2525}
lib/compiler_rt/trunctfhf2.zig+2-2
......@@ -7,6 +7,6 @@ comptime {
77 @export(__trunctfhf2, .{ .name = "__trunctfhf2", .linkage = common.linkage, .visibility = common.visibility });
88}
99
10pub fn __trunctfhf2(a: f128) callconv(.C) common.F16T {
11 return @bitCast(common.F16T, truncf(f16, f128, a));
10pub fn __trunctfhf2(a: f128) callconv(.C) common.F16T(f128) {
11 return @bitCast(common.F16T(f128), truncf(f16, f128, a));
1212}
lib/compiler_rt/truncxfhf2.zig+2-2
......@@ -7,6 +7,6 @@ comptime {
77 @export(__truncxfhf2, .{ .name = "__truncxfhf2", .linkage = common.linkage, .visibility = common.visibility });
88}
99
10fn __truncxfhf2(a: f80) callconv(.C) common.F16T {
11 return @bitCast(common.F16T, trunc_f80(f16, a));
10fn __truncxfhf2(a: f80) callconv(.C) common.F16T(f80) {
11 return @bitCast(common.F16T(f80), trunc_f80(f16, a));
1212}
lib/zig.h+10-4
......@@ -2873,6 +2873,12 @@ typedef zig_repr_f16 zig_f16;
28732873#undef zig_init_special_f16
28742874#define zig_init_special_f16(sign, name, arg, repr) repr
28752875#endif
2876#if __APPLE__
2877typedef zig_repr_f16 zig_compiler_rt_f16;
2878#else
2879typedef zig_f16 zig_compiler_rt_f16;
2880#endif
2881#define zig_compiler_rt_abbrev_zig_compiler_rt_f16 zig_compiler_rt_abbrev_zig_f16
28762882
28772883#define zig_has_f32 1
28782884#define zig_bitSizeOf_f32 32
......@@ -3088,15 +3094,15 @@ zig_float_from_repr(f128)
30883094#define zig_convert_builtin(ResType, operation, ArgType, version) \
30893095 zig_extern ResType zig_expand_concat(zig_expand_concat(zig_expand_concat(__##operation, \
30903096 zig_compiler_rt_abbrev_##ArgType), zig_compiler_rt_abbrev_##ResType), version)(ArgType);
3091zig_convert_builtin(zig_f16, trunc, zig_f32, 2)
3092zig_convert_builtin(zig_f16, trunc, zig_f64, 2)
3097zig_convert_builtin(zig_compiler_rt_f16, trunc, zig_f32, 2)
3098zig_convert_builtin(zig_compiler_rt_f16, trunc, zig_f64, 2)
30933099zig_convert_builtin(zig_f16, trunc, zig_f80, 2)
30943100zig_convert_builtin(zig_f16, trunc, zig_f128, 2)
3095zig_convert_builtin(zig_f32, extend, zig_f16, 2)
3101zig_convert_builtin(zig_f32, extend, zig_compiler_rt_f16, 2)
30963102zig_convert_builtin(zig_f32, trunc, zig_f64, 2)
30973103zig_convert_builtin(zig_f32, trunc, zig_f80, 2)
30983104zig_convert_builtin(zig_f32, trunc, zig_f128, 2)
3099zig_convert_builtin(zig_f64, extend, zig_f16, 2)
3105zig_convert_builtin(zig_f64, extend, zig_compiler_rt_f16, 2)
31003106zig_convert_builtin(zig_f64, extend, zig_f32, 2)
31013107zig_convert_builtin(zig_f64, trunc, zig_f80, 2)
31023108zig_convert_builtin(zig_f64, trunc, zig_f128, 2)