facebook / facebook/zstd

Huffman assembly is slower than no asm on Zen 2

Open
#3,278 6 comments 1 reaction 1 assignee Claimed by @terrelln View on GitHub
Dominant language
C
Stars
27.9k
Forks
2.6k
Avg merge
1d 3h
Merged PRs (30d)
8

Description

**Describe the bug**
Defining `ZSTD_DISABLE_ASM` results in consistently faster decoding performance.

**To Reproduce**
1. Get a Zen 2 CPU
2. `#define ZSTD_DISABLE_ASM` in portability_macros.h (for simplicity)
3. Observe results

```
Release:
Bench (executable=zstd level=1 filename=huffman-compressed-larger, iterations=1):
[cspeed: 34.1 MB/s, dspeed: 1319.0 MB/s]
Bench (executable=zstd level=1 filename=large-literal-and-match-lengths, iterations=1):
[cspeed: 4748.98 MB/s, dspeed: 9444.9 MB/s]
Bench (executable=zstd level=1 filename=http, iterations=1):
[cspeed: 213.64 MB/s, dspeed: 505.8 MB/s]

Dev, NO_ASM:
Bench (executable=zstd level=1 filename=huffman-compressed-larger, iterations=1):
[cspeed: 35.19 MB/s, dspeed: 1542.9 MB/s]
Bench (executable=zstd level=1 filename=large-literal-and-match-lengths, iterations=1):
[cspeed: 4299.98 MB/s, dspeed: 9412.5 MB/s]
Bench (executable=zstd level=1 filename=http, iterations=1):
[cspeed: 220.41 MB/s, dspeed: 557.2 MB/s]
```

I observe a similar 10% decoding improvement when running the benchmark for release branch (it doesn't have the `large-literal-and-match-lengths` bench though).

**Expected behavior**
If ASM is not faster it should be off by default.

IMHO the non-ASM version is easier to tinker with since the compiler will handle register allocation decently and allows more scratch registers to be used.

**Desktop (please complete the following information):**
- OS: [e.g. Mac] Arch Linux
- Version [e.g. 22] Rolling, updated 2022-10-01
- Compiler [e.g. gcc] gcc 12.2.0
- Flags [e.g. O2] -O3 (Makefile default)
- Other relevant hardware specs [e.g. Dual-core] Ryzen 7 3700X, Boost disabled
- Build system [e.g. Makefile] Makefile

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.