11.5Sskrll/*	$NetBSD: atomic_xor_32.S,v 1.5 2021/07/28 07:32:20 skrll Exp $	*/
21.1Smatt/*-
31.1Smatt * Copyright (c) 2008 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.4Sskrll#if defined(_ARM_ARCH_6)
341.1Smatt
351.1SmattENTRY_NP(_atomic_xor_32)
361.1Smatt	mov	ip, r0
371.1Smatt1:	ldrex	r0, [ip]		/* load old value (to be returned) */
381.1Smatt	eors	r3, r0, r1		/* calculate new value */
391.1Smatt	strex	r2, r3, [ip]		/* try to store */
401.1Smatt	cmp	r2, #0			/*   succeed? */
411.1Smatt	bne	1b			/*     no, try again */
421.1Smatt	RET				/* return old value */
431.1SmattEND(_atomic_xor_32)
441.1Smatt
451.1SmattATOMIC_OP_ALIAS(atomic_xor_32,_atomic_xor_32)
461.1SmattATOMIC_OP_ALIAS(atomic_xor_uint,_atomic_xor_32)
471.1SmattATOMIC_OP_ALIAS(atomic_xor_ulong,_atomic_xor_32)
481.3SjoergCRT_ALIAS(__atomic_fetch_xor_4,_atomic_xor_32)
491.1SmattSTRONG_ALIAS(_atomic_xor_uint,_atomic_xor_32)
501.1SmattSTRONG_ALIAS(_atomic_xor_ulong,_atomic_xor_32)
511.1Smatt
521.5SskrllENTRY_NP(__sync_fetch_and_xor_4)
531.5Sskrll	push	{r4, lr}
541.5Sskrll	DMB
551.5Sskrll	bl	_atomic_xor_32
561.5Sskrll	DMB
571.5Sskrll	pop	{r4, pc}
581.5SskrllEND(__sync_fetch_and_xor_4)
591.5Sskrll
601.1SmattENTRY_NP(_atomic_xor_32_nv)
611.1Smatt	mov	ip, r0			/* need r0 for return value */
621.1Smatt1:	ldrex	r0, [ip]		/* load old value */
631.1Smatt	eors	r0, r0, r1		/* calculate new value (return value) */
641.1Smatt	strex	r2, r0, [ip]		/* try to store */
651.1Smatt	cmp	r2, #0			/*   succeed? */
661.1Smatt	bne	1b			/*     no, try again? */
671.1Smatt	RET				/* return new value */
681.1SmattEND(_atomic_xor_32_nv)
691.1Smatt
701.1SmattATOMIC_OP_ALIAS(atomic_xor_32_nv,_atomic_xor_32_nv)
711.1SmattATOMIC_OP_ALIAS(atomic_xor_uint_nv,_atomic_xor_32_nv)
721.1SmattATOMIC_OP_ALIAS(atomic_xor_ulong_nv,_atomic_xor_32_nv)
731.1SmattSTRONG_ALIAS(_atomic_xor_uint_nv,_atomic_xor_32_nv)
741.1SmattSTRONG_ALIAS(_atomic_xor_ulong_nv,_atomic_xor_32_nv)
751.1Smatt
761.5SskrllENTRY_NP(__sync_xor_and_fetch_4)
771.5Sskrll	push	{r4, lr}
781.5Sskrll	DMB
791.5Sskrll	bl	_atomic_xor_32_nv
801.5Sskrll	DMB
811.5Sskrll	pop	{r4, pc}
821.5SskrllEND(__sync_xor_and_fetch_4)
831.5Sskrll
841.5Sskrll
851.1Smatt#endif /* _ARM_ARCH_6 */
86