SpirvShader: Implement GLSLstd450Acos
Bug: b/126873455
Tests: dEQP-VK.glsl.builtin.precision.acos.*
Change-Id: I7f65b398b6dc9ba5daf2df0a98c41b50b9775cd2
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28672
Tested-by: Ben Clayton <bclayton@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Reactor/LLVMReactor.cpp b/src/Reactor/LLVMReactor.cpp
index c97e9d3..d3fd354 100644
--- a/src/Reactor/LLVMReactor.cpp
+++ b/src/Reactor/LLVMReactor.cpp
@@ -557,6 +557,7 @@
func_.emplace("sinf", reinterpret_cast<void*>(sinf));
func_.emplace("cosf", reinterpret_cast<void*>(cosf));
func_.emplace("asinf", reinterpret_cast<void*>(asinf));
+ func_.emplace("acosf", reinterpret_cast<void*>(acosf));
#ifdef __APPLE__
// LLVM uses this function on macOS for tan.
@@ -3090,10 +3091,10 @@
return Sin(v) / Cos(v);
}
- RValue<Float4> Asin(RValue<Float4> v)
+ static RValue<Float4> TransformFloat4PerElement(RValue<Float4> v, const char* name)
{
auto funcTy = ::llvm::FunctionType::get(T(Float::getType()), {T(Float::getType())}, false);
- auto func = ::module->getOrInsertFunction("asinf", funcTy);
+ auto func = ::module->getOrInsertFunction(name, funcTy);
llvm::Value *out = ::llvm::UndefValue::get(T(Float4::getType()));
for (uint64_t i = 0; i < 4; i++)
{
@@ -3103,6 +3104,16 @@
return RValue<Float4>(V(out));
}
+ RValue<Float4> Asin(RValue<Float4> v)
+ {
+ return TransformFloat4PerElement(v, "asinf");
+ }
+
+ RValue<Float4> Acos(RValue<Float4> v)
+ {
+ return TransformFloat4PerElement(v, "acosf");
+ }
+
Type *Float4::getType()
{
return T(llvm::VectorType::get(T(Float::getType()), 4));