1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
;; GCC machine description for ARC atomic instructions.
;; Copyright (C) 2015 Free Software Foundation, Inc.
;;
;; This file is part of GCC.
;;
;; GCC is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; GCC is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GCC; see the file COPYING3. If not see
;; <http://www.gnu.org/licenses/>.
(define_mode_iterator QHSI [QI HI SI])
(define_code_iterator atomicop [plus minus ior xor and])
(define_code_attr atomic_optab
[(ior "or") (xor "xor") (and "and") (plus "add") (minus "sub")])
(define_expand "memory_barrier"
[(set (match_dup 0)
(unspec:BLK [(match_dup 0)] UNSPEC_ARC_MEMBAR))]
""
{
operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
MEM_VOLATILE_P (operands[0]) = 1;
})
;; A compiler-only memory barrier for ARC700. Generic code, when
;; checking for the existence of various named patterns, uses
;; asm("":::"memory") when we don't need an actual instruction. For
;; ARCHS, we use a hardware data memory barrier that waits for
;; completion of current data memory operations before initiating
;; similar data memory operations.
(define_insn "*memory_barrier"
[(set (match_operand:BLK 0 "" "")
(unspec:BLK [(match_dup 0)] UNSPEC_ARC_MEMBAR))]
""
{
if (TARGET_HS)
{
return "dmb";
}
else
{
return "";
}
}
[(set_attr "type" "multi")
(set_attr "length" "4")])
(define_expand "atomic_compare_and_swap<mode>"
[(match_operand:SI 0 "register_operand" "") ;; bool out
(match_operand:QHSI 1 "register_operand" "") ;; val out
(match_operand:QHSI 2 "mem_noofs_operand" "");; memory
(match_operand:QHSI 3 "register_operand" "") ;; expected
(match_operand:QHSI 4 "register_operand" "") ;; desired
(match_operand:SI 5 "const_int_operand") ;; is_weak
(match_operand:SI 6 "const_int_operand") ;; mod_s
(match_operand:SI 7 "const_int_operand")] ;; mod_f
"TARGET_ATOMIC"
{
arc_expand_compare_and_swap (operands);
DONE;
})
(define_insn_and_split "atomic_compare_and_swapsi_1"
[(set (reg:CC_Z CC_REG) ;; bool out
(unspec_volatile:CC_Z [(const_int 0)] VUNSPEC_ARC_CAS))
(set (match_operand:SI 0 "register_operand" "=&r") ;; val out
(match_operand:SI 1 "mem_noofs_operand" "+ATO")) ;; memory
(set (match_dup 1)
(unspec_volatile:SI
[(match_operand:SI 2 "register_operand" "r") ;; expect
(match_operand:SI 3 "register_operand" "r") ;; desired
(match_operand:SI 4 "const_int_operand") ;; is_weak
(match_operand:SI 5 "const_int_operand") ;; mod_s
(match_operand:SI 6 "const_int_operand")] ;; mod_f
VUNSPEC_ARC_CAS))]
"TARGET_ATOMIC"
"#"
"&& reload_completed"
[(const_int 0)]
{
arc_split_compare_and_swap (operands);
DONE;
})
(define_insn "arc_load_exclusivesi"
[(set (match_operand:SI 0 "register_operand" "=r")
(unspec_volatile:SI
[(match_operand:SI 1 "mem_noofs_operand" "ATO")]
VUNSPEC_ARC_LL))]
"TARGET_ATOMIC"
"llock %0,%1"
[(set_attr "type" "load")
(set_attr "iscompact" "false")
(set_attr "predicable" "no")
(set_attr "length" "*")])
(define_insn "arc_store_exclusivesi"
[(set (match_operand:SI 0 "mem_noofs_operand" "=ATO")
(unspec_volatile:SI[(match_operand:SI 1 "register_operand" "r")]
VUNSPEC_ARC_SC))
(clobber (reg:CC_Z CC_REG))]
"TARGET_ATOMIC"
"scond %1,%0"
[(set_attr "type" "store")
(set_attr "iscompact" "false")
(set_attr "predicable" "no")
(set_attr "length" "*")])
(define_expand "atomic_exchangesi"
[(match_operand:SI 0 "register_operand" "")
(match_operand:SI 1 "mem_noofs_operand" "")
(match_operand:SI 2 "register_operand" "")
(match_operand:SI 3 "const_int_operand" "")]
"TARGET_ATOMIC"
{
enum memmodel model = (enum memmodel) INTVAL (operands[3]);
if (model == MEMMODEL_SEQ_CST)
emit_insn (gen_sync (const1_rtx));
emit_insn (gen_exchangesi (operands[0], operands[1], operands[2]));
DONE;
})
(define_insn "exchangesi"
[(set (match_operand:SI 0 "register_operand" "=r")
(unspec_volatile:SI [(match_operand:SI 1 "mem_noofs_operand" "+ATO")]
VUNSPEC_ARC_EX))
(set (match_dup 1)
(match_operand:SI 2 "register_operand" "0"))]
""
"ex %0,%1"
[(set_attr "type" "load")
(set_attr "iscompact" "false")
(set_attr "predicable" "no")
(set_attr "length" "*")])
(define_expand "atomic_<atomic_optab>si"
[(match_operand:SI 0 "mem_noofs_operand" "") ;; memory
(atomicop:SI (match_dup 0)
(match_operand:SI 1 "register_operand" "")) ;; operand
(match_operand:SI 2 "const_int_operand" "")] ;; model
"TARGET_ATOMIC"
{
arc_expand_atomic_op (<CODE>, operands[0], operands[1],
NULL_RTX, NULL_RTX, operands[2]);
DONE;
})
(define_expand "atomic_nandsi"
[(match_operand:SI 0 "mem_noofs_operand" "") ;; memory
(match_operand:SI 1 "register_operand" "") ;; operand
(match_operand:SI 2 "const_int_operand" "")] ;; model
"TARGET_ATOMIC"
{
arc_expand_atomic_op (NOT, operands[0], operands[1],
NULL_RTX, NULL_RTX, operands[2]);
DONE;
})
(define_expand "atomic_fetch_<atomic_optab>si"
[(match_operand:SI 0 "register_operand" "") ;; output
(match_operand:SI 1 "mem_noofs_operand" "") ;; memory
(atomicop:SI (match_dup 1)
(match_operand:SI 2 "register_operand" "")) ;; operand
(match_operand:SI 3 "const_int_operand" "")] ;; model
"TARGET_ATOMIC"
{
arc_expand_atomic_op (<CODE>, operands[1], operands[2],
operands[0], NULL_RTX, operands[3]);
DONE;
})
(define_expand "atomic_fetch_nandsi"
[(match_operand:SI 0 "register_operand" "") ;; output
(match_operand:SI 1 "mem_noofs_operand" "") ;; memory
(match_operand:SI 2 "register_operand" "") ;; operand
(match_operand:SI 3 "const_int_operand" "")] ;; model
"TARGET_ATOMIC"
{
arc_expand_atomic_op (NOT, operands[1], operands[2],
operands[0], NULL_RTX, operands[3]);
DONE;
})
(define_expand "atomic_<atomic_optab>_fetchsi"
[(match_operand:SI 0 "register_operand" "") ;; output
(match_operand:SI 1 "mem_noofs_operand" "") ;; memory
(atomicop:SI (match_dup 1)
(match_operand:SI 2 "register_operand" "")) ;; operand
(match_operand:SI 3 "const_int_operand" "")] ;; model
"TARGET_ATOMIC"
{
arc_expand_atomic_op (<CODE>, operands[1], operands[2],
NULL_RTX, operands[0], operands[3]);
DONE;
})
(define_expand "atomic_nand_fetchsi"
[(match_operand:SI 0 "register_operand" "") ;; output
(match_operand:SI 1 "mem_noofs_operand" "") ;; memory
(match_operand:SI 2 "register_operand" "") ;; operand
(match_operand:SI 3 "const_int_operand" "")] ;; model
"TARGET_ATOMIC"
{
arc_expand_atomic_op (NOT, operands[1], operands[2],
NULL_RTX, operands[0], operands[3]);
DONE;
})
|