[spirv-writer] Add binary greater than equal comparison.
This CL adds generation for the binary greater than or equal comparison.
Bug: tint:5
Change-Id: I5c81b7d142d29f388800d8b576ec69dc260b243e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19407
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc
index 1126dc3..93489a9 100644
--- a/src/writer/spirv/builder.cc
+++ b/src/writer/spirv/builder.cc
@@ -587,6 +587,14 @@
} else {
op = spv::Op::OpSGreaterThan;
}
+ } else if (expr->IsGreaterThanEqual()) {
+ if (lhs_is_float_or_vec) {
+ op = spv::Op::OpFOrdGreaterThanEqual;
+ } else if (lhs_is_unsigned) {
+ op = spv::Op::OpUGreaterThanEqual;
+ } else {
+ op = spv::Op::OpSGreaterThanEqual;
+ }
} else if (expr->IsLessThan()) {
if (lhs_is_float_or_vec) {
op = spv::Op::OpFOrdLessThan;
diff --git a/src/writer/spirv/builder_binary_expression_test.cc b/src/writer/spirv/builder_binary_expression_test.cc
index ae2ef18..9736ce2 100644
--- a/src/writer/spirv/builder_binary_expression_test.cc
+++ b/src/writer/spirv/builder_binary_expression_test.cc
@@ -280,12 +280,13 @@
INSTANTIATE_TEST_SUITE_P(
BuilderTest,
BinaryCompareUnsignedIntegerTest,
- 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"}));
+ testing::Values(
+ BinaryData{ast::BinaryOp::kEqual, "OpIEqual"},
+ BinaryData{ast::BinaryOp::kGreaterThan, "OpUGreaterThan"},
+ BinaryData{ast::BinaryOp::kGreaterThanEqual, "OpUGreaterThanEqual"},
+ BinaryData{ast::BinaryOp::kLessThan, "OpULessThan"},
+ BinaryData{ast::BinaryOp::kLessThanEqual, "OpULessThanEqual"},
+ BinaryData{ast::BinaryOp::kNotEqual, "OpINotEqual"}));
using BinaryCompareSignedIntegerTest = testing::TestWithParam<BinaryData>;
TEST_P(BinaryCompareSignedIntegerTest, Scalar) {
@@ -366,12 +367,13 @@
INSTANTIATE_TEST_SUITE_P(
BuilderTest,
BinaryCompareSignedIntegerTest,
- 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"}));
+ testing::Values(
+ BinaryData{ast::BinaryOp::kEqual, "OpIEqual"},
+ BinaryData{ast::BinaryOp::kGreaterThan, "OpSGreaterThan"},
+ BinaryData{ast::BinaryOp::kGreaterThanEqual, "OpSGreaterThanEqual"},
+ BinaryData{ast::BinaryOp::kLessThan, "OpSLessThan"},
+ BinaryData{ast::BinaryOp::kLessThanEqual, "OpSLessThanEqual"},
+ BinaryData{ast::BinaryOp::kNotEqual, "OpINotEqual"}));
using BinaryCompareFloatTest = testing::TestWithParam<BinaryData>;
TEST_P(BinaryCompareFloatTest, Scalar) {
@@ -455,6 +457,7 @@
testing::Values(
BinaryData{ast::BinaryOp::kEqual, "OpFOrdEqual"},
BinaryData{ast::BinaryOp::kGreaterThan, "OpFOrdGreaterThan"},
+ BinaryData{ast::BinaryOp::kGreaterThanEqual, "OpFOrdGreaterThanEqual"},
BinaryData{ast::BinaryOp::kLessThan, "OpFOrdLessThan"},
BinaryData{ast::BinaryOp::kLessThanEqual, "OpFOrdLessThanEqual"},
BinaryData{ast::BinaryOp::kNotEqual, "OpFOrdNotEqual"}));