Debian Codegraph @

gcc/config/i386/sync.md

raw
1 ;; GCC machine description for i386 synchronization instructions.
2 ;; Copyright (C) 2005-2025 Free Software Foundation, Inc.
3 ;;
4 ;; This file is part of GCC.
5 ;;
6 ;; GCC is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 3, or (at your option)
9 ;; any later version.
10 ;;
11 ;; GCC is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;; GNU General Public License for more details.
15 ;;
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GCC; see the file COPYING3. If not see
18 ;; <http://www.gnu.org/licenses/>.
19
20 (define_c_enum "unspec" [
21 UNSPEC_LFENCE
22 UNSPEC_SFENCE
23 UNSPEC_MFENCE
24
25 UNSPEC_FILD_ATOMIC
26 UNSPEC_FIST_ATOMIC
27
28 UNSPEC_LDX_ATOMIC
29 UNSPEC_STX_ATOMIC
30
31 ;; __atomic support
32 UNSPEC_LDA
33 UNSPEC_STA
34 ])
35
36 (define_c_enum "unspecv" [
37 UNSPECV_CMPXCHG
38 UNSPECV_XCHG
39 UNSPECV_LOCK
40
41 ;; For CMPccXADD support
42 UNSPECV_CMPCCXADD
43
44 ;; For RAOINT support
45 UNSPECV_RAOINT
46 ])
47
48 (define_expand "sse2_lfence"
49 [(set (match_dup 0)
50 (unspec:BLK [(match_dup 0)] UNSPEC_LFENCE))]
51 "TARGET_SSE2"
52 {
53 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
54 MEM_VOLATILE_P (operands[0]) = 1;
55 })
56
57 (define_insn "*sse2_lfence"
58 [(set (match_operand:BLK 0)
59 (unspec:BLK [(match_dup 0)] UNSPEC_LFENCE))]
60 "TARGET_SSE2"
61 "lfence"
62 [(set_attr "type" "sse")
63 (set_attr "length_address" "0")
64 (set_attr "atom_sse_attr" "lfence")
65 (set_attr "memory" "unknown")])
66
67 (define_expand "sse_sfence"
68 [(set (match_dup 0)
69 (unspec:BLK [(match_dup 0)] UNSPEC_SFENCE))]
70 "TARGET_SSE || TARGET_3DNOW_A"
71 {
72 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
73 MEM_VOLATILE_P (operands[0]) = 1;
74 })
75
76 (define_insn "*sse_sfence"
77 [(set (match_operand:BLK 0)
78 (unspec:BLK [(match_dup 0)] UNSPEC_SFENCE))]
79 "TARGET_SSE || TARGET_3DNOW_A"
80 "sfence"
81 [(set_attr "type" "sse")
82 (set_attr "length_address" "0")
83 (set_attr "atom_sse_attr" "fence")
84 (set_attr "memory" "unknown")])
85
86 (define_expand "sse2_mfence"
87 [(set (match_dup 0)
88 (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
89 "TARGET_SSE2"
90 {
91 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
92 MEM_VOLATILE_P (operands[0]) = 1;
93 })
94
95 (define_insn "mfence_sse2"
96 [(set (match_operand:BLK 0)
97 (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
98 "TARGET_64BIT || TARGET_SSE2"
99 "mfence"
100 [(set_attr "type" "sse")
101 (set_attr "length_address" "0")
102 (set_attr "atom_sse_attr" "fence")
103 (set_attr "memory" "unknown")])
104
105 (define_insn "mfence_nosse"
106 [(set (match_operand:BLK 0)
107 (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))
108 (clobber (reg:CC FLAGS_REG))]
109 ""
110 {
111 rtx mem = gen_rtx_MEM (word_mode, stack_pointer_rtx);
112
113 output_asm_insn ("lock{%;} or%z0\t{$0, %0|%0, 0}", &mem);
114 return "";
115 }
116 [(set_attr "memory" "unknown")])
117
118 (define_expand "mem_thread_fence"
119 [(match_operand:SI 0 "const_int_operand")] ;; model
120 ""
121 {
122 enum memmodel model = memmodel_from_int (INTVAL (operands[0]));
123
124 /* Unless this is a SEQ_CST fence, the i386 memory model is strong
125 enough not to require barriers of any kind. */
126 if (is_mm_seq_cst (model))
127 {
128 rtx (*mfence_insn)(rtx);
129 rtx mem;
130
131 if ((TARGET_64BIT || TARGET_SSE2)
132 && (optimize_function_for_size_p (cfun)
133 || !TARGET_AVOID_MFENCE))
134 mfence_insn = gen_mfence_sse2;
135 else
136 mfence_insn = gen_mfence_nosse;
137
138 mem = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
139 MEM_VOLATILE_P (mem) = 1;
140
141 emit_insn (mfence_insn (mem));
142 }
143 DONE;
144 })
145
146 ;; ??? From volume 3 section 8.1.1 Guaranteed Atomic Operations,
147 ;; Only beginning at Pentium family processors do we get any guarantee of
148 ;; atomicity in aligned 64-bit quantities. Beginning at P6, we get a
149 ;; guarantee for 64-bit accesses that do not cross a cacheline boundary.
150 ;;
151 ;; Note that the TARGET_CMPXCHG8B test below is a stand-in for "Pentium".
152 ;;
153 ;; Importantly, *no* processor makes atomicity guarantees for larger
154 ;; accesses. In particular, there's no way to perform an atomic TImode
155 ;; move, despite the apparent applicability of MOVDQA et al.
156
157 (define_mode_iterator ATOMIC
158 [QI HI SI
159 (DI "TARGET_64BIT || (TARGET_CMPXCHG8B && (TARGET_80387 || TARGET_SSE))")
160 ])
161
162 (define_expand "atomic_load<mode>"
163 [(set (match_operand:ATOMIC 0 "nonimmediate_operand")
164 (unspec:ATOMIC [(match_operand:ATOMIC 1 "memory_operand")
165 (match_operand:SI 2 "const_int_operand")]
166 UNSPEC_LDA))]
167 ""
168 {
169 /* For DImode on 32-bit, we can use the FPU to perform the load. */
170 if (<MODE>mode == DImode && !TARGET_64BIT)
171 emit_insn (gen_atomic_loaddi_fpu
172 (operands[0], operands[1],
173 assign_stack_temp (DImode, GET_MODE_SIZE (DImode))));
174 else
175 {
176 rtx dst = operands[0];
177
178 if (MEM_P (dst))
179 dst = gen_reg_rtx (<MODE>mode);
180
181 emit_move_insn (dst, operands[1]);
182
183 /* Fix up the destination if needed. */
184 if (dst != operands[0])
185 emit_move_insn (operands[0], dst);
186 }
187 DONE;
188 })
189
190 (define_insn_and_split "atomic_loaddi_fpu"
191 [(set (match_operand:DI 0 "nonimmediate_operand" "=x,m,?r")
192 (unspec:DI [(match_operand:DI 1 "memory_operand" "m,m,m")]
193 UNSPEC_LDA))
194 (clobber (match_operand:DI 2 "memory_operand" "=X,X,m"))
195 (clobber (match_scratch:DF 3 "=X,xf,xf"))]
196 "!TARGET_64BIT && (TARGET_80387 || TARGET_SSE)"
197 "#"
198 "&& reload_completed"
199 [(const_int 0)]
200 {
201 rtx dst = operands[0], src = operands[1];
202 rtx mem = operands[2], tmp = operands[3];
203
204 if (SSE_REG_P (dst))
205 emit_move_insn (dst, src);
206 else
207 {
208 if (MEM_P (dst))
209 mem = dst;
210
211 if (STACK_REG_P (tmp))
212 {
213 emit_insn (gen_loaddi_via_fpu (tmp, src));
214 emit_insn (gen_storedi_via_fpu (mem, tmp));
215 }
216 else
217 {
218 rtx tmpdi = gen_lowpart (DImode, tmp);
219
220 emit_insn (gen_loaddi_via_sse (tmp, src));
221
222 if (GENERAL_REG_P (dst)
223 && TARGET_SSE4_1 && TARGET_INTER_UNIT_MOVES_FROM_VEC)
224 {
225 emit_move_insn (dst, tmpdi);
226 DONE;
227 }
228 else
229 emit_move_insn (mem, tmpdi);
230 }
231
232 if (mem != dst)
233 emit_move_insn (dst, mem);
234 }
235 DONE;
236 })
237
238 (define_expand "atomic_store<mode>"
239 [(set (match_operand:ATOMIC 0 "memory_operand")
240 (unspec:ATOMIC [(match_operand:ATOMIC 1 "nonimmediate_operand")
241 (match_operand:SI 2 "const_int_operand")]
242 UNSPEC_STA))]
243 ""
244 {
245 enum memmodel model = memmodel_from_int (INTVAL (operands[2]));
246
247 if (<MODE>mode == DImode && !TARGET_64BIT)
248 {
249 /* For DImode on 32-bit, we can use the FPU to perform the store. */
250 /* Note that while we could perform a cmpxchg8b loop, that turns
251 out to be significantly larger than this plus a barrier. */
252 emit_insn (gen_atomic_storedi_fpu
253 (operands[0], operands[1],
254 assign_stack_temp (DImode, GET_MODE_SIZE (DImode))));
255 }
256 else
257 {
258 operands[1] = force_reg (<MODE>mode, operands[1]);
259
260 /* For seq-cst stores, use XCHG when we lack MFENCE. */
261 if (is_mm_seq_cst (model)
262 && (!(TARGET_64BIT || TARGET_SSE2)
263 || TARGET_AVOID_MFENCE))
264 {
265 emit_insn (gen_atomic_exchange<mode> (gen_reg_rtx (<MODE>mode),
266 operands[0], operands[1],
267 operands[2]));
268 DONE;
269 }
270
271 /* Otherwise use a store. */
272 emit_insn (gen_atomic_store<mode>_1 (operands[0], operands[1],
273 operands[2]));
274 }
275 /* ... followed by an MFENCE, if required. */
276 if (is_mm_seq_cst (model))
277 emit_insn (gen_mem_thread_fence (operands[2]));
278 DONE;
279 })
280
281 (define_insn "atomic_store<mode>_1"
282 [(set (match_operand:SWI 0 "memory_operand" "=m")
283 (unspec:SWI [(match_operand:SWI 1 "<nonmemory_operand>" "<r><i>")
284 (match_operand:SI 2 "const_int_operand")]
285 UNSPEC_STA))]
286 ""
287 "%K2mov{<imodesuffix>}\t{%1, %0|%0, %1}")
288
289 (define_insn_and_split "atomic_storedi_fpu"
290 [(set (match_operand:DI 0 "memory_operand" "=m,m,m")
291 (unspec:DI [(match_operand:DI 1 "nonimmediate_operand" "x,m,?r")]
292 UNSPEC_STA))
293 (clobber (match_operand:DI 2 "memory_operand" "=X,X,m"))
294 (clobber (match_scratch:DF 3 "=X,xf,xf"))]
295 "!TARGET_64BIT && (TARGET_80387 || TARGET_SSE)"
296 "#"
297 "&& reload_completed"
298 [(const_int 0)]
299 {
300 rtx dst = operands[0], src = operands[1];
301 rtx mem = operands[2], tmp = operands[3];
302
303 if (SSE_REG_P (src))
304 emit_move_insn (dst, src);
305 else
306 {
307 if (STACK_REG_P (tmp))
308 {
309 if (GENERAL_REG_P (src))
310 {
311 emit_move_insn (mem, src);
312 src = mem;
313 }
314
315 emit_insn (gen_loaddi_via_fpu (tmp, src));
316 emit_insn (gen_storedi_via_fpu (dst, tmp));
317 }
318 else
319 {
320 rtx tmpdi = gen_lowpart (DImode, tmp);
321
322 if (GENERAL_REG_P (src)
323 && !(TARGET_SSE4_1 && TARGET_INTER_UNIT_MOVES_TO_VEC))
324 {
325 emit_move_insn (mem, src);
326 src = mem;
327 }
328
329 emit_move_insn (tmpdi, src);
330
331 emit_insn (gen_storedi_via_sse (dst, tmp));
332 }
333 }
334 DONE;
335 })
336
337 ;; ??? You'd think that we'd be able to perform this via FLOAT + FIX_TRUNC
338 ;; operations. But the fix_trunc patterns want way more setup than we want
339 ;; to provide. Note that the scratch is DFmode instead of XFmode in order
340 ;; to make it easy to allocate a scratch in either SSE or FP_REGs above.
341
342 (define_insn "loaddi_via_fpu"
343 [(set (match_operand:DF 0 "register_operand" "=f")
344 (unspec:DF [(match_operand:DI 1 "memory_operand" "m")]
345 UNSPEC_FILD_ATOMIC))]
346 "TARGET_80387"
347 "fild%Z1\t%1"
348 [(set_attr "type" "fmov")
349 (set_attr "mode" "DF")
350 (set_attr "fp_int_src" "true")])
351
352 (define_insn "storedi_via_fpu"
353 [(set (match_operand:DI 0 "memory_operand" "=m")
354 (unspec:DI [(match_operand:DF 1 "register_operand" "f")]
355 UNSPEC_FIST_ATOMIC))]
356 "TARGET_80387"
357 {
358 gcc_assert (find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != NULL_RTX);
359
360 return "fistp%Z0\t%0";
361 }
362 [(set_attr "type" "fmov")
363 (set_attr "mode" "DI")])
364
365 (define_insn "loaddi_via_sse"
366 [(set (match_operand:DF 0 "register_operand" "=x")
367 (unspec:DF [(match_operand:DI 1 "memory_operand" "m")]
368 UNSPEC_LDX_ATOMIC))]
369 "TARGET_SSE"
370 {
371 if (TARGET_SSE2)
372 return "%vmovq\t{%1, %0|%0, %1}";
373 return "movlps\t{%1, %0|%0, %1}";
374 }
375 [(set_attr "type" "ssemov")
376 (set_attr "mode" "DI")])
377
378 (define_insn "storedi_via_sse"
379 [(set (match_operand:DI 0 "memory_operand" "=m")
380 (unspec:DI [(match_operand:DF 1 "register_operand" "x")]
381 UNSPEC_STX_ATOMIC))]
382 "TARGET_SSE"
383 {
384 if (TARGET_SSE2)
385 return "%vmovq\t{%1, %0|%0, %1}";
386 return "movlps\t{%1, %0|%0, %1}";
387 }
388 [(set_attr "type" "ssemov")
389 (set_attr "mode" "DI")])
390
391 (define_expand "atomic_compare_and_swap<mode>"
392 [(match_operand:QI 0 "register_operand") ;; bool success output
393 (match_operand:SWI124 1 "register_operand") ;; oldval output
394 (match_operand:SWI124 2 "memory_operand") ;; memory
395 (match_operand:SWI124 3 "register_operand") ;; expected input
396 (match_operand:SWI124 4 "register_operand") ;; newval input
397 (match_operand:SI 5 "const_int_operand") ;; is_weak
398 (match_operand:SI 6 "const_int_operand") ;; success model
399 (match_operand:SI 7 "const_int_operand")] ;; failure model
400 "TARGET_CMPXCHG"
401 {
402 if (TARGET_RELAX_CMPXCHG_LOOP)
403 {
404 ix86_expand_cmpxchg_loop (&operands[0], operands[1], operands[2],
405 operands[3], operands[4], operands[6],
406 false, NULL);
407 }
408 else
409 {
410 emit_insn
411 (gen_atomic_compare_and_swap<mode>_1
412 (operands[1], operands[2], operands[3], operands[4], operands[6]));
413 ix86_expand_setcc (operands[0], EQ, gen_rtx_REG (CCZmode, FLAGS_REG),
414 const0_rtx);
415 }
416 DONE;
417 })
418
419 (define_mode_iterator CASMODE
420 [(DI "TARGET_64BIT || TARGET_CMPXCHG8B")
421 (TI "TARGET_64BIT && TARGET_CMPXCHG16B")])
422 (define_mode_attr CASHMODE [(DI "SI") (TI "DI")])
423
424 (define_expand "atomic_compare_and_swap<mode>"
425 [(match_operand:QI 0 "register_operand") ;; bool success output
426 (match_operand:CASMODE 1 "register_operand") ;; oldval output
427 (match_operand:CASMODE 2 "memory_operand") ;; memory
428 (match_operand:CASMODE 3 "register_operand") ;; expected input
429 (match_operand:CASMODE 4 "register_operand") ;; newval input
430 (match_operand:SI 5 "const_int_operand") ;; is_weak
431 (match_operand:SI 6 "const_int_operand") ;; success model
432 (match_operand:SI 7 "const_int_operand")] ;; failure model
433 "TARGET_CMPXCHG"
434 {
435 int doubleword = !(<MODE>mode == DImode && TARGET_64BIT);
436 if (TARGET_RELAX_CMPXCHG_LOOP)
437 {
438 ix86_expand_cmpxchg_loop (&operands[0], operands[1], operands[2],
439 operands[3], operands[4], operands[6],
440 doubleword, NULL);
441 }
442 else
443 {
444 if (!doubleword)
445 {
446 emit_insn
447 (gen_atomic_compare_and_swapdi_1
448 (operands[1], operands[2], operands[3], operands[4], operands[6]));
449 }
450 else
451 {
452 machine_mode hmode = <CASHMODE>mode;
453
454 emit_insn
455 (gen_atomic_compare_and_swap<mode>_doubleword
456 (operands[1], operands[2], operands[3],
457 gen_lowpart (hmode, operands[4]), gen_highpart (hmode, operands[4]),
458 operands[6]));
459 }
460
461 ix86_expand_setcc (operands[0], EQ, gen_rtx_REG (CCZmode, FLAGS_REG),
462 const0_rtx);
463 }
464 DONE;
465 })
466
467 ;; For double-word compare and swap, we are obliged to play tricks with
468 ;; the input newval (op3:op4) because the Intel register numbering does
469 ;; not match the gcc register numbering, so the pair must be CX:BX.
470
471 (define_mode_attr doublemodesuffix [(SI "8") (DI "16")])
472
473 (define_insn "atomic_compare_and_swap<dwi>_doubleword"
474 [(set (match_operand:<DWI> 0 "register_operand" "=A")
475 (unspec_volatile:<DWI>
476 [(match_operand:<DWI> 1 "memory_operand" "+m")
477 (match_operand:<DWI> 2 "register_operand" "0")
478 (match_operand:DWIH 3 "register_operand" "b")
479 (match_operand:DWIH 4 "register_operand" "c")
480 (match_operand:SI 5 "const_int_operand")]
481 UNSPECV_CMPXCHG))
482 (set (match_dup 1)
483 (unspec_volatile:<DWI> [(const_int 0)] UNSPECV_CMPXCHG))
484 (set (reg:CCZ FLAGS_REG)
485 (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))]
486 "TARGET_CMPXCHG<doublemodesuffix>B"
487 "lock{%;} %K5cmpxchg<doublemodesuffix>b\t%1")
488
489 (define_insn "atomic_compare_and_swap<mode>_1"
490 [(set (match_operand:SWI 0 "register_operand" "=a")
491 (unspec_volatile:SWI
492 [(match_operand:SWI 1 "memory_operand" "+m")
493 (match_operand:SWI 2 "register_operand" "0")
494 (match_operand:SWI 3 "register_operand" "<r>")
495 (match_operand:SI 4 "const_int_operand")]
496 UNSPECV_CMPXCHG))
497 (set (match_dup 1)
498 (unspec_volatile:SWI [(const_int 0)] UNSPECV_CMPXCHG))
499 (set (reg:CCZ FLAGS_REG)
500 (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))]
501 "TARGET_CMPXCHG"
502 "lock{%;} %K4cmpxchg{<imodesuffix>}\t{%3, %1|%1, %3}")
503
504 (define_peephole2
505 [(set (match_operand:SWI 0 "register_operand")
506 (match_operand:SWI 1 "general_operand"))
507 (parallel [(set (match_dup 0)
508 (unspec_volatile:SWI
509 [(match_operand:SWI 2 "memory_operand")
510 (match_dup 0)
511 (match_operand:SWI 3 "register_operand")
512 (match_operand:SI 4 "const_int_operand")]
513 UNSPECV_CMPXCHG))
514 (set (match_dup 2)
515 (unspec_volatile:SWI [(const_int 0)] UNSPECV_CMPXCHG))
516 (set (reg:CCZ FLAGS_REG)
517 (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))])
518 (set (reg:CCZ FLAGS_REG)
519 (compare:CCZ (match_operand:SWI 5 "register_operand")
520 (match_operand:SWI 6 "general_operand")))]
521 "(rtx_equal_p (operands[0], operands[5])
522 && rtx_equal_p (operands[1], operands[6]))
523 || (rtx_equal_p (operands[0], operands[6])
524 && rtx_equal_p (operands[1], operands[5]))"
525 [(set (match_dup 0)
526 (match_dup 1))
527 (parallel [(set (match_dup 0)
528 (unspec_volatile:SWI
529 [(match_dup 2)
530 (match_dup 0)
531 (match_dup 3)
532 (match_dup 4)]
533 UNSPECV_CMPXCHG))
534 (set (match_dup 2)
535 (unspec_volatile:SWI [(const_int 0)] UNSPECV_CMPXCHG))
536 (set (reg:CCZ FLAGS_REG)
537 (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))])])
538
539 (define_peephole2
540 [(parallel [(set (match_operand:SWI48 0 "register_operand")
541 (match_operand:SWI48 1 "const_int_operand"))
542 (clobber (reg:CC FLAGS_REG))])
543 (parallel [(set (match_operand:SWI 2 "register_operand")
544 (unspec_volatile:SWI
545 [(match_operand:SWI 3 "memory_operand")
546 (match_dup 2)
547 (match_operand:SWI 4 "register_operand")
548 (match_operand:SI 5 "const_int_operand")]
549 UNSPECV_CMPXCHG))
550 (set (match_dup 3)
551 (unspec_volatile:SWI [(const_int 0)] UNSPECV_CMPXCHG))
552 (set (reg:CCZ FLAGS_REG)
553 (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))])
554 (set (reg:CCZ FLAGS_REG)
555 (compare:CCZ (match_dup 2)
556 (match_dup 1)))]
557 "REGNO (operands[0]) == REGNO (operands[2])"
558 [(parallel [(set (match_dup 0)
559 (match_dup 1))
560 (clobber (reg:CC FLAGS_REG))])
561 (parallel [(set (match_dup 2)
562 (unspec_volatile:SWI
563 [(match_dup 3)
564 (match_dup 2)
565 (match_dup 4)
566 (match_dup 5)]
567 UNSPECV_CMPXCHG))
568 (set (match_dup 3)
569 (unspec_volatile:SWI [(const_int 0)] UNSPECV_CMPXCHG))
570 (set (reg:CCZ FLAGS_REG)
571 (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))])])
572
573 (define_expand "atomic_fetch_<logic><mode>"
574 [(match_operand:SWI124 0 "register_operand")
575 (any_logic:SWI124
576 (match_operand:SWI124 1 "memory_operand")
577 (match_operand:SWI124 2 "register_operand"))
578 (match_operand:SI 3 "const_int_operand")]
579 "TARGET_CMPXCHG && TARGET_RELAX_CMPXCHG_LOOP"
580 {
581 ix86_expand_atomic_fetch_op_loop (operands[0], operands[1],
582 operands[2], <CODE>, false,
583 false);
584 DONE;
585 })
586
587 (define_expand "atomic_<logic>_fetch<mode>"
588 [(match_operand:SWI124 0 "register_operand")
589 (any_logic:SWI124
590 (match_operand:SWI124 1 "memory_operand")
591 (match_operand:SWI124 2 "register_operand"))
592 (match_operand:SI 3 "const_int_operand")]
593 "TARGET_CMPXCHG && TARGET_RELAX_CMPXCHG_LOOP"
594 {
595 ix86_expand_atomic_fetch_op_loop (operands[0], operands[1],
596 operands[2], <CODE>, true,
597 false);
598 DONE;
599 })
600
601 (define_expand "atomic_fetch_nand<mode>"
602 [(match_operand:SWI124 0 "register_operand")
603 (match_operand:SWI124 1 "memory_operand")
604 (match_operand:SWI124 2 "register_operand")
605 (match_operand:SI 3 "const_int_operand")]
606 "TARGET_CMPXCHG && TARGET_RELAX_CMPXCHG_LOOP"
607 {
608 ix86_expand_atomic_fetch_op_loop (operands[0], operands[1],
609 operands[2], NOT, false,
610 false);
611 DONE;
612 })
613
614 (define_expand "atomic_nand_fetch<mode>"
615 [(match_operand:SWI124 0 "register_operand")
616 (match_operand:SWI124 1 "memory_operand")
617 (match_operand:SWI124 2 "register_operand")
618 (match_operand:SI 3 "const_int_operand")]
619 "TARGET_CMPXCHG && TARGET_RELAX_CMPXCHG_LOOP"
620 {
621 ix86_expand_atomic_fetch_op_loop (operands[0], operands[1],
622 operands[2], NOT, true,
623 false);
624 DONE;
625 })
626
627 (define_expand "atomic_fetch_<logic><mode>"
628 [(match_operand:CASMODE 0 "register_operand")
629 (any_logic:CASMODE
630 (match_operand:CASMODE 1 "memory_operand")
631 (match_operand:CASMODE 2 "register_operand"))
632 (match_operand:SI 3 "const_int_operand")]
633 "TARGET_CMPXCHG && TARGET_RELAX_CMPXCHG_LOOP"
634 {
635 bool doubleword = (<MODE>mode == DImode && !TARGET_64BIT)
636 || (<MODE>mode == TImode);
637 ix86_expand_atomic_fetch_op_loop (operands[0], operands[1],
638 operands[2], <CODE>, false,
639 doubleword);
640 DONE;
641 })
642
643 (define_expand "atomic_<logic>_fetch<mode>"
644 [(match_operand:CASMODE 0 "register_operand")
645 (any_logic:CASMODE
646 (match_operand:CASMODE 1 "memory_operand")
647 (match_operand:CASMODE 2 "register_operand"))
648 (match_operand:SI 3 "const_int_operand")]
649 "TARGET_CMPXCHG && TARGET_RELAX_CMPXCHG_LOOP"
650 {
651 bool doubleword = (<MODE>mode == DImode && !TARGET_64BIT)
652 || (<MODE>mode == TImode);
653 ix86_expand_atomic_fetch_op_loop (operands[0], operands[1],
654 operands[2], <CODE>, true,
655 doubleword);
656 DONE;
657 })
658
659 (define_expand "atomic_fetch_nand<mode>"
660 [(match_operand:CASMODE 0 "register_operand")
661 (match_operand:CASMODE 1 "memory_operand")
662 (match_operand:CASMODE 2 "register_operand")
663 (match_operand:SI 3 "const_int_operand")]
664 "TARGET_CMPXCHG && TARGET_RELAX_CMPXCHG_LOOP"
665 {
666 bool doubleword = (<MODE>mode == DImode && !TARGET_64BIT)
667 || (<MODE>mode == TImode);
668 ix86_expand_atomic_fetch_op_loop (operands[0], operands[1],
669 operands[2], NOT, false,
670 doubleword);
671 DONE;
672 })
673
674 (define_expand "atomic_nand_fetch<mode>"
675 [(match_operand:CASMODE 0 "register_operand")
676 (match_operand:CASMODE 1 "memory_operand")
677 (match_operand:CASMODE 2 "register_operand")
678 (match_operand:SI 3 "const_int_operand")]
679 "TARGET_CMPXCHG && TARGET_RELAX_CMPXCHG_LOOP"
680 {
681 bool doubleword = (<MODE>mode == DImode && !TARGET_64BIT)
682 || (<MODE>mode == TImode);
683 ix86_expand_atomic_fetch_op_loop (operands[0], operands[1],
684 operands[2], NOT, true,
685 doubleword);
686 DONE;
687 })
688
689
690 ;; For operand 2 nonmemory_operand predicate is used instead of
691 ;; register_operand to allow combiner to better optimize atomic
692 ;; additions of constants.
693 (define_insn "atomic_fetch_add<mode>"
694 [(set (match_operand:SWI 0 "register_operand" "=<r>")
695 (unspec_volatile:SWI
696 [(match_operand:SWI 1 "memory_operand" "+m")
697 (match_operand:SI 3 "const_int_operand")] ;; model
698 UNSPECV_XCHG))
699 (set (match_dup 1)
700 (plus:SWI (match_dup 1)
701 (match_operand:SWI 2 "nonmemory_operand" "0")))
702 (clobber (reg:CC FLAGS_REG))]
703 "TARGET_XADD"
704 "lock{%;} %K3xadd{<imodesuffix>}\t{%0, %1|%1, %0}")
705
706 ;; This peephole2 and following insn optimize
707 ;; __sync_fetch_and_add (x, -N) == N into just lock {add,sub,inc,dec}
708 ;; followed by testing of flags instead of lock xadd and comparisons.
709 (define_peephole2
710 [(set (match_operand:SWI 0 "register_operand")
711 (match_operand:SWI 2 "const_int_operand"))
712 (parallel [(set (match_dup 0)
713 (unspec_volatile:SWI
714 [(match_operand:SWI 1 "memory_operand")
715 (match_operand:SI 4 "const_int_operand")]
716 UNSPECV_XCHG))
717 (set (match_dup 1)
718 (plus:SWI (match_dup 1)
719 (match_dup 0)))
720 (clobber (reg:CC FLAGS_REG))])
721 (set (reg:CCZ FLAGS_REG)
722 (compare:CCZ (match_dup 0)
723 (match_operand:SWI 3 "const_int_operand")))]
724 "peep2_reg_dead_p (3, operands[0])
725 && (unsigned HOST_WIDE_INT) INTVAL (operands[2])
726 == -(unsigned HOST_WIDE_INT) INTVAL (operands[3])
727 && !reg_overlap_mentioned_p (operands[0], operands[1])"
728 [(parallel [(set (reg:CCZ FLAGS_REG)
729 (compare:CCZ
730 (unspec_volatile:SWI [(match_dup 1) (match_dup 4)]
731 UNSPECV_XCHG)
732 (match_dup 3)))
733 (set (match_dup 1)
734 (plus:SWI (match_dup 1)
735 (match_dup 2)))])])
736
737 ;; Likewise, but for the -Os special case of *mov<mode>_or.
738 (define_peephole2
739 [(parallel [(set (match_operand:SWI 0 "register_operand")
740 (match_operand:SWI 2 "constm1_operand"))
741 (clobber (reg:CC FLAGS_REG))])
742 (parallel [(set (match_dup 0)
743 (unspec_volatile:SWI
744 [(match_operand:SWI 1 "memory_operand")
745 (match_operand:SI 4 "const_int_operand")]
746 UNSPECV_XCHG))
747 (set (match_dup 1)
748 (plus:SWI (match_dup 1)
749 (match_dup 0)))
750 (clobber (reg:CC FLAGS_REG))])
751 (set (reg:CCZ FLAGS_REG)
752 (compare:CCZ (match_dup 0)
753 (match_operand:SWI 3 "const_int_operand")))]
754 "peep2_reg_dead_p (3, operands[0])
755 && (unsigned HOST_WIDE_INT) INTVAL (operands[2])
756 == -(unsigned HOST_WIDE_INT) INTVAL (operands[3])
757 && !reg_overlap_mentioned_p (operands[0], operands[1])"
758 [(parallel [(set (reg:CCZ FLAGS_REG)
759 (compare:CCZ
760 (unspec_volatile:SWI [(match_dup 1) (match_dup 4)]
761 UNSPECV_XCHG)
762 (match_dup 3)))
763 (set (match_dup 1)
764 (plus:SWI (match_dup 1)
765 (match_dup 2)))])])
766
767 (define_insn "*atomic_fetch_add_cmp<mode>"
768 [(set (reg:CCZ FLAGS_REG)
769 (compare:CCZ
770 (unspec_volatile:SWI
771 [(match_operand:SWI 0 "memory_operand" "+m")
772 (match_operand:SI 3 "const_int_operand")] ;; model
773 UNSPECV_XCHG)
774 (match_operand:SWI 2 "const_int_operand")))
775 (set (match_dup 0)
776 (plus:SWI (match_dup 0)
777 (match_operand:SWI 1 "const_int_operand")))]
778 "(unsigned HOST_WIDE_INT) INTVAL (operands[1])
779 == -(unsigned HOST_WIDE_INT) INTVAL (operands[2])"
780 {
781 if (incdec_operand (operands[1], <MODE>mode))
782 {
783 if (operands[1] == const1_rtx)
784 return "lock{%;} %K3inc{<imodesuffix>}\t%0";
785 else
786 {
787 gcc_assert (operands[1] == constm1_rtx);
788 return "lock{%;} %K3dec{<imodesuffix>}\t%0";
789 }
790 }
791
792 if (x86_maybe_negate_const_int (&operands[1], <MODE>mode))
793 return "lock{%;} %K3sub{<imodesuffix>}\t{%1, %0|%0, %1}";
794
795 return "lock{%;} %K3add{<imodesuffix>}\t{%1, %0|%0, %1}";
796 })
797
798 ;; Recall that xchg implicitly sets LOCK#, so adding it again wastes space.
799 ;; In addition, it is always a full barrier, so we can ignore the memory model.
800 (define_insn "atomic_exchange<mode>"
801 [(set (match_operand:SWI 0 "register_operand" "=<r>") ;; output
802 (unspec_volatile:SWI
803 [(match_operand:SWI 1 "memory_operand" "+m") ;; memory
804 (match_operand:SI 3 "const_int_operand")] ;; model
805 UNSPECV_XCHG))
806 (set (match_dup 1)
807 (match_operand:SWI 2 "register_operand" "0"))] ;; input
808 ""
809 "%K3xchg{<imodesuffix>}\t{%1, %0|%0, %1}")
810
811 (define_code_iterator any_plus_logic [and ior xor plus])
812 (define_code_attr plus_logic [(and "and") (ior "or") (xor "xor") (plus "add")])
813
814 (define_insn "rao_a<plus_logic><mode>"
815 [(set (match_operand:SWI48 0 "memory_operand" "+m")
816 (unspec_volatile:SWI48
817 [(any_plus_logic:SWI48 (match_dup 0)
818 (match_operand:SWI48 1 "register_operand" "r"))
819 (const_int 0)] ;; MEMMODEL_RELAXED
820 UNSPECV_RAOINT))]
821 "TARGET_RAOINT"
822 "a<plus_logic>\t{%1, %0|%0, %1}")
823
824 (define_insn "atomic_add<mode>"
825 [(set (match_operand:SWI 0 "memory_operand" "+m")
826 (unspec_volatile:SWI
827 [(plus:SWI (match_dup 0)
828 (match_operand:SWI 1 "nonmemory_operand" "<r><i>"))
829 (match_operand:SI 2 "const_int_operand")] ;; model
830 UNSPECV_LOCK))
831 (clobber (reg:CC FLAGS_REG))]
832 ""
833 {
834 if (incdec_operand (operands[1], <MODE>mode))
835 {
836 if (operands[1] == const1_rtx)
837 return "lock{%;} %K2inc{<imodesuffix>}\t%0";
838 else
839 {
840 gcc_assert (operands[1] == constm1_rtx);
841 return "lock{%;} %K2dec{<imodesuffix>}\t%0";
842 }
843 }
844
845 if (x86_maybe_negate_const_int (&operands[1], <MODE>mode))
846 return "lock{%;} %K2sub{<imodesuffix>}\t{%1, %0|%0, %1}";
847
848 return "lock{%;} %K2add{<imodesuffix>}\t{%1, %0|%0, %1}";
849 })
850
851 (define_insn "atomic_sub<mode>"
852 [(set (match_operand:SWI 0 "memory_operand" "+m")
853 (unspec_volatile:SWI
854 [(minus:SWI (match_dup 0)
855 (match_operand:SWI 1 "nonmemory_operand" "<r><i>"))
856 (match_operand:SI 2 "const_int_operand")] ;; model
857 UNSPECV_LOCK))
858 (clobber (reg:CC FLAGS_REG))]
859 ""
860 {
861 if (incdec_operand (operands[1], <MODE>mode))
862 {
863 if (operands[1] == const1_rtx)
864 return "lock{%;} %K2dec{<imodesuffix>}\t%0";
865 else
866 {
867 gcc_assert (operands[1] == constm1_rtx);
868 return "lock{%;} %K2inc{<imodesuffix>}\t%0";
869 }
870 }
871
872 if (x86_maybe_negate_const_int (&operands[1], <MODE>mode))
873 return "lock{%;} %K2add{<imodesuffix>}\t{%1, %0|%0, %1}";
874
875 return "lock{%;} %K2sub{<imodesuffix>}\t{%1, %0|%0, %1}";
876 })
877
878 (define_insn "atomic_<logic><mode>"
879 [(set (match_operand:SWI 0 "memory_operand" "+m")
880 (unspec_volatile:SWI
881 [(any_logic:SWI (match_dup 0)
882 (match_operand:SWI 1 "nonmemory_operand" "<r><i>"))
883 (match_operand:SI 2 "const_int_operand")] ;; model
884 UNSPECV_LOCK))
885 (clobber (reg:CC FLAGS_REG))]
886 ""
887 "lock{%;} %K2<logic>{<imodesuffix>}\t{%1, %0|%0, %1}")
888
889 (define_expand "atomic_bit_test_and_set<mode>"
890 [(match_operand:SWI248 0 "register_operand")
891 (match_operand:SWI248 1 "memory_operand")
892 (match_operand:SWI248 2 "nonmemory_operand")
893 (match_operand:SI 3 "const_int_operand") ;; model
894 (match_operand:SI 4 "const_int_operand")]
895 ""
896 {
897 emit_insn (gen_atomic_bit_test_and_set<mode>_1 (operands[1], operands[2],
898 operands[3]));
899 rtx tem = gen_reg_rtx (QImode);
900 ix86_expand_setcc (tem, EQ, gen_rtx_REG (CCCmode, FLAGS_REG), const0_rtx);
901 rtx result = convert_modes (<MODE>mode, QImode, tem, 1);
902 if (operands[4] == const0_rtx)
903 result = expand_simple_binop (<MODE>mode, ASHIFT, result,
904 operands[2], operands[0], 0, OPTAB_WIDEN);
905 if (result != operands[0])
906 emit_move_insn (operands[0], result);
907 DONE;
908 })
909
910 (define_insn "atomic_bit_test_and_set<mode>_1"
911 [(set (reg:CCC FLAGS_REG)
912 (compare:CCC
913 (unspec_volatile:SWI248
914 [(match_operand:SWI248 0 "memory_operand" "+m")
915 (match_operand:SI 2 "const_int_operand")] ;; model
916 UNSPECV_XCHG)
917 (const_int 0)))
918 (set (zero_extract:SWI248 (match_dup 0)
919 (const_int 1)
920 (match_operand:SWI248 1 "nonmemory_operand" "rN"))
921 (const_int 1))]
922 ""
923 "lock{%;} %K2bts{<imodesuffix>}\t{%1, %0|%0, %1}")
924
925 (define_expand "atomic_bit_test_and_complement<mode>"
926 [(match_operand:SWI248 0 "register_operand")
927 (match_operand:SWI248 1 "memory_operand")
928 (match_operand:SWI248 2 "nonmemory_operand")
929 (match_operand:SI 3 "const_int_operand") ;; model
930 (match_operand:SI 4 "const_int_operand")]
931 ""
932 {
933 emit_insn (gen_atomic_bit_test_and_complement<mode>_1 (operands[1],
934 operands[2],
935 operands[3]));
936 rtx tem = gen_reg_rtx (QImode);
937 ix86_expand_setcc (tem, EQ, gen_rtx_REG (CCCmode, FLAGS_REG), const0_rtx);
938 rtx result = convert_modes (<MODE>mode, QImode, tem, 1);
939 if (operands[4] == const0_rtx)
940 result = expand_simple_binop (<MODE>mode, ASHIFT, result,
941 operands[2], operands[0], 0, OPTAB_WIDEN);
942 if (result != operands[0])
943 emit_move_insn (operands[0], result);
944 DONE;
945 })
946
947 (define_insn "atomic_bit_test_and_complement<mode>_1"
948 [(set (reg:CCC FLAGS_REG)
949 (compare:CCC
950 (unspec_volatile:SWI248
951 [(match_operand:SWI248 0 "memory_operand" "+m")
952 (match_operand:SI 2 "const_int_operand")] ;; model
953 UNSPECV_XCHG)
954 (const_int 0)))
955 (set (zero_extract:SWI248 (match_dup 0)
956 (const_int 1)
957 (match_operand:SWI248 1 "nonmemory_operand" "rN"))
958 (not:SWI248 (zero_extract:SWI248 (match_dup 0)
959 (const_int 1)
960 (match_dup 1))))]
961 ""
962 "lock{%;} %K2btc{<imodesuffix>}\t{%1, %0|%0, %1}")
963
964 (define_expand "atomic_bit_test_and_reset<mode>"
965 [(match_operand:SWI248 0 "register_operand")
966 (match_operand:SWI248 1 "memory_operand")
967 (match_operand:SWI248 2 "nonmemory_operand")
968 (match_operand:SI 3 "const_int_operand") ;; model
969 (match_operand:SI 4 "const_int_operand")]
970 ""
971 {
972 emit_insn (gen_atomic_bit_test_and_reset<mode>_1 (operands[1], operands[2],
973 operands[3]));
974 rtx tem = gen_reg_rtx (QImode);
975 ix86_expand_setcc (tem, EQ, gen_rtx_REG (CCCmode, FLAGS_REG), const0_rtx);
976 rtx result = convert_modes (<MODE>mode, QImode, tem, 1);
977 if (operands[4] == const0_rtx)
978 result = expand_simple_binop (<MODE>mode, ASHIFT, result,
979 operands[2], operands[0], 0, OPTAB_WIDEN);
980 if (result != operands[0])
981 emit_move_insn (operands[0], result);
982 DONE;
983 })
984
985 (define_insn "atomic_bit_test_and_reset<mode>_1"
986 [(set (reg:CCC FLAGS_REG)
987 (compare:CCC
988 (unspec_volatile:SWI248
989 [(match_operand:SWI248 0 "memory_operand" "+m")
990 (match_operand:SI 2 "const_int_operand")] ;; model
991 UNSPECV_XCHG)
992 (const_int 0)))
993 (set (zero_extract:SWI248 (match_dup 0)
994 (const_int 1)
995 (match_operand:SWI248 1 "nonmemory_operand" "rN"))
996 (const_int 0))]
997 ""
998 "lock{%;} %K2btr{<imodesuffix>}\t{%1, %0|%0, %1}")
999
1000 (define_expand "atomic_<plusminus_mnemonic>_fetch_cmp_0<mode>"
1001 [(match_operand:QI 0 "register_operand")
1002 (plusminus:SWI (match_operand:SWI 1 "memory_operand")
1003 (match_operand:SWI 2 "nonmemory_operand"))
1004 (match_operand:SI 3 "const_int_operand") ;; model
1005 (match_operand:SI 4 "const_int_operand")]
1006 ""
1007 {
1008 if (INTVAL (operands[4]) == GT || INTVAL (operands[4]) == LE)
1009 FAIL;
1010 emit_insn (gen_atomic_<plusminus_mnemonic>_fetch_cmp_0<mode>_1 (operands[1],
1011 operands[2],
1012 operands[3]));
1013 ix86_expand_setcc (operands[0], (enum rtx_code) INTVAL (operands[4]),
1014 gen_rtx_REG (CCGOCmode, FLAGS_REG), const0_rtx);
1015 DONE;
1016 })
1017
1018 (define_insn "atomic_add_fetch_cmp_0<mode>_1"
1019 [(set (reg:CCGOC FLAGS_REG)
1020 (compare:CCGOC
1021 (plus:SWI
1022 (unspec_volatile:SWI
1023 [(match_operand:SWI 0 "memory_operand" "+m")
1024 (match_operand:SI 2 "const_int_operand")] ;; model
1025 UNSPECV_XCHG)
1026 (match_operand:SWI 1 "nonmemory_operand" "<r><i>"))
1027 (const_int 0)))
1028 (set (match_dup 0)
1029 (plus:SWI (match_dup 0) (match_dup 1)))]
1030 ""
1031 {
1032 if (incdec_operand (operands[1], <MODE>mode))
1033 {
1034 if (operands[1] == const1_rtx)
1035 return "lock{%;} %K2inc{<imodesuffix>}\t%0";
1036 else
1037 return "lock{%;} %K2dec{<imodesuffix>}\t%0";
1038 }
1039
1040 if (x86_maybe_negate_const_int (&operands[1], <MODE>mode))
1041 return "lock{%;} %K2sub{<imodesuffix>}\t{%1, %0|%0, %1}";
1042
1043 return "lock{%;} %K2add{<imodesuffix>}\t{%1, %0|%0, %1}";
1044 })
1045
1046 (define_insn "atomic_sub_fetch_cmp_0<mode>_1"
1047 [(set (reg:CCGOC FLAGS_REG)
1048 (compare:CCGOC
1049 (minus:SWI
1050 (unspec_volatile:SWI
1051 [(match_operand:SWI 0 "memory_operand" "+m")
1052 (match_operand:SI 2 "const_int_operand")] ;; model
1053 UNSPECV_XCHG)
1054 (match_operand:SWI 1 "nonmemory_operand" "<r><i>"))
1055 (const_int 0)))
1056 (set (match_dup 0)
1057 (minus:SWI (match_dup 0) (match_dup 1)))]
1058 ""
1059 {
1060 if (incdec_operand (operands[1], <MODE>mode))
1061 {
1062 if (operands[1] != const1_rtx)
1063 return "lock{%;} %K2inc{<imodesuffix>}\t%0";
1064 else
1065 return "lock{%;} %K2dec{<imodesuffix>}\t%0";
1066 }
1067
1068 if (x86_maybe_negate_const_int (&operands[1], <MODE>mode))
1069 return "lock{%;} %K2add{<imodesuffix>}\t{%1, %0|%0, %1}";
1070
1071 return "lock{%;} %K2sub{<imodesuffix>}\t{%1, %0|%0, %1}";
1072 })
1073
1074 (define_expand "atomic_<logic>_fetch_cmp_0<mode>"
1075 [(match_operand:QI 0 "register_operand")
1076 (any_logic:SWI (match_operand:SWI 1 "memory_operand")
1077 (match_operand:SWI 2 "nonmemory_operand"))
1078 (match_operand:SI 3 "const_int_operand") ;; model
1079 (match_operand:SI 4 "const_int_operand")]
1080 ""
1081 {
1082 emit_insn (gen_atomic_<logic>_fetch_cmp_0<mode>_1 (operands[1], operands[2],
1083 operands[3]));
1084 ix86_expand_setcc (operands[0], (enum rtx_code) INTVAL (operands[4]),
1085 gen_rtx_REG (CCNOmode, FLAGS_REG), const0_rtx);
1086 DONE;
1087 })
1088
1089 (define_insn "atomic_<logic>_fetch_cmp_0<mode>_1"
1090 [(set (reg:CCNO FLAGS_REG)
1091 (compare:CCNO
1092 (any_logic:SWI
1093 (unspec_volatile:SWI
1094 [(match_operand:SWI 0 "memory_operand" "+m")
1095 (match_operand:SI 2 "const_int_operand")] ;; model
1096 UNSPECV_XCHG)
1097 (match_operand:SWI 1 "nonmemory_operand" "<r><i>"))
1098 (const_int 0)))
1099 (set (match_dup 0)
1100 (any_logic:SWI (match_dup 0) (match_dup 1)))]
1101 ""
1102 "lock{%;} %K2<logic>{<imodesuffix>}\t{%1, %0|%0, %1}")
1103
1104 ;; CMPCCXADD
1105
1106 (define_insn "cmpccxadd_<mode>"
1107 [(set (match_operand:SWI48x 0 "register_operand" "=r")
1108 (unspec_volatile:SWI48x
1109 [(match_operand:SWI48x 1 "memory_operand" "+m")
1110 (match_operand:SWI48x 2 "register_operand" "0")
1111 (match_operand:SWI48x 3 "register_operand" "r")
1112 (match_operand:SI 4 "const_0_to_15_operand" "n")]
1113 UNSPECV_CMPCCXADD))
1114 (set (match_dup 1)
1115 (unspec_volatile:SWI48x [(const_int 0)] UNSPECV_CMPCCXADD))
1116 (set (reg:CC FLAGS_REG)
1117 (compare:CC (match_dup 1)
1118 (match_dup 2)))]
1119 "TARGET_CMPCCXADD && TARGET_64BIT"
1120 {
1121 char buf[128];
1122 const char *ops = "cmp%sxadd\t{%%3, %%0, %%1|%%1, %%0, %%3}";
1123 char const *cc[16] = {"o" ,"no", "b", "nb", "z", "nz", "be", "nbe",
1124 "s", "ns", "p", "np", "l", "nl", "le", "nle"};
1125
1126 snprintf (buf, sizeof (buf), ops, cc[INTVAL (operands[4])]);
1127 output_asm_insn (buf, operands);
1128 return "";
1129 })
1130
1131 (define_peephole2
1132 [(set (match_operand:SWI48x 0 "register_operand")
1133 (match_operand:SWI48x 1 "x86_64_general_operand"))
1134 (parallel [(set (match_dup 0)
1135 (unspec_volatile:SWI48x
1136 [(match_operand:SWI48x 2 "memory_operand")
1137 (match_dup 0)
1138 (match_operand:SWI48x 3 "register_operand")
1139 (match_operand:SI 4 "const_int_operand")]
1140 UNSPECV_CMPCCXADD))
1141 (set (match_dup 2)
1142 (unspec_volatile:SWI48x [(const_int 0)] UNSPECV_CMPCCXADD))
1143 (set (reg:CC FLAGS_REG)
1144 (compare:CC (match_dup 2)
1145 (match_dup 0)))])
1146 (set (reg FLAGS_REG)
1147 (compare (match_operand:SWI48x 5 "register_operand")
1148 (match_operand:SWI48x 6 "x86_64_general_operand")))]
1149 "TARGET_CMPCCXADD && TARGET_64BIT
1150 && rtx_equal_p (operands[0], operands[5])
1151 && rtx_equal_p (operands[1], operands[6])"
1152 [(set (match_dup 0)
1153 (match_dup 1))
1154 (parallel [(set (match_dup 0)
1155 (unspec_volatile:SWI48x
1156 [(match_dup 2)
1157 (match_dup 0)
1158 (match_dup 3)
1159 (match_dup 4)]
1160 UNSPECV_CMPCCXADD))
1161 (set (match_dup 2)
1162 (unspec_volatile:SWI48x [(const_int 0)] UNSPECV_CMPCCXADD))
1163 (set (reg:CC FLAGS_REG)
1164 (compare:CC (match_dup 2)
1165 (match_dup 0)))])
1166 (set (match_dup 7)
1167 (match_op_dup 8
1168 [(match_dup 9) (const_int 0)]))])
1169
1170 (define_peephole2
1171 [(set (match_operand:SWI48x 0 "register_operand")
1172 (match_operand:SWI48x 1 "x86_64_general_operand"))
1173 (parallel [(set (match_dup 0)
1174 (unspec_volatile:SWI48x
1175 [(match_operand:SWI48x 2 "memory_operand")
1176 (match_dup 0)
1177 (match_operand:SWI48x 3 "register_operand")
1178 (match_operand:SI 4 "const_int_operand")]
1179 UNSPECV_CMPCCXADD))
1180 (set (match_dup 2)
1181 (unspec_volatile:SWI48x [(const_int 0)] UNSPECV_CMPCCXADD))
1182 (set (reg:CC FLAGS_REG)
1183 (compare:CC (match_dup 2)
1184 (match_dup 0)))])
1185 (set (reg FLAGS_REG)
1186 (compare (match_operand:SWI48x 5 "register_operand")
1187 (match_operand:SWI48x 6 "x86_64_general_operand")))
1188 (set (match_operand:QI 7 "nonimmediate_operand")
1189 (match_operator:QI 8 "ix86_comparison_int_operator"
1190 [(reg FLAGS_REG) (const_int 0)]))]
1191 "TARGET_CMPCCXADD && TARGET_64BIT
1192 && rtx_equal_p (operands[0], operands[6])
1193 && rtx_equal_p (operands[1], operands[5])
1194 && peep2_regno_dead_p (4, FLAGS_REG)"
1195 [(set (match_dup 0)
1196 (match_dup 1))
1197 (parallel [(set (match_dup 0)
1198 (unspec_volatile:SWI48x
1199 [(match_dup 2)
1200 (match_dup 0)
1201 (match_dup 3)
1202 (match_dup 4)]
1203 UNSPECV_CMPCCXADD))
1204 (set (match_dup 2)
1205 (unspec_volatile:SWI48x [(const_int 0)] UNSPECV_CMPCCXADD))
1206 (set (reg:CC FLAGS_REG)
1207 (compare:CC (match_dup 2)
1208 (match_dup 0)))])
1209 (set (match_dup 7)
1210 (match_op_dup 8
1211 [(match_dup 9) (const_int 0)]))]
1212 {
1213 operands[9] = gen_rtx_REG (GET_MODE (XEXP (operands[8], 0)), FLAGS_REG);
1214 if (swap_condition (GET_CODE (operands[8])) != GET_CODE (operands[8]))
1215 {
1216 operands[8] = shallow_copy_rtx (operands[8]);
1217 enum rtx_code ccode = swap_condition (GET_CODE (operands[8]));
1218 PUT_CODE (operands[8], ccode);
1219 operands[9] = gen_rtx_REG (SELECT_CC_MODE (ccode,
1220 operands[6],
1221 operands[5]),
1222 FLAGS_REG);
1223 }
1224 })
1225
1226 (define_peephole2
1227 [(set (match_operand:SWI48x 0 "register_operand")
1228 (match_operand:SWI48x 1 "x86_64_general_operand"))
1229 (parallel [(set (match_dup 0)
1230 (unspec_volatile:SWI48x
1231 [(match_operand:SWI48x 2 "memory_operand")
1232 (match_dup 0)
1233 (match_operand:SWI48x 3 "register_operand")
1234 (match_operand:SI 4 "const_int_operand")]
1235 UNSPECV_CMPCCXADD))
1236 (set (match_dup 2)
1237 (unspec_volatile:SWI48x [(const_int 0)] UNSPECV_CMPCCXADD))
1238 (set (reg:CC FLAGS_REG)
1239 (compare:CC (match_dup 2)
1240 (match_dup 0)))])
1241 (set (reg FLAGS_REG)
1242 (compare (match_operand:SWI48x 5 "register_operand")
1243 (match_operand:SWI48x 6 "x86_64_general_operand")))
1244 (set (pc)
1245 (if_then_else (match_operator 7 "ix86_comparison_int_operator"
1246 [(reg FLAGS_REG) (const_int 0)])
1247 (label_ref (match_operand 8))
1248 (pc)))]
1249 "TARGET_CMPCCXADD && TARGET_64BIT
1250 && rtx_equal_p (operands[0], operands[6])
1251 && rtx_equal_p (operands[1], operands[5])
1252 && peep2_regno_dead_p (4, FLAGS_REG)"
1253 [(set (match_dup 0)
1254 (match_dup 1))
1255 (parallel [(set (match_dup 0)
1256 (unspec_volatile:SWI48x
1257 [(match_dup 2)
1258 (match_dup 0)
1259 (match_dup 3)
1260 (match_dup 4)]
1261 UNSPECV_CMPCCXADD))
1262 (set (match_dup 2)
1263 (unspec_volatile:SWI48x [(const_int 0)] UNSPECV_CMPCCXADD))
1264 (set (reg:CC FLAGS_REG)
1265 (compare:CC (match_dup 2)
1266 (match_dup 0)))])
1267 (set (pc)
1268 (if_then_else
1269 (match_op_dup 7
1270 [(match_dup 9) (const_int 0)])
1271 (label_ref (match_dup 8))
1272 (pc)))]
1273 {
1274 operands[9] = gen_rtx_REG (GET_MODE (XEXP (operands[7], 0)), FLAGS_REG);
1275 if (swap_condition (GET_CODE (operands[7])) != GET_CODE (operands[7]))
1276 {
1277 operands[7] = shallow_copy_rtx (operands[7]);
1278 enum rtx_code ccode = swap_condition (GET_CODE (operands[7]));
1279 PUT_CODE (operands[7], ccode);
1280 operands[9] = gen_rtx_REG (SELECT_CC_MODE (ccode,
1281 operands[6],
1282 operands[5]),
1283 FLAGS_REG);
1284 }
1285 })