Re: Assembly question

From: Richard B. Johnson (root@chaos.analogic.com)
Date: Fri Apr 26 2002 - 07:34:04 EST


On Fri, 26 Apr 2002, Gabriel Paubert wrote:

> Mark Zealey wrote:
>
> > On Thu, Apr 25, 2002 at 10:32:25AM +0200, Szekeres Istvan wrote:
> >
> >
> >> void p_memset_dword( void *d, int b, int l ) { __asm__ ("rep\n\t"
> "stosl\n\t"
> >>
>
> >> : : "D" (d), "a" (b), "c" (l) : "memory","edi", "eax", "ecx"
> >>
> >
> > An input or output operand is implicitly clobbered, so it should be
> ^^^^^
> I had expected gcc specialists to jump on that one: if you don't
> explicitly tell gcc that an input is clobbered, it may reuse it later if
> it needs the same value. So the clobbers are necessary...

    : : "D" (d), "a" (b), "c" (l) : "memory","edi", "eax", "ecx"
... is correct. Registers EDI, EAX, and ECX are altered and memory
is changed. Nothing having to do with the 'input' is altered in
any meaningful sense. You alter an 'input' by doing something like:

        pushl %ebx
        ..... code
        popl %eax ; Input value of ebx is destroyed

Passed parameters are (usually) passed on the stack. They are
local and disappear when the call returns, i.e.,

        pushl string ; 4 - byte address
        call puts ; call function
        addl $4, esp ; Level stack

GCC may optimize in-line and not bother to push a value that is
readily accessible to the in-line function. That value is not
clobbered in any way. The in-line function doesn't have to
'return' since it's in-line. Therefore the return address isn't
on the stack either. When setting up 'clobbers', you have
observe the registers that are used and declare whether or
not memory is altered. That's all. For instance, we see EAX as
a clobbered register. GCC may decide that it is a scratch-register
so it doesn't bother to save/restore its value. On the other hand,
if you didn't tell GCC that you destroyed EAX, it's a bug and a
hard-to-find bug because most of the time, the code will work.

Cheers,
Dick Johnson

Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).

                 Windows-2000/Professional isn't.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Apr 30 2002 - 22:00:12 EST