The fastest way to check if a number is a power of two is not to compute roundup_pow_of_two; it is to use ispower2 (param.h) or is_power_of_2 (log2.h in linux). Do that in two places.
Also, in one place, use order_base_2 instead of ilog2(roundup_pow_of_two()).