Mail Archives: djgpp/1997/12/23/19:45:30
From: | "Richard" <RiM AT msn DOT com>
|
Subject: | Extended Assembly
|
Date: | Wed, 24 Dec 1997 01:25:30 +0100
|
Lines: | 107
|
MIME-Version: | 1.0
|
Message-ID: | <e$JXWMAE9GA.170@upnetnews02.moswest.msn.net>
|
Newsgroups: | comp.os.msdos.djgpp
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
I ran into a problem with extended assembly. It seems to ignore my
clobber list and reuse the
registers. Usually it works save in some situation such as the
following :
(I tried to narrow it down to a example not too artificial)
**********************************
long overflow;
#define addll(x, y) \
({ \
long __result; \
asm( \
"movl %1,%%eax \n\t" \
"xorl %%edx,%%edx \n\t" \
"addl %2,%%eax \n\t" \
"adcl %%edx,%%edx \n\t" \
"movl %%edx,_overflow \n\t" \
:"=a" (__result) \
:"g" (x), "g" (y) \
:"%eax", "%edx", "memory" \
); \
__result; \
})
long * f(long *x, long *y, long *z,int lx){
int i, j;
for(i=1;i<lx;i++)
z[i] = addll( x[i], y[i]);
return z;
}
**********************************
Which gives such code : (basic prolog/epilog trimmed)
movl 12(%ebp),%edi
movl 16(%ebp),%esi
movl 20(%ebp),%ebx
movl $1,%ecx
cmpl %ebx,%ecx
jge L3
.align 2,0x90
L5:
movl 8(%ebp),%eax
/APP
movl (%eax,%ecx,4),%eax <---- Here is the problem !
xorl %edx,%edx
addl (%edi,%ecx,4),%eax
adcl %edx,%edx
movl %edx,_overflow
/NO_APP
movl %eax,(%esi,%ecx,4)
incl %ecx
cmpl %ebx,%ecx
jl L5
L3:
movl %esi,%eax
leal -12(%ebp),%esp
***************************************
The trouble is the use of the "eax" register as base pointer in the
instruction :
movl (%eax,%ecx,4),%eax
If it was three local arrays, such case would not arise as in every
array the "ebp"
register would hold the base pointer.
In this very case, I can tell the gcc to use "esi" and "edi" to hold
the x and y
parameters. But it does not cure the problem in other situations.
Is it simply that gcc run out of register ? So, why it does not take
some variable
out of the registers, such as "ebx" (my "lx") ?
Or is there a bug in my clobber list ? I tried many variations, but it
changed nothing.
Why gcc does not take into account my clobber list ?
Please shed some light on my troubles !
--Richard.
PS :
* "gcc --version " give me "2.7.2". It should be the one bundled in
the 2.00 djgpp.
* The optimization level doesn't change anything on that problem.
* I know that here I could ask gcc to load "eax" for me. But in a
slightly more
complicated assembly function, I had to load "eax" after a few other
instructions.
*If I ask gcc to use :"r" (x), "r" (y), this give me the following
code which is hardly
better !
L5:
movl 8(%ebp),%eax
movl (%eax,%ecx,4),%ebx
movl 12(%ebp),%eax
movl (%eax,%ecx,4),%eax
/APP
movl %ebx,%eax <-- Overwrite eax
xorl %edx,%edx
addl %eax,%eax <-- and add it to myself !
adcl %edx,%edx
movl %edx,_overflow
/NO_APP
--.
- Raw text -