From patchwork Wed Feb 6 14:58:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 157624 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6507269jaa; Wed, 6 Feb 2019 06:59:33 -0800 (PST) X-Google-Smtp-Source: AHgI3IaKXEmOfvLbskSCD5Tm5mR3juph/cQyZIwolPVrVER2oP6D7VG8U+1tzmvsNH2RMsOLwAmL X-Received: by 2002:a17:902:848f:: with SMTP id c15mr10759155plo.119.1549465173919; Wed, 06 Feb 2019 06:59:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549465173; cv=none; d=google.com; s=arc-20160816; b=gZ+h/tuDH7bwmb/vzv7bLoXetgbquZpJRzKd1fgrWaPqTTcxonpW2kM8BYkK9SDS0g T5wK3w1Bti/xAjE90ONzwGW9QmCXio88ACwm5dy42xPbBT5RfM97HdkKB9EfqnlcyyIN u1uT0pCTyhNgQa8r6ig7+NrKdkWEQtf/LCDZE5PHS61b7XPQZT+8AJLqa6VcenQ+gfzv jMN8RAvGnxca1IUUfh50foTkSB/GOnvCW4kJ5bCaoIbNuoke4Wq7mn7TeiHxqPLeRinX oAhQg5p1gXkH3k41hQYX1w/r19YgvOCExi7KKtPCG9xZz14HPIp9PSQmXAtWwN3+8BLX GJVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-subscribe:list-unsubscribe:list-id:precedence:mailing-list :dkim-signature:domainkey-signature; bh=YEHjSRylSKspwtxkcOpFJheWVJKuV/aAHF8ak+CM49g=; b=h4UgA4jOZAcNpQBTKYDBbv+y/N9DLXeNDTWu2JRKuXCLGP5F2BZOcAcJeB2jp1ZpDH fEwOeoJaJ6Tv7rVFihq/oHCeJ1f/Iyito2+azTxhwFw0Z/jnb54eYAzxx60RLNKAb97j WhqL8ljH1IrvWvFAQXF4g/pmCCyy/37R+94jYcYCIou+huCM4o1zqUcBL8QqO9ZsJ0YF pdiK59QvHJlt57AnO7p4yaxkrwwjFmgF5Csw+jeWXoTI6Ijri1WB0nwSq83/+mkv7aDT 4BZm2irwYJYzAm4bQL9uwJ8fHf3iyTW5W1oSdLykXgzkEW6hQ+3G5UZDnliaVEvtYBJr /H2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=q0gSkTIA; dkim=pass header.i=@linaro.org header.s=google header.b=HIKwtIX9; spf=pass (google.com: domain of libc-alpha-return-99818-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99818-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id t17si4005087pfh.267.2019.02.06.06.59.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 06:59:33 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-99818-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=q0gSkTIA; dkim=pass header.i=@linaro.org header.s=google header.b=HIKwtIX9; spf=pass (google.com: domain of libc-alpha-return-99818-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99818-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=O2Hcbd2KK22X7yQw8abFM5J761iBWpP ppBNcgys0XCW8CsaicfxfG+sZh1dz3+Z02yMnFUCLpoO2D1VSpA8XYJf9VuUZukk BR6bf4zHh6wTDwOvRazN0b/smOj/+wtRelkxh67SRWzNksFCwS+FpNhzN3WZFR5L L3pdPuVLSrhA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=DvuZ9SAGfysdW+nuQqZ8Y+u5juc=; b=q0gSk TIAAFPeRyI786luzrmTUOHWLwmYxOokoYEWCb1WuROb0hV3ZNrPHfqcWHSgshe1w 75/tEtlyNvcLJFmv3lsYx6of9/R6rFkqbqf4kL7qOWO/C6OnvbWFIOD61AvhPwK3 WVjAXITL3OJZ418iOfI/qkUON02fAvlSWxTxQM= Received: (qmail 109551 invoked by alias); 6 Feb 2019 14:59:02 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 109451 invoked by uid 89); 6 Feb 2019 14:59:02 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=1620 X-HELO: mail-qt1-f195.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=YEHjSRylSKspwtxkcOpFJheWVJKuV/aAHF8ak+CM49g=; b=HIKwtIX9Y+8Q3ZxW0EYgpz6YYGlX/qeYebnA9vpQ7g1NZR9axARULVETrupcIw1jYx 1sp4AQ2OHKkHtprwZLxkwFSKMs58GAdEkIB+ra8QAazP0d1gnq1dsBcnWrHkvDc27Egf abwII+9RJ9CX44hAReHhchxHyF0ty3SHb3L/Vu8W8loFtQ7yAMDpW3DNOWxtjvcVovFN z0U0EOPpWoZe9d1/q/Po/q65awU8yjUMVW6LnJ4TNJNPYIhyFPJz5tz5rq334WSHEGrN 115gFsCyOoJbyIxv1Obt8dh31EMIH9ZPDzsmUF4hks5CRytJzpGTe6lGudm0G2V7xOcc 8feQ== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 3/7] wcsmbs: optimize wcscat Date: Wed, 6 Feb 2019 12:58:46 -0200 Message-Id: <20190206145850.22003-3-adhemerval.zanella@linaro.org> In-Reply-To: <20190206145850.22003-1-adhemerval.zanella@linaro.org> References: <20190206145850.22003-1-adhemerval.zanella@linaro.org> This patch rewrites wcscat using wcslen and wcscpy. This is similar to the optimization done on strcat by 6e46de42fe. The strcpy changes are mainly to add the internal alias to avoid PLT calls. Checked on x86_64-linux-gnu and a build against the affected architectures. * include/wchar.h (__wcscpy): New prototype. * sysdeps/powerpc/powerpc32/power4/multiarch/wcscpy-ppc32.c (__wcscpy): Route internal symbol to generic implementation. * sysdeps/powerpc/powerpc32/power4/multiarch/wcscpy.c (wcscpy): Add internal __wcscpy alias. * sysdeps/powerpc/powerpc64/multiarch/wcscpy.c (wcscpy): Likewise. * sysdeps/s390/wcscpy.c (wcscpy): Likewise. * sysdeps/x86_64/multiarch/wcscpy.c (wcscpy): Likewise. * wcsmbs/wcscpy.c (wcscpy): Add * sysdeps/x86_64/multiarch/wcscpy-c.c (WCSCPY): Adjust macro to use generic implementation. * wcsmbs/wcscat.c (wcscat): Rewrite using wcslen and wcscpy. --- include/wchar.h | 4 +++ .../powerpc32/power4/multiarch/wcscpy-ppc32.c | 9 ++++--- .../powerpc32/power4/multiarch/wcscpy.c | 13 ++++------ sysdeps/powerpc/powerpc64/multiarch/wcscpy.c | 25 +++++++++---------- sysdeps/s390/wcscpy.c | 4 ++- sysdeps/x86_64/multiarch/wcscpy-c.c | 4 +-- sysdeps/x86_64/multiarch/wcscpy.c | 11 +++++--- wcsmbs/wcscat.c | 21 +--------------- wcsmbs/wcscpy.c | 10 +++++--- 9 files changed, 47 insertions(+), 54 deletions(-) -- 2.17.1 diff --git a/include/wchar.h b/include/wchar.h index 614073bcb3..2cb44954fc 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -182,6 +182,10 @@ extern size_t __wcsnrtombs (char *__restrict __dst, size_t __nwc, size_t __len, __mbstate_t *__restrict __ps) attribute_hidden; +extern wchar_t *__wcscpy (wchar_t *__restrict __dest, + const wchar_t *__restrict __src) + attribute_hidden __nonnull ((1, 2)); +libc_hidden_proto (__wcscpy) extern wchar_t *__wcsncpy (wchar_t *__restrict __dest, const wchar_t *__restrict __src, size_t __n); extern wchar_t *__wcpcpy (wchar_t *__dest, const wchar_t *__src); diff --git a/sysdeps/powerpc/powerpc32/power4/multiarch/wcscpy-ppc32.c b/sysdeps/powerpc/powerpc32/power4/multiarch/wcscpy-ppc32.c index 52b692b47b..31e0d81ef0 100644 --- a/sysdeps/powerpc/powerpc32/power4/multiarch/wcscpy-ppc32.c +++ b/sysdeps/powerpc/powerpc32/power4/multiarch/wcscpy-ppc32.c @@ -17,10 +17,11 @@ #include -#if IS_IN (libc) -# define WCSCPY __wcscpy_ppc -#endif - extern __typeof (wcscpy) __wcscpy_ppc; +#define WCSCPY __wcscpy_ppc #include + +#ifdef SHARED +__hidden_ver1 (__wcscpy_ppc, __GI___wcscpy, __wcscpy_ppc); +#endif diff --git a/sysdeps/powerpc/powerpc32/power4/multiarch/wcscpy.c b/sysdeps/powerpc/powerpc32/power4/multiarch/wcscpy.c index ecca37d5d6..eb95c856bd 100644 --- a/sysdeps/powerpc/powerpc32/power4/multiarch/wcscpy.c +++ b/sysdeps/powerpc/powerpc32/power4/multiarch/wcscpy.c @@ -16,21 +16,18 @@ License along with the GNU C Library; if not, see . */ -#if IS_IN (libc) -# include -# include -# include "init-arch.h" +#include +#include +#include "init-arch.h" extern __typeof (wcscpy) __wcscpy_ppc attribute_hidden; extern __typeof (wcscpy) __wcscpy_power6 attribute_hidden; extern __typeof (wcscpy) __wcscpy_power7 attribute_hidden; -libc_ifunc (wcscpy, +libc_ifunc (__wcscpy, (hwcap & PPC_FEATURE_HAS_VSX) ? __wcscpy_power7 : (hwcap & PPC_FEATURE_ARCH_2_05) ? __wcscpy_power6 : __wcscpy_ppc); -#else -#include -#endif +weak_alias (__wcscpy, wcscpy) diff --git a/sysdeps/powerpc/powerpc64/multiarch/wcscpy.c b/sysdeps/powerpc/powerpc64/multiarch/wcscpy.c index 3cea9a489d..3f918b27c6 100644 --- a/sysdeps/powerpc/powerpc64/multiarch/wcscpy.c +++ b/sysdeps/powerpc/powerpc64/multiarch/wcscpy.c @@ -16,21 +16,20 @@ License along with the GNU C Library; if not, see . */ -#if IS_IN (libc) -# include -# include -# include "init-arch.h" +#define __wcscpy __redirect___wcscpy +#include +#undef __wcscpy +#include +#include "init-arch.h" extern __typeof (wcscpy) __wcscpy_ppc attribute_hidden; extern __typeof (wcscpy) __wcscpy_power6 attribute_hidden; extern __typeof (wcscpy) __wcscpy_power7 attribute_hidden; -libc_ifunc (wcscpy, - (hwcap & PPC_FEATURE_HAS_VSX) - ? __wcscpy_power7 : - (hwcap & PPC_FEATURE_ARCH_2_05) - ? __wcscpy_power6 - : __wcscpy_ppc); -#else -#include -#endif +libc_ifunc_redirected (__redirect___wcscpy, __wcscpy, + (hwcap & PPC_FEATURE_HAS_VSX) + ? __wcscpy_power7 : + (hwcap & PPC_FEATURE_ARCH_2_05) + ? __wcscpy_power6 + : __wcscpy_ppc); +weak_alias (__wcscpy, wcscpy) diff --git a/sysdeps/s390/wcscpy.c b/sysdeps/s390/wcscpy.c index 2e8ef5024f..a569f917af 100644 --- a/sysdeps/s390/wcscpy.c +++ b/sysdeps/s390/wcscpy.c @@ -30,9 +30,11 @@ extern __typeof (wcscpy) WCSCPY_C attribute_hidden; extern __typeof (wcscpy) WCSCPY_Z13 attribute_hidden; # endif -s390_libc_ifunc_expr (wcscpy, wcscpy, +s390_libc_ifunc_expr (wcscpy, __wcscpy, (HAVE_WCSCPY_Z13 && (hwcap & HWCAP_S390_VX)) ? WCSCPY_Z13 : WCSCPY_DEFAULT ) +weak_alias (__wcscpy, wcscpy) +libc_hidden_def (__wcscpy) #endif diff --git a/sysdeps/x86_64/multiarch/wcscpy-c.c b/sysdeps/x86_64/multiarch/wcscpy-c.c index a51a83a9be..26d6984e9b 100644 --- a/sysdeps/x86_64/multiarch/wcscpy-c.c +++ b/sysdeps/x86_64/multiarch/wcscpy-c.c @@ -1,5 +1,5 @@ #if IS_IN (libc) -# define wcscpy __wcscpy_sse2 +# define WCSCPY __wcscpy_sse2 #endif -#include "wcsmbs/wcscpy.c" +#include diff --git a/sysdeps/x86_64/multiarch/wcscpy.c b/sysdeps/x86_64/multiarch/wcscpy.c index 101a585358..96151b4963 100644 --- a/sysdeps/x86_64/multiarch/wcscpy.c +++ b/sysdeps/x86_64/multiarch/wcscpy.c @@ -19,9 +19,9 @@ /* Define multiple versions only for the definition in libc. */ #if IS_IN (libc) -# define wcscpy __redirect_wcscpy +# define __wcscpy __redirect_wcscpy # include -# undef wcscpy +# undef __wcscpy # define SYMBOL_NAME wcscpy # include @@ -40,5 +40,10 @@ IFUNC_SELECTOR (void) return OPTIMIZE (sse2); } -libc_ifunc_redirected (__redirect_wcscpy, wcscpy, IFUNC_SELECTOR ()); +libc_ifunc_redirected (__redirect_wcscpy, __wcscpy, IFUNC_SELECTOR ()); +weak_alias (__wcscpy, wcscpy) +# ifdef SHARED +__hidden_ver1 (__wcscpy, __GI___wcscpy, __redirect_wcscpy) + __attribute__((visibility ("hidden"))) __attribute_copy__ (wcscpy); +# endif #endif diff --git a/wcsmbs/wcscat.c b/wcsmbs/wcscat.c index 6a25b20e31..1a9d667fda 100644 --- a/wcsmbs/wcscat.c +++ b/wcsmbs/wcscat.c @@ -26,26 +26,7 @@ wchar_t * __wcscat (wchar_t *dest, const wchar_t *src) { - wchar_t *s1 = dest; - const wchar_t *s2 = src; - wchar_t c; - - /* Find the end of the string. */ - do - c = *s1++; - while (c != L'\0'); - - /* Make S1 point before the next character, so we can increment - it while memory is read (wins on pipelined cpus). */ - s1 -= 2; - - do - { - c = *s2++; - *++s1 = c; - } - while (c != L'\0'); - + __wcscpy (dest + __wcslen (dest), src); return dest; } #ifndef WCSCAT diff --git a/wcsmbs/wcscpy.c b/wcsmbs/wcscpy.c index 7a34c77a9e..636bf6bd01 100644 --- a/wcsmbs/wcscpy.c +++ b/wcsmbs/wcscpy.c @@ -20,13 +20,13 @@ #include -#ifndef WCSCPY -# define WCSCPY wcscpy +#ifdef WCSCPY +# define __wcscpy WCSCPY #endif /* Copy SRC to DEST. */ wchar_t * -WCSCPY (wchar_t *dest, const wchar_t *src) +__wcscpy (wchar_t *dest, const wchar_t *src) { wint_t c; wchar_t *wcp; @@ -58,3 +58,7 @@ WCSCPY (wchar_t *dest, const wchar_t *src) return dest; } +#ifndef WCSCPY +weak_alias (__wcscpy, wcscpy) +libc_hidden_def (__wcscpy) +#endif