Reactor: Fix RoundInt generic code generation
This commit fixes `RoundInt(Float)` and `RoundInt(Float4)` generic LLVM
code generation.
Bug: b/115344057
Test: functional.shaders.builtin_functions.precision.sinh.highp_vertex
Test: functional.shaders.builtin_functions.precision.sinh.highp_fragment
Test: functional.shaders.builtin_functions.precision.cosh.highp_vertex
Test: functional.shaders.builtin_functions.precision.cosh.highp_fragment
Change-Id: I35de5cf6bec6607725523a10ebf098333957f39a
Reviewed-on: https://swiftshader-review.googlesource.com/20931
Tested-by: Chris Forbes <chrisforbes@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Chris Forbes <chrisforbes@google.com>
diff --git a/src/Reactor/LLVMReactor.cpp b/src/Reactor/LLVMReactor.cpp
index 7d75fe9..cfecb4f 100644
--- a/src/Reactor/LLVMReactor.cpp
+++ b/src/Reactor/LLVMReactor.cpp
@@ -190,6 +190,11 @@
return ::builder->CreateCall(nearbyint, ARGS(x));
}
+ llvm::Value *lowerRoundInt(llvm::Value *x, llvm::Type *ty)
+ {
+ return ::builder->CreateFPToSI(lowerRound(x), ty);
+ }
+
llvm::Value *lowerFloor(llvm::Value *x)
{
llvm::Function *floor = llvm::Intrinsic::getDeclaration(
@@ -4438,7 +4443,7 @@
#if defined(__i386__) || defined(__x86_64__)
return x86::cvtss2si(cast);
#else
- return IfThenElse(cast > 0.0f, Int(cast + 0.5f), Int(cast - 0.5f));
+ return RValue<Int>(V(lowerRoundInt(V(cast.value), T(Int::getType()))));
#endif
}
@@ -5685,7 +5690,7 @@
#if defined(__i386__) || defined(__x86_64__)
return x86::cvtps2dq(cast);
#else
- return As<Int4>(V(::builder->CreateFPToSI(V(cast.value), T(Int4::getType()))));
+ return As<Int4>(V(lowerRoundInt(V(cast.value), T(Int4::getType()))));
#endif
}