You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
535 B
Rust
22 lines
535 B
Rust
4 years ago
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||
|
//
|
||
4 years ago
|
// Copyright (c) 2020-2021 Andre Richter <andre.o.richter@gmail.com>
|
||
4 years ago
|
|
||
|
//! General purpose code.
|
||
|
|
||
|
/// Check if a value is aligned to a given size.
|
||
|
#[inline(always)]
|
||
|
pub const fn is_aligned(value: usize, alignment: usize) -> bool {
|
||
|
assert!(alignment.is_power_of_two());
|
||
|
|
||
|
(value & (alignment - 1)) == 0
|
||
|
}
|
||
|
|
||
|
/// Align down.
|
||
|
#[inline(always)]
|
||
|
pub const fn align_down(value: usize, alignment: usize) -> usize {
|
||
|
assert!(alignment.is_power_of_two());
|
||
|
|
||
|
value & !(alignment - 1)
|
||
|
}
|