Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 24 Feb 2010 18:07:23 -0800
From:      Juli Mallett <jmallett@FreeBSD.org>
To:        Patrick Mahan <mahan@mahan.org>
Cc:        freebsd-mips@freebsd.org
Subject:   Re: Writing MIPS assembler instructions in C
Message-ID:  <eaa228be1002241807q2613ccecy9773155e68ccda62@mail.gmail.com>
In-Reply-To: <17060.1267061906@mahan.org>
References:  <17060.1267061906@mahan.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi Patrick,

On Wed, Feb 24, 2010 at 17:38, Patrick Mahan <mahan@mahan.org> wrote:
> part of some code built on the linux platform and
> there they are using "%[rt]" which I cannot find
> a description.

%[foo] can be used to refer to named parameters (input or output,
maybe even clobbered) of inline assembly instructions rather than
using %0, %1, etc., which can be hard to read.  Consider:

%%%
static inline bool
atomic_cmpset64(volatile uint64_t *p, uint64_t o, uint64_t v)
{
	uint64_t temp;
	int res;

	asm volatile (
	"1:\n\t"
	"move	%[res], $0\n\t"
	"lld	%[temp], %[p]\n\t"
	"bne	%[temp], %[o], 2f\n\t"
	"move	%[temp], %[v]\n\t"
	"li	%[res], 1\n\t"
	"scd	%[temp], %[p]\n\t"
	"beqz	%[temp], 1b\n\t"
	"2:\n\t"
	: [res] "=&r"(res), [temp] "=&r"(temp), [p] "+m"(*p)
	: [o] "r"(o), [v] "r"(v)
	: "memory"
	);

	return (res != 0);
}
%%%

The brackets with the input and output parameters specify what names
to use to refer to them in the assembly listing (here they happen to
be mostly the same as the variable names, but that's not necessary.)

Juli.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?eaa228be1002241807q2613ccecy9773155e68ccda62>