tweaked documentation.
fixed a stack overflow and removed dead code.
renamed foundation::log2() to int_log2() to avoid conflicts with std::log2(), and added fast implementations of int_log2() based on intrinsics.