Re: Patch to remove undefined C code

2000-10-20 Thread Albert D. Cahalan
> Yes. In practice the usual question is whether the compiler will > evaluate the operands from left to right or from right to left, > but the compiler is within its rights to evaluate the operands in > any order it wants. For ia64, it would be good to evaluate the operands in parallel. One coul

Re: Patch to remove undefined C code

2000-10-20 Thread Rick Hohensee
([EMAIL PROTECTED]) nobly encouraged empiricism thusly... > Just to encourage empiricism, I usually check stuff like that with > > % cat > foo.c > main(){ > int i; > i = 1 , 2; > printf("%d\n",i); > } > % gcc foo.c > % ./a.out > 1 > > or similar if I'm confused. Indeed. Furt

Re: Patch to remove undefined C code

2000-10-17 Thread Tom Leete
[CC trimmed] Bill Wendling wrote: > > Also sprach Tom Leete: > } > } You are correct that in C the rightmost argument is always > } at the open end of the stack, and that varargs require that. > } The opposite is called the Pascal convention. > } > Where in the standard does it say this? It's pr

Re: Patch to remove undefined C code

2000-10-17 Thread Jeff Epler
On Tue, Oct 17, 2000 at 07:42:31AM +, Peter Samuelson wrote: > So, if you choose left-to-right, how do you implement varargs? Keep in > mind that prototypes are optional. I bet anything your solution is > slower and more complex than right-to-left, as all known compilers do. Calling a varar

Re: Patch to remove undefined C code

2000-10-17 Thread Richard Henderson
> [Matti Aarnio] > > > That depends mainly on question: Does your stack grow up or down ? Actually a combination -- which direction do arguments grow in relation to stack growth direction, and do you have a stack push instruction. > [Ben Pfaff] > > No it doesn't. It depends mainly on wheth

Re: Patch to remove undefined C code

2000-10-17 Thread Richard Henderson
On Tue, Oct 17, 2000 at 10:40:12AM +0100, Bernd Schmidt wrote: > > I compiled using "gcc -S -Wall -O2 -fomit-frame-pointer -m486" to generate > > the assembler code. The old code is 17 instructions long and the new code > > is 11 instructions. As well as being shorter, simple timing test indic

Re: Patch to remove undefined C code

2000-10-17 Thread Raja R Harinath
Bill Wendling <[EMAIL PROTECTED]> writes: > Also sprach Bernd Schmidt: > } > Looking at the above code, I noticed that there are a lot of ++ > } > operations. I rewrote the code as: > } > > } > setup_from[0] = setup_from[1] = eaddrs[0]; > } > setup_from[2] = setup_from[3] = eaddrs[1];

Re: Patch to remove undefined C code

2000-10-17 Thread Bernd Schmidt
On Tue, 17 Oct 2000, Horst von Brand wrote: > Richard Guenther <[EMAIL PROTECTED]> said: > > The following one is wrong, tho - should be rather > > str[i] = dn[i]; i++; > > > > diff -x log.build -x .* -dru linux-2.4/drivers/isdn/sc/debug.c linux-2.4-fixe > > d/drivers/isdn/sc/deb

Re: Patch to remove undefined C code

2000-10-17 Thread Bill Wendling
Also sprach Tom Leete: } } You are correct that in C the rightmost argument is always } at the open end of the stack, and that varargs require that. } The opposite is called the Pascal convention. } Where in the standard does it say this? It's probably done most of the time in this fashion for c

Re: Patch to remove undefined C code

2000-10-17 Thread Bill Wendling
Also sprach Bernd Schmidt: } > Looking at the above code, I noticed that there are a lot of ++ } > operations. I rewrote the code as: } > } > setup_from[0] = setup_from[1] = eaddrs[0]; } > setup_from[2] = setup_from[3] = eaddrs[1]; } > setup_from[4] = setup_from[5] = eaddrs[2]; }

Re: Patch to remove undefined C code

2000-10-17 Thread Bill Wendling
Also sprach Mark Montague: } } dn[i], i++ evaluates to i, but str[i] = dn[i], i++ sets str[i] to } dn[i] first, then increments i returning its previous value, which is } discarded. Which was probably specified this way so } } for(i=1,j=2; something; something else) } } works as expected, rathe

Re: Patch to remove undefined C code

2000-10-17 Thread Horst von Brand
Bernd Schmidt <[EMAIL PROTECTED]> said: > On Tue, 17 Oct 2000, Richard Guenther wrote: > > On Tue, 17 Oct 2000, Bernd Schmidt wrote: > > > On Tue, 17 Oct 2000, Richard Guenther wrote: > > > > The following one is wrong, tho - should be rather > > > > str[i] = dn[i]; i++; > > > > >

Re: Patch to remove undefined C code

2000-10-17 Thread Horst von Brand
Richard Guenther <[EMAIL PROTECTED]> said: > On Mon, 16 Oct 2000, Bernd Schmidt wrote: > The following one is wrong, tho - should be rather > str[i] = dn[i]; i++; > > diff -x log.build -x .* -dru linux-2.4/drivers/isdn/sc/debug.c linux-2.4-fixe > d/drivers/isdn/sc/debug.c > > ---

Re: Patch to remove undefined C code

2000-10-17 Thread Tom Leete
Peter Samuelson wrote: > > [Matti Aarnio] > > > That depends mainly on question: Does your stack grow up or down ? > > [Ben Pfaff] > > No it doesn't. It depends mainly on whether the ABI for the machine > > says that arguments are pushed onto the stack in left-to-right or > > right-to-left

Re: Patch to remove undefined C code

2000-10-17 Thread Mark Montague
Richard Guenther <[EMAIL PROTECTED]> writes: > On Tue, 17 Oct 2000, Bernd Schmidt wrote: > > > On Tue, 17 Oct 2000, Richard Guenther wrote: > > > > > On Mon, 16 Oct 2000, Bernd Schmidt wrote: > > > > > > > I've been playing with some gcc patches to detect code with undefined > > > > behaviour

Re: Patch to remove undefined C code

2000-10-17 Thread Bernd Schmidt
On Tue, 17 Oct 2000, Richard Guenther wrote: > On Tue, 17 Oct 2000, Bernd Schmidt wrote: > > On Tue, 17 Oct 2000, Richard Guenther wrote: > > > The following one is wrong, tho - should be rather > > > str[i] = dn[i]; i++; > > > > Nope. (Well, at least you need to add extra braces

Re: Patch to remove undefined C code

2000-10-17 Thread Richard Guenther
On Tue, 17 Oct 2000, Bernd Schmidt wrote: > On Tue, 17 Oct 2000, Richard Guenther wrote: > > > On Mon, 16 Oct 2000, Bernd Schmidt wrote: > > > > > I've been playing with some gcc patches to detect code with undefined > > > behaviour of the i = i++ variety. The patch below fixes all places in >

Re: Patch to remove undefined C code

2000-10-17 Thread Bernd Schmidt
> Looking at the above code, I noticed that there are a lot of ++ > operations. I rewrote the code as: > > setup_from[0] = setup_from[1] = eaddrs[0]; > setup_from[2] = setup_from[3] = eaddrs[1]; > setup_from[4] = setup_from[5] = eaddrs[2]; > setup_from += 6; > > I compiled

Re: Patch to remove undefined C code

2000-10-17 Thread Bernd Schmidt
On Tue, 17 Oct 2000, Helge Hafting wrote: > Bernd Schmidt wrote: > > > > I've been playing with some gcc patches to detect code with undefined > > behaviour of the i = i++ variety. The patch below fixes all places in > > the kernel that I could find. Note that in some cases, it wasn't > > enti

Re: Patch to remove undefined C code

2000-10-17 Thread Bernd Schmidt
On Tue, 17 Oct 2000, Richard Guenther wrote: > On Mon, 16 Oct 2000, Bernd Schmidt wrote: > > > I've been playing with some gcc patches to detect code with undefined > > behaviour of the i = i++ variety. The patch below fixes all places in > > the kernel that I could find. Note that in some cas

Re: Patch to remove undefined C code

2000-10-17 Thread Richard Guenther
On Mon, 16 Oct 2000, Bernd Schmidt wrote: > I've been playing with some gcc patches to detect code with undefined > behaviour of the i = i++ variety. The patch below fixes all places in > the kernel that I could find. Note that in some cases, it wasn't > entirely clear what the code intended, s

Re: Patch to remove undefined C code

2000-10-17 Thread Helge Hafting
Bernd Schmidt wrote: > > I've been playing with some gcc patches to detect code with undefined > behaviour of the i = i++ variety. The patch below fixes all places in > the kernel that I could find. Note that in some cases, it wasn't > entirely clear what the code intended, so I had to guess.

Re: Patch to remove undefined C code

2000-10-17 Thread Peter Samuelson
[Matti Aarnio] > > That depends mainly on question: Does your stack grow up or down ? [Ben Pfaff] > No it doesn't. It depends mainly on whether the ABI for the machine > says that arguments are pushed onto the stack in left-to-right or > right-to-left order. You could do either on x86, fo

Re: Patch to remove undefined C code

2000-10-16 Thread Ben Pfaff
Matti Aarnio <[EMAIL PROTECTED]> writes: > On Mon, Oct 16, 2000 at 04:55:08PM -0400, Ben Pfaff wrote: > > Yes. In practice the usual question is whether the compiler will > > evaluate the operands from left to right or from right to left, > > but the compiler is within its rights to evaluate the

Re: Patch to remove undefined C code

2000-10-16 Thread Matti Aarnio
On Mon, Oct 16, 2000 at 04:55:08PM -0400, Ben Pfaff wrote: > > > $ The order of evaluation of the function designator, the > > > $ arguments, and subexpressions within the arguments is > > > $ unspecified, ... > > > > I sit surprised and corrected. With every version of every C compiler on

Re: Patch to remove undefined C code

2000-10-16 Thread Alexander Viro
On Mon, 16 Oct 2000, Mike Castle wrote: > On Mon, Oct 16, 2000 at 04:47:09PM -0400, Alexander Viro wrote: > > tmp = *p++; > > *q = f(tmp, *p++); > > return p; > > > > is equivalent to more idiomatic > > > > *q = f(p[0], p[1]); > > return p+2; > > > Which gets better assembler out of various

Re: Patch to remove undefined C code

2000-10-16 Thread Mike Castle
On Mon, Oct 16, 2000 at 04:47:09PM -0400, Alexander Viro wrote: > tmp = *p++; > *q = f(tmp, *p++); > return p; > > is equivalent to more idiomatic > > *q = f(p[0], p[1]); > return p+2; Which gets better assembler out of various versions of gcc? mrc -- Mike Castle Life is like a

RE: Patch to remove undefined C code

2000-10-16 Thread Jonathan George
>-Original Message- >From: Alexander Viro [mailto:[EMAIL PROTECTED]] [snip] > >No arguments here, but proposed fixes were remarkably ugly. Example: > >tmp = *p++; >*q = f(tmp, *p++); >return p; > >is equivalent to more idiomatic > >*q = f(p[0], p[1]); >return p+2; > >And example with copyi

Re: Patch to remove undefined C code

2000-10-16 Thread Ben Pfaff
Jonathan George <[EMAIL PROTECTED]> writes: > > $ The order of evaluation of the function designator, the > > $ arguments, and subexpressions within the arguments is > > $ unspecified, ... > >-- > > I sit surprised and corrected. With every version of every C compiler on > every OS

RE: Patch to remove undefined C code

2000-10-16 Thread Jonathan George
-Original Message- From: Ben Pfaff [mailto:[EMAIL PROTECTED]] >Jonathan George <[EMAIL PROTECTED]> writes: > >> This patch has many bogus corrections where new variables were created, but >> the order of evaluation is already unambiguous. >> >> For example each comma separated clause in a

Re: Patch to remove undefined C code

2000-10-16 Thread Alexander Viro
On 16 Oct 2000, Ben Pfaff wrote: > Jonathan George <[EMAIL PROTECTED]> writes: > > > This patch has many bogus corrections where new variables were created, but > > the order of evaluation is already unambiguous. > > > > For example each comma separated clause in an expression is guaranteed t

Re: Patch to remove undefined C code

2000-10-16 Thread Ben Pfaff
Jonathan George <[EMAIL PROTECTED]> writes: > This patch has many bogus corrections where new variables were created, but > the order of evaluation is already unambiguous. > > For example each comma separated clause in an expression is guaranteed to be > completely evaluated before the next comm

Re: Patch to remove undefined C code

2000-10-16 Thread Bill Wendling
Also sprach Abramo Bagnara: } } Isn't this more efficient? } n = (x>>32) | (x<<32); } n = ((n & 0xLL)<<16) | (n & 0xLL)>>16; } n = ((n & 0x00ff00ff00ff00ffLL)<<8) | (n & 0xff00ff00ff00ff00LL)>>8; } } 6 shift } 4 and } 3 or } Plus 3 assigns...but they may

Re: Patch to remove undefined C code

2000-10-16 Thread David Relson
At 01:21 PM 10/16/00, Jeff Garzik wrote: >Bernd Schmidt wrote: > > diff -x log.build -x .* -dru linux-2.4/drivers/net/tulip/tulip_core.c > linux-2.4-fixed/drivers/net/tulip/tulip_core.c > > --- linux-2.4/drivers/net/tulip/tulip_core.cMon Oct 16 13:51:23 2000 > > +++ linux-2.4-fixed/drivers/ne

Re: Patch to remove undefined C code

2000-10-16 Thread Abramo Bagnara
Bernd Schmidt wrote: > > + > +#define ___swab64(x) \ > +({ \ > + __u64 __x = (x); \ > + ((__u64)( \ > + (__u64)(((__u64)(__x) & (__u64)0x00ffULL) << 56) | \ > + (__u64)(((__u64)(__x) & (__u64)0xff00ULL) << 40) | \ > + (

Re: Patch to remove undefined C code

2000-10-16 Thread Bernd Schmidt
On Mon, 16 Oct 2000, Jeff Garzik wrote: > > --- linux-2.4/drivers/scsi/aha152x.cMon Oct 16 13:51:24 2000 > > +++ linux-2.4-fixed/drivers/scsi/aha152x.c Mon Oct 16 14:51:29 2000 > > @@ -1280,7 +1280,8 @@ > > scsi_unregister(shpnt); > > regis

Re: Patch to remove undefined C code

2000-10-16 Thread Jeff Garzik
Bernd Schmidt wrote: > diff -x log.build -x .* -dru linux-2.4/drivers/net/tulip/tulip_core.c >linux-2.4-fixed/drivers/net/tulip/tulip_core.c > --- linux-2.4/drivers/net/tulip/tulip_core.cMon Oct 16 13:51:23 2000 > +++ linux-2.4-fixed/drivers/net/tulip/tulip_core.c Mon Oct 16 15:40:12 200