OSDN Git Service

56158b9b22eab3b84b6de0b5067d1c469f2d185a
[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, 2001
3 ;; Free Software Foundation, Inc.
4 ;; Mostly by William Schelter.
5 ;; x86_64 support added by Jan Hubicka
6 ;;
7 ;; This file is part of GNU CC.
8 ;;
9 ;; GNU CC is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13 ;;
14 ;; GNU CC is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18 ;;
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU CC; see the file COPYING.  If not, write to
21 ;; the Free Software Foundation, 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA. */
23 ;;
24 ;; The original PO technology requires these to be ordered by speed,
25 ;; so that assigner will pick the fastest.
26 ;;
27 ;; See file "rtl.def" for documentation on define_insn, match_*, et. al.
28 ;;
29 ;; Macro #define NOTICE_UPDATE_CC in file i386.h handles condition code
30 ;; updates for most instructions.
31 ;;
32 ;; Macro REG_CLASS_FROM_LETTER in file i386.h defines the register
33 ;; constraint letters.
34 ;;
35 ;; The special asm out single letter directives following a '%' are:
36 ;; 'z' mov%z1 would be movl, movw, or movb depending on the mode of
37 ;;     operands[1].
38 ;; 'L' Print the opcode suffix for a 32-bit integer opcode.
39 ;; 'W' Print the opcode suffix for a 16-bit integer opcode.
40 ;; 'B' Print the opcode suffix for an 8-bit integer opcode.
41 ;; 'Q' Print the opcode suffix for a 64-bit float opcode.
42 ;; 'S' Print the opcode suffix for a 32-bit float opcode.
43 ;; 'T' Print the opcode suffix for an 80-bit extended real XFmode float opcode.
44 ;; 'J' Print the appropriate jump operand.
45 ;;
46 ;; 'b' Print the QImode name of the register for the indicated operand.
47 ;;     %b0 would print %al if operands[0] is reg 0.
48 ;; 'w' Likewise, print the HImode name of the register.
49 ;; 'k' Likewise, print the SImode name of the register.
50 ;; 'h' Print the QImode name for a "high" register, either ah, bh, ch or dh.
51 ;; 'y' Print "st(0)" instead of "st" as a register.
52 ;;
53 ;; UNSPEC usage:
54 ;; 0  This is a `scas' operation.  The mode of the UNSPEC is always SImode.
55 ;;    operand 0 is the memory address to scan.
56 ;;    operand 1 is a register containing the value to scan for.  The mode
57 ;;       of the scas opcode will be the same as the mode of this operand.
58 ;;    operand 2 is the known alignment of operand 0.
59 ;; 1  This is a `sin' operation.  The mode of the UNSPEC is MODE_FLOAT.
60 ;;    operand 0 is the argument for `sin'.
61 ;; 2  This is a `cos' operation.  The mode of the UNSPEC is MODE_FLOAT.
62 ;;    operand 0 is the argument for `cos'.
63 ;; 3  This is part of a `stack probe' operation.  The mode of the UNSPEC is 
64 ;;    always SImode.  operand 0 is the size of the stack allocation.
65 ;; 4  This is the source of a fake SET of the frame pointer which is used to
66 ;;    prevent insns referencing it being scheduled across the initial
67 ;;    decrement of the stack pointer.
68 ;; 5  This is a `bsf' operation.
69 ;; 6  This is the @GOT offset of a PIC address.
70 ;; 7  This is the @GOTOFF offset of a PIC address.
71 ;; 8  This is a reference to a symbol's @PLT address.
72 ;; 9  This is an `fnstsw' operation.
73 ;; 10 This is a `sahf' operation.
74 ;; 11 This is a `fstcw' operation
75 ;; 12 This is behaviour of add when setting carry flag.
76 ;; 13 This is a `eh_return' placeholder.
77
78 ;; For SSE/MMX support:
79 ;; 30 This is `fix', guaranteed to be truncating.
80 ;; 31 This is a `emms' operation.
81 ;; 32 This is a `maskmov' operation.
82 ;; 33 This is a `movmsk' operation.
83 ;; 34 This is a `non-temporal' move.
84 ;; 35 This is a `prefetch' operation.
85 ;; 36 This is used to distinguish COMISS from UCOMISS.
86 ;; 37 This is a `ldmxcsr' operation.
87 ;; 38 This is a forced `movaps' instruction (rather than whatever movti does)
88 ;; 39 This is a forced `movups' instruction (rather than whatever movti does)
89 ;; 40 This is a `stmxcsr' operation.
90 ;; 41 This is a `shuffle' operation.
91 ;; 42 This is a `rcp' operation.
92 ;; 43 This is a `rsqsrt' operation.
93 ;; 44 This is a `sfence' operation.
94 ;; 45 This is a noop to prevent excessive combiner cleverness.
95
96 ;; Insns whose names begin with "x86_" are emitted by gen_FOO calls
97 ;; from i386.c.
98
99 \f
100 ;; Processor type.  This attribute must exactly match the processor_type
101 ;; enumeration in i386.h.
102 (define_attr "cpu" "i386,i486,pentium,pentiumpro,k6,athlon,pentium4"
103   (const (symbol_ref "ix86_cpu")))
104
105 ;; A basic instruction type.  Refinements due to arguments to be
106 ;; provided in other attributes.
107 (define_attr "type"
108   "other,multi,alu1,negnot,alu,icmp,test,imov,imovx,lea,incdec,ishift,imul,idiv,ibr,setcc,push,pop,call,callv,icmov,fmov,fop,fop1,fsgn,fmul,fdiv,fpspc,fcmov,fcmp,fxch,str,cld,sse,mmx,fistp"
109   (const_string "other"))
110
111 ;; Main data type used by the insn
112 (define_attr "mode" "unknown,none,QI,HI,SI,DI,unknownfp,SF,DF,XF,TI"
113   (const_string "unknown"))
114
115 ;; Set for i387 operations.
116 (define_attr "i387" ""
117   (if_then_else (eq_attr "type" "fmov,fop,fop1,fsgn,fmul,fdiv,fpspc,fcmov,fcmp,fxch,fistp")
118     (const_int 1)
119     (const_int 0)))
120
121 ;; The (bounding maximum) length of an instruction immediate.
122 (define_attr "length_immediate" ""
123   (cond [(eq_attr "type" "incdec,setcc,icmov,ibr,str,cld,lea,other,multi,idiv,sse,mmx")
124            (const_int 0)
125          (eq_attr "i387" "1")
126            (const_int 0)
127          (eq_attr "type" "alu1,negnot,alu,icmp,imovx,ishift,imul,push,pop")
128            (symbol_ref "ix86_attr_length_immediate_default(insn,1)")
129          (eq_attr "type" "imov,test")
130            (symbol_ref "ix86_attr_length_immediate_default(insn,0)")
131          (eq_attr "type" "call")
132            (if_then_else (match_operand 0 "constant_call_address_operand" "")
133              (const_int 4)
134              (const_int 0))
135          (eq_attr "type" "callv")
136            (if_then_else (match_operand 1 "constant_call_address_operand" "")
137              (const_int 4)
138              (const_int 0))
139          (eq_attr "type" "ibr")
140            (if_then_else (and (ge (minus (match_dup 0) (pc))
141                                   (const_int -128))
142                               (lt (minus (match_dup 0) (pc))
143                                   (const_int 124)))
144              (const_int 1)
145              (const_int 4))
146          ]
147          (symbol_ref "/* Update immediate_length and other attributes! */ abort(),1")))
148
149 ;; The (bounding maximum) length of an instruction address.
150 (define_attr "length_address" ""
151   (cond [(eq_attr "type" "str,cld,other,multi,fxch")
152            (const_int 0)
153          (and (eq_attr "type" "call")
154               (match_operand 1 "constant_call_address_operand" ""))
155              (const_int 0)
156          (and (eq_attr "type" "callv")
157               (match_operand 1 "constant_call_address_operand" ""))
158              (const_int 0)
159          ]
160          (symbol_ref "ix86_attr_length_address_default (insn)")))
161
162 ;; Set when length prefix is used.
163 (define_attr "prefix_data16" ""
164   (if_then_else (eq_attr "mode" "HI")
165     (const_int 1)
166     (const_int 0)))
167
168 ;; Set when string REP prefix is used.
169 (define_attr "prefix_rep" "" (const_int 0))
170
171 ;; Set when 0f opcode prefix is used.
172 (define_attr "prefix_0f" ""
173   (if_then_else (eq_attr "type" "imovx,setcc,icmov,sse,mmx")
174     (const_int 1)
175     (const_int 0)))
176
177 ;; Set when modrm byte is used.
178 (define_attr "modrm" ""
179   (cond [(eq_attr "type" "str,cld")
180            (const_int 0)
181          (eq_attr "i387" "1")
182            (const_int 0)
183          (and (eq_attr "type" "incdec")
184               (ior (match_operand:SI 1 "register_operand" "")
185                    (match_operand:HI 1 "register_operand" "")))
186            (const_int 0)
187          (and (eq_attr "type" "push")
188               (not (match_operand 1 "memory_operand" "")))
189            (const_int 0)
190          (and (eq_attr "type" "pop")
191               (not (match_operand 0 "memory_operand" "")))
192            (const_int 0)
193          (and (eq_attr "type" "imov")
194               (and (match_operand 0 "register_operand" "")
195                    (match_operand 1 "immediate_operand" "")))
196            (const_int 0)
197          ]
198          (const_int 1)))
199
200 ;; The (bounding maximum) length of an instruction in bytes.
201 ;; ??? fistp is in fact fldcw/fistp/fldcw sequence.  Later we may want
202 ;; to split it and compute proper length as for other insns.
203 (define_attr "length" ""
204   (cond [(eq_attr "type" "other,multi,fistp")
205            (const_int 16)
206          ]
207          (plus (plus (attr "modrm")
208                      (plus (attr "prefix_0f")
209                            (plus (attr "i387")
210                                  (const_int 1))))
211                (plus (attr "prefix_rep")
212                      (plus (attr "prefix_data16")
213                            (plus (attr "length_immediate")
214                                  (attr "length_address")))))))
215
216 ;; The `memory' attribute is `none' if no memory is referenced, `load' or
217 ;; `store' if there is a simple memory reference therein, or `unknown'
218 ;; if the instruction is complex.
219
220 (define_attr "memory" "none,load,store,both,unknown"
221   (cond [(eq_attr "type" "other,multi,str")
222            (const_string "unknown")
223          (eq_attr "type" "lea,fcmov,fpspc,cld")
224            (const_string "none")
225          (eq_attr "type" "fistp")
226            (const_string "both")
227          (eq_attr "type" "push")
228            (if_then_else (match_operand 1 "memory_operand" "")
229              (const_string "both")
230              (const_string "store"))
231          (eq_attr "type" "pop,setcc")
232            (if_then_else (match_operand 0 "memory_operand" "")
233              (const_string "both")
234              (const_string "load"))
235          (eq_attr "type" "icmp,test")
236            (if_then_else (ior (match_operand 0 "memory_operand" "")
237                               (match_operand 1 "memory_operand" ""))
238              (const_string "load")
239              (const_string "none"))
240          (eq_attr "type" "ibr")
241            (if_then_else (match_operand 0 "memory_operand" "")
242              (const_string "load")
243              (const_string "none"))
244          (eq_attr "type" "call")
245            (if_then_else (match_operand 0 "constant_call_address_operand" "")
246              (const_string "none")
247              (const_string "load"))
248          (eq_attr "type" "callv")
249            (if_then_else (match_operand 1 "constant_call_address_operand" "")
250              (const_string "none")
251              (const_string "load"))
252          (and (eq_attr "type" "alu1,negnot")
253               (match_operand 1 "memory_operand" ""))
254            (const_string "both")
255          (and (match_operand 0 "memory_operand" "")
256               (match_operand 1 "memory_operand" ""))
257            (const_string "both")
258          (match_operand 0 "memory_operand" "")
259            (const_string "store")
260          (match_operand 1 "memory_operand" "")
261            (const_string "load")
262          (and (eq_attr "type" "!icmp,test,alu1,negnot,fop1,fsgn,imov,imovx,fmov,fcmp,sse,mmx")
263               (match_operand 2 "memory_operand" ""))
264            (const_string "load")
265          (and (eq_attr "type" "icmov")
266               (match_operand 3 "memory_operand" ""))
267            (const_string "load")
268         ]
269         (const_string "none")))
270
271 ;; Indicates if an instruction has both an immediate and a displacement.
272
273 (define_attr "imm_disp" "false,true,unknown"
274   (cond [(eq_attr "type" "other,multi")
275            (const_string "unknown")
276          (and (eq_attr "type" "icmp,test,imov")
277               (and (match_operand 0 "memory_displacement_operand" "")
278                    (match_operand 1 "immediate_operand" "")))
279            (const_string "true")
280          (and (eq_attr "type" "alu,ishift,imul,idiv")
281               (and (match_operand 0 "memory_displacement_operand" "")
282                    (match_operand 2 "immediate_operand" "")))
283            (const_string "true")
284         ]
285         (const_string "false")))
286
287 ;; Indicates if an FP operation has an integer source.
288
289 (define_attr "fp_int_src" "false,true"
290   (const_string "false"))
291
292 ;; Describe a user's asm statement.
293 (define_asm_attributes
294   [(set_attr "length" "128")
295    (set_attr "type" "multi")])
296 \f
297 ;; Pentium Scheduling
298 ;;
299 ;; The Pentium is an in-order core with two integer pipelines.
300
301 ;; True for insns that behave like prefixed insns on the Pentium.
302 (define_attr "pent_prefix" "false,true"
303   (if_then_else (ior (eq_attr "prefix_0f" "1")
304                      (ior (eq_attr "prefix_data16" "1")
305                           (eq_attr "prefix_rep" "1")))
306     (const_string "true")
307     (const_string "false")))
308
309 ;; Categorize how an instruction slots.
310
311 ;; The non-MMX Pentium slots an instruction with prefixes on U pipe only,
312 ;; while MMX Pentium can slot it on either U or V.  Model non-MMX Pentium
313 ;; rules, because it results in noticeably better code on non-MMX Pentium
314 ;; and doesn't hurt much on MMX.  (Prefixed instructions are not very
315 ;; common, so the scheduler usualy has a non-prefixed insn to pair).
316
317 (define_attr "pent_pair" "uv,pu,pv,np"
318   (cond [(eq_attr "imm_disp" "true")
319            (const_string "np")
320          (ior (eq_attr "type" "alu1,alu,imov,icmp,test,lea,incdec")
321               (and (eq_attr "type" "pop,push")
322                    (eq_attr "memory" "!both")))
323            (if_then_else (eq_attr "pent_prefix" "true")
324              (const_string "pu")
325              (const_string "uv"))
326          (eq_attr "type" "ibr")
327            (const_string "pv")
328          (and (eq_attr "type" "ishift")
329               (match_operand 2 "const_int_operand" ""))
330            (const_string "pu")
331          (and (eq_attr "type" "call")
332               (match_operand 0 "constant_call_address_operand" ""))
333            (const_string "pv")
334          (and (eq_attr "type" "callv")
335               (match_operand 1 "constant_call_address_operand" ""))
336            (const_string "pv")
337         ]
338         (const_string "np")))
339
340 ;; Rough readiness numbers.  Fine tuning happens in i386.c.
341 ;;
342 ;; u    describes pipe U
343 ;; v    describes pipe V
344 ;; uv   describes either pipe U or V for those that can issue to either
345 ;; np   describes not paring
346 ;; fpu  describes fpu
347 ;; fpm  describes fp insns of different types are not pipelined.
348 ;;
349 ;; ??? fxch isn't handled; not an issue until sched3 after reg-stack is real.
350
351 (define_function_unit "pent_np" 1 0
352   (and (eq_attr "cpu" "pentium")
353        (eq_attr "type" "imul"))
354   11 11)
355
356 (define_function_unit "pent_mul" 1 1
357   (and (eq_attr "cpu" "pentium")
358        (eq_attr "type" "imul"))
359   11 11)
360
361 ;; Rep movs takes minimally 12 cycles.
362 (define_function_unit "pent_np" 1 0
363   (and (eq_attr "cpu" "pentium")
364        (eq_attr "type" "str"))
365   12 12)
366
367 ; ??? IDIV for SI takes 46 cycles, for HI 30, for QI 22
368 (define_function_unit "pent_np" 1 0
369   (and (eq_attr "cpu" "pentium")
370        (eq_attr "type" "idiv"))
371   46 46)
372
373 ; Fp reg-reg moves takes 1 cycle. Loads takes 1 cycle for SF/DF mode,
374 ; 3 cycles for XFmode.  Stores takes 2 cycles for SF/DF and 3 for XF.
375 ; fldz and fld1 takes 2 cycles.  Only reg-reg moves are pairable.
376 ; The integer <-> fp conversion is not modeled correctly. Fild behaves
377 ; like normal fp operation and fist takes 6 cycles.
378
379 (define_function_unit "fpu" 1 0
380   (and (eq_attr "cpu" "pentium")
381        (and (eq_attr "type" "fmov")
382             (and (eq_attr "memory" "load,store")
383                  (eq_attr "mode" "XF"))))
384   3 3)
385
386 (define_function_unit "pent_np" 1 0
387   (and (eq_attr "cpu" "pentium")
388        (and (eq_attr "type" "fmov")
389             (and (eq_attr "memory" "load,store")
390                  (eq_attr "mode" "XF"))))
391   3 3)
392
393 (define_function_unit "fpu" 1 0
394   (and (eq_attr "cpu" "pentium")
395        (and (eq_attr "type" "fmov")
396             (ior (match_operand 1 "immediate_operand" "")
397                  (eq_attr "memory" "store"))))
398   2 2)
399
400 (define_function_unit "pent_np" 1 0
401   (and (eq_attr "cpu" "pentium")
402        (and (eq_attr "type" "fmov")
403             (ior (match_operand 1 "immediate_operand" "")
404                  (eq_attr "memory" "store"))))
405   2 2)
406
407 (define_function_unit "pent_np" 1 0
408   (and (eq_attr "cpu" "pentium")
409        (eq_attr "type" "cld"))
410   2 2)
411
412 (define_function_unit "fpu" 1 0
413   (and (eq_attr "cpu" "pentium")
414        (and (eq_attr "type" "fmov")
415             (eq_attr "memory" "none,load")))
416   1 1)
417
418 ; Read/Modify/Write instructions usually take 3 cycles.
419 (define_function_unit "pent_u" 1 0
420   (and (eq_attr "cpu" "pentium")
421        (and (eq_attr "type" "alu,alu1,ishift")
422             (and (eq_attr "pent_pair" "pu")
423                  (eq_attr "memory" "both"))))
424   3 3)
425
426 (define_function_unit "pent_uv" 2 0
427   (and (eq_attr "cpu" "pentium")
428        (and (eq_attr "type" "alu,alu1,ishift")
429             (and (eq_attr "pent_pair" "!np")
430                  (eq_attr "memory" "both"))))
431   3 3)
432
433 (define_function_unit "pent_np" 1 0
434   (and (eq_attr "cpu" "pentium")
435        (and (eq_attr "type" "alu,alu1,negnot,ishift")
436             (and (eq_attr "pent_pair" "np")
437                  (eq_attr "memory" "both"))))
438   3 3)
439
440 ; Read/Modify or Modify/Write instructions usually take 2 cycles.
441 (define_function_unit "pent_u" 1 0
442   (and (eq_attr "cpu" "pentium")
443        (and (eq_attr "type" "alu,ishift")
444             (and (eq_attr "pent_pair" "pu")
445                  (eq_attr "memory" "load,store"))))
446   2 2)
447
448 (define_function_unit "pent_uv" 2 0
449   (and (eq_attr "cpu" "pentium")
450        (and (eq_attr "type" "alu,ishift")
451             (and (eq_attr "pent_pair" "!np")
452                  (eq_attr "memory" "load,store"))))
453   2 2)
454
455 (define_function_unit "pent_np" 1 0
456   (and (eq_attr "cpu" "pentium")
457        (and (eq_attr "type" "alu,ishift")
458             (and (eq_attr "pent_pair" "np")
459                  (eq_attr "memory" "load,store"))))
460   2 2)
461
462 ; Insns w/o memory operands and move instructions usually take one cycle.
463 (define_function_unit "pent_u" 1 0
464   (and (eq_attr "cpu" "pentium")
465        (eq_attr "pent_pair" "pu"))
466   1 1)
467
468 (define_function_unit "pent_v" 1 0
469   (and (eq_attr "cpu" "pentium")
470        (eq_attr "pent_pair" "pv"))
471   1 1)
472
473 (define_function_unit "pent_uv" 2 0
474   (and (eq_attr "cpu" "pentium")
475        (eq_attr "pent_pair" "!np"))
476   1 1)
477
478 (define_function_unit "pent_np" 1 0
479   (and (eq_attr "cpu" "pentium")
480        (eq_attr "pent_pair" "np"))
481   1 1)
482
483 ; Pairable insns only conflict with other non-pairable insns.
484 (define_function_unit "pent_np" 1 0
485   (and (eq_attr "cpu" "pentium")
486        (and (eq_attr "type" "alu,alu1,ishift")
487             (and (eq_attr "pent_pair" "!np")
488                  (eq_attr "memory" "both"))))
489   3 3
490   [(eq_attr "pent_pair" "np")])
491
492 (define_function_unit "pent_np" 1 0
493   (and (eq_attr "cpu" "pentium")
494        (and (eq_attr "type" "alu,alu1,ishift")
495             (and (eq_attr "pent_pair" "!np")
496                  (eq_attr "memory" "load,store"))))
497   2 2
498   [(eq_attr "pent_pair" "np")])
499
500 (define_function_unit "pent_np" 1 0
501   (and (eq_attr "cpu" "pentium")
502        (eq_attr "pent_pair" "!np"))
503   1 1
504   [(eq_attr "pent_pair" "np")])
505
506 ; Floating point instructions usually blocks cycle longer when combined with
507 ; integer instructions, because of the inpaired fxch instruction.
508 (define_function_unit "pent_np" 1 0
509   (and (eq_attr "cpu" "pentium")
510        (eq_attr "type" "fmov,fop,fop1,fsgn,fmul,fpspc,fcmov,fcmp,fistp"))
511   2 2
512   [(eq_attr "type" "!fmov,fop,fop1,fsgn,fmul,fpspc,fcmov,fcmp,fistp")])
513
514 (define_function_unit "fpu" 1 0
515   (and (eq_attr "cpu" "pentium")
516        (eq_attr "type" "fcmp,fxch,fsgn"))
517   1 1)
518
519 ; Addition takes 3 cycles; assume other random cruft does as well.
520 ; ??? Trivial fp operations such as fabs or fchs takes only one cycle.
521 (define_function_unit "fpu" 1 0
522   (and (eq_attr "cpu" "pentium")
523        (eq_attr "type" "fop,fop1,fistp"))
524   3 1)
525
526 ; Multiplication takes 3 cycles and is only half pipelined.
527 (define_function_unit "fpu" 1 0
528   (and (eq_attr "cpu" "pentium")
529        (eq_attr "type" "fmul"))
530   3 1)
531
532 (define_function_unit "pent_mul" 1 1
533   (and (eq_attr "cpu" "pentium")
534        (eq_attr "type" "fmul"))
535   2 2)
536
537 ; ??? This is correct only for fdiv and sqrt -- sin/cos take 65-100 cycles. 
538 ; They can overlap with integer insns.  Only the last two cycles can overlap
539 ; with other fp insns.  Only fsin/fcos can overlap with multiplies.
540 ; Only last two cycles of fsin/fcos can overlap with other instructions.
541 (define_function_unit "fpu" 1 0
542   (and (eq_attr "cpu" "pentium")
543        (eq_attr "type" "fdiv"))
544   39 37)
545
546 (define_function_unit "pent_mul" 1 1
547   (and (eq_attr "cpu" "pentium")
548        (eq_attr "type" "fdiv"))
549   39 39)
550
551 (define_function_unit "fpu" 1 0
552   (and (eq_attr "cpu" "pentium")
553        (eq_attr "type" "fpspc"))
554   70 68)
555
556 (define_function_unit "pent_mul" 1 1
557   (and (eq_attr "cpu" "pentium")
558        (eq_attr "type" "fpspc"))
559   70 70)
560 \f
561 ;; Pentium Pro/PII Scheduling
562 ;;
563 ;; The PPro has an out-of-order core, but the instruction decoders are
564 ;; naturally in-order and asymmetric.  We get best performance by scheduling
565 ;; for the decoders, for in doing so we give the oo execution unit the 
566 ;; most choices.
567
568 ;; Categorize how many uops an ia32 instruction evaluates to:
569 ;;   one --  an instruction with 1 uop can be decoded by any of the
570 ;;           three decoders.
571 ;;   few --  an instruction with 1 to 4 uops can be decoded only by 
572 ;;           decoder 0.
573 ;;   many -- a complex instruction may take an unspecified number of
574 ;;           cycles to decode in decoder 0.
575
576 (define_attr "ppro_uops" "one,few,many"
577   (cond [(eq_attr "type" "other,multi,call,callv,fpspc,str")
578            (const_string "many")
579          (eq_attr "type" "icmov,fcmov,str,cld")
580            (const_string "few")
581          (eq_attr "type" "imov")
582            (if_then_else (eq_attr "memory" "store,both")
583              (const_string "few")
584              (const_string "one"))
585          (eq_attr "memory" "!none")
586            (const_string "few")
587         ]
588         (const_string "one")))
589
590 ;; Rough readiness numbers.  Fine tuning happens in i386.c.
591 ;;
592 ;; p0   describes port 0.
593 ;; p01  describes ports 0 and 1 as a pair; alu insns can issue to either.
594 ;; p2   describes port 2 for loads.
595 ;; p34  describes ports 3 and 4 for stores.
596 ;; fpu  describes the fpu accessed via port 0. 
597 ;;      ??? It is less than clear if there are separate fadd and fmul units
598 ;;      that could operate in parallel.
599 ;;
600 ;; ??? fxch isn't handled; not an issue until sched3 after reg-stack is real.
601
602 (define_function_unit "ppro_p0" 1 0
603   (and (eq_attr "cpu" "pentiumpro")
604        (eq_attr "type" "ishift,lea,ibr,cld"))
605   1 1)
606
607 (define_function_unit "ppro_p0" 1 0
608   (and (eq_attr "cpu" "pentiumpro")
609        (eq_attr "type" "imul"))
610   4 1)
611
612 ;; ??? Does the divider lock out the pipe while it works,
613 ;; or is there a disconnected unit?
614 (define_function_unit "ppro_p0" 1 0
615   (and (eq_attr "cpu" "pentiumpro")
616        (eq_attr "type" "idiv"))
617   17 17)
618
619 (define_function_unit "ppro_p0" 1 0
620   (and (eq_attr "cpu" "pentiumpro")
621        (eq_attr "type" "fop,fop1,fsgn,fistp"))
622   3 1)
623
624 (define_function_unit "ppro_p0" 1 0
625   (and (eq_attr "cpu" "pentiumpro")
626        (eq_attr "type" "fcmov"))
627   2 1)
628
629 (define_function_unit "ppro_p0" 1 0
630   (and (eq_attr "cpu" "pentiumpro")
631        (eq_attr "type" "fcmp"))
632   1 1)
633
634 (define_function_unit "ppro_p0" 1 0
635   (and (eq_attr "cpu" "pentiumpro")
636        (eq_attr "type" "fmov"))
637   1 1)
638
639 (define_function_unit "ppro_p0" 1 0
640   (and (eq_attr "cpu" "pentiumpro")
641        (eq_attr "type" "fmul"))
642   5 1)
643
644 (define_function_unit "ppro_p0" 1 0
645   (and (eq_attr "cpu" "pentiumpro")
646        (eq_attr "type" "fdiv,fpspc"))
647   56 1)
648
649 (define_function_unit "ppro_p01" 2 0
650   (and (eq_attr "cpu" "pentiumpro")
651        (eq_attr "type" "!imov,fmov"))
652   1 1)
653
654 (define_function_unit "ppro_p01" 2 0
655   (and (and (eq_attr "cpu" "pentiumpro")
656             (eq_attr "type" "imov,fmov"))
657        (eq_attr "memory" "none"))
658   1 1)
659
660 (define_function_unit "ppro_p2" 1 0
661   (and (eq_attr "cpu" "pentiumpro")
662        (ior (eq_attr "type" "pop")
663             (eq_attr "memory" "load,both")))
664   3 1)
665
666 (define_function_unit "ppro_p34" 1 0
667   (and (eq_attr "cpu" "pentiumpro")
668        (ior (eq_attr "type" "push")
669             (eq_attr "memory" "store,both")))
670   1 1)
671
672 (define_function_unit "fpu" 1 0
673   (and (eq_attr "cpu" "pentiumpro")
674        (eq_attr "type" "fop,fop1,fsgn,fmov,fcmp,fcmov,fistp"))
675   1 1)
676
677 (define_function_unit "fpu" 1 0
678   (and (eq_attr "cpu" "pentiumpro")
679        (eq_attr "type" "fmul"))
680   5 2)
681
682 (define_function_unit "fpu" 1 0
683   (and (eq_attr "cpu" "pentiumpro")
684        (eq_attr "type" "fdiv,fpspc"))
685   56 56)
686
687 ;; imul uses the fpu.  ??? does it have the same throughput as fmul?
688 (define_function_unit "fpu" 1 0
689   (and (eq_attr "cpu" "pentiumpro")
690        (eq_attr "type" "imul"))
691   4 1)
692 \f
693 ;; AMD K6/K6-2 Scheduling
694 ;;
695 ;; The K6 has similar architecture to PPro.  Important difference is, that
696 ;; there are only two decoders and they seems to be much slower than execution
697 ;; units.  So we have to pay much more attention to proper decoding for
698 ;; schedulers.  We share most of scheduler code for PPro in i386.c
699 ;;
700 ;; The fp unit is not pipelined and do one operation per two cycles including
701 ;; the FXCH.
702 ;;
703 ;; alu    describes both ALU units (ALU-X and ALU-Y).
704 ;; alux   describes X alu unit
705 ;; fpu    describes FPU unit
706 ;; load   describes load unit.
707 ;; branch describes branch unit.
708 ;; store  decsribes store unit.  This unit is not modelled completely and only
709 ;;        used to model lea operation.  Otherwise it lie outside of the critical
710 ;;        path.
711 ;;
712 ;; ??? fxch isn't handled; not an issue until sched3 after reg-stack is real.
713
714 ;; The decoder specification is in the PPro section above!
715
716 ;; Shift instructions and certain arithmetic are issued only to X pipe.
717 (define_function_unit "k6_alux" 1 0
718   (and (eq_attr "cpu" "k6")
719        (eq_attr "type" "ishift,alu1,negnot,cld"))
720   1 1)
721
722 ;; The QI mode arithmetic is issued to X pipe only.
723 (define_function_unit "k6_alux" 1 0
724   (and (eq_attr "cpu" "k6")
725        (and (eq_attr "type" "alu,alu1,negnot,icmp,test,imovx,incdec")
726             (match_operand:QI 0 "general_operand" "")))
727   1 1)
728
729 (define_function_unit "k6_alu" 2 0
730   (and (eq_attr "cpu" "k6")
731        (eq_attr "type" "ishift,alu1,negnot,alu,icmp,test,imovx,incdec,setcc,lea"))
732   1 1)
733
734 (define_function_unit "k6_alu" 2 0
735   (and (eq_attr "cpu" "k6")
736        (and (eq_attr "type" "imov")
737             (eq_attr "memory" "none")))
738   1 1)
739
740 (define_function_unit "k6_branch" 1 0
741   (and (eq_attr "cpu" "k6")
742        (eq_attr "type" "call,callv,ibr"))
743   1 1)
744
745 ;; Load unit have two cycle latency, but we take care for it in adjust_cost
746 (define_function_unit "k6_load" 1 0
747   (and (eq_attr "cpu" "k6")
748        (ior (eq_attr "type" "pop")
749             (eq_attr "memory" "load,both")))
750   1 1)
751
752 (define_function_unit "k6_load" 1 0
753   (and (eq_attr "cpu" "k6")
754        (and (eq_attr "type" "str")
755             (eq_attr "memory" "load,both")))
756   10 10)
757
758 ;; Lea have two instructions, so latency is probably 2
759 (define_function_unit "k6_store" 1 0
760   (and (eq_attr "cpu" "k6")
761        (eq_attr "type" "lea"))
762   2 1)
763
764 (define_function_unit "k6_store" 1 0
765   (and (eq_attr "cpu" "k6")
766        (eq_attr "type" "str"))
767   10 10)
768
769 (define_function_unit "k6_store" 1 0
770   (and (eq_attr "cpu" "k6")
771        (ior (eq_attr "type" "push")
772             (eq_attr "memory" "store,both")))
773   1 1)
774
775 (define_function_unit "k6_fpu" 1 1
776   (and (eq_attr "cpu" "k6")
777        (eq_attr "type" "fop,fop1,fmov,fcmp,fistp"))
778   2 2)
779
780 (define_function_unit "k6_fpu" 1 1
781   (and (eq_attr "cpu" "k6")
782        (eq_attr "type" "fmul"))
783   2 2)
784
785 ;; ??? Guess
786 (define_function_unit "k6_fpu" 1 1
787   (and (eq_attr "cpu" "k6")
788        (eq_attr "type" "fdiv,fpspc"))
789   56 56)
790
791 (define_function_unit "k6_alu" 2 0
792   (and (eq_attr "cpu" "k6")
793        (eq_attr "type" "imul"))
794   2 2)
795
796 (define_function_unit "k6_alux" 1 0
797   (and (eq_attr "cpu" "k6")
798        (eq_attr "type" "imul"))
799   2 2)
800
801 ;; ??? Guess
802 (define_function_unit "k6_alu" 2 0
803   (and (eq_attr "cpu" "k6")
804        (eq_attr "type" "idiv"))
805   17 17)
806
807 (define_function_unit "k6_alux" 1 0
808   (and (eq_attr "cpu" "k6")
809        (eq_attr "type" "idiv"))
810   17 17)
811 \f
812 ;; AMD Athlon Scheduling
813 ;;
814 ;; The Athlon does contain three pipelined FP units, three integer units and
815 ;; three address generation units. 
816 ;;
817 ;; The predecode logic is determining boundaries of instructions in the 64
818 ;; byte cache line. So the cache line straddling problem of K6 might be issue
819 ;; here as well, but it is not noted in the documentation.
820 ;;
821 ;; Three DirectPath instructions decoders and only one VectorPath decoder
822 ;; is available. They can decode three DirectPath instructions or one VectorPath
823 ;; instruction per cycle.
824 ;; Decoded macro instructions are then passed to 72 entry instruction control
825 ;; unit, that passes
826 ;; it to the specialized integer (18 entry) and fp (36 entry) schedulers.
827 ;;
828 ;; The load/store queue unit is not attached to the schedulers but
829 ;; communicates with all the execution units seperately instead.
830
831 (define_attr "athlon_decode" "direct,vector"
832   (cond [(eq_attr "type" "call,imul,idiv,other,multi,fcmov,fpspc,str,pop,cld,fcmov")
833            (const_string "vector")
834          (and (eq_attr "type" "push")
835               (match_operand 1 "memory_operand" ""))
836            (const_string "vector")
837          (and (eq_attr "type" "fmov")
838               (and (eq_attr "memory" "load,store")
839                    (eq_attr "mode" "XF")))
840            (const_string "vector")]
841         (const_string "direct")))
842
843 (define_function_unit "athlon_vectordec" 1 0
844   (and (eq_attr "cpu" "athlon")
845        (eq_attr "athlon_decode" "vector"))
846   1 1)
847
848 (define_function_unit "athlon_directdec" 3 0
849   (and (eq_attr "cpu" "athlon")
850        (eq_attr "athlon_decode" "direct"))
851   1 1)
852
853 (define_function_unit "athlon_vectordec" 1 0
854   (and (eq_attr "cpu" "athlon")
855        (eq_attr "athlon_decode" "direct"))
856   1 1 [(eq_attr "athlon_decode" "vector")])
857
858 (define_function_unit "athlon_ieu" 3 0
859   (and (eq_attr "cpu" "athlon")
860        (eq_attr "type" "alu1,negnot,alu,icmp,test,imov,imovx,lea,incdec,ishift,ibr,call,callv,icmov,cld,pop,setcc,push,pop"))
861   1 1)
862
863 (define_function_unit "athlon_ieu" 3 0
864   (and (eq_attr "cpu" "athlon")
865        (eq_attr "type" "str"))
866   15 15)
867
868 (define_function_unit "athlon_ieu" 3 0
869   (and (eq_attr "cpu" "athlon")
870        (eq_attr "type" "imul"))
871   5 0)
872
873 (define_function_unit "athlon_ieu" 3 0
874   (and (eq_attr "cpu" "athlon")
875        (eq_attr "type" "idiv"))
876   42 0)
877
878 (define_function_unit "athlon_muldiv" 1 0
879   (and (eq_attr "cpu" "athlon")
880        (eq_attr "type" "imul"))
881   5 0)
882
883 (define_function_unit "athlon_muldiv" 1 0
884   (and (eq_attr "cpu" "athlon")
885        (eq_attr "type" "idiv"))
886   42 42)
887
888 (define_attr "athlon_fpunits" "none,store,mul,add,muladd,any"
889   (cond [(eq_attr "type" "fop,fop1,fcmp,fistp")
890            (const_string "add")
891          (eq_attr "type" "fmul,fdiv,fpspc,fsgn,fcmov")
892            (const_string "mul")
893          (and (eq_attr "type" "fmov") (eq_attr "memory" "store,both"))
894            (const_string "store")
895          (and (eq_attr "type" "fmov") (eq_attr "memory" "load"))
896            (const_string "any")
897          (and (eq_attr "type" "fmov")
898               (ior (match_operand:SI 1 "register_operand" "")
899                    (match_operand 1 "immediate_operand" "")))
900            (const_string "store")
901          (eq_attr "type" "fmov")
902            (const_string "muladd")]
903         (const_string "none")))
904
905 ;; We use latencies 1 for definitions.  This is OK to model colisions
906 ;; in execution units.  The real latencies are modeled in the "fp" pipeline.
907
908 ;; fsin, fcos: 96-192
909 ;; fsincos: 107-211
910 ;; fsqrt: 19 for SFmode, 27 for DFmode, 35 for XFmode.
911 (define_function_unit "athlon_fp" 3 0
912   (and (eq_attr "cpu" "athlon")
913        (eq_attr "type" "fpspc"))
914   100 1)
915
916 ;; 16 cycles for SFmode, 20 for DFmode and 24 for XFmode.
917 (define_function_unit "athlon_fp" 3 0
918   (and (eq_attr "cpu" "athlon")
919        (eq_attr "type" "fdiv"))
920   24 1)
921
922 (define_function_unit "athlon_fp" 3 0
923   (and (eq_attr "cpu" "athlon")
924        (eq_attr "type" "fop,fop1,fmul,fistp"))
925   4 1)
926
927 ;; XFmode loads are slow.
928 ;; XFmode store is slow too (8 cycles), but we don't need to model it, because
929 ;; there are no dependent instructions.
930
931 (define_function_unit "athlon_fp" 3 0
932   (and (eq_attr "cpu" "athlon")
933        (and (eq_attr "type" "fmov")
934             (and (eq_attr "memory" "load")
935                  (eq_attr "mode" "XF"))))
936   10 1)
937
938 (define_function_unit "athlon_fp" 3 0
939   (and (eq_attr "cpu" "athlon")
940        (eq_attr "type" "fmov,fsgn"))
941   2 1)
942
943 ;; fcmp and ftst instructions
944 (define_function_unit "athlon_fp" 3 0
945   (and (eq_attr "cpu" "athlon")
946        (and (eq_attr "type" "fcmp")
947             (eq_attr "athlon_decode" "direct")))
948   3 1)
949
950 ;; fcmpi instructions.
951 (define_function_unit "athlon_fp" 3 0
952   (and (eq_attr "cpu" "athlon")
953        (and (eq_attr "type" "fcmp")
954             (eq_attr "athlon_decode" "vector")))
955   3 1)
956
957 (define_function_unit "athlon_fp" 3 0
958   (and (eq_attr "cpu" "athlon")
959        (eq_attr "type" "fcmov"))
960   7 1)
961
962 (define_function_unit "athlon_fp_mul" 1 0
963   (and (eq_attr "cpu" "athlon")
964        (eq_attr "athlon_fpunits" "mul"))
965   1 1)
966
967 (define_function_unit "athlon_fp_add" 1 0
968   (and (eq_attr "cpu" "athlon")
969        (eq_attr "athlon_fpunits" "add"))
970   1 1)
971
972 (define_function_unit "athlon_fp_muladd" 2 0
973   (and (eq_attr "cpu" "athlon")
974        (eq_attr "athlon_fpunits" "muladd,mul,add"))
975   1 1)
976
977 (define_function_unit "athlon_fp_store" 1 0
978   (and (eq_attr "cpu" "athlon")
979        (eq_attr "athlon_fpunits" "store"))
980   1 1)
981
982 ;; We don't need to model the Adress Generation Unit, since we don't model
983 ;; the re-order buffer yet and thus we never schedule more than three operations
984 ;; at time.  Later we may want to experiment with MD_SCHED macros modeling the
985 ;; decoders independently on the functional units.
986
987 ;(define_function_unit "athlon_agu" 3 0
988 ;  (and (eq_attr "cpu" "athlon")
989 ;       (and (eq_attr "memory" "!none")
990 ;            (eq_attr "athlon_fpunits" "none")))
991 ;  1 1)
992
993 ;; Model load unit to avoid too long sequences of loads.  We don't need to
994 ;; model store queue, since it is hardly going to be bottleneck.
995
996 (define_function_unit "athlon_load" 2 0
997   (and (eq_attr "cpu" "athlon")
998        (eq_attr "memory" "load,both"))
999   1 1)
1000
1001 \f
1002 ;; Compare instructions.
1003
1004 ;; All compare insns have expanders that save the operands away without
1005 ;; actually generating RTL.  The bCOND or sCOND (emitted immediately
1006 ;; after the cmp) will actually emit the cmpM.
1007
1008 (define_expand "cmpdi"
1009   [(set (reg:CC 17)
1010         (compare:CC (match_operand:DI 0 "nonimmediate_operand" "")
1011                     (match_operand:DI 1 "x86_64_general_operand" "")))]
1012   ""
1013 {
1014   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
1015     operands[0] = force_reg (DImode, operands[0]);
1016   ix86_compare_op0 = operands[0];
1017   ix86_compare_op1 = operands[1];
1018   DONE;
1019 })
1020
1021 (define_expand "cmpsi"
1022   [(set (reg:CC 17)
1023         (compare:CC (match_operand:SI 0 "cmpsi_operand" "")
1024                     (match_operand:SI 1 "general_operand" "")))]
1025   ""
1026 {
1027   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
1028     operands[0] = force_reg (SImode, operands[0]);
1029   ix86_compare_op0 = operands[0];
1030   ix86_compare_op1 = operands[1];
1031   DONE;
1032 })
1033
1034 (define_expand "cmphi"
1035   [(set (reg:CC 17)
1036         (compare:CC (match_operand:HI 0 "nonimmediate_operand" "")
1037                     (match_operand:HI 1 "general_operand" "")))]
1038   ""
1039 {
1040   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
1041     operands[0] = force_reg (HImode, operands[0]);
1042   ix86_compare_op0 = operands[0];
1043   ix86_compare_op1 = operands[1];
1044   DONE;
1045 })
1046
1047 (define_expand "cmpqi"
1048   [(set (reg:CC 17)
1049         (compare:CC (match_operand:QI 0 "nonimmediate_operand" "")
1050                     (match_operand:QI 1 "general_operand" "")))]
1051   "TARGET_QIMODE_MATH"
1052 {
1053   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
1054     operands[0] = force_reg (QImode, operands[0]);
1055   ix86_compare_op0 = operands[0];
1056   ix86_compare_op1 = operands[1];
1057   DONE;
1058 })
1059
1060 (define_insn "cmpdi_ccno_1_rex64"
1061   [(set (reg 17)
1062         (compare (match_operand:DI 0 "nonimmediate_operand" "r,?mr")
1063                  (match_operand:DI 1 "const0_operand" "n,n")))]
1064   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
1065   "@
1066    test{q}\t{%0, %0|%0, %0}
1067    cmp{q}\t{%1, %0|%0, %1}"
1068   [(set_attr "type" "test,icmp")
1069    (set_attr "length_immediate" "0,1")
1070    (set_attr "mode" "DI")])
1071
1072 (define_insn "*cmpdi_minus_1_rex64"
1073   [(set (reg 17)
1074         (compare (minus:DI (match_operand:DI 0 "nonimmediate_operand" "rm,r")
1075                            (match_operand:DI 1 "x86_64_general_operand" "re,mr"))
1076                  (const_int 0)))]
1077   "ix86_match_ccmode (insn, CCGOCmode)"
1078   "cmp{q}\t{%1, %0|%0, %1}"
1079   [(set_attr "type" "icmp")
1080    (set_attr "mode" "DI")])
1081
1082 (define_expand "cmpdi_1_rex64"
1083   [(set (reg:CC 17)
1084         (compare:CC (match_operand:DI 0 "nonimmediate_operand" "")
1085                     (match_operand:DI 1 "general_operand" "")))]
1086   ""
1087   "")
1088
1089 (define_insn "cmpdi_1_insn_rex64"
1090   [(set (reg 17)
1091         (compare (match_operand:DI 0 "nonimmediate_operand" "mr,r")
1092                  (match_operand:DI 1 "x86_64_general_operand" "re,mr")))]
1093   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1094   "cmp{q}\t{%1, %0|%0, %1}"
1095   [(set_attr "type" "icmp")
1096    (set_attr "mode" "DI")])
1097
1098
1099 (define_insn "*cmpsi_ccno_1"
1100   [(set (reg 17)
1101         (compare (match_operand:SI 0 "nonimmediate_operand" "r,?mr")
1102                  (match_operand:SI 1 "const0_operand" "n,n")))]
1103   "ix86_match_ccmode (insn, CCNOmode)"
1104   "@
1105    test{l}\t{%0, %0|%0, %0}
1106    cmp{l}\t{%1, %0|%0, %1}"
1107   [(set_attr "type" "test,icmp")
1108    (set_attr "length_immediate" "0,1")
1109    (set_attr "mode" "SI")])
1110
1111 (define_insn "*cmpsi_minus_1"
1112   [(set (reg 17)
1113         (compare (minus:SI (match_operand:SI 0 "nonimmediate_operand" "rm,r")
1114                            (match_operand:SI 1 "general_operand" "ri,mr"))
1115                  (const_int 0)))]
1116   "ix86_match_ccmode (insn, CCGOCmode)"
1117   "cmp{l}\t{%1, %0|%0, %1}"
1118   [(set_attr "type" "icmp")
1119    (set_attr "mode" "SI")])
1120
1121 (define_expand "cmpsi_1"
1122   [(set (reg:CC 17)
1123         (compare:CC (match_operand:SI 0 "nonimmediate_operand" "rm,r")
1124                     (match_operand:SI 1 "general_operand" "ri,mr")))]
1125   ""
1126   "")
1127
1128 (define_insn "*cmpsi_1_insn"
1129   [(set (reg 17)
1130         (compare (match_operand:SI 0 "nonimmediate_operand" "rm,r")
1131                  (match_operand:SI 1 "general_operand" "ri,mr")))]
1132   "(GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
1133     && ix86_match_ccmode (insn, CCmode)"
1134   "cmp{l}\t{%1, %0|%0, %1}"
1135   [(set_attr "type" "icmp")
1136    (set_attr "mode" "SI")])
1137
1138 (define_insn "*cmphi_ccno_1"
1139   [(set (reg 17)
1140         (compare (match_operand:HI 0 "nonimmediate_operand" "r,?mr")
1141                  (match_operand:HI 1 "const0_operand" "n,n")))]
1142   "ix86_match_ccmode (insn, CCNOmode)"
1143   "@
1144    test{w}\t{%0, %0|%0, %0}
1145    cmp{w}\t{%1, %0|%0, %1}"
1146   [(set_attr "type" "test,icmp")
1147    (set_attr "length_immediate" "0,1")
1148    (set_attr "mode" "HI")])
1149
1150 (define_insn "*cmphi_minus_1"
1151   [(set (reg 17)
1152         (compare (minus:HI (match_operand:HI 0 "nonimmediate_operand" "rm,r")
1153                            (match_operand:HI 1 "general_operand" "ri,mr"))
1154                  (const_int 0)))]
1155   "ix86_match_ccmode (insn, CCGOCmode)"
1156   "cmp{w}\t{%1, %0|%0, %1}"
1157   [(set_attr "type" "icmp")
1158    (set_attr "mode" "HI")])
1159
1160 (define_insn "*cmphi_1"
1161   [(set (reg 17)
1162         (compare (match_operand:HI 0 "nonimmediate_operand" "rm,r")
1163                  (match_operand:HI 1 "general_operand" "ri,mr")))]
1164   "(GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
1165    && ix86_match_ccmode (insn, CCmode)"
1166   "cmp{w}\t{%1, %0|%0, %1}"
1167   [(set_attr "type" "icmp")
1168    (set_attr "mode" "HI")])
1169
1170 (define_insn "*cmpqi_ccno_1"
1171   [(set (reg 17)
1172         (compare (match_operand:QI 0 "nonimmediate_operand" "q,?mq")
1173                  (match_operand:QI 1 "const0_operand" "n,n")))]
1174   "ix86_match_ccmode (insn, CCNOmode)"
1175   "@
1176    test{b}\t{%0, %0|%0, %0}
1177    cmp{b}\t{$0, %0|%0, 0}"
1178   [(set_attr "type" "test,icmp")
1179    (set_attr "length_immediate" "0,1")
1180    (set_attr "mode" "QI")])
1181
1182 (define_insn "*cmpqi_1"
1183   [(set (reg 17)
1184         (compare (match_operand:QI 0 "nonimmediate_operand" "qm,q")
1185                  (match_operand:QI 1 "general_operand" "qi,mq")))]
1186   "(GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
1187     && ix86_match_ccmode (insn, CCmode)"
1188   "cmp{b}\t{%1, %0|%0, %1}"
1189   [(set_attr "type" "icmp")
1190    (set_attr "mode" "QI")])
1191
1192 (define_insn "*cmpqi_minus_1"
1193   [(set (reg 17)
1194         (compare (minus:QI (match_operand:QI 0 "nonimmediate_operand" "qm,q")
1195                            (match_operand:QI 1 "general_operand" "qi,mq"))
1196                  (const_int 0)))]
1197   "ix86_match_ccmode (insn, CCGOCmode)"
1198   "cmp{b}\t{%1, %0|%0, %1}"
1199   [(set_attr "type" "icmp")
1200    (set_attr "mode" "QI")])
1201
1202 (define_insn "*cmpqi_ext_1"
1203   [(set (reg 17)
1204         (compare
1205           (match_operand:QI 0 "general_operand" "Qm")
1206           (subreg:QI
1207             (zero_extract:SI
1208               (match_operand 1 "ext_register_operand" "Q")
1209               (const_int 8)
1210               (const_int 8)) 0)))]
1211   "!TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1212   "cmp{b}\t{%h1, %0|%0, %h1}"
1213   [(set_attr "type" "icmp")
1214    (set_attr "mode" "QI")])
1215
1216 (define_insn "*cmpqi_ext_1_rex64"
1217   [(set (reg 17)
1218         (compare
1219           (match_operand:QI 0 "register_operand" "Q")
1220           (subreg:QI
1221             (zero_extract:SI
1222               (match_operand 1 "ext_register_operand" "Q")
1223               (const_int 8)
1224               (const_int 8)) 0)))]
1225   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1226   "cmp{b}\t{%h1, %0|%0, %h1}"
1227   [(set_attr "type" "icmp")
1228    (set_attr "mode" "QI")])
1229
1230 (define_insn "*cmpqi_ext_2"
1231   [(set (reg 17)
1232         (compare
1233           (subreg:QI
1234             (zero_extract:SI
1235               (match_operand 0 "ext_register_operand" "Q")
1236               (const_int 8)
1237               (const_int 8)) 0)
1238           (match_operand:QI 1 "const0_operand" "n")))]
1239   "ix86_match_ccmode (insn, CCNOmode)"
1240   "test{b}\t%h0, %h0"
1241   [(set_attr "type" "test")
1242    (set_attr "length_immediate" "0")
1243    (set_attr "mode" "QI")])
1244
1245 (define_expand "cmpqi_ext_3"
1246   [(set (reg:CC 17)
1247         (compare:CC
1248           (subreg:QI
1249             (zero_extract:SI
1250               (match_operand 0 "ext_register_operand" "")
1251               (const_int 8)
1252               (const_int 8)) 0)
1253           (match_operand:QI 1 "general_operand" "")))]
1254   ""
1255   "")
1256
1257 (define_insn "cmpqi_ext_3_insn"
1258   [(set (reg 17)
1259         (compare
1260           (subreg:QI
1261             (zero_extract:SI
1262               (match_operand 0 "ext_register_operand" "Q")
1263               (const_int 8)
1264               (const_int 8)) 0)
1265           (match_operand:QI 1 "general_operand" "Qmn")))]
1266   "!TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1267   "cmp{b}\t{%1, %h0|%h0, %1}"
1268   [(set_attr "type" "icmp")
1269    (set_attr "mode" "QI")])
1270
1271 (define_insn "cmpqi_ext_3_insn_rex64"
1272   [(set (reg 17)
1273         (compare
1274           (subreg:QI
1275             (zero_extract:SI
1276               (match_operand 0 "ext_register_operand" "Q")
1277               (const_int 8)
1278               (const_int 8)) 0)
1279           (match_operand:QI 1 "nonmemory_operand" "Qn")))]
1280   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1281   "cmp{b}\t{%1, %h0|%h0, %1}"
1282   [(set_attr "type" "icmp")
1283    (set_attr "mode" "QI")])
1284
1285 (define_insn "*cmpqi_ext_4"
1286   [(set (reg 17)
1287         (compare
1288           (subreg:QI
1289             (zero_extract:SI
1290               (match_operand 0 "ext_register_operand" "Q")
1291               (const_int 8)
1292               (const_int 8)) 0)
1293           (subreg:QI
1294             (zero_extract:SI
1295               (match_operand 1 "ext_register_operand" "Q")
1296               (const_int 8)
1297               (const_int 8)) 0)))]
1298   "ix86_match_ccmode (insn, CCmode)"
1299   "cmp{b}\t{%h1, %h0|%h0, %h1}"
1300   [(set_attr "type" "icmp")
1301    (set_attr "mode" "QI")])
1302
1303 ;; These implement float point compares.
1304 ;; %%% See if we can get away with VOIDmode operands on the actual insns,
1305 ;; which would allow mix and match FP modes on the compares.  Which is what
1306 ;; the old patterns did, but with many more of them.
1307
1308 (define_expand "cmpxf"
1309   [(set (reg:CC 17)
1310         (compare:CC (match_operand:XF 0 "cmp_fp_expander_operand" "")
1311                     (match_operand:XF 1 "cmp_fp_expander_operand" "")))]
1312   "TARGET_80387 && !TARGET_64BIT"
1313 {
1314   ix86_compare_op0 = operands[0];
1315   ix86_compare_op1 = operands[1];
1316   DONE;
1317 })
1318
1319 (define_expand "cmptf"
1320   [(set (reg:CC 17)
1321         (compare:CC (match_operand:TF 0 "cmp_fp_expander_operand" "")
1322                     (match_operand:TF 1 "cmp_fp_expander_operand" "")))]
1323   "TARGET_80387"
1324 {
1325   ix86_compare_op0 = operands[0];
1326   ix86_compare_op1 = operands[1];
1327   DONE;
1328 })
1329
1330 (define_expand "cmpdf"
1331   [(set (reg:CC 17)
1332         (compare:CC (match_operand:DF 0 "cmp_fp_expander_operand" "")
1333                     (match_operand:DF 1 "cmp_fp_expander_operand" "")))]
1334   "TARGET_80387 || TARGET_SSE2"
1335 {
1336   ix86_compare_op0 = operands[0];
1337   ix86_compare_op1 = operands[1];
1338   DONE;
1339 })
1340
1341 (define_expand "cmpsf"
1342   [(set (reg:CC 17)
1343         (compare:CC (match_operand:SF 0 "cmp_fp_expander_operand" "")
1344                     (match_operand:SF 1 "cmp_fp_expander_operand" "")))]
1345   "TARGET_80387 || TARGET_SSE"
1346 {
1347   ix86_compare_op0 = operands[0];
1348   ix86_compare_op1 = operands[1];
1349   DONE;
1350 })
1351
1352 ;; FP compares, step 1:
1353 ;; Set the FP condition codes.
1354 ;;
1355 ;; CCFPmode     compare with exceptions
1356 ;; CCFPUmode    compare with no exceptions
1357
1358 ;; %%% It is an unfortunate fact that ftst has no non-popping variant,
1359 ;; and that fp moves clobber the condition codes, and that there is
1360 ;; currently no way to describe this fact to reg-stack.  So there are
1361 ;; no splitters yet for this.
1362
1363 ;; %%% YIKES!  This scheme does not retain a strong connection between 
1364 ;; the real compare and the ultimate cc0 user, so CC_REVERSE does not
1365 ;; work!  Only allow tos/mem with tos in op 0.
1366 ;;
1367 ;; Hmm, of course, this is what the actual _hardware_ does.  Perhaps
1368 ;; things aren't as bad as they sound...
1369
1370 (define_insn "*cmpfp_0"
1371   [(set (match_operand:HI 0 "register_operand" "=a")
1372         (unspec:HI
1373           [(compare:CCFP (match_operand 1 "register_operand" "f")
1374                          (match_operand 2 "const0_operand" "X"))] 9))]
1375   "TARGET_80387
1376    && FLOAT_MODE_P (GET_MODE (operands[1]))
1377    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
1378 {
1379   if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
1380     return "ftst\;fnstsw\t%0\;fstp\t%y0";
1381   else
1382     return "ftst\;fnstsw\t%0";
1383 }
1384   [(set_attr "type" "multi")
1385    (set_attr "mode" "unknownfp")])
1386
1387 ;; We may not use "#" to split and emit these, since the REG_DEAD notes
1388 ;; used to manage the reg stack popping would not be preserved.
1389
1390 (define_insn "*cmpfp_2_sf"
1391   [(set (reg:CCFP 18)
1392         (compare:CCFP
1393           (match_operand:SF 0 "register_operand" "f")
1394           (match_operand:SF 1 "nonimmediate_operand" "fm")))]
1395   "TARGET_80387"
1396   "* return output_fp_compare (insn, operands, 0, 0);"
1397   [(set_attr "type" "fcmp")
1398    (set_attr "mode" "SF")])
1399
1400 (define_insn "*cmpfp_2_sf_1"
1401   [(set (match_operand:HI 0 "register_operand" "=a")
1402         (unspec:HI
1403           [(compare:CCFP
1404              (match_operand:SF 1 "register_operand" "f")
1405              (match_operand:SF 2 "nonimmediate_operand" "fm"))] 9))]
1406   "TARGET_80387"
1407   "* return output_fp_compare (insn, operands, 2, 0);"
1408   [(set_attr "type" "fcmp")
1409    (set_attr "mode" "SF")])
1410
1411 (define_insn "*cmpfp_2_df"
1412   [(set (reg:CCFP 18)
1413         (compare:CCFP
1414           (match_operand:DF 0 "register_operand" "f")
1415           (match_operand:DF 1 "nonimmediate_operand" "fm")))]
1416   "TARGET_80387"
1417   "* return output_fp_compare (insn, operands, 0, 0);"
1418   [(set_attr "type" "fcmp")
1419    (set_attr "mode" "DF")])
1420
1421 (define_insn "*cmpfp_2_df_1"
1422   [(set (match_operand:HI 0 "register_operand" "=a")
1423         (unspec:HI
1424           [(compare:CCFP
1425              (match_operand:DF 1 "register_operand" "f")
1426              (match_operand:DF 2 "nonimmediate_operand" "fm"))] 9))]
1427   "TARGET_80387"
1428   "* return output_fp_compare (insn, operands, 2, 0);"
1429   [(set_attr "type" "multi")
1430    (set_attr "mode" "DF")])
1431
1432 (define_insn "*cmpfp_2_xf"
1433   [(set (reg:CCFP 18)
1434         (compare:CCFP
1435           (match_operand:XF 0 "register_operand" "f")
1436           (match_operand:XF 1 "register_operand" "f")))]
1437   "TARGET_80387 && !TARGET_64BIT"
1438   "* return output_fp_compare (insn, operands, 0, 0);"
1439   [(set_attr "type" "fcmp")
1440    (set_attr "mode" "XF")])
1441
1442 (define_insn "*cmpfp_2_tf"
1443   [(set (reg:CCFP 18)
1444         (compare:CCFP
1445           (match_operand:TF 0 "register_operand" "f")
1446           (match_operand:TF 1 "register_operand" "f")))]
1447   "TARGET_80387"
1448   "* return output_fp_compare (insn, operands, 0, 0);"
1449   [(set_attr "type" "fcmp")
1450    (set_attr "mode" "XF")])
1451
1452 (define_insn "*cmpfp_2_xf_1"
1453   [(set (match_operand:HI 0 "register_operand" "=a")
1454         (unspec:HI
1455           [(compare:CCFP
1456              (match_operand:XF 1 "register_operand" "f")
1457              (match_operand:XF 2 "register_operand" "f"))] 9))]
1458   "TARGET_80387 && !TARGET_64BIT"
1459   "* return output_fp_compare (insn, operands, 2, 0);"
1460   [(set_attr "type" "multi")
1461    (set_attr "mode" "XF")])
1462
1463 (define_insn "*cmpfp_2_tf_1"
1464   [(set (match_operand:HI 0 "register_operand" "=a")
1465         (unspec:HI
1466           [(compare:CCFP
1467              (match_operand:TF 1 "register_operand" "f")
1468              (match_operand:TF 2 "register_operand" "f"))] 9))]
1469   "TARGET_80387"
1470   "* return output_fp_compare (insn, operands, 2, 0);"
1471   [(set_attr "type" "multi")
1472    (set_attr "mode" "XF")])
1473
1474 (define_insn "*cmpfp_2u"
1475   [(set (reg:CCFPU 18)
1476         (compare:CCFPU
1477           (match_operand 0 "register_operand" "f")
1478           (match_operand 1 "register_operand" "f")))]
1479   "TARGET_80387
1480    && FLOAT_MODE_P (GET_MODE (operands[0]))
1481    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1482   "* return output_fp_compare (insn, operands, 0, 1);"
1483   [(set_attr "type" "fcmp")
1484    (set_attr "mode" "unknownfp")])
1485
1486 (define_insn "*cmpfp_2u_1"
1487   [(set (match_operand:HI 0 "register_operand" "=a")
1488         (unspec:HI
1489           [(compare:CCFPU
1490              (match_operand 1 "register_operand" "f")
1491              (match_operand 2 "register_operand" "f"))] 9))]
1492   "TARGET_80387
1493    && FLOAT_MODE_P (GET_MODE (operands[1]))
1494    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
1495   "* return output_fp_compare (insn, operands, 2, 1);"
1496   [(set_attr "type" "multi")
1497    (set_attr "mode" "unknownfp")])
1498
1499 ;; Patterns to match the SImode-in-memory ficom instructions.
1500 ;;
1501 ;; %%% Play games with accepting gp registers, as otherwise we have to
1502 ;; force them to memory during rtl generation, which is no good.  We
1503 ;; can get rid of this once we teach reload to do memory input reloads 
1504 ;; via pushes.
1505
1506 (define_insn "*ficom_1"
1507   [(set (reg:CCFP 18)
1508         (compare:CCFP
1509           (match_operand 0 "register_operand" "f,f")
1510           (float (match_operand:SI 1 "nonimmediate_operand" "m,?r"))))]
1511   "0 && TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[0]))
1512    && GET_MODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == GET_MODE (operands[0])"
1513   "#")
1514
1515 ;; Split the not-really-implemented gp register case into a
1516 ;; push-op-pop sequence.
1517 ;;
1518 ;; %%% This is most efficient, but am I gonna get in trouble
1519 ;; for separating cc0_setter and cc0_user?
1520
1521 (define_split
1522   [(set (reg:CCFP 18)
1523         (compare:CCFP
1524           (match_operand:SF 0 "register_operand" "")
1525           (float (match_operand:SI 1 "register_operand" ""))))]
1526   "0 && TARGET_80387 && reload_completed"
1527   [(set (mem:SI (pre_dec:SI (reg:SI 7))) (match_dup 1))
1528    (set (reg:CCFP 18) (compare:CCFP (match_dup 0) (match_dup 2)))
1529    (parallel [(set (match_dup 1) (mem:SI (reg:SI 7)))
1530               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))])]
1531   "operands[2] = gen_rtx_MEM (Pmode, stack_pointer_rtx);
1532    operands[2] = gen_rtx_FLOAT (GET_MODE (operands[0]), operands[2]);")
1533
1534 ;; FP compares, step 2
1535 ;; Move the fpsw to ax.
1536
1537 (define_insn "x86_fnstsw_1"
1538   [(set (match_operand:HI 0 "register_operand" "=a")
1539         (unspec:HI [(reg 18)] 9))]
1540   "TARGET_80387"
1541   "fnstsw\t%0"
1542   [(set_attr "length" "2")
1543    (set_attr "mode" "SI")
1544    (set_attr "i387" "1")
1545    (set_attr "ppro_uops" "few")])
1546
1547 ;; FP compares, step 3
1548 ;; Get ax into flags, general case.
1549
1550 (define_insn "x86_sahf_1"
1551   [(set (reg:CC 17)
1552         (unspec:CC [(match_operand:HI 0 "register_operand" "a")] 10))]
1553   "!TARGET_64BIT"
1554   "sahf"
1555   [(set_attr "length" "1")
1556    (set_attr "athlon_decode" "vector")
1557    (set_attr "mode" "SI")
1558    (set_attr "ppro_uops" "one")])
1559
1560 ;; Pentium Pro can do steps 1 through 3 in one go.
1561
1562 (define_insn "*cmpfp_i"
1563   [(set (reg:CCFP 17)
1564         (compare:CCFP (match_operand 0 "register_operand" "f")
1565                       (match_operand 1 "register_operand" "f")))]
1566   "TARGET_80387 && TARGET_CMOVE
1567    && !SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1568    && FLOAT_MODE_P (GET_MODE (operands[0]))
1569    && GET_MODE (operands[0]) == GET_MODE (operands[0])"
1570   "* return output_fp_compare (insn, operands, 1, 0);"
1571   [(set_attr "type" "fcmp")
1572    (set_attr "mode" "unknownfp")
1573    (set_attr "athlon_decode" "vector")])
1574
1575 (define_insn "*cmpfp_i_sse"
1576   [(set (reg:CCFP 17)
1577         (compare:CCFP (match_operand 0 "register_operand" "f#x,x#f")
1578                       (match_operand 1 "nonimmediate_operand" "f#x,xm#f")))]
1579   "TARGET_80387
1580    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1581    && GET_MODE (operands[0]) == GET_MODE (operands[0])"
1582   "* return output_fp_compare (insn, operands, 1, 0);"
1583   [(set_attr "type" "fcmp,sse")
1584    (set_attr "mode" "unknownfp")
1585    (set_attr "athlon_decode" "vector")])
1586
1587 (define_insn "*cmpfp_i_sse_only"
1588   [(set (reg:CCFP 17)
1589         (compare:CCFP (match_operand 0 "register_operand" "x")
1590                       (match_operand 1 "nonimmediate_operand" "xm")))]
1591   "SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1592    && GET_MODE (operands[0]) == GET_MODE (operands[0])"
1593   "* return output_fp_compare (insn, operands, 1, 0);"
1594   [(set_attr "type" "sse")
1595    (set_attr "mode" "unknownfp")
1596    (set_attr "athlon_decode" "vector")])
1597
1598 (define_insn "*cmpfp_iu"
1599   [(set (reg:CCFPU 17)
1600         (compare:CCFPU (match_operand 0 "register_operand" "f")
1601                        (match_operand 1 "register_operand" "f")))]
1602   "TARGET_80387 && TARGET_CMOVE
1603    && !SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1604    && FLOAT_MODE_P (GET_MODE (operands[0]))
1605    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1606   "* return output_fp_compare (insn, operands, 1, 1);"
1607   [(set_attr "type" "fcmp")
1608    (set_attr "mode" "unknownfp")
1609    (set_attr "athlon_decode" "vector")])
1610
1611 (define_insn "*cmpfp_iu_sse"
1612   [(set (reg:CCFPU 17)
1613         (compare:CCFPU (match_operand 0 "register_operand" "f#x,x#f")
1614                        (match_operand 1 "nonimmediate_operand" "f#x,xm#f")))]
1615   "TARGET_80387
1616    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1617    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1618   "* return output_fp_compare (insn, operands, 1, 1);"
1619   [(set_attr "type" "fcmp,sse")
1620    (set_attr "mode" "unknownfp")
1621    (set_attr "athlon_decode" "vector")])
1622
1623 (define_insn "*cmpfp_iu_sse_only"
1624   [(set (reg:CCFPU 17)
1625         (compare:CCFPU (match_operand 0 "register_operand" "x")
1626                        (match_operand 1 "nonimmediate_operand" "xm")))]
1627   "SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1628    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1629   "* return output_fp_compare (insn, operands, 1, 1);"
1630   [(set_attr "type" "sse")
1631    (set_attr "mode" "unknownfp")
1632    (set_attr "athlon_decode" "vector")])
1633 \f
1634 ;; Move instructions.
1635
1636 ;; General case of fullword move.
1637
1638 (define_expand "movsi"
1639   [(set (match_operand:SI 0 "nonimmediate_operand" "")
1640         (match_operand:SI 1 "general_operand" ""))]
1641   ""
1642   "ix86_expand_move (SImode, operands); DONE;")
1643
1644 ;; Push/pop instructions.  They are separate since autoinc/dec is not a
1645 ;; general_operand.
1646 ;;
1647 ;; %%% We don't use a post-inc memory reference because x86 is not a 
1648 ;; general AUTO_INC_DEC host, which impacts how it is treated in flow.
1649 ;; Changing this impacts compiler performance on other non-AUTO_INC_DEC
1650 ;; targets without our curiosities, and it is just as easy to represent
1651 ;; this differently.
1652
1653 (define_insn "*pushsi2"
1654   [(set (match_operand:SI 0 "push_operand" "=<")
1655         (match_operand:SI 1 "general_no_elim_operand" "ri*m"))]
1656   "!TARGET_64BIT"
1657   "push{l}\t%1"
1658   [(set_attr "type" "push")
1659    (set_attr "mode" "SI")])
1660
1661 ;; For 64BIT abi we always round up to 8 bytes.
1662 (define_insn "*pushsi2_rex64"
1663   [(set (match_operand:SI 0 "push_operand" "=X")
1664         (match_operand:SI 1 "nonmemory_no_elim_operand" "ri"))]
1665   "TARGET_64BIT"
1666   "push{q}\t%q1"
1667   [(set_attr "type" "push")
1668    (set_attr "mode" "SI")])
1669
1670 (define_insn "*pushsi2_prologue"
1671   [(set (match_operand:SI 0 "push_operand" "=<")
1672         (match_operand:SI 1 "general_no_elim_operand" "ri*m"))
1673    (clobber (mem:BLK (scratch)))]
1674   "!TARGET_64BIT"
1675   "push{l}\t%1"
1676   [(set_attr "type" "push")
1677    (set_attr "mode" "SI")])
1678
1679 (define_insn "*popsi1_epilogue"
1680   [(set (match_operand:SI 0 "nonimmediate_operand" "=r*m")
1681         (mem:SI (reg:SI 7)))
1682    (set (reg:SI 7)
1683         (plus:SI (reg:SI 7) (const_int 4)))
1684    (clobber (mem:BLK (scratch)))]
1685   "!TARGET_64BIT"
1686   "pop{l}\t%0"
1687   [(set_attr "type" "pop")
1688    (set_attr "mode" "SI")])
1689
1690 (define_insn "popsi1"
1691   [(set (match_operand:SI 0 "nonimmediate_operand" "=r*m")
1692         (mem:SI (reg:SI 7)))
1693    (set (reg:SI 7)
1694         (plus:SI (reg:SI 7) (const_int 4)))]
1695   "!TARGET_64BIT"
1696   "pop{l}\t%0"
1697   [(set_attr "type" "pop")
1698    (set_attr "mode" "SI")])
1699
1700 (define_insn "*movsi_xor"
1701   [(set (match_operand:SI 0 "register_operand" "=r")
1702         (match_operand:SI 1 "const0_operand" "i"))
1703    (clobber (reg:CC 17))]
1704   "reload_completed && (!TARGET_USE_MOV0 || optimize_size)"
1705   "xor{l}\t{%0, %0|%0, %0}"
1706   [(set_attr "type" "alu1")
1707    (set_attr "mode" "SI")
1708    (set_attr "length_immediate" "0")])
1709
1710 (define_insn "*movsi_or"
1711   [(set (match_operand:SI 0 "register_operand" "=r")
1712         (match_operand:SI 1 "immediate_operand" "i"))
1713    (clobber (reg:CC 17))]
1714   "reload_completed && GET_CODE (operands[1]) == CONST_INT
1715    && INTVAL (operands[1]) == -1
1716    && (TARGET_PENTIUM || optimize_size)"
1717 {
1718   operands[1] = constm1_rtx;
1719   return "or{l}\t{%1, %0|%0, %1}";
1720 }
1721   [(set_attr "type" "alu1")
1722    (set_attr "mode" "SI")
1723    (set_attr "length_immediate" "1")])
1724
1725 (define_insn "*movsi_1"
1726   [(set (match_operand:SI 0 "nonimmediate_operand" "=*a,r,*a,m,!*y,!rm,!*Y,!rm,!*Y")
1727         (match_operand:SI 1 "general_operand" "im,rinm,rinm,rin,rm,*y,rm,*Y,*Y"))]
1728   "GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM"
1729 {
1730   switch (get_attr_type (insn))
1731     {
1732     case TYPE_SSE:
1733       if (get_attr_mode (insn) == TImode)
1734         return "movdqa\t{%1, %0|%0, %1}";
1735       return "movd\t{%1, %0|%0, %1}";
1736
1737     case TYPE_MMX:
1738       return "movd\t{%1, %0|%0, %1}";
1739
1740     case TYPE_LEA:
1741       return "lea{l}\t{%1, %0|%0, %1}";
1742
1743     default:
1744       if (flag_pic && SYMBOLIC_CONST (operands[1]))
1745         abort();
1746       return "mov{l}\t{%1, %0|%0, %1}";
1747     }
1748 }
1749   [(set (attr "type")
1750      (cond [(eq_attr "alternative" "4,5")
1751               (const_string "mmx")
1752             (eq_attr "alternative" "6,7,8")
1753               (const_string "sse")
1754             (and (ne (symbol_ref "flag_pic") (const_int 0))
1755                  (match_operand:SI 1 "symbolic_operand" ""))
1756               (const_string "lea")
1757            ]
1758            (const_string "imov")))
1759    (set_attr "modrm" "0,*,0,*,*,*,*,*,*")
1760    (set_attr "mode" "SI,SI,SI,SI,SI,SI,TI,SI,SI")])
1761
1762 ;; Stores and loads of ax to arbitary constant address.
1763 ;; We fake an second form of instruction to force reload to load address
1764 ;; into register when rax is not available
1765 (define_insn "*movabssi_1_rex64"
1766   [(set (mem:SI (match_operand:DI 0 "x86_64_movabs_operand" "i,r,r"))
1767         (match_operand:SI 1 "nonmemory_operand" "a,er,i"))]
1768   "TARGET_64BIT"
1769   "@
1770    movabs{l}\t{%1, %P0|%P0, %1}
1771    mov{l}\t{%1, %a0|%a0, %1}
1772    movabs{l}\t{%1, %a0|%a0, %1}"
1773   [(set_attr "type" "imov")
1774    (set_attr "modrm" "0,*,*")
1775    (set_attr "length_address" "8,0,0")
1776    (set_attr "length_immediate" "0,*,*")
1777    (set_attr "memory" "store")
1778    (set_attr "mode" "SI")])
1779
1780 (define_insn "*movabssi_2_rex64"
1781   [(set (match_operand:SI 0 "register_operand" "=a,r")
1782         (mem:SI (match_operand:DI 1 "x86_64_movabs_operand" "i,r")))]
1783   "TARGET_64BIT"
1784   "@
1785    movabs{l}\t{%P1, %0|%0, %P1}
1786    mov{l}\t{%a1, %0|%0, %a1}"
1787   [(set_attr "type" "imov")
1788    (set_attr "modrm" "0,*")
1789    (set_attr "length_address" "8,0")
1790    (set_attr "length_immediate" "0")
1791    (set_attr "memory" "load")
1792    (set_attr "mode" "SI")])
1793
1794 (define_insn "*swapsi"
1795   [(set (match_operand:SI 0 "register_operand" "+r")
1796         (match_operand:SI 1 "register_operand" "+r"))
1797    (set (match_dup 1)
1798         (match_dup 0))]
1799   ""
1800   "xchg{l}\t%1, %0"
1801   [(set_attr "type" "imov")
1802    (set_attr "pent_pair" "np")
1803    (set_attr "athlon_decode" "vector")
1804    (set_attr "mode" "SI")
1805    (set_attr "modrm" "0")
1806    (set_attr "ppro_uops" "few")])
1807
1808 (define_expand "movhi"
1809   [(set (match_operand:HI 0 "nonimmediate_operand" "")
1810         (match_operand:HI 1 "general_operand" ""))]
1811   ""
1812   "ix86_expand_move (HImode, operands); DONE;")
1813
1814 (define_insn "*pushhi2"
1815   [(set (match_operand:HI 0 "push_operand" "=<,<")
1816         (match_operand:HI 1 "general_no_elim_operand" "n,r*m"))]
1817   "!TARGET_64BIT"
1818   "@
1819    push{w}\t{|WORD PTR }%1
1820    push{w}\t%1"
1821   [(set_attr "type" "push")
1822    (set_attr "mode" "HI")])
1823
1824 ;; For 64BIT abi we always round up to 8 bytes.
1825 (define_insn "*pushhi2_rex64"
1826   [(set (match_operand:HI 0 "push_operand" "=X")
1827         (match_operand:HI 1 "nonmemory_no_elim_operand" "ri"))]
1828   "TARGET_64BIT"
1829   "push{q}\t%q1"
1830   [(set_attr "type" "push")
1831    (set_attr "mode" "QI")])
1832
1833 (define_insn "*movhi_1"
1834   [(set (match_operand:HI 0 "nonimmediate_operand" "=*a,r,r,*a,r,m")
1835         (match_operand:HI 1 "general_operand" "i,r,rn,rm,rm,rn"))]
1836   "GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM"
1837 {
1838   switch (get_attr_type (insn))
1839     {
1840     case TYPE_IMOVX:
1841       /* movzwl is faster than movw on p2 due to partial word stalls,
1842          though not as fast as an aligned movl.  */
1843       return "movz{wl|x}\t{%1, %k0|%k0, %1}";
1844     default:
1845       if (get_attr_mode (insn) == MODE_SI)
1846         return "mov{l}\t{%k1, %k0|%k0, %k1}";
1847       else
1848         return "mov{w}\t{%1, %0|%0, %1}";
1849     }
1850 }
1851   [(set (attr "type")
1852      (cond [(and (eq_attr "alternative" "0,1")
1853                  (ior (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
1854                           (const_int 0))
1855                       (eq (symbol_ref "TARGET_HIMODE_MATH")
1856                           (const_int 0))))
1857               (const_string "imov")
1858             (and (eq_attr "alternative" "2,3,4")
1859                  (match_operand:HI 1 "aligned_operand" ""))
1860               (const_string "imov")
1861             (and (ne (symbol_ref "TARGET_MOVX")
1862                      (const_int 0))
1863                  (eq_attr "alternative" "0,1,3,4"))
1864               (const_string "imovx")
1865            ]
1866            (const_string "imov")))
1867     (set (attr "mode")
1868       (cond [(eq_attr "type" "imovx")
1869                (const_string "SI")
1870              (and (eq_attr "alternative" "2,3,4")
1871                   (match_operand:HI 1 "aligned_operand" ""))
1872                (const_string "SI")
1873              (and (eq_attr "alternative" "0,1")
1874                   (ior (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
1875                            (const_int 0))
1876                        (eq (symbol_ref "TARGET_HIMODE_MATH")
1877                            (const_int 0))))
1878                (const_string "SI")
1879             ]
1880             (const_string "HI")))
1881    (set_attr "modrm" "0,*,*,0,*,*")])
1882
1883 ;; Stores and loads of ax to arbitary constant address.
1884 ;; We fake an second form of instruction to force reload to load address
1885 ;; into register when rax is not available
1886 (define_insn "*movabshi_1_rex64"
1887   [(set (mem:HI (match_operand:DI 0 "x86_64_movabs_operand" "i,r,r"))
1888         (match_operand:HI 1 "nonmemory_operand" "a,er,i"))]
1889   "TARGET_64BIT"
1890   "@
1891    movabs{w}\t{%1, %P0|%P0, %1}
1892    mov{w}\t{%1, %a0|%a0, %1}
1893    movabs{w}\t{%1, %a0|%a0, %1}"
1894   [(set_attr "type" "imov")
1895    (set_attr "modrm" "0,*,*")
1896    (set_attr "length_address" "8,0,0")
1897    (set_attr "length_immediate" "0,*,*")
1898    (set_attr "memory" "store")
1899    (set_attr "mode" "HI")])
1900
1901 (define_insn "*movabshi_2_rex64"
1902   [(set (match_operand:HI 0 "register_operand" "=a,r")
1903         (mem:HI (match_operand:DI 1 "x86_64_movabs_operand" "i,r")))]
1904   "TARGET_64BIT"
1905   "@
1906    movabs{w}\t{%P1, %0|%0, %P1}
1907    mov{w}\t{%a1, %0|%0, %a1}"
1908   [(set_attr "type" "imov")
1909    (set_attr "modrm" "0,*")
1910    (set_attr "length_address" "8,0")
1911    (set_attr "length_immediate" "0")
1912    (set_attr "memory" "load")
1913    (set_attr "mode" "HI")])
1914
1915 (define_insn "*swaphi_1"
1916   [(set (match_operand:HI 0 "register_operand" "+r")
1917         (match_operand:HI 1 "register_operand" "+r"))
1918    (set (match_dup 1)
1919         (match_dup 0))]
1920   "TARGET_PARTIAL_REG_STALL"
1921   "xchg{w}\t%1, %0"
1922   [(set_attr "type" "imov")
1923    (set_attr "pent_pair" "np")
1924    (set_attr "mode" "HI")
1925    (set_attr "modrm" "0")
1926    (set_attr "ppro_uops" "few")])
1927
1928 (define_insn "*swaphi_2"
1929   [(set (match_operand:HI 0 "register_operand" "+r")
1930         (match_operand:HI 1 "register_operand" "+r"))
1931    (set (match_dup 1)
1932         (match_dup 0))]
1933   "! TARGET_PARTIAL_REG_STALL"
1934   "xchg{l}\t%k1, %k0"
1935   [(set_attr "type" "imov")
1936    (set_attr "pent_pair" "np")
1937    (set_attr "mode" "SI")
1938    (set_attr "modrm" "0")
1939    (set_attr "ppro_uops" "few")])
1940
1941 (define_expand "movstricthi"
1942   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" ""))
1943         (match_operand:HI 1 "general_operand" ""))]
1944   "! TARGET_PARTIAL_REG_STALL || optimize_size"
1945 {
1946   /* Don't generate memory->memory moves, go through a register */
1947   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
1948     operands[1] = force_reg (HImode, operands[1]);
1949 })
1950
1951 (define_insn "*movstricthi_1"
1952   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+rm,r"))
1953         (match_operand:HI 1 "general_operand" "rn,m"))]
1954   "(! TARGET_PARTIAL_REG_STALL || optimize_size)
1955    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
1956   "mov{w}\t{%1, %0|%0, %1}"
1957   [(set_attr "type" "imov")
1958    (set_attr "mode" "HI")])
1959
1960 (define_insn "*movstricthi_xor"
1961   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+r"))
1962         (match_operand:HI 1 "const0_operand" "i"))
1963    (clobber (reg:CC 17))]
1964   "reload_completed
1965    && ((!TARGET_USE_MOV0 && !TARGET_PARTIAL_REG_STALL) || optimize_size)"
1966   "xor{w}\t{%0, %0|%0, %0}"
1967   [(set_attr "type" "alu1")
1968    (set_attr "mode" "HI")
1969    (set_attr "length_immediate" "0")])
1970
1971 (define_expand "movqi"
1972   [(set (match_operand:QI 0 "nonimmediate_operand" "")
1973         (match_operand:QI 1 "general_operand" ""))]
1974   ""
1975   "ix86_expand_move (QImode, operands); DONE;")
1976
1977 ;; emit_push_insn when it calls move_by_pieces requires an insn to
1978 ;; "push a byte".  But actually we use pushw, which has the effect
1979 ;; of rounding the amount pushed up to a halfword.
1980
1981 (define_insn "*pushqi2"
1982   [(set (match_operand:QI 0 "push_operand" "=X,X")
1983         (match_operand:QI 1 "nonmemory_no_elim_operand" "n,r"))]
1984   "!TARGET_64BIT"
1985   "@
1986    push{w}\t{|word ptr }%1
1987    push{w}\t%w1"
1988   [(set_attr "type" "push")
1989    (set_attr "mode" "HI")])
1990
1991 ;; For 64BIT abi we always round up to 8 bytes.
1992 (define_insn "*pushqi2_rex64"
1993   [(set (match_operand:QI 0 "push_operand" "=X")
1994         (match_operand:QI 1 "nonmemory_no_elim_operand" "ri"))]
1995   "TARGET_64BIT"
1996   "push{q}\t%q1"
1997   [(set_attr "type" "push")
1998    (set_attr "mode" "QI")])
1999
2000 ;; Situation is quite tricky about when to choose full sized (SImode) move
2001 ;; over QImode moves.  For Q_REG -> Q_REG move we use full size only for
2002 ;; partial register dependency machines (such as AMD Athlon), where QImode
2003 ;; moves issue extra dependency and for partial register stalls machines
2004 ;; that don't use QImode patterns (and QImode move cause stall on the next
2005 ;; instruction).
2006 ;;
2007 ;; For loads of Q_REG to NONQ_REG we use full sized moves except for partial
2008 ;; register stall machines with, where we use QImode instructions, since
2009 ;; partial register stall can be caused there.  Then we use movzx.
2010 (define_insn "*movqi_1"
2011   [(set (match_operand:QI 0 "nonimmediate_operand" "=q,q ,q ,r,r ,?r,m")
2012         (match_operand:QI 1 "general_operand"      " q,qn,qm,q,rn,qm,qn"))]
2013   "GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM"
2014 {
2015   switch (get_attr_type (insn))
2016     {
2017     case TYPE_IMOVX:
2018       if (!ANY_QI_REG_P (operands[1]) && GET_CODE (operands[1]) != MEM)
2019         abort ();
2020       return "movz{bl|x}\t{%1, %k0|%k0, %1}";
2021     default:
2022       if (get_attr_mode (insn) == MODE_SI)
2023         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2024       else
2025         return "mov{b}\t{%1, %0|%0, %1}";
2026     }
2027 }
2028   [(set (attr "type")
2029      (cond [(and (eq_attr "alternative" "3")
2030                  (ior (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
2031                           (const_int 0))
2032                       (eq (symbol_ref "TARGET_QIMODE_MATH")
2033                           (const_int 0))))
2034               (const_string "imov")
2035             (eq_attr "alternative" "3,5")
2036               (const_string "imovx")
2037             (and (ne (symbol_ref "TARGET_MOVX")
2038                      (const_int 0))
2039                  (eq_attr "alternative" "2"))
2040               (const_string "imovx")
2041            ]
2042            (const_string "imov")))
2043    (set (attr "mode")
2044       (cond [(eq_attr "alternative" "3,4,5")
2045                (const_string "SI")
2046              (eq_attr "alternative" "6")
2047                (const_string "QI")
2048              (eq_attr "type" "imovx")
2049                (const_string "SI")
2050              (and (eq_attr "type" "imov")
2051                   (and (eq_attr "alternative" "0,1,2")
2052                        (ne (symbol_ref "TARGET_PARTIAL_REG_DEPENDENCY")
2053                            (const_int 0))))
2054                (const_string "SI")
2055              ;; Avoid partial register stalls when not using QImode arithmetic
2056              (and (eq_attr "type" "imov")
2057                   (and (eq_attr "alternative" "0,1,2")
2058                        (and (ne (symbol_ref "TARGET_PARTIAL_REG_STALL")
2059                                 (const_int 0))
2060                             (eq (symbol_ref "TARGET_QIMODE_MATH")
2061                                 (const_int 0)))))
2062                (const_string "SI")
2063            ]
2064            (const_string "QI")))])
2065
2066 (define_expand "reload_outqi"
2067   [(parallel [(match_operand:QI 0 "" "=m")
2068               (match_operand:QI 1 "register_operand" "r")
2069               (match_operand:QI 2 "register_operand" "=&q")])]
2070   ""
2071 {
2072   rtx op0, op1, op2;
2073   op0 = operands[0]; op1 = operands[1]; op2 = operands[2];
2074
2075   if (reg_overlap_mentioned_p (op2, op0))
2076     abort ();
2077   if (! q_regs_operand (op1, QImode))
2078     {
2079       emit_insn (gen_movqi (op2, op1));
2080       op1 = op2;
2081     }
2082   emit_insn (gen_movqi (op0, op1));
2083   DONE;
2084 })
2085
2086 (define_insn "*swapqi"
2087   [(set (match_operand:QI 0 "register_operand" "+r")
2088         (match_operand:QI 1 "register_operand" "+r"))
2089    (set (match_dup 1)
2090         (match_dup 0))]
2091   ""
2092   "xchg{b}\t%1, %0"
2093   [(set_attr "type" "imov")
2094    (set_attr "pent_pair" "np")
2095    (set_attr "mode" "QI")
2096    (set_attr "modrm" "0")
2097    (set_attr "ppro_uops" "few")])
2098
2099 (define_expand "movstrictqi"
2100   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" ""))
2101         (match_operand:QI 1 "general_operand" ""))]
2102   "! TARGET_PARTIAL_REG_STALL"
2103 {
2104   /* Don't generate memory->memory moves, go through a register */
2105   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
2106     operands[1] = force_reg (QImode, operands[1]);
2107 })
2108
2109 (define_insn "*movstrictqi_1"
2110   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
2111         (match_operand:QI 1 "general_operand" "*qn,m"))]
2112   "! TARGET_PARTIAL_REG_STALL
2113    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
2114   "mov{b}\t{%1, %0|%0, %1}"
2115   [(set_attr "type" "imov")
2116    (set_attr "mode" "QI")])
2117
2118 (define_insn "*movstrictqi_xor"
2119   [(set (strict_low_part (match_operand:QI 0 "q_regs_operand" "+q"))
2120         (match_operand:QI 1 "const0_operand" "i"))
2121    (clobber (reg:CC 17))]
2122   "reload_completed && (!TARGET_USE_MOV0 || optimize_size)"
2123   "xor{b}\t{%0, %0|%0, %0}"
2124   [(set_attr "type" "alu1")
2125    (set_attr "mode" "QI")
2126    (set_attr "length_immediate" "0")])
2127
2128 (define_insn "*movsi_extv_1"
2129   [(set (match_operand:SI 0 "register_operand" "=R")
2130         (sign_extract:SI (match_operand 1 "ext_register_operand" "Q")
2131                          (const_int 8)
2132                          (const_int 8)))]
2133   ""
2134   "movs{bl|x}\t{%h1, %0|%0, %h1}"
2135   [(set_attr "type" "imovx")
2136    (set_attr "mode" "SI")])
2137
2138 (define_insn "*movhi_extv_1"
2139   [(set (match_operand:HI 0 "register_operand" "=R")
2140         (sign_extract:HI (match_operand 1 "ext_register_operand" "Q")
2141                          (const_int 8)
2142                          (const_int 8)))]
2143   ""
2144   "movs{bl|x}\t{%h1, %k0|%k0, %h1}"
2145   [(set_attr "type" "imovx")
2146    (set_attr "mode" "SI")])
2147
2148 (define_insn "*movqi_extv_1"
2149   [(set (match_operand:QI 0 "nonimmediate_operand" "=Qm,?r")
2150         (sign_extract:QI (match_operand 1 "ext_register_operand" "Q,Q")
2151                          (const_int 8)
2152                          (const_int 8)))]
2153   "!TARGET_64BIT"
2154 {
2155   switch (get_attr_type (insn))
2156     {
2157     case TYPE_IMOVX:
2158       return "movs{bl|x}\t{%h1, %k0|%k0, %h1}";
2159     default:
2160       return "mov{b}\t{%h1, %0|%0, %h1}";
2161     }
2162 }
2163   [(set (attr "type")
2164      (if_then_else (and (match_operand:QI 0 "register_operand" "")
2165                         (ior (not (match_operand:QI 0 "q_regs_operand" ""))
2166                              (ne (symbol_ref "TARGET_MOVX")
2167                                  (const_int 0))))
2168         (const_string "imovx")
2169         (const_string "imov")))
2170    (set (attr "mode")
2171      (if_then_else (eq_attr "type" "imovx")
2172         (const_string "SI")
2173         (const_string "QI")))])
2174
2175 (define_insn "*movqi_extv_1_rex64"
2176   [(set (match_operand:QI 0 "register_operand" "=Q,?R")
2177         (sign_extract:QI (match_operand 1 "ext_register_operand" "Q,Q")
2178                          (const_int 8)
2179                          (const_int 8)))]
2180   "TARGET_64BIT"
2181 {
2182   switch (get_attr_type (insn))
2183     {
2184     case TYPE_IMOVX:
2185       return "movs{bl|x}\t{%h1, %k0|%k0, %h1}";
2186     default:
2187       return "mov{b}\t{%h1, %0|%0, %h1}";
2188     }
2189 }
2190   [(set (attr "type")
2191      (if_then_else (and (match_operand:QI 0 "register_operand" "")
2192                         (ior (not (match_operand:QI 0 "q_regs_operand" ""))
2193                              (ne (symbol_ref "TARGET_MOVX")
2194                                  (const_int 0))))
2195         (const_string "imovx")
2196         (const_string "imov")))
2197    (set (attr "mode")
2198      (if_then_else (eq_attr "type" "imovx")
2199         (const_string "SI")
2200         (const_string "QI")))])
2201
2202 ;; Stores and loads of ax to arbitary constant address.
2203 ;; We fake an second form of instruction to force reload to load address
2204 ;; into register when rax is not available
2205 (define_insn "*movabsqi_1_rex64"
2206   [(set (mem:QI (match_operand:DI 0 "x86_64_movabs_operand" "i,r,r"))
2207         (match_operand:QI 1 "nonmemory_operand" "a,er,i"))]
2208   "TARGET_64BIT"
2209   "@
2210    movabs{q}\t{%1, %P0|%P0, %1}
2211    mov{q}\t{%1, %a0|%a0, %1}
2212    movabs{q}\t{%1, %a0|%a0, %1}"
2213   [(set_attr "type" "imov")
2214    (set_attr "modrm" "0,*,*")
2215    (set_attr "length_address" "8,0,0")
2216    (set_attr "length_immediate" "0,*,*")
2217    (set_attr "memory" "store")
2218    (set_attr "mode" "QI")])
2219
2220 (define_insn "*movabsqi_2_rex64"
2221   [(set (match_operand:QI 0 "register_operand" "=a,r")
2222         (mem:QI (match_operand:DI 1 "x86_64_movabs_operand" "i,r")))]
2223   "TARGET_64BIT"
2224   "@
2225    movabs{q}\t{%P1, %0|%0, %P1}
2226    mov{q}\t{%a1, %0|%0, %a1}"
2227   [(set_attr "type" "imov")
2228    (set_attr "modrm" "0,*")
2229    (set_attr "length_address" "8,0")
2230    (set_attr "length_immediate" "0")
2231    (set_attr "memory" "load")
2232    (set_attr "mode" "QI")])
2233
2234 (define_insn "*movsi_extzv_1"
2235   [(set (match_operand:SI 0 "register_operand" "=R")
2236         (zero_extract:SI (match_operand 1 "ext_register_operand" "Q")
2237                          (const_int 8)
2238                          (const_int 8)))]
2239   ""
2240   "movz{bl|x}\t{%h1, %0|%0, %h1}"
2241   [(set_attr "type" "imovx")
2242    (set_attr "mode" "SI")])
2243
2244 (define_insn "*movqi_extzv_2"
2245   [(set (match_operand:QI 0 "nonimmediate_operand" "=Qm,?R")
2246         (subreg:QI (zero_extract:SI (match_operand 1 "ext_register_operand" "Q,Q")
2247                                     (const_int 8)
2248                                     (const_int 8)) 0))]
2249   "!TARGET_64BIT"
2250 {
2251   switch (get_attr_type (insn))
2252     {
2253     case TYPE_IMOVX:
2254       return "movz{bl|x}\t{%h1, %k0|%k0, %h1}";
2255     default:
2256       return "mov{b}\t{%h1, %0|%0, %h1}";
2257     }
2258 }
2259   [(set (attr "type")
2260      (if_then_else (and (match_operand:QI 0 "register_operand" "")
2261                         (ior (not (match_operand:QI 0 "q_regs_operand" ""))
2262                              (ne (symbol_ref "TARGET_MOVX")
2263                                  (const_int 0))))
2264         (const_string "imovx")
2265         (const_string "imov")))
2266    (set (attr "mode")
2267      (if_then_else (eq_attr "type" "imovx")
2268         (const_string "SI")
2269         (const_string "QI")))])
2270
2271 (define_insn "*movqi_extzv_2_rex64"
2272   [(set (match_operand:QI 0 "register_operand" "=Q,?R")
2273         (subreg:QI (zero_extract:SI (match_operand 1 "ext_register_operand" "Q,Q")
2274                                     (const_int 8)
2275                                     (const_int 8)) 0))]
2276   "TARGET_64BIT"
2277 {
2278   switch (get_attr_type (insn))
2279     {
2280     case TYPE_IMOVX:
2281       return "movz{bl|x}\t{%h1, %k0|%k0, %h1}";
2282     default:
2283       return "mov{b}\t{%h1, %0|%0, %h1}";
2284     }
2285 }
2286   [(set (attr "type")
2287      (if_then_else (ior (not (match_operand:QI 0 "q_regs_operand" ""))
2288                         (ne (symbol_ref "TARGET_MOVX")
2289                             (const_int 0)))
2290         (const_string "imovx")
2291         (const_string "imov")))
2292    (set (attr "mode")
2293      (if_then_else (eq_attr "type" "imovx")
2294         (const_string "SI")
2295         (const_string "QI")))])
2296
2297 (define_insn "movsi_insv_1"
2298   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "+Q")
2299                          (const_int 8)
2300                          (const_int 8))
2301         (match_operand:SI 1 "general_operand" "Qmn"))]
2302   "!TARGET_64BIT"
2303   "mov{b}\t{%b1, %h0|%h0, %b1}"
2304   [(set_attr "type" "imov")
2305    (set_attr "mode" "QI")])
2306
2307 (define_insn "*movsi_insv_1_rex64"
2308   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "+Q")
2309                          (const_int 8)
2310                          (const_int 8))
2311         (match_operand:SI 1 "nonmemory_operand" "Qn"))]
2312   "TARGET_64BIT"
2313   "mov{b}\t{%b1, %h0|%h0, %b1}"
2314   [(set_attr "type" "imov")
2315    (set_attr "mode" "QI")])
2316
2317 (define_insn "*movqi_insv_2"
2318   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "+Q")
2319                          (const_int 8)
2320                          (const_int 8))
2321         (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "Q")
2322                              (const_int 8))
2323                 (const_int 255)))]
2324   ""
2325   "mov{b}\t{%h1, %h0|%h0, %h1}"
2326   [(set_attr "type" "imov")
2327    (set_attr "mode" "QI")])
2328
2329 (define_expand "movdi"
2330   [(set (match_operand:DI 0 "nonimmediate_operand" "")
2331         (match_operand:DI 1 "general_operand" ""))]
2332   ""
2333   "ix86_expand_move (DImode, operands); DONE;")
2334
2335 (define_insn "*pushdi"
2336   [(set (match_operand:DI 0 "push_operand" "=<")
2337         (match_operand:DI 1 "general_no_elim_operand" "riF*m"))]
2338   "!TARGET_64BIT"
2339   "#")
2340
2341 (define_insn "pushdi2_rex64"
2342   [(set (match_operand:DI 0 "push_operand" "=<,!<")
2343         (match_operand:DI 1 "general_no_elim_operand" "re*m,n"))]
2344   "TARGET_64BIT"
2345   "@
2346    push{q}\t%1
2347    #"
2348   [(set_attr "type" "push,multi")
2349    (set_attr "mode" "DI")])
2350
2351 ;; Convert impossible pushes of immediate to existing instructions.
2352 ;; First try to get scratch register and go trought it.  In case this
2353 ;; fails, push sign extended lower part first and then overwrite
2354 ;; upper part by 32bit move.
2355 (define_peephole2
2356   [(match_scratch:DI 2 "r")
2357    (set (match_operand:DI 0 "push_operand" "")
2358         (match_operand:DI 1 "immediate_operand" ""))]
2359   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
2360    && !x86_64_immediate_operand (operands[1], DImode)"
2361   [(set (match_dup 2) (match_dup 1))
2362    (set (match_dup 0) (match_dup 2))]
2363   "")
2364
2365 ;; We need to define this as both peepholer and splitter for case
2366 ;; peephole2 pass is not run.
2367 (define_peephole2
2368   [(set (match_operand:DI 0 "push_operand" "")
2369         (match_operand:DI 1 "immediate_operand" ""))]
2370   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
2371    && !x86_64_immediate_operand (operands[1], DImode) && 1"
2372   [(set (match_dup 0) (match_dup 1))
2373    (set (match_dup 2) (match_dup 3))]
2374   "split_di (operands + 1, 1, operands + 2, operands + 3);
2375    operands[1] = gen_lowpart (DImode, operands[2]);
2376    operands[2] = gen_rtx_MEM (SImode, gen_rtx_PLUS (DImode, stack_pointer_rtx,
2377                                                     GEN_INT (4)));
2378   ")
2379
2380 (define_split
2381   [(set (match_operand:DI 0 "push_operand" "")
2382         (match_operand:DI 1 "immediate_operand" ""))]
2383   "TARGET_64BIT && (flow2_completed || (reload_completed && !flag_peephole2))
2384    && !symbolic_operand (operands[1], DImode)
2385    && !x86_64_immediate_operand (operands[1], DImode)"
2386   [(set (match_dup 0) (match_dup 1))
2387    (set (match_dup 2) (match_dup 3))]
2388   "split_di (operands + 1, 1, operands + 2, operands + 3);
2389    operands[1] = gen_lowpart (DImode, operands[2]);
2390    operands[2] = gen_rtx_MEM (SImode, gen_rtx_PLUS (DImode, stack_pointer_rtx,
2391                                                     GEN_INT (4)));
2392   ")
2393
2394 (define_insn "*pushdi2_prologue_rex64"
2395   [(set (match_operand:DI 0 "push_operand" "=<")
2396         (match_operand:DI 1 "general_no_elim_operand" "re*m"))
2397    (clobber (mem:BLK (scratch)))]
2398   "TARGET_64BIT"
2399   "push{q}\t%1"
2400   [(set_attr "type" "push")
2401    (set_attr "mode" "DI")])
2402
2403 (define_insn "*popdi1_epilogue_rex64"
2404   [(set (match_operand:DI 0 "nonimmediate_operand" "=r*m")
2405         (mem:DI (reg:DI 7)))
2406    (set (reg:DI 7)
2407         (plus:DI (reg:DI 7) (const_int 8)))
2408    (clobber (mem:BLK (scratch)))]
2409   "TARGET_64BIT"
2410   "pop{q}\t%0"
2411   [(set_attr "type" "pop")
2412    (set_attr "mode" "DI")])
2413
2414 (define_insn "popdi1"
2415   [(set (match_operand:DI 0 "nonimmediate_operand" "=r*m")
2416         (mem:DI (reg:DI 7)))
2417    (set (reg:DI 7)
2418         (plus:DI (reg:DI 7) (const_int 8)))]
2419   "TARGET_64BIT"
2420   "pop{q}\t%0"
2421   [(set_attr "type" "pop")
2422    (set_attr "mode" "DI")])
2423
2424 (define_insn "*movdi_xor_rex64"
2425   [(set (match_operand:DI 0 "register_operand" "=r")
2426         (match_operand:DI 1 "const0_operand" "i"))
2427    (clobber (reg:CC 17))]
2428   "reload_completed && (!TARGET_USE_MOV0 || optimize_size)
2429    && TARGET_64BIT"
2430   "xor{l}\t{%k0, %k0|%k0, %k0}"
2431   [(set_attr "type" "alu1")
2432    (set_attr "mode" "SI")
2433    (set_attr "length_immediate" "0")])
2434
2435 (define_insn "*movdi_or_rex64"
2436   [(set (match_operand:DI 0 "register_operand" "=r")
2437         (match_operand:DI 1 "const_int_operand" "i"))
2438    (clobber (reg:CC 17))]
2439   "reload_completed && GET_CODE (operands[1]) == CONST_INT
2440    && TARGET_64BIT
2441    && INTVAL (operands[1]) == -1
2442    && (TARGET_PENTIUM || optimize_size)"
2443 {
2444   operands[1] = constm1_rtx;
2445   return "or{q}\t{%1, %0|%0, %1}";
2446 }
2447   [(set_attr "type" "alu1")
2448    (set_attr "mode" "DI")
2449    (set_attr "length_immediate" "1")])
2450
2451 (define_insn "*movdi_2"
2452   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,o,!m*y,!*y,!m,*Y,!*Y")
2453         (match_operand:DI 1 "general_operand" "riFo,riF,*y,m,*Y,*Y,m"))]
2454   "!TARGET_64BIT
2455    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
2456   "@
2457    #
2458    #
2459    movq\t{%1, %0|%0, %1}
2460    movq\t{%1, %0|%0, %1}
2461    movq\t{%1, %0|%0, %1}
2462    movdqa\t{%1, %0|%0, %1}
2463    movq\t{%1, %0|%0, %1}"
2464   [(set_attr "type" "*,*,mmx,mmx,sse,sse,sse")
2465    (set_attr "mode" "DI,DI,DI,DI,DI,TI,DI")])
2466
2467 (define_split
2468   [(set (match_operand:DI 0 "push_operand" "")
2469         (match_operand:DI 1 "general_operand" ""))]
2470   "!TARGET_64BIT && reload_completed
2471    && (! MMX_REG_P (operands[1]) && !SSE_REG_P (operands[1]))"
2472   [(const_int 0)]
2473   "ix86_split_long_move (operands); DONE;")
2474
2475 ;; %%% This multiword shite has got to go.
2476 (define_split
2477   [(set (match_operand:DI 0 "nonimmediate_operand" "")
2478         (match_operand:DI 1 "general_operand" ""))]
2479   "!TARGET_64BIT && reload_completed
2480    && (!MMX_REG_P (operands[0]) && !SSE_REG_P (operands[0]))
2481    && (!MMX_REG_P (operands[1]) && !SSE_REG_P (operands[1]))"
2482   [(const_int 0)]
2483   "ix86_split_long_move (operands); DONE;")
2484
2485 (define_insn "*movdi_1_rex64"
2486   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,r,mr,!mr,!m*y,!*y,!*Y,!m,!*Y")
2487         (match_operand:DI 1 "general_operand" "Z,rem,i,re,n,*y,m,*Y,*Y,*m"))]
2488   "(GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
2489    && TARGET_64BIT"
2490 {
2491   switch (get_attr_type (insn))
2492     {
2493     case TYPE_SSE:
2494       if (register_operand (operands[0], DImode)
2495           && register_operand (operands[1], DImode))
2496           return "movdqa\t{%1, %0|%0, %1}";
2497       /* FALLTHRU */
2498     case TYPE_MMX:
2499       return "movq\t{%1, %0|%0, %1}";
2500     case TYPE_MULTI:
2501       return "#";
2502     case TYPE_LEA:
2503       return "lea{q}\t{%a1, %0|%0, %a1}";
2504     default:
2505       if (flag_pic && SYMBOLIC_CONST (operands[1]))
2506         abort ();
2507       if (get_attr_mode (insn) == MODE_SI)
2508         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2509       else if (which_alternative == 2)
2510         return "movabs{q}\t{%1, %0|%0, %1}";
2511       else
2512         return "mov{q}\t{%1, %0|%0, %1}";
2513     }
2514 }
2515   [(set (attr "type")
2516      (cond [(eq_attr "alternative" "5,6")
2517               (const_string "mmx")
2518             (eq_attr "alternative" "7,8")
2519               (const_string "sse")
2520             (eq_attr "alternative" "4")
2521               (const_string "multi")
2522             (and (ne (symbol_ref "flag_pic") (const_int 0))
2523                  (match_operand:DI 1 "symbolic_operand" ""))
2524               (const_string "lea")
2525            ]
2526            (const_string "imov")))
2527    (set_attr "modrm" "*,0,0,*,*,*,*,*,*,*")
2528    (set_attr "length_immediate" "*,4,8,*,*,*,*,*,*,*")
2529    (set_attr "mode" "SI,DI,DI,DI,SI,DI,DI,DI,TI,DI")])
2530
2531 ;; Stores and loads of ax to arbitary constant address.
2532 ;; We fake an second form of instruction to force reload to load address
2533 ;; into register when rax is not available
2534 (define_insn "*movabsdi_1_rex64"
2535   [(set (mem:DI (match_operand:DI 0 "x86_64_movabs_operand" "i,r,r"))
2536         (match_operand:DI 1 "nonmemory_operand" "a,er,i"))]
2537   "TARGET_64BIT"
2538   "@
2539    movabs{q}\t{%1, %P0|%P0, %1}
2540    mov{q}\t{%1, %a0|%a0, %1}
2541    movabs{q}\t{%1, %a0|%a0, %1}"
2542   [(set_attr "type" "imov")
2543    (set_attr "modrm" "0,*,*")
2544    (set_attr "length_address" "8,0,0")
2545    (set_attr "length_immediate" "0,*,*")
2546    (set_attr "memory" "store")
2547    (set_attr "mode" "DI")])
2548
2549 (define_insn "*movabsdi_2_rex64"
2550   [(set (match_operand:DI 0 "register_operand" "=a,r")
2551         (mem:DI (match_operand:DI 1 "x86_64_movabs_operand" "i,r")))]
2552   "TARGET_64BIT"
2553   "@
2554    movabs{q}\t{%P1, %0|%0, %P1}
2555    mov{q}\t{%a1, %0|%0, %a1}"
2556   [(set_attr "type" "imov")
2557    (set_attr "modrm" "0,*")
2558    (set_attr "length_address" "8,0")
2559    (set_attr "length_immediate" "0")
2560    (set_attr "memory" "load")
2561    (set_attr "mode" "DI")])
2562
2563 ;; Convert impossible stores of immediate to existing instructions.
2564 ;; First try to get scratch register and go trought it.  In case this
2565 ;; fails, move by 32bit parts.
2566 (define_peephole2
2567   [(match_scratch:DI 2 "r")
2568    (set (match_operand:DI 0 "memory_operand" "")
2569         (match_operand:DI 1 "immediate_operand" ""))]
2570   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
2571    && !x86_64_immediate_operand (operands[1], DImode)"
2572   [(set (match_dup 2) (match_dup 1))
2573    (set (match_dup 0) (match_dup 2))]
2574   "")
2575
2576 ;; We need to define this as both peepholer and splitter for case
2577 ;; peephole2 pass is not run.
2578 (define_peephole2
2579   [(set (match_operand:DI 0 "memory_operand" "")
2580         (match_operand:DI 1 "immediate_operand" ""))]
2581   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
2582    && !x86_64_immediate_operand (operands[1], DImode) && 1"
2583   [(set (match_dup 2) (match_dup 3))
2584    (set (match_dup 4) (match_dup 5))]
2585   "split_di (operands, 2, operands + 2, operands + 4);")
2586
2587 (define_split
2588   [(set (match_operand:DI 0 "memory_operand" "")
2589         (match_operand:DI 1 "immediate_operand" ""))]
2590   "TARGET_64BIT && (flow2_completed || (reload_completed && !flag_peephole2))
2591    && !symbolic_operand (operands[1], DImode)
2592    && !x86_64_immediate_operand (operands[1], DImode)"
2593   [(set (match_dup 2) (match_dup 3))
2594    (set (match_dup 4) (match_dup 5))]
2595   "split_di (operands, 2, operands + 2, operands + 4);")
2596
2597 (define_insn "*swapdi_rex64"
2598   [(set (match_operand:DI 0 "register_operand" "+r")
2599         (match_operand:DI 1 "register_operand" "+r"))
2600    (set (match_dup 1)
2601         (match_dup 0))]
2602   "TARGET_64BIT"
2603   "xchg{q}\t%1, %0"
2604   [(set_attr "type" "imov")
2605    (set_attr "pent_pair" "np")
2606    (set_attr "athlon_decode" "vector")
2607    (set_attr "mode" "DI")
2608    (set_attr "modrm" "0")
2609    (set_attr "ppro_uops" "few")])
2610
2611   
2612 (define_expand "movsf"
2613   [(set (match_operand:SF 0 "nonimmediate_operand" "")
2614         (match_operand:SF 1 "general_operand" ""))]
2615   ""
2616   "ix86_expand_move (SFmode, operands); DONE;")
2617
2618 (define_insn "*pushsf"
2619   [(set (match_operand:SF 0 "push_operand" "=<,<,<")
2620         (match_operand:SF 1 "general_no_elim_operand" "f#rx,rFm#fx,x#rf"))]
2621   "!TARGET_64BIT"
2622 {
2623   switch (which_alternative)
2624     {
2625     case 0:
2626       /* %%% We loose REG_DEAD notes for controling pops if we split late.  */
2627       operands[0] = gen_rtx_MEM (SFmode, stack_pointer_rtx);
2628       operands[2] = stack_pointer_rtx;
2629       operands[3] = GEN_INT (4);
2630       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2631         return "sub{l}\t{%3, %2|%2, %3}\;fstp%z0\t%y0";
2632       else
2633         return "sub{l}\t{%3, %2|%2, %3}\;fst%z0\t%y0";
2634
2635     case 1:
2636       return "push{l}\t%1";
2637     case 2:
2638       return "#";
2639
2640     default:
2641       abort ();
2642     }
2643 }
2644   [(set_attr "type" "multi,push,multi")
2645    (set_attr "mode" "SF,SI,SF")])
2646
2647 (define_insn "*pushsf_rex64"
2648   [(set (match_operand:SF 0 "push_operand" "=X,X,X")
2649         (match_operand:SF 1 "nonmemory_no_elim_operand" "f#rx,rF#fx,x#rf"))]
2650   "TARGET_64BIT"
2651 {
2652   switch (which_alternative)
2653     {
2654     case 0:
2655       /* %%% We loose REG_DEAD notes for controling pops if we split late.  */
2656       operands[0] = gen_rtx_MEM (SFmode, stack_pointer_rtx);
2657       operands[2] = stack_pointer_rtx;
2658       operands[3] = GEN_INT (8);
2659       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2660         return "sub{q}\t{%3, %2|%2, %3}\;fstp%z0\t%y0";
2661       else
2662         return "sub{q}\t{%3, %2|%2, %3}\;fst%z0\t%y0";
2663
2664     case 1:
2665       return "push{q}\t%q1";
2666
2667     case 2:
2668       return "#";
2669
2670     default:
2671       abort ();
2672     }
2673 }
2674   [(set_attr "type" "multi,push,multi")
2675    (set_attr "mode" "SF,DI,SF")])
2676
2677 (define_split
2678   [(set (match_operand:SF 0 "push_operand" "")
2679         (match_operand:SF 1 "memory_operand" ""))]
2680   "reload_completed
2681    && GET_CODE (operands[1]) == MEM
2682    && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
2683    && CONSTANT_POOL_ADDRESS_P (XEXP (operands[1], 0))"
2684   [(set (match_dup 0)
2685         (match_dup 1))]
2686   "operands[1] = get_pool_constant (XEXP (operands[1], 0));")
2687
2688
2689 ;; %%% Kill this when call knows how to work this out.
2690 (define_split
2691   [(set (match_operand:SF 0 "push_operand" "")
2692         (match_operand:SF 1 "register_operand" ""))]
2693   "!TARGET_64BIT && ANY_FP_REGNO_P (REGNO (operands[1]))"
2694   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -4)))
2695    (set (mem:SF (reg:SI 7)) (match_dup 1))])
2696
2697 (define_split
2698   [(set (match_operand:SF 0 "push_operand" "")
2699         (match_operand:SF 1 "register_operand" ""))]
2700   "TARGET_64BIT && ANY_FP_REGNO_P (REGNO (operands[1]))"
2701   [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -8)))
2702    (set (mem:SF (reg:DI 7)) (match_dup 1))])
2703
2704 (define_insn "*movsf_1"
2705   [(set (match_operand:SF 0 "nonimmediate_operand" "=f#xr,m,f#xr,r#xf,m,x#rf,x#rf,x#rf,m")
2706         (match_operand:SF 1 "general_operand" "fm#rx,f#rx,G,rmF#fx,Fr#fx,H,x,xm#rf,x#rf"))]
2707   "(GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
2708    && (reload_in_progress || reload_completed
2709        || GET_CODE (operands[1]) != CONST_DOUBLE
2710        || memory_operand (operands[0], SFmode))" 
2711 {
2712   switch (which_alternative)
2713     {
2714     case 0:
2715       if (REG_P (operands[1])
2716           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2717         return "fstp\t%y0";
2718       else if (STACK_TOP_P (operands[0]))
2719         return "fld%z1\t%y1";
2720       else
2721         return "fst\t%y0";
2722
2723     case 1:
2724       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2725         return "fstp%z0\t%y0";
2726       else
2727         return "fst%z0\t%y0";
2728
2729     case 2:
2730       switch (standard_80387_constant_p (operands[1]))
2731         {
2732         case 1:
2733           return "fldz";
2734         case 2:
2735           return "fld1";
2736         }
2737       abort();
2738
2739     case 3:
2740     case 4:
2741       return "mov{l}\t{%1, %0|%0, %1}";
2742     case 5:
2743       return "pxor\t%0, %0";
2744     case 6:
2745       if (TARGET_PARTIAL_REG_DEPENDENCY)
2746         return "movaps\t{%1, %0|%0, %1}";
2747       else
2748         return "movss\t{%1, %0|%0, %1}";
2749     case 7:
2750     case 8:
2751       return "movss\t{%1, %0|%0, %1}";
2752
2753     default:
2754       abort();
2755     }
2756 }
2757   [(set_attr "type" "fmov,fmov,fmov,imov,imov,sse,sse,sse,sse")
2758    (set_attr "mode" "SF,SF,SF,SI,SI,TI,SF,SF,SF")])
2759
2760 (define_insn "*swapsf"
2761   [(set (match_operand:SF 0 "register_operand" "+f")
2762         (match_operand:SF 1 "register_operand" "+f"))
2763    (set (match_dup 1)
2764         (match_dup 0))]
2765   "reload_completed || !TARGET_SSE2"
2766 {
2767   if (STACK_TOP_P (operands[0]))
2768     return "fxch\t%1";
2769   else
2770     return "fxch\t%0";
2771 }
2772   [(set_attr "type" "fxch")
2773    (set_attr "mode" "SF")])
2774
2775 (define_expand "movdf"
2776   [(set (match_operand:DF 0 "nonimmediate_operand" "")
2777         (match_operand:DF 1 "general_operand" ""))]
2778   ""
2779   "ix86_expand_move (DFmode, operands); DONE;")
2780
2781 ;; Size of pushdf is 3 (for sub) + 2 (for fstp) + memory operand size.
2782 ;; Size of pushdf using integer insturctions is 2+2*memory operand size
2783 ;; On the average, pushdf using integers can be still shorter.  Allow this
2784 ;; pattern for optimize_size too.
2785
2786 (define_insn "*pushdf_nointeger"
2787   [(set (match_operand:DF 0 "push_operand" "=<,<,<,<")
2788         (match_operand:DF 1 "general_no_elim_operand" "f#Y,Fo#fY,*r#fY,Y#f"))]
2789   "!TARGET_64BIT && !TARGET_INTEGER_DFMODE_MOVES"
2790 {
2791   switch (which_alternative)
2792     {
2793     case 0:
2794       /* %%% We loose REG_DEAD notes for controling pops if we split late.  */
2795       operands[0] = gen_rtx_MEM (DFmode, stack_pointer_rtx);
2796       operands[2] = stack_pointer_rtx;
2797       operands[3] = GEN_INT (8);
2798       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2799         return "sub{l}\t{%3, %2|%2, %3}\;fstp%z0\t%y0";
2800       else
2801         return "sub{l}\t{%3, %2|%2, %3}\;fst%z0\t%y0";
2802
2803     case 1:
2804     case 2:
2805     case 3:
2806       return "#";
2807
2808     default:
2809       abort ();
2810     }
2811 }
2812   [(set_attr "type" "multi")
2813    (set_attr "mode" "DF,SI,SI,DF")])
2814
2815 (define_insn "*pushdf_integer"
2816   [(set (match_operand:DF 0 "push_operand" "=<,<,<")
2817         (match_operand:DF 1 "general_no_elim_operand" "f#rY,rFo#fY,Y#rf"))]
2818   "TARGET_64BIT || TARGET_INTEGER_DFMODE_MOVES"
2819 {
2820   switch (which_alternative)
2821     {
2822     case 0:
2823       /* %%% We loose REG_DEAD notes for controling pops if we split late.  */
2824       operands[0] = gen_rtx_MEM (DFmode, stack_pointer_rtx);
2825       operands[2] = stack_pointer_rtx;
2826       operands[3] = GEN_INT (8);
2827       if (TARGET_64BIT)
2828         if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2829           return "sub{q}\t{%3, %2|%2, %3}\;fstp%z0\t%y0";
2830         else
2831           return "sub{q}\t{%3, %2|%2, %3}\;fst%z0\t%y0";
2832       else
2833         if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2834           return "sub{l}\t{%3, %2|%2, %3}\;fstp%z0\t%y0";
2835         else
2836           return "sub{l}\t{%3, %2|%2, %3}\;fst%z0\t%y0";
2837
2838
2839     case 1:
2840     case 2:
2841       return "#";
2842
2843     default:
2844       abort ();
2845     }
2846 }
2847   [(set_attr "type" "multi")
2848    (set_attr "mode" "DF,SI,DF")])
2849
2850 ;; %%% Kill this when call knows how to work this out.
2851 (define_split
2852   [(set (match_operand:DF 0 "push_operand" "")
2853         (match_operand:DF 1 "register_operand" ""))]
2854   "!TARGET_64BIT && reload_completed && ANY_FP_REGNO_P (REGNO (operands[1]))"
2855   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -8)))
2856    (set (mem:DF (reg:SI 7)) (match_dup 1))]
2857   "")
2858
2859 (define_split
2860   [(set (match_operand:DF 0 "push_operand" "")
2861         (match_operand:DF 1 "register_operand" ""))]
2862   "TARGET_64BIT && reload_completed && ANY_FP_REGNO_P (REGNO (operands[1]))"
2863   [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -8)))
2864    (set (mem:DF (reg:DI 7)) (match_dup 1))]
2865   "")
2866
2867 (define_split
2868   [(set (match_operand:DF 0 "push_operand" "")
2869         (match_operand:DF 1 "general_operand" ""))]
2870   "reload_completed"
2871   [(const_int 0)]
2872   "ix86_split_long_move (operands); DONE;")
2873
2874 ;; Moving is usually shorter when only FP registers are used. This separate
2875 ;; movdf pattern avoids the use of integer registers for FP operations
2876 ;; when optimizing for size.
2877
2878 (define_insn "*movdf_nointeger"
2879   [(set (match_operand:DF 0 "nonimmediate_operand" "=f#Y,m,f#Y,*r,o,Y#f,Y#f,Y#f,m")
2880         (match_operand:DF 1 "general_operand" "fm#Y,f#Y,G,*roF,F*r,H,Y#f,YHm#f,Y#f"))]
2881   "(GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
2882    && (optimize_size || !TARGET_INTEGER_DFMODE_MOVES)
2883    && (reload_in_progress || reload_completed
2884        || GET_CODE (operands[1]) != CONST_DOUBLE
2885        || memory_operand (operands[0], DFmode))" 
2886 {
2887   switch (which_alternative)
2888     {
2889     case 0:
2890       if (REG_P (operands[1])
2891           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2892         return "fstp\t%y0";
2893       else if (STACK_TOP_P (operands[0]))
2894         return "fld%z1\t%y1";
2895       else
2896         return "fst\t%y0";
2897
2898     case 1:
2899       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2900         return "fstp%z0\t%y0";
2901       else
2902         return "fst%z0\t%y0";
2903
2904     case 2:
2905       switch (standard_80387_constant_p (operands[1]))
2906         {
2907         case 1:
2908           return "fldz";
2909         case 2:
2910           return "fld1";
2911         }
2912       abort();
2913
2914     case 3:
2915     case 4:
2916       return "#";
2917     case 5:
2918       return "pxor\t%0, %0";
2919     case 6:
2920       if (TARGET_PARTIAL_REG_DEPENDENCY)
2921         return "movapd\t{%1, %0|%0, %1}";
2922       else
2923         return "movsd\t{%1, %0|%0, %1}";
2924     case 7:
2925     case 8:
2926         return "movsd\t{%1, %0|%0, %1}";
2927
2928     default:
2929       abort();
2930     }
2931 }
2932   [(set_attr "type" "fmov,fmov,fmov,multi,multi,sse,sse,sse,sse")
2933    (set_attr "mode" "DF,DF,DF,SI,SI,TI,DF,DF,DF")])
2934
2935 (define_insn "*movdf_integer"
2936   [(set (match_operand:DF 0 "nonimmediate_operand" "=f#Yr,m,f#Yr,r#Yf,o,Y#rf,Y#rf,Y#rf,m")
2937         (match_operand:DF 1 "general_operand" "fm#Yr,f#Yr,G,roF#Yf,Fr#Yf,H,Y#rf,Ym#rf,Y#rf"))]
2938   "(GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
2939    && !optimize_size && TARGET_INTEGER_DFMODE_MOVES
2940    && (reload_in_progress || reload_completed
2941        || GET_CODE (operands[1]) != CONST_DOUBLE
2942        || memory_operand (operands[0], DFmode))" 
2943 {
2944   switch (which_alternative)
2945     {
2946     case 0:
2947       if (REG_P (operands[1])
2948           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2949         return "fstp\t%y0";
2950       else if (STACK_TOP_P (operands[0]))
2951         return "fld%z1\t%y1";
2952       else
2953         return "fst\t%y0";
2954
2955     case 1:
2956       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
2957         return "fstp%z0\t%y0";
2958       else
2959         return "fst%z0\t%y0";
2960
2961     case 2:
2962       switch (standard_80387_constant_p (operands[1]))
2963         {
2964         case 1:
2965           return "fldz";
2966         case 2:
2967           return "fld1";
2968         }
2969       abort();
2970
2971     case 3:
2972     case 4:
2973       return "#";
2974
2975     case 5:
2976       return "pxor\t%0, %0";
2977     case 6:
2978       if (TARGET_PARTIAL_REG_DEPENDENCY)
2979         return "movapd\t{%1, %0|%0, %1}";
2980       else
2981         return "movsd\t{%1, %0|%0, %1}";
2982     case 7:
2983     case 8:
2984       return "movsd\t{%1, %0|%0, %1}";
2985
2986     default:
2987       abort();
2988     }
2989 }
2990   [(set_attr "type" "fmov,fmov,fmov,multi,multi,sse,sse,sse,sse")
2991    (set_attr "mode" "DF,DF,DF,SI,SI,TI,DF,DF,DF")])
2992
2993 (define_split
2994   [(set (match_operand:DF 0 "nonimmediate_operand" "")
2995         (match_operand:DF 1 "general_operand" ""))]
2996   "reload_completed
2997    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
2998    && ! (ANY_FP_REG_P (operands[0]) || 
2999          (GET_CODE (operands[0]) == SUBREG
3000           && ANY_FP_REG_P (SUBREG_REG (operands[0]))))
3001    && ! (ANY_FP_REG_P (operands[1]) || 
3002          (GET_CODE (operands[1]) == SUBREG
3003           && ANY_FP_REG_P (SUBREG_REG (operands[1]))))"
3004   [(const_int 0)]
3005   "ix86_split_long_move (operands); DONE;")
3006
3007 (define_insn "*swapdf"
3008   [(set (match_operand:DF 0 "register_operand" "+f")
3009         (match_operand:DF 1 "register_operand" "+f"))
3010    (set (match_dup 1)
3011         (match_dup 0))]
3012   "reload_completed || !TARGET_SSE2"
3013 {
3014   if (STACK_TOP_P (operands[0]))
3015     return "fxch\t%1";
3016   else
3017     return "fxch\t%0";
3018 }
3019   [(set_attr "type" "fxch")
3020    (set_attr "mode" "DF")])
3021
3022 (define_expand "movxf"
3023   [(set (match_operand:XF 0 "nonimmediate_operand" "")
3024         (match_operand:XF 1 "general_operand" ""))]
3025   "!TARGET_64BIT"
3026   "ix86_expand_move (XFmode, operands); DONE;")
3027
3028 (define_expand "movtf"
3029   [(set (match_operand:TF 0 "nonimmediate_operand" "")
3030         (match_operand:TF 1 "general_operand" ""))]
3031   ""
3032   "ix86_expand_move (TFmode, operands); DONE;")
3033
3034 ;; Size of pushdf is 3 (for sub) + 2 (for fstp) + memory operand size.
3035 ;; Size of pushdf using integer insturctions is 3+3*memory operand size
3036 ;; Pushing using integer instructions is longer except for constants
3037 ;; and direct memory references.
3038 ;; (assuming that any given constant is pushed only once, but this ought to be
3039 ;;  handled elsewhere).
3040
3041 (define_insn "*pushxf_nointeger"
3042   [(set (match_operand:XF 0 "push_operand" "=X,X,X")
3043         (match_operand:XF 1 "general_no_elim_operand" "f,Fo,*r"))]
3044   "optimize_size && !TARGET_64BIT"
3045 {
3046   switch (which_alternative)
3047     {
3048     case 0:
3049       /* %%% We loose REG_DEAD notes for controling pops if we split late.  */
3050       operands[0] = gen_rtx_MEM (XFmode, stack_pointer_rtx);
3051       operands[2] = stack_pointer_rtx;
3052       operands[3] = GEN_INT (12);
3053       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3054         return "sub{l}\t{%3, %2|%2, %3}\;fstp%z0\t%y0";
3055       else
3056         return "sub{l}\t{%3, %2|%2, %3}\;fst%z0\t%y0";
3057
3058     case 1:
3059     case 2:
3060       return "#";
3061
3062     default:
3063       abort ();
3064     }
3065 }
3066   [(set_attr "type" "multi")
3067    (set_attr "mode" "XF,SI,SI")])
3068
3069 (define_insn "*pushtf_nointeger"
3070   [(set (match_operand:TF 0 "push_operand" "=<,<,<")
3071         (match_operand:TF 1 "general_no_elim_operand" "f,Fo,*r"))]
3072   "optimize_size"
3073 {
3074   switch (which_alternative)
3075     {
3076     case 0:
3077       /* %%% We loose REG_DEAD notes for controling pops if we split late.  */
3078       operands[0] = gen_rtx_MEM (XFmode, stack_pointer_rtx);
3079       operands[2] = stack_pointer_rtx;
3080       operands[3] = GEN_INT (16);
3081       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3082         return "sub{l}\t{%3, %2|%2, %3}\;fstp%z0\t%y0";
3083       else
3084         return "sub{l}\t{%3, %2|%2, %3}\;fst%z0\t%y0";
3085
3086     case 1:
3087     case 2:
3088       return "#";
3089
3090     default:
3091       abort ();
3092     }
3093 }
3094   [(set_attr "type" "multi")
3095    (set_attr "mode" "XF,SI,SI")])
3096
3097 (define_insn "*pushxf_integer"
3098   [(set (match_operand:XF 0 "push_operand" "=<,<")
3099         (match_operand:XF 1 "general_no_elim_operand" "f#r,ro#f"))]
3100   "!optimize_size && !TARGET_64BIT"
3101 {
3102   switch (which_alternative)
3103     {
3104     case 0:
3105       /* %%% We loose REG_DEAD notes for controling pops if we split late.  */
3106       operands[0] = gen_rtx_MEM (XFmode, stack_pointer_rtx);
3107       operands[2] = stack_pointer_rtx;
3108       operands[3] = GEN_INT (12);
3109       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3110         return "sub{l}\t{%3, %2|%2, %3}\;fstp%z0\t%y0";
3111       else
3112         return "sub{l}\t{%3, %2|%2, %3}\;fst%z0\t%y0";
3113
3114     case 1:
3115       return "#";
3116
3117     default:
3118       abort ();
3119     }
3120 }
3121   [(set_attr "type" "multi")
3122    (set_attr "mode" "XF,SI")])
3123
3124 (define_insn "*pushtf_integer"
3125   [(set (match_operand:TF 0 "push_operand" "=<,<")
3126         (match_operand:TF 1 "general_no_elim_operand" "f#r,rFo#f"))]
3127   "!optimize_size"
3128 {
3129   switch (which_alternative)
3130     {
3131     case 0:
3132       /* %%% We loose REG_DEAD notes for controling pops if we split late.  */
3133       operands[0] = gen_rtx_MEM (XFmode, stack_pointer_rtx);
3134       operands[2] = stack_pointer_rtx;
3135       operands[3] = GEN_INT (16);
3136       if (TARGET_64BIT)
3137         if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3138           return "sub{q}\t{%3, %2|%2, %3}\;fstp%z0\t%y0";
3139         else
3140           return "sub{q}\t{%3, %2|%2, %3}\;fst%z0\t%y0";
3141       else
3142         if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3143           return "sub{l}\t{%3, %2|%2, %3}\;fstp%z0\t%y0";
3144         else
3145           return "sub{l}\t{%3, %2|%2, %3}\;fst%z0\t%y0";
3146
3147     case 1:
3148       return "#";
3149
3150     default:
3151       abort ();
3152     }
3153 }
3154   [(set_attr "type" "multi")
3155    (set_attr "mode" "XF,SI")])
3156
3157 (define_split
3158   [(set (match_operand 0 "push_operand" "")
3159         (match_operand 1 "general_operand" ""))]
3160   "reload_completed
3161    && (GET_MODE (operands[0]) == XFmode
3162        || GET_MODE (operands[0]) == TFmode
3163        || GET_MODE (operands[0]) == DFmode)
3164    && (!REG_P (operands[1]) || !ANY_FP_REGNO_P (REGNO (operands[1])))"
3165   [(const_int 0)]
3166   "ix86_split_long_move (operands); DONE;")
3167
3168 (define_split
3169   [(set (match_operand:XF 0 "push_operand" "")
3170         (match_operand:XF 1 "register_operand" ""))]
3171   "!TARGET_64BIT && ANY_FP_REGNO_P (REGNO (operands[1]))"
3172   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -12)))
3173    (set (mem:XF (reg:SI 7)) (match_dup 1))])
3174
3175 (define_split
3176   [(set (match_operand:TF 0 "push_operand" "")
3177         (match_operand:TF 1 "register_operand" ""))]
3178   "!TARGET_64BIT && ANY_FP_REGNO_P (REGNO (operands[1]))"
3179   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -16)))
3180    (set (mem:TF (reg:SI 7)) (match_dup 1))])
3181
3182 (define_split
3183   [(set (match_operand:TF 0 "push_operand" "")
3184         (match_operand:TF 1 "register_operand" ""))]
3185   "TARGET_64BIT && ANY_FP_REGNO_P (REGNO (operands[1]))"
3186   [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -16)))
3187    (set (mem:TF (reg:DI 7)) (match_dup 1))])
3188
3189 ;; Do not use integer registers when optimizing for size
3190 (define_insn "*movxf_nointeger"
3191   [(set (match_operand:XF 0 "nonimmediate_operand" "=f,m,f,*r,o")
3192         (match_operand:XF 1 "general_operand" "fm,f,G,*roF,F*r"))]
3193   "(GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
3194    && !TARGET_64BIT
3195    && optimize_size
3196    && (reload_in_progress || reload_completed
3197        || GET_CODE (operands[1]) != CONST_DOUBLE
3198        || memory_operand (operands[0], XFmode))" 
3199 {
3200   switch (which_alternative)
3201     {
3202     case 0:
3203       if (REG_P (operands[1])
3204           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3205         return "fstp\t%y0";
3206       else if (STACK_TOP_P (operands[0]))
3207         return "fld%z1\t%y1";
3208       else
3209         return "fst\t%y0";
3210
3211     case 1:
3212       /* There is no non-popping store to memory for XFmode.  So if
3213          we need one, follow the store with a load.  */
3214       if (! find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3215         return "fstp%z0\t%y0\;fld%z0\t%y0";
3216       else
3217         return "fstp%z0\t%y0";
3218
3219     case 2:
3220       switch (standard_80387_constant_p (operands[1]))
3221         {
3222         case 1:
3223           return "fldz";
3224         case 2:
3225           return "fld1";
3226         }
3227       break;
3228
3229     case 3: case 4:
3230       return "#";
3231     }
3232   abort();
3233 }
3234   [(set_attr "type" "fmov,fmov,fmov,multi,multi")
3235    (set_attr "mode" "XF,XF,XF,SI,SI")])
3236
3237 (define_insn "*movtf_nointeger"
3238   [(set (match_operand:TF 0 "nonimmediate_operand" "=f,m,f,*r,o")
3239         (match_operand:TF 1 "general_operand" "fm,f,G,*roF,F*r"))]
3240   "(GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
3241    && optimize_size
3242    && (reload_in_progress || reload_completed
3243        || GET_CODE (operands[1]) != CONST_DOUBLE
3244        || memory_operand (operands[0], TFmode))" 
3245 {
3246   switch (which_alternative)
3247     {
3248     case 0:
3249       if (REG_P (operands[1])
3250           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3251         return "fstp\t%y0";
3252       else if (STACK_TOP_P (operands[0]))
3253         return "fld%z1\t%y1";
3254       else
3255         return "fst\t%y0";
3256
3257     case 1:
3258       /* There is no non-popping store to memory for XFmode.  So if
3259          we need one, follow the store with a load.  */
3260       if (! find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3261         return "fstp%z0\t%y0\;fld%z0\t%y0";
3262       else
3263         return "fstp%z0\t%y0";
3264
3265     case 2:
3266       switch (standard_80387_constant_p (operands[1]))
3267         {
3268         case 1:
3269           return "fldz";
3270         case 2:
3271           return "fld1";
3272         }
3273       break;
3274
3275     case 3: case 4:
3276       return "#";
3277     }
3278   abort();
3279 }
3280   [(set_attr "type" "fmov,fmov,fmov,multi,multi")
3281    (set_attr "mode" "XF,XF,XF,SI,SI")])
3282
3283 (define_insn "*movxf_integer"
3284   [(set (match_operand:XF 0 "nonimmediate_operand" "=f#r,m,f#r,r#f,o")
3285         (match_operand:XF 1 "general_operand" "fm#r,f#r,G,roF#f,Fr#f"))]
3286   "(GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
3287    && !TARGET_64BIT
3288    && !optimize_size
3289    && (reload_in_progress || reload_completed
3290        || GET_CODE (operands[1]) != CONST_DOUBLE
3291        || memory_operand (operands[0], XFmode))" 
3292 {
3293   switch (which_alternative)
3294     {
3295     case 0:
3296       if (REG_P (operands[1])
3297           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3298         return "fstp\t%y0";
3299       else if (STACK_TOP_P (operands[0]))
3300         return "fld%z1\t%y1";
3301       else
3302         return "fst\t%y0";
3303
3304     case 1:
3305       /* There is no non-popping store to memory for XFmode.  So if
3306          we need one, follow the store with a load.  */
3307       if (! find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3308         return "fstp%z0\t%y0\;fld%z0\t%y0";
3309       else
3310         return "fstp%z0\t%y0";
3311
3312     case 2:
3313       switch (standard_80387_constant_p (operands[1]))
3314         {
3315         case 1:
3316           return "fldz";
3317         case 2:
3318           return "fld1";
3319         }
3320       break;
3321
3322     case 3: case 4:
3323       return "#";
3324     }
3325   abort();
3326 }
3327   [(set_attr "type" "fmov,fmov,fmov,multi,multi")
3328    (set_attr "mode" "XF,XF,XF,SI,SI")])
3329
3330 (define_insn "*movtf_integer"
3331   [(set (match_operand:TF 0 "nonimmediate_operand" "=f#r,m,f#r,r#f,o")
3332         (match_operand:TF 1 "general_operand" "fm#r,f#r,G,roF#f,Fr#f"))]
3333   "(GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
3334    && !optimize_size
3335    && (reload_in_progress || reload_completed
3336        || GET_CODE (operands[1]) != CONST_DOUBLE
3337        || memory_operand (operands[0], TFmode))" 
3338 {
3339   switch (which_alternative)
3340     {
3341     case 0:
3342       if (REG_P (operands[1])
3343           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3344         return "fstp\t%y0";
3345       else if (STACK_TOP_P (operands[0]))
3346         return "fld%z1\t%y1";
3347       else
3348         return "fst\t%y0";
3349
3350     case 1:
3351       /* There is no non-popping store to memory for XFmode.  So if
3352          we need one, follow the store with a load.  */
3353       if (! find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3354         return "fstp%z0\t%y0\;fld%z0\t%y0";
3355       else
3356         return "fstp%z0\t%y0";
3357
3358     case 2:
3359       switch (standard_80387_constant_p (operands[1]))
3360         {
3361         case 1:
3362           return "fldz";
3363         case 2:
3364           return "fld1";
3365         }
3366       break;
3367
3368     case 3: case 4:
3369       return "#";
3370     }
3371   abort();
3372 }
3373   [(set_attr "type" "fmov,fmov,fmov,multi,multi")
3374    (set_attr "mode" "XF,XF,XF,SI,SI")])
3375
3376 (define_split
3377   [(set (match_operand 0 "nonimmediate_operand" "")
3378         (match_operand 1 "general_operand" ""))]
3379   "reload_completed
3380    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)
3381    && (GET_MODE (operands[0]) == XFmode || GET_MODE (operands[0]) == TFmode)
3382    && ! (ANY_FP_REG_P (operands[0]) || 
3383          (GET_CODE (operands[0]) == SUBREG
3384           && ANY_FP_REG_P (SUBREG_REG (operands[0]))))
3385    && ! (ANY_FP_REG_P (operands[1]) || 
3386          (GET_CODE (operands[1]) == SUBREG
3387           && ANY_FP_REG_P (SUBREG_REG (operands[1]))))"
3388   [(const_int 0)]
3389   "ix86_split_long_move (operands); DONE;")
3390
3391 (define_split
3392   [(set (match_operand 0 "register_operand" "")
3393         (match_operand 1 "memory_operand" ""))]
3394   "reload_completed
3395    && GET_CODE (operands[1]) == MEM
3396    && (GET_MODE (operands[0]) == XFmode || GET_MODE (operands[0]) == TFmode
3397        || GET_MODE (operands[0]) == SFmode || GET_MODE (operands[0]) == DFmode)
3398    && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
3399    && CONSTANT_POOL_ADDRESS_P (XEXP (operands[1], 0))
3400    && (!(SSE_REG_P (operands[0]) || 
3401          (GET_CODE (operands[0]) == SUBREG
3402           && SSE_REG_P (SUBREG_REG (operands[0]))))
3403        || standard_sse_constant_p (get_pool_constant (XEXP (operands[1], 0))))
3404    && (!(FP_REG_P (operands[0]) || 
3405          (GET_CODE (operands[0]) == SUBREG
3406           && FP_REG_P (SUBREG_REG (operands[0]))))
3407        || standard_80387_constant_p (get_pool_constant (XEXP (operands[1], 0))))"
3408   [(set (match_dup 0)
3409         (match_dup 1))]
3410   "operands[1] = get_pool_constant (XEXP (operands[1], 0));")
3411
3412 (define_insn "swapxf"
3413   [(set (match_operand:XF 0 "register_operand" "+f")
3414         (match_operand:XF 1 "register_operand" "+f"))
3415    (set (match_dup 1)
3416         (match_dup 0))]
3417   ""
3418 {
3419   if (STACK_TOP_P (operands[0]))
3420     return "fxch\t%1";
3421   else
3422     return "fxch\t%0";
3423 }
3424   [(set_attr "type" "fxch")
3425    (set_attr "mode" "XF")])
3426
3427 (define_insn "swaptf"
3428   [(set (match_operand:TF 0 "register_operand" "+f")
3429         (match_operand:TF 1 "register_operand" "+f"))
3430    (set (match_dup 1)
3431         (match_dup 0))]
3432   ""
3433 {
3434   if (STACK_TOP_P (operands[0]))
3435     return "fxch\t%1";
3436   else
3437     return "fxch\t%0";
3438 }
3439   [(set_attr "type" "fxch")
3440    (set_attr "mode" "XF")])
3441 \f
3442 ;; Zero extension instructions
3443
3444 (define_expand "zero_extendhisi2"
3445   [(set (match_operand:SI 0 "register_operand" "")
3446      (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "")))]
3447   ""
3448 {
3449   if (TARGET_ZERO_EXTEND_WITH_AND && !optimize_size)
3450     {
3451       operands[1] = force_reg (HImode, operands[1]);
3452       emit_insn (gen_zero_extendhisi2_and (operands[0], operands[1]));
3453       DONE;
3454     }
3455 })
3456
3457 (define_insn "zero_extendhisi2_and"
3458   [(set (match_operand:SI 0 "register_operand" "=r")
3459      (zero_extend:SI (match_operand:HI 1 "register_operand" "0")))
3460    (clobber (reg:CC 17))]
3461   "TARGET_ZERO_EXTEND_WITH_AND && !optimize_size"
3462   "#"
3463   [(set_attr "type" "alu1")
3464    (set_attr "mode" "SI")])
3465
3466 (define_split
3467   [(set (match_operand:SI 0 "register_operand" "")
3468         (zero_extend:SI (match_operand:HI 1 "register_operand" "")))
3469    (clobber (reg:CC 17))]
3470   "reload_completed && TARGET_ZERO_EXTEND_WITH_AND && !optimize_size"
3471   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (const_int 65535)))
3472               (clobber (reg:CC 17))])]
3473   "")
3474
3475 (define_insn "*zero_extendhisi2_movzwl"
3476   [(set (match_operand:SI 0 "register_operand" "=r")
3477      (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "rm")))]
3478   "!TARGET_ZERO_EXTEND_WITH_AND || optimize_size"
3479   "movz{wl|x}\t{%1, %0|%0, %1}"
3480   [(set_attr "type" "imovx")
3481    (set_attr "mode" "SI")])
3482
3483 (define_expand "zero_extendqihi2"
3484   [(parallel
3485     [(set (match_operand:HI 0 "register_operand" "")
3486        (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))
3487      (clobber (reg:CC 17))])]
3488   ""
3489   "")
3490
3491 (define_insn "*zero_extendqihi2_and"
3492   [(set (match_operand:HI 0 "register_operand" "=r,?&q")
3493      (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,qm")))
3494    (clobber (reg:CC 17))]
3495   "TARGET_ZERO_EXTEND_WITH_AND && !optimize_size"
3496   "#"
3497   [(set_attr "type" "alu1")
3498    (set_attr "mode" "HI")])
3499
3500 (define_insn "*zero_extendqihi2_movzbw_and"
3501   [(set (match_operand:HI 0 "register_operand" "=r,r")
3502      (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "qm,0")))
3503    (clobber (reg:CC 17))]
3504   "!TARGET_ZERO_EXTEND_WITH_AND || optimize_size"
3505   "#"
3506   [(set_attr "type" "imovx,alu1")
3507    (set_attr "mode" "HI")])
3508
3509 (define_insn "*zero_extendqihi2_movzbw"
3510   [(set (match_operand:HI 0 "register_operand" "=r")
3511      (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
3512   "(!TARGET_ZERO_EXTEND_WITH_AND || optimize_size) && reload_completed"
3513   "movz{bw|x}\t{%1, %0|%0, %1}"
3514   [(set_attr "type" "imovx")
3515    (set_attr "mode" "HI")])
3516
3517 ;; For the movzbw case strip only the clobber
3518 (define_split
3519   [(set (match_operand:HI 0 "register_operand" "")
3520         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))
3521    (clobber (reg:CC 17))]
3522   "reload_completed 
3523    && (!TARGET_ZERO_EXTEND_WITH_AND || optimize_size)
3524    && (!REG_P (operands[1]) || ANY_QI_REG_P (operands[1]))"
3525   [(set (match_operand:HI 0 "register_operand" "")
3526         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))])
3527
3528 ;; When source and destination does not overlap, clear destination
3529 ;; first and then do the movb
3530 (define_split
3531   [(set (match_operand:HI 0 "register_operand" "")
3532         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))
3533    (clobber (reg:CC 17))]
3534   "reload_completed
3535    && ANY_QI_REG_P (operands[0])
3536    && (TARGET_ZERO_EXTEND_WITH_AND && !optimize_size)
3537    && !reg_overlap_mentioned_p (operands[0], operands[1])"
3538   [(set (match_dup 0) (const_int 0))
3539    (set (strict_low_part (match_dup 2)) (match_dup 1))]
3540   "operands[2] = gen_lowpart (QImode, operands[0]);")
3541
3542 ;; Rest is handled by single and.
3543 (define_split
3544   [(set (match_operand:HI 0 "register_operand" "")
3545         (zero_extend:HI (match_operand:QI 1 "register_operand" "")))
3546    (clobber (reg:CC 17))]
3547   "reload_completed
3548    && true_regnum (operands[0]) == true_regnum (operands[1])"
3549   [(parallel [(set (match_dup 0) (and:HI (match_dup 0) (const_int 255)))
3550               (clobber (reg:CC 17))])]
3551   "")
3552
3553 (define_expand "zero_extendqisi2"
3554   [(parallel
3555     [(set (match_operand:SI 0 "register_operand" "")
3556        (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "")))
3557      (clobber (reg:CC 17))])]
3558   ""
3559   "")
3560
3561 (define_insn "*zero_extendqisi2_and"
3562   [(set (match_operand:SI 0 "register_operand" "=r,?&q")
3563      (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "0,qm")))
3564    (clobber (reg:CC 17))]
3565   "TARGET_ZERO_EXTEND_WITH_AND && !optimize_size"
3566   "#"
3567   [(set_attr "type" "alu1")
3568    (set_attr "mode" "SI")])
3569
3570 (define_insn "*zero_extendqisi2_movzbw_and"
3571   [(set (match_operand:SI 0 "register_operand" "=r,r")
3572      (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm,0")))
3573    (clobber (reg:CC 17))]
3574   "!TARGET_ZERO_EXTEND_WITH_AND || optimize_size"
3575   "#"
3576   [(set_attr "type" "imovx,alu1")
3577    (set_attr "mode" "SI")])
3578
3579 (define_insn "*zero_extendqisi2_movzbw"
3580   [(set (match_operand:SI 0 "register_operand" "=r")
3581      (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
3582   "(!TARGET_ZERO_EXTEND_WITH_AND || optimize_size) && reload_completed"
3583   "movz{bl|x}\t{%1, %0|%0, %1}"
3584   [(set_attr "type" "imovx")
3585    (set_attr "mode" "SI")])
3586
3587 ;; For the movzbl case strip only the clobber
3588 (define_split
3589   [(set (match_operand:SI 0 "register_operand" "")
3590         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "")))
3591    (clobber (reg:CC 17))]
3592   "reload_completed 
3593    && (!TARGET_ZERO_EXTEND_WITH_AND || optimize_size)
3594    && (!REG_P (operands[1]) || ANY_QI_REG_P (operands[1]))"
3595   [(set (match_dup 0)
3596         (zero_extend:SI (match_dup 1)))])
3597
3598 ;; When source and destination does not overlap, clear destination
3599 ;; first and then do the movb
3600 (define_split
3601   [(set (match_operand:SI 0 "register_operand" "")
3602         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "")))
3603    (clobber (reg:CC 17))]
3604   "reload_completed
3605    && ANY_QI_REG_P (operands[0])
3606    && (ANY_QI_REG_P (operands[1]) || GET_CODE (operands[1]) == MEM)
3607    && (TARGET_ZERO_EXTEND_WITH_AND && !optimize_size)
3608    && !reg_overlap_mentioned_p (operands[0], operands[1])"
3609   [(set (match_dup 0) (const_int 0))
3610    (set (strict_low_part (match_dup 2)) (match_dup 1))]
3611   "operands[2] = gen_lowpart (QImode, operands[0]);")
3612
3613 ;; Rest is handled by single and.
3614 (define_split
3615   [(set (match_operand:SI 0 "register_operand" "")
3616         (zero_extend:SI (match_operand:QI 1 "register_operand" "")))
3617    (clobber (reg:CC 17))]
3618   "reload_completed
3619    && true_regnum (operands[0]) == true_regnum (operands[1])"
3620   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (const_int 255)))
3621               (clobber (reg:CC 17))])]
3622   "")
3623
3624 ;; %%% Kill me once multi-word ops are sane.
3625 (define_expand "zero_extendsidi2"
3626   [(set (match_operand:DI 0 "register_operand" "=r")
3627      (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "rm")))]
3628   ""
3629   "if (!TARGET_64BIT)
3630      {
3631        emit_insn (gen_zero_extendsidi2_32 (operands[0], operands[1]));
3632        DONE;
3633      }
3634   ")
3635
3636 (define_insn "zero_extendsidi2_32"
3637   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,?r,?*o")
3638         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,rm,r")))
3639    (clobber (reg:CC 17))]
3640   "!TARGET_64BIT"
3641   "#"
3642   [(set_attr "mode" "SI")])
3643
3644 (define_insn "zero_extendsidi2_rex64"
3645   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,o")
3646      (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "rm,0")))]
3647   "TARGET_64BIT"
3648   "@
3649    mov\t{%k1, %k0|%k0, %k1}
3650    #"
3651   [(set_attr "type" "imovx,imov")
3652    (set_attr "mode" "SI,DI")])
3653
3654 (define_split
3655   [(set (match_operand:DI 0 "memory_operand" "")
3656      (zero_extend:DI (match_dup 0)))]
3657   ""
3658   [(set (match_dup 4) (const_int 0))]
3659   "split_di (&operands[0], 1, &operands[3], &operands[4]);")
3660
3661 (define_split 
3662   [(set (match_operand:DI 0 "register_operand" "")
3663         (zero_extend:DI (match_operand:SI 1 "register_operand" "")))
3664    (clobber (reg:CC 17))]
3665   "reload_completed && true_regnum (operands[0]) == true_regnum (operands[1])
3666    && !TARGET_64BIT"
3667   [(set (match_dup 4) (const_int 0))]
3668   "split_di (&operands[0], 1, &operands[3], &operands[4]);")
3669
3670 (define_split 
3671   [(set (match_operand:DI 0 "nonimmediate_operand" "")
3672         (zero_extend:DI (match_operand:SI 1 "general_operand" "")))
3673    (clobber (reg:CC 17))]
3674   "reload_completed && !TARGET_64BIT"
3675   [(set (match_dup 3) (match_dup 1))
3676    (set (match_dup 4) (const_int 0))]
3677   "split_di (&operands[0], 1, &operands[3], &operands[4]);")
3678
3679 (define_insn "zero_extendhidi2"
3680   [(set (match_operand:DI 0 "register_operand" "=r,r")
3681      (zero_extend:DI (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
3682   "TARGET_64BIT"
3683   "@
3684    movz{wl|x}\t{%1, %k0|%k0, %1} 
3685    movz{wq|x}\t{%1, %0|%0, %1}"
3686   [(set_attr "type" "imovx")
3687    (set_attr "mode" "SI,DI")])
3688
3689 (define_insn "zero_extendqidi2"
3690   [(set (match_operand:DI 0 "register_operand" "=r,r")
3691      (zero_extend:DI (match_operand:QI 1 "nonimmediate_operand" "Q,m")))]
3692   "TARGET_64BIT"
3693   "@
3694    movz{bl|x}\t{%1, %k0|%k0, %1} 
3695    movz{bq|x}\t{%1, %0|%0, %1}"
3696   [(set_attr "type" "imovx")
3697    (set_attr "mode" "SI,DI")])
3698 \f
3699 ;; Sign extension instructions
3700
3701 (define_expand "extendsidi2"
3702   [(parallel [(set (match_operand:DI 0 "register_operand" "")
3703                    (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
3704               (clobber (reg:CC 17))
3705               (clobber (match_scratch:SI 2 ""))])]
3706   ""
3707 {
3708   if (TARGET_64BIT)
3709     {
3710       emit_insn (gen_extendsidi2_rex64 (operands[0], operands[1]));
3711       DONE;
3712     }
3713 })
3714
3715 (define_insn "*extendsidi2_1"
3716   [(set (match_operand:DI 0 "nonimmediate_operand" "=*A,r,?r,?*o")
3717         (sign_extend:DI (match_operand:SI 1 "register_operand" "0,0,r,r")))
3718    (clobber (reg:CC 17))
3719    (clobber (match_scratch:SI 2 "=X,X,X,&r"))]
3720   "!TARGET_64BIT"
3721   "#")
3722
3723 (define_insn "extendsidi2_rex64"
3724   [(set (match_operand:DI 0 "register_operand" "=*a,r")
3725         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "*0,rm")))]
3726   "TARGET_64BIT"
3727   "@
3728    {cltq|cdqe}
3729    movs{lq|x}\t{%1,%0|%0, %1}"
3730   [(set_attr "type" "imovx")
3731    (set_attr "mode" "DI")
3732    (set_attr "prefix_0f" "0")
3733    (set_attr "modrm" "0,1")])
3734
3735 (define_insn "extendhidi2"
3736   [(set (match_operand:DI 0 "register_operand" "=r")
3737         (sign_extend:DI (match_operand:HI 1 "nonimmediate_operand" "rm")))]
3738   "TARGET_64BIT"
3739   "movs{wq|x}\t{%1,%0|%0, %1}"
3740   [(set_attr "type" "imovx")
3741    (set_attr "mode" "DI")])
3742
3743 (define_insn "extendqidi2"
3744   [(set (match_operand:DI 0 "register_operand" "=r")
3745         (sign_extend:DI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
3746   "TARGET_64BIT"
3747   "movs{bq|x}\t{%1,%0|%0, %1}"
3748    [(set_attr "type" "imovx")
3749     (set_attr "mode" "DI")])
3750
3751 ;; Extend to memory case when source register does die.
3752 (define_split 
3753   [(set (match_operand:DI 0 "memory_operand" "")
3754         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
3755    (clobber (reg:CC 17))
3756    (clobber (match_operand:SI 2 "register_operand" ""))]
3757   "(reload_completed
3758     && dead_or_set_p (insn, operands[1])
3759     && !reg_mentioned_p (operands[1], operands[0]))"
3760   [(set (match_dup 3) (match_dup 1))
3761    (parallel [(set (match_dup 1) (ashiftrt:SI (match_dup 1) (const_int 31)))
3762               (clobber (reg:CC 17))])
3763    (set (match_dup 4) (match_dup 1))]
3764   "split_di (&operands[0], 1, &operands[3], &operands[4]);")
3765
3766 ;; Extend to memory case when source register does not die.
3767 (define_split 
3768   [(set (match_operand:DI 0 "memory_operand" "")
3769         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
3770    (clobber (reg:CC 17))
3771    (clobber (match_operand:SI 2 "register_operand" ""))]
3772   "reload_completed"
3773   [(const_int 0)]
3774 {
3775   split_di (&operands[0], 1, &operands[3], &operands[4]);
3776
3777   emit_move_insn (operands[3], operands[1]);
3778
3779   /* Generate a cltd if possible and doing so it profitable.  */
3780   if (true_regnum (operands[1]) == 0
3781       && true_regnum (operands[2]) == 1
3782       && (optimize_size || TARGET_USE_CLTD))
3783     {
3784       emit_insn (gen_ashrsi3_31 (operands[2], operands[1], GEN_INT (31)));
3785     }
3786   else
3787     {
3788       emit_move_insn (operands[2], operands[1]);
3789       emit_insn (gen_ashrsi3_31 (operands[2], operands[2], GEN_INT (31)));
3790     }
3791   emit_move_insn (operands[4], operands[2]);
3792   DONE;
3793 })
3794
3795 ;; Extend to register case.  Optimize case where source and destination
3796 ;; registers match and cases where we can use cltd.
3797 (define_split 
3798   [(set (match_operand:DI 0 "register_operand" "")
3799         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
3800    (clobber (reg:CC 17))
3801    (clobber (match_scratch:SI 2 ""))]
3802   "reload_completed"
3803   [(const_int 0)]
3804 {
3805   split_di (&operands[0], 1, &operands[3], &operands[4]);
3806
3807   if (true_regnum (operands[3]) != true_regnum (operands[1]))
3808     emit_move_insn (operands[3], operands[1]);
3809
3810   /* Generate a cltd if possible and doing so it profitable.  */
3811   if (true_regnum (operands[3]) == 0
3812       && (optimize_size || TARGET_USE_CLTD))
3813     {
3814       emit_insn (gen_ashrsi3_31 (operands[4], operands[3], GEN_INT (31)));
3815       DONE;
3816     }
3817
3818   if (true_regnum (operands[4]) != true_regnum (operands[1]))
3819     emit_move_insn (operands[4], operands[1]);
3820
3821   emit_insn (gen_ashrsi3_31 (operands[4], operands[4], GEN_INT (31)));
3822   DONE;
3823 })
3824
3825 (define_insn "extendhisi2"
3826   [(set (match_operand:SI 0 "register_operand" "=*a,r")
3827         (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "*0,rm")))]
3828   ""
3829 {
3830   switch (get_attr_prefix_0f (insn))
3831     {
3832     case 0:
3833       return "{cwtl|cwde}";
3834     default:
3835       return "movs{wl|x}\t{%1,%0|%0, %1}";
3836     }
3837 }
3838   [(set_attr "type" "imovx")
3839    (set_attr "mode" "SI")
3840    (set (attr "prefix_0f")
3841      ;; movsx is short decodable while cwtl is vector decoded.
3842      (if_then_else (and (eq_attr "cpu" "!k6")
3843                         (eq_attr "alternative" "0"))
3844         (const_string "0")
3845         (const_string "1")))
3846    (set (attr "modrm")
3847      (if_then_else (eq_attr "prefix_0f" "0")
3848         (const_string "0")
3849         (const_string "1")))])
3850
3851 (define_insn "*extendhisi2_zext"
3852   [(set (match_operand:DI 0 "register_operand" "=*a,r")
3853         (zero_extend:DI
3854           (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "*0,rm"))))]
3855   "TARGET_64BIT"
3856 {
3857   switch (get_attr_prefix_0f (insn))
3858     {
3859     case 0:
3860       return "{cwtl|cwde}";
3861     default:
3862       return "movs{wl|x}\t{%1,%k0|%k0, %1}";
3863     }
3864 }
3865   [(set_attr "type" "imovx")
3866    (set_attr "mode" "SI")
3867    (set (attr "prefix_0f")
3868      ;; movsx is short decodable while cwtl is vector decoded.
3869      (if_then_else (and (eq_attr "cpu" "!k6")
3870                         (eq_attr "alternative" "0"))
3871         (const_string "0")
3872         (const_string "1")))
3873    (set (attr "modrm")
3874      (if_then_else (eq_attr "prefix_0f" "0")
3875         (const_string "0")
3876         (const_string "1")))])
3877
3878 (define_insn "extendqihi2"
3879   [(set (match_operand:HI 0 "register_operand" "=*a,r")
3880         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "*0,qm")))]
3881   ""
3882 {
3883   switch (get_attr_prefix_0f (insn))
3884     {
3885     case 0:
3886       return "{cbtw|cbw}";
3887     default:
3888       return "movs{bw|x}\t{%1,%0|%0, %1}";
3889     }
3890 }
3891   [(set_attr "type" "imovx")
3892    (set_attr "mode" "HI")
3893    (set (attr "prefix_0f")
3894      ;; movsx is short decodable while cwtl is vector decoded.
3895      (if_then_else (and (eq_attr "cpu" "!k6")
3896                         (eq_attr "alternative" "0"))
3897         (const_string "0")
3898         (const_string "1")))
3899    (set (attr "modrm")
3900      (if_then_else (eq_attr "prefix_0f" "0")
3901         (const_string "0")
3902         (const_string "1")))])
3903
3904 (define_insn "extendqisi2"
3905   [(set (match_operand:SI 0 "register_operand" "=r")
3906         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
3907   ""
3908   "movs{bl|x}\t{%1,%0|%0, %1}"
3909    [(set_attr "type" "imovx")
3910     (set_attr "mode" "SI")])
3911
3912 (define_insn "*extendqisi2_zext"
3913   [(set (match_operand:DI 0 "register_operand" "=r")
3914         (zero_extend:DI
3915           (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm"))))]
3916   "TARGET_64BIT"
3917   "movs{bl|x}\t{%1,%k0|%k0, %1}"
3918    [(set_attr "type" "imovx")
3919     (set_attr "mode" "SI")])
3920 \f
3921 ;; Conversions between float and double.
3922
3923 ;; These are all no-ops in the model used for the 80387.  So just
3924 ;; emit moves.
3925
3926 ;; %%% Kill these when call knows how to work out a DFmode push earlier. 
3927 (define_insn "*dummy_extendsfdf2"
3928   [(set (match_operand:DF 0 "push_operand" "=<")
3929         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "fY")))]
3930   "0"
3931   "#")
3932
3933 (define_split
3934   [(set (match_operand:DF 0 "push_operand" "")
3935         (float_extend:DF (match_operand:SF 1 "register_operand" "")))]
3936   "FP_REGNO_P (REGNO (operands[1])) && !TARGET_64BIT"
3937   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -8)))
3938    (set (mem:DF (reg:SI 7)) (float_extend:DF (match_dup 1)))])
3939
3940 (define_split
3941   [(set (match_operand:DF 0 "push_operand" "")
3942         (float_extend:DF (match_operand:SF 1 "register_operand" "")))]
3943   "FP_REGNO_P (REGNO (operands[1])) && TARGET_64BIT"
3944   [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -8)))
3945    (set (mem:DF (reg:DI 7)) (float_extend:DF (match_dup 1)))])
3946
3947 (define_insn "*dummy_extendsfxf2"
3948   [(set (match_operand:XF 0 "push_operand" "=<")
3949         (float_extend:XF (match_operand:SF 1 "nonimmediate_operand" "f")))]
3950   "0"
3951   "#")
3952
3953 (define_split
3954   [(set (match_operand:XF 0 "push_operand" "")
3955         (float_extend:XF (match_operand:SF 1 "register_operand" "")))]
3956   "FP_REGNO_P (REGNO (operands[1])) && !TARGET_64BIT"
3957   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -12)))
3958    (set (mem:XF (reg:SI 7)) (float_extend:XF (match_dup 1)))])
3959
3960 (define_insn "*dummy_extendsftf2"
3961   [(set (match_operand:TF 0 "push_operand" "=<")
3962         (float_extend:TF (match_operand:SF 1 "nonimmediate_operand" "f")))]
3963   "0"
3964   "#")
3965
3966 (define_split
3967   [(set (match_operand:TF 0 "push_operand" "")
3968         (float_extend:TF (match_operand:SF 1 "register_operand" "")))]
3969   "FP_REGNO_P (REGNO (operands[1])) && !TARGET_64BIT"
3970   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -16)))
3971    (set (mem:TF (reg:SI 7)) (float_extend:TF (match_dup 1)))])
3972
3973 (define_split
3974   [(set (match_operand:TF 0 "push_operand" "")
3975         (float_extend:TF (match_operand:SF 1 "register_operand" "")))]
3976   "FP_REGNO_P (REGNO (operands[1])) && TARGET_64BIT"
3977   [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -16)))
3978    (set (mem:DF (reg:DI 7)) (float_extend:TF (match_dup 1)))])
3979
3980 (define_insn "*dummy_extenddfxf2"
3981   [(set (match_operand:XF 0 "push_operand" "=<")
3982         (float_extend:XF (match_operand:DF 1 "nonimmediate_operand" "f")))]
3983   "0"
3984   "#")
3985
3986 (define_split
3987   [(set (match_operand:XF 0 "push_operand" "")
3988         (float_extend:XF (match_operand:DF 1 "register_operand" "")))]
3989   "FP_REGNO_P (REGNO (operands[1])) && !TARGET_64BIT"
3990   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -12)))
3991    (set (mem:DF (reg:SI 7)) (float_extend:XF (match_dup 1)))])
3992
3993 (define_insn "*dummy_extenddftf2"
3994   [(set (match_operand:TF 0 "push_operand" "=<")
3995         (float_extend:TF (match_operand:DF 1 "nonimmediate_operand" "f")))]
3996   "0"
3997   "#")
3998
3999 (define_split
4000   [(set (match_operand:TF 0 "push_operand" "")
4001         (float_extend:TF (match_operand:DF 1 "register_operand" "")))]
4002   "FP_REGNO_P (REGNO (operands[1])) && !TARGET_64BIT"
4003   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -16)))
4004    (set (mem:TF (reg:SI 7)) (float_extend:XF (match_dup 1)))])
4005
4006 (define_split
4007   [(set (match_operand:TF 0 "push_operand" "")
4008         (float_extend:TF (match_operand:DF 1 "register_operand" "")))]
4009   "FP_REGNO_P (REGNO (operands[1])) && TARGET_64BIT"
4010   [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -16)))
4011    (set (mem:TF (reg:DI 7)) (float_extend:TF (match_dup 1)))])
4012
4013 (define_expand "extendsfdf2"
4014   [(set (match_operand:DF 0 "nonimmediate_operand" "")
4015         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "")))]
4016   "TARGET_80387 || TARGET_SSE2"
4017 {
4018   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
4019     operands[1] = force_reg (SFmode, operands[1]);
4020 })
4021
4022 (define_insn "*extendsfdf2_1"
4023   [(set (match_operand:DF 0 "nonimmediate_operand" "=f#Y,mf#Y,Y#f")
4024         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "fm#Y,f#Y,mY#f")))]
4025   "(TARGET_80387 || TARGET_SSE2)
4026    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
4027 {
4028   switch (which_alternative)
4029     {
4030     case 0:
4031       if (REG_P (operands[1])
4032           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4033         return "fstp\t%y0";
4034       else if (STACK_TOP_P (operands[0]))
4035         return "fld%z1\t%y1";
4036       else
4037         return "fst\t%y0";
4038
4039     case 1:
4040       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4041         return "fstp%z0\t%y0";
4042
4043       else
4044         return "fst%z0\t%y0";
4045     case 2:
4046       return "cvtss2sd\t{%1, %0|%0, %1}";
4047
4048     default:
4049       abort ();
4050     }
4051 }
4052   [(set_attr "type" "fmov,fmov,sse")
4053    (set_attr "mode" "SF,XF,DF")])
4054
4055 (define_insn "*extendsfdf2_1_sse_only"
4056   [(set (match_operand:DF 0 "register_operand" "=Y")
4057         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "mY")))]
4058   "!TARGET_80387 && TARGET_SSE2
4059    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
4060   "cvtss2sd\t{%1, %0|%0, %1}"
4061   [(set_attr "type" "sse")
4062    (set_attr "mode" "DF")])
4063
4064 (define_expand "extendsfxf2"
4065   [(set (match_operand:XF 0 "nonimmediate_operand" "")
4066         (float_extend:XF (match_operand:SF 1 "nonimmediate_operand" "")))]
4067   "TARGET_80387 && !TARGET_64BIT"
4068 {
4069   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
4070     operands[1] = force_reg (SFmode, operands[1]);
4071 })
4072
4073 (define_insn "*extendsfxf2_1"
4074   [(set (match_operand:XF 0 "nonimmediate_operand" "=f,m")
4075         (float_extend:XF (match_operand:SF 1 "nonimmediate_operand" "fm,f")))]
4076   "TARGET_80387 && !TARGET_64BIT
4077    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
4078 {
4079   switch (which_alternative)
4080     {
4081     case 0:
4082       if (REG_P (operands[1])
4083           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4084         return "fstp\t%y0";
4085       else if (STACK_TOP_P (operands[0]))
4086         return "fld%z1\t%y1";
4087       else
4088         return "fst\t%y0";
4089
4090     case 1:
4091       /* There is no non-popping store to memory for XFmode.  So if
4092          we need one, follow the store with a load.  */
4093       if (! find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4094         return "fstp%z0\t%y0\n\tfld%z0\t%y0";
4095       else
4096         return "fstp%z0\t%y0";
4097
4098     default:
4099       abort ();
4100     }
4101 }
4102   [(set_attr "type" "fmov")
4103    (set_attr "mode" "SF,XF")])
4104
4105 (define_expand "extendsftf2"
4106   [(set (match_operand:TF 0 "nonimmediate_operand" "")
4107         (float_extend:TF (match_operand:SF 1 "nonimmediate_operand" "")))]
4108   "TARGET_80387"
4109 {
4110   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
4111     operands[1] = force_reg (SFmode, operands[1]);
4112 })
4113
4114 (define_insn "*extendsftf2_1"
4115   [(set (match_operand:TF 0 "nonimmediate_operand" "=f,m")
4116         (float_extend:TF (match_operand:SF 1 "nonimmediate_operand" "fm,f")))]
4117   "TARGET_80387
4118    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
4119 {
4120   switch (which_alternative)
4121     {
4122     case 0:
4123       if (REG_P (operands[1])
4124           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4125         return "fstp\t%y0";
4126       else if (STACK_TOP_P (operands[0]))
4127         return "fld%z1\t%y1";
4128       else
4129         return "fst\t%y0";
4130
4131     case 1:
4132       /* There is no non-popping store to memory for XFmode.  So if
4133          we need one, follow the store with a load.  */
4134       if (! find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4135         return "fstp%z0\t%y0\n\tfld%z0\t%y0";
4136       else
4137         return "fstp%z0\t%y0";
4138
4139     default:
4140       abort ();
4141     }
4142 }
4143   [(set_attr "type" "fmov")
4144    (set_attr "mode" "SF,XF")])
4145
4146 (define_expand "extenddfxf2"
4147   [(set (match_operand:XF 0 "nonimmediate_operand" "")
4148         (float_extend:XF (match_operand:DF 1 "nonimmediate_operand" "")))]
4149   "TARGET_80387 && !TARGET_64BIT"
4150 {
4151   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
4152     operands[1] = force_reg (DFmode, operands[1]);
4153 })
4154
4155 (define_insn "*extenddfxf2_1"
4156   [(set (match_operand:XF 0 "nonimmediate_operand" "=f,m")
4157         (float_extend:XF (match_operand:DF 1 "nonimmediate_operand" "fm,f")))]
4158   "TARGET_80387 && !TARGET_64BIT
4159    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
4160 {
4161   switch (which_alternative)
4162     {
4163     case 0:
4164       if (REG_P (operands[1])
4165           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4166         return "fstp\t%y0";
4167       else if (STACK_TOP_P (operands[0]))
4168         return "fld%z1\t%y1";
4169       else
4170         return "fst\t%y0";
4171
4172     case 1:
4173       /* There is no non-popping store to memory for XFmode.  So if
4174          we need one, follow the store with a load.  */
4175       if (! find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4176         return "fstp%z0\t%y0\n\tfld%z0\t%y0";
4177       else
4178         return "fstp%z0\t%y0";
4179
4180     default:
4181       abort ();
4182     }
4183 }
4184   [(set_attr "type" "fmov")
4185    (set_attr "mode" "DF,XF")])
4186
4187 (define_expand "extenddftf2"
4188   [(set (match_operand:TF 0 "nonimmediate_operand" "")
4189         (float_extend:TF (match_operand:DF 1 "nonimmediate_operand" "")))]
4190   "TARGET_80387"
4191 {
4192   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
4193     operands[1] = force_reg (DFmode, operands[1]);
4194 })
4195
4196 (define_insn "*extenddftf2_1"
4197   [(set (match_operand:TF 0 "nonimmediate_operand" "=f,m")
4198         (float_extend:TF (match_operand:DF 1 "nonimmediate_operand" "fm,f")))]
4199   "TARGET_80387
4200    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
4201 {
4202   switch (which_alternative)
4203     {
4204     case 0:
4205       if (REG_P (operands[1])
4206           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4207         return "fstp\t%y0";
4208       else if (STACK_TOP_P (operands[0]))
4209         return "fld%z1\t%y1";
4210       else
4211         return "fst\t%y0";
4212
4213     case 1:
4214       /* There is no non-popping store to memory for XFmode.  So if
4215          we need one, follow the store with a load.  */
4216       if (! find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4217         return "fstp%z0\t%y0\n\tfld%z0\t%y0";
4218       else
4219         return "fstp%z0\t%y0";
4220
4221     default:
4222       abort ();
4223     }
4224 }
4225   [(set_attr "type" "fmov")
4226    (set_attr "mode" "DF,XF")])
4227
4228 ;; %%% This seems bad bad news.
4229 ;; This cannot output into an f-reg because there is no way to be sure
4230 ;; of truncating in that case.  Otherwise this is just like a simple move
4231 ;; insn.  So we pretend we can output to a reg in order to get better
4232 ;; register preferencing, but we really use a stack slot.
4233
4234 (define_expand "truncdfsf2"
4235   [(parallel [(set (match_operand:SF 0 "nonimmediate_operand" "")
4236                    (float_truncate:SF
4237                     (match_operand:DF 1 "register_operand" "")))
4238               (clobber (match_dup 2))])]
4239   "TARGET_80387 || TARGET_SSE2"
4240   "
4241    if (TARGET_80387)
4242      operands[2] = assign_386_stack_local (SFmode, 0);
4243    else
4244      {
4245         emit_insn (gen_truncdfsf2_sse_only (operands[0], operands[1]));
4246         DONE;
4247      }
4248 ")
4249
4250 (define_insn "*truncdfsf2_1"
4251   [(set (match_operand:SF 0 "nonimmediate_operand" "=m,?f#rx,?r#fx,?x#rf")
4252         (float_truncate:SF
4253          (match_operand:DF 1 "register_operand" "f,f,f,f")))
4254    (clobber (match_operand:SF 2 "memory_operand" "=X,m,m,m"))]
4255   "TARGET_80387 && !TARGET_SSE2"
4256 {
4257   switch (which_alternative)
4258     {
4259     case 0:
4260       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4261         return "fstp%z0\t%y0";
4262       else
4263         return "fst%z0\t%y0";
4264     default:
4265       abort ();
4266     }
4267 }
4268   [(set_attr "type" "fmov,multi,multi,multi")
4269    (set_attr "mode" "SF,SF,SF,SF")])
4270
4271 (define_insn "*truncdfsf2_1_sse"
4272   [(set (match_operand:SF 0 "nonimmediate_operand" "=*!m,?f#rx,?r#fx,?x#rf,Y")
4273         (float_truncate:SF
4274          (match_operand:DF 1 "nonimmediate_operand" "f,f,f,f,mY")))
4275    (clobber (match_operand:SF 2 "memory_operand" "=X,m,m,m,X"))]
4276   "TARGET_80387 && TARGET_SSE2"
4277 {
4278   switch (which_alternative)
4279     {
4280     case 0:
4281       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4282         return "fstp%z0\t%y0";
4283       else
4284         return "fst%z0\t%y0";
4285     case 4:
4286       return "cvtsd2ss\t{%1, %0|%0, %1}";
4287     default:
4288       abort ();
4289     }
4290 }
4291   [(set_attr "type" "fmov,multi,multi,multi,sse")
4292    (set_attr "mode" "SF,SF,SF,SF,DF")])
4293
4294 (define_insn "*truncdfsf2_2"
4295   [(set (match_operand:SF 0 "nonimmediate_operand" "=Y,!m")
4296         (float_truncate:SF
4297          (match_operand:DF 1 "nonimmediate_operand" "mY,f")))]
4298   "TARGET_80387 && TARGET_SSE2
4299    && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)"
4300 {
4301   switch (which_alternative)
4302     {
4303     case 0:
4304       return "cvtsd2ss\t{%1, %0|%0, %1}";
4305     case 1:
4306       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4307         return "fstp%z0\t%y0";
4308       else
4309         return "fst%z0\t%y0";
4310     default:
4311       abort ();
4312     }
4313 }
4314   [(set_attr "type" "sse,fmov")
4315    (set_attr "mode" "DF,SF")])
4316
4317 (define_insn "truncdfsf2_3"
4318   [(set (match_operand:SF 0 "memory_operand" "=m")
4319         (float_truncate:SF
4320          (match_operand:DF 1 "register_operand" "f")))]
4321   "TARGET_80387"
4322 {
4323   if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4324     return "fstp%z0\t%y0";
4325   else
4326     return "fst%z0\t%y0";
4327 }
4328   [(set_attr "type" "fmov")
4329    (set_attr "mode" "SF")])
4330
4331 (define_insn "truncdfsf2_sse_only"
4332   [(set (match_operand:SF 0 "register_operand" "=Y")
4333         (float_truncate:SF
4334          (match_operand:DF 1 "nonimmediate_operand" "mY")))]
4335   "!TARGET_80387 && TARGET_SSE2"
4336   "cvtsd2ss\t{%1, %0|%0, %1}"
4337   [(set_attr "type" "sse")
4338    (set_attr "mode" "DF")])
4339
4340 (define_split
4341   [(set (match_operand:SF 0 "memory_operand" "")
4342         (float_truncate:SF
4343          (match_operand:DF 1 "register_operand" "")))
4344    (clobber (match_operand:SF 2 "memory_operand" ""))]
4345   "TARGET_80387"
4346   [(set (match_dup 0) (float_truncate:SF (match_dup 1)))]
4347   "")
4348
4349 (define_split
4350   [(set (match_operand:SF 0 "nonimmediate_operand" "")
4351         (float_truncate:SF
4352          (match_operand:DF 1 "nonimmediate_operand" "")))
4353    (clobber (match_operand 2 "" ""))]
4354   "TARGET_80387 && reload_completed
4355    && !FP_REG_P (operands[0]) && !FP_REG_P (operands[1])"
4356   [(set (match_dup 0) (float_truncate:SF (match_dup 1)))]
4357   "")
4358
4359 (define_split
4360   [(set (match_operand:SF 0 "register_operand" "")
4361         (float_truncate:SF
4362          (match_operand:DF 1 "register_operand" "")))
4363    (clobber (match_operand:SF 2 "memory_operand" ""))]
4364   "TARGET_80387 && reload_completed
4365    && FP_REG_P (operands[1])"
4366   [(set (match_dup 2) (float_truncate:SF (match_dup 1)))
4367    (set (match_dup 0) (match_dup 2))]
4368   "")
4369
4370 (define_expand "truncxfsf2"
4371   [(parallel [(set (match_operand:SF 0 "nonimmediate_operand" "")
4372                    (float_truncate:SF
4373                     (match_operand:XF 1 "register_operand" "")))
4374               (clobber (match_dup 2))])]
4375   "TARGET_80387 && !TARGET_64BIT"
4376   "operands[2] = assign_386_stack_local (SFmode, 0);")
4377
4378 (define_insn "*truncxfsf2_1"
4379   [(set (match_operand:SF 0 "nonimmediate_operand" "=m,?f#rx,?r#fx,?x#rf")
4380         (float_truncate:SF
4381          (match_operand:XF 1 "register_operand" "f,f,f,f")))
4382    (clobber (match_operand:SF 2 "memory_operand" "=X,m,m,m"))]
4383   "TARGET_80387 && !TARGET_64BIT"
4384 {
4385   switch (which_alternative)
4386     {
4387     case 0:
4388       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4389         return "fstp%z0\t%y0";
4390       else
4391         return "fst%z0\t%y0";
4392     default:
4393       abort();
4394     }
4395 }
4396   [(set_attr "type" "fmov,multi,multi,multi")
4397    (set_attr "mode" "SF")])
4398
4399 (define_insn "*truncxfsf2_2"
4400   [(set (match_operand:SF 0 "memory_operand" "=m")
4401         (float_truncate:SF
4402          (match_operand:XF 1 "register_operand" "f")))]
4403   "TARGET_80387 && !TARGET_64BIT"
4404 {
4405   if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4406     return "fstp%z0\t%y0";
4407   else
4408     return "fst%z0\t%y0";
4409 }
4410   [(set_attr "type" "fmov")
4411    (set_attr "mode" "SF")])
4412
4413 (define_split
4414   [(set (match_operand:SF 0 "memory_operand" "")
4415         (float_truncate:SF
4416          (match_operand:XF 1 "register_operand" "")))
4417    (clobber (match_operand:SF 2 "memory_operand" ""))]
4418   "TARGET_80387"
4419   [(set (match_dup 0) (float_truncate:SF (match_dup 1)))]
4420   "")
4421
4422 (define_split
4423   [(set (match_operand:SF 0 "register_operand" "")
4424         (float_truncate:SF
4425          (match_operand:XF 1 "register_operand" "")))
4426    (clobber (match_operand:SF 2 "memory_operand" ""))]
4427   "TARGET_80387 && reload_completed"
4428   [(set (match_dup 2) (float_truncate:SF (match_dup 1)))
4429    (set (match_dup 0) (match_dup 2))]
4430   "")
4431
4432 (define_expand "trunctfsf2"
4433   [(parallel [(set (match_operand:SF 0 "nonimmediate_operand" "")
4434                    (float_truncate:SF
4435                     (match_operand:TF 1 "register_operand" "")))
4436               (clobber (match_dup 2))])]
4437   "TARGET_80387"
4438   "operands[2] = assign_386_stack_local (SFmode, 0);")
4439
4440 (define_insn "*trunctfsf2_1"
4441   [(set (match_operand:SF 0 "nonimmediate_operand" "=m,?f#rx,?r#fx,?x#rf")
4442         (float_truncate:SF
4443          (match_operand:TF 1 "register_operand" "f,f,f,f")))
4444    (clobber (match_operand:SF 2 "memory_operand" "=X,m,m,m"))]
4445   "TARGET_80387"
4446 {
4447   switch (which_alternative)
4448     {
4449     case 0:
4450       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4451         return "fstp%z0\t%y0";
4452       else
4453         return "fst%z0\t%y0";
4454     default:
4455       abort();
4456     }
4457 }
4458   [(set_attr "type" "fmov,multi,multi,multi")
4459    (set_attr "mode" "SF")])
4460
4461 (define_insn "*trunctfsf2_2"
4462   [(set (match_operand:SF 0 "memory_operand" "=m")
4463         (float_truncate:SF
4464          (match_operand:TF 1 "register_operand" "f")))]
4465   "TARGET_80387"
4466 {
4467   if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4468     return "fstp%z0\t%y0";
4469   else
4470     return "fst%z0\t%y0";
4471 }
4472   [(set_attr "type" "fmov")
4473    (set_attr "mode" "SF")])
4474
4475 (define_split
4476   [(set (match_operand:SF 0 "memory_operand" "")
4477         (float_truncate:SF
4478          (match_operand:TF 1 "register_operand" "")))
4479    (clobber (match_operand:SF 2 "memory_operand" ""))]
4480   "TARGET_80387"
4481   [(set (match_dup 0) (float_truncate:SF (match_dup 1)))]
4482   "")
4483
4484 (define_split
4485   [(set (match_operand:SF 0 "register_operand" "")
4486         (float_truncate:SF
4487          (match_operand:TF 1 "register_operand" "")))
4488    (clobber (match_operand:SF 2 "memory_operand" ""))]
4489   "TARGET_80387 && reload_completed"
4490   [(set (match_dup 2) (float_truncate:SF (match_dup 1)))
4491    (set (match_dup 0) (match_dup 2))]
4492   "")
4493
4494
4495 (define_expand "truncxfdf2"
4496   [(parallel [(set (match_operand:DF 0 "nonimmediate_operand" "")
4497                    (float_truncate:DF
4498                     (match_operand:XF 1 "register_operand" "")))
4499               (clobber (match_dup 2))])]
4500   "TARGET_80387 && !TARGET_64BIT"
4501   "operands[2] = assign_386_stack_local (DFmode, 0);")
4502
4503 (define_insn "*truncxfdf2_1"
4504   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,?f#rY,?r#fY,?Y#rf")
4505         (float_truncate:DF
4506          (match_operand:XF 1 "register_operand" "f,f,f,f")))
4507    (clobber (match_operand:DF 2 "memory_operand" "=X,m,m,m"))]
4508   "TARGET_80387 && !TARGET_64BIT"
4509 {
4510   switch (which_alternative)
4511     {
4512     case 0:
4513       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4514         return "fstp%z0\t%y0";
4515       else
4516         return "fst%z0\t%y0";
4517     default:
4518       abort();
4519     }
4520   abort ();
4521 }
4522   [(set_attr "type" "fmov,multi,multi,multi")
4523    (set_attr "mode" "DF")])
4524
4525 (define_insn "*truncxfdf2_2"
4526   [(set (match_operand:DF 0 "memory_operand" "=m")
4527         (float_truncate:DF
4528           (match_operand:XF 1 "register_operand" "f")))]
4529   "TARGET_80387 && !TARGET_64BIT"
4530 {
4531   if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4532     return "fstp%z0\t%y0";
4533   else
4534     return "fst%z0\t%y0";
4535 }
4536   [(set_attr "type" "fmov")
4537    (set_attr "mode" "DF")])
4538
4539 (define_split
4540   [(set (match_operand:DF 0 "memory_operand" "")
4541         (float_truncate:DF
4542          (match_operand:XF 1 "register_operand" "")))
4543    (clobber (match_operand:DF 2 "memory_operand" ""))]
4544   "TARGET_80387"
4545   [(set (match_dup 0) (float_truncate:DF (match_dup 1)))]
4546   "")
4547
4548 (define_split
4549   [(set (match_operand:DF 0 "register_operand" "")
4550         (float_truncate:DF
4551          (match_operand:XF 1 "register_operand" "")))
4552    (clobber (match_operand:DF 2 "memory_operand" ""))]
4553   "TARGET_80387 && reload_completed"
4554   [(set (match_dup 2) (float_truncate:DF (match_dup 1)))
4555    (set (match_dup 0) (match_dup 2))]
4556   "")
4557
4558 (define_expand "trunctfdf2"
4559   [(parallel [(set (match_operand:DF 0 "nonimmediate_operand" "")
4560                    (float_truncate:DF
4561                     (match_operand:TF 1 "register_operand" "")))
4562               (clobber (match_dup 2))])]
4563   "TARGET_80387"
4564   "operands[2] = assign_386_stack_local (DFmode, 0);")
4565
4566 (define_insn "*trunctfdf2_1"
4567   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,?f#rY,?r#fY,?Y#rf")
4568         (float_truncate:DF
4569          (match_operand:TF 1 "register_operand" "f,f,f,f")))
4570    (clobber (match_operand:DF 2 "memory_operand" "=X,m,m,m"))]
4571   "TARGET_80387"
4572 {
4573   switch (which_alternative)
4574     {
4575     case 0:
4576       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4577         return "fstp%z0\t%y0";
4578       else
4579         return "fst%z0\t%y0";
4580     default:
4581       abort();
4582     }
4583   abort ();
4584 }
4585   [(set_attr "type" "fmov,multi,multi,multi")
4586    (set_attr "mode" "DF")])
4587
4588         (define_insn "*trunctfdf2_2"
4589   [(set (match_operand:DF 0 "memory_operand" "=m")
4590         (float_truncate:DF
4591           (match_operand:TF 1 "register_operand" "f")))]
4592   "TARGET_80387"
4593 {
4594   if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4595     return "fstp%z0\t%y0";
4596   else
4597     return "fst%z0\t%y0";
4598 }
4599   [(set_attr "type" "fmov")
4600    (set_attr "mode" "DF")])
4601
4602 (define_split
4603   [(set (match_operand:DF 0 "memory_operand" "")
4604         (float_truncate:DF
4605          (match_operand:TF 1 "register_operand" "")))
4606    (clobber (match_operand:DF 2 "memory_operand" ""))]
4607   "TARGET_80387"
4608   [(set (match_dup 0) (float_truncate:DF (match_dup 1)))]
4609   "")
4610
4611 (define_split
4612   [(set (match_operand:DF 0 "register_operand" "")
4613         (float_truncate:DF
4614          (match_operand:TF 1 "register_operand" "")))
4615    (clobber (match_operand:DF 2 "memory_operand" ""))]
4616   "TARGET_80387 && reload_completed"
4617   [(set (match_dup 2) (float_truncate:DF (match_dup 1)))
4618    (set (match_dup 0) (match_dup 2))]
4619   "")
4620
4621 \f
4622 ;; %%% Break up all these bad boys.
4623
4624 ;; Signed conversion to DImode.
4625
4626 (define_expand "fix_truncxfdi2"
4627   [(set (match_operand:DI 0 "nonimmediate_operand" "")
4628         (fix:DI (match_operand:XF 1 "register_operand" "")))]
4629   "TARGET_80387 && !TARGET_64BIT"
4630   "")
4631
4632 (define_expand "fix_trunctfdi2"
4633   [(set (match_operand:DI 0 "nonimmediate_operand" "")
4634         (fix:DI (match_operand:TF 1 "register_operand" "")))]
4635   "TARGET_80387"
4636   "")
4637
4638 (define_expand "fix_truncdfdi2"
4639   [(set (match_operand:DI 0 "nonimmediate_operand" "")
4640         (fix:DI (match_operand:DF 1 "register_operand" "")))]
4641   "TARGET_80387 || (TARGET_SSE2 && TARGET_64BIT)"
4642 {
4643   if (TARGET_SSE2 && TARGET_64BIT)
4644    {
4645      rtx out = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (DImode);
4646      emit_insn (gen_fix_truncdfdi_sse (out, operands[1]));
4647      if (out != operands[0])
4648         emit_move_insn (operands[0], out);
4649      DONE;
4650    }
4651 })
4652
4653 (define_expand "fix_truncsfdi2"
4654   [(set (match_operand:DI 0 "nonimmediate_operand" "")
4655         (fix:DI (match_operand:SF 1 "register_operand" "")))]
4656   "TARGET_80387 || (TARGET_SSE && TARGET_64BIT)"
4657 {
4658   if (TARGET_SSE && TARGET_64BIT)
4659    {
4660      rtx out = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (DImode);
4661      emit_insn (gen_fix_truncsfdi_sse (out, operands[1]));
4662      if (out != operands[0])
4663         emit_move_insn (operands[0], out);
4664      DONE;
4665    }
4666 })
4667
4668 ;; See the comments in i386.h near OPTIMIZE_MODE_SWITCHING for the description
4669 ;; of the machinery.
4670 (define_insn_and_split "*fix_truncdi_1"
4671   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r")
4672         (fix:DI (match_operand 1 "register_operand" "f,f")))]
4673   "TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[1]))
4674    && !reload_completed && !reload_in_progress
4675    && (!SSE_FLOAT_MODE_P (GET_MODE (operands[1])) || !TARGET_64BIT)"
4676   "#"
4677   ""
4678   [(const_int 0)]
4679 {
4680   operands[2] = assign_386_stack_local (HImode, 1);
4681   operands[3] = assign_386_stack_local (HImode, 2);
4682   if (memory_operand (operands[0], VOIDmode))
4683     emit_insn (gen_fix_truncdi_memory (operands[0], operands[1],
4684                                        operands[2], operands[3]));
4685   else
4686     {
4687       operands[4] = assign_386_stack_local (DImode, 0);
4688       emit_insn (gen_fix_truncdi_nomemory (operands[0], operands[1],
4689                                            operands[2], operands[3],
4690                                            operands[4]));
4691     }
4692   DONE;
4693 }
4694   [(set_attr "type" "fistp")])
4695
4696 (define_insn "fix_truncdi_nomemory"
4697   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r")
4698         (fix:DI (match_operand 1 "register_operand" "f,f")))
4699    (use (match_operand:HI 2 "memory_operand" "m,m"))
4700    (use (match_operand:HI 3 "memory_operand" "m,m"))
4701    (clobber (match_operand:DI 4 "memory_operand" "=m,m"))
4702    (clobber (match_scratch:DF 5 "=&1f,&1f"))]
4703   "TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[1]))
4704    && (!SSE_FLOAT_MODE_P (GET_MODE (operands[1])) || !TARGET_64BIT)"
4705   "#"
4706   [(set_attr "type" "fistp")])
4707
4708 (define_insn "fix_truncdi_memory"
4709   [(set (match_operand:DI 0 "memory_operand" "=m")
4710         (fix:DI (match_operand 1 "register_operand" "f")))
4711    (use (match_operand:HI 2 "memory_operand" "m"))
4712    (use (match_operand:HI 3 "memory_operand" "m"))
4713    (clobber (match_scratch:DF 4 "=&1f"))]
4714   "TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[1]))
4715    && (!SSE_FLOAT_MODE_P (GET_MODE (operands[1])) || !TARGET_64BIT)"
4716   "* operands[5] = operands[4]; return output_fix_trunc (insn, operands);"
4717   [(set_attr "type" "fistp")])
4718
4719 (define_split 
4720   [(set (match_operand:DI 0 "register_operand" "")
4721         (fix:DI (match_operand 1 "register_operand" "")))
4722    (use (match_operand:HI 2 "memory_operand" ""))
4723    (use (match_operand:HI 3 "memory_operand" ""))
4724    (clobber (match_operand:DI 4 "memory_operand" ""))
4725    (clobber (match_scratch 5 ""))]
4726   "reload_completed"
4727   [(parallel [(set (match_dup 4) (fix:DI (match_dup 1)))
4728               (use (match_dup 2))
4729               (use (match_dup 3))
4730               (clobber (match_dup 5))])
4731    (set (match_dup 0) (match_dup 4))]
4732   "")
4733
4734 (define_split 
4735   [(set (match_operand:DI 0 "memory_operand" "")
4736         (fix:DI (match_operand 1 "register_operand" "")))
4737    (use (match_operand:HI 2 "memory_operand" ""))
4738    (use (match_operand:HI 3 "memory_operand" ""))
4739    (clobber (match_operand:DI 4 "memory_operand" ""))
4740    (clobber (match_scratch 5 ""))]
4741   "reload_completed"
4742   [(parallel [(set (match_dup 0) (fix:DI (match_dup 1)))
4743               (use (match_dup 2))
4744               (use (match_dup 3))
4745               (clobber (match_dup 5))])]
4746   "")
4747
4748 ;; When SSE available, it is always faster to use it!
4749 (define_insn "fix_truncsfdi_sse"
4750   [(set (match_operand:DI 0 "register_operand" "=r")
4751         (fix:DI (match_operand:SF 1 "nonimmediate_operand" "xm")))]
4752   "TARGET_SSE && TARGET_64BIT"
4753   "cvttss2si{q}\t{%1, %0|%0, %1}"
4754   [(set_attr "type" "sse")])
4755
4756 (define_insn "fix_truncdfdi_sse"
4757   [(set (match_operand:DI 0 "register_operand" "=r")
4758         (fix:DI (match_operand:DF 1 "nonimmediate_operand" "Ym")))]
4759   "TARGET_SSE2 && TARGET_64BIT"
4760   "cvttsd2si{q}\t{%1, %0|%0, %1}"
4761   [(set_attr "type" "sse")])
4762
4763 ;; Signed conversion to SImode.
4764
4765 (define_expand "fix_truncxfsi2"
4766   [(set (match_operand:SI 0 "nonimmediate_operand" "")
4767         (fix:SI (match_operand:XF 1 "register_operand" "")))]
4768   "TARGET_80387 && !TARGET_64BIT"
4769   "")
4770
4771 (define_expand "fix_trunctfsi2"
4772   [(set (match_operand:SI 0 "nonimmediate_operand" "")
4773         (fix:SI (match_operand:TF 1 "register_operand" "")))]
4774   "TARGET_80387"
4775   "")
4776
4777 (define_expand "fix_truncdfsi2"
4778   [(set (match_operand:SI 0 "nonimmediate_operand" "")
4779         (fix:SI (match_operand:DF 1 "register_operand" "")))]
4780   "TARGET_80387 || TARGET_SSE2"
4781 {
4782   if (TARGET_SSE2)
4783    {
4784      rtx out = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (SImode);
4785      emit_insn (gen_fix_truncdfsi_sse (out, operands[1]));
4786      if (out != operands[0])
4787         emit_move_insn (operands[0], out);
4788      DONE;
4789    }
4790 })
4791
4792 (define_expand "fix_truncsfsi2"
4793   [(set (match_operand:SI 0 "nonimmediate_operand" "")
4794         (fix:SI (match_operand:SF 1 "register_operand" "")))]
4795   "TARGET_80387 || TARGET_SSE"
4796 {
4797   if (TARGET_SSE)
4798    {
4799      rtx out = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (SImode);
4800      emit_insn (gen_fix_truncsfsi_sse (out, operands[1]));
4801      if (out != operands[0])
4802         emit_move_insn (operands[0], out);
4803      DONE;
4804    }
4805 })
4806
4807 ;; See the comments in i386.h near OPTIMIZE_MODE_SWITCHING for the description
4808 ;; of the machinery.
4809 (define_insn_and_split "*fix_truncsi_1"
4810   [(set (match_operand:SI 0 "nonimmediate_operand" "=m,?r")
4811         (fix:SI (match_operand 1 "register_operand" "f,f")))]
4812   "TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[1]))
4813    && !reload_completed && !reload_in_progress
4814    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
4815   "#"
4816   ""
4817   [(const_int 0)]
4818 {
4819   operands[2] = assign_386_stack_local (HImode, 1);
4820   operands[3] = assign_386_stack_local (HImode, 2);
4821   if (memory_operand (operands[0], VOIDmode))
4822     emit_insn (gen_fix_truncsi_memory (operands[0], operands[1],
4823                                        operands[2], operands[3]));
4824   else
4825     {
4826       operands[4] = assign_386_stack_local (SImode, 0);
4827       emit_insn (gen_fix_truncsi_nomemory (operands[0], operands[1],
4828                                            operands[2], operands[3],
4829                                            operands[4]));
4830     }
4831   DONE;
4832 }
4833   [(set_attr "type" "fistp")])
4834
4835 (define_insn "fix_truncsi_nomemory"
4836   [(set (match_operand:SI 0 "nonimmediate_operand" "=m,?r")
4837         (fix:SI (match_operand 1 "register_operand" "f,f")))
4838    (use (match_operand:HI 2 "memory_operand" "m,m"))
4839    (use (match_operand:HI 3 "memory_operand" "m,m"))
4840    (clobber (match_operand:SI 4 "memory_operand" "=m,m"))]
4841   "TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[1]))
4842    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
4843   "#"
4844   [(set_attr "type" "fistp")])
4845
4846 (define_insn "fix_truncsi_memory"
4847   [(set (match_operand:SI 0 "memory_operand" "=m")
4848         (fix:SI (match_operand 1 "register_operand" "f")))
4849    (use (match_operand:HI 2 "memory_operand" "m"))
4850    (use (match_operand:HI 3 "memory_operand" "m"))]
4851   "TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[1]))
4852    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
4853   "* return output_fix_trunc (insn, operands);"
4854   [(set_attr "type" "fistp")])
4855
4856 ;; When SSE available, it is always faster to use it!
4857 (define_insn "fix_truncsfsi_sse"
4858   [(set (match_operand:SI 0 "register_operand" "=r")
4859         (fix:SI (match_operand:SF 1 "nonimmediate_operand" "xm")))]
4860   "TARGET_SSE"
4861   "cvttss2si\t{%1, %0|%0, %1}"
4862   [(set_attr "type" "sse")])
4863
4864 (define_insn "fix_truncdfsi_sse"
4865   [(set (match_operand:SI 0 "register_operand" "=r")
4866         (fix:SI (match_operand:DF 1 "nonimmediate_operand" "Ym")))]
4867   "TARGET_SSE2"
4868   "cvttsd2si\t{%1, %0|%0, %1}"
4869   [(set_attr "type" "sse")])
4870
4871 (define_split 
4872   [(set (match_operand:SI 0 "register_operand" "")
4873         (fix:SI (match_operand 1 "register_operand" "")))
4874    (use (match_operand:HI 2 "memory_operand" ""))
4875    (use (match_operand:HI 3 "memory_operand" ""))
4876    (clobber (match_operand:SI 4 "memory_operand" ""))]
4877   "reload_completed"
4878   [(parallel [(set (match_dup 4) (fix:SI (match_dup 1)))
4879               (use (match_dup 2))
4880               (use (match_dup 3))])
4881    (set (match_dup 0) (match_dup 4))]
4882   "")
4883
4884 (define_split 
4885   [(set (match_operand:SI 0 "memory_operand" "")
4886         (fix:SI (match_operand 1 "register_operand" "")))
4887    (use (match_operand:HI 2 "memory_operand" ""))
4888    (use (match_operand:HI 3 "memory_operand" ""))
4889    (clobber (match_operand:SI 4 "memory_operand" ""))]
4890   "reload_completed"
4891   [(parallel [(set (match_dup 0) (fix:SI (match_dup 1)))
4892               (use (match_dup 2))
4893               (use (match_dup 3))])]
4894   "")
4895
4896 ;; Signed conversion to HImode.
4897
4898 (define_expand "fix_truncxfhi2"
4899   [(set (match_operand:HI 0 "nonimmediate_operand" "")
4900         (fix:HI (match_operand:XF 1 "register_operand" "")))]
4901   "TARGET_80387 && !TARGET_64BIT"
4902   "")
4903
4904 (define_expand "fix_trunctfhi2"
4905   [(set (match_operand:HI 0 "nonimmediate_operand" "")
4906         (fix:HI (match_operand:TF 1 "register_operand" "")))]
4907   "TARGET_80387"
4908   "")
4909
4910 (define_expand "fix_truncdfhi2"
4911   [(set (match_operand:HI 0 "nonimmediate_operand" "")
4912         (fix:HI (match_operand:DF 1 "register_operand" "")))]
4913   "TARGET_80387 && !TARGET_SSE2"
4914   "")
4915
4916 (define_expand "fix_truncsfhi2"
4917   [(set (match_operand:HI 0 "nonimmediate_operand" "")
4918         (fix:HI (match_operand:SF 1 "register_operand" "")))]
4919   "TARGET_80387 && !TARGET_SSE"
4920   "")
4921
4922 ;; See the comments in i386.h near OPTIMIZE_MODE_SWITCHING for the description
4923 ;; of the machinery.
4924 (define_insn_and_split "*fix_trunchi_1"
4925   [(set (match_operand:HI 0 "nonimmediate_operand" "=m,?r")
4926         (fix:HI (match_operand 1 "register_operand" "f,f")))]
4927   "TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[1]))
4928    && !reload_completed && !reload_in_progress
4929    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
4930   "#"
4931   ""
4932   [(const_int 0)]
4933 {
4934   operands[2] = assign_386_stack_local (HImode, 1);
4935   operands[3] = assign_386_stack_local (HImode, 2);
4936   if (memory_operand (operands[0], VOIDmode))
4937     emit_insn (gen_fix_trunchi_memory (operands[0], operands[1],
4938                                        operands[2], operands[3]));
4939   else
4940     {
4941       operands[4] = assign_386_stack_local (HImode, 0);
4942       emit_insn (gen_fix_trunchi_nomemory (operands[0], operands[1],
4943                                            operands[2], operands[3],
4944                                            operands[4]));
4945     }
4946   DONE;
4947 }
4948   [(set_attr "type" "fistp")])
4949
4950 (define_insn "fix_trunchi_nomemory"
4951   [(set (match_operand:HI 0 "nonimmediate_operand" "=m,?r")
4952         (fix:HI (match_operand 1 "register_operand" "f,f")))
4953    (use (match_operand:HI 2 "memory_operand" "m,m"))
4954    (use (match_operand:HI 3 "memory_operand" "m,m"))
4955    (clobber (match_operand:HI 4 "memory_operand" "=m,m"))]
4956   "TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[1]))
4957    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
4958   "#"
4959   [(set_attr "type" "fistp")])
4960
4961 (define_insn "fix_trunchi_memory"
4962   [(set (match_operand:HI 0 "memory_operand" "=m")
4963         (fix:HI (match_operand 1 "register_operand" "f")))
4964    (use (match_operand:HI 2 "memory_operand" "m"))
4965    (use (match_operand:HI 3 "memory_operand" "m"))]
4966   "TARGET_80387 && FLOAT_MODE_P (GET_MODE (operands[1]))
4967    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
4968   "* return output_fix_trunc (insn, operands);"
4969   [(set_attr "type" "fistp")])
4970
4971 (define_split 
4972   [(set (match_operand:HI 0 "memory_operand" "")
4973         (fix:HI (match_operand 1 "register_operand" "")))
4974    (use (match_operand:HI 2 "memory_operand" ""))
4975    (use (match_operand:HI 3 "memory_operand" ""))
4976    (clobber (match_operand:HI 4 "memory_operand" ""))]
4977   "reload_completed"
4978   [(parallel [(set (match_dup 0) (fix:HI (match_dup 1)))
4979               (use (match_dup 2))
4980               (use (match_dup 3))])]
4981   "")
4982
4983 (define_split 
4984   [(set (match_operand:HI 0 "register_operand" "")
4985         (fix:HI (match_operand 1 "register_operand" "")))
4986    (use (match_operand:HI 2 "memory_operand" ""))
4987    (use (match_operand:HI 3 "memory_operand" ""))
4988    (clobber (match_operand:HI 4 "memory_operand" ""))]
4989   "reload_completed"
4990   [(parallel [(set (match_dup 4) (fix:HI (match_dup 1)))
4991               (use (match_dup 2))
4992               (use (match_dup 3))
4993               (clobber (match_dup 4))])
4994    (set (match_dup 0) (match_dup 4))]
4995   "")
4996
4997 ;; %% Not used yet.
4998 (define_insn "x86_fnstcw_1"
4999   [(set (match_operand:HI 0 "memory_operand" "=m")
5000         (unspec:HI [(reg:HI 18)] 11))]
5001   "TARGET_80387"
5002   "fnstcw\t%0"
5003   [(set_attr "length" "2")
5004    (set_attr "mode" "HI")
5005    (set_attr "i387" "1")
5006    (set_attr "ppro_uops" "few")])
5007
5008 (define_insn "x86_fldcw_1"
5009   [(set (reg:HI 18)
5010         (unspec:HI [(match_operand:HI 0 "memory_operand" "m")] 12))]
5011   "TARGET_80387"
5012   "fldcw\t%0"
5013   [(set_attr "length" "2")
5014    (set_attr "mode" "HI")
5015    (set_attr "i387" "1")
5016    (set_attr "athlon_decode" "vector")
5017    (set_attr "ppro_uops" "few")])
5018 \f
5019 ;; Conversion between fixed point and floating point.
5020
5021 ;; Even though we only accept memory inputs, the backend _really_
5022 ;; wants to be able to do this between registers.
5023
5024 (define_insn "floathisf2"
5025   [(set (match_operand:SF 0 "register_operand" "=f,f")
5026         (float:SF (match_operand:HI 1 "nonimmediate_operand" "m,r")))]
5027   "TARGET_80387 && !TARGET_SSE"
5028   "@
5029    fild%z1\t%1
5030    #"
5031   [(set_attr "type" "fmov,multi")
5032    (set_attr "mode" "SF")
5033    (set_attr "fp_int_src" "true")])
5034
5035 (define_expand "floatsisf2"
5036   [(set (match_operand:SF 0 "register_operand" "")
5037         (float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
5038   "TARGET_SSE || TARGET_80387"
5039   "")
5040
5041 (define_insn "*floatsisf2_i387"
5042   [(set (match_operand:SF 0 "register_operand" "=f,?f,x")
5043         (float:SF (match_operand:SI 1 "nonimmediate_operand" "m,r,mr")))]
5044   "TARGET_80387 && (!TARGET_SSE || TARGET_MIX_SSE_I387)"
5045   "@
5046    fild%z1\t%1
5047    #
5048    cvtsi2ss\t{%1, %0|%0, %1}"
5049   [(set_attr "type" "fmov,multi,sse")
5050    (set_attr "mode" "SF")
5051    (set_attr "fp_int_src" "true")])
5052
5053 (define_insn "*floatsisf2_sse"
5054   [(set (match_operand:SF 0 "register_operand" "=x")
5055         (float:SF (match_operand:SI 1 "nonimmediate_operand" "mr")))]
5056   "TARGET_SSE"
5057   "cvtsi2ss\t{%1, %0|%0, %1}"
5058   [(set_attr "type" "sse")
5059    (set_attr "mode" "SF")
5060    (set_attr "fp_int_src" "true")])
5061
5062 (define_expand "floatdisf2"
5063   [(set (match_operand:SF 0 "register_operand" "")
5064         (float:SF (match_operand:DI 1 "nonimmediate_operand" "")))]
5065   "(TARGET_SSE && TARGET_64BIT) || TARGET_80387"
5066   "")
5067
5068 (define_insn "*floatdisf2_i387_only"
5069   [(set (match_operand:SF 0 "register_operand" "=f,?f")
5070         (float:SF (match_operand:DI 1 "nonimmediate_operand" "m,r")))]
5071   "TARGET_80387 && (!TARGET_SSE || !TARGET_64BIT || TARGET_MIX_SSE_I387)"
5072   "@
5073    fild%z1\t%1
5074    #"
5075   [(set_attr "type" "fmov,multi")
5076    (set_attr "mode" "SF")
5077    (set_attr "fp_int_src" "true")])
5078
5079 (define_insn "*floatdisf2_i387"
5080   [(set (match_operand:SF 0 "register_operand" "=f,?f,x")
5081         (float:SF (match_operand:DI 1 "nonimmediate_operand" "m,r,mr")))]
5082   "TARGET_80387 && TARGET_64BIT && (!TARGET_SSE || TARGET_MIX_SSE_I387)"
5083   "@
5084    fild%z1\t%1
5085    #
5086    cvtsi2ss{q}\t{%1, %0|%0, %1}"
5087   [(set_attr "type" "fmov,multi,sse")
5088    (set_attr "mode" "SF")
5089    (set_attr "fp_int_src" "true")])
5090
5091 (define_insn "*floatdisf2_sse"
5092   [(set (match_operand:SF 0 "register_operand" "=x")
5093         (float:SF (match_operand:DI 1 "nonimmediate_operand" "mr")))]
5094   "TARGET_SSE && TARGET_64BIT"
5095   "cvtsi2ss{q}\t{%1, %0|%0, %1}"
5096   [(set_attr "type" "sse")
5097    (set_attr "mode" "SF")
5098    (set_attr "fp_int_src" "true")])
5099
5100 (define_insn "floathidf2"
5101   [(set (match_operand:DF 0 "register_operand" "=f,f")
5102         (float:DF (match_operand:HI 1 "nonimmediate_operand" "m,r")))]
5103   "TARGET_80387 && !TARGET_SSE2"
5104   "@
5105    fild%z1\t%1
5106    #"
5107   [(set_attr "type" "fmov,multi")
5108    (set_attr "mode" "DF")
5109    (set_attr "fp_int_src" "true")])
5110
5111 (define_expand "floatsidf2"
5112   [(set (match_operand:DF 0 "register_operand" "")
5113         (float:DF (match_operand:SI 1 "nonimmediate_operand" "")))]
5114   ""
5115   "")
5116
5117 (define_insn "*floatsidf2_i387"
5118   [(set (match_operand:DF 0 "register_operand" "=f,?f,Y")
5119         (float:DF (match_operand:SI 1 "nonimmediate_operand" "m,r,mr")))]
5120   "TARGET_80387 && (!TARGET_SSE2 || TARGET_MIX_SSE_I387)"
5121   "@
5122    fild%z1\t%1
5123    #
5124    cvtsi2sd\t{%1, %0|%0, %1}"
5125   [(set_attr "type" "fmov,multi,sse")
5126    (set_attr "mode" "DF")
5127    (set_attr "fp_int_src" "true")])
5128
5129 (define_insn "*floatsidf2_sse"
5130   [(set (match_operand:DF 0 "register_operand" "=Y")
5131         (float:DF (match_operand:SI 1 "nonimmediate_operand" "mr")))]
5132   "TARGET_SSE2"
5133   "cvtsi2sd\t{%1, %0|%0, %1}"
5134   [(set_attr "type" "sse")
5135    (set_attr "mode" "DF")
5136    (set_attr "fp_int_src" "true")])
5137
5138 (define_expand "floatdidf2"
5139   [(set (match_operand:DF 0 "register_operand" "")
5140         (float:DF (match_operand:DI 1 "nonimmediate_operand" "")))]
5141   "TARGET_80387 || (TARGET_SSE2 && TARGET_64BIT)"
5142   "")
5143
5144 (define_insn "*floatdidf2_i387_only"
5145   [(set (match_operand:DF 0 "register_operand" "=f,?f")
5146         (float:DF (match_operand:DI 1 "nonimmediate_operand" "m,r")))]
5147   "TARGET_80387 && (!TARGET_SSE2 || !TARGET_64BIT)"
5148   "@
5149    fild%z1\t%1
5150    #"
5151   [(set_attr "type" "fmov,multi")
5152    (set_attr "mode" "DF")
5153    (set_attr "fp_int_src" "true")])
5154
5155 (define_insn "*floatdidf2_i387"
5156   [(set (match_operand:DF 0 "register_operand" "=f,?f,Y")
5157         (float:DF (match_operand:DI 1 "nonimmediate_operand" "m,r,mr")))]
5158   "TARGET_80387 && TARGET_64BIT && (!TARGET_SSE2 || TARGET_MIX_SSE_I387)"
5159   "@
5160    fild%z1\t%1
5161    #
5162    cvtsi2sd{q}\t{%1, %0|%0, %1}"
5163   [(set_attr "type" "fmov,multi,sse")
5164    (set_attr "mode" "DF")
5165    (set_attr "fp_int_src" "true")])
5166
5167 (define_insn "*floatdidf2_sse"
5168   [(set (match_operand:DF 0 "register_operand" "=Y")
5169         (float:DF (match_operand:DI 1 "nonimmediate_operand" "mr")))]
5170   "TARGET_SSE2"
5171   "cvtsi2sd{q}\t{%1, %0|%0, %1}"
5172   [(set_attr "type" "sse")
5173    (set_attr "mode" "DF")
5174    (set_attr "fp_int_src" "true")])
5175
5176 (define_insn "floathixf2"
5177   [(set (match_operand:XF 0 "register_operand" "=f,f")
5178         (float:XF (match_operand:HI 1 "nonimmediate_operand" "m,r")))]
5179   "TARGET_80387 && !TARGET_64BIT"
5180   "@
5181    fild%z1\t%1
5182    #"
5183   [(set_attr "type" "fmov,multi")
5184    (set_attr "mode" "XF")
5185    (set_attr "fp_int_src" "true")])
5186
5187 (define_insn "floathitf2"
5188   [(set (match_operand:TF 0 "register_operand" "=f,f")
5189         (float:TF (match_operand:HI 1 "nonimmediate_operand" "m,r")))]
5190   "TARGET_80387"
5191   "@
5192    fild%z1\t%1
5193    #"
5194   [(set_attr "type" "fmov,multi")
5195    (set_attr "mode" "XF")
5196    (set_attr "fp_int_src" "true")])
5197
5198 (define_insn "floatsixf2"
5199   [(set (match_operand:XF 0 "register_operand" "=f,f")
5200         (float:XF (match_operand:SI 1 "nonimmediate_operand" "m,r")))]
5201   "TARGET_80387 && !TARGET_64BIT"
5202   "@
5203    fild%z1\t%1
5204    #"
5205   [(set_attr "type" "fmov,multi")
5206    (set_attr "mode" "XF")
5207    (set_attr "fp_int_src" "true")])
5208
5209 (define_insn "floatsitf2"
5210   [(set (match_operand:TF 0 "register_operand" "=f,f")
5211         (float:TF (match_operand:SI 1 "nonimmediate_operand" "m,r")))]
5212   "TARGET_80387"
5213   "@
5214    fild%z1\t%1
5215    #"
5216   [(set_attr "type" "fmov,multi")
5217    (set_attr "mode" "XF")
5218    (set_attr "fp_int_src" "true")])
5219
5220 (define_insn "floatdixf2"
5221   [(set (match_operand:XF 0 "register_operand" "=f,f")
5222         (float:XF (match_operand:DI 1 "nonimmediate_operand" "m,r")))]
5223   "TARGET_80387 && !TARGET_64BIT"
5224   "@
5225    fild%z1\t%1
5226    #"
5227   [(set_attr "type" "fmov,multi")
5228    (set_attr "mode" "XF")
5229    (set_attr "fp_int_src" "true")])
5230
5231 (define_insn "floatditf2"
5232   [(set (match_operand:TF 0 "register_operand" "=f,f")
5233         (float:TF (match_operand:DI 1 "nonimmediate_operand" "m,r")))]
5234   "TARGET_80387"
5235   "@
5236    fild%z1\t%1
5237    #"
5238   [(set_attr "type" "fmov,multi")
5239    (set_attr "mode" "XF")
5240    (set_attr "fp_int_src" "true")])
5241
5242 ;; %%% Kill these when reload knows how to do it.
5243 (define_split
5244   [(set (match_operand 0 "register_operand" "")
5245         (float (match_operand 1 "register_operand" "")))]
5246   "reload_completed && FLOAT_MODE_P (GET_MODE (operands[0]))
5247    && FP_REG_P (operands[0])"
5248   [(const_int 0)]
5249 {
5250   operands[2] = ix86_force_to_memory (GET_MODE (operands[1]), operands[1]);
5251   operands[2] = gen_rtx_FLOAT (GET_MODE (operands[0]), operands[2]);
5252   emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[2]));
5253   ix86_free_from_memory (GET_MODE (operands[1]));
5254   DONE;
5255 })
5256 \f
5257 ;; Add instructions
5258
5259 ;; %%% splits for addsidi3
5260 ;  [(set (match_operand:DI 0 "nonimmediate_operand" "")
5261 ;       (plus:DI (match_operand:DI 1 "general_operand" "")
5262 ;                (zero_extend:DI (match_operand:SI 2 "general_operand" ""))))]
5263
5264 (define_expand "adddi3"
5265   [(set (match_operand:DI 0 "nonimmediate_operand" "")
5266         (plus:DI (match_operand:DI 1 "nonimmediate_operand" "")
5267                  (match_operand:DI 2 "x86_64_general_operand" "")))
5268    (clobber (reg:CC 17))]
5269   ""
5270   "ix86_expand_binary_operator (PLUS, DImode, operands); DONE;")
5271
5272 (define_insn "*adddi3_1"
5273   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,o")
5274         (plus:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
5275                  (match_operand:DI 2 "general_operand" "roiF,riF")))
5276    (clobber (reg:CC 17))]
5277   "!TARGET_64BIT"
5278   "#")
5279
5280 (define_split
5281   [(set (match_operand:DI 0 "nonimmediate_operand" "")
5282         (plus:DI (match_operand:DI 1 "nonimmediate_operand" "")
5283                  (match_operand:DI 2 "general_operand" "")))
5284    (clobber (reg:CC 17))]
5285   "reload_completed && !TARGET_64BIT"
5286   [(parallel [(set (reg:CC 17) (unspec:CC [(match_dup 1) (match_dup 2)] 12))
5287               (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))])
5288    (parallel [(set (match_dup 3)
5289                    (plus:SI (plus:SI (ltu:SI (reg:CC 17) (const_int 0))
5290                                      (match_dup 4))
5291                             (match_dup 5)))
5292               (clobber (reg:CC 17))])]
5293   "split_di (operands+0, 1, operands+0, operands+3);
5294    split_di (operands+1, 1, operands+1, operands+4);
5295    split_di (operands+2, 1, operands+2, operands+5);")
5296
5297 (define_insn "*adddi3_carry_rex64"
5298   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
5299           (plus:DI (plus:DI (ltu:DI (reg:CC 17) (const_int 0))
5300                             (match_operand:DI 1 "nonimmediate_operand" "%0,0"))
5301                    (match_operand:DI 2 "x86_64_general_operand" "re,rm")))
5302    (clobber (reg:CC 17))]
5303   "ix86_binary_operator_ok (PLUS, DImode, operands)"
5304   "adc{q}\t{%2, %0|%0, %2}"
5305   [(set_attr "type" "alu")
5306    (set_attr "pent_pair" "pu")
5307    (set_attr "mode" "DI")
5308    (set_attr "ppro_uops" "few")])
5309
5310 (define_insn "*adddi3_cc_rex64"
5311   [(set (reg:CC 17) (unspec:CC [(match_operand:DI 1 "nonimmediate_operand" "%0,0")
5312                                 (match_operand:DI 2 "x86_64_general_operand" "re,rm")] 12))
5313    (set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
5314         (plus:DI (match_dup 1) (match_dup 2)))]
5315   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, DImode, operands)"
5316   "add{q}\t{%2, %0|%0, %2}"
5317   [(set_attr "type" "alu")
5318    (set_attr "mode" "DI")])
5319
5320 (define_insn "*addsi3_carry"
5321   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
5322           (plus:SI (plus:SI (ltu:SI (reg:CC 17) (const_int 0))
5323                             (match_operand:SI 1 "nonimmediate_operand" "%0,0"))
5324                    (match_operand:SI 2 "general_operand" "ri,rm")))
5325    (clobber (reg:CC 17))]
5326   "ix86_binary_operator_ok (PLUS, SImode, operands)"
5327   "adc{l}\t{%2, %0|%0, %2}"
5328   [(set_attr "type" "alu")
5329    (set_attr "pent_pair" "pu")
5330    (set_attr "mode" "SI")
5331    (set_attr "ppro_uops" "few")])
5332
5333 (define_insn "*addsi3_carry_zext"
5334   [(set (match_operand:DI 0 "register_operand" "=r")
5335           (zero_extend:DI 
5336             (plus:SI (plus:SI (ltu:SI (reg:CC 17) (const_int 0))
5337                               (match_operand:SI 1 "nonimmediate_operand" "%0"))
5338                      (match_operand:SI 2 "general_operand" "rim"))))
5339    (clobber (reg:CC 17))]
5340   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, SImode, operands)"
5341   "adc{l}\t{%2, %k0|%k0, %2}"
5342   [(set_attr "type" "alu")
5343    (set_attr "pent_pair" "pu")
5344    (set_attr "mode" "SI")
5345    (set_attr "ppro_uops" "few")])
5346
5347 (define_insn "*addsi3_cc"
5348   [(set (reg:CC 17) (unspec:CC [(match_operand:SI 1 "nonimmediate_operand" "%0,0")
5349                                 (match_operand:SI 2 "general_operand" "ri,rm")] 12))
5350    (set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
5351         (plus:SI (match_dup 1) (match_dup 2)))]
5352   "ix86_binary_operator_ok (PLUS, SImode, operands)"
5353   "add{l}\t{%2, %0|%0, %2}"
5354   [(set_attr "type" "alu")
5355    (set_attr "mode" "SI")])
5356
5357 (define_insn "addqi3_cc"
5358   [(set (reg:CC 17) (unspec:CC [(match_operand:QI 1 "nonimmediate_operand" "%0,0")
5359                                 (match_operand:QI 2 "general_operand" "qi,qm")] 12))
5360    (set (match_operand:QI 0 "nonimmediate_operand" "=qm,q")
5361         (plus:QI (match_dup 1) (match_dup 2)))]
5362   "ix86_binary_operator_ok (PLUS, QImode, operands)"
5363   "add{b}\t{%2, %0|%0, %2}"
5364   [(set_attr "type" "alu")
5365    (set_attr "mode" "QI")])
5366
5367 (define_expand "addsi3"
5368   [(parallel [(set (match_operand:SI 0 "nonimmediate_operand" "")
5369                    (plus:SI (match_operand:SI 1 "nonimmediate_operand" "")
5370                             (match_operand:SI 2 "general_operand" "")))
5371               (clobber (reg:CC 17))])]
5372   ""
5373   "ix86_expand_binary_operator (PLUS, SImode, operands); DONE;")
5374
5375 (define_insn "*lea_1"
5376   [(set (match_operand:SI 0 "register_operand" "=r")
5377         (match_operand:SI 1 "address_operand" "p"))]
5378   "!TARGET_64BIT"
5379   "lea{l}\t{%a1, %0|%0, %a1}"
5380   [(set_attr "type" "lea")
5381    (set_attr "mode" "SI")])
5382
5383 (define_insn "*lea_1_rex64"
5384   [(set (match_operand:SI 0 "register_operand" "=r")
5385         (subreg:SI (match_operand:DI 1 "address_operand" "p") 0))]
5386   "TARGET_64BIT"
5387   "lea{l}\t{%a1, %0|%0, %a1}"
5388   [(set_attr "type" "lea")
5389    (set_attr "mode" "SI")])
5390
5391 (define_insn "*lea_1_zext"
5392   [(set (match_operand:DI 0 "register_operand" "=r")
5393         (zero_extend:DI (subreg:SI (match_operand:DI 1 "address_operand" "p") 0)))]
5394   "TARGET_64BIT"
5395   "lea{l}\t{%a1, %k0|%k0, %a1}"
5396   [(set_attr "type" "lea")
5397    (set_attr "mode" "SI")])
5398
5399 (define_insn "*lea_2_rex64"
5400   [(set (match_operand:DI 0 "register_operand" "=r")
5401         (match_operand:DI 1 "address_operand" "p"))]
5402   "TARGET_64BIT"
5403   "lea{q}\t{%a1, %0|%0, %a1}"
5404   [(set_attr "type" "lea")
5405    (set_attr "mode" "DI")])
5406
5407 ;; The lea patterns for non-Pmodes needs to be matched by several
5408 ;; insns converted to real lea by splitters.
5409
5410 (define_insn_and_split "*lea_general_1"
5411   [(set (match_operand 0 "register_operand" "=r")
5412         (plus (plus (match_operand 1 "register_operand" "r")
5413                     (match_operand 2 "register_operand" "r"))
5414               (match_operand 3 "immediate_operand" "i")))]
5415   "(GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode
5416     || (TARGET_64BIT && GET_MODE (operands[0]) == SImode))
5417    && (!TARGET_PARTIAL_REG_STALL || optimize_size)
5418    && GET_MODE (operands[0]) == GET_MODE (operands[1])
5419    && GET_MODE (operands[0]) == GET_MODE (operands[2])
5420    && (GET_MODE (operands[0]) == GET_MODE (operands[3])
5421        || GET_MODE (operands[3]) == VOIDmode)"
5422   "#"
5423   "&& reload_completed"
5424   [(const_int 0)]
5425 {
5426   rtx pat;
5427   operands[0] = gen_lowpart (SImode, operands[0]);
5428   operands[1] = gen_lowpart (Pmode, operands[1]);
5429   operands[2] = gen_lowpart (Pmode, operands[2]);
5430   operands[3] = gen_lowpart (Pmode, operands[3]);
5431   pat = gen_rtx_PLUS (Pmode, gen_rtx_PLUS (Pmode, operands[1], operands[2]),
5432                       operands[3]);
5433   if (Pmode != SImode)
5434     pat = gen_rtx_SUBREG (SImode, pat, 0);
5435   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
5436   DONE;
5437 }
5438   [(set_attr "type" "lea")
5439    (set_attr "mode" "SI")])
5440
5441 (define_insn_and_split "*lea_general_1_zext"
5442   [(set (match_operand:DI 0 "register_operand" "=r")
5443         (zero_extend:DI
5444           (plus:SI (plus:SI (match_operand:SI 1 "register_operand" "r")
5445                             (match_operand:SI 2 "register_operand" "r"))
5446                    (match_operand:SI 3 "immediate_operand" "i"))))]
5447   "TARGET_64BIT"
5448   "#"
5449   "&& reload_completed"
5450   [(set (match_dup 0)
5451         (zero_extend:DI (subreg:SI (plus:DI (plus:DI (match_dup 1)
5452                                                      (match_dup 2))
5453                                             (match_dup 3)) 0)))]
5454 {
5455   operands[1] = gen_lowpart (Pmode, operands[1]);
5456   operands[2] = gen_lowpart (Pmode, operands[2]);
5457   operands[3] = gen_lowpart (Pmode, operands[3]);
5458 }
5459   [(set_attr "type" "lea")
5460    (set_attr "mode" "SI")])
5461
5462 (define_insn_and_split "*lea_general_2"
5463   [(set (match_operand 0 "register_operand" "=r")
5464         (plus (mult (match_operand 1 "register_operand" "r")
5465                     (match_operand 2 "const248_operand" "i"))
5466               (match_operand 3 "nonmemory_operand" "ri")))]
5467   "(GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode
5468     || (TARGET_64BIT && GET_MODE (operands[0]) == SImode))
5469    && (!TARGET_PARTIAL_REG_STALL || optimize_size)
5470    && GET_MODE (operands[0]) == GET_MODE (operands[1])
5471    && (GET_MODE (operands[0]) == GET_MODE (operands[3])
5472        || GET_MODE (operands[3]) == VOIDmode)"
5473   "#"
5474   "&& reload_completed"
5475   [(const_int 0)]
5476 {
5477   rtx pat;
5478   operands[0] = gen_lowpart (SImode, operands[0]);
5479   operands[1] = gen_lowpart (Pmode, operands[1]);
5480   operands[3] = gen_lowpart (Pmode, operands[3]);
5481   pat = gen_rtx_PLUS (Pmode, gen_rtx_MULT (Pmode, operands[1], operands[2]),
5482                       operands[3]);
5483   if (Pmode != SImode)
5484     pat = gen_rtx_SUBREG (SImode, pat, 0);
5485   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
5486   DONE;
5487 }
5488   [(set_attr "type" "lea")
5489    (set_attr "mode" "SI")])
5490
5491 (define_insn_and_split "*lea_general_2_zext"
5492   [(set (match_operand:DI 0 "register_operand" "=r")
5493         (zero_extend:DI
5494           (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
5495                             (match_operand:SI 2 "const248_operand" "n"))
5496                    (match_operand:SI 3 "nonmemory_operand" "ri"))))]
5497   "TARGET_64BIT"
5498   "#"
5499   "&& reload_completed"
5500   [(set (match_dup 0)
5501         (zero_extend:DI (subreg:SI (plus:DI (mult:DI (match_dup 1)
5502                                                      (match_dup 2))
5503                                             (match_dup 3)) 0)))]
5504 {
5505   operands[1] = gen_lowpart (Pmode, operands[1]);
5506   operands[3] = gen_lowpart (Pmode, operands[3]);
5507 }
5508   [(set_attr "type" "lea")
5509    (set_attr "mode" "SI")])
5510
5511 (define_insn_and_split "*lea_general_3"
5512   [(set (match_operand 0 "register_operand" "=r")
5513         (plus (plus (mult (match_operand 1 "register_operand" "r")
5514                           (match_operand 2 "const248_operand" "i"))
5515                     (match_operand 3 "register_operand" "r"))
5516               (match_operand 4 "immediate_operand" "i")))]
5517   "(GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode
5518     || (TARGET_64BIT && GET_MODE (operands[0]) == SImode))
5519    && (!TARGET_PARTIAL_REG_STALL || optimize_size)
5520    && GET_MODE (operands[0]) == GET_MODE (operands[1])
5521    && GET_MODE (operands[0]) == GET_MODE (operands[3])"
5522   "#"
5523   "&& reload_completed"
5524   [(const_int 0)]
5525 {
5526   rtx pat;
5527   operands[0] = gen_lowpart (SImode, operands[0]);
5528   operands[1] = gen_lowpart (Pmode, operands[1]);
5529   operands[3] = gen_lowpart (Pmode, operands[3]);
5530   operands[4] = gen_lowpart (Pmode, operands[4]);
5531   pat = gen_rtx_PLUS (Pmode,
5532                       gen_rtx_PLUS (Pmode, gen_rtx_MULT (Pmode, operands[1],
5533                                                          operands[2]),
5534                                     operands[3]),
5535                       operands[4]);
5536   if (Pmode != SImode)
5537     pat = gen_rtx_SUBREG (SImode, pat, 0);
5538   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
5539   DONE;
5540 }
5541   [(set_attr "type" "lea")
5542    (set_attr "mode" "SI")])
5543
5544 (define_insn_and_split "*lea_general_3_zext"
5545   [(set (match_operand:DI 0 "register_operand" "=r")
5546         (zero_extend:DI
5547           (plus:SI (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
5548                                      (match_operand:SI 2 "const248_operand" "n"))
5549                             (match_operand:SI 3 "register_operand" "r"))
5550                    (match_operand:SI 4 "immediate_operand" "i"))))]
5551   "TARGET_64BIT"
5552   "#"
5553   "&& reload_completed"
5554   [(set (match_dup 0)
5555         (zero_extend:DI (subreg:SI (plus:DI (plus:DI (mult:DI (match_dup 1)
5556                                                               (match_dup 2))
5557                                                      (match_dup 3))
5558                                             (match_dup 4)) 0)))]
5559 {
5560   operands[1] = gen_lowpart (Pmode, operands[1]);
5561   operands[3] = gen_lowpart (Pmode, operands[3]);
5562   operands[4] = gen_lowpart (Pmode, operands[4]);
5563 }
5564   [(set_attr "type" "lea")
5565    (set_attr "mode" "SI")])
5566
5567 (define_insn "*adddi_1_rex64"
5568   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,rm,r")
5569         (plus:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0,r")
5570                  (match_operand:DI 2 "x86_64_general_operand" "rme,re,re")))
5571    (clobber (reg:CC 17))]
5572   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, DImode, operands)"
5573 {
5574   switch (get_attr_type (insn))
5575     {
5576     case TYPE_LEA:
5577       operands[2] = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
5578       return "lea{q}\t{%a2, %0|%0, %a2}";
5579
5580     case TYPE_INCDEC:
5581       if (! rtx_equal_p (operands[0], operands[1]))
5582         abort ();
5583       if (operands[2] == const1_rtx)
5584         return "inc{q}\t%0";
5585       else if (operands[2] == constm1_rtx)
5586         return "dec{q}\t%0";
5587       else
5588         abort ();
5589
5590     default:
5591       if (! rtx_equal_p (operands[0], operands[1]))
5592         abort ();
5593
5594       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
5595          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
5596       if (GET_CODE (operands[2]) == CONST_INT
5597           /* Avoid overflows.  */
5598           && ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1)))
5599           && (INTVAL (operands[2]) == 128
5600               || (INTVAL (operands[2]) < 0
5601                   && INTVAL (operands[2]) != -128)))
5602         {
5603           operands[2] = GEN_INT (-INTVAL (operands[2]));
5604           return "sub{q}\t{%2, %0|%0, %2}";
5605         }
5606       return "add{q}\t{%2, %0|%0, %2}";
5607     }
5608 }
5609   [(set (attr "type")
5610      (cond [(eq_attr "alternative" "2")
5611               (const_string "lea")
5612             ; Current assemblers are broken and do not allow @GOTOFF in
5613             ; ought but a memory context.
5614             (match_operand:DI 2 "pic_symbolic_operand" "")
5615               (const_string "lea")
5616             (match_operand:DI 2 "incdec_operand" "")
5617               (const_string "incdec")
5618            ]
5619            (const_string "alu")))
5620    (set_attr "mode" "DI")])
5621
5622 ;; Convert lea to the lea pattern to avoid flags dependency.
5623 (define_split
5624   [(set (match_operand:DI 0 "register_operand" "")
5625         (plus:DI (match_operand:DI 1 "register_operand" "")
5626                  (match_operand:DI 2 "x86_64_nonmemory_operand" "")))
5627    (clobber (reg:CC 17))]
5628   "reload_completed && TARGET_64BIT
5629    && true_regnum (operands[0]) != true_regnum (operands[1])"
5630   [(set (match_dup 0)
5631         (plus:DI (match_dup 1)
5632                  (match_dup 2)))]
5633   "")
5634
5635 (define_insn "*adddi_2_rex64"
5636   [(set (reg 17)
5637         (compare
5638           (plus:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
5639                    (match_operand:DI 2 "x86_64_general_operand" "rme,re"))
5640           (const_int 0)))                       
5641    (set (match_operand:DI 0 "nonimmediate_operand" "=r,rm")
5642         (plus:DI (match_dup 1) (match_dup 2)))]
5643   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
5644    && ix86_binary_operator_ok (PLUS, DImode, operands)
5645    /* Current assemblers are broken and do not allow @GOTOFF in
5646       ought but a memory context. */
5647    && ! pic_symbolic_operand (operands[2], VOIDmode)"
5648 {
5649   switch (get_attr_type (insn))
5650     {
5651     case TYPE_INCDEC:
5652       if (! rtx_equal_p (operands[0], operands[1]))
5653         abort ();
5654       if (operands[2] == const1_rtx)
5655         return "inc{q}\t%0";
5656       else if (operands[2] == constm1_rtx)
5657         return "dec{q}\t%0";
5658       else
5659         abort ();
5660
5661     default:
5662       if (! rtx_equal_p (operands[0], operands[1]))
5663         abort ();
5664       /* ???? We ought to handle there the 32bit case too
5665          - do we need new constrant?  */
5666       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
5667          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
5668       if (GET_CODE (operands[2]) == CONST_INT
5669           /* Avoid overflows.  */
5670           && ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1)))
5671           && (INTVAL (operands[2]) == 128
5672               || (INTVAL (operands[2]) < 0
5673                   && INTVAL (operands[2]) != -128)))
5674         {
5675           operands[2] = GEN_INT (-INTVAL (operands[2]));
5676           return "sub{q}\t{%2, %0|%0, %2}";
5677         }
5678       return "add{q}\t{%2, %0|%0, %2}";
5679     }
5680 }
5681   [(set (attr "type")
5682      (if_then_else (match_operand:DI 2 "incdec_operand" "")
5683         (const_string "incdec")
5684         (const_string "alu")))
5685    (set_attr "mode" "DI")])
5686
5687 (define_insn "*adddi_3_rex64"
5688   [(set (reg 17)
5689         (compare (neg:DI (match_operand:DI 2 "x86_64_general_operand" "rme"))
5690                  (match_operand:DI 1 "x86_64_general_operand" "%0")))
5691    (clobber (match_scratch:DI 0 "=r"))]
5692   "TARGET_64BIT
5693    && ix86_match_ccmode (insn, CCZmode)
5694    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)
5695    /* Current assemblers are broken and do not allow @GOTOFF in
5696       ought but a memory context. */
5697    && ! pic_symbolic_operand (operands[2], VOIDmode)"
5698 {
5699   switch (get_attr_type (insn))
5700     {
5701     case TYPE_INCDEC:
5702       if (! rtx_equal_p (operands[0], operands[1]))
5703         abort ();
5704       if (operands[2] == const1_rtx)
5705         return "inc{q}\t%0";
5706       else if (operands[2] == constm1_rtx)
5707         return "dec{q}\t%0";
5708       else
5709         abort ();
5710
5711     default:
5712       if (! rtx_equal_p (operands[0], operands[1]))
5713         abort ();
5714       /* ???? We ought to handle there the 32bit case too
5715          - do we need new constrant?  */
5716       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
5717          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
5718       if (GET_CODE (operands[2]) == CONST_INT
5719           /* Avoid overflows.  */
5720           && ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1)))
5721           && (INTVAL (operands[2]) == 128
5722               || (INTVAL (operands[2]) < 0
5723                   && INTVAL (operands[2]) != -128)))
5724         {
5725           operands[2] = GEN_INT (-INTVAL (operands[2]));
5726           return "sub{q}\t{%2, %0|%0, %2}";
5727         }
5728       return "add{q}\t{%2, %0|%0, %2}";
5729     }
5730 }
5731   [(set (attr "type")
5732      (if_then_else (match_operand:DI 2 "incdec_operand" "")
5733         (const_string "incdec")
5734         (const_string "alu")))
5735    (set_attr "mode" "DI")])
5736
5737 ; For comparisons against 1, -1 and 128, we may generate better code
5738 ; by converting cmp to add, inc or dec as done by peephole2.  This pattern
5739 ; is matched then.  We can't accept general immediate, because for
5740 ; case of overflows,  the result is messed up.
5741 ; This pattern also don't hold of 0x8000000000000000, since the value overflows
5742 ; when negated.
5743 ; Also carry flag is reversed compared to cmp, so this converison is valid
5744 ; only for comparisons not depending on it.
5745 (define_insn "*adddi_4_rex64"
5746   [(set (reg 17)
5747         (compare (match_operand:DI 1 "nonimmediate_operand" "0")
5748                  (match_operand:DI 2 "x86_64_immediate_operand" "e")))
5749    (clobber (match_scratch:DI 0 "=rm"))]
5750   "TARGET_64BIT
5751    &&  ix86_match_ccmode (insn, CCGCmode)"
5752 {
5753   switch (get_attr_type (insn))
5754     {
5755     case TYPE_INCDEC:
5756       if (operands[2] == constm1_rtx)
5757         return "inc{q}\t%0";
5758       else if (operands[2] == const1_rtx)
5759         return "dec{q}\t%0";
5760       else
5761         abort();
5762
5763     default:
5764       if (! rtx_equal_p (operands[0], operands[1]))
5765         abort ();
5766       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
5767          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
5768       if ((INTVAL (operands[2]) == -128
5769            || (INTVAL (operands[2]) > 0
5770                && INTVAL (operands[2]) != 128))
5771           /* Avoid overflows.  */
5772           && ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1))))
5773         return "sub{q}\t{%2, %0|%0, %2}";
5774       operands[2] = GEN_INT (-INTVAL (operands[2]));
5775       return "add{q}\t{%2, %0|%0, %2}";
5776     }
5777 }
5778   [(set (attr "type")
5779      (if_then_else (match_operand:DI 2 "incdec_operand" "")
5780         (const_string "incdec")
5781         (const_string "alu")))
5782    (set_attr "mode" "DI")])
5783
5784 (define_insn "*adddi_5_rex64"
5785   [(set (reg 17)
5786         (compare
5787           (plus:DI (match_operand:DI 1 "nonimmediate_operand" "%0")
5788                    (match_operand:DI 2 "x86_64_general_operand" "rme"))
5789           (const_int 0)))                       
5790    (clobber (match_scratch:DI 0 "=r"))]
5791   "TARGET_64BIT
5792    && ix86_match_ccmode (insn, CCGOCmode)
5793    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)
5794    /* Current assemblers are broken and do not allow @GOTOFF in
5795       ought but a memory context. */
5796    && ! pic_symbolic_operand (operands[2], VOIDmode)"
5797 {
5798   switch (get_attr_type (insn))
5799     {
5800     case TYPE_INCDEC:
5801       if (! rtx_equal_p (operands[0], operands[1]))
5802         abort ();
5803       if (operands[2] == const1_rtx)
5804         return "inc{q}\t%0";
5805       else if (operands[2] == constm1_rtx)
5806         return "dec{q}\t%0";
5807       else
5808         abort();
5809
5810     default:
5811       if (! rtx_equal_p (operands[0], operands[1]))
5812         abort ();
5813       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
5814          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
5815       if (GET_CODE (operands[2]) == CONST_INT
5816           /* Avoid overflows.  */
5817           && ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1)))
5818           && (INTVAL (operands[2]) == 128
5819               || (INTVAL (operands[2]) < 0
5820                   && INTVAL (operands[2]) != -128)))
5821         {
5822           operands[2] = GEN_INT (-INTVAL (operands[2]));
5823           return "sub{q}\t{%2, %0|%0, %2}";
5824         }
5825       return "add{q}\t{%2, %0|%0, %2}";
5826     }
5827 }
5828   [(set (attr "type")
5829      (if_then_else (match_operand:DI 2 "incdec_operand" "")
5830         (const_string "incdec")
5831         (const_string "alu")))
5832    (set_attr "mode" "DI")])
5833
5834
5835 (define_insn "*addsi_1"
5836   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,rm,r")
5837         (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,r")
5838                  (match_operand:SI 2 "general_operand" "rmni,rni,rni")))
5839    (clobber (reg:CC 17))]
5840   "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, %0|%0, %a2}";
5847
5848     case TYPE_INCDEC:
5849       if (! rtx_equal_p (operands[0], operands[1]))
5850         abort ();
5851       if (operands[2] == const1_rtx)
5852         return "inc{l}\t%0";
5853       else if (operands[2] == constm1_rtx)
5854         return "dec{l}\t%0";
5855       else
5856         abort();
5857
5858     default:
5859       if (! rtx_equal_p (operands[0], operands[1]))
5860         abort ();
5861
5862       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
5863          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
5864       if (GET_CODE (operands[2]) == CONST_INT
5865           && (INTVAL (operands[2]) == 128
5866               || (INTVAL (operands[2]) < 0
5867                   && INTVAL (operands[2]) != -128)))
5868         {
5869           operands[2] = GEN_INT (-INTVAL (operands[2]));
5870           return "sub{l}\t{%2, %0|%0, %2}";
5871         }
5872       return "add{l}\t{%2, %0|%0, %2}";
5873     }
5874 }
5875   [(set (attr "type")
5876      (cond [(eq_attr "alternative" "2")
5877               (const_string "lea")
5878             ; Current assemblers are broken and do not allow @GOTOFF in
5879             ; ought but a memory context.
5880             (match_operand:SI 2 "pic_symbolic_operand" "")
5881               (const_string "lea")
5882             (match_operand:SI 2 "incdec_operand" "")
5883               (const_string "incdec")
5884            ]
5885            (const_string "alu")))
5886    (set_attr "mode" "SI")])
5887
5888 ;; Convert lea to the lea pattern to avoid flags dependency.
5889 (define_split
5890   [(set (match_operand 0 "register_operand" "")
5891         (plus (match_operand 1 "register_operand" "")
5892               (match_operand 2 "nonmemory_operand" "")))
5893    (clobber (reg:CC 17))]
5894   "reload_completed
5895    && true_regnum (operands[0]) != true_regnum (operands[1])"
5896   [(const_int 0)]
5897 {
5898   rtx pat;
5899   /* In -fPIC mode the constructs like (const (unspec [symbol_ref]))
5900      may confuse gen_lowpart.  */
5901   if (GET_MODE (operands[0]) != Pmode)
5902     {
5903       operands[1] = gen_lowpart (Pmode, operands[1]);
5904       operands[2] = gen_lowpart (Pmode, operands[2]);
5905     }
5906   operands[0] = gen_lowpart (SImode, operands[0]);
5907   pat = gen_rtx_PLUS (Pmode, operands[1], operands[2]);
5908   if (Pmode != SImode)
5909     pat = gen_rtx_SUBREG (SImode, pat, 0);
5910   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
5911   DONE;
5912 })
5913
5914 ;; It may seem that nonimmediate operand is proper one for operand 1.
5915 ;; The addsi_1 pattern allows nonimmediate operand at that place and
5916 ;; we take care in ix86_binary_operator_ok to not allow two memory
5917 ;; operands so proper swapping will be done in reload.  This allow
5918 ;; patterns constructed from addsi_1 to match.
5919 (define_insn "addsi_1_zext"
5920   [(set (match_operand:DI 0 "register_operand" "=r,r")
5921         (zero_extend:DI
5922           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0,r")
5923                    (match_operand:SI 2 "general_operand" "rmni,rni"))))
5924    (clobber (reg:CC 17))]
5925   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, SImode, operands)"
5926 {
5927   switch (get_attr_type (insn))
5928     {
5929     case TYPE_LEA:
5930       operands[2] = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
5931       return "lea{l}\t{%a2, %k0|%k0, %a2}";
5932
5933     case TYPE_INCDEC:
5934       if (operands[2] == const1_rtx)
5935         return "inc{l}\t%k0";
5936       else if (operands[2] == constm1_rtx)
5937         return "dec{l}\t%k0";
5938       else
5939         abort();
5940
5941     default:
5942       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
5943          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
5944       if (GET_CODE (operands[2]) == CONST_INT
5945           && (INTVAL (operands[2]) == 128
5946               || (INTVAL (operands[2]) < 0
5947                   && INTVAL (operands[2]) != -128)))
5948         {
5949           operands[2] = GEN_INT (-INTVAL (operands[2]));
5950           return "sub{l}\t{%2, %k0|%k0, %2}";
5951         }
5952       return "add{l}\t{%2, %k0|%k0, %2}";
5953     }
5954 }
5955   [(set (attr "type")
5956      (cond [(eq_attr "alternative" "1")
5957               (const_string "lea")
5958             ; Current assemblers are broken and do not allow @GOTOFF in
5959             ; ought but a memory context.
5960             (match_operand:SI 2 "pic_symbolic_operand" "")
5961               (const_string "lea")
5962             (match_operand:SI 2 "incdec_operand" "")
5963               (const_string "incdec")
5964            ]
5965            (const_string "alu")))
5966    (set_attr "mode" "SI")])
5967
5968 ;; Convert lea to the lea pattern to avoid flags dependency.
5969 (define_split
5970   [(set (match_operand:DI 0 "register_operand" "")
5971         (zero_extend:DI
5972           (plus:SI (match_operand:SI 1 "register_operand" "")
5973                    (match_operand:SI 2 "nonmemory_operand" ""))))
5974    (clobber (reg:CC 17))]
5975   "reload_completed
5976    && true_regnum (operands[0]) != true_regnum (operands[1])"
5977   [(set (match_dup 0)
5978         (zero_extend:DI (subreg:SI (plus:DI (match_dup 1) (match_dup 2)) 0)))]
5979 {
5980   operands[1] = gen_lowpart (Pmode, operands[1]);
5981   operands[2] = gen_lowpart (Pmode, operands[2]);
5982 })
5983
5984 (define_insn "*addsi_2"
5985   [(set (reg 17)
5986         (compare
5987           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0")
5988                    (match_operand:SI 2 "general_operand" "rmni,rni"))
5989           (const_int 0)))                       
5990    (set (match_operand:SI 0 "nonimmediate_operand" "=r,rm")
5991         (plus:SI (match_dup 1) (match_dup 2)))]
5992   "ix86_match_ccmode (insn, CCGOCmode)
5993    && ix86_binary_operator_ok (PLUS, SImode, operands)
5994    /* Current assemblers are broken and do not allow @GOTOFF in
5995       ought but a memory context. */
5996    && ! pic_symbolic_operand (operands[2], VOIDmode)"
5997 {
5998   switch (get_attr_type (insn))
5999     {
6000     case TYPE_INCDEC:
6001       if (! rtx_equal_p (operands[0], operands[1]))
6002         abort ();
6003       if (operands[2] == const1_rtx)
6004         return "inc{l}\t%0";
6005       else if (operands[2] == constm1_rtx)
6006         return "dec{l}\t%0";
6007       else
6008         abort();
6009
6010     default:
6011       if (! rtx_equal_p (operands[0], operands[1]))
6012         abort ();
6013       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6014          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6015       if (GET_CODE (operands[2]) == CONST_INT
6016           && (INTVAL (operands[2]) == 128
6017               || (INTVAL (operands[2]) < 0
6018                   && INTVAL (operands[2]) != -128)))
6019         {
6020           operands[2] = GEN_INT (-INTVAL (operands[2]));
6021           return "sub{l}\t{%2, %0|%0, %2}";
6022         }
6023       return "add{l}\t{%2, %0|%0, %2}";
6024     }
6025 }
6026   [(set (attr "type")
6027      (if_then_else (match_operand:SI 2 "incdec_operand" "")
6028         (const_string "incdec")
6029         (const_string "alu")))
6030    (set_attr "mode" "SI")])
6031
6032 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
6033 (define_insn "*addsi_2_zext"
6034   [(set (reg 17)
6035         (compare
6036           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
6037                    (match_operand:SI 2 "general_operand" "rmni"))
6038           (const_int 0)))                       
6039    (set (match_operand:DI 0 "register_operand" "=r")
6040         (zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))]
6041   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
6042    && ix86_binary_operator_ok (PLUS, SImode, operands)
6043    /* Current assemblers are broken and do not allow @GOTOFF in
6044       ought but a memory context. */
6045    && ! pic_symbolic_operand (operands[2], VOIDmode)"
6046 {
6047   switch (get_attr_type (insn))
6048     {
6049     case TYPE_INCDEC:
6050       if (operands[2] == const1_rtx)
6051         return "inc{l}\t%k0";
6052       else if (operands[2] == constm1_rtx)
6053         return "dec{l}\t%k0";
6054       else
6055         abort();
6056
6057     default:
6058       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6059          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6060       if (GET_CODE (operands[2]) == CONST_INT
6061           && (INTVAL (operands[2]) == 128
6062               || (INTVAL (operands[2]) < 0
6063                   && INTVAL (operands[2]) != -128)))
6064         {
6065           operands[2] = GEN_INT (-INTVAL (operands[2]));
6066           return "sub{l}\t{%2, %k0|%k0, %2}";
6067         }
6068       return "add{l}\t{%2, %k0|%k0, %2}";
6069     }
6070 }
6071   [(set (attr "type")
6072      (if_then_else (match_operand:SI 2 "incdec_operand" "")
6073         (const_string "incdec")
6074         (const_string "alu")))
6075    (set_attr "mode" "SI")])
6076
6077 (define_insn "*addsi_3"
6078   [(set (reg 17)
6079         (compare (neg:SI (match_operand:SI 2 "general_operand" "rmni"))
6080                  (match_operand:SI 1 "nonimmediate_operand" "%0")))
6081    (clobber (match_scratch:SI 0 "=r"))]
6082   "ix86_match_ccmode (insn, CCZmode)
6083    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)
6084    /* Current assemblers are broken and do not allow @GOTOFF in
6085       ought but a memory context. */
6086    && ! pic_symbolic_operand (operands[2], VOIDmode)"
6087 {
6088   switch (get_attr_type (insn))
6089     {
6090     case TYPE_INCDEC:
6091       if (! rtx_equal_p (operands[0], operands[1]))
6092         abort ();
6093       if (operands[2] == const1_rtx)
6094         return "inc{l}\t%0";
6095       else if (operands[2] == constm1_rtx)
6096         return "dec{l}\t%0";
6097       else
6098         abort();
6099
6100     default:
6101       if (! rtx_equal_p (operands[0], operands[1]))
6102         abort ();
6103       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6104          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6105       if (GET_CODE (operands[2]) == CONST_INT
6106           && (INTVAL (operands[2]) == 128
6107               || (INTVAL (operands[2]) < 0
6108                   && INTVAL (operands[2]) != -128)))
6109         {
6110           operands[2] = GEN_INT (-INTVAL (operands[2]));
6111           return "sub{l}\t{%2, %0|%0, %2}";
6112         }
6113       return "add{l}\t{%2, %0|%0, %2}";
6114     }
6115 }
6116   [(set (attr "type")
6117      (if_then_else (match_operand:SI 2 "incdec_operand" "")
6118         (const_string "incdec")
6119         (const_string "alu")))
6120    (set_attr "mode" "SI")])
6121
6122 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
6123 (define_insn "*addsi_3_zext"
6124   [(set (reg 17)
6125         (compare (neg:SI (match_operand:SI 2 "general_operand" "rmni"))
6126                  (match_operand:SI 1 "nonimmediate_operand" "%0")))
6127    (set (match_operand:DI 0 "register_operand" "=r")
6128         (zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))]
6129   "TARGET_64BIT && ix86_match_ccmode (insn, CCZmode)
6130    && ix86_binary_operator_ok (PLUS, SImode, operands)
6131    /* Current assemblers are broken and do not allow @GOTOFF in
6132       ought but a memory context. */
6133    && ! pic_symbolic_operand (operands[2], VOIDmode)"
6134 {
6135   switch (get_attr_type (insn))
6136     {
6137     case TYPE_INCDEC:
6138       if (operands[2] == const1_rtx)
6139         return "inc{l}\t%k0";
6140       else if (operands[2] == constm1_rtx)
6141         return "dec{l}\t%k0";
6142       else
6143         abort();
6144
6145     default:
6146       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6147          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6148       if (GET_CODE (operands[2]) == CONST_INT
6149           && (INTVAL (operands[2]) == 128
6150               || (INTVAL (operands[2]) < 0
6151                   && INTVAL (operands[2]) != -128)))
6152         {
6153           operands[2] = GEN_INT (-INTVAL (operands[2]));
6154           return "sub{l}\t{%2, %k0|%k0, %2}";
6155         }
6156       return "add{l}\t{%2, %k0|%k0, %2}";
6157     }
6158 }
6159   [(set (attr "type")
6160      (if_then_else (match_operand:SI 2 "incdec_operand" "")
6161         (const_string "incdec")
6162         (const_string "alu")))
6163    (set_attr "mode" "SI")])
6164
6165 ; For comparisons agains 1, -1 and 128, we may generate better code
6166 ; by converting cmp to add, inc or dec as done by peephole2.  This pattern
6167 ; is matched then.  We can't accept general immediate, because for
6168 ; case of overflows,  the result is messed up.
6169 ; This pattern also don't hold of 0x80000000, since the value overflows
6170 ; when negated.
6171 ; Also carry flag is reversed compared to cmp, so this converison is valid
6172 ; only for comparisons not depending on it.
6173 (define_insn "*addsi_4"
6174   [(set (reg 17)
6175         (compare (match_operand:SI 1 "nonimmediate_operand" "0")
6176                  (match_operand:SI 2 "const_int_operand" "n")))
6177    (clobber (match_scratch:SI 0 "=rm"))]
6178   "ix86_match_ccmode (insn, CCGCmode)
6179    && (INTVAL (operands[2]) & 0xffffffff) != 0x80000000"
6180 {
6181   switch (get_attr_type (insn))
6182     {
6183     case TYPE_INCDEC:
6184       if (operands[2] == constm1_rtx)
6185         return "inc{l}\t%0";
6186       else if (operands[2] == const1_rtx)
6187         return "dec{l}\t%0";
6188       else
6189         abort();
6190
6191     default:
6192       if (! rtx_equal_p (operands[0], operands[1]))
6193         abort ();
6194       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6195          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6196       if ((INTVAL (operands[2]) == -128
6197            || (INTVAL (operands[2]) > 0
6198                && INTVAL (operands[2]) != 128)))
6199         return "sub{l}\t{%2, %0|%0, %2}";
6200       operands[2] = GEN_INT (-INTVAL (operands[2]));
6201       return "add{l}\t{%2, %0|%0, %2}";
6202     }
6203 }
6204   [(set (attr "type")
6205      (if_then_else (match_operand:SI 2 "incdec_operand" "")
6206         (const_string "incdec")
6207         (const_string "alu")))
6208    (set_attr "mode" "SI")])
6209
6210 (define_insn "*addsi_5"
6211   [(set (reg 17)
6212         (compare
6213           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
6214                    (match_operand:SI 2 "general_operand" "rmni"))
6215           (const_int 0)))                       
6216    (clobber (match_scratch:SI 0 "=r"))]
6217   "ix86_match_ccmode (insn, CCGOCmode)
6218    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)
6219    /* Current assemblers are broken and do not allow @GOTOFF in
6220       ought but a memory context. */
6221    && ! pic_symbolic_operand (operands[2], VOIDmode)"
6222 {
6223   switch (get_attr_type (insn))
6224     {
6225     case TYPE_INCDEC:
6226       if (! rtx_equal_p (operands[0], operands[1]))
6227         abort ();
6228       if (operands[2] == const1_rtx)
6229         return "inc{l}\t%0";
6230       else if (operands[2] == constm1_rtx)
6231         return "dec{l}\t%0";
6232       else
6233         abort();
6234
6235     default:
6236       if (! rtx_equal_p (operands[0], operands[1]))
6237         abort ();
6238       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6239          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6240       if (GET_CODE (operands[2]) == CONST_INT
6241           && (INTVAL (operands[2]) == 128
6242               || (INTVAL (operands[2]) < 0
6243                   && INTVAL (operands[2]) != -128)))
6244         {
6245           operands[2] = GEN_INT (-INTVAL (operands[2]));
6246           return "sub{l}\t{%2, %0|%0, %2}";
6247         }
6248       return "add{l}\t{%2, %0|%0, %2}";
6249     }
6250 }
6251   [(set (attr "type")
6252      (if_then_else (match_operand:SI 2 "incdec_operand" "")
6253         (const_string "incdec")
6254         (const_string "alu")))
6255    (set_attr "mode" "SI")])
6256
6257 (define_expand "addhi3"
6258   [(parallel [(set (match_operand:HI 0 "nonimmediate_operand" "")
6259                    (plus:HI (match_operand:HI 1 "nonimmediate_operand" "")
6260                             (match_operand:HI 2 "general_operand" "")))
6261               (clobber (reg:CC 17))])]
6262   "TARGET_HIMODE_MATH"
6263   "ix86_expand_binary_operator (PLUS, HImode, operands); DONE;")
6264
6265 ;; %%% After Dave's SUBREG_BYTE stuff goes in, re-enable incb %ah
6266 ;; type optimizations enabled by define-splits.  This is not important
6267 ;; for PII, and in fact harmful because of partial register stalls.
6268
6269 (define_insn "*addhi_1_lea"
6270   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r,r")
6271         (plus:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,r")
6272                  (match_operand:HI 2 "general_operand" "ri,rm,rni")))
6273    (clobber (reg:CC 17))]
6274   "!TARGET_PARTIAL_REG_STALL
6275    && ix86_binary_operator_ok (PLUS, HImode, operands)"
6276 {
6277   switch (get_attr_type (insn))
6278     {
6279     case TYPE_LEA:
6280       return "#";
6281     case TYPE_INCDEC:
6282       if (operands[2] == const1_rtx)
6283         return "inc{w}\t%0";
6284       else if (operands[2] == constm1_rtx
6285                || (GET_CODE (operands[2]) == CONST_INT
6286                    && INTVAL (operands[2]) == 65535))
6287         return "dec{w}\t%0";
6288       abort();
6289
6290     default:
6291       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6292          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6293       if (GET_CODE (operands[2]) == CONST_INT
6294           && (INTVAL (operands[2]) == 128
6295               || (INTVAL (operands[2]) < 0
6296                   && INTVAL (operands[2]) != -128)))
6297         {
6298           operands[2] = GEN_INT (-INTVAL (operands[2]));
6299           return "sub{w}\t{%2, %0|%0, %2}";
6300         }
6301       return "add{w}\t{%2, %0|%0, %2}";
6302     }
6303 }
6304   [(set (attr "type")
6305      (if_then_else (eq_attr "alternative" "2")
6306         (const_string "lea")
6307         (if_then_else (match_operand:HI 2 "incdec_operand" "")
6308            (const_string "incdec")
6309            (const_string "alu"))))
6310    (set_attr "mode" "HI,HI,SI")])
6311
6312 (define_insn "*addhi_1"
6313   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r")
6314         (plus:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
6315                  (match_operand:HI 2 "general_operand" "ri,rm")))
6316    (clobber (reg:CC 17))]
6317   "TARGET_PARTIAL_REG_STALL
6318    && ix86_binary_operator_ok (PLUS, HImode, operands)"
6319 {
6320   switch (get_attr_type (insn))
6321     {
6322     case TYPE_INCDEC:
6323       if (operands[2] == const1_rtx)
6324         return "inc{w}\t%0";
6325       else if (operands[2] == constm1_rtx
6326                || (GET_CODE (operands[2]) == CONST_INT
6327                    && INTVAL (operands[2]) == 65535))
6328         return "dec{w}\t%0";
6329       abort();
6330
6331     default:
6332       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6333          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6334       if (GET_CODE (operands[2]) == CONST_INT
6335           && (INTVAL (operands[2]) == 128
6336               || (INTVAL (operands[2]) < 0
6337                   && INTVAL (operands[2]) != -128)))
6338         {
6339           operands[2] = GEN_INT (-INTVAL (operands[2]));
6340           return "sub{w}\t{%2, %0|%0, %2}";
6341         }
6342       return "add{w}\t{%2, %0|%0, %2}";
6343     }
6344 }
6345   [(set (attr "type")
6346      (if_then_else (match_operand:HI 2 "incdec_operand" "")
6347         (const_string "incdec")
6348         (const_string "alu")))
6349    (set_attr "mode" "HI")])
6350
6351 (define_insn "*addhi_2"
6352   [(set (reg 17)
6353         (compare
6354           (plus:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
6355                    (match_operand:HI 2 "general_operand" "rmni,rni"))
6356           (const_int 0)))                       
6357    (set (match_operand:HI 0 "nonimmediate_operand" "=r,rm")
6358         (plus:HI (match_dup 1) (match_dup 2)))]
6359   "ix86_match_ccmode (insn, CCGOCmode)
6360    && ix86_binary_operator_ok (PLUS, HImode, operands)"
6361 {
6362   switch (get_attr_type (insn))
6363     {
6364     case TYPE_INCDEC:
6365       if (operands[2] == const1_rtx)
6366         return "inc{w}\t%0";
6367       else if (operands[2] == constm1_rtx
6368                || (GET_CODE (operands[2]) == CONST_INT
6369                    && INTVAL (operands[2]) == 65535))
6370         return "dec{w}\t%0";
6371       abort();
6372
6373     default:
6374       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6375          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6376       if (GET_CODE (operands[2]) == CONST_INT
6377           && (INTVAL (operands[2]) == 128
6378               || (INTVAL (operands[2]) < 0
6379                   && INTVAL (operands[2]) != -128)))
6380         {
6381           operands[2] = GEN_INT (-INTVAL (operands[2]));
6382           return "sub{w}\t{%2, %0|%0, %2}";
6383         }
6384       return "add{w}\t{%2, %0|%0, %2}";
6385     }
6386 }
6387   [(set (attr "type")
6388      (if_then_else (match_operand:HI 2 "incdec_operand" "")
6389         (const_string "incdec")
6390         (const_string "alu")))
6391    (set_attr "mode" "HI")])
6392
6393 (define_insn "*addhi_3"
6394   [(set (reg 17)
6395         (compare (neg:HI (match_operand:HI 2 "general_operand" "rmni"))
6396                  (match_operand:HI 1 "nonimmediate_operand" "%0")))
6397    (clobber (match_scratch:HI 0 "=r"))]
6398   "ix86_match_ccmode (insn, CCZmode)
6399    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
6400 {
6401   switch (get_attr_type (insn))
6402     {
6403     case TYPE_INCDEC:
6404       if (operands[2] == const1_rtx)
6405         return "inc{w}\t%0";
6406       else if (operands[2] == constm1_rtx
6407                || (GET_CODE (operands[2]) == CONST_INT
6408                    && INTVAL (operands[2]) == 65535))
6409         return "dec{w}\t%0";
6410       abort();
6411
6412     default:
6413       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6414          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6415       if (GET_CODE (operands[2]) == CONST_INT
6416           && (INTVAL (operands[2]) == 128
6417               || (INTVAL (operands[2]) < 0
6418                   && INTVAL (operands[2]) != -128)))
6419         {
6420           operands[2] = GEN_INT (-INTVAL (operands[2]));
6421           return "sub{w}\t{%2, %0|%0, %2}";
6422         }
6423       return "add{w}\t{%2, %0|%0, %2}";
6424     }
6425 }
6426   [(set (attr "type")
6427      (if_then_else (match_operand:HI 2 "incdec_operand" "")
6428         (const_string "incdec")
6429         (const_string "alu")))
6430    (set_attr "mode" "HI")])
6431
6432 ; See comments above addsi_3_imm for details.
6433 (define_insn "*addhi_4"
6434   [(set (reg 17)
6435         (compare (match_operand:HI 1 "nonimmediate_operand" "0")
6436                  (match_operand:HI 2 "const_int_operand" "n")))
6437    (clobber (match_scratch:HI 0 "=rm"))]
6438   "ix86_match_ccmode (insn, CCGCmode)
6439    && (INTVAL (operands[2]) & 0xffff) != 0x8000"
6440 {
6441   switch (get_attr_type (insn))
6442     {
6443     case TYPE_INCDEC:
6444       if (operands[2] == constm1_rtx
6445           || (GET_CODE (operands[2]) == CONST_INT
6446               && INTVAL (operands[2]) == 65535))
6447         return "inc{w}\t%0";
6448       else if (operands[2] == const1_rtx)
6449         return "dec{w}\t%0";
6450       else
6451         abort();
6452
6453     default:
6454       if (! rtx_equal_p (operands[0], operands[1]))
6455         abort ();
6456       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6457          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6458       if ((INTVAL (operands[2]) == -128
6459            || (INTVAL (operands[2]) > 0
6460                && INTVAL (operands[2]) != 128)))
6461         return "sub{w}\t{%2, %0|%0, %2}";
6462       operands[2] = GEN_INT (-INTVAL (operands[2]));
6463       return "add{w}\t{%2, %0|%0, %2}";
6464     }
6465 }
6466   [(set (attr "type")
6467      (if_then_else (match_operand:HI 2 "incdec_operand" "")
6468         (const_string "incdec")
6469         (const_string "alu")))
6470    (set_attr "mode" "SI")])
6471
6472
6473 (define_insn "*addhi_5"
6474   [(set (reg 17)
6475         (compare
6476           (plus:HI (match_operand:HI 1 "nonimmediate_operand" "%0")
6477                    (match_operand:HI 2 "general_operand" "rmni"))
6478           (const_int 0)))                       
6479    (clobber (match_scratch:HI 0 "=r"))]
6480   "ix86_match_ccmode (insn, CCGOCmode)
6481    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
6482 {
6483   switch (get_attr_type (insn))
6484     {
6485     case TYPE_INCDEC:
6486       if (operands[2] == const1_rtx)
6487         return "inc{w}\t%0";
6488       else if (operands[2] == constm1_rtx
6489                || (GET_CODE (operands[2]) == CONST_INT
6490                    && INTVAL (operands[2]) == 65535))
6491         return "dec{w}\t%0";
6492       abort();
6493
6494     default:
6495       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6496          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6497       if (GET_CODE (operands[2]) == CONST_INT
6498           && (INTVAL (operands[2]) == 128
6499               || (INTVAL (operands[2]) < 0
6500                   && INTVAL (operands[2]) != -128)))
6501         {
6502           operands[2] = GEN_INT (-INTVAL (operands[2]));
6503           return "sub{w}\t{%2, %0|%0, %2}";
6504         }
6505       return "add{w}\t{%2, %0|%0, %2}";
6506     }
6507 }
6508   [(set (attr "type")
6509      (if_then_else (match_operand:HI 2 "incdec_operand" "")
6510         (const_string "incdec")
6511         (const_string "alu")))
6512    (set_attr "mode" "HI")])
6513
6514 (define_expand "addqi3"
6515   [(parallel [(set (match_operand:QI 0 "nonimmediate_operand" "")
6516                    (plus:QI (match_operand:QI 1 "nonimmediate_operand" "")
6517                             (match_operand:QI 2 "general_operand" "")))
6518               (clobber (reg:CC 17))])]
6519   "TARGET_QIMODE_MATH"
6520   "ix86_expand_binary_operator (PLUS, QImode, operands); DONE;")
6521
6522 ;; %%% Potential partial reg stall on alternative 2.  What to do?
6523 (define_insn "*addqi_1_lea"
6524   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,q,r,r")
6525         (plus:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0,r")
6526                  (match_operand:QI 2 "general_operand" "qn,qmn,rn,rn")))
6527    (clobber (reg:CC 17))]
6528   "!TARGET_PARTIAL_REG_STALL
6529    && ix86_binary_operator_ok (PLUS, QImode, operands)"
6530 {
6531   int widen = (which_alternative == 2);
6532   switch (get_attr_type (insn))
6533     {
6534     case TYPE_LEA:
6535       return "#";
6536     case TYPE_INCDEC:
6537       if (operands[2] == const1_rtx)
6538         return widen ? "inc{l}\t%k0" : "inc{b}\t%0";
6539       else if (operands[2] == constm1_rtx
6540                || (GET_CODE (operands[2]) == CONST_INT
6541                    && INTVAL (operands[2]) == 255))
6542         return widen ? "dec{l}\t%k0" : "dec{b}\t%0";
6543       abort();
6544
6545     default:
6546       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6547          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6548       if (GET_CODE (operands[2]) == CONST_INT
6549           && (INTVAL (operands[2]) == 128
6550               || (INTVAL (operands[2]) < 0
6551                   && INTVAL (operands[2]) != -128)))
6552         {
6553           operands[2] = GEN_INT (-INTVAL (operands[2]));
6554           if (widen)
6555             return "sub{l}\t{%2, %k0|%k0, %2}";
6556           else
6557             return "sub{b}\t{%2, %0|%0, %2}";
6558         }
6559       if (widen)
6560         return "add{l}\t{%k2, %k0|%k0, %k2}";
6561       else
6562         return "add{b}\t{%2, %0|%0, %2}";
6563     }
6564 }
6565   [(set (attr "type")
6566      (if_then_else (eq_attr "alternative" "3")
6567         (const_string "lea")
6568         (if_then_else (match_operand:QI 2 "incdec_operand" "")
6569            (const_string "incdec")
6570            (const_string "alu"))))
6571    (set_attr "mode" "QI,QI,SI,SI")])
6572
6573 (define_insn "*addqi_1"
6574   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,q,r")
6575         (plus:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
6576                  (match_operand:QI 2 "general_operand" "qn,qmn,rn")))
6577    (clobber (reg:CC 17))]
6578   "TARGET_PARTIAL_REG_STALL
6579    && ix86_binary_operator_ok (PLUS, QImode, operands)"
6580 {
6581   int widen = (which_alternative == 2);
6582   switch (get_attr_type (insn))
6583     {
6584     case TYPE_INCDEC:
6585       if (operands[2] == const1_rtx)
6586         return widen ? "inc{l}\t%k0" : "inc{b}\t%0";
6587       else if (operands[2] == constm1_rtx
6588                || (GET_CODE (operands[2]) == CONST_INT
6589                    && INTVAL (operands[2]) == 255))
6590         return widen ? "dec{l}\t%k0" : "dec{b}\t%0";
6591       abort();
6592
6593     default:
6594       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6595          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6596       if (GET_CODE (operands[2]) == CONST_INT
6597           && (INTVAL (operands[2]) == 128
6598               || (INTVAL (operands[2]) < 0
6599                   && INTVAL (operands[2]) != -128)))
6600         {
6601           operands[2] = GEN_INT (-INTVAL (operands[2]));
6602           if (widen)
6603             return "sub{l}\t{%2, %k0|%k0, %2}";
6604           else
6605             return "sub{b}\t{%2, %0|%0, %2}";
6606         }
6607       if (widen)
6608         return "add{l}\t{%k2, %k0|%k0, %k2}";
6609       else
6610         return "add{b}\t{%2, %0|%0, %2}";
6611     }
6612 }
6613   [(set (attr "type")
6614      (if_then_else (match_operand:QI 2 "incdec_operand" "")
6615         (const_string "incdec")
6616         (const_string "alu")))
6617    (set_attr "mode" "QI,QI,SI")])
6618
6619 (define_insn "*addqi_2"
6620   [(set (reg 17)
6621         (compare
6622           (plus:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0")
6623                    (match_operand:QI 2 "general_operand" "qmni,qni"))
6624           (const_int 0)))
6625    (set (match_operand:QI 0 "nonimmediate_operand" "=q,qm")
6626         (plus:QI (match_dup 1) (match_dup 2)))]
6627   "ix86_match_ccmode (insn, CCGOCmode)
6628    && ix86_binary_operator_ok (PLUS, QImode, operands)"
6629 {
6630   switch (get_attr_type (insn))
6631     {
6632     case TYPE_INCDEC:
6633       if (operands[2] == const1_rtx)
6634         return "inc{b}\t%0";
6635       else if (operands[2] == constm1_rtx
6636                || (GET_CODE (operands[2]) == CONST_INT
6637                    && INTVAL (operands[2]) == 255))
6638         return "dec{b}\t%0";
6639       abort();
6640
6641     default:
6642       /* Make things pretty and `subb $4,%al' rather than `addb $-4, %al'.  */
6643       if (GET_CODE (operands[2]) == CONST_INT
6644           && INTVAL (operands[2]) < 0)
6645         {
6646           operands[2] = GEN_INT (-INTVAL (operands[2]));
6647           return "sub{b}\t{%2, %0|%0, %2}";
6648         }
6649       return "add{b}\t{%2, %0|%0, %2}";
6650     }
6651 }
6652   [(set (attr "type")
6653      (if_then_else (match_operand:QI 2 "incdec_operand" "")
6654         (const_string "incdec")
6655         (const_string "alu")))
6656    (set_attr "mode" "QI")])
6657
6658 (define_insn "*addqi_3"
6659   [(set (reg 17)
6660         (compare (neg:QI (match_operand:QI 2 "general_operand" "qmni"))
6661                  (match_operand:QI 1 "nonimmediate_operand" "%0")))
6662    (clobber (match_scratch:QI 0 "=q"))]
6663   "ix86_match_ccmode (insn, CCZmode)
6664    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
6665 {
6666   switch (get_attr_type (insn))
6667     {
6668     case TYPE_INCDEC:
6669       if (operands[2] == const1_rtx)
6670         return "inc{b}\t%0";
6671       else if (operands[2] == constm1_rtx
6672                || (GET_CODE (operands[2]) == CONST_INT
6673                    && INTVAL (operands[2]) == 255))
6674         return "dec{b}\t%0";
6675       abort();
6676
6677     default:
6678       /* Make things pretty and `subb $4,%al' rather than `addb $-4, %al'.  */
6679       if (GET_CODE (operands[2]) == CONST_INT
6680           && INTVAL (operands[2]) < 0)
6681         {
6682           operands[2] = GEN_INT (-INTVAL (operands[2]));
6683           return "sub{b}\t{%2, %0|%0, %2}";
6684         }
6685       return "add{b}\t{%2, %0|%0, %2}";
6686     }
6687 }
6688   [(set (attr "type")
6689      (if_then_else (match_operand:QI 2 "incdec_operand" "")
6690         (const_string "incdec")
6691         (const_string "alu")))
6692    (set_attr "mode" "QI")])
6693
6694 ; See comments above addsi_3_imm for details.
6695 (define_insn "*addqi_4"
6696   [(set (reg 17)
6697         (compare (match_operand:QI 1 "nonimmediate_operand" "0")
6698                  (match_operand:QI 2 "const_int_operand" "n")))
6699    (clobber (match_scratch:QI 0 "=qm"))]
6700   "ix86_match_ccmode (insn, CCGCmode)
6701    && (INTVAL (operands[2]) & 0xff) != 0x80"
6702 {
6703   switch (get_attr_type (insn))
6704     {
6705     case TYPE_INCDEC:
6706       if (operands[2] == constm1_rtx
6707           || (GET_CODE (operands[2]) == CONST_INT
6708               && INTVAL (operands[2]) == 255))
6709         return "inc{b}\t%0";
6710       else if (operands[2] == const1_rtx)
6711         return "dec{b}\t%0";
6712       else
6713         abort();
6714
6715     default:
6716       if (! rtx_equal_p (operands[0], operands[1]))
6717         abort ();
6718       if (INTVAL (operands[2]) < 0)
6719         {
6720           operands[2] = GEN_INT (-INTVAL (operands[2]));
6721           return "add{b}\t{%2, %0|%0, %2}";
6722         }
6723       return "sub{b}\t{%2, %0|%0, %2}";
6724     }
6725 }
6726   [(set (attr "type")
6727      (if_then_else (match_operand:HI 2 "incdec_operand" "")
6728         (const_string "incdec")
6729         (const_string "alu")))
6730    (set_attr "mode" "QI")])
6731
6732
6733 (define_insn "*addqi_5"
6734   [(set (reg 17)
6735         (compare
6736           (plus:QI (match_operand:QI 1 "nonimmediate_operand" "%0")
6737                    (match_operand:QI 2 "general_operand" "qmni"))
6738           (const_int 0)))
6739    (clobber (match_scratch:QI 0 "=q"))]
6740   "ix86_match_ccmode (insn, CCGOCmode)
6741    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
6742 {
6743   switch (get_attr_type (insn))
6744     {
6745     case TYPE_INCDEC:
6746       if (operands[2] == const1_rtx)
6747         return "inc{b}\t%0";
6748       else if (operands[2] == constm1_rtx
6749                || (GET_CODE (operands[2]) == CONST_INT
6750                    && INTVAL (operands[2]) == 255))
6751         return "dec{b}\t%0";
6752       abort();
6753
6754     default:
6755       /* Make things pretty and `subb $4,%al' rather than `addb $-4, %al'.  */
6756       if (GET_CODE (operands[2]) == CONST_INT
6757           && INTVAL (operands[2]) < 0)
6758         {
6759           operands[2] = GEN_INT (-INTVAL (operands[2]));
6760           return "sub{b}\t{%2, %0|%0, %2}";
6761         }
6762       return "add{b}\t{%2, %0|%0, %2}";
6763     }
6764 }
6765   [(set (attr "type")
6766      (if_then_else (match_operand:QI 2 "incdec_operand" "")
6767         (const_string "incdec")
6768         (const_string "alu")))
6769    (set_attr "mode" "QI")])
6770
6771
6772 (define_insn "addqi_ext_1"
6773   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
6774                          (const_int 8)
6775                          (const_int 8))
6776         (plus:SI
6777           (zero_extract:SI
6778             (match_operand 1 "ext_register_operand" "0")
6779             (const_int 8)
6780             (const_int 8))
6781           (match_operand:QI 2 "general_operand" "Qmn")))
6782    (clobber (reg:CC 17))]
6783   "!TARGET_64BIT"
6784 {
6785   switch (get_attr_type (insn))
6786     {
6787     case TYPE_INCDEC:
6788       if (operands[2] == const1_rtx)
6789         return "inc{b}\t%h0";
6790       else if (operands[2] == constm1_rtx
6791                || (GET_CODE (operands[2]) == CONST_INT
6792                    && INTVAL (operands[2]) == 255))
6793         return "dec{b}\t%h0";
6794       abort();
6795
6796     default:
6797       return "add{b}\t{%2, %h0|%h0, %2}";
6798     }
6799 }
6800   [(set (attr "type")
6801      (if_then_else (match_operand:QI 2 "incdec_operand" "")
6802         (const_string "incdec")
6803         (const_string "alu")))
6804    (set_attr "mode" "QI")])
6805
6806 (define_insn "*addqi_ext_1_rex64"
6807   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
6808                          (const_int 8)
6809                          (const_int 8))
6810         (plus:SI
6811           (zero_extract:SI
6812             (match_operand 1 "ext_register_operand" "0")
6813             (const_int 8)
6814             (const_int 8))
6815           (match_operand:QI 2 "nonmemory_operand" "Qn")))
6816    (clobber (reg:CC 17))]
6817   "TARGET_64BIT"
6818 {
6819   switch (get_attr_type (insn))
6820     {
6821     case TYPE_INCDEC:
6822       if (operands[2] == const1_rtx)
6823         return "inc{b}\t%h0";
6824       else if (operands[2] == constm1_rtx
6825                || (GET_CODE (operands[2]) == CONST_INT
6826                    && INTVAL (operands[2]) == 255))
6827         return "dec{b}\t%h0";
6828       abort();
6829
6830     default:
6831       return "add{b}\t{%2, %h0|%h0, %2}";
6832     }
6833 }
6834   [(set (attr "type")
6835      (if_then_else (match_operand:QI 2 "incdec_operand" "")
6836         (const_string "incdec")
6837         (const_string "alu")))
6838    (set_attr "mode" "QI")])
6839
6840 (define_insn "*addqi_ext_2"
6841   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
6842                          (const_int 8)
6843                          (const_int 8))
6844         (plus:SI
6845           (zero_extract:SI
6846             (match_operand 1 "ext_register_operand" "%0")
6847             (const_int 8)
6848             (const_int 8))
6849           (zero_extract:SI
6850             (match_operand 2 "ext_register_operand" "Q")
6851             (const_int 8)
6852             (const_int 8))))
6853    (clobber (reg:CC 17))]
6854   ""
6855   "add{b}\t{%h2, %h0|%h0, %h2}"
6856   [(set_attr "type" "alu")
6857    (set_attr "mode" "QI")])
6858
6859 ;; The patterns that match these are at the end of this file.
6860
6861 (define_expand "addxf3"
6862   [(set (match_operand:XF 0 "register_operand" "")
6863         (plus:XF (match_operand:XF 1 "register_operand" "")
6864                  (match_operand:XF 2 "register_operand" "")))]
6865   "TARGET_80387 && !TARGET_64BIT"
6866   "")
6867
6868 (define_expand "addtf3"
6869   [(set (match_operand:TF 0 "register_operand" "")
6870         (plus:TF (match_operand:TF 1 "register_operand" "")
6871                  (match_operand:TF 2 "register_operand" "")))]
6872   "TARGET_80387"
6873   "")
6874
6875 (define_expand "adddf3"
6876   [(set (match_operand:DF 0 "register_operand" "")
6877         (plus:DF (match_operand:DF 1 "register_operand" "")
6878                  (match_operand:DF 2 "nonimmediate_operand" "")))]
6879   "TARGET_80387 || TARGET_SSE2"
6880   "")
6881
6882 (define_expand "addsf3"
6883   [(set (match_operand:SF 0 "register_operand" "")
6884         (plus:SF (match_operand:SF 1 "register_operand" "")
6885                  (match_operand:SF 2 "nonimmediate_operand" "")))]
6886   "TARGET_80387 || TARGET_SSE"
6887   "")
6888 \f
6889 ;; Subtract instructions
6890
6891 ;; %%% splits for subsidi3
6892
6893 (define_expand "subdi3"
6894   [(parallel [(set (match_operand:DI 0 "nonimmediate_operand" "")
6895                    (minus:DI (match_operand:DI 1 "nonimmediate_operand" "")
6896                              (match_operand:DI 2 "x86_64_general_operand" "")))
6897               (clobber (reg:CC 17))])]
6898   ""
6899   "ix86_expand_binary_operator (MINUS, DImode, operands); DONE;")
6900
6901 (define_insn "*subdi3_1"
6902   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,o")
6903         (minus:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
6904                   (match_operand:DI 2 "general_operand" "roiF,riF")))
6905    (clobber (reg:CC 17))]
6906   "!TARGET_64BIT"
6907   "#")
6908
6909 (define_split
6910   [(set (match_operand:DI 0 "nonimmediate_operand" "")
6911         (minus:DI (match_operand:DI 1 "nonimmediate_operand" "")
6912                   (match_operand:DI 2 "general_operand" "")))
6913    (clobber (reg:CC 17))]
6914   "reload_completed && !TARGET_64BIT"
6915   [(parallel [(set (reg:CC 17) (compare:CC (match_dup 1) (match_dup 2)))
6916               (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 2)))])
6917    (parallel [(set (match_dup 3)
6918                    (minus:SI (match_dup 4)
6919                              (plus:SI (ltu:SI (reg:CC 17) (const_int 0))
6920                                       (match_dup 5))))
6921               (clobber (reg:CC 17))])]
6922   "split_di (operands+0, 1, operands+0, operands+3);
6923    split_di (operands+1, 1, operands+1, operands+4);
6924    split_di (operands+2, 1, operands+2, operands+5);")
6925
6926 (define_insn "subdi3_carry_rex64"
6927   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
6928           (minus:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
6929             (plus:DI (ltu:DI (reg:CC 17) (const_int 0))
6930                (match_operand:DI 2 "x86_64_general_operand" "re,rm"))))
6931    (clobber (reg:CC 17))]
6932   "ix86_binary_operator_ok (MINUS, DImode, operands)"
6933   "sbb{q}\t{%2, %0|%0, %2}"
6934   [(set_attr "type" "alu")
6935    (set_attr "pent_pair" "pu")
6936    (set_attr "ppro_uops" "few")
6937    (set_attr "mode" "DI")])
6938
6939 (define_insn "*subdi_1_rex64"
6940   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
6941         (minus:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
6942                   (match_operand:DI 2 "x86_64_general_operand" "re,rm")))
6943    (clobber (reg:CC 17))]
6944   "TARGET_64BIT && ix86_binary_operator_ok (MINUS, DImode, operands)"
6945   "sub{q}\t{%2, %0|%0, %2}"
6946   [(set_attr "type" "alu")
6947    (set_attr "mode" "DI")])
6948
6949 (define_insn "*subdi_2_rex64"
6950   [(set (reg 17)
6951         (compare
6952           (minus:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
6953                     (match_operand:DI 2 "x86_64_general_operand" "re,rm"))
6954           (const_int 0)))
6955    (set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
6956         (minus:DI (match_dup 1) (match_dup 2)))]
6957   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
6958    && ix86_binary_operator_ok (MINUS, DImode, operands)"
6959   "sub{q}\t{%2, %0|%0, %2}"
6960   [(set_attr "type" "alu")
6961    (set_attr "mode" "DI")])
6962
6963 (define_insn "*subdi_3_rex63"
6964   [(set (reg 17)
6965         (compare (match_operand:DI 1 "nonimmediate_operand" "0,0")
6966                  (match_operand:DI 2 "x86_64_general_operand" "re,rm")))
6967    (set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
6968         (minus:DI (match_dup 1) (match_dup 2)))]
6969   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)
6970    && ix86_binary_operator_ok (MINUS, SImode, operands)"
6971   "sub{q}\t{%2, %0|%0, %2}"
6972   [(set_attr "type" "alu")
6973    (set_attr "mode" "DI")])
6974
6975
6976 (define_insn "subsi3_carry"
6977   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
6978           (minus:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
6979             (plus:SI (ltu:SI (reg:CC 17) (const_int 0))
6980                (match_operand:SI 2 "general_operand" "ri,rm"))))
6981    (clobber (reg:CC 17))]
6982   "ix86_binary_operator_ok (MINUS, SImode, operands)"
6983   "sbb{l}\t{%2, %0|%0, %2}"
6984   [(set_attr "type" "alu")
6985    (set_attr "pent_pair" "pu")
6986    (set_attr "ppro_uops" "few")
6987    (set_attr "mode" "SI")])
6988
6989 (define_insn "subsi3_carry_zext"
6990   [(set (match_operand:DI 0 "register_operand" "=rm,r")
6991           (zero_extend:DI
6992             (minus:SI (match_operand:SI 1 "register_operand" "0,0")
6993               (plus:SI (ltu:SI (reg:CC 17) (const_int 0))
6994                  (match_operand:SI 2 "general_operand" "ri,rm")))))
6995    (clobber (reg:CC 17))]
6996   "TARGET_64BIT && ix86_binary_operator_ok (MINUS, SImode, operands)"
6997   "sbb{l}\t{%2, %k0|%k0, %2}"
6998   [(set_attr "type" "alu")
6999    (set_attr "pent_pair" "pu")
7000    (set_attr "ppro_uops" "few")
7001    (set_attr "mode" "SI")])
7002
7003 (define_expand "subsi3"
7004   [(parallel [(set (match_operand:SI 0 "nonimmediate_operand" "")
7005                    (minus:SI (match_operand:SI 1 "nonimmediate_operand" "")
7006                              (match_operand:SI 2 "general_operand" "")))
7007               (clobber (reg:CC 17))])]
7008   ""
7009   "ix86_expand_binary_operator (MINUS, SImode, operands); DONE;")
7010
7011 (define_insn "*subsi_1"
7012   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
7013         (minus:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
7014                   (match_operand:SI 2 "general_operand" "ri,rm")))
7015    (clobber (reg:CC 17))]
7016   "ix86_binary_operator_ok (MINUS, SImode, operands)"
7017   "sub{l}\t{%2, %0|%0, %2}"
7018   [(set_attr "type" "alu")
7019    (set_attr "mode" "SI")])
7020
7021 (define_insn "*subsi_1_zext"
7022   [(set (match_operand:DI 0 "register_operand" "=r")
7023         (zero_extend:DI
7024           (minus:SI (match_operand:SI 1 "register_operand" "0")
7025                     (match_operand:SI 2 "general_operand" "rim"))))
7026    (clobber (reg:CC 17))]
7027   "TARGET_64BIT && ix86_binary_operator_ok (MINUS, SImode, operands)"
7028   "sub{l}\t{%2, %k0|%k0, %2}"
7029   [(set_attr "type" "alu")
7030    (set_attr "mode" "SI")])
7031
7032 (define_insn "*subsi_2"
7033   [(set (reg 17)
7034         (compare
7035           (minus:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
7036                     (match_operand:SI 2 "general_operand" "ri,rm"))
7037           (const_int 0)))
7038    (set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
7039         (minus:SI (match_dup 1) (match_dup 2)))]
7040   "ix86_match_ccmode (insn, CCGOCmode)
7041    && ix86_binary_operator_ok (MINUS, SImode, operands)"
7042   "sub{l}\t{%2, %0|%0, %2}"
7043   [(set_attr "type" "alu")
7044    (set_attr "mode" "SI")])
7045
7046 (define_insn "*subsi_2_zext"
7047   [(set (reg 17)
7048         (compare
7049           (minus:SI (match_operand:SI 1 "register_operand" "0")
7050                     (match_operand:SI 2 "general_operand" "rim"))
7051           (const_int 0)))
7052    (set (match_operand:DI 0 "register_operand" "=r")
7053         (zero_extend:DI
7054           (minus:SI (match_dup 1)
7055                     (match_dup 2))))]
7056   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
7057    && ix86_binary_operator_ok (MINUS, SImode, operands)"
7058   "sub{l}\t{%2, %k0|%k0, %2}"
7059   [(set_attr "type" "alu")
7060    (set_attr "mode" "SI")])
7061
7062 (define_insn "*subsi_3"
7063   [(set (reg 17)
7064         (compare (match_operand:SI 1 "nonimmediate_operand" "0,0")
7065                  (match_operand:SI 2 "general_operand" "ri,rm")))
7066    (set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
7067         (minus:SI (match_dup 1) (match_dup 2)))]
7068   "ix86_match_ccmode (insn, CCmode)
7069    && ix86_binary_operator_ok (MINUS, SImode, operands)"
7070   "sub{l}\t{%2, %0|%0, %2}"
7071   [(set_attr "type" "alu")
7072    (set_attr "mode" "SI")])
7073
7074 (define_insn "*subsi_3_zext"
7075   [(set (reg 17)
7076         (compare (match_operand:SI 1 "nonimmediate_operand" "0")
7077                  (match_operand:SI 2 "general_operand" "rim")))
7078    (set (match_operand:DI 0 "register_operand" "=r")
7079         (zero_extend:DI
7080           (minus:SI (match_dup 1)
7081                     (match_dup 2))))]
7082   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)
7083    && ix86_binary_operator_ok (MINUS, SImode, operands)"
7084   "sub{q}\t{%2, %0|%0, %2}"
7085   [(set_attr "type" "alu")
7086    (set_attr "mode" "DI")])
7087
7088 (define_expand "subhi3"
7089   [(parallel [(set (match_operand:HI 0 "nonimmediate_operand" "")
7090                    (minus:HI (match_operand:HI 1 "nonimmediate_operand" "")
7091                              (match_operand:HI 2 "general_operand" "")))
7092               (clobber (reg:CC 17))])]
7093   "TARGET_HIMODE_MATH"
7094   "ix86_expand_binary_operator (MINUS, HImode, operands); DONE;")
7095
7096 (define_insn "*subhi_1"
7097   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r")
7098         (minus:HI (match_operand:HI 1 "nonimmediate_operand" "0,0")
7099                   (match_operand:HI 2 "general_operand" "ri,rm")))
7100    (clobber (reg:CC 17))]
7101   "ix86_binary_operator_ok (MINUS, HImode, operands)"
7102   "sub{w}\t{%2, %0|%0, %2}"
7103   [(set_attr "type" "alu")
7104    (set_attr "mode" "HI")])
7105
7106 (define_insn "*subhi_2"
7107   [(set (reg 17)
7108         (compare
7109           (minus:HI (match_operand:HI 1 "nonimmediate_operand" "0,0")
7110                     (match_operand:HI 2 "general_operand" "ri,rm"))
7111           (const_int 0)))
7112    (set (match_operand:HI 0 "nonimmediate_operand" "=rm,r")
7113         (minus:HI (match_dup 1) (match_dup 2)))]
7114   "ix86_match_ccmode (insn, CCGOCmode)
7115    && ix86_binary_operator_ok (MINUS, HImode, operands)"
7116   "sub{w}\t{%2, %0|%0, %2}"
7117   [(set_attr "type" "alu")
7118    (set_attr "mode" "HI")])
7119
7120 (define_insn "*subhi_3"
7121   [(set (reg 17)
7122         (compare (match_operand:HI 1 "nonimmediate_operand" "0,0")
7123                  (match_operand:HI 2 "general_operand" "ri,rm")))
7124    (set (match_operand:HI 0 "nonimmediate_operand" "=rm,r")
7125         (minus:HI (match_dup 1) (match_dup 2)))]
7126   "ix86_match_ccmode (insn, CCmode)
7127    && ix86_binary_operator_ok (MINUS, HImode, operands)"
7128   "sub{w}\t{%2, %0|%0, %2}"
7129   [(set_attr "type" "alu")
7130    (set_attr "mode" "HI")])
7131
7132 (define_expand "subqi3"
7133   [(parallel [(set (match_operand:QI 0 "nonimmediate_operand" "")
7134                    (minus:QI (match_operand:QI 1 "nonimmediate_operand" "")
7135                              (match_operand:QI 2 "general_operand" "")))
7136               (clobber (reg:CC 17))])]
7137   "TARGET_QIMODE_MATH"
7138   "ix86_expand_binary_operator (MINUS, QImode, operands); DONE;")
7139
7140 (define_insn "*subqi_1"
7141   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,q")
7142         (minus:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
7143                   (match_operand:QI 2 "general_operand" "qn,qmn")))
7144    (clobber (reg:CC 17))]
7145   "ix86_binary_operator_ok (MINUS, QImode, operands)"
7146   "sub{b}\t{%2, %0|%0, %2}"
7147   [(set_attr "type" "alu")
7148    (set_attr "mode" "QI")])
7149
7150 (define_insn "*subqi_2"
7151   [(set (reg 17)
7152         (compare
7153           (minus:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
7154                     (match_operand:QI 2 "general_operand" "qi,qm"))
7155           (const_int 0)))
7156    (set (match_operand:HI 0 "nonimmediate_operand" "=qm,q")
7157         (minus:HI (match_dup 1) (match_dup 2)))]
7158   "ix86_match_ccmode (insn, CCGOCmode)
7159    && ix86_binary_operator_ok (MINUS, QImode, operands)"
7160   "sub{b}\t{%2, %0|%0, %2}"
7161   [(set_attr "type" "alu")
7162    (set_attr "mode" "QI")])
7163
7164 (define_insn "*subqi_3"
7165   [(set (reg 17)
7166         (compare (match_operand:QI 1 "nonimmediate_operand" "0,0")
7167                  (match_operand:QI 2 "general_operand" "qi,qm")))
7168    (set (match_operand:HI 0 "nonimmediate_operand" "=qm,q")
7169         (minus:HI (match_dup 1) (match_dup 2)))]
7170   "ix86_match_ccmode (insn, CCmode)
7171    && ix86_binary_operator_ok (MINUS, QImode, operands)"
7172   "sub{b}\t{%2, %0|%0, %2}"
7173   [(set_attr "type" "alu")
7174    (set_attr "mode" "QI")])
7175
7176 ;; The patterns that match these are at the end of this file.
7177
7178 (define_expand "subxf3"
7179   [(set (match_operand:XF 0 "register_operand" "")
7180         (minus:XF (match_operand:XF 1 "register_operand" "")
7181                   (match_operand:XF 2 "register_operand" "")))]
7182   "TARGET_80387 && !TARGET_64BIT"
7183   "")
7184
7185 (define_expand "subtf3"
7186   [(set (match_operand:TF 0 "register_operand" "")
7187         (minus:TF (match_operand:TF 1 "register_operand" "")
7188                   (match_operand:TF 2 "register_operand" "")))]
7189   "TARGET_80387"
7190   "")
7191
7192 (define_expand "subdf3"
7193   [(set (match_operand:DF 0 "register_operand" "")
7194         (minus:DF (match_operand:DF 1 "register_operand" "")
7195                   (match_operand:DF 2 "nonimmediate_operand" "")))]
7196   "TARGET_80387 || TARGET_SSE2"
7197   "")
7198
7199 (define_expand "subsf3"
7200   [(set (match_operand:SF 0 "register_operand" "")
7201         (minus:SF (match_operand:SF 1 "register_operand" "")
7202                   (match_operand:SF 2 "nonimmediate_operand" "")))]
7203   "TARGET_80387 || TARGET_SSE"
7204   "")
7205 \f
7206 ;; Multiply instructions
7207
7208 (define_expand "muldi3"
7209   [(parallel [(set (match_operand:DI 0 "register_operand" "")
7210                    (mult:DI (match_operand:DI 1 "register_operand" "")
7211                             (match_operand:DI 2 "x86_64_general_operand" "")))
7212               (clobber (reg:CC 17))])]
7213   "TARGET_64BIT"
7214   "")
7215
7216 (define_insn "*muldi3_1_rex64"
7217   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
7218         (mult:DI (match_operand:DI 1 "nonimmediate_operand" "%rm,0,0")
7219                  (match_operand:DI 2 "x86_64_general_operand" "K,e,mr")))
7220    (clobber (reg:CC 17))]
7221   "(GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)
7222    && TARGET_64BIT"
7223   "@
7224    imul{q}\t{%2, %1, %0|%0, %1, %2}
7225    imul{q}\t{%2, %1, %0|%0, %1, %2}
7226    imul{q}\t{%2, %0|%0, %2}"
7227   [(set_attr "type" "imul")
7228    (set_attr "prefix_0f" "0,0,1")
7229    (set_attr "mode" "DI")])
7230
7231 (define_expand "mulsi3"
7232   [(parallel [(set (match_operand:SI 0 "register_operand" "")
7233                    (mult:SI (match_operand:SI 1 "register_operand" "")
7234                             (match_operand:SI 2 "general_operand" "")))
7235               (clobber (reg:CC 17))])]
7236   ""
7237   "")
7238
7239 (define_insn "*mulsi3_1"
7240   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
7241         (mult:SI (match_operand:SI 1 "nonimmediate_operand" "%rm,0,0")
7242                  (match_operand:SI 2 "general_operand" "K,i,mr")))
7243    (clobber (reg:CC 17))]
7244   "GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM"
7245   ; For the {r,0,i} alternative (i.e., register <- register * immediate),
7246   ; there are two ways of writing the exact same machine instruction
7247   ; in assembly language.  One, for example, is:
7248   ;
7249   ;   imul $12, %eax
7250   ;
7251   ; while the other is:
7252   ;
7253   ;   imul $12, %eax, %eax
7254   ;
7255   ; The first is simply short-hand for the latter.  But, some assemblers,
7256   ; like the SCO OSR5 COFF assembler, don't handle the first form.
7257   "@
7258    imul{l}\t{%2, %1, %0|%0, %1, %2}
7259    imul{l}\t{%2, %1, %0|%0, %1, %2}
7260    imul{l}\t{%2, %0|%0, %2}"
7261   [(set_attr "type" "imul")
7262    (set_attr "prefix_0f" "0,0,1")
7263    (set_attr "mode" "SI")])
7264
7265 (define_insn "*mulsi3_1_zext"
7266   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
7267         (zero_extend:DI
7268           (mult:SI (match_operand:SI 1 "nonimmediate_operand" "%rm,0,0")
7269                    (match_operand:SI 2 "general_operand" "K,i,mr"))))
7270    (clobber (reg:CC 17))]
7271   "TARGET_64BIT
7272    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
7273   ; For the {r,0,i} alternative (i.e., register <- register * immediate),
7274   ; there are two ways of writing the exact same machine instruction
7275   ; in assembly language.  One, for example, is:
7276   ;
7277   ;   imul $12, %eax
7278   ;
7279   ; while the other is:
7280   ;
7281   ;   imul $12, %eax, %eax
7282   ;
7283   ; The first is simply short-hand for the latter.  But, some assemblers,
7284   ; like the SCO OSR5 COFF assembler, don't handle the first form.
7285   "@
7286    imul{l}\t{%2, %1, %k0|%k0, %1, %2}
7287    imul{l}\t{%2, %1, %k0|%k0, %1, %2}
7288    imul{l}\t{%2, %k0|%k0, %2}"
7289   [(set_attr "type" "imul")
7290    (set_attr "prefix_0f" "0,0,1")
7291    (set_attr "mode" "SI")])
7292
7293 (define_expand "mulhi3"
7294   [(parallel [(set (match_operand:HI 0 "register_operand" "")
7295                    (mult:HI (match_operand:HI 1 "register_operand" "")
7296                             (match_operand:HI 2 "general_operand" "")))
7297               (clobber (reg:CC 17))])]
7298   "TARGET_HIMODE_MATH"
7299   "")
7300
7301 (define_insn "*mulhi3_1"
7302   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
7303         (mult:HI (match_operand:HI 1 "nonimmediate_operand" "%rm,0,0")
7304                  (match_operand:HI 2 "general_operand" "K,i,mr")))
7305    (clobber (reg:CC 17))]
7306   "GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM"
7307   ; %%% There was a note about "Assembler has weird restrictions",
7308   ; concerning alternative 1 when op1 == op0.  True?
7309   "@
7310    imul{w}\t{%2, %1, %0|%0, %1, %2}
7311    imul{w}\t{%2, %1, %0|%0, %1, %2}
7312    imul{w}\t{%2, %0|%0, %2}"
7313   [(set_attr "type" "imul")
7314    (set_attr "prefix_0f" "0,0,1")
7315    (set_attr "mode" "HI")])
7316
7317 (define_insn "mulqi3"
7318   [(set (match_operand:QI 0 "register_operand" "=a")
7319         (mult:QI (match_operand:QI 1 "register_operand" "%0")
7320                  (match_operand:QI 2 "nonimmediate_operand" "qm")))
7321    (clobber (reg:CC 17))]
7322   "TARGET_QIMODE_MATH"
7323   "mul{b}\t%2"
7324   [(set_attr "type" "imul")
7325    (set_attr "length_immediate" "0")
7326    (set_attr "mode" "QI")])
7327
7328 (define_insn "umulqihi3"
7329   [(set (match_operand:HI 0 "register_operand" "=a")
7330         (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "%0"))
7331                  (zero_extend:HI (match_operand:QI 2 "nonimmediate_operand" "qm"))))
7332    (clobber (reg:CC 17))]
7333   "TARGET_QIMODE_MATH"
7334   "mul{b}\t%2"
7335   [(set_attr "type" "imul")
7336    (set_attr "length_immediate" "0")
7337    (set_attr "mode" "QI")])
7338
7339 (define_insn "mulqihi3"
7340   [(set (match_operand:HI 0 "register_operand" "=a")
7341         (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "%0"))
7342                  (sign_extend:HI (match_operand:QI 2 "nonimmediate_operand" "qm"))))
7343    (clobber (reg:CC 17))]
7344   "TARGET_QIMODE_MATH"
7345   "imul{b}\t%2"
7346   [(set_attr "type" "imul")
7347    (set_attr "length_immediate" "0")
7348    (set_attr "mode" "QI")])
7349
7350 (define_insn "umulditi3"
7351   [(set (match_operand:TI 0 "register_operand" "=A")
7352         (mult:TI (zero_extend:TI (match_operand:DI 1 "register_operand" "%0"))
7353                  (zero_extend:TI (match_operand:DI 2 "nonimmediate_operand" "rm"))))
7354    (clobber (reg:CC 17))]
7355   "TARGET_64BIT"
7356   "mul{q}\t%2"
7357   [(set_attr "type" "imul")
7358    (set_attr "ppro_uops" "few")
7359    (set_attr "length_immediate" "0")
7360    (set_attr "mode" "DI")])
7361
7362 ;; We can't use this pattern in 64bit mode, since it results in two separate 32bit registers
7363 (define_insn "umulsidi3"
7364   [(set (match_operand:DI 0 "register_operand" "=A")
7365         (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "%0"))
7366                  (zero_extend:DI (match_operand:SI 2 "nonimmediate_operand" "rm"))))
7367    (clobber (reg:CC 17))]
7368   "!TARGET_64BIT"
7369   "mul{l}\t%2"
7370   [(set_attr "type" "imul")
7371    (set_attr "ppro_uops" "few")
7372    (set_attr "length_immediate" "0")
7373    (set_attr "mode" "SI")])
7374
7375 (define_insn "mulditi3"
7376   [(set (match_operand:TI 0 "register_operand" "=A")
7377         (mult:TI (sign_extend:TI (match_operand:DI 1 "register_operand" "%0"))
7378                  (sign_extend:TI (match_operand:DI 2 "nonimmediate_operand" "rm"))))
7379    (clobber (reg:CC 17))]
7380   "TARGET_64BIT"
7381   "imul{q}\t%2"
7382   [(set_attr "type" "imul")
7383    (set_attr "length_immediate" "0")
7384    (set_attr "mode" "DI")])
7385
7386 (define_insn "mulsidi3"
7387   [(set (match_operand:DI 0 "register_operand" "=A")
7388         (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "%0"))
7389                  (sign_extend:DI (match_operand:SI 2 "nonimmediate_operand" "rm"))))
7390    (clobber (reg:CC 17))]
7391   "!TARGET_64BIT"
7392   "imul{l}\t%2"
7393   [(set_attr "type" "imul")
7394    (set_attr "length_immediate" "0")
7395    (set_attr "mode" "SI")])
7396
7397 (define_insn "*umuldi3_highpart_rex64"
7398   [(set (match_operand:DI 0 "register_operand" "=d")
7399         (truncate:DI
7400           (lshiftrt:TI
7401             (mult:TI (zero_extend:TI
7402                        (match_operand:DI 1 "register_operand" "%a"))
7403                      (zero_extend:TI
7404                        (match_operand:DI 2 "nonimmediate_operand" "rm")))
7405             (const_int 64))))
7406    (clobber (match_scratch:DI 3 "=a"))
7407    (clobber (reg:CC 17))]
7408   "TARGET_64BIT"
7409   "mul{q}\t%2"
7410   [(set_attr "type" "imul")
7411    (set_attr "ppro_uops" "few")
7412    (set_attr "length_immediate" "0")
7413    (set_attr "mode" "DI")])
7414
7415 (define_insn "umulsi3_highpart"
7416   [(set (match_operand:SI 0 "register_operand" "=d")
7417         (truncate:SI
7418           (lshiftrt:DI
7419             (mult:DI (zero_extend:DI
7420                        (match_operand:SI 1 "register_operand" "%a"))
7421                      (zero_extend:DI
7422                        (match_operand:SI 2 "nonimmediate_operand" "rm")))
7423             (const_int 32))))
7424    (clobber (match_scratch:SI 3 "=a"))
7425    (clobber (reg:CC 17))]
7426   ""
7427   "mul{l}\t%2"
7428   [(set_attr "type" "imul")
7429    (set_attr "ppro_uops" "few")
7430    (set_attr "length_immediate" "0")
7431    (set_attr "mode" "SI")])
7432
7433 (define_insn "*umulsi3_highpart_zext"
7434   [(set (match_operand:DI 0 "register_operand" "=d")
7435         (zero_extend:DI (truncate:SI
7436           (lshiftrt:DI
7437             (mult:DI (zero_extend:DI
7438                        (match_operand:SI 1 "register_operand" "%a"))
7439                      (zero_extend:DI
7440                        (match_operand:SI 2 "nonimmediate_operand" "rm")))
7441             (const_int 32)))))
7442    (clobber (match_scratch:SI 3 "=a"))
7443    (clobber (reg:CC 17))]
7444   "TARGET_64BIT"
7445   "mul{l}\t%2"
7446   [(set_attr "type" "imul")
7447    (set_attr "ppro_uops" "few")
7448    (set_attr "length_immediate" "0")
7449    (set_attr "mode" "SI")])
7450
7451 (define_insn "*smuldi3_highpart_rex64"
7452   [(set (match_operand:DI 0 "register_operand" "=d")
7453         (truncate:DI
7454           (lshiftrt:TI
7455             (mult:TI (sign_extend:TI
7456                        (match_operand:DI 1 "register_operand" "%a"))
7457                      (sign_extend:TI
7458                        (match_operand:DI 2 "nonimmediate_operand" "rm")))
7459             (const_int 64))))
7460    (clobber (match_scratch:DI 3 "=a"))
7461    (clobber (reg:CC 17))]
7462   "TARGET_64BIT"
7463   "imul{q}\t%2"
7464   [(set_attr "type" "imul")
7465    (set_attr "ppro_uops" "few")
7466    (set_attr "mode" "DI")])
7467
7468 (define_insn "smulsi3_highpart"
7469   [(set (match_operand:SI 0 "register_operand" "=d")
7470         (truncate:SI
7471           (lshiftrt:DI
7472             (mult:DI (sign_extend:DI
7473                        (match_operand:SI 1 "register_operand" "%a"))
7474                      (sign_extend:DI
7475                        (match_operand:SI 2 "nonimmediate_operand" "rm")))
7476             (const_int 32))))
7477    (clobber (match_scratch:SI 3 "=a"))
7478    (clobber (reg:CC 17))]
7479   ""
7480   "imul{l}\t%2"
7481   [(set_attr "type" "imul")
7482    (set_attr "ppro_uops" "few")
7483    (set_attr "mode" "SI")])
7484
7485 (define_insn "*smulsi3_highpart_zext"
7486   [(set (match_operand:DI 0 "register_operand" "=d")
7487         (zero_extend:DI (truncate:SI
7488           (lshiftrt:DI
7489             (mult:DI (sign_extend:DI
7490                        (match_operand:SI 1 "register_operand" "%a"))
7491                      (sign_extend:DI
7492                        (match_operand:SI 2 "nonimmediate_operand" "rm")))
7493             (const_int 32)))))
7494    (clobber (match_scratch:SI 3 "=a"))
7495    (clobber (reg:CC 17))]
7496   "TARGET_64BIT"
7497   "imul{l}\t%2"
7498   [(set_attr "type" "imul")
7499    (set_attr "ppro_uops" "few")
7500    (set_attr "mode" "SI")])
7501
7502 ;; The patterns that match these are at the end of this file.
7503
7504 (define_expand "mulxf3"
7505   [(set (match_operand:XF 0 "register_operand" "")
7506         (mult:XF (match_operand:XF 1 "register_operand" "")
7507                  (match_operand:XF 2 "register_operand" "")))]
7508   "TARGET_80387 && !TARGET_64BIT"
7509   "")
7510
7511 (define_expand "multf3"
7512   [(set (match_operand:TF 0 "register_operand" "")
7513         (mult:TF (match_operand:TF 1 "register_operand" "")
7514                  (match_operand:TF 2 "register_operand" "")))]
7515   "TARGET_80387"
7516   "")
7517
7518 (define_expand "muldf3"
7519   [(set (match_operand:DF 0 "register_operand" "")
7520         (mult:DF (match_operand:DF 1 "register_operand" "")
7521                  (match_operand:DF 2 "nonimmediate_operand" "")))]
7522   "TARGET_80387 || TARGET_SSE2"
7523   "")
7524
7525 (define_expand "mulsf3"
7526   [(set (match_operand:SF 0 "register_operand" "")
7527         (mult:SF (match_operand:SF 1 "register_operand" "")
7528                  (match_operand:SF 2 "nonimmediate_operand" "")))]
7529   "TARGET_80387 || TARGET_SSE"
7530   "")
7531 \f
7532 ;; Divide instructions
7533
7534 (define_insn "divqi3"
7535   [(set (match_operand:QI 0 "register_operand" "=a")
7536         (div:QI (match_operand:HI 1 "register_operand" "0")
7537                 (match_operand:QI 2 "nonimmediate_operand" "qm")))
7538    (clobber (reg:CC 17))]
7539   "TARGET_QIMODE_MATH"
7540   "idiv{b}\t%2"
7541   [(set_attr "type" "idiv")
7542    (set_attr "mode" "QI")
7543    (set_attr "ppro_uops" "few")])
7544
7545 (define_insn "udivqi3"
7546   [(set (match_operand:QI 0 "register_operand" "=a")
7547         (udiv:QI (match_operand:HI 1 "register_operand" "0")
7548                  (match_operand:QI 2 "nonimmediate_operand" "qm")))
7549    (clobber (reg:CC 17))]
7550   "TARGET_QIMODE_MATH"
7551   "div{b}\t%2"
7552   [(set_attr "type" "idiv")
7553    (set_attr "mode" "QI")
7554    (set_attr "ppro_uops" "few")])
7555
7556 ;; The patterns that match these are at the end of this file.
7557
7558 (define_expand "divxf3"
7559   [(set (match_operand:XF 0 "register_operand" "")
7560         (div:XF (match_operand:XF 1 "register_operand" "")
7561                 (match_operand:XF 2 "register_operand" "")))]
7562   "TARGET_80387 && !TARGET_64BIT"
7563   "")
7564
7565 (define_expand "divtf3"
7566   [(set (match_operand:TF 0 "register_operand" "")
7567         (div:TF (match_operand:TF 1 "register_operand" "")
7568                 (match_operand:TF 2 "register_operand" "")))]
7569   "TARGET_80387"
7570   "")
7571
7572 (define_expand "divdf3"
7573   [(set (match_operand:DF 0 "register_operand" "")
7574         (div:DF (match_operand:DF 1 "register_operand" "")
7575                 (match_operand:DF 2 "nonimmediate_operand" "")))]
7576    "TARGET_80387 || TARGET_SSE2"
7577    "")
7578  
7579 (define_expand "divsf3"
7580   [(set (match_operand:SF 0 "register_operand" "")
7581         (div:SF (match_operand:SF 1 "register_operand" "")
7582                 (match_operand:SF 2 "nonimmediate_operand" "")))]
7583   "TARGET_80387 || TARGET_SSE"
7584   "")
7585 \f
7586 ;; Remainder instructions.
7587
7588 (define_expand "divmoddi4"
7589   [(parallel [(set (match_operand:DI 0 "register_operand" "")
7590                    (div:DI (match_operand:DI 1 "register_operand" "")
7591                            (match_operand:DI 2 "nonimmediate_operand" "")))
7592               (set (match_operand:DI 3 "register_operand" "")
7593                    (mod:DI (match_dup 1) (match_dup 2)))
7594               (clobber (reg:CC 17))])]
7595   "TARGET_64BIT"
7596   "")
7597
7598 ;; Allow to come the parameter in eax or edx to avoid extra moves.
7599 ;; Penalize eax case sligthly because it results in worse scheduling
7600 ;; of code.
7601 (define_insn "*divmoddi4_nocltd_rex64"
7602   [(set (match_operand:DI 0 "register_operand" "=&a,?a")
7603         (div:DI (match_operand:DI 2 "register_operand" "1,0")
7604                 (match_operand:DI 3 "nonimmediate_operand" "rm,rm")))
7605    (set (match_operand:DI 1 "register_operand" "=&d,&d")
7606         (mod:DI (match_dup 2) (match_dup 3)))
7607    (clobber (reg:CC 17))]
7608   "TARGET_64BIT && !optimize_size && !TARGET_USE_CLTD"
7609   "#"
7610   [(set_attr "type" "multi")])
7611
7612 (define_insn "*divmoddi4_cltd_rex64"
7613   [(set (match_operand:DI 0 "register_operand" "=a")
7614         (div:DI (match_operand:DI 2 "register_operand" "a")
7615                 (match_operand:DI 3 "nonimmediate_operand" "rm")))
7616    (set (match_operand:DI 1 "register_operand" "=&d")
7617         (mod:DI (match_dup 2) (match_dup 3)))
7618    (clobber (reg:CC 17))]
7619   "TARGET_64BIT && (optimize_size || TARGET_USE_CLTD)"
7620   "#"
7621   [(set_attr "type" "multi")])
7622
7623 (define_insn "*divmoddi_noext_rex64"
7624   [(set (match_operand:DI 0 "register_operand" "=a")
7625         (div:DI (match_operand:DI 1 "register_operand" "0")
7626                 (match_operand:DI 2 "nonimmediate_operand" "rm")))
7627    (set (match_operand:DI 3 "register_operand" "=d")
7628         (mod:DI (match_dup 1) (match_dup 2)))
7629    (use (match_operand:DI 4 "register_operand" "3"))
7630    (clobber (reg:CC 17))]
7631   "TARGET_64BIT"
7632   "idiv{q}\t%2"
7633   [(set_attr "type" "idiv")
7634    (set_attr "mode" "DI")
7635    (set_attr "ppro_uops" "few")])
7636
7637 (define_split
7638   [(set (match_operand:DI 0 "register_operand" "")
7639         (div:DI (match_operand:DI 1 "register_operand" "")
7640                 (match_operand:DI 2 "nonimmediate_operand" "")))
7641    (set (match_operand:DI 3 "register_operand" "")
7642         (mod:DI (match_dup 1) (match_dup 2)))
7643    (clobber (reg:CC 17))]
7644   "TARGET_64BIT && reload_completed"
7645   [(parallel [(set (match_dup 3)
7646                    (ashiftrt:DI (match_dup 4) (const_int 63)))
7647               (clobber (reg:CC 17))])
7648    (parallel [(set (match_dup 0)
7649                    (div:DI (reg:DI 0) (match_dup 2)))
7650               (set (match_dup 3)
7651                    (mod:DI (reg:DI 0) (match_dup 2)))
7652               (use (match_dup 3))
7653               (clobber (reg:CC 17))])]
7654 {
7655   /* Avoid use of cltd in favour of a mov+shift.  */
7656   if (!TARGET_USE_CLTD && !optimize_size)
7657     {
7658       if (true_regnum (operands[1]))
7659         emit_move_insn (operands[0], operands[1]);
7660       else
7661         emit_move_insn (operands[3], operands[1]);
7662       operands[4] = operands[3];
7663     }
7664   else
7665     {
7666       if (true_regnum (operands[1]))
7667         abort();
7668       operands[4] = operands[1];
7669     }
7670 })
7671
7672
7673 (define_expand "divmodsi4"
7674   [(parallel [(set (match_operand:SI 0 "register_operand" "")
7675                    (div:SI (match_operand:SI 1 "register_operand" "")
7676                            (match_operand:SI 2 "nonimmediate_operand" "")))
7677               (set (match_operand:SI 3 "register_operand" "")
7678                    (mod:SI (match_dup 1) (match_dup 2)))
7679               (clobber (reg:CC 17))])]
7680   ""
7681   "")
7682
7683 ;; Allow to come the parameter in eax or edx to avoid extra moves.
7684 ;; Penalize eax case sligthly because it results in worse scheduling
7685 ;; of code.
7686 (define_insn "*divmodsi4_nocltd"
7687   [(set (match_operand:SI 0 "register_operand" "=&a,?a")
7688         (div:SI (match_operand:SI 2 "register_operand" "1,0")
7689                 (match_operand:SI 3 "nonimmediate_operand" "rm,rm")))
7690    (set (match_operand:SI 1 "register_operand" "=&d,&d")
7691         (mod:SI (match_dup 2) (match_dup 3)))
7692    (clobber (reg:CC 17))]
7693   "!optimize_size && !TARGET_USE_CLTD"
7694   "#"
7695   [(set_attr "type" "multi")])
7696
7697 (define_insn "*divmodsi4_cltd"
7698   [(set (match_operand:SI 0 "register_operand" "=a")
7699         (div:SI (match_operand:SI 2 "register_operand" "a")
7700                 (match_operand:SI 3 "nonimmediate_operand" "rm")))
7701    (set (match_operand:SI 1 "register_operand" "=&d")
7702         (mod:SI (match_dup 2) (match_dup 3)))
7703    (clobber (reg:CC 17))]
7704   "optimize_size || TARGET_USE_CLTD"
7705   "#"
7706   [(set_attr "type" "multi")])
7707
7708 (define_insn "*divmodsi_noext"
7709   [(set (match_operand:SI 0 "register_operand" "=a")
7710         (div:SI (match_operand:SI 1 "register_operand" "0")
7711                 (match_operand:SI 2 "nonimmediate_operand" "rm")))
7712    (set (match_operand:SI 3 "register_operand" "=d")
7713         (mod:SI (match_dup 1) (match_dup 2)))
7714    (use (match_operand:SI 4 "register_operand" "3"))
7715    (clobber (reg:CC 17))]
7716   ""
7717   "idiv{l}\t%2"
7718   [(set_attr "type" "idiv")
7719    (set_attr "mode" "SI")
7720    (set_attr "ppro_uops" "few")])
7721
7722 (define_split
7723   [(set (match_operand:SI 0 "register_operand" "")
7724         (div:SI (match_operand:SI 1 "register_operand" "")
7725                 (match_operand:SI 2 "nonimmediate_operand" "")))
7726    (set (match_operand:SI 3 "register_operand" "")
7727         (mod:SI (match_dup 1) (match_dup 2)))
7728    (clobber (reg:CC 17))]
7729   "reload_completed"
7730   [(parallel [(set (match_dup 3)
7731                    (ashiftrt:SI (match_dup 4) (const_int 31)))
7732               (clobber (reg:CC 17))])
7733    (parallel [(set (match_dup 0)
7734                    (div:SI (reg:SI 0) (match_dup 2)))
7735               (set (match_dup 3)
7736                    (mod:SI (reg:SI 0) (match_dup 2)))
7737               (use (match_dup 3))
7738               (clobber (reg:CC 17))])]
7739 {
7740   /* Avoid use of cltd in favour of a mov+shift.  */
7741   if (!TARGET_USE_CLTD && !optimize_size)
7742     {
7743       if (true_regnum (operands[1]))
7744         emit_move_insn (operands[0], operands[1]);
7745       else
7746         emit_move_insn (operands[3], operands[1]);
7747       operands[4] = operands[3];
7748     }
7749   else
7750     {
7751       if (true_regnum (operands[1]))
7752         abort();
7753       operands[4] = operands[1];
7754     }
7755 })
7756 ;; %%% Split me.
7757 (define_insn "divmodhi4"
7758   [(set (match_operand:HI 0 "register_operand" "=a")
7759         (div:HI (match_operand:HI 1 "register_operand" "0")
7760                 (match_operand:HI 2 "nonimmediate_operand" "rm")))
7761    (set (match_operand:HI 3 "register_operand" "=&d")
7762         (mod:HI (match_dup 1) (match_dup 2)))
7763    (clobber (reg:CC 17))]
7764   "TARGET_HIMODE_MATH"
7765   "cwtd\;idiv{w}\t%2"
7766   [(set_attr "type" "multi")
7767    (set_attr "length_immediate" "0")
7768    (set_attr "mode" "SI")])
7769
7770 (define_insn "udivmoddi4"
7771   [(set (match_operand:DI 0 "register_operand" "=a")
7772         (udiv:DI (match_operand:DI 1 "register_operand" "0")
7773                  (match_operand:DI 2 "nonimmediate_operand" "rm")))
7774    (set (match_operand:DI 3 "register_operand" "=&d")
7775         (umod:DI (match_dup 1) (match_dup 2)))
7776    (clobber (reg:CC 17))]
7777   "TARGET_64BIT"
7778   "xor{q}\t%3, %3\;div{q}\t%2"
7779   [(set_attr "type" "multi")
7780    (set_attr "length_immediate" "0")
7781    (set_attr "mode" "DI")])
7782
7783 (define_insn "*udivmoddi4_noext"
7784   [(set (match_operand:DI 0 "register_operand" "=a")
7785         (udiv:DI (match_operand:DI 1 "register_operand" "0")
7786                  (match_operand:DI 2 "nonimmediate_operand" "rm")))
7787    (set (match_operand:DI 3 "register_operand" "=d")
7788         (umod:DI (match_dup 1) (match_dup 2)))
7789    (use (match_dup 3))
7790    (clobber (reg:CC 17))]
7791   "TARGET_64BIT"
7792   "div{q}\t%2"
7793   [(set_attr "type" "idiv")
7794    (set_attr "ppro_uops" "few")
7795    (set_attr "mode" "DI")])
7796
7797 (define_split
7798   [(set (match_operand:DI 0 "register_operand" "")
7799         (udiv:DI (match_operand:DI 1 "register_operand" "")
7800                  (match_operand:DI 2 "nonimmediate_operand" "")))
7801    (set (match_operand:DI 3 "register_operand" "")
7802         (umod:DI (match_dup 1) (match_dup 2)))
7803    (clobber (reg:CC 17))]
7804   "reload_completed && TARGET_64BIT"
7805   [(set (match_dup 3) (const_int 0))
7806    (parallel [(set (match_dup 0)
7807                    (udiv:DI (match_dup 1) (match_dup 2)))
7808               (set (match_dup 3)
7809                    (umod:DI (match_dup 1) (match_dup 2)))
7810               (use (match_dup 3))
7811               (clobber (reg:CC 17))])]
7812   "")
7813
7814 (define_insn "udivmodsi4"
7815   [(set (match_operand:SI 0 "register_operand" "=a")
7816         (udiv:SI (match_operand:SI 1 "register_operand" "0")
7817                  (match_operand:SI 2 "nonimmediate_operand" "rm")))
7818    (set (match_operand:SI 3 "register_operand" "=&d")
7819         (umod:SI (match_dup 1) (match_dup 2)))
7820    (clobber (reg:CC 17))]
7821   ""
7822   "xor{l}\t%3, %3\;div{l}\t%2"
7823   [(set_attr "type" "multi")
7824    (set_attr "length_immediate" "0")
7825    (set_attr "mode" "SI")])
7826
7827 (define_insn "*udivmodsi4_noext"
7828   [(set (match_operand:SI 0 "register_operand" "=a")
7829         (udiv:SI (match_operand:SI 1 "register_operand" "0")
7830                  (match_operand:SI 2 "nonimmediate_operand" "rm")))
7831    (set (match_operand:SI 3 "register_operand" "=d")
7832         (umod:SI (match_dup 1) (match_dup 2)))
7833    (use (match_dup 3))
7834    (clobber (reg:CC 17))]
7835   ""
7836   "div{l}\t%2"
7837   [(set_attr "type" "idiv")
7838    (set_attr "ppro_uops" "few")
7839    (set_attr "mode" "SI")])
7840
7841 (define_split
7842   [(set (match_operand:SI 0 "register_operand" "")
7843         (udiv:SI (match_operand:SI 1 "register_operand" "")
7844                  (match_operand:SI 2 "nonimmediate_operand" "")))
7845    (set (match_operand:SI 3 "register_operand" "")
7846         (umod:SI (match_dup 1) (match_dup 2)))
7847    (clobber (reg:CC 17))]
7848   "reload_completed"
7849   [(set (match_dup 3) (const_int 0))
7850    (parallel [(set (match_dup 0)
7851                    (udiv:SI (match_dup 1) (match_dup 2)))
7852               (set (match_dup 3)
7853                    (umod:SI (match_dup 1) (match_dup 2)))
7854               (use (match_dup 3))
7855               (clobber (reg:CC 17))])]
7856   "")
7857
7858 (define_expand "udivmodhi4"
7859   [(set (match_dup 4) (const_int 0))
7860    (parallel [(set (match_operand:HI 0 "register_operand" "")
7861                    (udiv:HI (match_operand:HI 1 "register_operand" "")
7862                             (match_operand:HI 2 "nonimmediate_operand" "")))
7863               (set (match_operand:HI 3 "register_operand" "")
7864                    (umod:HI (match_dup 1) (match_dup 2)))
7865               (use (match_dup 4))
7866               (clobber (reg:CC 17))])]
7867   "TARGET_HIMODE_MATH"
7868   "operands[4] = gen_reg_rtx (HImode);")
7869
7870 (define_insn "*udivmodhi_noext"
7871   [(set (match_operand:HI 0 "register_operand" "=a")
7872         (udiv:HI (match_operand:HI 1 "register_operand" "0")
7873                  (match_operand:HI 2 "nonimmediate_operand" "rm")))
7874    (set (match_operand:HI 3 "register_operand" "=d")
7875         (umod:HI (match_dup 1) (match_dup 2)))
7876    (use (match_operand:HI 4 "register_operand" "3"))
7877    (clobber (reg:CC 17))]
7878   ""
7879   "div{w}\t%2"
7880   [(set_attr "type" "idiv")
7881    (set_attr "mode" "HI")
7882    (set_attr "ppro_uops" "few")])
7883
7884 ;; We can not use div/idiv for double division, because it causes
7885 ;; "division by zero" on the overflow and that's not what we expect
7886 ;; from truncate.  Because true (non truncating) double division is
7887 ;; never generated, we can't create this insn anyway.
7888 ;
7889 ;(define_insn ""
7890 ;  [(set (match_operand:SI 0 "register_operand" "=a")
7891 ;       (truncate:SI
7892 ;         (udiv:DI (match_operand:DI 1 "register_operand" "A")
7893 ;                  (zero_extend:DI
7894 ;                    (match_operand:SI 2 "nonimmediate_operand" "rm")))))
7895 ;   (set (match_operand:SI 3 "register_operand" "=d")
7896 ;       (truncate:SI
7897 ;         (umod:DI (match_dup 1) (zero_extend:DI (match_dup 2)))))
7898 ;   (clobber (reg:CC 17))]
7899 ;  ""
7900 ;  "div{l}\t{%2, %0|%0, %2}"
7901 ;  [(set_attr "type" "idiv")
7902 ;   (set_attr "ppro_uops" "few")])
7903 \f
7904 ;;- Logical AND instructions
7905
7906 ;; On Pentium, "test imm, reg" is pairable only with eax, ax, and al.
7907 ;; Note that this excludes ah.
7908
7909 (define_insn "*testdi_1_rex64"
7910   [(set (reg 17)
7911         (compare
7912           (and:DI (match_operand:DI 0 "nonimmediate_operand" "%*a,r,*a,r,rm")
7913                   (match_operand:DI 1 "x86_64_szext_nonmemory_operand" "Z,Z,e,e,re"))
7914           (const_int 0)))]
7915   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
7916   "@
7917    test{l}\t{%k1, %k0|%k0, %k1} 
7918    test{l}\t{%k1, %k0|%k0, %k1} 
7919    test{q}\t{%1, %0|%0, %1} 
7920    test{q}\t{%1, %0|%0, %1} 
7921    test{q}\t{%1, %0|%0, %1}"
7922   [(set_attr "type" "test")
7923    (set_attr "modrm" "0,1,0,1,1")
7924    (set_attr "mode" "SI,SI,DI,DI,DI")
7925    (set_attr "pent_pair" "uv,np,uv,np,uv")])
7926
7927 (define_insn "testsi_1"
7928   [(set (reg 17)
7929         (compare
7930           (and:SI (match_operand:SI 0 "nonimmediate_operand" "%*a,r,rm")
7931                   (match_operand:SI 1 "nonmemory_operand" "in,in,rin"))
7932           (const_int 0)))]
7933   "ix86_match_ccmode (insn, CCNOmode)"
7934   "test{l}\t{%1, %0|%0, %1}"
7935   [(set_attr "type" "test")
7936    (set_attr "modrm" "0,1,1")
7937    (set_attr "mode" "SI")
7938    (set_attr "pent_pair" "uv,np,uv")])
7939
7940 (define_expand "testsi_ccno_1"
7941   [(set (reg:CCNO 17)
7942         (compare:CCNO
7943           (and:SI (match_operand:SI 0 "nonimmediate_operand" "")
7944                   (match_operand:SI 1 "nonmemory_operand" ""))
7945           (const_int 0)))]
7946   ""
7947   "")
7948
7949 (define_insn "*testhi_1"
7950   [(set (reg 17)
7951         (compare (and:HI (match_operand:HI 0 "nonimmediate_operand" "%*a,r,rm")
7952                          (match_operand:HI 1 "nonmemory_operand" "n,n,rn"))
7953                  (const_int 0)))]
7954   "ix86_match_ccmode (insn, CCNOmode)"
7955   "test{w}\t{%1, %0|%0, %1}"
7956   [(set_attr "type" "test")
7957    (set_attr "modrm" "0,1,1")
7958    (set_attr "mode" "HI")
7959    (set_attr "pent_pair" "uv,np,uv")])
7960
7961 (define_expand "testqi_ccz_1"
7962   [(set (reg:CCZ 17)
7963         (compare:CCZ (and:QI (match_operand:QI 0 "nonimmediate_operand" "")
7964                              (match_operand:QI 1 "nonmemory_operand" ""))
7965                  (const_int 0)))]
7966   ""
7967   "")
7968
7969 (define_insn "*testqi_1"
7970   [(set (reg 17)
7971         (compare (and:QI (match_operand:QI 0 "nonimmediate_operand" "%*a,q,qm,r")
7972                          (match_operand:QI 1 "nonmemory_operand" "n,n,qn,n"))
7973                  (const_int 0)))]
7974   "ix86_match_ccmode (insn, CCNOmode)"
7975 {
7976   if (which_alternative == 3)
7977     {
7978       if (GET_CODE (operands[1]) == CONST_INT
7979           && (INTVAL (operands[1]) & 0xffffff00))
7980         operands[1] = GEN_INT (INTVAL (operands[1]) & 0xff);
7981       return "test{l}\t{%1, %k0|%k0, %1}";
7982     }
7983   return "test{b}\t{%1, %0|%0, %1}";
7984 }
7985   [(set_attr "type" "test")
7986    (set_attr "modrm" "0,1,1,1")
7987    (set_attr "mode" "QI,QI,QI,SI")
7988    (set_attr "pent_pair" "uv,np,uv,np")])
7989
7990 (define_expand "testqi_ext_ccno_0"
7991   [(set (reg:CCNO 17)
7992         (compare:CCNO
7993           (and:SI
7994             (zero_extract:SI
7995               (match_operand 0 "ext_register_operand" "")
7996               (const_int 8)
7997               (const_int 8))
7998             (match_operand 1 "const_int_operand" ""))
7999           (const_int 0)))]
8000   ""
8001   "")
8002
8003 (define_insn "*testqi_ext_0"
8004   [(set (reg 17)
8005         (compare
8006           (and:SI
8007             (zero_extract:SI
8008               (match_operand 0 "ext_register_operand" "Q")
8009               (const_int 8)
8010               (const_int 8))
8011             (match_operand 1 "const_int_operand" "n"))
8012           (const_int 0)))]
8013   "(unsigned HOST_WIDE_INT) INTVAL (operands[1]) <= 0xff
8014    && ix86_match_ccmode (insn, CCNOmode)"
8015   "test{b}\t{%1, %h0|%h0, %1}"
8016   [(set_attr "type" "test")
8017    (set_attr "mode" "QI")
8018    (set_attr "length_immediate" "1")
8019    (set_attr "pent_pair" "np")])
8020
8021 (define_insn "*testqi_ext_1"
8022   [(set (reg 17)
8023         (compare
8024           (and:SI
8025             (zero_extract:SI
8026               (match_operand 0 "ext_register_operand" "Q")
8027               (const_int 8)
8028               (const_int 8))
8029             (zero_extend:SI
8030               (match_operand:QI 1 "nonimmediate_operand" "Qm")))
8031           (const_int 0)))]
8032   "!TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
8033   "test{b}\t{%1, %h0|%h0, %1}"
8034   [(set_attr "type" "test")
8035    (set_attr "mode" "QI")])
8036
8037 (define_insn "*testqi_ext_1_rex64"
8038   [(set (reg 17)
8039         (compare
8040           (and:SI
8041             (zero_extract:SI
8042               (match_operand 0 "ext_register_operand" "Q")
8043               (const_int 8)
8044               (const_int 8))
8045             (zero_extend:SI
8046               (match_operand:QI 1 "register_operand" "Q")))
8047           (const_int 0)))]
8048   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
8049   "test{b}\t{%1, %h0|%h0, %1}"
8050   [(set_attr "type" "test")
8051    (set_attr "mode" "QI")])
8052
8053 (define_insn "*testqi_ext_2"
8054   [(set (reg 17)
8055         (compare
8056           (and:SI
8057             (zero_extract:SI
8058               (match_operand 0 "ext_register_operand" "Q")
8059               (const_int 8)
8060               (const_int 8))
8061             (zero_extract:SI
8062               (match_operand 1 "ext_register_operand" "Q")
8063               (const_int 8)
8064               (const_int 8)))
8065           (const_int 0)))]
8066   "ix86_match_ccmode (insn, CCNOmode)"
8067   "test{b}\t{%h1, %h0|%h0, %h1}"
8068   [(set_attr "type" "test")
8069    (set_attr "mode" "QI")])
8070
8071 ;; Combine likes to form bit extractions for some tests.  Humor it.
8072 (define_insn "*testqi_ext_3"
8073   [(set (reg 17)
8074         (compare (zero_extract:SI
8075                    (match_operand 0 "nonimmediate_operand" "rm")
8076                    (match_operand:SI 1 "const_int_operand" "")
8077                    (match_operand:SI 2 "const_int_operand" ""))
8078                  (const_int 0)))]
8079   "ix86_match_ccmode (insn, CCNOmode)
8080    && (GET_MODE (operands[0]) == SImode
8081        || (TARGET_64BIT && GET_MODE (operands[0]) == DImode)
8082        || GET_MODE (operands[0]) == HImode
8083        || GET_MODE (operands[0]) == QImode)"
8084   "#")
8085
8086 (define_insn "*testqi_ext_3_rex64"
8087   [(set (reg 17)
8088         (compare (zero_extract:DI
8089                    (match_operand 0 "nonimmediate_operand" "rm")
8090                    (match_operand:DI 1 "const_int_operand" "")
8091                    (match_operand:DI 2 "const_int_operand" ""))
8092                  (const_int 0)))]
8093   "ix86_match_ccmode (insn, CCNOmode)
8094    && TARGET_64BIT
8095    && (GET_MODE (operands[0]) == SImode
8096        || GET_MODE (operands[0]) == DImode
8097        || GET_MODE (operands[0]) == HImode
8098        || GET_MODE (operands[0]) == QImode)"
8099   "#")
8100
8101 (define_split
8102   [(set (reg 17)
8103         (compare (zero_extract
8104                    (match_operand 0 "nonimmediate_operand" "")
8105                    (match_operand 1 "const_int_operand" "")
8106                    (match_operand 2 "const_int_operand" ""))
8107                  (const_int 0)))]
8108   "ix86_match_ccmode (insn, CCNOmode)"
8109   [(set (reg:CCNO 17) (compare:CCNO (match_dup 3) (const_int 0)))]
8110 {
8111   HOST_WIDE_INT len = INTVAL (operands[1]);
8112   HOST_WIDE_INT pos = INTVAL (operands[2]);
8113   HOST_WIDE_INT mask;
8114   enum machine_mode mode;
8115
8116   mode = GET_MODE (operands[0]);
8117   if (GET_CODE (operands[0]) == MEM)
8118     {
8119       /* ??? Combine likes to put non-volatile mem extractions in QImode
8120          no matter the size of the test.  So find a mode that works.  */
8121       if (! MEM_VOLATILE_P (operands[0]))
8122         {
8123           mode = smallest_mode_for_size (pos + len, MODE_INT);
8124           operands[0] = adjust_address (operands[0], mode, 0);
8125         }
8126     }
8127   else if (mode == HImode && pos + len <= 8)
8128     {
8129       /* Small HImode tests can be converted to QImode.  */
8130       mode = QImode;
8131       operands[0] = gen_lowpart (QImode, operands[0]);
8132     }
8133
8134   mask  = ((HOST_WIDE_INT)1 << (pos + len)) - 1;
8135   mask &= ~(((HOST_WIDE_INT)1 << pos) - 1);
8136
8137   operands[3] = gen_rtx_AND (mode, operands[0],
8138                              GEN_INT (trunc_int_for_mode (mask, mode)));
8139 })
8140
8141 ;; %%% This used to optimize known byte-wide and operations to memory,
8142 ;; and sometimes to QImode registers.  If this is considered useful,
8143 ;; it should be done with splitters.
8144
8145 (define_expand "anddi3"
8146   [(set (match_operand:DI 0 "nonimmediate_operand" "")
8147         (and:DI (match_operand:DI 1 "nonimmediate_operand" "")
8148                 (match_operand:DI 2 "x86_64_szext_general_operand" "")))
8149    (clobber (reg:CC 17))]
8150   "TARGET_64BIT"
8151   "ix86_expand_binary_operator (AND, DImode, operands); DONE;")
8152
8153 (define_insn "*anddi_1_rex64"
8154   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,rm,r,r")
8155         (and:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0,0,qm")
8156                 (match_operand:DI 2 "x86_64_szext_general_operand" "Z,re,rm,L")))
8157    (clobber (reg:CC 17))]
8158   "TARGET_64BIT && ix86_binary_operator_ok (AND, DImode, operands)"
8159 {
8160   switch (get_attr_type (insn))
8161     {
8162     case TYPE_IMOVX:
8163       {
8164         enum machine_mode mode;
8165
8166         if (GET_CODE (operands[2]) != CONST_INT)
8167           abort ();
8168         if (INTVAL (operands[2]) == 0xff)
8169           mode = QImode;
8170         else if (INTVAL (operands[2]) == 0xffff)
8171           mode = HImode;
8172         else
8173           abort ();
8174         
8175         operands[1] = gen_lowpart (mode, operands[1]);
8176         if (mode == QImode)
8177           return "movz{bq|x}\t{%1,%0|%0, %1}";
8178         else
8179           return "movz{wq|x}\t{%1,%0|%0, %1}";
8180       }
8181
8182     default:
8183       if (! rtx_equal_p (operands[0], operands[1]))
8184         abort ();
8185       if (get_attr_mode (insn) == MODE_SI)
8186         return "and{l}\t{%k2, %k0|%k0, %k2}";
8187       else
8188         return "and{q}\t{%2, %0|%0, %2}";
8189     }
8190 }
8191   [(set_attr "type" "alu,alu,alu,imovx")
8192    (set_attr "length_immediate" "*,*,*,0")
8193    (set_attr "mode" "SI,DI,DI,DI")])
8194
8195 (define_insn "*anddi_2"
8196   [(set (reg 17)
8197         (compare (and:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0,0")
8198                          (match_operand:DI 2 "x86_64_szext_general_operand" "Z,rem,re"))
8199                  (const_int 0)))
8200    (set (match_operand:DI 0 "nonimmediate_operand" "=r,r,rm")
8201         (and:DI (match_dup 1) (match_dup 2)))]
8202   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8203    && ix86_binary_operator_ok (AND, DImode, operands)"
8204   "@
8205    and{l}\t{%k2, %k0|%k0, %k2} 
8206    and{q}\t{%2, %0|%0, %2} 
8207    and{q}\t{%2, %0|%0, %2}"
8208   [(set_attr "type" "alu")
8209    (set_attr "mode" "SI,DI,DI")])
8210
8211 (define_expand "andsi3"
8212   [(set (match_operand:SI 0 "nonimmediate_operand" "")
8213         (and:SI (match_operand:SI 1 "nonimmediate_operand" "")
8214                 (match_operand:SI 2 "general_operand" "")))
8215    (clobber (reg:CC 17))]
8216   ""
8217   "ix86_expand_binary_operator (AND, SImode, operands); DONE;")
8218
8219 (define_insn "*andsi_1"
8220   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r,r")
8221         (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,qm")
8222                 (match_operand:SI 2 "general_operand" "ri,rm,L")))
8223    (clobber (reg:CC 17))]
8224   "ix86_binary_operator_ok (AND, SImode, operands)"
8225 {
8226   switch (get_attr_type (insn))
8227     {
8228     case TYPE_IMOVX:
8229       {
8230         enum machine_mode mode;
8231
8232         if (GET_CODE (operands[2]) != CONST_INT)
8233           abort ();
8234         if (INTVAL (operands[2]) == 0xff)
8235           mode = QImode;
8236         else if (INTVAL (operands[2]) == 0xffff)
8237           mode = HImode;
8238         else
8239           abort ();
8240         
8241         operands[1] = gen_lowpart (mode, operands[1]);
8242         if (mode == QImode)
8243           return "movz{bl|x}\t{%1,%0|%0, %1}";
8244         else
8245           return "movz{wl|x}\t{%1,%0|%0, %1}";
8246       }
8247
8248     default:
8249       if (! rtx_equal_p (operands[0], operands[1]))
8250         abort ();
8251       return "and{l}\t{%2, %0|%0, %2}";
8252     }
8253 }
8254   [(set_attr "type" "alu,alu,imovx")
8255    (set_attr "length_immediate" "*,*,0")
8256    (set_attr "mode" "SI")])
8257
8258 (define_split
8259   [(set (match_operand 0 "register_operand" "")
8260         (and (match_dup 0)
8261              (const_int -65536)))
8262    (clobber (reg:CC 17))]
8263   "optimize_size"
8264   [(set (strict_low_part (match_dup 1)) (const_int 0))]
8265   "operands[1] = gen_lowpart (HImode, operands[0]);")
8266
8267 (define_split
8268   [(set (match_operand 0 "ext_register_operand" "")
8269         (and (match_dup 0)
8270              (const_int -256)))
8271    (clobber (reg:CC 17))]
8272   "(optimize_size || !TARGET_PARTIAL_REG_STALL) && reload_completed"
8273   [(set (strict_low_part (match_dup 1)) (const_int 0))]
8274   "operands[1] = gen_lowpart (QImode, operands[0]);")
8275
8276 (define_split
8277   [(set (match_operand 0 "ext_register_operand" "")
8278         (and (match_dup 0)
8279              (const_int -65281)))
8280    (clobber (reg:CC 17))]
8281   "(optimize_size || !TARGET_PARTIAL_REG_STALL) && reload_completed"
8282   [(parallel [(set (zero_extract:SI (match_dup 0)
8283                                     (const_int 8)
8284                                     (const_int 8))
8285                    (xor:SI 
8286                      (zero_extract:SI (match_dup 0)
8287                                       (const_int 8)
8288                                       (const_int 8))
8289                      (zero_extract:SI (match_dup 0)
8290                                       (const_int 8)
8291                                       (const_int 8))))
8292               (clobber (reg:CC 17))])]
8293   "operands[0] = gen_lowpart (SImode, operands[0]);")
8294
8295 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8296 (define_insn "*andsi_1_zext"
8297   [(set (match_operand:DI 0 "register_operand" "=r")
8298         (zero_extend:DI
8299           (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8300                   (match_operand:SI 2 "general_operand" "rim"))))
8301    (clobber (reg:CC 17))]
8302   "TARGET_64BIT && ix86_binary_operator_ok (AND, SImode, operands)"
8303   "and{l}\t{%2, %k0|%k0, %2}"
8304   [(set_attr "type" "alu")
8305    (set_attr "mode" "SI")])
8306
8307 (define_insn "*andsi_2"
8308   [(set (reg 17)
8309         (compare (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0")
8310                          (match_operand:SI 2 "general_operand" "rim,ri"))
8311                  (const_int 0)))
8312    (set (match_operand:SI 0 "nonimmediate_operand" "=r,rm")
8313         (and:SI (match_dup 1) (match_dup 2)))]
8314   "ix86_match_ccmode (insn, CCNOmode)
8315    && ix86_binary_operator_ok (AND, SImode, operands)"
8316   "and{l}\t{%2, %0|%0, %2}"
8317   [(set_attr "type" "alu")
8318    (set_attr "mode" "SI")])
8319
8320 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8321 (define_insn "*andsi_2_zext"
8322   [(set (reg 17)
8323         (compare (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8324                          (match_operand:SI 2 "general_operand" "rim"))
8325                  (const_int 0)))
8326    (set (match_operand:DI 0 "register_operand" "=r")
8327         (zero_extend:DI (and:SI (match_dup 1) (match_dup 2))))]
8328   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8329    && ix86_binary_operator_ok (AND, SImode, operands)"
8330   "and{l}\t{%2, %k0|%k0, %2}"
8331   [(set_attr "type" "alu")
8332    (set_attr "mode" "SI")])
8333
8334 (define_expand "andhi3"
8335   [(set (match_operand:HI 0 "nonimmediate_operand" "")
8336         (and:HI (match_operand:HI 1 "nonimmediate_operand" "")
8337                 (match_operand:HI 2 "general_operand" "")))
8338    (clobber (reg:CC 17))]
8339   "TARGET_HIMODE_MATH"
8340   "ix86_expand_binary_operator (AND, HImode, operands); DONE;")
8341
8342 (define_insn "*andhi_1"
8343   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r,r")
8344         (and:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,qm")
8345                 (match_operand:HI 2 "general_operand" "ri,rm,L")))
8346    (clobber (reg:CC 17))]
8347   "ix86_binary_operator_ok (AND, HImode, operands)"
8348 {
8349   switch (get_attr_type (insn))
8350     {
8351     case TYPE_IMOVX:
8352       if (GET_CODE (operands[2]) != CONST_INT)
8353         abort ();
8354       if (INTVAL (operands[2]) == 0xff)
8355         return "movz{bl|x}\t{%b1, %k0|%k0, %b1}";
8356       abort ();
8357
8358     default:
8359       if (! rtx_equal_p (operands[0], operands[1]))
8360         abort ();
8361
8362       return "and{w}\t{%2, %0|%0, %2}";
8363     }
8364 }
8365   [(set_attr "type" "alu,alu,imovx")
8366    (set_attr "length_immediate" "*,*,0")
8367    (set_attr "mode" "HI,HI,SI")])
8368
8369 (define_insn "*andhi_2"
8370   [(set (reg 17)
8371         (compare (and:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
8372                          (match_operand:HI 2 "general_operand" "rim,ri"))
8373                  (const_int 0)))
8374    (set (match_operand:HI 0 "nonimmediate_operand" "=r,rm")
8375         (and:HI (match_dup 1) (match_dup 2)))]
8376   "ix86_match_ccmode (insn, CCNOmode)
8377    && ix86_binary_operator_ok (AND, HImode, operands)"
8378   "and{w}\t{%2, %0|%0, %2}"
8379   [(set_attr "type" "alu")
8380    (set_attr "mode" "HI")])
8381
8382 (define_expand "andqi3"
8383   [(set (match_operand:QI 0 "nonimmediate_operand" "")
8384         (and:QI (match_operand:QI 1 "nonimmediate_operand" "")
8385                 (match_operand:QI 2 "general_operand" "")))
8386    (clobber (reg:CC 17))]
8387   "TARGET_QIMODE_MATH"
8388   "ix86_expand_binary_operator (AND, QImode, operands); DONE;")
8389
8390 ;; %%% Potential partial reg stall on alternative 2.  What to do?
8391 (define_insn "*andqi_1"
8392   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,q,r")
8393         (and:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
8394                 (match_operand:QI 2 "general_operand" "qi,qmi,ri")))
8395    (clobber (reg:CC 17))]
8396   "ix86_binary_operator_ok (AND, QImode, operands)"
8397   "@
8398    and{b}\t{%2, %0|%0, %2}
8399    and{b}\t{%2, %0|%0, %2}
8400    and{l}\t{%k2, %k0|%k0, %k2}"
8401   [(set_attr "type" "alu")
8402    (set_attr "mode" "QI,QI,SI")])
8403
8404 (define_insn "*andqi_1_slp"
8405   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
8406         (and:QI (match_dup 0)
8407                 (match_operand:QI 1 "general_operand" "qi,qmi")))
8408    (clobber (reg:CC 17))]
8409   ""
8410   "and{b}\t{%1, %0|%0, %1}"
8411   [(set_attr "type" "alu1")
8412    (set_attr "mode" "QI")])
8413
8414 (define_insn "*andqi_2"
8415   [(set (reg 17)
8416         (compare (and:QI
8417                    (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
8418                    (match_operand:QI 2 "general_operand" "qim,qi,i"))
8419                  (const_int 0)))
8420    (set (match_operand:QI 0 "nonimmediate_operand" "=q,qm,*r")
8421         (and:QI (match_dup 1) (match_dup 2)))]
8422   "ix86_match_ccmode (insn, CCNOmode)
8423    && ix86_binary_operator_ok (AND, QImode, operands)"
8424 {
8425   if (which_alternative == 2)
8426     {
8427       if (GET_CODE (operands[2]) == CONST_INT
8428           && (INTVAL (operands[2]) & 0xffffff00))
8429         operands[2] = GEN_INT (INTVAL (operands[2]) & 0xff);
8430       return "and{l}\t{%2, %k0|%k0, %2}";
8431     }
8432   return "and{b}\t{%2, %0|%0, %2}";
8433 }
8434   [(set_attr "type" "alu")
8435    (set_attr "mode" "QI,QI,SI")])
8436
8437 (define_insn "*andqi_2_slp"
8438   [(set (reg 17)
8439         (compare (and:QI
8440                    (match_operand:QI 0 "nonimmediate_operand" "+q,qm")
8441                    (match_operand:QI 1 "nonimmediate_operand" "qmi,qi"))
8442                  (const_int 0)))
8443    (set (strict_low_part (match_dup 0))
8444         (and:QI (match_dup 0) (match_dup 1)))]
8445   "ix86_match_ccmode (insn, CCNOmode)"
8446   "and{b}\t{%1, %0|%0, %1}"
8447   [(set_attr "type" "alu1")
8448    (set_attr "mode" "QI")])
8449
8450 ;; ??? A bug in recog prevents it from recognizing a const_int as an
8451 ;; operand to zero_extend in andqi_ext_1.  It was checking explicitly
8452 ;; for a QImode operand, which of course failed.
8453
8454 (define_insn "andqi_ext_0"
8455   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8456                          (const_int 8)
8457                          (const_int 8))
8458         (and:SI 
8459           (zero_extract:SI
8460             (match_operand 1 "ext_register_operand" "0")
8461             (const_int 8)
8462             (const_int 8))
8463           (match_operand 2 "const_int_operand" "n")))
8464    (clobber (reg:CC 17))]
8465   "(unsigned HOST_WIDE_INT)INTVAL (operands[2]) <= 0xff"
8466   "and{b}\t{%2, %h0|%h0, %2}"
8467   [(set_attr "type" "alu")
8468    (set_attr "length_immediate" "1")
8469    (set_attr "mode" "QI")])
8470
8471 ;; Generated by peephole translating test to and.  This shows up
8472 ;; often in fp comparisons.
8473
8474 (define_insn "*andqi_ext_0_cc"
8475   [(set (reg 17)
8476         (compare
8477           (and:SI
8478             (zero_extract:SI
8479               (match_operand 1 "ext_register_operand" "0")
8480               (const_int 8)
8481               (const_int 8))
8482             (match_operand 2 "const_int_operand" "n"))
8483           (const_int 0)))
8484    (set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8485                          (const_int 8)
8486                          (const_int 8))
8487         (and:SI 
8488           (zero_extract:SI
8489             (match_dup 1)
8490             (const_int 8)
8491             (const_int 8))
8492           (match_dup 2)))]
8493   "ix86_match_ccmode (insn, CCNOmode)
8494    && (unsigned HOST_WIDE_INT)INTVAL (operands[2]) <= 0xff"
8495   "and{b}\t{%2, %h0|%h0, %2}"
8496   [(set_attr "type" "alu")
8497    (set_attr "length_immediate" "1")
8498    (set_attr "mode" "QI")])
8499
8500 (define_insn "*andqi_ext_1"
8501   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8502                          (const_int 8)
8503                          (const_int 8))
8504         (and:SI 
8505           (zero_extract:SI
8506             (match_operand 1 "ext_register_operand" "0")
8507             (const_int 8)
8508             (const_int 8))
8509           (zero_extend:SI
8510             (match_operand:QI 2 "general_operand" "Qm"))))
8511    (clobber (reg:CC 17))]
8512   "!TARGET_64BIT"
8513   "and{b}\t{%2, %h0|%h0, %2}"
8514   [(set_attr "type" "alu")
8515    (set_attr "length_immediate" "0")
8516    (set_attr "mode" "QI")])
8517
8518 (define_insn "*andqi_ext_1_rex64"
8519   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8520                          (const_int 8)
8521                          (const_int 8))
8522         (and:SI 
8523           (zero_extract:SI
8524             (match_operand 1 "ext_register_operand" "0")
8525             (const_int 8)
8526             (const_int 8))
8527           (zero_extend:SI
8528             (match_operand 2 "ext_register_operand" "Q"))))
8529    (clobber (reg:CC 17))]
8530   "TARGET_64BIT"
8531   "and{b}\t{%2, %h0|%h0, %2}"
8532   [(set_attr "type" "alu")
8533    (set_attr "length_immediate" "0")
8534    (set_attr "mode" "QI")])
8535
8536 (define_insn "*andqi_ext_2"
8537   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8538                          (const_int 8)
8539                          (const_int 8))
8540         (and:SI
8541           (zero_extract:SI
8542             (match_operand 1 "ext_register_operand" "%0")
8543             (const_int 8)
8544             (const_int 8))
8545           (zero_extract:SI
8546             (match_operand 2 "ext_register_operand" "Q")
8547             (const_int 8)
8548             (const_int 8))))
8549    (clobber (reg:CC 17))]
8550   ""
8551   "and{b}\t{%h2, %h0|%h0, %h2}"
8552   [(set_attr "type" "alu")
8553    (set_attr "length_immediate" "0")
8554    (set_attr "mode" "QI")])
8555 \f
8556 ;; Logical inclusive OR instructions
8557
8558 ;; %%% This used to optimize known byte-wide and operations to memory.
8559 ;; If this is considered useful, it should be done with splitters.
8560
8561 (define_expand "iordi3"
8562   [(set (match_operand:DI 0 "nonimmediate_operand" "")
8563         (ior:DI (match_operand:DI 1 "nonimmediate_operand" "")
8564                 (match_operand:DI 2 "x86_64_general_operand" "")))
8565    (clobber (reg:CC 17))]
8566   "TARGET_64BIT"
8567   "ix86_expand_binary_operator (IOR, DImode, operands); DONE;")
8568
8569 (define_insn "*iordi_1_rex64"
8570   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
8571         (ior:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
8572                 (match_operand:DI 2 "x86_64_general_operand" "re,rme")))
8573    (clobber (reg:CC 17))]
8574   "TARGET_64BIT
8575    && ix86_binary_operator_ok (IOR, DImode, operands)"
8576   "or{q}\t{%2, %0|%0, %2}"
8577   [(set_attr "type" "alu")
8578    (set_attr "mode" "DI")])
8579
8580 (define_insn "*iordi_2_rex64"
8581   [(set (reg 17)
8582         (compare (ior:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
8583                          (match_operand:DI 2 "x86_64_general_operand" "rem,re"))
8584                  (const_int 0)))
8585    (set (match_operand:DI 0 "nonimmediate_operand" "=r,rm")
8586         (ior:DI (match_dup 1) (match_dup 2)))]
8587   "TARGET_64BIT
8588    && ix86_match_ccmode (insn, CCNOmode)
8589    && ix86_binary_operator_ok (IOR, DImode, operands)"
8590   "or{q}\t{%2, %0|%0, %2}"
8591   [(set_attr "type" "alu")
8592    (set_attr "mode" "DI")])
8593
8594 (define_insn "*iordi_3_rex64"
8595   [(set (reg 17)
8596         (compare (ior:DI (match_operand:DI 1 "nonimmediate_operand" "%0")
8597                          (match_operand:DI 2 "x86_64_general_operand" "rem"))
8598                  (const_int 0)))
8599    (clobber (match_scratch:DI 0 "=r"))]
8600   "TARGET_64BIT
8601    && ix86_match_ccmode (insn, CCNOmode)
8602    && ix86_binary_operator_ok (IOR, DImode, operands)"
8603   "or{q}\t{%2, %0|%0, %2}"
8604   [(set_attr "type" "alu")
8605    (set_attr "mode" "DI")])
8606
8607
8608 (define_expand "iorsi3"
8609   [(set (match_operand:SI 0 "nonimmediate_operand" "")
8610         (ior:SI (match_operand:SI 1 "nonimmediate_operand" "")
8611                 (match_operand:SI 2 "general_operand" "")))
8612    (clobber (reg:CC 17))]
8613   ""
8614   "ix86_expand_binary_operator (IOR, SImode, operands); DONE;")
8615
8616 (define_insn "*iorsi_1"
8617   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
8618         (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0")
8619                 (match_operand:SI 2 "general_operand" "ri,rmi")))
8620    (clobber (reg:CC 17))]
8621   "ix86_binary_operator_ok (IOR, SImode, operands)"
8622   "or{l}\t{%2, %0|%0, %2}"
8623   [(set_attr "type" "alu")
8624    (set_attr "mode" "SI")])
8625
8626 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8627 (define_insn "*iorsi_1_zext"
8628   [(set (match_operand:DI 0 "register_operand" "=rm")
8629         (zero_extend:DI
8630           (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8631                   (match_operand:SI 2 "general_operand" "rim"))))
8632    (clobber (reg:CC 17))]
8633   "TARGET_64BIT && ix86_binary_operator_ok (IOR, SImode, operands)"
8634   "or{l}\t{%2, %k0|%k0, %2}"
8635   [(set_attr "type" "alu")
8636    (set_attr "mode" "SI")])
8637
8638 (define_insn "*iorsi_1_zext_imm"
8639   [(set (match_operand:DI 0 "register_operand" "=rm")
8640         (ior:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "%0"))
8641                 (match_operand:DI 2 "x86_64_zext_immediate_operand" "Z")))
8642    (clobber (reg:CC 17))]
8643   "TARGET_64BIT"
8644   "or{l}\t{%2, %k0|%k0, %2}"
8645   [(set_attr "type" "alu")
8646    (set_attr "mode" "SI")])
8647
8648 (define_insn "*iorsi_2"
8649   [(set (reg 17)
8650         (compare (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0")
8651                          (match_operand:SI 2 "general_operand" "rim,ri"))
8652                  (const_int 0)))
8653    (set (match_operand:SI 0 "nonimmediate_operand" "=r,rm")
8654         (ior:SI (match_dup 1) (match_dup 2)))]
8655   "ix86_match_ccmode (insn, CCNOmode)
8656    && ix86_binary_operator_ok (IOR, SImode, operands)"
8657   "or{l}\t{%2, %0|%0, %2}"
8658   [(set_attr "type" "alu")
8659    (set_attr "mode" "SI")])
8660
8661 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8662 ;; ??? Special case for immediate operand is missing - it is tricky.
8663 (define_insn "*iorsi_2_zext"
8664   [(set (reg 17)
8665         (compare (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8666                          (match_operand:SI 2 "general_operand" "rim"))
8667                  (const_int 0)))
8668    (set (match_operand:DI 0 "register_operand" "=r")
8669         (zero_extend:DI (ior:SI (match_dup 1) (match_dup 2))))]
8670   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8671    && ix86_binary_operator_ok (IOR, SImode, operands)"
8672   "or{l}\t{%2, %k0|%k0, %2}"
8673   [(set_attr "type" "alu")
8674    (set_attr "mode" "SI")])
8675
8676 (define_insn "*iorsi_2_zext_imm"
8677   [(set (reg 17)
8678         (compare (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8679                          (match_operand 2 "x86_64_zext_immediate_operand" "Z"))
8680                  (const_int 0)))
8681    (set (match_operand:DI 0 "register_operand" "=r")
8682         (ior:DI (zero_extend:DI (match_dup 1)) (match_dup 2)))]
8683   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8684    && ix86_binary_operator_ok (IOR, SImode, operands)"
8685   "or{l}\t{%2, %k0|%k0, %2}"
8686   [(set_attr "type" "alu")
8687    (set_attr "mode" "SI")])
8688
8689 (define_insn "*iorsi_3"
8690   [(set (reg 17)
8691         (compare (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8692                          (match_operand:SI 2 "general_operand" "rim"))
8693                  (const_int 0)))
8694    (clobber (match_scratch:SI 0 "=r"))]
8695   "ix86_match_ccmode (insn, CCNOmode)
8696    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
8697   "or{l}\t{%2, %0|%0, %2}"
8698   [(set_attr "type" "alu")
8699    (set_attr "mode" "SI")])
8700
8701 (define_expand "iorhi3"
8702   [(set (match_operand:HI 0 "nonimmediate_operand" "")
8703         (ior:HI (match_operand:HI 1 "nonimmediate_operand" "")
8704                 (match_operand:HI 2 "general_operand" "")))
8705    (clobber (reg:CC 17))]
8706   "TARGET_HIMODE_MATH"
8707   "ix86_expand_binary_operator (IOR, HImode, operands); DONE;")
8708
8709 (define_insn "*iorhi_1"
8710   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,m")
8711         (ior:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
8712                 (match_operand:HI 2 "general_operand" "rmi,ri")))
8713    (clobber (reg:CC 17))]
8714   "ix86_binary_operator_ok (IOR, HImode, operands)"
8715   "or{w}\t{%2, %0|%0, %2}"
8716   [(set_attr "type" "alu")
8717    (set_attr "mode" "HI")])
8718
8719 (define_insn "*iorhi_2"
8720   [(set (reg 17)
8721         (compare (ior:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
8722                          (match_operand:HI 2 "general_operand" "rim,ri"))
8723                  (const_int 0)))
8724    (set (match_operand:HI 0 "nonimmediate_operand" "=r,rm")
8725         (ior:HI (match_dup 1) (match_dup 2)))]
8726   "ix86_match_ccmode (insn, CCNOmode)
8727    && ix86_binary_operator_ok (IOR, HImode, operands)"
8728   "or{w}\t{%2, %0|%0, %2}"
8729   [(set_attr "type" "alu")
8730    (set_attr "mode" "HI")])
8731
8732 (define_insn "*iorhi_3"
8733   [(set (reg 17)
8734         (compare (ior:HI (match_operand:HI 1 "nonimmediate_operand" "%0")
8735                          (match_operand:HI 2 "general_operand" "rim"))
8736                  (const_int 0)))
8737    (clobber (match_scratch:HI 0 "=r"))]
8738   "ix86_match_ccmode (insn, CCNOmode)
8739    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
8740   "or{w}\t{%2, %0|%0, %2}"
8741   [(set_attr "type" "alu")
8742    (set_attr "mode" "HI")])
8743
8744 (define_expand "iorqi3"
8745   [(set (match_operand:QI 0 "nonimmediate_operand" "")
8746         (ior:QI (match_operand:QI 1 "nonimmediate_operand" "")
8747                 (match_operand:QI 2 "general_operand" "")))
8748    (clobber (reg:CC 17))]
8749   "TARGET_QIMODE_MATH"
8750   "ix86_expand_binary_operator (IOR, QImode, operands); DONE;")
8751
8752 ;; %%% Potential partial reg stall on alternative 2.  What to do?
8753 (define_insn "*iorqi_1"
8754   [(set (match_operand:QI 0 "nonimmediate_operand" "=q,m,r")
8755         (ior:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
8756                 (match_operand:QI 2 "general_operand" "qmi,qi,ri")))
8757    (clobber (reg:CC 17))]
8758   "ix86_binary_operator_ok (IOR, QImode, operands)"
8759   "@
8760    or{b}\t{%2, %0|%0, %2}
8761    or{b}\t{%2, %0|%0, %2}
8762    or{l}\t{%k2, %k0|%k0, %k2}"
8763   [(set_attr "type" "alu")
8764    (set_attr "mode" "QI,QI,SI")])
8765
8766 (define_insn "*iorqi_1_slp"
8767   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+q,m"))
8768         (ior:QI (match_dup 0)
8769                 (match_operand:QI 1 "general_operand" "qmi,qi")))
8770    (clobber (reg:CC 17))]
8771   ""
8772   "or{b}\t{%1, %0|%0, %1}"
8773   [(set_attr "type" "alu1")
8774    (set_attr "mode" "QI")])
8775
8776 (define_insn "*iorqi_2"
8777   [(set (reg 17)
8778         (compare (ior:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0")
8779                          (match_operand:QI 2 "general_operand" "qim,qi"))
8780                  (const_int 0)))
8781    (set (match_operand:QI 0 "nonimmediate_operand" "=q,qm")
8782         (ior:QI (match_dup 1) (match_dup 2)))]
8783   "ix86_match_ccmode (insn, CCNOmode)
8784    && ix86_binary_operator_ok (IOR, QImode, operands)"
8785   "or{b}\t{%2, %0|%0, %2}"
8786   [(set_attr "type" "alu")
8787    (set_attr "mode" "QI")])
8788
8789 (define_insn "*iorqi_2_slp"
8790   [(set (reg 17)
8791         (compare (ior:QI (match_operand:QI 0 "nonimmediate_operand" "+q,qm")
8792                          (match_operand:QI 1 "general_operand" "qim,qi"))
8793                  (const_int 0)))
8794    (set (strict_low_part (match_dup 0))
8795         (ior:QI (match_dup 0) (match_dup 1)))]
8796   "ix86_match_ccmode (insn, CCNOmode)"
8797   "or{b}\t{%1, %0|%0, %1}"
8798   [(set_attr "type" "alu1")
8799    (set_attr "mode" "QI")])
8800
8801 (define_insn "*iorqi_3"
8802   [(set (reg 17)
8803         (compare (ior:QI (match_operand:QI 1 "nonimmediate_operand" "%0")
8804                          (match_operand:QI 2 "general_operand" "qim"))
8805                  (const_int 0)))
8806    (clobber (match_scratch:QI 0 "=q"))]
8807   "ix86_match_ccmode (insn, CCNOmode)
8808    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
8809   "or{b}\t{%2, %0|%0, %2}"
8810   [(set_attr "type" "alu")
8811    (set_attr "mode" "QI")])
8812
8813 \f
8814 ;; Logical XOR instructions
8815
8816 ;; %%% This used to optimize known byte-wide and operations to memory.
8817 ;; If this is considered useful, it should be done with splitters.
8818
8819 (define_expand "xordi3"
8820   [(set (match_operand:DI 0 "nonimmediate_operand" "")
8821         (xor:DI (match_operand:DI 1 "nonimmediate_operand" "")
8822                 (match_operand:DI 2 "x86_64_general_operand" "")))
8823    (clobber (reg:CC 17))]
8824   "TARGET_64BIT"
8825   "ix86_expand_binary_operator (XOR, DImode, operands); DONE;")
8826
8827 (define_insn "*xordi_1_rex64"
8828   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
8829         (xor:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
8830                 (match_operand:DI 2 "x86_64_general_operand" "re,rm")))
8831    (clobber (reg:CC 17))]
8832   "TARGET_64BIT
8833    && ix86_binary_operator_ok (XOR, DImode, operands)"
8834   "@
8835    xor{q}\t{%2, %0|%0, %2} 
8836    xor{q}\t{%2, %0|%0, %2}"
8837   [(set_attr "type" "alu")
8838    (set_attr "mode" "DI,DI")])
8839
8840 (define_insn "*xordi_2_rex64"
8841   [(set (reg 17)
8842         (compare (xor:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
8843                          (match_operand:DI 2 "x86_64_general_operand" "rem,re"))
8844                  (const_int 0)))
8845    (set (match_operand:DI 0 "nonimmediate_operand" "=r,rm")
8846         (xor:DI (match_dup 1) (match_dup 2)))]
8847   "TARGET_64BIT
8848    && ix86_match_ccmode (insn, CCNOmode)
8849    && ix86_binary_operator_ok (XOR, DImode, operands)"
8850   "@
8851    xor{q}\t{%2, %0|%0, %2} 
8852    xor{q}\t{%2, %0|%0, %2}"
8853   [(set_attr "type" "alu")
8854    (set_attr "mode" "DI,DI")])
8855
8856 (define_insn "*xordi_3_rex64"
8857   [(set (reg 17)
8858         (compare (xor:DI (match_operand:DI 1 "nonimmediate_operand" "%0")
8859                          (match_operand:DI 2 "x86_64_general_operand" "rem"))
8860                  (const_int 0)))
8861    (clobber (match_scratch:DI 0 "=r"))]
8862   "TARGET_64BIT
8863    && ix86_match_ccmode (insn, CCNOmode)
8864    && ix86_binary_operator_ok (XOR, DImode, operands)"
8865   "xor{q}\t{%2, %0|%0, %2}"
8866   [(set_attr "type" "alu")
8867    (set_attr "mode" "DI")])
8868
8869 (define_expand "xorsi3"
8870   [(set (match_operand:SI 0 "nonimmediate_operand" "")
8871         (xor:SI (match_operand:SI 1 "nonimmediate_operand" "")
8872                 (match_operand:SI 2 "general_operand" "")))
8873    (clobber (reg:CC 17))]
8874   ""
8875   "ix86_expand_binary_operator (XOR, SImode, operands); DONE;")
8876
8877 (define_insn "*xorsi_1"
8878   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
8879         (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0")
8880                 (match_operand:SI 2 "general_operand" "ri,rm")))
8881    (clobber (reg:CC 17))]
8882   "ix86_binary_operator_ok (XOR, SImode, operands)"
8883   "xor{l}\t{%2, %0|%0, %2}"
8884   [(set_attr "type" "alu")
8885    (set_attr "mode" "SI")])
8886
8887 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8888 ;; Add speccase for immediates
8889 (define_insn "*xorsi_1_zext"
8890   [(set (match_operand:DI 0 "register_operand" "=r")
8891         (zero_extend:DI
8892           (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8893                   (match_operand:SI 2 "general_operand" "rim"))))
8894    (clobber (reg:CC 17))]
8895   "TARGET_64BIT && ix86_binary_operator_ok (XOR, SImode, operands)"
8896   "xor{l}\t{%2, %k0|%k0, %2}"
8897   [(set_attr "type" "alu")
8898    (set_attr "mode" "SI")])
8899
8900 (define_insn "*xorsi_1_zext_imm"
8901   [(set (match_operand:DI 0 "register_operand" "=r")
8902         (xor:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "%0"))
8903                 (match_operand:DI 2 "x86_64_zext_immediate_operand" "Z")))
8904    (clobber (reg:CC 17))]
8905   "TARGET_64BIT && ix86_binary_operator_ok (XOR, SImode, operands)"
8906   "xor{l}\t{%2, %k0|%k0, %2}"
8907   [(set_attr "type" "alu")
8908    (set_attr "mode" "SI")])
8909
8910 (define_insn "*xorsi_2"
8911   [(set (reg 17)
8912         (compare (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0")
8913                          (match_operand:SI 2 "general_operand" "rim,ri"))
8914                  (const_int 0)))
8915    (set (match_operand:SI 0 "nonimmediate_operand" "=r,rm")
8916         (xor:SI (match_dup 1) (match_dup 2)))]
8917   "ix86_match_ccmode (insn, CCNOmode)
8918    && ix86_binary_operator_ok (XOR, SImode, operands)"
8919   "xor{l}\t{%2, %0|%0, %2}"
8920   [(set_attr "type" "alu")
8921    (set_attr "mode" "SI")])
8922
8923 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8924 ;; ??? Special case for immediate operand is missing - it is tricky.
8925 (define_insn "*xorsi_2_zext"
8926   [(set (reg 17)
8927         (compare (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8928                          (match_operand:SI 2 "general_operand" "rim"))
8929                  (const_int 0)))
8930    (set (match_operand:DI 0 "register_operand" "=r")
8931         (zero_extend:DI (xor:SI (match_dup 1) (match_dup 2))))]
8932   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8933    && ix86_binary_operator_ok (XOR, SImode, operands)"
8934   "xor{l}\t{%2, %k0|%k0, %2}"
8935   [(set_attr "type" "alu")
8936    (set_attr "mode" "SI")])
8937
8938 (define_insn "*xorsi_2_zext_imm"
8939   [(set (reg 17)
8940         (compare (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8941                          (match_operand 2 "x86_64_zext_immediate_operand" "Z"))
8942                  (const_int 0)))
8943    (set (match_operand:DI 0 "register_operand" "=r")
8944         (xor:DI (zero_extend:DI (match_dup 1)) (match_dup 2)))]
8945   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8946    && ix86_binary_operator_ok (XOR, SImode, operands)"
8947   "xor{l}\t{%2, %k0|%k0, %2}"
8948   [(set_attr "type" "alu")
8949    (set_attr "mode" "SI")])
8950
8951 (define_insn "*xorsi_3"
8952   [(set (reg 17)
8953         (compare (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8954                          (match_operand:SI 2 "general_operand" "rim"))
8955                  (const_int 0)))
8956    (clobber (match_scratch:SI 0 "=r"))]
8957   "ix86_match_ccmode (insn, CCNOmode)
8958    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
8959   "xor{l}\t{%2, %0|%0, %2}"
8960   [(set_attr "type" "alu")
8961    (set_attr "mode" "SI")])
8962
8963 (define_expand "xorhi3"
8964   [(set (match_operand:HI 0 "nonimmediate_operand" "")
8965         (xor:HI (match_operand:HI 1 "nonimmediate_operand" "")
8966                 (match_operand:HI 2 "general_operand" "")))
8967    (clobber (reg:CC 17))]
8968   "TARGET_HIMODE_MATH"
8969   "ix86_expand_binary_operator (XOR, HImode, operands); DONE;")
8970
8971 (define_insn "*xorhi_1"
8972   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,m")
8973         (xor:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
8974                 (match_operand:HI 2 "general_operand" "rmi,ri")))
8975    (clobber (reg:CC 17))]
8976   "ix86_binary_operator_ok (XOR, HImode, operands)"
8977   "xor{w}\t{%2, %0|%0, %2}"
8978   [(set_attr "type" "alu")
8979    (set_attr "mode" "HI")])
8980
8981 (define_insn "*xorhi_2"
8982   [(set (reg 17)
8983         (compare (xor:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
8984                          (match_operand:HI 2 "general_operand" "rim,ri"))
8985                  (const_int 0)))
8986    (set (match_operand:HI 0 "nonimmediate_operand" "=r,rm")
8987         (xor:HI (match_dup 1) (match_dup 2)))]
8988   "ix86_match_ccmode (insn, CCNOmode)
8989    && ix86_binary_operator_ok (XOR, HImode, operands)"
8990   "xor{w}\t{%2, %0|%0, %2}"
8991   [(set_attr "type" "alu")
8992    (set_attr "mode" "HI")])
8993
8994 (define_insn "*xorhi_3"
8995   [(set (reg 17)
8996         (compare (xor:HI (match_operand:HI 1 "nonimmediate_operand" "%0")
8997                          (match_operand:HI 2 "general_operand" "rim"))
8998                  (const_int 0)))
8999    (clobber (match_scratch:HI 0 "=r"))]
9000   "ix86_match_ccmode (insn, CCNOmode)
9001    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
9002   "xor{w}\t{%2, %0|%0, %2}"
9003   [(set_attr "type" "alu")
9004    (set_attr "mode" "HI")])
9005
9006 (define_expand "xorqi3"
9007   [(set (match_operand:QI 0 "nonimmediate_operand" "")
9008         (xor:QI (match_operand:QI 1 "nonimmediate_operand" "")
9009                 (match_operand:QI 2 "general_operand" "")))
9010    (clobber (reg:CC 17))]
9011   "TARGET_QIMODE_MATH"
9012   "ix86_expand_binary_operator (XOR, QImode, operands); DONE;")
9013
9014 ;; %%% Potential partial reg stall on alternative 2.  What to do?
9015 (define_insn "*xorqi_1"
9016   [(set (match_operand:QI 0 "nonimmediate_operand" "=q,m,r")
9017         (xor:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
9018                 (match_operand:QI 2 "general_operand" "qmi,qi,ri")))
9019    (clobber (reg:CC 17))]
9020   "ix86_binary_operator_ok (XOR, QImode, operands)"
9021   "@
9022    xor{b}\t{%2, %0|%0, %2}
9023    xor{b}\t{%2, %0|%0, %2}
9024    xor{l}\t{%k2, %k0|%k0, %k2}"
9025   [(set_attr "type" "alu")
9026    (set_attr "mode" "QI,QI,SI")])
9027
9028 (define_insn "*xorqi_ext_1"
9029   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9030                          (const_int 8)
9031                          (const_int 8))
9032         (xor:SI 
9033           (zero_extract:SI (match_operand 1 "ext_register_operand" "0")
9034                            (const_int 8)
9035                            (const_int 8))
9036           (zero_extract:SI (match_operand 2 "ext_register_operand" "Q")
9037                            (const_int 8)
9038                            (const_int 8))))
9039    (clobber (reg:CC 17))]
9040   ""
9041   "xor{b}\t{%h2, %h0|%h0, %h2}"
9042   [(set_attr "type" "alu")
9043    (set_attr "length_immediate" "0")
9044    (set_attr "mode" "QI")])
9045
9046 (define_insn "*xorqi_cc_1"
9047   [(set (reg 17)
9048         (compare
9049           (xor:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0")
9050                   (match_operand:QI 2 "general_operand" "qim,qi"))
9051           (const_int 0)))
9052    (set (match_operand:QI 0 "nonimmediate_operand" "=q,qm")
9053         (xor:QI (match_dup 1) (match_dup 2)))]
9054   "ix86_match_ccmode (insn, CCNOmode)
9055    && ix86_binary_operator_ok (XOR, QImode, operands)"
9056   "xor{b}\t{%2, %0|%0, %2}"
9057   [(set_attr "type" "alu")
9058    (set_attr "mode" "QI")])
9059
9060 (define_insn "*xorqi_cc_2"
9061   [(set (reg 17)
9062         (compare
9063           (xor:QI (match_operand:QI 1 "nonimmediate_operand" "%0")
9064                   (match_operand:QI 2 "general_operand" "qim"))
9065           (const_int 0)))
9066    (clobber (match_scratch:QI 0 "=q"))]
9067   "ix86_match_ccmode (insn, CCNOmode)
9068    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
9069   "xor{b}\t{%2, %0|%0, %2}"
9070   [(set_attr "type" "alu")
9071    (set_attr "mode" "QI")])
9072
9073 (define_insn "*xorqi_cc_ext_1"
9074   [(set (reg 17)
9075         (compare
9076           (xor:SI
9077             (zero_extract:SI
9078               (match_operand 1 "ext_register_operand" "0")
9079               (const_int 8)
9080               (const_int 8))
9081             (match_operand:QI 2 "general_operand" "qmn"))
9082           (const_int 0)))
9083    (set (zero_extract:SI (match_operand 0 "ext_register_operand" "=q")
9084                          (const_int 8)
9085                          (const_int 8))
9086         (xor:SI 
9087           (zero_extract:SI (match_dup 1) (const_int 8) (const_int 8))
9088           (match_dup 2)))]
9089   "!TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
9090   "xor{b}\t{%2, %h0|%h0, %2}"
9091   [(set_attr "type" "alu")
9092    (set_attr "mode" "QI")])
9093
9094 (define_insn "*xorqi_cc_ext_1_rex64"
9095   [(set (reg 17)
9096         (compare
9097           (xor:SI
9098             (zero_extract:SI
9099               (match_operand 1 "ext_register_operand" "0")
9100               (const_int 8)
9101               (const_int 8))
9102             (match_operand:QI 2 "nonmemory_operand" "Qn"))
9103           (const_int 0)))
9104    (set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9105                          (const_int 8)
9106                          (const_int 8))
9107         (xor:SI 
9108           (zero_extract:SI (match_dup 1) (const_int 8) (const_int 8))
9109           (match_dup 2)))]
9110   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
9111   "xor{b}\t{%2, %h0|%h0, %2}"
9112   [(set_attr "type" "alu")
9113    (set_attr "mode" "QI")])
9114
9115 (define_expand "xorqi_cc_ext_1"
9116   [(parallel [
9117      (set (reg:CCNO 17)
9118           (compare:CCNO
9119             (xor:SI
9120               (zero_extract:SI
9121                 (match_operand 1 "ext_register_operand" "")
9122                 (const_int 8)
9123                 (const_int 8))
9124               (match_operand:QI 2 "general_operand" ""))
9125             (const_int 0)))
9126      (set (zero_extract:SI (match_operand 0 "ext_register_operand" "")
9127                            (const_int 8)
9128                            (const_int 8))
9129           (xor:SI 
9130             (zero_extract:SI (match_dup 1) (const_int 8) (const_int 8))
9131             (match_dup 2)))])]
9132   ""
9133   "")
9134 \f
9135 ;; Negation instructions
9136
9137 (define_expand "negdi2"
9138   [(parallel [(set (match_operand:DI 0 "nonimmediate_operand" "")
9139                    (neg:DI (match_operand:DI 1 "nonimmediate_operand" "")))
9140               (clobber (reg:CC 17))])]
9141   ""
9142   "ix86_expand_unary_operator (NEG, DImode, operands); DONE;")
9143
9144 (define_insn "*negdi2_1"
9145   [(set (match_operand:DI 0 "nonimmediate_operand" "=ro")
9146         (neg:DI (match_operand:DI 1 "general_operand" "0")))
9147    (clobber (reg:CC 17))]
9148   "!TARGET_64BIT
9149    && ix86_unary_operator_ok (NEG, DImode, operands)"
9150   "#")
9151
9152 (define_split
9153   [(set (match_operand:DI 0 "nonimmediate_operand" "")
9154         (neg:DI (match_operand:DI 1 "general_operand" "")))
9155    (clobber (reg:CC 17))]
9156   "reload_completed
9157    && !TARGET_64BIT"
9158   [(parallel
9159     [(set (reg:CCZ 17)
9160           (compare:CCZ (neg:SI (match_dup 2)) (const_int 0)))
9161      (set (match_dup 0) (neg:SI (match_dup 2)))])
9162    (parallel
9163     [(set (match_dup 1)
9164           (plus:SI (plus:SI (ltu:SI (reg:CC 17) (const_int 0))
9165                             (match_dup 3))
9166                    (const_int 0)))
9167      (clobber (reg:CC 17))])
9168    (parallel
9169     [(set (match_dup 1)
9170           (neg:SI (match_dup 1)))
9171      (clobber (reg:CC 17))])]
9172   "split_di (operands+1, 1, operands+2, operands+3);
9173    split_di (operands+0, 1, operands+0, operands+1);")
9174
9175 (define_insn "*negdi2_1_rex64"
9176   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
9177         (neg:DI (match_operand:DI 1 "nonimmediate_operand" "0")))
9178    (clobber (reg:CC 17))]
9179   "TARGET_64BIT && ix86_unary_operator_ok (NEG, DImode, operands)"
9180   "neg{q}\t%0"
9181   [(set_attr "type" "negnot")
9182    (set_attr "mode" "DI")])
9183
9184 ;; The problem with neg is that it does not perform (compare x 0),
9185 ;; it really performs (compare 0 x), which leaves us with the zero
9186 ;; flag being the only useful item.
9187
9188 (define_insn "*negdi2_cmpz_rex64"
9189   [(set (reg:CCZ 17)
9190         (compare:CCZ (neg:DI (match_operand:DI 1 "nonimmediate_operand" "0"))
9191                      (const_int 0)))
9192    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
9193         (neg:DI (match_dup 1)))]
9194   "TARGET_64BIT && ix86_unary_operator_ok (NEG, DImode, operands)"
9195   "neg{q}\t%0"
9196   [(set_attr "type" "negnot")
9197    (set_attr "mode" "DI")])
9198
9199
9200 (define_expand "negsi2"
9201   [(parallel [(set (match_operand:SI 0 "nonimmediate_operand" "")
9202                    (neg:SI (match_operand:SI 1 "nonimmediate_operand" "")))
9203               (clobber (reg:CC 17))])]
9204   ""
9205   "ix86_expand_unary_operator (NEG, SImode, operands); DONE;")
9206
9207 (define_insn "*negsi2_1"
9208   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
9209         (neg:SI (match_operand:SI 1 "nonimmediate_operand" "0")))
9210    (clobber (reg:CC 17))]
9211   "ix86_unary_operator_ok (NEG, SImode, operands)"
9212   "neg{l}\t%0"
9213   [(set_attr "type" "negnot")
9214    (set_attr "mode" "SI")])
9215
9216 ;; Combine is quite creative about this pattern.
9217 (define_insn "*negsi2_1_zext"
9218   [(set (match_operand:DI 0 "register_operand" "=r")
9219         (lshiftrt:DI (neg:DI (ashift:DI (match_operand:DI 1 "register_operand" "0")
9220                                         (const_int 32)))
9221                      (const_int 32)))
9222    (clobber (reg:CC 17))]
9223   "TARGET_64BIT && ix86_unary_operator_ok (NEG, SImode, operands)"
9224   "neg{l}\t%k0"
9225   [(set_attr "type" "negnot")
9226    (set_attr "mode" "SI")])
9227
9228 ;; The problem with neg is that it does not perform (compare x 0),
9229 ;; it really performs (compare 0 x), which leaves us with the zero
9230 ;; flag being the only useful item.
9231
9232 (define_insn "*negsi2_cmpz"
9233   [(set (reg:CCZ 17)
9234         (compare:CCZ (neg:SI (match_operand:SI 1 "nonimmediate_operand" "0"))
9235                      (const_int 0)))
9236    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
9237         (neg:SI (match_dup 1)))]
9238   "ix86_unary_operator_ok (NEG, SImode, operands)"
9239   "neg{l}\t%0"
9240   [(set_attr "type" "negnot")
9241    (set_attr "mode" "SI")])
9242
9243 (define_insn "*negsi2_cmpz_zext"
9244   [(set (reg:CCZ 17)
9245         (compare:CCZ (lshiftrt:DI
9246                        (neg:DI (ashift:DI
9247                                  (match_operand:DI 1 "register_operand" "0")
9248                                  (const_int 32)))
9249                        (const_int 32))
9250                      (const_int 0)))
9251    (set (match_operand:DI 0 "register_operand" "=r")
9252         (lshiftrt:DI (neg:DI (ashift:DI (match_dup 1)
9253                                         (const_int 32)))
9254                      (const_int 32)))]
9255   "TARGET_64BIT && ix86_unary_operator_ok (NEG, SImode, operands)"
9256   "neg{l}\t%k0"
9257   [(set_attr "type" "negnot")
9258    (set_attr "mode" "SI")])
9259
9260 (define_expand "neghi2"
9261   [(parallel [(set (match_operand:HI 0 "nonimmediate_operand" "")
9262                    (neg:HI (match_operand:HI 1 "nonimmediate_operand" "")))
9263               (clobber (reg:CC 17))])]
9264   "TARGET_HIMODE_MATH"
9265   "ix86_expand_unary_operator (NEG, HImode, operands); DONE;")
9266
9267 (define_insn "*neghi2_1"
9268   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
9269         (neg:HI (match_operand:HI 1 "nonimmediate_operand" "0")))
9270    (clobber (reg:CC 17))]
9271   "ix86_unary_operator_ok (NEG, HImode, operands)"
9272   "neg{w}\t%0"
9273   [(set_attr "type" "negnot")
9274    (set_attr "mode" "HI")])
9275
9276 (define_insn "*neghi2_cmpz"
9277   [(set (reg:CCZ 17)
9278         (compare:CCZ (neg:HI (match_operand:HI 1 "nonimmediate_operand" "0"))
9279                      (const_int 0)))
9280    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
9281         (neg:HI (match_dup 1)))]
9282   "ix86_unary_operator_ok (NEG, HImode, operands)"
9283   "neg{w}\t%0"
9284   [(set_attr "type" "negnot")
9285    (set_attr "mode" "HI")])
9286
9287 (define_expand "negqi2"
9288   [(parallel [(set (match_operand:QI 0 "nonimmediate_operand" "")
9289                    (neg:QI (match_operand:QI 1 "nonimmediate_operand" "")))
9290               (clobber (reg:CC 17))])]
9291   "TARGET_QIMODE_MATH"
9292   "ix86_expand_unary_operator (NEG, QImode, operands); DONE;")
9293
9294 (define_insn "*negqi2_1"
9295   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
9296         (neg:QI (match_operand:QI 1 "nonimmediate_operand" "0")))
9297    (clobber (reg:CC 17))]
9298   "ix86_unary_operator_ok (NEG, QImode, operands)"
9299   "neg{b}\t%0"
9300   [(set_attr "type" "negnot")
9301    (set_attr "mode" "QI")])
9302
9303 (define_insn "*negqi2_cmpz"
9304   [(set (reg:CCZ 17)
9305         (compare:CCZ (neg:QI (match_operand:QI 1 "nonimmediate_operand" "0"))
9306                      (const_int 0)))
9307    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
9308         (neg:QI (match_dup 1)))]
9309   "ix86_unary_operator_ok (NEG, QImode, operands)"
9310   "neg{b}\t%0"
9311   [(set_attr "type" "negnot")
9312    (set_attr "mode" "QI")])
9313
9314 ;; Changing of sign for FP values is doable using integer unit too.
9315
9316 (define_expand "negsf2"
9317   [(parallel [(set (match_operand:SF 0 "nonimmediate_operand" "")
9318                    (neg:SF (match_operand:SF 1 "nonimmediate_operand" "")))
9319               (clobber (reg:CC 17))])]
9320   "TARGET_80387"
9321   "if (TARGET_SSE)
9322      {
9323        /* In case operand is in memory,  we will not use SSE.  */
9324        if (memory_operand (operands[0], VOIDmode)
9325            && rtx_equal_p (operands[0], operands[1]))
9326          emit_insn (gen_negsf2_memory (operands[0], operands[1]));
9327        else
9328         {
9329           /* Using SSE is tricky, since we need bitwise negation of -0
9330              in register.  */
9331           rtx reg = gen_reg_rtx (SFmode);
9332           rtx dest = operands[0];
9333
9334           operands[1] = force_reg (SFmode, operands[1]);
9335           operands[0] = force_reg (SFmode, operands[0]);
9336           emit_move_insn (reg,
9337                           gen_lowpart (SFmode,
9338                                        GEN_INT (trunc_int_for_mode (0x80000000,
9339                                                                     SImode))));
9340           emit_insn (gen_negsf2_ifs (operands[0], operands[1], reg));
9341           if (dest != operands[0])
9342             emit_move_insn (dest, operands[0]);
9343         }
9344        DONE;
9345      }
9346    ix86_expand_unary_operator (NEG, SFmode, operands); DONE;")
9347
9348 (define_insn "negsf2_memory"
9349   [(set (match_operand:SF 0 "memory_operand" "=m")
9350         (neg:SF (match_operand:SF 1 "memory_operand" "0")))
9351    (clobber (reg:CC 17))]
9352   "ix86_unary_operator_ok (NEG, SFmode, operands)"
9353   "#")
9354
9355 (define_insn "negsf2_ifs"
9356   [(set (match_operand:SF 0 "nonimmediate_operand" "=x#fr,x#fr,f#xr,rm#xf")
9357         (neg:SF (match_operand:SF 1 "nonimmediate_operand" "0,x#fr,0,0")))
9358    (use (match_operand:SF 2 "nonmemory_operand" "x,0#x,*g#x,*g#x"))
9359    (clobber (reg:CC 17))]
9360   "TARGET_SSE
9361    && (reload_in_progress || reload_completed
9362        || (register_operand (operands[0], VOIDmode)
9363            && register_operand (operands[1], VOIDmode)))"
9364   "#")
9365
9366 (define_split
9367   [(set (match_operand:SF 0 "memory_operand" "")
9368         (neg:SF (match_operand:SF 1 "memory_operand" "")))
9369    (use (match_operand:SF 2 "" ""))
9370    (clobber (reg:CC 17))]
9371   ""
9372   [(parallel [(set (match_dup 0)
9373                    (neg:SF (match_dup 1)))
9374               (clobber (reg:CC 17))])])
9375
9376 (define_split
9377   [(set (match_operand:SF 0 "register_operand" "")
9378         (neg:SF (match_operand:SF 1 "register_operand" "")))
9379    (use (match_operand:SF 2 "" ""))
9380    (clobber (reg:CC 17))]
9381   "reload_completed && !SSE_REG_P (operands[0])"
9382   [(parallel [(set (match_dup 0)
9383                    (neg:SF (match_dup 1)))
9384               (clobber (reg:CC 17))])])
9385
9386 (define_split
9387   [(set (match_operand:SF 0 "register_operand" "")
9388         (neg:SF (match_operand:SF 1 "register_operand" "")))
9389    (use (match_operand:SF 2 "register_operand" ""))
9390    (clobber (reg:CC 17))]
9391   "reload_completed && SSE_REG_P (operands[0])"
9392   [(set (subreg:TI (match_dup 0) 0)
9393         (xor:TI (subreg:TI (match_dup 1) 0)
9394                 (subreg:TI (match_dup 2) 0)))]
9395 {
9396   if (operands_match_p (operands[0], operands[2]))
9397     {
9398       rtx tmp;
9399       tmp = operands[1];
9400       operands[1] = operands[2];
9401       operands[2] = tmp;
9402     }
9403 })
9404
9405
9406 ;; Keep 'f' and 'r' in separate alternatives to avoid reload problems
9407 ;; because of secondary memory needed to reload from class FLOAT_INT_REGS
9408 ;; to itself.
9409 (define_insn "*negsf2_if"
9410   [(set (match_operand:SF 0 "nonimmediate_operand" "=f#r,rm#f")
9411         (neg:SF (match_operand:SF 1 "nonimmediate_operand" "0,0")))
9412    (clobber (reg:CC 17))]
9413   "TARGET_80387 && !TARGET_SSE
9414    && ix86_unary_operator_ok (NEG, SFmode, operands)"
9415   "#")
9416
9417 (define_split
9418   [(set (match_operand:SF 0 "register_operand" "")
9419         (neg:SF (match_operand:SF 1 "register_operand" "")))
9420    (clobber (reg:CC 17))]
9421   "TARGET_80387 && FP_REGNO_P (REGNO (operands[0])) && reload_completed"
9422   [(set (match_dup 0)
9423         (neg:SF (match_dup 1)))]
9424   "")
9425
9426 (define_split
9427   [(set (match_operand:SF 0 "register_operand" "")
9428         (neg:SF (match_operand:SF 1 "register_operand" "")))
9429    (clobber (reg:CC 17))]
9430   "TARGET_80387 && reload_completed && !FP_REGNO_P (REGNO (operands[0]))"
9431   [(parallel [(set (match_dup 0) (xor:SI (match_dup 0) (match_dup 1)))
9432               (clobber (reg:CC 17))])]
9433   "operands[1] = GEN_INT (trunc_int_for_mode (0x80000000, SImode));
9434    operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));")
9435
9436 (define_split
9437   [(set (match_operand 0 "memory_operand" "")
9438         (neg (match_operand 1 "memory_operand" "")))
9439    (clobber (reg:CC 17))]
9440   "TARGET_80387 && reload_completed && FLOAT_MODE_P (GET_MODE (operands[0]))"
9441   [(parallel [(set (match_dup 0) (xor:QI (match_dup 0) (match_dup 1)))
9442               (clobber (reg:CC 17))])]
9443 {
9444   int size = GET_MODE_SIZE (GET_MODE (operands[1]));
9445
9446   /* XFmode's size is 12, TFmode 16, but only 10 bytes are used.  */
9447   if (size >= 12)
9448     size = 10;
9449   operands[0] = adjust_address (operands[0], QImode, size - 1);
9450   operands[1] = GEN_INT (trunc_int_for_mode (0x80, QImode));
9451 })
9452
9453 (define_expand "negdf2"
9454   [(parallel [(set (match_operand:DF 0 "nonimmediate_operand" "")
9455                    (neg:DF (match_operand:DF 1 "nonimmediate_operand" "")))
9456               (clobber (reg:CC 17))])]
9457   "TARGET_80387"
9458   "if (TARGET_SSE2)
9459      {
9460        /* In case operand is in memory,  we will not use SSE.  */
9461        if (memory_operand (operands[0], VOIDmode)
9462            && rtx_equal_p (operands[0], operands[1]))
9463          emit_insn (gen_negdf2_memory (operands[0], operands[1]));
9464        else
9465         {
9466           /* Using SSE is tricky, since we need bitwise negation of -0
9467              in register.  */
9468           rtx reg = gen_reg_rtx (DFmode);
9469 #if HOST_BITS_PER_WIDE_INT >= 64
9470           rtx imm = GEN_INT (trunc_int_for_mode(((HOST_WIDE_INT)1) << 63,
9471                                                 DImode));
9472 #else
9473           rtx imm = immed_double_const (0, 0x80000000, DImode);
9474 #endif
9475           rtx dest = operands[0];
9476
9477           operands[1] = force_reg (DFmode, operands[1]);
9478           operands[0] = force_reg (DFmode, operands[0]);
9479           emit_move_insn (reg, gen_lowpart (DFmode, imm));
9480           emit_insn (gen_negdf2_ifs (operands[0], operands[1], reg));
9481           if (dest != operands[0])
9482             emit_move_insn (dest, operands[0]);
9483         }
9484        DONE;
9485      }
9486    ix86_expand_unary_operator (NEG, DFmode, operands); DONE;")
9487
9488 (define_insn "negdf2_memory"
9489   [(set (match_operand:DF 0 "memory_operand" "=m")
9490         (neg:DF (match_operand:DF 1 "memory_operand" "0")))
9491    (clobber (reg:CC 17))]
9492   "ix86_unary_operator_ok (NEG, DFmode, operands)"
9493   "#")
9494
9495 (define_insn "negdf2_ifs"
9496   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y#fr,Y#fr,f#Yr,rm#Yf")
9497         (neg:DF (match_operand:DF 1 "nonimmediate_operand" "0,Y#fr,0,0")))
9498    (use (match_operand:DF 2 "nonmemory_operand" "Y,0,*g#Y,*g#Y"))
9499    (clobber (reg:CC 17))]
9500   "TARGET_SSE2 && !TARGET_64BIT
9501    && (reload_in_progress || reload_completed
9502        || (register_operand (operands[0], VOIDmode)
9503            && register_operand (operands[1], VOIDmode)))"
9504   "#")
9505
9506 (define_insn "*negdf2_ifs_rex64"
9507   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y#fr,Y#fr,fm#Yr,r#Yf")
9508         (neg:DF (match_operand:DF 1 "nonimmediate_operand" "0,Y#fr,0,0")))
9509    (use (match_operand:DF 2 "general_operand" "Y,0,*g#Yr,*rm"))
9510    (clobber (reg:CC 17))]
9511   "TARGET_SSE2 && TARGET_64BIT
9512    && (reload_in_progress || reload_completed
9513        || (register_operand (operands[0], VOIDmode)
9514            && register_operand (operands[1], VOIDmode)))"
9515   "#")
9516
9517 (define_split
9518   [(set (match_operand:DF 0 "memory_operand" "")
9519         (neg:DF (match_operand:DF 1 "memory_operand" "")))
9520    (use (match_operand:DF 2 "" ""))
9521    (clobber (reg:CC 17))]
9522   ""
9523   [(parallel [(set (match_dup 0)
9524                    (neg:DF (match_dup 1)))
9525               (clobber (reg:CC 17))])])
9526
9527 (define_split
9528   [(set (match_operand:DF 0 "register_operand" "")
9529         (neg:DF (match_operand:DF 1 "register_operand" "")))
9530    (use (match_operand:DF 2 "" ""))
9531    (clobber (reg:CC 17))]
9532   "reload_completed && !SSE_REG_P (operands[0])
9533    && (!TARGET_64BIT || FP_REG_P (operands[0]))"
9534   [(parallel [(set (match_dup 0)
9535                    (neg:DF (match_dup 1)))
9536               (clobber (reg:CC 17))])])
9537
9538 (define_split
9539   [(set (match_operand:DF 0 "register_operand" "")
9540         (neg:DF (match_operand:DF 1 "register_operand" "")))
9541    (use (match_operand:DF 2 "" ""))
9542    (clobber (reg:CC 17))]
9543   "reload_completed && GENERAL_REG_P (operands[0]) && TARGET_64BIT"
9544   [(parallel [(set (match_dup 0)
9545                    (xor:DI (match_dup 1) (match_dup 2)))
9546               (clobber (reg:CC 17))])]
9547    "operands[0] = gen_lowpart (DImode, operands[0]);
9548     operands[1] = gen_lowpart (DImode, operands[1]);
9549     operands[2] = gen_lowpart (DImode, operands[2]);")
9550
9551 (define_split
9552   [(set (match_operand:DF 0 "register_operand" "")
9553         (neg:DF (match_operand:DF 1 "register_operand" "")))
9554    (use (match_operand:DF 2 "register_operand" ""))
9555    (clobber (reg:CC 17))]
9556   "reload_completed && SSE_REG_P (operands[0])"
9557   [(set (subreg:TI (match_dup 0) 0)
9558         (xor:TI (subreg:TI (match_dup 1) 0)
9559                 (subreg:TI (match_dup 2) 0)))]
9560 {
9561   if (operands_match_p (operands[0], operands[2]))
9562     {
9563       rtx tmp;
9564       tmp = operands[1];
9565       operands[1] = operands[2];
9566       operands[2] = tmp;
9567     }
9568 })
9569
9570 ;; Keep 'f' and 'r' in separate alternatives to avoid reload problems
9571 ;; because of secondary memory needed to reload from class FLOAT_INT_REGS
9572 ;; to itself.
9573 (define_insn "*negdf2_if"
9574   [(set (match_operand:DF 0 "nonimmediate_operand" "=f#r,rm#f")
9575         (neg:DF (match_operand:DF 1 "nonimmediate_operand" "0,0")))
9576    (clobber (reg:CC 17))]
9577   "TARGET_80387 && !TARGET_64BIT
9578    && ix86_unary_operator_ok (NEG, DFmode, operands)"
9579   "#")
9580
9581 ;; FIXME: We should to allow integer registers here.  Problem is that
9582 ;; we need another scratch register to get constant from.
9583 ;; Forcing constant to mem if no register available in peep2 should be
9584 ;; safe even for PIC mode, because of RIP relative addressing.
9585 (define_insn "*negdf2_if_rex64"
9586   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,mf")
9587         (neg:DF (match_operand:DF 1 "nonimmediate_operand" "0,0")))
9588    (clobber (reg:CC 17))]
9589   "TARGET_80387 && TARGET_64BIT
9590    && ix86_unary_operator_ok (NEG, DFmode, operands)"
9591   "#")
9592
9593 (define_split
9594   [(set (match_operand:DF 0 "register_operand" "")
9595         (neg:DF (match_operand:DF 1 "register_operand" "")))
9596    (clobber (reg:CC 17))]
9597   "TARGET_80387 && FP_REGNO_P (REGNO (operands[0])) && reload_completed"
9598   [(set (match_dup 0)
9599         (neg:DF (match_dup 1)))]
9600   "")
9601
9602 (define_split
9603   [(set (match_operand:DF 0 "register_operand" "")
9604         (neg:DF (match_operand:DF 1 "register_operand" "")))
9605    (clobber (reg:CC 17))]
9606   "TARGET_80387 && reload_completed && !FP_REGNO_P (REGNO (operands[0]))
9607    && !TARGET_64BIT"
9608   [(parallel [(set (match_dup 3) (xor:SI (match_dup 3) (match_dup 4)))
9609               (clobber (reg:CC 17))])]
9610   "operands[4] = GEN_INT (trunc_int_for_mode (0x80000000, SImode));
9611    split_di (operands+0, 1, operands+2, operands+3);")
9612
9613 (define_expand "negxf2"
9614   [(parallel [(set (match_operand:XF 0 "nonimmediate_operand" "")
9615                    (neg:XF (match_operand:XF 1 "nonimmediate_operand" "")))
9616               (clobber (reg:CC 17))])]
9617   "TARGET_80387 && !TARGET_64BIT"
9618   "ix86_expand_unary_operator (NEG, XFmode, operands); DONE;")
9619
9620 (define_expand "negtf2"
9621   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
9622                    (neg:TF (match_operand:TF 1 "nonimmediate_operand" "")))
9623               (clobber (reg:CC 17))])]
9624   "TARGET_80387"
9625   "ix86_expand_unary_operator (NEG, TFmode, operands); DONE;")
9626
9627 ;; Keep 'f' and 'r' in separate alternatives to avoid reload problems
9628 ;; because of secondary memory needed to reload from class FLOAT_INT_REGS
9629 ;; to itself.
9630 (define_insn "*negxf2_if"
9631   [(set (match_operand:XF 0 "nonimmediate_operand" "=f#r,rm#f")
9632         (neg:XF (match_operand:XF 1 "nonimmediate_operand" "0,0")))
9633    (clobber (reg:CC 17))]
9634   "TARGET_80387 && !TARGET_64BIT
9635    && ix86_unary_operator_ok (NEG, XFmode, operands)"
9636   "#")
9637
9638 (define_split
9639   [(set (match_operand:XF 0 "register_operand" "")
9640         (neg:XF (match_operand:XF 1 "register_operand" "")))
9641    (clobber (reg:CC 17))]
9642   "TARGET_80387 && FP_REGNO_P (REGNO (operands[0])) && reload_completed"
9643   [(set (match_dup 0)
9644         (neg:XF (match_dup 1)))]
9645   "")
9646
9647 (define_split
9648   [(set (match_operand:XF 0 "register_operand" "")
9649         (neg:XF (match_operand:XF 1 "register_operand" "")))
9650    (clobber (reg:CC 17))]
9651   "TARGET_80387 && reload_completed && !FP_REGNO_P (REGNO (operands[0]))"
9652   [(parallel [(set (match_dup 0) (xor:SI (match_dup 0) (match_dup 1)))
9653               (clobber (reg:CC 17))])]
9654   "operands[1] = GEN_INT (0x8000);
9655    operands[0] = gen_rtx_REG (SImode,
9656                               true_regnum (operands[0]) + (TARGET_64BIT ? 1 : 2));")
9657
9658 ;; Keep 'f' and 'r' in separate alternatives to avoid reload problems
9659 ;; because of secondary memory needed to reload from class FLOAT_INT_REGS
9660 ;; to itself.
9661 (define_insn "*negtf2_if"
9662   [(set (match_operand:TF 0 "nonimmediate_operand" "=f#r,rm#f")
9663         (neg:TF (match_operand:TF 1 "nonimmediate_operand" "0,0")))
9664    (clobber (reg:CC 17))]
9665   "TARGET_80387 && ix86_unary_operator_ok (NEG, TFmode, operands)"
9666   "#")
9667
9668 (define_split
9669   [(set (match_operand:TF 0 "register_operand" "")
9670         (neg:TF (match_operand:TF 1 "register_operand" "")))
9671    (clobber (reg:CC 17))]
9672   "TARGET_80387 && FP_REGNO_P (REGNO (operands[0])) && reload_completed"
9673   [(set (match_dup 0)
9674         (neg:TF (match_dup 1)))]
9675   "")
9676
9677 (define_split
9678   [(set (match_operand:TF 0 "register_operand" "")
9679         (neg:TF (match_operand:TF 1 "register_operand" "")))
9680    (clobber (reg:CC 17))]
9681   "TARGET_80387 && reload_completed && !FP_REGNO_P (REGNO (operands[0]))"
9682   [(parallel [(set (match_dup 0) (xor:SI (match_dup 0) (match_dup 1)))
9683               (clobber (reg:CC 17))])]
9684   "operands[1] = GEN_INT (0x8000);
9685    operands[0] = gen_rtx_REG (SImode,
9686                               true_regnum (operands[0]) + (TARGET_64BIT ? 1 : 2));")
9687
9688 ;; Conditionize these after reload. If they matches before reload, we 
9689 ;; lose the clobber and ability to use integer instructions.
9690
9691 (define_insn "*negsf2_1"
9692   [(set (match_operand:SF 0 "register_operand" "=f")
9693         (neg:SF (match_operand:SF 1 "register_operand" "0")))]
9694   "TARGET_80387 && reload_completed"
9695   "fchs"
9696   [(set_attr "type" "fsgn")
9697    (set_attr "mode" "SF")
9698    (set_attr "ppro_uops" "few")])
9699
9700 (define_insn "*negdf2_1"
9701   [(set (match_operand:DF 0 "register_operand" "=f")
9702         (neg:DF (match_operand:DF 1 "register_operand" "0")))]
9703   "TARGET_80387 && reload_completed"
9704   "fchs"
9705   [(set_attr "type" "fsgn")
9706    (set_attr "mode" "DF")
9707    (set_attr "ppro_uops" "few")])
9708
9709 (define_insn "*negextendsfdf2"
9710   [(set (match_operand:DF 0 "register_operand" "=f")
9711         (neg:DF (float_extend:DF
9712                   (match_operand:SF 1 "register_operand" "0"))))]
9713   "TARGET_80387"
9714   "fchs"
9715   [(set_attr "type" "fsgn")
9716    (set_attr "mode" "DF")
9717    (set_attr "ppro_uops" "few")])
9718
9719 (define_insn "*negxf2_1"
9720   [(set (match_operand:XF 0 "register_operand" "=f")
9721         (neg:XF (match_operand:XF 1 "register_operand" "0")))]
9722   "TARGET_80387 && !TARGET_64BIT && reload_completed"
9723   "fchs"
9724   [(set_attr "type" "fsgn")
9725    (set_attr "mode" "XF")
9726    (set_attr "ppro_uops" "few")])
9727
9728 (define_insn "*negextenddfxf2"
9729   [(set (match_operand:XF 0 "register_operand" "=f")
9730         (neg:XF (float_extend:XF
9731                   (match_operand:DF 1 "register_operand" "0"))))]
9732   "TARGET_80387 && !TARGET_64BIT"
9733   "fchs"
9734   [(set_attr "type" "fsgn")
9735    (set_attr "mode" "XF")
9736    (set_attr "ppro_uops" "few")])
9737
9738 (define_insn "*negextendsfxf2"
9739   [(set (match_operand:XF 0 "register_operand" "=f")
9740         (neg:XF (float_extend:XF
9741                   (match_operand:SF 1 "register_operand" "0"))))]
9742   "TARGET_80387 && !TARGET_64BIT"
9743   "fchs"
9744   [(set_attr "type" "fsgn")
9745    (set_attr "mode" "XF")
9746    (set_attr "ppro_uops" "few")])
9747
9748 (define_insn "*negtf2_1"
9749   [(set (match_operand:TF 0 "register_operand" "=f")
9750         (neg:TF (match_operand:TF 1 "register_operand" "0")))]
9751   "TARGET_80387 && reload_completed"
9752   "fchs"
9753   [(set_attr "type" "fsgn")
9754    (set_attr "mode" "XF")
9755    (set_attr "ppro_uops" "few")])
9756
9757 (define_insn "*negextenddftf2"
9758   [(set (match_operand:TF 0 "register_operand" "=f")
9759         (neg:TF (float_extend:TF
9760                   (match_operand:DF 1 "register_operand" "0"))))]
9761   "TARGET_80387"
9762   "fchs"
9763   [(set_attr "type" "fsgn")
9764    (set_attr "mode" "XF")
9765    (set_attr "ppro_uops" "few")])
9766
9767 (define_insn "*negextendsftf2"
9768   [(set (match_operand:TF 0 "register_operand" "=f")
9769         (neg:TF (float_extend:TF
9770                   (match_operand:SF 1 "register_operand" "0"))))]
9771   "TARGET_80387"
9772   "fchs"
9773   [(set_attr "type" "fsgn")
9774    (set_attr "mode" "XF")
9775    (set_attr "ppro_uops" "few")])
9776 \f
9777 ;; Absolute value instructions
9778
9779 (define_expand "abssf2"
9780   [(parallel [(set (match_operand:SF 0 "nonimmediate_operand" "")
9781                    (neg:SF (match_operand:SF 1 "nonimmediate_operand" "")))
9782               (clobber (reg:CC 17))])]
9783   "TARGET_80387"
9784   "if (TARGET_SSE)
9785      {
9786        /* In case operand is in memory,  we will not use SSE.  */
9787        if (memory_operand (operands[0], VOIDmode)
9788            && rtx_equal_p (operands[0], operands[1]))
9789          emit_insn (gen_abssf2_memory (operands[0], operands[1]));
9790        else
9791         {
9792           /* Using SSE is tricky, since we need bitwise negation of -0
9793              in register.  */
9794           rtx reg = gen_reg_rtx (SFmode);
9795           rtx dest = operands[0];
9796
9797           operands[1] = force_reg (SFmode, operands[1]);
9798           operands[0] = force_reg (SFmode, operands[0]);
9799           emit_move_insn (reg,
9800                           gen_lowpart (SFmode,
9801                                        GEN_INT (trunc_int_for_mode (0x80000000,
9802                                                                     SImode))));
9803           emit_insn (gen_abssf2_ifs (operands[0], operands[1], reg));
9804           if (dest != operands[0])
9805             emit_move_insn (dest, operands[0]);
9806         }
9807        DONE;
9808      }
9809    ix86_expand_unary_operator (ABS, SFmode, operands); DONE;")
9810
9811 (define_insn "abssf2_memory"
9812   [(set (match_operand:SF 0 "memory_operand" "=m")
9813         (abs:SF (match_operand:SF 1 "memory_operand" "0")))
9814    (clobber (reg:CC 17))]
9815   "ix86_unary_operator_ok (ABS, SFmode, operands)"
9816   "#")
9817
9818 (define_insn "abssf2_ifs"
9819   [(set (match_operand:SF 0 "nonimmediate_operand" "=x#fr,f#xr,rm#xf")
9820         (abs:SF (match_operand:SF 1 "nonimmediate_operand" "x,0,0")))
9821    (use (match_operand:SF 2 "nonmemory_operand" "*0#x,*g#x,*g#x"))
9822    (clobber (reg:CC 17))]
9823   "TARGET_SSE
9824    && (reload_in_progress || reload_completed
9825        || (register_operand (operands[0], VOIDmode)
9826            && register_operand (operands[1], VOIDmode)))"
9827   "#")
9828
9829 (define_split
9830   [(set (match_operand:SF 0 "memory_operand" "")
9831         (abs:SF (match_operand:SF 1 "memory_operand" "")))
9832    (use (match_operand:SF 2 "" ""))
9833    (clobber (reg:CC 17))]
9834   ""
9835   [(parallel [(set (match_dup 0)
9836                    (abs:SF (match_dup 1)))
9837               (clobber (reg:CC 17))])])
9838
9839 (define_split
9840   [(set (match_operand:SF 0 "register_operand" "")
9841         (abs:SF (match_operand:SF 1 "register_operand" "")))
9842    (use (match_operand:SF 2 "" ""))
9843    (clobber (reg:CC 17))]
9844   "reload_completed && !SSE_REG_P (operands[0])"
9845   [(parallel [(set (match_dup 0)
9846                    (abs:SF (match_dup 1)))
9847               (clobber (reg:CC 17))])])
9848
9849 (define_split
9850   [(set (match_operand:SF 0 "register_operand" "")
9851         (abs:SF (match_operand:SF 1 "register_operand" "")))
9852    (use (match_operand:SF 2 "register_operand" ""))
9853    (clobber (reg:CC 17))]
9854   "reload_completed && SSE_REG_P (operands[0])"
9855   [(set (subreg:TI (match_dup 0) 0)
9856         (and:TI (not:TI (subreg:TI (match_dup 2) 0))
9857                 (subreg:TI (match_dup 1) 0)))])
9858
9859 ;; Keep 'f' and 'r' in separate alternatives to avoid reload problems
9860 ;; because of secondary memory needed to reload from class FLOAT_INT_REGS
9861 ;; to itself.
9862 (define_insn "*abssf2_if"
9863   [(set (match_operand:SF 0 "nonimmediate_operand" "=f#r,rm#f")
9864         (abs:SF (match_operand:SF 1 "nonimmediate_operand" "0,0")))
9865    (clobber (reg:CC 17))]
9866   "TARGET_80387 && ix86_unary_operator_ok (ABS, SFmode, operands) && !TARGET_SSE"
9867   "#")
9868
9869 (define_split
9870   [(set (match_operand:SF 0 "register_operand" "")
9871         (abs:SF (match_operand:SF 1 "register_operand" "")))
9872    (clobber (reg:CC 17))]
9873   "TARGET_80387 && FP_REGNO_P (REGNO (operands[0]))"
9874   [(set (match_dup 0)
9875         (abs:SF (match_dup 1)))]
9876   "")
9877
9878 (define_split
9879   [(set (match_operand:SF 0 "register_operand" "")
9880         (abs:SF (match_operand:SF 1 "register_operand" "")))
9881    (clobber (reg:CC 17))]
9882   "TARGET_80387 && reload_completed && !FP_REGNO_P (REGNO (operands[0]))"
9883   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (match_dup 1)))
9884               (clobber (reg:CC 17))])]
9885   "operands[1] = GEN_INT (trunc_int_for_mode (~0x80000000, SImode));
9886    operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));")
9887
9888 (define_split
9889   [(set (match_operand 0 "memory_operand" "")
9890         (abs (match_operand 1 "memory_operand" "")))
9891    (clobber (reg:CC 17))]
9892   "TARGET_80387 && reload_completed && FLOAT_MODE_P (GET_MODE (operands[0]))"
9893   [(parallel [(set (match_dup 0) (and:QI (match_dup 0) (match_dup 1)))
9894               (clobber (reg:CC 17))])]
9895 {
9896   int size = GET_MODE_SIZE (GET_MODE (operands[1]));
9897
9898   /* XFmode's size is 12, TFmode 16, but only 10 bytes are used.  */
9899   if (size >= 12)
9900     size = 10;
9901   operands[0] = adjust_address (operands[0], QImode, size - 1);
9902   operands[1] = GEN_INT (trunc_int_for_mode (~0x80, QImode));
9903 })
9904
9905 (define_expand "absdf2"
9906   [(parallel [(set (match_operand:DF 0 "nonimmediate_operand" "")
9907                    (neg:DF (match_operand:DF 1 "nonimmediate_operand" "")))
9908               (clobber (reg:CC 17))])]
9909   "TARGET_80387"
9910   "if (TARGET_SSE2)
9911      {
9912        /* In case operand is in memory,  we will not use SSE.  */
9913        if (memory_operand (operands[0], VOIDmode)
9914            && rtx_equal_p (operands[0], operands[1]))
9915          emit_insn (gen_absdf2_memory (operands[0], operands[1]));
9916        else
9917         {
9918           /* Using SSE is tricky, since we need bitwise negation of -0
9919              in register.  */
9920           rtx reg = gen_reg_rtx (DFmode);
9921 #if HOST_BITS_PER_WIDE_INT >= 64
9922           rtx imm = GEN_INT (trunc_int_for_mode(((HOST_WIDE_INT)1) << 63,
9923                                                 DImode));
9924 #else
9925           rtx imm = immed_double_const (0, 0x80000000, DImode);
9926 #endif
9927           rtx dest = operands[0];
9928
9929           operands[1] = force_reg (DFmode, operands[1]);
9930           operands[0] = force_reg (DFmode, operands[0]);
9931           emit_move_insn (reg, gen_lowpart (DFmode, imm));
9932           emit_insn (gen_absdf2_ifs (operands[0], operands[1], reg));
9933           if (dest != operands[0])
9934             emit_move_insn (dest, operands[0]);
9935         }
9936        DONE;
9937      }
9938    ix86_expand_unary_operator (ABS, DFmode, operands); DONE;")
9939
9940 (define_insn "absdf2_memory"
9941   [(set (match_operand:DF 0 "memory_operand" "=m")
9942         (abs:DF (match_operand:DF 1 "memory_operand" "0")))
9943    (clobber (reg:CC 17))]
9944   "ix86_unary_operator_ok (ABS, DFmode, operands)"
9945   "#")
9946
9947 (define_insn "absdf2_ifs"
9948   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y#fr,mf#Yr,mr#Yf")
9949         (abs:DF (match_operand:DF 1 "nonimmediate_operand" "Y,0,0")))
9950    (use (match_operand:DF 2 "nonmemory_operand" "*0#Y,*g#Y,*g#Y"))
9951    (clobber (reg:CC 17))]
9952   "TARGET_SSE2 && !TARGET_64BIT
9953    && (reload_in_progress || reload_completed
9954        || (register_operand (operands[0], VOIDmode)
9955            && register_operand (operands[1], VOIDmode)))"
9956   "#")
9957
9958 (define_insn "*absdf2_ifs_rex64"
9959   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y#fr,mf#Yr")
9960         (abs:DF (match_operand:DF 1 "nonimmediate_operand" "Y,0")))
9961    (use (match_operand:DF 2 "nonmemory_operand" "*0#Y,*g#Y"))
9962    (clobber (reg:CC 17))]
9963   "TARGET_SSE2 && TARGET_64BIT
9964    && (reload_in_progress || reload_completed
9965        || (register_operand (operands[0], VOIDmode)
9966            && register_operand (operands[1], VOIDmode)))"
9967   "#")
9968
9969 (define_split
9970   [(set (match_operand:DF 0 "memory_operand" "")
9971         (abs:DF (match_operand:DF 1 "memory_operand" "")))
9972    (use (match_operand:DF 2 "" ""))
9973    (clobber (reg:CC 17))]
9974   ""
9975   [(parallel [(set (match_dup 0)
9976                    (abs:DF (match_dup 1)))
9977               (clobber (reg:CC 17))])])
9978
9979 (define_split
9980   [(set (match_operand:DF 0 "register_operand" "")
9981         (abs:DF (match_operand:DF 1 "register_operand" "")))
9982    (use (match_operand:DF 2 "" ""))
9983    (clobber (reg:CC 17))]
9984   "reload_completed && !SSE_REG_P (operands[0])"
9985   [(parallel [(set (match_dup 0)
9986                    (abs:DF (match_dup 1)))
9987               (clobber (reg:CC 17))])])
9988
9989 (define_split
9990   [(set (match_operand:DF 0 "register_operand" "")
9991         (abs:DF (match_operand:DF 1 "register_operand" "")))
9992    (use (match_operand:DF 2 "register_operand" ""))
9993    (clobber (reg:CC 17))]
9994   "reload_completed && SSE_REG_P (operands[0])"
9995   [(set (subreg:TI (match_dup 0) 0)
9996         (and:TI (not:TI (subreg:TI (match_dup 2) 0))
9997                 (subreg:TI (match_dup 1) 0)))])
9998
9999
10000 ;; Keep 'f' and 'r' in separate alternatives to avoid reload problems
10001 ;; because of secondary memory needed to reload from class FLOAT_INT_REGS
10002 ;; to itself.
10003 (define_insn "*absdf2_if"
10004   [(set (match_operand:DF 0 "nonimmediate_operand" "=f#r,rm#f")
10005         (abs:DF (match_operand:DF 1 "nonimmediate_operand" "0,0")))
10006    (clobber (reg:CC 17))]
10007   "TARGET_80387 && !TARGET_64BIT
10008    && ix86_unary_operator_ok (ABS, DFmode, operands)"
10009   "#")
10010
10011 ;; FIXME: We should to allow integer registers here.  Problem is that
10012 ;; we need another scratch register to get constant from.
10013 ;; Forcing constant to mem if no register available in peep2 should be
10014 ;; safe even for PIC mode, because of RIP relative addressing.
10015 (define_insn "*absdf2_if_rex64"
10016   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,mf")
10017         (abs:DF (match_operand:DF 1 "nonimmediate_operand" "0,0")))
10018    (clobber (reg:CC 17))]
10019   "TARGET_80387 && TARGET_64BIT
10020    && ix86_unary_operator_ok (ABS, DFmode, operands)"
10021   "#")
10022
10023 (define_split
10024   [(set (match_operand:DF 0 "register_operand" "")
10025         (abs:DF (match_operand:DF 1 "register_operand" "")))
10026    (clobber (reg:CC 17))]
10027   "TARGET_80387 && FP_REGNO_P (REGNO (operands[0])) && reload_completed"
10028   [(set (match_dup 0)
10029         (abs:DF (match_dup 1)))]
10030   "")
10031
10032 (define_split
10033   [(set (match_operand:DF 0 "register_operand" "")
10034         (abs:DF (match_operand:DF 1 "register_operand" "")))
10035    (clobber (reg:CC 17))]
10036   "TARGET_80387 && reload_completed && !FP_REGNO_P (REGNO (operands[0]))
10037    && !TARGET_64BIT"
10038   [(parallel [(set (match_dup 3) (and:SI (match_dup 3) (match_dup 4)))
10039               (clobber (reg:CC 17))])]
10040   "operands[4] = GEN_INT (trunc_int_for_mode (~0x80000000, SImode));
10041    split_di (operands+0, 1, operands+2, operands+3);")
10042
10043 (define_expand "absxf2"
10044   [(parallel [(set (match_operand:XF 0 "nonimmediate_operand" "")
10045                    (neg:XF (match_operand:XF 1 "nonimmediate_operand" "")))
10046               (clobber (reg:CC 17))])]
10047   "TARGET_80387 && !TARGET_64BIT"
10048   "ix86_expand_unary_operator (ABS, XFmode, operands); DONE;")
10049
10050 (define_expand "abstf2"
10051   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
10052                    (neg:TF (match_operand:TF 1 "nonimmediate_operand" "")))
10053               (clobber (reg:CC 17))])]
10054   "TARGET_80387"
10055   "ix86_expand_unary_operator (ABS, TFmode, operands); DONE;")
10056
10057 ;; Keep 'f' and 'r' in separate alternatives to avoid reload problems
10058 ;; because of secondary memory needed to reload from class FLOAT_INT_REGS
10059 ;; to itself.
10060 (define_insn "*absxf2_if"
10061   [(set (match_operand:XF 0 "nonimmediate_operand" "=f#r,rm#f")
10062         (abs:XF (match_operand:XF 1 "nonimmediate_operand" "0,0")))
10063    (clobber (reg:CC 17))]
10064   "TARGET_80387 && !TARGET_64BIT
10065    && ix86_unary_operator_ok (ABS, XFmode, operands)"
10066   "#")
10067
10068 (define_split
10069   [(set (match_operand:XF 0 "register_operand" "")
10070         (abs:XF (match_operand:XF 1 "register_operand" "")))
10071    (clobber (reg:CC 17))]
10072   "TARGET_80387 && FP_REGNO_P (REGNO (operands[0])) && reload_completed"
10073   [(set (match_dup 0)
10074         (abs:XF (match_dup 1)))]
10075   "")
10076
10077 (define_split
10078   [(set (match_operand:XF 0 "register_operand" "")
10079         (abs:XF (match_operand:XF 1 "register_operand" "")))
10080    (clobber (reg:CC 17))]
10081   "TARGET_80387 && reload_completed && !FP_REGNO_P (REGNO (operands[0]))"
10082   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (match_dup 1)))
10083               (clobber (reg:CC 17))])]
10084   "operands[1] = GEN_INT (~0x8000);
10085    operands[0] = gen_rtx_REG (SImode,
10086                               true_regnum (operands[0]) + (TARGET_64BIT ? 1 : 2));")
10087
10088 (define_insn "*abstf2_if"
10089   [(set (match_operand:TF 0 "nonimmediate_operand" "=f#r,rm#f")
10090         (abs:TF (match_operand:TF 1 "nonimmediate_operand" "0,0")))
10091    (clobber (reg:CC 17))]
10092   "TARGET_80387 && ix86_unary_operator_ok (ABS, TFmode, operands)"
10093   "#")
10094
10095 (define_split
10096   [(set (match_operand:TF 0 "register_operand" "")
10097         (abs:TF (match_operand:TF 1 "register_operand" "")))
10098    (clobber (reg:CC 17))]
10099   "TARGET_80387 && FP_REGNO_P (REGNO (operands[0])) && reload_completed"
10100   [(set (match_dup 0)
10101         (abs:TF (match_dup 1)))]
10102   "")
10103
10104 (define_split
10105   [(set (match_operand:TF 0 "register_operand" "")
10106         (abs:TF (match_operand:TF 1 "register_operand" "")))
10107    (clobber (reg:CC 17))]
10108   "TARGET_80387 && reload_completed && !FP_REGNO_P (REGNO (operands[0]))"
10109   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (match_dup 1)))
10110               (clobber (reg:CC 17))])]
10111   "operands[1] = GEN_INT (~0x8000);
10112    operands[0] = gen_rtx_REG (SImode,
10113                               true_regnum (operands[0]) + (TARGET_64BIT ? 1 : 2));")
10114
10115 (define_insn "*abssf2_1"
10116   [(set (match_operand:SF 0 "register_operand" "=f")
10117         (abs:SF (match_operand:SF 1 "register_operand" "0")))]
10118   "TARGET_80387 && reload_completed"
10119   "fabs"
10120   [(set_attr "type" "fsgn")
10121    (set_attr "mode" "SF")])
10122
10123 (define_insn "*absdf2_1"
10124   [(set (match_operand:DF 0 "register_operand" "=f")
10125         (abs:DF (match_operand:DF 1 "register_operand" "0")))]
10126   "TARGET_80387 && reload_completed"
10127   "fabs"
10128   [(set_attr "type" "fsgn")
10129    (set_attr "mode" "DF")])
10130
10131 (define_insn "*absextendsfdf2"
10132   [(set (match_operand:DF 0 "register_operand" "=f")
10133         (abs:DF (float_extend:DF
10134                   (match_operand:SF 1 "register_operand" "0"))))]
10135   "TARGET_80387"
10136   "fabs"
10137   [(set_attr "type" "fsgn")
10138    (set_attr "mode" "DF")])
10139
10140 (define_insn "*absxf2_1"
10141   [(set (match_operand:XF 0 "register_operand" "=f")
10142         (abs:XF (match_operand:XF 1 "register_operand" "0")))]
10143   "TARGET_80387 && !TARGET_64BIT && reload_completed"
10144   "fabs"
10145   [(set_attr "type" "fsgn")
10146    (set_attr "mode" "DF")])
10147
10148 (define_insn "*absextenddfxf2"
10149   [(set (match_operand:XF 0 "register_operand" "=f")
10150         (abs:XF (float_extend:XF
10151           (match_operand:DF 1 "register_operand" "0"))))]
10152   "TARGET_80387 && !TARGET_64BIT"
10153   "fabs"
10154   [(set_attr "type" "fsgn")
10155    (set_attr "mode" "XF")])
10156
10157 (define_insn "*absextendsfxf2"
10158   [(set (match_operand:XF 0 "register_operand" "=f")
10159         (abs:XF (float_extend:XF
10160           (match_operand:SF 1 "register_operand" "0"))))]
10161   "TARGET_80387 && !TARGET_64BIT"
10162   "fabs"
10163   [(set_attr "type" "fsgn")
10164    (set_attr "mode" "XF")])
10165
10166 (define_insn "*abstf2_1"
10167   [(set (match_operand:TF 0 "register_operand" "=f")
10168         (abs:TF (match_operand:TF 1 "register_operand" "0")))]
10169   "TARGET_80387 && reload_completed"
10170   "fabs"
10171   [(set_attr "type" "fsgn")
10172    (set_attr "mode" "DF")])
10173
10174 (define_insn "*absextenddftf2"
10175   [(set (match_operand:TF 0 "register_operand" "=f")
10176         (abs:TF (float_extend:TF
10177           (match_operand:DF 1 "register_operand" "0"))))]
10178   "TARGET_80387"
10179   "fabs"
10180   [(set_attr "type" "fsgn")
10181    (set_attr "mode" "XF")])
10182
10183 (define_insn "*absextendsftf2"
10184   [(set (match_operand:TF 0 "register_operand" "=f")
10185         (abs:TF (float_extend:TF
10186           (match_operand:SF 1 "register_operand" "0"))))]
10187   "TARGET_80387"
10188   "fabs"
10189   [(set_attr "type" "fsgn")
10190    (set_attr "mode" "XF")])
10191 \f
10192 ;; One complement instructions
10193
10194 (define_expand "one_cmpldi2"
10195   [(set (match_operand:DI 0 "nonimmediate_operand" "")
10196         (not:DI (match_operand:DI 1 "nonimmediate_operand" "")))]
10197   "TARGET_64BIT"
10198   "ix86_expand_unary_operator (NOT, DImode, operands); DONE;")
10199
10200 (define_insn "*one_cmpldi2_1_rex64"
10201   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
10202         (not:DI (match_operand:DI 1 "nonimmediate_operand" "0")))]
10203   "TARGET_64BIT && ix86_unary_operator_ok (NOT, DImode, operands)"
10204   "not{q}\t%0"
10205   [(set_attr "type" "negnot")
10206    (set_attr "mode" "DI")])
10207
10208 (define_insn "*one_cmpldi2_2_rex64"
10209   [(set (reg 17)
10210         (compare (not:DI (match_operand:DI 1 "nonimmediate_operand" "0"))
10211                  (const_int 0)))
10212    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
10213         (not:DI (match_dup 1)))]
10214   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
10215    && ix86_unary_operator_ok (NOT, DImode, operands)"
10216   "#"
10217   [(set_attr "type" "alu1")
10218    (set_attr "mode" "DI")])
10219
10220 (define_split
10221   [(set (reg 17)
10222         (compare (not:DI (match_operand:DI 1 "nonimmediate_operand" ""))
10223                  (const_int 0)))
10224    (set (match_operand:DI 0 "nonimmediate_operand" "")
10225         (not:DI (match_dup 1)))]
10226   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
10227   [(parallel [(set (reg:CCNO 17)
10228                    (compare:CCNO (xor:DI (match_dup 1) (const_int -1))
10229                                  (const_int 0)))
10230               (set (match_dup 0)
10231                    (xor:DI (match_dup 1) (const_int -1)))])]
10232   "")
10233
10234 (define_expand "one_cmplsi2"
10235   [(set (match_operand:SI 0 "nonimmediate_operand" "")
10236         (not:SI (match_operand:SI 1 "nonimmediate_operand" "")))]
10237   ""
10238   "ix86_expand_unary_operator (NOT, SImode, operands); DONE;")
10239
10240 (define_insn "*one_cmplsi2_1"
10241   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
10242         (not:SI (match_operand:SI 1 "nonimmediate_operand" "0")))]
10243   "ix86_unary_operator_ok (NOT, SImode, operands)"
10244   "not{l}\t%0"
10245   [(set_attr "type" "negnot")
10246    (set_attr "mode" "SI")])
10247
10248 ;; ??? Currently never generated - xor is used instead.
10249 (define_insn "*one_cmplsi2_1_zext"
10250   [(set (match_operand:DI 0 "register_operand" "=r")
10251         (zero_extend:DI (not:SI (match_operand:SI 1 "register_operand" "0"))))]
10252   "TARGET_64BIT && ix86_unary_operator_ok (NOT, SImode, operands)"
10253   "not{l}\t%k0"
10254   [(set_attr "type" "negnot")
10255    (set_attr "mode" "SI")])
10256
10257 (define_insn "*one_cmplsi2_2"
10258   [(set (reg 17)
10259         (compare (not:SI (match_operand:SI 1 "nonimmediate_operand" "0"))
10260                  (const_int 0)))
10261    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
10262         (not:SI (match_dup 1)))]
10263   "ix86_match_ccmode (insn, CCNOmode)
10264    && ix86_unary_operator_ok (NOT, SImode, operands)"
10265   "#"
10266   [(set_attr "type" "alu1")
10267    (set_attr "mode" "SI")])
10268
10269 (define_split
10270   [(set (reg 17)
10271         (compare (not:SI (match_operand:SI 1 "nonimmediate_operand" ""))
10272                  (const_int 0)))
10273    (set (match_operand:SI 0 "nonimmediate_operand" "")
10274         (not:SI (match_dup 1)))]
10275   "ix86_match_ccmode (insn, CCNOmode)"
10276   [(parallel [(set (reg:CCNO 17)
10277                    (compare:CCNO (xor:SI (match_dup 1) (const_int -1))
10278                                  (const_int 0)))
10279               (set (match_dup 0)
10280                    (xor:SI (match_dup 1) (const_int -1)))])]
10281   "")
10282
10283 ;; ??? Currently never generated - xor is used instead.
10284 (define_insn "*one_cmplsi2_2_zext"
10285   [(set (reg 17)
10286         (compare (not:SI (match_operand:SI 1 "register_operand" "0"))
10287                  (const_int 0)))
10288    (set (match_operand:DI 0 "register_operand" "=r")
10289         (zero_extend:DI (not:SI (match_dup 1))))]
10290   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
10291    && ix86_unary_operator_ok (NOT, SImode, operands)"
10292   "#"
10293   [(set_attr "type" "alu1")
10294    (set_attr "mode" "SI")])
10295
10296 (define_split
10297   [(set (reg 17)
10298         (compare (not:SI (match_operand:SI 1 "register_operand" ""))
10299                  (const_int 0)))
10300    (set (match_operand:DI 0 "register_operand" "")
10301         (zero_extend:DI (not:SI (match_dup 1))))]
10302   "ix86_match_ccmode (insn, CCNOmode)"
10303   [(parallel [(set (reg:CCNO 17)
10304                    (compare:CCNO (xor:SI (match_dup 1) (const_int -1))
10305                                  (const_int 0)))
10306               (set (match_dup 0)
10307                    (zero_extend:DI (xor:SI (match_dup 1) (const_int -1))))])]
10308   "")
10309
10310 (define_expand "one_cmplhi2"
10311   [(set (match_operand:HI 0 "nonimmediate_operand" "")
10312         (not:HI (match_operand:HI 1 "nonimmediate_operand" "")))]
10313   "TARGET_HIMODE_MATH"
10314   "ix86_expand_unary_operator (NOT, HImode, operands); DONE;")
10315
10316 (define_insn "*one_cmplhi2_1"
10317   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
10318         (not:HI (match_operand:HI 1 "nonimmediate_operand" "0")))]
10319   "ix86_unary_operator_ok (NOT, HImode, operands)"
10320   "not{w}\t%0"
10321   [(set_attr "type" "negnot")
10322    (set_attr "mode" "HI")])
10323
10324 (define_insn "*one_cmplhi2_2"
10325   [(set (reg 17)
10326         (compare (not:HI (match_operand:HI 1 "nonimmediate_operand" "0"))
10327                  (const_int 0)))
10328    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
10329         (not:HI (match_dup 1)))]
10330   "ix86_match_ccmode (insn, CCNOmode)
10331    && ix86_unary_operator_ok (NEG, HImode, operands)"
10332   "#"
10333   [(set_attr "type" "alu1")
10334    (set_attr "mode" "HI")])
10335
10336 (define_split
10337   [(set (reg 17)
10338         (compare (not:HI (match_operand:HI 1 "nonimmediate_operand" ""))
10339                  (const_int 0)))
10340    (set (match_operand:HI 0 "nonimmediate_operand" "")
10341         (not:HI (match_dup 1)))]
10342   "ix86_match_ccmode (insn, CCNOmode)"
10343   [(parallel [(set (reg:CCNO 17)
10344                    (compare:CCNO (xor:HI (match_dup 1) (const_int -1))
10345                                  (const_int 0)))
10346               (set (match_dup 0)
10347                    (xor:HI (match_dup 1) (const_int -1)))])]
10348   "")
10349
10350 ;; %%% Potential partial reg stall on alternative 1.  What to do?
10351 (define_expand "one_cmplqi2"
10352   [(set (match_operand:QI 0 "nonimmediate_operand" "")
10353         (not:QI (match_operand:QI 1 "nonimmediate_operand" "")))]
10354   "TARGET_QIMODE_MATH"
10355   "ix86_expand_unary_operator (NOT, QImode, operands); DONE;")
10356
10357 (define_insn "*one_cmplqi2_1"
10358   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r")
10359         (not:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")))]
10360   "ix86_unary_operator_ok (NOT, QImode, operands)"
10361   "@
10362    not{b}\t%0
10363    not{l}\t%k0"
10364   [(set_attr "type" "negnot")
10365    (set_attr "mode" "QI,SI")])
10366
10367 (define_insn "*one_cmplqi2_2"
10368   [(set (reg 17)
10369         (compare (not:QI (match_operand:QI 1 "nonimmediate_operand" "0"))
10370                  (const_int 0)))
10371    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
10372         (not:QI (match_dup 1)))]
10373   "ix86_match_ccmode (insn, CCNOmode)
10374    && ix86_unary_operator_ok (NOT, QImode, operands)"
10375   "#"
10376   [(set_attr "type" "alu1")
10377    (set_attr "mode" "QI")])
10378
10379 (define_split
10380   [(set (reg 17)
10381         (compare (not:QI (match_operand:QI 1 "nonimmediate_operand" ""))
10382                  (const_int 0)))
10383    (set (match_operand:QI 0 "nonimmediate_operand" "")
10384         (not:QI (match_dup 1)))]
10385   "ix86_match_ccmode (insn, CCNOmode)"
10386   [(parallel [(set (reg:CCNO 17)
10387                    (compare:CCNO (xor:QI (match_dup 1) (const_int -1))
10388                                  (const_int 0)))
10389               (set (match_dup 0)
10390                    (xor:QI (match_dup 1) (const_int -1)))])]
10391   "")
10392 \f
10393 ;; Arithmetic shift instructions
10394
10395 ;; DImode shifts are implemented using the i386 "shift double" opcode,
10396 ;; which is written as "sh[lr]d[lw] imm,reg,reg/mem".  If the shift count
10397 ;; is variable, then the count is in %cl and the "imm" operand is dropped
10398 ;; from the assembler input.
10399 ;;
10400 ;; This instruction shifts the target reg/mem as usual, but instead of
10401 ;; shifting in zeros, bits are shifted in from reg operand.  If the insn
10402 ;; is a left shift double, bits are taken from the high order bits of
10403 ;; reg, else if the insn is a shift right double, bits are taken from the
10404 ;; low order bits of reg.  So if %eax is "1234" and %edx is "5678",
10405 ;; "shldl $8,%edx,%eax" leaves %edx unchanged and sets %eax to "2345".
10406 ;;
10407 ;; Since sh[lr]d does not change the `reg' operand, that is done
10408 ;; separately, making all shifts emit pairs of shift double and normal
10409 ;; shift.  Since sh[lr]d does not shift more than 31 bits, and we wish to
10410 ;; support a 63 bit shift, each shift where the count is in a reg expands
10411 ;; to a pair of shifts, a branch, a shift by 32 and a label.
10412 ;;
10413 ;; If the shift count is a constant, we need never emit more than one
10414 ;; shift pair, instead using moves and sign extension for counts greater
10415 ;; than 31.
10416
10417 (define_expand "ashldi3"
10418   [(parallel [(set (match_operand:DI 0 "shiftdi_operand" "")
10419                    (ashift:DI (match_operand:DI 1 "shiftdi_operand" "")
10420                               (match_operand:QI 2 "nonmemory_operand" "")))
10421               (clobber (reg:CC 17))])]
10422   ""
10423 {
10424   if (!TARGET_64BIT && TARGET_CMOVE && ! immediate_operand (operands[2], QImode))
10425     {
10426       emit_insn (gen_ashldi3_1 (operands[0], operands[1], operands[2]));
10427       DONE;
10428     }
10429   ix86_expand_binary_operator (ASHIFT, DImode, operands);
10430   DONE;
10431 })
10432
10433 (define_insn "*ashldi3_1_rex64"
10434   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
10435         (ashift:DI (match_operand:DI 1 "nonimmediate_operand" "0,r")
10436                    (match_operand:QI 2 "nonmemory_operand" "cJ,M")))
10437    (clobber (reg:CC 17))]
10438   "TARGET_64BIT && ix86_binary_operator_ok (ASHIFT, DImode, operands)"
10439 {
10440   switch (get_attr_type (insn))
10441     {
10442     case TYPE_ALU:
10443       if (operands[2] != const1_rtx)
10444         abort ();
10445       if (!rtx_equal_p (operands[0], operands[1]))
10446         abort ();
10447       return "add{q}\t{%0, %0|%0, %0}";
10448
10449     case TYPE_LEA:
10450       if (GET_CODE (operands[2]) != CONST_INT
10451           || (unsigned HOST_WIDE_INT) INTVAL (operands[2]) > 3)
10452         abort ();
10453       operands[1] = gen_rtx_MULT (DImode, operands[1],
10454                                   GEN_INT (1 << INTVAL (operands[2])));
10455       return "lea{q}\t{%a1, %0|%0, %a1}";
10456
10457     default:
10458       if (REG_P (operands[2]))
10459         return "sal{q}\t{%b2, %0|%0, %b2}";
10460       else if (GET_CODE (operands[2]) == CONST_INT
10461                && INTVAL (operands[2]) == 1
10462                && (TARGET_PENTIUM || TARGET_PENTIUMPRO))
10463         return "sal{q}\t%0";
10464       else
10465         return "sal{q}\t{%2, %0|%0, %2}";
10466     }
10467 }
10468   [(set (attr "type")
10469      (cond [(eq_attr "alternative" "1")
10470               (const_string "lea")
10471             (and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
10472                           (const_int 0))
10473                       (match_operand 0 "register_operand" ""))
10474                  (match_operand 2 "const1_operand" ""))
10475               (const_string "alu")
10476            ]
10477            (const_string "ishift")))
10478    (set_attr "mode" "DI")])
10479
10480 ;; Convert lea to the lea pattern to avoid flags dependency.
10481 (define_split
10482   [(set (match_operand:DI 0 "register_operand" "")
10483         (ashift:DI (match_operand:DI 1 "register_operand" "")
10484                    (match_operand:QI 2 "immediate_operand" "")))
10485    (clobber (reg:CC 17))]
10486   "reload_completed
10487    && TARGET_64BIT
10488    && true_regnum (operands[0]) != true_regnum (operands[1])"
10489   [(set (match_dup 0)
10490         (mult:DI (match_dup 1)
10491                  (match_dup 2)))]
10492   "operands[2] = GEN_INT (trunc_int_for_mode (1 << INTVAL (operands[2]),
10493                                               DImode));")
10494
10495 ;; This pattern can't accept a variable shift count, since shifts by
10496 ;; zero don't affect the flags.  We assume that shifts by constant
10497 ;; zero are optimized away.
10498 (define_insn "*ashldi3_cmp_rex64"
10499   [(set (reg 17)
10500         (compare
10501           (ashift:DI (match_operand:DI 1 "nonimmediate_operand" "0")
10502                      (match_operand:QI 2 "immediate_operand" "e"))
10503           (const_int 0)))
10504    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
10505         (ashift:DI (match_dup 1) (match_dup 2)))]
10506   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
10507    && ix86_binary_operator_ok (ASHIFT, DImode, operands)"
10508 {
10509   switch (get_attr_type (insn))
10510     {
10511     case TYPE_ALU:
10512       if (operands[2] != const1_rtx)
10513         abort ();
10514       return "add{q}\t{%0, %0|%0, %0}";
10515
10516     default:
10517       if (REG_P (operands[2]))
10518         return "sal{q}\t{%b2, %0|%0, %b2}";
10519       else if (GET_CODE (operands[2]) == CONST_INT
10520                && INTVAL (operands[2]) == 1
10521                && (TARGET_PENTIUM || TARGET_PENTIUMPRO))
10522         return "sal{q}\t%0";
10523       else
10524         return "sal{q}\t{%2, %0|%0, %2}";
10525     }
10526 }
10527   [(set (attr "type")
10528      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
10529                           (const_int 0))
10530                       (match_operand 0 "register_operand" ""))
10531                  (match_operand 2 "const1_operand" ""))
10532               (const_string "alu")
10533            ]
10534            (const_string "ishift")))
10535    (set_attr "mode" "DI")])
10536
10537 (define_insn "ashldi3_1"
10538   [(set (match_operand:DI 0 "register_operand" "=r")
10539         (ashift:DI (match_operand:DI 1 "register_operand" "0")
10540                    (match_operand:QI 2 "nonmemory_operand" "Jc")))
10541    (clobber (match_scratch:SI 3 "=&r"))
10542    (clobber (reg:CC 17))]
10543   "!TARGET_64BIT && TARGET_CMOVE"
10544   "#"
10545   [(set_attr "type" "multi")])
10546
10547 (define_insn "*ashldi3_2"
10548   [(set (match_operand:DI 0 "register_operand" "=r")
10549         (ashift:DI (match_operand:DI 1 "register_operand" "0")
10550                    (match_operand:QI 2 "nonmemory_operand" "Jc")))
10551    (clobber (reg:CC 17))]
10552   "!TARGET_64BIT"
10553   "#"
10554   [(set_attr "type" "multi")])
10555
10556 (define_split
10557   [(set (match_operand:DI 0 "register_operand" "")
10558         (ashift:DI (match_operand:DI 1 "register_operand" "")
10559                    (match_operand:QI 2 "nonmemory_operand" "")))
10560    (clobber (match_scratch:SI 3 ""))
10561    (clobber (reg:CC 17))]
10562   "!TARGET_64BIT && TARGET_CMOVE && reload_completed"
10563   [(const_int 0)]
10564   "ix86_split_ashldi (operands, operands[3]); DONE;")
10565
10566 (define_split
10567   [(set (match_operand:DI 0 "register_operand" "")
10568         (ashift:DI (match_operand:DI 1 "register_operand" "")
10569                    (match_operand:QI 2 "nonmemory_operand" "")))
10570    (clobber (reg:CC 17))]
10571   "!TARGET_64BIT && reload_completed"
10572   [(const_int 0)]
10573   "ix86_split_ashldi (operands, NULL_RTX); DONE;")
10574
10575 (define_insn "x86_shld_1"
10576   [(set (match_operand:SI 0 "nonimmediate_operand" "+r*m,r*m")
10577         (ior:SI (ashift:SI (match_dup 0)
10578                   (match_operand:QI 2 "nonmemory_operand" "I,c"))
10579                 (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,r")
10580                   (minus:QI (const_int 32) (match_dup 2)))))
10581    (clobber (reg:CC 17))]
10582   ""
10583   "@
10584    shld{l}\t{%2, %1, %0|%0, %1, %2}
10585    shld{l}\t{%s2%1, %0|%0, %1, %2}"
10586   [(set_attr "type" "ishift")
10587    (set_attr "prefix_0f" "1")
10588    (set_attr "mode" "SI")
10589    (set_attr "pent_pair" "np")
10590    (set_attr "athlon_decode" "vector")
10591    (set_attr "ppro_uops" "few")])
10592
10593 (define_expand "x86_shift_adj_1"
10594   [(set (reg:CCZ 17)
10595         (compare:CCZ (and:QI (match_operand:QI 2 "register_operand" "")
10596                              (const_int 32))
10597                      (const_int 0)))
10598    (set (match_operand:SI 0 "register_operand" "")
10599         (if_then_else:SI (ne (reg:CCZ 17) (const_int 0))
10600                          (match_operand:SI 1 "register_operand" "")
10601                          (match_dup 0)))
10602    (set (match_dup 1)
10603         (if_then_else:SI (ne (reg:CCZ 17) (const_int 0))
10604                          (match_operand:SI 3 "register_operand" "r")
10605                          (match_dup 1)))]
10606   "TARGET_CMOVE"
10607   "")
10608
10609 (define_expand "x86_shift_adj_2"
10610   [(use (match_operand:SI 0 "register_operand" ""))
10611    (use (match_operand:SI 1 "register_operand" ""))
10612    (use (match_operand:QI 2 "register_operand" ""))]
10613   ""
10614 {
10615   rtx label = gen_label_rtx ();
10616   rtx tmp;
10617
10618   emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (32)));
10619
10620   tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
10621   tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
10622   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
10623                               gen_rtx_LABEL_REF (VOIDmode, label),
10624                               pc_rtx);
10625   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
10626   JUMP_LABEL (tmp) = label;
10627
10628   emit_move_insn (operands[0], operands[1]);
10629   emit_move_insn (operands[1], const0_rtx);
10630
10631   emit_label (label);
10632   LABEL_NUSES (label) = 1;
10633
10634   DONE;
10635 })
10636
10637 (define_expand "ashlsi3"
10638   [(set (match_operand:SI 0 "nonimmediate_operand" "")
10639         (ashift:SI (match_operand:SI 1 "nonimmediate_operand" "")
10640                    (match_operand:QI 2 "nonmemory_operand" "")))
10641    (clobber (reg:CC 17))]
10642   ""
10643   "ix86_expand_binary_operator (ASHIFT, SImode, operands); DONE;")
10644
10645 (define_insn "*ashlsi3_1"
10646   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
10647         (ashift:SI (match_operand:SI 1 "nonimmediate_operand" "0,r")
10648                    (match_operand:QI 2 "nonmemory_operand" "cI,M")))
10649    (clobber (reg:CC 17))]
10650   "ix86_binary_operator_ok (ASHIFT, SImode, operands)"
10651 {
10652   switch (get_attr_type (insn))
10653     {
10654     case TYPE_ALU:
10655       if (operands[2] != const1_rtx)
10656         abort ();
10657       if (!rtx_equal_p (operands[0], operands[1]))
10658         abort ();
10659       return "add{l}\t{%0, %0|%0, %0}";
10660
10661     case TYPE_LEA:
10662       return "#";
10663
10664     default:
10665       if (REG_P (operands[2]))
10666         return "sal{l}\t{%b2, %0|%0, %b2}";
10667       else if (GET_CODE (operands[2]) == CONST_INT
10668                && INTVAL (operands[2]) == 1
10669                && (TARGET_PENTIUM || TARGET_PENTIUMPRO))
10670         return "sal{l}\t%0";
10671       else
10672         return "sal{l}\t{%2, %0|%0, %2}";
10673     }
10674 }
10675   [(set (attr "type")
10676      (cond [(eq_attr "alternative" "1")
10677               (const_string "lea")
10678             (and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
10679                           (const_int 0))
10680                       (match_operand 0 "register_operand" ""))
10681                  (match_operand 2 "const1_operand" ""))
10682               (const_string "alu")
10683            ]
10684            (const_string "ishift")))
10685    (set_attr "mode" "SI")])
10686
10687 ;; Convert lea to the lea pattern to avoid flags dependency.
10688 (define_split
10689   [(set (match_operand 0 "register_operand" "")
10690         (ashift (match_operand 1 "register_operand" "")
10691                 (match_operand:QI 2 "const_int_operand" "")))
10692    (clobber (reg:CC 17))]
10693   "reload_completed
10694    && true_regnum (operands[0]) != true_regnum (operands[1])"
10695   [(const_int 0)]
10696 {
10697   rtx pat;
10698   operands[0] = gen_lowpart (SImode, operands[0]);
10699   operands[1] = gen_lowpart (Pmode, operands[1]);
10700   operands[2] = GEN_INT (trunc_int_for_mode (1 << INTVAL (operands[2]),
10701                                              Pmode));
10702   pat = gen_rtx_MULT (Pmode, operands[1], operands[2]);
10703   if (Pmode != SImode)
10704     pat = gen_rtx_SUBREG (SImode, pat, 0);
10705   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
10706   DONE;
10707 })
10708
10709 (define_insn "*ashlsi3_1_zext"
10710   [(set (match_operand:DI 0 "register_operand" "=r,r")
10711         (zero_extend:DI (ashift:SI (match_operand:SI 1 "register_operand" "0,r")
10712                         (match_operand:QI 2 "nonmemory_operand" "cI,M"))))
10713    (clobber (reg:CC 17))]
10714   "ix86_binary_operator_ok (ASHIFT, SImode, operands) && TARGET_64BIT"
10715 {
10716   switch (get_attr_type (insn))
10717     {
10718     case TYPE_ALU:
10719       if (operands[2] != const1_rtx)
10720         abort ();
10721       return "add{l}\t{%k0, %k0|%k0, %k0}";
10722
10723     case TYPE_LEA:
10724       return "#";
10725
10726     default:
10727       if (REG_P (operands[2]))
10728         return "sal{l}\t{%b2, %k0|%k0, %b2}";
10729       else if (GET_CODE (operands[2]) == CONST_INT
10730                && INTVAL (operands[2]) == 1
10731                && (TARGET_PENTIUM || TARGET_PENTIUMPRO))
10732         return "sal{l}\t%k0";
10733       else
10734         return "sal{l}\t{%2, %k0|%k0, %2}";
10735     }
10736 }
10737   [(set (attr "type")
10738      (cond [(eq_attr "alternative" "1")
10739               (const_string "lea")
10740             (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
10741                      (const_int 0))
10742                  (match_operand 2 "const1_operand" ""))
10743               (const_string "alu")
10744            ]
10745            (const_string "ishift")))
10746    (set_attr "mode" "SI")])
10747
10748 ;; Convert lea to the lea pattern to avoid flags dependency.
10749 (define_split
10750   [(set (match_operand:DI 0 "register_operand" "")
10751         (zero_extend:DI (ashift (match_operand 1 "register_operand" "")
10752                                 (match_operand:QI 2 "const_int_operand" ""))))
10753    (clobber (reg:CC 17))]
10754   "reload_completed
10755    && true_regnum (operands[0]) != true_regnum (operands[1])"
10756   [(set (match_dup 0) (zero_extend:DI (subreg:SI (mult:SI (match_dup 1) (match_dup 2)) 0)))]
10757 {
10758   operands[1] = gen_lowpart (Pmode, operands[1]);
10759   operands[2] = GEN_INT (trunc_int_for_mode (1 << INTVAL (operands[2]),
10760                                              Pmode));
10761 })
10762
10763 ;; This pattern can't accept a variable shift count, since shifts by
10764 ;; zero don't affect the flags.  We assume that shifts by constant
10765 ;; zero are optimized away.
10766 (define_insn "*ashlsi3_cmp"
10767   [(set (reg 17)
10768         (compare
10769           (ashift:SI (match_operand:SI 1 "nonimmediate_operand" "0")
10770                      (match_operand:QI 2 "immediate_operand" "I"))
10771           (const_int 0)))
10772    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
10773         (ashift:SI (match_dup 1) (match_dup 2)))]
10774   "ix86_match_ccmode (insn, CCGOCmode)
10775    && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
10776 {
10777   switch (get_attr_type (insn))
10778     {
10779     case TYPE_ALU:
10780       if (operands[2] != const1_rtx)
10781         abort ();
10782       return "add{l}\t{%0, %0|%0, %0}";
10783
10784     default:
10785       if (REG_P (operands[2]))
10786         return "sal{l}\t{%b2, %0|%0, %b2}";
10787       else if (GET_CODE (operands[2]) == CONST_INT
10788                && INTVAL (operands[2]) == 1
10789                && (TARGET_PENTIUM || TARGET_PENTIUMPRO))
10790         return "sal{l}\t%0";
10791       else
10792         return "sal{l}\t{%2, %0|%0, %2}";
10793     }
10794 }
10795   [(set (attr "type")
10796      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
10797                           (const_int 0))
10798                       (match_operand 0 "register_operand" ""))
10799                  (match_operand 2 "const1_operand" ""))
10800               (const_string "alu")
10801            ]
10802            (const_string "ishift")))
10803    (set_attr "mode" "SI")])
10804
10805 (define_insn "*ashlsi3_cmp_zext"
10806   [(set (reg 17)
10807         (compare
10808           (ashift:SI (match_operand:SI 1 "register_operand" "0")
10809                      (match_operand:QI 2 "immediate_operand" "I"))
10810           (const_int 0)))
10811    (set (match_operand:DI 0 "register_operand" "=r")
10812         (zero_extend:DI (ashift:SI (match_dup 1) (match_dup 2))))]
10813   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
10814    && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
10815 {
10816   switch (get_attr_type (insn))
10817     {
10818     case TYPE_ALU:
10819       if (operands[2] != const1_rtx)
10820         abort ();
10821       return "add{l}\t{%k0, %k0|%k0, %k0}";
10822
10823     default:
10824       if (REG_P (operands[2]))
10825         return "sal{l}\t{%b2, %k0|%k0, %b2}";
10826       else if (GET_CODE (operands[2]) == CONST_INT
10827                && INTVAL (operands[2]) == 1
10828                && (TARGET_PENTIUM || TARGET_PENTIUMPRO))
10829         return "sal{l}\t%k0";
10830       else
10831         return "sal{l}\t{%2, %k0|%k0, %2}";
10832     }
10833 }
10834   [(set (attr "type")
10835      (cond [(and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
10836                      (const_int 0))
10837                  (match_operand 2 "const1_operand" ""))
10838               (const_string "alu")
10839            ]
10840            (const_string "ishift")))
10841    (set_attr "mode" "SI")])
10842
10843 (define_expand "ashlhi3"
10844   [(set (match_operand:HI 0 "nonimmediate_operand" "")
10845         (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "")
10846                    (match_operand:QI 2 "nonmemory_operand" "")))
10847    (clobber (reg:CC 17))]
10848   "TARGET_HIMODE_MATH"
10849   "ix86_expand_binary_operator (ASHIFT, HImode, operands); DONE;")
10850
10851 (define_insn "*ashlhi3_1_lea"
10852   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r")
10853         (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0,r")
10854                    (match_operand:QI 2 "nonmemory_operand" "cI,M")))
10855    (clobber (reg:CC 17))]
10856   "!TARGET_PARTIAL_REG_STALL
10857    && ix86_binary_operator_ok (ASHIFT, HImode, operands)"
10858 {
10859   switch (get_attr_type (insn))
10860     {
10861     case TYPE_LEA:
10862       return "#";
10863     case TYPE_ALU:
10864       if (operands[2] != const1_rtx)
10865         abort ();
10866       return "add{w}\t{%0, %0|%0, %0}";
10867
10868     default:
10869       if (REG_P (operands[2]))
10870         return "sal{w}\t{%b2, %0|%0, %b2}";
10871       else if (GET_CODE (operands[2]) == CONST_INT
10872                && INTVAL (operands[2]) == 1
10873                && (TARGET_PENTIUM || TARGET_PENTIUMPRO))
10874         return "sal{w}\t%0";
10875       else
10876         return "sal{w}\t{%2, %0|%0, %2}";
10877     }
10878 }
10879   [(set (attr "type")
10880      (cond [(eq_attr "alternative" "1")
10881               (const_string "lea")
10882             (and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
10883                           (const_int 0))
10884                       (match_operand 0 "register_operand" ""))
10885                  (match_operand 2 "const1_operand" ""))
10886               (const_string "alu")
10887            ]
10888            (const_string "ishift")))
10889    (set_attr "mode" "HI,SI")])
10890
10891 (define_insn "*ashlhi3_1"
10892   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
10893         (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0")
10894                    (match_operand:QI 2 "nonmemory_operand" "cI")))
10895    (clobber (reg:CC 17))]
10896   "TARGET_PARTIAL_REG_STALL
10897    && ix86_binary_operator_ok (ASHIFT, HImode, operands)"
10898 {
10899   switch (get_attr_type (insn))
10900     {
10901     case TYPE_ALU:
10902       if (operands[2] != const1_rtx)
10903         abort ();
10904       return "add{w}\t{%0, %0|%0, %0}";
10905
10906     default:
10907       if (REG_P (operands[2]))
10908         return "sal{w}\t{%b2, %0|%0, %b2}";
10909       else if (GET_CODE (operands[2]) == CONST_INT
10910                && INTVAL (operands[2]) == 1
10911                && (TARGET_PENTIUM || TARGET_PENTIUMPRO))
10912         return "sal{w}\t%0";
10913       else
10914         return "sal{w}\t{%2, %0|%0, %2}";
10915     }
10916 }
10917   [(set (attr "type")
10918      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
10919                           (const_int 0))
10920                       (match_operand 0 "register_operand" ""))
10921                  (match_operand 2 "const1_operand" ""))
10922               (const_string "alu")
10923            ]
10924            (const_string "ishift")))
10925    (set_attr "mode" "HI")])
10926
10927 ;; This pattern can't accept a variable shift count, since shifts by
10928 ;; zero don't affect the flags.  We assume that shifts by constant
10929 ;; zero are optimized away.
10930 (define_insn "*ashlhi3_cmp"
10931   [(set (reg 17)
10932         (compare
10933           (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0")
10934                      (match_operand:QI 2 "immediate_operand" "I"))
10935           (const_int 0)))
10936    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
10937         (ashift:HI (match_dup 1) (match_dup 2)))]
10938   "ix86_match_ccmode (insn, CCGOCmode)
10939    && ix86_binary_operator_ok (ASHIFT, HImode, operands)"
10940 {
10941   switch (get_attr_type (insn))
10942     {
10943     case TYPE_ALU:
10944       if (operands[2] != const1_rtx)
10945         abort ();
10946       return "add{w}\t{%0, %0|%0, %0}";
10947
10948     default:
10949       if (REG_P (operands[2]))
10950         return "sal{w}\t{%b2, %0|%0, %b2}";
10951       else if (GET_CODE (operands[2]) == CONST_INT
10952                && INTVAL (operands[2]) == 1
10953                && (TARGET_PENTIUM || TARGET_PENTIUMPRO))
10954         return "sal{w}\t%0";
10955       else
10956         return "sal{w}\t{%2, %0|%0, %2}";
10957     }
10958 }
10959   [(set (attr "type")
10960      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
10961                           (const_int 0))
10962                       (match_operand 0 "register_operand" ""))
10963                  (match_operand 2 "const1_operand" ""))
10964               (const_string "alu")
10965            ]
10966            (const_string "ishift")))
10967    (set_attr "mode" "HI")])
10968
10969 (define_expand "ashlqi3"
10970   [(set (match_operand:QI 0 "nonimmediate_operand" "")
10971         (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "")
10972                    (match_operand:QI 2 "nonmemory_operand" "")))
10973    (clobber (reg:CC 17))]
10974   "TARGET_QIMODE_MATH"
10975   "ix86_expand_binary_operator (ASHIFT, QImode, operands); DONE;")
10976
10977 ;; %%% Potential partial reg stall on alternative 2.  What to do?
10978
10979 (define_insn "*ashlqi3_1_lea"
10980   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r,r")
10981         (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0,0,r")
10982                    (match_operand:QI 2 "nonmemory_operand" "cI,cI,M")))
10983    (clobber (reg:CC 17))]
10984   "!TARGET_PARTIAL_REG_STALL
10985    && ix86_binary_operator_ok (ASHIFT, QImode, operands)"
10986 {
10987   switch (get_attr_type (insn))
10988     {
10989     case TYPE_LEA:
10990       return "#";
10991     case TYPE_ALU:
10992       if (operands[2] != const1_rtx)
10993         abort ();
10994       if (REG_P (operands[1]) && !ANY_QI_REG_P (operands[1]))
10995         return "add{l}\t{%k0, %k0|%k0, %k0}";
10996       else
10997         return "add{b}\t{%0, %0|%0, %0}";
10998
10999     default:
11000       if (REG_P (operands[2]))
11001         {
11002           if (get_attr_mode (insn) == MODE_SI)
11003             return "sal{l}\t{%b2, %k0|%k0, %b2}";
11004           else
11005             return "sal{b}\t{%b2, %0|%0, %b2}";
11006         }
11007       else if (GET_CODE (operands[2]) == CONST_INT
11008                && INTVAL (operands[2]) == 1
11009                && (TARGET_PENTIUM || TARGET_PENTIUMPRO))
11010         {
11011           if (get_attr_mode (insn) == MODE_SI)
11012             return "sal{l}\t%0";
11013           else
11014             return "sal{b}\t%0";
11015         }
11016       else
11017         {
11018           if (get_attr_mode (insn) == MODE_SI)
11019             return "sal{l}\t{%2, %k0|%k0, %2}";
11020           else
11021             return "sal{b}\t{%2, %0|%0, %2}";
11022         }
11023     }
11024 }
11025   [(set (attr "type")
11026      (cond [(eq_attr "alternative" "2")
11027               (const_string "lea")
11028             (and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11029                           (const_int 0))
11030                       (match_operand 0 "register_operand" ""))
11031                  (match_operand 2 "const1_operand" ""))
11032               (const_string "alu")
11033            ]
11034            (const_string "ishift")))
11035    (set_attr "mode" "QI,SI,SI")])
11036
11037 (define_insn "*ashlqi3_1"
11038   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r")
11039         (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
11040                    (match_operand:QI 2 "nonmemory_operand" "cI,cI")))
11041    (clobber (reg:CC 17))]
11042   "TARGET_PARTIAL_REG_STALL
11043    && ix86_binary_operator_ok (ASHIFT, QImode, operands)"
11044 {
11045   switch (get_attr_type (insn))
11046     {
11047     case TYPE_ALU:
11048       if (operands[2] != const1_rtx)
11049         abort ();
11050       if (REG_P (operands[1]) && !ANY_QI_REG_P (operands[1]))
11051         return "add{l}\t{%k0, %k0|%k0, %k0}";
11052       else
11053         return "add{b}\t{%0, %0|%0, %0}";
11054
11055     default:
11056       if (REG_P (operands[2]))
11057         {
11058           if (get_attr_mode (insn) == MODE_SI)
11059             return "sal{l}\t{%b2, %k0|%k0, %b2}";
11060           else
11061             return "sal{b}\t{%b2, %0|%0, %b2}";
11062         }
11063       else if (GET_CODE (operands[2]) == CONST_INT
11064                && INTVAL (operands[2]) == 1
11065                && (TARGET_PENTIUM || TARGET_PENTIUMPRO))
11066         {
11067           if (get_attr_mode (insn) == MODE_SI)
11068             return "sal{l}\t%0";
11069           else
11070             return "sal{b}\t%0";
11071         }
11072       else
11073         {
11074           if (get_attr_mode (insn) == MODE_SI)
11075             return "sal{l}\t{%2, %k0|%k0, %2}";
11076           else
11077             return "sal{b}\t{%2, %0|%0, %2}";
11078         }
11079     }
11080 }
11081   [(set (attr "type")
11082      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11083                           (const_int 0))
11084                       (match_operand 0 "register_operand" ""))
11085                  (match_operand 2 "const1_operand" ""))
11086               (const_string "alu")
11087            ]
11088            (const_string "ishift")))
11089    (set_attr "mode" "QI,SI")])
11090
11091 ;; This pattern can't accept a variable shift count, since shifts by
11092 ;; zero don't affect the flags.  We assume that shifts by constant
11093 ;; zero are optimized away.
11094 (define_insn "*ashlqi3_cmp"
11095   [(set (reg 17)
11096         (compare
11097           (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0")
11098                      (match_operand:QI 2 "immediate_operand" "I"))
11099           (const_int 0)))
11100    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
11101         (ashift:QI (match_dup 1) (match_dup 2)))]
11102   "ix86_match_ccmode (insn, CCGOCmode)
11103    && ix86_binary_operator_ok (ASHIFT, QImode, operands)"
11104 {
11105   switch (get_attr_type (insn))
11106     {
11107     case TYPE_ALU:
11108       if (operands[2] != const1_rtx)
11109         abort ();
11110       return "add{b}\t{%0, %0|%0, %0}";
11111
11112     default:
11113       if (REG_P (operands[2]))
11114         return "sal{b}\t{%b2, %0|%0, %b2}";
11115       else if (GET_CODE (operands[2]) == CONST_INT
11116                && INTVAL (operands[2]) == 1
11117                && (TARGET_PENTIUM || TARGET_PENTIUMPRO))
11118         return "sal{b}\t%0";
11119       else
11120         return "sal{b}\t{%2, %0|%0, %2}";
11121     }
11122 }
11123   [(set (attr "type")
11124      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11125                           (const_int 0))
11126                       (match_operand 0 "register_operand" ""))
11127                  (match_operand 2 "const1_operand" ""))
11128               (const_string "alu")
11129            ]
11130            (const_string "ishift")))
11131    (set_attr "mode" "QI")])
11132
11133 ;; See comment above `ashldi3' about how this works.
11134
11135 (define_expand "ashrdi3"
11136   [(parallel [(set (match_operand:DI 0 "shiftdi_operand" "")
11137                    (ashiftrt:DI (match_operand:DI 1 "shiftdi_operand" "")
11138                                 (match_operand:QI 2 "nonmemory_operand" "")))
11139               (clobber (reg:CC 17))])]
11140   ""
11141 {
11142   if (!TARGET_64BIT && TARGET_CMOVE && ! immediate_operand (operands[2], QImode))
11143     {
11144       emit_insn (gen_ashrdi3_1 (operands[0], operands[1], operands[2]));
11145       DONE;
11146     }
11147   ix86_expand_binary_operator (ASHIFTRT, DImode, operands);
11148   DONE;
11149 })
11150
11151 (define_insn "ashrdi3_63_rex64"
11152   [(set (match_operand:DI 0 "nonimmediate_operand" "=*d,rm")
11153         (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "*a,0")
11154                      (match_operand:DI 2 "const_int_operand" "i,i")))
11155    (clobber (reg:CC 17))]
11156   "TARGET_64BIT && INTVAL (operands[2]) == 63 && (TARGET_USE_CLTD || optimize_size)
11157    && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
11158   "@
11159    {cqto|cqo}
11160    sar{q}\t{%2, %0|%0, %2}"
11161   [(set_attr "type" "imovx,ishift")
11162    (set_attr "prefix_0f" "0,*")
11163    (set_attr "length_immediate" "0,*")
11164    (set_attr "modrm" "0,1")
11165    (set_attr "mode" "DI")])
11166
11167 (define_insn "*ashrdi3_1_one_bit_rex64"
11168   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
11169         (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
11170                      (match_operand:QI 2 "const_int_1_operand" "")))
11171    (clobber (reg:CC 17))]
11172   "TARGET_64BIT && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)
11173    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
11174   "sar{q}\t%0"
11175   [(set_attr "type" "ishift")
11176    (set (attr "length") 
11177      (if_then_else (match_operand:DI 0 "register_operand" "") 
11178         (const_string "2")
11179         (const_string "*")))])
11180
11181 (define_insn "*ashrdi3_1_rex64"
11182   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,rm")
11183         (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
11184                      (match_operand:QI 2 "nonmemory_operand" "J,c")))
11185    (clobber (reg:CC 17))]
11186   "TARGET_64BIT && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
11187   "@
11188    sar{q}\t{%2, %0|%0, %2}
11189    sar{q}\t{%b2, %0|%0, %b2}"
11190   [(set_attr "type" "ishift")
11191    (set_attr "mode" "DI")])
11192
11193 ;; This pattern can't accept a variable shift count, since shifts by
11194 ;; zero don't affect the flags.  We assume that shifts by constant
11195 ;; zero are optimized away.
11196 (define_insn "*ashrdi3_one_bit_cmp_rex64"
11197   [(set (reg 17)
11198         (compare
11199           (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
11200                        (match_operand:QI 2 "const_int_1_operand" ""))
11201           (const_int 0)))
11202    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
11203         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
11204   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
11205    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)
11206    && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
11207   "sar{q}\t%0"
11208   [(set_attr "type" "ishift")
11209    (set (attr "length") 
11210      (if_then_else (match_operand:DI 0 "register_operand" "") 
11211         (const_string "2")
11212         (const_string "*")))])
11213
11214 ;; This pattern can't accept a variable shift count, since shifts by
11215 ;; zero don't affect the flags.  We assume that shifts by constant
11216 ;; zero are optimized away.
11217 (define_insn "*ashrdi3_cmp_rex64"
11218   [(set (reg 17)
11219         (compare
11220           (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
11221                        (match_operand:QI 2 "const_int_operand" "n"))
11222           (const_int 0)))
11223    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
11224         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
11225   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
11226    && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
11227   "sar{q}\t{%2, %0|%0, %2}"
11228   [(set_attr "type" "ishift")
11229    (set_attr "mode" "DI")])
11230
11231
11232 (define_insn "ashrdi3_1"
11233   [(set (match_operand:DI 0 "register_operand" "=r")
11234         (ashiftrt:DI (match_operand:DI 1 "register_operand" "0")
11235                      (match_operand:QI 2 "nonmemory_operand" "Jc")))
11236    (clobber (match_scratch:SI 3 "=&r"))
11237    (clobber (reg:CC 17))]
11238   "!TARGET_64BIT && TARGET_CMOVE"
11239   "#"
11240   [(set_attr "type" "multi")])
11241
11242 (define_insn "*ashrdi3_2"
11243   [(set (match_operand:DI 0 "register_operand" "=r")
11244         (ashiftrt:DI (match_operand:DI 1 "register_operand" "0")
11245                      (match_operand:QI 2 "nonmemory_operand" "Jc")))
11246    (clobber (reg:CC 17))]
11247   "!TARGET_64BIT"
11248   "#"
11249   [(set_attr "type" "multi")])
11250
11251 (define_split
11252   [(set (match_operand:DI 0 "register_operand" "")
11253         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
11254                      (match_operand:QI 2 "nonmemory_operand" "")))
11255    (clobber (match_scratch:SI 3 ""))
11256    (clobber (reg:CC 17))]
11257   "!TARGET_64BIT && TARGET_CMOVE && reload_completed"
11258   [(const_int 0)]
11259   "ix86_split_ashrdi (operands, operands[3]); DONE;")
11260
11261 (define_split
11262   [(set (match_operand:DI 0 "register_operand" "")
11263         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
11264                      (match_operand:QI 2 "nonmemory_operand" "")))
11265    (clobber (reg:CC 17))]
11266   "!TARGET_64BIT && reload_completed"
11267   [(const_int 0)]
11268   "ix86_split_ashrdi (operands, NULL_RTX); DONE;")
11269
11270 (define_insn "x86_shrd_1"
11271   [(set (match_operand:SI 0 "nonimmediate_operand" "+r*m,r*m")
11272         (ior:SI (ashiftrt:SI (match_dup 0)
11273                   (match_operand:QI 2 "nonmemory_operand" "I,c"))
11274                 (ashift:SI (match_operand:SI 1 "register_operand" "r,r")
11275                   (minus:QI (const_int 32) (match_dup 2)))))
11276    (clobber (reg:CC 17))]
11277   ""
11278   "@
11279    shrd{l}\t{%2, %1, %0|%0, %1, %2}
11280    shrd{l}\t{%s2%1, %0|%0, %1, %2}"
11281   [(set_attr "type" "ishift")
11282    (set_attr "prefix_0f" "1")
11283    (set_attr "pent_pair" "np")
11284    (set_attr "ppro_uops" "few")
11285    (set_attr "mode" "SI")])
11286
11287 (define_expand "x86_shift_adj_3"
11288   [(use (match_operand:SI 0 "register_operand" ""))
11289    (use (match_operand:SI 1 "register_operand" ""))
11290    (use (match_operand:QI 2 "register_operand" ""))]
11291   ""
11292 {
11293   rtx label = gen_label_rtx ();
11294   rtx tmp;
11295
11296   emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (32)));
11297
11298   tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
11299   tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
11300   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
11301                               gen_rtx_LABEL_REF (VOIDmode, label),
11302                               pc_rtx);
11303   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
11304   JUMP_LABEL (tmp) = label;
11305
11306   emit_move_insn (operands[0], operands[1]);
11307   emit_insn (gen_ashrsi3_31 (operands[1], operands[1], GEN_INT (31)));
11308
11309   emit_label (label);
11310   LABEL_NUSES (label) = 1;
11311
11312   DONE;
11313 })
11314
11315 (define_insn "ashrsi3_31"
11316   [(set (match_operand:SI 0 "nonimmediate_operand" "=*d,rm")
11317         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "*a,0")
11318                      (match_operand:SI 2 "const_int_operand" "i,i")))
11319    (clobber (reg:CC 17))]
11320   "INTVAL (operands[2]) == 31 && (TARGET_USE_CLTD || optimize_size)
11321    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
11322   "@
11323    {cltd|cdq}
11324    sar{l}\t{%2, %0|%0, %2}"
11325   [(set_attr "type" "imovx,ishift")
11326    (set_attr "prefix_0f" "0,*")
11327    (set_attr "length_immediate" "0,*")
11328    (set_attr "modrm" "0,1")
11329    (set_attr "mode" "SI")])
11330
11331 (define_insn "*ashrsi3_31_zext"
11332   [(set (match_operand:DI 0 "register_operand" "=*d,r")
11333         (zero_extend:DI (ashiftrt:SI (match_operand:SI 1 "register_operand" "*a,0")
11334                                      (match_operand:SI 2 "const_int_operand" "i,i"))))
11335    (clobber (reg:CC 17))]
11336   "INTVAL (operands[2]) == 31 && (TARGET_USE_CLTD || optimize_size)
11337    && TARGET_64BIT && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
11338   "@
11339    {cltd|cdq}
11340    sar{l}\t{%2, %k0|%k0, %2}"
11341   [(set_attr "type" "imovx,ishift")
11342    (set_attr "prefix_0f" "0,*")
11343    (set_attr "length_immediate" "0,*")
11344    (set_attr "modrm" "0,1")
11345    (set_attr "mode" "SI")])
11346
11347 (define_expand "ashrsi3"
11348   [(set (match_operand:SI 0 "nonimmediate_operand" "")
11349         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "")
11350                      (match_operand:QI 2 "nonmemory_operand" "")))
11351    (clobber (reg:CC 17))]
11352   ""
11353   "ix86_expand_binary_operator (ASHIFTRT, SImode, operands); DONE;")
11354
11355 (define_insn "*ashrsi3_1_one_bit"
11356   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
11357         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
11358                      (match_operand:QI 2 "const_int_1_operand" "")))
11359    (clobber (reg:CC 17))]
11360   "ix86_binary_operator_ok (ASHIFTRT, SImode, operands)
11361    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
11362   "sar{l}\t%0"
11363   [(set_attr "type" "ishift")
11364    (set (attr "length") 
11365      (if_then_else (match_operand:SI 0 "register_operand" "") 
11366         (const_string "2")
11367         (const_string "*")))])
11368
11369 (define_insn "*ashrsi3_1_one_bit_zext"
11370   [(set (match_operand:DI 0 "register_operand" "=r")
11371         (zero_extend:DI (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
11372                                      (match_operand:QI 2 "const_int_1_operand" ""))))
11373    (clobber (reg:CC 17))]
11374   "TARGET_64BIT && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)
11375    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
11376   "sar{l}\t%k0"
11377   [(set_attr "type" "ishift")
11378    (set_attr "length" "2")])
11379
11380 (define_insn "*ashrsi3_1"
11381   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,rm")
11382         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
11383                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
11384    (clobber (reg:CC 17))]
11385   "ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
11386   "@
11387    sar{l}\t{%2, %0|%0, %2}
11388    sar{l}\t{%b2, %0|%0, %b2}"
11389   [(set_attr "type" "ishift")
11390    (set_attr "mode" "SI")])
11391
11392 (define_insn "*ashrsi3_1_zext"
11393   [(set (match_operand:DI 0 "register_operand" "=r,r")
11394         (zero_extend:DI (ashiftrt:SI (match_operand:SI 1 "register_operand" "0,0")
11395                                      (match_operand:QI 2 "nonmemory_operand" "I,c"))))
11396    (clobber (reg:CC 17))]
11397   "TARGET_64BIT && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
11398   "@
11399    sar{l}\t{%2, %k0|%k0, %2}
11400    sar{l}\t{%b2, %k0|%k0, %b2}"
11401   [(set_attr "type" "ishift")
11402    (set_attr "mode" "SI")])
11403
11404 ;; This pattern can't accept a variable shift count, since shifts by
11405 ;; zero don't affect the flags.  We assume that shifts by constant
11406 ;; zero are optimized away.
11407 (define_insn "*ashrsi3_one_bit_cmp"
11408   [(set (reg 17)
11409         (compare
11410           (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
11411                        (match_operand:QI 2 "const_int_1_operand" ""))
11412           (const_int 0)))
11413    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
11414         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
11415   "ix86_match_ccmode (insn, CCGOCmode)
11416    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)
11417    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
11418   "sar{l}\t%0"
11419   [(set_attr "type" "ishift")
11420    (set (attr "length") 
11421      (if_then_else (match_operand:SI 0 "register_operand" "") 
11422         (const_string "2")
11423         (const_string "*")))])
11424
11425 (define_insn "*ashrsi3_one_bit_cmp_zext"
11426   [(set (reg 17)
11427         (compare
11428           (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
11429                        (match_operand:QI 2 "const_int_1_operand" ""))
11430           (const_int 0)))
11431    (set (match_operand:DI 0 "register_operand" "=r")
11432         (zero_extend:DI (ashiftrt:SI (match_dup 1) (match_dup 2))))]
11433   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)
11434    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)
11435    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
11436   "sar{l}\t%k0"
11437   [(set_attr "type" "ishift")
11438    (set_attr "length" "2")])
11439
11440 ;; This pattern can't accept a variable shift count, since shifts by
11441 ;; zero don't affect the flags.  We assume that shifts by constant
11442 ;; zero are optimized away.
11443 (define_insn "*ashrsi3_cmp"
11444   [(set (reg 17)
11445         (compare
11446           (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
11447                        (match_operand:QI 2 "immediate_operand" "I"))
11448           (const_int 0)))
11449    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
11450         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
11451   "ix86_match_ccmode (insn, CCGOCmode)
11452    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
11453   "sar{l}\t{%2, %0|%0, %2}"
11454   [(set_attr "type" "ishift")
11455    (set_attr "mode" "SI")])
11456
11457 (define_insn "*ashrsi3_cmp_zext"
11458   [(set (reg 17)
11459         (compare
11460           (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
11461                        (match_operand:QI 2 "immediate_operand" "I"))
11462           (const_int 0)))
11463    (set (match_operand:DI 0 "register_operand" "=r")
11464         (zero_extend:DI (ashiftrt:SI (match_dup 1) (match_dup 2))))]
11465   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
11466    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
11467   "sar{l}\t{%2, %k0|%k0, %2}"
11468   [(set_attr "type" "ishift")
11469    (set_attr "mode" "SI")])
11470
11471 (define_expand "ashrhi3"
11472   [(set (match_operand:HI 0 "nonimmediate_operand" "")
11473         (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "")
11474                      (match_operand:QI 2 "nonmemory_operand" "")))
11475    (clobber (reg:CC 17))]
11476   "TARGET_HIMODE_MATH"
11477   "ix86_expand_binary_operator (ASHIFTRT, HImode, operands); DONE;")
11478
11479 (define_insn "*ashrhi3_1_one_bit"
11480   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
11481         (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
11482                      (match_operand:QI 2 "const_int_1_operand" "")))
11483    (clobber (reg:CC 17))]
11484   "ix86_binary_operator_ok (ASHIFTRT, HImode, operands)
11485    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
11486   "sar{w}\t%0"
11487   [(set_attr "type" "ishift")
11488    (set (attr "length") 
11489      (if_then_else (match_operand 0 "register_operand" "") 
11490         (const_string "2")
11491         (const_string "*")))])
11492
11493 (define_insn "*ashrhi3_1"
11494   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,rm")
11495         (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0,0")
11496                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
11497    (clobber (reg:CC 17))]
11498   "ix86_binary_operator_ok (ASHIFTRT, HImode, operands)"
11499   "@
11500    sar{w}\t{%2, %0|%0, %2}
11501    sar{w}\t{%b2, %0|%0, %b2}"
11502   [(set_attr "type" "ishift")
11503    (set_attr "mode" "HI")])
11504
11505 ;; This pattern can't accept a variable shift count, since shifts by
11506 ;; zero don't affect the flags.  We assume that shifts by constant
11507 ;; zero are optimized away.
11508 (define_insn "*ashrhi3_one_bit_cmp"
11509   [(set (reg 17)
11510         (compare
11511           (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
11512                        (match_operand:QI 2 "const_int_1_operand" ""))
11513           (const_int 0)))
11514    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
11515         (ashiftrt:HI (match_dup 1) (match_dup 2)))]
11516   "ix86_match_ccmode (insn, CCGOCmode)
11517    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)
11518    && ix86_binary_operator_ok (ASHIFTRT, HImode, operands)"
11519   "sar{w}\t%0"
11520   [(set_attr "type" "ishift")
11521    (set (attr "length") 
11522      (if_then_else (match_operand 0 "register_operand" "") 
11523         (const_string "2")
11524         (const_string "*")))])
11525
11526 ;; This pattern can't accept a variable shift count, since shifts by
11527 ;; zero don't affect the flags.  We assume that shifts by constant
11528 ;; zero are optimized away.
11529 (define_insn "*ashrhi3_cmp"
11530   [(set (reg 17)
11531         (compare
11532           (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
11533                        (match_operand:QI 2 "immediate_operand" "I"))
11534           (const_int 0)))
11535    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
11536         (ashiftrt:HI (match_dup 1) (match_dup 2)))]
11537   "ix86_match_ccmode (insn, CCGOCmode)
11538    && ix86_binary_operator_ok (ASHIFTRT, HImode, operands)"
11539   "sar{w}\t{%2, %0|%0, %2}"
11540   [(set_attr "type" "ishift")
11541    (set_attr "mode" "HI")])
11542
11543 (define_expand "ashrqi3"
11544   [(set (match_operand:QI 0 "nonimmediate_operand" "")
11545         (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "")
11546                      (match_operand:QI 2 "nonmemory_operand" "")))
11547    (clobber (reg:CC 17))]
11548   "TARGET_QIMODE_MATH"
11549   "ix86_expand_binary_operator (ASHIFTRT, QImode, operands); DONE;")
11550
11551 (define_insn "*ashrqi3_1_one_bit"
11552   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
11553         (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
11554                      (match_operand:QI 2 "const_int_1_operand" "")))
11555    (clobber (reg:CC 17))]
11556   "ix86_binary_operator_ok (ASHIFTRT, QImode, operands)
11557    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
11558   "sar{b}\t%0"
11559   [(set_attr "type" "ishift")
11560    (set (attr "length") 
11561      (if_then_else (match_operand 0 "register_operand" "") 
11562         (const_string "2")
11563         (const_string "*")))])
11564
11565 (define_insn "*ashrqi3_1"
11566   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,qm")
11567         (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
11568                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
11569    (clobber (reg:CC 17))]
11570   "ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
11571   "@
11572    sar{b}\t{%2, %0|%0, %2}
11573    sar{b}\t{%b2, %0|%0, %b2}"
11574   [(set_attr "type" "ishift")
11575    (set_attr "mode" "QI")])
11576
11577 ;; This pattern can't accept a variable shift count, since shifts by
11578 ;; zero don't affect the flags.  We assume that shifts by constant
11579 ;; zero are optimized away.
11580 (define_insn "*ashrqi3_one_bit_cmp"
11581   [(set (reg 17)
11582         (compare
11583           (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
11584                        (match_operand:QI 2 "const_int_1_operand" "I"))
11585           (const_int 0)))
11586    (set (match_operand:QI 0 "nonimmediate_operand" "=rm")
11587         (ashiftrt:QI (match_dup 1) (match_dup 2)))]
11588   "ix86_match_ccmode (insn, CCGOCmode)
11589    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)
11590    && ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
11591   "sar{b}\t%0"
11592   [(set_attr "type" "ishift")
11593    (set (attr "length") 
11594      (if_then_else (match_operand 0 "register_operand" "") 
11595         (const_string "2")
11596         (const_string "*")))])
11597
11598 ;; This pattern can't accept a variable shift count, since shifts by
11599 ;; zero don't affect the flags.  We assume that shifts by constant
11600 ;; zero are optimized away.
11601 (define_insn "*ashrqi3_cmp"
11602   [(set (reg 17)
11603         (compare
11604           (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
11605                        (match_operand:QI 2 "immediate_operand" "I"))
11606           (const_int 0)))
11607    (set (match_operand:QI 0 "nonimmediate_operand" "=rm")
11608         (ashiftrt:QI (match_dup 1) (match_dup 2)))]
11609   "ix86_match_ccmode (insn, CCGOCmode)
11610    && ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
11611   "sar{b}\t{%2, %0|%0, %2}"
11612   [(set_attr "type" "ishift")
11613    (set_attr "mode" "QI")])
11614 \f
11615 ;; Logical shift instructions
11616
11617 ;; See comment above `ashldi3' about how this works.
11618
11619 (define_expand "lshrdi3"
11620   [(parallel [(set (match_operand:DI 0 "shiftdi_operand" "")
11621                    (lshiftrt:DI (match_operand:DI 1 "shiftdi_operand" "")
11622                                 (match_operand:QI 2 "nonmemory_operand" "")))
11623               (clobber (reg:CC 17))])]
11624   ""
11625 {
11626   if (!TARGET_64BIT && TARGET_CMOVE && ! immediate_operand (operands[2], QImode))
11627     {
11628       emit_insn (gen_lshrdi3_1 (operands[0], operands[1], operands[2]));
11629       DONE;
11630     }
11631   ix86_expand_binary_operator (LSHIFTRT, DImode, operands);
11632   DONE;
11633 })
11634
11635 (define_insn "*lshrdi3_1_one_bit_rex64"
11636   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
11637         (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
11638                      (match_operand:QI 2 "const_int_1_operand" "")))
11639    (clobber (reg:CC 17))]
11640   "TARGET_64BIT && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)
11641    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
11642   "shr{q}\t%0"
11643   [(set_attr "type" "ishift")
11644    (set (attr "length") 
11645      (if_then_else (match_operand:DI 0 "register_operand" "") 
11646         (const_string "2")
11647         (const_string "*")))])
11648
11649 (define_insn "*lshrdi3_1_rex64"
11650   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,rm")
11651         (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
11652                      (match_operand:QI 2 "nonmemory_operand" "J,c")))
11653    (clobber (reg:CC 17))]
11654   "TARGET_64BIT && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
11655   "@
11656    shr{q}\t{%2, %0|%0, %2}
11657    shr{q}\t{%b2, %0|%0, %b2}"
11658   [(set_attr "type" "ishift")
11659    (set_attr "mode" "DI")])
11660
11661 ;; This pattern can't accept a variable shift count, since shifts by
11662 ;; zero don't affect the flags.  We assume that shifts by constant
11663 ;; zero are optimized away.
11664 (define_insn "*lshrdi3_cmp_one_bit_rex64"
11665   [(set (reg 17)
11666         (compare
11667           (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
11668                        (match_operand:QI 2 "const_int_1_operand" ""))
11669           (const_int 0)))
11670    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
11671         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
11672   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
11673    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)
11674    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
11675   "shr{q}\t%0"
11676   [(set_attr "type" "ishift")
11677    (set (attr "length") 
11678      (if_then_else (match_operand:DI 0 "register_operand" "") 
11679         (const_string "2")
11680         (const_string "*")))])
11681
11682 ;; This pattern can't accept a variable shift count, since shifts by
11683 ;; zero don't affect the flags.  We assume that shifts by constant
11684 ;; zero are optimized away.
11685 (define_insn "*lshrdi3_cmp_rex64"
11686   [(set (reg 17)
11687         (compare
11688           (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
11689                        (match_operand:QI 2 "const_int_operand" "e"))
11690           (const_int 0)))
11691    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
11692         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
11693   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
11694    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
11695   "shr{q}\t{%2, %0|%0, %2}"
11696   [(set_attr "type" "ishift")
11697    (set_attr "mode" "DI")])
11698
11699 (define_insn "lshrdi3_1"
11700   [(set (match_operand:DI 0 "register_operand" "=r")
11701         (lshiftrt:DI (match_operand:DI 1 "register_operand" "0")
11702                      (match_operand:QI 2 "nonmemory_operand" "Jc")))
11703    (clobber (match_scratch:SI 3 "=&r"))
11704    (clobber (reg:CC 17))]
11705   "!TARGET_64BIT && TARGET_CMOVE"
11706   "#"
11707   [(set_attr "type" "multi")])
11708
11709 (define_insn "*lshrdi3_2"
11710   [(set (match_operand:DI 0 "register_operand" "=r")
11711         (lshiftrt:DI (match_operand:DI 1 "register_operand" "0")
11712                      (match_operand:QI 2 "nonmemory_operand" "Jc")))
11713    (clobber (reg:CC 17))]
11714   "!TARGET_64BIT"
11715   "#"
11716   [(set_attr "type" "multi")])
11717
11718 (define_split 
11719   [(set (match_operand:DI 0 "register_operand" "")
11720         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
11721                      (match_operand:QI 2 "nonmemory_operand" "")))
11722    (clobber (match_scratch:SI 3 ""))
11723    (clobber (reg:CC 17))]
11724   "!TARGET_64BIT && TARGET_CMOVE && reload_completed"
11725   [(const_int 0)]
11726   "ix86_split_lshrdi (operands, operands[3]); DONE;")
11727
11728 (define_split 
11729   [(set (match_operand:DI 0 "register_operand" "")
11730         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
11731                      (match_operand:QI 2 "nonmemory_operand" "")))
11732    (clobber (reg:CC 17))]
11733   "!TARGET_64BIT && reload_completed"
11734   [(const_int 0)]
11735   "ix86_split_lshrdi (operands, NULL_RTX); DONE;")
11736
11737 (define_expand "lshrsi3"
11738   [(set (match_operand:SI 0 "nonimmediate_operand" "")
11739         (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "")
11740                      (match_operand:QI 2 "nonmemory_operand" "")))
11741    (clobber (reg:CC 17))]
11742   ""
11743   "ix86_expand_binary_operator (LSHIFTRT, SImode, operands); DONE;")
11744
11745 (define_insn "*lshrsi3_1_one_bit"
11746   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
11747         (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
11748                      (match_operand:QI 2 "const_int_1_operand" "")))
11749    (clobber (reg:CC 17))]
11750   "ix86_binary_operator_ok (LSHIFTRT, HImode, operands)
11751    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
11752   "shr{l}\t%0"
11753   [(set_attr "type" "ishift")
11754    (set (attr "length") 
11755      (if_then_else (match_operand:SI 0 "register_operand" "") 
11756         (const_string "2")
11757         (const_string "*")))])
11758
11759 (define_insn "*lshrsi3_1_one_bit_zext"
11760   [(set (match_operand:DI 0 "register_operand" "=r")
11761         (lshiftrt:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "0"))
11762                      (match_operand:QI 2 "const_int_1_operand" "")))
11763    (clobber (reg:CC 17))]
11764   "TARGET_64BIT && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)
11765    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
11766   "shr{l}\t%k0"
11767   [(set_attr "type" "ishift")
11768    (set_attr "length" "2")])
11769
11770 (define_insn "*lshrsi3_1"
11771   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,rm")
11772         (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
11773                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
11774    (clobber (reg:CC 17))]
11775   "ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
11776   "@
11777    shr{l}\t{%2, %0|%0, %2}
11778    shr{l}\t{%b2, %0|%0, %b2}"
11779   [(set_attr "type" "ishift")
11780    (set_attr "mode" "SI")])
11781
11782 (define_insn "*lshrsi3_1_zext"
11783   [(set (match_operand:DI 0 "register_operand" "=r,r")
11784         (zero_extend:DI
11785           (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
11786                        (match_operand:QI 2 "nonmemory_operand" "I,c"))))
11787    (clobber (reg:CC 17))]
11788   "TARGET_64BIT && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
11789   "@
11790    shr{l}\t{%2, %k0|%k0, %2}
11791    shr{l}\t{%b2, %k0|%k0, %b2}"
11792   [(set_attr "type" "ishift")
11793    (set_attr "mode" "SI")])
11794
11795 ;; This pattern can't accept a variable shift count, since shifts by
11796 ;; zero don't affect the flags.  We assume that shifts by constant
11797 ;; zero are optimized away.
11798 (define_insn "*lshrsi3_one_bit_cmp"
11799   [(set (reg 17)
11800         (compare
11801           (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
11802                        (match_operand:QI 2 "const_int_1_operand" ""))
11803           (const_int 0)))
11804    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
11805         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
11806   "ix86_match_ccmode (insn, CCGOCmode)
11807    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)
11808    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
11809   "shr{l}\t%0"
11810   [(set_attr "type" "ishift")
11811    (set (attr "length") 
11812      (if_then_else (match_operand:SI 0 "register_operand" "") 
11813         (const_string "2")
11814         (const_string "*")))])
11815
11816 (define_insn "*lshrsi3_cmp_one_bit_zext"
11817   [(set (reg 17)
11818         (compare
11819           (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
11820                        (match_operand:QI 2 "const_int_1_operand" ""))
11821           (const_int 0)))
11822    (set (match_operand:DI 0 "register_operand" "=r")
11823         (lshiftrt:DI (zero_extend:DI (match_dup 1)) (match_dup 2)))]
11824   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
11825    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)
11826    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
11827   "shr{l}\t%k0"
11828   [(set_attr "type" "ishift")
11829    (set_attr "length" "2")])
11830
11831 ;; This pattern can't accept a variable shift count, since shifts by
11832 ;; zero don't affect the flags.  We assume that shifts by constant
11833 ;; zero are optimized away.
11834 (define_insn "*lshrsi3_cmp"
11835   [(set (reg 17)
11836         (compare
11837           (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
11838                        (match_operand:QI 2 "immediate_operand" "I"))
11839           (const_int 0)))
11840    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
11841         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
11842   "ix86_match_ccmode (insn, CCGOCmode)
11843    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
11844   "shr{l}\t{%2, %0|%0, %2}"
11845   [(set_attr "type" "ishift")
11846    (set_attr "mode" "SI")])
11847
11848 (define_insn "*lshrsi3_cmp_zext"
11849   [(set (reg 17)
11850         (compare
11851           (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
11852                        (match_operand:QI 2 "immediate_operand" "I"))
11853           (const_int 0)))
11854    (set (match_operand:DI 0 "register_operand" "=r")
11855         (lshiftrt:DI (zero_extend:DI (match_dup 1)) (match_dup 2)))]
11856   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
11857    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
11858   "shr{l}\t{%2, %k0|%k0, %2}"
11859   [(set_attr "type" "ishift")
11860    (set_attr "mode" "SI")])
11861
11862 (define_expand "lshrhi3"
11863   [(set (match_operand:HI 0 "nonimmediate_operand" "")
11864         (lshiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "")
11865                      (match_operand:QI 2 "nonmemory_operand" "")))
11866    (clobber (reg:CC 17))]
11867   "TARGET_HIMODE_MATH"
11868   "ix86_expand_binary_operator (LSHIFTRT, HImode, operands); DONE;")
11869
11870 (define_insn "*lshrhi3_1_one_bit"
11871   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
11872         (lshiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
11873                      (match_operand:QI 2 "const_int_1_operand" "")))
11874    (clobber (reg:CC 17))]
11875   "ix86_binary_operator_ok (LSHIFTRT, HImode, operands)
11876    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
11877   "shr{w}\t%0"
11878   [(set_attr "type" "ishift")
11879    (set (attr "length") 
11880      (if_then_else (match_operand 0 "register_operand" "") 
11881         (const_string "2")
11882         (const_string "*")))])
11883
11884 (define_insn "*lshrhi3_1"
11885   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,rm")
11886         (lshiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0,0")
11887                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
11888    (clobber (reg:CC 17))]
11889   "ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
11890   "@
11891    shr{w}\t{%2, %0|%0, %2}
11892    shr{w}\t{%b2, %0|%0, %b2}"
11893   [(set_attr "type" "ishift")
11894    (set_attr "mode" "HI")])
11895
11896 ;; This pattern can't accept a variable shift count, since shifts by
11897 ;; zero don't affect the flags.  We assume that shifts by constant
11898 ;; zero are optimized away.
11899 (define_insn "*lshrhi3_one_bit_cmp"
11900   [(set (reg 17)
11901         (compare
11902           (lshiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
11903                        (match_operand:QI 2 "const_int_1_operand" ""))
11904           (const_int 0)))
11905    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
11906         (lshiftrt:HI (match_dup 1) (match_dup 2)))]
11907   "ix86_match_ccmode (insn, CCGOCmode)
11908    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)
11909    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
11910   "shr{w}\t%0"
11911   [(set_attr "type" "ishift")
11912    (set (attr "length") 
11913      (if_then_else (match_operand:SI 0 "register_operand" "") 
11914         (const_string "2")
11915         (const_string "*")))])
11916
11917 ;; This pattern can't accept a variable shift count, since shifts by
11918 ;; zero don't affect the flags.  We assume that shifts by constant
11919 ;; zero are optimized away.
11920 (define_insn "*lshrhi3_cmp"
11921   [(set (reg 17)
11922         (compare
11923           (lshiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
11924                        (match_operand:QI 2 "immediate_operand" "I"))
11925           (const_int 0)))
11926    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
11927         (lshiftrt:HI (match_dup 1) (match_dup 2)))]
11928   "ix86_match_ccmode (insn, CCGOCmode)
11929    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
11930   "shr{w}\t{%2, %0|%0, %2}"
11931   [(set_attr "type" "ishift")
11932    (set_attr "mode" "HI")])
11933
11934 (define_expand "lshrqi3"
11935   [(set (match_operand:QI 0 "nonimmediate_operand" "")
11936         (lshiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "")
11937                      (match_operand:QI 2 "nonmemory_operand" "")))
11938    (clobber (reg:CC 17))]
11939   "TARGET_QIMODE_MATH"
11940   "ix86_expand_binary_operator (LSHIFTRT, QImode, operands); DONE;")
11941
11942 (define_insn "*lshrqi3_1_one_bit"
11943   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
11944         (lshiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
11945                      (match_operand:QI 2 "const_int_1_operand" "")))
11946    (clobber (reg:CC 17))]
11947   "ix86_binary_operator_ok (LSHIFTRT, QImode, operands)
11948    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
11949   "shr{b}\t%0"
11950   [(set_attr "type" "ishift")
11951    (set (attr "length") 
11952      (if_then_else (match_operand 0 "register_operand" "") 
11953         (const_string "2")
11954         (const_string "*")))])
11955
11956 (define_insn "*lshrqi3_1"
11957   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,qm")
11958         (lshiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
11959                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
11960    (clobber (reg:CC 17))]
11961   "ix86_binary_operator_ok (LSHIFTRT, QImode, operands)"
11962   "@
11963    shr{b}\t{%2, %0|%0, %2}
11964    shr{b}\t{%b2, %0|%0, %b2}"
11965   [(set_attr "type" "ishift")
11966    (set_attr "mode" "QI")])
11967
11968 ;; This pattern can't accept a variable shift count, since shifts by
11969 ;; zero don't affect the flags.  We assume that shifts by constant
11970 ;; zero are optimized away.
11971 (define_insn "*lshrqi2_one_bit_cmp"
11972   [(set (reg 17)
11973         (compare
11974           (lshiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
11975                        (match_operand:QI 2 "const_int_1_operand" ""))
11976           (const_int 0)))
11977    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
11978         (lshiftrt:QI (match_dup 1) (match_dup 2)))]
11979   "ix86_match_ccmode (insn, CCGOCmode)
11980    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)
11981    && ix86_binary_operator_ok (LSHIFTRT, QImode, operands)"
11982   "shr{b}\t%0"
11983   [(set_attr "type" "ishift")
11984    (set (attr "length") 
11985      (if_then_else (match_operand:SI 0 "register_operand" "") 
11986         (const_string "2")
11987         (const_string "*")))])
11988
11989 ;; This pattern can't accept a variable shift count, since shifts by
11990 ;; zero don't affect the flags.  We assume that shifts by constant
11991 ;; zero are optimized away.
11992 (define_insn "*lshrqi2_cmp"
11993   [(set (reg 17)
11994         (compare
11995           (lshiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
11996                        (match_operand:QI 2 "immediate_operand" "I"))
11997           (const_int 0)))
11998    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
11999         (lshiftrt:QI (match_dup 1) (match_dup 2)))]
12000   "ix86_match_ccmode (insn, CCGOCmode)
12001    && ix86_binary_operator_ok (LSHIFTRT, QImode, operands)"
12002   "shr{b}\t{%2, %0|%0, %2}"
12003   [(set_attr "type" "ishift")
12004    (set_attr "mode" "QI")])
12005 \f
12006 ;; Rotate instructions
12007
12008 (define_expand "rotldi3"
12009   [(set (match_operand:DI 0 "nonimmediate_operand" "")
12010         (rotate:DI (match_operand:DI 1 "nonimmediate_operand" "")
12011                    (match_operand:QI 2 "nonmemory_operand" "")))
12012    (clobber (reg:CC 17))]
12013   "TARGET_64BIT"
12014   "ix86_expand_binary_operator (ROTATE, DImode, operands); DONE;")
12015
12016 (define_insn "*rotlsi3_1_one_bit_rex64"
12017   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
12018         (rotate:DI (match_operand:DI 1 "nonimmediate_operand" "0")
12019                    (match_operand:QI 2 "const_int_1_operand" "")))
12020    (clobber (reg:CC 17))]
12021   "TARGET_64BIT && ix86_binary_operator_ok (ROTATE, DImode, operands)
12022    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
12023   "rol{q}\t%0"
12024   [(set_attr "type" "ishift")
12025    (set (attr "length") 
12026      (if_then_else (match_operand:DI 0 "register_operand" "") 
12027         (const_string "2")
12028         (const_string "*")))])
12029
12030 (define_insn "*rotldi3_1_rex64"
12031   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,rm")
12032         (rotate:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
12033                    (match_operand:QI 2 "nonmemory_operand" "e,c")))
12034    (clobber (reg:CC 17))]
12035   "TARGET_64BIT && ix86_binary_operator_ok (ROTATE, DImode, operands)"
12036   "@
12037    rol{q}\t{%2, %0|%0, %2}
12038    rol{q}\t{%b2, %0|%0, %b2}"
12039   [(set_attr "type" "ishift")
12040    (set_attr "mode" "DI")])
12041
12042 (define_expand "rotlsi3"
12043   [(set (match_operand:SI 0 "nonimmediate_operand" "")
12044         (rotate:SI (match_operand:SI 1 "nonimmediate_operand" "")
12045                    (match_operand:QI 2 "nonmemory_operand" "")))
12046    (clobber (reg:CC 17))]
12047   ""
12048   "ix86_expand_binary_operator (ROTATE, SImode, operands); DONE;")
12049
12050 (define_insn "*rotlsi3_1_one_bit"
12051   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
12052         (rotate:SI (match_operand:SI 1 "nonimmediate_operand" "0")
12053                    (match_operand:QI 2 "const_int_1_operand" "")))
12054    (clobber (reg:CC 17))]
12055   "ix86_binary_operator_ok (ROTATE, SImode, operands)
12056    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
12057   "rol{l}\t%0"
12058   [(set_attr "type" "ishift")
12059    (set (attr "length") 
12060      (if_then_else (match_operand:SI 0 "register_operand" "") 
12061         (const_string "2")
12062         (const_string "*")))])
12063
12064 (define_insn "*rotlsi3_1_one_bit_zext"
12065   [(set (match_operand:DI 0 "register_operand" "=r")
12066         (zero_extend:DI
12067           (rotate:SI (match_operand:SI 1 "register_operand" "0")
12068                      (match_operand:QI 2 "const_int_1_operand" ""))))
12069    (clobber (reg:CC 17))]
12070   "TARGET_64BIT && ix86_binary_operator_ok (ROTATE, SImode, operands)
12071    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
12072   "rol{l}\t%k0"
12073   [(set_attr "type" "ishift")
12074    (set_attr "length" "2")])
12075
12076 (define_insn "*rotlsi3_1"
12077   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,rm")
12078         (rotate:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
12079                    (match_operand:QI 2 "nonmemory_operand" "I,c")))
12080    (clobber (reg:CC 17))]
12081   "ix86_binary_operator_ok (ROTATE, SImode, operands)"
12082   "@
12083    rol{l}\t{%2, %0|%0, %2}
12084    rol{l}\t{%b2, %0|%0, %b2}"
12085   [(set_attr "type" "ishift")
12086    (set_attr "mode" "SI")])
12087
12088 (define_insn "*rotlsi3_1_zext"
12089   [(set (match_operand:DI 0 "register_operand" "=r,r")
12090         (zero_extend:DI
12091           (rotate:SI (match_operand:SI 1 "register_operand" "0,0")
12092                      (match_operand:QI 2 "nonmemory_operand" "I,c"))))
12093    (clobber (reg:CC 17))]
12094   "TARGET_64BIT && ix86_binary_operator_ok (ROTATE, SImode, operands)"
12095   "@
12096    rol{l}\t{%2, %k0|%k0, %2}
12097    rol{l}\t{%b2, %k0|%k0, %b2}"
12098   [(set_attr "type" "ishift")
12099    (set_attr "mode" "SI")])
12100
12101 (define_expand "rotlhi3"
12102   [(set (match_operand:HI 0 "nonimmediate_operand" "")
12103         (rotate:HI (match_operand:HI 1 "nonimmediate_operand" "")
12104                    (match_operand:QI 2 "nonmemory_operand" "")))
12105    (clobber (reg:CC 17))]
12106   "TARGET_HIMODE_MATH"
12107   "ix86_expand_binary_operator (ROTATE, HImode, operands); DONE;")
12108
12109 (define_insn "*rotlhi3_1_one_bit"
12110   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
12111         (rotate:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12112                    (match_operand:QI 2 "const_int_1_operand" "")))
12113    (clobber (reg:CC 17))]
12114   "ix86_binary_operator_ok (ROTATE, HImode, operands)
12115    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
12116   "rol{w}\t%0"
12117   [(set_attr "type" "ishift")
12118    (set (attr "length") 
12119      (if_then_else (match_operand 0 "register_operand" "") 
12120         (const_string "2")
12121         (const_string "*")))])
12122
12123 (define_insn "*rotlhi3_1"
12124   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,rm")
12125         (rotate:HI (match_operand:HI 1 "nonimmediate_operand" "0,0")
12126                    (match_operand:QI 2 "nonmemory_operand" "I,c")))
12127    (clobber (reg:CC 17))]
12128   "ix86_binary_operator_ok (ROTATE, HImode, operands)"
12129   "@
12130    rol{w}\t{%2, %0|%0, %2}
12131    rol{w}\t{%b2, %0|%0, %b2}"
12132   [(set_attr "type" "ishift")
12133    (set_attr "mode" "HI")])
12134
12135 (define_expand "rotlqi3"
12136   [(set (match_operand:QI 0 "nonimmediate_operand" "")
12137         (rotate:QI (match_operand:QI 1 "nonimmediate_operand" "")
12138                    (match_operand:QI 2 "nonmemory_operand" "")))
12139    (clobber (reg:CC 17))]
12140   "TARGET_QIMODE_MATH"
12141   "ix86_expand_binary_operator (ROTATE, QImode, operands); DONE;")
12142
12143 (define_insn "*rotlqi3_1_one_bit"
12144   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
12145         (rotate:QI (match_operand:QI 1 "nonimmediate_operand" "0")
12146                    (match_operand:QI 2 "const_int_1_operand" "")))
12147    (clobber (reg:CC 17))]
12148   "ix86_binary_operator_ok (ROTATE, QImode, operands)
12149    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
12150   "rol{b}\t%0"
12151   [(set_attr "type" "ishift")
12152    (set (attr "length") 
12153      (if_then_else (match_operand 0 "register_operand" "") 
12154         (const_string "2")
12155         (const_string "*")))])
12156
12157 (define_insn "*rotlqi3_1"
12158   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,qm")
12159         (rotate:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
12160                    (match_operand:QI 2 "nonmemory_operand" "I,c")))
12161    (clobber (reg:CC 17))]
12162   "ix86_binary_operator_ok (ROTATE, QImode, operands)"
12163   "@
12164    rol{b}\t{%2, %0|%0, %2}
12165    rol{b}\t{%b2, %0|%0, %b2}"
12166   [(set_attr "type" "ishift")
12167    (set_attr "mode" "QI")])
12168
12169 (define_expand "rotrdi3"
12170   [(set (match_operand:DI 0 "nonimmediate_operand" "")
12171         (rotatert:DI (match_operand:DI 1 "nonimmediate_operand" "")
12172                      (match_operand:QI 2 "nonmemory_operand" "")))
12173    (clobber (reg:CC 17))]
12174   "TARGET_64BIT"
12175   "ix86_expand_binary_operator (ROTATERT, DImode, operands); DONE;")
12176
12177 (define_insn "*rotrdi3_1_one_bit_rex64"
12178   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
12179         (rotatert:DI (match_operand:DI 1 "nonimmediate_operand" "0")
12180                      (match_operand:QI 2 "const_int_1_operand" "")))
12181    (clobber (reg:CC 17))]
12182   "TARGET_64BIT && ix86_binary_operator_ok (ROTATERT, DImode, operands)
12183    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
12184   "ror{q}\t%0"
12185   [(set_attr "type" "ishift")
12186    (set (attr "length") 
12187      (if_then_else (match_operand:DI 0 "register_operand" "") 
12188         (const_string "2")
12189         (const_string "*")))])
12190
12191 (define_insn "*rotrdi3_1_rex64"
12192   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,rm")
12193         (rotatert:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
12194                      (match_operand:QI 2 "nonmemory_operand" "J,c")))
12195    (clobber (reg:CC 17))]
12196   "TARGET_64BIT && ix86_binary_operator_ok (ROTATERT, DImode, operands)"
12197   "@
12198    ror{q}\t{%2, %0|%0, %2}
12199    ror{q}\t{%b2, %0|%0, %b2}"
12200   [(set_attr "type" "ishift")
12201    (set_attr "mode" "DI")])
12202
12203 (define_expand "rotrsi3"
12204   [(set (match_operand:SI 0 "nonimmediate_operand" "")
12205         (rotatert:SI (match_operand:SI 1 "nonimmediate_operand" "")
12206                      (match_operand:QI 2 "nonmemory_operand" "")))
12207    (clobber (reg:CC 17))]
12208   ""
12209   "ix86_expand_binary_operator (ROTATERT, SImode, operands); DONE;")
12210
12211 (define_insn "*rotrsi3_1_one_bit"
12212   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
12213         (rotatert:SI (match_operand:SI 1 "nonimmediate_operand" "0")
12214                      (match_operand:QI 2 "const_int_1_operand" "")))
12215    (clobber (reg:CC 17))]
12216   "ix86_binary_operator_ok (ROTATERT, SImode, operands)
12217    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
12218   "ror{l}\t%0"
12219   [(set_attr "type" "ishift")
12220    (set (attr "length") 
12221      (if_then_else (match_operand:SI 0 "register_operand" "") 
12222         (const_string "2")
12223         (const_string "*")))])
12224
12225 (define_insn "*rotrsi3_1_one_bit_zext"
12226   [(set (match_operand:DI 0 "register_operand" "=r")
12227         (zero_extend:DI
12228           (rotatert:SI (match_operand:SI 1 "register_operand" "0")
12229                        (match_operand:QI 2 "const_int_1_operand" ""))))
12230    (clobber (reg:CC 17))]
12231   "TARGET_64BIT && ix86_binary_operator_ok (ROTATERT, SImode, operands)
12232    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
12233   "ror{l}\t%k0"
12234   [(set_attr "type" "ishift")
12235    (set (attr "length") 
12236      (if_then_else (match_operand:SI 0 "register_operand" "") 
12237         (const_string "2")
12238         (const_string "*")))])
12239
12240 (define_insn "*rotrsi3_1"
12241   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,rm")
12242         (rotatert:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
12243                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
12244    (clobber (reg:CC 17))]
12245   "ix86_binary_operator_ok (ROTATERT, SImode, operands)"
12246   "@
12247    ror{l}\t{%2, %0|%0, %2}
12248    ror{l}\t{%b2, %0|%0, %b2}"
12249   [(set_attr "type" "ishift")
12250    (set_attr "mode" "SI")])
12251
12252 (define_insn "*rotrsi3_1_zext"
12253   [(set (match_operand:DI 0 "register_operand" "=r,r")
12254         (zero_extend:DI
12255           (rotatert:SI (match_operand:SI 1 "register_operand" "0,0")
12256                        (match_operand:QI 2 "nonmemory_operand" "I,c"))))
12257    (clobber (reg:CC 17))]
12258   "TARGET_64BIT && ix86_binary_operator_ok (ROTATERT, SImode, operands)"
12259   "@
12260    ror{l}\t{%2, %k0|%k0, %2}
12261    ror{l}\t{%b2, %k0|%k0, %b2}"
12262   [(set_attr "type" "ishift")
12263    (set_attr "mode" "SI")])
12264
12265 (define_expand "rotrhi3"
12266   [(set (match_operand:HI 0 "nonimmediate_operand" "")
12267         (rotatert:HI (match_operand:HI 1 "nonimmediate_operand" "")
12268                      (match_operand:QI 2 "nonmemory_operand" "")))
12269    (clobber (reg:CC 17))]
12270   "TARGET_HIMODE_MATH"
12271   "ix86_expand_binary_operator (ROTATERT, HImode, operands); DONE;")
12272
12273 (define_insn "*rotrhi3_one_bit"
12274   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
12275         (rotatert:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12276                      (match_operand:QI 2 "const_int_1_operand" "")))
12277    (clobber (reg:CC 17))]
12278   "ix86_binary_operator_ok (ROTATERT, HImode, operands)
12279    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
12280   "ror{w}\t%0"
12281   [(set_attr "type" "ishift")
12282    (set (attr "length") 
12283      (if_then_else (match_operand 0 "register_operand" "") 
12284         (const_string "2")
12285         (const_string "*")))])
12286
12287 (define_insn "*rotrhi3"
12288   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,rm")
12289         (rotatert:HI (match_operand:HI 1 "nonimmediate_operand" "0,0")
12290                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
12291    (clobber (reg:CC 17))]
12292   "ix86_binary_operator_ok (ROTATERT, HImode, operands)"
12293   "@
12294    ror{w}\t{%2, %0|%0, %2}
12295    ror{w}\t{%b2, %0|%0, %b2}"
12296   [(set_attr "type" "ishift")
12297    (set_attr "mode" "HI")])
12298
12299 (define_expand "rotrqi3"
12300   [(set (match_operand:QI 0 "nonimmediate_operand" "")
12301         (rotatert:QI (match_operand:QI 1 "nonimmediate_operand" "")
12302                      (match_operand:QI 2 "nonmemory_operand" "")))
12303    (clobber (reg:CC 17))]
12304   "TARGET_QIMODE_MATH"
12305   "ix86_expand_binary_operator (ROTATERT, QImode, operands); DONE;")
12306
12307 (define_insn "*rotrqi3_1_one_bit"
12308   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
12309         (rotatert:QI (match_operand:QI 1 "nonimmediate_operand" "0")
12310                      (match_operand:QI 2 "const_int_1_operand" "")))
12311    (clobber (reg:CC 17))]
12312   "ix86_binary_operator_ok (ROTATERT, QImode, operands)
12313    && (TARGET_PENTIUM || TARGET_PENTIUMPRO)"
12314   "ror{b}\t%0"
12315   [(set_attr "type" "ishift")
12316    (set (attr "length") 
12317      (if_then_else (match_operand 0 "register_operand" "") 
12318         (const_string "2")
12319         (const_string "*")))])
12320
12321 (define_insn "*rotrqi3_1"
12322   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,qm")
12323         (rotatert:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
12324                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
12325    (clobber (reg:CC 17))]
12326   "ix86_binary_operator_ok (ROTATERT, QImode, operands)"
12327   "@
12328    ror{b}\t{%2, %0|%0, %2}
12329    ror{b}\t{%b2, %0|%0, %b2}"
12330   [(set_attr "type" "ishift")
12331    (set_attr "mode" "QI")])
12332 \f
12333 ;; Bit set / bit test instructions
12334
12335 (define_expand "extv"
12336   [(set (match_operand:SI 0 "register_operand" "")
12337         (sign_extract:SI (match_operand:SI 1 "register_operand" "")
12338                          (match_operand:SI 2 "immediate_operand" "")
12339                          (match_operand:SI 3 "immediate_operand" "")))]
12340   ""
12341 {
12342   /* Handle extractions from %ah et al.  */
12343   if (INTVAL (operands[2]) != 8 || INTVAL (operands[3]) != 8)
12344     FAIL;
12345
12346   /* From mips.md: extract_bit_field doesn't verify that our source
12347      matches the predicate, so check it again here.  */
12348   if (! register_operand (operands[1], VOIDmode))
12349     FAIL;
12350 })
12351
12352 (define_expand "extzv"
12353   [(set (match_operand:SI 0 "register_operand" "")
12354         (zero_extract:SI (match_operand 1 "ext_register_operand" "")
12355                          (match_operand:SI 2 "immediate_operand" "")
12356                          (match_operand:SI 3 "immediate_operand" "")))]
12357   ""
12358 {
12359   /* Handle extractions from %ah et al.  */
12360   if (INTVAL (operands[2]) != 8 || INTVAL (operands[3]) != 8)
12361     FAIL;
12362
12363   /* From mips.md: extract_bit_field doesn't verify that our source
12364      matches the predicate, so check it again here.  */
12365   if (! register_operand (operands[1], VOIDmode))
12366     FAIL;
12367 })
12368
12369 (define_expand "insv"
12370   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "")
12371                          (match_operand:SI 1 "immediate_operand" "")
12372                          (match_operand:SI 2 "immediate_operand" ""))
12373         (match_operand:SI 3 "register_operand" ""))]
12374   ""
12375 {
12376   /* Handle extractions from %ah et al.  */
12377   if (INTVAL (operands[1]) != 8 || INTVAL (operands[2]) != 8)
12378     FAIL;
12379
12380   /* From mips.md: insert_bit_field doesn't verify that our source
12381      matches the predicate, so check it again here.  */
12382   if (! register_operand (operands[0], VOIDmode))
12383     FAIL;
12384 })
12385
12386 ;; %%% bts, btr, btc, bt.
12387 \f
12388 ;; Store-flag instructions.
12389
12390 ;; For all sCOND expanders, also expand the compare or test insn that
12391 ;; generates cc0.  Generate an equality comparison if `seq' or `sne'.
12392
12393 ;; %%% Do the expansion to SImode.  If PII, do things the xor+setcc way
12394 ;; to avoid partial register stalls.  Otherwise do things the setcc+movzx
12395 ;; way, which can later delete the movzx if only QImode is needed.
12396
12397 (define_expand "seq"
12398   [(set (match_operand:SI 0 "register_operand" "")
12399         (eq:SI (reg:CC 17) (const_int 0)))]
12400   ""
12401   "if (ix86_expand_setcc (EQ, operands[0])) DONE; else FAIL;")
12402
12403 (define_expand "sne"
12404   [(set (match_operand:SI 0 "register_operand" "")
12405         (ne:SI (reg:CC 17) (const_int 0)))]
12406   ""
12407   "if (ix86_expand_setcc (NE, operands[0])) DONE; else FAIL;")
12408
12409 (define_expand "sgt"
12410   [(set (match_operand:SI 0 "register_operand" "")
12411         (gt:SI (reg:CC 17) (const_int 0)))]
12412   ""
12413   "if (ix86_expand_setcc (GT, operands[0])) DONE; else FAIL;")
12414
12415 (define_expand "sgtu"
12416   [(set (match_operand:SI 0 "register_operand" "")
12417         (gtu:SI (reg:CC 17) (const_int 0)))]
12418   ""
12419   "if (ix86_expand_setcc (GTU, operands[0])) DONE; else FAIL;")
12420
12421 (define_expand "slt"
12422   [(set (match_operand:SI 0 "register_operand" "")
12423         (lt:SI (reg:CC 17) (const_int 0)))]
12424   ""
12425   "if (ix86_expand_setcc (LT, operands[0])) DONE; else FAIL;")
12426
12427 (define_expand "sltu"
12428   [(set (match_operand:SI 0 "register_operand" "")
12429         (ltu:SI (reg:CC 17) (const_int 0)))]
12430   ""
12431   "if (ix86_expand_setcc (LTU, operands[0])) DONE; else FAIL;")
12432
12433 (define_expand "sge"
12434   [(set (match_operand:SI 0 "register_operand" "")
12435         (ge:SI (reg:CC 17) (const_int 0)))]
12436   ""
12437   "if (ix86_expand_setcc (GE, operands[0])) DONE; else FAIL;")
12438
12439 (define_expand "sgeu"
12440   [(set (match_operand:SI 0 "register_operand" "")
12441         (geu:SI (reg:CC 17) (const_int 0)))]
12442   ""
12443   "if (ix86_expand_setcc (GEU, operands[0])) DONE; else FAIL;")
12444
12445 (define_expand "sle"
12446   [(set (match_operand:SI 0 "register_operand" "")
12447         (le:SI (reg:CC 17) (const_int 0)))]
12448   ""
12449   "if (ix86_expand_setcc (LE, operands[0])) DONE; else FAIL;")
12450
12451 (define_expand "sleu"
12452   [(set (match_operand:SI 0 "register_operand" "")
12453         (leu:SI (reg:CC 17) (const_int 0)))]
12454   ""
12455   "if (ix86_expand_setcc (LEU, operands[0])) DONE; else FAIL;")
12456
12457 (define_expand "sunordered"
12458   [(set (match_operand:SI 0 "register_operand" "")
12459         (unordered:SI (reg:CC 17) (const_int 0)))]
12460   "TARGET_80387 || TARGET_SSE"
12461   "if (ix86_expand_setcc (UNORDERED, operands[0])) DONE; else FAIL;")
12462
12463 (define_expand "sordered"
12464   [(set (match_operand:SI 0 "register_operand" "")
12465         (ordered:SI (reg:CC 17) (const_int 0)))]
12466   "TARGET_80387"
12467   "if (ix86_expand_setcc (ORDERED, operands[0])) DONE; else FAIL;")
12468
12469 (define_expand "suneq"
12470   [(set (match_operand:SI 0 "register_operand" "")
12471         (uneq:SI (reg:CC 17) (const_int 0)))]
12472   "TARGET_80387 || TARGET_SSE"
12473   "if (ix86_expand_setcc (UNEQ, operands[0])) DONE; else FAIL;")
12474
12475 (define_expand "sunge"
12476   [(set (match_operand:SI 0 "register_operand" "")
12477         (unge:SI (reg:CC 17) (const_int 0)))]
12478   "TARGET_80387 || TARGET_SSE"
12479   "if (ix86_expand_setcc (UNGE, operands[0])) DONE; else FAIL;")
12480
12481 (define_expand "sungt"
12482   [(set (match_operand:SI 0 "register_operand" "")
12483         (ungt:SI (reg:CC 17) (const_int 0)))]
12484   "TARGET_80387 || TARGET_SSE"
12485   "if (ix86_expand_setcc (UNGT, operands[0])) DONE; else FAIL;")
12486
12487 (define_expand "sunle"
12488   [(set (match_operand:SI 0 "register_operand" "")
12489         (unle:SI (reg:CC 17) (const_int 0)))]
12490   "TARGET_80387 || TARGET_SSE"
12491   "if (ix86_expand_setcc (UNLE, operands[0])) DONE; else FAIL;")
12492
12493 (define_expand "sunlt"
12494   [(set (match_operand:SI 0 "register_operand" "")
12495         (unlt:SI (reg:CC 17) (const_int 0)))]
12496   "TARGET_80387 || TARGET_SSE"
12497   "if (ix86_expand_setcc (UNLT, operands[0])) DONE; else FAIL;")
12498
12499 (define_expand "sltgt"
12500   [(set (match_operand:SI 0 "register_operand" "")
12501         (ltgt:SI (reg:CC 17) (const_int 0)))]
12502   "TARGET_80387 || TARGET_SSE"
12503   "if (ix86_expand_setcc (LTGT, operands[0])) DONE; else FAIL;")
12504
12505 (define_insn "*setcc_1"
12506   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
12507         (match_operator:QI 1 "ix86_comparison_operator"
12508           [(reg 17) (const_int 0)]))]
12509   ""
12510   "set%C1\t%0"
12511   [(set_attr "type" "setcc")
12512    (set_attr "mode" "QI")])
12513
12514 (define_insn "setcc_2"
12515   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
12516         (match_operator:QI 1 "ix86_comparison_operator"
12517           [(reg 17) (const_int 0)]))]
12518   ""
12519   "set%C1\t%0"
12520   [(set_attr "type" "setcc")
12521    (set_attr "mode" "QI")])
12522
12523 ;; The SSE store flag instructions saves 0 or 0xffffffff to the result.
12524 ;; subsequent logical operations are used to imitate conditional moves.
12525 ;; 0xffffffff is NaN, but not in normalized form, so we can't represent
12526 ;; it directly.  Futher holding this value in pseudo register might bring
12527 ;; problem in implicit normalization in spill code.
12528 ;; So we don't define FLOAT_STORE_FLAG_VALUE and create these
12529 ;; instructions after reload by splitting the conditional move patterns.
12530
12531 (define_insn "*sse_setccsf"
12532   [(set (match_operand:SF 0 "register_operand" "=x")
12533         (match_operator:SF 1 "sse_comparison_operator"
12534           [(match_operand:SF 2 "register_operand" "0")
12535            (match_operand:SF 3 "nonimmediate_operand" "xm")]))]
12536   "TARGET_SSE && reload_completed"
12537   "cmp%D1ss\t{%3, %0|%0, %3}"
12538   [(set_attr "type" "sse")
12539    (set_attr "mode" "SF")])
12540
12541 (define_insn "*sse_setccdf"
12542   [(set (match_operand:DF 0 "register_operand" "=Y")
12543         (match_operator:DF 1 "sse_comparison_operator"
12544           [(match_operand:DF 2 "register_operand" "0")
12545            (match_operand:DF 3 "nonimmediate_operand" "Ym")]))]
12546   "TARGET_SSE2 && reload_completed"
12547   "cmp%D1sd\t{%3, %0|%0, %3}"
12548   [(set_attr "type" "sse")
12549    (set_attr "mode" "DF")])
12550 \f
12551 ;; Basic conditional jump instructions.
12552 ;; We ignore the overflow flag for signed branch instructions.
12553
12554 ;; For all bCOND expanders, also expand the compare or test insn that
12555 ;; generates reg 17.  Generate an equality comparison if `beq' or `bne'.
12556
12557 (define_expand "beq"
12558   [(set (pc)
12559         (if_then_else (match_dup 1)
12560                       (label_ref (match_operand 0 "" ""))
12561                       (pc)))]
12562   ""
12563   "ix86_expand_branch (EQ, operands[0]); DONE;")
12564
12565 (define_expand "bne"
12566   [(set (pc)
12567         (if_then_else (match_dup 1)
12568                       (label_ref (match_operand 0 "" ""))
12569                       (pc)))]
12570   ""
12571   "ix86_expand_branch (NE, operands[0]); DONE;")
12572
12573 (define_expand "bgt"
12574   [(set (pc)
12575         (if_then_else (match_dup 1)
12576                       (label_ref (match_operand 0 "" ""))
12577                       (pc)))]
12578   ""
12579   "ix86_expand_branch (GT, operands[0]); DONE;")
12580
12581 (define_expand "bgtu"
12582   [(set (pc)
12583         (if_then_else (match_dup 1)
12584                       (label_ref (match_operand 0 "" ""))
12585                       (pc)))]
12586   ""
12587   "ix86_expand_branch (GTU, operands[0]); DONE;")
12588
12589 (define_expand "blt"
12590   [(set (pc)
12591         (if_then_else (match_dup 1)
12592                       (label_ref (match_operand 0 "" ""))
12593                       (pc)))]
12594   ""
12595   "ix86_expand_branch (LT, operands[0]); DONE;")
12596
12597 (define_expand "bltu"
12598   [(set (pc)
12599         (if_then_else (match_dup 1)
12600                       (label_ref (match_operand 0 "" ""))
12601                       (pc)))]
12602   ""
12603   "ix86_expand_branch (LTU, operands[0]); DONE;")
12604
12605 (define_expand "bge"
12606   [(set (pc)
12607         (if_then_else (match_dup 1)
12608                       (label_ref (match_operand 0 "" ""))
12609                       (pc)))]
12610   ""
12611   "ix86_expand_branch (GE, operands[0]); DONE;")
12612
12613 (define_expand "bgeu"
12614   [(set (pc)
12615         (if_then_else (match_dup 1)
12616                       (label_ref (match_operand 0 "" ""))
12617                       (pc)))]
12618   ""
12619   "ix86_expand_branch (GEU, operands[0]); DONE;")
12620
12621 (define_expand "ble"
12622   [(set (pc)
12623         (if_then_else (match_dup 1)
12624                       (label_ref (match_operand 0 "" ""))
12625                       (pc)))]
12626   ""
12627   "ix86_expand_branch (LE, operands[0]); DONE;")
12628
12629 (define_expand "bleu"
12630   [(set (pc)
12631         (if_then_else (match_dup 1)
12632                       (label_ref (match_operand 0 "" ""))
12633                       (pc)))]
12634   ""
12635   "ix86_expand_branch (LEU, operands[0]); DONE;")
12636
12637 (define_expand "bunordered"
12638   [(set (pc)
12639         (if_then_else (match_dup 1)
12640                       (label_ref (match_operand 0 "" ""))
12641                       (pc)))]
12642   "TARGET_80387 || TARGET_SSE"
12643   "ix86_expand_branch (UNORDERED, operands[0]); DONE;")
12644
12645 (define_expand "bordered"
12646   [(set (pc)
12647         (if_then_else (match_dup 1)
12648                       (label_ref (match_operand 0 "" ""))
12649                       (pc)))]
12650   "TARGET_80387 || TARGET_SSE"
12651   "ix86_expand_branch (ORDERED, operands[0]); DONE;")
12652
12653 (define_expand "buneq"
12654   [(set (pc)
12655         (if_then_else (match_dup 1)
12656                       (label_ref (match_operand 0 "" ""))
12657                       (pc)))]
12658   "TARGET_80387 || TARGET_SSE"
12659   "ix86_expand_branch (UNEQ, operands[0]); DONE;")
12660
12661 (define_expand "bunge"
12662   [(set (pc)
12663         (if_then_else (match_dup 1)
12664                       (label_ref (match_operand 0 "" ""))
12665                       (pc)))]
12666   "TARGET_80387 || TARGET_SSE"
12667   "ix86_expand_branch (UNGE, operands[0]); DONE;")
12668
12669 (define_expand "bungt"
12670   [(set (pc)
12671         (if_then_else (match_dup 1)
12672                       (label_ref (match_operand 0 "" ""))
12673                       (pc)))]
12674   "TARGET_80387 || TARGET_SSE"
12675   "ix86_expand_branch (UNGT, operands[0]); DONE;")
12676
12677 (define_expand "bunle"
12678   [(set (pc)
12679         (if_then_else (match_dup 1)
12680                       (label_ref (match_operand 0 "" ""))
12681                       (pc)))]
12682   "TARGET_80387 || TARGET_SSE"
12683   "ix86_expand_branch (UNLE, operands[0]); DONE;")
12684
12685 (define_expand "bunlt"
12686   [(set (pc)
12687         (if_then_else (match_dup 1)
12688                       (label_ref (match_operand 0 "" ""))
12689                       (pc)))]
12690   "TARGET_80387 || TARGET_SSE"
12691   "ix86_expand_branch (UNLT, operands[0]); DONE;")
12692
12693 (define_expand "bltgt"
12694   [(set (pc)
12695         (if_then_else (match_dup 1)
12696                       (label_ref (match_operand 0 "" ""))
12697                       (pc)))]
12698   "TARGET_80387 || TARGET_SSE"
12699   "ix86_expand_branch (LTGT, operands[0]); DONE;")
12700
12701 (define_insn "*jcc_1"
12702   [(set (pc)
12703         (if_then_else (match_operator 1 "ix86_comparison_operator"
12704                                       [(reg 17) (const_int 0)])
12705                       (label_ref (match_operand 0 "" ""))
12706                       (pc)))]
12707   ""
12708   "%+j%C1\t%l0"
12709   [(set_attr "type" "ibr")
12710    (set (attr "prefix_0f")
12711            (if_then_else (and (ge (minus (match_dup 0) (pc))
12712                                   (const_int -128))
12713                               (lt (minus (match_dup 0) (pc))
12714                                   (const_int 124)))
12715              (const_int 0)
12716              (const_int 1)))])
12717
12718 (define_insn "*jcc_2"
12719   [(set (pc)
12720         (if_then_else (match_operator 1 "ix86_comparison_operator"
12721                                       [(reg 17) (const_int 0)])
12722                       (pc)
12723                       (label_ref (match_operand 0 "" ""))))]
12724   ""
12725   "%+j%c1\t%l0"
12726   [(set_attr "type" "ibr")
12727    (set (attr "prefix_0f")
12728            (if_then_else (and (ge (minus (match_dup 0) (pc))
12729                                   (const_int -128))
12730                               (lt (minus (match_dup 0) (pc))
12731                                   (const_int 124)))
12732              (const_int 0)
12733              (const_int 1)))])
12734
12735 ;; Define combination compare-and-branch fp compare instructions to use
12736 ;; during early optimization.  Splitting the operation apart early makes
12737 ;; for bad code when we want to reverse the operation.
12738
12739 (define_insn "*fp_jcc_1"
12740   [(set (pc)
12741         (if_then_else (match_operator 0 "comparison_operator"
12742                         [(match_operand 1 "register_operand" "f")
12743                          (match_operand 2 "register_operand" "f")])
12744           (label_ref (match_operand 3 "" ""))
12745           (pc)))
12746    (clobber (reg:CCFP 18))
12747    (clobber (reg:CCFP 17))]
12748   "TARGET_CMOVE && TARGET_80387
12749    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
12750    && FLOAT_MODE_P (GET_MODE (operands[1]))
12751    && GET_MODE (operands[1]) == GET_MODE (operands[2])
12752    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
12753   "#")
12754
12755 (define_insn "*fp_jcc_1_sse"
12756   [(set (pc)
12757         (if_then_else (match_operator 0 "comparison_operator"
12758                         [(match_operand 1 "register_operand" "f#x,x#f")
12759                          (match_operand 2 "nonimmediate_operand" "f#x,xm#f")])
12760           (label_ref (match_operand 3 "" ""))
12761           (pc)))
12762    (clobber (reg:CCFP 18))
12763    (clobber (reg:CCFP 17))]
12764   "TARGET_80387
12765    && SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
12766    && GET_MODE (operands[1]) == GET_MODE (operands[2])
12767    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
12768   "#")
12769
12770 (define_insn "*fp_jcc_1_sse_only"
12771   [(set (pc)
12772         (if_then_else (match_operator 0 "comparison_operator"
12773                         [(match_operand 1 "register_operand" "x")
12774                          (match_operand 2 "nonimmediate_operand" "xm")])
12775           (label_ref (match_operand 3 "" ""))
12776           (pc)))
12777    (clobber (reg:CCFP 18))
12778    (clobber (reg:CCFP 17))]
12779   "SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
12780    && GET_MODE (operands[1]) == GET_MODE (operands[2])
12781    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
12782   "#")
12783
12784 (define_insn "*fp_jcc_2"
12785   [(set (pc)
12786         (if_then_else (match_operator 0 "comparison_operator"
12787                         [(match_operand 1 "register_operand" "f")
12788                          (match_operand 2 "register_operand" "f")])
12789           (pc)
12790           (label_ref (match_operand 3 "" ""))))
12791    (clobber (reg:CCFP 18))
12792    (clobber (reg:CCFP 17))]
12793   "TARGET_CMOVE && TARGET_80387
12794    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
12795    && FLOAT_MODE_P (GET_MODE (operands[1]))
12796    && GET_MODE (operands[1]) == GET_MODE (operands[2])
12797    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
12798   "#")
12799
12800 (define_insn "*fp_jcc_2_sse"
12801   [(set (pc)
12802         (if_then_else (match_operator 0 "comparison_operator"
12803                         [(match_operand 1 "register_operand" "f#x,x#f")
12804                          (match_operand 2 "nonimmediate_operand" "f#x,xm#f")])
12805           (pc)
12806           (label_ref (match_operand 3 "" ""))))
12807    (clobber (reg:CCFP 18))
12808    (clobber (reg:CCFP 17))]
12809   "TARGET_80387
12810    && SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
12811    && GET_MODE (operands[1]) == GET_MODE (operands[2])
12812    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
12813   "#")
12814
12815 (define_insn "*fp_jcc_2_sse_only"
12816   [(set (pc)
12817         (if_then_else (match_operator 0 "comparison_operator"
12818                         [(match_operand 1 "register_operand" "x")
12819                          (match_operand 2 "nonimmediate_operand" "xm")])
12820           (pc)
12821           (label_ref (match_operand 3 "" ""))))
12822    (clobber (reg:CCFP 18))
12823    (clobber (reg:CCFP 17))]
12824   "SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
12825    && GET_MODE (operands[1]) == GET_MODE (operands[2])
12826    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
12827   "#")
12828
12829 (define_insn "*fp_jcc_3"
12830   [(set (pc)
12831         (if_then_else (match_operator 0 "comparison_operator"
12832                         [(match_operand 1 "register_operand" "f")
12833                          (match_operand 2 "nonimmediate_operand" "fm")])
12834           (label_ref (match_operand 3 "" ""))
12835           (pc)))
12836    (clobber (reg:CCFP 18))
12837    (clobber (reg:CCFP 17))
12838    (clobber (match_scratch:HI 4 "=a"))]
12839   "TARGET_80387
12840    && (GET_MODE (operands[1]) == SFmode || GET_MODE (operands[1]) == DFmode)
12841    && GET_MODE (operands[1]) == GET_MODE (operands[2])
12842    && !ix86_use_fcomi_compare (GET_CODE (operands[0]))
12843    && SELECT_CC_MODE (GET_CODE (operands[0]),
12844                       operands[1], operands[2]) == CCFPmode
12845    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
12846   "#")
12847
12848 (define_insn "*fp_jcc_4"
12849   [(set (pc)
12850         (if_then_else (match_operator 0 "comparison_operator"
12851                         [(match_operand 1 "register_operand" "f")
12852                          (match_operand 2 "nonimmediate_operand" "fm")])
12853           (pc)
12854           (label_ref (match_operand 3 "" ""))))
12855    (clobber (reg:CCFP 18))
12856    (clobber (reg:CCFP 17))
12857    (clobber (match_scratch:HI 4 "=a"))]
12858   "TARGET_80387
12859    && (GET_MODE (operands[1]) == SFmode || GET_MODE (operands[1]) == DFmode)
12860    && GET_MODE (operands[1]) == GET_MODE (operands[2])
12861    && !ix86_use_fcomi_compare (GET_CODE (operands[0]))
12862    && SELECT_CC_MODE (GET_CODE (operands[0]),
12863                       operands[1], operands[2]) == CCFPmode
12864    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
12865   "#")
12866
12867 (define_insn "*fp_jcc_5"
12868   [(set (pc)
12869         (if_then_else (match_operator 0 "comparison_operator"
12870                         [(match_operand 1 "register_operand" "f")
12871                          (match_operand 2 "register_operand" "f")])
12872           (label_ref (match_operand 3 "" ""))
12873           (pc)))
12874    (clobber (reg:CCFP 18))
12875    (clobber (reg:CCFP 17))
12876    (clobber (match_scratch:HI 4 "=a"))]
12877   "TARGET_80387
12878    && FLOAT_MODE_P (GET_MODE (operands[1]))
12879    && GET_MODE (operands[1]) == GET_MODE (operands[2])
12880    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
12881   "#")
12882
12883 (define_insn "*fp_jcc_6"
12884   [(set (pc)
12885         (if_then_else (match_operator 0 "comparison_operator"
12886                         [(match_operand 1 "register_operand" "f")
12887                          (match_operand 2 "register_operand" "f")])
12888           (pc)
12889           (label_ref (match_operand 3 "" ""))))
12890    (clobber (reg:CCFP 18))
12891    (clobber (reg:CCFP 17))
12892    (clobber (match_scratch:HI 4 "=a"))]
12893   "TARGET_80387
12894    && FLOAT_MODE_P (GET_MODE (operands[1]))
12895    && GET_MODE (operands[1]) == GET_MODE (operands[2])
12896    && ix86_fp_jump_nontrivial_p (GET_CODE (operands[0]))"
12897   "#")
12898
12899 (define_split
12900   [(set (pc)
12901         (if_then_else (match_operator 0 "comparison_operator"
12902                         [(match_operand 1 "register_operand" "")
12903                          (match_operand 2 "nonimmediate_operand" "")])
12904           (match_operand 3 "" "")
12905           (match_operand 4 "" "")))
12906    (clobber (reg:CCFP 18))
12907    (clobber (reg:CCFP 17))]
12908   "reload_completed"
12909   [(const_int 0)]
12910 {
12911   ix86_split_fp_branch (GET_CODE (operands[0]), operands[1], operands[2],
12912                         operands[3], operands[4], NULL_RTX);
12913   DONE;
12914 })
12915
12916 (define_split
12917   [(set (pc)
12918         (if_then_else (match_operator 0 "comparison_operator"
12919                         [(match_operand 1 "register_operand" "")
12920                          (match_operand 2 "nonimmediate_operand" "")])
12921           (match_operand 3 "" "")
12922           (match_operand 4 "" "")))
12923    (clobber (reg:CCFP 18))
12924    (clobber (reg:CCFP 17))
12925    (clobber (match_scratch:HI 5 "=a"))]
12926   "reload_completed"
12927   [(set (pc)
12928         (if_then_else (match_dup 6)
12929           (match_dup 3)
12930           (match_dup 4)))]
12931 {
12932   ix86_split_fp_branch (GET_CODE (operands[0]), operands[1], operands[2],
12933                         operands[3], operands[4], operands[5]);
12934   DONE;
12935 })
12936 \f
12937 ;; Unconditional and other jump instructions
12938
12939 (define_insn "jump"
12940   [(set (pc)
12941         (label_ref (match_operand 0 "" "")))]
12942   ""
12943   "jmp\t%l0"
12944   [(set_attr "type" "ibr")])
12945
12946 (define_insn "indirect_jump"
12947   [(set (pc) (match_operand:SI 0 "nonimmediate_operand" "rm"))]
12948   ""
12949   "jmp\t%A0"
12950   [(set_attr "type" "ibr")
12951    (set_attr "length_immediate" "0")])
12952
12953 (define_insn "tablejump"
12954   [(set (pc) (match_operand:SI 0 "nonimmediate_operand" "rm"))
12955    (use (label_ref (match_operand 1 "" "")))]
12956   "! flag_pic"
12957   "jmp\t%A0"
12958   [(set_attr "type" "ibr")
12959    (set_attr "length_immediate" "0")])
12960
12961 ;; Implement switch statements when generating PIC code.  Switches are
12962 ;; implemented by `tablejump' when not using -fpic.
12963 ;;
12964 ;; Emit code here to do the range checking and make the index zero based.
12965 ;;
12966 ;; Each entry in the "addr_diff_vec" looks like this as the result of the
12967 ;; two rules below:
12968 ;; 
12969 ;;      .long _GLOBAL_OFFSET_TABLE_+[.-.L2]
12970 ;; 
12971 ;; 1. An expression involving an external reference may only use the
12972 ;;    addition operator, and only with an assembly-time constant.
12973 ;;    The example above satisfies this because ".-.L2" is a constant.
12974 ;; 
12975 ;; 2. The symbol _GLOBAL_OFFSET_TABLE_ is magic, and at link time is
12976 ;;    given the value of "GOT - .", where GOT is the actual address of
12977 ;;    the Global Offset Table.  Therefore, the .long above actually
12978 ;;    stores the value "( GOT - . ) + [ . - .L2 ]", or "GOT - .L2".  The
12979 ;;    expression "GOT - .L2" by itself would generate an error from as(1).
12980 ;; 
12981 ;; The pattern below emits code that looks like this:
12982 ;; 
12983 ;;      movl %ebx,reg
12984 ;;      subl TABLE@GOTOFF(%ebx,index,4),reg
12985 ;;      jmp reg
12986 ;; 
12987 ;; The addr_diff_vec contents may be directly referenced with @GOTOFF, since
12988 ;; the addr_diff_vec is known to be part of this module.
12989 ;; 
12990 ;; The subl above calculates "GOT - (( GOT - . ) + [ . - .L2 ])", which
12991 ;; evaluates to just ".L2".
12992
12993 (define_expand "casesi"
12994   [(set (match_dup 5)
12995         (match_operand:SI 0 "general_operand" ""))
12996    (parallel [(set (match_dup 6)
12997                    (minus:SI (match_dup 5)
12998                              (match_operand:SI 1 "general_operand" "")))
12999               (clobber (reg:CC 17))])
13000    (set (reg:CC 17)
13001         (compare:CC (match_dup 6)
13002                     (match_operand:SI 2 "general_operand" "")))
13003    (set (pc)
13004         (if_then_else (gtu (reg:CC 17)
13005                            (const_int 0))
13006                       (label_ref (match_operand 4 "" ""))
13007                       (pc)))
13008    (parallel
13009      [(set (match_dup 7)
13010            (minus:SI (match_dup 8)
13011              (mem:SI (plus:SI (plus:SI (mult:SI (match_dup 6) (const_int 4))
13012                               (match_dup 8))
13013                      (const (unspec [(label_ref (match_operand 3 "" ""))] 7))))))
13014       (clobber (reg:CC 17))])
13015    (parallel [(set (pc) (match_dup 7))
13016               (use (label_ref (match_dup 3)))])]
13017   "flag_pic"
13018 {
13019   operands[5] = gen_reg_rtx (SImode);
13020   operands[6] = gen_reg_rtx (SImode);
13021   operands[7] = gen_reg_rtx (SImode);
13022   operands[8] = pic_offset_table_rtx;
13023   current_function_uses_pic_offset_table = 1;
13024 })
13025
13026 (define_insn "*tablejump_pic"
13027   [(set (pc) (match_operand:SI 0 "nonimmediate_operand" "rm"))
13028    (use (label_ref (match_operand 1 "" "")))]
13029   ""
13030   "jmp\t%A0"
13031   [(set_attr "type" "ibr")
13032    (set_attr "length_immediate" "0")])
13033 \f
13034 ;; Loop instruction
13035 ;;
13036 ;; This is all complicated by the fact that since this is a jump insn
13037 ;; we must handle our own reloads.
13038
13039 (define_expand "doloop_end"
13040   [(use (match_operand 0 "" ""))        ; loop pseudo
13041    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
13042    (use (match_operand 2 "" ""))        ; max iterations
13043    (use (match_operand 3 "" ""))        ; loop level 
13044    (use (match_operand 4 "" ""))]       ; label
13045   "TARGET_USE_LOOP && !TARGET_64BIT"
13046   "                                 
13047 {
13048   /* Only use cloop on innermost loops.  */
13049   if (INTVAL (operands[3]) > 1)
13050     FAIL;
13051   if (GET_MODE (operands[0]) != SImode)
13052     FAIL;
13053   emit_jump_insn (gen_doloop_end_internal (operands[4], operands[0],
13054                                            operands[0]));
13055   DONE;
13056 }")
13057
13058 (define_insn "doloop_end_internal"
13059   [(set (pc)
13060         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,?*r,?*r")
13061                           (const_int 1))
13062                       (label_ref (match_operand 0 "" ""))
13063                       (pc)))
13064    (set (match_operand:SI 2 "register_operand" "=1,1,*m*r")
13065         (plus:SI (match_dup 1)
13066                  (const_int -1)))
13067    (clobber (match_scratch:SI 3 "=X,X,r"))
13068    (clobber (reg:CC 17))]
13069   "TARGET_USE_LOOP && !TARGET_64BIT"
13070 {
13071   if (which_alternative != 0)
13072     return "#";
13073   if (get_attr_length (insn) == 2)
13074     return "%+loop\t%l0";
13075   else
13076     return "dec{l}\t%1\;%+jne\t%l0";
13077 }
13078   [(set_attr "ppro_uops" "many")
13079    (set (attr "type")
13080         (if_then_else (and (eq_attr "alternative" "0")
13081                            (and (ge (minus (match_dup 0) (pc))
13082                                     (const_int -128))
13083                                 (lt (minus (match_dup 0) (pc))
13084                                     (const_int 124))))
13085                       (const_string "ibr")
13086                       (const_string "multi")))])
13087
13088 (define_split
13089   [(set (pc)
13090         (if_then_else (ne (match_operand:SI 1 "register_operand" "")
13091                           (const_int 1))
13092                       (match_operand 0 "" "")
13093                       (pc)))
13094    (set (match_dup 1)
13095         (plus:SI (match_dup 1)
13096                  (const_int -1)))
13097    (clobber (match_scratch:SI 2 ""))
13098    (clobber (reg:CC 17))]
13099   "TARGET_USE_LOOP && !TARGET_64BIT
13100    && reload_completed
13101    && REGNO (operands[1]) != 2"
13102   [(parallel [(set (reg:CCZ 17)
13103                    (compare:CCZ (plus:SI (match_dup 1) (const_int -1))
13104                                  (const_int 0)))
13105               (set (match_dup 1) (plus:SI (match_dup 1) (const_int -1)))])
13106    (set (pc) (if_then_else (ne (reg:CCZ 17) (const_int 0))
13107                            (match_dup 0)
13108                            (pc)))]
13109   "")
13110   
13111 (define_split
13112   [(set (pc)
13113         (if_then_else (ne (match_operand:SI 1 "register_operand" "")
13114                           (const_int 1))
13115                       (match_operand 0 "" "")
13116                       (pc)))
13117    (set (match_operand:SI 2 "nonimmediate_operand" "")
13118         (plus:SI (match_dup 1)
13119                  (const_int -1)))
13120    (clobber (match_scratch:SI 3 ""))
13121    (clobber (reg:CC 17))]
13122   "TARGET_USE_LOOP && !TARGET_64BIT
13123    && reload_completed
13124    && (! REG_P (operands[2])
13125        || ! rtx_equal_p (operands[1], operands[2]))"
13126   [(set (match_dup 3) (match_dup 1))
13127    (parallel [(set (reg:CCZ 17)
13128                    (compare:CCZ (plus:SI (match_dup 3) (const_int -1))
13129                                 (const_int 0)))
13130               (set (match_dup 3) (plus:SI (match_dup 3) (const_int -1)))])
13131    (set (match_dup 2) (match_dup 3))
13132    (set (pc) (if_then_else (ne (reg:CCZ 17) (const_int 0))
13133                            (match_dup 0)
13134                            (pc)))]
13135   "")
13136 \f
13137 ;; Call instructions.
13138
13139 ;; The predicates normally associated with named expanders are not properly
13140 ;; checked for calls.  This is a bug in the generic code, but it isn't that
13141 ;; easy to fix.  Ignore it for now and be prepared to fix things up.
13142
13143 ;; Call subroutine returning no value.
13144
13145 (define_expand "call_pop"
13146   [(parallel [(call (match_operand:QI 0 "" "")
13147                     (match_operand:SI 1 "" ""))
13148               (set (reg:SI 7)
13149                    (plus:SI (reg:SI 7)
13150                             (match_operand:SI 3 "" "")))])]
13151   "!TARGET_64BIT"
13152 {
13153   if (operands[3] == const0_rtx)
13154     {
13155       emit_insn (gen_call (operands[0], operands[1], constm1_rtx));
13156       DONE;
13157     }
13158   /* Static functions and indirect calls don't need
13159      current_function_uses_pic_offset_table.  */
13160   if (flag_pic
13161       && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF
13162       && ! SYMBOL_REF_FLAG (XEXP (operands[0], 0)))
13163     current_function_uses_pic_offset_table = 1;
13164   if (! call_insn_operand (XEXP (operands[0], 0), Pmode))
13165     XEXP (operands[0], 0) = copy_to_mode_reg (Pmode, XEXP (operands[0], 0));
13166   if (TARGET_64BIT)
13167     abort();
13168 })
13169
13170 (define_insn "*call_pop_0"
13171   [(call (mem:QI (match_operand:SI 0 "constant_call_address_operand" ""))
13172          (match_operand:SI 1 "" ""))
13173    (set (reg:SI 7) (plus:SI (reg:SI 7)
13174                             (match_operand:SI 2 "immediate_operand" "")))]
13175   "!TARGET_64BIT"
13176 {
13177   if (SIBLING_CALL_P (insn))
13178     return "jmp\t%P0";
13179   else
13180     return "call\t%P0";
13181 }
13182   [(set_attr "type" "call")])
13183   
13184 (define_insn "*call_pop_1"
13185   [(call (mem:QI (match_operand:SI 0 "call_insn_operand" "rsm"))
13186          (match_operand:SI 1 "" ""))
13187    (set (reg:SI 7) (plus:SI (reg:SI 7)
13188                             (match_operand:SI 2 "immediate_operand" "i")))]
13189   "!TARGET_64BIT"
13190 {
13191   if (constant_call_address_operand (operands[0], Pmode))
13192     {
13193       if (SIBLING_CALL_P (insn))
13194         return "jmp\t%P0";
13195       else
13196         return "call\t%P0";
13197     }
13198   if (SIBLING_CALL_P (insn))
13199     return "jmp\t%A0";
13200   else
13201     return "call\t%A0";
13202 }
13203   [(set_attr "type" "call")])
13204
13205 (define_expand "call"
13206   [(call (match_operand:QI 0 "" "")
13207          (match_operand 1 "" ""))
13208    (use (match_operand 2 "" ""))]
13209   ;; Operand 1 not used on the i386.
13210   ""
13211 {
13212   rtx insn;
13213   /* Static functions and indirect calls don't need
13214      current_function_uses_pic_offset_table.  */
13215   if (flag_pic
13216       && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF
13217       && ! SYMBOL_REF_FLAG (XEXP (operands[0], 0)))
13218     current_function_uses_pic_offset_table = 1;
13219
13220   if (! call_insn_operand (XEXP (operands[0], 0), Pmode))
13221     XEXP (operands[0], 0) = copy_to_mode_reg (Pmode, XEXP (operands[0], 0));
13222   if (TARGET_64BIT && INTVAL (operands[2]) >= 0)
13223     {
13224       rtx reg = gen_rtx_REG (QImode, 0);
13225       emit_move_insn (reg, operands[2]);
13226       insn = emit_call_insn (gen_call_exp (operands[0], operands[1]));
13227       use_reg (&CALL_INSN_FUNCTION_USAGE (insn), reg);
13228       DONE;
13229     }
13230    insn = emit_call_insn (gen_call_exp (operands[0], operands[1]));
13231    DONE;
13232 })
13233
13234 (define_expand "call_exp"
13235   [(call (match_operand:QI 0 "" "")
13236          (match_operand 1 "" ""))]
13237   ""
13238   "")
13239
13240 (define_insn "*call_0"
13241   [(call (mem:QI (match_operand 0 "constant_call_address_operand" ""))
13242          (match_operand 1 "" ""))]
13243   ""
13244 {
13245   if (SIBLING_CALL_P (insn))
13246     return "jmp\t%P0";
13247   else
13248     return "call\t%P0";
13249 }
13250   [(set_attr "type" "call")])
13251
13252 (define_insn "*call_1"
13253   [(call (mem:QI (match_operand:SI 0 "call_insn_operand" "rsm"))
13254          (match_operand 1 "" ""))]
13255   "!TARGET_64BIT"
13256 {
13257   if (constant_call_address_operand (operands[0], QImode))
13258     {
13259       if (SIBLING_CALL_P (insn))
13260         return "jmp\t%P0";
13261       else
13262         return "call\t%P0";
13263     }
13264   if (SIBLING_CALL_P (insn))
13265     return "jmp\t%A0";
13266   else
13267     return "call\t%A0";
13268 }
13269   [(set_attr "type" "call")])
13270
13271 (define_insn "*call_1_rex64"
13272   [(call (mem:QI (match_operand:DI 0 "call_insn_operand" "rsm"))
13273          (match_operand 1 "" ""))]
13274   "TARGET_64BIT"
13275 {
13276   if (constant_call_address_operand (operands[0], QImode))
13277     {
13278       if (SIBLING_CALL_P (insn))
13279         return "jmp\t%P0";
13280       else
13281         return "call\t%P0";
13282     }
13283   if (SIBLING_CALL_P (insn))
13284     return "jmp\t%A0";
13285   else
13286     return "call\t%A0";
13287 }
13288   [(set_attr "type" "call")])
13289
13290 ;; Call subroutine, returning value in operand 0
13291 ;; (which must be a hard register).
13292
13293 (define_expand "call_value_pop"
13294   [(parallel [(set (match_operand 0 "" "")
13295                    (call (match_operand:QI 1 "" "")
13296                          (match_operand:SI 2 "" "")))
13297               (set (reg:SI 7)
13298                    (plus:SI (reg:SI 7)
13299                             (match_operand:SI 4 "" "")))])]
13300   "!TARGET_64BIT"
13301 {
13302   if (operands[4] == const0_rtx)
13303     {
13304       emit_insn (gen_call_value (operands[0], operands[1], operands[2],
13305                                  constm1_rtx));
13306       DONE;
13307     }
13308   /* Static functions and indirect calls don't need
13309      current_function_uses_pic_offset_table.  */
13310   if (flag_pic
13311       && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
13312       && ! SYMBOL_REF_FLAG (XEXP (operands[1], 0)))
13313     current_function_uses_pic_offset_table = 1;
13314   if (! call_insn_operand (XEXP (operands[1], 0), Pmode))
13315     XEXP (operands[1], 0) = copy_to_mode_reg (Pmode, XEXP (operands[1], 0));
13316 })
13317
13318 (define_expand "call_value"
13319   [(set (match_operand 0 "" "")
13320         (call (match_operand:QI 1 "" "")
13321               (match_operand:SI 2 "" "")))
13322    (use (match_operand:SI 3 "" ""))]
13323   ;; Operand 2 not used on the i386.
13324   ""
13325 {
13326   rtx insn;
13327   /* Static functions and indirect calls don't need
13328      current_function_uses_pic_offset_table.  */
13329   if (flag_pic
13330       && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
13331       && ! SYMBOL_REF_FLAG (XEXP (operands[1], 0)))
13332     current_function_uses_pic_offset_table = 1;
13333   if (! call_insn_operand (XEXP (operands[1], 0), Pmode))
13334     XEXP (operands[1], 0) = copy_to_mode_reg (Pmode, XEXP (operands[1], 0));
13335   if (TARGET_64BIT && INTVAL (operands[3]) >= 0)
13336     {
13337       rtx reg = gen_rtx_REG (QImode, 0);
13338       emit_move_insn (reg, operands[3]);
13339       insn = emit_call_insn (gen_call_value_exp (operands[0], operands[1],
13340                                                  operands[2]));
13341       use_reg (&CALL_INSN_FUNCTION_USAGE (insn), reg);
13342       DONE;
13343     }
13344   insn = emit_call_insn (gen_call_value_exp (operands[0], operands[1],
13345                                              operands[2]));
13346   DONE;
13347 })
13348
13349 (define_expand "call_value_exp"
13350   [(set (match_operand 0 "" "")
13351         (call (match_operand:QI 1 "" "")
13352               (match_operand:SI 2 "" "")))]
13353   ""
13354   "")
13355
13356 ;; Call subroutine returning any type.
13357
13358 (define_expand "untyped_call"
13359   [(parallel [(call (match_operand 0 "" "")
13360                     (const_int 0))
13361               (match_operand 1 "" "")
13362               (match_operand 2 "" "")])]
13363   ""
13364 {
13365   int i;
13366
13367   /* In order to give reg-stack an easier job in validating two
13368      coprocessor registers as containing a possible return value,
13369      simply pretend the untyped call returns a complex long double
13370      value.  */
13371
13372   emit_call_insn (TARGET_80387
13373                   ? gen_call_value (gen_rtx_REG (XCmode, FIRST_FLOAT_REG),
13374                                     operands[0], const0_rtx,
13375                                     GEN_INT (SSE_REGPARM_MAX - 1))
13376                   : gen_call (operands[0], const0_rtx,
13377                               GEN_INT (SSE_REGPARM_MAX - 1)));
13378
13379   for (i = 0; i < XVECLEN (operands[2], 0); i++)
13380     {
13381       rtx set = XVECEXP (operands[2], 0, i);
13382       emit_move_insn (SET_DEST (set), SET_SRC (set));
13383     }
13384
13385   /* The optimizer does not know that the call sets the function value
13386      registers we stored in the result block.  We avoid problems by
13387      claiming that all hard registers are used and clobbered at this
13388      point.  */
13389   emit_insn (gen_blockage ());
13390
13391   DONE;
13392 })
13393 \f
13394 ;; Prologue and epilogue instructions
13395
13396 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
13397 ;; all of memory.  This blocks insns from being moved across this point.
13398
13399 (define_insn "blockage"
13400   [(unspec_volatile [(const_int 0)] 0)]
13401   ""
13402   ""
13403   [(set_attr "length" "0")])
13404
13405 ;; Insn emitted into the body of a function to return from a function.
13406 ;; This is only done if the function's epilogue is known to be simple.
13407 ;; See comments for ix86_can_use_return_insn_p in i386.c.
13408
13409 (define_expand "return"
13410   [(return)]
13411   "ix86_can_use_return_insn_p ()"
13412 {
13413   if (current_function_pops_args)
13414     {
13415       rtx popc = GEN_INT (current_function_pops_args);
13416       emit_jump_insn (gen_return_pop_internal (popc));
13417       DONE;
13418     }
13419 })
13420
13421 (define_insn "return_internal"
13422   [(return)]
13423   "reload_completed"
13424   "ret"
13425   [(set_attr "length" "1")
13426    (set_attr "length_immediate" "0")
13427    (set_attr "modrm" "0")])
13428
13429 (define_insn "return_pop_internal"
13430   [(return)
13431    (use (match_operand:SI 0 "const_int_operand" ""))]
13432   "reload_completed"
13433   "ret\t%0"
13434   [(set_attr "length" "3")
13435    (set_attr "length_immediate" "2")
13436    (set_attr "modrm" "0")])
13437
13438 (define_insn "return_indirect_internal"
13439   [(return)
13440    (use (match_operand:SI 0 "register_operand" "r"))]
13441   "reload_completed"
13442   "jmp\t%A0"
13443   [(set_attr "type" "ibr")
13444    (set_attr "length_immediate" "0")])
13445
13446 (define_insn "nop"
13447   [(const_int 0)]
13448   ""
13449   "nop"
13450   [(set_attr "length" "1")
13451    (set_attr "length_immediate" "0")
13452    (set_attr "modrm" "0")
13453    (set_attr "ppro_uops" "one")])
13454
13455 (define_expand "prologue"
13456   [(const_int 1)]
13457   ""
13458   "ix86_expand_prologue (); DONE;")
13459
13460 (define_insn "prologue_set_got"
13461   [(set (match_operand:SI 0 "register_operand" "=r")
13462         (unspec_volatile:SI
13463          [(plus:SI (match_dup 0)
13464                    (plus:SI (match_operand:SI 1 "symbolic_operand" "")
13465                             (minus:SI (pc) (match_operand 2 "" ""))))] 1))
13466    (clobber (reg:CC 17))]
13467   "!TARGET_64BIT"
13468 {
13469   if (GET_CODE (operands[2]) == LABEL_REF)
13470      operands[2] = XEXP (operands[2], 0);
13471   if (TARGET_DEEP_BRANCH_PREDICTION) 
13472     return "add{l}\t{%1, %0|%0, %1}";
13473   else  
13474     return "add{l}\t{%1+[.-%X2], %0|%0, %a1+(.-%X2)}";
13475 }
13476   [(set_attr "type" "alu")
13477    ; Since this insn may have two constant operands, we must set the
13478    ; length manually.
13479    (set_attr "length_immediate" "4")
13480    (set_attr "mode" "SI")])
13481
13482 (define_insn "prologue_get_pc"
13483   [(set (match_operand:SI 0 "register_operand" "=r")
13484     (unspec_volatile:SI [(plus:SI (pc) (match_operand 1 "" ""))] 2))]
13485   "!TARGET_64BIT"
13486 {
13487   if (GET_CODE (operands[1]) == LABEL_REF)
13488     operands[1] = XEXP (operands[1], 0);
13489   output_asm_insn ("call\t%X1", operands);
13490   if (! TARGET_DEEP_BRANCH_PREDICTION)
13491     {
13492       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L",
13493                                  CODE_LABEL_NUMBER (operands[1]));
13494     }
13495   RET;
13496 }
13497   [(set_attr "type" "multi")])
13498
13499 (define_expand "epilogue"
13500   [(const_int 1)]
13501   ""
13502   "ix86_expand_epilogue (1); DONE;")
13503
13504 (define_expand "sibcall_epilogue"
13505   [(const_int 1)]
13506   ""
13507   "ix86_expand_epilogue (0); DONE;")
13508
13509 (define_expand "eh_return"
13510   [(use (match_operand 0 "register_operand" ""))
13511    (use (match_operand 1 "register_operand" ""))]
13512   ""
13513 {
13514   rtx tmp, sa = operands[0], ra = operands[1];
13515
13516   /* Tricky bit: we write the address of the handler to which we will
13517      be returning into someone else's stack frame, one word below the
13518      stack address we wish to restore.  */
13519   tmp = gen_rtx_PLUS (Pmode, arg_pointer_rtx, sa);
13520   tmp = plus_constant (tmp, -UNITS_PER_WORD);
13521   tmp = gen_rtx_MEM (Pmode, tmp);
13522   emit_move_insn (tmp, ra);
13523
13524   if (Pmode == SImode)
13525     emit_insn (gen_eh_return_si (sa));
13526   else
13527     emit_insn (gen_eh_return_di (sa));
13528   emit_barrier ();
13529   DONE;
13530 })
13531
13532 (define_insn_and_split "eh_return_si"
13533   [(unspec_volatile [(match_operand:SI 0 "register_operand" "c")] 13)]
13534   ""
13535   "#"
13536   "reload_completed"
13537   [(const_int 1)]
13538   "ix86_expand_epilogue (2); DONE;")
13539
13540 (define_insn_and_split "eh_return_di"
13541   [(unspec_volatile [(match_operand:DI 0 "register_operand" "c")] 13)]
13542   ""
13543   "#"
13544   "reload_completed"
13545   [(const_int 1)]
13546   "ix86_expand_epilogue (2); DONE;")
13547
13548 (define_insn "leave"
13549   [(set (reg:SI 7) (reg:SI 6))
13550    (set (reg:SI 6) (mem:SI (pre_dec:SI (reg:SI 7))))
13551    (clobber (mem:BLK (scratch)))]
13552   "!TARGET_64BIT"
13553   "leave"
13554   [(set_attr "length_immediate" "0")
13555    (set_attr "length" "1")
13556    (set_attr "modrm" "0")
13557    (set_attr "modrm" "0")
13558    (set_attr "athlon_decode" "vector")
13559    (set_attr "ppro_uops" "few")])
13560
13561 (define_insn "leave_rex64"
13562   [(set (reg:DI 7) (reg:DI 6))
13563    (set (reg:DI 6) (mem:DI (pre_dec:DI (reg:DI 7))))
13564    (clobber (mem:BLK (scratch)))]
13565   "TARGET_64BIT"
13566   "leave"
13567   [(set_attr "length_immediate" "0")
13568    (set_attr "length" "1")
13569    (set_attr "modrm" "0")
13570    (set_attr "modrm" "0")
13571    (set_attr "athlon_decode" "vector")
13572    (set_attr "ppro_uops" "few")])
13573 \f
13574 (define_expand "ffssi2"
13575   [(set (match_operand:SI 0 "nonimmediate_operand" "") 
13576         (ffs:SI (match_operand:SI 1 "general_operand" "")))]
13577   ""
13578 {
13579   rtx out = gen_reg_rtx (SImode), tmp = gen_reg_rtx (SImode);
13580   rtx in = operands[1];
13581
13582   if (TARGET_CMOVE)
13583     {
13584       emit_move_insn (tmp, constm1_rtx);
13585       emit_insn (gen_ffssi_1 (out, in));
13586       emit_insn (gen_rtx_SET (VOIDmode, out,
13587                   gen_rtx_IF_THEN_ELSE (SImode, 
13588                     gen_rtx_EQ (VOIDmode, gen_rtx_REG (CCZmode, FLAGS_REG),
13589                                 const0_rtx),
13590                     tmp,
13591                     out)));
13592       emit_insn (gen_addsi3 (out, out, const1_rtx));
13593       emit_move_insn (operands[0], out);
13594     }
13595
13596   /* Pentium bsf instruction is extremly slow.  The following code is
13597      recommended by the Intel Optimizing Manual as a reasonable replacement:
13598            TEST    EAX,EAX
13599            JZ      SHORT BS2
13600            XOR     ECX,ECX
13601            MOV     DWORD PTR [TEMP+4],ECX
13602            SUB     ECX,EAX
13603            AND     EAX,ECX
13604            MOV     DWORD PTR [TEMP],EAX
13605            FILD    QWORD PTR [TEMP]
13606            FSTP    QWORD PTR [TEMP]
13607            WAIT    ; WAIT only needed for compatibility with
13608                    ; earlier processors
13609            MOV     ECX, DWORD PTR [TEMP+4]
13610            SHR     ECX,20
13611            SUB     ECX,3FFH
13612            TEST    EAX,EAX       ; clear zero flag
13613        BS2:
13614      Following piece of code expand ffs to similar beast.
13615        */
13616
13617   else if (TARGET_PENTIUM && !optimize_size && TARGET_80387)
13618     {
13619       rtx label = gen_label_rtx ();
13620       rtx lo, hi;
13621       rtx mem = assign_386_stack_local (DImode, 0);
13622       rtx fptmp = gen_reg_rtx (DFmode);
13623       split_di (&mem, 1, &lo, &hi);
13624
13625       emit_move_insn (out, const0_rtx);
13626
13627       emit_cmp_and_jump_insns (in, const0_rtx, EQ, 0, SImode, 1, 0, label);
13628
13629       emit_move_insn (hi, out);
13630       emit_insn (gen_subsi3 (out, out, in));
13631       emit_insn (gen_andsi3 (out, out, in));
13632       emit_move_insn (lo, out);
13633       emit_insn (gen_floatdidf2 (fptmp,mem));
13634       emit_move_insn (gen_rtx_MEM (DFmode, XEXP (mem, 0)), fptmp);
13635       emit_move_insn (out, hi);
13636       emit_insn (gen_lshrsi3 (out, out, GEN_INT (20)));
13637       emit_insn (gen_subsi3 (out, out, GEN_INT (0x3ff - 1)));
13638
13639       emit_label (label);
13640       LABEL_NUSES (label) = 1;
13641
13642       emit_move_insn (operands[0], out);
13643     }
13644   else
13645     {
13646       emit_move_insn (tmp, const0_rtx);
13647       emit_insn (gen_ffssi_1 (out, in));
13648       emit_insn (gen_rtx_SET (VOIDmode, 
13649                   gen_rtx_STRICT_LOW_PART (VOIDmode, gen_lowpart (QImode, tmp)),
13650                   gen_rtx_EQ (QImode, gen_rtx_REG (CCZmode, FLAGS_REG),
13651                               const0_rtx)));
13652       emit_insn (gen_negsi2 (tmp, tmp));
13653       emit_insn (gen_iorsi3 (out, out, tmp));
13654       emit_insn (gen_addsi3 (out, out, const1_rtx));
13655       emit_move_insn (operands[0], out);
13656     }
13657   DONE;  
13658 })
13659
13660 (define_insn "ffssi_1"
13661   [(set (reg:CCZ 17)
13662         (compare:CCZ (match_operand:SI 1 "nonimmediate_operand" "rm")
13663                      (const_int 0)))
13664    (set (match_operand:SI 0 "register_operand" "=r")
13665         (unspec:SI [(match_dup 1)] 5))]
13666   ""
13667   "bsf{l}\t{%1, %0|%0, %1}"
13668   [(set_attr "prefix_0f" "1")
13669    (set_attr "ppro_uops" "few")])
13670
13671 ;; ffshi2 is not useful -- 4 word prefix ops are needed, which is larger
13672 ;; and slower than the two-byte movzx insn needed to do the work in SImode.
13673 \f
13674 ;; These patterns match the binary 387 instructions for addM3, subM3,
13675 ;; mulM3 and divM3.  There are three patterns for each of DFmode and
13676 ;; SFmode.  The first is the normal insn, the second the same insn but
13677 ;; with one operand a conversion, and the third the same insn but with
13678 ;; the other operand a conversion.  The conversion may be SFmode or
13679 ;; SImode if the target mode DFmode, but only SImode if the target mode
13680 ;; is SFmode.
13681
13682 ;; Gcc is slightly more smart about handling normal two address instructions
13683 ;; so use special patterns for add and mull.
13684 (define_insn "*fop_sf_comm"
13685   [(set (match_operand:SF 0 "register_operand" "=f#x,x#f")
13686         (match_operator:SF 3 "binary_fp_operator"
13687                         [(match_operand:SF 1 "register_operand" "%0,0")
13688                          (match_operand:SF 2 "nonimmediate_operand" "fm#x,xm#f")]))]
13689   "TARGET_80387 && (!TARGET_SSE || TARGET_MIX_SSE_I387)
13690    && GET_RTX_CLASS (GET_CODE (operands[3])) == 'c'"
13691   "* return output_387_binary_op (insn, operands);"
13692   [(set (attr "type") 
13693         (if_then_else (eq_attr "alternative" "1")
13694            (const_string "sse")
13695            (if_then_else (match_operand:SF 3 "mult_operator" "") 
13696               (const_string "fmul")
13697               (const_string "fop"))))
13698    (set_attr "mode" "SF")])
13699
13700 (define_insn "*fop_sf_comm_sse"
13701   [(set (match_operand:SF 0 "register_operand" "=x")
13702         (match_operator:SF 3 "binary_fp_operator"
13703                         [(match_operand:SF 1 "register_operand" "%0")
13704                          (match_operand:SF 2 "nonimmediate_operand" "xm")]))]
13705   "TARGET_SSE && GET_RTX_CLASS (GET_CODE (operands[3])) == 'c'"
13706   "* return output_387_binary_op (insn, operands);"
13707   [(set_attr "type" "sse")
13708    (set_attr "mode" "SF")])
13709
13710 (define_insn "*fop_df_comm"
13711   [(set (match_operand:DF 0 "register_operand" "=f#Y,Y#f")
13712         (match_operator:DF 3 "binary_fp_operator"
13713                         [(match_operand:DF 1 "register_operand" "%0,0")
13714                          (match_operand:DF 2 "nonimmediate_operand" "fm#Y,Ym#f")]))]
13715   "TARGET_80387 && (!TARGET_SSE2 || TARGET_MIX_SSE_I387)
13716    && GET_RTX_CLASS (GET_CODE (operands[3])) == 'c'"
13717   "* return output_387_binary_op (insn, operands);"
13718   [(set (attr "type") 
13719         (if_then_else (eq_attr "alternative" "1")
13720            (const_string "sse")
13721            (if_then_else (match_operand:SF 3 "mult_operator" "") 
13722               (const_string "fmul")
13723               (const_string "fop"))))
13724    (set_attr "mode" "DF")])
13725
13726 (define_insn "*fop_df_comm_sse"
13727   [(set (match_operand:DF 0 "register_operand" "=Y")
13728         (match_operator:DF 3 "binary_fp_operator"
13729                         [(match_operand:DF 1 "register_operand" "%0")
13730                          (match_operand:DF 2 "nonimmediate_operand" "Ym")]))]
13731   "TARGET_SSE2
13732    && GET_RTX_CLASS (GET_CODE (operands[3])) == 'c'"
13733   "* return output_387_binary_op (insn, operands);"
13734   [(set_attr "type" "sse")
13735    (set_attr "mode" "DF")])
13736
13737 (define_insn "*fop_xf_comm"
13738   [(set (match_operand:XF 0 "register_operand" "=f")
13739         (match_operator:XF 3 "binary_fp_operator"
13740                         [(match_operand:XF 1 "register_operand" "%0")
13741                          (match_operand:XF 2 "register_operand" "f")]))]
13742   "TARGET_80387 && !TARGET_64BIT
13743    && GET_RTX_CLASS (GET_CODE (operands[3])) == 'c'"
13744   "* return output_387_binary_op (insn, operands);"
13745   [(set (attr "type") 
13746         (if_then_else (match_operand:XF 3 "mult_operator" "") 
13747            (const_string "fmul")
13748            (const_string "fop")))
13749    (set_attr "mode" "XF")])
13750
13751 (define_insn "*fop_tf_comm"
13752   [(set (match_operand:TF 0 "register_operand" "=f")
13753         (match_operator:TF 3 "binary_fp_operator"
13754                         [(match_operand:TF 1 "register_operand" "%0")
13755                          (match_operand:TF 2 "register_operand" "f")]))]
13756   "TARGET_80387 && GET_RTX_CLASS (GET_CODE (operands[3])) == 'c'"
13757   "* return output_387_binary_op (insn, operands);"
13758   [(set (attr "type") 
13759         (if_then_else (match_operand:TF 3 "mult_operator" "") 
13760            (const_string "fmul")
13761            (const_string "fop")))
13762    (set_attr "mode" "XF")])
13763
13764 (define_insn "*fop_sf_1"
13765   [(set (match_operand:SF 0 "register_operand" "=f,f,x")
13766         (match_operator:SF 3 "binary_fp_operator"
13767                         [(match_operand:SF 1 "nonimmediate_operand" "0,fm,0")
13768                          (match_operand:SF 2 "nonimmediate_operand" "fm,0,xm#f")]))]
13769   "TARGET_80387 && (!TARGET_SSE || TARGET_MIX_SSE_I387)
13770    && GET_RTX_CLASS (GET_CODE (operands[3])) != 'c'
13771    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
13772   "* return output_387_binary_op (insn, operands);"
13773   [(set (attr "type") 
13774         (cond [(eq_attr "alternative" "2")
13775                  (const_string "sse")
13776                (match_operand:SF 3 "mult_operator" "") 
13777                  (const_string "fmul")
13778                (match_operand:SF 3 "div_operator" "") 
13779                  (const_string "fdiv")
13780               ]
13781               (const_string "fop")))
13782    (set_attr "mode" "SF")])
13783
13784 (define_insn "*fop_sf_1_sse"
13785   [(set (match_operand:SF 0 "register_operand" "=x")
13786         (match_operator:SF 3 "binary_fp_operator"
13787                         [(match_operand:SF 1 "register_operand" "0")
13788                          (match_operand:SF 2 "nonimmediate_operand" "xm")]))]
13789   "TARGET_SSE
13790    && GET_RTX_CLASS (GET_CODE (operands[3])) != 'c'"
13791   "* return output_387_binary_op (insn, operands);"
13792   [(set_attr "type" "sse")
13793    (set_attr "mode" "SF")])
13794
13795 ;; ??? Add SSE splitters for these!
13796 (define_insn "*fop_sf_2"
13797   [(set (match_operand:SF 0 "register_operand" "=f,f")
13798         (match_operator:SF 3 "binary_fp_operator"
13799           [(float:SF (match_operand:SI 1 "nonimmediate_operand" "m,?r"))
13800            (match_operand:SF 2 "register_operand" "0,0")]))]
13801   "TARGET_80387 && TARGET_USE_FIOP && !TARGET_SSE"
13802   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
13803   [(set (attr "type") 
13804         (cond [(match_operand:SF 3 "mult_operator" "") 
13805                  (const_string "fmul")
13806                (match_operand:SF 3 "div_operator" "") 
13807                  (const_string "fdiv")
13808               ]
13809               (const_string "fop")))
13810    (set_attr "fp_int_src" "true")
13811    (set_attr "ppro_uops" "many")
13812    (set_attr "mode" "SI")])
13813
13814 (define_insn "*fop_sf_3"
13815   [(set (match_operand:SF 0 "register_operand" "=f,f")
13816         (match_operator:SF 3 "binary_fp_operator"
13817           [(match_operand:SF 1 "register_operand" "0,0")
13818            (float:SF (match_operand:SI 2 "nonimmediate_operand" "m,?r"))]))]
13819   "TARGET_80387 && TARGET_USE_FIOP && !TARGET_SSE"
13820   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
13821   [(set (attr "type") 
13822         (cond [(match_operand:SF 3 "mult_operator" "") 
13823                  (const_string "fmul")
13824                (match_operand:SF 3 "div_operator" "") 
13825                  (const_string "fdiv")
13826               ]
13827               (const_string "fop")))
13828    (set_attr "fp_int_src" "true")
13829    (set_attr "ppro_uops" "many")
13830    (set_attr "mode" "SI")])
13831
13832 (define_insn "*fop_df_1"
13833   [(set (match_operand:DF 0 "register_operand" "=f#Y,f#Y,Y#f")
13834         (match_operator:DF 3 "binary_fp_operator"
13835                         [(match_operand:DF 1 "nonimmediate_operand" "0,fm,0")
13836                          (match_operand:DF 2 "nonimmediate_operand" "fm,0,Ym#f")]))]
13837   "TARGET_80387 && (!TARGET_SSE2 || TARGET_MIX_SSE_I387)
13838    && GET_RTX_CLASS (GET_CODE (operands[3])) != 'c'
13839    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
13840   "* return output_387_binary_op (insn, operands);"
13841   [(set (attr "type") 
13842         (cond [(eq_attr "alternative" "2")
13843                  (const_string "sse")
13844                (match_operand:DF 3 "mult_operator" "") 
13845                  (const_string "fmul")
13846                (match_operand:DF 3 "div_operator" "") 
13847                  (const_string "fdiv")
13848               ]
13849               (const_string "fop")))
13850    (set_attr "mode" "DF")])
13851
13852 (define_insn "*fop_df_1_sse"
13853   [(set (match_operand:DF 0 "register_operand" "=Y")
13854         (match_operator:DF 3 "binary_fp_operator"
13855                         [(match_operand:DF 1 "register_operand" "0")
13856                          (match_operand:DF 2 "nonimmediate_operand" "Ym")]))]
13857   "TARGET_SSE
13858    && GET_RTX_CLASS (GET_CODE (operands[3])) != 'c'"
13859   "* return output_387_binary_op (insn, operands);"
13860   [(set_attr "type" "sse")])
13861
13862 ;; ??? Add SSE splitters for these!
13863 (define_insn "*fop_df_2"
13864   [(set (match_operand:DF 0 "register_operand" "=f,f")
13865         (match_operator:DF 3 "binary_fp_operator"
13866            [(float:DF (match_operand:SI 1 "nonimmediate_operand" "m,?r"))
13867             (match_operand:DF 2 "register_operand" "0,0")]))]
13868   "TARGET_80387 && TARGET_USE_FIOP && !TARGET_SSE2"
13869   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
13870   [(set (attr "type") 
13871         (cond [(match_operand:DF 3 "mult_operator" "") 
13872                  (const_string "fmul")
13873                (match_operand:DF 3 "div_operator" "") 
13874                  (const_string "fdiv")
13875               ]
13876               (const_string "fop")))
13877    (set_attr "fp_int_src" "true")
13878    (set_attr "ppro_uops" "many")
13879    (set_attr "mode" "SI")])
13880
13881 (define_insn "*fop_df_3"
13882   [(set (match_operand:DF 0 "register_operand" "=f,f")
13883         (match_operator:DF 3 "binary_fp_operator"
13884            [(match_operand:DF 1 "register_operand" "0,0")
13885             (float:DF (match_operand:SI 2 "nonimmediate_operand" "m,?r"))]))]
13886   "TARGET_80387 && TARGET_USE_FIOP && !TARGET_SSE2"
13887   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
13888   [(set (attr "type") 
13889         (cond [(match_operand:DF 3 "mult_operator" "") 
13890                  (const_string "fmul")
13891                (match_operand:DF 3 "div_operator" "") 
13892                  (const_string "fdiv")
13893               ]
13894               (const_string "fop")))
13895    (set_attr "fp_int_src" "true")
13896    (set_attr "ppro_uops" "many")
13897    (set_attr "mode" "SI")])
13898
13899 (define_insn "*fop_df_4"
13900   [(set (match_operand:DF 0 "register_operand" "=f,f")
13901         (match_operator:DF 3 "binary_fp_operator"
13902            [(float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "fm,0"))
13903             (match_operand:DF 2 "register_operand" "0,f")]))]
13904   "TARGET_80387
13905    && (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != MEM)"
13906   "* return output_387_binary_op (insn, operands);"
13907   [(set (attr "type") 
13908         (cond [(match_operand:DF 3 "mult_operator" "") 
13909                  (const_string "fmul")
13910                (match_operand:DF 3 "div_operator" "") 
13911                  (const_string "fdiv")
13912               ]
13913               (const_string "fop")))
13914    (set_attr "mode" "SF")])
13915
13916 (define_insn "*fop_df_5"
13917   [(set (match_operand:DF 0 "register_operand" "=f,f")
13918         (match_operator:DF 3 "binary_fp_operator"
13919           [(match_operand:DF 1 "register_operand" "0,f")
13920            (float_extend:DF
13921             (match_operand:SF 2 "nonimmediate_operand" "fm,0"))]))]
13922   "TARGET_80387 && !TARGET_SSE2"
13923   "* return output_387_binary_op (insn, operands);"
13924   [(set (attr "type") 
13925         (cond [(match_operand:DF 3 "mult_operator" "") 
13926                  (const_string "fmul")
13927                (match_operand:DF 3 "div_operator" "") 
13928                  (const_string "fdiv")
13929               ]
13930               (const_string "fop")))
13931    (set_attr "mode" "SF")])
13932
13933 (define_insn "*fop_xf_1"
13934   [(set (match_operand:XF 0 "register_operand" "=f,f")
13935         (match_operator:XF 3 "binary_fp_operator"
13936                         [(match_operand:XF 1 "register_operand" "0,f")
13937                          (match_operand:XF 2 "register_operand" "f,0")]))]
13938   "TARGET_80387 && !TARGET_64BIT
13939    && GET_RTX_CLASS (GET_CODE (operands[3])) != 'c'"
13940   "* return output_387_binary_op (insn, operands);"
13941   [(set (attr "type") 
13942         (cond [(match_operand:XF 3 "mult_operator" "") 
13943                  (const_string "fmul")
13944                (match_operand:XF 3 "div_operator" "") 
13945                  (const_string "fdiv")
13946               ]
13947               (const_string "fop")))
13948    (set_attr "mode" "XF")])
13949
13950 (define_insn "*fop_tf_1"
13951   [(set (match_operand:TF 0 "register_operand" "=f,f")
13952         (match_operator:TF 3 "binary_fp_operator"
13953                         [(match_operand:TF 1 "register_operand" "0,f")
13954                          (match_operand:TF 2 "register_operand" "f,0")]))]
13955   "TARGET_80387
13956    && GET_RTX_CLASS (GET_CODE (operands[3])) != 'c'"
13957   "* return output_387_binary_op (insn, operands);"
13958   [(set (attr "type") 
13959         (cond [(match_operand:TF 3 "mult_operator" "") 
13960                  (const_string "fmul")
13961                (match_operand:TF 3 "div_operator" "") 
13962                  (const_string "fdiv")
13963               ]
13964               (const_string "fop")))
13965    (set_attr "mode" "XF")])
13966
13967 (define_insn "*fop_xf_2"
13968   [(set (match_operand:XF 0 "register_operand" "=f,f")
13969         (match_operator:XF 3 "binary_fp_operator"
13970            [(float:XF (match_operand:SI 1 "nonimmediate_operand" "m,?r"))
13971             (match_operand:XF 2 "register_operand" "0,0")]))]
13972   "TARGET_80387 && !TARGET_64BIT && TARGET_USE_FIOP"
13973   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
13974   [(set (attr "type") 
13975         (cond [(match_operand:XF 3 "mult_operator" "") 
13976                  (const_string "fmul")
13977                (match_operand:XF 3 "div_operator" "") 
13978                  (const_string "fdiv")
13979               ]
13980               (const_string "fop")))
13981    (set_attr "fp_int_src" "true")
13982    (set_attr "mode" "SI")
13983    (set_attr "ppro_uops" "many")])
13984
13985 (define_insn "*fop_tf_2"
13986   [(set (match_operand:TF 0 "register_operand" "=f,f")
13987         (match_operator:TF 3 "binary_fp_operator"
13988            [(float:TF (match_operand:SI 1 "nonimmediate_operand" "m,?r"))
13989             (match_operand:TF 2 "register_operand" "0,0")]))]
13990   "TARGET_80387 && TARGET_USE_FIOP"
13991   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
13992   [(set (attr "type") 
13993         (cond [(match_operand:TF 3 "mult_operator" "") 
13994                  (const_string "fmul")
13995                (match_operand:TF 3 "div_operator" "") 
13996                  (const_string "fdiv")
13997               ]
13998               (const_string "fop")))
13999    (set_attr "fp_int_src" "true")
14000    (set_attr "mode" "SI")
14001    (set_attr "ppro_uops" "many")])
14002
14003 (define_insn "*fop_xf_3"
14004   [(set (match_operand:XF 0 "register_operand" "=f,f")
14005         (match_operator:XF 3 "binary_fp_operator"
14006           [(match_operand:XF 1 "register_operand" "0,0")
14007            (float:XF (match_operand:SI 2 "nonimmediate_operand" "m,?r"))]))]
14008   "TARGET_80387 && !TARGET_64BIT && TARGET_USE_FIOP"
14009   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
14010   [(set (attr "type") 
14011         (cond [(match_operand:XF 3 "mult_operator" "") 
14012                  (const_string "fmul")
14013                (match_operand:XF 3 "div_operator" "") 
14014                  (const_string "fdiv")
14015               ]
14016               (const_string "fop")))
14017    (set_attr "fp_int_src" "true")
14018    (set_attr "mode" "SI")
14019    (set_attr "ppro_uops" "many")])
14020
14021 (define_insn "*fop_tf_3"
14022   [(set (match_operand:TF 0 "register_operand" "=f,f")
14023         (match_operator:TF 3 "binary_fp_operator"
14024           [(match_operand:TF 1 "register_operand" "0,0")
14025            (float:TF (match_operand:SI 2 "nonimmediate_operand" "m,?r"))]))]
14026   "TARGET_80387 && TARGET_USE_FIOP"
14027   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
14028   [(set (attr "type") 
14029         (cond [(match_operand:TF 3 "mult_operator" "") 
14030                  (const_string "fmul")
14031                (match_operand:TF 3 "div_operator" "") 
14032                  (const_string "fdiv")
14033               ]
14034               (const_string "fop")))
14035    (set_attr "fp_int_src" "true")
14036    (set_attr "mode" "SI")
14037    (set_attr "ppro_uops" "many")])
14038
14039 (define_insn "*fop_xf_4"
14040   [(set (match_operand:XF 0 "register_operand" "=f,f")
14041         (match_operator:XF 3 "binary_fp_operator"
14042            [(float_extend:XF (match_operand:SF 1 "nonimmediate_operand" "fm,0"))
14043             (match_operand:XF 2 "register_operand" "0,f")]))]
14044   "TARGET_80387 && !TARGET_64BIT"
14045   "* return output_387_binary_op (insn, operands);"
14046   [(set (attr "type") 
14047         (cond [(match_operand:XF 3 "mult_operator" "") 
14048                  (const_string "fmul")
14049                (match_operand:XF 3 "div_operator" "") 
14050                  (const_string "fdiv")
14051               ]
14052               (const_string "fop")))
14053    (set_attr "mode" "SF")])
14054
14055 (define_insn "*fop_tf_4"
14056   [(set (match_operand:TF 0 "register_operand" "=f,f")
14057         (match_operator:TF 3 "binary_fp_operator"
14058            [(float_extend:TF (match_operand:SF 1 "nonimmediate_operand" "fm,0"))
14059             (match_operand:TF 2 "register_operand" "0,f")]))]
14060   "TARGET_80387"
14061   "* return output_387_binary_op (insn, operands);"
14062   [(set (attr "type") 
14063         (cond [(match_operand:TF 3 "mult_operator" "") 
14064                  (const_string "fmul")
14065                (match_operand:TF 3 "div_operator" "") 
14066                  (const_string "fdiv")
14067               ]
14068               (const_string "fop")))
14069    (set_attr "mode" "SF")])
14070
14071 (define_insn "*fop_xf_5"
14072   [(set (match_operand:XF 0 "register_operand" "=f,f")
14073         (match_operator:XF 3 "binary_fp_operator"
14074           [(match_operand:XF 1 "register_operand" "0,f")
14075            (float_extend:XF
14076             (match_operand:SF 2 "nonimmediate_operand" "fm,0"))]))]
14077   "TARGET_80387 && !TARGET_64BIT"
14078   "* return output_387_binary_op (insn, operands);"
14079   [(set (attr "type") 
14080         (cond [(match_operand:XF 3 "mult_operator" "") 
14081                  (const_string "fmul")
14082                (match_operand:XF 3 "div_operator" "") 
14083                  (const_string "fdiv")
14084               ]
14085               (const_string "fop")))
14086    (set_attr "mode" "SF")])
14087
14088 (define_insn "*fop_tf_5"
14089   [(set (match_operand:TF 0 "register_operand" "=f,f")
14090         (match_operator:TF 3 "binary_fp_operator"
14091           [(match_operand:TF 1 "register_operand" "0,f")
14092            (float_extend:TF
14093             (match_operand:SF 2 "nonimmediate_operand" "fm,0"))]))]
14094   "TARGET_80387"
14095   "* return output_387_binary_op (insn, operands);"
14096   [(set (attr "type") 
14097         (cond [(match_operand:TF 3 "mult_operator" "") 
14098                  (const_string "fmul")
14099                (match_operand:TF 3 "div_operator" "") 
14100                  (const_string "fdiv")
14101               ]
14102               (const_string "fop")))
14103    (set_attr "mode" "SF")])
14104
14105 (define_insn "*fop_xf_6"
14106   [(set (match_operand:XF 0 "register_operand" "=f,f")
14107         (match_operator:XF 3 "binary_fp_operator"
14108            [(float_extend:XF (match_operand:DF 1 "nonimmediate_operand" "fm,0"))
14109             (match_operand:XF 2 "register_operand" "0,f")]))]
14110   "TARGET_80387 && !TARGET_64BIT"
14111   "* return output_387_binary_op (insn, operands);"
14112   [(set (attr "type") 
14113         (cond [(match_operand:XF 3 "mult_operator" "") 
14114                  (const_string "fmul")
14115                (match_operand:XF 3 "div_operator" "") 
14116                  (const_string "fdiv")
14117               ]
14118               (const_string "fop")))
14119    (set_attr "mode" "DF")])
14120
14121 (define_insn "*fop_tf_6"
14122   [(set (match_operand:TF 0 "register_operand" "=f,f")
14123         (match_operator:TF 3 "binary_fp_operator"
14124            [(float_extend:TF (match_operand:DF 1 "nonimmediate_operand" "fm,0"))
14125             (match_operand:TF 2 "register_operand" "0,f")]))]
14126   "TARGET_80387"
14127   "* return output_387_binary_op (insn, operands);"
14128   [(set (attr "type") 
14129         (cond [(match_operand:TF 3 "mult_operator" "") 
14130                  (const_string "fmul")
14131                (match_operand:TF 3 "div_operator" "") 
14132                  (const_string "fdiv")
14133               ]
14134               (const_string "fop")))
14135    (set_attr "mode" "DF")])
14136
14137 (define_insn "*fop_xf_7"
14138   [(set (match_operand:XF 0 "register_operand" "=f,f")
14139         (match_operator:XF 3 "binary_fp_operator"
14140           [(match_operand:XF 1 "register_operand" "0,f")
14141            (float_extend:XF
14142             (match_operand:DF 2 "nonimmediate_operand" "fm,0"))]))]
14143   "TARGET_80387 && !TARGET_64BIT"
14144   "* return output_387_binary_op (insn, operands);"
14145   [(set (attr "type") 
14146         (cond [(match_operand:XF 3 "mult_operator" "") 
14147                  (const_string "fmul")
14148                (match_operand:XF 3 "div_operator" "") 
14149                  (const_string "fdiv")
14150               ]
14151               (const_string "fop")))
14152    (set_attr "mode" "DF")])
14153
14154 (define_insn "*fop_tf_7"
14155   [(set (match_operand:TF 0 "register_operand" "=f,f")
14156         (match_operator:TF 3 "binary_fp_operator"
14157           [(match_operand:TF 1 "register_operand" "0,f")
14158            (float_extend:TF
14159             (match_operand:DF 2 "nonimmediate_operand" "fm,0"))]))]
14160   "TARGET_80387"
14161   "* return output_387_binary_op (insn, operands);"
14162   [(set (attr "type") 
14163         (cond [(match_operand:TF 3 "mult_operator" "") 
14164                  (const_string "fmul")
14165                (match_operand:TF 3 "div_operator" "") 
14166                  (const_string "fdiv")
14167               ]
14168               (const_string "fop")))
14169    (set_attr "mode" "DF")])
14170
14171 (define_split
14172   [(set (match_operand 0 "register_operand" "")
14173         (match_operator 3 "binary_fp_operator"
14174            [(float (match_operand:SI 1 "register_operand" ""))
14175             (match_operand 2 "register_operand" "")]))]
14176   "TARGET_80387 && reload_completed
14177    && FLOAT_MODE_P (GET_MODE (operands[0]))"
14178   [(const_int 0)]
14179
14180   operands[4] = ix86_force_to_memory (GET_MODE (operands[1]), operands[1]);
14181   operands[4] = gen_rtx_FLOAT (GET_MODE (operands[0]), operands[4]);
14182   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
14183                           gen_rtx_fmt_ee (GET_CODE (operands[3]),
14184                                           GET_MODE (operands[3]),
14185                                           operands[4],
14186                                           operands[2])));
14187   ix86_free_from_memory (GET_MODE (operands[1]));
14188   DONE;
14189 })
14190
14191 (define_split
14192   [(set (match_operand 0 "register_operand" "")
14193         (match_operator 3 "binary_fp_operator"
14194            [(match_operand 1 "register_operand" "")
14195             (float (match_operand:SI 2 "register_operand" ""))]))]
14196   "TARGET_80387 && reload_completed
14197    && FLOAT_MODE_P (GET_MODE (operands[0]))"
14198   [(const_int 0)]
14199 {
14200   operands[4] = ix86_force_to_memory (GET_MODE (operands[2]), operands[2]);
14201   operands[4] = gen_rtx_FLOAT (GET_MODE (operands[0]), operands[4]);
14202   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
14203                           gen_rtx_fmt_ee (GET_CODE (operands[3]),
14204                                           GET_MODE (operands[3]),
14205                                           operands[1],
14206                                           operands[4])));
14207   ix86_free_from_memory (GET_MODE (operands[2]));
14208   DONE;
14209 })
14210 \f
14211 ;; FPU special functions.
14212
14213 (define_expand "sqrtsf2"
14214   [(set (match_operand:SF 0 "register_operand" "")
14215         (sqrt:SF (match_operand:SF 1 "nonimmediate_operand" "")))]
14216   "(! TARGET_NO_FANCY_MATH_387 && TARGET_80387) || TARGET_SSE"
14217 {
14218   if (!TARGET_SSE)
14219     operands[1] = force_reg (SFmode, operands[1]);
14220 })
14221
14222 (define_insn "sqrtsf2_1"
14223   [(set (match_operand:SF 0 "register_operand" "=f#x,x#f")
14224         (sqrt:SF (match_operand:SF 1 "nonimmediate_operand" "0#x,xm#f")))]
14225   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387
14226    && (TARGET_SSE && TARGET_MIX_SSE_I387)"
14227   "@
14228    fsqrt
14229    sqrtss\t{%1, %0|%0, %1}"
14230   [(set_attr "type" "fpspc,sse")
14231    (set_attr "mode" "SF,SF")
14232    (set_attr "athlon_decode" "direct,*")])
14233
14234 (define_insn "sqrtsf2_1_sse_only"
14235   [(set (match_operand:SF 0 "register_operand" "=x")
14236         (sqrt:SF (match_operand:SF 1 "nonimmediate_operand" "xm")))]
14237   "TARGET_SSE && (!TARGET_80387 || !TARGET_MIX_SSE_I387)"
14238   "sqrtss\t{%1, %0|%0, %1}"
14239   [(set_attr "type" "sse")
14240    (set_attr "mode" "SF")
14241    (set_attr "athlon_decode" "*")])
14242
14243 (define_insn "sqrtsf2_i387"
14244   [(set (match_operand:SF 0 "register_operand" "=f")
14245         (sqrt:SF (match_operand:SF 1 "register_operand" "0")))]
14246   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387
14247    && (!TARGET_SSE && !TARGET_MIX_SSE_I387)"
14248   "fsqrt"
14249   [(set_attr "type" "fpspc")
14250    (set_attr "mode" "SF")
14251    (set_attr "athlon_decode" "direct")])
14252
14253 (define_expand "sqrtdf2"
14254   [(set (match_operand:DF 0 "register_operand" "")
14255         (sqrt:DF (match_operand:DF 1 "nonimmediate_operand" "")))]
14256   "(! TARGET_NO_FANCY_MATH_387 && TARGET_80387) || TARGET_SSE2"
14257 {
14258   if (!TARGET_SSE2)
14259     operands[1] = force_reg (DFmode, operands[1]);
14260 })
14261
14262 (define_insn "sqrtdf2_1"
14263   [(set (match_operand:DF 0 "register_operand" "=f#Y,Y#f")
14264         (sqrt:DF (match_operand:DF 1 "nonimmediate_operand" "0#Y,Ym#f")))]
14265   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387
14266    && (TARGET_SSE2 && TARGET_MIX_SSE_I387)"
14267   "@
14268    fsqrt
14269    sqrtsd\t{%1, %0|%0, %1}"
14270   [(set_attr "type" "fpspc,sse")
14271    (set_attr "mode" "DF,DF")
14272    (set_attr "athlon_decode" "direct,*")])
14273
14274 (define_insn "sqrtdf2_1_sse_only"
14275   [(set (match_operand:DF 0 "register_operand" "=Y")
14276         (sqrt:DF (match_operand:DF 1 "nonimmediate_operand" "Ym")))]
14277   "TARGET_SSE2 && (!TARGET_80387 || !TARGET_MIX_SSE_I387)"
14278   "sqrtsd\t{%1, %0|%0, %1}"
14279   [(set_attr "type" "sse")
14280    (set_attr "mode" "DF")
14281    (set_attr "athlon_decode" "*")])
14282
14283 (define_insn "sqrtdf2_i387"
14284   [(set (match_operand:DF 0 "register_operand" "=f")
14285         (sqrt:DF (match_operand:DF 1 "register_operand" "0")))]
14286   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387
14287    && (!TARGET_SSE2 && !TARGET_MIX_SSE_I387)"
14288   "fsqrt"
14289   [(set_attr "type" "fpspc")
14290    (set_attr "mode" "DF")
14291    (set_attr "athlon_decode" "direct")])
14292
14293 (define_insn "*sqrtextendsfdf2"
14294   [(set (match_operand:DF 0 "register_operand" "=f")
14295         (sqrt:DF (float_extend:DF
14296                   (match_operand:SF 1 "register_operand" "0"))))]
14297   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 && !TARGET_SSE2"
14298   "fsqrt"
14299   [(set_attr "type" "fpspc")
14300    (set_attr "mode" "DF")
14301    (set_attr "athlon_decode" "direct")])
14302
14303 (define_insn "sqrtxf2"
14304   [(set (match_operand:XF 0 "register_operand" "=f")
14305         (sqrt:XF (match_operand:XF 1 "register_operand" "0")))]
14306   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 && !TARGET_64BIT
14307    && (TARGET_IEEE_FP || flag_unsafe_math_optimizations) "
14308   "fsqrt"
14309   [(set_attr "type" "fpspc")
14310    (set_attr "mode" "XF")
14311    (set_attr "athlon_decode" "direct")])
14312
14313 (define_insn "sqrttf2"
14314   [(set (match_operand:TF 0 "register_operand" "=f")
14315         (sqrt:TF (match_operand:TF 1 "register_operand" "0")))]
14316   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 
14317    && (TARGET_IEEE_FP || flag_unsafe_math_optimizations) "
14318   "fsqrt"
14319   [(set_attr "type" "fpspc")
14320    (set_attr "mode" "XF")
14321    (set_attr "athlon_decode" "direct")])
14322
14323 (define_insn "*sqrtextenddfxf2"
14324   [(set (match_operand:XF 0 "register_operand" "=f")
14325         (sqrt:XF (float_extend:XF
14326                   (match_operand:DF 1 "register_operand" "0"))))]
14327   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 && !TARGET_64BIT"
14328   "fsqrt"
14329   [(set_attr "type" "fpspc")
14330    (set_attr "mode" "XF")
14331    (set_attr "athlon_decode" "direct")])
14332
14333 (define_insn "*sqrtextenddftf2"
14334   [(set (match_operand:TF 0 "register_operand" "=f")
14335         (sqrt:TF (float_extend:TF
14336                   (match_operand:DF 1 "register_operand" "0"))))]
14337   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387"
14338   "fsqrt"
14339   [(set_attr "type" "fpspc")
14340    (set_attr "mode" "XF")
14341    (set_attr "athlon_decode" "direct")])
14342
14343 (define_insn "*sqrtextendsfxf2"
14344   [(set (match_operand:XF 0 "register_operand" "=f")
14345         (sqrt:XF (float_extend:XF
14346                   (match_operand:SF 1 "register_operand" "0"))))]
14347   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 && !TARGET_64BIT"
14348   "fsqrt"
14349   [(set_attr "type" "fpspc")
14350    (set_attr "mode" "XF")
14351    (set_attr "athlon_decode" "direct")])
14352
14353 (define_insn "*sqrtextendsftf2"
14354   [(set (match_operand:TF 0 "register_operand" "=f")
14355         (sqrt:TF (float_extend:TF
14356                   (match_operand:SF 1 "register_operand" "0"))))]
14357   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387"
14358   "fsqrt"
14359   [(set_attr "type" "fpspc")
14360    (set_attr "mode" "XF")
14361    (set_attr "athlon_decode" "direct")])
14362
14363 (define_insn "sindf2"
14364   [(set (match_operand:DF 0 "register_operand" "=f")
14365         (unspec:DF [(match_operand:DF 1 "register_operand" "0")] 1))]
14366   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 
14367    && flag_unsafe_math_optimizations"
14368   "fsin"
14369   [(set_attr "type" "fpspc")
14370    (set_attr "mode" "DF")])
14371
14372 (define_insn "sinsf2"
14373   [(set (match_operand:SF 0 "register_operand" "=f")
14374         (unspec:SF [(match_operand:SF 1 "register_operand" "0")] 1))]
14375   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 
14376    && flag_unsafe_math_optimizations"
14377   "fsin"
14378   [(set_attr "type" "fpspc")
14379    (set_attr "mode" "SF")])
14380
14381 (define_insn "*sinextendsfdf2"
14382   [(set (match_operand:DF 0 "register_operand" "=f")
14383         (unspec:DF [(float_extend:DF
14384                      (match_operand:SF 1 "register_operand" "0"))] 1))]
14385   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 
14386    && flag_unsafe_math_optimizations"
14387   "fsin"
14388   [(set_attr "type" "fpspc")
14389    (set_attr "mode" "DF")])
14390
14391 (define_insn "sinxf2"
14392   [(set (match_operand:XF 0 "register_operand" "=f")
14393         (unspec:XF [(match_operand:XF 1 "register_operand" "0")] 1))]
14394   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 && !TARGET_64BIT
14395    && flag_unsafe_math_optimizations"
14396   "fsin"
14397   [(set_attr "type" "fpspc")
14398    (set_attr "mode" "XF")])
14399
14400 (define_insn "sintf2"
14401   [(set (match_operand:TF 0 "register_operand" "=f")
14402         (unspec:TF [(match_operand:TF 1 "register_operand" "0")] 1))]
14403   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 
14404    && flag_unsafe_math_optimizations"
14405   "fsin"
14406   [(set_attr "type" "fpspc")
14407    (set_attr "mode" "XF")])
14408
14409 (define_insn "cosdf2"
14410   [(set (match_operand:DF 0 "register_operand" "=f")
14411         (unspec:DF [(match_operand:DF 1 "register_operand" "0")] 2))]
14412   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 
14413    && flag_unsafe_math_optimizations"
14414   "fcos"
14415   [(set_attr "type" "fpspc")
14416    (set_attr "mode" "DF")])
14417
14418 (define_insn "cossf2"
14419   [(set (match_operand:SF 0 "register_operand" "=f")
14420         (unspec:SF [(match_operand:SF 1 "register_operand" "0")] 2))]
14421   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 
14422    && flag_unsafe_math_optimizations"
14423   "fcos"
14424   [(set_attr "type" "fpspc")
14425    (set_attr "mode" "SF")])
14426
14427 (define_insn "*cosextendsfdf2"
14428   [(set (match_operand:DF 0 "register_operand" "=f")
14429         (unspec:DF [(float_extend:DF
14430                      (match_operand:SF 1 "register_operand" "0"))] 2))]
14431   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 
14432    && flag_unsafe_math_optimizations"
14433   "fcos"
14434   [(set_attr "type" "fpspc")
14435    (set_attr "mode" "DF")])
14436
14437 (define_insn "cosxf2"
14438   [(set (match_operand:XF 0 "register_operand" "=f")
14439         (unspec:XF [(match_operand:XF 1 "register_operand" "0")] 2))]
14440   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387
14441    && flag_unsafe_math_optimizations"
14442   "fcos"
14443   [(set_attr "type" "fpspc")
14444    (set_attr "mode" "XF")])
14445
14446 (define_insn "costf2"
14447   [(set (match_operand:TF 0 "register_operand" "=f")
14448         (unspec:TF [(match_operand:TF 1 "register_operand" "0")] 2))]
14449   "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 
14450    && flag_unsafe_math_optimizations"
14451   "fcos"
14452   [(set_attr "type" "fpspc")
14453    (set_attr "mode" "XF")])
14454 \f
14455 ;; Block operation instructions
14456
14457 (define_insn "cld"
14458  [(set (reg:SI 19) (const_int 0))]
14459  ""
14460  "cld"
14461   [(set_attr "type" "cld")])
14462
14463 (define_expand "movstrsi"
14464   [(use (match_operand:BLK 0 "memory_operand" ""))
14465    (use (match_operand:BLK 1 "memory_operand" ""))
14466    (use (match_operand:SI 2 "nonmemory_operand" ""))
14467    (use (match_operand:SI 3 "const_int_operand" ""))]
14468   ""
14469 {
14470  if (ix86_expand_movstr (operands[0], operands[1], operands[2], operands[3]))
14471    DONE;
14472  else
14473    FAIL;
14474 })
14475
14476 (define_expand "movstrdi"
14477   [(use (match_operand:BLK 0 "memory_operand" ""))
14478    (use (match_operand:BLK 1 "memory_operand" ""))
14479    (use (match_operand:DI 2 "nonmemory_operand" ""))
14480    (use (match_operand:DI 3 "const_int_operand" ""))]
14481   "TARGET_64BIT"
14482 {
14483  if (ix86_expand_movstr (operands[0], operands[1], operands[2], operands[3]))
14484    DONE;
14485  else
14486    FAIL;
14487 })
14488
14489 ;; Most CPUs don't like single string operations
14490 ;; Handle this case here to simplify previous expander.
14491
14492 (define_expand "strmovdi_rex64"
14493   [(set (match_dup 2)
14494         (mem:DI (match_operand:DI 1 "register_operand" "")))
14495    (set (mem:DI (match_operand:DI 0 "register_operand" ""))
14496         (match_dup 2))
14497    (parallel [(set (match_dup 0) (plus:DI (match_dup 0) (const_int 8)))
14498               (clobber (reg:CC 17))])
14499    (parallel [(set (match_dup 1) (plus:DI (match_dup 1) (const_int 8)))
14500               (clobber (reg:CC 17))])]
14501   "TARGET_64BIT"
14502 {
14503   if (TARGET_SINGLE_STRINGOP || optimize_size)
14504     {
14505       emit_insn (gen_strmovdi_rex_1 (operands[0], operands[1], operands[0],
14506                                      operands[1]));
14507       DONE;
14508     }
14509   else 
14510     operands[2] = gen_reg_rtx (DImode);
14511 })
14512
14513
14514 (define_expand "strmovsi"
14515   [(set (match_dup 2)
14516         (mem:SI (match_operand:SI 1 "register_operand" "")))
14517    (set (mem:SI (match_operand:SI 0 "register_operand" ""))
14518         (match_dup 2))
14519    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 4)))
14520               (clobber (reg:CC 17))])
14521    (parallel [(set (match_dup 1) (plus:SI (match_dup 1) (const_int 4)))
14522               (clobber (reg:CC 17))])]
14523   ""
14524 {
14525   if (TARGET_64BIT)
14526     {
14527       emit_insn (gen_strmovsi_rex64 (operands[0], operands[1]));
14528       DONE;
14529     }
14530   if (TARGET_SINGLE_STRINGOP || optimize_size)
14531     {
14532       emit_insn (gen_strmovsi_1 (operands[0], operands[1], operands[0],
14533                                 operands[1]));
14534       DONE;
14535     }
14536   else 
14537     operands[2] = gen_reg_rtx (SImode);
14538 })
14539
14540 (define_expand "strmovsi_rex64"
14541   [(set (match_dup 2)
14542         (mem:SI (match_operand:DI 1 "register_operand" "")))
14543    (set (mem:SI (match_operand:DI 0 "register_operand" ""))
14544         (match_dup 2))
14545    (parallel [(set (match_dup 0) (plus:DI (match_dup 0) (const_int 4)))
14546               (clobber (reg:CC 17))])
14547    (parallel [(set (match_dup 1) (plus:DI (match_dup 1) (const_int 4)))
14548               (clobber (reg:CC 17))])]
14549   "TARGET_64BIT"
14550 {
14551   if (TARGET_SINGLE_STRINGOP || optimize_size)
14552     {
14553       emit_insn (gen_strmovsi_rex_1 (operands[0], operands[1], operands[0],
14554                                      operands[1]));
14555       DONE;
14556     }
14557   else 
14558     operands[2] = gen_reg_rtx (SImode);
14559 })
14560
14561 (define_expand "strmovhi"
14562   [(set (match_dup 2)
14563         (mem:HI (match_operand:SI 1 "register_operand" "")))
14564    (set (mem:HI (match_operand:SI 0 "register_operand" ""))
14565         (match_dup 2))
14566    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 2)))
14567               (clobber (reg:CC 17))])
14568    (parallel [(set (match_dup 1) (plus:SI (match_dup 1) (const_int 2)))
14569               (clobber (reg:CC 17))])]
14570   ""
14571 {
14572   if (TARGET_64BIT)
14573     {
14574       emit_insn (gen_strmovhi_rex64 (operands[0], operands[1]));
14575       DONE;
14576     }
14577   if (TARGET_SINGLE_STRINGOP || optimize_size)
14578     {
14579       emit_insn (gen_strmovhi_1 (operands[0], operands[1], operands[0],
14580                                 operands[1]));
14581       DONE;
14582     }
14583   else 
14584     operands[2] = gen_reg_rtx (HImode);
14585 })
14586
14587 (define_expand "strmovhi_rex64"
14588   [(set (match_dup 2)
14589         (mem:HI (match_operand:DI 1 "register_operand" "")))
14590    (set (mem:HI (match_operand:DI 0 "register_operand" ""))
14591         (match_dup 2))
14592    (parallel [(set (match_dup 0) (plus:DI (match_dup 0) (const_int 2)))
14593               (clobber (reg:CC 17))])
14594    (parallel [(set (match_dup 1) (plus:DI (match_dup 1) (const_int 2)))
14595               (clobber (reg:CC 17))])]
14596   "TARGET_64BIT"
14597 {
14598   if (TARGET_SINGLE_STRINGOP || optimize_size)
14599     {
14600       emit_insn (gen_strmovhi_rex_1 (operands[0], operands[1], operands[0],
14601                                      operands[1]));
14602       DONE;
14603     }
14604   else 
14605     operands[2] = gen_reg_rtx (HImode);
14606 })
14607
14608 (define_expand "strmovqi"
14609   [(set (match_dup 2)
14610         (mem:QI (match_operand:SI 1 "register_operand" "")))
14611    (set (mem:QI (match_operand:SI 0 "register_operand" ""))
14612         (match_dup 2))
14613    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 1)))
14614               (clobber (reg:CC 17))])
14615    (parallel [(set (match_dup 1) (plus:SI (match_dup 1) (const_int 1)))
14616               (clobber (reg:CC 17))])]
14617   ""
14618 {
14619   if (TARGET_64BIT)
14620     {
14621       emit_insn (gen_strmovqi_rex64 (operands[0], operands[1]));
14622       DONE;
14623     }
14624   if (TARGET_SINGLE_STRINGOP || optimize_size)
14625     {
14626       emit_insn (gen_strmovqi_1 (operands[0], operands[1], operands[0],
14627                                 operands[1]));
14628       DONE;
14629     }
14630   else 
14631     operands[2] = gen_reg_rtx (QImode);
14632 })
14633
14634 (define_expand "strmovqi_rex64"
14635   [(set (match_dup 2)
14636         (mem:QI (match_operand:DI 1 "register_operand" "")))
14637    (set (mem:QI (match_operand:DI 0 "register_operand" ""))
14638         (match_dup 2))
14639    (parallel [(set (match_dup 0) (plus:DI (match_dup 0) (const_int 1)))
14640               (clobber (reg:CC 17))])
14641    (parallel [(set (match_dup 1) (plus:DI (match_dup 1) (const_int 1)))
14642               (clobber (reg:CC 17))])]
14643   "!TARGET_64BIT"
14644 {
14645   if (TARGET_SINGLE_STRINGOP || optimize_size)
14646     {
14647       emit_insn (gen_strmovqi_rex_1 (operands[0], operands[1], operands[0],
14648                                      operands[1]));
14649       DONE;
14650     }
14651   else 
14652     operands[2] = gen_reg_rtx (QImode);
14653 })
14654
14655 (define_insn "strmovdi_rex_1"
14656   [(set (mem:DI (match_operand:DI 2 "register_operand" "0"))
14657         (mem:DI (match_operand:DI 3 "register_operand" "1")))
14658    (set (match_operand:DI 0 "register_operand" "=D")
14659         (plus:DI (match_dup 2)
14660                  (const_int 8)))
14661    (set (match_operand:DI 1 "register_operand" "=S")
14662         (plus:DI (match_dup 3)
14663                  (const_int 8)))
14664    (use (reg:SI 19))]
14665   "TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
14666   "movsq"
14667   [(set_attr "type" "str")
14668    (set_attr "mode" "DI")
14669    (set_attr "memory" "both")])
14670
14671 (define_insn "strmovsi_1"
14672   [(set (mem:SI (match_operand:SI 2 "register_operand" "0"))
14673         (mem:SI (match_operand:SI 3 "register_operand" "1")))
14674    (set (match_operand:SI 0 "register_operand" "=D")
14675         (plus:SI (match_dup 2)
14676                  (const_int 4)))
14677    (set (match_operand:SI 1 "register_operand" "=S")
14678         (plus:SI (match_dup 3)
14679                  (const_int 4)))
14680    (use (reg:SI 19))]
14681   "!TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
14682   "{movsl|movsd}"
14683   [(set_attr "type" "str")
14684    (set_attr "mode" "SI")
14685    (set_attr "memory" "both")])
14686
14687 (define_insn "strmovsi_rex_1"
14688   [(set (mem:SI (match_operand:DI 2 "register_operand" "0"))
14689         (mem:SI (match_operand:DI 3 "register_operand" "1")))
14690    (set (match_operand:DI 0 "register_operand" "=D")
14691         (plus:DI (match_dup 2)
14692                  (const_int 4)))
14693    (set (match_operand:DI 1 "register_operand" "=S")
14694         (plus:DI (match_dup 3)
14695                  (const_int 4)))
14696    (use (reg:SI 19))]
14697   "TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
14698   "{movsl|movsd}"
14699   [(set_attr "type" "str")
14700    (set_attr "mode" "SI")
14701    (set_attr "memory" "both")])
14702
14703 (define_insn "strmovhi_1"
14704   [(set (mem:HI (match_operand:SI 2 "register_operand" "0"))
14705         (mem:HI (match_operand:SI 3 "register_operand" "1")))
14706    (set (match_operand:SI 0 "register_operand" "=D")
14707         (plus:SI (match_dup 2)
14708                  (const_int 2)))
14709    (set (match_operand:SI 1 "register_operand" "=S")
14710         (plus:SI (match_dup 3)
14711                  (const_int 2)))
14712    (use (reg:SI 19))]
14713   "!TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
14714   "movsw"
14715   [(set_attr "type" "str")
14716    (set_attr "memory" "both")
14717    (set_attr "mode" "HI")])
14718
14719 (define_insn "strmovhi_rex_1"
14720   [(set (mem:HI (match_operand:DI 2 "register_operand" "0"))
14721         (mem:HI (match_operand:DI 3 "register_operand" "1")))
14722    (set (match_operand:DI 0 "register_operand" "=D")
14723         (plus:DI (match_dup 2)
14724                  (const_int 2)))
14725    (set (match_operand:DI 1 "register_operand" "=S")
14726         (plus:DI (match_dup 3)
14727                  (const_int 2)))
14728    (use (reg:SI 19))]
14729   "TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
14730   "movsw"
14731   [(set_attr "type" "str")
14732    (set_attr "memory" "both")
14733    (set_attr "mode" "HI")])
14734
14735 (define_insn "strmovqi_1"
14736   [(set (mem:QI (match_operand:SI 2 "register_operand" "0"))
14737         (mem:QI (match_operand:SI 3 "register_operand" "1")))
14738    (set (match_operand:SI 0 "register_operand" "=D")
14739         (plus:SI (match_dup 2)
14740                  (const_int 1)))
14741    (set (match_operand:SI 1 "register_operand" "=S")
14742         (plus:SI (match_dup 3)
14743                  (const_int 1)))
14744    (use (reg:SI 19))]
14745   "!TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
14746   "movsb"
14747   [(set_attr "type" "str")
14748    (set_attr "memory" "both")
14749    (set_attr "mode" "QI")])
14750
14751 (define_insn "strmovqi_rex_1"
14752   [(set (mem:QI (match_operand:DI 2 "register_operand" "0"))
14753         (mem:QI (match_operand:DI 3 "register_operand" "1")))
14754    (set (match_operand:DI 0 "register_operand" "=D")
14755         (plus:DI (match_dup 2)
14756                  (const_int 1)))
14757    (set (match_operand:DI 1 "register_operand" "=S")
14758         (plus:DI (match_dup 3)
14759                  (const_int 1)))
14760    (use (reg:SI 19))]
14761   "TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
14762   "movsb"
14763   [(set_attr "type" "str")
14764    (set_attr "memory" "both")
14765    (set_attr "mode" "QI")])
14766
14767 (define_insn "rep_movdi_rex64"
14768   [(set (match_operand:DI 2 "register_operand" "=c") (const_int 0))
14769    (set (match_operand:DI 0 "register_operand" "=D") 
14770         (plus:DI (ashift:DI (match_operand:DI 5 "register_operand" "2")
14771                             (const_int 3))
14772                  (match_operand:DI 3 "register_operand" "0")))
14773    (set (match_operand:DI 1 "register_operand" "=S") 
14774         (plus:DI (ashift:DI (match_dup 5) (const_int 3))
14775                  (match_operand:DI 4 "register_operand" "1")))
14776    (set (mem:BLK (match_dup 3))
14777         (mem:BLK (match_dup 4)))
14778    (use (match_dup 5))
14779    (use (reg:SI 19))]
14780   "TARGET_64BIT"
14781   "rep\;movsq|rep movsq"
14782   [(set_attr "type" "str")
14783    (set_attr "prefix_rep" "1")
14784    (set_attr "memory" "both")
14785    (set_attr "mode" "DI")])
14786
14787 (define_insn "rep_movsi"
14788   [(set (match_operand:SI 2 "register_operand" "=c") (const_int 0))
14789    (set (match_operand:SI 0 "register_operand" "=D") 
14790         (plus:SI (ashift:SI (match_operand:SI 5 "register_operand" "2")
14791                             (const_int 2))
14792                  (match_operand:SI 3 "register_operand" "0")))
14793    (set (match_operand:SI 1 "register_operand" "=S") 
14794         (plus:SI (ashift:SI (match_dup 5) (const_int 2))
14795                  (match_operand:SI 4 "register_operand" "1")))
14796    (set (mem:BLK (match_dup 3))
14797         (mem:BLK (match_dup 4)))
14798    (use (match_dup 5))
14799    (use (reg:SI 19))]
14800   "!TARGET_64BIT"
14801   "rep\;movsl|rep movsd"
14802   [(set_attr "type" "str")
14803    (set_attr "prefix_rep" "1")
14804    (set_attr "memory" "both")
14805    (set_attr "mode" "SI")])
14806
14807 (define_insn "rep_movsi_rex64"
14808   [(set (match_operand:DI 2 "register_operand" "=c") (const_int 0))
14809    (set (match_operand:DI 0 "register_operand" "=D") 
14810         (plus:DI (ashift:DI (match_operand:DI 5 "register_operand" "2")
14811                             (const_int 2))
14812                  (match_operand:DI 3 "register_operand" "0")))
14813    (set (match_operand:DI 1 "register_operand" "=S") 
14814         (plus:DI (ashift:DI (match_dup 5) (const_int 2))
14815                  (match_operand:DI 4 "register_operand" "1")))
14816    (set (mem:BLK (match_dup 3))
14817         (mem:BLK (match_dup 4)))
14818    (use (match_dup 5))
14819    (use (reg:SI 19))]
14820   "TARGET_64BIT"
14821   "rep\;movsl|rep movsd"
14822   [(set_attr "type" "str")
14823    (set_attr "prefix_rep" "1")
14824    (set_attr "memory" "both")
14825    (set_attr "mode" "SI")])
14826
14827 (define_insn "rep_movqi"
14828   [(set (match_operand:SI 2 "register_operand" "=c") (const_int 0))
14829    (set (match_operand:SI 0 "register_operand" "=D") 
14830         (plus:SI (match_operand:SI 3 "register_operand" "0")
14831                  (match_operand:SI 5 "register_operand" "2")))
14832    (set (match_operand:SI 1 "register_operand" "=S") 
14833         (plus:SI (match_operand:SI 4 "register_operand" "1") (match_dup 5)))
14834    (set (mem:BLK (match_dup 3))
14835         (mem:BLK (match_dup 4)))
14836    (use (match_dup 5))
14837    (use (reg:SI 19))]
14838   "!TARGET_64BIT"
14839   "rep\;movsb|rep movsb"
14840   [(set_attr "type" "str")
14841    (set_attr "prefix_rep" "1")
14842    (set_attr "memory" "both")
14843    (set_attr "mode" "SI")])
14844
14845 (define_insn "rep_movqi_rex64"
14846   [(set (match_operand:DI 2 "register_operand" "=c") (const_int 0))
14847    (set (match_operand:DI 0 "register_operand" "=D") 
14848         (plus:DI (match_operand:DI 3 "register_operand" "0")
14849                  (match_operand:DI 5 "register_operand" "2")))
14850    (set (match_operand:DI 1 "register_operand" "=S") 
14851         (plus:DI (match_operand:DI 4 "register_operand" "1") (match_dup 5)))
14852    (set (mem:BLK (match_dup 3))
14853         (mem:BLK (match_dup 4)))
14854    (use (match_dup 5))
14855    (use (reg:SI 19))]
14856   "TARGET_64BIT"
14857   "rep\;movsb|rep movsb"
14858   [(set_attr "type" "str")
14859    (set_attr "prefix_rep" "1")
14860    (set_attr "memory" "both")
14861    (set_attr "mode" "SI")])
14862
14863 (define_expand "clrstrsi"
14864    [(use (match_operand:BLK 0 "memory_operand" ""))
14865     (use (match_operand:SI 1 "nonmemory_operand" ""))
14866     (use (match_operand 2 "const_int_operand" ""))]
14867   ""
14868 {
14869  if (ix86_expand_clrstr (operands[0], operands[1], operands[2]))
14870    DONE;
14871  else
14872    FAIL;
14873 })
14874
14875 (define_expand "clrstrdi"
14876    [(use (match_operand:BLK 0 "memory_operand" ""))
14877     (use (match_operand:DI 1 "nonmemory_operand" ""))
14878     (use (match_operand 2 "const_int_operand" ""))]
14879   "TARGET_64BIT"
14880 {
14881  if (ix86_expand_clrstr (operands[0], operands[1], operands[2]))
14882    DONE;
14883  else
14884    FAIL;
14885 })
14886
14887 ;; Most CPUs don't like single string operations
14888 ;; Handle this case here to simplify previous expander.
14889
14890 (define_expand "strsetdi_rex64"
14891   [(set (mem:DI (match_operand:DI 0 "register_operand" ""))
14892         (match_operand:DI 1 "register_operand" ""))
14893    (parallel [(set (match_dup 0) (plus:DI (match_dup 0) (const_int 8)))
14894               (clobber (reg:CC 17))])]
14895   "TARGET_64BIT"
14896 {
14897   if (TARGET_SINGLE_STRINGOP || optimize_size)
14898     {
14899       emit_insn (gen_strsetdi_rex_1 (operands[0], operands[0], operands[1]));
14900       DONE;
14901     }
14902 })
14903
14904 (define_expand "strsetsi"
14905   [(set (mem:SI (match_operand:SI 0 "register_operand" ""))
14906         (match_operand:SI 1 "register_operand" ""))
14907    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 4)))
14908               (clobber (reg:CC 17))])]
14909   ""
14910 {
14911   if (TARGET_64BIT)
14912     {
14913       emit_insn (gen_strsetsi_rex64 (operands[0], operands[1]));
14914       DONE;
14915     }
14916   else if (TARGET_SINGLE_STRINGOP || optimize_size)
14917     {
14918       emit_insn (gen_strsetsi_1 (operands[0], operands[0], operands[1]));
14919       DONE;
14920     }
14921 })
14922
14923 (define_expand "strsetsi_rex64"
14924   [(set (mem:SI (match_operand:DI 0 "register_operand" ""))
14925         (match_operand:SI 1 "register_operand" ""))
14926    (parallel [(set (match_dup 0) (plus:DI (match_dup 0) (const_int 4)))
14927               (clobber (reg:CC 17))])]
14928   "TARGET_64BIT"
14929 {
14930   if (TARGET_SINGLE_STRINGOP || optimize_size)
14931     {
14932       emit_insn (gen_strsetsi_rex_1 (operands[0], operands[0], operands[1]));
14933       DONE;
14934     }
14935 })
14936
14937 (define_expand "strsethi"
14938   [(set (mem:HI (match_operand:SI 0 "register_operand" ""))
14939         (match_operand:HI 1 "register_operand" ""))
14940    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 2)))
14941               (clobber (reg:CC 17))])]
14942   ""
14943 {
14944   if (TARGET_64BIT)
14945     {
14946       emit_insn (gen_strsethi_rex64 (operands[0], operands[1]));
14947       DONE;
14948     }
14949   else if (TARGET_SINGLE_STRINGOP || optimize_size)
14950     {
14951       emit_insn (gen_strsethi_1 (operands[0], operands[0], operands[1]));
14952       DONE;
14953     }
14954 })
14955
14956 (define_expand "strsethi_rex64"
14957   [(set (mem:HI (match_operand:DI 0 "register_operand" ""))
14958         (match_operand:HI 1 "register_operand" ""))
14959    (parallel [(set (match_dup 0) (plus:DI (match_dup 0) (const_int 2)))
14960               (clobber (reg:CC 17))])]
14961   "TARGET_64BIT"
14962 {
14963   if (TARGET_SINGLE_STRINGOP || optimize_size)
14964     {
14965       emit_insn (gen_strsethi_rex_1 (operands[0], operands[0], operands[1]));
14966       DONE;
14967     }
14968 })
14969
14970 (define_expand "strsetqi"
14971   [(set (mem:QI (match_operand:SI 0 "register_operand" ""))
14972         (match_operand:QI 1 "register_operand" ""))
14973    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 1)))
14974               (clobber (reg:CC 17))])]
14975   ""
14976 {
14977   if (TARGET_64BIT)
14978     {
14979       emit_insn (gen_strsetqi_rex64 (operands[0], operands[1]));
14980       DONE;
14981     }
14982   else if (TARGET_SINGLE_STRINGOP || optimize_size)
14983     {
14984       emit_insn (gen_strsetqi_1 (operands[0], operands[0], operands[1]));
14985       DONE;
14986     }
14987 })
14988
14989 (define_expand "strsetqi_rex64"
14990   [(set (mem:QI (match_operand:DI 0 "register_operand" ""))
14991         (match_operand:QI 1 "register_operand" ""))
14992    (parallel [(set (match_dup 0) (plus:DI (match_dup 0) (const_int 1)))
14993               (clobber (reg:CC 17))])]
14994   "TARGET_64BIT"
14995 {
14996   if (TARGET_SINGLE_STRINGOP || optimize_size)
14997     {
14998       emit_insn (gen_strsetqi_rex_1 (operands[0], operands[0], operands[1]));
14999       DONE;
15000     }
15001 })
15002
15003 (define_insn "strsetdi_rex_1"
15004   [(set (mem:SI (match_operand:DI 1 "register_operand" "0"))
15005         (match_operand:SI 2 "register_operand" "a"))
15006    (set (match_operand:DI 0 "register_operand" "=D")
15007         (plus:DI (match_dup 1)
15008                  (const_int 8)))
15009    (use (reg:SI 19))]
15010   "TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
15011   "stosq"
15012   [(set_attr "type" "str")
15013    (set_attr "memory" "store")
15014    (set_attr "mode" "DI")])
15015
15016 (define_insn "strsetsi_1"
15017   [(set (mem:SI (match_operand:SI 1 "register_operand" "0"))
15018         (match_operand:SI 2 "register_operand" "a"))
15019    (set (match_operand:SI 0 "register_operand" "=D")
15020         (plus:SI (match_dup 1)
15021                  (const_int 4)))
15022    (use (reg:SI 19))]
15023   "!TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
15024   "stosl|stosd"
15025   [(set_attr "type" "str")
15026    (set_attr "memory" "store")
15027    (set_attr "mode" "SI")])
15028
15029 (define_insn "strsetsi_rex_1"
15030   [(set (mem:SI (match_operand:DI 1 "register_operand" "0"))
15031         (match_operand:SI 2 "register_operand" "a"))
15032    (set (match_operand:DI 0 "register_operand" "=D")
15033         (plus:DI (match_dup 1)
15034                  (const_int 4)))
15035    (use (reg:SI 19))]
15036   "TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
15037   "stosl|stosd"
15038   [(set_attr "type" "str")
15039    (set_attr "memory" "store")
15040    (set_attr "mode" "SI")])
15041
15042 (define_insn "strsethi_1"
15043   [(set (mem:HI (match_operand:SI 1 "register_operand" "0"))
15044         (match_operand:HI 2 "register_operand" "a"))
15045    (set (match_operand:SI 0 "register_operand" "=D")
15046         (plus:SI (match_dup 1)
15047                  (const_int 2)))
15048    (use (reg:SI 19))]
15049   "!TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
15050   "stosw"
15051   [(set_attr "type" "str")
15052    (set_attr "memory" "store")
15053    (set_attr "mode" "HI")])
15054
15055 (define_insn "strsethi_rex_1"
15056   [(set (mem:HI (match_operand:DI 1 "register_operand" "0"))
15057         (match_operand:HI 2 "register_operand" "a"))
15058    (set (match_operand:DI 0 "register_operand" "=D")
15059         (plus:DI (match_dup 1)
15060                  (const_int 2)))
15061    (use (reg:SI 19))]
15062   "TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
15063   "stosw"
15064   [(set_attr "type" "str")
15065    (set_attr "memory" "store")
15066    (set_attr "mode" "HI")])
15067
15068 (define_insn "strsetqi_1"
15069   [(set (mem:QI (match_operand:SI 1 "register_operand" "0"))
15070         (match_operand:QI 2 "register_operand" "a"))
15071    (set (match_operand:SI 0 "register_operand" "=D")
15072         (plus:SI (match_dup 1)
15073                  (const_int 1)))
15074    (use (reg:SI 19))]
15075   "!TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
15076   "stosb"
15077   [(set_attr "type" "str")
15078    (set_attr "memory" "store")
15079    (set_attr "mode" "QI")])
15080
15081 (define_insn "strsetqi_rex_1"
15082   [(set (mem:QI (match_operand:DI 1 "register_operand" "0"))
15083         (match_operand:QI 2 "register_operand" "a"))
15084    (set (match_operand:DI 0 "register_operand" "=D")
15085         (plus:DI (match_dup 1)
15086                  (const_int 1)))
15087    (use (reg:SI 19))]
15088   "TARGET_64BIT && (TARGET_SINGLE_STRINGOP || optimize_size)"
15089   "stosb"
15090   [(set_attr "type" "str")
15091    (set_attr "memory" "store")
15092    (set_attr "mode" "QI")])
15093
15094 (define_insn "rep_stosdi_rex64"
15095   [(set (match_operand:DI 1 "register_operand" "=c") (const_int 0))
15096    (set (match_operand:DI 0 "register_operand" "=D") 
15097         (plus:DI (ashift:DI (match_operand:DI 4 "register_operand" "1")
15098                             (const_int 3))
15099                  (match_operand:DI 3 "register_operand" "0")))
15100    (set (mem:BLK (match_dup 3))
15101         (const_int 0))
15102    (use (match_operand:DI 2 "register_operand" "a"))
15103    (use (match_dup 4))
15104    (use (reg:SI 19))]
15105   "TARGET_64BIT"
15106   "rep\;stosq|rep stosq"
15107   [(set_attr "type" "str")
15108    (set_attr "prefix_rep" "1")
15109    (set_attr "memory" "store")
15110    (set_attr "mode" "DI")])
15111
15112 (define_insn "rep_stossi"
15113   [(set (match_operand:SI 1 "register_operand" "=c") (const_int 0))
15114    (set (match_operand:SI 0 "register_operand" "=D") 
15115         (plus:SI (ashift:SI (match_operand:SI 4 "register_operand" "1")
15116                             (const_int 2))
15117                  (match_operand:SI 3 "register_operand" "0")))
15118    (set (mem:BLK (match_dup 3))
15119         (const_int 0))
15120    (use (match_operand:SI 2 "register_operand" "a"))
15121    (use (match_dup 4))
15122    (use (reg:SI 19))]
15123   "!TARGET_64BIT"
15124   "rep\;stosl|rep stosd"
15125   [(set_attr "type" "str")
15126    (set_attr "prefix_rep" "1")
15127    (set_attr "memory" "store")
15128    (set_attr "mode" "SI")])
15129
15130 (define_insn "rep_stossi_rex64"
15131   [(set (match_operand:DI 1 "register_operand" "=c") (const_int 0))
15132    (set (match_operand:DI 0 "register_operand" "=D") 
15133         (plus:DI (ashift:DI (match_operand:DI 4 "register_operand" "1")
15134                             (const_int 2))
15135                  (match_operand:DI 3 "register_operand" "0")))
15136    (set (mem:BLK (match_dup 3))
15137         (const_int 0))
15138    (use (match_operand:SI 2 "register_operand" "a"))
15139    (use (match_dup 4))
15140    (use (reg:SI 19))]
15141   "TARGET_64BIT"
15142   "rep\;stosl|rep stosd"
15143   [(set_attr "type" "str")
15144    (set_attr "prefix_rep" "1")
15145    (set_attr "memory" "store")
15146    (set_attr "mode" "SI")])
15147
15148 (define_insn "rep_stosqi"
15149   [(set (match_operand:SI 1 "register_operand" "=c") (const_int 0))
15150    (set (match_operand:SI 0 "register_operand" "=D") 
15151         (plus:SI (match_operand:SI 3 "register_operand" "0")
15152                  (match_operand:SI 4 "register_operand" "1")))
15153    (set (mem:BLK (match_dup 3))
15154         (const_int 0))
15155    (use (match_operand:QI 2 "register_operand" "a"))
15156    (use (match_dup 4))
15157    (use (reg:SI 19))]
15158   "!TARGET_64BIT"
15159   "rep\;stosb|rep stosb"
15160   [(set_attr "type" "str")
15161    (set_attr "prefix_rep" "1")
15162    (set_attr "memory" "store")
15163    (set_attr "mode" "QI")])
15164
15165 (define_insn "rep_stosqi_rex64"
15166   [(set (match_operand:DI 1 "register_operand" "=c") (const_int 0))
15167    (set (match_operand:DI 0 "register_operand" "=D") 
15168         (plus:DI (match_operand:DI 3 "register_operand" "0")
15169                  (match_operand:DI 4 "register_operand" "1")))
15170    (set (mem:BLK (match_dup 3))
15171         (const_int 0))
15172    (use (match_operand:QI 2 "register_operand" "a"))
15173    (use (match_dup 4))
15174    (use (reg:DI 19))]
15175   "TARGET_64BIT"
15176   "rep\;stosb|rep stosb"
15177   [(set_attr "type" "str")
15178    (set_attr "prefix_rep" "1")
15179    (set_attr "memory" "store")
15180    (set_attr "mode" "QI")])
15181
15182 (define_expand "cmpstrsi"
15183   [(set (match_operand:SI 0 "register_operand" "")
15184         (compare:SI (match_operand:BLK 1 "general_operand" "")
15185                     (match_operand:BLK 2 "general_operand" "")))
15186    (use (match_operand 3 "general_operand" ""))
15187    (use (match_operand 4 "immediate_operand" ""))]
15188   ""
15189 {
15190   rtx addr1, addr2, out, outlow, count, countreg, align;
15191
15192   out = operands[0];
15193   if (GET_CODE (out) != REG)
15194     out = gen_reg_rtx (SImode);
15195
15196   addr1 = copy_to_mode_reg (Pmode, XEXP (operands[1], 0));
15197   addr2 = copy_to_mode_reg (Pmode, XEXP (operands[2], 0));
15198   
15199   count = operands[3];
15200   countreg = copy_to_mode_reg (Pmode, count);
15201
15202   /* %%% Iff we are testing strict equality, we can use known alignment
15203      to good advantage.  This may be possible with combine, particularly
15204      once cc0 is dead.  */
15205   align = operands[4];
15206
15207   emit_insn (gen_cld ());
15208   if (GET_CODE (count) == CONST_INT)
15209     {
15210       if (INTVAL (count) == 0)
15211         {
15212           emit_move_insn (operands[0], const0_rtx);
15213           DONE;
15214         }
15215       if (TARGET_64BIT)
15216         emit_insn (gen_cmpstrqi_nz_rex_1 (addr1, addr2, countreg, align,
15217                                           addr1, addr2, countreg));
15218       else
15219         emit_insn (gen_cmpstrqi_nz_1 (addr1, addr2, countreg, align,
15220                                       addr1, addr2, countreg));
15221     }
15222   else
15223     {
15224       if (TARGET_64BIT)
15225         {
15226           emit_insn (gen_cmpdi_1_rex64 (countreg, countreg));
15227           emit_insn (gen_cmpstrqi_rex_1 (addr1, addr2, countreg, align,
15228                                          addr1, addr2, countreg));
15229         }
15230       else
15231         {
15232           emit_insn (gen_cmpsi_1 (countreg, countreg));
15233           emit_insn (gen_cmpstrqi_1 (addr1, addr2, countreg, align,
15234                                      addr1, addr2, countreg));
15235         }
15236     }
15237
15238   outlow = gen_lowpart (QImode, out);
15239   emit_insn (gen_cmpintqi (outlow));
15240   emit_move_insn (out, gen_rtx_SIGN_EXTEND (SImode, outlow));
15241
15242   if (operands[0] != out)
15243     emit_move_insn (operands[0], out);
15244
15245   DONE;
15246 })
15247
15248 ;; Produce a tri-state integer (-1, 0, 1) from condition codes.
15249
15250 (define_expand "cmpintqi"
15251   [(set (match_dup 1)
15252         (gtu:QI (reg:CC 17) (const_int 0)))
15253    (set (match_dup 2)
15254         (ltu:QI (reg:CC 17) (const_int 0)))
15255    (parallel [(set (match_operand:QI 0 "register_operand" "")
15256                    (minus:QI (match_dup 1)
15257                              (match_dup 2)))
15258               (clobber (reg:CC 17))])]
15259   ""
15260   "operands[1] = gen_reg_rtx (QImode);
15261    operands[2] = gen_reg_rtx (QImode);")
15262
15263 ;; memcmp recognizers.  The `cmpsb' opcode does nothing if the count is
15264 ;; zero.  Emit extra code to make sure that a zero-length compare is EQ.
15265
15266 (define_insn "cmpstrqi_nz_1"
15267   [(set (reg:CC 17)
15268         (compare:CC (mem:BLK (match_operand:SI 4 "register_operand" "0"))
15269                     (mem:BLK (match_operand:SI 5 "register_operand" "1"))))
15270    (use (match_operand:SI 6 "register_operand" "2"))
15271    (use (match_operand:SI 3 "immediate_operand" "i"))
15272    (use (reg:SI 19))
15273    (clobber (match_operand:SI 0 "register_operand" "=S"))
15274    (clobber (match_operand:SI 1 "register_operand" "=D"))
15275    (clobber (match_operand:SI 2 "register_operand" "=c"))]
15276   "!TARGET_64BIT"
15277   "repz{\;| }cmpsb"
15278   [(set_attr "type" "str")
15279    (set_attr "mode" "QI")
15280    (set_attr "prefix_rep" "1")])
15281
15282 (define_insn "cmpstrqi_nz_rex_1"
15283   [(set (reg:CC 17)
15284         (compare:CC (mem:BLK (match_operand:DI 4 "register_operand" "0"))
15285                     (mem:BLK (match_operand:DI 5 "register_operand" "1"))))
15286    (use (match_operand:DI 6 "register_operand" "2"))
15287    (use (match_operand:SI 3 "immediate_operand" "i"))
15288    (use (reg:SI 19))
15289    (clobber (match_operand:DI 0 "register_operand" "=S"))
15290    (clobber (match_operand:DI 1 "register_operand" "=D"))
15291    (clobber (match_operand:DI 2 "register_operand" "=c"))]
15292   "TARGET_64BIT"
15293   "repz{\;| }cmpsb"
15294   [(set_attr "type" "str")
15295    (set_attr "mode" "QI")
15296    (set_attr "prefix_rep" "1")])
15297
15298 ;; The same, but the count is not known to not be zero.
15299
15300 (define_insn "cmpstrqi_1"
15301   [(set (reg:CC 17)
15302         (if_then_else:CC (ne (match_operand:SI 6 "register_operand" "2")
15303                              (const_int 0))
15304           (compare:CC (mem:BLK (match_operand:SI 4 "register_operand" "0"))
15305                       (mem:BLK (match_operand:SI 5 "register_operand" "1")))
15306           (const_int 0)))
15307    (use (match_operand:SI 3 "immediate_operand" "i"))
15308    (use (reg:CC 17))
15309    (use (reg:SI 19))
15310    (clobber (match_operand:SI 0 "register_operand" "=S"))
15311    (clobber (match_operand:SI 1 "register_operand" "=D"))
15312    (clobber (match_operand:SI 2 "register_operand" "=c"))]
15313   "!TARGET_64BIT"
15314   "repz{\;| }cmpsb"
15315   [(set_attr "type" "str")
15316    (set_attr "mode" "QI")
15317    (set_attr "prefix_rep" "1")])
15318
15319 (define_insn "cmpstrqi_rex_1"
15320   [(set (reg:CC 17)
15321         (if_then_else:CC (ne (match_operand:DI 6 "register_operand" "2")
15322                              (const_int 0))
15323           (compare:CC (mem:BLK (match_operand:DI 4 "register_operand" "0"))
15324                       (mem:BLK (match_operand:DI 5 "register_operand" "1")))
15325           (const_int 0)))
15326    (use (match_operand:SI 3 "immediate_operand" "i"))
15327    (use (reg:CC 17))
15328    (use (reg:SI 19))
15329    (clobber (match_operand:DI 0 "register_operand" "=S"))
15330    (clobber (match_operand:DI 1 "register_operand" "=D"))
15331    (clobber (match_operand:DI 2 "register_operand" "=c"))]
15332   "TARGET_64BIT"
15333   "repz{\;| }cmpsb"
15334   [(set_attr "type" "str")
15335    (set_attr "mode" "QI")
15336    (set_attr "prefix_rep" "1")])
15337
15338 (define_expand "strlensi"
15339   [(set (match_operand:SI 0 "register_operand" "")
15340         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
15341                     (match_operand:QI 2 "immediate_operand" "")
15342                     (match_operand 3 "immediate_operand" "")] 0))]
15343   ""
15344 {
15345  if (ix86_expand_strlen (operands[0], operands[1], operands[2], operands[3]))
15346    DONE;
15347  else
15348    FAIL;
15349 })
15350
15351 (define_expand "strlendi"
15352   [(set (match_operand:DI 0 "register_operand" "")
15353         (unspec:DI [(match_operand:BLK 1 "general_operand" "")
15354                     (match_operand:QI 2 "immediate_operand" "")
15355                     (match_operand 3 "immediate_operand" "")] 0))]
15356   ""
15357 {
15358  if (ix86_expand_strlen (operands[0], operands[1], operands[2], operands[3]))
15359    DONE;
15360  else
15361    FAIL;
15362 })
15363
15364 (define_insn "strlenqi_1"
15365   [(set (match_operand:SI 0 "register_operand" "=&c")
15366         (unspec:SI [(mem:BLK (match_operand:SI 5 "register_operand" "1"))
15367                     (match_operand:QI 2 "register_operand" "a")
15368                     (match_operand:SI 3 "immediate_operand" "i")
15369                     (match_operand:SI 4 "register_operand" "0")] 0))
15370    (use (reg:SI 19))
15371    (clobber (match_operand:SI 1 "register_operand" "=D"))
15372    (clobber (reg:CC 17))]
15373   "!TARGET_64BIT"
15374   "repnz{\;| }scasb"
15375   [(set_attr "type" "str")
15376    (set_attr "mode" "QI")
15377    (set_attr "prefix_rep" "1")])
15378
15379 (define_insn "strlenqi_rex_1"
15380   [(set (match_operand:DI 0 "register_operand" "=&c")
15381         (unspec:DI [(mem:BLK (match_operand:DI 5 "register_operand" "1"))
15382                     (match_operand:QI 2 "register_operand" "a")
15383                     (match_operand:DI 3 "immediate_operand" "i")
15384                     (match_operand:DI 4 "register_operand" "0")] 0))
15385    (use (reg:SI 19))
15386    (clobber (match_operand:DI 1 "register_operand" "=D"))
15387    (clobber (reg:CC 17))]
15388   "TARGET_64BIT"
15389   "repnz{\;| }scasb"
15390   [(set_attr "type" "str")
15391    (set_attr "mode" "QI")
15392    (set_attr "prefix_rep" "1")])
15393
15394 ;; Peephole optimizations to clean up after cmpstr*.  This should be
15395 ;; handled in combine, but it is not currently up to the task.
15396 ;; When used for their truth value, the cmpstr* expanders generate
15397 ;; code like this:
15398 ;;
15399 ;;   repz cmpsb
15400 ;;   seta       %al
15401 ;;   setb       %dl
15402 ;;   cmpb       %al, %dl
15403 ;;   jcc        label
15404 ;;
15405 ;; The intermediate three instructions are unnecessary.
15406
15407 ;; This one handles cmpstr*_nz_1...
15408 (define_peephole2
15409   [(parallel[
15410      (set (reg:CC 17)
15411           (compare:CC (mem:BLK (match_operand 4 "register_operand" ""))
15412                       (mem:BLK (match_operand 5 "register_operand" ""))))
15413      (use (match_operand 6 "register_operand" ""))
15414      (use (match_operand:SI 3 "immediate_operand" ""))
15415      (use (reg:SI 19))
15416      (clobber (match_operand 0 "register_operand" ""))
15417      (clobber (match_operand 1 "register_operand" ""))
15418      (clobber (match_operand 2 "register_operand" ""))])
15419    (set (match_operand:QI 7 "register_operand" "")
15420         (gtu:QI (reg:CC 17) (const_int 0)))
15421    (set (match_operand:QI 8 "register_operand" "")
15422         (ltu:QI (reg:CC 17) (const_int 0)))
15423    (set (reg 17)
15424         (compare (match_dup 7) (match_dup 8)))
15425   ]
15426   "peep2_reg_dead_p (4, operands[7]) && peep2_reg_dead_p (4, operands[8])"
15427   [(parallel[
15428      (set (reg:CC 17)
15429           (compare:CC (mem:BLK (match_dup 4))
15430                       (mem:BLK (match_dup 5))))
15431      (use (match_dup 6))
15432      (use (match_dup 3))
15433      (use (reg:SI 19))
15434      (clobber (match_dup 0))
15435      (clobber (match_dup 1))
15436      (clobber (match_dup 2))])]
15437   "")
15438
15439 ;; ...and this one handles cmpstr*_1.
15440 (define_peephole2
15441   [(parallel[
15442      (set (reg:CC 17)
15443           (if_then_else:CC (ne (match_operand 6 "register_operand" "")
15444                                (const_int 0))
15445             (compare:CC (mem:BLK (match_operand 4 "register_operand" ""))
15446                         (mem:BLK (match_operand 5 "register_operand" "")))
15447             (const_int 0)))
15448      (use (match_operand:SI 3 "immediate_operand" ""))
15449      (use (reg:CC 17))
15450      (use (reg:SI 19))
15451      (clobber (match_operand 0 "register_operand" ""))
15452      (clobber (match_operand 1 "register_operand" ""))
15453      (clobber (match_operand 2 "register_operand" ""))])
15454    (set (match_operand:QI 7 "register_operand" "")
15455         (gtu:QI (reg:CC 17) (const_int 0)))
15456    (set (match_operand:QI 8 "register_operand" "")
15457         (ltu:QI (reg:CC 17) (const_int 0)))
15458    (set (reg 17)
15459         (compare (match_dup 7) (match_dup 8)))
15460   ]
15461   "peep2_reg_dead_p (4, operands[7]) && peep2_reg_dead_p (4, operands[8])"
15462   [(parallel[
15463      (set (reg:CC 17)
15464           (if_then_else:CC (ne (match_dup 6)
15465                                (const_int 0))
15466             (compare:CC (mem:BLK (match_dup 4))
15467                         (mem:BLK (match_dup 5)))
15468             (const_int 0)))
15469      (use (match_dup 3))
15470      (use (reg:CC 17))
15471      (use (reg:SI 19))
15472      (clobber (match_dup 0))
15473      (clobber (match_dup 1))
15474      (clobber (match_dup 2))])]
15475   "")
15476
15477
15478 \f
15479 ;; Conditional move instructions.
15480
15481 (define_expand "movdicc_rex64"
15482   [(set (match_operand:DI 0 "register_operand" "")
15483         (if_then_else:DI (match_operand 1 "comparison_operator" "")
15484                          (match_operand:DI 2 "x86_64_general_operand" "")
15485                          (match_operand:DI 3 "x86_64_general_operand" "")))]
15486   "TARGET_64BIT"
15487   "if (!ix86_expand_int_movcc (operands)) FAIL; DONE;")
15488
15489 (define_insn "x86_movdicc_0_m1_rex64"
15490   [(set (match_operand:DI 0 "register_operand" "=r")
15491         (if_then_else:DI (ltu (reg:CC 17) (const_int 0))
15492           (const_int -1)
15493           (const_int 0)))
15494    (clobber (reg:CC 17))]
15495   "TARGET_64BIT"
15496   "sbb{q}\t%0, %0"
15497   ; Since we don't have the proper number of operands for an alu insn,
15498   ; fill in all the blanks.
15499   [(set_attr "type" "alu")
15500    (set_attr "memory" "none")
15501    (set_attr "imm_disp" "false")
15502    (set_attr "mode" "DI")
15503    (set_attr "length_immediate" "0")])
15504
15505 (define_insn "*movdicc_c_rex64"
15506   [(set (match_operand:DI 0 "register_operand" "=r,r")
15507         (if_then_else:DI (match_operator 1 "ix86_comparison_operator" 
15508                                 [(reg 17) (const_int 0)])
15509                       (match_operand:DI 2 "nonimmediate_operand" "rm,0")
15510                       (match_operand:DI 3 "nonimmediate_operand" "0,rm")))]
15511   "TARGET_64BIT && TARGET_CMOVE
15512    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)"
15513   "@
15514    cmov%C1\t{%2, %0|%0, %2}
15515    cmov%c1\t{%3, %0|%0, %3}"
15516   [(set_attr "type" "icmov")
15517    (set_attr "mode" "DI")])
15518
15519 (define_expand "movsicc"
15520   [(set (match_operand:SI 0 "register_operand" "")
15521         (if_then_else:SI (match_operand 1 "comparison_operator" "")
15522                          (match_operand:SI 2 "general_operand" "")
15523                          (match_operand:SI 3 "general_operand" "")))]
15524   ""
15525   "if (!ix86_expand_int_movcc (operands)) FAIL; DONE;")
15526
15527 ;; Data flow gets confused by our desire for `sbbl reg,reg', and clearing
15528 ;; the register first winds up with `sbbl $0,reg', which is also weird.
15529 ;; So just document what we're doing explicitly.
15530
15531 (define_insn "x86_movsicc_0_m1"
15532   [(set (match_operand:SI 0 "register_operand" "=r")
15533         (if_then_else:SI (ltu (reg:CC 17) (const_int 0))
15534           (const_int -1)
15535           (const_int 0)))
15536    (clobber (reg:CC 17))]
15537   ""
15538   "sbb{l}\t%0, %0"
15539   ; Since we don't have the proper number of operands for an alu insn,
15540   ; fill in all the blanks.
15541   [(set_attr "type" "alu")
15542    (set_attr "memory" "none")
15543    (set_attr "imm_disp" "false")
15544    (set_attr "mode" "SI")
15545    (set_attr "length_immediate" "0")])
15546
15547 (define_insn "*movsicc_noc"
15548   [(set (match_operand:SI 0 "register_operand" "=r,r")
15549         (if_then_else:SI (match_operator 1 "ix86_comparison_operator" 
15550                                 [(reg 17) (const_int 0)])
15551                       (match_operand:SI 2 "nonimmediate_operand" "rm,0")
15552                       (match_operand:SI 3 "nonimmediate_operand" "0,rm")))]
15553   "TARGET_CMOVE
15554    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)"
15555   "@
15556    cmov%C1\t{%2, %0|%0, %2}
15557    cmov%c1\t{%3, %0|%0, %3}"
15558   [(set_attr "type" "icmov")
15559    (set_attr "mode" "SI")])
15560
15561 (define_expand "movhicc"
15562   [(set (match_operand:HI 0 "register_operand" "")
15563         (if_then_else:HI (match_operand 1 "comparison_operator" "")
15564                          (match_operand:HI 2 "nonimmediate_operand" "")
15565                          (match_operand:HI 3 "nonimmediate_operand" "")))]
15566   "TARGET_CMOVE && TARGET_HIMODE_MATH"
15567   "if (!ix86_expand_int_movcc (operands)) FAIL; DONE;")
15568
15569 (define_insn "*movhicc_noc"
15570   [(set (match_operand:HI 0 "register_operand" "=r,r")
15571         (if_then_else:HI (match_operator 1 "ix86_comparison_operator" 
15572                                 [(reg 17) (const_int 0)])
15573                       (match_operand:HI 2 "nonimmediate_operand" "rm,0")
15574                       (match_operand:HI 3 "nonimmediate_operand" "0,rm")))]
15575   "TARGET_CMOVE
15576    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)"
15577   "@
15578    cmov%C1\t{%2, %0|%0, %2}
15579    cmov%c1\t{%3, %0|%0, %3}"
15580   [(set_attr "type" "icmov")
15581    (set_attr "mode" "HI")])
15582
15583 (define_expand "movsfcc"
15584   [(set (match_operand:SF 0 "register_operand" "")
15585         (if_then_else:SF (match_operand 1 "comparison_operator" "")
15586                          (match_operand:SF 2 "register_operand" "")
15587                          (match_operand:SF 3 "register_operand" "")))]
15588   "TARGET_CMOVE"
15589   "if (! ix86_expand_fp_movcc (operands)) FAIL; DONE;")
15590
15591 (define_insn "*movsfcc_1"
15592   [(set (match_operand:SF 0 "register_operand" "=f,f,r,r")
15593         (if_then_else:SF (match_operator 1 "fcmov_comparison_operator" 
15594                                 [(reg 17) (const_int 0)])
15595                       (match_operand:SF 2 "nonimmediate_operand" "f,0,rm,0")
15596                       (match_operand:SF 3 "nonimmediate_operand" "0,f,0,rm")))]
15597   "TARGET_CMOVE
15598    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)"
15599   "@
15600    fcmov%F1\t{%2, %0|%0, %2}
15601    fcmov%f1\t{%3, %0|%0, %3}
15602    cmov%C1\t{%2, %0|%0, %2}
15603    cmov%c1\t{%3, %0|%0, %3}"
15604   [(set_attr "type" "fcmov,fcmov,icmov,icmov")
15605    (set_attr "mode" "SF,SF,SI,SI")])
15606
15607 (define_expand "movdfcc"
15608   [(set (match_operand:DF 0 "register_operand" "")
15609         (if_then_else:DF (match_operand 1 "comparison_operator" "")
15610                          (match_operand:DF 2 "register_operand" "")
15611                          (match_operand:DF 3 "register_operand" "")))]
15612   "TARGET_CMOVE"
15613   "if (! ix86_expand_fp_movcc (operands)) FAIL; DONE;")
15614
15615 (define_insn "*movdfcc_1"
15616   [(set (match_operand:DF 0 "register_operand" "=f,f,&r,&r")
15617         (if_then_else:DF (match_operator 1 "fcmov_comparison_operator" 
15618                                 [(reg 17) (const_int 0)])
15619                       (match_operand:DF 2 "nonimmediate_operand" "f,0,rm,0")
15620                       (match_operand:DF 3 "nonimmediate_operand" "0,f,0,rm")))]
15621   "TARGET_CMOVE && !TARGET_64BIT
15622    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)"
15623   "@
15624    fcmov%F1\t{%2, %0|%0, %2}
15625    fcmov%f1\t{%3, %0|%0, %3}
15626    #
15627    #"
15628   [(set_attr "type" "fcmov,fcmov,multi,multi")
15629    (set_attr "mode" "DF")])
15630
15631 (define_insn "*movdfcc_1_rex64"
15632   [(set (match_operand:DF 0 "register_operand" "=f,f,&r,&r")
15633         (if_then_else:DF (match_operator 1 "fcmov_comparison_operator" 
15634                                 [(reg 17) (const_int 0)])
15635                       (match_operand:DF 2 "nonimmediate_operand" "f,0,rm,0")
15636                       (match_operand:DF 3 "nonimmediate_operand" "0,f,0,rm")))]
15637   "TARGET_CMOVE && TARGET_64BIT
15638    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)"
15639   "@
15640    fcmov%F1\t{%2, %0|%0, %2}
15641    fcmov%f1\t{%3, %0|%0, %3}
15642    cmov%C1\t{%2, %0|%0, %2}
15643    cmov%c1\t{%3, %0|%0, %3}"
15644   [(set_attr "type" "fcmov,fcmov,icmov,icmov")
15645    (set_attr "mode" "DF")])
15646
15647 (define_split
15648   [(set (match_operand:DF 0 "register_operand" "")
15649         (if_then_else:DF (match_operator 1 "fcmov_comparison_operator" 
15650                                 [(match_operand 4 "" "") (const_int 0)])
15651                       (match_operand:DF 2 "nonimmediate_operand" "")
15652                       (match_operand:DF 3 "nonimmediate_operand" "")))]
15653   "!ANY_FP_REG_P (operands[0]) && reload_completed && !TARGET_64BIT"
15654   [(set (match_dup 2)
15655         (if_then_else:SI (match_op_dup 1 [(match_dup 4) (const_int 0)])
15656                       (match_dup 5)
15657                       (match_dup 7)))
15658    (set (match_dup 3)
15659         (if_then_else:SI (match_op_dup 1 [(match_dup 4) (const_int 0)])
15660                       (match_dup 6)
15661                       (match_dup 8)))]
15662   "split_di (operands+2, 1, operands+5, operands+6);
15663    split_di (operands+3, 1, operands+7, operands+8);
15664    split_di (operands, 1, operands+2, operands+3);")
15665
15666 (define_expand "movxfcc"
15667   [(set (match_operand:XF 0 "register_operand" "")
15668         (if_then_else:XF (match_operand 1 "comparison_operator" "")
15669                          (match_operand:XF 2 "register_operand" "")
15670                          (match_operand:XF 3 "register_operand" "")))]
15671   "TARGET_CMOVE && !TARGET_64BIT"
15672   "if (! ix86_expand_fp_movcc (operands)) FAIL; DONE;")
15673
15674 (define_expand "movtfcc"
15675   [(set (match_operand:TF 0 "register_operand" "")
15676         (if_then_else:TF (match_operand 1 "comparison_operator" "")
15677                          (match_operand:TF 2 "register_operand" "")
15678                          (match_operand:TF 3 "register_operand" "")))]
15679   "TARGET_CMOVE"
15680   "if (! ix86_expand_fp_movcc (operands)) FAIL; DONE;")
15681
15682 (define_insn "*movxfcc_1"
15683   [(set (match_operand:XF 0 "register_operand" "=f,f")
15684         (if_then_else:XF (match_operator 1 "fcmov_comparison_operator" 
15685                                 [(reg 17) (const_int 0)])
15686                       (match_operand:XF 2 "register_operand" "f,0")
15687                       (match_operand:XF 3 "register_operand" "0,f")))]
15688   "TARGET_CMOVE && !TARGET_64BIT"
15689   "@
15690    fcmov%F1\t{%2, %0|%0, %2}
15691    fcmov%f1\t{%3, %0|%0, %3}"
15692   [(set_attr "type" "fcmov")
15693    (set_attr "mode" "XF")])
15694
15695 (define_insn "*movtfcc_1"
15696   [(set (match_operand:TF 0 "register_operand" "=f,f")
15697         (if_then_else:TF (match_operator 1 "fcmov_comparison_operator" 
15698                                 [(reg 17) (const_int 0)])
15699                       (match_operand:TF 2 "register_operand" "f,0")
15700                       (match_operand:TF 3 "register_operand" "0,f")))]
15701   "TARGET_CMOVE"
15702   "@
15703    fcmov%F1\t{%2, %0|%0, %2}
15704    fcmov%f1\t{%3, %0|%0, %3}"
15705   [(set_attr "type" "fcmov")
15706    (set_attr "mode" "XF")])
15707
15708 (define_expand "minsf3"
15709   [(parallel [
15710      (set (match_operand:SF 0 "register_operand" "")
15711           (if_then_else:SF (lt (match_operand:SF 1 "register_operand" "")
15712                                (match_operand:SF 2 "nonimmediate_operand" ""))
15713                            (match_dup 1)
15714                            (match_dup 2)))
15715      (clobber (reg:CC 17))])]
15716   "TARGET_SSE"
15717   "")
15718
15719 (define_insn "*minsf"
15720   [(set (match_operand:SF 0 "register_operand" "=x#f,f#x,f#x")
15721         (if_then_else:SF (lt (match_operand:SF 1 "register_operand" "0,0,f#x")
15722                              (match_operand:SF 2 "nonimmediate_operand" "xm#f,f#x,0"))
15723                          (match_dup 1)
15724                          (match_dup 2)))
15725    (clobber (reg:CC 17))]
15726   "TARGET_SSE && TARGET_IEEE_FP"
15727   "#")
15728
15729 (define_insn "*minsf_nonieee"
15730   [(set (match_operand:SF 0 "register_operand" "=x#f,f#x")
15731         (if_then_else:SF (lt (match_operand:SF 1 "register_operand" "%0,0")
15732                              (match_operand:SF 2 "nonimmediate_operand" "xm#f,fm#x"))
15733                          (match_dup 1)
15734                          (match_dup 2)))
15735    (clobber (reg:CC 17))]
15736   "TARGET_SSE && !TARGET_IEEE_FP"
15737   "#")
15738
15739 (define_split
15740   [(set (match_operand:SF 0 "register_operand" "")
15741         (if_then_else:SF (lt (match_operand:SF 1 "register_operand" "")
15742                              (match_operand:SF 2 "nonimmediate_operand" ""))
15743                          (match_operand:SF 3 "register_operand" "")
15744                          (match_operand:SF 4 "nonimmediate_operand" "")))
15745    (clobber (reg:CC 17))]
15746   "SSE_REG_P (operands[0]) && reload_completed
15747    && ((operands_match_p (operands[1], operands[3])
15748         && operands_match_p (operands[2], operands[4]))
15749        || (operands_match_p (operands[1], operands[4])
15750            && operands_match_p (operands[2], operands[3])))"
15751   [(set (match_dup 0)
15752         (if_then_else:SF (lt (match_dup 1)
15753                              (match_dup 2))
15754                          (match_dup 1)
15755                          (match_dup 2)))])
15756
15757 ;; We can't represent the LT test directly.  Do this by swapping the operands.
15758
15759 (define_split
15760   [(set (match_operand:SF 0 "register_operand" "")
15761         (if_then_else:SF (lt (match_operand:SF 1 "register_operand" "")
15762                              (match_operand:SF 2 "register_operand" ""))
15763                          (match_operand:DF 3 "register_operand" "")
15764                          (match_operand:DF 4 "register_operand" "")))
15765    (clobber (reg:CC 17))]
15766   "FP_REG_P (operands[0]) && reload_completed
15767    && ((operands_match_p (operands[1], operands[3])
15768         && operands_match_p (operands[2], operands[4]))
15769        || (operands_match_p (operands[1], operands[4])
15770            && operands_match_p (operands[2], operands[3])))"
15771   [(set (reg:CCFP 17)
15772         (compare:CCFP (match_dup 2)
15773                       (match_dup 1)))
15774    (set (match_dup 0)
15775         (if_then_else:SF (ge (reg:CCFP 17) (const_int 0))
15776                          (match_dup 1)
15777                          (match_dup 2)))])
15778
15779 (define_insn "*minsf_sse"
15780   [(set (match_operand:SF 0 "register_operand" "=x")
15781         (if_then_else:SF (lt (match_operand:SF 1 "register_operand" "0")
15782                              (match_operand:SF 2 "nonimmediate_operand" "xm"))
15783                          (match_dup 1)
15784                          (match_dup 2)))]
15785   "TARGET_SSE && reload_completed"
15786   "minss\t{%2, %0|%0, %2}"
15787   [(set_attr "type" "sse")
15788    (set_attr "mode" "SF")])
15789
15790 (define_expand "mindf3"
15791   [(parallel [
15792      (set (match_operand:DF 0 "register_operand" "")
15793           (if_then_else:DF (lt (match_operand:DF 1 "register_operand" "")
15794                                (match_operand:DF 2 "nonimmediate_operand" ""))
15795                            (match_dup 1)
15796                            (match_dup 2)))
15797      (clobber (reg:CC 17))])]
15798   "TARGET_SSE2"
15799   "#")
15800
15801 (define_insn "*mindf"
15802   [(set (match_operand:DF 0 "register_operand" "=Y#f,f#Y,f#Y")
15803         (if_then_else:DF (lt (match_operand:DF 1 "register_operand" "0,0,f#Y")
15804                              (match_operand:DF 2 "nonimmediate_operand" "Ym#f,f#Y,0"))
15805                          (match_dup 1)
15806                          (match_dup 2)))
15807    (clobber (reg:CC 17))]
15808   "TARGET_SSE2 && TARGET_IEEE_FP"
15809   "#")
15810
15811 (define_insn "*mindf_nonieee"
15812   [(set (match_operand:DF 0 "register_operand" "=Y#f,f#Y")
15813         (if_then_else:DF (lt (match_operand:DF 1 "register_operand" "%0,0")
15814                              (match_operand:DF 2 "nonimmediate_operand" "Ym#f,fm#Y"))
15815                          (match_dup 1)
15816                          (match_dup 2)))
15817    (clobber (reg:CC 17))]
15818   "TARGET_SSE2 && !TARGET_IEEE_FP"
15819   "#")
15820
15821 (define_split
15822   [(set (match_operand:DF 0 "register_operand" "")
15823         (if_then_else:DF (lt (match_operand:DF 1 "register_operand" "")
15824                              (match_operand:DF 2 "nonimmediate_operand" ""))
15825                          (match_operand:DF 3 "register_operand" "")
15826                          (match_operand:DF 4 "nonimmediate_operand" "")))
15827    (clobber (reg:CC 17))]
15828   "SSE_REG_P (operands[0]) && reload_completed
15829    && ((operands_match_p (operands[1], operands[3])
15830         && operands_match_p (operands[2], operands[4]))
15831        || (operands_match_p (operands[1], operands[4])
15832            && operands_match_p (operands[2], operands[3])))"
15833   [(set (match_dup 0)
15834         (if_then_else:DF (lt (match_dup 1)
15835                              (match_dup 2))
15836                          (match_dup 1)
15837                          (match_dup 2)))])
15838
15839 ;; We can't represent the LT test directly.  Do this by swapping the operands.
15840 (define_split
15841   [(set (match_operand:DF 0 "register_operand" "")
15842         (if_then_else:DF (lt (match_operand:DF 1 "register_operand" "")
15843                              (match_operand:DF 2 "register_operand" ""))
15844                          (match_operand:DF 3 "register_operand" "")
15845                          (match_operand:DF 4 "register_operand" "")))
15846    (clobber (reg:CC 17))]
15847   "FP_REG_P (operands[0]) && reload_completed
15848    && ((operands_match_p (operands[1], operands[3])
15849         && operands_match_p (operands[2], operands[4]))
15850        || (operands_match_p (operands[1], operands[4])
15851            && operands_match_p (operands[2], operands[3])))"
15852   [(set (reg:CCFP 17)
15853         (compare:CCFP (match_dup 2)
15854                       (match_dup 2)))
15855    (set (match_dup 0)
15856         (if_then_else:DF (ge (reg:CCFP 17) (const_int 0))
15857                          (match_dup 1)
15858                          (match_dup 2)))])
15859
15860 (define_insn "*mindf_sse"
15861   [(set (match_operand:DF 0 "register_operand" "=Y")
15862         (if_then_else:DF (lt (match_operand:DF 1 "register_operand" "0")
15863                              (match_operand:DF 2 "nonimmediate_operand" "Ym"))
15864                          (match_dup 1)
15865                          (match_dup 2)))]
15866   "TARGET_SSE2 && reload_completed"
15867   "minsd\t{%2, %0|%0, %2}"
15868   [(set_attr "type" "sse")
15869    (set_attr "mode" "DF")])
15870
15871 (define_expand "maxsf3"
15872   [(parallel [
15873      (set (match_operand:SF 0 "register_operand" "")
15874           (if_then_else:SF (gt (match_operand:SF 1 "register_operand" "")
15875                                (match_operand:SF 2 "nonimmediate_operand" ""))
15876                            (match_dup 1)
15877                            (match_dup 2)))
15878      (clobber (reg:CC 17))])]
15879   "TARGET_SSE"
15880   "#")
15881
15882 (define_insn "*maxsf"
15883   [(set (match_operand:SF 0 "register_operand" "=x#f,f#x,f#x")
15884         (if_then_else:SF (gt (match_operand:SF 1 "register_operand" "0,0,f#x")
15885                              (match_operand:SF 2 "nonimmediate_operand" "xm#f,fm#x,0"))
15886                          (match_dup 1)
15887                          (match_dup 2)))
15888    (clobber (reg:CC 17))]
15889   "TARGET_SSE && TARGET_IEEE_FP"
15890   "#")
15891
15892 (define_insn "*maxsf_nonieee"
15893   [(set (match_operand:SF 0 "register_operand" "=x#f,f#x")
15894         (if_then_else:SF (gt (match_operand:SF 1 "register_operand" "%0,0")
15895                              (match_operand:SF 2 "nonimmediate_operand" "xm#f,fm#x"))
15896                          (match_dup 1)
15897                          (match_dup 2)))
15898    (clobber (reg:CC 17))]
15899   "TARGET_SSE && !TARGET_IEEE_FP"
15900   "#")
15901
15902 (define_split
15903   [(set (match_operand:SF 0 "register_operand" "")
15904         (if_then_else:SF (gt (match_operand:SF 1 "register_operand" "")
15905                              (match_operand:SF 2 "nonimmediate_operand" ""))
15906                          (match_operand:SF 3 "register_operand" "")
15907                          (match_operand:SF 4 "nonimmediate_operand" "")))
15908    (clobber (reg:CC 17))]
15909   "SSE_REG_P (operands[0]) && reload_completed
15910    && ((operands_match_p (operands[1], operands[3])
15911         && operands_match_p (operands[2], operands[4]))
15912        || (operands_match_p (operands[1], operands[4])
15913            && operands_match_p (operands[2], operands[3])))"
15914   [(set (match_dup 0)
15915         (if_then_else:SF (gt (match_dup 1)
15916                              (match_dup 2))
15917                          (match_dup 1)
15918                          (match_dup 2)))])
15919
15920 (define_split
15921   [(set (match_operand:SF 0 "register_operand" "")
15922         (if_then_else:SF (gt (match_operand:SF 1 "register_operand" "")
15923                              (match_operand:SF 2 "register_operand" ""))
15924                          (match_operand:SF 3 "register_operand" "")
15925                          (match_operand:SF 4 "register_operand" "")))
15926    (clobber (reg:CC 17))]
15927   "FP_REG_P (operands[0]) && reload_completed
15928    && ((operands_match_p (operands[1], operands[3])
15929         && operands_match_p (operands[2], operands[4]))
15930        || (operands_match_p (operands[1], operands[4])
15931            && operands_match_p (operands[2], operands[3])))"
15932   [(set (reg:CCFP 17)
15933         (compare:CCFP (match_dup 1)
15934                       (match_dup 2)))
15935    (set (match_dup 0)
15936         (if_then_else:SF (gt (reg:CCFP 17) (const_int 0))
15937                          (match_dup 1)
15938                          (match_dup 2)))])
15939
15940 (define_insn "*maxsf_sse"
15941   [(set (match_operand:SF 0 "register_operand" "=x")
15942         (if_then_else:SF (gt (match_operand:SF 1 "register_operand" "0")
15943                              (match_operand:SF 2 "nonimmediate_operand" "xm"))
15944                          (match_dup 1)
15945                          (match_dup 2)))]
15946   "TARGET_SSE && reload_completed"
15947   "maxss\t{%2, %0|%0, %2}"
15948   [(set_attr "type" "sse")
15949    (set_attr "mode" "SF")])
15950
15951 (define_expand "maxdf3"
15952   [(parallel [
15953      (set (match_operand:DF 0 "register_operand" "")
15954           (if_then_else:DF (gt (match_operand:DF 1 "register_operand" "")
15955                                (match_operand:DF 2 "nonimmediate_operand" ""))
15956                            (match_dup 1)
15957                            (match_dup 2)))
15958      (clobber (reg:CC 17))])]
15959   "TARGET_SSE2"
15960   "#")
15961
15962 (define_insn "*maxdf"
15963   [(set (match_operand:DF 0 "register_operand" "=Y#f,f#Y,f#Y")
15964         (if_then_else:DF (gt (match_operand:DF 1 "register_operand" "0,0,f#Y")
15965                              (match_operand:DF 2 "nonimmediate_operand" "Ym#f,fm#Y,0"))
15966                          (match_dup 1)
15967                          (match_dup 2)))
15968    (clobber (reg:CC 17))]
15969   "TARGET_SSE2 && TARGET_IEEE_FP"
15970   "#")
15971
15972 (define_insn "*maxdf_nonieee"
15973   [(set (match_operand:DF 0 "register_operand" "=Y#f,f#Y")
15974         (if_then_else:DF (gt (match_operand:DF 1 "register_operand" "%0,0")
15975                              (match_operand:DF 2 "nonimmediate_operand" "Ym#f,fm#Y"))
15976                          (match_dup 1)
15977                          (match_dup 2)))
15978    (clobber (reg:CC 17))]
15979   "TARGET_SSE2 && !TARGET_IEEE_FP"
15980   "#")
15981
15982 (define_split
15983   [(set (match_operand:DF 0 "register_operand" "")
15984         (if_then_else:DF (gt (match_operand:DF 1 "register_operand" "")
15985                              (match_operand:DF 2 "nonimmediate_operand" ""))
15986                          (match_operand:DF 3 "register_operand" "")
15987                          (match_operand:DF 4 "nonimmediate_operand" "")))
15988    (clobber (reg:CC 17))]
15989   "SSE_REG_P (operands[0]) && reload_completed
15990    && ((operands_match_p (operands[1], operands[3])
15991         && operands_match_p (operands[2], operands[4]))
15992        || (operands_match_p (operands[1], operands[4])
15993            && operands_match_p (operands[2], operands[3])))"
15994   [(set (match_dup 0)
15995         (if_then_else:DF (gt (match_dup 1)
15996                              (match_dup 2))
15997                          (match_dup 1)
15998                          (match_dup 2)))])
15999
16000 (define_split
16001   [(set (match_operand:DF 0 "register_operand" "")
16002         (if_then_else:DF (gt (match_operand:DF 1 "register_operand" "")
16003                              (match_operand:DF 2 "register_operand" ""))
16004                          (match_operand:DF 3 "register_operand" "")
16005                          (match_operand:DF 4 "register_operand" "")))
16006    (clobber (reg:CC 17))]
16007   "FP_REG_P (operands[0]) && reload_completed
16008    && ((operands_match_p (operands[1], operands[3])
16009         && operands_match_p (operands[2], operands[4]))
16010        || (operands_match_p (operands[1], operands[4])
16011            && operands_match_p (operands[2], operands[3])))"
16012   [(set (reg:CCFP 17)
16013         (compare:CCFP (match_dup 1)
16014                       (match_dup 2)))
16015    (set (match_dup 0)
16016         (if_then_else:DF (gt (reg:CCFP 17) (const_int 0))
16017                          (match_dup 1)
16018                          (match_dup 2)))])
16019
16020 (define_insn "*maxdf_sse"
16021   [(set (match_operand:DF 0 "register_operand" "=Y")
16022         (if_then_else:DF (gt (match_operand:DF 1 "register_operand" "0")
16023                              (match_operand:DF 2 "nonimmediate_operand" "Ym"))
16024                          (match_dup 1)
16025                          (match_dup 2)))]
16026   "TARGET_SSE2 && reload_completed"
16027   "maxsd\t{%2, %0|%0, %2}"
16028   [(set_attr "type" "sse")
16029    (set_attr "mode" "DF")])
16030 \f
16031 ;; Misc patterns (?)
16032
16033 ;; This pattern exists to put a dependancy on all ebp-based memory accesses.
16034 ;; Otherwise there will be nothing to keep
16035 ;; 
16036 ;; [(set (reg ebp) (reg esp))]
16037 ;; [(set (reg esp) (plus (reg esp) (const_int -160000)))
16038 ;;  (clobber (eflags)]
16039 ;; [(set (mem (plus (reg ebp) (const_int -160000))) (const_int 0))]
16040 ;;
16041 ;; in proper program order.
16042 (define_expand "pro_epilogue_adjust_stack"
16043   [(parallel [(set (match_operand:SI 0 "register_operand" "=r,r")
16044                    (plus:SI (match_operand:SI 1 "register_operand" "0,r")
16045                             (match_operand:SI 2 "immediate_operand" "i,i")))
16046               (clobber (reg:CC 17))
16047               (clobber (mem:BLK (scratch)))])]
16048  ""
16049 {
16050   if (TARGET_64BIT)
16051     {
16052       emit_insn (gen_pro_epilogue_adjust_stack_rex64
16053                  (operands[0], operands[1], operands[2]));
16054       DONE;
16055     }
16056 })
16057
16058 (define_insn "*pro_epilogue_adjust_stack_1"
16059   [(set (match_operand:SI 0 "register_operand" "=r,r")
16060         (plus:SI (match_operand:SI 1 "register_operand" "0,r")
16061                  (match_operand:SI 2 "immediate_operand" "i,i")))
16062    (clobber (reg:CC 17))
16063    (clobber (mem:BLK (scratch)))]
16064   "!TARGET_64BIT"
16065 {
16066   switch (get_attr_type (insn))
16067     {
16068     case TYPE_IMOV:
16069       return "mov{l}\t{%1, %0|%0, %1}";
16070
16071     case TYPE_ALU:
16072       if (GET_CODE (operands[2]) == CONST_INT
16073           && (INTVAL (operands[2]) == 128
16074               || (INTVAL (operands[2]) < 0
16075                   && INTVAL (operands[2]) != -128)))
16076         {
16077           operands[2] = GEN_INT (-INTVAL (operands[2]));
16078           return "sub{l}\t{%2, %0|%0, %2}";
16079         }
16080       return "add{l}\t{%2, %0|%0, %2}";
16081
16082     case TYPE_LEA:
16083       operands[2] = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
16084       return "lea{l}\t{%a2, %0|%0, %a2}";
16085
16086     default:
16087       abort ();
16088     }
16089 }
16090   [(set (attr "type")
16091         (cond [(eq_attr "alternative" "0")
16092                  (const_string "alu")
16093                (match_operand:SI 2 "const0_operand" "")
16094                  (const_string "imov")
16095               ]
16096               (const_string "lea")))
16097    (set_attr "mode" "SI")])
16098
16099 (define_insn "pro_epilogue_adjust_stack_rex64"
16100   [(set (match_operand:DI 0 "register_operand" "=r,r")
16101         (plus:DI (match_operand:DI 1 "register_operand" "0,r")
16102                  (match_operand:DI 2 "x86_64_immediate_operand" "e,e")))
16103    (clobber (reg:CC 17))
16104    (clobber (mem:BLK (scratch)))]
16105   "TARGET_64BIT"
16106 {
16107   switch (get_attr_type (insn))
16108     {
16109     case TYPE_IMOV:
16110       return "mov{q}\t{%1, %0|%0, %1}";
16111
16112     case TYPE_ALU:
16113       if (GET_CODE (operands[2]) == CONST_INT
16114           && (INTVAL (operands[2]) == 128
16115               || (INTVAL (operands[2]) < 0
16116                   && INTVAL (operands[2]) != -128)))
16117         {
16118           operands[2] = GEN_INT (-INTVAL (operands[2]));
16119           return "sub{q}\t{%2, %0|%0, %2}";
16120         }
16121       return "add{q}\t{%2, %0|%0, %2}";
16122
16123     case TYPE_LEA:
16124       operands[2] = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
16125       return "lea{q}\t{%a2, %0|%0, %a2}";
16126
16127     default:
16128       abort ();
16129     }
16130 }
16131   [(set (attr "type")
16132         (cond [(eq_attr "alternative" "0")
16133                  (const_string "alu")
16134                (match_operand:DI 2 "const0_operand" "")
16135                  (const_string "imov")
16136               ]
16137               (const_string "lea")))
16138    (set_attr "mode" "DI")])
16139
16140
16141 ;; Placeholder for the conditional moves.  This one is split eighter to SSE
16142 ;; based moves emulation or to usual cmove sequence.  Little bit unfortunate
16143 ;; fact is that compares supported by the cmp??ss instructions are exactly
16144 ;; swapped of those supported by cmove sequence.
16145 ;; The EQ/NE comparisons also needs bit care, since they are not directly
16146 ;; supported by i387 comparisons and we do need to emit two conditional moves
16147 ;; in tandem.
16148
16149 (define_insn "sse_movsfcc"
16150   [(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")
16151         (if_then_else:SF (match_operator 1 "sse_comparison_operator"
16152                         [(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")
16153                          (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")])
16154                       (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")
16155                       (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")))
16156    (clobber (match_scratch:SF 6 "=2,&4,X,X,X,X,X,X,X,X"))
16157    (clobber (reg:CC 17))]
16158   "TARGET_SSE
16159    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)
16160    && (!TARGET_IEEE_FP
16161        || (GET_CODE (operands[1]) != EQ && GET_CODE (operands[1]) != NE))"
16162   "#")
16163
16164 (define_insn "sse_movsfcc_eq"
16165   [(set (match_operand:SF 0 "register_operand" "=&x#rf,x#rf,?f#xr,?f#xr,?r#xf,?r#xf")
16166         (if_then_else:SF (eq (match_operand:SF 3 "nonimmediate_operand" "%0#fx,x#fx,f#x,xm#f,f#x,xm#f")
16167                              (match_operand:SF 4 "nonimmediate_operand" "xm#f,xm#f,f#x,x#f,f#x,x#f"))
16168                       (match_operand:SF 1 "nonimmediate_operand" "x#fr,0#fr,0#fx,0#fx,0#rx,0#rx")
16169                       (match_operand:SF 2 "nonimmediate_operand" "x#fr,x#fr,f#fx,f#fx,rm#rx,rm#rx")))
16170    (clobber (match_scratch:SF 5 "=1,&3,X,X,X,X"))
16171    (clobber (reg:CC 17))]
16172   "TARGET_SSE
16173    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)"
16174   "#")
16175
16176 (define_insn "sse_movdfcc"
16177   [(set (match_operand:DF 0 "register_operand" "=&x#rf,x#rf,?f#xr,?f#xr,?f#xr,?f#xr,?r#xf,?r#xf,?r#xf,?r#xf")
16178         (if_then_else:DF (match_operator 1 "sse_comparison_operator"
16179                         [(match_operand:DF 4 "nonimmediate_operand" "0#fx,x#fx,f#x,f#x,xm#f,xm#f,f#x,f#x,xm#f,xm#f")
16180                          (match_operand:DF 5 "nonimmediate_operand" "xm#f,xm#f,f#x,f#x,x#f,x#f,f#x,f#x,x#f,x#f")])
16181                       (match_operand:DF 2 "nonimmediate_operand" "x#fr,0#fr,f#fx,0#fx,f#fx,0#fx,rm#rx,0#rx,rm#rx,0#rx")
16182                       (match_operand:DF 3 "nonimmediate_operand" "x#fr,x#fr,0#fx,f#fx,0#fx,f#fx,0#fx,rm#rx,0#rx,rm#rx")))
16183    (clobber (match_scratch:DF 6 "=2,&4,X,X,X,X,X,X,X,X"))
16184    (clobber (reg:CC 17))]
16185   "TARGET_SSE2
16186    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)
16187    && (!TARGET_IEEE_FP
16188        || (GET_CODE (operands[1]) != EQ && GET_CODE (operands[1]) != NE))"
16189   "#")
16190
16191 (define_insn "sse_movdfcc_eq"
16192   [(set (match_operand:DF 0 "register_operand" "=&x#rf,x#rf,?f#xr,?f#xr,?r#xf,?r#xf")
16193         (if_then_else:DF (eq (match_operand:DF 3 "nonimmediate_operand" "%0#fx,x#fx,f#x,xm#f,f#x,xm#f")
16194                              (match_operand:DF 4 "nonimmediate_operand" "xm#f,xm#f,f#x,x#f,f#x,x#f"))
16195                       (match_operand:DF 1 "nonimmediate_operand" "x#fr,0#fr,0#fx,0#fx,0#rx,0#rx")
16196                       (match_operand:DF 2 "nonimmediate_operand" "x#fr,x#fr,f#fx,f#fx,rm#rx,rm#rx")))
16197    (clobber (match_scratch:DF 5 "=1,&3,X,X,X,X"))
16198    (clobber (reg:CC 17))]
16199   "TARGET_SSE
16200    && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)"
16201   "#")
16202
16203 ;; For non-sse moves just expand the usual cmove sequence.
16204 (define_split
16205   [(set (match_operand 0 "register_operand" "")
16206         (if_then_else (match_operator 1 "comparison_operator"
16207                         [(match_operand 4 "nonimmediate_operand" "")
16208                          (match_operand 5 "register_operand" "")])
16209                       (match_operand 2 "nonimmediate_operand" "")
16210                       (match_operand 3 "nonimmediate_operand" "")))
16211    (clobber (match_operand 6 "" ""))
16212    (clobber (reg:CC 17))]
16213   "!SSE_REG_P (operands[0]) && reload_completed
16214    && VALID_SSE_REG_MODE (GET_MODE (operands[0]))"
16215   [(const_int 0)]
16216 {
16217    ix86_compare_op0 = operands[5];
16218    ix86_compare_op1 = operands[4];
16219    operands[1] = gen_rtx_fmt_ee (swap_condition (GET_CODE (operands[1])),
16220                                  VOIDmode, operands[5], operands[4]);
16221    ix86_expand_fp_movcc (operands);
16222    DONE;
16223 })
16224
16225 ;; Split SSE based conditional move into seqence:
16226 ;; cmpCC op0, op4   -  set op0 to 0 or ffffffff depending on the comparison
16227 ;; and   op2, op0   -  zero op2 if comparison was false
16228 ;; nand  op0, op3   -  load op3 to op0 if comparison was false
16229 ;; or    op2, op0   -  get the non-zero one into the result.
16230 (define_split
16231   [(set (match_operand 0 "register_operand" "")
16232         (if_then_else (match_operator 1 "sse_comparison_operator"
16233                         [(match_operand 4 "register_operand" "")
16234                          (match_operand 5 "nonimmediate_operand" "")])
16235                       (match_operand 2 "register_operand" "")
16236                       (match_operand 3 "register_operand" "")))
16237    (clobber (match_operand 6 "" ""))
16238    (clobber (reg:CC 17))]
16239   "SSE_REG_P (operands[0]) && reload_completed"
16240   [(set (match_dup 4) (match_op_dup 1 [(match_dup 4) (match_dup 5)]))
16241    (set (subreg:TI (match_dup 2) 0) (and:TI (subreg:TI (match_dup 2) 0)
16242                                             (subreg:TI (match_dup 4) 0)))
16243    (set (subreg:TI (match_dup 4) 0) (and:TI (not:TI (subreg:TI (match_dup 4) 0))
16244                                             (subreg:TI (match_dup 3) 0)))
16245    (set (subreg:TI (match_dup 0) 0) (ior:TI (subreg:TI (match_dup 6) 0)
16246                                             (subreg:TI (match_dup 7) 0)))]
16247 {
16248   PUT_MODE (operands[1], GET_MODE (operands[0]));
16249   if (operands_match_p (operands[0], operands[4]))
16250     operands[6] = operands[4], operands[7] = operands[2];
16251   else
16252     operands[6] = operands[2], operands[7] = operands[4];
16253 })
16254
16255 ;; Special case of conditional move we can handle effectivly.
16256 ;; Do not brother with the integer/floating point case, since these are
16257 ;; bot considerably slower, unlike in the generic case.
16258 (define_insn "*sse_movsfcc_const0_1"
16259   [(set (match_operand:SF 0 "register_operand" "=x")
16260         (if_then_else:SF (match_operator 1 "sse_comparison_operator"
16261                         [(match_operand:SF 4 "register_operand" "0")
16262                          (match_operand:SF 5 "nonimmediate_operand" "xm")])
16263                       (match_operand:SF 2 "register_operand" "x")
16264                       (match_operand:SF 3 "const0_operand" "X")))]
16265   "TARGET_SSE"
16266   "#")
16267
16268 (define_insn "*sse_movsfcc_const0_2"
16269   [(set (match_operand:SF 0 "register_operand" "=x")
16270         (if_then_else:SF (match_operator 1 "sse_comparison_operator"
16271                         [(match_operand:SF 4 "register_operand" "0")
16272                          (match_operand:SF 5 "nonimmediate_operand" "xm")])
16273                       (match_operand:SF 2 "const0_operand" "x")
16274                       (match_operand:SF 3 "register_operand" "X")))]
16275   "TARGET_SSE"
16276   "#")
16277
16278 (define_insn "*sse_movsfcc_const0_3"
16279   [(set (match_operand:SF 0 "register_operand" "=x")
16280         (if_then_else:SF (match_operator 1 "fcmov_comparison_operator"
16281                         [(match_operand:SF 4 "nonimmediate_operand" "xm")
16282                          (match_operand:SF 5 "register_operand" "0")])
16283                       (match_operand:SF 2 "register_operand" "x")
16284                       (match_operand:SF 3 "const0_operand" "X")))]
16285   "TARGET_SSE"
16286   "#")
16287
16288 (define_insn "*sse_movsfcc_const0_4"
16289   [(set (match_operand:SF 0 "register_operand" "=x")
16290         (if_then_else:SF (match_operator 1 "fcmov_comparison_operator"
16291                         [(match_operand:SF 4 "nonimmediate_operand" "xm")
16292                          (match_operand:SF 5 "register_operand" "0")])
16293                       (match_operand:SF 2 "const0_operand" "x")
16294                       (match_operand:SF 3 "register_operand" "X")))]
16295   "TARGET_SSE"
16296   "#")
16297
16298 (define_insn "*sse_movdfcc_const0_1"
16299   [(set (match_operand:SF 0 "register_operand" "=x")
16300         (if_then_else:SF (match_operator 1 "sse_comparison_operator"
16301                         [(match_operand:SF 4 "register_operand" "0")
16302                          (match_operand:SF 5 "nonimmediate_operand" "xm")])
16303                       (match_operand:SF 2 "register_operand" "x")
16304                       (match_operand:SF 3 "const0_operand" "X")))]
16305   "TARGET_SSE2"
16306   "#")
16307
16308 (define_insn "*sse_movdfcc_const0_2"
16309   [(set (match_operand:SF 0 "register_operand" "=x")
16310         (if_then_else:SF (match_operator 1 "sse_comparison_operator"
16311                         [(match_operand:SF 4 "register_operand" "0")
16312                          (match_operand:SF 5 "nonimmediate_operand" "xm")])
16313                       (match_operand:SF 2 "const0_operand" "x")
16314                       (match_operand:SF 3 "register_operand" "X")))]
16315   "TARGET_SSE2"
16316   "#")
16317
16318 (define_insn "*sse_movdfcc_const0_3"
16319   [(set (match_operand:SF 0 "register_operand" "=x")
16320         (if_then_else:SF (match_operator 1 "fcmov_comparison_operator"
16321                         [(match_operand:SF 4 "nonimmediate_operand" "xm")
16322                          (match_operand:SF 5 "register_operand" "0")])
16323                       (match_operand:SF 2 "register_operand" "x")
16324                       (match_operand:SF 3 "const0_operand" "X")))]
16325   "TARGET_SSE2"
16326   "#")
16327
16328 (define_insn "*sse_movdfcc_const0_4"
16329   [(set (match_operand:SF 0 "register_operand" "=x")
16330         (if_then_else:SF (match_operator 1 "fcmov_comparison_operator"
16331                         [(match_operand:SF 4 "nonimmediate_operand" "xm")
16332                          (match_operand:SF 5 "register_operand" "0")])
16333                       (match_operand:SF 2 "const0_operand" "x")
16334                       (match_operand:SF 3 "register_operand" "X")))]
16335   "TARGET_SSE2"
16336   "#")
16337
16338 (define_split
16339   [(set (match_operand 0 "register_operand" "")
16340         (if_then_else (match_operator 1 "comparison_operator"
16341                         [(match_operand 4 "register_operand" "")
16342                          (match_operand 5 "nonimmediate_operand" "")])
16343                       (match_operand 2 "nonmemory_operand" "")
16344                       (match_operand 3 "nonmemory_operand" "")))]
16345   "SSE_REG_P (operands[0]) && reload_completed
16346    && (const0_operand (operands[2], GET_MODE (operands[0]))
16347        || const0_operand (operands[3], GET_MODE (operands[0])))"
16348   [(set (match_dup 0) (match_op_dup 1 [(match_dup 0) (match_dup 5)]))
16349    (set (subreg:TI (match_dup 0) 0) (and:TI (match_dup 6)
16350                                             (subreg:TI (match_dup 7) 0)))]
16351 {
16352   PUT_MODE (operands[1], GET_MODE (operands[0]));
16353   if (!sse_comparison_operator (operands[1], VOIDmode))
16354     {
16355       rtx tmp = operands[5];
16356       operands[5] = operands[4];
16357       operands[4] = tmp;
16358       PUT_CODE (operands[1], swap_condition (GET_CODE (operands[1])));
16359     }
16360   if (const0_operand (operands[2], GET_MODE (operands[0])))
16361     {
16362       operands[7] = operands[3];
16363       operands[6] = gen_rtx_NOT (TImode, gen_rtx_SUBREG (TImode, operands[0],
16364                                                          0));
16365     }
16366   else
16367     {
16368       operands[7] = operands[2];
16369       operands[6] = gen_rtx_SUBREG (TImode, operands[0], 0);
16370     }
16371 })
16372
16373 (define_expand "allocate_stack_worker"
16374   [(match_operand:SI 0 "register_operand" "")]
16375   "TARGET_STACK_PROBE"
16376 {
16377   if (TARGET_64BIT)
16378     emit_insn (gen_allocate_stack_worker_rex64 (operands[0]));
16379   else
16380     emit_insn (gen_allocate_stack_worker_1 (operands[0]));
16381   DONE;
16382 })
16383
16384 (define_insn "allocate_stack_worker_1"
16385   [(unspec:SI [(match_operand:SI 0 "register_operand" "a")] 3)
16386    (set (reg:SI 7) (minus:SI (reg:SI 7) (match_dup 0)))
16387    (clobber (match_dup 0))
16388    (clobber (reg:CC 17))]
16389   "TARGET_STACK_PROBE && !TARGET_64BIT"
16390   "call\t__alloca"
16391   [(set_attr "type" "multi")
16392    (set_attr "length" "5")])
16393
16394 (define_insn "allocate_stack_worker_rex64"
16395   [(unspec:DI [(match_operand:DI 0 "register_operand" "a")] 3)
16396    (set (reg:DI 7) (minus:DI (reg:DI 7) (match_dup 0)))
16397    (clobber (match_dup 0))
16398    (clobber (reg:CC 17))]
16399   "TARGET_STACK_PROBE && TARGET_64BIT"
16400   "call\t__alloca"
16401   [(set_attr "type" "multi")
16402    (set_attr "length" "5")])
16403
16404 (define_expand "allocate_stack"
16405   [(parallel [(set (match_operand:SI 0 "register_operand" "=r")
16406                    (minus:SI (reg:SI 7)
16407                              (match_operand:SI 1 "general_operand" "")))
16408               (clobber (reg:CC 17))])
16409    (parallel [(set (reg:SI 7)
16410                    (minus:SI (reg:SI 7) (match_dup 1)))
16411               (clobber (reg:CC 17))])]
16412   "TARGET_STACK_PROBE"
16413 {
16414 #ifdef CHECK_STACK_LIMIT
16415   if (GET_CODE (operands[1]) == CONST_INT
16416       && INTVAL (operands[1]) < CHECK_STACK_LIMIT)
16417     emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx,
16418                            operands[1]));
16419   else 
16420 #endif
16421     emit_insn (gen_allocate_stack_worker (copy_to_mode_reg (SImode,
16422                                                             operands[1])));
16423
16424   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
16425   DONE;
16426 })
16427
16428 (define_expand "builtin_setjmp_receiver"
16429   [(label_ref (match_operand 0 "" ""))]
16430   "flag_pic && !TARGET_64BIT"
16431 {
16432   load_pic_register ();
16433   DONE;
16434 })
16435 \f
16436 ;; Avoid redundant prefixes by splitting HImode arithmetic to SImode.
16437
16438 (define_split
16439   [(set (match_operand 0 "register_operand" "")
16440         (match_operator 3 "promotable_binary_operator"
16441            [(match_operand 1 "register_operand" "")
16442             (match_operand 2 "aligned_operand" "")]))
16443    (clobber (reg:CC 17))]
16444   "! TARGET_PARTIAL_REG_STALL && reload_completed
16445    && ((GET_MODE (operands[0]) == HImode 
16446         && (!optimize_size || GET_CODE (operands[2]) != CONST_INT
16447             || CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'K')))
16448        || (GET_MODE (operands[0]) == QImode 
16449            && (TARGET_PROMOTE_QImode || optimize_size)))"
16450   [(parallel [(set (match_dup 0)
16451                    (match_op_dup 3 [(match_dup 1) (match_dup 2)]))
16452               (clobber (reg:CC 17))])]
16453   "operands[0] = gen_lowpart (SImode, operands[0]);
16454    operands[1] = gen_lowpart (SImode, operands[1]);
16455    if (GET_CODE (operands[3]) != ASHIFT)
16456      operands[2] = gen_lowpart (SImode, operands[2]);
16457    PUT_MODE (operands[3], SImode);")
16458
16459 (define_split
16460   [(set (reg 17)
16461         (compare (and (match_operand 1 "aligned_operand" "")
16462                       (match_operand 2 "const_int_operand" ""))
16463                  (const_int 0)))
16464    (set (match_operand 0 "register_operand" "")
16465         (and (match_dup 1) (match_dup 2)))]
16466   "! TARGET_PARTIAL_REG_STALL && reload_completed
16467    && ix86_match_ccmode (insn, CCNOmode)
16468    && (GET_MODE (operands[0]) == HImode
16469        || (GET_MODE (operands[0]) == QImode 
16470            && (TARGET_PROMOTE_QImode || optimize_size)))"
16471   [(parallel [(set (reg:CCNO 17)
16472                    (compare:CCNO (and:SI (match_dup 1) (match_dup 2))
16473                                  (const_int 0)))
16474               (set (match_dup 0)
16475                    (and:SI (match_dup 1) (match_dup 2)))])]
16476   "operands[2]
16477      = GEN_INT (trunc_int_for_mode (INTVAL (operands[2])
16478                                     & GET_MODE_MASK (GET_MODE (operands[0])),
16479                                     SImode));
16480    operands[0] = gen_lowpart (SImode, operands[0]);
16481    operands[1] = gen_lowpart (SImode, operands[1]);")
16482
16483 (define_split
16484   [(set (reg 17)
16485         (compare (and (match_operand 0 "aligned_operand" "")
16486                       (match_operand 1 "const_int_operand" ""))
16487                  (const_int 0)))]
16488   "! TARGET_PARTIAL_REG_STALL && reload_completed
16489    && ix86_match_ccmode (insn, CCNOmode)
16490    && (GET_MODE (operands[0]) == HImode
16491        || (GET_MODE (operands[0]) == QImode 
16492            && (TARGET_PROMOTE_QImode || optimize_size)))"
16493   [(set (reg:CCNO 17)
16494         (compare:CCNO (and:SI (match_dup 0) (match_dup 1))
16495                       (const_int 0)))]
16496   "operands[1]
16497      = GEN_INT (trunc_int_for_mode (INTVAL (operands[1])
16498                                     & GET_MODE_MASK (GET_MODE (operands[0])),
16499                                     SImode));
16500    operands[0] = gen_lowpart (SImode, operands[0]);")
16501
16502 (define_split
16503   [(set (match_operand 0 "register_operand" "")
16504         (neg (match_operand 1 "register_operand" "")))
16505    (clobber (reg:CC 17))]
16506   "! TARGET_PARTIAL_REG_STALL && reload_completed
16507    && (GET_MODE (operands[0]) == HImode
16508        || (GET_MODE (operands[0]) == QImode 
16509            && (TARGET_PROMOTE_QImode || optimize_size)))"
16510   [(parallel [(set (match_dup 0)
16511                    (neg:SI (match_dup 1)))
16512               (clobber (reg:CC 17))])]
16513   "operands[0] = gen_lowpart (SImode, operands[0]);
16514    operands[1] = gen_lowpart (SImode, operands[1]);")
16515
16516 (define_split
16517   [(set (match_operand 0 "register_operand" "")
16518         (not (match_operand 1 "register_operand" "")))]
16519   "! TARGET_PARTIAL_REG_STALL && reload_completed
16520    && (GET_MODE (operands[0]) == HImode
16521        || (GET_MODE (operands[0]) == QImode 
16522            && (TARGET_PROMOTE_QImode || optimize_size)))"
16523   [(set (match_dup 0)
16524         (not:SI (match_dup 1)))]
16525   "operands[0] = gen_lowpart (SImode, operands[0]);
16526    operands[1] = gen_lowpart (SImode, operands[1]);")
16527
16528 (define_split 
16529   [(set (match_operand 0 "register_operand" "")
16530         (if_then_else (match_operator 1 "comparison_operator" 
16531                                 [(reg 17) (const_int 0)])
16532                       (match_operand 2 "register_operand" "")
16533                       (match_operand 3 "register_operand" "")))]
16534   "! TARGET_PARTIAL_REG_STALL && TARGET_CMOVE
16535    && (GET_MODE (operands[0]) == HImode
16536        || (GET_MODE (operands[0]) == QImode 
16537            && (TARGET_PROMOTE_QImode || optimize_size)))"
16538   [(set (match_dup 0)
16539         (if_then_else:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
16540   "operands[0] = gen_lowpart (SImode, operands[0]);
16541    operands[2] = gen_lowpart (SImode, operands[2]);
16542    operands[3] = gen_lowpart (SImode, operands[3]);")
16543                         
16544 \f
16545 ;; RTL Peephole optimizations, run before sched2.  These primarily look to
16546 ;; transform a complex memory operation into two memory to register operations.
16547
16548 ;; Don't push memory operands
16549 (define_peephole2
16550   [(set (match_operand:SI 0 "push_operand" "")
16551         (match_operand:SI 1 "memory_operand" ""))
16552    (match_scratch:SI 2 "r")]
16553   "! optimize_size && ! TARGET_PUSH_MEMORY"
16554   [(set (match_dup 2) (match_dup 1))
16555    (set (match_dup 0) (match_dup 2))]
16556   "")
16557
16558 (define_peephole2
16559   [(set (match_operand:DI 0 "push_operand" "")
16560         (match_operand:DI 1 "memory_operand" ""))
16561    (match_scratch:DI 2 "r")]
16562   "! optimize_size && ! TARGET_PUSH_MEMORY"
16563   [(set (match_dup 2) (match_dup 1))
16564    (set (match_dup 0) (match_dup 2))]
16565   "")
16566
16567 ;; We need to handle SFmode only, because DFmode and XFmode is split to
16568 ;; SImode pushes.
16569 (define_peephole2
16570   [(set (match_operand:SF 0 "push_operand" "")
16571         (match_operand:SF 1 "memory_operand" ""))
16572    (match_scratch:SF 2 "r")]
16573   "! optimize_size && ! TARGET_PUSH_MEMORY"
16574   [(set (match_dup 2) (match_dup 1))
16575    (set (match_dup 0) (match_dup 2))]
16576   "")
16577
16578 (define_peephole2
16579   [(set (match_operand:HI 0 "push_operand" "")
16580         (match_operand:HI 1 "memory_operand" ""))
16581    (match_scratch:HI 2 "r")]
16582   "! optimize_size && ! TARGET_PUSH_MEMORY"
16583   [(set (match_dup 2) (match_dup 1))
16584    (set (match_dup 0) (match_dup 2))]
16585   "")
16586
16587 (define_peephole2
16588   [(set (match_operand:QI 0 "push_operand" "")
16589         (match_operand:QI 1 "memory_operand" ""))
16590    (match_scratch:QI 2 "q")]
16591   "! optimize_size && ! TARGET_PUSH_MEMORY"
16592   [(set (match_dup 2) (match_dup 1))
16593    (set (match_dup 0) (match_dup 2))]
16594   "")
16595
16596 ;; Don't move an immediate directly to memory when the instruction
16597 ;; gets too big.
16598 (define_peephole2
16599   [(match_scratch:SI 1 "r")
16600    (set (match_operand:SI 0 "memory_operand" "")
16601         (const_int 0))]
16602   "! optimize_size
16603    && ! TARGET_USE_MOV0
16604    && TARGET_SPLIT_LONG_MOVES
16605    && get_attr_length (insn) >= ix86_cost->large_insn
16606    && peep2_regno_dead_p (0, FLAGS_REG)"
16607   [(parallel [(set (match_dup 1) (const_int 0))
16608               (clobber (reg:CC 17))])
16609    (set (match_dup 0) (match_dup 1))]
16610   "")
16611
16612 (define_peephole2
16613   [(match_scratch:HI 1 "r")
16614    (set (match_operand:HI 0 "memory_operand" "")
16615         (const_int 0))]
16616   "! optimize_size
16617    && ! TARGET_USE_MOV0
16618    && TARGET_SPLIT_LONG_MOVES
16619    && get_attr_length (insn) >= ix86_cost->large_insn
16620    && peep2_regno_dead_p (0, FLAGS_REG)"
16621   [(parallel [(set (match_dup 2) (const_int 0))
16622               (clobber (reg:CC 17))])
16623    (set (match_dup 0) (match_dup 1))]
16624   "operands[2] = gen_rtx_REG (SImode, true_regnum (operands[1]));")
16625
16626 (define_peephole2
16627   [(match_scratch:QI 1 "q")
16628    (set (match_operand:QI 0 "memory_operand" "")
16629         (const_int 0))]
16630   "! optimize_size
16631    && ! TARGET_USE_MOV0
16632    && TARGET_SPLIT_LONG_MOVES
16633    && get_attr_length (insn) >= ix86_cost->large_insn
16634    && peep2_regno_dead_p (0, FLAGS_REG)"
16635   [(parallel [(set (match_dup 2) (const_int 0))
16636               (clobber (reg:CC 17))])
16637    (set (match_dup 0) (match_dup 1))]
16638   "operands[2] = gen_rtx_REG (SImode, true_regnum (operands[1]));")
16639
16640 (define_peephole2
16641   [(match_scratch:SI 2 "r")
16642    (set (match_operand:SI 0 "memory_operand" "")
16643         (match_operand:SI 1 "immediate_operand" ""))]
16644   "! optimize_size
16645    && get_attr_length (insn) >= ix86_cost->large_insn
16646    && TARGET_SPLIT_LONG_MOVES"
16647   [(set (match_dup 2) (match_dup 1))
16648    (set (match_dup 0) (match_dup 2))]
16649   "")
16650
16651 (define_peephole2
16652   [(match_scratch:HI 2 "r")
16653    (set (match_operand:HI 0 "memory_operand" "")
16654         (match_operand:HI 1 "immediate_operand" ""))]
16655   "! optimize_size && get_attr_length (insn) >= ix86_cost->large_insn
16656   && TARGET_SPLIT_LONG_MOVES"
16657   [(set (match_dup 2) (match_dup 1))
16658    (set (match_dup 0) (match_dup 2))]
16659   "")
16660
16661 (define_peephole2
16662   [(match_scratch:QI 2 "q")
16663    (set (match_operand:QI 0 "memory_operand" "")
16664         (match_operand:QI 1 "immediate_operand" ""))]
16665   "! optimize_size && get_attr_length (insn) >= ix86_cost->large_insn
16666   && TARGET_SPLIT_LONG_MOVES"
16667   [(set (match_dup 2) (match_dup 1))
16668    (set (match_dup 0) (match_dup 2))]
16669   "")
16670
16671 ;; Don't compare memory with zero, load and use a test instead.
16672 (define_peephole2
16673   [(set (reg 17)
16674         (compare (match_operand:SI 0 "memory_operand" "")
16675                  (const_int 0)))
16676    (match_scratch:SI 3 "r")]
16677   "ix86_match_ccmode (insn, CCNOmode) && ! optimize_size"
16678   [(set (match_dup 3) (match_dup 0))
16679    (set (reg:CCNO 17) (compare:CCNO (match_dup 3) (const_int 0)))]
16680   "")
16681
16682 ;; NOT is not pairable on Pentium, while XOR is, but one byte longer. 
16683 ;; Don't split NOTs with a displacement operand, because resulting XOR
16684 ;; will not be pariable anyway.
16685 ;;
16686 ;; On AMD K6, NOT is vector decoded with memory operand that can not be
16687 ;; represented using a modRM byte.  The XOR replacement is long decoded,
16688 ;; so this split helps here as well.
16689 ;;
16690 ;; Note: Can't do this as a regular split because we can't get proper
16691 ;; lifetime information then.
16692
16693 (define_peephole2
16694   [(set (match_operand:SI 0 "nonimmediate_operand" "")
16695         (not:SI (match_operand:SI 1 "nonimmediate_operand" "")))]
16696   "!optimize_size
16697    && peep2_regno_dead_p (0, FLAGS_REG)
16698    && ((TARGET_PENTIUM 
16699         && (GET_CODE (operands[0]) != MEM
16700             || !memory_displacement_operand (operands[0], SImode)))
16701        || (TARGET_K6 && long_memory_operand (operands[0], SImode)))"
16702   [(parallel [(set (match_dup 0)
16703                    (xor:SI (match_dup 1) (const_int -1)))
16704               (clobber (reg:CC 17))])]
16705   "")
16706
16707 (define_peephole2
16708   [(set (match_operand:HI 0 "nonimmediate_operand" "")
16709         (not:HI (match_operand:HI 1 "nonimmediate_operand" "")))]
16710   "!optimize_size
16711    && peep2_regno_dead_p (0, FLAGS_REG)
16712    && ((TARGET_PENTIUM 
16713         && (GET_CODE (operands[0]) != MEM
16714             || !memory_displacement_operand (operands[0], HImode)))
16715        || (TARGET_K6 && long_memory_operand (operands[0], HImode)))"
16716   [(parallel [(set (match_dup 0)
16717                    (xor:HI (match_dup 1) (const_int -1)))
16718               (clobber (reg:CC 17))])]
16719   "")
16720
16721 (define_peephole2
16722   [(set (match_operand:QI 0 "nonimmediate_operand" "")
16723         (not:QI (match_operand:QI 1 "nonimmediate_operand" "")))]
16724   "!optimize_size
16725    && peep2_regno_dead_p (0, FLAGS_REG)
16726    && ((TARGET_PENTIUM 
16727         && (GET_CODE (operands[0]) != MEM
16728             || !memory_displacement_operand (operands[0], QImode)))
16729        || (TARGET_K6 && long_memory_operand (operands[0], QImode)))"
16730   [(parallel [(set (match_dup 0)
16731                    (xor:QI (match_dup 1) (const_int -1)))
16732               (clobber (reg:CC 17))])]
16733   "")
16734
16735 ;; Non pairable "test imm, reg" instructions can be translated to
16736 ;; "and imm, reg" if reg dies.  The "and" form is also shorter (one
16737 ;; byte opcode instead of two, have a short form for byte operands),
16738 ;; so do it for other CPUs as well.  Given that the value was dead,
16739 ;; this should not create any new dependancies.  Pass on the sub-word
16740 ;; versions if we're concerned about partial register stalls.
16741
16742 (define_peephole2
16743   [(set (reg 17)
16744         (compare (and:SI (match_operand:SI 0 "register_operand" "")
16745                          (match_operand:SI 1 "immediate_operand" ""))
16746                  (const_int 0)))]
16747   "ix86_match_ccmode (insn, CCNOmode)
16748    && (true_regnum (operands[0]) != 0
16749        || CONST_OK_FOR_LETTER_P (INTVAL (operands[1]), 'K'))
16750    && find_regno_note (insn, REG_DEAD, true_regnum (operands[0]))"
16751   [(parallel
16752      [(set (reg:CCNO 17)
16753            (compare:CCNO (and:SI (match_dup 0)
16754                                  (match_dup 1))
16755                          (const_int 0)))
16756       (set (match_dup 0)
16757            (and:SI (match_dup 0) (match_dup 1)))])]
16758   "")
16759
16760 ;; We don't need to handle HImode case, because it will be promoted to SImode
16761 ;; on ! TARGET_PARTIAL_REG_STALL
16762
16763 (define_peephole2
16764   [(set (reg 17)
16765         (compare (and:QI (match_operand:QI 0 "register_operand" "")
16766                          (match_operand:QI 1 "immediate_operand" ""))
16767                  (const_int 0)))]
16768   "! TARGET_PARTIAL_REG_STALL
16769    && ix86_match_ccmode (insn, CCNOmode)
16770    && true_regnum (operands[0]) != 0
16771    && find_regno_note (insn, REG_DEAD, true_regnum (operands[0]))"
16772   [(parallel
16773      [(set (reg:CCNO 17)
16774            (compare:CCNO (and:QI (match_dup 0)
16775                                  (match_dup 1))
16776                          (const_int 0)))
16777       (set (match_dup 0)
16778            (and:QI (match_dup 0) (match_dup 1)))])]
16779   "")
16780
16781 (define_peephole2
16782   [(set (reg 17)
16783         (compare
16784           (and:SI
16785             (zero_extract:SI
16786               (match_operand 0 "ext_register_operand" "")
16787               (const_int 8)
16788               (const_int 8))
16789             (match_operand 1 "const_int_operand" ""))
16790           (const_int 0)))]
16791   "! TARGET_PARTIAL_REG_STALL
16792    && ix86_match_ccmode (insn, CCNOmode)
16793    && true_regnum (operands[0]) != 0
16794    && find_regno_note (insn, REG_DEAD, true_regnum (operands[0]))"
16795   [(parallel [(set (reg:CCNO 17)
16796                    (compare:CCNO
16797                        (and:SI
16798                          (zero_extract:SI
16799                          (match_dup 0)
16800                          (const_int 8)
16801                          (const_int 8))
16802                         (match_dup 1))
16803                    (const_int 0)))
16804               (set (zero_extract:SI (match_dup 0)
16805                                     (const_int 8)
16806                                     (const_int 8))
16807                    (and:SI 
16808                      (zero_extract:SI
16809                        (match_dup 0)
16810                        (const_int 8)
16811                        (const_int 8))
16812                      (match_dup 1)))])]
16813   "")
16814
16815 ;; Don't do logical operations with memory inputs.
16816 (define_peephole2
16817   [(match_scratch:SI 2 "r")
16818    (parallel [(set (match_operand:SI 0 "register_operand" "")
16819                    (match_operator:SI 3 "arith_or_logical_operator"
16820                      [(match_dup 0)
16821                       (match_operand:SI 1 "memory_operand" "")]))
16822               (clobber (reg:CC 17))])]
16823   "! optimize_size && ! TARGET_READ_MODIFY"
16824   [(set (match_dup 2) (match_dup 1))
16825    (parallel [(set (match_dup 0)
16826                    (match_op_dup 3 [(match_dup 0) (match_dup 2)]))
16827               (clobber (reg:CC 17))])]
16828   "")
16829
16830 (define_peephole2
16831   [(match_scratch:SI 2 "r")
16832    (parallel [(set (match_operand:SI 0 "register_operand" "")
16833                    (match_operator:SI 3 "arith_or_logical_operator"
16834                      [(match_operand:SI 1 "memory_operand" "")
16835                       (match_dup 0)]))
16836               (clobber (reg:CC 17))])]
16837   "! optimize_size && ! TARGET_READ_MODIFY"
16838   [(set (match_dup 2) (match_dup 1))
16839    (parallel [(set (match_dup 0)
16840                    (match_op_dup 3 [(match_dup 2) (match_dup 0)]))
16841               (clobber (reg:CC 17))])]
16842   "")
16843
16844 ; Don't do logical operations with memory outputs
16845 ;
16846 ; These two don't make sense for PPro/PII -- we're expanding a 4-uop
16847 ; instruction into two 1-uop insns plus a 2-uop insn.  That last has
16848 ; the same decoder scheduling characteristics as the original.
16849
16850 (define_peephole2
16851   [(match_scratch:SI 2 "r")
16852    (parallel [(set (match_operand:SI 0 "memory_operand" "")
16853                    (match_operator:SI 3 "arith_or_logical_operator"
16854                      [(match_dup 0)
16855                       (match_operand:SI 1 "nonmemory_operand" "")]))
16856               (clobber (reg:CC 17))])]
16857   "! optimize_size && ! TARGET_READ_MODIFY_WRITE"
16858   [(set (match_dup 2) (match_dup 0))
16859    (parallel [(set (match_dup 2)
16860                    (match_op_dup 3 [(match_dup 2) (match_dup 1)]))
16861               (clobber (reg:CC 17))])
16862    (set (match_dup 0) (match_dup 2))]
16863   "")
16864
16865 (define_peephole2
16866   [(match_scratch:SI 2 "r")
16867    (parallel [(set (match_operand:SI 0 "memory_operand" "")
16868                    (match_operator:SI 3 "arith_or_logical_operator"
16869                      [(match_operand:SI 1 "nonmemory_operand" "")
16870                       (match_dup 0)]))
16871               (clobber (reg:CC 17))])]
16872   "! optimize_size && ! TARGET_READ_MODIFY_WRITE"
16873   [(set (match_dup 2) (match_dup 0))
16874    (parallel [(set (match_dup 2)
16875                    (match_op_dup 3 [(match_dup 1) (match_dup 2)]))
16876               (clobber (reg:CC 17))])
16877    (set (match_dup 0) (match_dup 2))]
16878   "")
16879
16880 ;; Attempt to always use XOR for zeroing registers.
16881 (define_peephole2
16882   [(set (match_operand 0 "register_operand" "")
16883         (const_int 0))]
16884   "(GET_MODE (operands[0]) == QImode
16885     || GET_MODE (operands[0]) == HImode
16886     || GET_MODE (operands[0]) == SImode
16887     || (GET_MODE (operands[0]) == DImode && TARGET_64BIT))
16888    && (! TARGET_USE_MOV0 || optimize_size)
16889    && peep2_regno_dead_p (0, FLAGS_REG)"
16890   [(parallel [(set (match_dup 0) (const_int 0))
16891               (clobber (reg:CC 17))])]
16892   "operands[0] = gen_rtx_REG (GET_MODE (operands[0]) == DImode ? DImode : SImode,
16893                               true_regnum (operands[0]));")
16894
16895 (define_peephole2
16896   [(set (strict_low_part (match_operand 0 "register_operand" ""))
16897         (const_int 0))]
16898   "(GET_MODE (operands[0]) == QImode
16899     || GET_MODE (operands[0]) == HImode)
16900    && (! TARGET_USE_MOV0 || optimize_size)
16901    && peep2_regno_dead_p (0, FLAGS_REG)"
16902   [(parallel [(set (strict_low_part (match_dup 0)) (const_int 0))
16903               (clobber (reg:CC 17))])])
16904
16905 ;; For HI and SI modes, or $-1,reg is smaller than mov $-1,reg.
16906 (define_peephole2
16907   [(set (match_operand 0 "register_operand" "")
16908         (const_int -1))]
16909   "(GET_MODE (operands[0]) == HImode
16910     || GET_MODE (operands[0]) == SImode 
16911     || (GET_MODE (operands[0]) == DImode && TARGET_64BIT))
16912    && (optimize_size || TARGET_PENTIUM)
16913    && peep2_regno_dead_p (0, FLAGS_REG)"
16914   [(parallel [(set (match_dup 0) (const_int -1))
16915               (clobber (reg:CC 17))])]
16916   "operands[0] = gen_rtx_REG (GET_MODE (operands[0]) == DImode ? DImode : SImode,
16917                               true_regnum (operands[0]));")
16918
16919 ;; Attempt to convert simple leas to adds. These can be created by
16920 ;; move expanders.
16921 (define_peephole2
16922   [(set (match_operand:SI 0 "register_operand" "")
16923         (plus:SI (match_dup 0)
16924                  (match_operand:SI 1 "nonmemory_operand" "")))]
16925   "peep2_regno_dead_p (0, FLAGS_REG)"
16926   [(parallel [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
16927               (clobber (reg:CC 17))])]
16928   "")
16929
16930 (define_peephole2
16931   [(set (match_operand:SI 0 "register_operand" "")
16932         (subreg:SI (plus:DI (match_operand:DI 1 "register_operand" "")
16933                             (match_operand:DI 2 "nonmemory_operand" "")) 0))]
16934   "peep2_regno_dead_p (0, FLAGS_REG) && REGNO (operands[0]) == REGNO (operands[1])"
16935   [(parallel [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))
16936               (clobber (reg:CC 17))])]
16937   "operands[2] = gen_lowpart (SImode, operands[2]);")
16938
16939 (define_peephole2
16940   [(set (match_operand:DI 0 "register_operand" "")
16941         (plus:DI (match_dup 0)
16942                  (match_operand:DI 1 "x86_64_general_operand" "")))]
16943   "peep2_regno_dead_p (0, FLAGS_REG)"
16944   [(parallel [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
16945               (clobber (reg:CC 17))])]
16946   "")
16947
16948 (define_peephole2
16949   [(set (match_operand:SI 0 "register_operand" "")
16950         (mult:SI (match_dup 0)
16951                  (match_operand:SI 1 "const_int_operand" "")))]
16952   "exact_log2 (INTVAL (operands[1])) >= 0
16953    && peep2_regno_dead_p (0, FLAGS_REG)"
16954   [(parallel [(set (match_dup 0) (ashift:SI (match_dup 0) (match_dup 2)))
16955               (clobber (reg:CC 17))])]
16956   "operands[2] = GEN_INT (exact_log2 (INTVAL (operands[1])));")
16957
16958 (define_peephole2
16959   [(set (match_operand:DI 0 "register_operand" "")
16960         (mult:DI (match_dup 0)
16961                  (match_operand:DI 1 "const_int_operand" "")))]
16962   "exact_log2 (INTVAL (operands[1])) >= 0
16963    && peep2_regno_dead_p (0, FLAGS_REG)"
16964   [(parallel [(set (match_dup 0) (ashift:DI (match_dup 0) (match_dup 2)))
16965               (clobber (reg:CC 17))])]
16966   "operands[2] = GEN_INT (exact_log2 (INTVAL (operands[1])));")
16967
16968 (define_peephole2
16969   [(set (match_operand:SI 0 "register_operand" "")
16970         (subreg:SI (mult:DI (match_operand:DI 1 "register_operand" "")
16971                    (match_operand:DI 2 "const_int_operand" "")) 0))]
16972   "exact_log2 (INTVAL (operands[1])) >= 0
16973    && REGNO (operands[0]) == REGNO (operands[1])
16974    && peep2_regno_dead_p (0, FLAGS_REG)"
16975   [(parallel [(set (match_dup 0) (ashift:SI (match_dup 0) (match_dup 2)))
16976               (clobber (reg:CC 17))])]
16977   "operands[2] = GEN_INT (exact_log2 (INTVAL (operands[2])));")
16978
16979 ;; The ESP adjustments can be done by the push and pop instructions.  Resulting
16980 ;; code is shorter, since push is only 1 byte, while add imm, %esp 3 bytes.  On
16981 ;; many CPUs it is also faster, since special hardware to avoid esp
16982 ;; dependancies is present.
16983
16984 ;; While some of these converisons may be done using splitters, we use peepholes
16985 ;; in order to allow combine_stack_adjustments pass to see nonobfuscated RTL.
16986
16987 ;; Convert prologue esp substractions to push.
16988 ;; We need register to push.  In order to keep verify_flow_info happy we have
16989 ;; two choices
16990 ;; - use scratch and clobber it in order to avoid dependencies
16991 ;; - use already live register
16992 ;; We can't use the second way right now, since there is no reliable way how to
16993 ;; verify that given register is live.  First choice will also most likely in
16994 ;; fewer dependencies.  On the place of esp adjustments it is very likely that
16995 ;; call clobbered registers are dead.  We may want to use base pointer as an
16996 ;; alternative when no register is available later.
16997
16998 (define_peephole2
16999   [(match_scratch:SI 0 "r")
17000    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -4)))
17001               (clobber (reg:CC 17))
17002               (clobber (mem:BLK (scratch)))])]
17003   "optimize_size || !TARGET_SUB_ESP_4"
17004   [(clobber (match_dup 0))
17005    (parallel [(set (mem:SI (pre_dec:SI (reg:SI 7))) (match_dup 0))
17006               (clobber (mem:BLK (scratch)))])])
17007
17008 (define_peephole2
17009   [(match_scratch:SI 0 "r")
17010    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -8)))
17011               (clobber (reg:CC 17))
17012               (clobber (mem:BLK (scratch)))])]
17013   "optimize_size || !TARGET_SUB_ESP_8"
17014   [(clobber (match_dup 0))
17015    (set (mem:SI (pre_dec:SI (reg:SI 7))) (match_dup 0))
17016    (parallel [(set (mem:SI (pre_dec:SI (reg:SI 7))) (match_dup 0))
17017               (clobber (mem:BLK (scratch)))])])
17018
17019 ;; Convert esp substractions to push.
17020 (define_peephole2
17021   [(match_scratch:SI 0 "r")
17022    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -4)))
17023               (clobber (reg:CC 17))])]
17024   "optimize_size || !TARGET_SUB_ESP_4"
17025   [(clobber (match_dup 0))
17026    (set (mem:SI (pre_dec:SI (reg:SI 7))) (match_dup 0))])
17027
17028 (define_peephole2
17029   [(match_scratch:SI 0 "r")
17030    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -8)))
17031               (clobber (reg:CC 17))])]
17032   "optimize_size || !TARGET_SUB_ESP_8"
17033   [(clobber (match_dup 0))
17034    (set (mem:SI (pre_dec:SI (reg:SI 7))) (match_dup 0))
17035    (set (mem:SI (pre_dec:SI (reg:SI 7))) (match_dup 0))])
17036
17037 ;; Convert epilogue deallocator to pop.
17038 (define_peephole2
17039   [(match_scratch:SI 0 "r")
17040    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))
17041               (clobber (reg:CC 17))
17042               (clobber (mem:BLK (scratch)))])]
17043   "optimize_size || !TARGET_ADD_ESP_4"
17044   [(parallel [(set (match_dup 0) (mem:SI (reg:SI 7)))
17045               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))
17046               (clobber (mem:BLK (scratch)))])]
17047   "")
17048
17049 ;; Two pops case is tricky, since pop causes dependency on destination register.
17050 ;; We use two registers if available.
17051 (define_peephole2
17052   [(match_scratch:SI 0 "r")
17053    (match_scratch:SI 1 "r")
17054    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 8)))
17055               (clobber (reg:CC 17))
17056               (clobber (mem:BLK (scratch)))])]
17057   "optimize_size || !TARGET_ADD_ESP_8"
17058   [(parallel [(set (match_dup 0) (mem:SI (reg:SI 7)))
17059               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))
17060               (clobber (mem:BLK (scratch)))])
17061    (parallel [(set (match_dup 1) (mem:SI (reg:SI 7)))
17062               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))])]
17063   "")
17064
17065 (define_peephole2
17066   [(match_scratch:SI 0 "r")
17067    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 8)))
17068               (clobber (reg:CC 17))
17069               (clobber (mem:BLK (scratch)))])]
17070   "optimize_size"
17071   [(parallel [(set (match_dup 0) (mem:SI (reg:SI 7)))
17072               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))
17073               (clobber (mem:BLK (scratch)))])
17074    (parallel [(set (match_dup 0) (mem:SI (reg:SI 7)))
17075               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))])]
17076   "")
17077
17078 ;; Convert esp additions to pop.
17079 (define_peephole2
17080   [(match_scratch:SI 0 "r")
17081    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))
17082               (clobber (reg:CC 17))])]
17083   ""
17084   [(parallel [(set (match_dup 0) (mem:SI (reg:SI 7)))
17085               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))])]
17086   "")
17087
17088 ;; Two pops case is tricky, since pop causes dependency on destination register.
17089 ;; We use two registers if available.
17090 (define_peephole2
17091   [(match_scratch:SI 0 "r")
17092    (match_scratch:SI 1 "r")
17093    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 8)))
17094               (clobber (reg:CC 17))])]
17095   ""
17096   [(parallel [(set (match_dup 0) (mem:SI (reg:SI 7)))
17097               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))])
17098    (parallel [(set (match_dup 1) (mem:SI (reg:SI 7)))
17099               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))])]
17100   "")
17101
17102 (define_peephole2
17103   [(match_scratch:SI 0 "r")
17104    (parallel [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 8)))
17105               (clobber (reg:CC 17))])]
17106   "optimize_size"
17107   [(parallel [(set (match_dup 0) (mem:SI (reg:SI 7)))
17108               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))])
17109    (parallel [(set (match_dup 0) (mem:SI (reg:SI 7)))
17110               (set (reg:SI 7) (plus:SI (reg:SI 7) (const_int 4)))])]
17111   "")
17112 \f
17113 ;; Convert compares with 1 to shorter inc/dec operations when CF is not
17114 ;; required and register dies.
17115 (define_peephole2
17116   [(set (reg 17)
17117         (compare (match_operand:SI 0 "register_operand" "")
17118                  (match_operand:SI 1 "incdec_operand" "")))]
17119   "ix86_match_ccmode (insn, CCGCmode)
17120    && find_regno_note (insn, REG_DEAD, true_regnum (operands[0]))"
17121   [(parallel [(set (reg:CCGC 17)
17122                    (compare:CCGC (match_dup 0)
17123                                  (match_dup 1)))
17124               (clobber (match_dup 0))])]
17125   "")
17126
17127 (define_peephole2
17128   [(set (reg 17)
17129         (compare (match_operand:HI 0 "register_operand" "")
17130                  (match_operand:HI 1 "incdec_operand" "")))]
17131   "ix86_match_ccmode (insn, CCGCmode)
17132    && find_regno_note (insn, REG_DEAD, true_regnum (operands[0]))"
17133   [(parallel [(set (reg:CCGC 17)
17134                    (compare:CCGC (match_dup 0)
17135                                  (match_dup 1)))
17136               (clobber (match_dup 0))])]
17137   "")
17138
17139 (define_peephole2
17140   [(set (reg 17)
17141         (compare (match_operand:QI 0 "register_operand" "")
17142                  (match_operand:QI 1 "incdec_operand" "")))]
17143   "ix86_match_ccmode (insn, CCGCmode)
17144    && find_regno_note (insn, REG_DEAD, true_regnum (operands[0]))"
17145   [(parallel [(set (reg:CCGC 17)
17146                    (compare:CCGC (match_dup 0)
17147                                  (match_dup 1)))
17148               (clobber (match_dup 0))])]
17149   "")
17150
17151 ;; Convert compares with 128 to shorter add -128
17152 (define_peephole2
17153   [(set (reg 17)
17154         (compare (match_operand:SI 0 "register_operand" "")
17155                  (const_int 128)))]
17156   "ix86_match_ccmode (insn, CCGCmode)
17157    && find_regno_note (insn, REG_DEAD, true_regnum (operands[0]))"
17158   [(parallel [(set (reg:CCGC 17)
17159                    (compare:CCGC (match_dup 0)
17160                                  (const_int 128)))
17161               (clobber (match_dup 0))])]
17162   "")
17163
17164 (define_peephole2
17165   [(set (reg 17)
17166         (compare (match_operand:HI 0 "register_operand" "")
17167                  (const_int 128)))]
17168   "ix86_match_ccmode (insn, CCGCmode)
17169    && find_regno_note (insn, REG_DEAD, true_regnum (operands[0]))"
17170   [(parallel [(set (reg:CCGC 17)
17171                    (compare:CCGC (match_dup 0)
17172                                  (const_int 128)))
17173               (clobber (match_dup 0))])]
17174   "")
17175 \f
17176 (define_peephole2
17177   [(match_scratch:DI 0 "r")
17178    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -8)))
17179               (clobber (reg:CC 17))
17180               (clobber (mem:BLK (scratch)))])]
17181   "optimize_size || !TARGET_SUB_ESP_4"
17182   [(clobber (match_dup 0))
17183    (parallel [(set (mem:DI (pre_dec:DI (reg:DI 7))) (match_dup 0))
17184               (clobber (mem:BLK (scratch)))])])
17185
17186 (define_peephole2
17187   [(match_scratch:DI 0 "r")
17188    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -16)))
17189               (clobber (reg:CC 17))
17190               (clobber (mem:BLK (scratch)))])]
17191   "optimize_size || !TARGET_SUB_ESP_8"
17192   [(clobber (match_dup 0))
17193    (set (mem:DI (pre_dec:DI (reg:DI 7))) (match_dup 0))
17194    (parallel [(set (mem:DI (pre_dec:DI (reg:DI 7))) (match_dup 0))
17195               (clobber (mem:BLK (scratch)))])])
17196
17197 ;; Convert esp substractions to push.
17198 (define_peephole2
17199   [(match_scratch:DI 0 "r")
17200    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -8)))
17201               (clobber (reg:CC 17))])]
17202   "optimize_size || !TARGET_SUB_ESP_4"
17203   [(clobber (match_dup 0))
17204    (set (mem:DI (pre_dec:DI (reg:DI 7))) (match_dup 0))])
17205
17206 (define_peephole2
17207   [(match_scratch:DI 0 "r")
17208    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int -16)))
17209               (clobber (reg:CC 17))])]
17210   "optimize_size || !TARGET_SUB_ESP_8"
17211   [(clobber (match_dup 0))
17212    (set (mem:DI (pre_dec:DI (reg:DI 7))) (match_dup 0))
17213    (set (mem:DI (pre_dec:DI (reg:DI 7))) (match_dup 0))])
17214
17215 ;; Convert epilogue deallocator to pop.
17216 (define_peephole2
17217   [(match_scratch:DI 0 "r")
17218    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))
17219               (clobber (reg:CC 17))
17220               (clobber (mem:BLK (scratch)))])]
17221   "optimize_size || !TARGET_ADD_ESP_4"
17222   [(parallel [(set (match_dup 0) (mem:DI (reg:DI 7)))
17223               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))
17224               (clobber (mem:BLK (scratch)))])]
17225   "")
17226
17227 ;; Two pops case is tricky, since pop causes dependency on destination register.
17228 ;; We use two registers if available.
17229 (define_peephole2
17230   [(match_scratch:DI 0 "r")
17231    (match_scratch:DI 1 "r")
17232    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 16)))
17233               (clobber (reg:CC 17))
17234               (clobber (mem:BLK (scratch)))])]
17235   "optimize_size || !TARGET_ADD_ESP_8"
17236   [(parallel [(set (match_dup 0) (mem:DI (reg:DI 7)))
17237               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))
17238               (clobber (mem:BLK (scratch)))])
17239    (parallel [(set (match_dup 1) (mem:DI (reg:DI 7)))
17240               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))])]
17241   "")
17242
17243 (define_peephole2
17244   [(match_scratch:DI 0 "r")
17245    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 16)))
17246               (clobber (reg:CC 17))
17247               (clobber (mem:BLK (scratch)))])]
17248   "optimize_size"
17249   [(parallel [(set (match_dup 0) (mem:DI (reg:DI 7)))
17250               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))
17251               (clobber (mem:BLK (scratch)))])
17252    (parallel [(set (match_dup 0) (mem:DI (reg:DI 7)))
17253               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))])]
17254   "")
17255
17256 ;; Convert esp additions to pop.
17257 (define_peephole2
17258   [(match_scratch:DI 0 "r")
17259    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))
17260               (clobber (reg:CC 17))])]
17261   ""
17262   [(parallel [(set (match_dup 0) (mem:DI (reg:DI 7)))
17263               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))])]
17264   "")
17265
17266 ;; Two pops case is tricky, since pop causes dependency on destination register.
17267 ;; We use two registers if available.
17268 (define_peephole2
17269   [(match_scratch:DI 0 "r")
17270    (match_scratch:DI 1 "r")
17271    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 16)))
17272               (clobber (reg:CC 17))])]
17273   ""
17274   [(parallel [(set (match_dup 0) (mem:DI (reg:DI 7)))
17275               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))])
17276    (parallel [(set (match_dup 1) (mem:DI (reg:DI 7)))
17277               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))])]
17278   "")
17279
17280 (define_peephole2
17281   [(match_scratch:DI 0 "r")
17282    (parallel [(set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 16)))
17283               (clobber (reg:CC 17))])]
17284   "optimize_size"
17285   [(parallel [(set (match_dup 0) (mem:DI (reg:DI 7)))
17286               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))])
17287    (parallel [(set (match_dup 0) (mem:DI (reg:DI 7)))
17288               (set (reg:DI 7) (plus:DI (reg:DI 7) (const_int 8)))])]
17289   "")
17290 \f
17291 ;; Call-value patterns last so that the wildcard operand does not
17292 ;; disrupt insn-recog's switch tables.
17293
17294 (define_insn "*call_value_pop_0"
17295   [(set (match_operand 0 "" "")
17296         (call (mem:QI (match_operand:SI 1 "constant_call_address_operand" ""))
17297               (match_operand:SI 2 "" "")))
17298    (set (reg:SI 7) (plus:SI (reg:SI 7)
17299                             (match_operand:SI 3 "immediate_operand" "")))]
17300   "!TARGET_64BIT"
17301 {
17302   if (SIBLING_CALL_P (insn))
17303     return "jmp\t%P1";
17304   else
17305     return "call\t%P1";
17306 }
17307   [(set_attr "type" "callv")])
17308
17309 (define_insn "*call_value_pop_1"
17310   [(set (match_operand 0 "" "")
17311         (call (mem:QI (match_operand:SI 1 "call_insn_operand" "rsm"))
17312               (match_operand:SI 2 "" "")))
17313    (set (reg:SI 7) (plus:SI (reg:SI 7)
17314                             (match_operand:SI 3 "immediate_operand" "i")))]
17315   "!TARGET_64BIT"
17316 {
17317   if (constant_call_address_operand (operands[1], QImode))
17318     {
17319       if (SIBLING_CALL_P (insn))
17320         return "jmp\t%P1";
17321       else
17322         return "call\t%P1";
17323     }
17324   if (SIBLING_CALL_P (insn))
17325     return "jmp\t%A1";
17326   else
17327     return "call\t%A1";
17328 }
17329   [(set_attr "type" "callv")])
17330
17331 (define_insn "*call_value_0"
17332   [(set (match_operand 0 "" "")
17333         (call (mem:QI (match_operand:SI 1 "constant_call_address_operand" ""))
17334               (match_operand:SI 2 "" "")))]
17335   "!TARGET_64BIT"
17336 {
17337   if (SIBLING_CALL_P (insn))
17338     return "jmp\t%P1";
17339   else
17340     return "call\t%P1";
17341 }
17342   [(set_attr "type" "callv")])
17343
17344 (define_insn "*call_value_0_rex64"
17345   [(set (match_operand 0 "" "")
17346         (call (mem:QI (match_operand:DI 1 "constant_call_address_operand" ""))
17347               (match_operand:DI 2 "const_int_operand" "")))]
17348   "TARGET_64BIT"
17349 {
17350   if (SIBLING_CALL_P (insn))
17351     return "jmp\t%P1";
17352   else
17353     return "call\t%P1";
17354 }
17355   [(set_attr "type" "callv")])
17356
17357 (define_insn "*call_value_1"
17358   [(set (match_operand 0 "" "")
17359         (call (mem:QI (match_operand:SI 1 "call_insn_operand" "rsm"))
17360               (match_operand:SI 2 "" "")))]
17361   "!TARGET_64BIT"
17362 {
17363   if (constant_call_address_operand (operands[1], QImode))
17364     {
17365       if (SIBLING_CALL_P (insn))
17366         return "jmp\t%P1";
17367       else
17368         return "call\t%P1";
17369     }
17370   if (SIBLING_CALL_P (insn))
17371     return "jmp\t%*%1";
17372   else
17373     return "call\t%*%1";
17374 }
17375   [(set_attr "type" "callv")])
17376
17377 (define_insn "*call_value_1_rex64"
17378   [(set (match_operand 0 "" "")
17379         (call (mem:QI (match_operand:DI 1 "call_insn_operand" "rsm"))
17380               (match_operand:DI 2 "" "")))]
17381   "TARGET_64BIT"
17382 {
17383   if (constant_call_address_operand (operands[1], QImode))
17384     {
17385       if (SIBLING_CALL_P (insn))
17386         return "jmp\t%P1";
17387       else
17388         return "call\t%P1";
17389     }
17390   if (SIBLING_CALL_P (insn))
17391     return "jmp\t%A1";
17392   else
17393     return "call\t%A1";
17394 }
17395   [(set_attr "type" "callv")])
17396 \f
17397 (define_insn "trap"
17398   [(trap_if (const_int 1) (const_int 5))]
17399   ""
17400   "int\t$5")
17401
17402 ;;; ix86 doesn't have conditional trap instructions, but we fake them
17403 ;;; for the sake of bounds checking.  By emitting bounds checks as
17404 ;;; conditional traps rather than as conditional jumps around
17405 ;;; unconditional traps we avoid introducing spurious basic-block
17406 ;;; boundaries and facilitate elimination of redundant checks.  In
17407 ;;; honor of the too-inflexible-for-BPs `bound' instruction, we use
17408 ;;; interrupt 5.
17409 ;;; 
17410 ;;; FIXME: Static branch prediction rules for ix86 are such that
17411 ;;; forward conditional branches predict as untaken.  As implemented
17412 ;;; below, pseudo conditional traps violate that rule.  We should use
17413 ;;; .pushsection/.popsection to place all of the `int 5's in a special
17414 ;;; section loaded at the end of the text segment and branch forward
17415 ;;; there on bounds-failure, and then jump back immediately (in case
17416 ;;; the system chooses to ignore bounds violations, or to report
17417 ;;; violations and continue execution).
17418
17419 (define_expand "conditional_trap"
17420   [(trap_if (match_operator 0 "comparison_operator"
17421              [(match_dup 2) (const_int 0)])
17422             (match_operand 1 "const_int_operand" ""))]
17423   ""
17424 {
17425   emit_insn (gen_rtx_TRAP_IF (VOIDmode,
17426                               ix86_expand_compare (GET_CODE (operands[0]),
17427                                                    NULL, NULL),
17428                               operands[1]));
17429   DONE;
17430 })
17431
17432 (define_insn "*conditional_trap_1"
17433   [(trap_if (match_operator 0 "comparison_operator"
17434              [(reg 17) (const_int 0)])
17435             (match_operand 1 "const_int_operand" ""))]
17436   ""
17437 {
17438   operands[2] = gen_label_rtx ();
17439   output_asm_insn ("j%c0\t%l2\; int\t%1", operands);
17440   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L",
17441                              CODE_LABEL_NUMBER (operands[2]));
17442   RET;
17443 })
17444
17445         ;; Pentium III SIMD instructions.
17446
17447 ;; Moves for SSE/MMX regs.
17448
17449 (define_insn "movv4sf_internal"
17450   [(set (match_operand:V4SF 0 "nonimmediate_operand" "=x,m")
17451         (match_operand:V4SF 1 "general_operand" "xm,x"))]
17452   "TARGET_SSE"
17453   ;; @@@ let's try to use movaps here.
17454   "movaps\t{%1, %0|%0, %1}"
17455   [(set_attr "type" "sse")])
17456
17457 (define_insn "movv4si_internal"
17458   [(set (match_operand:V4SI 0 "nonimmediate_operand" "=x,m")
17459         (match_operand:V4SI 1 "general_operand" "xm,x"))]
17460   "TARGET_SSE"
17461   ;; @@@ let's try to use movaps here.
17462   "movaps\t{%1, %0|%0, %1}"
17463   [(set_attr "type" "sse")])
17464
17465 (define_insn "movv8qi_internal"
17466   [(set (match_operand:V8QI 0 "nonimmediate_operand" "=y,m")
17467         (match_operand:V8QI 1 "general_operand" "ym,y"))]
17468   "TARGET_MMX"
17469   "movq\t{%1, %0|%0, %1}"
17470   [(set_attr "type" "mmx")])
17471
17472 (define_insn "movv4hi_internal"
17473   [(set (match_operand:V4HI 0 "nonimmediate_operand" "=y,m")
17474         (match_operand:V4HI 1 "general_operand" "ym,y"))]
17475   "TARGET_MMX"
17476   "movq\t{%1, %0|%0, %1}"
17477   [(set_attr "type" "mmx")])
17478
17479 (define_insn "movv2si_internal"
17480   [(set (match_operand:V2SI 0 "nonimmediate_operand" "=y,m")
17481         (match_operand:V2SI 1 "general_operand" "ym,y"))]
17482   "TARGET_MMX"
17483   "movq\t{%1, %0|%0, %1}"
17484   [(set_attr "type" "mmx")])
17485
17486 (define_expand "movti"
17487   [(set (match_operand:TI 0 "general_operand" "")
17488         (match_operand:TI 1 "general_operand" ""))]
17489   "TARGET_SSE"
17490 {
17491   /* For constants other than zero into memory.  We do not know how the
17492      instructions used to build constants modify the upper 64 bits
17493      of the register, once we have that information we may be able
17494      to handle some of them more efficiently.  */
17495   if ((reload_in_progress | reload_completed) == 0
17496       && register_operand (operands[0], TImode)
17497       && CONSTANT_P (operands[1]))
17498     {
17499       rtx addr = gen_reg_rtx (Pmode);
17500
17501       emit_move_insn (addr, XEXP (force_const_mem (TImode, operands[1]), 0));
17502       operands[1] = gen_rtx_MEM (TImode, addr);
17503     }
17504
17505   /* Make operand1 a register if it isn't already.  */
17506   if ((reload_in_progress | reload_completed) == 0
17507       && !register_operand (operands[0], TImode)
17508       && !register_operand (operands[1], TImode)
17509       && operands[1] != CONST0_RTX (TImode))
17510     {
17511       rtx temp = force_reg (TImode, operands[1]);
17512       emit_move_insn (operands[0], temp);
17513       DONE;
17514     }
17515 })
17516
17517 (define_expand "movv4sf"
17518   [(set (match_operand:V4SF 0 "general_operand" "")
17519         (match_operand:V4SF 1 "general_operand" ""))]
17520   "TARGET_SSE"
17521 {
17522   /* For constants other than zero into memory.  We do not know how the
17523      instructions used to build constants modify the upper 64 bits
17524      of the register, once we have that information we may be able
17525      to handle some of them more efficiently.  */
17526   if ((reload_in_progress | reload_completed) == 0
17527       && register_operand (operands[0], V4SFmode)
17528       && CONSTANT_P (operands[1]))
17529     {
17530       rtx addr = gen_reg_rtx (Pmode);
17531
17532       emit_move_insn (addr, XEXP (force_const_mem (V4SFmode, operands[1]), 0));
17533       operands[1] = gen_rtx_MEM (V4SFmode, addr);
17534     }
17535
17536   /* Make operand1 a register if it isn't already.  */
17537   if ((reload_in_progress | reload_completed) == 0
17538       && !register_operand (operands[0], V4SFmode)
17539       && !register_operand (operands[1], V4SFmode)
17540       && operands[1] != CONST0_RTX (V4SFmode))
17541     {
17542       rtx temp = force_reg (V4SFmode, operands[1]);
17543       emit_move_insn (operands[0], temp);
17544       DONE;
17545     }
17546 })
17547
17548 (define_expand "movv4si"
17549   [(set (match_operand:V4SI 0 "general_operand" "")
17550         (match_operand:V4SI 1 "general_operand" ""))]
17551   "TARGET_MMX"
17552 {
17553   /* For constants other than zero into memory.  We do not know how the
17554      instructions used to build constants modify the upper 64 bits
17555      of the register, once we have that information we may be able
17556      to handle some of them more efficiently.  */
17557   if ((reload_in_progress | reload_completed) == 0
17558       && register_operand (operands[0], V4SImode)
17559       && CONSTANT_P (operands[1]))
17560     {
17561       rtx addr = gen_reg_rtx (Pmode);
17562
17563       emit_move_insn (addr, XEXP (force_const_mem (V4SImode, operands[1]), 0));
17564       operands[1] = gen_rtx_MEM (V4SImode, addr);
17565     }
17566
17567   /* Make operand1 a register if it isn't already.  */
17568   if ((reload_in_progress | reload_completed) == 0
17569       && !register_operand (operands[0], V4SImode)
17570       && !register_operand (operands[1], V4SImode)
17571       && operands[1] != CONST0_RTX (V4SImode))
17572     {
17573       rtx temp = force_reg (V4SImode, operands[1]);
17574       emit_move_insn (operands[0], temp);
17575       DONE;
17576     }
17577 })
17578
17579 (define_expand "movv2si"
17580   [(set (match_operand:V2SI 0 "general_operand" "")
17581         (match_operand:V2SI 1 "general_operand" ""))]
17582   "TARGET_MMX"
17583 {
17584   /* For constants other than zero into memory.  We do not know how the
17585      instructions used to build constants modify the upper 64 bits
17586      of the register, once we have that information we may be able
17587      to handle some of them more efficiently.  */
17588   if ((reload_in_progress | reload_completed) == 0
17589       && register_operand (operands[0], V2SImode)
17590       && CONSTANT_P (operands[1]))
17591     {
17592       rtx addr = gen_reg_rtx (Pmode);
17593
17594       emit_move_insn (addr, XEXP (force_const_mem (V2SImode, operands[1]), 0));
17595       operands[1] = gen_rtx_MEM (V2SImode, addr);
17596     }
17597
17598   /* Make operand1 a register if it isn't already.  */
17599   if ((reload_in_progress | reload_completed) == 0
17600       && !register_operand (operands[0], V2SImode)
17601       && !register_operand (operands[1], V2SImode)
17602       && operands[1] != CONST0_RTX (V2SImode))
17603     {
17604       rtx temp = force_reg (V2SImode, operands[1]);
17605       emit_move_insn (operands[0], temp);
17606       DONE;
17607     }
17608 })
17609
17610 (define_expand "movv4hi"
17611   [(set (match_operand:V4HI 0 "general_operand" "")
17612         (match_operand:V4HI 1 "general_operand" ""))]
17613   "TARGET_MMX"
17614 {
17615   /* For constants other than zero into memory.  We do not know how the
17616      instructions used to build constants modify the upper 64 bits
17617      of the register, once we have that information we may be able
17618      to handle some of them more efficiently.  */
17619   if ((reload_in_progress | reload_completed) == 0
17620       && register_operand (operands[0], V4HImode)
17621       && CONSTANT_P (operands[1]))
17622     {
17623       rtx addr = gen_reg_rtx (Pmode);
17624
17625       emit_move_insn (addr, XEXP (force_const_mem (V4HImode, operands[1]), 0));
17626       operands[1] = gen_rtx_MEM (V4HImode, addr);
17627     }
17628
17629   /* Make operand1 a register if it isn't already.  */
17630   if ((reload_in_progress | reload_completed) == 0
17631       && !register_operand (operands[0], V4HImode)
17632       && !register_operand (operands[1], V4HImode)
17633       && operands[1] != CONST0_RTX (V4HImode))
17634     {
17635       rtx temp = force_reg (V4HImode, operands[1]);
17636       emit_move_insn (operands[0], temp);
17637       DONE;
17638     }
17639 })
17640
17641 (define_expand "movv8qi"
17642   [(set (match_operand:V8QI 0 "general_operand" "")
17643         (match_operand:V8QI 1 "general_operand" ""))]
17644   "TARGET_MMX"
17645 {
17646   /* For constants other than zero into memory.  We do not know how the
17647      instructions used to build constants modify the upper 64 bits
17648      of the register, once we have that information we may be able
17649      to handle some of them more efficiently.  */
17650   if ((reload_in_progress | reload_completed) == 0
17651       && register_operand (operands[0], V8QImode)
17652       && CONSTANT_P (operands[1]))
17653     {
17654       rtx addr = gen_reg_rtx (Pmode);
17655
17656       emit_move_insn (addr, XEXP (force_const_mem (V8QImode, operands[1]), 0));
17657       operands[1] = gen_rtx_MEM (V8QImode, addr);
17658     }
17659
17660   /* Make operand1 a register if it isn't already.  */
17661   if ((reload_in_progress | reload_completed) == 0
17662       && !register_operand (operands[0], V8QImode)
17663       && !register_operand (operands[1], V8QImode)
17664       && operands[1] != CONST0_RTX (V8QImode))
17665     {
17666       rtx temp = force_reg (V8QImode, operands[1]);
17667       emit_move_insn (operands[0], temp);
17668       DONE;
17669     }
17670 })
17671
17672 (define_insn_and_split "*pushti"
17673   [(set (match_operand:TI 0 "push_operand" "=<")
17674         (match_operand:TI 1 "nonmemory_operand" "x"))]
17675   "TARGET_SSE"
17676   "#"
17677   ""
17678   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -16)))
17679    (set (mem:TI (reg:SI 7)) (match_dup 1))]
17680   ""
17681   [(set_attr "type" "sse")])
17682
17683 (define_insn_and_split "*pushv4sf"
17684   [(set (match_operand:V4SF 0 "push_operand" "=<")
17685         (match_operand:V4SF 1 "nonmemory_operand" "x"))]
17686   "TARGET_SSE"
17687   "#"
17688   ""
17689   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -16)))
17690    (set (mem:V4SF (reg:SI 7)) (match_dup 1))]
17691   ""
17692   [(set_attr "type" "sse")])
17693
17694 (define_insn_and_split "*pushv4si"
17695   [(set (match_operand:V4SI 0 "push_operand" "=<")
17696         (match_operand:V4SI 1 "nonmemory_operand" "x"))]
17697   "TARGET_SSE"
17698   "#"
17699   ""
17700   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -16)))
17701    (set (mem:V4SI (reg:SI 7)) (match_dup 1))]
17702   ""
17703   [(set_attr "type" "sse")])
17704
17705 (define_insn_and_split "*pushv2si"
17706   [(set (match_operand:V2SI 0 "push_operand" "=<")
17707         (match_operand:V2SI 1 "nonmemory_operand" "y"))]
17708   "TARGET_MMX"
17709   "#"
17710   ""
17711   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -8)))
17712    (set (mem:V2SI (reg:SI 7)) (match_dup 1))]
17713   ""
17714   [(set_attr "type" "mmx")])
17715
17716 (define_insn_and_split "*pushv4hi"
17717   [(set (match_operand:V4HI 0 "push_operand" "=<")
17718         (match_operand:V4HI 1 "nonmemory_operand" "y"))]
17719   "TARGET_MMX"
17720   "#"
17721   ""
17722   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -8)))
17723    (set (mem:V4HI (reg:SI 7)) (match_dup 1))]
17724   ""
17725   [(set_attr "type" "mmx")])
17726
17727 (define_insn_and_split "*pushv8qi"
17728   [(set (match_operand:V8QI 0 "push_operand" "=<")
17729         (match_operand:V8QI 1 "nonmemory_operand" "y"))]
17730   "TARGET_MMX"
17731   "#"
17732   ""
17733   [(set (reg:SI 7) (plus:SI (reg:SI 7) (const_int -8)))
17734    (set (mem:V8QI (reg:SI 7)) (match_dup 1))]
17735   ""
17736   [(set_attr "type" "mmx")])
17737
17738 (define_insn "movti_internal"
17739   [(set (match_operand:TI 0 "nonimmediate_operand" "=x,m")
17740         (match_operand:TI 1 "general_operand" "xm,x"))]
17741   "TARGET_SSE"
17742   "@
17743    movaps\t{%1, %0|%0, %1}
17744    movaps\t{%1, %0|%0, %1}"
17745   [(set_attr "type" "sse")])
17746
17747 ;; These two patterns are useful for specifying exactly whether to use
17748 ;; movaps or movups
17749 (define_insn "sse_movaps"
17750   [(set (match_operand:V4SF 0 "nonimmediate_operand" "=x,m")
17751         (unspec:V4SF [(match_operand:V4SF 1 "general_operand" "xm,x")] 38))]
17752   "TARGET_SSE"
17753   "@
17754    movaps\t{%1, %0|%0, %1}
17755    movaps\t{%1, %0|%0, %1}"
17756   [(set_attr "type" "sse")])
17757
17758 (define_insn "sse_movups"
17759   [(set (match_operand:V4SF 0 "nonimmediate_operand" "=x,m")
17760         (unspec:V4SF [(match_operand:V4SF 1 "general_operand" "xm,x")] 39))]
17761   "TARGET_SSE"
17762   "@
17763    movups\t{%1, %0|%0, %1}
17764    movups\t{%1, %0|%0, %1}"
17765   [(set_attr "type" "sse")])
17766
17767
17768 ;; SSE Strange Moves.
17769
17770 (define_insn "sse_movmskps"
17771   [(set (match_operand:SI 0 "register_operand" "=r")
17772         (unspec:SI [(match_operand:V4SF 1 "register_operand" "x")] 33))]
17773   "TARGET_SSE"
17774   "movmskps\t{%1, %0|%0, %1}"
17775   [(set_attr "type" "sse")])
17776
17777 (define_insn "mmx_pmovmskb"
17778   [(set (match_operand:SI 0 "register_operand" "=r")
17779         (unspec:SI [(match_operand:V8QI 1 "register_operand" "y")] 33))]
17780   "TARGET_SSE"
17781   "pmovmskb\t{%1, %0|%0, %1}"
17782   [(set_attr "type" "sse")])
17783
17784 (define_insn "mmx_maskmovq"
17785   [(set (mem:V8QI (match_operand:SI 0 "register_operand" "D"))
17786         (unspec:V8QI [(match_operand:V8QI 1 "register_operand" "y")
17787                       (match_operand:V8QI 2 "register_operand" "y")] 32))]
17788   "TARGET_SSE"
17789   ;; @@@ check ordering of operands in intel/nonintel syntax
17790   "maskmovq\t{%2, %1|%1, %2}"
17791   [(set_attr "type" "sse")])
17792
17793 (define_insn "sse_movntv4sf"
17794   [(set (match_operand:V4SF 0 "memory_operand" "=m")
17795         (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "x")] 34))]
17796   "TARGET_SSE"
17797   "movntps\t{%1, %0|%0, %1}"
17798   [(set_attr "type" "sse")])
17799
17800 (define_insn "sse_movntdi"
17801   [(set (match_operand:DI 0 "memory_operand" "=m")
17802         (unspec:DI [(match_operand:DI 1 "register_operand" "y")] 34))]
17803   "TARGET_SSE"
17804   "movntq\t{%1, %0|%0, %1}"
17805   [(set_attr "type" "sse")])
17806
17807 (define_insn "sse_movhlps"
17808   [(set (match_operand:V4SF 0 "register_operand" "=x")
17809         (vec_merge:V4SF
17810          (match_operand:V4SF 1 "register_operand" "0")
17811          (vec_select:V4SF (match_operand:V4SF 2 "register_operand" "x")
17812                           (parallel [(const_int 2)
17813                                      (const_int 3)
17814                                      (const_int 0)
17815                                      (const_int 1)]))
17816          (const_int 3)))]
17817   "TARGET_SSE"
17818   "movhlps\t{%2, %0|%0, %2}"
17819   [(set_attr "type" "sse")])
17820
17821 (define_insn "sse_movlhps"
17822   [(set (match_operand:V4SF 0 "register_operand" "=x")
17823         (vec_merge:V4SF
17824          (match_operand:V4SF 1 "register_operand" "0")
17825          (vec_select:V4SF (match_operand:V4SF 2 "register_operand" "x")
17826                           (parallel [(const_int 2)
17827                                      (const_int 3)
17828                                      (const_int 0)
17829                                      (const_int 1)]))
17830          (const_int 12)))]
17831   "TARGET_SSE"
17832   "movlhps\t{%2, %0|%0, %2}"
17833   [(set_attr "type" "sse")])
17834
17835 (define_insn "sse_movhps"
17836   [(set (match_operand:V4SF 0 "nonimmediate_operand" "=x,m")
17837         (vec_merge:V4SF
17838          (match_operand:V4SF 1 "nonimmediate_operand" "0,0")
17839          (match_operand:V4SF 2 "nonimmediate_operand" "m,x")
17840          (const_int 12)))]
17841   "TARGET_SSE && (GET_CODE (operands[1]) == MEM || GET_CODE (operands[2]) == MEM)"
17842   "movhps\t{%2, %0|%0, %2}"
17843   [(set_attr "type" "sse")])
17844
17845 (define_insn "sse_movlps"
17846   [(set (match_operand:V4SF 0 "nonimmediate_operand" "=x,m")
17847         (vec_merge:V4SF
17848          (match_operand:V4SF 1 "nonimmediate_operand" "0,0")
17849          (match_operand:V4SF 2 "nonimmediate_operand" "m,x")
17850          (const_int 3)))]
17851   "TARGET_SSE && (GET_CODE (operands[1]) == MEM || GET_CODE (operands[2]) == MEM)"
17852   "movlps\t{%2, %0|%0, %2}"
17853   [(set_attr "type" "sse")])
17854
17855 (define_insn "sse_loadss"
17856   [(set (match_operand:V4SF 0 "register_operand" "=x")
17857         (vec_merge:V4SF
17858          (match_operand:V4SF 1 "memory_operand" "m")
17859          (vec_duplicate:V4SF (float:SF (const_int 0)))
17860          (const_int 1)))]
17861   "TARGET_SSE"
17862   "movss\t{%1, %0|%0, %1}"
17863   [(set_attr "type" "sse")])
17864
17865 (define_insn "sse_movss"
17866   [(set (match_operand:V4SF 0 "register_operand" "=x")
17867         (vec_merge:V4SF
17868          (match_operand:V4SF 1 "register_operand" "0")
17869          (match_operand:V4SF 2 "register_operand" "x")
17870          (const_int 1)))]
17871   "TARGET_SSE"
17872   "movss\t{%2, %0|%0, %2}"
17873   [(set_attr "type" "sse")])
17874
17875 (define_insn "sse_storess"
17876   [(set (match_operand:SF 0 "memory_operand" "=m")
17877         (vec_select:SF
17878          (match_operand:V4SF 1 "register_operand" "x")
17879          (parallel [(const_int 0)])))]
17880   "TARGET_SSE"
17881   "movss\t{%1, %0|%0, %1}"
17882   [(set_attr "type" "sse")])
17883
17884 (define_insn "sse_shufps"
17885   [(set (match_operand:V4SF 0 "register_operand" "=x")
17886         (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "0")
17887                       (match_operand:V4SF 2 "nonimmediate_operand" "xm")
17888                       (match_operand:SI 3 "immediate_operand" "i")] 41))]
17889   "TARGET_SSE"
17890   ;; @@@ check operand order for intel/nonintel syntax
17891   "shufps\t{%3, %2, %0|%0, %2, %3}"
17892   [(set_attr "type" "sse")])
17893
17894
17895 ;; SSE arithmetic
17896
17897 (define_insn "addv4sf3"
17898   [(set (match_operand:V4SF 0 "register_operand" "=x")
17899         (plus:V4SF (match_operand:V4SF 1 "register_operand" "0")
17900                    (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
17901   "TARGET_SSE"
17902   "addps\t{%2, %0|%0, %2}"
17903   [(set_attr "type" "sse")])
17904
17905 (define_insn "vmaddv4sf3"
17906   [(set (match_operand:V4SF 0 "register_operand" "=x")
17907         (vec_merge:V4SF (plus:V4SF (match_operand:V4SF 1 "register_operand" "0")
17908                                    (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
17909                         (match_dup 1)
17910                         (const_int 1)))]
17911   "TARGET_SSE"
17912   "addss\t{%2, %0|%0, %2}"
17913   [(set_attr "type" "sse")])
17914
17915 (define_insn "subv4sf3"
17916   [(set (match_operand:V4SF 0 "register_operand" "=x")
17917         (minus:V4SF (match_operand:V4SF 1 "register_operand" "0")
17918                    (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
17919   "TARGET_SSE"
17920   "subps\t{%2, %0|%0, %2}"
17921   [(set_attr "type" "sse")])
17922
17923 (define_insn "vmsubv4sf3"
17924   [(set (match_operand:V4SF 0 "register_operand" "=x")
17925         (vec_merge:V4SF (minus:V4SF (match_operand:V4SF 1 "register_operand" "0")
17926                                    (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
17927                         (match_dup 1)
17928                         (const_int 1)))]
17929   "TARGET_SSE"
17930   "subss\t{%2, %0|%0, %2}"
17931   [(set_attr "type" "sse")])
17932
17933 (define_insn "mulv4sf3"
17934   [(set (match_operand:V4SF 0 "register_operand" "=x")
17935         (mult:V4SF (match_operand:V4SF 1 "register_operand" "0")
17936                    (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
17937   "TARGET_SSE"
17938   "mulps\t{%2, %0|%0, %2}"
17939   [(set_attr "type" "sse")])
17940
17941 (define_insn "vmmulv4sf3"
17942   [(set (match_operand:V4SF 0 "register_operand" "=x")
17943         (vec_merge:V4SF (mult:V4SF (match_operand:V4SF 1 "register_operand" "0")
17944                                    (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
17945                         (match_dup 1)
17946                         (const_int 1)))]
17947   "TARGET_SSE"
17948   "mulss\t{%2, %0|%0, %2}"
17949   [(set_attr "type" "sse")])
17950
17951 (define_insn "divv4sf3"
17952   [(set (match_operand:V4SF 0 "register_operand" "=x")
17953         (div:V4SF (match_operand:V4SF 1 "register_operand" "0")
17954                   (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
17955   "TARGET_SSE"
17956   "divps\t{%2, %0|%0, %2}"
17957   [(set_attr "type" "sse")])
17958
17959 (define_insn "vmdivv4sf3"
17960   [(set (match_operand:V4SF 0 "register_operand" "=x")
17961         (vec_merge:V4SF (div:V4SF (match_operand:V4SF 1 "register_operand" "0")
17962                                   (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
17963                         (match_dup 1)
17964                         (const_int 1)))]
17965   "TARGET_SSE"
17966   "divss\t{%2, %0|%0, %2}"
17967   [(set_attr "type" "sse")])
17968
17969
17970 ;; SSE square root/reciprocal
17971
17972 (define_insn "rcpv4sf2"
17973   [(set (match_operand:V4SF 0 "register_operand" "=x")
17974         (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "xm")] 42))]
17975   "TARGET_SSE"
17976   "rcpps\t{%1, %0|%0, %1}"
17977   [(set_attr "type" "sse")])
17978
17979 (define_insn "vmrcpv4sf2"
17980   [(set (match_operand:V4SF 0 "register_operand" "=x")
17981         (vec_merge:V4SF (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "xm")] 42)
17982                         (match_operand:V4SF 2 "register_operand" "0")
17983                         (const_int 1)))]
17984   "TARGET_SSE"
17985   "rcpss\t{%1, %0|%0, %1}"
17986   [(set_attr "type" "sse")])
17987
17988 (define_insn "rsqrtv4sf2"
17989   [(set (match_operand:V4SF 0 "register_operand" "=x")
17990         (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "xm")] 43))]
17991   "TARGET_SSE"
17992   "rsqrtps\t{%1, %0|%0, %1}"
17993   [(set_attr "type" "sse")])
17994
17995 (define_insn "vmrsqrtv4sf2"
17996   [(set (match_operand:V4SF 0 "register_operand" "=x")
17997         (vec_merge:V4SF (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "xm")] 43)
17998                         (match_operand:V4SF 2 "register_operand" "0")
17999                         (const_int 1)))]
18000   "TARGET_SSE"
18001   "rsqrtss\t{%1, %0|%0, %1}"
18002   [(set_attr "type" "sse")])
18003
18004 (define_insn "sqrtv4sf2"
18005   [(set (match_operand:V4SF 0 "register_operand" "=x")
18006         (sqrt:V4SF (match_operand:V4SF 1 "register_operand" "xm")))]
18007   "TARGET_SSE"
18008   "sqrtps\t{%1, %0|%0, %1}"
18009   [(set_attr "type" "sse")])
18010
18011 (define_insn "vmsqrtv4sf2"
18012   [(set (match_operand:V4SF 0 "register_operand" "=x")
18013         (vec_merge:V4SF (sqrt:V4SF (match_operand:V4SF 1 "register_operand" "xm"))
18014                         (match_operand:V4SF 2 "register_operand" "0")
18015                         (const_int 1)))]
18016   "TARGET_SSE"
18017   "sqrtss\t{%1, %0|%0, %1}"
18018   [(set_attr "type" "sse")])
18019
18020
18021 ;; SSE logical operations.
18022
18023 ;; These are not called andti3 etc. because we really really don't want
18024 ;; the compiler to widen DImode ands to TImode ands and then try to move
18025 ;; into DImode subregs of SSE registers, and them together, and move out
18026 ;; of DImode subregs again!
18027
18028 (define_insn "*sse_andti3_df_1"
18029   [(set (subreg:TI (match_operand:DF 0 "register_operand" "=Y") 0)
18030         (and:TI (subreg:TI (match_operand:DF 1 "register_operand" "%0") 0)
18031                 (subreg:TI (match_operand:DF 2 "register_operand" "Y") 0)))]
18032   "TARGET_SSE2"
18033   "andpd\t{%2, %0|%0, %2}"
18034   [(set_attr "type" "sse")])
18035
18036 (define_insn "*sse_andti3_df_2"
18037   [(set (subreg:TI (match_operand:DF 0 "register_operand" "=Y") 0)
18038         (and:TI (subreg:TI (match_operand:DF 1 "register_operand" "0") 0)
18039                 (match_operand:TI 2 "nonimmediate_operand" "Ym")))]
18040   "TARGET_SSE2"
18041   "andpd\t{%2, %0|%0, %2}"
18042   [(set_attr "type" "sse")])
18043
18044 (define_insn "*sse_andti3_sf_1"
18045   [(set (subreg:TI (match_operand:SF 0 "register_operand" "=x") 0)
18046         (and:TI (subreg:TI (match_operand:SF 1 "register_operand" "%0") 0)
18047                 (subreg:TI (match_operand:SF 2 "register_operand" "x") 0)))]
18048   "TARGET_SSE"
18049   "andps\t{%2, %0|%0, %2}"
18050   [(set_attr "type" "sse")])
18051
18052 (define_insn "*sse_andti3_sf_2"
18053   [(set (subreg:TI (match_operand:SF 0 "register_operand" "=x") 0)
18054         (and:TI (subreg:TI (match_operand:SF 1 "register_operand" "0") 0)
18055                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
18056   "TARGET_SSE"
18057   "andps\t{%2, %0|%0, %2}"
18058   [(set_attr "type" "sse")])
18059
18060 (define_insn "sse_andti3"
18061   [(set (match_operand:TI 0 "register_operand" "=x")
18062         (and:TI (match_operand:TI 1 "register_operand" "%0")
18063                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
18064   "TARGET_SSE && !TARGET_SSE2"
18065   "andps\t{%2, %0|%0, %2}"
18066   [(set_attr "type" "sse")])
18067
18068 (define_insn "*sse_andti3_sse2"
18069   [(set (match_operand:TI 0 "register_operand" "=x")
18070         (and:TI (match_operand:TI 1 "register_operand" "%0")
18071                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
18072   "TARGET_SSE2"
18073   "pand\t{%2, %0|%0, %2}"
18074   [(set_attr "type" "sse")])
18075
18076 (define_insn "*sse_nandti3_df"
18077   [(set (subreg:TI (match_operand:DF 0 "register_operand" "=Y") 0)
18078         (and:TI (not:TI (subreg:TI (match_operand:DF 1 "register_operand" "0") 0))
18079                 (match_operand:TI 2 "nonimmediate_operand" "Ym")))]
18080   "TARGET_SSE2"
18081   "andnpd\t{%2, %0|%0, %2}"
18082   [(set_attr "type" "sse")])
18083
18084 (define_insn "*sse_nandti3_sf"
18085   [(set (subreg:TI (match_operand:SF 0 "register_operand" "=x") 0)
18086         (and:TI (not:TI (subreg:TI (match_operand:SF 1 "register_operand" "0") 0))
18087                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
18088   "TARGET_SSE"
18089   "andnps\t{%2, %0|%0, %2}"
18090   [(set_attr "type" "sse")])
18091
18092 (define_insn "sse_nandti3"
18093   [(set (match_operand:TI 0 "register_operand" "=x")
18094         (and:TI (not:TI (match_operand:TI 1 "register_operand" "0"))
18095                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
18096   "TARGET_SSE && !TARGET_SSE2"
18097   "andnps\t{%2, %0|%0, %2}"
18098   [(set_attr "type" "sse")])
18099
18100 (define_insn "*sse_nandti3_sse2"
18101   [(set (match_operand:TI 0 "register_operand" "=x")
18102         (and:TI (not:TI (match_operand:TI 1 "register_operand" "0"))
18103                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
18104   "TARGET_SSE2"
18105   "pnand\t{%2, %0|%0, %2}"
18106   [(set_attr "type" "sse")])
18107
18108 (define_insn "*sse_iorti3_df_1"
18109   [(set (subreg:TI (match_operand:DF 0 "register_operand" "=Y") 0)
18110         (ior:TI (subreg:TI (match_operand:DF 1 "register_operand" "%0") 0)
18111                 (subreg:TI (match_operand:DF 2 "register_operand" "Y") 0)))]
18112   "TARGET_SSE2"
18113   "orpd\t{%2, %0|%0, %2}"
18114   [(set_attr "type" "sse")])
18115
18116 (define_insn "*sse_iorti3_df_2"
18117   [(set (subreg:TI (match_operand:DF 0 "register_operand" "=Y") 0)
18118         (ior:TI (subreg:TI (match_operand:DF 1 "register_operand" "0") 0)
18119                 (match_operand:TI 2 "nonimmediate_operand" "Ym")))]
18120   "TARGET_SSE2"
18121   "orpd\t{%2, %0|%0, %2}"
18122   [(set_attr "type" "sse")])
18123
18124 (define_insn "*sse_iorti3_sf_1"
18125   [(set (subreg:TI (match_operand:SF 0 "register_operand" "=x") 0)
18126         (ior:TI (subreg:TI (match_operand:SF 1 "register_operand" "%0") 0)
18127                 (subreg:TI (match_operand:SF 2 "register_operand" "x") 0)))]
18128   "TARGET_SSE"
18129   "orps\t{%2, %0|%0, %2}"
18130   [(set_attr "type" "sse")])
18131
18132 (define_insn "*sse_iorti3_sf_2"
18133   [(set (subreg:TI (match_operand:SF 0 "register_operand" "=x") 0)
18134         (ior:TI (subreg:TI (match_operand:SF 1 "register_operand" "0") 0)
18135                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
18136   "TARGET_SSE"
18137   "orps\t{%2, %0|%0, %2}"
18138   [(set_attr "type" "sse")])
18139
18140 (define_insn "sse_iorti3"
18141   [(set (match_operand:TI 0 "register_operand" "=x")
18142         (ior:TI (match_operand:TI 1 "register_operand" "%0")
18143                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
18144   "TARGET_SSE && !TARGET_SSE2"
18145   "orps\t{%2, %0|%0, %2}"
18146   [(set_attr "type" "sse")])
18147
18148 (define_insn "*sse_iorti3_sse2"
18149   [(set (match_operand:TI 0 "register_operand" "=x")
18150         (ior:TI (match_operand:TI 1 "register_operand" "%0")
18151                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
18152   "TARGET_SSE2"
18153   "por\t{%2, %0|%0, %2}"
18154   [(set_attr "type" "sse")])
18155
18156 (define_insn "*sse_xorti3_df_1"
18157   [(set (subreg:TI (match_operand:DF 0 "register_operand" "=Y") 0)
18158         (xor:TI (subreg:TI (match_operand:DF 1 "register_operand" "%0") 0)
18159                 (subreg:TI (match_operand:DF 2 "register_operand" "Y") 0)))]
18160   "TARGET_SSE2"
18161   "xorpd\t{%2, %0|%0, %2}"
18162   [(set_attr "type" "sse")])
18163
18164 (define_insn "*sse_xorti3_df_2"
18165   [(set (subreg:TI (match_operand:DF 0 "register_operand" "=Y") 0)
18166         (xor:TI (subreg:TI (match_operand:DF 1 "register_operand" "0") 0)
18167                 (match_operand:TI 2 "nonimmediate_operand" "Ym")))]
18168   "TARGET_SSE2"
18169   "xorpd\t{%2, %0|%0, %2}"
18170   [(set_attr "type" "sse")])
18171
18172 (define_insn "*sse_xorti3_sf_1"
18173   [(set (subreg:TI (match_operand:SF 0 "register_operand" "=x") 0)
18174         (xor:TI (subreg:TI (match_operand:SF 1 "register_operand" "%0") 0)
18175                 (subreg:TI (match_operand:SF 2 "register_operand" "x") 0)))]
18176   "TARGET_SSE"
18177   "xorps\t{%2, %0|%0, %2}"
18178   [(set_attr "type" "sse")])
18179
18180 (define_insn "*sse_xorti3_sf_2"
18181   [(set (subreg:TI (match_operand:SF 0 "register_operand" "=x") 0)
18182         (xor:TI (subreg:TI (match_operand:SF 1 "register_operand" "0") 0)
18183                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
18184   "TARGET_SSE"
18185   "xorps\t{%2, %0|%0, %2}"
18186   [(set_attr "type" "sse")])
18187
18188 (define_insn "sse_xorti3"
18189   [(set (match_operand:TI 0 "register_operand" "=x")
18190         (xor:TI (match_operand:TI 1 "register_operand" "%0")
18191                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
18192   "TARGET_SSE && !TARGET_SSE2"
18193   "xorps\t{%2, %0|%0, %2}"
18194   [(set_attr "type" "sse")])
18195
18196 (define_insn "*sse_xorti3_sse2"
18197   [(set (match_operand:TI 0 "register_operand" "=x")
18198         (xor:TI (match_operand:TI 1 "register_operand" "%0")
18199                 (match_operand:TI 2 "nonimmediate_operand" "xm")))]
18200   "TARGET_SSE2"
18201   "pxor\t{%2, %0|%0, %2}"
18202   [(set_attr "type" "sse")])
18203
18204 ;; Use xor, but don't show input operands so they aren't live before
18205 ;; this insn.
18206 (define_insn "sse_clrti"
18207   [(set (match_operand:TI 0 "register_operand" "=x")
18208         (unspec:TI [(const_int 0)] 45))]
18209   "TARGET_SSE"
18210   "xorps\t{%0, %0|%0, %0}"
18211   [(set_attr "type" "sse")])
18212
18213
18214 ;; SSE mask-generating compares
18215
18216 (define_insn "maskcmpv4sf3"
18217   [(set (match_operand:V4SI 0 "register_operand" "=x")
18218         (match_operator:V4SI 3 "sse_comparison_operator"
18219                              [(match_operand:V4SF 1 "register_operand" "0")
18220                               (match_operand:V4SF 2 "nonimmediate_operand" "x")]))]
18221   "TARGET_SSE"
18222   "cmp%D3ps\t{%2, %0|%0, %2}"
18223   [(set_attr "type" "sse")])
18224
18225 (define_insn "maskncmpv4sf3"
18226   [(set (match_operand:V4SI 0 "register_operand" "=x")
18227         (not:V4SI
18228          (match_operator:V4SI 3 "sse_comparison_operator"
18229                               [(match_operand:V4SF 1 "register_operand" "0")
18230                                (match_operand:V4SF 2 "nonimmediate_operand" "x")])))]
18231   "TARGET_SSE"
18232   "cmpn%D3ps\t{%2, %0|%0, %2}"
18233   [(set_attr "type" "sse")])
18234
18235 (define_insn "vmmaskcmpv4sf3"
18236   [(set (match_operand:V4SI 0 "register_operand" "=x")
18237         (vec_merge:V4SI
18238          (match_operator:V4SI 3 "sse_comparison_operator"
18239                               [(match_operand:V4SF 1 "register_operand" "0")
18240                                (match_operand:V4SF 2 "nonimmediate_operand" "x")])
18241          (match_dup 1)
18242          (const_int 1)))]
18243   "TARGET_SSE"
18244   "cmp%D3ss\t{%2, %0|%0, %2}"
18245   [(set_attr "type" "sse")])
18246
18247 (define_insn "vmmaskncmpv4sf3"
18248   [(set (match_operand:V4SI 0 "register_operand" "=x")
18249         (vec_merge:V4SI
18250          (not:V4SI
18251           (match_operator:V4SI 3 "sse_comparison_operator"
18252                                [(match_operand:V4SF 1 "register_operand" "0")
18253                                 (match_operand:V4SF 2 "nonimmediate_operand" "x")]))
18254          (subreg:V4SI (match_dup 1) 0)
18255          (const_int 1)))]
18256   "TARGET_SSE"
18257   "cmp%D3ss\t{%2, %0|%0, %2}"
18258   [(set_attr "type" "sse")])
18259
18260 (define_insn "sse_comi"
18261   [(set (reg:CCFP 17)
18262         (match_operator:CCFP 2 "sse_comparison_operator"
18263                         [(vec_select:SF
18264                           (match_operand:V4SF 0 "register_operand" "x")
18265                           (parallel [(const_int 0)]))
18266                          (vec_select:SF
18267                           (match_operand:V4SF 1 "register_operand" "x")
18268                           (parallel [(const_int 0)]))]))]
18269   "TARGET_SSE"
18270   "comiss\t{%2, %0|%0, %2}"
18271   [(set_attr "type" "sse")])
18272
18273 (define_insn "sse_ucomi"
18274   [(set (reg:CCFPU 17)
18275         (match_operator:CCFPU 2 "sse_comparison_operator"
18276                         [(vec_select:SF
18277                           (match_operand:V4SF 0 "register_operand" "x")
18278                           (parallel [(const_int 0)]))
18279                          (vec_select:SF
18280                           (match_operand:V4SF 1 "register_operand" "x")
18281                           (parallel [(const_int 0)]))]))]
18282   "TARGET_SSE"
18283   "ucomiss\t{%2, %0|%0, %2}"
18284   [(set_attr "type" "sse")])
18285
18286
18287 ;; SSE unpack
18288
18289 (define_insn "sse_unpckhps"
18290   [(set (match_operand:V4SF 0 "register_operand" "=x")
18291         (vec_merge:V4SF
18292          (vec_select:V4SF (match_operand:V4SF 1 "register_operand" "0")
18293                           (parallel [(const_int 2)
18294                                      (const_int 0)
18295                                      (const_int 3)
18296                                      (const_int 1)]))
18297          (vec_select:V8QI (match_operand:V8QI 2 "register_operand" "x")
18298                           (parallel [(const_int 0)
18299                                      (const_int 2)
18300                                      (const_int 1)
18301                                      (const_int 3)]))
18302          (const_int 5)))]
18303   "TARGET_SSE"
18304   "unpckhps\t{%2, %0|%0, %2}"
18305   [(set_attr "type" "sse")])
18306
18307 (define_insn "sse_unpcklps"
18308   [(set (match_operand:V4SF 0 "register_operand" "=x")
18309         (vec_merge:V4SF
18310          (vec_select:V4SF (match_operand:V4SF 1 "register_operand" "0")
18311                           (parallel [(const_int 0)
18312                                      (const_int 2)
18313                                      (const_int 1)
18314                                      (const_int 3)]))
18315          (vec_select:V8QI (match_operand:V8QI 2 "register_operand" "x")
18316                           (parallel [(const_int 2)
18317                                      (const_int 0)
18318                                      (const_int 3)
18319                                      (const_int 1)]))
18320          (const_int 5)))]
18321   "TARGET_SSE"
18322   "unpcklps\t{%2, %0|%0, %2}"
18323   [(set_attr "type" "sse")])
18324
18325
18326 ;; SSE min/max
18327
18328 (define_insn "smaxv4sf3"
18329   [(set (match_operand:V4SF 0 "register_operand" "=x")
18330         (smax:V4SF (match_operand:V4SF 1 "register_operand" "0")
18331                    (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
18332   "TARGET_SSE"
18333   "maxps\t{%2, %0|%0, %2}"
18334   [(set_attr "type" "sse")])
18335
18336 (define_insn "vmsmaxv4sf3"
18337   [(set (match_operand:V4SF 0 "register_operand" "=x")
18338         (vec_merge:V4SF (smax:V4SF (match_operand:V4SF 1 "register_operand" "0")
18339                                    (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
18340                         (match_dup 1)
18341                         (const_int 1)))]
18342   "TARGET_SSE"
18343   "maxss\t{%2, %0|%0, %2}"
18344   [(set_attr "type" "sse")])
18345
18346 (define_insn "sminv4sf3"
18347   [(set (match_operand:V4SF 0 "register_operand" "=x")
18348         (smin:V4SF (match_operand:V4SF 1 "register_operand" "0")
18349                    (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
18350   "TARGET_SSE"
18351   "minps\t{%2, %0|%0, %2}"
18352   [(set_attr "type" "sse")])
18353
18354 (define_insn "vmsminv4sf3"
18355   [(set (match_operand:V4SF 0 "register_operand" "=x")
18356         (vec_merge:V4SF (smin:V4SF (match_operand:V4SF 1 "register_operand" "0")
18357                                    (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
18358                         (match_dup 1)
18359                         (const_int 1)))]
18360   "TARGET_SSE"
18361   "minss\t{%2, %0|%0, %2}"
18362   [(set_attr "type" "sse")])
18363
18364
18365 ;; SSE <-> integer/MMX conversions
18366
18367 (define_insn "cvtpi2ps"
18368   [(set (match_operand:V4SF 0 "register_operand" "=x")
18369         (vec_merge:V4SF (match_operand:V4SF 1 "register_operand" "0")
18370                         (vec_duplicate:V4SF
18371                          (float:V2SF (match_operand:V2SI 2 "register_operand" "ym")))
18372                         (const_int 12)))]
18373   "TARGET_SSE"
18374   "cvtpi2ps\t{%2, %0|%0, %2}"
18375   [(set_attr "type" "sse")])
18376
18377 (define_insn "cvtps2pi"
18378   [(set (match_operand:V2SI 0 "register_operand" "=y")
18379         (vec_select:V2SI (fix:V4SI (match_operand:V4SF 1 "register_operand" "xm"))
18380                          (parallel
18381                           [(const_int 0)
18382                            (const_int 1)])))]
18383   "TARGET_SSE"
18384   "cvtps2pi\t{%1, %0|%0, %1}"
18385   [(set_attr "type" "sse")])
18386
18387 (define_insn "cvttps2pi"
18388   [(set (match_operand:V2SI 0 "register_operand" "=y")
18389         (vec_select:V2SI (unspec:V4SI [(match_operand:V4SF 1 "register_operand" "xm")] 30)
18390                          (parallel
18391                           [(const_int 0)
18392                            (const_int 1)])))]
18393   "TARGET_SSE"
18394   "cvttps2pi\t{%1, %0|%0, %1}"
18395   [(set_attr "type" "sse")])
18396
18397 (define_insn "cvtsi2ss"
18398   [(set (match_operand:V4SF 0 "register_operand" "=x")
18399         (vec_merge:V4SF (match_operand:V4SF 1 "register_operand" "0")
18400                         (vec_duplicate:V4SF
18401                          (float:SF (match_operand:SI 2 "register_operand" "rm")))
18402                         (const_int 15)))]
18403   "TARGET_SSE"
18404   "cvtsi2ss\t{%2, %0|%0, %2}"
18405   [(set_attr "type" "sse")])
18406
18407 (define_insn "cvtss2si"
18408   [(set (match_operand:SI 0 "register_operand" "=y")
18409         (vec_select:SI (fix:V4SI (match_operand:V4SF 1 "register_operand" "xm"))
18410                        (parallel [(const_int 0)])))]
18411   "TARGET_SSE"
18412   "cvtss2si\t{%1, %0|%0, %1}"
18413   [(set_attr "type" "sse")])
18414
18415 (define_insn "cvttss2si"
18416   [(set (match_operand:SI 0 "register_operand" "=y")
18417         (vec_select:SI (unspec:V4SI [(match_operand:V4SF 1 "register_operand" "xm")] 30)
18418                        (parallel [(const_int 0)])))]
18419   "TARGET_SSE"
18420   "cvttss2si\t{%1, %0|%0, %1}"
18421   [(set_attr "type" "sse")])
18422
18423
18424 ;; MMX insns
18425
18426 ;; MMX arithmetic
18427
18428 (define_insn "addv8qi3"
18429   [(set (match_operand:V8QI 0 "register_operand" "=y")
18430         (plus:V8QI (match_operand:V8QI 1 "register_operand" "0")
18431                    (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
18432   "TARGET_MMX"
18433   "paddb\t{%2, %0|%0, %2}"
18434   [(set_attr "type" "mmx")])
18435
18436 (define_insn "addv4hi3"
18437   [(set (match_operand:V4HI 0 "register_operand" "=y")
18438         (plus:V4HI (match_operand:V4HI 1 "register_operand" "0")
18439                    (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
18440   "TARGET_MMX"
18441   "paddw\t{%2, %0|%0, %2}"
18442   [(set_attr "type" "mmx")])
18443
18444 (define_insn "addv2si3"
18445   [(set (match_operand:V2SI 0 "register_operand" "=y")
18446         (plus:V2SI (match_operand:V2SI 1 "register_operand" "0")
18447                    (match_operand:V2SI 2 "nonimmediate_operand" "ym")))]
18448   "TARGET_MMX"
18449   "paddd\t{%2, %0|%0, %2}"
18450   [(set_attr "type" "mmx")])
18451
18452 (define_insn "ssaddv8qi3"
18453   [(set (match_operand:V8QI 0 "register_operand" "=y")
18454         (ss_plus:V8QI (match_operand:V8QI 1 "register_operand" "0")
18455                       (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
18456   "TARGET_MMX"
18457   "paddsb\t{%2, %0|%0, %2}"
18458   [(set_attr "type" "mmx")])
18459
18460 (define_insn "ssaddv4hi3"
18461   [(set (match_operand:V4HI 0 "register_operand" "=y")
18462         (ss_plus:V4HI (match_operand:V4HI 1 "register_operand" "0")
18463                       (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
18464   "TARGET_MMX"
18465   "paddsw\t{%2, %0|%0, %2}"
18466   [(set_attr "type" "mmx")])
18467
18468 (define_insn "usaddv8qi3"
18469   [(set (match_operand:V8QI 0 "register_operand" "=y")
18470         (us_plus:V8QI (match_operand:V8QI 1 "register_operand" "0")
18471                       (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
18472   "TARGET_MMX"
18473   "paddusb\t{%2, %0|%0, %2}"
18474   [(set_attr "type" "mmx")])
18475
18476 (define_insn "usaddv4hi3"
18477   [(set (match_operand:V4HI 0 "register_operand" "=y")
18478         (us_plus:V4HI (match_operand:V4HI 1 "register_operand" "0")
18479                       (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
18480   "TARGET_MMX"
18481   "paddusw\t{%2, %0|%0, %2}"
18482   [(set_attr "type" "mmx")])
18483
18484 (define_insn "subv8qi3"
18485   [(set (match_operand:V8QI 0 "register_operand" "=y")
18486         (minus:V8QI (match_operand:V8QI 1 "register_operand" "0")
18487                     (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
18488   "TARGET_MMX"
18489   "psubb\t{%2, %0|%0, %2}"
18490   [(set_attr "type" "mmx")])
18491
18492 (define_insn "subv4hi3"
18493   [(set (match_operand:V4HI 0 "register_operand" "=y")
18494         (minus:V4HI (match_operand:V4HI 1 "register_operand" "0")
18495                     (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
18496   "TARGET_MMX"
18497   "psubw\t{%2, %0|%0, %2}"
18498   [(set_attr "type" "mmx")])
18499
18500 (define_insn "subv2si3"
18501   [(set (match_operand:V2SI 0 "register_operand" "=y")
18502         (minus:V2SI (match_operand:V2SI 1 "register_operand" "0")
18503                     (match_operand:V2SI 2 "nonimmediate_operand" "ym")))]
18504   "TARGET_MMX"
18505   "psubd\t{%2, %0|%0, %2}"
18506   [(set_attr "type" "mmx")])
18507
18508 (define_insn "sssubv8qi3"
18509   [(set (match_operand:V8QI 0 "register_operand" "=y")
18510         (ss_minus:V8QI (match_operand:V8QI 1 "register_operand" "0")
18511                        (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
18512   "TARGET_MMX"
18513   "psubsb\t{%2, %0|%0, %2}"
18514   [(set_attr "type" "mmx")])
18515
18516 (define_insn "sssubv4hi3"
18517   [(set (match_operand:V4HI 0 "register_operand" "=y")
18518         (ss_minus:V4HI (match_operand:V4HI 1 "register_operand" "0")
18519                        (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
18520   "TARGET_MMX"
18521   "psubsw\t{%2, %0|%0, %2}"
18522   [(set_attr "type" "mmx")])
18523
18524 (define_insn "ussubv8qi3"
18525   [(set (match_operand:V8QI 0 "register_operand" "=y")
18526         (us_minus:V8QI (match_operand:V8QI 1 "register_operand" "0")
18527                        (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
18528   "TARGET_MMX"
18529   "psubusb\t{%2, %0|%0, %2}"
18530   [(set_attr "type" "mmx")])
18531
18532 (define_insn "ussubv4hi3"
18533   [(set (match_operand:V4HI 0 "register_operand" "=y")
18534         (us_minus:V4HI (match_operand:V4HI 1 "register_operand" "0")
18535                        (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
18536   "TARGET_MMX"
18537   "psubusw\t{%2, %0|%0, %2}"
18538   [(set_attr "type" "mmx")])
18539
18540 (define_insn "mulv4hi3"
18541   [(set (match_operand:V4HI 0 "register_operand" "=y")
18542         (mult:V4HI (match_operand:V4HI 1 "register_operand" "0")
18543                    (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
18544   "TARGET_MMX"
18545   "pmullw\t{%2, %0|%0, %2}"
18546   [(set_attr "type" "mmx")])
18547
18548 (define_insn "smulv4hi3_highpart"
18549   [(set (match_operand:V4HI 0 "register_operand" "=y")
18550         (truncate:V4HI
18551          (lshiftrt:V4SI
18552           (mult:V4SI (sign_extend:V4SI (match_operand:V4HI 1 "register_operand" "0"))
18553                      (sign_extend:V4SI (match_operand:V4HI 2 "nonimmediate_operand" "ym")))
18554           (const_int 16))))]
18555   "TARGET_MMX"
18556   "pmulhw\t{%2, %0|%0, %2}"
18557   [(set_attr "type" "mmx")])
18558
18559 (define_insn "umulv4hi3_highpart"
18560   [(set (match_operand:V4HI 0 "register_operand" "=y")
18561         (truncate:V4HI
18562          (lshiftrt:V4SI
18563           (mult:V4SI (zero_extend:V4SI (match_operand:V4HI 1 "register_operand" "0"))
18564                      (zero_extend:V4SI (match_operand:V4HI 2 "nonimmediate_operand" "ym")))
18565           (const_int 16))))]
18566   "TARGET_MMX"
18567   "pmulhuw\t{%2, %0|%0, %2}"
18568   [(set_attr "type" "mmx")])
18569
18570 (define_insn "mmx_pmaddwd"
18571   [(set (match_operand:V2SI 0 "register_operand" "=y")
18572         (plus:V2SI
18573          (mult:V2SI
18574           (sign_extend:V2SI (vec_select:V2HI (match_operand:V4HI 1 "register_operand" "0")
18575                                              (parallel [(const_int 0)
18576                                                         (const_int 2)])))
18577           (sign_extend:V2SI (vec_select:V2HI (match_operand:V4HI 2 "nonimmediate_operand" "ym")
18578                                              (parallel [(const_int 0)
18579                                                         (const_int 2)]))))
18580          (mult:V2SI
18581           (sign_extend:V2SI (vec_select:V2HI (match_dup 1)
18582                                              (parallel [(const_int 1)
18583                                                         (const_int 3)])))
18584           (sign_extend:V2SI (vec_select:V2HI (match_dup 2)
18585                                              (parallel [(const_int 1)
18586                                                         (const_int 3)]))))))]
18587   "TARGET_MMX"
18588   "pmaddwd\t{%2, %0|%0, %2}"
18589   [(set_attr "type" "mmx")])
18590
18591
18592 ;; MMX logical operations
18593 ;; Note we don't want to declare these as regular iordi3 insns to prevent
18594 ;; normal code that also wants to use the FPU from getting broken.
18595 ;; The UNSPECs are there to prevent the combiner from getting overly clever.
18596 (define_insn "mmx_iordi3"
18597   [(set (match_operand:DI 0 "register_operand" "=y")
18598         (unspec:DI
18599          [(ior:DI (match_operand:DI 1 "register_operand" "0")
18600                   (match_operand:DI 2 "nonimmediate_operand" "ym"))] 45))]
18601   "TARGET_MMX"
18602   "por\t{%2, %0|%0, %2}"
18603   [(set_attr "type" "mmx")])
18604
18605 (define_insn "mmx_xordi3"
18606   [(set (match_operand:DI 0 "register_operand" "=y")
18607         (unspec:DI
18608          [(xor:DI (match_operand:DI 1 "register_operand" "0")
18609                   (match_operand:DI 2 "nonimmediate_operand" "ym"))] 45))]
18610   "TARGET_MMX"
18611   "pxor\t{%2, %0|%0, %2}"
18612   [(set_attr "type" "mmx")])
18613
18614 ;; Same as pxor, but don't show input operands so that we don't think
18615 ;; they are live.
18616 (define_insn "mmx_clrdi"
18617   [(set (match_operand:DI 0 "register_operand" "=y")
18618         (unspec:DI [(const_int 0)] 45))]
18619   "TARGET_MMX"
18620   "pxor\t{%0, %0|%0, %0}"
18621   [(set_attr "type" "mmx")])
18622
18623 (define_insn "mmx_anddi3"
18624   [(set (match_operand:DI 0 "register_operand" "=y")
18625         (unspec:DI
18626          [(and:DI (match_operand:DI 1 "register_operand" "0")
18627                   (match_operand:DI 2 "nonimmediate_operand" "ym"))] 45))]
18628   "TARGET_MMX"
18629   "pand\t{%2, %0|%0, %2}"
18630   [(set_attr "type" "mmx")])
18631
18632 (define_insn "mmx_nanddi3"
18633   [(set (match_operand:DI 0 "register_operand" "=y")
18634         (unspec:DI
18635          [(and:DI (not:DI (match_operand:DI 1 "register_operand" "0"))
18636                           (match_operand:DI 2 "nonimmediate_operand" "ym"))] 45))]
18637   "TARGET_MMX"
18638   "pandn\t{%2, %0|%0, %2}"
18639   [(set_attr "type" "mmx")])
18640
18641
18642 ;; MMX unsigned averages/sum of absolute differences
18643
18644 (define_insn "mmx_uavgv8qi3"
18645   [(set (match_operand:V8QI 0 "register_operand" "=y")
18646         (ashiftrt:V8QI
18647          (plus:V8QI (plus:V8QI
18648                      (match_operand:V8QI 1 "register_operand" "0")
18649                      (match_operand:V8QI 2 "nonimmediate_operand" "ym"))
18650                     (vec_const:V8QI (parallel [(const_int 1)
18651                                                (const_int 1)
18652                                                (const_int 1)
18653                                                (const_int 1)
18654                                                (const_int 1)
18655                                                (const_int 1)
18656                                                (const_int 1)
18657                                                (const_int 1)])))
18658          (const_int 1)))]
18659   "TARGET_SSE"
18660   "pavgb\t{%2, %0|%0, %2}"
18661   [(set_attr "type" "sse")])
18662
18663 (define_insn "mmx_uavgv4hi3"
18664   [(set (match_operand:V4HI 0 "register_operand" "=y")
18665         (ashiftrt:V4HI
18666          (plus:V4HI (plus:V4HI
18667                      (match_operand:V4HI 1 "register_operand" "0")
18668                      (match_operand:V4HI 2 "nonimmediate_operand" "ym"))
18669                     (vec_const:V4HI (parallel [(const_int 1)
18670                                                (const_int 1)
18671                                                (const_int 1)
18672                                                (const_int 1)])))
18673          (const_int 1)))]
18674   "TARGET_SSE"
18675   "pavgw\t{%2, %0|%0, %2}"
18676   [(set_attr "type" "sse")])
18677
18678 (define_insn "mmx_psadbw"
18679   [(set (match_operand:V8QI 0 "register_operand" "=y")
18680         (abs:V8QI (minus:V8QI (match_operand:V8QI 1 "register_operand" "0")
18681                               (match_operand:V8QI 2 "nonimmediate_operand" "ym"))))]
18682   "TARGET_SSE"
18683   "psadbw\t{%2, %0|%0, %2}"
18684   [(set_attr "type" "sse")])
18685
18686
18687 ;; MMX insert/extract/shuffle
18688
18689 (define_insn "mmx_pinsrw"
18690   [(set (match_operand:V4HI 0 "register_operand" "=y")
18691         (vec_merge:V4HI (match_operand:V4HI 1 "register_operand" "0")
18692                         (vec_duplicate:V4HI
18693                          (truncate:HI (match_operand:SI 2 "nonimmediate_operand" "rm")))
18694                         (match_operand:SI 3 "immediate_operand" "i")))]
18695   "TARGET_SSE"
18696   "pinsrw\t{%3, %2, %0|%0, %2, %3}"
18697   [(set_attr "type" "sse")])
18698
18699 (define_insn "mmx_pextrw"
18700   [(set (match_operand:SI 0 "register_operand" "=r")
18701         (zero_extend:SI (vec_select:HI (match_operand:V4HI 1 "register_operand" "y")
18702                                        (parallel
18703                                         [(match_operand:SI 2 "immediate_operand" "i")]))))]
18704   "TARGET_SSE"
18705   "pextrw\t{%2, %1, %0|%0, %1, %2}"
18706   [(set_attr "type" "sse")])
18707
18708 (define_insn "mmx_pshufw"
18709   [(set (match_operand:V4HI 0 "register_operand" "=y")
18710         (unspec:V4HI [(match_operand:V4HI 1 "register_operand" "0")
18711                       (match_operand:V4HI 2 "nonimmediate_operand" "ym")
18712                       (match_operand:SI 3 "immediate_operand" "i")] 41))]
18713   "TARGET_SSE"
18714   "pshufw\t{%3, %2, %0|%0, %2, %3}"
18715   [(set_attr "type" "sse")])
18716
18717
18718 ;; MMX mask-generating comparisons
18719
18720 (define_insn "eqv8qi3"
18721   [(set (match_operand:V8QI 0 "register_operand" "=y")
18722         (eq:V8QI (match_operand:V8QI 1 "register_operand" "0")
18723                  (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
18724   "TARGET_MMX"
18725   "pcmpeqb\t{%2, %0|%0, %2}"
18726   [(set_attr "type" "mmx")])
18727
18728 (define_insn "eqv4hi3"
18729   [(set (match_operand:V4HI 0 "register_operand" "=y")
18730         (eq:V4HI (match_operand:V4HI 1 "register_operand" "0")
18731                  (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
18732   "TARGET_MMX"
18733   "pcmpeqw\t{%2, %0|%0, %2}"
18734   [(set_attr "type" "mmx")])
18735
18736 (define_insn "eqv2si3"
18737   [(set (match_operand:V2SI 0 "register_operand" "=y")
18738         (eq:V2SI (match_operand:V2SI 1 "register_operand" "0")
18739                  (match_operand:V2SI 2 "nonimmediate_operand" "ym")))]
18740   "TARGET_MMX"
18741   "pcmpeqd\t{%2, %0|%0, %2}"
18742   [(set_attr "type" "mmx")])
18743
18744 (define_insn "gtv8qi3"
18745   [(set (match_operand:V8QI 0 "register_operand" "=y")
18746         (gt:V8QI (match_operand:V8QI 1 "register_operand" "0")
18747                  (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
18748   "TARGET_MMX"
18749   "pcmpgtb\t{%2, %0|%0, %2}"
18750   [(set_attr "type" "mmx")])
18751
18752 (define_insn "gtv4hi3"
18753   [(set (match_operand:V4HI 0 "register_operand" "=y")
18754         (gt:V4HI (match_operand:V4HI 1 "register_operand" "0")
18755                  (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
18756   "TARGET_MMX"
18757   "pcmpgtw\t{%2, %0|%0, %2}"
18758   [(set_attr "type" "mmx")])
18759
18760 (define_insn "gtv2si3"
18761   [(set (match_operand:V2SI 0 "register_operand" "=y")
18762         (gt:V2SI (match_operand:V2SI 1 "register_operand" "0")
18763                  (match_operand:V2SI 2 "nonimmediate_operand" "ym")))]
18764   "TARGET_MMX"
18765   "pcmpgtd\t{%2, %0|%0, %2}"
18766   [(set_attr "type" "mmx")])
18767
18768
18769 ;; MMX max/min insns
18770
18771 (define_insn "umaxv8qi3"
18772   [(set (match_operand:V8QI 0 "register_operand" "=y")
18773         (umax:V8QI (match_operand:V8QI 1 "register_operand" "0")
18774                    (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
18775   "TARGET_SSE"
18776   "pmaxub\t{%2, %0|%0, %2}"
18777   [(set_attr "type" "sse")])
18778
18779 (define_insn "smaxv4hi3"
18780   [(set (match_operand:V4HI 0 "register_operand" "=y")
18781         (smax:V4HI (match_operand:V4HI 1 "register_operand" "0")
18782                    (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
18783   "TARGET_SSE"
18784   "pmaxsw\t{%2, %0|%0, %2}"
18785   [(set_attr "type" "sse")])
18786
18787 (define_insn "uminv8qi3"
18788   [(set (match_operand:V8QI 0 "register_operand" "=y")
18789         (umin:V8QI (match_operand:V8QI 1 "register_operand" "0")
18790                    (match_operand:V8QI 2 "nonimmediate_operand" "ym")))]
18791   "TARGET_SSE"
18792   "pminub\t{%2, %0|%0, %2}"
18793   [(set_attr "type" "sse")])
18794
18795 (define_insn "sminv4hi3"
18796   [(set (match_operand:V4HI 0 "register_operand" "=y")
18797         (smin:V4HI (match_operand:V4HI 1 "register_operand" "0")
18798                    (match_operand:V4HI 2 "nonimmediate_operand" "ym")))]
18799   "TARGET_SSE"
18800   "pminsw\t{%2, %0|%0, %2}"
18801   [(set_attr "type" "sse")])
18802
18803
18804 ;; MMX shifts
18805
18806 (define_insn "ashrv4hi3"
18807   [(set (match_operand:V4HI 0 "register_operand" "=y")
18808         (ashiftrt:V4HI (match_operand:V4HI 1 "register_operand" "0")
18809                        (match_operand:DI 2 "nonmemory_operand" "yi")))]
18810   "TARGET_MMX"
18811   "psraw\t{%2, %0|%0, %2}"
18812   [(set_attr "type" "mmx")])
18813
18814 (define_insn "ashrv2si3"
18815   [(set (match_operand:V2SI 0 "register_operand" "=y")
18816         (ashiftrt:V2SI (match_operand:V2SI 1 "register_operand" "0")
18817                        (match_operand:DI 2 "nonmemory_operand" "yi")))]
18818   "TARGET_MMX"
18819   "psrad\t{%2, %0|%0, %2}"
18820   [(set_attr "type" "mmx")])
18821
18822 (define_insn "lshrv4hi3"
18823   [(set (match_operand:V4HI 0 "register_operand" "=y")
18824         (lshiftrt:V4HI (match_operand:V4HI 1 "register_operand" "0")
18825                        (match_operand:DI 2 "nonmemory_operand" "yi")))]
18826   "TARGET_MMX"
18827   "psrlw\t{%2, %0|%0, %2}"
18828   [(set_attr "type" "mmx")])
18829
18830 (define_insn "lshrv2si3"
18831   [(set (match_operand:V2SI 0 "register_operand" "=y")
18832         (lshiftrt:V2SI (match_operand:V2SI 1 "register_operand" "0")
18833                        (match_operand:DI 2 "nonmemory_operand" "yi")))]
18834   "TARGET_MMX"
18835   "psrld\t{%2, %0|%0, %2}"
18836   [(set_attr "type" "mmx")])
18837
18838 ;; See logical MMX insns.
18839 (define_insn "mmx_lshrdi3"
18840   [(set (match_operand:DI 0 "register_operand" "=y")
18841         (unspec:DI
18842           [(lshiftrt:DI (match_operand:DI 1 "register_operand" "0")
18843                        (match_operand:DI 2 "nonmemory_operand" "yi"))] 45))]
18844   "TARGET_MMX"
18845   "psrlq\t{%2, %0|%0, %2}"
18846   [(set_attr "type" "mmx")])
18847
18848 (define_insn "ashlv4hi3"
18849   [(set (match_operand:V4HI 0 "register_operand" "=y")
18850         (ashift:V4HI (match_operand:V4HI 1 "register_operand" "0")
18851                        (match_operand:DI 2 "nonmemory_operand" "yi")))]
18852   "TARGET_MMX"
18853   "psllw\t{%2, %0|%0, %2}"
18854   [(set_attr "type" "mmx")])
18855
18856 (define_insn "ashlv2si3"
18857   [(set (match_operand:V2SI 0 "register_operand" "=y")
18858         (ashift:V2SI (match_operand:V2SI 1 "register_operand" "0")
18859                        (match_operand:DI 2 "nonmemory_operand" "yi")))]
18860   "TARGET_MMX"
18861   "pslld\t{%2, %0|%0, %2}"
18862   [(set_attr "type" "mmx")])
18863
18864 ;; See logical MMX insns.
18865 (define_insn "mmx_ashldi3"
18866   [(set (match_operand:DI 0 "register_operand" "=y")
18867         (unspec:DI
18868          [(ashift:DI (match_operand:DI 1 "register_operand" "0")
18869                      (match_operand:DI 2 "nonmemory_operand" "yi"))] 45))]
18870   "TARGET_MMX"
18871   "psllq\t{%2, %0|%0, %2}"
18872   [(set_attr "type" "mmx")])
18873
18874
18875 ;; MMX pack/unpack insns.
18876
18877 (define_insn "mmx_packsswb"
18878   [(set (match_operand:V8QI 0 "register_operand" "=y")
18879         (vec_concat:V8QI
18880          (ss_truncate:V4QI (match_operand:V4HI 1 "register_operand" "0"))
18881          (ss_truncate:V4QI (match_operand:V4HI 2 "register_operand" "y"))))]
18882   "TARGET_MMX"
18883   "packsswb\t{%2, %0|%0, %2}"
18884   [(set_attr "type" "mmx")])
18885
18886 (define_insn "mmx_packssdw"
18887   [(set (match_operand:V4HI 0 "register_operand" "=y")
18888         (vec_concat:V4HI
18889          (ss_truncate:V2HI (match_operand:V2SI 1 "register_operand" "0"))
18890          (ss_truncate:V2HI (match_operand:V2SI 2 "register_operand" "y"))))]
18891   "TARGET_MMX"
18892   "packssdw\t{%2, %0|%0, %2}"
18893   [(set_attr "type" "mmx")])
18894
18895 (define_insn "mmx_packuswb"
18896   [(set (match_operand:V8QI 0 "register_operand" "=y")
18897         (vec_concat:V8QI
18898          (us_truncate:V4QI (match_operand:V4HI 1 "register_operand" "0"))
18899          (us_truncate:V4QI (match_operand:V4HI 2 "register_operand" "y"))))]
18900   "TARGET_MMX"
18901   "packuswb\t{%2, %0|%0, %2}"
18902   [(set_attr "type" "mmx")])
18903
18904 (define_insn "mmx_punpckhbw"
18905   [(set (match_operand:V8QI 0 "register_operand" "=y")
18906         (vec_merge:V8QI
18907          (vec_select:V8QI (match_operand:V8QI 1 "register_operand" "0")
18908                           (parallel [(const_int 4)
18909                                      (const_int 0)
18910                                      (const_int 5)
18911                                      (const_int 1)
18912                                      (const_int 6)
18913                                      (const_int 2)
18914                                      (const_int 7)
18915                                      (const_int 3)]))
18916          (vec_select:V8QI (match_operand:V8QI 2 "register_operand" "y")
18917                           (parallel [(const_int 0)
18918                                      (const_int 4)
18919                                      (const_int 1)
18920                                      (const_int 5)
18921                                      (const_int 2)
18922                                      (const_int 6)
18923                                      (const_int 3)
18924                                      (const_int 7)]))
18925          (const_int 85)))]
18926   "TARGET_MMX"
18927   "punpckhbw\t{%2, %0|%0, %2}"
18928   [(set_attr "type" "mmx")])
18929
18930 (define_insn "mmx_punpckhwd"
18931   [(set (match_operand:V4HI 0 "register_operand" "=y")
18932         (vec_merge:V4HI
18933          (vec_select:V4HI (match_operand:V4HI 1 "register_operand" "0")
18934                           (parallel [(const_int 0)
18935                                      (const_int 2)
18936                                      (const_int 1)
18937                                      (const_int 3)]))
18938          (vec_select:V4HI (match_operand:V4HI 2 "register_operand" "y")
18939                           (parallel [(const_int 2)
18940                                      (const_int 0)
18941                                      (const_int 3)
18942                                      (const_int 1)]))
18943          (const_int 5)))]
18944   "TARGET_MMX"
18945   "punpckhwd\t{%2, %0|%0, %2}"
18946   [(set_attr "type" "mmx")])
18947
18948 (define_insn "mmx_punpckhdq"
18949   [(set (match_operand:V2SI 0 "register_operand" "=y")
18950         (vec_merge:V2SI
18951          (vec_select:V2SI (match_operand:V2SI 1 "register_operand" "0")
18952                           (parallel [(const_int 0)
18953                                      (const_int 1)]))
18954          (vec_select:V2SI (match_operand:V2SI 2 "register_operand" "y")
18955                           (parallel [(const_int 1)
18956                                      (const_int 0)]))
18957          (const_int 1)))]
18958   "TARGET_MMX"
18959   "punpckhdq\t{%2, %0|%0, %2}"
18960   [(set_attr "type" "mmx")])
18961
18962 (define_insn "mmx_punpcklbw"
18963   [(set (match_operand:V8QI 0 "register_operand" "=y")
18964         (vec_merge:V8QI
18965          (vec_select:V8QI (match_operand:V8QI 1 "register_operand" "0")
18966                           (parallel [(const_int 0)
18967                                      (const_int 4)
18968                                      (const_int 1)
18969                                      (const_int 5)
18970                                      (const_int 2)
18971                                      (const_int 6)
18972                                      (const_int 3)
18973                                      (const_int 7)]))
18974          (vec_select:V8QI (match_operand:V8QI 2 "register_operand" "y")
18975                           (parallel [(const_int 4)
18976                                      (const_int 0)
18977                                      (const_int 5)
18978                                      (const_int 1)
18979                                      (const_int 6)
18980                                      (const_int 2)
18981                                      (const_int 7)
18982                                      (const_int 3)]))
18983          (const_int 85)))]
18984   "TARGET_MMX"
18985   "punpcklbw\t{%2, %0|%0, %2}"
18986   [(set_attr "type" "mmx")])
18987
18988 (define_insn "mmx_punpcklwd"
18989   [(set (match_operand:V4HI 0 "register_operand" "=y")
18990         (vec_merge:V4HI
18991          (vec_select:V4HI (match_operand:V4HI 1 "register_operand" "0")
18992                           (parallel [(const_int 2)
18993                                      (const_int 0)
18994                                      (const_int 3)
18995                                      (const_int 1)]))
18996          (vec_select:V4HI (match_operand:V4HI 2 "register_operand" "y")
18997                           (parallel [(const_int 0)
18998                                      (const_int 2)
18999                                      (const_int 1)
19000                                      (const_int 3)]))
19001          (const_int 5)))]
19002   "TARGET_MMX"
19003   "punpcklwd\t{%2, %0|%0, %2}"
19004   [(set_attr "type" "mmx")])
19005
19006 (define_insn "mmx_punpckldq"
19007   [(set (match_operand:V2SI 0 "register_operand" "=y")
19008         (vec_merge:V2SI
19009          (vec_select:V2SI (match_operand:V2SI 1 "register_operand" "0")
19010                            (parallel [(const_int 1)
19011                                       (const_int 0)]))
19012          (vec_select:V2SI (match_operand:V2SI 2 "register_operand" "y")
19013                           (parallel [(const_int 0)
19014                                      (const_int 1)]))
19015          (const_int 1)))]
19016   "TARGET_MMX"
19017   "punpckldq\t{%2, %0|%0, %2}"
19018   [(set_attr "type" "mmx")])
19019
19020
19021 ;; Miscellaneous stuff
19022
19023 (define_insn "emms"
19024   [(unspec_volatile [(const_int 0)] 31)
19025    (clobber (reg:XF 8))
19026    (clobber (reg:XF 9))
19027    (clobber (reg:XF 10))
19028    (clobber (reg:XF 11))
19029    (clobber (reg:XF 12))
19030    (clobber (reg:XF 13))
19031    (clobber (reg:XF 14))
19032    (clobber (reg:XF 15))
19033    (clobber (reg:DI 29))
19034    (clobber (reg:DI 30))
19035    (clobber (reg:DI 31))
19036    (clobber (reg:DI 32))
19037    (clobber (reg:DI 33))
19038    (clobber (reg:DI 34))
19039    (clobber (reg:DI 35))
19040    (clobber (reg:DI 36))]
19041   "TARGET_MMX"
19042   "emms"
19043   [(set_attr "type" "mmx")
19044    (set_attr "memory" "unknown")])
19045
19046 (define_insn "ldmxcsr"
19047   [(unspec_volatile [(match_operand:SI 0 "memory_operand" "m")] 37)]
19048   "TARGET_MMX"
19049   "ldmxcsr\t%0"
19050   [(set_attr "type" "mmx")])
19051
19052 (define_insn "stmxcsr"
19053   [(set (match_operand:SI 0 "memory_operand" "=m")
19054         (unspec_volatile:SI [(const_int 0)] 40))]
19055   "TARGET_MMX"
19056   "stmxcsr\t%0"
19057   [(set_attr "type" "mmx")])
19058
19059 (define_expand "sfence"
19060   [(set (match_dup 0)
19061         (unspec:BLK [(match_dup 0)] 44))]
19062   "TARGET_SSE"
19063 {
19064   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
19065   MEM_VOLATILE_P (operands[0]) = 1;
19066 })
19067
19068 (define_insn "*sfence_insn"
19069   [(set (match_operand:BLK 0 "" "")
19070         (unspec:BLK [(match_dup 0)] 44))]
19071   "TARGET_SSE"
19072   "sfence"
19073   [(set_attr "type" "sse")
19074    (set_attr "memory" "unknown")])
19075
19076 (define_insn "prefetch"
19077   [(unspec [(match_operand:SI 0 "address_operand" "p")
19078             (match_operand:SI 1 "immediate_operand" "n")] 35)]
19079   "TARGET_SSE"
19080 {
19081   switch (INTVAL (operands[1]))
19082     {
19083     case 0:
19084       return "prefetchnta\t%a0";
19085     case 1:
19086       return "prefetcht0\t%a0";
19087     case 2:
19088       return "prefetcht1\t%a0";
19089     case 3:
19090       return "prefetcht2\t%a0";
19091     default:
19092       abort ();
19093     }
19094 }
19095   [(set_attr "type" "sse")])
19096