Add const-eval for all.

This CL adds const-eval for the `all` builtin.

Bug: tint:1581
Change-Id: Ib1d857ba24114c61e1a90b30dd66d063edfa136d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/107464
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
dan sinclair
2022-11-03 12:07:49 +00:00
committed by Dawn LUCI CQ
parent aa4b64f4c8
commit 58eca19f33
24 changed files with 131 additions and 96 deletions

View File

@@ -410,8 +410,8 @@ fn acos<T: f32_f16>(T) -> T
fn acos<N: num, T: f32_f16>(vec<N, T>) -> vec<N, T>
fn acosh<T: f32_f16>(T) -> T
fn acosh<N: num, T: f32_f16>(vec<N, T>) -> vec<N, T>
fn all(bool) -> bool
fn all<N: num>(vec<N, bool>) -> bool
@const fn all(bool) -> bool
@const fn all<N: num>(vec<N, bool>) -> bool
@const fn any(bool) -> bool
@const fn any<N: num>(vec<N, bool>) -> bool
fn arrayLength<T, A: access>(ptr<storage, array<T>, A>) -> u32

View File

@@ -1570,6 +1570,12 @@ ConstEval::Result ConstEval::OpShiftLeft(const sem::Type* ty,
return r;
}
ConstEval::Result ConstEval::all(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source&) {
return CreateElement(builder, ty, !args[0]->AnyZero());
}
ConstEval::Result ConstEval::any(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source&) {

View File

@@ -377,6 +377,15 @@ class ConstEval {
// Builtins
////////////////////////////////////////////////////////////////////////////
/// all builtin
/// @param ty the expression type
/// @param args the input arguments
/// @param source the source location of the conversion
/// @return the result value, or null if the value cannot be calculated
Result all(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
/// any builtin
/// @param ty the expression type
/// @param args the input arguments

View File

@@ -146,6 +146,35 @@ INSTANTIATE_TEST_SUITE_P( //
C({1.0_a, 0_a}, kPiOver2<AFloat>),
})));
static std::vector<Case> AllCases() {
return {
C({Val(true)}, Val(true)),
C({Val(false)}, Val(false)),
C({Vec(true, true)}, Val(true)),
C({Vec(true, false)}, Val(false)),
C({Vec(false, true)}, Val(false)),
C({Vec(false, false)}, Val(false)),
C({Vec(true, true, true)}, Val(true)),
C({Vec(false, true, true)}, Val(false)),
C({Vec(true, false, true)}, Val(false)),
C({Vec(true, true, false)}, Val(false)),
C({Vec(false, false, false)}, Val(false)),
C({Vec(true, true, true, true)}, Val(true)),
C({Vec(false, true, true, true)}, Val(false)),
C({Vec(true, false, true, true)}, Val(false)),
C({Vec(true, true, false, true)}, Val(false)),
C({Vec(true, true, true, false)}, Val(false)),
C({Vec(false, false, false, false)}, Val(false)),
};
}
INSTANTIATE_TEST_SUITE_P( //
All,
ResolverConstEvalBuiltinTest,
testing::Combine(testing::Values(sem::BuiltinType::kAll), testing::ValuesIn(AllCases())));
static std::vector<Case> AnyCases() {
return {
C({Val(true)}, Val(true)),

View File

@@ -13430,7 +13430,7 @@ constexpr OverloadInfo kOverloads[] = {
/* parameters */ &kParameters[996],
/* return matcher indices */ &kMatcherIndices[41],
/* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
/* const eval */ nullptr,
/* const eval */ &ConstEval::all,
},
{
/* [425] */
@@ -13442,7 +13442,7 @@ constexpr OverloadInfo kOverloads[] = {
/* parameters */ &kParameters[1017],
/* return matcher indices */ &kMatcherIndices[41],
/* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
/* const eval */ nullptr,
/* const eval */ &ConstEval::all,
},
{
/* [426] */