Date: Thu, 7 Aug 2003 12:12:33 -0700 From: Marcel Moolenaar <marcel@xcllnt.net> To: deischen@freebsd.org Cc: alpha@freebsd.org Subject: Re: Atomic swap Message-ID: <20030807191233.GB559@athlon.pn.xcllnt.net> In-Reply-To: <Pine.GSO.4.10.10308071500390.29641-100000@pcnet5.pcnet.com> References: <20030807185507.GA559@athlon.pn.xcllnt.net> <Pine.GSO.4.10.10308071500390.29641-100000@pcnet5.pcnet.com>
index | next in thread | previous in thread | raw e-mail
On Thu, Aug 07, 2003 at 03:05:28PM -0400, Daniel Eischen wrote:
> > The following has been written down without testing (I
> > dropped the cosmetic \t and instead indented by hand to
> > make the source code readable, not what is given to the
> > assembler (per se):
> >
> > static __inline void
> > atomic_swap_long(volatile long *dst, long val, long *res)
> > {
> > __asm ( "1: ldq_l t0,%0\n"
> > " mov %1,t1\n"
>
> If I swap the first 2 instructions:
>
> __asm ( "1: mov %1,t1\n"
> ldq_l t0,%0\n"
>
> that eliminates 1 instruction from between the locked
> instructions. Is there anything wrong with doing that?
No.
>
> So it's OK to hardcode registers (t0, t1) in inline assembly?
>
Not generally. On some platforms the compiler needs temporary
registers to move the C types into registers. You need to stay
away from the registers the compiler uses. I don't think this
is the case here, but you might want to check (ie cc -S and
see if the compiler uses t0 and t1). Since arguments are passed
in registers, the compiler can directly use 0(a0), a1 and 0(a2)
without needing anything else.
--
Marcel Moolenaar USPA: A-39004 marcel@xcllnt.net
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030807191233.GB559>
