Allow division and modulo operations on fixed-width bit (unsinged) types - #1414
Open
jaehyun1ee wants to merge 3 commits into
Open
Allow division and modulo operations on fixed-width bit (unsinged) types#1414jaehyun1ee wants to merge 3 commits into
jaehyun1ee wants to merge 3 commits into
Conversation
Signed-off-by: jaehyun1ee <99jaehyunlee@kaist.ac.kr>
jafingerhut
requested changes
May 29, 2026
| and is computed by truncating the result to the output's width. | ||
| P4 architectures may impose additional restrictions --- e.g., they may only | ||
| allow multiplication by a non-negative integer power of two. | ||
| * Truncating integer division between positive values, denoted by `/`. |
Collaborator
There was a problem hiding this comment.
The numerator for division or modulo should be allowed to be 0, not only positive, yes? I agree it is reasonable to require the denominator to be positive, and not attempt to define the result of such an operation with a denominator of 0.
Contributor
Author
There was a problem hiding this comment.
Thank you for the suggestion, I made the following edit:
* Truncating integer division, denoted by `/`.
The denominator must be positive.
Signed-off-by: jaehyun1ee <99jaehyunlee@kaist.ac.kr>
Signed-off-by: jaehyun1ee <99jaehyunlee@kaist.ac.kr>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a follow-up PR from #1327.
The current specification only allows division and modulo for arbitrary-precision integer types (
int), but not forbit<W>orint<S>types. Yet, there were uses of division and modulo onbit<W>andint<S>types in p4c tests (where p4c allows such, under certain p4c-specific restrictions).This was first discussed in Nov-2025 LDWG meeting, where @jonathan-dilorenzo summarized as:
However, no follow-up PR was made, thus this has gone through another round of discussion in May-2026 LDWG meeting. The consensus is the same: allow division and modulo for
bit<W>types, yet disallow forint<S>types since there is no clear consensus on how division and modulo should be defined regarding signedness and rounding.This PR adds division and modulo to 8.7. Operations on fixed-width bit types (unsigned integers), also mentioning that P4 architectures may restrict division and modulo.