-
- Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix hardware capabilities detection; cksum --debug #9603
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
Conversation
41dd915 to 70f9707 Compare | GNU testsuite comparison: |
70f9707 to 6a734c6 Compare | GNU testsuite comparison: |
6a734c6 to e1fef5d Compare | GNU testsuite comparison: |
e1fef5d to 46c3bb6 Compare | GNU testsuite comparison: |
| My string approach worked but was naive. Your enum-based design with TryFrom validation is the right way: type-safe, O(log n) lookups, feature alias support. Excellent work avx512: detect_avx512() && !disabled.contains(&"AVX512F".to_string()), avx2: detect_avx2() && !disabled.contains(&"AVX2".to_string()), pclmul: detect_pclmul() && !disabled.contains(&"PMULL".to_string()), vmull: detect_vmull() && !disabled.contains(&"VMULL".to_string()), sse2: detect_sse2() && !disabled.contains(&"SSE2".to_string()), asimd: detect_asimd() && !disabled.contains(&"ASIMD".to_string()), |
| let mut set = BTreeSet::new(); | ||
| if detect_avx512() { | ||
| set.insert(HardwareFeature::Avx512); | ||
| } | ||
| if self.avx2 { | ||
| features.push("AVX2"); | ||
| if detect_avx2() { | ||
| set.insert(HardwareFeature::Avx2); | ||
| } | ||
| if self.pclmul { | ||
| features.push("PCLMUL"); | ||
| if detect_pclmul() { | ||
| set.insert(HardwareFeature::PclMul); | ||
| } | ||
| if self.vmull { | ||
| features.push("VMULL"); | ||
| if detect_vmull() { | ||
| set.insert(HardwareFeature::Vmull); | ||
| } | ||
| if self.sse2 { | ||
| features.push("SSE2"); | ||
| if detect_sse2() { | ||
| set.insert(HardwareFeature::Sse2); | ||
| } | ||
| if self.asimd { | ||
| features.push("ASIMD"); | ||
| if detect_asimd() { | ||
| set.insert(HardwareFeature::Asimd); | ||
| } | ||
| features |
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.
Here a functional approach might be cleaner, something like:
let set = [ (HardwareFeature::Avx512, detect_avx512 as fn() -> bool), (HardwareFeature::Avx2, detect_avx2), (HardwareFeature::PclMul, detect_pclmul), (HardwareFeature::Vmull, detect_vmull), (HardwareFeature::Sse2, detect_sse2), (HardwareFeature::Asimd, detect_asimd), ] .into_iter() .filter_map(|(feature, detect_func)| detect_func().then_some(feature)) .collect();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.
Oh, that looks really clean, I will switch to that. Thanks !
46c3bb6 to 231a857 Compare | GNU testsuite comparison: |
Kudos, good work! |
This MR fixes the GNU
cksum.shby correctly taking in account theGLIBC_TUNABLESenv varFixes #9518