SpirvShader: Implement GLSLstd450Tan
Bug: b/126873455
Tests: dEQP-VK.glsl.builtin.precision.tan.*
Change-Id: I229b46b285075bd25272145a562135df08438160
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28670
Presubmit-Ready: Ben Clayton <bclayton@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chris Forbes <chrisforbes@google.com>
Tested-by: Chris Forbes <chrisforbes@google.com>
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index ad3d08f..14677f5 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -3302,6 +3302,15 @@
}
break;
}
+ case GLSLstd450Tan:
+ {
+ auto radians = GenericValue(this, routine, insn.word(5));
+ for (auto i = 0u; i < type.sizeInComponents; i++)
+ {
+ dst.move(i, Tan(radians.Float(i)));
+ }
+ break;
+ }
default:
UNIMPLEMENTED("Unhandled ExtInst %d", extInstIndex);
}
diff --git a/src/Reactor/LLVMReactor.cpp b/src/Reactor/LLVMReactor.cpp
index 578dfa1..f7ad721 100644
--- a/src/Reactor/LLVMReactor.cpp
+++ b/src/Reactor/LLVMReactor.cpp
@@ -556,6 +556,13 @@
func_.emplace("fmodf", reinterpret_cast<void*>(fmodf));
func_.emplace("sinf", reinterpret_cast<void*>(sinf));
func_.emplace("cosf", reinterpret_cast<void*>(cosf));
+
+#ifdef __APPLE__
+ // LLVM uses this function on macOS for tan.
+ func_.emplace("sincosf_stret", reinterpret_cast<void*>(__sincosf_stret));
+#elif defined(__linux__)
+ func_.emplace("sincosf", reinterpret_cast<void*>(sincosf));
+#endif // __APPLE__
}
void *findSymbol(const std::string &name) const
@@ -3077,6 +3084,11 @@
return RValue<Float4>(V(::builder->CreateCall(func, V(v.value))));
}
+ RValue<Float4> Tan(RValue<Float4> v)
+ {
+ return Sin(v) / Cos(v);
+ }
+
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 2419dbe..ab3989e 100644
--- a/src/Reactor/Reactor.hpp
+++ b/src/Reactor/Reactor.hpp
@@ -2210,6 +2210,7 @@
// TODO: Currentlhy unimplemented for Subzero.
RValue<Float4> Sin(RValue<Float4> x);
RValue<Float4> Cos(RValue<Float4> x);
+ RValue<Float4> Tan(RValue<Float4> x);
template<class T>
class Pointer : public LValue<Pointer<T>>