From ff39c35ac21fb17c7a96622d9d13f605dbe86b1d Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Mar 2026 23:12:18 +0100 Subject: [PATCH] arch: x86_64: Collapse nested if into match arm guards Do the necessary replacements to satisfy clippy::collapsible_match. Signed-off-by: Anatol Belski --- arch/src/x86_64/mod.rs | 96 ++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 50 deletions(-) diff --git a/arch/src/x86_64/mod.rs b/arch/src/x86_64/mod.rs index 8bc5ec19c..2b9ce3812 100644 --- a/arch/src/x86_64/mod.rs +++ b/arch/src/x86_64/mod.rs @@ -643,15 +643,13 @@ pub fn generate_common_cpuid( for entry in cpuid.as_mut_slice().iter_mut() { match entry.function { // Clear AMX related bits if the AMX feature is not enabled - 0x7 => { - if !config.amx { - if entry.index == 0 { - entry.edx &= !((1 << AMX_BF16) | (1 << AMX_TILE) | (1 << AMX_INT8)); - } - if entry.index == 1 { - entry.eax &= !(1 << AMX_FP16); - entry.edx &= !(1 << AMX_COMPLEX); - } + 0x7 if !config.amx => { + if entry.index == 0 { + entry.edx &= !((1 << AMX_BF16) | (1 << AMX_TILE) | (1 << AMX_INT8)); + } + if entry.index == 1 { + entry.eax &= !(1 << AMX_FP16); + entry.edx &= !(1 << AMX_COMPLEX); } } 0xd => @@ -673,55 +671,53 @@ pub fn generate_common_cpuid( } } } - 0x1d => { - // Tile Information (purely AMX related). - if !config.amx { - entry.eax = 0; - entry.ebx = 0; - entry.ecx = 0; - entry.edx = 0; - } + // Tile Information (purely AMX related). + 0x1d if !config.amx => { + entry.eax = 0; + entry.ebx = 0; + entry.ecx = 0; + entry.edx = 0; } - 0x1e => { - // TMUL information (purely AMX related) - if !config.amx { - entry.eax = 0; - entry.ebx = 0; - entry.ecx = 0; - entry.edx = 0; - } + // TMUL information (purely AMX related) + 0x1e if !config.amx => { + entry.eax = 0; + entry.ebx = 0; + entry.ecx = 0; + entry.edx = 0; } // Copy host L1 cache details if not populated by KVM - 0x8000_0005 => { - if entry.eax == 0 && entry.ebx == 0 && entry.ecx == 0 && entry.edx == 0 { - #[allow(unused_unsafe)] + 0x8000_0005 + if entry.eax == 0 + && entry.ebx == 0 + && entry.ecx == 0 + && entry.edx == 0 // SAFETY: cpuid called with valid leaves - if unsafe { std::arch::x86_64::__cpuid(0x8000_0000).eax } >= 0x8000_0005 { - // SAFETY: cpuid called with valid leaves - let leaf = unsafe { std::arch::x86_64::__cpuid(0x8000_0005) }; - entry.eax = leaf.eax; - entry.ebx = leaf.ebx; - entry.ecx = leaf.ecx; - entry.edx = leaf.edx; - } - } + && unsafe { std::arch::x86_64::__cpuid(0x8000_0000).eax } >= 0x8000_0005 => + { + // SAFETY: cpuid called with valid leaves + let leaf = unsafe { std::arch::x86_64::__cpuid(0x8000_0005) }; + entry.eax = leaf.eax; + entry.ebx = leaf.ebx; + entry.ecx = leaf.ecx; + entry.edx = leaf.edx; } // Copy host L2 cache details if not populated by KVM - 0x8000_0006 => { - if entry.eax == 0 && entry.ebx == 0 && entry.ecx == 0 && entry.edx == 0 { - #[allow(unused_unsafe)] + 0x8000_0006 + if entry.eax == 0 + && entry.ebx == 0 + && entry.ecx == 0 + && entry.edx == 0 // SAFETY: cpuid called with valid leaves - if unsafe { std::arch::x86_64::__cpuid(0x8000_0000).eax } >= 0x8000_0006 { - #[allow(unused_unsafe)] - // SAFETY: cpuid called with valid leaves - let leaf = unsafe { std::arch::x86_64::__cpuid(0x8000_0006) }; - entry.eax = leaf.eax; - entry.ebx = leaf.ebx; - entry.ecx = leaf.ecx; - entry.edx = leaf.edx; - } - } + && unsafe { std::arch::x86_64::__cpuid(0x8000_0000).eax } >= 0x8000_0006 => + { + #[allow(unused_unsafe)] + // SAFETY: cpuid called with valid leaves + let leaf = unsafe { std::arch::x86_64::__cpuid(0x8000_0006) }; + entry.eax = leaf.eax; + entry.ebx = leaf.ebx; + entry.ecx = leaf.ecx; + entry.edx = leaf.edx; } // Set CPU physical bits 0x8000_0008 => {