Conversation
There was a problem hiding this comment.
I found some small issues, but the general idea of storePrimitive* and getPrimitive* makes sense
However, I have a question.
In cases where you have something like a bit<22>.
Is getPrimitive32's first parameter guaranteed to be zeroed out?
Analogously, is the second parameter of storePrimitive32 (u32 value) guaranteed to have the remaining 10 bits zeroed out?
If it is, I think there is no issue, otherwise masking or shifting should be necessary
| { | ||
| hdr->ethernet.srcAddr = bpf_cpu_to_be64(value->u.MainControlImpl_send_nh.smac); | ||
| hdr->ethernet.dstAddr = ntohll(value->u.MainControlImpl_send_nh.dmac << 16); | ||
| storePrimitive64(&hdr->ethernet.srcAddr, 48, (bpf_cpu_to_be64(value->u.MainControlImpl_send_nh.smac))); |
There was a problem hiding this comment.
I think I accidentally found a bug
Was testing changing EthernetAddress' typecast[1] to a bit<39> and saw that the generated code was outputing this line as:
storePrimitive64(&hdr->ethernet.srcAddr, 40, (bpf_cpu_to_be64((u64)(u64)value->u.MainControlImpl_send_nh.smac)));
From what I understood, the second argument should be 39, not 40
[1] https://github.com/p4lang/p4c/blob/main/testdata/p4tc_samples/add_entry_1_example.p4#L4
There was a problem hiding this comment.
I am unable to reproduce this issue, If I change srcaddr to bit<39>, I get error about invalid ethernet packet size.
7c87489 to
34b62d4
Compare
vbnogueira
left a comment
There was a problem hiding this comment.
I can't show this in the diff because it wasn't changed in this PR [1], however it is causing a compilation error:
1 warning generated.
/home/vagrant/p4c/backends/tc/runtime/tmpn_esd7rd/add_entry_1_example_control_blocks.c:98:88: error: array type 'u8[6]' (aka 'unsigned char[6]') is not assignable
update_act_bpf_val->u.MainControlImpl_send_nh.dmac = hdr->ethernet.dstAddr;
A similar issue happens in [2]
[1] https://github.com/komaljai/p4c/blob/align_key_bytewise/testdata/p4tc_samples_outputs/add_entry_1_example_control_blocks.c#L96
[2] https://github.com/komaljai/p4c/blob/align_key_bytewise/testdata/p4tc_samples_outputs/add_entry_3_example_control_blocks.c#L96
testdata/p4tc_samples_outputs/add_entry_1_example_control_blocks.c
Outdated
Show resolved
Hide resolved
9635f71 to
295a6ce
Compare
psivanup
left a comment
There was a problem hiding this comment.
Please check the nice to have comments.
| } | ||
|
|
||
| bool isPrimitiveByteAligned(int width) const { | ||
| return (width <= 8 || width <= 16 || (width > 24 && width <= 32) || |
There was a problem hiding this comment.
Looks width <= 8 check is redundant
| return (width <= 8 || width <= 16 || (width > 24 && width <= 32) || | |
| return (width <= 16 || (width > 24 && width <= 32) || |
|
|
||
| public: | ||
| explicit EBPFScalarTypePNA(const IR::Type_Bits *bits) : EBPFScalarType(bits) { | ||
| isPrimitiveByteAligned = (width <= 8 || width <= 16 || (width > 24 && width <= 32) || |
There was a problem hiding this comment.
| isPrimitiveByteAligned = (width <= 8 || width <= 16 || (width > 24 && width <= 32) || | |
| isPrimitiveByteAligned = (width <= 16 || (width > 24 && width <= 32) || |
| if (generatesScalar(width) && isPrimitiveByteAligned == true) { | ||
| builder->append("0"); | ||
| } else { | ||
| builder->append("{ 0 }"); |
There was a problem hiding this comment.
may be you can add a comment that array initializer is emitted for non byte aligned primitive types as they are emitted as array type.
| : "getPrimitive64"_cs; | ||
| builder->appendFormat("%v((u8 *)", getPrimitive); | ||
| visit(expression); | ||
| builder->appendFormat(", %d)", scalar->implementationWidthInBits()); |
There was a problem hiding this comment.
| builder->appendFormat(", %d)", scalar->implementationWidthInBits()); | |
| builder->appendFormat(", %d)", scalar->implementationWidthInBits()); | |
| return; |
By adding return to the above code, you can replace all else blocks below with just one visit(expression).
cb20ec1 to
e5a365e
Compare
e5a365e to
889848e
Compare
998f749 to
ffca7b6
Compare
3f9f128 to
1234582
Compare
1234582 to
6395a85
Compare
6395a85 to
7f7134f
Compare
Signed-off-by: Komal, Jain <komal.jain@intel.com>
85c46fd to
ff5d749
Compare
No description provided.