I use @stage to arrange multiple registers in one stage, but when I arrange more than 4 registers in one stage, I receive a warning, and then the extra registers are arranged into other stages.
However, when I observe through p4i, I find that the SRAM Blocks occupied by each register are actually very small, and there are still many SRAM Blocks unused.
How can I arrange more than 4 registers in one stage?
Someone like Vlad could give a more authoritative answer than I can, but if I recall correctly, Tofino hardware may have a designed-in limitation of at most 4 registers in one stage, and that limit is due to other parts of the hardware than how much SRAM those registers use.
In your case, the critical resource are the so-called “Meter ALUs”, which are used to implement all stateful externs except counters (that is meters, registers, low-pass filters (LPFs), weighted random early discard externs (WREDs) and action selector externs). I know, that name migth be a little confusing, but that’s what it is.
The column “S/M ALUs”, located right between the MAP RAMs and the right-hand-side (6x8) group of SRAM blocks represents both the Meter ALUs (M) and the Statistic ALUs (S) – the latter are responsible for the counters. The very top square there is the Meter ALU, the one underneath is a Counter ALU, the one down is the next Meter ALU and so on.
Since this column contains 8 squares, that means that each stage contains 4 meter and 4 counter ALUs. Thus, you can have no more than 4 registers/meters/LPfs/WREDs/ActionSelectors (total) plus 4 counters in any stage.
P4i tool also has a useful “Resource Utilization” section that shows all the resources and their utilization per stage. If some resource is 100% utilized, (in your case you will see that in the stage in question Meter ALU utilization is 100%).