From patchwork Wed Feb 6 14:58:44 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: 1037583 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-99815-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="vr7gCb6P"; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="VGccabcc"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43vl2d2Y1Vz9sLw for ; Thu, 7 Feb 2019 01:59:05 +1100 (AEDT) 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; q=dns; s= default; b=U16XyaDm8F/t9J6uc/GWGZvWOPGNNvumgwPyMmPkQMS9Qfcz8WhRm OJDRtXTy7pvMa7rtR2YZo2hsF69MiB+jlcTuZD/UX1ZKOSNqhKEy2km63XrGnHEL MmHo3b4P4JwbI52i9/IRJSDMI0L7JL8QkG0iIWwvavtxvFhnjW5K/g= 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; s=default; bh=uy+AD5J7sb4PCJ1WGVIO5zY8jrM=; b=vr7gCb6PYoFgMQN1klP4av/laUw2 I0gwWO/JjK9SEwKRR6YCUbK4ooe2K3Uzn1z3Fbca+9PMUdMdWJzVP7Nem0M36sOY 8NngK6zS5rbTQxKXT0pKYwT+ZULiMDxsCr21bSDHn9TS9034xWL6c5lQ7yzGCGei X1WWSJSlEFLO7rg= Received: (qmail 108897 invoked by alias); 6 Feb 2019 14:58:58 -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 108830 invoked by uid 89); 6 Feb 2019 14:58:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=drepper, 2920 X-HELO: mail-qt1-f194.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id; bh=lZba5FDsuN1vVFJD5XEauVSuUioz3geYJbfKqOGpteY=; b=VGccabcc+QsdYXhQGQI1igMBRUGgvJ7QmMWPpGB6Yuwc/LytEubdk5dFMXV5dHKA6t v8bkM++jXEYF9dHy9JuDZxpwCrEGRnHi+Jd+9zYUdnURYNVft0H1enynqS6XH9CEDj0D MLanj42DlXsNMmpcGg9OCZJ58sW5ofd/P66xHfot30n6yNQTSZI7wQ49YYCfUbWal8ue ACZx+lF7SrX7fu/lJtJrgUVKsfkFj5y2yDkAZ6b4jEjZhht8bwBuYG5WFNUz2EP/Q0Ku dE15EMvgtK8U+VoRSJbhf10kp/GvZtYQwUeSoGso/KB6UIiw7aLDhIOeiixS8dK9YhDE LGNg== From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 1/7] wcsmbs: optimize wcpcpy Date: Wed, 6 Feb 2019 12:58:44 -0200 Message-Id: <20190206145850.22003-1-adhemerval.zanella@linaro.org> This patch rewrites wcpcpy using wcslen and wmemcpy. This is similar to the optimizatio done on stpcpy by f559d8cf29. Checked on x86_64-linux-gnu and string tests on a simulated m68k-linux-gnu. * sysdeps/m68k/wcpcpy.c: Remove file. * wcsmbs/wcpcpy.c (__wcpcpy): Rewrite using wcslen and wmemcpy. --- sysdeps/m68k/wcpcpy.c | 36 ------------------------------------ wcsmbs/wcpcpy.c | 16 +++------------- 2 files changed, 3 insertions(+), 49 deletions(-) delete mode 100644 sysdeps/m68k/wcpcpy.c diff --git a/sysdeps/m68k/wcpcpy.c b/sysdeps/m68k/wcpcpy.c deleted file mode 100644 index a4bac08308..0000000000 --- a/sysdeps/m68k/wcpcpy.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (C) 1996-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - 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 - . */ - -/* The generic version of this file assumes that __alignof__(wchar_t) == - sizeof (wchar_t). We therefore use this port-specific implementation - instead. */ -#include - -/* Copy SRC to DEST, returning the address of the terminating L'\0' in - DEST. */ -wchar_t * -__wcpcpy (wchar_t *dest, const wchar_t *src) -{ - do - ; - while ((*dest++ = *src++)); - - return dest - 1; -} - -weak_alias (__wcpcpy, wcpcpy) diff --git a/wcsmbs/wcpcpy.c b/wcsmbs/wcpcpy.c index 01978e98f3..dc30e9694e 100644 --- a/wcsmbs/wcpcpy.c +++ b/wcsmbs/wcpcpy.c @@ -17,6 +17,7 @@ . */ #include +#include #define __need_ptrdiff_t #include @@ -29,20 +30,9 @@ wchar_t * __wcpcpy (wchar_t *dest, const wchar_t *src) { - wchar_t *wcp = (wchar_t *) dest - 1; - wint_t c; - const ptrdiff_t off = src - dest + 1; - - do - { - c = wcp[off]; - *++wcp = c; - } - while (c != L'\0'); - - return wcp; + size_t len = __wcslen (src); + return __wmemcpy (dest, src, len + 1) + len; } - #ifndef WCPCPY weak_alias (__wcpcpy, wcpcpy) #endif From patchwork Wed Feb 6 14:58:45 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: 1037584 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-99816-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="HXfnMCK+"; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="EpJ+oH5/"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43vl2n1Dhhz9sLw for ; Thu, 7 Feb 2019 01:59:12 +1100 (AEDT) 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=hlrLgj/K+eK77pQi95dL/PzLpTrZy0p h16zIxua4zMx8z5Z4UbcvJMTjbMT+r4kNBkGj88xuAeSdMVvAGqwg1voRTDvdSM6 cNLZUpr/u8KT+7CCQBv9qSxS+vvVXUIp845bC1IurTSeMJWFZod08tlkZiisD0lK sXHzFkBjqHnw= 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=tSND/M1JSaNr7jXMqbmHeqzt6jM=; b=HXfnM CK+z3n4cro4SXY/t8sE7XTFvUHTXm+pYgZDB6dzoKpvVdVm5T7AkJ/9boN+VT0nK CqKc3gFJpc1vSpUqzeRju6caHdspJ79ETV0FERlsPeSlZhiH2v52JcEeQQDvFLpr esm9Mv1aEkpf9HlWncvFAgkO+Ar6xdDiJGO2kk= Received: (qmail 109131 invoked by alias); 6 Feb 2019 14:59:00 -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 109068 invoked by uid 89); 6 Feb 2019 14:58:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt1-f196.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=xkf+5KH5Asn8C6vLg9IFSmnYDBF6qQpn6Ef0WM/jU5k=; b=EpJ+oH5/uhPkNc7O1KIzcA5EiPcH8Zdq76JVIvOYye8llMV3vCO8ZIAJaan5BeTBfI olatzOxMw7A69PgBnBlOTWmWMTw8Ti2D09cARp/qh3jVKxqO8YEkNdsQ2lT5be6Va20D +ZEuPexWzCmtceCVw+tgAAx3mYuHGH/8PbWPo80daqxucjmtYfnR6/p1TK8bmx3MvrHM AJB9f/4c/AOS+ryQ9h+Bs/TiZbpggie7zCYbx92lOz4t6e5Z84qTHjikKtZkLuzrND0h 48RRP5DGDqHYcR73dzgcp0/TZzM/n1oDQYxB15A75RLF8v/NcXuUlvX/qWEkl7MOtsqj zURQ== From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 2/7] wcsmbs: optimize wcpncpy Date: Wed, 6 Feb 2019 12:58:45 -0200 Message-Id: <20190206145850.22003-2-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 wcpncpy using wcslen, wmemcpy, and wmemset. This is similar to the optimization done on stpncpy by 48497aba8e. Checked on x86_64-linux-gnu. * wcsmbs/wcpncpy.c (__wcpcpy): Rewrite using wcslen, wmemcpy, and wmemset. --- wcsmbs/wcpncpy.c | 58 +++++------------------------------------------- 1 file changed, 6 insertions(+), 52 deletions(-) diff --git a/wcsmbs/wcpncpy.c b/wcsmbs/wcpncpy.c index 7568f3b11c..7147affdd5 100644 --- a/wcsmbs/wcpncpy.c +++ b/wcsmbs/wcpncpy.c @@ -17,6 +17,7 @@ . */ #include +#include #ifdef WCPNCPY # define __wcpncpy WCPNCPY @@ -27,59 +28,12 @@ wchar_t * __wcpncpy (wchar_t *dest, const wchar_t *src, size_t n) { - wint_t c; - wchar_t *const s = dest; - - if (n >= 4) - { - size_t n4 = n >> 2; - - for (;;) - { - c = *src++; - *dest++ = c; - if (c == L'\0') - break; - c = *src++; - *dest++ = c; - if (c == L'\0') - break; - c = *src++; - *dest++ = c; - if (c == L'\0') - break; - c = *src++; - *dest++ = c; - if (c == L'\0') - break; - if (--n4 == 0) - goto last_chars; - } - n -= dest - s; - goto zero_fill; - } - - last_chars: - n &= 3; - if (n == 0) + size_t size = __wcsnlen (src, n); + __wmemcpy (dest, src, size); + dest += size; + if (size == n) return dest; - - for (;;) - { - c = *src++; - --n; - *dest++ = c; - if (c == L'\0') - break; - if (n == 0) - return dest; - } - - zero_fill: - while (n-- > 0) - dest[n] = L'\0'; - - return dest - 1; + return wmemset (dest, L'\0', (n - size)); } #ifndef WCPNCPY 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: 1037588 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-99818-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="ZqBv4hds"; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="HIKwtIX9"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43vl364TfWz9sMl for ; Thu, 7 Feb 2019 01:59:30 +1100 (AEDT) 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=W6/VXF/UjU7NG08C1Os4ffKpJz0Vz3g fTjb7uVczebY1D5vOj+sbWgYXTV/nm/hHy2EnUL1U9mXEfjOdM/s7t8dghoZzW9K EFCVdhGG+1JdCyr3Z5Lya0WEK2fxRzukZoAQu0owA8qIXfJ7VU0X0U+LfWCCXX4Z l9pVDI/+u8/g= 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=ZqBv4 hdsH8h0DUw2ps6Rg2VSFFBULCW0FGQyl6XG+piFs5AZhdz6POEmTVVwzTukCkAd0 sYhZ/h0BHuYKwzYftdMSM0JN4pYqXKS9wdUuLmJ35gd+dA+MN8iq5OtMUoEkET2E dbIkWBCUNSKJaRBAWdqWJNDZcXirw+1cwZPRCw= 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== 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(-) 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 From patchwork Wed Feb 6 14:58:47 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: 1037586 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-99817-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="nQtvdYzP"; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="l7CP17sI"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43vl2y2QNbz9sLw for ; Thu, 7 Feb 2019 01:59:22 +1100 (AEDT) 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=bCBG0ubUD4FF+l8eofCD7RvL4k/bIwd /GAaGydZ+tbB7nPUEG5sQqBPibH9l0SAY2Nfc+PVsp+WBQsl18C0ozuRszz3tmVj hKnEaXiG08lJCXySO3Opa+RvHYOGOum/Y4zQiDxOu2/s5Kr7txXsSZDHOFzSU6ny mYX6lG6SRE9c= 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=Y90K5ByF90XZefyM6SmlKqpZQJ8=; b=nQtvd YzPTaqlS4uEdS6rhcTPy4Qbi8CD22f59pPC9oKbKQJD09LGGuTCBXmqOB4g6ojLO 6l2vmo5E8J5uSpXwp0IH3BAIPOU58mU+AzEzlj9Ck0tIEwYJrZUnoV+oZgVCJCaD T4AONwQXORFuOQw3bcO/DsXy+Zw1FdIZNXElJI= Received: (qmail 109503 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 109426 invoked by uid 89); 6 Feb 2019 14:59:02 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt1-f196.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=S76CAuspJZwpLYcbne6+GnRiSQhycXIyeGCQWmiG0JA=; b=l7CP17sIkxnKw+GB4DWpZvN5Y66SvmlgCwVnCN2UZSECi88Id5yY9jDJUhapTZQJAp 05P1PQz49P5LAz1WJecyDdJrzY6d1dwpzF6kqd1/c1RZbFEzG7+jVaTM8JvMZD4eAJUS uY8NJymmqY9q6XMVLq1FTZ0oYVjQOPuwIKIyMdXT7mg4q6cGdbwlAA3JKzFfnIDrP3/P brAjzkqrLC7Wjok0EW36nupQC7+zLPKfe/1U0KV8vRpK5uj/vBnODilzfPgtk7skHHH2 mewkhjrKH/WMoYgK2WUEks912cG7QJ+n9eFesNgZZeZgoIxhHPdUy2A+uX9Xtkdfs5aa zsaA== From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 4/7] wcsmbs: optimize wcscpy Date: Wed, 6 Feb 2019 12:58:47 -0200 Message-Id: <20190206145850.22003-4-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 wcscpy using wcslen and wmemcpy. This is similar to the optimization done on strcpy by b863d2bc4d. Checked on x86_64-linux-gnu. * wcsmbs/wcscpy.c (__wcpcpy): Rewrite using wcslen and wmemcpy. --- wcsmbs/wcscpy.c | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/wcsmbs/wcscpy.c b/wcsmbs/wcscpy.c index 636bf6bd01..0ed4d4b3d7 100644 --- a/wcsmbs/wcscpy.c +++ b/wcsmbs/wcscpy.c @@ -19,7 +19,6 @@ #include #include - #ifdef WCSCPY # define __wcscpy WCSCPY #endif @@ -28,35 +27,7 @@ wchar_t * __wcscpy (wchar_t *dest, const wchar_t *src) { - wint_t c; - wchar_t *wcp; - - if (__alignof__ (wchar_t) >= sizeof (wchar_t)) - { - const ptrdiff_t off = dest - src - 1; - - wcp = (wchar_t *) src; - - do - { - c = *wcp++; - wcp[off] = c; - } - while (c != L'\0'); - } - else - { - wcp = dest; - - do - { - c = *src++; - *wcp++ = c; - } - while (c != L'\0'); - } - - return dest; + return __wmemcpy (dest, src, __wcslen (src) + 1); } #ifndef WCSCPY weak_alias (__wcscpy, wcscpy) From patchwork Wed Feb 6 14:58:48 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: 1037589 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-99819-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="kqDrg3v6"; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="CWqzzSOC"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43vl3H17Nyz9sLw for ; Thu, 7 Feb 2019 01:59:38 +1100 (AEDT) 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=wbQA8x6ecQPva/onIXjOTZtfMPwvFxr IuSRV6fTdJP6k2hHqqmlaCEv8LIHdFtZKR/buAv12m0LZYgNjG1yepvGO3Jcc8/p MysbaPOjOcQ7iRpg9j5D7tUaj4Cseq3sW0DWV18lOn3galMnqVHaPhxlX0rWZaGb gWsyz6uDY7yI= 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=kO8xg6uwqo2WvJA+wiMPGdd+h0Y=; b=kqDrg 3v6i+8sd7D0bht+Go3aNW+MFLc639Y2d4avp+FGp77fGPPMEXaFLjrI3xNMUEC/s 2HoYPW+G7YJw7U8+5yBgNWiaKTMrDQcwDIVcFfz+qrNCcHsGXppjF9Q3Taw1I69J AEG8gjWYzevIdeky9CK6ZCRQOtu59OKkfJ3oaY= Received: (qmail 109819 invoked by alias); 6 Feb 2019 14:59:04 -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 109745 invoked by uid 89); 6 Feb 2019 14:59:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qk1-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=20SJ21tlZpNhS1XJTfqXZ9f9nW5s8hKP6KYDk0x+OEA=; b=CWqzzSOC6tKXEOnIueTGBMbZ69CBu7odn4vgEGqVzhBa8POlifoRggqIBid159dIln 59qJLOcnWcfHFlWlEjHCu5clGDCpiEPZqbOxGmmJys05c8ZoKpmua6PiymrHW3L028RT 7c2I4xZX1pdGUL0HHQvZeMGge2LHCRFfpW0yfgXmdd8kZPsBDS8B3lwsX0dnlzRsoTwf PYwV0UOIhZEF+q7qLFmVQ0j069tVj4JUGeUGaaT7y9W6nbR9pJpaPLYxJ9rN+hr8ddmn v3cV9wIIRphhWDPLEWcNbxOxmFCMPScKBH8++qHiuWntTVHfpXN5pVRo4LcJfIzfRRmL DqSg== From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 5/7] wcsmbs: optimize wcsncat Date: Wed, 6 Feb 2019 12:58:48 -0200 Message-Id: <20190206145850.22003-5-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 wcsncat using wcslen, wcsnlen, and wmemcpy. This is similar to the optimization done on strncat by 3eb38795db and e80514b5a8. Checked on x86_64-linux-gnu. * wcsmbs/wcsncat.c (wcsncat): Rewrite using wcslen, wcsnlen, and wmemcpy. --- wcsmbs/wcsncat.c | 53 +++++++----------------------------------------- 1 file changed, 7 insertions(+), 46 deletions(-) diff --git a/wcsmbs/wcsncat.c b/wcsmbs/wcsncat.c index 65e9b226c6..cb6fe71e19 100644 --- a/wcsmbs/wcsncat.c +++ b/wcsmbs/wcsncat.c @@ -26,54 +26,15 @@ wchar_t * WCSNCAT (wchar_t *dest, const wchar_t *src, size_t n) { - wchar_t c; - wchar_t * const s = dest; + wchar_t *ret = dest; - /* Find the end of DEST. */ - do - c = *dest++; - while (c != L'\0'); + /* Find the end of dest. */ + dest += __wcslen (dest); - /* Make DEST point before next character, so we can increment - it while memory is read (wins on pipelined cpus). */ - dest -= 2; + size_t ds = __wcsnlen (src, n); - if (n >= 4) - { - size_t n4 = n >> 2; - do - { - c = *src++; - *++dest = c; - if (c == L'\0') - return s; - c = *src++; - *++dest = c; - if (c == L'\0') - return s; - c = *src++; - *++dest = c; - if (c == L'\0') - return s; - c = *src++; - *++dest = c; - if (c == L'\0') - return s; - } while (--n4 > 0); - n &= 3; - } + dest[ds] = L'\0'; + __wmemcpy (dest, src, ds); - while (n > 0) - { - c = *src++; - *++dest = c; - if (c == L'\0') - return s; - n--; - } - - if (c != L'\0') - *++dest = L'\0'; - - return s; + return ret; } From patchwork Wed Feb 6 14:58:49 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: 1037590 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-99820-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="ig4Hau8H"; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="G4lDscib"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43vl3R2vlgz9s7T for ; Thu, 7 Feb 2019 01:59:47 +1100 (AEDT) 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=DGxdgEpt05JwFg2OeNlot6XsvRn+V9X Nn5sFAhauNMNNdigqnVOl9KgonVt+qn8sGV63kmByBzS4ds9JPVdL/FlCw+0IpGg DqX/bMCoViv8cZR5gCoke3KYsm+7ay0YdBBzqledgEvqf34X17zDlvv8a2De5U8r B+fkU0nimBek= 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=Tdvku9jR99pQcth0tNcGvfOCNFs=; b=ig4Ha u8HdVWoe2J79vru7U7lUYbkRyf33cSt4+wYPJMKwRFbK3jwPE34lkXDWCl6IWlrt YvW31RjyAu4sRj6XCPghrybi7VoivsiVvZtfCFh7T8VjCR6Su80z8rPUA/mET9IW s3JKhrmVF4Vt9u/EBVFuJ919v82s57QLJOxt/A= Received: (qmail 110078 invoked by alias); 6 Feb 2019 14:59:05 -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 110033 invoked by uid 89); 6 Feb 2019 14:59:05 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qk1-f176.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=V2aQ/Yu5qAsX0B4JdCgC4Jknz71S7kCZHOUeR3xT+VI=; b=G4lDscibi5Oap9jcQkCExwRahD0egGuX0I7tzaaDDj0+qndhNGsw621fLcYe0BBWjY jBOozzK4/Ik7EpHulgNPcoPzVqZbUQw5EhuWbhVp0DF8PTIHHFm54Carr4nmrRYq0Ckk 64f3GHgHx0IpSRJeFrVXo+vRTjJTcAbllK1cjnH8TFLx+RcyVqjE0DgS1wMuiUrOaBG3 WfQATJt7jiwfEvixRbJ0/tIo3pRW0mmrrNaTk3SN8kdrMXe0D4bn8Oz6OmbSWQA+pMjS 2n62EF0l9xpBArYZ/ujvlljauuGg0ia3GSplGHssM71jnhqlg8ttu4zSBNVPfabd0Db0 JXyQ== From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 6/7] wcsmbs: optimize wcsncpy Date: Wed, 6 Feb 2019 12:58:49 -0200 Message-Id: <20190206145850.22003-6-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 wcsncpy using wcsnlen, wmemset, and wmemcpy. This is similar to the optimization done on strncpy by f6482cf29d and 6423d4754c. Checked on x86_64-linux-gnu. * wcsmbs/wcsncpy.c (__wcsncpy): Rewrite using wcsnlen, wmemset, and wmemcpy. --- wcsmbs/wcsncpy.c | 60 ++++-------------------------------------------- 1 file changed, 4 insertions(+), 56 deletions(-) diff --git a/wcsmbs/wcsncpy.c b/wcsmbs/wcsncpy.c index 2fd523c815..d5d7f4ad86 100644 --- a/wcsmbs/wcsncpy.c +++ b/wcsmbs/wcsncpy.c @@ -26,62 +26,10 @@ wchar_t * __wcsncpy (wchar_t *dest, const wchar_t *src, size_t n) { - wint_t c; - wchar_t *const s = dest; - - --dest; - - if (n >= 4) - { - size_t n4 = n >> 2; - - for (;;) - { - c = *src++; - *++dest = c; - if (c == L'\0') - break; - c = *src++; - *++dest = c; - if (c == L'\0') - break; - c = *src++; - *++dest = c; - if (c == L'\0') - break; - c = *src++; - *++dest = c; - if (c == L'\0') - break; - if (--n4 == 0) - goto last_chars; - } - n = n - (dest - s) - 1; - if (n == 0) - return s; - goto zero_fill; - } - - last_chars: - n &= 3; - if (n == 0) - return s; - - do - { - c = *src++; - *++dest = c; - if (--n == 0) - return s; - } - while (c != L'\0'); - - zero_fill: - do - *++dest = L'\0'; - while (--n > 0); - - return s; + size_t size = __wcsnlen (src, n); + if (size != n) + __wmemset (dest + size, L'\0', n - size); + return __wmemcpy (dest, src, size); } #ifndef WCSNCPY weak_alias (__wcsncpy, wcsncpy) From patchwork Wed Feb 6 14:58:50 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: 1037591 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-99821-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="IoozTyqp"; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="chk/4Fdp"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43vl3b39qPz9sMp for ; Thu, 7 Feb 2019 01:59:55 +1100 (AEDT) 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=Z7beW9AA3FzoLhX/TOUsTU3RaMKcZlr lPCr1lZfRujW+n0ghOqw6XRQ4XhVtce2phEcbDWR5pT/m+XyEMvBnJn2qpljq/g4 DH4CwUDkLG+8Nqh1LJyAWV1hq6ZidhoNT1/fnklo4PH3ztQ+I8LIjSqbCMzYAR+h AQtKVplJwWZ4= 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=2vwamcCfRncW4l6cZssaYZyEX1I=; b=IoozT yqp4rxhDTXcMd3qi74LfhHUDxYoKVpDJVY5dpsxNRvyrI7+RSMerCqOixjDo8JD5 LoeyC0/Woj2iuQWaIlChIg4iTdVfyjI0CdSagsol9XXRfKrITpQJtW4cWRpZ6wVn /Ilgi7YLsMXcku9ENsKvLX17iDJTytF0FtA1zA= Received: (qmail 110258 invoked by alias); 6 Feb 2019 14:59:07 -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 110195 invoked by uid 89); 6 Feb 2019 14:59:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qk1-f193.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=HNWORm9QaeNi3ZBQubRO6r8ZHAI3qUNzolm0gxBVXgc=; b=chk/4Fdpw6tw+nsL13ltRexqWEzsSvQQZhYRXxcjbKb72LCB4Q5gHNTekT++SFzJyN 7VIZXn83t+cTsdAgcOCMgtsNAeCxUm9A4wq3z/LeGqkrlB3Z6skGkjcGMcVmoDiD3ABc T3I4hUUZmY5CYSY+BiRJLLSJFY8aS3fvmkyHU25A3/5g9XtanMBmMPwsvmLhg83Vx+s+ qRkK+BKDQ3gZjuSR/AqhkiH/08RmuHhj8YyQoPitkQtYJuHqSfeH2xGWzRlN27gyvUTZ 1BjtV2aOXPefMSH7HsHAX0DwsLkPwZ/nk2YLcabJCNWkIIoGN1hsyxrwdWEKUJ/HaNxY YQfA== From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 7/7] wcsmbs: optimize wcsnlen Date: Wed, 6 Feb 2019 12:58:50 -0200 Message-Id: <20190206145850.22003-7-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 wcsnlen using wmemchr. The generic wmemchr already uses the strategy (loop unrolling and tail handling) and by using it it allows architectures that have optimized wmemchr (s390 and x86_64) to optimize wcsnlen as well. Checked on x86_64-linux-gnu. * wcsmbs/wcsnlen.c (__wcsnlen): Rewrite using wmemchr. --- wcsmbs/wcsnlen.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/wcsmbs/wcsnlen.c b/wcsmbs/wcsnlen.c index f3d5fc1fba..d38c7e4953 100644 --- a/wcsmbs/wcsnlen.c +++ b/wcsmbs/wcsnlen.c @@ -26,24 +26,10 @@ size_t __wcsnlen (const wchar_t *s, size_t maxlen) { - size_t len = 0; - - while (maxlen > 0 && s[len] != L'\0') - { - ++len; - if (--maxlen == 0 || s[len] == L'\0') - return len; - ++len; - if (--maxlen == 0 || s[len] == L'\0') - return len; - ++len; - if (--maxlen == 0 || s[len] == L'\0') - return len; - ++len; - --maxlen; - } - - return len; + const wchar_t *ret = __wmemchr (s, L'\0', maxlen); + if (ret) + maxlen = ret - s; + return maxlen; } #ifndef WCSNLEN weak_alias (__wcsnlen, wcsnlen)