From: Andi Kleen <andi@firstfloor.org>
To: Robert Hancock <hancockrwd@gmail.com>
Cc: Andi Kleen <andi@firstfloor.org>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Make shr to divide by power of 2
Date: Sat, 8 Aug 2009 09:35:34 +0200 [thread overview]
Message-ID: <20090808073534.GA12190@basil.fritz.box> (raw)
In-Reply-To: <4A7CEC70.4050806@gmail.com>
On Fri, Aug 07, 2009 at 09:09:36PM -0600, Robert Hancock wrote:
> On 08/07/2009 12:50 AM, Andi Kleen wrote:
>> Sergey Senozhatsky<sergey.senozhatsky@gmail.com> writes:
>>> Of course, compiler supposed to do something like
>>> add $0x7,%eax
>>> shr $0x3,%eax
>>> instead of div. Should we rely on this?
>>
>> Yes. We should rely on this.
>
> It may depend on the selected CPU type that gcc is optimizing for - I
> believe that on some P4s the shift may actually be slower than the divide..
DIV should be always slower than a SHIFT.
But it has nothing really to do with the CPU. The point is that the compiler
always selects a suitable one by itself. Rewriting x / 2 to x >> 1 is
one of the easiest exercises in compiler optimizations.
The only case when the compiler cannot do this easily by itself is
when the dividend is not a constant.
That said -Os sometimes screws us up on this, but it's still not worth
doing this change manually.
-Andi
--
ak@linux.intel.com -- Speaking for myself only.
next prev parent reply other threads:[~2009-08-08 7:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-06 18:09 [PATCH] Make shr to divide by power of 2 Sergey Senozhatsky
2009-08-07 6:50 ` Andi Kleen
2009-08-07 7:42 ` Sergey Senozhatsky
2009-08-08 3:09 ` Robert Hancock
2009-08-08 7:35 ` Andi Kleen [this message]
2009-08-09 9:40 ` Sergey Senozhatsky
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=20090808073534.GA12190@basil.fritz.box \
--to=andi@firstfloor.org \
--cc=akpm@linux-foundation.org \
--cc=hancockrwd@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sergey.senozhatsky@gmail.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