From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751530AbcF2Q0m (ORCPT ); Wed, 29 Jun 2016 12:26:42 -0400 Received: from smtprelay0225.hostedemail.com ([216.40.44.225]:52955 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751207AbcF2Q0l (ORCPT ); Wed, 29 Jun 2016 12:26:41 -0400 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::::::::::::::::::::::,RULES_HIT:41:69:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1543:1593:1594:1605:1711:1730:1747:1777:1792:2393:2553:2559:2562:2693:3138:3139:3140:3141:3142:3151:3622:3865:3866:3867:3868:3870:3874:4321:4605:5007:6261:6742:7514:7576:7875:7903:8660:10004:10400:10450:10455:10848:10967:11026:11232:11658:11914:12043:12517:12519:12555:12683:12740:13148:13230:13439:13891:14096:14097:14181:14659:14721:19904:19999:21080:21433,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: mass28_487a96bf01a2a X-Filterd-Recvd-Size: 4764 Date: Wed, 29 Jun 2016 12:24:56 -0400 From: Steven Rostedt To: zengzhaoxiu@163.com Cc: linux-kernel@vger.kernel.org, Zhaoxiu Zeng , Andrew Morton , Hidehiro Kawai , Michal Nazarewicz , Borislav Petkov , Michal Hocko , Rasmus Villemoes , Nicolas Iooss , Gustavo Padovan , Geert Uytterhoeven , Horacio Mijail Anton Quiles , Andy Shevchenko Subject: Re: [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin Message-ID: <20160629122456.2d5b08f0@gandalf.local.home> In-Reply-To: <1467216957-58885-1-git-send-email-zengzhaoxiu@163.com> References: <1467216957-58885-1-git-send-email-zengzhaoxiu@163.com> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 30 Jun 2016 00:15:54 +0800 zengzhaoxiu@163.com wrote: > From: Zhaoxiu Zeng 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 > --- > 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