[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160629122456.2d5b08f0@gandalf.local.home>
Date: Wed, 29 Jun 2016 12:24:56 -0400
From: Steven Rostedt <rostedt@...dmis.org>
To: zengzhaoxiu@....com
Cc: linux-kernel@...r.kernel.org,
Zhaoxiu Zeng <zhaoxiu.zeng@...il.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Hidehiro Kawai <hidehiro.kawai.ez@...achi.com>,
Michal Nazarewicz <mina86@...a86.com>,
Borislav Petkov <bp@...e.de>, Michal Hocko <mhocko@...e.com>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
Nicolas Iooss <nicolas.iooss_linux@....org>,
Gustavo Padovan <gustavo.padovan@...labora.co.uk>,
Geert Uytterhoeven <geert@...ux-m68k.org>,
Horacio Mijail Anton Quiles <hmijail@...il.com>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Subject: Re: [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin
On Thu, 30 Jun 2016 00:15:54 +0800
zengzhaoxiu@....com wrote:
> From: Zhaoxiu Zeng <zhaoxiu.zeng@...il.com>
I have to ask, what hot paths call this where we need to add a table
for optimization. And there's a chance that this wont even optimize the
flow and may even slow down execution as the table will now need to be
loaded into cache.
-- Steve
>
> Signed-off-by: Zhaoxiu Zeng <zhaoxiu.zeng@...il.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
Powered by blists - more mailing lists