zig/lib/compiler_rt/negXf2.zig
Andrew Kelley 0556a2ba53 compiler-rt: finish cleanups
Finishes cleanups that I started in other commits in this branch.

 * Use common.linkage for all exports instead of redoing the logic in
   each file.
 * Remove pointless `@setRuntimeSafety` calls.
 * Avoid redundantly exporting multiple versions of functions. For
   example, if PPC wants `ceilf128` then don't also export `ceilq`;
   similarly if ARM wants `__aeabi_ddiv` then don't also export
   `__divdf3`.
 * Use `inline` for helper functions instead of making inline calls at
   callsites.
2022-06-17 18:10:00 -07:00

43 lines
1.2 KiB
Zig

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);
}