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/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index daea265..ab12f60 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -3320,6 +3320,15 @@
 			}
 			break;
 		}
+		case GLSLstd450Acos:
+		{
+			auto val = GenericValue(this, routine, insn.word(5));
+			for (auto i = 0u; i < type.sizeInComponents; i++)
+			{
+				dst.move(i, Acos(val.Float(i)));
+			}
+			break;
+		}
 		default:
 			UNIMPLEMENTED("Unhandled ExtInst %d", extInstIndex);
 		}
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));
diff --git a/src/Reactor/Reactor.hpp b/src/Reactor/Reactor.hpp
index 6e25a16..96c87e0 100644
--- a/src/Reactor/Reactor.hpp
+++ b/src/Reactor/Reactor.hpp
@@ -2212,6 +2212,7 @@
 	RValue<Float4> Cos(RValue<Float4> x);
 	RValue<Float4> Tan(RValue<Float4> x);
 	RValue<Float4> Asin(RValue<Float4> x);
+	RValue<Float4> Acos(RValue<Float4> x);
 
 	template<class T>
 	class Pointer : public LValue<Pointer<T>>