Re: [PATCH 03/15] print_integer: new and improved way of printing integers
From: Matthew Wilcox
Date: Tue Apr 21 2020 - 12:59:51 EST
On Mon, Apr 20, 2020 at 11:57:31PM +0300, Alexey Dobriyan wrote:
> 1) memcpy is done in forward direction
> it can be done backwards but nobody does that,
If you're determined to do this, then use memmove() which actually
guarantees to work with overlapping ranges. Don't rely on non-guaranteed
behaviour of current implementations of memcpy(). Did you really check
the two dozen assembly implementations of memcpy() in the kernel?
> 2) digits can be extracted in a very simple loop which costs only
> 1 multiplication and shift (division by constant is not division)
> +noinline
> +char *_print_integer_u32(char *p, u32 x)
> +{
> + do {
> + *--p = '0' + (x % 10);
> + } while (x /= 10);
> + return p;
> +}
Why not do two digits at a time like put_dec() does?