11.3Sriastrad/*	$NetBSD: atomic_cas_up.S,v 1.3 2022/04/06 22:47:56 riastradh Exp $	*/
21.1Smartin
31.1Smartin/*-
41.1Smartin * Copyright (c) 2012 The NetBSD Foundation, Inc.
51.1Smartin * All rights reserved.
61.1Smartin *
71.1Smartin * Redistribution and use in source and binary forms, with or without
81.1Smartin * modification, are permitted provided that the following conditions
91.1Smartin * are met:
101.1Smartin * 1. Redistributions of source code must retain the above copyright
111.1Smartin *    notice, this list of conditions and the following disclaimer.
121.1Smartin * 2. Redistributions in binary form must reproduce the above copyright
131.1Smartin *    notice, this list of conditions and the following disclaimer in the
141.1Smartin *    documentation and/or other materials provided with the distribution.
151.3Sriastrad *
161.1Smartin * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
171.1Smartin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
181.1Smartin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
191.1Smartin * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
201.1Smartin * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
211.1Smartin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
221.1Smartin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
231.1Smartin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
241.1Smartin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
251.1Smartin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
261.1Smartin * POSSIBILITY OF SUCH DAMAGE.
271.1Smartin */
281.1Smartin
291.1Smartin#include <sys/ras.h>
301.1Smartin#include "atomic_op_asm.h"
311.1Smartin
321.1Smartin	.text
331.1Smartin
341.1SmartinENTRY(_atomic_cas_up)
351.1Smartin	.hidden	_C_LABEL(_atomic_cas_up)
361.1SmartinRAS_START_ASM_HIDDEN(_atomic_cas)
371.1Smartin	ld	[%o0], %o3			! get old value
381.1Smartin	cmp	%o1, %o3			! old == new?
391.1Smartin	beq,a	1f				! yes, do the store
401.1Smartin	 st	%o2, [%o0]			! (in the delay slot)
411.1SmartinRAS_END_ASM_HIDDEN(_atomic_cas)
421.1Smartin1:
431.1Smartin	retl
441.1Smartin	 mov	%o3, %o0			! return old value
451.1Smartin
461.2SmartinENTRY(_atomic_cas_16_up)
471.2Smartin	.hidden	_C_LABEL(_atomic_cas_16_up)
481.2SmartinRAS_START_ASM_HIDDEN(_atomic_cas_16)
491.2Smartin	lduh	[%o0], %o3			! get old value
501.2Smartin	cmp	%o1, %o3			! old == new?
511.2Smartin	beq,a	1f				! yes, do the store
521.2Smartin	 sth	%o2, [%o0]			! (in the delay slot)
531.2SmartinRAS_END_ASM_HIDDEN(_atomic_cas_16)
541.2Smartin1:
551.2Smartin	retl
561.2Smartin	 mov	%o3, %o0			! return old value
571.2Smartin
581.2SmartinENTRY(_atomic_cas_8_up)
591.2Smartin	.hidden	_C_LABEL(_atomic_cas_8_up)
601.2SmartinRAS_START_ASM_HIDDEN(_atomic_cas_8)
611.2Smartin	ldub	[%o0], %o3			! get old value
621.2Smartin	cmp	%o1, %o3			! old == new?
631.2Smartin	beq,a	1f				! yes, do the store
641.2Smartin	 stb	%o2, [%o0]			! (in the delay slot)
651.2SmartinRAS_END_ASM_HIDDEN(_atomic_cas_8)
661.2Smartin1:
671.2Smartin	retl
681.2Smartin	 mov	%o3, %o0			! return old value
691.2Smartin
70