1use crate::queue::INDEX_SHIFT;
2
3pub(crate) const REGION_MASK: usize = 0b11111111;
4
5#[cfg(target_pointer_width = "64")]
6pub(crate) const REGION_COUNT: usize = 8;
7
8#[cfg(target_pointer_width = "32")]
9pub(crate) const REGION_COUNT: usize = 4;
10
11#[inline(always)]
13#[cfg(target_pointer_width = "64")]
14pub(crate) const fn region_size<const N: usize>() -> usize {
15 N >> 3
16}
17
18#[inline(always)]
20#[cfg(target_pointer_width = "32")]
21pub(crate) const fn region_size<const N: usize>() -> usize {
22 N >> 2
23}
24
25#[inline(always)]
27#[cfg(target_pointer_width = "64")]
28pub(crate) const fn region_shift<const N: usize>() -> usize {
29 N.trailing_zeros() as usize - 3
30}
31
32#[inline(always)]
34#[cfg(target_pointer_width = "32")]
35pub(crate) const fn region_shift<const N: usize>() -> usize {
36 N.trailing_zeros() as usize - 2
37}
38
39#[inline(always)]
41pub(crate) fn current_region<const N: usize>(index: usize) -> usize {
42 index >> region_shift::<N>()
43}
44
45#[inline(always)]
47pub(crate) fn region_mask<const N: usize>(index: usize) -> usize {
48 REGION_MASK << (current_region::<N>(index) << REGION_COUNT.trailing_zeros())
50}
51
52#[inline(always)]
54pub(crate) fn slot_index<const N: usize>(slot: usize) -> usize {
55 slot >> INDEX_SHIFT & (N - 1)
60}
61
62#[inline(always)]
64pub(crate) fn one_shifted<const N: usize>(index: usize) -> usize {
65 1 << ((index >> region_shift::<N>()) << REGION_COUNT.trailing_zeros())
66}