1 /* Copyright (C) 2006 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) \
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)
55 ATOMIC_TEST_AND_SET (2,w)
56 ATOMIC_TEST_AND_SET (4,l)
58 #define ATOMIC_COMPARE_AND_SWAP(N,T) \
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)
77 ATOMIC_COMPARE_AND_SWAP (2,w)
78 ATOMIC_COMPARE_AND_SWAP (4,l)
80 #define ATOMIC_FETCH_AND_OP(OP,N,T) \
81 .global __sync_fetch_and_##OP##_##N; \
82 HIDDEN_FUNC(__sync_fetch_and_##OP##_##N); \
84 __sync_fetch_and_##OP##_##N:; \
94 ENDFUNC(__sync_fetch_and_##OP##_##N)
96 ATOMIC_FETCH_AND_OP(add,1,b)
97 ATOMIC_FETCH_AND_OP(add,2,w)
98 ATOMIC_FETCH_AND_OP(add,4,l)
100 ATOMIC_FETCH_AND_OP(or,1,b)
101 ATOMIC_FETCH_AND_OP(or,2,w)
102 ATOMIC_FETCH_AND_OP(or,4,l)
104 ATOMIC_FETCH_AND_OP(and,1,b)
105 ATOMIC_FETCH_AND_OP(and,2,w)
106 ATOMIC_FETCH_AND_OP(and,4,l)
108 ATOMIC_FETCH_AND_OP(xor,1,b)
109 ATOMIC_FETCH_AND_OP(xor,2,w)
110 ATOMIC_FETCH_AND_OP(xor,4,l)
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); \
116 __sync_fetch_and_##OP##_##N:; \
121 0: mov.##T @r4, r2; \
128 ENDFUNC(__sync_fetch_and_##OP##_##N)
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)
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)
138 #endif /* ! __SH5__ */