From: Andrew Morton <akpm@linux-foundation.org>
To: Denys Vlasenko <vda.linux@googlemail.com>
Cc: linux-kernel@vger.kernel.org,
Douglas W Jones <jones@cs.uiowa.edu>,
Michal Nazarewicz <mnazarewicz@google.com>
Subject: Re: [PATCH 1/1] vsprintf: optimize decimal conversion (again)
Date: Mon, 26 Mar 2012 12:51:29 -0700 [thread overview]
Message-ID: <20120326125129.78975baf.akpm@linux-foundation.org> (raw)
In-Reply-To: <201203262051.24271.vda.linux@googlemail.com>
On Mon, 26 Mar 2012 20:51:24 +0200
Denys Vlasenko <vda.linux@googlemail.com> wrote:
> commit 01a2904d31d2373886f489429ec662c9be64a6ab
> Author: Denys Vlasenko <vda.linux@googlemail.com>
> Date: Mon Mar 26 20:40:53 2012 +0200
>
> vsprintf: optimize decimal conversion (again)
>
> Previous code was using optimizations which were developed
> to work well even on narrow-word CPUs (by today's standards).
> But Linux runs only on 32-bit and wider CPUs. We can use that.
>
> First: using 32x32->64 multiply and trivial 32-bit shift,
> we can correctly divide by 10 much larger numbers, and thus
> we can print groups of 9 digits instead of groups of 5 digits.
>
> Next: there are two algorithms to print larger numbers.
> One is generic: divide by 1000000000 and repeatedly print
> groups of (up to) 9 digits. It's conceptually simple,
> but requires an (unsigned long long) / 1000000000 division.
>
> Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
> manipulates them cleverly and generates groups of 4 decimal digits.
> It so happens that it does NOT require long long division.
>
> If long is > 32 bits, division of 64-bit values is relatively easy,
> and we will use the first algorithm.
> If long long is > 64 bits (strange architecture with VERY large long long),
> second algorithm can't be used, and we again use the first one.
>
> Else (if long is 32 bits and long long is 64 bits) we use second one.
>
> And third: there is a simple optimization which takes fast path
> not only for zero as was done before, but for all one-digit numbers.
>
> In all tested cases new code is faster than old one, in many cases by 30%,
> in few cases by more than 50% (for example, on x86-32, conversion of 12345678).
> Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit case.
>
This patch is so nutty that I like it.
> +#if BITS_PER_LONG != 32 || (~(0ULL)>>1) != ((1ULL<<63)-1)
What's this for?
next prev parent reply other threads:[~2012-03-26 19:51 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-26 18:47 [PATCH 0/1] vsprintf: optimize decimal conversion (again) Denys Vlasenko
2012-03-26 18:51 ` [PATCH 1/1] " Denys Vlasenko
2012-03-26 19:51 ` Andrew Morton [this message]
2012-03-26 19:56 ` Denys Vlasenko
2012-03-26 20:13 ` Andrew Morton
2012-03-26 20:18 ` Geert Uytterhoeven
2012-03-26 23:18 ` Denys Vlasenko
2012-03-27 0:30 ` Denys Vlasenko
2012-03-27 3:49 ` H. Peter Anvin
2012-03-26 20:20 ` H. Peter Anvin
2012-03-27 17:12 ` Michal Nazarewicz
2012-03-27 17:17 ` H. Peter Anvin
2012-03-27 0:26 ` Denys Vlasenko
2012-03-27 12:08 ` [PATCH 0/1] " roma1390
2012-03-27 15:32 ` Denys Vlasenko
2012-03-27 15:42 ` Denys Vlasenko
2012-03-28 5:56 ` roma1390
2012-03-28 10:13 ` Denys Vlasenko
2012-03-28 10:24 ` roma1390
2012-03-28 10:33 ` Denys Vlasenko
2012-03-28 10:39 ` roma1390
2012-03-28 11:20 ` Denys Vlasenko
2012-03-29 10:35 ` Denys Vlasenko
2012-03-28 10:31 ` roma1390
2012-03-28 11:23 ` Denys Vlasenko
2012-03-29 5:23 ` roma1390
2012-03-29 10:33 ` Denys Vlasenko
2012-03-27 13:49 ` roma1390
2012-03-27 15:33 ` Denys Vlasenko
2012-03-29 5:16 ` roma1390
2012-03-29 10:33 ` Denys Vlasenko
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=20120326125129.78975baf.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=jones@cs.uiowa.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=mnazarewicz@google.com \
--cc=vda.linux@googlemail.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