~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/js/src/lock_SunOS.s

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
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/
 
6
 
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.
 
11
 
12
! The Original Code is Mozilla Communicator client code, released
 
13
! March 31, 1998.
 
14
 
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
 
18
! Rights Reserved.
 
19
 
20
! Contributor(s):
 
21
 
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.
 
32
 
33
 
 
34
!
 
35
!  atomic compare-and-swap routines for V8 sparc 
 
36
!  and for V8+ (ultrasparc)
 
37
!
 
38
!
 
39
!  standard asm linkage macros; this module must be compiled
 
40
!  with the -P option (use C preprocessor)
 
41
 
 
42
#include <sys/asm_linkage.h>
 
43
 
 
44
!  ======================================================================
 
45
!
 
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.   
 
49
!
 
50
!  usage : old_val = compare_and_swap(address, oldval, newval)
 
51
!
 
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.
 
59
!
 
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
!  -----------------------
 
66
#ifndef ULTRA_SPARC
 
67
!  v8   
 
68
 
 
69
        ENTRY(compare_and_swap)         ! standard assembler/ELF prologue
 
70
 
 
71
        stbar
 
72
        mov -1,%o3                      ! busy flag
 
73
        swap [%o0],%o3                  ! get current value
 
74
l1:     cmp %o3,-1                      ! busy?
 
75
        be,a l1                         ! if so, spin
 
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
 
81
        retl
 
82
        mov 0,%o0                       ! return false
 
83
l2:     retl
 
84
        mov 1,%o0                       ! return true
 
85
        
 
86
        SET_SIZE(compare_and_swap)      ! standard assembler/ELF epilogue
 
87
 
 
88
!
 
89
!  end
 
90
!
 
91
#else /* ULTRA_SPARC */
 
92
!  ======================================================================
 
93
!
 
94
!  v9
 
95
 
 
96
        ENTRY(compare_and_swap)         ! standard assembler/ELF prologue
 
97
 
 
98
        stbar
 
99
        cas [%o0],%o1,%o2               ! compare *w with old value and set to new if equal
 
100
        cmp %o1,%o2                     ! did we succeed?
 
101
        be,a m1                         ! yes
 
102
        mov 1,%o0                       ! return true (annulled when no jump)
 
103
        mov 0,%o0                       ! return false
 
104
m1:     retl
 
105
        nop
 
106
                
 
107
        SET_SIZE(compare_and_swap)      ! standard assembler/ELF epilogue
 
108
 
 
109
!
 
110
!  end
 
111
!
 
112
!  ======================================================================
 
113
!
 
114
#endif