lkml.org 
[lkml]   [1999]   [May]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] Improving send_sigio() scalability


On Wed, 26 May 1999, Jamie Lokier wrote:

> > > > Why don't you use != when that is what you mean?
>
> Linus Torvalds wrote:
> > It used to do noticeably better compiler-wise. I don't know if newer
> > versions of gcc have made ^ and != generate the same code.
>
> Odd.
>
> I would expect != to generate better code than ^: != uses `cmp'
> instruction, ^ uses `xor' unless the compiler gets clever.

Exactly.

The thing is, that the "obvious" implementation of a != comparison will
look something like

cmp a,b
jne same
...

which on the face of it is perfect. However, in the presense of _other_
comparisons, it's suddenly not necessarily the best thing any more,
especially if there are combinations of these comparisons. Especially as
conditional branches are expensive, and what you _really_ want to happen
is something more like

cmp a,b
sete x
cmp c,d
sete y
cmp e,f
sete z
and x,y
and y,z
je not_true

With combinations, using xor and other binary operations are often
advantageous exactly because the obvious implementation does _not_ imply a
compare and the status register, but instead implies a normal arithmetic
operation with the result in a general register - and suddenly the
compiler sees more options for combining such operations.

Now, for a perfect compiler, none of these source modifications will make
any difference. In fact, at least for this case, anything newer than
gcc-2.6 will apparently generate the same thing in the end.

> Are you thinking of the sequence `if ((a ^ b) | (c ^ d))' etc. instead?
> That might be marginally smaller and faster with xor because branches
> are optimised away. But I wouldn't expect such speed from `if ((a ^ b)
> && (c ^ d))'.

The compiler I have access to right now do not generate any different code
for != and ^, and I don't remember what the original code generation issue
was...

Linus


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

\
 
 \ /
  Last update: 2005-03-22 13:51    [W:0.028 / U:0.660 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site