diff --git a/src/gallium/frontends/rusticl/util/math.rs b/src/gallium/frontends/rusticl/util/math.rs index f6e8d96e9ae..267c288c52c 100644 --- a/src/gallium/frontends/rusticl/util/math.rs +++ b/src/gallium/frontends/rusticl/util/math.rs @@ -33,3 +33,27 @@ where val + (a - tmp) } } + +pub struct SetBitIndices { + val: T, +} + +impl SetBitIndices { + pub fn from_msb(val: T) -> Self { + Self { val: val } + } +} + +impl Iterator for SetBitIndices { + type Item = u32; + + fn next(&mut self) -> Option { + if self.val == 0 { + None + } else { + let pos = u32::BITS - self.val.leading_zeros() - 1; + self.val ^= 1 << pos; + Some(pos) + } + } +}