atomic_64.S 2.8 KB
Newer Older
1
/* atomic.S: These things are too big to do inline.
L
Linus Torvalds 已提交
2
 *
3
 * Copyright (C) 1999, 2007 David S. Miller (davem@davemloft.net)
L
Linus Torvalds 已提交
4 5 6
 */

#include <asm/asi.h>
7
#include <asm/backoff.h>
L
Linus Torvalds 已提交
8 9 10 11 12 13 14 15 16 17 18

	.text

	/* Two versions of the atomic routines, one that
	 * does not return a value and does not perform
	 * memory barriers, and a second which returns
	 * a value and does the barriers.
	 */
	.globl	atomic_add
	.type	atomic_add,#function
atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
19
	BACKOFF_SETUP(%o2)
L
Linus Torvalds 已提交
20 21 22 23
1:	lduw	[%o1], %g1
	add	%g1, %o0, %g7
	cas	[%o1], %g1, %g7
	cmp	%g1, %g7
24
	bne,pn	%icc, 2f
L
Linus Torvalds 已提交
25 26 27
	 nop
	retl
	 nop
28
2:	BACKOFF_SPIN(%o2, %o3, 1b)
L
Linus Torvalds 已提交
29 30 31 32 33
	.size	atomic_add, .-atomic_add

	.globl	atomic_sub
	.type	atomic_sub,#function
atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
34
	BACKOFF_SETUP(%o2)
L
Linus Torvalds 已提交
35 36 37 38
1:	lduw	[%o1], %g1
	sub	%g1, %o0, %g7
	cas	[%o1], %g1, %g7
	cmp	%g1, %g7
39
	bne,pn	%icc, 2f
L
Linus Torvalds 已提交
40 41 42
	 nop
	retl
	 nop
43
2:	BACKOFF_SPIN(%o2, %o3, 1b)
L
Linus Torvalds 已提交
44 45 46 47 48
	.size	atomic_sub, .-atomic_sub

	.globl	atomic_add_ret
	.type	atomic_add_ret,#function
atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
49
	BACKOFF_SETUP(%o2)
L
Linus Torvalds 已提交
50 51 52 53
1:	lduw	[%o1], %g1
	add	%g1, %o0, %g7
	cas	[%o1], %g1, %g7
	cmp	%g1, %g7
54
	bne,pn	%icc, 2f
55
	 add	%g1, %o0, %g1
L
Linus Torvalds 已提交
56
	retl
57
	 sra	%g1, 0, %o0
58
2:	BACKOFF_SPIN(%o2, %o3, 1b)
L
Linus Torvalds 已提交
59 60 61 62 63
	.size	atomic_add_ret, .-atomic_add_ret

	.globl	atomic_sub_ret
	.type	atomic_sub_ret,#function
atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
64
	BACKOFF_SETUP(%o2)
L
Linus Torvalds 已提交
65 66 67 68
1:	lduw	[%o1], %g1
	sub	%g1, %o0, %g7
	cas	[%o1], %g1, %g7
	cmp	%g1, %g7
69
	bne,pn	%icc, 2f
70
	 sub	%g1, %o0, %g1
L
Linus Torvalds 已提交
71
	retl
72
	 sra	%g1, 0, %o0
73
2:	BACKOFF_SPIN(%o2, %o3, 1b)
L
Linus Torvalds 已提交
74 75 76 77 78
	.size	atomic_sub_ret, .-atomic_sub_ret

	.globl	atomic64_add
	.type	atomic64_add,#function
atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
79
	BACKOFF_SETUP(%o2)
L
Linus Torvalds 已提交
80 81 82 83
1:	ldx	[%o1], %g1
	add	%g1, %o0, %g7
	casx	[%o1], %g1, %g7
	cmp	%g1, %g7
84
	bne,pn	%xcc, 2f
L
Linus Torvalds 已提交
85 86 87
	 nop
	retl
	 nop
88
2:	BACKOFF_SPIN(%o2, %o3, 1b)
L
Linus Torvalds 已提交
89 90 91 92 93
	.size	atomic64_add, .-atomic64_add

	.globl	atomic64_sub
	.type	atomic64_sub,#function
atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
94
	BACKOFF_SETUP(%o2)
L
Linus Torvalds 已提交
95 96 97 98
1:	ldx	[%o1], %g1
	sub	%g1, %o0, %g7
	casx	[%o1], %g1, %g7
	cmp	%g1, %g7
99
	bne,pn	%xcc, 2f
L
Linus Torvalds 已提交
100 101 102
	 nop
	retl
	 nop
103
2:	BACKOFF_SPIN(%o2, %o3, 1b)
L
Linus Torvalds 已提交
104 105 106 107 108
	.size	atomic64_sub, .-atomic64_sub

	.globl	atomic64_add_ret
	.type	atomic64_add_ret,#function
atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
109
	BACKOFF_SETUP(%o2)
L
Linus Torvalds 已提交
110 111 112 113
1:	ldx	[%o1], %g1
	add	%g1, %o0, %g7
	casx	[%o1], %g1, %g7
	cmp	%g1, %g7
114
	bne,pn	%xcc, 2f
115
	 nop
116 117
	retl
	 add	%g1, %o0, %o0
118
2:	BACKOFF_SPIN(%o2, %o3, 1b)
L
Linus Torvalds 已提交
119 120 121 122 123
	.size	atomic64_add_ret, .-atomic64_add_ret

	.globl	atomic64_sub_ret
	.type	atomic64_sub_ret,#function
atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
124
	BACKOFF_SETUP(%o2)
L
Linus Torvalds 已提交
125 126 127 128
1:	ldx	[%o1], %g1
	sub	%g1, %o0, %g7
	casx	[%o1], %g1, %g7
	cmp	%g1, %g7
129
	bne,pn	%xcc, 2f
130
	 nop
131 132
	retl
	 sub	%g1, %o0, %o0
133
2:	BACKOFF_SPIN(%o2, %o3, 1b)
L
Linus Torvalds 已提交
134
	.size	atomic64_sub_ret, .-atomic64_sub_ret