public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Steve Grubb" <ddata@gate.net>
To: <linux-kernel@vger.kernel.org>
Subject: Re: [Patch] performance enhancement for simple_strtoul
Date: Wed, 20 Dec 2000 13:42:56 -0500	[thread overview]
Message-ID: <001401c06ab4$ac8615e0$7d1a24cf@master> (raw)
In-Reply-To: <000e01c06a8e$6945db60$bc1a24cf@master> <20001220100446.A1249@inetnebr.com>

Hello,

I continued experimenting with the Test Case and found a further speed
improvement & I am re-submiting the patch. It is the same as the first one
with the two local variables changed to register storage types.

On a K6-2, I now see:
Base 10 - 28% speedup
Base 16 - 24% speedup
Base 8 - 30% speedup

On a P3 system, I now see:
Base 10 - 25% speedup
Base 16 - 17% speedup
Base 8 - 20% speedup

It seems gcc creates much better code with the variables set to register
types. Please apply the following patch. It should apply to any recent 2.2.x
without problems. In 2.4 the function starts 2 lines later.

Cheers,
Steve Grubb

----------------------------------

 --- lib/vsprintf.orig Fri Dec  1 08:58:02 2000
+++ lib/vsprintf.c Wed Dec 20 13:14:13 2000
@@ -14,10 +14,13 @@
 #include <linux/string.h>
 #include <linux/ctype.h>

+/*
+* This function converts base 8, 10, or 16 only - Steve Grubb
+*/
 unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base)
 {
- unsigned long result = 0,value;
-
+ register unsigned char c;
+ register unsigned long result = 0;
  if (!base) {
   base = 10;
   if (*cp == '0') {
@@ -29,11 +32,36 @@
    }
   }
  }
- while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp)
-     ? toupper(*cp) : *cp)-'A'+10) < base) {
-  result = result*base + value;
-  cp++;
- }
+ c = *cp;
+        switch (base) {
+                case 10:
+                        while (isdigit(c)) {
+                                result = (result*10) + (c & 0x0f);
+                                c = *(++cp);
+                        }
+                        break;
+                case 16:
+                        while (isxdigit(c)) {
+                                result = result<<4;
+                                if (c&0x40)
+                                         result += (c & 0x07) + 9;
+                                else
+                                        result += c & 0x0f;
+                                c = *(++cp);
+                        }
+                        break;
+                case 8:
+                        while (isdigit(c)) {
+                                if ((c&0x37) == c)
+                                        result = (result<<3) + (c & 0x07);
+                                else
+                                        break;
+                                c = *(++cp);
+                        }
+                        break;
+                default: /* Is anything else used by the kernel? */
+                        break;
+        }
  if (endp)
   *endp = (char *)cp;
  return result;



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

  parent reply	other threads:[~2000-12-20 19:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-12-20 14:09 [Patch] performance enhancement for simple_strtoul Steve Grubb
2000-12-20 16:04 ` Jeff Epler
2000-12-20 16:35   ` Steve Grubb
2000-12-20 18:42   ` Steve Grubb [this message]
2000-12-21  0:09     ` Jamie Lokier
2000-12-21 20:06       ` Pavel Machek
2000-12-28  5:15         ` Jamie Lokier
2000-12-21  9:16 ` Matthias Andree
2000-12-21 10:28   ` Bernd Schmidt
2000-12-21 16:07   ` Alan Cox
2000-12-21 20:05 ` Pavel Machek

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='001401c06ab4$ac8615e0$7d1a24cf@master' \
    --to=ddata@gate.net \
    --cc=linux-kernel@vger.kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox