Re: [PATCH v4 3/4] powerpc/lib: implement strlen() in assembly

From: Segher Boessenkool
Date: Fri Jun 08 2018 - 08:07:00 EST


On Fri, Jun 08, 2018 at 01:45:13PM +0200, Gabriel Paubert wrote:
> On Fri, Jun 08, 2018 at 10:20:41AM +0000, Christophe Leroy wrote:
> > + rlwinm. r8, r9, 0, 0xff000000
> > + beq 20f
> > + rlwinm. r8, r9, 0, 0x00ff0000
> > + beq 21f
> > + rlwinm. r8, r9, 0, 0x0000ff00
> > + beq 22f
> > +23: subf r3, r3, r10
>
> Actually these rlwinm. can likely be replaced by a single
> cntlzw /cntlzd; for 32 bit something like:
>
> cntlzw r8,r9
> subf r3,r3,r10
> srwi r8,r8,3
> add r3,r3,r8
> blr

The code is finding the first zero byte in the word, not how many leading
zero bytes there are.


Segher