This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: asm() statements


> Hi all,
> 
> I recently posted this to gcc-help but it seems like it was the wrong
> forum. My apologies.
> 
> Here is my code that I'm trying to get to compile using gcc 2.95.2
> for target arm-elf:
> 
>   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");
> 
> My problem is that the optimizer removes the top two instructions
> since I dont know how to tell it that the last adcs and the mid rsbcc
> reads the condition code register, cpsr. Telling that an instruction
> writes the cpsr is done by putting "cc" as a clobbered register, but
> how do tell when an instruction reads the cpsr?

This is ARM code, right?

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.  The only solution is to combine the three ASMs as RTH suggests.

The optimizer is removing the first two instructions because it can see no 
link between those and the third instruction (the "cc" is a clobber 
indication, not a use indication); so it is simply deleting them (I'm 
assuming that the variable n is not used elsewhere).

Richard.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]