From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Andi Kleen <andi@firstfloor.org>
Cc: Robert Hancock <hancockrwd@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: Sun, 9 Aug 2009 12:40:48 +0300 [thread overview]
Message-ID: <20090809094048.GA3100@localdomain.by> (raw)
In-Reply-To: <20090808073534.GA12190@basil.fritz.box>
[-- Attachment #1: Type: text/plain, Size: 2086 bytes --]
On (08/08/09 10:22), Robert Hancock wrote:
> Actually, the Intel Architecture Optimization Reference Manual doesn't
> say divide may be faster, but it does say that "On processors based on
> Intel NetBurst microarchitecture, latencies of some instructions are
> relatively significant (including shifts, rotates, integer multiplies,
> and moves from memory with sign extension)." and that "The SHIFT and
> ROTATE instructions have a longer latency on processor with a CPUID
> signature corresponding to family 15 and model encoding of 0, 1, or 2.
> The latency of a sequence of adds will be shorter for left shifts of three or less."
Intel Architecture Optimization Reference Manual does say about latency:
Table C-13a. General Purpose Instructions
Instruction Latency Throughput
IDIV | 11-21 13-23 17-41 22 | 5-13 5-14 12-36 22
SAL/SAR/SHL/SHR | 1 1 1 | 0.33 0.33 0.33
For example,
Table 12-2. Intel® Atom™ Microarchitecture Instructions Latency Data
Instruction Latency Throughput
IDIV r/m8; IDIV r/m16; | 33;42; | 32;41;56;196
IDIV r/m32; IDIV r/m64; | 57;197 |
| |
ROL; ROR; SAL; | 1 | 1
SAR; SHL; SHR | |
*SHLD/SHRD |4;2-11 |3;1-10
On (08/08/09 09:35), Andi Kleen wrote:
> 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.
>
int width = (vc->vc_font.width + 7) >> 3;
> That said -Os sometimes screws us up on this, but it's still not worth
> doing this change manually.
>
My point is that it should 'look the same'.
I mean there are 5
int width = (vc->vc_font.width + 7) >> 3;
*not exactly this one, but vc->vc_font.width (+ 7)? >> 3
and _only_ one
int width = (vc->vc_font.width + 7) / 8;
P.S.
Sorry, hit "reply", not "reply to all".
Sergey
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 315 bytes --]
prev parent reply other threads:[~2009-08-09 9:37 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
2009-08-09 9:40 ` Sergey Senozhatsky [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=20090809094048.GA3100@localdomain.by \
--to=sergey.senozhatsky@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=hancockrwd@gmail.com \
--cc=linux-kernel@vger.kernel.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