Re: Count Leading Zeros (cntlzw)



Kostas wrote:
I wanted to use this function -which is part of the PowerPC assembly
language- in a x86 architecture (prefered an Athlon).
This function calculates the leading zeros of a word.
I need this function to be really fast, so i thought to ask the basm group
:)

How should it be best implemented in order to be best optimised?

Thanks in advance
Kostas


My proposal

function cntlzw(const x: word): word;
asm
  cmp  AX, 0
  jnz  @@BSF
  mov  AX, 16
  ret

@@BSF:
  mov  cx,15
  bsr  ax,ax
  sub  cx,ax
  mov  ax,cx
end;

Regards
Lars G
.



Relevant Pages