xref: /titanic_52/usr/src/common/atomic/sparcv9/atomic.s (revision 895ca178e38ac3583d0c0d8317d51dc5f388df6e)
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 */
217c478bd9Sstevel@tonic-gate/*
22*895ca178Sae112802 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate	.ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate	.file	"%M%"
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h>
317c478bd9Sstevel@tonic-gate
32*895ca178Sae112802/*
33*895ca178Sae112802 * ATOMIC_BO_ENABLE_SHIFT can be selectively defined by processors
34*895ca178Sae112802 * to enable exponential backoff. No definition means backoff is
35*895ca178Sae112802 * not desired i.e. backoff should be disabled.
36*895ca178Sae112802 * By default, the shift value is used to generate a power of 2
37*895ca178Sae112802 * value for backoff limit. In the kernel, processors scale this
38*895ca178Sae112802 * shift value with the number of online cpus.
39*895ca178Sae112802 */
40*895ca178Sae112802
417c478bd9Sstevel@tonic-gate#if defined(_KERNEL)
427c478bd9Sstevel@tonic-gate	/*
437c478bd9Sstevel@tonic-gate	 * Legacy kernel interfaces; they will go away (eventually).
447c478bd9Sstevel@tonic-gate	 */
457c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(cas8,atomic_cas_8,function)
467c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(cas32,atomic_cas_32,function)
477c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(cas64,atomic_cas_64,function)
487c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(caslong,atomic_cas_ulong,function)
497c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(casptr,atomic_cas_ptr,function)
507c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(atomic_and_long,atomic_and_ulong,function)
517c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(atomic_or_long,atomic_or_ulong,function)
527c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(swapl,atomic_swap_32,function)
53*895ca178Sae112802
54*895ca178Sae112802#ifdef ATOMIC_BO_ENABLE_SHIFT
55*895ca178Sae112802
56*895ca178Sae112802#if !defined(lint)
57*895ca178Sae112802	.weak   cpu_atomic_delay
58*895ca178Sae112802	.type   cpu_atomic_delay, #function
59*895ca178Sae112802#endif  /* lint */
60*895ca178Sae112802
61*895ca178Sae112802/*
62*895ca178Sae112802 * For the kernel, invoke processor specific delay routine to perform
63*895ca178Sae112802 * low-impact spin delay. The value of ATOMIC_BO_ENABLE_SHIFT is tuned
64*895ca178Sae112802 * with respect to the specific spin delay implementation.
65*895ca178Sae112802 */
66*895ca178Sae112802#define	DELAY_SPIN(label, tmp1, tmp2)					\
67*895ca178Sae112802	/*								; \
68*895ca178Sae112802	 * Define a pragma weak reference to a cpu specific		; \
69*895ca178Sae112802	 * delay routine for atomic backoff. For CPUs that		; \
70*895ca178Sae112802	 * have no such delay routine defined, the delay becomes	; \
71*895ca178Sae112802	 * just a simple tight loop.					; \
72*895ca178Sae112802	 *								; \
73*895ca178Sae112802	 * tmp1 = holds CPU specific delay routine			; \
74*895ca178Sae112802	 * tmp2 = holds atomic routine's callee return address		; \
75*895ca178Sae112802	 */								; \
76*895ca178Sae112802	sethi	%hi(cpu_atomic_delay), tmp1				; \
77*895ca178Sae112802	or	tmp1, %lo(cpu_atomic_delay), tmp1			; \
78*895ca178Sae112802label/**/0:								; \
79*895ca178Sae112802	brz,pn	tmp1, label/**/1					; \
80*895ca178Sae112802	mov	%o7, tmp2						; \
81*895ca178Sae112802	jmpl	tmp1, %o7	/* call CPU specific delay routine */	; \
82*895ca178Sae112802	  nop			/* delay slot : do nothing */		; \
83*895ca178Sae112802	mov	tmp2, %o7	/* restore callee's return address */	; \
84*895ca178Sae112802label/**/1:
85*895ca178Sae112802
86*895ca178Sae112802/*
87*895ca178Sae112802 * For the kernel, we take into consideration of cas failures
88*895ca178Sae112802 * and also scale the backoff limit w.r.t. the number of cpus.
89*895ca178Sae112802 * For cas failures, we reset the backoff value to 1 if the cas
90*895ca178Sae112802 * failures exceed or equal to the number of online cpus. This
91*895ca178Sae112802 * will enforce some degree of fairness and prevent starvation.
92*895ca178Sae112802 * We also scale/normalize the processor provided specific
93*895ca178Sae112802 * ATOMIC_BO_ENABLE_SHIFT w.r.t. the number of online cpus to
94*895ca178Sae112802 * obtain the actual final limit to use.
95*895ca178Sae112802 */
96*895ca178Sae112802#define ATOMIC_BACKOFF_CPU(val, limit, ncpu, cas_cnt, label)		\
97*895ca178Sae112802	brnz,pt	ncpu, label/**/0					; \
98*895ca178Sae112802	  inc	cas_cnt							; \
99*895ca178Sae112802	sethi	%hi(ncpus_online), ncpu					; \
100*895ca178Sae112802	ld	[ncpu + %lo(ncpus_online)], ncpu			; \
101*895ca178Sae112802label/**/0:								; \
102*895ca178Sae112802	cmp	cas_cnt, ncpu						; \
103*895ca178Sae112802	blu,pt	%xcc, label/**/1					; \
104*895ca178Sae112802	  sllx	ncpu, ATOMIC_BO_ENABLE_SHIFT, limit			; \
105*895ca178Sae112802	mov	%g0, cas_cnt						; \
106*895ca178Sae112802	mov	1, val							; \
107*895ca178Sae112802label/**/1:
108*895ca178Sae112802#endif	/* ATOMIC_BO_ENABLE_SHIFT */
109*895ca178Sae112802
110*895ca178Sae112802#else	/* _KERNEL */
1117c478bd9Sstevel@tonic-gate	/*
1127c478bd9Sstevel@tonic-gate	 * Include the definitions for the libc weak aliases.
1137c478bd9Sstevel@tonic-gate	 */
1147c478bd9Sstevel@tonic-gate#include "../atomic_asm_weak.h"
115*895ca178Sae112802
116*895ca178Sae112802/*
117*895ca178Sae112802 * ATOMIC_BO_ENABLE_SHIFT may be enabled/defined here for generic
118*895ca178Sae112802 * libc atomics. None for now.
119*895ca178Sae112802 */
120*895ca178Sae112802#ifdef ATOMIC_BO_ENABLE_SHIFT
121*895ca178Sae112802#define	DELAY_SPIN(label, tmp1, tmp2)	\
122*895ca178Sae112802label/**/0:
123*895ca178Sae112802
124*895ca178Sae112802#define ATOMIC_BACKOFF_CPU(val, limit, ncpu, cas_cnt, label)  \
125*895ca178Sae112802	set	1 << ATOMIC_BO_ENABLE_SHIFT, limit
126*895ca178Sae112802#endif	/* ATOMIC_BO_ENABLE_SHIFT */
127*895ca178Sae112802#endif	/* _KERNEL */
128*895ca178Sae112802
129*895ca178Sae112802#ifdef ATOMIC_BO_ENABLE_SHIFT
130*895ca178Sae112802/*
131*895ca178Sae112802 * ATOMIC_BACKOFF_INIT macro for initialization.
132*895ca178Sae112802 * backoff val is initialized to 1.
133*895ca178Sae112802 * ncpu is initialized to 0
134*895ca178Sae112802 * The cas_cnt counts the cas instruction failure and is
135*895ca178Sae112802 * initialized to 0.
136*895ca178Sae112802 */
137*895ca178Sae112802#define ATOMIC_BACKOFF_INIT(val, ncpu, cas_cnt)	\
138*895ca178Sae112802	mov	1, val				; \
139*895ca178Sae112802	mov	%g0, ncpu			; \
140*895ca178Sae112802	mov	%g0, cas_cnt
141*895ca178Sae112802
142*895ca178Sae112802#define ATOMIC_BACKOFF_BRANCH(cr, backoff, loop) \
143*895ca178Sae112802	bne,a,pn cr, backoff
144*895ca178Sae112802
145*895ca178Sae112802/*
146*895ca178Sae112802 * Main ATOMIC_BACKOFF_BACKOFF macro for backoff.
147*895ca178Sae112802 */
148*895ca178Sae112802#define ATOMIC_BACKOFF_BACKOFF(val, limit, ncpu, cas_cnt, label, retlabel) \
149*895ca178Sae112802	ATOMIC_BACKOFF_CPU(val, limit, ncpu, cas_cnt, label/**/_0)	; \
150*895ca178Sae112802	cmp	val, limit						; \
151*895ca178Sae112802	blu,a,pt %xcc, label/**/_1					; \
152*895ca178Sae112802	  mov	val, limit						; \
153*895ca178Sae112802label/**/_1:								; \
154*895ca178Sae112802	mov	limit, val						; \
155*895ca178Sae112802	DELAY_SPIN(label/**/_2, %g2, %g3)				; \
156*895ca178Sae112802	deccc	limit							; \
157*895ca178Sae112802	bgu,pn	%xcc, label/**/_20 /* branch to middle of DELAY_SPIN */	; \
158*895ca178Sae112802	  nop								; \
159*895ca178Sae112802	ba	retlabel						; \
160*895ca178Sae112802	  sllx  val, 1, val
161*895ca178Sae112802#else	/* ATOMIC_BO_ENABLE_SHIFT */
162*895ca178Sae112802#define ATOMIC_BACKOFF_INIT(val, ncpu, cas_cnt)
163*895ca178Sae112802
164*895ca178Sae112802#define ATOMIC_BACKOFF_BRANCH(cr, backoff, loop) \
165*895ca178Sae112802	bne,a,pn cr, loop
166*895ca178Sae112802
167*895ca178Sae112802#define ATOMIC_BACKOFF_BACKOFF(val, limit, ncpu, cas_cnt, label, retlabel)
168*895ca178Sae112802#endif	/* ATOMIC_BO_ENABLE_SHIFT */
1697c478bd9Sstevel@tonic-gate
170dfb96a4fSab196087	/*
171dfb96a4fSab196087	 * NOTE: If atomic_inc_8 and atomic_inc_8_nv are ever
172dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
173dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
174dfb96a4fSab196087	 * from atomic_inc_8_nv.
175dfb96a4fSab196087	 */
1767c478bd9Sstevel@tonic-gate	ENTRY(atomic_inc_8)
1777c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_8_nv)
1787c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_uchar)
1797c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_uchar_nv)
1807c478bd9Sstevel@tonic-gate	ba	add_8
1817c478bd9Sstevel@tonic-gate	  add	%g0, 1, %o1
1827c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_uchar_nv)
1837c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_uchar)
1847c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_8_nv)
1857c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_8)
1867c478bd9Sstevel@tonic-gate
187dfb96a4fSab196087	/*
188dfb96a4fSab196087	 * NOTE: If atomic_dec_8 and atomic_dec_8_nv are ever
189dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
190dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
191dfb96a4fSab196087	 * from atomic_dec_8_nv.
192dfb96a4fSab196087	 */
1937c478bd9Sstevel@tonic-gate	ENTRY(atomic_dec_8)
1947c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_8_nv)
1957c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_uchar)
1967c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_uchar_nv)
1977c478bd9Sstevel@tonic-gate	ba	add_8
1987c478bd9Sstevel@tonic-gate	  sub	%g0, 1, %o1
1997c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_uchar_nv)
2007c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_uchar)
2017c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_8_nv)
2027c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_8)
2037c478bd9Sstevel@tonic-gate
204dfb96a4fSab196087	/*
205dfb96a4fSab196087	 * NOTE: If atomic_add_8 and atomic_add_8_nv are ever
206dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
207dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
208dfb96a4fSab196087	 * from atomic_add_8_nv.
209dfb96a4fSab196087	 */
2107c478bd9Sstevel@tonic-gate	ENTRY(atomic_add_8)
2117c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_8_nv)
2127c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_char)
2137c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_char_nv)
2147c478bd9Sstevel@tonic-gateadd_8:
2157c478bd9Sstevel@tonic-gate	and	%o0, 0x3, %o4		! %o4 = byte offset, left-to-right
2167c478bd9Sstevel@tonic-gate	xor	%o4, 0x3, %g1		! %g1 = byte offset, right-to-left
2177c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
2187c478bd9Sstevel@tonic-gate	set	0xff, %o3		! %o3 = mask
2197c478bd9Sstevel@tonic-gate	sll	%o3, %g1, %o3		! %o3 = shifted to bit offset
2207c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
2217c478bd9Sstevel@tonic-gate	and	%o1, %o3, %o1		! %o1 = single byte value
2227c478bd9Sstevel@tonic-gate	andn	%o0, 0x3, %o0		! %o0 = word address
2237c478bd9Sstevel@tonic-gate	ld	[%o0], %o2		! read old value
2247c478bd9Sstevel@tonic-gate1:
2257c478bd9Sstevel@tonic-gate	add	%o2, %o1, %o5		! add value to the old value
2267c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5		! clear other bits
2277c478bd9Sstevel@tonic-gate	andn	%o2, %o3, %o4		! clear target bits
2287c478bd9Sstevel@tonic-gate	or	%o4, %o5, %o5		! insert the new value
2297c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o5
2307c478bd9Sstevel@tonic-gate	cmp	%o2, %o5
2317c478bd9Sstevel@tonic-gate	bne,a,pn %icc, 1b
2327c478bd9Sstevel@tonic-gate	  mov	%o5, %o2		! %o2 = old value
2337c478bd9Sstevel@tonic-gate	add	%o2, %o1, %o5
2347c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5
2357c478bd9Sstevel@tonic-gate	retl
2367c478bd9Sstevel@tonic-gate	srl	%o5, %g1, %o0		! %o0 = new value
2377c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_char_nv)
2387c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_char)
2397c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_8_nv)
2407c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_8)
2417c478bd9Sstevel@tonic-gate
242dfb96a4fSab196087	/*
243dfb96a4fSab196087	 * NOTE: If atomic_inc_16 and atomic_inc_16_nv are ever
244dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
245dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
246dfb96a4fSab196087	 * from atomic_inc_16_nv.
247dfb96a4fSab196087	 */
2487c478bd9Sstevel@tonic-gate	ENTRY(atomic_inc_16)
2497c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_16_nv)
2507c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_ushort)
2517c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_ushort_nv)
2527c478bd9Sstevel@tonic-gate	ba	add_16
2537c478bd9Sstevel@tonic-gate	  add	%g0, 1, %o1
2547c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_ushort_nv)
2557c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_ushort)
2567c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_16_nv)
2577c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_16)
2587c478bd9Sstevel@tonic-gate
259dfb96a4fSab196087	/*
260dfb96a4fSab196087	 * NOTE: If atomic_dec_16 and atomic_dec_16_nv are ever
261dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
262dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
263dfb96a4fSab196087	 * from atomic_dec_16_nv.
264dfb96a4fSab196087	 */
2657c478bd9Sstevel@tonic-gate	ENTRY(atomic_dec_16)
2667c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_16_nv)
2677c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_ushort)
2687c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_ushort_nv)
2697c478bd9Sstevel@tonic-gate	ba	add_16
2707c478bd9Sstevel@tonic-gate	  sub	%g0, 1, %o1
2717c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_ushort_nv)
2727c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_ushort)
2737c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_16_nv)
2747c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_16)
2757c478bd9Sstevel@tonic-gate
276dfb96a4fSab196087	/*
277dfb96a4fSab196087	 * NOTE: If atomic_add_16 and atomic_add_16_nv are ever
278dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
279dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
280dfb96a4fSab196087	 * from atomic_add_16_nv.
281dfb96a4fSab196087	 */
2827c478bd9Sstevel@tonic-gate	ENTRY(atomic_add_16)
2837c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_16_nv)
2847c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_short)
2857c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_short_nv)
2867c478bd9Sstevel@tonic-gateadd_16:
2877c478bd9Sstevel@tonic-gate	and	%o0, 0x2, %o4		! %o4 = byte offset, left-to-right
2887c478bd9Sstevel@tonic-gate	xor	%o4, 0x2, %g1		! %g1 = byte offset, right-to-left
2897c478bd9Sstevel@tonic-gate	sll	%o4, 3, %o4		! %o4 = bit offset, left-to-right
2907c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
2917c478bd9Sstevel@tonic-gate	sethi	%hi(0xffff0000), %o3	! %o3 = mask
2927c478bd9Sstevel@tonic-gate	srl	%o3, %o4, %o3		! %o3 = shifted to bit offset
2937c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
2947c478bd9Sstevel@tonic-gate	and	%o1, %o3, %o1		! %o1 = single short value
2957c478bd9Sstevel@tonic-gate	andn	%o0, 0x2, %o0		! %o0 = word address
2967c478bd9Sstevel@tonic-gate	! if low-order bit is 1, we will properly get an alignment fault here
2977c478bd9Sstevel@tonic-gate	ld	[%o0], %o2		! read old value
2987c478bd9Sstevel@tonic-gate1:
2997c478bd9Sstevel@tonic-gate	add	%o1, %o2, %o5		! add value to the old value
3007c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5		! clear other bits
3017c478bd9Sstevel@tonic-gate	andn	%o2, %o3, %o4		! clear target bits
3027c478bd9Sstevel@tonic-gate	or	%o4, %o5, %o5		! insert the new value
3037c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o5
3047c478bd9Sstevel@tonic-gate	cmp	%o2, %o5
3057c478bd9Sstevel@tonic-gate	bne,a,pn %icc, 1b
3067c478bd9Sstevel@tonic-gate	  mov	%o5, %o2		! %o2 = old value
3077c478bd9Sstevel@tonic-gate	add	%o1, %o2, %o5
3087c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5
3097c478bd9Sstevel@tonic-gate	retl
3107c478bd9Sstevel@tonic-gate	srl	%o5, %g1, %o0		! %o0 = new value
3117c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_short_nv)
3127c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_short)
3137c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_16_nv)
3147c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_16)
3157c478bd9Sstevel@tonic-gate
316dfb96a4fSab196087	/*
317dfb96a4fSab196087	 * NOTE: If atomic_inc_32 and atomic_inc_32_nv are ever
318dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
319dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
320dfb96a4fSab196087	 * from atomic_inc_32_nv.
321dfb96a4fSab196087	 */
3227c478bd9Sstevel@tonic-gate	ENTRY(atomic_inc_32)
3237c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_32_nv)
3247c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_uint)
3257c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_uint_nv)
3267c478bd9Sstevel@tonic-gate	ba	add_32
3277c478bd9Sstevel@tonic-gate	  add	%g0, 1, %o1
3287c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_uint_nv)
3297c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_uint)
3307c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_32_nv)
3317c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_32)
3327c478bd9Sstevel@tonic-gate
333dfb96a4fSab196087	/*
334dfb96a4fSab196087	 * NOTE: If atomic_dec_32 and atomic_dec_32_nv are ever
335dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
336dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
337dfb96a4fSab196087	 * from atomic_dec_32_nv.
338dfb96a4fSab196087	 */
3397c478bd9Sstevel@tonic-gate	ENTRY(atomic_dec_32)
3407c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_32_nv)
3417c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_uint)
3427c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_uint_nv)
3437c478bd9Sstevel@tonic-gate	ba	add_32
3447c478bd9Sstevel@tonic-gate	  sub	%g0, 1, %o1
3457c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_uint_nv)
3467c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_uint)
3477c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_32_nv)
3487c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_32)
3497c478bd9Sstevel@tonic-gate
350dfb96a4fSab196087	/*
351dfb96a4fSab196087	 * NOTE: If atomic_add_32 and atomic_add_32_nv are ever
352dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
353dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
354dfb96a4fSab196087	 * from atomic_add_32_nv.
355dfb96a4fSab196087	 */
3567c478bd9Sstevel@tonic-gate	ENTRY(atomic_add_32)
3577c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_32_nv)
3587c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_int)
3597c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_int_nv)
3607c478bd9Sstevel@tonic-gateadd_32:
361*895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o4, %g4, %g5)
362*895ca178Sae1128020:
3637c478bd9Sstevel@tonic-gate	ld	[%o0], %o2
3647c478bd9Sstevel@tonic-gate1:
3657c478bd9Sstevel@tonic-gate	add	%o2, %o1, %o3
3667c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o3
3677c478bd9Sstevel@tonic-gate	cmp	%o2, %o3
368*895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%icc, 2f, 1b)
3697c478bd9Sstevel@tonic-gate	  mov	%o3, %o2
3707c478bd9Sstevel@tonic-gate	retl
3717c478bd9Sstevel@tonic-gate	add	%o2, %o1, %o0		! return new value
372*895ca178Sae1128022:
373*895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o4, %o5, %g4, %g5, add32, 0b)
3747c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_int_nv)
3757c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_int)
3767c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_32_nv)
3777c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_32)
3787c478bd9Sstevel@tonic-gate
379dfb96a4fSab196087	/*
380dfb96a4fSab196087	 * NOTE: If atomic_inc_64 and atomic_inc_64_nv are ever
381dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
382dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
383dfb96a4fSab196087	 * from atomic_inc_64_nv.
384dfb96a4fSab196087	 */
3857c478bd9Sstevel@tonic-gate	ENTRY(atomic_inc_64)
3867c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_64_nv)
3877c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_ulong)
3887c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_ulong_nv)
3897c478bd9Sstevel@tonic-gate	ba	add_64
3907c478bd9Sstevel@tonic-gate	  add	%g0, 1, %o1
3917c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_ulong_nv)
3927c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_ulong)
3937c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_64_nv)
3947c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_64)
3957c478bd9Sstevel@tonic-gate
396dfb96a4fSab196087	/*
397dfb96a4fSab196087	 * NOTE: If atomic_dec_64 and atomic_dec_64_nv are ever
398dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
399dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
400dfb96a4fSab196087	 * from atomic_dec_64_nv.
401dfb96a4fSab196087	 */
4027c478bd9Sstevel@tonic-gate	ENTRY(atomic_dec_64)
4037c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_64_nv)
4047c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_ulong)
4057c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_ulong_nv)
4067c478bd9Sstevel@tonic-gate	ba	add_64
4077c478bd9Sstevel@tonic-gate	  sub	%g0, 1, %o1
4087c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_ulong_nv)
4097c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_ulong)
4107c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_64_nv)
4117c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_64)
4127c478bd9Sstevel@tonic-gate
413dfb96a4fSab196087	/*
414dfb96a4fSab196087	 * NOTE: If atomic_add_64 and atomic_add_64_nv are ever
415dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
416dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
417dfb96a4fSab196087	 * from atomic_add_64_nv.
418dfb96a4fSab196087	 */
4197c478bd9Sstevel@tonic-gate	ENTRY(atomic_add_64)
4207c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_64_nv)
4217c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_ptr)
4227c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_ptr_nv)
4237c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_long)
4247c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_long_nv)
4257c478bd9Sstevel@tonic-gateadd_64:
426*895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o4, %g4, %g5)
427*895ca178Sae1128020:
4287c478bd9Sstevel@tonic-gate	ldx	[%o0], %o2
4297c478bd9Sstevel@tonic-gate1:
4307c478bd9Sstevel@tonic-gate	add	%o2, %o1, %o3
4317c478bd9Sstevel@tonic-gate	casx	[%o0], %o2, %o3
4327c478bd9Sstevel@tonic-gate	cmp	%o2, %o3
433*895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%xcc, 2f, 1b)
4347c478bd9Sstevel@tonic-gate	  mov	%o3, %o2
4357c478bd9Sstevel@tonic-gate	retl
4367c478bd9Sstevel@tonic-gate	add	%o2, %o1, %o0		! return new value
437*895ca178Sae1128022:
438*895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o4, %o5, %g4, %g5, add64, 0b)
4397c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_long_nv)
4407c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_long)
4417c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_ptr_nv)
4427c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_ptr)
4437c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_64_nv)
4447c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_64)
4457c478bd9Sstevel@tonic-gate
446dfb96a4fSab196087	/*
447dfb96a4fSab196087	 * NOTE: If atomic_or_8 and atomic_or_8_nv are ever
448dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
449dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
450dfb96a4fSab196087	 * from atomic_or_8_nv.
451dfb96a4fSab196087	 */
4527c478bd9Sstevel@tonic-gate	ENTRY(atomic_or_8)
4537c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_8_nv)
4547c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_uchar)
4557c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_uchar_nv)
4567c478bd9Sstevel@tonic-gate	and	%o0, 0x3, %o4		! %o4 = byte offset, left-to-right
4577c478bd9Sstevel@tonic-gate	xor	%o4, 0x3, %g1		! %g1 = byte offset, right-to-left
4587c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
4597c478bd9Sstevel@tonic-gate	set	0xff, %o3		! %o3 = mask
4607c478bd9Sstevel@tonic-gate	sll	%o3, %g1, %o3		! %o3 = shifted to bit offset
4617c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
4627c478bd9Sstevel@tonic-gate	and	%o1, %o3, %o1		! %o1 = single byte value
4637c478bd9Sstevel@tonic-gate	andn	%o0, 0x3, %o0		! %o0 = word address
4647c478bd9Sstevel@tonic-gate	ld	[%o0], %o2		! read old value
4657c478bd9Sstevel@tonic-gate1:
4667c478bd9Sstevel@tonic-gate	or	%o2, %o1, %o5		! or in the new value
4677c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o5
4687c478bd9Sstevel@tonic-gate	cmp	%o2, %o5
4697c478bd9Sstevel@tonic-gate	bne,a,pn %icc, 1b
4707c478bd9Sstevel@tonic-gate	  mov	%o5, %o2		! %o2 = old value
4717c478bd9Sstevel@tonic-gate	or	%o2, %o1, %o5
4727c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5
4737c478bd9Sstevel@tonic-gate	retl
4747c478bd9Sstevel@tonic-gate	srl	%o5, %g1, %o0		! %o0 = new value
4757c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_uchar_nv)
4767c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_uchar)
4777c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_8_nv)
4787c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_8)
4797c478bd9Sstevel@tonic-gate
480dfb96a4fSab196087	/*
481dfb96a4fSab196087	 * NOTE: If atomic_or_16 and atomic_or_16_nv are ever
482dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
483dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
484dfb96a4fSab196087	 * from atomic_or_16_nv.
485dfb96a4fSab196087	 */
4867c478bd9Sstevel@tonic-gate	ENTRY(atomic_or_16)
4877c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_16_nv)
4887c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_ushort)
4897c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_ushort_nv)
4907c478bd9Sstevel@tonic-gate	and	%o0, 0x2, %o4		! %o4 = byte offset, left-to-right
4917c478bd9Sstevel@tonic-gate	xor	%o4, 0x2, %g1		! %g1 = byte offset, right-to-left
4927c478bd9Sstevel@tonic-gate	sll	%o4, 3, %o4		! %o4 = bit offset, left-to-right
4937c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
4947c478bd9Sstevel@tonic-gate	sethi	%hi(0xffff0000), %o3	! %o3 = mask
4957c478bd9Sstevel@tonic-gate	srl	%o3, %o4, %o3		! %o3 = shifted to bit offset
4967c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
4977c478bd9Sstevel@tonic-gate	and	%o1, %o3, %o1		! %o1 = single short value
4987c478bd9Sstevel@tonic-gate	andn	%o0, 0x2, %o0		! %o0 = word address
4997c478bd9Sstevel@tonic-gate	! if low-order bit is 1, we will properly get an alignment fault here
5007c478bd9Sstevel@tonic-gate	ld	[%o0], %o2		! read old value
5017c478bd9Sstevel@tonic-gate1:
5027c478bd9Sstevel@tonic-gate	or	%o2, %o1, %o5		! or in the new value
5037c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o5
5047c478bd9Sstevel@tonic-gate	cmp	%o2, %o5
5057c478bd9Sstevel@tonic-gate	bne,a,pn %icc, 1b
5067c478bd9Sstevel@tonic-gate	  mov	%o5, %o2		! %o2 = old value
5077c478bd9Sstevel@tonic-gate	or	%o2, %o1, %o5		! or in the new value
5087c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5
5097c478bd9Sstevel@tonic-gate	retl
5107c478bd9Sstevel@tonic-gate	srl	%o5, %g1, %o0		! %o0 = new value
5117c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_ushort_nv)
5127c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_ushort)
5137c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_16_nv)
5147c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_16)
5157c478bd9Sstevel@tonic-gate
516dfb96a4fSab196087	/*
517dfb96a4fSab196087	 * NOTE: If atomic_or_32 and atomic_or_32_nv are ever
518dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
519dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
520dfb96a4fSab196087	 * from atomic_or_32_nv.
521dfb96a4fSab196087	 */
5227c478bd9Sstevel@tonic-gate	ENTRY(atomic_or_32)
5237c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_32_nv)
5247c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_uint)
5257c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_uint_nv)
526*895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o4, %g4, %g5)
527*895ca178Sae1128020:
5287c478bd9Sstevel@tonic-gate	ld	[%o0], %o2
5297c478bd9Sstevel@tonic-gate1:
5307c478bd9Sstevel@tonic-gate	or	%o2, %o1, %o3
5317c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o3
5327c478bd9Sstevel@tonic-gate	cmp	%o2, %o3
533*895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%icc, 2f, 1b)
5347c478bd9Sstevel@tonic-gate	  mov	%o3, %o2
5357c478bd9Sstevel@tonic-gate	retl
5367c478bd9Sstevel@tonic-gate	or	%o2, %o1, %o0		! return new value
537*895ca178Sae1128022:
538*895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o4, %o5, %g4, %g5, or32, 0b)
5397c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_uint_nv)
5407c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_uint)
5417c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_32_nv)
5427c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_32)
5437c478bd9Sstevel@tonic-gate
544dfb96a4fSab196087	/*
545dfb96a4fSab196087	 * NOTE: If atomic_or_64 and atomic_or_64_nv are ever
546dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
547dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
548dfb96a4fSab196087	 * from atomic_or_64_nv.
549dfb96a4fSab196087	 */
5507c478bd9Sstevel@tonic-gate	ENTRY(atomic_or_64)
5517c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_64_nv)
5527c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_ulong)
5537c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_ulong_nv)
554*895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o4, %g4, %g5)
555*895ca178Sae1128020:
5567c478bd9Sstevel@tonic-gate	ldx	[%o0], %o2
5577c478bd9Sstevel@tonic-gate1:
5587c478bd9Sstevel@tonic-gate	or	%o2, %o1, %o3
5597c478bd9Sstevel@tonic-gate	casx	[%o0], %o2, %o3
5607c478bd9Sstevel@tonic-gate	cmp	%o2, %o3
561*895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%xcc, 2f, 1b)
5627c478bd9Sstevel@tonic-gate	  mov	%o3, %o2
5637c478bd9Sstevel@tonic-gate	retl
5647c478bd9Sstevel@tonic-gate	or	%o2, %o1, %o0		! return new value
565*895ca178Sae1128022:
566*895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o4, %o5, %g4, %g5, or64, 0b)
5677c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_ulong_nv)
5687c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_ulong)
5697c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_64_nv)
5707c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_64)
5717c478bd9Sstevel@tonic-gate
572dfb96a4fSab196087	/*
573dfb96a4fSab196087	 * NOTE: If atomic_and_8 and atomic_and_8_nv are ever
574dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
575dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
576dfb96a4fSab196087	 * from atomic_and_8_nv.
577dfb96a4fSab196087	 */
5787c478bd9Sstevel@tonic-gate	ENTRY(atomic_and_8)
5797c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_8_nv)
5807c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_uchar)
5817c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_uchar_nv)
5827c478bd9Sstevel@tonic-gate	and	%o0, 0x3, %o4		! %o4 = byte offset, left-to-right
5837c478bd9Sstevel@tonic-gate	xor	%o4, 0x3, %g1		! %g1 = byte offset, right-to-left
5847c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
5857c478bd9Sstevel@tonic-gate	set	0xff, %o3		! %o3 = mask
5867c478bd9Sstevel@tonic-gate	sll	%o3, %g1, %o3		! %o3 = shifted to bit offset
5877c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
5887c478bd9Sstevel@tonic-gate	orn	%o1, %o3, %o1		! all ones in other bytes
5897c478bd9Sstevel@tonic-gate	andn	%o0, 0x3, %o0		! %o0 = word address
5907c478bd9Sstevel@tonic-gate	ld	[%o0], %o2		! read old value
5917c478bd9Sstevel@tonic-gate1:
5927c478bd9Sstevel@tonic-gate	and	%o2, %o1, %o5		! and in the new value
5937c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o5
5947c478bd9Sstevel@tonic-gate	cmp	%o2, %o5
5957c478bd9Sstevel@tonic-gate	bne,a,pn %icc, 1b
5967c478bd9Sstevel@tonic-gate	  mov	%o5, %o2		! %o2 = old value
5977c478bd9Sstevel@tonic-gate	and	%o2, %o1, %o5
5987c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5
5997c478bd9Sstevel@tonic-gate	retl
6007c478bd9Sstevel@tonic-gate	srl	%o5, %g1, %o0		! %o0 = new value
6017c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_uchar_nv)
6027c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_uchar)
6037c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_8_nv)
6047c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_8)
6057c478bd9Sstevel@tonic-gate
606dfb96a4fSab196087	/*
607dfb96a4fSab196087	 * NOTE: If atomic_and_16 and atomic_and_16_nv are ever
608dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
609dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
610dfb96a4fSab196087	 * from atomic_and_16_nv.
611dfb96a4fSab196087	 */
6127c478bd9Sstevel@tonic-gate	ENTRY(atomic_and_16)
6137c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_16_nv)
6147c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_ushort)
6157c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_ushort_nv)
6167c478bd9Sstevel@tonic-gate	and	%o0, 0x2, %o4		! %o4 = byte offset, left-to-right
6177c478bd9Sstevel@tonic-gate	xor	%o4, 0x2, %g1		! %g1 = byte offset, right-to-left
6187c478bd9Sstevel@tonic-gate	sll	%o4, 3, %o4		! %o4 = bit offset, left-to-right
6197c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
6207c478bd9Sstevel@tonic-gate	sethi	%hi(0xffff0000), %o3	! %o3 = mask
6217c478bd9Sstevel@tonic-gate	srl	%o3, %o4, %o3		! %o3 = shifted to bit offset
6227c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
6237c478bd9Sstevel@tonic-gate	orn	%o1, %o3, %o1		! all ones in the other half
6247c478bd9Sstevel@tonic-gate	andn	%o0, 0x2, %o0		! %o0 = word address
6257c478bd9Sstevel@tonic-gate	! if low-order bit is 1, we will properly get an alignment fault here
6267c478bd9Sstevel@tonic-gate	ld	[%o0], %o2		! read old value
6277c478bd9Sstevel@tonic-gate1:
6287c478bd9Sstevel@tonic-gate	and	%o2, %o1, %o5		! and in the new value
6297c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o5
6307c478bd9Sstevel@tonic-gate	cmp	%o2, %o5
6317c478bd9Sstevel@tonic-gate	bne,a,pn %icc, 1b
6327c478bd9Sstevel@tonic-gate	  mov	%o5, %o2		! %o2 = old value
6337c478bd9Sstevel@tonic-gate	and	%o2, %o1, %o5
6347c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5
6357c478bd9Sstevel@tonic-gate	retl
6367c478bd9Sstevel@tonic-gate	srl	%o5, %g1, %o0		! %o0 = new value
6377c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_ushort_nv)
6387c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_ushort)
6397c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_16_nv)
6407c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_16)
6417c478bd9Sstevel@tonic-gate
642dfb96a4fSab196087	/*
643dfb96a4fSab196087	 * NOTE: If atomic_and_32 and atomic_and_32_nv are ever
644dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
645dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
646dfb96a4fSab196087	 * from atomic_and_32_nv.
647dfb96a4fSab196087	 */
6487c478bd9Sstevel@tonic-gate	ENTRY(atomic_and_32)
6497c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_32_nv)
6507c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_uint)
6517c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_uint_nv)
652*895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o4, %g4, %g5)
653*895ca178Sae1128020:
6547c478bd9Sstevel@tonic-gate	ld	[%o0], %o2
6557c478bd9Sstevel@tonic-gate1:
6567c478bd9Sstevel@tonic-gate	and	%o2, %o1, %o3
6577c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o3
6587c478bd9Sstevel@tonic-gate	cmp	%o2, %o3
659*895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%icc, 2f, 1b)
6607c478bd9Sstevel@tonic-gate	  mov	%o3, %o2
6617c478bd9Sstevel@tonic-gate	retl
6627c478bd9Sstevel@tonic-gate	and	%o2, %o1, %o0		! return new value
663*895ca178Sae1128022:
664*895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o4, %o5, %g4, %g5, and32, 0b)
6657c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_uint_nv)
6667c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_uint)
6677c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_32_nv)
6687c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_32)
6697c478bd9Sstevel@tonic-gate
670dfb96a4fSab196087	/*
671dfb96a4fSab196087	 * NOTE: If atomic_and_64 and atomic_and_64_nv are ever
672dfb96a4fSab196087	 * separated, you need to also edit the libc sparcv9 platform
673dfb96a4fSab196087	 * specific mapfile and remove the NODYNSORT attribute
674dfb96a4fSab196087	 * from atomic_and_64_nv.
675dfb96a4fSab196087	 */
6767c478bd9Sstevel@tonic-gate	ENTRY(atomic_and_64)
6777c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_64_nv)
6787c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_ulong)
6797c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_ulong_nv)
680*895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o4, %g4, %g5)
681*895ca178Sae1128020:
6827c478bd9Sstevel@tonic-gate	ldx	[%o0], %o2
6837c478bd9Sstevel@tonic-gate1:
6847c478bd9Sstevel@tonic-gate	and	%o2, %o1, %o3
6857c478bd9Sstevel@tonic-gate	casx	[%o0], %o2, %o3
6867c478bd9Sstevel@tonic-gate	cmp	%o2, %o3
687*895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%xcc, 2f, 1b)
6887c478bd9Sstevel@tonic-gate	  mov	%o3, %o2
6897c478bd9Sstevel@tonic-gate	retl
6907c478bd9Sstevel@tonic-gate	and	%o2, %o1, %o0		! return new value
691*895ca178Sae1128022:
692*895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o4, %o5, %g4, %g5, and64, 0b)
6937c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_ulong_nv)
6947c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_ulong)
6957c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_64_nv)
6967c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_64)
6977c478bd9Sstevel@tonic-gate
6987c478bd9Sstevel@tonic-gate	ENTRY(atomic_cas_8)
6997c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_cas_uchar)
7007c478bd9Sstevel@tonic-gate	and	%o0, 0x3, %o4		! %o4 = byte offset, left-to-right
7017c478bd9Sstevel@tonic-gate	xor	%o4, 0x3, %g1		! %g1 = byte offset, right-to-left
7027c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
7037c478bd9Sstevel@tonic-gate	set	0xff, %o3		! %o3 = mask
7047c478bd9Sstevel@tonic-gate	sll	%o3, %g1, %o3		! %o3 = shifted to bit offset
7057c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
7067c478bd9Sstevel@tonic-gate	and	%o1, %o3, %o1		! %o1 = single byte value
7077c478bd9Sstevel@tonic-gate	sll	%o2, %g1, %o2		! %o2 = shifted to bit offset
7087c478bd9Sstevel@tonic-gate	and	%o2, %o3, %o2		! %o2 = single byte value
7097c478bd9Sstevel@tonic-gate	andn	%o0, 0x3, %o0		! %o0 = word address
7107c478bd9Sstevel@tonic-gate	ld	[%o0], %o4		! read old value
7117c478bd9Sstevel@tonic-gate1:
7127c478bd9Sstevel@tonic-gate	andn	%o4, %o3, %o4		! clear target bits
7137c478bd9Sstevel@tonic-gate	or	%o4, %o2, %o5		! insert the new value
7147c478bd9Sstevel@tonic-gate	or	%o4, %o1, %o4		! insert the comparison value
7157c478bd9Sstevel@tonic-gate	cas	[%o0], %o4, %o5
7167c478bd9Sstevel@tonic-gate	cmp	%o4, %o5		! did we succeed?
7177c478bd9Sstevel@tonic-gate	be,pt	%icc, 2f
7187c478bd9Sstevel@tonic-gate	  and	%o5, %o3, %o4		! isolate the old value
7197c478bd9Sstevel@tonic-gate	cmp	%o1, %o4		! should we have succeeded?
7207c478bd9Sstevel@tonic-gate	be,a,pt	%icc, 1b		! yes, try again
7217c478bd9Sstevel@tonic-gate	  mov	%o5, %o4		! %o4 = old value
7227c478bd9Sstevel@tonic-gate2:
7237c478bd9Sstevel@tonic-gate	retl
7247c478bd9Sstevel@tonic-gate	srl	%o4, %g1, %o0		! %o0 = old value
7257c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_uchar)
7267c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_8)
7277c478bd9Sstevel@tonic-gate
7287c478bd9Sstevel@tonic-gate	ENTRY(atomic_cas_16)
7297c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_cas_ushort)
7307c478bd9Sstevel@tonic-gate	and	%o0, 0x2, %o4		! %o4 = byte offset, left-to-right
7317c478bd9Sstevel@tonic-gate	xor	%o4, 0x2, %g1		! %g1 = byte offset, right-to-left
7327c478bd9Sstevel@tonic-gate	sll	%o4, 3, %o4		! %o4 = bit offset, left-to-right
7337c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
7347c478bd9Sstevel@tonic-gate	sethi	%hi(0xffff0000), %o3	! %o3 = mask
7357c478bd9Sstevel@tonic-gate	srl	%o3, %o4, %o3		! %o3 = shifted to bit offset
7367c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
7377c478bd9Sstevel@tonic-gate	and	%o1, %o3, %o1		! %o1 = single short value
7387c478bd9Sstevel@tonic-gate	sll	%o2, %g1, %o2		! %o2 = shifted to bit offset
7397c478bd9Sstevel@tonic-gate	and	%o2, %o3, %o2		! %o2 = single short value
7407c478bd9Sstevel@tonic-gate	andn	%o0, 0x2, %o0		! %o0 = word address
7417c478bd9Sstevel@tonic-gate	! if low-order bit is 1, we will properly get an alignment fault here
7427c478bd9Sstevel@tonic-gate	ld	[%o0], %o4		! read old value
7437c478bd9Sstevel@tonic-gate1:
7447c478bd9Sstevel@tonic-gate	andn	%o4, %o3, %o4		! clear target bits
7457c478bd9Sstevel@tonic-gate	or	%o4, %o2, %o5		! insert the new value
7467c478bd9Sstevel@tonic-gate	or	%o4, %o1, %o4		! insert the comparison value
7477c478bd9Sstevel@tonic-gate	cas	[%o0], %o4, %o5
7487c478bd9Sstevel@tonic-gate	cmp	%o4, %o5		! did we succeed?
7497c478bd9Sstevel@tonic-gate	be,pt	%icc, 2f
7507c478bd9Sstevel@tonic-gate	  and	%o5, %o3, %o4		! isolate the old value
7517c478bd9Sstevel@tonic-gate	cmp	%o1, %o4		! should we have succeeded?
7527c478bd9Sstevel@tonic-gate	be,a,pt	%icc, 1b		! yes, try again
7537c478bd9Sstevel@tonic-gate	  mov	%o5, %o4		! %o4 = old value
7547c478bd9Sstevel@tonic-gate2:
7557c478bd9Sstevel@tonic-gate	retl
7567c478bd9Sstevel@tonic-gate	srl	%o4, %g1, %o0		! %o0 = old value
7577c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_ushort)
7587c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_16)
7597c478bd9Sstevel@tonic-gate
7607c478bd9Sstevel@tonic-gate	ENTRY(atomic_cas_32)
7617c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_cas_uint)
7627c478bd9Sstevel@tonic-gate	cas	[%o0], %o1, %o2
7637c478bd9Sstevel@tonic-gate	retl
7647c478bd9Sstevel@tonic-gate	mov	%o2, %o0
7657c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_uint)
7667c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_32)
7677c478bd9Sstevel@tonic-gate
7687c478bd9Sstevel@tonic-gate	ENTRY(atomic_cas_64)
7697c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_cas_ptr)
7707c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_cas_ulong)
7717c478bd9Sstevel@tonic-gate	casx	[%o0], %o1, %o2
7727c478bd9Sstevel@tonic-gate	retl
7737c478bd9Sstevel@tonic-gate	mov	%o2, %o0
7747c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_ulong)
7757c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_ptr)
7767c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_64)
7777c478bd9Sstevel@tonic-gate
7787c478bd9Sstevel@tonic-gate	ENTRY(atomic_swap_8)
7797c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_swap_uchar)
7807c478bd9Sstevel@tonic-gate	and	%o0, 0x3, %o4		! %o4 = byte offset, left-to-right
7817c478bd9Sstevel@tonic-gate	xor	%o4, 0x3, %g1		! %g1 = byte offset, right-to-left
7827c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
7837c478bd9Sstevel@tonic-gate	set	0xff, %o3		! %o3 = mask
7847c478bd9Sstevel@tonic-gate	sll	%o3, %g1, %o3		! %o3 = shifted to bit offset
7857c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
7867c478bd9Sstevel@tonic-gate	and	%o1, %o3, %o1		! %o1 = single byte value
7877c478bd9Sstevel@tonic-gate	andn	%o0, 0x3, %o0		! %o0 = word address
7887c478bd9Sstevel@tonic-gate	ld	[%o0], %o2		! read old value
7897c478bd9Sstevel@tonic-gate1:
7907c478bd9Sstevel@tonic-gate	andn	%o2, %o3, %o5		! clear target bits
7917c478bd9Sstevel@tonic-gate	or	%o5, %o1, %o5		! insert the new value
7927c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o5
7937c478bd9Sstevel@tonic-gate	cmp	%o2, %o5
7947c478bd9Sstevel@tonic-gate	bne,a,pn %icc, 1b
7957c478bd9Sstevel@tonic-gate	  mov	%o5, %o2		! %o2 = old value
7967c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5
7977c478bd9Sstevel@tonic-gate	retl
7987c478bd9Sstevel@tonic-gate	srl	%o5, %g1, %o0		! %o0 = old value
7997c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_uchar)
8007c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_8)
8017c478bd9Sstevel@tonic-gate
8027c478bd9Sstevel@tonic-gate	ENTRY(atomic_swap_16)
8037c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_swap_ushort)
8047c478bd9Sstevel@tonic-gate	and	%o0, 0x2, %o4		! %o4 = byte offset, left-to-right
8057c478bd9Sstevel@tonic-gate	xor	%o4, 0x2, %g1		! %g1 = byte offset, right-to-left
8067c478bd9Sstevel@tonic-gate	sll	%o4, 3, %o4		! %o4 = bit offset, left-to-right
8077c478bd9Sstevel@tonic-gate	sll	%g1, 3, %g1		! %g1 = bit offset, right-to-left
8087c478bd9Sstevel@tonic-gate	sethi	%hi(0xffff0000), %o3	! %o3 = mask
8097c478bd9Sstevel@tonic-gate	srl	%o3, %o4, %o3		! %o3 = shifted to bit offset
8107c478bd9Sstevel@tonic-gate	sll	%o1, %g1, %o1		! %o1 = shifted to bit offset
8117c478bd9Sstevel@tonic-gate	and	%o1, %o3, %o1		! %o1 = single short value
8127c478bd9Sstevel@tonic-gate	andn	%o0, 0x2, %o0		! %o0 = word address
8137c478bd9Sstevel@tonic-gate	! if low-order bit is 1, we will properly get an alignment fault here
8147c478bd9Sstevel@tonic-gate	ld	[%o0], %o2		! read old value
8157c478bd9Sstevel@tonic-gate1:
8167c478bd9Sstevel@tonic-gate	andn	%o2, %o3, %o5		! clear target bits
8177c478bd9Sstevel@tonic-gate	or	%o5, %o1, %o5		! insert the new value
8187c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o5
8197c478bd9Sstevel@tonic-gate	cmp	%o2, %o5
8207c478bd9Sstevel@tonic-gate	bne,a,pn %icc, 1b
8217c478bd9Sstevel@tonic-gate	  mov	%o5, %o2		! %o2 = old value
8227c478bd9Sstevel@tonic-gate	and	%o5, %o3, %o5
8237c478bd9Sstevel@tonic-gate	retl
8247c478bd9Sstevel@tonic-gate	srl	%o5, %g1, %o0		! %o0 = old value
8257c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_ushort)
8267c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_16)
8277c478bd9Sstevel@tonic-gate
8287c478bd9Sstevel@tonic-gate	ENTRY(atomic_swap_32)
8297c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_swap_uint)
830*895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o4, %g4, %g5)
831*895ca178Sae1128020:
8327c478bd9Sstevel@tonic-gate	ld	[%o0], %o2
8337c478bd9Sstevel@tonic-gate1:
8347c478bd9Sstevel@tonic-gate	mov	%o1, %o3
8357c478bd9Sstevel@tonic-gate	cas	[%o0], %o2, %o3
8367c478bd9Sstevel@tonic-gate	cmp	%o2, %o3
837*895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%icc, 2f, 1b)
8387c478bd9Sstevel@tonic-gate	  mov	%o3, %o2
8397c478bd9Sstevel@tonic-gate	retl
8407c478bd9Sstevel@tonic-gate	mov	%o3, %o0
841*895ca178Sae1128022:
842*895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o4, %o5, %g4, %g5, swap32, 0b)
8437c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_uint)
8447c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_32)
8457c478bd9Sstevel@tonic-gate
8467c478bd9Sstevel@tonic-gate	ENTRY(atomic_swap_64)
8477c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_swap_ptr)
8487c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_swap_ulong)
849*895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o4, %g4, %g5)
850*895ca178Sae1128020:
8517c478bd9Sstevel@tonic-gate	ldx	[%o0], %o2
8527c478bd9Sstevel@tonic-gate1:
8537c478bd9Sstevel@tonic-gate	mov	%o1, %o3
8547c478bd9Sstevel@tonic-gate	casx	[%o0], %o2, %o3
8557c478bd9Sstevel@tonic-gate	cmp	%o2, %o3
856*895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%xcc, 2f, 1b)
8577c478bd9Sstevel@tonic-gate	  mov	%o3, %o2
8587c478bd9Sstevel@tonic-gate	retl
8597c478bd9Sstevel@tonic-gate	mov	%o3, %o0
860*895ca178Sae1128022:
861*895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o4, %o5, %g4, %g5, swap64, 0b)
8627c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_ulong)
8637c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_ptr)
8647c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_64)
8657c478bd9Sstevel@tonic-gate
8667c478bd9Sstevel@tonic-gate	ENTRY(atomic_set_long_excl)
867*895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o5, %g4, %g5)
8687c478bd9Sstevel@tonic-gate	mov	1, %o3
8697c478bd9Sstevel@tonic-gate	slln	%o3, %o1, %o3
870*895ca178Sae1128020:
8717c478bd9Sstevel@tonic-gate	ldn	[%o0], %o2
8727c478bd9Sstevel@tonic-gate1:
8737c478bd9Sstevel@tonic-gate	andcc	%o2, %o3, %g0		! test if the bit is set
8747c478bd9Sstevel@tonic-gate	bnz,a,pn %ncc, 2f		! if so, then fail out
8757c478bd9Sstevel@tonic-gate	  mov	-1, %o0
8767c478bd9Sstevel@tonic-gate	or	%o2, %o3, %o4		! set the bit, and try to commit it
8777c478bd9Sstevel@tonic-gate	casn	[%o0], %o2, %o4
8787c478bd9Sstevel@tonic-gate	cmp	%o2, %o4
879*895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%ncc, 5f, 1b)
8807c478bd9Sstevel@tonic-gate	  mov	%o4, %o2
8817c478bd9Sstevel@tonic-gate	mov	%g0, %o0
8827c478bd9Sstevel@tonic-gate2:
8837c478bd9Sstevel@tonic-gate	retl
8847c478bd9Sstevel@tonic-gate	nop
885*895ca178Sae1128025:
886*895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o5, %g1, %g4, %g5, setlongexcl, 0b)
8877c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_set_long_excl)
8887c478bd9Sstevel@tonic-gate
8897c478bd9Sstevel@tonic-gate	ENTRY(atomic_clear_long_excl)
890*895ca178Sae112802	ATOMIC_BACKOFF_INIT(%o5, %g4, %g5)
8917c478bd9Sstevel@tonic-gate	mov	1, %o3
8927c478bd9Sstevel@tonic-gate	slln	%o3, %o1, %o3
893*895ca178Sae1128020:
8947c478bd9Sstevel@tonic-gate	ldn	[%o0], %o2
8957c478bd9Sstevel@tonic-gate1:
8967c478bd9Sstevel@tonic-gate	andncc	%o3, %o2, %g0		! test if the bit is clear
8977c478bd9Sstevel@tonic-gate	bnz,a,pn %ncc, 2f		! if so, then fail out
8987c478bd9Sstevel@tonic-gate	  mov	-1, %o0
8997c478bd9Sstevel@tonic-gate	andn	%o2, %o3, %o4		! clear the bit, and try to commit it
9007c478bd9Sstevel@tonic-gate	casn	[%o0], %o2, %o4
9017c478bd9Sstevel@tonic-gate	cmp	%o2, %o4
902*895ca178Sae112802	ATOMIC_BACKOFF_BRANCH(%ncc, 5f, 1b)
9037c478bd9Sstevel@tonic-gate	  mov	%o4, %o2
9047c478bd9Sstevel@tonic-gate	mov	%g0, %o0
9057c478bd9Sstevel@tonic-gate2:
9067c478bd9Sstevel@tonic-gate	retl
9077c478bd9Sstevel@tonic-gate	nop
908*895ca178Sae1128025:
909*895ca178Sae112802	ATOMIC_BACKOFF_BACKOFF(%o5, %g1, %g4, %g5, clrlongexcl, 0b)
9107c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_clear_long_excl)
9117c478bd9Sstevel@tonic-gate
9127c478bd9Sstevel@tonic-gate#if !defined(_KERNEL)
9137c478bd9Sstevel@tonic-gate
9147c478bd9Sstevel@tonic-gate	/*
9157c478bd9Sstevel@tonic-gate	 * Spitfires and Blackbirds have a problem with membars in the
9167c478bd9Sstevel@tonic-gate	 * delay slot (SF_ERRATA_51).  For safety's sake, we assume
9177c478bd9Sstevel@tonic-gate	 * that the whole world needs the workaround.
9187c478bd9Sstevel@tonic-gate	 */
9197c478bd9Sstevel@tonic-gate	ENTRY(membar_enter)
9207c478bd9Sstevel@tonic-gate	membar	#StoreLoad|#StoreStore
9217c478bd9Sstevel@tonic-gate	retl
9227c478bd9Sstevel@tonic-gate	nop
9237c478bd9Sstevel@tonic-gate	SET_SIZE(membar_enter)
9247c478bd9Sstevel@tonic-gate
9257c478bd9Sstevel@tonic-gate	ENTRY(membar_exit)
9267c478bd9Sstevel@tonic-gate	membar	#LoadStore|#StoreStore
9277c478bd9Sstevel@tonic-gate	retl
9287c478bd9Sstevel@tonic-gate	nop
9297c478bd9Sstevel@tonic-gate	SET_SIZE(membar_exit)
9307c478bd9Sstevel@tonic-gate
9317c478bd9Sstevel@tonic-gate	ENTRY(membar_producer)
9327c478bd9Sstevel@tonic-gate	membar	#StoreStore
9337c478bd9Sstevel@tonic-gate	retl
9347c478bd9Sstevel@tonic-gate	nop
9357c478bd9Sstevel@tonic-gate	SET_SIZE(membar_producer)
9367c478bd9Sstevel@tonic-gate
9377c478bd9Sstevel@tonic-gate	ENTRY(membar_consumer)
9387c478bd9Sstevel@tonic-gate	membar	#LoadLoad
9397c478bd9Sstevel@tonic-gate	retl
9407c478bd9Sstevel@tonic-gate	nop
9417c478bd9Sstevel@tonic-gate	SET_SIZE(membar_consumer)
9427c478bd9Sstevel@tonic-gate
9437c478bd9Sstevel@tonic-gate#endif	/* !_KERNEL */
944