-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Align key components to the nearest 8-bit size #30
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -114,8 +114,8 @@ if (/* hdr->ipv4.isValid() */ | |||
break; | |||
case MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_SEND_NH: | |||
{ | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the nice to have comments.
@@ -238,6 +238,11 @@ class P4TCTarget : public KernelSamplesTarget { | |||
} | |||
return "HOST"_cs; | |||
} | |||
|
|||
bool isPrimitiveByteAligned(int width) const { | |||
return (width <= 8 || width <= 16 || (width > 24 && width <= 32) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Signed-off-by: Adarsh <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
bfa6b0c
to
998f749
Compare
Co-authored-by: rst0git <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Komal, Jain <[email protected]>
998f749
to
ffca7b6
Compare
No description provided.