Save all modification
[mozilla-1.9/m8.git] / js / src / lock_SunOS.s
blob6feb202da22bbc317871fce8cde793228c6069b0
1 !
2 ! ***** BEGIN LICENSE BLOCK *****
3 ! Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 ! The contents of this file are subject to the Mozilla Public License Version
6 ! 1.1 (the "License"); you may not use this file except in compliance with
7 ! the License. You may obtain a copy of the License at
8 ! http://www.mozilla.org/MPL/
10 ! Software distributed under the License is distributed on an "AS IS" basis,
11 ! WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 ! for the specific language governing rights and limitations under the
13 ! License.
15 ! The Original Code is Mozilla Communicator client code, released
16 ! March 31, 1998.
18 ! The Initial Developer of the Original Code is
19 ! Netscape Communications Corporation.
20 ! Portions created by the Initial Developer are Copyright (C) 1998-1999
21 ! the Initial Developer. All Rights Reserved.
23 ! Contributor(s):
25 ! Alternatively, the contents of this file may be used under the terms of
26 ! either the GNU General Public License Version 2 or later (the "GPL"), or
27 ! the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 ! in which case the provisions of the GPL or the LGPL are applicable instead
29 ! of those above. If you wish to allow use of your version of this file only
30 ! under the terms of either the GPL or the LGPL, and not to allow others to
31 ! use your version of this file under the terms of the MPL, indicate your
32 ! decision by deleting the provisions above and replace them with the notice
33 ! and other provisions required by the GPL or the LGPL. If you do not delete
34 ! the provisions above, a recipient may use your version of this file under
35 ! the terms of any one of the MPL, the GPL or the LGPL.
37 ! ***** END LICENSE BLOCK *****
40 ! atomic compare-and-swap routines for V8 sparc
41 ! and for V8+ (ultrasparc)
44 ! standard asm linkage macros; this module must be compiled
45 ! with the -P option (use C preprocessor)
47 #include <sys/asm_linkage.h>
49 ! ======================================================================
51 ! Perform the sequence *a = b atomically with respect to previous value
52 ! of a (a0). If *a==a0 then assign *a to b, all in one atomic operation.
53 ! Returns 1 if assignment happened, and 0 otherwise.
55 ! usage : old_val = compare_and_swap(address, oldval, newval)
57 ! -----------------------
58 ! Note on REGISTER USAGE:
59 ! as this is a LEAF procedure, a new stack frame is not created;
60 ! we use the caller stack frame so what would normally be %i (input)
61 ! registers are actually %o (output registers). Also, we must not
62 ! overwrite the contents of %l (local) registers as they are not
63 ! assumed to be volatile during calls.
65 ! So, the registers used are:
66 ! %o0 [input] - the address of the value to increment
67 ! %o1 [input] - the old value to compare with
68 ! %o2 [input] - the new value to set for [%o0]
69 ! %o3 [local] - work register
70 ! -----------------------
71 #ifndef ULTRA_SPARC
72 ! v8
74 ENTRY(compare_and_swap) ! standard assembler/ELF prologue
76 stbar
77 mov -1,%o3 ! busy flag
78 swap [%o0],%o3 ! get current value
79 l1: cmp %o3,-1 ! busy?
80 be,a l1 ! if so, spin
81 swap [%o0],%o3 ! using branch-delay to swap back value
82 cmp %o1,%o3 ! compare old with current
83 be,a l2 ! if equal then swap in new value
84 swap [%o0],%o2 ! done.
85 swap [%o0],%o3 ! otherwise, swap back current value
86 retl
87 mov 0,%o0 ! return false
88 l2: retl
89 mov 1,%o0 ! return true
91 SET_SIZE(compare_and_swap) ! standard assembler/ELF epilogue
94 ! end
96 #else /* ULTRA_SPARC */
97 ! ======================================================================
99 ! v9
101 ENTRY(compare_and_swap) ! standard assembler/ELF prologue
103 stbar
104 cas [%o0],%o1,%o2 ! compare *w with old value and set to new if equal
105 cmp %o1,%o2 ! did we succeed?
106 be,a m1 ! yes
107 mov 1,%o0 ! return true (annulled when no jump)
108 mov 0,%o0 ! return false
109 m1: retl
112 SET_SIZE(compare_and_swap) ! standard assembler/ELF epilogue
115 ! end
117 ! ======================================================================
119 #endif