p4lang / p4-hlir

Apache License 2.0
32 stars 40 forks source link

sig width in action when execute_meter is used #4

Open musgravepeter opened 9 years ago

musgravepeter commented 9 years ago

I have an action: action save_and_meter(meter_id) { modify_field( meter_metadata.meter_id, meter_id); execute_meter( color_meter, meter_id, meter_metadata.meter_color); } for which the metadata field meter_id is 10 bits.

The presence of the execute_meter statement seems to be over-riding the correct determination of the signature width:

h.p4_actions['save_and_meter'].signature_widths [32]

Without the execute_meter statement the correct value (10) will be reported.

antoninbas commented 9 years ago

The behavioral model assumes that all meter indexes are 32-bit wide, so I am not surprised by this behavior. This should not be a major problem given that the modify_field primitive action will correctly truncate the 32-bit input to copy it to your 10-bit field. It just means that your action data for this table will be wider than what you want. Ideally however, the compiler would use the instance_count attribute of the meter to determine a more accurate width. For example, if instance_count = 1024, a 10-bit index is good enough. Thanks for reporting this issue, I will try to make this better in the future.