From: arnd@arndb.de (Arnd Bergmann)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] optimize ktime_divns for constant divisors
Date: Thu, 04 Dec 2014 15:56:47 +0100 [thread overview]
Message-ID: <2362381.LDAGLC19vb@wuerfel> (raw)
In-Reply-To: <alpine.LFD.2.11.1412040837130.470@knanqh.ubzr>
On Thursday 04 December 2014 08:46:27 Nicolas Pitre wrote:
> On Thu, 4 Dec 2014, Arnd Bergmann wrote:
> Note the above code is for 32-bit architectures that support a 32x32=64
> bit multiply instruction. And even then, what kills performances is the
> inhability to efficiently deal with carry bits from C code. Hence the
> far better output from do_div() on ARM.
>
> If x86-64 has a 64x64=128 bit multiply instruction then the above may
> greatly be simplified to a single multiply and a shift. That would
> possibly outperform do_div().
I was trying this in 32-bit mode to see how it would work in x86-32
kernels. Since that architecture has a 64-by-32 divide instruction,
that gets used here.
x86-64 has a 64x64=128 multiply instruction and gcc uses that for
any 64-bit division by constant, so that's what already happens
in do_div. I assume for any 64-bit architecture, the result will
be similar.
I guess the only architectures that would benefit from your implementation
above are the ones that do not have any optimization for constant
64-by-32-bit division and just call do_div.
> > On a related note, I wonder if we can come up with a more efficient
> > implementation for do_div on ARMv7ve, and I think we should add the
> > Makefile logic to build with -march=armv7ve when we know that we do
> > not need to support processors without idiv.
>
> Multiplications will always be faster than divisions. However the idiv
> instruction would come very handy in the slow path when the divisor is
> not constant.
Makes sense. I also just checked the gcc sources and it seems that the
idiv/udiv instructions on ARM are not even used for implementing
__aeabi_uldivmod there. Not sure if that's intentional, but we probably
don't need to bother optimizing this in the kernel before user space
does. Building with -march=armv7ve still sounds helpful to avoid the
__aeabi_uidiv calls though.
Arnd
next prev parent reply other threads:[~2014-12-04 14:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-03 19:43 [PATCH] optimize ktime_divns for constant divisors Nicolas Pitre
2014-12-03 20:03 ` Arnd Bergmann
2014-12-04 7:23 ` Nicolas Pitre
2014-12-04 12:02 ` Arnd Bergmann
2014-12-04 13:46 ` Nicolas Pitre
2014-12-04 14:56 ` Arnd Bergmann [this message]
2014-12-04 16:47 ` Nicolas Pitre
[not found] ` <OF0EDEDB1C.C03829F7-ON48257DA5.00062083-48257DA5.0007628B@zte.com.cn>
2014-12-05 4:30 ` Nicolas Pitre
2014-12-05 10:08 ` Arnd Bergmann
2014-12-05 17:15 ` Nicolas Pitre
2014-12-03 20:16 ` Robert Jarzmik
2014-12-03 20:37 ` Nicolas Pitre
2014-12-05 18:00 ` Nicolas Pitre
2014-12-05 21:03 ` Arnd Bergmann
2014-12-18 21:21 ` John Stultz
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=2362381.LDAGLC19vb@wuerfel \
--to=arnd@arndb.de \
--cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).