Author: Dave Gomboc
Date: 01:04:59 02/11/00
Go up one level in this thread
On February 10, 2000 at 23:23:30, Robert Hyatt wrote:
>On February 10, 2000 at 18:38:51, Eugene Nalimov wrote:
>
>>And here is result of using MSVC:
>>
>>#include <stdlib.h>
>>
>>int type (int i)
>>{
>> return abs (i);
>>}
>>
>>Assembly code is:
>>
>> mov eax, DWORD PTR [esp-4]
>> cdq
>> xor eax, edx
>> sub eax, edx
>> ret
>>
>>It also lacks the branch, but it is also shorter than GCC output, and will run
>>on any 32-bit x86 processor.
>>
>>It is based in the following observation: abs (x) == (x ^ (x >> (sizeof (x) -
>>1))) - (x >> (sizeof (x) - 1)).
>>
>>That is an example when good compiler can get rid of branch remaining compatible
>>with old processors.
>>
>>Eugene
>
>
>
>Right. I was making the point that the "?" operator doesn't need to
>produce a branch at all. I only picked 'abs()' as an example... It
>used to be 'evil'. Now it is perfectly ok to use ? if the compiler
>knows about cmov.
Yes, but Eugene's point is that cmov isn't needed, and in fact is a bad choice
in this particular case.
Dave
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.