zig/lib/compiler_rt/negXf2.zig
Andrew Kelley ec95e00e28 flatten lib/std/special and improve "pkg inside another" logic
stage2: change logic for detecting whether the main package is inside
the std package. Previously it relied on realpath() which is not portable.
This uses resolve() which is how imports already work.

 * stage2: fix cleanup bug when creating Module
 * flatten lib/std/special/* to lib/*
   - this was motivated by making main_pkg_is_inside_std false for
     compiler_rt & friends.
 * rename "mini libc" to "universal libc"
2022-05-06 22:41:00 -07:00

31 lines
826 B
Zig

const std = @import("std");
pub fn __negsf2(a: f32) callconv(.C) f32 {
return negXf2(f32, a);
}
pub fn __negdf2(a: f64) callconv(.C) f64 {
return negXf2(f64, a);
}
pub fn __aeabi_fneg(arg: f32) callconv(.AAPCS) f32 {
@setRuntimeSafety(false);
return @call(.{ .modifier = .always_inline }, __negsf2, .{arg});
}
pub fn __aeabi_dneg(arg: f64) callconv(.AAPCS) f64 {
@setRuntimeSafety(false);
return @call(.{ .modifier = .always_inline }, __negdf2, .{arg});
}
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);
}