From patchwork Thu May 14 11:49:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Blanchard X-Patchwork-Id: 39246 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 35DF5395C83F; Thu, 14 May 2020 11:49:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 35DF5395C83F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1589456965; bh=9rlOUhcFMQpu5Y7TLwchfN5p5et2gVhyYtoZT+Yc+HU=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=MfGaCs2iywo3Q+F+ygnsyUOpl3vsanqiMU2BqExrd2CHHw81/+oF2ovvoi8aUvD+c +mB4J5nDTQfbUp98caR4td7a5RdZ/qXCGbjbLl2J6Le9r4G/ibE7GW9QnSq+9Ey0US TFkMUeJumr2uojZMDX8C8YmWSVqu69/aCXREImgs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from ozlabs.org (ozlabs.org [203.11.71.1]) by sourceware.org (Postfix) with ESMTPS id EC2B1395BC26 for ; Thu, 14 May 2020 11:49:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EC2B1395BC26 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 49N8vy3b9Pz9sTL; Thu, 14 May 2020 21:49:18 +1000 (AEST) Date: Thu, 14 May 2020 21:49:16 +1000 To: libc-alpha@sourceware.org Subject: [PATCH] powerpc: Optimized rawmemchr for POWER9 Message-ID: <20200514214916.5eb363bd@kryten.localdomain> X-Mailer: Mutt/1.8.0 (2017-02-23) MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Anton Blanchard via Libc-alpha From: Anton Blanchard Reply-To: Anton Blanchard Cc: Raphael M Zinsly Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" This version uses vector instructions and is up to 60% faster on medium matches and up to 90% faster on long matches, compared to the POWER7 version. A few examples: __rawmemchr_power9 __rawmemchr_power7 Length 32, alignment 0: 2.27566 3.77765 Length 64, alignment 2: 2.46231 3.51064 Length 1024, alignment 0: 17.3059 32.6678 --- .../powerpc/powerpc64/le/power9/rawmemchr.S | 107 ++++++++++++++++++ sysdeps/powerpc/powerpc64/multiarch/Makefile | 2 +- .../powerpc64/multiarch/ifunc-impl-list.c | 5 + .../powerpc64/multiarch/rawmemchr-power9.S | 21 ++++ .../powerpc/powerpc64/multiarch/rawmemchr.c | 12 +- 5 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 sysdeps/powerpc/powerpc64/le/power9/rawmemchr.S create mode 100644 sysdeps/powerpc/powerpc64/multiarch/rawmemchr-power9.S diff --git a/sysdeps/powerpc/powerpc64/le/power9/rawmemchr.S b/sysdeps/powerpc/powerpc64/le/power9/rawmemchr.S new file mode 100644 index 0000000000..9d0276c931 --- /dev/null +++ b/sysdeps/powerpc/powerpc64/le/power9/rawmemchr.S @@ -0,0 +1,107 @@ +/* Optimized rawmemchr implementation for PowerPC64/POWER9. + Copyright (C) 2020 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 + . */ + +#include + +#ifndef RAWMEMCHR +# define RAWMEMCHR __rawmemchr +#endif + +/* Implements the function + + int [r3] rawmemchr (void *s [r3], int c [r4]) + + The implementation can load bytes past a matching byte, but only + up to the next 16B boundary, so it never crosses a page. */ + +.machine power9 +ENTRY_TOCLESS (RAWMEMCHR, 4) + CALL_MCOUNT 2 + + xori r5,r4,0xff + + mtvsrd v18+32,r4 /* matching char in v18 */ + mtvsrd v19+32,r5 /* non matching char in v19 */ + + vspltb v18,v18,7 /* replicate */ + vspltb v19,v19,7 /* replicate */ + + neg r5,r3 + rldicl r9,r5,0,60 /* How many bytes to get source 16B aligned? */ + + /* 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 /* 0xff if byte matches, 0x00 otherwise */ + beq cr6,L(aligned) + + vctzlsbb r0,v6 + add r3,r3,r0 + blr + +L(aligned): + add r3,r3,r9 + +L(loop): + lxv v0+32,0(r3) + vcmpequb. v6,v0,v18 /* 0xff if byte matches, 0x00 otherwise */ + bne cr6,L(tail1) + + lxv v0+32,16(r3) + vcmpequb. v6,v0,v18 /* 0xff if byte matches, 0x00 otherwise */ + bne cr6,L(tail2) + + lxv v0+32,32(r3) + vcmpequb. v6,v0,v18 /* 0xff if byte matches, 0x00 otherwise */ + bne cr6,L(tail3) + + lxv v0+32,48(r3) + vcmpequb. v6,v0,v18 /* 0xff if byte matches, 0x00 otherwise */ + bne cr6,L(tail4) + + addi r3,r3,64 + b L(loop) + +L(tail1): + vctzlsbb r0,v6 + add r3,r3,r0 + blr + +L(tail2): + vctzlsbb r0,v6 + add r3,r3,r0 + addi r3,r3,16 + blr + +L(tail3): + vctzlsbb r0,v6 + add r3,r3,r0 + addi r3,r3,32 + blr + +L(tail4): + vctzlsbb r0,v6 + add r3,r3,r0 + addi r3,r3,48 + blr + +END (RAWMEMCHR) +weak_alias (__rawmemchr,rawmemchr) +libc_hidden_builtin_def (__rawmemchr) diff --git a/sysdeps/powerpc/powerpc64/multiarch/Makefile b/sysdeps/powerpc/powerpc64/multiarch/Makefile index ea936bf9ed..3b04512f1d 100644 --- a/sysdeps/powerpc/powerpc64/multiarch/Makefile +++ b/sysdeps/powerpc/powerpc64/multiarch/Makefile @@ -32,7 +32,7 @@ sysdep_routines += memcpy-power8-cached memcpy-power7 memcpy-a2 memcpy-power6 \ strncase-power8 ifneq (,$(filter %le,$(config-machine))) -sysdep_routines += strcmp-power9 strncmp-power9 +sysdep_routines += strcmp-power9 strncmp-power9 rawmemchr-power9 endif CFLAGS-strncase-power7.c += -mcpu=power7 -funroll-loops CFLAGS-strncase_l-power7.c += -mcpu=power7 -funroll-loops diff --git a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c index b9fef3f43c..386bb6936c 100644 --- a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c +++ b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c @@ -208,6 +208,11 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, /* Support sysdeps/powerpc/powerpc64/multiarch/rawmemchr.c. */ IFUNC_IMPL (i, name, rawmemchr, +#ifdef __LITTLE_ENDIAN__ + IFUNC_IMPL_ADD (array, i, rawmemchr, + hwcap2 & PPC_FEATURE2_ARCH_3_00, + __rawmemchr_power9) +#endif IFUNC_IMPL_ADD (array, i, rawmemchr, hwcap & PPC_FEATURE_HAS_VSX, __rawmemchr_power7) diff --git a/sysdeps/powerpc/powerpc64/multiarch/rawmemchr-power9.S b/sysdeps/powerpc/powerpc64/multiarch/rawmemchr-power9.S new file mode 100644 index 0000000000..bac0a9090e --- /dev/null +++ b/sysdeps/powerpc/powerpc64/multiarch/rawmemchr-power9.S @@ -0,0 +1,21 @@ +/* Optimized rawmemchr implementation for PowerPC64/POWER9. + Copyright (C) 2020 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 + . */ + +#define RAWMEMCHR __rawmemchr_power9 + +#include diff --git a/sysdeps/powerpc/powerpc64/multiarch/rawmemchr.c b/sysdeps/powerpc/powerpc64/multiarch/rawmemchr.c index 847157e5f0..c49c0c51ff 100644 --- a/sysdeps/powerpc/powerpc64/multiarch/rawmemchr.c +++ b/sysdeps/powerpc/powerpc64/multiarch/rawmemchr.c @@ -24,13 +24,21 @@ extern __typeof (__rawmemchr) __rawmemchr_ppc attribute_hidden; extern __typeof (__rawmemchr) __rawmemchr_power7 attribute_hidden; +# ifdef __LITTLE_ENDIAN__ +extern __typeof (__rawmemchr) __rawmemchr_power9 attribute_hidden; +# endif + # undef __rawmemchr /* Avoid DWARF definition DIE on ifunc symbol so that GDB can handle ifunc symbol properly. */ libc_ifunc_redirected (__redirect___rawmemchr, __rawmemchr, - (hwcap & PPC_FEATURE_HAS_VSX) - ? __rawmemchr_power7 +# ifdef __LITTLE_ENDIAN__ + (hwcap2 & PPC_FEATURE2_ARCH_3_00) + ? __rawmemchr_power9 : +# endif + (hwcap & PPC_FEATURE_HAS_VSX) + ? __rawmemchr_power7 : __rawmemchr_ppc); weak_alias (__rawmemchr, rawmemchr)