[ir][spirv-writer] Emit binary bitwise operators

Bug: tint:1906
Change-Id: Ica8436cd59aabe521df0445edc5a9f03c45cd1bf
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/134322
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
James Price 2023-05-25 01:29:41 +00:00 committed by Dawn LUCI CQ
parent 59339216a1
commit dd7b314105
2 changed files with 52 additions and 0 deletions

View File

@ -426,6 +426,19 @@ uint32_t GeneratorImplIr::EmitBinary(const ir::Binary* binary) {
break; break;
} }
case ir::Binary::Kind::kAnd: {
op = spv::Op::OpBitwiseAnd;
break;
}
case ir::Binary::Kind::kOr: {
op = spv::Op::OpBitwiseOr;
break;
}
case ir::Binary::Kind::kXor: {
op = spv::Op::OpBitwiseXor;
break;
}
case ir::Binary::Kind::kEqual: { case ir::Binary::Kind::kEqual: {
if (lhs_ty->is_bool_scalar_or_vector()) { if (lhs_ty->is_bool_scalar_or_vector()) {
op = spv::Op::OpLogicalEqual; op = spv::Op::OpLogicalEqual;

View File

@ -308,6 +308,45 @@ OpFunctionEnd
)"); )");
} }
using Bitwise = BinaryInstructionTest;
TEST_P(Bitwise, Scalar) {
auto params = GetParam();
auto* func = b.CreateFunction("foo", mod.Types().void_());
func->StartTarget()->SetInstructions(
utils::Vector{b.CreateBinary(params.kind, MakeScalarType(params.type),
MakeScalarValue(params.type), MakeScalarValue(params.type)),
b.Branch(func->EndTarget())});
generator_.EmitFunction(func);
EXPECT_THAT(DumpModule(generator_.Module()), ::testing::HasSubstr(params.spirv_inst));
}
TEST_P(Bitwise, Vector) {
auto params = GetParam();
auto* func = b.CreateFunction("foo", mod.Types().void_());
func->StartTarget()->SetInstructions(
utils::Vector{b.CreateBinary(params.kind, MakeVectorType(params.type),
MakeVectorValue(params.type), MakeVectorValue(params.type)),
b.Branch(func->EndTarget())});
generator_.EmitFunction(func);
EXPECT_THAT(DumpModule(generator_.Module()), ::testing::HasSubstr(params.spirv_inst));
}
INSTANTIATE_TEST_SUITE_P(
SpvGeneratorImplTest_Binary_I32,
Bitwise,
testing::Values(BinaryTestCase{kI32, ir::Binary::Kind::kAnd, "OpBitwiseAnd"},
BinaryTestCase{kI32, ir::Binary::Kind::kOr, "OpBitwiseOr"},
BinaryTestCase{kI32, ir::Binary::Kind::kXor, "OpBitwiseXor"}));
INSTANTIATE_TEST_SUITE_P(
SpvGeneratorImplTest_Binary_U32,
Bitwise,
testing::Values(BinaryTestCase{kU32, ir::Binary::Kind::kAnd, "OpBitwiseAnd"},
BinaryTestCase{kU32, ir::Binary::Kind::kOr, "OpBitwiseOr"},
BinaryTestCase{kU32, ir::Binary::Kind::kXor, "OpBitwiseXor"}));
using Comparison = BinaryInstructionTest; using Comparison = BinaryInstructionTest;
TEST_P(Comparison, Scalar) { TEST_P(Comparison, Scalar) {
auto params = GetParam(); auto params = GetParam();