You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+34-22
Original file line number
Diff line number
Diff line change
@@ -95,13 +95,15 @@ A more detailed analysis is documented [in the wiki](https://github.com/Cyan4973
95
95
96
96
The following macros can be set at compilation time to modify libxxhash's behavior. They are generally disabled by default.
97
97
98
-
-`XXH_INLINE_ALL`: Make all functions `inline`, with implementations being directly included within `xxhash.h`.
98
+
-`XXH_INLINE_ALL`: Make all functions `inline`, implementations is directly included from within `xxhash.h`.
99
99
Inlining functions is beneficial for speed on small keys.
100
100
It's _extremely effective_ when key length is expressed as _a compile time constant_,
101
101
with performance improvements observed in the +200% range .
102
102
See [this article](https://fastcompression.blogspot.com/2018/03/xxhash-for-small-keys-impressive-power.html) for details.
103
103
-`XXH_PRIVATE_API`: same outcome as `XXH_INLINE_ALL`. Still available for legacy support.
104
104
The name underlines that `XXH_*` symbol names will not be exported.
105
+
-`XXH_STATIC_LINKING_ONLY`: gives access to internal state declaration, required for static allocation.
106
+
Incompatible with dynamic linking, due to risks of ABI changes.
105
107
-`XXH_NAMESPACE`: Prefixes all symbols with the value of `XXH_NAMESPACE`.
106
108
This macro can only use compilable character set.
107
109
Useful to evade symbol naming collisions,
@@ -117,40 +119,50 @@ The following macros can be set at compilation time to modify libxxhash's behavi
117
119
Method `1` uses a gcc-specific `packed` attribute, which can provide better performance for some targets.
118
120
Method `2` forces unaligned reads, which is not standard compliant, but might sometimes be the only way to extract better read performance.
119
121
Method `3` uses a byteshift operation, which is best for old compilers which don't inline `memcpy()` or big-endian systems without a byteswap instruction.
120
-
-`XXH_VECTOR` : manually select a vector instruction set (default: auto-selected at compilation time). Available instruction sets are `XXH_SCALAR`, `XXH_SSE2`, `XXH_AVX2`, `XXH_AVX512`, `XXH_NEON` and `XXH_VSX`. Compiler may require additional flags to ensure proper support (for example, `gcc` on linux will require `-mavx2` for `AVX2`, and `-mavx512f` for `AVX512`).
121
-
-`XXH_NO_PREFETCH` : disable prefetching. Some platforms or situations may perform better without prefetching. XXH3 only.
122
-
-`XXH_PREFETCH_DIST` : select prefetching distance. For close-to-metal adaptation to specific hardware platforms. XXH3 only.
122
+
-`XXH_CPU_LITTLE_ENDIAN`: By default, endianness is determined by a runtime test resolved at compile time.
123
+
If, for some reason, the compiler cannot simplify the runtime test, it can cost performance.
124
+
It's possible to skip auto-detection and simply state that the architecture is little-endian by setting this macro to 1.
125
+
Setting it to 0 states big-endian.
126
+
-`XXH_NO_STDLIB`: Disable invocation of `<stdlib.h>` functions, notably `malloc()` and `free()`.
127
+
`libxxhash`'s `XXH*_createState()` will always fail and return `NULL`.
128
+
But one-shot hashing (like `XXH32()`) or streaming using statically allocated states
129
+
still work as expected.
130
+
This build flag is useful for embedded environments without dynamic allocation.
123
131
-`XXH_NO_STREAM`: Disables the streaming API, limiting it to single shot variants only.
124
-
-`XXH_SIZE_OPT`: `0`: default, optimize for speed
125
-
`1`: default for `-Os` and `-Oz`: disables some speed hacks for size optimization
126
-
`2`: makes code as small as possible, performance may cry
127
132
-`XXH_NO_INLINE_HINTS`: By default, xxHash uses `__attribute__((always_inline))` and `__forceinline` to improve performance at the cost of code size.
128
133
Defining this macro to 1 will mark all internal functions as `static`, allowing the compiler to decide whether to inline a function or not.
129
134
This is very useful when optimizing for smallest binary size,
130
135
and is automatically defined when compiling with `-O0`, `-Os`, `-Oz`, or `-fno-inline` on GCC and Clang.
131
-
This may also increase performance depending on compiler and architecture.
136
+
This might also increase performance depending on compiler and architecture.
137
+
-`XXH_SIZE_OPT`: `0`: default, optimize for speed
138
+
`1`: default for `-Os` and `-Oz`: disables some speed hacks for size optimization
139
+
`2`: makes code as small as possible, performance may cry
140
+
-`XXH_DEBUGLEVEL` : When set to any value >= 1, enables `assert()` statements.
141
+
This (slightly) slows down execution, but may help finding bugs during debugging sessions.
142
+
-`XXH_ENABLE_AUTOVECTORIZE`: Auto-vectorization may be triggered for XXH32 and XXH64, depending on cpu vector capabilities and compiler version.
143
+
Note: auto-vectorization tends to be triggered more easily with recent versions of `clang`.
144
+
For XXH32, SSE4.1 or equivalent (NEON) is enough, while XXH64 requires AVX512.
145
+
Unfortunately, auto-vectorization is not always a good idea, and often degrades performance.
146
+
For this reason, the xxhash source code tries to prevent auto-vectorization by default.
147
+
That being said, systems evolve, and this conclusion is not forthcoming.
148
+
For example, it has been reported that recent Zen4 cpus are more likely to improve performance with vectorization.
149
+
Therefore, should you prefer or want to test vectorized code, just enable this flag:
150
+
it will remove the no-vectorization protection code, thus making it more likely for XXH32 and XXH64 to be auto-vectorized.
132
151
-`XXH32_ENDJMP`: Switch multi-branch finalization stage of XXH32 by a single jump.
133
152
This is generally undesirable for performance, especially when hashing inputs of random sizes.
134
153
But depending on exact architecture and compiler, a jump might provide slightly better performance on small inputs. Disabled by default.
135
-
-`XXH_NO_STDLIB`: Disable invocation of `<stdlib.h>` functions, notably `malloc()` and `free()`.
136
-
`libxxhash`'s `XXH*_createState()` will always fail and return `NULL`.
137
-
But one-shot hashing (like `XXH32()`) or streaming using statically allocated states
138
-
still work as expected.
139
-
This build flag is useful for embedded environments without dynamic allocation.
140
-
-`XXH_STATIC_LINKING_ONLY`: gives access to internal state declaration, required for static allocation.
141
-
Incompatible with dynamic linking, due to risks of ABI changes.
154
+
-`XXH_IMPORT`: MSVC specific: should only be defined for dynamic linking, as it prevents linkage errors.
155
+
156
+
#### Build modifiers specific for XXH3
157
+
-`XXH_VECTOR` : manually select a vector instruction set (default: auto-selected at compilation time). Available instruction sets are `XXH_SCALAR`, `XXH_SSE2`, `XXH_AVX2`, `XXH_AVX512`, `XXH_NEON` and `XXH_VSX`. Compiler may require additional flags to ensure proper support (for example, `gcc` on x86_64 requires `-mavx2` for `AVX2`, or `-mavx512f` for `AVX512`).
158
+
-`XXH_PREFETCH_DIST` : select prefetching distance. For close-to-metal adaptation to specific hardware platforms. XXH3 only.
159
+
-`XXH_NO_PREFETCH` : disable prefetching. Some platforms or situations may perform better without prefetching. XXH3 only.
142
160
-`XXH_NO_XXH3` : removes symbols related to `XXH3` (both 64 & 128 bits) from generated binary.
143
161
Useful to reduce binary size, notably for applications which do not employ `XXH3`.
144
162
-`XXH_NO_LONG_LONG`: removes compilation of algorithms relying on 64-bit types (`XXH3` and `XXH64`). Only `XXH32` will be compiled.
145
163
Useful for targets (architectures and compilers) without 64-bit support.
146
-
-`XXH_IMPORT`: MSVC specific: should only be defined for dynamic linking, as it prevents linkage errors.
147
-
-`XXH_CPU_LITTLE_ENDIAN`: By default, endianness is determined by a runtime test resolved at compile time.
148
-
If, for some reason, the compiler cannot simplify the runtime test, it can cost performance.
149
-
It's possible to skip auto-detection and simply state that the architecture is little-endian by setting this macro to 1.
150
-
Setting it to 0 states big-endian.
151
-
-`XXH_DEBUGLEVEL` : When set to any value >= 1, enables `assert()` statements.
152
-
This (slightly) slows down execution, but may help finding bugs during debugging sessions.
153
164
165
+
#### Makefile variables
154
166
When compiling the Command Line Interface `xxhsum` using `make`, the following environment variables can also be set :
155
167
-`DISPATCH=1` : use `xxh_x86dispatch.c`, to automatically select between `scalar`, `sse2`, `avx2` or `avx512` instruction set at runtime, depending on local host. This option is only valid for `x86`/`x64` systems.
156
168
-`XXH_1ST_SPEED_TARGET` : select an initial speed target, expressed in MB/s, for the first speed test in benchmark mode. Benchmark will adjust the target at subsequent iterations, but the first test is made "blindly" by targeting this speed. Currently conservatively set to 10 MB/s, to support very slow (emulated) platforms.
0 commit comments