diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 2acb35aa3c..400415f680 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -581,6 +581,14 @@ uint32_t Builder::GenerateBinaryExpression(ast::BinaryExpression* expr) { op = spv::Op::OpBitwiseAnd; } else if (expr->IsAdd()) { op = lhs_is_float_or_vec ? spv::Op::OpFAdd : spv::Op::OpIAdd; + } else if (expr->IsDivide()) { + if (lhs_is_float_or_vec) { + op = spv::Op::OpFDiv; + } else if (lhs_is_unsigned) { + op = spv::Op::OpUDiv; + } else { + op = spv::Op::OpSDiv; + } } else if (expr->IsEqual()) { op = lhs_is_float_or_vec ? spv::Op::OpFOrdEqual : spv::Op::OpIEqual; } else if (expr->IsGreaterThan()) { diff --git a/src/writer/spirv/builder_binary_expression_test.cc b/src/writer/spirv/builder_binary_expression_test.cc index 3a3c7b3c02..b2c0d38160 100644 --- a/src/writer/spirv/builder_binary_expression_test.cc +++ b/src/writer/spirv/builder_binary_expression_test.cc @@ -122,6 +122,7 @@ INSTANTIATE_TEST_SUITE_P( BinaryArithSignedIntegerTest, testing::Values(BinaryData{ast::BinaryOp::kAdd, "OpIAdd"}, BinaryData{ast::BinaryOp::kAnd, "OpBitwiseAnd"}, + BinaryData{ast::BinaryOp::kDivide, "OpSDiv"}, BinaryData{ast::BinaryOp::kModulo, "OpSMod"}, BinaryData{ast::BinaryOp::kOr, "OpBitwiseOr"}, BinaryData{ast::BinaryOp::kSubtract, "OpISub"}, @@ -204,6 +205,7 @@ INSTANTIATE_TEST_SUITE_P( BinaryArithUnsignedIntegerTest, testing::Values(BinaryData{ast::BinaryOp::kAdd, "OpIAdd"}, BinaryData{ast::BinaryOp::kAnd, "OpBitwiseAnd"}, + BinaryData{ast::BinaryOp::kDivide, "OpUDiv"}, BinaryData{ast::BinaryOp::kModulo, "OpUMod"}, BinaryData{ast::BinaryOp::kOr, "OpBitwiseOr"}, BinaryData{ast::BinaryOp::kSubtract, "OpISub"}, @@ -286,6 +288,7 @@ INSTANTIATE_TEST_SUITE_P( BuilderTest, BinaryArithFloatTest, testing::Values(BinaryData{ast::BinaryOp::kAdd, "OpFAdd"}, + BinaryData{ast::BinaryOp::kDivide, "OpFDiv"}, BinaryData{ast::BinaryOp::kModulo, "OpFMod"}, BinaryData{ast::BinaryOp::kSubtract, "OpFSub"}));