This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: asm() statements
Richard Earnshaw wrote:
>
> > asm("adcs %0, %1, %2 lsl #1" : "=r"(n) : "r"(d), "0"(n) : "cc");
> > asm("rsbcc %0, %1, %2" : "=r"(n) : "r"(d), "0"(n));
> > asm("adcs %0, %1, %1" : "=r"(q) : "0"(q) : "cc");
> >
> You can't preserve the condition codes across ASM statements, since the
> compiler has no way of saving the value if a conflict with its own needs
> arises.
One could imagine a way of telling the compiler that a cpsr dependency
exists between the three instructions, the same way one specify
registers,
allowing the optimizer to insert instructions that do not affect the
cpsr
inbetween. If it's not possible to save the cpsr, it could give errors
(or
atleast warnings) when hitting such a situation, for example ..
int a, b;
asm("movs %0, #0" : "=r"(b), "cc"); // Affects cpsr
if(5 < 3) { a = 5; } else { a = 3; }
asm("adcs %0, %1" : "=r"(b) : "r"(a), "cc"); // Uses cpsr
.. would yield a warning/error, but removing the if() statement would
not.
From what I learned from you guys this is not possible today. Could it
be
added? Would it be desireable to add?
I'm optimizing a template for fix point arithmetics so for me, every
cycle
counts. :)
Dan