xref: /titanic_52/usr/src/common/atomic/sparcv9/atomic.s (revision 9a70fc3be3b1e966bf78825cdb8d509963a6f0a1)
17c478bd9Sstevel@tonic-gate/*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5dfb96a4fSab196087 * Common Development and Distribution License (the "License").
6dfb96a4fSab196087 * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217257d1b4Sraf
227c478bd9Sstevel@tonic-gate/*
23895ca178Sae112802 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
27*9a70fc3bSMark J. Nelson	.file	"atomic.s"
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h>
307c478bd9Sstevel@tonic-gate
31895ca178Sae112802/*
32895ca178Sae112802 * ATOMIC_BO_ENABLE_SHIFT can be selectively defined by processors
33895ca178Sae112802 * to enable exponential backoff. No definition means backoff is
34895ca178Sae112802 * not desired i.e. backoff should be disabled.
35895ca178Sae112802 * By default, the shift value is used to generate a power of 2
36895ca178Sae112802 * value for backoff limit. In the kernel, processors scale this
37895ca178Sae112802 * shift value with the number of online cpus.
38895ca178Sae112802 */
39895ca178Sae112802
407c478bd9Sstevel@tonic-gate#if defined(_KERNEL)
417c478bd9Sstevel@tonic-gate	/*
427c478bd9Sstevel@tonic-gate	 * Legacy kernel interfaces; they will go away (eventually).
437c478bd9Sstevel@tonic-gate	 */
447c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(cas8,atomic_cas_8,function)
457c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(cas32,atomic_cas_32,function)
467c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(cas64,atomic_cas_64,function)
477c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(caslong,atomic_cas_ulong,function)
487c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(casptr,atomic_cas_ptr,function)
497c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(atomic_and_long,atomic_and_ulong,function)
507c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(atomic_or_long,atomic_or_ulong,function)
517c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(swapl,atomic_swap_32,function)
52895ca178Sae112802
53895ca178Sae112802#ifdef ATOMIC_BO_ENABLE_SHIFT
54895ca178Sae112802
55895ca178Sae112802#if !defined(lint)
56895ca178Sae112802	.weak   cpu_atomic_delay
57895ca178Sae112802	.type   cpu_atomic_delay, #function
58895ca178Sae112802#endif  /* lint */
59895ca178Sae112802
60895ca178Sae112802/*
61895ca178Sae112802 * For the kernel, invoke processor specific delay routine to perform
62895ca178Sae112802 * low-impact spin delay. The value of ATOMIC_BO_ENABLE_SHIFT is tuned
63895ca178Sae112802 * with respect to the specific spin delay implementation.
64895ca178Sae112802 */
65895ca178Sae112802#define	DELAY_SPIN(label, tmp1, tmp2)					\
66895ca178Sae112802	/*								; \
67895ca178Sae112802	 * Define a pragma weak reference to a cpu specific		; \
68895ca178Sae112802	 * delay routine for atomic backoff. For CPUs that		; \
69895ca178Sae112802	 * have no such delay routine defined, the delay becomes	; \
70895ca178Sae112802	 * just a simple tight loop.					; \
71895ca178Sae112802	 *								; \
72895ca178Sae112802	 * tmp1 = holds CPU specific delay routine			; \
73895ca178Sae112802	 * tmp2 = holds atomic routine's callee return address		; \
74895ca178Sae112802	 */								; \
75895ca178Sae112802	sethi	%hi(cpu_atomic_delay), tmp1				; \
76895ca178Sae112802	or	tmp1, %lo(cpu_atomic_delay), tmp1			; \
77895ca178Sae112802label/**/0:								; \
78895ca178Sae112802	brz,pn	tmp1, label/**/1					; \
79895ca178Sae112802	mov	%o7, tmp2						; \
80895ca178Sae112802	jmpl	tmp1, %o7	/* call CPU specific delay routine */	; \
81895ca178Sae112802	  nop			/* delay slot : do nothing */		; \
82895ca178Sae112802	mov	tmp2, %o7	/* restore callee's return address */	; \
83895ca178Sae112802label/**/1:
84895ca178Sae112802
85895ca178Sae112802/*
86895ca178Sae112802 * For the kernel, we take into consideration of cas failures
87895ca178Sae112802 * and also scale the backoff limit w.r.t. the number of cpus.
88895ca178Sae112802 * For cas failures, we reset the backoff value to 1 if the cas
89895ca178Sae112802 * failures exceed or equal to the number of online cpus. This
90895ca178Sae112802 * will enforce some degree of fairness and prevent starvation.
91895ca178Sae112802 * We also scale/normalize the processor provided specific
92895ca178Sae112802 * ATOMIC_BO_ENABLE_SHIFT w.r.t. the number of online cpus to
93895ca178Sae112802 * obtain the actual final limit to use.
94895ca178Sae112802 */
95895ca178Sae112802#define ATOMIC_BACKOFF_CPU(val, limit, ncpu, cas_cnt, label)		\
96895ca178Sae112802	brnz,pt	ncpu, label/**/0					; \
97895ca178Sae112802	  inc	cas_cnt							; \
98895ca178Sae112802	sethi	%hi(ncpus_online), ncpu					; \
99895ca178Sae112802	ld	[ncpu + %lo(ncpus_online)], ncpu			; \
100895ca178Sae112802label/**/0:								; \
101895ca178Sae112802	cmp	cas_cnt, ncpu						; \
102895ca178Sae112802	blu,pt	%xcc, label/**/1					; \
103895ca178Sae112802	  sllx	ncpu, ATOMIC_BO_ENABLE_SHIFT, limit			; \
104895ca178Sae112802	mov	%g0, cas_cnt						; \
105895ca178Sae112802	mov	1, val							; \
106895ca178Sae112802label/**/1:
107895ca178Sae112802#endif	/* ATOMIC_BO_ENABLE_SHIFT */
108895ca178Sae112802
109895ca178Sae112802#else	/* _KERNEL */
110895ca178Sae112802
111895ca178Sae112802/*
112895ca178Sae112802 * ATOMIC_BO_ENABLE_SHIFT may be enabled/defined here for generic
113895ca178Sae112802 * libc atomics. None for now.
114895ca178Sae112802 */
115895ca178Sae112802#ifdef ATOMIC_BO_ENABLE_SHIFT
116895ca178Sae112802#define	DELAY_SPIN(label, tmp1, tmp2)	\
117895ca178Sae112802label/**/0:
118895ca178Sae112802
119895ca178Sae112802#define ATOMIC_BACKOFF_CPU(val, limit, ncpu, cas_cnt, label)  \
120895ca178Sae112802	set	1 << ATOMIC_BO_ENABLE_SHIFT, limit
121895ca178Sae112802#endif	/* ATOMIC_BO_ENABLE_SHIFT */
122895ca178Sae112802#endif	/* _KERNEL */
123895ca178Sae112802
124895ca178Sae112802#ifdef ATOMIC_BO_ENABLE_SHIFT
125895ca178Sae112802/*
126895ca178Sae112802 * ATOMIC_BACKOFF_INIT macro for initialization.
127895ca178Sae112802 * backoff val is initialized to 1.
128895ca178Sae112802 * ncpu is initialized to 0
129895ca178Sae112802 * The cas_cnt counts the cas instruction failure and is
130895ca178Sae112802 * initialized to 0.
131895ca178Sae112802 */
132895ca178Sae112802#define ATOMIC_BACKOFF_INIT(val, ncpu, cas_cnt)	\
133895ca178Sae112802	mov	1, val				; \
134895ca178Sae112802	mov	%g0, ncpu			; \
135895ca178Sae112802	mov	%g0, cas_cnt
136895ca178Sae112802
137895ca178Sae112802#define ATOMIC_BACKOFF_BRANCH(cr, backoff, loop) \
138895ca178Sae112802	bne,a,pn cr, backoff
139895ca178Sae112802
140895ca178Sae112802/*
141895ca178Sae112802 * Main ATOMIC_BACKOFF_BACKOFF macro for backoff.
142895ca178Sae112802 */
143895ca178Sae112802#define ATOMIC_BACKOFF_BACKOFF(val, limit, ncpu, cas_cnt, label, retlabel) \
144895ca178Sae112802	ATOMIC_BACKOFF_CPU(val, limit, ncpu, cas_cnt, label/**/_0)	; \
145895ca178Sae112802	cmp	val, limit						; \
146895ca178Sae112802	blu,a,pt %xcc, label/**/_1					; \
147895ca178Sae112802	  mov	val, limit						; \
148895ca178Sae112802label/**/_1:								; \
149895ca178Sae112802	mov	limit, val						; \
150895ca178Sae112802	DELAY_SPIN(label/**/_2, %g2, %g3)				; \
151895ca178Sae112802	deccc	limit							; \
152895ca178Sae112802	bgu,pn	%xcc, label/**/_20 /* branch to middle of DELAY_SPIN */	; \
153895ca178Sae112802	  nop								; \
154895ca178Sae112802	ba	retlabel						; \
155895ca178Sae112802	  sllx  val, 1, val
156895ca178Sae112802#else	/* ATOMIC_BO_ENABLE_SHIFT */
157895ca178Sae112802#define ATOMIC_BACKOFF_INIT(val, ncpu, cas_cnt)
158895ca178Sae112802
159895ca178Sae112802#define ATOMIC_BACKOFF_BRANCH(cr, backoff, loop) \
160895ca178Sae112802	bne,a,pn cr, loop
161895ca178Sae112802
162895ca178Sae112802#define ATOMIC_BACKOFF_BACKOFF(val, limit, ncpu, cas_cnt, label, retlabel)
163895ca178Sae112802#endif	/* ATOMIC_BO_ENABLE_SHIFT */
1647c478bd9Sstevel@tonic-gate
165dfb96a4fSab196087	/*
166dfb96a4fSab196087	 * NOTE: If atomic_inc_8 and atomic_inc_8_nv are ever
167dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
168dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
169dfb96a4fSab196087	 * from atomic_inc_8_nv.
170dfb96a4fSab196087	 */
1717c478bd9Sstevel@tonic-gate	ENTRY(atomic_inc_8)
1727c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_8_nv)
1737c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_uchar)
1747c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_uchar_nv)
1757c478bd9Sstevel@tonic-gate	ba	add_8
1767c478bd9Sstevel@tonic-gate	  add	%g0, 1, %o1
1777c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_uchar_nv)
1787c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_uchar)
1797c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_8_nv)
1807c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_8)
1817c478bd9Sstevel@tonic-gate
182dfb96a4fSab196087	/*
183dfb96a4fSab196087	 * NOTE: If atomic_dec_8 and atomic_dec_8_nv are ever
184dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
185dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
186dfb96a4fSab196087	 * from atomic_dec_8_nv.
187dfb96a4fSab196087	 */
1887c478bd9Sstevel@tonic-gate	ENTRY(atomic_dec_8)
1897c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_8_nv)
1907c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_uchar)
1917c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_uchar_nv)
1927c478bd9Sstevel@tonic-gate	ba	add_8
1937c478bd9Sstevel@tonic-gate	  sub	%g0, 1, %o1
1947c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_uchar_nv)
1957c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_uchar)
1967c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_8_nv)
1977c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_8)
1987c478bd9Sstevel@tonic-gate
199dfb96a4fSab196087	/*
200dfb96a4fSab196087	 * NOTE: If atomic_add_8 and atomic_add_8_nv are ever
201dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
202dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
203dfb96a4fSab196087	 * from atomic_add_8_nv.
204dfb96a4fSab196087	 */
2057c478bd9Sstevel@tonic-gate	ENTRY(atomic_add_8)
2067c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_8_nv)
2077c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_char)
2087c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_char_nv)
2097c478bd9Sstevel@tonic-gateadd_8:
2107c478bd9Sstevel@tonic-gate	and	%o0, 0x3, %o4		! %o4 = byte offset, left-to-right
2117c478bd9Sstevel@tonic-gate	xor	%o4, 0x3, %g1		! %g1 = byte offset, right-to-left
2127c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
2137c478bd9Sstevel@tonic-gate	set	0xff, %o3		! %o3 = mask
2147c478bd9Sstevel@tonic-gate	sll	%o3, %g1, %o3		! %o3 = shifted to bit offset
2157c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
2167c478bd9Sstevel@tonic-gate	and	%o1, %o3, %o1		! %o1 = single byte value
2177c478bd9Sstevel@tonic-gate	andn	%o0, 0x3, %o0		! %o0 = word address
2187c478bd9Sstevel@tonic-gate	ld	[%o0], %o2		! read old value
2197c478bd9Sstevel@tonic-gate1:
2207c478bd9Sstevel@tonic-gate	add	%o2, %o1, %o5		! add value to the old value
2217c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5		! clear other bits
2227c478bd9Sstevel@tonic-gate	andn	%o2, %o3, %o4		! clear target bits
2237c478bd9Sstevel@tonic-gate	or	%o4, %o5, %o5		! insert the new value
2247c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o5
2257c478bd9Sstevel@tonic-gate	cmp	%o2, %o5
2267c478bd9Sstevel@tonic-gate	bne,a,pn %icc, 1b
2277c478bd9Sstevel@tonic-gate	  mov	%o5, %o2		! %o2 = old value
2287c478bd9Sstevel@tonic-gate	add	%o2, %o1, %o5
2297c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5
2307c478bd9Sstevel@tonic-gate	retl
2317c478bd9Sstevel@tonic-gate	srl	%o5, %g1, %o0		! %o0 = new value
2327c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_char_nv)
2337c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_char)
2347c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_8_nv)
2357c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_8)
2367c478bd9Sstevel@tonic-gate
237dfb96a4fSab196087	/*
238dfb96a4fSab196087	 * NOTE: If atomic_inc_16 and atomic_inc_16_nv are ever
239dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
240dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
241dfb96a4fSab196087	 * from atomic_inc_16_nv.
242dfb96a4fSab196087	 */
2437c478bd9Sstevel@tonic-gate	ENTRY(atomic_inc_16)
2447c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_16_nv)
2457c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_ushort)
2467c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_ushort_nv)
2477c478bd9Sstevel@tonic-gate	ba	add_16
2487c478bd9Sstevel@tonic-gate	  add	%g0, 1, %o1
2497c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_ushort_nv)
2507c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_ushort)
2517c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_16_nv)
2527c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_16)
2537c478bd9Sstevel@tonic-gate
254dfb96a4fSab196087	/*
255dfb96a4fSab196087	 * NOTE: If atomic_dec_16 and atomic_dec_16_nv are ever
256dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
257dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
258dfb96a4fSab196087	 * from atomic_dec_16_nv.
259dfb96a4fSab196087	 */
2607c478bd9Sstevel@tonic-gate	ENTRY(atomic_dec_16)
2617c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_16_nv)
2627c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_ushort)
2637c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_ushort_nv)
2647c478bd9Sstevel@tonic-gate	ba	add_16
2657c478bd9Sstevel@tonic-gate	  sub	%g0, 1, %o1
2667c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_ushort_nv)
2677c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_ushort)
2687c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_16_nv)
2697c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_16)
2707c478bd9Sstevel@tonic-gate
271dfb96a4fSab196087	/*
272dfb96a4fSab196087	 * NOTE: If atomic_add_16 and atomic_add_16_nv are ever
273dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
274dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
275dfb96a4fSab196087	 * from atomic_add_16_nv.
276dfb96a4fSab196087	 */
2777c478bd9Sstevel@tonic-gate	ENTRY(atomic_add_16)
2787c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_16_nv)
2797c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_short)
2807c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_short_nv)
2817c478bd9Sstevel@tonic-gateadd_16:
2827c478bd9Sstevel@tonic-gate	and	%o0, 0x2, %o4		! %o4 = byte offset, left-to-right
2837c478bd9Sstevel@tonic-gate	xor	%o4, 0x2, %g1		! %g1 = byte offset, right-to-left
2847c478bd9Sstevel@tonic-gate	sll	%o4, 3, %o4		! %o4 = bit offset, left-to-right
2857c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
2867c478bd9Sstevel@tonic-gate	sethi	%hi(0xffff0000), %o3	! %o3 = mask
2877c478bd9Sstevel@tonic-gate	srl	%o3, %o4, %o3		! %o3 = shifted to bit offset
2887c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
2897c478bd9Sstevel@tonic-gate	and	%o1, %o3, %o1		! %o1 = single short value
2907c478bd9Sstevel@tonic-gate	andn	%o0, 0x2, %o0		! %o0 = word address
2917c478bd9Sstevel@tonic-gate	! if low-order bit is 1, we will properly get an alignment fault here
2927c478bd9Sstevel@tonic-gate	ld	[%o0], %o2		! read old value
2937c478bd9Sstevel@tonic-gate1:
2947c478bd9Sstevel@tonic-gate	add	%o1, %o2, %o5		! add value to the old value
2957c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5		! clear other bits
2967c478bd9Sstevel@tonic-gate	andn	%o2, %o3, %o4		! clear target bits
2977c478bd9Sstevel@tonic-gate	or	%o4, %o5, %o5		! insert the new value
2987c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o5
2997c478bd9Sstevel@tonic-gate	cmp	%o2, %o5
3007c478bd9Sstevel@tonic-gate	bne,a,pn %icc, 1b
3017c478bd9Sstevel@tonic-gate	  mov	%o5, %o2		! %o2 = old value
3027c478bd9Sstevel@tonic-gate	add	%o1, %o2, %o5
3037c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5
3047c478bd9Sstevel@tonic-gate	retl
3057c478bd9Sstevel@tonic-gate	srl	%o5, %g1, %o0		! %o0 = new value
3067c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_short_nv)
3077c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_short)
3087c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_16_nv)
3097c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_16)
3107c478bd9Sstevel@tonic-gate
311dfb96a4fSab196087	/*
312dfb96a4fSab196087	 * NOTE: If atomic_inc_32 and atomic_inc_32_nv are ever
313dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
314dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
315dfb96a4fSab196087	 * from atomic_inc_32_nv.
316dfb96a4fSab196087	 */
3177c478bd9Sstevel@tonic-gate	ENTRY(atomic_inc_32)
3187c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_32_nv)
3197c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_uint)
3207c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_uint_nv)
3217c478bd9Sstevel@tonic-gate	ba	add_32
3227c478bd9Sstevel@tonic-gate	  add	%g0, 1, %o1
3237c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_uint_nv)
3247c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_uint)
3257c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_32_nv)
3267c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_32)
3277c478bd9Sstevel@tonic-gate
328dfb96a4fSab196087	/*
329dfb96a4fSab196087	 * NOTE: If atomic_dec_32 and atomic_dec_32_nv are ever
330dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
331dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
332dfb96a4fSab196087	 * from atomic_dec_32_nv.
333dfb96a4fSab196087	 */
3347c478bd9Sstevel@tonic-gate	ENTRY(atomic_dec_32)
3357c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_32_nv)
3367c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_uint)
3377c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_uint_nv)
3387c478bd9Sstevel@tonic-gate	ba	add_32
3397c478bd9Sstevel@tonic-gate	  sub	%g0, 1, %o1
3407c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_uint_nv)
3417c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_uint)
3427c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_32_nv)
3437c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_32)
3447c478bd9Sstevel@tonic-gate
345dfb96a4fSab196087	/*
346dfb96a4fSab196087	 * NOTE: If atomic_add_32 and atomic_add_32_nv are ever
347dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
348dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
349dfb96a4fSab196087	 * from atomic_add_32_nv.
350dfb96a4fSab196087	 */
3517c478bd9Sstevel@tonic-gate	ENTRY(atomic_add_32)
3527c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_32_nv)
3537c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_int)
3547c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_int_nv)
3557c478bd9Sstevel@tonic-gateadd_32:
356895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o4, %g4, %g5)
357895ca178Sae1128020:
3587c478bd9Sstevel@tonic-gate	ld	[%o0], %o2
3597c478bd9Sstevel@tonic-gate1:
3607c478bd9Sstevel@tonic-gate	add	%o2, %o1, %o3
3617c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o3
3627c478bd9Sstevel@tonic-gate	cmp	%o2, %o3
363895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%icc, 2f, 1b)
3647c478bd9Sstevel@tonic-gate	  mov	%o3, %o2
3657c478bd9Sstevel@tonic-gate	retl
3667c478bd9Sstevel@tonic-gate	add	%o2, %o1, %o0		! return new value
367895ca178Sae1128022:
368895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o4, %o5, %g4, %g5, add32, 0b)
3697c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_int_nv)
3707c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_int)
3717c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_32_nv)
3727c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_32)
3737c478bd9Sstevel@tonic-gate
374dfb96a4fSab196087	/*
375dfb96a4fSab196087	 * NOTE: If atomic_inc_64 and atomic_inc_64_nv are ever
376dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
377dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
378dfb96a4fSab196087	 * from atomic_inc_64_nv.
379dfb96a4fSab196087	 */
3807c478bd9Sstevel@tonic-gate	ENTRY(atomic_inc_64)
3817c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_64_nv)
3827c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_ulong)
3837c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_ulong_nv)
3847c478bd9Sstevel@tonic-gate	ba	add_64
3857c478bd9Sstevel@tonic-gate	  add	%g0, 1, %o1
3867c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_ulong_nv)
3877c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_ulong)
3887c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_64_nv)
3897c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_64)
3907c478bd9Sstevel@tonic-gate
391dfb96a4fSab196087	/*
392dfb96a4fSab196087	 * NOTE: If atomic_dec_64 and atomic_dec_64_nv are ever
393dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
394dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
395dfb96a4fSab196087	 * from atomic_dec_64_nv.
396dfb96a4fSab196087	 */
3977c478bd9Sstevel@tonic-gate	ENTRY(atomic_dec_64)
3987c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_64_nv)
3997c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_ulong)
4007c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_ulong_nv)
4017c478bd9Sstevel@tonic-gate	ba	add_64
4027c478bd9Sstevel@tonic-gate	  sub	%g0, 1, %o1
4037c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_ulong_nv)
4047c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_ulong)
4057c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_64_nv)
4067c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_64)
4077c478bd9Sstevel@tonic-gate
408dfb96a4fSab196087	/*
409dfb96a4fSab196087	 * NOTE: If atomic_add_64 and atomic_add_64_nv are ever
410dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
411dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
412dfb96a4fSab196087	 * from atomic_add_64_nv.
413dfb96a4fSab196087	 */
4147c478bd9Sstevel@tonic-gate	ENTRY(atomic_add_64)
4157c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_64_nv)
4167c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_ptr)
4177c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_ptr_nv)
4187c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_long)
4197c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_long_nv)
4207c478bd9Sstevel@tonic-gateadd_64:
421895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o4, %g4, %g5)
422895ca178Sae1128020:
4237c478bd9Sstevel@tonic-gate	ldx	[%o0], %o2
4247c478bd9Sstevel@tonic-gate1:
4257c478bd9Sstevel@tonic-gate	add	%o2, %o1, %o3
4267c478bd9Sstevel@tonic-gate	casx	[%o0], %o2, %o3
4277c478bd9Sstevel@tonic-gate	cmp	%o2, %o3
428895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%xcc, 2f, 1b)
4297c478bd9Sstevel@tonic-gate	  mov	%o3, %o2
4307c478bd9Sstevel@tonic-gate	retl
4317c478bd9Sstevel@tonic-gate	add	%o2, %o1, %o0		! return new value
432895ca178Sae1128022:
433895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o4, %o5, %g4, %g5, add64, 0b)
4347c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_long_nv)
4357c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_long)
4367c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_ptr_nv)
4377c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_ptr)
4387c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_64_nv)
4397c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_64)
4407c478bd9Sstevel@tonic-gate
441dfb96a4fSab196087	/*
442dfb96a4fSab196087	 * NOTE: If atomic_or_8 and atomic_or_8_nv are ever
443dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
444dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
445dfb96a4fSab196087	 * from atomic_or_8_nv.
446dfb96a4fSab196087	 */
4477c478bd9Sstevel@tonic-gate	ENTRY(atomic_or_8)
4487c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_8_nv)
4497c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_uchar)
4507c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_uchar_nv)
4517c478bd9Sstevel@tonic-gate	and	%o0, 0x3, %o4		! %o4 = byte offset, left-to-right
4527c478bd9Sstevel@tonic-gate	xor	%o4, 0x3, %g1		! %g1 = byte offset, right-to-left
4537c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
4547c478bd9Sstevel@tonic-gate	set	0xff, %o3		! %o3 = mask
4557c478bd9Sstevel@tonic-gate	sll	%o3, %g1, %o3		! %o3 = shifted to bit offset
4567c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
4577c478bd9Sstevel@tonic-gate	and	%o1, %o3, %o1		! %o1 = single byte value
4587c478bd9Sstevel@tonic-gate	andn	%o0, 0x3, %o0		! %o0 = word address
4597c478bd9Sstevel@tonic-gate	ld	[%o0], %o2		! read old value
4607c478bd9Sstevel@tonic-gate1:
4617c478bd9Sstevel@tonic-gate	or	%o2, %o1, %o5		! or in the new value
4627c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o5
4637c478bd9Sstevel@tonic-gate	cmp	%o2, %o5
4647c478bd9Sstevel@tonic-gate	bne,a,pn %icc, 1b
4657c478bd9Sstevel@tonic-gate	  mov	%o5, %o2		! %o2 = old value
4667c478bd9Sstevel@tonic-gate	or	%o2, %o1, %o5
4677c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5
4687c478bd9Sstevel@tonic-gate	retl
4697c478bd9Sstevel@tonic-gate	srl	%o5, %g1, %o0		! %o0 = new value
4707c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_uchar_nv)
4717c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_uchar)
4727c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_8_nv)
4737c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_8)
4747c478bd9Sstevel@tonic-gate
475dfb96a4fSab196087	/*
476dfb96a4fSab196087	 * NOTE: If atomic_or_16 and atomic_or_16_nv are ever
477dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
478dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
479dfb96a4fSab196087	 * from atomic_or_16_nv.
480dfb96a4fSab196087	 */
4817c478bd9Sstevel@tonic-gate	ENTRY(atomic_or_16)
4827c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_16_nv)
4837c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_ushort)
4847c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_ushort_nv)
4857c478bd9Sstevel@tonic-gate	and	%o0, 0x2, %o4		! %o4 = byte offset, left-to-right
4867c478bd9Sstevel@tonic-gate	xor	%o4, 0x2, %g1		! %g1 = byte offset, right-to-left
4877c478bd9Sstevel@tonic-gate	sll	%o4, 3, %o4		! %o4 = bit offset, left-to-right
4887c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
4897c478bd9Sstevel@tonic-gate	sethi	%hi(0xffff0000), %o3	! %o3 = mask
4907c478bd9Sstevel@tonic-gate	srl	%o3, %o4, %o3		! %o3 = shifted to bit offset
4917c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
4927c478bd9Sstevel@tonic-gate	and	%o1, %o3, %o1		! %o1 = single short value
4937c478bd9Sstevel@tonic-gate	andn	%o0, 0x2, %o0		! %o0 = word address
4947c478bd9Sstevel@tonic-gate	! if low-order bit is 1, we will properly get an alignment fault here
4957c478bd9Sstevel@tonic-gate	ld	[%o0], %o2		! read old value
4967c478bd9Sstevel@tonic-gate1:
4977c478bd9Sstevel@tonic-gate	or	%o2, %o1, %o5		! or in the new value
4987c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o5
4997c478bd9Sstevel@tonic-gate	cmp	%o2, %o5
5007c478bd9Sstevel@tonic-gate	bne,a,pn %icc, 1b
5017c478bd9Sstevel@tonic-gate	  mov	%o5, %o2		! %o2 = old value
5027c478bd9Sstevel@tonic-gate	or	%o2, %o1, %o5		! or in the new value
5037c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5
5047c478bd9Sstevel@tonic-gate	retl
5057c478bd9Sstevel@tonic-gate	srl	%o5, %g1, %o0		! %o0 = new value
5067c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_ushort_nv)
5077c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_ushort)
5087c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_16_nv)
5097c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_16)
5107c478bd9Sstevel@tonic-gate
511dfb96a4fSab196087	/*
512dfb96a4fSab196087	 * NOTE: If atomic_or_32 and atomic_or_32_nv are ever
513dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
514dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
515dfb96a4fSab196087	 * from atomic_or_32_nv.
516dfb96a4fSab196087	 */
5177c478bd9Sstevel@tonic-gate	ENTRY(atomic_or_32)
5187c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_32_nv)
5197c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_uint)
5207c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_uint_nv)
521895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o4, %g4, %g5)
522895ca178Sae1128020:
5237c478bd9Sstevel@tonic-gate	ld	[%o0], %o2
5247c478bd9Sstevel@tonic-gate1:
5257c478bd9Sstevel@tonic-gate	or	%o2, %o1, %o3
5267c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o3
5277c478bd9Sstevel@tonic-gate	cmp	%o2, %o3
528895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%icc, 2f, 1b)
5297c478bd9Sstevel@tonic-gate	  mov	%o3, %o2
5307c478bd9Sstevel@tonic-gate	retl
5317c478bd9Sstevel@tonic-gate	or	%o2, %o1, %o0		! return new value
532895ca178Sae1128022:
533895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o4, %o5, %g4, %g5, or32, 0b)
5347c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_uint_nv)
5357c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_uint)
5367c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_32_nv)
5377c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_32)
5387c478bd9Sstevel@tonic-gate
539dfb96a4fSab196087	/*
540dfb96a4fSab196087	 * NOTE: If atomic_or_64 and atomic_or_64_nv are ever
541dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
542dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
543dfb96a4fSab196087	 * from atomic_or_64_nv.
544dfb96a4fSab196087	 */
5457c478bd9Sstevel@tonic-gate	ENTRY(atomic_or_64)
5467c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_64_nv)
5477c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_ulong)
5487c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_ulong_nv)
549895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o4, %g4, %g5)
550895ca178Sae1128020:
5517c478bd9Sstevel@tonic-gate	ldx	[%o0], %o2
5527c478bd9Sstevel@tonic-gate1:
5537c478bd9Sstevel@tonic-gate	or	%o2, %o1, %o3
5547c478bd9Sstevel@tonic-gate	casx	[%o0], %o2, %o3
5557c478bd9Sstevel@tonic-gate	cmp	%o2, %o3
556895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%xcc, 2f, 1b)
5577c478bd9Sstevel@tonic-gate	  mov	%o3, %o2
5587c478bd9Sstevel@tonic-gate	retl
5597c478bd9Sstevel@tonic-gate	or	%o2, %o1, %o0		! return new value
560895ca178Sae1128022:
561895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o4, %o5, %g4, %g5, or64, 0b)
5627c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_ulong_nv)
5637c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_ulong)
5647c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_64_nv)
5657c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_64)
5667c478bd9Sstevel@tonic-gate
567dfb96a4fSab196087	/*
568dfb96a4fSab196087	 * NOTE: If atomic_and_8 and atomic_and_8_nv are ever
569dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
570dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
571dfb96a4fSab196087	 * from atomic_and_8_nv.
572dfb96a4fSab196087	 */
5737c478bd9Sstevel@tonic-gate	ENTRY(atomic_and_8)
5747c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_8_nv)
5757c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_uchar)
5767c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_uchar_nv)
5777c478bd9Sstevel@tonic-gate	and	%o0, 0x3, %o4		! %o4 = byte offset, left-to-right
5787c478bd9Sstevel@tonic-gate	xor	%o4, 0x3, %g1		! %g1 = byte offset, right-to-left
5797c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
5807c478bd9Sstevel@tonic-gate	set	0xff, %o3		! %o3 = mask
5817c478bd9Sstevel@tonic-gate	sll	%o3, %g1, %o3		! %o3 = shifted to bit offset
5827c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
5837c478bd9Sstevel@tonic-gate	orn	%o1, %o3, %o1		! all ones in other bytes
5847c478bd9Sstevel@tonic-gate	andn	%o0, 0x3, %o0		! %o0 = word address
5857c478bd9Sstevel@tonic-gate	ld	[%o0], %o2		! read old value
5867c478bd9Sstevel@tonic-gate1:
5877c478bd9Sstevel@tonic-gate	and	%o2, %o1, %o5		! and in the new value
5887c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o5
5897c478bd9Sstevel@tonic-gate	cmp	%o2, %o5
5907c478bd9Sstevel@tonic-gate	bne,a,pn %icc, 1b
5917c478bd9Sstevel@tonic-gate	  mov	%o5, %o2		! %o2 = old value
5927c478bd9Sstevel@tonic-gate	and	%o2, %o1, %o5
5937c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5
5947c478bd9Sstevel@tonic-gate	retl
5957c478bd9Sstevel@tonic-gate	srl	%o5, %g1, %o0		! %o0 = new value
5967c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_uchar_nv)
5977c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_uchar)
5987c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_8_nv)
5997c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_8)
6007c478bd9Sstevel@tonic-gate
601dfb96a4fSab196087	/*
602dfb96a4fSab196087	 * NOTE: If atomic_and_16 and atomic_and_16_nv are ever
603dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
604dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
605dfb96a4fSab196087	 * from atomic_and_16_nv.
606dfb96a4fSab196087	 */
6077c478bd9Sstevel@tonic-gate	ENTRY(atomic_and_16)
6087c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_16_nv)
6097c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_ushort)
6107c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_ushort_nv)
6117c478bd9Sstevel@tonic-gate	and	%o0, 0x2, %o4		! %o4 = byte offset, left-to-right
6127c478bd9Sstevel@tonic-gate	xor	%o4, 0x2, %g1		! %g1 = byte offset, right-to-left
6137c478bd9Sstevel@tonic-gate	sll	%o4, 3, %o4		! %o4 = bit offset, left-to-right
6147c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
6157c478bd9Sstevel@tonic-gate	sethi	%hi(0xffff0000), %o3	! %o3 = mask
6167c478bd9Sstevel@tonic-gate	srl	%o3, %o4, %o3		! %o3 = shifted to bit offset
6177c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
6187c478bd9Sstevel@tonic-gate	orn	%o1, %o3, %o1		! all ones in the other half
6197c478bd9Sstevel@tonic-gate	andn	%o0, 0x2, %o0		! %o0 = word address
6207c478bd9Sstevel@tonic-gate	! if low-order bit is 1, we will properly get an alignment fault here
6217c478bd9Sstevel@tonic-gate	ld	[%o0], %o2		! read old value
6227c478bd9Sstevel@tonic-gate1:
6237c478bd9Sstevel@tonic-gate	and	%o2, %o1, %o5		! and in the new value
6247c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o5
6257c478bd9Sstevel@tonic-gate	cmp	%o2, %o5
6267c478bd9Sstevel@tonic-gate	bne,a,pn %icc, 1b
6277c478bd9Sstevel@tonic-gate	  mov	%o5, %o2		! %o2 = old value
6287c478bd9Sstevel@tonic-gate	and	%o2, %o1, %o5
6297c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5
6307c478bd9Sstevel@tonic-gate	retl
6317c478bd9Sstevel@tonic-gate	srl	%o5, %g1, %o0		! %o0 = new value
6327c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_ushort_nv)
6337c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_ushort)
6347c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_16_nv)
6357c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_16)
6367c478bd9Sstevel@tonic-gate
637dfb96a4fSab196087	/*
638dfb96a4fSab196087	 * NOTE: If atomic_and_32 and atomic_and_32_nv are ever
639dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
640dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
641dfb96a4fSab196087	 * from atomic_and_32_nv.
642dfb96a4fSab196087	 */
6437c478bd9Sstevel@tonic-gate	ENTRY(atomic_and_32)
6447c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_32_nv)
6457c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_uint)
6467c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_uint_nv)
647895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o4, %g4, %g5)
648895ca178Sae1128020:
6497c478bd9Sstevel@tonic-gate	ld	[%o0], %o2
6507c478bd9Sstevel@tonic-gate1:
6517c478bd9Sstevel@tonic-gate	and	%o2, %o1, %o3
6527c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o3
6537c478bd9Sstevel@tonic-gate	cmp	%o2, %o3
654895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%icc, 2f, 1b)
6557c478bd9Sstevel@tonic-gate	  mov	%o3, %o2
6567c478bd9Sstevel@tonic-gate	retl
6577c478bd9Sstevel@tonic-gate	and	%o2, %o1, %o0		! return new value
658895ca178Sae1128022:
659895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o4, %o5, %g4, %g5, and32, 0b)
6607c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_uint_nv)
6617c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_uint)
6627c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_32_nv)
6637c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_32)
6647c478bd9Sstevel@tonic-gate
665dfb96a4fSab196087	/*
666dfb96a4fSab196087	 * NOTE: If atomic_and_64 and atomic_and_64_nv are ever
667dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
668dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
669dfb96a4fSab196087	 * from atomic_and_64_nv.
670dfb96a4fSab196087	 */
6717c478bd9Sstevel@tonic-gate	ENTRY(atomic_and_64)
6727c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_64_nv)
6737c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_ulong)
6747c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_ulong_nv)
675895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o4, %g4, %g5)
676895ca178Sae1128020:
6777c478bd9Sstevel@tonic-gate	ldx	[%o0], %o2
6787c478bd9Sstevel@tonic-gate1:
6797c478bd9Sstevel@tonic-gate	and	%o2, %o1, %o3
6807c478bd9Sstevel@tonic-gate	casx	[%o0], %o2, %o3
6817c478bd9Sstevel@tonic-gate	cmp	%o2, %o3
682895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%xcc, 2f, 1b)
6837c478bd9Sstevel@tonic-gate	  mov	%o3, %o2
6847c478bd9Sstevel@tonic-gate	retl
6857c478bd9Sstevel@tonic-gate	and	%o2, %o1, %o0		! return new value
686895ca178Sae1128022:
687895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o4, %o5, %g4, %g5, and64, 0b)
6887c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_ulong_nv)
6897c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_ulong)
6907c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_64_nv)
6917c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_64)
6927c478bd9Sstevel@tonic-gate
6937c478bd9Sstevel@tonic-gate	ENTRY(atomic_cas_8)
6947c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_cas_uchar)
6957c478bd9Sstevel@tonic-gate	and	%o0, 0x3, %o4		! %o4 = byte offset, left-to-right
6967c478bd9Sstevel@tonic-gate	xor	%o4, 0x3, %g1		! %g1 = byte offset, right-to-left
6977c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
6987c478bd9Sstevel@tonic-gate	set	0xff, %o3		! %o3 = mask
6997c478bd9Sstevel@tonic-gate	sll	%o3, %g1, %o3		! %o3 = shifted to bit offset
7007c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
7017c478bd9Sstevel@tonic-gate	and	%o1, %o3, %o1		! %o1 = single byte value
7027c478bd9Sstevel@tonic-gate	sll	%o2, %g1, %o2		! %o2 = shifted to bit offset
7037c478bd9Sstevel@tonic-gate	and	%o2, %o3, %o2		! %o2 = single byte value
7047c478bd9Sstevel@tonic-gate	andn	%o0, 0x3, %o0		! %o0 = word address
7057c478bd9Sstevel@tonic-gate	ld	[%o0], %o4		! read old value
7067c478bd9Sstevel@tonic-gate1:
7077c478bd9Sstevel@tonic-gate	andn	%o4, %o3, %o4		! clear target bits
7087c478bd9Sstevel@tonic-gate	or	%o4, %o2, %o5		! insert the new value
7097c478bd9Sstevel@tonic-gate	or	%o4, %o1, %o4		! insert the comparison value
7107c478bd9Sstevel@tonic-gate	cas	[%o0], %o4, %o5
7117c478bd9Sstevel@tonic-gate	cmp	%o4, %o5		! did we succeed?
7127c478bd9Sstevel@tonic-gate	be,pt	%icc, 2f
7137c478bd9Sstevel@tonic-gate	  and	%o5, %o3, %o4		! isolate the old value
7147c478bd9Sstevel@tonic-gate	cmp	%o1, %o4		! should we have succeeded?
7157c478bd9Sstevel@tonic-gate	be,a,pt	%icc, 1b		! yes, try again
7167c478bd9Sstevel@tonic-gate	  mov	%o5, %o4		! %o4 = old value
7177c478bd9Sstevel@tonic-gate2:
7187c478bd9Sstevel@tonic-gate	retl
7197c478bd9Sstevel@tonic-gate	srl	%o4, %g1, %o0		! %o0 = old value
7207c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_uchar)
7217c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_8)
7227c478bd9Sstevel@tonic-gate
7237c478bd9Sstevel@tonic-gate	ENTRY(atomic_cas_16)
7247c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_cas_ushort)
7257c478bd9Sstevel@tonic-gate	and	%o0, 0x2, %o4		! %o4 = byte offset, left-to-right
7267c478bd9Sstevel@tonic-gate	xor	%o4, 0x2, %g1		! %g1 = byte offset, right-to-left
7277c478bd9Sstevel@tonic-gate	sll	%o4, 3, %o4		! %o4 = bit offset, left-to-right
7287c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
7297c478bd9Sstevel@tonic-gate	sethi	%hi(0xffff0000), %o3	! %o3 = mask
7307c478bd9Sstevel@tonic-gate	srl	%o3, %o4, %o3		! %o3 = shifted to bit offset
7317c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
7327c478bd9Sstevel@tonic-gate	and	%o1, %o3, %o1		! %o1 = single short value
7337c478bd9Sstevel@tonic-gate	sll	%o2, %g1, %o2		! %o2 = shifted to bit offset
7347c478bd9Sstevel@tonic-gate	and	%o2, %o3, %o2		! %o2 = single short value
7357c478bd9Sstevel@tonic-gate	andn	%o0, 0x2, %o0		! %o0 = word address
7367c478bd9Sstevel@tonic-gate	! if low-order bit is 1, we will properly get an alignment fault here
7377c478bd9Sstevel@tonic-gate	ld	[%o0], %o4		! read old value
7387c478bd9Sstevel@tonic-gate1:
7397c478bd9Sstevel@tonic-gate	andn	%o4, %o3, %o4		! clear target bits
7407c478bd9Sstevel@tonic-gate	or	%o4, %o2, %o5		! insert the new value
7417c478bd9Sstevel@tonic-gate	or	%o4, %o1, %o4		! insert the comparison value
7427c478bd9Sstevel@tonic-gate	cas	[%o0], %o4, %o5
7437c478bd9Sstevel@tonic-gate	cmp	%o4, %o5		! did we succeed?
7447c478bd9Sstevel@tonic-gate	be,pt	%icc, 2f
7457c478bd9Sstevel@tonic-gate	  and	%o5, %o3, %o4		! isolate the old value
7467c478bd9Sstevel@tonic-gate	cmp	%o1, %o4		! should we have succeeded?
7477c478bd9Sstevel@tonic-gate	be,a,pt	%icc, 1b		! yes, try again
7487c478bd9Sstevel@tonic-gate	  mov	%o5, %o4		! %o4 = old value
7497c478bd9Sstevel@tonic-gate2:
7507c478bd9Sstevel@tonic-gate	retl
7517c478bd9Sstevel@tonic-gate	srl	%o4, %g1, %o0		! %o0 = old value
7527c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_ushort)
7537c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_16)
7547c478bd9Sstevel@tonic-gate
7557c478bd9Sstevel@tonic-gate	ENTRY(atomic_cas_32)
7567c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_cas_uint)
7577c478bd9Sstevel@tonic-gate	cas	[%o0], %o1, %o2
7587c478bd9Sstevel@tonic-gate	retl
7597c478bd9Sstevel@tonic-gate	mov	%o2, %o0
7607c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_uint)
7617c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_32)
7627c478bd9Sstevel@tonic-gate
7637c478bd9Sstevel@tonic-gate	ENTRY(atomic_cas_64)
7647c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_cas_ptr)
7657c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_cas_ulong)
7667c478bd9Sstevel@tonic-gate	casx	[%o0], %o1, %o2
7677c478bd9Sstevel@tonic-gate	retl
7687c478bd9Sstevel@tonic-gate	mov	%o2, %o0
7697c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_ulong)
7707c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_ptr)
7717c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_64)
7727c478bd9Sstevel@tonic-gate
7737c478bd9Sstevel@tonic-gate	ENTRY(atomic_swap_8)
7747c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_swap_uchar)
7757c478bd9Sstevel@tonic-gate	and	%o0, 0x3, %o4		! %o4 = byte offset, left-to-right
7767c478bd9Sstevel@tonic-gate	xor	%o4, 0x3, %g1		! %g1 = byte offset, right-to-left
7777c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
7787c478bd9Sstevel@tonic-gate	set	0xff, %o3		! %o3 = mask
7797c478bd9Sstevel@tonic-gate	sll	%o3, %g1, %o3		! %o3 = shifted to bit offset
7807c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
7817c478bd9Sstevel@tonic-gate	and	%o1, %o3, %o1		! %o1 = single byte value
7827c478bd9Sstevel@tonic-gate	andn	%o0, 0x3, %o0		! %o0 = word address
7837c478bd9Sstevel@tonic-gate	ld	[%o0], %o2		! read old value
7847c478bd9Sstevel@tonic-gate1:
7857c478bd9Sstevel@tonic-gate	andn	%o2, %o3, %o5		! clear target bits
7867c478bd9Sstevel@tonic-gate	or	%o5, %o1, %o5		! insert the new value
7877c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o5
7887c478bd9Sstevel@tonic-gate	cmp	%o2, %o5
7897c478bd9Sstevel@tonic-gate	bne,a,pn %icc, 1b
7907c478bd9Sstevel@tonic-gate	  mov	%o5, %o2		! %o2 = old value
7917c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5
7927c478bd9Sstevel@tonic-gate	retl
7937c478bd9Sstevel@tonic-gate	srl	%o5, %g1, %o0		! %o0 = old value
7947c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_uchar)
7957c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_8)
7967c478bd9Sstevel@tonic-gate
7977c478bd9Sstevel@tonic-gate	ENTRY(atomic_swap_16)
7987c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_swap_ushort)
7997c478bd9Sstevel@tonic-gate	and	%o0, 0x2, %o4		! %o4 = byte offset, left-to-right
8007c478bd9Sstevel@tonic-gate	xor	%o4, 0x2, %g1		! %g1 = byte offset, right-to-left
8017c478bd9Sstevel@tonic-gate	sll	%o4, 3, %o4		! %o4 = bit offset, left-to-right
8027c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
8037c478bd9Sstevel@tonic-gate	sethi	%hi(0xffff0000), %o3	! %o3 = mask
8047c478bd9Sstevel@tonic-gate	srl	%o3, %o4, %o3		! %o3 = shifted to bit offset
8057c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
8067c478bd9Sstevel@tonic-gate	and	%o1, %o3, %o1		! %o1 = single short value
8077c478bd9Sstevel@tonic-gate	andn	%o0, 0x2, %o0		! %o0 = word address
8087c478bd9Sstevel@tonic-gate	! if low-order bit is 1, we will properly get an alignment fault here
8097c478bd9Sstevel@tonic-gate	ld	[%o0], %o2		! read old value
8107c478bd9Sstevel@tonic-gate1:
8117c478bd9Sstevel@tonic-gate	andn	%o2, %o3, %o5		! clear target bits
8127c478bd9Sstevel@tonic-gate	or	%o5, %o1, %o5		! insert the new value
8137c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o5
8147c478bd9Sstevel@tonic-gate	cmp	%o2, %o5
8157c478bd9Sstevel@tonic-gate	bne,a,pn %icc, 1b
8167c478bd9Sstevel@tonic-gate	  mov	%o5, %o2		! %o2 = old value
8177c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5
8187c478bd9Sstevel@tonic-gate	retl
8197c478bd9Sstevel@tonic-gate	srl	%o5, %g1, %o0		! %o0 = old value
8207c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_ushort)
8217c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_16)
8227c478bd9Sstevel@tonic-gate
8237c478bd9Sstevel@tonic-gate	ENTRY(atomic_swap_32)
8247c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_swap_uint)
825895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o4, %g4, %g5)
826895ca178Sae1128020:
8277c478bd9Sstevel@tonic-gate	ld	[%o0], %o2
8287c478bd9Sstevel@tonic-gate1:
8297c478bd9Sstevel@tonic-gate	mov	%o1, %o3
8307c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o3
8317c478bd9Sstevel@tonic-gate	cmp	%o2, %o3
832895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%icc, 2f, 1b)
8337c478bd9Sstevel@tonic-gate	  mov	%o3, %o2
8347c478bd9Sstevel@tonic-gate	retl
8357c478bd9Sstevel@tonic-gate	mov	%o3, %o0
836895ca178Sae1128022:
837895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o4, %o5, %g4, %g5, swap32, 0b)
8387c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_uint)
8397c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_32)
8407c478bd9Sstevel@tonic-gate
8417c478bd9Sstevel@tonic-gate	ENTRY(atomic_swap_64)
8427c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_swap_ptr)
8437c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_swap_ulong)
844895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o4, %g4, %g5)
845895ca178Sae1128020:
8467c478bd9Sstevel@tonic-gate	ldx	[%o0], %o2
8477c478bd9Sstevel@tonic-gate1:
8487c478bd9Sstevel@tonic-gate	mov	%o1, %o3
8497c478bd9Sstevel@tonic-gate	casx	[%o0], %o2, %o3
8507c478bd9Sstevel@tonic-gate	cmp	%o2, %o3
851895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%xcc, 2f, 1b)
8527c478bd9Sstevel@tonic-gate	  mov	%o3, %o2
8537c478bd9Sstevel@tonic-gate	retl
8547c478bd9Sstevel@tonic-gate	mov	%o3, %o0
855895ca178Sae1128022:
856895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o4, %o5, %g4, %g5, swap64, 0b)
8577c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_ulong)
8587c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_ptr)
8597c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_64)
8607c478bd9Sstevel@tonic-gate
8617c478bd9Sstevel@tonic-gate	ENTRY(atomic_set_long_excl)
862895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o5, %g4, %g5)
8637c478bd9Sstevel@tonic-gate	mov	1, %o3
8647c478bd9Sstevel@tonic-gate	slln	%o3, %o1, %o3
865895ca178Sae1128020:
8667c478bd9Sstevel@tonic-gate	ldn	[%o0], %o2
8677c478bd9Sstevel@tonic-gate1:
8687c478bd9Sstevel@tonic-gate	andcc	%o2, %o3, %g0		! test if the bit is set
8697c478bd9Sstevel@tonic-gate	bnz,a,pn %ncc, 2f		! if so, then fail out
8707c478bd9Sstevel@tonic-gate	  mov	-1, %o0
8717c478bd9Sstevel@tonic-gate	or	%o2, %o3, %o4		! set the bit, and try to commit it
8727c478bd9Sstevel@tonic-gate	casn	[%o0], %o2, %o4
8737c478bd9Sstevel@tonic-gate	cmp	%o2, %o4
874895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%ncc, 5f, 1b)
8757c478bd9Sstevel@tonic-gate	  mov	%o4, %o2
8767c478bd9Sstevel@tonic-gate	mov	%g0, %o0
8777c478bd9Sstevel@tonic-gate2:
8787c478bd9Sstevel@tonic-gate	retl
8797c478bd9Sstevel@tonic-gate	nop
880895ca178Sae1128025:
881895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o5, %g1, %g4, %g5, setlongexcl, 0b)
8827c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_set_long_excl)
8837c478bd9Sstevel@tonic-gate
8847c478bd9Sstevel@tonic-gate	ENTRY(atomic_clear_long_excl)
885895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o5, %g4, %g5)
8867c478bd9Sstevel@tonic-gate	mov	1, %o3
8877c478bd9Sstevel@tonic-gate	slln	%o3, %o1, %o3
888895ca178Sae1128020:
8897c478bd9Sstevel@tonic-gate	ldn	[%o0], %o2
8907c478bd9Sstevel@tonic-gate1:
8917c478bd9Sstevel@tonic-gate	andncc	%o3, %o2, %g0		! test if the bit is clear
8927c478bd9Sstevel@tonic-gate	bnz,a,pn %ncc, 2f		! if so, then fail out
8937c478bd9Sstevel@tonic-gate	  mov	-1, %o0
8947c478bd9Sstevel@tonic-gate	andn	%o2, %o3, %o4		! clear the bit, and try to commit it
8957c478bd9Sstevel@tonic-gate	casn	[%o0], %o2, %o4
8967c478bd9Sstevel@tonic-gate	cmp	%o2, %o4
897895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%ncc, 5f, 1b)
8987c478bd9Sstevel@tonic-gate	  mov	%o4, %o2
8997c478bd9Sstevel@tonic-gate	mov	%g0, %o0
9007c478bd9Sstevel@tonic-gate2:
9017c478bd9Sstevel@tonic-gate	retl
9027c478bd9Sstevel@tonic-gate	nop
903895ca178Sae1128025:
904895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o5, %g1, %g4, %g5, clrlongexcl, 0b)
9057c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_clear_long_excl)
9067c478bd9Sstevel@tonic-gate
9077c478bd9Sstevel@tonic-gate#if !defined(_KERNEL)
9087c478bd9Sstevel@tonic-gate
9097c478bd9Sstevel@tonic-gate	/*
9107c478bd9Sstevel@tonic-gate	 * Spitfires and Blackbirds have a problem with membars in the
9117c478bd9Sstevel@tonic-gate	 * delay slot (SF_ERRATA_51).  For safety's sake, we assume
9127c478bd9Sstevel@tonic-gate	 * that the whole world needs the workaround.
9137c478bd9Sstevel@tonic-gate	 */
9147c478bd9Sstevel@tonic-gate	ENTRY(membar_enter)
9157c478bd9Sstevel@tonic-gate	membar	#StoreLoad|#StoreStore
9167c478bd9Sstevel@tonic-gate	retl
9177c478bd9Sstevel@tonic-gate	nop
9187c478bd9Sstevel@tonic-gate	SET_SIZE(membar_enter)
9197c478bd9Sstevel@tonic-gate
9207c478bd9Sstevel@tonic-gate	ENTRY(membar_exit)
9217c478bd9Sstevel@tonic-gate	membar	#LoadStore|#StoreStore
9227c478bd9Sstevel@tonic-gate	retl
9237c478bd9Sstevel@tonic-gate	nop
9247c478bd9Sstevel@tonic-gate	SET_SIZE(membar_exit)
9257c478bd9Sstevel@tonic-gate
9267c478bd9Sstevel@tonic-gate	ENTRY(membar_producer)
9277c478bd9Sstevel@tonic-gate	membar	#StoreStore
9287c478bd9Sstevel@tonic-gate	retl
9297c478bd9Sstevel@tonic-gate	nop
9307c478bd9Sstevel@tonic-gate	SET_SIZE(membar_producer)
9317c478bd9Sstevel@tonic-gate
9327c478bd9Sstevel@tonic-gate	ENTRY(membar_consumer)
9337c478bd9Sstevel@tonic-gate	membar	#LoadLoad
9347c478bd9Sstevel@tonic-gate	retl
9357c478bd9Sstevel@tonic-gate	nop
9367c478bd9Sstevel@tonic-gate	SET_SIZE(membar_consumer)
9377c478bd9Sstevel@tonic-gate
9387c478bd9Sstevel@tonic-gate#endif	/* !_KERNEL */
939