lkml.org 
[lkml]   [2023]   [Nov]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 2/2] zstd: Backport Huffman speed improvement from upstream
On Mon, 20 Nov 2023 at 16:52, Nick Terrell <nickrterrell@gmail.com> wrote:
>
> +/* Calls X(N) for each stream 0, 1, 2, 3. */
> +#define HUF_4X_FOR_EACH_STREAM(X) \
> + { \
> + X(0) \
> + X(1) \
> + X(2) \
> + X(3) \
> + }
> +
> +/* Calls X(N, var) for each stream 0, 1, 2, 3. */
> +#define HUF_4X_FOR_EACH_STREAM_WITH_VAR(X, var) \
> + { \
> + X(0, (var)) \
> + X(1, (var)) \
> + X(2, (var)) \
> + X(3, (var)) \
> + }
> +

What shitty compilers do you need to be compatible with?

Because at least for Linux, the above is one single #define:

#define FOUR(X,y...) do { \
X(0,##y); X(1,##y); X(2,##y); X(3,##y); \
} while (0)

and it does the right thing for any number of arguments, ie

FOUR(fn)
FOUR(fn1,a)
FOUR(fn2,a,b)

expands to

do { fn(0); fn(1); fn(2); fn(3); } while (0)
do { fn1(0,a); fn1(1,a); fn1(2,a); fn1(3,a); } while (0)
do { fn2(0,a,b); fn2(1,a,b); fn2(2,a,b); fn2(3,a,b); } while (0)

so unless you need to support some completely garbage compiler
upstream, please just do the single #define.

Linus

\
 
 \ /
  Last update: 2023-11-21 18:24    [W:0.075 / U:0.288 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site