From: Segher Boessenkool <segher@kernel.crashing.org>
To: Christophe Leroy <christophe.leroy@c-s.fr>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Paul Mackerras <paulus@samba.org>,
Michael Ellerman <mpe@ellerman.id.au>,
wei.guo.simon@gmail.com, linuxppc-dev@lists.ozlabs.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 3/4] powerpc/lib: implement strlen() in assembly
Date: Fri, 8 Jun 2018 09:54:23 -0500 [thread overview]
Message-ID: <20180608145423.GF17342@gate.crashing.org> (raw)
In-Reply-To: <ce98c6b8e80f85635a67093bbb59f13dae758112.1528463979.git.christophe.leroy@c-s.fr>
Hi!
On Fri, Jun 08, 2018 at 01:27:39PM +0000, Christophe Leroy wrote:
> ---
> Not tested on PPC64.
> +#ifdef CPU_LITTLE_ENDIAN
> + rldicl. r8, r9, 0, 56
> + beq 20f
> + rldicl. r8, r9, 56, 56
> + beq 21f
> + rldicl. r8, r9, 48, 56
> + beq 22f
> + rldicl. r8, r9, 40, 56
> + beq 23f
> + addi r10, r10, 4
> + rldicl. r8, r9, 32, 56
> + beq 20f
> + rldicl. r8, r9, 24, 56
> + beq 21f
> + rldicl. r8, r9, 16, 56
> + beq 22f
> + rldicl. r8, r9, 8, 56
> +#else
> +#ifdef CONFIG_PPC64
> + rldicl. r8, r9, 8, 56
> + beq 20f
> + rldicl. r8, r9, 16, 56
> + beq 21f
> + rldicl. r8, r9, 24, 56
> + beq 22f
> + rldicl. r8, r9, 32, 56
> + beq 23f
> + addi r10, r10, 4
> +#endif
> + rlwinm. r8, r9, 0, 0xff000000
> + beq 20f
> + rlwinm. r8, r9, 0, 0x00ff0000
> + beq 21f
> + rlwinm. r8, r9, 0, 0x0000ff00
> + beq 22f
> +#endif /* CPU_LITTLE_ENDIAN */
That isn't going to perform well on processors that have more than two
or so cycles penalty on a branch mispredict (i.e. all modern processors).
ISA 2.05 and later cpus (Power6 and later) can use cmpb and a single
cntlz, on BE; on LE you can use the cnttz insn on ISA 3.0 (Power9) or
later, or do add/andc/popcntd (on ISA2.06, Power7 and later) or
neg/and/cntlz/sub.
Lots of options. You can also write branchless code for this without
using any new insns (less nice of course).
Segher
next prev parent reply other threads:[~2018-06-08 14:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-08 13:27 [PATCH v5 1/4] selftests/powerpc: add test for 32 bits memcmp Christophe Leroy
2018-06-08 13:27 ` [PATCH v5 2/4] selftests/powerpc: Add test for strlen() Christophe Leroy
2018-06-08 13:27 ` [PATCH v5 3/4] powerpc/lib: implement strlen() in assembly Christophe Leroy
2018-06-08 14:54 ` Segher Boessenkool [this message]
2018-06-08 13:27 ` [PATCH v5 4/4] selftests/powerpc: update strlen() test to test the new assembly function Christophe Leroy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180608145423.GF17342@gate.crashing.org \
--to=segher@kernel.crashing.org \
--cc=benh@kernel.crashing.org \
--cc=christophe.leroy@c-s.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=paulus@samba.org \
--cc=wei.guo.simon@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).