| ... | ... | @@ -3252,13 +3252,13 @@ test "sliceAsBytes preserves pointer attributes" { |
| 3252 | 3252 | try testing.expectEqual(in.alignment, out.alignment); |
| 3253 | 3253 | } |
| 3254 | 3254 | |
| 3255 | | /// Round an address up to the nearest aligned address |
| 3255 | /// Round an address up to the next (or current) aligned address. |
| 3256 | 3256 | /// The alignment must be a power of 2 and greater than 0. |
| 3257 | 3257 | pub fn alignForward(addr: usize, alignment: usize) usize { |
| 3258 | 3258 | return alignForwardGeneric(usize, addr, alignment); |
| 3259 | 3259 | } |
| 3260 | 3260 | |
| 3261 | | /// Round an address up to the nearest aligned address |
| 3261 | /// Round an address up to the next (or current) aligned address. |
| 3262 | 3262 | /// The alignment must be a power of 2 and greater than 0. |
| 3263 | 3263 | pub fn alignForwardGeneric(comptime T: type, addr: T, alignment: T) T { |
| 3264 | 3264 | return alignBackwardGeneric(T, addr + (alignment - 1), alignment); |
| ... | ... | @@ -3290,7 +3290,7 @@ test "alignForward" { |
| 3290 | 3290 | try testing.expect(alignForward(17, 8) == 24); |
| 3291 | 3291 | } |
| 3292 | 3292 | |
| 3293 | | /// Round an address up to the previous aligned address |
| 3293 | /// Round an address down to the previous (or current) aligned address. |
| 3294 | 3294 | /// Unlike `alignBackward`, `alignment` can be any positive number, not just a power of 2. |
| 3295 | 3295 | pub fn alignBackwardAnyAlign(i: usize, alignment: usize) usize { |
| 3296 | 3296 | if (@popCount(alignment) == 1) |
| ... | ... | @@ -3299,13 +3299,13 @@ pub fn alignBackwardAnyAlign(i: usize, alignment: usize) usize { |
| 3299 | 3299 | return i - @mod(i, alignment); |
| 3300 | 3300 | } |
| 3301 | 3301 | |
| 3302 | | /// Round an address up to the previous aligned address |
| 3302 | /// Round an address down to the previous (or current) aligned address. |
| 3303 | 3303 | /// The alignment must be a power of 2 and greater than 0. |
| 3304 | 3304 | pub fn alignBackward(addr: usize, alignment: usize) usize { |
| 3305 | 3305 | return alignBackwardGeneric(usize, addr, alignment); |
| 3306 | 3306 | } |
| 3307 | 3307 | |
| 3308 | | /// Round an address up to the previous aligned address |
| 3308 | /// Round an address down to the previous (or current) aligned address. |
| 3309 | 3309 | /// The alignment must be a power of 2 and greater than 0. |
| 3310 | 3310 | pub fn alignBackwardGeneric(comptime T: type, addr: T, alignment: T) T { |
| 3311 | 3311 | assert(@popCount(alignment) == 1); |