One can use std::log2 directly.
std::log2
Note: I find this benchmark: https://quick-bench.com/q/BLCPebC3ibgA6vwewqUpiZRV4Qw quite surprising.