Add hulk.util and round_up_power_2()

This commit is contained in:
josh committed 2023-02-24 21:15:33 -05:00
1 parent 2ab388f2e9
commit ea6f485bd9
3 files changed
+23 -4

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
/**
* HULK utility functions.
*/
module hulk.util;
/**
* Round a value up to the next power of 2.
*
* @param v Value to round up.
* @param p Power of 2 to round up to.
*
* @return Rounded up value.
*/
T round_up_power_2(T)(T v, T p)
{
return (v + p - 1u) & ~(p - 1u);
}