2022-04-26 18:13:55 +01:00
|
|
|
const std = @import("std");
|
2022-06-10 09:25:59 +01:00
|
|
|
const builtin = @import("builtin");
|
|
|
|
const arch = builtin.cpu.arch;
|
2022-06-18 02:10:00 +01:00
|
|
|
const common = @import("common.zig");
|
|
|
|
|
|
|
|
pub const panic = common.panic;
|
2022-06-10 09:25:59 +01:00
|
|
|
|
|
|
|
comptime {
|
2022-06-18 02:10:00 +01:00
|
|
|
@export(__fabsh, .{ .name = "__fabsh", .linkage = common.linkage });
|
|
|
|
@export(fabsf, .{ .name = "fabsf", .linkage = common.linkage });
|
|
|
|
@export(fabs, .{ .name = "fabs", .linkage = common.linkage });
|
|
|
|
@export(__fabsx, .{ .name = "__fabsx", .linkage = common.linkage });
|
2022-10-22 21:31:09 +01:00
|
|
|
if (common.want_ppc_abi) {
|
|
|
|
@export(fabsq, .{ .name = "fabsf128", .linkage = common.linkage });
|
|
|
|
}
|
|
|
|
@export(fabsq, .{ .name = "fabsq", .linkage = common.linkage });
|
2022-06-18 02:10:00 +01:00
|
|
|
@export(fabsl, .{ .name = "fabsl", .linkage = common.linkage });
|
2022-06-10 09:25:59 +01:00
|
|
|
}
|
2022-04-26 18:13:55 +01:00
|
|
|
|
|
|
|
pub fn __fabsh(a: f16) callconv(.C) f16 {
|
|
|
|
return generic_fabs(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn fabsf(a: f32) callconv(.C) f32 {
|
|
|
|
return generic_fabs(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn fabs(a: f64) callconv(.C) f64 {
|
|
|
|
return generic_fabs(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn __fabsx(a: f80) callconv(.C) f80 {
|
|
|
|
return generic_fabs(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn fabsq(a: f128) callconv(.C) f128 {
|
|
|
|
return generic_fabs(a);
|
|
|
|
}
|
|
|
|
|
2022-05-08 21:06:21 +01:00
|
|
|
pub fn fabsl(x: c_longdouble) callconv(.C) c_longdouble {
|
|
|
|
switch (@typeInfo(c_longdouble).Float.bits) {
|
|
|
|
16 => return __fabsh(x),
|
|
|
|
32 => return fabsf(x),
|
|
|
|
64 => return fabs(x),
|
|
|
|
80 => return __fabsx(x),
|
|
|
|
128 => return fabsq(x),
|
|
|
|
else => @compileError("unreachable"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-26 18:13:55 +01:00
|
|
|
inline fn generic_fabs(x: anytype) @TypeOf(x) {
|
|
|
|
const T = @TypeOf(x);
|
|
|
|
const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
|
|
|
|
const float_bits = @bitCast(TBits, x);
|
|
|
|
const remove_sign = ~@as(TBits, 0) >> 1;
|
|
|
|
return @bitCast(T, float_bits & remove_sign);
|
|
|
|
}
|