#include <stdlib.h> #define mmx_m2r(op, mem, reg) \ __asm__ __volatile__ (#op "\t%0, %%" #reg \ : /* nothing */ \ : "X" (mem)) #define movd_m2r(var, reg) mmx_m2r(movd, var, reg)
int main () { int a; int c; int b; int d; b = 100; c = rand () % 256; a = 256 - c; d = (a / 4) + 1; movd_m2r(b, mm4); movd_m2r(c, mm5); movd_m2r(a, mm6); movd_m2r(d, mm7); return 0; } gcc-4.0.0 desn't compile the above code if compile with option -O[s1-9], and i got following output. smspc tmp # gcc -Wall -S -o - testmmx.c -O .file "testmmx.c" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp subl $8, %esp andl $-16, %esp subl $16, %esp call rand cltd shrl $24, %edx addl %edx, %eax andl $255, %eax subl %edx, %eax movl %eax, %ecx movl $256, %edx subl %eax, %edx #APP movd $100, %mm4 movd %ecx, %mm5 movd %edx, %mm6 testmmx.c: In function 'main': testmmx.c:22: error: invalid 'asm': invalid expression as operand movd +1, %mm7 #NO_APP movl $0, %eax leave ret .size main, .-main .ident "GCC: (GNU) 4.0.0-20050522 (Gentoo 4.0.0.20050522)" .section .note.GNU-stack,"",@progbits compiling without -O is ok. smspc tmp # gcc -Wall -S -o - testmmx.c .file "testmmx.c" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp subl $24, %esp andl $-16, %esp movl $0, %eax addl $15, %eax addl $15, %eax shrl $4, %eax sall $4, %eax subl %eax, %esp movl $100, -8(%ebp) call rand movl %eax, %edx movl %edx, %eax sarl $31, %eax movl %eax, %ecx shrl $24, %ecx leal (%edx,%ecx), %eax andl $255, %eax subl %ecx, %eax movl %eax, -12(%ebp) movl $256, %eax subl -12(%ebp), %eax movl %eax, -16(%ebp) movl -16(%ebp), %edx movl %edx, %eax sarl $31, %eax shrl $30, %eax addl %edx, %eax sarl $2, %eax incl %eax movl %eax, -4(%ebp) #APP movd -8(%ebp), %mm4 movd -12(%ebp), %mm5 movd -16(%ebp), %mm6 movd -4(%ebp), %mm7 #NO_APP movl $0, %eax leave ret .size main, .-main .ident "GCC: (GNU) 4.0.0-20050522 (Gentoo 4.0.0.20050522)" .section .note.GNU-stack,"",@progbits some additional info about my system: Portage 2.0.51.22-r1 (default-linux/x86/2005.0, gcc-4.0.0-20050522, glibc-2.3.5.20050418-r0, 2.6.12-rc4-skunk1-unicon i686) ================================================================= System uname: 2.6.12-rc4-skunk1-unicon i686 Intel(R) Celeron(R) CPU 1.70GHz Gentoo Base System version 1.6.12 dev-lang/python: 2.3.5 sys-apps/sandbox: 1.2.8 sys-devel/autoconf: 2.13, 2.59-r6 sys-devel/automake: 1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.5 sys-devel/binutils: 2.15.97 sys-devel/libtool: 1.5.16 virtual/os-headers: 2.6.11 ACCEPT_KEYWORDS="x86 ~x86" AUTOCLEAN="yes" CBUILD="i686-pc-linux-gnu" CFLAGS="-O1 -pipe -march=pentium4" CHOST="i686-pc-linux-gnu" -- Summary: gcc doesn't compile my c code (with some inline asm ocde) if compiling with optimization options Product: gcc Version: 4.0.1 Status: UNCONFIRMED Severity: normal Priority: P2 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sunmoon1997 at gmail dot com CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21748