commit 07afd5bdbaef991a177e2df03af0502fce5dde23 (tree)
parent d8e22fcb208e2b52b272fb2c988f2123773b23e8
Author: Jonas Gollenz <jgollenz@outlook.com>
Date: Wed, 24 Aug 2022 01:35:45 +0200
docs: remove confusion about align[For|Back]ward
Diffstat:
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/std/mem.zig b/lib/std/mem.zig
@@ -3252,13 +3252,13 @@ test "sliceAsBytes preserves pointer attributes" {
try testing.expectEqual(in.alignment, out.alignment);
}
-/// Round an address up to the nearest aligned address
+/// Round an address up to the next (or current) aligned address.
/// The alignment must be a power of 2 and greater than 0.
pub fn alignForward(addr: usize, alignment: usize) usize {
return alignForwardGeneric(usize, addr, alignment);
}
-/// Round an address up to the nearest aligned address
+/// Round an address up to the next (or current) aligned address.
/// The alignment must be a power of 2 and greater than 0.
pub fn alignForwardGeneric(comptime T: type, addr: T, alignment: T) T {
return alignBackwardGeneric(T, addr + (alignment - 1), alignment);
@@ -3290,7 +3290,7 @@ test "alignForward" {
try testing.expect(alignForward(17, 8) == 24);
}
-/// Round an address up to the previous aligned address
+/// Round an address down to the previous (or current) aligned address.
/// Unlike `alignBackward`, `alignment` can be any positive number, not just a power of 2.
pub fn alignBackwardAnyAlign(i: usize, alignment: usize) usize {
if (@popCount(alignment) == 1)
@@ -3299,13 +3299,13 @@ pub fn alignBackwardAnyAlign(i: usize, alignment: usize) usize {
return i - @mod(i, alignment);
}
-/// Round an address up to the previous aligned address
+/// Round an address down to the previous (or current) aligned address.
/// The alignment must be a power of 2 and greater than 0.
pub fn alignBackward(addr: usize, alignment: usize) usize {
return alignBackwardGeneric(usize, addr, alignment);
}
-/// Round an address up to the previous aligned address
+/// Round an address down to the previous (or current) aligned address.
/// The alignment must be a power of 2 and greater than 0.
pub fn alignBackwardGeneric(comptime T: type, addr: T, alignment: T) T {
assert(@popCount(alignment) == 1);