Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / bl / lib / utl / src / BL_Atomic.s
CommitLineData
920dae64
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* OpenSPARC T2 Processor File: BL_Atomic.s
5* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
7*
8* The above named program is free software; you can redistribute it and/or
9* modify it under the terms of the GNU General Public
10* License version 2 as published by the Free Software Foundation.
11*
12* The above named program is distributed in the hope that it will be
13* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15* General Public License for more details.
16*
17* You should have received a copy of the GNU General Public
18* License along with this work; if not, write to the Free Software
19* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20*
21* ========== Copyright Header End ============================================
22*/
23#if defined(ARCH_X64)
24
25 .text
26
27/*============================================================================*\
28 * int64_t bl_atomic_add64( int64_t* var, int64_t val )
29 *
30 * Implement atomic 64bit add with casxa, The value returned is the old *var
31\*============================================================================*/
32
33 .align 16
34 .globl bl_atomic_add64
35 .type bl_atomic_add64, @function
36bl_atomic_add64:
37 movq %rsi,%rax
38 lock
39 xaddq %rax,(%rdi)
40 ret
41 .size bl_atomic_add64, [.-bl_atomic_add64]
42
43/*============================================================================*\
44 * int32_t bl_atomic_add32( int32_t* var, int32_t val )
45 *
46 * Implement atomic 32bit add with casa. The value returned in the old *var
47\*============================================================================*/
48
49 .align 16
50 .globl bl_atomic_add32
51 .type bl_atomic_add32, @function
52bl_atomic_add32:
53 movl %esi,%eax
54 lock
55 xaddl %eax,(%rdi)
56 ret
57 .size bl_atomic_add32, [.-bl_atomic_add32]
58
59#else
60
61.section ".text"
62
63/*============================================================================*\
64 * int64_t bl_atomic_add64( int64_t* var, int64_t val )
65 *
66 * Implement atomic 64bit add with casxa, The value returned is the old *var
67\*============================================================================*/
68
69.global bl_atomic_add64
70.type bl_atomic_add64, #function
71
72bl_atomic_add64:
73 ldx [%o0],%o2 /* Load *var */
741:
75 add %o2,%o1,%o3 /* Goal is *var + val */
76 casxa [%o0]0x80,%o2,%o3 /* */
77 cmp %o2,%o3 /* Test if we added to same *var value */
78 bne %xcc,1b /* If not we did not */
79 mov %o3,%o2 /* Try again with new *var (casxa is ldx) */
80 retl
81 mov %o3,%o0 /* Return previous value */
82
83
84/*============================================================================*\
85 * int32_t bl_atomic_add32( int32_t* var, int32_t val )
86 *
87 * Implement atomic 32bit add with casa. The value returned in the old *var
88\*============================================================================*/
89
90.global bl_atomic_add32
91.type bl_atomic_add32, #function
92
93bl_atomic_add32:
94 ld [%o0],%o2 /* Load *var */
951:
96 add %o2,%o1,%o3 /* Goal is *var = val + *var */
97 casa [%o0]0x80,%o2,%o3 /* */
98 cmp %o2,%o3 /* Test if we added to same *var value */
99 bne %icc,1b /* If not we did not */
100 mov %o3,%o2 /* Try again with new *var (casxa is ldx) */
101 retl
102 sra %o3,0,%o0 /* Return previous value (32 bit) */
103
104#endif