1 ;; GCC machine description for i386 synchronization instructions.
2 ;; Copyright (C) 2005-2022 Free Software Foundation, Inc.
4 ;; This file is part of GCC.
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)
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.
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/>.
20 (define_c_enum "unspec" [
36 (define_c_enum "unspecv" [
42 (define_expand "sse2_lfence"
44 (unspec:BLK [(match_dup 0)] UNSPEC_LFENCE))]
47 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
48 MEM_VOLATILE_P (operands[0]) = 1;
51 (define_insn "*sse2_lfence"
52 [(set (match_operand:BLK 0)
53 (unspec:BLK [(match_dup 0)] UNSPEC_LFENCE))]
56 [(set_attr "type" "sse")
57 (set_attr "length_address" "0")
58 (set_attr "atom_sse_attr" "lfence")
59 (set_attr "memory" "unknown")])
61 (define_expand "sse_sfence"
63 (unspec:BLK [(match_dup 0)] UNSPEC_SFENCE))]
64 "TARGET_SSE || TARGET_3DNOW_A"
66 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
67 MEM_VOLATILE_P (operands[0]) = 1;
70 (define_insn "*sse_sfence"
71 [(set (match_operand:BLK 0)
72 (unspec:BLK [(match_dup 0)] UNSPEC_SFENCE))]
73 "TARGET_SSE || TARGET_3DNOW_A"
75 [(set_attr "type" "sse")
76 (set_attr "length_address" "0")
77 (set_attr "atom_sse_attr" "fence")
78 (set_attr "memory" "unknown")])
80 (define_expand "sse2_mfence"
82 (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
85 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
86 MEM_VOLATILE_P (operands[0]) = 1;
89 (define_insn "mfence_sse2"
90 [(set (match_operand:BLK 0)
91 (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
92 "TARGET_64BIT || TARGET_SSE2"
94 [(set_attr "type" "sse")
95 (set_attr "length_address" "0")
96 (set_attr "atom_sse_attr" "fence")
97 (set_attr "memory" "unknown")])
99 (define_insn "mfence_nosse"
100 [(set (match_operand:BLK 0)
101 (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))
102 (clobber (reg:CC FLAGS_REG))]
105 rtx mem = gen_rtx_MEM (word_mode, stack_pointer_rtx);
107 output_asm_insn ("lock{%;} or%z0\t{$0, %0|%0, 0}", &mem);
110 [(set_attr "memory" "unknown")])
112 (define_expand "mem_thread_fence"
113 [(match_operand:SI 0 "const_int_operand")] ;; model
116 enum memmodel model = memmodel_from_int (INTVAL (operands[0]));
118 /* Unless this is a SEQ_CST fence, the i386 memory model is strong
119 enough not to require barriers of any kind. */
120 if (is_mm_seq_cst (model))
122 rtx (*mfence_insn)(rtx);
125 if ((TARGET_64BIT || TARGET_SSE2)
126 && (optimize_function_for_size_p (cfun)
127 || !TARGET_AVOID_MFENCE))
128 mfence_insn = gen_mfence_sse2;
130 mfence_insn = gen_mfence_nosse;
132 mem = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
133 MEM_VOLATILE_P (mem) = 1;
135 emit_insn (mfence_insn (mem));
140 ;; ??? From volume 3 section 8.1.1 Guaranteed Atomic Operations,
141 ;; Only beginning at Pentium family processors do we get any guarantee of
142 ;; atomicity in aligned 64-bit quantities. Beginning at P6, we get a
143 ;; guarantee for 64-bit accesses that do not cross a cacheline boundary.
145 ;; Note that the TARGET_CMPXCHG8B test below is a stand-in for "Pentium".
147 ;; Importantly, *no* processor makes atomicity guarantees for larger
148 ;; accesses. In particular, there's no way to perform an atomic TImode
149 ;; move, despite the apparent applicability of MOVDQA et al.
151 (define_mode_iterator ATOMIC
153 (DI "TARGET_64BIT || (TARGET_CMPXCHG8B && (TARGET_80387 || TARGET_SSE))")
156 (define_expand "atomic_load<mode>"
157 [(set (match_operand:ATOMIC 0 "nonimmediate_operand")
158 (unspec:ATOMIC [(match_operand:ATOMIC 1 "memory_operand")
159 (match_operand:SI 2 "const_int_operand")]
163 /* For DImode on 32-bit, we can use the FPU to perform the load. */
164 if (<MODE>mode == DImode && !TARGET_64BIT)
165 emit_insn (gen_atomic_loaddi_fpu
166 (operands[0], operands[1],
167 assign_386_stack_local (DImode, SLOT_TEMP)));
170 rtx dst = operands[0];
173 dst = gen_reg_rtx (<MODE>mode);
175 emit_move_insn (dst, operands[1]);
177 /* Fix up the destination if needed. */
178 if (dst != operands[0])
179 emit_move_insn (operands[0], dst);
184 (define_insn_and_split "atomic_loaddi_fpu"
185 [(set (match_operand:DI 0 "nonimmediate_operand" "=x,m,?r")
186 (unspec:DI [(match_operand:DI 1 "memory_operand" "m,m,m")]
188 (clobber (match_operand:DI 2 "memory_operand" "=X,X,m"))
189 (clobber (match_scratch:DF 3 "=X,xf,xf"))]
190 "!TARGET_64BIT && (TARGET_80387 || TARGET_SSE)"
192 "&& reload_completed"
195 rtx dst = operands[0], src = operands[1];
196 rtx mem = operands[2], tmp = operands[3];
199 emit_move_insn (dst, src);
205 if (STACK_REG_P (tmp))
207 emit_insn (gen_loaddi_via_fpu (tmp, src));
208 emit_insn (gen_storedi_via_fpu (mem, tmp));
212 emit_insn (gen_loaddi_via_sse (tmp, src));
213 emit_insn (gen_storedi_via_sse (mem, tmp));
217 emit_move_insn (dst, mem);
222 (define_expand "atomic_store<mode>"
223 [(set (match_operand:ATOMIC 0 "memory_operand")
224 (unspec:ATOMIC [(match_operand:ATOMIC 1 "nonimmediate_operand")
225 (match_operand:SI 2 "const_int_operand")]
229 enum memmodel model = memmodel_from_int (INTVAL (operands[2]));
231 if (<MODE>mode == DImode && !TARGET_64BIT)
233 /* For DImode on 32-bit, we can use the FPU to perform the store. */
234 /* Note that while we could perform a cmpxchg8b loop, that turns
235 out to be significantly larger than this plus a barrier. */
236 emit_insn (gen_atomic_storedi_fpu
237 (operands[0], operands[1],
238 assign_386_stack_local (DImode, SLOT_TEMP)));
242 operands[1] = force_reg (<MODE>mode, operands[1]);
244 /* For seq-cst stores, use XCHG when we lack MFENCE. */
245 if (is_mm_seq_cst (model)
246 && (!(TARGET_64BIT || TARGET_SSE2)
247 || TARGET_AVOID_MFENCE))
249 emit_insn (gen_atomic_exchange<mode> (gen_reg_rtx (<MODE>mode),
250 operands[0], operands[1],
255 /* Otherwise use a store. */
256 emit_insn (gen_atomic_store<mode>_1 (operands[0], operands[1],
259 /* ... followed by an MFENCE, if required. */
260 if (is_mm_seq_cst (model))
261 emit_insn (gen_mem_thread_fence (operands[2]));
265 (define_insn "atomic_store<mode>_1"
266 [(set (match_operand:SWI 0 "memory_operand" "=m")
267 (unspec:SWI [(match_operand:SWI 1 "<nonmemory_operand>" "<r><i>")
268 (match_operand:SI 2 "const_int_operand")]
271 "%K2mov{<imodesuffix>}\t{%1, %0|%0, %1}")
273 (define_insn_and_split "atomic_storedi_fpu"
274 [(set (match_operand:DI 0 "memory_operand" "=m,m,m")
275 (unspec:DI [(match_operand:DI 1 "nonimmediate_operand" "x,m,?r")]
277 (clobber (match_operand:DI 2 "memory_operand" "=X,X,m"))
278 (clobber (match_scratch:DF 3 "=X,xf,xf"))]
279 "!TARGET_64BIT && (TARGET_80387 || TARGET_SSE)"
281 "&& reload_completed"
284 rtx dst = operands[0], src = operands[1];
285 rtx mem = operands[2], tmp = operands[3];
288 emit_move_insn (dst, src);
293 emit_move_insn (mem, src);
297 if (STACK_REG_P (tmp))
299 emit_insn (gen_loaddi_via_fpu (tmp, src));
300 emit_insn (gen_storedi_via_fpu (dst, tmp));
304 emit_insn (gen_loaddi_via_sse (tmp, src));
305 emit_insn (gen_storedi_via_sse (dst, tmp));
311 ;; ??? You'd think that we'd be able to perform this via FLOAT + FIX_TRUNC
312 ;; operations. But the fix_trunc patterns want way more setup than we want
313 ;; to provide. Note that the scratch is DFmode instead of XFmode in order
314 ;; to make it easy to allocate a scratch in either SSE or FP_REGs above.
316 (define_insn "loaddi_via_fpu"
317 [(set (match_operand:DF 0 "register_operand" "=f")
318 (unspec:DF [(match_operand:DI 1 "memory_operand" "m")]
319 UNSPEC_FILD_ATOMIC))]
322 [(set_attr "type" "fmov")
323 (set_attr "mode" "DF")
324 (set_attr "fp_int_src" "true")])
326 (define_insn "storedi_via_fpu"
327 [(set (match_operand:DI 0 "memory_operand" "=m")
328 (unspec:DI [(match_operand:DF 1 "register_operand" "f")]
329 UNSPEC_FIST_ATOMIC))]
332 gcc_assert (find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != NULL_RTX);
334 return "fistp%Z0\t%0";
336 [(set_attr "type" "fmov")
337 (set_attr "mode" "DI")])
339 (define_insn "loaddi_via_sse"
340 [(set (match_operand:DF 0 "register_operand" "=x")
341 (unspec:DF [(match_operand:DI 1 "memory_operand" "m")]
346 return "%vmovq\t{%1, %0|%0, %1}";
347 return "movlps\t{%1, %0|%0, %1}";
349 [(set_attr "type" "ssemov")
350 (set_attr "mode" "DI")])
352 (define_insn "storedi_via_sse"
353 [(set (match_operand:DI 0 "memory_operand" "=m")
354 (unspec:DI [(match_operand:DF 1 "register_operand" "x")]
359 return "%vmovq\t{%1, %0|%0, %1}";
360 return "movlps\t{%1, %0|%0, %1}";
362 [(set_attr "type" "ssemov")
363 (set_attr "mode" "DI")])
365 (define_expand "atomic_compare_and_swap<mode>"
366 [(match_operand:QI 0 "register_operand") ;; bool success output
367 (match_operand:SWI124 1 "register_operand") ;; oldval output
368 (match_operand:SWI124 2 "memory_operand") ;; memory
369 (match_operand:SWI124 3 "register_operand") ;; expected input
370 (match_operand:SWI124 4 "register_operand") ;; newval input
371 (match_operand:SI 5 "const_int_operand") ;; is_weak
372 (match_operand:SI 6 "const_int_operand") ;; success model
373 (match_operand:SI 7 "const_int_operand")] ;; failure model
377 (gen_atomic_compare_and_swap<mode>_1
378 (operands[1], operands[2], operands[3], operands[4], operands[6]));
379 ix86_expand_setcc (operands[0], EQ, gen_rtx_REG (CCZmode, FLAGS_REG),
384 (define_mode_iterator CASMODE
385 [(DI "TARGET_64BIT || TARGET_CMPXCHG8B")
386 (TI "TARGET_64BIT && TARGET_CMPXCHG16B")])
387 (define_mode_attr CASHMODE [(DI "SI") (TI "DI")])
389 (define_expand "atomic_compare_and_swap<mode>"
390 [(match_operand:QI 0 "register_operand") ;; bool success output
391 (match_operand:CASMODE 1 "register_operand") ;; oldval output
392 (match_operand:CASMODE 2 "memory_operand") ;; memory
393 (match_operand:CASMODE 3 "register_operand") ;; expected input
394 (match_operand:CASMODE 4 "register_operand") ;; newval input
395 (match_operand:SI 5 "const_int_operand") ;; is_weak
396 (match_operand:SI 6 "const_int_operand") ;; success model
397 (match_operand:SI 7 "const_int_operand")] ;; failure model
400 if (<MODE>mode == DImode && TARGET_64BIT)
403 (gen_atomic_compare_and_swapdi_1
404 (operands[1], operands[2], operands[3], operands[4], operands[6]));
408 machine_mode hmode = <CASHMODE>mode;
411 (gen_atomic_compare_and_swap<mode>_doubleword
412 (operands[1], operands[2], operands[3],
413 gen_lowpart (hmode, operands[4]), gen_highpart (hmode, operands[4]),
417 ix86_expand_setcc (operands[0], EQ, gen_rtx_REG (CCZmode, FLAGS_REG),
422 ;; For double-word compare and swap, we are obliged to play tricks with
423 ;; the input newval (op3:op4) because the Intel register numbering does
424 ;; not match the gcc register numbering, so the pair must be CX:BX.
426 (define_mode_attr doublemodesuffix [(SI "8") (DI "16")])
428 (define_insn "atomic_compare_and_swap<dwi>_doubleword"
429 [(set (match_operand:<DWI> 0 "register_operand" "=A")
430 (unspec_volatile:<DWI>
431 [(match_operand:<DWI> 1 "memory_operand" "+m")
432 (match_operand:<DWI> 2 "register_operand" "0")
433 (match_operand:DWIH 3 "register_operand" "b")
434 (match_operand:DWIH 4 "register_operand" "c")
435 (match_operand:SI 5 "const_int_operand")]
438 (unspec_volatile:<DWI> [(const_int 0)] UNSPECV_CMPXCHG))
439 (set (reg:CCZ FLAGS_REG)
440 (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))]
441 "TARGET_CMPXCHG<doublemodesuffix>B"
442 "lock{%;} %K5cmpxchg<doublemodesuffix>b\t%1")
444 (define_insn "atomic_compare_and_swap<mode>_1"
445 [(set (match_operand:SWI 0 "register_operand" "=a")
447 [(match_operand:SWI 1 "memory_operand" "+m")
448 (match_operand:SWI 2 "register_operand" "0")
449 (match_operand:SWI 3 "register_operand" "<r>")
450 (match_operand:SI 4 "const_int_operand")]
453 (unspec_volatile:SWI [(const_int 0)] UNSPECV_CMPXCHG))
454 (set (reg:CCZ FLAGS_REG)
455 (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))]
457 "lock{%;} %K4cmpxchg{<imodesuffix>}\t{%3, %1|%1, %3}")
460 [(set (match_operand:SWI 0 "register_operand")
461 (match_operand:SWI 1 "general_operand"))
462 (parallel [(set (match_dup 0)
464 [(match_operand:SWI 2 "memory_operand")
466 (match_operand:SWI 3 "register_operand")
467 (match_operand:SI 4 "const_int_operand")]
470 (unspec_volatile:SWI [(const_int 0)] UNSPECV_CMPXCHG))
471 (set (reg:CCZ FLAGS_REG)
472 (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))])
473 (set (reg:CCZ FLAGS_REG)
474 (compare:CCZ (match_operand:SWI 5 "register_operand")
475 (match_operand:SWI 6 "general_operand")))]
476 "(rtx_equal_p (operands[0], operands[5])
477 && rtx_equal_p (operands[1], operands[6]))
478 || (rtx_equal_p (operands[0], operands[6])
479 && rtx_equal_p (operands[1], operands[5]))"
482 (parallel [(set (match_dup 0)
490 (unspec_volatile:SWI [(const_int 0)] UNSPECV_CMPXCHG))
491 (set (reg:CCZ FLAGS_REG)
492 (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))])])
495 [(parallel [(set (match_operand:SWI48 0 "register_operand")
496 (match_operand:SWI48 1 "const_int_operand"))
497 (clobber (reg:CC FLAGS_REG))])
498 (parallel [(set (match_operand:SWI 2 "register_operand")
500 [(match_operand:SWI 3 "memory_operand")
502 (match_operand:SWI 4 "register_operand")
503 (match_operand:SI 5 "const_int_operand")]
506 (unspec_volatile:SWI [(const_int 0)] UNSPECV_CMPXCHG))
507 (set (reg:CCZ FLAGS_REG)
508 (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))])
509 (set (reg:CCZ FLAGS_REG)
510 (compare:CCZ (match_dup 2)
512 "REGNO (operands[0]) == REGNO (operands[2])"
513 [(parallel [(set (match_dup 0)
515 (clobber (reg:CC FLAGS_REG))])
516 (parallel [(set (match_dup 2)
524 (unspec_volatile:SWI [(const_int 0)] UNSPECV_CMPXCHG))
525 (set (reg:CCZ FLAGS_REG)
526 (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))])])
528 (define_expand "atomic_fetch_<logic><mode>"
529 [(match_operand:SWI124 0 "register_operand")
531 (match_operand:SWI124 1 "memory_operand")
532 (match_operand:SWI124 2 "register_operand"))
533 (match_operand:SI 3 "const_int_operand")]
534 "TARGET_CMPXCHG && TARGET_RELAX_CMPXCHG_LOOP"
536 ix86_expand_atomic_fetch_op_loop (operands[0], operands[1],
537 operands[2], <CODE>, false,
542 (define_expand "atomic_<logic>_fetch<mode>"
543 [(match_operand:SWI124 0 "register_operand")
545 (match_operand:SWI124 1 "memory_operand")
546 (match_operand:SWI124 2 "register_operand"))
547 (match_operand:SI 3 "const_int_operand")]
548 "TARGET_CMPXCHG && TARGET_RELAX_CMPXCHG_LOOP"
550 ix86_expand_atomic_fetch_op_loop (operands[0], operands[1],
551 operands[2], <CODE>, true,
556 (define_expand "atomic_fetch_nand<mode>"
557 [(match_operand:SWI124 0 "register_operand")
558 (match_operand:SWI124 1 "memory_operand")
559 (match_operand:SWI124 2 "register_operand")
560 (match_operand:SI 3 "const_int_operand")]
561 "TARGET_CMPXCHG && TARGET_RELAX_CMPXCHG_LOOP"
563 ix86_expand_atomic_fetch_op_loop (operands[0], operands[1],
564 operands[2], NOT, false,
569 (define_expand "atomic_nand_fetch<mode>"
570 [(match_operand:SWI124 0 "register_operand")
571 (match_operand:SWI124 1 "memory_operand")
572 (match_operand:SWI124 2 "register_operand")
573 (match_operand:SI 3 "const_int_operand")]
574 "TARGET_CMPXCHG && TARGET_RELAX_CMPXCHG_LOOP"
576 ix86_expand_atomic_fetch_op_loop (operands[0], operands[1],
577 operands[2], NOT, true,
582 (define_expand "atomic_fetch_<logic><mode>"
583 [(match_operand:CASMODE 0 "register_operand")
585 (match_operand:CASMODE 1 "memory_operand")
586 (match_operand:CASMODE 2 "register_operand"))
587 (match_operand:SI 3 "const_int_operand")]
588 "TARGET_CMPXCHG && TARGET_RELAX_CMPXCHG_LOOP"
590 bool doubleword = (<MODE>mode == DImode && !TARGET_64BIT)
591 || (<MODE>mode == TImode);
592 ix86_expand_atomic_fetch_op_loop (operands[0], operands[1],
593 operands[2], <CODE>, false,
598 (define_expand "atomic_<logic>_fetch<mode>"
599 [(match_operand:CASMODE 0 "register_operand")
601 (match_operand:CASMODE 1 "memory_operand")
602 (match_operand:CASMODE 2 "register_operand"))
603 (match_operand:SI 3 "const_int_operand")]
604 "TARGET_CMPXCHG && TARGET_RELAX_CMPXCHG_LOOP"
606 bool doubleword = (<MODE>mode == DImode && !TARGET_64BIT)
607 || (<MODE>mode == TImode);
608 ix86_expand_atomic_fetch_op_loop (operands[0], operands[1],
609 operands[2], <CODE>, true,
614 (define_expand "atomic_fetch_nand<mode>"
615 [(match_operand:CASMODE 0 "register_operand")
616 (match_operand:CASMODE 1 "memory_operand")
617 (match_operand:CASMODE 2 "register_operand")
618 (match_operand:SI 3 "const_int_operand")]
619 "TARGET_CMPXCHG && TARGET_RELAX_CMPXCHG_LOOP"
621 bool doubleword = (<MODE>mode == DImode && !TARGET_64BIT)
622 || (<MODE>mode == TImode);
623 ix86_expand_atomic_fetch_op_loop (operands[0], operands[1],
624 operands[2], NOT, false,
629 (define_expand "atomic_nand_fetch<mode>"
630 [(match_operand:CASMODE 0 "register_operand")
631 (match_operand:CASMODE 1 "memory_operand")
632 (match_operand:CASMODE 2 "register_operand")
633 (match_operand:SI 3 "const_int_operand")]
634 "TARGET_CMPXCHG && TARGET_RELAX_CMPXCHG_LOOP"
636 bool doubleword = (<MODE>mode == DImode && !TARGET_64BIT)
637 || (<MODE>mode == TImode);
638 ix86_expand_atomic_fetch_op_loop (operands[0], operands[1],
639 operands[2], NOT, true,
645 ;; For operand 2 nonmemory_operand predicate is used instead of
646 ;; register_operand to allow combiner to better optimize atomic
647 ;; additions of constants.
648 (define_insn "atomic_fetch_add<mode>"
649 [(set (match_operand:SWI 0 "register_operand" "=<r>")
651 [(match_operand:SWI 1 "memory_operand" "+m")
652 (match_operand:SI 3 "const_int_operand")] ;; model
655 (plus:SWI (match_dup 1)
656 (match_operand:SWI 2 "nonmemory_operand" "0")))
657 (clobber (reg:CC FLAGS_REG))]
659 "lock{%;} %K3xadd{<imodesuffix>}\t{%0, %1|%1, %0}")
661 ;; This peephole2 and following insn optimize
662 ;; __sync_fetch_and_add (x, -N) == N into just lock {add,sub,inc,dec}
663 ;; followed by testing of flags instead of lock xadd and comparisons.
665 [(set (match_operand:SWI 0 "register_operand")
666 (match_operand:SWI 2 "const_int_operand"))
667 (parallel [(set (match_dup 0)
669 [(match_operand:SWI 1 "memory_operand")
670 (match_operand:SI 4 "const_int_operand")]
673 (plus:SWI (match_dup 1)
675 (clobber (reg:CC FLAGS_REG))])
676 (set (reg:CCZ FLAGS_REG)
677 (compare:CCZ (match_dup 0)
678 (match_operand:SWI 3 "const_int_operand")))]
679 "peep2_reg_dead_p (3, operands[0])
680 && (unsigned HOST_WIDE_INT) INTVAL (operands[2])
681 == -(unsigned HOST_WIDE_INT) INTVAL (operands[3])
682 && !reg_overlap_mentioned_p (operands[0], operands[1])"
683 [(parallel [(set (reg:CCZ FLAGS_REG)
685 (unspec_volatile:SWI [(match_dup 1) (match_dup 4)]
689 (plus:SWI (match_dup 1)
692 ;; Likewise, but for the -Os special case of *mov<mode>_or.
694 [(parallel [(set (match_operand:SWI 0 "register_operand")
695 (match_operand:SWI 2 "constm1_operand"))
696 (clobber (reg:CC FLAGS_REG))])
697 (parallel [(set (match_dup 0)
699 [(match_operand:SWI 1 "memory_operand")
700 (match_operand:SI 4 "const_int_operand")]
703 (plus:SWI (match_dup 1)
705 (clobber (reg:CC FLAGS_REG))])
706 (set (reg:CCZ FLAGS_REG)
707 (compare:CCZ (match_dup 0)
708 (match_operand:SWI 3 "const_int_operand")))]
709 "peep2_reg_dead_p (3, operands[0])
710 && (unsigned HOST_WIDE_INT) INTVAL (operands[2])
711 == -(unsigned HOST_WIDE_INT) INTVAL (operands[3])
712 && !reg_overlap_mentioned_p (operands[0], operands[1])"
713 [(parallel [(set (reg:CCZ FLAGS_REG)
715 (unspec_volatile:SWI [(match_dup 1) (match_dup 4)]
719 (plus:SWI (match_dup 1)
722 (define_insn "*atomic_fetch_add_cmp<mode>"
723 [(set (reg:CCZ FLAGS_REG)
726 [(match_operand:SWI 0 "memory_operand" "+m")
727 (match_operand:SI 3 "const_int_operand")] ;; model
729 (match_operand:SWI 2 "const_int_operand" "i")))
731 (plus:SWI (match_dup 0)
732 (match_operand:SWI 1 "const_int_operand" "i")))]
733 "(unsigned HOST_WIDE_INT) INTVAL (operands[1])
734 == -(unsigned HOST_WIDE_INT) INTVAL (operands[2])"
736 if (incdec_operand (operands[1], <MODE>mode))
738 if (operands[1] == const1_rtx)
739 return "lock{%;} %K3inc{<imodesuffix>}\t%0";
742 gcc_assert (operands[1] == constm1_rtx);
743 return "lock{%;} %K3dec{<imodesuffix>}\t%0";
747 if (x86_maybe_negate_const_int (&operands[1], <MODE>mode))
748 return "lock{%;} %K3sub{<imodesuffix>}\t{%1, %0|%0, %1}";
750 return "lock{%;} %K3add{<imodesuffix>}\t{%1, %0|%0, %1}";
753 ;; Recall that xchg implicitly sets LOCK#, so adding it again wastes space.
754 ;; In addition, it is always a full barrier, so we can ignore the memory model.
755 (define_insn "atomic_exchange<mode>"
756 [(set (match_operand:SWI 0 "register_operand" "=<r>") ;; output
758 [(match_operand:SWI 1 "memory_operand" "+m") ;; memory
759 (match_operand:SI 3 "const_int_operand")] ;; model
762 (match_operand:SWI 2 "register_operand" "0"))] ;; input
764 "%K3xchg{<imodesuffix>}\t{%1, %0|%0, %1}")
766 (define_insn "atomic_add<mode>"
767 [(set (match_operand:SWI 0 "memory_operand" "+m")
769 [(plus:SWI (match_dup 0)
770 (match_operand:SWI 1 "nonmemory_operand" "<r><i>"))
771 (match_operand:SI 2 "const_int_operand")] ;; model
773 (clobber (reg:CC FLAGS_REG))]
776 if (incdec_operand (operands[1], <MODE>mode))
778 if (operands[1] == const1_rtx)
779 return "lock{%;} %K2inc{<imodesuffix>}\t%0";
782 gcc_assert (operands[1] == constm1_rtx);
783 return "lock{%;} %K2dec{<imodesuffix>}\t%0";
787 if (x86_maybe_negate_const_int (&operands[1], <MODE>mode))
788 return "lock{%;} %K2sub{<imodesuffix>}\t{%1, %0|%0, %1}";
790 return "lock{%;} %K2add{<imodesuffix>}\t{%1, %0|%0, %1}";
793 (define_insn "atomic_sub<mode>"
794 [(set (match_operand:SWI 0 "memory_operand" "+m")
796 [(minus:SWI (match_dup 0)
797 (match_operand:SWI 1 "nonmemory_operand" "<r><i>"))
798 (match_operand:SI 2 "const_int_operand")] ;; model
800 (clobber (reg:CC FLAGS_REG))]
803 if (incdec_operand (operands[1], <MODE>mode))
805 if (operands[1] == const1_rtx)
806 return "lock{%;} %K2dec{<imodesuffix>}\t%0";
809 gcc_assert (operands[1] == constm1_rtx);
810 return "lock{%;} %K2inc{<imodesuffix>}\t%0";
814 if (x86_maybe_negate_const_int (&operands[1], <MODE>mode))
815 return "lock{%;} %K2add{<imodesuffix>}\t{%1, %0|%0, %1}";
817 return "lock{%;} %K2sub{<imodesuffix>}\t{%1, %0|%0, %1}";
820 (define_insn "atomic_<logic><mode>"
821 [(set (match_operand:SWI 0 "memory_operand" "+m")
823 [(any_logic:SWI (match_dup 0)
824 (match_operand:SWI 1 "nonmemory_operand" "<r><i>"))
825 (match_operand:SI 2 "const_int_operand")] ;; model
827 (clobber (reg:CC FLAGS_REG))]
829 "lock{%;} %K2<logic>{<imodesuffix>}\t{%1, %0|%0, %1}")
831 (define_expand "atomic_bit_test_and_set<mode>"
832 [(match_operand:SWI248 0 "register_operand")
833 (match_operand:SWI248 1 "memory_operand")
834 (match_operand:SWI248 2 "nonmemory_operand")
835 (match_operand:SI 3 "const_int_operand") ;; model
836 (match_operand:SI 4 "const_int_operand")]
839 emit_insn (gen_atomic_bit_test_and_set<mode>_1 (operands[1], operands[2],
841 rtx tem = gen_reg_rtx (QImode);
842 ix86_expand_setcc (tem, EQ, gen_rtx_REG (CCCmode, FLAGS_REG), const0_rtx);
843 rtx result = convert_modes (<MODE>mode, QImode, tem, 1);
844 if (operands[4] == const0_rtx)
845 result = expand_simple_binop (<MODE>mode, ASHIFT, result,
846 operands[2], operands[0], 0, OPTAB_WIDEN);
847 if (result != operands[0])
848 emit_move_insn (operands[0], result);
852 (define_insn "atomic_bit_test_and_set<mode>_1"
853 [(set (reg:CCC FLAGS_REG)
855 (unspec_volatile:SWI248
856 [(match_operand:SWI248 0 "memory_operand" "+m")
857 (match_operand:SI 2 "const_int_operand")] ;; model
860 (set (zero_extract:SWI248 (match_dup 0)
862 (match_operand:SWI248 1 "nonmemory_operand" "rN"))
865 "lock{%;} %K2bts{<imodesuffix>}\t{%1, %0|%0, %1}")
867 (define_expand "atomic_bit_test_and_complement<mode>"
868 [(match_operand:SWI248 0 "register_operand")
869 (match_operand:SWI248 1 "memory_operand")
870 (match_operand:SWI248 2 "nonmemory_operand")
871 (match_operand:SI 3 "const_int_operand") ;; model
872 (match_operand:SI 4 "const_int_operand")]
875 emit_insn (gen_atomic_bit_test_and_complement<mode>_1 (operands[1],
878 rtx tem = gen_reg_rtx (QImode);
879 ix86_expand_setcc (tem, EQ, gen_rtx_REG (CCCmode, FLAGS_REG), const0_rtx);
880 rtx result = convert_modes (<MODE>mode, QImode, tem, 1);
881 if (operands[4] == const0_rtx)
882 result = expand_simple_binop (<MODE>mode, ASHIFT, result,
883 operands[2], operands[0], 0, OPTAB_WIDEN);
884 if (result != operands[0])
885 emit_move_insn (operands[0], result);
889 (define_insn "atomic_bit_test_and_complement<mode>_1"
890 [(set (reg:CCC FLAGS_REG)
892 (unspec_volatile:SWI248
893 [(match_operand:SWI248 0 "memory_operand" "+m")
894 (match_operand:SI 2 "const_int_operand")] ;; model
897 (set (zero_extract:SWI248 (match_dup 0)
899 (match_operand:SWI248 1 "nonmemory_operand" "rN"))
900 (not:SWI248 (zero_extract:SWI248 (match_dup 0)
904 "lock{%;} %K2btc{<imodesuffix>}\t{%1, %0|%0, %1}")
906 (define_expand "atomic_bit_test_and_reset<mode>"
907 [(match_operand:SWI248 0 "register_operand")
908 (match_operand:SWI248 1 "memory_operand")
909 (match_operand:SWI248 2 "nonmemory_operand")
910 (match_operand:SI 3 "const_int_operand") ;; model
911 (match_operand:SI 4 "const_int_operand")]
914 emit_insn (gen_atomic_bit_test_and_reset<mode>_1 (operands[1], operands[2],
916 rtx tem = gen_reg_rtx (QImode);
917 ix86_expand_setcc (tem, EQ, gen_rtx_REG (CCCmode, FLAGS_REG), const0_rtx);
918 rtx result = convert_modes (<MODE>mode, QImode, tem, 1);
919 if (operands[4] == const0_rtx)
920 result = expand_simple_binop (<MODE>mode, ASHIFT, result,
921 operands[2], operands[0], 0, OPTAB_WIDEN);
922 if (result != operands[0])
923 emit_move_insn (operands[0], result);
927 (define_insn "atomic_bit_test_and_reset<mode>_1"
928 [(set (reg:CCC FLAGS_REG)
930 (unspec_volatile:SWI248
931 [(match_operand:SWI248 0 "memory_operand" "+m")
932 (match_operand:SI 2 "const_int_operand")] ;; model
935 (set (zero_extract:SWI248 (match_dup 0)
937 (match_operand:SWI248 1 "nonmemory_operand" "rN"))
940 "lock{%;} %K2btr{<imodesuffix>}\t{%1, %0|%0, %1}")