p4lang / p4c

P4_16 reference compiler
https://p4.org/
Apache License 2.0
670 stars 441 forks source link

128bit LPM match support #3841

Open lzhzero opened 1 year ago

lzhzero commented 1 year ago

Hi, When we use p4c-bm2-ss to compile the attached program, sometime we get the following error depend on the Clang/gcc versions.

test_128.p4(43): [--Werror=invalid] error: &&&: invalid mask for LPM key
      IPv6_UNICAST &&& IPv6_MASK3 : A1();
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^

This issue is only observed when we compile the p4c-bm2-ss binary with certain version of Clang/gcc. For other versions of Clang/gcc, the p4 program will just compile fine without any complains, I doubt it will run ok, but I haven't tested it.

A little digging revealed that the LPM implementation is only using 64bit unsigned long. https://github.com/p4lang/p4c/blob/main/backends/bmv2/common/control.h#L488

Can 128bit LPM match be supported? Or at least the p4c-bm2-ss compiler should reject unsupported p4 programs no matter which Clang/gcc we use.

test_128.p4.txt

mihaibudiu commented 1 year ago

If the bmv2 simulator supports wide masks the compiler should have no problem. The error message is not very good either.

mihaibudiu commented 1 year ago

@hanw, the blame claims you wrote this code. Can I assign this bug to you? Indeed, using static_cast is unsafe.