Re: Count Leading Zeros (cntlzw)
- From: "Avatar Zondertau" <avatarzt@xxxxxxxxx (please reply to newsgroup)>
- Date: 30 Aug 2005 00:02:08 -0700
> > 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
> >
>
> 80x86 have BSF (Bit Scan Forward) and BSR (B.S. Reverse) functions
BSR is the right one to use. I think the code should be something like
this (untested):
function Cntlzw(Value: Word): Word;
asm
bsr dx, ax
jz @Zero
mov ax, 15
sub ax, dx
@Zero:
mov ax, 16
end;
CMOV instead of the branch could provide more performance, but that may
depend on how often you get Value = 0 (and, of course, on the CPU).
.
- References:
- Count Leading Zeros (cntlzw)
- From: Kostas
- Re: Count Leading Zeros (cntlzw)
- From: vt
- Count Leading Zeros (cntlzw)
- Prev by Date: Re: Potential FastCode speed increase?
- Next by Date: Re: Potential FastCode speed increase?
- Previous by thread: Re: Count Leading Zeros (cntlzw)
- Next by thread: Re: Count Leading Zeros (cntlzw)
- Index(es):
Relevant Pages
|