Hello everyone,
Assume the following header definition:
header MyHeader {
bit<7> field_1;
bit<10> field_2;
}
Now consider P4 supported switch with a packet header vector that contains 10 fields. Among them, two are 16 bits wide and the rest of them are 8 bit wide. Now to map the fields of MyHeader we can either map field_2 to a 16 bit wide PHV field or merge two 8 bit wide PHV field together. I guess the task is handled by a compiler backend.
My question is, how a compiler backend decides which field of P4 program to be mapped to which fields in the PHV? I guess it should be a version of Knapsack optimization problem?
Secondly, if a 10 bit header field is mapped to two 8 bit wide field in the PHV, then there should be some kind of padding to be included. Does the parser handles the task of including the padding or it is does afterwards?