OSDN Git Service

97c6d9e6a75b857f68c7dfbc928944ac4b6af3ef
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / i386.md
1 ;; GCC machine description for IA-32 and x86-64.
2 ;; Copyright (C) 1988, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 ;; 2001, 2002, 2003
4 ;; Free Software Foundation, Inc.
5 ;; Mostly by William Schelter.
6 ;; x86_64 support added by Jan Hubicka
7 ;;
8 ;; This file is part of GNU CC.
9 ;;
10 ;; GNU CC is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14 ;;
15 ;; GNU CC is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19 ;;
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU CC; see the file COPYING.  If not, write to
22 ;; the Free Software Foundation, 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.  */
24 ;;
25 ;; The original PO technology requires these to be ordered by speed,
26 ;; so that assigner will pick the fastest.
27 ;;
28 ;; See file "rtl.def" for documentation on define_insn, match_*, et. al.
29 ;;
30 ;; Macro #define NOTICE_UPDATE_CC in file i386.h handles condition code
31 ;; updates for most instructions.
32 ;;
33 ;; Macro REG_CLASS_FROM_LETTER in file i386.h defines the register
34 ;; constraint letters.
35 ;;
36 ;; The special asm out single letter directives following a '%' are:
37 ;; 'z' mov%z1 would be movl, movw, or movb depending on the mode of
38 ;;     operands[1].
39 ;; 'L' Print the opcode suffix for a 32-bit integer opcode.
40 ;; 'W' Print the opcode suffix for a 16-bit integer opcode.
41 ;; 'B' Print the opcode suffix for an 8-bit integer opcode.
42 ;; 'Q' Print the opcode suffix for a 64-bit float opcode.
43 ;; 'S' Print the opcode suffix for a 32-bit float opcode.
44 ;; 'T' Print the opcode suffix for an 80-bit extended real XFmode float opcode.
45 ;; 'J' Print the appropriate jump operand.
46 ;;
47 ;; 'b' Print the QImode name of the register for the indicated operand.
48 ;;     %b0 would print %al if operands[0] is reg 0.
49 ;; 'w' Likewise, print the HImode name of the register.
50 ;; 'k' Likewise, print the SImode name of the register.
51 ;; 'h' Print the QImode name for a "high" register, either ah, bh, ch or dh.
52 ;; 'y' Print "st(0)" instead of "st" as a register.
53
54 ;; UNSPEC usage:
55
56 (define_constants
57   [; Relocation specifiers
58    (UNSPEC_GOT                  0)
59    (UNSPEC_GOTOFF               1)
60    (UNSPEC_GOTPCREL             2)
61    (UNSPEC_GOTTPOFF             3)
62    (UNSPEC_TPOFF                4)
63    (UNSPEC_NTPOFF               5)
64    (UNSPEC_DTPOFF               6)
65    (UNSPEC_GOTNTPOFF            7)
66    (UNSPEC_INDNTPOFF            8)
67
68    ; Prologue support
69    (UNSPEC_STACK_PROBE          10)
70    (UNSPEC_STACK_ALLOC          11)
71    (UNSPEC_SET_GOT              12)
72    (UNSPEC_SSE_PROLOGUE_SAVE    13)
73
74    ; TLS support
75    (UNSPEC_TP                   15)
76    (UNSPEC_TLS_GD               16)
77    (UNSPEC_TLS_LD_BASE          17)
78
79    ; Other random patterns
80    (UNSPEC_SCAS                 20)
81    (UNSPEC_SIN                  21)
82    (UNSPEC_COS                  22)
83    (UNSPEC_FNSTSW               24)
84    (UNSPEC_SAHF                 25)
85    (UNSPEC_FSTCW                26)
86    (UNSPEC_ADD_CARRY            27)
87    (UNSPEC_FLDCW                28)
88
89    ; For SSE/MMX support:
90    (UNSPEC_FIX                  30)
91    (UNSPEC_MASKMOV              32)
92    (UNSPEC_MOVMSK               33)
93    (UNSPEC_MOVNT                34)
94    (UNSPEC_MOVA                 38)
95    (UNSPEC_MOVU                 39)
96    (UNSPEC_SHUFFLE              41)
97    (UNSPEC_RCP                  42)
98    (UNSPEC_RSQRT                43)
99    (UNSPEC_SFENCE               44)
100    (UNSPEC_NOP                  45)     ; prevents combiner cleverness
101    (UNSPEC_PAVGUSB              49)
102    (UNSPEC_PFRCP                50)
103    (UNSPEC_PFRCPIT1             51)
104    (UNSPEC_PFRCPIT2             52)
105    (UNSPEC_PFRSQRT              53)
106    (UNSPEC_PFRSQIT1             54)
107    (UNSPEC_PSHUFLW              55)
108    (UNSPEC_PSHUFHW              56)
109    (UNSPEC_MFENCE               59)
110    (UNSPEC_LFENCE               60)
111    (UNSPEC_PSADBW               61)
112   ])
113
114 (define_constants
115   [(UNSPECV_BLOCKAGE            0)
116    (UNSPECV_EH_RETURN           13)
117    (UNSPECV_EMMS                31)
118    (UNSPECV_LDMXCSR             37)
119    (UNSPECV_STMXCSR             40)
120    (UNSPECV_FEMMS               46)
121    (UNSPECV_CLFLUSH             57)
122   ])
123
124 ;; Insns whose names begin with "x86_" are emitted by gen_FOO calls
125 ;; from i386.c.
126
127 ;; In C guard expressions, put expressions which may be compile-time
128 ;; constants first.  This allows for better optimization.  For
129 ;; example, write "TARGET_64BIT && reload_completed", not
130 ;; "reload_completed && TARGET_64BIT".
131
132 \f
133 ;; Processor type.  This attribute must exactly match the processor_type
134 ;; enumeration in i386.h.
135 (define_attr "cpu" "i386,i486,pentium,pentiumpro,k6,athlon,pentium4,k8"
136   (const (symbol_ref "ix86_cpu")))
137
138 ;; A basic instruction type.  Refinements due to arguments to be
139 ;; provided in other attributes.
140 (define_attr "type"
141   "other,multi,
142    alu,alu1,negnot,imov,imovx,lea,
143    incdec,ishift,ishift1,rotate,rotate1,imul,idiv,
144    icmp,test,ibr,setcc,icmov,
145    push,pop,call,callv,leave,
146    str,cld,
147    fmov,fop,fsgn,fmul,fdiv,fpspc,fcmov,fcmp,fxch,fistp,
148    sselog,sseiadd,sseishft,sseimul,
149    sse,ssemov,sseadd,ssemul,ssecmp,ssecomi,ssecvt,sseicvt,ssediv,
150    mmx,mmxmov,mmxadd,mmxmul,mmxcmp,mmxcvt,mmxshft"
151   (const_string "other"))
152
153 ;; Main data type used by the insn
154 (define_attr "mode"
155   "unknown,none,QI,HI,SI,DI,SF,DF,XF,TI,V4SF,V2DF,V2SF"
156   (const_string "unknown"))
157
158 ;; The CPU unit operations uses.
159 (define_attr "unit" "integer,i387,sse,mmx,unknown"
160   (cond [(eq_attr "type" "fmov,fop,fsgn,fmul,fdiv,fpspc,fcmov,fcmp,fxch,fistp")
161            (const_string "i387")
162          (eq_attr "type" "sselog,sseiadd,sseishft,sseimul,
163                           sse,ssemov,sseadd,ssemul,ssecmp,ssecomi,ssecvt,sseicvt,ssediv")
164            (const_string "sse")
165          (eq_attr "type" "mmx,mmxmov,mmxadd,mmxmul,mmxcmp,mmxcvt,mmxshft")
166            (const_string "mmx")
167          (eq_attr "type" "other")
168            (const_string "unknown")]
169          (const_string "integer")))
170
171 ;; The (bounding maximum) length of an instruction immediate.
172 (define_attr "length_immediate" ""
173   (cond [(eq_attr "type" "incdec,setcc,icmov,str,cld,lea,other,multi,idiv,leave")
174            (const_int 0)
175          (eq_attr "unit" "i387,sse,mmx")
176            (const_int 0)
177          (eq_attr "type" "alu,alu1,negnot,imovx,ishift,rotate,ishift1,rotate1,
178                           imul,icmp,push,pop")
179            (symbol_ref "ix86_attr_length_immediate_default(insn,1)")
180          (eq_attr "type" "imov,test")
181            (symbol_ref "ix86_attr_length_immediate_default(insn,0)")
182          (eq_attr "type" "call")
183            (if_then_else (match_operand 0 "constant_call_address_operand" "")
184              (const_int 4)
185              (const_int 0))
186          (eq_attr "type" "callv")
187            (if_then_else (match_operand 1 "constant_call_address_operand" "")
188              (const_int 4)
189              (const_int 0))
190          ;; We don't know the size before shorten_branches.  Expect
191          ;; the instruction to fit for better scheduling.
192          (eq_attr "type" "ibr")
193            (const_int 1)
194          ]
195          (symbol_ref "/* Update immediate_length and other attributes! */
196                       abort(),1")))
197
198 ;; The (bounding maximum) length of an instruction address.
199 (define_attr "length_address" ""
200   (cond [(eq_attr "type" "str,cld,other,multi,fxch")
201            (const_int 0)
202          (and (eq_attr "type" "call")
203               (match_operand 0 "constant_call_address_operand" ""))
204              (const_int 0)
205          (and (eq_attr "type" "callv")
206               (match_operand 1 "constant_call_address_operand" ""))
207              (const_int 0)
208          ]
209          (symbol_ref "ix86_attr_length_address_default (insn)")))
210
211 ;; Set when length prefix is used.
212 (define_attr "prefix_data16" ""
213   (if_then_else (ior (eq_attr "mode" "HI")
214                      (and (eq_attr "unit" "sse") (eq_attr "mode" "V2DF")))
215     (const_int 1)
216     (const_int 0)))
217
218 ;; Set when string REP prefix is used.
219 (define_attr "prefix_rep" "" 
220   (if_then_else (and (eq_attr "unit" "sse") (eq_attr "mode" "SF,DF"))
221     (const_int 1)
222     (const_int 0)))
223
224 ;; Set when 0f opcode prefix is used.
225 (define_attr "prefix_0f" ""
226   (if_then_else 
227     (ior (eq_attr "type" "imovx,setcc,icmov")
228          (eq_attr "unit" "sse,mmx"))
229     (const_int 1)
230     (const_int 0)))
231
232 ;; Set when 0f opcode prefix is used.
233 (define_attr "prefix_rex" ""
234   (cond [(and (eq_attr "mode" "DI")
235               (eq_attr "type" "!push,pop,call,callv,leave,ibr"))
236            (const_int 1)
237          (and (eq_attr "mode" "QI")
238               (ne (symbol_ref "x86_extended_QIreg_mentioned_p (insn)")
239                   (const_int 0)))
240            (const_int 1)
241          (ne (symbol_ref "x86_extended_reg_mentioned_p (insn)")
242              (const_int 0))
243            (const_int 1)
244         ]
245         (const_int 0)))
246
247 ;; Set when modrm byte is used.
248 (define_attr "modrm" ""
249   (cond [(eq_attr "type" "str,cld,leave")
250            (const_int 0)
251          (eq_attr "unit" "i387")
252            (const_int 0)
253          (and (eq_attr "type" "incdec")
254               (ior (match_operand:SI 1 "register_operand" "")
255                    (match_operand:HI 1 "register_operand" "")))
256            (const_int 0)
257          (and (eq_attr "type" "push")
258               (not (match_operand 1 "memory_operand" "")))
259            (const_int 0)
260          (and (eq_attr "type" "pop")
261               (not (match_operand 0 "memory_operand" "")))
262            (const_int 0)
263          (and (eq_attr "type" "imov")
264               (and (match_operand 0 "register_operand" "")
265                    (match_operand 1 "immediate_operand" "")))
266            (const_int 0)
267          (and (eq_attr "type" "call")
268               (match_operand 0 "constant_call_address_operand" ""))
269              (const_int 0)
270          (and (eq_attr "type" "callv")
271               (match_operand 1 "constant_call_address_operand" ""))
272              (const_int 0)
273          ]
274          (const_int 1)))
275
276 ;; The (bounding maximum) length of an instruction in bytes.
277 ;; ??? fistp is in fact fldcw/fistp/fldcw sequence.  Later we may want
278 ;; to split it and compute proper length as for other insns.
279 (define_attr "length" ""
280   (cond [(eq_attr "type" "other,multi,fistp")
281            (const_int 16)
282          (eq_attr "unit" "i387")
283            (plus (const_int 2)
284                  (plus (attr "prefix_data16")
285                        (attr "length_address")))]
286          (plus (plus (attr "modrm")
287                      (plus (attr "prefix_0f")
288                            (plus (attr "prefix_rex")
289                                  (const_int 1))))
290                (plus (attr "prefix_rep")
291                      (plus (attr "prefix_data16")
292                            (plus (attr "length_immediate")
293                                  (attr "length_address")))))))
294
295 ;; The `memory' attribute is `none' if no memory is referenced, `load' or
296 ;; `store' if there is a simple memory reference therein, or `unknown'
297 ;; if the instruction is complex.
298
299 (define_attr "memory" "none,load,store,both,unknown"
300   (cond [(eq_attr "type" "other,multi,str")
301            (const_string "unknown")
302          (eq_attr "type" "lea,fcmov,fpspc,cld")
303            (const_string "none")
304          (eq_attr "type" "fistp,leave")
305            (const_string "both")
306          (eq_attr "type" "push")
307            (if_then_else (match_operand 1 "memory_operand" "")
308              (const_string "both")
309              (const_string "store"))
310          (eq_attr "type" "pop")
311            (if_then_else (match_operand 0 "memory_operand" "")
312              (const_string "both")
313              (const_string "load"))
314          (eq_attr "type" "setcc")
315            (if_then_else (match_operand 0 "memory_operand" "")
316              (const_string "store")
317              (const_string "none"))
318          (eq_attr "type" "icmp,test,ssecmp,ssecomi,mmxcmp,fcmp")
319            (if_then_else (ior (match_operand 0 "memory_operand" "")
320                               (match_operand 1 "memory_operand" ""))
321              (const_string "load")
322              (const_string "none"))
323          (eq_attr "type" "ibr")
324            (if_then_else (match_operand 0 "memory_operand" "")
325              (const_string "load")
326              (const_string "none"))
327          (eq_attr "type" "call")
328            (if_then_else (match_operand 0 "constant_call_address_operand" "")
329              (const_string "none")
330              (const_string "load"))
331          (eq_attr "type" "callv")
332            (if_then_else (match_operand 1 "constant_call_address_operand" "")
333              (const_string "none")
334              (const_string "load"))
335          (and (eq_attr "type" "alu1,negnot")
336               (match_operand 1 "memory_operand" ""))
337            (const_string "both")
338          (and (match_operand 0 "memory_operand" "")
339               (match_operand 1 "memory_operand" ""))
340            (const_string "both")
341          (match_operand 0 "memory_operand" "")
342            (const_string "store")
343          (match_operand 1 "memory_operand" "")
344            (const_string "load")
345          (and (eq_attr "type"
346                  "!alu1,negnot,
347                    imov,imovx,icmp,test,
348                    fmov,fcmp,fsgn,
349                    sse,ssemov,ssecmp,ssecomi,ssecvt,sseicvt,
350                    mmx,mmxmov,mmxcmp,mmxcvt")
351               (match_operand 2 "memory_operand" ""))
352            (const_string "load")
353          (and (eq_attr "type" "icmov")
354               (match_operand 3 "memory_operand" ""))
355            (const_string "load")
356         ]
357         (const_string "none")))
358
359 ;; Indicates if an instruction has both an immediate and a displacement.
360
361 (define_attr "imm_disp" "false,true,unknown"
362   (cond [(eq_attr "type" "other,multi")
363            (const_string "unknown")
364          (and (eq_attr "type" "icmp,test,imov,alu1,ishift1,rotate1")
365               (and (match_operand 0 "memory_displacement_operand" "")
366                    (match_operand 1 "immediate_operand" "")))
367            (const_string "true")
368          (and (eq_attr "type" "alu,ishift,rotate,imul,idiv")
369               (and (match_operand 0 "memory_displacement_operand" "")
370                    (match_operand 2 "immediate_operand" "")))
371            (const_string "true")
372         ]
373         (const_string "false")))
374
375 ;; Indicates if an FP operation has an integer source.
376
377 (define_attr "fp_int_src" "false,true"
378   (const_string "false"))
379
380 ;; Describe a user's asm statement.
381 (define_asm_attributes
382   [(set_attr "length" "128")
383    (set_attr "type" "multi")])
384 \f
385 (include "pentium.md")
386 (include "ppro.md")
387 (include "k6.md")
388 (include "athlon.md")
389 \f
390 ;; Compare instructions.
391
392 ;; All compare insns have expanders that save the operands away without
393 ;; actually generating RTL.  The bCOND or sCOND (emitted immediately
394 ;; after the cmp) will actually emit the cmpM.
395
396 (define_expand "cmpdi"
397   [(set (reg:CC 17)
398         (compare:CC (match_operand:DI 0 "nonimmediate_operand" "")
399                     (match_operand:DI 1 "x86_64_general_operand" "")))]
400   ""
401 {
402   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
403     operands[0] = force_reg (DImode, operands[0]);
404   ix86_compare_op0 = operands[0];
405   ix86_compare_op1 = operands[1];
406   DONE;
407 })
408
409 (define_expand "cmpsi"
410   [(set (reg:CC 17)
411         (compare:CC (match_operand:SI 0 "cmpsi_operand" "")
412                     (match_operand:SI 1 "general_operand" "")))]
413   ""
414 {
415   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
416     operands[0] = force_reg (SImode, operands[0]);
417   ix86_compare_op0 = operands[0];
418   ix86_compare_op1 = operands[1];
419   DONE;
420 })
421
422 (define_expand "cmphi"
423   [(set (reg:CC 17)
424         (compare:CC (match_operand:HI 0 "nonimmediate_operand" "")
425                     (match_operand:HI 1 "general_operand" "")))]
426   ""
427 {
428   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
429     operands[0] = force_reg (HImode, operands[0]);
430   ix86_compare_op0 = operands[0];
431   ix86_compare_op1 = operands[1];
432   DONE;
433 })
434
435 (define_expand "cmpqi"
436   [(set (reg:CC 17)
437         (compare:CC (match_operand:QI 0 "nonimmediate_operand" "")
438                     (match_operand:QI 1 "general_operand" "")))]
439   "TARGET_QIMODE_MATH"
440 {
441   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
442     operands[0] = force_reg (QImode, operands[0]);
443   ix86_compare_op0 = operands[0];
444   ix86_compare_op1 = operands[1];
445   DONE;
446 })
447
448 (define_insn "cmpdi_ccno_1_rex64"
449   [(set (reg 17)
450         (compare (match_operand:DI 0 "nonimmediate_operand" "r,?mr")
451                  (match_operand:DI 1 "const0_operand" "n,n")))]
452   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
453   "@
454    test{q}\t{%0, %0|%0, %0}
455    cmp{q}\t{%1, %0|%0, %1}"
456   [(set_attr "type" "test,icmp")
457    (set_attr "length_immediate" "0,1")
458    (set_attr "mode" "DI")])
459
460 (define_insn "*cmpdi_minus_1_rex64"
461   [(set (reg 17)
462         (compare (minus:DI (match_operand:DI 0 "nonimmediate_operand" "rm,r")
463                            (match_operand:DI 1 "x86_64_general_operand" "re,mr"))
464                  (const_int 0)))]
465   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)"
466   "cmp{q}\t{%1, %0|%0, %1}"
467   [(set_attr "type" "icmp")
468    (set_attr "mode" "DI")])
469
470 (define_expand "cmpdi_1_rex64"
471   [(set (reg:CC 17)
472         (compare:CC (match_operand:DI 0 "nonimmediate_operand" "")
473                     (match_operand:DI 1 "general_operand" "")))]
474   "TARGET_64BIT"
475   "")
476
477 (define_insn "cmpdi_1_insn_rex64"
478   [(set (reg 17)
479         (compare (match_operand:DI 0 "nonimmediate_operand" "mr,r")
480                  (match_operand:DI 1 "x86_64_general_operand" "re,mr")))]
481   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
482   "cmp{q}\t{%1, %0|%0, %1}"
483   [(set_attr "type" "icmp")
484    (set_attr "mode" "DI")])
485
486
487 (define_insn "*cmpsi_ccno_1"
488   [(set (reg 17)
489         (compare (match_operand:SI 0 "nonimmediate_operand" "r,?mr")
490                  (match_operand:SI 1 "const0_operand" "n,n")))]
491   "ix86_match_ccmode (insn, CCNOmode)"
492   "@
493    test{l}\t{%0, %0|%0, %0}
494    cmp{l}\t{%1, %0|%0, %1}"
495   [(set_attr "type" "test,icmp")
496    (set_attr "length_immediate" "0,1")
497    (set_attr "mode" "SI")])
498
499 (define_insn "*cmpsi_minus_1"
500   [(set (reg 17)
501         (compare (minus:SI (match_operand:SI 0 "nonimmediate_operand" "rm,r")
502                            (match_operand:SI 1 "general_operand" "ri,mr"))
503                  (const_int 0)))]
504   "ix86_match_ccmode (insn, CCGOCmode)"
505   "cmp{l}\t{%1, %0|%0, %1}"
506   [(set_attr "type" "icmp")
507    (set_attr "mode" "SI")])
508
509 (define_expand "cmpsi_1"
510   [(set (reg:CC 17)
511         (compare:CC (match_operand:SI 0 "nonimmediate_operand" "rm,r")
512                     (match_operand:SI 1 "general_operand" "ri,mr")))]
513   ""
514   "")
515
516 (define_insn "*cmpsi_1_insn"
517   [(set (reg 17)
518         (compare (match_operand:SI 0 "nonimmediate_operand" "rm,r")
519                  (match_operand:SI 1 "general_operand" "ri,mr")))]
520   "(GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
521     && ix86_match_ccmode (insn, CCmode)"
522   "cmp{l}\t{%1, %0|%0, %1}"
523   [(set_attr "type" "icmp")
524    (set_attr "mode" "SI")])
525
526 (define_insn "*cmphi_ccno_1"
527   [(set (reg 17)
528         (compare (match_operand:HI 0 "nonimmediate_operand" "r,?mr")
529                  (match_operand:HI 1 "const0_operand" "n,n")))]
530   "ix86_match_ccmode (insn, CCNOmode)"
531   "@
532    test{w}\t{%0, %0|%0, %0}
533    cmp{w}\t{%1, %0|%0, %1}"
534   [(set_attr "type" "test,icmp")
535    (set_attr "length_immediate" "0,1")
536    (set_attr "mode" "HI")])
537
538 (define_insn "*cmphi_minus_1"
539   [(set (reg 17)
540         (compare (minus:HI (match_operand:HI 0 "nonimmediate_operand" "rm,r")
541                            (match_operand:HI 1 "general_operand" "ri,mr"))
542                  (const_int 0)))]
543   "ix86_match_ccmode (insn, CCGOCmode)"
544   "cmp{w}\t{%1, %0|%0, %1}"
545   [(set_attr "type" "icmp")
546    (set_attr "mode" "HI")])
547
548 (define_insn "*cmphi_1"
549   [(set (reg 17)
550         (compare (match_operand:HI 0 "nonimmediate_operand" "rm,r")
551                  (match_operand:HI 1 "general_operand" "ri,mr")))]
552   "(GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
553    && ix86_match_ccmode (insn, CCmode)"
554   "cmp{w}\t{%1, %0|%0, %1}"
555   [(set_attr "type" "icmp")
556    (set_attr "mode" "HI")])
557
558 (define_insn "*cmpqi_ccno_1"
559   [(set (reg 17)
560         (compare (match_operand:QI 0 "nonimmediate_operand" "q,?mq")
561                  (match_operand:QI 1 "const0_operand" "n,n")))]
562   "ix86_match_ccmode (insn, CCNOmode)"
563   "@
564    test{b}\t{%0, %0|%0, %0}
565    cmp{b}\t{$0, %0|%0, 0}"
566   [(set_attr "type" "test,icmp")
567    (set_attr "length_immediate" "0,1")
568    (set_attr "mode" "QI")])
569
570 (define_insn "*cmpqi_1"
571   [(set (reg 17)
572         (compare (match_operand:QI 0 "nonimmediate_operand" "qm,q")
573                  (match_operand:QI 1 "general_operand" "qi,mq")))]
574   "(GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
575     && ix86_match_ccmode (insn, CCmode)"
576   "cmp{b}\t{%1, %0|%0, %1}"
577   [(set_attr "type" "icmp")
578    (set_attr "mode" "QI")])
579
580 (define_insn "*cmpqi_minus_1"
581   [(set (reg 17)
582         (compare (minus:QI (match_operand:QI 0 "nonimmediate_operand" "qm,q")
583                            (match_operand:QI 1 "general_operand" "qi,mq"))
584                  (const_int 0)))]
585   "ix86_match_ccmode (insn, CCGOCmode)"
586   "cmp{b}\t{%1, %0|%0, %1}"
587   [(set_attr "type" "icmp")
588    (set_attr "mode" "QI")])
589
590 (define_insn "*cmpqi_ext_1"
591   [(set (reg 17)
592         (compare
593           (match_operand:QI 0 "general_operand" "Qm")
594           (subreg:QI
595             (zero_extract:SI
596               (match_operand 1 "ext_register_operand" "Q")
597               (const_int 8)
598               (const_int 8)) 0)))]
599   "!TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
600   "cmp{b}\t{%h1, %0|%0, %h1}"
601   [(set_attr "type" "icmp")
602    (set_attr "mode" "QI")])
603
604 (define_insn "*cmpqi_ext_1_rex64"
605   [(set (reg 17)
606         (compare
607           (match_operand:QI 0 "register_operand" "Q")
608           (subreg:QI
609             (zero_extract:SI
610               (match_operand 1 "ext_register_operand" "Q")
611               (const_int 8)
612               (const_int 8)) 0)))]
613   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
614   "cmp{b}\t{%h1, %0|%0, %h1}"
615   [(set_attr "type" "icmp")
616    (set_attr "mode" "QI")])
617
618 (define_insn "*cmpqi_ext_2"
619   [(set (reg 17)
620         (compare
621           (subreg:QI
622             (zero_extract:SI
623               (match_operand 0 "ext_register_operand" "Q")
624               (const_int 8)
625               (const_int 8)) 0)
626           (match_operand:QI 1 "const0_operand" "n")))]
627   "ix86_match_ccmode (insn, CCNOmode)"
628   "test{b}\t%h0, %h0"
629   [(set_attr "type" "test")
630    (set_attr "length_immediate" "0")
631    (set_attr "mode" "QI")])
632
633 (define_expand "cmpqi_ext_3"
634   [(set (reg:CC 17)
635         (compare:CC
636           (subreg:QI
637             (zero_extract:SI
638               (match_operand 0 "ext_register_operand" "")
639               (const_int 8)
640               (const_int 8)) 0)
641           (match_operand:QI 1 "general_operand" "")))]
642   ""
643   "")
644
645 (define_insn "cmpqi_ext_3_insn"
646   [(set (reg 17)
647         (compare
648           (subreg:QI
649             (zero_extract:SI
650               (match_operand 0 "ext_register_operand" "Q")
651               (const_int 8)
652               (const_int 8)) 0)
653           (match_operand:QI 1 "general_operand" "Qmn")))]
654   "!TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
655   "cmp{b}\t{%1, %h0|%h0, %1}"
656   [(set_attr "type" "icmp")
657    (set_attr "mode" "QI")])
658
659 (define_insn "cmpqi_ext_3_insn_rex64"
660   [(set (reg 17)
661         (compare
662           (subreg:QI
663             (zero_extract:SI
664               (match_operand 0 "ext_register_operand" "Q")
665               (const_int 8)
666               (const_int 8)) 0)
667           (match_operand:QI 1 "nonmemory_operand" "Qn")))]
668   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
669   "cmp{b}\t{%1, %h0|%h0, %1}"
670   [(set_attr "type" "icmp")
671    (set_attr "mode" "QI")])
672
673 (define_insn "*cmpqi_ext_4"
674   [(set (reg 17)
675         (compare
676           (subreg:QI
677             (zero_extract:SI
678               (match_operand 0 "ext_register_operand" "Q")
679               (const_int 8)
680               (const_int 8)) 0)
681           (subreg:QI
682             (zero_extract:SI
683               (match_operand 1 "ext_register_operand" "Q")
684               (const_int 8)
685               (const_int 8)) 0)))]
686   "ix86_match_ccmode (insn, CCmode)"
687   "cmp{b}\t{%h1, %h0|%h0, %h1}"
688   [(set_attr "type" "icmp")
689    (set_attr "mode" "QI")])
690
691 ;; These implement float point compares.
692 ;; %%% See if we can get away with VOIDmode operands on the actual insns,
693 ;; which would allow mix and match FP modes on the compares.  Which is what
694 ;; the old patterns did, but with many more of them.
695
696 (define_expand "cmpxf"
697   [(set (reg:CC 17)
698         (compare:CC (match_operand:XF 0 "cmp_fp_expander_operand" "")
699                     (match_operand:XF 1 "cmp_fp_expander_operand" "")))]
700   "!TARGET_64BIT && TARGET_80387"
701 {
702   ix86_compare_op0 = operands[0];
703   ix86_compare_op1 = operands[1];
704   DONE;
705 })
706
707 (define_expand "cmptf"
708   [(set (reg:CC 17)
709         (compare:CC (match_operand:TF 0 "cmp_fp_expander_operand" "")
710                     (match_operand:TF 1 "cmp_fp_expander_operand" "")))]
711   "TARGET_80387"
712 {
713   ix86_compare_op0 = operands[0];
714   ix86_compare_op1 = operands[1];
715   DONE;
716 })
717
718 (define_expand "cmpdf"
719   [(set (reg:CC 17)
720         (compare:CC (match_operand:DF 0 "cmp_fp_expander_operand" "")
721                     (match_operand:DF 1 "cmp_fp_expander_operand" "")))]
722   "TARGET_80387 || TARGET_SSE2"
723 {
724   ix86_compare_op0 = operands[0];
725   ix86_compare_op1 = operands[1];
726   DONE;
727 })
728
729 (define_expand "cmpsf"
730   [(set (reg:CC 17)
731         (compare:CC (match_operand:SF 0 "cmp_fp_expander_operand" "")
732                     (match_operand:SF 1 "cmp_fp_expander_operand" "")))]
733   "TARGET_80387 || TARGET_SSE"
734 {
735   ix86_compare_op0 = operands[0];
736   ix86_compare_op1 = operands[1];
737   DONE;
738 })
739
740 ;; FP compares, step 1:
741 ;; Set the FP condition codes.
742 ;;
743 ;; CCFPmode     compare with exceptions
744 ;; CCFPUmode    compare with no exceptions
745
746 ;; %%% It is an unfortunate fact that ftst has no non-popping variant,
747 ;; and that fp moves clobber the condition codes, and that there is
748 ;; currently no way to describe this fact to reg-stack.  So there are
749 ;; no splitters yet for this.
750
751 ;; %%% YIKES!  This scheme does not retain a strong connection between 
752 ;; the real compare and the ultimate cc0 user, so CC_REVERSE does not
753 ;; work!  Only allow tos/mem with tos in op 0.
754 ;;
755 ;; Hmm, of course, this is what the actual _hardware_ does.  Perhaps
756 ;; things aren't as bad as they sound...
757
758 (define_insn "*cmpfp_0"
759   [(set (match_operand:HI 0 "register_operand" "=a")
760         (unspec:HI
761           [(compare:CCFP (match_operand 1 "register_operand" "f")
762                          (match_operand 2 "const0_operand" "X"))]
763           UNSPEC_FNSTSW))]
764   "TARGET_80387
765    && FLOAT_MODE_P (GET_MODE (operands[1]))
766    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
767 {
768   if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
769     return "ftst\;fnstsw\t%0\;fstp\t%y0";
770   else
771     return "ftst\;fnstsw\t%0";
772 }
773   [(set_attr "type" "multi")
774    (set (attr "mode")
775      (cond [(match_operand:SF 1 "" "")
776               (const_string "SF")
777             (match_operand:DF 1 "" "")
778               (const_string "DF")
779            ]
780            (const_string "XF")))])
781
782 ;; We may not use "#" to split and emit these, since the REG_DEAD notes
783 ;; used to manage the reg stack popping would not be preserved.
784
785 (define_insn "*cmpfp_2_sf"
786   [(set (reg:CCFP 18)
787         (compare:CCFP
788           (match_operand:SF 0 "register_operand" "f")
789           (match_operand:SF 1 "nonimmediate_operand" "fm")))]
790   "TARGET_80387"
791   "* return output_fp_compare (insn, operands, 0, 0);"
792   [(set_attr "type" "fcmp")
793    (set_attr "mode" "SF")])
794
795 (define_insn "*cmpfp_2_sf_1"
796   [(set (match_operand:HI 0 "register_operand" "=a")
797         (unspec:HI
798           [(compare:CCFP
799              (match_operand:SF 1 "register_operand" "f")
800              (match_operand:SF 2 "nonimmediate_operand" "fm"))]
801           UNSPEC_FNSTSW))]
802   "TARGET_80387"
803   "* return output_fp_compare (insn, operands, 2, 0);"
804   [(set_attr "type" "fcmp")
805    (set_attr "mode" "SF")])
806
807 (define_insn "*cmpfp_2_df"
808   [(set (reg:CCFP 18)
809         (compare:CCFP
810           (match_operand:DF 0 "register_operand" "f")
811           (match_operand:DF 1 "nonimmediate_operand" "fm")))]
812   "TARGET_80387"
813   "* return output_fp_compare (insn, operands, 0, 0);"
814   [(set_attr "type" "fcmp")
815    (set_attr "mode" "DF")])
816
817 (define_insn "*cmpfp_2_df_1"
818   [(set (match_operand:HI 0 "register_operand" "=a")
819         (unspec:HI
820           [(compare:CCFP
821              (match_operand:DF 1 "register_operand" "f")
822              (match_operand:DF 2 "nonimmediate_operand" "fm"))]
823           UNSPEC_FNSTSW))]
824   "TARGET_80387"
825   "* return output_fp_compare (insn, operands, 2, 0);"
826   [(set_attr "type" "multi")
827    (set_attr "mode" "DF")])
828
829 (define_insn "*cmpfp_2_xf"
830   [(set (reg:CCFP 18)
831         (compare:CCFP
832           (match_operand:XF 0 "register_operand" "f")
833           (match_operand:XF 1 "register_operand" "f")))]
834   "!TARGET_64BIT && TARGET_80387"
835   "* return output_fp_compare (insn, operands, 0, 0);"
836   [(set_attr "type" "fcmp")
837    (set_attr "mode" "XF")])
838
839 (define_insn "*cmpfp_2_tf"
840   [(set (reg:CCFP 18)
841         (compare:CCFP
842           (match_operand:TF 0 "register_operand" "f")
843           (match_operand:TF 1 "register_operand" "f")))]
844   "TARGET_80387"
845   "* return output_fp_compare (insn, operands, 0, 0);"
846   [(set_attr "type" "fcmp")
847    (set_attr "mode" "XF")])
848
849 (define_insn "*cmpfp_2_xf_1"
850   [(set (match_operand:HI 0 "register_operand" "=a")
851         (unspec:HI
852           [(compare:CCFP
853              (match_operand:XF 1 "register_operand" "f")
854              (match_operand:XF 2 "register_operand" "f"))]
855           UNSPEC_FNSTSW))]
856   "!TARGET_64BIT && TARGET_80387"
857   "* return output_fp_compare (insn, operands, 2, 0);"
858   [(set_attr "type" "multi")
859    (set_attr "mode" "XF")])
860
861 (define_insn "*cmpfp_2_tf_1"
862   [(set (match_operand:HI 0 "register_operand" "=a")
863         (unspec:HI
864           [(compare:CCFP
865              (match_operand:TF 1 "register_operand" "f")
866              (match_operand:TF 2 "register_operand" "f"))]
867           UNSPEC_FNSTSW))]
868   "TARGET_80387"
869   "* return output_fp_compare (insn, operands, 2, 0);"
870   [(set_attr "type" "multi")
871    (set_attr "mode" "XF")])
872
873 (define_insn "*cmpfp_2u"
874   [(set (reg:CCFPU 18)
875         (compare:CCFPU
876           (match_operand 0 "register_operand" "f")
877           (match_operand 1 "register_operand" "f")))]
878   "TARGET_80387
879    && FLOAT_MODE_P (GET_MODE (operands[0]))
880    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
881   "* return output_fp_compare (insn, operands, 0, 1);"
882   [(set_attr "type" "fcmp")
883    (set (attr "mode")
884      (cond [(match_operand:SF 1 "" "")
885               (const_string "SF")
886             (match_operand:DF 1 "" "")
887               (const_string "DF")
888            ]
889            (const_string "XF")))])
890
891 (define_insn "*cmpfp_2u_1"
892   [(set (match_operand:HI 0 "register_operand" "=a")
893         (unspec:HI
894           [(compare:CCFPU
895              (match_operand 1 "register_operand" "f")
896              (match_operand 2 "register_operand" "f"))]
897           UNSPEC_FNSTSW))]
898   "TARGET_80387
899    && FLOAT_MODE_P (GET_MODE (operands[1]))
900    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
901   "* return output_fp_compare (insn, operands, 2, 1);"
902   [(set_attr "type" "multi")
903    (set (attr "mode")
904      (cond [(match_operand:SF 1 "" "")
905               (const_string "SF")
906             (match_operand:DF 1 "" "")
907               (const_string "DF")
908            ]
909            (const_string "XF")))])
910
911 ;; Patterns to match the SImode-in-memory ficom instructions.
912 ;;
913 ;; %%% Play games with accepting gp registers, as otherwise we have to
914 ;; force them to memory during rtl generation, which is no good.  We
915 ;; can get rid of this once we teach reload to do memory input reloads 
916 ;; via pushes.
917
918 (define_insn "*ficom_1"
919   [(set (reg:CCFP 18)
920         (compare:CCFP
921           (match_operand 0 "register_operand" "f,f")
922           (float (match_operand:SI 1 "nonimmediate_operand" "m,?r"))))]
923   "0 && TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[0]))
924    && GET_MODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == GET_MODE (operands[0])"
925   "#")
926
927 ;; Split the not-really-implemented gp register case into a
928 ;; push-op-pop sequence.
929 ;;
930 ;; %%% This is most efficient, but am I gonna get in trouble
931 ;; for separating cc0_setter and cc0_user?
932
933 (define_split
934   [(set (reg:CCFP 18)
935         (compare:CCFP
936           (match_operand:SF 0 "register_operand" "")
937           (float (match_operand:SI 1 "register_operand" ""))))]
938   "0 && TARGET_80387 && reload_completed"
939   [(set (mem:SI (pre_dec:SI (reg:SI 7))) (match_dup 1))
940    (set (reg:CCFP 18) (compare:CCFP (match_dup 0) (match_dup 2)))
941    (parallel [(set (match_dup 1) (mem:SI (reg:SI 7)))
942               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))])]
943   "operands[2] = gen_rtx_MEM (Pmode, stack_pointer_rtx);
944    operands[2] = gen_rtx_FLOAT (GET_MODE (operands[0]), operands[2]);")
945
946 ;; FP compares, step 2
947 ;; Move the fpsw to ax.
948
949 (define_insn "*x86_fnstsw_1"
950   [(set (match_operand:HI 0 "register_operand" "=a")
951         (unspec:HI [(reg 18)] UNSPEC_FNSTSW))]
952   "TARGET_80387"
953   "fnstsw\t%0"
954   [(set_attr "length" "2")
955    (set_attr "mode" "SI")
956    (set_attr "unit" "i387")
957    (set_attr "ppro_uops" "few")])
958
959 ;; FP compares, step 3
960 ;; Get ax into flags, general case.
961
962 (define_insn "x86_sahf_1"
963   [(set (reg:CC 17)
964         (unspec:CC [(match_operand:HI 0 "register_operand" "a")] UNSPEC_SAHF))]
965   "!TARGET_64BIT"
966   "sahf"
967   [(set_attr "length" "1")
968    (set_attr "athlon_decode" "vector")
969    (set_attr "mode" "SI")
970    (set_attr "ppro_uops" "one")])
971
972 ;; Pentium Pro can do steps 1 through 3 in one go.
973
974 (define_insn "*cmpfp_i"
975   [(set (reg:CCFP 17)
976         (compare:CCFP (match_operand 0 "register_operand" "f")
977                       (match_operand 1 "register_operand" "f")))]
978   "TARGET_80387 && TARGET_CMOVE
979    && !SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
980    && FLOAT_MODE_P (GET_MODE (operands[0]))
981    && GET_MODE (operands[0]) == GET_MODE (operands[0])"
982   "* return output_fp_compare (insn, operands, 1, 0);"
983   [(set_attr "type" "fcmp")
984    (set (attr "mode")
985      (cond [(match_operand:SF 1 "" "")
986               (const_string "SF")
987             (match_operand:DF 1 "" "")
988               (const_string "DF")
989            ]
990            (const_string "XF")))
991    (set_attr "athlon_decode" "vector")])
992
993 (define_insn "*cmpfp_i_sse"
994   [(set (reg:CCFP 17)
995         (compare:CCFP (match_operand 0 "register_operand" "f#x,x#f")
996                       (match_operand 1 "nonimmediate_operand" "f#x,xm#f")))]
997   "TARGET_80387
998    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
999    && GET_MODE (operands[0]) == GET_MODE (operands[0])"
1000   "* return output_fp_compare (insn, operands, 1, 0);"
1001   [(set_attr "type" "fcmp,ssecomi")
1002    (set (attr "mode")
1003      (if_then_else (match_operand:SF 1 "" "")
1004         (const_string "SF")
1005         (const_string "DF")))
1006    (set_attr "athlon_decode" "vector")])
1007
1008 (define_insn "*cmpfp_i_sse_only"
1009   [(set (reg:CCFP 17)
1010         (compare:CCFP (match_operand 0 "register_operand" "x")
1011                       (match_operand 1 "nonimmediate_operand" "xm")))]
1012   "SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1013    && GET_MODE (operands[0]) == GET_MODE (operands[0])"
1014   "* return output_fp_compare (insn, operands, 1, 0);"
1015   [(set_attr "type" "ssecomi")
1016    (set (attr "mode")
1017      (if_then_else (match_operand:SF 1 "" "")
1018         (const_string "SF")
1019         (const_string "DF")))
1020    (set_attr "athlon_decode" "vector")])
1021
1022 (define_insn "*cmpfp_iu"
1023   [(set (reg:CCFPU 17)
1024         (compare:CCFPU (match_operand 0 "register_operand" "f")
1025                        (match_operand 1 "register_operand" "f")))]
1026   "TARGET_80387 && TARGET_CMOVE
1027    && !SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1028    && FLOAT_MODE_P (GET_MODE (operands[0]))
1029    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1030   "* return output_fp_compare (insn, operands, 1, 1);"
1031   [(set_attr "type" "fcmp")
1032    (set (attr "mode")
1033      (cond [(match_operand:SF 1 "" "")
1034               (const_string "SF")
1035             (match_operand:DF 1 "" "")
1036               (const_string "DF")
1037            ]
1038            (const_string "XF")))
1039    (set_attr "athlon_decode" "vector")])
1040
1041 (define_insn "*cmpfp_iu_sse"
1042   [(set (reg:CCFPU 17)
1043         (compare:CCFPU (match_operand 0 "register_operand" "f#x,x#f")
1044                        (match_operand 1 "nonimmediate_operand" "f#x,xm#f")))]
1045   "TARGET_80387
1046    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1047    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1048   "* return output_fp_compare (insn, operands, 1, 1);"
1049   [(set_attr "type" "fcmp,ssecomi")
1050    (set (attr "mode")
1051      (if_then_else (match_operand:SF 1 "" "")
1052         (const_string "SF")
1053         (const_string "DF")))
1054    (set_attr "athlon_decode" "vector")])
1055
1056 (define_insn "*cmpfp_iu_sse_only"
1057   [(set (reg:CCFPU 17)
1058         (compare:CCFPU (match_operand 0 "register_operand" "x")
1059                        (match_operand 1 "nonimmediate_operand" "xm")))]
1060   "SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1061    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1062   "* return output_fp_compare (insn, operands, 1, 1);"
1063   [(set_attr "type" "ssecomi")
1064    (set (attr "mode")
1065      (if_then_else (match_operand:SF 1 "" "")
1066         (const_string "SF")
1067         (const_string "DF")))
1068    (set_attr "athlon_decode" "vector")])
1069 \f
1070 ;; Move instructions.
1071
1072 ;; General case of fullword move.
1073
1074 (define_expand "movsi"
1075   [(set (match_operand:SI 0 "nonimmediate_operand" "")
1076         (match_operand:SI 1 "general_operand" ""))]
1077   ""
1078   "ix86_expand_move (SImode, operands); DONE;")
1079
1080 ;; Push/pop instructions.  They are separate since autoinc/dec is not a
1081 ;; general_operand.
1082 ;;
1083 ;; %%% We don't use a post-inc memory reference because x86 is not a 
1084 ;; general AUTO_INC_DEC host, which impacts how it is treated in flow.
1085 ;; Changing this impacts compiler performance on other non-AUTO_INC_DEC
1086 ;; targets without our curiosities, and it is just as easy to represent
1087 ;; this differently.
1088
1089 (define_insn "*pushsi2"
1090   [(set (match_operand:SI 0 "push_operand" "=<")
1091         (match_operand:SI 1 "general_no_elim_operand" "ri*m"))]
1092   "!TARGET_64BIT"
1093   "push{l}\t%1"
1094   [(set_attr "type" "push")
1095    (set_attr "mode" "SI")])
1096
1097 ;; For 64BIT abi we always round up to 8 bytes.
1098 (define_insn "*pushsi2_rex64"
1099   [(set (match_operand:SI 0 "push_operand" "=X")
1100         (match_operand:SI 1 "nonmemory_no_elim_operand" "ri"))]
1101   "TARGET_64BIT"
1102   "push{q}\t%q1"
1103   [(set_attr "type" "push")
1104    (set_attr "mode" "SI")])
1105
1106 (define_insn "*pushsi2_prologue"
1107   [(set (match_operand:SI 0 "push_operand" "=<")
1108         (match_operand:SI 1 "general_no_elim_operand" "ri*m"))
1109    (clobber (mem:BLK (scratch)))]
1110   "!TARGET_64BIT"
1111   "push{l}\t%1"
1112   [(set_attr "type" "push")
1113    (set_attr "mode" "SI")])
1114
1115 (define_insn "*popsi1_epilogue"
1116   [(set (match_operand:SI 0 "nonimmediate_operand" "=r*m")
1117         (mem:SI (reg:SI 7)))
1118    (set (reg:SI 7)
1119         (plus:SI (reg:SI 7) (const_int 4)))
1120    (clobber (mem:BLK (scratch)))]
1121   "!TARGET_64BIT"
1122   "pop{l}\t%0"
1123   [(set_attr "type" "pop")
1124    (set_attr "mode" "SI")])
1125
1126 (define_insn "popsi1"
1127   [(set (match_operand:SI 0 "nonimmediate_operand" "=r*m")
1128         (mem:SI (reg:SI 7)))
1129    (set (reg:SI 7)
1130         (plus:SI (reg:SI 7) (const_int 4)))]
1131   "!TARGET_64BIT"
1132   "pop{l}\t%0"
1133   [(set_attr "type" "pop")
1134    (set_attr "mode" "SI")])
1135
1136 (define_insn "*movsi_xor"
1137   [(set (match_operand:SI 0 "register_operand" "=r")
1138         (match_operand:SI 1 "const0_operand" "i"))
1139    (clobber (reg:CC 17))]
1140   "reload_completed && (!TARGET_USE_MOV0 || optimize_size)"
1141   "xor{l}\t{%0, %0|%0, %0}"
1142   [(set_attr "type" "alu1")
1143    (set_attr "mode" "SI")
1144    (set_attr "length_immediate" "0")])
1145
1146 (define_insn "*movsi_or"
1147   [(set (match_operand:SI 0 "register_operand" "=r")
1148         (match_operand:SI 1 "immediate_operand" "i"))
1149    (clobber (reg:CC 17))]
1150   "reload_completed && GET_CODE (operands[1]) == CONST_INT
1151    && INTVAL (operands[1]) == -1
1152    && (TARGET_PENTIUM || optimize_size)"
1153 {
1154   operands[1] = constm1_rtx;
1155   return "or{l}\t{%1, %0|%0, %1}";
1156 }
1157   [(set_attr "type" "alu1")
1158    (set_attr "mode" "SI")
1159    (set_attr "length_immediate" "1")])
1160
1161 ; The first alternative is used only to compute proper length of instruction.
1162 ; Reload's algorithm does not take into account the cost of spill instructions
1163 ; needed to free register in given class, so avoid it from choosing the first
1164 ; alternative when eax is not available.
1165
1166 (define_insn "*movsi_1"
1167   [(set (match_operand:SI 0 "nonimmediate_operand" "=*?a,r,*?a,m,!*y,!rm,!*y,!*Y,!rm,!*Y")
1168         (match_operand:SI 1 "general_operand" "im,rinm,rinm,rin,*y,*y,rm,*Y,*Y,rm"))]
1169   "(TARGET_INTER_UNIT_MOVES || optimize_size)
1170    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
1171 {
1172   switch (get_attr_type (insn))
1173     {
1174     case TYPE_SSEMOV:
1175       if (get_attr_mode (insn) == TImode)
1176         return "movdqa\t{%1, %0|%0, %1}";
1177       return "movd\t{%1, %0|%0, %1}";
1178
1179     case TYPE_MMXMOV:
1180       if (get_attr_mode (insn) == DImode)
1181         return "movq\t{%1, %0|%0, %1}";
1182       return "movd\t{%1, %0|%0, %1}";
1183
1184     case TYPE_LEA:
1185       return "lea{l}\t{%1, %0|%0, %1}";
1186
1187     default:
1188       if (flag_pic && !LEGITIMATE_PIC_OPERAND_P (operands[1]))
1189         abort();
1190       return "mov{l}\t{%1, %0|%0, %1}";
1191     }
1192 }
1193   [(set (attr "type")
1194      (cond [(eq_attr "alternative" "4,5,6")
1195               (const_string "mmxmov")
1196             (eq_attr "alternative" "7,8,9")
1197               (const_string "ssemov")
1198             (and (ne (symbol_ref "flag_pic") (const_int 0))
1199                  (match_operand:SI 1 "symbolic_operand" ""))
1200               (const_string "lea")
1201            ]
1202            (const_string "imov")))
1203    (set_attr "modrm" "0,*,0,*,*,*,*,*,*,*")
1204    (set_attr "mode" "SI,SI,SI,SI,DI,SI,SI,TI,SI,SI")])
1205
1206 (define_insn "*movsi_1_nointernunit"
1207   [(set (match_operand:SI 0 "nonimmediate_operand" "=*?a,r,*?a,m,!*y,!m,!*y,!*Y,!m,!*Y")
1208         (match_operand:SI 1 "general_operand" "im,rinm,rinm,rin,*y,*y,m,*Y,*Y,m"))]
1209   "(!TARGET_INTER_UNIT_MOVES && !optimize_size)
1210    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
1211 {
1212   switch (get_attr_type (insn))
1213     {
1214     case TYPE_SSEMOV:
1215       if (get_attr_mode (insn) == TImode || which_alternative == 9)
1216         return "movdqa\t{%1, %0|%0, %1}";
1217       return "movd\t{%1, %0|%0, %1}";
1218
1219     case TYPE_MMXMOV:
1220       if (get_attr_mode (insn) == DImode)
1221         return "movq\t{%1, %0|%0, %1}";
1222       return "movd\t{%1, %0|%0, %1}";
1223
1224     case TYPE_LEA:
1225       return "lea{l}\t{%1, %0|%0, %1}";
1226
1227     default:
1228       if (flag_pic && !LEGITIMATE_PIC_OPERAND_P (operands[1]))
1229         abort();
1230       return "mov{l}\t{%1, %0|%0, %1}";
1231     }
1232 }
1233   [(set (attr "type")
1234      (cond [(eq_attr "alternative" "4,5,6")
1235               (const_string "mmxmov")
1236             (eq_attr "alternative" "7,8,9")
1237               (const_string "ssemov")
1238             (and (ne (symbol_ref "flag_pic") (const_int 0))
1239                  (match_operand:SI 1 "symbolic_operand" ""))
1240               (const_string "lea")
1241            ]
1242            (const_string "imov")))
1243    (set_attr "modrm" "0,*,0,*,*,*,*,*,*,*")
1244    (set_attr "mode" "SI,SI,SI,SI,DI,SI,SI,TI,SI,SI")])
1245
1246 ;; Stores and loads of ax to arbitrary constant address.
1247 ;; We fake an second form of instruction to force reload to load address
1248 ;; into register when rax is not available
1249 (define_insn "*movabssi_1_rex64"
1250   [(set (mem:SI (match_operand:DI 0 "x86_64_movabs_operand" "i,r,r"))
1251         (match_operand:SI 1 "nonmemory_operand" "a,er,i"))]
1252   "TARGET_64BIT"
1253   "@
1254    movabs{l}\t{%1, %P0|%P0, %1}
1255    mov{l}\t{%1, %a0|%a0, %1}
1256    movabs{l}\t{%1, %a0|%a0, %1}"
1257   [(set_attr "type" "imov")
1258    (set_attr "modrm" "0,*,*")
1259    (set_attr "length_address" "8,0,0")
1260    (set_attr "length_immediate" "0,*,*")
1261    (set_attr "memory" "store")
1262    (set_attr "mode" "SI")])
1263
1264 (define_insn "*movabssi_2_rex64"
1265   [(set (match_operand:SI 0 "register_operand" "=a,r")
1266         (mem:SI (match_operand:DI 1 "x86_64_movabs_operand" "i,r")))]
1267   "TARGET_64BIT"
1268   "@
1269    movabs{l}\t{%P1, %0|%0, %P1}
1270    mov{l}\t{%a1, %0|%0, %a1}"
1271   [(set_attr "type" "imov")
1272    (set_attr "modrm" "0,*")
1273    (set_attr "length_address" "8,0")
1274    (set_attr "length_immediate" "0")
1275    (set_attr "memory" "load")
1276    (set_attr "mode" "SI")])
1277
1278 (define_insn "*swapsi"
1279   [(set (match_operand:SI 0 "register_operand" "+r")
1280         (match_operand:SI 1 "register_operand" "+r"))
1281    (set (match_dup 1)
1282         (match_dup 0))]
1283   ""
1284   "xchg{l}\t%1, %0"
1285   [(set_attr "type" "imov")
1286    (set_attr "pent_pair" "np")
1287    (set_attr "athlon_decode" "vector")
1288    (set_attr "mode" "SI")
1289    (set_attr "modrm" "0")
1290    (set_attr "ppro_uops" "few")])
1291
1292 (define_expand "movhi"
1293   [(set (match_operand:HI 0 "nonimmediate_operand" "")
1294         (match_operand:HI 1 "general_operand" ""))]
1295   ""
1296   "ix86_expand_move (HImode, operands); DONE;")
1297
1298 (define_insn "*pushhi2"
1299   [(set (match_operand:HI 0 "push_operand" "=<,<")
1300         (match_operand:HI 1 "general_no_elim_operand" "n,r*m"))]
1301   "!TARGET_64BIT"
1302   "@
1303    push{w}\t{|WORD PTR }%1
1304    push{w}\t%1"
1305   [(set_attr "type" "push")
1306    (set_attr "mode" "HI")])
1307
1308 ;; For 64BIT abi we always round up to 8 bytes.
1309 (define_insn "*pushhi2_rex64"
1310   [(set (match_operand:HI 0 "push_operand" "=X")
1311         (match_operand:HI 1 "nonmemory_no_elim_operand" "ri"))]
1312   "TARGET_64BIT"
1313   "push{q}\t%q1"
1314   [(set_attr "type" "push")
1315    (set_attr "mode" "QI")])
1316
1317 ; The first alternative is used only to compute proper length of instruction.
1318 ; Reload's algorithm does not take into account the cost of spill instructions
1319 ; needed to free register in given class, so avoid it from choosing the first
1320 ; alternative when eax is not available.
1321
1322 (define_insn "*movhi_1"
1323   [(set (match_operand:HI 0 "nonimmediate_operand" "=*?a,r,r,*?a,r,m")
1324         (match_operand:HI 1 "general_operand" "i,r,rn,rm,rm,rn"))]
1325   "GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM"
1326 {
1327   switch (get_attr_type (insn))
1328     {
1329     case TYPE_IMOVX:
1330       /* movzwl is faster than movw on p2 due to partial word stalls,
1331          though not as fast as an aligned movl.  */
1332       return "movz{wl|x}\t{%1, %k0|%k0, %1}";
1333     default:
1334       if (get_attr_mode (insn) == MODE_SI)
1335         return "mov{l}\t{%k1, %k0|%k0, %k1}";
1336       else
1337         return "mov{w}\t{%1, %0|%0, %1}";
1338     }
1339 }
1340   [(set (attr "type")
1341      (cond [(and (eq_attr "alternative" "0,1")
1342                  (ior (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
1343                           (const_int 0))
1344                       (eq (symbol_ref "TARGET_HIMODE_MATH")
1345                           (const_int 0))))
1346               (const_string "imov")
1347             (and (eq_attr "alternative" "2,3,4")
1348                  (match_operand:HI 1 "aligned_operand" ""))
1349               (const_string "imov")
1350             (and (ne (symbol_ref "TARGET_MOVX")
1351                      (const_int 0))
1352                  (eq_attr "alternative" "0,1,3,4"))
1353               (const_string "imovx")
1354            ]
1355            (const_string "imov")))
1356     (set (attr "mode")
1357       (cond [(eq_attr "type" "imovx")
1358                (const_string "SI")
1359              (and (eq_attr "alternative" "2,3,4")
1360                   (match_operand:HI 1 "aligned_operand" ""))
1361                (const_string "SI")
1362              (and (eq_attr "alternative" "0,1")
1363                   (ior (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
1364                            (const_int 0))
1365                        (eq (symbol_ref "TARGET_HIMODE_MATH")
1366                            (const_int 0))))
1367                (const_string "SI")
1368             ]
1369             (const_string "HI")))
1370    (set_attr "modrm" "0,*,*,0,*,*")])
1371
1372 ;; Stores and loads of ax to arbitrary constant address.
1373 ;; We fake an second form of instruction to force reload to load address
1374 ;; into register when rax is not available
1375 (define_insn "*movabshi_1_rex64"
1376   [(set (mem:HI (match_operand:DI 0 "x86_64_movabs_operand" "i,r,r"))
1377         (match_operand:HI 1 "nonmemory_operand" "a,er,i"))]
1378   "TARGET_64BIT"
1379   "@
1380    movabs{w}\t{%1, %P0|%P0, %1}
1381    mov{w}\t{%1, %a0|%a0, %1}
1382    movabs{w}\t{%1, %a0|%a0, %1}"
1383   [(set_attr "type" "imov")
1384    (set_attr "modrm" "0,*,*")
1385    (set_attr "length_address" "8,0,0")
1386    (set_attr "length_immediate" "0,*,*")
1387    (set_attr "memory" "store")
1388    (set_attr "mode" "HI")])
1389
1390 (define_insn "*movabshi_2_rex64"
1391   [(set (match_operand:HI 0 "register_operand" "=a,r")
1392         (mem:HI (match_operand:DI 1 "x86_64_movabs_operand" "i,r")))]
1393   "TARGET_64BIT"
1394   "@
1395    movabs{w}\t{%P1, %0|%0, %P1}
1396    mov{w}\t{%a1, %0|%0, %a1}"
1397   [(set_attr "type" "imov")
1398    (set_attr "modrm" "0,*")
1399    (set_attr "length_address" "8,0")
1400    (set_attr "length_immediate" "0")
1401    (set_attr "memory" "load")
1402    (set_attr "mode" "HI")])
1403
1404 (define_insn "*swaphi_1"
1405   [(set (match_operand:HI 0 "register_operand" "+r")
1406         (match_operand:HI 1 "register_operand" "+r"))
1407    (set (match_dup 1)
1408         (match_dup 0))]
1409   "TARGET_PARTIAL_REG_STALL"
1410   "xchg{w}\t%1, %0"
1411   [(set_attr "type" "imov")
1412    (set_attr "pent_pair" "np")
1413    (set_attr "mode" "HI")
1414    (set_attr "modrm" "0")
1415    (set_attr "ppro_uops" "few")])
1416
1417 (define_insn "*swaphi_2"
1418   [(set (match_operand:HI 0 "register_operand" "+r")
1419         (match_operand:HI 1 "register_operand" "+r"))
1420    (set (match_dup 1)
1421         (match_dup 0))]
1422   "! TARGET_PARTIAL_REG_STALL"
1423   "xchg{l}\t%k1, %k0"
1424   [(set_attr "type" "imov")
1425    (set_attr "pent_pair" "np")
1426    (set_attr "mode" "SI")
1427    (set_attr "modrm" "0")
1428    (set_attr "ppro_uops" "few")])
1429
1430 (define_expand "movstricthi"
1431   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" ""))
1432         (match_operand:HI 1 "general_operand" ""))]
1433   "! TARGET_PARTIAL_REG_STALL || optimize_size"
1434 {
1435   /* Don't generate memory->memory moves, go through a register */
1436   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
1437     operands[1] = force_reg (HImode, operands[1]);
1438 })
1439
1440 (define_insn "*movstricthi_1"
1441   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+rm,r"))
1442         (match_operand:HI 1 "general_operand" "rn,m"))]
1443   "(! TARGET_PARTIAL_REG_STALL || optimize_size)
1444    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
1445   "mov{w}\t{%1, %0|%0, %1}"
1446   [(set_attr "type" "imov")
1447    (set_attr "mode" "HI")])
1448
1449 (define_insn "*movstricthi_xor"
1450   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+r"))
1451         (match_operand:HI 1 "const0_operand" "i"))
1452    (clobber (reg:CC 17))]
1453   "reload_completed
1454    && ((!TARGET_USE_MOV0 && !TARGET_PARTIAL_REG_STALL) || optimize_size)"
1455   "xor{w}\t{%0, %0|%0, %0}"
1456   [(set_attr "type" "alu1")
1457    (set_attr "mode" "HI")
1458    (set_attr "length_immediate" "0")])
1459
1460 (define_expand "movqi"
1461   [(set (match_operand:QI 0 "nonimmediate_operand" "")
1462         (match_operand:QI 1 "general_operand" ""))]
1463   ""
1464   "ix86_expand_move (QImode, operands); DONE;")
1465
1466 ;; emit_push_insn when it calls move_by_pieces requires an insn to
1467 ;; "push a byte".  But actually we use pushw, which has the effect
1468 ;; of rounding the amount pushed up to a halfword.
1469
1470 (define_insn "*pushqi2"
1471   [(set (match_operand:QI 0 "push_operand" "=X,X")
1472         (match_operand:QI 1 "nonmemory_no_elim_operand" "n,r"))]
1473   "!TARGET_64BIT"
1474   "@
1475    push{w}\t{|word ptr }%1
1476    push{w}\t%w1"
1477   [(set_attr "type" "push")
1478    (set_attr "mode" "HI")])
1479
1480 ;; For 64BIT abi we always round up to 8 bytes.
1481 (define_insn "*pushqi2_rex64"
1482   [(set (match_operand:QI 0 "push_operand" "=X")
1483         (match_operand:QI 1 "nonmemory_no_elim_operand" "qi"))]
1484   "TARGET_64BIT"
1485   "push{q}\t%q1"
1486   [(set_attr "type" "push")
1487    (set_attr "mode" "QI")])
1488
1489 ;; Situation is quite tricky about when to choose full sized (SImode) move
1490 ;; over QImode moves.  For Q_REG -> Q_REG move we use full size only for
1491 ;; partial register dependency machines (such as AMD Athlon), where QImode
1492 ;; moves issue extra dependency and for partial register stalls machines
1493 ;; that don't use QImode patterns (and QImode move cause stall on the next
1494 ;; instruction).
1495 ;;
1496 ;; For loads of Q_REG to NONQ_REG we use full sized moves except for partial
1497 ;; register stall machines with, where we use QImode instructions, since
1498 ;; partial register stall can be caused there.  Then we use movzx.
1499 (define_insn "*movqi_1"
1500   [(set (match_operand:QI 0 "nonimmediate_operand" "=q,q ,q ,r,r ,?r,m")
1501         (match_operand:QI 1 "general_operand"      " q,qn,qm,q,rn,qm,qn"))]
1502   "GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM"
1503 {
1504   switch (get_attr_type (insn))
1505     {
1506     case TYPE_IMOVX:
1507       if (!ANY_QI_REG_P (operands[1]) && GET_CODE (operands[1]) != MEM)
1508         abort ();
1509       return "movz{bl|x}\t{%1, %k0|%k0, %1}";
1510     default:
1511       if (get_attr_mode (insn) == MODE_SI)
1512         return "mov{l}\t{%k1, %k0|%k0, %k1}";
1513       else
1514         return "mov{b}\t{%1, %0|%0, %1}";
1515     }
1516 }
1517   [(set (attr "type")
1518      (cond [(and (eq_attr "alternative" "3")
1519                  (ior (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
1520                           (const_int 0))
1521                       (eq (symbol_ref "TARGET_QIMODE_MATH")
1522                           (const_int 0))))
1523               (const_string "imov")
1524             (eq_attr "alternative" "3,5")
1525               (const_string "imovx")
1526             (and (ne (symbol_ref "TARGET_MOVX")
1527                      (const_int 0))
1528                  (eq_attr "alternative" "2"))
1529               (const_string "imovx")
1530            ]
1531            (const_string "imov")))
1532    (set (attr "mode")
1533       (cond [(eq_attr "alternative" "3,4,5")
1534                (const_string "SI")
1535              (eq_attr "alternative" "6")
1536                (const_string "QI")
1537              (eq_attr "type" "imovx")
1538                (const_string "SI")
1539              (and (eq_attr "type" "imov")
1540                   (and (eq_attr "alternative" "0,1,2")
1541                        (ne (symbol_ref "TARGET_PARTIAL_REG_DEPENDENCY")
1542                            (const_int 0))))
1543                (const_string "SI")
1544              ;; Avoid partial register stalls when not using QImode arithmetic
1545              (and (eq_attr "type" "imov")
1546                   (and (eq_attr "alternative" "0,1,2")
1547                        (and (ne (symbol_ref "TARGET_PARTIAL_REG_STALL")
1548                                 (const_int 0))
1549                             (eq (symbol_ref "TARGET_QIMODE_MATH")
1550                                 (const_int 0)))))
1551                (const_string "SI")
1552            ]
1553            (const_string "QI")))])
1554
1555 (define_expand "reload_outqi"
1556   [(parallel [(match_operand:QI 0 "" "=m")
1557               (match_operand:QI 1 "register_operand" "r")
1558               (match_operand:QI 2 "register_operand" "=&q")])]
1559   ""
1560 {
1561   rtx op0, op1, op2;
1562   op0 = operands[0]; op1 = operands[1]; op2 = operands[2];
1563
1564   if (reg_overlap_mentioned_p (op2, op0))
1565     abort ();
1566   if (! q_regs_operand (op1, QImode))
1567     {
1568       emit_insn (gen_movqi (op2, op1));
1569       op1 = op2;
1570     }
1571   emit_insn (gen_movqi (op0, op1));
1572   DONE;
1573 })
1574
1575 (define_insn "*swapqi"
1576   [(set (match_operand:QI 0 "register_operand" "+r")
1577         (match_operand:QI 1 "register_operand" "+r"))
1578    (set (match_dup 1)
1579         (match_dup 0))]
1580   ""
1581   "xchg{b}\t%1, %0"
1582   [(set_attr "type" "imov")
1583    (set_attr "pent_pair" "np")
1584    (set_attr "mode" "QI")
1585    (set_attr "modrm" "0")
1586    (set_attr "ppro_uops" "few")])
1587
1588 (define_expand "movstrictqi"
1589   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" ""))
1590         (match_operand:QI 1 "general_operand" ""))]
1591   "! TARGET_PARTIAL_REG_STALL"
1592 {
1593   /* Don't generate memory->memory moves, go through a register.  */
1594   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
1595     operands[1] = force_reg (QImode, operands[1]);
1596 })
1597
1598 (define_insn "*movstrictqi_1"
1599   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
1600         (match_operand:QI 1 "general_operand" "*qn,m"))]
1601   "! TARGET_PARTIAL_REG_STALL
1602    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
1603   "mov{b}\t{%1, %0|%0, %1}"
1604   [(set_attr "type" "imov")
1605    (set_attr "mode" "QI")])
1606
1607 (define_insn "*movstrictqi_xor"
1608   [(set (strict_low_part (match_operand:QI 0 "q_regs_operand" "+q"))
1609         (match_operand:QI 1 "const0_operand" "i"))
1610    (clobber (reg:CC 17))]
1611   "reload_completed && (!TARGET_USE_MOV0 || optimize_size)"
1612   "xor{b}\t{%0, %0|%0, %0}"
1613   [(set_attr "type" "alu1")
1614    (set_attr "mode" "QI")
1615    (set_attr "length_immediate" "0")])
1616
1617 (define_insn "*movsi_extv_1"
1618   [(set (match_operand:SI 0 "register_operand" "=R")
1619         (sign_extract:SI (match_operand 1 "ext_register_operand" "Q")
1620                          (const_int 8)
1621                          (const_int 8)))]
1622   ""
1623   "movs{bl|x}\t{%h1, %0|%0, %h1}"
1624   [(set_attr "type" "imovx")
1625    (set_attr "mode" "SI")])
1626
1627 (define_insn "*movhi_extv_1"
1628   [(set (match_operand:HI 0 "register_operand" "=R")
1629         (sign_extract:HI (match_operand 1 "ext_register_operand" "Q")
1630                          (const_int 8)
1631                          (const_int 8)))]
1632   ""
1633   "movs{bl|x}\t{%h1, %k0|%k0, %h1}"
1634   [(set_attr "type" "imovx")
1635    (set_attr "mode" "SI")])
1636
1637 (define_insn "*movqi_extv_1"
1638   [(set (match_operand:QI 0 "nonimmediate_operand" "=Qm,?r")
1639         (sign_extract:QI (match_operand 1 "ext_register_operand" "Q,Q")
1640                          (const_int 8)
1641                          (const_int 8)))]
1642   "!TARGET_64BIT"
1643 {
1644   switch (get_attr_type (insn))
1645     {
1646     case TYPE_IMOVX:
1647       return "movs{bl|x}\t{%h1, %k0|%k0, %h1}";
1648     default:
1649       return "mov{b}\t{%h1, %0|%0, %h1}";
1650     }
1651 }
1652   [(set (attr "type")
1653      (if_then_else (and (match_operand:QI 0 "register_operand" "")
1654                         (ior (not (match_operand:QI 0 "q_regs_operand" ""))
1655                              (ne (symbol_ref "TARGET_MOVX")
1656                                  (const_int 0))))
1657         (const_string "imovx")
1658         (const_string "imov")))
1659    (set (attr "mode")
1660      (if_then_else (eq_attr "type" "imovx")
1661         (const_string "SI")
1662         (const_string "QI")))])
1663
1664 (define_insn "*movqi_extv_1_rex64"
1665   [(set (match_operand:QI 0 "register_operand" "=Q,?R")
1666         (sign_extract:QI (match_operand 1 "ext_register_operand" "Q,Q")
1667                          (const_int 8)
1668                          (const_int 8)))]
1669   "TARGET_64BIT"
1670 {
1671   switch (get_attr_type (insn))
1672     {
1673     case TYPE_IMOVX:
1674       return "movs{bl|x}\t{%h1, %k0|%k0, %h1}";
1675     default:
1676       return "mov{b}\t{%h1, %0|%0, %h1}";
1677     }
1678 }
1679   [(set (attr "type")
1680      (if_then_else (and (match_operand:QI 0 "register_operand" "")
1681                         (ior (not (match_operand:QI 0 "q_regs_operand" ""))
1682                              (ne (symbol_ref "TARGET_MOVX")
1683                                  (const_int 0))))
1684         (const_string "imovx")
1685         (const_string "imov")))
1686    (set (attr "mode")
1687      (if_then_else (eq_attr "type" "imovx")
1688         (const_string "SI")
1689         (const_string "QI")))])
1690
1691 ;; Stores and loads of ax to arbitrary constant address.
1692 ;; We fake an second form of instruction to force reload to load address
1693 ;; into register when rax is not available
1694 (define_insn "*movabsqi_1_rex64"
1695   [(set (mem:QI (match_operand:DI 0 "x86_64_movabs_operand" "i,r,r"))
1696         (match_operand:QI 1 "nonmemory_operand" "a,er,i"))]
1697   "TARGET_64BIT"
1698   "@
1699    movabs{b}\t{%1, %P0|%P0, %1}
1700    mov{b}\t{%1, %a0|%a0, %1}
1701    movabs{b}\t{%1, %a0|%a0, %1}"
1702   [(set_attr "type" "imov")
1703    (set_attr "modrm" "0,*,*")
1704    (set_attr "length_address" "8,0,0")
1705    (set_attr "length_immediate" "0,*,*")
1706    (set_attr "memory" "store")
1707    (set_attr "mode" "QI")])
1708
1709 (define_insn "*movabsqi_2_rex64"
1710   [(set (match_operand:QI 0 "register_operand" "=a,r")
1711         (mem:QI (match_operand:DI 1 "x86_64_movabs_operand" "i,r")))]
1712   "TARGET_64BIT"
1713   "@
1714    movabs{b}\t{%P1, %0|%0, %P1}
1715    mov{b}\t{%a1, %0|%0, %a1}"
1716   [(set_attr "type" "imov")
1717    (set_attr "modrm" "0,*")
1718    (set_attr "length_address" "8,0")
1719    (set_attr "length_immediate" "0")
1720    (set_attr "memory" "load")
1721    (set_attr "mode" "QI")])
1722
1723 (define_insn "*movsi_extzv_1"
1724   [(set (match_operand:SI 0 "register_operand" "=R")
1725         (zero_extract:SI (match_operand 1 "ext_register_operand" "Q")
1726                          (const_int 8)
1727                          (const_int 8)))]
1728   ""
1729   "movz{bl|x}\t{%h1, %0|%0, %h1}"
1730   [(set_attr "type" "imovx")
1731    (set_attr "mode" "SI")])
1732
1733 (define_insn "*movqi_extzv_2"
1734   [(set (match_operand:QI 0 "nonimmediate_operand" "=Qm,?R")
1735         (subreg:QI (zero_extract:SI (match_operand 1 "ext_register_operand" "Q,Q")
1736                                     (const_int 8)
1737                                     (const_int 8)) 0))]
1738   "!TARGET_64BIT"
1739 {
1740   switch (get_attr_type (insn))
1741     {
1742     case TYPE_IMOVX:
1743       return "movz{bl|x}\t{%h1, %k0|%k0, %h1}";
1744     default:
1745       return "mov{b}\t{%h1, %0|%0, %h1}";
1746     }
1747 }
1748   [(set (attr "type")
1749      (if_then_else (and (match_operand:QI 0 "register_operand" "")
1750                         (ior (not (match_operand:QI 0 "q_regs_operand" ""))
1751                              (ne (symbol_ref "TARGET_MOVX")
1752                                  (const_int 0))))
1753         (const_string "imovx")
1754         (const_string "imov")))
1755    (set (attr "mode")
1756      (if_then_else (eq_attr "type" "imovx")
1757         (const_string "SI")
1758         (const_string "QI")))])
1759
1760 (define_insn "*movqi_extzv_2_rex64"
1761   [(set (match_operand:QI 0 "register_operand" "=Q,?R")
1762         (subreg:QI (zero_extract:SI (match_operand 1 "ext_register_operand" "Q,Q")
1763                                     (const_int 8)
1764                                     (const_int 8)) 0))]
1765   "TARGET_64BIT"
1766 {
1767   switch (get_attr_type (insn))
1768     {
1769     case TYPE_IMOVX:
1770       return "movz{bl|x}\t{%h1, %k0|%k0, %h1}";
1771     default:
1772       return "mov{b}\t{%h1, %0|%0, %h1}";
1773     }
1774 }
1775   [(set (attr "type")
1776      (if_then_else (ior (not (match_operand:QI 0 "q_regs_operand" ""))
1777                         (ne (symbol_ref "TARGET_MOVX")
1778                             (const_int 0)))
1779         (const_string "imovx")
1780         (const_string "imov")))
1781    (set (attr "mode")
1782      (if_then_else (eq_attr "type" "imovx")
1783         (const_string "SI")
1784         (const_string "QI")))])
1785
1786 (define_insn "movsi_insv_1"
1787   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "+Q")
1788                          (const_int 8)
1789                          (const_int 8))
1790         (match_operand:SI 1 "general_operand" "Qmn"))]
1791   "!TARGET_64BIT"
1792   "mov{b}\t{%b1, %h0|%h0, %b1}"
1793   [(set_attr "type" "imov")
1794    (set_attr "mode" "QI")])
1795
1796 (define_insn "*movsi_insv_1_rex64"
1797   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "+Q")
1798                          (const_int 8)
1799                          (const_int 8))
1800         (match_operand:SI 1 "nonmemory_operand" "Qn"))]
1801   "TARGET_64BIT"
1802   "mov{b}\t{%b1, %h0|%h0, %b1}"
1803   [(set_attr "type" "imov")
1804    (set_attr "mode" "QI")])
1805
1806 (define_insn "*movqi_insv_2"
1807   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "+Q")
1808                          (const_int 8)
1809                          (const_int 8))
1810         (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "Q")
1811                              (const_int 8))
1812                 (const_int 255)))]
1813   ""
1814   "mov{b}\t{%h1, %h0|%h0, %h1}"
1815   [(set_attr "type" "imov")
1816    (set_attr "mode" "QI")])
1817
1818 (define_expand "movdi"
1819   [(set (match_operand:DI 0 "nonimmediate_operand" "")
1820         (match_operand:DI 1 "general_operand" ""))]
1821   ""
1822   "ix86_expand_move (DImode, operands); DONE;")
1823
1824 (define_insn "*pushdi"
1825   [(set (match_operand:DI 0 "push_operand" "=<")
1826         (match_operand:DI 1 "general_no_elim_operand" "riF*m"))]
1827   "!TARGET_64BIT"
1828   "#")
1829
1830 (define_insn "pushdi2_rex64"
1831   [(set (match_operand:DI 0 "push_operand" "=<,!<")
1832         (match_operand:DI 1 "general_no_elim_operand" "re*m,n"))]
1833   "TARGET_64BIT"
1834   "@
1835    push{q}\t%1
1836    #"
1837   [(set_attr "type" "push,multi")
1838    (set_attr "mode" "DI")])
1839
1840 ;; Convert impossible pushes of immediate to existing instructions.
1841 ;; First try to get scratch register and go through it.  In case this
1842 ;; fails, push sign extended lower part first and then overwrite
1843 ;; upper part by 32bit move.
1844 (define_peephole2
1845   [(match_scratch:DI 2 "r")
1846    (set (match_operand:DI 0 "push_operand" "")
1847         (match_operand:DI 1 "immediate_operand" ""))]
1848   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
1849    && !x86_64_immediate_operand (operands[1], DImode)"
1850   [(set (match_dup 2) (match_dup 1))
1851    (set (match_dup 0) (match_dup 2))]
1852   "")
1853
1854 ;; We need to define this as both peepholer and splitter for case
1855 ;; peephole2 pass is not run.
1856 (define_peephole2
1857   [(set (match_operand:DI 0 "push_operand" "")
1858         (match_operand:DI 1 "immediate_operand" ""))]
1859   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
1860    && !x86_64_immediate_operand (operands[1], DImode) && 1"
1861   [(set (match_dup 0) (match_dup 1))
1862    (set (match_dup 2) (match_dup 3))]
1863   "split_di (operands + 1, 1, operands + 2, operands + 3);
1864    operands[1] = gen_lowpart (DImode, operands[2]);
1865    operands[2] = gen_rtx_MEM (SImode, gen_rtx_PLUS (DImode, stack_pointer_rtx,
1866                                                     GEN_INT (4)));
1867   ")
1868
1869 (define_split
1870   [(set (match_operand:DI 0 "push_operand" "")
1871         (match_operand:DI 1 "immediate_operand" ""))]
1872   "TARGET_64BIT && (flow2_completed || (reload_completed && !flag_peephole2))
1873    && !symbolic_operand (operands[1], DImode)
1874    && !x86_64_immediate_operand (operands[1], DImode)"
1875   [(set (match_dup 0) (match_dup 1))
1876    (set (match_dup 2) (match_dup 3))]
1877   "split_di (operands + 1, 1, operands + 2, operands + 3);
1878    operands[1] = gen_lowpart (DImode, operands[2]);
1879    operands[2] = gen_rtx_MEM (SImode, gen_rtx_PLUS (DImode, stack_pointer_rtx,
1880                                                     GEN_INT (4)));
1881   ")
1882
1883 (define_insn "*pushdi2_prologue_rex64"
1884   [(set (match_operand:DI 0 "push_operand" "=<")
1885         (match_operand:DI 1 "general_no_elim_operand" "re*m"))
1886    (clobber (mem:BLK (scratch)))]
1887   "TARGET_64BIT"
1888   "push{q}\t%1"
1889   [(set_attr "type" "push")
1890    (set_attr "mode" "DI")])
1891
1892 (define_insn "*popdi1_epilogue_rex64"
1893   [(set (match_operand:DI 0 "nonimmediate_operand" "=r*m")
1894         (mem:DI (reg:DI 7)))
1895    (set (reg:DI 7)
1896         (plus:DI (reg:DI 7) (const_int 8)))
1897    (clobber (mem:BLK (scratch)))]
1898   "TARGET_64BIT"
1899   "pop{q}\t%0"
1900   [(set_attr "type" "pop")
1901    (set_attr "mode" "DI")])
1902
1903 (define_insn "popdi1"
1904   [(set (match_operand:DI 0 "nonimmediate_operand" "=r*m")
1905         (mem:DI (reg:DI 7)))
1906    (set (reg:DI 7)
1907         (plus:DI (reg:DI 7) (const_int 8)))]
1908   "TARGET_64BIT"
1909   "pop{q}\t%0"
1910   [(set_attr "type" "pop")
1911    (set_attr "mode" "DI")])
1912
1913 (define_insn "*movdi_xor_rex64"
1914   [(set (match_operand:DI 0 "register_operand" "=r")
1915         (match_operand:DI 1 "const0_operand" "i"))
1916    (clobber (reg:CC 17))]
1917   "TARGET_64BIT && (!TARGET_USE_MOV0 || optimize_size)
1918    && reload_completed"
1919   "xor{l}\t{%k0, %k0|%k0, %k0}"
1920   [(set_attr "type" "alu1")
1921    (set_attr "mode" "SI")
1922    (set_attr "length_immediate" "0")])
1923
1924 (define_insn "*movdi_or_rex64"
1925   [(set (match_operand:DI 0 "register_operand" "=r")
1926         (match_operand:DI 1 "const_int_operand" "i"))
1927    (clobber (reg:CC 17))]
1928   "TARGET_64BIT && (TARGET_PENTIUM || optimize_size)
1929    && reload_completed
1930    && GET_CODE (operands[1]) == CONST_INT
1931    && INTVAL (operands[1]) == -1"
1932 {
1933   operands[1] = constm1_rtx;
1934   return "or{q}\t{%1, %0|%0, %1}";
1935 }
1936   [(set_attr "type" "alu1")
1937    (set_attr "mode" "DI")
1938    (set_attr "length_immediate" "1")])
1939
1940 (define_insn "*movdi_2"
1941   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,o,!m*y,!*y,!m,!*Y,!*Y")
1942         (match_operand:DI 1 "general_operand" "riFo,riF,*y,m,*Y,*Y,m"))]
1943   "!TARGET_64BIT
1944    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
1945   "@
1946    #
1947    #
1948    movq\t{%1, %0|%0, %1}
1949    movq\t{%1, %0|%0, %1}
1950    movq\t{%1, %0|%0, %1}
1951    movdqa\t{%1, %0|%0, %1}
1952    movq\t{%1, %0|%0, %1}"
1953   [(set_attr "type" "*,*,mmx,mmx,ssemov,ssemov,ssemov")
1954    (set_attr "mode" "DI,DI,DI,DI,DI,TI,DI")])
1955
1956 (define_split
1957   [(set (match_operand:DI 0 "push_operand" "")
1958         (match_operand:DI 1 "general_operand" ""))]
1959   "!TARGET_64BIT && reload_completed
1960    && (! MMX_REG_P (operands[1]) && !SSE_REG_P (operands[1]))"
1961   [(const_int 0)]
1962   "ix86_split_long_move (operands); DONE;")
1963
1964 ;; %%% This multiword shite has got to go.
1965 (define_split
1966   [(set (match_operand:DI 0 "nonimmediate_operand" "")
1967         (match_operand:DI 1 "general_operand" ""))]
1968   "!TARGET_64BIT && reload_completed
1969    && (!MMX_REG_P (operands[0]) && !SSE_REG_P (operands[0]))
1970    && (!MMX_REG_P (operands[1]) && !SSE_REG_P (operands[1]))"
1971   [(const_int 0)]
1972   "ix86_split_long_move (operands); DONE;")
1973
1974 (define_insn "*movdi_1_rex64"
1975   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,r,mr,!mr,!*y,!rm,!*y,!*Y,!rm,!*Y")
1976         (match_operand:DI 1 "general_operand" "Z,rem,i,re,n,*y,*y,rm,*Y,*Y,rm"))]
1977   "TARGET_64BIT
1978    && (TARGET_INTER_UNIT_MOVES || optimize_size)
1979    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
1980 {
1981   switch (get_attr_type (insn))
1982     {
1983     case TYPE_SSEMOV:
1984       if (get_attr_mode (insn) == MODE_TI)
1985           return "movdqa\t{%1, %0|%0, %1}";
1986       /* FALLTHRU */
1987     case TYPE_MMXMOV:
1988       /* Moves from and into integer register is done using movd opcode with
1989          REX prefix.  */
1990       if (GENERAL_REG_P (operands[0]) || GENERAL_REG_P (operands[1]))
1991           return "movd\t{%1, %0|%0, %1}";
1992       return "movq\t{%1, %0|%0, %1}";
1993     case TYPE_MULTI:
1994       return "#";
1995     case TYPE_LEA:
1996       return "lea{q}\t{%a1, %0|%0, %a1}";
1997     default:
1998       if (flag_pic && !LEGITIMATE_PIC_OPERAND_P (operands[1]))
1999         abort ();
2000       if (get_attr_mode (insn) == MODE_SI)
2001         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2002       else if (which_alternative == 2)
2003         return "movabs{q}\t{%1, %0|%0, %1}";
2004       else
2005         return "mov{q}\t{%1, %0|%0, %1}";
2006     }
2007 }
2008   [(set (attr "type")
2009      (cond [(eq_attr "alternative" "5,6,7")
2010               (const_string "mmxmov")
2011             (eq_attr "alternative" "8,9,10")
2012               (const_string "ssemov")
2013             (eq_attr "alternative" "4")
2014               (const_string "multi")
2015             (and (ne (symbol_ref "flag_pic") (const_int 0))
2016                  (match_operand:DI 1 "symbolic_operand" ""))
2017               (const_string "lea")
2018            ]
2019            (const_string "imov")))
2020    (set_attr "modrm" "*,0,0,*,*,*,*,*,*,*,*")
2021    (set_attr "length_immediate" "*,4,8,*,*,*,*,*,*,*,*")
2022    (set_attr "mode" "SI,DI,DI,DI,SI,DI,DI,DI,TI,DI,DI")])
2023
2024 (define_insn "*movdi_1_rex64_nointerunit"
2025   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,r,mr,!mr,!*y,!m,!*y,!*Y,!m,!*Y")
2026         (match_operand:DI 1 "general_operand" "Z,rem,i,re,n,*y,*y,m,*Y,*Y,m"))]
2027   "TARGET_64BIT
2028    && (!TARGET_INTER_UNIT_MOVES && !optimize_size)
2029    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
2030 {
2031   switch (get_attr_type (insn))
2032     {
2033     case TYPE_SSEMOV:
2034       if (get_attr_mode (insn) == MODE_TI)
2035           return "movdqa\t{%1, %0|%0, %1}";
2036       /* FALLTHRU */
2037     case TYPE_MMXMOV:
2038       return "movq\t{%1, %0|%0, %1}";
2039     case TYPE_MULTI:
2040       return "#";
2041     case TYPE_LEA:
2042       return "lea{q}\t{%a1, %0|%0, %a1}";
2043     default:
2044       if (flag_pic && !LEGITIMATE_PIC_OPERAND_P (operands[1]))
2045         abort ();
2046       if (get_attr_mode (insn) == MODE_SI)
2047         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2048       else if (which_alternative == 2)
2049         return "movabs{q}\t{%1, %0|%0, %1}";
2050       else
2051         return "mov{q}\t{%1, %0|%0, %1}";
2052     }
2053 }
2054   [(set (attr "type")
2055      (cond [(eq_attr "alternative" "5,6,7")
2056               (const_string "mmxmov")
2057             (eq_attr "alternative" "8,9,10")
2058               (const_string "ssemov")
2059             (eq_attr "alternative" "4")
2060               (const_string "multi")
2061             (and (ne (symbol_ref "flag_pic") (const_int 0))
2062                  (match_operand:DI 1 "symbolic_operand" ""))
2063               (const_string "lea")
2064            ]
2065            (const_string "imov")))
2066    (set_attr "modrm" "*,0,0,*,*,*,*,*,*,*,*")
2067    (set_attr "length_immediate" "*,4,8,*,*,*,*,*,*,*,*")
2068    (set_attr "mode" "SI,DI,DI,DI,SI,DI,DI,DI,TI,DI,DI")])
2069
2070 ;; Stores and loads of ax to arbitrary constant address.
2071 ;; We fake an second form of instruction to force reload to load address
2072 ;; into register when rax is not available
2073 (define_insn "*movabsdi_1_rex64"
2074   [(set (mem:DI (match_operand:DI 0 "x86_64_movabs_operand" "i,r,r"))
2075         (match_operand:DI 1 "nonmemory_operand" "a,er,i"))]
2076   "TARGET_64BIT"
2077   "@
2078    movabs{q}\t{%1, %P0|%P0, %1}
2079    mov{q}\t{%1, %a0|%a0, %1}
2080    movabs{q}\t{%1, %a0|%a0, %1}"
2081   [(set_attr "type" "imov")
2082    (set_attr "modrm" "0,*,*")
2083    (set_attr "length_address" "8,0,0")
2084    (set_attr "length_immediate" "0,*,*")
2085    (set_attr "memory" "store")
2086    (set_attr "mode" "DI")])
2087
2088 (define_insn "*movabsdi_2_rex64"
2089   [(set (match_operand:DI 0 "register_operand" "=a,r")
2090         (mem:DI (match_operand:DI 1 "x86_64_movabs_operand" "i,r")))]
2091   "TARGET_64BIT"
2092   "@
2093    movabs{q}\t{%P1, %0|%0, %P1}
2094    mov{q}\t{%a1, %0|%0, %a1}"
2095   [(set_attr "type" "imov")
2096    (set_attr "modrm" "0,*")
2097    (set_attr "length_address" "8,0")
2098    (set_attr "length_immediate" "0")
2099    (set_attr "memory" "load")
2100    (set_attr "mode" "DI")])
2101
2102 ;; Convert impossible stores of immediate to existing instructions.
2103 ;; First try to get scratch register and go through it.  In case this
2104 ;; fails, move by 32bit parts.
2105 (define_peephole2
2106   [(match_scratch:DI 2 "r")
2107    (set (match_operand:DI 0 "memory_operand" "")
2108         (match_operand:DI 1 "immediate_operand" ""))]
2109   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
2110    && !x86_64_immediate_operand (operands[1], DImode)"
2111   [(set (match_dup 2) (match_dup 1))
2112    (set (match_dup 0) (match_dup 2))]
2113   "")
2114
2115 ;; We need to define this as both peepholer and splitter for case
2116 ;; peephole2 pass is not run.
2117 (define_peephole2
2118   [(set (match_operand:DI 0 "memory_operand" "")
2119         (match_operand:DI 1 "immediate_operand" ""))]
2120   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
2121    && !x86_64_immediate_operand (operands[1], DImode) && 1"
2122   [(set (match_dup 2) (match_dup 3))
2123    (set (match_dup 4) (match_dup 5))]
2124   "split_di (operands, 2, operands + 2, operands + 4);")
2125
2126 (define_split
2127   [(set (match_operand:DI 0 "memory_operand" "")
2128         (match_operand:DI 1 "immediate_operand" ""))]
2129   "TARGET_64BIT && (flow2_completed || (reload_completed && !flag_peephole2))
2130    && !symbolic_operand (operands[1], DImode)
2131    && !x86_64_immediate_operand (operands[1], DImode)"
2132   [(set (match_dup 2) (match_dup 3))
2133    (set (match_dup 4) (match_dup 5))]
2134   "split_di (operands, 2, operands + 2, operands + 4);")
2135
2136 (define_insn "*swapdi_rex64"
2137   [(set (match_operand:DI 0 "register_operand" "+r")
2138         (match_operand:DI 1 "register_operand" "+r"))
2139    (set (match_dup 1)
2140         (match_dup 0))]
2141   "TARGET_64BIT"
2142   "xchg{q}\t%1, %0"
2143   [(set_attr "type" "imov")
2144    (set_attr "pent_pair" "np")
2145    (set_attr "athlon_decode" "vector")
2146    (set_attr "mode" "DI")
2147    (set_attr "modrm" "0")
2148    (set_attr "ppro_uops" "few")])
2149
2150   
2151 (define_expand "movsf"
2152   [(set (match_operand:SF 0 "nonimmediate_operand" "")
2153         (match_operand:SF 1 "general_operand" ""))]
2154   ""
2155   "ix86_expand_move (SFmode, operands); DONE;")
2156
2157 (define_insn "*pushsf"
2158   [(set (match_operand:SF 0 "push_operand" "=<,<,<")
2159         (match_operand:SF 1 "general_no_elim_operand" "f#rx,rFm#fx,x#rf"))]
2160   "!TARGET_64BIT"
2161 {
2162   switch (which_alternative)
2163     {
2164     case 1:
2165       return "push{l}\t%1";
2166
2167     default:
2168       /* This insn should be already splitted before reg-stack.  */
2169       abort ();
2170     }
2171 }
2172   [(set_attr "type" "multi,push,multi")
2173    (set_attr "mode" "SF,SI,SF")])
2174
2175 (define_insn "*pushsf_rex64"
2176   [(set (match_operand:SF 0 "push_operand" "=X,X,X")
2177         (match_operand:SF 1 "nonmemory_no_elim_operand" "f#rx,rF#fx,x#rf"))]
2178   "TARGET_64BIT"
2179 {
2180   switch (which_alternative)
2181     {
2182     case 1:
2183       return "push{q}\t%q1";
2184
2185     default:
2186       /* This insn should be already splitted before reg-stack.  */
2187       abort ();
2188     }
2189 }
2190   [(set_attr "type" "multi,push,multi")
2191    (set_attr "mode" "SF,DI,SF")])
2192
2193 (define_split
2194   [(set (match_operand:SF 0 "push_operand" "")
2195         (match_operand:SF 1 "memory_operand" ""))]
2196   "reload_completed
2197    && GET_CODE (operands[1]) == MEM
2198    && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
2199    && CONSTANT_POOL_ADDRESS_P (XEXP (operands[1], 0))"
2200   [(set (match_dup 0)
2201         (match_dup 1))]
2202   "operands[1] = get_pool_constant (XEXP (operands[1], 0));")
2203
2204
2205 ;; %%% Kill this when call knows how to work this out.
2206 (define_split
2207   [(set (match_operand:SF 0 "push_operand" "")
2208         (match_operand:SF 1 "any_fp_register_operand" ""))]
2209   "!TARGET_64BIT"
2210   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -4)))
2211    (set (mem:SF (reg:SI 7)) (match_dup 1))])
2212
2213 (define_split
2214   [(set (match_operand:SF 0 "push_operand" "")
2215         (match_operand:SF 1 "any_fp_register_operand" ""))]
2216   "TARGET_64BIT"
2217   [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -8)))
2218    (set (mem:SF (reg:DI 7)) (match_dup 1))])
2219
2220 (define_insn "*movsf_1"
2221   [(set (match_operand:SF 0 "nonimmediate_operand" "=f#xr,m,f#xr,r#xf,m,x#rf,x#rf,x#rf,m,!*y,!rm,!*y")
2222         (match_operand:SF 1 "general_operand" "fm#rx,f#rx,G,rmF#fx,Fr#fx,C,x,xm#rf,x#rf,rm,*y,*y"))]
2223   "(TARGET_INTER_UNIT_MOVES || optimize_size)
2224    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
2225    && (reload_in_progress || reload_completed
2226        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
2227        || GET_CODE (operands[1]) != CONST_DOUBLE
2228        || memory_operand (operands[0], SFmode))" 
2229 {
2230   switch (which_alternative)
2231     {
2232     case 0:
2233       if (REG_P (operands[1])
2234           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2235         return "fstp\t%y0";
2236       else if (STACK_TOP_P (operands[0]))
2237         return "fld%z1\t%y1";
2238       else
2239         return "fst\t%y0";
2240
2241     case 1:
2242       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2243         return "fstp%z0\t%y0";
2244       else
2245         return "fst%z0\t%y0";
2246
2247     case 2:
2248       switch (standard_80387_constant_p (operands[1]))
2249         {
2250         case 1:
2251           return "fldz";
2252         case 2:
2253           return "fld1";
2254         }
2255       abort();
2256
2257     case 3:
2258     case 4:
2259       return "mov{l}\t{%1, %0|%0, %1}";
2260     case 5:
2261       if (get_attr_mode (insn) == MODE_TI)
2262         return "pxor\t%0, %0";
2263       else
2264         return "xorps\t%0, %0";
2265     case 6:
2266       if (get_attr_mode (insn) == MODE_V4SF)
2267         return "movaps\t{%1, %0|%0, %1}";
2268       else
2269         return "movss\t{%1, %0|%0, %1}";
2270     case 7:
2271     case 8:
2272       return "movss\t{%1, %0|%0, %1}";
2273
2274     case 9:
2275     case 10:
2276       return "movd\t{%1, %0|%0, %1}";
2277
2278     case 11:
2279       return "movq\t{%1, %0|%0, %1}";
2280
2281     default:
2282       abort();
2283     }
2284 }
2285   [(set_attr "type" "fmov,fmov,fmov,imov,imov,ssemov,ssemov,ssemov,ssemov,mmxmov,mmxmov,mmxmov")
2286    (set (attr "mode")
2287         (cond [(eq_attr "alternative" "3,4,9,10")
2288                  (const_string "SI")
2289                (eq_attr "alternative" "5")
2290                  (if_then_else
2291                    (and (and (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
2292                                  (const_int 0))
2293                              (ne (symbol_ref "TARGET_SSE2")
2294                                  (const_int 0)))
2295                         (eq (symbol_ref "optimize_size")
2296                             (const_int 0)))
2297                    (const_string "TI")
2298                    (const_string "V4SF"))
2299                /* For architectures resolving dependencies on
2300                   whole SSE registers use APS move to break dependency
2301                   chains, otherwise use short move to avoid extra work. 
2302
2303                   Do the same for architectures resolving dependencies on
2304                   the parts.  While in DF mode it is better to always handle
2305                   just register parts, the SF mode is different due to lack
2306                   of instructions to load just part of the register.  It is
2307                   better to maintain the whole registers in single format
2308                   to avoid problems on using packed logical operations.  */
2309                (eq_attr "alternative" "6")
2310                  (if_then_else
2311                    (ior (ne (symbol_ref "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
2312                             (const_int 0))
2313                         (ne (symbol_ref "TARGET_SSE_PARTIAL_REGS")
2314                             (const_int 0)))
2315                    (const_string "V4SF")
2316                    (const_string "SF"))
2317                (eq_attr "alternative" "11")
2318                  (const_string "DI")]
2319                (const_string "SF")))])
2320
2321 (define_insn "*movsf_1_nointerunit"
2322   [(set (match_operand:SF 0 "nonimmediate_operand" "=f#xr,m,f#xr,r#xf,m,x#rf,x#rf,x#rf,m,!*y,!m,!*y")
2323         (match_operand:SF 1 "general_operand" "fm#rx,f#rx,G,rmF#fx,Fr#fx,C,x,xm#rf,x#rf,m,*y,*y"))]
2324   "(!TARGET_INTER_UNIT_MOVES && !optimize_size)
2325    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
2326    && (reload_in_progress || reload_completed
2327        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
2328        || GET_CODE (operands[1]) != CONST_DOUBLE
2329        || memory_operand (operands[0], SFmode))" 
2330 {
2331   switch (which_alternative)
2332     {
2333     case 0:
2334       if (REG_P (operands[1])
2335           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2336         {
2337           if (REGNO (operands[0]) == FIRST_STACK_REG
2338               && TARGET_USE_FFREEP)
2339             return "ffreep\t%y0";
2340           return "fstp\t%y0";
2341         }
2342       else if (STACK_TOP_P (operands[0]))
2343         return "fld%z1\t%y1";
2344       else
2345         return "fst\t%y0";
2346
2347     case 1:
2348       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2349         return "fstp%z0\t%y0";
2350       else
2351         return "fst%z0\t%y0";
2352
2353     case 2:
2354       switch (standard_80387_constant_p (operands[1]))
2355         {
2356         case 1:
2357           return "fldz";
2358         case 2:
2359           return "fld1";
2360         }
2361       abort();
2362
2363     case 3:
2364     case 4:
2365       return "mov{l}\t{%1, %0|%0, %1}";
2366     case 5:
2367       if (get_attr_mode (insn) == MODE_TI)
2368         return "pxor\t%0, %0";
2369       else
2370         return "xorps\t%0, %0";
2371     case 6:
2372       if (get_attr_mode (insn) == MODE_V4SF)
2373         return "movaps\t{%1, %0|%0, %1}";
2374       else
2375         return "movss\t{%1, %0|%0, %1}";
2376     case 7:
2377     case 8:
2378       return "movss\t{%1, %0|%0, %1}";
2379
2380     case 9:
2381     case 10:
2382       return "movd\t{%1, %0|%0, %1}";
2383
2384     case 11:
2385       return "movq\t{%1, %0|%0, %1}";
2386
2387     default:
2388       abort();
2389     }
2390 }
2391   [(set_attr "type" "fmov,fmov,fmov,imov,imov,ssemov,ssemov,ssemov,ssemov,mmxmov,mmxmov,mmxmov")
2392    (set (attr "mode")
2393         (cond [(eq_attr "alternative" "3,4,9,10")
2394                  (const_string "SI")
2395                (eq_attr "alternative" "5")
2396                  (if_then_else
2397                    (and (and (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
2398                                  (const_int 0))
2399                              (ne (symbol_ref "TARGET_SSE2")
2400                                  (const_int 0)))
2401                         (eq (symbol_ref "optimize_size")
2402                             (const_int 0)))
2403                    (const_string "TI")
2404                    (const_string "V4SF"))
2405                /* For architectures resolving dependencies on
2406                   whole SSE registers use APS move to break dependency
2407                   chains, otherwise use short move to avoid extra work. 
2408
2409                   Do the same for architectures resolving dependencies on
2410                   the parts.  While in DF mode it is better to always handle
2411                   just register parts, the SF mode is different due to lack
2412                   of instructions to load just part of the register.  It is
2413                   better to maintain the whole registers in single format
2414                   to avoid problems on using packed logical operations.  */
2415                (eq_attr "alternative" "6")
2416                  (if_then_else
2417                    (ior (ne (symbol_ref "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
2418                             (const_int 0))
2419                         (ne (symbol_ref "TARGET_SSE_PARTIAL_REGS")
2420                             (const_int 0)))
2421                    (const_string "V4SF")
2422                    (const_string "SF"))
2423                (eq_attr "alternative" "11")
2424                  (const_string "DI")]
2425                (const_string "SF")))])
2426
2427 (define_insn "*swapsf"
2428   [(set (match_operand:SF 0 "register_operand" "+f")
2429         (match_operand:SF 1 "register_operand" "+f"))
2430    (set (match_dup 1)
2431         (match_dup 0))]
2432   "reload_completed || !TARGET_SSE"
2433 {
2434   if (STACK_TOP_P (operands[0]))
2435     return "fxch\t%1";
2436   else
2437     return "fxch\t%0";
2438 }
2439   [(set_attr "type" "fxch")
2440    (set_attr "mode" "SF")])
2441
2442 (define_expand "movdf"
2443   [(set (match_operand:DF 0 "nonimmediate_operand" "")
2444         (match_operand:DF 1 "general_operand" ""))]
2445   ""
2446   "ix86_expand_move (DFmode, operands); DONE;")
2447
2448 ;; Size of pushdf is 3 (for sub) + 2 (for fstp) + memory operand size.
2449 ;; Size of pushdf using integer instructions is 2+2*memory operand size
2450 ;; On the average, pushdf using integers can be still shorter.  Allow this
2451 ;; pattern for optimize_size too.
2452
2453 (define_insn "*pushdf_nointeger"
2454   [(set (match_operand:DF 0 "push_operand" "=<,<,<,<")
2455         (match_operand:DF 1 "general_no_elim_operand" "f#Y,Fo#fY,*r#fY,Y#f"))]
2456   "!TARGET_64BIT && !TARGET_INTEGER_DFMODE_MOVES"
2457 {
2458   /* This insn should be already splitted before reg-stack.  */
2459   abort ();
2460 }
2461   [(set_attr "type" "multi")
2462    (set_attr "mode" "DF,SI,SI,DF")])
2463
2464 (define_insn "*pushdf_integer"
2465   [(set (match_operand:DF 0 "push_operand" "=<,<,<")
2466         (match_operand:DF 1 "general_no_elim_operand" "f#rY,rFo#fY,Y#rf"))]
2467   "TARGET_64BIT || TARGET_INTEGER_DFMODE_MOVES"
2468 {
2469   /* This insn should be already splitted before reg-stack.  */
2470   abort ();
2471 }
2472   [(set_attr "type" "multi")
2473    (set_attr "mode" "DF,SI,DF")])
2474
2475 ;; %%% Kill this when call knows how to work this out.
2476 (define_split
2477   [(set (match_operand:DF 0 "push_operand" "")
2478         (match_operand:DF 1 "any_fp_register_operand" ""))]
2479   "!TARGET_64BIT && reload_completed"
2480   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -8)))
2481    (set (mem:DF (reg:SI 7)) (match_dup 1))]
2482   "")
2483
2484 (define_split
2485   [(set (match_operand:DF 0 "push_operand" "")
2486         (match_operand:DF 1 "any_fp_register_operand" ""))]
2487   "TARGET_64BIT && reload_completed"
2488   [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -8)))
2489    (set (mem:DF (reg:DI 7)) (match_dup 1))]
2490   "")
2491
2492 (define_split
2493   [(set (match_operand:DF 0 "push_operand" "")
2494         (match_operand:DF 1 "general_operand" ""))]
2495   "reload_completed"
2496   [(const_int 0)]
2497   "ix86_split_long_move (operands); DONE;")
2498
2499 ;; Moving is usually shorter when only FP registers are used. This separate
2500 ;; movdf pattern avoids the use of integer registers for FP operations
2501 ;; when optimizing for size.
2502
2503 (define_insn "*movdf_nointeger"
2504   [(set (match_operand:DF 0 "nonimmediate_operand" "=f#Y,m,f#Y,*r,o,Y#f,Y#f,Y#f,m")
2505         (match_operand:DF 1 "general_operand" "fm#Y,f#Y,G,*roF,F*r,C,Y#f,YHm#f,Y#f"))]
2506   "(GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
2507    && ((optimize_size || !TARGET_INTEGER_DFMODE_MOVES) && !TARGET_64BIT)
2508    && (reload_in_progress || reload_completed
2509        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
2510        || GET_CODE (operands[1]) != CONST_DOUBLE
2511        || memory_operand (operands[0], DFmode))" 
2512 {
2513   switch (which_alternative)
2514     {
2515     case 0:
2516       if (REG_P (operands[1])
2517           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2518         {
2519           if (REGNO (operands[0]) == FIRST_STACK_REG
2520               && TARGET_USE_FFREEP)
2521             return "ffreep\t%y0";
2522           return "fstp\t%y0";
2523         }
2524       else if (STACK_TOP_P (operands[0]))
2525         return "fld%z1\t%y1";
2526       else
2527         return "fst\t%y0";
2528
2529     case 1:
2530       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2531         return "fstp%z0\t%y0";
2532       else
2533         return "fst%z0\t%y0";
2534
2535     case 2:
2536       switch (standard_80387_constant_p (operands[1]))
2537         {
2538         case 1:
2539           return "fldz";
2540         case 2:
2541           return "fld1";
2542         }
2543       abort();
2544
2545     case 3:
2546     case 4:
2547       return "#";
2548     case 5:
2549       switch (get_attr_mode (insn))
2550         {
2551         case MODE_V4SF:
2552           return "xorps\t%0, %0";
2553         case MODE_V2DF:
2554           return "xorpd\t%0, %0";
2555         case MODE_TI:
2556           return "pxor\t%0, %0";
2557         default:
2558           abort ();
2559         }
2560     case 6:
2561       switch (get_attr_mode (insn))
2562         {
2563         case MODE_V4SF:
2564           return "movaps\t{%1, %0|%0, %1}";
2565         case MODE_V2DF:
2566           return "movapd\t{%1, %0|%0, %1}";
2567         case MODE_DF:
2568           return "movsd\t{%1, %0|%0, %1}";
2569         default:
2570           abort ();
2571         }
2572     case 7:
2573       if (get_attr_mode (insn) == MODE_V2DF)
2574         return "movlpd\t{%1, %0|%0, %1}";
2575       else
2576         return "movsd\t{%1, %0|%0, %1}";
2577     case 8:
2578       return "movsd\t{%1, %0|%0, %1}";
2579
2580     default:
2581       abort();
2582     }
2583 }
2584   [(set_attr "type" "fmov,fmov,fmov,multi,multi,ssemov,ssemov,ssemov,ssemov")
2585    (set (attr "mode")
2586         (cond [(eq_attr "alternative" "3,4")
2587                  (const_string "SI")
2588                /* xorps is one byte shorter.  */
2589                (eq_attr "alternative" "5")
2590                  (cond [(ne (symbol_ref "optimize_size")
2591                             (const_int 0))
2592                           (const_string "V4SF")
2593                         (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
2594                             (const_int 0))
2595                           (const_string "TI")]
2596                        (const_string "V2DF"))
2597                /* For architectures resolving dependencies on
2598                   whole SSE registers use APD move to break dependency
2599                   chains, otherwise use short move to avoid extra work.
2600
2601                   movaps encodes one byte shorter.  */
2602                (eq_attr "alternative" "6")
2603                  (cond
2604                   [(ne (symbol_ref "optimize_size")
2605                        (const_int 0))
2606                      (const_string "V4SF")
2607                    (ne (symbol_ref "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
2608                        (const_int 0))
2609                      (const_string "V2DF")]
2610                    (const_string "DF"))
2611                /* For architectures resolving dependencies on register
2612                   parts we may avoid extra work to zero out upper part
2613                   of register.  */
2614                (eq_attr "alternative" "7")
2615                  (if_then_else
2616                    (ne (symbol_ref "TARGET_SSE_PARTIAL_REGS")
2617                        (const_int 0))
2618                    (const_string "V2DF")
2619                    (const_string "DF"))]
2620                (const_string "DF")))])
2621
2622 (define_insn "*movdf_integer"
2623   [(set (match_operand:DF 0 "nonimmediate_operand" "=f#Yr,m,f#Yr,r#Yf,o,Y#rf,Y#rf,Y#rf,m")
2624         (match_operand:DF 1 "general_operand" "fm#Yr,f#Yr,G,roF#Yf,Fr#Yf,C,Y#rf,Ym#rf,Y#rf"))]
2625   "(GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
2626    && ((!optimize_size && TARGET_INTEGER_DFMODE_MOVES) || TARGET_64BIT)
2627    && (reload_in_progress || reload_completed
2628        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
2629        || GET_CODE (operands[1]) != CONST_DOUBLE
2630        || memory_operand (operands[0], DFmode))" 
2631 {
2632   switch (which_alternative)
2633     {
2634     case 0:
2635       if (REG_P (operands[1])
2636           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2637         {
2638           if (REGNO (operands[0]) == FIRST_STACK_REG
2639               && TARGET_USE_FFREEP)
2640             return "ffreep\t%y0";
2641           return "fstp\t%y0";
2642         }
2643       else if (STACK_TOP_P (operands[0]))
2644         return "fld%z1\t%y1";
2645       else
2646         return "fst\t%y0";
2647
2648     case 1:
2649       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2650         return "fstp%z0\t%y0";
2651       else
2652         return "fst%z0\t%y0";
2653
2654     case 2:
2655       switch (standard_80387_constant_p (operands[1]))
2656         {
2657         case 1:
2658           return "fldz";
2659         case 2:
2660           return "fld1";
2661         }
2662       abort();
2663
2664     case 3:
2665     case 4:
2666       return "#";
2667
2668     case 5:
2669       switch (get_attr_mode (insn))
2670         {
2671         case MODE_V4SF:
2672           return "xorps\t%0, %0";
2673         case MODE_V2DF:
2674           return "xorpd\t%0, %0";
2675         case MODE_TI:
2676           return "pxor\t%0, %0";
2677         default:
2678           abort ();
2679         }
2680     case 6:
2681       switch (get_attr_mode (insn))
2682         {
2683         case MODE_V4SF:
2684           return "movaps\t{%1, %0|%0, %1}";
2685         case MODE_V2DF:
2686           return "movapd\t{%1, %0|%0, %1}";
2687         case MODE_DF:
2688           return "movsd\t{%1, %0|%0, %1}";
2689         default:
2690           abort ();
2691         }
2692     case 7:
2693       if (get_attr_mode (insn) == MODE_V2DF)
2694         return "movlpd\t{%1, %0|%0, %1}";
2695       else
2696         return "movsd\t{%1, %0|%0, %1}";
2697     case 8:
2698       return "movsd\t{%1, %0|%0, %1}";
2699
2700     default:
2701       abort();
2702     }
2703 }
2704   [(set_attr "type" "fmov,fmov,fmov,multi,multi,ssemov,ssemov,ssemov,ssemov")
2705    (set (attr "mode")
2706         (cond [(eq_attr "alternative" "3,4")
2707                  (const_string "SI")
2708                /* xorps is one byte shorter.  */
2709                (eq_attr "alternative" "5")
2710                  (cond [(ne (symbol_ref "optimize_size")
2711                             (const_int 0))
2712                           (const_string "V4SF")
2713                         (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
2714                             (const_int 0))
2715                           (const_string "TI")]
2716                        (const_string "V2DF"))
2717                /* For architectures resolving dependencies on
2718                   whole SSE registers use APD move to break dependency
2719                   chains, otherwise use short move to avoid extra work.  
2720
2721                   movaps encodes one byte shorter.  */
2722                (eq_attr "alternative" "6")
2723                  (cond
2724                   [(ne (symbol_ref "optimize_size")
2725                        (const_int 0))
2726                      (const_string "V4SF")
2727                    (ne (symbol_ref "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
2728                        (const_int 0))
2729                      (const_string "V2DF")]
2730                    (const_string "DF"))
2731                /* For architectures resolving dependencies on register
2732                   parts we may avoid extra work to zero out upper part
2733                   of register.  */
2734                (eq_attr "alternative" "7")
2735                  (if_then_else
2736                    (ne (symbol_ref "TARGET_SSE_PARTIAL_REGS")
2737                        (const_int 0))
2738                    (const_string "V2DF")
2739                    (const_string "DF"))]
2740                (const_string "DF")))])
2741
2742 (define_split
2743   [(set (match_operand:DF 0 "nonimmediate_operand" "")
2744         (match_operand:DF 1 "general_operand" ""))]
2745   "reload_completed
2746    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
2747    && ! (ANY_FP_REG_P (operands[0]) || 
2748          (GET_CODE (operands[0]) == SUBREG
2749           && ANY_FP_REG_P (SUBREG_REG (operands[0]))))
2750    && ! (ANY_FP_REG_P (operands[1]) || 
2751          (GET_CODE (operands[1]) == SUBREG
2752           && ANY_FP_REG_P (SUBREG_REG (operands[1]))))"
2753   [(const_int 0)]
2754   "ix86_split_long_move (operands); DONE;")
2755
2756 (define_insn "*swapdf"
2757   [(set (match_operand:DF 0 "register_operand" "+f")
2758         (match_operand:DF 1 "register_operand" "+f"))
2759    (set (match_dup 1)
2760         (match_dup 0))]
2761   "reload_completed || !TARGET_SSE2"
2762 {
2763   if (STACK_TOP_P (operands[0]))
2764     return "fxch\t%1";
2765   else
2766     return "fxch\t%0";
2767 }
2768   [(set_attr "type" "fxch")
2769    (set_attr "mode" "DF")])
2770
2771 (define_expand "movxf"
2772   [(set (match_operand:XF 0 "nonimmediate_operand" "")
2773         (match_operand:XF 1 "general_operand" ""))]
2774   "!TARGET_64BIT"
2775   "ix86_expand_move (XFmode, operands); DONE;")
2776
2777 (define_expand "movtf"
2778   [(set (match_operand:TF 0 "nonimmediate_operand" "")
2779         (match_operand:TF 1 "general_operand" ""))]
2780   ""
2781   "ix86_expand_move (TFmode, operands); DONE;")
2782
2783 ;; Size of pushdf is 3 (for sub) + 2 (for fstp) + memory operand size.
2784 ;; Size of pushdf using integer instructions is 3+3*memory operand size
2785 ;; Pushing using integer instructions is longer except for constants
2786 ;; and direct memory references.
2787 ;; (assuming that any given constant is pushed only once, but this ought to be
2788 ;;  handled elsewhere).
2789
2790 (define_insn "*pushxf_nointeger"
2791   [(set (match_operand:XF 0 "push_operand" "=X,X,X")
2792         (match_operand:XF 1 "general_no_elim_operand" "f,Fo,*r"))]
2793   "!TARGET_64BIT && optimize_size"
2794 {
2795   /* This insn should be already splitted before reg-stack.  */
2796   abort ();
2797 }
2798   [(set_attr "type" "multi")
2799    (set_attr "mode" "XF,SI,SI")])
2800
2801 (define_insn "*pushtf_nointeger"
2802   [(set (match_operand:TF 0 "push_operand" "=<,<,<")
2803         (match_operand:TF 1 "general_no_elim_operand" "f,Fo,*r"))]
2804   "optimize_size"
2805 {
2806   /* This insn should be already splitted before reg-stack.  */
2807   abort ();
2808 }
2809   [(set_attr "type" "multi")
2810    (set_attr "mode" "XF,SI,SI")])
2811
2812 (define_insn "*pushxf_integer"
2813   [(set (match_operand:XF 0 "push_operand" "=<,<")
2814         (match_operand:XF 1 "general_no_elim_operand" "f#r,ro#f"))]
2815   "!TARGET_64BIT && !optimize_size"
2816 {
2817   /* This insn should be already splitted before reg-stack.  */
2818   abort ();
2819 }
2820   [(set_attr "type" "multi")
2821    (set_attr "mode" "XF,SI")])
2822
2823 (define_insn "*pushtf_integer"
2824   [(set (match_operand:TF 0 "push_operand" "=<,<")
2825         (match_operand:TF 1 "general_no_elim_operand" "f#r,rFo#f"))]
2826   "!optimize_size"
2827 {
2828   /* This insn should be already splitted before reg-stack.  */
2829   abort ();
2830 }
2831   [(set_attr "type" "multi")
2832    (set_attr "mode" "XF,SI")])
2833
2834 (define_split
2835   [(set (match_operand 0 "push_operand" "")
2836         (match_operand 1 "general_operand" ""))]
2837   "reload_completed
2838    && (GET_MODE (operands[0]) == XFmode
2839        || GET_MODE (operands[0]) == TFmode
2840        || GET_MODE (operands[0]) == DFmode)
2841    && !ANY_FP_REG_P (operands[1])"
2842   [(const_int 0)]
2843   "ix86_split_long_move (operands); DONE;")
2844
2845 (define_split
2846   [(set (match_operand:XF 0 "push_operand" "")
2847         (match_operand:XF 1 "any_fp_register_operand" ""))]
2848   "!TARGET_64BIT"
2849   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -12)))
2850    (set (mem:XF (reg:SI 7)) (match_dup 1))])
2851
2852 (define_split
2853   [(set (match_operand:TF 0 "push_operand" "")
2854         (match_operand:TF 1 "any_fp_register_operand" ""))]
2855   "!TARGET_64BIT"
2856   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -16)))
2857    (set (mem:TF (reg:SI 7)) (match_dup 1))])
2858
2859 (define_split
2860   [(set (match_operand:TF 0 "push_operand" "")
2861         (match_operand:TF 1 "any_fp_register_operand" ""))]
2862   "TARGET_64BIT"
2863   [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -16)))
2864    (set (mem:TF (reg:DI 7)) (match_dup 1))])
2865
2866 ;; Do not use integer registers when optimizing for size
2867 (define_insn "*movxf_nointeger"
2868   [(set (match_operand:XF 0 "nonimmediate_operand" "=f,m,f,*r,o")
2869         (match_operand:XF 1 "general_operand" "fm,f,G,*roF,F*r"))]
2870   "!TARGET_64BIT
2871    && optimize_size
2872    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
2873    && (reload_in_progress || reload_completed
2874        || GET_CODE (operands[1]) != CONST_DOUBLE
2875        || memory_operand (operands[0], XFmode))" 
2876 {
2877   switch (which_alternative)
2878     {
2879     case 0:
2880       if (REG_P (operands[1])
2881           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2882         {
2883           if (REGNO (operands[0]) == FIRST_STACK_REG
2884               && TARGET_USE_FFREEP)
2885             return "ffreep\t%y0";
2886           return "fstp\t%y0";
2887         }
2888       else if (STACK_TOP_P (operands[0]))
2889         return "fld%z1\t%y1";
2890       else
2891         return "fst\t%y0";
2892
2893     case 1:
2894       /* There is no non-popping store to memory for XFmode.  So if
2895          we need one, follow the store with a load.  */
2896       if (! find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2897         return "fstp%z0\t%y0\;fld%z0\t%y0";
2898       else
2899         return "fstp%z0\t%y0";
2900
2901     case 2:
2902       switch (standard_80387_constant_p (operands[1]))
2903         {
2904         case 1:
2905           return "fldz";
2906         case 2:
2907           return "fld1";
2908         }
2909       break;
2910
2911     case 3: case 4:
2912       return "#";
2913     }
2914   abort();
2915 }
2916   [(set_attr "type" "fmov,fmov,fmov,multi,multi")
2917    (set_attr "mode" "XF,XF,XF,SI,SI")])
2918
2919 (define_insn "*movtf_nointeger"
2920   [(set (match_operand:TF 0 "nonimmediate_operand" "=f,m,f,*r,o")
2921         (match_operand:TF 1 "general_operand" "fm,f,G,*roF,F*r"))]
2922   "(GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
2923    && optimize_size
2924    && (reload_in_progress || reload_completed
2925        || GET_CODE (operands[1]) != CONST_DOUBLE
2926        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
2927        || memory_operand (operands[0], TFmode))" 
2928 {
2929   switch (which_alternative)
2930     {
2931     case 0:
2932       if (REG_P (operands[1])
2933           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2934         {
2935           if (REGNO (operands[0]) == FIRST_STACK_REG
2936               && TARGET_USE_FFREEP)
2937             return "ffreep\t%y0";
2938           return "fstp\t%y0";
2939         }
2940       else if (STACK_TOP_P (operands[0]))
2941         return "fld%z1\t%y1";
2942       else
2943         return "fst\t%y0";
2944
2945     case 1:
2946       /* There is no non-popping store to memory for XFmode.  So if
2947          we need one, follow the store with a load.  */
2948       if (! find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2949         return "fstp%z0\t%y0\;fld%z0\t%y0";
2950       else
2951         return "fstp%z0\t%y0";
2952
2953     case 2:
2954       switch (standard_80387_constant_p (operands[1]))
2955         {
2956         case 1:
2957           return "fldz";
2958         case 2:
2959           return "fld1";
2960         }
2961       break;
2962
2963     case 3: case 4:
2964       return "#";
2965     }
2966   abort();
2967 }
2968   [(set_attr "type" "fmov,fmov,fmov,multi,multi")
2969    (set_attr "mode" "XF,XF,XF,SI,SI")])
2970
2971 (define_insn "*movxf_integer"
2972   [(set (match_operand:XF 0 "nonimmediate_operand" "=f#r,m,f#r,r#f,o")
2973         (match_operand:XF 1 "general_operand" "fm#r,f#r,G,roF#f,Fr#f"))]
2974   "!TARGET_64BIT
2975    && !optimize_size
2976    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
2977    && (reload_in_progress || reload_completed
2978        || GET_CODE (operands[1]) != CONST_DOUBLE
2979        || memory_operand (operands[0], XFmode))" 
2980 {
2981   switch (which_alternative)
2982     {
2983     case 0:
2984       if (REG_P (operands[1])
2985           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2986         {
2987           if (REGNO (operands[0]) == FIRST_STACK_REG
2988               && TARGET_USE_FFREEP)
2989             return "ffreep\t%y0";
2990           return "fstp\t%y0";
2991         }
2992       else if (STACK_TOP_P (operands[0]))
2993         return "fld%z1\t%y1";
2994       else
2995         return "fst\t%y0";
2996
2997     case 1:
2998       /* There is no non-popping store to memory for XFmode.  So if
2999          we need one, follow the store with a load.  */
3000       if (! find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3001         return "fstp%z0\t%y0\;fld%z0\t%y0";
3002       else
3003         return "fstp%z0\t%y0";
3004
3005     case 2:
3006       switch (standard_80387_constant_p (operands[1]))
3007         {
3008         case 1:
3009           return "fldz";
3010         case 2:
3011           return "fld1";
3012         }
3013       break;
3014
3015     case 3: case 4:
3016       return "#";
3017     }
3018   abort();
3019 }
3020   [(set_attr "type" "fmov,fmov,fmov,multi,multi")
3021    (set_attr "mode" "XF,XF,XF,SI,SI")])
3022
3023 (define_insn "*movtf_integer"
3024   [(set (match_operand:TF 0 "nonimmediate_operand" "=f#r,m,f#r,r#f,o")
3025         (match_operand:TF 1 "general_operand" "fm#r,f#r,G,roF#f,Fr#f"))]
3026   "(GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
3027    && !optimize_size
3028    && (reload_in_progress || reload_completed
3029        || GET_CODE (operands[1]) != CONST_DOUBLE
3030        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
3031        || memory_operand (operands[0], TFmode))" 
3032 {
3033   switch (which_alternative)
3034     {
3035     case 0:
3036       if (REG_P (operands[1])
3037           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3038         {
3039           if (REGNO (operands[0]) == FIRST_STACK_REG
3040               && TARGET_USE_FFREEP)
3041             return "ffreep\t%y0";
3042           return "fstp\t%y0";
3043         }
3044       else if (STACK_TOP_P (operands[0]))
3045         return "fld%z1\t%y1";
3046       else
3047         return "fst\t%y0";
3048
3049     case 1:
3050       /* There is no non-popping store to memory for XFmode.  So if
3051          we need one, follow the store with a load.  */
3052       if (! find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3053         return "fstp%z0\t%y0\;fld%z0\t%y0";
3054       else
3055         return "fstp%z0\t%y0";
3056
3057     case 2:
3058       switch (standard_80387_constant_p (operands[1]))
3059         {
3060         case 1:
3061           return "fldz";
3062         case 2:
3063           return "fld1";
3064         }
3065       break;
3066
3067     case 3: case 4:
3068       return "#";
3069     }
3070   abort();
3071 }
3072   [(set_attr "type" "fmov,fmov,fmov,multi,multi")
3073    (set_attr "mode" "XF,XF,XF,SI,SI")])
3074
3075 (define_split
3076   [(set (match_operand 0 "nonimmediate_operand" "")
3077         (match_operand 1 "general_operand" ""))]
3078   "reload_completed
3079    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
3080    && (GET_MODE (operands[0]) == XFmode || GET_MODE (operands[0]) == TFmode)
3081    && ! (ANY_FP_REG_P (operands[0]) || 
3082          (GET_CODE (operands[0]) == SUBREG
3083           && ANY_FP_REG_P (SUBREG_REG (operands[0]))))
3084    && ! (ANY_FP_REG_P (operands[1]) || 
3085          (GET_CODE (operands[1]) == SUBREG
3086           && ANY_FP_REG_P (SUBREG_REG (operands[1]))))"
3087   [(const_int 0)]
3088   "ix86_split_long_move (operands); DONE;")
3089
3090 (define_split
3091   [(set (match_operand 0 "register_operand" "")
3092         (match_operand 1 "memory_operand" ""))]
3093   "reload_completed
3094    && GET_CODE (operands[1]) == MEM
3095    && (GET_MODE (operands[0]) == XFmode || GET_MODE (operands[0]) == TFmode
3096        || GET_MODE (operands[0]) == SFmode || GET_MODE (operands[0]) == DFmode)
3097    && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
3098    && CONSTANT_POOL_ADDRESS_P (XEXP (operands[1], 0))
3099    && (!(SSE_REG_P (operands[0]) || 
3100          (GET_CODE (operands[0]) == SUBREG
3101           && SSE_REG_P (SUBREG_REG (operands[0]))))
3102        || standard_sse_constant_p (get_pool_constant (XEXP (operands[1], 0))))
3103    && (!(FP_REG_P (operands[0]) || 
3104          (GET_CODE (operands[0]) == SUBREG
3105           && FP_REG_P (SUBREG_REG (operands[0]))))
3106        || standard_80387_constant_p (get_pool_constant (XEXP (operands[1], 0))))"
3107   [(set (match_dup 0)
3108         (match_dup 1))]
3109   "operands[1] = get_pool_constant (XEXP (operands[1], 0));")
3110
3111 (define_insn "swapxf"
3112   [(set (match_operand:XF 0 "register_operand" "+f")
3113         (match_operand:XF 1 "register_operand" "+f"))
3114    (set (match_dup 1)
3115         (match_dup 0))]
3116   ""
3117 {
3118   if (STACK_TOP_P (operands[0]))
3119     return "fxch\t%1";
3120   else
3121     return "fxch\t%0";
3122 }
3123   [(set_attr "type" "fxch")
3124    (set_attr "mode" "XF")])
3125
3126 (define_insn "swaptf"
3127   [(set (match_operand:TF 0 "register_operand" "+f")
3128         (match_operand:TF 1 "register_operand" "+f"))
3129    (set (match_dup 1)
3130         (match_dup 0))]
3131   ""
3132 {
3133   if (STACK_TOP_P (operands[0]))
3134     return "fxch\t%1";
3135   else
3136     return "fxch\t%0";
3137 }
3138   [(set_attr "type" "fxch")
3139    (set_attr "mode" "XF")])
3140 \f
3141 ;; Zero extension instructions
3142
3143 (define_expand "zero_extendhisi2"
3144   [(set (match_operand:SI 0 "register_operand" "")
3145      (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "")))]
3146   ""
3147 {
3148   if (TARGET_ZERO_EXTEND_WITH_AND && !optimize_size)
3149     {
3150       operands[1] = force_reg (HImode, operands[1]);
3151       emit_insn (gen_zero_extendhisi2_and (operands[0], operands[1]));
3152       DONE;
3153     }
3154 })
3155
3156 (define_insn "zero_extendhisi2_and"
3157   [(set (match_operand:SI 0 "register_operand" "=r")
3158      (zero_extend:SI (match_operand:HI 1 "register_operand" "0")))
3159    (clobber (reg:CC 17))]
3160   "TARGET_ZERO_EXTEND_WITH_AND && !optimize_size"
3161   "#"
3162   [(set_attr "type" "alu1")
3163    (set_attr "mode" "SI")])
3164
3165 (define_split
3166   [(set (match_operand:SI 0 "register_operand" "")
3167         (zero_extend:SI (match_operand:HI 1 "register_operand" "")))
3168    (clobber (reg:CC 17))]
3169   "reload_completed && TARGET_ZERO_EXTEND_WITH_AND && !optimize_size"
3170   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (const_int 65535)))
3171               (clobber (reg:CC 17))])]
3172   "")
3173
3174 (define_insn "*zero_extendhisi2_movzwl"
3175   [(set (match_operand:SI 0 "register_operand" "=r")
3176      (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "rm")))]
3177   "!TARGET_ZERO_EXTEND_WITH_AND || optimize_size"
3178   "movz{wl|x}\t{%1, %0|%0, %1}"
3179   [(set_attr "type" "imovx")
3180    (set_attr "mode" "SI")])
3181
3182 (define_expand "zero_extendqihi2"
3183   [(parallel
3184     [(set (match_operand:HI 0 "register_operand" "")
3185        (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))
3186      (clobber (reg:CC 17))])]
3187   ""
3188   "")
3189
3190 (define_insn "*zero_extendqihi2_and"
3191   [(set (match_operand:HI 0 "register_operand" "=r,?&q")
3192      (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,qm")))
3193    (clobber (reg:CC 17))]
3194   "TARGET_ZERO_EXTEND_WITH_AND && !optimize_size"
3195   "#"
3196   [(set_attr "type" "alu1")
3197    (set_attr "mode" "HI")])
3198
3199 (define_insn "*zero_extendqihi2_movzbw_and"
3200   [(set (match_operand:HI 0 "register_operand" "=r,r")
3201      (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "qm,0")))
3202    (clobber (reg:CC 17))]
3203   "!TARGET_ZERO_EXTEND_WITH_AND || optimize_size"
3204   "#"
3205   [(set_attr "type" "imovx,alu1")
3206    (set_attr "mode" "HI")])
3207
3208 (define_insn "*zero_extendqihi2_movzbw"
3209   [(set (match_operand:HI 0 "register_operand" "=r")
3210      (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
3211   "(!TARGET_ZERO_EXTEND_WITH_AND || optimize_size) && reload_completed"
3212   "movz{bw|x}\t{%1, %0|%0, %1}"
3213   [(set_attr "type" "imovx")
3214    (set_attr "mode" "HI")])
3215
3216 ;; For the movzbw case strip only the clobber
3217 (define_split
3218   [(set (match_operand:HI 0 "register_operand" "")
3219         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))
3220    (clobber (reg:CC 17))]
3221   "reload_completed 
3222    && (!TARGET_ZERO_EXTEND_WITH_AND || optimize_size)
3223    && (!REG_P (operands[1]) || ANY_QI_REG_P (operands[1]))"
3224   [(set (match_operand:HI 0 "register_operand" "")
3225         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))])
3226
3227 ;; When source and destination does not overlap, clear destination
3228 ;; first and then do the movb
3229 (define_split
3230   [(set (match_operand:HI 0 "register_operand" "")
3231         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))
3232    (clobber (reg:CC 17))]
3233   "reload_completed
3234    && ANY_QI_REG_P (operands[0])
3235    && (TARGET_ZERO_EXTEND_WITH_AND && !optimize_size)
3236    && !reg_overlap_mentioned_p (operands[0], operands[1])"
3237   [(set (match_dup 0) (const_int 0))
3238    (set (strict_low_part (match_dup 2)) (match_dup 1))]
3239   "operands[2] = gen_lowpart (QImode, operands[0]);")
3240
3241 ;; Rest is handled by single and.
3242 (define_split
3243   [(set (match_operand:HI 0 "register_operand" "")
3244         (zero_extend:HI (match_operand:QI 1 "register_operand" "")))
3245    (clobber (reg:CC 17))]
3246   "reload_completed
3247    && true_regnum (operands[0]) == true_regnum (operands[1])"
3248   [(parallel [(set (match_dup 0) (and:HI (match_dup 0) (const_int 255)))
3249               (clobber (reg:CC 17))])]
3250   "")
3251
3252 (define_expand "zero_extendqisi2"
3253   [(parallel
3254     [(set (match_operand:SI 0 "register_operand" "")
3255        (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "")))
3256      (clobber (reg:CC 17))])]
3257   ""
3258   "")
3259
3260 (define_insn "*zero_extendqisi2_and"
3261   [(set (match_operand:SI 0 "register_operand" "=r,?&q")
3262      (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "0,qm")))
3263    (clobber (reg:CC 17))]
3264   "TARGET_ZERO_EXTEND_WITH_AND && !optimize_size"
3265   "#"
3266   [(set_attr "type" "alu1")
3267    (set_attr "mode" "SI")])
3268
3269 (define_insn "*zero_extendqisi2_movzbw_and"
3270   [(set (match_operand:SI 0 "register_operand" "=r,r")
3271      (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm,0")))
3272    (clobber (reg:CC 17))]
3273   "!TARGET_ZERO_EXTEND_WITH_AND || optimize_size"
3274   "#"
3275   [(set_attr "type" "imovx,alu1")
3276    (set_attr "mode" "SI")])
3277
3278 (define_insn "*zero_extendqisi2_movzbw"
3279   [(set (match_operand:SI 0 "register_operand" "=r")
3280      (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
3281   "(!TARGET_ZERO_EXTEND_WITH_AND || optimize_size) && reload_completed"
3282   "movz{bl|x}\t{%1, %0|%0, %1}"
3283   [(set_attr "type" "imovx")
3284    (set_attr "mode" "SI")])
3285
3286 ;; For the movzbl case strip only the clobber
3287 (define_split
3288   [(set (match_operand:SI 0 "register_operand" "")
3289         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "")))
3290    (clobber (reg:CC 17))]
3291   "reload_completed 
3292    && (!TARGET_ZERO_EXTEND_WITH_AND || optimize_size)
3293    && (!REG_P (operands[1]) || ANY_QI_REG_P (operands[1]))"
3294   [(set (match_dup 0)
3295         (zero_extend:SI (match_dup 1)))])
3296
3297 ;; When source and destination does not overlap, clear destination
3298 ;; first and then do the movb
3299 (define_split
3300   [(set (match_operand:SI 0 "register_operand" "")
3301         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "")))
3302    (clobber (reg:CC 17))]
3303   "reload_completed
3304    && ANY_QI_REG_P (operands[0])
3305    && (ANY_QI_REG_P (operands[1]) || GET_CODE (operands[1]) == MEM)
3306    && (TARGET_ZERO_EXTEND_WITH_AND && !optimize_size)
3307    && !reg_overlap_mentioned_p (operands[0], operands[1])"
3308   [(set (match_dup 0) (const_int 0))
3309    (set (strict_low_part (match_dup 2)) (match_dup 1))]
3310   "operands[2] = gen_lowpart (QImode, operands[0]);")
3311
3312 ;; Rest is handled by single and.
3313 (define_split
3314   [(set (match_operand:SI 0 "register_operand" "")
3315         (zero_extend:SI (match_operand:QI 1 "register_operand" "")))
3316    (clobber (reg:CC 17))]
3317   "reload_completed
3318    && true_regnum (operands[0]) == true_regnum (operands[1])"
3319   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (const_int 255)))
3320               (clobber (reg:CC 17))])]
3321   "")
3322
3323 ;; %%% Kill me once multi-word ops are sane.
3324 (define_expand "zero_extendsidi2"
3325   [(set (match_operand:DI 0 "register_operand" "=r")
3326      (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "rm")))]
3327   ""
3328   "if (!TARGET_64BIT)
3329      {
3330        emit_insn (gen_zero_extendsidi2_32 (operands[0], operands[1]));
3331        DONE;
3332      }
3333   ")
3334
3335 (define_insn "zero_extendsidi2_32"
3336   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,?r,?*o")
3337         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,rm,r")))
3338    (clobber (reg:CC 17))]
3339   "!TARGET_64BIT"
3340   "#"
3341   [(set_attr "mode" "SI")])
3342
3343 (define_insn "zero_extendsidi2_rex64"
3344   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,o")
3345      (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "rm,0")))]
3346   "TARGET_64BIT"
3347   "@
3348    mov\t{%k1, %k0|%k0, %k1}
3349    #"
3350   [(set_attr "type" "imovx,imov")
3351    (set_attr "mode" "SI,DI")])
3352
3353 (define_split
3354   [(set (match_operand:DI 0 "memory_operand" "")
3355      (zero_extend:DI (match_dup 0)))]
3356   "TARGET_64BIT"
3357   [(set (match_dup 4) (const_int 0))]
3358   "split_di (&operands[0], 1, &operands[3], &operands[4]);")
3359
3360 (define_split 
3361   [(set (match_operand:DI 0 "register_operand" "")
3362         (zero_extend:DI (match_operand:SI 1 "register_operand" "")))
3363    (clobber (reg:CC 17))]
3364   "!TARGET_64BIT && reload_completed
3365    && true_regnum (operands[0]) == true_regnum (operands[1])"
3366   [(set (match_dup 4) (const_int 0))]
3367   "split_di (&operands[0], 1, &operands[3], &operands[4]);")
3368
3369 (define_split 
3370   [(set (match_operand:DI 0 "nonimmediate_operand" "")
3371         (zero_extend:DI (match_operand:SI 1 "general_operand" "")))
3372    (clobber (reg:CC 17))]
3373   "!TARGET_64BIT && reload_completed"
3374   [(set (match_dup 3) (match_dup 1))
3375    (set (match_dup 4) (const_int 0))]
3376   "split_di (&operands[0], 1, &operands[3], &operands[4]);")
3377
3378 (define_insn "zero_extendhidi2"
3379   [(set (match_operand:DI 0 "register_operand" "=r,r")
3380      (zero_extend:DI (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
3381   "TARGET_64BIT"
3382   "@
3383    movz{wl|x}\t{%1, %k0|%k0, %1} 
3384    movz{wq|x}\t{%1, %0|%0, %1}"
3385   [(set_attr "type" "imovx")
3386    (set_attr "mode" "SI,DI")])
3387
3388 (define_insn "zero_extendqidi2"
3389   [(set (match_operand:DI 0 "register_operand" "=r,r")
3390      (zero_extend:DI (match_operand:QI 1 "nonimmediate_operand" "Q,m")))]
3391   "TARGET_64BIT"
3392   "@
3393    movz{bl|x}\t{%1, %k0|%k0, %1} 
3394    movz{bq|x}\t{%1, %0|%0, %1}"
3395   [(set_attr "type" "imovx")
3396    (set_attr "mode" "SI,DI")])
3397 \f
3398 ;; Sign extension instructions
3399
3400 (define_expand "extendsidi2"
3401   [(parallel [(set (match_operand:DI 0 "register_operand" "")
3402                    (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
3403               (clobber (reg:CC 17))
3404               (clobber (match_scratch:SI 2 ""))])]
3405   ""
3406 {
3407   if (TARGET_64BIT)
3408     {
3409       emit_insn (gen_extendsidi2_rex64 (operands[0], operands[1]));
3410       DONE;
3411     }
3412 })
3413
3414 (define_insn "*extendsidi2_1"
3415   [(set (match_operand:DI 0 "nonimmediate_operand" "=*A,r,?r,?*o")
3416         (sign_extend:DI (match_operand:SI 1 "register_operand" "0,0,r,r")))
3417    (clobber (reg:CC 17))
3418    (clobber (match_scratch:SI 2 "=X,X,X,&r"))]
3419   "!TARGET_64BIT"
3420   "#")
3421
3422 (define_insn "extendsidi2_rex64"
3423   [(set (match_operand:DI 0 "register_operand" "=*a,r")
3424         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "*0,rm")))]
3425   "TARGET_64BIT"
3426   "@
3427    {cltq|cdqe}
3428    movs{lq|x}\t{%1,%0|%0, %1}"
3429   [(set_attr "type" "imovx")
3430    (set_attr "mode" "DI")
3431    (set_attr "prefix_0f" "0")
3432    (set_attr "modrm" "0,1")])
3433
3434 (define_insn "extendhidi2"
3435   [(set (match_operand:DI 0 "register_operand" "=r")
3436         (sign_extend:DI (match_operand:HI 1 "nonimmediate_operand" "rm")))]
3437   "TARGET_64BIT"
3438   "movs{wq|x}\t{%1,%0|%0, %1}"
3439   [(set_attr "type" "imovx")
3440    (set_attr "mode" "DI")])
3441
3442 (define_insn "extendqidi2"
3443   [(set (match_operand:DI 0 "register_operand" "=r")
3444         (sign_extend:DI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
3445   "TARGET_64BIT"
3446   "movs{bq|x}\t{%1,%0|%0, %1}"
3447    [(set_attr "type" "imovx")
3448     (set_attr "mode" "DI")])
3449
3450 ;; Extend to memory case when source register does die.
3451 (define_split 
3452   [(set (match_operand:DI 0 "memory_operand" "")
3453         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
3454    (clobber (reg:CC 17))
3455    (clobber (match_operand:SI 2 "register_operand" ""))]
3456   "(reload_completed
3457     && dead_or_set_p (insn, operands[1])
3458     && !reg_mentioned_p (operands[1], operands[0]))"
3459   [(set (match_dup 3) (match_dup 1))
3460    (parallel [(set (match_dup 1) (ashiftrt:SI (match_dup 1) (const_int 31)))
3461               (clobber (reg:CC 17))])
3462    (set (match_dup 4) (match_dup 1))]
3463   "split_di (&operands[0], 1, &operands[3], &operands[4]);")
3464
3465 ;; Extend to memory case when source register does not die.
3466 (define_split 
3467   [(set (match_operand:DI 0 "memory_operand" "")
3468         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
3469    (clobber (reg:CC 17))
3470    (clobber (match_operand:SI 2 "register_operand" ""))]
3471   "reload_completed"
3472   [(const_int 0)]
3473 {
3474   split_di (&operands[0], 1, &operands[3], &operands[4]);
3475
3476   emit_move_insn (operands[3], operands[1]);
3477
3478   /* Generate a cltd if possible and doing so it profitable.  */
3479   if (true_regnum (operands[1]) == 0
3480       && true_regnum (operands[2]) == 1
3481       && (optimize_size || TARGET_USE_CLTD))
3482     {
3483       emit_insn (gen_ashrsi3_31 (operands[2], operands[1], GEN_INT (31)));
3484     }
3485   else
3486     {
3487       emit_move_insn (operands[2], operands[1]);
3488       emit_insn (gen_ashrsi3_31 (operands[2], operands[2], GEN_INT (31)));
3489     }
3490   emit_move_insn (operands[4], operands[2]);
3491   DONE;
3492 })
3493
3494 ;; Extend to register case.  Optimize case where source and destination
3495 ;; registers match and cases where we can use cltd.
3496 (define_split 
3497   [(set (match_operand:DI 0 "register_operand" "")
3498         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
3499    (clobber (reg:CC 17))
3500    (clobber (match_scratch:SI 2 ""))]
3501   "reload_completed"
3502   [(const_int 0)]
3503 {
3504   split_di (&operands[0], 1, &operands[3], &operands[4]);
3505
3506   if (true_regnum (operands[3]) != true_regnum (operands[1]))
3507     emit_move_insn (operands[3], operands[1]);
3508
3509   /* Generate a cltd if possible and doing so it profitable.  */
3510   if (true_regnum (operands[3]) == 0
3511       && (optimize_size || TARGET_USE_CLTD))
3512     {
3513       emit_insn (gen_ashrsi3_31 (operands[4], operands[3], GEN_INT (31)));
3514       DONE;
3515     }
3516
3517   if (true_regnum (operands[4]) != true_regnum (operands[1]))
3518     emit_move_insn (operands[4], operands[1]);
3519
3520   emit_insn (gen_ashrsi3_31 (operands[4], operands[4], GEN_INT (31)));
3521   DONE;
3522 })
3523
3524 (define_insn "extendhisi2"
3525   [(set (match_operand:SI 0 "register_operand" "=*a,r")
3526         (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "*0,rm")))]
3527   ""
3528 {
3529   switch (get_attr_prefix_0f (insn))
3530     {
3531     case 0:
3532       return "{cwtl|cwde}";
3533     default:
3534       return "movs{wl|x}\t{%1,%0|%0, %1}";
3535     }
3536 }
3537   [(set_attr "type" "imovx")
3538    (set_attr "mode" "SI")
3539    (set (attr "prefix_0f")
3540      ;; movsx is short decodable while cwtl is vector decoded.
3541      (if_then_else (and (eq_attr "cpu" "!k6")
3542                         (eq_attr "alternative" "0"))
3543         (const_string "0")
3544         (const_string "1")))
3545    (set (attr "modrm")
3546      (if_then_else (eq_attr "prefix_0f" "0")
3547         (const_string "0")
3548         (const_string "1")))])
3549
3550 (define_insn "*extendhisi2_zext"
3551   [(set (match_operand:DI 0 "register_operand" "=*a,r")
3552         (zero_extend:DI
3553           (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "*0,rm"))))]
3554   "TARGET_64BIT"
3555 {
3556   switch (get_attr_prefix_0f (insn))
3557     {
3558     case 0:
3559       return "{cwtl|cwde}";
3560     default:
3561       return "movs{wl|x}\t{%1,%k0|%k0, %1}";
3562     }
3563 }
3564   [(set_attr "type" "imovx")
3565    (set_attr "mode" "SI")
3566    (set (attr "prefix_0f")
3567      ;; movsx is short decodable while cwtl is vector decoded.
3568      (if_then_else (and (eq_attr "cpu" "!k6")
3569                         (eq_attr "alternative" "0"))
3570         (const_string "0")
3571         (const_string "1")))
3572    (set (attr "modrm")
3573      (if_then_else (eq_attr "prefix_0f" "0")
3574         (const_string "0")
3575         (const_string "1")))])
3576
3577 (define_insn "extendqihi2"
3578   [(set (match_operand:HI 0 "register_operand" "=*a,r")
3579         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "*0,qm")))]
3580   ""
3581 {
3582   switch (get_attr_prefix_0f (insn))
3583     {
3584     case 0:
3585       return "{cbtw|cbw}";
3586     default:
3587       return "movs{bw|x}\t{%1,%0|%0, %1}";
3588     }
3589 }
3590   [(set_attr "type" "imovx")
3591    (set_attr "mode" "HI")
3592    (set (attr "prefix_0f")
3593      ;; movsx is short decodable while cwtl is vector decoded.
3594      (if_then_else (and (eq_attr "cpu" "!k6")
3595                         (eq_attr "alternative" "0"))
3596         (const_string "0")
3597         (const_string "1")))
3598    (set (attr "modrm")
3599      (if_then_else (eq_attr "prefix_0f" "0")
3600         (const_string "0")
3601         (const_string "1")))])
3602
3603 (define_insn "extendqisi2"
3604   [(set (match_operand:SI 0 "register_operand" "=r")
3605         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
3606   ""
3607   "movs{bl|x}\t{%1,%0|%0, %1}"
3608    [(set_attr "type" "imovx")
3609     (set_attr "mode" "SI")])
3610
3611 (define_insn "*extendqisi2_zext"
3612   [(set (match_operand:DI 0 "register_operand" "=r")
3613         (zero_extend:DI
3614           (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm"))))]
3615   "TARGET_64BIT"
3616   "movs{bl|x}\t{%1,%k0|%k0, %1}"
3617    [(set_attr "type" "imovx")
3618     (set_attr "mode" "SI")])
3619 \f
3620 ;; Conversions between float and double.
3621
3622 ;; These are all no-ops in the model used for the 80387.  So just
3623 ;; emit moves.
3624
3625 ;; %%% Kill these when call knows how to work out a DFmode push earlier. 
3626 (define_insn "*dummy_extendsfdf2"
3627   [(set (match_operand:DF 0 "push_operand" "=<")
3628         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "fY")))]
3629   "0"
3630   "#")
3631
3632 (define_split
3633   [(set (match_operand:DF 0 "push_operand" "")
3634         (float_extend:DF (match_operand:SF 1 "fp_register_operand" "")))]
3635   "!TARGET_64BIT"
3636   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -8)))
3637    (set (mem:DF (reg:SI 7)) (float_extend:DF (match_dup 1)))])
3638
3639 (define_split
3640   [(set (match_operand:DF 0 "push_operand" "")
3641         (float_extend:DF (match_operand:SF 1 "fp_register_operand" "")))]
3642   "TARGET_64BIT"
3643   [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -8)))
3644    (set (mem:DF (reg:DI 7)) (float_extend:DF (match_dup 1)))])
3645
3646 (define_insn "*dummy_extendsfxf2"
3647   [(set (match_operand:XF 0 "push_operand" "=<")
3648         (float_extend:XF (match_operand:SF 1 "nonimmediate_operand" "f")))]
3649   "0"
3650   "#")
3651
3652 (define_split
3653   [(set (match_operand:XF 0 "push_operand" "")
3654         (float_extend:XF (match_operand:SF 1 "fp_register_operand" "")))]
3655   "!TARGET_64BIT"
3656   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -12)))
3657    (set (mem:XF (reg:SI 7)) (float_extend:XF (match_dup 1)))])
3658
3659 (define_insn "*dummy_extendsftf2"
3660   [(set (match_operand:TF 0 "push_operand" "=<")
3661         (float_extend:TF (match_operand:SF 1 "nonimmediate_operand" "f")))]
3662   "0"
3663   "#")
3664
3665 (define_split
3666   [(set (match_operand:TF 0 "push_operand" "")
3667         (float_extend:TF (match_operand:SF 1 "fp_register_operand" "")))]
3668   "!TARGET_64BIT"
3669   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -16)))
3670    (set (mem:TF (reg:SI 7)) (float_extend:TF (match_dup 1)))])
3671
3672 (define_split
3673   [(set (match_operand:TF 0 "push_operand" "")
3674         (float_extend:TF (match_operand:SF 1 "fp_register_operand" "")))]
3675   "TARGET_64BIT"
3676   [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -16)))
3677    (set (mem:DF (reg:DI 7)) (float_extend:TF (match_dup 1)))])
3678
3679 (define_insn "*dummy_extenddfxf2"
3680   [(set (match_operand:XF 0 "push_operand" "=<")
3681         (float_extend:XF (match_operand:DF 1 "nonimmediate_operand" "f")))]
3682   "0"
3683   "#")
3684
3685 (define_split
3686   [(set (match_operand:XF 0 "push_operand" "")
3687         (float_extend:XF (match_operand:DF 1 "fp_register_operand" "")))]
3688   "!TARGET_64BIT"
3689   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -12)))
3690    (set (mem:DF (reg:SI 7)) (float_extend:XF (match_dup 1)))])
3691
3692 (define_insn "*dummy_extenddftf2"
3693   [(set (match_operand:TF 0 "push_operand" "=<")
3694         (float_extend:TF (match_operand:DF 1 "nonimmediate_operand" "f")))]
3695   "0"
3696   "#")
3697
3698 (define_split
3699   [(set (match_operand:TF 0 "push_operand" "")
3700         (float_extend:TF (match_operand:DF 1 "fp_register_operand" "")))]
3701   "!TARGET_64BIT"
3702   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -16)))
3703    (set (mem:TF (reg:SI 7)) (float_extend:XF (match_dup 1)))])
3704
3705 (define_split
3706   [(set (match_operand:TF 0 "push_operand" "")
3707         (float_extend:TF (match_operand:DF 1 "fp_register_operand" "")))]
3708   "TARGET_64BIT"
3709   [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -16)))
3710    (set (mem:TF (reg:DI 7)) (float_extend:TF (match_dup 1)))])
3711
3712 (define_expand "extendsfdf2"
3713   [(set (match_operand:DF 0 "nonimmediate_operand" "")
3714         (float_extend:DF (match_operand:SF 1 "general_operand" "")))]
3715   "TARGET_80387 || TARGET_SSE2"
3716 {
3717   /* ??? Needed for compress_float_constant since all fp constants
3718      are LEGITIMATE_CONSTANT_P.  */
3719   if (GET_CODE (operands[1]) == CONST_DOUBLE)
3720     operands[1] = validize_mem (force_const_mem (SFmode, operands[1]));
3721   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
3722     operands[1] = force_reg (SFmode, operands[1]);
3723 })
3724
3725 (define_insn "*extendsfdf2_1"
3726   [(set (match_operand:DF 0 "nonimmediate_operand" "=f#Y,mf#Y,Y#f")
3727         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "fm#Y,f#Y,mY#f")))]
3728   "(TARGET_80387 || TARGET_SSE2)
3729    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
3730 {
3731   switch (which_alternative)
3732     {
3733     case 0:
3734       if (REG_P (operands[1])
3735           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3736         return "fstp\t%y0";
3737       else if (STACK_TOP_P (operands[0]))
3738         return "fld%z1\t%y1";
3739       else
3740         return "fst\t%y0";
3741
3742     case 1:
3743       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3744         return "fstp%z0\t%y0";
3745
3746       else
3747         return "fst%z0\t%y0";
3748     case 2:
3749       return "cvtss2sd\t{%1, %0|%0, %1}";
3750
3751     default:
3752       abort ();
3753     }
3754 }
3755   [(set_attr "type" "fmov,fmov,ssecvt")
3756    (set_attr "mode" "SF,XF,DF")])
3757
3758 (define_insn "*extendsfdf2_1_sse_only"
3759   [(set (match_operand:DF 0 "register_operand" "=Y")
3760         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "mY")))]
3761   "!TARGET_80387 && TARGET_SSE2
3762    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
3763   "cvtss2sd\t{%1, %0|%0, %1}"
3764   [(set_attr "type" "ssecvt")
3765    (set_attr "mode" "DF")])
3766
3767 (define_expand "extendsfxf2"
3768   [(set (match_operand:XF 0 "nonimmediate_operand" "")
3769         (float_extend:XF (match_operand:SF 1 "general_operand" "")))]
3770   "!TARGET_64BIT && TARGET_80387"
3771 {
3772   /* ??? Needed for compress_float_constant since all fp constants
3773      are LEGITIMATE_CONSTANT_P.  */
3774   if (GET_CODE (operands[1]) == CONST_DOUBLE)
3775     operands[1] = validize_mem (force_const_mem (SFmode, operands[1]));
3776   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
3777     operands[1] = force_reg (SFmode, operands[1]);
3778 })
3779
3780 (define_insn "*extendsfxf2_1"
3781   [(set (match_operand:XF 0 "nonimmediate_operand" "=f,m")
3782         (float_extend:XF (match_operand:SF 1 "nonimmediate_operand" "fm,f")))]
3783   "!TARGET_64BIT && TARGET_80387
3784    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
3785 {
3786   switch (which_alternative)
3787     {
3788     case 0:
3789       if (REG_P (operands[1])
3790           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3791         return "fstp\t%y0";
3792       else if (STACK_TOP_P (operands[0]))
3793         return "fld%z1\t%y1";
3794       else
3795         return "fst\t%y0";
3796
3797     case 1:
3798       /* There is no non-popping store to memory for XFmode.  So if
3799          we need one, follow the store with a load.  */
3800       if (! find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3801         return "fstp%z0\t%y0\n\tfld%z0\t%y0";
3802       else
3803         return "fstp%z0\t%y0";
3804
3805     default:
3806       abort ();
3807     }
3808 }
3809   [(set_attr "type" "fmov")
3810    (set_attr "mode" "SF,XF")])
3811
3812 (define_expand "extendsftf2"
3813   [(set (match_operand:TF 0 "nonimmediate_operand" "")
3814         (float_extend:TF (match_operand:SF 1 "general_operand" "")))]
3815   "TARGET_80387"
3816 {
3817   /* ??? Needed for compress_float_constant since all fp constants
3818      are LEGITIMATE_CONSTANT_P.  */
3819   if (GET_CODE (operands[1]) == CONST_DOUBLE)
3820     operands[1] = validize_mem (force_const_mem (SFmode, operands[1]));
3821   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
3822     operands[1] = force_reg (SFmode, operands[1]);
3823 })
3824
3825 (define_insn "*extendsftf2_1"
3826   [(set (match_operand:TF 0 "nonimmediate_operand" "=f,m")
3827         (float_extend:TF (match_operand:SF 1 "nonimmediate_operand" "fm,f")))]
3828   "TARGET_80387
3829    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
3830 {
3831   switch (which_alternative)
3832     {
3833     case 0:
3834       if (REG_P (operands[1])
3835           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3836         return "fstp\t%y0";
3837       else if (STACK_TOP_P (operands[0]))
3838         return "fld%z1\t%y1";
3839       else
3840         return "fst\t%y0";
3841
3842     case 1:
3843       /* There is no non-popping store to memory for XFmode.  So if
3844          we need one, follow the store with a load.  */
3845       if (! find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3846         return "fstp%z0\t%y0\n\tfld%z0\t%y0";
3847       else
3848         return "fstp%z0\t%y0";
3849
3850     default:
3851       abort ();
3852     }
3853 }
3854   [(set_attr "type" "fmov")
3855    (set_attr "mode" "SF,XF")])
3856
3857 (define_expand "extenddfxf2"
3858   [(set (match_operand:XF 0 "nonimmediate_operand" "")
3859         (float_extend:XF (match_operand:DF 1 "general_operand" "")))]
3860   "!TARGET_64BIT && TARGET_80387"
3861 {
3862   /* ??? Needed for compress_float_constant since all fp constants
3863      are LEGITIMATE_CONSTANT_P.  */
3864   if (GET_CODE (operands[1]) == CONST_DOUBLE)
3865     operands[1] = validize_mem (force_const_mem (DFmode, operands[1]));
3866   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
3867     operands[1] = force_reg (DFmode, operands[1]);
3868 })
3869
3870 (define_insn "*extenddfxf2_1"
3871   [(set (match_operand:XF 0 "nonimmediate_operand" "=f,m")
3872         (float_extend:XF (match_operand:DF 1 "nonimmediate_operand" "fm,f")))]
3873   "!TARGET_64BIT && TARGET_80387
3874    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
3875 {
3876   switch (which_alternative)
3877     {
3878     case 0:
3879       if (REG_P (operands[1])
3880           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3881         return "fstp\t%y0";
3882       else if (STACK_TOP_P (operands[0]))
3883         return "fld%z1\t%y1";
3884       else
3885         return "fst\t%y0";
3886
3887     case 1:
3888       /* There is no non-popping store to memory for XFmode.  So if
3889          we need one, follow the store with a load.  */
3890       if (! find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3891         return "fstp%z0\t%y0\n\tfld%z0\t%y0";
3892       else
3893         return "fstp%z0\t%y0";
3894
3895     default:
3896       abort ();
3897     }
3898 }
3899   [(set_attr "type" "fmov")
3900    (set_attr "mode" "DF,XF")])
3901
3902 (define_expand "extenddftf2"
3903   [(set (match_operand:TF 0 "nonimmediate_operand" "")
3904         (float_extend:TF (match_operand:DF 1 "general_operand" "")))]
3905   "TARGET_80387"
3906 {
3907   /* ??? Needed for compress_float_constant since all fp constants
3908      are LEGITIMATE_CONSTANT_P.  */
3909   if (GET_CODE (operands[1]) == CONST_DOUBLE)
3910     operands[1] = validize_mem (force_const_mem (DFmode, operands[1]));
3911   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
3912     operands[1] = force_reg (DFmode, operands[1]);
3913 })
3914
3915 (define_insn "*extenddftf2_1"
3916   [(set (match_operand:TF 0 "nonimmediate_operand" "=f,m")
3917         (float_extend:TF (match_operand:DF 1 "nonimmediate_operand" "fm,f")))]
3918   "TARGET_80387
3919    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
3920 {
3921   switch (which_alternative)
3922     {
3923     case 0:
3924       if (REG_P (operands[1])
3925           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3926         return "fstp\t%y0";
3927       else if (STACK_TOP_P (operands[0]))
3928         return "fld%z1\t%y1";
3929       else
3930         return "fst\t%y0";
3931
3932     case 1:
3933       /* There is no non-popping store to memory for XFmode.  So if
3934          we need one, follow the store with a load.  */
3935       if (! find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3936         return "fstp%z0\t%y0\n\tfld%z0\t%y0";
3937       else
3938         return "fstp%z0\t%y0";
3939
3940     default:
3941       abort ();
3942     }
3943 }
3944   [(set_attr "type" "fmov")
3945    (set_attr "mode" "DF,XF")])
3946
3947 ;; %%% This seems bad bad news.
3948 ;; This cannot output into an f-reg because there is no way to be sure
3949 ;; of truncating in that case.  Otherwise this is just like a simple move
3950 ;; insn.  So we pretend we can output to a reg in order to get better
3951 ;; register preferencing, but we really use a stack slot.
3952
3953 (define_expand "truncdfsf2"
3954   [(parallel [(set (match_operand:SF 0 "nonimmediate_operand" "")
3955                    (float_truncate:SF
3956                     (match_operand:DF 1 "register_operand" "")))
3957               (clobber (match_dup 2))])]
3958   "TARGET_80387 || TARGET_SSE2"
3959   "
3960    if (TARGET_80387)
3961      operands[2] = assign_386_stack_local (SFmode, 0);
3962    else
3963      {
3964         emit_insn (gen_truncdfsf2_sse_only (operands[0], operands[1]));
3965         DONE;
3966      }
3967 ")
3968
3969 (define_insn "*truncdfsf2_1"
3970   [(set (match_operand:SF 0 "nonimmediate_operand" "=m,?f#rx,?r#fx,?x#rf")
3971         (float_truncate:SF
3972          (match_operand:DF 1 "register_operand" "f,f,f,f")))
3973    (clobber (match_operand:SF 2 "memory_operand" "=X,m,m,m"))]
3974   "TARGET_80387 && !TARGET_SSE2"
3975 {
3976   switch (which_alternative)
3977     {
3978     case 0:
3979       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3980         return "fstp%z0\t%y0";
3981       else
3982         return "fst%z0\t%y0";
3983     default:
3984       abort ();
3985     }
3986 }
3987   [(set_attr "type" "fmov,multi,multi,multi")
3988    (set_attr "mode" "SF,SF,SF,SF")])
3989
3990 (define_insn "*truncdfsf2_1_sse"
3991   [(set (match_operand:SF 0 "nonimmediate_operand" "=*!m#fxr,?f#xr,?r#fx,?x#fr,Y#fr")
3992         (float_truncate:SF
3993          (match_operand:DF 1 "nonimmediate_operand" "f#Y,f#Y,f#Y,f#Y,mY#f")))
3994    (clobber (match_operand:SF 2 "memory_operand" "=X,m,m,m,X"))]
3995   "TARGET_80387 && TARGET_SSE2 && !TARGET_SSE_PARTIAL_REGS_FOR_CVTSD2SS"
3996 {
3997   switch (which_alternative)
3998     {
3999     case 0:
4000       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4001         return "fstp%z0\t%y0";
4002       else
4003         return "fst%z0\t%y0";
4004     case 4:
4005       return "#";
4006     default:
4007       abort ();
4008     }
4009 }
4010   [(set_attr "type" "fmov,multi,multi,multi,ssecvt")
4011    (set_attr "mode" "SF,SF,SF,SF,DF")])
4012
4013 (define_insn "*truncdfsf2_1_sse_nooverlap"
4014   [(set (match_operand:SF 0 "nonimmediate_operand" "=*!m,?f#rx,?r#fx,?x#rf,&Y")
4015         (float_truncate:SF
4016          (match_operand:DF 1 "nonimmediate_operand" "f#Y,f#Y,f#Y,f#Y,mY#f")))
4017    (clobber (match_operand:SF 2 "memory_operand" "=X,m,m,m,X"))]
4018   "TARGET_80387 && TARGET_SSE2 && TARGET_SSE_PARTIAL_REGS_FOR_CVTSD2SS"
4019 {
4020   switch (which_alternative)
4021     {
4022     case 0:
4023       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4024         return "fstp%z0\t%y0";
4025       else
4026         return "fst%z0\t%y0";
4027     case 4:
4028       return "#";
4029     default:
4030       abort ();
4031     }
4032 }
4033   [(set_attr "type" "fmov,multi,multi,multi,ssecvt")
4034    (set_attr "mode" "SF,SF,SF,SF,DF")])
4035
4036 (define_insn "*truncdfsf2_2"
4037   [(set (match_operand:SF 0 "nonimmediate_operand" "=Y,Y,!m")
4038         (float_truncate:SF
4039          (match_operand:DF 1 "nonimmediate_operand" "Y,mY,f#Y")))]
4040   "TARGET_80387 && TARGET_SSE2 && !TARGET_SSE_PARTIAL_REGS_FOR_CVTSD2SS
4041    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
4042 {
4043   switch (which_alternative)
4044     {
4045     case 0:
4046     case 1:
4047       return "cvtsd2ss\t{%1, %0|%0, %1}";
4048     case 2:
4049       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4050         return "fstp%z0\t%y0";
4051       else
4052         return "fst%z0\t%y0";
4053     default:
4054       abort ();
4055     }
4056 }
4057   [(set_attr "type" "ssecvt,ssecvt,fmov")
4058    (set_attr "athlon_decode" "vector,double,*")
4059    (set_attr "mode" "DF,DF,SF")])
4060
4061 (define_insn "*truncdfsf2_2_nooverlap"
4062   [(set (match_operand:SF 0 "nonimmediate_operand" "=&Y,!m")
4063         (float_truncate:SF
4064          (match_operand:DF 1 "nonimmediate_operand" "mY,f")))]
4065   "TARGET_80387 && TARGET_SSE2 && TARGET_SSE_PARTIAL_REGS_FOR_CVTSD2SS
4066    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
4067 {
4068   switch (which_alternative)
4069     {
4070     case 0:
4071       return "#";
4072     case 1:
4073       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4074         return "fstp%z0\t%y0";
4075       else
4076         return "fst%z0\t%y0";
4077     default:
4078       abort ();
4079     }
4080 }
4081   [(set_attr "type" "ssecvt,fmov")
4082    (set_attr "mode" "DF,SF")])
4083
4084 (define_insn "*truncdfsf2_3"
4085   [(set (match_operand:SF 0 "memory_operand" "=m")
4086         (float_truncate:SF
4087          (match_operand:DF 1 "register_operand" "f")))]
4088   "TARGET_80387"
4089 {
4090   if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4091     return "fstp%z0\t%y0";
4092   else
4093     return "fst%z0\t%y0";
4094 }
4095   [(set_attr "type" "fmov")
4096    (set_attr "mode" "SF")])
4097
4098 (define_insn "truncdfsf2_sse_only"
4099   [(set (match_operand:SF 0 "register_operand" "=Y,Y")
4100         (float_truncate:SF
4101          (match_operand:DF 1 "nonimmediate_operand" "Y,mY")))]
4102   "!TARGET_80387 && TARGET_SSE2 && !TARGET_SSE_PARTIAL_REGS_FOR_CVTSD2SS"
4103   "cvtsd2ss\t{%1, %0|%0, %1}"
4104   [(set_attr "type" "ssecvt")
4105    (set_attr "athlon_decode" "vector,double")
4106    (set_attr "mode" "DF")])
4107
4108 (define_insn "*truncdfsf2_sse_only_nooverlap"
4109   [(set (match_operand:SF 0 "register_operand" "=&Y")
4110         (float_truncate:SF
4111          (match_operand:DF 1 "nonimmediate_operand" "mY")))]
4112   "!TARGET_80387 && TARGET_SSE2 && TARGET_SSE_PARTIAL_REGS_FOR_CVTSD2SS"
4113   "#"
4114   [(set_attr "type" "ssecvt")
4115    (set_attr "mode" "DF")])
4116
4117 (define_split
4118   [(set (match_operand:SF 0 "memory_operand" "")
4119         (float_truncate:SF
4120          (match_operand:DF 1 "register_operand" "")))
4121    (clobber (match_operand:SF 2 "memory_operand" ""))]
4122   "TARGET_80387"
4123   [(set (match_dup 0) (float_truncate:SF (match_dup 1)))]
4124   "")
4125
4126 ; Avoid possible reformatting penalty on the destination by first
4127 ; zeroing it out
4128 (define_split
4129   [(set (match_operand:SF 0 "register_operand" "")
4130         (float_truncate:SF
4131          (match_operand:DF 1 "nonimmediate_operand" "")))
4132    (clobber (match_operand 2 "" ""))]
4133   "TARGET_80387 && reload_completed
4134    && SSE_REG_P (operands[0])
4135    && !STACK_REG_P (operands[1])"
4136   [(const_int 0)]
4137 {
4138   rtx src, dest;
4139   if (!TARGET_SSE_PARTIAL_REGS_FOR_CVTSD2SS)
4140     emit_insn (gen_truncdfsf2_sse_only (operands[0], operands[1]));
4141   else
4142     {
4143       dest = simplify_gen_subreg (V4SFmode, operands[0], SFmode, 0);
4144       src = simplify_gen_subreg (V2DFmode, operands[1], DFmode, 0);
4145       /* simplify_gen_subreg refuses to widen memory references.  */
4146       if (GET_CODE (src) == SUBREG)
4147         alter_subreg (&src);
4148       if (reg_overlap_mentioned_p (operands[0], operands[1]))
4149         abort ();
4150       emit_insn (gen_sse_clrv4sf (dest, CONST0_RTX (V4SFmode)));
4151       emit_insn (gen_cvtsd2ss (dest, dest, src));
4152     }
4153   DONE;
4154 })
4155
4156 (define_split
4157   [(set (match_operand:SF 0 "register_operand" "")
4158         (float_truncate:SF
4159          (match_operand:DF 1 "nonimmediate_operand" "")))]
4160   "TARGET_80387 && reload_completed
4161    && SSE_REG_P (operands[0]) && TARGET_SSE_PARTIAL_REGS_FOR_CVTSD2SS"
4162   [(const_int 0)]
4163 {
4164   rtx src, dest;
4165   dest = simplify_gen_subreg (V4SFmode, operands[0], SFmode, 0);
4166   src = simplify_gen_subreg (V2DFmode, operands[1], DFmode, 0);
4167   /* simplify_gen_subreg refuses to widen memory references.  */
4168   if (GET_CODE (src) == SUBREG)
4169     alter_subreg (&src);
4170   if (reg_overlap_mentioned_p (operands[0], operands[1]))
4171     abort ();
4172   emit_insn (gen_sse_clrv4sf (dest, CONST0_RTX (V4SFmode)));
4173   emit_insn (gen_cvtsd2ss (dest, dest, src));
4174   DONE;
4175 })
4176
4177 (define_split
4178   [(set (match_operand:SF 0 "register_operand" "")
4179         (float_truncate:SF
4180          (match_operand:DF 1 "fp_register_operand" "")))
4181    (clobber (match_operand:SF 2 "memory_operand" ""))]
4182   "TARGET_80387 && reload_completed"
4183   [(set (match_dup 2) (float_truncate:SF (match_dup 1)))
4184    (set (match_dup 0) (match_dup 2))]
4185   "")
4186
4187 (define_expand "truncxfsf2"
4188   [(parallel [(set (match_operand:SF 0 "nonimmediate_operand" "")
4189                    (float_truncate:SF
4190                     (match_operand:XF 1 "register_operand" "")))
4191               (clobber (match_dup 2))])]
4192   "!TARGET_64BIT && TARGET_80387"
4193   "operands[2] = assign_386_stack_local (SFmode, 0);")
4194
4195 (define_insn "*truncxfsf2_1"
4196   [(set (match_operand:SF 0 "nonimmediate_operand" "=m,?f#rx,?r#fx,?x#rf")
4197         (float_truncate:SF
4198          (match_operand:XF 1 "register_operand" "f,f,f,f")))
4199    (clobber (match_operand:SF 2 "memory_operand" "=X,m,m,m"))]
4200   "!TARGET_64BIT && TARGET_80387"
4201 {
4202   switch (which_alternative)
4203     {
4204     case 0:
4205       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4206         return "fstp%z0\t%y0";
4207       else
4208         return "fst%z0\t%y0";
4209     default:
4210       abort();
4211     }
4212 }
4213   [(set_attr "type" "fmov,multi,multi,multi")
4214    (set_attr "mode" "SF")])
4215
4216 (define_insn "*truncxfsf2_2"
4217   [(set (match_operand:SF 0 "memory_operand" "=m")
4218         (float_truncate:SF
4219          (match_operand:XF 1 "register_operand" "f")))]
4220   "!TARGET_64BIT && TARGET_80387"
4221 {
4222   if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4223     return "fstp%z0\t%y0";
4224   else
4225     return "fst%z0\t%y0";
4226 }
4227   [(set_attr "type" "fmov")
4228    (set_attr "mode" "SF")])
4229
4230 (define_split
4231   [(set (match_operand:SF 0 "memory_operand" "")
4232         (float_truncate:SF
4233          (match_operand:XF 1 "register_operand" "")))
4234    (clobber (match_operand:SF 2 "memory_operand" ""))]
4235   "TARGET_80387"
4236   [(set (match_dup 0) (float_truncate:SF (match_dup 1)))]
4237   "")
4238
4239 (define_split
4240   [(set (match_operand:SF 0 "register_operand" "")
4241         (float_truncate:SF
4242          (match_operand:XF 1 "register_operand" "")))
4243    (clobber (match_operand:SF 2 "memory_operand" ""))]
4244   "TARGET_80387 && reload_completed"
4245   [(set (match_dup 2) (float_truncate:SF (match_dup 1)))
4246    (set (match_dup 0) (match_dup 2))]
4247   "")
4248
4249 (define_expand "trunctfsf2"
4250   [(parallel [(set (match_operand:SF 0 "nonimmediate_operand" "")
4251                    (float_truncate:SF
4252                     (match_operand:TF 1 "register_operand" "")))
4253               (clobber (match_dup 2))])]
4254   "TARGET_80387"
4255   "operands[2] = assign_386_stack_local (SFmode, 0);")
4256
4257 (define_insn "*trunctfsf2_1"
4258   [(set (match_operand:SF 0 "nonimmediate_operand" "=m,?f#rx,?r#fx,?x#rf")
4259         (float_truncate:SF
4260          (match_operand:TF 1 "register_operand" "f,f,f,f")))
4261    (clobber (match_operand:SF 2 "memory_operand" "=X,m,m,m"))]
4262   "TARGET_80387"
4263 {
4264   switch (which_alternative)
4265     {
4266     case 0:
4267       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4268         return "fstp%z0\t%y0";
4269       else
4270         return "fst%z0\t%y0";
4271     default:
4272       abort();
4273     }
4274 }
4275   [(set_attr "type" "fmov,multi,multi,multi")
4276    (set_attr "mode" "SF")])
4277
4278 (define_insn "*trunctfsf2_2"
4279   [(set (match_operand:SF 0 "memory_operand" "=m")
4280         (float_truncate:SF
4281          (match_operand:TF 1 "register_operand" "f")))]
4282   "TARGET_80387"
4283 {
4284   if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4285     return "fstp%z0\t%y0";
4286   else
4287     return "fst%z0\t%y0";
4288 }
4289   [(set_attr "type" "fmov")
4290    (set_attr "mode" "SF")])
4291
4292 (define_split
4293   [(set (match_operand:SF 0 "memory_operand" "")
4294         (float_truncate:SF
4295          (match_operand:TF 1 "register_operand" "")))
4296    (clobber (match_operand:SF 2 "memory_operand" ""))]
4297   "TARGET_80387"
4298   [(set (match_dup 0) (float_truncate:SF (match_dup 1)))]
4299   "")
4300
4301 (define_split
4302   [(set (match_operand:SF 0 "register_operand" "")
4303         (float_truncate:SF
4304          (match_operand:TF 1 "register_operand" "")))
4305    (clobber (match_operand:SF 2 "memory_operand" ""))]
4306   "TARGET_80387 && reload_completed"
4307   [(set (match_dup 2) (float_truncate:SF (match_dup 1)))
4308    (set (match_dup 0) (match_dup 2))]
4309   "")
4310
4311
4312 (define_expand "truncxfdf2"
4313   [(parallel [(set (match_operand:DF 0 "nonimmediate_operand" "")
4314                    (float_truncate:DF
4315                     (match_operand:XF 1 "register_operand" "")))
4316               (clobber (match_dup 2))])]
4317   "!TARGET_64BIT && TARGET_80387"
4318   "operands[2] = assign_386_stack_local (DFmode, 0);")
4319
4320 (define_insn "*truncxfdf2_1"
4321   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,?f#rY,?r#fY,?Y#rf")
4322         (float_truncate:DF
4323          (match_operand:XF 1 "register_operand" "f,f,f,f")))
4324    (clobber (match_operand:DF 2 "memory_operand" "=X,m,m,m"))]
4325   "!TARGET_64BIT && TARGET_80387"
4326 {
4327   switch (which_alternative)
4328     {
4329     case 0:
4330       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4331         return "fstp%z0\t%y0";
4332       else
4333         return "fst%z0\t%y0";
4334     default:
4335       abort();
4336     }
4337   abort ();
4338 }
4339   [(set_attr "type" "fmov,multi,multi,multi")
4340    (set_attr "mode" "DF")])
4341
4342 (define_insn "*truncxfdf2_2"
4343   [(set (match_operand:DF 0 "memory_operand" "=m")
4344         (float_truncate:DF
4345           (match_operand:XF 1 "register_operand" "f")))]
4346   "!TARGET_64BIT && TARGET_80387"
4347 {
4348   if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4349     return "fstp%z0\t%y0";
4350   else
4351     return "fst%z0\t%y0";
4352 }
4353   [(set_attr "type" "fmov")
4354    (set_attr "mode" "DF")])
4355
4356 (define_split
4357   [(set (match_operand:DF 0 "memory_operand" "")
4358         (float_truncate:DF
4359          (match_operand:XF 1 "register_operand" "")))
4360    (clobber (match_operand:DF 2 "memory_operand" ""))]
4361   "TARGET_80387"
4362   [(set (match_dup 0) (float_truncate:DF (match_dup 1)))]
4363   "")
4364
4365 (define_split
4366   [(set (match_operand:DF 0 "register_operand" "")
4367         (float_truncate:DF
4368          (match_operand:XF 1 "register_operand" "")))
4369    (clobber (match_operand:DF 2 "memory_operand" ""))]
4370   "TARGET_80387 && reload_completed"
4371   [(set (match_dup 2) (float_truncate:DF (match_dup 1)))
4372    (set (match_dup 0) (match_dup 2))]
4373   "")
4374
4375 (define_expand "trunctfdf2"
4376   [(parallel [(set (match_operand:DF 0 "nonimmediate_operand" "")
4377                    (float_truncate:DF
4378                     (match_operand:TF 1 "register_operand" "")))
4379               (clobber (match_dup 2))])]
4380   "TARGET_80387"
4381   "operands[2] = assign_386_stack_local (DFmode, 0);")
4382
4383 (define_insn "*trunctfdf2_1"
4384   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,?f#rY,?r#fY,?Y#rf")
4385         (float_truncate:DF
4386          (match_operand:TF 1 "register_operand" "f,f,f,f")))
4387    (clobber (match_operand:DF 2 "memory_operand" "=X,m,m,m"))]
4388   "TARGET_80387"
4389 {
4390   switch (which_alternative)
4391     {
4392     case 0:
4393       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4394         return "fstp%z0\t%y0";
4395       else
4396         return "fst%z0\t%y0";
4397     default:
4398       abort();
4399     }
4400   abort ();
4401 }
4402   [(set_attr "type" "fmov,multi,multi,multi")
4403    (set_attr "mode" "DF")])
4404
4405         (define_insn "*trunctfdf2_2"
4406   [(set (match_operand:DF 0 "memory_operand" "=m")
4407         (float_truncate:DF
4408           (match_operand:TF 1 "register_operand" "f")))]
4409   "TARGET_80387"
4410 {
4411   if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4412     return "fstp%z0\t%y0";
4413   else
4414     return "fst%z0\t%y0";
4415 }
4416   [(set_attr "type" "fmov")
4417    (set_attr "mode" "DF")])
4418
4419 (define_split
4420   [(set (match_operand:DF 0 "memory_operand" "")
4421         (float_truncate:DF
4422          (match_operand:TF 1 "register_operand" "")))
4423    (clobber (match_operand:DF 2 "memory_operand" ""))]
4424   "TARGET_80387"
4425   [(set (match_dup 0) (float_truncate:DF (match_dup 1)))]
4426   "")
4427
4428 (define_split
4429   [(set (match_operand:DF 0 "register_operand" "")
4430         (float_truncate:DF
4431          (match_operand:TF 1 "register_operand" "")))
4432    (clobber (match_operand:DF 2 "memory_operand" ""))]
4433   "TARGET_80387 && reload_completed"
4434   [(set (match_dup 2) (float_truncate:DF (match_dup 1)))
4435    (set (match_dup 0) (match_dup 2))]
4436   "")
4437
4438 \f
4439 ;; %%% Break up all these bad boys.
4440
4441 ;; Signed conversion to DImode.
4442
4443 (define_expand "fix_truncxfdi2"
4444   [(set (match_operand:DI 0 "nonimmediate_operand" "")
4445         (fix:DI (match_operand:XF 1 "register_operand" "")))]
4446   "!TARGET_64BIT && TARGET_80387"
4447   "")
4448
4449 (define_expand "fix_trunctfdi2"
4450   [(set (match_operand:DI 0 "nonimmediate_operand" "")
4451         (fix:DI (match_operand:TF 1 "register_operand" "")))]
4452   "TARGET_80387"
4453   "")
4454
4455 (define_expand "fix_truncdfdi2"
4456   [(set (match_operand:DI 0 "nonimmediate_operand" "")
4457         (fix:DI (match_operand:DF 1 "register_operand" "")))]
4458   "TARGET_80387 || (TARGET_SSE2 && TARGET_64BIT)"
4459 {
4460   if (TARGET_64BIT && TARGET_SSE2)
4461    {
4462      rtx out = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (DImode);
4463      emit_insn (gen_fix_truncdfdi_sse (out, operands[1]));
4464      if (out != operands[0])
4465         emit_move_insn (operands[0], out);
4466      DONE;
4467    }
4468 })
4469
4470 (define_expand "fix_truncsfdi2"
4471   [(set (match_operand:DI 0 "nonimmediate_operand" "")
4472         (fix:DI (match_operand:SF 1 "register_operand" "")))]
4473   "TARGET_80387 || (TARGET_SSE && TARGET_64BIT)"
4474 {
4475   if (TARGET_SSE && TARGET_64BIT)
4476    {
4477      rtx out = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (DImode);
4478      emit_insn (gen_fix_truncsfdi_sse (out, operands[1]));
4479      if (out != operands[0])
4480         emit_move_insn (operands[0], out);
4481      DONE;
4482    }
4483 })
4484
4485 ;; See the comments in i386.h near OPTIMIZE_MODE_SWITCHING for the description
4486 ;; of the machinery.
4487 (define_insn_and_split "*fix_truncdi_1"
4488   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r")
4489         (fix:DI (match_operand 1 "register_operand" "f,f")))]
4490   "TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[1]))
4491    && !reload_completed && !reload_in_progress
4492    && (!SSE_FLOAT_MODE_P (GET_MODE (operands[1])) || !TARGET_64BIT)"
4493   "#"
4494   "&& 1"
4495   [(const_int 0)]
4496 {
4497   operands[2] = assign_386_stack_local (HImode, 1);
4498   operands[3] = assign_386_stack_local (HImode, 2);
4499   if (memory_operand (operands[0], VOIDmode))
4500     emit_insn (gen_fix_truncdi_memory (operands[0], operands[1],
4501                                        operands[2], operands[3]));
4502   else
4503     {
4504       operands[4] = assign_386_stack_local (DImode, 0);
4505       emit_insn (gen_fix_truncdi_nomemory (operands[0], operands[1],
4506                                            operands[2], operands[3],
4507                                            operands[4]));
4508     }
4509   DONE;
4510 }
4511   [(set_attr "type" "fistp")])
4512
4513 (define_insn "fix_truncdi_nomemory"
4514   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r")
4515         (fix:DI (match_operand 1 "register_operand" "f,f")))
4516    (use (match_operand:HI 2 "memory_operand" "m,m"))
4517    (use (match_operand:HI 3 "memory_operand" "m,m"))
4518    (clobber (match_operand:DI 4 "memory_operand" "=m,m"))
4519    (clobber (match_scratch:DF 5 "=&1f,&1f"))]
4520   "TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[1]))
4521    && (!SSE_FLOAT_MODE_P (GET_MODE (operands[1])) || !TARGET_64BIT)"
4522   "#"
4523   [(set_attr "type" "fistp")])
4524
4525 (define_insn "fix_truncdi_memory"
4526   [(set (match_operand:DI 0 "memory_operand" "=m")
4527         (fix:DI (match_operand 1 "register_operand" "f")))
4528    (use (match_operand:HI 2 "memory_operand" "m"))
4529    (use (match_operand:HI 3 "memory_operand" "m"))
4530    (clobber (match_scratch:DF 4 "=&1f"))]
4531   "TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[1]))
4532    && (!SSE_FLOAT_MODE_P (GET_MODE (operands[1])) || !TARGET_64BIT)"
4533   "* operands[5] = operands[4]; return output_fix_trunc (insn, operands);"
4534   [(set_attr "type" "fistp")])
4535
4536 (define_split 
4537   [(set (match_operand:DI 0 "register_operand" "")
4538         (fix:DI (match_operand 1 "register_operand" "")))
4539    (use (match_operand:HI 2 "memory_operand" ""))
4540    (use (match_operand:HI 3 "memory_operand" ""))
4541    (clobber (match_operand:DI 4 "memory_operand" ""))
4542    (clobber (match_scratch 5 ""))]
4543   "reload_completed"
4544   [(parallel [(set (match_dup 4) (fix:DI (match_dup 1)))
4545               (use (match_dup 2))
4546               (use (match_dup 3))
4547               (clobber (match_dup 5))])
4548    (set (match_dup 0) (match_dup 4))]
4549   "")
4550
4551 (define_split 
4552   [(set (match_operand:DI 0 "memory_operand" "")
4553         (fix:DI (match_operand 1 "register_operand" "")))
4554    (use (match_operand:HI 2 "memory_operand" ""))
4555    (use (match_operand:HI 3 "memory_operand" ""))
4556    (clobber (match_operand:DI 4 "memory_operand" ""))
4557    (clobber (match_scratch 5 ""))]
4558   "reload_completed"
4559   [(parallel [(set (match_dup 0) (fix:DI (match_dup 1)))
4560               (use (match_dup 2))
4561               (use (match_dup 3))
4562               (clobber (match_dup 5))])]
4563   "")
4564
4565 ;; When SSE available, it is always faster to use it!
4566 (define_insn "fix_truncsfdi_sse"
4567   [(set (match_operand:DI 0 "register_operand" "=r,r")
4568         (fix:DI (match_operand:SF 1 "nonimmediate_operand" "x,xm")))]
4569   "TARGET_64BIT && TARGET_SSE"
4570   "cvttss2si{q}\t{%1, %0|%0, %1}"
4571   [(set_attr "type" "sseicvt")
4572    (set_attr "athlon_decode" "double,vector")])
4573
4574 (define_insn "fix_truncdfdi_sse"
4575   [(set (match_operand:DI 0 "register_operand" "=r,r")
4576         (fix:DI (match_operand:DF 1 "nonimmediate_operand" "Y,Ym")))]
4577   "TARGET_64BIT && TARGET_SSE2"
4578   "cvttsd2si{q}\t{%1, %0|%0, %1}"
4579   [(set_attr "type" "sseicvt,sseicvt")
4580    (set_attr "athlon_decode" "double,vector")])
4581
4582 ;; Signed conversion to SImode.
4583
4584 (define_expand "fix_truncxfsi2"
4585   [(set (match_operand:SI 0 "nonimmediate_operand" "")
4586         (fix:SI (match_operand:XF 1 "register_operand" "")))]
4587   "!TARGET_64BIT && TARGET_80387"
4588   "")
4589
4590 (define_expand "fix_trunctfsi2"
4591   [(set (match_operand:SI 0 "nonimmediate_operand" "")
4592         (fix:SI (match_operand:TF 1 "register_operand" "")))]
4593   "TARGET_80387"
4594   "")
4595
4596 (define_expand "fix_truncdfsi2"
4597   [(set (match_operand:SI 0 "nonimmediate_operand" "")
4598         (fix:SI (match_operand:DF 1 "register_operand" "")))]
4599   "TARGET_80387 || TARGET_SSE2"
4600 {
4601   if (TARGET_SSE2)
4602    {
4603      rtx out = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (SImode);
4604      emit_insn (gen_fix_truncdfsi_sse (out, operands[1]));
4605      if (out != operands[0])
4606         emit_move_insn (operands[0], out);
4607      DONE;
4608    }
4609 })
4610
4611 (define_expand "fix_truncsfsi2"
4612   [(set (match_operand:SI 0 "nonimmediate_operand" "")
4613         (fix:SI (match_operand:SF 1 "register_operand" "")))]
4614   "TARGET_80387 || TARGET_SSE"
4615 {
4616   if (TARGET_SSE)
4617    {
4618      rtx out = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (SImode);
4619      emit_insn (gen_fix_truncsfsi_sse (out, operands[1]));
4620      if (out != operands[0])
4621         emit_move_insn (operands[0], out);
4622      DONE;
4623    }
4624 })
4625
4626 ;; See the comments in i386.h near OPTIMIZE_MODE_SWITCHING for the description
4627 ;; of the machinery.
4628 (define_insn_and_split "*fix_truncsi_1"
4629   [(set (match_operand:SI 0 "nonimmediate_operand" "=m,?r")
4630         (fix:SI (match_operand 1 "register_operand" "f,f")))]
4631   "TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[1]))
4632    && !reload_completed && !reload_in_progress
4633    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
4634   "#"
4635   "&& 1"
4636   [(const_int 0)]
4637 {
4638   operands[2] = assign_386_stack_local (HImode, 1);
4639   operands[3] = assign_386_stack_local (HImode, 2);
4640   if (memory_operand (operands[0], VOIDmode))
4641     emit_insn (gen_fix_truncsi_memory (operands[0], operands[1],
4642                                        operands[2], operands[3]));
4643   else
4644     {
4645       operands[4] = assign_386_stack_local (SImode, 0);
4646       emit_insn (gen_fix_truncsi_nomemory (operands[0], operands[1],
4647                                            operands[2], operands[3],
4648                                            operands[4]));
4649     }
4650   DONE;
4651 }
4652   [(set_attr "type" "fistp")])
4653
4654 (define_insn "fix_truncsi_nomemory"
4655   [(set (match_operand:SI 0 "nonimmediate_operand" "=m,?r")
4656         (fix:SI (match_operand 1 "register_operand" "f,f")))
4657    (use (match_operand:HI 2 "memory_operand" "m,m"))
4658    (use (match_operand:HI 3 "memory_operand" "m,m"))
4659    (clobber (match_operand:SI 4 "memory_operand" "=m,m"))]
4660   "TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[1]))
4661    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
4662   "#"
4663   [(set_attr "type" "fistp")])
4664
4665 (define_insn "fix_truncsi_memory"
4666   [(set (match_operand:SI 0 "memory_operand" "=m")
4667         (fix:SI (match_operand 1 "register_operand" "f")))
4668    (use (match_operand:HI 2 "memory_operand" "m"))
4669    (use (match_operand:HI 3 "memory_operand" "m"))]
4670   "TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[1]))
4671    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
4672   "* return output_fix_trunc (insn, operands);"
4673   [(set_attr "type" "fistp")])
4674
4675 ;; When SSE available, it is always faster to use it!
4676 (define_insn "fix_truncsfsi_sse"
4677   [(set (match_operand:SI 0 "register_operand" "=r,r")
4678         (fix:SI (match_operand:SF 1 "nonimmediate_operand" "x,xm")))]
4679   "TARGET_SSE"
4680   "cvttss2si\t{%1, %0|%0, %1}"
4681   [(set_attr "type" "sseicvt")
4682    (set_attr "athlon_decode" "double,vector")])
4683
4684 (define_insn "fix_truncdfsi_sse"
4685   [(set (match_operand:SI 0 "register_operand" "=r,r")
4686         (fix:SI (match_operand:DF 1 "nonimmediate_operand" "Y,Ym")))]
4687   "TARGET_SSE2"
4688   "cvttsd2si\t{%1, %0|%0, %1}"
4689   [(set_attr "type" "sseicvt")
4690    (set_attr "athlon_decode" "double,vector")])
4691
4692 (define_split 
4693   [(set (match_operand:SI 0 "register_operand" "")
4694         (fix:SI (match_operand 1 "register_operand" "")))
4695    (use (match_operand:HI 2 "memory_operand" ""))
4696    (use (match_operand:HI 3 "memory_operand" ""))
4697    (clobber (match_operand:SI 4 "memory_operand" ""))]
4698   "reload_completed"
4699   [(parallel [(set (match_dup 4) (fix:SI (match_dup 1)))
4700               (use (match_dup 2))
4701               (use (match_dup 3))])
4702    (set (match_dup 0) (match_dup 4))]
4703   "")
4704
4705 (define_split 
4706   [(set (match_operand:SI 0 "memory_operand" "")
4707         (fix:SI (match_operand 1 "register_operand" "")))
4708    (use (match_operand:HI 2 "memory_operand" ""))
4709    (use (match_operand:HI 3 "memory_operand" ""))
4710    (clobber (match_operand:SI 4 "memory_operand" ""))]
4711   "reload_completed"
4712   [(parallel [(set (match_dup 0) (fix:SI (match_dup 1)))
4713               (use (match_dup 2))
4714               (use (match_dup 3))])]
4715   "")
4716
4717 ;; Signed conversion to HImode.
4718
4719 (define_expand "fix_truncxfhi2"
4720   [(set (match_operand:HI 0 "nonimmediate_operand" "")
4721         (fix:HI (match_operand:XF 1 "register_operand" "")))]
4722   "!TARGET_64BIT && TARGET_80387"
4723   "")
4724
4725 (define_expand "fix_trunctfhi2"
4726   [(set (match_operand:HI 0 "nonimmediate_operand" "")
4727         (fix:HI (match_operand:TF 1 "register_operand" "")))]
4728   "TARGET_80387"
4729   "")
4730
4731 (define_expand "fix_truncdfhi2"
4732   [(set (match_operand:HI 0 "nonimmediate_operand" "")
4733         (fix:HI (match_operand:DF 1 "register_operand" "")))]
4734   "TARGET_80387 && !TARGET_SSE2"
4735   "")
4736
4737 (define_expand "fix_truncsfhi2"
4738   [(set (match_operand:HI 0 "nonimmediate_operand" "")
4739         (fix:HI (match_operand:SF 1 "register_operand" "")))]
4740   "TARGET_80387 && !TARGET_SSE"
4741   "")
4742
4743 ;; See the comments in i386.h near OPTIMIZE_MODE_SWITCHING for the description
4744 ;; of the machinery.
4745 (define_insn_and_split "*fix_trunchi_1"
4746   [(set (match_operand:HI 0 "nonimmediate_operand" "=m,?r")
4747         (fix:HI (match_operand 1 "register_operand" "f,f")))]
4748   "TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[1]))
4749    && !reload_completed && !reload_in_progress
4750    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
4751   "#"
4752   ""
4753   [(const_int 0)]
4754 {
4755   operands[2] = assign_386_stack_local (HImode, 1);
4756   operands[3] = assign_386_stack_local (HImode, 2);
4757   if (memory_operand (operands[0], VOIDmode))
4758     emit_insn (gen_fix_trunchi_memory (operands[0], operands[1],
4759                                        operands[2], operands[3]));
4760   else
4761     {
4762       operands[4] = assign_386_stack_local (HImode, 0);
4763       emit_insn (gen_fix_trunchi_nomemory (operands[0], operands[1],
4764                                            operands[2], operands[3],
4765                                            operands[4]));
4766     }
4767   DONE;
4768 }
4769   [(set_attr "type" "fistp")])
4770
4771 (define_insn "fix_trunchi_nomemory"
4772   [(set (match_operand:HI 0 "nonimmediate_operand" "=m,?r")
4773         (fix:HI (match_operand 1 "register_operand" "f,f")))
4774    (use (match_operand:HI 2 "memory_operand" "m,m"))
4775    (use (match_operand:HI 3 "memory_operand" "m,m"))
4776    (clobber (match_operand:HI 4 "memory_operand" "=m,m"))]
4777   "TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[1]))
4778    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
4779   "#"
4780   [(set_attr "type" "fistp")])
4781
4782 (define_insn "fix_trunchi_memory"
4783   [(set (match_operand:HI 0 "memory_operand" "=m")
4784         (fix:HI (match_operand 1 "register_operand" "f")))
4785    (use (match_operand:HI 2 "memory_operand" "m"))
4786    (use (match_operand:HI 3 "memory_operand" "m"))]
4787   "TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[1]))
4788    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
4789   "* return output_fix_trunc (insn, operands);"
4790   [(set_attr "type" "fistp")])
4791
4792 (define_split 
4793   [(set (match_operand:HI 0 "memory_operand" "")
4794         (fix:HI (match_operand 1 "register_operand" "")))
4795    (use (match_operand:HI 2 "memory_operand" ""))
4796    (use (match_operand:HI 3 "memory_operand" ""))
4797    (clobber (match_operand:HI 4 "memory_operand" ""))]
4798   "reload_completed"
4799   [(parallel [(set (match_dup 0) (fix:HI (match_dup 1)))
4800               (use (match_dup 2))
4801               (use (match_dup 3))])]
4802   "")
4803
4804 (define_split 
4805   [(set (match_operand:HI 0 "register_operand" "")
4806         (fix:HI (match_operand 1 "register_operand" "")))
4807    (use (match_operand:HI 2 "memory_operand" ""))
4808    (use (match_operand:HI 3 "memory_operand" ""))
4809    (clobber (match_operand:HI 4 "memory_operand" ""))]
4810   "reload_completed"
4811   [(parallel [(set (match_dup 4) (fix:HI (match_dup 1)))
4812               (use (match_dup 2))
4813               (use (match_dup 3))
4814               (clobber (match_dup 4))])
4815    (set (match_dup 0) (match_dup 4))]
4816   "")
4817
4818 ;; %% Not used yet.
4819 (define_insn "x86_fnstcw_1"
4820   [(set (match_operand:HI 0 "memory_operand" "=m")
4821         (unspec:HI [(reg:HI 18)] UNSPEC_FSTCW))]
4822   "TARGET_80387"
4823   "fnstcw\t%0"
4824   [(set_attr "length" "2")
4825    (set_attr "mode" "HI")
4826    (set_attr "unit" "i387")
4827    (set_attr "ppro_uops" "few")])
4828
4829 (define_insn "x86_fldcw_1"
4830   [(set (reg:HI 18)
4831         (unspec:HI [(match_operand:HI 0 "memory_operand" "m")] UNSPEC_FLDCW))]
4832   "TARGET_80387"
4833   "fldcw\t%0"
4834   [(set_attr "length" "2")
4835    (set_attr "mode" "HI")
4836    (set_attr "unit" "i387")
4837    (set_attr "athlon_decode" "vector")
4838    (set_attr "ppro_uops" "few")])
4839 \f
4840 ;; Conversion between fixed point and floating point.
4841
4842 ;; Even though we only accept memory inputs, the backend _really_
4843 ;; wants to be able to do this between registers.
4844
4845 (define_insn "floathisf2"
4846   [(set (match_operand:SF 0 "register_operand" "=f,f")
4847         (float:SF (match_operand:HI 1 "nonimmediate_operand" "m,r")))]
4848   "TARGET_80387 && !TARGET_SSE"
4849   "@
4850    fild%z1\t%1
4851    #"
4852   [(set_attr "type" "fmov,multi")
4853    (set_attr "mode" "SF")
4854    (set_attr "fp_int_src" "true")])
4855
4856 (define_expand "floatsisf2"
4857   [(set (match_operand:SF 0 "register_operand" "")
4858         (float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
4859   "TARGET_SSE || TARGET_80387"
4860   "")
4861
4862 (define_insn "*floatsisf2_i387"
4863   [(set (match_operand:SF 0 "register_operand" "=f#x,?f#x,x#f,x#f")
4864         (float:SF (match_operand:SI 1 "nonimmediate_operand" "m,r,r,mr")))]
4865   "TARGET_80387 && (!TARGET_SSE || TARGET_MIX_SSE_I387)"
4866   "@
4867    fild%z1\t%1
4868    #
4869    cvtsi2ss\t{%1, %0|%0, %1}
4870    cvtsi2ss\t{%1, %0|%0, %1}"
4871   [(set_attr "type" "fmov,multi,sseicvt,sseicvt")
4872    (set_attr "mode" "SF")
4873    (set_attr "athlon_decode" "*,*,vector,double")
4874    (set_attr "fp_int_src" "true")])
4875
4876 (define_insn "*floatsisf2_sse"
4877   [(set (match_operand:SF 0 "register_operand" "=x,x")
4878         (float:SF (match_operand:SI 1 "nonimmediate_operand" "r,mr")))]
4879   "TARGET_SSE"
4880   "cvtsi2ss\t{%1, %0|%0, %1}"
4881   [(set_attr "type" "sseicvt")
4882    (set_attr "mode" "SF")
4883    (set_attr "athlon_decode" "vector,double")
4884    (set_attr "fp_int_src" "true")])
4885
4886 ; Avoid possible reformatting penalty on the destination by first
4887 ; zeroing it out
4888 (define_split
4889   [(set (match_operand:SF 0 "register_operand" "")
4890         (float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
4891   "TARGET_80387 && reload_completed && TARGET_SSE_PARTIAL_REGS
4892    && SSE_REG_P (operands[0])"
4893   [(const_int 0)]
4894 {
4895   rtx dest;
4896   dest = simplify_gen_subreg (V4SFmode, operands[0], SFmode, 0);
4897   emit_insn (gen_sse_clrv4sf (dest, CONST0_RTX (V4SFmode)));
4898   emit_insn (gen_cvtsi2ss (dest, dest, operands[1]));
4899   DONE;
4900 })
4901
4902 (define_expand "floatdisf2"
4903   [(set (match_operand:SF 0 "register_operand" "")
4904         (float:SF (match_operand:DI 1 "nonimmediate_operand" "")))]
4905   "(TARGET_64BIT && TARGET_SSE) || TARGET_80387"
4906   "")
4907
4908 (define_insn "*floatdisf2_i387_only"
4909   [(set (match_operand:SF 0 "register_operand" "=f,?f")
4910         (float:SF (match_operand:DI 1 "nonimmediate_operand" "m,r")))]
4911   "TARGET_80387 && (!TARGET_SSE || !TARGET_64BIT || TARGET_MIX_SSE_I387)"
4912   "@
4913    fild%z1\t%1
4914    #"
4915   [(set_attr "type" "fmov,multi")
4916    (set_attr "mode" "SF")
4917    (set_attr "fp_int_src" "true")])
4918
4919 (define_insn "*floatdisf2_i387"
4920   [(set (match_operand:SF 0 "register_operand" "=f#x,?f#x,x#f,x#f")
4921         (float:SF (match_operand:DI 1 "nonimmediate_operand" "m,r,r,mr")))]
4922   "TARGET_64BIT && TARGET_80387 && (!TARGET_SSE || TARGET_MIX_SSE_I387)"
4923   "@
4924    fild%z1\t%1
4925    #
4926    cvtsi2ss{q}\t{%1, %0|%0, %1}
4927    cvtsi2ss{q}\t{%1, %0|%0, %1}"
4928   [(set_attr "type" "fmov,multi,sseicvt,sseicvt")
4929    (set_attr "mode" "SF")
4930    (set_attr "athlon_decode" "*,*,vector,double")
4931    (set_attr "fp_int_src" "true")])
4932
4933 (define_insn "*floatdisf2_sse"
4934   [(set (match_operand:SF 0 "register_operand" "=x,x")
4935         (float:SF (match_operand:DI 1 "nonimmediate_operand" "r,mr")))]
4936   "TARGET_64BIT && TARGET_SSE"
4937   "cvtsi2ss{q}\t{%1, %0|%0, %1}"
4938   [(set_attr "type" "sseicvt")
4939    (set_attr "mode" "SF")
4940    (set_attr "athlon_decode" "vector,double")
4941    (set_attr "fp_int_src" "true")])
4942
4943 ; Avoid possible reformatting penalty on the destination by first
4944 ; zeroing it out
4945 (define_split
4946   [(set (match_operand:SF 0 "register_operand" "")
4947         (float:SF (match_operand:DI 1 "nonimmediate_operand" "")))]
4948   "TARGET_80387 && reload_completed && TARGET_SSE_PARTIAL_REGS
4949    && SSE_REG_P (operands[0])"
4950   [(const_int 0)]
4951 {
4952   rtx dest;
4953   dest = simplify_gen_subreg (V4SFmode, operands[0], SFmode, 0);
4954   emit_insn (gen_sse_clrv4sf (dest, CONST0_RTX (V4SFmode)));
4955   emit_insn (gen_cvtsi2ssq (dest, dest, operands[1]));
4956   DONE;
4957 })
4958
4959 (define_insn "floathidf2"
4960   [(set (match_operand:DF 0 "register_operand" "=f,f")
4961         (float:DF (match_operand:HI 1 "nonimmediate_operand" "m,r")))]
4962   "TARGET_80387 && !TARGET_SSE2"
4963   "@
4964    fild%z1\t%1
4965    #"
4966   [(set_attr "type" "fmov,multi")
4967    (set_attr "mode" "DF")
4968    (set_attr "fp_int_src" "true")])
4969
4970 (define_expand "floatsidf2"
4971   [(set (match_operand:DF 0 "register_operand" "")
4972         (float:DF (match_operand:SI 1 "nonimmediate_operand" "")))]
4973   "TARGET_80387 || TARGET_SSE2"
4974   "")
4975
4976 (define_insn "*floatsidf2_i387"
4977   [(set (match_operand:DF 0 "register_operand" "=f#Y,?f#Y,Y#f,Y#f")
4978         (float:DF (match_operand:SI 1 "nonimmediate_operand" "m,r,r,mr")))]
4979   "TARGET_80387 && (!TARGET_SSE2 || TARGET_MIX_SSE_I387)"
4980   "@
4981    fild%z1\t%1
4982    #
4983    cvtsi2sd\t{%1, %0|%0, %1}
4984    cvtsi2sd\t{%1, %0|%0, %1}"
4985   [(set_attr "type" "fmov,multi,sseicvt,sseicvt")
4986    (set_attr "mode" "DF")
4987    (set_attr "athlon_decode" "*,*,double,direct")
4988    (set_attr "fp_int_src" "true")])
4989
4990 (define_insn "*floatsidf2_sse"
4991   [(set (match_operand:DF 0 "register_operand" "=Y,Y")
4992         (float:DF (match_operand:SI 1 "nonimmediate_operand" "r,mr")))]
4993   "TARGET_SSE2"
4994   "cvtsi2sd\t{%1, %0|%0, %1}"
4995   [(set_attr "type" "sseicvt")
4996    (set_attr "mode" "DF")
4997    (set_attr "athlon_decode" "double,direct")
4998    (set_attr "fp_int_src" "true")])
4999
5000 (define_expand "floatdidf2"
5001   [(set (match_operand:DF 0 "register_operand" "")
5002         (float:DF (match_operand:DI 1 "nonimmediate_operand" "")))]
5003   "(TARGET_64BIT && TARGET_SSE2) || TARGET_80387"
5004   "")
5005
5006 (define_insn "*floatdidf2_i387_only"
5007   [(set (match_operand:DF 0 "register_operand" "=f,?f")
5008         (float:DF (match_operand:DI 1 "nonimmediate_operand" "m,r")))]
5009   "TARGET_80387 && (!TARGET_SSE2 || !TARGET_64BIT)"
5010   "@
5011    fild%z1\t%1
5012    #"
5013   [(set_attr "type" "fmov,multi")
5014    (set_attr "mode" "DF")
5015    (set_attr "fp_int_src" "true")])
5016
5017 (define_insn "*floatdidf2_i387"
5018   [(set (match_operand:DF 0 "register_operand" "=f#Y,?f#Y,Y#f,Y#f")
5019         (float:DF (match_operand:DI 1 "nonimmediate_operand" "m,r,r,mr")))]
5020   "TARGET_64BIT && TARGET_80387 && (!TARGET_SSE2 || TARGET_MIX_SSE_I387)"
5021   "@
5022    fild%z1\t%1
5023    #
5024    cvtsi2sd{q}\t{%1, %0|%0, %1}
5025    cvtsi2sd{q}\t{%1, %0|%0, %1}"
5026   [(set_attr "type" "fmov,multi,sseicvt,sseicvt")
5027    (set_attr "mode" "DF")
5028    (set_attr "athlon_decode" "*,*,double,direct")
5029    (set_attr "fp_int_src" "true")])
5030
5031 (define_insn "*floatdidf2_sse"
5032   [(set (match_operand:DF 0 "register_operand" "=Y,Y")
5033         (float:DF (match_operand:DI 1 "nonimmediate_operand" "r,mr")))]
5034   "TARGET_SSE2"
5035   "cvtsi2sd{q}\t{%1, %0|%0, %1}"
5036   [(set_attr "type" "sseicvt")
5037    (set_attr "mode" "DF")
5038    (set_attr "athlon_decode" "double,direct")
5039    (set_attr "fp_int_src" "true")])
5040
5041 (define_insn "floathixf2"
5042   [(set (match_operand:XF 0 "register_operand" "=f,f")
5043         (float:XF (match_operand:HI 1 "nonimmediate_operand" "m,r")))]
5044   "!TARGET_64BIT && TARGET_80387"
5045   "@
5046    fild%z1\t%1
5047    #"
5048   [(set_attr "type" "fmov,multi")
5049    (set_attr "mode" "XF")
5050    (set_attr "fp_int_src" "true")])
5051
5052 (define_insn "floathitf2"
5053   [(set (match_operand:TF 0 "register_operand" "=f,f")
5054         (float:TF (match_operand:HI 1 "nonimmediate_operand" "m,r")))]
5055   "TARGET_80387"
5056   "@
5057    fild%z1\t%1
5058    #"
5059   [(set_attr "type" "fmov,multi")
5060    (set_attr "mode" "XF")
5061    (set_attr "fp_int_src" "true")])
5062
5063 (define_insn "floatsixf2"
5064   [(set (match_operand:XF 0 "register_operand" "=f,f")
5065         (float:XF (match_operand:SI 1 "nonimmediate_operand" "m,r")))]
5066   "!TARGET_64BIT && TARGET_80387"
5067   "@
5068    fild%z1\t%1
5069    #"
5070   [(set_attr "type" "fmov,multi")
5071    (set_attr "mode" "XF")
5072    (set_attr "fp_int_src" "true")])
5073
5074 (define_insn "floatsitf2"
5075   [(set (match_operand:TF 0 "register_operand" "=f,f")
5076         (float:TF (match_operand:SI 1 "nonimmediate_operand" "m,r")))]
5077   "TARGET_80387"
5078   "@
5079    fild%z1\t%1
5080    #"
5081   [(set_attr "type" "fmov,multi")
5082    (set_attr "mode" "XF")
5083    (set_attr "fp_int_src" "true")])
5084
5085 (define_insn "floatdixf2"
5086   [(set (match_operand:XF 0 "register_operand" "=f,f")
5087         (float:XF (match_operand:DI 1 "nonimmediate_operand" "m,r")))]
5088   "!TARGET_64BIT && TARGET_80387"
5089   "@
5090    fild%z1\t%1
5091    #"
5092   [(set_attr "type" "fmov,multi")
5093    (set_attr "mode" "XF")
5094    (set_attr "fp_int_src" "true")])
5095
5096 (define_insn "floatditf2"
5097   [(set (match_operand:TF 0 "register_operand" "=f,f")
5098         (float:TF (match_operand:DI 1 "nonimmediate_operand" "m,r")))]
5099   "TARGET_80387"
5100   "@
5101    fild%z1\t%1
5102    #"
5103   [(set_attr "type" "fmov,multi")
5104    (set_attr "mode" "XF")
5105    (set_attr "fp_int_src" "true")])
5106
5107 ;; %%% Kill these when reload knows how to do it.
5108 (define_split
5109   [(set (match_operand 0 "fp_register_operand" "")
5110         (float (match_operand 1 "register_operand" "")))]
5111   "reload_completed && FLOAT_MODE_P (GET_MODE (operands[0]))"
5112   [(const_int 0)]
5113 {
5114   operands[2] = ix86_force_to_memory (GET_MODE (operands[1]), operands[1]);
5115   operands[2] = gen_rtx_FLOAT (GET_MODE (operands[0]), operands[2]);
5116   emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[2]));
5117   ix86_free_from_memory (GET_MODE (operands[1]));
5118   DONE;
5119 })
5120
5121 (define_expand "floatunssisf2"
5122   [(use (match_operand:SF 0 "register_operand" ""))
5123    (use (match_operand:SI 1 "register_operand" ""))]
5124   "TARGET_SSE && TARGET_SSE_MATH && !TARGET_64BIT"
5125   "x86_emit_floatuns (operands); DONE;")
5126
5127 (define_expand "floatunsdisf2"
5128   [(use (match_operand:SF 0 "register_operand" ""))
5129    (use (match_operand:DI 1 "register_operand" ""))]
5130   "TARGET_SSE && TARGET_SSE_MATH && TARGET_64BIT"
5131   "x86_emit_floatuns (operands); DONE;")
5132
5133 (define_expand "floatunsdidf2"
5134   [(use (match_operand:DF 0 "register_operand" ""))
5135    (use (match_operand:DI 1 "register_operand" ""))]
5136   "TARGET_SSE2 && TARGET_SSE_MATH && TARGET_64BIT"
5137   "x86_emit_floatuns (operands); DONE;")
5138 \f
5139 ;; Add instructions
5140
5141 ;; %%% splits for addsidi3
5142 ;  [(set (match_operand:DI 0 "nonimmediate_operand" "")
5143 ;       (plus:DI (match_operand:DI 1 "general_operand" "")
5144 ;                (zero_extend:DI (match_operand:SI 2 "general_operand" ""))))]
5145
5146 (define_expand "adddi3"
5147   [(set (match_operand:DI 0 "nonimmediate_operand" "")
5148         (plus:DI (match_operand:DI 1 "nonimmediate_operand" "")
5149                  (match_operand:DI 2 "x86_64_general_operand" "")))
5150    (clobber (reg:CC 17))]
5151   ""
5152   "ix86_expand_binary_operator (PLUS, DImode, operands); DONE;")
5153
5154 (define_insn "*adddi3_1"
5155   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,o")
5156         (plus:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
5157                  (match_operand:DI 2 "general_operand" "roiF,riF")))
5158    (clobber (reg:CC 17))]
5159   "!TARGET_64BIT && ix86_binary_operator_ok (PLUS, DImode, operands)"
5160   "#")
5161
5162 (define_split
5163   [(set (match_operand:DI 0 "nonimmediate_operand" "")
5164         (plus:DI (match_operand:DI 1 "nonimmediate_operand" "")
5165                  (match_operand:DI 2 "general_operand" "")))
5166    (clobber (reg:CC 17))]
5167   "!TARGET_64BIT && reload_completed"
5168   [(parallel [(set (reg:CC 17) (unspec:CC [(match_dup 1) (match_dup 2)]
5169                                           UNSPEC_ADD_CARRY))
5170               (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))])
5171    (parallel [(set (match_dup 3)
5172                    (plus:SI (plus:SI (ltu:SI (reg:CC 17) (const_int 0))
5173                                      (match_dup 4))
5174                             (match_dup 5)))
5175               (clobber (reg:CC 17))])]
5176   "split_di (operands+0, 1, operands+0, operands+3);
5177    split_di (operands+1, 1, operands+1, operands+4);
5178    split_di (operands+2, 1, operands+2, operands+5);")
5179
5180 (define_insn "adddi3_carry_rex64"
5181   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
5182           (plus:DI (plus:DI (match_operand:DI 3 "ix86_carry_flag_operator" "")
5183                             (match_operand:DI 1 "nonimmediate_operand" "%0,0"))
5184                    (match_operand:DI 2 "x86_64_general_operand" "re,rm")))
5185    (clobber (reg:CC 17))]
5186   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, DImode, operands)"
5187   "adc{q}\t{%2, %0|%0, %2}"
5188   [(set_attr "type" "alu")
5189    (set_attr "pent_pair" "pu")
5190    (set_attr "mode" "DI")
5191    (set_attr "ppro_uops" "few")])
5192
5193 (define_insn "*adddi3_cc_rex64"
5194   [(set (reg:CC 17)
5195         (unspec:CC [(match_operand:DI 1 "nonimmediate_operand" "%0,0")
5196                     (match_operand:DI 2 "x86_64_general_operand" "re,rm")]
5197                    UNSPEC_ADD_CARRY))
5198    (set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
5199         (plus:DI (match_dup 1) (match_dup 2)))]
5200   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, DImode, operands)"
5201   "add{q}\t{%2, %0|%0, %2}"
5202   [(set_attr "type" "alu")
5203    (set_attr "mode" "DI")])
5204
5205 (define_insn "addqi3_carry"
5206   [(set (match_operand:QI 0 "nonimmediate_operand" "=rm,r")
5207           (plus:QI (plus:QI (match_operand:QI 3 "ix86_carry_flag_operator" "")
5208                             (match_operand:QI 1 "nonimmediate_operand" "%0,0"))
5209                    (match_operand:QI 2 "general_operand" "ri,rm")))
5210    (clobber (reg:CC 17))]
5211   "ix86_binary_operator_ok (PLUS, QImode, operands)"
5212   "adc{b}\t{%2, %0|%0, %2}"
5213   [(set_attr "type" "alu")
5214    (set_attr "pent_pair" "pu")
5215    (set_attr "mode" "QI")
5216    (set_attr "ppro_uops" "few")])
5217
5218 (define_insn "addhi3_carry"
5219   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r")
5220           (plus:HI (plus:HI (match_operand:HI 3 "ix86_carry_flag_operator" "")
5221                             (match_operand:HI 1 "nonimmediate_operand" "%0,0"))
5222                    (match_operand:HI 2 "general_operand" "ri,rm")))
5223    (clobber (reg:CC 17))]
5224   "ix86_binary_operator_ok (PLUS, HImode, operands)"
5225   "adc{w}\t{%2, %0|%0, %2}"
5226   [(set_attr "type" "alu")
5227    (set_attr "pent_pair" "pu")
5228    (set_attr "mode" "HI")
5229    (set_attr "ppro_uops" "few")])
5230
5231 (define_insn "addsi3_carry"
5232   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
5233           (plus:SI (plus:SI (match_operand:SI 3 "ix86_carry_flag_operator" "")
5234                             (match_operand:SI 1 "nonimmediate_operand" "%0,0"))
5235                    (match_operand:SI 2 "general_operand" "ri,rm")))
5236    (clobber (reg:CC 17))]
5237   "ix86_binary_operator_ok (PLUS, SImode, operands)"
5238   "adc{l}\t{%2, %0|%0, %2}"
5239   [(set_attr "type" "alu")
5240    (set_attr "pent_pair" "pu")
5241    (set_attr "mode" "SI")
5242    (set_attr "ppro_uops" "few")])
5243
5244 (define_insn "*addsi3_carry_zext"
5245   [(set (match_operand:DI 0 "register_operand" "=r")
5246           (zero_extend:DI 
5247             (plus:SI (plus:SI (match_operand:SI 3 "ix86_carry_flag_operator" "")
5248                               (match_operand:SI 1 "nonimmediate_operand" "%0"))
5249                      (match_operand:SI 2 "general_operand" "rim"))))
5250    (clobber (reg:CC 17))]
5251   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, SImode, operands)"
5252   "adc{l}\t{%2, %k0|%k0, %2}"
5253   [(set_attr "type" "alu")
5254    (set_attr "pent_pair" "pu")
5255    (set_attr "mode" "SI")
5256    (set_attr "ppro_uops" "few")])
5257
5258 (define_insn "*addsi3_cc"
5259   [(set (reg:CC 17)
5260         (unspec:CC [(match_operand:SI 1 "nonimmediate_operand" "%0,0")
5261                     (match_operand:SI 2 "general_operand" "ri,rm")]
5262                    UNSPEC_ADD_CARRY))
5263    (set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
5264         (plus:SI (match_dup 1) (match_dup 2)))]
5265   "ix86_binary_operator_ok (PLUS, SImode, operands)"
5266   "add{l}\t{%2, %0|%0, %2}"
5267   [(set_attr "type" "alu")
5268    (set_attr "mode" "SI")])
5269
5270 (define_insn "addqi3_cc"
5271   [(set (reg:CC 17)
5272         (unspec:CC [(match_operand:QI 1 "nonimmediate_operand" "%0,0")
5273                     (match_operand:QI 2 "general_operand" "qi,qm")]
5274                    UNSPEC_ADD_CARRY))
5275    (set (match_operand:QI 0 "nonimmediate_operand" "=qm,q")
5276         (plus:QI (match_dup 1) (match_dup 2)))]
5277   "ix86_binary_operator_ok (PLUS, QImode, operands)"
5278   "add{b}\t{%2, %0|%0, %2}"
5279   [(set_attr "type" "alu")
5280    (set_attr "mode" "QI")])
5281
5282 (define_expand "addsi3"
5283   [(parallel [(set (match_operand:SI 0 "nonimmediate_operand" "")
5284                    (plus:SI (match_operand:SI 1 "nonimmediate_operand" "")
5285                             (match_operand:SI 2 "general_operand" "")))
5286               (clobber (reg:CC 17))])]
5287   ""
5288   "ix86_expand_binary_operator (PLUS, SImode, operands); DONE;")
5289
5290 (define_insn "*lea_1"
5291   [(set (match_operand:SI 0 "register_operand" "=r")
5292         (match_operand:SI 1 "address_operand" "p"))]
5293   "!TARGET_64BIT"
5294   "lea{l}\t{%a1, %0|%0, %a1}"
5295   [(set_attr "type" "lea")
5296    (set_attr "mode" "SI")])
5297
5298 (define_insn "*lea_1_rex64"
5299   [(set (match_operand:SI 0 "register_operand" "=r")
5300         (subreg:SI (match_operand:DI 1 "address_operand" "p") 0))]
5301   "TARGET_64BIT"
5302   "lea{l}\t{%a1, %0|%0, %a1}"
5303   [(set_attr "type" "lea")
5304    (set_attr "mode" "SI")])
5305
5306 (define_insn "*lea_1_zext"
5307   [(set (match_operand:DI 0 "register_operand" "=r")
5308         (zero_extend:DI (subreg:SI (match_operand:DI 1 "address_operand" "p") 0)))]
5309   "TARGET_64BIT"
5310   "lea{l}\t{%a1, %k0|%k0, %a1}"
5311   [(set_attr "type" "lea")
5312    (set_attr "mode" "SI")])
5313
5314 (define_insn "*lea_2_rex64"
5315   [(set (match_operand:DI 0 "register_operand" "=r")
5316         (match_operand:DI 1 "address_operand" "p"))]
5317   "TARGET_64BIT"
5318   "lea{q}\t{%a1, %0|%0, %a1}"
5319   [(set_attr "type" "lea")
5320    (set_attr "mode" "DI")])
5321
5322 ;; The lea patterns for non-Pmodes needs to be matched by several
5323 ;; insns converted to real lea by splitters.
5324
5325 (define_insn_and_split "*lea_general_1"
5326   [(set (match_operand 0 "register_operand" "=r")
5327         (plus (plus (match_operand 1 "index_register_operand" "r")
5328                     (match_operand 2 "register_operand" "r"))
5329               (match_operand 3 "immediate_operand" "i")))]
5330   "(GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode
5331     || (TARGET_64BIT && GET_MODE (operands[0]) == SImode))
5332    && (!TARGET_PARTIAL_REG_STALL || optimize_size)
5333    && GET_MODE (operands[0]) == GET_MODE (operands[1])
5334    && GET_MODE (operands[0]) == GET_MODE (operands[2])
5335    && (GET_MODE (operands[0]) == GET_MODE (operands[3])
5336        || GET_MODE (operands[3]) == VOIDmode)"
5337   "#"
5338   "&& reload_completed"
5339   [(const_int 0)]
5340 {
5341   rtx pat;
5342   operands[0] = gen_lowpart (SImode, operands[0]);
5343   operands[1] = gen_lowpart (Pmode, operands[1]);
5344   operands[2] = gen_lowpart (Pmode, operands[2]);
5345   operands[3] = gen_lowpart (Pmode, operands[3]);
5346   pat = gen_rtx_PLUS (Pmode, gen_rtx_PLUS (Pmode, operands[1], operands[2]),
5347                       operands[3]);
5348   if (Pmode != SImode)
5349     pat = gen_rtx_SUBREG (SImode, pat, 0);
5350   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
5351   DONE;
5352 }
5353   [(set_attr "type" "lea")
5354    (set_attr "mode" "SI")])
5355
5356 (define_insn_and_split "*lea_general_1_zext"
5357   [(set (match_operand:DI 0 "register_operand" "=r")
5358         (zero_extend:DI
5359           (plus:SI (plus:SI (match_operand:SI 1 "index_register_operand" "r")
5360                             (match_operand:SI 2 "register_operand" "r"))
5361                    (match_operand:SI 3 "immediate_operand" "i"))))]
5362   "TARGET_64BIT"
5363   "#"
5364   "&& reload_completed"
5365   [(set (match_dup 0)
5366         (zero_extend:DI (subreg:SI (plus:DI (plus:DI (match_dup 1)
5367                                                      (match_dup 2))
5368                                             (match_dup 3)) 0)))]
5369 {
5370   operands[1] = gen_lowpart (Pmode, operands[1]);
5371   operands[2] = gen_lowpart (Pmode, operands[2]);
5372   operands[3] = gen_lowpart (Pmode, operands[3]);
5373 }
5374   [(set_attr "type" "lea")
5375    (set_attr "mode" "SI")])
5376
5377 (define_insn_and_split "*lea_general_2"
5378   [(set (match_operand 0 "register_operand" "=r")
5379         (plus (mult (match_operand 1 "index_register_operand" "r")
5380                     (match_operand 2 "const248_operand" "i"))
5381               (match_operand 3 "nonmemory_operand" "ri")))]
5382   "(GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode
5383     || (TARGET_64BIT && GET_MODE (operands[0]) == SImode))
5384    && (!TARGET_PARTIAL_REG_STALL || optimize_size)
5385    && GET_MODE (operands[0]) == GET_MODE (operands[1])
5386    && (GET_MODE (operands[0]) == GET_MODE (operands[3])
5387        || GET_MODE (operands[3]) == VOIDmode)"
5388   "#"
5389   "&& reload_completed"
5390   [(const_int 0)]
5391 {
5392   rtx pat;
5393   operands[0] = gen_lowpart (SImode, operands[0]);
5394   operands[1] = gen_lowpart (Pmode, operands[1]);
5395   operands[3] = gen_lowpart (Pmode, operands[3]);
5396   pat = gen_rtx_PLUS (Pmode, gen_rtx_MULT (Pmode, operands[1], operands[2]),
5397                       operands[3]);
5398   if (Pmode != SImode)
5399     pat = gen_rtx_SUBREG (SImode, pat, 0);
5400   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
5401   DONE;
5402 }
5403   [(set_attr "type" "lea")
5404    (set_attr "mode" "SI")])
5405
5406 (define_insn_and_split "*lea_general_2_zext"
5407   [(set (match_operand:DI 0 "register_operand" "=r")
5408         (zero_extend:DI
5409           (plus:SI (mult:SI (match_operand:SI 1 "index_register_operand" "r")
5410                             (match_operand:SI 2 "const248_operand" "n"))
5411                    (match_operand:SI 3 "nonmemory_operand" "ri"))))]
5412   "TARGET_64BIT"
5413   "#"
5414   "&& reload_completed"
5415   [(set (match_dup 0)
5416         (zero_extend:DI (subreg:SI (plus:DI (mult:DI (match_dup 1)
5417                                                      (match_dup 2))
5418                                             (match_dup 3)) 0)))]
5419 {
5420   operands[1] = gen_lowpart (Pmode, operands[1]);
5421   operands[3] = gen_lowpart (Pmode, operands[3]);
5422 }
5423   [(set_attr "type" "lea")
5424    (set_attr "mode" "SI")])
5425
5426 (define_insn_and_split "*lea_general_3"
5427   [(set (match_operand 0 "register_operand" "=r")
5428         (plus (plus (mult (match_operand 1 "index_register_operand" "r")
5429                           (match_operand 2 "const248_operand" "i"))
5430                     (match_operand 3 "register_operand" "r"))
5431               (match_operand 4 "immediate_operand" "i")))]
5432   "(GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode
5433     || (TARGET_64BIT && GET_MODE (operands[0]) == SImode))
5434    && (!TARGET_PARTIAL_REG_STALL || optimize_size)
5435    && GET_MODE (operands[0]) == GET_MODE (operands[1])
5436    && GET_MODE (operands[0]) == GET_MODE (operands[3])"
5437   "#"
5438   "&& reload_completed"
5439   [(const_int 0)]
5440 {
5441   rtx pat;
5442   operands[0] = gen_lowpart (SImode, operands[0]);
5443   operands[1] = gen_lowpart (Pmode, operands[1]);
5444   operands[3] = gen_lowpart (Pmode, operands[3]);
5445   operands[4] = gen_lowpart (Pmode, operands[4]);
5446   pat = gen_rtx_PLUS (Pmode,
5447                       gen_rtx_PLUS (Pmode, gen_rtx_MULT (Pmode, operands[1],
5448                                                          operands[2]),
5449                                     operands[3]),
5450                       operands[4]);
5451   if (Pmode != SImode)
5452     pat = gen_rtx_SUBREG (SImode, pat, 0);
5453   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
5454   DONE;
5455 }
5456   [(set_attr "type" "lea")
5457    (set_attr "mode" "SI")])
5458
5459 (define_insn_and_split "*lea_general_3_zext"
5460   [(set (match_operand:DI 0 "register_operand" "=r")
5461         (zero_extend:DI
5462           (plus:SI (plus:SI (mult:SI (match_operand:SI 1 "index_register_operand" "r")
5463                                      (match_operand:SI 2 "const248_operand" "n"))
5464                             (match_operand:SI 3 "register_operand" "r"))
5465                    (match_operand:SI 4 "immediate_operand" "i"))))]
5466   "TARGET_64BIT"
5467   "#"
5468   "&& reload_completed"
5469   [(set (match_dup 0)
5470         (zero_extend:DI (subreg:SI (plus:DI (plus:DI (mult:DI (match_dup 1)
5471                                                               (match_dup 2))
5472                                                      (match_dup 3))
5473                                             (match_dup 4)) 0)))]
5474 {
5475   operands[1] = gen_lowpart (Pmode, operands[1]);
5476   operands[3] = gen_lowpart (Pmode, operands[3]);
5477   operands[4] = gen_lowpart (Pmode, operands[4]);
5478 }
5479   [(set_attr "type" "lea")
5480    (set_attr "mode" "SI")])
5481
5482 (define_insn "*adddi_1_rex64"
5483   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,rm,r")
5484         (plus:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0,r")
5485                  (match_operand:DI 2 "x86_64_general_operand" "rme,re,re")))
5486    (clobber (reg:CC 17))]
5487   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, DImode, operands)"
5488 {
5489   switch (get_attr_type (insn))
5490     {
5491     case TYPE_LEA:
5492       operands[2] = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
5493       return "lea{q}\t{%a2, %0|%0, %a2}";
5494
5495     case TYPE_INCDEC:
5496       if (! rtx_equal_p (operands[0], operands[1]))
5497         abort ();
5498       if (operands[2] == const1_rtx)
5499         return "inc{q}\t%0";
5500       else if (operands[2] == constm1_rtx)
5501         return "dec{q}\t%0";
5502       else
5503         abort ();
5504
5505     default:
5506       if (! rtx_equal_p (operands[0], operands[1]))
5507         abort ();
5508
5509       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
5510          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
5511       if (GET_CODE (operands[2]) == CONST_INT
5512           /* Avoid overflows.  */
5513           && ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1)))
5514           && (INTVAL (operands[2]) == 128
5515               || (INTVAL (operands[2]) < 0
5516                   && INTVAL (operands[2]) != -128)))
5517         {
5518           operands[2] = GEN_INT (-INTVAL (operands[2]));
5519           return "sub{q}\t{%2, %0|%0, %2}";
5520         }
5521       return "add{q}\t{%2, %0|%0, %2}";
5522     }
5523 }
5524   [(set (attr "type")
5525      (cond [(eq_attr "alternative" "2")
5526               (const_string "lea")
5527             ; Current assemblers are broken and do not allow @GOTOFF in
5528             ; ought but a memory context.
5529             (match_operand:DI 2 "pic_symbolic_operand" "")
5530               (const_string "lea")
5531             (match_operand:DI 2 "incdec_operand" "")
5532               (const_string "incdec")
5533            ]
5534            (const_string "alu")))
5535    (set_attr "mode" "DI")])
5536
5537 ;; Convert lea to the lea pattern to avoid flags dependency.
5538 (define_split
5539   [(set (match_operand:DI 0 "register_operand" "")
5540         (plus:DI (match_operand:DI 1 "register_operand" "")
5541                  (match_operand:DI 2 "x86_64_nonmemory_operand" "")))
5542    (clobber (reg:CC 17))]
5543   "TARGET_64BIT && reload_completed
5544    && true_regnum (operands[0]) != true_regnum (operands[1])"
5545   [(set (match_dup 0)
5546         (plus:DI (match_dup 1)
5547                  (match_dup 2)))]
5548   "")
5549
5550 (define_insn "*adddi_2_rex64"
5551   [(set (reg 17)
5552         (compare
5553           (plus:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
5554                    (match_operand:DI 2 "x86_64_general_operand" "rme,re"))
5555           (const_int 0)))                       
5556    (set (match_operand:DI 0 "nonimmediate_operand" "=r,rm")
5557         (plus:DI (match_dup 1) (match_dup 2)))]
5558   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
5559    && ix86_binary_operator_ok (PLUS, DImode, operands)
5560    /* Current assemblers are broken and do not allow @GOTOFF in
5561       ought but a memory context.  */
5562    && ! pic_symbolic_operand (operands[2], VOIDmode)"
5563 {
5564   switch (get_attr_type (insn))
5565     {
5566     case TYPE_INCDEC:
5567       if (! rtx_equal_p (operands[0], operands[1]))
5568         abort ();
5569       if (operands[2] == const1_rtx)
5570         return "inc{q}\t%0";
5571       else if (operands[2] == constm1_rtx)
5572         return "dec{q}\t%0";
5573       else
5574         abort ();
5575
5576     default:
5577       if (! rtx_equal_p (operands[0], operands[1]))
5578         abort ();
5579       /* ???? We ought to handle there the 32bit case too
5580          - do we need new constraint?  */
5581       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
5582          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
5583       if (GET_CODE (operands[2]) == CONST_INT
5584           /* Avoid overflows.  */
5585           && ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1)))
5586           && (INTVAL (operands[2]) == 128
5587               || (INTVAL (operands[2]) < 0
5588                   && INTVAL (operands[2]) != -128)))
5589         {
5590           operands[2] = GEN_INT (-INTVAL (operands[2]));
5591           return "sub{q}\t{%2, %0|%0, %2}";
5592         }
5593       return "add{q}\t{%2, %0|%0, %2}";
5594     }
5595 }
5596   [(set (attr "type")
5597      (if_then_else (match_operand:DI 2 "incdec_operand" "")
5598         (const_string "incdec")
5599         (const_string "alu")))
5600    (set_attr "mode" "DI")])
5601
5602 (define_insn "*adddi_3_rex64"
5603   [(set (reg 17)
5604         (compare (neg:DI (match_operand:DI 2 "x86_64_general_operand" "rme"))
5605                  (match_operand:DI 1 "x86_64_general_operand" "%0")))
5606    (clobber (match_scratch:DI 0 "=r"))]
5607   "TARGET_64BIT
5608    && ix86_match_ccmode (insn, CCZmode)
5609    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)
5610    /* Current assemblers are broken and do not allow @GOTOFF in
5611       ought but a memory context.  */
5612    && ! pic_symbolic_operand (operands[2], VOIDmode)"
5613 {
5614   switch (get_attr_type (insn))
5615     {
5616     case TYPE_INCDEC:
5617       if (! rtx_equal_p (operands[0], operands[1]))
5618         abort ();
5619       if (operands[2] == const1_rtx)
5620         return "inc{q}\t%0";
5621       else if (operands[2] == constm1_rtx)
5622         return "dec{q}\t%0";
5623       else
5624         abort ();
5625
5626     default:
5627       if (! rtx_equal_p (operands[0], operands[1]))
5628         abort ();
5629       /* ???? We ought to handle there the 32bit case too
5630          - do we need new constraint?  */
5631       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
5632          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
5633       if (GET_CODE (operands[2]) == CONST_INT
5634           /* Avoid overflows.  */
5635           && ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1)))
5636           && (INTVAL (operands[2]) == 128
5637               || (INTVAL (operands[2]) < 0
5638                   && INTVAL (operands[2]) != -128)))
5639         {
5640           operands[2] = GEN_INT (-INTVAL (operands[2]));
5641           return "sub{q}\t{%2, %0|%0, %2}";
5642         }
5643       return "add{q}\t{%2, %0|%0, %2}";
5644     }
5645 }
5646   [(set (attr "type")
5647      (if_then_else (match_operand:DI 2 "incdec_operand" "")
5648         (const_string "incdec")
5649         (const_string "alu")))
5650    (set_attr "mode" "DI")])
5651
5652 ; For comparisons against 1, -1 and 128, we may generate better code
5653 ; by converting cmp to add, inc or dec as done by peephole2.  This pattern
5654 ; is matched then.  We can't accept general immediate, because for
5655 ; case of overflows,  the result is messed up.
5656 ; This pattern also don't hold of 0x8000000000000000, since the value overflows
5657 ; when negated.
5658 ; Also carry flag is reversed compared to cmp, so this conversion is valid
5659 ; only for comparisons not depending on it.
5660 (define_insn "*adddi_4_rex64"
5661   [(set (reg 17)
5662         (compare (match_operand:DI 1 "nonimmediate_operand" "0")
5663                  (match_operand:DI 2 "x86_64_immediate_operand" "e")))
5664    (clobber (match_scratch:DI 0 "=rm"))]
5665   "TARGET_64BIT
5666    &&  ix86_match_ccmode (insn, CCGCmode)"
5667 {
5668   switch (get_attr_type (insn))
5669     {
5670     case TYPE_INCDEC:
5671       if (operands[2] == constm1_rtx)
5672         return "inc{q}\t%0";
5673       else if (operands[2] == const1_rtx)
5674         return "dec{q}\t%0";
5675       else
5676         abort();
5677
5678     default:
5679       if (! rtx_equal_p (operands[0], operands[1]))
5680         abort ();
5681       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
5682          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
5683       if ((INTVAL (operands[2]) == -128
5684            || (INTVAL (operands[2]) > 0
5685                && INTVAL (operands[2]) != 128))
5686           /* Avoid overflows.  */
5687           && ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1))))
5688         return "sub{q}\t{%2, %0|%0, %2}";
5689       operands[2] = GEN_INT (-INTVAL (operands[2]));
5690       return "add{q}\t{%2, %0|%0, %2}";
5691     }
5692 }
5693   [(set (attr "type")
5694      (if_then_else (match_operand:DI 2 "incdec_operand" "")
5695         (const_string "incdec")
5696         (const_string "alu")))
5697    (set_attr "mode" "DI")])
5698
5699 (define_insn "*adddi_5_rex64"
5700   [(set (reg 17)
5701         (compare
5702           (plus:DI (match_operand:DI 1 "nonimmediate_operand" "%0")
5703                    (match_operand:DI 2 "x86_64_general_operand" "rme"))
5704           (const_int 0)))                       
5705    (clobber (match_scratch:DI 0 "=r"))]
5706   "TARGET_64BIT
5707    && ix86_match_ccmode (insn, CCGOCmode)
5708    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)
5709    /* Current assemblers are broken and do not allow @GOTOFF in
5710       ought but a memory context.  */
5711    && ! pic_symbolic_operand (operands[2], VOIDmode)"
5712 {
5713   switch (get_attr_type (insn))
5714     {
5715     case TYPE_INCDEC:
5716       if (! rtx_equal_p (operands[0], operands[1]))
5717         abort ();
5718       if (operands[2] == const1_rtx)
5719         return "inc{q}\t%0";
5720       else if (operands[2] == constm1_rtx)
5721         return "dec{q}\t%0";
5722       else
5723         abort();
5724
5725     default:
5726       if (! rtx_equal_p (operands[0], operands[1]))
5727         abort ();
5728       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
5729          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
5730       if (GET_CODE (operands[2]) == CONST_INT
5731           /* Avoid overflows.  */
5732           && ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1)))
5733           && (INTVAL (operands[2]) == 128
5734               || (INTVAL (operands[2]) < 0
5735                   && INTVAL (operands[2]) != -128)))
5736         {
5737           operands[2] = GEN_INT (-INTVAL (operands[2]));
5738           return "sub{q}\t{%2, %0|%0, %2}";
5739         }
5740       return "add{q}\t{%2, %0|%0, %2}";
5741     }
5742 }
5743   [(set (attr "type")
5744      (if_then_else (match_operand:DI 2 "incdec_operand" "")
5745         (const_string "incdec")
5746         (const_string "alu")))
5747    (set_attr "mode" "DI")])
5748
5749
5750 (define_insn "*addsi_1"
5751   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,rm,r")
5752         (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,r")
5753                  (match_operand:SI 2 "general_operand" "rmni,rni,rni")))
5754    (clobber (reg:CC 17))]
5755   "ix86_binary_operator_ok (PLUS, SImode, operands)"
5756 {
5757   switch (get_attr_type (insn))
5758     {
5759     case TYPE_LEA:
5760       operands[2] = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
5761       return "lea{l}\t{%a2, %0|%0, %a2}";
5762
5763     case TYPE_INCDEC:
5764       if (! rtx_equal_p (operands[0], operands[1]))
5765         abort ();
5766       if (operands[2] == const1_rtx)
5767         return "inc{l}\t%0";
5768       else if (operands[2] == constm1_rtx)
5769         return "dec{l}\t%0";
5770       else
5771         abort();
5772
5773     default:
5774       if (! rtx_equal_p (operands[0], operands[1]))
5775         abort ();
5776
5777       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
5778          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
5779       if (GET_CODE (operands[2]) == CONST_INT
5780           && (INTVAL (operands[2]) == 128
5781               || (INTVAL (operands[2]) < 0
5782                   && INTVAL (operands[2]) != -128)))
5783         {
5784           operands[2] = GEN_INT (-INTVAL (operands[2]));
5785           return "sub{l}\t{%2, %0|%0, %2}";
5786         }
5787       return "add{l}\t{%2, %0|%0, %2}";
5788     }
5789 }
5790   [(set (attr "type")
5791      (cond [(eq_attr "alternative" "2")
5792               (const_string "lea")
5793             ; Current assemblers are broken and do not allow @GOTOFF in
5794             ; ought but a memory context.
5795             (match_operand:SI 2 "pic_symbolic_operand" "")
5796               (const_string "lea")
5797             (match_operand:SI 2 "incdec_operand" "")
5798               (const_string "incdec")
5799            ]
5800            (const_string "alu")))
5801    (set_attr "mode" "SI")])
5802
5803 ;; Convert lea to the lea pattern to avoid flags dependency.
5804 (define_split
5805   [(set (match_operand 0 "register_operand" "")
5806         (plus (match_operand 1 "register_operand" "")
5807               (match_operand 2 "nonmemory_operand" "")))
5808    (clobber (reg:CC 17))]
5809   "reload_completed
5810    && true_regnum (operands[0]) != true_regnum (operands[1])"
5811   [(const_int 0)]
5812 {
5813   rtx pat;
5814   /* In -fPIC mode the constructs like (const (unspec [symbol_ref]))
5815      may confuse gen_lowpart.  */
5816   if (GET_MODE (operands[0]) != Pmode)
5817     {
5818       operands[1] = gen_lowpart (Pmode, operands[1]);
5819       operands[2] = gen_lowpart (Pmode, operands[2]);
5820     }
5821   operands[0] = gen_lowpart (SImode, operands[0]);
5822   pat = gen_rtx_PLUS (Pmode, operands[1], operands[2]);
5823   if (Pmode != SImode)
5824     pat = gen_rtx_SUBREG (SImode, pat, 0);
5825   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
5826   DONE;
5827 })
5828
5829 ;; It may seem that nonimmediate operand is proper one for operand 1.
5830 ;; The addsi_1 pattern allows nonimmediate operand at that place and
5831 ;; we take care in ix86_binary_operator_ok to not allow two memory
5832 ;; operands so proper swapping will be done in reload.  This allow
5833 ;; patterns constructed from addsi_1 to match.
5834 (define_insn "addsi_1_zext"
5835   [(set (match_operand:DI 0 "register_operand" "=r,r")
5836         (zero_extend:DI
5837           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0,r")
5838                    (match_operand:SI 2 "general_operand" "rmni,rni"))))
5839    (clobber (reg:CC 17))]
5840   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, SImode, operands)"
5841 {
5842   switch (get_attr_type (insn))
5843     {
5844     case TYPE_LEA:
5845       operands[2] = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
5846       return "lea{l}\t{%a2, %k0|%k0, %a2}";
5847
5848     case TYPE_INCDEC:
5849       if (operands[2] == const1_rtx)
5850         return "inc{l}\t%k0";
5851       else if (operands[2] == constm1_rtx)
5852         return "dec{l}\t%k0";
5853       else
5854         abort();
5855
5856     default:
5857       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
5858          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
5859       if (GET_CODE (operands[2]) == CONST_INT
5860           && (INTVAL (operands[2]) == 128
5861               || (INTVAL (operands[2]) < 0
5862                   && INTVAL (operands[2]) != -128)))
5863         {
5864           operands[2] = GEN_INT (-INTVAL (operands[2]));
5865           return "sub{l}\t{%2, %k0|%k0, %2}";
5866         }
5867       return "add{l}\t{%2, %k0|%k0, %2}";
5868     }
5869 }
5870   [(set (attr "type")
5871      (cond [(eq_attr "alternative" "1")
5872               (const_string "lea")
5873             ; Current assemblers are broken and do not allow @GOTOFF in
5874             ; ought but a memory context.
5875             (match_operand:SI 2 "pic_symbolic_operand" "")
5876               (const_string "lea")
5877             (match_operand:SI 2 "incdec_operand" "")
5878               (const_string "incdec")
5879            ]
5880            (const_string "alu")))
5881    (set_attr "mode" "SI")])
5882
5883 ;; Convert lea to the lea pattern to avoid flags dependency.
5884 (define_split
5885   [(set (match_operand:DI 0 "register_operand" "")
5886         (zero_extend:DI
5887           (plus:SI (match_operand:SI 1 "register_operand" "")
5888                    (match_operand:SI 2 "nonmemory_operand" ""))))
5889    (clobber (reg:CC 17))]
5890   "TARGET_64BIT && reload_completed
5891    && true_regnum (operands[0]) != true_regnum (operands[1])"
5892   [(set (match_dup 0)
5893         (zero_extend:DI (subreg:SI (plus:DI (match_dup 1) (match_dup 2)) 0)))]
5894 {
5895   operands[1] = gen_lowpart (Pmode, operands[1]);
5896   operands[2] = gen_lowpart (Pmode, operands[2]);
5897 })
5898
5899 (define_insn "*addsi_2"
5900   [(set (reg 17)
5901         (compare
5902           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0")
5903                    (match_operand:SI 2 "general_operand" "rmni,rni"))
5904           (const_int 0)))                       
5905    (set (match_operand:SI 0 "nonimmediate_operand" "=r,rm")
5906         (plus:SI (match_dup 1) (match_dup 2)))]
5907   "ix86_match_ccmode (insn, CCGOCmode)
5908    && ix86_binary_operator_ok (PLUS, SImode, operands)
5909    /* Current assemblers are broken and do not allow @GOTOFF in
5910       ought but a memory context.  */
5911    && ! pic_symbolic_operand (operands[2], VOIDmode)"
5912 {
5913   switch (get_attr_type (insn))
5914     {
5915     case TYPE_INCDEC:
5916       if (! rtx_equal_p (operands[0], operands[1]))
5917         abort ();
5918       if (operands[2] == const1_rtx)
5919         return "inc{l}\t%0";
5920       else if (operands[2] == constm1_rtx)
5921         return "dec{l}\t%0";
5922       else
5923         abort();
5924
5925     default:
5926       if (! rtx_equal_p (operands[0], operands[1]))
5927         abort ();
5928       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
5929          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
5930       if (GET_CODE (operands[2]) == CONST_INT
5931           && (INTVAL (operands[2]) == 128
5932               || (INTVAL (operands[2]) < 0
5933                   && INTVAL (operands[2]) != -128)))
5934         {
5935           operands[2] = GEN_INT (-INTVAL (operands[2]));
5936           return "sub{l}\t{%2, %0|%0, %2}";
5937         }
5938       return "add{l}\t{%2, %0|%0, %2}";
5939     }
5940 }
5941   [(set (attr "type")
5942      (if_then_else (match_operand:SI 2 "incdec_operand" "")
5943         (const_string "incdec")
5944         (const_string "alu")))
5945    (set_attr "mode" "SI")])
5946
5947 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
5948 (define_insn "*addsi_2_zext"
5949   [(set (reg 17)
5950         (compare
5951           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
5952                    (match_operand:SI 2 "general_operand" "rmni"))
5953           (const_int 0)))                       
5954    (set (match_operand:DI 0 "register_operand" "=r")
5955         (zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))]
5956   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
5957    && ix86_binary_operator_ok (PLUS, SImode, operands)
5958    /* Current assemblers are broken and do not allow @GOTOFF in
5959       ought but a memory context.  */
5960    && ! pic_symbolic_operand (operands[2], VOIDmode)"
5961 {
5962   switch (get_attr_type (insn))
5963     {
5964     case TYPE_INCDEC:
5965       if (operands[2] == const1_rtx)
5966         return "inc{l}\t%k0";
5967       else if (operands[2] == constm1_rtx)
5968         return "dec{l}\t%k0";
5969       else
5970         abort();
5971
5972     default:
5973       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
5974          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
5975       if (GET_CODE (operands[2]) == CONST_INT
5976           && (INTVAL (operands[2]) == 128
5977               || (INTVAL (operands[2]) < 0
5978                   && INTVAL (operands[2]) != -128)))
5979         {
5980           operands[2] = GEN_INT (-INTVAL (operands[2]));
5981           return "sub{l}\t{%2, %k0|%k0, %2}";
5982         }
5983       return "add{l}\t{%2, %k0|%k0, %2}";
5984     }
5985 }
5986   [(set (attr "type")
5987      (if_then_else (match_operand:SI 2 "incdec_operand" "")
5988         (const_string "incdec")
5989         (const_string "alu")))
5990    (set_attr "mode" "SI")])
5991
5992 (define_insn "*addsi_3"
5993   [(set (reg 17)
5994         (compare (neg:SI (match_operand:SI 2 "general_operand" "rmni"))
5995                  (match_operand:SI 1 "nonimmediate_operand" "%0")))
5996    (clobber (match_scratch:SI 0 "=r"))]
5997   "ix86_match_ccmode (insn, CCZmode)
5998    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)
5999    /* Current assemblers are broken and do not allow @GOTOFF in
6000       ought but a memory context.  */
6001    && ! pic_symbolic_operand (operands[2], VOIDmode)"
6002 {
6003   switch (get_attr_type (insn))
6004     {
6005     case TYPE_INCDEC:
6006       if (! rtx_equal_p (operands[0], operands[1]))
6007         abort ();
6008       if (operands[2] == const1_rtx)
6009         return "inc{l}\t%0";
6010       else if (operands[2] == constm1_rtx)
6011         return "dec{l}\t%0";
6012       else
6013         abort();
6014
6015     default:
6016       if (! rtx_equal_p (operands[0], operands[1]))
6017         abort ();
6018       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6019          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6020       if (GET_CODE (operands[2]) == CONST_INT
6021           && (INTVAL (operands[2]) == 128
6022               || (INTVAL (operands[2]) < 0
6023                   && INTVAL (operands[2]) != -128)))
6024         {
6025           operands[2] = GEN_INT (-INTVAL (operands[2]));
6026           return "sub{l}\t{%2, %0|%0, %2}";
6027         }
6028       return "add{l}\t{%2, %0|%0, %2}";
6029     }
6030 }
6031   [(set (attr "type")
6032      (if_then_else (match_operand:SI 2 "incdec_operand" "")
6033         (const_string "incdec")
6034         (const_string "alu")))
6035    (set_attr "mode" "SI")])
6036
6037 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
6038 (define_insn "*addsi_3_zext"
6039   [(set (reg 17)
6040         (compare (neg:SI (match_operand:SI 2 "general_operand" "rmni"))
6041                  (match_operand:SI 1 "nonimmediate_operand" "%0")))
6042    (set (match_operand:DI 0 "register_operand" "=r")
6043         (zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))]
6044   "TARGET_64BIT && ix86_match_ccmode (insn, CCZmode)
6045    && ix86_binary_operator_ok (PLUS, SImode, operands)
6046    /* Current assemblers are broken and do not allow @GOTOFF in
6047       ought but a memory context.  */
6048    && ! pic_symbolic_operand (operands[2], VOIDmode)"
6049 {
6050   switch (get_attr_type (insn))
6051     {
6052     case TYPE_INCDEC:
6053       if (operands[2] == const1_rtx)
6054         return "inc{l}\t%k0";
6055       else if (operands[2] == constm1_rtx)
6056         return "dec{l}\t%k0";
6057       else
6058         abort();
6059
6060     default:
6061       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6062          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6063       if (GET_CODE (operands[2]) == CONST_INT
6064           && (INTVAL (operands[2]) == 128
6065               || (INTVAL (operands[2]) < 0
6066                   && INTVAL (operands[2]) != -128)))
6067         {
6068           operands[2] = GEN_INT (-INTVAL (operands[2]));
6069           return "sub{l}\t{%2, %k0|%k0, %2}";
6070         }
6071       return "add{l}\t{%2, %k0|%k0, %2}";
6072     }
6073 }
6074   [(set (attr "type")
6075      (if_then_else (match_operand:SI 2 "incdec_operand" "")
6076         (const_string "incdec")
6077         (const_string "alu")))
6078    (set_attr "mode" "SI")])
6079
6080 ; For comparisons against 1, -1 and 128, we may generate better code
6081 ; by converting cmp to add, inc or dec as done by peephole2.  This pattern
6082 ; is matched then.  We can't accept general immediate, because for
6083 ; case of overflows,  the result is messed up.
6084 ; This pattern also don't hold of 0x80000000, since the value overflows
6085 ; when negated.
6086 ; Also carry flag is reversed compared to cmp, so this conversion is valid
6087 ; only for comparisons not depending on it.
6088 (define_insn "*addsi_4"
6089   [(set (reg 17)
6090         (compare (match_operand:SI 1 "nonimmediate_operand" "0")
6091                  (match_operand:SI 2 "const_int_operand" "n")))
6092    (clobber (match_scratch:SI 0 "=rm"))]
6093   "ix86_match_ccmode (insn, CCGCmode)
6094    && (INTVAL (operands[2]) & 0xffffffff) != 0x80000000"
6095 {
6096   switch (get_attr_type (insn))
6097     {
6098     case TYPE_INCDEC:
6099       if (operands[2] == constm1_rtx)
6100         return "inc{l}\t%0";
6101       else if (operands[2] == const1_rtx)
6102         return "dec{l}\t%0";
6103       else
6104         abort();
6105
6106     default:
6107       if (! rtx_equal_p (operands[0], operands[1]))
6108         abort ();
6109       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6110          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6111       if ((INTVAL (operands[2]) == -128
6112            || (INTVAL (operands[2]) > 0
6113                && INTVAL (operands[2]) != 128)))
6114         return "sub{l}\t{%2, %0|%0, %2}";
6115       operands[2] = GEN_INT (-INTVAL (operands[2]));
6116       return "add{l}\t{%2, %0|%0, %2}";
6117     }
6118 }
6119   [(set (attr "type")
6120      (if_then_else (match_operand:SI 2 "incdec_operand" "")
6121         (const_string "incdec")
6122         (const_string "alu")))
6123    (set_attr "mode" "SI")])
6124
6125 (define_insn "*addsi_5"
6126   [(set (reg 17)
6127         (compare
6128           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
6129                    (match_operand:SI 2 "general_operand" "rmni"))
6130           (const_int 0)))                       
6131    (clobber (match_scratch:SI 0 "=r"))]
6132   "ix86_match_ccmode (insn, CCGOCmode)
6133    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)
6134    /* Current assemblers are broken and do not allow @GOTOFF in
6135       ought but a memory context.  */
6136    && ! pic_symbolic_operand (operands[2], VOIDmode)"
6137 {
6138   switch (get_attr_type (insn))
6139     {
6140     case TYPE_INCDEC:
6141       if (! rtx_equal_p (operands[0], operands[1]))
6142         abort ();
6143       if (operands[2] == const1_rtx)
6144         return "inc{l}\t%0";
6145       else if (operands[2] == constm1_rtx)
6146         return "dec{l}\t%0";
6147       else
6148         abort();
6149
6150     default:
6151       if (! rtx_equal_p (operands[0], operands[1]))
6152         abort ();
6153       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6154          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6155       if (GET_CODE (operands[2]) == CONST_INT
6156           && (INTVAL (operands[2]) == 128
6157               || (INTVAL (operands[2]) < 0
6158                   && INTVAL (operands[2]) != -128)))
6159         {
6160           operands[2] = GEN_INT (-INTVAL (operands[2]));
6161           return "sub{l}\t{%2, %0|%0, %2}";
6162         }
6163       return "add{l}\t{%2, %0|%0, %2}";
6164     }
6165 }
6166   [(set (attr "type")
6167      (if_then_else (match_operand:SI 2 "incdec_operand" "")
6168         (const_string "incdec")
6169         (const_string "alu")))
6170    (set_attr "mode" "SI")])
6171
6172 (define_expand "addhi3"
6173   [(parallel [(set (match_operand:HI 0 "nonimmediate_operand" "")
6174                    (plus:HI (match_operand:HI 1 "nonimmediate_operand" "")
6175                             (match_operand:HI 2 "general_operand" "")))
6176               (clobber (reg:CC 17))])]
6177   "TARGET_HIMODE_MATH"
6178   "ix86_expand_binary_operator (PLUS, HImode, operands); DONE;")
6179
6180 ;; %%% After Dave's SUBREG_BYTE stuff goes in, re-enable incb %ah
6181 ;; type optimizations enabled by define-splits.  This is not important
6182 ;; for PII, and in fact harmful because of partial register stalls.
6183
6184 (define_insn "*addhi_1_lea"
6185   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r,r")
6186         (plus:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,r")
6187                  (match_operand:HI 2 "general_operand" "ri,rm,rni")))
6188    (clobber (reg:CC 17))]
6189   "!TARGET_PARTIAL_REG_STALL
6190    && ix86_binary_operator_ok (PLUS, HImode, operands)"
6191 {
6192   switch (get_attr_type (insn))
6193     {
6194     case TYPE_LEA:
6195       return "#";
6196     case TYPE_INCDEC:
6197       if (operands[2] == const1_rtx)
6198         return "inc{w}\t%0";
6199       else if (operands[2] == constm1_rtx)
6200         return "dec{w}\t%0";
6201       abort();
6202
6203     default:
6204       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6205          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6206       if (GET_CODE (operands[2]) == CONST_INT
6207           && (INTVAL (operands[2]) == 128
6208               || (INTVAL (operands[2]) < 0
6209                   && INTVAL (operands[2]) != -128)))
6210         {
6211           operands[2] = GEN_INT (-INTVAL (operands[2]));
6212           return "sub{w}\t{%2, %0|%0, %2}";
6213         }
6214       return "add{w}\t{%2, %0|%0, %2}";
6215     }
6216 }
6217   [(set (attr "type")
6218      (if_then_else (eq_attr "alternative" "2")
6219         (const_string "lea")
6220         (if_then_else (match_operand:HI 2 "incdec_operand" "")
6221            (const_string "incdec")
6222            (const_string "alu"))))
6223    (set_attr "mode" "HI,HI,SI")])
6224
6225 (define_insn "*addhi_1"
6226   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r")
6227         (plus:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
6228                  (match_operand:HI 2 "general_operand" "ri,rm")))
6229    (clobber (reg:CC 17))]
6230   "TARGET_PARTIAL_REG_STALL
6231    && ix86_binary_operator_ok (PLUS, HImode, operands)"
6232 {
6233   switch (get_attr_type (insn))
6234     {
6235     case TYPE_INCDEC:
6236       if (operands[2] == const1_rtx)
6237         return "inc{w}\t%0";
6238       else if (operands[2] == constm1_rtx)
6239         return "dec{w}\t%0";
6240       abort();
6241
6242     default:
6243       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6244          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6245       if (GET_CODE (operands[2]) == CONST_INT
6246           && (INTVAL (operands[2]) == 128
6247               || (INTVAL (operands[2]) < 0
6248                   && INTVAL (operands[2]) != -128)))
6249         {
6250           operands[2] = GEN_INT (-INTVAL (operands[2]));
6251           return "sub{w}\t{%2, %0|%0, %2}";
6252         }
6253       return "add{w}\t{%2, %0|%0, %2}";
6254     }
6255 }
6256   [(set (attr "type")
6257      (if_then_else (match_operand:HI 2 "incdec_operand" "")
6258         (const_string "incdec")
6259         (const_string "alu")))
6260    (set_attr "mode" "HI")])
6261
6262 (define_insn "*addhi_2"
6263   [(set (reg 17)
6264         (compare
6265           (plus:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
6266                    (match_operand:HI 2 "general_operand" "rmni,rni"))
6267           (const_int 0)))                       
6268    (set (match_operand:HI 0 "nonimmediate_operand" "=r,rm")
6269         (plus:HI (match_dup 1) (match_dup 2)))]
6270   "ix86_match_ccmode (insn, CCGOCmode)
6271    && ix86_binary_operator_ok (PLUS, HImode, operands)"
6272 {
6273   switch (get_attr_type (insn))
6274     {
6275     case TYPE_INCDEC:
6276       if (operands[2] == const1_rtx)
6277         return "inc{w}\t%0";
6278       else if (operands[2] == constm1_rtx)
6279         return "dec{w}\t%0";
6280       abort();
6281
6282     default:
6283       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6284          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6285       if (GET_CODE (operands[2]) == CONST_INT
6286           && (INTVAL (operands[2]) == 128
6287               || (INTVAL (operands[2]) < 0
6288                   && INTVAL (operands[2]) != -128)))
6289         {
6290           operands[2] = GEN_INT (-INTVAL (operands[2]));
6291           return "sub{w}\t{%2, %0|%0, %2}";
6292         }
6293       return "add{w}\t{%2, %0|%0, %2}";
6294     }
6295 }
6296   [(set (attr "type")
6297      (if_then_else (match_operand:HI 2 "incdec_operand" "")
6298         (const_string "incdec")
6299         (const_string "alu")))
6300    (set_attr "mode" "HI")])
6301
6302 (define_insn "*addhi_3"
6303   [(set (reg 17)
6304         (compare (neg:HI (match_operand:HI 2 "general_operand" "rmni"))
6305                  (match_operand:HI 1 "nonimmediate_operand" "%0")))
6306    (clobber (match_scratch:HI 0 "=r"))]
6307   "ix86_match_ccmode (insn, CCZmode)
6308    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
6309 {
6310   switch (get_attr_type (insn))
6311     {
6312     case TYPE_INCDEC:
6313       if (operands[2] == const1_rtx)
6314         return "inc{w}\t%0";
6315       else if (operands[2] == constm1_rtx)
6316         return "dec{w}\t%0";
6317       abort();
6318
6319     default:
6320       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6321          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6322       if (GET_CODE (operands[2]) == CONST_INT
6323           && (INTVAL (operands[2]) == 128
6324               || (INTVAL (operands[2]) < 0
6325                   && INTVAL (operands[2]) != -128)))
6326         {
6327           operands[2] = GEN_INT (-INTVAL (operands[2]));
6328           return "sub{w}\t{%2, %0|%0, %2}";
6329         }
6330       return "add{w}\t{%2, %0|%0, %2}";
6331     }
6332 }
6333   [(set (attr "type")
6334      (if_then_else (match_operand:HI 2 "incdec_operand" "")
6335         (const_string "incdec")
6336         (const_string "alu")))
6337    (set_attr "mode" "HI")])
6338
6339 ; See comments above addsi_3_imm for details.
6340 (define_insn "*addhi_4"
6341   [(set (reg 17)
6342         (compare (match_operand:HI 1 "nonimmediate_operand" "0")
6343                  (match_operand:HI 2 "const_int_operand" "n")))
6344    (clobber (match_scratch:HI 0 "=rm"))]
6345   "ix86_match_ccmode (insn, CCGCmode)
6346    && (INTVAL (operands[2]) & 0xffff) != 0x8000"
6347 {
6348   switch (get_attr_type (insn))
6349     {
6350     case TYPE_INCDEC:
6351       if (operands[2] == constm1_rtx)
6352         return "inc{w}\t%0";
6353       else if (operands[2] == const1_rtx)
6354         return "dec{w}\t%0";
6355       else
6356         abort();
6357
6358     default:
6359       if (! rtx_equal_p (operands[0], operands[1]))
6360         abort ();
6361       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6362          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6363       if ((INTVAL (operands[2]) == -128
6364            || (INTVAL (operands[2]) > 0
6365                && INTVAL (operands[2]) != 128)))
6366         return "sub{w}\t{%2, %0|%0, %2}";
6367       operands[2] = GEN_INT (-INTVAL (operands[2]));
6368       return "add{w}\t{%2, %0|%0, %2}";
6369     }
6370 }
6371   [(set (attr "type")
6372      (if_then_else (match_operand:HI 2 "incdec_operand" "")
6373         (const_string "incdec")
6374         (const_string "alu")))
6375    (set_attr "mode" "SI")])
6376
6377
6378 (define_insn "*addhi_5"
6379   [(set (reg 17)
6380         (compare
6381           (plus:HI (match_operand:HI 1 "nonimmediate_operand" "%0")
6382                    (match_operand:HI 2 "general_operand" "rmni"))
6383           (const_int 0)))                       
6384    (clobber (match_scratch:HI 0 "=r"))]
6385   "ix86_match_ccmode (insn, CCGOCmode)
6386    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
6387 {
6388   switch (get_attr_type (insn))
6389     {
6390     case TYPE_INCDEC:
6391       if (operands[2] == const1_rtx)
6392         return "inc{w}\t%0";
6393       else if (operands[2] == constm1_rtx)
6394         return "dec{w}\t%0";
6395       abort();
6396
6397     default:
6398       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6399          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6400       if (GET_CODE (operands[2]) == CONST_INT
6401           && (INTVAL (operands[2]) == 128
6402               || (INTVAL (operands[2]) < 0
6403                   && INTVAL (operands[2]) != -128)))
6404         {
6405           operands[2] = GEN_INT (-INTVAL (operands[2]));
6406           return "sub{w}\t{%2, %0|%0, %2}";
6407         }
6408       return "add{w}\t{%2, %0|%0, %2}";
6409     }
6410 }
6411   [(set (attr "type")
6412      (if_then_else (match_operand:HI 2 "incdec_operand" "")
6413         (const_string "incdec")
6414         (const_string "alu")))
6415    (set_attr "mode" "HI")])
6416
6417 (define_expand "addqi3"
6418   [(parallel [(set (match_operand:QI 0 "nonimmediate_operand" "")
6419                    (plus:QI (match_operand:QI 1 "nonimmediate_operand" "")
6420                             (match_operand:QI 2 "general_operand" "")))
6421               (clobber (reg:CC 17))])]
6422   "TARGET_QIMODE_MATH"
6423   "ix86_expand_binary_operator (PLUS, QImode, operands); DONE;")
6424
6425 ;; %%% Potential partial reg stall on alternative 2.  What to do?
6426 (define_insn "*addqi_1_lea"
6427   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,q,r,r")
6428         (plus:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0,r")
6429                  (match_operand:QI 2 "general_operand" "qn,qmn,rn,rn")))
6430    (clobber (reg:CC 17))]
6431   "!TARGET_PARTIAL_REG_STALL
6432    && ix86_binary_operator_ok (PLUS, QImode, operands)"
6433 {
6434   int widen = (which_alternative == 2);
6435   switch (get_attr_type (insn))
6436     {
6437     case TYPE_LEA:
6438       return "#";
6439     case TYPE_INCDEC:
6440       if (operands[2] == const1_rtx)
6441         return widen ? "inc{l}\t%k0" : "inc{b}\t%0";
6442       else if (operands[2] == constm1_rtx)
6443         return widen ? "dec{l}\t%k0" : "dec{b}\t%0";
6444       abort();
6445
6446     default:
6447       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6448          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6449       if (GET_CODE (operands[2]) == CONST_INT
6450           && (INTVAL (operands[2]) == 128
6451               || (INTVAL (operands[2]) < 0
6452                   && INTVAL (operands[2]) != -128)))
6453         {
6454           operands[2] = GEN_INT (-INTVAL (operands[2]));
6455           if (widen)
6456             return "sub{l}\t{%2, %k0|%k0, %2}";
6457           else
6458             return "sub{b}\t{%2, %0|%0, %2}";
6459         }
6460       if (widen)
6461         return "add{l}\t{%k2, %k0|%k0, %k2}";
6462       else
6463         return "add{b}\t{%2, %0|%0, %2}";
6464     }
6465 }
6466   [(set (attr "type")
6467      (if_then_else (eq_attr "alternative" "3")
6468         (const_string "lea")
6469         (if_then_else (match_operand:QI 2 "incdec_operand" "")
6470            (const_string "incdec")
6471            (const_string "alu"))))
6472    (set_attr "mode" "QI,QI,SI,SI")])
6473
6474 (define_insn "*addqi_1"
6475   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,q,r")
6476         (plus:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
6477                  (match_operand:QI 2 "general_operand" "qn,qmn,rn")))
6478    (clobber (reg:CC 17))]
6479   "TARGET_PARTIAL_REG_STALL
6480    && ix86_binary_operator_ok (PLUS, QImode, operands)"
6481 {
6482   int widen = (which_alternative == 2);
6483   switch (get_attr_type (insn))
6484     {
6485     case TYPE_INCDEC:
6486       if (operands[2] == const1_rtx)
6487         return widen ? "inc{l}\t%k0" : "inc{b}\t%0";
6488       else if (operands[2] == constm1_rtx)
6489         return widen ? "dec{l}\t%k0" : "dec{b}\t%0";
6490       abort();
6491
6492     default:
6493       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6494          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6495       if (GET_CODE (operands[2]) == CONST_INT
6496           && (INTVAL (operands[2]) == 128
6497               || (INTVAL (operands[2]) < 0
6498                   && INTVAL (operands[2]) != -128)))
6499         {
6500           operands[2] = GEN_INT (-INTVAL (operands[2]));
6501           if (widen)
6502             return "sub{l}\t{%2, %k0|%k0, %2}";
6503           else
6504             return "sub{b}\t{%2, %0|%0, %2}";
6505         }
6506       if (widen)
6507         return "add{l}\t{%k2, %k0|%k0, %k2}";
6508       else
6509         return "add{b}\t{%2, %0|%0, %2}";
6510     }
6511 }
6512   [(set (attr "type")
6513      (if_then_else (match_operand:QI 2 "incdec_operand" "")
6514         (const_string "incdec")
6515         (const_string "alu")))
6516    (set_attr "mode" "QI,QI,SI")])
6517
6518 (define_insn "*addqi_1_slp"
6519   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
6520         (plus:QI (match_dup 0)
6521                  (match_operand:QI 1 "general_operand" "qn,qnm")))
6522    (clobber (reg:CC 17))]
6523   "(! TARGET_PARTIAL_REG_STALL || optimize_size)
6524    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
6525 {
6526   switch (get_attr_type (insn))
6527     {
6528     case TYPE_INCDEC:
6529       if (operands[1] == const1_rtx)
6530         return "inc{b}\t%0";
6531       else if (operands[1] == constm1_rtx)
6532         return "dec{b}\t%0";
6533       abort();
6534
6535     default:
6536       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.  */
6537       if (GET_CODE (operands[1]) == CONST_INT
6538           && INTVAL (operands[1]) < 0)
6539         {
6540           operands[2] = GEN_INT (-INTVAL (operands[2]));
6541           return "sub{b}\t{%1, %0|%0, %1}";
6542         }
6543       return "add{b}\t{%1, %0|%0, %1}";
6544     }
6545 }
6546   [(set (attr "type")
6547      (if_then_else (match_operand:QI 2 "incdec_operand" "")
6548         (const_string "incdec")
6549         (const_string "alu1")))
6550    (set_attr "mode" "QI")])
6551
6552 (define_insn "*addqi_2"
6553   [(set (reg 17)
6554         (compare
6555           (plus:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0")
6556                    (match_operand:QI 2 "general_operand" "qmni,qni"))
6557           (const_int 0)))
6558    (set (match_operand:QI 0 "nonimmediate_operand" "=q,qm")
6559         (plus:QI (match_dup 1) (match_dup 2)))]
6560   "ix86_match_ccmode (insn, CCGOCmode)
6561    && ix86_binary_operator_ok (PLUS, QImode, operands)"
6562 {
6563   switch (get_attr_type (insn))
6564     {
6565     case TYPE_INCDEC:
6566       if (operands[2] == const1_rtx)
6567         return "inc{b}\t%0";
6568       else if (operands[2] == constm1_rtx
6569                || (GET_CODE (operands[2]) == CONST_INT
6570                    && INTVAL (operands[2]) == 255))
6571         return "dec{b}\t%0";
6572       abort();
6573
6574     default:
6575       /* Make things pretty and `subb $4,%al' rather than `addb $-4, %al'.  */
6576       if (GET_CODE (operands[2]) == CONST_INT
6577           && INTVAL (operands[2]) < 0)
6578         {
6579           operands[2] = GEN_INT (-INTVAL (operands[2]));
6580           return "sub{b}\t{%2, %0|%0, %2}";
6581         }
6582       return "add{b}\t{%2, %0|%0, %2}";
6583     }
6584 }
6585   [(set (attr "type")
6586      (if_then_else (match_operand:QI 2 "incdec_operand" "")
6587         (const_string "incdec")
6588         (const_string "alu")))
6589    (set_attr "mode" "QI")])
6590
6591 (define_insn "*addqi_3"
6592   [(set (reg 17)
6593         (compare (neg:QI (match_operand:QI 2 "general_operand" "qmni"))
6594                  (match_operand:QI 1 "nonimmediate_operand" "%0")))
6595    (clobber (match_scratch:QI 0 "=q"))]
6596   "ix86_match_ccmode (insn, CCZmode)
6597    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
6598 {
6599   switch (get_attr_type (insn))
6600     {
6601     case TYPE_INCDEC:
6602       if (operands[2] == const1_rtx)
6603         return "inc{b}\t%0";
6604       else if (operands[2] == constm1_rtx
6605                || (GET_CODE (operands[2]) == CONST_INT
6606                    && INTVAL (operands[2]) == 255))
6607         return "dec{b}\t%0";
6608       abort();
6609
6610     default:
6611       /* Make things pretty and `subb $4,%al' rather than `addb $-4, %al'.  */
6612       if (GET_CODE (operands[2]) == CONST_INT
6613           && INTVAL (operands[2]) < 0)
6614         {
6615           operands[2] = GEN_INT (-INTVAL (operands[2]));
6616           return "sub{b}\t{%2, %0|%0, %2}";
6617         }
6618       return "add{b}\t{%2, %0|%0, %2}";
6619     }
6620 }
6621   [(set (attr "type")
6622      (if_then_else (match_operand:QI 2 "incdec_operand" "")
6623         (const_string "incdec")
6624         (const_string "alu")))
6625    (set_attr "mode" "QI")])
6626
6627 ; See comments above addsi_3_imm for details.
6628 (define_insn "*addqi_4"
6629   [(set (reg 17)
6630         (compare (match_operand:QI 1 "nonimmediate_operand" "0")
6631                  (match_operand:QI 2 "const_int_operand" "n")))
6632    (clobber (match_scratch:QI 0 "=qm"))]
6633   "ix86_match_ccmode (insn, CCGCmode)
6634    && (INTVAL (operands[2]) & 0xff) != 0x80"
6635 {
6636   switch (get_attr_type (insn))
6637     {
6638     case TYPE_INCDEC:
6639       if (operands[2] == constm1_rtx
6640           || (GET_CODE (operands[2]) == CONST_INT
6641               && INTVAL (operands[2]) == 255))
6642         return "inc{b}\t%0";
6643       else if (operands[2] == const1_rtx)
6644         return "dec{b}\t%0";
6645       else
6646         abort();
6647
6648     default:
6649       if (! rtx_equal_p (operands[0], operands[1]))
6650         abort ();
6651       if (INTVAL (operands[2]) < 0)
6652         {
6653           operands[2] = GEN_INT (-INTVAL (operands[2]));
6654           return "add{b}\t{%2, %0|%0, %2}";
6655         }
6656       return "sub{b}\t{%2, %0|%0, %2}";
6657     }
6658 }
6659   [(set (attr "type")
6660      (if_then_else (match_operand:HI 2 "incdec_operand" "")
6661         (const_string "incdec")
6662         (const_string "alu")))
6663    (set_attr "mode" "QI")])
6664
6665
6666 (define_insn "*addqi_5"
6667   [(set (reg 17)
6668         (compare
6669           (plus:QI (match_operand:QI 1 "nonimmediate_operand" "%0")
6670                    (match_operand:QI 2 "general_operand" "qmni"))
6671           (const_int 0)))
6672    (clobber (match_scratch:QI 0 "=q"))]
6673   "ix86_match_ccmode (insn, CCGOCmode)
6674    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
6675 {
6676   switch (get_attr_type (insn))
6677     {
6678     case TYPE_INCDEC:
6679       if (operands[2] == const1_rtx)
6680         return "inc{b}\t%0";
6681       else if (operands[2] == constm1_rtx
6682                || (GET_CODE (operands[2]) == CONST_INT
6683                    && INTVAL (operands[2]) == 255))
6684         return "dec{b}\t%0";
6685       abort();
6686
6687     default:
6688       /* Make things pretty and `subb $4,%al' rather than `addb $-4, %al'.  */
6689       if (GET_CODE (operands[2]) == CONST_INT
6690           && INTVAL (operands[2]) < 0)
6691         {
6692           operands[2] = GEN_INT (-INTVAL (operands[2]));
6693           return "sub{b}\t{%2, %0|%0, %2}";
6694         }
6695       return "add{b}\t{%2, %0|%0, %2}";
6696     }
6697 }
6698   [(set (attr "type")
6699      (if_then_else (match_operand:QI 2 "incdec_operand" "")
6700         (const_string "incdec")
6701         (const_string "alu")))
6702    (set_attr "mode" "QI")])
6703
6704
6705 (define_insn "addqi_ext_1"
6706   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
6707                          (const_int 8)
6708                          (const_int 8))
6709         (plus:SI
6710           (zero_extract:SI
6711             (match_operand 1 "ext_register_operand" "0")
6712             (const_int 8)
6713             (const_int 8))
6714           (match_operand:QI 2 "general_operand" "Qmn")))
6715    (clobber (reg:CC 17))]
6716   "!TARGET_64BIT"
6717 {
6718   switch (get_attr_type (insn))
6719     {
6720     case TYPE_INCDEC:
6721       if (operands[2] == const1_rtx)
6722         return "inc{b}\t%h0";
6723       else if (operands[2] == constm1_rtx
6724                || (GET_CODE (operands[2]) == CONST_INT
6725                    && INTVAL (operands[2]) == 255))
6726         return "dec{b}\t%h0";
6727       abort();
6728
6729     default:
6730       return "add{b}\t{%2, %h0|%h0, %2}";
6731     }
6732 }
6733   [(set (attr "type")
6734      (if_then_else (match_operand:QI 2 "incdec_operand" "")
6735         (const_string "incdec")
6736         (const_string "alu")))
6737    (set_attr "mode" "QI")])
6738
6739 (define_insn "*addqi_ext_1_rex64"
6740   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
6741                          (const_int 8)
6742                          (const_int 8))
6743         (plus:SI
6744           (zero_extract:SI
6745             (match_operand 1 "ext_register_operand" "0")
6746             (const_int 8)
6747             (const_int 8))
6748           (match_operand:QI 2 "nonmemory_operand" "Qn")))
6749    (clobber (reg:CC 17))]
6750   "TARGET_64BIT"
6751 {
6752   switch (get_attr_type (insn))
6753     {
6754     case TYPE_INCDEC:
6755       if (operands[2] == const1_rtx)
6756         return "inc{b}\t%h0";
6757       else if (operands[2] == constm1_rtx
6758                || (GET_CODE (operands[2]) == CONST_INT
6759                    && INTVAL (operands[2]) == 255))
6760         return "dec{b}\t%h0";
6761       abort();
6762
6763     default:
6764       return "add{b}\t{%2, %h0|%h0, %2}";
6765     }
6766 }
6767   [(set (attr "type")
6768      (if_then_else (match_operand:QI 2 "incdec_operand" "")
6769         (const_string "incdec")
6770         (const_string "alu")))
6771    (set_attr "mode" "QI")])
6772
6773 (define_insn "*addqi_ext_2"
6774   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
6775                          (const_int 8)
6776                          (const_int 8))
6777         (plus:SI
6778           (zero_extract:SI
6779             (match_operand 1 "ext_register_operand" "%0")
6780             (const_int 8)
6781             (const_int 8))
6782           (zero_extract:SI
6783             (match_operand 2 "ext_register_operand" "Q")
6784             (const_int 8)
6785             (const_int 8))))
6786    (clobber (reg:CC 17))]
6787   ""
6788   "add{b}\t{%h2, %h0|%h0, %h2}"
6789   [(set_attr "type" "alu")
6790    (set_attr "mode" "QI")])
6791
6792 ;; The patterns that match these are at the end of this file.
6793
6794 (define_expand "addxf3"
6795   [(set (match_operand:XF 0 "register_operand" "")
6796         (plus:XF (match_operand:XF 1 "register_operand" "")
6797                  (match_operand:XF 2 "register_operand" "")))]
6798   "!TARGET_64BIT && TARGET_80387"
6799   "")
6800
6801 (define_expand "addtf3"
6802   [(set (match_operand:TF 0 "register_operand" "")
6803         (plus:TF (match_operand:TF 1 "register_operand" "")
6804                  (match_operand:TF 2 "register_operand" "")))]
6805   "TARGET_80387"
6806   "")
6807
6808 (define_expand "adddf3"
6809   [(set (match_operand:DF 0 "register_operand" "")
6810         (plus:DF (match_operand:DF 1 "register_operand" "")
6811                  (match_operand:DF 2 "nonimmediate_operand" "")))]
6812   "TARGET_80387 || (TARGET_SSE2 && TARGET_SSE_MATH)"
6813   "")
6814
6815 (define_expand "addsf3"
6816   [(set (match_operand:SF 0 "register_operand" "")
6817         (plus:SF (match_operand:SF 1 "register_operand" "")
6818                  (match_operand:SF 2 "nonimmediate_operand" "")))]
6819   "TARGET_80387 || TARGET_SSE_MATH"
6820   "")
6821 \f
6822 ;; Subtract instructions
6823
6824 ;; %%% splits for subsidi3
6825
6826 (define_expand "subdi3"
6827   [(parallel [(set (match_operand:DI 0 "nonimmediate_operand" "")
6828                    (minus:DI (match_operand:DI 1 "nonimmediate_operand" "")
6829                              (match_operand:DI 2 "x86_64_general_operand" "")))
6830               (clobber (reg:CC 17))])]
6831   ""
6832   "ix86_expand_binary_operator (MINUS, DImode, operands); DONE;")
6833
6834 (define_insn "*subdi3_1"
6835   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,o")
6836         (minus:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
6837                   (match_operand:DI 2 "general_operand" "roiF,riF")))
6838    (clobber (reg:CC 17))]
6839   "!TARGET_64BIT && ix86_binary_operator_ok (MINUS, DImode, operands)"
6840   "#")
6841
6842 (define_split
6843   [(set (match_operand:DI 0 "nonimmediate_operand" "")
6844         (minus:DI (match_operand:DI 1 "nonimmediate_operand" "")
6845                   (match_operand:DI 2 "general_operand" "")))
6846    (clobber (reg:CC 17))]
6847   "!TARGET_64BIT && reload_completed"
6848   [(parallel [(set (reg:CC 17) (compare:CC (match_dup 1) (match_dup 2)))
6849               (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 2)))])
6850    (parallel [(set (match_dup 3)
6851                    (minus:SI (match_dup 4)
6852                              (plus:SI (ltu:SI (reg:CC 17) (const_int 0))
6853                                       (match_dup 5))))
6854               (clobber (reg:CC 17))])]
6855   "split_di (operands+0, 1, operands+0, operands+3);
6856    split_di (operands+1, 1, operands+1, operands+4);
6857    split_di (operands+2, 1, operands+2, operands+5);")
6858
6859 (define_insn "subdi3_carry_rex64"
6860   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
6861           (minus:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
6862             (plus:DI (match_operand:DI 3 "ix86_carry_flag_operator" "")
6863                (match_operand:DI 2 "x86_64_general_operand" "re,rm"))))
6864    (clobber (reg:CC 17))]
6865   "TARGET_64BIT && ix86_binary_operator_ok (MINUS, DImode, operands)"
6866   "sbb{q}\t{%2, %0|%0, %2}"
6867   [(set_attr "type" "alu")
6868    (set_attr "pent_pair" "pu")
6869    (set_attr "ppro_uops" "few")
6870    (set_attr "mode" "DI")])
6871
6872 (define_insn "*subdi_1_rex64"
6873   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
6874         (minus:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
6875                   (match_operand:DI 2 "x86_64_general_operand" "re,rm")))
6876    (clobber (reg:CC 17))]
6877   "TARGET_64BIT && ix86_binary_operator_ok (MINUS, DImode, operands)"
6878   "sub{q}\t{%2, %0|%0, %2}"
6879   [(set_attr "type" "alu")
6880    (set_attr "mode" "DI")])
6881
6882 (define_insn "*subdi_2_rex64"
6883   [(set (reg 17)
6884         (compare
6885           (minus:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
6886                     (match_operand:DI 2 "x86_64_general_operand" "re,rm"))
6887           (const_int 0)))
6888    (set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
6889         (minus:DI (match_dup 1) (match_dup 2)))]
6890   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
6891    && ix86_binary_operator_ok (MINUS, DImode, operands)"
6892   "sub{q}\t{%2, %0|%0, %2}"
6893   [(set_attr "type" "alu")
6894    (set_attr "mode" "DI")])
6895
6896 (define_insn "*subdi_3_rex63"
6897   [(set (reg 17)
6898         (compare (match_operand:DI 1 "nonimmediate_operand" "0,0")
6899                  (match_operand:DI 2 "x86_64_general_operand" "re,rm")))
6900    (set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
6901         (minus:DI (match_dup 1) (match_dup 2)))]
6902   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)
6903    && ix86_binary_operator_ok (MINUS, SImode, operands)"
6904   "sub{q}\t{%2, %0|%0, %2}"
6905   [(set_attr "type" "alu")
6906    (set_attr "mode" "DI")])
6907
6908 (define_insn "subqi3_carry"
6909   [(set (match_operand:QI 0 "nonimmediate_operand" "=rm,r")
6910           (minus:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
6911             (plus:QI (match_operand:QI 3 "ix86_carry_flag_operator" "")
6912                (match_operand:QI 2 "general_operand" "ri,rm"))))
6913    (clobber (reg:CC 17))]
6914   "ix86_binary_operator_ok (MINUS, QImode, operands)"
6915   "sbb{b}\t{%2, %0|%0, %2}"
6916   [(set_attr "type" "alu")
6917    (set_attr "pent_pair" "pu")
6918    (set_attr "ppro_uops" "few")
6919    (set_attr "mode" "QI")])
6920
6921 (define_insn "subhi3_carry"
6922   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r")
6923           (minus:HI (match_operand:HI 1 "nonimmediate_operand" "0,0")
6924             (plus:HI (match_operand:HI 3 "ix86_carry_flag_operator" "")
6925                (match_operand:HI 2 "general_operand" "ri,rm"))))
6926    (clobber (reg:CC 17))]
6927   "ix86_binary_operator_ok (MINUS, HImode, operands)"
6928   "sbb{w}\t{%2, %0|%0, %2}"
6929   [(set_attr "type" "alu")
6930    (set_attr "pent_pair" "pu")
6931    (set_attr "ppro_uops" "few")
6932    (set_attr "mode" "HI")])
6933
6934 (define_insn "subsi3_carry"
6935   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
6936           (minus:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
6937             (plus:SI (match_operand:SI 3 "ix86_carry_flag_operator" "")
6938                (match_operand:SI 2 "general_operand" "ri,rm"))))
6939    (clobber (reg:CC 17))]
6940   "ix86_binary_operator_ok (MINUS, SImode, operands)"
6941   "sbb{l}\t{%2, %0|%0, %2}"
6942   [(set_attr "type" "alu")
6943    (set_attr "pent_pair" "pu")
6944    (set_attr "ppro_uops" "few")
6945    (set_attr "mode" "SI")])
6946
6947 (define_insn "subsi3_carry_zext"
6948   [(set (match_operand:DI 0 "register_operand" "=rm,r")
6949           (zero_extend:DI
6950             (minus:SI (match_operand:SI 1 "register_operand" "0,0")
6951               (plus:SI (match_operand:SI 3 "ix86_carry_flag_operator" "")
6952                  (match_operand:SI 2 "general_operand" "ri,rm")))))
6953    (clobber (reg:CC 17))]
6954   "TARGET_64BIT && ix86_binary_operator_ok (MINUS, SImode, operands)"
6955   "sbb{l}\t{%2, %k0|%k0, %2}"
6956   [(set_attr "type" "alu")
6957    (set_attr "pent_pair" "pu")
6958    (set_attr "ppro_uops" "few")
6959    (set_attr "mode" "SI")])
6960
6961 (define_expand "subsi3"
6962   [(parallel [(set (match_operand:SI 0 "nonimmediate_operand" "")
6963                    (minus:SI (match_operand:SI 1 "nonimmediate_operand" "")
6964                              (match_operand:SI 2 "general_operand" "")))
6965               (clobber (reg:CC 17))])]
6966   ""
6967   "ix86_expand_binary_operator (MINUS, SImode, operands); DONE;")
6968
6969 (define_insn "*subsi_1"
6970   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
6971         (minus:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
6972                   (match_operand:SI 2 "general_operand" "ri,rm")))
6973    (clobber (reg:CC 17))]
6974   "ix86_binary_operator_ok (MINUS, SImode, operands)"
6975   "sub{l}\t{%2, %0|%0, %2}"
6976   [(set_attr "type" "alu")
6977    (set_attr "mode" "SI")])
6978
6979 (define_insn "*subsi_1_zext"
6980   [(set (match_operand:DI 0 "register_operand" "=r")
6981         (zero_extend:DI
6982           (minus:SI (match_operand:SI 1 "register_operand" "0")
6983                     (match_operand:SI 2 "general_operand" "rim"))))
6984    (clobber (reg:CC 17))]
6985   "TARGET_64BIT && ix86_binary_operator_ok (MINUS, SImode, operands)"
6986   "sub{l}\t{%2, %k0|%k0, %2}"
6987   [(set_attr "type" "alu")
6988    (set_attr "mode" "SI")])
6989
6990 (define_insn "*subsi_2"
6991   [(set (reg 17)
6992         (compare
6993           (minus:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
6994                     (match_operand:SI 2 "general_operand" "ri,rm"))
6995           (const_int 0)))
6996    (set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
6997         (minus:SI (match_dup 1) (match_dup 2)))]
6998   "ix86_match_ccmode (insn, CCGOCmode)
6999    && ix86_binary_operator_ok (MINUS, SImode, operands)"
7000   "sub{l}\t{%2, %0|%0, %2}"
7001   [(set_attr "type" "alu")
7002    (set_attr "mode" "SI")])
7003
7004 (define_insn "*subsi_2_zext"
7005   [(set (reg 17)
7006         (compare
7007           (minus:SI (match_operand:SI 1 "register_operand" "0")
7008                     (match_operand:SI 2 "general_operand" "rim"))
7009           (const_int 0)))
7010    (set (match_operand:DI 0 "register_operand" "=r")
7011         (zero_extend:DI
7012           (minus:SI (match_dup 1)
7013                     (match_dup 2))))]
7014   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
7015    && ix86_binary_operator_ok (MINUS, SImode, operands)"
7016   "sub{l}\t{%2, %k0|%k0, %2}"
7017   [(set_attr "type" "alu")
7018    (set_attr "mode" "SI")])
7019
7020 (define_insn "*subsi_3"
7021   [(set (reg 17)
7022         (compare (match_operand:SI 1 "nonimmediate_operand" "0,0")
7023                  (match_operand:SI 2 "general_operand" "ri,rm")))
7024    (set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
7025         (minus:SI (match_dup 1) (match_dup 2)))]
7026   "ix86_match_ccmode (insn, CCmode)
7027    && ix86_binary_operator_ok (MINUS, SImode, operands)"
7028   "sub{l}\t{%2, %0|%0, %2}"
7029   [(set_attr "type" "alu")
7030    (set_attr "mode" "SI")])
7031
7032 (define_insn "*subsi_3_zext"
7033   [(set (reg 17)
7034         (compare (match_operand:SI 1 "nonimmediate_operand" "0")
7035                  (match_operand:SI 2 "general_operand" "rim")))
7036    (set (match_operand:DI 0 "register_operand" "=r")
7037         (zero_extend:DI
7038           (minus:SI (match_dup 1)
7039                     (match_dup 2))))]
7040   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)
7041    && ix86_binary_operator_ok (MINUS, SImode, operands)"
7042   "sub{q}\t{%2, %0|%0, %2}"
7043   [(set_attr "type" "alu")
7044    (set_attr "mode" "DI")])
7045
7046 (define_expand "subhi3"
7047   [(parallel [(set (match_operand:HI 0 "nonimmediate_operand" "")
7048                    (minus:HI (match_operand:HI 1 "nonimmediate_operand" "")
7049                              (match_operand:HI 2 "general_operand" "")))
7050               (clobber (reg:CC 17))])]
7051   "TARGET_HIMODE_MATH"
7052   "ix86_expand_binary_operator (MINUS, HImode, operands); DONE;")
7053
7054 (define_insn "*subhi_1"
7055   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r")
7056         (minus:HI (match_operand:HI 1 "nonimmediate_operand" "0,0")
7057                   (match_operand:HI 2 "general_operand" "ri,rm")))
7058    (clobber (reg:CC 17))]
7059   "ix86_binary_operator_ok (MINUS, HImode, operands)"
7060   "sub{w}\t{%2, %0|%0, %2}"
7061   [(set_attr "type" "alu")
7062    (set_attr "mode" "HI")])
7063
7064 (define_insn "*subhi_2"
7065   [(set (reg 17)
7066         (compare
7067           (minus:HI (match_operand:HI 1 "nonimmediate_operand" "0,0")
7068                     (match_operand:HI 2 "general_operand" "ri,rm"))
7069           (const_int 0)))
7070    (set (match_operand:HI 0 "nonimmediate_operand" "=rm,r")
7071         (minus:HI (match_dup 1) (match_dup 2)))]
7072   "ix86_match_ccmode (insn, CCGOCmode)
7073    && ix86_binary_operator_ok (MINUS, HImode, operands)"
7074   "sub{w}\t{%2, %0|%0, %2}"
7075   [(set_attr "type" "alu")
7076    (set_attr "mode" "HI")])
7077
7078 (define_insn "*subhi_3"
7079   [(set (reg 17)
7080         (compare (match_operand:HI 1 "nonimmediate_operand" "0,0")
7081                  (match_operand:HI 2 "general_operand" "ri,rm")))
7082    (set (match_operand:HI 0 "nonimmediate_operand" "=rm,r")
7083         (minus:HI (match_dup 1) (match_dup 2)))]
7084   "ix86_match_ccmode (insn, CCmode)
7085    && ix86_binary_operator_ok (MINUS, HImode, operands)"
7086   "sub{w}\t{%2, %0|%0, %2}"
7087   [(set_attr "type" "alu")
7088    (set_attr "mode" "HI")])
7089
7090 (define_expand "subqi3"
7091   [(parallel [(set (match_operand:QI 0 "nonimmediate_operand" "")
7092                    (minus:QI (match_operand:QI 1 "nonimmediate_operand" "")
7093                              (match_operand:QI 2 "general_operand" "")))
7094               (clobber (reg:CC 17))])]
7095   "TARGET_QIMODE_MATH"
7096   "ix86_expand_binary_operator (MINUS, QImode, operands); DONE;")
7097
7098 (define_insn "*subqi_1"
7099   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,q")
7100         (minus:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
7101                   (match_operand:QI 2 "general_operand" "qn,qmn")))
7102    (clobber (reg:CC 17))]
7103   "ix86_binary_operator_ok (MINUS, QImode, operands)"
7104   "sub{b}\t{%2, %0|%0, %2}"
7105   [(set_attr "type" "alu")
7106    (set_attr "mode" "QI")])
7107
7108 (define_insn "*subqi_1_slp"
7109   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
7110         (minus:QI (match_dup 0)
7111                   (match_operand:QI 1 "general_operand" "qn,qmn")))
7112    (clobber (reg:CC 17))]
7113   "(! TARGET_PARTIAL_REG_STALL || optimize_size)
7114    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
7115   "sub{b}\t{%1, %0|%0, %1}"
7116   [(set_attr "type" "alu1")
7117    (set_attr "mode" "QI")])
7118
7119 (define_insn "*subqi_2"
7120   [(set (reg 17)
7121         (compare
7122           (minus:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
7123                     (match_operand:QI 2 "general_operand" "qi,qm"))
7124           (const_int 0)))
7125    (set (match_operand:HI 0 "nonimmediate_operand" "=qm,q")
7126         (minus:HI (match_dup 1) (match_dup 2)))]
7127   "ix86_match_ccmode (insn, CCGOCmode)
7128    && ix86_binary_operator_ok (MINUS, QImode, operands)"
7129   "sub{b}\t{%2, %0|%0, %2}"
7130   [(set_attr "type" "alu")
7131    (set_attr "mode" "QI")])
7132
7133 (define_insn "*subqi_3"
7134   [(set (reg 17)
7135         (compare (match_operand:QI 1 "nonimmediate_operand" "0,0")
7136                  (match_operand:QI 2 "general_operand" "qi,qm")))
7137    (set (match_operand:HI 0 "nonimmediate_operand" "=qm,q")
7138         (minus:HI (match_dup 1) (match_dup 2)))]
7139   "ix86_match_ccmode (insn, CCmode)
7140    && ix86_binary_operator_ok (MINUS, QImode, operands)"
7141   "sub{b}\t{%2, %0|%0, %2}"
7142   [(set_attr "type" "alu")
7143    (set_attr "mode" "QI")])
7144
7145 ;; The patterns that match these are at the end of this file.
7146
7147 (define_expand "subxf3"
7148   [(set (match_operand:XF 0 "register_operand" "")
7149         (minus:XF (match_operand:XF 1 "register_operand" "")
7150                   (match_operand:XF 2 "register_operand" "")))]
7151   "!TARGET_64BIT && TARGET_80387"
7152   "")
7153
7154 (define_expand "subtf3"
7155   [(set (match_operand:TF 0 "register_operand" "")
7156         (minus:TF (match_operand:TF 1 "register_operand" "")
7157                   (match_operand:TF 2 "register_operand" "")))]
7158   "TARGET_80387"
7159   "")
7160
7161 (define_expand "subdf3"
7162   [(set (match_operand:DF 0 "register_operand" "")
7163         (minus:DF (match_operand:DF 1 "register_operand" "")
7164                   (match_operand:DF 2 "nonimmediate_operand" "")))]
7165   "TARGET_80387 || (TARGET_SSE2 && TARGET_SSE_MATH)"
7166   "")
7167
7168 (define_expand "subsf3"
7169   [(set (match_operand:SF 0 "register_operand" "")
7170         (minus:SF (match_operand:SF 1 "register_operand" "")
7171                   (match_operand:SF 2 "nonimmediate_operand" "")))]
7172   "TARGET_80387 || TARGET_SSE_MATH"
7173   "")
7174 \f
7175 ;; Multiply instructions
7176
7177 (define_expand "muldi3"
7178   [(parallel [(set (match_operand:DI 0 "register_operand" "")
7179                    (mult:DI (match_operand:DI 1 "register_operand" "")
7180                             (match_operand:DI 2 "x86_64_general_operand" "")))
7181               (clobber (reg:CC 17))])]
7182   "TARGET_64BIT"
7183   "")
7184
7185 (define_insn "*muldi3_1_rex64"
7186   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
7187         (mult:DI (match_operand:DI 1 "nonimmediate_operand" "%rm,rm,0")
7188                  (match_operand:DI 2 "x86_64_general_operand" "K,e,mr")))
7189    (clobber (reg:CC 17))]
7190   "TARGET_64BIT
7191    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
7192   "@
7193    imul{q}\t{%2, %1, %0|%0, %1, %2}
7194    imul{q}\t{%2, %1, %0|%0, %1, %2}
7195    imul{q}\t{%2, %0|%0, %2}"
7196   [(set_attr "type" "imul")
7197    (set_attr "prefix_0f" "0,0,1")
7198    (set (attr "athlon_decode")
7199         (cond [(eq_attr "cpu" "athlon")
7200                   (const_string "vector")
7201                (eq_attr "alternative" "1")
7202                   (const_string "vector")
7203                (and (eq_attr "alternative" "2")
7204                     (match_operand 1 "memory_operand" ""))
7205                   (const_string "vector")]
7206               (const_string "direct")))
7207    (set_attr "mode" "DI")])
7208
7209 (define_expand "mulsi3"
7210   [(parallel [(set (match_operand:SI 0 "register_operand" "")
7211                    (mult:SI (match_operand:SI 1 "register_operand" "")
7212                             (match_operand:SI 2 "general_operand" "")))
7213               (clobber (reg:CC 17))])]
7214   ""
7215   "")
7216
7217 (define_insn "*mulsi3_1"
7218   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
7219         (mult:SI (match_operand:SI 1 "nonimmediate_operand" "%rm,rm,0")
7220                  (match_operand:SI 2 "general_operand" "K,i,mr")))
7221    (clobber (reg:CC 17))]
7222   "GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM"
7223   "@
7224    imul{l}\t{%2, %1, %0|%0, %1, %2}
7225    imul{l}\t{%2, %1, %0|%0, %1, %2}
7226    imul{l}\t{%2, %0|%0, %2}"
7227   [(set_attr "type" "imul")
7228    (set_attr "prefix_0f" "0,0,1")
7229    (set (attr "athlon_decode")
7230         (cond [(eq_attr "cpu" "athlon")
7231                   (const_string "vector")
7232                (eq_attr "alternative" "1")
7233                   (const_string "vector")
7234                (and (eq_attr "alternative" "2")
7235                     (match_operand 1 "memory_operand" ""))
7236                   (const_string "vector")]
7237               (const_string "direct")))
7238    (set_attr "mode" "SI")])
7239
7240 (define_insn "*mulsi3_1_zext"
7241   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
7242         (zero_extend:DI
7243           (mult:SI (match_operand:SI 1 "nonimmediate_operand" "%rm,rm,0")
7244                    (match_operand:SI 2 "general_operand" "K,i,mr"))))
7245    (clobber (reg:CC 17))]
7246   "TARGET_64BIT
7247    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
7248   "@
7249    imul{l}\t{%2, %1, %k0|%k0, %1, %2}
7250    imul{l}\t{%2, %1, %k0|%k0, %1, %2}
7251    imul{l}\t{%2, %k0|%k0, %2}"
7252   [(set_attr "type" "imul")
7253    (set_attr "prefix_0f" "0,0,1")
7254    (set (attr "athlon_decode")
7255         (cond [(eq_attr "cpu" "athlon")
7256                   (const_string "vector")
7257                (eq_attr "alternative" "1")
7258                   (const_string "vector")
7259                (and (eq_attr "alternative" "2")
7260                     (match_operand 1 "memory_operand" ""))
7261                   (const_string "vector")]
7262               (const_string "direct")))
7263    (set_attr "mode" "SI")])
7264
7265 (define_expand "mulhi3"
7266   [(parallel [(set (match_operand:HI 0 "register_operand" "")
7267                    (mult:HI (match_operand:HI 1 "register_operand" "")
7268                             (match_operand:HI 2 "general_operand" "")))
7269               (clobber (reg:CC 17))])]
7270   "TARGET_HIMODE_MATH"
7271   "")
7272
7273 (define_insn "*mulhi3_1"
7274   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
7275         (mult:HI (match_operand:HI 1 "nonimmediate_operand" "%rm,rm,0")
7276                  (match_operand:HI 2 "general_operand" "K,i,mr")))
7277    (clobber (reg:CC 17))]
7278   "GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM"
7279   "@
7280    imul{w}\t{%2, %1, %0|%0, %1, %2}
7281    imul{w}\t{%2, %1, %0|%0, %1, %2}
7282    imul{w}\t{%2, %0|%0, %2}"
7283   [(set_attr "type" "imul")
7284    (set_attr "prefix_0f" "0,0,1")
7285    (set (attr "athlon_decode")
7286         (cond [(eq_attr "cpu" "athlon")
7287                   (const_string "vector")
7288                (eq_attr "alternative" "1,2")
7289                   (const_string "vector")]
7290               (const_string "direct")))
7291    (set_attr "mode" "HI")])
7292
7293 (define_expand "mulqi3"
7294   [(parallel [(set (match_operand:QI 0 "register_operand" "")
7295                    (mult:QI (match_operand:QI 1 "nonimmediate_operand" "")
7296                             (match_operand:QI 2 "register_operand" "")))
7297               (clobber (reg:CC 17))])]
7298   "TARGET_QIMODE_MATH"
7299   "")
7300
7301 (define_insn "*mulqi3_1"
7302   [(set (match_operand:QI 0 "register_operand" "=a")
7303         (mult:QI (match_operand:QI 1 "nonimmediate_operand" "%0")
7304                  (match_operand:QI 2 "nonimmediate_operand" "qm")))
7305    (clobber (reg:CC 17))]
7306   "TARGET_QIMODE_MATH
7307    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
7308   "mul{b}\t%2"
7309   [(set_attr "type" "imul")
7310    (set_attr "length_immediate" "0")
7311    (set (attr "athlon_decode")
7312      (if_then_else (eq_attr "cpu" "athlon")
7313         (const_string "vector")
7314         (const_string "direct")))
7315    (set_attr "mode" "QI")])
7316
7317 (define_expand "umulqihi3"
7318   [(parallel [(set (match_operand:HI 0 "register_operand" "")
7319                    (mult:HI (zero_extend:HI
7320                               (match_operand:QI 1 "nonimmediate_operand" ""))
7321                             (zero_extend:HI
7322                               (match_operand:QI 2 "register_operand" ""))))
7323               (clobber (reg:CC 17))])]
7324   "TARGET_QIMODE_MATH"
7325   "")
7326
7327 (define_insn "*umulqihi3_1"
7328   [(set (match_operand:HI 0 "register_operand" "=a")
7329         (mult:HI (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "%0"))
7330                  (zero_extend:HI (match_operand:QI 2 "nonimmediate_operand" "qm"))))
7331    (clobber (reg:CC 17))]
7332   "TARGET_QIMODE_MATH
7333    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
7334   "mul{b}\t%2"
7335   [(set_attr "type" "imul")
7336    (set_attr "length_immediate" "0")
7337    (set (attr "athlon_decode")
7338      (if_then_else (eq_attr "cpu" "athlon")
7339         (const_string "vector")
7340         (const_string "direct")))
7341    (set_attr "mode" "QI")])
7342
7343 (define_expand "mulqihi3"
7344   [(parallel [(set (match_operand:HI 0 "register_operand" "")
7345                    (mult:HI (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" ""))
7346                             (sign_extend:HI (match_operand:QI 2 "register_operand" ""))))
7347               (clobber (reg:CC 17))])]
7348   "TARGET_QIMODE_MATH"
7349   "")
7350
7351 (define_insn "*mulqihi3_insn"
7352   [(set (match_operand:HI 0 "register_operand" "=a")
7353         (mult:HI (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "%0"))
7354                  (sign_extend:HI (match_operand:QI 2 "nonimmediate_operand" "qm"))))
7355    (clobber (reg:CC 17))]
7356   "TARGET_QIMODE_MATH
7357    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
7358   "imul{b}\t%2"
7359   [(set_attr "type" "imul")
7360    (set_attr "length_immediate" "0")
7361    (set (attr "athlon_decode")
7362      (if_then_else (eq_attr "cpu" "athlon")
7363         (const_string "vector")
7364         (const_string "direct")))
7365    (set_attr "mode" "QI")])
7366
7367 (define_expand "umulditi3"
7368   [(parallel [(set (match_operand:TI 0 "register_operand" "")
7369                    (mult:TI (zero_extend:TI
7370                               (match_operand:DI 1 "nonimmediate_operand" ""))
7371                             (zero_extend:TI
7372                               (match_operand:DI 2 "register_operand" ""))))
7373               (clobber (reg:CC 17))])]
7374   "TARGET_64BIT"
7375   "")
7376
7377 (define_insn "*umulditi3_insn"
7378   [(set (match_operand:TI 0 "register_operand" "=A")
7379         (mult:TI (zero_extend:TI (match_operand:DI 1 "nonimmediate_operand" "%0"))
7380                  (zero_extend:TI (match_operand:DI 2 "nonimmediate_operand" "rm"))))
7381    (clobber (reg:CC 17))]
7382   "TARGET_64BIT
7383    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
7384   "mul{q}\t%2"
7385   [(set_attr "type" "imul")
7386    (set_attr "ppro_uops" "few")
7387    (set_attr "length_immediate" "0")
7388    (set (attr "athlon_decode")
7389      (if_then_else (eq_attr "cpu" "athlon")
7390         (const_string "vector")
7391         (const_string "double")))
7392    (set_attr "mode" "DI")])
7393
7394 ;; We can't use this pattern in 64bit mode, since it results in two separate 32bit registers
7395 (define_expand "umulsidi3"
7396   [(parallel [(set (match_operand:DI 0 "register_operand" "")
7397                    (mult:DI (zero_extend:DI
7398                               (match_operand:SI 1 "nonimmediate_operand" ""))
7399                             (zero_extend:DI
7400                               (match_operand:SI 2 "register_operand" ""))))
7401               (clobber (reg:CC 17))])]
7402   "!TARGET_64BIT"
7403   "")
7404
7405 (define_insn "*umulsidi3_insn"
7406   [(set (match_operand:DI 0 "register_operand" "=A")
7407         (mult:DI (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "%0"))
7408                  (zero_extend:DI (match_operand:SI 2 "nonimmediate_operand" "rm"))))
7409    (clobber (reg:CC 17))]
7410   "!TARGET_64BIT
7411    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
7412   "mul{l}\t%2"
7413   [(set_attr "type" "imul")
7414    (set_attr "ppro_uops" "few")
7415    (set_attr "length_immediate" "0")
7416    (set (attr "athlon_decode")
7417      (if_then_else (eq_attr "cpu" "athlon")
7418         (const_string "vector")
7419         (const_string "double")))
7420    (set_attr "mode" "SI")])
7421
7422 (define_expand "mulditi3"
7423   [(parallel [(set (match_operand:TI 0 "register_operand" "")
7424                    (mult:TI (sign_extend:TI
7425                               (match_operand:DI 1 "nonimmediate_operand" ""))
7426                             (sign_extend:TI
7427                               (match_operand:DI 2 "register_operand" ""))))
7428               (clobber (reg:CC 17))])]
7429   "TARGET_64BIT"
7430   "")
7431
7432 (define_insn "*mulditi3_insn"
7433   [(set (match_operand:TI 0 "register_operand" "=A")
7434         (mult:TI (sign_extend:TI (match_operand:DI 1 "nonimmediate_operand" "%0"))
7435                  (sign_extend:TI (match_operand:DI 2 "nonimmediate_operand" "rm"))))
7436    (clobber (reg:CC 17))]
7437   "TARGET_64BIT
7438    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
7439   "imul{q}\t%2"
7440   [(set_attr "type" "imul")
7441    (set_attr "length_immediate" "0")
7442    (set (attr "athlon_decode")
7443      (if_then_else (eq_attr "cpu" "athlon")
7444         (const_string "vector")
7445         (const_string "double")))
7446    (set_attr "mode" "DI")])
7447
7448 (define_expand "mulsidi3"
7449   [(parallel [(set (match_operand:DI 0 "register_operand" "")
7450                    (mult:DI (sign_extend:DI
7451                               (match_operand:SI 1 "nonimmediate_operand" ""))
7452                             (sign_extend:DI
7453                               (match_operand:SI 2 "register_operand" ""))))
7454               (clobber (reg:CC 17))])]
7455   "!TARGET_64BIT"
7456   "")
7457
7458 (define_insn "*mulsidi3_insn"
7459   [(set (match_operand:DI 0 "register_operand" "=A")
7460         (mult:DI (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "%0"))
7461                  (sign_extend:DI (match_operand:SI 2 "nonimmediate_operand" "rm"))))
7462    (clobber (reg:CC 17))]
7463   "!TARGET_64BIT
7464    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
7465   "imul{l}\t%2"
7466   [(set_attr "type" "imul")
7467    (set_attr "length_immediate" "0")
7468    (set (attr "athlon_decode")
7469      (if_then_else (eq_attr "cpu" "athlon")
7470         (const_string "vector")
7471         (const_string "double")))
7472    (set_attr "mode" "SI")])
7473
7474 (define_expand "umuldi3_highpart"
7475   [(parallel [(set (match_operand:DI 0 "register_operand" "")
7476                    (truncate:DI
7477                      (lshiftrt:TI
7478                        (mult:TI (zero_extend:TI
7479                                   (match_operand:DI 1 "nonimmediate_operand" ""))
7480                                 (zero_extend:TI
7481                                   (match_operand:DI 2 "register_operand" "")))
7482                        (const_int 64))))
7483               (clobber (match_scratch:DI 3 ""))
7484               (clobber (reg:CC 17))])]
7485   "TARGET_64BIT"
7486   "")
7487
7488 (define_insn "*umuldi3_highpart_rex64"
7489   [(set (match_operand:DI 0 "register_operand" "=d")
7490         (truncate:DI
7491           (lshiftrt:TI
7492             (mult:TI (zero_extend:TI
7493                        (match_operand:DI 1 "nonimmediate_operand" "%a"))
7494                      (zero_extend:TI
7495                        (match_operand:DI 2 "nonimmediate_operand" "rm")))
7496             (const_int 64))))
7497    (clobber (match_scratch:DI 3 "=1"))
7498    (clobber (reg:CC 17))]
7499   "TARGET_64BIT
7500    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
7501   "mul{q}\t%2"
7502   [(set_attr "type" "imul")
7503    (set_attr "ppro_uops" "few")
7504    (set_attr "length_immediate" "0")
7505    (set (attr "athlon_decode")
7506      (if_then_else (eq_attr "cpu" "athlon")
7507         (const_string "vector")
7508         (const_string "double")))
7509    (set_attr "mode" "DI")])
7510
7511 (define_expand "umulsi3_highpart"
7512   [(parallel [(set (match_operand:SI 0 "register_operand" "")
7513                    (truncate:SI
7514                      (lshiftrt:DI
7515                        (mult:DI (zero_extend:DI
7516                                   (match_operand:SI 1 "nonimmediate_operand" ""))
7517                                 (zero_extend:DI
7518                                   (match_operand:SI 2 "register_operand" "")))
7519                        (const_int 32))))
7520               (clobber (match_scratch:SI 3 ""))
7521               (clobber (reg:CC 17))])]
7522   ""
7523   "")
7524
7525 (define_insn "*umulsi3_highpart_insn"
7526   [(set (match_operand:SI 0 "register_operand" "=d")
7527         (truncate:SI
7528           (lshiftrt:DI
7529             (mult:DI (zero_extend:DI
7530                        (match_operand:SI 1 "nonimmediate_operand" "%a"))
7531                      (zero_extend:DI
7532                        (match_operand:SI 2 "nonimmediate_operand" "rm")))
7533             (const_int 32))))
7534    (clobber (match_scratch:SI 3 "=1"))
7535    (clobber (reg:CC 17))]
7536   "GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM"
7537   "mul{l}\t%2"
7538   [(set_attr "type" "imul")
7539    (set_attr "ppro_uops" "few")
7540    (set_attr "length_immediate" "0")
7541    (set (attr "athlon_decode")
7542      (if_then_else (eq_attr "cpu" "athlon")
7543         (const_string "vector")
7544         (const_string "double")))
7545    (set_attr "mode" "SI")])
7546
7547 (define_insn "*umulsi3_highpart_zext"
7548   [(set (match_operand:DI 0 "register_operand" "=d")
7549         (zero_extend:DI (truncate:SI
7550           (lshiftrt:DI
7551             (mult:DI (zero_extend:DI
7552                        (match_operand:SI 1 "nonimmediate_operand" "%a"))
7553                      (zero_extend:DI
7554                        (match_operand:SI 2 "nonimmediate_operand" "rm")))
7555             (const_int 32)))))
7556    (clobber (match_scratch:SI 3 "=1"))
7557    (clobber (reg:CC 17))]
7558   "TARGET_64BIT
7559    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
7560   "mul{l}\t%2"
7561   [(set_attr "type" "imul")
7562    (set_attr "ppro_uops" "few")
7563    (set_attr "length_immediate" "0")
7564    (set (attr "athlon_decode")
7565      (if_then_else (eq_attr "cpu" "athlon")
7566         (const_string "vector")
7567         (const_string "double")))
7568    (set_attr "mode" "SI")])
7569
7570 (define_expand "smuldi3_highpart"
7571   [(parallel [(set (match_operand:DI 0 "register_operand" "=d")
7572                    (truncate:DI
7573                      (lshiftrt:TI
7574                        (mult:TI (sign_extend:TI
7575                                   (match_operand:DI 1 "nonimmediate_operand" ""))
7576                                 (sign_extend:TI
7577                                   (match_operand:DI 2 "register_operand" "")))
7578                        (const_int 64))))
7579               (clobber (match_scratch:DI 3 ""))
7580               (clobber (reg:CC 17))])]
7581   "TARGET_64BIT"
7582   "")
7583
7584 (define_insn "*smuldi3_highpart_rex64"
7585   [(set (match_operand:DI 0 "register_operand" "=d")
7586         (truncate:DI
7587           (lshiftrt:TI
7588             (mult:TI (sign_extend:TI
7589                        (match_operand:DI 1 "nonimmediate_operand" "%a"))
7590                      (sign_extend:TI
7591                        (match_operand:DI 2 "nonimmediate_operand" "rm")))
7592             (const_int 64))))
7593    (clobber (match_scratch:DI 3 "=1"))
7594    (clobber (reg:CC 17))]
7595   "TARGET_64BIT
7596    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
7597   "imul{q}\t%2"
7598   [(set_attr "type" "imul")
7599    (set_attr "ppro_uops" "few")
7600    (set (attr "athlon_decode")
7601      (if_then_else (eq_attr "cpu" "athlon")
7602         (const_string "vector")
7603         (const_string "double")))
7604    (set_attr "mode" "DI")])
7605
7606 (define_expand "smulsi3_highpart"
7607   [(parallel [(set (match_operand:SI 0 "register_operand" "")
7608                    (truncate:SI
7609                      (lshiftrt:DI
7610                        (mult:DI (sign_extend:DI
7611                                   (match_operand:SI 1 "nonimmediate_operand" ""))
7612                                 (sign_extend:DI
7613                                   (match_operand:SI 2 "register_operand" "")))
7614                        (const_int 32))))
7615               (clobber (match_scratch:SI 3 ""))
7616               (clobber (reg:CC 17))])]
7617   ""
7618   "")
7619
7620 (define_insn "*smulsi3_highpart_insn"
7621   [(set (match_operand:SI 0 "register_operand" "=d")
7622         (truncate:SI
7623           (lshiftrt:DI
7624             (mult:DI (sign_extend:DI
7625                        (match_operand:SI 1 "nonimmediate_operand" "%a"))
7626                      (sign_extend:DI
7627                        (match_operand:SI 2 "nonimmediate_operand" "rm")))
7628             (const_int 32))))
7629    (clobber (match_scratch:SI 3 "=1"))
7630    (clobber (reg:CC 17))]
7631   "GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM"
7632   "imul{l}\t%2"
7633   [(set_attr "type" "imul")
7634    (set_attr "ppro_uops" "few")
7635    (set (attr "athlon_decode")
7636      (if_then_else (eq_attr "cpu" "athlon")
7637         (const_string "vector")
7638         (const_string "double")))
7639    (set_attr "mode" "SI")])
7640
7641 (define_insn "*smulsi3_highpart_zext"
7642   [(set (match_operand:DI 0 "register_operand" "=d")
7643         (zero_extend:DI (truncate:SI
7644           (lshiftrt:DI
7645             (mult:DI (sign_extend:DI
7646                        (match_operand:SI 1 "nonimmediate_operand" "%a"))
7647                      (sign_extend:DI
7648                        (match_operand:SI 2 "nonimmediate_operand" "rm")))
7649             (const_int 32)))))
7650    (clobber (match_scratch:SI 3 "=1"))
7651    (clobber (reg:CC 17))]
7652   "TARGET_64BIT
7653    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
7654   "imul{l}\t%2"
7655   [(set_attr "type" "imul")
7656    (set_attr "ppro_uops" "few")
7657    (set (attr "athlon_decode")
7658      (if_then_else (eq_attr "cpu" "athlon")
7659         (const_string "vector")
7660         (const_string "double")))
7661    (set_attr "mode" "SI")])
7662
7663 ;; The patterns that match these are at the end of this file.
7664
7665 (define_expand "mulxf3"
7666   [(set (match_operand:XF 0 "register_operand" "")
7667         (mult:XF (match_operand:XF 1 "register_operand" "")
7668                  (match_operand:XF 2 "register_operand" "")))]
7669   "!TARGET_64BIT && TARGET_80387"
7670   "")
7671
7672 (define_expand "multf3"
7673   [(set (match_operand:TF 0 "register_operand" "")
7674         (mult:TF (match_operand:TF 1 "register_operand" "")
7675                  (match_operand:TF 2 "register_operand" "")))]
7676   "TARGET_80387"
7677   "")
7678
7679 (define_expand "muldf3"
7680   [(set (match_operand:DF 0 "register_operand" "")
7681         (mult:DF (match_operand:DF 1 "register_operand" "")
7682                  (match_operand:DF 2 "nonimmediate_operand" "")))]
7683   "TARGET_80387 || (TARGET_SSE2 && TARGET_SSE_MATH)"
7684   "")
7685
7686 (define_expand "mulsf3"
7687   [(set (match_operand:SF 0 "register_operand" "")
7688         (mult:SF (match_operand:SF 1 "register_operand" "")
7689                  (match_operand:SF 2 "nonimmediate_operand" "")))]
7690   "TARGET_80387 || TARGET_SSE_MATH"
7691   "")
7692 \f
7693 ;; Divide instructions
7694
7695 (define_insn "divqi3"
7696   [(set (match_operand:QI 0 "register_operand" "=a")
7697         (div:QI (match_operand:HI 1 "register_operand" "0")
7698                 (match_operand:QI 2 "nonimmediate_operand" "qm")))
7699    (clobber (reg:CC 17))]
7700   "TARGET_QIMODE_MATH"
7701   "idiv{b}\t%2"
7702   [(set_attr "type" "idiv")
7703    (set_attr "mode" "QI")
7704    (set_attr "ppro_uops" "few")])
7705
7706 (define_insn "udivqi3"
7707   [(set (match_operand:QI 0 "register_operand" "=a")
7708         (udiv:QI (match_operand:HI 1 "register_operand" "0")
7709                  (match_operand:QI 2 "nonimmediate_operand" "qm")))
7710    (clobber (reg:CC 17))]
7711   "TARGET_QIMODE_MATH"
7712   "div{b}\t%2"
7713   [(set_attr "type" "idiv")
7714    (set_attr "mode" "QI")
7715    (set_attr "ppro_uops" "few")])
7716
7717 ;; The patterns that match these are at the end of this file.
7718
7719 (define_expand "divxf3"
7720   [(set (match_operand:XF 0 "register_operand" "")
7721         (div:XF (match_operand:XF 1 "register_operand" "")
7722                 (match_operand:XF 2 "register_operand" "")))]
7723   "!TARGET_64BIT && TARGET_80387"
7724   "")
7725
7726 (define_expand "divtf3"
7727   [(set (match_operand:TF 0 "register_operand" "")
7728         (div:TF (match_operand:TF 1 "register_operand" "")
7729                 (match_operand:TF 2 "register_operand" "")))]
7730   "TARGET_80387"
7731   "")
7732
7733 (define_expand "divdf3"
7734   [(set (match_operand:DF 0 "register_operand" "")
7735         (div:DF (match_operand:DF 1 "register_operand" "")
7736                 (match_operand:DF 2 "nonimmediate_operand" "")))]
7737    "TARGET_80387 || (TARGET_SSE2 && TARGET_SSE_MATH)"
7738    "")
7739  
7740 (define_expand "divsf3"
7741   [(set (match_operand:SF 0 "register_operand" "")
7742         (div:SF (match_operand:SF 1 "register_operand" "")
7743                 (match_operand:SF 2 "nonimmediate_operand" "")))]
7744   "TARGET_80387 || TARGET_SSE_MATH"
7745   "")
7746 \f
7747 ;; Remainder instructions.
7748
7749 (define_expand "divmoddi4"
7750   [(parallel [(set (match_operand:DI 0 "register_operand" "")
7751                    (div:DI (match_operand:DI 1 "register_operand" "")
7752                            (match_operand:DI 2 "nonimmediate_operand" "")))
7753               (set (match_operand:DI 3 "register_operand" "")
7754                    (mod:DI (match_dup 1) (match_dup 2)))
7755               (clobber (reg:CC 17))])]
7756   "TARGET_64BIT"
7757   "")
7758
7759 ;; Allow to come the parameter in eax or edx to avoid extra moves.
7760 ;; Penalize eax case slightly because it results in worse scheduling
7761 ;; of code.
7762 (define_insn "*divmoddi4_nocltd_rex64"
7763   [(set (match_operand:DI 0 "register_operand" "=&a,?a")
7764         (div:DI (match_operand:DI 2 "register_operand" "1,0")
7765                 (match_operand:DI 3 "nonimmediate_operand" "rm,rm")))
7766    (set (match_operand:DI 1 "register_operand" "=&d,&d")
7767         (mod:DI (match_dup 2) (match_dup 3)))
7768    (clobber (reg:CC 17))]
7769   "TARGET_64BIT && !optimize_size && !TARGET_USE_CLTD"
7770   "#"
7771   [(set_attr "type" "multi")])
7772
7773 (define_insn "*divmoddi4_cltd_rex64"
7774   [(set (match_operand:DI 0 "register_operand" "=a")
7775         (div:DI (match_operand:DI 2 "register_operand" "a")
7776                 (match_operand:DI 3 "nonimmediate_operand" "rm")))
7777    (set (match_operand:DI 1 "register_operand" "=&d")
7778         (mod:DI (match_dup 2) (match_dup 3)))
7779    (clobber (reg:CC 17))]
7780   "TARGET_64BIT && (optimize_size || TARGET_USE_CLTD)"
7781   "#"
7782   [(set_attr "type" "multi")])
7783
7784 (define_insn "*divmoddi_noext_rex64"
7785   [(set (match_operand:DI 0 "register_operand" "=a")
7786         (div:DI (match_operand:DI 1 "register_operand" "0")
7787                 (match_operand:DI 2 "nonimmediate_operand" "rm")))
7788    (set (match_operand:DI 3 "register_operand" "=d")
7789         (mod:DI (match_dup 1) (match_dup 2)))
7790    (use (match_operand:DI 4 "register_operand" "3"))
7791    (clobber (reg:CC 17))]
7792   "TARGET_64BIT"
7793   "idiv{q}\t%2"
7794   [(set_attr "type" "idiv")
7795    (set_attr "mode" "DI")
7796    (set_attr "ppro_uops" "few")])
7797
7798 (define_split
7799   [(set (match_operand:DI 0 "register_operand" "")
7800         (div:DI (match_operand:DI 1 "register_operand" "")
7801                 (match_operand:DI 2 "nonimmediate_operand" "")))
7802    (set (match_operand:DI 3 "register_operand" "")
7803         (mod:DI (match_dup 1) (match_dup 2)))
7804    (clobber (reg:CC 17))]
7805   "TARGET_64BIT && reload_completed"
7806   [(parallel [(set (match_dup 3)
7807                    (ashiftrt:DI (match_dup 4) (const_int 63)))
7808               (clobber (reg:CC 17))])
7809    (parallel [(set (match_dup 0)
7810                    (div:DI (reg:DI 0) (match_dup 2)))
7811               (set (match_dup 3)
7812                    (mod:DI (reg:DI 0) (match_dup 2)))
7813               (use (match_dup 3))
7814               (clobber (reg:CC 17))])]
7815 {
7816   /* Avoid use of cltd in favor of a mov+shift.  */
7817   if (!TARGET_USE_CLTD && !optimize_size)
7818     {
7819       if (true_regnum (operands[1]))
7820         emit_move_insn (operands[0], operands[1]);
7821       else
7822         emit_move_insn (operands[3], operands[1]);
7823       operands[4] = operands[3];
7824     }
7825   else
7826     {
7827       if (true_regnum (operands[1]))
7828         abort();
7829       operands[4] = operands[1];
7830     }
7831 })
7832
7833
7834 (define_expand "divmodsi4"
7835   [(parallel [(set (match_operand:SI 0 "register_operand" "")
7836                    (div:SI (match_operand:SI 1 "register_operand" "")
7837                            (match_operand:SI 2 "nonimmediate_operand" "")))
7838               (set (match_operand:SI 3 "register_operand" "")
7839                    (mod:SI (match_dup 1) (match_dup 2)))
7840               (clobber (reg:CC 17))])]
7841   ""
7842   "")
7843
7844 ;; Allow to come the parameter in eax or edx to avoid extra moves.
7845 ;; Penalize eax case slightly because it results in worse scheduling
7846 ;; of code.
7847 (define_insn "*divmodsi4_nocltd"
7848   [(set (match_operand:SI 0 "register_operand" "=&a,?a")
7849         (div:SI (match_operand:SI 2 "register_operand" "1,0")
7850                 (match_operand:SI 3 "nonimmediate_operand" "rm,rm")))
7851    (set (match_operand:SI 1 "register_operand" "=&d,&d")
7852         (mod:SI (match_dup 2) (match_dup 3)))
7853    (clobber (reg:CC 17))]
7854   "!optimize_size && !TARGET_USE_CLTD"
7855   "#"
7856   [(set_attr "type" "multi")])
7857
7858 (define_insn "*divmodsi4_cltd"
7859   [(set (match_operand:SI 0 "register_operand" "=a")
7860         (div:SI (match_operand:SI 2 "register_operand" "a")
7861                 (match_operand:SI 3 "nonimmediate_operand" "rm")))
7862    (set (match_operand:SI 1 "register_operand" "=&d")
7863         (mod:SI (match_dup 2) (match_dup 3)))
7864    (clobber (reg:CC 17))]
7865   "optimize_size || TARGET_USE_CLTD"
7866   "#"
7867   [(set_attr "type" "multi")])
7868
7869 (define_insn "*divmodsi_noext"
7870   [(set (match_operand:SI 0 "register_operand" "=a")
7871         (div:SI (match_operand:SI 1 "register_operand" "0")
7872                 (match_operand:SI 2 "nonimmediate_operand" "rm")))
7873    (set (match_operand:SI 3 "register_operand" "=d")
7874         (mod:SI (match_dup 1) (match_dup 2)))
7875    (use (match_operand:SI 4 "register_operand" "3"))
7876    (clobber (reg:CC 17))]
7877   ""
7878   "idiv{l}\t%2"
7879   [(set_attr "type" "idiv")
7880    (set_attr "mode" "SI")
7881    (set_attr "ppro_uops" "few")])
7882
7883 (define_split
7884   [(set (match_operand:SI 0 "register_operand" "")
7885         (div:SI (match_operand:SI 1 "register_operand" "")
7886                 (match_operand:SI 2 "nonimmediate_operand" "")))
7887    (set (match_operand:SI 3 "register_operand" "")
7888         (mod:SI (match_dup 1) (match_dup 2)))
7889    (clobber (reg:CC 17))]
7890   "reload_completed"
7891   [(parallel [(set (match_dup 3)
7892                    (ashiftrt:SI (match_dup 4) (const_int 31)))
7893               (clobber (reg:CC 17))])
7894    (parallel [(set (match_dup 0)
7895                    (div:SI (reg:SI 0) (match_dup 2)))
7896               (set (match_dup 3)
7897                    (mod:SI (reg:SI 0) (match_dup 2)))
7898               (use (match_dup 3))
7899               (clobber (reg:CC 17))])]
7900 {
7901   /* Avoid use of cltd in favor of a mov+shift.  */
7902   if (!TARGET_USE_CLTD && !optimize_size)
7903     {
7904       if (true_regnum (operands[1]))
7905         emit_move_insn (operands[0], operands[1]);
7906       else
7907         emit_move_insn (operands[3], operands[1]);
7908       operands[4] = operands[3];
7909     }
7910   else
7911     {
7912       if (true_regnum (operands[1]))
7913         abort();
7914       operands[4] = operands[1];
7915     }
7916 })
7917 ;; %%% Split me.
7918 (define_insn "divmodhi4"
7919   [(set (match_operand:HI 0 "register_operand" "=a")
7920         (div:HI (match_operand:HI 1 "register_operand" "0")
7921                 (match_operand:HI 2 "nonimmediate_operand" "rm")))
7922    (set (match_operand:HI 3 "register_operand" "=&d")
7923         (mod:HI (match_dup 1) (match_dup 2)))
7924    (clobber (reg:CC 17))]
7925   "TARGET_HIMODE_MATH"
7926   "cwtd\;idiv{w}\t%2"
7927   [(set_attr "type" "multi")
7928    (set_attr "length_immediate" "0")
7929    (set_attr "mode" "SI")])
7930
7931 (define_insn "udivmoddi4"
7932   [(set (match_operand:DI 0 "register_operand" "=a")
7933         (udiv:DI (match_operand:DI 1 "register_operand" "0")
7934                  (match_operand:DI 2 "nonimmediate_operand" "rm")))
7935    (set (match_operand:DI 3 "register_operand" "=&d")
7936         (umod:DI (match_dup 1) (match_dup 2)))
7937    (clobber (reg:CC 17))]
7938   "TARGET_64BIT"
7939   "xor{q}\t%3, %3\;div{q}\t%2"
7940   [(set_attr "type" "multi")
7941    (set_attr "length_immediate" "0")
7942    (set_attr "mode" "DI")])
7943
7944 (define_insn "*udivmoddi4_noext"
7945   [(set (match_operand:DI 0 "register_operand" "=a")
7946         (udiv:DI (match_operand:DI 1 "register_operand" "0")
7947                  (match_operand:DI 2 "nonimmediate_operand" "rm")))
7948    (set (match_operand:DI 3 "register_operand" "=d")
7949         (umod:DI (match_dup 1) (match_dup 2)))
7950    (use (match_dup 3))
7951    (clobber (reg:CC 17))]
7952   "TARGET_64BIT"
7953   "div{q}\t%2"
7954   [(set_attr "type" "idiv")
7955    (set_attr "ppro_uops" "few")
7956    (set_attr "mode" "DI")])
7957
7958 (define_split
7959   [(set (match_operand:DI 0 "register_operand" "")
7960         (udiv:DI (match_operand:DI 1 "register_operand" "")
7961                  (match_operand:DI 2 "nonimmediate_operand" "")))
7962    (set (match_operand:DI 3 "register_operand" "")
7963         (umod:DI (match_dup 1) (match_dup 2)))
7964    (clobber (reg:CC 17))]
7965   "TARGET_64BIT && reload_completed"
7966   [(set (match_dup 3) (const_int 0))
7967    (parallel [(set (match_dup 0)
7968                    (udiv:DI (match_dup 1) (match_dup 2)))
7969               (set (match_dup 3)
7970                    (umod:DI (match_dup 1) (match_dup 2)))
7971               (use (match_dup 3))
7972               (clobber (reg:CC 17))])]
7973   "")
7974
7975 (define_insn "udivmodsi4"
7976   [(set (match_operand:SI 0 "register_operand" "=a")
7977         (udiv:SI (match_operand:SI 1 "register_operand" "0")
7978                  (match_operand:SI 2 "nonimmediate_operand" "rm")))
7979    (set (match_operand:SI 3 "register_operand" "=&d")
7980         (umod:SI (match_dup 1) (match_dup 2)))
7981    (clobber (reg:CC 17))]
7982   ""
7983   "xor{l}\t%3, %3\;div{l}\t%2"
7984   [(set_attr "type" "multi")
7985    (set_attr "length_immediate" "0")
7986    (set_attr "mode" "SI")])
7987
7988 (define_insn "*udivmodsi4_noext"
7989   [(set (match_operand:SI 0 "register_operand" "=a")
7990         (udiv:SI (match_operand:SI 1 "register_operand" "0")
7991                  (match_operand:SI 2 "nonimmediate_operand" "rm")))
7992    (set (match_operand:SI 3 "register_operand" "=d")
7993         (umod:SI (match_dup 1) (match_dup 2)))
7994    (use (match_dup 3))
7995    (clobber (reg:CC 17))]
7996   ""
7997   "div{l}\t%2"
7998   [(set_attr "type" "idiv")
7999    (set_attr "ppro_uops" "few")
8000    (set_attr "mode" "SI")])
8001
8002 (define_split
8003   [(set (match_operand:SI 0 "register_operand" "")
8004         (udiv:SI (match_operand:SI 1 "register_operand" "")
8005                  (match_operand:SI 2 "nonimmediate_operand" "")))
8006    (set (match_operand:SI 3 "register_operand" "")
8007         (umod:SI (match_dup 1) (match_dup 2)))
8008    (clobber (reg:CC 17))]
8009   "reload_completed"
8010   [(set (match_dup 3) (const_int 0))
8011    (parallel [(set (match_dup 0)
8012                    (udiv:SI (match_dup 1) (match_dup 2)))
8013               (set (match_dup 3)
8014                    (umod:SI (match_dup 1) (match_dup 2)))
8015               (use (match_dup 3))
8016               (clobber (reg:CC 17))])]
8017   "")
8018
8019 (define_expand "udivmodhi4"
8020   [(set (match_dup 4) (const_int 0))
8021    (parallel [(set (match_operand:HI 0 "register_operand" "")
8022                    (udiv:HI (match_operand:HI 1 "register_operand" "")
8023                             (match_operand:HI 2 "nonimmediate_operand" "")))
8024               (set (match_operand:HI 3 "register_operand" "")
8025                    (umod:HI (match_dup 1) (match_dup 2)))
8026               (use (match_dup 4))
8027               (clobber (reg:CC 17))])]
8028   "TARGET_HIMODE_MATH"
8029   "operands[4] = gen_reg_rtx (HImode);")
8030
8031 (define_insn "*udivmodhi_noext"
8032   [(set (match_operand:HI 0 "register_operand" "=a")
8033         (udiv:HI (match_operand:HI 1 "register_operand" "0")
8034                  (match_operand:HI 2 "nonimmediate_operand" "rm")))
8035    (set (match_operand:HI 3 "register_operand" "=d")
8036         (umod:HI (match_dup 1) (match_dup 2)))
8037    (use (match_operand:HI 4 "register_operand" "3"))
8038    (clobber (reg:CC 17))]
8039   ""
8040   "div{w}\t%2"
8041   [(set_attr "type" "idiv")
8042    (set_attr "mode" "HI")
8043    (set_attr "ppro_uops" "few")])
8044
8045 ;; We can not use div/idiv for double division, because it causes
8046 ;; "division by zero" on the overflow and that's not what we expect
8047 ;; from truncate.  Because true (non truncating) double division is
8048 ;; never generated, we can't create this insn anyway.
8049 ;
8050 ;(define_insn ""
8051 ;  [(set (match_operand:SI 0 "register_operand" "=a")
8052 ;       (truncate:SI
8053 ;         (udiv:DI (match_operand:DI 1 "register_operand" "A")
8054 ;                  (zero_extend:DI
8055 ;                    (match_operand:SI 2 "nonimmediate_operand" "rm")))))
8056 ;   (set (match_operand:SI 3 "register_operand" "=d")
8057 ;       (truncate:SI
8058 ;         (umod:DI (match_dup 1) (zero_extend:DI (match_dup 2)))))
8059 ;   (clobber (reg:CC 17))]
8060 ;  ""
8061 ;  "div{l}\t{%2, %0|%0, %2}"
8062 ;  [(set_attr "type" "idiv")
8063 ;   (set_attr "ppro_uops" "few")])
8064 \f
8065 ;;- Logical AND instructions
8066
8067 ;; On Pentium, "test imm, reg" is pairable only with eax, ax, and al.
8068 ;; Note that this excludes ah.
8069
8070 (define_insn "*testdi_1_rex64"
8071   [(set (reg 17)
8072         (compare
8073           (and:DI (match_operand:DI 0 "nonimmediate_operand" "%*a,r,*a,r,rm")
8074                   (match_operand:DI 1 "x86_64_szext_nonmemory_operand" "Z,Z,e,e,re"))
8075           (const_int 0)))]
8076   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
8077   "@
8078    test{l}\t{%k1, %k0|%k0, %k1} 
8079    test{l}\t{%k1, %k0|%k0, %k1} 
8080    test{q}\t{%1, %0|%0, %1} 
8081    test{q}\t{%1, %0|%0, %1} 
8082    test{q}\t{%1, %0|%0, %1}"
8083   [(set_attr "type" "test")
8084    (set_attr "modrm" "0,1,0,1,1")
8085    (set_attr "mode" "SI,SI,DI,DI,DI")
8086    (set_attr "pent_pair" "uv,np,uv,np,uv")])
8087
8088 (define_insn "testsi_1"
8089   [(set (reg 17)
8090         (compare
8091           (and:SI (match_operand:SI 0 "nonimmediate_operand" "%*a,r,rm")
8092                   (match_operand:SI 1 "nonmemory_operand" "in,in,rin"))
8093           (const_int 0)))]
8094   "ix86_match_ccmode (insn, CCNOmode)"
8095   "test{l}\t{%1, %0|%0, %1}"
8096   [(set_attr "type" "test")
8097    (set_attr "modrm" "0,1,1")
8098    (set_attr "mode" "SI")
8099    (set_attr "pent_pair" "uv,np,uv")])
8100
8101 (define_expand "testsi_ccno_1"
8102   [(set (reg:CCNO 17)
8103         (compare:CCNO
8104           (and:SI (match_operand:SI 0 "nonimmediate_operand" "")
8105                   (match_operand:SI 1 "nonmemory_operand" ""))
8106           (const_int 0)))]
8107   ""
8108   "")
8109
8110 (define_insn "*testhi_1"
8111   [(set (reg 17)
8112         (compare (and:HI (match_operand:HI 0 "nonimmediate_operand" "%*a,r,rm")
8113                          (match_operand:HI 1 "nonmemory_operand" "n,n,rn"))
8114                  (const_int 0)))]
8115   "ix86_match_ccmode (insn, CCNOmode)"
8116   "test{w}\t{%1, %0|%0, %1}"
8117   [(set_attr "type" "test")
8118    (set_attr "modrm" "0,1,1")
8119    (set_attr "mode" "HI")
8120    (set_attr "pent_pair" "uv,np,uv")])
8121
8122 (define_expand "testqi_ccz_1"
8123   [(set (reg:CCZ 17)
8124         (compare:CCZ (and:QI (match_operand:QI 0 "nonimmediate_operand" "")
8125                              (match_operand:QI 1 "nonmemory_operand" ""))
8126                  (const_int 0)))]
8127   ""
8128   "")
8129
8130 (define_insn "*testqi_1"
8131   [(set (reg 17)
8132         (compare (and:QI (match_operand:QI 0 "nonimmediate_operand" "%*a,q,qm,r")
8133                          (match_operand:QI 1 "nonmemory_operand" "n,n,qn,n"))
8134                  (const_int 0)))]
8135   "ix86_match_ccmode (insn, CCNOmode)"
8136 {
8137   if (which_alternative == 3)
8138     {
8139       if (GET_CODE (operands[1]) == CONST_INT
8140           && (INTVAL (operands[1]) & 0xffffff00))
8141         operands[1] = GEN_INT (INTVAL (operands[1]) & 0xff);
8142       return "test{l}\t{%1, %k0|%k0, %1}";
8143     }
8144   return "test{b}\t{%1, %0|%0, %1}";
8145 }
8146   [(set_attr "type" "test")
8147    (set_attr "modrm" "0,1,1,1")
8148    (set_attr "mode" "QI,QI,QI,SI")
8149    (set_attr "pent_pair" "uv,np,uv,np")])
8150
8151 (define_expand "testqi_ext_ccno_0"
8152   [(set (reg:CCNO 17)
8153         (compare:CCNO
8154           (and:SI
8155             (zero_extract:SI
8156               (match_operand 0 "ext_register_operand" "")
8157               (const_int 8)
8158               (const_int 8))
8159             (match_operand 1 "const_int_operand" ""))
8160           (const_int 0)))]
8161   ""
8162   "")
8163
8164 (define_insn "*testqi_ext_0"
8165   [(set (reg 17)
8166         (compare
8167           (and:SI
8168             (zero_extract:SI
8169               (match_operand 0 "ext_register_operand" "Q")
8170               (const_int 8)
8171               (const_int 8))
8172             (match_operand 1 "const_int_operand" "n"))
8173           (const_int 0)))]
8174   "ix86_match_ccmode (insn, CCNOmode)"
8175   "test{b}\t{%1, %h0|%h0, %1}"
8176   [(set_attr "type" "test")
8177    (set_attr "mode" "QI")
8178    (set_attr "length_immediate" "1")
8179    (set_attr "pent_pair" "np")])
8180
8181 (define_insn "*testqi_ext_1"
8182   [(set (reg 17)
8183         (compare
8184           (and:SI
8185             (zero_extract:SI
8186               (match_operand 0 "ext_register_operand" "Q")
8187               (const_int 8)
8188               (const_int 8))
8189             (zero_extend:SI
8190               (match_operand:QI 1 "nonimmediate_operand" "Qm")))
8191           (const_int 0)))]
8192   "!TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
8193   "test{b}\t{%1, %h0|%h0, %1}"
8194   [(set_attr "type" "test")
8195    (set_attr "mode" "QI")])
8196
8197 (define_insn "*testqi_ext_1_rex64"
8198   [(set (reg 17)
8199         (compare
8200           (and:SI
8201             (zero_extract:SI
8202               (match_operand 0 "ext_register_operand" "Q")
8203               (const_int 8)
8204               (const_int 8))
8205             (zero_extend:SI
8206               (match_operand:QI 1 "register_operand" "Q")))
8207           (const_int 0)))]
8208   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
8209   "test{b}\t{%1, %h0|%h0, %1}"
8210   [(set_attr "type" "test")
8211    (set_attr "mode" "QI")])
8212
8213 (define_insn "*testqi_ext_2"
8214   [(set (reg 17)
8215         (compare
8216           (and:SI
8217             (zero_extract:SI
8218               (match_operand 0 "ext_register_operand" "Q")
8219               (const_int 8)
8220               (const_int 8))
8221             (zero_extract:SI
8222               (match_operand 1 "ext_register_operand" "Q")
8223               (const_int 8)
8224               (const_int 8)))
8225           (const_int 0)))]
8226   "ix86_match_ccmode (insn, CCNOmode)"
8227   "test{b}\t{%h1, %h0|%h0, %h1}"
8228   [(set_attr "type" "test")
8229    (set_attr "mode" "QI")])
8230
8231 ;; Combine likes to form bit extractions for some tests.  Humor it.
8232 (define_insn "*testqi_ext_3"
8233   [(set (reg 17)
8234         (compare (zero_extract:SI
8235                    (match_operand 0 "nonimmediate_operand" "rm")
8236                    (match_operand:SI 1 "const_int_operand" "")
8237                    (match_operand:SI 2 "const_int_operand" ""))
8238                  (const_int 0)))]
8239   "ix86_match_ccmode (insn, CCNOmode)
8240    && (GET_MODE (operands[0]) == SImode
8241        || (TARGET_64BIT && GET_MODE (operands[0]) == DImode)
8242        || GET_MODE (operands[0]) == HImode
8243        || GET_MODE (operands[0]) == QImode)"
8244   "#")
8245
8246 (define_insn "*testqi_ext_3_rex64"
8247   [(set (reg 17)
8248         (compare (zero_extract:DI
8249                    (match_operand 0 "nonimmediate_operand" "rm")
8250                    (match_operand:DI 1 "const_int_operand" "")
8251                    (match_operand:DI 2 "const_int_operand" ""))
8252                  (const_int 0)))]
8253   "TARGET_64BIT
8254    && ix86_match_ccmode (insn, CCNOmode)
8255    /* The code below cannot deal with constants outside HOST_WIDE_INT.  */
8256    && INTVAL (operands[1]) + INTVAL (operands[2]) < HOST_BITS_PER_WIDE_INT
8257    /* Ensure that resulting mask is zero or sign extended operand.  */
8258    && (INTVAL (operands[1]) + INTVAL (operands[2]) <= 32
8259        || (INTVAL (operands[1]) + INTVAL (operands[2]) == 64
8260            && INTVAL (operands[1]) > 32))
8261    && (GET_MODE (operands[0]) == SImode
8262        || GET_MODE (operands[0]) == DImode
8263        || GET_MODE (operands[0]) == HImode
8264        || GET_MODE (operands[0]) == QImode)"
8265   "#")
8266
8267 (define_split
8268   [(set (reg 17)
8269         (compare (zero_extract
8270                    (match_operand 0 "nonimmediate_operand" "")
8271                    (match_operand 1 "const_int_operand" "")
8272                    (match_operand 2 "const_int_operand" ""))
8273                  (const_int 0)))]
8274   "ix86_match_ccmode (insn, CCNOmode)"
8275   [(set (reg:CCNO 17) (compare:CCNO (match_dup 3) (const_int 0)))]
8276 {
8277   HOST_WIDE_INT len = INTVAL (operands[1]);
8278   HOST_WIDE_INT pos = INTVAL (operands[2]);
8279   HOST_WIDE_INT mask;
8280   enum machine_mode mode, submode;
8281
8282   mode = GET_MODE (operands[0]);
8283   if (GET_CODE (operands[0]) == MEM)
8284     {
8285       /* ??? Combine likes to put non-volatile mem extractions in QImode
8286          no matter the size of the test.  So find a mode that works.  */
8287       if (! MEM_VOLATILE_P (operands[0]))
8288         {
8289           mode = smallest_mode_for_size (pos + len, MODE_INT);
8290           operands[0] = adjust_address (operands[0], mode, 0);
8291         }
8292     }
8293   else if (GET_CODE (operands[0]) == SUBREG
8294            && (submode = GET_MODE (SUBREG_REG (operands[0])),
8295                GET_MODE_BITSIZE (mode) > GET_MODE_BITSIZE (submode))
8296            && pos + len <= GET_MODE_BITSIZE (submode))
8297     {
8298       /* Narrow a paradoxical subreg to prevent partial register stalls.  */
8299       mode = submode;
8300       operands[0] = SUBREG_REG (operands[0]);
8301     }
8302   else if (mode == HImode && pos + len <= 8)
8303     {
8304       /* Small HImode tests can be converted to QImode.  */
8305       mode = QImode;
8306       operands[0] = gen_lowpart (QImode, operands[0]);
8307     }
8308
8309   mask  = ((HOST_WIDE_INT)1 << (pos + len)) - 1;
8310   mask &= ~(((HOST_WIDE_INT)1 << pos) - 1);
8311
8312   operands[3] = gen_rtx_AND (mode, operands[0], gen_int_mode (mask, mode));
8313 })
8314
8315 ;; Convert HImode/SImode test instructions with immediate to QImode ones.
8316 ;; i386 does not allow to encode test with 8bit sign extended immediate, so
8317 ;; this is relatively important trick.
8318 ;; Do the conversion only post-reload to avoid limiting of the register class
8319 ;; to QI regs.
8320 (define_split
8321   [(set (reg 17)
8322         (compare
8323           (and (match_operand 0 "register_operand" "")
8324                (match_operand 1 "const_int_operand" ""))
8325           (const_int 0)))]
8326    "reload_completed
8327     && QI_REG_P (operands[0])
8328     && ((ix86_match_ccmode (insn, CCZmode)
8329          && !(INTVAL (operands[1]) & ~(255 << 8)))
8330         || (ix86_match_ccmode (insn, CCNOmode)
8331             && !(INTVAL (operands[1]) & ~(127 << 8))))
8332     && GET_MODE (operands[0]) != QImode"
8333   [(set (reg:CCNO 17)
8334         (compare:CCNO
8335           (and:SI (zero_extract:SI (match_dup 0) (const_int 8) (const_int 8))
8336                   (match_dup 1))
8337           (const_int 0)))]
8338   "operands[0] = gen_lowpart (SImode, operands[0]);
8339    operands[1] = gen_int_mode (INTVAL (operands[1]) >> 8, SImode);")
8340
8341 (define_split
8342   [(set (reg 17)
8343         (compare
8344           (and (match_operand 0 "nonimmediate_operand" "")
8345                (match_operand 1 "const_int_operand" ""))
8346           (const_int 0)))]
8347    "reload_completed
8348     && (!REG_P (operands[0]) || ANY_QI_REG_P (operands[0]))
8349     && ((ix86_match_ccmode (insn, CCZmode)
8350          && !(INTVAL (operands[1]) & ~255))
8351         || (ix86_match_ccmode (insn, CCNOmode)
8352             && !(INTVAL (operands[1]) & ~127)))
8353     && GET_MODE (operands[0]) != QImode"
8354   [(set (reg:CCNO 17)
8355         (compare:CCNO
8356           (and:QI (match_dup 0)
8357                   (match_dup 1))
8358           (const_int 0)))]
8359   "operands[0] = gen_lowpart (QImode, operands[0]);
8360    operands[1] = gen_lowpart (QImode, operands[1]);")
8361
8362
8363 ;; %%% This used to optimize known byte-wide and operations to memory,
8364 ;; and sometimes to QImode registers.  If this is considered useful,
8365 ;; it should be done with splitters.
8366
8367 (define_expand "anddi3"
8368   [(set (match_operand:DI 0 "nonimmediate_operand" "")
8369         (and:DI (match_operand:DI 1 "nonimmediate_operand" "")
8370                 (match_operand:DI 2 "x86_64_szext_general_operand" "")))
8371    (clobber (reg:CC 17))]
8372   "TARGET_64BIT"
8373   "ix86_expand_binary_operator (AND, DImode, operands); DONE;")
8374
8375 (define_insn "*anddi_1_rex64"
8376   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,rm,r,r")
8377         (and:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0,0,qm")
8378                 (match_operand:DI 2 "x86_64_szext_general_operand" "Z,re,rm,L")))
8379    (clobber (reg:CC 17))]
8380   "TARGET_64BIT && ix86_binary_operator_ok (AND, DImode, operands)"
8381 {
8382   switch (get_attr_type (insn))
8383     {
8384     case TYPE_IMOVX:
8385       {
8386         enum machine_mode mode;
8387
8388         if (GET_CODE (operands[2]) != CONST_INT)
8389           abort ();
8390         if (INTVAL (operands[2]) == 0xff)
8391           mode = QImode;
8392         else if (INTVAL (operands[2]) == 0xffff)
8393           mode = HImode;
8394         else
8395           abort ();
8396         
8397         operands[1] = gen_lowpart (mode, operands[1]);
8398         if (mode == QImode)
8399           return "movz{bq|x}\t{%1,%0|%0, %1}";
8400         else
8401           return "movz{wq|x}\t{%1,%0|%0, %1}";
8402       }
8403
8404     default:
8405       if (! rtx_equal_p (operands[0], operands[1]))
8406         abort ();
8407       if (get_attr_mode (insn) == MODE_SI)
8408         return "and{l}\t{%k2, %k0|%k0, %k2}";
8409       else
8410         return "and{q}\t{%2, %0|%0, %2}";
8411     }
8412 }
8413   [(set_attr "type" "alu,alu,alu,imovx")
8414    (set_attr "length_immediate" "*,*,*,0")
8415    (set_attr "mode" "SI,DI,DI,DI")])
8416
8417 (define_insn "*anddi_2"
8418   [(set (reg 17)
8419         (compare (and:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0,0")
8420                          (match_operand:DI 2 "x86_64_szext_general_operand" "Z,rem,re"))
8421                  (const_int 0)))
8422    (set (match_operand:DI 0 "nonimmediate_operand" "=r,r,rm")
8423         (and:DI (match_dup 1) (match_dup 2)))]
8424   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8425    && ix86_binary_operator_ok (AND, DImode, operands)"
8426   "@
8427    and{l}\t{%k2, %k0|%k0, %k2} 
8428    and{q}\t{%2, %0|%0, %2} 
8429    and{q}\t{%2, %0|%0, %2}"
8430   [(set_attr "type" "alu")
8431    (set_attr "mode" "SI,DI,DI")])
8432
8433 (define_expand "andsi3"
8434   [(set (match_operand:SI 0 "nonimmediate_operand" "")
8435         (and:SI (match_operand:SI 1 "nonimmediate_operand" "")
8436                 (match_operand:SI 2 "general_operand" "")))
8437    (clobber (reg:CC 17))]
8438   ""
8439   "ix86_expand_binary_operator (AND, SImode, operands); DONE;")
8440
8441 (define_insn "*andsi_1"
8442   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r,r")
8443         (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,qm")
8444                 (match_operand:SI 2 "general_operand" "ri,rm,L")))
8445    (clobber (reg:CC 17))]
8446   "ix86_binary_operator_ok (AND, SImode, operands)"
8447 {
8448   switch (get_attr_type (insn))
8449     {
8450     case TYPE_IMOVX:
8451       {
8452         enum machine_mode mode;
8453
8454         if (GET_CODE (operands[2]) != CONST_INT)
8455           abort ();
8456         if (INTVAL (operands[2]) == 0xff)
8457           mode = QImode;
8458         else if (INTVAL (operands[2]) == 0xffff)
8459           mode = HImode;
8460         else
8461           abort ();
8462         
8463         operands[1] = gen_lowpart (mode, operands[1]);
8464         if (mode == QImode)
8465           return "movz{bl|x}\t{%1,%0|%0, %1}";
8466         else
8467           return "movz{wl|x}\t{%1,%0|%0, %1}";
8468       }
8469
8470     default:
8471       if (! rtx_equal_p (operands[0], operands[1]))
8472         abort ();
8473       return "and{l}\t{%2, %0|%0, %2}";
8474     }
8475 }
8476   [(set_attr "type" "alu,alu,imovx")
8477    (set_attr "length_immediate" "*,*,0")
8478    (set_attr "mode" "SI")])
8479
8480 (define_split
8481   [(set (match_operand 0 "register_operand" "")
8482         (and (match_dup 0)
8483              (const_int -65536)))
8484    (clobber (reg:CC 17))]
8485   "optimize_size || (TARGET_FAST_PREFIX && !TARGET_PARTIAL_REG_STALL)"
8486   [(set (strict_low_part (match_dup 1)) (const_int 0))]
8487   "operands[1] = gen_lowpart (HImode, operands[0]);")
8488
8489 (define_split
8490   [(set (match_operand 0 "ext_register_operand" "")
8491         (and (match_dup 0)
8492              (const_int -256)))
8493    (clobber (reg:CC 17))]
8494   "(optimize_size || !TARGET_PARTIAL_REG_STALL) && reload_completed"
8495   [(set (strict_low_part (match_dup 1)) (const_int 0))]
8496   "operands[1] = gen_lowpart (QImode, operands[0]);")
8497
8498 (define_split
8499   [(set (match_operand 0 "ext_register_operand" "")
8500         (and (match_dup 0)
8501              (const_int -65281)))
8502    (clobber (reg:CC 17))]
8503   "(optimize_size || !TARGET_PARTIAL_REG_STALL) && reload_completed"
8504   [(parallel [(set (zero_extract:SI (match_dup 0)
8505                                     (const_int 8)
8506                                     (const_int 8))
8507                    (xor:SI 
8508                      (zero_extract:SI (match_dup 0)
8509                                       (const_int 8)
8510                                       (const_int 8))
8511                      (zero_extract:SI (match_dup 0)
8512                                       (const_int 8)
8513                                       (const_int 8))))
8514               (clobber (reg:CC 17))])]
8515   "operands[0] = gen_lowpart (SImode, operands[0]);")
8516
8517 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8518 (define_insn "*andsi_1_zext"
8519   [(set (match_operand:DI 0 "register_operand" "=r")
8520         (zero_extend:DI
8521           (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8522                   (match_operand:SI 2 "general_operand" "rim"))))
8523    (clobber (reg:CC 17))]
8524   "TARGET_64BIT && ix86_binary_operator_ok (AND, SImode, operands)"
8525   "and{l}\t{%2, %k0|%k0, %2}"
8526   [(set_attr "type" "alu")
8527    (set_attr "mode" "SI")])
8528
8529 (define_insn "*andsi_2"
8530   [(set (reg 17)
8531         (compare (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0")
8532                          (match_operand:SI 2 "general_operand" "rim,ri"))
8533                  (const_int 0)))
8534    (set (match_operand:SI 0 "nonimmediate_operand" "=r,rm")
8535         (and:SI (match_dup 1) (match_dup 2)))]
8536   "ix86_match_ccmode (insn, CCNOmode)
8537    && ix86_binary_operator_ok (AND, SImode, operands)"
8538   "and{l}\t{%2, %0|%0, %2}"
8539   [(set_attr "type" "alu")
8540    (set_attr "mode" "SI")])
8541
8542 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8543 (define_insn "*andsi_2_zext"
8544   [(set (reg 17)
8545         (compare (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8546                          (match_operand:SI 2 "general_operand" "rim"))
8547                  (const_int 0)))
8548    (set (match_operand:DI 0 "register_operand" "=r")
8549         (zero_extend:DI (and:SI (match_dup 1) (match_dup 2))))]
8550   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8551    && ix86_binary_operator_ok (AND, SImode, operands)"
8552   "and{l}\t{%2, %k0|%k0, %2}"
8553   [(set_attr "type" "alu")
8554    (set_attr "mode" "SI")])
8555
8556 (define_expand "andhi3"
8557   [(set (match_operand:HI 0 "nonimmediate_operand" "")
8558         (and:HI (match_operand:HI 1 "nonimmediate_operand" "")
8559                 (match_operand:HI 2 "general_operand" "")))
8560    (clobber (reg:CC 17))]
8561   "TARGET_HIMODE_MATH"
8562   "ix86_expand_binary_operator (AND, HImode, operands); DONE;")
8563
8564 (define_insn "*andhi_1"
8565   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r,r")
8566         (and:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,qm")
8567                 (match_operand:HI 2 "general_operand" "ri,rm,L")))
8568    (clobber (reg:CC 17))]
8569   "ix86_binary_operator_ok (AND, HImode, operands)"
8570 {
8571   switch (get_attr_type (insn))
8572     {
8573     case TYPE_IMOVX:
8574       if (GET_CODE (operands[2]) != CONST_INT)
8575         abort ();
8576       if (INTVAL (operands[2]) == 0xff)
8577         return "movz{bl|x}\t{%b1, %k0|%k0, %b1}";
8578       abort ();
8579
8580     default:
8581       if (! rtx_equal_p (operands[0], operands[1]))
8582         abort ();
8583
8584       return "and{w}\t{%2, %0|%0, %2}";
8585     }
8586 }
8587   [(set_attr "type" "alu,alu,imovx")
8588    (set_attr "length_immediate" "*,*,0")
8589    (set_attr "mode" "HI,HI,SI")])
8590
8591 (define_insn "*andhi_2"
8592   [(set (reg 17)
8593         (compare (and:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
8594                          (match_operand:HI 2 "general_operand" "rim,ri"))
8595                  (const_int 0)))
8596    (set (match_operand:HI 0 "nonimmediate_operand" "=r,rm")
8597         (and:HI (match_dup 1) (match_dup 2)))]
8598   "ix86_match_ccmode (insn, CCNOmode)
8599    && ix86_binary_operator_ok (AND, HImode, operands)"
8600   "and{w}\t{%2, %0|%0, %2}"
8601   [(set_attr "type" "alu")
8602    (set_attr "mode" "HI")])
8603
8604 (define_expand "andqi3"
8605   [(set (match_operand:QI 0 "nonimmediate_operand" "")
8606         (and:QI (match_operand:QI 1 "nonimmediate_operand" "")
8607                 (match_operand:QI 2 "general_operand" "")))
8608    (clobber (reg:CC 17))]
8609   "TARGET_QIMODE_MATH"
8610   "ix86_expand_binary_operator (AND, QImode, operands); DONE;")
8611
8612 ;; %%% Potential partial reg stall on alternative 2.  What to do?
8613 (define_insn "*andqi_1"
8614   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,q,r")
8615         (and:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
8616                 (match_operand:QI 2 "general_operand" "qi,qmi,ri")))
8617    (clobber (reg:CC 17))]
8618   "ix86_binary_operator_ok (AND, QImode, operands)"
8619   "@
8620    and{b}\t{%2, %0|%0, %2}
8621    and{b}\t{%2, %0|%0, %2}
8622    and{l}\t{%k2, %k0|%k0, %k2}"
8623   [(set_attr "type" "alu")
8624    (set_attr "mode" "QI,QI,SI")])
8625
8626 (define_insn "*andqi_1_slp"
8627   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
8628         (and:QI (match_dup 0)
8629                 (match_operand:QI 1 "general_operand" "qi,qmi")))
8630    (clobber (reg:CC 17))]
8631   "(! TARGET_PARTIAL_REG_STALL || optimize_size)
8632    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
8633   "and{b}\t{%1, %0|%0, %1}"
8634   [(set_attr "type" "alu1")
8635    (set_attr "mode" "QI")])
8636
8637 (define_insn "*andqi_2"
8638   [(set (reg 17)
8639         (compare (and:QI
8640                    (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
8641                    (match_operand:QI 2 "general_operand" "qim,qi,i"))
8642                  (const_int 0)))
8643    (set (match_operand:QI 0 "nonimmediate_operand" "=q,qm,*r")
8644         (and:QI (match_dup 1) (match_dup 2)))]
8645   "ix86_match_ccmode (insn, CCNOmode)
8646    && ix86_binary_operator_ok (AND, QImode, operands)"
8647 {
8648   if (which_alternative == 2)
8649     {
8650       if (GET_CODE (operands[2]) == CONST_INT
8651           && (INTVAL (operands[2]) & 0xffffff00))
8652         operands[2] = GEN_INT (INTVAL (operands[2]) & 0xff);
8653       return "and{l}\t{%2, %k0|%k0, %2}";
8654     }
8655   return "and{b}\t{%2, %0|%0, %2}";
8656 }
8657   [(set_attr "type" "alu")
8658    (set_attr "mode" "QI,QI,SI")])
8659
8660 (define_insn "*andqi_2_slp"
8661   [(set (reg 17)
8662         (compare (and:QI
8663                    (match_operand:QI 0 "nonimmediate_operand" "+q,qm")
8664                    (match_operand:QI 1 "nonimmediate_operand" "qmi,qi"))
8665                  (const_int 0)))
8666    (set (strict_low_part (match_dup 0))
8667         (and:QI (match_dup 0) (match_dup 1)))]
8668   "(! TARGET_PARTIAL_REG_STALL || optimize_size)
8669    && ix86_match_ccmode (insn, CCNOmode)
8670    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
8671   "and{b}\t{%1, %0|%0, %1}"
8672   [(set_attr "type" "alu1")
8673    (set_attr "mode" "QI")])
8674
8675 ;; ??? A bug in recog prevents it from recognizing a const_int as an
8676 ;; operand to zero_extend in andqi_ext_1.  It was checking explicitly
8677 ;; for a QImode operand, which of course failed.
8678
8679 (define_insn "andqi_ext_0"
8680   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8681                          (const_int 8)
8682                          (const_int 8))
8683         (and:SI 
8684           (zero_extract:SI
8685             (match_operand 1 "ext_register_operand" "0")
8686             (const_int 8)
8687             (const_int 8))
8688           (match_operand 2 "const_int_operand" "n")))
8689    (clobber (reg:CC 17))]
8690   ""
8691   "and{b}\t{%2, %h0|%h0, %2}"
8692   [(set_attr "type" "alu")
8693    (set_attr "length_immediate" "1")
8694    (set_attr "mode" "QI")])
8695
8696 ;; Generated by peephole translating test to and.  This shows up
8697 ;; often in fp comparisons.
8698
8699 (define_insn "*andqi_ext_0_cc"
8700   [(set (reg 17)
8701         (compare
8702           (and:SI
8703             (zero_extract:SI
8704               (match_operand 1 "ext_register_operand" "0")
8705               (const_int 8)
8706               (const_int 8))
8707             (match_operand 2 "const_int_operand" "n"))
8708           (const_int 0)))
8709    (set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8710                          (const_int 8)
8711                          (const_int 8))
8712         (and:SI 
8713           (zero_extract:SI
8714             (match_dup 1)
8715             (const_int 8)
8716             (const_int 8))
8717           (match_dup 2)))]
8718   "ix86_match_ccmode (insn, CCNOmode)"
8719   "and{b}\t{%2, %h0|%h0, %2}"
8720   [(set_attr "type" "alu")
8721    (set_attr "length_immediate" "1")
8722    (set_attr "mode" "QI")])
8723
8724 (define_insn "*andqi_ext_1"
8725   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8726                          (const_int 8)
8727                          (const_int 8))
8728         (and:SI 
8729           (zero_extract:SI
8730             (match_operand 1 "ext_register_operand" "0")
8731             (const_int 8)
8732             (const_int 8))
8733           (zero_extend:SI
8734             (match_operand:QI 2 "general_operand" "Qm"))))
8735    (clobber (reg:CC 17))]
8736   "!TARGET_64BIT"
8737   "and{b}\t{%2, %h0|%h0, %2}"
8738   [(set_attr "type" "alu")
8739    (set_attr "length_immediate" "0")
8740    (set_attr "mode" "QI")])
8741
8742 (define_insn "*andqi_ext_1_rex64"
8743   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8744                          (const_int 8)
8745                          (const_int 8))
8746         (and:SI 
8747           (zero_extract:SI
8748             (match_operand 1 "ext_register_operand" "0")
8749             (const_int 8)
8750             (const_int 8))
8751           (zero_extend:SI
8752             (match_operand 2 "ext_register_operand" "Q"))))
8753    (clobber (reg:CC 17))]
8754   "TARGET_64BIT"
8755   "and{b}\t{%2, %h0|%h0, %2}"
8756   [(set_attr "type" "alu")
8757    (set_attr "length_immediate" "0")
8758    (set_attr "mode" "QI")])
8759
8760 (define_insn "*andqi_ext_2"
8761   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8762                          (const_int 8)
8763                          (const_int 8))
8764         (and:SI
8765           (zero_extract:SI
8766             (match_operand 1 "ext_register_operand" "%0")
8767             (const_int 8)
8768             (const_int 8))
8769           (zero_extract:SI
8770             (match_operand 2 "ext_register_operand" "Q")
8771             (const_int 8)
8772             (const_int 8))))
8773    (clobber (reg:CC 17))]
8774   ""
8775   "and{b}\t{%h2, %h0|%h0, %h2}"
8776   [(set_attr "type" "alu")
8777    (set_attr "length_immediate" "0")
8778    (set_attr "mode" "QI")])
8779
8780 ;; Convert wide AND instructions with immediate operand to shorter QImode
8781 ;; equivalents when possible.
8782 ;; Don't do the splitting with memory operands, since it introduces risk
8783 ;; of memory mismatch stalls.  We may want to do the splitting for optimizing
8784 ;; for size, but that can (should?) be handled by generic code instead.
8785 (define_split
8786   [(set (match_operand 0 "register_operand" "")
8787         (and (match_operand 1 "register_operand" "")
8788              (match_operand 2 "const_int_operand" "")))
8789    (clobber (reg:CC 17))]
8790    "reload_completed
8791     && QI_REG_P (operands[0])
8792     && (!TARGET_PARTIAL_REG_STALL || optimize_size)
8793     && !(~INTVAL (operands[2]) & ~(255 << 8))
8794     && GET_MODE (operands[0]) != QImode"
8795   [(parallel [(set (zero_extract:SI (match_dup 0) (const_int 8) (const_int 8))
8796                    (and:SI (zero_extract:SI (match_dup 1)
8797                                             (const_int 8) (const_int 8))
8798                            (match_dup 2)))
8799               (clobber (reg:CC 17))])]
8800   "operands[0] = gen_lowpart (SImode, operands[0]);
8801    operands[1] = gen_lowpart (SImode, operands[1]);
8802    operands[2] = gen_int_mode ((INTVAL (operands[2]) >> 8) & 0xff, SImode);")
8803
8804 ;; Since AND can be encoded with sign extended immediate, this is only
8805 ;; profitable when 7th bit is not set.
8806 (define_split
8807   [(set (match_operand 0 "register_operand" "")
8808         (and (match_operand 1 "general_operand" "")
8809              (match_operand 2 "const_int_operand" "")))
8810    (clobber (reg:CC 17))]
8811    "reload_completed
8812     && ANY_QI_REG_P (operands[0])
8813     && (!TARGET_PARTIAL_REG_STALL || optimize_size)
8814     && !(~INTVAL (operands[2]) & ~255)
8815     && !(INTVAL (operands[2]) & 128)
8816     && GET_MODE (operands[0]) != QImode"
8817   [(parallel [(set (strict_low_part (match_dup 0))
8818                    (and:QI (match_dup 1)
8819                            (match_dup 2)))
8820               (clobber (reg:CC 17))])]
8821   "operands[0] = gen_lowpart (QImode, operands[0]);
8822    operands[1] = gen_lowpart (QImode, operands[1]);
8823    operands[2] = gen_lowpart (QImode, operands[2]);")
8824 \f
8825 ;; Logical inclusive OR instructions
8826
8827 ;; %%% This used to optimize known byte-wide and operations to memory.
8828 ;; If this is considered useful, it should be done with splitters.
8829
8830 (define_expand "iordi3"
8831   [(set (match_operand:DI 0 "nonimmediate_operand" "")
8832         (ior:DI (match_operand:DI 1 "nonimmediate_operand" "")
8833                 (match_operand:DI 2 "x86_64_general_operand" "")))
8834    (clobber (reg:CC 17))]
8835   "TARGET_64BIT"
8836   "ix86_expand_binary_operator (IOR, DImode, operands); DONE;")
8837
8838 (define_insn "*iordi_1_rex64"
8839   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
8840         (ior:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
8841                 (match_operand:DI 2 "x86_64_general_operand" "re,rme")))
8842    (clobber (reg:CC 17))]
8843   "TARGET_64BIT
8844    && ix86_binary_operator_ok (IOR, DImode, operands)"
8845   "or{q}\t{%2, %0|%0, %2}"
8846   [(set_attr "type" "alu")
8847    (set_attr "mode" "DI")])
8848
8849 (define_insn "*iordi_2_rex64"
8850   [(set (reg 17)
8851         (compare (ior:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
8852                          (match_operand:DI 2 "x86_64_general_operand" "rem,re"))
8853                  (const_int 0)))
8854    (set (match_operand:DI 0 "nonimmediate_operand" "=r,rm")
8855         (ior:DI (match_dup 1) (match_dup 2)))]
8856   "TARGET_64BIT
8857    && ix86_match_ccmode (insn, CCNOmode)
8858    && ix86_binary_operator_ok (IOR, DImode, operands)"
8859   "or{q}\t{%2, %0|%0, %2}"
8860   [(set_attr "type" "alu")
8861    (set_attr "mode" "DI")])
8862
8863 (define_insn "*iordi_3_rex64"
8864   [(set (reg 17)
8865         (compare (ior:DI (match_operand:DI 1 "nonimmediate_operand" "%0")
8866                          (match_operand:DI 2 "x86_64_general_operand" "rem"))
8867                  (const_int 0)))
8868    (clobber (match_scratch:DI 0 "=r"))]
8869   "TARGET_64BIT
8870    && ix86_match_ccmode (insn, CCNOmode)
8871    && ix86_binary_operator_ok (IOR, DImode, operands)"
8872   "or{q}\t{%2, %0|%0, %2}"
8873   [(set_attr "type" "alu")
8874    (set_attr "mode" "DI")])
8875
8876
8877 (define_expand "iorsi3"
8878   [(set (match_operand:SI 0 "nonimmediate_operand" "")
8879         (ior:SI (match_operand:SI 1 "nonimmediate_operand" "")
8880                 (match_operand:SI 2 "general_operand" "")))
8881    (clobber (reg:CC 17))]
8882   ""
8883   "ix86_expand_binary_operator (IOR, SImode, operands); DONE;")
8884
8885 (define_insn "*iorsi_1"
8886   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
8887         (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0")
8888                 (match_operand:SI 2 "general_operand" "ri,rmi")))
8889    (clobber (reg:CC 17))]
8890   "ix86_binary_operator_ok (IOR, SImode, operands)"
8891   "or{l}\t{%2, %0|%0, %2}"
8892   [(set_attr "type" "alu")
8893    (set_attr "mode" "SI")])
8894
8895 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8896 (define_insn "*iorsi_1_zext"
8897   [(set (match_operand:DI 0 "register_operand" "=rm")
8898         (zero_extend:DI
8899           (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8900                   (match_operand:SI 2 "general_operand" "rim"))))
8901    (clobber (reg:CC 17))]
8902   "TARGET_64BIT && ix86_binary_operator_ok (IOR, SImode, operands)"
8903   "or{l}\t{%2, %k0|%k0, %2}"
8904   [(set_attr "type" "alu")
8905    (set_attr "mode" "SI")])
8906
8907 (define_insn "*iorsi_1_zext_imm"
8908   [(set (match_operand:DI 0 "register_operand" "=rm")
8909         (ior:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "%0"))
8910                 (match_operand:DI 2 "x86_64_zext_immediate_operand" "Z")))
8911    (clobber (reg:CC 17))]
8912   "TARGET_64BIT"
8913   "or{l}\t{%2, %k0|%k0, %2}"
8914   [(set_attr "type" "alu")
8915    (set_attr "mode" "SI")])
8916
8917 (define_insn "*iorsi_2"
8918   [(set (reg 17)
8919         (compare (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0")
8920                          (match_operand:SI 2 "general_operand" "rim,ri"))
8921                  (const_int 0)))
8922    (set (match_operand:SI 0 "nonimmediate_operand" "=r,rm")
8923         (ior:SI (match_dup 1) (match_dup 2)))]
8924   "ix86_match_ccmode (insn, CCNOmode)
8925    && ix86_binary_operator_ok (IOR, SImode, operands)"
8926   "or{l}\t{%2, %0|%0, %2}"
8927   [(set_attr "type" "alu")
8928    (set_attr "mode" "SI")])
8929
8930 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8931 ;; ??? Special case for immediate operand is missing - it is tricky.
8932 (define_insn "*iorsi_2_zext"
8933   [(set (reg 17)
8934         (compare (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8935                          (match_operand:SI 2 "general_operand" "rim"))
8936                  (const_int 0)))
8937    (set (match_operand:DI 0 "register_operand" "=r")
8938         (zero_extend:DI (ior:SI (match_dup 1) (match_dup 2))))]
8939   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8940    && ix86_binary_operator_ok (IOR, SImode, operands)"
8941   "or{l}\t{%2, %k0|%k0, %2}"
8942   [(set_attr "type" "alu")
8943    (set_attr "mode" "SI")])
8944
8945 (define_insn "*iorsi_2_zext_imm"
8946   [(set (reg 17)
8947         (compare (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8948                          (match_operand 2 "x86_64_zext_immediate_operand" "Z"))
8949                  (const_int 0)))
8950    (set (match_operand:DI 0 "register_operand" "=r")
8951         (ior:DI (zero_extend:DI (match_dup 1)) (match_dup 2)))]
8952   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8953    && ix86_binary_operator_ok (IOR, SImode, operands)"
8954   "or{l}\t{%2, %k0|%k0, %2}"
8955   [(set_attr "type" "alu")
8956    (set_attr "mode" "SI")])
8957
8958 (define_insn "*iorsi_3"
8959   [(set (reg 17)
8960         (compare (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8961                          (match_operand:SI 2 "general_operand" "rim"))
8962                  (const_int 0)))
8963    (clobber (match_scratch:SI 0 "=r"))]
8964   "ix86_match_ccmode (insn, CCNOmode)
8965    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
8966   "or{l}\t{%2, %0|%0, %2}"
8967   [(set_attr "type" "alu")
8968    (set_attr "mode" "SI")])
8969
8970 (define_expand "iorhi3"
8971   [(set (match_operand:HI 0 "nonimmediate_operand" "")
8972         (ior:HI (match_operand:HI 1 "nonimmediate_operand" "")
8973                 (match_operand:HI 2 "general_operand" "")))
8974    (clobber (reg:CC 17))]
8975   "TARGET_HIMODE_MATH"
8976   "ix86_expand_binary_operator (IOR, HImode, operands); DONE;")
8977
8978 (define_insn "*iorhi_1"
8979   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,m")
8980         (ior:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
8981                 (match_operand:HI 2 "general_operand" "rmi,ri")))
8982    (clobber (reg:CC 17))]
8983   "ix86_binary_operator_ok (IOR, HImode, operands)"
8984   "or{w}\t{%2, %0|%0, %2}"
8985   [(set_attr "type" "alu")
8986    (set_attr "mode" "HI")])
8987
8988 (define_insn "*iorhi_2"
8989   [(set (reg 17)
8990         (compare (ior:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
8991                          (match_operand:HI 2 "general_operand" "rim,ri"))
8992                  (const_int 0)))
8993    (set (match_operand:HI 0 "nonimmediate_operand" "=r,rm")
8994         (ior:HI (match_dup 1) (match_dup 2)))]
8995   "ix86_match_ccmode (insn, CCNOmode)
8996    && ix86_binary_operator_ok (IOR, HImode, operands)"
8997   "or{w}\t{%2, %0|%0, %2}"
8998   [(set_attr "type" "alu")
8999    (set_attr "mode" "HI")])
9000
9001 (define_insn "*iorhi_3"
9002   [(set (reg 17)
9003         (compare (ior:HI (match_operand:HI 1 "nonimmediate_operand" "%0")
9004                          (match_operand:HI 2 "general_operand" "rim"))
9005                  (const_int 0)))
9006    (clobber (match_scratch:HI 0 "=r"))]
9007   "ix86_match_ccmode (insn, CCNOmode)
9008    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
9009   "or{w}\t{%2, %0|%0, %2}"
9010   [(set_attr "type" "alu")
9011    (set_attr "mode" "HI")])
9012
9013 (define_expand "iorqi3"
9014   [(set (match_operand:QI 0 "nonimmediate_operand" "")
9015         (ior:QI (match_operand:QI 1 "nonimmediate_operand" "")
9016                 (match_operand:QI 2 "general_operand" "")))
9017    (clobber (reg:CC 17))]
9018   "TARGET_QIMODE_MATH"
9019   "ix86_expand_binary_operator (IOR, QImode, operands); DONE;")
9020
9021 ;; %%% Potential partial reg stall on alternative 2.  What to do?
9022 (define_insn "*iorqi_1"
9023   [(set (match_operand:QI 0 "nonimmediate_operand" "=q,m,r")
9024         (ior:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
9025                 (match_operand:QI 2 "general_operand" "qmi,qi,ri")))
9026    (clobber (reg:CC 17))]
9027   "ix86_binary_operator_ok (IOR, QImode, operands)"
9028   "@
9029    or{b}\t{%2, %0|%0, %2}
9030    or{b}\t{%2, %0|%0, %2}
9031    or{l}\t{%k2, %k0|%k0, %k2}"
9032   [(set_attr "type" "alu")
9033    (set_attr "mode" "QI,QI,SI")])
9034
9035 (define_insn "*iorqi_1_slp"
9036   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+q,m"))
9037         (ior:QI (match_dup 0)
9038                 (match_operand:QI 1 "general_operand" "qmi,qi")))
9039    (clobber (reg:CC 17))]
9040   "(! TARGET_PARTIAL_REG_STALL || optimize_size)
9041    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
9042   "or{b}\t{%1, %0|%0, %1}"
9043   [(set_attr "type" "alu1")
9044    (set_attr "mode" "QI")])
9045
9046 (define_insn "*iorqi_2"
9047   [(set (reg 17)
9048         (compare (ior:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0")
9049                          (match_operand:QI 2 "general_operand" "qim,qi"))
9050                  (const_int 0)))
9051    (set (match_operand:QI 0 "nonimmediate_operand" "=q,qm")
9052         (ior:QI (match_dup 1) (match_dup 2)))]
9053   "ix86_match_ccmode (insn, CCNOmode)
9054    && ix86_binary_operator_ok (IOR, QImode, operands)"
9055   "or{b}\t{%2, %0|%0, %2}"
9056   [(set_attr "type" "alu")
9057    (set_attr "mode" "QI")])
9058
9059 (define_insn "*iorqi_2_slp"
9060   [(set (reg 17)
9061         (compare (ior:QI (match_operand:QI 0 "nonimmediate_operand" "+q,qm")
9062                          (match_operand:QI 1 "general_operand" "qim,qi"))
9063                  (const_int 0)))
9064    (set (strict_low_part (match_dup 0))
9065         (ior:QI (match_dup 0) (match_dup 1)))]
9066   "(! TARGET_PARTIAL_REG_STALL || optimize_size)
9067    && ix86_match_ccmode (insn, CCNOmode)
9068    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
9069   "or{b}\t{%1, %0|%0, %1}"
9070   [(set_attr "type" "alu1")
9071    (set_attr "mode" "QI")])
9072
9073 (define_insn "*iorqi_3"
9074   [(set (reg 17)
9075         (compare (ior:QI (match_operand:QI 1 "nonimmediate_operand" "%0")
9076                          (match_operand:QI 2 "general_operand" "qim"))
9077                  (const_int 0)))
9078    (clobber (match_scratch:QI 0 "=q"))]
9079   "ix86_match_ccmode (insn, CCNOmode)
9080    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
9081   "or{b}\t{%2, %0|%0, %2}"
9082   [(set_attr "type" "alu")
9083    (set_attr "mode" "QI")])
9084
9085 (define_insn "iorqi_ext_0"
9086   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9087                          (const_int 8)
9088                          (const_int 8))
9089         (ior:SI 
9090           (zero_extract:SI
9091             (match_operand 1 "ext_register_operand" "0")
9092             (const_int 8)
9093             (const_int 8))
9094           (match_operand 2 "const_int_operand" "n")))
9095    (clobber (reg:CC 17))]
9096   "(!TARGET_PARTIAL_REG_STALL || optimize_size)"
9097   "or{b}\t{%2, %h0|%h0, %2}"
9098   [(set_attr "type" "alu")
9099    (set_attr "length_immediate" "1")
9100    (set_attr "mode" "QI")])
9101
9102 (define_insn "*iorqi_ext_1"
9103   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9104                          (const_int 8)
9105                          (const_int 8))
9106         (ior:SI 
9107           (zero_extract:SI
9108             (match_operand 1 "ext_register_operand" "0")
9109             (const_int 8)
9110             (const_int 8))
9111           (zero_extend:SI
9112             (match_operand:QI 2 "general_operand" "Qm"))))
9113    (clobber (reg:CC 17))]
9114   "!TARGET_64BIT
9115    && (!TARGET_PARTIAL_REG_STALL || optimize_size)"
9116   "or{b}\t{%2, %h0|%h0, %2}"
9117   [(set_attr "type" "alu")
9118    (set_attr "length_immediate" "0")
9119    (set_attr "mode" "QI")])
9120
9121 (define_insn "*iorqi_ext_1_rex64"
9122   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9123                          (const_int 8)
9124                          (const_int 8))
9125         (ior:SI 
9126           (zero_extract:SI
9127             (match_operand 1 "ext_register_operand" "0")
9128             (const_int 8)
9129             (const_int 8))
9130           (zero_extend:SI
9131             (match_operand 2 "ext_register_operand" "Q"))))
9132    (clobber (reg:CC 17))]
9133   "TARGET_64BIT
9134    && (!TARGET_PARTIAL_REG_STALL || optimize_size)"
9135   "or{b}\t{%2, %h0|%h0, %2}"
9136   [(set_attr "type" "alu")
9137    (set_attr "length_immediate" "0")
9138    (set_attr "mode" "QI")])
9139
9140 (define_insn "*iorqi_ext_2"
9141   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9142                          (const_int 8)
9143                          (const_int 8))
9144         (ior:SI 
9145           (zero_extract:SI (match_operand 1 "ext_register_operand" "0")
9146                            (const_int 8)
9147                            (const_int 8))
9148           (zero_extract:SI (match_operand 2 "ext_register_operand" "Q")
9149                            (const_int 8)
9150                            (const_int 8))))
9151    (clobber (reg:CC 17))]
9152   "(!TARGET_PARTIAL_REG_STALL || optimize_size)"
9153   "ior{b}\t{%h2, %h0|%h0, %h2}"
9154   [(set_attr "type" "alu")
9155    (set_attr "length_immediate" "0")
9156    (set_attr "mode" "QI")])
9157
9158 (define_split
9159   [(set (match_operand 0 "register_operand" "")
9160         (ior (match_operand 1 "register_operand" "")
9161              (match_operand 2 "const_int_operand" "")))
9162    (clobber (reg:CC 17))]
9163    "reload_completed
9164     && QI_REG_P (operands[0])
9165     && (!TARGET_PARTIAL_REG_STALL || optimize_size)
9166     && !(INTVAL (operands[2]) & ~(255 << 8))
9167     && GET_MODE (operands[0]) != QImode"
9168   [(parallel [(set (zero_extract:SI (match_dup 0) (const_int 8) (const_int 8))
9169                    (ior:SI (zero_extract:SI (match_dup 1)
9170                                             (const_int 8) (const_int 8))
9171                            (match_dup 2)))
9172               (clobber (reg:CC 17))])]
9173   "operands[0] = gen_lowpart (SImode, operands[0]);
9174    operands[1] = gen_lowpart (SImode, operands[1]);
9175    operands[2] = gen_int_mode ((INTVAL (operands[2]) >> 8) & 0xff, SImode);")
9176
9177 ;; Since OR can be encoded with sign extended immediate, this is only
9178 ;; profitable when 7th bit is set.
9179 (define_split
9180   [(set (match_operand 0 "register_operand" "")
9181         (ior (match_operand 1 "general_operand" "")
9182              (match_operand 2 "const_int_operand" "")))
9183    (clobber (reg:CC 17))]
9184    "reload_completed
9185     && ANY_QI_REG_P (operands[0])
9186     && (!TARGET_PARTIAL_REG_STALL || optimize_size)
9187     && !(INTVAL (operands[2]) & ~255)
9188     && (INTVAL (operands[2]) & 128)
9189     && GET_MODE (operands[0]) != QImode"
9190   [(parallel [(set (strict_low_part (match_dup 0))
9191                    (ior:QI (match_dup 1)
9192                            (match_dup 2)))
9193               (clobber (reg:CC 17))])]
9194   "operands[0] = gen_lowpart (QImode, operands[0]);
9195    operands[1] = gen_lowpart (QImode, operands[1]);
9196    operands[2] = gen_lowpart (QImode, operands[2]);")
9197 \f
9198 ;; Logical XOR instructions
9199
9200 ;; %%% This used to optimize known byte-wide and operations to memory.
9201 ;; If this is considered useful, it should be done with splitters.
9202
9203 (define_expand "xordi3"
9204   [(set (match_operand:DI 0 "nonimmediate_operand" "")
9205         (xor:DI (match_operand:DI 1 "nonimmediate_operand" "")
9206                 (match_operand:DI 2 "x86_64_general_operand" "")))
9207    (clobber (reg:CC 17))]
9208   "TARGET_64BIT"
9209   "ix86_expand_binary_operator (XOR, DImode, operands); DONE;")
9210
9211 (define_insn "*xordi_1_rex64"
9212   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
9213         (xor:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
9214                 (match_operand:DI 2 "x86_64_general_operand" "re,rm")))
9215    (clobber (reg:CC 17))]
9216   "TARGET_64BIT
9217    && ix86_binary_operator_ok (XOR, DImode, operands)"
9218   "@
9219    xor{q}\t{%2, %0|%0, %2} 
9220    xor{q}\t{%2, %0|%0, %2}"
9221   [(set_attr "type" "alu")
9222    (set_attr "mode" "DI,DI")])
9223
9224 (define_insn "*xordi_2_rex64"
9225   [(set (reg 17)
9226         (compare (xor:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
9227                          (match_operand:DI 2 "x86_64_general_operand" "rem,re"))
9228                  (const_int 0)))
9229    (set (match_operand:DI 0 "nonimmediate_operand" "=r,rm")
9230         (xor:DI (match_dup 1) (match_dup 2)))]
9231   "TARGET_64BIT
9232    && ix86_match_ccmode (insn, CCNOmode)
9233    && ix86_binary_operator_ok (XOR, DImode, operands)"
9234   "@
9235    xor{q}\t{%2, %0|%0, %2} 
9236    xor{q}\t{%2, %0|%0, %2}"
9237   [(set_attr "type" "alu")
9238    (set_attr "mode" "DI,DI")])
9239
9240 (define_insn "*xordi_3_rex64"
9241   [(set (reg 17)
9242         (compare (xor:DI (match_operand:DI 1 "nonimmediate_operand" "%0")
9243                          (match_operand:DI 2 "x86_64_general_operand" "rem"))
9244                  (const_int 0)))
9245    (clobber (match_scratch:DI 0 "=r"))]
9246   "TARGET_64BIT
9247    && ix86_match_ccmode (insn, CCNOmode)
9248    && ix86_binary_operator_ok (XOR, DImode, operands)"
9249   "xor{q}\t{%2, %0|%0, %2}"
9250   [(set_attr "type" "alu")
9251    (set_attr "mode" "DI")])
9252
9253 (define_expand "xorsi3"
9254   [(set (match_operand:SI 0 "nonimmediate_operand" "")
9255         (xor:SI (match_operand:SI 1 "nonimmediate_operand" "")
9256                 (match_operand:SI 2 "general_operand" "")))
9257    (clobber (reg:CC 17))]
9258   ""
9259   "ix86_expand_binary_operator (XOR, SImode, operands); DONE;")
9260
9261 (define_insn "*xorsi_1"
9262   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
9263         (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0")
9264                 (match_operand:SI 2 "general_operand" "ri,rm")))
9265    (clobber (reg:CC 17))]
9266   "ix86_binary_operator_ok (XOR, SImode, operands)"
9267   "xor{l}\t{%2, %0|%0, %2}"
9268   [(set_attr "type" "alu")
9269    (set_attr "mode" "SI")])
9270
9271 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
9272 ;; Add speccase for immediates
9273 (define_insn "*xorsi_1_zext"
9274   [(set (match_operand:DI 0 "register_operand" "=r")
9275         (zero_extend:DI
9276           (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
9277                   (match_operand:SI 2 "general_operand" "rim"))))
9278    (clobber (reg:CC 17))]
9279   "TARGET_64BIT && ix86_binary_operator_ok (XOR, SImode, operands)"
9280   "xor{l}\t{%2, %k0|%k0, %2}"
9281   [(set_attr "type" "alu")
9282    (set_attr "mode" "SI")])
9283
9284 (define_insn "*xorsi_1_zext_imm"
9285   [(set (match_operand:DI 0 "register_operand" "=r")
9286         (xor:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "%0"))
9287                 (match_operand:DI 2 "x86_64_zext_immediate_operand" "Z")))
9288    (clobber (reg:CC 17))]
9289   "TARGET_64BIT && ix86_binary_operator_ok (XOR, SImode, operands)"
9290   "xor{l}\t{%2, %k0|%k0, %2}"
9291   [(set_attr "type" "alu")
9292    (set_attr "mode" "SI")])
9293
9294 (define_insn "*xorsi_2"
9295   [(set (reg 17)
9296         (compare (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0")
9297                          (match_operand:SI 2 "general_operand" "rim,ri"))
9298                  (const_int 0)))
9299    (set (match_operand:SI 0 "nonimmediate_operand" "=r,rm")
9300         (xor:SI (match_dup 1) (match_dup 2)))]
9301   "ix86_match_ccmode (insn, CCNOmode)
9302    && ix86_binary_operator_ok (XOR, SImode, operands)"
9303   "xor{l}\t{%2, %0|%0, %2}"
9304   [(set_attr "type" "alu")
9305    (set_attr "mode" "SI")])
9306
9307 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
9308 ;; ??? Special case for immediate operand is missing - it is tricky.
9309 (define_insn "*xorsi_2_zext"
9310   [(set (reg 17)
9311         (compare (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
9312                          (match_operand:SI 2 "general_operand" "rim"))
9313                  (const_int 0)))
9314    (set (match_operand:DI 0 "register_operand" "=r")
9315         (zero_extend:DI (xor:SI (match_dup 1) (match_dup 2))))]
9316   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
9317    && ix86_binary_operator_ok (XOR, SImode, operands)"
9318   "xor{l}\t{%2, %k0|%k0, %2}"
9319   [(set_attr "type" "alu")
9320    (set_attr "mode" "SI")])
9321
9322 (define_insn "*xorsi_2_zext_imm"
9323   [(set (reg 17)
9324         (compare (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
9325                          (match_operand 2 "x86_64_zext_immediate_operand" "Z"))
9326                  (const_int 0)))
9327    (set (match_operand:DI 0 "register_operand" "=r")
9328         (xor:DI (zero_extend:DI (match_dup 1)) (match_dup 2)))]
9329   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
9330    && ix86_binary_operator_ok (XOR, SImode, operands)"
9331   "xor{l}\t{%2, %k0|%k0, %2}"
9332   [(set_attr "type" "alu")
9333    (set_attr "mode" "SI")])
9334
9335 (define_insn "*xorsi_3"
9336   [(set (reg 17)
9337         (compare (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
9338                          (match_operand:SI 2 "general_operand" "rim"))
9339                  (const_int 0)))
9340    (clobber (match_scratch:SI 0 "=r"))]
9341   "ix86_match_ccmode (insn, CCNOmode)
9342    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
9343   "xor{l}\t{%2, %0|%0, %2}"
9344   [(set_attr "type" "alu")
9345    (set_attr "mode" "SI")])
9346
9347 (define_expand "xorhi3"
9348   [(set (match_operand:HI 0 "nonimmediate_operand" "")
9349         (xor:HI (match_operand:HI 1 "nonimmediate_operand" "")
9350                 (match_operand:HI 2 "general_operand" "")))
9351    (clobber (reg:CC 17))]
9352   "TARGET_HIMODE_MATH"
9353   "ix86_expand_binary_operator (XOR, HImode, operands); DONE;")
9354
9355 (define_insn "*xorhi_1"
9356   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,m")
9357         (xor:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
9358                 (match_operand:HI 2 "general_operand" "rmi,ri")))
9359    (clobber (reg:CC 17))]
9360   "ix86_binary_operator_ok (XOR, HImode, operands)"
9361   "xor{w}\t{%2, %0|%0, %2}"
9362   [(set_attr "type" "alu")
9363    (set_attr "mode" "HI")])
9364
9365 (define_insn "*xorhi_2"
9366   [(set (reg 17)
9367         (compare (xor:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
9368                          (match_operand:HI 2 "general_operand" "rim,ri"))
9369                  (const_int 0)))
9370    (set (match_operand:HI 0 "nonimmediate_operand" "=r,rm")
9371         (xor:HI (match_dup 1) (match_dup 2)))]
9372   "ix86_match_ccmode (insn, CCNOmode)
9373    && ix86_binary_operator_ok (XOR, HImode, operands)"
9374   "xor{w}\t{%2, %0|%0, %2}"
9375   [(set_attr "type" "alu")
9376    (set_attr "mode" "HI")])
9377
9378 (define_insn "*xorhi_3"
9379   [(set (reg 17)
9380         (compare (xor:HI (match_operand:HI 1 "nonimmediate_operand" "%0")
9381                          (match_operand:HI 2 "general_operand" "rim"))
9382                  (const_int 0)))
9383    (clobber (match_scratch:HI 0 "=r"))]
9384   "ix86_match_ccmode (insn, CCNOmode)
9385    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
9386   "xor{w}\t{%2, %0|%0, %2}"
9387   [(set_attr "type" "alu")
9388    (set_attr "mode" "HI")])
9389
9390 (define_expand "xorqi3"
9391   [(set (match_operand:QI 0 "nonimmediate_operand" "")
9392         (xor:QI (match_operand:QI 1 "nonimmediate_operand" "")
9393                 (match_operand:QI 2 "general_operand" "")))
9394    (clobber (reg:CC 17))]
9395   "TARGET_QIMODE_MATH"
9396   "ix86_expand_binary_operator (XOR, QImode, operands); DONE;")
9397
9398 ;; %%% Potential partial reg stall on alternative 2.  What to do?
9399 (define_insn "*xorqi_1"
9400   [(set (match_operand:QI 0 "nonimmediate_operand" "=q,m,r")
9401         (xor:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
9402                 (match_operand:QI 2 "general_operand" "qmi,qi,ri")))
9403    (clobber (reg:CC 17))]
9404   "ix86_binary_operator_ok (XOR, QImode, operands)"
9405   "@
9406    xor{b}\t{%2, %0|%0, %2}
9407    xor{b}\t{%2, %0|%0, %2}
9408    xor{l}\t{%k2, %k0|%k0, %k2}"
9409   [(set_attr "type" "alu")
9410    (set_attr "mode" "QI,QI,SI")])
9411
9412 (define_insn "*xorqi_1_slp"
9413   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
9414         (xor:QI (match_dup 0)
9415                 (match_operand:QI 1 "general_operand" "qi,qmi")))
9416    (clobber (reg:CC 17))]
9417   "(! TARGET_PARTIAL_REG_STALL || optimize_size)
9418    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
9419   "xor{b}\t{%1, %0|%0, %1}"
9420   [(set_attr "type" "alu1")
9421    (set_attr "mode" "QI")])
9422
9423 (define_insn "xorqi_ext_0"
9424   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9425                          (const_int 8)
9426                          (const_int 8))
9427         (xor:SI 
9428           (zero_extract:SI
9429             (match_operand 1 "ext_register_operand" "0")
9430             (const_int 8)
9431             (const_int 8))
9432           (match_operand 2 "const_int_operand" "n")))
9433    (clobber (reg:CC 17))]
9434   "(!TARGET_PARTIAL_REG_STALL || optimize_size)"
9435   "xor{b}\t{%2, %h0|%h0, %2}"
9436   [(set_attr "type" "alu")
9437    (set_attr "length_immediate" "1")
9438    (set_attr "mode" "QI")])
9439
9440 (define_insn "*xorqi_ext_1"
9441   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9442                          (const_int 8)
9443                          (const_int 8))
9444         (xor:SI 
9445           (zero_extract:SI
9446             (match_operand 1 "ext_register_operand" "0")
9447             (const_int 8)
9448             (const_int 8))
9449           (zero_extend:SI
9450             (match_operand:QI 2 "general_operand" "Qm"))))
9451    (clobber (reg:CC 17))]
9452   "!TARGET_64BIT
9453    && (!TARGET_PARTIAL_REG_STALL || optimize_size)"
9454   "xor{b}\t{%2, %h0|%h0, %2}"
9455   [(set_attr "type" "alu")
9456    (set_attr "length_immediate" "0")
9457    (set_attr "mode" "QI")])
9458
9459 (define_insn "*xorqi_ext_1_rex64"
9460   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9461                          (const_int 8)
9462                          (const_int 8))
9463         (xor:SI 
9464           (zero_extract:SI
9465             (match_operand 1 "ext_register_operand" "0")
9466             (const_int 8)
9467             (const_int 8))
9468           (zero_extend:SI
9469             (match_operand 2 "ext_register_operand" "Q"))))
9470    (clobber (reg:CC 17))]
9471   "TARGET_64BIT
9472    && (!TARGET_PARTIAL_REG_STALL || optimize_size)"
9473   "xor{b}\t{%2, %h0|%h0, %2}"
9474   [(set_attr "type" "alu")
9475    (set_attr "length_immediate" "0")
9476    (set_attr "mode" "QI")])
9477
9478 (define_insn "*xorqi_ext_2"
9479   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9480                          (const_int 8)
9481                          (const_int 8))
9482         (xor:SI 
9483           (zero_extract:SI (match_operand 1 "ext_register_operand" "0")
9484                            (const_int 8)
9485                            (const_int 8))
9486           (zero_extract:SI (match_operand 2 "ext_register_operand" "Q")
9487                            (const_int 8)
9488                            (const_int 8))))
9489    (clobber (reg:CC 17))]
9490   "(!TARGET_PARTIAL_REG_STALL || optimize_size)"
9491   "xor{b}\t{%h2, %h0|%h0, %h2}"
9492   [(set_attr "type" "alu")
9493    (set_attr "length_immediate" "0")
9494    (set_attr "mode" "QI")])
9495
9496 (define_insn "*xorqi_cc_1"
9497   [(set (reg 17)
9498         (compare
9499           (xor:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0")
9500                   (match_operand:QI 2 "general_operand" "qim,qi"))
9501           (const_int 0)))
9502    (set (match_operand:QI 0 "nonimmediate_operand" "=q,qm")
9503         (xor:QI (match_dup 1) (match_dup 2)))]
9504   "ix86_match_ccmode (insn, CCNOmode)
9505    && ix86_binary_operator_ok (XOR, QImode, operands)"
9506   "xor{b}\t{%2, %0|%0, %2}"
9507   [(set_attr "type" "alu")
9508    (set_attr "mode" "QI")])
9509
9510 (define_insn "*xorqi_2_slp"
9511   [(set (reg 17)
9512         (compare (xor:QI (match_operand:QI 0 "nonimmediate_operand" "+q,qm")
9513                          (match_operand:QI 1 "general_operand" "qim,qi"))
9514                  (const_int 0)))
9515    (set (strict_low_part (match_dup 0))
9516         (xor:QI (match_dup 0) (match_dup 1)))]
9517   "(! TARGET_PARTIAL_REG_STALL || optimize_size)
9518    && ix86_match_ccmode (insn, CCNOmode)
9519    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
9520   "xor{b}\t{%1, %0|%0, %1}"
9521   [(set_attr "type" "alu1")
9522    (set_attr "mode" "QI")])
9523
9524 (define_insn "*xorqi_cc_2"
9525   [(set (reg 17)
9526         (compare
9527           (xor:QI (match_operand:QI 1 "nonimmediate_operand" "%0")
9528                   (match_operand:QI 2 "general_operand" "qim"))
9529           (const_int 0)))
9530    (clobber (match_scratch:QI 0 "=q"))]
9531   "ix86_match_ccmode (insn, CCNOmode)
9532    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
9533   "xor{b}\t{%2, %0|%0, %2}"
9534   [(set_attr "type" "alu")
9535    (set_attr "mode" "QI")])
9536
9537 (define_insn "*xorqi_cc_ext_1"
9538   [(set (reg 17)
9539         (compare
9540           (xor:SI
9541             (zero_extract:SI
9542               (match_operand 1 "ext_register_operand" "0")
9543               (const_int 8)
9544               (const_int 8))
9545             (match_operand:QI 2 "general_operand" "qmn"))
9546           (const_int 0)))
9547    (set (zero_extract:SI (match_operand 0 "ext_register_operand" "=q")
9548                          (const_int 8)
9549                          (const_int 8))
9550         (xor:SI 
9551           (zero_extract:SI (match_dup 1) (const_int 8) (const_int 8))
9552           (match_dup 2)))]
9553   "!TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
9554   "xor{b}\t{%2, %h0|%h0, %2}"
9555   [(set_attr "type" "alu")
9556    (set_attr "mode" "QI")])
9557
9558 (define_insn "*xorqi_cc_ext_1_rex64"
9559   [(set (reg 17)
9560         (compare
9561           (xor:SI
9562             (zero_extract:SI
9563               (match_operand 1 "ext_register_operand" "0")
9564               (const_int 8)
9565               (const_int 8))
9566             (match_operand:QI 2 "nonmemory_operand" "Qn"))
9567           (const_int 0)))
9568    (set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9569                          (const_int 8)
9570                          (const_int 8))
9571         (xor:SI 
9572           (zero_extract:SI (match_dup 1) (const_int 8) (const_int 8))
9573           (match_dup 2)))]
9574   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
9575   "xor{b}\t{%2, %h0|%h0, %2}"
9576   [(set_attr "type" "alu")
9577    (set_attr "mode" "QI")])
9578
9579 (define_expand "xorqi_cc_ext_1"
9580   [(parallel [
9581      (set (reg:CCNO 17)
9582           (compare:CCNO
9583             (xor:SI
9584               (zero_extract:SI
9585                 (match_operand 1 "ext_register_operand" "")
9586                 (const_int 8)
9587                 (const_int 8))
9588               (match_operand:QI 2 "general_operand" ""))
9589             (const_int 0)))
9590      (set (zero_extract:SI (match_operand 0 "ext_register_operand" "")
9591                            (const_int 8)
9592                            (const_int 8))
9593           (xor:SI 
9594             (zero_extract:SI (match_dup 1) (const_int 8) (const_int 8))
9595             (match_dup 2)))])]
9596   ""
9597   "")
9598
9599 (define_split
9600   [(set (match_operand 0 "register_operand" "")
9601         (xor (match_operand 1 "register_operand" "")
9602              (match_operand 2 "const_int_operand" "")))
9603    (clobber (reg:CC 17))]
9604    "reload_completed
9605     && QI_REG_P (operands[0])
9606     && (!TARGET_PARTIAL_REG_STALL || optimize_size)
9607     && !(INTVAL (operands[2]) & ~(255 << 8))
9608     && GET_MODE (operands[0]) != QImode"
9609   [(parallel [(set (zero_extract:SI (match_dup 0) (const_int 8) (const_int 8))
9610                    (xor:SI (zero_extract:SI (match_dup 1)
9611                                             (const_int 8) (const_int 8))
9612                            (match_dup 2)))
9613               (clobber (reg:CC 17))])]
9614   "operands[0] = gen_lowpart (SImode, operands[0]);
9615    operands[1] = gen_lowpart (SImode, operands[1]);
9616    operands[2] = gen_int_mode ((INTVAL (operands[2]) >> 8) & 0xff, SImode);")
9617
9618 ;; Since XOR can be encoded with sign extended immediate, this is only
9619 ;; profitable when 7th bit is set.
9620 (define_split
9621   [(set (match_operand 0 "register_operand" "")
9622         (xor (match_operand 1 "general_operand" "")
9623              (match_operand 2 "const_int_operand" "")))
9624    (clobber (reg:CC 17))]
9625    "reload_completed
9626     && ANY_QI_REG_P (operands[0])
9627     && (!TARGET_PARTIAL_REG_STALL || optimize_size)
9628     && !(INTVAL (operands[2]) & ~255)
9629     && (INTVAL (operands[2]) & 128)
9630     && GET_MODE (operands[0]) != QImode"
9631   [(parallel [(set (strict_low_part (match_dup 0))
9632                    (xor:QI (match_dup 1)
9633                            (match_dup 2)))
9634               (clobber (reg:CC 17))])]
9635   "operands[0] = gen_lowpart (QImode, operands[0]);
9636    operands[1] = gen_lowpart (QImode, operands[1]);
9637    operands[2] = gen_lowpart (QImode, operands[2]);")
9638 \f
9639 ;; Negation instructions
9640
9641 (define_expand "negdi2"
9642   [(parallel [(set (match_operand:DI 0 "nonimmediate_operand" "")
9643                    (neg:DI (match_operand:DI 1 "nonimmediate_operand" "")))
9644               (clobber (reg:CC 17))])]
9645   ""
9646   "ix86_expand_unary_operator (NEG, DImode, operands); DONE;")
9647
9648 (define_insn "*negdi2_1"
9649   [(set (match_operand:DI 0 "nonimmediate_operand" "=ro")
9650         (neg:DI (match_operand:DI 1 "general_operand" "0")))
9651    (clobber (reg:CC 17))]
9652   "!TARGET_64BIT
9653    && ix86_unary_operator_ok (NEG, DImode, operands)"
9654   "#")
9655
9656 (define_split
9657   [(set (match_operand:DI 0 "nonimmediate_operand" "")
9658         (neg:DI (match_operand:DI 1 "general_operand" "")))
9659    (clobber (reg:CC 17))]
9660   "!TARGET_64BIT && reload_completed"
9661   [(parallel
9662     [(set (reg:CCZ 17)
9663           (compare:CCZ (neg:SI (match_dup 2)) (const_int 0)))
9664      (set (match_dup 0) (neg:SI (match_dup 2)))])
9665    (parallel
9666     [(set (match_dup 1)
9667           (plus:SI (plus:SI (ltu:SI (reg:CC 17) (const_int 0))
9668                             (match_dup 3))
9669                    (const_int 0)))
9670      (clobber (reg:CC 17))])
9671    (parallel
9672     [(set (match_dup 1)
9673           (neg:SI (match_dup 1)))
9674      (clobber (reg:CC 17))])]
9675   "split_di (operands+1, 1, operands+2, operands+3);
9676    split_di (operands+0, 1, operands+0, operands+1);")
9677
9678 (define_insn "*negdi2_1_rex64"
9679   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
9680         (neg:DI (match_operand:DI 1 "nonimmediate_operand" "0")))
9681    (clobber (reg:CC 17))]
9682   "TARGET_64BIT && ix86_unary_operator_ok (NEG, DImode, operands)"
9683   "neg{q}\t%0"
9684   [(set_attr "type" "negnot")
9685    (set_attr "mode" "DI")])
9686
9687 ;; The problem with neg is that it does not perform (compare x 0),
9688 ;; it really performs (compare 0 x), which leaves us with the zero
9689 ;; flag being the only useful item.
9690
9691 (define_insn "*negdi2_cmpz_rex64"
9692   [(set (reg:CCZ 17)
9693         (compare:CCZ (neg:DI (match_operand:DI 1 "nonimmediate_operand" "0"))
9694                      (const_int 0)))
9695    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
9696         (neg:DI (match_dup 1)))]
9697   "TARGET_64BIT && ix86_unary_operator_ok (NEG, DImode, operands)"
9698   "neg{q}\t%0"
9699   [(set_attr "type" "negnot")
9700    (set_attr "mode" "DI")])
9701
9702
9703 (define_expand "negsi2"
9704   [(parallel [(set (match_operand:SI 0 "nonimmediate_operand" "")
9705                    (neg:SI (match_operand:SI 1 "nonimmediate_operand" "")))
9706               (clobber (reg:CC 17))])]
9707   ""
9708   "ix86_expand_unary_operator (NEG, SImode, operands); DONE;")
9709
9710 (define_insn "*negsi2_1"
9711   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
9712         (neg:SI (match_operand:SI 1 "nonimmediate_operand" "0")))
9713    (clobber (reg:CC 17))]
9714   "ix86_unary_operator_ok (NEG, SImode, operands)"
9715   "neg{l}\t%0"
9716   [(set_attr "type" "negnot")
9717    (set_attr "mode" "SI")])
9718
9719 ;; Combine is quite creative about this pattern.
9720 (define_insn "*negsi2_1_zext"
9721   [(set (match_operand:DI 0 "register_operand" "=r")
9722         (lshiftrt:DI (neg:DI (ashift:DI (match_operand:DI 1 "register_operand" "0")
9723                                         (const_int 32)))
9724                      (const_int 32)))
9725    (clobber (reg:CC 17))]
9726   "TARGET_64BIT && ix86_unary_operator_ok (NEG, SImode, operands)"
9727   "neg{l}\t%k0"
9728   [(set_attr "type" "negnot")
9729    (set_attr "mode" "SI")])
9730
9731 ;; The problem with neg is that it does not perform (compare x 0),
9732 ;; it really performs (compare 0 x), which leaves us with the zero
9733 ;; flag being the only useful item.
9734
9735 (define_insn "*negsi2_cmpz"
9736   [(set (reg:CCZ 17)
9737         (compare:CCZ (neg:SI (match_operand:SI 1 "nonimmediate_operand" "0"))
9738                      (const_int 0)))
9739    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
9740         (neg:SI (match_dup 1)))]
9741   "ix86_unary_operator_ok (NEG, SImode, operands)"
9742   "neg{l}\t%0"
9743   [(set_attr "type" "negnot")
9744    (set_attr "mode" "SI")])
9745
9746 (define_insn "*negsi2_cmpz_zext"
9747   [(set (reg:CCZ 17)
9748         (compare:CCZ (lshiftrt:DI
9749                        (neg:DI (ashift:DI
9750                                  (match_operand:DI 1 "register_operand" "0")
9751                                  (const_int 32)))
9752                        (const_int 32))
9753                      (const_int 0)))
9754    (set (match_operand:DI 0 "register_operand" "=r")
9755         (lshiftrt:DI (neg:DI (ashift:DI (match_dup 1)
9756                                         (const_int 32)))
9757                      (const_int 32)))]
9758   "TARGET_64BIT && ix86_unary_operator_ok (NEG, SImode, operands)"
9759   "neg{l}\t%k0"
9760   [(set_attr "type" "negnot")
9761    (set_attr "mode" "SI")])
9762
9763 (define_expand "neghi2"
9764   [(parallel [(set (match_operand:HI 0 "nonimmediate_operand" "")
9765                    (neg:HI (match_operand:HI 1 "nonimmediate_operand" "")))
9766               (clobber (reg:CC 17))])]
9767   "TARGET_HIMODE_MATH"
9768   "ix86_expand_unary_operator (NEG, HImode, operands); DONE;")
9769
9770 (define_insn "*neghi2_1"
9771   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
9772         (neg:HI (match_operand:HI 1 "nonimmediate_operand" "0")))
9773    (clobber (reg:CC 17))]
9774   "ix86_unary_operator_ok (NEG, HImode, operands)"
9775   "neg{w}\t%0"
9776   [(set_attr "type" "negnot")
9777    (set_attr "mode" "HI")])
9778
9779 (define_insn "*neghi2_cmpz"
9780   [(set (reg:CCZ 17)
9781         (compare:CCZ (neg:HI (match_operand:HI 1 "nonimmediate_operand" "0"))
9782                      (const_int 0)))
9783    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
9784         (neg:HI (match_dup 1)))]
9785   "ix86_unary_operator_ok (NEG, HImode, operands)"
9786   "neg{w}\t%0"
9787   [(set_attr "type" "negnot")
9788    (set_attr "mode" "HI")])
9789
9790 (define_expand "negqi2"
9791   [(parallel [(set (match_operand:QI 0 "nonimmediate_operand" "")
9792                    (neg:QI (match_operand:QI 1 "nonimmediate_operand" "")))
9793               (clobber (reg:CC 17))])]
9794   "TARGET_QIMODE_MATH"
9795   "ix86_expand_unary_operator (NEG, QImode, operands); DONE;")
9796
9797 (define_insn "*negqi2_1"
9798   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
9799         (neg:QI (match_operand:QI 1 "nonimmediate_operand" "0")))
9800    (clobber (reg:CC 17))]
9801   "ix86_unary_operator_ok (NEG, QImode, operands)"
9802   "neg{b}\t%0"
9803   [(set_attr "type" "negnot")
9804    (set_attr "mode" "QI")])
9805
9806 (define_insn "*negqi2_cmpz"
9807   [(set (reg:CCZ 17)
9808         (compare:CCZ (neg:QI (match_operand:QI 1 "nonimmediate_operand" "0"))
9809                      (const_int 0)))
9810    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
9811         (neg:QI (match_dup 1)))]
9812   "ix86_unary_operator_ok (NEG, QImode, operands)"
9813   "neg{b}\t%0"
9814   [(set_attr "type" "negnot")
9815    (set_attr "mode" "QI")])
9816
9817 ;; Changing of sign for FP values is doable using integer unit too.
9818
9819 (define_expand "negsf2"
9820   [(parallel [(set (match_operand:SF 0 "nonimmediate_operand" "")
9821                    (neg:SF (match_operand:SF 1 "nonimmediate_operand" "")))
9822               (clobber (reg:CC 17))])]
9823   "TARGET_80387"
9824   "if (TARGET_SSE)
9825      {
9826        /* In case operand is in memory,  we will not use SSE.  */
9827        if (memory_operand (operands[0], VOIDmode)
9828            && rtx_equal_p (operands[0], operands[1]))
9829          emit_insn (gen_negsf2_memory (operands[0], operands[1]));
9830        else
9831         {
9832           /* Using SSE is tricky, since we need bitwise negation of -0
9833              in register.  */
9834           rtx reg = gen_reg_rtx (SFmode);
9835           rtx dest = operands[0];
9836           rtx imm = gen_lowpart (SFmode, gen_int_mode (0x80000000, SImode));
9837
9838           operands[1] = force_reg (SFmode, operands[1]);
9839           operands[0] = force_reg (SFmode, operands[0]);
9840           reg = force_reg (V4SFmode,
9841                            gen_rtx_CONST_VECTOR (V4SFmode,
9842                              gen_rtvec (4, imm, CONST0_RTX (SFmode),
9843                                         CONST0_RTX (SFmode),
9844                                         CONST0_RTX (SFmode))));
9845           emit_insn (gen_negsf2_ifs (operands[0], operands[1], reg));
9846           if (dest != operands[0])
9847             emit_move_insn (dest, operands[0]);
9848         }
9849        DONE;
9850      }
9851    ix86_expand_unary_operator (NEG, SFmode, operands); DONE;")
9852
9853 (define_insn "negsf2_memory"
9854   [(set (match_operand:SF 0 "memory_operand" "=m")
9855         (neg:SF (match_operand:SF 1 "memory_operand" "0")))
9856    (clobber (reg:CC 17))]
9857   "ix86_unary_operator_ok (NEG, SFmode, operands)"
9858   "#")
9859
9860 (define_insn "negsf2_ifs"
9861   [(set (match_operand:SF 0 "nonimmediate_operand" "=x#fr,x#fr,f#xr,rm#xf")
9862         (neg:SF (match_operand:SF 1 "nonimmediate_operand" "0,x#fr,0,0")))
9863    (use (match_operand:V4SF 2 "nonimmediate_operand" "xm,0,xm*r,xm*r"))
9864    (clobber (reg:CC 17))]
9865   "TARGET_SSE
9866    && (reload_in_progress || reload_completed
9867        || (register_operand (operands[0], VOIDmode)
9868            && register_operand (operands[1], VOIDmode)))"
9869   "#")
9870
9871 (define_split
9872   [(set (match_operand:SF 0 "memory_operand" "")
9873         (neg:SF (match_operand:SF 1 "memory_operand" "")))
9874    (use (match_operand:SF 2 "" ""))
9875    (clobber (reg:CC 17))]
9876   ""
9877   [(parallel [(set (match_dup 0)
9878                    (neg:SF (match_dup 1)))
9879               (clobber (reg:CC 17))])])
9880
9881 (define_split
9882   [(set (match_operand:SF 0 "register_operand" "")
9883         (neg:SF (match_operand:SF 1 "register_operand" "")))
9884    (use (match_operand:V4SF 2 "" ""))
9885    (clobber (reg:CC 17))]
9886   "reload_completed && !SSE_REG_P (operands[0])"
9887   [(parallel [(set (match_dup 0)
9888                    (neg:SF (match_dup 1)))
9889               (clobber (reg:CC 17))])])
9890
9891 (define_split
9892   [(set (match_operand:SF 0 "register_operand" "")
9893         (neg:SF (match_operand:SF 1 "register_operand" "")))
9894    (use (match_operand:V4SF 2 "nonimmediate_operand" ""))
9895    (clobber (reg:CC 17))]
9896   "reload_completed && SSE_REG_P (operands[0])"
9897   [(set (subreg:TI (match_dup 0) 0)
9898         (xor:TI (match_dup 1)
9899                 (match_dup 2)))]
9900 {
9901   operands[1] = simplify_gen_subreg (TImode, operands[1], SFmode, 0);
9902   operands[2] = simplify_gen_subreg (TImode, operands[2], V4SFmode, 0);
9903   if (operands_match_p (operands[0], operands[2]))
9904     {
9905       rtx tmp;
9906       tmp = operands[1];
9907       operands[1] = operands[2];
9908       operands[2] = tmp;
9909     }
9910 })
9911
9912
9913 ;; Keep 'f' and 'r' in separate alternatives to avoid reload problems
9914 ;; because of secondary memory needed to reload from class FLOAT_INT_REGS
9915 ;; to itself.
9916 (define_insn "*negsf2_if"
9917   [(set (match_operand:SF 0 "nonimmediate_operand" "=f#r,rm#f")
9918         (neg:SF (match_operand:SF 1 "nonimmediate_operand" "0,0")))
9919    (clobber (reg:CC 17))]
9920   "TARGET_80387 && !TARGET_SSE
9921    && ix86_unary_operator_ok (NEG, SFmode, operands)"
9922   "#")
9923
9924 (define_split
9925   [(set (match_operand:SF 0 "fp_register_operand" "")
9926         (neg:SF (match_operand:SF 1 "register_operand" "")))
9927    (clobber (reg:CC 17))]
9928   "TARGET_80387 && reload_completed"
9929   [(set (match_dup 0)
9930         (neg:SF (match_dup 1)))]
9931   "")
9932
9933 (define_split
9934   [(set (match_operand:SF 0 "register_and_not_fp_reg_operand" "")
9935         (neg:SF (match_operand:SF 1 "register_operand" "")))
9936    (clobber (reg:CC 17))]
9937   "TARGET_80387 && reload_completed"
9938   [(parallel [(set (match_dup 0) (xor:SI (match_dup 0) (match_dup 1)))
9939               (clobber (reg:CC 17))])]
9940   "operands[1] = gen_int_mode (0x80000000, SImode);
9941    operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));")
9942
9943 (define_split
9944   [(set (match_operand 0 "memory_operand" "")
9945         (neg (match_operand 1 "memory_operand" "")))
9946    (clobber (reg:CC 17))]
9947   "TARGET_80387 && reload_completed && FLOAT_MODE_P (GET_MODE (operands[0]))"
9948   [(parallel [(set (match_dup 0) (xor:QI (match_dup 0) (match_dup 1)))
9949               (clobber (reg:CC 17))])]
9950 {
9951   int size = GET_MODE_SIZE (GET_MODE (operands[1]));
9952
9953   /* XFmode's size is 12, TFmode 16, but only 10 bytes are used.  */
9954   if (size >= 12)
9955     size = 10;
9956   operands[0] = adjust_address (operands[0], QImode, size - 1);
9957   operands[1] = gen_int_mode (0x80, QImode);
9958 })
9959
9960 (define_expand "negdf2"
9961   [(parallel [(set (match_operand:DF 0 "nonimmediate_operand" "")
9962                    (neg:DF (match_operand:DF 1 "nonimmediate_operand" "")))
9963               (clobber (reg:CC 17))])]
9964   "TARGET_80387"
9965   "if (TARGET_SSE2)
9966      {
9967        /* In case operand is in memory,  we will not use SSE.  */
9968        if (memory_operand (operands[0], VOIDmode)
9969            && rtx_equal_p (operands[0], operands[1]))
9970          emit_insn (gen_negdf2_memory (operands[0], operands[1]));
9971        else
9972         {
9973           /* Using SSE is tricky, since we need bitwise negation of -0
9974              in register.  */
9975           rtx reg;
9976 #if HOST_BITS_PER_WIDE_INT >= 64
9977           rtx imm = gen_int_mode (((HOST_WIDE_INT)1) << 63, DImode);
9978 #else
9979           rtx imm = immed_double_const (0, 0x80000000, DImode);
9980 #endif
9981           rtx dest = operands[0];
9982
9983           operands[1] = force_reg (DFmode, operands[1]);
9984           operands[0] = force_reg (DFmode, operands[0]);
9985           imm = gen_lowpart (DFmode, imm);
9986           reg = force_reg (V2DFmode,
9987                            gen_rtx_CONST_VECTOR (V2DFmode,
9988                              gen_rtvec (2, imm, CONST0_RTX (DFmode))));
9989           emit_insn (gen_negdf2_ifs (operands[0], operands[1], reg));
9990           if (dest != operands[0])
9991             emit_move_insn (dest, operands[0]);
9992         }
9993        DONE;
9994      }
9995    ix86_expand_unary_operator (NEG, DFmode, operands); DONE;")
9996
9997 (define_insn "negdf2_memory"
9998   [(set (match_operand:DF 0 "memory_operand" "=m")
9999         (neg:DF (match_operand:DF 1 "memory_operand" "0")))
10000    (clobber (reg:CC 17))]
10001   "ix86_unary_operator_ok (NEG, DFmode, operands)"
10002   "#")
10003
10004 (define_insn "negdf2_ifs"
10005   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y#fr,Y#fr,f#Yr,rm#Yf")
10006         (neg:DF (match_operand:DF 1 "nonimmediate_operand" "0,Y#fr,0,0")))
10007    (use (match_operand:V2DF 2 "nonimmediate_operand" "Ym,0,Ym*r,Ym*r"))
10008    (clobber (reg:CC 17))]
10009   "!TARGET_64BIT && TARGET_SSE2
10010    && (reload_in_progress || reload_completed
10011        || (register_operand (operands[0], VOIDmode)
10012            && register_operand (operands[1], VOIDmode)))"
10013   "#")
10014
10015 (define_insn "*negdf2_ifs_rex64"
10016   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y#f,Y#f,fm#Y")
10017         (neg:DF (match_operand:DF 1 "nonimmediate_operand" "0,Y#fr,0")))
10018    (use (match_operand:V2DF 2 "nonimmediate_operand" "Ym,0,Ym*r"))
10019    (clobber (reg:CC 17))]
10020   "TARGET_64BIT && TARGET_SSE2
10021    && (reload_in_progress || reload_completed
10022        || (register_operand (operands[0], VOIDmode)
10023            && register_operand (operands[1], VOIDmode)))"
10024   "#")
10025
10026 (define_split
10027   [(set (match_operand:DF 0 "memory_operand" "")
10028         (neg:DF (match_operand:DF 1 "memory_operand" "")))
10029    (use (match_operand:V2DF 2 "" ""))
10030    (clobber (reg:CC 17))]
10031   ""
10032   [(parallel [(set (match_dup 0)
10033                    (neg:DF (match_dup 1)))
10034               (clobber (reg:CC 17))])])
10035
10036 (define_split
10037   [(set (match_operand:DF 0 "register_operand" "")
10038         (neg:DF (match_operand:DF 1 "register_operand" "")))
10039    (use (match_operand:V2DF 2 "" ""))
10040    (clobber (reg:CC 17))]
10041   "reload_completed && !SSE_REG_P (operands[0])
10042    && (!TARGET_64BIT || FP_REG_P (operands[0]))"
10043   [(parallel [(set (match_dup 0)
10044                    (neg:DF (match_dup 1)))
10045               (clobber (reg:CC 17))])])
10046
10047 (define_split
10048   [(set (match_operand:DF 0 "register_operand" "")
10049         (neg:DF (match_operand:DF 1 "register_operand" "")))
10050    (use (match_operand:V2DF 2 "" ""))
10051    (clobber (reg:CC 17))]
10052   "TARGET_64BIT && reload_completed && GENERAL_REG_P (operands[0])"
10053   [(parallel [(set (match_dup 0)
10054                    (xor:DI (match_dup 1) (match_dup 2)))
10055               (clobber (reg:CC 17))])]
10056    "operands[0] = gen_lowpart (DImode, operands[0]);
10057     operands[1] = gen_lowpart (DImode, operands[1]);
10058     operands[2] = gen_lowpart (DImode, operands[2]);")
10059
10060 (define_split
10061   [(set (match_operand:DF 0 "register_operand" "")
10062         (neg:DF (match_operand:DF 1 "register_operand" "")))
10063    (use (match_operand:V2DF 2 "nonimmediate_operand" ""))
10064    (clobber (reg:CC 17))]
10065   "reload_completed && SSE_REG_P (operands[0])"
10066   [(set (subreg:TI (match_dup 0) 0)
10067         (xor:TI (match_dup 1)
10068                 (match_dup 2)))]
10069 {
10070   operands[0] = simplify_gen_subreg (V2DFmode, operands[0], DFmode, 0);
10071   operands[1] = simplify_gen_subreg (TImode, operands[1], DFmode, 0);
10072   operands[2] = simplify_gen_subreg (TImode, operands[2], V2DFmode, 0);
10073   /* Avoid possible reformatting on the operands.  */
10074   if (TARGET_SSE_PARTIAL_REGS && !optimize_size)
10075     emit_insn (gen_sse2_unpcklpd (operands[0], operands[0], operands[0]));
10076   if (operands_match_p (operands[0], operands[2]))
10077     {
10078       rtx tmp;
10079       tmp = operands[1];
10080       operands[1] = operands[2];
10081       operands[2] = tmp;
10082     }
10083 })
10084
10085 ;; Keep 'f' and 'r' in separate alternatives to avoid reload problems
10086 ;; because of secondary memory needed to reload from class FLOAT_INT_REGS
10087 ;; to itself.
10088 (define_insn "*negdf2_if"
10089   [(set (match_operand:DF 0 "nonimmediate_operand" "=f#r,rm#f")
10090         (neg:DF (match_operand:DF 1 "nonimmediate_operand" "0,0")))
10091    (clobber (reg:CC 17))]
10092   "!TARGET_64BIT && TARGET_80387
10093    && ix86_unary_operator_ok (NEG, DFmode, operands)"
10094   "#")
10095
10096 ;; FIXME: We should to allow integer registers here.  Problem is that
10097 ;; we need another scratch register to get constant from.
10098 ;; Forcing constant to mem if no register available in peep2 should be
10099 ;; safe even for PIC mode, because of RIP relative addressing.
10100 (define_insn "*negdf2_if_rex64"
10101   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,mf")
10102         (neg:DF (match_operand:DF 1 "nonimmediate_operand" "0,0")))
10103    (clobber (reg:CC 17))]
10104   "TARGET_64BIT && TARGET_80387
10105    && ix86_unary_operator_ok (NEG, DFmode, operands)"
10106   "#")
10107
10108 (define_split
10109   [(set (match_operand:DF 0 "fp_register_operand" "")
10110         (neg:DF (match_operand:DF 1 "register_operand" "")))
10111    (clobber (reg:CC 17))]
10112   "TARGET_80387 && reload_completed"
10113   [(set (match_dup 0)
10114         (neg:DF (match_dup 1)))]
10115   "")
10116
10117 (define_split
10118   [(set (match_operand:DF 0 "register_and_not_fp_reg_operand" "")
10119         (neg:DF (match_operand:DF 1 "register_operand" "")))
10120    (clobber (reg:CC 17))]
10121   "!TARGET_64BIT && TARGET_80387 && reload_completed"
10122   [(parallel [(set (match_dup 3) (xor:SI (match_dup 3) (match_dup 4)))
10123               (clobber (reg:CC 17))])]
10124   "operands[4] = gen_int_mode (0x80000000, SImode);
10125    split_di (operands+0, 1, operands+2, operands+3);")
10126
10127 (define_expand "negxf2"
10128   [(parallel [(set (match_operand:XF 0 "nonimmediate_operand" "")
10129                    (neg:XF (match_operand:XF 1 "nonimmediate_operand" "")))
10130               (clobber (reg:CC 17))])]
10131   "!TARGET_64BIT && TARGET_80387"
10132   "ix86_expand_unary_operator (NEG, XFmode, operands); DONE;")
10133
10134 (define_expand "negtf2"
10135   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
10136                    (neg:TF (match_operand:TF 1 "nonimmediate_operand" "")))
10137               (clobber (reg:CC 17))])]
10138   "TARGET_80387"
10139   "ix86_expand_unary_operator (NEG, TFmode, operands); DONE;")
10140
10141 ;; Keep 'f' and 'r' in separate alternatives to avoid reload problems
10142 ;; because of secondary memory needed to reload from class FLOAT_INT_REGS
10143 ;; to itself.
10144 (define_insn "*negxf2_if"
10145   [(set (match_operand:XF 0 "nonimmediate_operand" "=f#r,rm#f")
10146         (neg:XF (match_operand:XF 1 "nonimmediate_operand" "0,0")))
10147    (clobber (reg:CC 17))]
10148   "!TARGET_64BIT && TARGET_80387
10149    && ix86_unary_operator_ok (NEG, XFmode, operands)"
10150   "#")
10151
10152 (define_split
10153   [(set (match_operand:XF 0 "fp_register_operand" "")
10154         (neg:XF (match_operand:XF 1 "register_operand" "")))
10155    (clobber (reg:CC 17))]
10156   "TARGET_80387 && reload_completed"
10157   [(set (match_dup 0)
10158         (neg:XF (match_dup 1)))]
10159   "")
10160
10161 (define_split
10162   [(set (match_operand:XF 0 "register_and_not_fp_reg_operand" "")
10163         (neg:XF (match_operand:XF 1 "register_operand" "")))
10164    (clobber (reg:CC 17))]
10165   "TARGET_80387 && reload_completed"
10166   [(parallel [(set (match_dup 0) (xor:SI (match_dup 0) (match_dup 1)))
10167               (clobber (reg:CC 17))])]
10168   "operands[1] = GEN_INT (0x8000);
10169    operands[0] = gen_rtx_REG (SImode,
10170                               true_regnum (operands[0]) + (TARGET_64BIT ? 1 : 2));")
10171
10172 ;; Keep 'f' and 'r' in separate alternatives to avoid reload problems
10173 ;; because of secondary memory needed to reload from class FLOAT_INT_REGS
10174 ;; to itself.
10175 (define_insn "*negtf2_if"
10176   [(set (match_operand:TF 0 "nonimmediate_operand" "=f#r,rm#f")
10177         (neg:TF (match_operand:TF 1 "nonimmediate_operand" "0,0")))
10178    (clobber (reg:CC 17))]
10179   "TARGET_80387 && ix86_unary_operator_ok (NEG, TFmode, operands)"
10180   "#")
10181
10182 (define_split
10183   [(set (match_operand:TF 0 "fp_register_operand" "")
10184         (neg:TF (match_operand:TF 1 "register_operand" "")))
10185    (clobber (reg:CC 17))]
10186   "TARGET_80387 && reload_completed"
10187   [(set (match_dup 0)
10188         (neg:TF (match_dup 1)))]
10189   "")
10190
10191 (define_split
10192   [(set (match_operand:TF 0 "register_and_not_fp_reg_operand" "")
10193         (neg:TF (match_operand:TF 1 "register_operand" "")))
10194    (clobber (reg:CC 17))]
10195   "TARGET_80387 && reload_completed"
10196   [(parallel [(set (match_dup 0) (xor:SI (match_dup 0) (match_dup 1)))
10197               (clobber (reg:CC 17))])]
10198   "operands[1] = GEN_INT (0x8000);
10199    operands[0] = gen_rtx_REG (SImode,
10200                               true_regnum (operands[0]) + (TARGET_64BIT ? 1 : 2));")
10201
10202 ;; Conditionalize these after reload. If they matches before reload, we 
10203 ;; lose the clobber and ability to use integer instructions.
10204
10205 (define_insn "*negsf2_1"
10206   [(set (match_operand:SF 0 "register_operand" "=f")
10207         (neg:SF (match_operand:SF 1 "register_operand" "0")))]
10208   "TARGET_80387 && reload_completed"
10209   "fchs"
10210   [(set_attr "type" "fsgn")
10211    (set_attr "mode" "SF")
10212    (set_attr "ppro_uops" "few")])
10213
10214 (define_insn "*negdf2_1"
10215   [(set (match_operand:DF 0 "register_operand" "=f")
10216         (neg:DF (match_operand:DF 1 "register_operand" "0")))]
10217   "TARGET_80387 && reload_completed"
10218   "fchs"
10219   [(set_attr "type" "fsgn")
10220    (set_attr "mode" "DF")
10221    (set_attr "ppro_uops" "few")])
10222
10223 (define_insn "*negextendsfdf2"
10224   [(set (match_operand:DF 0 "register_operand" "=f")
10225         (neg:DF (float_extend:DF
10226                   (match_operand:SF 1 "register_operand" "0"))))]
10227   "TARGET_80387"
10228   "fchs"
10229   [(set_attr "type" "fsgn")
10230    (set_attr "mode" "DF")
10231    (set_attr "ppro_uops" "few")])
10232
10233 (define_insn "*negxf2_1"
10234   [(set (match_operand:XF 0 "register_operand" "=f")
10235         (neg:XF (match_operand:XF 1 "register_operand" "0")))]
10236   "!TARGET_64BIT && TARGET_80387 && reload_completed"
10237   "fchs"
10238   [(set_attr "type" "fsgn")
10239    (set_attr "mode" "XF")
10240    (set_attr "ppro_uops" "few")])
10241
10242 (define_insn "*negextenddfxf2"
10243   [(set (match_operand:XF 0 "register_operand" "=f")
10244         (neg:XF (float_extend:XF
10245                   (match_operand:DF 1 "register_operand" "0"))))]
10246   "!TARGET_64BIT && TARGET_80387"
10247   "fchs"
10248   [(set_attr "type" "fsgn")
10249    (set_attr "mode" "XF")
10250    (set_attr "ppro_uops" "few")])
10251
10252 (define_insn "*negextendsfxf2"
10253   [(set (match_operand:XF 0 "register_operand" "=f")
10254         (neg:XF (float_extend:XF
10255                   (match_operand:SF 1 "register_operand" "0"))))]
10256   "!TARGET_64BIT && TARGET_80387"
10257   "fchs"
10258   [(set_attr "type" "fsgn")
10259    (set_attr "mode" "XF")
10260    (set_attr "ppro_uops" "few")])
10261
10262 (define_insn "*negtf2_1"
10263   [(set (match_operand:TF 0 "register_operand" "=f")
10264         (neg:TF (match_operand:TF 1 "register_operand" "0")))]
10265   "TARGET_80387 && reload_completed"
10266   "fchs"
10267   [(set_attr "type" "fsgn")
10268    (set_attr "mode" "XF")
10269    (set_attr "ppro_uops" "few")])
10270
10271 (define_insn "*negextenddftf2"
10272   [(set (match_operand:TF 0 "register_operand" "=f")
10273         (neg:TF (float_extend:TF
10274                   (match_operand:DF 1 "register_operand" "0"))))]
10275   "TARGET_80387"
10276   "fchs"
10277   [(set_attr "type" "fsgn")
10278    (set_attr "mode" "XF")
10279    (set_attr "ppro_uops" "few")])
10280
10281 (define_insn "*negextendsftf2"
10282   [(set (match_operand:TF 0 "register_operand" "=f")
10283         (neg:TF (float_extend:TF
10284                   (match_operand:SF 1 "register_operand" "0"))))]
10285   "TARGET_80387"
10286   "fchs"
10287   [(set_attr "type" "fsgn")
10288    (set_attr "mode" "XF")
10289    (set_attr "ppro_uops" "few")])
10290 \f
10291 ;; Absolute value instructions
10292
10293 (define_expand "abssf2"
10294   [(parallel [(set (match_operand:SF 0 "nonimmediate_operand" "")
10295                    (neg:SF (match_operand:SF 1 "nonimmediate_operand" "")))
10296               (clobber (reg:CC 17))])]
10297   "TARGET_80387"
10298   "if (TARGET_SSE)
10299      {
10300        /* In case operand is in memory,  we will not use SSE.  */
10301        if (memory_operand (operands[0], VOIDmode)
10302            && rtx_equal_p (operands[0], operands[1]))
10303          emit_insn (gen_abssf2_memory (operands[0], operands[1]));
10304        else
10305         {
10306           /* Using SSE is tricky, since we need bitwise negation of -0
10307              in register.  */
10308           rtx reg = gen_reg_rtx (V4SFmode);
10309           rtx dest = operands[0];
10310           rtx imm;
10311
10312           operands[1] = force_reg (SFmode, operands[1]);
10313           operands[0] = force_reg (SFmode, operands[0]);
10314           imm = gen_lowpart (SFmode, gen_int_mode(~0x80000000, SImode));
10315           reg = force_reg (V4SFmode,
10316                            gen_rtx_CONST_VECTOR (V4SFmode,
10317                            gen_rtvec (4, imm, CONST0_RTX (SFmode),
10318                                       CONST0_RTX (SFmode),
10319                                       CONST0_RTX (SFmode))));
10320           emit_insn (gen_abssf2_ifs (operands[0], operands[1], reg));
10321           if (dest != operands[0])
10322             emit_move_insn (dest, operands[0]);
10323         }
10324        DONE;
10325      }
10326    ix86_expand_unary_operator (ABS, SFmode, operands); DONE;")
10327
10328 (define_insn "abssf2_memory"
10329   [(set (match_operand:SF 0 "memory_operand" "=m")
10330         (abs:SF (match_operand:SF 1 "memory_operand" "0")))
10331    (clobber (reg:CC 17))]
10332   "ix86_unary_operator_ok (ABS, SFmode, operands)"
10333   "#")
10334
10335 (define_insn "abssf2_ifs"
10336   [(set (match_operand:SF 0 "nonimmediate_operand" "=x#fr,x#fr,f#xr,rm#xf")
10337         (abs:SF (match_operand:SF 1 "nonimmediate_operand" "0,x#fr,0,0")))
10338    (use (match_operand:V4SF 2 "nonimmediate_operand" "xm,0,xm*r,xm*r"))
10339    (clobber (reg:CC 17))]
10340   "TARGET_SSE
10341    && (reload_in_progress || reload_completed
10342        || (register_operand (operands[0], VOIDmode)
10343             && register_operand (operands[1], VOIDmode)))"
10344   "#")
10345
10346 (define_split
10347   [(set (match_operand:SF 0 "memory_operand" "")
10348         (abs:SF (match_operand:SF 1 "memory_operand" "")))
10349    (use (match_operand:V4SF 2 "" ""))
10350    (clobber (reg:CC 17))]
10351   ""
10352   [(parallel [(set (match_dup 0)
10353                    (abs:SF (match_dup 1)))
10354               (clobber (reg:CC 17))])])
10355
10356 (define_split
10357   [(set (match_operand:SF 0 "register_operand" "")
10358         (abs:SF (match_operand:SF 1 "register_operand" "")))
10359    (use (match_operand:V4SF 2 "" ""))
10360    (clobber (reg:CC 17))]
10361   "reload_completed && !SSE_REG_P (operands[0])"
10362   [(parallel [(set (match_dup 0)
10363                    (abs:SF (match_dup 1)))
10364               (clobber (reg:CC 17))])])
10365
10366 (define_split
10367   [(set (match_operand:SF 0 "register_operand" "")
10368         (abs:SF (match_operand:SF 1 "register_operand" "")))
10369    (use (match_operand:V4SF 2 "nonimmediate_operand" ""))
10370    (clobber (reg:CC 17))]
10371   "reload_completed && SSE_REG_P (operands[0])"
10372   [(set (subreg:TI (match_dup 0) 0)
10373         (and:TI (match_dup 1)
10374                 (match_dup 2)))]
10375 {
10376   operands[1] = simplify_gen_subreg (TImode, operands[1], SFmode, 0);
10377   operands[2] = simplify_gen_subreg (TImode, operands[2], V4SFmode, 0);
10378   if (operands_match_p (operands[0], operands[2]))
10379     {
10380       rtx tmp;
10381       tmp = operands[1];
10382       operands[1] = operands[2];
10383       operands[2] = tmp;
10384     }
10385 })
10386
10387 ;; Keep 'f' and 'r' in separate alternatives to avoid reload problems
10388 ;; because of secondary memory needed to reload from class FLOAT_INT_REGS
10389 ;; to itself.
10390 (define_insn "*abssf2_if"
10391   [(set (match_operand:SF 0 "nonimmediate_operand" "=f#r,rm#f")
10392         (abs:SF (match_operand:SF 1 "nonimmediate_operand" "0,0")))
10393    (clobber (reg:CC 17))]
10394   "TARGET_80387 && ix86_unary_operator_ok (ABS, SFmode, operands) && !TARGET_SSE"
10395   "#")
10396
10397 (define_split
10398   [(set (match_operand:SF 0 "fp_register_operand" "")
10399         (abs:SF (match_operand:SF 1 "register_operand" "")))
10400    (clobber (reg:CC 17))]
10401   "TARGET_80387"
10402   [(set (match_dup 0)
10403         (abs:SF (match_dup 1)))]
10404   "")
10405
10406 (define_split
10407   [(set (match_operand:SF 0 "register_and_not_fp_reg_operand" "")
10408         (abs:SF (match_operand:SF 1 "register_operand" "")))
10409    (clobber (reg:CC 17))]
10410   "TARGET_80387 && reload_completed"
10411   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (match_dup 1)))
10412               (clobber (reg:CC 17))])]
10413   "operands[1] = gen_int_mode (~0x80000000, SImode);
10414    operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));")
10415
10416 (define_split
10417   [(set (match_operand 0 "memory_operand" "")
10418         (abs (match_operand 1 "memory_operand" "")))
10419    (clobber (reg:CC 17))]
10420   "TARGET_80387 && reload_completed && FLOAT_MODE_P (GET_MODE (operands[0]))"
10421   [(parallel [(set (match_dup 0) (and:QI (match_dup 0) (match_dup 1)))
10422               (clobber (reg:CC 17))])]
10423 {
10424   int size = GET_MODE_SIZE (GET_MODE (operands[1]));
10425
10426   /* XFmode's size is 12, TFmode 16, but only 10 bytes are used.  */
10427   if (size >= 12)
10428     size = 10;
10429   operands[0] = adjust_address (operands[0], QImode, size - 1);
10430   operands[1] = gen_int_mode (~0x80, QImode);
10431 })
10432
10433 (define_expand "absdf2"
10434   [(parallel [(set (match_operand:DF 0 "nonimmediate_operand" "")
10435                    (neg:DF (match_operand:DF 1 "nonimmediate_operand" "")))
10436               (clobber (reg:CC 17))])]
10437   "TARGET_80387"
10438   "if (TARGET_SSE2)
10439      {
10440        /* In case operand is in memory,  we will not use SSE.  */
10441        if (memory_operand (operands[0], VOIDmode)
10442            && rtx_equal_p (operands[0], operands[1]))
10443          emit_insn (gen_absdf2_memory (operands[0], operands[1]));
10444        else
10445         {
10446           /* Using SSE is tricky, since we need bitwise negation of -0
10447              in register.  */
10448           rtx reg = gen_reg_rtx (V2DFmode);
10449 #if HOST_BITS_PER_WIDE_INT >= 64
10450           rtx imm = gen_int_mode (~(((HOST_WIDE_INT)1) << 63), DImode);
10451 #else
10452           rtx imm = immed_double_const (~0, ~0x80000000, DImode);
10453 #endif
10454           rtx dest = operands[0];
10455
10456           operands[1] = force_reg (DFmode, operands[1]);
10457           operands[0] = force_reg (DFmode, operands[0]);
10458
10459           /* Produce LONG_DOUBLE with the proper immediate argument.  */
10460           imm = gen_lowpart (DFmode, imm);
10461           reg = force_reg (V2DFmode,
10462                            gen_rtx_CONST_VECTOR (V2DFmode,
10463                            gen_rtvec (2, imm, CONST0_RTX (DFmode))));
10464           emit_insn (gen_absdf2_ifs (operands[0], operands[1], reg));
10465           if (dest != operands[0])
10466             emit_move_insn (dest, operands[0]);
10467         }
10468        DONE;
10469      }
10470    ix86_expand_unary_operator (ABS, DFmode, operands); DONE;")
10471
10472 (define_insn "absdf2_memory"
10473   [(set (match_operand:DF 0 "memory_operand" "=m")
10474         (abs:DF (match_operand:DF 1 "memory_operand" "0")))
10475    (clobber (reg:CC 17))]
10476   "ix86_unary_operator_ok (ABS, DFmode, operands)"
10477   "#")
10478
10479 (define_insn "absdf2_ifs"
10480   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y#fr,Y#fr,mf#Yr,mr#Yf")
10481         (abs:DF (match_operand:DF 1 "nonimmediate_operand" "0,Y#fr,0,0")))
10482    (use (match_operand:V2DF 2 "nonimmediate_operand" "Ym,0,Ym*r,Ym*r"))
10483    (clobber (reg:CC 17))]
10484   "!TARGET_64BIT && TARGET_SSE2
10485    && (reload_in_progress || reload_completed
10486        || (register_operand (operands[0], VOIDmode)
10487            && register_operand (operands[1], VOIDmode)))"
10488   "#")
10489
10490 (define_insn "*absdf2_ifs_rex64"
10491   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y#fr,Y#fr,mf#Yr")
10492         (abs:DF (match_operand:DF 1 "nonimmediate_operand" "0,Y#fr,0")))
10493    (use (match_operand:V2DF 2 "nonimmediate_operand" "Ym,0,Ym*r"))
10494    (clobber (reg:CC 17))]
10495   "TARGET_64BIT && TARGET_SSE2
10496    && (reload_in_progress || reload_completed
10497        || (register_operand (operands[0], VOIDmode)
10498            && register_operand (operands[1], VOIDmode)))"
10499   "#")
10500
10501 (define_split
10502   [(set (match_operand:DF 0 "memory_operand" "")
10503         (abs:DF (match_operand:DF 1 "memory_operand" "")))
10504    (use (match_operand:V2DF 2 "" ""))
10505    (clobber (reg:CC 17))]
10506   ""
10507   [(parallel [(set (match_dup 0)
10508                    (abs:DF (match_dup 1)))
10509               (clobber (reg:CC 17))])])
10510
10511 (define_split
10512   [(set (match_operand:DF 0 "register_operand" "")
10513         (abs:DF (match_operand:DF 1 "register_operand" "")))
10514    (use (match_operand:V2DF 2 "" ""))
10515    (clobber (reg:CC 17))]
10516   "reload_completed && !SSE_REG_P (operands[0])"
10517   [(parallel [(set (match_dup 0)
10518                    (abs:DF (match_dup 1)))
10519               (clobber (reg:CC 17))])])
10520
10521 (define_split
10522   [(set (match_operand:DF 0 "register_operand" "")
10523         (abs:DF (match_operand:DF 1 "register_operand" "")))
10524    (use (match_operand:V2DF 2 "nonimmediate_operand" ""))
10525    (clobber (reg:CC 17))]
10526   "reload_completed && SSE_REG_P (operands[0])"
10527   [(set (subreg:TI (match_dup 0) 0)
10528         (and:TI (match_dup 1)
10529                 (match_dup 2)))]
10530 {
10531   operands[0] = simplify_gen_subreg (V2DFmode, operands[0], DFmode, 0);
10532   operands[1] = simplify_gen_subreg (TImode, operands[1], DFmode, 0);
10533   operands[2] = simplify_gen_subreg (TImode, operands[2], V2DFmode, 0);
10534   /* Avoid possible reformatting on the operands.  */
10535   if (TARGET_SSE_PARTIAL_REGS && !optimize_size)
10536     emit_insn (gen_sse2_unpcklpd (operands[0], operands[0], operands[0]));
10537   if (operands_match_p (operands[0], operands[2]))
10538     {
10539       rtx tmp;
10540       tmp = operands[1];
10541       operands[1] = operands[2];
10542       operands[2] = tmp;
10543     }
10544 })
10545
10546
10547 ;; Keep 'f' and 'r' in separate alternatives to avoid reload problems
10548 ;; because of secondary memory needed to reload from class FLOAT_INT_REGS
10549 ;; to itself.
10550 (define_insn "*absdf2_if"
10551   [(set (match_operand:DF 0 "nonimmediate_operand" "=f#r,rm#f")
10552         (abs:DF (match_operand:DF 1 "nonimmediate_operand" "0,0")))
10553    (clobber (reg:CC 17))]
10554   "!TARGET_64BIT && TARGET_80387
10555    && ix86_unary_operator_ok (ABS, DFmode, operands)"
10556   "#")
10557
10558 ;; FIXME: We should to allow integer registers here.  Problem is that
10559 ;; we need another scratch register to get constant from.
10560 ;; Forcing constant to mem if no register available in peep2 should be
10561 ;; safe even for PIC mode, because of RIP relative addressing.
10562 (define_insn "*absdf2_if_rex64"
10563   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,mf")
10564         (abs:DF (match_operand:DF 1 "nonimmediate_operand" "0,0")))
10565    (clobber (reg:CC 17))]
10566   "TARGET_64BIT && TARGET_80387
10567    && ix86_unary_operator_ok (ABS, DFmode, operands)"
10568   "#")
10569
10570 (define_split
10571   [(set (match_operand:DF 0 "fp_register_operand" "")
10572         (abs:DF (match_operand:DF 1 "register_operand" "")))
10573    (clobber (reg:CC 17))]
10574   "TARGET_80387 && reload_completed"
10575   [(set (match_dup 0)
10576         (abs:DF (match_dup 1)))]
10577   "")
10578
10579 (define_split
10580   [(set (match_operand:DF 0 "register_and_not_fp_reg_operand" "")
10581         (abs:DF (match_operand:DF 1 "register_operand" "")))
10582    (clobber (reg:CC 17))]
10583   "!TARGET_64BIT && TARGET_80387 && reload_completed"
10584   [(parallel [(set (match_dup 3) (and:SI (match_dup 3) (match_dup 4)))
10585               (clobber (reg:CC 17))])]
10586   "operands[4] = gen_int_mode (~0x80000000, SImode);
10587    split_di (operands+0, 1, operands+2, operands+3);")
10588
10589 (define_expand "absxf2"
10590   [(parallel [(set (match_operand:XF 0 "nonimmediate_operand" "")
10591                    (neg:XF (match_operand:XF 1 "nonimmediate_operand" "")))
10592               (clobber (reg:CC 17))])]
10593   "!TARGET_64BIT && TARGET_80387"
10594   "ix86_expand_unary_operator (ABS, XFmode, operands); DONE;")
10595
10596 (define_expand "abstf2"
10597   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
10598                    (neg:TF (match_operand:TF 1 "nonimmediate_operand" "")))
10599               (clobber (reg:CC 17))])]
10600   "TARGET_80387"
10601   "ix86_expand_unary_operator (ABS, TFmode, operands); DONE;")
10602
10603 ;; Keep 'f' and 'r' in separate alternatives to avoid reload problems
10604 ;; because of secondary memory needed to reload from class FLOAT_INT_REGS
10605 ;; to itself.
10606 (define_insn "*absxf2_if"
10607   [(set (match_operand:XF 0 "nonimmediate_operand" "=f#r,rm#f")
10608         (abs:XF (match_operand:XF 1 "nonimmediate_operand" "0,0")))
10609    (clobber (reg:CC 17))]
10610   "!TARGET_64BIT && TARGET_80387
10611    && ix86_unary_operator_ok (ABS, XFmode, operands)"
10612   "#")
10613
10614 (define_split
10615   [(set (match_operand:XF 0 "fp_register_operand" "")
10616         (abs:XF (match_operand:XF 1 "register_operand" "")))
10617    (clobber (reg:CC 17))]
10618   "TARGET_80387 && reload_completed"
10619   [(set (match_dup 0)
10620         (abs:XF (match_dup 1)))]
10621   "")
10622
10623 (define_split
10624   [(set (match_operand:XF 0 "register_and_not_fp_reg_operand" "")
10625         (abs:XF (match_operand:XF 1 "register_operand" "")))
10626    (clobber (reg:CC 17))]
10627   "TARGET_80387 && reload_completed"
10628   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (match_dup 1)))
10629               (clobber (reg:CC 17))])]
10630   "operands[1] = GEN_INT (~0x8000);
10631    operands[0] = gen_rtx_REG (SImode,
10632                               true_regnum (operands[0]) + (TARGET_64BIT ? 1 : 2));")
10633
10634 (define_insn "*abstf2_if"
10635   [(set (match_operand:TF 0 "nonimmediate_operand" "=f#r,rm#f")
10636         (abs:TF (match_operand:TF 1 "nonimmediate_operand" "0,0")))
10637    (clobber (reg:CC 17))]
10638   "TARGET_80387 && ix86_unary_operator_ok (ABS, TFmode, operands)"
10639   "#")
10640
10641 (define_split
10642   [(set (match_operand:TF 0 "fp_register_operand" "")
10643         (abs:TF (match_operand:TF 1 "register_operand" "")))
10644    (clobber (reg:CC 17))]
10645   "TARGET_80387 && reload_completed"
10646   [(set (match_dup 0)
10647         (abs:TF (match_dup 1)))]
10648   "")
10649
10650 (define_split
10651   [(set (match_operand:TF 0 "register_and_not_any_fp_reg_operand" "")
10652         (abs:TF (match_operand:TF 1 "register_operand" "")))
10653    (clobber (reg:CC 17))]
10654   "TARGET_80387 && reload_completed"
10655   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (match_dup 1)))
10656               (clobber (reg:CC 17))])]
10657   "operands[1] = GEN_INT (~0x8000);
10658    operands[0] = gen_rtx_REG (SImode,
10659                               true_regnum (operands[0]) + (TARGET_64BIT ? 1 : 2));")
10660
10661 (define_insn "*abssf2_1"
10662   [(set (match_operand:SF 0 "register_operand" "=f")
10663         (abs:SF (match_operand:SF 1 "register_operand" "0")))]
10664   "TARGET_80387 && reload_completed"
10665   "fabs"
10666   [(set_attr "type" "fsgn")
10667    (set_attr "mode" "SF")])
10668
10669 (define_insn "*absdf2_1"
10670   [(set (match_operand:DF 0 "register_operand" "=f")
10671         (abs:DF (match_operand:DF 1 "register_operand" "0")))]
10672   "TARGET_80387 && reload_completed"
10673   "fabs"
10674   [(set_attr "type" "fsgn")
10675    (set_attr "mode" "DF")])
10676
10677 (define_insn "*absextendsfdf2"
10678   [(set (match_operand:DF 0 "register_operand" "=f")
10679         (abs:DF (float_extend:DF
10680                   (match_operand:SF 1 "register_operand" "0"))))]
10681   "TARGET_80387"
10682   "fabs"
10683   [(set_attr "type" "fsgn")
10684    (set_attr "mode" "DF")])
10685
10686 (define_insn "*absxf2_1"
10687   [(set (match_operand:XF 0 "register_operand" "=f")
10688         (abs:XF (match_operand:XF 1 "register_operand" "0")))]
10689   "!TARGET_64BIT && TARGET_80387 && reload_completed"
10690   "fabs"
10691   [(set_attr "type" "fsgn")
10692    (set_attr "mode" "DF")])
10693
10694 (define_insn "*absextenddfxf2"
10695   [(set (match_operand:XF 0 "register_operand" "=f")
10696         (abs:XF (float_extend:XF
10697           (match_operand:DF 1 "register_operand" "0"))))]
10698   "!TARGET_64BIT && TARGET_80387"
10699   "fabs"
10700   [(set_attr "type" "fsgn")
10701    (set_attr "mode" "XF")])
10702
10703 (define_insn "*absextendsfxf2"
10704   [(set (match_operand:XF 0 "register_operand" "=f")
10705         (abs:XF (float_extend:XF
10706           (match_operand:SF 1 "register_operand" "0"))))]
10707   "!TARGET_64BIT && TARGET_80387"
10708   "fabs"
10709   [(set_attr "type" "fsgn")
10710    (set_attr "mode" "XF")])
10711
10712 (define_insn "*abstf2_1"
10713   [(set (match_operand:TF 0 "register_operand" "=f")
10714         (abs:TF (match_operand:TF 1 "register_operand" "0")))]
10715   "TARGET_80387 && reload_completed"
10716   "fabs"
10717   [(set_attr "type" "fsgn")
10718    (set_attr "mode" "DF")])
10719
10720 (define_insn "*absextenddftf2"
10721   [(set (match_operand:TF 0 "register_operand" "=f")
10722         (abs:TF (float_extend:TF
10723           (match_operand:DF 1 "register_operand" "0"))))]
10724   "TARGET_80387"
10725   "fabs"
10726   [(set_attr "type" "fsgn")
10727    (set_attr "mode" "XF")])
10728
10729 (define_insn "*absextendsftf2"
10730   [(set (match_operand:TF 0 "register_operand" "=f")
10731         (abs:TF (float_extend:TF
10732           (match_operand:SF 1 "register_operand" "0"))))]
10733   "TARGET_80387"
10734   "fabs"
10735   [(set_attr "type" "fsgn")
10736    (set_attr "mode" "XF")])
10737 \f
10738 ;; One complement instructions
10739
10740 (define_expand "one_cmpldi2"
10741   [(set (match_operand:DI 0 "nonimmediate_operand" "")
10742         (not:DI (match_operand:DI 1 "nonimmediate_operand" "")))]
10743   "TARGET_64BIT"
10744   "ix86_expand_unary_operator (NOT, DImode, operands); DONE;")
10745
10746 (define_insn "*one_cmpldi2_1_rex64"
10747   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
10748         (not:DI (match_operand:DI 1 "nonimmediate_operand" "0")))]
10749   "TARGET_64BIT && ix86_unary_operator_ok (NOT, DImode, operands)"
10750   "not{q}\t%0"
10751   [(set_attr "type" "negnot")
10752    (set_attr "mode" "DI")])
10753
10754 (define_insn "*one_cmpldi2_2_rex64"
10755   [(set (reg 17)
10756         (compare (not:DI (match_operand:DI 1 "nonimmediate_operand" "0"))
10757                  (const_int 0)))
10758    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
10759         (not:DI (match_dup 1)))]
10760   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
10761    && ix86_unary_operator_ok (NOT, DImode, operands)"
10762   "#"
10763   [(set_attr "type" "alu1")
10764    (set_attr "mode" "DI")])
10765
10766 (define_split
10767   [(set (reg 17)
10768         (compare (not:DI (match_operand:DI 1 "nonimmediate_operand" ""))
10769                  (const_int 0)))
10770    (set (match_operand:DI 0 "nonimmediate_operand" "")
10771         (not:DI (match_dup 1)))]
10772   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
10773   [(parallel [(set (reg:CCNO 17)
10774                    (compare:CCNO (xor:DI (match_dup 1) (const_int -1))
10775                                  (const_int 0)))
10776               (set (match_dup 0)
10777                    (xor:DI (match_dup 1) (const_int -1)))])]
10778   "")
10779
10780 (define_expand "one_cmplsi2"
10781   [(set (match_operand:SI 0 "nonimmediate_operand" "")
10782         (not:SI (match_operand:SI 1 "nonimmediate_operand" "")))]
10783   ""
10784   "ix86_expand_unary_operator (NOT, SImode, operands); DONE;")
10785
10786 (define_insn "*one_cmplsi2_1"
10787   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
10788         (not:SI (match_operand:SI 1 "nonimmediate_operand" "0")))]
10789   "ix86_unary_operator_ok (NOT, SImode, operands)"
10790   "not{l}\t%0"
10791   [(set_attr "type" "negnot")
10792    (set_attr "mode" "SI")])
10793
10794 ;; ??? Currently never generated - xor is used instead.
10795 (define_insn "*one_cmplsi2_1_zext"
10796   [(set (match_operand:DI 0 "register_operand" "=r")
10797         (zero_extend:DI (not:SI (match_operand:SI 1 "register_operand" "0"))))]
10798   "TARGET_64BIT && ix86_unary_operator_ok (NOT, SImode, operands)"
10799   "not{l}\t%k0"
10800   [(set_attr "type" "negnot")
10801    (set_attr "mode" "SI")])
10802
10803 (define_insn "*one_cmplsi2_2"
10804   [(set (reg 17)
10805         (compare (not:SI (match_operand:SI 1 "nonimmediate_operand" "0"))
10806                  (const_int 0)))
10807    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
10808         (not:SI (match_dup 1)))]
10809   "ix86_match_ccmode (insn, CCNOmode)
10810    && ix86_unary_operator_ok (NOT, SImode, operands)"
10811   "#"
10812   [(set_attr "type" "alu1")
10813    (set_attr "mode" "SI")])
10814
10815 (define_split
10816   [(set (reg 17)
10817         (compare (not:SI (match_operand:SI 1 "nonimmediate_operand" ""))
10818                  (const_int 0)))
10819    (set (match_operand:SI 0 "nonimmediate_operand" "")
10820         (not:SI (match_dup 1)))]
10821   "ix86_match_ccmode (insn, CCNOmode)"
10822   [(parallel [(set (reg:CCNO 17)
10823                    (compare:CCNO (xor:SI (match_dup 1) (const_int -1))
10824                                  (const_int 0)))
10825               (set (match_dup 0)
10826                    (xor:SI (match_dup 1) (const_int -1)))])]
10827   "")
10828
10829 ;; ??? Currently never generated - xor is used instead.
10830 (define_insn "*one_cmplsi2_2_zext"
10831   [(set (reg 17)
10832         (compare (not:SI (match_operand:SI 1 "register_operand" "0"))
10833                  (const_int 0)))
10834    (set (match_operand:DI 0 "register_operand" "=r")
10835         (zero_extend:DI (not:SI (match_dup 1))))]
10836   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
10837    && ix86_unary_operator_ok (NOT, SImode, operands)"
10838   "#"
10839   [(set_attr "type" "alu1")
10840    (set_attr "mode" "SI")])
10841
10842 (define_split
10843   [(set (reg 17)
10844         (compare (not:SI (match_operand:SI 1 "register_operand" ""))
10845                  (const_int 0)))
10846    (set (match_operand:DI 0 "register_operand" "")
10847         (zero_extend:DI (not:SI (match_dup 1))))]
10848   "ix86_match_ccmode (insn, CCNOmode)"
10849   [(parallel [(set (reg:CCNO 17)
10850                    (compare:CCNO (xor:SI (match_dup 1) (const_int -1))
10851                                  (const_int 0)))
10852               (set (match_dup 0)
10853                    (zero_extend:DI (xor:SI (match_dup 1) (const_int -1))))])]
10854   "")
10855
10856 (define_expand "one_cmplhi2"
10857   [(set (match_operand:HI 0 "nonimmediate_operand" "")
10858         (not:HI (match_operand:HI 1 "nonimmediate_operand" "")))]
10859   "TARGET_HIMODE_MATH"
10860   "ix86_expand_unary_operator (NOT, HImode, operands); DONE;")
10861
10862 (define_insn "*one_cmplhi2_1"
10863   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
10864         (not:HI (match_operand:HI 1 "nonimmediate_operand" "0")))]
10865   "ix86_unary_operator_ok (NOT, HImode, operands)"
10866   "not{w}\t%0"
10867   [(set_attr "type" "negnot")
10868    (set_attr "mode" "HI")])
10869
10870 (define_insn "*one_cmplhi2_2"
10871   [(set (reg 17)
10872         (compare (not:HI (match_operand:HI 1 "nonimmediate_operand" "0"))
10873                  (const_int 0)))
10874    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
10875         (not:HI (match_dup 1)))]
10876   "ix86_match_ccmode (insn, CCNOmode)
10877    && ix86_unary_operator_ok (NEG, HImode, operands)"
10878   "#"
10879   [(set_attr "type" "alu1")
10880    (set_attr "mode" "HI")])
10881
10882 (define_split
10883   [(set (reg 17)
10884         (compare (not:HI (match_operand:HI 1 "nonimmediate_operand" ""))
10885                  (const_int 0)))
10886    (set (match_operand:HI 0 "nonimmediate_operand" "")
10887         (not:HI (match_dup 1)))]
10888   "ix86_match_ccmode (insn, CCNOmode)"
10889   [(parallel [(set (reg:CCNO 17)
10890                    (compare:CCNO (xor:HI (match_dup 1) (const_int -1))
10891                                  (const_int 0)))
10892               (set (match_dup 0)
10893                    (xor:HI (match_dup 1) (const_int -1)))])]
10894   "")
10895
10896 ;; %%% Potential partial reg stall on alternative 1.  What to do?
10897 (define_expand "one_cmplqi2"
10898   [(set (match_operand:QI 0 "nonimmediate_operand" "")
10899         (not:QI (match_operand:QI 1 "nonimmediate_operand" "")))]
10900   "TARGET_QIMODE_MATH"
10901   "ix86_expand_unary_operator (NOT, QImode, operands); DONE;")
10902
10903 (define_insn "*one_cmplqi2_1"
10904   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r")
10905         (not:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")))]
10906   "ix86_unary_operator_ok (NOT, QImode, operands)"
10907   "@
10908    not{b}\t%0
10909    not{l}\t%k0"
10910   [(set_attr "type" "negnot")
10911    (set_attr "mode" "QI,SI")])
10912
10913 (define_insn "*one_cmplqi2_2"
10914   [(set (reg 17)
10915         (compare (not:QI (match_operand:QI 1 "nonimmediate_operand" "0"))
10916                  (const_int 0)))
10917    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
10918         (not:QI (match_dup 1)))]
10919   "ix86_match_ccmode (insn, CCNOmode)
10920    && ix86_unary_operator_ok (NOT, QImode, operands)"
10921   "#"
10922   [(set_attr "type" "alu1")
10923    (set_attr "mode" "QI")])
10924
10925 (define_split
10926   [(set (reg 17)
10927         (compare (not:QI (match_operand:QI 1 "nonimmediate_operand" ""))
10928                  (const_int 0)))
10929    (set (match_operand:QI 0 "nonimmediate_operand" "")
10930         (not:QI (match_dup 1)))]
10931   "ix86_match_ccmode (insn, CCNOmode)"
10932   [(parallel [(set (reg:CCNO 17)
10933                    (compare:CCNO (xor:QI (match_dup 1) (const_int -1))
10934                                  (const_int 0)))
10935               (set (match_dup 0)
10936                    (xor:QI (match_dup 1) (const_int -1)))])]
10937   "")
10938 \f
10939 ;; Arithmetic shift instructions
10940
10941 ;; DImode shifts are implemented using the i386 "shift double" opcode,
10942 ;; which is written as "sh[lr]d[lw] imm,reg,reg/mem".  If the shift count
10943 ;; is variable, then the count is in %cl and the "imm" operand is dropped
10944 ;; from the assembler input.
10945 ;;
10946 ;; This instruction shifts the target reg/mem as usual, but instead of
10947 ;; shifting in zeros, bits are shifted in from reg operand.  If the insn
10948 ;; is a left shift double, bits are taken from the high order bits of
10949 ;; reg, else if the insn is a shift right double, bits are taken from the
10950 ;; low order bits of reg.  So if %eax is "1234" and %edx is "5678",
10951 ;; "shldl $8,%edx,%eax" leaves %edx unchanged and sets %eax to "2345".
10952 ;;
10953 ;; Since sh[lr]d does not change the `reg' operand, that is done
10954 ;; separately, making all shifts emit pairs of shift double and normal
10955 ;; shift.  Since sh[lr]d does not shift more than 31 bits, and we wish to
10956 ;; support a 63 bit shift, each shift where the count is in a reg expands
10957 ;; to a pair of shifts, a branch, a shift by 32 and a label.
10958 ;;
10959 ;; If the shift count is a constant, we need never emit more than one
10960 ;; shift pair, instead using moves and sign extension for counts greater
10961 ;; than 31.
10962
10963 (define_expand "ashldi3"
10964   [(parallel [(set (match_operand:DI 0 "shiftdi_operand" "")
10965                    (ashift:DI (match_operand:DI 1 "shiftdi_operand" "")
10966                               (match_operand:QI 2 "nonmemory_operand" "")))
10967               (clobber (reg:CC 17))])]
10968   ""
10969 {
10970   if (!TARGET_64BIT && TARGET_CMOVE && ! immediate_operand (operands[2], QImode))
10971     {
10972       emit_insn (gen_ashldi3_1 (operands[0], operands[1], operands[2]));
10973       DONE;
10974     }
10975   ix86_expand_binary_operator (ASHIFT, DImode, operands);
10976   DONE;
10977 })
10978
10979 (define_insn "*ashldi3_1_rex64"
10980   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
10981         (ashift:DI (match_operand:DI 1 "nonimmediate_operand" "0,r")
10982                    (match_operand:QI 2 "nonmemory_operand" "cJ,M")))
10983    (clobber (reg:CC 17))]
10984   "TARGET_64BIT && ix86_binary_operator_ok (ASHIFT, DImode, operands)"
10985 {
10986   switch (get_attr_type (insn))
10987     {
10988     case TYPE_ALU:
10989       if (operands[2] != const1_rtx)
10990         abort ();
10991       if (!rtx_equal_p (operands[0], operands[1]))
10992         abort ();
10993       return "add{q}\t{%0, %0|%0, %0}";
10994
10995     case TYPE_LEA:
10996       if (GET_CODE (operands[2]) != CONST_INT
10997           || (unsigned HOST_WIDE_INT) INTVAL (operands[2]) > 3)
10998         abort ();
10999       operands[1] = gen_rtx_MULT (DImode, operands[1],
11000                                   GEN_INT (1 << INTVAL (operands[2])));
11001       return "lea{q}\t{%a1, %0|%0, %a1}";
11002
11003     default:
11004       if (REG_P (operands[2]))
11005         return "sal{q}\t{%b2, %0|%0, %b2}";
11006       else if (GET_CODE (operands[2]) == CONST_INT
11007                && INTVAL (operands[2]) == 1
11008                && (TARGET_SHIFT1 || optimize_size))
11009         return "sal{q}\t%0";
11010       else
11011         return "sal{q}\t{%2, %0|%0, %2}";
11012     }
11013 }
11014   [(set (attr "type")
11015      (cond [(eq_attr "alternative" "1")
11016               (const_string "lea")
11017             (and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11018                           (const_int 0))
11019                       (match_operand 0 "register_operand" ""))
11020                  (match_operand 2 "const1_operand" ""))
11021               (const_string "alu")
11022            ]
11023            (const_string "ishift")))
11024    (set_attr "mode" "DI")])
11025
11026 ;; Convert lea to the lea pattern to avoid flags dependency.
11027 (define_split
11028   [(set (match_operand:DI 0 "register_operand" "")
11029         (ashift:DI (match_operand:DI 1 "register_operand" "")
11030                    (match_operand:QI 2 "immediate_operand" "")))
11031    (clobber (reg:CC 17))]
11032   "TARGET_64BIT && reload_completed
11033    && true_regnum (operands[0]) != true_regnum (operands[1])"
11034   [(set (match_dup 0)
11035         (mult:DI (match_dup 1)
11036                  (match_dup 2)))]
11037   "operands[2] = gen_int_mode (1 << INTVAL (operands[2]), DImode);")
11038
11039 ;; This pattern can't accept a variable shift count, since shifts by
11040 ;; zero don't affect the flags.  We assume that shifts by constant
11041 ;; zero are optimized away.
11042 (define_insn "*ashldi3_cmp_rex64"
11043   [(set (reg 17)
11044         (compare
11045           (ashift:DI (match_operand:DI 1 "nonimmediate_operand" "0")
11046                      (match_operand:QI 2 "immediate_operand" "e"))
11047           (const_int 0)))
11048    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
11049         (ashift:DI (match_dup 1) (match_dup 2)))]
11050   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
11051    && ix86_binary_operator_ok (ASHIFT, DImode, operands)"
11052 {
11053   switch (get_attr_type (insn))
11054     {
11055     case TYPE_ALU:
11056       if (operands[2] != const1_rtx)
11057         abort ();
11058       return "add{q}\t{%0, %0|%0, %0}";
11059
11060     default:
11061       if (REG_P (operands[2]))
11062         return "sal{q}\t{%b2, %0|%0, %b2}";
11063       else if (GET_CODE (operands[2]) == CONST_INT
11064                && INTVAL (operands[2]) == 1
11065                && (TARGET_SHIFT1 || optimize_size))
11066         return "sal{q}\t%0";
11067       else
11068         return "sal{q}\t{%2, %0|%0, %2}";
11069     }
11070 }
11071   [(set (attr "type")
11072      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11073                           (const_int 0))
11074                       (match_operand 0 "register_operand" ""))
11075                  (match_operand 2 "const1_operand" ""))
11076               (const_string "alu")
11077            ]
11078            (const_string "ishift")))
11079    (set_attr "mode" "DI")])
11080
11081 (define_insn "ashldi3_1"
11082   [(set (match_operand:DI 0 "register_operand" "=r")
11083         (ashift:DI (match_operand:DI 1 "register_operand" "0")
11084                    (match_operand:QI 2 "nonmemory_operand" "Jc")))
11085    (clobber (match_scratch:SI 3 "=&r"))
11086    (clobber (reg:CC 17))]
11087   "!TARGET_64BIT && TARGET_CMOVE"
11088   "#"
11089   [(set_attr "type" "multi")])
11090
11091 (define_insn "*ashldi3_2"
11092   [(set (match_operand:DI 0 "register_operand" "=r")
11093         (ashift:DI (match_operand:DI 1 "register_operand" "0")
11094                    (match_operand:QI 2 "nonmemory_operand" "Jc")))
11095    (clobber (reg:CC 17))]
11096   "!TARGET_64BIT"
11097   "#"
11098   [(set_attr "type" "multi")])
11099
11100 (define_split
11101   [(set (match_operand:DI 0 "register_operand" "")
11102         (ashift:DI (match_operand:DI 1 "register_operand" "")
11103                    (match_operand:QI 2 "nonmemory_operand" "")))
11104    (clobber (match_scratch:SI 3 ""))
11105    (clobber (reg:CC 17))]
11106   "!TARGET_64BIT && TARGET_CMOVE && reload_completed"
11107   [(const_int 0)]
11108   "ix86_split_ashldi (operands, operands[3]); DONE;")
11109
11110 (define_split
11111   [(set (match_operand:DI 0 "register_operand" "")
11112         (ashift:DI (match_operand:DI 1 "register_operand" "")
11113                    (match_operand:QI 2 "nonmemory_operand" "")))
11114    (clobber (reg:CC 17))]
11115   "!TARGET_64BIT && reload_completed"
11116   [(const_int 0)]
11117   "ix86_split_ashldi (operands, NULL_RTX); DONE;")
11118
11119 (define_insn "x86_shld_1"
11120   [(set (match_operand:SI 0 "nonimmediate_operand" "+r*m,r*m")
11121         (ior:SI (ashift:SI (match_dup 0)
11122                   (match_operand:QI 2 "nonmemory_operand" "I,c"))
11123                 (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,r")
11124                   (minus:QI (const_int 32) (match_dup 2)))))
11125    (clobber (reg:CC 17))]
11126   ""
11127   "@
11128    shld{l}\t{%2, %1, %0|%0, %1, %2}
11129    shld{l}\t{%s2%1, %0|%0, %1, %2}"
11130   [(set_attr "type" "ishift")
11131    (set_attr "prefix_0f" "1")
11132    (set_attr "mode" "SI")
11133    (set_attr "pent_pair" "np")
11134    (set_attr "athlon_decode" "vector")
11135    (set_attr "ppro_uops" "few")])
11136
11137 (define_expand "x86_shift_adj_1"
11138   [(set (reg:CCZ 17)
11139         (compare:CCZ (and:QI (match_operand:QI 2 "register_operand" "")
11140                              (const_int 32))
11141                      (const_int 0)))
11142    (set (match_operand:SI 0 "register_operand" "")
11143         (if_then_else:SI (ne (reg:CCZ 17) (const_int 0))
11144                          (match_operand:SI 1 "register_operand" "")
11145                          (match_dup 0)))
11146    (set (match_dup 1)
11147         (if_then_else:SI (ne (reg:CCZ 17) (const_int 0))
11148                          (match_operand:SI 3 "register_operand" "r")
11149                          (match_dup 1)))]
11150   "TARGET_CMOVE"
11151   "")
11152
11153 (define_expand "x86_shift_adj_2"
11154   [(use (match_operand:SI 0 "register_operand" ""))
11155    (use (match_operand:SI 1 "register_operand" ""))
11156    (use (match_operand:QI 2 "register_operand" ""))]
11157   ""
11158 {
11159   rtx label = gen_label_rtx ();
11160   rtx tmp;
11161
11162   emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (32)));
11163
11164   tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
11165   tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
11166   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
11167                               gen_rtx_LABEL_REF (VOIDmode, label),
11168                               pc_rtx);
11169   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
11170   JUMP_LABEL (tmp) = label;
11171
11172   emit_move_insn (operands[0], operands[1]);
11173   emit_move_insn (operands[1], const0_rtx);
11174
11175   emit_label (label);
11176   LABEL_NUSES (label) = 1;
11177
11178   DONE;
11179 })
11180
11181 (define_expand "ashlsi3"
11182   [(set (match_operand:SI 0 "nonimmediate_operand" "")
11183         (ashift:SI (match_operand:SI 1 "nonimmediate_operand" "")
11184                    (match_operand:QI 2 "nonmemory_operand" "")))
11185    (clobber (reg:CC 17))]
11186   ""
11187   "ix86_expand_binary_operator (ASHIFT, SImode, operands); DONE;")
11188
11189 (define_insn "*ashlsi3_1"
11190   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
11191         (ashift:SI (match_operand:SI 1 "nonimmediate_operand" "0,r")
11192                    (match_operand:QI 2 "nonmemory_operand" "cI,M")))
11193    (clobber (reg:CC 17))]
11194   "ix86_binary_operator_ok (ASHIFT, SImode, operands)"
11195 {
11196   switch (get_attr_type (insn))
11197     {
11198     case TYPE_ALU:
11199       if (operands[2] != const1_rtx)
11200         abort ();
11201       if (!rtx_equal_p (operands[0], operands[1]))
11202         abort ();
11203       return "add{l}\t{%0, %0|%0, %0}";
11204
11205     case TYPE_LEA:
11206       return "#";
11207
11208     default:
11209       if (REG_P (operands[2]))
11210         return "sal{l}\t{%b2, %0|%0, %b2}";
11211       else if (GET_CODE (operands[2]) == CONST_INT
11212                && INTVAL (operands[2]) == 1
11213                && (TARGET_SHIFT1 || optimize_size))
11214         return "sal{l}\t%0";
11215       else
11216         return "sal{l}\t{%2, %0|%0, %2}";
11217     }
11218 }
11219   [(set (attr "type")
11220      (cond [(eq_attr "alternative" "1")
11221               (const_string "lea")
11222             (and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11223                           (const_int 0))
11224                       (match_operand 0 "register_operand" ""))
11225                  (match_operand 2 "const1_operand" ""))
11226               (const_string "alu")
11227            ]
11228            (const_string "ishift")))
11229    (set_attr "mode" "SI")])
11230
11231 ;; Convert lea to the lea pattern to avoid flags dependency.
11232 (define_split
11233   [(set (match_operand 0 "register_operand" "")
11234         (ashift (match_operand 1 "index_register_operand" "")
11235                 (match_operand:QI 2 "const_int_operand" "")))
11236    (clobber (reg:CC 17))]
11237   "reload_completed
11238    && true_regnum (operands[0]) != true_regnum (operands[1])"
11239   [(const_int 0)]
11240 {
11241   rtx pat;
11242   operands[0] = gen_lowpart (SImode, operands[0]);
11243   operands[1] = gen_lowpart (Pmode, operands[1]);
11244   operands[2] = gen_int_mode (1 << INTVAL (operands[2]), Pmode);
11245   pat = gen_rtx_MULT (Pmode, operands[1], operands[2]);
11246   if (Pmode != SImode)
11247     pat = gen_rtx_SUBREG (SImode, pat, 0);
11248   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
11249   DONE;
11250 })
11251
11252 ;; Rare case of shifting RSP is handled by generating move and shift
11253 (define_split
11254   [(set (match_operand 0 "register_operand" "")
11255         (ashift (match_operand 1 "register_operand" "")
11256                 (match_operand:QI 2 "const_int_operand" "")))
11257    (clobber (reg:CC 17))]
11258   "reload_completed
11259    && true_regnum (operands[0]) != true_regnum (operands[1])"
11260   [(const_int 0)]
11261 {
11262   rtx pat, clob;
11263   emit_move_insn (operands[1], operands[0]);
11264   pat = gen_rtx_SET (VOIDmode, operands[0],
11265                      gen_rtx_ASHIFT (GET_MODE (operands[0]),
11266                                      operands[0], operands[2]));
11267   clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
11268   emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, pat, clob)));
11269   DONE;
11270 })
11271
11272 (define_insn "*ashlsi3_1_zext"
11273   [(set (match_operand:DI 0 "register_operand" "=r,r")
11274         (zero_extend:DI (ashift:SI (match_operand:SI 1 "register_operand" "0,r")
11275                         (match_operand:QI 2 "nonmemory_operand" "cI,M"))))
11276    (clobber (reg:CC 17))]
11277   "TARGET_64BIT && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
11278 {
11279   switch (get_attr_type (insn))
11280     {
11281     case TYPE_ALU:
11282       if (operands[2] != const1_rtx)
11283         abort ();
11284       return "add{l}\t{%k0, %k0|%k0, %k0}";
11285
11286     case TYPE_LEA:
11287       return "#";
11288
11289     default:
11290       if (REG_P (operands[2]))
11291         return "sal{l}\t{%b2, %k0|%k0, %b2}";
11292       else if (GET_CODE (operands[2]) == CONST_INT
11293                && INTVAL (operands[2]) == 1
11294                && (TARGET_SHIFT1 || optimize_size))
11295         return "sal{l}\t%k0";
11296       else
11297         return "sal{l}\t{%2, %k0|%k0, %2}";
11298     }
11299 }
11300   [(set (attr "type")
11301      (cond [(eq_attr "alternative" "1")
11302               (const_string "lea")
11303             (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11304                      (const_int 0))
11305                  (match_operand 2 "const1_operand" ""))
11306               (const_string "alu")
11307            ]
11308            (const_string "ishift")))
11309    (set_attr "mode" "SI")])
11310
11311 ;; Convert lea to the lea pattern to avoid flags dependency.
11312 (define_split
11313   [(set (match_operand:DI 0 "register_operand" "")
11314         (zero_extend:DI (ashift (match_operand 1 "register_operand" "")
11315                                 (match_operand:QI 2 "const_int_operand" ""))))
11316    (clobber (reg:CC 17))]
11317   "TARGET_64BIT && reload_completed
11318    && true_regnum (operands[0]) != true_regnum (operands[1])"
11319   [(set (match_dup 0) (zero_extend:DI
11320                         (subreg:SI (mult:SI (match_dup 1)
11321                                             (match_dup 2)) 0)))]
11322 {
11323   operands[1] = gen_lowpart (Pmode, operands[1]);
11324   operands[2] = gen_int_mode (1 << INTVAL (operands[2]), Pmode);
11325 })
11326
11327 ;; This pattern can't accept a variable shift count, since shifts by
11328 ;; zero don't affect the flags.  We assume that shifts by constant
11329 ;; zero are optimized away.
11330 (define_insn "*ashlsi3_cmp"
11331   [(set (reg 17)
11332         (compare
11333           (ashift:SI (match_operand:SI 1 "nonimmediate_operand" "0")
11334                      (match_operand:QI 2 "const_int_1_31_operand" "I"))
11335           (const_int 0)))
11336    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
11337         (ashift:SI (match_dup 1) (match_dup 2)))]
11338   "ix86_match_ccmode (insn, CCGOCmode)
11339    && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
11340 {
11341   switch (get_attr_type (insn))
11342     {
11343     case TYPE_ALU:
11344       if (operands[2] != const1_rtx)
11345         abort ();
11346       return "add{l}\t{%0, %0|%0, %0}";
11347
11348     default:
11349       if (REG_P (operands[2]))
11350         return "sal{l}\t{%b2, %0|%0, %b2}";
11351       else if (GET_CODE (operands[2]) == CONST_INT
11352                && INTVAL (operands[2]) == 1
11353                && (TARGET_SHIFT1 || optimize_size))
11354         return "sal{l}\t%0";
11355       else
11356         return "sal{l}\t{%2, %0|%0, %2}";
11357     }
11358 }
11359   [(set (attr "type")
11360      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11361                           (const_int 0))
11362                       (match_operand 0 "register_operand" ""))
11363                  (match_operand 2 "const1_operand" ""))
11364               (const_string "alu")
11365            ]
11366            (const_string "ishift")))
11367    (set_attr "mode" "SI")])
11368
11369 (define_insn "*ashlsi3_cmp_zext"
11370   [(set (reg 17)
11371         (compare
11372           (ashift:SI (match_operand:SI 1 "register_operand" "0")
11373                      (match_operand:QI 2 "const_int_1_31_operand" "I"))
11374           (const_int 0)))
11375    (set (match_operand:DI 0 "register_operand" "=r")
11376         (zero_extend:DI (ashift:SI (match_dup 1) (match_dup 2))))]
11377   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
11378    && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
11379 {
11380   switch (get_attr_type (insn))
11381     {
11382     case TYPE_ALU:
11383       if (operands[2] != const1_rtx)
11384         abort ();
11385       return "add{l}\t{%k0, %k0|%k0, %k0}";
11386
11387     default:
11388       if (REG_P (operands[2]))
11389         return "sal{l}\t{%b2, %k0|%k0, %b2}";
11390       else if (GET_CODE (operands[2]) == CONST_INT
11391                && INTVAL (operands[2]) == 1
11392                && (TARGET_SHIFT1 || optimize_size))
11393         return "sal{l}\t%k0";
11394       else
11395         return "sal{l}\t{%2, %k0|%k0, %2}";
11396     }
11397 }
11398   [(set (attr "type")
11399      (cond [(and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11400                      (const_int 0))
11401                  (match_operand 2 "const1_operand" ""))
11402               (const_string "alu")
11403            ]
11404            (const_string "ishift")))
11405    (set_attr "mode" "SI")])
11406
11407 (define_expand "ashlhi3"
11408   [(set (match_operand:HI 0 "nonimmediate_operand" "")
11409         (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "")
11410                    (match_operand:QI 2 "nonmemory_operand" "")))
11411    (clobber (reg:CC 17))]
11412   "TARGET_HIMODE_MATH"
11413   "ix86_expand_binary_operator (ASHIFT, HImode, operands); DONE;")
11414
11415 (define_insn "*ashlhi3_1_lea"
11416   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r")
11417         (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0,r")
11418                    (match_operand:QI 2 "nonmemory_operand" "cI,M")))
11419    (clobber (reg:CC 17))]
11420   "!TARGET_PARTIAL_REG_STALL
11421    && ix86_binary_operator_ok (ASHIFT, HImode, operands)"
11422 {
11423   switch (get_attr_type (insn))
11424     {
11425     case TYPE_LEA:
11426       return "#";
11427     case TYPE_ALU:
11428       if (operands[2] != const1_rtx)
11429         abort ();
11430       return "add{w}\t{%0, %0|%0, %0}";
11431
11432     default:
11433       if (REG_P (operands[2]))
11434         return "sal{w}\t{%b2, %0|%0, %b2}";
11435       else if (GET_CODE (operands[2]) == CONST_INT
11436                && INTVAL (operands[2]) == 1
11437                && (TARGET_SHIFT1 || optimize_size))
11438         return "sal{w}\t%0";
11439       else
11440         return "sal{w}\t{%2, %0|%0, %2}";
11441     }
11442 }
11443   [(set (attr "type")
11444      (cond [(eq_attr "alternative" "1")
11445               (const_string "lea")
11446             (and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11447                           (const_int 0))
11448                       (match_operand 0 "register_operand" ""))
11449                  (match_operand 2 "const1_operand" ""))
11450               (const_string "alu")
11451            ]
11452            (const_string "ishift")))
11453    (set_attr "mode" "HI,SI")])
11454
11455 (define_insn "*ashlhi3_1"
11456   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
11457         (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0")
11458                    (match_operand:QI 2 "nonmemory_operand" "cI")))
11459    (clobber (reg:CC 17))]
11460   "TARGET_PARTIAL_REG_STALL
11461    && ix86_binary_operator_ok (ASHIFT, HImode, operands)"
11462 {
11463   switch (get_attr_type (insn))
11464     {
11465     case TYPE_ALU:
11466       if (operands[2] != const1_rtx)
11467         abort ();
11468       return "add{w}\t{%0, %0|%0, %0}";
11469
11470     default:
11471       if (REG_P (operands[2]))
11472         return "sal{w}\t{%b2, %0|%0, %b2}";
11473       else if (GET_CODE (operands[2]) == CONST_INT
11474                && INTVAL (operands[2]) == 1
11475                && (TARGET_SHIFT1 || optimize_size))
11476         return "sal{w}\t%0";
11477       else
11478         return "sal{w}\t{%2, %0|%0, %2}";
11479     }
11480 }
11481   [(set (attr "type")
11482      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11483                           (const_int 0))
11484                       (match_operand 0 "register_operand" ""))
11485                  (match_operand 2 "const1_operand" ""))
11486               (const_string "alu")
11487            ]
11488            (const_string "ishift")))
11489    (set_attr "mode" "HI")])
11490
11491 ;; This pattern can't accept a variable shift count, since shifts by
11492 ;; zero don't affect the flags.  We assume that shifts by constant
11493 ;; zero are optimized away.
11494 (define_insn "*ashlhi3_cmp"
11495   [(set (reg 17)
11496         (compare
11497           (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0")
11498                      (match_operand:QI 2 "const_int_1_31_operand" "I"))
11499           (const_int 0)))
11500    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
11501         (ashift:HI (match_dup 1) (match_dup 2)))]
11502   "ix86_match_ccmode (insn, CCGOCmode)
11503    && ix86_binary_operator_ok (ASHIFT, HImode, operands)"
11504 {
11505   switch (get_attr_type (insn))
11506     {
11507     case TYPE_ALU:
11508       if (operands[2] != const1_rtx)
11509         abort ();
11510       return "add{w}\t{%0, %0|%0, %0}";
11511
11512     default:
11513       if (REG_P (operands[2]))
11514         return "sal{w}\t{%b2, %0|%0, %b2}";
11515       else if (GET_CODE (operands[2]) == CONST_INT
11516                && INTVAL (operands[2]) == 1
11517                && (TARGET_SHIFT1 || optimize_size))
11518         return "sal{w}\t%0";
11519       else
11520         return "sal{w}\t{%2, %0|%0, %2}";
11521     }
11522 }
11523   [(set (attr "type")
11524      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11525                           (const_int 0))
11526                       (match_operand 0 "register_operand" ""))
11527                  (match_operand 2 "const1_operand" ""))
11528               (const_string "alu")
11529            ]
11530            (const_string "ishift")))
11531    (set_attr "mode" "HI")])
11532
11533 (define_expand "ashlqi3"
11534   [(set (match_operand:QI 0 "nonimmediate_operand" "")
11535         (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "")
11536                    (match_operand:QI 2 "nonmemory_operand" "")))
11537    (clobber (reg:CC 17))]
11538   "TARGET_QIMODE_MATH"
11539   "ix86_expand_binary_operator (ASHIFT, QImode, operands); DONE;")
11540
11541 ;; %%% Potential partial reg stall on alternative 2.  What to do?
11542
11543 (define_insn "*ashlqi3_1_lea"
11544   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r,r")
11545         (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0,0,r")
11546                    (match_operand:QI 2 "nonmemory_operand" "cI,cI,M")))
11547    (clobber (reg:CC 17))]
11548   "!TARGET_PARTIAL_REG_STALL
11549    && ix86_binary_operator_ok (ASHIFT, QImode, operands)"
11550 {
11551   switch (get_attr_type (insn))
11552     {
11553     case TYPE_LEA:
11554       return "#";
11555     case TYPE_ALU:
11556       if (operands[2] != const1_rtx)
11557         abort ();
11558       if (REG_P (operands[1]) && !ANY_QI_REG_P (operands[1]))
11559         return "add{l}\t{%k0, %k0|%k0, %k0}";
11560       else
11561         return "add{b}\t{%0, %0|%0, %0}";
11562
11563     default:
11564       if (REG_P (operands[2]))
11565         {
11566           if (get_attr_mode (insn) == MODE_SI)
11567             return "sal{l}\t{%b2, %k0|%k0, %b2}";
11568           else
11569             return "sal{b}\t{%b2, %0|%0, %b2}";
11570         }
11571       else if (GET_CODE (operands[2]) == CONST_INT
11572                && INTVAL (operands[2]) == 1
11573                && (TARGET_SHIFT1 || optimize_size))
11574         {
11575           if (get_attr_mode (insn) == MODE_SI)
11576             return "sal{l}\t%0";
11577           else
11578             return "sal{b}\t%0";
11579         }
11580       else
11581         {
11582           if (get_attr_mode (insn) == MODE_SI)
11583             return "sal{l}\t{%2, %k0|%k0, %2}";
11584           else
11585             return "sal{b}\t{%2, %0|%0, %2}";
11586         }
11587     }
11588 }
11589   [(set (attr "type")
11590      (cond [(eq_attr "alternative" "2")
11591               (const_string "lea")
11592             (and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11593                           (const_int 0))
11594                       (match_operand 0 "register_operand" ""))
11595                  (match_operand 2 "const1_operand" ""))
11596               (const_string "alu")
11597            ]
11598            (const_string "ishift")))
11599    (set_attr "mode" "QI,SI,SI")])
11600
11601 (define_insn "*ashlqi3_1"
11602   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r")
11603         (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
11604                    (match_operand:QI 2 "nonmemory_operand" "cI,cI")))
11605    (clobber (reg:CC 17))]
11606   "TARGET_PARTIAL_REG_STALL
11607    && ix86_binary_operator_ok (ASHIFT, QImode, operands)"
11608 {
11609   switch (get_attr_type (insn))
11610     {
11611     case TYPE_ALU:
11612       if (operands[2] != const1_rtx)
11613         abort ();
11614       if (REG_P (operands[1]) && !ANY_QI_REG_P (operands[1]))
11615         return "add{l}\t{%k0, %k0|%k0, %k0}";
11616       else
11617         return "add{b}\t{%0, %0|%0, %0}";
11618
11619     default:
11620       if (REG_P (operands[2]))
11621         {
11622           if (get_attr_mode (insn) == MODE_SI)
11623             return "sal{l}\t{%b2, %k0|%k0, %b2}";
11624           else
11625             return "sal{b}\t{%b2, %0|%0, %b2}";
11626         }
11627       else if (GET_CODE (operands[2]) == CONST_INT
11628                && INTVAL (operands[2]) == 1
11629                && (TARGET_SHIFT1 || optimize_size))
11630         {
11631           if (get_attr_mode (insn) == MODE_SI)
11632             return "sal{l}\t%0";
11633           else
11634             return "sal{b}\t%0";
11635         }
11636       else
11637         {
11638           if (get_attr_mode (insn) == MODE_SI)
11639             return "sal{l}\t{%2, %k0|%k0, %2}";
11640           else
11641             return "sal{b}\t{%2, %0|%0, %2}";
11642         }
11643     }
11644 }
11645   [(set (attr "type")
11646      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11647                           (const_int 0))
11648                       (match_operand 0 "register_operand" ""))
11649                  (match_operand 2 "const1_operand" ""))
11650               (const_string "alu")
11651            ]
11652            (const_string "ishift")))
11653    (set_attr "mode" "QI,SI")])
11654
11655 ;; This pattern can't accept a variable shift count, since shifts by
11656 ;; zero don't affect the flags.  We assume that shifts by constant
11657 ;; zero are optimized away.
11658 (define_insn "*ashlqi3_cmp"
11659   [(set (reg 17)
11660         (compare
11661           (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0")
11662                      (match_operand:QI 2 "const_int_1_31_operand" "I"))
11663           (const_int 0)))
11664    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
11665         (ashift:QI (match_dup 1) (match_dup 2)))]
11666   "ix86_match_ccmode (insn, CCGOCmode)
11667    && ix86_binary_operator_ok (ASHIFT, QImode, operands)"
11668 {
11669   switch (get_attr_type (insn))
11670     {
11671     case TYPE_ALU:
11672       if (operands[2] != const1_rtx)
11673         abort ();
11674       return "add{b}\t{%0, %0|%0, %0}";
11675
11676     default:
11677       if (REG_P (operands[2]))
11678         return "sal{b}\t{%b2, %0|%0, %b2}";
11679       else if (GET_CODE (operands[2]) == CONST_INT
11680                && INTVAL (operands[2]) == 1
11681                && (TARGET_SHIFT1 || optimize_size))
11682         return "sal{b}\t%0";
11683       else
11684         return "sal{b}\t{%2, %0|%0, %2}";
11685     }
11686 }
11687   [(set (attr "type")
11688      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11689                           (const_int 0))
11690                       (match_operand 0 "register_operand" ""))
11691                  (match_operand 2 "const1_operand" ""))
11692               (const_string "alu")
11693            ]
11694            (const_string "ishift")))
11695    (set_attr "mode" "QI")])
11696
11697 ;; See comment above `ashldi3' about how this works.
11698
11699 (define_expand "ashrdi3"
11700   [(parallel [(set (match_operand:DI 0 "shiftdi_operand" "")
11701                    (ashiftrt:DI (match_operand:DI 1 "shiftdi_operand" "")
11702                                 (match_operand:QI 2 "nonmemory_operand" "")))
11703               (clobber (reg:CC 17))])]
11704   ""
11705 {
11706   if (!TARGET_64BIT && TARGET_CMOVE && ! immediate_operand (operands[2], QImode))
11707     {
11708       emit_insn (gen_ashrdi3_1 (operands[0], operands[1], operands[2]));
11709       DONE;
11710     }
11711   ix86_expand_binary_operator (ASHIFTRT, DImode, operands);
11712   DONE;
11713 })
11714
11715 (define_insn "ashrdi3_63_rex64"
11716   [(set (match_operand:DI 0 "nonimmediate_operand" "=*d,rm")
11717         (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "*a,0")
11718                      (match_operand:DI 2 "const_int_operand" "i,i")))
11719    (clobber (reg:CC 17))]
11720   "TARGET_64BIT && INTVAL (operands[2]) == 63 && (TARGET_USE_CLTD || optimize_size)
11721    && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
11722   "@
11723    {cqto|cqo}
11724    sar{q}\t{%2, %0|%0, %2}"
11725   [(set_attr "type" "imovx,ishift")
11726    (set_attr "prefix_0f" "0,*")
11727    (set_attr "length_immediate" "0,*")
11728    (set_attr "modrm" "0,1")
11729    (set_attr "mode" "DI")])
11730
11731 (define_insn "*ashrdi3_1_one_bit_rex64"
11732   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
11733         (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
11734                      (match_operand:QI 2 "const_int_1_operand" "")))
11735    (clobber (reg:CC 17))]
11736   "TARGET_64BIT && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)
11737    && (TARGET_SHIFT1 || optimize_size)"
11738   "sar{q}\t%0"
11739   [(set_attr "type" "ishift")
11740    (set (attr "length") 
11741      (if_then_else (match_operand:DI 0 "register_operand" "") 
11742         (const_string "2")
11743         (const_string "*")))])
11744
11745 (define_insn "*ashrdi3_1_rex64"
11746   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,rm")
11747         (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
11748                      (match_operand:QI 2 "nonmemory_operand" "J,c")))
11749    (clobber (reg:CC 17))]
11750   "TARGET_64BIT && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
11751   "@
11752    sar{q}\t{%2, %0|%0, %2}
11753    sar{q}\t{%b2, %0|%0, %b2}"
11754   [(set_attr "type" "ishift")
11755    (set_attr "mode" "DI")])
11756
11757 ;; This pattern can't accept a variable shift count, since shifts by
11758 ;; zero don't affect the flags.  We assume that shifts by constant
11759 ;; zero are optimized away.
11760 (define_insn "*ashrdi3_one_bit_cmp_rex64"
11761   [(set (reg 17)
11762         (compare
11763           (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
11764                        (match_operand:QI 2 "const_int_1_operand" ""))
11765           (const_int 0)))
11766    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
11767         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
11768   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
11769    && (TARGET_SHIFT1 || optimize_size)
11770    && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
11771   "sar{q}\t%0"
11772   [(set_attr "type" "ishift")
11773    (set (attr "length") 
11774      (if_then_else (match_operand:DI 0 "register_operand" "") 
11775         (const_string "2")
11776         (const_string "*")))])
11777
11778 ;; This pattern can't accept a variable shift count, since shifts by
11779 ;; zero don't affect the flags.  We assume that shifts by constant
11780 ;; zero are optimized away.
11781 (define_insn "*ashrdi3_cmp_rex64"
11782   [(set (reg 17)
11783         (compare
11784           (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
11785                        (match_operand:QI 2 "const_int_operand" "n"))
11786           (const_int 0)))
11787    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
11788         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
11789   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
11790    && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
11791   "sar{q}\t{%2, %0|%0, %2}"
11792   [(set_attr "type" "ishift")
11793    (set_attr "mode" "DI")])
11794
11795
11796 (define_insn "ashrdi3_1"
11797   [(set (match_operand:DI 0 "register_operand" "=r")
11798         (ashiftrt:DI (match_operand:DI 1 "register_operand" "0")
11799                      (match_operand:QI 2 "nonmemory_operand" "Jc")))
11800    (clobber (match_scratch:SI 3 "=&r"))
11801    (clobber (reg:CC 17))]
11802   "!TARGET_64BIT && TARGET_CMOVE"
11803   "#"
11804   [(set_attr "type" "multi")])
11805
11806 (define_insn "*ashrdi3_2"
11807   [(set (match_operand:DI 0 "register_operand" "=r")
11808         (ashiftrt:DI (match_operand:DI 1 "register_operand" "0")
11809                      (match_operand:QI 2 "nonmemory_operand" "Jc")))
11810    (clobber (reg:CC 17))]
11811   "!TARGET_64BIT"
11812   "#"
11813   [(set_attr "type" "multi")])
11814
11815 (define_split
11816   [(set (match_operand:DI 0 "register_operand" "")
11817         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
11818                      (match_operand:QI 2 "nonmemory_operand" "")))
11819    (clobber (match_scratch:SI 3 ""))
11820    (clobber (reg:CC 17))]
11821   "!TARGET_64BIT && TARGET_CMOVE && reload_completed"
11822   [(const_int 0)]
11823   "ix86_split_ashrdi (operands, operands[3]); DONE;")
11824
11825 (define_split
11826   [(set (match_operand:DI 0 "register_operand" "")
11827         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
11828                      (match_operand:QI 2 "nonmemory_operand" "")))
11829    (clobber (reg:CC 17))]
11830   "!TARGET_64BIT && reload_completed"
11831   [(const_int 0)]
11832   "ix86_split_ashrdi (operands, NULL_RTX); DONE;")
11833
11834 (define_insn "x86_shrd_1"
11835   [(set (match_operand:SI 0 "nonimmediate_operand" "+r*m,r*m")
11836         (ior:SI (ashiftrt:SI (match_dup 0)
11837                   (match_operand:QI 2 "nonmemory_operand" "I,c"))
11838                 (ashift:SI (match_operand:SI 1 "register_operand" "r,r")
11839                   (minus:QI (const_int 32) (match_dup 2)))))
11840    (clobber (reg:CC 17))]
11841   ""
11842   "@
11843    shrd{l}\t{%2, %1, %0|%0, %1, %2}
11844    shrd{l}\t{%s2%1, %0|%0, %1, %2}"
11845   [(set_attr "type" "ishift")
11846    (set_attr "prefix_0f" "1")
11847    (set_attr "pent_pair" "np")
11848    (set_attr "ppro_uops" "few")
11849    (set_attr "mode" "SI")])
11850
11851 (define_expand "x86_shift_adj_3"
11852   [(use (match_operand:SI 0 "register_operand" ""))
11853    (use (match_operand:SI 1 "register_operand" ""))
11854    (use (match_operand:QI 2 "register_operand" ""))]
11855   ""
11856 {
11857   rtx label = gen_label_rtx ();
11858   rtx tmp;
11859
11860   emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (32)));
11861
11862   tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
11863   tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
11864   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
11865                               gen_rtx_LABEL_REF (VOIDmode, label),
11866                               pc_rtx);
11867   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
11868   JUMP_LABEL (tmp) = label;
11869
11870   emit_move_insn (operands[0], operands[1]);
11871   emit_insn (gen_ashrsi3_31 (operands[1], operands[1], GEN_INT (31)));
11872
11873   emit_label (label);
11874   LABEL_NUSES (label) = 1;
11875
11876   DONE;
11877 })
11878
11879 (define_insn "ashrsi3_31"
11880   [(set (match_operand:SI 0 "nonimmediate_operand" "=*d,rm")
11881         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "*a,0")
11882                      (match_operand:SI 2 "const_int_operand" "i,i")))
11883    (clobber (reg:CC 17))]
11884   "INTVAL (operands[2]) == 31 && (TARGET_USE_CLTD || optimize_size)
11885    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
11886   "@
11887    {cltd|cdq}
11888    sar{l}\t{%2, %0|%0, %2}"
11889   [(set_attr "type" "imovx,ishift")
11890    (set_attr "prefix_0f" "0,*")
11891    (set_attr "length_immediate" "0,*")
11892    (set_attr "modrm" "0,1")
11893    (set_attr "mode" "SI")])
11894
11895 (define_insn "*ashrsi3_31_zext"
11896   [(set (match_operand:DI 0 "register_operand" "=*d,r")
11897         (zero_extend:DI (ashiftrt:SI (match_operand:SI 1 "register_operand" "*a,0")
11898                                      (match_operand:SI 2 "const_int_operand" "i,i"))))
11899    (clobber (reg:CC 17))]
11900   "TARGET_64BIT && (TARGET_USE_CLTD || optimize_size)
11901    && INTVAL (operands[2]) == 31
11902    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
11903   "@
11904    {cltd|cdq}
11905    sar{l}\t{%2, %k0|%k0, %2}"
11906   [(set_attr "type" "imovx,ishift")
11907    (set_attr "prefix_0f" "0,*")
11908    (set_attr "length_immediate" "0,*")
11909    (set_attr "modrm" "0,1")
11910    (set_attr "mode" "SI")])
11911
11912 (define_expand "ashrsi3"
11913   [(set (match_operand:SI 0 "nonimmediate_operand" "")
11914         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "")
11915                      (match_operand:QI 2 "nonmemory_operand" "")))
11916    (clobber (reg:CC 17))]
11917   ""
11918   "ix86_expand_binary_operator (ASHIFTRT, SImode, operands); DONE;")
11919
11920 (define_insn "*ashrsi3_1_one_bit"
11921   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
11922         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
11923                      (match_operand:QI 2 "const_int_1_operand" "")))
11924    (clobber (reg:CC 17))]
11925   "ix86_binary_operator_ok (ASHIFTRT, SImode, operands)
11926    && (TARGET_SHIFT1 || optimize_size)"
11927   "sar{l}\t%0"
11928   [(set_attr "type" "ishift")
11929    (set (attr "length") 
11930      (if_then_else (match_operand:SI 0 "register_operand" "") 
11931         (const_string "2")
11932         (const_string "*")))])
11933
11934 (define_insn "*ashrsi3_1_one_bit_zext"
11935   [(set (match_operand:DI 0 "register_operand" "=r")
11936         (zero_extend:DI (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
11937                                      (match_operand:QI 2 "const_int_1_operand" ""))))
11938    (clobber (reg:CC 17))]
11939   "TARGET_64BIT && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)
11940    && (TARGET_SHIFT1 || optimize_size)"
11941   "sar{l}\t%k0"
11942   [(set_attr "type" "ishift")
11943    (set_attr "length" "2")])
11944
11945 (define_insn "*ashrsi3_1"
11946   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,rm")
11947         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
11948                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
11949    (clobber (reg:CC 17))]
11950   "ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
11951   "@
11952    sar{l}\t{%2, %0|%0, %2}
11953    sar{l}\t{%b2, %0|%0, %b2}"
11954   [(set_attr "type" "ishift")
11955    (set_attr "mode" "SI")])
11956
11957 (define_insn "*ashrsi3_1_zext"
11958   [(set (match_operand:DI 0 "register_operand" "=r,r")
11959         (zero_extend:DI (ashiftrt:SI (match_operand:SI 1 "register_operand" "0,0")
11960                                      (match_operand:QI 2 "nonmemory_operand" "I,c"))))
11961    (clobber (reg:CC 17))]
11962   "TARGET_64BIT && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
11963   "@
11964    sar{l}\t{%2, %k0|%k0, %2}
11965    sar{l}\t{%b2, %k0|%k0, %b2}"
11966   [(set_attr "type" "ishift")
11967    (set_attr "mode" "SI")])
11968
11969 ;; This pattern can't accept a variable shift count, since shifts by
11970 ;; zero don't affect the flags.  We assume that shifts by constant
11971 ;; zero are optimized away.
11972 (define_insn "*ashrsi3_one_bit_cmp"
11973   [(set (reg 17)
11974         (compare
11975           (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
11976                        (match_operand:QI 2 "const_int_1_operand" ""))
11977           (const_int 0)))
11978    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
11979         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
11980   "ix86_match_ccmode (insn, CCGOCmode)
11981    && (TARGET_SHIFT1 || optimize_size)
11982    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
11983   "sar{l}\t%0"
11984   [(set_attr "type" "ishift")
11985    (set (attr "length") 
11986      (if_then_else (match_operand:SI 0 "register_operand" "") 
11987         (const_string "2")
11988         (const_string "*")))])
11989
11990 (define_insn "*ashrsi3_one_bit_cmp_zext"
11991   [(set (reg 17)
11992         (compare
11993           (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
11994                        (match_operand:QI 2 "const_int_1_operand" ""))
11995           (const_int 0)))
11996    (set (match_operand:DI 0 "register_operand" "=r")
11997         (zero_extend:DI (ashiftrt:SI (match_dup 1) (match_dup 2))))]
11998   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)
11999    && (TARGET_SHIFT1 || optimize_size)
12000    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
12001   "sar{l}\t%k0"
12002   [(set_attr "type" "ishift")
12003    (set_attr "length" "2")])
12004
12005 ;; This pattern can't accept a variable shift count, since shifts by
12006 ;; zero don't affect the flags.  We assume that shifts by constant
12007 ;; zero are optimized away.
12008 (define_insn "*ashrsi3_cmp"
12009   [(set (reg 17)
12010         (compare
12011           (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
12012                        (match_operand:QI 2 "const_int_1_31_operand" "I"))
12013           (const_int 0)))
12014    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
12015         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
12016   "ix86_match_ccmode (insn, CCGOCmode)
12017    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
12018   "sar{l}\t{%2, %0|%0, %2}"
12019   [(set_attr "type" "ishift")
12020    (set_attr "mode" "SI")])
12021
12022 (define_insn "*ashrsi3_cmp_zext"
12023   [(set (reg 17)
12024         (compare
12025           (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
12026                        (match_operand:QI 2 "const_int_1_31_operand" "I"))
12027           (const_int 0)))
12028    (set (match_operand:DI 0 "register_operand" "=r")
12029         (zero_extend:DI (ashiftrt:SI (match_dup 1) (match_dup 2))))]
12030   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
12031    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
12032   "sar{l}\t{%2, %k0|%k0, %2}"
12033   [(set_attr "type" "ishift")
12034    (set_attr "mode" "SI")])
12035
12036 (define_expand "ashrhi3"
12037   [(set (match_operand:HI 0 "nonimmediate_operand" "")
12038         (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "")
12039                      (match_operand:QI 2 "nonmemory_operand" "")))
12040    (clobber (reg:CC 17))]
12041   "TARGET_HIMODE_MATH"
12042   "ix86_expand_binary_operator (ASHIFTRT, HImode, operands); DONE;")
12043
12044 (define_insn "*ashrhi3_1_one_bit"
12045   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
12046         (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12047                      (match_operand:QI 2 "const_int_1_operand" "")))
12048    (clobber (reg:CC 17))]
12049   "ix86_binary_operator_ok (ASHIFTRT, HImode, operands)
12050    && (TARGET_SHIFT1 || optimize_size)"
12051   "sar{w}\t%0"
12052   [(set_attr "type" "ishift")
12053    (set (attr "length") 
12054      (if_then_else (match_operand 0 "register_operand" "") 
12055         (const_string "2")
12056         (const_string "*")))])
12057
12058 (define_insn "*ashrhi3_1"
12059   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,rm")
12060         (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0,0")
12061                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
12062    (clobber (reg:CC 17))]
12063   "ix86_binary_operator_ok (ASHIFTRT, HImode, operands)"
12064   "@
12065    sar{w}\t{%2, %0|%0, %2}
12066    sar{w}\t{%b2, %0|%0, %b2}"
12067   [(set_attr "type" "ishift")
12068    (set_attr "mode" "HI")])
12069
12070 ;; This pattern can't accept a variable shift count, since shifts by
12071 ;; zero don't affect the flags.  We assume that shifts by constant
12072 ;; zero are optimized away.
12073 (define_insn "*ashrhi3_one_bit_cmp"
12074   [(set (reg 17)
12075         (compare
12076           (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12077                        (match_operand:QI 2 "const_int_1_operand" ""))
12078           (const_int 0)))
12079    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
12080         (ashiftrt:HI (match_dup 1) (match_dup 2)))]
12081   "ix86_match_ccmode (insn, CCGOCmode)
12082    && (TARGET_SHIFT1 || optimize_size)
12083    && ix86_binary_operator_ok (ASHIFTRT, HImode, operands)"
12084   "sar{w}\t%0"
12085   [(set_attr "type" "ishift")
12086    (set (attr "length") 
12087      (if_then_else (match_operand 0 "register_operand" "") 
12088         (const_string "2")
12089         (const_string "*")))])
12090
12091 ;; This pattern can't accept a variable shift count, since shifts by
12092 ;; zero don't affect the flags.  We assume that shifts by constant
12093 ;; zero are optimized away.
12094 (define_insn "*ashrhi3_cmp"
12095   [(set (reg 17)
12096         (compare
12097           (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12098                        (match_operand:QI 2 "const_int_1_31_operand" "I"))
12099           (const_int 0)))
12100    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
12101         (ashiftrt:HI (match_dup 1) (match_dup 2)))]
12102   "ix86_match_ccmode (insn, CCGOCmode)
12103    && ix86_binary_operator_ok (ASHIFTRT, HImode, operands)"
12104   "sar{w}\t{%2, %0|%0, %2}"
12105   [(set_attr "type" "ishift")
12106    (set_attr "mode" "HI")])
12107
12108 (define_expand "ashrqi3"
12109   [(set (match_operand:QI 0 "nonimmediate_operand" "")
12110         (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "")
12111                      (match_operand:QI 2 "nonmemory_operand" "")))
12112    (clobber (reg:CC 17))]
12113   "TARGET_QIMODE_MATH"
12114   "ix86_expand_binary_operator (ASHIFTRT, QImode, operands); DONE;")
12115
12116 (define_insn "*ashrqi3_1_one_bit"
12117   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
12118         (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
12119                      (match_operand:QI 2 "const_int_1_operand" "")))
12120    (clobber (reg:CC 17))]
12121   "ix86_binary_operator_ok (ASHIFTRT, QImode, operands)
12122    && (TARGET_SHIFT1 || optimize_size)"
12123   "sar{b}\t%0"
12124   [(set_attr "type" "ishift")
12125    (set (attr "length") 
12126      (if_then_else (match_operand 0 "register_operand" "") 
12127         (const_string "2")
12128         (const_string "*")))])
12129
12130 (define_insn "*ashrqi3_1_one_bit_slp"
12131   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
12132         (ashiftrt:QI (match_dup 0)
12133                      (match_operand:QI 1 "const_int_1_operand" "")))
12134    (clobber (reg:CC 17))]
12135   "ix86_binary_operator_ok (ASHIFTRT, QImode, operands)
12136    && (! TARGET_PARTIAL_REG_STALL || optimize_size)
12137    && (TARGET_SHIFT1 || optimize_size)"
12138   "sar{b}\t%0"
12139   [(set_attr "type" "ishift1")
12140    (set (attr "length") 
12141      (if_then_else (match_operand 0 "register_operand" "") 
12142         (const_string "2")
12143         (const_string "*")))])
12144
12145 (define_insn "*ashrqi3_1"
12146   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,qm")
12147         (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
12148                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
12149    (clobber (reg:CC 17))]
12150   "ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
12151   "@
12152    sar{b}\t{%2, %0|%0, %2}
12153    sar{b}\t{%b2, %0|%0, %b2}"
12154   [(set_attr "type" "ishift")
12155    (set_attr "mode" "QI")])
12156
12157 (define_insn "*ashrqi3_1_slp"
12158   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,qm"))
12159         (ashiftrt:QI (match_dup 0)
12160                      (match_operand:QI 1 "nonmemory_operand" "I,c")))
12161    (clobber (reg:CC 17))]
12162   "(! TARGET_PARTIAL_REG_STALL || optimize_size)
12163    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
12164   "@
12165    sar{b}\t{%1, %0|%0, %1}
12166    sar{b}\t{%b1, %0|%0, %b1}"
12167   [(set_attr "type" "ishift1")
12168    (set_attr "mode" "QI")])
12169
12170 ;; This pattern can't accept a variable shift count, since shifts by
12171 ;; zero don't affect the flags.  We assume that shifts by constant
12172 ;; zero are optimized away.
12173 (define_insn "*ashrqi3_one_bit_cmp"
12174   [(set (reg 17)
12175         (compare
12176           (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
12177                        (match_operand:QI 2 "const_int_1_operand" "I"))
12178           (const_int 0)))
12179    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
12180         (ashiftrt:QI (match_dup 1) (match_dup 2)))]
12181   "ix86_match_ccmode (insn, CCGOCmode)
12182    && (TARGET_SHIFT1 || optimize_size)
12183    && ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
12184   "sar{b}\t%0"
12185   [(set_attr "type" "ishift")
12186    (set (attr "length") 
12187      (if_then_else (match_operand 0 "register_operand" "") 
12188         (const_string "2")
12189         (const_string "*")))])
12190
12191 ;; This pattern can't accept a variable shift count, since shifts by
12192 ;; zero don't affect the flags.  We assume that shifts by constant
12193 ;; zero are optimized away.
12194 (define_insn "*ashrqi3_cmp"
12195   [(set (reg 17)
12196         (compare
12197           (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
12198                        (match_operand:QI 2 "const_int_1_31_operand" "I"))
12199           (const_int 0)))
12200    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
12201         (ashiftrt:QI (match_dup 1) (match_dup 2)))]
12202   "ix86_match_ccmode (insn, CCGOCmode)
12203    && ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
12204   "sar{b}\t{%2, %0|%0, %2}"
12205   [(set_attr "type" "ishift")
12206    (set_attr "mode" "QI")])
12207 \f
12208 ;; Logical shift instructions
12209
12210 ;; See comment above `ashldi3' about how this works.
12211
12212 (define_expand "lshrdi3"
12213   [(parallel [(set (match_operand:DI 0 "shiftdi_operand" "")
12214                    (lshiftrt:DI (match_operand:DI 1 "shiftdi_operand" "")
12215                                 (match_operand:QI 2 "nonmemory_operand" "")))
12216               (clobber (reg:CC 17))])]
12217   ""
12218 {
12219   if (!TARGET_64BIT && TARGET_CMOVE && ! immediate_operand (operands[2], QImode))
12220     {
12221       emit_insn (gen_lshrdi3_1 (operands[0], operands[1], operands[2]));
12222       DONE;
12223     }
12224   ix86_expand_binary_operator (LSHIFTRT, DImode, operands);
12225   DONE;
12226 })
12227
12228 (define_insn "*lshrdi3_1_one_bit_rex64"
12229   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
12230         (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
12231                      (match_operand:QI 2 "const_int_1_operand" "")))
12232    (clobber (reg:CC 17))]
12233   "TARGET_64BIT && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)
12234    && (TARGET_SHIFT1 || optimize_size)"
12235   "shr{q}\t%0"
12236   [(set_attr "type" "ishift")
12237    (set (attr "length") 
12238      (if_then_else (match_operand:DI 0 "register_operand" "") 
12239         (const_string "2")
12240         (const_string "*")))])
12241
12242 (define_insn "*lshrdi3_1_rex64"
12243   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,rm")
12244         (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
12245                      (match_operand:QI 2 "nonmemory_operand" "J,c")))
12246    (clobber (reg:CC 17))]
12247   "TARGET_64BIT && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12248   "@
12249    shr{q}\t{%2, %0|%0, %2}
12250    shr{q}\t{%b2, %0|%0, %b2}"
12251   [(set_attr "type" "ishift")
12252    (set_attr "mode" "DI")])
12253
12254 ;; This pattern can't accept a variable shift count, since shifts by
12255 ;; zero don't affect the flags.  We assume that shifts by constant
12256 ;; zero are optimized away.
12257 (define_insn "*lshrdi3_cmp_one_bit_rex64"
12258   [(set (reg 17)
12259         (compare
12260           (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
12261                        (match_operand:QI 2 "const_int_1_operand" ""))
12262           (const_int 0)))
12263    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
12264         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
12265   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
12266    && (TARGET_SHIFT1 || optimize_size)
12267    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12268   "shr{q}\t%0"
12269   [(set_attr "type" "ishift")
12270    (set (attr "length") 
12271      (if_then_else (match_operand:DI 0 "register_operand" "") 
12272         (const_string "2")
12273         (const_string "*")))])
12274
12275 ;; This pattern can't accept a variable shift count, since shifts by
12276 ;; zero don't affect the flags.  We assume that shifts by constant
12277 ;; zero are optimized away.
12278 (define_insn "*lshrdi3_cmp_rex64"
12279   [(set (reg 17)
12280         (compare
12281           (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
12282                        (match_operand:QI 2 "const_int_operand" "e"))
12283           (const_int 0)))
12284    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
12285         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
12286   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
12287    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12288   "shr{q}\t{%2, %0|%0, %2}"
12289   [(set_attr "type" "ishift")
12290    (set_attr "mode" "DI")])
12291
12292 (define_insn "lshrdi3_1"
12293   [(set (match_operand:DI 0 "register_operand" "=r")
12294         (lshiftrt:DI (match_operand:DI 1 "register_operand" "0")
12295                      (match_operand:QI 2 "nonmemory_operand" "Jc")))
12296    (clobber (match_scratch:SI 3 "=&r"))
12297    (clobber (reg:CC 17))]
12298   "!TARGET_64BIT && TARGET_CMOVE"
12299   "#"
12300   [(set_attr "type" "multi")])
12301
12302 (define_insn "*lshrdi3_2"
12303   [(set (match_operand:DI 0 "register_operand" "=r")
12304         (lshiftrt:DI (match_operand:DI 1 "register_operand" "0")
12305                      (match_operand:QI 2 "nonmemory_operand" "Jc")))
12306    (clobber (reg:CC 17))]
12307   "!TARGET_64BIT"
12308   "#"
12309   [(set_attr "type" "multi")])
12310
12311 (define_split 
12312   [(set (match_operand:DI 0 "register_operand" "")
12313         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
12314                      (match_operand:QI 2 "nonmemory_operand" "")))
12315    (clobber (match_scratch:SI 3 ""))
12316    (clobber (reg:CC 17))]
12317   "!TARGET_64BIT && TARGET_CMOVE && reload_completed"
12318   [(const_int 0)]
12319   "ix86_split_lshrdi (operands, operands[3]); DONE;")
12320
12321 (define_split 
12322   [(set (match_operand:DI 0 "register_operand" "")
12323         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
12324                      (match_operand:QI 2 "nonmemory_operand" "")))
12325    (clobber (reg:CC 17))]
12326   "!TARGET_64BIT && reload_completed"
12327   [(const_int 0)]
12328   "ix86_split_lshrdi (operands, NULL_RTX); DONE;")
12329
12330 (define_expand "lshrsi3"
12331   [(set (match_operand:SI 0 "nonimmediate_operand" "")
12332         (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "")
12333                      (match_operand:QI 2 "nonmemory_operand" "")))
12334    (clobber (reg:CC 17))]
12335   ""
12336   "ix86_expand_binary_operator (LSHIFTRT, SImode, operands); DONE;")
12337
12338 (define_insn "*lshrsi3_1_one_bit"
12339   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
12340         (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
12341                      (match_operand:QI 2 "const_int_1_operand" "")))
12342    (clobber (reg:CC 17))]
12343   "ix86_binary_operator_ok (LSHIFTRT, HImode, operands)
12344    && (TARGET_SHIFT1 || optimize_size)"
12345   "shr{l}\t%0"
12346   [(set_attr "type" "ishift")
12347    (set (attr "length") 
12348      (if_then_else (match_operand:SI 0 "register_operand" "") 
12349         (const_string "2")
12350         (const_string "*")))])
12351
12352 (define_insn "*lshrsi3_1_one_bit_zext"
12353   [(set (match_operand:DI 0 "register_operand" "=r")
12354         (lshiftrt:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "0"))
12355                      (match_operand:QI 2 "const_int_1_operand" "")))
12356    (clobber (reg:CC 17))]
12357   "TARGET_64BIT && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)
12358    && (TARGET_SHIFT1 || optimize_size)"
12359   "shr{l}\t%k0"
12360   [(set_attr "type" "ishift")
12361    (set_attr "length" "2")])
12362
12363 (define_insn "*lshrsi3_1"
12364   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,rm")
12365         (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
12366                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
12367    (clobber (reg:CC 17))]
12368   "ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12369   "@
12370    shr{l}\t{%2, %0|%0, %2}
12371    shr{l}\t{%b2, %0|%0, %b2}"
12372   [(set_attr "type" "ishift")
12373    (set_attr "mode" "SI")])
12374
12375 (define_insn "*lshrsi3_1_zext"
12376   [(set (match_operand:DI 0 "register_operand" "=r,r")
12377         (zero_extend:DI
12378           (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
12379                        (match_operand:QI 2 "nonmemory_operand" "I,c"))))
12380    (clobber (reg:CC 17))]
12381   "TARGET_64BIT && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12382   "@
12383    shr{l}\t{%2, %k0|%k0, %2}
12384    shr{l}\t{%b2, %k0|%k0, %b2}"
12385   [(set_attr "type" "ishift")
12386    (set_attr "mode" "SI")])
12387
12388 ;; This pattern can't accept a variable shift count, since shifts by
12389 ;; zero don't affect the flags.  We assume that shifts by constant
12390 ;; zero are optimized away.
12391 (define_insn "*lshrsi3_one_bit_cmp"
12392   [(set (reg 17)
12393         (compare
12394           (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
12395                        (match_operand:QI 2 "const_int_1_operand" ""))
12396           (const_int 0)))
12397    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
12398         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
12399   "ix86_match_ccmode (insn, CCGOCmode)
12400    && (TARGET_SHIFT1 || optimize_size)
12401    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12402   "shr{l}\t%0"
12403   [(set_attr "type" "ishift")
12404    (set (attr "length") 
12405      (if_then_else (match_operand:SI 0 "register_operand" "") 
12406         (const_string "2")
12407         (const_string "*")))])
12408
12409 (define_insn "*lshrsi3_cmp_one_bit_zext"
12410   [(set (reg 17)
12411         (compare
12412           (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
12413                        (match_operand:QI 2 "const_int_1_operand" ""))
12414           (const_int 0)))
12415    (set (match_operand:DI 0 "register_operand" "=r")
12416         (lshiftrt:DI (zero_extend:DI (match_dup 1)) (match_dup 2)))]
12417   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
12418    && (TARGET_SHIFT1 || optimize_size)
12419    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12420   "shr{l}\t%k0"
12421   [(set_attr "type" "ishift")
12422    (set_attr "length" "2")])
12423
12424 ;; This pattern can't accept a variable shift count, since shifts by
12425 ;; zero don't affect the flags.  We assume that shifts by constant
12426 ;; zero are optimized away.
12427 (define_insn "*lshrsi3_cmp"
12428   [(set (reg 17)
12429         (compare
12430           (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
12431                        (match_operand:QI 2 "const_int_1_31_operand" "I"))
12432           (const_int 0)))
12433    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
12434         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
12435   "ix86_match_ccmode (insn, CCGOCmode)
12436    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12437   "shr{l}\t{%2, %0|%0, %2}"
12438   [(set_attr "type" "ishift")
12439    (set_attr "mode" "SI")])
12440
12441 (define_insn "*lshrsi3_cmp_zext"
12442   [(set (reg 17)
12443         (compare
12444           (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
12445                        (match_operand:QI 2 "const_int_1_31_operand" "I"))
12446           (const_int 0)))
12447    (set (match_operand:DI 0 "register_operand" "=r")
12448         (lshiftrt:DI (zero_extend:DI (match_dup 1)) (match_dup 2)))]
12449   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
12450    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12451   "shr{l}\t{%2, %k0|%k0, %2}"
12452   [(set_attr "type" "ishift")
12453    (set_attr "mode" "SI")])
12454
12455 (define_expand "lshrhi3"
12456   [(set (match_operand:HI 0 "nonimmediate_operand" "")
12457         (lshiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "")
12458                      (match_operand:QI 2 "nonmemory_operand" "")))
12459    (clobber (reg:CC 17))]
12460   "TARGET_HIMODE_MATH"
12461   "ix86_expand_binary_operator (LSHIFTRT, HImode, operands); DONE;")
12462
12463 (define_insn "*lshrhi3_1_one_bit"
12464   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
12465         (lshiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12466                      (match_operand:QI 2 "const_int_1_operand" "")))
12467    (clobber (reg:CC 17))]
12468   "ix86_binary_operator_ok (LSHIFTRT, HImode, operands)
12469    && (TARGET_SHIFT1 || optimize_size)"
12470   "shr{w}\t%0"
12471   [(set_attr "type" "ishift")
12472    (set (attr "length") 
12473      (if_then_else (match_operand 0 "register_operand" "") 
12474         (const_string "2")
12475         (const_string "*")))])
12476
12477 (define_insn "*lshrhi3_1"
12478   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,rm")
12479         (lshiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0,0")
12480                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
12481    (clobber (reg:CC 17))]
12482   "ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12483   "@
12484    shr{w}\t{%2, %0|%0, %2}
12485    shr{w}\t{%b2, %0|%0, %b2}"
12486   [(set_attr "type" "ishift")
12487    (set_attr "mode" "HI")])
12488
12489 ;; This pattern can't accept a variable shift count, since shifts by
12490 ;; zero don't affect the flags.  We assume that shifts by constant
12491 ;; zero are optimized away.
12492 (define_insn "*lshrhi3_one_bit_cmp"
12493   [(set (reg 17)
12494         (compare
12495           (lshiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12496                        (match_operand:QI 2 "const_int_1_operand" ""))
12497           (const_int 0)))
12498    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
12499         (lshiftrt:HI (match_dup 1) (match_dup 2)))]
12500   "ix86_match_ccmode (insn, CCGOCmode)
12501    && (TARGET_SHIFT1 || optimize_size)
12502    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12503   "shr{w}\t%0"
12504   [(set_attr "type" "ishift")
12505    (set (attr "length") 
12506      (if_then_else (match_operand:SI 0 "register_operand" "") 
12507         (const_string "2")
12508         (const_string "*")))])
12509
12510 ;; This pattern can't accept a variable shift count, since shifts by
12511 ;; zero don't affect the flags.  We assume that shifts by constant
12512 ;; zero are optimized away.
12513 (define_insn "*lshrhi3_cmp"
12514   [(set (reg 17)
12515         (compare
12516           (lshiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12517                        (match_operand:QI 2 "const_int_1_31_operand" "I"))
12518           (const_int 0)))
12519    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
12520         (lshiftrt:HI (match_dup 1) (match_dup 2)))]
12521   "ix86_match_ccmode (insn, CCGOCmode)
12522    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12523   "shr{w}\t{%2, %0|%0, %2}"
12524   [(set_attr "type" "ishift")
12525    (set_attr "mode" "HI")])
12526
12527 (define_expand "lshrqi3"
12528   [(set (match_operand:QI 0 "nonimmediate_operand" "")
12529         (lshiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "")
12530                      (match_operand:QI 2 "nonmemory_operand" "")))
12531    (clobber (reg:CC 17))]
12532   "TARGET_QIMODE_MATH"
12533   "ix86_expand_binary_operator (LSHIFTRT, QImode, operands); DONE;")
12534
12535 (define_insn "*lshrqi3_1_one_bit"
12536   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
12537         (lshiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
12538                      (match_operand:QI 2 "const_int_1_operand" "")))
12539    (clobber (reg:CC 17))]
12540   "ix86_binary_operator_ok (LSHIFTRT, QImode, operands)
12541    && (TARGET_SHIFT1 || optimize_size)"
12542   "shr{b}\t%0"
12543   [(set_attr "type" "ishift")
12544    (set (attr "length") 
12545      (if_then_else (match_operand 0 "register_operand" "") 
12546         (const_string "2")
12547         (const_string "*")))])
12548
12549 (define_insn "*lshrqi3_1_one_bit_slp"
12550   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
12551         (lshiftrt:QI (match_dup 0)
12552                      (match_operand:QI 1 "const_int_1_operand" "")))
12553    (clobber (reg:CC 17))]
12554   "(! TARGET_PARTIAL_REG_STALL || optimize_size)
12555    && (TARGET_SHIFT1 || optimize_size)"
12556   "shr{b}\t%0"
12557   [(set_attr "type" "ishift1")
12558    (set (attr "length") 
12559      (if_then_else (match_operand 0 "register_operand" "") 
12560         (const_string "2")
12561         (const_string "*")))])
12562
12563 (define_insn "*lshrqi3_1"
12564   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,qm")
12565         (lshiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
12566                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
12567    (clobber (reg:CC 17))]
12568   "ix86_binary_operator_ok (LSHIFTRT, QImode, operands)"
12569   "@
12570    shr{b}\t{%2, %0|%0, %2}
12571    shr{b}\t{%b2, %0|%0, %b2}"
12572   [(set_attr "type" "ishift")
12573    (set_attr "mode" "QI")])
12574
12575 (define_insn "*lshrqi3_1_slp"
12576   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,qm"))
12577         (lshiftrt:QI (match_dup 0)
12578                      (match_operand:QI 1 "nonmemory_operand" "I,c")))
12579    (clobber (reg:CC 17))]
12580   "(! TARGET_PARTIAL_REG_STALL || optimize_size)
12581    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
12582   "@
12583    shr{b}\t{%1, %0|%0, %1}
12584    shr{b}\t{%b1, %0|%0, %b1}"
12585   [(set_attr "type" "ishift1")
12586    (set_attr "mode" "QI")])
12587
12588 ;; This pattern can't accept a variable shift count, since shifts by
12589 ;; zero don't affect the flags.  We assume that shifts by constant
12590 ;; zero are optimized away.
12591 (define_insn "*lshrqi2_one_bit_cmp"
12592   [(set (reg 17)
12593         (compare
12594           (lshiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
12595                        (match_operand:QI 2 "const_int_1_operand" ""))
12596           (const_int 0)))
12597    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
12598         (lshiftrt:QI (match_dup 1) (match_dup 2)))]
12599   "ix86_match_ccmode (insn, CCGOCmode)
12600    && (TARGET_SHIFT1 || optimize_size)
12601    && ix86_binary_operator_ok (LSHIFTRT, QImode, operands)"
12602   "shr{b}\t%0"
12603   [(set_attr "type" "ishift")
12604    (set (attr "length") 
12605      (if_then_else (match_operand:SI 0 "register_operand" "") 
12606         (const_string "2")
12607         (const_string "*")))])
12608
12609 ;; This pattern can't accept a variable shift count, since shifts by
12610 ;; zero don't affect the flags.  We assume that shifts by constant
12611 ;; zero are optimized away.
12612 (define_insn "*lshrqi2_cmp"
12613   [(set (reg 17)
12614         (compare
12615           (lshiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
12616                        (match_operand:QI 2 "const_int_1_31_operand" "I"))
12617           (const_int 0)))
12618    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
12619         (lshiftrt:QI (match_dup 1) (match_dup 2)))]
12620   "ix86_match_ccmode (insn, CCGOCmode)
12621    && ix86_binary_operator_ok (LSHIFTRT, QImode, operands)"
12622   "shr{b}\t{%2, %0|%0, %2}"
12623   [(set_attr "type" "ishift")
12624    (set_attr "mode" "QI")])
12625 \f
12626 ;; Rotate instructions
12627
12628 (define_expand "rotldi3"
12629   [(set (match_operand:DI 0 "nonimmediate_operand" "")
12630         (rotate:DI (match_operand:DI 1 "nonimmediate_operand" "")
12631                    (match_operand:QI 2 "nonmemory_operand" "")))
12632    (clobber (reg:CC 17))]
12633   "TARGET_64BIT"
12634   "ix86_expand_binary_operator (ROTATE, DImode, operands); DONE;")
12635
12636 (define_insn "*rotlsi3_1_one_bit_rex64"
12637   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
12638         (rotate:DI (match_operand:DI 1 "nonimmediate_operand" "0")
12639                    (match_operand:QI 2 "const_int_1_operand" "")))
12640    (clobber (reg:CC 17))]
12641   "TARGET_64BIT && ix86_binary_operator_ok (ROTATE, DImode, operands)
12642    && (TARGET_SHIFT1 || optimize_size)"
12643   "rol{q}\t%0"
12644   [(set_attr "type" "rotate")
12645    (set (attr "length") 
12646      (if_then_else (match_operand:DI 0 "register_operand" "") 
12647         (const_string "2")
12648         (const_string "*")))])
12649
12650 (define_insn "*rotldi3_1_rex64"
12651   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,rm")
12652         (rotate:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
12653                    (match_operand:QI 2 "nonmemory_operand" "e,c")))
12654    (clobber (reg:CC 17))]
12655   "TARGET_64BIT && ix86_binary_operator_ok (ROTATE, DImode, operands)"
12656   "@
12657    rol{q}\t{%2, %0|%0, %2}
12658    rol{q}\t{%b2, %0|%0, %b2}"
12659   [(set_attr "type" "rotate")
12660    (set_attr "mode" "DI")])
12661
12662 (define_expand "rotlsi3"
12663   [(set (match_operand:SI 0 "nonimmediate_operand" "")
12664         (rotate:SI (match_operand:SI 1 "nonimmediate_operand" "")
12665                    (match_operand:QI 2 "nonmemory_operand" "")))
12666    (clobber (reg:CC 17))]
12667   ""
12668   "ix86_expand_binary_operator (ROTATE, SImode, operands); DONE;")
12669
12670 (define_insn "*rotlsi3_1_one_bit"
12671   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
12672         (rotate:SI (match_operand:SI 1 "nonimmediate_operand" "0")
12673                    (match_operand:QI 2 "const_int_1_operand" "")))
12674    (clobber (reg:CC 17))]
12675   "ix86_binary_operator_ok (ROTATE, SImode, operands)
12676    && (TARGET_SHIFT1 || optimize_size)"
12677   "rol{l}\t%0"
12678   [(set_attr "type" "rotate")
12679    (set (attr "length") 
12680      (if_then_else (match_operand:SI 0 "register_operand" "") 
12681         (const_string "2")
12682         (const_string "*")))])
12683
12684 (define_insn "*rotlsi3_1_one_bit_zext"
12685   [(set (match_operand:DI 0 "register_operand" "=r")
12686         (zero_extend:DI
12687           (rotate:SI (match_operand:SI 1 "register_operand" "0")
12688                      (match_operand:QI 2 "const_int_1_operand" ""))))
12689    (clobber (reg:CC 17))]
12690   "TARGET_64BIT && ix86_binary_operator_ok (ROTATE, SImode, operands)
12691    && (TARGET_SHIFT1 || optimize_size)"
12692   "rol{l}\t%k0"
12693   [(set_attr "type" "rotate")
12694    (set_attr "length" "2")])
12695
12696 (define_insn "*rotlsi3_1"
12697   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,rm")
12698         (rotate:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
12699                    (match_operand:QI 2 "nonmemory_operand" "I,c")))
12700    (clobber (reg:CC 17))]
12701   "ix86_binary_operator_ok (ROTATE, SImode, operands)"
12702   "@
12703    rol{l}\t{%2, %0|%0, %2}
12704    rol{l}\t{%b2, %0|%0, %b2}"
12705   [(set_attr "type" "rotate")
12706    (set_attr "mode" "SI")])
12707
12708 (define_insn "*rotlsi3_1_zext"
12709   [(set (match_operand:DI 0 "register_operand" "=r,r")
12710         (zero_extend:DI
12711           (rotate:SI (match_operand:SI 1 "register_operand" "0,0")
12712                      (match_operand:QI 2 "nonmemory_operand" "I,c"))))
12713    (clobber (reg:CC 17))]
12714   "TARGET_64BIT && ix86_binary_operator_ok (ROTATE, SImode, operands)"
12715   "@
12716    rol{l}\t{%2, %k0|%k0, %2}
12717    rol{l}\t{%b2, %k0|%k0, %b2}"
12718   [(set_attr "type" "rotate")
12719    (set_attr "mode" "SI")])
12720
12721 (define_expand "rotlhi3"
12722   [(set (match_operand:HI 0 "nonimmediate_operand" "")
12723         (rotate:HI (match_operand:HI 1 "nonimmediate_operand" "")
12724                    (match_operand:QI 2 "nonmemory_operand" "")))
12725    (clobber (reg:CC 17))]
12726   "TARGET_HIMODE_MATH"
12727   "ix86_expand_binary_operator (ROTATE, HImode, operands); DONE;")
12728
12729 (define_insn "*rotlhi3_1_one_bit"
12730   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
12731         (rotate:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12732                    (match_operand:QI 2 "const_int_1_operand" "")))
12733    (clobber (reg:CC 17))]
12734   "ix86_binary_operator_ok (ROTATE, HImode, operands)
12735    && (TARGET_SHIFT1 || optimize_size)"
12736   "rol{w}\t%0"
12737   [(set_attr "type" "rotate")
12738    (set (attr "length") 
12739      (if_then_else (match_operand 0 "register_operand" "") 
12740         (const_string "2")
12741         (const_string "*")))])
12742
12743 (define_insn "*rotlhi3_1"
12744   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,rm")
12745         (rotate:HI (match_operand:HI 1 "nonimmediate_operand" "0,0")
12746                    (match_operand:QI 2 "nonmemory_operand" "I,c")))
12747    (clobber (reg:CC 17))]
12748   "ix86_binary_operator_ok (ROTATE, HImode, operands)"
12749   "@
12750    rol{w}\t{%2, %0|%0, %2}
12751    rol{w}\t{%b2, %0|%0, %b2}"
12752   [(set_attr "type" "rotate")
12753    (set_attr "mode" "HI")])
12754
12755 (define_expand "rotlqi3"
12756   [(set (match_operand:QI 0 "nonimmediate_operand" "")
12757         (rotate:QI (match_operand:QI 1 "nonimmediate_operand" "")
12758                    (match_operand:QI 2 "nonmemory_operand" "")))
12759    (clobber (reg:CC 17))]
12760   "TARGET_QIMODE_MATH"
12761   "ix86_expand_binary_operator (ROTATE, QImode, operands); DONE;")
12762
12763 (define_insn "*rotlqi3_1_one_bit_slp"
12764   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
12765         (rotate:QI (match_dup 0)
12766                    (match_operand:QI 1 "const_int_1_operand" "")))
12767    (clobber (reg:CC 17))]
12768   "(! TARGET_PARTIAL_REG_STALL || optimize_size)
12769    && (TARGET_SHIFT1 || optimize_size)"
12770   "rol{b}\t%0"
12771   [(set_attr "type" "rotate1")
12772    (set (attr "length") 
12773      (if_then_else (match_operand 0 "register_operand" "") 
12774         (const_string "2")
12775         (const_string "*")))])
12776
12777 (define_insn "*rotlqi3_1_one_bit"
12778   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
12779         (rotate:QI (match_operand:QI 1 "nonimmediate_operand" "0")
12780                    (match_operand:QI 2 "const_int_1_operand" "")))
12781    (clobber (reg:CC 17))]
12782   "ix86_binary_operator_ok (ROTATE, QImode, operands)
12783    && (TARGET_SHIFT1 || optimize_size)"
12784   "rol{b}\t%0"
12785   [(set_attr "type" "rotate")
12786    (set (attr "length") 
12787      (if_then_else (match_operand 0 "register_operand" "") 
12788         (const_string "2")
12789         (const_string "*")))])
12790
12791 (define_insn "*rotlqi3_1_slp"
12792   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,qm"))
12793         (rotate:QI (match_dup 0)
12794                    (match_operand:QI 1 "nonmemory_operand" "I,c")))
12795    (clobber (reg:CC 17))]
12796   "(! TARGET_PARTIAL_REG_STALL || optimize_size)
12797    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
12798   "@
12799    rol{b}\t{%1, %0|%0, %1}
12800    rol{b}\t{%b1, %0|%0, %b1}"
12801   [(set_attr "type" "rotate1")
12802    (set_attr "mode" "QI")])
12803
12804 (define_insn "*rotlqi3_1"
12805   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,qm")
12806         (rotate:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
12807                    (match_operand:QI 2 "nonmemory_operand" "I,c")))
12808    (clobber (reg:CC 17))]
12809   "ix86_binary_operator_ok (ROTATE, QImode, operands)"
12810   "@
12811    rol{b}\t{%2, %0|%0, %2}
12812    rol{b}\t{%b2, %0|%0, %b2}"
12813   [(set_attr "type" "rotate")
12814    (set_attr "mode" "QI")])
12815
12816 (define_expand "rotrdi3"
12817   [(set (match_operand:DI 0 "nonimmediate_operand" "")
12818         (rotatert:DI (match_operand:DI 1 "nonimmediate_operand" "")
12819                      (match_operand:QI 2 "nonmemory_operand" "")))
12820    (clobber (reg:CC 17))]
12821   "TARGET_64BIT"
12822   "ix86_expand_binary_operator (ROTATERT, DImode, operands); DONE;")
12823
12824 (define_insn "*rotrdi3_1_one_bit_rex64"
12825   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
12826         (rotatert:DI (match_operand:DI 1 "nonimmediate_operand" "0")
12827                      (match_operand:QI 2 "const_int_1_operand" "")))
12828    (clobber (reg:CC 17))]
12829   "TARGET_64BIT && ix86_binary_operator_ok (ROTATERT, DImode, operands)
12830    && (TARGET_SHIFT1 || optimize_size)"
12831   "ror{q}\t%0"
12832   [(set_attr "type" "rotate")
12833    (set (attr "length") 
12834      (if_then_else (match_operand:DI 0 "register_operand" "") 
12835         (const_string "2")
12836         (const_string "*")))])
12837
12838 (define_insn "*rotrdi3_1_rex64"
12839   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,rm")
12840         (rotatert:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
12841                      (match_operand:QI 2 "nonmemory_operand" "J,c")))
12842    (clobber (reg:CC 17))]
12843   "TARGET_64BIT && ix86_binary_operator_ok (ROTATERT, DImode, operands)"
12844   "@
12845    ror{q}\t{%2, %0|%0, %2}
12846    ror{q}\t{%b2, %0|%0, %b2}"
12847   [(set_attr "type" "rotate")
12848    (set_attr "mode" "DI")])
12849
12850 (define_expand "rotrsi3"
12851   [(set (match_operand:SI 0 "nonimmediate_operand" "")
12852         (rotatert:SI (match_operand:SI 1 "nonimmediate_operand" "")
12853                      (match_operand:QI 2 "nonmemory_operand" "")))
12854    (clobber (reg:CC 17))]
12855   ""
12856   "ix86_expand_binary_operator (ROTATERT, SImode, operands); DONE;")
12857
12858 (define_insn "*rotrsi3_1_one_bit"
12859   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
12860         (rotatert:SI (match_operand:SI 1 "nonimmediate_operand" "0")
12861                      (match_operand:QI 2 "const_int_1_operand" "")))
12862    (clobber (reg:CC 17))]
12863   "ix86_binary_operator_ok (ROTATERT, SImode, operands)
12864    && (TARGET_SHIFT1 || optimize_size)"
12865   "ror{l}\t%0"
12866   [(set_attr "type" "rotate")
12867    (set (attr "length") 
12868      (if_then_else (match_operand:SI 0 "register_operand" "") 
12869         (const_string "2")
12870         (const_string "*")))])
12871
12872 (define_insn "*rotrsi3_1_one_bit_zext"
12873   [(set (match_operand:DI 0 "register_operand" "=r")
12874         (zero_extend:DI
12875           (rotatert:SI (match_operand:SI 1 "register_operand" "0")
12876                        (match_operand:QI 2 "const_int_1_operand" ""))))
12877    (clobber (reg:CC 17))]
12878   "TARGET_64BIT && ix86_binary_operator_ok (ROTATERT, SImode, operands)
12879    && (TARGET_SHIFT1 || optimize_size)"
12880   "ror{l}\t%k0"
12881   [(set_attr "type" "rotate")
12882    (set (attr "length") 
12883      (if_then_else (match_operand:SI 0 "register_operand" "") 
12884         (const_string "2")
12885         (const_string "*")))])
12886
12887 (define_insn "*rotrsi3_1"
12888   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,rm")
12889         (rotatert:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
12890                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
12891    (clobber (reg:CC 17))]
12892   "ix86_binary_operator_ok (ROTATERT, SImode, operands)"
12893   "@
12894    ror{l}\t{%2, %0|%0, %2}
12895    ror{l}\t{%b2, %0|%0, %b2}"
12896   [(set_attr "type" "rotate")
12897    (set_attr "mode" "SI")])
12898
12899 (define_insn "*rotrsi3_1_zext"
12900   [(set (match_operand:DI 0 "register_operand" "=r,r")
12901         (zero_extend:DI
12902           (rotatert:SI (match_operand:SI 1 "register_operand" "0,0")
12903                        (match_operand:QI 2 "nonmemory_operand" "I,c"))))
12904    (clobber (reg:CC 17))]
12905   "TARGET_64BIT && ix86_binary_operator_ok (ROTATERT, SImode, operands)"
12906   "@
12907    ror{l}\t{%2, %k0|%k0, %2}
12908    ror{l}\t{%b2, %k0|%k0, %b2}"
12909   [(set_attr "type" "rotate")
12910    (set_attr "mode" "SI")])
12911
12912 (define_expand "rotrhi3"
12913   [(set (match_operand:HI 0 "nonimmediate_operand" "")
12914         (rotatert:HI (match_operand:HI 1 "nonimmediate_operand" "")
12915                      (match_operand:QI 2 "nonmemory_operand" "")))
12916    (clobber (reg:CC 17))]
12917   "TARGET_HIMODE_MATH"
12918   "ix86_expand_binary_operator (ROTATERT, HImode, operands); DONE;")
12919
12920 (define_insn "*rotrhi3_one_bit"
12921   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
12922         (rotatert:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12923                      (match_operand:QI 2 "const_int_1_operand" "")))
12924    (clobber (reg:CC 17))]
12925   "ix86_binary_operator_ok (ROTATERT, HImode, operands)
12926    && (TARGET_SHIFT1 || optimize_size)"
12927   "ror{w}\t%0"
12928   [(set_attr "type" "rotate")
12929    (set (attr "length") 
12930      (if_then_else (match_operand 0 "register_operand" "") 
12931         (const_string "2")
12932         (const_string "*")))])
12933
12934 (define_insn "*rotrhi3"
12935   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,rm")
12936         (rotatert:HI (match_operand:HI 1 "nonimmediate_operand" "0,0")
12937                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
12938    (clobber (reg:CC 17))]
12939   "ix86_binary_operator_ok (ROTATERT, HImode, operands)"
12940   "@
12941    ror{w}\t{%2, %0|%0, %2}
12942    ror{w}\t{%b2, %0|%0, %b2}"
12943   [(set_attr "type" "rotate")
12944    (set_attr "mode" "HI")])
12945
12946 (define_expand "rotrqi3"
12947   [(set (match_operand:QI 0 "nonimmediate_operand" "")
12948         (rotatert:QI (match_operand:QI 1 "nonimmediate_operand" "")
12949                      (match_operand:QI 2 "nonmemory_operand" "")))
12950    (clobber (reg:CC 17))]
12951   "TARGET_QIMODE_MATH"
12952   "ix86_expand_binary_operator (ROTATERT, QImode, operands); DONE;")
12953
12954 (define_insn "*rotrqi3_1_one_bit"
12955   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
12956         (rotatert:QI (match_operand:QI 1 "nonimmediate_operand" "0")
12957                      (match_operand:QI 2 "const_int_1_operand" "")))
12958    (clobber (reg:CC 17))]
12959   "ix86_binary_operator_ok (ROTATERT, QImode, operands)
12960    && (TARGET_SHIFT1 || optimize_size)"
12961   "ror{b}\t%0"
12962   [(set_attr "type" "rotate")
12963    (set (attr "length") 
12964      (if_then_else (match_operand 0 "register_operand" "") 
12965         (const_string "2")
12966         (const_string "*")))])
12967
12968 (define_insn "*rotrqi3_1_one_bit_slp"
12969   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
12970         (rotatert:QI (match_dup 0)
12971                      (match_operand:QI 1 "const_int_1_operand" "")))
12972    (clobber (reg:CC 17))]
12973   "(! TARGET_PARTIAL_REG_STALL || optimize_size)
12974    && (TARGET_SHIFT1 || optimize_size)"
12975   "ror{b}\t%0"
12976   [(set_attr "type" "rotate1")
12977    (set (attr "length") 
12978      (if_then_else (match_operand 0 "register_operand" "") 
12979         (const_string "2")
12980         (const_string "*")))])
12981
12982 (define_insn "*rotrqi3_1"
12983   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,qm")
12984         (rotatert:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
12985                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
12986    (clobber (reg:CC 17))]
12987   "ix86_binary_operator_ok (ROTATERT, QImode, operands)"
12988   "@
12989    ror{b}\t{%2, %0|%0, %2}
12990    ror{b}\t{%b2, %0|%0, %b2}"
12991   [(set_attr "type" "rotate")
12992    (set_attr "mode" "QI")])
12993
12994 (define_insn "*rotrqi3_1_slp"
12995   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,qm"))
12996         (rotatert:QI (match_dup 0)
12997                      (match_operand:QI 1 "nonmemory_operand" "I,c")))
12998    (clobber (reg:CC 17))]
12999   "(! TARGET_PARTIAL_REG_STALL || optimize_size)
13000    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
13001   "@
13002    ror{b}\t{%1, %0|%0, %1}
13003    ror{b}\t{%b1, %0|%0, %b1}"
13004   [(set_attr "type" "rotate1")
13005    (set_attr "mode" "QI")])
13006 \f
13007 ;; Bit set / bit test instructions
13008
13009 (define_expand "extv"
13010   [(set (match_operand:SI 0 "register_operand" "")
13011         (sign_extract:SI (match_operand:SI 1 "register_operand" "")
13012                          (match_operand:SI 2 "immediate_operand" "")
13013                          (match_operand:SI 3 "immediate_operand" "")))]
13014   ""
13015 {
13016   /* Handle extractions from %ah et al.  */
13017   if (INTVAL (operands[2]) != 8 || INTVAL (operands[3]) != 8)
13018     FAIL;
13019
13020   /* From mips.md: extract_bit_field doesn't verify that our source
13021      matches the predicate, so check it again here.  */
13022   if (! register_operand (operands[1], VOIDmode))
13023     FAIL;
13024 })
13025
13026 (define_expand "extzv"
13027   [(set (match_operand:SI 0 "register_operand" "")
13028         (zero_extract:SI (match_operand 1 "ext_register_operand" "")
13029                          (match_operand:SI 2 "immediate_operand" "")
13030                          (match_operand:SI 3 "immediate_operand" "")))]
13031   ""
13032 {
13033   /* Handle extractions from %ah et al.  */
13034   if (INTVAL (operands[2]) != 8 || INTVAL (operands[3]) != 8)
13035     FAIL;
13036
13037   /* From mips.md: extract_bit_field doesn't verify that our source
13038      matches the predicate, so check it again here.  */
13039   if (! register_operand (operands[1], VOIDmode))
13040     FAIL;
13041 })
13042
13043 (define_expand "insv"
13044   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "")
13045                          (match_operand:SI 1 "immediate_operand" "")
13046                          (match_operand:SI 2 "immediate_operand" ""))
13047         (match_operand:SI 3 "register_operand" ""))]
13048   ""
13049 {
13050   /* Handle extractions from %ah et al.  */
13051   if (INTVAL (operands[1]) != 8 || INTVAL (operands[2]) != 8)
13052     FAIL;
13053
13054   /* From mips.md: insert_bit_field doesn't verify that our source
13055      matches the predicate, so check it again here.  */
13056   if (! register_operand (operands[0], VOIDmode))
13057     FAIL;
13058 })
13059
13060 ;; %%% bts, btr, btc, bt.
13061 \f
13062 ;; Store-flag instructions.
13063
13064 ;; For all sCOND expanders, also expand the compare or test insn that
13065 ;; generates cc0.  Generate an equality comparison if `seq' or `sne'.
13066
13067 ;; %%% Do the expansion to SImode.  If PII, do things the xor+setcc way
13068 ;; to avoid partial register stalls.  Otherwise do things the setcc+movzx
13069 ;; way, which can later delete the movzx if only QImode is needed.
13070
13071 (define_expand "seq"
13072   [(set (match_operand:QI 0 "register_operand" "")
13073         (eq:QI (reg:CC 17) (const_int 0)))]
13074   ""
13075   "if (ix86_expand_setcc (EQ, operands[0])) DONE; else FAIL;")
13076
13077 (define_expand "sne"
13078   [(set (match_operand:QI 0 "register_operand" "")
13079         (ne:QI (reg:CC 17) (const_int 0)))]
13080   ""
13081   "if (ix86_expand_setcc (NE, operands[0])) DONE; else FAIL;")
13082
13083 (define_expand "sgt"
13084   [(set (match_operand:QI 0 "register_operand" "")
13085         (gt:QI (reg:CC 17) (const_int 0)))]
13086   ""
13087   "if (ix86_expand_setcc (GT, operands[0])) DONE; else FAIL;")
13088
13089 (define_expand "sgtu"
13090   [(set (match_operand:QI 0 "register_operand" "")
13091         (gtu:QI (reg:CC 17) (const_int 0)))]
13092   ""
13093   "if (ix86_expand_setcc (GTU, operands[0])) DONE; else FAIL;")
13094
13095 (define_expand "slt"
13096   [(set (match_operand:QI 0 "register_operand" "")
13097         (lt:QI (reg:CC 17) (const_int 0)))]
13098   ""
13099   "if (ix86_expand_setcc (LT, operands[0])) DONE; else FAIL;")
13100
13101 (define_expand "sltu"
13102   [(set (match_operand:QI 0 "register_operand" "")
13103         (ltu:QI (reg:CC 17) (const_int 0)))]
13104   ""
13105   "if (ix86_expand_setcc (LTU, operands[0])) DONE; else FAIL;")
13106
13107 (define_expand "sge"
13108   [(set (match_operand:QI 0 "register_operand" "")
13109         (ge:QI (reg:CC 17) (const_int 0)))]
13110   ""
13111   "if (ix86_expand_setcc (GE, operands[0])) DONE; else FAIL;")
13112
13113 (define_expand "sgeu"
13114   [(set (match_operand:QI 0 "register_operand" "")
13115         (geu:QI (reg:CC 17) (const_int 0)))]
13116   ""
13117   "if (ix86_expand_setcc (GEU, operands[0])) DONE; else FAIL;")
13118
13119 (define_expand "sle"
13120   [(set (match_operand:QI 0 "register_operand" "")
13121         (le:QI (reg:CC 17) (const_int 0)))]
13122   ""
13123   "if (ix86_expand_setcc (LE, operands[0])) DONE; else FAIL;")
13124
13125 (define_expand "sleu"
13126   [(set (match_operand:QI 0 "register_operand" "")
13127         (leu:QI (reg:CC 17) (const_int 0)))]
13128   ""
13129   "if (ix86_expand_setcc (LEU, operands[0])) DONE; else FAIL;")
13130
13131 (define_expand "sunordered"
13132   [(set (match_operand:QI 0 "register_operand" "")
13133         (unordered:QI (reg:CC 17) (const_int 0)))]
13134   "TARGET_80387 || TARGET_SSE"
13135   "if (ix86_expand_setcc (UNORDERED, operands[0])) DONE; else FAIL;")
13136
13137 (define_expand "sordered"
13138   [(set (match_operand:QI 0 "register_operand" "")
13139         (ordered:QI (reg:CC 17) (const_int 0)))]
13140   "TARGET_80387"
13141   "if (ix86_expand_setcc (ORDERED, operands[0])) DONE; else FAIL;")
13142
13143 (define_expand "suneq"
13144   [(set (match_operand:QI 0 "register_operand" "")
13145         (uneq:QI (reg:CC 17) (const_int 0)))]
13146   "TARGET_80387 || TARGET_SSE"
13147   "if (ix86_expand_setcc (UNEQ, operands[0])) DONE; else FAIL;")
13148
13149 (define_expand "sunge"
13150   [(set (match_operand:QI 0 "register_operand" "")
13151         (unge:QI (reg:CC 17) (const_int 0)))]
13152   "TARGET_80387 || TARGET_SSE"
13153   "if (ix86_expand_setcc (UNGE, operands[0])) DONE; else FAIL;")
13154
13155 (define_expand "sungt"
13156   [(set (match_operand:QI 0 "register_operand" "")
13157         (ungt:QI (reg:CC 17) (const_int 0)))]
13158   "TARGET_80387 || TARGET_SSE"
13159   "if (ix86_expand_setcc (UNGT, operands[0])) DONE; else FAIL;")
13160
13161 (define_expand "sunle"
13162   [(set (match_operand:QI 0 "register_operand" "")
13163         (unle:QI (reg:CC 17) (const_int 0)))]
13164   "TARGET_80387 || TARGET_SSE"
13165   "if (ix86_expand_setcc (UNLE, operands[0])) DONE; else FAIL;")
13166
13167 (define_expand "sunlt"
13168   [(set (match_operand:QI 0 "register_operand" "")
13169         (unlt:QI (reg:CC 17) (const_int 0)))]
13170   "TARGET_80387 || TARGET_SSE"
13171   "if (ix86_expand_setcc (UNLT, operands[0])) DONE; else FAIL;")
13172
13173 (define_expand "sltgt"
13174   [(set (match_operand:QI 0 "register_operand" "")
13175         (ltgt:QI (reg:CC 17) (const_int 0)))]
13176   "TARGET_80387 || TARGET_SSE"
13177   "if (ix86_expand_setcc (LTGT, operands[0])) DONE; else FAIL;")
13178
13179 (define_insn "*setcc_1"
13180   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
13181         (match_operator:QI 1 "ix86_comparison_operator"
13182           [(reg 17) (const_int 0)]))]
13183   ""
13184   "set%C1\t%0"
13185   [(set_attr "type" "setcc")
13186    (set_attr "mode" "QI")])
13187
13188 (define_insn "setcc_2"
13189   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
13190         (match_operator:QI 1 "ix86_comparison_operator"
13191           [(reg 17) (const_int 0)]))]
13192   ""
13193   "set%C1\t%0"
13194   [(set_attr "type" "setcc")
13195    (set_attr "mode" "QI")])
13196
13197 ;; In general it is not safe to assume too much about CCmode registers,
13198 ;; so simplify-rtx stops when it sees a second one.  Under certain 
13199 ;; conditions this is safe on x86, so help combine not create
13200 ;;
13201 ;;      seta    %al
13202 ;;      testb   %al, %al
13203 ;;      sete    %al
13204
13205 (define_split 
13206   [(set (match_operand:QI 0 "nonimmediate_operand" "")
13207         (ne:QI (match_operator 1 "ix86_comparison_operator"
13208                  [(reg 17) (const_int 0)])
13209             (const_int 0)))]
13210   ""
13211   [(set (match_dup 0) (match_dup 1))]
13212 {
13213   PUT_MODE (operands[1], QImode);
13214 })
13215
13216 (define_split 
13217   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" ""))
13218         (ne:QI (match_operator 1 "ix86_comparison_operator"
13219                  [(reg 17) (const_int 0)])
13220             (const_int 0)))]
13221   ""
13222   [(set (match_dup 0) (match_dup 1))]
13223 {
13224   PUT_MODE (operands[1], QImode);
13225 })
13226
13227 (define_split 
13228   [(set (match_operand:QI 0 "nonimmediate_operand" "")
13229         (eq:QI (match_operator 1 "ix86_comparison_operator"
13230                  [(reg 17) (const_int 0)])
13231             (const_int 0)))]
13232   ""
13233   [(set (match_dup 0) (match_dup 1))]
13234 {
13235   rtx new_op1 = copy_rtx (operands[1]);
13236   operands[1] = new_op1;
13237   PUT_MODE (new_op1, QImode);
13238   PUT_CODE (new_op1, REVERSE_CONDITION (GET_CODE (new_op1),
13239                                         GET_MODE (XEXP (new_op1, 0))));
13240
13241   /* Make sure that (a) the CCmode we have for the flags is strong
13242      enough for the reversed compare or (b) we have a valid FP compare.  */
13243   if (! ix86_comparison_operator (new_op1, VOIDmode))
13244     FAIL;
13245 })
13246
13247 (define_split 
13248   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" ""))
13249         (eq:QI (match_operator 1 "ix86_comparison_operator"
13250                  [(reg 17) (const_int 0)])
13251             (const_int 0)))]
13252   ""
13253   [(set (match_dup 0) (match_dup 1))]
13254 {
13255   rtx new_op1 = copy_rtx (operands[1]);
13256   operands[1] = new_op1;
13257   PUT_MODE (new_op1, QImode);
13258   PUT_CODE (new_op1, REVERSE_CONDITION (GET_CODE (new_op1),
13259                                         GET_MODE (XEXP (new_op1, 0))));
13260
13261   /* Make sure that (a) the CCmode we have for the flags is strong
13262      enough for the reversed compare or (b) we have a valid FP compare.  */
13263   if (! ix86_comparison_operator (new_op1, VOIDmode))
13264     FAIL;
13265 })
13266
13267 ;; The SSE store flag instructions saves 0 or 0xffffffff to the result.
13268 ;; subsequent logical operations are used to imitate conditional moves.
13269 ;; 0xffffffff is NaN, but not in normalized form, so we can't represent
13270 ;; it directly.  Further holding this value in pseudo register might bring
13271 ;; problem in implicit normalization in spill code.
13272 ;; So we don't define FLOAT_STORE_FLAG_VALUE and create these
13273 ;; instructions after reload by splitting the conditional move patterns.
13274
13275 (define_insn "*sse_setccsf"
13276   [(set (match_operand:SF 0 "register_operand" "=x")
13277         (match_operator:SF 1 "sse_comparison_operator"
13278           [(match_operand:SF 2 "register_operand" "0")
13279            (match_operand:SF 3 "nonimmediate_operand" "xm")]))]
13280   "TARGET_SSE && reload_completed"
13281   "cmp%D1ss\t{%3, %0|%0, %3}"
13282   [(set_attr "type" "ssecmp")
13283    (set_attr "mode" "SF")])
13284
13285 (define_insn "*sse_setccdf"
13286   [(set (match_operand:DF 0 "register_operand" "=Y")
13287         (match_operator:DF 1 "sse_comparison_operator"
13288           [(match_operand:DF 2 "register_operand" "0")
13289            (match_operand:DF 3 "nonimmediate_operand" "Ym")]))]
13290   "TARGET_SSE2 && reload_completed"
13291   "cmp%D1sd\t{%3, %0|%0, %3}"
13292   [(set_attr "type" "ssecmp")
13293    (set_attr "mode" "DF")])
13294 \f
13295 ;; Basic conditional jump instructions.
13296 ;; We ignore the overflow flag for signed branch instructions.
13297
13298 ;; For all bCOND expanders, also expand the compare or test insn that
13299 ;; generates reg 17.  Generate an equality comparison if `beq' or `bne'.
13300
13301 (define_expand "beq"
13302   [(set (pc)
13303         (if_then_else (match_dup 1)
13304                       (label_ref (match_operand 0 "" ""))
13305                       (pc)))]
13306   ""
13307   "ix86_expand_branch (EQ, operands[0]); DONE;")
13308
13309 (define_expand "bne"
13310   [(set (pc)
13311         (if_then_else (match_dup 1)
13312                       (label_ref (match_operand 0 "" ""))
13313                       (pc)))]
13314   ""
13315   "ix86_expand_branch (NE, operands[0]); DONE;")
13316
13317 (define_expand "bgt"
13318   [(set (pc)
13319         (if_then_else (match_dup 1)
13320                       (label_ref (match_operand 0 "" ""))
13321                       (pc)))]
13322   ""
13323   "ix86_expand_branch (GT, operands[0]); DONE;")
13324
13325 (define_expand "bgtu"
13326   [(set (pc)
13327         (if_then_else (match_dup 1)
13328                       (label_ref (match_operand 0 "" ""))
13329                       (pc)))]
13330   ""
13331   "ix86_expand_branch (GTU, operands[0]); DONE;")
13332
13333 (define_expand "blt"
13334   [(set (pc)
13335         (if_then_else (match_dup 1)
13336                       (label_ref (match_operand 0 "" ""))
13337                       (pc)))]
13338   ""
13339   "ix86_expand_branch (LT, operands[0]); DONE;")
13340
13341 (define_expand "bltu"
13342   [(set (pc)
13343         (if_then_else (match_dup 1)
13344                       (label_ref (match_operand 0 "" ""))
13345                       (pc)))]
13346   ""
13347   "ix86_expand_branch (LTU, operands[0]); DONE;")
13348
13349 (define_expand "bge"
13350   [(set (pc)
13351         (if_then_else (match_dup 1)
13352                       (label_ref (match_operand 0 "" ""))
13353                       (pc)))]
13354   ""
13355   "ix86_expand_branch (GE, operands[0]); DONE;")
13356
13357 (define_expand "bgeu"
13358   [(set (pc)
13359         (if_then_else (match_dup 1)
13360                       (label_ref (match_operand 0 "" ""))
13361                       (pc)))]
13362   ""
13363   "ix86_expand_branch (GEU, operands[0]); DONE;")
13364
13365 (define_expand "ble"
13366   [(set (pc)
13367         (if_then_else (match_dup 1)
13368                       (label_ref (match_operand 0 "" ""))
13369                       (pc)))]
13370   ""
13371   "ix86_expand_branch (LE, operands[0]); DONE;")
13372
13373 (define_expand "bleu"
13374   [(set (pc)
13375         (if_then_else (match_dup 1)
13376                       (label_ref (match_operand 0 "" ""))
13377                       (pc)))]
13378   ""
13379   "ix86_expand_branch (LEU, operands[0]); DONE;")
13380
13381 (define_expand "bunordered"
13382   [(set (pc)
13383         (if_then_else (match_dup 1)
13384                       (label_ref (match_operand 0 "" ""))
13385                       (pc)))]
13386   "TARGET_80387 || TARGET_SSE"
13387   "ix86_expand_branch (UNORDERED, operands[0]); DONE;")
13388
13389 (define_expand "bordered"
13390   [(set (pc)
13391         (if_then_else (match_dup 1)
13392                       (label_ref (match_operand 0 "" ""))
13393                       (pc)))]
13394   "TARGET_80387 || TARGET_SSE"
13395   "ix86_expand_branch (ORDERED, operands[0]); DONE;")
13396
13397 (define_expand "buneq"
13398   [(set (pc)
13399         (if_then_else (match_dup 1)
13400                       (label_ref (match_operand 0 "" ""))
13401                       (pc)))]
13402   "TARGET_80387 || TARGET_SSE"
13403   "ix86_expand_branch (UNEQ, operands[0]); DONE;")
13404
13405 (define_expand "bunge"
13406   [(set (pc)
13407         (if_then_else (match_dup 1)
13408                       (label_ref (match_operand 0 "" ""))
13409                       (pc)))]
13410   "TARGET_80387 || TARGET_SSE"
13411   "ix86_expand_branch (UNGE, operands[0]); DONE;")
13412
13413 (define_expand "bungt"
13414   [(set (pc)
13415         (if_then_else (match_dup 1)
13416                       (label_ref (match_operand 0 "" ""))
13417                       (pc)))]
13418   "TARGET_80387 || TARGET_SSE"
13419   "ix86_expand_branch (UNGT, operands[0]); DONE;")
13420
13421 (define_expand "bunle"
13422   [(set (pc)
13423         (if_then_else (match_dup 1)
13424                       (label_ref (match_operand 0 "" ""))
13425                       (pc)))]
13426   "TARGET_80387 || TARGET_SSE"
13427   "ix86_expand_branch (UNLE, operands[0]); DONE;")
13428
13429 (define_expand "bunlt"
13430   [(set (pc)
13431         (if_then_else (match_dup 1)
13432                       (label_ref (match_operand 0 "" ""))
13433                       (pc)))]
13434   "TARGET_80387 || TARGET_SSE"
13435   "ix86_expand_branch (UNLT, operands[0]); DONE;")
13436
13437 (define_expand "bltgt"
13438   [(set (pc)
13439         (if_then_else (match_dup 1)
13440                       (label_ref (match_operand 0 "" ""))
13441                       (pc)))]
13442   "TARGET_80387 || TARGET_SSE"
13443   "ix86_expand_branch (LTGT, operands[0]); DONE;")
13444
13445 (define_insn "*jcc_1"
13446   [(set (pc)
13447         (if_then_else (match_operator 1 "ix86_comparison_operator"
13448                                       [(reg 17) (const_int 0)])
13449                       (label_ref (match_operand 0 "" ""))
13450                       (pc)))]
13451   ""
13452   "%+j%C1\t%l0"
13453   [(set_attr "type" "ibr")
13454    (set_attr "modrm" "0")
13455    (set (attr "length")
13456            (if_then_else (and (ge (minus (match_dup 0) (pc))
13457                                   (const_int -128))
13458                               (lt (minus (match_dup 0) (pc))
13459                                   (const_int 124)))
13460              (const_int 2)
13461              (const_int 6)))])
13462
13463 (define_insn "*jcc_2"
13464   [(set (pc)
13465         (if_then_else (match_operator 1 "ix86_comparison_operator"
13466                                       [(reg 17) (const_int 0)])
13467                       (pc)
13468                       (label_ref (match_operand 0 "" ""))))]
13469   ""
13470   "%+j%c1\t%l0"
13471   [(set_attr "type" "ibr")
13472    (set_attr "modrm" "0")
13473    (set (attr "length")
13474            (if_then_else (and (ge (minus (match_dup 0) (pc))
13475                                   (const_int -128))
13476                               (lt (minus (match_dup 0) (pc))
13477                                   (const_int 124)))
13478              (const_int 2)
13479              (const_int 6)))])
13480
13481 ;; In general it is not safe to assume too much about CCmode registers,
13482 ;; so simplify-rtx stops when it sees a second one.  Under certain 
13483 ;; conditions this is safe on x86, so help combine not create
13484 ;;
13485 ;;      seta    %al
13486 ;;      testb   %al, %al
13487 ;;      je      Lfoo
13488
13489 (define_split 
13490   [(set (pc)
13491         (if_then_else (ne (match_operator 0 "ix86_comparison_operator"
13492                                       [(reg 17) (const_int 0)])
13493                           (const_int 0))
13494                       (label_ref (match_operand 1 "" ""))
13495                       (pc)))]
13496   ""
13497   [(set (pc)
13498         (if_then_else (match_dup 0)
13499                       (label_ref (match_dup 1))
13500                       (pc)))]
13501 {
13502   PUT_MODE (operands[0], VOIDmode);
13503 })
13504   
13505 (define_split 
13506   [(set (pc)
13507         (if_then_else (eq (match_operator 0 "ix86_comparison_operator"
13508                                       [(reg 17) (const_int 0)])
13509                           (const_int 0))
13510                       (label_ref (match_operand 1 "" ""))
13511                       (pc)))]
13512   ""
13513   [(set (pc)
13514         (if_then_else (match_dup 0)
13515                       (label_ref (match_dup 1))
13516                       (pc)))]
13517 {
13518   rtx new_op0 = copy_rtx (operands[0]);
13519   operands[0] = new_op0;
13520   PUT_MODE (new_op0, VOIDmode);
13521   PUT_CODE (new_op0, REVERSE_CONDITION (GET_CODE (new_op0),
13522                                         GET_MODE (XEXP (new_op0, 0))));
13523
13524   /* Make sure that (a) the CCmode we have for the flags is strong
13525      enough for the reversed compare or (b) we have a valid FP compare.  */
13526   if (! ix86_comparison_operator (new_op0, VOIDmode))
13527     FAIL;
13528 })
13529
13530 ;; Define combination compare-and-branch fp compare instructions to use
13531 ;; during early optimization.  Splitting the operation apart early makes
13532 ;; for bad code when we want to reverse the operation.
13533
13534 (define_insn "*fp_jcc_1"
13535   [(set (pc)
13536         (if_then_else (match_operator 0 "comparison_operator"
13537                         [(match_operand 1 "register_operand" "f")
13538                          (match_operand 2 "register_operand" "f")])
13539           (label_ref (match_operand 3 "" ""))
13540           (pc)))
13541    (clobber (reg:CCFP 18))
13542    (clobber (reg:CCFP 17))]
13543   "TARGET_CMOVE && TARGET_80387
13544    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
13545    && FLOAT_MODE_P (GET_MODE (operands[1]))
13546    && GET_MODE (operands[1]) == GET_MODE (operands[2])
13547    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
13548   "#")
13549
13550 (define_insn "*fp_jcc_1_sse"
13551   [(set (pc)
13552         (if_then_else (match_operator 0 "comparison_operator"
13553                         [(match_operand 1 "register_operand" "f#x,x#f")
13554                          (match_operand 2 "nonimmediate_operand" "f#x,xm#f")])
13555           (label_ref (match_operand 3 "" ""))
13556           (pc)))
13557    (clobber (reg:CCFP 18))
13558    (clobber (reg:CCFP 17))]
13559   "TARGET_80387
13560    && SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
13561    && GET_MODE (operands[1]) == GET_MODE (operands[2])
13562    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
13563   "#")
13564
13565 (define_insn "*fp_jcc_1_sse_only"
13566   [(set (pc)
13567         (if_then_else (match_operator 0 "comparison_operator"
13568                         [(match_operand 1 "register_operand" "x")
13569                          (match_operand 2 "nonimmediate_operand" "xm")])
13570           (label_ref (match_operand 3 "" ""))
13571           (pc)))
13572    (clobber (reg:CCFP 18))
13573    (clobber (reg:CCFP 17))]
13574   "SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
13575    && GET_MODE (operands[1]) == GET_MODE (operands[2])
13576    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
13577   "#")
13578
13579 (define_insn "*fp_jcc_2"
13580   [(set (pc)
13581         (if_then_else (match_operator 0 "comparison_operator"
13582                         [(match_operand 1 "register_operand" "f")
13583                          (match_operand 2 "register_operand" "f")])
13584           (pc)
13585           (label_ref (match_operand 3 "" ""))))
13586    (clobber (reg:CCFP 18))
13587    (clobber (reg:CCFP 17))]
13588   "TARGET_CMOVE && TARGET_80387
13589    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
13590    && FLOAT_MODE_P (GET_MODE (operands[1]))
13591    && GET_MODE (operands[1]) == GET_MODE (operands[2])
13592    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
13593   "#")
13594
13595 (define_insn "*fp_jcc_2_sse"
13596   [(set (pc)
13597         (if_then_else (match_operator 0 "comparison_operator"
13598                         [(match_operand 1 "register_operand" "f#x,x#f")
13599                          (match_operand 2 "nonimmediate_operand" "f#x,xm#f")])
13600           (pc)
13601           (label_ref (match_operand 3 "" ""))))
13602    (clobber (reg:CCFP 18))
13603    (clobber (reg:CCFP 17))]
13604   "TARGET_80387
13605    && SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
13606    && GET_MODE (operands[1]) == GET_MODE (operands[2])
13607    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
13608   "#")
13609
13610 (define_insn "*fp_jcc_2_sse_only"
13611   [(set (pc)
13612         (if_then_else (match_operator 0 "comparison_operator"
13613                         [(match_operand 1 "register_operand" "x")
13614                          (match_operand 2 "nonimmediate_operand" "xm")])
13615           (pc)
13616           (label_ref (match_operand 3 "" ""))))
13617    (clobber (reg:CCFP 18))
13618    (clobber (reg:CCFP 17))]
13619   "SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
13620    && GET_MODE (operands[1]) == GET_MODE (operands[2])
13621    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
13622   "#")
13623
13624 (define_insn "*fp_jcc_3"
13625   [(set (pc)
13626         (if_then_else (match_operator 0 "comparison_operator"
13627                         [(match_operand 1 "register_operand" "f")
13628                          (match_operand 2 "nonimmediate_operand" "fm")])
13629           (label_ref (match_operand 3 "" ""))
13630           (pc)))
13631    (clobber (reg:CCFP 18))
13632    (clobber (reg:CCFP 17))
13633    (clobber (match_scratch:HI 4 "=a"))]
13634   "TARGET_80387
13635    && (GET_MODE (operands[1]) == SFmode || GET_MODE (operands[1]) == DFmode)
13636    && GET_MODE (operands[1]) == GET_MODE (operands[2])
13637    && !ix86_use_fcomi_compare (GET_CODE (operands[0]))
13638    && SELECT_CC_MODE (GET_CODE (operands[0]),
13639                       operands[1], operands[2]) == CCFPmode
13640    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
13641   "#")
13642
13643 (define_insn "*fp_jcc_4"
13644   [(set (pc)
13645         (if_then_else (match_operator 0 "comparison_operator"
13646                         [(match_operand 1 "register_operand" "f")
13647                          (match_operand 2 "nonimmediate_operand" "fm")])
13648           (pc)
13649           (label_ref (match_operand 3 "" ""))))
13650    (clobber (reg:CCFP 18))
13651    (clobber (reg:CCFP 17))
13652    (clobber (match_scratch:HI 4 "=a"))]
13653   "TARGET_80387
13654    && (GET_MODE (operands[1]) == SFmode || GET_MODE (operands[1]) == DFmode)
13655    && GET_MODE (operands[1]) == GET_MODE (operands[2])
13656    && !ix86_use_fcomi_compare (GET_CODE (operands[0]))
13657    && SELECT_CC_MODE (GET_CODE (operands[0]),
13658                       operands[1], operands[2]) == CCFPmode
13659    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
13660   "#")
13661
13662 (define_insn "*fp_jcc_5"
13663   [(set (pc)
13664         (if_then_else (match_operator 0 "comparison_operator"
13665                         [(match_operand 1 "register_operand" "f")
13666                          (match_operand 2 "register_operand" "f")])
13667           (label_ref (match_operand 3 "" ""))
13668           (pc)))
13669    (clobber (reg:CCFP 18))
13670    (clobber (reg:CCFP 17))
13671    (clobber (match_scratch:HI 4 "=a"))]
13672   "TARGET_80387
13673    && FLOAT_MODE_P (GET_MODE (operands[1]))
13674    && GET_MODE (operands[1]) == GET_MODE (operands[2])
13675    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
13676   "#")
13677
13678 (define_insn "*fp_jcc_6"
13679   [(set (pc)
13680         (if_then_else (match_operator 0 "comparison_operator"
13681                         [(match_operand 1 "register_operand" "f")
13682                          (match_operand 2 "register_operand" "f")])
13683           (pc)
13684           (label_ref (match_operand 3 "" ""))))
13685    (clobber (reg:CCFP 18))
13686    (clobber (reg:CCFP 17))
13687    (clobber (match_scratch:HI 4 "=a"))]
13688   "TARGET_80387
13689    && FLOAT_MODE_P (GET_MODE (operands[1]))
13690    && GET_MODE (operands[1]) == GET_MODE (operands[2])
13691    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
13692   "#")
13693
13694 (define_split
13695   [(set (pc)
13696         (if_then_else (match_operator 0 "comparison_operator"
13697                         [(match_operand 1 "register_operand" "")
13698                          (match_operand 2 "nonimmediate_operand" "")])
13699           (match_operand 3 "" "")
13700           (match_operand 4 "" "")))
13701    (clobber (reg:CCFP 18))
13702    (clobber (reg:CCFP 17))]
13703   "reload_completed"
13704   [(const_int 0)]
13705 {
13706   ix86_split_fp_branch (GET_CODE (operands[0]), operands[1], operands[2],
13707                         operands[3], operands[4], NULL_RTX);
13708   DONE;
13709 })
13710
13711 (define_split
13712   [(set (pc)
13713         (if_then_else (match_operator 0 "comparison_operator"
13714                         [(match_operand 1 "register_operand" "")
13715                          (match_operand 2 "nonimmediate_operand" "")])
13716           (match_operand 3 "" "")
13717           (match_operand 4 "" "")))
13718    (clobber (reg:CCFP 18))
13719    (clobber (reg:CCFP 17))
13720    (clobber (match_scratch:HI 5 "=a"))]
13721   "reload_completed"
13722   [(set (pc)
13723         (if_then_else (match_dup 6)
13724           (match_dup 3)
13725           (match_dup 4)))]
13726 {
13727   ix86_split_fp_branch (GET_CODE (operands[0]), operands[1], operands[2],
13728                         operands[3], operands[4], operands[5]);
13729   DONE;
13730 })
13731 \f
13732 ;; Unconditional and other jump instructions
13733
13734 (define_insn "jump"
13735   [(set (pc)
13736         (label_ref (match_operand 0 "" "")))]
13737   ""
13738   "jmp\t%l0"
13739   [(set_attr "type" "ibr")
13740    (set (attr "length")
13741            (if_then_else (and (ge (minus (match_dup 0) (pc))
13742                                   (const_int -128))
13743                               (lt (minus (match_dup 0) (pc))
13744                                   (const_int 124)))
13745              (const_int 2)
13746              (const_int 5)))
13747    (set_attr "modrm" "0")])
13748
13749 (define_expand "indirect_jump"
13750   [(set (pc) (match_operand 0 "nonimmediate_operand" "rm"))]
13751   ""
13752   "")
13753
13754 (define_insn "*indirect_jump"
13755   [(set (pc) (match_operand:SI 0 "nonimmediate_operand" "rm"))]
13756   "!TARGET_64BIT"
13757   "jmp\t%A0"
13758   [(set_attr "type" "ibr")
13759    (set_attr "length_immediate" "0")])
13760
13761 (define_insn "*indirect_jump_rtx64"
13762   [(set (pc) (match_operand:DI 0 "nonimmediate_operand" "rm"))]
13763   "TARGET_64BIT"
13764   "jmp\t%A0"
13765   [(set_attr "type" "ibr")
13766    (set_attr "length_immediate" "0")])
13767
13768 (define_expand "tablejump"
13769   [(parallel [(set (pc) (match_operand 0 "nonimmediate_operand" "rm"))
13770               (use (label_ref (match_operand 1 "" "")))])]
13771   ""
13772 {
13773   /* In PIC mode, the table entries are stored GOT (32-bit) or PC (64-bit)
13774      relative.  Convert the relative address to an absolute address.  */
13775   if (flag_pic)
13776     {
13777       rtx op0, op1;
13778       enum rtx_code code;
13779
13780       if (TARGET_64BIT)
13781         {
13782           code = PLUS;
13783           op0 = operands[0];
13784           op1 = gen_rtx_LABEL_REF (Pmode, operands[1]);
13785         }
13786       else if (TARGET_MACHO || HAVE_AS_GOTOFF_IN_DATA)
13787         {
13788           code = PLUS;
13789           op0 = operands[0];
13790           op1 = pic_offset_table_rtx;
13791         }
13792       else
13793         {
13794           code = MINUS;
13795           op0 = pic_offset_table_rtx;
13796           op1 = operands[0];
13797         }
13798
13799       operands[0] = expand_simple_binop (Pmode, code, op0, op1, NULL_RTX, 0,
13800                                          OPTAB_DIRECT);
13801     }
13802 })
13803
13804 (define_insn "*tablejump_1"
13805   [(set (pc) (match_operand:SI 0 "nonimmediate_operand" "rm"))
13806    (use (label_ref (match_operand 1 "" "")))]
13807   "!TARGET_64BIT"
13808   "jmp\t%A0"
13809   [(set_attr "type" "ibr")
13810    (set_attr "length_immediate" "0")])
13811
13812 (define_insn "*tablejump_1_rtx64"
13813   [(set (pc) (match_operand:DI 0 "nonimmediate_operand" "rm"))
13814    (use (label_ref (match_operand 1 "" "")))]
13815   "TARGET_64BIT"
13816   "jmp\t%A0"
13817   [(set_attr "type" "ibr")
13818    (set_attr "length_immediate" "0")])
13819 \f
13820 ;; Loop instruction
13821 ;;
13822 ;; This is all complicated by the fact that since this is a jump insn
13823 ;; we must handle our own reloads.
13824
13825 (define_expand "doloop_end"
13826   [(use (match_operand 0 "" ""))        ; loop pseudo
13827    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
13828    (use (match_operand 2 "" ""))        ; max iterations
13829    (use (match_operand 3 "" ""))        ; loop level 
13830    (use (match_operand 4 "" ""))]       ; label
13831   "!TARGET_64BIT && TARGET_USE_LOOP"
13832   "                                 
13833 {
13834   /* Only use cloop on innermost loops.  */
13835   if (INTVAL (operands[3]) > 1)
13836     FAIL;
13837   if (GET_MODE (operands[0]) != SImode)
13838     FAIL;
13839   emit_jump_insn (gen_doloop_end_internal (operands[4], operands[0],
13840                                            operands[0]));
13841   DONE;
13842 }")
13843
13844 (define_insn "doloop_end_internal"
13845   [(set (pc)
13846         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,?*r,?*r")
13847                           (const_int 1))
13848                       (label_ref (match_operand 0 "" ""))
13849                       (pc)))
13850    (set (match_operand:SI 2 "register_operand" "=1,1,*m*r")
13851         (plus:SI (match_dup 1)
13852                  (const_int -1)))
13853    (clobber (match_scratch:SI 3 "=X,X,r"))
13854    (clobber (reg:CC 17))]
13855   "!TARGET_64BIT && TARGET_USE_LOOP"
13856 {
13857   if (which_alternative != 0)
13858     return "#";
13859   if (get_attr_length (insn) == 2)
13860     return "%+loop\t%l0";
13861   else
13862     return "dec{l}\t%1\;%+jne\t%l0";
13863 }
13864   [(set_attr "ppro_uops" "many")
13865    (set (attr "length")
13866         (if_then_else (and (eq_attr "alternative" "0")
13867                            (and (ge (minus (match_dup 0) (pc))
13868                                     (const_int -128))
13869                                 (lt (minus (match_dup 0) (pc))
13870                                     (const_int 124))))
13871                       (const_int 2)
13872                       (const_int 16)))
13873    ;; We don't know the type before shorten branches.  Optimistically expect
13874    ;; the loop instruction to match.
13875    (set (attr "type") (const_string "ibr"))])
13876
13877 (define_split
13878   [(set (pc)
13879         (if_then_else (ne (match_operand:SI 1 "register_operand" "")
13880                           (const_int 1))
13881                       (match_operand 0 "" "")
13882                       (pc)))
13883    (set (match_dup 1)
13884         (plus:SI (match_dup 1)
13885                  (const_int -1)))
13886    (clobber (match_scratch:SI 2 ""))
13887    (clobber (reg:CC 17))]
13888   "!TARGET_64BIT && TARGET_USE_LOOP
13889    && reload_completed
13890    && REGNO (operands[1]) != 2"
13891   [(parallel [(set (reg:CCZ 17)
13892                    (compare:CCZ (plus:SI (match_dup 1) (const_int -1))
13893                                  (const_int 0)))
13894               (set (match_dup 1) (plus:SI (match_dup 1) (const_int -1)))])
13895    (set (pc) (if_then_else (ne (reg:CCZ 17) (const_int 0))
13896                            (match_dup 0)
13897                            (pc)))]
13898   "")
13899   
13900 (define_split
13901   [(set (pc)
13902         (if_then_else (ne (match_operand:SI 1 "register_operand" "")
13903                           (const_int 1))
13904                       (match_operand 0 "" "")
13905                       (pc)))
13906    (set (match_operand:SI 2 "nonimmediate_operand" "")
13907         (plus:SI (match_dup 1)
13908                  (const_int -1)))
13909    (clobber (match_scratch:SI 3 ""))
13910    (clobber (reg:CC 17))]
13911   "!TARGET_64BIT && TARGET_USE_LOOP
13912    && reload_completed
13913    && (! REG_P (operands[2])
13914        || ! rtx_equal_p (operands[1], operands[2]))"
13915   [(set (match_dup 3) (match_dup 1))
13916    (parallel [(set (reg:CCZ 17)
13917                    (compare:CCZ (plus:SI (match_dup 3) (const_int -1))
13918                                 (const_int 0)))
13919               (set (match_dup 3) (plus:SI (match_dup 3) (const_int -1)))])
13920    (set (match_dup 2) (match_dup 3))
13921    (set (pc) (if_then_else (ne (reg:CCZ 17) (const_int 0))
13922                            (match_dup 0)
13923                            (pc)))]
13924   "")
13925
13926 ;; Convert setcc + movzbl to xor + setcc if operands don't overlap.
13927
13928 (define_peephole2
13929   [(set (reg 17) (match_operand 0 "" ""))
13930    (set (match_operand:QI 1 "register_operand" "")
13931         (match_operator:QI 2 "ix86_comparison_operator"
13932           [(reg 17) (const_int 0)]))
13933    (set (match_operand 3 "q_regs_operand" "")
13934         (zero_extend (match_dup 1)))]
13935   "(peep2_reg_dead_p (3, operands[1])
13936     || operands_match_p (operands[1], operands[3]))
13937    && ! reg_overlap_mentioned_p (operands[3], operands[0])"
13938   [(set (match_dup 4) (match_dup 0))
13939    (set (strict_low_part (match_dup 5))
13940         (match_dup 2))]
13941 {
13942   operands[4] = gen_rtx_REG (GET_MODE (operands[0]), 17);
13943   operands[5] = gen_rtx_REG (QImode, REGNO (operands[3]));
13944   ix86_expand_clear (operands[3]);
13945 })
13946
13947 ;; Similar, but match zero_extendhisi2_and, which adds a clobber.
13948
13949 (define_peephole2
13950   [(set (reg 17) (match_operand 0 "" ""))
13951    (set (match_operand:QI 1 "register_operand" "")
13952         (match_operator:QI 2 "ix86_comparison_operator"
13953           [(reg 17) (const_int 0)]))
13954    (parallel [(set (match_operand 3 "q_regs_operand" "")
13955                    (zero_extend (match_dup 1)))
13956               (clobber (reg:CC 17))])]
13957   "(peep2_reg_dead_p (3, operands[1])
13958     || operands_match_p (operands[1], operands[3]))
13959    && ! reg_overlap_mentioned_p (operands[3], operands[0])"
13960   [(set (match_dup 4) (match_dup 0))
13961    (set (strict_low_part (match_dup 5))
13962         (match_dup 2))]
13963 {
13964   operands[4] = gen_rtx_REG (GET_MODE (operands[0]), 17);
13965   operands[5] = gen_rtx_REG (QImode, REGNO (operands[3]));
13966   ix86_expand_clear (operands[3]);
13967 })
13968 \f
13969 ;; Call instructions.
13970
13971 ;; The predicates normally associated with named expanders are not properly
13972 ;; checked for calls.  This is a bug in the generic code, but it isn't that
13973 ;; easy to fix.  Ignore it for now and be prepared to fix things up.
13974
13975 ;; Call subroutine returning no value.
13976
13977 (define_expand "call_pop"
13978   [(parallel [(call (match_operand:QI 0 "" "")
13979                     (match_operand:SI 1 "" ""))
13980               (set (reg:SI 7)
13981                    (plus:SI (reg:SI 7)
13982                             (match_operand:SI 3 "" "")))])]
13983   "!TARGET_64BIT"
13984 {
13985   ix86_expand_call (NULL, operands[0], operands[1], operands[2], operands[3], 0);
13986   DONE;
13987 })
13988
13989 (define_insn "*call_pop_0"
13990   [(call (mem:QI (match_operand:SI 0 "constant_call_address_operand" ""))
13991          (match_operand:SI 1 "" ""))
13992    (set (reg:SI 7) (plus:SI (reg:SI 7)
13993                             (match_operand:SI 2 "immediate_operand" "")))]
13994   "!TARGET_64BIT"
13995 {
13996   if (SIBLING_CALL_P (insn))
13997     return "jmp\t%P0";
13998   else
13999     return "call\t%P0";
14000 }
14001   [(set_attr "type" "call")])
14002   
14003 (define_insn "*call_pop_1"
14004   [(call (mem:QI (match_operand:SI 0 "call_insn_operand" "rsm"))
14005          (match_operand:SI 1 "" ""))
14006    (set (reg:SI 7) (plus:SI (reg:SI 7)
14007                             (match_operand:SI 2 "immediate_operand" "i")))]
14008   "!TARGET_64BIT"
14009 {
14010   if (constant_call_address_operand (operands[0], Pmode))
14011     {
14012       if (SIBLING_CALL_P (insn))
14013         return "jmp\t%P0";
14014       else
14015         return "call\t%P0";
14016     }
14017   if (SIBLING_CALL_P (insn))
14018     return "jmp\t%A0";
14019   else
14020     return "call\t%A0";
14021 }
14022   [(set_attr "type" "call")])
14023
14024 (define_expand "call"
14025   [(call (match_operand:QI 0 "" "")
14026          (match_operand 1 "" ""))
14027    (use (match_operand 2 "" ""))]
14028   ""
14029 {
14030   ix86_expand_call (NULL, operands[0], operands[1], operands[2], NULL, 0);
14031   DONE;
14032 })
14033
14034 (define_expand "sibcall"
14035   [(call (match_operand:QI 0 "" "")
14036          (match_operand 1 "" ""))
14037    (use (match_operand 2 "" ""))]
14038   ""
14039 {
14040   ix86_expand_call (NULL, operands[0], operands[1], operands[2], NULL, 1);
14041   DONE;
14042 })
14043
14044 (define_insn "*call_0"
14045   [(call (mem:QI (match_operand 0 "constant_call_address_operand" ""))
14046          (match_operand 1 "" ""))]
14047   ""
14048 {
14049   if (SIBLING_CALL_P (insn))
14050     return "jmp\t%P0";
14051   else
14052     return "call\t%P0";
14053 }
14054   [(set_attr "type" "call")])
14055
14056 (define_insn "*call_1"
14057   [(call (mem:QI (match_operand:SI 0 "call_insn_operand" "rsm"))
14058          (match_operand 1 "" ""))]
14059   "!SIBLING_CALL_P (insn) && !TARGET_64BIT"
14060 {
14061   if (constant_call_address_operand (operands[0], QImode))
14062     return "call\t%P0";
14063   return "call\t%A0";
14064 }
14065   [(set_attr "type" "call")])
14066
14067 (define_insn "*sibcall_1"
14068   [(call (mem:QI (match_operand:SI 0 "sibcall_insn_operand" "s,c,d,a"))
14069          (match_operand 1 "" ""))]
14070   "SIBLING_CALL_P (insn) && !TARGET_64BIT"
14071 {
14072   if (constant_call_address_operand (operands[0], QImode))
14073     return "jmp\t%P0";
14074   return "jmp\t%A0";
14075 }
14076   [(set_attr "type" "call")])
14077
14078 (define_insn "*call_1_rex64"
14079   [(call (mem:QI (match_operand:DI 0 "call_insn_operand" "rsm"))
14080          (match_operand 1 "" ""))]
14081   "!SIBLING_CALL_P (insn) && TARGET_64BIT"
14082 {
14083   if (constant_call_address_operand (operands[0], QImode))
14084     return "call\t%P0";
14085   return "call\t%A0";
14086 }
14087   [(set_attr "type" "call")])
14088
14089 (define_insn "*sibcall_1_rex64"
14090   [(call (mem:QI (match_operand:DI 0 "constant_call_address_operand" ""))
14091          (match_operand 1 "" ""))]
14092   "SIBLING_CALL_P (insn) && TARGET_64BIT"
14093   "jmp\t%P0"
14094   [(set_attr "type" "call")])
14095
14096 (define_insn "*sibcall_1_rex64_v"
14097   [(call (mem:QI (reg:DI 40))
14098          (match_operand 0 "" ""))]
14099   "SIBLING_CALL_P (insn) && TARGET_64BIT"
14100   "jmp\t*%%r11"
14101   [(set_attr "type" "call")])
14102
14103
14104 ;; Call subroutine, returning value in operand 0
14105
14106 (define_expand "call_value_pop"
14107   [(parallel [(set (match_operand 0 "" "")
14108                    (call (match_operand:QI 1 "" "")
14109                          (match_operand:SI 2 "" "")))
14110               (set (reg:SI 7)
14111                    (plus:SI (reg:SI 7)
14112                             (match_operand:SI 4 "" "")))])]
14113   "!TARGET_64BIT"
14114 {
14115   ix86_expand_call (operands[0], operands[1], operands[2],
14116                     operands[3], operands[4], 0);
14117   DONE;
14118 })
14119
14120 (define_expand "call_value"
14121   [(set (match_operand 0 "" "")
14122         (call (match_operand:QI 1 "" "")
14123               (match_operand:SI 2 "" "")))
14124    (use (match_operand:SI 3 "" ""))]
14125   ;; Operand 2 not used on the i386.
14126   ""
14127 {
14128   ix86_expand_call (operands[0], operands[1], operands[2], operands[3], NULL, 0);
14129   DONE;
14130 })
14131
14132 (define_expand "sibcall_value"
14133   [(set (match_operand 0 "" "")
14134         (call (match_operand:QI 1 "" "")
14135               (match_operand:SI 2 "" "")))
14136    (use (match_operand:SI 3 "" ""))]
14137   ;; Operand 2 not used on the i386.
14138   ""
14139 {
14140   ix86_expand_call (operands[0], operands[1], operands[2], operands[3], NULL, 1);
14141   DONE;
14142 })
14143
14144 ;; Call subroutine returning any type.
14145
14146 (define_expand "untyped_call"
14147   [(parallel [(call (match_operand 0 "" "")
14148                     (const_int 0))
14149               (match_operand 1 "" "")
14150               (match_operand 2 "" "")])]
14151   ""
14152 {
14153   int i;
14154
14155   /* In order to give reg-stack an easier job in validating two
14156      coprocessor registers as containing a possible return value,
14157      simply pretend the untyped call returns a complex long double
14158      value.  */
14159
14160   ix86_expand_call ((TARGET_FLOAT_RETURNS_IN_80387
14161                      ? gen_rtx_REG (XCmode, FIRST_FLOAT_REG) : NULL),
14162                     operands[0], const0_rtx, GEN_INT (SSE_REGPARM_MAX - 1),
14163                     NULL, 0);
14164
14165   for (i = 0; i < XVECLEN (operands[2], 0); i++)
14166     {
14167       rtx set = XVECEXP (operands[2], 0, i);
14168       emit_move_insn (SET_DEST (set), SET_SRC (set));
14169     }
14170
14171   /* The optimizer does not know that the call sets the function value
14172      registers we stored in the result block.  We avoid problems by
14173      claiming that all hard registers are used and clobbered at this
14174      point.  */
14175   emit_insn (gen_blockage (const0_rtx));
14176
14177   DONE;
14178 })
14179 \f
14180 ;; Prologue and epilogue instructions
14181
14182 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
14183 ;; all of memory.  This blocks insns from being moved across this point.
14184
14185 (define_insn "blockage"
14186   [(unspec_volatile [(match_operand 0 "" "")] UNSPECV_BLOCKAGE)]
14187   ""
14188   ""
14189   [(set_attr "length" "0")])
14190
14191 ;; Insn emitted into the body of a function to return from a function.
14192 ;; This is only done if the function's epilogue is known to be simple.
14193 ;; See comments for ix86_can_use_return_insn_p in i386.c.
14194
14195 (define_expand "return"
14196   [(return)]
14197   "ix86_can_use_return_insn_p ()"
14198 {
14199   if (current_function_pops_args)
14200     {
14201       rtx popc = GEN_INT (current_function_pops_args);
14202       emit_jump_insn (gen_return_pop_internal (popc));
14203       DONE;
14204     }
14205 })
14206
14207 (define_insn "return_internal"
14208   [(return)]
14209   "reload_completed"
14210   "ret"
14211   [(set_attr "length" "1")
14212    (set_attr "length_immediate" "0")
14213    (set_attr "modrm" "0")])
14214
14215 (define_insn "return_pop_internal"
14216   [(return)
14217    (use (match_operand:SI 0 "const_int_operand" ""))]
14218   "reload_completed"
14219   "ret\t%0"
14220   [(set_attr "length" "3")
14221    (set_attr "length_immediate" "2")
14222    (set_attr "modrm" "0")])
14223
14224 (define_insn "return_indirect_internal"
14225   [(return)
14226    (use (match_operand:SI 0 "register_operand" "r"))]
14227   "reload_completed"
14228   "jmp\t%A0"
14229   [(set_attr "type" "ibr")
14230    (set_attr "length_immediate" "0")])
14231
14232 (define_insn "nop"
14233   [(const_int 0)]
14234   ""
14235   "nop"
14236   [(set_attr "length" "1")
14237    (set_attr "length_immediate" "0")
14238    (set_attr "modrm" "0")
14239    (set_attr "ppro_uops" "one")])
14240
14241 (define_expand "prologue"
14242   [(const_int 1)]
14243   ""
14244   "ix86_expand_prologue (); DONE;")
14245
14246 (define_insn "set_got"
14247   [(set (match_operand:SI 0 "register_operand" "=r")
14248         (unspec:SI [(const_int 0)] UNSPEC_SET_GOT))
14249    (clobber (reg:CC 17))]
14250   "!TARGET_64BIT"
14251   { return output_set_got (operands[0]); }
14252   [(set_attr "type" "multi")
14253    (set_attr "length" "12")])
14254
14255 (define_expand "epilogue"
14256   [(const_int 1)]
14257   ""
14258   "ix86_expand_epilogue (1); DONE;")
14259
14260 (define_expand "sibcall_epilogue"
14261   [(const_int 1)]
14262   ""
14263   "ix86_expand_epilogue (0); DONE;")
14264
14265 (define_expand "eh_return"
14266   [(use (match_operand 0 "register_operand" ""))
14267    (use (match_operand 1 "register_operand" ""))]
14268   ""
14269 {
14270   rtx tmp, sa = operands[0], ra = operands[1];
14271
14272   /* Tricky bit: we write the address of the handler to which we will
14273      be returning into someone else's stack frame, one word below the
14274      stack address we wish to restore.  */
14275   tmp = gen_rtx_PLUS (Pmode, arg_pointer_rtx, sa);
14276   tmp = plus_constant (tmp, -UNITS_PER_WORD);
14277   tmp = gen_rtx_MEM (Pmode, tmp);
14278   emit_move_insn (tmp, ra);
14279
14280   if (Pmode == SImode)
14281     emit_insn (gen_eh_return_si (sa));
14282   else
14283     emit_insn (gen_eh_return_di (sa));
14284   emit_barrier ();
14285   DONE;
14286 })
14287
14288 (define_insn_and_split "eh_return_si"
14289   [(unspec_volatile [(match_operand:SI 0 "register_operand" "c")]
14290                     UNSPECV_EH_RETURN)]
14291   "!TARGET_64BIT"
14292   "#"
14293   "reload_completed"
14294   [(const_int 1)]
14295   "ix86_expand_epilogue (2); DONE;")
14296
14297 (define_insn_and_split "eh_return_di"
14298   [(unspec_volatile [(match_operand:DI 0 "register_operand" "c")]
14299                     UNSPECV_EH_RETURN)]
14300   "TARGET_64BIT"
14301   "#"
14302   "reload_completed"
14303   [(const_int 1)]
14304   "ix86_expand_epilogue (2); DONE;")
14305
14306 (define_insn "leave"
14307   [(set (reg:SI 7) (plus:SI (reg:SI 6) (const_int 4)))
14308    (set (reg:SI 6) (mem:SI (reg:SI 6)))
14309    (clobber (mem:BLK (scratch)))]
14310   "!TARGET_64BIT"
14311   "leave"
14312   [(set_attr "type" "leave")])
14313
14314 (define_insn "leave_rex64"
14315   [(set (reg:DI 7) (plus:DI (reg:DI 6) (const_int 8)))
14316    (set (reg:DI 6) (mem:DI (reg:DI 6)))
14317    (clobber (mem:BLK (scratch)))]
14318   "TARGET_64BIT"
14319   "leave"
14320   [(set_attr "type" "leave")])
14321 \f
14322 (define_expand "ffssi2"
14323   [(parallel
14324      [(set (match_operand:SI 0 "register_operand" "") 
14325            (ffs:SI (match_operand:SI 1 "nonimmediate_operand" "")))
14326       (clobber (match_scratch:SI 2 ""))
14327       (clobber (reg:CC 17))])]
14328   ""
14329   "")
14330
14331 (define_insn_and_split "*ffs_cmove"
14332   [(set (match_operand:SI 0 "register_operand" "=r") 
14333         (ffs:SI (match_operand:SI 1 "nonimmediate_operand" "rm")))
14334    (clobber (match_scratch:SI 2 "=&r"))
14335    (clobber (reg:CC 17))]
14336   "TARGET_CMOVE"
14337   "#"
14338   "&& reload_completed"
14339   [(set (match_dup 2) (const_int -1))
14340    (parallel [(set (reg:CCZ 17) (compare:CCZ (match_dup 1) (const_int 0)))
14341               (set (match_dup 0) (ctz:SI (match_dup 1)))])
14342    (set (match_dup 0) (if_then_else:SI
14343                         (eq (reg:CCZ 17) (const_int 0))
14344                         (match_dup 2)
14345                         (match_dup 0)))
14346    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 1)))
14347               (clobber (reg:CC 17))])]
14348   "")
14349
14350 (define_insn_and_split "*ffs_no_cmove"
14351   [(set (match_operand:SI 0 "nonimmediate_operand" "=r") 
14352         (ffs:SI (match_operand:SI 1 "nonimmediate_operand" "rm")))
14353    (clobber (match_scratch:SI 2 "=&r"))
14354    (clobber (reg:CC 17))]
14355   ""
14356   "#"
14357   "reload_completed"
14358   [(parallel [(set (match_dup 2) (const_int 0))
14359               (clobber (reg:CC 17))])
14360    (parallel [(set (reg:CCZ 17) (compare:CCZ (match_dup 1) (const_int 0)))
14361               (set (match_dup 0) (ctz:SI (match_dup 1)))])
14362    (set (strict_low_part (match_dup 3))
14363         (eq:QI (reg:CCZ 17) (const_int 0)))
14364    (parallel [(set (match_dup 2) (neg:SI (match_dup 2)))
14365               (clobber (reg:CC 17))])
14366    (parallel [(set (match_dup 0) (ior:SI (match_dup 0) (match_dup 2)))
14367               (clobber (reg:CC 17))])
14368    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 1)))
14369               (clobber (reg:CC 17))])]
14370 {
14371   operands[3] = gen_lowpart (QImode, operands[2]);
14372 })
14373
14374 (define_insn "*ffssi_1"
14375   [(set (reg:CCZ 17)
14376         (compare:CCZ (match_operand:SI 1 "nonimmediate_operand" "rm")
14377                      (const_int 0)))
14378    (set (match_operand:SI 0 "register_operand" "=r")
14379         (ctz:SI (match_dup 1)))]
14380   ""
14381   "bsf{l}\t{%1, %0|%0, %1}"
14382   [(set_attr "prefix_0f" "1")
14383    (set_attr "ppro_uops" "few")])
14384
14385 (define_insn "ctzsi2"
14386   [(set (match_operand:SI 0 "register_operand" "=r")
14387         (ctz:SI (match_operand:SI 1 "nonimmediate_operand" "rm")))
14388    (clobber (reg:CC 17))]
14389   ""
14390   "bsf{l}\t{%1, %0|%0, %1}"
14391   [(set_attr "prefix_0f" "1")
14392    (set_attr "ppro_uops" "few")])
14393
14394 (define_expand "clzsi2"
14395   [(parallel
14396      [(set (match_operand:SI 0 "register_operand" "")
14397            (minus:SI (const_int 31)
14398                      (clz:SI (match_operand:SI 1 "nonimmediate_operand" ""))))
14399       (clobber (reg:CC 17))])
14400    (parallel
14401      [(set (match_dup 0) (xor:SI (match_dup 0) (const_int 31)))
14402       (clobber (reg:CC 17))])]
14403   ""
14404   "")
14405
14406 (define_insn "*bsr"
14407   [(set (match_operand:SI 0 "register_operand" "=r")
14408         (minus:SI (const_int 31)
14409                   (clz:SI (match_operand:SI 1 "nonimmediate_operand" "rm"))))
14410    (clobber (reg:CC 17))]
14411   ""
14412   "bsr{l}\t{%1, %0|%0, %1}"
14413   [(set_attr "prefix_0f" "1")
14414    (set_attr "ppro_uops" "few")])
14415 \f
14416 ;; Thread-local storage patterns for ELF.
14417 ;;
14418 ;; Note that these code sequences must appear exactly as shown
14419 ;; in order to allow linker relaxation.
14420
14421 (define_insn "*tls_global_dynamic_32_gnu"
14422   [(set (match_operand:SI 0 "register_operand" "=a")
14423         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
14424                     (match_operand:SI 2 "tls_symbolic_operand" "")
14425                     (match_operand:SI 3 "call_insn_operand" "")]
14426                     UNSPEC_TLS_GD))
14427    (clobber (match_scratch:SI 4 "=d"))
14428    (clobber (match_scratch:SI 5 "=c"))
14429    (clobber (reg:CC 17))]
14430   "!TARGET_64BIT && TARGET_GNU_TLS"
14431   "lea{l}\t{%a2@TLSGD(,%1,1), %0|%0, %a2@TLSGD[%1*1]}\;call\t%P3"
14432   [(set_attr "type" "multi")
14433    (set_attr "length" "12")])
14434
14435 (define_insn "*tls_global_dynamic_32_sun"
14436   [(set (match_operand:SI 0 "register_operand" "=a")
14437         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
14438                     (match_operand:SI 2 "tls_symbolic_operand" "")
14439                     (match_operand:SI 3 "call_insn_operand" "")]
14440                     UNSPEC_TLS_GD))
14441    (clobber (match_scratch:SI 4 "=d"))
14442    (clobber (match_scratch:SI 5 "=c"))
14443    (clobber (reg:CC 17))]
14444   "!TARGET_64BIT && TARGET_SUN_TLS"
14445   "lea{l}\t{%a2@DTLNDX(%1), %4|%4, %a2@DTLNDX[%1]}
14446         push{l}\t%4\;call\t%a2@TLSPLT\;pop{l}\t%4\;nop"
14447   [(set_attr "type" "multi")
14448    (set_attr "length" "14")])
14449
14450 (define_expand "tls_global_dynamic_32"
14451   [(parallel [(set (match_operand:SI 0 "register_operand" "")
14452                    (unspec:SI
14453                     [(match_dup 2)
14454                      (match_operand:SI 1 "tls_symbolic_operand" "")
14455                      (match_dup 3)]
14456                     UNSPEC_TLS_GD))
14457               (clobber (match_scratch:SI 4 ""))
14458               (clobber (match_scratch:SI 5 ""))
14459               (clobber (reg:CC 17))])]
14460   ""
14461 {
14462   if (flag_pic)
14463     operands[2] = pic_offset_table_rtx;
14464   else
14465     {
14466       operands[2] = gen_reg_rtx (Pmode);
14467       emit_insn (gen_set_got (operands[2]));
14468     }
14469   operands[3] = ix86_tls_get_addr ();
14470 })
14471
14472 (define_insn "*tls_global_dynamic_64"
14473   [(set (match_operand:DI 0 "register_operand" "=a")
14474         (call (mem:QI (match_operand:DI 2 "call_insn_operand" ""))
14475                       (match_operand:DI 3 "" "")))
14476    (unspec:DI [(match_operand:DI 1 "tls_symbolic_operand" "")]
14477               UNSPEC_TLS_GD)]
14478   "TARGET_64BIT"
14479   ".byte\t0x66\;lea{q}\t{%a1@TLSGD(%%rip), %%rdi|%%rdi, %a1@TLSGD[%%rip]}\;.word\t0x6666\;rex64\;call\t%P2"
14480   [(set_attr "type" "multi")
14481    (set_attr "length" "16")])
14482
14483 (define_expand "tls_global_dynamic_64"
14484   [(parallel [(set (match_operand:DI 0 "register_operand" "")
14485                    (call (mem:QI (match_dup 2)) (const_int 0)))
14486               (unspec:DI [(match_operand:DI 1 "tls_symbolic_operand" "")]
14487                          UNSPEC_TLS_GD)])]
14488   ""
14489 {
14490   operands[2] = ix86_tls_get_addr ();
14491 })
14492
14493 (define_insn "*tls_local_dynamic_base_32_gnu"
14494   [(set (match_operand:SI 0 "register_operand" "=a")
14495         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
14496                     (match_operand:SI 2 "call_insn_operand" "")]
14497                    UNSPEC_TLS_LD_BASE))
14498    (clobber (match_scratch:SI 3 "=d"))
14499    (clobber (match_scratch:SI 4 "=c"))
14500    (clobber (reg:CC 17))]
14501   "!TARGET_64BIT && TARGET_GNU_TLS"
14502   "lea{l}\t{%&@TLSLDM(%1), %0|%0, %&@TLSLDM[%1]}\;call\t%P2"
14503   [(set_attr "type" "multi")
14504    (set_attr "length" "11")])
14505
14506 (define_insn "*tls_local_dynamic_base_32_sun"
14507   [(set (match_operand:SI 0 "register_operand" "=a")
14508         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
14509                     (match_operand:SI 2 "call_insn_operand" "")]
14510                    UNSPEC_TLS_LD_BASE))
14511    (clobber (match_scratch:SI 3 "=d"))
14512    (clobber (match_scratch:SI 4 "=c"))
14513    (clobber (reg:CC 17))]
14514   "!TARGET_64BIT && TARGET_SUN_TLS"
14515   "lea{l}\t{%&@TMDNX(%1), %3|%3, %&@TMDNX[%1]}
14516         push{l}\t%3\;call\t%&@TLSPLT\;pop{l}\t%3"
14517   [(set_attr "type" "multi")
14518    (set_attr "length" "13")])
14519
14520 (define_expand "tls_local_dynamic_base_32"
14521   [(parallel [(set (match_operand:SI 0 "register_operand" "")
14522                    (unspec:SI [(match_dup 1) (match_dup 2)]
14523                               UNSPEC_TLS_LD_BASE))
14524               (clobber (match_scratch:SI 3 ""))
14525               (clobber (match_scratch:SI 4 ""))
14526               (clobber (reg:CC 17))])]
14527   ""
14528 {
14529   if (flag_pic)
14530     operands[1] = pic_offset_table_rtx;
14531   else
14532     {
14533       operands[1] = gen_reg_rtx (Pmode);
14534       emit_insn (gen_set_got (operands[1]));
14535     }
14536   operands[2] = ix86_tls_get_addr ();
14537 })
14538
14539 (define_insn "*tls_local_dynamic_base_64"
14540   [(set (match_operand:DI 0 "register_operand" "=a")
14541         (call (mem:QI (match_operand:DI 1 "call_insn_operand" ""))
14542                       (match_operand:DI 2 "" "")))
14543    (unspec:DI [(const_int 0)] UNSPEC_TLS_LD_BASE)]
14544   "TARGET_64BIT"
14545   "lea{q}\t{%&@TLSLD(%%rip), %%rdi|%%rdi, %&@TLSLD[%%rip]}\;call\t%P1"
14546   [(set_attr "type" "multi")
14547    (set_attr "length" "12")])
14548
14549 (define_expand "tls_local_dynamic_base_64"
14550   [(parallel [(set (match_operand:DI 0 "register_operand" "")
14551                    (call (mem:QI (match_dup 1)) (const_int 0)))
14552               (unspec:DI [(const_int 0)] UNSPEC_TLS_LD_BASE)])]
14553   ""
14554 {
14555   operands[1] = ix86_tls_get_addr ();
14556 })
14557
14558 ;; Local dynamic of a single variable is a lose.  Show combine how
14559 ;; to convert that back to global dynamic.
14560
14561 (define_insn_and_split "*tls_local_dynamic_32_once"
14562   [(set (match_operand:SI 0 "register_operand" "=a")
14563         (plus:SI (unspec:SI [(match_operand:SI 1 "register_operand" "b")
14564                              (match_operand:SI 2 "call_insn_operand" "")]
14565                             UNSPEC_TLS_LD_BASE)
14566                  (const:SI (unspec:SI
14567                             [(match_operand:SI 3 "tls_symbolic_operand" "")]
14568                             UNSPEC_DTPOFF))))
14569    (clobber (match_scratch:SI 4 "=d"))
14570    (clobber (match_scratch:SI 5 "=c"))
14571    (clobber (reg:CC 17))]
14572   ""
14573   "#"
14574   ""
14575   [(parallel [(set (match_dup 0)
14576                    (unspec:SI [(match_dup 1) (match_dup 3) (match_dup 2)]
14577                               UNSPEC_TLS_GD))
14578               (clobber (match_dup 4))
14579               (clobber (match_dup 5))
14580               (clobber (reg:CC 17))])]
14581   "")
14582 \f
14583 ;; These patterns match the binary 387 instructions for addM3, subM3,
14584 ;; mulM3 and divM3.  There are three patterns for each of DFmode and
14585 ;; SFmode.  The first is the normal insn, the second the same insn but
14586 ;; with one operand a conversion, and the third the same insn but with
14587 ;; the other operand a conversion.  The conversion may be SFmode or
14588 ;; SImode if the target mode DFmode, but only SImode if the target mode
14589 ;; is SFmode.
14590
14591 ;; Gcc is slightly more smart about handling normal two address instructions
14592 ;; so use special patterns for add and mull.
14593 (define_insn "*fop_sf_comm_nosse"
14594   [(set (match_operand:SF 0 "register_operand" "=f")
14595         (match_operator:SF 3 "binary_fp_operator"
14596                         [(match_operand:SF 1 "nonimmediate_operand" "%0")
14597                          (match_operand:SF 2 "nonimmediate_operand" "fm")]))]
14598   "TARGET_80387 && !TARGET_SSE_MATH
14599    && GET_RTX_CLASS (GET_CODE (operands[3])) == 'c'
14600    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
14601   "* return output_387_binary_op (insn, operands);"
14602   [(set (attr "type") 
14603         (if_then_else (match_operand:SF 3 "mult_operator" "") 
14604            (const_string "fmul")
14605            (const_string "fop")))
14606    (set_attr "mode" "SF")])
14607
14608 (define_insn "*fop_sf_comm"
14609   [(set (match_operand:SF 0 "register_operand" "=f#x,x#f")
14610         (match_operator:SF 3 "binary_fp_operator"
14611                         [(match_operand:SF 1 "nonimmediate_operand" "%0,0")
14612                          (match_operand:SF 2 "nonimmediate_operand" "fm#x,xm#f")]))]
14613   "TARGET_80387 && TARGET_SSE_MATH && TARGET_MIX_SSE_I387
14614    && GET_RTX_CLASS (GET_CODE (operands[3])) == 'c'
14615    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
14616   "* return output_387_binary_op (insn, operands);"
14617   [(set (attr "type") 
14618         (if_then_else (eq_attr "alternative" "1")
14619            (if_then_else (match_operand:SF 3 "mult_operator" "") 
14620               (const_string "ssemul")
14621               (const_string "sseadd"))
14622            (if_then_else (match_operand:SF 3 "mult_operator" "") 
14623               (const_string "fmul")
14624               (const_string "fop"))))
14625    (set_attr "mode" "SF")])
14626
14627 (define_insn "*fop_sf_comm_sse"
14628   [(set (match_operand:SF 0 "register_operand" "=x")
14629         (match_operator:SF 3 "binary_fp_operator"
14630                         [(match_operand:SF 1 "nonimmediate_operand" "%0")
14631                          (match_operand:SF 2 "nonimmediate_operand" "xm")]))]
14632   "TARGET_SSE_MATH && GET_RTX_CLASS (GET_CODE (operands[3])) == 'c'
14633    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
14634   "* return output_387_binary_op (insn, operands);"
14635   [(set (attr "type") 
14636         (if_then_else (match_operand:SF 3 "mult_operator" "") 
14637            (const_string "ssemul")
14638            (const_string "sseadd")))
14639    (set_attr "mode" "SF")])
14640
14641 (define_insn "*fop_df_comm_nosse"
14642   [(set (match_operand:DF 0 "register_operand" "=f")
14643         (match_operator:DF 3 "binary_fp_operator"
14644                         [(match_operand:DF 1 "nonimmediate_operand" "%0")
14645                          (match_operand:DF 2 "nonimmediate_operand" "fm")]))]
14646   "TARGET_80387 && (!TARGET_SSE2 || !TARGET_SSE_MATH)
14647    && GET_RTX_CLASS (GET_CODE (operands[3])) == 'c'
14648    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
14649   "* return output_387_binary_op (insn, operands);"
14650   [(set (attr "type") 
14651         (if_then_else (match_operand:SF 3 "mult_operator" "") 
14652            (const_string "fmul")
14653            (const_string "fop")))
14654    (set_attr "mode" "DF")])
14655
14656 (define_insn "*fop_df_comm"
14657   [(set (match_operand:DF 0 "register_operand" "=f#Y,Y#f")
14658         (match_operator:DF 3 "binary_fp_operator"
14659                         [(match_operand:DF 1 "nonimmediate_operand" "%0,0")
14660                          (match_operand:DF 2 "nonimmediate_operand" "fm#Y,Ym#f")]))]
14661   "TARGET_80387 && TARGET_SSE_MATH && TARGET_SSE2 && TARGET_MIX_SSE_I387
14662    && GET_RTX_CLASS (GET_CODE (operands[3])) == 'c'
14663    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
14664   "* return output_387_binary_op (insn, operands);"
14665   [(set (attr "type") 
14666         (if_then_else (eq_attr "alternative" "1")
14667            (if_then_else (match_operand:SF 3 "mult_operator" "") 
14668               (const_string "ssemul")
14669               (const_string "sseadd"))
14670            (if_then_else (match_operand:SF 3 "mult_operator" "") 
14671               (const_string "fmul")
14672               (const_string "fop"))))
14673    (set_attr "mode" "DF")])
14674
14675 (define_insn "*fop_df_comm_sse"
14676   [(set (match_operand:DF 0 "register_operand" "=Y")
14677         (match_operator:DF 3 "binary_fp_operator"
14678                         [(match_operand:DF 1 "nonimmediate_operand" "%0")
14679                          (match_operand:DF 2 "nonimmediate_operand" "Ym")]))]
14680   "TARGET_SSE2 && TARGET_SSE_MATH
14681    && GET_RTX_CLASS (GET_CODE (operands[3])) == 'c'
14682    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
14683   "* return output_387_binary_op (insn, operands);"
14684   [(set (attr "type") 
14685         (if_then_else (match_operand:SF 3 "mult_operator" "") 
14686            (const_string "ssemul")
14687            (const_string "sseadd")))
14688    (set_attr "mode" "DF")])
14689
14690 (define_insn "*fop_xf_comm"
14691   [(set (match_operand:XF 0 "register_operand" "=f")
14692         (match_operator:XF 3 "binary_fp_operator"
14693                         [(match_operand:XF 1 "register_operand" "%0")
14694                          (match_operand:XF 2 "register_operand" "f")]))]
14695   "!TARGET_64BIT && TARGET_80387
14696    && GET_RTX_CLASS (GET_CODE (operands[3])) == 'c'"
14697   "* return output_387_binary_op (insn, operands);"
14698   [(set (attr "type") 
14699         (if_then_else (match_operand:XF 3 "mult_operator" "") 
14700            (const_string "fmul")
14701            (const_string "fop")))
14702    (set_attr "mode" "XF")])
14703
14704 (define_insn "*fop_tf_comm"
14705   [(set (match_operand:TF 0 "register_operand" "=f")
14706         (match_operator:TF 3 "binary_fp_operator"
14707                         [(match_operand:TF 1 "register_operand" "%0")
14708                          (match_operand:TF 2 "register_operand" "f")]))]
14709   "TARGET_80387 && GET_RTX_CLASS (GET_CODE (operands[3])) == 'c'"
14710   "* return output_387_binary_op (insn, operands);"
14711   [(set (attr "type") 
14712         (if_then_else (match_operand:TF 3 "mult_operator" "") 
14713            (const_string "fmul")
14714            (const_string "fop")))
14715    (set_attr "mode" "XF")])
14716
14717 (define_insn "*fop_sf_1_nosse"
14718   [(set (match_operand:SF 0 "register_operand" "=f,f")
14719         (match_operator:SF 3 "binary_fp_operator"
14720                         [(match_operand:SF 1 "nonimmediate_operand" "0,fm")
14721                          (match_operand:SF 2 "nonimmediate_operand" "fm,0")]))]
14722   "TARGET_80387 && !TARGET_SSE_MATH
14723    && GET_RTX_CLASS (GET_CODE (operands[3])) != 'c'
14724    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
14725   "* return output_387_binary_op (insn, operands);"
14726   [(set (attr "type") 
14727         (cond [(match_operand:SF 3 "mult_operator" "") 
14728                  (const_string "fmul")
14729                (match_operand:SF 3 "div_operator" "") 
14730                  (const_string "fdiv")
14731               ]
14732               (const_string "fop")))
14733    (set_attr "mode" "SF")])
14734
14735 (define_insn "*fop_sf_1"
14736   [(set (match_operand:SF 0 "register_operand" "=f,f,x")
14737         (match_operator:SF 3 "binary_fp_operator"
14738                         [(match_operand:SF 1 "nonimmediate_operand" "0,fm,0")
14739                          (match_operand:SF 2 "nonimmediate_operand" "fm,0,xm#f")]))]
14740   "TARGET_80387 && TARGET_SSE_MATH && TARGET_MIX_SSE_I387
14741    && GET_RTX_CLASS (GET_CODE (operands[3])) != 'c'
14742    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
14743   "* return output_387_binary_op (insn, operands);"
14744   [(set (attr "type") 
14745         (cond [(and (eq_attr "alternative" "2")
14746                     (match_operand:SF 3 "mult_operator" ""))
14747                  (const_string "ssemul")
14748                (and (eq_attr "alternative" "2")
14749                     (match_operand:SF 3 "div_operator" ""))
14750                  (const_string "ssediv")
14751                (eq_attr "alternative" "2")
14752                  (const_string "sseadd")
14753                (match_operand:SF 3 "mult_operator" "") 
14754                  (const_string "fmul")
14755                (match_operand:SF 3 "div_operator" "") 
14756                  (const_string "fdiv")
14757               ]
14758               (const_string "fop")))
14759    (set_attr "mode" "SF")])
14760
14761 (define_insn "*fop_sf_1_sse"
14762   [(set (match_operand:SF 0 "register_operand" "=x")
14763         (match_operator:SF 3 "binary_fp_operator"
14764                         [(match_operand:SF 1 "register_operand" "0")
14765                          (match_operand:SF 2 "nonimmediate_operand" "xm")]))]
14766   "TARGET_SSE_MATH
14767    && GET_RTX_CLASS (GET_CODE (operands[3])) != 'c'"
14768   "* return output_387_binary_op (insn, operands);"
14769   [(set (attr "type") 
14770         (cond [(match_operand:SF 3 "mult_operator" "")
14771                  (const_string "ssemul")
14772                (match_operand:SF 3 "div_operator" "")
14773                  (const_string "ssediv")
14774               ]
14775               (const_string "sseadd")))
14776    (set_attr "mode" "SF")])
14777
14778 ;; ??? Add SSE splitters for these!
14779 (define_insn "*fop_sf_2"
14780   [(set (match_operand:SF 0 "register_operand" "=f,f")
14781         (match_operator:SF 3 "binary_fp_operator"
14782           [(float:SF (match_operand:SI 1 "nonimmediate_operand" "m,?r"))
14783            (match_operand:SF 2 "register_operand" "0,0")]))]
14784   "TARGET_80387 && TARGET_USE_FIOP && !TARGET_SSE_MATH"
14785   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
14786   [(set (attr "type") 
14787         (cond [(match_operand:SF 3 "mult_operator" "") 
14788                  (const_string "fmul")
14789                (match_operand:SF 3 "div_operator" "") 
14790                  (const_string "fdiv")
14791               ]
14792               (const_string "fop")))
14793    (set_attr "fp_int_src" "true")
14794    (set_attr "ppro_uops" "many")
14795    (set_attr "mode" "SI")])
14796
14797 (define_insn "*fop_sf_3"
14798   [(set (match_operand:SF 0 "register_operand" "=f,f")
14799         (match_operator:SF 3 "binary_fp_operator"
14800           [(match_operand:SF 1 "register_operand" "0,0")
14801            (float:SF (match_operand:SI 2 "nonimmediate_operand" "m,?r"))]))]
14802   "TARGET_80387 && TARGET_USE_FIOP && !TARGET_SSE_MATH"
14803   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
14804   [(set (attr "type") 
14805         (cond [(match_operand:SF 3 "mult_operator" "") 
14806                  (const_string "fmul")
14807                (match_operand:SF 3 "div_operator" "") 
14808                  (const_string "fdiv")
14809               ]
14810               (const_string "fop")))
14811    (set_attr "fp_int_src" "true")
14812    (set_attr "ppro_uops" "many")
14813    (set_attr "mode" "SI")])
14814
14815 (define_insn "*fop_df_1_nosse"
14816   [(set (match_operand:DF 0 "register_operand" "=f,f")
14817         (match_operator:DF 3 "binary_fp_operator"
14818                         [(match_operand:DF 1 "nonimmediate_operand" "0,fm")
14819                          (match_operand:DF 2 "nonimmediate_operand" "fm,0")]))]
14820   "TARGET_80387 && (!TARGET_SSE2 || !TARGET_SSE_MATH)
14821    && GET_RTX_CLASS (GET_CODE (operands[3])) != 'c'
14822    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
14823   "* return output_387_binary_op (insn, operands);"
14824   [(set (attr "type") 
14825         (cond [(match_operand:DF 3 "mult_operator" "") 
14826                  (const_string "fmul")
14827                (match_operand:DF 3 "div_operator" "")
14828                  (const_string "fdiv")
14829               ]
14830               (const_string "fop")))
14831    (set_attr "mode" "DF")])
14832
14833
14834 (define_insn "*fop_df_1"
14835   [(set (match_operand:DF 0 "register_operand" "=f#Y,f#Y,Y#f")
14836         (match_operator:DF 3 "binary_fp_operator"
14837                         [(match_operand:DF 1 "nonimmediate_operand" "0,fm,0")
14838                          (match_operand:DF 2 "nonimmediate_operand" "fm,0,Ym#f")]))]
14839   "TARGET_80387 && TARGET_SSE2 && TARGET_SSE_MATH && TARGET_MIX_SSE_I387
14840    && GET_RTX_CLASS (GET_CODE (operands[3])) != 'c'
14841    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
14842   "* return output_387_binary_op (insn, operands);"
14843   [(set (attr "type") 
14844         (cond [(and (eq_attr "alternative" "2")
14845                     (match_operand:SF 3 "mult_operator" ""))
14846                  (const_string "ssemul")
14847                (and (eq_attr "alternative" "2")
14848                     (match_operand:SF 3 "div_operator" ""))
14849                  (const_string "ssediv")
14850                (eq_attr "alternative" "2")
14851                  (const_string "sseadd")
14852                (match_operand:DF 3 "mult_operator" "") 
14853                  (const_string "fmul")
14854                (match_operand:DF 3 "div_operator" "") 
14855                  (const_string "fdiv")
14856               ]
14857               (const_string "fop")))
14858    (set_attr "mode" "DF")])
14859
14860 (define_insn "*fop_df_1_sse"
14861   [(set (match_operand:DF 0 "register_operand" "=Y")
14862         (match_operator:DF 3 "binary_fp_operator"
14863                         [(match_operand:DF 1 "register_operand" "0")
14864                          (match_operand:DF 2 "nonimmediate_operand" "Ym")]))]
14865   "TARGET_SSE2 && TARGET_SSE_MATH
14866    && GET_RTX_CLASS (GET_CODE (operands[3])) != 'c'"
14867   "* return output_387_binary_op (insn, operands);"
14868   [(set_attr "mode" "DF")
14869    (set (attr "type") 
14870         (cond [(match_operand:SF 3 "mult_operator" "")
14871                  (const_string "ssemul")
14872                (match_operand:SF 3 "div_operator" "")
14873                  (const_string "ssediv")
14874               ]
14875               (const_string "sseadd")))])
14876
14877 ;; ??? Add SSE splitters for these!
14878 (define_insn "*fop_df_2"
14879   [(set (match_operand:DF 0 "register_operand" "=f,f")
14880         (match_operator:DF 3 "binary_fp_operator"
14881            [(float:DF (match_operand:SI 1 "nonimmediate_operand" "m,?r"))
14882             (match_operand:DF 2 "register_operand" "0,0")]))]
14883   "TARGET_80387 && TARGET_USE_FIOP && !(TARGET_SSE2 && TARGET_SSE_MATH)"
14884   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
14885   [(set (attr "type") 
14886         (cond [(match_operand:DF 3 "mult_operator" "") 
14887                  (const_string "fmul")
14888                (match_operand:DF 3 "div_operator" "") 
14889                  (const_string "fdiv")
14890               ]
14891               (const_string "fop")))
14892    (set_attr "fp_int_src" "true")
14893    (set_attr "ppro_uops" "many")
14894    (set_attr "mode" "SI")])
14895
14896 (define_insn "*fop_df_3"
14897   [(set (match_operand:DF 0 "register_operand" "=f,f")
14898         (match_operator:DF 3 "binary_fp_operator"
14899            [(match_operand:DF 1 "register_operand" "0,0")
14900             (float:DF (match_operand:SI 2 "nonimmediate_operand" "m,?r"))]))]
14901   "TARGET_80387 && TARGET_USE_FIOP && !(TARGET_SSE2 && TARGET_SSE_MATH)"
14902   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
14903   [(set (attr "type") 
14904         (cond [(match_operand:DF 3 "mult_operator" "") 
14905                  (const_string "fmul")
14906                (match_operand:DF 3 "div_operator" "") 
14907                  (const_string "fdiv")
14908               ]
14909               (const_string "fop")))
14910    (set_attr "fp_int_src" "true")
14911    (set_attr "ppro_uops" "many")
14912    (set_attr "mode" "SI")])
14913
14914 (define_insn "*fop_df_4"
14915   [(set (match_operand:DF 0 "register_operand" "=f,f")
14916         (match_operator:DF 3 "binary_fp_operator"
14917            [(float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "fm,0"))
14918             (match_operand:DF 2 "register_operand" "0,f")]))]
14919   "TARGET_80387 && (!TARGET_SSE2 || !TARGET_SSE_MATH)
14920    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
14921   "* return output_387_binary_op (insn, operands);"
14922   [(set (attr "type") 
14923         (cond [(match_operand:DF 3 "mult_operator" "") 
14924                  (const_string "fmul")
14925                (match_operand:DF 3 "div_operator" "") 
14926                  (const_string "fdiv")
14927               ]
14928               (const_string "fop")))
14929    (set_attr "mode" "SF")])
14930
14931 (define_insn "*fop_df_5"
14932   [(set (match_operand:DF 0 "register_operand" "=f,f")
14933         (match_operator:DF 3 "binary_fp_operator"
14934           [(match_operand:DF 1 "register_operand" "0,f")
14935            (float_extend:DF
14936             (match_operand:SF 2 "nonimmediate_operand" "fm,0"))]))]
14937   "TARGET_80387 && !(TARGET_SSE2 && TARGET_SSE_MATH)"
14938   "* return output_387_binary_op (insn, operands);"
14939   [(set (attr "type") 
14940         (cond [(match_operand:DF 3 "mult_operator" "") 
14941                  (const_string "fmul")
14942                (match_operand:DF 3 "div_operator" "") 
14943                  (const_string "fdiv")
14944               ]
14945               (const_string "fop")))
14946    (set_attr "mode" "SF")])
14947
14948 (define_insn "*fop_df_6"
14949   [(set (match_operand:DF 0 "register_operand" "=f,f")
14950         (match_operator:DF 3 "binary_fp_operator"
14951           [(float_extend:DF
14952             (match_operand:SF 1 "register_operand" "0,f"))
14953            (float_extend:DF
14954             (match_operand:SF 2 "nonimmediate_operand" "fm,0"))]))]
14955   "TARGET_80387 && !(TARGET_SSE2 && TARGET_SSE_MATH)"
14956   "* return output_387_binary_op (insn, operands);"
14957   [(set (attr "type") 
14958         (cond [(match_operand:DF 3 "mult_operator" "") 
14959                  (const_string "fmul")
14960                (match_operand:DF 3 "div_operator" "") 
14961                  (const_string "fdiv")
14962               ]
14963               (const_string "fop")))
14964    (set_attr "mode" "SF")])
14965
14966 (define_insn "*fop_xf_1"
14967   [(set (match_operand:XF 0 "register_operand" "=f,f")
14968         (match_operator:XF 3 "binary_fp_operator"
14969                         [(match_operand:XF 1 "register_operand" "0,f")
14970                          (match_operand:XF 2 "register_operand" "f,0")]))]
14971   "!TARGET_64BIT && TARGET_80387
14972    && GET_RTX_CLASS (GET_CODE (operands[3])) != 'c'"
14973   "* return output_387_binary_op (insn, operands);"
14974   [(set (attr "type") 
14975         (cond [(match_operand:XF 3 "mult_operator" "") 
14976                  (const_string "fmul")
14977                (match_operand:XF 3 "div_operator" "") 
14978                  (const_string "fdiv")
14979               ]
14980               (const_string "fop")))
14981    (set_attr "mode" "XF")])
14982
14983 (define_insn "*fop_tf_1"
14984   [(set (match_operand:TF 0 "register_operand" "=f,f")
14985         (match_operator:TF 3 "binary_fp_operator"
14986                         [(match_operand:TF 1 "register_operand" "0,f")
14987                          (match_operand:TF 2 "register_operand" "f,0")]))]
14988   "TARGET_80387
14989    && GET_RTX_CLASS (GET_CODE (operands[3])) != 'c'"
14990   "* return output_387_binary_op (insn, operands);"
14991   [(set (attr "type") 
14992         (cond [(match_operand:TF 3 "mult_operator" "") 
14993                  (const_string "fmul")
14994                (match_operand:TF 3 "div_operator" "") 
14995                  (const_string "fdiv")
14996               ]
14997               (const_string "fop")))
14998    (set_attr "mode" "XF")])
14999
15000 (define_insn "*fop_xf_2"
15001   [(set (match_operand:XF 0 "register_operand" "=f,f")
15002         (match_operator:XF 3 "binary_fp_operator"
15003            [(float:XF (match_operand:SI 1 "nonimmediate_operand" "m,?r"))
15004             (match_operand:XF 2 "register_operand" "0,0")]))]
15005   "!TARGET_64BIT && TARGET_80387 && TARGET_USE_FIOP"
15006   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
15007   [(set (attr "type") 
15008         (cond [(match_operand:XF 3 "mult_operator" "") 
15009                  (const_string "fmul")
15010                (match_operand:XF 3 "div_operator" "") 
15011                  (const_string "fdiv")
15012               ]
15013               (const_string "fop")))
15014    (set_attr "fp_int_src" "true")
15015    (set_attr "mode" "SI")
15016    (set_attr "ppro_uops" "many")])
15017
15018 (define_insn "*fop_tf_2"
15019   [(set (match_operand:TF 0 "register_operand" "=f,f")
15020         (match_operator:TF 3 "binary_fp_operator"
15021            [(float:TF (match_operand:SI 1 "nonimmediate_operand" "m,?r"))
15022             (match_operand:TF 2 "register_operand" "0,0")]))]
15023   "TARGET_80387 && TARGET_USE_FIOP"
15024   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
15025   [(set (attr "type") 
15026         (cond [(match_operand:TF 3 "mult_operator" "") 
15027                  (const_string "fmul")
15028                (match_operand:TF 3 "div_operator" "") 
15029                  (const_string "fdiv")
15030               ]
15031               (const_string "fop")))
15032    (set_attr "fp_int_src" "true")
15033    (set_attr "mode" "SI")
15034    (set_attr "ppro_uops" "many")])
15035
15036 (define_insn "*fop_xf_3"
15037   [(set (match_operand:XF 0 "register_operand" "=f,f")
15038         (match_operator:XF 3 "binary_fp_operator"
15039           [(match_operand:XF 1 "register_operand" "0,0")
15040            (float:XF (match_operand:SI 2 "nonimmediate_operand" "m,?r"))]))]
15041   "!TARGET_64BIT && TARGET_80387 && TARGET_USE_FIOP"
15042   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
15043   [(set (attr "type") 
15044         (cond [(match_operand:XF 3 "mult_operator" "") 
15045                  (const_string "fmul")
15046                (match_operand:XF 3 "div_operator" "") 
15047                  (const_string "fdiv")
15048               ]
15049               (const_string "fop")))
15050    (set_attr "fp_int_src" "true")
15051    (set_attr "mode" "SI")
15052    (set_attr "ppro_uops" "many")])
15053
15054 (define_insn "*fop_tf_3"
15055   [(set (match_operand:TF 0 "register_operand" "=f,f")
15056         (match_operator:TF 3 "binary_fp_operator"
15057           [(match_operand:TF 1 "register_operand" "0,0")
15058            (float:TF (match_operand:SI 2 "nonimmediate_operand" "m,?r"))]))]
15059   "TARGET_80387 && TARGET_USE_FIOP"
15060   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
15061   [(set (attr "type") 
15062         (cond [(match_operand:TF 3 "mult_operator" "") 
15063                  (const_string "fmul")
15064                (match_operand:TF 3 "div_operator" "") 
15065                  (const_string "fdiv")
15066               ]
15067               (const_string "fop")))
15068    (set_attr "fp_int_src" "true")
15069    (set_attr "mode" "SI")
15070    (set_attr "ppro_uops" "many")])
15071
15072 (define_insn "*fop_xf_4"
15073   [(set (match_operand:XF 0 "register_operand" "=f,f")
15074         (match_operator:XF 3 "binary_fp_operator"
15075            [(float_extend:XF (match_operand 1 "nonimmediate_operand" "fm,0"))
15076             (match_operand:XF 2 "register_operand" "0,f")]))]
15077   "!TARGET_64BIT && TARGET_80387"
15078   "* return output_387_binary_op (insn, operands);"
15079   [(set (attr "type") 
15080         (cond [(match_operand:XF 3 "mult_operator" "") 
15081                  (const_string "fmul")
15082                (match_operand:XF 3 "div_operator" "") 
15083                  (const_string "fdiv")
15084               ]
15085               (const_string "fop")))
15086    (set_attr "mode" "SF")])
15087
15088 (define_insn "*fop_tf_4"
15089   [(set (match_operand:TF 0 "register_operand" "=f,f")
15090         (match_operator:TF 3 "binary_fp_operator"
15091            [(float_extend:TF (match_operand 1 "nonimmediate_operand" "fm,0"))
15092             (match_operand:TF 2 "register_operand" "0,f")]))]
15093   "TARGET_80387"
15094   "* return output_387_binary_op (insn, operands);"
15095   [(set (attr "type") 
15096         (cond [(match_operand:TF 3 "mult_operator" "") 
15097                  (const_string "fmul")
15098                (match_operand:TF 3 "div_operator" "") 
15099                  (const_string "fdiv")
15100               ]
15101               (const_string "fop")))
15102    (set_attr "mode" "SF")])
15103
15104 (define_insn "*fop_xf_5"
15105   [(set (match_operand:XF 0 "register_operand" "=f,f")
15106         (match_operator:XF 3 "binary_fp_operator"
15107           [(match_operand:XF 1 "register_operand" "0,f")
15108            (float_extend:XF
15109             (match_operand 2 "nonimmediate_operand" "fm,0"))]))]
15110   "!TARGET_64BIT && TARGET_80387"
15111   "* return output_387_binary_op (insn, operands);"
15112   [(set (attr "type") 
15113         (cond [(match_operand:XF 3 "mult_operator" "") 
15114                  (const_string "fmul")
15115                (match_operand:XF 3 "div_operator" "") 
15116                  (const_string "fdiv")
15117               ]
15118               (const_string "fop")))
15119    (set_attr "mode" "SF")])
15120
15121 (define_insn "*fop_tf_5"
15122   [(set (match_operand:TF 0 "register_operand" "=f,f")
15123         (match_operator:TF 3 "binary_fp_operator"
15124           [(match_operand:TF 1 "register_operand" "0,f")
15125            (float_extend:TF
15126             (match_operand 2 "nonimmediate_operand" "fm,0"))]))]
15127   "TARGET_80387"
15128   "* return output_387_binary_op (insn, operands);"
15129   [(set (attr "type") 
15130         (cond [(match_operand:TF 3 "mult_operator" "") 
15131                  (const_string "fmul")
15132                (match_operand:TF 3 "div_operator" "") 
15133                  (const_string "fdiv")
15134               ]
15135               (const_string "fop")))
15136    (set_attr "mode" "SF")])
15137
15138 (define_insn "*fop_xf_6"
15139   [(set (match_operand:XF 0 "register_operand" "=f,f")
15140         (match_operator:XF 3 "binary_fp_operator"
15141           [(float_extend:XF
15142             (match_operand 1 "register_operand" "0,f"))
15143            (float_extend:XF
15144             (match_operand 2 "nonimmediate_operand" "fm,0"))]))]
15145   "!TARGET_64BIT && TARGET_80387"
15146   "* return output_387_binary_op (insn, operands);"
15147   [(set (attr "type") 
15148         (cond [(match_operand:XF 3 "mult_operator" "") 
15149                  (const_string "fmul")
15150                (match_operand:XF 3 "div_operator" "") 
15151                  (const_string "fdiv")
15152               ]
15153               (const_string "fop")))
15154    (set_attr "mode" "SF")])
15155
15156 (define_insn "*fop_tf_6"
15157   [(set (match_operand:TF 0 "register_operand" "=f,f")
15158         (match_operator:TF 3 "binary_fp_operator"
15159           [(float_extend:TF
15160             (match_operand 1 "register_operand" "0,f"))
15161            (float_extend:TF
15162             (match_operand 2 "nonimmediate_operand" "fm,0"))]))]
15163   "TARGET_80387"
15164   "* return output_387_binary_op (insn, operands);"
15165   [(set (attr "type") 
15166         (cond [(match_operand:TF 3 "mult_operator" "") 
15167                  (const_string "fmul")
15168                (match_operand:TF 3 "div_operator" "") 
15169                  (const_string "fdiv")
15170               ]
15171               (const_string "fop")))
15172    (set_attr "mode" "SF")])
15173
15174 (define_split
15175   [(set (match_operand 0 "register_operand" "")
15176         (match_operator 3 "binary_fp_operator"
15177            [(float (match_operand:SI 1 "register_operand" ""))
15178             (match_operand 2 "register_operand" "")]))]
15179   "TARGET_80387 && reload_completed
15180    && FLOAT_MODE_P (GET_MODE (operands[0]))"
15181   [(const_int 0)]
15182
15183   operands[4] = ix86_force_to_memory (GET_MODE (operands[1]), operands[1]);
15184   operands[4] = gen_rtx_FLOAT (GET_MODE (operands[0]), operands[4]);
15185   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15186                           gen_rtx_fmt_ee (GET_CODE (operands[3]),
15187                                           GET_MODE (operands[3]),
15188                                           operands[4],
15189                                           operands[2])));
15190   ix86_free_from_memory (GET_MODE (operands[1]));
15191   DONE;
15192 })
15193
15194 (define_split
15195   [(set (match_operand 0 "register_operand" "")
15196         (match_operator 3 "binary_fp_operator"
15197            [(match_operand 1 "register_operand" "")
15198             (float (match_operand:SI 2 "register_operand" ""))]))]
15199   "TARGET_80387 && reload_completed
15200    && FLOAT_MODE_P (GET_MODE (operands[0]))"
15201   [(const_int 0)]
15202 {
15203   operands[4] = ix86_force_to_memory (GET_MODE (operands[2]), operands[2]);
15204   operands[4] = gen_rtx_FLOAT (GET_MODE (operands[0]), operands[4]);
15205   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15206                           gen_rtx_fmt_ee (GET_CODE (operands[3]),
15207                                           GET_MODE (operands[3]),
15208                                           operands[1],
15209                                           operands[4])));
15210   ix86_free_from_memory (GET_MODE (operands[2]));
15211   DONE;
15212 })
15213 \f
15214 ;; FPU special functions.
15215
15216 (define_expand "sqrtsf2"
15217   [(set (match_operand:SF 0 "register_operand" "")
15218         (sqrt:SF (match_operand:SF 1 "nonimmediate_operand" "")))]
15219   "(! TARGET_NO_FANCY_MATH_387 && TARGET_80387) || TARGET_SSE_MATH"
15220 {
15221   if (!TARGET_SSE_MATH)
15222     operands[1] = force_reg (SFmode, operands[1]);
15223 })
15224
15225 (define_insn "sqrtsf2_1"
15226   [(set (match_operand:SF 0 "register_operand" "=f#x,x#f")
15227         (sqrt:SF (match_operand:SF 1 "nonimmediate_operand" "0#x,xm#f")))]
15228   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387
15229    && (TARGET_SSE_MATH && TARGET_MIX_SSE_I387)"
15230   "@
15231    fsqrt
15232    sqrtss\t{%1, %0|%0, %1}"
15233   [(set_attr "type" "fpspc,sse")
15234    (set_attr "mode" "SF,SF")
15235    (set_attr "athlon_decode" "direct,*")])
15236
15237 (define_insn "sqrtsf2_1_sse_only"
15238   [(set (match_operand:SF 0 "register_operand" "=x")
15239         (sqrt:SF (match_operand:SF 1 "nonimmediate_operand" "xm")))]
15240   "TARGET_SSE_MATH && (!TARGET_80387 || !TARGET_MIX_SSE_I387)"
15241   "sqrtss\t{%1, %0|%0, %1}"
15242   [(set_attr "type" "sse")
15243    (set_attr "mode" "SF")
15244    (set_attr "athlon_decode" "*")])
15245
15246 (define_insn "sqrtsf2_i387"
15247   [(set (match_operand:SF 0 "register_operand" "=f")
15248         (sqrt:SF (match_operand:SF 1 "register_operand" "0")))]
15249   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387
15250    && !TARGET_SSE_MATH"
15251   "fsqrt"
15252   [(set_attr "type" "fpspc")
15253    (set_attr "mode" "SF")
15254    (set_attr "athlon_decode" "direct")])
15255
15256 (define_expand "sqrtdf2"
15257   [(set (match_operand:DF 0 "register_operand" "")
15258         (sqrt:DF (match_operand:DF 1 "nonimmediate_operand" "")))]
15259   "(! TARGET_NO_FANCY_MATH_387 && TARGET_80387)
15260    || (TARGET_SSE2 && TARGET_SSE_MATH)"
15261 {
15262   if (!TARGET_SSE2 || !TARGET_SSE_MATH)
15263     operands[1] = force_reg (DFmode, operands[1]);
15264 })
15265
15266 (define_insn "sqrtdf2_1"
15267   [(set (match_operand:DF 0 "register_operand" "=f#Y,Y#f")
15268         (sqrt:DF (match_operand:DF 1 "nonimmediate_operand" "0#Y,Ym#f")))]
15269   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387
15270    && (TARGET_SSE2 && TARGET_SSE_MATH && TARGET_MIX_SSE_I387)"
15271   "@
15272    fsqrt
15273    sqrtsd\t{%1, %0|%0, %1}"
15274   [(set_attr "type" "fpspc,sse")
15275    (set_attr "mode" "DF,DF")
15276    (set_attr "athlon_decode" "direct,*")])
15277
15278 (define_insn "sqrtdf2_1_sse_only"
15279   [(set (match_operand:DF 0 "register_operand" "=Y")
15280         (sqrt:DF (match_operand:DF 1 "nonimmediate_operand" "Ym")))]
15281   "TARGET_SSE2 && TARGET_SSE_MATH && (!TARGET_80387 || !TARGET_MIX_SSE_I387)"
15282   "sqrtsd\t{%1, %0|%0, %1}"
15283   [(set_attr "type" "sse")
15284    (set_attr "mode" "DF")
15285    (set_attr "athlon_decode" "*")])
15286
15287 (define_insn "sqrtdf2_i387"
15288   [(set (match_operand:DF 0 "register_operand" "=f")
15289         (sqrt:DF (match_operand:DF 1 "register_operand" "0")))]
15290   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387
15291    && (!TARGET_SSE2 || !TARGET_SSE_MATH)"
15292   "fsqrt"
15293   [(set_attr "type" "fpspc")
15294    (set_attr "mode" "DF")
15295    (set_attr "athlon_decode" "direct")])
15296
15297 (define_insn "*sqrtextendsfdf2"
15298   [(set (match_operand:DF 0 "register_operand" "=f")
15299         (sqrt:DF (float_extend:DF
15300                   (match_operand:SF 1 "register_operand" "0"))))]
15301   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387
15302    && !(TARGET_SSE2 && TARGET_SSE_MATH)"
15303   "fsqrt"
15304   [(set_attr "type" "fpspc")
15305    (set_attr "mode" "DF")
15306    (set_attr "athlon_decode" "direct")])
15307
15308 (define_insn "sqrtxf2"
15309   [(set (match_operand:XF 0 "register_operand" "=f")
15310         (sqrt:XF (match_operand:XF 1 "register_operand" "0")))]
15311   "!TARGET_64BIT && TARGET_80387 && !TARGET_NO_FANCY_MATH_387 
15312    && (TARGET_IEEE_FP || flag_unsafe_math_optimizations) "
15313   "fsqrt"
15314   [(set_attr "type" "fpspc")
15315    (set_attr "mode" "XF")
15316    (set_attr "athlon_decode" "direct")])
15317
15318 (define_insn "sqrttf2"
15319   [(set (match_operand:TF 0 "register_operand" "=f")
15320         (sqrt:TF (match_operand:TF 1 "register_operand" "0")))]
15321   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 
15322    && (TARGET_IEEE_FP || flag_unsafe_math_optimizations) "
15323   "fsqrt"
15324   [(set_attr "type" "fpspc")
15325    (set_attr "mode" "XF")
15326    (set_attr "athlon_decode" "direct")])
15327
15328 (define_insn "*sqrtextenddfxf2"
15329   [(set (match_operand:XF 0 "register_operand" "=f")
15330         (sqrt:XF (float_extend:XF
15331                   (match_operand:DF 1 "register_operand" "0"))))]
15332   "!TARGET_64BIT && TARGET_80387 && !TARGET_NO_FANCY_MATH_387"
15333   "fsqrt"
15334   [(set_attr "type" "fpspc")
15335    (set_attr "mode" "XF")
15336    (set_attr "athlon_decode" "direct")])
15337
15338 (define_insn "*sqrtextenddftf2"
15339   [(set (match_operand:TF 0 "register_operand" "=f")
15340         (sqrt:TF (float_extend:TF
15341                   (match_operand:DF 1 "register_operand" "0"))))]
15342   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387"
15343   "fsqrt"
15344   [(set_attr "type" "fpspc")
15345    (set_attr "mode" "XF")
15346    (set_attr "athlon_decode" "direct")])
15347
15348 (define_insn "*sqrtextendsfxf2"
15349   [(set (match_operand:XF 0 "register_operand" "=f")
15350         (sqrt:XF (float_extend:XF
15351                   (match_operand:SF 1 "register_operand" "0"))))]
15352   "!TARGET_64BIT && TARGET_80387 && !TARGET_NO_FANCY_MATH_387"
15353   "fsqrt"
15354   [(set_attr "type" "fpspc")
15355    (set_attr "mode" "XF")
15356    (set_attr "athlon_decode" "direct")])
15357
15358 (define_insn "*sqrtextendsftf2"
15359   [(set (match_operand:TF 0 "register_operand" "=f")
15360         (sqrt:TF (float_extend:TF
15361                   (match_operand:SF 1 "register_operand" "0"))))]
15362   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387"
15363   "fsqrt"
15364   [(set_attr "type" "fpspc")
15365    (set_attr "mode" "XF")
15366    (set_attr "athlon_decode" "direct")])
15367
15368 (define_insn "sindf2"
15369   [(set (match_operand:DF 0 "register_operand" "=f")
15370         (unspec:DF [(match_operand:DF 1 "register_operand" "0")] UNSPEC_SIN))]
15371   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 
15372    && flag_unsafe_math_optimizations"
15373   "fsin"
15374   [(set_attr "type" "fpspc")
15375    (set_attr "mode" "DF")])
15376
15377 (define_insn "sinsf2"
15378   [(set (match_operand:SF 0 "register_operand" "=f")
15379         (unspec:SF [(match_operand:SF 1 "register_operand" "0")] UNSPEC_SIN))]
15380   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 
15381    && flag_unsafe_math_optimizations"
15382   "fsin"
15383   [(set_attr "type" "fpspc")
15384    (set_attr "mode" "SF")])
15385
15386 (define_insn "*sinextendsfdf2"
15387   [(set (match_operand:DF 0 "register_operand" "=f")
15388         (unspec:DF [(float_extend:DF
15389                      (match_operand:SF 1 "register_operand" "0"))]
15390                    UNSPEC_SIN))]
15391   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 
15392    && flag_unsafe_math_optimizations"
15393   "fsin"
15394   [(set_attr "type" "fpspc")
15395    (set_attr "mode" "DF")])
15396
15397 (define_insn "sinxf2"
15398   [(set (match_operand:XF 0 "register_operand" "=f")
15399         (unspec:XF [(match_operand:XF 1 "register_operand" "0")] UNSPEC_SIN))]
15400   "!TARGET_64BIT && TARGET_80387 && !TARGET_NO_FANCY_MATH_387
15401    && flag_unsafe_math_optimizations"
15402   "fsin"
15403   [(set_attr "type" "fpspc")
15404    (set_attr "mode" "XF")])
15405
15406 (define_insn "sintf2"
15407   [(set (match_operand:TF 0 "register_operand" "=f")
15408         (unspec:TF [(match_operand:TF 1 "register_operand" "0")] UNSPEC_SIN))]
15409   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 
15410    && flag_unsafe_math_optimizations"
15411   "fsin"
15412   [(set_attr "type" "fpspc")
15413    (set_attr "mode" "XF")])
15414
15415 (define_insn "cosdf2"
15416   [(set (match_operand:DF 0 "register_operand" "=f")
15417         (unspec:DF [(match_operand:DF 1 "register_operand" "0")] UNSPEC_COS))]
15418   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 
15419    && flag_unsafe_math_optimizations"
15420   "fcos"
15421   [(set_attr "type" "fpspc")
15422    (set_attr "mode" "DF")])
15423
15424 (define_insn "cossf2"
15425   [(set (match_operand:SF 0 "register_operand" "=f")
15426         (unspec:SF [(match_operand:SF 1 "register_operand" "0")] UNSPEC_COS))]
15427   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 
15428    && flag_unsafe_math_optimizations"
15429   "fcos"
15430   [(set_attr "type" "fpspc")
15431    (set_attr "mode" "SF")])
15432
15433 (define_insn "*cosextendsfdf2"
15434   [(set (match_operand:DF 0 "register_operand" "=f")
15435         (unspec:DF [(float_extend:DF
15436                      (match_operand:SF 1 "register_operand" "0"))]
15437                    UNSPEC_COS))]
15438   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 
15439    && flag_unsafe_math_optimizations"
15440   "fcos"
15441   [(set_attr "type" "fpspc")
15442    (set_attr "mode" "DF")])
15443
15444 (define_insn "cosxf2"
15445   [(set (match_operand:XF 0 "register_operand" "=f")
15446         (unspec:XF [(match_operand:XF 1 "register_operand" "0")] UNSPEC_COS))]
15447   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387
15448    && flag_unsafe_math_optimizations"
15449   "fcos"
15450   [(set_attr "type" "fpspc")
15451    (set_attr "mode" "XF")])
15452
15453 (define_insn "costf2"
15454   [(set (match_operand:TF 0 "register_operand" "=f")
15455         (unspec:TF [(match_operand:TF 1 "register_operand" "0")] UNSPEC_COS))]
15456   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 
15457    && flag_unsafe_math_optimizations"
15458   "fcos"
15459   [(set_attr "type" "fpspc")
15460    (set_attr "mode" "XF")])
15461 \f
15462 ;; Block operation instructions
15463
15464 (define_insn "cld"
15465  [(set (reg:SI 19) (const_int 0))]
15466  ""
15467  "cld"
15468   [(set_attr "type" "cld")])
15469
15470 (define_expand "movstrsi"
15471   [(use (match_operand:BLK 0 "memory_operand" ""))
15472    (use (match_operand:BLK 1 "memory_operand" ""))
15473    (use (match_operand:SI 2 "nonmemory_operand" ""))
15474    (use (match_operand:SI 3 "const_int_operand" ""))]
15475   ""
15476 {
15477  if (ix86_expand_movstr (operands[0], operands[1], operands[2], operands[3]))
15478    DONE;
15479  else
15480    FAIL;
15481 })
15482
15483 (define_expand "movstrdi"
15484   [(use (match_operand:BLK 0 "memory_operand" ""))
15485    (use (match_operand:BLK 1 "memory_operand" ""))
15486    (use (match_operand:DI 2 "nonmemory_operand" ""))
15487    (use (match_operand:DI 3 "const_int_operand" ""))]
15488   "TARGET_64BIT"
15489 {
15490  if (ix86_expand_movstr (operands[0], operands[1], operands[2], operands[3]))
15491    DONE;
15492  else
15493    FAIL;
15494 })
15495
15496 ;; Most CPUs don't like single string operations
15497 ;; Handle this case here to simplify previous expander.
15498
15499 (define_expand "strmovdi_rex64"
15500   [(set (match_dup 2)
15501         (mem:DI (match_operand:DI 1 "register_operand" "")))
15502    (set (mem:DI (match_operand:DI 0 "register_operand" ""))
15503         (match_dup 2))
15504    (parallel [(set (match_dup 0) (plus:DI (match_dup 0) (const_int 8)))
15505               (clobber (reg:CC 17))])
15506    (parallel [(set (match_dup 1) (plus:DI (match_dup 1) (const_int 8)))
15507               (clobber (reg:CC 17))])]
15508   "TARGET_64BIT"
15509 {
15510   if (TARGET_SINGLE_STRINGOP || optimize_size)
15511     {
15512       emit_insn (gen_strmovdi_rex_1 (operands[0], operands[1], operands[0],
15513                                      operands[1]));
15514       DONE;
15515     }
15516   else 
15517     operands[2] = gen_reg_rtx (DImode);
15518 })
15519
15520
15521 (define_expand "strmovsi"
15522   [(set (match_dup 2)
15523         (mem:SI (match_operand:SI 1 "register_operand" "")))
15524    (set (mem:SI (match_operand:SI 0 "register_operand" ""))
15525         (match_dup 2))
15526    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 4)))
15527               (clobber (reg:CC 17))])
15528    (parallel [(set (match_dup 1) (plus:SI (match_dup 1) (const_int 4)))
15529               (clobber (reg:CC 17))])]
15530   ""
15531 {
15532   if (TARGET_64BIT)
15533     {
15534       emit_insn (gen_strmovsi_rex64 (operands[0], operands[1]));
15535       DONE;
15536     }
15537   if (TARGET_SINGLE_STRINGOP || optimize_size)
15538     {
15539       emit_insn (gen_strmovsi_1 (operands[0], operands[1], operands[0],
15540                                 operands[1]));
15541       DONE;
15542     }
15543   else 
15544     operands[2] = gen_reg_rtx (SImode);
15545 })
15546
15547 (define_expand "strmovsi_rex64"
15548   [(set (match_dup 2)
15549         (mem:SI (match_operand:DI 1 "register_operand" "")))
15550    (set (mem:SI (match_operand:DI 0 "register_operand" ""))
15551         (match_dup 2))
15552    (parallel [(set (match_dup 0) (plus:DI (match_dup 0) (const_int 4)))
15553               (clobber (reg:CC 17))])
15554    (parallel [(set (match_dup 1) (plus:DI (match_dup 1) (const_int 4)))
15555               (clobber (reg:CC 17))])]
15556   "TARGET_64BIT"
15557 {
15558   if (TARGET_SINGLE_STRINGOP || optimize_size)
15559     {
15560       emit_insn (gen_strmovsi_rex_1 (operands[0], operands[1], operands[0],
15561                                      operands[1]));
15562       DONE;
15563     }
15564   else 
15565     operands[2] = gen_reg_rtx (SImode);
15566 })
15567
15568 (define_expand "strmovhi"
15569   [(set (match_dup 2)
15570         (mem:HI (match_operand:SI 1 "register_operand" "")))
15571    (set (mem:HI (match_operand:SI 0 "register_operand" ""))
15572         (match_dup 2))
15573    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 2)))
15574               (clobber (reg:CC 17))])
15575    (parallel [(set (match_dup 1) (plus:SI (match_dup 1) (const_int 2)))
15576               (clobber (reg:CC 17))])]
15577   ""
15578 {
15579   if (TARGET_64BIT)
15580     {
15581       emit_insn (gen_strmovhi_rex64 (operands[0], operands[1]));
15582       DONE;
15583     }
15584   if (TARGET_SINGLE_STRINGOP || optimize_size)
15585     {
15586       emit_insn (gen_strmovhi_1 (operands[0], operands[1], operands[0],
15587                                 operands[1]));
15588       DONE;
15589     }
15590   else 
15591     operands[2] = gen_reg_rtx (HImode);
15592 })
15593
15594 (define_expand "strmovhi_rex64"
15595   [(set (match_dup 2)
15596         (mem:HI (match_operand:DI 1 "register_operand" "")))
15597    (set (mem:HI (match_operand:DI 0 "register_operand" ""))
15598         (match_dup 2))
15599    (parallel [(set (match_dup 0) (plus:DI (match_dup 0) (const_int 2)))
15600               (clobber (reg:CC 17))])
15601    (parallel [(set (match_dup 1) (plus:DI (match_dup 1) (const_int 2)))
15602               (clobber (reg:CC 17))])]
15603   "TARGET_64BIT"
15604 {
15605   if (TARGET_SINGLE_STRINGOP || optimize_size)
15606     {
15607       emit_insn (gen_strmovhi_rex_1 (operands[0], operands[1], operands[0],
15608                                      operands[1]));
15609       DONE;
15610     }
15611   else 
15612     operands[2] = gen_reg_rtx (HImode);
15613 })
15614
15615 (define_expand "strmovqi"
15616   [(set (match_dup 2)
15617         (mem:QI (match_operand:SI 1 "register_operand" "")))
15618    (set (mem:QI (match_operand:SI 0 "register_operand" ""))
15619         (match_dup 2))
15620    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 1)))
15621               (clobber (reg:CC 17))])
15622    (parallel [(set (match_dup 1) (plus:SI (match_dup 1) (const_int 1)))
15623               (clobber (reg:CC 17))])]
15624   ""
15625 {
15626   if (TARGET_64BIT)
15627     {
15628       emit_insn (gen_strmovqi_rex64 (operands[0], operands[1]));
15629       DONE;
15630     }
15631   if (TARGET_SINGLE_STRINGOP || optimize_size)
15632     {
15633       emit_insn (gen_strmovqi_1 (operands[0], operands[1], operands[0],
15634                                 operands[1]));
15635       DONE;
15636     }
15637   else 
15638     operands[2] = gen_reg_rtx (QImode);
15639 })
15640
15641 (define_expand "strmovqi_rex64"
15642   [(set (match_dup 2)
15643         (mem:QI (match_operand:DI 1 "register_operand" "")))
15644    (set (mem:QI (match_operand:DI 0 "register_operand" ""))
15645         (match_dup 2))
15646    (parallel [(set (match_dup 0) (plus:DI (match_dup 0) (const_int 1)))
15647               (clobber (reg:CC 17))])
15648    (parallel [(set (match_dup 1) (plus:DI (match_dup 1) (const_int 1)))
15649               (clobber (reg:CC 17))])]
15650   "TARGET_64BIT"
15651 {
15652   if (TARGET_SINGLE_STRINGOP || optimize_size)
15653     {
15654       emit_insn (gen_strmovqi_rex_1 (operands[0], operands[1], operands[0],
15655                                      operands[1]));
15656       DONE;
15657     }
15658   else 
15659     operands[2] = gen_reg_rtx (QImode);
15660 })
15661
15662 (define_insn "strmovdi_rex_1"
15663   [(set (mem:DI (match_operand:DI 2 "register_operand" "0"))
15664         (mem:DI (match_operand:DI 3 "register_operand" "1")))
15665    (set (match_operand:DI 0 "register_operand" "=D")
15666         (plus:DI (match_dup 2)
15667                  (const_int 8)))
15668    (set (match_operand:DI 1 "register_operand" "=S")
15669         (plus:DI (match_dup 3)
15670                  (const_int 8)))
15671    (use (reg:SI 19))]
15672   "TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
15673   "movsq"
15674   [(set_attr "type" "str")
15675    (set_attr "mode" "DI")
15676    (set_attr "memory" "both")])
15677
15678 (define_insn "strmovsi_1"
15679   [(set (mem:SI (match_operand:SI 2 "register_operand" "0"))
15680         (mem:SI (match_operand:SI 3 "register_operand" "1")))
15681    (set (match_operand:SI 0 "register_operand" "=D")
15682         (plus:SI (match_dup 2)
15683                  (const_int 4)))
15684    (set (match_operand:SI 1 "register_operand" "=S")
15685         (plus:SI (match_dup 3)
15686                  (const_int 4)))
15687    (use (reg:SI 19))]
15688   "!TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
15689   "{movsl|movsd}"
15690   [(set_attr "type" "str")
15691    (set_attr "mode" "SI")
15692    (set_attr "memory" "both")])
15693
15694 (define_insn "strmovsi_rex_1"
15695   [(set (mem:SI (match_operand:DI 2 "register_operand" "0"))
15696         (mem:SI (match_operand:DI 3 "register_operand" "1")))
15697    (set (match_operand:DI 0 "register_operand" "=D")
15698         (plus:DI (match_dup 2)
15699                  (const_int 4)))
15700    (set (match_operand:DI 1 "register_operand" "=S")
15701         (plus:DI (match_dup 3)
15702                  (const_int 4)))
15703    (use (reg:SI 19))]
15704   "TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
15705   "{movsl|movsd}"
15706   [(set_attr "type" "str")
15707    (set_attr "mode" "SI")
15708    (set_attr "memory" "both")])
15709
15710 (define_insn "strmovhi_1"
15711   [(set (mem:HI (match_operand:SI 2 "register_operand" "0"))
15712         (mem:HI (match_operand:SI 3 "register_operand" "1")))
15713    (set (match_operand:SI 0 "register_operand" "=D")
15714         (plus:SI (match_dup 2)
15715                  (const_int 2)))
15716    (set (match_operand:SI 1 "register_operand" "=S")
15717         (plus:SI (match_dup 3)
15718                  (const_int 2)))
15719    (use (reg:SI 19))]
15720   "!TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
15721   "movsw"
15722   [(set_attr "type" "str")
15723    (set_attr "memory" "both")
15724    (set_attr "mode" "HI")])
15725
15726 (define_insn "strmovhi_rex_1"
15727   [(set (mem:HI (match_operand:DI 2 "register_operand" "0"))
15728         (mem:HI (match_operand:DI 3 "register_operand" "1")))
15729    (set (match_operand:DI 0 "register_operand" "=D")
15730         (plus:DI (match_dup 2)
15731                  (const_int 2)))
15732    (set (match_operand:DI 1 "register_operand" "=S")
15733         (plus:DI (match_dup 3)
15734                  (const_int 2)))
15735    (use (reg:SI 19))]
15736   "TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
15737   "movsw"
15738   [(set_attr "type" "str")
15739    (set_attr "memory" "both")
15740    (set_attr "mode" "HI")])
15741
15742 (define_insn "strmovqi_1"
15743   [(set (mem:QI (match_operand:SI 2 "register_operand" "0"))
15744         (mem:QI (match_operand:SI 3 "register_operand" "1")))
15745    (set (match_operand:SI 0 "register_operand" "=D")
15746         (plus:SI (match_dup 2)
15747                  (const_int 1)))
15748    (set (match_operand:SI 1 "register_operand" "=S")
15749         (plus:SI (match_dup 3)
15750                  (const_int 1)))
15751    (use (reg:SI 19))]
15752   "!TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
15753   "movsb"
15754   [(set_attr "type" "str")
15755    (set_attr "memory" "both")
15756    (set_attr "mode" "QI")])
15757
15758 (define_insn "strmovqi_rex_1"
15759   [(set (mem:QI (match_operand:DI 2 "register_operand" "0"))
15760         (mem:QI (match_operand:DI 3 "register_operand" "1")))
15761    (set (match_operand:DI 0 "register_operand" "=D")
15762         (plus:DI (match_dup 2)
15763                  (const_int 1)))
15764    (set (match_operand:DI 1 "register_operand" "=S")
15765         (plus:DI (match_dup 3)
15766                  (const_int 1)))
15767    (use (reg:SI 19))]
15768   "TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
15769   "movsb"
15770   [(set_attr "type" "str")
15771    (set_attr "memory" "both")
15772    (set_attr "mode" "QI")])
15773
15774 (define_insn "rep_movdi_rex64"
15775   [(set (match_operand:DI 2 "register_operand" "=c") (const_int 0))
15776    (set (match_operand:DI 0 "register_operand" "=D") 
15777         (plus:DI (ashift:DI (match_operand:DI 5 "register_operand" "2")
15778                             (const_int 3))
15779                  (match_operand:DI 3 "register_operand" "0")))
15780    (set (match_operand:DI 1 "register_operand" "=S") 
15781         (plus:DI (ashift:DI (match_dup 5) (const_int 3))
15782                  (match_operand:DI 4 "register_operand" "1")))
15783    (set (mem:BLK (match_dup 3))
15784         (mem:BLK (match_dup 4)))
15785    (use (match_dup 5))
15786    (use (reg:SI 19))]
15787   "TARGET_64BIT"
15788   "{rep\;movsq|rep movsq}"
15789   [(set_attr "type" "str")
15790    (set_attr "prefix_rep" "1")
15791    (set_attr "memory" "both")
15792    (set_attr "mode" "DI")])
15793
15794 (define_insn "rep_movsi"
15795   [(set (match_operand:SI 2 "register_operand" "=c") (const_int 0))
15796    (set (match_operand:SI 0 "register_operand" "=D") 
15797         (plus:SI (ashift:SI (match_operand:SI 5 "register_operand" "2")
15798                             (const_int 2))
15799                  (match_operand:SI 3 "register_operand" "0")))
15800    (set (match_operand:SI 1 "register_operand" "=S") 
15801         (plus:SI (ashift:SI (match_dup 5) (const_int 2))
15802                  (match_operand:SI 4 "register_operand" "1")))
15803    (set (mem:BLK (match_dup 3))
15804         (mem:BLK (match_dup 4)))
15805    (use (match_dup 5))
15806    (use (reg:SI 19))]
15807   "!TARGET_64BIT"
15808   "{rep\;movsl|rep movsd}"
15809   [(set_attr "type" "str")
15810    (set_attr "prefix_rep" "1")
15811    (set_attr "memory" "both")
15812    (set_attr "mode" "SI")])
15813
15814 (define_insn "rep_movsi_rex64"
15815   [(set (match_operand:DI 2 "register_operand" "=c") (const_int 0))
15816    (set (match_operand:DI 0 "register_operand" "=D") 
15817         (plus:DI (ashift:DI (match_operand:DI 5 "register_operand" "2")
15818                             (const_int 2))
15819                  (match_operand:DI 3 "register_operand" "0")))
15820    (set (match_operand:DI 1 "register_operand" "=S") 
15821         (plus:DI (ashift:DI (match_dup 5) (const_int 2))
15822                  (match_operand:DI 4 "register_operand" "1")))
15823    (set (mem:BLK (match_dup 3))
15824         (mem:BLK (match_dup 4)))
15825    (use (match_dup 5))
15826    (use (reg:SI 19))]
15827   "TARGET_64BIT"
15828   "{rep\;movsl|rep movsd}"
15829   [(set_attr "type" "str")
15830    (set_attr "prefix_rep" "1")
15831    (set_attr "memory" "both")
15832    (set_attr "mode" "SI")])
15833
15834 (define_insn "rep_movqi"
15835   [(set (match_operand:SI 2 "register_operand" "=c") (const_int 0))
15836    (set (match_operand:SI 0 "register_operand" "=D") 
15837         (plus:SI (match_operand:SI 3 "register_operand" "0")
15838                  (match_operand:SI 5 "register_operand" "2")))
15839    (set (match_operand:SI 1 "register_operand" "=S") 
15840         (plus:SI (match_operand:SI 4 "register_operand" "1") (match_dup 5)))
15841    (set (mem:BLK (match_dup 3))
15842         (mem:BLK (match_dup 4)))
15843    (use (match_dup 5))
15844    (use (reg:SI 19))]
15845   "!TARGET_64BIT"
15846   "{rep\;movsb|rep movsb}"
15847   [(set_attr "type" "str")
15848    (set_attr "prefix_rep" "1")
15849    (set_attr "memory" "both")
15850    (set_attr "mode" "SI")])
15851
15852 (define_insn "rep_movqi_rex64"
15853   [(set (match_operand:DI 2 "register_operand" "=c") (const_int 0))
15854    (set (match_operand:DI 0 "register_operand" "=D") 
15855         (plus:DI (match_operand:DI 3 "register_operand" "0")
15856                  (match_operand:DI 5 "register_operand" "2")))
15857    (set (match_operand:DI 1 "register_operand" "=S") 
15858         (plus:DI (match_operand:DI 4 "register_operand" "1") (match_dup 5)))
15859    (set (mem:BLK (match_dup 3))
15860         (mem:BLK (match_dup 4)))
15861    (use (match_dup 5))
15862    (use (reg:SI 19))]
15863   "TARGET_64BIT"
15864   "{rep\;movsb|rep movsb}"
15865   [(set_attr "type" "str")
15866    (set_attr "prefix_rep" "1")
15867    (set_attr "memory" "both")
15868    (set_attr "mode" "SI")])
15869
15870 (define_expand "clrstrsi"
15871    [(use (match_operand:BLK 0 "memory_operand" ""))
15872     (use (match_operand:SI 1 "nonmemory_operand" ""))
15873     (use (match_operand 2 "const_int_operand" ""))]
15874   ""
15875 {
15876  if (ix86_expand_clrstr (operands[0], operands[1], operands[2]))
15877    DONE;
15878  else
15879    FAIL;
15880 })
15881
15882 (define_expand "clrstrdi"
15883    [(use (match_operand:BLK 0 "memory_operand" ""))
15884     (use (match_operand:DI 1 "nonmemory_operand" ""))
15885     (use (match_operand 2 "const_int_operand" ""))]
15886   "TARGET_64BIT"
15887 {
15888  if (ix86_expand_clrstr (operands[0], operands[1], operands[2]))
15889    DONE;
15890  else
15891    FAIL;
15892 })
15893
15894 ;; Most CPUs don't like single string operations
15895 ;; Handle this case here to simplify previous expander.
15896
15897 (define_expand "strsetdi_rex64"
15898   [(set (mem:DI (match_operand:DI 0 "register_operand" ""))
15899         (match_operand:DI 1 "register_operand" ""))
15900    (parallel [(set (match_dup 0) (plus:DI (match_dup 0) (const_int 8)))
15901               (clobber (reg:CC 17))])]
15902   "TARGET_64BIT"
15903 {
15904   if (TARGET_SINGLE_STRINGOP || optimize_size)
15905     {
15906       emit_insn (gen_strsetdi_rex_1 (operands[0], operands[0], operands[1]));
15907       DONE;
15908     }
15909 })
15910
15911 (define_expand "strsetsi"
15912   [(set (mem:SI (match_operand:SI 0 "register_operand" ""))
15913         (match_operand:SI 1 "register_operand" ""))
15914    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 4)))
15915               (clobber (reg:CC 17))])]
15916   ""
15917 {
15918   if (TARGET_64BIT)
15919     {
15920       emit_insn (gen_strsetsi_rex64 (operands[0], operands[1]));
15921       DONE;
15922     }
15923   else if (TARGET_SINGLE_STRINGOP || optimize_size)
15924     {
15925       emit_insn (gen_strsetsi_1 (operands[0], operands[0], operands[1]));
15926       DONE;
15927     }
15928 })
15929
15930 (define_expand "strsetsi_rex64"
15931   [(set (mem:SI (match_operand:DI 0 "register_operand" ""))
15932         (match_operand:SI 1 "register_operand" ""))
15933    (parallel [(set (match_dup 0) (plus:DI (match_dup 0) (const_int 4)))
15934               (clobber (reg:CC 17))])]
15935   "TARGET_64BIT"
15936 {
15937   if (TARGET_SINGLE_STRINGOP || optimize_size)
15938     {
15939       emit_insn (gen_strsetsi_rex_1 (operands[0], operands[0], operands[1]));
15940       DONE;
15941     }
15942 })
15943
15944 (define_expand "strsethi"
15945   [(set (mem:HI (match_operand:SI 0 "register_operand" ""))
15946         (match_operand:HI 1 "register_operand" ""))
15947    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 2)))
15948               (clobber (reg:CC 17))])]
15949   ""
15950 {
15951   if (TARGET_64BIT)
15952     {
15953       emit_insn (gen_strsethi_rex64 (operands[0], operands[1]));
15954       DONE;
15955     }
15956   else if (TARGET_SINGLE_STRINGOP || optimize_size)
15957     {
15958       emit_insn (gen_strsethi_1 (operands[0], operands[0], operands[1]));
15959       DONE;
15960     }
15961 })
15962
15963 (define_expand "strsethi_rex64"
15964   [(set (mem:HI (match_operand:DI 0 "register_operand" ""))
15965         (match_operand:HI 1 "register_operand" ""))
15966    (parallel [(set (match_dup 0) (plus:DI (match_dup 0) (const_int 2)))
15967               (clobber (reg:CC 17))])]
15968   "TARGET_64BIT"
15969 {
15970   if (TARGET_SINGLE_STRINGOP || optimize_size)
15971     {
15972       emit_insn (gen_strsethi_rex_1 (operands[0], operands[0], operands[1]));
15973       DONE;
15974     }
15975 })
15976
15977 (define_expand "strsetqi"
15978   [(set (mem:QI (match_operand:SI 0 "register_operand" ""))
15979         (match_operand:QI 1 "register_operand" ""))
15980    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 1)))
15981               (clobber (reg:CC 17))])]
15982   ""
15983 {
15984   if (TARGET_64BIT)
15985     {
15986       emit_insn (gen_strsetqi_rex64 (operands[0], operands[1]));
15987       DONE;
15988     }
15989   else if (TARGET_SINGLE_STRINGOP || optimize_size)
15990     {
15991       emit_insn (gen_strsetqi_1 (operands[0], operands[0], operands[1]));
15992       DONE;
15993     }
15994 })
15995
15996 (define_expand "strsetqi_rex64"
15997   [(set (mem:QI (match_operand:DI 0 "register_operand" ""))
15998         (match_operand:QI 1 "register_operand" ""))
15999    (parallel [(set (match_dup 0) (plus:DI (match_dup 0) (const_int 1)))
16000               (clobber (reg:CC 17))])]
16001   "TARGET_64BIT"
16002 {
16003   if (TARGET_SINGLE_STRINGOP || optimize_size)
16004     {
16005       emit_insn (gen_strsetqi_rex_1 (operands[0], operands[0], operands[1]));
16006       DONE;
16007     }
16008 })
16009
16010 (define_insn "strsetdi_rex_1"
16011   [(set (mem:SI (match_operand:DI 1 "register_operand" "0"))
16012         (match_operand:SI 2 "register_operand" "a"))
16013    (set (match_operand:DI 0 "register_operand" "=D")
16014         (plus:DI (match_dup 1)
16015                  (const_int 8)))
16016    (use (reg:SI 19))]
16017   "TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
16018   "stosq"
16019   [(set_attr "type" "str")
16020    (set_attr "memory" "store")
16021    (set_attr "mode" "DI")])
16022
16023 (define_insn "strsetsi_1"
16024   [(set (mem:SI (match_operand:SI 1 "register_operand" "0"))
16025         (match_operand:SI 2 "register_operand" "a"))
16026    (set (match_operand:SI 0 "register_operand" "=D")
16027         (plus:SI (match_dup 1)
16028                  (const_int 4)))
16029    (use (reg:SI 19))]
16030   "!TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
16031   "{stosl|stosd}"
16032   [(set_attr "type" "str")
16033    (set_attr "memory" "store")
16034    (set_attr "mode" "SI")])
16035
16036 (define_insn "strsetsi_rex_1"
16037   [(set (mem:SI (match_operand:DI 1 "register_operand" "0"))
16038         (match_operand:SI 2 "register_operand" "a"))
16039    (set (match_operand:DI 0 "register_operand" "=D")
16040         (plus:DI (match_dup 1)
16041                  (const_int 4)))
16042    (use (reg:SI 19))]
16043   "TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
16044   "{stosl|stosd}"
16045   [(set_attr "type" "str")
16046    (set_attr "memory" "store")
16047    (set_attr "mode" "SI")])
16048
16049 (define_insn "strsethi_1"
16050   [(set (mem:HI (match_operand:SI 1 "register_operand" "0"))
16051         (match_operand:HI 2 "register_operand" "a"))
16052    (set (match_operand:SI 0 "register_operand" "=D")
16053         (plus:SI (match_dup 1)
16054                  (const_int 2)))
16055    (use (reg:SI 19))]
16056   "!TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
16057   "stosw"
16058   [(set_attr "type" "str")
16059    (set_attr "memory" "store")
16060    (set_attr "mode" "HI")])
16061
16062 (define_insn "strsethi_rex_1"
16063   [(set (mem:HI (match_operand:DI 1 "register_operand" "0"))
16064         (match_operand:HI 2 "register_operand" "a"))
16065    (set (match_operand:DI 0 "register_operand" "=D")
16066         (plus:DI (match_dup 1)
16067                  (const_int 2)))
16068    (use (reg:SI 19))]
16069   "TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
16070   "stosw"
16071   [(set_attr "type" "str")
16072    (set_attr "memory" "store")
16073    (set_attr "mode" "HI")])
16074
16075 (define_insn "strsetqi_1"
16076   [(set (mem:QI (match_operand:SI 1 "register_operand" "0"))
16077         (match_operand:QI 2 "register_operand" "a"))
16078    (set (match_operand:SI 0 "register_operand" "=D")
16079         (plus:SI (match_dup 1)
16080                  (const_int 1)))
16081    (use (reg:SI 19))]
16082   "!TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
16083   "stosb"
16084   [(set_attr "type" "str")
16085    (set_attr "memory" "store")
16086    (set_attr "mode" "QI")])
16087
16088 (define_insn "strsetqi_rex_1"
16089   [(set (mem:QI (match_operand:DI 1 "register_operand" "0"))
16090         (match_operand:QI 2 "register_operand" "a"))
16091    (set (match_operand:DI 0 "register_operand" "=D")
16092         (plus:DI (match_dup 1)
16093                  (const_int 1)))
16094    (use (reg:SI 19))]
16095   "TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
16096   "stosb"
16097   [(set_attr "type" "str")
16098    (set_attr "memory" "store")
16099    (set_attr "mode" "QI")])
16100
16101 (define_insn "rep_stosdi_rex64"
16102   [(set (match_operand:DI 1 "register_operand" "=c") (const_int 0))
16103    (set (match_operand:DI 0 "register_operand" "=D") 
16104         (plus:DI (ashift:DI (match_operand:DI 4 "register_operand" "1")
16105                             (const_int 3))
16106                  (match_operand:DI 3 "register_operand" "0")))
16107    (set (mem:BLK (match_dup 3))
16108         (const_int 0))
16109    (use (match_operand:DI 2 "register_operand" "a"))
16110    (use (match_dup 4))
16111    (use (reg:SI 19))]
16112   "TARGET_64BIT"
16113   "{rep\;stosq|rep stosq}"
16114   [(set_attr "type" "str")
16115    (set_attr "prefix_rep" "1")
16116    (set_attr "memory" "store")
16117    (set_attr "mode" "DI")])
16118
16119 (define_insn "rep_stossi"
16120   [(set (match_operand:SI 1 "register_operand" "=c") (const_int 0))
16121    (set (match_operand:SI 0 "register_operand" "=D") 
16122         (plus:SI (ashift:SI (match_operand:SI 4 "register_operand" "1")
16123                             (const_int 2))
16124                  (match_operand:SI 3 "register_operand" "0")))
16125    (set (mem:BLK (match_dup 3))
16126         (const_int 0))
16127    (use (match_operand:SI 2 "register_operand" "a"))
16128    (use (match_dup 4))
16129    (use (reg:SI 19))]
16130   "!TARGET_64BIT"
16131   "{rep\;stosl|rep stosd}"
16132   [(set_attr "type" "str")
16133    (set_attr "prefix_rep" "1")
16134    (set_attr "memory" "store")
16135    (set_attr "mode" "SI")])
16136
16137 (define_insn "rep_stossi_rex64"
16138   [(set (match_operand:DI 1 "register_operand" "=c") (const_int 0))
16139    (set (match_operand:DI 0 "register_operand" "=D") 
16140         (plus:DI (ashift:DI (match_operand:DI 4 "register_operand" "1")
16141                             (const_int 2))
16142                  (match_operand:DI 3 "register_operand" "0")))
16143    (set (mem:BLK (match_dup 3))
16144         (const_int 0))
16145    (use (match_operand:SI 2 "register_operand" "a"))
16146    (use (match_dup 4))
16147    (use (reg:SI 19))]
16148   "TARGET_64BIT"
16149   "{rep\;stosl|rep stosd}"
16150   [(set_attr "type" "str")
16151    (set_attr "prefix_rep" "1")
16152    (set_attr "memory" "store")
16153    (set_attr "mode" "SI")])
16154
16155 (define_insn "rep_stosqi"
16156   [(set (match_operand:SI 1 "register_operand" "=c") (const_int 0))
16157    (set (match_operand:SI 0 "register_operand" "=D") 
16158         (plus:SI (match_operand:SI 3 "register_operand" "0")
16159                  (match_operand:SI 4 "register_operand" "1")))
16160    (set (mem:BLK (match_dup 3))
16161         (const_int 0))
16162    (use (match_operand:QI 2 "register_operand" "a"))
16163    (use (match_dup 4))
16164    (use (reg:SI 19))]
16165   "!TARGET_64BIT"
16166   "{rep\;stosb|rep stosb}"
16167   [(set_attr "type" "str")
16168    (set_attr "prefix_rep" "1")
16169    (set_attr "memory" "store")
16170    (set_attr "mode" "QI")])
16171
16172 (define_insn "rep_stosqi_rex64"
16173   [(set (match_operand:DI 1 "register_operand" "=c") (const_int 0))
16174    (set (match_operand:DI 0 "register_operand" "=D") 
16175         (plus:DI (match_operand:DI 3 "register_operand" "0")
16176                  (match_operand:DI 4 "register_operand" "1")))
16177    (set (mem:BLK (match_dup 3))
16178         (const_int 0))
16179    (use (match_operand:QI 2 "register_operand" "a"))
16180    (use (match_dup 4))
16181    (use (reg:DI 19))]
16182   "TARGET_64BIT"
16183   "{rep\;stosb|rep stosb}"
16184   [(set_attr "type" "str")
16185    (set_attr "prefix_rep" "1")
16186    (set_attr "memory" "store")
16187    (set_attr "mode" "QI")])
16188
16189 (define_expand "cmpstrsi"
16190   [(set (match_operand:SI 0 "register_operand" "")
16191         (compare:SI (match_operand:BLK 1 "general_operand" "")
16192                     (match_operand:BLK 2 "general_operand" "")))
16193    (use (match_operand 3 "general_operand" ""))
16194    (use (match_operand 4 "immediate_operand" ""))]
16195   ""
16196 {
16197   rtx addr1, addr2, out, outlow, count, countreg, align;
16198
16199   out = operands[0];
16200   if (GET_CODE (out) != REG)
16201     out = gen_reg_rtx (SImode);
16202
16203   addr1 = copy_to_mode_reg (Pmode, XEXP (operands[1], 0));
16204   addr2 = copy_to_mode_reg (Pmode, XEXP (operands[2], 0));
16205   
16206   count = operands[3];
16207   countreg = ix86_zero_extend_to_Pmode (count);
16208
16209   /* %%% Iff we are testing strict equality, we can use known alignment
16210      to good advantage.  This may be possible with combine, particularly
16211      once cc0 is dead.  */
16212   align = operands[4];
16213
16214   emit_insn (gen_cld ());
16215   if (GET_CODE (count) == CONST_INT)
16216     {
16217       if (INTVAL (count) == 0)
16218         {
16219           emit_move_insn (operands[0], const0_rtx);
16220           DONE;
16221         }
16222       if (TARGET_64BIT)
16223         emit_insn (gen_cmpstrqi_nz_rex_1 (addr1, addr2, countreg, align,
16224                                           addr1, addr2, countreg));
16225       else
16226         emit_insn (gen_cmpstrqi_nz_1 (addr1, addr2, countreg, align,
16227                                       addr1, addr2, countreg));
16228     }
16229   else
16230     {
16231       if (TARGET_64BIT)
16232         {
16233           emit_insn (gen_cmpdi_1_rex64 (countreg, countreg));
16234           emit_insn (gen_cmpstrqi_rex_1 (addr1, addr2, countreg, align,
16235                                          addr1, addr2, countreg));
16236         }
16237       else
16238         {
16239           emit_insn (gen_cmpsi_1 (countreg, countreg));
16240           emit_insn (gen_cmpstrqi_1 (addr1, addr2, countreg, align,
16241                                      addr1, addr2, countreg));
16242         }
16243     }
16244
16245   outlow = gen_lowpart (QImode, out);
16246   emit_insn (gen_cmpintqi (outlow));
16247   emit_move_insn (out, gen_rtx_SIGN_EXTEND (SImode, outlow));
16248
16249   if (operands[0] != out)
16250     emit_move_insn (operands[0], out);
16251
16252   DONE;
16253 })
16254
16255 ;; Produce a tri-state integer (-1, 0, 1) from condition codes.
16256
16257 (define_expand "cmpintqi"
16258   [(set (match_dup 1)
16259         (gtu:QI (reg:CC 17) (const_int 0)))
16260    (set (match_dup 2)
16261         (ltu:QI (reg:CC 17) (const_int 0)))
16262    (parallel [(set (match_operand:QI 0 "register_operand" "")
16263                    (minus:QI (match_dup 1)
16264                              (match_dup 2)))
16265               (clobber (reg:CC 17))])]
16266   ""
16267   "operands[1] = gen_reg_rtx (QImode);
16268    operands[2] = gen_reg_rtx (QImode);")
16269
16270 ;; memcmp recognizers.  The `cmpsb' opcode does nothing if the count is
16271 ;; zero.  Emit extra code to make sure that a zero-length compare is EQ.
16272
16273 (define_insn "cmpstrqi_nz_1"
16274   [(set (reg:CC 17)
16275         (compare:CC (mem:BLK (match_operand:SI 4 "register_operand" "0"))
16276                     (mem:BLK (match_operand:SI 5 "register_operand" "1"))))
16277    (use (match_operand:SI 6 "register_operand" "2"))
16278    (use (match_operand:SI 3 "immediate_operand" "i"))
16279    (use (reg:SI 19))
16280    (clobber (match_operand:SI 0 "register_operand" "=S"))
16281    (clobber (match_operand:SI 1 "register_operand" "=D"))
16282    (clobber (match_operand:SI 2 "register_operand" "=c"))]
16283   "!TARGET_64BIT"
16284   "repz{\;| }cmpsb"
16285   [(set_attr "type" "str")
16286    (set_attr "mode" "QI")
16287    (set_attr "prefix_rep" "1")])
16288
16289 (define_insn "cmpstrqi_nz_rex_1"
16290   [(set (reg:CC 17)
16291         (compare:CC (mem:BLK (match_operand:DI 4 "register_operand" "0"))
16292                     (mem:BLK (match_operand:DI 5 "register_operand" "1"))))
16293    (use (match_operand:DI 6 "register_operand" "2"))
16294    (use (match_operand:SI 3 "immediate_operand" "i"))
16295    (use (reg:SI 19))
16296    (clobber (match_operand:DI 0 "register_operand" "=S"))
16297    (clobber (match_operand:DI 1 "register_operand" "=D"))
16298    (clobber (match_operand:DI 2 "register_operand" "=c"))]
16299   "TARGET_64BIT"
16300   "repz{\;| }cmpsb"
16301   [(set_attr "type" "str")
16302    (set_attr "mode" "QI")
16303    (set_attr "prefix_rep" "1")])
16304
16305 ;; The same, but the count is not known to not be zero.
16306
16307 (define_insn "cmpstrqi_1"
16308   [(set (reg:CC 17)
16309         (if_then_else:CC (ne (match_operand:SI 6 "register_operand" "2")
16310                              (const_int 0))
16311           (compare:CC (mem:BLK (match_operand:SI 4 "register_operand" "0"))
16312                       (mem:BLK (match_operand:SI 5 "register_operand" "1")))
16313           (const_int 0)))
16314    (use (match_operand:SI 3 "immediate_operand" "i"))
16315    (use (reg:CC 17))
16316    (use (reg:SI 19))
16317    (clobber (match_operand:SI 0 "register_operand" "=S"))
16318    (clobber (match_operand:SI 1 "register_operand" "=D"))
16319    (clobber (match_operand:SI 2 "register_operand" "=c"))]
16320   "!TARGET_64BIT"
16321   "repz{\;| }cmpsb"
16322   [(set_attr "type" "str")
16323    (set_attr "mode" "QI")
16324    (set_attr "prefix_rep" "1")])
16325
16326 (define_insn "cmpstrqi_rex_1"
16327   [(set (reg:CC 17)
16328         (if_then_else:CC (ne (match_operand:DI 6 "register_operand" "2")
16329                              (const_int 0))
16330           (compare:CC (mem:BLK (match_operand:DI 4 "register_operand" "0"))
16331                       (mem:BLK (match_operand:DI 5 "register_operand" "1")))
16332           (const_int 0)))
16333    (use (match_operand:SI 3 "immediate_operand" "i"))
16334    (use (reg:CC 17))
16335    (use (reg:SI 19))
16336    (clobber (match_operand:DI 0 "register_operand" "=S"))
16337    (clobber (match_operand:DI 1 "register_operand" "=D"))
16338    (clobber (match_operand:DI 2 "register_operand" "=c"))]
16339   "TARGET_64BIT"
16340   "repz{\;| }cmpsb"
16341   [(set_attr "type" "str")
16342    (set_attr "mode" "QI")
16343    (set_attr "prefix_rep" "1")])
16344
16345 (define_expand "strlensi"
16346   [(set (match_operand:SI 0 "register_operand" "")
16347         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
16348                     (match_operand:QI 2 "immediate_operand" "")
16349                     (match_operand 3 "immediate_operand" "")] UNSPEC_SCAS))]
16350   ""
16351 {
16352  if (ix86_expand_strlen (operands[0], operands[1], operands[2], operands[3]))
16353    DONE;
16354  else
16355    FAIL;
16356 })
16357
16358 (define_expand "strlendi"
16359   [(set (match_operand:DI 0 "register_operand" "")
16360         (unspec:DI [(match_operand:BLK 1 "general_operand" "")
16361                     (match_operand:QI 2 "immediate_operand" "")
16362                     (match_operand 3 "immediate_operand" "")] UNSPEC_SCAS))]
16363   ""
16364 {
16365  if (ix86_expand_strlen (operands[0], operands[1], operands[2], operands[3]))
16366    DONE;
16367  else
16368    FAIL;
16369 })
16370
16371 (define_insn "strlenqi_1"
16372   [(set (match_operand:SI 0 "register_operand" "=&c")
16373         (unspec:SI [(mem:BLK (match_operand:SI 5 "register_operand" "1"))
16374                     (match_operand:QI 2 "register_operand" "a")
16375                     (match_operand:SI 3 "immediate_operand" "i")
16376                     (match_operand:SI 4 "register_operand" "0")] UNSPEC_SCAS))
16377    (use (reg:SI 19))
16378    (clobber (match_operand:SI 1 "register_operand" "=D"))
16379    (clobber (reg:CC 17))]
16380   "!TARGET_64BIT"
16381   "repnz{\;| }scasb"
16382   [(set_attr "type" "str")
16383    (set_attr "mode" "QI")
16384    (set_attr "prefix_rep" "1")])
16385
16386 (define_insn "strlenqi_rex_1"
16387   [(set (match_operand:DI 0 "register_operand" "=&c")
16388         (unspec:DI [(mem:BLK (match_operand:DI 5 "register_operand" "1"))
16389                     (match_operand:QI 2 "register_operand" "a")
16390                     (match_operand:DI 3 "immediate_operand" "i")
16391                     (match_operand:DI 4 "register_operand" "0")] UNSPEC_SCAS))
16392    (use (reg:SI 19))
16393    (clobber (match_operand:DI 1 "register_operand" "=D"))
16394    (clobber (reg:CC 17))]
16395   "TARGET_64BIT"
16396   "repnz{\;| }scasb"
16397   [(set_attr "type" "str")
16398    (set_attr "mode" "QI")
16399    (set_attr "prefix_rep" "1")])
16400
16401 ;; Peephole optimizations to clean up after cmpstr*.  This should be
16402 ;; handled in combine, but it is not currently up to the task.
16403 ;; When used for their truth value, the cmpstr* expanders generate
16404 ;; code like this:
16405 ;;
16406 ;;   repz cmpsb
16407 ;;   seta       %al
16408 ;;   setb       %dl
16409 ;;   cmpb       %al, %dl
16410 ;;   jcc        label
16411 ;;
16412 ;; The intermediate three instructions are unnecessary.
16413
16414 ;; This one handles cmpstr*_nz_1...
16415 (define_peephole2
16416   [(parallel[
16417      (set (reg:CC 17)
16418           (compare:CC (mem:BLK (match_operand 4 "register_operand" ""))
16419                       (mem:BLK (match_operand 5 "register_operand" ""))))
16420      (use (match_operand 6 "register_operand" ""))
16421      (use (match_operand:SI 3 "immediate_operand" ""))
16422      (use (reg:SI 19))
16423      (clobber (match_operand 0 "register_operand" ""))
16424      (clobber (match_operand 1 "register_operand" ""))
16425      (clobber (match_operand 2 "register_operand" ""))])
16426    (set (match_operand:QI 7 "register_operand" "")
16427         (gtu:QI (reg:CC 17) (const_int 0)))
16428    (set (match_operand:QI 8 "register_operand" "")
16429         (ltu:QI (reg:CC 17) (const_int 0)))
16430    (set (reg 17)
16431         (compare (match_dup 7) (match_dup 8)))
16432   ]
16433   "peep2_reg_dead_p (4, operands[7]) && peep2_reg_dead_p (4, operands[8])"
16434   [(parallel[
16435      (set (reg:CC 17)
16436           (compare:CC (mem:BLK (match_dup 4))
16437                       (mem:BLK (match_dup 5))))
16438      (use (match_dup 6))
16439      (use (match_dup 3))
16440      (use (reg:SI 19))
16441      (clobber (match_dup 0))
16442      (clobber (match_dup 1))
16443      (clobber (match_dup 2))])]
16444   "")
16445
16446 ;; ...and this one handles cmpstr*_1.
16447 (define_peephole2
16448   [(parallel[
16449      (set (reg:CC 17)
16450           (if_then_else:CC (ne (match_operand 6 "register_operand" "")
16451                                (const_int 0))
16452             (compare:CC (mem:BLK (match_operand 4 "register_operand" ""))
16453                         (mem:BLK (match_operand 5 "register_operand" "")))
16454             (const_int 0)))
16455      (use (match_operand:SI 3 "immediate_operand" ""))
16456      (use (reg:CC 17))
16457      (use (reg:SI 19))
16458      (clobber (match_operand 0 "register_operand" ""))
16459      (clobber (match_operand 1 "register_operand" ""))
16460      (clobber (match_operand 2 "register_operand" ""))])
16461    (set (match_operand:QI 7 "register_operand" "")
16462         (gtu:QI (reg:CC 17) (const_int 0)))
16463    (set (match_operand:QI 8 "register_operand" "")
16464         (ltu:QI (reg:CC 17) (const_int 0)))
16465    (set (reg 17)
16466         (compare (match_dup 7) (match_dup 8)))
16467   ]
16468   "peep2_reg_dead_p (4, operands[7]) && peep2_reg_dead_p (4, operands[8])"
16469   [(parallel[
16470      (set (reg:CC 17)
16471           (if_then_else:CC (ne (match_dup 6)
16472                                (const_int 0))
16473             (compare:CC (mem:BLK (match_dup 4))
16474                         (mem:BLK (match_dup 5)))
16475             (const_int 0)))
16476      (use (match_dup 3))
16477      (use (reg:CC 17))
16478      (use (reg:SI 19))
16479      (clobber (match_dup 0))
16480      (clobber (match_dup 1))
16481      (clobber (match_dup 2))])]
16482   "")
16483
16484
16485 \f
16486 ;; Conditional move instructions.
16487
16488 (define_expand "movdicc"
16489   [(set (match_operand:DI 0 "register_operand" "")
16490         (if_then_else:DI (match_operand 1 "comparison_operator" "")
16491                          (match_operand:DI 2 "general_operand" "")
16492                          (match_operand:DI 3 "general_operand" "")))]
16493   "TARGET_64BIT"
16494   "if (!ix86_expand_int_movcc (operands)) FAIL; DONE;")
16495
16496 (define_insn "x86_movdicc_0_m1_rex64"
16497   [(set (match_operand:DI 0 "register_operand" "=r")
16498         (if_then_else:DI (match_operand 1 "ix86_carry_flag_operator" "")
16499           (const_int -1)
16500           (const_int 0)))
16501    (clobber (reg:CC 17))]
16502   "TARGET_64BIT"
16503   "sbb{q}\t%0, %0"
16504   ; Since we don't have the proper number of operands for an alu insn,
16505   ; fill in all the blanks.
16506   [(set_attr "type" "alu")
16507    (set_attr "pent_pair" "pu")
16508    (set_attr "memory" "none")
16509    (set_attr "imm_disp" "false")
16510    (set_attr "mode" "DI")
16511    (set_attr "length_immediate" "0")])
16512
16513 (define_insn "movdicc_c_rex64"
16514   [(set (match_operand:DI 0 "register_operand" "=r,r")
16515         (if_then_else:DI (match_operator 1 "ix86_comparison_operator" 
16516                                 [(reg 17) (const_int 0)])
16517                       (match_operand:DI 2 "nonimmediate_operand" "rm,0")
16518                       (match_operand:DI 3 "nonimmediate_operand" "0,rm")))]
16519   "TARGET_64BIT && TARGET_CMOVE
16520    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)"
16521   "@
16522    cmov%O2%C1\t{%2, %0|%0, %2}
16523    cmov%O2%c1\t{%3, %0|%0, %3}"
16524   [(set_attr "type" "icmov")
16525    (set_attr "mode" "DI")])
16526
16527 (define_expand "movsicc"
16528   [(set (match_operand:SI 0 "register_operand" "")
16529         (if_then_else:SI (match_operand 1 "comparison_operator" "")
16530                          (match_operand:SI 2 "general_operand" "")
16531                          (match_operand:SI 3 "general_operand" "")))]
16532   ""
16533   "if (!ix86_expand_int_movcc (operands)) FAIL; DONE;")
16534
16535 ;; Data flow gets confused by our desire for `sbbl reg,reg', and clearing
16536 ;; the register first winds up with `sbbl $0,reg', which is also weird.
16537 ;; So just document what we're doing explicitly.
16538
16539 (define_insn "x86_movsicc_0_m1"
16540   [(set (match_operand:SI 0 "register_operand" "=r")
16541         (if_then_else:SI (match_operand 1 "ix86_carry_flag_operator" "")
16542           (const_int -1)
16543           (const_int 0)))
16544    (clobber (reg:CC 17))]
16545   ""
16546   "sbb{l}\t%0, %0"
16547   ; Since we don't have the proper number of operands for an alu insn,
16548   ; fill in all the blanks.
16549   [(set_attr "type" "alu")
16550    (set_attr "pent_pair" "pu")
16551    (set_attr "memory" "none")
16552    (set_attr "imm_disp" "false")
16553    (set_attr "mode" "SI")
16554    (set_attr "length_immediate" "0")])
16555
16556 (define_insn "*movsicc_noc"
16557   [(set (match_operand:SI 0 "register_operand" "=r,r")
16558         (if_then_else:SI (match_operator 1 "ix86_comparison_operator" 
16559                                 [(reg 17) (const_int 0)])
16560                       (match_operand:SI 2 "nonimmediate_operand" "rm,0")
16561                       (match_operand:SI 3 "nonimmediate_operand" "0,rm")))]
16562   "TARGET_CMOVE
16563    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)"
16564   "@
16565    cmov%O2%C1\t{%2, %0|%0, %2}
16566    cmov%O2%c1\t{%3, %0|%0, %3}"
16567   [(set_attr "type" "icmov")
16568    (set_attr "mode" "SI")])
16569
16570 (define_expand "movhicc"
16571   [(set (match_operand:HI 0 "register_operand" "")
16572         (if_then_else:HI (match_operand 1 "comparison_operator" "")
16573                          (match_operand:HI 2 "general_operand" "")
16574                          (match_operand:HI 3 "general_operand" "")))]
16575   "TARGET_HIMODE_MATH"
16576   "if (!ix86_expand_int_movcc (operands)) FAIL; DONE;")
16577
16578 (define_insn "*movhicc_noc"
16579   [(set (match_operand:HI 0 "register_operand" "=r,r")
16580         (if_then_else:HI (match_operator 1 "ix86_comparison_operator" 
16581                                 [(reg 17) (const_int 0)])
16582                       (match_operand:HI 2 "nonimmediate_operand" "rm,0")
16583                       (match_operand:HI 3 "nonimmediate_operand" "0,rm")))]
16584   "TARGET_CMOVE
16585    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)"
16586   "@
16587    cmov%O2%C1\t{%2, %0|%0, %2}
16588    cmov%O2%c1\t{%3, %0|%0, %3}"
16589   [(set_attr "type" "icmov")
16590    (set_attr "mode" "HI")])
16591
16592 (define_expand "movqicc"
16593   [(set (match_operand:QI 0 "register_operand" "")
16594         (if_then_else:QI (match_operand 1 "comparison_operator" "")
16595                          (match_operand:QI 2 "general_operand" "")
16596                          (match_operand:QI 3 "general_operand" "")))]
16597   "TARGET_QIMODE_MATH"
16598   "if (!ix86_expand_int_movcc (operands)) FAIL; DONE;")
16599
16600 (define_insn_and_split "*movqicc_noc"
16601   [(set (match_operand:QI 0 "register_operand" "=r,r")
16602         (if_then_else:QI (match_operator 1 "ix86_comparison_operator" 
16603                                 [(match_operand 4 "flags_reg_operand" "") (const_int 0)])
16604                       (match_operand:QI 2 "register_operand" "r,0")
16605                       (match_operand:QI 3 "register_operand" "0,r")))]
16606   "TARGET_CMOVE && !TARGET_PARTIAL_REG_STALL"
16607   "#"
16608   "&& reload_completed"
16609   [(set (match_dup 0)
16610         (if_then_else:SI (match_op_dup 1 [(match_dup 4) (const_int 0)])
16611                       (match_dup 2)
16612                       (match_dup 3)))]
16613   "operands[0] = gen_lowpart (SImode, operands[0]);
16614    operands[2] = gen_lowpart (SImode, operands[2]);
16615    operands[3] = gen_lowpart (SImode, operands[3]);"
16616   [(set_attr "type" "icmov")
16617    (set_attr "mode" "SI")])
16618
16619 (define_expand "movsfcc"
16620   [(set (match_operand:SF 0 "register_operand" "")
16621         (if_then_else:SF (match_operand 1 "comparison_operator" "")
16622                          (match_operand:SF 2 "register_operand" "")
16623                          (match_operand:SF 3 "register_operand" "")))]
16624   "TARGET_CMOVE"
16625   "if (! ix86_expand_fp_movcc (operands)) FAIL; DONE;")
16626
16627 (define_insn "*movsfcc_1"
16628   [(set (match_operand:SF 0 "register_operand" "=f,f,r,r")
16629         (if_then_else:SF (match_operator 1 "fcmov_comparison_operator" 
16630                                 [(reg 17) (const_int 0)])
16631                       (match_operand:SF 2 "nonimmediate_operand" "f,0,rm,0")
16632                       (match_operand:SF 3 "nonimmediate_operand" "0,f,0,rm")))]
16633   "TARGET_CMOVE
16634    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)"
16635   "@
16636    fcmov%F1\t{%2, %0|%0, %2}
16637    fcmov%f1\t{%3, %0|%0, %3}
16638    cmov%O2%C1\t{%2, %0|%0, %2}
16639    cmov%O2%c1\t{%3, %0|%0, %3}"
16640   [(set_attr "type" "fcmov,fcmov,icmov,icmov")
16641    (set_attr "mode" "SF,SF,SI,SI")])
16642
16643 (define_expand "movdfcc"
16644   [(set (match_operand:DF 0 "register_operand" "")
16645         (if_then_else:DF (match_operand 1 "comparison_operator" "")
16646                          (match_operand:DF 2 "register_operand" "")
16647                          (match_operand:DF 3 "register_operand" "")))]
16648   "TARGET_CMOVE"
16649   "if (! ix86_expand_fp_movcc (operands)) FAIL; DONE;")
16650
16651 (define_insn "*movdfcc_1"
16652   [(set (match_operand:DF 0 "register_operand" "=f,f,&r,&r")
16653         (if_then_else:DF (match_operator 1 "fcmov_comparison_operator" 
16654                                 [(reg 17) (const_int 0)])
16655                       (match_operand:DF 2 "nonimmediate_operand" "f,0,rm,0")
16656                       (match_operand:DF 3 "nonimmediate_operand" "0,f,0,rm")))]
16657   "!TARGET_64BIT && TARGET_CMOVE
16658    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)"
16659   "@
16660    fcmov%F1\t{%2, %0|%0, %2}
16661    fcmov%f1\t{%3, %0|%0, %3}
16662    #
16663    #"
16664   [(set_attr "type" "fcmov,fcmov,multi,multi")
16665    (set_attr "mode" "DF")])
16666
16667 (define_insn "*movdfcc_1_rex64"
16668   [(set (match_operand:DF 0 "register_operand" "=f,f,&r,&r")
16669         (if_then_else:DF (match_operator 1 "fcmov_comparison_operator" 
16670                                 [(reg 17) (const_int 0)])
16671                       (match_operand:DF 2 "nonimmediate_operand" "f,0,rm,0")
16672                       (match_operand:DF 3 "nonimmediate_operand" "0,f,0,rm")))]
16673   "TARGET_64BIT && TARGET_CMOVE
16674    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)"
16675   "@
16676    fcmov%F1\t{%2, %0|%0, %2}
16677    fcmov%f1\t{%3, %0|%0, %3}
16678    cmov%O2%C1\t{%2, %0|%0, %2}
16679    cmov%O2%c1\t{%3, %0|%0, %3}"
16680   [(set_attr "type" "fcmov,fcmov,icmov,icmov")
16681    (set_attr "mode" "DF")])
16682
16683 (define_split
16684   [(set (match_operand:DF 0 "register_and_not_any_fp_reg_operand" "")
16685         (if_then_else:DF (match_operator 1 "fcmov_comparison_operator" 
16686                                 [(match_operand 4 "flags_reg_operand" "") (const_int 0)])
16687                       (match_operand:DF 2 "nonimmediate_operand" "")
16688                       (match_operand:DF 3 "nonimmediate_operand" "")))]
16689   "!TARGET_64BIT && reload_completed"
16690   [(set (match_dup 2)
16691         (if_then_else:SI (match_op_dup 1 [(match_dup 4) (const_int 0)])
16692                       (match_dup 5)
16693                       (match_dup 7)))
16694    (set (match_dup 3)
16695         (if_then_else:SI (match_op_dup 1 [(match_dup 4) (const_int 0)])
16696                       (match_dup 6)
16697                       (match_dup 8)))]
16698   "split_di (operands+2, 1, operands+5, operands+6);
16699    split_di (operands+3, 1, operands+7, operands+8);
16700    split_di (operands, 1, operands+2, operands+3);")
16701
16702 (define_expand "movxfcc"
16703   [(set (match_operand:XF 0 "register_operand" "")
16704         (if_then_else:XF (match_operand 1 "comparison_operator" "")
16705                          (match_operand:XF 2 "register_operand" "")
16706                          (match_operand:XF 3 "register_operand" "")))]
16707   "!TARGET_64BIT && TARGET_CMOVE"
16708   "if (! ix86_expand_fp_movcc (operands)) FAIL; DONE;")
16709
16710 (define_expand "movtfcc"
16711   [(set (match_operand:TF 0 "register_operand" "")
16712         (if_then_else:TF (match_operand 1 "comparison_operator" "")
16713                          (match_operand:TF 2 "register_operand" "")
16714                          (match_operand:TF 3 "register_operand" "")))]
16715   "TARGET_CMOVE"
16716   "if (! ix86_expand_fp_movcc (operands)) FAIL; DONE;")
16717
16718 (define_insn "*movxfcc_1"
16719   [(set (match_operand:XF 0 "register_operand" "=f,f")
16720         (if_then_else:XF (match_operator 1 "fcmov_comparison_operator" 
16721                                 [(reg 17) (const_int 0)])
16722                       (match_operand:XF 2 "register_operand" "f,0")
16723                       (match_operand:XF 3 "register_operand" "0,f")))]
16724   "!TARGET_64BIT && TARGET_CMOVE"
16725   "@
16726    fcmov%F1\t{%2, %0|%0, %2}
16727    fcmov%f1\t{%3, %0|%0, %3}"
16728   [(set_attr "type" "fcmov")
16729    (set_attr "mode" "XF")])
16730
16731 (define_insn "*movtfcc_1"
16732   [(set (match_operand:TF 0 "register_operand" "=f,f")
16733         (if_then_else:TF (match_operator 1 "fcmov_comparison_operator" 
16734                                 [(reg 17) (const_int 0)])
16735                       (match_operand:TF 2 "register_operand" "f,0")
16736                       (match_operand:TF 3 "register_operand" "0,f")))]
16737   "TARGET_CMOVE"
16738   "@
16739    fcmov%F1\t{%2, %0|%0, %2}
16740    fcmov%f1\t{%3, %0|%0, %3}"
16741   [(set_attr "type" "fcmov")
16742    (set_attr "mode" "XF")])
16743
16744 (define_expand "minsf3"
16745   [(parallel [
16746      (set (match_operand:SF 0 "register_operand" "")
16747           (if_then_else:SF (lt (match_operand:SF 1 "register_operand" "")
16748                                (match_operand:SF 2 "nonimmediate_operand" ""))
16749                            (match_dup 1)
16750                            (match_dup 2)))
16751      (clobber (reg:CC 17))])]
16752   "TARGET_SSE"
16753   "")
16754
16755 (define_insn "*minsf"
16756   [(set (match_operand:SF 0 "register_operand" "=x#f,f#x,f#x")
16757         (if_then_else:SF (lt (match_operand:SF 1 "register_operand" "0,0,f#x")
16758                              (match_operand:SF 2 "nonimmediate_operand" "xm#f,f#x,0"))
16759                          (match_dup 1)
16760                          (match_dup 2)))
16761    (clobber (reg:CC 17))]
16762   "TARGET_SSE && TARGET_IEEE_FP"
16763   "#")
16764
16765 (define_insn "*minsf_nonieee"
16766   [(set (match_operand:SF 0 "register_operand" "=x#f,f#x")
16767         (if_then_else:SF (lt (match_operand:SF 1 "nonimmediate_operand" "%0,0")
16768                              (match_operand:SF 2 "nonimmediate_operand" "xm#f,f#x"))
16769                          (match_dup 1)
16770                          (match_dup 2)))
16771    (clobber (reg:CC 17))]
16772   "TARGET_SSE && !TARGET_IEEE_FP
16773    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
16774   "#")
16775
16776 (define_split
16777   [(set (match_operand:SF 0 "register_operand" "")
16778         (if_then_else:SF (lt (match_operand:SF 1 "register_operand" "")
16779                              (match_operand:SF 2 "nonimmediate_operand" ""))
16780                          (match_operand:SF 3 "register_operand" "")
16781                          (match_operand:SF 4 "nonimmediate_operand" "")))
16782    (clobber (reg:CC 17))]
16783   "SSE_REG_P (operands[0]) && reload_completed
16784    && ((operands_match_p (operands[1], operands[3])
16785         && operands_match_p (operands[2], operands[4]))
16786        || (operands_match_p (operands[1], operands[4])
16787            && operands_match_p (operands[2], operands[3])))"
16788   [(set (match_dup 0)
16789         (if_then_else:SF (lt (match_dup 1)
16790                              (match_dup 2))
16791                          (match_dup 1)
16792                          (match_dup 2)))])
16793
16794 ;; Conditional addition patterns
16795 (define_expand "addqicc"
16796   [(match_operand:QI 0 "register_operand" "")
16797    (match_operand 1 "comparison_operator" "")
16798    (match_operand:QI 2 "register_operand" "")
16799    (match_operand:QI 3 "const_int_operand" "")]
16800   ""
16801   "if (!ix86_expand_int_addcc (operands)) FAIL; DONE;")
16802
16803 (define_expand "addhicc"
16804   [(match_operand:HI 0 "register_operand" "")
16805    (match_operand 1 "comparison_operator" "")
16806    (match_operand:HI 2 "register_operand" "")
16807    (match_operand:HI 3 "const_int_operand" "")]
16808   ""
16809   "if (!ix86_expand_int_addcc (operands)) FAIL; DONE;")
16810
16811 (define_expand "addsicc"
16812   [(match_operand:SI 0 "register_operand" "")
16813    (match_operand 1 "comparison_operator" "")
16814    (match_operand:SI 2 "register_operand" "")
16815    (match_operand:SI 3 "const_int_operand" "")]
16816   ""
16817   "if (!ix86_expand_int_addcc (operands)) FAIL; DONE;")
16818
16819 (define_expand "adddicc"
16820   [(match_operand:DI 0 "register_operand" "")
16821    (match_operand 1 "comparison_operator" "")
16822    (match_operand:DI 2 "register_operand" "")
16823    (match_operand:DI 3 "const_int_operand" "")]
16824   "TARGET_64BIT"
16825   "if (!ix86_expand_int_addcc (operands)) FAIL; DONE;")
16826
16827 ;; We can't represent the LT test directly.  Do this by swapping the operands.
16828
16829 (define_split
16830   [(set (match_operand:SF 0 "fp_register_operand" "")
16831         (if_then_else:SF (lt (match_operand:SF 1 "register_operand" "")
16832                              (match_operand:SF 2 "register_operand" ""))
16833                          (match_operand:SF 3 "register_operand" "")
16834                          (match_operand:SF 4 "register_operand" "")))
16835    (clobber (reg:CC 17))]
16836   "reload_completed
16837    && ((operands_match_p (operands[1], operands[3])
16838         && operands_match_p (operands[2], operands[4]))
16839        || (operands_match_p (operands[1], operands[4])
16840            && operands_match_p (operands[2], operands[3])))"
16841   [(set (reg:CCFP 17)
16842         (compare:CCFP (match_dup 2)
16843                       (match_dup 1)))
16844    (set (match_dup 0)
16845         (if_then_else:SF (ge (reg:CCFP 17) (const_int 0))
16846                          (match_dup 1)
16847                          (match_dup 2)))])
16848
16849 (define_insn "*minsf_sse"
16850   [(set (match_operand:SF 0 "register_operand" "=x")
16851         (if_then_else:SF (lt (match_operand:SF 1 "register_operand" "0")
16852                              (match_operand:SF 2 "nonimmediate_operand" "xm"))
16853                          (match_dup 1)
16854                          (match_dup 2)))]
16855   "TARGET_SSE && reload_completed"
16856   "minss\t{%2, %0|%0, %2}"
16857   [(set_attr "type" "sse")
16858    (set_attr "mode" "SF")])
16859
16860 (define_expand "mindf3"
16861   [(parallel [
16862      (set (match_operand:DF 0 "register_operand" "")
16863           (if_then_else:DF (lt (match_operand:DF 1 "register_operand" "")
16864                                (match_operand:DF 2 "nonimmediate_operand" ""))
16865                            (match_dup 1)
16866                            (match_dup 2)))
16867      (clobber (reg:CC 17))])]
16868   "TARGET_SSE2 && TARGET_SSE_MATH"
16869   "#")
16870
16871 (define_insn "*mindf"
16872   [(set (match_operand:DF 0 "register_operand" "=Y#f,f#Y,f#Y")
16873         (if_then_else:DF (lt (match_operand:DF 1 "register_operand" "0,0,f#Y")
16874                              (match_operand:DF 2 "nonimmediate_operand" "Ym#f,f#Y,0"))
16875                          (match_dup 1)
16876                          (match_dup 2)))
16877    (clobber (reg:CC 17))]
16878   "TARGET_SSE2 && TARGET_IEEE_FP && TARGET_SSE_MATH"
16879   "#")
16880
16881 (define_insn "*mindf_nonieee"
16882   [(set (match_operand:DF 0 "register_operand" "=Y#f,f#Y")
16883         (if_then_else:DF (lt (match_operand:DF 1 "nonimmediate_operand" "%0,0")
16884                              (match_operand:DF 2 "nonimmediate_operand" "Ym#f,f#Y"))
16885                          (match_dup 1)
16886                          (match_dup 2)))
16887    (clobber (reg:CC 17))]
16888   "TARGET_SSE2 && TARGET_SSE_MATH && !TARGET_IEEE_FP
16889    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
16890   "#")
16891
16892 (define_split
16893   [(set (match_operand:DF 0 "register_operand" "")
16894         (if_then_else:DF (lt (match_operand:DF 1 "register_operand" "")
16895                              (match_operand:DF 2 "nonimmediate_operand" ""))
16896                          (match_operand:DF 3 "register_operand" "")
16897                          (match_operand:DF 4 "nonimmediate_operand" "")))
16898    (clobber (reg:CC 17))]
16899   "SSE_REG_P (operands[0]) && reload_completed
16900    && ((operands_match_p (operands[1], operands[3])
16901         && operands_match_p (operands[2], operands[4]))
16902        || (operands_match_p (operands[1], operands[4])
16903            && operands_match_p (operands[2], operands[3])))"
16904   [(set (match_dup 0)
16905         (if_then_else:DF (lt (match_dup 1)
16906                              (match_dup 2))
16907                          (match_dup 1)
16908                          (match_dup 2)))])
16909
16910 ;; We can't represent the LT test directly.  Do this by swapping the operands.
16911 (define_split
16912   [(set (match_operand:DF 0 "fp_register_operand" "")
16913         (if_then_else:DF (lt (match_operand:DF 1 "register_operand" "")
16914                              (match_operand:DF 2 "register_operand" ""))
16915                          (match_operand:DF 3 "register_operand" "")
16916                          (match_operand:DF 4 "register_operand" "")))
16917    (clobber (reg:CC 17))]
16918   "reload_completed
16919    && ((operands_match_p (operands[1], operands[3])
16920         && operands_match_p (operands[2], operands[4]))
16921        || (operands_match_p (operands[1], operands[4])
16922            && operands_match_p (operands[2], operands[3])))"
16923   [(set (reg:CCFP 17)
16924         (compare:CCFP (match_dup 2)
16925                       (match_dup 2)))
16926    (set (match_dup 0)
16927         (if_then_else:DF (ge (reg:CCFP 17) (const_int 0))
16928                          (match_dup 1)
16929                          (match_dup 2)))])
16930
16931 (define_insn "*mindf_sse"
16932   [(set (match_operand:DF 0 "register_operand" "=Y")
16933         (if_then_else:DF (lt (match_operand:DF 1 "register_operand" "0")
16934                              (match_operand:DF 2 "nonimmediate_operand" "Ym"))
16935                          (match_dup 1)
16936                          (match_dup 2)))]
16937   "TARGET_SSE2 && TARGET_SSE_MATH && reload_completed"
16938   "minsd\t{%2, %0|%0, %2}"
16939   [(set_attr "type" "sse")
16940    (set_attr "mode" "DF")])
16941
16942 (define_expand "maxsf3"
16943   [(parallel [
16944      (set (match_operand:SF 0 "register_operand" "")
16945           (if_then_else:SF (gt (match_operand:SF 1 "register_operand" "")
16946                                (match_operand:SF 2 "nonimmediate_operand" ""))
16947                            (match_dup 1)
16948                            (match_dup 2)))
16949      (clobber (reg:CC 17))])]
16950   "TARGET_SSE"
16951   "#")
16952
16953 (define_insn "*maxsf"
16954   [(set (match_operand:SF 0 "register_operand" "=x#f,f#x,f#x")
16955         (if_then_else:SF (gt (match_operand:SF 1 "register_operand" "0,0,f#x")
16956                              (match_operand:SF 2 "nonimmediate_operand" "xm#f,f#x,0"))
16957                          (match_dup 1)
16958                          (match_dup 2)))
16959    (clobber (reg:CC 17))]
16960   "TARGET_SSE && TARGET_IEEE_FP"
16961   "#")
16962
16963 (define_insn "*maxsf_nonieee"
16964   [(set (match_operand:SF 0 "register_operand" "=x#f,f#x")
16965         (if_then_else:SF (gt (match_operand:SF 1 "nonimmediate_operand" "%0,0")
16966                              (match_operand:SF 2 "nonimmediate_operand" "xm#f,f#x"))
16967                          (match_dup 1)
16968                          (match_dup 2)))
16969    (clobber (reg:CC 17))]
16970   "TARGET_SSE && !TARGET_IEEE_FP
16971    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
16972   "#")
16973
16974 (define_split
16975   [(set (match_operand:SF 0 "register_operand" "")
16976         (if_then_else:SF (gt (match_operand:SF 1 "register_operand" "")
16977                              (match_operand:SF 2 "nonimmediate_operand" ""))
16978                          (match_operand:SF 3 "register_operand" "")
16979                          (match_operand:SF 4 "nonimmediate_operand" "")))
16980    (clobber (reg:CC 17))]
16981   "SSE_REG_P (operands[0]) && reload_completed
16982    && ((operands_match_p (operands[1], operands[3])
16983         && operands_match_p (operands[2], operands[4]))
16984        || (operands_match_p (operands[1], operands[4])
16985            && operands_match_p (operands[2], operands[3])))"
16986   [(set (match_dup 0)
16987         (if_then_else:SF (gt (match_dup 1)
16988                              (match_dup 2))
16989                          (match_dup 1)
16990                          (match_dup 2)))])
16991
16992 (define_split
16993   [(set (match_operand:SF 0 "fp_register_operand" "")
16994         (if_then_else:SF (gt (match_operand:SF 1 "register_operand" "")
16995                              (match_operand:SF 2 "register_operand" ""))
16996                          (match_operand:SF 3 "register_operand" "")
16997                          (match_operand:SF 4 "register_operand" "")))
16998    (clobber (reg:CC 17))]
16999   "reload_completed
17000    && ((operands_match_p (operands[1], operands[3])
17001         && operands_match_p (operands[2], operands[4]))
17002        || (operands_match_p (operands[1], operands[4])
17003            && operands_match_p (operands[2], operands[3])))"
17004   [(set (reg:CCFP 17)
17005         (compare:CCFP (match_dup 1)
17006                       (match_dup 2)))
17007    (set (match_dup 0)
17008         (if_then_else:SF (gt (reg:CCFP 17) (const_int 0))
17009                          (match_dup 1)
17010                          (match_dup 2)))])
17011
17012 (define_insn "*maxsf_sse"
17013   [(set (match_operand:SF 0 "register_operand" "=x")
17014         (if_then_else:SF (gt (match_operand:SF 1 "register_operand" "0")
17015                              (match_operand:SF 2 "nonimmediate_operand" "xm"))
17016                          (match_dup 1)
17017                          (match_dup 2)))]
17018   "TARGET_SSE && reload_completed"
17019   "maxss\t{%2, %0|%0, %2}"
17020   [(set_attr "type" "sse")
17021    (set_attr "mode" "SF")])
17022
17023 (define_expand "maxdf3"
17024   [(parallel [
17025      (set (match_operand:DF 0 "register_operand" "")
17026           (if_then_else:DF (gt (match_operand:DF 1 "register_operand" "")
17027                                (match_operand:DF 2 "nonimmediate_operand" ""))
17028                            (match_dup 1)
17029                            (match_dup 2)))
17030      (clobber (reg:CC 17))])]
17031   "TARGET_SSE2 && TARGET_SSE_MATH"
17032   "#")
17033
17034 (define_insn "*maxdf"
17035   [(set (match_operand:DF 0 "register_operand" "=Y#f,f#Y,f#Y")
17036         (if_then_else:DF (gt (match_operand:DF 1 "register_operand" "0,0,f#Y")
17037                              (match_operand:DF 2 "nonimmediate_operand" "Ym#f,f#Y,0"))
17038                          (match_dup 1)
17039                          (match_dup 2)))
17040    (clobber (reg:CC 17))]
17041   "TARGET_SSE2 && TARGET_SSE_MATH && TARGET_IEEE_FP"
17042   "#")
17043
17044 (define_insn "*maxdf_nonieee"
17045   [(set (match_operand:DF 0 "register_operand" "=Y#f,f#Y")
17046         (if_then_else:DF (gt (match_operand:DF 1 "nonimmediate_operand" "%0,0")
17047                              (match_operand:DF 2 "nonimmediate_operand" "Ym#f,f#Y"))
17048                          (match_dup 1)
17049                          (match_dup 2)))
17050    (clobber (reg:CC 17))]
17051   "TARGET_SSE2 && TARGET_SSE_MATH && !TARGET_IEEE_FP
17052    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
17053   "#")
17054
17055 (define_split
17056   [(set (match_operand:DF 0 "register_operand" "")
17057         (if_then_else:DF (gt (match_operand:DF 1 "register_operand" "")
17058                              (match_operand:DF 2 "nonimmediate_operand" ""))
17059                          (match_operand:DF 3 "register_operand" "")
17060                          (match_operand:DF 4 "nonimmediate_operand" "")))
17061    (clobber (reg:CC 17))]
17062   "SSE_REG_P (operands[0]) && reload_completed
17063    && ((operands_match_p (operands[1], operands[3])
17064         && operands_match_p (operands[2], operands[4]))
17065        || (operands_match_p (operands[1], operands[4])
17066            && operands_match_p (operands[2], operands[3])))"
17067   [(set (match_dup 0)
17068         (if_then_else:DF (gt (match_dup 1)
17069                              (match_dup 2))
17070                          (match_dup 1)
17071                          (match_dup 2)))])
17072
17073 (define_split
17074   [(set (match_operand:DF 0 "fp_register_operand" "")
17075         (if_then_else:DF (gt (match_operand:DF 1 "register_operand" "")
17076                              (match_operand:DF 2 "register_operand" ""))
17077                          (match_operand:DF 3 "register_operand" "")
17078                          (match_operand:DF 4 "register_operand" "")))
17079    (clobber (reg:CC 17))]
17080   "reload_completed
17081    && ((operands_match_p (operands[1], operands[3])
17082         && operands_match_p (operands[2], operands[4]))
17083        || (operands_match_p (operands[1], operands[4])
17084            && operands_match_p (operands[2], operands[3])))"
17085   [(set (reg:CCFP 17)
17086         (compare:CCFP (match_dup 1)
17087                       (match_dup 2)))
17088    (set (match_dup 0)
17089         (if_then_else:DF (gt (reg:CCFP 17) (const_int 0))
17090                          (match_dup 1)
17091                          (match_dup 2)))])
17092
17093 (define_insn "*maxdf_sse"
17094   [(set (match_operand:DF 0 "register_operand" "=Y")
17095         (if_then_else:DF (gt (match_operand:DF 1 "register_operand" "0")
17096                              (match_operand:DF 2 "nonimmediate_operand" "Ym"))
17097                          (match_dup 1)
17098                          (match_dup 2)))]
17099   "TARGET_SSE2 && TARGET_SSE_MATH && reload_completed"
17100   "maxsd\t{%2, %0|%0, %2}"
17101   [(set_attr "type" "sse")
17102    (set_attr "mode" "DF")])
17103 \f
17104 ;; Misc patterns (?)
17105
17106 ;; This pattern exists to put a dependency on all ebp-based memory accesses.
17107 ;; Otherwise there will be nothing to keep
17108 ;; 
17109 ;; [(set (reg ebp) (reg esp))]
17110 ;; [(set (reg esp) (plus (reg esp) (const_int -160000)))
17111 ;;  (clobber (eflags)]
17112 ;; [(set (mem (plus (reg ebp) (const_int -160000))) (const_int 0))]
17113 ;;
17114 ;; in proper program order.
17115 (define_expand "pro_epilogue_adjust_stack"
17116   [(parallel [(set (match_operand:SI 0 "register_operand" "=r,r")
17117                    (plus:SI (match_operand:SI 1 "register_operand" "0,r")
17118                             (match_operand:SI 2 "immediate_operand" "i,i")))
17119               (clobber (reg:CC 17))
17120               (clobber (mem:BLK (scratch)))])]
17121  ""
17122 {
17123   if (TARGET_64BIT)
17124     {
17125       emit_insn (gen_pro_epilogue_adjust_stack_rex64
17126                  (operands[0], operands[1], operands[2]));
17127       DONE;
17128     }
17129 })
17130
17131 (define_insn "*pro_epilogue_adjust_stack_1"
17132   [(set (match_operand:SI 0 "register_operand" "=r,r")
17133         (plus:SI (match_operand:SI 1 "register_operand" "0,r")
17134                  (match_operand:SI 2 "immediate_operand" "i,i")))
17135    (clobber (reg:CC 17))
17136    (clobber (mem:BLK (scratch)))]
17137   "!TARGET_64BIT"
17138 {
17139   switch (get_attr_type (insn))
17140     {
17141     case TYPE_IMOV:
17142       return "mov{l}\t{%1, %0|%0, %1}";
17143
17144     case TYPE_ALU:
17145       if (GET_CODE (operands[2]) == CONST_INT
17146           && (INTVAL (operands[2]) == 128
17147               || (INTVAL (operands[2]) < 0
17148                   && INTVAL (operands[2]) != -128)))
17149         {
17150           operands[2] = GEN_INT (-INTVAL (operands[2]));
17151           return "sub{l}\t{%2, %0|%0, %2}";
17152         }
17153       return "add{l}\t{%2, %0|%0, %2}";
17154
17155     case TYPE_LEA:
17156       operands[2] = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
17157       return "lea{l}\t{%a2, %0|%0, %a2}";
17158
17159     default:
17160       abort ();
17161     }
17162 }
17163   [(set (attr "type")
17164         (cond [(eq_attr "alternative" "0")
17165                  (const_string "alu")
17166                (match_operand:SI 2 "const0_operand" "")
17167                  (const_string "imov")
17168               ]
17169               (const_string "lea")))
17170    (set_attr "mode" "SI")])
17171
17172 (define_insn "pro_epilogue_adjust_stack_rex64"
17173   [(set (match_operand:DI 0 "register_operand" "=r,r")
17174         (plus:DI (match_operand:DI 1 "register_operand" "0,r")
17175                  (match_operand:DI 2 "x86_64_immediate_operand" "e,e")))
17176    (clobber (reg:CC 17))
17177    (clobber (mem:BLK (scratch)))]
17178   "TARGET_64BIT"
17179 {
17180   switch (get_attr_type (insn))
17181     {
17182     case TYPE_IMOV:
17183       return "mov{q}\t{%1, %0|%0, %1}";
17184
17185     case TYPE_ALU:
17186       if (GET_CODE (operands[2]) == CONST_INT
17187           && (INTVAL (operands[2]) == 128
17188               || (INTVAL (operands[2]) < 0
17189                   && INTVAL (operands[2]) != -128)))
17190         {
17191           operands[2] = GEN_INT (-INTVAL (operands[2]));
17192           return "sub{q}\t{%2, %0|%0, %2}";
17193         }
17194       return "add{q}\t{%2, %0|%0, %2}";
17195
17196     case TYPE_LEA:
17197       operands[2] = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
17198       return "lea{q}\t{%a2, %0|%0, %a2}";
17199
17200     default:
17201       abort ();
17202     }
17203 }
17204   [(set (attr "type")
17205         (cond [(eq_attr "alternative" "0")
17206                  (const_string "alu")
17207                (match_operand:DI 2 "const0_operand" "")
17208                  (const_string "imov")
17209               ]
17210               (const_string "lea")))
17211    (set_attr "mode" "DI")])
17212
17213
17214 ;; Placeholder for the conditional moves.  This one is split either to SSE
17215 ;; based moves emulation or to usual cmove sequence.  Little bit unfortunate
17216 ;; fact is that compares supported by the cmp??ss instructions are exactly
17217 ;; swapped of those supported by cmove sequence.
17218 ;; The EQ/NE comparisons also needs bit care, since they are not directly
17219 ;; supported by i387 comparisons and we do need to emit two conditional moves
17220 ;; in tandem.
17221
17222 (define_insn "sse_movsfcc"
17223   [(set (match_operand:SF 0 "register_operand" "=&x#rf,x#rf,?f#xr,?f#xr,?f#xr,?f#xr,?r#xf,?r#xf,?r#xf,?r#xf")
17224         (if_then_else:SF (match_operator 1 "sse_comparison_operator"
17225                         [(match_operand:SF 4 "nonimmediate_operand" "0#fx,x#fx,f#x,f#x,xm#f,xm#f,f#x,f#x,xm#f,xm#f")
17226                          (match_operand:SF 5 "nonimmediate_operand" "xm#f,xm#f,f#x,f#x,x#f,x#f,f#x,f#x,x#f,x#f")])
17227                       (match_operand:SF 2 "nonimmediate_operand" "x#fr,0#fr,f#fx,0#fx,f#fx,0#fx,rm#rx,0#rx,rm#rx,0#rx")
17228                       (match_operand:SF 3 "nonimmediate_operand" "x#fr,x#fr,0#fx,f#fx,0#fx,f#fx,0#fx,rm#rx,0#rx,rm#rx")))
17229    (clobber (match_scratch:SF 6 "=2,&4,X,X,X,X,X,X,X,X"))
17230    (clobber (reg:CC 17))]
17231   "TARGET_SSE
17232    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)
17233    /* Avoid combine from being smart and converting min/max
17234       instruction patterns into conditional moves.  */
17235    && ((GET_CODE (operands[1]) != LT && GET_CODE (operands[1]) != GT
17236         && GET_CODE (operands[1]) != UNLE && GET_CODE (operands[1]) != UNGE)
17237        || !rtx_equal_p (operands[4], operands[2])
17238        || !rtx_equal_p (operands[5], operands[3]))
17239    && (!TARGET_IEEE_FP
17240        || (GET_CODE (operands[1]) != EQ && GET_CODE (operands[1]) != NE))"
17241   "#")
17242
17243 (define_insn "sse_movsfcc_eq"
17244   [(set (match_operand:SF 0 "register_operand" "=&x#rf,x#rf,?f#xr,?f#xr,?r#xf,?r#xf")
17245         (if_then_else:SF (eq (match_operand:SF 3 "nonimmediate_operand" "%0#fx,x#fx,f#x,xm#f,f#x,xm#f")
17246                              (match_operand:SF 4 "nonimmediate_operand" "xm#f,xm#f,f#x,x#f,f#x,x#f"))
17247                       (match_operand:SF 1 "nonimmediate_operand" "x#fr,0#fr,0#fx,0#fx,0#rx,0#rx")
17248                       (match_operand:SF 2 "nonimmediate_operand" "x#fr,x#fr,f#fx,f#fx,rm#rx,rm#rx")))
17249    (clobber (match_scratch:SF 5 "=1,&3,X,X,X,X"))
17250    (clobber (reg:CC 17))]
17251   "TARGET_SSE
17252    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)"
17253   "#")
17254
17255 (define_insn "sse_movdfcc"
17256   [(set (match_operand:DF 0 "register_operand" "=&Y#rf,Y#rf,?f#Yr,?f#Yr,?f#Yr,?f#Yr,?r#Yf,?r#Yf,?r#Yf,?r#Yf")
17257         (if_then_else:DF (match_operator 1 "sse_comparison_operator"
17258                         [(match_operand:DF 4 "nonimmediate_operand" "0#fY,Y#fY,f#Y,f#Y,Ym#f,Ym#f,f#Y,f#Y,Ym#f,Ym#f")
17259                          (match_operand:DF 5 "nonimmediate_operand" "Ym#f,Ym#f,f#Y,f#Y,Y#f,Y#f,f#Y,f#Y,Y#f,Y#f")])
17260                       (match_operand:DF 2 "nonimmediate_operand" "Y#fr,0#fr,f#fY,0#fY,f#fY,0#fY,rm#rY,0#rY,rm#rY,0#rY")
17261                       (match_operand:DF 3 "nonimmediate_operand" "Y#fr,Y#fr,0#fY,f#fY,0#fY,f#fY,0#fY,rm#rY,0#rY,rm#rY")))
17262    (clobber (match_scratch:DF 6 "=2,&4,X,X,X,X,X,X,X,X"))
17263    (clobber (reg:CC 17))]
17264   "TARGET_SSE2
17265    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)
17266    /* Avoid combine from being smart and converting min/max
17267       instruction patterns into conditional moves.  */
17268    && ((GET_CODE (operands[1]) != LT && GET_CODE (operands[1]) != GT
17269         && GET_CODE (operands[1]) != UNLE && GET_CODE (operands[1]) != UNGE)
17270        || !rtx_equal_p (operands[4], operands[2])
17271        || !rtx_equal_p (operands[5], operands[3]))
17272    && (!TARGET_IEEE_FP
17273        || (GET_CODE (operands[1]) != EQ && GET_CODE (operands[1]) != NE))"
17274   "#")
17275
17276 (define_insn "sse_movdfcc_eq"
17277   [(set (match_operand:DF 0 "register_operand" "=&Y#rf,Y#rf,?f#Yr,?f#Yr,?r#Yf,?r#Yf")
17278         (if_then_else:DF (eq (match_operand:DF 3 "nonimmediate_operand" "%0#fY,Y#fY,f#Y,Ym#f,f#Y,Ym#f")
17279                              (match_operand:DF 4 "nonimmediate_operand" "Ym#f,Ym#f,f#Y,Y#f,f#Y,Y#f"))
17280                       (match_operand:DF 1 "nonimmediate_operand" "Y#fr,0#fr,0#fY,0#fY,0#rY,0#rY")
17281                       (match_operand:DF 2 "nonimmediate_operand" "Y#fr,Y#fr,f#fY,f#fY,rm#rY,rm#rY")))
17282    (clobber (match_scratch:DF 5 "=1,&3,X,X,X,X"))
17283    (clobber (reg:CC 17))]
17284   "TARGET_SSE
17285    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)"
17286   "#")
17287
17288 ;; For non-sse moves just expand the usual cmove sequence.
17289 (define_split
17290   [(set (match_operand 0 "register_operand" "")
17291         (if_then_else (match_operator 1 "comparison_operator"
17292                         [(match_operand 4 "nonimmediate_operand" "")
17293                          (match_operand 5 "register_operand" "")])
17294                       (match_operand 2 "nonimmediate_operand" "")
17295                       (match_operand 3 "nonimmediate_operand" "")))
17296    (clobber (match_operand 6 "" ""))
17297    (clobber (reg:CC 17))]
17298   "!SSE_REG_P (operands[0]) && reload_completed
17299    && VALID_SSE_REG_MODE (GET_MODE (operands[0]))"
17300   [(const_int 0)]
17301 {
17302    ix86_compare_op0 = operands[5];
17303    ix86_compare_op1 = operands[4];
17304    operands[1] = gen_rtx_fmt_ee (swap_condition (GET_CODE (operands[1])),
17305                                  VOIDmode, operands[5], operands[4]);
17306    ix86_expand_fp_movcc (operands);
17307    DONE;
17308 })
17309
17310 ;; Split SSE based conditional move into sequence:
17311 ;; cmpCC op0, op4   -  set op0 to 0 or ffffffff depending on the comparison
17312 ;; and   op2, op0   -  zero op2 if comparison was false
17313 ;; nand  op0, op3   -  load op3 to op0 if comparison was false
17314 ;; or    op2, op0   -  get the nonzero one into the result.
17315 (define_split
17316   [(set (match_operand 0 "register_operand" "")
17317         (if_then_else (match_operator 1 "sse_comparison_operator"
17318                         [(match_operand 4 "register_operand" "")
17319                          (match_operand 5 "nonimmediate_operand" "")])
17320                       (match_operand 2 "register_operand" "")
17321                       (match_operand 3 "register_operand" "")))
17322    (clobber (match_operand 6 "" ""))
17323    (clobber (reg:CC 17))]
17324   "SSE_REG_P (operands[0]) && reload_completed"
17325   [(set (match_dup 4) (match_op_dup 1 [(match_dup 4) (match_dup 5)]))
17326    (set (subreg:TI (match_dup 2) 0) (and:TI (subreg:TI (match_dup 2) 0)
17327                                             (subreg:TI (match_dup 4) 0)))
17328    (set (subreg:TI (match_dup 4) 0) (and:TI (not:TI (subreg:TI (match_dup 4) 0))
17329                                             (subreg:TI (match_dup 3) 0)))
17330    (set (subreg:TI (match_dup 0) 0) (ior:TI (subreg:TI (match_dup 6) 0)
17331                                             (subreg:TI (match_dup 7) 0)))]
17332 {
17333   if (GET_MODE (operands[2]) == DFmode
17334       && TARGET_SSE_PARTIAL_REGS && !optimize_size)
17335     {
17336       rtx op = simplify_gen_subreg (V2DFmode, operands[2], DFmode, 0);
17337       emit_insn (gen_sse2_unpcklpd (op, op, op));
17338       op = simplify_gen_subreg (V2DFmode, operands[3], DFmode, 0);
17339       emit_insn (gen_sse2_unpcklpd (op, op, op));
17340     }
17341
17342   /* If op2 == op3, op3 would be clobbered before it is used.  */
17343   if (operands_match_p (operands[2], operands[3]))
17344     {
17345       emit_move_insn (operands[0], operands[2]);
17346       DONE;
17347     }
17348
17349   PUT_MODE (operands[1], GET_MODE (operands[0]));
17350   if (operands_match_p (operands[0], operands[4]))
17351     operands[6] = operands[4], operands[7] = operands[2];
17352   else
17353     operands[6] = operands[2], operands[7] = operands[4];
17354 })
17355
17356 ;; Special case of conditional move we can handle effectively.
17357 ;; Do not brother with the integer/floating point case, since these are
17358 ;; bot considerably slower, unlike in the generic case.
17359 (define_insn "*sse_movsfcc_const0_1"
17360   [(set (match_operand:SF 0 "register_operand" "=&x")
17361         (if_then_else:SF (match_operator 1 "sse_comparison_operator"
17362                         [(match_operand:SF 4 "register_operand" "0")
17363                          (match_operand:SF 5 "nonimmediate_operand" "xm")])
17364                       (match_operand:SF 2 "register_operand" "x")
17365                       (match_operand:SF 3 "const0_operand" "X")))]
17366   "TARGET_SSE"
17367   "#")
17368
17369 (define_insn "*sse_movsfcc_const0_2"
17370   [(set (match_operand:SF 0 "register_operand" "=&x")
17371         (if_then_else:SF (match_operator 1 "sse_comparison_operator"
17372                         [(match_operand:SF 4 "register_operand" "0")
17373                          (match_operand:SF 5 "nonimmediate_operand" "xm")])
17374                       (match_operand:SF 2 "const0_operand" "X")
17375                       (match_operand:SF 3 "register_operand" "x")))]
17376   "TARGET_SSE"
17377   "#")
17378
17379 (define_insn "*sse_movsfcc_const0_3"
17380   [(set (match_operand:SF 0 "register_operand" "=&x")
17381         (if_then_else:SF (match_operator 1 "fcmov_comparison_operator"
17382                         [(match_operand:SF 4 "nonimmediate_operand" "xm")
17383                          (match_operand:SF 5 "register_operand" "0")])
17384                       (match_operand:SF 2 "register_operand" "x")
17385                       (match_operand:SF 3 "const0_operand" "X")))]
17386   "TARGET_SSE"
17387   "#")
17388
17389 (define_insn "*sse_movsfcc_const0_4"
17390   [(set (match_operand:SF 0 "register_operand" "=&x")
17391         (if_then_else:SF (match_operator 1 "fcmov_comparison_operator"
17392                         [(match_operand:SF 4 "nonimmediate_operand" "xm")
17393                          (match_operand:SF 5 "register_operand" "0")])
17394                       (match_operand:SF 2 "const0_operand" "X")
17395                       (match_operand:SF 3 "register_operand" "x")))]
17396   "TARGET_SSE"
17397   "#")
17398
17399 (define_insn "*sse_movdfcc_const0_1"
17400   [(set (match_operand:DF 0 "register_operand" "=&Y")
17401         (if_then_else:DF (match_operator 1 "sse_comparison_operator"
17402                         [(match_operand:DF 4 "register_operand" "0")
17403                          (match_operand:DF 5 "nonimmediate_operand" "Ym")])
17404                       (match_operand:DF 2 "register_operand" "Y")
17405                       (match_operand:DF 3 "const0_operand" "X")))]
17406   "TARGET_SSE2"
17407   "#")
17408
17409 (define_insn "*sse_movdfcc_const0_2"
17410   [(set (match_operand:DF 0 "register_operand" "=&Y")
17411         (if_then_else:DF (match_operator 1 "sse_comparison_operator"
17412                         [(match_operand:DF 4 "register_operand" "0")
17413                          (match_operand:DF 5 "nonimmediate_operand" "Ym")])
17414                       (match_operand:DF 2 "const0_operand" "X")
17415                       (match_operand:DF 3 "register_operand" "Y")))]
17416   "TARGET_SSE2"
17417   "#")
17418
17419 (define_insn "*sse_movdfcc_const0_3"
17420   [(set (match_operand:DF 0 "register_operand" "=&Y")
17421         (if_then_else:DF (match_operator 1 "fcmov_comparison_operator"
17422                         [(match_operand:DF 4 "nonimmediate_operand" "Ym")
17423                          (match_operand:DF 5 "register_operand" "0")])
17424                       (match_operand:DF 2 "register_operand" "Y")
17425                       (match_operand:DF 3 "const0_operand" "X")))]
17426   "TARGET_SSE2"
17427   "#")
17428
17429 (define_insn "*sse_movdfcc_const0_4"
17430   [(set (match_operand:DF 0 "register_operand" "=&Y")
17431         (if_then_else:DF (match_operator 1 "fcmov_comparison_operator"
17432                         [(match_operand:DF 4 "nonimmediate_operand" "Ym")
17433                          (match_operand:DF 5 "register_operand" "0")])
17434                       (match_operand:DF 2 "const0_operand" "X")
17435                       (match_operand:DF 3 "register_operand" "Y")))]
17436   "TARGET_SSE2"
17437   "#")
17438
17439 (define_split
17440   [(set (match_operand 0 "register_operand" "")
17441         (if_then_else (match_operator 1 "comparison_operator"
17442                         [(match_operand 4 "nonimmediate_operand" "")
17443                          (match_operand 5 "nonimmediate_operand" "")])
17444                       (match_operand 2 "nonmemory_operand" "")
17445                       (match_operand 3 "nonmemory_operand" "")))]
17446   "SSE_REG_P (operands[0]) && reload_completed
17447    && (const0_operand (operands[2], GET_MODE (operands[0]))
17448        || const0_operand (operands[3], GET_MODE (operands[0])))"
17449   [(set (match_dup 0) (match_op_dup 1 [(match_dup 0) (match_dup 5)]))
17450    (set (subreg:TI (match_dup 0) 0) (and:TI (match_dup 6)
17451                                             (match_dup 7)))]
17452 {
17453   if (TARGET_SSE_PARTIAL_REGS && !optimize_size
17454       && GET_MODE (operands[2]) == DFmode)
17455     {
17456       if (REG_P (operands[2]))
17457         {
17458           rtx op = simplify_gen_subreg (V2DFmode, operands[2], DFmode, 0);
17459           emit_insn (gen_sse2_unpcklpd (op, op, op));
17460         }
17461       if (REG_P (operands[3]))
17462         {
17463           rtx op = simplify_gen_subreg (V2DFmode, operands[3], DFmode, 0);
17464           emit_insn (gen_sse2_unpcklpd (op, op, op));
17465         }
17466     }
17467   PUT_MODE (operands[1], GET_MODE (operands[0]));
17468   if (!sse_comparison_operator (operands[1], VOIDmode)
17469       || !rtx_equal_p (operands[0], operands[4]))
17470     {
17471       rtx tmp = operands[5];
17472       operands[5] = operands[4];
17473       operands[4] = tmp;
17474       PUT_CODE (operands[1], swap_condition (GET_CODE (operands[1])));
17475     }
17476   if (!rtx_equal_p (operands[0], operands[4]))
17477     abort ();
17478   if (const0_operand (operands[2], GET_MODE (operands[0])))
17479     {
17480       operands[7] = operands[3];
17481       operands[6] = gen_rtx_NOT (TImode, gen_rtx_SUBREG (TImode, operands[0],
17482                                                          0));
17483     }
17484   else
17485     {
17486       operands[7] = operands[2];
17487       operands[6] = gen_rtx_SUBREG (TImode, operands[0], 0);
17488     }
17489   operands[7] = simplify_gen_subreg (TImode, operands[7],
17490                                      GET_MODE (operands[7]), 0);
17491 })
17492
17493 (define_expand "allocate_stack_worker"
17494   [(match_operand:SI 0 "register_operand" "")]
17495   "TARGET_STACK_PROBE"
17496 {
17497   if (TARGET_64BIT)
17498     emit_insn (gen_allocate_stack_worker_rex64 (operands[0]));
17499   else
17500     emit_insn (gen_allocate_stack_worker_1 (operands[0]));
17501   DONE;
17502 })
17503
17504 (define_insn "allocate_stack_worker_1"
17505   [(unspec:SI [(match_operand:SI 0 "register_operand" "a")] UNSPEC_STACK_PROBE)
17506    (set (reg:SI 7) (minus:SI (reg:SI 7) (match_dup 0)))
17507    (clobber (match_dup 0))
17508    (clobber (reg:CC 17))]
17509   "!TARGET_64BIT && TARGET_STACK_PROBE"
17510   "call\t__alloca"
17511   [(set_attr "type" "multi")
17512    (set_attr "length" "5")])
17513
17514 (define_insn "allocate_stack_worker_rex64"
17515   [(unspec:DI [(match_operand:DI 0 "register_operand" "a")] UNSPEC_STACK_PROBE)
17516    (set (reg:DI 7) (minus:DI (reg:DI 7) (match_dup 0)))
17517    (clobber (match_dup 0))
17518    (clobber (reg:CC 17))]
17519   "TARGET_64BIT && TARGET_STACK_PROBE"
17520   "call\t__alloca"
17521   [(set_attr "type" "multi")
17522    (set_attr "length" "5")])
17523
17524 (define_expand "allocate_stack"
17525   [(parallel [(set (match_operand:SI 0 "register_operand" "=r")
17526                    (minus:SI (reg:SI 7)
17527                              (match_operand:SI 1 "general_operand" "")))
17528               (clobber (reg:CC 17))])
17529    (parallel [(set (reg:SI 7)
17530                    (minus:SI (reg:SI 7) (match_dup 1)))
17531               (clobber (reg:CC 17))])]
17532   "TARGET_STACK_PROBE"
17533 {
17534 #ifdef CHECK_STACK_LIMIT
17535   if (GET_CODE (operands[1]) == CONST_INT
17536       && INTVAL (operands[1]) < CHECK_STACK_LIMIT)
17537     emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx,
17538                            operands[1]));
17539   else 
17540 #endif
17541     emit_insn (gen_allocate_stack_worker (copy_to_mode_reg (SImode,
17542                                                             operands[1])));
17543
17544   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
17545   DONE;
17546 })
17547
17548 (define_expand "builtin_setjmp_receiver"
17549   [(label_ref (match_operand 0 "" ""))]
17550   "!TARGET_64BIT && flag_pic"
17551 {
17552   emit_insn (gen_set_got (pic_offset_table_rtx));
17553   DONE;
17554 })
17555 \f
17556 ;; Avoid redundant prefixes by splitting HImode arithmetic to SImode.
17557
17558 (define_split
17559   [(set (match_operand 0 "register_operand" "")
17560         (match_operator 3 "promotable_binary_operator"
17561            [(match_operand 1 "register_operand" "")
17562             (match_operand 2 "aligned_operand" "")]))
17563    (clobber (reg:CC 17))]
17564   "! TARGET_PARTIAL_REG_STALL && reload_completed
17565    && ((GET_MODE (operands[0]) == HImode 
17566         && ((!optimize_size && !TARGET_FAST_PREFIX)
17567             || GET_CODE (operands[2]) != CONST_INT
17568             || CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'K')))
17569        || (GET_MODE (operands[0]) == QImode 
17570            && (TARGET_PROMOTE_QImode || optimize_size)))"
17571   [(parallel [(set (match_dup 0)
17572                    (match_op_dup 3 [(match_dup 1) (match_dup 2)]))
17573               (clobber (reg:CC 17))])]
17574   "operands[0] = gen_lowpart (SImode, operands[0]);
17575    operands[1] = gen_lowpart (SImode, operands[1]);
17576    if (GET_CODE (operands[3]) != ASHIFT)
17577      operands[2] = gen_lowpart (SImode, operands[2]);
17578    PUT_MODE (operands[3], SImode);")
17579
17580 (define_split
17581   [(set (reg 17)
17582         (compare (and (match_operand 1 "aligned_operand" "")
17583                       (match_operand 2 "const_int_operand" ""))
17584                  (const_int 0)))
17585    (set (match_operand 0 "register_operand" "")
17586         (and (match_dup 1) (match_dup 2)))]
17587   "! TARGET_PARTIAL_REG_STALL && reload_completed
17588    && ix86_match_ccmode (insn, CCNOmode)
17589    && (GET_MODE (operands[0]) == HImode
17590        || (GET_MODE (operands[0]) == QImode 
17591            /* Ensure that the operand will remain sign extended immediate.  */
17592            && INTVAL (operands[2]) >= 0
17593            && (TARGET_PROMOTE_QImode || optimize_size)))"
17594   [(parallel [(set (reg:CCNO 17)
17595                    (compare:CCNO (and:SI (match_dup 1) (match_dup 2))
17596                                  (const_int 0)))
17597               (set (match_dup 0)
17598                    (and:SI (match_dup 1) (match_dup 2)))])]
17599   "operands[2]
17600      = gen_int_mode (INTVAL (operands[2])
17601                      & GET_MODE_MASK (GET_MODE (operands[0])),
17602                      SImode);
17603    operands[0] = gen_lowpart (SImode, operands[0]);
17604    operands[1] = gen_lowpart (SImode, operands[1]);")
17605
17606 ; Don't promote the QImode tests, as i386 don't have encoding of
17607 ; the test instruction with 32bit sign extended immediate and thus
17608 ; the code grows.
17609 (define_split
17610   [(set (reg 17)
17611         (compare (and (match_operand:HI 0 "aligned_operand" "")
17612                       (match_operand:HI 1 "const_int_operand" ""))
17613                  (const_int 0)))]
17614   "! TARGET_PARTIAL_REG_STALL && reload_completed
17615    && ix86_match_ccmode (insn, CCNOmode)
17616    && GET_MODE (operands[0]) == HImode"
17617   [(set (reg:CCNO 17)
17618         (compare:CCNO (and:SI (match_dup 0) (match_dup 1))
17619                       (const_int 0)))]
17620   "operands[1]
17621      = gen_int_mode (INTVAL (operands[1])
17622                      & GET_MODE_MASK (GET_MODE (operands[0])),
17623                      SImode);
17624    operands[0] = gen_lowpart (SImode, operands[0]);")
17625
17626 (define_split
17627   [(set (match_operand 0 "register_operand" "")
17628         (neg (match_operand 1 "register_operand" "")))
17629    (clobber (reg:CC 17))]
17630   "! TARGET_PARTIAL_REG_STALL && reload_completed
17631    && (GET_MODE (operands[0]) == HImode
17632        || (GET_MODE (operands[0]) == QImode 
17633            && (TARGET_PROMOTE_QImode || optimize_size)))"
17634   [(parallel [(set (match_dup 0)
17635                    (neg:SI (match_dup 1)))
17636               (clobber (reg:CC 17))])]
17637   "operands[0] = gen_lowpart (SImode, operands[0]);
17638    operands[1] = gen_lowpart (SImode, operands[1]);")
17639
17640 (define_split
17641   [(set (match_operand 0 "register_operand" "")
17642         (not (match_operand 1 "register_operand" "")))]
17643   "! TARGET_PARTIAL_REG_STALL && reload_completed
17644    && (GET_MODE (operands[0]) == HImode
17645        || (GET_MODE (operands[0]) == QImode 
17646            && (TARGET_PROMOTE_QImode || optimize_size)))"
17647   [(set (match_dup 0)
17648         (not:SI (match_dup 1)))]
17649   "operands[0] = gen_lowpart (SImode, operands[0]);
17650    operands[1] = gen_lowpart (SImode, operands[1]);")
17651
17652 (define_split 
17653   [(set (match_operand 0 "register_operand" "")
17654         (if_then_else (match_operator 1 "comparison_operator" 
17655                                 [(reg 17) (const_int 0)])
17656                       (match_operand 2 "register_operand" "")
17657                       (match_operand 3 "register_operand" "")))]
17658   "! TARGET_PARTIAL_REG_STALL && TARGET_CMOVE
17659    && (GET_MODE (operands[0]) == HImode
17660        || (GET_MODE (operands[0]) == QImode 
17661            && (TARGET_PROMOTE_QImode || optimize_size)))"
17662   [(set (match_dup 0)
17663         (if_then_else:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
17664   "operands[0] = gen_lowpart (SImode, operands[0]);
17665    operands[2] = gen_lowpart (SImode, operands[2]);
17666    operands[3] = gen_lowpart (SImode, operands[3]);")
17667                         
17668 \f
17669 ;; RTL Peephole optimizations, run before sched2.  These primarily look to
17670 ;; transform a complex memory operation into two memory to register operations.
17671
17672 ;; Don't push memory operands
17673 (define_peephole2
17674   [(set (match_operand:SI 0 "push_operand" "")
17675         (match_operand:SI 1 "memory_operand" ""))
17676    (match_scratch:SI 2 "r")]
17677   "! optimize_size && ! TARGET_PUSH_MEMORY"
17678   [(set (match_dup 2) (match_dup 1))
17679    (set (match_dup 0) (match_dup 2))]
17680   "")
17681
17682 (define_peephole2
17683   [(set (match_operand:DI 0 "push_operand" "")
17684         (match_operand:DI 1 "memory_operand" ""))
17685    (match_scratch:DI 2 "r")]
17686   "! optimize_size && ! TARGET_PUSH_MEMORY"
17687   [(set (match_dup 2) (match_dup 1))
17688    (set (match_dup 0) (match_dup 2))]
17689   "")
17690
17691 ;; We need to handle SFmode only, because DFmode and XFmode is split to
17692 ;; SImode pushes.
17693 (define_peephole2
17694   [(set (match_operand:SF 0 "push_operand" "")
17695         (match_operand:SF 1 "memory_operand" ""))
17696    (match_scratch:SF 2 "r")]
17697   "! optimize_size && ! TARGET_PUSH_MEMORY"
17698   [(set (match_dup 2) (match_dup 1))
17699    (set (match_dup 0) (match_dup 2))]
17700   "")
17701
17702 (define_peephole2
17703   [(set (match_operand:HI 0 "push_operand" "")
17704         (match_operand:HI 1 "memory_operand" ""))
17705    (match_scratch:HI 2 "r")]
17706   "! optimize_size && ! TARGET_PUSH_MEMORY"
17707   [(set (match_dup 2) (match_dup 1))
17708    (set (match_dup 0) (match_dup 2))]
17709   "")
17710
17711 (define_peephole2
17712   [(set (match_operand:QI 0 "push_operand" "")
17713         (match_operand:QI 1 "memory_operand" ""))
17714    (match_scratch:QI 2 "q")]
17715   "! optimize_size && ! TARGET_PUSH_MEMORY"
17716   [(set (match_dup 2) (match_dup 1))
17717    (set (match_dup 0) (match_dup 2))]
17718   "")
17719
17720 ;; Don't move an immediate directly to memory when the instruction
17721 ;; gets too big.
17722 (define_peephole2
17723   [(match_scratch:SI 1 "r")
17724    (set (match_operand:SI 0 "memory_operand" "")
17725         (const_int 0))]
17726   "! optimize_size
17727    && ! TARGET_USE_MOV0
17728    && TARGET_SPLIT_LONG_MOVES
17729    && get_attr_length (insn) >= ix86_cost->large_insn
17730    && peep2_regno_dead_p (0, FLAGS_REG)"
17731   [(parallel [(set (match_dup 1) (const_int 0))
17732               (clobber (reg:CC 17))])
17733    (set (match_dup 0) (match_dup 1))]
17734   "")
17735
17736 (define_peephole2
17737   [(match_scratch:HI 1 "r")
17738    (set (match_operand:HI 0 "memory_operand" "")
17739         (const_int 0))]
17740   "! optimize_size
17741    && ! TARGET_USE_MOV0
17742    && TARGET_SPLIT_LONG_MOVES
17743    && get_attr_length (insn) >= ix86_cost->large_insn
17744    && peep2_regno_dead_p (0, FLAGS_REG)"
17745   [(parallel [(set (match_dup 2) (const_int 0))
17746               (clobber (reg:CC 17))])
17747    (set (match_dup 0) (match_dup 1))]
17748   "operands[2] = gen_rtx_REG (SImode, true_regnum (operands[1]));")
17749
17750 (define_peephole2
17751   [(match_scratch:QI 1 "q")
17752    (set (match_operand:QI 0 "memory_operand" "")
17753         (const_int 0))]
17754   "! optimize_size
17755    && ! TARGET_USE_MOV0
17756    && TARGET_SPLIT_LONG_MOVES
17757    && get_attr_length (insn) >= ix86_cost->large_insn
17758    && peep2_regno_dead_p (0, FLAGS_REG)"
17759   [(parallel [(set (match_dup 2) (const_int 0))
17760               (clobber (reg:CC 17))])
17761    (set (match_dup 0) (match_dup 1))]
17762   "operands[2] = gen_rtx_REG (SImode, true_regnum (operands[1]));")
17763
17764 (define_peephole2
17765   [(match_scratch:SI 2 "r")
17766    (set (match_operand:SI 0 "memory_operand" "")
17767         (match_operand:SI 1 "immediate_operand" ""))]
17768   "! optimize_size
17769    && get_attr_length (insn) >= ix86_cost->large_insn
17770    && TARGET_SPLIT_LONG_MOVES"
17771   [(set (match_dup 2) (match_dup 1))
17772    (set (match_dup 0) (match_dup 2))]
17773   "")
17774
17775 (define_peephole2
17776   [(match_scratch:HI 2 "r")
17777    (set (match_operand:HI 0 "memory_operand" "")
17778         (match_operand:HI 1 "immediate_operand" ""))]
17779   "! optimize_size && get_attr_length (insn) >= ix86_cost->large_insn
17780   && TARGET_SPLIT_LONG_MOVES"
17781   [(set (match_dup 2) (match_dup 1))
17782    (set (match_dup 0) (match_dup 2))]
17783   "")
17784
17785 (define_peephole2
17786   [(match_scratch:QI 2 "q")
17787    (set (match_operand:QI 0 "memory_operand" "")
17788         (match_operand:QI 1 "immediate_operand" ""))]
17789   "! optimize_size && get_attr_length (insn) >= ix86_cost->large_insn
17790   && TARGET_SPLIT_LONG_MOVES"
17791   [(set (match_dup 2) (match_dup 1))
17792    (set (match_dup 0) (match_dup 2))]
17793   "")
17794
17795 ;; Don't compare memory with zero, load and use a test instead.
17796 (define_peephole2
17797   [(set (reg 17)
17798         (compare (match_operand:SI 0 "memory_operand" "")
17799                  (const_int 0)))
17800    (match_scratch:SI 3 "r")]
17801   "ix86_match_ccmode (insn, CCNOmode) && ! optimize_size"
17802   [(set (match_dup 3) (match_dup 0))
17803    (set (reg:CCNO 17) (compare:CCNO (match_dup 3) (const_int 0)))]
17804   "")
17805
17806 ;; NOT is not pairable on Pentium, while XOR is, but one byte longer. 
17807 ;; Don't split NOTs with a displacement operand, because resulting XOR
17808 ;; will not be pairable anyway.
17809 ;;
17810 ;; On AMD K6, NOT is vector decoded with memory operand that can not be
17811 ;; represented using a modRM byte.  The XOR replacement is long decoded,
17812 ;; so this split helps here as well.
17813 ;;
17814 ;; Note: Can't do this as a regular split because we can't get proper
17815 ;; lifetime information then.
17816
17817 (define_peephole2
17818   [(set (match_operand:SI 0 "nonimmediate_operand" "")
17819         (not:SI (match_operand:SI 1 "nonimmediate_operand" "")))]
17820   "!optimize_size
17821    && peep2_regno_dead_p (0, FLAGS_REG)
17822    && ((TARGET_PENTIUM 
17823         && (GET_CODE (operands[0]) != MEM
17824             || !memory_displacement_operand (operands[0], SImode)))
17825        || (TARGET_K6 && long_memory_operand (operands[0], SImode)))"
17826   [(parallel [(set (match_dup 0)
17827                    (xor:SI (match_dup 1) (const_int -1)))
17828               (clobber (reg:CC 17))])]
17829   "")
17830
17831 (define_peephole2
17832   [(set (match_operand:HI 0 "nonimmediate_operand" "")
17833         (not:HI (match_operand:HI 1 "nonimmediate_operand" "")))]
17834   "!optimize_size
17835    && peep2_regno_dead_p (0, FLAGS_REG)
17836    && ((TARGET_PENTIUM 
17837         && (GET_CODE (operands[0]) != MEM
17838             || !memory_displacement_operand (operands[0], HImode)))
17839        || (TARGET_K6 && long_memory_operand (operands[0], HImode)))"
17840   [(parallel [(set (match_dup 0)
17841                    (xor:HI (match_dup 1) (const_int -1)))
17842               (clobber (reg:CC 17))])]
17843   "")
17844
17845 (define_peephole2
17846   [(set (match_operand:QI 0 "nonimmediate_operand" "")
17847         (not:QI (match_operand:QI 1 "nonimmediate_operand" "")))]
17848   "!optimize_size
17849    && peep2_regno_dead_p (0, FLAGS_REG)
17850    && ((TARGET_PENTIUM 
17851         && (GET_CODE (operands[0]) != MEM
17852             || !memory_displacement_operand (operands[0], QImode)))
17853        || (TARGET_K6 && long_memory_operand (operands[0], QImode)))"
17854   [(parallel [(set (match_dup 0)
17855                    (xor:QI (match_dup 1) (const_int -1)))
17856               (clobber (reg:CC 17))])]
17857   "")
17858
17859 ;; Non pairable "test imm, reg" instructions can be translated to
17860 ;; "and imm, reg" if reg dies.  The "and" form is also shorter (one
17861 ;; byte opcode instead of two, have a short form for byte operands),
17862 ;; so do it for other CPUs as well.  Given that the value was dead,
17863 ;; this should not create any new dependencies.  Pass on the sub-word
17864 ;; versions if we're concerned about partial register stalls.
17865
17866 (define_peephole2
17867   [(set (reg 17)
17868         (compare (and:SI (match_operand:SI 0 "register_operand" "")
17869                          (match_operand:SI 1 "immediate_operand" ""))
17870                  (const_int 0)))]
17871   "ix86_match_ccmode (insn, CCNOmode)
17872    && (true_regnum (operands[0]) != 0
17873        || (GET_CODE (operands[1]) == CONST_INT
17874            && CONST_OK_FOR_LETTER_P (INTVAL (operands[1]), 'K')))
17875    && find_regno_note (insn, REG_DEAD, true_regnum (operands[0]))"
17876   [(parallel
17877      [(set (reg:CCNO 17)
17878            (compare:CCNO (and:SI (match_dup 0)
17879                                  (match_dup 1))
17880                          (const_int 0)))
17881       (set (match_dup 0)
17882            (and:SI (match_dup 0) (match_dup 1)))])]
17883   "")
17884
17885 ;; We don't need to handle HImode case, because it will be promoted to SImode
17886 ;; on ! TARGET_PARTIAL_REG_STALL
17887
17888 (define_peephole2
17889   [(set (reg 17)
17890         (compare (and:QI (match_operand:QI 0 "register_operand" "")
17891                          (match_operand:QI 1 "immediate_operand" ""))
17892                  (const_int 0)))]
17893   "! TARGET_PARTIAL_REG_STALL
17894    && ix86_match_ccmode (insn, CCNOmode)
17895    && true_regnum (operands[0]) != 0
17896    && find_regno_note (insn, REG_DEAD, true_regnum (operands[0]))"
17897   [(parallel
17898      [(set (reg:CCNO 17)
17899            (compare:CCNO (and:QI (match_dup 0)
17900                                  (match_dup 1))
17901                          (const_int 0)))
17902       (set (match_dup 0)
17903            (and:QI (match_dup 0) (match_dup 1)))])]
17904   "")
17905
17906 (define_peephole2
17907   [(set (reg 17)
17908         (compare
17909           (and:SI
17910             (zero_extract:SI
17911               (match_operand 0 "ext_register_operand" "")
17912               (const_int 8)
17913               (const_int 8))
17914             (match_operand 1 "const_int_operand" ""))
17915           (const_int 0)))]
17916   "! TARGET_PARTIAL_REG_STALL
17917    && ix86_match_ccmode (insn, CCNOmode)
17918    && true_regnum (operands[0]) != 0
17919    && find_regno_note (insn, REG_DEAD, true_regnum (operands[0]))"
17920   [(parallel [(set (reg:CCNO 17)
17921                    (compare:CCNO
17922                        (and:SI
17923                          (zero_extract:SI
17924                          (match_dup 0)
17925                          (const_int 8)
17926                          (const_int 8))
17927                         (match_dup 1))
17928                    (const_int 0)))
17929               (set (zero_extract:SI (match_dup 0)
17930                                     (const_int 8)
17931                                     (const_int 8))
17932                    (and:SI 
17933                      (zero_extract:SI
17934                        (match_dup 0)
17935                        (const_int 8)
17936                        (const_int 8))
17937                      (match_dup 1)))])]
17938   "")
17939
17940 ;; Don't do logical operations with memory inputs.
17941 (define_peephole2
17942   [(match_scratch:SI 2 "r")
17943    (parallel [(set (match_operand:SI 0 "register_operand" "")
17944                    (match_operator:SI 3 "arith_or_logical_operator"
17945                      [(match_dup 0)
17946                       (match_operand:SI 1 "memory_operand" "")]))
17947               (clobber (reg:CC 17))])]
17948   "! optimize_size && ! TARGET_READ_MODIFY"
17949   [(set (match_dup 2) (match_dup 1))
17950    (parallel [(set (match_dup 0)
17951                    (match_op_dup 3 [(match_dup 0) (match_dup 2)]))
17952               (clobber (reg:CC 17))])]
17953   "")
17954
17955 (define_peephole2
17956   [(match_scratch:SI 2 "r")
17957    (parallel [(set (match_operand:SI 0 "register_operand" "")
17958                    (match_operator:SI 3 "arith_or_logical_operator"
17959                      [(match_operand:SI 1 "memory_operand" "")
17960                       (match_dup 0)]))
17961               (clobber (reg:CC 17))])]
17962   "! optimize_size && ! TARGET_READ_MODIFY"
17963   [(set (match_dup 2) (match_dup 1))
17964    (parallel [(set (match_dup 0)
17965                    (match_op_dup 3 [(match_dup 2) (match_dup 0)]))
17966               (clobber (reg:CC 17))])]
17967   "")
17968
17969 ; Don't do logical operations with memory outputs
17970 ;
17971 ; These two don't make sense for PPro/PII -- we're expanding a 4-uop
17972 ; instruction into two 1-uop insns plus a 2-uop insn.  That last has
17973 ; the same decoder scheduling characteristics as the original.
17974
17975 (define_peephole2
17976   [(match_scratch:SI 2 "r")
17977    (parallel [(set (match_operand:SI 0 "memory_operand" "")
17978                    (match_operator:SI 3 "arith_or_logical_operator"
17979                      [(match_dup 0)
17980                       (match_operand:SI 1 "nonmemory_operand" "")]))
17981               (clobber (reg:CC 17))])]
17982   "! optimize_size && ! TARGET_READ_MODIFY_WRITE"
17983   [(set (match_dup 2) (match_dup 0))
17984    (parallel [(set (match_dup 2)
17985                    (match_op_dup 3 [(match_dup 2) (match_dup 1)]))
17986               (clobber (reg:CC 17))])
17987    (set (match_dup 0) (match_dup 2))]
17988   "")
17989
17990 (define_peephole2
17991   [(match_scratch:SI 2 "r")
17992    (parallel [(set (match_operand:SI 0 "memory_operand" "")
17993                    (match_operator:SI 3 "arith_or_logical_operator"
17994                      [(match_operand:SI 1 "nonmemory_operand" "")
17995                       (match_dup 0)]))
17996               (clobber (reg:CC 17))])]
17997   "! optimize_size && ! TARGET_READ_MODIFY_WRITE"
17998   [(set (match_dup 2) (match_dup 0))
17999    (parallel [(set (match_dup 2)
18000                    (match_op_dup 3 [(match_dup 1) (match_dup 2)]))
18001               (clobber (reg:CC 17))])
18002    (set (match_dup 0) (match_dup 2))]
18003   "")
18004
18005 ;; Attempt to always use XOR for zeroing registers.
18006 (define_peephole2
18007   [(set (match_operand 0 "register_operand" "")
18008         (const_int 0))]
18009   "(GET_MODE (operands[0]) == QImode
18010     || GET_MODE (operands[0]) == HImode
18011     || GET_MODE (operands[0]) == SImode
18012     || (GET_MODE (operands[0]) == DImode && TARGET_64BIT))
18013    && (! TARGET_USE_MOV0 || optimize_size)
18014    && peep2_regno_dead_p (0, FLAGS_REG)"
18015   [(parallel [(set (match_dup 0) (const_int 0))
18016               (clobber (reg:CC 17))])]
18017   "operands[0] = gen_rtx_REG (GET_MODE (operands[0]) == DImode ? DImode : SImode,
18018                               true_regnum (operands[0]));")
18019
18020 (define_peephole2
18021   [(set (strict_low_part (match_operand 0 "register_operand" ""))
18022         (const_int 0))]
18023   "(GET_MODE (operands[0]) == QImode
18024     || GET_MODE (operands[0]) == HImode)
18025    && (! TARGET_USE_MOV0 || optimize_size)
18026    && peep2_regno_dead_p (0, FLAGS_REG)"
18027   [(parallel [(set (strict_low_part (match_dup 0)) (const_int 0))
18028               (clobber (reg:CC 17))])])
18029
18030 ;; For HI and SI modes, or $-1,reg is smaller than mov $-1,reg.
18031 (define_peephole2
18032   [(set (match_operand 0 "register_operand" "")
18033         (const_int -1))]
18034   "(GET_MODE (operands[0]) == HImode
18035     || GET_MODE (operands[0]) == SImode 
18036     || (GET_MODE (operands[0]) == DImode && TARGET_64BIT))
18037    && (optimize_size || TARGET_PENTIUM)
18038    && peep2_regno_dead_p (0, FLAGS_REG)"
18039   [(parallel [(set (match_dup 0) (const_int -1))
18040               (clobber (reg:CC 17))])]
18041   "operands[0] = gen_rtx_REG (GET_MODE (operands[0]) == DImode ? DImode : SImode,
18042                               true_regnum (operands[0]));")
18043
18044 ;; Attempt to convert simple leas to adds. These can be created by
18045 ;; move expanders.
18046 (define_peephole2
18047   [(set (match_operand:SI 0 "register_operand" "")
18048         (plus:SI (match_dup 0)
18049                  (match_operand:SI 1 "nonmemory_operand" "")))]
18050   "peep2_regno_dead_p (0, FLAGS_REG)"
18051   [(parallel [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
18052               (clobber (reg:CC 17))])]
18053   "")
18054
18055 (define_peephole2
18056   [(set (match_operand:SI 0 "register_operand" "")
18057         (subreg:SI (plus:DI (match_operand:DI 1 "register_operand" "")
18058                             (match_operand:DI 2 "nonmemory_operand" "")) 0))]
18059   "peep2_regno_dead_p (0, FLAGS_REG) && REGNO (operands[0]) == REGNO (operands[1])"
18060   [(parallel [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))
18061               (clobber (reg:CC 17))])]
18062   "operands[2] = gen_lowpart (SImode, operands[2]);")
18063
18064 (define_peephole2
18065   [(set (match_operand:DI 0 "register_operand" "")
18066         (plus:DI (match_dup 0)
18067                  (match_operand:DI 1 "x86_64_general_operand" "")))]
18068   "peep2_regno_dead_p (0, FLAGS_REG)"
18069   [(parallel [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
18070               (clobber (reg:CC 17))])]
18071   "")
18072
18073 (define_peephole2
18074   [(set (match_operand:SI 0 "register_operand" "")
18075         (mult:SI (match_dup 0)
18076                  (match_operand:SI 1 "const_int_operand" "")))]
18077   "exact_log2 (INTVAL (operands[1])) >= 0
18078    && peep2_regno_dead_p (0, FLAGS_REG)"
18079   [(parallel [(set (match_dup 0) (ashift:SI (match_dup 0) (match_dup 2)))
18080               (clobber (reg:CC 17))])]
18081   "operands[2] = GEN_INT (exact_log2 (INTVAL (operands[1])));")
18082
18083 (define_peephole2
18084   [(set (match_operand:DI 0 "register_operand" "")
18085         (mult:DI (match_dup 0)
18086                  (match_operand:DI 1 "const_int_operand" "")))]
18087   "exact_log2 (INTVAL (operands[1])) >= 0
18088    && peep2_regno_dead_p (0, FLAGS_REG)"
18089   [(parallel [(set (match_dup 0) (ashift:DI (match_dup 0) (match_dup 2)))
18090               (clobber (reg:CC 17))])]
18091   "operands[2] = GEN_INT (exact_log2 (INTVAL (operands[1])));")
18092
18093 (define_peephole2
18094   [(set (match_operand:SI 0 "register_operand" "")
18095         (subreg:SI (mult:DI (match_operand:DI 1 "register_operand" "")
18096                    (match_operand:DI 2 "const_int_operand" "")) 0))]
18097   "exact_log2 (INTVAL (operands[2])) >= 0
18098    && REGNO (operands[0]) == REGNO (operands[1])
18099    && peep2_regno_dead_p (0, FLAGS_REG)"
18100   [(parallel [(set (match_dup 0) (ashift:SI (match_dup 0) (match_dup 2)))
18101               (clobber (reg:CC 17))])]
18102   "operands[2] = GEN_INT (exact_log2 (INTVAL (operands[2])));")
18103
18104 ;; The ESP adjustments can be done by the push and pop instructions.  Resulting
18105 ;; code is shorter, since push is only 1 byte, while add imm, %esp 3 bytes.  On
18106 ;; many CPUs it is also faster, since special hardware to avoid esp
18107 ;; dependencies is present.
18108
18109 ;; While some of these conversions may be done using splitters, we use peepholes
18110 ;; in order to allow combine_stack_adjustments pass to see nonobfuscated RTL.
18111
18112 ;; Convert prologue esp subtractions to push.
18113 ;; We need register to push.  In order to keep verify_flow_info happy we have
18114 ;; two choices
18115 ;; - use scratch and clobber it in order to avoid dependencies
18116 ;; - use already live register
18117 ;; We can't use the second way right now, since there is no reliable way how to
18118 ;; verify that given register is live.  First choice will also most likely in
18119 ;; fewer dependencies.  On the place of esp adjustments it is very likely that
18120 ;; call clobbered registers are dead.  We may want to use base pointer as an
18121 ;; alternative when no register is available later.
18122
18123 (define_peephole2
18124   [(match_scratch:SI 0 "r")
18125    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -4)))
18126               (clobber (reg:CC 17))
18127               (clobber (mem:BLK (scratch)))])]
18128   "optimize_size || !TARGET_SUB_ESP_4"
18129   [(clobber (match_dup 0))
18130    (parallel [(set (mem:SI (pre_dec:SI (reg:SI 7))) (match_dup 0))
18131               (clobber (mem:BLK (scratch)))])])
18132
18133 (define_peephole2
18134   [(match_scratch:SI 0 "r")
18135    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -8)))
18136               (clobber (reg:CC 17))
18137               (clobber (mem:BLK (scratch)))])]
18138   "optimize_size || !TARGET_SUB_ESP_8"
18139   [(clobber (match_dup 0))
18140    (set (mem:SI (pre_dec:SI (reg:SI 7))) (match_dup 0))
18141    (parallel [(set (mem:SI (pre_dec:SI (reg:SI 7))) (match_dup 0))
18142               (clobber (mem:BLK (scratch)))])])
18143
18144 ;; Convert esp subtractions to push.
18145 (define_peephole2
18146   [(match_scratch:SI 0 "r")
18147    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -4)))
18148               (clobber (reg:CC 17))])]
18149   "optimize_size || !TARGET_SUB_ESP_4"
18150   [(clobber (match_dup 0))
18151    (set (mem:SI (pre_dec:SI (reg:SI 7))) (match_dup 0))])
18152
18153 (define_peephole2
18154   [(match_scratch:SI 0 "r")
18155    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -8)))
18156               (clobber (reg:CC 17))])]
18157   "optimize_size || !TARGET_SUB_ESP_8"
18158   [(clobber (match_dup 0))
18159    (set (mem:SI (pre_dec:SI (reg:SI 7))) (match_dup 0))
18160    (set (mem:SI (pre_dec:SI (reg:SI 7))) (match_dup 0))])
18161
18162 ;; Convert epilogue deallocator to pop.
18163 (define_peephole2
18164   [(match_scratch:SI 0 "r")
18165    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))
18166               (clobber (reg:CC 17))
18167               (clobber (mem:BLK (scratch)))])]
18168   "optimize_size || !TARGET_ADD_ESP_4"
18169   [(parallel [(set (match_dup 0) (mem:SI (reg:SI 7)))
18170               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))
18171               (clobber (mem:BLK (scratch)))])]
18172   "")
18173
18174 ;; Two pops case is tricky, since pop causes dependency on destination register.
18175 ;; We use two registers if available.
18176 (define_peephole2
18177   [(match_scratch:SI 0 "r")
18178    (match_scratch:SI 1 "r")
18179    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 8)))
18180               (clobber (reg:CC 17))
18181               (clobber (mem:BLK (scratch)))])]
18182   "optimize_size || !TARGET_ADD_ESP_8"
18183   [(parallel [(set (match_dup 0) (mem:SI (reg:SI 7)))
18184               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))
18185               (clobber (mem:BLK (scratch)))])
18186    (parallel [(set (match_dup 1) (mem:SI (reg:SI 7)))
18187               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))])]
18188   "")
18189
18190 (define_peephole2
18191   [(match_scratch:SI 0 "r")
18192    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 8)))
18193               (clobber (reg:CC 17))
18194               (clobber (mem:BLK (scratch)))])]
18195   "optimize_size"
18196   [(parallel [(set (match_dup 0) (mem:SI (reg:SI 7)))
18197               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))
18198               (clobber (mem:BLK (scratch)))])
18199    (parallel [(set (match_dup 0) (mem:SI (reg:SI 7)))
18200               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))])]
18201   "")
18202
18203 ;; Convert esp additions to pop.
18204 (define_peephole2
18205   [(match_scratch:SI 0 "r")
18206    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))
18207               (clobber (reg:CC 17))])]
18208   ""
18209   [(parallel [(set (match_dup 0) (mem:SI (reg:SI 7)))
18210               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))])]
18211   "")
18212
18213 ;; Two pops case is tricky, since pop causes dependency on destination register.
18214 ;; We use two registers if available.
18215 (define_peephole2
18216   [(match_scratch:SI 0 "r")
18217    (match_scratch:SI 1 "r")
18218    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 8)))
18219               (clobber (reg:CC 17))])]
18220   ""
18221   [(parallel [(set (match_dup 0) (mem:SI (reg:SI 7)))
18222               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))])
18223    (parallel [(set (match_dup 1) (mem:SI (reg:SI 7)))
18224               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))])]
18225   "")
18226
18227 (define_peephole2
18228   [(match_scratch:SI 0 "r")
18229    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 8)))
18230               (clobber (reg:CC 17))])]
18231   "optimize_size"
18232   [(parallel [(set (match_dup 0) (mem:SI (reg:SI 7)))
18233               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))])
18234    (parallel [(set (match_dup 0) (mem:SI (reg:SI 7)))
18235               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))])]
18236   "")
18237 \f
18238 ;; Convert compares with 1 to shorter inc/dec operations when CF is not
18239 ;; required and register dies.
18240 (define_peephole2
18241   [(set (reg 17)
18242         (compare (match_operand:SI 0 "register_operand" "")
18243                  (match_operand:SI 1 "incdec_operand" "")))]
18244   "ix86_match_ccmode (insn, CCGCmode)
18245    && find_regno_note (insn, REG_DEAD, true_regnum (operands[0]))"
18246   [(parallel [(set (reg:CCGC 17)
18247                    (compare:CCGC (match_dup 0)
18248                                  (match_dup 1)))
18249               (clobber (match_dup 0))])]
18250   "")
18251
18252 (define_peephole2
18253   [(set (reg 17)
18254         (compare (match_operand:HI 0 "register_operand" "")
18255                  (match_operand:HI 1 "incdec_operand" "")))]
18256   "ix86_match_ccmode (insn, CCGCmode)
18257    && find_regno_note (insn, REG_DEAD, true_regnum (operands[0]))"
18258   [(parallel [(set (reg:CCGC 17)
18259                    (compare:CCGC (match_dup 0)
18260                                  (match_dup 1)))
18261               (clobber (match_dup 0))])]
18262   "")
18263
18264 (define_peephole2
18265   [(set (reg 17)
18266         (compare (match_operand:QI 0 "register_operand" "")
18267                  (match_operand:QI 1 "incdec_operand" "")))]
18268   "ix86_match_ccmode (insn, CCGCmode)
18269    && find_regno_note (insn, REG_DEAD, true_regnum (operands[0]))"
18270   [(parallel [(set (reg:CCGC 17)
18271                    (compare:CCGC (match_dup 0)
18272                                  (match_dup 1)))
18273               (clobber (match_dup 0))])]
18274   "")
18275
18276 ;; Convert compares with 128 to shorter add -128
18277 (define_peephole2
18278   [(set (reg 17)
18279         (compare (match_operand:SI 0 "register_operand" "")
18280                  (const_int 128)))]
18281   "ix86_match_ccmode (insn, CCGCmode)
18282    && find_regno_note (insn, REG_DEAD, true_regnum (operands[0]))"
18283   [(parallel [(set (reg:CCGC 17)
18284                    (compare:CCGC (match_dup 0)
18285                                  (const_int 128)))
18286               (clobber (match_dup 0))])]
18287   "")
18288
18289 (define_peephole2
18290   [(set (reg 17)
18291         (compare (match_operand:HI 0 "register_operand" "")
18292                  (const_int 128)))]
18293   "ix86_match_ccmode (insn, CCGCmode)
18294    && find_regno_note (insn, REG_DEAD, true_regnum (operands[0]))"
18295   [(parallel [(set (reg:CCGC 17)
18296                    (compare:CCGC (match_dup 0)
18297                                  (const_int 128)))
18298               (clobber (match_dup 0))])]
18299   "")
18300 \f
18301 (define_peephole2
18302   [(match_scratch:DI 0 "r")
18303    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -8)))
18304               (clobber (reg:CC 17))
18305               (clobber (mem:BLK (scratch)))])]
18306   "optimize_size || !TARGET_SUB_ESP_4"
18307   [(clobber (match_dup 0))
18308    (parallel [(set (mem:DI (pre_dec:DI (reg:DI 7))) (match_dup 0))
18309               (clobber (mem:BLK (scratch)))])])
18310
18311 (define_peephole2
18312   [(match_scratch:DI 0 "r")
18313    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -16)))
18314               (clobber (reg:CC 17))
18315               (clobber (mem:BLK (scratch)))])]
18316   "optimize_size || !TARGET_SUB_ESP_8"
18317   [(clobber (match_dup 0))
18318    (set (mem:DI (pre_dec:DI (reg:DI 7))) (match_dup 0))
18319    (parallel [(set (mem:DI (pre_dec:DI (reg:DI 7))) (match_dup 0))
18320               (clobber (mem:BLK (scratch)))])])
18321
18322 ;; Convert esp subtractions to push.
18323 (define_peephole2
18324   [(match_scratch:DI 0 "r")
18325    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -8)))
18326               (clobber (reg:CC 17))])]
18327   "optimize_size || !TARGET_SUB_ESP_4"
18328   [(clobber (match_dup 0))
18329    (set (mem:DI (pre_dec:DI (reg:DI 7))) (match_dup 0))])
18330
18331 (define_peephole2
18332   [(match_scratch:DI 0 "r")
18333    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -16)))
18334               (clobber (reg:CC 17))])]
18335   "optimize_size || !TARGET_SUB_ESP_8"
18336   [(clobber (match_dup 0))
18337    (set (mem:DI (pre_dec:DI (reg:DI 7))) (match_dup 0))
18338    (set (mem:DI (pre_dec:DI (reg:DI 7))) (match_dup 0))])
18339
18340 ;; Convert epilogue deallocator to pop.
18341 (define_peephole2
18342   [(match_scratch:DI 0 "r")
18343    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))
18344               (clobber (reg:CC 17))
18345               (clobber (mem:BLK (scratch)))])]
18346   "optimize_size || !TARGET_ADD_ESP_4"
18347   [(parallel [(set (match_dup 0) (mem:DI (reg:DI 7)))
18348               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))
18349               (clobber (mem:BLK (scratch)))])]
18350   "")
18351
18352 ;; Two pops case is tricky, since pop causes dependency on destination register.
18353 ;; We use two registers if available.
18354 (define_peephole2
18355   [(match_scratch:DI 0 "r")
18356    (match_scratch:DI 1 "r")
18357    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 16)))
18358               (clobber (reg:CC 17))
18359               (clobber (mem:BLK (scratch)))])]
18360   "optimize_size || !TARGET_ADD_ESP_8"
18361   [(parallel [(set (match_dup 0) (mem:DI (reg:DI 7)))
18362               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))
18363               (clobber (mem:BLK (scratch)))])
18364    (parallel [(set (match_dup 1) (mem:DI (reg:DI 7)))
18365               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))])]
18366   "")
18367
18368 (define_peephole2
18369   [(match_scratch:DI 0 "r")
18370    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 16)))
18371               (clobber (reg:CC 17))
18372               (clobber (mem:BLK (scratch)))])]
18373   "optimize_size"
18374   [(parallel [(set (match_dup 0) (mem:DI (reg:DI 7)))
18375               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))
18376               (clobber (mem:BLK (scratch)))])
18377    (parallel [(set (match_dup 0) (mem:DI (reg:DI 7)))
18378               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))])]
18379   "")
18380
18381 ;; Convert esp additions to pop.
18382 (define_peephole2
18383   [(match_scratch:DI 0 "r")
18384    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))
18385               (clobber (reg:CC 17))])]
18386   ""
18387   [(parallel [(set (match_dup 0) (mem:DI (reg:DI 7)))
18388               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))])]
18389   "")
18390
18391 ;; Two pops case is tricky, since pop causes dependency on destination register.
18392 ;; We use two registers if available.
18393 (define_peephole2
18394   [(match_scratch:DI 0 "r")
18395    (match_scratch:DI 1 "r")
18396    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 16)))
18397               (clobber (reg:CC 17))])]
18398   ""
18399   [(parallel [(set (match_dup 0) (mem:DI (reg:DI 7)))
18400               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))])
18401    (parallel [(set (match_dup 1) (mem:DI (reg:DI 7)))
18402               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))])]
18403   "")
18404
18405 (define_peephole2
18406   [(match_scratch:DI 0 "r")
18407    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 16)))
18408               (clobber (reg:CC 17))])]
18409   "optimize_size"
18410   [(parallel [(set (match_dup 0) (mem:DI (reg:DI 7)))
18411               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))])
18412    (parallel [(set (match_dup 0) (mem:DI (reg:DI 7)))
18413               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))])]
18414   "")
18415 \f
18416 ;; Imul $32bit_imm, mem, reg is vector decoded, while
18417 ;; imul $32bit_imm, reg, reg is direct decoded.
18418 (define_peephole2
18419   [(match_scratch:DI 3 "r")
18420    (parallel [(set (match_operand:DI 0 "register_operand" "")
18421                    (mult:DI (match_operand:DI 1 "memory_operand" "")
18422                             (match_operand:DI 2 "immediate_operand" "")))
18423               (clobber (reg:CC 17))])]
18424   "TARGET_K8 && !optimize_size
18425    && (GET_CODE (operands[2]) != CONST_INT
18426        || !CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'K'))"
18427   [(set (match_dup 3) (match_dup 1))
18428    (parallel [(set (match_dup 0) (mult:DI (match_dup 3) (match_dup 2)))
18429               (clobber (reg:CC 17))])]
18430 "")
18431
18432 (define_peephole2
18433   [(match_scratch:SI 3 "r")
18434    (parallel [(set (match_operand:SI 0 "register_operand" "")
18435                    (mult:SI (match_operand:SI 1 "memory_operand" "")
18436                             (match_operand:SI 2 "immediate_operand" "")))
18437               (clobber (reg:CC 17))])]
18438   "TARGET_K8 && !optimize_size
18439    && (GET_CODE (operands[2]) != CONST_INT
18440        || !CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'K'))"
18441   [(set (match_dup 3) (match_dup 1))
18442    (parallel [(set (match_dup 0) (mult:SI (match_dup 3) (match_dup 2)))
18443               (clobber (reg:CC 17))])]
18444 "")
18445
18446 (define_peephole2
18447   [(match_scratch:SI 3 "r")
18448    (parallel [(set (match_operand:DI 0 "register_operand" "")
18449                    (zero_extend:DI
18450                      (mult:SI (match_operand:SI 1 "memory_operand" "")
18451                               (match_operand:SI 2 "immediate_operand" ""))))
18452               (clobber (reg:CC 17))])]
18453   "TARGET_K8 && !optimize_size
18454    && (GET_CODE (operands[2]) != CONST_INT
18455        || !CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'K'))"
18456   [(set (match_dup 3) (match_dup 1))
18457    (parallel [(set (match_dup 0) (zero_extend:DI (mult:SI (match_dup 3) (match_dup 2))))
18458               (clobber (reg:CC 17))])]
18459 "")
18460
18461 ;; imul $8/16bit_imm, regmem, reg is vector decoded.
18462 ;; Convert it into imul reg, reg
18463 ;; It would be better to force assembler to encode instruction using long
18464 ;; immediate, but there is apparently no way to do so.
18465 (define_peephole2
18466   [(parallel [(set (match_operand:DI 0 "register_operand" "")
18467                    (mult:DI (match_operand:DI 1 "nonimmediate_operand" "")
18468                             (match_operand:DI 2 "const_int_operand" "")))
18469               (clobber (reg:CC 17))])
18470    (match_scratch:DI 3 "r")]
18471   "TARGET_K8 && !optimize_size
18472    && CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'K')"
18473   [(set (match_dup 3) (match_dup 2))
18474    (parallel [(set (match_dup 0) (mult:DI (match_dup 0) (match_dup 3)))
18475               (clobber (reg:CC 17))])]
18476 {
18477   if (!rtx_equal_p (operands[0], operands[1]))
18478     emit_move_insn (operands[0], operands[1]);
18479 })
18480
18481 (define_peephole2
18482   [(parallel [(set (match_operand:SI 0 "register_operand" "")
18483                    (mult:SI (match_operand:SI 1 "nonimmediate_operand" "")
18484                             (match_operand:SI 2 "const_int_operand" "")))
18485               (clobber (reg:CC 17))])
18486    (match_scratch:SI 3 "r")]
18487   "TARGET_K8 && !optimize_size
18488    && CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'K')"
18489   [(set (match_dup 3) (match_dup 2))
18490    (parallel [(set (match_dup 0) (mult:SI (match_dup 0) (match_dup 3)))
18491               (clobber (reg:CC 17))])]
18492 {
18493   if (!rtx_equal_p (operands[0], operands[1]))
18494     emit_move_insn (operands[0], operands[1]);
18495 })
18496
18497 (define_peephole2
18498   [(parallel [(set (match_operand:HI 0 "register_operand" "")
18499                    (mult:HI (match_operand:HI 1 "nonimmediate_operand" "")
18500                             (match_operand:HI 2 "immediate_operand" "")))
18501               (clobber (reg:CC 17))])
18502    (match_scratch:HI 3 "r")]
18503   "TARGET_K8 && !optimize_size"
18504   [(set (match_dup 3) (match_dup 2))
18505    (parallel [(set (match_dup 0) (mult:HI (match_dup 0) (match_dup 3)))
18506               (clobber (reg:CC 17))])]
18507 {
18508   if (!rtx_equal_p (operands[0], operands[1]))
18509     emit_move_insn (operands[0], operands[1]);
18510 })
18511 \f
18512 ;; Call-value patterns last so that the wildcard operand does not
18513 ;; disrupt insn-recog's switch tables.
18514
18515 (define_insn "*call_value_pop_0"
18516   [(set (match_operand 0 "" "")
18517         (call (mem:QI (match_operand:SI 1 "constant_call_address_operand" ""))
18518               (match_operand:SI 2 "" "")))
18519    (set (reg:SI 7) (plus:SI (reg:SI 7)
18520                             (match_operand:SI 3 "immediate_operand" "")))]
18521   "!TARGET_64BIT"
18522 {
18523   if (SIBLING_CALL_P (insn))
18524     return "jmp\t%P1";
18525   else
18526     return "call\t%P1";
18527 }
18528   [(set_attr "type" "callv")])
18529
18530 (define_insn "*call_value_pop_1"
18531   [(set (match_operand 0 "" "")
18532         (call (mem:QI (match_operand:SI 1 "call_insn_operand" "rsm"))
18533               (match_operand:SI 2 "" "")))
18534    (set (reg:SI 7) (plus:SI (reg:SI 7)
18535                             (match_operand:SI 3 "immediate_operand" "i")))]
18536   "!TARGET_64BIT"
18537 {
18538   if (constant_call_address_operand (operands[1], QImode))
18539     {
18540       if (SIBLING_CALL_P (insn))
18541         return "jmp\t%P1";
18542       else
18543         return "call\t%P1";
18544     }
18545   if (SIBLING_CALL_P (insn))
18546     return "jmp\t%A1";
18547   else
18548     return "call\t%A1";
18549 }
18550   [(set_attr "type" "callv")])
18551
18552 (define_insn "*call_value_0"
18553   [(set (match_operand 0 "" "")
18554         (call (mem:QI (match_operand:SI 1 "constant_call_address_operand" ""))
18555               (match_operand:SI 2 "" "")))]
18556   "!TARGET_64BIT"
18557 {
18558   if (SIBLING_CALL_P (insn))
18559     return "jmp\t%P1";
18560   else
18561     return "call\t%P1";
18562 }
18563   [(set_attr "type" "callv")])
18564
18565 (define_insn "*call_value_0_rex64"
18566   [(set (match_operand 0 "" "")
18567         (call (mem:QI (match_operand:DI 1 "constant_call_address_operand" ""))
18568               (match_operand:DI 2 "const_int_operand" "")))]
18569   "TARGET_64BIT"
18570 {
18571   if (SIBLING_CALL_P (insn))
18572     return "jmp\t%P1";
18573   else
18574     return "call\t%P1";
18575 }
18576   [(set_attr "type" "callv")])
18577
18578 (define_insn "*call_value_1"
18579   [(set (match_operand 0 "" "")
18580         (call (mem:QI (match_operand:SI 1 "call_insn_operand" "rsm"))
18581               (match_operand:SI 2 "" "")))]
18582   "!SIBLING_CALL_P (insn) && !TARGET_64BIT"
18583 {
18584   if (constant_call_address_operand (operands[1], QImode))
18585     return "call\t%P1";
18586   return "call\t%*%1";
18587 }
18588   [(set_attr "type" "callv")])
18589
18590 (define_insn "*sibcall_value_1"
18591   [(set (match_operand 0 "" "")
18592         (call (mem:QI (match_operand:SI 1 "sibcall_insn_operand" "s,c,d,a"))
18593               (match_operand:SI 2 "" "")))]
18594   "SIBLING_CALL_P (insn) && !TARGET_64BIT"
18595 {
18596   if (constant_call_address_operand (operands[1], QImode))
18597     return "jmp\t%P1";
18598   return "jmp\t%*%1";
18599 }
18600   [(set_attr "type" "callv")])
18601
18602 (define_insn "*call_value_1_rex64"
18603   [(set (match_operand 0 "" "")
18604         (call (mem:QI (match_operand:DI 1 "call_insn_operand" "rsm"))
18605               (match_operand:DI 2 "" "")))]
18606   "!SIBLING_CALL_P (insn) && TARGET_64BIT"
18607 {
18608   if (constant_call_address_operand (operands[1], QImode))
18609     return "call\t%P1";
18610   return "call\t%A1";
18611 }
18612   [(set_attr "type" "callv")])
18613
18614 (define_insn "*sibcall_value_1_rex64"
18615   [(set (match_operand 0 "" "")
18616         (call (mem:QI (match_operand:DI 1 "constant_call_address_operand" ""))
18617               (match_operand:DI 2 "" "")))]
18618   "SIBLING_CALL_P (insn) && TARGET_64BIT"
18619   "jmp\t%P1"
18620   [(set_attr "type" "callv")])
18621
18622 (define_insn "*sibcall_value_1_rex64_v"
18623   [(set (match_operand 0 "" "")
18624         (call (mem:QI (reg:DI 40))
18625               (match_operand:DI 1 "" "")))]
18626   "SIBLING_CALL_P (insn) && TARGET_64BIT"
18627   "jmp\t*%%r11"
18628   [(set_attr "type" "callv")])
18629 \f
18630 (define_insn "trap"
18631   [(trap_if (const_int 1) (const_int 5))]
18632   ""
18633   "int\t$5")
18634
18635 ;;; ix86 doesn't have conditional trap instructions, but we fake them
18636 ;;; for the sake of bounds checking.  By emitting bounds checks as
18637 ;;; conditional traps rather than as conditional jumps around
18638 ;;; unconditional traps we avoid introducing spurious basic-block
18639 ;;; boundaries and facilitate elimination of redundant checks.  In
18640 ;;; honor of the too-inflexible-for-BPs `bound' instruction, we use
18641 ;;; interrupt 5.
18642 ;;; 
18643 ;;; FIXME: Static branch prediction rules for ix86 are such that
18644 ;;; forward conditional branches predict as untaken.  As implemented
18645 ;;; below, pseudo conditional traps violate that rule.  We should use
18646 ;;; .pushsection/.popsection to place all of the `int 5's in a special
18647 ;;; section loaded at the end of the text segment and branch forward
18648 ;;; there on bounds-failure, and then jump back immediately (in case
18649 ;;; the system chooses to ignore bounds violations, or to report
18650 ;;; violations and continue execution).
18651
18652 (define_expand "conditional_trap"
18653   [(trap_if (match_operator 0 "comparison_operator"
18654              [(match_dup 2) (const_int 0)])
18655             (match_operand 1 "const_int_operand" ""))]
18656   ""
18657 {
18658   emit_insn (gen_rtx_TRAP_IF (VOIDmode,
18659                               ix86_expand_compare (GET_CODE (operands[0]),
18660                                                    NULL, NULL),
18661                               operands[1]));
18662   DONE;
18663 })
18664
18665 (define_insn "*conditional_trap_1"
18666   [(trap_if (match_operator 0 "comparison_operator"
18667              [(reg 17) (const_int 0)])
18668             (match_operand 1 "const_int_operand" ""))]
18669   ""
18670 {
18671   operands[2] = gen_label_rtx ();
18672   output_asm_insn ("j%c0\t%l2\; int\t%1", operands);
18673   (*targetm.asm_out.internal_label) (asm_out_file, "L",
18674                              CODE_LABEL_NUMBER (operands[2]));
18675   RET;
18676 })
18677
18678         ;; Pentium III SIMD instructions.
18679
18680 ;; Moves for SSE/MMX regs.
18681
18682 (define_insn "movv4sf_internal"
18683   [(set (match_operand:V4SF 0 "nonimmediate_operand" "=x,m")
18684         (match_operand:V4SF 1 "nonimmediate_operand" "xm,x"))]
18685   "TARGET_SSE"
18686   "movaps\t{%1, %0|%0, %1}"
18687   [(set_attr "type" "ssemov")
18688    (set_attr "mode" "V4SF")])
18689
18690 (define_split
18691   [(set (match_operand:V4SF 0 "register_operand" "")
18692         (match_operand:V4SF 1 "zero_extended_scalar_load_operand" ""))]
18693   "TARGET_SSE"
18694   [(set (match_dup 0)
18695         (vec_merge:V4SF
18696          (vec_duplicate:V4SF (match_dup 1))
18697          (match_dup 2)
18698          (const_int 1)))]
18699 {
18700   operands[1] = simplify_gen_subreg (SFmode, operands[1], V4SFmode, 0);
18701   operands[2] = CONST0_RTX (V4SFmode);
18702 })
18703
18704 (define_insn "movv4si_internal"
18705   [(set (match_operand:V4SI 0 "nonimmediate_operand" "=x,m")
18706         (match_operand:V4SI 1 "nonimmediate_operand" "xm,x"))]
18707   "TARGET_SSE"
18708 {
18709   if (get_attr_mode (insn) == MODE_V4SF)
18710     return "movaps\t{%1, %0|%0, %1}";
18711   else
18712     return "movdqa\t{%1, %0|%0, %1}";
18713 }
18714   [(set_attr "type" "ssemov")
18715    (set (attr "mode")
18716         (cond [(eq_attr "alternative" "0")
18717                  (if_then_else
18718                    (ne (symbol_ref "optimize_size")
18719                        (const_int 0))
18720                    (const_string "V4SF")
18721                    (const_string "TI"))
18722                (eq_attr "alternative" "1")
18723                  (if_then_else
18724                    (ior (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
18725                             (const_int 0))
18726                         (ne (symbol_ref "optimize_size")
18727                             (const_int 0)))
18728                    (const_string "V4SF")
18729                    (const_string "TI"))]
18730                (const_string "TI")))])
18731
18732 (define_insn "movv2di_internal"
18733   [(set (match_operand:V2DI 0 "nonimmediate_operand" "=x,m")
18734         (match_operand:V2DI 1 "nonimmediate_operand" "xm,x"))]
18735   "TARGET_SSE2"
18736 {
18737   if (get_attr_mode (insn) == MODE_V4SF)
18738     return "movaps\t{%1, %0|%0, %1}";
18739   else
18740     return "movdqa\t{%1, %0|%0, %1}";
18741 }
18742   [(set_attr "type" "ssemov")
18743    (set (attr "mode")
18744         (cond [(eq_attr "alternative" "0")
18745                  (if_then_else
18746                    (ne (symbol_ref "optimize_size")
18747                        (const_int 0))
18748                    (const_string "V4SF")
18749                    (const_string "TI"))
18750                (eq_attr "alternative" "1")
18751                  (if_then_else
18752                    (ior (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
18753                             (const_int 0))
18754                         (ne (symbol_ref "optimize_size")
18755                             (const_int 0)))
18756                    (const_string "V4SF")
18757                    (const_string "TI"))]
18758                (const_string "TI")))])
18759
18760 (define_split
18761   [(set (match_operand:V2DF 0 "register_operand" "")
18762         (match_operand:V2DF 1 "zero_extended_scalar_load_operand" ""))]
18763   "TARGET_SSE2"
18764   [(set (match_dup 0)
18765         (vec_merge:V2DF
18766          (vec_duplicate:V2DF (match_dup 1))
18767          (match_dup 2)
18768          (const_int 1)))]
18769 {
18770   operands[1] = simplify_gen_subreg (DFmode, operands[1], V2DFmode, 0);
18771   operands[2] = CONST0_RTX (V2DFmode);
18772 })
18773
18774 (define_insn "movv8qi_internal"
18775   [(set (match_operand:V8QI 0 "nonimmediate_operand" "=y,m")
18776         (match_operand:V8QI 1 "nonimmediate_operand" "ym,y"))]
18777   "TARGET_MMX
18778    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
18779   "movq\t{%1, %0|%0, %1}"
18780   [(set_attr "type" "mmxmov")
18781    (set_attr "mode" "DI")])
18782
18783 (define_insn "movv4hi_internal"
18784   [(set (match_operand:V4HI 0 "nonimmediate_operand" "=y,m")
18785         (match_operand:V4HI 1 "nonimmediate_operand" "ym,y"))]
18786   "TARGET_MMX
18787    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
18788   "movq\t{%1, %0|%0, %1}"
18789   [(set_attr "type" "mmxmov")
18790    (set_attr "mode" "DI")])
18791
18792 (define_insn "movv2si_internal"
18793   [(set (match_operand:V2SI 0 "nonimmediate_operand" "=y,m")
18794         (match_operand:V2SI 1 "nonimmediate_operand" "ym,y"))]
18795   "TARGET_MMX
18796    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
18797   "movq\t{%1, %0|%0, %1}"
18798   [(set_attr "type" "mmxcvt")
18799    (set_attr "mode" "DI")])
18800
18801 (define_insn "movv2sf_internal"
18802   [(set (match_operand:V2SF 0 "nonimmediate_operand" "=y,m")
18803         (match_operand:V2SF 1 "nonimmediate_operand" "ym,y"))]
18804   "TARGET_3DNOW
18805    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
18806   "movq\\t{%1, %0|%0, %1}"
18807   [(set_attr "type" "mmxcvt")
18808    (set_attr "mode" "DI")])
18809
18810 (define_expand "movti"
18811   [(set (match_operand:TI 0 "nonimmediate_operand" "")
18812         (match_operand:TI 1 "nonimmediate_operand" ""))]
18813   "TARGET_SSE || TARGET_64BIT"
18814 {
18815   if (TARGET_64BIT)
18816     ix86_expand_move (TImode, operands);
18817   else
18818     ix86_expand_vector_move (TImode, operands);
18819   DONE;
18820 })
18821
18822 (define_insn "movv2df_internal"
18823   [(set (match_operand:V2DF 0 "nonimmediate_operand" "=x,m")
18824         (match_operand:V2DF 1 "nonimmediate_operand" "xm,x"))]
18825   "TARGET_SSE2
18826    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
18827 {
18828   if (get_attr_mode (insn) == MODE_V4SF)
18829     return "movaps\t{%1, %0|%0, %1}";
18830   else
18831     return "movapd\t{%1, %0|%0, %1}";
18832 }
18833   [(set_attr "type" "ssemov")
18834    (set (attr "mode")
18835         (cond [(eq_attr "alternative" "0")
18836                  (if_then_else
18837                    (ne (symbol_ref "optimize_size")
18838                        (const_int 0))
18839                    (const_string "V4SF")
18840                    (const_string "V2DF"))
18841                (eq_attr "alternative" "1")
18842                  (if_then_else
18843                    (ior (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
18844                             (const_int 0))
18845                         (ne (symbol_ref "optimize_size")
18846                             (const_int 0)))
18847                    (const_string "V4SF")
18848                    (const_string "V2DF"))]
18849                (const_string "V2DF")))])
18850
18851 (define_insn "movv8hi_internal"
18852   [(set (match_operand:V8HI 0 "nonimmediate_operand" "=x,m")
18853         (match_operand:V8HI 1 "nonimmediate_operand" "xm,x"))]
18854   "TARGET_SSE2
18855    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
18856 {
18857   if (get_attr_mode (insn) == MODE_V4SF)
18858     return "movaps\t{%1, %0|%0, %1}";
18859   else
18860     return "movdqa\t{%1, %0|%0, %1}";
18861 }
18862   [(set_attr "type" "ssemov")
18863    (set (attr "mode")
18864         (cond [(eq_attr "alternative" "0")
18865                  (if_then_else
18866                    (ne (symbol_ref "optimize_size")
18867                        (const_int 0))
18868                    (const_string "V4SF")
18869                    (const_string "TI"))
18870                (eq_attr "alternative" "1")
18871                  (if_then_else
18872                    (ior (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
18873                             (const_int 0))
18874                         (ne (symbol_ref "optimize_size")
18875                             (const_int 0)))
18876                    (const_string "V4SF")
18877                    (const_string "TI"))]
18878                (const_string "TI")))])
18879
18880 (define_insn "movv16qi_internal"
18881   [(set (match_operand:V16QI 0 "nonimmediate_operand" "=x,m")
18882         (match_operand:V16QI 1 "nonimmediate_operand" "xm,x"))]
18883   "TARGET_SSE2
18884    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
18885 {
18886   if (get_attr_mode (insn) == MODE_V4SF)
18887     return "movaps\t{%1, %0|%0, %1}";
18888   else
18889     return "movdqa\t{%1, %0|%0, %1}";
18890 }
18891   [(set_attr "type" "ssemov")
18892    (set (attr "mode")
18893         (cond [(eq_attr "alternative" "0")
18894                  (if_then_else
18895                    (ne (symbol_ref "optimize_size")
18896                        (const_int 0))
18897                    (const_string "V4SF")
18898                    (const_string "TI"))
18899                (eq_attr "alternative" "1")
18900                  (if_then_else
18901                    (ior (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
18902                             (const_int 0))
18903                         (ne (symbol_ref "optimize_size")
18904                             (const_int 0)))
18905                    (const_string "V4SF")
18906                    (const_string "TI"))]
18907                (const_string "TI")))])
18908
18909 (define_expand "movv2df"
18910   [(set (match_operand:V2DF 0 "nonimmediate_operand" "")
18911         (match_operand:V2DF 1 "nonimmediate_operand" ""))]
18912   "TARGET_SSE2"
18913 {
18914   ix86_expand_vector_move (V2DFmode, operands);
18915   DONE;
18916 })
18917
18918 (define_expand "movv8hi"
18919   [(set (match_operand:V8HI 0 "nonimmediate_operand" "")
18920         (match_operand:V8HI 1 "nonimmediate_operand" ""))]
18921   "TARGET_SSE2"
18922 {
18923   ix86_expand_vector_move (V8HImode, operands);
18924   DONE;
18925 })
18926
18927 (define_expand "movv16qi"
18928   [(set (match_operand:V16QI 0 "nonimmediate_operand" "")
18929         (match_operand:V16QI 1 "nonimmediate_operand" ""))]
18930   "TARGET_SSE2"
18931 {
18932   ix86_expand_vector_move (V16QImode, operands);
18933   DONE;
18934 })
18935
18936 (define_expand "movv4sf"
18937   [(set (match_operand:V4SF 0 "nonimmediate_operand" "")
18938         (match_operand:V4SF 1 "nonimmediate_operand" ""))]
18939   "TARGET_SSE"
18940 {
18941   ix86_expand_vector_move (V4SFmode, operands);
18942   DONE;
18943 })
18944
18945 (define_expand "movv4si"
18946   [(set (match_operand:V4SI 0 "nonimmediate_operand" "")
18947         (match_operand:V4SI 1 "nonimmediate_operand" ""))]
18948   "TARGET_SSE"
18949 {
18950   ix86_expand_vector_move (V4SImode, operands);
18951   DONE;
18952 })
18953
18954 (define_expand "movv2di"
18955   [(set (match_operand:V2DI 0 "nonimmediate_operand" "")
18956         (match_operand:V2DI 1 "nonimmediate_operand" ""))]
18957   "TARGET_SSE"
18958 {
18959   ix86_expand_vector_move (V2DImode, operands);
18960   DONE;
18961 })
18962
18963 (define_expand "movv2si"
18964   [(set (match_operand:V2SI 0 "nonimmediate_operand" "")
18965         (match_operand:V2SI 1 "nonimmediate_operand" ""))]
18966   "TARGET_MMX"
18967 {
18968   ix86_expand_vector_move (V2SImode, operands);
18969   DONE;
18970 })
18971
18972 (define_expand "movv4hi"
18973   [(set (match_operand:V4HI 0 "nonimmediate_operand" "")
18974         (match_operand:V4HI 1 "nonimmediate_operand" ""))]
18975   "TARGET_MMX"
18976 {
18977   ix86_expand_vector_move (V4HImode, operands);
18978   DONE;
18979 })
18980
18981 (define_expand "movv8qi"
18982   [(set (match_operand:V8QI 0 "nonimmediate_operand" "")
18983         (match_operand:V8QI 1 "nonimmediate_operand" ""))]
18984   "TARGET_MMX"
18985 {
18986   ix86_expand_vector_move (V8QImode, operands);
18987   DONE;
18988 })
18989
18990 (define_expand "movv2sf"
18991   [(set (match_operand:V2SF 0 "nonimmediate_operand" "")
18992         (match_operand:V2SF 1 "nonimmediate_operand" ""))]
18993    "TARGET_3DNOW"
18994 {
18995   ix86_expand_vector_move (V2SFmode, operands);
18996   DONE;
18997 })
18998
18999 (define_insn "*pushti"
19000   [(set (match_operand:TI 0 "push_operand" "=<")
19001         (match_operand:TI 1 "register_operand" "x"))]
19002   "TARGET_SSE"
19003   "#")
19004
19005 (define_insn "*pushv2df"
19006   [(set (match_operand:V2DF 0 "push_operand" "=<")
19007         (match_operand:V2DF 1 "register_operand" "x"))]
19008   "TARGET_SSE"
19009   "#")
19010
19011 (define_insn "*pushv2di"
19012   [(set (match_operand:V2DI 0 "push_operand" "=<")
19013         (match_operand:V2DI 1 "register_operand" "x"))]
19014   "TARGET_SSE2"
19015   "#")
19016
19017 (define_insn "*pushv8hi"
19018   [(set (match_operand:V8HI 0 "push_operand" "=<")
19019         (match_operand:V8HI 1 "register_operand" "x"))]
19020   "TARGET_SSE2"
19021   "#")
19022
19023 (define_insn "*pushv16qi"
19024   [(set (match_operand:V16QI 0 "push_operand" "=<")
19025         (match_operand:V16QI 1 "register_operand" "x"))]
19026   "TARGET_SSE2"
19027   "#")
19028
19029 (define_insn "*pushv4sf"
19030   [(set (match_operand:V4SF 0 "push_operand" "=<")
19031         (match_operand:V4SF 1 "register_operand" "x"))]
19032   "TARGET_SSE"
19033   "#")
19034
19035 (define_insn "*pushv4si"
19036   [(set (match_operand:V4SI 0 "push_operand" "=<")
19037         (match_operand:V4SI 1 "register_operand" "x"))]
19038   "TARGET_SSE2"
19039   "#")
19040
19041 (define_insn "*pushv2si"
19042   [(set (match_operand:V2SI 0 "push_operand" "=<")
19043         (match_operand:V2SI 1 "register_operand" "y"))]
19044   "TARGET_MMX"
19045   "#")
19046
19047 (define_insn "*pushv4hi"
19048   [(set (match_operand:V4HI 0 "push_operand" "=<")
19049         (match_operand:V4HI 1 "register_operand" "y"))]
19050   "TARGET_MMX"
19051   "#")
19052
19053 (define_insn "*pushv8qi"
19054   [(set (match_operand:V8QI 0 "push_operand" "=<")
19055         (match_operand:V8QI 1 "register_operand" "y"))]
19056   "TARGET_MMX"
19057   "#")
19058
19059 (define_insn "*pushv2sf"
19060   [(set (match_operand:V2SF 0 "push_operand" "=<")
19061         (match_operand:V2SF 1 "register_operand" "y"))]
19062   "TARGET_3DNOW"
19063   "#")
19064
19065 (define_split
19066   [(set (match_operand 0 "push_operand" "")
19067         (match_operand 1 "register_operand" ""))]
19068   "!TARGET_64BIT && reload_completed
19069    && (SSE_REG_P (operands[1]) || MMX_REG_P (operands[1]))"
19070   [(set (reg:SI 7) (plus:SI (reg:SI 7) (match_dup 3)))
19071    (set (match_dup 2) (match_dup 1))]
19072   "operands[2] = change_address (operands[0], GET_MODE (operands[0]),
19073                                  stack_pointer_rtx);
19074    operands[3] = GEN_INT (-GET_MODE_SIZE (GET_MODE (operands[0])));")
19075
19076 (define_split
19077   [(set (match_operand 0 "push_operand" "")
19078         (match_operand 1 "register_operand" ""))]
19079   "TARGET_64BIT && reload_completed
19080    && (SSE_REG_P (operands[1]) || MMX_REG_P (operands[1]))"
19081   [(set (reg:DI 7) (plus:DI (reg:DI 7) (match_dup 3)))
19082    (set (match_dup 2) (match_dup 1))]
19083   "operands[2] = change_address (operands[0], GET_MODE (operands[0]),
19084                                  stack_pointer_rtx);
19085    operands[3] = GEN_INT (-GET_MODE_SIZE (GET_MODE (operands[0])));")
19086
19087
19088 (define_insn "movti_internal"
19089   [(set (match_operand:TI 0 "nonimmediate_operand" "=x,x,m")
19090         (match_operand:TI 1 "general_operand" "C,xm,x"))]
19091   "TARGET_SSE && !TARGET_64BIT
19092    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
19093 {
19094   switch (which_alternative)
19095     {
19096     case 0:
19097       if (get_attr_mode (insn) == MODE_V4SF)
19098         return "xorps\t%0, %0";
19099       else
19100         return "pxor\t%0, %0";
19101     case 1:
19102     case 2:
19103       if (get_attr_mode (insn) == MODE_V4SF)
19104         return "movaps\t{%1, %0|%0, %1}";
19105       else
19106         return "movdqa\t{%1, %0|%0, %1}";
19107     default:
19108       abort ();
19109     }
19110 }
19111   [(set_attr "type" "ssemov,ssemov,ssemov")
19112    (set (attr "mode")
19113         (cond [(eq_attr "alternative" "0,1")
19114                  (if_then_else
19115                    (ne (symbol_ref "optimize_size")
19116                        (const_int 0))
19117                    (const_string "V4SF")
19118                    (const_string "TI"))
19119                (eq_attr "alternative" "2")
19120                  (if_then_else
19121                    (ne (symbol_ref "optimize_size")
19122                        (const_int 0))
19123                    (const_string "V4SF")
19124                    (const_string "TI"))]
19125                (const_string "TI")))])
19126
19127 (define_insn "*movti_rex64"
19128   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,o,x,x,xm")
19129         (match_operand:TI 1 "general_operand" "riFo,riF,C,xm,x"))]
19130   "TARGET_64BIT
19131    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
19132 {
19133   switch (which_alternative)
19134     {
19135     case 0:
19136     case 1:
19137       return "#";
19138     case 2:
19139       if (get_attr_mode (insn) == MODE_V4SF)
19140         return "xorps\t%0, %0";
19141       else
19142         return "pxor\t%0, %0";
19143     case 3:
19144     case 4:
19145       if (get_attr_mode (insn) == MODE_V4SF)
19146         return "movaps\t{%1, %0|%0, %1}";
19147       else
19148         return "movdqa\t{%1, %0|%0, %1}";
19149     default:
19150       abort ();
19151     }
19152 }
19153   [(set_attr "type" "*,*,ssemov,ssemov,ssemov")
19154    (set (attr "mode")
19155         (cond [(eq_attr "alternative" "2,3")
19156                  (if_then_else
19157                    (ne (symbol_ref "optimize_size")
19158                        (const_int 0))
19159                    (const_string "V4SF")
19160                    (const_string "TI"))
19161                (eq_attr "alternative" "4")
19162                  (if_then_else
19163                    (ior (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
19164                             (const_int 0))
19165                         (ne (symbol_ref "optimize_size")
19166                             (const_int 0)))
19167                    (const_string "V4SF")
19168                    (const_string "TI"))]
19169                (const_string "DI")))])
19170
19171 (define_split
19172   [(set (match_operand:TI 0 "nonimmediate_operand" "")
19173         (match_operand:TI 1 "general_operand" ""))]
19174   "reload_completed && !SSE_REG_P (operands[0])
19175    && !SSE_REG_P (operands[1])"
19176   [(const_int 0)]
19177   "ix86_split_long_move (operands); DONE;")
19178
19179 ;; These two patterns are useful for specifying exactly whether to use
19180 ;; movaps or movups
19181 (define_insn "sse_movaps"
19182   [(set (match_operand:V4SF 0 "nonimmediate_operand" "=x,m")
19183         (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "xm,x")]
19184                      UNSPEC_MOVA))]
19185   "TARGET_SSE
19186    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
19187   "movaps\t{%1, %0|%0, %1}"
19188   [(set_attr "type" "ssemov,ssemov")
19189    (set_attr "mode" "V4SF")])
19190
19191 (define_insn "sse_movups"
19192   [(set (match_operand:V4SF 0 "nonimmediate_operand" "=x,m")
19193         (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "xm,x")]
19194                      UNSPEC_MOVU))]
19195   "TARGET_SSE
19196    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
19197   "movups\t{%1, %0|%0, %1}"
19198   [(set_attr "type" "ssecvt,ssecvt")
19199    (set_attr "mode" "V4SF")])
19200
19201
19202 ;; SSE Strange Moves.
19203
19204 (define_insn "sse_movmskps"
19205   [(set (match_operand:SI 0 "register_operand" "=r")
19206         (unspec:SI [(match_operand:V4SF 1 "register_operand" "x")]
19207                    UNSPEC_MOVMSK))]
19208   "TARGET_SSE"
19209   "movmskps\t{%1, %0|%0, %1}"
19210   [(set_attr "type" "ssecvt")
19211    (set_attr "mode" "V4SF")])
19212
19213 (define_insn "mmx_pmovmskb"
19214   [(set (match_operand:SI 0 "register_operand" "=r")
19215         (unspec:SI [(match_operand:V8QI 1 "register_operand" "y")]
19216                    UNSPEC_MOVMSK))]
19217   "TARGET_SSE || TARGET_3DNOW_A"
19218   "pmovmskb\t{%1, %0|%0, %1}"
19219   [(set_attr "type" "ssecvt")
19220    (set_attr "mode" "V4SF")])
19221
19222
19223 (define_insn "mmx_maskmovq"
19224   [(set (mem:V8QI (match_operand:SI 0 "register_operand" "D"))
19225         (unspec:V8QI [(match_operand:V8QI 1 "register_operand" "y")
19226                       (match_operand:V8QI 2 "register_operand" "y")]
19227                      UNSPEC_MASKMOV))]
19228   "(TARGET_SSE || TARGET_3DNOW_A) && !TARGET_64BIT"
19229   ;; @@@ check ordering of operands in intel/nonintel syntax
19230   "maskmovq\t{%2, %1|%1, %2}"
19231   [(set_attr "type" "mmxcvt")
19232    (set_attr "mode" "DI")])
19233
19234 (define_insn "mmx_maskmovq_rex"
19235   [(set (mem:V8QI (match_operand:DI 0 "register_operand" "D"))
19236         (unspec:V8QI [(match_operand:V8QI 1 "register_operand" "y")
19237                       (match_operand:V8QI 2 "register_operand" "y")]
19238                      UNSPEC_MASKMOV))]
19239   "(TARGET_SSE || TARGET_3DNOW_A) && TARGET_64BIT"
19240   ;; @@@ check ordering of operands in intel/nonintel syntax
19241   "maskmovq\t{%2, %1|%1, %2}"
19242   [(set_attr "type" "mmxcvt")
19243    (set_attr "mode" "DI")])
19244
19245 (define_insn "sse_movntv4sf"
19246   [(set (match_operand:V4SF 0 "memory_operand" "=m")
19247         (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "x")]
19248                      UNSPEC_MOVNT))]
19249   "TARGET_SSE"
19250   "movntps\t{%1, %0|%0, %1}"
19251   [(set_attr "type" "ssemov")
19252    (set_attr "mode" "V4SF")])
19253
19254 (define_insn "sse_movntdi"
19255   [(set (match_operand:DI 0 "memory_operand" "=m")
19256         (unspec:DI [(match_operand:DI 1 "register_operand" "y")]
19257                    UNSPEC_MOVNT))]
19258   "TARGET_SSE || TARGET_3DNOW_A"
19259   "movntq\t{%1, %0|%0, %1}"
19260   [(set_attr "type" "mmxmov")
19261    (set_attr "mode" "DI")])
19262
19263 (define_insn "sse_movhlps"
19264   [(set (match_operand:V4SF 0 "register_operand" "=x")
19265         (vec_merge:V4SF
19266          (match_operand:V4SF 1 "register_operand" "0")
19267          (vec_select:V4SF (match_operand:V4SF 2 "register_operand" "x")
19268                           (parallel [(const_int 2)
19269                                      (const_int 3)
19270                                      (const_int 0)
19271                                      (const_int 1)]))
19272          (const_int 3)))]
19273   "TARGET_SSE"
19274   "movhlps\t{%2, %0|%0, %2}"
19275   [(set_attr "type" "ssecvt")
19276    (set_attr "mode" "V4SF")])
19277
19278 (define_insn "sse_movlhps"
19279   [(set (match_operand:V4SF 0 "register_operand" "=x")
19280         (vec_merge:V4SF
19281          (match_operand:V4SF 1 "register_operand" "0")
19282          (vec_select:V4SF (match_operand:V4SF 2 "register_operand" "x")
19283                           (parallel [(const_int 2)
19284                                      (const_int 3)
19285                                      (const_int 0)
19286                                      (const_int 1)]))
19287          (const_int 12)))]
19288   "TARGET_SSE"
19289   "movlhps\t{%2, %0|%0, %2}"
19290   [(set_attr "type" "ssecvt")
19291    (set_attr "mode" "V4SF")])
19292
19293 (define_insn "sse_movhps"
19294   [(set (match_operand:V4SF 0 "nonimmediate_operand" "=x,m")
19295         (vec_merge:V4SF
19296          (match_operand:V4SF 1 "nonimmediate_operand" "0,0")
19297          (match_operand:V4SF 2 "nonimmediate_operand" "m,x")
19298          (const_int 12)))]
19299   "TARGET_SSE
19300    && (GET_CODE (operands[1]) == MEM || GET_CODE (operands[2]) == MEM)"
19301   "movhps\t{%2, %0|%0, %2}"
19302   [(set_attr "type" "ssecvt")
19303    (set_attr "mode" "V4SF")])
19304
19305 (define_insn "sse_movlps"
19306   [(set (match_operand:V4SF 0 "nonimmediate_operand" "=x,m")
19307         (vec_merge:V4SF
19308          (match_operand:V4SF 1 "nonimmediate_operand" "0,0")
19309          (match_operand:V4SF 2 "nonimmediate_operand" "m,x")
19310          (const_int 3)))]
19311   "TARGET_SSE
19312    && (GET_CODE (operands[1]) == MEM || GET_CODE (operands[2]) == MEM)"
19313   "movlps\t{%2, %0|%0, %2}"
19314   [(set_attr "type" "ssecvt")
19315    (set_attr "mode" "V4SF")])
19316
19317 (define_expand "sse_loadss"
19318   [(match_operand:V4SF 0 "register_operand" "")
19319    (match_operand:SF 1 "memory_operand" "")]
19320   "TARGET_SSE"
19321 {
19322   emit_insn (gen_sse_loadss_1 (operands[0], operands[1],
19323                                CONST0_RTX (V4SFmode)));
19324   DONE;
19325 })
19326
19327 (define_insn "sse_loadss_1"
19328   [(set (match_operand:V4SF 0 "register_operand" "=x")
19329         (vec_merge:V4SF
19330          (vec_duplicate:V4SF (match_operand:SF 1 "memory_operand" "m"))
19331          (match_operand:V4SF 2 "const0_operand" "X")
19332          (const_int 1)))]
19333   "TARGET_SSE"
19334   "movss\t{%1, %0|%0, %1}"
19335   [(set_attr "type" "ssemov")
19336    (set_attr "mode" "SF")])
19337
19338 (define_insn "sse_movss"
19339   [(set (match_operand:V4SF 0 "register_operand" "=x")
19340         (vec_merge:V4SF
19341          (match_operand:V4SF 1 "register_operand" "0")
19342          (match_operand:V4SF 2 "register_operand" "x")
19343          (const_int 1)))]
19344   "TARGET_SSE"
19345   "movss\t{%2, %0|%0, %2}"
19346   [(set_attr "type" "ssemov")
19347    (set_attr "mode" "SF")])
19348
19349 (define_insn "sse_storess"
19350   [(set (match_operand:SF 0 "memory_operand" "=m")
19351         (vec_select:SF
19352          (match_operand:V4SF 1 "register_operand" "x")
19353          (parallel [(const_int 0)])))]
19354   "TARGET_SSE"
19355   "movss\t{%1, %0|%0, %1}"
19356   [(set_attr "type" "ssemov")
19357    (set_attr "mode" "SF")])
19358
19359 (define_insn "sse_shufps"
19360   [(set (match_operand:V4SF 0 "register_operand" "=x")
19361         (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "0")
19362                       (match_operand:V4SF 2 "nonimmediate_operand" "xm")
19363                       (match_operand:SI 3 "immediate_operand" "i")]
19364                      UNSPEC_SHUFFLE))]
19365   "TARGET_SSE"
19366   ;; @@@ check operand order for intel/nonintel syntax
19367   "shufps\t{%3, %2, %0|%0, %2, %3}"
19368   [(set_attr "type" "ssecvt")
19369    (set_attr "mode" "V4SF")])
19370
19371
19372 ;; SSE arithmetic
19373
19374 (define_insn "addv4sf3"
19375   [(set (match_operand:V4SF 0 "register_operand" "=x")
19376         (plus:V4SF (match_operand:V4SF 1 "register_operand" "0")
19377                    (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
19378   "TARGET_SSE"
19379   "addps\t{%2, %0|%0, %2}"
19380   [(set_attr "type" "sseadd")
19381    (set_attr "mode" "V4SF")])
19382
19383 (define_insn "vmaddv4sf3"
19384   [(set (match_operand:V4SF 0 "register_operand" "=x")
19385         (vec_merge:V4SF
19386          (plus:V4SF (match_operand:V4SF 1 "register_operand" "0")
19387                     (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
19388          (match_dup 1)
19389          (const_int 1)))]
19390   "TARGET_SSE"
19391   "addss\t{%2, %0|%0, %2}"
19392   [(set_attr "type" "sseadd")
19393    (set_attr "mode" "SF")])
19394
19395 (define_insn "subv4sf3"
19396   [(set (match_operand:V4SF 0 "register_operand" "=x")
19397         (minus:V4SF (match_operand:V4SF 1 "register_operand" "0")
19398                     (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
19399   "TARGET_SSE"
19400   "subps\t{%2, %0|%0, %2}"
19401   [(set_attr "type" "sseadd")
19402    (set_attr "mode" "V4SF")])
19403
19404 (define_insn "vmsubv4sf3"
19405   [(set (match_operand:V4SF 0 "register_operand" "=x")
19406         (vec_merge:V4SF
19407          (minus:V4SF (match_operand:V4SF 1 "register_operand" "0")
19408                      (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
19409          (match_dup 1)
19410          (const_int 1)))]
19411   "TARGET_SSE"
19412   "subss\t{%2, %0|%0, %2}"
19413   [(set_attr "type" "sseadd")
19414    (set_attr "mode" "SF")])
19415
19416 (define_insn "mulv4sf3"
19417   [(set (match_operand:V4SF 0 "register_operand" "=x")
19418         (mult:V4SF (match_operand:V4SF 1 "register_operand" "0")
19419                    (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
19420   "TARGET_SSE"
19421   "mulps\t{%2, %0|%0, %2}"
19422   [(set_attr "type" "ssemul")
19423    (set_attr "mode" "V4SF")])
19424
19425 (define_insn "vmmulv4sf3"
19426   [(set (match_operand:V4SF 0 "register_operand" "=x")
19427         (vec_merge:V4SF
19428          (mult:V4SF (match_operand:V4SF 1 "register_operand" "0")
19429                     (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
19430          (match_dup 1)
19431          (const_int 1)))]
19432   "TARGET_SSE"
19433   "mulss\t{%2, %0|%0, %2}"
19434   [(set_attr "type" "ssemul")
19435    (set_attr "mode" "SF")])
19436
19437 (define_insn "divv4sf3"
19438   [(set (match_operand:V4SF 0 "register_operand" "=x")
19439         (div:V4SF (match_operand:V4SF 1 "register_operand" "0")
19440                   (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
19441   "TARGET_SSE"
19442   "divps\t{%2, %0|%0, %2}"
19443   [(set_attr "type" "ssediv")
19444    (set_attr "mode" "V4SF")])
19445
19446 (define_insn "vmdivv4sf3"
19447   [(set (match_operand:V4SF 0 "register_operand" "=x")
19448         (vec_merge:V4SF
19449          (div:V4SF (match_operand:V4SF 1 "register_operand" "0")
19450                    (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
19451          (match_dup 1)
19452          (const_int 1)))]
19453   "TARGET_SSE"
19454   "divss\t{%2, %0|%0, %2}"
19455   [(set_attr "type" "ssediv")
19456    (set_attr "mode" "SF")])
19457
19458
19459 ;; SSE square root/reciprocal
19460
19461 (define_insn "rcpv4sf2"
19462   [(set (match_operand:V4SF 0 "register_operand" "=x")
19463         (unspec:V4SF
19464          [(match_operand:V4SF 1 "nonimmediate_operand" "xm")] UNSPEC_RCP))]
19465   "TARGET_SSE"
19466   "rcpps\t{%1, %0|%0, %1}"
19467   [(set_attr "type" "sse")
19468    (set_attr "mode" "V4SF")])
19469
19470 (define_insn "vmrcpv4sf2"
19471   [(set (match_operand:V4SF 0 "register_operand" "=x")
19472         (vec_merge:V4SF
19473          (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "xm")]
19474                       UNSPEC_RCP)
19475          (match_operand:V4SF 2 "register_operand" "0")
19476          (const_int 1)))]
19477   "TARGET_SSE"
19478   "rcpss\t{%1, %0|%0, %1}"
19479   [(set_attr "type" "sse")
19480    (set_attr "mode" "SF")])
19481
19482 (define_insn "rsqrtv4sf2"
19483   [(set (match_operand:V4SF 0 "register_operand" "=x")
19484         (unspec:V4SF
19485          [(match_operand:V4SF 1 "nonimmediate_operand" "xm")] UNSPEC_RSQRT))]
19486   "TARGET_SSE"
19487   "rsqrtps\t{%1, %0|%0, %1}"
19488   [(set_attr "type" "sse")
19489    (set_attr "mode" "V4SF")])
19490
19491 (define_insn "vmrsqrtv4sf2"
19492   [(set (match_operand:V4SF 0 "register_operand" "=x")
19493         (vec_merge:V4SF
19494          (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "xm")]
19495                       UNSPEC_RSQRT)
19496          (match_operand:V4SF 2 "register_operand" "0")
19497          (const_int 1)))]
19498   "TARGET_SSE"
19499   "rsqrtss\t{%1, %0|%0, %1}"
19500   [(set_attr "type" "sse")
19501    (set_attr "mode" "SF")])
19502
19503 (define_insn "sqrtv4sf2"
19504   [(set (match_operand:V4SF 0 "register_operand" "=x")
19505         (sqrt:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "xm")))]
19506   "TARGET_SSE"
19507   "sqrtps\t{%1, %0|%0, %1}"
19508   [(set_attr "type" "sse")
19509    (set_attr "mode" "V4SF")])
19510
19511 (define_insn "vmsqrtv4sf2"
19512   [(set (match_operand:V4SF 0 "register_operand" "=x")
19513         (vec_merge:V4SF
19514          (sqrt:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "xm"))
19515          (match_operand:V4SF 2 "register_operand" "0")
19516          (const_int 1)))]
19517   "TARGET_SSE"
19518   "sqrtss\t{%1, %0|%0, %1}"
19519   [(set_attr "type" "sse")
19520    (set_attr "mode" "SF")])
19521
19522 ;; SSE logical operations.
19523
19524 ;; SSE defines logical operations on floating point values.  This brings
19525 ;; interesting challenge to RTL representation where logicals are only valid
19526 ;; on integral types.  We deal with this by representing the floating point
19527 ;; logical as logical on arguments casted to TImode as this is what hardware
19528 ;; really does.  Unfortunately hardware requires the type information to be
19529 ;; present and thus we must avoid subregs from being simplified and eliminated
19530 ;; in later compilation phases.
19531 ;;
19532 ;; We have following variants from each instruction:
19533 ;; sse_andsf3 - the operation taking V4SF vector operands
19534 ;;              and doing TImode cast on them
19535 ;; *sse_andsf3_memory - the operation taking one memory operand casted to
19536 ;;                      TImode, since backend insist on eliminating casts
19537 ;;                      on memory operands
19538 ;; sse_andti3_sf_1 - the operation taking SF scalar operands.
19539 ;;                   We can not accept memory operand here as instruction reads
19540 ;;                   whole scalar.  This is generated only post reload by GCC
19541 ;;                   scalar float operations that expands to logicals (fabs)
19542 ;; sse_andti3_sf_2 - the operation taking SF scalar input and TImode
19543 ;;                   memory operand.  Eventually combine can be able
19544 ;;                   to synthesize these using splitter.
19545 ;; sse2_anddf3, *sse2_anddf3_memory
19546 ;;              
19547 ;; 
19548 ;; These are not called andti3 etc. because we really really don't want
19549 ;; the compiler to widen DImode ands to TImode ands and then try to move
19550 ;; into DImode subregs of SSE registers, and them together, and move out
19551 ;; of DImode subregs again!
19552 ;; SSE1 single precision floating point logical operation
19553 (define_expand "sse_andv4sf3"
19554   [(set (subreg:TI (match_operand:V4SF 0 "register_operand" "") 0)
19555         (and:TI (subreg:TI (match_operand:V4SF 1 "register_operand" "") 0)
19556                 (subreg:TI (match_operand:V4SF 2 "nonimmediate_operand" "") 0)))]
19557   "TARGET_SSE"
19558   "")
19559
19560 (define_insn "*sse_andv4sf3"
19561   [(set (subreg:TI (match_operand:V4SF 0 "register_operand" "=x") 0)
19562         (and:TI (match_operand:TI 1 "nonimmediate_operand" "%0")
19563                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19564   "TARGET_SSE
19565    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19566   "andps\t{%2, %0|%0, %2}"
19567   [(set_attr "type" "sselog")
19568    (set_attr "mode" "V4SF")])
19569
19570 (define_insn "*sse_andsf3"
19571   [(set (subreg:TI (match_operand:SF 0 "register_operand" "=x") 0)
19572         (and:TI (match_operand:TI 1 "nonimmediate_operand" "%0")
19573                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19574   "TARGET_SSE
19575    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19576   "andps\t{%2, %0|%0, %2}"
19577   [(set_attr "type" "sselog")
19578    (set_attr "mode" "V4SF")])
19579
19580 (define_expand "sse_nandv4sf3"
19581   [(set (subreg:TI (match_operand:V4SF 0 "register_operand" "") 0)
19582         (and:TI (not:TI (subreg:TI (match_operand:V4SF 1 "register_operand" "") 0))
19583                 (subreg:TI (match_operand:V4SF 2 "nonimmediate_operand" "") 0)))]
19584   "TARGET_SSE"
19585   "")
19586
19587 (define_insn "*sse_nandv4sf3"
19588   [(set (subreg:TI (match_operand:V4SF 0 "register_operand" "=x") 0)
19589         (and:TI (not:TI (match_operand:TI 1 "register_operand" "0"))
19590                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19591   "TARGET_SSE"
19592   "andnps\t{%2, %0|%0, %2}"
19593   [(set_attr "type" "sselog")
19594    (set_attr "mode" "V4SF")])
19595
19596 (define_insn "*sse_nandsf3"
19597   [(set (subreg:TI (match_operand:SF 0 "register_operand" "=x") 0)
19598         (and:TI (not:TI (match_operand:TI 1 "register_operand" "0"))
19599                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19600   "TARGET_SSE"
19601   "andnps\t{%2, %0|%0, %2}"
19602   [(set_attr "type" "sselog")
19603    (set_attr "mode" "V4SF")])
19604
19605 (define_expand "sse_iorv4sf3"
19606   [(set (subreg:TI (match_operand:V4SF 0 "register_operand" "") 0)
19607         (ior:TI (subreg:TI (match_operand:V4SF 1 "register_operand" "") 0)
19608                 (subreg:TI (match_operand:V4SF 2 "nonimmediate_operand" "") 0)))]
19609   "TARGET_SSE"
19610   "")
19611
19612 (define_insn "*sse_iorv4sf3"
19613   [(set (subreg:TI (match_operand:V4SF 0 "register_operand" "=x") 0)
19614         (ior:TI (match_operand:TI 1 "nonimmediate_operand" "%0")
19615                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19616   "TARGET_SSE
19617    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19618   "orps\t{%2, %0|%0, %2}"
19619   [(set_attr "type" "sselog")
19620    (set_attr "mode" "V4SF")])
19621
19622 (define_insn "*sse_iorsf3"
19623   [(set (subreg:TI (match_operand:SF 0 "register_operand" "=x") 0)
19624         (ior:TI (match_operand:TI 1 "nonimmediate_operand" "%0")
19625                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19626   "TARGET_SSE
19627    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19628   "orps\t{%2, %0|%0, %2}"
19629   [(set_attr "type" "sselog")
19630    (set_attr "mode" "V4SF")])
19631
19632 (define_expand "sse_xorv4sf3"
19633   [(set (subreg:TI (match_operand:V4SF 0 "register_operand" "") 0)
19634         (xor:TI (subreg:TI (match_operand:V4SF 1 "register_operand" "") 0)
19635                 (subreg:TI (match_operand:V4SF 2 "nonimmediate_operand" "") 0)))]
19636   "TARGET_SSE
19637    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19638   "")
19639
19640 (define_insn "*sse_xorv4sf3"
19641   [(set (subreg:TI (match_operand:V4SF 0 "register_operand" "=x") 0)
19642         (xor:TI (match_operand:TI 1 "nonimmediate_operand" "%0")
19643                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19644   "TARGET_SSE
19645    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19646   "xorps\t{%2, %0|%0, %2}"
19647   [(set_attr "type" "sselog")
19648    (set_attr "mode" "V4SF")])
19649
19650 (define_insn "*sse_xorsf3"
19651   [(set (subreg:TI (match_operand:SF 0 "register_operand" "=x") 0)
19652         (xor:TI (match_operand:TI 1 "nonimmediate_operand" "%0")
19653                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19654   "TARGET_SSE
19655    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19656   "xorps\t{%2, %0|%0, %2}"
19657   [(set_attr "type" "sselog")
19658    (set_attr "mode" "V4SF")])
19659
19660 ;; SSE2 double precision floating point logical operation
19661
19662 (define_expand "sse2_andv2df3"
19663   [(set (subreg:TI (match_operand:V2DF 0 "register_operand" "") 0)
19664         (and:TI (subreg:TI (match_operand:V2DF 1 "register_operand" "") 0)
19665                 (subreg:TI (match_operand:V2DF 2 "nonimmediate_operand" "") 0)))]
19666   "TARGET_SSE2"
19667   "")
19668
19669 (define_insn "*sse2_andv2df3"
19670   [(set (subreg:TI (match_operand:V2DF 0 "register_operand" "=x") 0)
19671         (and:TI (match_operand:TI 1 "nonimmediate_operand" "%0")
19672                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19673   "TARGET_SSE2
19674    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19675   "andpd\t{%2, %0|%0, %2}"
19676   [(set_attr "type" "sselog")
19677    (set_attr "mode" "V2DF")])
19678
19679 (define_insn "*sse2_andv2df3"
19680   [(set (subreg:TI (match_operand:DF 0 "register_operand" "=x") 0)
19681         (and:TI (match_operand:TI 1 "nonimmediate_operand" "%0")
19682                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19683   "TARGET_SSE2
19684    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19685   "andpd\t{%2, %0|%0, %2}"
19686   [(set_attr "type" "sselog")
19687    (set_attr "mode" "V2DF")])
19688
19689 (define_expand "sse2_nandv2df3"
19690   [(set (subreg:TI (match_operand:V2DF 0 "register_operand" "") 0)
19691         (and:TI (not:TI (subreg:TI (match_operand:V2DF 1 "register_operand" "") 0))
19692                 (subreg:TI (match_operand:V2DF 2 "nonimmediate_operand" "") 0)))]
19693   "TARGET_SSE2"
19694   "")
19695
19696 (define_insn "*sse2_nandv2df3"
19697   [(set (subreg:TI (match_operand:V2DF 0 "register_operand" "=x") 0)
19698         (and:TI (not:TI (match_operand:TI 1 "register_operand" "0"))
19699                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19700   "TARGET_SSE2"
19701   "andnpd\t{%2, %0|%0, %2}"
19702   [(set_attr "type" "sselog")
19703    (set_attr "mode" "V2DF")])
19704
19705 (define_insn "*sse_nandti3_df"
19706   [(set (subreg:TI (match_operand:DF 0 "register_operand" "=Y") 0)
19707         (and:TI (not:TI (match_operand:TI 1 "register_operand" "0"))
19708                 (match_operand:TI 2 "nonimmediate_operand" "Ym")))]
19709   "TARGET_SSE2"
19710   "andnpd\t{%2, %0|%0, %2}"
19711   [(set_attr "type" "sselog")
19712    (set_attr "mode" "V2DF")])
19713
19714 (define_expand "sse2_iorv2df3"
19715   [(set (subreg:TI (match_operand:V2DF 0 "register_operand" "") 0)
19716         (ior:TI (subreg:TI (match_operand:V2DF 1 "register_operand" "") 0)
19717                 (subreg:TI (match_operand:V2DF 2 "nonimmediate_operand" "") 0)))]
19718   "TARGET_SSE2"
19719   "")
19720
19721 (define_insn "*sse2_iorv2df3"
19722   [(set (subreg:TI (match_operand:V2DF 0 "register_operand" "=x") 0)
19723         (ior:TI (match_operand:TI 1 "nonimmediate_operand" "%0")
19724                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19725   "TARGET_SSE2
19726    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19727   "orpd\t{%2, %0|%0, %2}"
19728   [(set_attr "type" "sselog")
19729    (set_attr "mode" "V2DF")])
19730
19731 (define_insn "*sse2_iordf3"
19732   [(set (subreg:TI (match_operand:DF 0 "register_operand" "=x") 0)
19733         (ior:TI (match_operand:TI 1 "nonimmediate_operand" "%0")
19734                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19735   "TARGET_SSE2
19736    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19737   "orpd\t{%2, %0|%0, %2}"
19738   [(set_attr "type" "sselog")
19739    (set_attr "mode" "V2DF")])
19740
19741 (define_expand "sse2_xorv2df3"
19742   [(set (subreg:TI (match_operand:V2DF 0 "register_operand" "") 0)
19743         (xor:TI (subreg:TI (match_operand:V2DF 1 "nonimmediate_operand" "") 0)
19744                 (subreg:TI (match_operand:V2DF 2 "nonimmediate_operand" "") 0)))]
19745   "TARGET_SSE2"
19746   "")
19747
19748 (define_insn "*sse2_xorv2df3"
19749   [(set (subreg:TI (match_operand:V2DF 0 "register_operand" "=x") 0)
19750         (xor:TI (match_operand:TI 1 "nonimmediate_operand" "%0")
19751                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19752   "TARGET_SSE2
19753    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19754   "xorpd\t{%2, %0|%0, %2}"
19755   [(set_attr "type" "sselog")
19756    (set_attr "mode" "V2DF")])
19757
19758 (define_insn "*sse2_xordf3"
19759   [(set (subreg:TI (match_operand:DF 0 "register_operand" "=x") 0)
19760         (xor:TI (match_operand:TI 1 "nonimmediate_operand" "%0")
19761                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19762   "TARGET_SSE2
19763    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19764   "xorpd\t{%2, %0|%0, %2}"
19765   [(set_attr "type" "sselog")
19766    (set_attr "mode" "V2DF")])
19767
19768 ;; SSE2 integral logicals.  These patterns must always come after floating
19769 ;; point ones since we don't want compiler to use integer opcodes on floating
19770 ;; point SSE values to avoid matching of subregs in the match_operand.
19771 (define_insn "*sse2_andti3"
19772   [(set (match_operand:TI 0 "register_operand" "=x")
19773         (and:TI (match_operand:TI 1 "nonimmediate_operand" "%0")
19774                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19775   "TARGET_SSE2
19776    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19777   "pand\t{%2, %0|%0, %2}"
19778   [(set_attr "type" "sselog")
19779    (set_attr "mode" "TI")])
19780
19781 (define_insn "sse2_andv2di3"
19782   [(set (match_operand:V2DI 0 "register_operand" "=x")
19783         (and:V2DI (match_operand:V2DI 1 "nonimmediate_operand" "%0")
19784                   (match_operand:V2DI 2 "nonimmediate_operand" "xm")))]
19785   "TARGET_SSE2
19786    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19787   "pand\t{%2, %0|%0, %2}"
19788   [(set_attr "type" "sselog")
19789    (set_attr "mode" "TI")])
19790
19791 (define_insn "*sse2_nandti3"
19792   [(set (match_operand:TI 0 "register_operand" "=x")
19793         (and:TI (not:TI (match_operand:TI 1 "register_operand" "0"))
19794                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19795   "TARGET_SSE2"
19796   "pandn\t{%2, %0|%0, %2}"
19797   [(set_attr "type" "sselog")
19798    (set_attr "mode" "TI")])
19799
19800 (define_insn "sse2_nandv2di3"
19801   [(set (match_operand:V2DI 0 "register_operand" "=x")
19802         (and:V2DI (not:V2DI (match_operand:V2DI 1 "nonimmediate_operand" "0"))
19803                   (match_operand:V2DI 2 "nonimmediate_operand" "xm")))]
19804   "TARGET_SSE2
19805    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19806   "pandn\t{%2, %0|%0, %2}"
19807   [(set_attr "type" "sselog")
19808    (set_attr "mode" "TI")])
19809
19810 (define_insn "*sse2_iorti3"
19811   [(set (match_operand:TI 0 "register_operand" "=x")
19812         (ior:TI (match_operand:TI 1 "nonimmediate_operand" "%0")
19813                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19814   "TARGET_SSE2
19815    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19816   "por\t{%2, %0|%0, %2}"
19817   [(set_attr "type" "sselog")
19818    (set_attr "mode" "TI")])
19819
19820 (define_insn "sse2_iorv2di3"
19821   [(set (match_operand:V2DI 0 "register_operand" "=x")
19822         (ior:V2DI (match_operand:V2DI 1 "nonimmediate_operand" "%0")
19823                   (match_operand:V2DI 2 "nonimmediate_operand" "xm")))]
19824   "TARGET_SSE2
19825    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19826   "por\t{%2, %0|%0, %2}"
19827   [(set_attr "type" "sselog")
19828    (set_attr "mode" "TI")])
19829
19830 (define_insn "*sse2_xorti3"
19831   [(set (match_operand:TI 0 "register_operand" "=x")
19832         (xor:TI (match_operand:TI 1 "nonimmediate_operand" "%0")
19833                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
19834   "TARGET_SSE2
19835    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19836   "pxor\t{%2, %0|%0, %2}"
19837   [(set_attr "type" "sselog")
19838    (set_attr "mode" "TI")])
19839
19840 (define_insn "sse2_xorv2di3"
19841   [(set (match_operand:V2DI 0 "register_operand" "=x")
19842         (xor:V2DI (match_operand:V2DI 1 "nonimmediate_operand" "%0")
19843                   (match_operand:V2DI 2 "nonimmediate_operand" "xm")))]
19844   "TARGET_SSE2
19845    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
19846   "pxor\t{%2, %0|%0, %2}"
19847   [(set_attr "type" "sselog")
19848    (set_attr "mode" "TI")])
19849
19850 ;; Use xor, but don't show input operands so they aren't live before
19851 ;; this insn.
19852 (define_insn "sse_clrv4sf"
19853   [(set (match_operand:V4SF 0 "register_operand" "=x")
19854         (match_operand:V4SF 1 "const0_operand" "X"))]
19855   "TARGET_SSE"
19856 {
19857   if (get_attr_mode (insn) == MODE_TI)
19858     return "pxor\t{%0, %0|%0, %0}";
19859   else
19860     return "xorps\t{%0, %0|%0, %0}";
19861 }
19862   [(set_attr "type" "sselog")
19863    (set_attr "memory" "none")
19864    (set (attr "mode")
19865         (if_then_else
19866            (and (and (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
19867                          (const_int 0))
19868                      (ne (symbol_ref "TARGET_SSE2")
19869                          (const_int 0)))
19870                 (eq (symbol_ref "optimize_size")
19871                     (const_int 0)))
19872          (const_string "TI")
19873          (const_string "V4SF")))])
19874
19875 ;; Use xor, but don't show input operands so they aren't live before
19876 ;; this insn.
19877 (define_insn "sse_clrv2df"
19878   [(set (match_operand:V2DF 0 "register_operand" "=x")
19879         (unspec:V2DF [(const_int 0)] UNSPEC_NOP))]
19880   "TARGET_SSE2"
19881   "xorpd\t{%0, %0|%0, %0}"
19882   [(set_attr "type" "sselog")
19883    (set_attr "memory" "none")
19884    (set_attr "mode" "V4SF")])
19885
19886 ;; SSE mask-generating compares
19887
19888 (define_insn "maskcmpv4sf3"
19889   [(set (match_operand:V4SI 0 "register_operand" "=x")
19890         (match_operator:V4SI 3 "sse_comparison_operator"
19891                 [(match_operand:V4SF 1 "register_operand" "0")
19892                  (match_operand:V4SF 2 "register_operand" "x")]))]
19893   "TARGET_SSE"
19894   "cmp%D3ps\t{%2, %0|%0, %2}"
19895   [(set_attr "type" "ssecmp")
19896    (set_attr "mode" "V4SF")])
19897
19898 (define_insn "maskncmpv4sf3"
19899   [(set (match_operand:V4SI 0 "register_operand" "=x")
19900         (not:V4SI
19901          (match_operator:V4SI 3 "sse_comparison_operator"
19902                 [(match_operand:V4SF 1 "register_operand" "0")
19903                  (match_operand:V4SF 2 "register_operand" "x")])))]
19904   "TARGET_SSE"
19905 {
19906   if (GET_CODE (operands[3]) == UNORDERED)
19907     return "cmpordps\t{%2, %0|%0, %2}";
19908   else
19909     return "cmpn%D3ps\t{%2, %0|%0, %2}";
19910 }
19911   [(set_attr "type" "ssecmp")
19912    (set_attr "mode" "V4SF")])
19913
19914 (define_insn "vmmaskcmpv4sf3"
19915   [(set (match_operand:V4SI 0 "register_operand" "=x")
19916         (vec_merge:V4SI
19917          (match_operator:V4SI 3 "sse_comparison_operator"
19918                 [(match_operand:V4SF 1 "register_operand" "0")
19919                  (match_operand:V4SF 2 "register_operand" "x")])
19920          (subreg:V4SI (match_dup 1) 0)
19921          (const_int 1)))]
19922   "TARGET_SSE"
19923   "cmp%D3ss\t{%2, %0|%0, %2}"
19924   [(set_attr "type" "ssecmp")
19925    (set_attr "mode" "SF")])
19926
19927 (define_insn "vmmaskncmpv4sf3"
19928   [(set (match_operand:V4SI 0 "register_operand" "=x")
19929         (vec_merge:V4SI
19930          (not:V4SI
19931           (match_operator:V4SI 3 "sse_comparison_operator"
19932                 [(match_operand:V4SF 1 "register_operand" "0")
19933                  (match_operand:V4SF 2 "register_operand" "x")]))
19934          (subreg:V4SI (match_dup 1) 0)
19935          (const_int 1)))]
19936   "TARGET_SSE"
19937 {
19938   if (GET_CODE (operands[3]) == UNORDERED)
19939     return "cmpordss\t{%2, %0|%0, %2}";
19940   else
19941     return "cmpn%D3ss\t{%2, %0|%0, %2}";
19942 }
19943   [(set_attr "type" "ssecmp")
19944    (set_attr "mode" "SF")])
19945
19946 (define_insn "sse_comi"
19947   [(set (reg:CCFP 17)
19948         (compare:CCFP (vec_select:SF
19949                        (match_operand:V4SF 0 "register_operand" "x")
19950                        (parallel [(const_int 0)]))
19951                       (vec_select:SF
19952                        (match_operand:V4SF 1 "register_operand" "x")
19953                        (parallel [(const_int 0)]))))]
19954   "TARGET_SSE"
19955   "comiss\t{%1, %0|%0, %1}"
19956   [(set_attr "type" "ssecomi")
19957    (set_attr "mode" "SF")])
19958
19959 (define_insn "sse_ucomi"
19960   [(set (reg:CCFPU 17)
19961         (compare:CCFPU (vec_select:SF
19962                         (match_operand:V4SF 0 "register_operand" "x")
19963                         (parallel [(const_int 0)]))
19964                        (vec_select:SF
19965                         (match_operand:V4SF 1 "register_operand" "x")
19966                         (parallel [(const_int 0)]))))]
19967   "TARGET_SSE"
19968   "ucomiss\t{%1, %0|%0, %1}"
19969   [(set_attr "type" "ssecomi")
19970    (set_attr "mode" "SF")])
19971
19972
19973 ;; SSE unpack
19974
19975 (define_insn "sse_unpckhps"
19976   [(set (match_operand:V4SF 0 "register_operand" "=x")
19977         (vec_merge:V4SF
19978          (vec_select:V4SF (match_operand:V4SF 1 "register_operand" "0")
19979                           (parallel [(const_int 2)
19980                                      (const_int 0)
19981                                      (const_int 3)
19982                                      (const_int 1)]))
19983          (vec_select:V4SF (match_operand:V4SF 2 "register_operand" "x")
19984                           (parallel [(const_int 0)
19985                                      (const_int 2)
19986                                      (const_int 1)
19987                                      (const_int 3)]))
19988          (const_int 5)))]
19989   "TARGET_SSE"
19990   "unpckhps\t{%2, %0|%0, %2}"
19991   [(set_attr "type" "ssecvt")
19992    (set_attr "mode" "V4SF")])
19993
19994 (define_insn "sse_unpcklps"
19995   [(set (match_operand:V4SF 0 "register_operand" "=x")
19996         (vec_merge:V4SF
19997          (vec_select:V4SF (match_operand:V4SF 1 "register_operand" "0")
19998                           (parallel [(const_int 0)
19999                                      (const_int 2)
20000                                      (const_int 1)
20001                                      (const_int 3)]))
20002          (vec_select:V4SF (match_operand:V4SF 2 "register_operand" "x")
20003                           (parallel [(const_int 2)
20004                                      (const_int 0)
20005                                      (const_int 3)
20006                                      (const_int 1)]))
20007          (const_int 5)))]
20008   "TARGET_SSE"
20009   "unpcklps\t{%2, %0|%0, %2}"
20010   [(set_attr "type" "ssecvt")
20011    (set_attr "mode" "V4SF")])
20012
20013
20014 ;; SSE min/max
20015
20016 (define_insn "smaxv4sf3"
20017   [(set (match_operand:V4SF 0 "register_operand" "=x")
20018         (smax:V4SF (match_operand:V4SF 1 "register_operand" "0")
20019                    (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
20020   "TARGET_SSE"
20021   "maxps\t{%2, %0|%0, %2}"
20022   [(set_attr "type" "sse")
20023    (set_attr "mode" "V4SF")])
20024
20025 (define_insn "vmsmaxv4sf3"
20026   [(set (match_operand:V4SF 0 "register_operand" "=x")
20027         (vec_merge:V4SF
20028          (smax:V4SF (match_operand:V4SF 1 "register_operand" "0")
20029                     (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
20030          (match_dup 1)
20031          (const_int 1)))]
20032   "TARGET_SSE"
20033   "maxss\t{%2, %0|%0, %2}"
20034   [(set_attr "type" "sse")
20035    (set_attr "mode" "SF")])
20036
20037 (define_insn "sminv4sf3"
20038   [(set (match_operand:V4SF 0 "register_operand" "=x")
20039         (smin:V4SF (match_operand:V4SF 1 "register_operand" "0")
20040                    (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
20041   "TARGET_SSE"
20042   "minps\t{%2, %0|%0, %2}"
20043   [(set_attr "type" "sse")
20044    (set_attr "mode" "V4SF")])
20045
20046 (define_insn "vmsminv4sf3"
20047   [(set (match_operand:V4SF 0 "register_operand" "=x")
20048         (vec_merge:V4SF
20049          (smin:V4SF (match_operand:V4SF 1 "register_operand" "0")
20050                     (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
20051          (match_dup 1)
20052          (const_int 1)))]
20053   "TARGET_SSE"
20054   "minss\t{%2, %0|%0, %2}"
20055   [(set_attr "type" "sse")
20056    (set_attr "mode" "SF")])
20057
20058 ;; SSE <-> integer/MMX conversions
20059
20060 (define_insn "cvtpi2ps"
20061   [(set (match_operand:V4SF 0 "register_operand" "=x")
20062         (vec_merge:V4SF
20063          (match_operand:V4SF 1 "register_operand" "0")
20064          (vec_duplicate:V4SF
20065           (float:V2SF (match_operand:V2SI 2 "nonimmediate_operand" "ym")))
20066          (const_int 12)))]
20067   "TARGET_SSE"
20068   "cvtpi2ps\t{%2, %0|%0, %2}"
20069   [(set_attr "type" "ssecvt")
20070    (set_attr "mode" "V4SF")])
20071
20072 (define_insn "cvtps2pi"
20073   [(set (match_operand:V2SI 0 "register_operand" "=y")
20074         (vec_select:V2SI
20075          (fix:V4SI (match_operand:V4SF 1 "nonimmediate_operand" "xm"))
20076          (parallel [(const_int 0) (const_int 1)])))]
20077   "TARGET_SSE"
20078   "cvtps2pi\t{%1, %0|%0, %1}"
20079   [(set_attr "type" "ssecvt")
20080    (set_attr "mode" "V4SF")])
20081
20082 (define_insn "cvttps2pi"
20083   [(set (match_operand:V2SI 0 "register_operand" "=y")
20084         (vec_select:V2SI
20085          (unspec:V4SI [(match_operand:V4SF 1 "nonimmediate_operand" "xm")]
20086                       UNSPEC_FIX)
20087          (parallel [(const_int 0) (const_int 1)])))]
20088   "TARGET_SSE"
20089   "cvttps2pi\t{%1, %0|%0, %1}"
20090   [(set_attr "type" "ssecvt")
20091    (set_attr "mode" "SF")])
20092
20093 (define_insn "cvtsi2ss"
20094   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
20095         (vec_merge:V4SF
20096          (match_operand:V4SF 1 "register_operand" "0,0")
20097          (vec_duplicate:V4SF
20098           (float:SF (match_operand:SI 2 "nonimmediate_operand" "r,rm")))
20099          (const_int 14)))]
20100   "TARGET_SSE"
20101   "cvtsi2ss\t{%2, %0|%0, %2}"
20102   [(set_attr "type" "sseicvt")
20103    (set_attr "athlon_decode" "vector,double")
20104    (set_attr "mode" "SF")])
20105
20106 (define_insn "cvtsi2ssq"
20107   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
20108         (vec_merge:V4SF
20109          (match_operand:V4SF 1 "register_operand" "0,0")
20110          (vec_duplicate:V4SF
20111           (float:SF (match_operand:DI 2 "nonimmediate_operand" "r,rm")))
20112          (const_int 14)))]
20113   "TARGET_SSE && TARGET_64BIT"
20114   "cvtsi2ssq\t{%2, %0|%0, %2}"
20115   [(set_attr "type" "sseicvt")
20116    (set_attr "athlon_decode" "vector,double")
20117    (set_attr "mode" "SF")])
20118
20119 (define_insn "cvtss2si"
20120   [(set (match_operand:SI 0 "register_operand" "=r,r")
20121         (vec_select:SI
20122          (fix:V4SI (match_operand:V4SF 1 "nonimmediate_operand" "x,m"))
20123          (parallel [(const_int 0)])))]
20124   "TARGET_SSE"
20125   "cvtss2si\t{%1, %0|%0, %1}"
20126   [(set_attr "type" "sseicvt")
20127    (set_attr "athlon_decode" "double,vector")
20128    (set_attr "mode" "SF")])
20129
20130 (define_insn "cvttss2si"
20131   [(set (match_operand:SI 0 "register_operand" "=r,r")
20132         (vec_select:SI
20133          (unspec:V4SI [(match_operand:V4SF 1 "nonimmediate_operand" "x,xm")]
20134                       UNSPEC_FIX)
20135          (parallel [(const_int 0)])))]
20136   "TARGET_SSE"
20137   "cvttss2si\t{%1, %0|%0, %1}"
20138   [(set_attr "type" "sseicvt")
20139    (set_attr "mode" "SF")
20140    (set_attr "athlon_decode" "double,vector")])
20141
20142
20143 ;; MMX insns
20144
20145 ;; MMX arithmetic
20146
20147 (define_insn "addv8qi3"
20148   [(set (match_operand:V8QI 0 "register_operand" "=y")
20149         (plus:V8QI (match_operand:V8QI 1 "register_operand" "0")
20150                    (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
20151   "TARGET_MMX"
20152   "paddb\t{%2, %0|%0, %2}"
20153   [(set_attr "type" "mmxadd")
20154    (set_attr "mode" "DI")])
20155
20156 (define_insn "addv4hi3"
20157   [(set (match_operand:V4HI 0 "register_operand" "=y")
20158         (plus:V4HI (match_operand:V4HI 1 "register_operand" "0")
20159                    (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
20160   "TARGET_MMX"
20161   "paddw\t{%2, %0|%0, %2}"
20162   [(set_attr "type" "mmxadd")
20163    (set_attr "mode" "DI")])
20164
20165 (define_insn "addv2si3"
20166   [(set (match_operand:V2SI 0 "register_operand" "=y")
20167         (plus:V2SI (match_operand:V2SI 1 "register_operand" "0")
20168                    (match_operand:V2SI 2 "nonimmediate_operand" "ym")))]
20169   "TARGET_MMX"
20170   "paddd\t{%2, %0|%0, %2}"
20171   [(set_attr "type" "mmxadd")
20172    (set_attr "mode" "DI")])
20173
20174 (define_insn "ssaddv8qi3"
20175   [(set (match_operand:V8QI 0 "register_operand" "=y")
20176         (ss_plus:V8QI (match_operand:V8QI 1 "register_operand" "0")
20177                       (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
20178   "TARGET_MMX"
20179   "paddsb\t{%2, %0|%0, %2}"
20180   [(set_attr "type" "mmxadd")
20181    (set_attr "mode" "DI")])
20182
20183 (define_insn "ssaddv4hi3"
20184   [(set (match_operand:V4HI 0 "register_operand" "=y")
20185         (ss_plus:V4HI (match_operand:V4HI 1 "register_operand" "0")
20186                       (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
20187   "TARGET_MMX"
20188   "paddsw\t{%2, %0|%0, %2}"
20189   [(set_attr "type" "mmxadd")
20190    (set_attr "mode" "DI")])
20191
20192 (define_insn "usaddv8qi3"
20193   [(set (match_operand:V8QI 0 "register_operand" "=y")
20194         (us_plus:V8QI (match_operand:V8QI 1 "register_operand" "0")
20195                       (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
20196   "TARGET_MMX"
20197   "paddusb\t{%2, %0|%0, %2}"
20198   [(set_attr "type" "mmxadd")
20199    (set_attr "mode" "DI")])
20200
20201 (define_insn "usaddv4hi3"
20202   [(set (match_operand:V4HI 0 "register_operand" "=y")
20203         (us_plus:V4HI (match_operand:V4HI 1 "register_operand" "0")
20204                       (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
20205   "TARGET_MMX"
20206   "paddusw\t{%2, %0|%0, %2}"
20207   [(set_attr "type" "mmxadd")
20208    (set_attr "mode" "DI")])
20209
20210 (define_insn "subv8qi3"
20211   [(set (match_operand:V8QI 0 "register_operand" "=y")
20212         (minus:V8QI (match_operand:V8QI 1 "register_operand" "0")
20213                     (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
20214   "TARGET_MMX"
20215   "psubb\t{%2, %0|%0, %2}"
20216   [(set_attr "type" "mmxadd")
20217    (set_attr "mode" "DI")])
20218
20219 (define_insn "subv4hi3"
20220   [(set (match_operand:V4HI 0 "register_operand" "=y")
20221         (minus:V4HI (match_operand:V4HI 1 "register_operand" "0")
20222                     (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
20223   "TARGET_MMX"
20224   "psubw\t{%2, %0|%0, %2}"
20225   [(set_attr "type" "mmxadd")
20226    (set_attr "mode" "DI")])
20227
20228 (define_insn "subv2si3"
20229   [(set (match_operand:V2SI 0 "register_operand" "=y")
20230         (minus:V2SI (match_operand:V2SI 1 "register_operand" "0")
20231                     (match_operand:V2SI 2 "nonimmediate_operand" "ym")))]
20232   "TARGET_MMX"
20233   "psubd\t{%2, %0|%0, %2}"
20234   [(set_attr "type" "mmxadd")
20235    (set_attr "mode" "DI")])
20236
20237 (define_insn "sssubv8qi3"
20238   [(set (match_operand:V8QI 0 "register_operand" "=y")
20239         (ss_minus:V8QI (match_operand:V8QI 1 "register_operand" "0")
20240                        (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
20241   "TARGET_MMX"
20242   "psubsb\t{%2, %0|%0, %2}"
20243   [(set_attr "type" "mmxadd")
20244    (set_attr "mode" "DI")])
20245
20246 (define_insn "sssubv4hi3"
20247   [(set (match_operand:V4HI 0 "register_operand" "=y")
20248         (ss_minus:V4HI (match_operand:V4HI 1 "register_operand" "0")
20249                        (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
20250   "TARGET_MMX"
20251   "psubsw\t{%2, %0|%0, %2}"
20252   [(set_attr "type" "mmxadd")
20253    (set_attr "mode" "DI")])
20254
20255 (define_insn "ussubv8qi3"
20256   [(set (match_operand:V8QI 0 "register_operand" "=y")
20257         (us_minus:V8QI (match_operand:V8QI 1 "register_operand" "0")
20258                        (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
20259   "TARGET_MMX"
20260   "psubusb\t{%2, %0|%0, %2}"
20261   [(set_attr "type" "mmxadd")
20262    (set_attr "mode" "DI")])
20263
20264 (define_insn "ussubv4hi3"
20265   [(set (match_operand:V4HI 0 "register_operand" "=y")
20266         (us_minus:V4HI (match_operand:V4HI 1 "register_operand" "0")
20267                        (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
20268   "TARGET_MMX"
20269   "psubusw\t{%2, %0|%0, %2}"
20270   [(set_attr "type" "mmxadd")
20271    (set_attr "mode" "DI")])
20272
20273 (define_insn "mulv4hi3"
20274   [(set (match_operand:V4HI 0 "register_operand" "=y")
20275         (mult:V4HI (match_operand:V4HI 1 "register_operand" "0")
20276                    (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
20277   "TARGET_MMX"
20278   "pmullw\t{%2, %0|%0, %2}"
20279   [(set_attr "type" "mmxmul")
20280    (set_attr "mode" "DI")])
20281
20282 (define_insn "smulv4hi3_highpart"
20283   [(set (match_operand:V4HI 0 "register_operand" "=y")
20284         (truncate:V4HI
20285          (lshiftrt:V4SI
20286           (mult:V4SI (sign_extend:V4SI
20287                       (match_operand:V4HI 1 "register_operand" "0"))
20288                      (sign_extend:V4SI
20289                       (match_operand:V4HI 2 "nonimmediate_operand" "ym")))
20290           (const_int 16))))]
20291   "TARGET_MMX"
20292   "pmulhw\t{%2, %0|%0, %2}"
20293   [(set_attr "type" "mmxmul")
20294    (set_attr "mode" "DI")])
20295
20296 (define_insn "umulv4hi3_highpart"
20297   [(set (match_operand:V4HI 0 "register_operand" "=y")
20298         (truncate:V4HI
20299          (lshiftrt:V4SI
20300           (mult:V4SI (zero_extend:V4SI
20301                       (match_operand:V4HI 1 "register_operand" "0"))
20302                      (zero_extend:V4SI
20303                       (match_operand:V4HI 2 "nonimmediate_operand" "ym")))
20304           (const_int 16))))]
20305   "TARGET_SSE || TARGET_3DNOW_A"
20306   "pmulhuw\t{%2, %0|%0, %2}"
20307   [(set_attr "type" "mmxmul")
20308    (set_attr "mode" "DI")])
20309
20310 (define_insn "mmx_pmaddwd"
20311   [(set (match_operand:V2SI 0 "register_operand" "=y")
20312         (plus:V2SI
20313          (mult:V2SI
20314           (sign_extend:V2SI
20315            (vec_select:V2HI (match_operand:V4HI 1 "register_operand" "0")
20316                             (parallel [(const_int 0) (const_int 2)])))
20317           (sign_extend:V2SI
20318            (vec_select:V2HI (match_operand:V4HI 2 "nonimmediate_operand" "ym")
20319                             (parallel [(const_int 0) (const_int 2)]))))
20320          (mult:V2SI
20321           (sign_extend:V2SI (vec_select:V2HI (match_dup 1)
20322                                              (parallel [(const_int 1)
20323                                                         (const_int 3)])))
20324           (sign_extend:V2SI (vec_select:V2HI (match_dup 2)
20325                                              (parallel [(const_int 1)
20326                                                         (const_int 3)]))))))]
20327   "TARGET_MMX"
20328   "pmaddwd\t{%2, %0|%0, %2}"
20329   [(set_attr "type" "mmxmul")
20330    (set_attr "mode" "DI")])
20331
20332
20333 ;; MMX logical operations
20334 ;; Note we don't want to declare these as regular iordi3 insns to prevent
20335 ;; normal code that also wants to use the FPU from getting broken.
20336 ;; The UNSPECs are there to prevent the combiner from getting overly clever.
20337 (define_insn "mmx_iordi3"
20338   [(set (match_operand:DI 0 "register_operand" "=y")
20339         (unspec:DI
20340          [(ior:DI (match_operand:DI 1 "register_operand" "0")
20341                   (match_operand:DI 2 "nonimmediate_operand" "ym"))]
20342          UNSPEC_NOP))]
20343   "TARGET_MMX"
20344   "por\t{%2, %0|%0, %2}"
20345   [(set_attr "type" "mmxadd")
20346    (set_attr "mode" "DI")])
20347
20348 (define_insn "mmx_xordi3"
20349   [(set (match_operand:DI 0 "register_operand" "=y")
20350         (unspec:DI
20351          [(xor:DI (match_operand:DI 1 "register_operand" "0")
20352                   (match_operand:DI 2 "nonimmediate_operand" "ym"))]
20353          UNSPEC_NOP))]
20354   "TARGET_MMX"
20355   "pxor\t{%2, %0|%0, %2}"
20356   [(set_attr "type" "mmxadd")
20357    (set_attr "mode" "DI")
20358    (set_attr "memory" "none")])
20359
20360 ;; Same as pxor, but don't show input operands so that we don't think
20361 ;; they are live.
20362 (define_insn "mmx_clrdi"
20363   [(set (match_operand:DI 0 "register_operand" "=y")
20364         (unspec:DI [(const_int 0)] UNSPEC_NOP))]
20365   "TARGET_MMX"
20366   "pxor\t{%0, %0|%0, %0}"
20367   [(set_attr "type" "mmxadd")
20368    (set_attr "mode" "DI")
20369    (set_attr "memory" "none")])
20370
20371 (define_insn "mmx_anddi3"
20372   [(set (match_operand:DI 0 "register_operand" "=y")
20373         (unspec:DI
20374          [(and:DI (match_operand:DI 1 "register_operand" "0")
20375                   (match_operand:DI 2 "nonimmediate_operand" "ym"))]
20376          UNSPEC_NOP))]
20377   "TARGET_MMX"
20378   "pand\t{%2, %0|%0, %2}"
20379   [(set_attr "type" "mmxadd")
20380    (set_attr "mode" "DI")])
20381
20382 (define_insn "mmx_nanddi3"
20383   [(set (match_operand:DI 0 "register_operand" "=y")
20384         (unspec:DI
20385          [(and:DI (not:DI (match_operand:DI 1 "register_operand" "0"))
20386                           (match_operand:DI 2 "nonimmediate_operand" "ym"))]
20387          UNSPEC_NOP))]
20388   "TARGET_MMX"
20389   "pandn\t{%2, %0|%0, %2}"
20390   [(set_attr "type" "mmxadd")
20391    (set_attr "mode" "DI")])
20392
20393
20394 ;; MMX unsigned averages/sum of absolute differences
20395
20396 (define_insn "mmx_uavgv8qi3"
20397   [(set (match_operand:V8QI 0 "register_operand" "=y")
20398         (ashiftrt:V8QI
20399          (plus:V8QI (plus:V8QI
20400                      (match_operand:V8QI 1 "register_operand" "0")
20401                      (match_operand:V8QI 2 "nonimmediate_operand" "ym"))
20402                     (const_vector:V8QI [(const_int 1)
20403                                         (const_int 1)
20404                                         (const_int 1)
20405                                         (const_int 1)
20406                                         (const_int 1)
20407                                         (const_int 1)
20408                                         (const_int 1)
20409                                         (const_int 1)]))
20410          (const_int 1)))]
20411   "TARGET_SSE || TARGET_3DNOW_A"
20412   "pavgb\t{%2, %0|%0, %2}"
20413   [(set_attr "type" "mmxshft")
20414    (set_attr "mode" "DI")])
20415
20416 (define_insn "mmx_uavgv4hi3"
20417   [(set (match_operand:V4HI 0 "register_operand" "=y")
20418         (ashiftrt:V4HI
20419          (plus:V4HI (plus:V4HI
20420                      (match_operand:V4HI 1 "register_operand" "0")
20421                      (match_operand:V4HI 2 "nonimmediate_operand" "ym"))
20422                     (const_vector:V4HI [(const_int 1)
20423                                         (const_int 1)
20424                                         (const_int 1)
20425                                         (const_int 1)]))
20426          (const_int 1)))]
20427   "TARGET_SSE || TARGET_3DNOW_A"
20428   "pavgw\t{%2, %0|%0, %2}"
20429   [(set_attr "type" "mmxshft")
20430    (set_attr "mode" "DI")])
20431
20432 (define_insn "mmx_psadbw"
20433   [(set (match_operand:DI 0 "register_operand" "=y")
20434         (unspec:DI [(match_operand:V8QI 1 "register_operand" "0")
20435                     (match_operand:V8QI 2 "nonimmediate_operand" "ym")]
20436                    UNSPEC_PSADBW))]
20437   "TARGET_SSE || TARGET_3DNOW_A"
20438   "psadbw\t{%2, %0|%0, %2}"
20439   [(set_attr "type" "mmxshft")
20440    (set_attr "mode" "DI")])
20441
20442
20443 ;; MMX insert/extract/shuffle
20444
20445 (define_insn "mmx_pinsrw"
20446   [(set (match_operand:V4HI 0 "register_operand" "=y")
20447         (vec_merge:V4HI (match_operand:V4HI 1 "register_operand" "0")
20448                         (vec_duplicate:V4HI
20449                          (truncate:HI (match_operand:SI 2 "nonimmediate_operand" "rm")))
20450                         (match_operand:SI 3 "immediate_operand" "i")))]
20451   "TARGET_SSE || TARGET_3DNOW_A"
20452   "pinsrw\t{%3, %2, %0|%0, %2, %3}"
20453   [(set_attr "type" "mmxcvt")
20454    (set_attr "mode" "DI")])
20455
20456 (define_insn "mmx_pextrw"
20457   [(set (match_operand:SI 0 "register_operand" "=r")
20458         (zero_extend:SI (vec_select:HI (match_operand:V4HI 1 "register_operand" "y")
20459                                        (parallel
20460                                         [(match_operand:SI 2 "immediate_operand" "i")]))))]
20461   "TARGET_SSE || TARGET_3DNOW_A"
20462   "pextrw\t{%2, %1, %0|%0, %1, %2}"
20463   [(set_attr "type" "mmxcvt")
20464    (set_attr "mode" "DI")])
20465
20466 (define_insn "mmx_pshufw"
20467   [(set (match_operand:V4HI 0 "register_operand" "=y")
20468         (unspec:V4HI [(match_operand:V4HI 1 "register_operand" "0")
20469                       (match_operand:SI 2 "immediate_operand" "i")]
20470                      UNSPEC_SHUFFLE))]
20471   "TARGET_SSE || TARGET_3DNOW_A"
20472   "pshufw\t{%2, %1, %0|%0, %1, %2}"
20473   [(set_attr "type" "mmxcvt")
20474    (set_attr "mode" "DI")])
20475
20476
20477 ;; MMX mask-generating comparisons
20478
20479 (define_insn "eqv8qi3"
20480   [(set (match_operand:V8QI 0 "register_operand" "=y")
20481         (eq:V8QI (match_operand:V8QI 1 "register_operand" "0")
20482                  (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
20483   "TARGET_MMX"
20484   "pcmpeqb\t{%2, %0|%0, %2}"
20485   [(set_attr "type" "mmxcmp")
20486    (set_attr "mode" "DI")])
20487
20488 (define_insn "eqv4hi3"
20489   [(set (match_operand:V4HI 0 "register_operand" "=y")
20490         (eq:V4HI (match_operand:V4HI 1 "register_operand" "0")
20491                  (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
20492   "TARGET_MMX"
20493   "pcmpeqw\t{%2, %0|%0, %2}"
20494   [(set_attr "type" "mmxcmp")
20495    (set_attr "mode" "DI")])
20496
20497 (define_insn "eqv2si3"
20498   [(set (match_operand:V2SI 0 "register_operand" "=y")
20499         (eq:V2SI (match_operand:V2SI 1 "register_operand" "0")
20500                  (match_operand:V2SI 2 "nonimmediate_operand" "ym")))]
20501   "TARGET_MMX"
20502   "pcmpeqd\t{%2, %0|%0, %2}"
20503   [(set_attr "type" "mmxcmp")
20504    (set_attr "mode" "DI")])
20505
20506 (define_insn "gtv8qi3"
20507   [(set (match_operand:V8QI 0 "register_operand" "=y")
20508         (gt:V8QI (match_operand:V8QI 1 "register_operand" "0")
20509                  (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
20510   "TARGET_MMX"
20511   "pcmpgtb\t{%2, %0|%0, %2}"
20512   [(set_attr "type" "mmxcmp")
20513    (set_attr "mode" "DI")])
20514
20515 (define_insn "gtv4hi3"
20516   [(set (match_operand:V4HI 0 "register_operand" "=y")
20517         (gt:V4HI (match_operand:V4HI 1 "register_operand" "0")
20518                  (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
20519   "TARGET_MMX"
20520   "pcmpgtw\t{%2, %0|%0, %2}"
20521   [(set_attr "type" "mmxcmp")
20522    (set_attr "mode" "DI")])
20523
20524 (define_insn "gtv2si3"
20525   [(set (match_operand:V2SI 0 "register_operand" "=y")
20526         (gt:V2SI (match_operand:V2SI 1 "register_operand" "0")
20527                  (match_operand:V2SI 2 "nonimmediate_operand" "ym")))]
20528   "TARGET_MMX"
20529   "pcmpgtd\t{%2, %0|%0, %2}"
20530   [(set_attr "type" "mmxcmp")
20531    (set_attr "mode" "DI")])
20532
20533
20534 ;; MMX max/min insns
20535
20536 (define_insn "umaxv8qi3"
20537   [(set (match_operand:V8QI 0 "register_operand" "=y")
20538         (umax:V8QI (match_operand:V8QI 1 "register_operand" "0")
20539                    (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
20540   "TARGET_SSE || TARGET_3DNOW_A"
20541   "pmaxub\t{%2, %0|%0, %2}"
20542   [(set_attr "type" "mmxadd")
20543    (set_attr "mode" "DI")])
20544
20545 (define_insn "smaxv4hi3"
20546   [(set (match_operand:V4HI 0 "register_operand" "=y")
20547         (smax:V4HI (match_operand:V4HI 1 "register_operand" "0")
20548                    (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
20549   "TARGET_SSE || TARGET_3DNOW_A"
20550   "pmaxsw\t{%2, %0|%0, %2}"
20551   [(set_attr "type" "mmxadd")
20552    (set_attr "mode" "DI")])
20553
20554 (define_insn "uminv8qi3"
20555   [(set (match_operand:V8QI 0 "register_operand" "=y")
20556         (umin:V8QI (match_operand:V8QI 1 "register_operand" "0")
20557                    (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
20558   "TARGET_SSE || TARGET_3DNOW_A"
20559   "pminub\t{%2, %0|%0, %2}"
20560   [(set_attr "type" "mmxadd")
20561    (set_attr "mode" "DI")])
20562
20563 (define_insn "sminv4hi3"
20564   [(set (match_operand:V4HI 0 "register_operand" "=y")
20565         (smin:V4HI (match_operand:V4HI 1 "register_operand" "0")
20566                    (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
20567   "TARGET_SSE || TARGET_3DNOW_A"
20568   "pminsw\t{%2, %0|%0, %2}"
20569   [(set_attr "type" "mmxadd")
20570    (set_attr "mode" "DI")])
20571
20572
20573 ;; MMX shifts
20574
20575 (define_insn "ashrv4hi3"
20576   [(set (match_operand:V4HI 0 "register_operand" "=y")
20577         (ashiftrt:V4HI (match_operand:V4HI 1 "register_operand" "0")
20578                        (match_operand:DI 2 "nonmemory_operand" "yi")))]
20579   "TARGET_MMX"
20580   "psraw\t{%2, %0|%0, %2}"
20581   [(set_attr "type" "mmxshft")
20582    (set_attr "mode" "DI")])
20583
20584 (define_insn "ashrv2si3"
20585   [(set (match_operand:V2SI 0 "register_operand" "=y")
20586         (ashiftrt:V2SI (match_operand:V2SI 1 "register_operand" "0")
20587                        (match_operand:DI 2 "nonmemory_operand" "yi")))]
20588   "TARGET_MMX"
20589   "psrad\t{%2, %0|%0, %2}"
20590   [(set_attr "type" "mmxshft")
20591    (set_attr "mode" "DI")])
20592
20593 (define_insn "lshrv4hi3"
20594   [(set (match_operand:V4HI 0 "register_operand" "=y")
20595         (lshiftrt:V4HI (match_operand:V4HI 1 "register_operand" "0")
20596                        (match_operand:DI 2 "nonmemory_operand" "yi")))]
20597   "TARGET_MMX"
20598   "psrlw\t{%2, %0|%0, %2}"
20599   [(set_attr "type" "mmxshft")
20600    (set_attr "mode" "DI")])
20601
20602 (define_insn "lshrv2si3"
20603   [(set (match_operand:V2SI 0 "register_operand" "=y")
20604         (lshiftrt:V2SI (match_operand:V2SI 1 "register_operand" "0")
20605                        (match_operand:DI 2 "nonmemory_operand" "yi")))]
20606   "TARGET_MMX"
20607   "psrld\t{%2, %0|%0, %2}"
20608   [(set_attr "type" "mmxshft")
20609    (set_attr "mode" "DI")])
20610
20611 ;; See logical MMX insns.
20612 (define_insn "mmx_lshrdi3"
20613   [(set (match_operand:DI 0 "register_operand" "=y")
20614         (unspec:DI
20615           [(lshiftrt:DI (match_operand:DI 1 "register_operand" "0")
20616                        (match_operand:DI 2 "nonmemory_operand" "yi"))]
20617           UNSPEC_NOP))]
20618   "TARGET_MMX"
20619   "psrlq\t{%2, %0|%0, %2}"
20620   [(set_attr "type" "mmxshft")
20621    (set_attr "mode" "DI")])
20622
20623 (define_insn "ashlv4hi3"
20624   [(set (match_operand:V4HI 0 "register_operand" "=y")
20625         (ashift:V4HI (match_operand:V4HI 1 "register_operand" "0")
20626                        (match_operand:DI 2 "nonmemory_operand" "yi")))]
20627   "TARGET_MMX"
20628   "psllw\t{%2, %0|%0, %2}"
20629   [(set_attr "type" "mmxshft")
20630    (set_attr "mode" "DI")])
20631
20632 (define_insn "ashlv2si3"
20633   [(set (match_operand:V2SI 0 "register_operand" "=y")
20634         (ashift:V2SI (match_operand:V2SI 1 "register_operand" "0")
20635                        (match_operand:DI 2 "nonmemory_operand" "yi")))]
20636   "TARGET_MMX"
20637   "pslld\t{%2, %0|%0, %2}"
20638   [(set_attr "type" "mmxshft")
20639    (set_attr "mode" "DI")])
20640
20641 ;; See logical MMX insns.
20642 (define_insn "mmx_ashldi3"
20643   [(set (match_operand:DI 0 "register_operand" "=y")
20644         (unspec:DI
20645          [(ashift:DI (match_operand:DI 1 "register_operand" "0")
20646                      (match_operand:DI 2 "nonmemory_operand" "yi"))]
20647          UNSPEC_NOP))]
20648   "TARGET_MMX"
20649   "psllq\t{%2, %0|%0, %2}"
20650   [(set_attr "type" "mmxshft")
20651    (set_attr "mode" "DI")])
20652
20653
20654 ;; MMX pack/unpack insns.
20655
20656 (define_insn "mmx_packsswb"
20657   [(set (match_operand:V8QI 0 "register_operand" "=y")
20658         (vec_concat:V8QI
20659          (ss_truncate:V4QI (match_operand:V4HI 1 "register_operand" "0"))
20660          (ss_truncate:V4QI (match_operand:V4HI 2 "register_operand" "y"))))]
20661   "TARGET_MMX"
20662   "packsswb\t{%2, %0|%0, %2}"
20663   [(set_attr "type" "mmxshft")
20664    (set_attr "mode" "DI")])
20665
20666 (define_insn "mmx_packssdw"
20667   [(set (match_operand:V4HI 0 "register_operand" "=y")
20668         (vec_concat:V4HI
20669          (ss_truncate:V2HI (match_operand:V2SI 1 "register_operand" "0"))
20670          (ss_truncate:V2HI (match_operand:V2SI 2 "register_operand" "y"))))]
20671   "TARGET_MMX"
20672   "packssdw\t{%2, %0|%0, %2}"
20673   [(set_attr "type" "mmxshft")
20674    (set_attr "mode" "DI")])
20675
20676 (define_insn "mmx_packuswb"
20677   [(set (match_operand:V8QI 0 "register_operand" "=y")
20678         (vec_concat:V8QI
20679          (us_truncate:V4QI (match_operand:V4HI 1 "register_operand" "0"))
20680          (us_truncate:V4QI (match_operand:V4HI 2 "register_operand" "y"))))]
20681   "TARGET_MMX"
20682   "packuswb\t{%2, %0|%0, %2}"
20683   [(set_attr "type" "mmxshft")
20684    (set_attr "mode" "DI")])
20685
20686 (define_insn "mmx_punpckhbw"
20687   [(set (match_operand:V8QI 0 "register_operand" "=y")
20688         (vec_merge:V8QI
20689          (vec_select:V8QI (match_operand:V8QI 1 "register_operand" "0")
20690                           (parallel [(const_int 4)
20691                                      (const_int 0)
20692                                      (const_int 5)
20693                                      (const_int 1)
20694                                      (const_int 6)
20695                                      (const_int 2)
20696                                      (const_int 7)
20697                                      (const_int 3)]))
20698          (vec_select:V8QI (match_operand:V8QI 2 "register_operand" "y")
20699                           (parallel [(const_int 0)
20700                                      (const_int 4)
20701                                      (const_int 1)
20702                                      (const_int 5)
20703                                      (const_int 2)
20704                                      (const_int 6)
20705                                      (const_int 3)
20706                                      (const_int 7)]))
20707          (const_int 85)))]
20708   "TARGET_MMX"
20709   "punpckhbw\t{%2, %0|%0, %2}"
20710   [(set_attr "type" "mmxcvt")
20711    (set_attr "mode" "DI")])
20712
20713 (define_insn "mmx_punpckhwd"
20714   [(set (match_operand:V4HI 0 "register_operand" "=y")
20715         (vec_merge:V4HI
20716          (vec_select:V4HI (match_operand:V4HI 1 "register_operand" "0")
20717                           (parallel [(const_int 0)
20718                                      (const_int 2)
20719                                      (const_int 1)
20720                                      (const_int 3)]))
20721          (vec_select:V4HI (match_operand:V4HI 2 "register_operand" "y")
20722                           (parallel [(const_int 2)
20723                                      (const_int 0)
20724                                      (const_int 3)
20725                                      (const_int 1)]))
20726          (const_int 5)))]
20727   "TARGET_MMX"
20728   "punpckhwd\t{%2, %0|%0, %2}"
20729   [(set_attr "type" "mmxcvt")
20730    (set_attr "mode" "DI")])
20731
20732 (define_insn "mmx_punpckhdq"
20733   [(set (match_operand:V2SI 0 "register_operand" "=y")
20734         (vec_merge:V2SI
20735          (match_operand:V2SI 1 "register_operand" "0")
20736          (vec_select:V2SI (match_operand:V2SI 2 "register_operand" "y")
20737                           (parallel [(const_int 1)
20738                                      (const_int 0)]))
20739          (const_int 1)))]
20740   "TARGET_MMX"
20741   "punpckhdq\t{%2, %0|%0, %2}"
20742   [(set_attr "type" "mmxcvt")
20743    (set_attr "mode" "DI")])
20744
20745 (define_insn "mmx_punpcklbw"
20746   [(set (match_operand:V8QI 0 "register_operand" "=y")
20747         (vec_merge:V8QI
20748          (vec_select:V8QI (match_operand:V8QI 1 "register_operand" "0")
20749                           (parallel [(const_int 0)
20750                                      (const_int 4)
20751                                      (const_int 1)
20752                                      (const_int 5)
20753                                      (const_int 2)
20754                                      (const_int 6)
20755                                      (const_int 3)
20756                                      (const_int 7)]))
20757          (vec_select:V8QI (match_operand:V8QI 2 "register_operand" "y")
20758                           (parallel [(const_int 4)
20759                                      (const_int 0)
20760                                      (const_int 5)
20761                                      (const_int 1)
20762                                      (const_int 6)
20763                                      (const_int 2)
20764                                      (const_int 7)
20765                                      (const_int 3)]))
20766          (const_int 85)))]
20767   "TARGET_MMX"
20768   "punpcklbw\t{%2, %0|%0, %2}"
20769   [(set_attr "type" "mmxcvt")
20770    (set_attr "mode" "DI")])
20771
20772 (define_insn "mmx_punpcklwd"
20773   [(set (match_operand:V4HI 0 "register_operand" "=y")
20774         (vec_merge:V4HI
20775          (vec_select:V4HI (match_operand:V4HI 1 "register_operand" "0")
20776                           (parallel [(const_int 2)
20777                                      (const_int 0)
20778                                      (const_int 3)
20779                                      (const_int 1)]))
20780          (vec_select:V4HI (match_operand:V4HI 2 "register_operand" "y")
20781                           (parallel [(const_int 0)
20782                                      (const_int 2)
20783                                      (const_int 1)
20784                                      (const_int 3)]))
20785          (const_int 5)))]
20786   "TARGET_MMX"
20787   "punpcklwd\t{%2, %0|%0, %2}"
20788   [(set_attr "type" "mmxcvt")
20789    (set_attr "mode" "DI")])
20790
20791 (define_insn "mmx_punpckldq"
20792   [(set (match_operand:V2SI 0 "register_operand" "=y")
20793         (vec_merge:V2SI
20794          (vec_select:V2SI (match_operand:V2SI 1 "register_operand" "0")
20795                            (parallel [(const_int 1)
20796                                       (const_int 0)]))
20797          (match_operand:V2SI 2 "register_operand" "y")
20798          (const_int 1)))]
20799   "TARGET_MMX"
20800   "punpckldq\t{%2, %0|%0, %2}"
20801   [(set_attr "type" "mmxcvt")
20802    (set_attr "mode" "DI")])
20803
20804
20805 ;; Miscellaneous stuff
20806
20807 (define_insn "emms"
20808   [(unspec_volatile [(const_int 0)] UNSPECV_EMMS)
20809    (clobber (reg:XF 8))
20810    (clobber (reg:XF 9))
20811    (clobber (reg:XF 10))
20812    (clobber (reg:XF 11))
20813    (clobber (reg:XF 12))
20814    (clobber (reg:XF 13))
20815    (clobber (reg:XF 14))
20816    (clobber (reg:XF 15))
20817    (clobber (reg:DI 29))
20818    (clobber (reg:DI 30))
20819    (clobber (reg:DI 31))
20820    (clobber (reg:DI 32))
20821    (clobber (reg:DI 33))
20822    (clobber (reg:DI 34))
20823    (clobber (reg:DI 35))
20824    (clobber (reg:DI 36))]
20825   "TARGET_MMX"
20826   "emms"
20827   [(set_attr "type" "mmx")
20828    (set_attr "memory" "unknown")])
20829
20830 (define_insn "ldmxcsr"
20831   [(unspec_volatile [(match_operand:SI 0 "memory_operand" "m")]
20832                     UNSPECV_LDMXCSR)]
20833   "TARGET_SSE"
20834   "ldmxcsr\t%0"
20835   [(set_attr "type" "sse")
20836    (set_attr "memory" "load")])
20837
20838 (define_insn "stmxcsr"
20839   [(set (match_operand:SI 0 "memory_operand" "=m")
20840         (unspec_volatile:SI [(const_int 0)] UNSPECV_STMXCSR))]
20841   "TARGET_SSE"
20842   "stmxcsr\t%0"
20843   [(set_attr "type" "sse")
20844    (set_attr "memory" "store")])
20845
20846 (define_expand "sfence"
20847   [(set (match_dup 0)
20848         (unspec:BLK [(match_dup 0)] UNSPEC_SFENCE))]
20849   "TARGET_SSE || TARGET_3DNOW_A"
20850 {
20851   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
20852   MEM_VOLATILE_P (operands[0]) = 1;
20853 })
20854
20855 (define_insn "*sfence_insn"
20856   [(set (match_operand:BLK 0 "" "")
20857         (unspec:BLK [(match_dup 0)] UNSPEC_SFENCE))]
20858   "TARGET_SSE || TARGET_3DNOW_A"
20859   "sfence"
20860   [(set_attr "type" "sse")
20861    (set_attr "memory" "unknown")])
20862
20863 (define_expand "sse_prologue_save"
20864   [(parallel [(set (match_operand:BLK 0 "" "")
20865                    (unspec:BLK [(reg:DI 21)
20866                                 (reg:DI 22)
20867                                 (reg:DI 23)
20868                                 (reg:DI 24)
20869                                 (reg:DI 25)
20870                                 (reg:DI 26)
20871                                 (reg:DI 27)
20872                                 (reg:DI 28)] UNSPEC_SSE_PROLOGUE_SAVE))
20873               (use (match_operand:DI 1 "register_operand" ""))
20874               (use (match_operand:DI 2 "immediate_operand" ""))
20875               (use (label_ref:DI (match_operand 3 "" "")))])]
20876   "TARGET_64BIT"
20877   "")
20878
20879 (define_insn "*sse_prologue_save_insn"
20880   [(set (mem:BLK (plus:DI (match_operand:DI 0 "register_operand" "R")
20881                           (match_operand:DI 4 "const_int_operand" "n")))
20882         (unspec:BLK [(reg:DI 21)
20883                      (reg:DI 22)
20884                      (reg:DI 23)
20885                      (reg:DI 24)
20886                      (reg:DI 25)
20887                      (reg:DI 26)
20888                      (reg:DI 27)
20889                      (reg:DI 28)] UNSPEC_SSE_PROLOGUE_SAVE))
20890    (use (match_operand:DI 1 "register_operand" "r"))
20891    (use (match_operand:DI 2 "const_int_operand" "i"))
20892    (use (label_ref:DI (match_operand 3 "" "X")))]
20893   "TARGET_64BIT
20894    && INTVAL (operands[4]) + SSE_REGPARM_MAX * 16 - 16 < 128
20895    && INTVAL (operands[4]) + INTVAL (operands[2]) * 16 >= -128"
20896   "*
20897 {
20898   int i;
20899   operands[0] = gen_rtx_MEM (Pmode,
20900                              gen_rtx_PLUS (Pmode, operands[0], operands[4]));
20901   output_asm_insn (\"jmp\\t%A1\", operands);
20902   for (i = SSE_REGPARM_MAX - 1; i >= INTVAL (operands[2]); i--)
20903     {
20904       operands[4] = adjust_address (operands[0], DImode, i*16);
20905       operands[5] = gen_rtx_REG (TImode, SSE_REGNO (i));
20906       PUT_MODE (operands[4], TImode);
20907       if (GET_CODE (XEXP (operands[0], 0)) != PLUS)
20908         output_asm_insn (\"rex\", operands);
20909       output_asm_insn (\"movaps\\t{%5, %4|%4, %5}\", operands);
20910     }
20911   (*targetm.asm_out.internal_label) (asm_out_file, \"L\",
20912                              CODE_LABEL_NUMBER (operands[3]));
20913   RET;
20914 }
20915   "
20916   [(set_attr "type" "other")
20917    (set_attr "length_immediate" "0")
20918    (set_attr "length_address" "0")
20919    (set_attr "length" "135")
20920    (set_attr "memory" "store")
20921    (set_attr "modrm" "0")
20922    (set_attr "mode" "DI")])
20923
20924 ;; 3Dnow! instructions
20925
20926 (define_insn "addv2sf3"
20927   [(set (match_operand:V2SF 0 "register_operand" "=y")
20928         (plus:V2SF (match_operand:V2SF 1 "register_operand" "0")
20929                    (match_operand:V2SF 2 "nonimmediate_operand" "ym")))]
20930   "TARGET_3DNOW"
20931   "pfadd\\t{%2, %0|%0, %2}"
20932   [(set_attr "type" "mmxadd")
20933    (set_attr "mode" "V2SF")])
20934
20935 (define_insn "subv2sf3"
20936   [(set (match_operand:V2SF 0 "register_operand" "=y")
20937         (minus:V2SF (match_operand:V2SF 1 "register_operand" "0")
20938                     (match_operand:V2SF 2 "nonimmediate_operand" "ym")))]
20939   "TARGET_3DNOW"
20940   "pfsub\\t{%2, %0|%0, %2}"
20941   [(set_attr "type" "mmxadd")
20942    (set_attr "mode" "V2SF")])
20943
20944 (define_insn "subrv2sf3"
20945   [(set (match_operand:V2SF 0 "register_operand" "=y")
20946         (minus:V2SF (match_operand:V2SF 2 "nonimmediate_operand" "ym")
20947                     (match_operand:V2SF 1 "register_operand" "0")))]
20948   "TARGET_3DNOW"
20949   "pfsubr\\t{%2, %0|%0, %2}"
20950   [(set_attr "type" "mmxadd")
20951    (set_attr "mode" "V2SF")])
20952
20953 (define_insn "gtv2sf3"
20954   [(set (match_operand:V2SI 0 "register_operand" "=y")
20955         (gt:V2SI (match_operand:V2SF 1 "register_operand" "0")
20956                  (match_operand:V2SF 2 "nonimmediate_operand" "ym")))]
20957  "TARGET_3DNOW"
20958   "pfcmpgt\\t{%2, %0|%0, %2}"
20959   [(set_attr "type" "mmxcmp")
20960    (set_attr "mode" "V2SF")])
20961
20962 (define_insn "gev2sf3"
20963   [(set (match_operand:V2SI 0 "register_operand" "=y")
20964         (ge:V2SI (match_operand:V2SF 1 "register_operand" "0")
20965                  (match_operand:V2SF 2 "nonimmediate_operand" "ym")))]
20966   "TARGET_3DNOW"
20967   "pfcmpge\\t{%2, %0|%0, %2}"
20968   [(set_attr "type" "mmxcmp")
20969    (set_attr "mode" "V2SF")])
20970
20971 (define_insn "eqv2sf3"
20972   [(set (match_operand:V2SI 0 "register_operand" "=y")
20973         (eq:V2SI (match_operand:V2SF 1 "register_operand" "0")
20974                  (match_operand:V2SF 2 "nonimmediate_operand" "ym")))]
20975   "TARGET_3DNOW"
20976   "pfcmpeq\\t{%2, %0|%0, %2}"
20977   [(set_attr "type" "mmxcmp")
20978    (set_attr "mode" "V2SF")])
20979
20980 (define_insn "pfmaxv2sf3"
20981   [(set (match_operand:V2SF 0 "register_operand" "=y")
20982         (smax:V2SF (match_operand:V2SF 1 "register_operand" "0")
20983                    (match_operand:V2SF 2 "nonimmediate_operand" "ym")))]
20984   "TARGET_3DNOW"
20985   "pfmax\\t{%2, %0|%0, %2}"
20986   [(set_attr "type" "mmxadd")
20987    (set_attr "mode" "V2SF")])
20988
20989 (define_insn "pfminv2sf3"
20990   [(set (match_operand:V2SF 0 "register_operand" "=y")
20991         (smin:V2SF (match_operand:V2SF 1 "register_operand" "0")
20992                    (match_operand:V2SF 2 "nonimmediate_operand" "ym")))]
20993   "TARGET_3DNOW"
20994   "pfmin\\t{%2, %0|%0, %2}"
20995   [(set_attr "type" "mmxadd")
20996    (set_attr "mode" "V2SF")])
20997
20998 (define_insn "mulv2sf3"
20999   [(set (match_operand:V2SF 0 "register_operand" "=y")
21000         (mult:V2SF (match_operand:V2SF 1 "register_operand" "0")
21001                    (match_operand:V2SF 2 "nonimmediate_operand" "ym")))]
21002   "TARGET_3DNOW"
21003   "pfmul\\t{%2, %0|%0, %2}"
21004   [(set_attr "type" "mmxmul")
21005    (set_attr "mode" "V2SF")])
21006
21007 (define_insn "femms"
21008   [(unspec_volatile [(const_int 0)] UNSPECV_FEMMS)
21009    (clobber (reg:XF 8))
21010    (clobber (reg:XF 9))
21011    (clobber (reg:XF 10))
21012    (clobber (reg:XF 11))
21013    (clobber (reg:XF 12))
21014    (clobber (reg:XF 13))
21015    (clobber (reg:XF 14))
21016    (clobber (reg:XF 15))
21017    (clobber (reg:DI 29))
21018    (clobber (reg:DI 30))
21019    (clobber (reg:DI 31))
21020    (clobber (reg:DI 32))
21021    (clobber (reg:DI 33))
21022    (clobber (reg:DI 34))
21023    (clobber (reg:DI 35))
21024    (clobber (reg:DI 36))]
21025   "TARGET_3DNOW"
21026   "femms"
21027   [(set_attr "type" "mmx")
21028    (set_attr "memory" "none")]) 
21029
21030 (define_insn "pf2id"
21031   [(set (match_operand:V2SI 0 "register_operand" "=y")
21032         (fix:V2SI (match_operand:V2SF 1 "nonimmediate_operand" "ym")))]
21033   "TARGET_3DNOW"
21034   "pf2id\\t{%1, %0|%0, %1}"
21035   [(set_attr "type" "mmxcvt")
21036    (set_attr "mode" "V2SF")])
21037
21038 (define_insn "pf2iw"
21039   [(set (match_operand:V2SI 0 "register_operand" "=y")
21040         (sign_extend:V2SI
21041            (ss_truncate:V2HI
21042               (fix:V2SI (match_operand:V2SF 1 "nonimmediate_operand" "ym")))))]
21043   "TARGET_3DNOW_A"
21044   "pf2iw\\t{%1, %0|%0, %1}"
21045   [(set_attr "type" "mmxcvt")
21046    (set_attr "mode" "V2SF")])
21047
21048 (define_insn "pfacc"
21049   [(set (match_operand:V2SF 0 "register_operand" "=y")
21050         (vec_concat:V2SF
21051            (plus:SF
21052               (vec_select:SF (match_operand:V2SF 1 "register_operand" "0")
21053                              (parallel [(const_int  0)]))
21054               (vec_select:SF (match_dup 1)
21055                              (parallel [(const_int 1)])))
21056            (plus:SF
21057               (vec_select:SF (match_operand:V2SF 2 "nonimmediate_operand" "y")
21058                              (parallel [(const_int  0)]))
21059               (vec_select:SF (match_dup 2)
21060                              (parallel [(const_int 1)])))))]
21061   "TARGET_3DNOW"
21062   "pfacc\\t{%2, %0|%0, %2}"
21063   [(set_attr "type" "mmxadd")
21064    (set_attr "mode" "V2SF")])
21065
21066 (define_insn "pfnacc"
21067   [(set (match_operand:V2SF 0 "register_operand" "=y")
21068         (vec_concat:V2SF
21069            (minus:SF
21070               (vec_select:SF (match_operand:V2SF 1 "register_operand" "0")
21071                              (parallel [(const_int 0)]))
21072               (vec_select:SF (match_dup 1)
21073                              (parallel [(const_int 1)])))
21074            (minus:SF
21075               (vec_select:SF (match_operand:V2SF 2 "nonimmediate_operand" "y")
21076                              (parallel [(const_int  0)]))
21077               (vec_select:SF (match_dup 2)
21078                              (parallel [(const_int 1)])))))]
21079   "TARGET_3DNOW_A"
21080   "pfnacc\\t{%2, %0|%0, %2}"
21081   [(set_attr "type" "mmxadd")
21082    (set_attr "mode" "V2SF")])
21083
21084 (define_insn "pfpnacc"
21085   [(set (match_operand:V2SF 0 "register_operand" "=y")
21086         (vec_concat:V2SF
21087            (minus:SF
21088               (vec_select:SF (match_operand:V2SF 1 "register_operand" "0")
21089                              (parallel [(const_int 0)]))
21090               (vec_select:SF (match_dup 1)
21091                              (parallel [(const_int 1)])))
21092            (plus:SF
21093               (vec_select:SF (match_operand:V2SF 2 "nonimmediate_operand" "y")
21094                              (parallel [(const_int 0)]))
21095               (vec_select:SF (match_dup 2)
21096                              (parallel [(const_int 1)])))))]
21097   "TARGET_3DNOW_A"
21098   "pfpnacc\\t{%2, %0|%0, %2}"
21099   [(set_attr "type" "mmxadd")
21100    (set_attr "mode" "V2SF")])
21101
21102 (define_insn "pi2fw"
21103   [(set (match_operand:V2SF 0 "register_operand" "=y")
21104         (float:V2SF
21105            (vec_concat:V2SI
21106               (sign_extend:SI
21107                  (truncate:HI
21108                     (vec_select:SI (match_operand:V2SI 1 "nonimmediate_operand" "ym")
21109                                    (parallel [(const_int 0)]))))
21110               (sign_extend:SI
21111                  (truncate:HI
21112                     (vec_select:SI (match_dup 1)
21113                                    (parallel [(const_int  1)])))))))]
21114   "TARGET_3DNOW_A"
21115   "pi2fw\\t{%1, %0|%0, %1}"
21116   [(set_attr "type" "mmxcvt")
21117    (set_attr "mode" "V2SF")])
21118
21119 (define_insn "floatv2si2"
21120   [(set (match_operand:V2SF 0 "register_operand" "=y")
21121         (float:V2SF (match_operand:V2SI 1 "nonimmediate_operand" "ym")))]
21122   "TARGET_3DNOW"
21123   "pi2fd\\t{%1, %0|%0, %1}"
21124   [(set_attr "type" "mmxcvt")
21125    (set_attr "mode" "V2SF")])
21126
21127 ;; This insn is identical to pavgb in operation, but the opcode is
21128 ;; different.  To avoid accidentally matching pavgb, use an unspec.
21129
21130 (define_insn "pavgusb"
21131  [(set (match_operand:V8QI 0 "register_operand" "=y")
21132        (unspec:V8QI
21133           [(match_operand:V8QI 1 "register_operand" "0")
21134            (match_operand:V8QI 2 "nonimmediate_operand" "ym")]
21135           UNSPEC_PAVGUSB))]
21136   "TARGET_3DNOW"
21137   "pavgusb\\t{%2, %0|%0, %2}"
21138   [(set_attr "type" "mmxshft")
21139    (set_attr "mode" "TI")])
21140
21141 ;; 3DNow reciprocal and sqrt
21142  
21143 (define_insn "pfrcpv2sf2"
21144   [(set (match_operand:V2SF 0 "register_operand" "=y")
21145         (unspec:V2SF [(match_operand:V2SF 1 "nonimmediate_operand" "ym")]
21146         UNSPEC_PFRCP))]
21147   "TARGET_3DNOW"
21148   "pfrcp\\t{%1, %0|%0, %1}"
21149   [(set_attr "type" "mmx")
21150    (set_attr "mode" "TI")])
21151
21152 (define_insn "pfrcpit1v2sf3"
21153   [(set (match_operand:V2SF 0 "register_operand" "=y")
21154         (unspec:V2SF [(match_operand:V2SF 1 "register_operand" "0")
21155                       (match_operand:V2SF 2 "nonimmediate_operand" "ym")]
21156                      UNSPEC_PFRCPIT1))]
21157   "TARGET_3DNOW"
21158   "pfrcpit1\\t{%2, %0|%0, %2}"
21159   [(set_attr "type" "mmx")
21160    (set_attr "mode" "TI")])
21161
21162 (define_insn "pfrcpit2v2sf3"
21163   [(set (match_operand:V2SF 0 "register_operand" "=y")
21164         (unspec:V2SF [(match_operand:V2SF 1 "register_operand" "0")
21165                       (match_operand:V2SF 2 "nonimmediate_operand" "ym")]
21166                      UNSPEC_PFRCPIT2))]
21167   "TARGET_3DNOW"
21168   "pfrcpit2\\t{%2, %0|%0, %2}"
21169   [(set_attr "type" "mmx")
21170    (set_attr "mode" "TI")])
21171
21172 (define_insn "pfrsqrtv2sf2"
21173   [(set (match_operand:V2SF 0 "register_operand" "=y")
21174         (unspec:V2SF [(match_operand:V2SF 1 "nonimmediate_operand" "ym")]
21175                      UNSPEC_PFRSQRT))]
21176   "TARGET_3DNOW"
21177   "pfrsqrt\\t{%1, %0|%0, %1}"
21178   [(set_attr "type" "mmx")
21179    (set_attr "mode" "TI")])
21180                 
21181 (define_insn "pfrsqit1v2sf3"
21182   [(set (match_operand:V2SF 0 "register_operand" "=y")
21183         (unspec:V2SF [(match_operand:V2SF 1 "register_operand" "0")
21184                       (match_operand:V2SF 2 "nonimmediate_operand" "ym")]
21185                      UNSPEC_PFRSQIT1))]
21186   "TARGET_3DNOW"
21187   "pfrsqit1\\t{%2, %0|%0, %2}"
21188   [(set_attr "type" "mmx")
21189    (set_attr "mode" "TI")])
21190
21191 (define_insn "pmulhrwv4hi3"
21192   [(set (match_operand:V4HI 0 "register_operand" "=y")
21193         (truncate:V4HI
21194            (lshiftrt:V4SI
21195               (plus:V4SI
21196                  (mult:V4SI
21197                     (sign_extend:V4SI
21198                        (match_operand:V4HI 1 "register_operand" "0"))
21199                     (sign_extend:V4SI
21200                        (match_operand:V4HI 2 "nonimmediate_operand" "ym")))
21201                  (const_vector:V4SI [(const_int 32768)
21202                                      (const_int 32768)
21203                                      (const_int 32768)
21204                                      (const_int 32768)]))
21205               (const_int 16))))]
21206   "TARGET_3DNOW"
21207   "pmulhrw\\t{%2, %0|%0, %2}"
21208   [(set_attr "type" "mmxmul")
21209    (set_attr "mode" "TI")])
21210
21211 (define_insn "pswapdv2si2"
21212   [(set (match_operand:V2SI 0 "register_operand" "=y")
21213         (vec_select:V2SI (match_operand:V2SI 1 "nonimmediate_operand" "ym")
21214                          (parallel [(const_int 1) (const_int 0)])))]
21215   "TARGET_3DNOW_A"
21216   "pswapd\\t{%1, %0|%0, %1}"
21217   [(set_attr "type" "mmxcvt")
21218    (set_attr "mode" "TI")])
21219
21220 (define_insn "pswapdv2sf2"
21221   [(set (match_operand:V2SF 0 "register_operand" "=y")
21222         (vec_select:V2SF (match_operand:V2SF 1 "nonimmediate_operand" "ym")
21223                          (parallel [(const_int 1) (const_int 0)])))]
21224   "TARGET_3DNOW_A"
21225   "pswapd\\t{%1, %0|%0, %1}"
21226   [(set_attr "type" "mmxcvt")
21227    (set_attr "mode" "TI")])
21228
21229 (define_expand "prefetch"
21230   [(prefetch (match_operand 0 "address_operand" "")
21231              (match_operand:SI 1 "const_int_operand" "")
21232              (match_operand:SI 2 "const_int_operand" ""))]
21233   "TARGET_PREFETCH_SSE || TARGET_3DNOW"
21234 {
21235   int rw = INTVAL (operands[1]);
21236   int locality = INTVAL (operands[2]);
21237
21238   if (rw != 0 && rw != 1)
21239     abort ();
21240   if (locality < 0 || locality > 3)
21241     abort ();
21242   if (GET_MODE (operands[0]) != Pmode && GET_MODE (operands[0]) != VOIDmode)
21243     abort ();
21244
21245   /* Use 3dNOW prefetch in case we are asking for write prefetch not
21246      suported by SSE counterpart or the SSE prefetch is not available
21247      (K6 machines).  Otherwise use SSE prefetch as it allows specifying
21248      of locality.  */
21249   if (TARGET_3DNOW && (!TARGET_PREFETCH_SSE || rw))
21250     operands[2] = GEN_INT (3);
21251   else
21252     operands[1] = const0_rtx;
21253 })
21254
21255 (define_insn "*prefetch_sse"
21256   [(prefetch (match_operand:SI 0 "address_operand" "p")
21257              (const_int 0)
21258              (match_operand:SI 1 "const_int_operand" ""))]
21259   "TARGET_PREFETCH_SSE && !TARGET_64BIT"
21260 {
21261   static const char * const patterns[4] = {
21262    "prefetchnta\t%a0", "prefetcht2\t%a0", "prefetcht1\t%a0", "prefetcht0\t%a0"
21263   };
21264
21265   int locality = INTVAL (operands[1]);
21266   if (locality < 0 || locality > 3)
21267     abort ();
21268
21269   return patterns[locality];  
21270 }
21271   [(set_attr "type" "sse")
21272    (set_attr "memory" "none")])
21273
21274 (define_insn "*prefetch_sse_rex"
21275   [(prefetch (match_operand:DI 0 "address_operand" "p")
21276              (const_int 0)
21277              (match_operand:SI 1 "const_int_operand" ""))]
21278   "TARGET_PREFETCH_SSE && TARGET_64BIT"
21279 {
21280   static const char * const patterns[4] = {
21281    "prefetchnta\t%a0", "prefetcht2\t%a0", "prefetcht1\t%a0", "prefetcht0\t%a0"
21282   };
21283
21284   int locality = INTVAL (operands[1]);
21285   if (locality < 0 || locality > 3)
21286     abort ();
21287
21288   return patterns[locality];  
21289 }
21290   [(set_attr "type" "sse")
21291    (set_attr "memory" "none")])
21292
21293 (define_insn "*prefetch_3dnow"
21294   [(prefetch (match_operand:SI 0 "address_operand" "p")
21295              (match_operand:SI 1 "const_int_operand" "n")
21296              (const_int 3))]
21297   "TARGET_3DNOW && !TARGET_64BIT"
21298 {
21299   if (INTVAL (operands[1]) == 0)
21300     return "prefetch\t%a0";
21301   else
21302     return "prefetchw\t%a0";
21303 }
21304   [(set_attr "type" "mmx")
21305    (set_attr "memory" "none")])
21306
21307 (define_insn "*prefetch_3dnow_rex"
21308   [(prefetch (match_operand:DI 0 "address_operand" "p")
21309              (match_operand:SI 1 "const_int_operand" "n")
21310              (const_int 3))]
21311   "TARGET_3DNOW && TARGET_64BIT"
21312 {
21313   if (INTVAL (operands[1]) == 0)
21314     return "prefetch\t%a0";
21315   else
21316     return "prefetchw\t%a0";
21317 }
21318   [(set_attr "type" "mmx")
21319    (set_attr "memory" "none")])
21320
21321 ;; SSE2 support
21322
21323 (define_insn "addv2df3"
21324   [(set (match_operand:V2DF 0 "register_operand" "=x")
21325         (plus:V2DF (match_operand:V2DF 1 "register_operand" "0")
21326                    (match_operand:V2DF 2 "nonimmediate_operand" "xm")))]
21327   "TARGET_SSE2"
21328   "addpd\t{%2, %0|%0, %2}"
21329   [(set_attr "type" "sseadd")
21330    (set_attr "mode" "V2DF")])
21331
21332 (define_insn "vmaddv2df3"
21333   [(set (match_operand:V2DF 0 "register_operand" "=x")
21334         (vec_merge:V2DF (plus:V2DF (match_operand:V2DF 1 "register_operand" "0")
21335                                    (match_operand:V2DF 2 "nonimmediate_operand" "xm"))
21336                         (match_dup 1)
21337                         (const_int 1)))]
21338   "TARGET_SSE2"
21339   "addsd\t{%2, %0|%0, %2}"
21340   [(set_attr "type" "sseadd")
21341    (set_attr "mode" "DF")])
21342
21343 (define_insn "subv2df3"
21344   [(set (match_operand:V2DF 0 "register_operand" "=x")
21345         (minus:V2DF (match_operand:V2DF 1 "register_operand" "0")
21346                    (match_operand:V2DF 2 "nonimmediate_operand" "xm")))]
21347   "TARGET_SSE2"
21348   "subpd\t{%2, %0|%0, %2}"
21349   [(set_attr "type" "sseadd")
21350    (set_attr "mode" "V2DF")])
21351
21352 (define_insn "vmsubv2df3"
21353   [(set (match_operand:V2DF 0 "register_operand" "=x")
21354         (vec_merge:V2DF (minus:V2DF (match_operand:V2DF 1 "register_operand" "0")
21355                                    (match_operand:V2DF 2 "nonimmediate_operand" "xm"))
21356                         (match_dup 1)
21357                         (const_int 1)))]
21358   "TARGET_SSE2"
21359   "subsd\t{%2, %0|%0, %2}"
21360   [(set_attr "type" "sseadd")
21361    (set_attr "mode" "DF")])
21362
21363 (define_insn "mulv2df3"
21364   [(set (match_operand:V2DF 0 "register_operand" "=x")
21365         (mult:V2DF (match_operand:V2DF 1 "register_operand" "0")
21366                    (match_operand:V2DF 2 "nonimmediate_operand" "xm")))]
21367   "TARGET_SSE2"
21368   "mulpd\t{%2, %0|%0, %2}"
21369   [(set_attr "type" "ssemul")
21370    (set_attr "mode" "V2DF")])
21371
21372 (define_insn "vmmulv2df3"
21373   [(set (match_operand:V2DF 0 "register_operand" "=x")
21374         (vec_merge:V2DF (mult:V2DF (match_operand:V2DF 1 "register_operand" "0")
21375                                    (match_operand:V2DF 2 "nonimmediate_operand" "xm"))
21376                         (match_dup 1)
21377                         (const_int 1)))]
21378   "TARGET_SSE2"
21379   "mulsd\t{%2, %0|%0, %2}"
21380   [(set_attr "type" "ssemul")
21381    (set_attr "mode" "DF")])
21382
21383 (define_insn "divv2df3"
21384   [(set (match_operand:V2DF 0 "register_operand" "=x")
21385         (div:V2DF (match_operand:V2DF 1 "register_operand" "0")
21386                   (match_operand:V2DF 2 "nonimmediate_operand" "xm")))]
21387   "TARGET_SSE2"
21388   "divpd\t{%2, %0|%0, %2}"
21389   [(set_attr "type" "ssediv")
21390    (set_attr "mode" "V2DF")])
21391
21392 (define_insn "vmdivv2df3"
21393   [(set (match_operand:V2DF 0 "register_operand" "=x")
21394         (vec_merge:V2DF (div:V2DF (match_operand:V2DF 1 "register_operand" "0")
21395                                   (match_operand:V2DF 2 "nonimmediate_operand" "xm"))
21396                         (match_dup 1)
21397                         (const_int 1)))]
21398   "TARGET_SSE2"
21399   "divsd\t{%2, %0|%0, %2}"
21400   [(set_attr "type" "ssediv")
21401    (set_attr "mode" "DF")])
21402
21403 ;; SSE min/max
21404
21405 (define_insn "smaxv2df3"
21406   [(set (match_operand:V2DF 0 "register_operand" "=x")
21407         (smax:V2DF (match_operand:V2DF 1 "register_operand" "0")
21408                    (match_operand:V2DF 2 "nonimmediate_operand" "xm")))]
21409   "TARGET_SSE2"
21410   "maxpd\t{%2, %0|%0, %2}"
21411   [(set_attr "type" "sseadd")
21412    (set_attr "mode" "V2DF")])
21413
21414 (define_insn "vmsmaxv2df3"
21415   [(set (match_operand:V2DF 0 "register_operand" "=x")
21416         (vec_merge:V2DF (smax:V2DF (match_operand:V2DF 1 "register_operand" "0")
21417                                    (match_operand:V2DF 2 "nonimmediate_operand" "xm"))
21418                         (match_dup 1)
21419                         (const_int 1)))]
21420   "TARGET_SSE2"
21421   "maxsd\t{%2, %0|%0, %2}"
21422   [(set_attr "type" "sseadd")
21423    (set_attr "mode" "DF")])
21424
21425 (define_insn "sminv2df3"
21426   [(set (match_operand:V2DF 0 "register_operand" "=x")
21427         (smin:V2DF (match_operand:V2DF 1 "register_operand" "0")
21428                    (match_operand:V2DF 2 "nonimmediate_operand" "xm")))]
21429   "TARGET_SSE2"
21430   "minpd\t{%2, %0|%0, %2}"
21431   [(set_attr "type" "sseadd")
21432    (set_attr "mode" "V2DF")])
21433
21434 (define_insn "vmsminv2df3"
21435   [(set (match_operand:V2DF 0 "register_operand" "=x")
21436         (vec_merge:V2DF (smin:V2DF (match_operand:V2DF 1 "register_operand" "0")
21437                                    (match_operand:V2DF 2 "nonimmediate_operand" "xm"))
21438                         (match_dup 1)
21439                         (const_int 1)))]
21440   "TARGET_SSE2"
21441   "minsd\t{%2, %0|%0, %2}"
21442   [(set_attr "type" "sseadd")
21443    (set_attr "mode" "DF")])
21444 ;; SSE2 square root.  There doesn't appear to be an extension for the
21445 ;; reciprocal/rsqrt instructions if the Intel manual is to be believed.
21446
21447 (define_insn "sqrtv2df2"
21448   [(set (match_operand:V2DF 0 "register_operand" "=x")
21449         (sqrt:V2DF (match_operand:V2DF 1 "register_operand" "xm")))]
21450   "TARGET_SSE2"
21451   "sqrtpd\t{%1, %0|%0, %1}"
21452   [(set_attr "type" "sse")
21453    (set_attr "mode" "V2DF")])
21454
21455 (define_insn "vmsqrtv2df2"
21456   [(set (match_operand:V2DF 0 "register_operand" "=x")
21457         (vec_merge:V2DF (sqrt:V2DF (match_operand:V2DF 1 "register_operand" "xm"))
21458                         (match_operand:V2DF 2 "register_operand" "0")
21459                         (const_int 1)))]
21460   "TARGET_SSE2"
21461   "sqrtsd\t{%1, %0|%0, %1}"
21462   [(set_attr "type" "sse")
21463    (set_attr "mode" "SF")])
21464
21465 ;; SSE mask-generating compares
21466
21467 (define_insn "maskcmpv2df3"
21468   [(set (match_operand:V2DI 0 "register_operand" "=x")
21469         (match_operator:V2DI 3 "sse_comparison_operator"
21470                              [(match_operand:V2DF 1 "register_operand" "0")
21471                               (match_operand:V2DF 2 "nonimmediate_operand" "x")]))]
21472   "TARGET_SSE2"
21473   "cmp%D3pd\t{%2, %0|%0, %2}"
21474   [(set_attr "type" "ssecmp")
21475    (set_attr "mode" "V2DF")])
21476
21477 (define_insn "maskncmpv2df3"
21478   [(set (match_operand:V2DI 0 "register_operand" "=x")
21479         (not:V2DI
21480          (match_operator:V2DI 3 "sse_comparison_operator"
21481                               [(match_operand:V2DF 1 "register_operand" "0")
21482                                (match_operand:V2DF 2 "nonimmediate_operand" "x")])))]
21483   "TARGET_SSE2"
21484 {
21485   if (GET_CODE (operands[3]) == UNORDERED)
21486     return "cmpordps\t{%2, %0|%0, %2}";
21487   else
21488     return "cmpn%D3pd\t{%2, %0|%0, %2}";
21489 }
21490   [(set_attr "type" "ssecmp")
21491    (set_attr "mode" "V2DF")])
21492
21493 (define_insn "vmmaskcmpv2df3"
21494   [(set (match_operand:V2DI 0 "register_operand" "=x")
21495         (vec_merge:V2DI
21496          (match_operator:V2DI 3 "sse_comparison_operator"
21497                               [(match_operand:V2DF 1 "register_operand" "0")
21498                                (match_operand:V2DF 2 "nonimmediate_operand" "x")])
21499          (subreg:V2DI (match_dup 1) 0)
21500          (const_int 1)))]
21501   "TARGET_SSE2"
21502   "cmp%D3sd\t{%2, %0|%0, %2}"
21503   [(set_attr "type" "ssecmp")
21504    (set_attr "mode" "DF")])
21505
21506 (define_insn "vmmaskncmpv2df3"
21507   [(set (match_operand:V2DI 0 "register_operand" "=x")
21508         (vec_merge:V2DI
21509          (not:V2DI
21510           (match_operator:V2DI 3 "sse_comparison_operator"
21511                                [(match_operand:V2DF 1 "register_operand" "0")
21512                                 (match_operand:V2DF 2 "nonimmediate_operand" "x")]))
21513          (subreg:V2DI (match_dup 1) 0)
21514          (const_int 1)))]
21515   "TARGET_SSE2"
21516 {
21517   if (GET_CODE (operands[3]) == UNORDERED)
21518     return "cmpordsd\t{%2, %0|%0, %2}";
21519   else
21520     return "cmpn%D3sd\t{%2, %0|%0, %2}";
21521 }
21522   [(set_attr "type" "ssecmp")
21523    (set_attr "mode" "DF")])
21524
21525 (define_insn "sse2_comi"
21526   [(set (reg:CCFP 17)
21527         (compare:CCFP (vec_select:DF
21528                        (match_operand:V2DF 0 "register_operand" "x")
21529                        (parallel [(const_int 0)]))
21530                       (vec_select:DF
21531                        (match_operand:V2DF 1 "register_operand" "x")
21532                        (parallel [(const_int 0)]))))]
21533   "TARGET_SSE2"
21534   "comisd\t{%1, %0|%0, %1}"
21535   [(set_attr "type" "ssecomi")
21536    (set_attr "mode" "DF")])
21537
21538 (define_insn "sse2_ucomi"
21539   [(set (reg:CCFPU 17)
21540         (compare:CCFPU (vec_select:DF
21541                          (match_operand:V2DF 0 "register_operand" "x")
21542                          (parallel [(const_int 0)]))
21543                         (vec_select:DF
21544                          (match_operand:V2DF 1 "register_operand" "x")
21545                          (parallel [(const_int 0)]))))]
21546   "TARGET_SSE2"
21547   "ucomisd\t{%1, %0|%0, %1}"
21548   [(set_attr "type" "ssecomi")
21549    (set_attr "mode" "DF")])
21550
21551 ;; SSE Strange Moves.
21552
21553 (define_insn "sse2_movmskpd"
21554   [(set (match_operand:SI 0 "register_operand" "=r")
21555         (unspec:SI [(match_operand:V2DF 1 "register_operand" "x")]
21556                    UNSPEC_MOVMSK))]
21557   "TARGET_SSE2"
21558   "movmskpd\t{%1, %0|%0, %1}"
21559   [(set_attr "type" "ssecvt")
21560    (set_attr "mode" "V2DF")])
21561
21562 (define_insn "sse2_pmovmskb"
21563   [(set (match_operand:SI 0 "register_operand" "=r")
21564         (unspec:SI [(match_operand:V16QI 1 "register_operand" "x")]
21565                    UNSPEC_MOVMSK))]
21566   "TARGET_SSE2"
21567   "pmovmskb\t{%1, %0|%0, %1}"
21568   [(set_attr "type" "ssecvt")
21569    (set_attr "mode" "V2DF")])
21570
21571 (define_insn "sse2_maskmovdqu"
21572   [(set (mem:V16QI (match_operand:SI 0 "register_operand" "D"))
21573         (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "x")
21574                        (match_operand:V16QI 2 "register_operand" "x")]
21575                       UNSPEC_MASKMOV))]
21576   "TARGET_SSE2"
21577   ;; @@@ check ordering of operands in intel/nonintel syntax
21578   "maskmovdqu\t{%2, %1|%1, %2}"
21579   [(set_attr "type" "ssecvt")
21580    (set_attr "mode" "TI")])
21581
21582 (define_insn "sse2_maskmovdqu_rex64"
21583   [(set (mem:V16QI (match_operand:DI 0 "register_operand" "D"))
21584         (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "x")
21585                        (match_operand:V16QI 2 "register_operand" "x")]
21586                       UNSPEC_MASKMOV))]
21587   "TARGET_SSE2"
21588   ;; @@@ check ordering of operands in intel/nonintel syntax
21589   "maskmovdqu\t{%2, %1|%1, %2}"
21590   [(set_attr "type" "ssecvt")
21591    (set_attr "mode" "TI")])
21592
21593 (define_insn "sse2_movntv2df"
21594   [(set (match_operand:V2DF 0 "memory_operand" "=m")
21595         (unspec:V2DF [(match_operand:V2DF 1 "register_operand" "x")]
21596                      UNSPEC_MOVNT))]
21597   "TARGET_SSE2"
21598   "movntpd\t{%1, %0|%0, %1}"
21599   [(set_attr "type" "ssecvt")
21600    (set_attr "mode" "V2DF")])
21601
21602 (define_insn "sse2_movntv2di"
21603   [(set (match_operand:V2DI 0 "memory_operand" "=m")
21604         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "x")]
21605                      UNSPEC_MOVNT))]
21606   "TARGET_SSE2"
21607   "movntdq\t{%1, %0|%0, %1}"
21608   [(set_attr "type" "ssecvt")
21609    (set_attr "mode" "TI")])
21610
21611 (define_insn "sse2_movntsi"
21612   [(set (match_operand:SI 0 "memory_operand" "=m")
21613         (unspec:SI [(match_operand:SI 1 "register_operand" "r")]
21614                    UNSPEC_MOVNT))]
21615   "TARGET_SSE2"
21616   "movnti\t{%1, %0|%0, %1}"
21617   [(set_attr "type" "ssecvt")
21618    (set_attr "mode" "V2DF")])
21619
21620 ;; SSE <-> integer/MMX conversions
21621
21622 ;; Conversions between SI and SF
21623
21624 (define_insn "cvtdq2ps"
21625   [(set (match_operand:V4SF 0 "register_operand" "=x")
21626         (float:V4SF (match_operand:V4SI 1 "nonimmediate_operand" "xm")))]
21627   "TARGET_SSE2"
21628   "cvtdq2ps\t{%1, %0|%0, %1}"
21629   [(set_attr "type" "ssecvt")
21630    (set_attr "mode" "V2DF")])
21631
21632 (define_insn "cvtps2dq"
21633   [(set (match_operand:V4SI 0 "register_operand" "=x")
21634         (fix:V4SI (match_operand:V4SF 1 "nonimmediate_operand" "xm")))]
21635   "TARGET_SSE2"
21636   "cvtps2dq\t{%1, %0|%0, %1}"
21637   [(set_attr "type" "ssecvt")
21638    (set_attr "mode" "TI")])
21639
21640 (define_insn "cvttps2dq"
21641   [(set (match_operand:V4SI 0 "register_operand" "=x")
21642         (unspec:V4SI [(match_operand:V4SF 1 "nonimmediate_operand" "xm")]
21643                      UNSPEC_FIX))]
21644   "TARGET_SSE2"
21645   "cvttps2dq\t{%1, %0|%0, %1}"
21646   [(set_attr "type" "ssecvt")
21647    (set_attr "mode" "TI")])
21648
21649 ;; Conversions between SI and DF
21650
21651 (define_insn "cvtdq2pd"
21652   [(set (match_operand:V2DF 0 "register_operand" "=x")
21653         (float:V2DF (vec_select:V2SI
21654                      (match_operand:V4SI 1 "nonimmediate_operand" "xm")
21655                      (parallel
21656                       [(const_int 0)
21657                        (const_int 1)]))))]
21658   "TARGET_SSE2"
21659   "cvtdq2pd\t{%1, %0|%0, %1}"
21660   [(set_attr "type" "ssecvt")
21661    (set_attr "mode" "V2DF")])
21662
21663 (define_insn "cvtpd2dq"
21664   [(set (match_operand:V4SI 0 "register_operand" "=x")
21665         (vec_concat:V4SI
21666          (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" "xm"))
21667          (const_vector:V2SI [(const_int 0) (const_int 0)])))]
21668   "TARGET_SSE2"
21669   "cvtpd2dq\t{%1, %0|%0, %1}"
21670   [(set_attr "type" "ssecvt")
21671    (set_attr "mode" "TI")])
21672
21673 (define_insn "cvttpd2dq"
21674   [(set (match_operand:V4SI 0 "register_operand" "=x")
21675         (vec_concat:V4SI
21676          (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand" "xm")]
21677                       UNSPEC_FIX)
21678          (const_vector:V2SI [(const_int 0) (const_int 0)])))]
21679   "TARGET_SSE2"
21680   "cvttpd2dq\t{%1, %0|%0, %1}"
21681   [(set_attr "type" "ssecvt")
21682    (set_attr "mode" "TI")])
21683
21684 (define_insn "cvtpd2pi"
21685   [(set (match_operand:V2SI 0 "register_operand" "=y")
21686         (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" "xm")))]
21687   "TARGET_SSE2"
21688   "cvtpd2pi\t{%1, %0|%0, %1}"
21689   [(set_attr "type" "ssecvt")
21690    (set_attr "mode" "TI")])
21691
21692 (define_insn "cvttpd2pi"
21693   [(set (match_operand:V2SI 0 "register_operand" "=y")
21694         (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand" "xm")]
21695                      UNSPEC_FIX))]
21696   "TARGET_SSE2"
21697   "cvttpd2pi\t{%1, %0|%0, %1}"
21698   [(set_attr "type" "ssecvt")
21699    (set_attr "mode" "TI")])
21700
21701 (define_insn "cvtpi2pd"
21702   [(set (match_operand:V2DF 0 "register_operand" "=x")
21703         (float:V2DF (match_operand:V2SI 1 "nonimmediate_operand" "ym")))]
21704   "TARGET_SSE2"
21705   "cvtpi2pd\t{%1, %0|%0, %1}"
21706   [(set_attr "type" "ssecvt")
21707    (set_attr "mode" "TI")])
21708
21709 ;; Conversions between SI and DF
21710
21711 (define_insn "cvtsd2si"
21712   [(set (match_operand:SI 0 "register_operand" "=r")
21713         (fix:SI (vec_select:DF (match_operand:V2DF 1 "register_operand" "xm")
21714                                (parallel [(const_int 0)]))))]
21715   "TARGET_SSE2"
21716   "cvtsd2si\t{%1, %0|%0, %1}"
21717   [(set_attr "type" "sseicvt")
21718    (set_attr "mode" "SI")])
21719
21720 (define_insn "cvttsd2si"
21721   [(set (match_operand:SI 0 "register_operand" "=r,r")
21722         (unspec:SI [(vec_select:DF (match_operand:V2DF 1 "register_operand" "x,xm")
21723                                    (parallel [(const_int 0)]))] UNSPEC_FIX))]
21724   "TARGET_SSE2"
21725   "cvttsd2si\t{%1, %0|%0, %1}"
21726   [(set_attr "type" "sseicvt")
21727    (set_attr "mode" "SI")
21728    (set_attr "athlon_decode" "double,vector")])
21729
21730 (define_insn "cvtsi2sd"
21731   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
21732         (vec_merge:V2DF (match_operand:V2DF 1 "register_operand" "0,0")
21733                         (vec_duplicate:V2DF
21734                           (float:DF
21735                             (match_operand:SI 2 "nonimmediate_operand" "r,rm")))
21736                         (const_int 2)))]
21737   "TARGET_SSE2"
21738   "cvtsi2sd\t{%2, %0|%0, %2}"
21739   [(set_attr "type" "sseicvt")
21740    (set_attr "mode" "DF")
21741    (set_attr "athlon_decode" "double,direct")])
21742
21743 ;; Conversions between SF and DF
21744
21745 (define_insn "cvtsd2ss"
21746   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
21747         (vec_merge:V4SF (match_operand:V4SF 1 "register_operand" "0,0")
21748                         (vec_duplicate:V4SF
21749                           (float_truncate:V2SF
21750                             (match_operand:V2DF 2 "nonimmediate_operand" "x,xm")))
21751                         (const_int 14)))]
21752   "TARGET_SSE2"
21753   "cvtsd2ss\t{%2, %0|%0, %2}"
21754   [(set_attr "type" "ssecvt")
21755    (set_attr "athlon_decode" "vector,double")
21756    (set_attr "mode" "SF")])
21757
21758 (define_insn "cvtss2sd"
21759   [(set (match_operand:V2DF 0 "register_operand" "=x")
21760         (vec_merge:V2DF (match_operand:V2DF 1 "register_operand" "0")
21761                         (float_extend:V2DF
21762                           (vec_select:V2SF
21763                             (match_operand:V4SF 2 "nonimmediate_operand" "xm")
21764                             (parallel [(const_int 0)
21765                                        (const_int 1)])))
21766                         (const_int 2)))]
21767   "TARGET_SSE2"
21768   "cvtss2sd\t{%2, %0|%0, %2}"
21769   [(set_attr "type" "ssecvt")
21770    (set_attr "mode" "DF")])
21771
21772 (define_insn "cvtpd2ps"
21773   [(set (match_operand:V4SF 0 "register_operand" "=x")
21774         (subreg:V4SF
21775           (vec_concat:V4SI
21776             (subreg:V2SI (float_truncate:V2SF
21777                            (match_operand:V2DF 1 "nonimmediate_operand" "xm")) 0)
21778             (const_vector:V2SI [(const_int 0) (const_int 0)])) 0))]
21779   "TARGET_SSE2"
21780   "cvtpd2ps\t{%1, %0|%0, %1}"
21781   [(set_attr "type" "ssecvt")
21782    (set_attr "mode" "V4SF")])
21783
21784 (define_insn "cvtps2pd"
21785   [(set (match_operand:V2DF 0 "register_operand" "=x")
21786         (float_extend:V2DF
21787           (vec_select:V2SF (match_operand:V4SF 1 "nonimmediate_operand" "xm")
21788                            (parallel [(const_int 0)
21789                                       (const_int 1)]))))]
21790   "TARGET_SSE2"
21791   "cvtps2pd\t{%1, %0|%0, %1}"
21792   [(set_attr "type" "ssecvt")
21793    (set_attr "mode" "V2DF")])
21794
21795 ;; SSE2 variants of MMX insns
21796
21797 ;; MMX arithmetic
21798
21799 (define_insn "addv16qi3"
21800   [(set (match_operand:V16QI 0 "register_operand" "=x")
21801         (plus:V16QI (match_operand:V16QI 1 "register_operand" "0")
21802                     (match_operand:V16QI 2 "nonimmediate_operand" "xm")))]
21803   "TARGET_SSE2"
21804   "paddb\t{%2, %0|%0, %2}"
21805   [(set_attr "type" "sseiadd")
21806    (set_attr "mode" "TI")])
21807
21808 (define_insn "addv8hi3"
21809   [(set (match_operand:V8HI 0 "register_operand" "=x")
21810         (plus:V8HI (match_operand:V8HI 1 "register_operand" "0")
21811                    (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
21812   "TARGET_SSE2"
21813   "paddw\t{%2, %0|%0, %2}"
21814   [(set_attr "type" "sseiadd")
21815    (set_attr "mode" "TI")])
21816
21817 (define_insn "addv4si3"
21818   [(set (match_operand:V4SI 0 "register_operand" "=x")
21819         (plus:V4SI (match_operand:V4SI 1 "register_operand" "0")
21820                    (match_operand:V4SI 2 "nonimmediate_operand" "xm")))]
21821   "TARGET_SSE2"
21822   "paddd\t{%2, %0|%0, %2}"
21823   [(set_attr "type" "sseiadd")
21824    (set_attr "mode" "TI")])
21825
21826 (define_insn "addv2di3"
21827   [(set (match_operand:V2DI 0 "register_operand" "=x")
21828         (plus:V2DI (match_operand:V2DI 1 "register_operand" "0")
21829                    (match_operand:V2DI 2 "nonimmediate_operand" "xm")))]
21830   "TARGET_SSE2"
21831   "paddq\t{%2, %0|%0, %2}"
21832   [(set_attr "type" "sseiadd")
21833    (set_attr "mode" "TI")])
21834
21835 (define_insn "ssaddv16qi3"
21836   [(set (match_operand:V16QI 0 "register_operand" "=x")
21837         (ss_plus:V16QI (match_operand:V16QI 1 "register_operand" "0")
21838                        (match_operand:V16QI 2 "nonimmediate_operand" "xm")))]
21839   "TARGET_SSE2"
21840   "paddsb\t{%2, %0|%0, %2}"
21841   [(set_attr "type" "sseiadd")
21842    (set_attr "mode" "TI")])
21843
21844 (define_insn "ssaddv8hi3"
21845   [(set (match_operand:V8HI 0 "register_operand" "=x")
21846         (ss_plus:V8HI (match_operand:V8HI 1 "register_operand" "0")
21847                       (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
21848   "TARGET_SSE2"
21849   "paddsw\t{%2, %0|%0, %2}"
21850   [(set_attr "type" "sseiadd")
21851    (set_attr "mode" "TI")])
21852
21853 (define_insn "usaddv16qi3"
21854   [(set (match_operand:V16QI 0 "register_operand" "=x")
21855         (us_plus:V16QI (match_operand:V16QI 1 "register_operand" "0")
21856                        (match_operand:V16QI 2 "nonimmediate_operand" "xm")))]
21857   "TARGET_SSE2"
21858   "paddusb\t{%2, %0|%0, %2}"
21859   [(set_attr "type" "sseiadd")
21860    (set_attr "mode" "TI")])
21861
21862 (define_insn "usaddv8hi3"
21863   [(set (match_operand:V8HI 0 "register_operand" "=x")
21864         (us_plus:V8HI (match_operand:V8HI 1 "register_operand" "0")
21865                       (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
21866   "TARGET_SSE2"
21867   "paddusw\t{%2, %0|%0, %2}"
21868   [(set_attr "type" "sseiadd")
21869    (set_attr "mode" "TI")])
21870
21871 (define_insn "subv16qi3"
21872   [(set (match_operand:V16QI 0 "register_operand" "=x")
21873         (minus:V16QI (match_operand:V16QI 1 "register_operand" "0")
21874                      (match_operand:V16QI 2 "nonimmediate_operand" "xm")))]
21875   "TARGET_SSE2"
21876   "psubb\t{%2, %0|%0, %2}"
21877   [(set_attr "type" "sseiadd")
21878    (set_attr "mode" "TI")])
21879
21880 (define_insn "subv8hi3"
21881   [(set (match_operand:V8HI 0 "register_operand" "=x")
21882         (minus:V8HI (match_operand:V8HI 1 "register_operand" "0")
21883                     (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
21884   "TARGET_SSE2"
21885   "psubw\t{%2, %0|%0, %2}"
21886   [(set_attr "type" "sseiadd")
21887    (set_attr "mode" "TI")])
21888
21889 (define_insn "subv4si3"
21890   [(set (match_operand:V4SI 0 "register_operand" "=x")
21891         (minus:V4SI (match_operand:V4SI 1 "register_operand" "0")
21892                     (match_operand:V4SI 2 "nonimmediate_operand" "xm")))]
21893   "TARGET_SSE2"
21894   "psubd\t{%2, %0|%0, %2}"
21895   [(set_attr "type" "sseiadd")
21896    (set_attr "mode" "TI")])
21897
21898 (define_insn "subv2di3"
21899   [(set (match_operand:V2DI 0 "register_operand" "=x")
21900         (minus:V2DI (match_operand:V2DI 1 "register_operand" "0")
21901                     (match_operand:V2DI 2 "nonimmediate_operand" "xm")))]
21902   "TARGET_SSE2"
21903   "psubq\t{%2, %0|%0, %2}"
21904   [(set_attr "type" "sseiadd")
21905    (set_attr "mode" "TI")])
21906
21907 (define_insn "sssubv16qi3"
21908   [(set (match_operand:V16QI 0 "register_operand" "=x")
21909         (ss_minus:V16QI (match_operand:V16QI 1 "register_operand" "0")
21910                         (match_operand:V16QI 2 "nonimmediate_operand" "xm")))]
21911   "TARGET_SSE2"
21912   "psubsb\t{%2, %0|%0, %2}"
21913   [(set_attr "type" "sseiadd")
21914    (set_attr "mode" "TI")])
21915
21916 (define_insn "sssubv8hi3"
21917   [(set (match_operand:V8HI 0 "register_operand" "=x")
21918         (ss_minus:V8HI (match_operand:V8HI 1 "register_operand" "0")
21919                        (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
21920   "TARGET_SSE2"
21921   "psubsw\t{%2, %0|%0, %2}"
21922   [(set_attr "type" "sseiadd")
21923    (set_attr "mode" "TI")])
21924
21925 (define_insn "ussubv16qi3"
21926   [(set (match_operand:V16QI 0 "register_operand" "=x")
21927         (us_minus:V16QI (match_operand:V16QI 1 "register_operand" "0")
21928                         (match_operand:V16QI 2 "nonimmediate_operand" "xm")))]
21929   "TARGET_SSE2"
21930   "psubusb\t{%2, %0|%0, %2}"
21931   [(set_attr "type" "sseiadd")
21932    (set_attr "mode" "TI")])
21933
21934 (define_insn "ussubv8hi3"
21935   [(set (match_operand:V8HI 0 "register_operand" "=x")
21936         (us_minus:V8HI (match_operand:V8HI 1 "register_operand" "0")
21937                        (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
21938   "TARGET_SSE2"
21939   "psubusw\t{%2, %0|%0, %2}"
21940   [(set_attr "type" "sseiadd")
21941    (set_attr "mode" "TI")])
21942
21943 (define_insn "mulv8hi3"
21944   [(set (match_operand:V8HI 0 "register_operand" "=x")
21945         (mult:V8HI (match_operand:V8HI 1 "register_operand" "0")
21946                    (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
21947   "TARGET_SSE2"
21948   "pmullw\t{%2, %0|%0, %2}"
21949   [(set_attr "type" "sseimul")
21950    (set_attr "mode" "TI")])
21951
21952 (define_insn "smulv8hi3_highpart"
21953   [(set (match_operand:V8HI 0 "register_operand" "=x")
21954         (truncate:V8HI
21955          (lshiftrt:V8SI
21956           (mult:V8SI (sign_extend:V8SI (match_operand:V8HI 1 "register_operand" "0"))
21957                      (sign_extend:V8SI (match_operand:V8HI 2 "nonimmediate_operand" "xm")))
21958           (const_int 16))))]
21959   "TARGET_SSE2"
21960   "pmulhw\t{%2, %0|%0, %2}"
21961   [(set_attr "type" "sseimul")
21962    (set_attr "mode" "TI")])
21963
21964 (define_insn "umulv8hi3_highpart"
21965   [(set (match_operand:V8HI 0 "register_operand" "=x")
21966         (truncate:V8HI
21967          (lshiftrt:V8SI
21968           (mult:V8SI (zero_extend:V8SI (match_operand:V8HI 1 "register_operand" "0"))
21969                      (zero_extend:V8SI (match_operand:V8HI 2 "nonimmediate_operand" "xm")))
21970           (const_int 16))))]
21971   "TARGET_SSE2"
21972   "pmulhuw\t{%2, %0|%0, %2}"
21973   [(set_attr "type" "sseimul")
21974    (set_attr "mode" "TI")])
21975
21976 (define_insn "sse2_umulsidi3"
21977   [(set (match_operand:DI 0 "register_operand" "=y")
21978         (mult:DI (zero_extend:DI (vec_select:SI
21979                                   (match_operand:V2SI 1 "register_operand" "0")
21980                                   (parallel [(const_int 0)])))
21981                  (zero_extend:DI (vec_select:SI
21982                                   (match_operand:V2SI 2 "nonimmediate_operand" "ym")
21983                                   (parallel [(const_int 0)])))))]
21984   "TARGET_SSE2"
21985   "pmuludq\t{%2, %0|%0, %2}"
21986   [(set_attr "type" "sseimul")
21987    (set_attr "mode" "TI")])
21988
21989 (define_insn "sse2_umulv2siv2di3"
21990   [(set (match_operand:V2DI 0 "register_operand" "=x")
21991         (mult:V2DI (zero_extend:V2DI
21992                      (vec_select:V2SI
21993                        (match_operand:V4SI 1 "register_operand" "0")
21994                        (parallel [(const_int 0) (const_int 2)])))
21995                    (zero_extend:V2DI
21996                      (vec_select:V2SI
21997                        (match_operand:V4SI 2 "nonimmediate_operand" "xm")
21998                        (parallel [(const_int 0) (const_int 2)])))))]
21999   "TARGET_SSE2"
22000   "pmuludq\t{%2, %0|%0, %2}"
22001   [(set_attr "type" "sseimul")
22002    (set_attr "mode" "TI")])
22003
22004 (define_insn "sse2_pmaddwd"
22005   [(set (match_operand:V4SI 0 "register_operand" "=x")
22006         (plus:V4SI
22007          (mult:V4SI
22008           (sign_extend:V4SI (vec_select:V4HI (match_operand:V8HI 1 "register_operand" "0")
22009                                              (parallel [(const_int 0)
22010                                                         (const_int 2)
22011                                                         (const_int 4)
22012                                                         (const_int 6)])))
22013           (sign_extend:V4SI (vec_select:V4HI (match_operand:V8HI 2 "nonimmediate_operand" "xm")
22014                                              (parallel [(const_int 0)
22015                                                         (const_int 2)
22016                                                         (const_int 4)
22017                                                         (const_int 6)]))))
22018          (mult:V4SI
22019           (sign_extend:V4SI (vec_select:V4HI (match_dup 1)
22020                                              (parallel [(const_int 1)
22021                                                         (const_int 3)
22022                                                         (const_int 5)
22023                                                         (const_int 7)])))
22024           (sign_extend:V4SI (vec_select:V4HI (match_dup 2)
22025                                              (parallel [(const_int 1)
22026                                                         (const_int 3)
22027                                                         (const_int 5)
22028                                                         (const_int 7)]))))))]
22029   "TARGET_SSE2"
22030   "pmaddwd\t{%2, %0|%0, %2}"
22031   [(set_attr "type" "sseiadd")
22032    (set_attr "mode" "TI")])
22033
22034 ;; Same as pxor, but don't show input operands so that we don't think
22035 ;; they are live.
22036 (define_insn "sse2_clrti"
22037   [(set (match_operand:TI 0 "register_operand" "=x") (const_int 0))]
22038   "TARGET_SSE2"
22039 {
22040   if (get_attr_mode (insn) == MODE_TI)
22041     return "pxor\t%0, %0";
22042   else
22043     return "xorps\t%0, %0";
22044 }
22045   [(set_attr "type" "ssemov")
22046    (set_attr "memory" "none")
22047    (set (attr "mode")
22048               (if_then_else
22049                 (ne (symbol_ref "optimize_size")
22050                     (const_int 0))
22051                 (const_string "V4SF")
22052                 (const_string "TI")))])
22053
22054 ;; MMX unsigned averages/sum of absolute differences
22055
22056 (define_insn "sse2_uavgv16qi3"
22057   [(set (match_operand:V16QI 0 "register_operand" "=x")
22058         (ashiftrt:V16QI
22059          (plus:V16QI (plus:V16QI
22060                      (match_operand:V16QI 1 "register_operand" "0")
22061                      (match_operand:V16QI 2 "nonimmediate_operand" "xm"))
22062                      (const_vector:V16QI [(const_int 1) (const_int 1)
22063                                           (const_int 1) (const_int 1)
22064                                           (const_int 1) (const_int 1)
22065                                           (const_int 1) (const_int 1)
22066                                           (const_int 1) (const_int 1)
22067                                           (const_int 1) (const_int 1)
22068                                           (const_int 1) (const_int 1)
22069                                           (const_int 1) (const_int 1)]))
22070          (const_int 1)))]
22071   "TARGET_SSE2"
22072   "pavgb\t{%2, %0|%0, %2}"
22073   [(set_attr "type" "sseiadd")
22074    (set_attr "mode" "TI")])
22075
22076 (define_insn "sse2_uavgv8hi3"
22077   [(set (match_operand:V8HI 0 "register_operand" "=x")
22078         (ashiftrt:V8HI
22079          (plus:V8HI (plus:V8HI
22080                      (match_operand:V8HI 1 "register_operand" "0")
22081                      (match_operand:V8HI 2 "nonimmediate_operand" "xm"))
22082                     (const_vector:V8HI [(const_int 1) (const_int 1)
22083                                         (const_int 1) (const_int 1)
22084                                         (const_int 1) (const_int 1)
22085                                         (const_int 1) (const_int 1)]))
22086          (const_int 1)))]
22087   "TARGET_SSE2"
22088   "pavgw\t{%2, %0|%0, %2}"
22089   [(set_attr "type" "sseiadd")
22090    (set_attr "mode" "TI")])
22091
22092 ;; @@@ this isn't the right representation.
22093 (define_insn "sse2_psadbw"
22094   [(set (match_operand:V2DI 0 "register_operand" "=x")
22095         (unspec:V2DI [(match_operand:V16QI 1 "register_operand" "0")
22096                       (match_operand:V16QI 2 "nonimmediate_operand" "xm")]
22097                      UNSPEC_PSADBW))]
22098   "TARGET_SSE2"
22099   "psadbw\t{%2, %0|%0, %2}"
22100   [(set_attr "type" "sseiadd")
22101    (set_attr "mode" "TI")])
22102
22103
22104 ;; MMX insert/extract/shuffle
22105
22106 (define_insn "sse2_pinsrw"
22107   [(set (match_operand:V8HI 0 "register_operand" "=x")
22108         (vec_merge:V8HI (match_operand:V8HI 1 "register_operand" "0")
22109                         (vec_duplicate:V8HI
22110                          (truncate:HI
22111                            (match_operand:SI 2 "nonimmediate_operand" "rm")))
22112                         (match_operand:SI 3 "immediate_operand" "i")))]
22113   "TARGET_SSE2"
22114   "pinsrw\t{%3, %2, %0|%0, %2, %3}"
22115   [(set_attr "type" "ssecvt")
22116    (set_attr "mode" "TI")])
22117
22118 (define_insn "sse2_pextrw"
22119   [(set (match_operand:SI 0 "register_operand" "=r")
22120         (zero_extend:SI
22121           (vec_select:HI (match_operand:V8HI 1 "register_operand" "x")
22122                          (parallel
22123                           [(match_operand:SI 2 "immediate_operand" "i")]))))]
22124   "TARGET_SSE2"
22125   "pextrw\t{%2, %1, %0|%0, %1, %2}"
22126   [(set_attr "type" "ssecvt")
22127    (set_attr "mode" "TI")])
22128
22129 (define_insn "sse2_pshufd"
22130   [(set (match_operand:V4SI 0 "register_operand" "=x")
22131         (unspec:V4SI [(match_operand:V4SI 1 "register_operand" "0")
22132                       (match_operand:SI 2 "immediate_operand" "i")]
22133                      UNSPEC_SHUFFLE))]
22134   "TARGET_SSE2"
22135   "pshufd\t{%2, %1, %0|%0, %1, %2}"
22136   [(set_attr "type" "ssecvt")
22137    (set_attr "mode" "TI")])
22138
22139 (define_insn "sse2_pshuflw"
22140   [(set (match_operand:V8HI 0 "register_operand" "=x")
22141         (unspec:V8HI [(match_operand:V8HI 1 "register_operand" "0")
22142                       (match_operand:SI 2 "immediate_operand" "i")]
22143                      UNSPEC_PSHUFLW))]
22144   "TARGET_SSE2"
22145   "pshuflw\t{%2, %1, %0|%0, %1, %2}"
22146   [(set_attr "type" "ssecvt")
22147    (set_attr "mode" "TI")])
22148
22149 (define_insn "sse2_pshufhw"
22150   [(set (match_operand:V8HI 0 "register_operand" "=x")
22151         (unspec:V8HI [(match_operand:V8HI 1 "register_operand" "0")
22152                       (match_operand:SI 2 "immediate_operand" "i")]
22153                      UNSPEC_PSHUFHW))]
22154   "TARGET_SSE2"
22155   "pshufhw\t{%2, %1, %0|%0, %1, %2}"
22156   [(set_attr "type" "ssecvt")
22157    (set_attr "mode" "TI")])
22158
22159 ;; MMX mask-generating comparisons
22160
22161 (define_insn "eqv16qi3"
22162   [(set (match_operand:V16QI 0 "register_operand" "=x")
22163         (eq:V16QI (match_operand:V16QI 1 "register_operand" "0")
22164                  (match_operand:V16QI 2 "nonimmediate_operand" "xm")))]
22165   "TARGET_SSE2"
22166   "pcmpeqb\t{%2, %0|%0, %2}"
22167   [(set_attr "type" "ssecmp")
22168    (set_attr "mode" "TI")])
22169
22170 (define_insn "eqv8hi3"
22171   [(set (match_operand:V8HI 0 "register_operand" "=x")
22172         (eq:V8HI (match_operand:V8HI 1 "register_operand" "0")
22173                  (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
22174   "TARGET_SSE2"
22175   "pcmpeqw\t{%2, %0|%0, %2}"
22176   [(set_attr "type" "ssecmp")
22177    (set_attr "mode" "TI")])
22178
22179 (define_insn "eqv4si3"
22180   [(set (match_operand:V4SI 0 "register_operand" "=x")
22181         (eq:V4SI (match_operand:V4SI 1 "register_operand" "0")
22182                  (match_operand:V4SI 2 "nonimmediate_operand" "xm")))]
22183   "TARGET_SSE2"
22184   "pcmpeqd\t{%2, %0|%0, %2}"
22185   [(set_attr "type" "ssecmp")
22186    (set_attr "mode" "TI")])
22187
22188 (define_insn "gtv16qi3"
22189   [(set (match_operand:V16QI 0 "register_operand" "=x")
22190         (gt:V16QI (match_operand:V16QI 1 "register_operand" "0")
22191                  (match_operand:V16QI 2 "nonimmediate_operand" "xm")))]
22192   "TARGET_SSE2"
22193   "pcmpgtb\t{%2, %0|%0, %2}"
22194   [(set_attr "type" "ssecmp")
22195    (set_attr "mode" "TI")])
22196
22197 (define_insn "gtv8hi3"
22198   [(set (match_operand:V8HI 0 "register_operand" "=x")
22199         (gt:V8HI (match_operand:V8HI 1 "register_operand" "0")
22200                  (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
22201   "TARGET_SSE2"
22202   "pcmpgtw\t{%2, %0|%0, %2}"
22203   [(set_attr "type" "ssecmp")
22204    (set_attr "mode" "TI")])
22205
22206 (define_insn "gtv4si3"
22207   [(set (match_operand:V4SI 0 "register_operand" "=x")
22208         (gt:V4SI (match_operand:V4SI 1 "register_operand" "0")
22209                  (match_operand:V4SI 2 "nonimmediate_operand" "xm")))]
22210   "TARGET_SSE2"
22211   "pcmpgtd\t{%2, %0|%0, %2}"
22212   [(set_attr "type" "ssecmp")
22213    (set_attr "mode" "TI")])
22214
22215
22216 ;; MMX max/min insns
22217
22218 (define_insn "umaxv16qi3"
22219   [(set (match_operand:V16QI 0 "register_operand" "=x")
22220         (umax:V16QI (match_operand:V16QI 1 "register_operand" "0")
22221                    (match_operand:V16QI 2 "nonimmediate_operand" "xm")))]
22222   "TARGET_SSE2"
22223   "pmaxub\t{%2, %0|%0, %2}"
22224   [(set_attr "type" "sseiadd")
22225    (set_attr "mode" "TI")])
22226
22227 (define_insn "smaxv8hi3"
22228   [(set (match_operand:V8HI 0 "register_operand" "=x")
22229         (smax:V8HI (match_operand:V8HI 1 "register_operand" "0")
22230                    (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
22231   "TARGET_SSE2"
22232   "pmaxsw\t{%2, %0|%0, %2}"
22233   [(set_attr "type" "sseiadd")
22234    (set_attr "mode" "TI")])
22235
22236 (define_insn "uminv16qi3"
22237   [(set (match_operand:V16QI 0 "register_operand" "=x")
22238         (umin:V16QI (match_operand:V16QI 1 "register_operand" "0")
22239                    (match_operand:V16QI 2 "nonimmediate_operand" "xm")))]
22240   "TARGET_SSE2"
22241   "pminub\t{%2, %0|%0, %2}"
22242   [(set_attr "type" "sseiadd")
22243    (set_attr "mode" "TI")])
22244
22245 (define_insn "sminv8hi3"
22246   [(set (match_operand:V8HI 0 "register_operand" "=x")
22247         (smin:V8HI (match_operand:V8HI 1 "register_operand" "0")
22248                    (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
22249   "TARGET_SSE2"
22250   "pminsw\t{%2, %0|%0, %2}"
22251   [(set_attr "type" "sseiadd")
22252    (set_attr "mode" "TI")])
22253
22254
22255 ;; MMX shifts
22256
22257 (define_insn "ashrv8hi3"
22258   [(set (match_operand:V8HI 0 "register_operand" "=x")
22259         (ashiftrt:V8HI (match_operand:V8HI 1 "register_operand" "0")
22260                        (match_operand:TI 2 "nonmemory_operand" "xi")))]
22261   "TARGET_SSE2"
22262   "psraw\t{%2, %0|%0, %2}"
22263   [(set_attr "type" "sseishft")
22264    (set_attr "mode" "TI")])
22265
22266 (define_insn "ashrv4si3"
22267   [(set (match_operand:V4SI 0 "register_operand" "=x")
22268         (ashiftrt:V4SI (match_operand:V4SI 1 "register_operand" "0")
22269                        (match_operand:TI 2 "nonmemory_operand" "xi")))]
22270   "TARGET_SSE2"
22271   "psrad\t{%2, %0|%0, %2}"
22272   [(set_attr "type" "sseishft")
22273    (set_attr "mode" "TI")])
22274
22275 (define_insn "lshrv8hi3"
22276   [(set (match_operand:V8HI 0 "register_operand" "=x")
22277         (lshiftrt:V8HI (match_operand:V8HI 1 "register_operand" "0")
22278                        (match_operand:TI 2 "nonmemory_operand" "xi")))]
22279   "TARGET_SSE2"
22280   "psrlw\t{%2, %0|%0, %2}"
22281   [(set_attr "type" "sseishft")
22282    (set_attr "mode" "TI")])
22283
22284 (define_insn "lshrv4si3"
22285   [(set (match_operand:V4SI 0 "register_operand" "=x")
22286         (lshiftrt:V4SI (match_operand:V4SI 1 "register_operand" "0")
22287                        (match_operand:TI 2 "nonmemory_operand" "xi")))]
22288   "TARGET_SSE2"
22289   "psrld\t{%2, %0|%0, %2}"
22290   [(set_attr "type" "sseishft")
22291    (set_attr "mode" "TI")])
22292
22293 (define_insn "lshrv2di3"
22294   [(set (match_operand:V2DI 0 "register_operand" "=x")
22295         (lshiftrt:V2DI (match_operand:V2DI 1 "register_operand" "0")
22296                        (match_operand:TI 2 "nonmemory_operand" "xi")))]
22297   "TARGET_SSE2"
22298   "psrlq\t{%2, %0|%0, %2}"
22299   [(set_attr "type" "sseishft")
22300    (set_attr "mode" "TI")])
22301
22302 (define_insn "ashlv8hi3"
22303   [(set (match_operand:V8HI 0 "register_operand" "=x")
22304         (ashift:V8HI (match_operand:V8HI 1 "register_operand" "0")
22305                      (match_operand:TI 2 "nonmemory_operand" "xi")))]
22306   "TARGET_SSE2"
22307   "psllw\t{%2, %0|%0, %2}"
22308   [(set_attr "type" "sseishft")
22309    (set_attr "mode" "TI")])
22310
22311 (define_insn "ashlv4si3"
22312   [(set (match_operand:V4SI 0 "register_operand" "=x")
22313         (ashift:V4SI (match_operand:V4SI 1 "register_operand" "0")
22314                      (match_operand:TI 2 "nonmemory_operand" "xi")))]
22315   "TARGET_SSE2"
22316   "pslld\t{%2, %0|%0, %2}"
22317   [(set_attr "type" "sseishft")
22318    (set_attr "mode" "TI")])
22319
22320 (define_insn "ashlv2di3"
22321   [(set (match_operand:V2DI 0 "register_operand" "=x")
22322         (ashift:V2DI (match_operand:V2DI 1 "register_operand" "0")
22323                      (match_operand:TI 2 "nonmemory_operand" "xi")))]
22324   "TARGET_SSE2"
22325   "psllq\t{%2, %0|%0, %2}"
22326   [(set_attr "type" "sseishft")
22327    (set_attr "mode" "TI")])
22328
22329 (define_insn "ashrv8hi3_ti"
22330   [(set (match_operand:V8HI 0 "register_operand" "=x")
22331         (ashiftrt:V8HI (match_operand:V8HI 1 "register_operand" "0")
22332                        (subreg:TI (match_operand:V2DI 2 "nonmemory_operand" "xi") 0)))]
22333   "TARGET_SSE2"
22334   "psraw\t{%2, %0|%0, %2}"
22335   [(set_attr "type" "sseishft")
22336    (set_attr "mode" "TI")])
22337
22338 (define_insn "ashrv4si3_ti"
22339   [(set (match_operand:V4SI 0 "register_operand" "=x")
22340         (ashiftrt:V4SI (match_operand:V4SI 1 "register_operand" "0")
22341                        (subreg:TI (match_operand:V2DI 2 "nonmemory_operand" "xi") 0)))]
22342   "TARGET_SSE2"
22343   "psrad\t{%2, %0|%0, %2}"
22344   [(set_attr "type" "sseishft")
22345    (set_attr "mode" "TI")])
22346
22347 (define_insn "lshrv8hi3_ti"
22348   [(set (match_operand:V8HI 0 "register_operand" "=x")
22349         (lshiftrt:V8HI (match_operand:V8HI 1 "register_operand" "0")
22350                        (subreg:TI (match_operand:V2DI 2 "nonmemory_operand" "xi") 0)))]
22351   "TARGET_SSE2"
22352   "psrlw\t{%2, %0|%0, %2}"
22353   [(set_attr "type" "sseishft")
22354    (set_attr "mode" "TI")])
22355
22356 (define_insn "lshrv4si3_ti"
22357   [(set (match_operand:V4SI 0 "register_operand" "=x")
22358         (lshiftrt:V4SI (match_operand:V4SI 1 "register_operand" "0")
22359                        (subreg:TI (match_operand:V2DI 2 "nonmemory_operand" "xi") 0)))]
22360   "TARGET_SSE2"
22361   "psrld\t{%2, %0|%0, %2}"
22362   [(set_attr "type" "sseishft")
22363    (set_attr "mode" "TI")])
22364
22365 (define_insn "lshrv2di3_ti"
22366   [(set (match_operand:V2DI 0 "register_operand" "=x")
22367         (lshiftrt:V2DI (match_operand:V2DI 1 "register_operand" "0")
22368                        (subreg:TI (match_operand:V2DI 2 "nonmemory_operand" "xi") 0)))]
22369   "TARGET_SSE2"
22370   "psrlq\t{%2, %0|%0, %2}"
22371   [(set_attr "type" "sseishft")
22372    (set_attr "mode" "TI")])
22373
22374 (define_insn "ashlv8hi3_ti"
22375   [(set (match_operand:V8HI 0 "register_operand" "=x")
22376         (ashift:V8HI (match_operand:V8HI 1 "register_operand" "0")
22377                      (subreg:TI (match_operand:V2DI 2 "nonmemory_operand" "xi") 0)))]
22378   "TARGET_SSE2"
22379   "psllw\t{%2, %0|%0, %2}"
22380   [(set_attr "type" "sseishft")
22381    (set_attr "mode" "TI")])
22382
22383 (define_insn "ashlv4si3_ti"
22384   [(set (match_operand:V4SI 0 "register_operand" "=x")
22385         (ashift:V4SI (match_operand:V4SI 1 "register_operand" "0")
22386                      (subreg:TI (match_operand:V2DI 2 "nonmemory_operand" "xi") 0)))]
22387   "TARGET_SSE2"
22388   "pslld\t{%2, %0|%0, %2}"
22389   [(set_attr "type" "sseishft")
22390    (set_attr "mode" "TI")])
22391
22392 (define_insn "ashlv2di3_ti"
22393   [(set (match_operand:V2DI 0 "register_operand" "=x")
22394         (ashift:V2DI (match_operand:V2DI 1 "register_operand" "0")
22395                      (subreg:TI (match_operand:V2DI 2 "nonmemory_operand" "xi") 0)))]
22396   "TARGET_SSE2"
22397   "psllq\t{%2, %0|%0, %2}"
22398   [(set_attr "type" "sseishft")
22399    (set_attr "mode" "TI")])
22400
22401 ;; See logical MMX insns for the reason for the unspec.  Strictly speaking
22402 ;; we wouldn't need here it since we never generate TImode arithmetic.
22403
22404 ;; There has to be some kind of prize for the weirdest new instruction...
22405 (define_insn "sse2_ashlti3"
22406   [(set (match_operand:TI 0 "register_operand" "=x")
22407         (unspec:TI
22408          [(ashift:TI (match_operand:TI 1 "register_operand" "0")
22409                      (mult:SI (match_operand:SI 2 "immediate_operand" "i")
22410                                (const_int 8)))] UNSPEC_NOP))]
22411   "TARGET_SSE2"
22412   "pslldq\t{%2, %0|%0, %2}"
22413   [(set_attr "type" "sseishft")
22414    (set_attr "mode" "TI")])
22415
22416 (define_insn "sse2_lshrti3"
22417   [(set (match_operand:TI 0 "register_operand" "=x")
22418         (unspec:TI
22419          [(lshiftrt:TI (match_operand:TI 1 "register_operand" "0")
22420                        (mult:SI (match_operand:SI 2 "immediate_operand" "i")
22421                                 (const_int 8)))] UNSPEC_NOP))]
22422   "TARGET_SSE2"
22423   "psrldq\t{%2, %0|%0, %2}"
22424   [(set_attr "type" "sseishft")
22425    (set_attr "mode" "TI")])
22426
22427 ;; SSE unpack
22428
22429 (define_insn "sse2_unpckhpd"
22430   [(set (match_operand:V2DF 0 "register_operand" "=x")
22431         (vec_concat:V2DF
22432          (vec_select:DF (match_operand:V2DF 1 "register_operand" "0")
22433                         (parallel [(const_int 1)]))
22434          (vec_select:DF (match_operand:V2DF 2 "register_operand" "x")
22435                         (parallel [(const_int 0)]))))]
22436   "TARGET_SSE2"
22437   "unpckhpd\t{%2, %0|%0, %2}"
22438   [(set_attr "type" "ssecvt")
22439    (set_attr "mode" "TI")])
22440
22441 (define_insn "sse2_unpcklpd"
22442   [(set (match_operand:V2DF 0 "register_operand" "=x")
22443         (vec_concat:V2DF
22444          (vec_select:DF (match_operand:V2DF 1 "register_operand" "0")
22445                         (parallel [(const_int 0)]))
22446          (vec_select:DF (match_operand:V2DF 2 "register_operand" "x")
22447                         (parallel [(const_int 1)]))))]
22448   "TARGET_SSE2"
22449   "unpcklpd\t{%2, %0|%0, %2}"
22450   [(set_attr "type" "ssecvt")
22451    (set_attr "mode" "TI")])
22452
22453 ;; MMX pack/unpack insns.
22454
22455 (define_insn "sse2_packsswb"
22456   [(set (match_operand:V16QI 0 "register_operand" "=x")
22457         (vec_concat:V16QI
22458          (ss_truncate:V8QI (match_operand:V8HI 1 "register_operand" "0"))
22459          (ss_truncate:V8QI (match_operand:V8HI 2 "register_operand" "x"))))]
22460   "TARGET_SSE2"
22461   "packsswb\t{%2, %0|%0, %2}"
22462   [(set_attr "type" "ssecvt")
22463    (set_attr "mode" "TI")])
22464
22465 (define_insn "sse2_packssdw"
22466   [(set (match_operand:V8HI 0 "register_operand" "=x")
22467         (vec_concat:V8HI
22468          (ss_truncate:V4HI (match_operand:V4SI 1 "register_operand" "0"))
22469          (ss_truncate:V4HI (match_operand:V4SI 2 "register_operand" "x"))))]
22470   "TARGET_SSE2"
22471   "packssdw\t{%2, %0|%0, %2}"
22472   [(set_attr "type" "ssecvt")
22473    (set_attr "mode" "TI")])
22474
22475 (define_insn "sse2_packuswb"
22476   [(set (match_operand:V16QI 0 "register_operand" "=x")
22477         (vec_concat:V16QI
22478          (us_truncate:V8QI (match_operand:V8HI 1 "register_operand" "0"))
22479          (us_truncate:V8QI (match_operand:V8HI 2 "register_operand" "x"))))]
22480   "TARGET_SSE2"
22481   "packuswb\t{%2, %0|%0, %2}"
22482   [(set_attr "type" "ssecvt")
22483    (set_attr "mode" "TI")])
22484
22485 (define_insn "sse2_punpckhbw"
22486   [(set (match_operand:V16QI 0 "register_operand" "=x")
22487         (vec_merge:V16QI
22488          (vec_select:V16QI (match_operand:V16QI 1 "register_operand" "0")
22489                            (parallel [(const_int 8) (const_int 0)
22490                                       (const_int 9) (const_int 1)
22491                                       (const_int 10) (const_int 2)
22492                                       (const_int 11) (const_int 3)
22493                                       (const_int 12) (const_int 4)
22494                                       (const_int 13) (const_int 5)
22495                                       (const_int 14) (const_int 6)
22496                                       (const_int 15) (const_int 7)]))
22497          (vec_select:V16QI (match_operand:V16QI 2 "register_operand" "x")
22498                            (parallel [(const_int 0) (const_int 8)
22499                                       (const_int 1) (const_int 9)
22500                                       (const_int 2) (const_int 10)
22501                                       (const_int 3) (const_int 11)
22502                                       (const_int 4) (const_int 12)
22503                                       (const_int 5) (const_int 13)
22504                                       (const_int 6) (const_int 14)
22505                                       (const_int 7) (const_int 15)]))
22506          (const_int 21845)))]
22507   "TARGET_SSE2"
22508   "punpckhbw\t{%2, %0|%0, %2}"
22509   [(set_attr "type" "ssecvt")
22510    (set_attr "mode" "TI")])
22511
22512 (define_insn "sse2_punpckhwd"
22513   [(set (match_operand:V8HI 0 "register_operand" "=x")
22514         (vec_merge:V8HI
22515          (vec_select:V8HI (match_operand:V8HI 1 "register_operand" "0")
22516                           (parallel [(const_int 4) (const_int 0)
22517                                      (const_int 5) (const_int 1)
22518                                      (const_int 6) (const_int 2)
22519                                      (const_int 7) (const_int 3)]))
22520          (vec_select:V8HI (match_operand:V8HI 2 "register_operand" "x")
22521                           (parallel [(const_int 0) (const_int 4)
22522                                      (const_int 1) (const_int 5)
22523                                      (const_int 2) (const_int 6)
22524                                      (const_int 3) (const_int 7)]))
22525          (const_int 85)))]
22526   "TARGET_SSE2"
22527   "punpckhwd\t{%2, %0|%0, %2}"
22528   [(set_attr "type" "ssecvt")
22529    (set_attr "mode" "TI")])
22530
22531 (define_insn "sse2_punpckhdq"
22532   [(set (match_operand:V4SI 0 "register_operand" "=x")
22533         (vec_merge:V4SI
22534          (vec_select:V4SI (match_operand:V4SI 1 "register_operand" "0")
22535                           (parallel [(const_int 2) (const_int 0)
22536                                      (const_int 3) (const_int 1)]))
22537          (vec_select:V4SI (match_operand:V4SI 2 "register_operand" "x")
22538                           (parallel [(const_int 0) (const_int 2)
22539                                      (const_int 1) (const_int 3)]))
22540          (const_int 5)))]
22541   "TARGET_SSE2"
22542   "punpckhdq\t{%2, %0|%0, %2}"
22543   [(set_attr "type" "ssecvt")
22544    (set_attr "mode" "TI")])
22545
22546 (define_insn "sse2_punpcklbw"
22547   [(set (match_operand:V16QI 0 "register_operand" "=x")
22548         (vec_merge:V16QI
22549          (vec_select:V16QI (match_operand:V16QI 1 "register_operand" "0")
22550                            (parallel [(const_int 0) (const_int 8)
22551                                       (const_int 1) (const_int 9)
22552                                       (const_int 2) (const_int 10)
22553                                       (const_int 3) (const_int 11)
22554                                       (const_int 4) (const_int 12)
22555                                       (const_int 5) (const_int 13)
22556                                       (const_int 6) (const_int 14)
22557                                       (const_int 7) (const_int 15)]))
22558          (vec_select:V16QI (match_operand:V16QI 2 "register_operand" "x")
22559                            (parallel [(const_int 8) (const_int 0)
22560                                       (const_int 9) (const_int 1)
22561                                       (const_int 10) (const_int 2)
22562                                       (const_int 11) (const_int 3)
22563                                       (const_int 12) (const_int 4)
22564                                       (const_int 13) (const_int 5)
22565                                       (const_int 14) (const_int 6)
22566                                       (const_int 15) (const_int 7)]))
22567          (const_int 21845)))]
22568   "TARGET_SSE2"
22569   "punpcklbw\t{%2, %0|%0, %2}"
22570   [(set_attr "type" "ssecvt")
22571    (set_attr "mode" "TI")])
22572
22573 (define_insn "sse2_punpcklwd"
22574   [(set (match_operand:V8HI 0 "register_operand" "=x")
22575         (vec_merge:V8HI
22576          (vec_select:V8HI (match_operand:V8HI 1 "register_operand" "0")
22577                           (parallel [(const_int 0) (const_int 4)
22578                                      (const_int 1) (const_int 5)
22579                                      (const_int 2) (const_int 6)
22580                                      (const_int 3) (const_int 7)]))
22581          (vec_select:V8HI (match_operand:V8HI 2 "register_operand" "x")
22582                           (parallel [(const_int 4) (const_int 0)
22583                                      (const_int 5) (const_int 1)
22584                                      (const_int 6) (const_int 2)
22585                                      (const_int 7) (const_int 3)]))
22586          (const_int 85)))]
22587   "TARGET_SSE2"
22588   "punpcklwd\t{%2, %0|%0, %2}"
22589   [(set_attr "type" "ssecvt")
22590    (set_attr "mode" "TI")])
22591
22592 (define_insn "sse2_punpckldq"
22593   [(set (match_operand:V4SI 0 "register_operand" "=x")
22594         (vec_merge:V4SI
22595          (vec_select:V4SI (match_operand:V4SI 1 "register_operand" "0")
22596                           (parallel [(const_int 0) (const_int 2)
22597                                      (const_int 1) (const_int 3)]))
22598          (vec_select:V4SI (match_operand:V4SI 2 "register_operand" "x")
22599                           (parallel [(const_int 2) (const_int 0)
22600                                      (const_int 3) (const_int 1)]))
22601          (const_int 5)))]
22602   "TARGET_SSE2"
22603   "punpckldq\t{%2, %0|%0, %2}"
22604   [(set_attr "type" "ssecvt")
22605    (set_attr "mode" "TI")])
22606
22607 (define_insn "sse2_punpcklqdq"
22608   [(set (match_operand:V2DI 0 "register_operand" "=x")
22609         (vec_merge:V2DI
22610          (vec_select:V2DI (match_operand:V2DI 2 "register_operand" "x")
22611                           (parallel [(const_int 1)
22612                                      (const_int 0)]))
22613          (match_operand:V2DI 1 "register_operand" "0")
22614          (const_int 1)))]
22615   "TARGET_SSE2"
22616   "punpcklqdq\t{%2, %0|%0, %2}"
22617   [(set_attr "type" "ssecvt")
22618    (set_attr "mode" "TI")])
22619
22620 (define_insn "sse2_punpckhqdq"
22621   [(set (match_operand:V2DI 0 "register_operand" "=x")
22622         (vec_merge:V2DI
22623          (match_operand:V2DI 1 "register_operand" "0")
22624          (vec_select:V2DI (match_operand:V2DI 2 "register_operand" "x")
22625                           (parallel [(const_int 1)
22626                                      (const_int 0)]))
22627          (const_int 1)))]
22628   "TARGET_SSE2"
22629   "punpckhqdq\t{%2, %0|%0, %2}"
22630   [(set_attr "type" "ssecvt")
22631    (set_attr "mode" "TI")])
22632
22633 ;; SSE2 moves
22634
22635 (define_insn "sse2_movapd"
22636   [(set (match_operand:V2DF 0 "nonimmediate_operand" "=x,m")
22637         (unspec:V2DF [(match_operand:V2DF 1 "nonimmediate_operand" "xm,x")]
22638                      UNSPEC_MOVA))]
22639   "TARGET_SSE2
22640    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
22641   "movapd\t{%1, %0|%0, %1}"
22642   [(set_attr "type" "ssemov")
22643    (set_attr "mode" "V2DF")])
22644
22645 (define_insn "sse2_movupd"
22646   [(set (match_operand:V2DF 0 "nonimmediate_operand" "=x,m")
22647         (unspec:V2DF [(match_operand:V2DF 1 "nonimmediate_operand" "xm,x")]
22648                      UNSPEC_MOVU))]
22649   "TARGET_SSE2
22650    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
22651   "movupd\t{%1, %0|%0, %1}"
22652   [(set_attr "type" "ssecvt")
22653    (set_attr "mode" "V2DF")])
22654
22655 (define_insn "sse2_movdqa"
22656   [(set (match_operand:V16QI 0 "nonimmediate_operand" "=x,m")
22657         (unspec:V16QI [(match_operand:V16QI 1 "nonimmediate_operand" "xm,x")]
22658                        UNSPEC_MOVA))]
22659   "TARGET_SSE2
22660    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
22661   "movdqa\t{%1, %0|%0, %1}"
22662   [(set_attr "type" "ssemov")
22663    (set_attr "mode" "TI")])
22664
22665 (define_insn "sse2_movdqu"
22666   [(set (match_operand:V16QI 0 "nonimmediate_operand" "=x,m")
22667         (unspec:V16QI [(match_operand:V16QI 1 "nonimmediate_operand" "xm,x")]
22668                        UNSPEC_MOVU))]
22669   "TARGET_SSE2
22670    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
22671   "movdqu\t{%1, %0|%0, %1}"
22672   [(set_attr "type" "ssecvt")
22673    (set_attr "mode" "TI")])
22674
22675 (define_insn "sse2_movdq2q"
22676   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,y")
22677         (vec_select:DI (match_operand:V2DI 1 "register_operand" "x,x")
22678                        (parallel [(const_int 0)])))]
22679   "TARGET_SSE2"
22680   "@
22681    movq\t{%1, %0|%0, %1}
22682    movdq2q\t{%1, %0|%0, %1}"
22683   [(set_attr "type" "ssecvt")
22684    (set_attr "mode" "TI")])
22685
22686 (define_insn "sse2_movq2dq"
22687   [(set (match_operand:V2DI 0 "register_operand" "=x,?x")
22688         (vec_concat:V2DI (match_operand:DI 1 "nonimmediate_operand" "m,y")
22689                          (const_int 0)))]
22690   "TARGET_SSE2"
22691   "@
22692    movq\t{%1, %0|%0, %1}
22693    movq2dq\t{%1, %0|%0, %1}"
22694   [(set_attr "type" "ssecvt,ssemov")
22695    (set_attr "mode" "TI")])
22696
22697 (define_insn "sse2_movq"
22698   [(set (match_operand:V2DI 0 "register_operand" "=x")
22699         (vec_concat:V2DI (vec_select:DI
22700                           (match_operand:V2DI 1 "nonimmediate_operand" "xm")
22701                           (parallel [(const_int 0)]))
22702                          (const_int 0)))]
22703   "TARGET_SSE2"
22704   "movq\t{%1, %0|%0, %1}"
22705   [(set_attr "type" "ssemov")
22706    (set_attr "mode" "TI")])
22707
22708 (define_insn "sse2_loadd"
22709   [(set (match_operand:V4SI 0 "register_operand" "=x")
22710         (vec_merge:V4SI
22711          (vec_duplicate:V4SI (match_operand:SI 1 "nonimmediate_operand" "mr"))
22712          (const_vector:V4SI [(const_int 0)
22713                              (const_int 0)
22714                              (const_int 0)
22715                              (const_int 0)])
22716          (const_int 1)))]
22717   "TARGET_SSE2"
22718   "movd\t{%1, %0|%0, %1}"
22719   [(set_attr "type" "ssemov")
22720    (set_attr "mode" "TI")])
22721
22722 (define_insn "sse2_stored"
22723   [(set (match_operand:SI 0 "nonimmediate_operand" "=mr")
22724         (vec_select:SI
22725          (match_operand:V4SI 1 "register_operand" "x")
22726          (parallel [(const_int 0)])))]
22727   "TARGET_SSE2"
22728   "movd\t{%1, %0|%0, %1}"
22729   [(set_attr "type" "ssemov")
22730    (set_attr "mode" "TI")])
22731
22732 (define_insn "sse2_movhpd"
22733   [(set (match_operand:V2DF 0 "nonimmediate_operand" "=x,m")
22734         (vec_merge:V2DF
22735          (match_operand:V2DF 1 "nonimmediate_operand" "0,0")
22736          (match_operand:V2DF 2 "nonimmediate_operand" "m,x")
22737          (const_int 2)))]
22738   "TARGET_SSE2 && (GET_CODE (operands[1]) == MEM || GET_CODE (operands[2]) == MEM)"
22739   "movhpd\t{%2, %0|%0, %2}"
22740   [(set_attr "type" "ssecvt")
22741    (set_attr "mode" "V2DF")])
22742
22743 (define_insn "sse2_movlpd"
22744   [(set (match_operand:V2DF 0 "nonimmediate_operand" "=x,m")
22745         (vec_merge:V2DF
22746          (match_operand:V2DF 1 "nonimmediate_operand" "0,0")
22747          (match_operand:V2DF 2 "nonimmediate_operand" "m,x")
22748          (const_int 1)))]
22749   "TARGET_SSE2 && (GET_CODE (operands[1]) == MEM || GET_CODE (operands[2]) == MEM)"
22750   "movlpd\t{%2, %0|%0, %2}"
22751   [(set_attr "type" "ssecvt")
22752    (set_attr "mode" "V2DF")])
22753
22754 (define_expand "sse2_loadsd"
22755   [(match_operand:V2DF 0 "register_operand" "")
22756    (match_operand:DF 1 "memory_operand" "")]
22757   "TARGET_SSE2"
22758 {
22759   emit_insn (gen_sse2_loadsd_1 (operands[0], operands[1],
22760                                 CONST0_RTX (V2DFmode)));
22761   DONE;
22762 })
22763
22764 (define_insn "sse2_loadsd_1"
22765   [(set (match_operand:V2DF 0 "register_operand" "=x")
22766         (vec_merge:V2DF
22767          (vec_duplicate:V2DF (match_operand:DF 1 "memory_operand" "m"))
22768          (match_operand:V2DF 2 "const0_operand" "X")
22769          (const_int 1)))]
22770   "TARGET_SSE2"
22771   "movsd\t{%1, %0|%0, %1}"
22772   [(set_attr "type" "ssecvt")
22773    (set_attr "mode" "DF")])
22774
22775 (define_insn "sse2_movsd"
22776   [(set (match_operand:V2DF 0 "register_operand" "=x")
22777         (vec_merge:V2DF
22778          (match_operand:V2DF 1 "register_operand" "0")
22779          (match_operand:V2DF 2 "register_operand" "x")
22780          (const_int 1)))]
22781   "TARGET_SSE2"
22782   "movsd\t{%2, %0|%0, %2}"
22783   [(set_attr "type" "ssecvt")
22784    (set_attr "mode" "DF")])
22785
22786 (define_insn "sse2_storesd"
22787   [(set (match_operand:DF 0 "memory_operand" "=m")
22788         (vec_select:DF
22789          (match_operand:V2DF 1 "register_operand" "x")
22790          (parallel [(const_int 0)])))]
22791   "TARGET_SSE2"
22792   "movsd\t{%1, %0|%0, %1}"
22793   [(set_attr "type" "ssecvt")
22794    (set_attr "mode" "DF")])
22795
22796 (define_insn "sse2_shufpd"
22797   [(set (match_operand:V2DF 0 "register_operand" "=x")
22798         (unspec:V2DF [(match_operand:V2DF 1 "register_operand" "0")
22799                       (match_operand:V2DF 2 "nonimmediate_operand" "xm")
22800                       (match_operand:SI 3 "immediate_operand" "i")]
22801                      UNSPEC_SHUFFLE))]
22802   "TARGET_SSE2"
22803   ;; @@@ check operand order for intel/nonintel syntax
22804   "shufpd\t{%3, %2, %0|%0, %2, %3}"
22805   [(set_attr "type" "ssecvt")
22806    (set_attr "mode" "V2DF")])
22807
22808 (define_insn "sse2_clflush"
22809   [(unspec_volatile [(match_operand 0 "address_operand" "p")]
22810                     UNSPECV_CLFLUSH)]
22811   "TARGET_SSE2"
22812   "clflush %0"
22813   [(set_attr "type" "sse")
22814    (set_attr "memory" "unknown")])
22815
22816 (define_expand "sse2_mfence"
22817   [(set (match_dup 0)
22818         (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
22819   "TARGET_SSE2"
22820 {
22821   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
22822   MEM_VOLATILE_P (operands[0]) = 1;
22823 })
22824
22825 (define_insn "*mfence_insn"
22826   [(set (match_operand:BLK 0 "" "")
22827         (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
22828   "TARGET_SSE2"
22829   "mfence"
22830   [(set_attr "type" "sse")
22831    (set_attr "memory" "unknown")])
22832
22833 (define_expand "sse2_lfence"
22834   [(set (match_dup 0)
22835         (unspec:BLK [(match_dup 0)] UNSPEC_LFENCE))]
22836   "TARGET_SSE2"
22837 {
22838   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
22839   MEM_VOLATILE_P (operands[0]) = 1;
22840 })
22841
22842 (define_insn "*lfence_insn"
22843   [(set (match_operand:BLK 0 "" "")
22844         (unspec:BLK [(match_dup 0)] UNSPEC_LFENCE))]
22845   "TARGET_SSE2"
22846   "lfence"
22847   [(set_attr "type" "sse")
22848    (set_attr "memory" "unknown")])