From ac3213b4addd55df34965121cab5f7d9aa1d5f2d Mon Sep 17 00:00:00 2001 From: David Neto Date: Wed, 15 Apr 2020 14:02:37 +0000 Subject: [PATCH] [spirv-reader] Add UMod, SMod, FMod Bug: tint:3 Change-Id: Idd0e5bbc51e05782d3f918e4ffeb83eab52d87d2 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19565 Reviewed-by: dan sinclair --- src/reader/spirv/function.cc | 4 +++ src/reader/spirv/function_arithmetic_test.cc | 37 ++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index 6860e15aad..2d520cb62b 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -52,6 +52,10 @@ ast::BinaryOp ConvertBinaryOp(SpvOp opcode) { case SpvOpSDiv: case SpvOpFDiv: return ast::BinaryOp::kDivide; + case SpvOpUMod: + case SpvOpSMod: + case SpvOpFMod: + return ast::BinaryOp::kModulo; case SpvOpShiftLeftLogical: return ast::BinaryOp::kShiftLeft; case SpvOpShiftRightLogical: diff --git a/src/reader/spirv/function_arithmetic_test.cc b/src/reader/spirv/function_arithmetic_test.cc index 7f1e62c797..b2945af5ab 100644 --- a/src/reader/spirv/function_arithmetic_test.cc +++ b/src/reader/spirv/function_arithmetic_test.cc @@ -337,6 +337,43 @@ INSTANTIATE_TEST_SUITE_P( "__vec_2__f32", AstFor("v2float_50_60"), "divide", AstFor("v2float_60_50")})); +INSTANTIATE_TEST_SUITE_P( + SpvParserTest_UMod, + SpvBinaryTest, + ::testing::Values( + // Both uint + BinaryData{"uint", "uint_10", "OpUMod", "uint_20", "__u32", + "ScalarConstructor{10}", "modulo", "ScalarConstructor{20}"}, + // Both v2uint + BinaryData{"v2uint", "v2uint_10_20", "OpUMod", "v2uint_20_10", + "__vec_2__u32", AstFor("v2uint_10_20"), "modulo", + AstFor("v2uint_20_10")})); + +INSTANTIATE_TEST_SUITE_P( + SpvParserTest_SMod, + SpvBinaryTest, + ::testing::Values( + // Both int + BinaryData{"int", "int_30", "OpSMod", "int_40", "__i32", + "ScalarConstructor{30}", "modulo", "ScalarConstructor{40}"}, + // Both v2int + BinaryData{"v2int", "v2int_30_40", "OpSMod", "v2int_40_30", + "__vec_2__i32", AstFor("v2int_30_40"), "modulo", + AstFor("v2int_40_30")})); + +INSTANTIATE_TEST_SUITE_P( + SpvParserTest_FMod, + SpvBinaryTest, + ::testing::Values( + // Scalar float + BinaryData{"float", "float_50", "OpFMod", "float_60", "__f32", + "ScalarConstructor{50.000000}", "modulo", + "ScalarConstructor{60.000000}"}, + // Vector float + BinaryData{"v2float", "v2float_50_60", "OpFMod", "v2float_60_50", + "__vec_2__f32", AstFor("v2float_50_60"), "modulo", + AstFor("v2float_60_50")})); + INSTANTIATE_TEST_SUITE_P( SpvParserTest_ShiftLeftLogical, SpvBinaryTest,