Main Content

Pipeline MATLAB Expressions

With the coder.hdl.pipeline pragma, you can specify the placement and number of pipeline registers in the HDL code generated for a MATLAB® expression.

If you insert pipeline registers and enable distributed pipelining, HDL Coder™ automatically moves the pipeline registers to break the critical path.

How To Pipeline a MATLAB Expression

To insert pipeline registers at the output of an expression in MATLAB code, place the expression in the coder.hdl.pipeline pragma. Specify the number of registers.

You can insert pipeline registers in the generated HDL code:

  • At the output of the entire right side of an assignment statement.

    The following code inserts three pipeline registers at the output of a MATLAB expression, a + b * c:

        y = coder.hdl.pipeline(a + b * c, 3);
    
  • At an intermediate stage within a longer MATLAB expression.

    The following code inserts five pipeline registers after the computation of b * c within a longer expression, a + b * c:

        y = a + coder.hdl.pipeline(b * c, 5);
    
  • By nesting multiple instances of the pragma.

    The following code inserts five pipeline registers after the computation of b * c, and two pipeline registers at the output of the whole expression, a + b * c:

        y = coder.hdl.pipeline(a + coder.hdl.pipeline(b * c, 5),2);
    

Alternatively, to insert one pipeline register instead of multiple pipeline registers, you can omit the second argument in the pragma:

y = coder.hdl.pipeline(a + b * c);
y = a + coder.hdl.pipeline(b * c);
y = coder.hdl.pipeline(a + coder.hdl.pipeline(b * c));

Limitations of Pipelining for MATLAB Expressions

Note

When you use the MATLAB code inside a MATLAB Function block and select the MATLAB Datapath architecture or enable the AggresiveDataflowConversion optimization, these limitations do not apply.

HDL Coder cannot insert a pipeline register at the output of a MATLAB expression if any of the variables in the expression are:

  • A persistent variable that maps to a state element, like a state register or RAM.

  • In a data feedback loop. For example, in the following code, you cannot pipeline an expression containing the t or pvar variables:

    persistent pvar;
    t = u + pvar;
    pvar = t + v;

See Also

Related Topics