kernel/bits.rs
1// Copyright 2026 The Fuchsia Authors
2//
3// Use of this source code is governed by a MIT-style
4// license that can be found in the LICENSE file or at
5// https://opensource.org/licenses/MIT
6
7/// Returns a bitmask of `x` low bits set, matching C++'s `BIT_MASK(x)` from `<bits.h>`.
8#[inline(always)]
9pub const fn bit_mask_u64(x: usize) -> u64 {
10 if x >= u64::BITS as usize { !0 } else { (1u64 << x) - 1 }
11}
12
13/// Returns a 32-bit bitmask of `x` low bits set, matching C++'s `BIT_MASK32(x)` from `<bits.h>`.
14#[inline(always)]
15pub const fn bit_mask_u32(x: usize) -> u32 {
16 if x >= u32::BITS as usize { !0 } else { (1u32 << x) - 1 }
17}