diff options
| author | Zachary Raineri <zach@raineri.software> | 2023-07-24 05:34:16 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-07-24 10:23:51 -0700 |
| commit | d82b35901035a325ca7afd38b28ff2386f90ae84 (patch) | |
| tree | 1a370e979308a3406ea42e55f16299d48ba19700 /lib/compiler_rt/log2.zig | |
| parent | 77b96231a6bc195cc482d05599e8c20ee01645a6 (diff) | |
| download | zig-d82b35901035a325ca7afd38b28ff2386f90ae84.tar.gz zig-d82b35901035a325ca7afd38b28ff2386f90ae84.zip | |
Use builtin inference over @as where possible
Diffstat (limited to 'lib/compiler_rt/log2.zig')
| -rw-r--r-- | lib/compiler_rt/log2.zig | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/lib/compiler_rt/log2.zig b/lib/compiler_rt/log2.zig index f3d80879d0..41027c3df1 100644 --- a/lib/compiler_rt/log2.zig +++ b/lib/compiler_rt/log2.zig @@ -28,7 +28,7 @@ comptime { pub fn __log2h(a: f16) callconv(.C) f16 { // TODO: more efficient implementation - return @as(f16, @floatCast(log2f(a))); + return @floatCast(log2f(a)); } pub fn log2f(x_: f32) callconv(.C) f32 { @@ -40,7 +40,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 { const Lg4: f32 = 0xf89e26.0p-26; var x = x_; - var u = @as(u32, @bitCast(x)); + var u: u32 = @bitCast(x); var ix = u; var k: i32 = 0; @@ -57,7 +57,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 { k -= 25; x *= 0x1.0p25; - ix = @as(u32, @bitCast(x)); + ix = @bitCast(x); } else if (ix >= 0x7F800000) { return x; } else if (ix == 0x3F800000) { @@ -68,7 +68,7 @@ pub fn log2f(x_: f32) callconv(.C) f32 { ix += 0x3F800000 - 0x3F3504F3; k += @as(i32, @intCast(ix >> 23)) - 0x7F; ix = (ix & 0x007FFFFF) + 0x3F3504F3; - x = @as(f32, @bitCast(ix)); + x = @bitCast(ix); const f = x - 1.0; const s = f / (2.0 + f); @@ -80,9 +80,9 @@ pub fn log2f(x_: f32) callconv(.C) f32 { const hfsq = 0.5 * f * f; var hi = f - hfsq; - u = @as(u32, @bitCast(hi)); + u = @bitCast(hi); u &= 0xFFFFF000; - hi = @as(f32, @bitCast(u)); + hi = @bitCast(u); const lo = f - hi - hfsq + s * (hfsq + R); return (lo + hi) * ivln2lo + lo * ivln2hi + hi * ivln2hi + @as(f32, @floatFromInt(k)); } @@ -99,8 +99,8 @@ pub fn log2(x_: f64) callconv(.C) f64 { const Lg7: f64 = 1.479819860511658591e-01; var x = x_; - var ix = @as(u64, @bitCast(x)); - var hx = @as(u32, @intCast(ix >> 32)); + var ix: u64 = @bitCast(x); + var hx: u32 = @intCast(ix >> 32); var k: i32 = 0; if (hx < 0x00100000 or hx >> 31 != 0) { @@ -116,7 +116,7 @@ pub fn log2(x_: f64) callconv(.C) f64 { // subnormal, scale x k -= 54; x *= 0x1.0p54; - hx = @as(u32, @intCast(@as(u64, @bitCast(x)) >> 32)); + hx = @intCast(@as(u64, @bitCast(x)) >> 32); } else if (hx >= 0x7FF00000) { return x; } else if (hx == 0x3FF00000 and ix << 32 == 0) { @@ -128,7 +128,7 @@ pub fn log2(x_: f64) callconv(.C) f64 { k += @as(i32, @intCast(hx >> 20)) - 0x3FF; hx = (hx & 0x000FFFFF) + 0x3FE6A09E; ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF); - x = @as(f64, @bitCast(ix)); + x = @bitCast(ix); const f = x - 1.0; const hfsq = 0.5 * f * f; @@ -143,14 +143,14 @@ pub fn log2(x_: f64) callconv(.C) f64 { var hi = f - hfsq; var hii = @as(u64, @bitCast(hi)); hii &= @as(u64, maxInt(u64)) << 32; - hi = @as(f64, @bitCast(hii)); + hi = @bitCast(hii); const lo = f - hi - hfsq + s * (hfsq + R); var val_hi = hi * ivln2hi; var val_lo = (lo + hi) * ivln2lo + lo * ivln2hi; // spadd(val_hi, val_lo, y) - const y = @as(f64, @floatFromInt(k)); + const y: f64 = @floatFromInt(k); const ww = y + val_hi; val_lo += (y - ww) + val_hi; val_hi = ww; @@ -160,12 +160,12 @@ pub fn log2(x_: f64) callconv(.C) f64 { pub fn __log2x(a: f80) callconv(.C) f80 { // TODO: more efficient implementation - return @as(f80, @floatCast(log2q(a))); + return @floatCast(log2q(a)); } pub fn log2q(a: f128) callconv(.C) f128 { // TODO: more correct implementation - return log2(@as(f64, @floatCast(a))); + return log2(@floatCast(a)); } pub fn log2l(x: c_longdouble) callconv(.C) c_longdouble { |
