authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-10-05 18:17:55-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-10-05 18:19:31-07:00
log01ad6c0b020193a6c5c82e13296a12e847f78d05
treeaaa1c6c428a0e0578efa1dce73c336cd682a4734
parent5518a0aff2ab023e9021b74a0a14eb9fcfc094cc

freestanding libc: don't rely on compiler_rt symbols we don't have yet

Previous commit made fmal depend on __extendxftf2 and __trunctfxf2 but we don't have implementations of those yet.

5 files changed, 32 insertions(+), 0 deletions(-)

lib/std/special/c_stage1.zig+4
...@@ -5,6 +5,7 @@ const isNan = std.math.isNan;...@@ -5,6 +5,7 @@ const isNan = std.math.isNan;
5const native_arch = builtin.cpu.arch;5const native_arch = builtin.cpu.arch;
6const native_abi = builtin.abi;6const native_abi = builtin.abi;
7const native_os = builtin.os.tag;7const native_os = builtin.os.tag;
8const long_double_is_f128 = builtin.target.longDoubleIsF128();
89
9const is_wasm = switch (native_arch) {10const is_wasm = switch (native_arch) {
10 .wasm32, .wasm64 => true,11 .wasm32, .wasm64 => true,
...@@ -657,6 +658,9 @@ export fn ceil(x: f64) f64 {...@@ -657,6 +658,9 @@ export fn ceil(x: f64) f64 {
657}658}
658659
659export fn fmal(a: c_longdouble, b: c_longdouble, c: c_longdouble) c_longdouble {660export fn fmal(a: c_longdouble, b: c_longdouble, c: c_longdouble) c_longdouble {
661 if (!long_double_is_f128) {
662 @panic("TODO implement this");
663 }
660 return math.fma(c_longdouble, a, b, c);664 return math.fma(c_longdouble, a, b, c);
661}665}
662666
lib/std/special/compiler_rt.zig+11
...@@ -18,6 +18,8 @@ const strong_linkage = if (is_test)...@@ -18,6 +18,8 @@ const strong_linkage = if (is_test)
18else18else
19 std.builtin.GlobalLinkage.Strong;19 std.builtin.GlobalLinkage.Strong;
2020
21const long_double_is_f128 = builtin.target.longDoubleIsF128();
22
21comptime {23comptime {
22 const __extenddftf2 = @import("compiler_rt/extendXfYf2.zig").__extenddftf2;24 const __extenddftf2 = @import("compiler_rt/extendXfYf2.zig").__extenddftf2;
23 @export(__extenddftf2, .{ .name = "__extenddftf2", .linkage = linkage });25 @export(__extenddftf2, .{ .name = "__extenddftf2", .linkage = linkage });
...@@ -75,6 +77,15 @@ comptime {...@@ -75,6 +77,15 @@ comptime {
75 }77 }
7678
77 if (!builtin.zig_is_stage2) {79 if (!builtin.zig_is_stage2) {
80 if (!long_double_is_f128) {
81 // TODO implement these
82 //const __extendxftf2 = @import("compiler_rt/extendXfYf2.zig").__extendxftf2;
83 //@export(__extendxftf2, .{ .name = "__extendxftf2", .linkage = linkage });
84
85 //const __trunctfxf2 = @import("compiler_rt/truncXfYf2.zig").__trunctfxf2;
86 //@export(__trunctfxf2, .{ .name = "__trunctfxf2", .linkage = linkage });
87 }
88
78 switch (arch) {89 switch (arch) {
79 .i386,90 .i386,
80 .x86_64,91 .x86_64,
lib/std/special/compiler_rt/extendXfYf2.zig+5
...@@ -22,6 +22,11 @@ pub fn __extendhftf2(a: u16) callconv(.C) f128 {...@@ -22,6 +22,11 @@ pub fn __extendhftf2(a: u16) callconv(.C) f128 {
22 return extendXfYf2(f128, f16, a);22 return extendXfYf2(f128, f16, a);
23}23}
2424
25pub fn __extendxftf2(a: c_longdouble) callconv(.C) f128 {
26 _ = a;
27 @panic("TODO implement");
28}
29
25pub fn __aeabi_h2f(arg: u16) callconv(.AAPCS) f32 {30pub fn __aeabi_h2f(arg: u16) callconv(.AAPCS) f32 {
26 @setRuntimeSafety(false);31 @setRuntimeSafety(false);
27 return @call(.{ .modifier = .always_inline }, __extendhfsf2, .{arg});32 return @call(.{ .modifier = .always_inline }, __extendhfsf2, .{arg});
lib/std/special/compiler_rt/truncXfYf2.zig+5
...@@ -20,6 +20,11 @@ pub fn __trunctfdf2(a: f128) callconv(.C) f64 {...@@ -20,6 +20,11 @@ pub fn __trunctfdf2(a: f128) callconv(.C) f64 {
20 return @call(.{ .modifier = .always_inline }, truncXfYf2, .{ f64, f128, a });20 return @call(.{ .modifier = .always_inline }, truncXfYf2, .{ f64, f128, a });
21}21}
2222
23pub fn __trunctfxf2(a: f128) callconv(.C) c_longdouble {
24 _ = a;
25 @panic("TODO implement");
26}
27
23pub fn __truncdfsf2(a: f64) callconv(.C) f32 {28pub fn __truncdfsf2(a: f64) callconv(.C) f32 {
24 return @call(.{ .modifier = .always_inline }, truncXfYf2, .{ f32, f64, a });29 return @call(.{ .modifier = .always_inline }, truncXfYf2, .{ f32, f64, a });
25}30}
lib/std/target.zig+7
...@@ -1712,6 +1712,13 @@ pub const Target = struct {...@@ -1712,6 +1712,13 @@ pub const Target = struct {
1712 else => ".X",1712 else => ".X",
1713 };1713 };
1714 }1714 }
1715
1716 pub inline fn longDoubleIsF128(target: Target) bool {
1717 return switch (target.cpu.arch) {
1718 .riscv64, .aarch64, .aarch64_be, .aarch64_32, .s390x, .mips64, .mips64el => true,
1719 else => false,
1720 };
1721 }
1715};1722};
17161723
1717test {1724test {