Commit 6095826b by Ben Clayton

SpirvShader: Implement GLSLstd450Find[U,S]Msb

Bug: b/126873455 Tests: dEQP-VK.glsl.builtin.function.integer.findMSB.* Change-Id: I6337998f725334c31d8adeae05fc441bb3895908 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28788Tested-by: 's avatarBen Clayton <bclayton@google.com> Presubmit-Ready: Ben Clayton <bclayton@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 1fb633c3
......@@ -3610,12 +3610,21 @@ namespace sw
}
case GLSLstd450FindSMsb:
{
UNIMPLEMENTED("GLSLstd450FindSMsb");
auto val = GenericValue(this, routine, insn.word(5));
for (auto i = 0u; i < type.sizeInComponents; i++)
{
auto v = val.UInt(i) ^ As<SIMD::UInt>(CmpLT(val.Int(i), SIMD::Int(0)));
dst.move(i, SIMD::UInt(31) - Ctlz(v, false));
}
break;
}
case GLSLstd450FindUMsb:
{
UNIMPLEMENTED("GLSLstd450FindUMsb");
auto val = GenericValue(this, routine, insn.word(5));
for (auto i = 0u; i < type.sizeInComponents; i++)
{
dst.move(i, SIMD::UInt(31) - Ctlz(val.UInt(i), false));
}
break;
}
case GLSLstd450InterpolateAtCentroid:
......
......@@ -3210,6 +3210,15 @@ namespace rr
return RValue<Float4>(V(::builder->CreateCall(func, { V(v.value) })));
}
RValue<UInt4> Ctlz(RValue<UInt4> v, bool isZeroUndef)
{
auto func = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::ctlz, { T(UInt4::getType()), T(Bool::getType()) } );
return RValue<UInt4>(V(::builder->CreateCall(func, {
V(v.value),
isZeroUndef ? ::llvm::ConstantInt::getTrue(*::context) : ::llvm::ConstantInt::getFalse(*::context)
})));
}
Type *Float4::getType()
{
return T(llvm::VectorType::get(T(Float::getType()), 4));
......
......@@ -2230,6 +2230,14 @@ namespace rr
RValue<Float4> Exp2(RValue<Float4> x);
RValue<Float4> Log2(RValue<Float4> x);
// Bit Manipulation functions.
// TODO: Currentlhy unimplemented for Subzero.
// Count leading zeros.
// Returns 32 when: isZeroUndef && x == 0.
// Returns an undefined value when: !isZeroUndef && x == 0.
RValue<UInt4> Ctlz(RValue<UInt4> x, bool isZeroUndef);
template<class T>
class Pointer : public LValue<Pointer<T>>
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment