[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:
parent
59339216a1
commit
dd7b314105
|
@ -426,6 +426,19 @@ uint32_t GeneratorImplIr::EmitBinary(const ir::Binary* binary) {
|
|||
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: {
|
||||
if (lhs_ty->is_bool_scalar_or_vector()) {
|
||||
op = spv::Op::OpLogicalEqual;
|
||||
|
|
|
@ -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;
|
||||
TEST_P(Comparison, Scalar) {
|
||||
auto params = GetParam();
|
||||
|
|
Loading…
Reference in New Issue