Fast way of checking block for non-zero in SPIN
MacTuxLin
Posts: 821
Kinda having a brain-freeze now. Is there a way to && %111...111 (long) and left shift to see if a long contains a bit in SPIN? Needed to quickly check a block of 3,074 longs for any bit set.
Thanks
Thanks

Comments
If you have a spare cog, you could use a short assembly routine that is running all the time, waiting for its shared memory long to get cleared to zero, then it scans the block and sets the shared long to the address of the first non-zero long found (and even the first bit number in the high order word of the long), then goes back to wait for the shared long to be cleared.
pub bit_pos(value, mode) '' Returns position of 1st "1" bit '' -- mode 0 (LSBFIRST) to scan from lsb, mode 1 (MSBFIRST) to scan from msb '' -- -1 = no bits set if (value == 0) ' if no bits return -1 ' return -1 else if (mode == LSBFIRST) ' check from LSB value ><= 32 ' flip for >| return (32 - >|value) else return (>|value - 1)Thanks Jon. Cool, I'll give this a shot & if it is still not fast enough, I'll change my code to make way for a spare cog for PASM.
Thanks