bsr-algorithm?



Hy;

I saw the discussion about the popcnt, and it reminded me of my own
search of a solution to this function:

/* first-bit position */
static int __fastcall fbpos(short int e) {
__asm {
/* handle '0'-case */
__asm xor eax, eax
__asm dec ax
__asm bsr ax, cx
};
}

but in MMX/XMMX.
I didn't find any slight dicussion of 'emulating' lzcnt or bsr at all,
and the solutions I could think of are very unsmart and probably
slower than sequencially transfering the data into GPRs and do the bsr
there.
I think on AltiVec helps the permutation-op, that we don't have on
x86.

Anybody got an idea about a branch-free 'emulation' of bsr?

Ciao
Niels

.



Relevant Pages

  • Re: bsr-algorithm?
    ... static int __fastcall fbpos{ ... I didn't find any slight dicussion of 'emulating' lzcnt or bsr at all, ... Getting the most significant bit is easy in SSE, as long as you don't need to work with integers larger than 2^24, or can stand the overhead of converting to double first: ... If you have to handle zero, then you'll have to add a compare against zero either before or after the conversion, then use that as a mask to POR on top of the regular result, so that you'll return -1 for zero inputs. ...
    (comp.lang.asm.x86)
  • Re: Binary Log Routine
    ... spamtrap@xxxxxxxxxx "DanCam " writes: ... it includes BSR, you sure that's not a 286+ command, but if it does, that is ... from the same era and has useful info on asm as well as other DOS ...
    (comp.lang.asm.x86)