Main Content

Unroll For-Generate Loops

Unroll and omit FOR and GENERATE loops from generated HDL code

Model Configuration Pane: Global Settings / Coding style


Specify whether FOR and GENERATE loops are unrolled and omitted from generated HDL code.


off (default) | on

Default: Off


Unroll and omit FOR and GENERATE loops from the generated HDL code.


Include FOR and GENERATE loops in the generated HDL code.


To set this property, use the functions hdlset_param or makehdl. To view the property value, use the function hdlget_param.

For some Simulink® blocks, by default, the HDL code is generated by using a FOR-GENERATE loop construct. These Simulink blocks are:

The code generated by using a FOR-GENERATE loop has better code readability, reduced lines of code, and reduced code generation time. For example, consider the VHDL® code generated for reshaping a 2-D matrix into a 1-D matrix. The example shows the code generated for the Reshape block with and without FOR-GENERATE loops.

  • Reshape block without FOR-GENERATE loop (Unroll For-Generate Loops is enabled):

Reshape_output : PROCESS (In1_signed)
Reshape_out1(0) <= In1_signed(0, 0);
Reshape_out1(1) <= In1_signed(1, 0);
Reshape_out1(2) <= In1_signed(2, 0);
Reshape_out1(3) <= In1_signed(3, 0);
Reshape_out1(4) <= In1_signed(4, 0);
Reshape_out1(5) <= In1_signed(5, 0);
Reshape_out1(6) <= In1_signed(6, 0);
Reshape_out1(7) <= In1_signed(7, 0);
Reshape_out1(8) <= In1_signed(8, 0);
Reshape_out1(9) <= In1_signed(9, 0);
Reshape_out1(10) <= In1_signed(0, 1);

  • Reshape block with a FOR-GENERATE loop (Unroll For-Generate Loops is disabled):

Reshape_out1GEN_LABEL1: FOR d1 IN 0 TO 1 GENERATE
  Reshape_out1GEN_LABEL: FOR d0 IN 0 TO 9 GENERATE
     Reshape_out1(d0 + (d1*10)) <= In1_signed(d0, d1);

  • If you are using an electronic design automation (EDA) tool that does not support GENERATE loops, select the loop unrolling option to omit loops from your generated HDL code.

  • Setting the loop unrolling option does not affect results obtained from simulation or synthesis of generated HDL code.

Recommended Settings

No recommended settings.

Programmatic Use

Parameter: LoopUnrolling
Type: character vector
Value: 'on' | 'off'
Default: 'off'

Version History

Introduced in R2012a