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]
Other format: [Raw text]

Memory outputs in inline asm


Say you have a pointer:

int *p;

and an inline asm that writes to a block of memory

  __asm__("\t0:\n"
	  "\tstr wzr, [%2, #4]!\n"
	  "\tsub %1, %1, #1\n"
	  "\tcbnz %1, 0b\n"
	  : "=m"(*p), "+r"(len) : "r"(p));

I presume this is wrong because *p only refers to p[0].  Is it
possible to tell GCC that the asm writes to the whole block of memory
reachable from p without a total memory clobber?

I have attached some code that works but it is so fugly that I'm
reluctant to recommend it.

Andrew.


typedef struct {
  int theData[0];
} thing;

int main() {

  int arr[20];
  thing *p = (thing*)arr;

  int len = 20;
  __asm__("\t0:\n"
	  "\tstr %1, [%2, #4]!\n"
	  "\tsub %1, %1, #1\n"
	  "\tcbnz %1, 0b\n"
	  : "=m"(*p), "+r"(len) : "r"(p));

  return p->theData[5];
}


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