vserver 1.9.3
[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         .type   ___test_and_set_bit,#function
13 ___test_and_set_bit:    /* %o0=nr, %o1=addr */
14         srlx    %o0, 6, %g1
15         mov     1, %g5
16         sllx    %g1, 3, %g3
17         and     %o0, 63, %g2
18         sllx    %g5, %g2, %g5
19         add     %o1, %g3, %o1
20         ldx     [%o1], %g7
21 1:      andcc   %g7, %g5, %o0
22         bne,pn  %xcc, 2f
23          xor    %g7, %g5, %g1
24         casx    [%o1], %g7, %g1
25         cmp     %g7, %g1
26         bne,a,pn %xcc, 1b
27          ldx    [%o1], %g7
28 2:      retl
29          membar #StoreLoad | #StoreStore
30         .size   ___test_and_set_bit, .-___test_and_set_bit
31
32         .globl  ___test_and_clear_bit
33         .type   ___test_and_clear_bit,#function
34 ___test_and_clear_bit:  /* %o0=nr, %o1=addr */
35         srlx    %o0, 6, %g1
36         mov     1, %g5
37         sllx    %g1, 3, %g3
38         and     %o0, 63, %g2
39         sllx    %g5, %g2, %g5
40         add     %o1, %g3, %o1
41         ldx     [%o1], %g7
42 1:      andcc   %g7, %g5, %o0
43         be,pn   %xcc, 2f
44          xor    %g7, %g5, %g1
45         casx    [%o1], %g7, %g1
46         cmp     %g7, %g1
47         bne,a,pn %xcc, 1b
48          ldx    [%o1], %g7
49 2:      retl
50          membar #StoreLoad | #StoreStore
51         .size   ___test_and_clear_bit, .-___test_and_clear_bit
52
53         .globl  ___test_and_change_bit
54         .type   ___test_and_change_bit,#function
55 ___test_and_change_bit: /* %o0=nr, %o1=addr */
56         srlx    %o0, 6, %g1
57         mov     1, %g5
58         sllx    %g1, 3, %g3
59         and     %o0, 63, %g2
60         sllx    %g5, %g2, %g5
61         add     %o1, %g3, %o1
62         ldx     [%o1], %g7
63 1:      and     %g7, %g5, %o0
64         xor     %g7, %g5, %g1
65         casx    [%o1], %g7, %g1
66         cmp     %g7, %g1
67         bne,a,pn %xcc, 1b
68          ldx    [%o1], %g7
69 2:      retl
70          membar #StoreLoad | #StoreStore
71         nop
72         .size   ___test_and_change_bit, .-___test_and_change_bit