Skip to content

Commit 9fe42b0

Browse files
committed
Add a mean to unset a bit in the cache
1 parent cb6fa68 commit 9fe42b0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

crates/std_detect/src/detect/cache.rs

+19
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ const fn test_bit(x: u64, bit: u32) -> bool {
2323
x & (1 << bit) != 0
2424
}
2525

26+
/// Unset the `bit of `x`.
27+
#[inline]
28+
const fn unset_bit(x: u64, bit: u32) -> u64 {
29+
x & !(1 << bit)
30+
}
31+
2632
/// Maximum number of features that can be cached.
2733
const CACHE_CAPACITY: u32 = 63;
2834

@@ -63,6 +69,19 @@ impl Initializer {
6369
let v = self.0;
6470
self.0 = set_bit(v, bit);
6571
}
72+
73+
/// Unsets the `bit` of the cache.
74+
#[inline]
75+
pub(crate) fn unset(&mut self, bit: u32) {
76+
// FIXME: this way of making sure that the cache is large enough is
77+
// brittle.
78+
debug_assert!(
79+
bit < CACHE_CAPACITY,
80+
"too many features, time to increase the cache size!"
81+
);
82+
let v = self.0;
83+
self.0 = unset_bit(v, bit);
84+
}
6685
}
6786

6887
/// This global variable is a cache of the features supported by the CPU.

0 commit comments

Comments
 (0)