xref: /titanic_51/usr/src/common/atomic/amd64/atomic.s (revision 6ed9368a130d7c9a82e574da808d34034da33748)
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/*
23bb5c894bSSurya Prakki * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
269a70fc3bSMark J. Nelson	.file	"atomic.s"
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h>
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate#if defined(_KERNEL)
317c478bd9Sstevel@tonic-gate	/*
32*6ed9368aSJosef 'Jeff' Sipek	 * Legacy kernel interfaces; they will go away the moment our closed
33*6ed9368aSJosef 'Jeff' Sipek	 * bins no longer require them.
347c478bd9Sstevel@tonic-gate	 */
357c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(cas8,atomic_cas_8,function)
367c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(cas32,atomic_cas_32,function)
377c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(cas64,atomic_cas_64,function)
387c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(caslong,atomic_cas_ulong,function)
397c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(casptr,atomic_cas_ptr,function)
407c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(atomic_and_long,atomic_and_ulong,function)
417c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK2(atomic_or_long,atomic_or_ulong,function)
427c478bd9Sstevel@tonic-gate#endif
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate	ENTRY(atomic_inc_8)
457c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_uchar)
467c478bd9Sstevel@tonic-gate	lock
477c478bd9Sstevel@tonic-gate	incb	(%rdi)
487c478bd9Sstevel@tonic-gate	ret
497c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_uchar)
507c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_8)
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate	ENTRY(atomic_inc_16)
537c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_ushort)
547c478bd9Sstevel@tonic-gate	lock
557c478bd9Sstevel@tonic-gate	incw	(%rdi)
567c478bd9Sstevel@tonic-gate	ret
577c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_ushort)
587c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_16)
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate	ENTRY(atomic_inc_32)
617c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_uint)
627c478bd9Sstevel@tonic-gate	lock
637c478bd9Sstevel@tonic-gate	incl	(%rdi)
647c478bd9Sstevel@tonic-gate	ret
657c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_uint)
667c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_32)
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate	ENTRY(atomic_inc_64)
697c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_ulong)
707c478bd9Sstevel@tonic-gate	lock
717c478bd9Sstevel@tonic-gate	incq	(%rdi)
727c478bd9Sstevel@tonic-gate	ret
737c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_ulong)
747c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_64)
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate	ENTRY(atomic_inc_8_nv)
777c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_uchar_nv)
7896d9f183SBill Holler	xorl	%eax, %eax	/ clear upper bits of %eax return register
7996d9f183SBill Holler	incb	%al		/ %al = 1
807c478bd9Sstevel@tonic-gate	lock
8196d9f183SBill Holler	  xaddb	%al, (%rdi)	/ %al = old value, (%rdi) = new value
8296d9f183SBill Holler	incb	%al		/ return new value
837c478bd9Sstevel@tonic-gate	ret
847c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_uchar_nv)
857c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_8_nv)
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate	ENTRY(atomic_inc_16_nv)
887c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_ushort_nv)
8996d9f183SBill Holler	xorl	%eax, %eax	/ clear upper bits of %eax return register
9096d9f183SBill Holler	incw	%ax		/ %ax = 1
917c478bd9Sstevel@tonic-gate	lock
9296d9f183SBill Holler	  xaddw	%ax, (%rdi)	/ %ax = old value, (%rdi) = new value
9396d9f183SBill Holler	incw	%ax		/ return new value
947c478bd9Sstevel@tonic-gate	ret
957c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_ushort_nv)
967c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_16_nv)
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate	ENTRY(atomic_inc_32_nv)
997c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_uint_nv)
10096d9f183SBill Holler	xorl	%eax, %eax	/ %eax = 0
10196d9f183SBill Holler	incl	%eax		/ %eax = 1
1027c478bd9Sstevel@tonic-gate	lock
10396d9f183SBill Holler	  xaddl	%eax, (%rdi)	/ %eax = old value, (%rdi) = new value
10496d9f183SBill Holler	incl	%eax		/ return new value
1057c478bd9Sstevel@tonic-gate	ret
1067c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_uint_nv)
1077c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_32_nv)
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate	ENTRY(atomic_inc_64_nv)
1107c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_inc_ulong_nv)
11196d9f183SBill Holler	xorq	%rax, %rax	/ %rax = 0
11296d9f183SBill Holler	incq	%rax		/ %rax = 1
1137c478bd9Sstevel@tonic-gate	lock
11496d9f183SBill Holler	  xaddq	%rax, (%rdi)	/ %rax = old value, (%rdi) = new value
11596d9f183SBill Holler	incq	%rax		/ return new value
1167c478bd9Sstevel@tonic-gate	ret
1177c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_ulong_nv)
1187c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_inc_64_nv)
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate	ENTRY(atomic_dec_8)
1217c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_uchar)
1227c478bd9Sstevel@tonic-gate	lock
1237c478bd9Sstevel@tonic-gate	decb	(%rdi)
1247c478bd9Sstevel@tonic-gate	ret
1257c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_uchar)
1267c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_8)
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate	ENTRY(atomic_dec_16)
1297c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_ushort)
1307c478bd9Sstevel@tonic-gate	lock
1317c478bd9Sstevel@tonic-gate	decw	(%rdi)
1327c478bd9Sstevel@tonic-gate	ret
1337c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_ushort)
1347c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_16)
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate	ENTRY(atomic_dec_32)
1377c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_uint)
1387c478bd9Sstevel@tonic-gate	lock
1397c478bd9Sstevel@tonic-gate	decl	(%rdi)
1407c478bd9Sstevel@tonic-gate	ret
1417c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_uint)
1427c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_32)
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate	ENTRY(atomic_dec_64)
1457c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_ulong)
1467c478bd9Sstevel@tonic-gate	lock
1477c478bd9Sstevel@tonic-gate	decq	(%rdi)
1487c478bd9Sstevel@tonic-gate	ret
1497c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_ulong)
1507c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_64)
1517c478bd9Sstevel@tonic-gate
1527c478bd9Sstevel@tonic-gate	ENTRY(atomic_dec_8_nv)
1537c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_uchar_nv)
15496d9f183SBill Holler	xorl	%eax, %eax	/ clear upper bits of %eax return register
15596d9f183SBill Holler	decb	%al		/ %al = -1
1567c478bd9Sstevel@tonic-gate	lock
15796d9f183SBill Holler	  xaddb	%al, (%rdi)	/ %al = old value, (%rdi) = new value
15896d9f183SBill Holler	decb	%al		/ return new value
1597c478bd9Sstevel@tonic-gate	ret
1607c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_uchar_nv)
1617c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_8_nv)
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate	ENTRY(atomic_dec_16_nv)
1647c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_ushort_nv)
16596d9f183SBill Holler	xorl	%eax, %eax	/ clear upper bits of %eax return register
16696d9f183SBill Holler	decw	%ax		/ %ax = -1
1677c478bd9Sstevel@tonic-gate	lock
16896d9f183SBill Holler	  xaddw	%ax, (%rdi)	/ %ax = old value, (%rdi) = new value
16996d9f183SBill Holler	decw	%ax		/ return new value
1707c478bd9Sstevel@tonic-gate	ret
1717c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_ushort_nv)
1727c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_16_nv)
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate	ENTRY(atomic_dec_32_nv)
1757c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_uint_nv)
17696d9f183SBill Holler	xorl	%eax, %eax	/ %eax = 0
17796d9f183SBill Holler	decl	%eax		/ %eax = -1
1787c478bd9Sstevel@tonic-gate	lock
17996d9f183SBill Holler	  xaddl	%eax, (%rdi)	/ %eax = old value, (%rdi) = new value
18096d9f183SBill Holler	decl	%eax		/ return new value
1817c478bd9Sstevel@tonic-gate	ret
1827c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_uint_nv)
1837c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_32_nv)
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate	ENTRY(atomic_dec_64_nv)
1867c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_dec_ulong_nv)
18796d9f183SBill Holler	xorq	%rax, %rax	/ %rax = 0
18896d9f183SBill Holler	decq	%rax		/ %rax = -1
1897c478bd9Sstevel@tonic-gate	lock
19096d9f183SBill Holler	  xaddq	%rax, (%rdi)	/ %rax = old value, (%rdi) = new value
19196d9f183SBill Holler	decq	%rax		/ return new value
1927c478bd9Sstevel@tonic-gate	ret
1937c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_ulong_nv)
1947c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_dec_64_nv)
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate	ENTRY(atomic_add_8)
1977c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_char)
1987c478bd9Sstevel@tonic-gate	lock
1997c478bd9Sstevel@tonic-gate	addb	%sil, (%rdi)
2007c478bd9Sstevel@tonic-gate	ret
2017c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_char)
2027c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_8)
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate	ENTRY(atomic_add_16)
2057c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_short)
2067c478bd9Sstevel@tonic-gate	lock
2077c478bd9Sstevel@tonic-gate	addw	%si, (%rdi)
2087c478bd9Sstevel@tonic-gate	ret
2097c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_short)
2107c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_16)
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate	ENTRY(atomic_add_32)
2137c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_int)
2147c478bd9Sstevel@tonic-gate	lock
2157c478bd9Sstevel@tonic-gate	addl	%esi, (%rdi)
2167c478bd9Sstevel@tonic-gate	ret
2177c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_int)
2187c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_32)
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate	ENTRY(atomic_add_64)
2217c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_ptr)
2227c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_long)
2237c478bd9Sstevel@tonic-gate	lock
2247c478bd9Sstevel@tonic-gate	addq	%rsi, (%rdi)
2257c478bd9Sstevel@tonic-gate	ret
2267c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_long)
2277c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_ptr)
2287c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_64)
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate	ENTRY(atomic_or_8)
2317c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_uchar)
2327c478bd9Sstevel@tonic-gate	lock
2337c478bd9Sstevel@tonic-gate	orb	%sil, (%rdi)
2347c478bd9Sstevel@tonic-gate	ret
2357c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_uchar)
2367c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_8)
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate	ENTRY(atomic_or_16)
2397c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_ushort)
2407c478bd9Sstevel@tonic-gate	lock
2417c478bd9Sstevel@tonic-gate	orw	%si, (%rdi)
2427c478bd9Sstevel@tonic-gate	ret
2437c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_ushort)
2447c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_16)
2457c478bd9Sstevel@tonic-gate
2467c478bd9Sstevel@tonic-gate	ENTRY(atomic_or_32)
2477c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_uint)
2487c478bd9Sstevel@tonic-gate	lock
2497c478bd9Sstevel@tonic-gate	orl	%esi, (%rdi)
2507c478bd9Sstevel@tonic-gate	ret
2517c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_uint)
2527c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_32)
2537c478bd9Sstevel@tonic-gate
2547c478bd9Sstevel@tonic-gate	ENTRY(atomic_or_64)
2557c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_ulong)
2567c478bd9Sstevel@tonic-gate	lock
2577c478bd9Sstevel@tonic-gate	orq	%rsi, (%rdi)
2587c478bd9Sstevel@tonic-gate	ret
2597c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_ulong)
2607c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_64)
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate	ENTRY(atomic_and_8)
2637c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_uchar)
2647c478bd9Sstevel@tonic-gate	lock
2657c478bd9Sstevel@tonic-gate	andb	%sil, (%rdi)
2667c478bd9Sstevel@tonic-gate	ret
2677c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_uchar)
2687c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_8)
2697c478bd9Sstevel@tonic-gate
2707c478bd9Sstevel@tonic-gate	ENTRY(atomic_and_16)
2717c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_ushort)
2727c478bd9Sstevel@tonic-gate	lock
2737c478bd9Sstevel@tonic-gate	andw	%si, (%rdi)
2747c478bd9Sstevel@tonic-gate	ret
2757c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_ushort)
2767c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_16)
2777c478bd9Sstevel@tonic-gate
2787c478bd9Sstevel@tonic-gate	ENTRY(atomic_and_32)
2797c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_uint)
2807c478bd9Sstevel@tonic-gate	lock
2817c478bd9Sstevel@tonic-gate	andl	%esi, (%rdi)
2827c478bd9Sstevel@tonic-gate	ret
2837c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_uint)
2847c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_32)
2857c478bd9Sstevel@tonic-gate
2867c478bd9Sstevel@tonic-gate	ENTRY(atomic_and_64)
2877c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_ulong)
2887c478bd9Sstevel@tonic-gate	lock
2897c478bd9Sstevel@tonic-gate	andq	%rsi, (%rdi)
2907c478bd9Sstevel@tonic-gate	ret
2917c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_ulong)
2927c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_64)
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate	ENTRY(atomic_add_8_nv)
2957c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_char_nv)
29696d9f183SBill Holler	movzbl	%sil, %eax		/ %al = delta addend, clear upper bits
2977c478bd9Sstevel@tonic-gate	lock
29896d9f183SBill Holler	  xaddb	%sil, (%rdi)		/ %sil = old value, (%rdi) = sum
29996d9f183SBill Holler	addb	%sil, %al		/ new value = original value + delta
3007c478bd9Sstevel@tonic-gate	ret
3017c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_char_nv)
3027c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_8_nv)
3037c478bd9Sstevel@tonic-gate
3047c478bd9Sstevel@tonic-gate	ENTRY(atomic_add_16_nv)
3057c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_short_nv)
30696d9f183SBill Holler	movzwl	%si, %eax		/ %ax = delta addend, clean upper bits
3077c478bd9Sstevel@tonic-gate	lock
30896d9f183SBill Holler	  xaddw	%si, (%rdi)		/ %si = old value, (%rdi) = sum
30996d9f183SBill Holler	addw	%si, %ax		/ new value = original value + delta
3107c478bd9Sstevel@tonic-gate	ret
3117c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_short_nv)
3127c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_16_nv)
3137c478bd9Sstevel@tonic-gate
3147c478bd9Sstevel@tonic-gate	ENTRY(atomic_add_32_nv)
3157c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_int_nv)
31696d9f183SBill Holler	mov	%esi, %eax		/ %eax = delta addend
3177c478bd9Sstevel@tonic-gate	lock
31896d9f183SBill Holler	  xaddl	%esi, (%rdi)		/ %esi = old value, (%rdi) = sum
31996d9f183SBill Holler	add	%esi, %eax		/ new value = original value + delta
3207c478bd9Sstevel@tonic-gate	ret
3217c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_int_nv)
3227c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_32_nv)
3237c478bd9Sstevel@tonic-gate
3247c478bd9Sstevel@tonic-gate	ENTRY(atomic_add_64_nv)
3257c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_ptr_nv)
3267c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_add_long_nv)
32796d9f183SBill Holler	mov	%rsi, %rax		/ %rax = delta addend
3287c478bd9Sstevel@tonic-gate	lock
32996d9f183SBill Holler	  xaddq	%rsi, (%rdi)		/ %rsi = old value, (%rdi) = sum
33096d9f183SBill Holler	addq	%rsi, %rax		/ new value = original value + delta
3317c478bd9Sstevel@tonic-gate	ret
3327c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_long_nv)
3337c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_ptr_nv)
3347c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_add_64_nv)
3357c478bd9Sstevel@tonic-gate
3367c478bd9Sstevel@tonic-gate	ENTRY(atomic_and_8_nv)
3377c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_uchar_nv)
3387c478bd9Sstevel@tonic-gate	movb	(%rdi), %al	/ %al = old value
3397c478bd9Sstevel@tonic-gate1:
3407c478bd9Sstevel@tonic-gate	movb	%sil, %cl
3417c478bd9Sstevel@tonic-gate	andb	%al, %cl	/ %cl = new value
3427c478bd9Sstevel@tonic-gate	lock
3437c478bd9Sstevel@tonic-gate	cmpxchgb %cl, (%rdi)	/ try to stick it in
3447c478bd9Sstevel@tonic-gate	jne	1b
3457c478bd9Sstevel@tonic-gate	movzbl	%cl, %eax	/ return new value
3467c478bd9Sstevel@tonic-gate	ret
3477c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_uchar_nv)
3487c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_8_nv)
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate	ENTRY(atomic_and_16_nv)
3517c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_ushort_nv)
3527c478bd9Sstevel@tonic-gate	movw	(%rdi), %ax	/ %ax = old value
3537c478bd9Sstevel@tonic-gate1:
3547c478bd9Sstevel@tonic-gate	movw	%si, %cx
3557c478bd9Sstevel@tonic-gate	andw	%ax, %cx	/ %cx = new value
3567c478bd9Sstevel@tonic-gate	lock
3577c478bd9Sstevel@tonic-gate	cmpxchgw %cx, (%rdi)	/ try to stick it in
3587c478bd9Sstevel@tonic-gate	jne	1b
3597c478bd9Sstevel@tonic-gate	movzwl	%cx, %eax	/ return new value
3607c478bd9Sstevel@tonic-gate	ret
3617c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_ushort_nv)
3627c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_16_nv)
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gate	ENTRY(atomic_and_32_nv)
3657c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_uint_nv)
3667c478bd9Sstevel@tonic-gate	movl	(%rdi), %eax
3677c478bd9Sstevel@tonic-gate1:
3687c478bd9Sstevel@tonic-gate	movl	%esi, %ecx
3697c478bd9Sstevel@tonic-gate	andl	%eax, %ecx
3707c478bd9Sstevel@tonic-gate	lock
3717c478bd9Sstevel@tonic-gate	cmpxchgl %ecx, (%rdi)
3727c478bd9Sstevel@tonic-gate	jne	1b
3737c478bd9Sstevel@tonic-gate	movl	%ecx, %eax
3747c478bd9Sstevel@tonic-gate	ret
3757c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_uint_nv)
3767c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_32_nv)
3777c478bd9Sstevel@tonic-gate
3787c478bd9Sstevel@tonic-gate	ENTRY(atomic_and_64_nv)
3797c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_and_ulong_nv)
3807c478bd9Sstevel@tonic-gate	movq	(%rdi), %rax
3817c478bd9Sstevel@tonic-gate1:
3827c478bd9Sstevel@tonic-gate	movq	%rsi, %rcx
3837c478bd9Sstevel@tonic-gate	andq	%rax, %rcx
3847c478bd9Sstevel@tonic-gate	lock
3857c478bd9Sstevel@tonic-gate	cmpxchgq %rcx, (%rdi)
3867c478bd9Sstevel@tonic-gate	jne	1b
3877c478bd9Sstevel@tonic-gate	movq	%rcx, %rax
3887c478bd9Sstevel@tonic-gate	ret
3897c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_ulong_nv)
3907c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_and_64_nv)
3917c478bd9Sstevel@tonic-gate
3927c478bd9Sstevel@tonic-gate	ENTRY(atomic_or_8_nv)
3937c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_uchar_nv)
3947c478bd9Sstevel@tonic-gate	movb	(%rdi), %al	/ %al = old value
3957c478bd9Sstevel@tonic-gate1:
3967c478bd9Sstevel@tonic-gate	movb	%sil, %cl
3977c478bd9Sstevel@tonic-gate	orb	%al, %cl	/ %cl = new value
3987c478bd9Sstevel@tonic-gate	lock
3997c478bd9Sstevel@tonic-gate	cmpxchgb %cl, (%rdi)	/ try to stick it in
4007c478bd9Sstevel@tonic-gate	jne	1b
4017c478bd9Sstevel@tonic-gate	movzbl	%cl, %eax	/ return new value
4027c478bd9Sstevel@tonic-gate	ret
403bb5c894bSSurya Prakki	SET_SIZE(atomic_or_uchar_nv)
404bb5c894bSSurya Prakki	SET_SIZE(atomic_or_8_nv)
4057c478bd9Sstevel@tonic-gate
4067c478bd9Sstevel@tonic-gate	ENTRY(atomic_or_16_nv)
4077c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_ushort_nv)
4087c478bd9Sstevel@tonic-gate	movw	(%rdi), %ax	/ %ax = old value
4097c478bd9Sstevel@tonic-gate1:
4107c478bd9Sstevel@tonic-gate	movw	%si, %cx
4117c478bd9Sstevel@tonic-gate	orw	%ax, %cx	/ %cx = new value
4127c478bd9Sstevel@tonic-gate	lock
4137c478bd9Sstevel@tonic-gate	cmpxchgw %cx, (%rdi)	/ try to stick it in
4147c478bd9Sstevel@tonic-gate	jne	1b
4157c478bd9Sstevel@tonic-gate	movzwl	%cx, %eax	/ return new value
4167c478bd9Sstevel@tonic-gate	ret
4177c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_ushort_nv)
4187c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_16_nv)
4197c478bd9Sstevel@tonic-gate
4207c478bd9Sstevel@tonic-gate	ENTRY(atomic_or_32_nv)
4217c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_uint_nv)
4227c478bd9Sstevel@tonic-gate	movl	(%rdi), %eax
4237c478bd9Sstevel@tonic-gate1:
4247c478bd9Sstevel@tonic-gate	movl	%esi, %ecx
4257c478bd9Sstevel@tonic-gate	orl	%eax, %ecx
4267c478bd9Sstevel@tonic-gate	lock
4277c478bd9Sstevel@tonic-gate	cmpxchgl %ecx, (%rdi)
4287c478bd9Sstevel@tonic-gate	jne	1b
4297c478bd9Sstevel@tonic-gate	movl	%ecx, %eax
4307c478bd9Sstevel@tonic-gate	ret
4317c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_uint_nv)
4327c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_32_nv)
4337c478bd9Sstevel@tonic-gate
4347c478bd9Sstevel@tonic-gate	ENTRY(atomic_or_64_nv)
4357c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_or_ulong_nv)
4367c478bd9Sstevel@tonic-gate	movq	(%rdi), %rax
4377c478bd9Sstevel@tonic-gate1:
4387c478bd9Sstevel@tonic-gate	movq	%rsi, %rcx
4397c478bd9Sstevel@tonic-gate	orq	%rax, %rcx
4407c478bd9Sstevel@tonic-gate	lock
4417c478bd9Sstevel@tonic-gate	cmpxchgq %rcx, (%rdi)
4427c478bd9Sstevel@tonic-gate	jne	1b
4437c478bd9Sstevel@tonic-gate	movq	%rcx, %rax
4447c478bd9Sstevel@tonic-gate	ret
4457c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_ulong_nv)
4467c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_or_64_nv)
4477c478bd9Sstevel@tonic-gate
4487c478bd9Sstevel@tonic-gate	ENTRY(atomic_cas_8)
4497c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_cas_uchar)
4507c478bd9Sstevel@tonic-gate	movzbl	%sil, %eax
4517c478bd9Sstevel@tonic-gate	lock
4527c478bd9Sstevel@tonic-gate	cmpxchgb %dl, (%rdi)
4537c478bd9Sstevel@tonic-gate	ret
4547c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_uchar)
4557c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_8)
4567c478bd9Sstevel@tonic-gate
4577c478bd9Sstevel@tonic-gate	ENTRY(atomic_cas_16)
4587c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_cas_ushort)
4597c478bd9Sstevel@tonic-gate	movzwl	%si, %eax
4607c478bd9Sstevel@tonic-gate	lock
4617c478bd9Sstevel@tonic-gate	cmpxchgw %dx, (%rdi)
4627c478bd9Sstevel@tonic-gate	ret
4637c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_ushort)
4647c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_16)
4657c478bd9Sstevel@tonic-gate
4667c478bd9Sstevel@tonic-gate	ENTRY(atomic_cas_32)
4677c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_cas_uint)
4687c478bd9Sstevel@tonic-gate	movl	%esi, %eax
4697c478bd9Sstevel@tonic-gate	lock
4707c478bd9Sstevel@tonic-gate	cmpxchgl %edx, (%rdi)
4717c478bd9Sstevel@tonic-gate	ret
4727c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_uint)
4737c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_32)
4747c478bd9Sstevel@tonic-gate
4757c478bd9Sstevel@tonic-gate	ENTRY(atomic_cas_64)
4767c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_cas_ulong)
4777c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_cas_ptr)
4787c478bd9Sstevel@tonic-gate	movq	%rsi, %rax
4797c478bd9Sstevel@tonic-gate	lock
4807c478bd9Sstevel@tonic-gate	cmpxchgq %rdx, (%rdi)
4817c478bd9Sstevel@tonic-gate	ret
4827c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_ptr)
4837c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_ulong)
4847c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_cas_64)
4857c478bd9Sstevel@tonic-gate
4867c478bd9Sstevel@tonic-gate	ENTRY(atomic_swap_8)
4877c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_swap_uchar)
4887c478bd9Sstevel@tonic-gate	movzbl	%sil, %eax
4897c478bd9Sstevel@tonic-gate	lock
4907c478bd9Sstevel@tonic-gate	xchgb %al, (%rdi)
4917c478bd9Sstevel@tonic-gate	ret
4927c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_uchar)
4937c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_8)
4947c478bd9Sstevel@tonic-gate
4957c478bd9Sstevel@tonic-gate	ENTRY(atomic_swap_16)
4967c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_swap_ushort)
4977c478bd9Sstevel@tonic-gate	movzwl	%si, %eax
4987c478bd9Sstevel@tonic-gate	lock
4997c478bd9Sstevel@tonic-gate	xchgw %ax, (%rdi)
5007c478bd9Sstevel@tonic-gate	ret
5017c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_ushort)
5027c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_16)
5037c478bd9Sstevel@tonic-gate
5047c478bd9Sstevel@tonic-gate	ENTRY(atomic_swap_32)
5057c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_swap_uint)
5067c478bd9Sstevel@tonic-gate	movl	%esi, %eax
5077c478bd9Sstevel@tonic-gate	lock
5087c478bd9Sstevel@tonic-gate	xchgl %eax, (%rdi)
5097c478bd9Sstevel@tonic-gate	ret
5107c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_uint)
5117c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_32)
5127c478bd9Sstevel@tonic-gate
5137c478bd9Sstevel@tonic-gate	ENTRY(atomic_swap_64)
5147c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_swap_ulong)
5157c478bd9Sstevel@tonic-gate	ALTENTRY(atomic_swap_ptr)
5167c478bd9Sstevel@tonic-gate	movq	%rsi, %rax
5177c478bd9Sstevel@tonic-gate	lock
5187c478bd9Sstevel@tonic-gate	xchgq %rax, (%rdi)
5197c478bd9Sstevel@tonic-gate	ret
5207c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_ptr)
5217c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_ulong)
5227c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_swap_64)
5237c478bd9Sstevel@tonic-gate
5247c478bd9Sstevel@tonic-gate	ENTRY(atomic_set_long_excl)
5257c478bd9Sstevel@tonic-gate	xorl	%eax, %eax
5267c478bd9Sstevel@tonic-gate	lock
5277c478bd9Sstevel@tonic-gate	btsq	%rsi, (%rdi)
5287c478bd9Sstevel@tonic-gate	jnc	1f
5297c478bd9Sstevel@tonic-gate	decl	%eax			/ return -1
5307c478bd9Sstevel@tonic-gate1:
5317c478bd9Sstevel@tonic-gate	ret
5327c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_set_long_excl)
5337c478bd9Sstevel@tonic-gate
5347c478bd9Sstevel@tonic-gate	ENTRY(atomic_clear_long_excl)
5357c478bd9Sstevel@tonic-gate	xorl	%eax, %eax
5367c478bd9Sstevel@tonic-gate	lock
5377c478bd9Sstevel@tonic-gate	btrq	%rsi, (%rdi)
5387c478bd9Sstevel@tonic-gate	jc	1f
5397c478bd9Sstevel@tonic-gate	decl	%eax			/ return -1
5407c478bd9Sstevel@tonic-gate1:
5417c478bd9Sstevel@tonic-gate	ret
5427c478bd9Sstevel@tonic-gate	SET_SIZE(atomic_clear_long_excl)
5437c478bd9Sstevel@tonic-gate
5447c478bd9Sstevel@tonic-gate#if !defined(_KERNEL)
5457c478bd9Sstevel@tonic-gate
546dfb96a4fSab196087	/*
547dfb96a4fSab196087	 * NOTE: membar_enter, and membar_exit are identical routines.
548dfb96a4fSab196087	 * We define them separately, instead of using an ALTENTRY
549dfb96a4fSab196087	 * definitions to alias them together, so that DTrace and
550dfb96a4fSab196087	 * debuggers will see a unique address for them, allowing
551dfb96a4fSab196087	 * more accurate tracing.
552dfb96a4fSab196087	*/
553dfb96a4fSab196087
5547c478bd9Sstevel@tonic-gate	ENTRY(membar_enter)
555dfb96a4fSab196087	mfence
556dfb96a4fSab196087	ret
557dfb96a4fSab196087	SET_SIZE(membar_enter)
558dfb96a4fSab196087
559dfb96a4fSab196087	ENTRY(membar_exit)
5607c478bd9Sstevel@tonic-gate	mfence
5617c478bd9Sstevel@tonic-gate	ret
5627c478bd9Sstevel@tonic-gate	SET_SIZE(membar_exit)
5637c478bd9Sstevel@tonic-gate
5647c478bd9Sstevel@tonic-gate	ENTRY(membar_producer)
5657c478bd9Sstevel@tonic-gate	sfence
5667c478bd9Sstevel@tonic-gate	ret
5677c478bd9Sstevel@tonic-gate	SET_SIZE(membar_producer)
5687c478bd9Sstevel@tonic-gate
5697c478bd9Sstevel@tonic-gate	ENTRY(membar_consumer)
5707c478bd9Sstevel@tonic-gate	lfence
5717c478bd9Sstevel@tonic-gate	ret
5727c478bd9Sstevel@tonic-gate	SET_SIZE(membar_consumer)
5737c478bd9Sstevel@tonic-gate
5747c478bd9Sstevel@tonic-gate#endif	/* !_KERNEL */
575