* ========== Copyright Header Begin ==========================================
* OpenSPARC T2 Processor File: atomic.h
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
* The above named program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
* ========== Copyright Header End ============================================
* atomic arithmetic and logical ops
* all atomic ops return the PREVIOUS value.
* barrier sync using atomics and spinloops,
* for when #workerthreads <= #hostcpus only, otherwise
* performance will be _severly_ degraded...
* and requires TSO memory as currently coded w/o any membars.
extern int32_t atomic_add_32 (volatile int32_t * variable
, const int32_t value
);
extern int32_t atomic_sub_32 (volatile int32_t * variable
, const int32_t value
);
extern int32_t atomic_and_32 (volatile int32_t * variable
, const int32_t value
);
extern int32_t atomic_or_32 (volatile int32_t * variable
, const int32_t value
);
extern int32_t atomic_xor_32 (volatile int32_t * variable
, const int32_t value
);
inline int32_t atomic_barrier (volatile int32_t * numThreads
,
volatile int32_t * doneCount
,
volatile int32_t * doneLock
,
volatile int32_t * returnVal
,
volatile int32_t * tempVal
)
register int32_t tmp
= *doneLock
; // fetch on entry <------------#
register int32_t NTm1
= *numThreads
-1;
if (atomic_add_32 (doneCount
, 1) < NTm1
) { // early arrivals
while (*doneLock
== tmp
) ; // spin until flip <---#
*doneCount
= 0; // resets
*tempVal
= *returnVal
; // inspects
*doneLock
= !tmp
; // flips <-------------#
return *tempVal
; // everybody gets identical return value.
extern int64_t atomic_add_64 (volatile int64_t * variable
, const int64_t value
);
extern int64_t atomic_sub_64 (volatile int64_t * variable
, const int64_t value
);
extern int64_t atomic_and_64 (volatile int64_t * variable
, const int64_t value
);
extern int64_t atomic_or_64 (volatile int64_t * variable
, const int64_t value
);
extern int64_t atomic_xor_64 (volatile int64_t * variable
, const int64_t value
);