gallivm: add a version of log2 which handles edge cases