Re: xor as a lazy comparison

linux-os (Dick Johnson)
2005-07-27T20:01:24Z

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 the XOR thread was started by somebody as a ruse or
a joke. XOR will always destroy the value of an operand. This
means that it needs to be loaded and perhaps reloaded. A 'TEST'
instruction or a 'CMP' instruction never destroys anything and
only affects the flags. TEST is an AND in which the result is
not saved, only the flags get changed. A CMP is a subtract in
which the result is not saved, only the flags. These are
ix86 instructions, but similar instructions exist for other
CPUs.

All these instructions in their simplest form (using registers)
are two-byte instructions!

Disassembly of section .text:

00000000 <.text>:
0: 39 c3 cmp %eax,%ebx
2: 31 c3 xor %eax,%ebx
4: 85 d8 test %ebx,%eax

Instructions that access memory use more bytes...

Cheers,
Dick Johnson
Penguin : Linux version 2.6.12 on an i686 machine (5537.79 BogoMips).
Warning : 98.36% of all statistics are fiction.
.
I apologize for the following. I tried to kill it with the above dot :

****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to DeliveryErrors@analogic.com - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.