VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / arch / sparc64 / lib / bitops.S
1 /* $Id: bitops.S,v 1.3 2001/11/18 00:12:56 davem Exp $
2  * bitops.S: Sparc64 atomic bit operations.
3  *
4  * Copyright (C) 2000 David S. Miller (davem@redhat.com)
5  */
6
7 #include <asm/asi.h>
8
9         .text
10         .align  64
11         .globl  ___test_and_set_bit
12 ___test_and_set_bit:    /* %o0=nr, %o1=addr */
13         srlx    %o0, 6, %g1
14         mov     1, %g5
15         sllx    %g1, 3, %g3
16         and     %o0, 63, %g2
17         sllx    %g5, %g2, %g5
18         add     %o1, %g3, %o1
19         ldx     [%o1], %g7
20 1:      andcc   %g7, %g5, %o0
21         bne,pn  %xcc, 2f
22          xor    %g7, %g5, %g1
23         casx    [%o1], %g7, %g1
24         cmp     %g7, %g1
25         bne,a,pn %xcc, 1b
26          ldx    [%o1], %g7
27 2:      retl
28          membar #StoreLoad | #StoreStore
29
30         .globl  ___test_and_clear_bit
31 ___test_and_clear_bit:  /* %o0=nr, %o1=addr */
32         srlx    %o0, 6, %g1
33         mov     1, %g5
34         sllx    %g1, 3, %g3
35         and     %o0, 63, %g2
36         sllx    %g5, %g2, %g5
37         add     %o1, %g3, %o1
38         ldx     [%o1], %g7
39 1:      andcc   %g7, %g5, %o0
40         be,pn   %xcc, 2f
41          xor    %g7, %g5, %g1
42         casx    [%o1], %g7, %g1
43         cmp     %g7, %g1
44         bne,a,pn %xcc, 1b
45          ldx    [%o1], %g7
46 2:      retl
47          membar #StoreLoad | #StoreStore
48
49         .globl  ___test_and_change_bit
50 ___test_and_change_bit: /* %o0=nr, %o1=addr */
51         srlx    %o0, 6, %g1
52         mov     1, %g5
53         sllx    %g1, 3, %g3
54         and     %o0, 63, %g2
55         sllx    %g5, %g2, %g5
56         add     %o1, %g3, %o1
57         ldx     [%o1], %g7
58 1:      and     %g7, %g5, %o0
59         xor     %g7, %g5, %g1
60         casx    [%o1], %g7, %g1
61         cmp     %g7, %g1
62         bne,a,pn %xcc, 1b
63          ldx    [%o1], %g7
64 2:      retl
65          membar #StoreLoad | #StoreStore
66         nop
67
68         .globl  ___test_and_set_le_bit
69 ___test_and_set_le_bit: /* %o0=nr, %o1=addr */
70         srlx    %o0, 5, %g1
71         mov     1, %g5
72         sllx    %g1, 2, %g3
73         and     %o0, 31, %g2
74         sllx    %g5, %g2, %g5
75         add     %o1, %g3, %o1
76         lduwa   [%o1] ASI_PL, %g7
77 1:      andcc   %g7, %g5, %o0
78         bne,pn  %icc, 2f
79          xor    %g7, %g5, %g1
80         casa    [%o1] ASI_PL, %g7, %g1
81         cmp     %g7, %g1
82         bne,a,pn %icc, 1b
83          lduwa  [%o1] ASI_PL, %g7
84 2:      retl
85          membar #StoreLoad | #StoreStore
86
87         .globl  ___test_and_clear_le_bit
88 ___test_and_clear_le_bit:       /* %o0=nr, %o1=addr */
89         srlx    %o0, 5, %g1
90         mov     1, %g5
91         sllx    %g1, 2, %g3
92         and     %o0, 31, %g2
93         sllx    %g5, %g2, %g5
94         add     %o1, %g3, %o1
95         lduwa   [%o1] ASI_PL, %g7
96 1:      andcc   %g7, %g5, %o0
97         be,pn   %icc, 2f
98          xor    %g7, %g5, %g1
99         casa    [%o1] ASI_PL, %g7, %g1
100         cmp     %g7, %g1
101         bne,a,pn %icc, 1b
102          lduwa  [%o1] ASI_PL, %g7
103 2:      retl
104          membar #StoreLoad | #StoreStore