diff --git a/CMakeLists.txt b/CMakeLists.txt index d8a5882d71..65bc905981 100644 --- 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 index 303b0ee6bb..d1bcf6de01 100644 --- 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 new file mode 100644 index 0000000000..b71a503c1d --- /dev/null +++ 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); +}