Skip to content

Commit bc3f664

Browse files
committed
rust: add function to create masks
Create a function that is equivalent to Linux's GENMASK macro. Signed-off-by: Fabien Parent <[email protected]>
1 parent 93d08ab commit bc3f664

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

rust/kernel/bits.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//use crate::static_assert;
2+
3+
/// Generate a mask where all bits >= `h` and <= `l` are set
4+
///
5+
/// This is a re-implementation in rust of `GENMASK`
6+
pub const fn genmask(h: u32, l: u32) -> u32 {
7+
//static_assert!(h >= l);
8+
//static_assert!(h < 32);
9+
((!0u32) - (1 << l) + 1) & ((!0u32) >> (32 - 1 - h))
10+
}

rust/kernel/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extern crate self as kernel;
3333
#[cfg(not(test))]
3434
#[cfg(not(testlib))]
3535
mod allocator;
36+
pub mod bits;
3637
mod build_assert;
3738
pub mod cred;
3839
pub mod device;

0 commit comments

Comments
 (0)