2
! The contents of this file are subject to the Netscape Public
3
! License Version 1.1 (the "License"); you may not use this file
4
! except in compliance with the License. You may obtain a copy of
5
! the License at http://www.mozilla.org/NPL/
7
! Software distributed under the License is distributed on an "AS
8
! IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9
! implied. See the License for the specific language governing
10
! rights and limitations under the License.
12
! The Original Code is Mozilla Communicator client code, released
15
! The Initial Developer of the Original Code is Netscape
16
! Communications Corporation. Portions created by Netscape are
17
! Copyright (C) 1998-1999 Netscape Communications Corporation. All
22
! Alternatively, the contents of this file may be used under the
23
! terms of the GNU Public License (the "GPL"), in which case the
24
! provisions of the GPL are applicable instead of those above.
25
! If you wish to allow use of your version of this file only
26
! under the terms of the GPL and not to allow others to use your
27
! version of this file under the NPL, indicate your decision by
28
! deleting the provisions above and replace them with the notice
29
! and other provisions required by the GPL. If you do not delete
30
! the provisions above, a recipient may use your version of this
31
! file under either the NPL or the GPL.
35
! atomic compare-and-swap routines for V8 sparc
36
! and for V8+ (ultrasparc)
39
! standard asm linkage macros; this module must be compiled
40
! with the -P option (use C preprocessor)
42
#include <sys/asm_linkage.h>
44
! ======================================================================
46
! Perform the sequence *a = b atomically with respect to previous value
47
! of a (a0). If *a==a0 then assign *a to b, all in one atomic operation.
48
! Returns 1 if assignment happened, and 0 otherwise.
50
! usage : old_val = compare_and_swap(address, oldval, newval)
52
! -----------------------
53
! Note on REGISTER USAGE:
54
! as this is a LEAF procedure, a new stack frame is not created;
55
! we use the caller stack frame so what would normally be %i (input)
56
! registers are actually %o (output registers). Also, we must not
57
! overwrite the contents of %l (local) registers as they are not
58
! assumed to be volatile during calls.
60
! So, the registers used are:
61
! %o0 [input] - the address of the value to increment
62
! %o1 [input] - the old value to compare with
63
! %o2 [input] - the new value to set for [%o0]
64
! %o3 [local] - work register
65
! -----------------------
69
ENTRY(compare_and_swap) ! standard assembler/ELF prologue
72
mov -1,%o3 ! busy flag
73
swap [%o0],%o3 ! get current value
74
l1: cmp %o3,-1 ! busy?
76
swap [%o0],%o3 ! using branch-delay to swap back value
77
cmp %o1,%o3 ! compare old with current
78
be,a l2 ! if equal then swap in new value
79
swap [%o0],%o2 ! done.
80
swap [%o0],%o3 ! otherwise, swap back current value
82
mov 0,%o0 ! return false
84
mov 1,%o0 ! return true
86
SET_SIZE(compare_and_swap) ! standard assembler/ELF epilogue
91
#else /* ULTRA_SPARC */
92
! ======================================================================
96
ENTRY(compare_and_swap) ! standard assembler/ELF prologue
99
cas [%o0],%o1,%o2 ! compare *w with old value and set to new if equal
100
cmp %o1,%o2 ! did we succeed?
102
mov 1,%o0 ! return true (annulled when no jump)
103
mov 0,%o0 ! return false
107
SET_SIZE(compare_and_swap) ! standard assembler/ELF epilogue
112
! ======================================================================