From e44a11341d21a14441c5607efa04b9c1be9baf5a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 22 Dec 2017 13:14:07 -0500 Subject: [PATCH] std.math: remove unnecessary inline calls and workaround windows 32 bit test failure See #537 --- std/math/acos.zig | 4 ++-- std/math/acosh.zig | 4 ++-- std/math/asin.zig | 4 ++-- std/math/asinh.zig | 4 ++-- std/math/atan.zig | 22 +++++++++++----------- std/math/atan2.zig | 4 ++-- std/math/atanh.zig | 4 ++-- std/math/cbrt.zig | 4 ++-- std/math/ceil.zig | 4 ++-- std/math/copysign.zig | 4 ++-- std/math/cos.zig | 4 ++-- std/math/cosh.zig | 4 ++-- std/math/exp.zig | 4 ++-- std/math/exp2.zig | 4 ++-- std/math/expm1.zig | 4 ++-- std/math/fabs.zig | 4 ++-- std/math/floor.zig | 4 ++-- std/math/fma.zig | 4 ++-- std/math/frexp.zig | 4 ++-- std/math/hypot.zig | 4 ++-- std/math/ilogb.zig | 4 ++-- std/math/log1p.zig | 4 ++-- std/math/modf.zig | 4 ++-- std/math/round.zig | 4 ++-- std/math/scalbn.zig | 4 ++-- std/math/signbit.zig | 4 ++-- std/math/sin.zig | 4 ++-- std/math/sinh.zig | 4 ++-- std/math/tan.zig | 4 ++-- std/math/tanh.zig | 4 ++-- std/math/trunc.zig | 4 ++-- 31 files changed, 71 insertions(+), 71 deletions(-) diff --git a/std/math/acos.zig b/std/math/acos.zig index ae7afce032..7690497da5 100644 --- a/std/math/acos.zig +++ b/std/math/acos.zig @@ -8,8 +8,8 @@ const assert = @import("../debug.zig").assert; pub fn acos(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(acos32, x), - f64 => @inlineCall(acos64, x), + f32 => acos32(x), + f64 => acos64(x), else => @compileError("acos not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/acosh.zig b/std/math/acosh.zig index 0fdf9e41e0..3b2c2c0f31 100644 --- a/std/math/acosh.zig +++ b/std/math/acosh.zig @@ -10,8 +10,8 @@ const assert = @import("../debug.zig").assert; pub fn acosh(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(acosh32, x), - f64 => @inlineCall(acosh64, x), + f32 => acosh32(x), + f64 => acosh64(x), else => @compileError("acosh not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/asin.zig b/std/math/asin.zig index 11aad04107..c5d24c35e5 100644 --- a/std/math/asin.zig +++ b/std/math/asin.zig @@ -9,8 +9,8 @@ const assert = @import("../debug.zig").assert; pub fn asin(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(asin32, x), - f64 => @inlineCall(asin64, x), + f32 => asin32(x), + f64 => asin64(x), else => @compileError("asin not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/asinh.zig b/std/math/asinh.zig index eda7e15861..f963dae77b 100644 --- a/std/math/asinh.zig +++ b/std/math/asinh.zig @@ -10,8 +10,8 @@ const assert = @import("../debug.zig").assert; pub fn asinh(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(asinh32, x), - f64 => @inlineCall(asinh64, x), + f32 => asinh32(x), + f64 => asinh64(x), else => @compileError("asinh not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/atan.zig b/std/math/atan.zig index 4527f6bf28..cf244eb762 100644 --- a/std/math/atan.zig +++ b/std/math/atan.zig @@ -9,8 +9,8 @@ const assert = @import("../debug.zig").assert; pub fn atan(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(atan32, x), - f64 => @inlineCall(atan64, x), + f32 => atan32(x), + f64 => atan64(x), else => @compileError("atan not implemented for " ++ @typeName(T)), }; } @@ -99,11 +99,11 @@ fn atan32(x_: f32) -> f32 { const s1 = z * (aT[0] + w * (aT[2] + w * aT[4])); const s2 = w * (aT[1] + w * aT[3]); - if (id == null) { - return x - x * (s1 + s2); - } else { - const zz = atanhi[??id] - ((x * (s1 + s2) - atanlo[??id]) - x); + if (id) |id_value| { + const zz = atanhi[id_value] - ((x * (s1 + s2) - atanlo[id_value]) - x); return if (sign != 0) -zz else zz; + } else { + return x - x * (s1 + s2); } } @@ -198,16 +198,16 @@ fn atan64(x_: f64) -> f64 { const s1 = z * (aT[0] + w * (aT[2] + w * (aT[4] + w * (aT[6] + w * (aT[8] + w * aT[10]))))); const s2 = w * (aT[1] + w * (aT[3] + w * (aT[5] + w * (aT[7] + w * aT[9])))); - if (id == null) { - return x - x * (s1 + s2); - } else { - const zz = atanhi[??id] - ((x * (s1 + s2) - atanlo[??id]) - x); + if (id) |id_value| { + const zz = atanhi[id_value] - ((x * (s1 + s2) - atanlo[id_value]) - x); return if (sign != 0) -zz else zz; + } else { + return x - x * (s1 + s2); } } test "math.atan" { - assert(atan(f32(0.2)) == atan32(0.2)); + assert(@bitCast(u32, atan(f32(0.2))) == @bitCast(u32, atan32(0.2))); assert(atan(f64(0.2)) == atan64(0.2)); } diff --git a/std/math/atan2.zig b/std/math/atan2.zig index 9124952b74..b3af18cd9e 100644 --- a/std/math/atan2.zig +++ b/std/math/atan2.zig @@ -23,8 +23,8 @@ const assert = @import("../debug.zig").assert; fn atan2(comptime T: type, x: T, y: T) -> T { return switch (T) { - f32 => @inlineCall(atan2_32, x, y), - f64 => @inlineCall(atan2_64, x, y), + f32 => atan2_32(x, y), + f64 => atan2_64(x, y), else => @compileError("atan2 not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/atanh.zig b/std/math/atanh.zig index 2f87efbbd3..13de90279b 100644 --- a/std/math/atanh.zig +++ b/std/math/atanh.zig @@ -10,8 +10,8 @@ const assert = @import("../debug.zig").assert; pub fn atanh(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(atanh_32, x), - f64 => @inlineCall(atanh_64, x), + f32 => atanh_32(x), + f64 => atanh_64(x), else => @compileError("atanh not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/cbrt.zig b/std/math/cbrt.zig index ff353655b5..a8df75dff2 100644 --- a/std/math/cbrt.zig +++ b/std/math/cbrt.zig @@ -10,8 +10,8 @@ const assert = @import("../debug.zig").assert; pub fn cbrt(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(cbrt32, x), - f64 => @inlineCall(cbrt64, x), + f32 => cbrt32(x), + f64 => cbrt64(x), else => @compileError("cbrt not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/ceil.zig b/std/math/ceil.zig index a8db486f92..8e27132e25 100644 --- a/std/math/ceil.zig +++ b/std/math/ceil.zig @@ -11,8 +11,8 @@ const assert = @import("../debug.zig").assert; pub fn ceil(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(ceil32, x), - f64 => @inlineCall(ceil64, x), + f32 => ceil32(x), + f64 => ceil64(x), else => @compileError("ceil not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/copysign.zig b/std/math/copysign.zig index 12e092c9ab..05205e1a0e 100644 --- a/std/math/copysign.zig +++ b/std/math/copysign.zig @@ -3,8 +3,8 @@ const assert = @import("../debug.zig").assert; pub fn copysign(comptime T: type, x: T, y: T) -> T { return switch (T) { - f32 => @inlineCall(copysign32, x, y), - f64 => @inlineCall(copysign64, x, y), + f32 => copysign32(x, y), + f64 => copysign64(x, y), else => @compileError("copysign not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/cos.zig b/std/math/cos.zig index 285a2e538b..4c3b8e1282 100644 --- a/std/math/cos.zig +++ b/std/math/cos.zig @@ -10,8 +10,8 @@ const assert = @import("../debug.zig").assert; pub fn cos(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(cos32, x), - f64 => @inlineCall(cos64, x), + f32 => cos32(x), + f64 => cos64(x), else => @compileError("cos not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/cosh.zig b/std/math/cosh.zig index f7fea99bcc..6d40d71b8d 100644 --- a/std/math/cosh.zig +++ b/std/math/cosh.zig @@ -12,8 +12,8 @@ const assert = @import("../debug.zig").assert; pub fn cosh(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(cosh32, x), - f64 => @inlineCall(cosh64, x), + f32 => cosh32(x), + f64 => cosh64(x), else => @compileError("cosh not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/exp.zig b/std/math/exp.zig index e51221a74a..6e591daea3 100644 --- a/std/math/exp.zig +++ b/std/math/exp.zig @@ -9,8 +9,8 @@ const assert = @import("../debug.zig").assert; pub fn exp(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(exp32, x), - f64 => @inlineCall(exp64, x), + f32 => exp32(x), + f64 => exp64(x), else => @compileError("exp not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/exp2.zig b/std/math/exp2.zig index e867aabe23..6061f32391 100644 --- a/std/math/exp2.zig +++ b/std/math/exp2.zig @@ -9,8 +9,8 @@ const assert = @import("../debug.zig").assert; pub fn exp2(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(exp2_32, x), - f64 => @inlineCall(exp2_64, x), + f32 => exp2_32(x), + f64 => exp2_64(x), else => @compileError("exp2 not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/expm1.zig b/std/math/expm1.zig index 14a69958e8..fbe1841030 100644 --- a/std/math/expm1.zig +++ b/std/math/expm1.zig @@ -10,8 +10,8 @@ const assert = @import("../debug.zig").assert; pub fn expm1(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(expm1_32, x), - f64 => @inlineCall(expm1_64, x), + f32 => expm1_32(x), + f64 => expm1_64(x), else => @compileError("exp1m not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/fabs.zig b/std/math/fabs.zig index 58244f4f2e..cf1b8f1f14 100644 --- a/std/math/fabs.zig +++ b/std/math/fabs.zig @@ -9,8 +9,8 @@ const assert = @import("../debug.zig").assert; pub fn fabs(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(fabs32, x), - f64 => @inlineCall(fabs64, x), + f32 => fabs32(x), + f64 => fabs64(x), else => @compileError("fabs not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/floor.zig b/std/math/floor.zig index 875070397d..d7de45e9d0 100644 --- a/std/math/floor.zig +++ b/std/math/floor.zig @@ -11,8 +11,8 @@ const math = @import("index.zig"); pub fn floor(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(floor32, x), - f64 => @inlineCall(floor64, x), + f32 => floor32(x), + f64 => floor64(x), else => @compileError("floor not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/fma.zig b/std/math/fma.zig index c870dfd293..8e5adc80b2 100644 --- a/std/math/fma.zig +++ b/std/math/fma.zig @@ -3,8 +3,8 @@ const assert = @import("../debug.zig").assert; pub fn fma(comptime T: type, x: T, y: T, z: T) -> T { return switch (T) { - f32 => @inlineCall(fma32, x, y, z), - f64 => @inlineCall(fma64, x, y ,z), + f32 => fma32(x, y, z), + f64 => fma64(x, y ,z), else => @compileError("fma not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/frexp.zig b/std/math/frexp.zig index e648555e31..1a317a2c80 100644 --- a/std/math/frexp.zig +++ b/std/math/frexp.zig @@ -19,8 +19,8 @@ pub const frexp64_result = frexp_result(f64); pub fn frexp(x: var) -> frexp_result(@typeOf(x)) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(frexp32, x), - f64 => @inlineCall(frexp64, x), + f32 => frexp32(x), + f64 => frexp64(x), else => @compileError("frexp not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/hypot.zig b/std/math/hypot.zig index 68794e24fe..9b09ed53a4 100644 --- a/std/math/hypot.zig +++ b/std/math/hypot.zig @@ -10,8 +10,8 @@ const assert = @import("../debug.zig").assert; pub fn hypot(comptime T: type, x: T, y: T) -> T { return switch (T) { - f32 => @inlineCall(hypot32, x, y), - f64 => @inlineCall(hypot64, x, y), + f32 => hypot32(x, y), + f64 => hypot64(x, y), else => @compileError("hypot not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/ilogb.zig b/std/math/ilogb.zig index e056ceb097..41a1e2d83f 100644 --- a/std/math/ilogb.zig +++ b/std/math/ilogb.zig @@ -10,8 +10,8 @@ const assert = @import("../debug.zig").assert; pub fn ilogb(x: var) -> i32 { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(ilogb32, x), - f64 => @inlineCall(ilogb64, x), + f32 => ilogb32(x), + f64 => ilogb64(x), else => @compileError("ilogb not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/log1p.zig b/std/math/log1p.zig index 433a7c6192..b369385038 100644 --- a/std/math/log1p.zig +++ b/std/math/log1p.zig @@ -12,8 +12,8 @@ const assert = @import("../debug.zig").assert; pub fn log1p(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(log1p_32, x), - f64 => @inlineCall(log1p_64, x), + f32 => log1p_32(x), + f64 => log1p_64(x), else => @compileError("log1p not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/modf.zig b/std/math/modf.zig index 5b78680c51..72730b67d7 100644 --- a/std/math/modf.zig +++ b/std/math/modf.zig @@ -18,8 +18,8 @@ pub const modf64_result = modf_result(f64); pub fn modf(x: var) -> modf_result(@typeOf(x)) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(modf32, x), - f64 => @inlineCall(modf64, x), + f32 => modf32(x), + f64 => modf64(x), else => @compileError("modf not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/round.zig b/std/math/round.zig index 8e604d1b68..1e193fb1d7 100644 --- a/std/math/round.zig +++ b/std/math/round.zig @@ -11,8 +11,8 @@ const math = @import("index.zig"); pub fn round(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(round32, x), - f64 => @inlineCall(round64, x), + f32 => round32(x), + f64 => round64(x), else => @compileError("round not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/scalbn.zig b/std/math/scalbn.zig index 0c898a783c..0be6a3d47e 100644 --- a/std/math/scalbn.zig +++ b/std/math/scalbn.zig @@ -4,8 +4,8 @@ const assert = @import("../debug.zig").assert; pub fn scalbn(x: var, n: i32) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(scalbn32, x, n), - f64 => @inlineCall(scalbn64, x, n), + f32 => scalbn32(x, n), + f64 => scalbn64(x, n), else => @compileError("scalbn not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/signbit.zig b/std/math/signbit.zig index 6efbc4db54..b8ccecfa1b 100644 --- a/std/math/signbit.zig +++ b/std/math/signbit.zig @@ -4,8 +4,8 @@ const assert = @import("../debug.zig").assert; pub fn signbit(x: var) -> bool { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(signbit32, x), - f64 => @inlineCall(signbit64, x), + f32 => signbit32(x), + f64 => signbit64(x), else => @compileError("signbit not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/sin.zig b/std/math/sin.zig index 6fbbaff291..392bef1bc0 100644 --- a/std/math/sin.zig +++ b/std/math/sin.zig @@ -11,8 +11,8 @@ const assert = @import("../debug.zig").assert; pub fn sin(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(sin32, x), - f64 => @inlineCall(sin64, x), + f32 => sin32(x), + f64 => sin64(x), else => @compileError("sin not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/sinh.zig b/std/math/sinh.zig index 095dd7ea06..4c575f10ec 100644 --- a/std/math/sinh.zig +++ b/std/math/sinh.zig @@ -12,8 +12,8 @@ const expo2 = @import("expo2.zig").expo2; pub fn sinh(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(sinh32, x), - f64 => @inlineCall(sinh64, x), + f32 => sinh32(x), + f64 => sinh64(x), else => @compileError("sinh not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/tan.zig b/std/math/tan.zig index 2a3c46eb6f..ff53a758b4 100644 --- a/std/math/tan.zig +++ b/std/math/tan.zig @@ -11,8 +11,8 @@ const assert = @import("../debug.zig").assert; pub fn tan(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(tan32, x), - f64 => @inlineCall(tan64, x), + f32 => tan32(x), + f64 => tan64(x), else => @compileError("tan not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/tanh.zig b/std/math/tanh.zig index c4fe8f2031..7715029361 100644 --- a/std/math/tanh.zig +++ b/std/math/tanh.zig @@ -12,8 +12,8 @@ const expo2 = @import("expo2.zig").expo2; pub fn tanh(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(tanh32, x), - f64 => @inlineCall(tanh64, x), + f32 => tanh32(x), + f64 => tanh64(x), else => @compileError("tanh not implemented for " ++ @typeName(T)), }; } diff --git a/std/math/trunc.zig b/std/math/trunc.zig index 01cb1bb84a..81eacb30ba 100644 --- a/std/math/trunc.zig +++ b/std/math/trunc.zig @@ -10,8 +10,8 @@ const assert = @import("../debug.zig").assert; pub fn trunc(x: var) -> @typeOf(x) { const T = @typeOf(x); return switch (T) { - f32 => @inlineCall(trunc32, x), - f64 => @inlineCall(trunc64, x), + f32 => trunc32(x), + f64 => trunc64(x), else => @compileError("trunc not implemented for " ++ @typeName(T)), }; }