best method to extract and compare single bits?
Jimmy W.
Posts: 112
What is everyone using to extract single bits from longs? I know they were some talks of using ctrb and whatnot, I am currently unhappy with the way I have been doing it for a while now, shift left till the bit is MSB then right shift it to LSB then compare against 1, it is a very inefficient process and I am looking to squeeze a bit more speed out of these comparisons.
Forgot to mention, this is in spin, thanks!
Thanks, and happy 4th!
Jimmy
Post Edited (Jimmy W.) : 7/5/2008 2:54:48 AM GMT
Forgot to mention, this is in spin, thanks!
Thanks, and happy 4th!
Jimmy
Post Edited (Jimmy W.) : 7/5/2008 2:54:48 AM GMT
Comments
The test instruction is simply an and that doesn't write the result.
or
Don't know which is quicker. If it was always the same value you could use a precalculated value instead which may speed things up. If speed is marginal there are a couple of things you can do such as making sure the two variables are in either the first 8 object variables or the the first 7 method variables. Also, if possible keep any constants small so that they will fit in a byte or word rather than a long which will also make it slightly faster (there's three less hub accesses needed for a byte than a long constant in spin).