[spirv-reader] Add shift operators

Bug: tint:3
Change-Id: I96ba69d35b072712f8c912fd258bca1f32ab5482
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19560
Reviewed-by: dan sinclair <dsinclair@google.com>
This commit is contained in:
David Neto 2020-04-14 21:02:17 +00:00
parent 11d9ac1ee1
commit 641208c2b1
2 changed files with 117 additions and 0 deletions

View File

@ -48,6 +48,12 @@ ast::BinaryOp ConvertBinaryOp(SpvOp opcode) {
return ast::BinaryOp::kMultiply;
case SpvOpFDiv:
return ast::BinaryOp::kDivide;
case SpvOpShiftLeftLogical:
return ast::BinaryOp::kShiftLeft;
case SpvOpShiftRightLogical:
return ast::BinaryOp::kShiftRight;
case SpvOpShiftRightArithmetic:
return ast::BinaryOp::kShiftRightArith;
case SpvOpIEqual:
return ast::BinaryOp::kEqual;
case SpvOpINotEqual:

View File

@ -239,6 +239,117 @@ INSTANTIATE_TEST_SUITE_P(
"__vec_2__f32", AstFor("v2float_50_60"), "divide",
AstFor("v2float_60_50")}));
INSTANTIATE_TEST_SUITE_P(
SpvParserTest_ShiftLeftLogical,
SpvBinaryTest,
::testing::Values(
// Both uint
BinaryData{"uint", "uint_10", "OpShiftLeftLogical", "uint_20", "__u32",
"ScalarConstructor{10}", "shift_left",
"ScalarConstructor{20}"},
// Both int
BinaryData{"int", "int_30", "OpShiftLeftLogical", "int_40", "__i32",
"ScalarConstructor{30}", "shift_left",
"ScalarConstructor{40}"},
// Mixed, returning uint
BinaryData{"uint", "int_30", "OpShiftLeftLogical", "uint_10", "__u32",
"ScalarConstructor{30}", "shift_left",
"ScalarConstructor{10}"},
// Mixed, returning int
BinaryData{"int", "int_30", "OpShiftLeftLogical", "uint_10", "__i32",
"ScalarConstructor{30}", "shift_left",
"ScalarConstructor{10}"},
// Both v2uint
BinaryData{"v2uint", "v2uint_10_20", "OpShiftLeftLogical",
"v2uint_20_10", "__vec_2__u32", AstFor("v2uint_10_20"),
"shift_left", AstFor("v2uint_20_10")},
// Both v2int
BinaryData{"v2int", "v2int_30_40", "OpShiftLeftLogical", "v2int_40_30",
"__vec_2__i32", AstFor("v2int_30_40"), "shift_left",
AstFor("v2int_40_30")},
// Mixed, returning v2uint
BinaryData{"v2uint", "v2int_30_40", "OpShiftLeftLogical",
"v2uint_10_20", "__vec_2__u32", AstFor("v2int_30_40"),
"shift_left", AstFor("v2uint_10_20")},
// Mixed, returning v2int
BinaryData{"v2int", "v2int_40_30", "OpShiftLeftLogical", "v2uint_20_10",
"__vec_2__i32", AstFor("v2int_40_30"), "shift_left",
AstFor("v2uint_20_10")}));
INSTANTIATE_TEST_SUITE_P(
SpvParserTest_ShiftRightLogical,
SpvBinaryTest,
::testing::Values(
// Both uint
BinaryData{"uint", "uint_10", "OpShiftRightLogical", "uint_20", "__u32",
"ScalarConstructor{10}", "shift_right",
"ScalarConstructor{20}"},
// Both int
BinaryData{"int", "int_30", "OpShiftRightLogical", "int_40", "__i32",
"ScalarConstructor{30}", "shift_right",
"ScalarConstructor{40}"},
// Mixed, returning uint
BinaryData{"uint", "int_30", "OpShiftRightLogical", "uint_10", "__u32",
"ScalarConstructor{30}", "shift_right",
"ScalarConstructor{10}"},
// Mixed, returning int
BinaryData{"int", "int_30", "OpShiftRightLogical", "uint_10", "__i32",
"ScalarConstructor{30}", "shift_right",
"ScalarConstructor{10}"},
// Both v2uint
BinaryData{"v2uint", "v2uint_10_20", "OpShiftRightLogical",
"v2uint_20_10", "__vec_2__u32", AstFor("v2uint_10_20"),
"shift_right", AstFor("v2uint_20_10")},
// Both v2int
BinaryData{"v2int", "v2int_30_40", "OpShiftRightLogical", "v2int_40_30",
"__vec_2__i32", AstFor("v2int_30_40"), "shift_right",
AstFor("v2int_40_30")},
// Mixed, returning v2uint
BinaryData{"v2uint", "v2int_30_40", "OpShiftRightLogical",
"v2uint_10_20", "__vec_2__u32", AstFor("v2int_30_40"),
"shift_right", AstFor("v2uint_10_20")},
// Mixed, returning v2int
BinaryData{"v2int", "v2int_40_30", "OpShiftRightLogical",
"v2uint_20_10", "__vec_2__i32", AstFor("v2int_40_30"),
"shift_right", AstFor("v2uint_20_10")}));
INSTANTIATE_TEST_SUITE_P(
SpvParserTest_ShiftRightArithmetic,
SpvBinaryTest,
::testing::Values(
// Both uint
BinaryData{"uint", "uint_10", "OpShiftRightArithmetic", "uint_20",
"__u32", "ScalarConstructor{10}", "shift_right_arith",
"ScalarConstructor{20}"},
// Both int
BinaryData{"int", "int_30", "OpShiftRightArithmetic", "int_40", "__i32",
"ScalarConstructor{30}", "shift_right_arith",
"ScalarConstructor{40}"},
// Mixed, returning uint
BinaryData{"uint", "int_30", "OpShiftRightArithmetic", "uint_10",
"__u32", "ScalarConstructor{30}", "shift_right_arith",
"ScalarConstructor{10}"},
// Mixed, returning int
BinaryData{"int", "int_30", "OpShiftRightArithmetic", "uint_10",
"__i32", "ScalarConstructor{30}", "shift_right_arith",
"ScalarConstructor{10}"},
// Both v2uint
BinaryData{"v2uint", "v2uint_10_20", "OpShiftRightArithmetic",
"v2uint_20_10", "__vec_2__u32", AstFor("v2uint_10_20"),
"shift_right_arith", AstFor("v2uint_20_10")},
// Both v2int
BinaryData{"v2int", "v2int_30_40", "OpShiftRightArithmetic",
"v2int_40_30", "__vec_2__i32", AstFor("v2int_30_40"),
"shift_right_arith", AstFor("v2int_40_30")},
// Mixed, returning v2uint
BinaryData{"v2uint", "v2int_30_40", "OpShiftRightArithmetic",
"v2uint_10_20", "__vec_2__u32", AstFor("v2int_30_40"),
"shift_right_arith", AstFor("v2uint_10_20")},
// Mixed, returning v2int
BinaryData{"v2int", "v2int_40_30", "OpShiftRightArithmetic",
"v2uint_20_10", "__vec_2__i32", AstFor("v2int_40_30"),
"shift_right_arith", AstFor("v2uint_20_10")}));
} // namespace
} // namespace spirv
} // namespace reader