]> git.ipfire.org Git - thirdparty/linux.git/commit
unroll: add generic loop unroll helpers
authorAlexander Lobakin <aleksander.lobakin@intel.com>
Thu, 6 Feb 2025 18:26:26 +0000 (19:26 +0100)
committerJakub Kicinski <kuba@kernel.org>
Tue, 11 Feb 2025 01:54:43 +0000 (17:54 -0800)
commitc6594d64271704b335378e7b74c39fe4d4fcc777
tree8bfd5baec9b16021b300ef7e8dd96734a7811a72
parent5b281fe7e396c519914863c5de5ce3a3f9cffd5b
unroll: add generic loop unroll helpers

There are cases when we need to explicitly unroll loops. For example,
cache operations, filling DMA descriptors on very high speeds etc.
Add compiler-specific attribute macros to give the compiler a hint
that we'd like to unroll a loop.
Example usage:

 #define UNROLL_BATCH 8

unrolled_count(UNROLL_BATCH)
for (u32 i = 0; i < UNROLL_BATCH; i++)
op(priv, i);

Note that sometimes the compilers won't unroll loops if they think this
would have worse optimization and perf than without unrolling, and that
unroll attributes are available only starting GCC 8. For older compiler
versions, no hints/attributes will be applied.
For better unrolling/parallelization, don't have any variables that
interfere between iterations except for the iterator itself.

Co-developed-by: Jose E. Marchesi <jose.marchesi@oracle.com> # pragmas
Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Link: https://patch.msgid.link/20250206182630.3914318-2-aleksander.lobakin@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/linux/unroll.h