Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ca5e8ad

Browse files
committed
fix(cksum): add x86 (32-bit) CPU feature detection support
The cpufeatures dependency was included for x86 architecture in Cargo.toml, but the hardware.rs file only had CPU feature detection functions for x86_64. This caused the x86 Android emulator test to fail because the CPU feature detection functions were missing. Added CPU feature detection functions for x86 (32-bit) architecture: - has_avx512() for x86 - has_avx2() for x86 - has_pclmul() for x86 Updated cfg attributes to include both x86_64 and x86 architectures. Updated test to cover both x86 and x86_64 architectures.
1 parent f49b134 commit ca5e8ad

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

src/uu/cksum/src/hardware.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,35 +67,53 @@ impl CpuFeatures {
6767
// CPU feature detection functions
6868
// These use cpufeatures crate for cross-platform detection
6969

70-
#[cfg(all(target_arch = "x86_64", not(target_os = "android")))]
70+
#[cfg(all(
71+
any(target_arch = "x86_64", target_arch = "x86"),
72+
not(target_os = "android")
73+
))]
7174
fn has_avx512() -> bool {
7275
cpufeatures::new!(cpuid_avx512, "avx512f", "avx512bw");
7376
cpuid_avx512::get()
7477
}
7578

76-
#[cfg(not(all(target_arch = "x86_64", not(target_os = "android"))))]
79+
#[cfg(not(all(
80+
any(target_arch = "x86_64", target_arch = "x86"),
81+
not(target_os = "android")
82+
)))]
7783
fn has_avx512() -> bool {
7884
false
7985
}
8086

81-
#[cfg(all(target_arch = "x86_64", not(target_os = "android")))]
87+
#[cfg(all(
88+
any(target_arch = "x86_64", target_arch = "x86"),
89+
not(target_os = "android")
90+
))]
8291
fn has_avx2() -> bool {
8392
cpufeatures::new!(cpuid_avx2, "avx2");
8493
cpuid_avx2::get()
8594
}
8695

87-
#[cfg(not(all(target_arch = "x86_64", not(target_os = "android"))))]
96+
#[cfg(not(all(
97+
any(target_arch = "x86_64", target_arch = "x86"),
98+
not(target_os = "android")
99+
)))]
88100
fn has_avx2() -> bool {
89101
false
90102
}
91103

92-
#[cfg(all(target_arch = "x86_64", not(target_os = "android")))]
104+
#[cfg(all(
105+
any(target_arch = "x86_64", target_arch = "x86"),
106+
not(target_os = "android")
107+
))]
93108
fn has_pclmul() -> bool {
94109
cpufeatures::new!(cpuid_pclmul, "pclmulqdq");
95110
cpuid_pclmul::get()
96111
}
97112

98-
#[cfg(not(all(target_arch = "x86_64", not(target_os = "android"))))]
113+
#[cfg(not(all(
114+
any(target_arch = "x86_64", target_arch = "x86"),
115+
not(target_os = "android")
116+
)))]
99117
fn has_pclmul() -> bool {
100118
false
101119
}
@@ -141,10 +159,13 @@ mod tests {
141159
}
142160

143161
#[test]
144-
#[cfg(all(target_arch = "x86_64", not(target_os = "android")))]
145-
fn test_cpu_features_on_x86_64() {
162+
#[cfg(all(
163+
any(target_arch = "x86_64", target_arch = "x86"),
164+
not(target_os = "android")
165+
))]
166+
fn test_cpu_features_on_x86() {
146167
let features = CpuFeatures::detect();
147-
// On x86_64, at least one feature should be detected or all false
168+
// On x86/x86_64, at least one feature should be detected or all false
148169
// (depending on CPU capabilities)
149170
let _ = features;
150171
}

0 commit comments

Comments
 (0)