lkml.org 
[lkml]   [2008]   [Aug]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: VolanoMark regression with 2.6.27-rc1
From
Date
On Wed, 2008-08-20 at 22:30 +0200, Peter Zijlstra wrote:
> On Wed, 2008-08-20 at 11:15 -0700, Ray Lee wrote:
> > On Wed, Aug 20, 2008 at 10:55 AM, Nick Piggin <nickpiggin@yahoo.com.au> wrote:
> > > On Thursday 21 August 2008 03:21, Peter Zijlstra wrote:
> > >> Ok, so one last time (I hope!)..
> > >>
> > >> Everybody happy with this?
> > >
> > >
> > >> Index: linux-2.6/include/linux/kernel.h
> > >> ===================================================================
> > >> --- linux-2.6.orig/include/linux/kernel.h
> > >> +++ linux-2.6/include/linux/kernel.h
> > >> @@ -367,6 +367,12 @@ static inline char *pack_hex_byte(char *
> > >> (void) (&_max1 == &_max2); \
> > >> _max1 > _max2 ? _max1 : _max2; })
> > >>
> > >> +#define avg(x, y) ({ \
> > >> + typeof(x) _avg1 = (x); \
> > >> + typeof(y) _avg2 = (y); \
> > >> + (void) (&_avg1 == &_avg2); \
> > >> + _avg1 + (_avg2 - _avg1)/2; })
> > >
> > > That's not going to work with unsigned types.
> >
> > Uhm, I think it works fine, even with unsigned, even where _avg2 is
> > smaller than _avg1. Underflow is a good thing here. And I mocked up a
> > little test harness and it gives the correct answers for a half dozen
> > sets of values I tossed at it
> >
> > But maybe I'm forgetting an obscure unsigned or signed int type
> > widening rule, so, care to elaborate?
>
> Nick is right, try:
>
> int main(int argc, char **argv)
> {
> unsigned int x = 7, y = 5;
> printf("%d\n", avg(x,y));
> return 0;
> }
>
> It fails because 5-7 = -2, which needs a signed division or sign
> extending right shift.
>
> we'd need something like:
>
> #define avg(x, y) ({ \
> typeof(x) _avg1 = (x); \
> typeof(y) _avg2 = (y); \
> (void) (&_avg1 == &_avg2); \
> _avg1 + (signed typeof(x))(_avg2 - _avg1)/2; })
>
> except that typeof() doesn't work that way.
>
> #define avg(x, y) ({ \
> typeof(x) _avg1 = (x); \
> typeof(y) _avg2 = (y); \
> (void) (&_avg1 == &_avg2); \
> _avg1 + (long)(_avg2 - _avg1)/2; })
>
> works for the above example, but when I make it long long, so as to
> match the longest supported type, it goes boom again - for as of yet
> unknown reasons.

Ok, people pointed out I got my promotion rules mixed up, I casted the
result of the division to signed, instead of ending up with a signed
division.

#define avg(x, y) ({ \
typeof(x) _avg1 = (x); \
typeof(y) _avg2 = (y); \
(void) (&_avg1 == &_avg2); \
(typeof(x))(_avg1 + ((long long)_avg2 - _avg1)/2); })

seems to work.



\
 
 \ /
  Last update: 2008-08-20 22:59    [W:2.381 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site