Writing MIPS assembler instructions in C

Juli Mallett jmallett at FreeBSD.org
Thu Feb 25 02:07:49 UTC 2010


Hi Patrick,

On Wed, Feb 24, 2010 at 17:38, Patrick Mahan <mahan at 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.


More information about the freebsd-mips mailing list