Use rr::MulAdd() to implement GLSL.std.450's Fma instruction
The 'SPIR-V Extended Instructions for GLSL' include an Fma instruction
which computes `a * b + c` which may be implemented as one operation.
This corresponds to Reactor's MulAdd() intrinsic which uses an FMA
instruction when available.
Bug: b/216472189
Change-Id: I20524282f201344501f6ab121487767391abc907
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/61849
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Pipeline/ShaderCore.cpp b/src/Pipeline/ShaderCore.cpp
index 7b4c77b..81a4251 100644
--- a/src/Pipeline/ShaderCore.cpp
+++ b/src/Pipeline/ShaderCore.cpp
@@ -668,16 +668,6 @@
return NthBit32(bitCount) - sw::SIMD::UInt(1);
}
-// Computes `a * b + c`, which may be fused into one operation to produce a higher-precision result.
-rr::RValue<sw::SIMD::Float> FMA(
- rr::RValue<sw::SIMD::Float> const &a,
- rr::RValue<sw::SIMD::Float> const &b,
- rr::RValue<sw::SIMD::Float> const &c)
-{
- // TODO(b/214591655): Use FMA when available.
- return a * b + c;
-}
-
// Returns the exponent of the floating point number f.
// Assumes IEEE 754
rr::RValue<sw::SIMD::Int> Exponent(rr::RValue<sw::SIMD::Float> f)
diff --git a/src/Pipeline/SpirvShaderGLSLstd450.cpp b/src/Pipeline/SpirvShaderGLSLstd450.cpp
index 9326d5c..7672201 100644
--- a/src/Pipeline/SpirvShaderGLSLstd450.cpp
+++ b/src/Pipeline/SpirvShaderGLSLstd450.cpp
@@ -505,7 +505,7 @@
auto c = Operand(this, state, insn.word(7));
for(auto i = 0u; i < type.componentCount; i++)
{
- dst.move(i, FMA(a.Float(i), b.Float(i), c.Float(i)));
+ dst.move(i, MulAdd(a.Float(i), b.Float(i), c.Float(i)));
}
}
break;