You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: p4-16/spec/P4-16-spec.adoc
+14-17Lines changed: 14 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3615,10 +3615,20 @@ Bit-strings also support the following operations:
3615
3615
`+0 <= L <= H < W+` are checked statically (where `W` is
3616
3616
the length of the source bit-string). Note that both endpoints of
3617
3617
the extraction are inclusive. The bounds are required to be
3618
-
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`.
3618
+
local compile-time known values so that the width of the result can be computed
3619
+
at compile time. Slices are also l-values, which means that P4 supports
3620
+
assigning to a slice: `e[H:L] = x`.
3619
3621
The effect of this statement is to set bits `H` through `L` (inclusive of
3620
3622
both) of `e` to the bit-pattern represented by `x`, and leaves all other bits
3621
-
of `e` unchanged. A slice of an unsigned integer is an unsigned integer.
3623
+
of `e` unchanged. A slice is always an unsigned integer.
3624
+
A slice may also be specified as `[L+:W]` where `L` is the lowest bit of the slice
3625
+
and `W` is the width of the slice. In this case, only `W` must be a non-negative
3626
+
local compile-time known numeric value. `L` must also be a numeric value and
3627
+
some architectures may require it to be compile-time known. It must also be
3628
+
non-negative and in-range for the type. Some architectures may allow variable indexing,
3629
+
in which case an out of range value will be equivalent to a shift of that amount.
3630
+
An index that is not compile-time known must be a `bit<W>` type in order to ensure that
3631
+
it is non-negative.
3622
3632
* Concatenation of bit-strings and/or fixed-width signed integers, denoted by `++`.
3623
3633
The two operands must be either `bit<W>` or `int<W>`, and they can be of
3624
3634
different signedness and width. The result has the same signedness as the
@@ -3695,21 +3705,8 @@ The `int<W>` datatype also support the following operations:
3695
3705
** all result bits are zero when shifting a non-negative value right
3696
3706
** all result bits are one when shifting a negative value right
3697
3707
* Extraction of a set of contiguous bits, also known as a slice,
3698
-
denoted by `[H:L]`, where `H` and `L` must be expressions that evaluate to
3699
-
non-negative, local compile-time known values, and `H >= L` must be true.
3700
-
The types of `H` and `L` (which do not need to be identical)
3701
-
must be numeric (<<sec-numeric-values>>).
3702
-
The result is an unsigned bit-string of width `H - L + 1`, including the bits
3703
-
numbered from `L` (which becomes the least significant bit of the result)
3704
-
to `H` (the most significant bit of the result) from the source operand.
3705
-
The conditions `+0 <= L <= H < W+` are checked statically (where `W` is
3706
-
the length of the source bit-string). Note that both endpoints of
3707
-
the extraction are inclusive. The bounds are required to be values
3708
-
that are known at compile time so that the width of the result can be
3709
-
computed at compile time. Slices are also l-values, which means that P4
3710
-
supports assigning to a slice: `e[H:L] = x`.
3711
-
The effect of this statement is to set bits `H` through `L` of `e` to the
3712
-
bit-pattern represented by `x`, and leaves all other bits of `e` unchanged.
3708
+
denoted by `[H:L]` or `[L+:W]`, with the same semantics as slices of
3709
+
bit strings.
3713
3710
A slice of a signed integer is treated as an unsigned integer.
3714
3711
* Concatenation of bit-strings and/or fixed-width signed integers, denoted by `++`.
3715
3712
The two operands must be either `bit<W>` or `int<W>`, and they can be of different signedness and width.
0 commit comments