1 ;; GCC machine description for i386 synchronization instructions.
2 ;; Copyright (C) 2005-2016 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" [
33 (define_c_enum "unspecv" [
39 (define_expand "sse2_lfence"
41 (unspec:BLK [(match_dup 0)] UNSPEC_LFENCE))]
44 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
45 MEM_VOLATILE_P (operands[0]) = 1;
48 (define_insn "*sse2_lfence"
49 [(set (match_operand:BLK 0)
50 (unspec:BLK [(match_dup 0)] UNSPEC_LFENCE))]
53 [(set_attr "type" "sse")
54 (set_attr "length_address" "0")
55 (set_attr "atom_sse_attr" "lfence")
56 (set_attr "memory" "unknown")])
58 (define_expand "sse_sfence"
60 (unspec:BLK [(match_dup 0)] UNSPEC_SFENCE))]
61 "TARGET_SSE || TARGET_3DNOW_A"
63 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
64 MEM_VOLATILE_P (operands[0]) = 1;
67 (define_insn "*sse_sfence"
68 [(set (match_operand:BLK 0)
69 (unspec:BLK [(match_dup 0)] UNSPEC_SFENCE))]
70 "TARGET_SSE || TARGET_3DNOW_A"
72 [(set_attr "type" "sse")
73 (set_attr "length_address" "0")
74 (set_attr "atom_sse_attr" "fence")
75 (set_attr "memory" "unknown")])
77 (define_expand "sse2_mfence"
79 (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
82 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
83 MEM_VOLATILE_P (operands[0]) = 1;
86 (define_insn "mfence_sse2"
87 [(set (match_operand:BLK 0)
88 (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
89 "TARGET_64BIT || TARGET_SSE2"
91 [(set_attr "type" "sse")
92 (set_attr "length_address" "0")
93 (set_attr "atom_sse_attr" "fence")
94 (set_attr "memory" "unknown")])
96 (define_insn "mfence_nosse"
97 [(set (match_operand:BLK 0)
98 (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))
99 (clobber (reg:CC FLAGS_REG))]
100 "!(TARGET_64BIT || TARGET_SSE2)"
101 "lock{%;} or{l}\t{$0, -4(%%esp)|DWORD PTR [esp-4], 0}"
102 [(set_attr "memory" "unknown")])
104 (define_expand "mem_thread_fence"
105 [(match_operand:SI 0 "const_int_operand")] ;; model
108 enum memmodel model = memmodel_from_int (INTVAL (operands[0]));
110 /* Unless this is a SEQ_CST fence, the i386 memory model is strong
111 enough not to require barriers of any kind. */
112 if (is_mm_seq_cst (model))
114 rtx (*mfence_insn)(rtx);
117 if (TARGET_64BIT || TARGET_SSE2)
118 mfence_insn = gen_mfence_sse2;
120 mfence_insn = gen_mfence_nosse;
122 mem = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
123 MEM_VOLATILE_P (mem) = 1;
125 emit_insn (mfence_insn (mem));
130 ;; ??? From volume 3 section 8.1.1 Guaranteed Atomic Operations,
131 ;; Only beginning at Pentium family processors do we get any guarantee of
132 ;; atomicity in aligned 64-bit quantities. Beginning at P6, we get a
133 ;; guarantee for 64-bit accesses that do not cross a cacheline boundary.
135 ;; Note that the TARGET_CMPXCHG8B test below is a stand-in for "Pentium".
137 ;; Importantly, *no* processor makes atomicity guarantees for larger
138 ;; accesses. In particular, there's no way to perform an atomic TImode
139 ;; move, despite the apparent applicability of MOVDQA et al.
141 (define_mode_iterator ATOMIC
143 (DI "TARGET_64BIT || (TARGET_CMPXCHG8B && (TARGET_80387 || TARGET_SSE))")
146 (define_expand "atomic_load<mode>"
147 [(set (match_operand:ATOMIC 0 "nonimmediate_operand")
148 (unspec:ATOMIC [(match_operand:ATOMIC 1 "memory_operand")
149 (match_operand:SI 2 "const_int_operand")]
153 /* For DImode on 32-bit, we can use the FPU to perform the load. */
154 if (<MODE>mode == DImode && !TARGET_64BIT)
155 emit_insn (gen_atomic_loaddi_fpu
156 (operands[0], operands[1],
157 assign_386_stack_local (DImode, SLOT_TEMP)));
160 rtx dst = operands[0];
163 dst = gen_reg_rtx (<MODE>mode);
165 emit_move_insn (dst, operands[1]);
167 /* Fix up the destination if needed. */
168 if (dst != operands[0])
169 emit_move_insn (operands[0], dst);
174 (define_insn_and_split "atomic_loaddi_fpu"
175 [(set (match_operand:DI 0 "nonimmediate_operand" "=x,m,?r")
176 (unspec:DI [(match_operand:DI 1 "memory_operand" "m,m,m")]
178 (clobber (match_operand:DI 2 "memory_operand" "=X,X,m"))
179 (clobber (match_scratch:DF 3 "=X,xf,xf"))]
180 "!TARGET_64BIT && (TARGET_80387 || TARGET_SSE)"
182 "&& reload_completed"
185 rtx dst = operands[0], src = operands[1];
186 rtx mem = operands[2], tmp = operands[3];
189 emit_move_insn (dst, src);
195 if (STACK_REG_P (tmp))
197 emit_insn (gen_loaddi_via_fpu (tmp, src));
198 emit_insn (gen_storedi_via_fpu (mem, tmp));
202 adjust_reg_mode (tmp, DImode);
203 emit_move_insn (tmp, src);
204 emit_move_insn (mem, tmp);
208 emit_move_insn (dst, mem);
214 [(set (match_operand:DF 0 "fp_register_operand")
215 (unspec:DF [(match_operand:DI 1 "memory_operand")]
217 (set (match_operand:DI 2 "memory_operand")
218 (unspec:DI [(match_dup 0)]
220 (set (match_operand:DF 3 "fp_register_operand")
221 (match_operand:DF 4 "memory_operand"))]
223 && peep2_reg_dead_p (2, operands[0])
224 && rtx_equal_p (operands[4], adjust_address_nv (operands[2], DFmode, 0))"
225 [(set (match_dup 3) (match_dup 5))]
226 "operands[5] = gen_lowpart (DFmode, operands[1]);")
229 [(set (match_operand:DI 0 "sse_reg_operand")
230 (match_operand:DI 1 "memory_operand"))
231 (set (match_operand:DI 2 "memory_operand")
233 (set (match_operand:DF 3 "fp_register_operand")
234 (match_operand:DF 4 "memory_operand"))]
236 && peep2_reg_dead_p (2, operands[0])
237 && rtx_equal_p (operands[4], adjust_address_nv (operands[2], DFmode, 0))"
238 [(set (match_dup 3) (match_dup 5))]
239 "operands[5] = gen_lowpart (DFmode, operands[1]);")
241 (define_expand "atomic_store<mode>"
242 [(set (match_operand:ATOMIC 0 "memory_operand")
243 (unspec:ATOMIC [(match_operand:ATOMIC 1 "nonimmediate_operand")
244 (match_operand:SI 2 "const_int_operand")]
248 enum memmodel model = memmodel_from_int (INTVAL (operands[2]));
250 if (<MODE>mode == DImode && !TARGET_64BIT)
252 /* For DImode on 32-bit, we can use the FPU to perform the store. */
253 /* Note that while we could perform a cmpxchg8b loop, that turns
254 out to be significantly larger than this plus a barrier. */
255 emit_insn (gen_atomic_storedi_fpu
256 (operands[0], operands[1],
257 assign_386_stack_local (DImode, SLOT_TEMP)));
261 operands[1] = force_reg (<MODE>mode, operands[1]);
263 /* For seq-cst stores, when we lack MFENCE, use XCHG. */
264 if (is_mm_seq_cst (model) && !(TARGET_64BIT || TARGET_SSE2))
266 emit_insn (gen_atomic_exchange<mode> (gen_reg_rtx (<MODE>mode),
267 operands[0], operands[1],
272 /* Otherwise use a store. */
273 emit_insn (gen_atomic_store<mode>_1 (operands[0], operands[1],
276 /* ... followed by an MFENCE, if required. */
277 if (is_mm_seq_cst (model))
278 emit_insn (gen_mem_thread_fence (operands[2]));
282 (define_insn "atomic_store<mode>_1"
283 [(set (match_operand:SWI 0 "memory_operand" "=m")
284 (unspec:SWI [(match_operand:SWI 1 "<nonmemory_operand>" "<r><i>")
285 (match_operand:SI 2 "const_int_operand")]
288 "%K2mov{<imodesuffix>}\t{%1, %0|%0, %1}")
290 (define_insn_and_split "atomic_storedi_fpu"
291 [(set (match_operand:DI 0 "memory_operand" "=m,m,m")
292 (unspec:DI [(match_operand:DI 1 "nonimmediate_operand" "x,m,?r")]
294 (clobber (match_operand:DI 2 "memory_operand" "=X,X,m"))
295 (clobber (match_scratch:DF 3 "=X,xf,xf"))]
296 "!TARGET_64BIT && (TARGET_80387 || TARGET_SSE)"
298 "&& reload_completed"
301 rtx dst = operands[0], src = operands[1];
302 rtx mem = operands[2], tmp = operands[3];
304 if (!SSE_REG_P (src))
308 emit_move_insn (mem, src);
312 if (STACK_REG_P (tmp))
314 emit_insn (gen_loaddi_via_fpu (tmp, src));
315 emit_insn (gen_storedi_via_fpu (dst, tmp));
320 adjust_reg_mode (tmp, DImode);
321 emit_move_insn (tmp, src);
325 emit_move_insn (dst, src);
330 [(set (match_operand:DF 0 "memory_operand")
331 (match_operand:DF 1 "fp_register_operand"))
332 (set (match_operand:DF 2 "fp_register_operand")
333 (unspec:DF [(match_operand:DI 3 "memory_operand")]
335 (set (match_operand:DI 4 "memory_operand")
336 (unspec:DI [(match_dup 2)]
337 UNSPEC_FIST_ATOMIC))]
339 && peep2_reg_dead_p (3, operands[2])
340 && rtx_equal_p (operands[0], adjust_address_nv (operands[3], DFmode, 0))"
341 [(set (match_dup 5) (match_dup 1))]
342 "operands[5] = gen_lowpart (DFmode, operands[4]);")
345 [(set (match_operand:DF 0 "memory_operand")
346 (match_operand:DF 1 "fp_register_operand"))
347 (set (match_operand:DI 2 "sse_reg_operand")
348 (match_operand:DI 3 "memory_operand"))
349 (set (match_operand:DI 4 "memory_operand")
352 && peep2_reg_dead_p (3, operands[2])
353 && rtx_equal_p (operands[0], adjust_address_nv (operands[3], DFmode, 0))"
354 [(set (match_dup 5) (match_dup 1))]
355 "operands[5] = gen_lowpart (DFmode, operands[4]);")
357 ;; ??? You'd think that we'd be able to perform this via FLOAT + FIX_TRUNC
358 ;; operations. But the fix_trunc patterns want way more setup than we want
359 ;; to provide. Note that the scratch is DFmode instead of XFmode in order
360 ;; to make it easy to allocate a scratch in either SSE or FP_REGs above.
362 (define_insn "loaddi_via_fpu"
363 [(set (match_operand:DF 0 "register_operand" "=f")
364 (unspec:DF [(match_operand:DI 1 "memory_operand" "m")]
365 UNSPEC_FILD_ATOMIC))]
368 [(set_attr "type" "fmov")
369 (set_attr "mode" "DF")
370 (set_attr "fp_int_src" "true")])
372 (define_insn "storedi_via_fpu"
373 [(set (match_operand:DI 0 "memory_operand" "=m")
374 (unspec:DI [(match_operand:DF 1 "register_operand" "f")]
375 UNSPEC_FIST_ATOMIC))]
378 gcc_assert (find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != NULL_RTX);
380 return "fistp%Z0\t%0";
382 [(set_attr "type" "fmov")
383 (set_attr "mode" "DI")])
385 (define_expand "atomic_compare_and_swap<mode>"
386 [(match_operand:QI 0 "register_operand") ;; bool success output
387 (match_operand:SWI124 1 "register_operand") ;; oldval output
388 (match_operand:SWI124 2 "memory_operand") ;; memory
389 (match_operand:SWI124 3 "register_operand") ;; expected input
390 (match_operand:SWI124 4 "register_operand") ;; newval input
391 (match_operand:SI 5 "const_int_operand") ;; is_weak
392 (match_operand:SI 6 "const_int_operand") ;; success model
393 (match_operand:SI 7 "const_int_operand")] ;; failure model
397 (gen_atomic_compare_and_swap<mode>_1
398 (operands[1], operands[2], operands[3], operands[4], operands[6]));
399 ix86_expand_setcc (operands[0], EQ, gen_rtx_REG (CCZmode, FLAGS_REG),
404 (define_mode_iterator CASMODE
405 [(DI "TARGET_64BIT || TARGET_CMPXCHG8B")
406 (TI "TARGET_64BIT && TARGET_CMPXCHG16B")])
407 (define_mode_attr CASHMODE [(DI "SI") (TI "DI")])
409 (define_expand "atomic_compare_and_swap<mode>"
410 [(match_operand:QI 0 "register_operand") ;; bool success output
411 (match_operand:CASMODE 1 "register_operand") ;; oldval output
412 (match_operand:CASMODE 2 "memory_operand") ;; memory
413 (match_operand:CASMODE 3 "register_operand") ;; expected input
414 (match_operand:CASMODE 4 "register_operand") ;; newval input
415 (match_operand:SI 5 "const_int_operand") ;; is_weak
416 (match_operand:SI 6 "const_int_operand") ;; success model
417 (match_operand:SI 7 "const_int_operand")] ;; failure model
420 if (<MODE>mode == DImode && TARGET_64BIT)
423 (gen_atomic_compare_and_swapdi_1
424 (operands[1], operands[2], operands[3], operands[4], operands[6]));
428 machine_mode hmode = <CASHMODE>mode;
431 (gen_atomic_compare_and_swap<mode>_doubleword
432 (operands[1], operands[2], operands[3],
433 gen_lowpart (hmode, operands[4]), gen_highpart (hmode, operands[4]),
437 ix86_expand_setcc (operands[0], EQ, gen_rtx_REG (CCZmode, FLAGS_REG),
442 ;; For double-word compare and swap, we are obliged to play tricks with
443 ;; the input newval (op3:op4) because the Intel register numbering does
444 ;; not match the gcc register numbering, so the pair must be CX:BX.
446 (define_mode_attr doublemodesuffix [(SI "8") (DI "16")])
448 (define_insn "atomic_compare_and_swap<dwi>_doubleword"
449 [(set (match_operand:<DWI> 0 "register_operand" "=A")
450 (unspec_volatile:<DWI>
451 [(match_operand:<DWI> 1 "memory_operand" "+m")
452 (match_operand:<DWI> 2 "register_operand" "0")
453 (match_operand:DWIH 3 "register_operand" "b")
454 (match_operand:DWIH 4 "register_operand" "c")
455 (match_operand:SI 5 "const_int_operand")]
458 (unspec_volatile:<DWI> [(const_int 0)] UNSPECV_CMPXCHG))
459 (set (reg:CCZ FLAGS_REG)
460 (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))]
461 "TARGET_CMPXCHG<doublemodesuffix>B"
462 "lock{%;} %K5cmpxchg<doublemodesuffix>b\t%1")
464 (define_insn "atomic_compare_and_swap<mode>_1"
465 [(set (match_operand:SWI 0 "register_operand" "=a")
467 [(match_operand:SWI 1 "memory_operand" "+m")
468 (match_operand:SWI 2 "register_operand" "0")
469 (match_operand:SWI 3 "register_operand" "<r>")
470 (match_operand:SI 4 "const_int_operand")]
473 (unspec_volatile:SWI [(const_int 0)] UNSPECV_CMPXCHG))
474 (set (reg:CCZ FLAGS_REG)
475 (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))]
477 "lock{%;} %K4cmpxchg{<imodesuffix>}\t{%3, %1|%1, %3}")
479 ;; For operand 2 nonmemory_operand predicate is used instead of
480 ;; register_operand to allow combiner to better optimize atomic
481 ;; additions of constants.
482 (define_insn "atomic_fetch_add<mode>"
483 [(set (match_operand:SWI 0 "register_operand" "=<r>")
485 [(match_operand:SWI 1 "memory_operand" "+m")
486 (match_operand:SI 3 "const_int_operand")] ;; model
489 (plus:SWI (match_dup 1)
490 (match_operand:SWI 2 "nonmemory_operand" "0")))
491 (clobber (reg:CC FLAGS_REG))]
493 "lock{%;} %K3xadd{<imodesuffix>}\t{%0, %1|%1, %0}")
495 ;; This peephole2 and following insn optimize
496 ;; __sync_fetch_and_add (x, -N) == N into just lock {add,sub,inc,dec}
497 ;; followed by testing of flags instead of lock xadd and comparisons.
499 [(set (match_operand:SWI 0 "register_operand")
500 (match_operand:SWI 2 "const_int_operand"))
501 (parallel [(set (match_dup 0)
503 [(match_operand:SWI 1 "memory_operand")
504 (match_operand:SI 4 "const_int_operand")]
507 (plus:SWI (match_dup 1)
509 (clobber (reg:CC FLAGS_REG))])
510 (set (reg:CCZ FLAGS_REG)
511 (compare:CCZ (match_dup 0)
512 (match_operand:SWI 3 "const_int_operand")))]
513 "peep2_reg_dead_p (3, operands[0])
514 && (unsigned HOST_WIDE_INT) INTVAL (operands[2])
515 == -(unsigned HOST_WIDE_INT) INTVAL (operands[3])
516 && !reg_overlap_mentioned_p (operands[0], operands[1])"
517 [(parallel [(set (reg:CCZ FLAGS_REG)
519 (unspec_volatile:SWI [(match_dup 1) (match_dup 4)]
523 (plus:SWI (match_dup 1)
526 ;; Likewise, but for the -Os special case of *mov<mode>_or.
528 [(parallel [(set (match_operand:SWI 0 "register_operand")
529 (match_operand:SWI 2 "constm1_operand"))
530 (clobber (reg:CC FLAGS_REG))])
531 (parallel [(set (match_dup 0)
533 [(match_operand:SWI 1 "memory_operand")
534 (match_operand:SI 4 "const_int_operand")]
537 (plus:SWI (match_dup 1)
539 (clobber (reg:CC FLAGS_REG))])
540 (set (reg:CCZ FLAGS_REG)
541 (compare:CCZ (match_dup 0)
542 (match_operand:SWI 3 "const_int_operand")))]
543 "peep2_reg_dead_p (3, operands[0])
544 && (unsigned HOST_WIDE_INT) INTVAL (operands[2])
545 == -(unsigned HOST_WIDE_INT) INTVAL (operands[3])
546 && !reg_overlap_mentioned_p (operands[0], operands[1])"
547 [(parallel [(set (reg:CCZ FLAGS_REG)
549 (unspec_volatile:SWI [(match_dup 1) (match_dup 4)]
553 (plus:SWI (match_dup 1)
556 (define_insn "*atomic_fetch_add_cmp<mode>"
557 [(set (reg:CCZ FLAGS_REG)
560 [(match_operand:SWI 0 "memory_operand" "+m")
561 (match_operand:SI 3 "const_int_operand")] ;; model
563 (match_operand:SWI 2 "const_int_operand" "i")))
565 (plus:SWI (match_dup 0)
566 (match_operand:SWI 1 "const_int_operand" "i")))]
567 "(unsigned HOST_WIDE_INT) INTVAL (operands[1])
568 == -(unsigned HOST_WIDE_INT) INTVAL (operands[2])"
570 if (incdec_operand (operands[1], <MODE>mode))
572 if (operands[1] == const1_rtx)
573 return "lock{%;} %K3inc{<imodesuffix>}\t%0";
576 gcc_assert (operands[1] == constm1_rtx);
577 return "lock{%;} %K3dec{<imodesuffix>}\t%0";
581 if (x86_maybe_negate_const_int (&operands[1], <MODE>mode))
582 return "lock{%;} %K3sub{<imodesuffix>}\t{%1, %0|%0, %1}";
584 return "lock{%;} %K3add{<imodesuffix>}\t{%1, %0|%0, %1}";
587 ;; Recall that xchg implicitly sets LOCK#, so adding it again wastes space.
588 ;; In addition, it is always a full barrier, so we can ignore the memory model.
589 (define_insn "atomic_exchange<mode>"
590 [(set (match_operand:SWI 0 "register_operand" "=<r>") ;; output
592 [(match_operand:SWI 1 "memory_operand" "+m") ;; memory
593 (match_operand:SI 3 "const_int_operand")] ;; model
596 (match_operand:SWI 2 "register_operand" "0"))] ;; input
598 "%K3xchg{<imodesuffix>}\t{%1, %0|%0, %1}")
600 (define_insn "atomic_add<mode>"
601 [(set (match_operand:SWI 0 "memory_operand" "+m")
603 [(plus:SWI (match_dup 0)
604 (match_operand:SWI 1 "nonmemory_operand" "<r><i>"))
605 (match_operand:SI 2 "const_int_operand")] ;; model
607 (clobber (reg:CC FLAGS_REG))]
610 if (incdec_operand (operands[1], <MODE>mode))
612 if (operands[1] == const1_rtx)
613 return "lock{%;} %K2inc{<imodesuffix>}\t%0";
616 gcc_assert (operands[1] == constm1_rtx);
617 return "lock{%;} %K2dec{<imodesuffix>}\t%0";
621 if (x86_maybe_negate_const_int (&operands[1], <MODE>mode))
622 return "lock{%;} %K2sub{<imodesuffix>}\t{%1, %0|%0, %1}";
624 return "lock{%;} %K2add{<imodesuffix>}\t{%1, %0|%0, %1}";
627 (define_insn "atomic_sub<mode>"
628 [(set (match_operand:SWI 0 "memory_operand" "+m")
630 [(minus:SWI (match_dup 0)
631 (match_operand:SWI 1 "nonmemory_operand" "<r><i>"))
632 (match_operand:SI 2 "const_int_operand")] ;; model
634 (clobber (reg:CC FLAGS_REG))]
637 if (incdec_operand (operands[1], <MODE>mode))
639 if (operands[1] == const1_rtx)
640 return "lock{%;} %K2dec{<imodesuffix>}\t%0";
643 gcc_assert (operands[1] == constm1_rtx);
644 return "lock{%;} %K2inc{<imodesuffix>}\t%0";
648 if (x86_maybe_negate_const_int (&operands[1], <MODE>mode))
649 return "lock{%;} %K2add{<imodesuffix>}\t{%1, %0|%0, %1}";
651 return "lock{%;} %K2sub{<imodesuffix>}\t{%1, %0|%0, %1}";
654 (define_insn "atomic_<logic><mode>"
655 [(set (match_operand:SWI 0 "memory_operand" "+m")
657 [(any_logic:SWI (match_dup 0)
658 (match_operand:SWI 1 "nonmemory_operand" "<r><i>"))
659 (match_operand:SI 2 "const_int_operand")] ;; model
661 (clobber (reg:CC FLAGS_REG))]
663 "lock{%;} %K2<logic>{<imodesuffix>}\t{%1, %0|%0, %1}")
665 (define_expand "atomic_bit_test_and_set<mode>"
666 [(match_operand:SWI248 0 "register_operand")
667 (match_operand:SWI248 1 "memory_operand")
668 (match_operand:SWI248 2 "nonmemory_operand")
669 (match_operand:SI 3 "const_int_operand") ;; model
670 (match_operand:SI 4 "const_int_operand")]
673 emit_insn (gen_atomic_bit_test_and_set<mode>_1 (operands[1], operands[2],
675 rtx tem = gen_reg_rtx (QImode);
676 ix86_expand_setcc (tem, EQ, gen_rtx_REG (CCCmode, FLAGS_REG), const0_rtx);
677 rtx result = convert_modes (<MODE>mode, QImode, tem, 1);
678 if (operands[4] == const0_rtx)
679 result = expand_simple_binop (<MODE>mode, ASHIFT, result,
680 operands[2], operands[0], 0, OPTAB_DIRECT);
681 if (result != operands[0])
682 emit_move_insn (operands[0], result);
686 (define_insn "atomic_bit_test_and_set<mode>_1"
687 [(set (reg:CCC FLAGS_REG)
689 (unspec_volatile:SWI248
690 [(match_operand:SWI248 0 "memory_operand" "+m")
691 (match_operand:SI 2 "const_int_operand")] ;; model
694 (set (zero_extract:SWI248 (match_dup 0)
696 (match_operand:SWI248 1 "nonmemory_operand" "rN"))
699 "lock{%;} %K2bts{<imodesuffix>}\t{%1, %0|%0, %1}")
701 (define_expand "atomic_bit_test_and_complement<mode>"
702 [(match_operand:SWI248 0 "register_operand")
703 (match_operand:SWI248 1 "memory_operand")
704 (match_operand:SWI248 2 "nonmemory_operand")
705 (match_operand:SI 3 "const_int_operand") ;; model
706 (match_operand:SI 4 "const_int_operand")]
709 emit_insn (gen_atomic_bit_test_and_complement<mode>_1 (operands[1],
712 rtx tem = gen_reg_rtx (QImode);
713 ix86_expand_setcc (tem, EQ, gen_rtx_REG (CCCmode, FLAGS_REG), const0_rtx);
714 rtx result = convert_modes (<MODE>mode, QImode, tem, 1);
715 if (operands[4] == const0_rtx)
716 result = expand_simple_binop (<MODE>mode, ASHIFT, result,
717 operands[2], operands[0], 0, OPTAB_DIRECT);
718 if (result != operands[0])
719 emit_move_insn (operands[0], result);
723 (define_insn "atomic_bit_test_and_complement<mode>_1"
724 [(set (reg:CCC FLAGS_REG)
726 (unspec_volatile:SWI248
727 [(match_operand:SWI248 0 "memory_operand" "+m")
728 (match_operand:SI 2 "const_int_operand")] ;; model
731 (set (zero_extract:SWI248 (match_dup 0)
733 (match_operand:SWI248 1 "nonmemory_operand" "rN"))
734 (not:SWI248 (zero_extract:SWI248 (match_dup 0)
738 "lock{%;} %K2btc{<imodesuffix>}\t{%1, %0|%0, %1}")
740 (define_expand "atomic_bit_test_and_reset<mode>"
741 [(match_operand:SWI248 0 "register_operand")
742 (match_operand:SWI248 1 "memory_operand")
743 (match_operand:SWI248 2 "nonmemory_operand")
744 (match_operand:SI 3 "const_int_operand") ;; model
745 (match_operand:SI 4 "const_int_operand")]
748 emit_insn (gen_atomic_bit_test_and_reset<mode>_1 (operands[1], operands[2],
750 rtx tem = gen_reg_rtx (QImode);
751 ix86_expand_setcc (tem, EQ, gen_rtx_REG (CCCmode, FLAGS_REG), const0_rtx);
752 rtx result = convert_modes (<MODE>mode, QImode, tem, 1);
753 if (operands[4] == const0_rtx)
754 result = expand_simple_binop (<MODE>mode, ASHIFT, result,
755 operands[2], operands[0], 0, OPTAB_DIRECT);
756 if (result != operands[0])
757 emit_move_insn (operands[0], result);
761 (define_insn "atomic_bit_test_and_reset<mode>_1"
762 [(set (reg:CCC FLAGS_REG)
764 (unspec_volatile:SWI248
765 [(match_operand:SWI248 0 "memory_operand" "+m")
766 (match_operand:SI 2 "const_int_operand")] ;; model
769 (set (zero_extract:SWI248 (match_dup 0)
771 (match_operand:SWI248 1 "nonmemory_operand" "rN"))
774 "lock{%;} %K2btr{<imodesuffix>}\t{%1, %0|%0, %1}")