public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ian Molton <spyro@armlinux.org>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hex <-> int conversion routines.
Date: Sat, 23 Feb 2002 02:30:07 +0000	[thread overview]
Message-ID: <20020223023007.7e929392.spyro@armlinux.org> (raw)
In-Reply-To: <a4ucfg$tfa$1@cesium.transmeta.com>
In-Reply-To: <02021919493204.00447@jakob> <200202191902.g1JJ2wx28246@frodo.gams.co.at> <a4ucfg$tfa$1@cesium.transmeta.com>

On a sunny 19 Feb 2002 12:27:28 -0800 H. Peter Anvin gathered a sheaf of
electrons and etched in their motions the following immortal words:

> extern const char inthex_digits[];
> static __inline__ char inthex_nybble(int x)
> {
> 	return inthex_digits[x & 15];
> }

What about the following? It maintains the exact behaviour of the original,
but can be smaller if it doesnt have to deal with >15 in the input (then it
wont need the x &= 0x0f).

It would be 3 cycles for <10 and 4 for >=10 on ARM. I'd imagine this would
be a little quicker than a load from memory as in the above example.

plus it doesnt waste 16 bytes of RAM in a lookup table.

static inline char inthex_nybble(int x){
        x &= 0x0f;
        return  x<10?x^48:x+87;
}

Just a thought...

  reply	other threads:[~2002-02-23  2:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-19 15:39 [PATCH] hex <-> int conversion routines Jakob Kemi
2002-02-19 15:52 ` Martin Dalecki
2002-02-19 18:49   ` Jakob Kemi
2002-02-19 19:02     ` Bernd Petrovitsch
2002-02-19 20:27       ` H. Peter Anvin
2002-02-23  2:30         ` Ian Molton [this message]
2002-02-19 19:04     ` H. Peter Anvin
2002-02-20 10:25     ` Martin Dalecki
2002-02-19 16:51 ` Richard B. Johnson
2002-02-19 18:02 ` Linus Torvalds
2002-02-19 20:29   ` george anzinger

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=20020223023007.7e929392.spyro@armlinux.org \
    --to=spyro@armlinux.org \
    --cc=hpa@zytor.com \
    --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