Function alignForward [src]
Round an address up to the next (or current) aligned address.
The alignment must be a power of 2 and greater than 0.
Asserts that rounding up the address does not cause integer overflow.
Prototype
pub fn alignForward(comptime T: type, addr: T, alignment: T) T
Parameters
T: type
addr: T
alignment: T
Example
test alignForward {
try testing.expect(alignForward(usize, 1, 1) == 1);
try testing.expect(alignForward(usize, 2, 1) == 2);
try testing.expect(alignForward(usize, 1, 2) == 2);
try testing.expect(alignForward(usize, 2, 2) == 2);
try testing.expect(alignForward(usize, 3, 2) == 4);
try testing.expect(alignForward(usize, 4, 2) == 4);
try testing.expect(alignForward(usize, 7, 8) == 8);
try testing.expect(alignForward(usize, 8, 8) == 8);
try testing.expect(alignForward(usize, 9, 8) == 16);
try testing.expect(alignForward(usize, 15, 8) == 16);
try testing.expect(alignForward(usize, 16, 8) == 16);
try testing.expect(alignForward(usize, 17, 8) == 24);
}
Source
pub fn alignForward(comptime T: type, addr: T, alignment: T) T {
assert(isValidAlignGeneric(T, alignment));
return alignBackward(T, addr + (alignment - 1), alignment);
}