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, _: ?...@@ -81,12 +81,20 @@ pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, _: ?
81/// need for extending them to wider fp types.81/// need for extending them to wider fp types.
82/// TODO remove this; do this type selection in the language rather than82/// TODO remove this; do this type selection in the language rather than
83/// here in compiler-rt.83/// here in compiler-rt.
84pub const F16T = switch (builtin.cpu.arch) {84pub fn F16T(comptime other_type: type) type {
85 .aarch64, .aarch64_be, .aarch64_32 => f16,85 return switch (builtin.cpu.arch) {
86 .riscv64 => if (builtin.zig_backend == .stage1) u16 else f16,86 .aarch64, .aarch64_be, .aarch64_32 => f16,
87 .x86, .x86_64 => if (builtin.target.isDarwin()) u16 else f16,87 .riscv64 => if (builtin.zig_backend == .stage1) u16 else f16,
88 else => u16,88 .x86, .x86_64 => if (builtin.target.isDarwin()) switch (other_type) {
89};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
91pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {99pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
92 switch (Z) {100 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 {...@@ -45,7 +45,7 @@ fn test__extenddftf2(a: f64, expected_hi: u64, expected_lo: u64) !void {
45}45}
4646
47fn test__extendhfsf2(a: u16, expected: u32) !void {47fn test__extendhfsf2(a: u16, expected: u32) !void {
48 const x = __extendhfsf2(@bitCast(F16T, a));48 const x = __extendhfsf2(@bitCast(F16T(f32), a));
49 const rep = @bitCast(u32, x);49 const rep = @bitCast(u32, x);
5050
51 if (rep == expected) {51 if (rep == expected) {
...@@ -208,7 +208,7 @@ fn makeInf32() f32 {...@@ -208,7 +208,7 @@ fn makeInf32() f32 {
208}208}
209209
210fn test__extendhftf2(a: u16, expected_hi: u64, expected_lo: u64) !void {210fn 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
213 const rep = @bitCast(u128, x);213 const rep = @bitCast(u128, x);
214 const hi = @intCast(u64, rep >> 64);214 const hi = @intCast(u64, rep >> 64);
lib/compiler_rt/extendhfdf2.zig+1-1
...@@ -7,6 +7,6 @@ comptime {...@@ -7,6 +7,6 @@ comptime {
7 @export(__extendhfdf2, .{ .name = "__extendhfdf2", .linkage = common.linkage, .visibility = common.visibility });7 @export(__extendhfdf2, .{ .name = "__extendhfdf2", .linkage = common.linkage, .visibility = common.visibility });
8}8}
99
10pub fn __extendhfdf2(a: common.F16T) callconv(.C) f64 {10pub fn __extendhfdf2(a: common.F16T(f64)) callconv(.C) f64 {
11 return extendf(f64, f16, @bitCast(u16, a));11 return extendf(f64, f16, @bitCast(u16, a));
12}12}
lib/compiler_rt/extendhfsf2.zig+2-2
...@@ -12,11 +12,11 @@ comptime {...@@ -12,11 +12,11 @@ comptime {
12 @export(__extendhfsf2, .{ .name = "__extendhfsf2", .linkage = common.linkage, .visibility = common.visibility });12 @export(__extendhfsf2, .{ .name = "__extendhfsf2", .linkage = common.linkage, .visibility = common.visibility });
13}13}
1414
15pub fn __extendhfsf2(a: common.F16T) callconv(.C) f32 {15pub fn __extendhfsf2(a: common.F16T(f32)) callconv(.C) f32 {
16 return extendf(f32, f16, @bitCast(u16, a));16 return extendf(f32, f16, @bitCast(u16, a));
17}17}
1818
19fn __gnu_h2f_ieee(a: common.F16T) callconv(.C) f32 {19fn __gnu_h2f_ieee(a: common.F16T(f32)) callconv(.C) f32 {
20 return extendf(f32, f16, @bitCast(u16, a));20 return extendf(f32, f16, @bitCast(u16, a));
21}21}
2222
lib/compiler_rt/extendhftf2.zig+1-1
...@@ -7,6 +7,6 @@ comptime {...@@ -7,6 +7,6 @@ comptime {
7 @export(__extendhftf2, .{ .name = "__extendhftf2", .linkage = common.linkage, .visibility = common.visibility });7 @export(__extendhftf2, .{ .name = "__extendhftf2", .linkage = common.linkage, .visibility = common.visibility });
8}8}
99
10pub fn __extendhftf2(a: common.F16T) callconv(.C) f128 {10pub fn __extendhftf2(a: common.F16T(f128)) callconv(.C) f128 {
11 return extendf(f128, f16, @bitCast(u16, a));11 return extendf(f128, f16, @bitCast(u16, a));
12}12}
lib/compiler_rt/extendhfxf2.zig+1-1
...@@ -7,6 +7,6 @@ comptime {...@@ -7,6 +7,6 @@ comptime {
7 @export(__extendhfxf2, .{ .name = "__extendhfxf2", .linkage = common.linkage, .visibility = common.visibility });7 @export(__extendhfxf2, .{ .name = "__extendhfxf2", .linkage = common.linkage, .visibility = common.visibility });
8}8}
99
10fn __extendhfxf2(a: common.F16T) callconv(.C) f80 {10fn __extendhfxf2(a: common.F16T(f80)) callconv(.C) f80 {
11 return extend_f80(f16, @bitCast(u16, a));11 return extend_f80(f16, @bitCast(u16, a));
12}12}
lib/compiler_rt/truncdfhf2.zig+3-3
...@@ -11,10 +11,10 @@ comptime {...@@ -11,10 +11,10 @@ comptime {
11 }11 }
12}12}
1313
14pub fn __truncdfhf2(a: f64) callconv(.C) common.F16T {14pub fn __truncdfhf2(a: f64) callconv(.C) common.F16T(f64) {
15 return @bitCast(common.F16T, truncf(f16, f64, a));15 return @bitCast(common.F16T(f64), truncf(f16, f64, a));
16}16}
1717
18fn __aeabi_d2h(a: f64) callconv(.AAPCS) u16 {18fn __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));
20}20}
lib/compiler_rt/truncsfhf2.zig+5-5
...@@ -12,14 +12,14 @@ comptime {...@@ -12,14 +12,14 @@ comptime {
12 @export(__truncsfhf2, .{ .name = "__truncsfhf2", .linkage = common.linkage, .visibility = common.visibility });12 @export(__truncsfhf2, .{ .name = "__truncsfhf2", .linkage = common.linkage, .visibility = common.visibility });
13}13}
1414
15pub fn __truncsfhf2(a: f32) callconv(.C) common.F16T {15pub fn __truncsfhf2(a: f32) callconv(.C) common.F16T(f32) {
16 return @bitCast(common.F16T, truncf(f16, f32, a));16 return @bitCast(common.F16T(f32), truncf(f16, f32, a));
17}17}
1818
19fn __gnu_f2h_ieee(a: f32) callconv(.C) common.F16T {19fn __gnu_f2h_ieee(a: f32) callconv(.C) common.F16T(f32) {
20 return @bitCast(common.F16T, truncf(f16, f32, a));20 return @bitCast(common.F16T(f32), truncf(f16, f32, a));
21}21}
2222
23fn __aeabi_f2h(a: f32) callconv(.AAPCS) u16 {23fn __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));
25}25}
lib/compiler_rt/trunctfhf2.zig+2-2
...@@ -7,6 +7,6 @@ comptime {...@@ -7,6 +7,6 @@ comptime {
7 @export(__trunctfhf2, .{ .name = "__trunctfhf2", .linkage = common.linkage, .visibility = common.visibility });7 @export(__trunctfhf2, .{ .name = "__trunctfhf2", .linkage = common.linkage, .visibility = common.visibility });
8}8}
99
10pub fn __trunctfhf2(a: f128) callconv(.C) common.F16T {10pub fn __trunctfhf2(a: f128) callconv(.C) common.F16T(f128) {
11 return @bitCast(common.F16T, truncf(f16, f128, a));11 return @bitCast(common.F16T(f128), truncf(f16, f128, a));
12}12}
lib/compiler_rt/truncxfhf2.zig+2-2
...@@ -7,6 +7,6 @@ comptime {...@@ -7,6 +7,6 @@ comptime {
7 @export(__truncxfhf2, .{ .name = "__truncxfhf2", .linkage = common.linkage, .visibility = common.visibility });7 @export(__truncxfhf2, .{ .name = "__truncxfhf2", .linkage = common.linkage, .visibility = common.visibility });
8}8}
99
10fn __truncxfhf2(a: f80) callconv(.C) common.F16T {10fn __truncxfhf2(a: f80) callconv(.C) common.F16T(f80) {
11 return @bitCast(common.F16T, trunc_f80(f16, a));11 return @bitCast(common.F16T(f80), trunc_f80(f16, a));
12}12}
lib/zig.h+10-4
...@@ -2873,6 +2873,12 @@ typedef zig_repr_f16 zig_f16;...@@ -2873,6 +2873,12 @@ typedef zig_repr_f16 zig_f16;
2873#undef zig_init_special_f162873#undef zig_init_special_f16
2874#define zig_init_special_f16(sign, name, arg, repr) repr2874#define zig_init_special_f16(sign, name, arg, repr) repr
2875#endif2875#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
2877#define zig_has_f32 12883#define zig_has_f32 1
2878#define zig_bitSizeOf_f32 322884#define zig_bitSizeOf_f32 32
...@@ -3088,15 +3094,15 @@ zig_float_from_repr(f128)...@@ -3088,15 +3094,15 @@ zig_float_from_repr(f128)
3088#define zig_convert_builtin(ResType, operation, ArgType, version) \3094#define zig_convert_builtin(ResType, operation, ArgType, version) \
3089 zig_extern ResType zig_expand_concat(zig_expand_concat(zig_expand_concat(__##operation, \3095 zig_extern ResType zig_expand_concat(zig_expand_concat(zig_expand_concat(__##operation, \
3090 zig_compiler_rt_abbrev_##ArgType), zig_compiler_rt_abbrev_##ResType), version)(ArgType);3096 zig_compiler_rt_abbrev_##ArgType), zig_compiler_rt_abbrev_##ResType), version)(ArgType);
3091zig_convert_builtin(zig_f16, trunc, zig_f32, 2)3097zig_convert_builtin(zig_compiler_rt_f16, trunc, zig_f32, 2)
3092zig_convert_builtin(zig_f16, trunc, zig_f64, 2)3098zig_convert_builtin(zig_compiler_rt_f16, trunc, zig_f64, 2)
3093zig_convert_builtin(zig_f16, trunc, zig_f80, 2)3099zig_convert_builtin(zig_f16, trunc, zig_f80, 2)
3094zig_convert_builtin(zig_f16, trunc, zig_f128, 2)3100zig_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)
3096zig_convert_builtin(zig_f32, trunc, zig_f64, 2)3102zig_convert_builtin(zig_f32, trunc, zig_f64, 2)
3097zig_convert_builtin(zig_f32, trunc, zig_f80, 2)3103zig_convert_builtin(zig_f32, trunc, zig_f80, 2)
3098zig_convert_builtin(zig_f32, trunc, zig_f128, 2)3104zig_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)
3100zig_convert_builtin(zig_f64, extend, zig_f32, 2)3106zig_convert_builtin(zig_f64, extend, zig_f32, 2)
3101zig_convert_builtin(zig_f64, trunc, zig_f80, 2)3107zig_convert_builtin(zig_f64, trunc, zig_f80, 2)
3102zig_convert_builtin(zig_f64, trunc, zig_f128, 2)3108zig_convert_builtin(zig_f64, trunc, zig_f128, 2)