[P4-design] global instances

Nate Foster jnfoster at cs.cornell.edu
Tue May 9 03:20:59 EDT 2017

Dear P4 Designers,

I take my job as a professor seriously including, too often, being quite
absent minded. Issues #150 (https://github.com/p4lang/p4-spec/issues/150)
was supposed to be on the agenda for this afternoon's meeting, but I
somehow neglected to include it. My apologies.

Since this issue was already discussed at a previous language design
working group meeting and we are in the home stretch for finalizing P4_16,
I'd like to propose that we attempt to resolve it by email if possible.

The issue concerns global instances -- i.e., can one declare a variable
outside of the scope of any P4-programmable component as in the following

bit<32> x;
control c1() { ... x = 0; ... }
control c2() { ... x = x + 1; }

Arguments for:

- The abstraction of top-level global variables may be more convenient and
more familiar to programmers.

- In cases where a top-level global variable is used just once, the
compiler can inline those variables anyway.

Arguments against:

- Not all targets will be able to implement programs where a top-level
global variable is accessed by multiple P4-programmable components.

- Arguably it's more in the spirit of P4-16 if all global state resides in
the architecture.

- Being conservative would suggest removing top-level global instances in
the short term, and adding them back if we decide they are useful later.
The opposite is harder to do.

Possible decisions:

(1) Stick with the status quo and allow top-level global state.

(2) Forbid top-level global state.

(3) Allow top-level global state only if it can be inlined.

I could personally live with any of these options. However, I have a
preference for (2) in the short-term since it seems safest.

Please let me know what you think about this issue, either publicly, or
privately if you prefer...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-design_lists.p4.org/attachments/20170509/7947fab0/attachment-0002.html>

More information about the P4-design mailing list