facebook / facebook/zstd

Weird code size when -mbmi2 or -mno-bmi2 is specified

Open
#3,798 2 comments 2 reactions 0 assignees View on GitHub
Dominant language
C
Stars
27.9k
Forks
2.6k
Avg merge
1d 3h
Merged PRs (30d)
8

Description

**Describe the bug**
I compile libzstd in folder `lib` with:
```
make ZSTD_LIB_COMPRESSION=0 ZSTD_LIB_DICTBUILDER=0 ZSTD_LIB_DEPRECATED=0 ZSTD_LEGACY_SUPPORT=0 ZSTD_NO_UNUSED_FUNCTIONS=1 DYNAMIC_BMI2=0 CC=clang
```
When I add `CFLAGS` on command line and override BMI2 manually, I get the following lib sizes:
```
CFLAGS="" -rw-rw-r-- 209504 libzstd.a
CFLAGS="-mbmi2" -rw-rw-r-- 270344 libzstd.a
CFLAGS="-mno-bmi2" -rw-rw-r-- 391528 libzstd.a
```
All three libraries have different code size. This does not make sense to me, as I would expect either `-mbmi2` or `-mno-bmi2` to match the default code size, as `DYNAMIC_BMI2=0` is specified (note that I'm seeing the same behavior and exactly same code size even with `DYNAMIC_BMI2=1`).
Also note that GCC produces roughly the same results.

**To Reproduce**
Compile libzstd in folder `lib` with the supplied `make` command

**Expected behavior**
Supplying either `-mbmi2` or `-mno-bmi2` would match the default code size.
Is this behavior expected? Am I overriding BMI2 correctly?

**Desktop (please complete the following information):**
- OS: Ubuntu
- Version: 23
- Compiler: Clang-15, GCC-12
- Flags: Default
- Other relevant hardware specs: Zen1
- Build system: Make

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.