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

View File

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

View File

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

View File

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

View File

@ -67,27 +67,6 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftRight) {
ASSERT_TRUE(init->literal()->AsBool()->IsTrue()); 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) { TEST_F(ParserImplTest, ShiftExpression_InvalidLHS) {
auto* p = parser("if (a) {} << true"); auto* p = parser("if (a) {} << true");
auto e = p->shift_expression(); auto e = p->shift_expression();

View File

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

View File

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

View File

@ -1144,9 +1144,10 @@ uint32_t Builder::GenerateBinaryExpression(ast::BinaryExpression* expr) {
} else if (expr->IsShiftLeft()) { } else if (expr->IsShiftLeft()) {
op = spv::Op::OpShiftLeftLogical; op = spv::Op::OpShiftLeftLogical;
} else if (expr->IsShiftRight()) { } 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; op = spv::Op::OpShiftRightLogical;
} else if (expr->IsShiftRightArith()) {
op = spv::Op::OpShiftRightArithmetic;
} else if (expr->IsSubtract()) { } else if (expr->IsSubtract()) {
op = lhs_is_float_or_vec ? spv::Op::OpFSub : spv::Op::OpISub; op = lhs_is_float_or_vec ? spv::Op::OpFSub : spv::Op::OpISub;
} else if (expr->IsXor()) { } else if (expr->IsXor()) {

View File

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

View File

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

View File

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