Home | History | Annotate | Line # | Download | only in i386
sync.md revision 1.8
      1  1.1  mrg ;; GCC machine description for i386 synchronization instructions.
      2  1.8  mrg ;; Copyright (C) 2005-2017 Free Software Foundation, Inc.
      3  1.1  mrg ;;
      4  1.1  mrg ;; This file is part of GCC.
      5  1.1  mrg ;;
      6  1.1  mrg ;; GCC is free software; you can redistribute it and/or modify
      7  1.1  mrg ;; it under the terms of the GNU General Public License as published by
      8  1.1  mrg ;; the Free Software Foundation; either version 3, or (at your option)
      9  1.1  mrg ;; any later version.
     10  1.1  mrg ;;
     11  1.1  mrg ;; GCC is distributed in the hope that it will be useful,
     12  1.1  mrg ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  1.1  mrg ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14  1.1  mrg ;; GNU General Public License for more details.
     15  1.1  mrg ;;
     16  1.1  mrg ;; You should have received a copy of the GNU General Public License
     17  1.1  mrg ;; along with GCC; see the file COPYING3.  If not see
     18  1.1  mrg ;; <http://www.gnu.org/licenses/>.
     19  1.1  mrg 
     20  1.3  mrg (define_c_enum "unspec" [
     21  1.3  mrg   UNSPEC_LFENCE
     22  1.3  mrg   UNSPEC_SFENCE
     23  1.3  mrg   UNSPEC_MFENCE
     24  1.5  mrg 
     25  1.5  mrg   UNSPEC_FILD_ATOMIC
     26  1.5  mrg   UNSPEC_FIST_ATOMIC
     27  1.5  mrg 
     28  1.8  mrg   UNSPEC_LDX_ATOMIC
     29  1.8  mrg   UNSPEC_STX_ATOMIC
     30  1.8  mrg 
     31  1.5  mrg   ;; __atomic support
     32  1.3  mrg   UNSPEC_LDA
     33  1.3  mrg   UNSPEC_STA
     34  1.3  mrg ])
     35  1.3  mrg 
     36  1.3  mrg (define_c_enum "unspecv" [
     37  1.3  mrg   UNSPECV_CMPXCHG
     38  1.3  mrg   UNSPECV_XCHG
     39  1.3  mrg   UNSPECV_LOCK
     40  1.3  mrg ])
     41  1.3  mrg 
     42  1.3  mrg (define_expand "sse2_lfence"
     43  1.3  mrg   [(set (match_dup 0)
     44  1.3  mrg 	(unspec:BLK [(match_dup 0)] UNSPEC_LFENCE))]
     45  1.3  mrg   "TARGET_SSE2"
     46  1.3  mrg {
     47  1.3  mrg   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
     48  1.3  mrg   MEM_VOLATILE_P (operands[0]) = 1;
     49  1.3  mrg })
     50  1.3  mrg 
     51  1.3  mrg (define_insn "*sse2_lfence"
     52  1.3  mrg   [(set (match_operand:BLK 0)
     53  1.3  mrg 	(unspec:BLK [(match_dup 0)] UNSPEC_LFENCE))]
     54  1.3  mrg   "TARGET_SSE2"
     55  1.3  mrg   "lfence"
     56  1.3  mrg   [(set_attr "type" "sse")
     57  1.3  mrg    (set_attr "length_address" "0")
     58  1.3  mrg    (set_attr "atom_sse_attr" "lfence")
     59  1.3  mrg    (set_attr "memory" "unknown")])
     60  1.3  mrg 
     61  1.3  mrg (define_expand "sse_sfence"
     62  1.3  mrg   [(set (match_dup 0)
     63  1.3  mrg 	(unspec:BLK [(match_dup 0)] UNSPEC_SFENCE))]
     64  1.3  mrg   "TARGET_SSE || TARGET_3DNOW_A"
     65  1.3  mrg {
     66  1.3  mrg   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
     67  1.3  mrg   MEM_VOLATILE_P (operands[0]) = 1;
     68  1.3  mrg })
     69  1.3  mrg 
     70  1.3  mrg (define_insn "*sse_sfence"
     71  1.3  mrg   [(set (match_operand:BLK 0)
     72  1.3  mrg 	(unspec:BLK [(match_dup 0)] UNSPEC_SFENCE))]
     73  1.3  mrg   "TARGET_SSE || TARGET_3DNOW_A"
     74  1.3  mrg   "sfence"
     75  1.3  mrg   [(set_attr "type" "sse")
     76  1.3  mrg    (set_attr "length_address" "0")
     77  1.3  mrg    (set_attr "atom_sse_attr" "fence")
     78  1.3  mrg    (set_attr "memory" "unknown")])
     79  1.1  mrg 
     80  1.3  mrg (define_expand "sse2_mfence"
     81  1.1  mrg   [(set (match_dup 0)
     82  1.1  mrg 	(unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
     83  1.3  mrg   "TARGET_SSE2"
     84  1.1  mrg {
     85  1.1  mrg   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
     86  1.1  mrg   MEM_VOLATILE_P (operands[0]) = 1;
     87  1.3  mrg })
     88  1.1  mrg 
     89  1.3  mrg (define_insn "mfence_sse2"
     90  1.3  mrg   [(set (match_operand:BLK 0)
     91  1.3  mrg 	(unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
     92  1.3  mrg   "TARGET_64BIT || TARGET_SSE2"
     93  1.3  mrg   "mfence"
     94  1.3  mrg   [(set_attr "type" "sse")
     95  1.3  mrg    (set_attr "length_address" "0")
     96  1.3  mrg    (set_attr "atom_sse_attr" "fence")
     97  1.3  mrg    (set_attr "memory" "unknown")])
     98  1.1  mrg 
     99  1.3  mrg (define_insn "mfence_nosse"
    100  1.3  mrg   [(set (match_operand:BLK 0)
    101  1.1  mrg 	(unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))
    102  1.1  mrg    (clobber (reg:CC FLAGS_REG))]
    103  1.1  mrg   "!(TARGET_64BIT || TARGET_SSE2)"
    104  1.1  mrg   "lock{%;} or{l}\t{$0, (%%esp)|DWORD PTR [esp], 0}"
    105  1.1  mrg   [(set_attr "memory" "unknown")])
    106  1.1  mrg 
    107  1.3  mrg (define_expand "mem_thread_fence"
    108  1.3  mrg   [(match_operand:SI 0 "const_int_operand")]		;; model
    109  1.3  mrg   ""
    110  1.3  mrg {
    111  1.5  mrg   enum memmodel model = memmodel_from_int (INTVAL (operands[0]));
    112  1.3  mrg 
    113  1.3  mrg   /* Unless this is a SEQ_CST fence, the i386 memory model is strong
    114  1.3  mrg      enough not to require barriers of any kind.  */
    115  1.5  mrg   if (is_mm_seq_cst (model))
    116  1.3  mrg     {
    117  1.3  mrg       rtx (*mfence_insn)(rtx);
    118  1.3  mrg       rtx mem;
    119  1.3  mrg 
    120  1.3  mrg       if (TARGET_64BIT || TARGET_SSE2)
    121  1.3  mrg 	mfence_insn = gen_mfence_sse2;
    122  1.3  mrg       else
    123  1.3  mrg 	mfence_insn = gen_mfence_nosse;
    124  1.3  mrg 
    125  1.3  mrg       mem = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
    126  1.3  mrg       MEM_VOLATILE_P (mem) = 1;
    127  1.3  mrg 
    128  1.3  mrg       emit_insn (mfence_insn (mem));
    129  1.3  mrg     }
    130  1.3  mrg   DONE;
    131  1.3  mrg })
    132  1.3  mrg 
    133  1.3  mrg ;; ??? From volume 3 section 8.1.1 Guaranteed Atomic Operations,
    134  1.3  mrg ;; Only beginning at Pentium family processors do we get any guarantee of
    135  1.3  mrg ;; atomicity in aligned 64-bit quantities.  Beginning at P6, we get a
    136  1.3  mrg ;; guarantee for 64-bit accesses that do not cross a cacheline boundary.
    137  1.3  mrg ;;
    138  1.3  mrg ;; Note that the TARGET_CMPXCHG8B test below is a stand-in for "Pentium".
    139  1.3  mrg ;;
    140  1.3  mrg ;; Importantly, *no* processor makes atomicity guarantees for larger
    141  1.3  mrg ;; accesses.  In particular, there's no way to perform an atomic TImode
    142  1.3  mrg ;; move, despite the apparent applicability of MOVDQA et al.
    143  1.3  mrg 
    144  1.3  mrg (define_mode_iterator ATOMIC
    145  1.3  mrg    [QI HI SI
    146  1.3  mrg     (DI "TARGET_64BIT || (TARGET_CMPXCHG8B && (TARGET_80387 || TARGET_SSE))")
    147  1.3  mrg    ])
    148  1.3  mrg 
    149  1.3  mrg (define_expand "atomic_load<mode>"
    150  1.5  mrg   [(set (match_operand:ATOMIC 0 "nonimmediate_operand")
    151  1.3  mrg 	(unspec:ATOMIC [(match_operand:ATOMIC 1 "memory_operand")
    152  1.3  mrg 			(match_operand:SI 2 "const_int_operand")]
    153  1.5  mrg 		       UNSPEC_LDA))]
    154  1.3  mrg   ""
    155  1.3  mrg {
    156  1.3  mrg   /* For DImode on 32-bit, we can use the FPU to perform the load.  */
    157  1.3  mrg   if (<MODE>mode == DImode && !TARGET_64BIT)
    158  1.3  mrg     emit_insn (gen_atomic_loaddi_fpu
    159  1.3  mrg 	       (operands[0], operands[1],
    160  1.3  mrg 	        assign_386_stack_local (DImode, SLOT_TEMP)));
    161  1.3  mrg   else
    162  1.5  mrg     {
    163  1.5  mrg       rtx dst = operands[0];
    164  1.5  mrg 
    165  1.5  mrg       if (MEM_P (dst))
    166  1.5  mrg 	dst = gen_reg_rtx (<MODE>mode);
    167  1.5  mrg 
    168  1.5  mrg       emit_move_insn (dst, operands[1]);
    169  1.5  mrg 
    170  1.5  mrg       /* Fix up the destination if needed.  */
    171  1.5  mrg       if (dst != operands[0])
    172  1.5  mrg 	emit_move_insn (operands[0], dst);
    173  1.5  mrg     }
    174  1.3  mrg   DONE;
    175  1.3  mrg })
    176  1.3  mrg 
    177  1.3  mrg (define_insn_and_split "atomic_loaddi_fpu"
    178  1.3  mrg   [(set (match_operand:DI 0 "nonimmediate_operand" "=x,m,?r")
    179  1.3  mrg 	(unspec:DI [(match_operand:DI 1 "memory_operand" "m,m,m")]
    180  1.5  mrg 		   UNSPEC_LDA))
    181  1.3  mrg    (clobber (match_operand:DI 2 "memory_operand" "=X,X,m"))
    182  1.3  mrg    (clobber (match_scratch:DF 3 "=X,xf,xf"))]
    183  1.3  mrg   "!TARGET_64BIT && (TARGET_80387 || TARGET_SSE)"
    184  1.3  mrg   "#"
    185  1.3  mrg   "&& reload_completed"
    186  1.3  mrg   [(const_int 0)]
    187  1.3  mrg {
    188  1.3  mrg   rtx dst = operands[0], src = operands[1];
    189  1.3  mrg   rtx mem = operands[2], tmp = operands[3];
    190  1.3  mrg 
    191  1.3  mrg   if (SSE_REG_P (dst))
    192  1.3  mrg     emit_move_insn (dst, src);
    193  1.3  mrg   else
    194  1.3  mrg     {
    195  1.3  mrg       if (MEM_P (dst))
    196  1.3  mrg 	mem = dst;
    197  1.3  mrg 
    198  1.3  mrg       if (STACK_REG_P (tmp))
    199  1.3  mrg         {
    200  1.3  mrg 	  emit_insn (gen_loaddi_via_fpu (tmp, src));
    201  1.3  mrg 	  emit_insn (gen_storedi_via_fpu (mem, tmp));
    202  1.3  mrg 	}
    203  1.3  mrg       else
    204  1.3  mrg 	{
    205  1.8  mrg 	  emit_insn (gen_loaddi_via_sse (tmp, src));
    206  1.8  mrg 	  emit_insn (gen_storedi_via_sse (mem, tmp));
    207  1.3  mrg 	}
    208  1.3  mrg 
    209  1.3  mrg       if (mem != dst)
    210  1.3  mrg 	emit_move_insn (dst, mem);
    211  1.3  mrg     }
    212  1.3  mrg   DONE;
    213  1.3  mrg })
    214  1.3  mrg 
    215  1.8  mrg (define_peephole2
    216  1.8  mrg   [(set (match_operand:DF 0 "fp_register_operand")
    217  1.8  mrg 	(unspec:DF [(match_operand:DI 1 "memory_operand")]
    218  1.8  mrg 		   UNSPEC_FILD_ATOMIC))
    219  1.8  mrg    (set (match_operand:DI 2 "memory_operand")
    220  1.8  mrg 	(unspec:DI [(match_dup 0)]
    221  1.8  mrg 		   UNSPEC_FIST_ATOMIC))
    222  1.8  mrg    (set (match_operand:DF 3 "fp_register_operand")
    223  1.8  mrg 	(match_operand:DF 4 "memory_operand"))]
    224  1.8  mrg   "!TARGET_64BIT
    225  1.8  mrg    && peep2_reg_dead_p (2, operands[0])
    226  1.8  mrg    && rtx_equal_p (operands[4], adjust_address_nv (operands[2], DFmode, 0))"
    227  1.8  mrg   [(set (match_dup 3) (match_dup 5))]
    228  1.8  mrg   "operands[5] = gen_lowpart (DFmode, operands[1]);")
    229  1.8  mrg 
    230  1.8  mrg (define_peephole2
    231  1.8  mrg   [(set (match_operand:DF 0 "sse_reg_operand")
    232  1.8  mrg 	(unspec:DF [(match_operand:DI 1 "memory_operand")]
    233  1.8  mrg 		   UNSPEC_LDX_ATOMIC))
    234  1.8  mrg    (set (match_operand:DI 2 "memory_operand")
    235  1.8  mrg 	(unspec:DI [(match_dup 0)]
    236  1.8  mrg 		   UNSPEC_STX_ATOMIC))
    237  1.8  mrg    (set (match_operand:DF 3 "fp_register_operand")
    238  1.8  mrg 	(match_operand:DF 4 "memory_operand"))]
    239  1.8  mrg   "!TARGET_64BIT
    240  1.8  mrg    && peep2_reg_dead_p (2, operands[0])
    241  1.8  mrg    && rtx_equal_p (operands[4], adjust_address_nv (operands[2], DFmode, 0))"
    242  1.8  mrg   [(set (match_dup 3) (match_dup 5))]
    243  1.8  mrg   "operands[5] = gen_lowpart (DFmode, operands[1]);")
    244  1.8  mrg 
    245  1.3  mrg (define_expand "atomic_store<mode>"
    246  1.3  mrg   [(set (match_operand:ATOMIC 0 "memory_operand")
    247  1.5  mrg 	(unspec:ATOMIC [(match_operand:ATOMIC 1 "nonimmediate_operand")
    248  1.3  mrg 			(match_operand:SI 2 "const_int_operand")]
    249  1.5  mrg 		       UNSPEC_STA))]
    250  1.3  mrg   ""
    251  1.3  mrg {
    252  1.5  mrg   enum memmodel model = memmodel_from_int (INTVAL (operands[2]));
    253  1.3  mrg 
    254  1.3  mrg   if (<MODE>mode == DImode && !TARGET_64BIT)
    255  1.3  mrg     {
    256  1.3  mrg       /* For DImode on 32-bit, we can use the FPU to perform the store.  */
    257  1.3  mrg       /* Note that while we could perform a cmpxchg8b loop, that turns
    258  1.3  mrg 	 out to be significantly larger than this plus a barrier.  */
    259  1.3  mrg       emit_insn (gen_atomic_storedi_fpu
    260  1.3  mrg 		 (operands[0], operands[1],
    261  1.3  mrg 	          assign_386_stack_local (DImode, SLOT_TEMP)));
    262  1.3  mrg     }
    263  1.3  mrg   else
    264  1.3  mrg     {
    265  1.5  mrg       operands[1] = force_reg (<MODE>mode, operands[1]);
    266  1.5  mrg 
    267  1.3  mrg       /* For seq-cst stores, when we lack MFENCE, use XCHG.  */
    268  1.5  mrg       if (is_mm_seq_cst (model) && !(TARGET_64BIT || TARGET_SSE2))
    269  1.3  mrg 	{
    270  1.3  mrg 	  emit_insn (gen_atomic_exchange<mode> (gen_reg_rtx (<MODE>mode),
    271  1.3  mrg 						operands[0], operands[1],
    272  1.3  mrg 						operands[2]));
    273  1.3  mrg 	  DONE;
    274  1.3  mrg 	}
    275  1.3  mrg 
    276  1.3  mrg       /* Otherwise use a store.  */
    277  1.3  mrg       emit_insn (gen_atomic_store<mode>_1 (operands[0], operands[1],
    278  1.3  mrg 					   operands[2]));
    279  1.3  mrg     }
    280  1.3  mrg   /* ... followed by an MFENCE, if required.  */
    281  1.5  mrg   if (is_mm_seq_cst (model))
    282  1.3  mrg     emit_insn (gen_mem_thread_fence (operands[2]));
    283  1.3  mrg   DONE;
    284  1.3  mrg })
    285  1.3  mrg 
    286  1.3  mrg (define_insn "atomic_store<mode>_1"
    287  1.3  mrg   [(set (match_operand:SWI 0 "memory_operand" "=m")
    288  1.3  mrg 	(unspec:SWI [(match_operand:SWI 1 "<nonmemory_operand>" "<r><i>")
    289  1.3  mrg 		     (match_operand:SI 2 "const_int_operand")]
    290  1.5  mrg 		    UNSPEC_STA))]
    291  1.3  mrg   ""
    292  1.3  mrg   "%K2mov{<imodesuffix>}\t{%1, %0|%0, %1}")
    293  1.3  mrg 
    294  1.3  mrg (define_insn_and_split "atomic_storedi_fpu"
    295  1.3  mrg   [(set (match_operand:DI 0 "memory_operand" "=m,m,m")
    296  1.5  mrg 	(unspec:DI [(match_operand:DI 1 "nonimmediate_operand" "x,m,?r")]
    297  1.5  mrg 		   UNSPEC_STA))
    298  1.3  mrg    (clobber (match_operand:DI 2 "memory_operand" "=X,X,m"))
    299  1.3  mrg    (clobber (match_scratch:DF 3 "=X,xf,xf"))]
    300  1.3  mrg   "!TARGET_64BIT && (TARGET_80387 || TARGET_SSE)"
    301  1.3  mrg   "#"
    302  1.3  mrg   "&& reload_completed"
    303  1.3  mrg   [(const_int 0)]
    304  1.3  mrg {
    305  1.3  mrg   rtx dst = operands[0], src = operands[1];
    306  1.3  mrg   rtx mem = operands[2], tmp = operands[3];
    307  1.3  mrg 
    308  1.8  mrg   if (SSE_REG_P (src))
    309  1.8  mrg     emit_move_insn (dst, src);
    310  1.8  mrg   else
    311  1.3  mrg     {
    312  1.3  mrg       if (REG_P (src))
    313  1.3  mrg 	{
    314  1.3  mrg 	  emit_move_insn (mem, src);
    315  1.3  mrg 	  src = mem;
    316  1.3  mrg 	}
    317  1.3  mrg 
    318  1.3  mrg       if (STACK_REG_P (tmp))
    319  1.3  mrg 	{
    320  1.3  mrg 	  emit_insn (gen_loaddi_via_fpu (tmp, src));
    321  1.3  mrg 	  emit_insn (gen_storedi_via_fpu (dst, tmp));
    322  1.3  mrg 	}
    323  1.3  mrg       else
    324  1.3  mrg 	{
    325  1.8  mrg 	  emit_insn (gen_loaddi_via_sse (tmp, src));
    326  1.8  mrg 	  emit_insn (gen_storedi_via_sse (dst, tmp));
    327  1.3  mrg 	}
    328  1.3  mrg     }
    329  1.3  mrg   DONE;
    330  1.3  mrg })
    331  1.3  mrg 
    332  1.8  mrg (define_peephole2
    333  1.8  mrg   [(set (match_operand:DF 0 "memory_operand")
    334  1.8  mrg 	(match_operand:DF 1 "fp_register_operand"))
    335  1.8  mrg    (set (match_operand:DF 2 "fp_register_operand")
    336  1.8  mrg 	(unspec:DF [(match_operand:DI 3 "memory_operand")]
    337  1.8  mrg 		   UNSPEC_FILD_ATOMIC))
    338  1.8  mrg    (set (match_operand:DI 4 "memory_operand")
    339  1.8  mrg 	(unspec:DI [(match_dup 2)]
    340  1.8  mrg 		   UNSPEC_FIST_ATOMIC))]
    341  1.8  mrg   "!TARGET_64BIT
    342  1.8  mrg    && peep2_reg_dead_p (3, operands[2])
    343  1.8  mrg    && rtx_equal_p (operands[0], adjust_address_nv (operands[3], DFmode, 0))"
    344  1.8  mrg   [(set (match_dup 5) (match_dup 1))]
    345  1.8  mrg   "operands[5] = gen_lowpart (DFmode, operands[4]);")
    346  1.8  mrg 
    347  1.8  mrg (define_peephole2
    348  1.8  mrg   [(set (match_operand:DF 0 "memory_operand")
    349  1.8  mrg 	(match_operand:DF 1 "fp_register_operand"))
    350  1.8  mrg    (set (match_operand:DF 2 "sse_reg_operand")
    351  1.8  mrg 	(unspec:DF [(match_operand:DI 3 "memory_operand")]
    352  1.8  mrg 		   UNSPEC_LDX_ATOMIC))
    353  1.8  mrg    (set (match_operand:DI 4 "memory_operand")
    354  1.8  mrg 	(unspec:DI [(match_dup 2)]
    355  1.8  mrg 		   UNSPEC_STX_ATOMIC))]
    356  1.8  mrg   "!TARGET_64BIT
    357  1.8  mrg    && peep2_reg_dead_p (3, operands[2])
    358  1.8  mrg    && rtx_equal_p (operands[0], adjust_address_nv (operands[3], DFmode, 0))"
    359  1.8  mrg   [(set (match_dup 5) (match_dup 1))]
    360  1.8  mrg   "operands[5] = gen_lowpart (DFmode, operands[4]);")
    361  1.8  mrg 
    362  1.3  mrg ;; ??? You'd think that we'd be able to perform this via FLOAT + FIX_TRUNC
    363  1.3  mrg ;; operations.  But the fix_trunc patterns want way more setup than we want
    364  1.3  mrg ;; to provide.  Note that the scratch is DFmode instead of XFmode in order
    365  1.3  mrg ;; to make it easy to allocate a scratch in either SSE or FP_REGs above.
    366  1.3  mrg 
    367  1.3  mrg (define_insn "loaddi_via_fpu"
    368  1.3  mrg   [(set (match_operand:DF 0 "register_operand" "=f")
    369  1.5  mrg 	(unspec:DF [(match_operand:DI 1 "memory_operand" "m")]
    370  1.5  mrg 		   UNSPEC_FILD_ATOMIC))]
    371  1.3  mrg   "TARGET_80387"
    372  1.3  mrg   "fild%Z1\t%1"
    373  1.3  mrg   [(set_attr "type" "fmov")
    374  1.3  mrg    (set_attr "mode" "DF")
    375  1.3  mrg    (set_attr "fp_int_src" "true")])
    376  1.3  mrg 
    377  1.3  mrg (define_insn "storedi_via_fpu"
    378  1.3  mrg   [(set (match_operand:DI 0 "memory_operand" "=m")
    379  1.5  mrg 	(unspec:DI [(match_operand:DF 1 "register_operand" "f")]
    380  1.5  mrg 		   UNSPEC_FIST_ATOMIC))]
    381  1.3  mrg   "TARGET_80387"
    382  1.3  mrg {
    383  1.3  mrg   gcc_assert (find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != NULL_RTX);
    384  1.3  mrg 
    385  1.3  mrg   return "fistp%Z0\t%0";
    386  1.3  mrg }
    387  1.3  mrg   [(set_attr "type" "fmov")
    388  1.3  mrg    (set_attr "mode" "DI")])
    389  1.3  mrg 
    390  1.8  mrg (define_insn "loaddi_via_sse"
    391  1.8  mrg   [(set (match_operand:DF 0 "register_operand" "=x")
    392  1.8  mrg 	(unspec:DF [(match_operand:DI 1 "memory_operand" "m")]
    393  1.8  mrg 		   UNSPEC_LDX_ATOMIC))]
    394  1.8  mrg   "TARGET_SSE"
    395  1.8  mrg {
    396  1.8  mrg   if (TARGET_SSE2)
    397  1.8  mrg     return "%vmovq\t{%1, %0|%0, %1}";
    398  1.8  mrg   return "movlps\t{%1, %0|%0, %1}";
    399  1.8  mrg }
    400  1.8  mrg   [(set_attr "type" "ssemov")
    401  1.8  mrg    (set_attr "mode" "DI")])
    402  1.8  mrg 
    403  1.8  mrg (define_insn "storedi_via_sse"
    404  1.8  mrg   [(set (match_operand:DI 0 "memory_operand" "=m")
    405  1.8  mrg 	(unspec:DI [(match_operand:DF 1 "register_operand" "x")]
    406  1.8  mrg 		   UNSPEC_STX_ATOMIC))]
    407  1.8  mrg   "TARGET_SSE"
    408  1.8  mrg {
    409  1.8  mrg   if (TARGET_SSE2)
    410  1.8  mrg     return "%vmovq\t{%1, %0|%0, %1}";
    411  1.8  mrg   return "movlps\t{%1, %0|%0, %1}";
    412  1.8  mrg }
    413  1.8  mrg   [(set_attr "type" "ssemov")
    414  1.8  mrg    (set_attr "mode" "DI")])
    415  1.8  mrg 
    416  1.3  mrg (define_expand "atomic_compare_and_swap<mode>"
    417  1.3  mrg   [(match_operand:QI 0 "register_operand")	;; bool success output
    418  1.3  mrg    (match_operand:SWI124 1 "register_operand")	;; oldval output
    419  1.3  mrg    (match_operand:SWI124 2 "memory_operand")	;; memory
    420  1.3  mrg    (match_operand:SWI124 3 "register_operand")	;; expected input
    421  1.3  mrg    (match_operand:SWI124 4 "register_operand")	;; newval input
    422  1.3  mrg    (match_operand:SI 5 "const_int_operand")	;; is_weak
    423  1.3  mrg    (match_operand:SI 6 "const_int_operand")	;; success model
    424  1.3  mrg    (match_operand:SI 7 "const_int_operand")]	;; failure model
    425  1.3  mrg   "TARGET_CMPXCHG"
    426  1.3  mrg {
    427  1.3  mrg   emit_insn
    428  1.3  mrg    (gen_atomic_compare_and_swap<mode>_1
    429  1.3  mrg     (operands[1], operands[2], operands[3], operands[4], operands[6]));
    430  1.3  mrg   ix86_expand_setcc (operands[0], EQ, gen_rtx_REG (CCZmode, FLAGS_REG),
    431  1.3  mrg 		     const0_rtx);
    432  1.3  mrg   DONE;
    433  1.3  mrg })
    434  1.3  mrg 
    435  1.3  mrg (define_mode_iterator CASMODE
    436  1.3  mrg   [(DI "TARGET_64BIT || TARGET_CMPXCHG8B")
    437  1.3  mrg    (TI "TARGET_64BIT && TARGET_CMPXCHG16B")])
    438  1.3  mrg (define_mode_attr CASHMODE [(DI "SI") (TI "DI")])
    439  1.3  mrg 
    440  1.3  mrg (define_expand "atomic_compare_and_swap<mode>"
    441  1.3  mrg   [(match_operand:QI 0 "register_operand")	;; bool success output
    442  1.3  mrg    (match_operand:CASMODE 1 "register_operand")	;; oldval output
    443  1.3  mrg    (match_operand:CASMODE 2 "memory_operand")	;; memory
    444  1.3  mrg    (match_operand:CASMODE 3 "register_operand")	;; expected input
    445  1.3  mrg    (match_operand:CASMODE 4 "register_operand")	;; newval input
    446  1.3  mrg    (match_operand:SI 5 "const_int_operand")	;; is_weak
    447  1.3  mrg    (match_operand:SI 6 "const_int_operand")	;; success model
    448  1.3  mrg    (match_operand:SI 7 "const_int_operand")]	;; failure model
    449  1.1  mrg   "TARGET_CMPXCHG"
    450  1.1  mrg {
    451  1.3  mrg   if (<MODE>mode == DImode && TARGET_64BIT)
    452  1.3  mrg     {
    453  1.3  mrg       emit_insn
    454  1.3  mrg        (gen_atomic_compare_and_swapdi_1
    455  1.3  mrg 	(operands[1], operands[2], operands[3], operands[4], operands[6]));
    456  1.3  mrg     }
    457  1.3  mrg   else
    458  1.1  mrg     {
    459  1.5  mrg       machine_mode hmode = <CASHMODE>mode;
    460  1.3  mrg 
    461  1.3  mrg       emit_insn
    462  1.3  mrg        (gen_atomic_compare_and_swap<mode>_doubleword
    463  1.5  mrg         (operands[1], operands[2], operands[3],
    464  1.5  mrg 	 gen_lowpart (hmode, operands[4]), gen_highpart (hmode, operands[4]),
    465  1.5  mrg 	 operands[6]));
    466  1.1  mrg     }
    467  1.3  mrg 
    468  1.3  mrg   ix86_expand_setcc (operands[0], EQ, gen_rtx_REG (CCZmode, FLAGS_REG),
    469  1.3  mrg 		     const0_rtx);
    470  1.3  mrg   DONE;
    471  1.1  mrg })
    472  1.1  mrg 
    473  1.5  mrg ;; For double-word compare and swap, we are obliged to play tricks with
    474  1.5  mrg ;; the input newval (op3:op4) because the Intel register numbering does
    475  1.5  mrg ;; not match the gcc register numbering, so the pair must be CX:BX.
    476  1.5  mrg 
    477  1.5  mrg (define_mode_attr doublemodesuffix [(SI "8") (DI "16")])
    478  1.5  mrg 
    479  1.5  mrg (define_insn "atomic_compare_and_swap<dwi>_doubleword"
    480  1.5  mrg   [(set (match_operand:<DWI> 0 "register_operand" "=A")
    481  1.5  mrg 	(unspec_volatile:<DWI>
    482  1.5  mrg 	  [(match_operand:<DWI> 1 "memory_operand" "+m")
    483  1.5  mrg 	   (match_operand:<DWI> 2 "register_operand" "0")
    484  1.5  mrg 	   (match_operand:DWIH 3 "register_operand" "b")
    485  1.5  mrg 	   (match_operand:DWIH 4 "register_operand" "c")
    486  1.5  mrg 	   (match_operand:SI 5 "const_int_operand")]
    487  1.5  mrg 	  UNSPECV_CMPXCHG))
    488  1.5  mrg    (set (match_dup 1)
    489  1.5  mrg 	(unspec_volatile:<DWI> [(const_int 0)] UNSPECV_CMPXCHG))
    490  1.5  mrg    (set (reg:CCZ FLAGS_REG)
    491  1.5  mrg         (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))]
    492  1.5  mrg   "TARGET_CMPXCHG<doublemodesuffix>B"
    493  1.5  mrg   "lock{%;} %K5cmpxchg<doublemodesuffix>b\t%1")
    494  1.5  mrg 
    495  1.3  mrg (define_insn "atomic_compare_and_swap<mode>_1"
    496  1.1  mrg   [(set (match_operand:SWI 0 "register_operand" "=a")
    497  1.1  mrg 	(unspec_volatile:SWI
    498  1.3  mrg 	  [(match_operand:SWI 1 "memory_operand" "+m")
    499  1.3  mrg 	   (match_operand:SWI 2 "register_operand" "0")
    500  1.3  mrg 	   (match_operand:SWI 3 "register_operand" "<r>")
    501  1.3  mrg 	   (match_operand:SI 4 "const_int_operand")]
    502  1.1  mrg 	  UNSPECV_CMPXCHG))
    503  1.3  mrg    (set (match_dup 1)
    504  1.3  mrg 	(unspec_volatile:SWI [(const_int 0)] UNSPECV_CMPXCHG))
    505  1.1  mrg    (set (reg:CCZ FLAGS_REG)
    506  1.3  mrg         (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))]
    507  1.1  mrg   "TARGET_CMPXCHG"
    508  1.3  mrg   "lock{%;} %K4cmpxchg{<imodesuffix>}\t{%3, %1|%1, %3}")
    509  1.1  mrg 
    510  1.3  mrg ;; For operand 2 nonmemory_operand predicate is used instead of
    511  1.3  mrg ;; register_operand to allow combiner to better optimize atomic
    512  1.3  mrg ;; additions of constants.
    513  1.3  mrg (define_insn "atomic_fetch_add<mode>"
    514  1.1  mrg   [(set (match_operand:SWI 0 "register_operand" "=<r>")
    515  1.1  mrg 	(unspec_volatile:SWI
    516  1.3  mrg 	  [(match_operand:SWI 1 "memory_operand" "+m")
    517  1.3  mrg 	   (match_operand:SI 3 "const_int_operand")]		;; model
    518  1.3  mrg 	  UNSPECV_XCHG))
    519  1.1  mrg    (set (match_dup 1)
    520  1.1  mrg 	(plus:SWI (match_dup 1)
    521  1.3  mrg 		  (match_operand:SWI 2 "nonmemory_operand" "0")))
    522  1.1  mrg    (clobber (reg:CC FLAGS_REG))]
    523  1.1  mrg   "TARGET_XADD"
    524  1.3  mrg   "lock{%;} %K3xadd{<imodesuffix>}\t{%0, %1|%1, %0}")
    525  1.3  mrg 
    526  1.3  mrg ;; This peephole2 and following insn optimize
    527  1.3  mrg ;; __sync_fetch_and_add (x, -N) == N into just lock {add,sub,inc,dec}
    528  1.3  mrg ;; followed by testing of flags instead of lock xadd and comparisons.
    529  1.3  mrg (define_peephole2
    530  1.3  mrg   [(set (match_operand:SWI 0 "register_operand")
    531  1.3  mrg 	(match_operand:SWI 2 "const_int_operand"))
    532  1.3  mrg    (parallel [(set (match_dup 0)
    533  1.3  mrg 		   (unspec_volatile:SWI
    534  1.3  mrg 		     [(match_operand:SWI 1 "memory_operand")
    535  1.3  mrg 		      (match_operand:SI 4 "const_int_operand")]
    536  1.3  mrg 		     UNSPECV_XCHG))
    537  1.3  mrg 	      (set (match_dup 1)
    538  1.3  mrg 		   (plus:SWI (match_dup 1)
    539  1.3  mrg 			     (match_dup 0)))
    540  1.3  mrg 	      (clobber (reg:CC FLAGS_REG))])
    541  1.3  mrg    (set (reg:CCZ FLAGS_REG)
    542  1.3  mrg 	(compare:CCZ (match_dup 0)
    543  1.3  mrg 		     (match_operand:SWI 3 "const_int_operand")))]
    544  1.3  mrg   "peep2_reg_dead_p (3, operands[0])
    545  1.3  mrg    && (unsigned HOST_WIDE_INT) INTVAL (operands[2])
    546  1.3  mrg       == -(unsigned HOST_WIDE_INT) INTVAL (operands[3])
    547  1.3  mrg    && !reg_overlap_mentioned_p (operands[0], operands[1])"
    548  1.3  mrg   [(parallel [(set (reg:CCZ FLAGS_REG)
    549  1.3  mrg 		   (compare:CCZ
    550  1.3  mrg 		     (unspec_volatile:SWI [(match_dup 1) (match_dup 4)]
    551  1.3  mrg 					  UNSPECV_XCHG)
    552  1.3  mrg 		     (match_dup 3)))
    553  1.3  mrg 	      (set (match_dup 1)
    554  1.3  mrg 		   (plus:SWI (match_dup 1)
    555  1.3  mrg 			     (match_dup 2)))])])
    556  1.3  mrg 
    557  1.8  mrg ;; Likewise, but for the -Os special case of *mov<mode>_or.
    558  1.8  mrg (define_peephole2
    559  1.8  mrg   [(parallel [(set (match_operand:SWI 0 "register_operand")
    560  1.8  mrg 		   (match_operand:SWI 2 "constm1_operand"))
    561  1.8  mrg 	      (clobber (reg:CC FLAGS_REG))])
    562  1.8  mrg    (parallel [(set (match_dup 0)
    563  1.8  mrg 		   (unspec_volatile:SWI
    564  1.8  mrg 		     [(match_operand:SWI 1 "memory_operand")
    565  1.8  mrg 		      (match_operand:SI 4 "const_int_operand")]
    566  1.8  mrg 		     UNSPECV_XCHG))
    567  1.8  mrg 	      (set (match_dup 1)
    568  1.8  mrg 		   (plus:SWI (match_dup 1)
    569  1.8  mrg 			     (match_dup 0)))
    570  1.8  mrg 	      (clobber (reg:CC FLAGS_REG))])
    571  1.8  mrg    (set (reg:CCZ FLAGS_REG)
    572  1.8  mrg 	(compare:CCZ (match_dup 0)
    573  1.8  mrg 		     (match_operand:SWI 3 "const_int_operand")))]
    574  1.8  mrg   "peep2_reg_dead_p (3, operands[0])
    575  1.8  mrg    && (unsigned HOST_WIDE_INT) INTVAL (operands[2])
    576  1.8  mrg       == -(unsigned HOST_WIDE_INT) INTVAL (operands[3])
    577  1.8  mrg    && !reg_overlap_mentioned_p (operands[0], operands[1])"
    578  1.8  mrg   [(parallel [(set (reg:CCZ FLAGS_REG)
    579  1.8  mrg 		   (compare:CCZ
    580  1.8  mrg 		     (unspec_volatile:SWI [(match_dup 1) (match_dup 4)]
    581  1.8  mrg 					  UNSPECV_XCHG)
    582  1.8  mrg 		     (match_dup 3)))
    583  1.8  mrg 	      (set (match_dup 1)
    584  1.8  mrg 		   (plus:SWI (match_dup 1)
    585  1.8  mrg 			     (match_dup 2)))])])
    586  1.8  mrg 
    587  1.3  mrg (define_insn "*atomic_fetch_add_cmp<mode>"
    588  1.3  mrg   [(set (reg:CCZ FLAGS_REG)
    589  1.3  mrg 	(compare:CCZ
    590  1.3  mrg 	  (unspec_volatile:SWI
    591  1.3  mrg 	    [(match_operand:SWI 0 "memory_operand" "+m")
    592  1.3  mrg 	     (match_operand:SI 3 "const_int_operand")]		;; model
    593  1.3  mrg 	    UNSPECV_XCHG)
    594  1.3  mrg 	  (match_operand:SWI 2 "const_int_operand" "i")))
    595  1.3  mrg    (set (match_dup 0)
    596  1.3  mrg 	(plus:SWI (match_dup 0)
    597  1.3  mrg 		  (match_operand:SWI 1 "const_int_operand" "i")))]
    598  1.3  mrg   "(unsigned HOST_WIDE_INT) INTVAL (operands[1])
    599  1.3  mrg    == -(unsigned HOST_WIDE_INT) INTVAL (operands[2])"
    600  1.3  mrg {
    601  1.3  mrg   if (incdec_operand (operands[1], <MODE>mode))
    602  1.3  mrg     {
    603  1.3  mrg       if (operands[1] == const1_rtx)
    604  1.3  mrg 	return "lock{%;} %K3inc{<imodesuffix>}\t%0";
    605  1.3  mrg       else
    606  1.3  mrg 	{
    607  1.3  mrg 	  gcc_assert (operands[1] == constm1_rtx);
    608  1.3  mrg 	  return "lock{%;} %K3dec{<imodesuffix>}\t%0";
    609  1.3  mrg 	}
    610  1.3  mrg     }
    611  1.3  mrg 
    612  1.3  mrg   if (x86_maybe_negate_const_int (&operands[1], <MODE>mode))
    613  1.3  mrg     return "lock{%;} %K3sub{<imodesuffix>}\t{%1, %0|%0, %1}";
    614  1.3  mrg 
    615  1.3  mrg   return "lock{%;} %K3add{<imodesuffix>}\t{%1, %0|%0, %1}";
    616  1.3  mrg })
    617  1.1  mrg 
    618  1.1  mrg ;; Recall that xchg implicitly sets LOCK#, so adding it again wastes space.
    619  1.3  mrg ;; In addition, it is always a full barrier, so we can ignore the memory model.
    620  1.3  mrg (define_insn "atomic_exchange<mode>"
    621  1.3  mrg   [(set (match_operand:SWI 0 "register_operand" "=<r>")		;; output
    622  1.1  mrg 	(unspec_volatile:SWI
    623  1.3  mrg 	  [(match_operand:SWI 1 "memory_operand" "+m")		;; memory
    624  1.3  mrg 	   (match_operand:SI 3 "const_int_operand")]		;; model
    625  1.3  mrg 	  UNSPECV_XCHG))
    626  1.1  mrg    (set (match_dup 1)
    627  1.3  mrg 	(match_operand:SWI 2 "register_operand" "0"))]		;; input
    628  1.1  mrg   ""
    629  1.3  mrg   "%K3xchg{<imodesuffix>}\t{%1, %0|%0, %1}")
    630  1.1  mrg 
    631  1.3  mrg (define_insn "atomic_add<mode>"
    632  1.1  mrg   [(set (match_operand:SWI 0 "memory_operand" "+m")
    633  1.1  mrg 	(unspec_volatile:SWI
    634  1.1  mrg 	  [(plus:SWI (match_dup 0)
    635  1.3  mrg 		     (match_operand:SWI 1 "nonmemory_operand" "<r><i>"))
    636  1.3  mrg 	   (match_operand:SI 2 "const_int_operand")]		;; model
    637  1.1  mrg 	  UNSPECV_LOCK))
    638  1.1  mrg    (clobber (reg:CC FLAGS_REG))]
    639  1.1  mrg   ""
    640  1.1  mrg {
    641  1.3  mrg   if (incdec_operand (operands[1], <MODE>mode))
    642  1.1  mrg     {
    643  1.1  mrg       if (operands[1] == const1_rtx)
    644  1.3  mrg 	return "lock{%;} %K2inc{<imodesuffix>}\t%0";
    645  1.3  mrg       else
    646  1.3  mrg 	{
    647  1.3  mrg 	  gcc_assert (operands[1] == constm1_rtx);
    648  1.3  mrg 	  return "lock{%;} %K2dec{<imodesuffix>}\t%0";
    649  1.3  mrg 	}
    650  1.1  mrg     }
    651  1.1  mrg 
    652  1.3  mrg   if (x86_maybe_negate_const_int (&operands[1], <MODE>mode))
    653  1.3  mrg     return "lock{%;} %K2sub{<imodesuffix>}\t{%1, %0|%0, %1}";
    654  1.3  mrg 
    655  1.3  mrg   return "lock{%;} %K2add{<imodesuffix>}\t{%1, %0|%0, %1}";
    656  1.1  mrg })
    657  1.1  mrg 
    658  1.3  mrg (define_insn "atomic_sub<mode>"
    659  1.1  mrg   [(set (match_operand:SWI 0 "memory_operand" "+m")
    660  1.1  mrg 	(unspec_volatile:SWI
    661  1.1  mrg 	  [(minus:SWI (match_dup 0)
    662  1.3  mrg 		      (match_operand:SWI 1 "nonmemory_operand" "<r><i>"))
    663  1.3  mrg 	   (match_operand:SI 2 "const_int_operand")]		;; model
    664  1.1  mrg 	  UNSPECV_LOCK))
    665  1.1  mrg    (clobber (reg:CC FLAGS_REG))]
    666  1.1  mrg   ""
    667  1.1  mrg {
    668  1.3  mrg   if (incdec_operand (operands[1], <MODE>mode))
    669  1.1  mrg     {
    670  1.1  mrg       if (operands[1] == const1_rtx)
    671  1.3  mrg 	return "lock{%;} %K2dec{<imodesuffix>}\t%0";
    672  1.3  mrg       else
    673  1.3  mrg 	{
    674  1.3  mrg 	  gcc_assert (operands[1] == constm1_rtx);
    675  1.3  mrg 	  return "lock{%;} %K2inc{<imodesuffix>}\t%0";
    676  1.3  mrg 	}
    677  1.1  mrg     }
    678  1.1  mrg 
    679  1.3  mrg   if (x86_maybe_negate_const_int (&operands[1], <MODE>mode))
    680  1.3  mrg     return "lock{%;} %K2add{<imodesuffix>}\t{%1, %0|%0, %1}";
    681  1.3  mrg 
    682  1.3  mrg   return "lock{%;} %K2sub{<imodesuffix>}\t{%1, %0|%0, %1}";
    683  1.1  mrg })
    684  1.1  mrg 
    685  1.3  mrg (define_insn "atomic_<logic><mode>"
    686  1.1  mrg   [(set (match_operand:SWI 0 "memory_operand" "+m")
    687  1.1  mrg 	(unspec_volatile:SWI
    688  1.1  mrg 	  [(any_logic:SWI (match_dup 0)
    689  1.3  mrg 			  (match_operand:SWI 1 "nonmemory_operand" "<r><i>"))
    690  1.3  mrg 	   (match_operand:SI 2 "const_int_operand")]		;; model
    691  1.1  mrg 	  UNSPECV_LOCK))
    692  1.1  mrg    (clobber (reg:CC FLAGS_REG))]
    693  1.1  mrg   ""
    694  1.3  mrg   "lock{%;} %K2<logic>{<imodesuffix>}\t{%1, %0|%0, %1}")
    695  1.8  mrg 
    696  1.8  mrg (define_expand "atomic_bit_test_and_set<mode>"
    697  1.8  mrg   [(match_operand:SWI248 0 "register_operand")
    698  1.8  mrg    (match_operand:SWI248 1 "memory_operand")
    699  1.8  mrg    (match_operand:SWI248 2 "nonmemory_operand")
    700  1.8  mrg    (match_operand:SI 3 "const_int_operand") ;; model
    701  1.8  mrg    (match_operand:SI 4 "const_int_operand")]
    702  1.8  mrg   ""
    703  1.8  mrg {
    704  1.8  mrg   emit_insn (gen_atomic_bit_test_and_set<mode>_1 (operands[1], operands[2],
    705  1.8  mrg 						  operands[3]));
    706  1.8  mrg   rtx tem = gen_reg_rtx (QImode);
    707  1.8  mrg   ix86_expand_setcc (tem, EQ, gen_rtx_REG (CCCmode, FLAGS_REG), const0_rtx);
    708  1.8  mrg   rtx result = convert_modes (<MODE>mode, QImode, tem, 1);
    709  1.8  mrg   if (operands[4] == const0_rtx)
    710  1.8  mrg     result = expand_simple_binop (<MODE>mode, ASHIFT, result,
    711  1.8  mrg 				  operands[2], operands[0], 0, OPTAB_DIRECT);
    712  1.8  mrg   if (result != operands[0])
    713  1.8  mrg     emit_move_insn (operands[0], result);
    714  1.8  mrg   DONE;
    715  1.8  mrg })
    716  1.8  mrg 
    717  1.8  mrg (define_insn "atomic_bit_test_and_set<mode>_1"
    718  1.8  mrg   [(set (reg:CCC FLAGS_REG)
    719  1.8  mrg 	(compare:CCC
    720  1.8  mrg 	  (unspec_volatile:SWI248
    721  1.8  mrg 	    [(match_operand:SWI248 0 "memory_operand" "+m")
    722  1.8  mrg 	     (match_operand:SI 2 "const_int_operand")]		;; model
    723  1.8  mrg 	    UNSPECV_XCHG)
    724  1.8  mrg 	  (const_int 0)))
    725  1.8  mrg    (set (zero_extract:SWI248 (match_dup 0)
    726  1.8  mrg 			     (const_int 1)
    727  1.8  mrg 			     (match_operand:SWI248 1 "nonmemory_operand" "rN"))
    728  1.8  mrg 	(const_int 1))]
    729  1.8  mrg   ""
    730  1.8  mrg   "lock{%;} %K2bts{<imodesuffix>}\t{%1, %0|%0, %1}")
    731  1.8  mrg 
    732  1.8  mrg (define_expand "atomic_bit_test_and_complement<mode>"
    733  1.8  mrg   [(match_operand:SWI248 0 "register_operand")
    734  1.8  mrg    (match_operand:SWI248 1 "memory_operand")
    735  1.8  mrg    (match_operand:SWI248 2 "nonmemory_operand")
    736  1.8  mrg    (match_operand:SI 3 "const_int_operand") ;; model
    737  1.8  mrg    (match_operand:SI 4 "const_int_operand")]
    738  1.8  mrg   ""
    739  1.8  mrg {
    740  1.8  mrg   emit_insn (gen_atomic_bit_test_and_complement<mode>_1 (operands[1],
    741  1.8  mrg 							 operands[2],
    742  1.8  mrg 							 operands[3]));
    743  1.8  mrg   rtx tem = gen_reg_rtx (QImode);
    744  1.8  mrg   ix86_expand_setcc (tem, EQ, gen_rtx_REG (CCCmode, FLAGS_REG), const0_rtx);
    745  1.8  mrg   rtx result = convert_modes (<MODE>mode, QImode, tem, 1);
    746  1.8  mrg   if (operands[4] == const0_rtx)
    747  1.8  mrg     result = expand_simple_binop (<MODE>mode, ASHIFT, result,
    748  1.8  mrg 				  operands[2], operands[0], 0, OPTAB_DIRECT);
    749  1.8  mrg   if (result != operands[0])
    750  1.8  mrg     emit_move_insn (operands[0], result);
    751  1.8  mrg   DONE;
    752  1.8  mrg })
    753  1.8  mrg 
    754  1.8  mrg (define_insn "atomic_bit_test_and_complement<mode>_1"
    755  1.8  mrg   [(set (reg:CCC FLAGS_REG)
    756  1.8  mrg 	(compare:CCC
    757  1.8  mrg 	  (unspec_volatile:SWI248
    758  1.8  mrg 	    [(match_operand:SWI248 0 "memory_operand" "+m")
    759  1.8  mrg 	     (match_operand:SI 2 "const_int_operand")]		;; model
    760  1.8  mrg 	    UNSPECV_XCHG)
    761  1.8  mrg 	  (const_int 0)))
    762  1.8  mrg    (set (zero_extract:SWI248 (match_dup 0)
    763  1.8  mrg 			     (const_int 1)
    764  1.8  mrg 			     (match_operand:SWI248 1 "nonmemory_operand" "rN"))
    765  1.8  mrg 	(not:SWI248 (zero_extract:SWI248 (match_dup 0)
    766  1.8  mrg 					 (const_int 1)
    767  1.8  mrg 					 (match_dup 1))))]
    768  1.8  mrg   ""
    769  1.8  mrg   "lock{%;} %K2btc{<imodesuffix>}\t{%1, %0|%0, %1}")
    770  1.8  mrg 
    771  1.8  mrg (define_expand "atomic_bit_test_and_reset<mode>"
    772  1.8  mrg   [(match_operand:SWI248 0 "register_operand")
    773  1.8  mrg    (match_operand:SWI248 1 "memory_operand")
    774  1.8  mrg    (match_operand:SWI248 2 "nonmemory_operand")
    775  1.8  mrg    (match_operand:SI 3 "const_int_operand") ;; model
    776  1.8  mrg    (match_operand:SI 4 "const_int_operand")]
    777  1.8  mrg   ""
    778  1.8  mrg {
    779  1.8  mrg   emit_insn (gen_atomic_bit_test_and_reset<mode>_1 (operands[1], operands[2],
    780  1.8  mrg 						    operands[3]));
    781  1.8  mrg   rtx tem = gen_reg_rtx (QImode);
    782  1.8  mrg   ix86_expand_setcc (tem, EQ, gen_rtx_REG (CCCmode, FLAGS_REG), const0_rtx);
    783  1.8  mrg   rtx result = convert_modes (<MODE>mode, QImode, tem, 1);
    784  1.8  mrg   if (operands[4] == const0_rtx)
    785  1.8  mrg     result = expand_simple_binop (<MODE>mode, ASHIFT, result,
    786  1.8  mrg 				  operands[2], operands[0], 0, OPTAB_DIRECT);
    787  1.8  mrg   if (result != operands[0])
    788  1.8  mrg     emit_move_insn (operands[0], result);
    789  1.8  mrg   DONE;
    790  1.8  mrg })
    791  1.8  mrg 
    792  1.8  mrg (define_insn "atomic_bit_test_and_reset<mode>_1"
    793  1.8  mrg   [(set (reg:CCC FLAGS_REG)
    794  1.8  mrg 	(compare:CCC
    795  1.8  mrg 	  (unspec_volatile:SWI248
    796  1.8  mrg 	    [(match_operand:SWI248 0 "memory_operand" "+m")
    797  1.8  mrg 	     (match_operand:SI 2 "const_int_operand")]		;; model
    798  1.8  mrg 	    UNSPECV_XCHG)
    799  1.8  mrg 	  (const_int 0)))
    800  1.8  mrg    (set (zero_extract:SWI248 (match_dup 0)
    801  1.8  mrg 			     (const_int 1)
    802  1.8  mrg 			     (match_operand:SWI248 1 "nonmemory_operand" "rN"))
    803  1.8  mrg 	(const_int 0))]
    804  1.8  mrg   ""
    805  1.8  mrg   "lock{%;} %K2btr{<imodesuffix>}\t{%1, %0|%0, %1}")
    806