From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Jiri Slaby <jirislaby@gmail.com>
Cc: Andi Kleen <andi@firstfloor.org>,
"Robert P. J. Day" <rpjday@crashcourse.ca>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Make shr to divide by power of 2 (resend)
Date: Sun, 16 Aug 2009 12:14:25 +0300 [thread overview]
Message-ID: <20090816091425.GB7968@localdomain.by> (raw)
In-Reply-To: <4A871DAF.10609@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2714 bytes --]
On (08/15/09 22:42), Jiri Slaby wrote:
> On 08/15/2009 04:12 PM, Sergey Senozhatsky wrote:
> > On (08/15/09 09:49), Robert P. J. Day wrote:
> >> 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.
>
> I think Andi (Cced again) meant divisor. When a divisor is constant, you
> can always transform division to some of subs/adds/muls/shifts.
Cced Andi Kleen <andi@firstfloor.org>
>
> > 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
>
> Then please use DIV_ROUND_UP macro (or whatever alias) all over the place.
>
Sorry, once again (just to clear).
There are different shr/shl operations in bitblit.c. Like,
#1
cur_height = vc->vc_font.height >> 1
cur_height = (vc->vc_font.height << 1)/3;
c |= c >> 1;
u32 idx = vc->vc_font.width >> 3;
etc.
So, should I convert it to something like:
#2
cur_height = DIV_XXX(vc->vc_font.height, 2)
cur_height = DIV_XXX( MUL_XXX(vc->vc_font.height, 2), 3); or cur_height = DIV_XXX( (vc->vc_font.height * 2), 3);
c |= DIV_XXX(c, 1);
u32 idx = DIV_XXX(vc->vc_font.width, 8);
#1 is better-looking I think.
Sergey
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 315 bytes --]
next prev parent reply other threads:[~2009-08-16 9:11 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-15 13:43 Sergey Senozhatsky
2009-08-15 13:48 ` Jiri Slaby
2009-08-15 13:49 ` Robert P. J. Day
2009-08-15 14:12 ` Sergey Senozhatsky
2009-08-15 20:42 ` Jiri Slaby
2009-08-16 9:14 ` Sergey Senozhatsky [this message]
2009-08-17 7:15 ` Jiri Slaby
2009-08-17 7:31 ` Sergey Senozhatsky
2009-08-17 7:48 ` [PATCH 1/1] VIDEO: console, use DIV_ROUND_UP Jiri Slaby
2009-08-17 8:00 ` Sergey Senozhatsky
2009-08-17 8:00 ` Jiri Slaby
2009-08-17 8:08 ` Sergey Senozhatsky
2009-08-17 8:11 ` Jiri Slaby
2009-08-15 14:26 ` [PATCH] Make shr to divide by power of 2 (resend) 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=20090816091425.GB7968@localdomain.by \
--to=sergey.senozhatsky@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=jirislaby@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rpjday@crashcourse.ca \
/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®