[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20090815141212.GA7692@localdomain.by>
Date: Sat, 15 Aug 2009 17:12:12 +0300
From: Sergey Senozhatsky <sergey.senozhatsky@...il.com>
To: "Robert P. J. Day" <rpjday@...shcourse.ca>
Cc: Jiri Slaby <jirislaby@...il.com>,
Andrew Morton <akpm@...ux-foundation.org>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] Make shr to divide by power of 2 (resend)
On (08/15/09 09:49), Robert P. J. Day wrote:
> Date: Sat, 15 Aug 2009 09:49:15 -0400 (EDT)
> From: "Robert P. J. Day" <rpjday@...shcourse.ca>
> To: Jiri Slaby <jirislaby@...il.com>
> cc: Sergey Senozhatsky <sergey.senozhatsky@...il.com>,
> Andrew Morton <akpm@...ux-foundation.org>,
> linux-kernel@...r.kernel.org
> Subject: Re: [PATCH] Make shr to divide by power of 2 (resend)
> User-Agent: Alpine 2.00 (LFD 1167 2008-08-23)
>
> On Sat, 15 Aug 2009, Jiri Slaby wrote:
>
> > On 08/15/2009 03:43 PM, Sergey Senozhatsky wrote:
> > > Make an arithmetic right shift to divide by power of 2.
> >
> > Why? Is out there a compiler not doing that?
> >
> > Seems like it should be rather converted to DIV_ROUND_UP.
> >
It was duscussed, so I'll just copy paste my answer.
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;
> it does seem like a DIV_ROUND_UP would be better but perhaps another
> solution would be to define a meaningful macro name for that
> operation. if that conversion is going to be done regularly, a macro
> with an informative name might be in order. if it's a one-shot
> operation, though, not much point.
>
No, it's not a one-shot.
grep -c '>>' bitblit.c
7
Sergey
Download attachment "signature.asc" of type "application/pgp-signature" (316 bytes)
Powered by blists - more mailing lists