P4C
The P4 Compiler
|
#include <bitrange.h>
A helper type used to construct a range that starts at zero and ends at the maximum index that is safely representable without overflow. Only meant to be used when constructing a HalfOpenRange or ClosedRange.
ZeroToMax ranges are useful as an identity when intersecting ranges. If you have a loop where you intersect ranges over and over, you may find ZeroToMax useful.
A caveat: "safely representable" above means that basic bitrange getters, queries, comparisons, and set operations work. It does not mean that any computation you do with the bitrange will be safe; operations that increase the size of very large bitranges, that shift them, or that change their units may result in integer overflow.
It's generally safe to change the endianness of ZeroToMax, as long as the space it lives inside is safe. If you try to treat it as living in a space which also has a very large size, you may encounter integer overflow.
XXX: There's no substitute for checking unsafe conversions before performing them, but we don't do that right now, so be cautious with very large ranges, just as you would be with storing very large values into a primitive type.