Commit 8c5ca8d1 by Logan Chien Committed by Chris Forbes

Reactor: Fix Trunc generic code generation

This commit fixes `Trunc(Float)` and `Trunc(Float4)` generic LLVM code generation. If `Trunc(x)` is implemented with `Float(Int(x))`, it will result in quality warning in dEQP. Bug: b/115344057 Test: dEQP-GLES3.functional.shaders.builtin_functions.precision.trunc Test: dEQP-GLES3.functional.shaders.builtin_functions.precision.modf Change-Id: I62d2dd1907e345fb00307b6c0d4d74613237f94b Reviewed-on: https://swiftshader-review.googlesource.com/21029Tested-by: 's avatarChris Forbes <chrisforbes@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com>
parent 3c6a1ae6
...@@ -202,6 +202,13 @@ namespace ...@@ -202,6 +202,13 @@ namespace
return ::builder->CreateCall(floor, ARGS(x)); return ::builder->CreateCall(floor, ARGS(x));
} }
llvm::Value *lowerTrunc(llvm::Value *x)
{
llvm::Function *trunc = llvm::Intrinsic::getDeclaration(
::module, llvm::Intrinsic::trunc, {x->getType()});
return ::builder->CreateCall(trunc, ARGS(x));
}
// Packed add/sub saturatation // Packed add/sub saturatation
llvm::Value *lowerPSAT(llvm::Value *x, llvm::Value *y, bool isAdd, bool isSigned) llvm::Value *lowerPSAT(llvm::Value *x, llvm::Value *y, bool isAdd, bool isSigned)
{ {
...@@ -535,6 +542,7 @@ namespace sw ...@@ -535,6 +542,7 @@ namespace sw
{ {
func_.emplace("floorf", reinterpret_cast<void*>(floorf)); func_.emplace("floorf", reinterpret_cast<void*>(floorf));
func_.emplace("nearbyintf", reinterpret_cast<void*>(nearbyintf)); func_.emplace("nearbyintf", reinterpret_cast<void*>(nearbyintf));
func_.emplace("truncf", reinterpret_cast<void*>(truncf));
} }
void *findSymbol(const std::string &name) const void *findSymbol(const std::string &name) const
...@@ -6274,10 +6282,12 @@ namespace sw ...@@ -6274,10 +6282,12 @@ namespace sw
return x86::roundss(x, 3); return x86::roundss(x, 3);
} }
else else
#endif
{ {
return Float(Int(x)); // Rounded toward zero return Float(Int(x)); // Rounded toward zero
} }
#else
return RValue<Float>(V(lowerTrunc(V(x.value))));
#endif
} }
RValue<Float> Frac(RValue<Float> x) RValue<Float> Frac(RValue<Float> x)
...@@ -6745,10 +6755,12 @@ namespace sw ...@@ -6745,10 +6755,12 @@ namespace sw
return x86::roundps(x, 3); return x86::roundps(x, 3);
} }
else else
#endif
{ {
return Float4(Int4(x)); return Float4(Int4(x));
} }
#else
return RValue<Float4>(V(lowerTrunc(V(x.value))));
#endif
} }
RValue<Float4> Frac(RValue<Float4> x) RValue<Float4> Frac(RValue<Float4> x)
......
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