Assembly optimizations
Nathan Sidwell
nathan@codesourcery.com
Wed Dec 1 09:21:00 GMT 2004
Klaus Winter wrote:
> Hi all,
>
> I compiled the following code with gcc-3.3.1. Once without
> optimization and one time with optimization -O. With optimization the
> Decrement function takes a LOT longer than before whereas the
> Increment function stays constant. I haven't found anything in the
> manpage about it ... Any help is appreciated.
>
> cheers,
> Klaus
>
> #include <stdio.h>
> #include <time.h>
> #include <sys/time.h>
>
> int g_Lock_Mini = 0;
>
> inline int Increment( int* count)
> {
> __asm__ __volatile__( "movl $1, %%eax\n\t"
> "lock; xaddl %%eax, (%%ecx)\n\t"
> "incl %%eax\n\t" : : "c" (count) );
> }
> inline int Decrement( int * count)
> {
> __asm__ __volatile__( "lock; decl (%%ecx)\n\t"
> "movl (%%ecx), %%eax\n\t" : : "c" (count));
> }
these asms are broken. I think you want something like
asm volatile("lock;decl (%1)\n\tmovl (%1),%0" : "=r" (result) : "r" (count) : "memory")
gcc does not otherwise know what registers are used by the asm.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
More information about the Gcc-help
mailing list