lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2c0942db0808201358t1126f4bwd745402f6e9b42d2@mail.gmail.com>
Date:	Wed, 20 Aug 2008 13:58:03 -0700
From:	"Ray Lee" <ray-lk@...rabbit.org>
To:	"Peter Zijlstra" <a.p.zijlstra@...llo.nl>
Cc:	"Nick Piggin" <nickpiggin@...oo.com.au>, adobriyan@...il.com,
	"Ingo Molnar" <mingo@...e.hu>,
	"Zhang, Yanmin" <yanmin_zhang@...ux.intel.com>,
	"Dhaval Giani" <dhaval@...ux.vnet.ibm.com>,
	LKML <linux-kernel@...r.kernel.org>,
	"Srivatsa Vaddagiri" <vatsa@...ux.vnet.ibm.com>,
	"Aneesh Kumar KV" <aneesh.kumar@...ux.vnet.ibm.com>,
	"Balbir Singh" <balbir@...ibm.com>,
	"Chris Friesen" <cfriesen@...tel.com>
Subject: Re: VolanoMark regression with 2.6.27-rc1

On Wed, Aug 20, 2008 at 1:30 PM, Peter Zijlstra <a.p.zijlstra@...llo.nl> wrote:
> 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.

I think you'd want to cast it with a (signed) instead? as in:

#include <stdio.h>

#define avg(x, y) ({            \
       typeof(x) _x = (x);      \
       typeof(y) _y = (y);      \
       (void) (&_x == &_y);     \
       _x + (signed)(_y - _x)/2; })

int main (void) {
        unsigned long long a=7,b=5;

        printf("%d %d\n", avg(a,b), avg(b,a));
}

...which works here, for me, but hey, I managed to goof up my other
test case, so take it for a spin.

Ray
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ