Open apinski-cavium opened 1 year ago
Or should |
, ^
and &
be valid really be made valid for arbitrary-precision integers. in similar way shifts and bit slices are handled?
Maybe I messed this up in the recent pr #3716
Maybe I messed this up in the recent pr #3716
No this has been accepted for a while I think.
Note: bitwise-operations (|,&,^,~) are not defined on expressions of type int.
In general, bitwise operations such as |
, &
and ^
are supported for int
in other programming languages. If I understand correctly, this restriction has been introduced with P4_14 and has not been updated since.
@mbudiu-vmw Is it worth discussing this at the P4 Language Design Working Group meetings?
Note: bitwise-operations (|,&,^,~) are not defined on expressions of type int.
In general, bitwise operations such as
|
,&
and^
are supported forint
in other programming languages. If I understand correctly, this restriction has been introduced with P4_14 and has not been updated since.
Arbitrary-precision integers always seemed too limited in the P4_16 language and it seemed like the spec was always too tight in that area so I am ok with loosing it up if there is well defined behavior.
Even CST0 ++ CST1 could be defined as (CST0 << shift) | CST1 where shift is the min bitwidth that fits CST1 (which I think is the same as ceil(log2(CST1+1))), though I might have done my math wrong). And yes I think this should be raised to the P4 LDWG.
Note the only issue with ++ is how to handle negative #s for all of those operations. But if it is positive it is obvious what should be done really.
Filed https://github.com/p4lang/p4-spec/issues/1189 for us to discuss at some point.
From the spec:
But p4c allows to compile:
Is there a pedantic mode to reject some extensions that p4c accept above the specifications like this case?
I noticed this while testing many of the testcases in the p4c testsuite on my front-end.
testdata/p4_16_samples/gauntlet_various_ops-bmv2.p4
has this in there.