-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix(wc):GNU wc-cpu.sh #9144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mattsu2020
wants to merge
4
commits into
uutils:main
Choose a base branch
from
mattsu2020:wc_compatibility
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix(wc):GNU wc-cpu.sh #9144
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4bbd987
feat(wc): add conditional SIMD support for counting with debug flag
mattsu2020 4752e2a
refactor(wc): reorder SIMD debug output conditions for better readabi…
mattsu2020 ead1881
chore: add jargon words to spellcheck dictionary
mattsu2020 6ea2596
Update src/uu/wc/src/cpu_features.rs
mattsu2020 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| // This file is part of the uutils coreutils package. | ||
| // | ||
| // For the full copyright and license information, please view the LICENSE | ||
| // file that was distributed with this source code. | ||
|
|
||
| use std::env; | ||
| use std::sync::OnceLock; | ||
|
|
||
| #[derive(Debug)] | ||
| pub(crate) struct SimdPolicy { | ||
| disabled_by_env: Vec<String>, | ||
| available: Vec<&'static str>, | ||
| } | ||
|
|
||
| impl SimdPolicy { | ||
| fn detect() -> Self { | ||
| let tunables = env::var_os("GLIBC_TUNABLES") | ||
| .and_then(|value| value.into_string().ok()) | ||
| .unwrap_or_default(); | ||
|
|
||
| let disabled_by_env = parse_disabled_features(&tunables); | ||
| let available = detect_available_features(); | ||
|
|
||
| Self { | ||
| disabled_by_env, | ||
| available, | ||
| } | ||
| } | ||
|
|
||
| pub(crate) fn env_allows_simd(&self) -> bool { | ||
| self.disabled_by_env.is_empty() | ||
| } | ||
|
|
||
| pub(crate) fn disabled_features(&self) -> &[String] { | ||
| &self.disabled_by_env | ||
| } | ||
|
|
||
| pub(crate) fn available_features(&self) -> &[&'static str] { | ||
| &self.available | ||
| } | ||
| } | ||
|
|
||
| static SIMD_POLICY: OnceLock<SimdPolicy> = OnceLock::new(); | ||
|
|
||
| pub(crate) fn simd_policy() -> &'static SimdPolicy { | ||
| SIMD_POLICY.get_or_init(SimdPolicy::detect) | ||
| } | ||
|
|
||
| fn parse_disabled_features(tunables: &str) -> Vec<String> { | ||
| if tunables.is_empty() { | ||
| return Vec::new(); | ||
| } | ||
|
|
||
| let mut disabled = Vec::new(); | ||
|
|
||
| for entry in tunables.split(':') { | ||
| let entry = entry.trim(); | ||
| let Some((name, raw_value)) = entry.split_once('=') else { | ||
| continue; | ||
| }; | ||
|
|
||
| if name.trim() != "glibc.cpu.hwcaps" { | ||
| continue; | ||
| } | ||
|
|
||
| for token in raw_value.split(',') { | ||
| let token = token.trim(); | ||
| if !token.starts_with('-') { | ||
| continue; | ||
| } | ||
| let feature = token.trim_start_matches('-').to_ascii_uppercase(); | ||
| if !feature.is_empty() { | ||
| disabled.push(feature); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| disabled | ||
| } | ||
|
|
||
| fn detect_available_features() -> Vec<&'static str> { | ||
| let mut features = Vec::new(); | ||
| #[cfg(any(target_arch = "x86", target_arch = "x86_64")] | ||
| { | ||
| if std::arch::is_x86_feature_detected!("avx2") { | ||
| features.push("AVX2"); | ||
| } | ||
| if std::arch::is_x86_feature_detected!("sse2") { | ||
| features.push("SSE2"); | ||
| } | ||
| } | ||
| #[cfg(all(target_arch = "aarch64", target_endian = "little"))] | ||
| { | ||
| if std::arch::is_aarch64_feature_detected!("asimd") { | ||
| features.push("ASIMD"); | ||
| } | ||
| } | ||
| features | ||
| } |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should agree on a common implementation to put in uucore for it to be reused for the --debug flag of
cksum(see #9088)