Repository navigation
Allow division and modulo operations on fixed-width bit (unsinged) types - #1414
Conversation
Signed-off-by: jaehyun1ee <99jaehyunlee@kaist.ac.kr>
| 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 `/`. |
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.
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>
|
LGTM, anything else you want to change here @jafingerhut or shall we resolve the conversation and merge this? |
| The denominator must be positive. | ||
| The result has the same width as the operands. Similar to multiplication, | ||
| P4 architectures may impose additional restrictions. | ||
| * Modulo between positive values, denoted by `%`. |
There was a problem hiding this comment.
Allow the numerator to be 0 here.
There was a problem hiding this comment.
Recommendation: Change "the denominator must be positive." with "The denominator must not be 0." The same restriction should exist for the modulo operator (the current language suggests that the numerator cannot be 0, but we should allow that).
There was a problem hiding this comment.
Thanks! Addressed as follows:
* Truncating integer division, denoted by `/`.
The denominator must not be zero.
The result has the same width as the operands. Similar to multiplication,
P4 architectures may impose additional restrictions.
* Modulo, denoted by `%`.
The denominator must not be zero.
The result has the same width as the operands. Similar to multiplication,
P4 architectures may impose additional restrictions.There was a problem hiding this comment.
Ideally allow 0 for numerator both here and in truncating integer division.
There was a problem hiding this comment.
Also addressed here:
- * Truncating integer division between positive values, denoted by `/`.
- * Modulo between positive values, denoted by `%`.
+ * Truncating integer division, denoted by `/`.
+ The numerator must be non-negative and the denominator must be positive.
+ * Modulo, denoted by `%`.
+ The numerator must be non-negative and the denominator must be positive.
jafingerhut
left a comment
There was a problem hiding this comment.
LGTM, subject to Jonathan's final review on small changes discussed in the 2026-Sep-14 LDWG meeting.
… type Signed-off-by: jaehyun1ee <99jaehyunlee@kaist.ac.kr>
|
Thank you for the comments! @jonathan-dilorenzo, can you take a look? |
|
Love it! Thanks @jaehyun1ee and @jafingerhut! |
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.