| ... | @@ -6,7 +6,9 @@ | ... | @@ -6,7 +6,9 @@ |
| 6 | | 6 | |
| 7 | const std = @import("std"); | 7 | const std = @import("std"); |
| 8 | const builtin = @import("builtin"); | 8 | const builtin = @import("builtin"); |
| | 9 | const math = std.math; |
| 9 | const native_os = builtin.os.tag; | 10 | const native_os = builtin.os.tag; |
| | 11 | const long_double_is_f128 = builtin.target.longDoubleIsF128(); |
| 10 | | 12 | |
| 11 | comptime { | 13 | comptime { |
| 12 | // When the self-hosted compiler is further along, all the logic from c_stage1.zig will | 14 | // When the self-hosted compiler is further along, all the logic from c_stage1.zig will |
| ... | @@ -15,6 +17,9 @@ comptime { | ... | @@ -15,6 +17,9 @@ comptime { |
| 15 | if (builtin.zig_backend != .stage1) { | 17 | if (builtin.zig_backend != .stage1) { |
| 16 | @export(memset, .{ .name = "memset", .linkage = .Strong }); | 18 | @export(memset, .{ .name = "memset", .linkage = .Strong }); |
| 17 | @export(memcpy, .{ .name = "memcpy", .linkage = .Strong }); | 19 | @export(memcpy, .{ .name = "memcpy", .linkage = .Strong }); |
| | 20 | @export(trunc, .{ .name = "trunc", .linkage = .Strong }); |
| | 21 | @export(truncf, .{ .name = "truncf", .linkage = .Strong }); |
| | 22 | @export(truncl, .{ .name = "truncl", .linkage = .Strong }); |
| 18 | } else { | 23 | } else { |
| 19 | _ = @import("c_stage1.zig"); | 24 | _ = @import("c_stage1.zig"); |
| 20 | } | 25 | } |
| ... | @@ -74,3 +79,18 @@ fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, len: usize) callconv( | ... | @@ -74,3 +79,18 @@ fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, len: usize) callconv( |
| 74 | | 79 | |
| 75 | return dest; | 80 | return dest; |
| 76 | } | 81 | } |
| | 82 | |
| | 83 | fn trunc(a: f64) f64 { |
| | 84 | return math.trunc(a); |
| | 85 | } |
| | 86 | |
| | 87 | fn truncf(a: f32) f32 { |
| | 88 | return math.trunc(a); |
| | 89 | } |
| | 90 | |
| | 91 | fn truncl(a: c_longdouble) c_longdouble { |
| | 92 | if (!long_double_is_f128) { |
| | 93 | @panic("TODO implement this"); |
| | 94 | } |
| | 95 | return math.trunc(a); |
| | 96 | } |