coder.loop.unrollAndJam
R2026bDescription
coder.loop.unrollAndJam(
prompts the code generator to unroll the loop identified by loopID,unrollFactor)loopID by a
factor of unrollFactor and combine the resulting inner loop computations
across iterations into a single, larger inner loop body in the generated code.
Use this directive for perfectly nested loops, where
all computation occurs in the innermost loop and the code
contains no statements between loop levels. This
directive is most effective for small, compute-dense loop bodies and helps remove loop
overhead and improve data reuse. It can be less beneficial for large or complex loops. The
loop size must be perfectly divisible by the unrollFactor argument. For
more information about loop optimizations, see Optimize Loops in Generated Code.
Examples
Input Arguments
Limitations
Because of internal, low-level optimizations during code generation, the generated code can contain an imperfectly nested loop, even when the corresponding loop in the MATLAB® code is perfectly nested. Under these circumstances, the code generator cannot apply the
unrollAndJamdirective.
Tips
To view potential issues that the code generator encounters when applying the
coder.loop.unrollAndJamdirective, review the Code Insights section of the code generation report. See Code Generation Reports.
Extended Capabilities
Version History
Introduced in R2023a