3 ms·
And fast; Mesa uses this. static INLINE boolean util_is_power_of_two( unsigned v ) { return (v & (v-1)) == 0; }
by MostAwesomeDude 15y ago
And fast; Mesa uses this.
static INLINE boolean
util_is_power_of_two( unsigned v )
{
return (v & (v-1)) == 0;
}
- ColinWright 15y agoReturns True when v==0, and yet 0 is not a power of 2. Further, this technique - correctly applied - is essentially #9 in the list.
- vog 15y agoAccording to the C spec, this is expression is undefined for v == 0. So it might return true, or return false, or start NetHack, or wipe your disk. In other words: Strictly speaken, that function is not allowed to be called for v == 0.
- MostAwesomeDude 15y agoMesa is a GL renderer. POT only matters in 3D for things like texture sizes. Textures aren't allowed to have zero-sized dimensions. The check for v == 0 occurs far higher up the stack than where this function's used. We're not writing bad code, we promise. :3