Commit 3c6a1ae6 by Logan Chien Committed by Chris Forbes

Reactor: Fix Frac generic code generation

This commit fixes `Frac(Float)` and `Frac(Float4)` generic LLVM code generation. See also: https://bugs.chromium.org/p/swiftshader/issues/detail?id=74 Bug: b/115344057 Test: functional.shaders.builtin_functions.precision.fract.highp_vertex Test: functional.shaders.builtin_functions.precision.fract.highp_fragment Change-Id: I027b7ab44ba3060dc100a220ba19e5275f41d4c9 Reviewed-on: https://swiftshader-review.googlesource.com/20933Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com> Tested-by: 's avatarChris Forbes <chrisforbes@google.com>
parent 2faa24a9
...@@ -6288,10 +6288,14 @@ namespace sw ...@@ -6288,10 +6288,14 @@ namespace sw
return x - x86::floorss(x); return x - x86::floorss(x);
} }
else else
#endif
{ {
return Float4(Frac(Float4(x))).x; return Float4(Frac(Float4(x))).x;
} }
#else
// x - floor(x) can be 1.0 for very small negative x.
// Clamp against the value just below 1.0.
return Min(x - Floor(x), As<Float>(Int(0x3F7FFFFF)));
#endif
} }
RValue<Float> Floor(RValue<Float> x) RValue<Float> Floor(RValue<Float> x)
...@@ -6757,12 +6761,14 @@ namespace sw ...@@ -6757,12 +6761,14 @@ namespace sw
frc = x - Floor(x); frc = x - Floor(x);
} }
else else
#endif
{ {
frc = x - Float4(Int4(x)); // Signed fractional part. frc = x - Float4(Int4(x)); // Signed fractional part.
frc += As<Float4>(As<Int4>(CmpNLE(Float4(0.0f), frc)) & As<Int4>(Float4(1.0f))); // Add 1.0 if negative. frc += As<Float4>(As<Int4>(CmpNLE(Float4(0.0f), frc)) & As<Int4>(Float4(1.0f))); // Add 1.0 if negative.
} }
#else
frc = x - Floor(x);
#endif
// x - floor(x) can be 1.0 for very small negative x. // x - floor(x) can be 1.0 for very small negative x.
// Clamp against the value just below 1.0. // Clamp against the value just below 1.0.
......
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