| author | |
| committer | |
| log | 0d533433e21621177fb291e2a4901bee11834501 |
| tree | efaaac92422e01ea10df243c9bd56a3ff300bda0 |
| parent | aedafb20cf32caea453b648cd19b7c82e993d02d |
This change also exposes some of the existing functions under both the
PPC-style names symbols and the compiler-rt-style names, since Zig
currently lowers softfloat calls to the latter.15 files changed, 203 insertions(+), 25 deletions(-)
lib/compiler_rt.zig+17-7| ... | ... | @@ -4,17 +4,20 @@ comptime { |
| 4 | 4 | _ = @import("compiler_rt/atomics.zig"); |
| 5 | 5 | |
| 6 | 6 | _ = @import("compiler_rt/addf3.zig"); |
| 7 | _ = @import("compiler_rt/addhf3.zig"); | |
| 7 | 8 | _ = @import("compiler_rt/addsf3.zig"); |
| 8 | 9 | _ = @import("compiler_rt/adddf3.zig"); |
| 9 | 10 | _ = @import("compiler_rt/addtf3.zig"); |
| 10 | 11 | _ = @import("compiler_rt/addxf3.zig"); |
| 11 | 12 | |
| 13 | _ = @import("compiler_rt/subhf3.zig"); | |
| 12 | 14 | _ = @import("compiler_rt/subsf3.zig"); |
| 13 | 15 | _ = @import("compiler_rt/subdf3.zig"); |
| 14 | 16 | _ = @import("compiler_rt/subtf3.zig"); |
| 15 | 17 | _ = @import("compiler_rt/subxf3.zig"); |
| 16 | 18 | |
| 17 | 19 | _ = @import("compiler_rt/mulf3.zig"); |
| 20 | _ = @import("compiler_rt/mulhf3.zig"); | |
| 18 | 21 | _ = @import("compiler_rt/mulsf3.zig"); |
| 19 | 22 | _ = @import("compiler_rt/muldf3.zig"); |
| 20 | 23 | _ = @import("compiler_rt/multf3.zig"); |
| ... | ... | @@ -34,51 +37,58 @@ comptime { |
| 34 | 37 | _ = @import("compiler_rt/divxc3.zig"); |
| 35 | 38 | _ = @import("compiler_rt/divtc3.zig"); |
| 36 | 39 | |
| 40 | _ = @import("compiler_rt/neghf2.zig"); | |
| 37 | 41 | _ = @import("compiler_rt/negsf2.zig"); |
| 38 | 42 | _ = @import("compiler_rt/negdf2.zig"); |
| 39 | 43 | _ = @import("compiler_rt/negtf2.zig"); |
| 40 | 44 | _ = @import("compiler_rt/negxf2.zig"); |
| 41 | 45 | |
| 42 | 46 | _ = @import("compiler_rt/comparef.zig"); |
| 47 | _ = @import("compiler_rt/cmphf2.zig"); | |
| 43 | 48 | _ = @import("compiler_rt/cmpsf2.zig"); |
| 44 | 49 | _ = @import("compiler_rt/cmpdf2.zig"); |
| 45 | 50 | _ = @import("compiler_rt/cmptf2.zig"); |
| 46 | 51 | _ = @import("compiler_rt/cmpxf2.zig"); |
| 52 | _ = @import("compiler_rt/gehf2.zig"); | |
| 47 | 53 | _ = @import("compiler_rt/gesf2.zig"); |
| 48 | 54 | _ = @import("compiler_rt/gedf2.zig"); |
| 49 | _ = @import("compiler_rt/getf2.zig"); | |
| 50 | 55 | _ = @import("compiler_rt/gexf2.zig"); |
| 56 | _ = @import("compiler_rt/getf2.zig"); | |
| 57 | _ = @import("compiler_rt/unordhf2.zig"); | |
| 51 | 58 | _ = @import("compiler_rt/unordsf2.zig"); |
| 52 | 59 | _ = @import("compiler_rt/unorddf2.zig"); |
| 60 | _ = @import("compiler_rt/unordxf2.zig"); | |
| 53 | 61 | _ = @import("compiler_rt/unordtf2.zig"); |
| 54 | 62 | |
| 55 | 63 | _ = @import("compiler_rt/extendf.zig"); |
| 56 | _ = @import("compiler_rt/extenddftf2.zig"); | |
| 57 | _ = @import("compiler_rt/extenddfxf2.zig"); | |
| 58 | 64 | _ = @import("compiler_rt/extendhfsf2.zig"); |
| 65 | _ = @import("compiler_rt/extendhfdf2.zig"); | |
| 59 | 66 | _ = @import("compiler_rt/extendhftf2.zig"); |
| 60 | 67 | _ = @import("compiler_rt/extendhfxf2.zig"); |
| 61 | 68 | _ = @import("compiler_rt/extendsfdf2.zig"); |
| 62 | 69 | _ = @import("compiler_rt/extendsftf2.zig"); |
| 63 | 70 | _ = @import("compiler_rt/extendsfxf2.zig"); |
| 71 | _ = @import("compiler_rt/extenddftf2.zig"); | |
| 72 | _ = @import("compiler_rt/extenddfxf2.zig"); | |
| 64 | 73 | _ = @import("compiler_rt/extendxftf2.zig"); |
| 65 | 74 | |
| 66 | 75 | _ = @import("compiler_rt/truncf.zig"); |
| 67 | 76 | _ = @import("compiler_rt/truncsfhf2.zig"); |
| 68 | 77 | _ = @import("compiler_rt/truncdfhf2.zig"); |
| 69 | 78 | _ = @import("compiler_rt/truncdfsf2.zig"); |
| 79 | _ = @import("compiler_rt/truncxfhf2.zig"); | |
| 80 | _ = @import("compiler_rt/truncxfsf2.zig"); | |
| 81 | _ = @import("compiler_rt/truncxfdf2.zig"); | |
| 70 | 82 | _ = @import("compiler_rt/trunctfhf2.zig"); |
| 71 | 83 | _ = @import("compiler_rt/trunctfsf2.zig"); |
| 72 | 84 | _ = @import("compiler_rt/trunctfdf2.zig"); |
| 73 | 85 | _ = @import("compiler_rt/trunctfxf2.zig"); |
| 74 | _ = @import("compiler_rt/truncxfhf2.zig"); | |
| 75 | _ = @import("compiler_rt/truncxfsf2.zig"); | |
| 76 | _ = @import("compiler_rt/truncxfdf2.zig"); | |
| 77 | 86 | |
| 78 | _ = @import("compiler_rt/divtf3.zig"); | |
| 87 | _ = @import("compiler_rt/divhf3.zig"); | |
| 79 | 88 | _ = @import("compiler_rt/divsf3.zig"); |
| 80 | 89 | _ = @import("compiler_rt/divdf3.zig"); |
| 81 | 90 | _ = @import("compiler_rt/divxf3.zig"); |
| 91 | _ = @import("compiler_rt/divtf3.zig"); | |
| 82 | 92 | _ = @import("compiler_rt/sin.zig"); |
| 83 | 93 | _ = @import("compiler_rt/cos.zig"); |
| 84 | 94 | _ = @import("compiler_rt/sincos.zig"); |
lib/compiler_rt/addhf3.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | const common = @import("./common.zig"); | |
| 2 | const addf3 = @import("./addf3.zig").addf3; | |
| 3 | ||
| 4 | pub const panic = common.panic; | |
| 5 | ||
| 6 | comptime { | |
| 7 | @export(__addhf3, .{ .name = "__addhf3", .linkage = common.linkage }); | |
| 8 | } | |
| 9 | ||
| 10 | fn __addhf3(a: f16, b: f16) callconv(.C) f16 { | |
| 11 | return addf3(f16, a, b); | |
| 12 | } |
lib/compiler_rt/cmphf2.zig created+50| ... | ... | @@ -0,0 +1,50 @@ |
| 1 | ///! The quoted behavior definitions are from | |
| 2 | ///! https://gcc.gnu.org/onlinedocs/gcc-12.1.0/gccint/Soft-float-library-routines.html#Soft-float-library-routines | |
| 3 | const common = @import("./common.zig"); | |
| 4 | const comparef = @import("./comparef.zig"); | |
| 5 | ||
| 6 | pub const panic = common.panic; | |
| 7 | ||
| 8 | comptime { | |
| 9 | @export(__eqhf2, .{ .name = "__eqhf2", .linkage = common.linkage }); | |
| 10 | @export(__nehf2, .{ .name = "__nehf2", .linkage = common.linkage }); | |
| 11 | @export(__lehf2, .{ .name = "__lehf2", .linkage = common.linkage }); | |
| 12 | @export(__cmphf2, .{ .name = "__cmphf2", .linkage = common.linkage }); | |
| 13 | @export(__lthf2, .{ .name = "__lthf2", .linkage = common.linkage }); | |
| 14 | } | |
| 15 | ||
| 16 | /// "These functions calculate a <=> b. That is, if a is less than b, they return -1; | |
| 17 | /// if a is greater than b, they return 1; and if a and b are equal they return 0. | |
| 18 | /// If either argument is NaN they return 1..." | |
| 19 | /// | |
| 20 | /// Note that this matches the definition of `__lehf2`, `__eqhf2`, `__nehf2`, `__cmphf2`, | |
| 21 | /// and `__lthf2`. | |
| 22 | fn __cmphf2(a: f16, b: f16) callconv(.C) i32 { | |
| 23 | return @enumToInt(comparef.cmpf2(f16, comparef.LE, a, b)); | |
| 24 | } | |
| 25 | ||
| 26 | /// "These functions return a value less than or equal to zero if neither argument is NaN, | |
| 27 | /// and a is less than or equal to b." | |
| 28 | pub fn __lehf2(a: f16, b: f16) callconv(.C) i32 { | |
| 29 | return __cmphf2(a, b); | |
| 30 | } | |
| 31 | ||
| 32 | /// "These functions return zero if neither argument is NaN, and a and b are equal." | |
| 33 | /// Note that due to some kind of historical accident, __eqhf2 and __nehf2 are defined | |
| 34 | /// to have the same return value. | |
| 35 | pub fn __eqhf2(a: f16, b: f16) callconv(.C) i32 { | |
| 36 | return __cmphf2(a, b); | |
| 37 | } | |
| 38 | ||
| 39 | /// "These functions return a nonzero value if either argument is NaN, or if a and b are unequal." | |
| 40 | /// Note that due to some kind of historical accident, __eqhf2 and __nehf2 are defined | |
| 41 | /// to have the same return value. | |
| 42 | pub fn __nehf2(a: f16, b: f16) callconv(.C) i32 { | |
| 43 | return __cmphf2(a, b); | |
| 44 | } | |
| 45 | ||
| 46 | /// "These functions return a value less than zero if neither argument is NaN, and a | |
| 47 | /// is strictly less than b." | |
| 48 | pub fn __lthf2(a: f16, b: f16) callconv(.C) i32 { | |
| 49 | return __cmphf2(a, b); | |
| 50 | } |
lib/compiler_rt/divhf3.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | const common = @import("common.zig"); | |
| 2 | const divsf3 = @import("./divsf3.zig"); | |
| 3 | ||
| 4 | comptime { | |
| 5 | @export(__divhf3, .{ .name = "__divhf3", .linkage = common.linkage }); | |
| 6 | } | |
| 7 | ||
| 8 | pub fn __divhf3(a: f16, b: f16) callconv(.C) f16 { | |
| 9 | // TODO: more efficient implementation | |
| 10 | return @floatCast(f16, divsf3.__divsf3(a, b)); | |
| 11 | } |
lib/compiler_rt/extendhfdf2.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | const common = @import("./common.zig"); | |
| 2 | const extendf = @import("./extendf.zig").extendf; | |
| 3 | ||
| 4 | pub const panic = common.panic; | |
| 5 | ||
| 6 | comptime { | |
| 7 | @export(__extendhfdf2, .{ .name = "__extendhfdf2", .linkage = common.linkage }); | |
| 8 | } | |
| 9 | ||
| 10 | pub fn __extendhfdf2(a: common.F16T) callconv(.C) f64 { | |
| 11 | return extendf(f64, f16, @bitCast(u16, a)); | |
| 12 | } |
lib/compiler_rt/extendhfsf2.zig+2-7| ... | ... | @@ -5,22 +5,17 @@ pub const panic = common.panic; |
| 5 | 5 | |
| 6 | 6 | comptime { |
| 7 | 7 | if (common.gnu_f16_abi) { |
| 8 | @export(__gnu_h2f_ieee, .{ .name = "__gnu_h2f_ieee", .linkage = common.linkage }); | |
| 8 | @export(__extendhfsf2, .{ .name = "__gnu_h2f_ieee", .linkage = common.linkage }); | |
| 9 | 9 | } else if (common.want_aeabi) { |
| 10 | 10 | @export(__aeabi_h2f, .{ .name = "__aeabi_h2f", .linkage = common.linkage }); |
| 11 | } else { | |
| 12 | @export(__extendhfsf2, .{ .name = "__extendhfsf2", .linkage = common.linkage }); | |
| 13 | 11 | } |
| 12 | @export(__extendhfsf2, .{ .name = "__extendhfsf2", .linkage = common.linkage }); | |
| 14 | 13 | } |
| 15 | 14 | |
| 16 | 15 | pub fn __extendhfsf2(a: common.F16T) callconv(.C) f32 { |
| 17 | 16 | return extendf(f32, f16, @bitCast(u16, a)); |
| 18 | 17 | } |
| 19 | 18 | |
| 20 | fn __gnu_h2f_ieee(a: common.F16T) callconv(.C) f32 { | |
| 21 | return extendf(f32, f16, @bitCast(u16, a)); | |
| 22 | } | |
| 23 | ||
| 24 | 19 | fn __aeabi_h2f(a: u16) callconv(.AAPCS) f32 { |
| 25 | 20 | return extendf(f32, f16, @bitCast(u16, a)); |
| 26 | 21 | } |
lib/compiler_rt/gehf2.zig created+31| ... | ... | @@ -0,0 +1,31 @@ |
| 1 | ///! The quoted behavior definitions are from | |
| 2 | ///! https://gcc.gnu.org/onlinedocs/gcc-12.1.0/gccint/Soft-float-library-routines.html#Soft-float-library-routines | |
| 3 | const common = @import("./common.zig"); | |
| 4 | const comparef = @import("./comparef.zig"); | |
| 5 | ||
| 6 | pub const panic = common.panic; | |
| 7 | ||
| 8 | comptime { | |
| 9 | @export(__gehf2, .{ .name = "__gehf2", .linkage = common.linkage }); | |
| 10 | @export(__gthf2, .{ .name = "__gthf2", .linkage = common.linkage }); | |
| 11 | } | |
| 12 | ||
| 13 | /// "These functions return a value greater than or equal to zero if neither | |
| 14 | /// argument is NaN, and a is greater than or equal to b." | |
| 15 | pub fn __gehf2(a: f16, b: f16) callconv(.C) i32 { | |
| 16 | return @enumToInt(comparef.cmpf2(f16, comparef.GE, a, b)); | |
| 17 | } | |
| 18 | ||
| 19 | /// "These functions return a value greater than zero if neither argument is NaN, | |
| 20 | /// and a is strictly greater than b." | |
| 21 | pub fn __gthf2(a: f16, b: f16) callconv(.C) i32 { | |
| 22 | return __gehf2(a, b); | |
| 23 | } | |
| 24 | ||
| 25 | fn __aeabi_fcmpge(a: f16, b: f16) callconv(.AAPCS) i32 { | |
| 26 | return @boolToInt(comparef.cmpf2(f16, comparef.GE, a, b) != .Less); | |
| 27 | } | |
| 28 | ||
| 29 | fn __aeabi_fcmpgt(a: f16, b: f16) callconv(.AAPCS) i32 { | |
| 30 | return @boolToInt(comparef.cmpf2(f16, comparef.LE, a, b) == .Greater); | |
| 31 | } |
lib/compiler_rt/mulf3.zig+3-2| ... | ... | @@ -32,8 +32,9 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T { |
| 32 | 32 | const infRep = @bitCast(Z, math.inf(T)); |
| 33 | 33 | const minNormalRep = @bitCast(Z, math.floatMin(T)); |
| 34 | 34 | |
| 35 | const aExponent = @truncate(u32, (@bitCast(Z, a) >> significandBits) & maxExponent); | |
| 36 | const bExponent = @truncate(u32, (@bitCast(Z, b) >> significandBits) & maxExponent); | |
| 35 | const ZExp = if (typeWidth >= 32) u32 else Z; | |
| 36 | const aExponent = @truncate(ZExp, (@bitCast(Z, a) >> significandBits) & maxExponent); | |
| 37 | const bExponent = @truncate(ZExp, (@bitCast(Z, b) >> significandBits) & maxExponent); | |
| 37 | 38 | const productSign: Z = (@bitCast(Z, a) ^ @bitCast(Z, b)) & signBit; |
| 38 | 39 | |
| 39 | 40 | var aSignificand: ZSignificand = @intCast(ZSignificand, @bitCast(Z, a) & significandMask); |
lib/compiler_rt/mulhf3.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | const common = @import("./common.zig"); | |
| 2 | const mulf3 = @import("./mulf3.zig").mulf3; | |
| 3 | ||
| 4 | pub const panic = common.panic; | |
| 5 | ||
| 6 | comptime { | |
| 7 | @export(__mulhf3, .{ .name = "__mulhf3", .linkage = common.linkage }); | |
| 8 | } | |
| 9 | ||
| 10 | pub fn __mulhf3(a: f16, b: f16) callconv(.C) f16 { | |
| 11 | return mulf3(f16, a, b); | |
| 12 | } |
lib/compiler_rt/neghf2.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | const common = @import("./common.zig"); | |
| 2 | ||
| 3 | pub const panic = common.panic; | |
| 4 | ||
| 5 | comptime { | |
| 6 | @export(__neghf2, .{ .name = "__neghf2", .linkage = common.linkage }); | |
| 7 | } | |
| 8 | ||
| 9 | fn __neghf2(a: f16) callconv(.C) f16 { | |
| 10 | return common.fneg(a); | |
| 11 | } |
lib/compiler_rt/subhf3.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | const common = @import("./common.zig"); | |
| 2 | ||
| 3 | pub const panic = common.panic; | |
| 4 | ||
| 5 | comptime { | |
| 6 | @export(__subhf3, .{ .name = "__subhf3", .linkage = common.linkage }); | |
| 7 | } | |
| 8 | ||
| 9 | fn __subhf3(a: f16, b: f16) callconv(.C) f16 { | |
| 10 | const neg_b = @bitCast(f16, @bitCast(u16, b) ^ (@as(u16, 1) << 15)); | |
| 11 | return a + neg_b; | |
| 12 | } |
lib/compiler_rt/tan.zig+4-2| ... | ... | @@ -24,8 +24,10 @@ comptime { |
| 24 | 24 | @export(tanf, .{ .name = "tanf", .linkage = common.linkage }); |
| 25 | 25 | @export(tan, .{ .name = "tan", .linkage = common.linkage }); |
| 26 | 26 | @export(__tanx, .{ .name = "__tanx", .linkage = common.linkage }); |
| 27 | const tanq_sym_name = if (common.want_ppc_abi) "tanf128" else "tanq"; | |
| 28 | @export(tanq, .{ .name = tanq_sym_name, .linkage = common.linkage }); | |
| 27 | if (common.want_ppc_abi) { | |
| 28 | @export(tanq, .{ .name = "tanf128", .linkage = common.linkage }); | |
| 29 | } | |
| 30 | @export(tanq, .{ .name = "tanq", .linkage = common.linkage }); | |
| 29 | 31 | @export(tanl, .{ .name = "tanl", .linkage = common.linkage }); |
| 30 | 32 | } |
| 31 | 33 |
lib/compiler_rt/truncsfhf2.zig+2-7| ... | ... | @@ -5,22 +5,17 @@ pub const panic = common.panic; |
| 5 | 5 | |
| 6 | 6 | comptime { |
| 7 | 7 | if (common.gnu_f16_abi) { |
| 8 | @export(__gnu_f2h_ieee, .{ .name = "__gnu_f2h_ieee", .linkage = common.linkage }); | |
| 8 | @export(__truncsfhf2, .{ .name = "__gnu_f2h_ieee", .linkage = common.linkage }); | |
| 9 | 9 | } else if (common.want_aeabi) { |
| 10 | 10 | @export(__aeabi_f2h, .{ .name = "__aeabi_f2h", .linkage = common.linkage }); |
| 11 | } else { | |
| 12 | @export(__truncsfhf2, .{ .name = "__truncsfhf2", .linkage = common.linkage }); | |
| 13 | 11 | } |
| 12 | @export(__truncsfhf2, .{ .name = "__truncsfhf2", .linkage = common.linkage }); | |
| 14 | 13 | } |
| 15 | 14 | |
| 16 | 15 | pub fn __truncsfhf2(a: f32) callconv(.C) common.F16T { |
| 17 | 16 | return @bitCast(common.F16T, truncf(f16, f32, a)); |
| 18 | 17 | } |
| 19 | 18 | |
| 20 | fn __gnu_f2h_ieee(a: f32) callconv(.C) common.F16T { | |
| 21 | return @bitCast(common.F16T, truncf(f16, f32, a)); | |
| 22 | } | |
| 23 | ||
| 24 | 19 | fn __aeabi_f2h(a: f32) callconv(.AAPCS) u16 { |
| 25 | 20 | return @bitCast(common.F16T, truncf(f16, f32, a)); |
| 26 | 21 | } |
lib/compiler_rt/unordhf2.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | const common = @import("./common.zig"); | |
| 2 | const comparef = @import("./comparef.zig"); | |
| 3 | ||
| 4 | pub const panic = common.panic; | |
| 5 | ||
| 6 | comptime { | |
| 7 | @export(__unordhf2, .{ .name = "__unordhf2", .linkage = common.linkage }); | |
| 8 | } | |
| 9 | ||
| 10 | pub fn __unordhf2(a: f16, b: f16) callconv(.C) i32 { | |
| 11 | return comparef.unordcmp(f16, a, b); | |
| 12 | } |
lib/compiler_rt/unordxf2.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | const common = @import("./common.zig"); | |
| 2 | const comparef = @import("./comparef.zig"); | |
| 3 | ||
| 4 | pub const panic = common.panic; | |
| 5 | ||
| 6 | comptime { | |
| 7 | @export(__unordxf2, .{ .name = "__unordxf2", .linkage = common.linkage }); | |
| 8 | } | |
| 9 | ||
| 10 | pub fn __unordxf2(a: f80, b: f80) callconv(.C) i32 { | |
| 11 | return comparef.unordcmp(f80, a, b); | |
| 12 | } |