This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Memory outputs in inline asm
- From: Andrew Haley <aph at redhat dot com>
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Wed, 26 Feb 2014 10:32:51 +0000
- Subject: Memory outputs in inline asm
- Authentication-results: sourceware.org; auth=none
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];
}