From: Zack Weinberg <zack@codesourcery.com>
To: linux-kernel@vger.kernel.org
Subject: Re: Assembly question
Date: Sun, 28 Apr 2002 11:07:20 -0700 [thread overview]
Message-ID: <20020428180720.GT26266@codesourcery.com> (raw)
In-Reply-To: <Pine.LNX.3.95.1020426081723.8083A-100000@chaos.analogic.com>
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
prev parent reply other threads:[~2002-04-28 18:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-25 8:32 Assembly question Szekeres Istvan
2002-04-25 23:52 ` Mark Zealey
2002-04-26 11:37 ` Gabriel Paubert
2002-04-26 12:34 ` Richard B. Johnson
2002-04-28 18:07 ` Zack Weinberg [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020428180720.GT26266@codesourcery.com \
--to=zack@codesourcery.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox