Re: xor as a lazy comparison

2005-07-27 Thread Grant Coady
On Wed, 27 Jul 2005 15:58:48 -0400, "linux-os \(Dick Johnson\)" <[EMAIL PROTECTED]> wrote: > >I think the XOR thread was started by somebody as a ruse or >a joke. XOR will always destroy the value of an operand. You missed the part where somebody checked assembler output and found compiler

Re: xor as a lazy comparison

2005-07-27 Thread linux-os \(Dick Johnson\)
On Wed, 27 Jul 2005, Clayton Weaver wrote: > Is not xor (^) typically compiled to a > one cycle instruction regardless of > requested optimization level? (May not > always have been the case on every > target architecture for != equality > tests.) > Clayton Weaver > cgweav at fastmail dot fm >

Re: xor as a lazy comparison

2005-07-27 Thread Clayton Weaver
Is not xor (^) typically compiled to a one cycle instruction regardless of requested optimization level? (May not always have been the case on every target architecture for != equality tests.) Clayton Weaver cgweav at fastmail dot fm PS: Anyone know where I can get a waterproof, battery powered

Re: xor as a lazy comparison

2005-07-27 Thread Clayton Weaver
Is not xor (^) typically compiled to a one cycle instruction regardless of requested optimization level? (May not always have been the case on every target architecture for != equality tests.) Clayton Weaver cgweav at fastmail dot fm PS: Anyone know where I can get a waterproof, battery powered

Re: xor as a lazy comparison

2005-07-27 Thread linux-os \(Dick Johnson\)
On Wed, 27 Jul 2005, Clayton Weaver wrote: Is not xor (^) typically compiled to a one cycle instruction regardless of requested optimization level? (May not always have been the case on every target architecture for != equality tests.) Clayton Weaver cgweav at fastmail dot fm I think

Re: xor as a lazy comparison

2005-07-27 Thread Grant Coady
On Wed, 27 Jul 2005 15:58:48 -0400, linux-os \(Dick Johnson\) [EMAIL PROTECTED] wrote: I think the XOR thread was started by somebody as a ruse or a joke. XOR will always destroy the value of an operand. You missed the part where somebody checked assembler output and found compiler optimised

Re: xor as a lazy comparison

2005-07-26 Thread Bernd Petrovitsch
On Tue, 2005-07-26 at 08:07 +0200, Jan Engelhardt wrote: [...] > To answer for x *= 2 vs x <<= 1: and x += x > Use * when you would logically want to do a multiplication, > << if you're working on a bitfield. It's just for keeping the code clean > enough so that others may understand it. > > In

Re: xor as a lazy comparison

2005-07-26 Thread Jan Engelhardt
>> > Where do we draw the line with this? Is x *= 2 preferable to x <<= 2 as >> > well? >> >> Depends if you want to multiply by 2 or 4 :-) > >I guess I just answered my own question ;-) To answer for x *= 2 vs x <<= 1: Use * when you would logically want to do a multiplication, << if you're

Re: xor as a lazy comparison

2005-07-26 Thread Jan Engelhardt
Where do we draw the line with this? Is x *= 2 preferable to x = 2 as well? Depends if you want to multiply by 2 or 4 :-) I guess I just answered my own question ;-) To answer for x *= 2 vs x = 1: Use * when you would logically want to do a multiplication, if you're working on a

Re: xor as a lazy comparison

2005-07-26 Thread Bernd Petrovitsch
On Tue, 2005-07-26 at 08:07 +0200, Jan Engelhardt wrote: [...] To answer for x *= 2 vs x = 1: and x += x Use * when you would logically want to do a multiplication, if you're working on a bitfield. It's just for keeping the code clean enough so that others may understand it. In the

Re: xor as a lazy comparison

2005-07-25 Thread Bill Davidsen
Lee Revell wrote: On Mon, 2005-07-25 at 13:55 -0400, Steven Rostedt wrote: Doesn't matter. The cycles saved for old compilers is not rational to have obfuscated code. Where do we draw the line with this? Is x *= 2 preferable to x <<= 2 as well? In addition to the obvious error, let's not

Re: xor as a lazy comparison

2005-07-25 Thread Paulo Marques
Lee Revell wrote: On Mon, 2005-07-25 at 13:55 -0400, Steven Rostedt wrote: Doesn't matter. The cycles saved for old compilers is not rational to have obfuscated code. Where do we draw the line with this? Is x *= 2 preferable to x <<= 2 as well? I guess this depends on what you logically

Re: xor as a lazy comparison

2005-07-25 Thread Lee Revell
On Mon, 2005-07-25 at 12:16 -0700, Philippe Troin wrote: > Lee Revell <[EMAIL PROTECTED]> writes: > > > On Mon, 2005-07-25 at 13:55 -0400, Steven Rostedt wrote: > > > Doesn't matter. The cycles saved for old compilers is not rational to > > > have obfuscated code. > > > > Where do we draw the

Re: xor as a lazy comparison

2005-07-25 Thread Lee Revell
On Mon, 2005-07-25 at 20:23 +0100, Paulo Marques wrote: > Lee Revell wrote: > > On Mon, 2005-07-25 at 13:55 -0400, Steven Rostedt wrote: > > > >>Doesn't matter. The cycles saved for old compilers is not rational to > >>have obfuscated code. > > > > Where do we draw the line with this? Is x *=

Re: xor as a lazy comparison

2005-07-25 Thread Steven Rostedt
On Mon, 2005-07-25 at 12:16 -0700, Philippe Troin wrote: > Lee Revell <[EMAIL PROTECTED]> writes: > > > On Mon, 2005-07-25 at 13:55 -0400, Steven Rostedt wrote: > > > Doesn't matter. The cycles saved for old compilers is not rational to > > > have obfuscated code. > > > > Where do we draw the

Re: xor as a lazy comparison

2005-07-25 Thread Lee Revell
On Mon, 2005-07-25 at 12:16 -0700, Philippe Troin wrote: > Lee Revell <[EMAIL PROTECTED]> writes: > > > On Mon, 2005-07-25 at 13:55 -0400, Steven Rostedt wrote: > > > Doesn't matter. The cycles saved for old compilers is not rational to > > > have obfuscated code. > > > > Where do we draw the

Re: xor as a lazy comparison

2005-07-25 Thread Philippe Troin
Lee Revell <[EMAIL PROTECTED]> writes: > On Mon, 2005-07-25 at 13:55 -0400, Steven Rostedt wrote: > > Doesn't matter. The cycles saved for old compilers is not rational to > > have obfuscated code. > > Where do we draw the line with this? Is x *= 2 preferable to x <<= 2 as > well? Depends if

Re: xor as a lazy comparison

2005-07-25 Thread Lee Revell
On Mon, 2005-07-25 at 13:55 -0400, Steven Rostedt wrote: > Doesn't matter. The cycles saved for old compilers is not rational to > have obfuscated code. Where do we draw the line with this? Is x *= 2 preferable to x <<= 2 as well? Lee - To unsubscribe from this list: send the line

[PATCH] make signal.c more readable (was: Re: xor as a lazy comparison)

2005-07-25 Thread Steven Rostedt
Sorry for the double post. I added [PATCH] and changed the subject, and added Linus. On Mon, 2005-07-25 at 10:57 +0200, Bernd Petrovitsch wrote: > On Sun, 2005-07-24 at 18:15 -0400, Puneet Vyas wrote: > [...] > > I just compiled two identical program , one with "!=" and other with > > "^". The

Re: xor as a lazy comparison

2005-07-25 Thread Steven Rostedt
On Mon, 2005-07-25 at 10:57 +0200, Bernd Petrovitsch wrote: > On Sun, 2005-07-24 at 18:15 -0400, Puneet Vyas wrote: > [...] > > I just compiled two identical program , one with "!=" and other with > > "^". The assembly output is identical. > > Hmm, which compiler and which version? > You might

Re: xor as a lazy comparison

2005-07-25 Thread Bernd Petrovitsch
On Sun, 2005-07-24 at 18:15 -0400, Puneet Vyas wrote: [...] > I just compiled two identical program , one with "!=" and other with > "^". The assembly output is identical. Hmm, which compiler and which version? You might want to try much older and other compilers. Bernd -- Firmix

Re: xor as a lazy comparison

2005-07-25 Thread Bernd Petrovitsch
On Sun, 2005-07-24 at 18:15 -0400, Puneet Vyas wrote: [...] I just compiled two identical program , one with != and other with ^. The assembly output is identical. Hmm, which compiler and which version? You might want to try much older and other compilers. Bernd -- Firmix Software

Re: xor as a lazy comparison

2005-07-25 Thread Steven Rostedt
On Mon, 2005-07-25 at 10:57 +0200, Bernd Petrovitsch wrote: On Sun, 2005-07-24 at 18:15 -0400, Puneet Vyas wrote: [...] I just compiled two identical program , one with != and other with ^. The assembly output is identical. Hmm, which compiler and which version? You might want to try

[PATCH] make signal.c more readable (was: Re: xor as a lazy comparison)

2005-07-25 Thread Steven Rostedt
Sorry for the double post. I added [PATCH] and changed the subject, and added Linus. On Mon, 2005-07-25 at 10:57 +0200, Bernd Petrovitsch wrote: On Sun, 2005-07-24 at 18:15 -0400, Puneet Vyas wrote: [...] I just compiled two identical program , one with != and other with ^. The assembly

Re: xor as a lazy comparison

2005-07-25 Thread Lee Revell
On Mon, 2005-07-25 at 13:55 -0400, Steven Rostedt wrote: Doesn't matter. The cycles saved for old compilers is not rational to have obfuscated code. Where do we draw the line with this? Is x *= 2 preferable to x = 2 as well? Lee - To unsubscribe from this list: send the line unsubscribe

Re: xor as a lazy comparison

2005-07-25 Thread Philippe Troin
Lee Revell [EMAIL PROTECTED] writes: On Mon, 2005-07-25 at 13:55 -0400, Steven Rostedt wrote: Doesn't matter. The cycles saved for old compilers is not rational to have obfuscated code. Where do we draw the line with this? Is x *= 2 preferable to x = 2 as well? Depends if you want to

Re: xor as a lazy comparison

2005-07-25 Thread Lee Revell
On Mon, 2005-07-25 at 12:16 -0700, Philippe Troin wrote: Lee Revell [EMAIL PROTECTED] writes: On Mon, 2005-07-25 at 13:55 -0400, Steven Rostedt wrote: Doesn't matter. The cycles saved for old compilers is not rational to have obfuscated code. Where do we draw the line with this?

Re: xor as a lazy comparison

2005-07-25 Thread Steven Rostedt
On Mon, 2005-07-25 at 12:16 -0700, Philippe Troin wrote: Lee Revell [EMAIL PROTECTED] writes: On Mon, 2005-07-25 at 13:55 -0400, Steven Rostedt wrote: Doesn't matter. The cycles saved for old compilers is not rational to have obfuscated code. Where do we draw the line with this?

Re: xor as a lazy comparison

2005-07-25 Thread Lee Revell
On Mon, 2005-07-25 at 20:23 +0100, Paulo Marques wrote: Lee Revell wrote: On Mon, 2005-07-25 at 13:55 -0400, Steven Rostedt wrote: Doesn't matter. The cycles saved for old compilers is not rational to have obfuscated code. Where do we draw the line with this? Is x *= 2 preferable to

Re: xor as a lazy comparison

2005-07-25 Thread Lee Revell
On Mon, 2005-07-25 at 12:16 -0700, Philippe Troin wrote: Lee Revell [EMAIL PROTECTED] writes: On Mon, 2005-07-25 at 13:55 -0400, Steven Rostedt wrote: Doesn't matter. The cycles saved for old compilers is not rational to have obfuscated code. Where do we draw the line with this?

Re: xor as a lazy comparison

2005-07-25 Thread Paulo Marques
Lee Revell wrote: On Mon, 2005-07-25 at 13:55 -0400, Steven Rostedt wrote: Doesn't matter. The cycles saved for old compilers is not rational to have obfuscated code. Where do we draw the line with this? Is x *= 2 preferable to x = 2 as well? I guess this depends on what you logically

Re: xor as a lazy comparison

2005-07-25 Thread Bill Davidsen
Lee Revell wrote: On Mon, 2005-07-25 at 13:55 -0400, Steven Rostedt wrote: Doesn't matter. The cycles saved for old compilers is not rational to have obfuscated code. Where do we draw the line with this? Is x *= 2 preferable to x = 2 as well? In addition to the obvious error, let's not

Re: xor as a lazy comparison

2005-07-24 Thread Puneet Vyas
Jan Engelhardt wrote: To confuse you, coders with assembly or hardware background throw in I doubt that. I'm good enough assembly to see this :) equivalent bit operations to succinctly describe their visualisation of solution space... Perhaps the writer _wanted_ you to pause and

Re: xor as a lazy comparison

2005-07-24 Thread Jan Engelhardt
>To confuse you, coders with assembly or hardware background throw in I doubt that. I'm good enough assembly to see this :) >equivalent bit operations to succinctly describe their visualisation >of solution space... Perhaps the writer _wanted_ you to pause and >think? Maybe the compiler

Re: xor as a lazy comparison

2005-07-24 Thread Grant Coady
On Sun, 24 Jul 2005 18:40:25 +0200 (MEST), Jan Engelhardt <[EMAIL PROTECTED]> wrote: > >I have seen this in kernel/signal.c:check_kill_permission() > >&& (current->euid ^ t->suid) && (current->euid ^ t->uid) > >If current->euid and t->suid are the same, the xor returns 0, so these

xor as a lazy comparison

2005-07-24 Thread Jan Engelhardt
Hi list, I have seen this in kernel/signal.c:check_kill_permission() && (current->euid ^ t->suid) && (current->euid ^ t->uid) If current->euid and t->suid are the same, the xor returns 0, so these statements are effectively the same as a != current->euid != t->suid ...

xor as a lazy comparison

2005-07-24 Thread Jan Engelhardt
Hi list, I have seen this in kernel/signal.c:check_kill_permission() (current-euid ^ t-suid) (current-euid ^ t-uid) If current-euid and t-suid are the same, the xor returns 0, so these statements are effectively the same as a != current-euid != t-suid ... Why ^ ? Jan

Re: xor as a lazy comparison

2005-07-24 Thread Grant Coady
On Sun, 24 Jul 2005 18:40:25 +0200 (MEST), Jan Engelhardt [EMAIL PROTECTED] wrote: I have seen this in kernel/signal.c:check_kill_permission() (current-euid ^ t-suid) (current-euid ^ t-uid) If current-euid and t-suid are the same, the xor returns 0, so these statements are

Re: xor as a lazy comparison

2005-07-24 Thread Jan Engelhardt
To confuse you, coders with assembly or hardware background throw in I doubt that. I'm good enough assembly to see this :) equivalent bit operations to succinctly describe their visualisation of solution space... Perhaps the writer _wanted_ you to pause and think? Maybe the compiler

Re: xor as a lazy comparison

2005-07-24 Thread Puneet Vyas
Jan Engelhardt wrote: To confuse you, coders with assembly or hardware background throw in I doubt that. I'm good enough assembly to see this :) equivalent bit operations to succinctly describe their visualisation of solution space... Perhaps the writer _wanted_ you to pause and