commit 14abf0fda5080b52ddfc0976d0e7c93928dbe543 (tree)
parent d422d5753b64b57b8559ceee45081f4e1e355e54
Author: SamTebbs33 <samuel.tebbs@gmail.com>
Date: Thu, 27 Jun 2019 22:22:17 +0100
Add doc comments to alignment functions
Diffstat:
1 file changed, 5 insertions(+), 0 deletions(-)
diff --git a/std/mem.zig b/std/mem.zig
@@ -1481,6 +1481,7 @@ test "subArrayPtr" {
}
/// Round an address up to the nearest aligned address
+/// The alignment must be greater than 0.
pub fn alignForward(addr: usize, alignment: usize) usize {
return alignBackward(addr + (alignment - 1), alignment);
}
@@ -1500,6 +1501,8 @@ test "alignForward" {
testing.expect(alignForward(17, 8) == 24);
}
+/// Round an address up to the previous aligned address
+/// The alignment must be greater than 0.
pub fn alignBackward(addr: usize, alignment: usize) usize {
// 000010000 // example addr
// 000001111 // subtract 1
@@ -1507,6 +1510,8 @@ pub fn alignBackward(addr: usize, alignment: usize) usize {
return addr & ~(alignment - 1);
}
+/// Given an address and an alignment, return true if the address is a multiple of the alignment
+/// The alignment must be greater than 0.
pub fn isAligned(addr: usize, alignment: usize) bool {
return alignBackward(addr, alignment) == addr;
}