diff options
| author | Luca Barbato <lu_zero@gentoo.org> | 2019-09-17 15:36:02 +0200 |
|---|---|---|
| committer | Luca Barbato <lu_zero@gentoo.org> | 2019-09-17 15:36:02 +0200 |
| commit | 1855195f402e1873ca40eaae365e20104bad866d (patch) | |
| tree | a4a398ec3cfdff2788f836dfc54a8c1832ac1818 /library/stdarch/crates/std_detect/src/detect | |
| parent | 13fffd5fdec3ab1a0476db1af1357cd2965833be (diff) | |
| download | rust-1855195f402e1873ca40eaae365e20104bad866d.tar.gz rust-1855195f402e1873ca40eaae365e20104bad866d.zip | |
Add a mean to unset a bit in the cache
Diffstat (limited to 'library/stdarch/crates/std_detect/src/detect')
| -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. |
