OSDN Git Service

d181fb3fad53b32f03da726f973626c1c96fd8ed
[pf3gnuchains/gcc-fork.git] / gcc / config / sh / linux-atomic.asm
1 /* Copyright (C) 2006 Free Software Foundation, Inc.
2
3    This file is part of GCC.
4
5    GCC is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2, or (at your option)
8    any later version.
9
10    GCC is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with GCC; see the file COPYING.  If not, write to
17    the Free Software Foundation, 51 Franklin Street, Fifth Floor,
18    Boston, MA 02110-1301, USA.  */
19
20 /* As a special exception, if you link this library with other files,
21    some of which are compiled with GCC, to produce an executable,
22    this library does not by itself cause the resulting executable
23    to be covered by the GNU General Public License.
24    This exception does not however invalidate any other reasons why
25    the executable file might be covered by the GNU General Public License.  */
26
27 !! Linux specific atomic routines for the Renesas / SuperH SH CPUs.
28 !! Linux kernel for SH3/4 has implemented the support for software
29 !! atomic sequences.
30
31 #define FUNC(X)         .type X,@function
32 #define HIDDEN_FUNC(X)  FUNC(X); .hidden X
33 #define ENDFUNC0(X)     .Lfe_##X: .size X,.Lfe_##X-X
34 #define ENDFUNC(X)      ENDFUNC0(X)
35
36 #if ! __SH5__
37
38 #define ATOMIC_TEST_AND_SET(N,T) \
39         .global __sync_lock_test_and_set_##N; \
40         HIDDEN_FUNC(__sync_lock_test_and_set_##N); \
41         .align  2; \
42 __sync_lock_test_and_set_##N:; \
43         mova    1f, r0; \
44         nop; \
45         mov     r15, r1; \
46         mov     #(0f-1f), r15; \
47 0:      mov.##T @r4, r2; \
48         mov.##T r5, @r4; \
49 1:      mov     r1, r15; \
50         rts; \
51          mov    r2, r0; \
52         ENDFUNC(__sync_lock_test_and_set_##N)
53
54 ATOMIC_TEST_AND_SET (1,b)
55 ATOMIC_TEST_AND_SET (2,w)
56 ATOMIC_TEST_AND_SET (4,l)
57
58 #define ATOMIC_COMPARE_AND_SWAP(N,T) \
59         .global __sync_compare_and_swap_##N; \
60         HIDDEN_FUNC(__sync_compare_and_swap_##N); \
61         .align  2; \
62 __sync_compare_and_swap_##N:; \
63         mova    1f, r0; \
64         nop; \
65         mov     r15, r1; \
66         mov     #(0f-1f), r15; \
67 0:      mov.##T @r4, r2; \
68         cmp/eq  r2, r5; \
69         bf      1f; \
70         mov.##T r6, @r4; \
71 1:      mov     r1, r15; \
72         rts; \
73          mov    r2, r0; \
74         ENDFUNC(__sync_compare_and_swap_##N)
75
76 ATOMIC_COMPARE_AND_SWAP (1,b)
77 ATOMIC_COMPARE_AND_SWAP (2,w)
78 ATOMIC_COMPARE_AND_SWAP (4,l)
79
80 #define ATOMIC_FETCH_AND_OP(OP,N,T) \
81         .global __sync_fetch_and_##OP##_##N; \
82         HIDDEN_FUNC(__sync_fetch_and_##OP##_##N); \
83         .align  2; \
84 __sync_fetch_and_##OP##_##N:; \
85         mova    1f, r0; \
86         mov     r15, r1; \
87         mov     #(0f-1f), r15; \
88 0:      mov.##T @r4, r2; \
89         OP      r2, r5; \
90         mov.##T r5, @r4; \
91 1:      mov     r1, r15; \
92         rts; \
93          mov    r2, r0; \
94         ENDFUNC(__sync_fetch_and_##OP##_##N)
95
96 ATOMIC_FETCH_AND_OP(add,1,b)
97 ATOMIC_FETCH_AND_OP(add,2,w)
98 ATOMIC_FETCH_AND_OP(add,4,l)
99
100 ATOMIC_FETCH_AND_OP(or,1,b)
101 ATOMIC_FETCH_AND_OP(or,2,w)
102 ATOMIC_FETCH_AND_OP(or,4,l)
103
104 ATOMIC_FETCH_AND_OP(and,1,b)
105 ATOMIC_FETCH_AND_OP(and,2,w)
106 ATOMIC_FETCH_AND_OP(and,4,l)
107
108 ATOMIC_FETCH_AND_OP(xor,1,b)
109 ATOMIC_FETCH_AND_OP(xor,2,w)
110 ATOMIC_FETCH_AND_OP(xor,4,l)
111
112 #define ATOMIC_FETCH_AND_COMBOP(OP,OP0,OP1,N,T) \
113         .global __sync_fetch_and_##OP##_##N; \
114         HIDDEN_FUNC(__sync_fetch_and_##OP##_##N); \
115         .align  2; \
116 __sync_fetch_and_##OP##_##N:; \
117         mova    1f, r0; \
118         nop; \
119         mov     r15, r1; \
120         mov     #(0f-1f), r15; \
121 0:      mov.##T @r4, r2; \
122         OP0     r2, r5; \
123         OP1     r5, r5; \
124         mov.##T r5, @r4; \
125 1:      mov     r1, r15; \
126         rts; \
127          mov    r2, r0; \
128         ENDFUNC(__sync_fetch_and_##OP##_##N)
129
130 ATOMIC_FETCH_AND_COMBOP(sub,sub,neg,1,b)
131 ATOMIC_FETCH_AND_COMBOP(sub,sub,neg,2,w)
132 ATOMIC_FETCH_AND_COMBOP(sub,sub,neg,4,l)
133
134 ATOMIC_FETCH_AND_COMBOP(nand,and,not,1,b)
135 ATOMIC_FETCH_AND_COMBOP(nand,and,not,2,w)
136 ATOMIC_FETCH_AND_COMBOP(nand,and,not,4,l)
137
138 #endif /* ! __SH5__ */