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)