Re: [PATCH] lib: zstd: make const array rtbTable static, reduces object code size

From: Nick Terrell
Date: Fri Sep 22 2017 - 15:14:18 EST


On 9/22/17, 8:00 AM, "linux-kernel-owner@xxxxxxxxxxxxxxx on behalf of Colin King" <linux-kernel-owner@xxxxxxxxxxxxxxx on behalf of colin.king@xxxxxxxxxxxxx> wrote:
> From: Colin Ian King <colin.king@xxxxxxxxxxxxx>
>
> Don't populate const array rtbTable on the stack, instead make it
> static. Also split overly long line to clean a chechkpach warning.
> Makes the object code smaller by nearly 500 bytes:
>
> Before:
> text data bss dec hex filename
> 13297 104 0 13401 3459 lib/zstd/fse_compress.o
>
> After:
> text data bss dec hex filename
> 12742 160 0 12902 3266 lib/zstd/fse_compress.o
>
> (gcc 6.3.0, x86-64)
>
> Signed-off-by: Colin Ian King <colin.king@xxxxxxxxxxxxx>

I tested your patch with gcc-7.1 on x86, and benchmarked the speed on
upstream zstd. There isn't a noticeable speed difference, since it isn't a
particularly hot piece of code. Would you be able to submit the same patch
upstream [1], or would you be okay with me porting it back upstream, so it
doesn't get lost on an update?

I didn't expect gcc to leave constant arrays on the stack, that seems
silly. Clang makes it static, but gcc loads it onto the stack, and in 6.3+
it saves the data statically, and then uses vector instructions to load it
onto the stack [2].

Tested-by: Nick Terrell <terrelln@xxxxxx>

[1] https://github.com/facebook/zstd
[2] https://godbolt.org/g/fvTcED