[P4-dev] Negative/Positive values multiplication and average for manipulation of data
antonin at barefootnetworks.com
Thu Feb 4 18:12:00 EST 2016
Division is not supported in bmv2, but right shift is.
Constants and temporaries in bmv2 are always integer. The bmv2 bm::Data C++
class is used to represent them, it is essentially implemented using libgmp
for integer functions (https://gmplib.org/). As a result constants and
temporaries have arbitrary integer precision (they are not bounded, except
by heap memory...). However, as soon as an integer is "stored" in a header
or metadata field, it is truncated based on the number of bits in the field.
For example, let's consider the following valid P4 statement:
modify_field(standard_metadata.egress_spec, 324 + 196). The bmv2 expression
evaluation engine will compute 324 + 196 and store the result, 520, in an
arbitrarily large Data temporary. However, when setting the
standard_metadata.egress_spec, which is 9 bit wide, the value will be
truncated to 8.
Negative numbers are not supported for header and metadata fields in bmv2
(yet?). So although I believe the model will not complain, the bit
representation will not be the 2-complement representation, it will be the
bit representation of the absolute value of the number. In other words,
while the expression engine will correctly evaluate 12 - 99 to -87, the
representation will be 0101 0111, and not, assuming the field is 8 bit 1010
1001 (which is the 2-complement representation).
On Thu, Feb 4, 2016 at 10:45 AM, Swaroop Thool <swaroopthool1991 at outlook.com
> Hello Everyone,
> Is support for negative values or any other values multiplication and
> finding average or something in bmv2 available?
> If yes, For example, I want to do ((-1x-8)+(1x5)+(-1x5))/3 = answer. What
> answer will I get: roundoff interger or in point? where -1,-8,5 etc are my
> run-time values.
> How and where to performance the above manipulation in p4? in action? or
> should add function in some switch file but how to provide run-time inputs
> to it and access in p4 program under particular action?
> P4-dev mailing list
> P4-dev at lists.p4.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the P4-dev