Question about implementing EWMA calculation in P4 data plane

Skip to first unread message

Xudong Liao

Aug 9, 2023, 12:26:45 PM8/9/23
to p4-dev

I am currently working on a project that involves using EWMA (Exponential Weighted Moving Average) to calculate a statistical value with a register in the P4 data plane. Code snippets are shown below, but the code cannot be compiled due to the invalid expression in "update_lo_1_value" . Does anyone know how to do it in p4 data plane?

register value_record {
    width : 64;
    instance_count : 4;

blackbox stateful_alu alu_record_value {
    reg: value_record;
    condition_lo: register_lo == 0;
    // update the value
    update_lo_1_predicate : not condition_lo;
    update_lo_1_value : (register_lo - (register_lo >> 3)) + (new_value >>3);
    // init this value
    update_lo_2_predicate : condition_lo;
    update_lo_2_value : new_value;


Andy Fingerhut

Aug 9, 2023, 2:00:49 PM8/9/23
to Xudong Liao, p4-dev
From the source code in your question, you appear to be using a P4_14 compiler for Tofino.

You may want to consider using P4_16 instead, as recent Tofino SDEs support it perhaps even better than P4_14 is supported.

There is a fairly low limit to what your NDA permits you to ask about the Tofino SDE on public forums.


You received this message because you are subscribed to the Google Groups "p4-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages