Re: [PATCH 2/2] zstd: Backport Huffman speed improvement from upstream

From: Linus Torvalds
Date: Tue Nov 21 2023 - 12:23:36 EST


On Mon, 20 Nov 2023 at 16:52, Nick Terrell <nickrterrell@xxxxxxxxx> 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