David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 1 | /* atomic.S: These things are too big to do inline. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 3 | * Copyright (C) 1999, 2007 David S. Miller (davem@davemloft.net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <asm/asi.h> |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 7 | #include <asm/backoff.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | .text |
| 10 | |
| 11 | /* Two versions of the atomic routines, one that |
| 12 | * does not return a value and does not perform |
| 13 | * memory barriers, and a second which returns |
| 14 | * a value and does the barriers. |
| 15 | */ |
| 16 | .globl atomic_add |
| 17 | .type atomic_add,#function |
| 18 | atomic_add: /* %o0 = increment, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 19 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | 1: lduw [%o1], %g1 |
| 21 | add %g1, %o0, %g7 |
| 22 | cas [%o1], %g1, %g7 |
| 23 | cmp %g1, %g7 |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 24 | bne,pn %icc, 2f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | nop |
| 26 | retl |
| 27 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 28 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | .size atomic_add, .-atomic_add |
| 30 | |
| 31 | .globl atomic_sub |
| 32 | .type atomic_sub,#function |
| 33 | atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 34 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | 1: lduw [%o1], %g1 |
| 36 | sub %g1, %o0, %g7 |
| 37 | cas [%o1], %g1, %g7 |
| 38 | cmp %g1, %g7 |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 39 | bne,pn %icc, 2f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | nop |
| 41 | retl |
| 42 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 43 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | .size atomic_sub, .-atomic_sub |
| 45 | |
| 46 | .globl atomic_add_ret |
| 47 | .type atomic_add_ret,#function |
| 48 | atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 49 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | 1: lduw [%o1], %g1 |
| 51 | add %g1, %o0, %g7 |
| 52 | cas [%o1], %g1, %g7 |
| 53 | cmp %g1, %g7 |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 54 | bne,pn %icc, 2f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | add %g7, %o0, %g7 |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 56 | sra %g7, 0, %o0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | retl |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 58 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 59 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | .size atomic_add_ret, .-atomic_add_ret |
| 61 | |
| 62 | .globl atomic_sub_ret |
| 63 | .type atomic_sub_ret,#function |
| 64 | atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 65 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | 1: lduw [%o1], %g1 |
| 67 | sub %g1, %o0, %g7 |
| 68 | cas [%o1], %g1, %g7 |
| 69 | cmp %g1, %g7 |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 70 | bne,pn %icc, 2f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | sub %g7, %o0, %g7 |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 72 | sra %g7, 0, %o0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | retl |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 74 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 75 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | .size atomic_sub_ret, .-atomic_sub_ret |
| 77 | |
| 78 | .globl atomic64_add |
| 79 | .type atomic64_add,#function |
| 80 | atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 81 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | 1: ldx [%o1], %g1 |
| 83 | add %g1, %o0, %g7 |
| 84 | casx [%o1], %g1, %g7 |
| 85 | cmp %g1, %g7 |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 86 | bne,pn %xcc, 2f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | nop |
| 88 | retl |
| 89 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 90 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | .size atomic64_add, .-atomic64_add |
| 92 | |
| 93 | .globl atomic64_sub |
| 94 | .type atomic64_sub,#function |
| 95 | atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 96 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | 1: ldx [%o1], %g1 |
| 98 | sub %g1, %o0, %g7 |
| 99 | casx [%o1], %g1, %g7 |
| 100 | cmp %g1, %g7 |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 101 | bne,pn %xcc, 2f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | nop |
| 103 | retl |
| 104 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 105 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | .size atomic64_sub, .-atomic64_sub |
| 107 | |
| 108 | .globl atomic64_add_ret |
| 109 | .type atomic64_add_ret,#function |
| 110 | atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 111 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | 1: ldx [%o1], %g1 |
| 113 | add %g1, %o0, %g7 |
| 114 | casx [%o1], %g1, %g7 |
| 115 | cmp %g1, %g7 |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 116 | bne,pn %xcc, 2f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | add %g7, %o0, %g7 |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 118 | mov %g7, %o0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | retl |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 120 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 121 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | .size atomic64_add_ret, .-atomic64_add_ret |
| 123 | |
| 124 | .globl atomic64_sub_ret |
| 125 | .type atomic64_sub_ret,#function |
| 126 | atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 127 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | 1: ldx [%o1], %g1 |
| 129 | sub %g1, %o0, %g7 |
| 130 | casx [%o1], %g1, %g7 |
| 131 | cmp %g1, %g7 |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 132 | bne,pn %xcc, 2f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | sub %g7, %o0, %g7 |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 134 | mov %g7, %o0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | retl |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 136 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 137 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | .size atomic64_sub_ret, .-atomic64_sub_ret |