11.5Sskrll/*	$NetBSD: atomic_or_16.S,v 1.5 2021/07/28 07:32:20 skrll Exp $	*/
21.1Smatt/*-
31.1Smatt * Copyright (c) 2013 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_or_16)
361.1Smatt	mov	ip, r0
371.1Smatt1:	ldrexh	r0, [ip]		/* load old value (to be returned) */
381.1Smatt	orrs	r3, r0, r1		/* calculate new value */
391.1Smatt	strexh	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_or_16)
441.1Smatt
451.1SmattATOMIC_OP_ALIAS(atomic_or_16,_atomic_or_16)
461.1SmattATOMIC_OP_ALIAS(atomic_or_ushort,_atomic_or_16)
471.3SjoergCRT_ALIAS(__atomic_fetch_or_2,_atomic_or_16)
481.1SmattSTRONG_ALIAS(_atomic_or_ushort,_atomic_or_16)
491.1Smatt
501.5SskrllENTRY_NP(__sync_fetch_and_or_2)
511.5Sskrll	push	{r4, lr}
521.5Sskrll	DMB
531.5Sskrll	bl	_atomic_or_16
541.5Sskrll	DMB
551.5Sskrll	pop	{r4, pc}
561.5SskrllEND(__sync_fetch_and_or_2)
571.5Sskrll
581.5Sskrll
591.1SmattENTRY_NP(_atomic_or_16_nv)
601.1Smatt	mov	ip, r0			/* need r0 for return value */
611.1Smatt1:	ldrexh	r0, [ip]		/* load old value */
621.1Smatt	orrs	r0, r0, r1		/* calculate new value (return value) */
631.1Smatt	strexh	r2, r0, [ip]		/* try to store */
641.1Smatt	cmp	r2, #0			/*   succeed? */
651.1Smatt	bne	1b			/*     no, try again? */
661.1Smatt	RET				/* return new value */
671.1SmattEND(_atomic_or_16_nv)
681.1Smatt
691.1SmattATOMIC_OP_ALIAS(atomic_or_16_nv,_atomic_or_16_nv)
701.1SmattATOMIC_OP_ALIAS(atomic_or_ushort_nv,_atomic_or_16_nv)
711.1SmattSTRONG_ALIAS(_atomic_or_ushort_nv,_atomic_or_16_nv)
721.1Smatt
731.5SskrllENTRY_NP(__sync_or_and_fetch_2)
741.5Sskrll	push	{r4, lr}
751.5Sskrll	DMB
761.5Sskrll	bl	_atomic_or_16_nv
771.5Sskrll	DMB
781.5Sskrll	pop	{r4, pc}
791.5SskrllEND(__sync_or_and_fetch_2)
801.5Sskrll
811.1Smatt#endif /* _ARM_ARCH_6 */
82