Remove right shift arithmetic operand.

The `>>>` symbol was folded into the `>>` symbol in WGSL. This CL
removes `>>>` from Tint.

Change-Id: I9d900de9a6026a8099796b94aad44483f0c6813f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22582
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
dan sinclair 2020-06-03 16:11:44 +00:00
parent 2b23e4bd70
commit ccb699eb00
11 changed files with 36 additions and 78 deletions

View File

@ -40,7 +40,6 @@ enum class BinaryOp {
kGreaterThanEqual,
kShiftLeft,
kShiftRight,
kShiftRightArith,
kAdd,
kSubtract,
kMultiply,
@ -105,8 +104,6 @@ class BinaryExpression : public Expression {
bool IsShiftLeft() const { return op_ == BinaryOp::kShiftLeft; }
/// @returns true if the op is shift right
bool IsShiftRight() const { return op_ == BinaryOp::kShiftRight; }
/// @returns true if the op is shift right arith
bool IsShiftRightArith() const { return op_ == BinaryOp::kShiftRightArith; }
/// @returns true if the op is add
bool IsAdd() const { return op_ == BinaryOp::kAdd; }
/// @returns true if the op is subtract
@ -193,9 +190,6 @@ inline std::ostream& operator<<(std::ostream& out, BinaryOp op) {
case BinaryOp::kShiftRight:
out << "shift_right";
break;
case BinaryOp::kShiftRightArith:
out << "shift_right_arith";
break;
case BinaryOp::kAdd:
out << "add";
break;

View File

@ -199,9 +199,8 @@ ast::BinaryOp ConvertBinaryOp(SpvOp opcode) {
case SpvOpShiftLeftLogical:
return ast::BinaryOp::kShiftLeft;
case SpvOpShiftRightLogical:
return ast::BinaryOp::kShiftRight;
case SpvOpShiftRightArithmetic:
return ast::BinaryOp::kShiftRightArith;
return ast::BinaryOp::kShiftRight;
case SpvOpLogicalEqual:
case SpvOpIEqual:
case SpvOpFOrdEqual:

View File

@ -246,36 +246,36 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Values(
// Both uint
BinaryData{"uint", "uint_10", "OpShiftRightArithmetic", "uint_20",
"__u32", "ScalarConstructor{10}", "shift_right_arith",
"__u32", "ScalarConstructor{10}", "shift_right",
"ScalarConstructor{20}"},
// Both int
BinaryData{"int", "int_30", "OpShiftRightArithmetic", "int_40", "__i32",
"ScalarConstructor{30}", "shift_right_arith",
"ScalarConstructor{30}", "shift_right",
"ScalarConstructor{40}"},
// Mixed, returning uint
BinaryData{"uint", "int_30", "OpShiftRightArithmetic", "uint_10",
"__u32", "ScalarConstructor{30}", "shift_right_arith",
"__u32", "ScalarConstructor{30}", "shift_right",
"ScalarConstructor{10}"},
// Mixed, returning int
BinaryData{"int", "int_30", "OpShiftRightArithmetic", "uint_10",
"__i32", "ScalarConstructor{30}", "shift_right_arith",
"__i32", "ScalarConstructor{30}", "shift_right",
"ScalarConstructor{10}"},
// Both v2uint
BinaryData{"v2uint", "v2uint_10_20", "OpShiftRightArithmetic",
"v2uint_20_10", "__vec_2__u32", AstFor("v2uint_10_20"),
"shift_right_arith", AstFor("v2uint_20_10")},
"shift_right", AstFor("v2uint_20_10")},
// Both v2int
BinaryData{"v2int", "v2int_30_40", "OpShiftRightArithmetic",
"v2int_40_30", "__vec_2__i32", AstFor("v2int_30_40"),
"shift_right_arith", AstFor("v2int_40_30")},
"shift_right", AstFor("v2int_40_30")},
// Mixed, returning v2uint
BinaryData{"v2uint", "v2int_30_40", "OpShiftRightArithmetic",
"v2uint_10_20", "__vec_2__u32", AstFor("v2int_30_40"),
"shift_right_arith", AstFor("v2uint_10_20")},
"shift_right", AstFor("v2uint_10_20")},
// Mixed, returning v2int
BinaryData{"v2int", "v2int_40_30", "OpShiftRightArithmetic",
"v2uint_20_10", "__vec_2__i32", AstFor("v2int_40_30"),
"shift_right_arith", AstFor("v2uint_20_10")}));
"shift_right", AstFor("v2uint_20_10")}));
INSTANTIATE_TEST_SUITE_P(
SpvParserTest_BitwiseAnd,

View File

@ -2291,13 +2291,11 @@ std::unique_ptr<ast::Expression> ParserImpl::additive_expression() {
// :
// | LESS_THAN LESS_THAN additive_expression shift_expr
// | GREATER_THAN GREATER_THAN additive_expression shift_expr
// | GREATER_THAN GREATER_THAN GREATER_THAN additive_expression shift_expr
std::unique_ptr<ast::Expression> ParserImpl::shift_expr(
std::unique_ptr<ast::Expression> lhs) {
auto t = peek();
auto source = t.source();
auto t2 = peek(1);
auto t3 = peek(2);
auto* name = "";
ast::BinaryOp op = ast::BinaryOp::kNone;
@ -2306,12 +2304,6 @@ std::unique_ptr<ast::Expression> ParserImpl::shift_expr(
next(); // Consume the t2 peek
op = ast::BinaryOp::kShiftLeft;
name = "<<";
} else if (t.IsGreaterThan() && t2.IsGreaterThan() && t3.IsGreaterThan()) {
next(); // Consume the t peek
next(); // Consume the t2 peek
next(); // Consume the t3 peek
op = ast::BinaryOp::kShiftRightArith;
name = ">>>";
} else if (t.IsGreaterThan() && t2.IsGreaterThan()) {
next(); // Consume the t peek
next(); // Consume the t2 peek

View File

@ -67,27 +67,6 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftRight) {
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftRightArith) {
auto* p = parser("a >>> true");
auto e = p->shift_expression();
ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e, nullptr);
ASSERT_TRUE(e->IsBinary());
auto* rel = e->AsBinary();
EXPECT_EQ(ast::BinaryOp::kShiftRightArith, rel->op());
ASSERT_TRUE(rel->lhs()->IsIdentifier());
auto* ident = rel->lhs()->AsIdentifier();
EXPECT_EQ(ident->name(), "a");
ASSERT_TRUE(rel->rhs()->IsConstructor());
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
TEST_F(ParserImplTest, ShiftExpression_InvalidLHS) {
auto* p = parser("if (a) {} << true");
auto e = p->shift_expression();

View File

@ -558,8 +558,8 @@ bool TypeDeterminer::DetermineBinary(ast::BinaryExpression* expr) {
// Result type matches first parameter type
if (expr->IsAnd() || expr->IsOr() || expr->IsXor() || expr->IsShiftLeft() ||
expr->IsShiftRight() || expr->IsShiftRightArith() || expr->IsAdd() ||
expr->IsSubtract() || expr->IsDivide() || expr->IsModulo()) {
expr->IsShiftRight() || expr->IsAdd() || expr->IsSubtract() ||
expr->IsDivide() || expr->IsModulo()) {
expr->set_result_type(expr->lhs()->result_type()->UnwrapPtrIfNeeded());
return true;
}

View File

@ -953,7 +953,6 @@ INSTANTIATE_TEST_SUITE_P(TypeDeterminerTest,
ast::BinaryOp::kXor,
ast::BinaryOp::kShiftLeft,
ast::BinaryOp::kShiftRight,
ast::BinaryOp::kShiftRightArith,
ast::BinaryOp::kAdd,
ast::BinaryOp::kSubtract,
ast::BinaryOp::kDivide,

View File

@ -1144,9 +1144,10 @@ uint32_t Builder::GenerateBinaryExpression(ast::BinaryExpression* expr) {
} else if (expr->IsShiftLeft()) {
op = spv::Op::OpShiftLeftLogical;
} else if (expr->IsShiftRight()) {
// TODO(dsinclair): This depends on the type of the LHS if it's a
// OpShiftRightLogical or OpShiftRightArithmetic
// http://crbug.com/tint/84
op = spv::Op::OpShiftRightLogical;
} else if (expr->IsShiftRightArith()) {
op = spv::Op::OpShiftRightArithmetic;
} else if (expr->IsSubtract()) {
op = lhs_is_float_or_vec ? spv::Op::OpFSub : spv::Op::OpISub;
} else if (expr->IsXor()) {

View File

@ -125,18 +125,17 @@ TEST_P(BinaryArithSignedIntegerTest, Vector) {
INSTANTIATE_TEST_SUITE_P(
BuilderTest,
BinaryArithSignedIntegerTest,
testing::Values(
BinaryData{ast::BinaryOp::kAdd, "OpIAdd"},
BinaryData{ast::BinaryOp::kAnd, "OpBitwiseAnd"},
BinaryData{ast::BinaryOp::kDivide, "OpSDiv"},
BinaryData{ast::BinaryOp::kModulo, "OpSMod"},
BinaryData{ast::BinaryOp::kMultiply, "OpIMul"},
BinaryData{ast::BinaryOp::kOr, "OpBitwiseOr"},
BinaryData{ast::BinaryOp::kShiftLeft, "OpShiftLeftLogical"},
BinaryData{ast::BinaryOp::kShiftRight, "OpShiftRightLogical"},
BinaryData{ast::BinaryOp::kShiftRightArith, "OpShiftRightArithmetic"},
BinaryData{ast::BinaryOp::kSubtract, "OpISub"},
BinaryData{ast::BinaryOp::kXor, "OpBitwiseXor"}));
testing::Values(BinaryData{ast::BinaryOp::kAdd, "OpIAdd"},
BinaryData{ast::BinaryOp::kAnd, "OpBitwiseAnd"},
BinaryData{ast::BinaryOp::kDivide, "OpSDiv"},
BinaryData{ast::BinaryOp::kModulo, "OpSMod"},
BinaryData{ast::BinaryOp::kMultiply, "OpIMul"},
BinaryData{ast::BinaryOp::kOr, "OpBitwiseOr"},
BinaryData{ast::BinaryOp::kShiftLeft, "OpShiftLeftLogical"},
BinaryData{ast::BinaryOp::kShiftRight,
"OpShiftRightLogical"},
BinaryData{ast::BinaryOp::kSubtract, "OpISub"},
BinaryData{ast::BinaryOp::kXor, "OpBitwiseXor"}));
using BinaryArithUnsignedIntegerTest = testing::TestWithParam<BinaryData>;
TEST_P(BinaryArithUnsignedIntegerTest, Scalar) {
@ -215,18 +214,17 @@ TEST_P(BinaryArithUnsignedIntegerTest, Vector) {
INSTANTIATE_TEST_SUITE_P(
BuilderTest,
BinaryArithUnsignedIntegerTest,
testing::Values(
BinaryData{ast::BinaryOp::kAdd, "OpIAdd"},
BinaryData{ast::BinaryOp::kAnd, "OpBitwiseAnd"},
BinaryData{ast::BinaryOp::kDivide, "OpUDiv"},
BinaryData{ast::BinaryOp::kModulo, "OpUMod"},
BinaryData{ast::BinaryOp::kMultiply, "OpIMul"},
BinaryData{ast::BinaryOp::kOr, "OpBitwiseOr"},
BinaryData{ast::BinaryOp::kShiftLeft, "OpShiftLeftLogical"},
BinaryData{ast::BinaryOp::kShiftRight, "OpShiftRightLogical"},
BinaryData{ast::BinaryOp::kShiftRightArith, "OpShiftRightArithmetic"},
BinaryData{ast::BinaryOp::kSubtract, "OpISub"},
BinaryData{ast::BinaryOp::kXor, "OpBitwiseXor"}));
testing::Values(BinaryData{ast::BinaryOp::kAdd, "OpIAdd"},
BinaryData{ast::BinaryOp::kAnd, "OpBitwiseAnd"},
BinaryData{ast::BinaryOp::kDivide, "OpUDiv"},
BinaryData{ast::BinaryOp::kModulo, "OpUMod"},
BinaryData{ast::BinaryOp::kMultiply, "OpIMul"},
BinaryData{ast::BinaryOp::kOr, "OpBitwiseOr"},
BinaryData{ast::BinaryOp::kShiftLeft, "OpShiftLeftLogical"},
BinaryData{ast::BinaryOp::kShiftRight,
"OpShiftRightLogical"},
BinaryData{ast::BinaryOp::kSubtract, "OpISub"},
BinaryData{ast::BinaryOp::kXor, "OpBitwiseXor"}));
using BinaryArithFloatTest = testing::TestWithParam<BinaryData>;
TEST_P(BinaryArithFloatTest, Scalar) {

View File

@ -554,9 +554,6 @@ bool GeneratorImpl::EmitBinary(ast::BinaryExpression* expr) {
case ast::BinaryOp::kShiftRight:
out_ << ">>";
break;
case ast::BinaryOp::kShiftRightArith:
out_ << ">>>";
break;
case ast::BinaryOp::kAdd:
out_ << "+";
break;

View File

@ -62,7 +62,6 @@ INSTANTIATE_TEST_SUITE_P(
BinaryData{"(left >= right)", ast::BinaryOp::kGreaterThanEqual},
BinaryData{"(left << right)", ast::BinaryOp::kShiftLeft},
BinaryData{"(left >> right)", ast::BinaryOp::kShiftRight},
BinaryData{"(left >>> right)", ast::BinaryOp::kShiftRightArith},
BinaryData{"(left + right)", ast::BinaryOp::kAdd},
BinaryData{"(left - right)", ast::BinaryOp::kSubtract},
BinaryData{"(left * right)", ast::BinaryOp::kMultiply},