[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>
diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc
index 6dddf29..8b749e9 100644
--- a/src/reader/spirv/function.cc
+++ b/src/reader/spirv/function.cc
@@ -48,6 +48,12 @@
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:
diff --git a/src/reader/spirv/function_arithmetic_test.cc b/src/reader/spirv/function_arithmetic_test.cc
index 1643aa2..6741916 100644
--- a/src/reader/spirv/function_arithmetic_test.cc
+++ b/src/reader/spirv/function_arithmetic_test.cc
@@ -239,6 +239,117 @@
"__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