[spirv-writer] Emit ShiftRightArithmetic.

This CL updates the SPIR-V writer to emit the arithmetic right shift if
the LHS of the expression is a signed scalar or vector.

Bug: tint:84
Change-Id: I4ca33a31783e1954515db5f12b2cf1d364aedee4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28940
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
dan sinclair 2020-09-24 14:29:29 +00:00 committed by Commit Bot service account
parent effd888d2f
commit 45292213bd
2 changed files with 4 additions and 4 deletions

View File

@ -1428,10 +1428,10 @@ uint32_t Builder::GenerateBinaryExpression(ast::BinaryExpression* expr) {
op = spv::Op::OpBitwiseOr;
} else if (expr->IsShiftLeft()) {
op = spv::Op::OpShiftLeftLogical;
} else if (expr->IsShiftRight() && lhs_type->is_signed_scalar_or_vector()) {
// A shift right with a signed LHS is an arithmetic shift.
op = spv::Op::OpShiftRightArithmetic;
} 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->IsSubtract()) {
op = lhs_is_float_or_vec ? spv::Op::OpFSub : spv::Op::OpISub;

View File

@ -135,7 +135,7 @@ INSTANTIATE_TEST_SUITE_P(
BinaryData{ast::BinaryOp::kOr, "OpBitwiseOr"},
BinaryData{ast::BinaryOp::kShiftLeft, "OpShiftLeftLogical"},
BinaryData{ast::BinaryOp::kShiftRight,
"OpShiftRightLogical"},
"OpShiftRightArithmetic"},
BinaryData{ast::BinaryOp::kSubtract, "OpISub"},
BinaryData{ast::BinaryOp::kXor, "OpBitwiseXor"}));