Mail Archives: djgpp/1998/01/03/14:42:34
At 11:42 1/1/1998 -0600, GAMMELJL AT SLU DOT EDU wrote:
>//The following code compiles and runs correctly. However, if one tries
>//to compile it with the -O2 optimization switch, an error message
>//"cannot reload integer constant operand in 'asm' " appears. Why?
>//(Note: I don't want a work-around.)
>
>#include <iostream.h>
>
>unsigned int zmax=10;
>
>#define mode4() \
>__asm__ ( \
> "movl $0x1,%%ecx;" \
> "movl %1(,%%ecx,4),%%eax;" \
> "addl %2(,%%ecx,4),%%eax;" \
> "movl %%eax,%0(,%%ecx,4);" \
> "movl $0x0,%%edx;" \
> "adcl $0x0,%%edx;" \
> "L2: incl %%ecx;" \
> "movl %1(,%%ecx,4),%%eax;" \
> "addl %%edx,%%eax;" \
> "movl $0x0,%%edx;" \
> "adcl $0x0,%%edx;" \
> "addl %2(,%%ecx,4),%%eax;" \
> "movl %%eax,%0(,%%ecx,4);" \
> "adcl $0x0,%%edx;" \
> "cmp _zmax,%%ecx;" \
> "jne L2" \
> : "=m" (z) \
> : "g" (x), "g" (y) \
> : "eax", "ecx", "edx", "memory", "cc");
I'm not sure whether this is related to your problem, but you have several
operands like "%1(,%%ecx,4)" in your code. But the %1 operand is declared
with the "g" constraint. This means that GCC would be well within its rights
to generate something like "(%ebx)(,%ecx,4)", which is clearly bogus. I
think you will need to use a constraint like "ri" instead.
Another problem that could be related is that you declare `z' as an output
operand. Since `z' is declared as `int []', it is a constant value, and it
may well be that trying to change it confuses the compiler. You don't want
to change `z's value, so try making it an input instead of an output operand.
Hope this helps.
Nate Eldredge
eldredge AT ap DOT net
- Raw text -