public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "George Spelvin" <linux@horizon.com>
To: andy.shevchenko@gmail.com, iveqy@iveqy.com
Cc: linux@horizon.com, linux-kernel@vger.kernel.org
Subject: Re: hex_to_bin speedup
Date: 28 May 2010 17:38:21 -0400	[thread overview]
Message-ID: <20100528213821.4351.qmail@science.horizon.com> (raw)

1) First of all, I'd worry about code size far more than speed.
   this is not fast-path code.
2) Second, given that you're already doing a range test,
   the fastest way to perform a tolower() is "c |= 0x20".

Generally it's something like:
int hex_to_bin(char ch)
{
	ch -= '0';
	if ((unsigned char)ch <= 9)
		return ch;
	ch |= 0x20;
	ch -= 'a' - '0';
	if ((unsigned char)ch <= 6)
		return ch+10
	return -1;
}


that produces the even smaller code:
hex_to_bin_or:
        movb    4(%esp), %dl
        subl    $48, %edx
        cmpb    $9, %dl
        movsbl  %dl,%eax
        jbe     .L10
        orl     $32, %edx
        orl     $-1, %eax
        subl    $49, %edx
        cmpb    $6, %dl
        ja      .L10
        movsbl  %dl,%eax
        addl    $10, %eax
.L10:
        ret


             reply	other threads:[~2010-05-28 21:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-28 21:38 George Spelvin [this message]
  -- strict thread matches above, loose matches on Subject: below --
2010-05-27 10:07 hex_to_bin speedup Fredrik Gustafsson
     [not found] ` <AANLkTinn7aEv0ueW4uRN06XdUbEltTfmjRXEABMRN-7e@mail.gmail.com>
     [not found]   ` <20100527142848.GA23543@iveqy.com>
2010-05-27 16:35     ` Andy Shevchenko
2010-05-28 21:05       ` Fredrik Gustafsson

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=20100528213821.4351.qmail@science.horizon.com \
    --to=linux@horizon.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=iveqy@iveqy.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