From 6b9587b697184d09ec027cceaed76cb545cef5ff Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Tue, 14 Apr 2020 15:03:39 +0000 Subject: [PATCH] [spirv-writer] Add binary greater than comparison. This CL adds the binary greater then comparison output. Bug: tint:5 Change-Id: I86fa90b3d98f3ee81174edafb188c445b94f9d29 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19405 Reviewed-by: Ryan Harrison --- src/writer/spirv/builder.cc | 8 ++++++++ src/writer/spirv/builder_binary_expression_test.cc | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index e50aab81cc..c06cba4829 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -579,6 +579,14 @@ uint32_t Builder::GenerateBinaryExpression(ast::BinaryExpression* expr) { op = lhs_is_float_or_vec ? spv::Op::OpFAdd : spv::Op::OpIAdd; } else if (expr->IsEqual()) { op = lhs_is_float_or_vec ? spv::Op::OpFOrdEqual : spv::Op::OpIEqual; + } else if (expr->IsGreaterThan()) { + if (lhs_is_float_or_vec) { + op = spv::Op::OpFOrdGreaterThan; + } else if (lhs_is_unsigned) { + op = spv::Op::OpUGreaterThan; + } else { + op = spv::Op::OpSGreaterThan; + } } 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 95589053b9..e344776b56 100644 --- a/src/writer/spirv/builder_binary_expression_test.cc +++ b/src/writer/spirv/builder_binary_expression_test.cc @@ -281,6 +281,7 @@ 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::kNotEqual, "OpINotEqual"})); @@ -364,6 +365,7 @@ 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::kNotEqual, "OpINotEqual"})); @@ -447,6 +449,8 @@ 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"}));