From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: zengzhaoxiu@163.com, linux-kernel@vger.kernel.org
Cc: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Hidehiro Kawai <hidehiro.kawai.ez@hitachi.com>,
Michal Nazarewicz <mina86@mina86.com>,
Borislav Petkov <bp@suse.de>, Michal Hocko <mhocko@suse.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Nicolas Iooss <nicolas.iooss_linux@m4x.org>,
"Steven Rostedt (Red Hat)" <rostedt@goodmis.org>,
Gustavo Padovan <gustavo.padovan@collabora.co.uk>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Horacio Mijail Anton Quiles <hmijail@gmail.com>
Subject: Re: [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin
Date: Wed, 29 Jun 2016 19:22:46 +0300 [thread overview]
Message-ID: <1467217366.30123.334.camel@linux.intel.com> (raw)
In-Reply-To: <1467216957-58885-1-git-send-email-zengzhaoxiu@163.com>
On Thu, 2016-06-30 at 00:15 +0800, zengzhaoxiu@163.com wrote:
> From: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
>
No way.
At least commit message.
And prerequisite is the performance / memory foot print tests.
> Signed-off-by: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
> ---
> include/linux/kernel.h | 15 ++++++++++++++-
> lib/hexdump.c | 36 +++++++++++++++++++-----------------
> 2 files changed, 33 insertions(+), 18 deletions(-)
>
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index 94aa10f..72a0432 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -532,7 +532,20 @@ static inline char *hex_byte_pack_upper(char
> *buf, u8 byte)
> return buf;
> }
>
> -extern int hex_to_bin(char ch);
> +extern const int8_t h2b_lut[];
> +
> +/**
> + * hex_to_bin - convert a hex digit to its real value
> + * @ch: ascii character represents hex digit
> + *
> + * hex_to_bin() converts one hex digit to its actual value or -1 in
> case of bad
> + * input.
> + */
> +static inline int hex_to_bin(char ch)
> +{
> + return h2b_lut[(unsigned char)ch];
> +}
> +
> extern int __must_check hex2bin(u8 *dst, const char *src, size_t
> count);
> extern char *bin2hex(char *dst, const void *src, size_t count);
>
> diff --git a/lib/hexdump.c b/lib/hexdump.c
> index 992457b..878697f 100644
> --- a/lib/hexdump.c
> +++ b/lib/hexdump.c
> @@ -18,23 +18,25 @@ EXPORT_SYMBOL(hex_asc);
> const char hex_asc_upper[] = "0123456789ABCDEF";
> EXPORT_SYMBOL(hex_asc_upper);
>
> -/**
> - * hex_to_bin - convert a hex digit to its real value
> - * @ch: ascii character represents hex digit
> - *
> - * hex_to_bin() converts one hex digit to its actual value or -1 in
> case of bad
> - * input.
> - */
> -int hex_to_bin(char ch)
> -{
> - if ((ch >= '0') && (ch <= '9'))
> - return ch - '0';
> - ch = tolower(ch);
> - if ((ch >= 'a') && (ch <= 'f'))
> - return ch - 'a' + 10;
> - return -1;
> -}
> -EXPORT_SYMBOL(hex_to_bin);
> +const int8_t h2b_lut[] = {
> + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
> -1,
> + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
> -1,
> + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
> -1,
> + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1,
> -1,
> + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1,
> -1,
> + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
> -1,
> + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1,
> -1,
> + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
> -1,
> + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
> -1,
> + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
> -1,
> + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
> -1,
> + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
> -1,
> + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
> -1,
> + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
> -1,
> + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
> -1,
> + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
> -1,
> +};
> +EXPORT_SYMBOL(h2b_lut);
>
> /**
> * hex2bin - convert an ascii hexadecimal string to its binary
> representation
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
next prev parent reply other threads:[~2016-06-29 16:23 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-29 16:15 [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin zengzhaoxiu
2016-06-29 16:22 ` [PATCH 2/2] lib: kstrtox: _parse_integer: use hex_to_bin instead local conversion, and reduce branches zengzhaoxiu
2016-06-29 22:06 ` Alexey Dobriyan
2016-06-30 14:45 ` Zhaoxiu Zeng
2016-06-29 16:22 ` Andy Shevchenko [this message]
2016-06-29 16:24 ` [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin Steven Rostedt
2016-06-29 18:31 ` Michal Nazarewicz
2016-06-29 18:52 ` Andy Shevchenko
2016-06-30 19:26 ` Joe Perches
2016-06-30 19:42 ` Geert Uytterhoeven
2016-06-30 20:06 ` Joe Perches
2016-06-30 20:44 ` Andy Shevchenko
2016-06-30 21:18 ` Michal Nazarewicz
2016-06-30 14:21 ` Zhaoxiu Zeng
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=1467217366.30123.334.camel@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=bp@suse.de \
--cc=geert@linux-m68k.org \
--cc=gustavo.padovan@collabora.co.uk \
--cc=hidehiro.kawai.ez@hitachi.com \
--cc=hmijail@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=mhocko@suse.com \
--cc=mina86@mina86.com \
--cc=nicolas.iooss_linux@m4x.org \
--cc=rostedt@goodmis.org \
--cc=zengzhaoxiu@163.com \
--cc=zhaoxiu.zeng@gmail.com \
/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