From 1855195f402e1873ca40eaae365e20104bad866d Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Tue, 17 Sep 2019 15:36:02 +0200 Subject: [PATCH] Add a mean to unset a bit in the cache --- .../crates/std_detect/src/detect/cache.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/library/stdarch/crates/std_detect/src/detect/cache.rs b/library/stdarch/crates/std_detect/src/detect/cache.rs index 92bc4b58d167..0056cd3026fd 100644 --- a/library/stdarch/crates/std_detect/src/detect/cache.rs +++ b/library/stdarch/crates/std_detect/src/detect/cache.rs @@ -23,6 +23,12 @@ const fn test_bit(x: u64, bit: u32) -> bool { x & (1 << bit) != 0 } +/// Unset the `bit of `x`. +#[inline] +const fn unset_bit(x: u64, bit: u32) -> u64 { + x & !(1 << bit) +} + /// Maximum number of features that can be cached. const CACHE_CAPACITY: u32 = 63; @@ -63,6 +69,19 @@ impl Initializer { let v = self.0; self.0 = set_bit(v, bit); } + + /// Unsets the `bit` of the cache. + #[inline] + pub(crate) fn unset(&mut self, bit: u32) { + // FIXME: this way of making sure that the cache is large enough is + // brittle. + debug_assert!( + bit < CACHE_CAPACITY, + "too many features, time to increase the cache size!" + ); + let v = self.0; + self.0 = unset_bit(v, bit); + } } /// This global variable is a cache of the features supported by the CPU.