This is a follow-up to my last question. I managed to implement a pretty fast "bit queue builder" as
data BitQueueB = BQB !Word !Word
by pushing elements in from the left (starting with a guard bit), then when I'm done "building" the queue, counting the trailing zeros and shifting them off, installing a new guard bit on the left.
However, this solution doesn't really do anything for GHC < 7.10, since that's when countTrailingZeros
was introduced. I also can't help wondering if there's some more magical way to accomplish this shift, or is leftward counterpart.
The point
I have a two-word representation of a double word, guaranteed to have at least one bit set. I'm looking for the fastest way to shift the double word to either the left or the right until the first set bit is shifted off, without using either countLeadingZeros
or countTrailingZeros
.
One thought
My poor intuition in these matters suggests that if there could be some way to use multiplication if I switch to shifting left, but maybe that's just wishful thinking.