This is the mail archive of the gcc-help@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]

Inline asm


Hi all,

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?

Note that this code is repeated a number of times (it's a part of a
division routine) so the n and d variables will get read at a later
time by the same lines.

A solution would be to put "volatile" after the asm statement; but
this is IMHO not the proper way of doing it and it does not work,
since the above code is in a template and a (known) bug in 2.95.2
wont allow you to use asm volatile in a template.

Any hints?

Dan

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