lkml.org 
[lkml]   [2002]   [Apr]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: Assembly question
From
Richard Johnson wrote:
> Gabriel Paubert wrote:
> > Mark Zealey wrote:
> > > 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.

As usual you are completely wrong. Clobbers can be used ONLY for
registers that do not already appear in either the input or output
list. In this case, it is the input registers that are modified. You
have to use notation that makes that explicit.

The correct way to write this asm statement with GCC 2.95 or later is

asm volatile
("rep; stosl"
: "+D" (d), "+c" (l) /* read and write edi, ecx */
: "a" (b)
: "memory");

With earlier versions you have to use a more verbose notation.

Some further notes:

rep stosl doesn't change %eax, so a plain input parameter can be used
for that argument.

GCC assumes that any asm with output parameters has no side effects.
The memory clobber doesn't count. Therefore, it will notice that d
and l are not used again and delete the whole asm statement, unless
you qualify it with 'volatile'.

There is no point in using __asm__ instead of asm, unless you are
writing code which has to compile with -pedantic on.

zw
-
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/

\
 
 \ /
  Last update: 2005-03-22 13:25    [W:0.084 / U:0.116 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site