Make maskAny() SIMD width agnostic.
This change also replaces two shift operations with a single compare
operation.
Bug: b/237494823
Change-Id: Ifec8b8741c362f1ee0ac66e2b3ed17f0909b1b9b
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/66870
Tested-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Pipeline/PixelProgram.cpp b/src/Pipeline/PixelProgram.cpp
index 9933839..8307544 100644
--- a/src/Pipeline/PixelProgram.cpp
+++ b/src/Pipeline/PixelProgram.cpp
@@ -34,7 +34,6 @@
// Union all cMask and return it as Booleans
SIMD::Int PixelProgram::maskAny(Int cMask[4], const SampleSet &samples)
{
- ASSERT(SIMD::Width == 4);
// See if at least 1 sample is used
Int maskUnion = 0;
for(unsigned int q : samples)
@@ -43,17 +42,15 @@
}
// Convert to Booleans
- SIMD::Int laneBits = SIMD::Int(1, 2, 4, 8);
- SIMD::Int laneShiftsToMSB = SIMD::Int(31, 30, 29, 28);
+ SIMD::Int laneBits = SIMD::Int([](int i) { return 1 << i; }); // 1, 2, 4, 8, ...
SIMD::Int mask(maskUnion);
- mask = ((mask & laneBits) << laneShiftsToMSB) >> 31;
+ mask = CmpNEQ(mask & laneBits, 0);
return mask;
}
// Union all cMask/sMask/zMask and return it as Booleans
SIMD::Int PixelProgram::maskAny(Int cMask[4], Int sMask[4], Int zMask[4], const SampleSet &samples)
{
- ASSERT(SIMD::Width == 4);
// See if at least 1 sample is used
Int maskUnion = 0;
for(unsigned int q : samples)
@@ -62,10 +59,9 @@
}
// Convert to Booleans
- SIMD::Int laneBits = SIMD::Int(1, 2, 4, 8);
- SIMD::Int laneShiftsToMSB = SIMD::Int(31, 30, 29, 28);
+ SIMD::Int laneBits = SIMD::Int([](int i) { return 1 << i; }); // 1, 2, 4, 8, ...
SIMD::Int mask(maskUnion);
- mask = ((mask & laneBits) << laneShiftsToMSB) >> 31;
+ mask = CmpNEQ(mask & laneBits, 0);
return mask;
}