Commit 3f007c4d by Ben Clayton

SpirvShader: Implement GLSLstd450FindILsb

Bug: b/126873455 Tests: dEQP-VK.glsl.builtin.function.integer.findlsb.* Change-Id: I46671fe6b64814a5c9cbc8dd9fe4cc449a328f42 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28789Tested-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 6095826b
...@@ -3605,7 +3605,12 @@ namespace sw ...@@ -3605,7 +3605,12 @@ namespace sw
} }
case GLSLstd450FindILsb: case GLSLstd450FindILsb:
{ {
UNIMPLEMENTED("GLSLstd450FindILsb"); auto val = GenericValue(this, routine, insn.word(5));
for (auto i = 0u; i < type.sizeInComponents; i++)
{
auto v = val.UInt(i);
dst.move(i, Cttz(v, true) | CmpEQ(v, SIMD::UInt(0)));
}
break; break;
} }
case GLSLstd450FindSMsb: case GLSLstd450FindSMsb:
......
...@@ -3219,6 +3219,15 @@ namespace rr ...@@ -3219,6 +3219,15 @@ namespace rr
}))); })));
} }
RValue<UInt4> Cttz(RValue<UInt4> v, bool isZeroUndef)
{
auto func = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::cttz, { 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() Type *Float4::getType()
{ {
return T(llvm::VectorType::get(T(Float::getType()), 4)); return T(llvm::VectorType::get(T(Float::getType()), 4));
......
...@@ -2238,6 +2238,11 @@ namespace rr ...@@ -2238,6 +2238,11 @@ namespace rr
// Returns an undefined value when: !isZeroUndef && x == 0. // Returns an undefined value when: !isZeroUndef && x == 0.
RValue<UInt4> Ctlz(RValue<UInt4> x, bool isZeroUndef); RValue<UInt4> Ctlz(RValue<UInt4> x, bool isZeroUndef);
// Count trailing zeros.
// Returns 32 when: isZeroUndef && x == 0.
// Returns an undefined value when: !isZeroUndef && x == 0.
RValue<UInt4> Cttz(RValue<UInt4> x, bool isZeroUndef);
template<class T> template<class T>
class Pointer : public LValue<Pointer<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