Easier implementation for software running on "normal" architectures #543
Labels
No labels
announcement
bug
build
CI
dependencies
documentation
duplicate
enhancement
experience feedback
feature request
github_actions
help wanted
install
invalid
Long-term
optimization
portability
question
target-specific
test issue
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-Cyan4973/xxHash#543
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I wish there was a simplified implementation of xxhash, in a single cpp file, without #ifdef, a ~6KB file instead of ~145KB
Something like this
https://create.stephan-brumme.com/xxhash/
but for XXH3 (the 128 bit version), just to get (snippet)
In fact, I find it particularly difficult to debug other programs in which XXH3 is "integrated", it is really difficult to understand the interaction of all the #ifdefs.
Often you have "normal" environments (x86 / x64 machines) in which to use xxhash (actually a great program, when ... it works!)
I'm having trouble with a software that compiles and works fine with gcc on Windows and FreeBSD but not Linux, due to XXH3_state_t
Thank you
I wish it too.
I like Stefan's variants.
Problem is, it would violate one of the rules of this repository, which is "one
xxhash.hfile for all", on the ground that it's easier to integrate.The objective is not all lost though. We could consider smaller specialized files, which are then aggregated into a single
xxhash.hfile. This way, both approaches (small specialized files + single file for all) would be possible.However, this is a complex goal, and I don't see that happening on short term.
For your immediate needs, better consider a fix.
Could you please describe your issue ?
XXH3is supposed to work fine on Linux.It's actually continuously tested on Linux.
It's a 64-bit alignment issue with the gcc 10.3 compiler (Ubuntu's 21 default) and the -O3 option.
You can find the ongoing thread here
https://encode.su/threads/3664-C-expert-(on-Linux)-needed-with-xxhash
Short version: if into a struct that do a lot of other things you insert a XXH3_state_t (that should be 64 byte aligned) very nasty things happens turning on optimizations.
Even if you try to align the member, the entire struct, or even typedefs of maps (!) to 64-byte.
Disabling XXH alignment does not seems to work either, I'm still working on it.
Running with -fsanitize=undefined show the behavior
Thanks anyway for the answer
PS If you DO NOT "inject" a XXH variables into a struct, but into code, works fine with this compiler.
PS/2 clang does not like at all, too (different alignment error)
Current workaroud: using this
https://github.com/embeddedartistry/...lloc_aligned.c
=> "manually" allocating
That looks like a correct workaround.
Note that
XXH3_createState()is essentially doing the same thing, guaranteeing that the allocated space for the state is correctly aligned.Indeed, aligning a member of a struct to 64-bytes has consequences for the encompassing structure.
The rules regarding structure alignment are pretty clear, so it should be a straightforward application.
However, given that aligning on 64-bytes is not common, this could be a case which is not tested, hence could be missed.
Given that the issue happens on a specific compiler version, on a specific OS, using a specific set of flags,
a compiler bug issue is not excluded at this stage.
C11 says:
Which, if I'm reading correctly, is not particularly encouraging. It looks like implementations are free to ignore
alignas(64)...I'm not sure if there's a good solution available, but one small possible improvement would be: is it possible the
XXH_ALIGN()macro does not interact well with C++? It only usesalignas()when it detects C11, but doesn't check for C++11. We should consider adding|| (defined(__cplusplus) && (__cplusplus >= 201103L).Yes that's a good suggestion.
I did not realized that the issue would be triggered when compiling the source code in
C++mode.As for C++, please use
operator newandoperator delete.The following code is minimal repro and solution of this issue.
Also, I'd like to note that it seems recent version of
libstdc++already fixed this issue. Please add-std=c++17to gcc/clang command line switch.Default allocator (
struct Issue543) returns nicely aligned memory pointer 🎉align macro:
@ new and delete
https://encode.su/threads/3664-C-expert-(on-Linux)-needed-with-xxhash?p=70372&viewfull=1#post70372
a matter of habit
aligned_alloc (or whatever) does not always exists (in fact, I used this as a workaround/fix https://github.com/embeddedartistry/embedded-resources/blob/master/examples/c/malloc_aligned.c
neither -std=c++17 is feasible (happen to compile my project for non-Intel NAS and vSphere servers and others "strange" things)
So I would like to ask a question about alignment as a mandatory prerequisite for XXH3.
Is it possible to eliminate at all (optionally), of course "paying" a certain performance penalty?
I only did a few quick (failed) tests as I ran into a concomitant g++ (!) bug that took me a long time
Thanks for all reply
PS The state is big, very big (hundreds of bytes) so, in fact, a "on demand" allocation it's an improvement for my software (sometimes it allocates 500,000 or even a few million structures), not all evils come to harm
If you can use accessor method and sacrifice 64 bytes, it allows you to introduce manual alignment.
With the following conditions, I think it's doable.
XXH_STATIC_LINKING_ONLYandXXH_VECTORasXXH_SCALARbefore includingxxhash.h,For example, add the following
#ifand#endifpair toxxhash.h.Compile and run the following code with and without
XXH_VECTORandXXH_ALIGN.