OSDN Git Service

* config/sh/linux-atomic.asm (ATOMIC_TEST_AND_SET): Take
[pf3gnuchains/gcc-fork.git] / gcc / config / sh / linux-atomic.asm
1 /* Copyright (C) 2006, 2008 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,EXT) \
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          EXT    r2, r0; \
52         ENDFUNC(__sync_lock_test_and_set_##N)
53
54 ATOMIC_TEST_AND_SET (1,b,extu.b)
55 ATOMIC_TEST_AND_SET (2,w,extu.w)
56 ATOMIC_TEST_AND_SET (4,l,mov)
57
58 #define ATOMIC_COMPARE_AND_SWAP(N,T,EXTS,EXT) \
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         EXTS    r5, r5; \
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          EXT    r2, r0; \
74         ENDFUNC(__sync_compare_and_swap_##N)
75
76 ATOMIC_COMPARE_AND_SWAP (1,b,exts.b,extu.b)
77 ATOMIC_COMPARE_AND_SWAP (2,w,exts.w,extu.w)
78 ATOMIC_COMPARE_AND_SWAP (4,l,mov,mov)
79
80 #define ATOMIC_FETCH_AND_OP(OP,N,T,EXT) \
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         nop; \
87         mov     r15, r1; \
88         mov     #(0f-1f), r15; \
89 0:      mov.##T @r4, r2; \
90         mov     r5, r3; \
91         OP      r2, r3; \
92         mov.##T r3, @r4; \
93 1:      mov     r1, r15; \
94         rts; \
95          EXT    r2, r0; \
96         ENDFUNC(__sync_fetch_and_##OP##_##N)
97
98 ATOMIC_FETCH_AND_OP(add,1,b,extu.b)
99 ATOMIC_FETCH_AND_OP(add,2,w,extu.w)
100 ATOMIC_FETCH_AND_OP(add,4,l,mov)
101
102 ATOMIC_FETCH_AND_OP(or,1,b,extu.b)
103 ATOMIC_FETCH_AND_OP(or,2,w,extu.w)
104 ATOMIC_FETCH_AND_OP(or,4,l,mov)
105
106 ATOMIC_FETCH_AND_OP(and,1,b,extu.b)
107 ATOMIC_FETCH_AND_OP(and,2,w,extu.w)
108 ATOMIC_FETCH_AND_OP(and,4,l,mov)
109
110 ATOMIC_FETCH_AND_OP(xor,1,b,extu.b)
111 ATOMIC_FETCH_AND_OP(xor,2,w,extu.w)
112 ATOMIC_FETCH_AND_OP(xor,4,l,mov)
113
114 #define ATOMIC_FETCH_AND_COMBOP(OP,OP0,OP1,N,T,EXT) \
115         .global __sync_fetch_and_##OP##_##N; \
116         HIDDEN_FUNC(__sync_fetch_and_##OP##_##N); \
117         .align  2; \
118 __sync_fetch_and_##OP##_##N:; \
119         mova    1f, r0; \
120         mov     r15, r1; \
121         mov     #(0f-1f), r15; \
122 0:      mov.##T @r4, r2; \
123         mov     r5, r3; \
124         OP0     r2, r3; \
125         OP1     r3, r3; \
126         mov.##T r3, @r4; \
127 1:      mov     r1, r15; \
128         rts; \
129          EXT    r2, r0; \
130         ENDFUNC(__sync_fetch_and_##OP##_##N)
131
132 ATOMIC_FETCH_AND_COMBOP(sub,sub,neg,1,b,extu.b)
133 ATOMIC_FETCH_AND_COMBOP(sub,sub,neg,2,w,extu.w)
134 ATOMIC_FETCH_AND_COMBOP(sub,sub,neg,4,l,mov)
135
136 ATOMIC_FETCH_AND_COMBOP(nand,and,not,1,b,extu.b)
137 ATOMIC_FETCH_AND_COMBOP(nand,and,not,2,w,extu.w)
138 ATOMIC_FETCH_AND_COMBOP(nand,and,not,4,l,mov)
139
140 #endif /* ! __SH5__ */