From patchwork Wed Jan 14 14:17:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco X-Patchwork-Id: 428975 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 C64711401EB for ; Thu, 15 Jan 2015 01:20:17 +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:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=stS 028CpQXxkAteAIUhMkDeZi3MyH7Yw69k0U1qqFYtfeaD+eew3xqEiqRmrCqwsuLU jzwkRKnwdHOpzbWCNV4aN66CIEH90JfrnUgK0MLWjVZE1ni2kEI07p6npWhUjU99 71ekKS1zpop7mboDG0WEp6u6ixkbPWnpEw+ZCWL0= 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:mime-version :content-type:content-transfer-encoding; s=default; bh=/bSotIUm7 SdODpKgwwo9lqu/Sr0=; b=Pem5wFsIm1fRuS2Vbqe0yicpvevG3C/u+eZn1/l+S RfkOmA9wumrsbrTwRwoxk4ejvqHElR3D9R4hjsutekUr5y6RMqfAKqhCDUMmuqiG 29+rPNbg9trcOiQv+rDPzsUI4Qi1bKrLO9swMfHtg+biKBkdd6xZXVIiFZkEmpDf +c= Received: (qmail 31457 invoked by alias); 14 Jan 2015 14:18:31 -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 31289 invoked by uid 89); 14 Jan 2015 14:18:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: service87.mimecast.com From: "Wilco Dijkstra" To: Subject: [PATCH] Improve memccpy performance Date: Wed, 14 Jan 2015 14:17:49 -0000 Message-ID: <001f01d03004$e05abdb0$a1103910$@com> MIME-Version: 1.0 X-MC-Unique: 115011414175608301 Improve memccpy performance by using memchr/memcpy rather than a byte loop. Overall performance on bench-memccpy is > 2x faster when using the C implementation of memchr and an optimized memcpy. ChangeLog: 2015-01-14 Wilco Dijkstra wdijkstr@arm.com * string/memccpy.c (memccpy): Improve performance using memchr/memcpy. --- string/memccpy.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/string/memccpy.c b/string/memccpy.c index 70ee2ae..d4146f9 100644 --- a/string/memccpy.c +++ b/string/memccpy.c @@ -26,15 +26,15 @@ void * __memccpy (void *dest, const void *src, int c, size_t n) { - const char *s = src; - char *d = dest; - const char x = c; - size_t i = n; + void *p = memchr (src, c, n); - while (i-- > 0) - if ((*d++ = *s++) == x) - return d; + if (p != NULL) + { + n = p - src + 1; + return memcpy (dest, src, n) + n; + } + memcpy (dest, src, n); return NULL; }