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 X-Patchwork-Id: 157621 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6506879jaa; Wed, 6 Feb 2019 06:59:08 -0800 (PST) X-Google-Smtp-Source: AHgI3Ia510ZWdruVOz7gq8C/Az6Hygv/QA2Dz3fVciIZQnI+XzUMHm14FRt7Oa7UZJ3d5eokQhkF X-Received: by 2002:a17:902:2887:: with SMTP id f7mr10844838plb.176.1549465148094; Wed, 06 Feb 2019 06:59:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549465148; cv=none; d=google.com; s=arc-20160816; b=qXnfhXLANS9JucrF6Ps9H1VK5Q1yjYqg3qiKTdeWkASKDBOuVByJKOiLE7VTLcXpC3 SJJ6m35ORwvt+889ypqc55n4oj7ts7TmAPpT84SXM3gzIdd+zKBIjyHdkwJmm2y0VxFB kciMdAhYgXAmpP3Q6DDtjm3eYVFXnLx/JhrPTXXT7++a7EyJdNVwdtoKHbb2kKe96Prd mO9j0adySP1kVKNdmFK+x9Sku46bMxeUH2qoAP0cvk/bgtyE2ZkWzu6y3Uj9AW40dWl6 pqRP+gSsjw9pZa/Hc149C3eIR7KrNzhbq1dr8kZtKgGJOAztJZ3LijY0fOod+CCKjAq5 g/Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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=lZba5FDsuN1vVFJD5XEauVSuUioz3geYJbfKqOGpteY=; b=hWTg4dqf65VCAYL8kNG/N1910J/T3exHrQ8JukfE9EZ23I7nZqVrGIm4LY5PuQuB1w zQkitWLw5JPFTPw5S6BDxSnwkRAa6cfPUQwrcFiWY/xatt9+FGGvUivaZpAj3fr9YjL4 JGG2/btAhC2e/l1rEmjvtl1F78FrXurczAsFDJ2V1qrIXmJO4s/R5XI3kMkOorM0Rwq1 aPAO/e6c0diqJFfpdyIklGIym2unrTmhaLAAm6HuGfwIaFHpjQENtThPahtTAfN6ug8g kO2bJmQniRYbR3bTK5vdA1e/Q7RDLB+mUON7XPU6VnhOwpTWVx6GP1alNlR9X0seOb7c p88A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=QgFQhGOf; dkim=pass header.i=@linaro.org header.s=google header.b=VGccabcc; spf=pass (google.com: domain of libc-alpha-return-99815-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99815-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 y123si471565pfy.18.2019.02.06.06.59.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 06:59:08 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-99815-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=QgFQhGOf; dkim=pass header.i=@linaro.org header.s=google header.b=VGccabcc; spf=pass (google.com: domain of libc-alpha-return-99815-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99815-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; q=dns; s= default; b=w3r3Mxcy2Ts9rhE9OepigPJgOHnifUGsCw/Oj0UzDzcLwUPJbytbt Osq6HxNKx6o+rYku+Bj7YwL+viL2HvN2maF/+a9IHIgQ30qKqOq3KGqpSfG95ngB DAL+ffhihjPvdQvBIjgd5w4wQOpUvqIJTCJo5Dt8b/pxAhepqh9mIA= 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=QgFQhGOfP82eHcPa7+AKlGB8peXu leYTlXjlkVAVa4O55kpZoibjRPpnxBP5FFuslfujE3xJbQaCD/y0jb1VPMMOCmNH m3HcSLG8kp6/J7D7HT4exRxKcceVtKCqCdivYg63gW2k0ByTYQLzqEP+Y6iizP4h EVW9xdGjh7+9j30= 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== Return-Path: 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 -- 2.17.1 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 X-Patchwork-Id: 157622 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6507020jaa; Wed, 6 Feb 2019 06:59:16 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib/rMvZjywD7HyxnTCuPImL5/brg52HUbiT/cKMhTRmcSTAH0SGHQKcHzTnjGJ7rKKv32bt X-Received: by 2002:a62:2a4b:: with SMTP id q72mr10794363pfq.61.1549465156785; Wed, 06 Feb 2019 06:59:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549465156; cv=none; d=google.com; s=arc-20160816; b=kp/ObjhdS0UT70YATZDpP96h4T8tFwM7itFcDQRGUzbSghrYmv1w1a5OZPYnzz9JEw L9Xpe4nRWA1DzIHJ53jeVOlh2HnEfOfF2no0oj4hloKwuFn2pPrETfyoSIqNWQUE/rIT rmmEdX91PcqqYFOMhTWq71b6yYm0tCW6oHMNlgrROsq9oU98981LeIfzJAAY4opCuxX1 1CYxNV4A4aHHEEeBEwNLgPkC7B3G1wgz83IprUb99HAEbqT5axHEE+WGcFXDLSJD7bcn fXbbpuHvIPKNQht1eEoRZhG4s9KzsBFveqOoGESg3GMPbvndKZbG/9f8/OR+uTxNhATc OZGQ== 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=xkf+5KH5Asn8C6vLg9IFSmnYDBF6qQpn6Ef0WM/jU5k=; b=aDnmiRmHjwS1/RImx41Ditzsf/IIEx3dtFC5/YEV3dUN8aMojZc04XXuV4YgZwtNIJ aoSeztnaCXhZjUWUoyi89YaiNs6ibN66jW/wzLjJTtRBCr8XShQk4dWRE9HLdeDOBpq7 Dx8fsRRiJTY4n0mZvm+tSOsynLhk097WrCJYF8KDoX+TP61x+6Pqe/zaAV8CrJ/810/T s20AxxQJMcOvs9Wdy6ul5LvP4NZ5wpi1BNjikhF/zQX0RPntlx4T71xIQy9Vi1kKH2Vh cXWKZQ32K0N83PlUH+wyzA0ZWW0f1J+NJsgvD7In2sFuPsYMeRJ4EdK8XtCAEkqjec+H lh2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=TwSJ93X6; dkim=pass header.i=@linaro.org header.s=google header.b="EpJ+oH5/"; spf=pass (google.com: domain of libc-alpha-return-99816-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99816-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 l96si805851plb.292.2019.02.06.06.59.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 06:59:16 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-99816-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=TwSJ93X6; dkim=pass header.i=@linaro.org header.s=google header.b="EpJ+oH5/"; spf=pass (google.com: domain of libc-alpha-return-99816-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99816-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=bf00S+leBCfIwWrIKoLHu3oZ2s733c8 DctEddM9hW95HoXSVUZQ8MfjtOHICl5Km3ZClItlo5IUDAPy5KaVzkhzCQ2VtmKQ BQaJn9ZKDJKEdC5kvSOop477TJOYKlJiRBRCmpcQpmjAbnh8IG3w7gJyJlk7HLmO FvTLeSDZF5Xc= 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=TwSJ9 3X6dpJr94tNFqbaigO3MZp1YKvz9y2aP42Fmt/4szl6FRdb97KxyBV0Bf7meSp81 eQdWfM4u9DBJxWslXhG9w5FhoHUEouGyfalK9vG++ui80c+X0/uvfqDzLiqxzO7X BMy83PmmfnI41NknpAHiAoWQnCGvTtXAIxqLIs= 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== Return-Path: 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(-) -- 2.17.1 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 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 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 X-Patchwork-Id: 157623 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6507140jaa; Wed, 6 Feb 2019 06:59:25 -0800 (PST) X-Google-Smtp-Source: AHgI3IatwksOJdE6CsfpI8h9Jtw2g4I1e7IMkN03aElGY+RLhuW2tu90QY8Fq/oeAiViis2//hFa X-Received: by 2002:a62:2606:: with SMTP id m6mr10656967pfm.133.1549465165018; Wed, 06 Feb 2019 06:59:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549465165; cv=none; d=google.com; s=arc-20160816; b=NphuCohxQoCY37j9T75mF0LYKzQxbWLxbAN2fJluxLEQ+hyB+50Qw5tNqZEOXQUB+B bQum91zKLMPyvKtNfQhYia3xQuRgpf2UW6RjmKxad/vuq8/7jHx1mB5lFDGsUHWBigoc qSxeYbQpoI5vErVm9jxpeVSPWTIh4jn5qSpqq+bkTyX6HYQgTHQFxr2XX7ZHO3dJVBkr mvGEeQeJkqzYEYT975Vyk1VK/C8nVSsvcSyr8EuunscO2NGgU7V3At3vH5YBv5WvRQ0E OeH4wRKZeUsrlRS/1oFh4+DC3J/Ay5nNG+N4/1QZCezrAHMJSe8/BB1y0CJyy0mOKiD9 +9WQ== 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=S76CAuspJZwpLYcbne6+GnRiSQhycXIyeGCQWmiG0JA=; b=xMyK/yx5XUc/a/bv+BU6O6i2pawCM7rAgVBXh8XhYyBAbn0Tlwjq6i2T5enTuq0t98 Rmg7EVOGumifuWFQdwUQf9IG98ZUM48+2M3JcdUgZIYAahDa8DOtIiKAtg2VBPAcLloa 00gHEy8Ad9ZI5TI/rlV5Er3xanKuZuMBPm4Y3J84Hh7Uo3179yevQyKv79n1Q+syc+Qb kZujrwiA3JzEGinNhigTY6+Wxgd2wKzg9LZArije/TN8THY0d4eQyWSS16lVtNDjAhoL BtBiZJ0rNvHMG5o3Da542v26uV95rnlpDMGwbnYtVrL7d8Xkkg7Za9cL8w1uP0IgoM7I amxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=MwksyTfr; dkim=pass header.i=@linaro.org header.s=google header.b=l7CP17sI; spf=pass (google.com: domain of libc-alpha-return-99817-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99817-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 n187si3425008pfn.83.2019.02.06.06.59.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 06:59:25 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-99817-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=MwksyTfr; dkim=pass header.i=@linaro.org header.s=google header.b=l7CP17sI; spf=pass (google.com: domain of libc-alpha-return-99817-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99817-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=ZtJ4w+GVJPll8hUb5dVdRUFDuTKcQ81 CVvh/SWSZnBFQwJQgfH9hXEeDHJ2r1kFbhUMuGQBsWGzUF+DnUz9KGOVsnXD+WFV eJ0j/HtiKn8FTBeuxQX9q+PINPK5tbK7qr70bqHoT4jyUfD+RwMJadfLuecDo5wm UcacJ2Z8pdws= 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=Mwksy TfrBmHRQhuH/XcCJVNGiGZB1LE4G3dzfURMjvBBohCdanHfSLTtNgo1MPiQzb8Ze 34MxEdCVKGUbOgmu34Y1KxfeC8FgUS25AKlTWhvvVIYm1tOK57ucWOgUXqAfeE3b kRhQ54v+c6oCT44Tz+R4xN0cpiioTycUJUvFjQ= 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== Return-Path: 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(-) -- 2.17.1 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 X-Patchwork-Id: 157625 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6507380jaa; Wed, 6 Feb 2019 06:59:42 -0800 (PST) X-Google-Smtp-Source: AHgI3IajFwumuaOVL99iYTgLlxGKz8IKX70LDcoV9zd+5M+f7Rbo8nm8a2xqquXLE1PFojc4RV5p X-Received: by 2002:a17:902:968d:: with SMTP id n13mr11205048plp.109.1549465182166; Wed, 06 Feb 2019 06:59:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549465182; cv=none; d=google.com; s=arc-20160816; b=tKYuB1X0P3G13wdSuDyrOjbX24dahwDiXJ+ArQv7IoRx1WF01zpCFciqEFN+iWB4+/ /8TqJf2Dp/r++vicChpWST+e62VXvKmEnG2URjcRnunE5T8m3sqplrNoGnTmcfQpbh0s xXNNJ9A1G6sV+40/tCKessD/t3D2yRaC9jhfqq4sSgonEeW+SlCQP1FquuPevxRROSaw JOkLwS1G3A9397ZIeEDq+JbtjNH5sDxdHIjpK0tX2iGlCcOp5dXJ8yX/vs+3Q2DBTZWs 0giRk8FDKhaOtP6NqB5zSzB4aQSKNXwlDDIBUoK4mkLFZ8m4Ta80Zuj6c/360FMTRim6 aSww== 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=20SJ21tlZpNhS1XJTfqXZ9f9nW5s8hKP6KYDk0x+OEA=; b=1D3Tb6XdtC7ieeVj9Nutnvdt8+dBQ8eUx5edpPcFqs0kXJ+kVErS4PyN+ucFuWw49+ QPv1tFG0xr1eKG8suhd02MaTN/3SYosNPigW6SfK2nG2H01J/8isNywPdDw/Vmg0aFt7 1foiybvXGERnKn1/BhBwaVqZOaQrQBohiRI29VcBoZotz1CCBGmFT1A3Lc8ATh0FbtaN 8Kza/bTtjbNOq3QdaDQ+9/5YtheLJXNilHBkyiwJkhE0tHBm5a4FAadOfqVQOlzSmlen lbHZc0fT2MpD5aiVEDvIcnv/J/rinMWBl06OVs7H9tuSLZvqzLSffuUOlZUgkRzywWTg zcZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=XAYQQzbo; dkim=pass header.i=@linaro.org header.s=google header.b=CWqzzSOC; spf=pass (google.com: domain of libc-alpha-return-99819-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99819-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 l94si6622463plb.209.2019.02.06.06.59.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 06:59:42 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-99819-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=XAYQQzbo; dkim=pass header.i=@linaro.org header.s=google header.b=CWqzzSOC; spf=pass (google.com: domain of libc-alpha-return-99819-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99819-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=bOkAnvmlEJSCnlky66sXVGZZRwNllhV ptOFB0rGtwv1Coz59ZGw2R5TFlgCF249zcVrh8qJzx5E5BFGbaWi073xBQw4KVnW xkxsLy4LiroF7PNzcSw95/K94SSkGJsAWY41Ef7mBioSJGUn8kSHGDDiXguhQVJa slMozADcHOsY= 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=XAYQQ zboEQy2LHpFI3xMxDtj78j9M0T4ViDTvzjGAAj932Kop8tzgzcaVS1yIRwi1jdVh C7Gprp8F+wez3yqPDBasFEWCNb3eVBST0i35HeRjieH6yb7Aac8LkoGFnyaJt5Qd RLRqGRlyYNpBwmuvptpFnlAnSlRBjSVu9GQrvQ= 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== Return-Path: 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(-) -- 2.17.1 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 X-Patchwork-Id: 157626 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6507501jaa; Wed, 6 Feb 2019 06:59:50 -0800 (PST) X-Google-Smtp-Source: AHgI3IbjWttTitZze//MwwUgPv2KO1gtzEZ9nZJx47H4MlumS+OqQCBOt4qVQMZC8BxH0viRhY00 X-Received: by 2002:a63:e5d:: with SMTP id 29mr9900470pgo.237.1549465190510; Wed, 06 Feb 2019 06:59:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549465190; cv=none; d=google.com; s=arc-20160816; b=f3wsVnqnkxvEbItbP/eCif1d7x6zUdaQ9Sd9WwlbRtdTa0OA1rIk/uKou9mMqyEDXM ATFpt9n3qcCX7+sY7C4Yrwvx2QozzIQ+v2m6v3O26WrbV8UxrdfBSnexzG/ZXBkYZZuJ +bmIIzYNAFBgfFl3uUKcOrvsUOZ63SinlhbUUJJ22U9PBPX79vpxTdcwgL1sd0N/ddDd aYbJoZmsd7WV/B4sSQ4VFiGl84UEvUIx02IXUpB/uTLj4Zdj7/c2AagSAGVl3cyUuzQT M86pufC5xuZ9py6pyVkN2iZ/+WhbejHtKAaniM/oR4mjUY8Q+pY0cdhPPuipoCMZ4nwJ ClLQ== 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=V2aQ/Yu5qAsX0B4JdCgC4Jknz71S7kCZHOUeR3xT+VI=; b=I7fwvrM2pIplimLxl+712RIvtga8AwXSw2xQ84PnqcsepadyLYjYVUyaCb2zZwHEPl /HOjrY3bePhdgG3BP5teZfu1APWZAry4s7ikj/2mL4r361CqG4GuP7nE3Nt+4GIjDmZi dQykI7yeV4ZDyPCEHf7eW0cST9lJIImhEKS4Q6vJhnrRi2mXqYtsdI/57BQTE3VZ6CPi y+Fco9kkPgdGWxErNhdf4PeMThANFJGCtiwHQp7y+cK20kLJStm6B7xCJMMj9DqkWRZy cyDfGAaDpNQmI17altblPOchcwXgqYfDJLlXgxwlDQVbeNwyqvTL2P87ZcsXBzYvdAsz qYqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=s0kyn3ee; dkim=pass header.i=@linaro.org header.s=google header.b=G4lDscib; spf=pass (google.com: domain of libc-alpha-return-99820-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99820-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 a10si6019015plp.167.2019.02.06.06.59.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 06:59:50 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-99820-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=s0kyn3ee; dkim=pass header.i=@linaro.org header.s=google header.b=G4lDscib; spf=pass (google.com: domain of libc-alpha-return-99820-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99820-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=ezpXKoW21jJe6biuCeZs2xFa792xjgM exIwjs5kgzvThc3sTA2AvGEqsSCQsuZvL2GzGzx01WcpoFuejnCbe/HicwehIzLh J2burG/j2rb3h5/6vkgoSThNacLBv+rxfjhfKI9xJn/CYbdeXUCzUO+z3ajNCI3X p58cxlvtpHwA= 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=s0kyn 3eejpSPGT5FHBJAo3XjT5yLJ+q5H0C3AFVsDU1i0Gx3RBSTDDR9hzRqpYRAXy5Kl 0LZ+pQzySiZxBCBfKCQStgM7YA15p7dT1SBaj1Bo0zDtIfy9hGxhXtFNcZp6ESgo TLv6lerOUBkTqBv4CCWVpRkJ36uOtTq4eFISjU= 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== Return-Path: 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(-) -- 2.17.1 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 X-Patchwork-Id: 157627 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6507605jaa; Wed, 6 Feb 2019 06:59:58 -0800 (PST) X-Google-Smtp-Source: AHgI3IbfrofeA9UDMWtfsglcLWtOxeP5jzzdGvU8o2Zx3GKa5nt7zAmoLM7s2v2qWfAAr7yRI+a1 X-Received: by 2002:a63:ed03:: with SMTP id d3mr9814090pgi.275.1549465198499; Wed, 06 Feb 2019 06:59:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549465198; cv=none; d=google.com; s=arc-20160816; b=hhWB/huxANg3quomE1xWB6IGMGWLMTg3taGNImIFClI0lz9VOzPhvEXl1+yH/N+FQm LD99tmK071jSEmjD58yAzoMZxfkxsuojbnekTdoPB8HZUWPLu3y2D5oSCw8Ne3qJn7Jj Oz+BjT79yq/Wvd2ebdrGXEZdvZQGLuZQLRXh04VMw0AH+DFcAfF+GHfafV0et3s5ecf/ iLH9Zi5C0YZNqgH+b0x+xLaRslLUOC4U7Q+mLngyBaF+eo+bqVu1UYaicbojktSj004i klxcxMiGBbQaPmclPYk/iNsQGSamgnkUZc4hvzCJgQ5FrIcUEeQCRqPPMZ9Uls8mAjNH 97ww== 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=HNWORm9QaeNi3ZBQubRO6r8ZHAI3qUNzolm0gxBVXgc=; b=rxYRJI9uxABGAxkxkLd6TE66PDQw5PBxnWJQipSPKmtmjV/FT3O4aS8mSuOmih9wkj ddyuA+D4zlXIw0y3Qmz/VDtebjLOqXZqERlYvrL6/3Reokpw0MpXGrPjIF/kWa7HdSrQ mh7nNxo5g8grKJETKebM6mTONFggnWA8ahk0eHzXDkBIKceeGWpPxvXBRkS2QDNZqkIA zzFC/PHYDOdITkeWtTqtZVH4WNa6v4tZIJh/kgeSzPsrSWcPOYPk5NzLAqkbaYhXEJH7 BPk33bRZc1la+ED24LsdkTt79ykwR4eKzEJ9gRxXWmF+iiDbNfvDKAqhS5Wu0y+yPJgD SggQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b="v/cVgZQU"; dkim=pass header.i=@linaro.org header.s=google header.b="chk/4Fdp"; spf=pass (google.com: domain of libc-alpha-return-99821-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99821-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 h127si1980305pfe.204.2019.02.06.06.59.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 06:59:58 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-99821-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="v/cVgZQU"; dkim=pass header.i=@linaro.org header.s=google header.b="chk/4Fdp"; spf=pass (google.com: domain of libc-alpha-return-99821-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99821-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=H6BTfSm2KnAunXrVslbnQr58Z1GfXS4 Q5hzVCC4n+TE6RF+7ZI/4GK7sDNfbgkbxdcSVp1j6sZOv7nTIO5kEeR6OENzFAPQ Nfo9+rVKpVsojX7hOlOVRc99F/YrEohMQ+KYDRP96oxTL7OPIZxZJS0RC8SFZC5C H3qwgIjrgWI8= 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=v/cVg ZQUAAtlTJ7M8wHLmkNHZ7OC4dxfv6CZgEj/KDgGn3nAghU50tcTwcLTg6k6G/dRp mRMKcqo7m84Hc75mMVpe6cv71Lpej64tFA4kba+0S77g7T2W3HS9pYL+3Xkz32Mm NCwSCJC0A5JsxntPB7lHuSC3m2KM6NJZTjpY7M= 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== Return-Path: 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(-) -- 2.17.1 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)