1 /* Copyright (C) 2006, 2008 Free Software Foundation, Inc.
3 This file is part of GCC.
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)
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.
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. */
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. */
27 !! Linux specific atomic routines for the Renesas / SuperH SH CPUs.
28 !! Linux kernel for SH3/4 has implemented the support for software
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)
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); \
42 __sync_lock_test_and_set_##N:; \
52 ENDFUNC(__sync_lock_test_and_set_##N)
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)
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); \
62 __sync_compare_and_swap_##N:; \
74 ENDFUNC(__sync_compare_and_swap_##N)
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)
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); \
84 __sync_fetch_and_##OP##_##N:; \
96 ENDFUNC(__sync_fetch_and_##OP##_##N)
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)
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)
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)
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)
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); \
118 __sync_fetch_and_##OP##_##N:; \
122 0: mov.##T @r4, r2; \
130 ENDFUNC(__sync_fetch_and_##OP##_##N)
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)
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)
140 #endif /* ! __SH5__ */