Use the builtin clz function to compute log2.

This allows for timing consistency (otherwise we end up leaking
timing info by computing log2).