v8.run/go/exp@v0.0.26-0.20230226010534-afcdbd3f782d/util/mathutil/round2.go (about) 1 /****************************************************************************** 2 3 Original C code: https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 4 5 *******************************************************************************/ 6 7 package mathutil 8 9 func RoundUpPowerOf2(v uint32) uint32 { 10 v-- 11 v |= v >> 1 12 v |= v >> 2 13 v |= v >> 4 14 v |= v >> 8 15 v |= v >> 16 16 v++ 17 return v 18 }