David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 1 | /* bitops.S: Sparc64 atomic bit operations. |
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) 2000, 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 | |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 9 | .text |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | .globl test_and_set_bit |
| 12 | .type test_and_set_bit,#function |
| 13 | test_and_set_bit: /* %o0=nr, %o1=addr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 14 | BACKOFF_SETUP(%o3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | srlx %o0, 6, %g1 |
| 16 | mov 1, %o2 |
| 17 | sllx %g1, 3, %g3 |
| 18 | and %o0, 63, %g2 |
| 19 | sllx %o2, %g2, %o2 |
| 20 | add %o1, %g3, %o1 |
| 21 | 1: ldx [%o1], %g7 |
| 22 | or %g7, %o2, %g1 |
| 23 | casx [%o1], %g7, %g1 |
| 24 | cmp %g7, %g1 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 25 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | and %g7, %o2, %g2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | clr %o0 |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 28 | movrne %g2, 1, %o0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | retl |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 30 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 31 | 2: BACKOFF_SPIN(%o3, %o4, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | .size test_and_set_bit, .-test_and_set_bit |
| 33 | |
| 34 | .globl test_and_clear_bit |
| 35 | .type test_and_clear_bit,#function |
| 36 | test_and_clear_bit: /* %o0=nr, %o1=addr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 37 | BACKOFF_SETUP(%o3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | srlx %o0, 6, %g1 |
| 39 | mov 1, %o2 |
| 40 | sllx %g1, 3, %g3 |
| 41 | and %o0, 63, %g2 |
| 42 | sllx %o2, %g2, %o2 |
| 43 | add %o1, %g3, %o1 |
| 44 | 1: ldx [%o1], %g7 |
| 45 | andn %g7, %o2, %g1 |
| 46 | casx [%o1], %g7, %g1 |
| 47 | cmp %g7, %g1 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 48 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | and %g7, %o2, %g2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | clr %o0 |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 51 | movrne %g2, 1, %o0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | retl |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 53 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 54 | 2: BACKOFF_SPIN(%o3, %o4, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | .size test_and_clear_bit, .-test_and_clear_bit |
| 56 | |
| 57 | .globl test_and_change_bit |
| 58 | .type test_and_change_bit,#function |
| 59 | test_and_change_bit: /* %o0=nr, %o1=addr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 60 | BACKOFF_SETUP(%o3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | srlx %o0, 6, %g1 |
| 62 | mov 1, %o2 |
| 63 | sllx %g1, 3, %g3 |
| 64 | and %o0, 63, %g2 |
| 65 | sllx %o2, %g2, %o2 |
| 66 | add %o1, %g3, %o1 |
| 67 | 1: ldx [%o1], %g7 |
| 68 | xor %g7, %o2, %g1 |
| 69 | casx [%o1], %g7, %g1 |
| 70 | cmp %g7, %g1 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 71 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | and %g7, %o2, %g2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | clr %o0 |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 74 | movrne %g2, 1, %o0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | retl |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 76 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 77 | 2: BACKOFF_SPIN(%o3, %o4, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | .size test_and_change_bit, .-test_and_change_bit |
| 79 | |
| 80 | .globl set_bit |
| 81 | .type set_bit,#function |
| 82 | set_bit: /* %o0=nr, %o1=addr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 83 | BACKOFF_SETUP(%o3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | srlx %o0, 6, %g1 |
| 85 | mov 1, %o2 |
| 86 | sllx %g1, 3, %g3 |
| 87 | and %o0, 63, %g2 |
| 88 | sllx %o2, %g2, %o2 |
| 89 | add %o1, %g3, %o1 |
| 90 | 1: ldx [%o1], %g7 |
| 91 | or %g7, %o2, %g1 |
| 92 | casx [%o1], %g7, %g1 |
| 93 | cmp %g7, %g1 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 94 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | nop |
| 96 | retl |
| 97 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 98 | 2: BACKOFF_SPIN(%o3, %o4, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | .size set_bit, .-set_bit |
| 100 | |
| 101 | .globl clear_bit |
| 102 | .type clear_bit,#function |
| 103 | clear_bit: /* %o0=nr, %o1=addr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 104 | BACKOFF_SETUP(%o3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | srlx %o0, 6, %g1 |
| 106 | mov 1, %o2 |
| 107 | sllx %g1, 3, %g3 |
| 108 | and %o0, 63, %g2 |
| 109 | sllx %o2, %g2, %o2 |
| 110 | add %o1, %g3, %o1 |
| 111 | 1: ldx [%o1], %g7 |
| 112 | andn %g7, %o2, %g1 |
| 113 | casx [%o1], %g7, %g1 |
| 114 | cmp %g7, %g1 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 115 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | nop |
| 117 | retl |
| 118 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 119 | 2: BACKOFF_SPIN(%o3, %o4, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | .size clear_bit, .-clear_bit |
| 121 | |
| 122 | .globl change_bit |
| 123 | .type change_bit,#function |
| 124 | change_bit: /* %o0=nr, %o1=addr */ |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 125 | BACKOFF_SETUP(%o3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | srlx %o0, 6, %g1 |
| 127 | mov 1, %o2 |
| 128 | sllx %g1, 3, %g3 |
| 129 | and %o0, 63, %g2 |
| 130 | sllx %o2, %g2, %o2 |
| 131 | add %o1, %g3, %o1 |
| 132 | 1: ldx [%o1], %g7 |
| 133 | xor %g7, %o2, %g1 |
| 134 | casx [%o1], %g7, %g1 |
| 135 | cmp %g7, %g1 |
David S. Miller | 0f58189 | 2010-08-18 22:53:26 -0700 | [diff] [blame] | 136 | bne,pn %xcc, BACKOFF_LABEL(2f, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | nop |
| 138 | retl |
| 139 | nop |
David S. Miller | 24f287e | 2007-10-15 16:41:44 -0700 | [diff] [blame] | 140 | 2: BACKOFF_SPIN(%o3, %o4, 1b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | .size change_bit, .-change_bit |