From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
"Peter Zijlstra \(Intel\)" <peterz@infradead.org>,
Tejun Heo <tj@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [RFC] lib/vsprintf.c: Even faster decimal conversion
Date: Wed, 18 Mar 2015 18:10:23 +0100 [thread overview]
Message-ID: <87r3sm2pvk.fsf@rasmusvillemoes.dk> (raw)
In-Reply-To: <CAK1hOcNsVyHHFX4e+=-_2MrWFnjDedWcO0sS+2gatCeLrV20sw@mail.gmail.com> (Denys Vlasenko's message of "Wed, 18 Mar 2015 01:50:35 +0100")
On Wed, Mar 18 2015, Denys Vlasenko <vda.linux@googlemail.com> wrote:
> Your code does four 16-bit stores.
> The version below does two 32-bit ones instead,
> and it is also marginally smaller.
>
> char *put_dec_full8(char *buf, unsigned r)
> {
> unsigned q;
> u32 v;
>
> /* 0 <= r < 10^8 */
> q = (r * (u64)0x28f5c29) >> 32;
> v = (u32)decpair[r - 100*q] << 16;
>
> /* 0 <= q < 10^6 */
> r = (q * (u64)0x28f5c29) >> 32;
> v = v | decpair[q - 100*r];
> ((u32*)buf)[0] = v;
>
> /* 0 <= r < 10^4 */
> q = (r * 0x147b) >> 19;
> v = (u32)decpair[r - 100*q] << 16;
>
> /* 0 <= q < 100 */
> v = v | decpair[q];
> ((u32*)buf)[1] = v;
>
> return buf + 8;
> }
>
> It may be faster not only because of having fewer stores,
> but because on x86, this code (moving 16-bit halves):
>
> movw decpair(%ebx,%ebx), %dx
> movw %dx, 4(%eax)
> movw decpair(%ecx,%ecx), %dx
> movw %dx, 6(%eax)
>
> suffers from register merge stall when 16-bit value
> is read into lower part of %edx. 32-bit code
> has no such stalls:
>
> movzwl decpair(%ebx,%ebx), %edx
> sall $16, %edx
> movzwl decpair(%ecx,%ecx), %ecx
> orl %ecx, %edx
> movl %edx, 4(%eax)
>
[On little-endian, I'm pretty sure the <<16 should be applied to the
second and fourth decpair value.]
Thanks for the suggestion. However, I don't see any change in the size
of the generated code (gcc 4.7), and, at least on my Xeon machine,
converting both ULONG_MAX and uniformly random u64s becomes slightly
slower (54 vs 56 cycles and 61 vs 65 cycles).
Rasmus
prev parent reply other threads:[~2015-03-18 17:10 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-20 23:51 Rasmus Villemoes
2015-03-05 15:22 ` Rasmus Villemoes
2015-03-05 16:03 ` Joe Perches
2015-03-05 16:10 ` Tejun Heo
2015-03-05 22:24 ` Rasmus Villemoes
2015-03-10 10:47 ` Rasmus Villemoes
2015-03-10 12:42 ` Tejun Heo
2015-03-10 12:57 ` Rasmus Villemoes
2015-03-10 23:01 ` [PATCH v1] " Rasmus Villemoes
2015-03-11 21:52 ` Andrew Morton
2015-03-19 21:41 ` Rasmus Villemoes
2015-03-12 18:49 ` Jeff Epler
2015-03-13 0:08 ` Jeff Epler
2015-03-13 0:30 ` Jeff Epler
2015-03-13 8:58 ` [PATCH] lib/vsprintf.c: silence sparse warnings about decpair[] initialization Rasmus Villemoes
2015-03-19 21:44 ` [PATCH] lib/vsprintf.c: improve put_dec_trunc8 slightly Rasmus Villemoes
2015-03-18 0:50 ` [RFC] lib/vsprintf.c: Even faster decimal conversion Denys Vlasenko
2015-03-18 0:52 ` Denys Vlasenko
2015-03-18 17:10 ` Rasmus Villemoes [this message]
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=87r3sm2pvk.fsf@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=tj@kernel.org \
--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
all inboxes | Powered by JetHome®