Messages in this thread | | | Date | Thu, 2 Dec 1999 09:12:49 +0100 | From | Jakub Jelinek <> | Subject | Re: gcc inline asm optimizing problem ? |
| |
On Thu, Dec 02, 1999 at 02:43:42PM +0800, wu_yb wrote: > in asm1.c > > int i = 1 ; > __asm__ volatile ( " > movl %0, %%eax\n > addl $1, %%eax\n > movl %%eax, %0\n" > : :"g"(i) : "eax" > ) ; > > gcc -O -S asm1.c. > output asm code: > ... > #APP > movl $1, %eax > addl $1, %eax > movl %eax, $1 > #NO_APP > ... > > Neigher the asm1.c or asm1.s can't assembled to a executable file. > But it can compiled by "gcc asm1.c"
Your code is broken. See info gcc on Constraints:
`g' Any register, memory or immediate integer operand is allowed, except for registers that are not general registers.
so you cannot use constraint g because it includes immediate and you cannot obviously change immediate.
Also, even if you used "rm" instead, your code has no outputs, so it illegally clobbers the i value without telling gcc about it. I'd propose something like:
int i = 1 ; __asm__ volatile ( " movl %1, %%eax\n addl $1, %%eax\n movl %%eax, %0\n" : "=rm"(i) :"g"(i) : "eax" ) ;
(that could turn into movl $1,%eax; addl $1,%eax; movl $eax,somereg) or if you want to make sure i are kept in the same register/memory, then
int i = 1 ; __asm__ volatile ( " movl %0, %%eax\n addl $1, %%eax\n movl %%eax, %0\n" : "=rm"(i) :"0"(i) : "eax" ) ;
Cheers, Jakub ___________________________________________________________________ Jakub Jelinek | jakub@redhat.com | http://sunsite.mff.cuni.cz/~jj Linux version 2.3.18 on a sparc64 machine (1343.49 BogoMips) ___________________________________________________________________
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |