linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Alexey Dobriyan <adobriyan@gmail.com>, akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib/string.c: make strncmp() smaller
Date: Fri, 08 Feb 2019 01:31:49 -0800	[thread overview]
Message-ID: <061655a972b4037b5bf245a65aed937967410e61.camel@perches.com> (raw)
In-Reply-To: <20190208073403.GA19734@avx2>

On Fri, 2019-02-08 at 10:34 +0300, Alexey Dobriyan wrote:
> Space savings on x86_64:
> 
> 	add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-29 (-29)
> 	Function                                     old     new   delta
> 	strncmp                                       67      38     -29
> 
> Space savings on arm:
> 
> 	add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-60 (-60)
> 	Function                                     old     new   delta
> 	strncmp                                      116      56     -60
[]
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -344,16 +344,14 @@ EXPORT_SYMBOL(strcmp);
>   */
>  int strncmp(const char *cs, const char *ct, size_t count)
>  {
> -	unsigned char c1, c2;
> +	while (count--) {
> +		unsigned int c1 = *(unsigned char *)cs++;
> +		unsigned int c2 = *(unsigned char *)ct++;
>  
> -	while (count) {
> -		c1 = *cs++;
> -		c2 = *ct++;
>  		if (c1 != c2)
> -			return c1 < c2 ? -1 : 1;
> +			return c1 - c2;

This does change the return value for most comparisons.

Wasn't there a specific reason for -1 and 1?



  reply	other threads:[~2019-02-08  9:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-08  7:34 Alexey Dobriyan
2019-02-08  9:31 ` Joe Perches [this message]
2019-02-09 13:02   ` Alexey Dobriyan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=061655a972b4037b5bf245a65aed937967410e61.camel@perches.com \
    --to=joe@perches.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [PATCH] lib/string.c: make strncmp() smaller' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).