Debian Codegraph @

gcc/config/arm/sync.md

raw
1 ;; Machine description for ARM processor synchronization primitives.
2 ;; Copyright (C) 2010-2025 Free Software Foundation, Inc.
3 ;; Written by Marcus Shawcroft ([email protected])
4 ;; 64bit Atomics by Dave Gilbert ([email protected])
5 ;;
6 ;; This file is part of GCC.
7 ;;
8 ;; GCC is free software; you can redistribute it and/or modify it
9 ;; under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 3, or (at your option)
11 ;; any later version.
12 ;;
13 ;; GCC is distributed in the hope that it will be useful, but
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ;; General Public License for more details.
17 ;;
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING3. If not see
20 ;; <http://www.gnu.org/licenses/>. */
21
22 (define_mode_attr sync_predtab
23 [(QI "TARGET_HAVE_LDREXBH && TARGET_HAVE_MEMORY_BARRIER")
24 (HI "TARGET_HAVE_LDREXBH && TARGET_HAVE_MEMORY_BARRIER")
25 (SI "TARGET_HAVE_LDREX && TARGET_HAVE_MEMORY_BARRIER")
26 (DI "TARGET_HAVE_LDREXD && ARM_DOUBLEWORD_ALIGN
27 && TARGET_HAVE_MEMORY_BARRIER")])
28
29 (define_code_iterator syncop [plus minus ior xor and])
30
31 (define_code_attr sync_optab
32 [(ior "or") (xor "xor") (and "and") (plus "add") (minus "sub")])
33
34 (define_mode_attr sync_sfx
35 [(QI "b") (HI "h") (SI "") (DI "d")])
36
37 (define_expand "memory_barrier"
38 [(set (match_dup 0)
39 (unspec:BLK [(match_dup 0)] UNSPEC_MEMORY_BARRIER))]
40 "TARGET_HAVE_MEMORY_BARRIER"
41 {
42 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
43 MEM_VOLATILE_P (operands[0]) = 1;
44 })
45
46 (define_insn "*memory_barrier"
47 [(set (match_operand:BLK 0 "" "")
48 (unspec:BLK [(match_dup 0)] UNSPEC_MEMORY_BARRIER))]
49 "TARGET_HAVE_MEMORY_BARRIER"
50 {
51 if (TARGET_HAVE_DMB)
52 {
53 return "dmb\\tish";
54 }
55
56 if (TARGET_HAVE_DMB_MCR)
57 return "mcr\\tp15, 0, r0, c7, c10, 5";
58
59 gcc_unreachable ();
60 }
61 [(set_attr "length" "4")
62 (set_attr "conds" "unconditional")
63 (set_attr "predicable" "no")])
64
65 (define_insn "arm_atomic_load<mode>"
66 [(set (match_operand:QHSI 0 "register_operand" "=r,l")
67 (unspec_volatile:QHSI
68 [(match_operand:QHSI 1 "mem_and_no_t1_wback_op" "m,Uw")]
69 VUNSPEC_LDR))]
70 ""
71 "ldr<sync_sfx>\t%0, %1"
72 [(set_attr "arch" "32,any")])
73
74 (define_insn "arm_atomic_load_acquire<mode>"
75 [(set (match_operand:QHSI 0 "register_operand" "=r")
76 (unspec_volatile:QHSI
77 [(match_operand:QHSI 1 "arm_sync_memory_operand" "Q")]
78 VUNSPEC_LDA))]
79 "TARGET_HAVE_LDACQ"
80 "lda<sync_sfx>\t%0, %C1"
81 )
82
83 (define_insn "arm_atomic_store<mode>"
84 [(set (match_operand:QHSI 0 "mem_and_no_t1_wback_op" "=m,Uw")
85 (unspec_volatile:QHSI
86 [(match_operand:QHSI 1 "register_operand" "r,l")]
87 VUNSPEC_STR))]
88 ""
89 "str<sync_sfx>\t%1, %0";
90 [(set_attr "arch" "32,any")])
91
92 (define_insn "arm_atomic_store_release<mode>"
93 [(set (match_operand:QHSI 0 "arm_sync_memory_operand" "=Q")
94 (unspec_volatile:QHSI
95 [(match_operand:QHSI 1 "register_operand" "r")]
96 VUNSPEC_STL))]
97 "TARGET_HAVE_LDACQ"
98 "stl<sync_sfx>\t%1, %C0")
99
100
101 (define_expand "atomic_load<mode>"
102 [(match_operand:QHSI 0 "register_operand") ;; val out
103 (match_operand:QHSI 1 "arm_sync_memory_operand") ;; memory
104 (match_operand:SI 2 "const_int_operand")] ;; model
105 ""
106 {
107 memmodel model = memmodel_from_int (INTVAL (operands[2]));
108
109 if (TARGET_HAVE_LDACQ && !is_mm_relaxed (model))
110 {
111 emit_insn (gen_arm_atomic_load_acquire<mode> (operands[0], operands[1]));
112 DONE;
113 }
114
115 /* The seq_cst model needs a barrier before the load to block reordering with
116 earlier accesses. */
117 if (is_mm_seq_cst (model))
118 expand_mem_thread_fence (model);
119
120 emit_insn (gen_arm_atomic_load<mode> (operands[0], operands[1]));
121
122 /* All non-relaxed models need a barrier after the load when load-acquire
123 instructions are not available. */
124 if (!is_mm_relaxed (model))
125 expand_mem_thread_fence (model);
126
127 DONE;
128 })
129
130 (define_expand "atomic_store<mode>"
131 [(match_operand:QHSI 0 "arm_sync_memory_operand") ;; memory
132 (match_operand:QHSI 1 "register_operand") ;; store value
133 (match_operand:SI 2 "const_int_operand")] ;; model
134 ""
135 {
136 memmodel model = memmodel_from_int (INTVAL (operands[2]));
137
138 if (TARGET_HAVE_LDACQ && !is_mm_relaxed (model))
139 {
140 emit_insn (gen_arm_atomic_store_release<mode> (operands[0], operands[1]));
141 DONE;
142 }
143
144 /* All non-relaxed models need a barrier after the load when load-acquire
145 instructions are not available. */
146 if (!is_mm_relaxed (model))
147 expand_mem_thread_fence (model);
148
149 emit_insn (gen_arm_atomic_store<mode> (operands[0], operands[1]));
150
151 /* The seq_cst model needs a barrier after the store to block reordering with
152 later accesses. */
153 if (is_mm_seq_cst (model))
154 expand_mem_thread_fence (model);
155
156 DONE;
157 })
158
159 ;; An LDRD instruction usable by the atomic_loaddi expander on LPAE targets
160
161 (define_insn "arm_atomic_loaddi2_ldrd"
162 [(set (match_operand:DI 0 "register_operand" "=r")
163 (unspec_volatile:DI
164 [(match_operand:DI 1 "arm_ldrd_memory_operand" "Uo")]
165 VUNSPEC_LDRD_ATOMIC))]
166 "ARM_DOUBLEWORD_ALIGN && TARGET_HAVE_LPAE"
167 "ldrd\t%0, %H0, %1"
168 )
169
170 ;; There are three ways to expand this depending on the architecture
171 ;; features available. As for the barriers, a load needs a barrier
172 ;; after it on all non-relaxed memory models except when the load
173 ;; has acquire semantics (for ARMv8-A).
174
175 (define_expand "atomic_loaddi"
176 [(match_operand:DI 0 "s_register_operand") ;; val out
177 (match_operand:DI 1 "mem_noofs_operand") ;; memory
178 (match_operand:SI 2 "const_int_operand")] ;; model
179 "(TARGET_HAVE_LDREXD || TARGET_HAVE_LPAE || TARGET_HAVE_LDACQEXD)
180 && ARM_DOUBLEWORD_ALIGN"
181 {
182 memmodel model = memmodel_from_int (INTVAL (operands[2]));
183
184 /* For ARMv8-A we can use an LDAEXD to atomically load two 32-bit registers
185 when acquire or stronger semantics are needed. When the relaxed model is
186 used this can be relaxed to a normal LDRD. */
187 if (TARGET_HAVE_LDACQEXD)
188 {
189 if (is_mm_relaxed (model))
190 emit_insn (gen_arm_atomic_loaddi2_ldrd (operands[0], operands[1]));
191 else
192 emit_insn (gen_arm_load_acquire_exclusivedi (operands[0], operands[1]));
193
194 DONE;
195 }
196
197 /* The seq_cst model needs a barrier before the load to block reordering with
198 earlier accesses. */
199 if (is_mm_seq_cst (model))
200 expand_mem_thread_fence (model);
201
202 /* On LPAE targets LDRD and STRD accesses to 64-bit aligned
203 locations are 64-bit single-copy atomic. We still need barriers in the
204 appropriate places to implement the ordering constraints. */
205 if (TARGET_HAVE_LPAE)
206 emit_insn (gen_arm_atomic_loaddi2_ldrd (operands[0], operands[1]));
207 else
208 emit_insn (gen_arm_load_exclusivedi (operands[0], operands[1]));
209
210 /* All non-relaxed models need a barrier after the load when load-acquire
211 instructions are not available. */
212 if (!is_mm_relaxed (model))
213 expand_mem_thread_fence (model);
214
215 DONE;
216 })
217
218 (define_expand "atomic_compare_and_swap<mode>"
219 [(match_operand:SI 0 "s_register_operand") ;; bool out
220 (match_operand:QHSD 1 "s_register_operand") ;; val out
221 (match_operand:QHSD 2 "mem_noofs_operand") ;; memory
222 (match_operand:QHSD 3 "general_operand") ;; expected
223 (match_operand:QHSD 4 "s_register_operand") ;; desired
224 (match_operand:SI 5 "const_int_operand") ;; is_weak
225 (match_operand:SI 6 "const_int_operand") ;; mod_s
226 (match_operand:SI 7 "const_int_operand")] ;; mod_f
227 "<sync_predtab>"
228 {
229 arm_expand_compare_and_swap (operands);
230 DONE;
231 })
232
233 ;; Constraints of this pattern must be at least as strict as those of the
234 ;; cbranchsi operations in thumb1.md and aim to be as permissive.
235 (define_insn_and_split "@atomic_compare_and_swap<CCSI:arch><NARROW:mode>_1"
236 [(set (match_operand:CCSI 0 "cc_register_operand" "=&c,&l,&l") ;; bool out
237 (unspec_volatile:CCSI [(const_int 0)] VUNSPEC_ATOMIC_CAS))
238 (set (match_operand:SI 1 "s_register_operand" "=&r,&l,&l*h") ;; val out
239 (zero_extend:SI
240 (match_operand:NARROW 2 "mem_noofs_operand" "+Ua,Ua,Ua"))) ;; memory
241 (set (match_dup 2)
242 (unspec_volatile:NARROW
243 [(match_operand:SI 3 "arm_add_operand" "rIL,lILJ*h,*r") ;; expected
244 (match_operand:NARROW 4 "s_register_operand" "r,r,r") ;; desired
245 (match_operand:SI 5 "const_int_operand") ;; is_weak
246 (match_operand:SI 6 "const_int_operand") ;; mod_s
247 (match_operand:SI 7 "const_int_operand")] ;; mod_f
248 VUNSPEC_ATOMIC_CAS))
249 (clobber (match_scratch:SI 8 "=&r,X,X"))]
250 "<NARROW:sync_predtab>"
251 "#"
252 "&& reload_completed"
253 [(const_int 0)]
254 {
255 arm_split_compare_and_swap (operands);
256 DONE;
257 }
258 [(set_attr "arch" "32,v8mb,v8mb")])
259
260 (define_mode_attr cas_cmp_operand
261 [(SI "arm_add_operand") (DI "cmpdi_operand")])
262 (define_mode_attr cas_cmp_str
263 [(SI "rIL") (DI "rDi")])
264
265 ;; Constraints of this pattern must be at least as strict as those of the
266 ;; cbranchsi operations in thumb1.md and aim to be as permissive.
267 (define_insn_and_split "@atomic_compare_and_swap<CCSI:arch><SIDI:mode>_1"
268 [(set (match_operand:CCSI 0 "cc_register_operand" "=&c,&l,&l") ;; bool out
269 (unspec_volatile:CCSI [(const_int 0)] VUNSPEC_ATOMIC_CAS))
270 (set (match_operand:SIDI 1 "s_register_operand" "=&r,&l,&l*h") ;; val out
271 (match_operand:SIDI 2 "mem_noofs_operand" "+Ua,Ua,Ua")) ;; memory
272 (set (match_dup 2)
273 (unspec_volatile:SIDI
274 [(match_operand:SIDI 3 "<SIDI:cas_cmp_operand>" "<SIDI:cas_cmp_str>,lILJ*h,*r") ;; expect
275 (match_operand:SIDI 4 "s_register_operand" "r,r,r") ;; desired
276 (match_operand:SI 5 "const_int_operand") ;; is_weak
277 (match_operand:SI 6 "const_int_operand") ;; mod_s
278 (match_operand:SI 7 "const_int_operand")] ;; mod_f
279 VUNSPEC_ATOMIC_CAS))
280 (clobber (match_scratch:SI 8 "=&r,X,X"))]
281 "<SIDI:sync_predtab>"
282 "#"
283 "&& reload_completed"
284 [(const_int 0)]
285 {
286 arm_split_compare_and_swap (operands);
287 DONE;
288 }
289 [(set_attr "arch" "32,v8mb,v8mb")])
290
291 (define_insn_and_split "atomic_exchange<mode>"
292 [(set (match_operand:QHSD 0 "s_register_operand" "=&r,&r") ;; output
293 (match_operand:QHSD 1 "mem_noofs_operand" "+Ua,Ua")) ;; memory
294 (set (match_dup 1)
295 (unspec_volatile:QHSD
296 [(match_operand:QHSD 2 "s_register_operand" "r,r") ;; input
297 (match_operand:SI 3 "const_int_operand" "")] ;; model
298 VUNSPEC_ATOMIC_XCHG))
299 (clobber (reg:CC CC_REGNUM))
300 (clobber (match_scratch:SI 4 "=&r,&l"))]
301 "<sync_predtab>"
302 "#"
303 "&& reload_completed"
304 [(const_int 0)]
305 {
306 arm_split_atomic_op (SET, operands[0], NULL, operands[1],
307 operands[2], operands[3], operands[4]);
308 DONE;
309 }
310 [(set_attr "arch" "32,v8mb")])
311
312 ;; The following mode and code attribute are defined here because they are
313 ;; specific to atomics and are not needed anywhere else.
314
315 (define_mode_attr atomic_op_operand
316 [(QI "reg_or_int_operand")
317 (HI "reg_or_int_operand")
318 (SI "reg_or_int_operand")
319 (DI "s_register_operand")])
320
321 (define_mode_attr atomic_op_str
322 [(QI "rn") (HI "rn") (SI "rn") (DI "r")])
323
324 (define_code_attr thumb1_atomic_op_str
325 [(ior "l,l") (xor "l,l") (and "l,l") (plus "lIJL,r") (minus "lPd,lPd")])
326
327 (define_code_attr thumb1_atomic_newop_str
328 [(ior "&l,&l") (xor "&l,&l") (and "&l,&l") (plus "&l,&r") (minus "&l,&l")])
329
330 ;; Constraints of this pattern must be at least as strict as those of the non
331 ;; atomic operations in thumb1.md and aim to be as permissive.
332 (define_insn_and_split "atomic_<sync_optab><mode>"
333 [(set (match_operand:QHSD 0 "mem_noofs_operand" "+Ua,Ua,Ua")
334 (unspec_volatile:QHSD
335 [(syncop:QHSD (match_dup 0)
336 (match_operand:QHSD 1 "<atomic_op_operand>" "<atomic_op_str>,<thumb1_atomic_op_str>"))
337 (match_operand:SI 2 "const_int_operand")] ;; model
338 VUNSPEC_ATOMIC_OP))
339 (clobber (reg:CC CC_REGNUM))
340 (clobber (match_scratch:QHSD 3 "=&r,<thumb1_atomic_newop_str>"))
341 (clobber (match_scratch:SI 4 "=&r,&l,&l"))]
342 "<sync_predtab>"
343 "#"
344 "&& reload_completed"
345 [(const_int 0)]
346 {
347 arm_split_atomic_op (<CODE>, NULL, operands[3], operands[0],
348 operands[1], operands[2], operands[4]);
349 DONE;
350 }
351 [(set_attr "arch" "32,v8mb,v8mb")])
352
353 ;; Constraints of this pattern must be at least as strict as those of the non
354 ;; atomic NANDs in thumb1.md and aim to be as permissive.
355 (define_insn_and_split "atomic_nand<mode>"
356 [(set (match_operand:QHSD 0 "mem_noofs_operand" "+Ua,Ua")
357 (unspec_volatile:QHSD
358 [(not:QHSD
359 (and:QHSD (match_dup 0)
360 (match_operand:QHSD 1 "<atomic_op_operand>" "<atomic_op_str>,l")))
361 (match_operand:SI 2 "const_int_operand")] ;; model
362 VUNSPEC_ATOMIC_OP))
363 (clobber (reg:CC CC_REGNUM))
364 (clobber (match_scratch:QHSD 3 "=&r,&l"))
365 (clobber (match_scratch:SI 4 "=&r,&l"))]
366 "<sync_predtab>"
367 "#"
368 "&& reload_completed"
369 [(const_int 0)]
370 {
371 arm_split_atomic_op (NOT, NULL, operands[3], operands[0],
372 operands[1], operands[2], operands[4]);
373 DONE;
374 }
375 [(set_attr "arch" "32,v8mb")])
376
377 ;; 3 alternatives are needed to represent constraints after split from
378 ;; thumb1_addsi3: (i) case where operand1 and destination can be in different
379 ;; registers, (ii) case where they are in the same low register and (iii) case
380 ;; when they are in the same register without restriction on the register. We
381 ;; disparage slightly alternatives that require copying the old value into the
382 ;; register for the new value (see bind_old_new in arm_split_atomic_op).
383 (define_code_attr thumb1_atomic_fetch_op_str
384 [(ior "l,l,l") (xor "l,l,l") (and "l,l,l") (plus "lL,?IJ,?r") (minus "lPd,lPd,lPd")])
385
386 (define_code_attr thumb1_atomic_fetch_newop_str
387 [(ior "&l,&l,&l") (xor "&l,&l,&l") (and "&l,&l,&l") (plus "&l,&l,&r") (minus "&l,&l,&l")])
388
389 (define_code_attr thumb1_atomic_fetch_oldop_str
390 [(ior "&r,&r,&r") (xor "&r,&r,&r") (and "&r,&r,&r") (plus "&l,&r,&r") (minus "&l,&l,&l")])
391
392 ;; Constraints of this pattern must be at least as strict as those of the non
393 ;; atomic operations in thumb1.md and aim to be as permissive.
394 (define_insn_and_split "atomic_fetch_<sync_optab><mode>"
395 [(set (match_operand:QHSD 0 "s_register_operand" "=&r,<thumb1_atomic_fetch_oldop_str>")
396 (match_operand:QHSD 1 "mem_noofs_operand" "+Ua,Ua,Ua,Ua"))
397 (set (match_dup 1)
398 (unspec_volatile:QHSD
399 [(syncop:QHSD (match_dup 1)
400 (match_operand:QHSD 2 "<atomic_op_operand>" "<atomic_op_str>,<thumb1_atomic_fetch_op_str>"))
401 (match_operand:SI 3 "const_int_operand")] ;; model
402 VUNSPEC_ATOMIC_OP))
403 (clobber (reg:CC CC_REGNUM))
404 (clobber (match_scratch:QHSD 4 "=&r,<thumb1_atomic_fetch_newop_str>"))
405 (clobber (match_scratch:SI 5 "=&r,&l,&l,&l"))]
406 "<sync_predtab>"
407 "#"
408 "&& reload_completed"
409 [(const_int 0)]
410 {
411 arm_split_atomic_op (<CODE>, operands[0], operands[4], operands[1],
412 operands[2], operands[3], operands[5]);
413 DONE;
414 }
415 [(set_attr "arch" "32,v8mb,v8mb,v8mb")])
416
417 ;; Constraints of this pattern must be at least as strict as those of the non
418 ;; atomic NANDs in thumb1.md and aim to be as permissive.
419 (define_insn_and_split "atomic_fetch_nand<mode>"
420 [(set (match_operand:QHSD 0 "s_register_operand" "=&r,&r")
421 (match_operand:QHSD 1 "mem_noofs_operand" "+Ua,Ua"))
422 (set (match_dup 1)
423 (unspec_volatile:QHSD
424 [(not:QHSD
425 (and:QHSD (match_dup 1)
426 (match_operand:QHSD 2 "<atomic_op_operand>" "<atomic_op_str>,l")))
427 (match_operand:SI 3 "const_int_operand")] ;; model
428 VUNSPEC_ATOMIC_OP))
429 (clobber (reg:CC CC_REGNUM))
430 (clobber (match_scratch:QHSD 4 "=&r,&l"))
431 (clobber (match_scratch:SI 5 "=&r,&l"))]
432 "<sync_predtab>"
433 "#"
434 "&& reload_completed"
435 [(const_int 0)]
436 {
437 arm_split_atomic_op (NOT, operands[0], operands[4], operands[1],
438 operands[2], operands[3], operands[5]);
439 DONE;
440 }
441 [(set_attr "arch" "32,v8mb")])
442
443 ;; Constraints of this pattern must be at least as strict as those of the non
444 ;; atomic operations in thumb1.md and aim to be as permissive.
445 (define_insn_and_split "atomic_<sync_optab>_fetch<mode>"
446 [(set (match_operand:QHSD 0 "s_register_operand" "=&r,<thumb1_atomic_newop_str>")
447 (syncop:QHSD
448 (match_operand:QHSD 1 "mem_noofs_operand" "+Ua,Ua,Ua")
449 (match_operand:QHSD 2 "<atomic_op_operand>" "<atomic_op_str>,<thumb1_atomic_op_str>")))
450 (set (match_dup 1)
451 (unspec_volatile:QHSD
452 [(match_dup 1) (match_dup 2)
453 (match_operand:SI 3 "const_int_operand")] ;; model
454 VUNSPEC_ATOMIC_OP))
455 (clobber (reg:CC CC_REGNUM))
456 (clobber (match_scratch:SI 4 "=&r,&l,&l"))]
457 "<sync_predtab>"
458 "#"
459 "&& reload_completed"
460 [(const_int 0)]
461 {
462 arm_split_atomic_op (<CODE>, NULL, operands[0], operands[1],
463 operands[2], operands[3], operands[4]);
464 DONE;
465 }
466 [(set_attr "arch" "32,v8mb,v8mb")])
467
468 ;; Constraints of this pattern must be at least as strict as those of the non
469 ;; atomic NANDs in thumb1.md and aim to be as permissive.
470 (define_insn_and_split "atomic_nand_fetch<mode>"
471 [(set (match_operand:QHSD 0 "s_register_operand" "=&r,&l")
472 (not:QHSD
473 (and:QHSD
474 (match_operand:QHSD 1 "mem_noofs_operand" "+Ua,Ua")
475 (match_operand:QHSD 2 "<atomic_op_operand>" "<atomic_op_str>,l"))))
476 (set (match_dup 1)
477 (unspec_volatile:QHSD
478 [(match_dup 1) (match_dup 2)
479 (match_operand:SI 3 "const_int_operand")] ;; model
480 VUNSPEC_ATOMIC_OP))
481 (clobber (reg:CC CC_REGNUM))
482 (clobber (match_scratch:SI 4 "=&r,&l"))]
483 "<sync_predtab>"
484 "#"
485 "&& reload_completed"
486 [(const_int 0)]
487 {
488 arm_split_atomic_op (NOT, NULL, operands[0], operands[1],
489 operands[2], operands[3], operands[4]);
490 DONE;
491 }
492 [(set_attr "arch" "32,v8mb")])
493
494 (define_insn "arm_load_exclusive<mode>"
495 [(set (match_operand:SI 0 "s_register_operand" "=r")
496 (zero_extend:SI
497 (unspec_volatile:NARROW
498 [(match_operand:NARROW 1 "mem_noofs_operand" "Ua")]
499 VUNSPEC_LL)))]
500 "TARGET_HAVE_LDREXBH"
501 "ldrex<sync_sfx>\t%0, %C1"
502 )
503
504 (define_insn "arm_load_acquire_exclusive<mode>"
505 [(set (match_operand:SI 0 "s_register_operand" "=r")
506 (zero_extend:SI
507 (unspec_volatile:NARROW
508 [(match_operand:NARROW 1 "mem_noofs_operand" "Ua")]
509 VUNSPEC_LAX)))]
510 "TARGET_HAVE_LDACQ"
511 "ldaex<sync_sfx>\\t%0, %C1"
512 )
513
514 (define_insn "arm_load_exclusivesi"
515 [(set (match_operand:SI 0 "s_register_operand" "=r")
516 (unspec_volatile:SI
517 [(match_operand:SI 1 "mem_noofs_operand" "Ua")]
518 VUNSPEC_LL))]
519 "TARGET_HAVE_LDREX"
520 "ldrex\t%0, %C1"
521 )
522
523 (define_insn "arm_load_acquire_exclusivesi"
524 [(set (match_operand:SI 0 "s_register_operand" "=r")
525 (unspec_volatile:SI
526 [(match_operand:SI 1 "mem_noofs_operand" "Ua")]
527 VUNSPEC_LAX))]
528 "TARGET_HAVE_LDACQ"
529 "ldaex\t%0, %C1"
530 )
531
532 (define_insn "arm_load_exclusivedi"
533 [(set (match_operand:DI 0 "s_register_operand" "=r")
534 (unspec_volatile:DI
535 [(match_operand:DI 1 "mem_noofs_operand" "Ua")]
536 VUNSPEC_LL))]
537 "TARGET_HAVE_LDREXD"
538 "ldrexd\t%0, %H0, %C1"
539 )
540
541 (define_insn "arm_load_acquire_exclusivedi"
542 [(set (match_operand:DI 0 "s_register_operand" "=r")
543 (unspec_volatile:DI
544 [(match_operand:DI 1 "mem_noofs_operand" "Ua")]
545 VUNSPEC_LAX))]
546 "TARGET_HAVE_LDACQEXD && ARM_DOUBLEWORD_ALIGN"
547 "ldaexd\t%0, %H0, %C1"
548 )
549
550 (define_insn "arm_store_exclusive<mode>"
551 [(set (match_operand:SI 0 "s_register_operand" "=&r")
552 (unspec_volatile:SI [(const_int 0)] VUNSPEC_SC))
553 (set (match_operand:QHSD 1 "mem_noofs_operand" "=Ua")
554 (unspec_volatile:QHSD
555 [(match_operand:QHSD 2 "s_register_operand" "r")]
556 VUNSPEC_SC))]
557 "<sync_predtab>"
558 {
559 if (<MODE>mode == DImode)
560 {
561 /* The restrictions on target registers in ARM mode are that the two
562 registers are consecutive and the first one is even; Thumb is
563 actually more flexible, but DI should give us this anyway.
564 Note that the 1st register always gets the
565 lowest word in memory. */
566 gcc_assert ((REGNO (operands[2]) & 1) == 0 || TARGET_THUMB2);
567 return "strexd\t%0, %2, %H2, %C1";
568 }
569 return "strex<sync_sfx>\t%0, %2, %C1";
570 }
571 )
572
573 (define_insn "arm_store_release_exclusivedi"
574 [(set (match_operand:SI 0 "s_register_operand" "=&r")
575 (unspec_volatile:SI [(const_int 0)] VUNSPEC_SLX))
576 (set (match_operand:DI 1 "mem_noofs_operand" "=Ua")
577 (unspec_volatile:DI
578 [(match_operand:DI 2 "s_register_operand" "r")]
579 VUNSPEC_SLX))]
580 "TARGET_HAVE_LDACQEXD && ARM_DOUBLEWORD_ALIGN"
581 {
582 /* See comment in arm_store_exclusive<mode> above. */
583 gcc_assert ((REGNO (operands[2]) & 1) == 0 || TARGET_THUMB2);
584 return "stlexd\t%0, %2, %H2, %C1";
585 }
586 )
587
588 (define_insn "arm_store_release_exclusive<mode>"
589 [(set (match_operand:SI 0 "s_register_operand" "=&r")
590 (unspec_volatile:SI [(const_int 0)] VUNSPEC_SLX))
591 (set (match_operand:QHSI 1 "mem_noofs_operand" "=Ua")
592 (unspec_volatile:QHSI
593 [(match_operand:QHSI 2 "s_register_operand" "r")]
594 VUNSPEC_SLX))]
595 "TARGET_HAVE_LDACQ"
596 "stlex<sync_sfx>\t%0, %2, %C1")