[P4-design] Deparse emit of Header Union

Andy Fingerhut (jafinger) jafinger at cisco.com
Fri Aug 4 11:37:13 EDT 2017

Yes, emit(h) is defined in the spec, a few lines above the pseudocode lines you quote, to be a no-op if it is called with a header where h.isValid() is false.  The relevant pseudocode contains the line “if(data.valid$) {“, where “.valid$” is intended to represent the hidden valid bit of a header.

With this knowledge, the spec does correctly define the desired behavior.  There could certainly be more efficient ways in an implementation to do emit() on a header_union, e.g. an implementation could have a ‘tag field’ that indicates exactly which header_union member is valid, if any, and you could have a case statement that only emits the one valid member.  The spec in this case is not trying to give guidance on how to do it efficiently, just what the resulting visible behavior ought to be.

Andy Fingerhut

From: P4-design <p4-design-bounces at lists.p4.org> on behalf of "Andy Keep (akeep)" <akeep at cisco.com>
Date: Friday, August 4, 2017 at 6:58 AM
To: "p4-design at lists.p4.org" <p4-design at lists.p4.org>, David George <david.george at netronome.com>
Subject: Re: [P4-design] Deparse emit of Header Union

Hey David,

It might be a little unclear, but I think the document is correct.  What the code there does, is look for each field within the header union (which are the individual headers in the union) and then recursively call emit on them, where the validity bit will be checked on the individual header.  Since the header union ensures that no more than one header in the union can ever be valid, it will emit the data for only the valid header (if there is one).


On August 4, 2017 at 9:30:53 AM, David George (david.george at netronome.com<mailto:david.george at netronome.com>) wrote:
Am I correct in saying that emitting a header_union will result in all fields of all member to be written out whether valid or not? I believe this is what the spec implies:

>> else if (isHeaderUnion(T) || isStruct(T))
>>      for (f : data.fields$)
>>            emit(e.f)
I believe the sensible behaviour should be to emit only the valid one.
David George
P4-design mailing list
P4-design at lists.p4.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-design_lists.p4.org/attachments/20170804/d7c82932/attachment-0002.html>

More information about the P4-design mailing list