PageRenderTime 182ms CodeModel.GetById 121ms app.highlight 9ms RepoModel.GetById 31ms app.codeStats 1ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/js/lock_SunOS.s

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
Assembly | 119 lines | 108 code | 11 blank | 0 comment | 8 complexity | 26af6a398d7424e7db62fb71d0be0cc4 MD5 | raw file
  1! 
  2! ***** BEGIN LICENSE BLOCK *****
  3! Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4!
  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/
  9!
 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.
 14!
 15! The Original Code is Mozilla Communicator client code, released
 16! March 31, 1998.
 17!
 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.
 22!
 23! Contributor(s):
 24!
 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.
 36!
 37! ***** END LICENSE BLOCK *****
 38
 39!
 40!  atomic compare-and-swap routines for V8 sparc 
 41!  and for V8+ (ultrasparc)
 42!
 43!
 44!  standard asm linkage macros; this module must be compiled
 45!  with the -P option (use C preprocessor)
 46
 47#include <sys/asm_linkage.h>
 48
 49!  ======================================================================
 50!
 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.	
 54!
 55!  usage : old_val = compare_and_swap(address, oldval, newval)
 56!
 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.
 64!
 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	
 73
 74        ENTRY(compare_and_swap)         ! standard assembler/ELF prologue
 75
 76	stbar
 77	mov -1,%o3                      ! busy flag
 78	swap [%o0],%o3                  ! get current value
 79l1:	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
 88l2:	retl
 89	mov 1,%o0                       ! return true
 90	
 91	SET_SIZE(compare_and_swap)      ! standard assembler/ELF epilogue
 92
 93!
 94!  end
 95!
 96#else /* ULTRA_SPARC */
 97!  ======================================================================
 98!
 99!  v9
100
101        ENTRY(compare_and_swap)         ! standard assembler/ELF prologue
102
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
109m1:	retl
110	nop
111		
112	SET_SIZE(compare_and_swap)      ! standard assembler/ELF epilogue
113
114!
115!  end
116!
117!  ======================================================================
118!
119#endif