diff --git a/p4-16/spec/P4-16-spec.mdk b/p4-16/spec/P4-16-spec.mdk index 61c1e8088d..a4fa9a323f 100644 --- a/p4-16/spec/P4-16-spec.mdk +++ b/p4-16/spec/P4-16-spec.mdk @@ -2982,6 +2982,10 @@ Variable-length bit-strings support a limited set of operations: - The `emit` method of a `packet_out` extern object, which inserts a variable-sized bit-string with a known dynamic width into the packet being constructed (see Section [#sec-deparse]). +- Comparison for equality or inequality with another `varbit` field. + Two `varbit` fields can be compared only if they have the same type. + Two varbits are equal if they have the same dynamic width and all + the bits up to the dynamic width are the same. ## Casts { #sec-casts } @@ -3281,6 +3285,11 @@ copying `struct`s using assignment when the source and target of the assignment have the same type. Finally, `struct`s can be initialized with a list expression, as discussed in Section [#sec-list-exprs]. +Two structs can be compared for equality (==) or inequality (!=) only +if they have the same type and all of their fields can be recursively +compared for equality. Two structures are equal if and only if all +their corresponding fields are equal. + ## Operations on headers { #sec-ops-on-hdrs } Headers provide the same operations as `struct`s. Assignment between @@ -3352,6 +3361,11 @@ H h; h = { 10, 12 }; // This also makes the header h valid ~ End P4Example +Two headers can be compared for equality (==) or inequality (!=) only +if they have the same type. Two headers are equal if and only if they +are both invalid, or they are both valid and all their corresponding +fields are equal. + ## Operations on header stacks { #sec-expr-hs } A header stack is a fixed-size array of headers with the same @@ -3471,6 +3485,11 @@ void pop_front(int count) { } ~ End P4Pseudo +Two header stacks can be compared for equality (==) or inequality (!=) +only if they have the same element type and the same length. Two +stacks are equal if and only if all their corresponding elements are +equal. Note that the `nextIndex` value is not used in the equality comparison. + ## Operations on header unions { #sec-expr-hu } A variable declared with a union type is initially invalid. For example: @@ -3673,6 +3692,12 @@ parser Tcp_option_parser(packet_in b, out Tcp_option_stack vec) { } ~End P4Example +Two header unions can be compared for equality (==) or inequality (!=) +if they have the same type. The unions are equal if and only if all +their corresponding fields are equal (i.e., either all fields are +invalid in both unions, or in both unions the same field is valid, and +the values of the valid fields are equal as headers). + ## Method invocations and function calls { #sec-functions } Method invocations and function calls can be invoked using standard