xref: /minix3/common/lib/libc/arch/sparc/atomic/atomic_cas_up.S (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc/*	$NetBSD: atomic_cas_up.S,v 1.2 2014/01/29 13:06:36 martin Exp $	*/
284d9c625SLionel Sambuc
384d9c625SLionel Sambuc/*-
484d9c625SLionel Sambuc * Copyright (c) 2012 The NetBSD Foundation, Inc.
584d9c625SLionel Sambuc * All rights reserved.
684d9c625SLionel Sambuc *
784d9c625SLionel Sambuc * Redistribution and use in source and binary forms, with or without
884d9c625SLionel Sambuc * modification, are permitted provided that the following conditions
984d9c625SLionel Sambuc * are met:
1084d9c625SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
1184d9c625SLionel Sambuc *    notice, this list of conditions and the following disclaimer.
1284d9c625SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
1384d9c625SLionel Sambuc *    notice, this list of conditions and the following disclaimer in the
1484d9c625SLionel Sambuc *    documentation and/or other materials provided with the distribution.
1584d9c625SLionel Sambuc *
1684d9c625SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1784d9c625SLionel Sambuc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1884d9c625SLionel Sambuc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1984d9c625SLionel Sambuc * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2084d9c625SLionel Sambuc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2184d9c625SLionel Sambuc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2284d9c625SLionel Sambuc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2384d9c625SLionel Sambuc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2484d9c625SLionel Sambuc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2584d9c625SLionel Sambuc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2684d9c625SLionel Sambuc * POSSIBILITY OF SUCH DAMAGE.
2784d9c625SLionel Sambuc */
2884d9c625SLionel Sambuc
2984d9c625SLionel Sambuc#include <sys/ras.h>
3084d9c625SLionel Sambuc#include "atomic_op_asm.h"
3184d9c625SLionel Sambuc
3284d9c625SLionel Sambuc	.text
3384d9c625SLionel Sambuc
3484d9c625SLionel SambucENTRY(_atomic_cas_up)
3584d9c625SLionel Sambuc	.hidden	_C_LABEL(_atomic_cas_up)
3684d9c625SLionel SambucRAS_START_ASM_HIDDEN(_atomic_cas)
3784d9c625SLionel Sambuc	ld	[%o0], %o3			! get old value
3884d9c625SLionel Sambuc	cmp	%o1, %o3			! old == new?
3984d9c625SLionel Sambuc	beq,a	1f				! yes, do the store
4084d9c625SLionel Sambuc	 st	%o2, [%o0]			! (in the delay slot)
4184d9c625SLionel SambucRAS_END_ASM_HIDDEN(_atomic_cas)
4284d9c625SLionel Sambuc1:
4384d9c625SLionel Sambuc	retl
4484d9c625SLionel Sambuc	 mov	%o3, %o0			! return old value
4584d9c625SLionel Sambuc
46*0a6a1f1dSLionel SambucENTRY(_atomic_cas_16_up)
47*0a6a1f1dSLionel Sambuc	.hidden	_C_LABEL(_atomic_cas_16_up)
48*0a6a1f1dSLionel SambucRAS_START_ASM_HIDDEN(_atomic_cas_16)
49*0a6a1f1dSLionel Sambuc	lduh	[%o0], %o3			! get old value
50*0a6a1f1dSLionel Sambuc	cmp	%o1, %o3			! old == new?
51*0a6a1f1dSLionel Sambuc	beq,a	1f				! yes, do the store
52*0a6a1f1dSLionel Sambuc	 sth	%o2, [%o0]			! (in the delay slot)
53*0a6a1f1dSLionel SambucRAS_END_ASM_HIDDEN(_atomic_cas_16)
54*0a6a1f1dSLionel Sambuc1:
55*0a6a1f1dSLionel Sambuc	retl
56*0a6a1f1dSLionel Sambuc	 mov	%o3, %o0			! return old value
57*0a6a1f1dSLionel Sambuc
58*0a6a1f1dSLionel SambucENTRY(_atomic_cas_8_up)
59*0a6a1f1dSLionel Sambuc	.hidden	_C_LABEL(_atomic_cas_8_up)
60*0a6a1f1dSLionel SambucRAS_START_ASM_HIDDEN(_atomic_cas_8)
61*0a6a1f1dSLionel Sambuc	ldub	[%o0], %o3			! get old value
62*0a6a1f1dSLionel Sambuc	cmp	%o1, %o3			! old == new?
63*0a6a1f1dSLionel Sambuc	beq,a	1f				! yes, do the store
64*0a6a1f1dSLionel Sambuc	 stb	%o2, [%o0]			! (in the delay slot)
65*0a6a1f1dSLionel SambucRAS_END_ASM_HIDDEN(_atomic_cas_8)
66*0a6a1f1dSLionel Sambuc1:
67*0a6a1f1dSLionel Sambuc	retl
68*0a6a1f1dSLionel Sambuc	 mov	%o3, %o0			! return old value
69*0a6a1f1dSLionel Sambuc
70