Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add arithmetic shift operation #68

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tagolog
Copy link
Collaborator

@tagolog tagolog commented Feb 14, 2025

Signed-off-by: Vladimir Shiryaev w@tagolog.com

Signed-off-by: Vladimir Shiryaev <w@tagolog.com>
@asl asl force-pushed the mlir-shift-operation branch from 8d6ea7c to b4c67f5 Compare February 20, 2025 06:45
Copy link
Collaborator

@asl asl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

"equal the width of the left-hand side operand";
}

if (::mlir::isa<P4HIR::BitsType>(rhsType)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified to:

if (auto rhsBits = mlir::dyn_cast<P4HIR::BitsType>(rhsType)) {
  if (rhsBits.isSigned())
           return op->emitOpError()
                   << "the right-hand side operand of an arithmetic shift must be unsigned";
}

Same in other places

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -598,6 +604,16 @@ mlir::Value P4HIRConverter::emitConcatOp(const P4::IR::Concat *concatop) {
getValue(concatop->right));
}

mlir::Value P4HIRConverter::emitShlOp(const P4::IR::Shl *op) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think we need separate methods for this (at least here, in translator), just emit shift ops in postorder directly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

"constant; width of left operand of shift needs to be specified or both "
"operands need to be constant";

if (!::mlir::isa<P4HIR::InfIntType>(resultType))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can start with the check that resultType equals to lhsType. This is a common invariant, so it could be hoisted out of conditions.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above. I think TypesMatchWith trait will make this check obsolete

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

let results = (outs AnyIntP4Type:$result);
let arguments = (ins AnyIntP4Type:$lhs, AnyIntP4Type:$rhs);

// Custom builder to infer the result type with the proper width
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the comment was just copied from concat and does not make sense here. Also, I think you can use TypesMatchWith to match result type with lhs type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Vladimir Shiryaev added 3 commits February 20, 2025 22:50
… result type.

Signed-off-by: Vladimir Shiryaev <w@tagolog.com>
… pull request.

Signed-off-by: Vladimir Shiryaev <w@tagolog.com>
… pull request. Get rid of separate emitSh(l/r)Op functions.

Signed-off-by: Vladimir Shiryaev <w@tagolog.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants