Use builtin_clz log2 for x86 architectures.
authorGodfrey van der Linden <gvdl@google.com>
Thu, 15 Jan 2015 18:42:34 +0000 (10:42 -0800)
committerGodfrey van der Linden <gvdl@google.com>
Tue, 20 Jan 2015 16:09:25 +0000 (08:09 -0800)
commit0766b65eff5923ac5a9e19b5f42a07e498d70e8b
treead453aa289852efee1f31a0a9e2c873dcfc4f3eb
parentb0514862de048412bc638f898ff1de816badcce7
Use builtin_clz log2 for x86 architectures.

Also fix LOG2_UP which would fail if n > 2^32.  (1 << (uintptr_t) 33) ==
0 unfortunately, the << operator does not promote the one to uint64_t.

Then I booted the kernel using both old and new versions and paniced if
they didn't agree. This code has also been tested using a clang compiler
on x86_64 using the following loop in a standalone app.

for (i = 0; i < 64; i++) {
uintptr_t v = (uintptr_t) 1 << i;
assert(new_log2_up(v) == old_log2_up(v));
assert(new_log2_up(v-1) == old_log2_up(v-1));
assert(new_log2_up(v+1) == old_log2_up(v+1));
assert(new_log2_down(v) == old_log2_down(v));
assert(new_log2_down(v-1) == old_log2_down(v-1));
assert(new_log2_down(v+1) == old_log2_down(v+1));
}
kern/include/ros/common.h