Message-Id: Comments: Authenticated sender is From: "Salvador Eduardo Tropea (SET)" Organization: INTI To: "Richard" , djgpp AT delorie DOT com Date: Fri, 26 Dec 1997 16:03:21 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: Extended Assembly In-reply-to: Precedence: bulk > From: "Richard" > Subject: Extended Assembly > Date: Wed, 24 Dec 1997 01:25:30 +0100 > To: djgpp AT delorie DOT com > 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 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 > --. > > > ------------------------------------ 0 -------------------------------- Visit my home page: http://www.geocities.com/SiliconValley/Vista/6552/ Salvador Eduardo Tropea (SET). (Electronics Engineer) Alternative e-mail: set-sot AT usa DOT net - ICQ: 2951574 Address: Curapaligue 2124, Caseros, 3 de Febrero Buenos Aires, (1678), ARGENTINA TE: +(541) 759 0013