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 | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 24 | bne,pn %icc, BACKOFF_LABEL(2f, 1b) |
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 | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 39 | bne,pn %icc, BACKOFF_LABEL(2f, 1b) |
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 | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 54 | bne,pn %icc, BACKOFF_LABEL(2f, 1b) |
Mikulas Patocka | 6ec2747 | 2010-08-18 08:03:37 +0000 | [diff] [blame] | 55 | add %g1, %o0, %g1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | retl |
Mikulas Patocka | 6ec2747 | 2010-08-18 08:03:37 +0000 | [diff] [blame] | 57 | sra %g1, 0, %o0 |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 58 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | .size atomic_add_ret, .-atomic_add_ret |
| 60 | |
| 61 | .globl atomic_sub_ret |
| 62 | .type atomic_sub_ret,#function |
| 63 | atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 64 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | 1: lduw [%o1], %g1 |
| 66 | sub %g1, %o0, %g7 |
| 67 | cas [%o1], %g1, %g7 |
| 68 | cmp %g1, %g7 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 69 | bne,pn %icc, BACKOFF_LABEL(2f, 1b) |
Mikulas Patocka | 6ec2747 | 2010-08-18 08:03:37 +0000 | [diff] [blame] | 70 | sub %g1, %o0, %g1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | retl |
Mikulas Patocka | 6ec2747 | 2010-08-18 08:03:37 +0000 | [diff] [blame] | 72 | sra %g1, 0, %o0 |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 73 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | .size atomic_sub_ret, .-atomic_sub_ret |
| 75 | |
| 76 | .globl atomic64_add |
| 77 | .type atomic64_add,#function |
| 78 | atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 79 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | 1: ldx [%o1], %g1 |
| 81 | add %g1, %o0, %g7 |
| 82 | casx [%o1], %g1, %g7 |
| 83 | cmp %g1, %g7 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 84 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | nop |
| 86 | retl |
| 87 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 88 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | .size atomic64_add, .-atomic64_add |
| 90 | |
| 91 | .globl atomic64_sub |
| 92 | .type atomic64_sub,#function |
| 93 | atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 94 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | 1: ldx [%o1], %g1 |
| 96 | sub %g1, %o0, %g7 |
| 97 | casx [%o1], %g1, %g7 |
| 98 | cmp %g1, %g7 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 99 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | nop |
| 101 | retl |
| 102 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 103 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | .size atomic64_sub, .-atomic64_sub |
| 105 | |
| 106 | .globl atomic64_add_ret |
| 107 | .type atomic64_add_ret,#function |
| 108 | atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 109 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | 1: ldx [%o1], %g1 |
| 111 | add %g1, %o0, %g7 |
| 112 | casx [%o1], %g1, %g7 |
| 113 | cmp %g1, %g7 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 114 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 115 | nop |
Mikulas Patocka | 6ec2747 | 2010-08-18 08:03:37 +0000 | [diff] [blame] | 116 | retl |
| 117 | add %g1, %o0, %o0 |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 118 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | .size atomic64_add_ret, .-atomic64_add_ret |
| 120 | |
| 121 | .globl atomic64_sub_ret |
| 122 | .type atomic64_sub_ret,#function |
| 123 | atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 124 | BACKOFF_SETUP(%o2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | 1: ldx [%o1], %g1 |
| 126 | sub %g1, %o0, %g7 |
| 127 | casx [%o1], %g1, %g7 |
| 128 | cmp %g1, %g7 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 129 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 130 | nop |
Mikulas Patocka | 6ec2747 | 2010-08-18 08:03:37 +0000 | [diff] [blame] | 131 | retl |
| 132 | sub %g1, %o0, %o0 |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 133 | 2: BACKOFF_SPIN(%o2, %o3, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | .size atomic64_sub_ret, .-atomic64_sub_ret |