Commit 41bcdc78 by Nicolas Capens Committed by Nicolas Capens

Refactor exp2().

Change-Id: I491411ba77addcb514944717b19918e4d1b98898 Reviewed-on: https://swiftshader-review.googlesource.com/16228Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 749ac9c8
...@@ -114,35 +114,30 @@ namespace sw ...@@ -114,35 +114,30 @@ namespace sw
Float4 exponential2(RValue<Float4> x, bool pp) Float4 exponential2(RValue<Float4> x, bool pp)
{ {
Float4 x0; // This implementation is based on 2^(i + f) = 2^i * 2^f,
Float4 x1; // where i is the integer part of x and f is the fraction.
Int4 x2;
x0 = x;
// For 2^i we can put the integer part directly in the exponent of
// the IEEE-754 floating-point number. Clamp to prevent overflow
// past the representation of infinity.
Float4 x0 = x;
x0 = Min(x0, As<Float4>(Int4(0x43010000))); // 129.00000e+0f x0 = Min(x0, As<Float4>(Int4(0x43010000))); // 129.00000e+0f
x0 = Max(x0, As<Float4>(Int4(0xC2FDFFFF))); // -126.99999e+0f x0 = Max(x0, As<Float4>(Int4(0xC2FDFFFF))); // -126.99999e+0f
x1 = x0;
x1 -= Float4(0.5f); Int4 i = RoundInt(x0 - Float4(0.5f));
x2 = RoundInt(x1); Float4 ii = As<Float4>((i + Int4(127)) << 23); // Add single-precision bias, and shift into exponent.
x1 = Float4(x2);
x2 += Int4(0x0000007F); // 127 // For the fractional part use a polynomial
x2 = x2 << 23; // which approximates 2^f in the 0 to 1 range.
x0 -= x1; Float4 f = x0 - Float4(i);
x1 = As<Float4>(Int4(0x3AF61905)); // 1.8775767e-3f Float4 ff = As<Float4>(Int4(0x3AF61905)); // 1.8775767e-3f
x1 *= x0; ff = ff * f + As<Float4>(Int4(0x3C134806)); // 8.9893397e-3f
x1 += As<Float4>(Int4(0x3C134806)); // 8.9893397e-3f ff = ff * f + As<Float4>(Int4(0x3D64AA23)); // 5.5826318e-2f
x1 *= x0; ff = ff * f + As<Float4>(Int4(0x3E75EAD4)); // 2.4015361e-1f
x1 += As<Float4>(Int4(0x3D64AA23)); // 5.5826318e-2f ff = ff * f + As<Float4>(Int4(0x3F31727B)); // 6.9315308e-1f
x1 *= x0; ff = ff * f + Float4(1.0f);
x1 += As<Float4>(Int4(0x3E75EAD4)); // 2.4015361e-1f
x1 *= x0; return ii * ff;
x1 += As<Float4>(Int4(0x3F31727B)); // 6.9315308e-1f
x1 *= x0;
x1 += Float4(1.0f);
x1 *= As<Float4>(x2);
return x1;
} }
Float4 logarithm2(RValue<Float4> x, bool absolute, bool pp) Float4 logarithm2(RValue<Float4> x, bool absolute, bool pp)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment