Thread (44 messages) 44 messages, 6 authors, 2023-10-02

Re: [PATCH v3 1/5] kernel: Add helper macros for loop unrolling

From: Song Liu <song@kernel.org>
Date: 2023-09-21 21:01:03
Also in: bpf

On Mon, Sep 18, 2023 at 2:25 PM KP Singh [off-list ref] wrote:
This helps in easily initializing blocks of code (e.g. static calls and
keys).

UNROLL(N, MACRO, __VA_ARGS__) calls MACRO N times with the first
argument as the index of the iteration. This allows string pasting to
create unique tokens for variable names, function calls etc.

As an example:

        #include <linux/unroll.h>

        #define MACRO(N, a, b)            \
                int add_##N(int a, int b) \
                {                         \
                        return a + b + N; \
                }

        UNROLL(2, MACRO, x, y)

expands to:

        int add_0(int x, int y)
        {
                return x + y + 0;
        }

        int add_1(int x, int y)
        {
                return x + y + 1;
        }

Signed-off-by: KP Singh <kpsingh@kernel.org>
Acked-by: Song Liu <song@kernel.org>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help