-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Kivi independent from Zig's std
- Loading branch information
1 parent
299a484
commit aa9a9ad
Showing
16 changed files
with
393 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const Math = @This(); | ||
|
||
pub fn alignBackward(comptime T: type, addr: T, alignment: T) T { | ||
// TODO: Panic | ||
// assert(isValidAlignGeneric(T, alignment)); | ||
|
||
// 000010000 // example alignment | ||
// 000001111 // subtract 1 | ||
// 111110000 // binary not | ||
return addr & ~(alignment - 1); | ||
} | ||
|
||
pub fn alignForward(comptime T: type, addr: T, alignment: T) T { | ||
// TODO: Panic | ||
// assert(isValidAlignGeneric(T, alignment)); | ||
|
||
return alignBackward(T, addr + (alignment - 1), alignment); | ||
} | ||
|
||
pub fn ceilPowerOfTwo(n_arg: u64) u64 { | ||
var n = n_arg; | ||
n -= 1; | ||
n |= n >> 1; | ||
n |= n >> 2; | ||
n |= n >> 4; | ||
n |= n >> 8; | ||
n |= n >> 16; | ||
n |= n >> 32; | ||
n += 1; | ||
|
||
return n; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.