mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 06:17:49 +00:00
Implement align_up using align_offset from Rust's standard library (#723)
Improve `align_up` performance using a bitmask
This commit is contained in:
@@ -74,11 +74,9 @@ impl<A> Locked<A> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Align the given address `addr` upwards to alignment `align`.
|
||||
///
|
||||
/// Requires that `align` is a power of two.
|
||||
fn align_up(addr: usize, align: usize) -> usize {
|
||||
let remainder = addr % align;
|
||||
if remainder == 0 {
|
||||
addr // addr already aligned
|
||||
} else {
|
||||
addr - remainder + align
|
||||
}
|
||||
(addr + align - 1) & !(align - 1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user