Implement bitCount intrinsic on SPIR-V and Metal.
This intrinsic was previously lacking a unit test, and wasn't actually
implemented in Metal or SPIR-V. Fortunately it's trivial to add.
Change-Id: I68bbdc58376b579c7f3f0ae5f49323b389c2b8c4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/346263
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/sksl/SkSLMetalCodeGenerator.cpp b/src/sksl/SkSLMetalCodeGenerator.cpp
index e24f358..8d12554 100644
--- a/src/sksl/SkSLMetalCodeGenerator.cpp
+++ b/src/sksl/SkSLMetalCodeGenerator.cpp
@@ -49,6 +49,7 @@
fIntrinsicMap[String("distance")] = SPECIAL(Distance);
fIntrinsicMap[String("dot")] = SPECIAL(Dot);
fIntrinsicMap[String("faceforward")] = SPECIAL(Faceforward);
+ fIntrinsicMap[String("bitCount")] = SPECIAL(BitCount);
fIntrinsicMap[String("findLSB")] = SPECIAL(FindLSB);
fIntrinsicMap[String("findMSB")] = SPECIAL(FindMSB);
fIntrinsicMap[String("length")] = SPECIAL(Length);
@@ -677,6 +678,12 @@
this->write(") * 0.0174532925)");
break;
}
+ case kBitCount_SpecialIntrinsic: {
+ this->write("popcount(");
+ this->writeExpression(*arguments[0], kSequence_Precedence);
+ this->write(")");
+ break;
+ }
case kFindLSB_SpecialIntrinsic: {
// Create a temp variable to store the expression, to avoid double-evaluating it.
String skTemp = this->getTempVariable(arguments[0]->type());