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: 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)