Add support for OpDot
Bug: b/126873455
Change-Id: Ibe76dc02ab22903f1ad2d00685cd1855aaeb3338
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/25968
Tested-by: Chris Forbes <chrisforbes@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index b828f31..3c9afb4 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -235,6 +235,7 @@
case spv::OpLogicalAnd:
case spv::OpUMulExtended:
case spv::OpSMulExtended:
+ case spv::OpDot:
// Instructions that yield an intermediate value
{
TypeID typeId = insn.word(1);
@@ -914,6 +915,10 @@
EmitBinaryOp(insn, routine);
break;
+ case spv::OpDot:
+ EmitDot(insn, routine);
+ break;
+
default:
printf("emit: ignoring opcode %s\n", OpcodeName(insn.opcode()).c_str());
break;
@@ -1279,6 +1284,25 @@
}
}
+ void SpirvShader::EmitDot(InsnIterator insn, SpirvRoutine *routine) const
+ {
+ auto &type = getType(insn.word(1));
+ assert(type.sizeInComponents == 1);
+ auto &dst = routine->createIntermediate(insn.word(2), type.sizeInComponents);
+ auto &lhsType = getType(getObject(insn.word(3)).type);
+ auto srcLHS = GenericValue(this, routine, insn.word(3));
+ auto srcRHS = GenericValue(this, routine, insn.word(4));
+
+ SIMD::Float result = srcLHS[0] * srcRHS[0];
+
+ for (auto i = 1u; i < lhsType.sizeInComponents; i++)
+ {
+ result += srcLHS[i] * srcRHS[i];
+ }
+
+ dst.emplace(0, result);
+ }
+
void SpirvShader::emitEpilog(SpirvRoutine *routine) const
{
for (auto insn : *this)