Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / system / util / barrier_subr_v9.s
/*
* ========== Copyright Header Begin ==========================================
*
* OpenSPARC T2 Processor File: barrier_subr_v9.s
* 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 ============================================
*/
#ifdef ARCH_X64
/*
* void barrier(uint32_t loopticks)
* Hmm, this function is not used anymore and should be deleted.
* In fact, the following files should be deleted:
* system/util/barrier_subr_v9.s
* system/util/barrier_subr_v8.s
* system/util/include/barrier.h
* system/util/barrier.cc
* and all references to cpu_barrier
*/
#else
#pragma ident "@(#)1.3 07/07/10 barrier_subr_v9.s"
#include <sys/asm_linkage.h>
#if 0
ENTRY(barrier)
ldx [%o0+24], %o1 ! load bp->sbp into %o1
! atomic decrement of running count
add %o1, 4, %o2
retry: ld [%o2], %o3
add %o3, -1, %o4
cas [%o2], %o3, %o4
cmp %o3, %o4
bne retry
nop
! check if this is the last one
cmp %o3, 1
bne wait
nop
! YES, switch sub-barriers, reset count and CV
add %o0, 4, %o2 ! %o2 = &bp->sb[0]
cmp %o1, %o2
bne 1f
nop
add %o0, 12, %o2 ! %o2 = &bp->sb[1]
1: stx %o2, [%o0 + 24] ! store %o2 into bp->sbp
set 1, %o4
st %o4, [%o2]
ld [%o0], %o3
st %o3, [%o2 + 4]
! release the CV busy-waiters
retl
clr [%o1]
! NO, busy-wait on CV
wait: ld [%o1], %o2
tst %o2
bne wait
nop
retl
nop
SET_SIZE(barrier)
#else
.global cpu_barrier
ENTRY(barrier)
or %o0, 0, %o5 ! loopticks
setx cpu_barrier, %o2, %o0
ldx [%o0 + 24], %o1 ! load bp->sbp into %o1
ldx [%o0 + 32], %o0 !!!!!! global tick pointer
! atomic decrement of running count
add %o1, 4, %o2
retry: ld [%o2], %o3
add %o3, -1, %o4
cas [%o2], %o3, %o4
cmp %o3, %o4
bne retry
nop
retry1: ldx [%o0], %o2 !! global_tick + looptick
add %o2, %o5, %o4 !!
casx [%o0], %o2, %o4 !!
cmp %o2, %o4 !!
bne,pn %xcc, retry1
nop !!
! check if this is the last one
cmp %o3, 1
bne wait
nop
! YES, switch sub-barriers, reset count and CV
setx cpu_barrier, %o2, %o0
add %o0, 4, %o2 ! %o2 = &bp->sb[0]
cmp %o1, %o2
bne 1f
nop
add %o0, 12, %o2 ! %o2 = &bp->sb[1]
1: stx %o2, [%o0 + 24] ! store %o2 into bp->sbp
set 1, %o4
st %o4, [%o2]
ld [%o0], %o3
st %o3, [%o2 + 4]
! release the CV busy-waiters
retl
clr [%o1]
! NO, busy-wait on CV
wait: ld [%o1], %o2
tst %o2
bne wait
nop
retl
nop
SET_SIZE(barrier)
#endif
#endif