Enforce target feature#61
Open
ogxd wants to merge 21 commits into
Open
Conversation
Owner
Author
|
This turns out to be much more challenging than expected: the target_feature disables inlining, which defeats the purpose of an fast hashing algorithm. This is done by design for "safety reasons" I assume. This is unfortunate because with runtime checks the context could have been made safe not to disable inlining. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem(s)
This PR addresses as few points:
platform#57target-cpu=nativebeing settarget-cpu=nativenot being set at allPossible Solutions
RUSTFLAGS target-feature=+aes,+sse2...#[target_feature(enable = "feature")]Chosen solution
This PR change behavior to enforce required target features to fully leverage hardware capabilities. In order not to enforce X86
avx2/vaeshowever we rely on an additional build-time check. This would not work properly in a cross-compiling situation, but I think it is acceptable for now, especially given thatavx2gxhash only runs on unstable rust anyway.EDIT 1: Inlining?
For some reason, it seems that
#[target_feature(enable = "feature")]prevents inlining. This is really unfortunate. It also seems that the attribute is "skipped" if the target feature is already enabled. For instance, if passed viaRUSTFLAGS, of it method is called within a method that itself has the attribute. When the attribute is skipped, we can have inlining.While it is rather annoying, we could deal with this limitation by using the attribute on the gxhash method itself (higher caller), However it's more complex for the
Hasherpart, as inlining on individualwrite_xmethods makes a big difference.