Which P4 target support multiplication operation?

Hello,

I understand P4_16 supports the multiplication operations, and multiplication can be implemented in bmv2.
However, some P4-programmable hardware switches, such as Tofino, lack support for multiplication. Therefore, I am interested in discovering if any hardware devices support multiplication functionalities.

Thanks

1 Like

Others may answer if they have knowledge of direct support for multiplication functionality in hardware devices.

Tofino does have support for a few mathematical operations, as externs. See section 7.13.1.1 “MathUnit Extern” in the Tofino Native Architecture documentation published here: Open-Tofino/PUBLIC_Tofino-Native-Arch.pdf at master · barefootnetworks/Open-Tofino · GitHub

As far as workarounds go, if you want to do an 8-bit by 8-bit integer multiply, for example, a P4 table with 2^(8+8)=64K entries is enough to enumerate all possible input values, and record the output values of an arbitrary operation, not only multiplication. See this article for other ideas: p4-guide/docs/floating-point-operations.md at master · jafingerhut/p4-guide · GitHub

You could also use such a 64K entry table, looked up 4 times, to implement 16-bit by 16-bit integer multiply, by doing a separate table lookup to get each of these intermediate results, where a[15:0] and b[15:0] are the values to be multiplied:

  1. a[7:0] x b[7:0]
  2. a[7:0] x b[15:8]
  3. a[15:8] x b[7:0]
  4. a[15:8] x b[15:8]

and then do the necessary shifting and adding to combine thus results to get a[15:0] x b[15:0]