diff options
Diffstat (limited to 'library/stdarch/crates/std_detect/src/detect/cache.rs')
| -rw-r--r-- | library/stdarch/crates/std_detect/src/detect/cache.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/library/stdarch/crates/std_detect/src/detect/cache.rs b/library/stdarch/crates/std_detect/src/detect/cache.rs index 92bc4b58d16..0056cd3026f 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. |
