aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/compiler_rt.zig12
-rw-r--r--lib/compiler_rt/common.zig12
-rw-r--r--lib/compiler_rt/negXf2.zig42
-rw-r--r--lib/compiler_rt/negdf2.zig19
-rw-r--r--lib/compiler_rt/negsf2.zig19
-rw-r--r--lib/compiler_rt/negtf2.zig11
-rw-r--r--lib/compiler_rt/negxf2.zig11
-rw-r--r--lib/std/fmt.zig2
-rw-r--r--lib/std/math/copysign.zig1
-rw-r--r--lib/std/math/signbit.zig1
10 files changed, 80 insertions, 50 deletions
diff --git a/lib/compiler_rt.zig b/lib/compiler_rt.zig
index 3216fcc357..105c5ed7ad 100644
--- a/lib/compiler_rt.zig
+++ b/lib/compiler_rt.zig
@@ -4,12 +4,13 @@ comptime {
_ = @import("compiler_rt/atomics.zig");
_ = @import("compiler_rt/addf3.zig");
- _ = @import("compiler_rt/adddf3.zig");
_ = @import("compiler_rt/addsf3.zig");
+ _ = @import("compiler_rt/adddf3.zig");
_ = @import("compiler_rt/addtf3.zig");
_ = @import("compiler_rt/addxf3.zig");
- _ = @import("compiler_rt/subdf3.zig");
+
_ = @import("compiler_rt/subsf3.zig");
+ _ = @import("compiler_rt/subdf3.zig");
_ = @import("compiler_rt/subtf3.zig");
_ = @import("compiler_rt/subxf3.zig");
@@ -19,6 +20,11 @@ comptime {
_ = @import("compiler_rt/multf3.zig");
_ = @import("compiler_rt/mulxf3.zig");
+ _ = @import("compiler_rt/negsf2.zig");
+ _ = @import("compiler_rt/negdf2.zig");
+ _ = @import("compiler_rt/negtf2.zig");
+ _ = @import("compiler_rt/negxf2.zig");
+
_ = @import("compiler_rt/comparef.zig");
_ = @import("compiler_rt/cmpsf2.zig");
_ = @import("compiler_rt/cmpdf2.zig");
@@ -172,8 +178,6 @@ comptime {
_ = @import("compiler_rt/mulo.zig");
_ = @import("compiler_rt/cmp.zig");
- _ = @import("compiler_rt/negXf2.zig");
-
_ = @import("compiler_rt/os_version_check.zig");
_ = @import("compiler_rt/emutls.zig");
_ = @import("compiler_rt/arm.zig");
diff --git a/lib/compiler_rt/common.zig b/lib/compiler_rt/common.zig
index b6e4a5d311..538b237e5e 100644
--- a/lib/compiler_rt/common.zig
+++ b/lib/compiler_rt/common.zig
@@ -188,3 +188,15 @@ pub fn normalize(comptime T: type, significand: *std.meta.Int(.unsigned, @typeIn
significand.* <<= @intCast(std.math.Log2Int(Z), shift);
return @as(i32, 1) - shift;
}
+
+pub inline fn fneg(a: anytype) @TypeOf(a) {
+ const F = @TypeOf(a);
+ const bits = @typeInfo(F).Float.bits;
+ const U = @Type(.{ .Int = .{
+ .signedness = .unsigned,
+ .bits = bits,
+ } });
+ const sign_bit_mask = @as(U, 1) << (bits - 1);
+ const negated = @bitCast(U, a) ^ sign_bit_mask;
+ return @bitCast(F, negated);
+}
diff --git a/lib/compiler_rt/negXf2.zig b/lib/compiler_rt/negXf2.zig
deleted file mode 100644
index bcff3660f4..0000000000
--- a/lib/compiler_rt/negXf2.zig
+++ /dev/null
@@ -1,42 +0,0 @@
-const std = @import("std");
-const builtin = @import("builtin");
-const common = @import("common.zig");
-
-pub const panic = common.panic;
-
-comptime {
- if (common.want_aeabi) {
- @export(__aeabi_fneg, .{ .name = "__aeabi_fneg", .linkage = common.linkage });
- @export(__aeabi_dneg, .{ .name = "__aeabi_dneg", .linkage = common.linkage });
- } else {
- @export(__negsf2, .{ .name = "__negsf2", .linkage = common.linkage });
- @export(__negdf2, .{ .name = "__negdf2", .linkage = common.linkage });
- }
-}
-
-pub fn __negsf2(a: f32) callconv(.C) f32 {
- return negXf2(f32, a);
-}
-
-fn __aeabi_fneg(a: f32) callconv(.AAPCS) f32 {
- return negXf2(f32, a);
-}
-
-pub fn __negdf2(a: f64) callconv(.C) f64 {
- return negXf2(f64, a);
-}
-
-fn __aeabi_dneg(a: f64) callconv(.AAPCS) f64 {
- return negXf2(f64, a);
-}
-
-inline fn negXf2(comptime T: type, a: T) T {
- const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
-
- const significandBits = std.math.floatMantissaBits(T);
- const exponentBits = std.math.floatExponentBits(T);
-
- const signBit = (@as(Z, 1) << (significandBits + exponentBits));
-
- return @bitCast(T, @bitCast(Z, a) ^ signBit);
-}
diff --git a/lib/compiler_rt/negdf2.zig b/lib/compiler_rt/negdf2.zig
new file mode 100644
index 0000000000..c730ada7e0
--- /dev/null
+++ b/lib/compiler_rt/negdf2.zig
@@ -0,0 +1,19 @@
+const common = @import("./common.zig");
+
+pub const panic = common.panic;
+
+comptime {
+ if (common.want_aeabi) {
+ @export(__aeabi_dneg, .{ .name = "__aeabi_dneg", .linkage = common.linkage });
+ } else {
+ @export(__negdf2, .{ .name = "__negdf2", .linkage = common.linkage });
+ }
+}
+
+fn __negdf2(a: f64) callconv(.C) f64 {
+ return common.fneg(a);
+}
+
+fn __aeabi_dneg(a: f64) callconv(.AAPCS) f64 {
+ return common.fneg(a);
+}
diff --git a/lib/compiler_rt/negsf2.zig b/lib/compiler_rt/negsf2.zig
new file mode 100644
index 0000000000..4cb32097ba
--- /dev/null
+++ b/lib/compiler_rt/negsf2.zig
@@ -0,0 +1,19 @@
+const common = @import("./common.zig");
+
+pub const panic = common.panic;
+
+comptime {
+ if (common.want_aeabi) {
+ @export(__aeabi_fneg, .{ .name = "__aeabi_fneg", .linkage = common.linkage });
+ } else {
+ @export(__negsf2, .{ .name = "__negsf2", .linkage = common.linkage });
+ }
+}
+
+fn __negsf2(a: f32) callconv(.C) f32 {
+ return common.fneg(a);
+}
+
+fn __aeabi_fneg(a: f32) callconv(.AAPCS) f32 {
+ return common.fneg(a);
+}
diff --git a/lib/compiler_rt/negtf2.zig b/lib/compiler_rt/negtf2.zig
new file mode 100644
index 0000000000..c1c1e97802
--- /dev/null
+++ b/lib/compiler_rt/negtf2.zig
@@ -0,0 +1,11 @@
+const common = @import("./common.zig");
+
+pub const panic = common.panic;
+
+comptime {
+ @export(__negtf2, .{ .name = "__negtf2", .linkage = common.linkage });
+}
+
+fn __negtf2(a: f128) callconv(.C) f128 {
+ return common.fneg(a);
+}
diff --git a/lib/compiler_rt/negxf2.zig b/lib/compiler_rt/negxf2.zig
new file mode 100644
index 0000000000..4e8258453b
--- /dev/null
+++ b/lib/compiler_rt/negxf2.zig
@@ -0,0 +1,11 @@
+const common = @import("./common.zig");
+
+pub const panic = common.panic;
+
+comptime {
+ @export(__negxf2, .{ .name = "__negxf2", .linkage = common.linkage });
+}
+
+fn __negxf2(a: f80) callconv(.C) f80 {
+ return common.fneg(a);
+}
diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig
index b49a954800..fb826f4562 100644
--- a/lib/std/fmt.zig
+++ b/lib/std/fmt.zig
@@ -2225,7 +2225,6 @@ test "float.scientific.precision" {
}
test "float.special" {
- if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
try expectFmt("f64: nan", "f64: {}", .{math.nan_f64});
// negative nan is not defined by IEE 754,
// and ARM thus normalizes it to positive nan
@@ -2237,7 +2236,6 @@ test "float.special" {
}
test "float.hexadecimal.special" {
- if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
try expectFmt("f64: nan", "f64: {x}", .{math.nan_f64});
// negative nan is not defined by IEE 754,
// and ARM thus normalizes it to positive nan
diff --git a/lib/std/math/copysign.zig b/lib/std/math/copysign.zig
index 521724a998..b5fd6d4d9a 100644
--- a/lib/std/math/copysign.zig
+++ b/lib/std/math/copysign.zig
@@ -13,7 +13,6 @@ pub fn copysign(magnitude: anytype, sign: @TypeOf(magnitude)) @TypeOf(magnitude)
}
test "math.copysign" {
- if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
inline for ([_]type{ f16, f32, f64, f80, f128 }) |T| {
try expect(copysign(@as(T, 1.0), @as(T, 1.0)) == 1.0);
try expect(copysign(@as(T, 2.0), @as(T, -2.0)) == -2.0);
diff --git a/lib/std/math/signbit.zig b/lib/std/math/signbit.zig
index cb19212b5b..9aab487d37 100644
--- a/lib/std/math/signbit.zig
+++ b/lib/std/math/signbit.zig
@@ -10,7 +10,6 @@ pub fn signbit(x: anytype) bool {
}
test "math.signbit" {
- if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
inline for ([_]type{ f16, f32, f64, f80, f128 }) |T| {
try expect(!signbit(@as(T, 0.0)));
try expect(!signbit(@as(T, 1.0)));