Thanks Ivan
Josef Templ wrote:It is a much better formulation because it is faster for small sets ...
If speed is important replace k + 2 <= MAX(SET) by k <= MAX(SET) - 2 so the subtraction takes place once at compile time rather than several times at run time.
A cheeky optimisation might be to replace MAX(SET) by
Code: Select all
PROCEDURE [code] BitScanReverse* (set : SET) : INTEGER
0FH, 0BDH, 0C0H; (* bsr eax -> eax *)
Do this outside the loop. Don't worry that it is undefined for empty sets.
On second thoughts, what we already have is simpler!
OK - Lets lock this topic now!