tint: Remove constant::Value::AllEqual()
The only uses of this method were to check for splats when emitting vector constants in some backends, and they can just check for constant::Splat instead. Change-Id: I12f5ecdd4a7c1191a3a516d4fd3f349230e42631 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/122803 Commit-Queue: James Price <jrprice@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
69253ee8a5
commit
7bca4d7293
|
@ -55,9 +55,6 @@ class Composite : public Castable<Composite, Value> {
|
|||
/// @copydoc Value::AnyZero()
|
||||
bool AnyZero() const override { return any_zero; }
|
||||
|
||||
/// @copydoc Value::AllEqual()
|
||||
bool AllEqual() const override { return false; }
|
||||
|
||||
/// @copydoc Value::Hash()
|
||||
size_t Hash() const override { return hash; }
|
||||
|
||||
|
|
|
@ -56,20 +56,6 @@ TEST_F(ConstantTest_Composite, AnyZero) {
|
|||
EXPECT_FALSE(compositeNone->AnyZero());
|
||||
}
|
||||
|
||||
TEST_F(ConstantTest_Composite, AllEqual) {
|
||||
auto* f32 = create<type::F32>();
|
||||
|
||||
auto* fPos0 = create<Scalar<tint::f32>>(f32, 0_f);
|
||||
auto* fNeg0 = create<Scalar<tint::f32>>(f32, -0_f);
|
||||
auto* fPos1 = create<Scalar<tint::f32>>(f32, 1_f);
|
||||
|
||||
auto* compositeEq = create<Composite>(f32, utils::Vector{fPos0, fPos0});
|
||||
auto* compositeNe = create<Composite>(f32, utils::Vector{fNeg0, fPos1, fPos0});
|
||||
|
||||
EXPECT_TRUE(compositeEq->AllEqual());
|
||||
EXPECT_FALSE(compositeNe->AllZero());
|
||||
}
|
||||
|
||||
TEST_F(ConstantTest_Composite, Index) {
|
||||
auto* f32 = create<type::F32>();
|
||||
|
||||
|
|
|
@ -55,9 +55,6 @@ class Scalar : public Castable<Scalar<T>, Value> {
|
|||
/// @copydoc Value::AnyZero()
|
||||
bool AnyZero() const override { return IsPositiveZero(); }
|
||||
|
||||
/// @copydoc Value::AllEqual()
|
||||
bool AllEqual() const override { return true; }
|
||||
|
||||
/// @copydoc Value::Hash()
|
||||
size_t Hash() const override { return utils::Hash(type, ValueOf()); }
|
||||
|
||||
|
|
|
@ -155,72 +155,6 @@ TEST_F(ConstantTest_Scalar, AnyZero) {
|
|||
EXPECT_FALSE(aiNeg1->AnyZero());
|
||||
}
|
||||
|
||||
TEST_F(ConstantTest_Scalar, AllEqual) {
|
||||
auto* i32 = create<type::I32>();
|
||||
auto* u32 = create<type::U32>();
|
||||
auto* f16 = create<type::F16>();
|
||||
auto* f32 = create<type::F32>();
|
||||
auto* bool_ = create<type::Bool>();
|
||||
|
||||
auto* i0 = create<Scalar<tint::i32>>(i32, 0_i);
|
||||
auto* iPos1 = create<Scalar<tint::i32>>(i32, 1_i);
|
||||
auto* iNeg1 = create<Scalar<tint::i32>>(i32, -1_i);
|
||||
|
||||
auto* u0 = create<Scalar<tint::u32>>(u32, 0_u);
|
||||
auto* u1 = create<Scalar<tint::u32>>(u32, 1_u);
|
||||
|
||||
auto* fPos0 = create<Scalar<tint::f32>>(f32, 0_f);
|
||||
auto* fNeg0 = create<Scalar<tint::f32>>(f32, -0_f);
|
||||
auto* fPos1 = create<Scalar<tint::f32>>(f32, 1_f);
|
||||
auto* fNeg1 = create<Scalar<tint::f32>>(f32, -1_f);
|
||||
|
||||
auto* f16Pos0 = create<Scalar<tint::f16>>(f16, 0_h);
|
||||
auto* f16Neg0 = create<Scalar<tint::f16>>(f16, -0_h);
|
||||
auto* f16Pos1 = create<Scalar<tint::f16>>(f16, 1_h);
|
||||
auto* f16Neg1 = create<Scalar<tint::f16>>(f16, -1_h);
|
||||
|
||||
auto* bf = create<Scalar<bool>>(bool_, false);
|
||||
auto* bt = create<Scalar<bool>>(bool_, true);
|
||||
|
||||
auto* afPos0 = create<Scalar<tint::AFloat>>(f32, 0.0_a);
|
||||
auto* afNeg0 = create<Scalar<tint::AFloat>>(f32, -0.0_a);
|
||||
auto* afPos1 = create<Scalar<tint::AFloat>>(f32, 1.0_a);
|
||||
auto* afNeg1 = create<Scalar<tint::AFloat>>(f32, -1.0_a);
|
||||
|
||||
auto* ai0 = create<Scalar<tint::AInt>>(i32, 0_a);
|
||||
auto* aiPos1 = create<Scalar<tint::AInt>>(i32, 1_a);
|
||||
auto* aiNeg1 = create<Scalar<tint::AInt>>(i32, -1_a);
|
||||
|
||||
EXPECT_TRUE(i0->AllEqual());
|
||||
EXPECT_TRUE(iPos1->AllEqual());
|
||||
EXPECT_TRUE(iNeg1->AllEqual());
|
||||
|
||||
EXPECT_TRUE(u0->AllEqual());
|
||||
EXPECT_TRUE(u1->AllEqual());
|
||||
|
||||
EXPECT_TRUE(fPos0->AllEqual());
|
||||
EXPECT_TRUE(fNeg0->AllEqual());
|
||||
EXPECT_TRUE(fPos1->AllEqual());
|
||||
EXPECT_TRUE(fNeg1->AllEqual());
|
||||
|
||||
EXPECT_TRUE(f16Pos0->AllEqual());
|
||||
EXPECT_TRUE(f16Neg0->AllEqual());
|
||||
EXPECT_TRUE(f16Pos1->AllEqual());
|
||||
EXPECT_TRUE(f16Neg1->AllEqual());
|
||||
|
||||
EXPECT_TRUE(bf->AllEqual());
|
||||
EXPECT_TRUE(bt->AllEqual());
|
||||
|
||||
EXPECT_TRUE(afPos0->AllEqual());
|
||||
EXPECT_TRUE(afNeg0->AllEqual());
|
||||
EXPECT_TRUE(afPos1->AllEqual());
|
||||
EXPECT_TRUE(afNeg1->AllEqual());
|
||||
|
||||
EXPECT_TRUE(ai0->AllEqual());
|
||||
EXPECT_TRUE(aiPos1->AllEqual());
|
||||
EXPECT_TRUE(aiNeg1->AllEqual());
|
||||
}
|
||||
|
||||
TEST_F(ConstantTest_Scalar, ValueOf) {
|
||||
auto* i32 = create<type::I32>();
|
||||
auto* u32 = create<type::U32>();
|
||||
|
|
|
@ -50,8 +50,6 @@ class Splat : public Castable<Splat, Value> {
|
|||
bool AllZero() const override { return el->AllZero(); }
|
||||
/// @returns true if the element is zero
|
||||
bool AnyZero() const override { return el->AnyZero(); }
|
||||
/// @returns true
|
||||
bool AllEqual() const override { return true; }
|
||||
|
||||
/// @returns the hash for the splat
|
||||
size_t Hash() const override { return utils::Hash(type, el->Hash(), count); }
|
||||
|
|
|
@ -56,22 +56,6 @@ TEST_F(ConstantTest_Splat, AnyZero) {
|
|||
EXPECT_FALSE(SpfPos1->AnyZero());
|
||||
}
|
||||
|
||||
TEST_F(ConstantTest_Splat, AllEqual) {
|
||||
auto* f32 = create<type::F32>();
|
||||
|
||||
auto* fPos0 = create<Scalar<tint::f32>>(f32, 0_f);
|
||||
auto* fNeg0 = create<Scalar<tint::f32>>(f32, -0_f);
|
||||
auto* fPos1 = create<Scalar<tint::f32>>(f32, 1_f);
|
||||
|
||||
auto* SpfPos0 = create<Splat>(f32, fPos0, 2);
|
||||
auto* SpfNeg0 = create<Splat>(f32, fNeg0, 2);
|
||||
auto* SpfPos1 = create<Splat>(f32, fPos1, 2);
|
||||
|
||||
EXPECT_TRUE(SpfPos0->AllEqual());
|
||||
EXPECT_TRUE(SpfNeg0->AllEqual());
|
||||
EXPECT_TRUE(SpfPos1->AllEqual());
|
||||
}
|
||||
|
||||
TEST_F(ConstantTest_Splat, Index) {
|
||||
auto* f32 = create<type::F32>();
|
||||
|
||||
|
|
|
@ -56,9 +56,6 @@ class Value : public Castable<Value, Node> {
|
|||
/// @returns true if any child elements are positive-zero valued.
|
||||
virtual bool AnyZero() const = 0;
|
||||
|
||||
/// @returns true if all child elements have the same value and type.
|
||||
virtual bool AllEqual() const = 0;
|
||||
|
||||
/// @returns a hash of the value.
|
||||
virtual size_t Hash() const = 0;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -236,21 +236,17 @@ TEST_F(ResolverConstEvalTest, Vec3_Convert_f32_to_i32) {
|
|||
EXPECT_TRUE(vec->type()->Is<type::I32>());
|
||||
EXPECT_EQ(vec->Width(), 3u);
|
||||
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllZero());
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<AInt>(), 1);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<AInt>(), 2);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->ValueAs<AInt>(), 3);
|
||||
|
@ -269,21 +265,17 @@ TEST_F(ResolverConstEvalTest, Vec3_Convert_u32_to_f32) {
|
|||
EXPECT_TRUE(vec->type()->Is<type::F32>());
|
||||
EXPECT_EQ(vec->Width(), 3u);
|
||||
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllZero());
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<AFloat>(), 10.f);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<AFloat>(), 20.f);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->ValueAs<AFloat>(), 30.f);
|
||||
|
@ -304,21 +296,17 @@ TEST_F(ResolverConstEvalTest, Vec3_Convert_f16_to_i32) {
|
|||
EXPECT_TRUE(vec->type()->Is<type::I32>());
|
||||
EXPECT_EQ(vec->Width(), 3u);
|
||||
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllZero());
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<AInt>(), 1_i);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<AInt>(), 2_i);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->ValueAs<AInt>(), 3_i);
|
||||
|
@ -339,21 +327,17 @@ TEST_F(ResolverConstEvalTest, Vec3_Convert_u32_to_f16) {
|
|||
EXPECT_TRUE(vec->type()->Is<type::F16>());
|
||||
EXPECT_EQ(vec->Width(), 3u);
|
||||
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllZero());
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<AFloat>(), 10.f);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<AFloat>(), 20.f);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->ValueAs<AFloat>(), 30.f);
|
||||
|
@ -372,21 +356,17 @@ TEST_F(ResolverConstEvalTest, Vec3_Convert_Large_f32_to_i32) {
|
|||
EXPECT_TRUE(vec->type()->Is<type::I32>());
|
||||
EXPECT_EQ(vec->Width(), 3u);
|
||||
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllZero());
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<AInt>(), i32::Highest());
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<AInt>(), i32::Lowest());
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->ValueAs<AInt>(), i32::Highest());
|
||||
|
@ -405,21 +385,17 @@ TEST_F(ResolverConstEvalTest, Vec3_Convert_Large_f32_to_u32) {
|
|||
EXPECT_TRUE(vec->type()->Is<type::U32>());
|
||||
EXPECT_EQ(vec->Width(), 3u);
|
||||
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllEqual());
|
||||
EXPECT_TRUE(sem->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllZero());
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<AInt>(), u32::Highest());
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<AInt>(), u32::Lowest());
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->ValueAs<AInt>(), u32::Highest());
|
||||
|
@ -450,23 +426,19 @@ TEST_F(ResolverConstEvalTest, Vec3_Convert_Small_f32_to_f16) {
|
|||
EXPECT_TRUE(vec->type()->Is<type::F16>());
|
||||
EXPECT_EQ(vec->Width(), 3u);
|
||||
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllEqual());
|
||||
EXPECT_TRUE(sem->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllZero());
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<AFloat>(), 0.0);
|
||||
EXPECT_FALSE(std::signbit(sem->ConstantValue()->Index(0)->ValueAs<AFloat>().value));
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<AFloat>(), -0.0);
|
||||
EXPECT_TRUE(std::signbit(sem->ConstantValue()->Index(1)->ValueAs<AFloat>().value));
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AllEqual());
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AnyZero());
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->ValueAs<AFloat>(), 0.0);
|
||||
|
@ -487,17 +459,14 @@ TEST_F(ResolverConstEvalTest, StructAbstractSplat_to_StructDifferentTypes) {
|
|||
auto* c = Sem().Get(expr_c);
|
||||
ASSERT_NE(c, nullptr);
|
||||
EXPECT_TRUE(c->ConstantValue()->Is<constant::Splat>());
|
||||
EXPECT_TRUE(c->ConstantValue()->AllEqual());
|
||||
EXPECT_TRUE(c->ConstantValue()->AnyZero());
|
||||
EXPECT_TRUE(c->ConstantValue()->AllZero());
|
||||
|
||||
EXPECT_TRUE(c->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_TRUE(c->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_TRUE(c->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_TRUE(c->ConstantValue()->Index(0)->Type()->Is<type::AbstractFloat>());
|
||||
EXPECT_EQ(c->ConstantValue()->Index(0)->ValueAs<AFloat>(), 0_f);
|
||||
|
||||
EXPECT_TRUE(c->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_TRUE(c->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_TRUE(c->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_TRUE(c->ConstantValue()->Index(1)->Type()->Is<type::AbstractFloat>());
|
||||
|
@ -507,17 +476,14 @@ TEST_F(ResolverConstEvalTest, StructAbstractSplat_to_StructDifferentTypes) {
|
|||
ASSERT_NE(v, nullptr);
|
||||
EXPECT_TRUE(v->Is<sem::Materialize>());
|
||||
EXPECT_TRUE(v->ConstantValue()->Is<constant::Splat>());
|
||||
EXPECT_TRUE(v->ConstantValue()->AllEqual());
|
||||
EXPECT_TRUE(v->ConstantValue()->AnyZero());
|
||||
EXPECT_TRUE(v->ConstantValue()->AllZero());
|
||||
|
||||
EXPECT_TRUE(v->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_TRUE(v->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_TRUE(v->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_TRUE(v->ConstantValue()->Index(0)->Type()->Is<type::F32>());
|
||||
EXPECT_EQ(v->ConstantValue()->Index(0)->ValueAs<f32>(), 0_f);
|
||||
|
||||
EXPECT_TRUE(v->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_TRUE(v->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_TRUE(v->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_TRUE(v->ConstantValue()->Index(1)->Type()->Is<type::F32>());
|
||||
|
|
|
@ -29,7 +29,6 @@ TEST_F(ResolverConstEvalTest, Vec3_Index) {
|
|||
ASSERT_NE(sem, nullptr);
|
||||
ASSERT_TRUE(sem->Type()->Is<type::I32>());
|
||||
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
|
||||
EXPECT_TRUE(sem->ConstantValue()->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->ValueAs<i32>(), 3_i);
|
||||
|
@ -133,7 +132,6 @@ TEST_F(ResolverConstEvalTest, Vec3_Swizzle_Scalar) {
|
|||
ASSERT_NE(sem, nullptr);
|
||||
ASSERT_TRUE(sem->Type()->Is<type::I32>());
|
||||
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
|
||||
EXPECT_TRUE(sem->ConstantValue()->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->ValueAs<i32>(), 2_i);
|
||||
|
@ -152,12 +150,10 @@ TEST_F(ResolverConstEvalTest, Vec3_Swizzle_Vector) {
|
|||
EXPECT_EQ(vec->Width(), 2u);
|
||||
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<f32>(), 3._a);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<f32>(), 1._a);
|
||||
|
@ -174,7 +170,6 @@ TEST_F(ResolverConstEvalTest, Vec3_Swizzle_Chain) {
|
|||
ASSERT_NE(sem, nullptr);
|
||||
ASSERT_TRUE(sem->Type()->Is<type::I32>());
|
||||
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
|
||||
EXPECT_TRUE(sem->ConstantValue()->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->ValueAs<i32>(), 2_i);
|
||||
|
@ -194,12 +189,10 @@ TEST_F(ResolverConstEvalTest, Mat3x2_Index) {
|
|||
EXPECT_EQ(vec->Width(), 2u);
|
||||
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<f32>(), 5._a);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<f32>(), 6._a);
|
||||
|
@ -241,17 +234,14 @@ TEST_F(ResolverConstEvalTest, Array_vec3_f32_Index) {
|
|||
EXPECT_EQ(vec->Width(), 3u);
|
||||
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<f32>(), 4_f);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<f32>(), 5_f);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->ValueAs<f32>(), 6_f);
|
||||
|
@ -310,36 +300,29 @@ TEST_F(ResolverConstEvalTest, ChainedIndex) {
|
|||
EXPECT_EQ(ty->columns(), 2u);
|
||||
EXPECT_EQ(ty->rows(), 3u);
|
||||
EXPECT_EQ(mat->ConstantValue()->Type(), mat->Type());
|
||||
EXPECT_FALSE(mat->ConstantValue()->AllEqual());
|
||||
EXPECT_TRUE(mat->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(mat->ConstantValue()->AllZero());
|
||||
|
||||
EXPECT_TRUE(mat->ConstantValue()->Index(0)->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(0)->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(0)->Index(0)->AllZero());
|
||||
EXPECT_EQ(mat->ConstantValue()->Index(0)->Index(0)->ValueAs<f32>(), 7_f);
|
||||
|
||||
EXPECT_TRUE(mat->ConstantValue()->Index(0)->Index(1)->AllEqual());
|
||||
EXPECT_TRUE(mat->ConstantValue()->Index(0)->Index(1)->AnyZero());
|
||||
EXPECT_TRUE(mat->ConstantValue()->Index(0)->Index(1)->AllZero());
|
||||
EXPECT_EQ(mat->ConstantValue()->Index(0)->Index(1)->ValueAs<f32>(), 0_f);
|
||||
|
||||
EXPECT_TRUE(mat->ConstantValue()->Index(0)->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(0)->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(0)->Index(2)->AllZero());
|
||||
EXPECT_EQ(mat->ConstantValue()->Index(0)->Index(2)->ValueAs<f32>(), 9_f);
|
||||
|
||||
EXPECT_TRUE(mat->ConstantValue()->Index(1)->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(1)->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(1)->Index(0)->AllZero());
|
||||
EXPECT_EQ(mat->ConstantValue()->Index(1)->Index(0)->ValueAs<f32>(), 10_f);
|
||||
|
||||
EXPECT_TRUE(mat->ConstantValue()->Index(1)->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(1)->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(1)->Index(1)->AllZero());
|
||||
EXPECT_EQ(mat->ConstantValue()->Index(1)->Index(1)->ValueAs<f32>(), 11_f);
|
||||
|
||||
EXPECT_TRUE(mat->ConstantValue()->Index(1)->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(1)->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(1)->Index(2)->AllZero());
|
||||
EXPECT_EQ(mat->ConstantValue()->Index(1)->Index(2)->ValueAs<f32>(), 12_f);
|
||||
|
@ -352,21 +335,17 @@ TEST_F(ResolverConstEvalTest, ChainedIndex) {
|
|||
EXPECT_TRUE(ty->type()->Is<type::F32>());
|
||||
EXPECT_EQ(ty->Width(), 3u);
|
||||
EXPECT_EQ(vec->ConstantValue()->Type(), vec->Type());
|
||||
EXPECT_FALSE(vec->ConstantValue()->AllEqual());
|
||||
EXPECT_TRUE(vec->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(vec->ConstantValue()->AllZero());
|
||||
|
||||
EXPECT_TRUE(vec->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(vec->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(vec->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(vec->ConstantValue()->Index(0)->ValueAs<f32>(), 7_f);
|
||||
|
||||
EXPECT_TRUE(vec->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_TRUE(vec->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_TRUE(vec->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(vec->ConstantValue()->Index(1)->ValueAs<f32>(), 0_f);
|
||||
|
||||
EXPECT_TRUE(vec->ConstantValue()->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(vec->ConstantValue()->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(vec->ConstantValue()->Index(2)->AllZero());
|
||||
EXPECT_EQ(vec->ConstantValue()->Index(2)->ValueAs<f32>(), 9_f);
|
||||
|
@ -376,7 +355,6 @@ TEST_F(ResolverConstEvalTest, ChainedIndex) {
|
|||
EXPECT_NE(f, nullptr);
|
||||
EXPECT_TRUE(f->Type()->Is<type::F32>());
|
||||
EXPECT_EQ(f->ConstantValue()->Type(), f->Type());
|
||||
EXPECT_TRUE(f->ConstantValue()->AllEqual());
|
||||
EXPECT_FALSE(f->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(f->ConstantValue()->AllZero());
|
||||
EXPECT_EQ(f->ConstantValue()->ValueAs<f32>(), 9_f);
|
||||
|
|
|
@ -46,13 +46,11 @@ TEST_F(ResolverConstEvalTest, StructMemberAccess) {
|
|||
EXPECT_EQ(str->Members().Length(), 2u);
|
||||
ASSERT_NE(outer->ConstantValue(), nullptr);
|
||||
EXPECT_TYPE(outer->ConstantValue()->Type(), outer->Type());
|
||||
EXPECT_FALSE(outer->ConstantValue()->AllEqual());
|
||||
EXPECT_TRUE(outer->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(outer->ConstantValue()->AllZero());
|
||||
|
||||
auto* o1 = Sem().Get(o1_expr);
|
||||
ASSERT_NE(o1->ConstantValue(), nullptr);
|
||||
EXPECT_FALSE(o1->ConstantValue()->AllEqual());
|
||||
EXPECT_FALSE(o1->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(o1->ConstantValue()->AllZero());
|
||||
EXPECT_TRUE(o1->ConstantValue()->Type()->Is<sem::Struct>());
|
||||
|
@ -63,7 +61,6 @@ TEST_F(ResolverConstEvalTest, StructMemberAccess) {
|
|||
|
||||
auto* i2 = Sem().Get(i2_expr);
|
||||
ASSERT_NE(i2->ConstantValue(), nullptr);
|
||||
EXPECT_TRUE(i2->ConstantValue()->AllEqual());
|
||||
EXPECT_FALSE(i2->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(i2->ConstantValue()->AllZero());
|
||||
EXPECT_TRUE(i2->ConstantValue()->Type()->Is<type::U32>());
|
||||
|
@ -85,7 +82,6 @@ TEST_F(ResolverConstEvalTest, Matrix_AFloat_Construct_From_AInt_Vectors) {
|
|||
EXPECT_TYPE(cv->Type(), sem->Type());
|
||||
EXPECT_TRUE(cv->Index(0)->Type()->Is<type::Vector>());
|
||||
EXPECT_TRUE(cv->Index(0)->Index(0)->Type()->Is<type::AbstractFloat>());
|
||||
EXPECT_FALSE(cv->AllEqual());
|
||||
EXPECT_FALSE(cv->AnyZero());
|
||||
EXPECT_FALSE(cv->AllZero());
|
||||
auto* c0 = cv->Index(0);
|
||||
|
@ -124,7 +120,6 @@ TEST_F(ResolverConstEvalTest, MatrixMemberAccess_AFloat) {
|
|||
EXPECT_TYPE(cv->Type(), sem->Type());
|
||||
EXPECT_TRUE(cv->Index(0)->Type()->Is<type::Vector>());
|
||||
EXPECT_TRUE(cv->Index(0)->Index(0)->Type()->Is<type::AbstractFloat>());
|
||||
EXPECT_FALSE(cv->AllEqual());
|
||||
EXPECT_FALSE(cv->AnyZero());
|
||||
EXPECT_FALSE(cv->AllZero());
|
||||
|
||||
|
@ -201,7 +196,6 @@ TEST_F(ResolverConstEvalTest, MatrixMemberAccess_f32) {
|
|||
EXPECT_TYPE(cv->Type(), sem->Type());
|
||||
EXPECT_TRUE(cv->Index(0)->Type()->Is<type::Vector>());
|
||||
EXPECT_TRUE(cv->Index(0)->Index(0)->Type()->Is<type::F32>());
|
||||
EXPECT_FALSE(cv->AllEqual());
|
||||
EXPECT_FALSE(cv->AnyZero());
|
||||
EXPECT_FALSE(cv->AllZero());
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@ class MockConstant : public constant::Value {
|
|||
size_t NumElements() const override { return 0; }
|
||||
bool AllZero() const override { return {}; }
|
||||
bool AnyZero() const override { return {}; }
|
||||
bool AllEqual() const override { return {}; }
|
||||
size_t Hash() const override { return 0; }
|
||||
MockConstant* Clone(constant::CloneContext&) const override { return nullptr; }
|
||||
|
||||
|
|
|
@ -2404,8 +2404,8 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out, const constant::Value
|
|||
|
||||
ScopedParen sp(out);
|
||||
|
||||
if (constant->AllEqual()) {
|
||||
return EmitConstant(out, constant->Index(0));
|
||||
if (auto* splat = constant->As<constant::Splat>()) {
|
||||
return EmitConstant(out, splat->el);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < v->Width(); i++) {
|
||||
|
|
|
@ -3323,10 +3323,10 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out,
|
|||
return true;
|
||||
},
|
||||
[&](const type::Vector* v) {
|
||||
if (constant->AllEqual()) {
|
||||
if (auto* splat = constant->As<constant::Splat>()) {
|
||||
{
|
||||
ScopedParen sp(out);
|
||||
if (!EmitConstant(out, constant->Index(0), is_variable_initializer)) {
|
||||
if (!EmitConstant(out, splat->el, is_variable_initializer)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1709,8 +1709,8 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out, const constant::Value
|
|||
|
||||
ScopedParen sp(out);
|
||||
|
||||
if (constant->AllEqual()) {
|
||||
if (!EmitConstant(out, constant->Index(0))) {
|
||||
if (auto* splat = constant->As<constant::Splat>()) {
|
||||
if (!EmitConstant(out, splat->el)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue