atomic_swap.S revision 1.2
11.2Smatt/*	$NetBSD: atomic_swap.S,v 1.2 2009/12/14 00:39:00 matt Exp $	*/
21.2Smatt
31.2Smatt/*-
41.2Smatt * Copyright (c) 2008 The NetBSD Foundation, Inc.
51.2Smatt * All rights reserved.
61.2Smatt *
71.2Smatt * Redistribution and use in source and binary forms, with or without
81.2Smatt * modification, are permitted provided that the following conditions
91.2Smatt * are met:
101.2Smatt * 1. Redistributions of source code must retain the above copyright
111.2Smatt *    notice, this list of conditions and the following disclaimer.
121.2Smatt * 2. Redistributions in binary form must reproduce the above copyright
131.2Smatt *    notice, this list of conditions and the following disclaimer in the
141.2Smatt *    documentation and/or other materials provided with the distribution.
151.2Smatt *
161.2Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
171.2Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
181.2Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
191.2Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
201.2Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
211.2Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
221.2Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
231.2Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
241.2Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
251.2Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
261.2Smatt * POSSIBILITY OF SUCH DAMAGE.
271.2Smatt */
281.2Smatt
291.2Smatt#include <sys/cdefs.h>
301.2Smatt#include <machine/asm.h>
311.2Smatt#include "atomic_op_asm.h"
321.2Smatt
331.2SmattRCSID("$NetBSD: atomic_swap.S,v 1.2 2009/12/14 00:39:00 matt Exp $")
341.2Smatt
351.2Smatt	.text
361.2Smatt	.set	noat
371.2Smatt	.set	noreorder
381.2Smatt	.set	nomacro
391.2Smatt
401.2SmattLEAF(_atomic_swap_32)
411.2Smatt1:	INT_LL		v0, 0(a0)
421.2Smatt	 nop
431.2Smatt	move		t0, a1
441.2Smatt	INT_SC		t0, 0(a0)
451.2Smatt	beq		t0, zero, 1b
461.2Smatt 	 nop
471.2Smatt2:
481.2Smatt	j		ra
491.2Smatt	 nop
501.2SmattEND(_atomic_swap_32)
511.2SmattATOMIC_OP_ALIAS(atomic_swap_32, _atomic_swap_32)
521.2Smatt
531.2Smatt#if !defined(__mips_o32)
541.2SmattLEAF(_atomic_swap_64)
551.2Smatt1:	REG_LL		v0, 0(a0)
561.2Smatt	 nop
571.2Smatt	move		t0, a1
581.2Smatt	REG_SC		t0, 0(a0)
591.2Smatt	beq		t0, zero, 1b
601.2Smatt 	 nop
611.2Smatt2:
621.2Smatt	j		ra
631.2Smatt	 nop
641.2SmattEND(_atomic_swap_64)
651.2SmattATOMIC_OP_ALIAS(atomic_swap_64, _atomic_swap_64)
661.2Smatt#endif
671.2Smatt
681.2Smatt#ifdef _LP64
691.2SmattSTRONG_ALIAS(_atomic_swap_ptr,		_atomic_swap_64)
701.2SmattSTRONG_ALIAS(_atomic_swap_ulong,	_atomic_swap_64)
711.2Smatt#else
721.2SmattSTRONG_ALIAS(_atomic_swap_ptr,		_atomic_swap_32)
731.2SmattSTRONG_ALIAS(_atomic_swap_ulong,	_atomic_swap_32)
741.2Smatt#endif
751.2SmattSTRONG_ALIAS(_atomic_swap_uint,		_atomic_swap_32)
761.2Smatt
771.2SmattATOMIC_OP_ALIAS(atomic_swap_ptr,	_atomic_swap_ptr)
781.2SmattATOMIC_OP_ALIAS(atomic_swap_uint,	_atomic_swap_uint)
791.2SmattATOMIC_OP_ALIAS(atomic_swap_ulong,	_atomic_swap_ulong)
80