11.3Smrg/*	$NetBSD: atomic_cas_32.S,v 1.3 2019/04/17 07:35:38 mrg Exp $	*/
21.1Smatt/*-
31.1Smatt * Copyright (c) 2014 The NetBSD Foundation, Inc.
41.1Smatt * All rights reserved.
51.1Smatt *
61.1Smatt * This code is derived from software contributed to The NetBSD Foundation
71.1Smatt * by Matt Thomas <matt@3am-software.com>
81.1Smatt *
91.1Smatt * Redistribution and use in source and binary forms, with or without
101.1Smatt * modification, are permitted provided that the following conditions
111.1Smatt * are met:
121.1Smatt * 1. Redistributions of source code must retain the above copyright
131.1Smatt *    notice, this list of conditions and the following disclaimer.
141.1Smatt * 2. Redistributions in binary form must reproduce the above copyright
151.1Smatt *    notice, this list of conditions and the following disclaimer in the
161.1Smatt *    documentation and/or other materials provided with the distribution.
171.1Smatt *
181.1Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
191.1Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
201.1Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
211.1Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
221.1Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
231.1Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
241.1Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
251.1Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
261.1Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
271.1Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
281.1Smatt * POSSIBILITY OF SUCH DAMAGE.
291.1Smatt */
301.1Smatt
311.1Smatt#include "atomic_op_asm.h"
321.1Smatt
331.1SmattENTRY_NP(_atomic_cas_32)
341.2Smatt	mv	t0, a0
351.2Smatt1:	lr.w	a0, 0(t0)
361.2Smatt	bne	a1, a0, 2f
371.2Smatt	sc.w	t1, a2, 0(t0)
381.2Smatt	bnez	t1, 1b
391.1Smatt2:
401.1Smatt	ret
411.1SmattEND(_atomic_cas_32)
421.1Smatt
431.1SmattATOMIC_OP_ALIAS(atomic_cas_32,_atomic_cas_32)
441.1SmattATOMIC_OP_ALIAS(atomic_cas_uint,_atomic_cas_32)
451.1SmattSTRONG_ALIAS(_atomic_cas_uint,_atomic_cas_32)
461.3Smrg
471.3SmrgATOMIC_OP_ALIAS(atomic_cas_32_ni,_atomic_cas_32)
481.3SmrgSTRONG_ALIAS(_atomic_cas_32_ni,_atomic_cas_32)
491.3SmrgATOMIC_OP_ALIAS(atomic_cas_uint_ni,_atomic_cas_32)
501.3SmrgSTRONG_ALIAS(_atomic_cas_uint_ni,_atomic_cas_32)
511.3Smrg
521.1Smatt#ifndef _LP64
531.1SmattATOMIC_OP_ALIAS(atomic_cas_ulong,_atomic_cas_32)
541.1SmattSTRONG_ALIAS(_atomic_cas_ulong,_atomic_cas_32)
551.1SmattATOMIC_OP_ALIAS(atomic_cas_ulong_ni,_atomic_cas_32)
561.1SmattSTRONG_ALIAS(_atomic_cas_ulong_ni,_atomic_cas_32)
571.1SmattATOMIC_OP_ALIAS(atomic_cas_ptr,_atomic_cas_32)
581.1SmattSTRONG_ALIAS(_atomic_cas_ptr,_atomic_cas_32)
591.1SmattATOMIC_OP_ALIAS(atomic_cas_ptr_ni,_atomic_cas_32)
601.1SmattSTRONG_ALIAS(_atomic_cas_ptr_ni,_atomic_cas_32)
611.1Smatt#endif
621.1SmattCRT_ALIAS(__sync_val_compare_and_swap_4,_atomic_cas_32)
631.1Smatt
641.1SmattENTRY_NP(_atomic_bool_cas_32)
651.2Smatt	mv	t0, a0
661.2Smatt	li	a0, 0
671.2Smatt1:	lr.w	t1, 0(t0)
681.2Smatt	bne	a1, t1, 2f
691.2Smatt	sc.w	t1, a2, 0(t0)
701.2Smatt	bnez	t1, 1b
711.2Smatt	li	a0, 1
721.1Smatt2:
731.1Smatt	ret
741.1SmattEND(_atomic_bool_cas_32)
751.1Smatt
761.1SmattATOMIC_OP_ALIAS(atomic_bool_cas_32,_atomic_bool_cas_32)
771.1SmattCRT_ALIAS(__bool_val_compare_and_swap_4,_atomic_bool_cas_32)
78