Для min(ctz(x), ctz(y)) мы можем использовать ctz(x | y), чтобы повысить производительность. А как насчет max(ctz(x), ctz(y))?
ctz представляет собой «подсчет конечных нулей».
Версия C++ (Compiler Explorer)
#include
#include
#include
int32_t test2(uint64_t x, uint64_t y) {
return std::max(std::countr_zero(x), std::countr_zero(y));
}
Версия Rust (Compiler Explorer)
pub fn test2(x: u64, y: u64) -> u32 {
x.trailing_zeros().max(y.trailing_zeros())
}
Подробнее здесь: https://stackoverflow.com/questions/763 ... xctzx-ctzy