commit 779137be4111ba60c888ed86f33654e538a7a0ca (tree)
parent 38c2093500dcb7dac7cce6bbe08abe92767f24ba
Author: vegecode <justin.b.alexander1@gmail.com>
Date: Fri, 22 Mar 2019 22:51:25 -0500
Add __aeabi_{f,d}neg and __neg{s,d,X}f2 to compiler-rt
Diffstat:
3 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -664,6 +664,7 @@ set(ZIG_STD_FILES
"special/compiler_rt/muloti4.zig"
"special/compiler_rt/mulXf3.zig"
"special/compiler_rt/multi3.zig"
+ "special/compiler_rt/negXf2.zig"
"special/compiler_rt/popcountdi2.zig"
"special/compiler_rt/truncXfYf2.zig"
"special/compiler_rt/udivmod.zig"
diff --git a/std/special/compiler_rt.zig b/std/special/compiler_rt.zig
@@ -82,6 +82,9 @@ comptime {
@export("__umoddi3", __umoddi3, linkage);
@export("__udivmodsi4", __udivmodsi4, linkage);
+ @export("__negsf2", @import("compiler_rt/negXf2.zig").__negsf2, linkage);
+ @export("__negdf2", @import("compiler_rt/negXf2.zig").__negdf2, linkage);
+
if (is_arm_arch and !is_arm_64) {
@export("__aeabi_uldivmod", __aeabi_uldivmod, linkage);
@export("__aeabi_uidivmod", __aeabi_uidivmod, linkage);
@@ -107,6 +110,9 @@ comptime {
@export("__aeabi_memcmp4", __aeabi_memcmp, linkage);
@export("__aeabi_memcmp8", __aeabi_memcmp, linkage);
+ @export("__aeabi_fneg", @import("compiler_rt/negXf2.zig").__negsf2, linkage);
+ @export("__aeabi_dneg", @import("compiler_rt/negXf2.zig").__negdf2, linkage);
+
@export("__aeabi_fadd", @import("compiler_rt/addXf3.zig").__addsf3, linkage);
@export("__aeabi_dadd", @import("compiler_rt/addXf3.zig").__adddf3, linkage);
@export("__aeabi_fsub", @import("compiler_rt/addXf3.zig").__subsf3, linkage);
diff --git a/std/special/compiler_rt/negXf2.zig b/std/special/compiler_rt/negXf2.zig
@@ -0,0 +1,21 @@
+const std = @import("std");
+
+pub extern fn __negsf2(a: f32) f32 {
+ return negXf2(f32, a);
+}
+
+pub extern fn __negdf2(a: f64) f64 {
+ return negXf2(f64, a);
+}
+
+fn negXf2(comptime T: type, a: T) T {
+ const Z = @IntType(false, T.bit_count);
+
+ const typeWidth = T.bit_count;
+ const significandBits = std.math.floatMantissaBits(T);
+ const exponentBits = std.math.floatExponentBits(T);
+
+ const signBit = (Z(1) << (significandBits + exponentBits));
+
+ return @bitCast(T, @bitCast(Z, a) ^ signBit);
+}