[spirv-writer] Add binary less than equal.

This CL adds generation for the less than equal binary operator.

Bug: tint:5
Change-Id: Ic9d0eb107079c29b2ca1b0eb088e3b2eb7531e1e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19406
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
dan sinclair 2020-04-14 15:03:47 +00:00 committed by dan sinclair
parent 6b9587b697
commit d7e2add6f3
2 changed files with 18 additions and 5 deletions

View File

@ -595,6 +595,14 @@ uint32_t Builder::GenerateBinaryExpression(ast::BinaryExpression* expr) {
} else {
op = spv::Op::OpSLessThan;
}
} else if (expr->IsLessThanEqual()) {
if (lhs_is_float_or_vec) {
op = spv::Op::OpFOrdLessThanEqual;
} else if (lhs_is_unsigned) {
op = spv::Op::OpULessThanEqual;
} else {
op = spv::Op::OpSLessThanEqual;
}
} else if (expr->IsNotEqual()) {
op = lhs_is_float_or_vec ? spv::Op::OpFOrdNotEqual : spv::Op::OpINotEqual;
} else {

View File

@ -283,6 +283,8 @@ INSTANTIATE_TEST_SUITE_P(
testing::Values(BinaryData{ast::BinaryOp::kEqual, "OpIEqual"},
BinaryData{ast::BinaryOp::kGreaterThan, "OpUGreaterThan"},
BinaryData{ast::BinaryOp::kLessThan, "OpULessThan"},
BinaryData{ast::BinaryOp::kLessThanEqual,
"OpULessThanEqual"},
BinaryData{ast::BinaryOp::kNotEqual, "OpINotEqual"}));
using BinaryCompareSignedIntegerTest = testing::TestWithParam<BinaryData>;
@ -367,6 +369,8 @@ INSTANTIATE_TEST_SUITE_P(
testing::Values(BinaryData{ast::BinaryOp::kEqual, "OpIEqual"},
BinaryData{ast::BinaryOp::kGreaterThan, "OpSGreaterThan"},
BinaryData{ast::BinaryOp::kLessThan, "OpSLessThan"},
BinaryData{ast::BinaryOp::kLessThanEqual,
"OpSLessThanEqual"},
BinaryData{ast::BinaryOp::kNotEqual, "OpINotEqual"}));
using BinaryCompareFloatTest = testing::TestWithParam<BinaryData>;
@ -448,11 +452,12 @@ TEST_P(BinaryCompareFloatTest, Vector) {
INSTANTIATE_TEST_SUITE_P(
BuilderTest,
BinaryCompareFloatTest,
testing::Values(BinaryData{ast::BinaryOp::kEqual, "OpFOrdEqual"},
BinaryData{ast::BinaryOp::kGreaterThan,
"OpFOrdGreaterThan"},
BinaryData{ast::BinaryOp::kLessThan, "OpFOrdLessThan"},
BinaryData{ast::BinaryOp::kNotEqual, "OpFOrdNotEqual"}));
testing::Values(
BinaryData{ast::BinaryOp::kEqual, "OpFOrdEqual"},
BinaryData{ast::BinaryOp::kGreaterThan, "OpFOrdGreaterThan"},
BinaryData{ast::BinaryOp::kLessThan, "OpFOrdLessThan"},
BinaryData{ast::BinaryOp::kLessThanEqual, "OpFOrdLessThanEqual"},
BinaryData{ast::BinaryOp::kNotEqual, "OpFOrdNotEqual"}));
} // namespace
} // namespace spirv