[spirv-writer] Add divide generation.

This CL adds generation for the OpFDiv, OpSDiv and OpUDiv SPIR-V
instructions.

Bug: tint:5
Change-Id: I9fd875f453dd71857b192a2dad56149bae52caf5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19507
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-04-14 20:32:20 +00:00 committed by dan sinclair
parent e7c23721b9
commit 87a3f86155
2 changed files with 11 additions and 0 deletions

View File

@ -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()) {

View File

@ -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"}));