Quote:Original post by FlowingOozeQuote:Original post by Nice Coder
Yep. Assuming a comparison ain't that expencive, its one of the best options.
The best option is a lut assisted binary search.
My best would be only a few comparisons. (ie. somewhere near three), and a 256 element lut.
Assume you have a 32 bit number.
First you test the first 16 bits. (jz, no cmp needed. Use the 16 bit registers)
Then if its true, then you try the first 8 bits. (another jz).
If that doesn't work, then you just use the lut on the output.
If the first 16 bits are false, then you just try the other way. (same thing, just using different registers).
i'm pretty sure an optimised asm version would be superfast.
From,
Nice coder
ARM doesn't have 16-bit subregisters. Other than that, this approach is worth trying and does actually return the MSB bit number. However one should not forget the penalty incurring from a cache miss when accessing the lut.
Though I still don't understand why anyone would need something like this when a three instruction loop does the trick in no more that 32 iterations.
Neither do i. But its a nice problem.
Also 3 instructino loop (+ overhead, your've got two instructions loop overhad, with branch mispredictions, ect. with another 4-5 in the loop itself.)
Assume you've got 7 instructions in the main loop.
7*31 = 217 instructions.
Thats pretty big. (tho nothing major unless your doing it heaps)
From,
Nice coder