| author | |
| committer | |
| log | 5870ffeb82e93ab2a35f9153668d170eced25cbc |
| tree | 58f3d0567f5aee38244f50934e3c70cf6d59b79f |
| parent | 243848167b753692602609888763d47898ea4ce9 |
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 | 81 | /// need for extending them to wider fp types. |
| 82 | 82 | /// TODO remove this; do this type selection in the language rather than |
| 83 | 83 | /// here in compiler-rt. |
| 84 | pub 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 | }; | |
| 84 | pub 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 | } | |
| 90 | 98 | |
| 91 | 99 | pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { |
| 92 | 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 | 45 | } |
| 46 | 46 | |
| 47 | 47 | fn test__extendhfsf2(a: u16, expected: u32) !void { |
| 48 | const x = __extendhfsf2(@bitCast(F16T, a)); | |
| 48 | const x = __extendhfsf2(@bitCast(F16T(f32), a)); | |
| 49 | 49 | const rep = @bitCast(u32, x); |
| 50 | 50 | |
| 51 | 51 | if (rep == expected) { |
| ... | ... | @@ -208,7 +208,7 @@ fn makeInf32() f32 { |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | fn 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)); | |
| 212 | 212 | |
| 213 | 213 | const rep = @bitCast(u128, x); |
| 214 | 214 | const hi = @intCast(u64, rep >> 64); |
lib/compiler_rt/extendhfdf2.zig+1-1| ... | ... | @@ -7,6 +7,6 @@ comptime { |
| 7 | 7 | @export(__extendhfdf2, .{ .name = "__extendhfdf2", .linkage = common.linkage, .visibility = common.visibility }); |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | pub fn __extendhfdf2(a: common.F16T) callconv(.C) f64 { | |
| 10 | pub fn __extendhfdf2(a: common.F16T(f64)) callconv(.C) f64 { | |
| 11 | 11 | return extendf(f64, f16, @bitCast(u16, a)); |
| 12 | 12 | } |
lib/compiler_rt/extendhfsf2.zig+2-2| ... | ... | @@ -12,11 +12,11 @@ comptime { |
| 12 | 12 | @export(__extendhfsf2, .{ .name = "__extendhfsf2", .linkage = common.linkage, .visibility = common.visibility }); |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | pub fn __extendhfsf2(a: common.F16T) callconv(.C) f32 { | |
| 15 | pub fn __extendhfsf2(a: common.F16T(f32)) callconv(.C) f32 { | |
| 16 | 16 | return extendf(f32, f16, @bitCast(u16, a)); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | fn __gnu_h2f_ieee(a: common.F16T) callconv(.C) f32 { | |
| 19 | fn __gnu_h2f_ieee(a: common.F16T(f32)) callconv(.C) f32 { | |
| 20 | 20 | return extendf(f32, f16, @bitCast(u16, a)); |
| 21 | 21 | } |
| 22 | 22 |
lib/compiler_rt/extendhftf2.zig+1-1| ... | ... | @@ -7,6 +7,6 @@ comptime { |
| 7 | 7 | @export(__extendhftf2, .{ .name = "__extendhftf2", .linkage = common.linkage, .visibility = common.visibility }); |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | pub fn __extendhftf2(a: common.F16T) callconv(.C) f128 { | |
| 10 | pub fn __extendhftf2(a: common.F16T(f128)) callconv(.C) f128 { | |
| 11 | 11 | return extendf(f128, f16, @bitCast(u16, a)); |
| 12 | 12 | } |
lib/compiler_rt/extendhfxf2.zig+1-1| ... | ... | @@ -7,6 +7,6 @@ comptime { |
| 7 | 7 | @export(__extendhfxf2, .{ .name = "__extendhfxf2", .linkage = common.linkage, .visibility = common.visibility }); |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | fn __extendhfxf2(a: common.F16T) callconv(.C) f80 { | |
| 10 | fn __extendhfxf2(a: common.F16T(f80)) callconv(.C) f80 { | |
| 11 | 11 | return extend_f80(f16, @bitCast(u16, a)); |
| 12 | 12 | } |
lib/compiler_rt/truncdfhf2.zig+3-3| ... | ... | @@ -11,10 +11,10 @@ comptime { |
| 11 | 11 | } |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | pub fn __truncdfhf2(a: f64) callconv(.C) common.F16T { | |
| 15 | return @bitCast(common.F16T, truncf(f16, f64, a)); | |
| 14 | pub fn __truncdfhf2(a: f64) callconv(.C) common.F16T(f64) { | |
| 15 | return @bitCast(common.F16T(f64), truncf(f16, f64, a)); | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | fn __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 | 12 | @export(__truncsfhf2, .{ .name = "__truncsfhf2", .linkage = common.linkage, .visibility = common.visibility }); |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | pub fn __truncsfhf2(a: f32) callconv(.C) common.F16T { | |
| 16 | return @bitCast(common.F16T, truncf(f16, f32, a)); | |
| 15 | pub fn __truncsfhf2(a: f32) callconv(.C) common.F16T(f32) { | |
| 16 | return @bitCast(common.F16T(f32), truncf(f16, f32, a)); | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | fn __gnu_f2h_ieee(a: f32) callconv(.C) common.F16T { | |
| 20 | return @bitCast(common.F16T, truncf(f16, f32, a)); | |
| 19 | fn __gnu_f2h_ieee(a: f32) callconv(.C) common.F16T(f32) { | |
| 20 | return @bitCast(common.F16T(f32), truncf(f16, f32, a)); | |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | fn __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 | 7 | @export(__trunctfhf2, .{ .name = "__trunctfhf2", .linkage = common.linkage, .visibility = common.visibility }); |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | pub fn __trunctfhf2(a: f128) callconv(.C) common.F16T { | |
| 11 | return @bitCast(common.F16T, truncf(f16, f128, a)); | |
| 10 | pub fn __trunctfhf2(a: f128) callconv(.C) common.F16T(f128) { | |
| 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 | 7 | @export(__truncxfhf2, .{ .name = "__truncxfhf2", .linkage = common.linkage, .visibility = common.visibility }); |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | fn __truncxfhf2(a: f80) callconv(.C) common.F16T { | |
| 11 | return @bitCast(common.F16T, trunc_f80(f16, a)); | |
| 10 | fn __truncxfhf2(a: f80) callconv(.C) common.F16T(f80) { | |
| 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 | 2873 | #undef zig_init_special_f16 |
| 2874 | 2874 | #define zig_init_special_f16(sign, name, arg, repr) repr |
| 2875 | 2875 | #endif |
| 2876 | #if __APPLE__ | |
| 2877 | typedef zig_repr_f16 zig_compiler_rt_f16; | |
| 2878 | #else | |
| 2879 | typedef zig_f16 zig_compiler_rt_f16; | |
| 2880 | #endif | |
| 2881 | #define zig_compiler_rt_abbrev_zig_compiler_rt_f16 zig_compiler_rt_abbrev_zig_f16 | |
| 2876 | 2882 | |
| 2877 | 2883 | #define zig_has_f32 1 |
| 2878 | 2884 | #define zig_bitSizeOf_f32 32 |
| ... | ... | @@ -3088,15 +3094,15 @@ zig_float_from_repr(f128) |
| 3088 | 3094 | #define zig_convert_builtin(ResType, operation, ArgType, version) \ |
| 3089 | 3095 | zig_extern ResType zig_expand_concat(zig_expand_concat(zig_expand_concat(__##operation, \ |
| 3090 | 3096 | zig_compiler_rt_abbrev_##ArgType), zig_compiler_rt_abbrev_##ResType), version)(ArgType); |
| 3091 | zig_convert_builtin(zig_f16, trunc, zig_f32, 2) | |
| 3092 | zig_convert_builtin(zig_f16, trunc, zig_f64, 2) | |
| 3097 | zig_convert_builtin(zig_compiler_rt_f16, trunc, zig_f32, 2) | |
| 3098 | zig_convert_builtin(zig_compiler_rt_f16, trunc, zig_f64, 2) | |
| 3093 | 3099 | zig_convert_builtin(zig_f16, trunc, zig_f80, 2) |
| 3094 | 3100 | zig_convert_builtin(zig_f16, trunc, zig_f128, 2) |
| 3095 | zig_convert_builtin(zig_f32, extend, zig_f16, 2) | |
| 3101 | zig_convert_builtin(zig_f32, extend, zig_compiler_rt_f16, 2) | |
| 3096 | 3102 | zig_convert_builtin(zig_f32, trunc, zig_f64, 2) |
| 3097 | 3103 | zig_convert_builtin(zig_f32, trunc, zig_f80, 2) |
| 3098 | 3104 | zig_convert_builtin(zig_f32, trunc, zig_f128, 2) |
| 3099 | zig_convert_builtin(zig_f64, extend, zig_f16, 2) | |
| 3105 | zig_convert_builtin(zig_f64, extend, zig_compiler_rt_f16, 2) | |
| 3100 | 3106 | zig_convert_builtin(zig_f64, extend, zig_f32, 2) |
| 3101 | 3107 | zig_convert_builtin(zig_f64, trunc, zig_f80, 2) |
| 3102 | 3108 | zig_convert_builtin(zig_f64, trunc, zig_f128, 2) |