public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Raphael M Zinsly <rzinsly@linux.ibm.com>
To: Matheus Castanho <msc@linux.ibm.com>, libc-alpha@sourceware.org
Subject: Re: [PATCH v2] powerpc: Add optimized strlen for POWER10
Date: Thu, 22 Apr 2021 12:22:47 -0300	[thread overview]
Message-ID: <3a3e48a5-1083-dcf3-bcc2-32350fa4d20a@linux.ibm.com> (raw)
In-Reply-To: <20210422122911.27758-1-msc@linux.ibm.com>

Hi Matheus, the patch LGTM with some trivial changes.

On 22/04/2021 09:29, Matheus Castanho via Libc-alpha wrote:
> diff --git a/sysdeps/powerpc/powerpc64/le/power10/strlen.S b/sysdeps/powerpc/powerpc64/le/power10/strlen.S
> new file mode 100644
> index 0000000000..7eb37a8f54
> --- /dev/null
> +++ b/sysdeps/powerpc/powerpc64/le/power10/strlen.S
> @@ -0,0 +1,221 @@
> +/* Optimized strlen implementation for POWER10 LE.
> +   Copyright (C) 2021 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <https://www.gnu.org/licenses/>.  */
> +
> +#include <sysdep.h>
> +
> +#ifndef STRLEN
> +# define STRLEN __strlen
> +# define DEFINE_STRLEN_HIDDEN_DEF 1
> +#endif
> +
> +/* TODO: Replace macros by the actual instructions when minimum binutils becomes
> +   >= 2.35.  This is used to keep compatibility with older versions.  */
> +#define VEXTRACTBM(rt,vrb)	 \
> +	.long(((4)<<(32-6))	 \
> +	      | ((rt)<<(32-11))	 \
> +	      | ((8)<<(32-16))	 \
> +	      | ((vrb)<<(32-21)) \
> +	      | 1602)
> +
> +#define LXVP(xtp,dq,ra)		   \
> +	.long(((6)<<(32-6))		   \
> +	      | ((((xtp)-32)>>1)<<(32-10)) \
> +	      | ((1)<<(32-11))		   \
> +	      | ((ra)<<(32-16))		   \
> +	      | dq)
> +
> +#define CHECK16(vreg,offset,addr,label) \
> +	lxv	  vreg+32,offset(addr);	\
> +	vcmpequb. vreg,vreg,v18;	\
> +	bne	  cr6,L(label);
> +
> +/* Load 4 quadwords, merge into one VR for speed and check for NULLs.  r6 has #
> +   of bytes already checked.  */
> +#define CHECK64(offset,addr,label)	    \
> +	li	  r6,offset;		    \
> +	LXVP(v4+32,offset,addr);	    \
> +	LXVP(v6+32,offset+32,addr);	    \
> +	vminub	  v14,v4,v5;		    \
> +	vminub	  v15,v6,v7;		    \
> +	vminub	  v16,v14,v15;		    \
> +	vcmpequb. v0,v16,v18;		    \
> +	bne	  cr6,L(label)
> +
> +# define TAIL(vreg,increment)	   \

nit: the space before define is not needed.

> +	vctzlsbb  r4,vreg;	   \
> +	subf	  r3,r3,r5;	   \
> +	addi	  r4,r4,increment; \
> +	add	  r3,r3,r4;	   \
> +	blr
> +
> +/* Implements the function
> +
> +   int [r3] strlen (const void *s [r3])
> +
> +   The implementation can load bytes past a matching byte, but only
> +   up to the next 64B boundary, so it never crosses a page.  */
> +
> +.machine power9
> +
> +ENTRY_TOCLESS (STRLEN, 4)
> +	CALL_MCOUNT 1
> +
> +	vspltisb  v18,0
> +	vspltisb  v19,-1
> +
> +	/* Next 16B-aligned address. Prepare address for L(aligned).  */
> +	addi	  r5,r3,16
> +	clrrdi	  r5,r5,4
> +
> +	/* Align data and fill bytes not loaded with non matching char.	 */
> +	lvx	  v0,0,r3
> +	lvsr	  v1,0,r3
> +	vperm	  v0,v19,v0,v1
> +
> +	vcmpequb. v6,v0,v18
> +	beq	  cr6,L(aligned)
> +
> +	vctzlsbb  r3,v6
> +	blr
> +
> +	/* Test more 112B, 16B at a time.  The main loop is optimized for longer

s/112B/176B/

> +	   strings, so checking the first bytes in 16B chunks benefits a lot
> +	   small strings.  */
> +	.p2align 5
> +L(aligned):

-- 
Raphael Moreira Zinsly

  reply	other threads:[~2021-04-22 15:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-22 12:29 Matheus Castanho
2021-04-22 15:22 ` Raphael M Zinsly [this message]
2021-04-22 18:20 ` Lucas A. M. Magalhaes
2021-04-22 19:50 ` Matheus Castanho

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=3a3e48a5-1083-dcf3-bcc2-32350fa4d20a@linux.ibm.com \
    --to=rzinsly@linux.ibm.com \
    --cc=libc-alpha@sourceware.org \
    --cc=msc@linux.ibm.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 read-only IMAP folder(s) and NNTP newsgroup(s).