From ec64092b122ab64711bfee4e06fac45cc31f9f1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Capucho?= Date: Fri, 7 Jan 2022 15:46:20 +0000 Subject: [PATCH] spv-in: more sign agnostic binary operations --- src/front/spv/convert.rs | 4 ++++ src/front/spv/mod.rs | 26 +++++++++++--------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/front/spv/convert.rs b/src/front/spv/convert.rs index ce9055152..bdc8a6d24 100644 --- a/src/front/spv/convert.rs +++ b/src/front/spv/convert.rs @@ -13,6 +13,7 @@ pub(super) fn map_binary_operator(word: spirv::Op) -> Result Ok(BinaryOperator::Multiply), Op::UDiv | Op::SDiv | Op::FDiv => Ok(BinaryOperator::Divide), Op::UMod | Op::SMod | Op::FMod => Ok(BinaryOperator::Modulo), + Op::SRem => Ok(BinaryOperator::Modulo), // Relational and Logical Instructions Op::IEqual | Op::FOrdEqual | Op::FUnordEqual | Op::LogicalEqual => { Ok(BinaryOperator::Equal) @@ -34,6 +35,9 @@ pub(super) fn map_binary_operator(word: spirv::Op) -> Result Ok(BinaryOperator::GreaterEqual), + Op::BitwiseOr => Ok(BinaryOperator::InclusiveOr), + Op::BitwiseXor => Ok(BinaryOperator::ExclusiveOr), + Op::BitwiseAnd => Ok(BinaryOperator::And), _ => Err(Error::UnknownBinaryOperator(word)), } } diff --git a/src/front/spv/mod.rs b/src/front/spv/mod.rs index 14705408a..8ca8c0d05 100644 --- a/src/front/spv/mod.rs +++ b/src/front/spv/mod.rs @@ -1891,7 +1891,15 @@ impl> Parser { inst.expect(4)?; parse_expr_op!(crate::UnaryOperator::Negate, UNARY)?; } - Op::IAdd | Op::ISub | Op::IMul => { + Op::IAdd + | Op::ISub + | Op::IMul + | Op::BitwiseOr + | Op::BitwiseXor + | Op::BitwiseAnd + | Op::SDiv + | Op::SMod + | Op::SRem => { inst.expect(5)?; let operator = map_binary_operator(inst.op)?; self.parse_expr_binary_op_sign_adjusted( @@ -1929,11 +1937,11 @@ impl> Parser { inst.expect(5)?; parse_expr_op!(crate::BinaryOperator::Multiply, BINARY)?; } - Op::SDiv | Op::UDiv | Op::FDiv => { + Op::UDiv | Op::FDiv => { inst.expect(5)?; parse_expr_op!(crate::BinaryOperator::Divide, BINARY)?; } - Op::SMod | Op::UMod | Op::FMod | Op::SRem | Op::FRem => { + Op::UMod | Op::FMod | Op::FRem => { inst.expect(5)?; parse_expr_op!(crate::BinaryOperator::Modulo, BINARY)?; } @@ -2170,18 +2178,6 @@ impl> Parser { inst.expect(4)?; parse_expr_op!(crate::UnaryOperator::Not, UNARY)?; } - Op::BitwiseOr => { - inst.expect(5)?; - parse_expr_op!(crate::BinaryOperator::InclusiveOr, BINARY)?; - } - Op::BitwiseXor => { - inst.expect(5)?; - parse_expr_op!(crate::BinaryOperator::ExclusiveOr, BINARY)?; - } - Op::BitwiseAnd => { - inst.expect(5)?; - parse_expr_op!(crate::BinaryOperator::And, BINARY)?; - } Op::ShiftRightLogical => { inst.expect(5)?; //TODO: convert input and result to usigned