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

dialects: (builtin) add support for IntegerType packing with arbitrary bitwidth up to 64 #3728

Merged
merged 6 commits into from
Jan 9, 2025

Conversation

jorendumoulin
Copy link
Collaborator

No description provided.

@jorendumoulin jorendumoulin self-assigned this Jan 8, 2025
@jorendumoulin jorendumoulin added the dialects Changes on the dialects label Jan 8, 2025
@alexarice
Copy link
Collaborator

While the bug I hit was with i2, I'm unsure why we can't support at least all IntegerTypes up to 64?

Copy link

codecov bot commented Jan 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.28%. Comparing base (0d39a26) to head (38ca057).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3728   +/-   ##
=======================================
  Coverage   91.28%   91.28%           
=======================================
  Files         468      468           
  Lines       58601    58611   +10     
  Branches     5656     5656           
=======================================
+ Hits        53492    53502   +10     
  Misses       3659     3659           
  Partials     1450     1450           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alexarice
Copy link
Collaborator

Can we not just store each integer in bitwidth // 8 bytes?

@jorendumoulin
Copy link
Collaborator Author

yes, I think that makes sense. for larger than 64 bits we would need something else than struct.pack however

@jorendumoulin jorendumoulin changed the title dialects: (builtin) add support for i2 dialects: (builtin) add support for IntegerType packing with arbitrary bitwidth up to 64 Jan 8, 2025
@jorendumoulin
Copy link
Collaborator Author

Can we not just store each integer in bitwidth // 8 bytes?

it should be ceil(bitwidth/8) though

Copy link
Collaborator

@alexarice alexarice left a comment

Choose a reason for hiding this comment

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

Great, thanks for the quick fix. What's the reason for using struct.pack to store these instead of a tuple of ints? Is this more space efficient? The documentation for struct seems to suggest it's mainly for C interop.

@alexarice
Copy link
Collaborator

Great, thanks for the quick fix. What's the reason for using struct.pack to store these instead of a tuple of ints? Is this more space efficient? The documentation for struct seems to suggest it's mainly for C interop.

To answer my own question, apparently python ints are at least 28 bytes

@@ -532,14 +532,14 @@ def print_value_without_type(self, value: int, printer: Printer):

@property
def format(self) -> str:
match self.bitwidth:
case 1 | 8:
match -(self.bitwidth // -8): # ceildiv
Copy link
Member

@superlopuh superlopuh Jan 8, 2025

Choose a reason for hiding this comment

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

?

Suggested change
match -(self.bitwidth // -8): # ceildiv
match (self.bitwidth - 1) >> 3:

Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't correct

Copy link
Collaborator

Choose a reason for hiding this comment

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

(7 + self.bitwidth) >> 3 works I think

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(self.bitwidth + 7) >> 3 is also used on L389 to compute the byte size of a FixedBitWidthType, so i think that one makes sense

@jorendumoulin jorendumoulin merged commit fcc7520 into main Jan 9, 2025
16 checks passed
@jorendumoulin jorendumoulin deleted the joren/support-i2 branch January 9, 2025 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialects Changes on the dialects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants