[P4-dev] Difference between "simple" control blocks and functions?

Mihai Budiu mbudiu at vmware.com
Wed Apr 3 12:34:19 EDT 2019


Controls can be used for many things; for example, an architecture model will generally require you to supply several controls with a specified signature. This functionality of controls cannot be replaced with functions.

You can use controls like functions, but it is a bit clunky. For example, controls have no return values, so you have to use out parameters. The control body is in an additional apply block, so you have to write more to achieve the same thing. Also, we currently do not support generic controls, but we do support generic functions.

Functions can also be ‘extern’, and then, of course, the compiler may not know much about how they are implemented – it may be up to the back-end to supply an implementation. Controls cannot be ‘extern’.

The open-source compiler front-end inlines both controls and functions, so in the end the resulting code should be the same. It should not make any difference in terms of hardware support. With p4c you can actually see the result of the inlining by using the flags ‘--top4 FrontEndLast’ on the command line; this will dump a P4 program at the end of the front-end, and you can see what happened to your controls and functions.

Mihai

From: P4-dev <p4-dev-bounces at lists.p4.org> On Behalf Of Kamila Soucková
Sent: Wednesday, April 3, 2019 5:49 AM
To: p4-dev <p4-dev at lists.p4.org>
Subject: [P4-dev] Difference between "simple" control blocks and functions?

Hello,

I am wondering if there is any semantic difference between a "simple" control block that has no constructor parameters and consists of only an apply {...}, and a void function. I am asking because I have something that could be written as either of those two things, and I am curious whether there are any considerations I'm not aware of, or whether it is in this case simply a matter of style.

Is the difference perhaps that some architectures don't allow conditionals in functions, but do allow it in controls? Or in how these things may map to hardware?

Thank you!

Best,
Kamila
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20190403/10966092/attachment.html>


More information about the P4-dev mailing list