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