Remove the 'finite' parameter from reciprocal()
This is an unused relic which was used to prevent returning infinity
for the reciprocal of 0. While the implementation of sine does set the
parameter to true, the denominator is a value of '1 + e' where 'e' is
a very small error value: https://arxiv.org/pdf/cs/0406049.pdf
Bug: b/169754022
Change-Id: Ib335a9072366ef996d706adafdffca9eb440b2c4
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/61128
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Sean Risser <srisser@google.com>
diff --git a/src/Pipeline/PixelRoutine.cpp b/src/Pipeline/PixelRoutine.cpp
index 2dc906d..e1edd21 100644
--- a/src/Pipeline/PixelRoutine.cpp
+++ b/src/Pipeline/PixelRoutine.cpp
@@ -174,7 +174,7 @@
if(interpolateW())
{
w = interpolate(xxxx, Dw, rhw, primitive + OFFSET(Primitive, w), false, false);
- rhw = reciprocal(w, false, false, true);
+ rhw = reciprocal(w, false, true);
if(state.centroid || shaderContainsInterpolation) // TODO(b/194714095)
{
diff --git a/src/Pipeline/ShaderCore.cpp b/src/Pipeline/ShaderCore.cpp
index 8426523..55cb390 100644
--- a/src/Pipeline/ShaderCore.cpp
+++ b/src/Pipeline/ShaderCore.cpp
@@ -222,9 +222,9 @@
return exponential2(log, pp);
}
-Float4 reciprocal(RValue<Float4> x, bool pp, bool finite, bool exactAtPow2)
+Float4 reciprocal(RValue<Float4> x, bool pp, bool exactAtPow2)
{
- return Rcp(x, pp ? Precision::Relaxed : Precision::Full, finite, exactAtPow2);
+ return Rcp(x, pp ? Precision::Relaxed : Precision::Full, exactAtPow2);
}
Float4 reciprocalSquareRoot(RValue<Float4> x, bool absolute, bool pp)
@@ -292,7 +292,7 @@
Float4 s1 = y * (y2 * (y2 * (y2 * Float4(-0.0046075748f) + Float4(0.0796819754f)) + Float4(-0.645963615f)) + Float4(1.5707963235f));
Float4 c2 = (c1 * c1) - (s1 * s1);
Float4 s2 = Float4(2.0f) * s1 * c1;
- return Float4(2.0f) * s2 * c2 * reciprocal(s2 * s2 + c2 * c2, pp, true);
+ return Float4(2.0f) * s2 * c2 * reciprocal(s2 * s2 + c2 * c2);
}
const Float4 A = Float4(-16.0f);
diff --git a/src/Pipeline/ShaderCore.hpp b/src/Pipeline/ShaderCore.hpp
index 93b3f01..e90c4a1 100644
--- a/src/Pipeline/ShaderCore.hpp
+++ b/src/Pipeline/ShaderCore.hpp
@@ -188,7 +188,7 @@
Float4 exponential(RValue<Float4> x, bool pp = false);
Float4 logarithm(RValue<Float4> x, bool pp = false);
Float4 power(RValue<Float4> x, RValue<Float4> y, bool pp = false);
-Float4 reciprocal(RValue<Float4> x, bool pp = false, bool finite = false, bool exactAtPow2 = false);
+Float4 reciprocal(RValue<Float4> x, bool pp = false, bool exactAtPow2 = false);
Float4 reciprocalSquareRoot(RValue<Float4> x, bool abs, bool pp = false);
Float4 modulo(RValue<Float4> x, RValue<Float4> y);
Float4 sine_pi(RValue<Float4> x, bool pp = false); // limited to [-pi, pi] range
diff --git a/src/Reactor/OptimalIntrinsics.cpp b/src/Reactor/OptimalIntrinsics.cpp
index d27e192..eea6489 100644
--- a/src/Reactor/OptimalIntrinsics.cpp
+++ b/src/Reactor/OptimalIntrinsics.cpp
@@ -25,12 +25,6 @@
rcp = (rcp + rcp) - (x * rcp * rcp);
}
- if(finite)
- {
- int big = 0x7F7FFFFF;
- rcp = Min(rcp, Float4((float &)big));
- }
-
return rcp;
}
@@ -50,7 +44,7 @@
Float4 s1 = y * (y2 * (y2 * (y2 * Float4(-0.0046075748f) + Float4(0.0796819754f)) + Float4(-0.645963615f)) + Float4(1.5707963235f));
Float4 c2 = (c1 * c1) - (s1 * s1);
Float4 s2 = Float4(2.0f) * s1 * c1;
- Float4 r = Reciprocal(s2 * s2 + c2 * c2, false, true, false);
+ Float4 r = Reciprocal(s2 * s2 + c2 * c2);
if(sin)
{
diff --git a/src/Reactor/Reactor.cpp b/src/Reactor/Reactor.cpp
index f3363b2..f86a5ba 100644
--- a/src/Reactor/Reactor.cpp
+++ b/src/Reactor/Reactor.cpp
@@ -4668,7 +4668,7 @@
RValue<Float> RcpApprox(RValue<Float> x, bool exactAtPow2 = false);
template<typename T>
-static RValue<T> DoRcp(RValue<T> x, Precision p, bool finite, bool exactAtPow2)
+static RValue<T> DoRcp(RValue<T> x, Precision p, bool exactAtPow2)
{
#if defined(__i386__) || defined(__x86_64__) // On x86, 1/x is fast enough, except for lower precision
bool approx = HasRcpApprox() && (p != Precision::Full);
@@ -4693,25 +4693,19 @@
rcp = T(1.0f) / x;
}
- if(finite)
- {
- constexpr int big = 0x7F7FFFFF;
- rcp = Min(rcp, T((float &)big));
- }
-
return rcp;
}
-RValue<Float4> Rcp(RValue<Float4> x, Precision p, bool finite, bool exactAtPow2)
+RValue<Float4> Rcp(RValue<Float4> x, Precision p, bool exactAtPow2)
{
RR_DEBUG_INFO_UPDATE_LOC();
- return DoRcp(x, p, finite, exactAtPow2);
+ return DoRcp(x, p, exactAtPow2);
}
-RValue<Float> Rcp(RValue<Float> x, Precision p, bool finite, bool exactAtPow2)
+RValue<Float> Rcp(RValue<Float> x, Precision p, bool exactAtPow2)
{
RR_DEBUG_INFO_UPDATE_LOC();
- return DoRcp(x, p, finite, exactAtPow2);
+ return DoRcp(x, p, exactAtPow2);
}
// Functions implemented by backends
diff --git a/src/Reactor/Reactor.hpp b/src/Reactor/Reactor.hpp
index 75980af..55ca984 100644
--- a/src/Reactor/Reactor.hpp
+++ b/src/Reactor/Reactor.hpp
@@ -2180,7 +2180,7 @@
// Deprecated: use RcpSqrt
// TODO(b/147516027): Remove when GLES frontend is removed
RValue<Float> RcpSqrt_pp(RValue<Float> val);
-RValue<Float> Rcp(RValue<Float> x, Precision p = Precision::Full, bool finite = false, bool exactAtPow2 = false);
+RValue<Float> Rcp(RValue<Float> x, Precision p = Precision::Full, bool exactAtPow2 = false);
RValue<Float> RcpSqrt(RValue<Float> x, Precision p = Precision::Full);
RValue<Float> Sqrt(RValue<Float> x);
@@ -2351,7 +2351,7 @@
// Deprecated: use RcpSqrt
// TODO(b/147516027): Remove when GLES frontend is removed
RValue<Float4> RcpSqrt_pp(RValue<Float4> val);
-RValue<Float4> Rcp(RValue<Float4> x, Precision p = Precision::Full, bool finite = false, bool exactAtPow2 = false);
+RValue<Float4> Rcp(RValue<Float4> x, Precision p = Precision::Full, bool exactAtPow2 = false);
RValue<Float4> RcpSqrt(RValue<Float4> x, Precision p = Precision::Full);
RValue<Float4> Sqrt(RValue<Float4> x);
RValue<Float4> Insert(RValue<Float4> val, RValue<Float> element, int i);