1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#;***************************************************************************
30#;* Boolean OSCompareAndSwap(SInt32 oldValue, SInt32 newValue, SInt32 *ptr) *
31#;***************************************************************************
32
33	.globl _OSCompareAndSwap
34_OSCompareAndSwap: #;oldValue, newValue, ptr
35#if	DEBUG
36	test	$3, %rdx
37	jz	1f
38	ud2
391:
40#endif
41	movl		 %edi, %eax
42	lock
43	cmpxchgl	%esi, (%rdx)	#; CAS (eax is an implicit operand)
44	sete		%al			#; did CAS succeed? (TZ=1)
45	movzbq		%al, %rax		#; clear out the high bytes
46	ret
47
48#;*****************************************************************************
49#;* Boolean OSCompareAndSwap64(SInt64 oldValue, SInt64 newValue, SInt64 *ptr) *
50#;*****************************************************************************
51
52	.globl _OSCompareAndSwap64
53	.globl _OSCompareAndSwapPtr
54
55_OSCompareAndSwap64:
56_OSCompareAndSwapPtr: #;oldValue, newValue, ptr
57#if	DEBUG
58	test	$7, %rdx
59	jz	1f
60	ud2
611:
62#endif
63	movq		%rdi, %rax
64	lock
65	cmpxchgq	%rsi, (%rdx)	#; CAS (rax is an implicit operand)
66	sete		%al			#; did CAS succeed? (TZ=1)
67	movzbq		%al, %rax		#; clear out the high bytes
68	ret
69
70#;*******************************************************
71#;* SInt64 OSAddAtomic64(SInt64 theAmount, SInt64 *ptr) *
72#;*******************************************************
73
74	.globl	_OSAddAtomicLong
75	.globl	_OSAddAtomic64
76_OSAddAtomic64:
77_OSAddAtomicLong:
78#if	DEBUG
79	test	$7, %rsi
80	jz	1f
81	ud2
821:
83#endif
84	lock
85	xaddq	%rdi, (%rsi)		#; Atomic exchange and add
86	movq	%rdi, %rax;
87	ret
88
89
90#;*******************************************************
91#; SInt32 OSAddAtomic(SInt32 delta, SInt32 *address)
92#;*******************************************************
93
94	.globl	_OSAddAtomic
95_OSAddAtomic:
96#if	DEBUG
97	test	$3, %rsi
98	jz	1f
99	ud2
1001:
101#endif
102	lock
103	xaddl	%edi, (%rsi)		#; Atomic exchange and add
104	movl	%edi, %eax;
105	ret
106