Wrap around by bit masking
Posted: Fri Jan 15, 2021 12:13 pm
Frustration after endless googling, and not finding the answer I need (or maybe I'm just being layzeee ..!)
I have stored waves of length 1024, or 512, or 128, or 64, and I have index counters. If I apply phase modulation to the index counters (aka 'FM') the index can then overrun or underrun, and to date I've been using ASM code derived from the % (modulo) function to sort out the required wrap arounds and restrain the number range. No problem as such, works OK.
But it has recently dawned on me that since my wavelengths are always these neat binary numbers I could probably just use a bit mask to AND with the counters and get the same result, by simply masking the higher bits, no?
However (pseudo code) ...
movaps xmm0, counter;
andps xmm0, waveLength;
... obviously doesn't work, because even I know that 128 in binary is 10000000, so is definitely not the mask I need!
How do I generate a floating point mask to remove bits higher than 128, or bits higher than 512 etc.?
Grateful for any guidance.
H
I have stored waves of length 1024, or 512, or 128, or 64, and I have index counters. If I apply phase modulation to the index counters (aka 'FM') the index can then overrun or underrun, and to date I've been using ASM code derived from the % (modulo) function to sort out the required wrap arounds and restrain the number range. No problem as such, works OK.
But it has recently dawned on me that since my wavelengths are always these neat binary numbers I could probably just use a bit mask to AND with the counters and get the same result, by simply masking the higher bits, no?
However (pseudo code) ...
movaps xmm0, counter;
andps xmm0, waveLength;
... obviously doesn't work, because even I know that 128 in binary is 10000000, so is definitely not the mask I need!
How do I generate a floating point mask to remove bits higher than 128, or bits higher than 512 etc.?
Grateful for any guidance.
H