From 94b7c6685880a1f0f1a9c971d46c51246faf032f Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 5 Oct 2020 19:46:16 +0000 Subject: [PATCH] [msl-writer][hlsl-writer] Add countOneBits and reverseBits This Cl adds countOneBits and reverseBits intrinsic support to the MSL and HLSL backends. Bug: tint:250 Change-Id: Idb572da32e9c10767a27326cacf58aafef44a77a Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/29401 Reviewed-by: Ryan Harrison Commit-Queue: dan sinclair --- src/writer/hlsl/generator_impl.cc | 24 ++++++++----- .../hlsl/generator_impl_intrinsic_test.cc | 5 ++- src/writer/msl/generator_impl.cc | 36 +++++++++++-------- .../msl/generator_impl_intrinsic_test.cc | 2 ++ 4 files changed, 42 insertions(+), 25 deletions(-) diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 2b54bac117..86eef79907 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -473,18 +473,12 @@ std::string GeneratorImpl::generate_intrinsic_name(ast::Intrinsic intrinsic) { if (intrinsic == ast::Intrinsic::kAll) { return "all"; } + if (intrinsic == ast::Intrinsic::kCountOneBits) { + return "countbits"; + } if (intrinsic == ast::Intrinsic::kDot) { return "dot"; } - if (intrinsic == ast::Intrinsic::kIsFinite) { - return "isfinite"; - } - if (intrinsic == ast::Intrinsic::kIsInf) { - return "isinf"; - } - if (intrinsic == ast::Intrinsic::kIsNan) { - return "isnan"; - } if (intrinsic == ast::Intrinsic::kDpdy) { return "ddy"; } @@ -508,6 +502,18 @@ std::string GeneratorImpl::generate_intrinsic_name(ast::Intrinsic intrinsic) { intrinsic == ast::Intrinsic::kFwidthCoarse) { return "fwidth"; } + if (intrinsic == ast::Intrinsic::kIsFinite) { + return "isfinite"; + } + if (intrinsic == ast::Intrinsic::kIsInf) { + return "isinf"; + } + if (intrinsic == ast::Intrinsic::kIsNan) { + return "isnan"; + } + if (intrinsic == ast::Intrinsic::kReverseBits) { + return "reversebits"; + } return ""; } diff --git a/src/writer/hlsl/generator_impl_intrinsic_test.cc b/src/writer/hlsl/generator_impl_intrinsic_test.cc index 8b46c7f8f8..7860c75af5 100644 --- a/src/writer/hlsl/generator_impl_intrinsic_test.cc +++ b/src/writer/hlsl/generator_impl_intrinsic_test.cc @@ -46,6 +46,7 @@ INSTANTIATE_TEST_SUITE_P( HlslIntrinsicTest, testing::Values(IntrinsicData{ast::Intrinsic::kAny, "any"}, IntrinsicData{ast::Intrinsic::kAll, "all"}, + IntrinsicData{ast::Intrinsic::kCountOneBits, "countbits"}, IntrinsicData{ast::Intrinsic::kDot, "dot"}, IntrinsicData{ast::Intrinsic::kDpdx, "ddx"}, IntrinsicData{ast::Intrinsic::kDpdxCoarse, "ddx_coarse"}, @@ -58,7 +59,9 @@ INSTANTIATE_TEST_SUITE_P( IntrinsicData{ast::Intrinsic::kFwidthFine, "fwidth"}, IntrinsicData{ast::Intrinsic::kIsFinite, "isfinite"}, IntrinsicData{ast::Intrinsic::kIsInf, "isinf"}, - IntrinsicData{ast::Intrinsic::kIsNan, "isnan"})); + IntrinsicData{ast::Intrinsic::kIsNan, "isnan"}, + IntrinsicData{ast::Intrinsic::kReverseBits, + "reversebits"})); TEST_F(HlslGeneratorImplTest_Intrinsic, DISABLED_Intrinsic_IsNormal) { FAIL(); diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index cd92b1c416..be20cdfb67 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -413,24 +413,12 @@ std::string GeneratorImpl::generate_intrinsic_name(ast::Intrinsic intrinsic) { if (intrinsic == ast::Intrinsic::kAll) { return "all"; } + if (intrinsic == ast::Intrinsic::kCountOneBits) { + return "popcount"; + } if (intrinsic == ast::Intrinsic::kDot) { return "dot"; } - if (intrinsic == ast::Intrinsic::kIsFinite) { - return "isfinite"; - } - if (intrinsic == ast::Intrinsic::kIsInf) { - return "isinf"; - } - if (intrinsic == ast::Intrinsic::kIsNan) { - return "isnan"; - } - if (intrinsic == ast::Intrinsic::kIsNormal) { - return "isnormal"; - } - if (intrinsic == ast::Intrinsic::kSelect) { - return "select"; - } if (intrinsic == ast::Intrinsic::kDpdy || intrinsic == ast::Intrinsic::kDpdyFine || intrinsic == ast::Intrinsic::kDpdyCoarse) { @@ -446,6 +434,24 @@ std::string GeneratorImpl::generate_intrinsic_name(ast::Intrinsic intrinsic) { intrinsic == ast::Intrinsic::kFwidthCoarse) { return "fwidth"; } + if (intrinsic == ast::Intrinsic::kIsFinite) { + return "isfinite"; + } + if (intrinsic == ast::Intrinsic::kIsInf) { + return "isinf"; + } + if (intrinsic == ast::Intrinsic::kIsNan) { + return "isnan"; + } + if (intrinsic == ast::Intrinsic::kIsNormal) { + return "isnormal"; + } + if (intrinsic == ast::Intrinsic::kReverseBits) { + return "reverse_bits"; + } + if (intrinsic == ast::Intrinsic::kSelect) { + return "select"; + } return ""; } diff --git a/src/writer/msl/generator_impl_intrinsic_test.cc b/src/writer/msl/generator_impl_intrinsic_test.cc index ed095716bc..9378229b77 100644 --- a/src/writer/msl/generator_impl_intrinsic_test.cc +++ b/src/writer/msl/generator_impl_intrinsic_test.cc @@ -50,6 +50,7 @@ INSTANTIATE_TEST_SUITE_P( MslIntrinsicTest, testing::Values(IntrinsicData{ast::Intrinsic::kAny, "any"}, IntrinsicData{ast::Intrinsic::kAll, "all"}, + IntrinsicData{ast::Intrinsic::kCountOneBits, "popcount"}, IntrinsicData{ast::Intrinsic::kDot, "dot"}, IntrinsicData{ast::Intrinsic::kDpdx, "dfdx"}, IntrinsicData{ast::Intrinsic::kDpdxCoarse, "dfdx"}, @@ -64,6 +65,7 @@ INSTANTIATE_TEST_SUITE_P( IntrinsicData{ast::Intrinsic::kIsInf, "isinf"}, IntrinsicData{ast::Intrinsic::kIsNan, "isnan"}, IntrinsicData{ast::Intrinsic::kIsNormal, "isnormal"}, + IntrinsicData{ast::Intrinsic::kReverseBits, "reverse_bits"}, IntrinsicData{ast::Intrinsic::kSelect, "select"})); TEST_F(MslGeneratorImplTest, DISABLED_Intrinsic_OuterProduct) {