public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Randy Dunlap <rdunlap@infradead.org>
Subject: Re: [PATCH next 1/1] lib: Optimise hex_dump_to_buffer()
Date: Sun, 16 Feb 2025 22:37:15 +0000	[thread overview]
Message-ID: <20250216223715.734fedc8@pumpkin> (raw)
In-Reply-To: <Z7JO9eutvu3KBEbc@smile.fi.intel.com>

On Sun, 16 Feb 2025 22:47:49 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> On Sun, Feb 16, 2025 at 08:19:01PM +0000, David Laight wrote:
> > Fastpath the normal case of single byte output that fits in the buffer.
> > Output byte groups (byteswapped on little-endian) without calling snprintf().
> > Remove the restriction that rowsize must be 16 or 32.
> > Remove the restriction that groupsize must be 8 or less.
> > If groupsize isn't a power of 2 or doesn't divide into both len and
> >   rowsize it is set to 1 (otherwise byteswapping is hard).
> > Change the types of the rowsize and groupsize parameters to be unsigned types.  
> 
> > Tested in a userspace harness, code size (x86-64) halved to 723 bytes.  
> 
> Does it imply running the respective test cases we have?
> Do you need to add more test cases? I believe so.
> Without test cases added it's a no go.
> 
> > +extern size_t hex_dump_to_buffer(const void *buf, size_t len, size_t rowsize,
> > +			      size_t groupsize, char *linebuf,
> > +			      size_t linebuflen, bool ascii);  
> 
> Looking at another thread where upper layer function wants to have unsigned
> long flags instead of bool ascii, I would also do the new API, that takes flags
> and leave the old one as a simple wrapper with all restrictions being applied.

I can't imagine any code relying on the rowsize being converted to 16.
And (elsewhere) I've definitely needed to do hexdumps with strange numbers
of bytes/line.

> 
> And again, provide it together with a bunch of test cases.
> 
> ...
> 
> > +			dst[0] = hex_asc_hi(ch);
> > +			dst[1] = hex_asc_lo(ch);  
> 
> We have hex_pack_byte() or so

At least some versions of gcc have generated better code if you don't
use *ptr++ but do the increment afterwards.
It is also what the old version used.
Not to mention being another wrapper you need to look up to work out
what the code is doing.

..
> ...
> 
> > -		linebuf[lx++] = (isascii(ch) && isprint(ch)) ? ch : '.';
> > +		*dst++ = ch >= ' ' && ch < 0x7f ? ch : '.';  
> 
> Please also add a test case for this to make sure it has no changes.

Well isascii() usually checks for the 0x80 bit being clear and isprint()
rejects control characters and 'del' (0x7f).
I'm not sure what isascii() does for EBCDIC type charsets - but I don't
expect Linux runs on any of those so who cares.
Oh, and isprint() seems to be based on a memory lookup in an _ctype[] array.
Very 1970s.

	David

> 


  reply	other threads:[~2025-02-16 22:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-16 20:19 [PATCH next 1/1] lib: Optimise hex_dump_to_buffer() David Laight
2025-02-16 20:47 ` Andy Shevchenko
2025-02-16 22:37   ` David Laight [this message]
2025-02-18 11:38     ` Andy Shevchenko
2025-02-18 22:52 ` Nick Child
2025-02-19 13:13   ` David Laight
2025-02-19 19:29   ` David Laight

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=20250216223715.734fedc8@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=torvalds@linux-foundation.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