Reactor: Add Ctlz() and Cttz() overloads for UInt
We had these already for UInt4.
Bug: b/139010488
Change-Id: Idb9451db1221da7b309b64ef407abcea33fea21e
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/34768
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
diff --git a/src/Reactor/LLVMReactor.cpp b/src/Reactor/LLVMReactor.cpp
index 9ada8ee..c255b81 100644
--- a/src/Reactor/LLVMReactor.cpp
+++ b/src/Reactor/LLVMReactor.cpp
@@ -3891,6 +3891,15 @@
return RValue<Float4>(V(jit->builder->CreateCall(func, V(v.value))));
}
+ RValue<UInt> Ctlz(RValue<UInt> v, bool isZeroUndef)
+ {
+ auto func = llvm::Intrinsic::getDeclaration(jit->module.get(), llvm::Intrinsic::ctlz, { T(UInt::getType()) } );
+ return RValue<UInt>(V(jit->builder->CreateCall2(func, ARGS(
+ V(v.value),
+ isZeroUndef ? ::llvm::ConstantInt::getTrue(jit->context) : ::llvm::ConstantInt::getFalse(jit->context)
+ ))));
+ }
+
RValue<UInt4> Ctlz(RValue<UInt4> v, bool isZeroUndef)
{
auto func = llvm::Intrinsic::getDeclaration(jit->module.get(), llvm::Intrinsic::ctlz, { T(UInt4::getType()) } );
@@ -3900,6 +3909,15 @@
))));
}
+ RValue<UInt> Cttz(RValue<UInt> v, bool isZeroUndef)
+ {
+ auto func = llvm::Intrinsic::getDeclaration(jit->module.get(), llvm::Intrinsic::cttz, { T(UInt::getType()) } );
+ return RValue<UInt>(V(jit->builder->CreateCall2(func, ARGS(
+ V(v.value),
+ isZeroUndef ? ::llvm::ConstantInt::getTrue(jit->context) : ::llvm::ConstantInt::getFalse(jit->context)
+ ))));
+ }
+
RValue<UInt4> Cttz(RValue<UInt4> v, bool isZeroUndef)
{
auto func = llvm::Intrinsic::getDeclaration(jit->module.get(), llvm::Intrinsic::cttz, { T(UInt4::getType()) } );
diff --git a/src/Reactor/Reactor.hpp b/src/Reactor/Reactor.hpp
index 61af2d0..597c983 100644
--- a/src/Reactor/Reactor.hpp
+++ b/src/Reactor/Reactor.hpp
@@ -2324,11 +2324,13 @@
// Count leading zeros.
// Returns 32 when: isZeroUndef && x == 0.
// Returns an undefined value when: !isZeroUndef && x == 0.
+ RValue<UInt> Ctlz(RValue<UInt> 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<UInt> Cttz(RValue<UInt> x, bool isZeroUndef);
RValue<UInt4> Cttz(RValue<UInt4> x, bool isZeroUndef);
template<class T>
diff --git a/src/Reactor/SubzeroReactor.cpp b/src/Reactor/SubzeroReactor.cpp
index 2099688..91feb65 100644
--- a/src/Reactor/SubzeroReactor.cpp
+++ b/src/Reactor/SubzeroReactor.cpp
@@ -3542,7 +3542,9 @@
RValue<Float4> Log(RValue<Float4> x) { UNIMPLEMENTED("Subzero Log()"); return Float4(0); }
RValue<Float4> Exp2(RValue<Float4> x) { UNIMPLEMENTED("Subzero Exp2()"); return Float4(0); }
RValue<Float4> Log2(RValue<Float4> x) { UNIMPLEMENTED("Subzero Log2()"); return Float4(0); }
+ RValue<UInt> Ctlz(RValue<UInt> x, bool isZeroUndef) { UNIMPLEMENTED("Subzero Ctlz()"); return UInt(0); }
RValue<UInt4> Ctlz(RValue<UInt4> x, bool isZeroUndef) { UNIMPLEMENTED("Subzero Ctlz()"); return UInt4(0); }
+ RValue<UInt> Cttz(RValue<UInt> x, bool isZeroUndef) { UNIMPLEMENTED("Subzero Cttz()"); return UInt(0); }
RValue<UInt4> Cttz(RValue<UInt4> x, bool isZeroUndef) { UNIMPLEMENTED("Subzero Cttz()"); return UInt4(0); }
void EmitDebugLocation() {}