xor as a lazy comparison
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 gps that will fit inside the handle of a Fenwick?
Quoted 9 lines · 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
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,%eaxInstructions 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 [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.
Thank you.
Quoted 3 lines · linux-os \(Dick Johnson\)
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 xor to cmp as nothing referenced the result.
Grant.