Hi *,
this is little performance improvement hint for IA-32, x86-64
In the userland I've been using following inlined functions in order
to avoid unpredictable conditional branching (indeed, it looks ugly).
static inline int
absolute (int x)
{
#if defined (__i386__)
asm volatile
(
".intel_syntax noprefix\n\t"
"mov ecx, eax\n\t"
"neg ecx\n\t"
"cmovns eax, ecx\n\t"
".att_syntax\n\t"
: "=a" (x) : "a" (x) : "ecx", "flags"
) ;
#else
if (x < 0)
{
x = -x ;
}
#endif
return x ;
}
GCC 3.x now emits cmov, however there is one specific case, where it
could be done bit more efficiently.
GCC generated code from Linux 2.5.69 kernel and then human made
equivalent of abs()
c036703c: 89 d0 mov %edx,%eax
c036703e: f7 d8 neg %eax
c0367040: 83 fa ff cmp $0xffffffff,%edx
c0367043: 0f 4e d0 cmovle %eax,%edx
c036703e: 89 c1 mov %eax,%ecx
c0367040: f7 d9 neg %ecx
c0367042: 0f 49 c1 cmovns %ecx,%eax
neg changes flags, cmp with constant -1 is not necessary.
Would it be possible to integrate in architecture specific code
generation?
br
Peter Kovar
====================== REKLAMA =================================
Získajte supervýhodné ADSL ešte výhodnejšie. Ceny už od 399 Sk mesačne
bez
DPH. Byť rýchly sa naozaj oplatí. http://www.slovanet.sk/menu/adsl.html