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 +: slices #1316

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions p4-16/spec/P4-16-spec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3577,10 +3577,18 @@ Bit-strings also support the following operations:
`+0 <= L <= H < W+` are checked statically (where `W` is
the length of the source bit-string). Note that both endpoints of
the extraction are inclusive. The bounds are required to be
local compile-time known values so that the width of the result can be computed at compile time. Slices are also l-values, which means that P4 supports assigning to a slice: `e[H:L] = x`.
local compile-time known values so that the width of the result can be computed
at compile time. Slices are also l-values, which means that P4 supports
assigning to a slice: `e[H:L] = x`.
The effect of this statement is to set bits `H` through `L` (inclusive of
both) of `e` to the bit-pattern represented by `x`, and leaves all other bits
of `e` unchanged. A slice of an unsigned integer is an unsigned integer.
of `e` unchanged. A slice is always an unsigned integer.
A slice may also be specified as `[L+:W]` where `L` is the lowest bit of the slice
and `W` is the width of the slice. In this case, only `W` must be a non-negative
local compile-time known numeric value. `L` must also be a numeric value and
some architectures may require it to be compile-time known. It must also be
non-negative and in-range for the type. Some architectures may allow variable indexing,
in which case an out of range value will be equivalent to a shift of that amount.
* Concatenation of bit-strings and/or fixed-width signed integers, denoted by `++`.
The two operands must be either `bit<W>` or `int<W>`, and they can be of
different signedness and width. The result has the same signedness as the
Expand Down Expand Up @@ -3657,21 +3665,8 @@ The `int<W>` datatype also support the following operations:
** all result bits are zero when shifting a non-negative value right
** all result bits are one when shifting a negative value right
* Extraction of a set of contiguous bits, also known as a slice,
denoted by `[H:L]`, where `H` and `L` must be expressions that evaluate to
non-negative, local compile-time known values, and `H >= L` must be true.
The types of `H` and `L` (which do not need to be identical)
must be numeric (<<sec-numeric-values>>).
The result is an unsigned bit-string of width `H - L + 1`, including the bits
numbered from `L` (which becomes the least significant bit of the result)
to `H` (the most significant bit of the result) from the source operand.
The conditions `+0 <= L <= H < W+` are checked statically (where `W` is
the length of the source bit-string). Note that both endpoints of
the extraction are inclusive. The bounds are required to be values
that are known at compile time so that the width of the result can be
computed at compile time. Slices are also l-values, which means that P4
supports assigning to a slice: `e[H:L] = x`.
The effect of this statement is to set bits `H` through `L` of `e` to the
bit-pattern represented by `x`, and leaves all other bits of `e` unchanged.
denoted by `[H:L]` or `[L+:W]`, with the same semantics as slices of
bit strings.
A slice of a signed integer is treated as an unsigned integer.
* Concatenation of bit-strings and/or fixed-width signed integers, denoted by `++`.
The two operands must be either `bit<W>` or `int<W>`, and they can be of different signedness and width.
Expand Down
3 changes: 3 additions & 0 deletions p4-16/spec/grammar.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@ lvalue
| lvalue "." member
| lvalue "[" expression "]"
| lvalue "[" expression ":" expression "]"
| lvalue "[" expression "+" ":" expression "]"
| "(" lvalue ")"
;
// end::lvalue[]
Expand Down Expand Up @@ -1114,6 +1115,7 @@ expression
| prefixedNonTypeName
| expression "[" expression "]"
| expression "[" expression ":" expression "]"
| expression "[" expression "+" ":" expression "]"
| "{" expressionList optTrailingComma "}"
| "{#}"
| "{" kvList optTrailingComma "}"
Expand Down Expand Up @@ -1164,6 +1166,7 @@ nonBraceExpression
| prefixedNonTypeName
| nonBraceExpression "[" expression "]"
| nonBraceExpression "[" expression ":" expression "]"
| nonBraceExpression "[" expression "+" ":" expression "]"
| "(" expression ")"
| "!" expression %prec PREFIX
| "~" expression %prec PREFIX
Expand Down