OSDN Git Service

661f5bb5c8db3045e3f71591e7ad90f7e0e05a5c
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / sse.md
1 ;; GCC machine description for SSE instructions
2 ;; Copyright (C) 2005, 2006, 2007
3 ;; Free Software Foundation, Inc.
4 ;;
5 ;; This file is part of GCC.
6 ;;
7 ;; GCC is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
10 ;; any later version.
11 ;;
12 ;; GCC is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ;; GNU General Public License for more details.
16 ;;
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING.  If not, write to
19 ;; the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 ;; Boston, MA 02110-1301, USA.
21
22
23 ;; 16 byte integral modes handled by SSE, minus TImode, which gets
24 ;; special-cased for TARGET_64BIT.
25 (define_mode_macro SSEMODEI [V16QI V8HI V4SI V2DI])
26
27 ;; All 16-byte vector modes handled by SSE
28 (define_mode_macro SSEMODE [V16QI V8HI V4SI V2DI V4SF V2DF])
29
30 ;; Mix-n-match
31 (define_mode_macro SSEMODE12 [V16QI V8HI])
32 (define_mode_macro SSEMODE24 [V8HI V4SI])
33 (define_mode_macro SSEMODE14 [V16QI V4SI])
34 (define_mode_macro SSEMODE124 [V16QI V8HI V4SI])
35 (define_mode_macro SSEMODE248 [V8HI V4SI V2DI])
36
37 ;; Mapping from integer vector mode to mnemonic suffix
38 (define_mode_attr ssevecsize [(V16QI "b") (V8HI "w") (V4SI "d") (V2DI "q")])
39
40 ;; Patterns whose name begins with "sse{,2,3}_" are invoked by intrinsics.
41
42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43 ;;
44 ;; Move patterns
45 ;;
46 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
47
48 ;; All of these patterns are enabled for SSE1 as well as SSE2.
49 ;; This is essential for maintaining stable calling conventions.
50
51 (define_expand "mov<mode>"
52   [(set (match_operand:SSEMODEI 0 "nonimmediate_operand" "")
53         (match_operand:SSEMODEI 1 "nonimmediate_operand" ""))]
54   "TARGET_SSE"
55 {
56   ix86_expand_vector_move (<MODE>mode, operands);
57   DONE;
58 })
59
60 (define_insn "*mov<mode>_internal"
61   [(set (match_operand:SSEMODEI 0 "nonimmediate_operand" "=x,x ,m")
62         (match_operand:SSEMODEI 1 "nonimmediate_or_sse_const_operand"  "C ,xm,x"))]
63   "TARGET_SSE
64    && (register_operand (operands[0], <MODE>mode)
65        || register_operand (operands[1], <MODE>mode))"
66 {
67   switch (which_alternative)
68     {
69     case 0:
70       return standard_sse_constant_opcode (insn, operands[1]);
71     case 1:
72     case 2:
73       if (get_attr_mode (insn) == MODE_V4SF)
74         return "movaps\t{%1, %0|%0, %1}";
75       else
76         return "movdqa\t{%1, %0|%0, %1}";
77     default:
78       gcc_unreachable ();
79     }
80 }
81   [(set_attr "type" "sselog1,ssemov,ssemov")
82    (set (attr "mode")
83         (if_then_else
84           (ior (ior (ne (symbol_ref "optimize_size") (const_int 0))
85                     (eq (symbol_ref "TARGET_SSE2") (const_int 0)))
86                (and (eq_attr "alternative" "2")
87                     (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
88                         (const_int 0))))
89           (const_string "V4SF")
90           (const_string "TI")))])
91
92 ;; Move a DI from a 32-bit register pair (e.g. %edx:%eax) to an xmm.
93 ;; We'd rather avoid this entirely; if the 32-bit reg pair was loaded
94 ;; from memory, we'd prefer to load the memory directly into the %xmm
95 ;; register.  To facilitate this happy circumstance, this pattern won't
96 ;; split until after register allocation.  If the 64-bit value didn't
97 ;; come from memory, this is the best we can do.  This is much better
98 ;; than storing %edx:%eax into a stack temporary and loading an %xmm
99 ;; from there.
100
101 (define_insn_and_split "movdi_to_sse"
102   [(parallel
103     [(set (match_operand:V4SI 0 "register_operand" "=?x,x")
104           (subreg:V4SI (match_operand:DI 1 "nonimmediate_operand" "r,m") 0))
105      (clobber (match_scratch:V4SI 2 "=&x,X"))])]
106   "!TARGET_64BIT && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES"
107   "#"
108   "&& reload_completed"
109   [(const_int 0)]
110 {
111   switch (which_alternative)
112     {
113     case 0:
114       /* The DImode arrived in a pair of integral registers (e.g. %edx:%eax).
115          Assemble the 64-bit DImode value in an xmm register.  */
116       emit_insn (gen_sse2_loadld (operands[0], CONST0_RTX (V4SImode),
117                                   gen_rtx_SUBREG (SImode, operands[1], 0)));
118       emit_insn (gen_sse2_loadld (operands[2], CONST0_RTX (V4SImode),
119                                   gen_rtx_SUBREG (SImode, operands[1], 4)));
120       emit_insn (gen_sse2_punpckldq (operands[0], operands[0], operands[2]));
121       break;
122
123     case 1:
124       emit_insn (gen_vec_concatv2di (operands[0], operands[1], const0_rtx));
125       break;
126
127     default:
128       gcc_unreachable ();
129     }
130   DONE;
131 })
132
133 (define_expand "movv4sf"
134   [(set (match_operand:V4SF 0 "nonimmediate_operand" "")
135         (match_operand:V4SF 1 "nonimmediate_operand" ""))]
136   "TARGET_SSE"
137 {
138   ix86_expand_vector_move (V4SFmode, operands);
139   DONE;
140 })
141
142 (define_insn "*movv4sf_internal"
143   [(set (match_operand:V4SF 0 "nonimmediate_operand" "=x,x,m")
144         (match_operand:V4SF 1 "nonimmediate_or_sse_const_operand" "C,xm,x"))]
145   "TARGET_SSE
146    && (register_operand (operands[0], V4SFmode)
147        || register_operand (operands[1], V4SFmode))"
148 {
149   switch (which_alternative)
150     {
151     case 0:
152       return standard_sse_constant_opcode (insn, operands[1]);
153     case 1:
154     case 2:
155       return "movaps\t{%1, %0|%0, %1}";
156     default:
157       abort();
158     }
159 }
160   [(set_attr "type" "sselog1,ssemov,ssemov")
161    (set_attr "mode" "V4SF")])
162
163 (define_split
164   [(set (match_operand:V4SF 0 "register_operand" "")
165         (match_operand:V4SF 1 "zero_extended_scalar_load_operand" ""))]
166   "TARGET_SSE && reload_completed"
167   [(set (match_dup 0)
168         (vec_merge:V4SF
169           (vec_duplicate:V4SF (match_dup 1))
170           (match_dup 2)
171           (const_int 1)))]
172 {
173   operands[1] = simplify_gen_subreg (SFmode, operands[1], V4SFmode, 0);
174   operands[2] = CONST0_RTX (V4SFmode);
175 })
176
177 (define_expand "movv2df"
178   [(set (match_operand:V2DF 0 "nonimmediate_operand" "")
179         (match_operand:V2DF 1 "nonimmediate_operand" ""))]
180   "TARGET_SSE"
181 {
182   ix86_expand_vector_move (V2DFmode, operands);
183   DONE;
184 })
185
186 (define_insn "*movv2df_internal"
187   [(set (match_operand:V2DF 0 "nonimmediate_operand" "=x,x,m")
188         (match_operand:V2DF 1 "nonimmediate_or_sse_const_operand" "C,xm,x"))]
189   "TARGET_SSE
190    && (register_operand (operands[0], V2DFmode)
191        || register_operand (operands[1], V2DFmode))"
192 {
193   switch (which_alternative)
194     {
195     case 0:
196       return standard_sse_constant_opcode (insn, operands[1]);
197     case 1:
198     case 2:
199       if (get_attr_mode (insn) == MODE_V4SF)
200         return "movaps\t{%1, %0|%0, %1}";
201       else
202         return "movapd\t{%1, %0|%0, %1}";
203     default:
204       gcc_unreachable ();
205     }
206 }
207   [(set_attr "type" "sselog1,ssemov,ssemov")
208    (set (attr "mode")
209         (if_then_else
210           (ior (ior (ne (symbol_ref "optimize_size") (const_int 0))
211                     (eq (symbol_ref "TARGET_SSE2") (const_int 0)))
212                (and (eq_attr "alternative" "2")
213                     (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
214                         (const_int 0))))
215           (const_string "V4SF")
216           (const_string "V2DF")))])
217
218 (define_split
219   [(set (match_operand:V2DF 0 "register_operand" "")
220         (match_operand:V2DF 1 "zero_extended_scalar_load_operand" ""))]
221   "TARGET_SSE2 && reload_completed"
222   [(set (match_dup 0) (vec_concat:V2DF (match_dup 1) (match_dup 2)))]
223 {
224   operands[1] = simplify_gen_subreg (DFmode, operands[1], V2DFmode, 0);
225   operands[2] = CONST0_RTX (DFmode);
226 })
227
228 (define_expand "push<mode>1"
229   [(match_operand:SSEMODE 0 "register_operand" "")]
230   "TARGET_SSE"
231 {
232   ix86_expand_push (<MODE>mode, operands[0]);
233   DONE;
234 })
235
236 (define_expand "movmisalign<mode>"
237   [(set (match_operand:SSEMODE 0 "nonimmediate_operand" "")
238         (match_operand:SSEMODE 1 "nonimmediate_operand" ""))]
239   "TARGET_SSE"
240 {
241   ix86_expand_vector_move_misalign (<MODE>mode, operands);
242   DONE;
243 })
244
245 (define_insn "sse_movups"
246   [(set (match_operand:V4SF 0 "nonimmediate_operand" "=x,m")
247         (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "xm,x")]
248                      UNSPEC_MOVU))]
249   "TARGET_SSE && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
250   "movups\t{%1, %0|%0, %1}"
251   [(set_attr "type" "ssemov")
252    (set_attr "mode" "V2DF")])
253
254 (define_insn "sse2_movupd"
255   [(set (match_operand:V2DF 0 "nonimmediate_operand" "=x,m")
256         (unspec:V2DF [(match_operand:V2DF 1 "nonimmediate_operand" "xm,x")]
257                      UNSPEC_MOVU))]
258   "TARGET_SSE2 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
259   "movupd\t{%1, %0|%0, %1}"
260   [(set_attr "type" "ssemov")
261    (set_attr "mode" "V2DF")])
262
263 (define_insn "sse2_movdqu"
264   [(set (match_operand:V16QI 0 "nonimmediate_operand" "=x,m")
265         (unspec:V16QI [(match_operand:V16QI 1 "nonimmediate_operand" "xm,x")]
266                       UNSPEC_MOVU))]
267   "TARGET_SSE2 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
268   "movdqu\t{%1, %0|%0, %1}"
269   [(set_attr "type" "ssemov")
270    (set_attr "prefix_data16" "1")
271    (set_attr "mode" "TI")])
272
273 (define_insn "sse_movntv4sf"
274   [(set (match_operand:V4SF 0 "memory_operand" "=m")
275         (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "x")]
276                      UNSPEC_MOVNT))]
277   "TARGET_SSE"
278   "movntps\t{%1, %0|%0, %1}"
279   [(set_attr "type" "ssemov")
280    (set_attr "mode" "V4SF")])
281
282 (define_insn "sse2_movntv2df"
283   [(set (match_operand:V2DF 0 "memory_operand" "=m")
284         (unspec:V2DF [(match_operand:V2DF 1 "register_operand" "x")]
285                      UNSPEC_MOVNT))]
286   "TARGET_SSE2"
287   "movntpd\t{%1, %0|%0, %1}"
288   [(set_attr "type" "ssecvt")
289    (set_attr "mode" "V2DF")])
290
291 (define_insn "sse2_movntv2di"
292   [(set (match_operand:V2DI 0 "memory_operand" "=m")
293         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "x")]
294                      UNSPEC_MOVNT))]
295   "TARGET_SSE2"
296   "movntdq\t{%1, %0|%0, %1}"
297   [(set_attr "type" "ssecvt")
298    (set_attr "prefix_data16" "1")
299    (set_attr "mode" "TI")])
300
301 (define_insn "sse2_movntsi"
302   [(set (match_operand:SI 0 "memory_operand" "=m")
303         (unspec:SI [(match_operand:SI 1 "register_operand" "r")]
304                    UNSPEC_MOVNT))]
305   "TARGET_SSE2"
306   "movnti\t{%1, %0|%0, %1}"
307   [(set_attr "type" "ssecvt")
308    (set_attr "mode" "V2DF")])
309
310 (define_insn "sse3_lddqu"
311   [(set (match_operand:V16QI 0 "register_operand" "=x")
312         (unspec:V16QI [(match_operand:V16QI 1 "memory_operand" "m")]
313                       UNSPEC_LDDQU))]
314   "TARGET_SSE3"
315   "lddqu\t{%1, %0|%0, %1}"
316   [(set_attr "type" "ssecvt")
317    (set_attr "prefix_rep" "1")
318    (set_attr "mode" "TI")])
319
320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
321 ;;
322 ;; Parallel single-precision floating point arithmetic
323 ;;
324 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
325
326 (define_expand "negv4sf2"
327   [(set (match_operand:V4SF 0 "register_operand" "")
328         (neg:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "")))]
329   "TARGET_SSE"
330   "ix86_expand_fp_absneg_operator (NEG, V4SFmode, operands); DONE;")
331
332 (define_expand "absv4sf2"
333   [(set (match_operand:V4SF 0 "register_operand" "")
334         (abs:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "")))]
335   "TARGET_SSE"
336   "ix86_expand_fp_absneg_operator (ABS, V4SFmode, operands); DONE;")
337
338 (define_expand "addv4sf3"
339   [(set (match_operand:V4SF 0 "register_operand" "")
340         (plus:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "")
341                    (match_operand:V4SF 2 "nonimmediate_operand" "")))]
342   "TARGET_SSE"
343   "ix86_fixup_binary_operands_no_copy (PLUS, V4SFmode, operands);")
344
345 (define_insn "*addv4sf3"
346   [(set (match_operand:V4SF 0 "register_operand" "=x")
347         (plus:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "%0")
348                    (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
349   "TARGET_SSE && ix86_binary_operator_ok (PLUS, V4SFmode, operands)"
350   "addps\t{%2, %0|%0, %2}"
351   [(set_attr "type" "sseadd")
352    (set_attr "mode" "V4SF")])
353
354 (define_insn "sse_vmaddv4sf3"
355   [(set (match_operand:V4SF 0 "register_operand" "=x")
356         (vec_merge:V4SF
357           (plus:V4SF (match_operand:V4SF 1 "register_operand" "0")
358                      (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
359           (match_dup 1)
360           (const_int 1)))]
361   "TARGET_SSE && ix86_binary_operator_ok (PLUS, V4SFmode, operands)"
362   "addss\t{%2, %0|%0, %2}"
363   [(set_attr "type" "sseadd")
364    (set_attr "mode" "SF")])
365
366 (define_expand "subv4sf3"
367   [(set (match_operand:V4SF 0 "register_operand" "")
368         (minus:V4SF (match_operand:V4SF 1 "register_operand" "")
369                     (match_operand:V4SF 2 "nonimmediate_operand" "")))]
370   "TARGET_SSE"
371   "ix86_fixup_binary_operands_no_copy (MINUS, V4SFmode, operands);")
372
373 (define_insn "*subv4sf3"
374   [(set (match_operand:V4SF 0 "register_operand" "=x")
375         (minus:V4SF (match_operand:V4SF 1 "register_operand" "0")
376                     (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
377   "TARGET_SSE"
378   "subps\t{%2, %0|%0, %2}"
379   [(set_attr "type" "sseadd")
380    (set_attr "mode" "V4SF")])
381
382 (define_insn "sse_vmsubv4sf3"
383   [(set (match_operand:V4SF 0 "register_operand" "=x")
384         (vec_merge:V4SF
385           (minus:V4SF (match_operand:V4SF 1 "register_operand" "0")
386                       (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
387           (match_dup 1)
388           (const_int 1)))]
389   "TARGET_SSE"
390   "subss\t{%2, %0|%0, %2}"
391   [(set_attr "type" "sseadd")
392    (set_attr "mode" "SF")])
393
394 (define_expand "mulv4sf3"
395   [(set (match_operand:V4SF 0 "register_operand" "")
396         (mult:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "")
397                    (match_operand:V4SF 2 "nonimmediate_operand" "")))]
398   "TARGET_SSE"
399   "ix86_fixup_binary_operands_no_copy (MULT, V4SFmode, operands);")
400
401 (define_insn "*mulv4sf3"
402   [(set (match_operand:V4SF 0 "register_operand" "=x")
403         (mult:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "%0")
404                    (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
405   "TARGET_SSE && ix86_binary_operator_ok (MULT, V4SFmode, operands)"
406   "mulps\t{%2, %0|%0, %2}"
407   [(set_attr "type" "ssemul")
408    (set_attr "mode" "V4SF")])
409
410 (define_insn "sse_vmmulv4sf3"
411   [(set (match_operand:V4SF 0 "register_operand" "=x")
412         (vec_merge:V4SF
413           (mult:V4SF (match_operand:V4SF 1 "register_operand" "0")
414                      (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
415           (match_dup 1)
416           (const_int 1)))]
417   "TARGET_SSE && ix86_binary_operator_ok (MULT, V4SFmode, operands)"
418   "mulss\t{%2, %0|%0, %2}"
419   [(set_attr "type" "ssemul")
420    (set_attr "mode" "SF")])
421
422 (define_expand "divv4sf3"
423   [(set (match_operand:V4SF 0 "register_operand" "")
424         (div:V4SF (match_operand:V4SF 1 "register_operand" "")
425                   (match_operand:V4SF 2 "nonimmediate_operand" "")))]
426   "TARGET_SSE"
427   "ix86_fixup_binary_operands_no_copy (DIV, V4SFmode, operands);")
428
429 (define_insn "*divv4sf3"
430   [(set (match_operand:V4SF 0 "register_operand" "=x")
431         (div:V4SF (match_operand:V4SF 1 "register_operand" "0")
432                   (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
433   "TARGET_SSE"
434   "divps\t{%2, %0|%0, %2}"
435   [(set_attr "type" "ssediv")
436    (set_attr "mode" "V4SF")])
437
438 (define_insn "sse_vmdivv4sf3"
439   [(set (match_operand:V4SF 0 "register_operand" "=x")
440         (vec_merge:V4SF
441           (div:V4SF (match_operand:V4SF 1 "register_operand" "0")
442                     (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
443           (match_dup 1)
444           (const_int 1)))]
445   "TARGET_SSE"
446   "divss\t{%2, %0|%0, %2}"
447   [(set_attr "type" "ssediv")
448    (set_attr "mode" "SF")])
449
450 (define_insn "sse_rcpv4sf2"
451   [(set (match_operand:V4SF 0 "register_operand" "=x")
452         (unspec:V4SF
453          [(match_operand:V4SF 1 "nonimmediate_operand" "xm")] UNSPEC_RCP))]
454   "TARGET_SSE"
455   "rcpps\t{%1, %0|%0, %1}"
456   [(set_attr "type" "sse")
457    (set_attr "mode" "V4SF")])
458
459 (define_insn "sse_vmrcpv4sf2"
460   [(set (match_operand:V4SF 0 "register_operand" "=x")
461         (vec_merge:V4SF
462           (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "xm")]
463                        UNSPEC_RCP)
464           (match_operand:V4SF 2 "register_operand" "0")
465           (const_int 1)))]
466   "TARGET_SSE"
467   "rcpss\t{%1, %0|%0, %1}"
468   [(set_attr "type" "sse")
469    (set_attr "mode" "SF")])
470
471 (define_insn "sse_rsqrtv4sf2"
472   [(set (match_operand:V4SF 0 "register_operand" "=x")
473         (unspec:V4SF
474           [(match_operand:V4SF 1 "nonimmediate_operand" "xm")] UNSPEC_RSQRT))]
475   "TARGET_SSE"
476   "rsqrtps\t{%1, %0|%0, %1}"
477   [(set_attr "type" "sse")
478    (set_attr "mode" "V4SF")])
479
480 (define_insn "sse_vmrsqrtv4sf2"
481   [(set (match_operand:V4SF 0 "register_operand" "=x")
482         (vec_merge:V4SF
483           (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "xm")]
484                        UNSPEC_RSQRT)
485           (match_operand:V4SF 2 "register_operand" "0")
486           (const_int 1)))]
487   "TARGET_SSE"
488   "rsqrtss\t{%1, %0|%0, %1}"
489   [(set_attr "type" "sse")
490    (set_attr "mode" "SF")])
491
492 (define_insn "sqrtv4sf2"
493   [(set (match_operand:V4SF 0 "register_operand" "=x")
494         (sqrt:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "xm")))]
495   "TARGET_SSE"
496   "sqrtps\t{%1, %0|%0, %1}"
497   [(set_attr "type" "sse")
498    (set_attr "mode" "V4SF")])
499
500 (define_insn "sse_vmsqrtv4sf2"
501   [(set (match_operand:V4SF 0 "register_operand" "=x")
502         (vec_merge:V4SF
503           (sqrt:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "xm"))
504           (match_operand:V4SF 2 "register_operand" "0")
505           (const_int 1)))]
506   "TARGET_SSE"
507   "sqrtss\t{%1, %0|%0, %1}"
508   [(set_attr "type" "sse")
509    (set_attr "mode" "SF")])
510
511 ;; ??? For !flag_finite_math_only, the representation with SMIN/SMAX
512 ;; isn't really correct, as those rtl operators aren't defined when 
513 ;; applied to NaNs.  Hopefully the optimizers won't get too smart on us.
514
515 (define_expand "smaxv4sf3"
516   [(set (match_operand:V4SF 0 "register_operand" "")
517         (smax:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "")
518                    (match_operand:V4SF 2 "nonimmediate_operand" "")))]
519   "TARGET_SSE"
520 {
521   if (!flag_finite_math_only)
522     operands[1] = force_reg (V4SFmode, operands[1]);
523   ix86_fixup_binary_operands_no_copy (SMAX, V4SFmode, operands);
524 })
525
526 (define_insn "*smaxv4sf3_finite"
527   [(set (match_operand:V4SF 0 "register_operand" "=x")
528         (smax:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "%0")
529                    (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
530   "TARGET_SSE && flag_finite_math_only
531    && ix86_binary_operator_ok (SMAX, V4SFmode, operands)"
532   "maxps\t{%2, %0|%0, %2}"
533   [(set_attr "type" "sse")
534    (set_attr "mode" "V4SF")])
535
536 (define_insn "*smaxv4sf3"
537   [(set (match_operand:V4SF 0 "register_operand" "=x")
538         (smax:V4SF (match_operand:V4SF 1 "register_operand" "0")
539                    (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
540   "TARGET_SSE"
541   "maxps\t{%2, %0|%0, %2}"
542   [(set_attr "type" "sse")
543    (set_attr "mode" "V4SF")])
544
545 (define_insn "sse_vmsmaxv4sf3"
546   [(set (match_operand:V4SF 0 "register_operand" "=x")
547         (vec_merge:V4SF
548          (smax:V4SF (match_operand:V4SF 1 "register_operand" "0")
549                     (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
550          (match_dup 1)
551          (const_int 1)))]
552   "TARGET_SSE"
553   "maxss\t{%2, %0|%0, %2}"
554   [(set_attr "type" "sse")
555    (set_attr "mode" "SF")])
556
557 (define_expand "sminv4sf3"
558   [(set (match_operand:V4SF 0 "register_operand" "")
559         (smin:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "")
560                    (match_operand:V4SF 2 "nonimmediate_operand" "")))]
561   "TARGET_SSE"
562 {
563   if (!flag_finite_math_only)
564     operands[1] = force_reg (V4SFmode, operands[1]);
565   ix86_fixup_binary_operands_no_copy (SMIN, V4SFmode, operands);
566 })
567
568 (define_insn "*sminv4sf3_finite"
569   [(set (match_operand:V4SF 0 "register_operand" "=x")
570         (smin:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "%0")
571                    (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
572   "TARGET_SSE && flag_finite_math_only
573    && ix86_binary_operator_ok (SMIN, V4SFmode, operands)"
574   "minps\t{%2, %0|%0, %2}"
575   [(set_attr "type" "sse")
576    (set_attr "mode" "V4SF")])
577
578 (define_insn "*sminv4sf3"
579   [(set (match_operand:V4SF 0 "register_operand" "=x")
580         (smin:V4SF (match_operand:V4SF 1 "register_operand" "0")
581                    (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
582   "TARGET_SSE"
583   "minps\t{%2, %0|%0, %2}"
584   [(set_attr "type" "sse")
585    (set_attr "mode" "V4SF")])
586
587 (define_insn "sse_vmsminv4sf3"
588   [(set (match_operand:V4SF 0 "register_operand" "=x")
589         (vec_merge:V4SF
590          (smin:V4SF (match_operand:V4SF 1 "register_operand" "0")
591                     (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
592          (match_dup 1)
593          (const_int 1)))]
594   "TARGET_SSE"
595   "minss\t{%2, %0|%0, %2}"
596   [(set_attr "type" "sse")
597    (set_attr "mode" "SF")])
598
599 ;; These versions of the min/max patterns implement exactly the operations
600 ;;   min = (op1 < op2 ? op1 : op2)
601 ;;   max = (!(op1 < op2) ? op1 : op2)
602 ;; Their operands are not commutative, and thus they may be used in the
603 ;; presence of -0.0 and NaN.
604
605 (define_insn "*ieee_sminv4sf3"
606   [(set (match_operand:V4SF 0 "register_operand" "=x")
607         (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "0")
608                       (match_operand:V4SF 2 "nonimmediate_operand" "xm")]
609                      UNSPEC_IEEE_MIN))]
610   "TARGET_SSE"
611   "minps\t{%2, %0|%0, %2}"
612   [(set_attr "type" "sseadd")
613    (set_attr "mode" "V4SF")])
614
615 (define_insn "*ieee_smaxv4sf3"
616   [(set (match_operand:V4SF 0 "register_operand" "=x")
617         (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "0")
618                       (match_operand:V4SF 2 "nonimmediate_operand" "xm")]
619                      UNSPEC_IEEE_MAX))]
620   "TARGET_SSE"
621   "maxps\t{%2, %0|%0, %2}"
622   [(set_attr "type" "sseadd")
623    (set_attr "mode" "V4SF")])
624
625 (define_insn "*ieee_sminv2df3"
626   [(set (match_operand:V2DF 0 "register_operand" "=x")
627         (unspec:V2DF [(match_operand:V2DF 1 "register_operand" "0")
628                       (match_operand:V2DF 2 "nonimmediate_operand" "xm")]
629                      UNSPEC_IEEE_MIN))]
630   "TARGET_SSE2"
631   "minpd\t{%2, %0|%0, %2}"
632   [(set_attr "type" "sseadd")
633    (set_attr "mode" "V2DF")])
634
635 (define_insn "*ieee_smaxv2df3"
636   [(set (match_operand:V2DF 0 "register_operand" "=x")
637         (unspec:V2DF [(match_operand:V2DF 1 "register_operand" "0")
638                       (match_operand:V2DF 2 "nonimmediate_operand" "xm")]
639                      UNSPEC_IEEE_MAX))]
640   "TARGET_SSE2"
641   "maxpd\t{%2, %0|%0, %2}"
642   [(set_attr "type" "sseadd")
643    (set_attr "mode" "V2DF")])
644
645 (define_insn "sse3_addsubv4sf3"
646   [(set (match_operand:V4SF 0 "register_operand" "=x")
647         (vec_merge:V4SF
648           (plus:V4SF
649             (match_operand:V4SF 1 "register_operand" "0")
650             (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
651           (minus:V4SF (match_dup 1) (match_dup 2))
652           (const_int 5)))]
653   "TARGET_SSE3"
654   "addsubps\t{%2, %0|%0, %2}"
655   [(set_attr "type" "sseadd")
656    (set_attr "prefix_rep" "1")
657    (set_attr "mode" "V4SF")])
658
659 (define_insn "sse3_haddv4sf3"
660   [(set (match_operand:V4SF 0 "register_operand" "=x")
661         (vec_concat:V4SF
662           (vec_concat:V2SF
663             (plus:SF
664               (vec_select:SF 
665                 (match_operand:V4SF 1 "register_operand" "0")
666                 (parallel [(const_int 0)]))
667               (vec_select:SF (match_dup 1) (parallel [(const_int 1)])))
668             (plus:SF
669               (vec_select:SF (match_dup 1) (parallel [(const_int 2)]))
670               (vec_select:SF (match_dup 1) (parallel [(const_int 3)]))))
671           (vec_concat:V2SF
672             (plus:SF
673               (vec_select:SF
674                 (match_operand:V4SF 2 "nonimmediate_operand" "xm")
675                 (parallel [(const_int 0)]))
676               (vec_select:SF (match_dup 2) (parallel [(const_int 1)])))
677             (plus:SF
678               (vec_select:SF (match_dup 2) (parallel [(const_int 2)]))
679               (vec_select:SF (match_dup 2) (parallel [(const_int 3)]))))))]
680   "TARGET_SSE3"
681   "haddps\t{%2, %0|%0, %2}"
682   [(set_attr "type" "sseadd")
683    (set_attr "prefix_rep" "1")
684    (set_attr "mode" "V4SF")])
685
686 (define_insn "sse3_hsubv4sf3"
687   [(set (match_operand:V4SF 0 "register_operand" "=x")
688         (vec_concat:V4SF
689           (vec_concat:V2SF
690             (minus:SF
691               (vec_select:SF 
692                 (match_operand:V4SF 1 "register_operand" "0")
693                 (parallel [(const_int 0)]))
694               (vec_select:SF (match_dup 1) (parallel [(const_int 1)])))
695             (minus:SF
696               (vec_select:SF (match_dup 1) (parallel [(const_int 2)]))
697               (vec_select:SF (match_dup 1) (parallel [(const_int 3)]))))
698           (vec_concat:V2SF
699             (minus:SF
700               (vec_select:SF
701                 (match_operand:V4SF 2 "nonimmediate_operand" "xm")
702                 (parallel [(const_int 0)]))
703               (vec_select:SF (match_dup 2) (parallel [(const_int 1)])))
704             (minus:SF
705               (vec_select:SF (match_dup 2) (parallel [(const_int 2)]))
706               (vec_select:SF (match_dup 2) (parallel [(const_int 3)]))))))]
707   "TARGET_SSE3"
708   "hsubps\t{%2, %0|%0, %2}"
709   [(set_attr "type" "sseadd")
710    (set_attr "prefix_rep" "1")
711    (set_attr "mode" "V4SF")])
712
713 (define_expand "reduc_splus_v4sf"
714   [(match_operand:V4SF 0 "register_operand" "")
715    (match_operand:V4SF 1 "register_operand" "")]
716   "TARGET_SSE"
717 {
718   if (TARGET_SSE3)
719     {
720       rtx tmp = gen_reg_rtx (V4SFmode);
721       emit_insn (gen_sse3_haddv4sf3 (tmp, operands[1], operands[1]));
722       emit_insn (gen_sse3_haddv4sf3 (operands[0], tmp, tmp));
723     }
724   else
725     ix86_expand_reduc_v4sf (gen_addv4sf3, operands[0], operands[1]);
726   DONE;
727 })
728
729 (define_expand "reduc_smax_v4sf"
730   [(match_operand:V4SF 0 "register_operand" "")
731    (match_operand:V4SF 1 "register_operand" "")]
732   "TARGET_SSE"
733 {
734   ix86_expand_reduc_v4sf (gen_smaxv4sf3, operands[0], operands[1]);
735   DONE;
736 })
737
738 (define_expand "reduc_smin_v4sf"
739   [(match_operand:V4SF 0 "register_operand" "")
740    (match_operand:V4SF 1 "register_operand" "")]
741   "TARGET_SSE"
742 {
743   ix86_expand_reduc_v4sf (gen_sminv4sf3, operands[0], operands[1]);
744   DONE;
745 })
746
747 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
748 ;;
749 ;; Parallel single-precision floating point comparisons
750 ;;
751 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
752
753 (define_insn "sse_maskcmpv4sf3"
754   [(set (match_operand:V4SF 0 "register_operand" "=x")
755         (match_operator:V4SF 3 "sse_comparison_operator"
756                 [(match_operand:V4SF 1 "register_operand" "0")
757                  (match_operand:V4SF 2 "nonimmediate_operand" "xm")]))]
758   "TARGET_SSE"
759   "cmp%D3ps\t{%2, %0|%0, %2}"
760   [(set_attr "type" "ssecmp")
761    (set_attr "mode" "V4SF")])
762
763 (define_insn "sse_maskcmpsf3"
764   [(set (match_operand:SF 0 "register_operand" "=x")
765         (match_operator:SF 3 "sse_comparison_operator"
766                 [(match_operand:SF 1 "register_operand" "0")
767                  (match_operand:SF 2 "nonimmediate_operand" "xm")]))]
768   "TARGET_SSE"
769   "cmp%D3ss\t{%2, %0|%0, %2}"
770   [(set_attr "type" "ssecmp")
771    (set_attr "mode" "SF")])
772
773 (define_insn "sse_vmmaskcmpv4sf3"
774   [(set (match_operand:V4SF 0 "register_operand" "=x")
775         (vec_merge:V4SF
776          (match_operator:V4SF 3 "sse_comparison_operator"
777                 [(match_operand:V4SF 1 "register_operand" "0")
778                  (match_operand:V4SF 2 "register_operand" "x")])
779          (match_dup 1)
780          (const_int 1)))]
781   "TARGET_SSE"
782   "cmp%D3ss\t{%2, %0|%0, %2}"
783   [(set_attr "type" "ssecmp")
784    (set_attr "mode" "SF")])
785
786 (define_insn "sse_comi"
787   [(set (reg:CCFP FLAGS_REG)
788         (compare:CCFP
789           (vec_select:SF
790             (match_operand:V4SF 0 "register_operand" "x")
791             (parallel [(const_int 0)]))
792           (vec_select:SF
793             (match_operand:V4SF 1 "nonimmediate_operand" "xm")
794             (parallel [(const_int 0)]))))]
795   "TARGET_SSE"
796   "comiss\t{%1, %0|%0, %1}"
797   [(set_attr "type" "ssecomi")
798    (set_attr "mode" "SF")])
799
800 (define_insn "sse_ucomi"
801   [(set (reg:CCFPU FLAGS_REG)
802         (compare:CCFPU
803           (vec_select:SF
804             (match_operand:V4SF 0 "register_operand" "x")
805             (parallel [(const_int 0)]))
806           (vec_select:SF
807             (match_operand:V4SF 1 "nonimmediate_operand" "xm")
808             (parallel [(const_int 0)]))))]
809   "TARGET_SSE"
810   "ucomiss\t{%1, %0|%0, %1}"
811   [(set_attr "type" "ssecomi")
812    (set_attr "mode" "SF")])
813
814 (define_expand "vcondv4sf"
815   [(set (match_operand:V4SF 0 "register_operand" "")
816         (if_then_else:V4SF
817           (match_operator 3 ""
818             [(match_operand:V4SF 4 "nonimmediate_operand" "")
819              (match_operand:V4SF 5 "nonimmediate_operand" "")])
820           (match_operand:V4SF 1 "general_operand" "")
821           (match_operand:V4SF 2 "general_operand" "")))]
822   "TARGET_SSE"
823 {
824   if (ix86_expand_fp_vcond (operands))
825     DONE;
826   else
827     FAIL;
828 })
829
830 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
831 ;;
832 ;; Parallel single-precision floating point logical operations
833 ;;
834 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
835
836 (define_expand "andv4sf3"
837   [(set (match_operand:V4SF 0 "register_operand" "")
838         (and:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "")
839                   (match_operand:V4SF 2 "nonimmediate_operand" "")))]
840   "TARGET_SSE"
841   "ix86_fixup_binary_operands_no_copy (AND, V4SFmode, operands);")
842
843 (define_insn "*andv4sf3"
844   [(set (match_operand:V4SF 0 "register_operand" "=x")
845         (and:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "%0")
846                   (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
847   "TARGET_SSE && ix86_binary_operator_ok (AND, V4SFmode, operands)"
848   "andps\t{%2, %0|%0, %2}"
849   [(set_attr "type" "sselog")
850    (set_attr "mode" "V4SF")])
851
852 (define_insn "sse_nandv4sf3"
853   [(set (match_operand:V4SF 0 "register_operand" "=x")
854         (and:V4SF (not:V4SF (match_operand:V4SF 1 "register_operand" "0"))
855                   (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
856   "TARGET_SSE"
857   "andnps\t{%2, %0|%0, %2}"
858   [(set_attr "type" "sselog")
859    (set_attr "mode" "V4SF")])
860
861 (define_expand "iorv4sf3"
862   [(set (match_operand:V4SF 0 "register_operand" "")
863         (ior:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "")
864                   (match_operand:V4SF 2 "nonimmediate_operand" "")))]
865   "TARGET_SSE"
866   "ix86_fixup_binary_operands_no_copy (IOR, V4SFmode, operands);")
867
868 (define_insn "*iorv4sf3"
869   [(set (match_operand:V4SF 0 "register_operand" "=x")
870         (ior:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "%0")
871                   (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
872   "TARGET_SSE && ix86_binary_operator_ok (IOR, V4SFmode, operands)"
873   "orps\t{%2, %0|%0, %2}"
874   [(set_attr "type" "sselog")
875    (set_attr "mode" "V4SF")])
876
877 (define_expand "xorv4sf3"
878   [(set (match_operand:V4SF 0 "register_operand" "")
879         (xor:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "")
880                   (match_operand:V4SF 2 "nonimmediate_operand" "")))]
881   "TARGET_SSE"
882   "ix86_fixup_binary_operands_no_copy (XOR, V4SFmode, operands);")
883
884 (define_insn "*xorv4sf3"
885   [(set (match_operand:V4SF 0 "register_operand" "=x")
886         (xor:V4SF (match_operand:V4SF 1 "nonimmediate_operand" "%0")
887                   (match_operand:V4SF 2 "nonimmediate_operand" "xm")))]
888   "TARGET_SSE && ix86_binary_operator_ok (XOR, V4SFmode, operands)"
889   "xorps\t{%2, %0|%0, %2}"
890   [(set_attr "type" "sselog")
891    (set_attr "mode" "V4SF")])
892
893 ;; Also define scalar versions.  These are used for abs, neg, and
894 ;; conditional move.  Using subregs into vector modes causes register
895 ;; allocation lossage.  These patterns do not allow memory operands
896 ;; because the native instructions read the full 128-bits.
897
898 (define_insn "*andsf3"
899   [(set (match_operand:SF 0 "register_operand" "=x")
900         (and:SF (match_operand:SF 1 "register_operand" "0")
901                 (match_operand:SF 2 "register_operand" "x")))]
902   "TARGET_SSE"
903   "andps\t{%2, %0|%0, %2}"
904   [(set_attr "type" "sselog")
905    (set_attr "mode" "V4SF")])
906
907 (define_insn "*nandsf3"
908   [(set (match_operand:SF 0 "register_operand" "=x")
909         (and:SF (not:SF (match_operand:SF 1 "register_operand" "0"))
910                 (match_operand:SF 2 "register_operand" "x")))]
911   "TARGET_SSE"
912   "andnps\t{%2, %0|%0, %2}"
913   [(set_attr "type" "sselog")
914    (set_attr "mode" "V4SF")])
915
916 (define_insn "*iorsf3"
917   [(set (match_operand:SF 0 "register_operand" "=x")
918         (ior:SF (match_operand:SF 1 "register_operand" "0")
919                 (match_operand:SF 2 "register_operand" "x")))]
920   "TARGET_SSE"
921   "orps\t{%2, %0|%0, %2}"
922   [(set_attr "type" "sselog")
923    (set_attr "mode" "V4SF")])
924
925 (define_insn "*xorsf3"
926   [(set (match_operand:SF 0 "register_operand" "=x")
927         (xor:SF (match_operand:SF 1 "register_operand" "0")
928                 (match_operand:SF 2 "register_operand" "x")))]
929   "TARGET_SSE"
930   "xorps\t{%2, %0|%0, %2}"
931   [(set_attr "type" "sselog")
932    (set_attr "mode" "V4SF")])
933
934 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
935 ;;
936 ;; Parallel single-precision floating point conversion operations
937 ;;
938 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
939
940 (define_insn "sse_cvtpi2ps"
941   [(set (match_operand:V4SF 0 "register_operand" "=x")
942         (vec_merge:V4SF
943           (vec_duplicate:V4SF
944             (float:V2SF (match_operand:V2SI 2 "nonimmediate_operand" "ym")))
945           (match_operand:V4SF 1 "register_operand" "0")
946           (const_int 3)))]
947   "TARGET_SSE"
948   "cvtpi2ps\t{%2, %0|%0, %2}"
949   [(set_attr "type" "ssecvt")
950    (set_attr "mode" "V4SF")])
951
952 (define_insn "sse_cvtps2pi"
953   [(set (match_operand:V2SI 0 "register_operand" "=y")
954         (vec_select:V2SI
955           (unspec:V4SI [(match_operand:V4SF 1 "nonimmediate_operand" "xm")]
956                        UNSPEC_FIX_NOTRUNC)
957           (parallel [(const_int 0) (const_int 1)])))]
958   "TARGET_SSE"
959   "cvtps2pi\t{%1, %0|%0, %1}"
960   [(set_attr "type" "ssecvt")
961    (set_attr "unit" "mmx")
962    (set_attr "mode" "DI")])
963
964 (define_insn "sse_cvttps2pi"
965   [(set (match_operand:V2SI 0 "register_operand" "=y")
966         (vec_select:V2SI
967           (fix:V4SI (match_operand:V4SF 1 "nonimmediate_operand" "xm"))
968           (parallel [(const_int 0) (const_int 1)])))]
969   "TARGET_SSE"
970   "cvttps2pi\t{%1, %0|%0, %1}"
971   [(set_attr "type" "ssecvt")
972    (set_attr "unit" "mmx")
973    (set_attr "mode" "SF")])
974
975 (define_insn "sse_cvtsi2ss"
976   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
977         (vec_merge:V4SF
978           (vec_duplicate:V4SF
979             (float:SF (match_operand:SI 2 "nonimmediate_operand" "r,m")))
980           (match_operand:V4SF 1 "register_operand" "0,0")
981           (const_int 1)))]
982   "TARGET_SSE"
983   "cvtsi2ss\t{%2, %0|%0, %2}"
984   [(set_attr "type" "sseicvt")
985    (set_attr "athlon_decode" "vector,double")
986    (set_attr "amdfam10_decode" "vector,double")
987    (set_attr "mode" "SF")])
988
989 (define_insn "sse_cvtsi2ssq"
990   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
991         (vec_merge:V4SF
992           (vec_duplicate:V4SF
993             (float:SF (match_operand:DI 2 "nonimmediate_operand" "r,rm")))
994           (match_operand:V4SF 1 "register_operand" "0,0")
995           (const_int 1)))]
996   "TARGET_SSE && TARGET_64BIT"
997   "cvtsi2ssq\t{%2, %0|%0, %2}"
998   [(set_attr "type" "sseicvt")
999    (set_attr "athlon_decode" "vector,double")
1000    (set_attr "amdfam10_decode" "vector,double")
1001    (set_attr "mode" "SF")])
1002
1003 (define_insn "sse_cvtss2si"
1004   [(set (match_operand:SI 0 "register_operand" "=r,r")
1005         (unspec:SI
1006           [(vec_select:SF
1007              (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
1008              (parallel [(const_int 0)]))]
1009           UNSPEC_FIX_NOTRUNC))]
1010   "TARGET_SSE"
1011   "cvtss2si\t{%1, %0|%0, %1}"
1012   [(set_attr "type" "sseicvt")
1013    (set_attr "athlon_decode" "double,vector")
1014    (set_attr "prefix_rep" "1")
1015    (set_attr "mode" "SI")])
1016
1017 (define_insn "sse_cvtss2si_2"
1018   [(set (match_operand:SI 0 "register_operand" "=r,r")
1019         (unspec:SI [(match_operand:SF 1 "nonimmediate_operand" "x,m")]
1020          UNSPEC_FIX_NOTRUNC))]
1021   "TARGET_SSE"
1022   "cvtss2si\t{%1, %0|%0, %1}"
1023   [(set_attr "type" "sseicvt")
1024    (set_attr "athlon_decode" "double,vector")
1025    (set_attr "amdfam10_decode" "double,double")
1026    (set_attr "prefix_rep" "1")
1027    (set_attr "mode" "SI")])
1028
1029 (define_insn "sse_cvtss2siq"
1030   [(set (match_operand:DI 0 "register_operand" "=r,r")
1031         (unspec:DI
1032           [(vec_select:SF
1033              (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
1034              (parallel [(const_int 0)]))]
1035           UNSPEC_FIX_NOTRUNC))]
1036   "TARGET_SSE && TARGET_64BIT"
1037   "cvtss2siq\t{%1, %0|%0, %1}"
1038   [(set_attr "type" "sseicvt")
1039    (set_attr "athlon_decode" "double,vector")
1040    (set_attr "prefix_rep" "1")
1041    (set_attr "mode" "DI")])
1042
1043 (define_insn "sse_cvtss2siq_2"
1044   [(set (match_operand:DI 0 "register_operand" "=r,r")
1045         (unspec:DI [(match_operand:SF 1 "nonimmediate_operand" "x,m")]
1046          UNSPEC_FIX_NOTRUNC))]
1047   "TARGET_SSE && TARGET_64BIT"
1048   "cvtss2siq\t{%1, %0|%0, %1}"
1049   [(set_attr "type" "sseicvt")
1050    (set_attr "athlon_decode" "double,vector")
1051    (set_attr "amdfam10_decode" "double,double")
1052    (set_attr "prefix_rep" "1")
1053    (set_attr "mode" "DI")])
1054
1055 (define_insn "sse_cvttss2si"
1056   [(set (match_operand:SI 0 "register_operand" "=r,r")
1057         (fix:SI
1058           (vec_select:SF
1059             (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
1060             (parallel [(const_int 0)]))))]
1061   "TARGET_SSE"
1062   "cvttss2si\t{%1, %0|%0, %1}"
1063   [(set_attr "type" "sseicvt")
1064    (set_attr "athlon_decode" "double,vector")
1065    (set_attr "amdfam10_decode" "double,double")
1066    (set_attr "prefix_rep" "1")
1067    (set_attr "mode" "SI")])
1068
1069 (define_insn "sse_cvttss2siq"
1070   [(set (match_operand:DI 0 "register_operand" "=r,r")
1071         (fix:DI
1072           (vec_select:SF
1073             (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
1074             (parallel [(const_int 0)]))))]
1075   "TARGET_SSE && TARGET_64BIT"
1076   "cvttss2siq\t{%1, %0|%0, %1}"
1077   [(set_attr "type" "sseicvt")
1078    (set_attr "athlon_decode" "double,vector")
1079    (set_attr "amdfam10_decode" "double,double")
1080    (set_attr "prefix_rep" "1")
1081    (set_attr "mode" "DI")])
1082
1083 (define_insn "sse2_cvtdq2ps"
1084   [(set (match_operand:V4SF 0 "register_operand" "=x")
1085         (float:V4SF (match_operand:V4SI 1 "nonimmediate_operand" "xm")))]
1086   "TARGET_SSE2"
1087   "cvtdq2ps\t{%1, %0|%0, %1}"
1088   [(set_attr "type" "ssecvt")
1089    (set_attr "mode" "V4SF")])
1090
1091 (define_insn "sse2_cvtps2dq"
1092   [(set (match_operand:V4SI 0 "register_operand" "=x")
1093         (unspec:V4SI [(match_operand:V4SF 1 "nonimmediate_operand" "xm")]
1094                      UNSPEC_FIX_NOTRUNC))]
1095   "TARGET_SSE2"
1096   "cvtps2dq\t{%1, %0|%0, %1}"
1097   [(set_attr "type" "ssecvt")
1098    (set_attr "prefix_data16" "1")
1099    (set_attr "mode" "TI")])
1100
1101 (define_insn "sse2_cvttps2dq"
1102   [(set (match_operand:V4SI 0 "register_operand" "=x")
1103         (fix:V4SI (match_operand:V4SF 1 "nonimmediate_operand" "xm")))]
1104   "TARGET_SSE2"
1105   "cvttps2dq\t{%1, %0|%0, %1}"
1106   [(set_attr "type" "ssecvt")
1107    (set_attr "prefix_rep" "1")
1108    (set_attr "mode" "TI")])
1109
1110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1111 ;;
1112 ;; Parallel single-precision floating point element swizzling
1113 ;;
1114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1115
1116 (define_insn "sse_movhlps"
1117   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,m")
1118         (vec_select:V4SF
1119           (vec_concat:V8SF
1120             (match_operand:V4SF 1 "nonimmediate_operand" " 0,0,0")
1121             (match_operand:V4SF 2 "nonimmediate_operand" " x,o,x"))
1122           (parallel [(const_int 6)
1123                      (const_int 7)
1124                      (const_int 2)
1125                      (const_int 3)])))]
1126   "TARGET_SSE && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
1127   "@
1128    movhlps\t{%2, %0|%0, %2}
1129    movlps\t{%H2, %0|%0, %H2}
1130    movhps\t{%2, %0|%0, %2}"
1131   [(set_attr "type" "ssemov")
1132    (set_attr "mode" "V4SF,V2SF,V2SF")])
1133
1134 (define_insn "sse_movlhps"
1135   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,o")
1136         (vec_select:V4SF
1137           (vec_concat:V8SF
1138             (match_operand:V4SF 1 "nonimmediate_operand" " 0,0,0")
1139             (match_operand:V4SF 2 "nonimmediate_operand" " x,m,x"))
1140           (parallel [(const_int 0)
1141                      (const_int 1)
1142                      (const_int 4)
1143                      (const_int 5)])))]
1144   "TARGET_SSE && ix86_binary_operator_ok (UNKNOWN, V4SFmode, operands)"
1145   "@
1146    movlhps\t{%2, %0|%0, %2}
1147    movhps\t{%2, %0|%0, %2}
1148    movlps\t{%2, %H0|%H0, %2}"
1149   [(set_attr "type" "ssemov")
1150    (set_attr "mode" "V4SF,V2SF,V2SF")])
1151
1152 (define_insn "sse_unpckhps"
1153   [(set (match_operand:V4SF 0 "register_operand" "=x")
1154         (vec_select:V4SF
1155           (vec_concat:V8SF
1156             (match_operand:V4SF 1 "register_operand" "0")
1157             (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
1158           (parallel [(const_int 2) (const_int 6)
1159                      (const_int 3) (const_int 7)])))]
1160   "TARGET_SSE"
1161   "unpckhps\t{%2, %0|%0, %2}"
1162   [(set_attr "type" "sselog")
1163    (set_attr "mode" "V4SF")])
1164
1165 (define_insn "sse_unpcklps"
1166   [(set (match_operand:V4SF 0 "register_operand" "=x")
1167         (vec_select:V4SF
1168           (vec_concat:V8SF
1169             (match_operand:V4SF 1 "register_operand" "0")
1170             (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
1171           (parallel [(const_int 0) (const_int 4)
1172                      (const_int 1) (const_int 5)])))]
1173   "TARGET_SSE"
1174   "unpcklps\t{%2, %0|%0, %2}"
1175   [(set_attr "type" "sselog")
1176    (set_attr "mode" "V4SF")])
1177
1178 ;; These are modeled with the same vec_concat as the others so that we
1179 ;; capture users of shufps that can use the new instructions
1180 (define_insn "sse3_movshdup"
1181   [(set (match_operand:V4SF 0 "register_operand" "=x")
1182         (vec_select:V4SF
1183           (vec_concat:V8SF
1184             (match_operand:V4SF 1 "nonimmediate_operand" "xm")
1185             (match_dup 1))
1186           (parallel [(const_int 1)
1187                      (const_int 1)
1188                      (const_int 7)
1189                      (const_int 7)])))]
1190   "TARGET_SSE3"
1191   "movshdup\t{%1, %0|%0, %1}"
1192   [(set_attr "type" "sse")
1193    (set_attr "prefix_rep" "1")
1194    (set_attr "mode" "V4SF")])
1195
1196 (define_insn "sse3_movsldup"
1197   [(set (match_operand:V4SF 0 "register_operand" "=x")
1198         (vec_select:V4SF
1199           (vec_concat:V8SF
1200             (match_operand:V4SF 1 "nonimmediate_operand" "xm")
1201             (match_dup 1))
1202           (parallel [(const_int 0)
1203                      (const_int 0)
1204                      (const_int 6)
1205                      (const_int 6)])))]
1206   "TARGET_SSE3"
1207   "movsldup\t{%1, %0|%0, %1}"
1208   [(set_attr "type" "sse")
1209    (set_attr "prefix_rep" "1")
1210    (set_attr "mode" "V4SF")])
1211
1212 (define_expand "sse_shufps"
1213   [(match_operand:V4SF 0 "register_operand" "")
1214    (match_operand:V4SF 1 "register_operand" "")
1215    (match_operand:V4SF 2 "nonimmediate_operand" "")
1216    (match_operand:SI 3 "const_int_operand" "")]
1217   "TARGET_SSE"
1218 {
1219   int mask = INTVAL (operands[3]);
1220   emit_insn (gen_sse_shufps_1 (operands[0], operands[1], operands[2],
1221                                GEN_INT ((mask >> 0) & 3),
1222                                GEN_INT ((mask >> 2) & 3),
1223                                GEN_INT (((mask >> 4) & 3) + 4),
1224                                GEN_INT (((mask >> 6) & 3) + 4)));
1225   DONE;
1226 })
1227
1228 (define_insn "sse_shufps_1"
1229   [(set (match_operand:V4SF 0 "register_operand" "=x")
1230         (vec_select:V4SF
1231           (vec_concat:V8SF
1232             (match_operand:V4SF 1 "register_operand" "0")
1233             (match_operand:V4SF 2 "nonimmediate_operand" "xm"))
1234           (parallel [(match_operand 3 "const_0_to_3_operand" "")
1235                      (match_operand 4 "const_0_to_3_operand" "")
1236                      (match_operand 5 "const_4_to_7_operand" "")
1237                      (match_operand 6 "const_4_to_7_operand" "")])))]
1238   "TARGET_SSE"
1239 {
1240   int mask = 0;
1241   mask |= INTVAL (operands[3]) << 0;
1242   mask |= INTVAL (operands[4]) << 2;
1243   mask |= (INTVAL (operands[5]) - 4) << 4;
1244   mask |= (INTVAL (operands[6]) - 4) << 6;
1245   operands[3] = GEN_INT (mask);
1246
1247   return "shufps\t{%3, %2, %0|%0, %2, %3}";
1248 }
1249   [(set_attr "type" "sselog")
1250    (set_attr "mode" "V4SF")])
1251
1252 (define_insn "sse_storehps"
1253   [(set (match_operand:V2SF 0 "nonimmediate_operand" "=m,x,x")
1254         (vec_select:V2SF
1255           (match_operand:V4SF 1 "nonimmediate_operand" "x,x,o")
1256           (parallel [(const_int 2) (const_int 3)])))]
1257   "TARGET_SSE"
1258   "@
1259    movhps\t{%1, %0|%0, %1}
1260    movhlps\t{%1, %0|%0, %1}
1261    movlps\t{%H1, %0|%0, %H1}"
1262   [(set_attr "type" "ssemov")
1263    (set_attr "mode" "V2SF,V4SF,V2SF")])
1264
1265 (define_insn "sse_loadhps"
1266   [(set (match_operand:V4SF 0 "nonimmediate_operand" "=x,x,o")
1267         (vec_concat:V4SF
1268           (vec_select:V2SF
1269             (match_operand:V4SF 1 "nonimmediate_operand" "0,0,0")
1270             (parallel [(const_int 0) (const_int 1)]))
1271           (match_operand:V2SF 2 "nonimmediate_operand" "m,x,x")))]
1272   "TARGET_SSE"
1273   "@
1274    movhps\t{%2, %0|%0, %2}
1275    movlhps\t{%2, %0|%0, %2}
1276    movlps\t{%2, %H0|%H0, %2}"
1277   [(set_attr "type" "ssemov")
1278    (set_attr "mode" "V2SF,V4SF,V2SF")])
1279
1280 (define_insn "sse_storelps"
1281   [(set (match_operand:V2SF 0 "nonimmediate_operand" "=m,x,x")
1282         (vec_select:V2SF
1283           (match_operand:V4SF 1 "nonimmediate_operand" "x,x,m")
1284           (parallel [(const_int 0) (const_int 1)])))]
1285   "TARGET_SSE"
1286   "@
1287    movlps\t{%1, %0|%0, %1}
1288    movaps\t{%1, %0|%0, %1}
1289    movlps\t{%1, %0|%0, %1}"
1290   [(set_attr "type" "ssemov")
1291    (set_attr "mode" "V2SF,V4SF,V2SF")])
1292
1293 (define_insn "sse_loadlps"
1294   [(set (match_operand:V4SF 0 "nonimmediate_operand" "=x,x,m")
1295         (vec_concat:V4SF
1296           (match_operand:V2SF 2 "nonimmediate_operand" "0,m,x")
1297           (vec_select:V2SF
1298             (match_operand:V4SF 1 "nonimmediate_operand" "x,0,0")
1299             (parallel [(const_int 2) (const_int 3)]))))]
1300   "TARGET_SSE"
1301   "@
1302    shufps\t{$0xe4, %1, %0|%0, %1, 0xe4}
1303    movlps\t{%2, %0|%0, %2}
1304    movlps\t{%2, %0|%0, %2}"
1305   [(set_attr "type" "sselog,ssemov,ssemov")
1306    (set_attr "mode" "V4SF,V2SF,V2SF")])
1307
1308 (define_insn "sse_movss"
1309   [(set (match_operand:V4SF 0 "register_operand" "=x")
1310         (vec_merge:V4SF
1311           (match_operand:V4SF 2 "register_operand" "x")
1312           (match_operand:V4SF 1 "register_operand" "0")
1313           (const_int 1)))]
1314   "TARGET_SSE"
1315   "movss\t{%2, %0|%0, %2}"
1316   [(set_attr "type" "ssemov")
1317    (set_attr "mode" "SF")])
1318
1319 (define_insn "*vec_dupv4sf"
1320   [(set (match_operand:V4SF 0 "register_operand" "=x")
1321         (vec_duplicate:V4SF
1322           (match_operand:SF 1 "register_operand" "0")))]
1323   "TARGET_SSE"
1324   "shufps\t{$0, %0, %0|%0, %0, 0}"
1325   [(set_attr "type" "sselog1")
1326    (set_attr "mode" "V4SF")])
1327
1328 ;; ??? In theory we can match memory for the MMX alternative, but allowing
1329 ;; nonimmediate_operand for operand 2 and *not* allowing memory for the SSE
1330 ;; alternatives pretty much forces the MMX alternative to be chosen.
1331 (define_insn "*sse_concatv2sf"
1332   [(set (match_operand:V2SF 0 "register_operand"     "=x,x,*y,*y")
1333         (vec_concat:V2SF
1334           (match_operand:SF 1 "nonimmediate_operand" " 0,m, 0, m")
1335           (match_operand:SF 2 "reg_or_0_operand"     " x,C,*y, C")))]
1336   "TARGET_SSE"
1337   "@
1338    unpcklps\t{%2, %0|%0, %2}
1339    movss\t{%1, %0|%0, %1}
1340    punpckldq\t{%2, %0|%0, %2}
1341    movd\t{%1, %0|%0, %1}"
1342   [(set_attr "type" "sselog,ssemov,mmxcvt,mmxmov")
1343    (set_attr "mode" "V4SF,SF,DI,DI")])
1344
1345 (define_insn "*sse_concatv4sf"
1346   [(set (match_operand:V4SF 0 "register_operand"   "=x,x")
1347         (vec_concat:V4SF
1348           (match_operand:V2SF 1 "register_operand" " 0,0")
1349           (match_operand:V2SF 2 "nonimmediate_operand" " x,m")))]
1350   "TARGET_SSE"
1351   "@
1352    movlhps\t{%2, %0|%0, %2}
1353    movhps\t{%2, %0|%0, %2}"
1354   [(set_attr "type" "ssemov")
1355    (set_attr "mode" "V4SF,V2SF")])
1356
1357 (define_expand "vec_initv4sf"
1358   [(match_operand:V4SF 0 "register_operand" "")
1359    (match_operand 1 "" "")]
1360   "TARGET_SSE"
1361 {
1362   ix86_expand_vector_init (false, operands[0], operands[1]);
1363   DONE;
1364 })
1365
1366 (define_insn "vec_setv4sf_0"
1367   [(set (match_operand:V4SF 0 "nonimmediate_operand"  "=x,x,Y2,m")
1368         (vec_merge:V4SF
1369           (vec_duplicate:V4SF
1370             (match_operand:SF 2 "general_operand"     " x,m,*r,x*rfF"))
1371           (match_operand:V4SF 1 "vector_move_operand" " 0,C,C ,0")
1372           (const_int 1)))]
1373   "TARGET_SSE"
1374   "@
1375    movss\t{%2, %0|%0, %2}
1376    movss\t{%2, %0|%0, %2}
1377    movd\t{%2, %0|%0, %2}
1378    #"
1379   [(set_attr "type" "ssemov")
1380    (set_attr "mode" "SF")])
1381
1382 ;; A subset is vec_setv4sf.
1383 (define_insn "*vec_setv4sf_sse4_1"
1384   [(set (match_operand:V4SF 0 "register_operand" "=x")
1385         (vec_merge:V4SF
1386           (vec_duplicate:V4SF
1387             (match_operand:SF 2 "nonimmediate_operand" "xm"))
1388           (match_operand:V4SF 1 "register_operand" "0")
1389           (match_operand:SI 3 "const_pow2_1_to_8_operand" "n")))]
1390   "TARGET_SSE4_1"
1391 {
1392   operands[3] = GEN_INT (exact_log2 (INTVAL (operands[3])) << 4);
1393   return "insertps\t{%3, %2, %0|%0, %2, %3}";
1394 }
1395   [(set_attr "type" "sselog")
1396    (set_attr "prefix_extra" "1")
1397    (set_attr "mode" "V4SF")])
1398
1399 (define_insn "sse4_1_insertps"
1400   [(set (match_operand:V4SF 0 "register_operand" "=x")
1401         (unspec:V4SF [(match_operand:V4SF 2 "register_operand" "x")
1402                       (match_operand:V4SF 1 "register_operand" "0")
1403                       (match_operand:SI 3 "const_0_to_255_operand" "n")]
1404                      UNSPEC_INSERTPS))]
1405   "TARGET_SSE4_1"
1406   "insertps\t{%3, %2, %0|%0, %2, %3}";
1407   [(set_attr "type" "sselog")
1408    (set_attr "prefix_extra" "1")
1409    (set_attr "mode" "V4SF")])
1410
1411 (define_split
1412   [(set (match_operand:V4SF 0 "memory_operand" "")
1413         (vec_merge:V4SF
1414           (vec_duplicate:V4SF
1415             (match_operand:SF 1 "nonmemory_operand" ""))
1416           (match_dup 0)
1417           (const_int 1)))]
1418   "TARGET_SSE && reload_completed"
1419   [(const_int 0)]
1420 {
1421   emit_move_insn (adjust_address (operands[0], SFmode, 0), operands[1]);
1422   DONE;
1423 })
1424
1425 (define_expand "vec_setv4sf"
1426   [(match_operand:V4SF 0 "register_operand" "")
1427    (match_operand:SF 1 "register_operand" "")
1428    (match_operand 2 "const_int_operand" "")]
1429   "TARGET_SSE"
1430 {
1431   ix86_expand_vector_set (false, operands[0], operands[1],
1432                           INTVAL (operands[2]));
1433   DONE;
1434 })
1435
1436 (define_insn_and_split "*vec_extractv4sf_0"
1437   [(set (match_operand:SF 0 "nonimmediate_operand" "=x,m,fr")
1438         (vec_select:SF
1439           (match_operand:V4SF 1 "nonimmediate_operand" "xm,x,m")
1440           (parallel [(const_int 0)])))]
1441   "TARGET_SSE && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
1442   "#"
1443   "&& reload_completed"
1444   [(const_int 0)]
1445 {
1446   rtx op1 = operands[1];
1447   if (REG_P (op1))
1448     op1 = gen_rtx_REG (SFmode, REGNO (op1));
1449   else
1450     op1 = gen_lowpart (SFmode, op1);
1451   emit_move_insn (operands[0], op1);
1452   DONE;
1453 })
1454
1455 (define_insn "*sse4_1_extractps"
1456   [(set (match_operand:SF 0 "register_operand" "=rm")
1457         (vec_select:SF
1458           (match_operand:V4SF 1 "register_operand" "x")
1459           (parallel [(match_operand:SI 2 "const_0_to_3_operand" "n")])))]
1460   "TARGET_SSE4_1"
1461   "extractps\t{%2, %1, %0|%0, %1, %2}"
1462   [(set_attr "type" "sselog")
1463    (set_attr "prefix_extra" "1")
1464    (set_attr "mode" "V4SF")])
1465
1466 (define_expand "vec_extractv4sf"
1467   [(match_operand:SF 0 "register_operand" "")
1468    (match_operand:V4SF 1 "register_operand" "")
1469    (match_operand 2 "const_int_operand" "")]
1470   "TARGET_SSE"
1471 {
1472   ix86_expand_vector_extract (false, operands[0], operands[1],
1473                               INTVAL (operands[2]));
1474   DONE;
1475 })
1476
1477 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1478 ;;
1479 ;; Parallel double-precision floating point arithmetic
1480 ;;
1481 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1482
1483 (define_expand "negv2df2"
1484   [(set (match_operand:V2DF 0 "register_operand" "")
1485         (neg:V2DF (match_operand:V2DF 1 "nonimmediate_operand" "")))]
1486   "TARGET_SSE2"
1487   "ix86_expand_fp_absneg_operator (NEG, V2DFmode, operands); DONE;")
1488
1489 (define_expand "absv2df2"
1490   [(set (match_operand:V2DF 0 "register_operand" "")
1491         (abs:V2DF (match_operand:V2DF 1 "nonimmediate_operand" "")))]
1492   "TARGET_SSE2"
1493   "ix86_expand_fp_absneg_operator (ABS, V2DFmode, operands); DONE;")
1494
1495 (define_expand "addv2df3"
1496   [(set (match_operand:V2DF 0 "register_operand" "")
1497         (plus:V2DF (match_operand:V2DF 1 "nonimmediate_operand" "")
1498                    (match_operand:V2DF 2 "nonimmediate_operand" "")))]
1499   "TARGET_SSE2"
1500   "ix86_fixup_binary_operands_no_copy (PLUS, V2DFmode, operands);")
1501
1502 (define_insn "*addv2df3"
1503   [(set (match_operand:V2DF 0 "register_operand" "=x")
1504         (plus:V2DF (match_operand:V2DF 1 "nonimmediate_operand" "%0")
1505                    (match_operand:V2DF 2 "nonimmediate_operand" "xm")))]
1506   "TARGET_SSE2 && ix86_binary_operator_ok (PLUS, V2DFmode, operands)"
1507   "addpd\t{%2, %0|%0, %2}"
1508   [(set_attr "type" "sseadd")
1509    (set_attr "mode" "V2DF")])
1510
1511 (define_insn "sse2_vmaddv2df3"
1512   [(set (match_operand:V2DF 0 "register_operand" "=x")
1513         (vec_merge:V2DF
1514           (plus:V2DF (match_operand:V2DF 1 "register_operand" "0")
1515                      (match_operand:V2DF 2 "nonimmediate_operand" "xm"))
1516           (match_dup 1)
1517           (const_int 1)))]
1518   "TARGET_SSE2 && ix86_binary_operator_ok (PLUS, V4SFmode, operands)"
1519   "addsd\t{%2, %0|%0, %2}"
1520   [(set_attr "type" "sseadd")
1521    (set_attr "mode" "DF")])
1522
1523 (define_expand "subv2df3"
1524   [(set (match_operand:V2DF 0 "register_operand" "")
1525         (minus:V2DF (match_operand:V2DF 1 "nonimmediate_operand" "")
1526                     (match_operand:V2DF 2 "nonimmediate_operand" "")))]
1527   "TARGET_SSE2"
1528   "ix86_fixup_binary_operands_no_copy (MINUS, V2DFmode, operands);")
1529
1530 (define_insn "*subv2df3"
1531   [(set (match_operand:V2DF 0 "register_operand" "=x")
1532         (minus:V2DF (match_operand:V2DF 1 "register_operand" "0")
1533                     (match_operand:V2DF 2 "nonimmediate_operand" "xm")))]
1534   "TARGET_SSE2"
1535   "subpd\t{%2, %0|%0, %2}"
1536   [(set_attr "type" "sseadd")
1537    (set_attr "mode" "V2DF")])
1538
1539 (define_insn "sse2_vmsubv2df3"
1540   [(set (match_operand:V2DF 0 "register_operand" "=x")
1541         (vec_merge:V2DF
1542           (minus:V2DF (match_operand:V2DF 1 "register_operand" "0")
1543                       (match_operand:V2DF 2 "nonimmediate_operand" "xm"))
1544           (match_dup 1)
1545           (const_int 1)))]
1546   "TARGET_SSE2"
1547   "subsd\t{%2, %0|%0, %2}"
1548   [(set_attr "type" "sseadd")
1549    (set_attr "mode" "DF")])
1550
1551 (define_expand "mulv2df3"
1552   [(set (match_operand:V2DF 0 "register_operand" "")
1553         (mult:V2DF (match_operand:V2DF 1 "nonimmediate_operand" "")
1554                    (match_operand:V2DF 2 "nonimmediate_operand" "")))]
1555   "TARGET_SSE2"
1556   "ix86_fixup_binary_operands_no_copy (MULT, V2DFmode, operands);")
1557
1558 (define_insn "*mulv2df3"
1559   [(set (match_operand:V2DF 0 "register_operand" "=x")
1560         (mult:V2DF (match_operand:V2DF 1 "nonimmediate_operand" "%0")
1561                    (match_operand:V2DF 2 "nonimmediate_operand" "xm")))]
1562   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, V2DFmode, operands)"
1563   "mulpd\t{%2, %0|%0, %2}"
1564   [(set_attr "type" "ssemul")
1565    (set_attr "mode" "V2DF")])
1566
1567 (define_insn "sse2_vmmulv2df3"
1568   [(set (match_operand:V2DF 0 "register_operand" "=x")
1569         (vec_merge:V2DF
1570           (mult:V2DF (match_operand:V2DF 1 "register_operand" "0")
1571                      (match_operand:V2DF 2 "nonimmediate_operand" "xm"))
1572           (match_dup 1)
1573           (const_int 1)))]
1574   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, V2DFmode, operands)"
1575   "mulsd\t{%2, %0|%0, %2}"
1576   [(set_attr "type" "ssemul")
1577    (set_attr "mode" "DF")])
1578
1579 (define_expand "divv2df3"
1580   [(set (match_operand:V2DF 0 "register_operand" "")
1581         (div:V2DF (match_operand:V2DF 1 "register_operand" "")
1582                   (match_operand:V2DF 2 "nonimmediate_operand" "")))]
1583   "TARGET_SSE2"
1584   "ix86_fixup_binary_operands_no_copy (DIV, V2DFmode, operands);")
1585
1586 (define_insn "*divv2df3"
1587   [(set (match_operand:V2DF 0 "register_operand" "=x")
1588         (div:V2DF (match_operand:V2DF 1 "register_operand" "0")
1589                   (match_operand:V2DF 2 "nonimmediate_operand" "xm")))]
1590   "TARGET_SSE2"
1591   "divpd\t{%2, %0|%0, %2}"
1592   [(set_attr "type" "ssediv")
1593    (set_attr "mode" "V2DF")])
1594
1595 (define_insn "sse2_vmdivv2df3"
1596   [(set (match_operand:V2DF 0 "register_operand" "=x")
1597         (vec_merge:V2DF
1598           (div:V2DF (match_operand:V2DF 1 "register_operand" "0")
1599                     (match_operand:V2DF 2 "nonimmediate_operand" "xm"))
1600           (match_dup 1)
1601           (const_int 1)))]
1602   "TARGET_SSE2"
1603   "divsd\t{%2, %0|%0, %2}"
1604   [(set_attr "type" "ssediv")
1605    (set_attr "mode" "DF")])
1606
1607 (define_insn "sqrtv2df2"
1608   [(set (match_operand:V2DF 0 "register_operand" "=x")
1609         (sqrt:V2DF (match_operand:V2DF 1 "nonimmediate_operand" "xm")))]
1610   "TARGET_SSE2"
1611   "sqrtpd\t{%1, %0|%0, %1}"
1612   [(set_attr "type" "sse")
1613    (set_attr "mode" "V2DF")])
1614
1615 (define_insn "sse2_vmsqrtv2df2"
1616   [(set (match_operand:V2DF 0 "register_operand" "=x")
1617         (vec_merge:V2DF
1618           (sqrt:V2DF (match_operand:V2DF 1 "register_operand" "xm"))
1619           (match_operand:V2DF 2 "register_operand" "0")
1620           (const_int 1)))]
1621   "TARGET_SSE2"
1622   "sqrtsd\t{%1, %0|%0, %1}"
1623   [(set_attr "type" "sse")
1624    (set_attr "mode" "DF")])
1625
1626 ;; ??? For !flag_finite_math_only, the representation with SMIN/SMAX
1627 ;; isn't really correct, as those rtl operators aren't defined when 
1628 ;; applied to NaNs.  Hopefully the optimizers won't get too smart on us.
1629
1630 (define_expand "smaxv2df3"
1631   [(set (match_operand:V2DF 0 "register_operand" "")
1632         (smax:V2DF (match_operand:V2DF 1 "nonimmediate_operand" "")
1633                    (match_operand:V2DF 2 "nonimmediate_operand" "")))]
1634   "TARGET_SSE2"
1635 {
1636   if (!flag_finite_math_only)
1637     operands[1] = force_reg (V2DFmode, operands[1]);
1638   ix86_fixup_binary_operands_no_copy (SMAX, V2DFmode, operands);
1639 })
1640
1641 (define_insn "*smaxv2df3_finite"
1642   [(set (match_operand:V2DF 0 "register_operand" "=x")
1643         (smax:V2DF (match_operand:V2DF 1 "nonimmediate_operand" "%0")
1644                    (match_operand:V2DF 2 "nonimmediate_operand" "xm")))]
1645   "TARGET_SSE2 && flag_finite_math_only
1646    && ix86_binary_operator_ok (SMAX, V2DFmode, operands)"
1647   "maxpd\t{%2, %0|%0, %2}"
1648   [(set_attr "type" "sseadd")
1649    (set_attr "mode" "V2DF")])
1650
1651 (define_insn "*smaxv2df3"
1652   [(set (match_operand:V2DF 0 "register_operand" "=x")
1653         (smax:V2DF (match_operand:V2DF 1 "register_operand" "0")
1654                    (match_operand:V2DF 2 "nonimmediate_operand" "xm")))]
1655   "TARGET_SSE2"
1656   "maxpd\t{%2, %0|%0, %2}"
1657   [(set_attr "type" "sseadd")
1658    (set_attr "mode" "V2DF")])
1659
1660 (define_insn "sse2_vmsmaxv2df3"
1661   [(set (match_operand:V2DF 0 "register_operand" "=x")
1662         (vec_merge:V2DF
1663           (smax:V2DF (match_operand:V2DF 1 "register_operand" "0")
1664                      (match_operand:V2DF 2 "nonimmediate_operand" "xm"))
1665           (match_dup 1)
1666           (const_int 1)))]
1667   "TARGET_SSE2"
1668   "maxsd\t{%2, %0|%0, %2}"
1669   [(set_attr "type" "sseadd")
1670    (set_attr "mode" "DF")])
1671
1672 (define_expand "sminv2df3"
1673   [(set (match_operand:V2DF 0 "register_operand" "")
1674         (smin:V2DF (match_operand:V2DF 1 "nonimmediate_operand" "")
1675                    (match_operand:V2DF 2 "nonimmediate_operand" "")))]
1676   "TARGET_SSE2"
1677 {
1678   if (!flag_finite_math_only)
1679     operands[1] = force_reg (V2DFmode, operands[1]);
1680   ix86_fixup_binary_operands_no_copy (SMIN, V2DFmode, operands);
1681 })
1682
1683 (define_insn "*sminv2df3_finite"
1684   [(set (match_operand:V2DF 0 "register_operand" "=x")
1685         (smin:V2DF (match_operand:V2DF 1 "nonimmediate_operand" "%0")
1686                    (match_operand:V2DF 2 "nonimmediate_operand" "xm")))]
1687   "TARGET_SSE2 && flag_finite_math_only
1688    && ix86_binary_operator_ok (SMIN, V2DFmode, operands)"
1689   "minpd\t{%2, %0|%0, %2}"
1690   [(set_attr "type" "sseadd")
1691    (set_attr "mode" "V2DF")])
1692
1693 (define_insn "*sminv2df3"
1694   [(set (match_operand:V2DF 0 "register_operand" "=x")
1695         (smin:V2DF (match_operand:V2DF 1 "register_operand" "0")
1696                    (match_operand:V2DF 2 "nonimmediate_operand" "xm")))]
1697   "TARGET_SSE2"
1698   "minpd\t{%2, %0|%0, %2}"
1699   [(set_attr "type" "sseadd")
1700    (set_attr "mode" "V2DF")])
1701
1702 (define_insn "sse2_vmsminv2df3"
1703   [(set (match_operand:V2DF 0 "register_operand" "=x")
1704         (vec_merge:V2DF
1705           (smin:V2DF (match_operand:V2DF 1 "register_operand" "0")
1706                      (match_operand:V2DF 2 "nonimmediate_operand" "xm"))
1707           (match_dup 1)
1708           (const_int 1)))]
1709   "TARGET_SSE2"
1710   "minsd\t{%2, %0|%0, %2}"
1711   [(set_attr "type" "sseadd")
1712    (set_attr "mode" "DF")])
1713
1714 (define_insn "sse3_addsubv2df3"
1715   [(set (match_operand:V2DF 0 "register_operand" "=x")
1716         (vec_merge:V2DF
1717           (plus:V2DF
1718             (match_operand:V2DF 1 "register_operand" "0")
1719             (match_operand:V2DF 2 "nonimmediate_operand" "xm"))
1720           (minus:V2DF (match_dup 1) (match_dup 2))
1721           (const_int 1)))]
1722   "TARGET_SSE3"
1723   "addsubpd\t{%2, %0|%0, %2}"
1724   [(set_attr "type" "sseadd")
1725    (set_attr "mode" "V2DF")])
1726
1727 (define_insn "sse3_haddv2df3"
1728   [(set (match_operand:V2DF 0 "register_operand" "=x")
1729         (vec_concat:V2DF
1730           (plus:DF
1731             (vec_select:DF
1732               (match_operand:V2DF 1 "register_operand" "0")
1733               (parallel [(const_int 0)]))
1734             (vec_select:DF (match_dup 1) (parallel [(const_int 1)])))
1735           (plus:DF
1736             (vec_select:DF
1737               (match_operand:V2DF 2 "nonimmediate_operand" "xm")
1738               (parallel [(const_int 0)]))
1739             (vec_select:DF (match_dup 2) (parallel [(const_int 1)])))))]
1740   "TARGET_SSE3"
1741   "haddpd\t{%2, %0|%0, %2}"
1742   [(set_attr "type" "sseadd")
1743    (set_attr "mode" "V2DF")])
1744
1745 (define_insn "sse3_hsubv2df3"
1746   [(set (match_operand:V2DF 0 "register_operand" "=x")
1747         (vec_concat:V2DF
1748           (minus:DF
1749             (vec_select:DF
1750               (match_operand:V2DF 1 "register_operand" "0")
1751               (parallel [(const_int 0)]))
1752             (vec_select:DF (match_dup 1) (parallel [(const_int 1)])))
1753           (minus:DF
1754             (vec_select:DF
1755               (match_operand:V2DF 2 "nonimmediate_operand" "xm")
1756               (parallel [(const_int 0)]))
1757             (vec_select:DF (match_dup 2) (parallel [(const_int 1)])))))]
1758   "TARGET_SSE3"
1759   "hsubpd\t{%2, %0|%0, %2}"
1760   [(set_attr "type" "sseadd")
1761    (set_attr "mode" "V2DF")])
1762
1763 (define_expand "reduc_splus_v2df"
1764   [(match_operand:V2DF 0 "register_operand" "")
1765    (match_operand:V2DF 1 "register_operand" "")]
1766   "TARGET_SSE3"
1767 {
1768   emit_insn (gen_sse3_haddv2df3 (operands[0], operands[1], operands[1]));
1769   DONE;
1770 })
1771
1772 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1773 ;;
1774 ;; Parallel double-precision floating point comparisons
1775 ;;
1776 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1777
1778 (define_insn "sse2_maskcmpv2df3"
1779   [(set (match_operand:V2DF 0 "register_operand" "=x")
1780         (match_operator:V2DF 3 "sse_comparison_operator"
1781                 [(match_operand:V2DF 1 "register_operand" "0")
1782                  (match_operand:V2DF 2 "nonimmediate_operand" "xm")]))]
1783   "TARGET_SSE2"
1784   "cmp%D3pd\t{%2, %0|%0, %2}"
1785   [(set_attr "type" "ssecmp")
1786    (set_attr "mode" "V2DF")])
1787
1788 (define_insn "sse2_maskcmpdf3"
1789   [(set (match_operand:DF 0 "register_operand" "=x")
1790         (match_operator:DF 3 "sse_comparison_operator"
1791                 [(match_operand:DF 1 "register_operand" "0")
1792                  (match_operand:DF 2 "nonimmediate_operand" "xm")]))]
1793   "TARGET_SSE2"
1794   "cmp%D3sd\t{%2, %0|%0, %2}"
1795   [(set_attr "type" "ssecmp")
1796    (set_attr "mode" "DF")])
1797
1798 (define_insn "sse2_vmmaskcmpv2df3"
1799   [(set (match_operand:V2DF 0 "register_operand" "=x")
1800         (vec_merge:V2DF
1801           (match_operator:V2DF 3 "sse_comparison_operator"
1802                 [(match_operand:V2DF 1 "register_operand" "0")
1803                  (match_operand:V2DF 2 "nonimmediate_operand" "xm")])
1804           (match_dup 1)
1805           (const_int 1)))]
1806   "TARGET_SSE2"
1807   "cmp%D3sd\t{%2, %0|%0, %2}"
1808   [(set_attr "type" "ssecmp")
1809    (set_attr "mode" "DF")])
1810
1811 (define_insn "sse2_comi"
1812   [(set (reg:CCFP FLAGS_REG)
1813         (compare:CCFP
1814           (vec_select:DF
1815             (match_operand:V2DF 0 "register_operand" "x")
1816             (parallel [(const_int 0)]))
1817           (vec_select:DF
1818             (match_operand:V2DF 1 "nonimmediate_operand" "xm")
1819             (parallel [(const_int 0)]))))]
1820   "TARGET_SSE2"
1821   "comisd\t{%1, %0|%0, %1}"
1822   [(set_attr "type" "ssecomi")
1823    (set_attr "mode" "DF")])
1824
1825 (define_insn "sse2_ucomi"
1826   [(set (reg:CCFPU FLAGS_REG)
1827         (compare:CCFPU
1828           (vec_select:DF
1829             (match_operand:V2DF 0 "register_operand" "x")
1830             (parallel [(const_int 0)]))
1831           (vec_select:DF
1832             (match_operand:V2DF 1 "nonimmediate_operand" "xm")
1833             (parallel [(const_int 0)]))))]
1834   "TARGET_SSE2"
1835   "ucomisd\t{%1, %0|%0, %1}"
1836   [(set_attr "type" "ssecomi")
1837    (set_attr "mode" "DF")])
1838
1839 (define_expand "vcondv2df"
1840   [(set (match_operand:V2DF 0 "register_operand" "")
1841         (if_then_else:V2DF
1842           (match_operator 3 ""
1843             [(match_operand:V2DF 4 "nonimmediate_operand" "")
1844              (match_operand:V2DF 5 "nonimmediate_operand" "")])
1845           (match_operand:V2DF 1 "general_operand" "")
1846           (match_operand:V2DF 2 "general_operand" "")))]
1847   "TARGET_SSE2"
1848 {
1849   if (ix86_expand_fp_vcond (operands))
1850     DONE;
1851   else
1852     FAIL;
1853 })
1854
1855 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1856 ;;
1857 ;; Parallel double-precision floating point logical operations
1858 ;;
1859 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1860
1861 (define_expand "andv2df3"
1862   [(set (match_operand:V2DF 0 "register_operand" "")
1863         (and:V2DF (match_operand:V2DF 1 "nonimmediate_operand" "")
1864                   (match_operand:V2DF 2 "nonimmediate_operand" "")))]
1865   "TARGET_SSE2"
1866   "ix86_fixup_binary_operands_no_copy (AND, V2DFmode, operands);")
1867
1868 (define_insn "*andv2df3"
1869   [(set (match_operand:V2DF 0 "register_operand" "=x")
1870         (and:V2DF (match_operand:V2DF 1 "nonimmediate_operand" "%0")
1871                   (match_operand:V2DF 2 "nonimmediate_operand" "xm")))]
1872   "TARGET_SSE2 && ix86_binary_operator_ok (AND, V2DFmode, operands)"
1873   "andpd\t{%2, %0|%0, %2}"
1874   [(set_attr "type" "sselog")
1875    (set_attr "mode" "V2DF")])
1876
1877 (define_insn "sse2_nandv2df3"
1878   [(set (match_operand:V2DF 0 "register_operand" "=x")
1879         (and:V2DF (not:V2DF (match_operand:V2DF 1 "register_operand" "0"))
1880                   (match_operand:V2DF 2 "nonimmediate_operand" "xm")))]
1881   "TARGET_SSE2"
1882   "andnpd\t{%2, %0|%0, %2}"
1883   [(set_attr "type" "sselog")
1884    (set_attr "mode" "V2DF")])
1885
1886 (define_expand "iorv2df3"
1887   [(set (match_operand:V2DF 0 "register_operand" "")
1888         (ior:V2DF (match_operand:V2DF 1 "nonimmediate_operand" "")
1889                   (match_operand:V2DF 2 "nonimmediate_operand" "")))]
1890   "TARGET_SSE2"
1891   "ix86_fixup_binary_operands_no_copy (IOR, V2DFmode, operands);")
1892
1893 (define_insn "*iorv2df3"
1894   [(set (match_operand:V2DF 0 "register_operand" "=x")
1895         (ior:V2DF (match_operand:V2DF 1 "nonimmediate_operand" "%0")
1896                   (match_operand:V2DF 2 "nonimmediate_operand" "xm")))]
1897   "TARGET_SSE2 && ix86_binary_operator_ok (IOR, V2DFmode, operands)"
1898   "orpd\t{%2, %0|%0, %2}"
1899   [(set_attr "type" "sselog")
1900    (set_attr "mode" "V2DF")])
1901
1902 (define_expand "xorv2df3"
1903   [(set (match_operand:V2DF 0 "register_operand" "")
1904         (xor:V2DF (match_operand:V2DF 1 "nonimmediate_operand" "")
1905                   (match_operand:V2DF 2 "nonimmediate_operand" "")))]
1906   "TARGET_SSE2"
1907   "ix86_fixup_binary_operands_no_copy (XOR, V2DFmode, operands);")
1908
1909 (define_insn "*xorv2df3"
1910   [(set (match_operand:V2DF 0 "register_operand" "=x")
1911         (xor:V2DF (match_operand:V2DF 1 "nonimmediate_operand" "%0")
1912                   (match_operand:V2DF 2 "nonimmediate_operand" "xm")))]
1913   "TARGET_SSE2 && ix86_binary_operator_ok (XOR, V2DFmode, operands)"
1914   "xorpd\t{%2, %0|%0, %2}"
1915   [(set_attr "type" "sselog")
1916    (set_attr "mode" "V2DF")])
1917
1918 ;; Also define scalar versions.  These are used for abs, neg, and
1919 ;; conditional move.  Using subregs into vector modes causes register
1920 ;; allocation lossage.  These patterns do not allow memory operands
1921 ;; because the native instructions read the full 128-bits.
1922
1923 (define_insn "*anddf3"
1924   [(set (match_operand:DF 0 "register_operand" "=x")
1925         (and:DF (match_operand:DF 1 "register_operand" "0")
1926                 (match_operand:DF 2 "register_operand" "x")))]
1927   "TARGET_SSE2"
1928   "andpd\t{%2, %0|%0, %2}"
1929   [(set_attr "type" "sselog")
1930    (set_attr "mode" "V2DF")])
1931
1932 (define_insn "*nanddf3"
1933   [(set (match_operand:DF 0 "register_operand" "=x")
1934         (and:DF (not:DF (match_operand:DF 1 "register_operand" "0"))
1935                 (match_operand:DF 2 "register_operand" "x")))]
1936   "TARGET_SSE2"
1937   "andnpd\t{%2, %0|%0, %2}"
1938   [(set_attr "type" "sselog")
1939    (set_attr "mode" "V2DF")])
1940
1941 (define_insn "*iordf3"
1942   [(set (match_operand:DF 0 "register_operand" "=x")
1943         (ior:DF (match_operand:DF 1 "register_operand" "0")
1944                 (match_operand:DF 2 "register_operand" "x")))]
1945   "TARGET_SSE2"
1946   "orpd\t{%2, %0|%0, %2}"
1947   [(set_attr "type" "sselog")
1948    (set_attr "mode" "V2DF")])
1949
1950 (define_insn "*xordf3"
1951   [(set (match_operand:DF 0 "register_operand" "=x")
1952         (xor:DF (match_operand:DF 1 "register_operand" "0")
1953                 (match_operand:DF 2 "register_operand" "x")))]
1954   "TARGET_SSE2"
1955   "xorpd\t{%2, %0|%0, %2}"
1956   [(set_attr "type" "sselog")
1957    (set_attr "mode" "V2DF")])
1958
1959 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1960 ;;
1961 ;; Parallel double-precision floating point conversion operations
1962 ;;
1963 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1964
1965 (define_insn "sse2_cvtpi2pd"
1966   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
1967         (float:V2DF (match_operand:V2SI 1 "nonimmediate_operand" "y,m")))]
1968   "TARGET_SSE2"
1969   "cvtpi2pd\t{%1, %0|%0, %1}"
1970   [(set_attr "type" "ssecvt")
1971    (set_attr "unit" "mmx,*")
1972    (set_attr "mode" "V2DF")])
1973
1974 (define_insn "sse2_cvtpd2pi"
1975   [(set (match_operand:V2SI 0 "register_operand" "=y")
1976         (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand" "xm")]
1977                      UNSPEC_FIX_NOTRUNC))]
1978   "TARGET_SSE2"
1979   "cvtpd2pi\t{%1, %0|%0, %1}"
1980   [(set_attr "type" "ssecvt")
1981    (set_attr "unit" "mmx")
1982    (set_attr "prefix_data16" "1")
1983    (set_attr "mode" "DI")])
1984
1985 (define_insn "sse2_cvttpd2pi"
1986   [(set (match_operand:V2SI 0 "register_operand" "=y")
1987         (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" "xm")))]
1988   "TARGET_SSE2"
1989   "cvttpd2pi\t{%1, %0|%0, %1}"
1990   [(set_attr "type" "ssecvt")
1991    (set_attr "unit" "mmx")
1992    (set_attr "prefix_data16" "1")
1993    (set_attr "mode" "TI")])
1994
1995 (define_insn "sse2_cvtsi2sd"
1996   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
1997         (vec_merge:V2DF
1998           (vec_duplicate:V2DF
1999             (float:DF (match_operand:SI 2 "nonimmediate_operand" "r,m")))
2000           (match_operand:V2DF 1 "register_operand" "0,0")
2001           (const_int 1)))]
2002   "TARGET_SSE2"
2003   "cvtsi2sd\t{%2, %0|%0, %2}"
2004   [(set_attr "type" "sseicvt")
2005    (set_attr "mode" "DF")
2006    (set_attr "athlon_decode" "double,direct")
2007    (set_attr "amdfam10_decode" "vector,double")])
2008
2009 (define_insn "sse2_cvtsi2sdq"
2010   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
2011         (vec_merge:V2DF
2012           (vec_duplicate:V2DF
2013             (float:DF (match_operand:DI 2 "nonimmediate_operand" "r,m")))
2014           (match_operand:V2DF 1 "register_operand" "0,0")
2015           (const_int 1)))]
2016   "TARGET_SSE2 && TARGET_64BIT"
2017   "cvtsi2sdq\t{%2, %0|%0, %2}"
2018   [(set_attr "type" "sseicvt")
2019    (set_attr "mode" "DF")
2020    (set_attr "athlon_decode" "double,direct")
2021    (set_attr "amdfam10_decode" "vector,double")])
2022
2023 (define_insn "sse2_cvtsd2si"
2024   [(set (match_operand:SI 0 "register_operand" "=r,r")
2025         (unspec:SI
2026           [(vec_select:DF
2027              (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2028              (parallel [(const_int 0)]))]
2029           UNSPEC_FIX_NOTRUNC))]
2030   "TARGET_SSE2"
2031   "cvtsd2si\t{%1, %0|%0, %1}"
2032   [(set_attr "type" "sseicvt")
2033    (set_attr "athlon_decode" "double,vector")
2034    (set_attr "prefix_rep" "1")
2035    (set_attr "mode" "SI")])
2036
2037 (define_insn "sse2_cvtsd2si_2"
2038   [(set (match_operand:SI 0 "register_operand" "=r,r")
2039         (unspec:SI [(match_operand:DF 1 "nonimmediate_operand" "x,m")]
2040          UNSPEC_FIX_NOTRUNC))]
2041   "TARGET_SSE2"
2042   "cvtsd2si\t{%1, %0|%0, %1}"
2043   [(set_attr "type" "sseicvt")
2044    (set_attr "athlon_decode" "double,vector")
2045    (set_attr "amdfam10_decode" "double,double")
2046    (set_attr "prefix_rep" "1")
2047    (set_attr "mode" "SI")])
2048
2049 (define_insn "sse2_cvtsd2siq"
2050   [(set (match_operand:DI 0 "register_operand" "=r,r")
2051         (unspec:DI
2052           [(vec_select:DF
2053              (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2054              (parallel [(const_int 0)]))]
2055           UNSPEC_FIX_NOTRUNC))]
2056   "TARGET_SSE2 && TARGET_64BIT"
2057   "cvtsd2siq\t{%1, %0|%0, %1}"
2058   [(set_attr "type" "sseicvt")
2059    (set_attr "athlon_decode" "double,vector")
2060    (set_attr "prefix_rep" "1")
2061    (set_attr "mode" "DI")])
2062
2063 (define_insn "sse2_cvtsd2siq_2"
2064   [(set (match_operand:DI 0 "register_operand" "=r,r")
2065         (unspec:DI [(match_operand:DF 1 "nonimmediate_operand" "x,m")]
2066          UNSPEC_FIX_NOTRUNC))]
2067   "TARGET_SSE2 && TARGET_64BIT"
2068   "cvtsd2siq\t{%1, %0|%0, %1}"
2069   [(set_attr "type" "sseicvt")
2070    (set_attr "athlon_decode" "double,vector")
2071    (set_attr "amdfam10_decode" "double,double")
2072    (set_attr "prefix_rep" "1")
2073    (set_attr "mode" "DI")])
2074
2075 (define_insn "sse2_cvttsd2si"
2076   [(set (match_operand:SI 0 "register_operand" "=r,r")
2077         (fix:SI
2078           (vec_select:DF
2079             (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2080             (parallel [(const_int 0)]))))]
2081   "TARGET_SSE2"
2082   "cvttsd2si\t{%1, %0|%0, %1}"
2083   [(set_attr "type" "sseicvt")
2084    (set_attr "prefix_rep" "1")
2085    (set_attr "mode" "SI")
2086    (set_attr "athlon_decode" "double,vector")
2087    (set_attr "amdfam10_decode" "double,double")])
2088
2089 (define_insn "sse2_cvttsd2siq"
2090   [(set (match_operand:DI 0 "register_operand" "=r,r")
2091         (fix:DI
2092           (vec_select:DF
2093             (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2094             (parallel [(const_int 0)]))))]
2095   "TARGET_SSE2 && TARGET_64BIT"
2096   "cvttsd2siq\t{%1, %0|%0, %1}"
2097   [(set_attr "type" "sseicvt")
2098    (set_attr "prefix_rep" "1")
2099    (set_attr "mode" "DI")
2100    (set_attr "athlon_decode" "double,vector")
2101    (set_attr "amdfam10_decode" "double,double")])
2102
2103 (define_insn "sse2_cvtdq2pd"
2104   [(set (match_operand:V2DF 0 "register_operand" "=x")
2105         (float:V2DF
2106           (vec_select:V2SI
2107             (match_operand:V4SI 1 "nonimmediate_operand" "xm")
2108             (parallel [(const_int 0) (const_int 1)]))))]
2109   "TARGET_SSE2"
2110   "cvtdq2pd\t{%1, %0|%0, %1}"
2111   [(set_attr "type" "ssecvt")
2112    (set_attr "mode" "V2DF")])
2113
2114 (define_expand "sse2_cvtpd2dq"
2115   [(set (match_operand:V4SI 0 "register_operand" "")
2116         (vec_concat:V4SI
2117           (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand" "")]
2118                        UNSPEC_FIX_NOTRUNC)
2119           (match_dup 2)))]
2120   "TARGET_SSE2"
2121   "operands[2] = CONST0_RTX (V2SImode);")
2122
2123 (define_insn "*sse2_cvtpd2dq"
2124   [(set (match_operand:V4SI 0 "register_operand" "=x")
2125         (vec_concat:V4SI
2126           (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand" "xm")]
2127                        UNSPEC_FIX_NOTRUNC)
2128           (match_operand:V2SI 2 "const0_operand" "")))]
2129   "TARGET_SSE2"
2130   "cvtpd2dq\t{%1, %0|%0, %1}"
2131   [(set_attr "type" "ssecvt")
2132    (set_attr "prefix_rep" "1")
2133    (set_attr "mode" "TI")
2134    (set_attr "amdfam10_decode" "double")])
2135
2136 (define_expand "sse2_cvttpd2dq"
2137   [(set (match_operand:V4SI 0 "register_operand" "")
2138         (vec_concat:V4SI
2139           (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" ""))
2140           (match_dup 2)))]
2141   "TARGET_SSE2"
2142   "operands[2] = CONST0_RTX (V2SImode);")
2143
2144 (define_insn "*sse2_cvttpd2dq"
2145   [(set (match_operand:V4SI 0 "register_operand" "=x")
2146         (vec_concat:V4SI
2147           (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" "xm"))
2148           (match_operand:V2SI 2 "const0_operand" "")))]
2149   "TARGET_SSE2"
2150   "cvttpd2dq\t{%1, %0|%0, %1}"
2151   [(set_attr "type" "ssecvt")
2152    (set_attr "prefix_rep" "1")
2153    (set_attr "mode" "TI")
2154    (set_attr "amdfam10_decode" "double")])
2155
2156 (define_insn "sse2_cvtsd2ss"
2157   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
2158         (vec_merge:V4SF
2159           (vec_duplicate:V4SF
2160             (float_truncate:V2SF
2161               (match_operand:V2DF 2 "nonimmediate_operand" "x,m")))
2162           (match_operand:V4SF 1 "register_operand" "0,0")
2163           (const_int 1)))]
2164   "TARGET_SSE2"
2165   "cvtsd2ss\t{%2, %0|%0, %2}"
2166   [(set_attr "type" "ssecvt")
2167    (set_attr "athlon_decode" "vector,double")
2168    (set_attr "amdfam10_decode" "vector,double")
2169    (set_attr "mode" "SF")])
2170
2171 (define_insn "sse2_cvtss2sd"
2172   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
2173         (vec_merge:V2DF
2174           (float_extend:V2DF
2175             (vec_select:V2SF
2176               (match_operand:V4SF 2 "nonimmediate_operand" "x,m")
2177               (parallel [(const_int 0) (const_int 1)])))
2178           (match_operand:V2DF 1 "register_operand" "0,0")
2179           (const_int 1)))]
2180   "TARGET_SSE2"
2181   "cvtss2sd\t{%2, %0|%0, %2}"
2182   [(set_attr "type" "ssecvt")
2183    (set_attr "amdfam10_decode" "vector,double")
2184    (set_attr "mode" "DF")])
2185
2186 (define_expand "sse2_cvtpd2ps"
2187   [(set (match_operand:V4SF 0 "register_operand" "")
2188         (vec_concat:V4SF
2189           (float_truncate:V2SF
2190             (match_operand:V2DF 1 "nonimmediate_operand" "xm"))
2191           (match_dup 2)))]
2192   "TARGET_SSE2"
2193   "operands[2] = CONST0_RTX (V2SFmode);")
2194
2195 (define_insn "*sse2_cvtpd2ps"
2196   [(set (match_operand:V4SF 0 "register_operand" "=x")
2197         (vec_concat:V4SF
2198           (float_truncate:V2SF
2199             (match_operand:V2DF 1 "nonimmediate_operand" "xm"))
2200           (match_operand:V2SF 2 "const0_operand" "")))]
2201   "TARGET_SSE2"
2202   "cvtpd2ps\t{%1, %0|%0, %1}"
2203   [(set_attr "type" "ssecvt")
2204    (set_attr "prefix_data16" "1")
2205    (set_attr "mode" "V4SF")
2206    (set_attr "amdfam10_decode" "double")])
2207
2208 (define_insn "sse2_cvtps2pd"
2209   [(set (match_operand:V2DF 0 "register_operand" "=x")
2210         (float_extend:V2DF
2211           (vec_select:V2SF
2212             (match_operand:V4SF 1 "nonimmediate_operand" "xm")
2213             (parallel [(const_int 0) (const_int 1)]))))]
2214   "TARGET_SSE2"
2215   "cvtps2pd\t{%1, %0|%0, %1}"
2216   [(set_attr "type" "ssecvt")
2217    (set_attr "mode" "V2DF")
2218    (set_attr "amdfam10_decode" "direct")])
2219
2220 (define_expand "vec_unpacks_hi_v4sf"
2221   [(set (match_dup 2)
2222    (vec_select:V4SF
2223      (vec_concat:V8SF
2224        (match_dup 2)
2225        (match_operand:V4SF 1 "nonimmediate_operand" ""))
2226      (parallel [(const_int 6)
2227                 (const_int 7)
2228                 (const_int 2)
2229                 (const_int 3)])))
2230   (set (match_operand:V2DF 0 "register_operand" "")
2231    (float_extend:V2DF
2232      (vec_select:V2SF
2233        (match_dup 2)
2234        (parallel [(const_int 0) (const_int 1)]))))]
2235  "TARGET_SSE2"
2236 {
2237  operands[2] = gen_reg_rtx (V4SFmode);
2238 })
2239
2240 (define_expand "vec_unpacks_lo_v4sf"
2241   [(set (match_operand:V2DF 0 "register_operand" "")
2242         (float_extend:V2DF
2243           (vec_select:V2SF
2244             (match_operand:V4SF 1 "nonimmediate_operand" "")
2245             (parallel [(const_int 0) (const_int 1)]))))]
2246   "TARGET_SSE2")
2247
2248 (define_expand "vec_unpacks_float_hi_v8hi"
2249   [(match_operand:V4SF 0 "register_operand" "")
2250    (match_operand:V8HI 1 "register_operand" "")]
2251   "TARGET_SSE2"
2252 {
2253   rtx tmp = gen_reg_rtx (V4SImode);
2254
2255   emit_insn (gen_vec_unpacks_hi_v8hi (tmp, operands[1]));
2256   emit_insn (gen_sse2_cvtdq2ps (operands[0], tmp));
2257   DONE;
2258 })
2259
2260 (define_expand "vec_unpacks_float_lo_v8hi"
2261   [(match_operand:V4SF 0 "register_operand" "")
2262    (match_operand:V8HI 1 "register_operand" "")]
2263   "TARGET_SSE2"
2264 {
2265   rtx tmp = gen_reg_rtx (V4SImode);
2266
2267   emit_insn (gen_vec_unpacks_lo_v8hi (tmp, operands[1]));
2268   emit_insn (gen_sse2_cvtdq2ps (operands[0], tmp));
2269   DONE;
2270 })
2271
2272 (define_expand "vec_unpacku_float_hi_v8hi"
2273   [(match_operand:V4SF 0 "register_operand" "")
2274    (match_operand:V8HI 1 "register_operand" "")]
2275   "TARGET_SSE2"
2276 {
2277   rtx tmp = gen_reg_rtx (V4SImode);
2278
2279   emit_insn (gen_vec_unpacku_hi_v8hi (tmp, operands[1]));
2280   emit_insn (gen_sse2_cvtdq2ps (operands[0], tmp));
2281   DONE;
2282 })
2283
2284 (define_expand "vec_unpacku_float_lo_v8hi"
2285   [(match_operand:V4SF 0 "register_operand" "")
2286    (match_operand:V8HI 1 "register_operand" "")]
2287   "TARGET_SSE2"
2288 {
2289   rtx tmp = gen_reg_rtx (V4SImode);
2290
2291   emit_insn (gen_vec_unpacku_lo_v8hi (tmp, operands[1]));
2292   emit_insn (gen_sse2_cvtdq2ps (operands[0], tmp));
2293   DONE;
2294 })
2295
2296 (define_expand "vec_unpacks_float_hi_v4si"
2297   [(set (match_dup 2)
2298         (vec_select:V4SI
2299           (match_operand:V4SI 1 "nonimmediate_operand" "")
2300           (parallel [(const_int 2)
2301                      (const_int 3)
2302                      (const_int 2)
2303                      (const_int 3)])))
2304    (set (match_operand:V2DF 0 "register_operand" "")
2305         (float:V2DF
2306           (vec_select:V2SI
2307           (match_dup 2)
2308             (parallel [(const_int 0) (const_int 1)]))))]
2309  "TARGET_SSE2"
2310 {
2311  operands[2] = gen_reg_rtx (V4SImode);
2312 })
2313
2314 (define_expand "vec_unpacks_float_lo_v4si"
2315   [(set (match_operand:V2DF 0 "register_operand" "")
2316         (float:V2DF
2317           (vec_select:V2SI
2318             (match_operand:V4SI 1 "nonimmediate_operand" "")
2319             (parallel [(const_int 0) (const_int 1)]))))]
2320   "TARGET_SSE2")
2321
2322 (define_expand "vec_pack_trunc_v2df"
2323   [(match_operand:V4SF 0 "register_operand" "")
2324    (match_operand:V2DF 1 "nonimmediate_operand" "")
2325    (match_operand:V2DF 2 "nonimmediate_operand" "")]
2326   "TARGET_SSE2"
2327 {
2328   rtx r1, r2;
2329
2330   r1 = gen_reg_rtx (V4SFmode);
2331   r2 = gen_reg_rtx (V4SFmode);
2332
2333   emit_insn (gen_sse2_cvtpd2ps (r1, operands[1]));
2334   emit_insn (gen_sse2_cvtpd2ps (r2, operands[2]));
2335   emit_insn (gen_sse_movlhps (operands[0], r1, r2));
2336   DONE;
2337 })
2338
2339 (define_expand "vec_pack_sfix_trunc_v2df"
2340   [(match_operand:V4SI 0 "register_operand" "")
2341    (match_operand:V2DF 1 "nonimmediate_operand" "")
2342    (match_operand:V2DF 2 "nonimmediate_operand" "")]
2343   "TARGET_SSE2"
2344 {
2345   rtx r1, r2;
2346
2347   r1 = gen_reg_rtx (V4SImode);
2348   r2 = gen_reg_rtx (V4SImode);
2349
2350   emit_insn (gen_sse2_cvttpd2dq (r1, operands[1]));
2351   emit_insn (gen_sse2_cvttpd2dq (r2, operands[2]));
2352   emit_insn (gen_sse2_punpcklqdq (gen_lowpart (V2DImode, operands[0]),
2353                                   gen_lowpart (V2DImode, r1),
2354                                   gen_lowpart (V2DImode, r2)));
2355   DONE;
2356 })
2357
2358 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2359 ;;
2360 ;; Parallel double-precision floating point element swizzling
2361 ;;
2362 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2363
2364 (define_insn "sse2_unpckhpd"
2365   [(set (match_operand:V2DF 0 "nonimmediate_operand"     "=x,x,m")
2366         (vec_select:V2DF
2367           (vec_concat:V4DF
2368             (match_operand:V2DF 1 "nonimmediate_operand" " 0,o,x")
2369             (match_operand:V2DF 2 "nonimmediate_operand" " x,0,0"))
2370           (parallel [(const_int 1)
2371                      (const_int 3)])))]
2372   "TARGET_SSE2 && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
2373   "@
2374    unpckhpd\t{%2, %0|%0, %2}
2375    movlpd\t{%H1, %0|%0, %H1}
2376    movhpd\t{%1, %0|%0, %1}"
2377   [(set_attr "type" "sselog,ssemov,ssemov")
2378    (set_attr "mode" "V2DF,V1DF,V1DF")])
2379
2380 (define_insn "*sse3_movddup"
2381   [(set (match_operand:V2DF 0 "nonimmediate_operand"     "=x,o")
2382         (vec_select:V2DF
2383           (vec_concat:V4DF
2384             (match_operand:V2DF 1 "nonimmediate_operand" "xm,x")
2385             (match_dup 1))
2386           (parallel [(const_int 0)
2387                      (const_int 2)])))]
2388   "TARGET_SSE3 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2389   "@
2390    movddup\t{%1, %0|%0, %1}
2391    #"
2392   [(set_attr "type" "sselog1,ssemov")
2393    (set_attr "mode" "V2DF")])
2394
2395 (define_split
2396   [(set (match_operand:V2DF 0 "memory_operand" "")
2397         (vec_select:V2DF
2398           (vec_concat:V4DF
2399             (match_operand:V2DF 1 "register_operand" "")
2400             (match_dup 1))
2401           (parallel [(const_int 0)
2402                      (const_int 2)])))]
2403   "TARGET_SSE3 && reload_completed"
2404   [(const_int 0)]
2405 {
2406   rtx low = gen_rtx_REG (DFmode, REGNO (operands[1]));
2407   emit_move_insn (adjust_address (operands[0], DFmode, 0), low);
2408   emit_move_insn (adjust_address (operands[0], DFmode, 8), low);
2409   DONE;
2410 })
2411
2412 (define_insn "sse2_unpcklpd"
2413   [(set (match_operand:V2DF 0 "nonimmediate_operand"     "=x,x,o")
2414         (vec_select:V2DF
2415           (vec_concat:V4DF
2416             (match_operand:V2DF 1 "nonimmediate_operand" " 0,0,0")
2417             (match_operand:V2DF 2 "nonimmediate_operand" " x,m,x"))
2418           (parallel [(const_int 0)
2419                      (const_int 2)])))]
2420   "TARGET_SSE2 && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
2421   "@
2422    unpcklpd\t{%2, %0|%0, %2}
2423    movhpd\t{%2, %0|%0, %2}
2424    movlpd\t{%2, %H0|%H0, %2}"
2425   [(set_attr "type" "sselog,ssemov,ssemov")
2426    (set_attr "mode" "V2DF,V1DF,V1DF")])
2427
2428 (define_expand "sse2_shufpd"
2429   [(match_operand:V2DF 0 "register_operand" "")
2430    (match_operand:V2DF 1 "register_operand" "")
2431    (match_operand:V2DF 2 "nonimmediate_operand" "")
2432    (match_operand:SI 3 "const_int_operand" "")]
2433   "TARGET_SSE2"
2434 {
2435   int mask = INTVAL (operands[3]);
2436   emit_insn (gen_sse2_shufpd_1 (operands[0], operands[1], operands[2],
2437                                 GEN_INT (mask & 1),
2438                                 GEN_INT (mask & 2 ? 3 : 2)));
2439   DONE;
2440 })
2441
2442 (define_insn "sse2_shufpd_1"
2443   [(set (match_operand:V2DF 0 "register_operand" "=x")
2444         (vec_select:V2DF
2445           (vec_concat:V4DF
2446             (match_operand:V2DF 1 "register_operand" "0")
2447             (match_operand:V2DF 2 "nonimmediate_operand" "xm"))
2448           (parallel [(match_operand 3 "const_0_to_1_operand" "")
2449                      (match_operand 4 "const_2_to_3_operand" "")])))]
2450   "TARGET_SSE2"
2451 {
2452   int mask;
2453   mask = INTVAL (operands[3]);
2454   mask |= (INTVAL (operands[4]) - 2) << 1;
2455   operands[3] = GEN_INT (mask);
2456
2457   return "shufpd\t{%3, %2, %0|%0, %2, %3}";
2458 }
2459   [(set_attr "type" "sselog")
2460    (set_attr "mode" "V2DF")])
2461
2462 (define_insn "sse2_storehpd"
2463   [(set (match_operand:DF 0 "nonimmediate_operand"     "=m,x,x*fr")
2464         (vec_select:DF
2465           (match_operand:V2DF 1 "nonimmediate_operand" " x,0,o")
2466           (parallel [(const_int 1)])))]
2467   "TARGET_SSE2 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2468   "@
2469    movhpd\t{%1, %0|%0, %1}
2470    unpckhpd\t%0, %0
2471    #"
2472   [(set_attr "type" "ssemov,sselog1,ssemov")
2473    (set_attr "mode" "V1DF,V2DF,DF")])
2474
2475 (define_split
2476   [(set (match_operand:DF 0 "register_operand" "")
2477         (vec_select:DF
2478           (match_operand:V2DF 1 "memory_operand" "")
2479           (parallel [(const_int 1)])))]
2480   "TARGET_SSE2 && reload_completed"
2481   [(set (match_dup 0) (match_dup 1))]
2482 {
2483   operands[1] = adjust_address (operands[1], DFmode, 8);
2484 })
2485
2486 (define_insn "sse2_storelpd"
2487   [(set (match_operand:DF 0 "nonimmediate_operand"     "=m,x,x*fr")
2488         (vec_select:DF
2489           (match_operand:V2DF 1 "nonimmediate_operand" " x,x,m")
2490           (parallel [(const_int 0)])))]
2491   "TARGET_SSE2 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2492   "@
2493    movlpd\t{%1, %0|%0, %1}
2494    #
2495    #"
2496   [(set_attr "type" "ssemov")
2497    (set_attr "mode" "V1DF,DF,DF")])
2498
2499 (define_split
2500   [(set (match_operand:DF 0 "register_operand" "")
2501         (vec_select:DF
2502           (match_operand:V2DF 1 "nonimmediate_operand" "")
2503           (parallel [(const_int 0)])))]
2504   "TARGET_SSE2 && reload_completed"
2505   [(const_int 0)]
2506 {
2507   rtx op1 = operands[1];
2508   if (REG_P (op1))
2509     op1 = gen_rtx_REG (DFmode, REGNO (op1));
2510   else
2511     op1 = gen_lowpart (DFmode, op1);
2512   emit_move_insn (operands[0], op1);
2513   DONE;
2514 })
2515
2516 (define_insn "sse2_loadhpd"
2517   [(set (match_operand:V2DF 0 "nonimmediate_operand"     "=x,x,x,o")
2518         (vec_concat:V2DF
2519           (vec_select:DF
2520             (match_operand:V2DF 1 "nonimmediate_operand" " 0,0,x,0")
2521             (parallel [(const_int 0)]))
2522           (match_operand:DF 2 "nonimmediate_operand"     " m,x,0,x*fr")))]
2523   "TARGET_SSE2 && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
2524   "@
2525    movhpd\t{%2, %0|%0, %2}
2526    unpcklpd\t{%2, %0|%0, %2}
2527    shufpd\t{$1, %1, %0|%0, %1, 1}
2528    #"
2529   [(set_attr "type" "ssemov,sselog,sselog,other")
2530    (set_attr "mode" "V1DF,V2DF,V2DF,DF")])
2531
2532 (define_split
2533   [(set (match_operand:V2DF 0 "memory_operand" "")
2534         (vec_concat:V2DF
2535           (vec_select:DF (match_dup 0) (parallel [(const_int 0)]))
2536           (match_operand:DF 1 "register_operand" "")))]
2537   "TARGET_SSE2 && reload_completed"
2538   [(set (match_dup 0) (match_dup 1))]
2539 {
2540   operands[0] = adjust_address (operands[0], DFmode, 8);
2541 })
2542
2543 (define_insn "sse2_loadlpd"
2544   [(set (match_operand:V2DF 0 "nonimmediate_operand"    "=x,x,x,x,x,m")
2545         (vec_concat:V2DF
2546           (match_operand:DF 2 "nonimmediate_operand"    " m,m,x,0,0,x*fr")
2547           (vec_select:DF
2548             (match_operand:V2DF 1 "vector_move_operand" " C,0,0,x,o,0")
2549             (parallel [(const_int 1)]))))]
2550   "TARGET_SSE2 && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
2551   "@
2552    movsd\t{%2, %0|%0, %2}
2553    movlpd\t{%2, %0|%0, %2}
2554    movsd\t{%2, %0|%0, %2}
2555    shufpd\t{$2, %2, %0|%0, %2, 2}
2556    movhpd\t{%H1, %0|%0, %H1}
2557    #"
2558   [(set_attr "type" "ssemov,ssemov,ssemov,sselog,ssemov,other")
2559    (set_attr "mode" "DF,V1DF,V1DF,V2DF,V1DF,DF")])
2560
2561 (define_split
2562   [(set (match_operand:V2DF 0 "memory_operand" "")
2563         (vec_concat:V2DF
2564           (match_operand:DF 1 "register_operand" "")
2565           (vec_select:DF (match_dup 0) (parallel [(const_int 1)]))))]
2566   "TARGET_SSE2 && reload_completed"
2567   [(set (match_dup 0) (match_dup 1))]
2568 {
2569   operands[0] = adjust_address (operands[0], DFmode, 8);
2570 })
2571
2572 ;; Not sure these two are ever used, but it doesn't hurt to have
2573 ;; them. -aoliva
2574 (define_insn "*vec_extractv2df_1_sse"
2575   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,x,x")
2576         (vec_select:DF
2577           (match_operand:V2DF 1 "nonimmediate_operand" "x,x,o")
2578           (parallel [(const_int 1)])))]
2579   "!TARGET_SSE2 && TARGET_SSE
2580    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2581   "@
2582    movhps\t{%1, %0|%0, %1}
2583    movhlps\t{%1, %0|%0, %1}
2584    movlps\t{%H1, %0|%0, %H1}"
2585   [(set_attr "type" "ssemov")
2586    (set_attr "mode" "V2SF,V4SF,V2SF")])
2587
2588 (define_insn "*vec_extractv2df_0_sse"
2589   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,x,x")
2590         (vec_select:DF
2591           (match_operand:V2DF 1 "nonimmediate_operand" "x,x,m")
2592           (parallel [(const_int 0)])))]
2593   "!TARGET_SSE2 && TARGET_SSE
2594    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2595   "@
2596    movlps\t{%1, %0|%0, %1}
2597    movaps\t{%1, %0|%0, %1}
2598    movlps\t{%1, %0|%0, %1}"
2599   [(set_attr "type" "ssemov")
2600    (set_attr "mode" "V2SF,V4SF,V2SF")])
2601
2602 (define_insn "sse2_movsd"
2603   [(set (match_operand:V2DF 0 "nonimmediate_operand"   "=x,x,m,x,x,o")
2604         (vec_merge:V2DF
2605           (match_operand:V2DF 2 "nonimmediate_operand" " x,m,x,0,0,0")
2606           (match_operand:V2DF 1 "nonimmediate_operand" " 0,0,0,x,o,x")
2607           (const_int 1)))]
2608   "TARGET_SSE2"
2609   "@
2610    movsd\t{%2, %0|%0, %2}
2611    movlpd\t{%2, %0|%0, %2}
2612    movlpd\t{%2, %0|%0, %2}
2613    shufpd\t{$2, %2, %0|%0, %2, 2}
2614    movhps\t{%H1, %0|%0, %H1}
2615    movhps\t{%1, %H0|%H0, %1}"
2616   [(set_attr "type" "ssemov,ssemov,ssemov,sselog,ssemov,ssemov")
2617    (set_attr "mode" "DF,V1DF,V1DF,V2DF,V1DF,V1DF")])
2618
2619 (define_insn "*vec_dupv2df_sse3"
2620   [(set (match_operand:V2DF 0 "register_operand" "=x")
2621         (vec_duplicate:V2DF
2622           (match_operand:DF 1 "nonimmediate_operand" "xm")))]
2623   "TARGET_SSE3"
2624   "movddup\t{%1, %0|%0, %1}"
2625   [(set_attr "type" "sselog1")
2626    (set_attr "mode" "DF")])
2627
2628 (define_insn "*vec_dupv2df"
2629   [(set (match_operand:V2DF 0 "register_operand" "=x")
2630         (vec_duplicate:V2DF
2631           (match_operand:DF 1 "register_operand" "0")))]
2632   "TARGET_SSE2"
2633   "unpcklpd\t%0, %0"
2634   [(set_attr "type" "sselog1")
2635    (set_attr "mode" "V2DF")])
2636
2637 (define_insn "*vec_concatv2df_sse3"
2638   [(set (match_operand:V2DF 0 "register_operand" "=x")
2639         (vec_concat:V2DF
2640           (match_operand:DF 1 "nonimmediate_operand" "xm")
2641           (match_dup 1)))]
2642   "TARGET_SSE3"
2643   "movddup\t{%1, %0|%0, %1}"
2644   [(set_attr "type" "sselog1")
2645    (set_attr "mode" "DF")])
2646
2647 (define_insn "*vec_concatv2df"
2648   [(set (match_operand:V2DF 0 "register_operand"     "=Y2,Y2,Y2,x,x")
2649         (vec_concat:V2DF
2650           (match_operand:DF 1 "nonimmediate_operand" " 0 ,0 ,m ,0,0")
2651           (match_operand:DF 2 "vector_move_operand"  " Y2,m ,C ,x,m")))]
2652   "TARGET_SSE"
2653   "@
2654    unpcklpd\t{%2, %0|%0, %2}
2655    movhpd\t{%2, %0|%0, %2}
2656    movsd\t{%1, %0|%0, %1}
2657    movlhps\t{%2, %0|%0, %2}
2658    movhps\t{%2, %0|%0, %2}"
2659   [(set_attr "type" "sselog,ssemov,ssemov,ssemov,ssemov")
2660    (set_attr "mode" "V2DF,V1DF,DF,V4SF,V2SF")])
2661
2662 (define_expand "vec_setv2df"
2663   [(match_operand:V2DF 0 "register_operand" "")
2664    (match_operand:DF 1 "register_operand" "")
2665    (match_operand 2 "const_int_operand" "")]
2666   "TARGET_SSE"
2667 {
2668   ix86_expand_vector_set (false, operands[0], operands[1],
2669                           INTVAL (operands[2]));
2670   DONE;
2671 })
2672
2673 (define_expand "vec_extractv2df"
2674   [(match_operand:DF 0 "register_operand" "")
2675    (match_operand:V2DF 1 "register_operand" "")
2676    (match_operand 2 "const_int_operand" "")]
2677   "TARGET_SSE"
2678 {
2679   ix86_expand_vector_extract (false, operands[0], operands[1],
2680                               INTVAL (operands[2]));
2681   DONE;
2682 })
2683
2684 (define_expand "vec_initv2df"
2685   [(match_operand:V2DF 0 "register_operand" "")
2686    (match_operand 1 "" "")]
2687   "TARGET_SSE"
2688 {
2689   ix86_expand_vector_init (false, operands[0], operands[1]);
2690   DONE;
2691 })
2692
2693 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2694 ;;
2695 ;; Parallel integral arithmetic
2696 ;;
2697 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2698
2699 (define_expand "neg<mode>2"
2700   [(set (match_operand:SSEMODEI 0 "register_operand" "")
2701         (minus:SSEMODEI
2702           (match_dup 2)
2703           (match_operand:SSEMODEI 1 "nonimmediate_operand" "")))]
2704   "TARGET_SSE2"
2705   "operands[2] = force_reg (<MODE>mode, CONST0_RTX (<MODE>mode));")
2706
2707 (define_expand "add<mode>3"
2708   [(set (match_operand:SSEMODEI 0 "register_operand" "")
2709         (plus:SSEMODEI (match_operand:SSEMODEI 1 "nonimmediate_operand" "")
2710                        (match_operand:SSEMODEI 2 "nonimmediate_operand" "")))]
2711   "TARGET_SSE2"
2712   "ix86_fixup_binary_operands_no_copy (PLUS, <MODE>mode, operands);")
2713
2714 (define_insn "*add<mode>3"
2715   [(set (match_operand:SSEMODEI 0 "register_operand" "=x")
2716         (plus:SSEMODEI
2717           (match_operand:SSEMODEI 1 "nonimmediate_operand" "%0")
2718           (match_operand:SSEMODEI 2 "nonimmediate_operand" "xm")))]
2719   "TARGET_SSE2 && ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
2720   "padd<ssevecsize>\t{%2, %0|%0, %2}"
2721   [(set_attr "type" "sseiadd")
2722    (set_attr "prefix_data16" "1")
2723    (set_attr "mode" "TI")])
2724
2725 (define_insn "sse2_ssadd<mode>3"
2726   [(set (match_operand:SSEMODE12 0 "register_operand" "=x")
2727         (ss_plus:SSEMODE12
2728           (match_operand:SSEMODE12 1 "nonimmediate_operand" "%0")
2729           (match_operand:SSEMODE12 2 "nonimmediate_operand" "xm")))]
2730   "TARGET_SSE2 && ix86_binary_operator_ok (SS_PLUS, <MODE>mode, operands)"
2731   "padds<ssevecsize>\t{%2, %0|%0, %2}"
2732   [(set_attr "type" "sseiadd")
2733    (set_attr "prefix_data16" "1")
2734    (set_attr "mode" "TI")])
2735
2736 (define_insn "sse2_usadd<mode>3"
2737   [(set (match_operand:SSEMODE12 0 "register_operand" "=x")
2738         (us_plus:SSEMODE12
2739           (match_operand:SSEMODE12 1 "nonimmediate_operand" "%0")
2740           (match_operand:SSEMODE12 2 "nonimmediate_operand" "xm")))]
2741   "TARGET_SSE2 && ix86_binary_operator_ok (US_PLUS, <MODE>mode, operands)"
2742   "paddus<ssevecsize>\t{%2, %0|%0, %2}"
2743   [(set_attr "type" "sseiadd")
2744    (set_attr "prefix_data16" "1")
2745    (set_attr "mode" "TI")])
2746
2747 (define_expand "sub<mode>3"
2748   [(set (match_operand:SSEMODEI 0 "register_operand" "")
2749         (minus:SSEMODEI (match_operand:SSEMODEI 1 "register_operand" "")
2750                         (match_operand:SSEMODEI 2 "nonimmediate_operand" "")))]
2751   "TARGET_SSE2"
2752   "ix86_fixup_binary_operands_no_copy (MINUS, <MODE>mode, operands);")
2753
2754 (define_insn "*sub<mode>3"
2755   [(set (match_operand:SSEMODEI 0 "register_operand" "=x")
2756         (minus:SSEMODEI
2757           (match_operand:SSEMODEI 1 "register_operand" "0")
2758           (match_operand:SSEMODEI 2 "nonimmediate_operand" "xm")))]
2759   "TARGET_SSE2"
2760   "psub<ssevecsize>\t{%2, %0|%0, %2}"
2761   [(set_attr "type" "sseiadd")
2762    (set_attr "prefix_data16" "1")
2763    (set_attr "mode" "TI")])
2764
2765 (define_insn "sse2_sssub<mode>3"
2766   [(set (match_operand:SSEMODE12 0 "register_operand" "=x")
2767         (ss_minus:SSEMODE12
2768           (match_operand:SSEMODE12 1 "register_operand" "0")
2769           (match_operand:SSEMODE12 2 "nonimmediate_operand" "xm")))]
2770   "TARGET_SSE2"
2771   "psubs<ssevecsize>\t{%2, %0|%0, %2}"
2772   [(set_attr "type" "sseiadd")
2773    (set_attr "prefix_data16" "1")
2774    (set_attr "mode" "TI")])
2775
2776 (define_insn "sse2_ussub<mode>3"
2777   [(set (match_operand:SSEMODE12 0 "register_operand" "=x")
2778         (us_minus:SSEMODE12
2779           (match_operand:SSEMODE12 1 "register_operand" "0")
2780           (match_operand:SSEMODE12 2 "nonimmediate_operand" "xm")))]
2781   "TARGET_SSE2"
2782   "psubus<ssevecsize>\t{%2, %0|%0, %2}"
2783   [(set_attr "type" "sseiadd")
2784    (set_attr "prefix_data16" "1")
2785    (set_attr "mode" "TI")])
2786
2787 (define_expand "mulv16qi3"
2788   [(set (match_operand:V16QI 0 "register_operand" "")
2789         (mult:V16QI (match_operand:V16QI 1 "register_operand" "")
2790                     (match_operand:V16QI 2 "register_operand" "")))]
2791   "TARGET_SSE2"
2792 {
2793   rtx t[12], op0;
2794   int i;
2795
2796   for (i = 0; i < 12; ++i)
2797     t[i] = gen_reg_rtx (V16QImode);
2798
2799   /* Unpack data such that we've got a source byte in each low byte of
2800      each word.  We don't care what goes into the high byte of each word.
2801      Rather than trying to get zero in there, most convenient is to let
2802      it be a copy of the low byte.  */
2803   emit_insn (gen_sse2_punpckhbw (t[0], operands[1], operands[1]));
2804   emit_insn (gen_sse2_punpckhbw (t[1], operands[2], operands[2]));
2805   emit_insn (gen_sse2_punpcklbw (t[2], operands[1], operands[1]));
2806   emit_insn (gen_sse2_punpcklbw (t[3], operands[2], operands[2]));
2807
2808   /* Multiply words.  The end-of-line annotations here give a picture of what
2809      the output of that instruction looks like.  Dot means don't care; the 
2810      letters are the bytes of the result with A being the most significant.  */
2811   emit_insn (gen_mulv8hi3 (gen_lowpart (V8HImode, t[4]), /* .A.B.C.D.E.F.G.H */
2812                            gen_lowpart (V8HImode, t[0]),
2813                            gen_lowpart (V8HImode, t[1])));
2814   emit_insn (gen_mulv8hi3 (gen_lowpart (V8HImode, t[5]), /* .I.J.K.L.M.N.O.P */
2815                            gen_lowpart (V8HImode, t[2]),
2816                            gen_lowpart (V8HImode, t[3])));
2817
2818   /* Extract the relevant bytes and merge them back together.  */
2819   emit_insn (gen_sse2_punpckhbw (t[6], t[5], t[4]));    /* ..AI..BJ..CK..DL */
2820   emit_insn (gen_sse2_punpcklbw (t[7], t[5], t[4]));    /* ..EM..FN..GO..HP */
2821   emit_insn (gen_sse2_punpckhbw (t[8], t[7], t[6]));    /* ....AEIM....BFJN */
2822   emit_insn (gen_sse2_punpcklbw (t[9], t[7], t[6]));    /* ....CGKO....DHLP */
2823   emit_insn (gen_sse2_punpckhbw (t[10], t[9], t[8]));   /* ........ACEGIKMO */
2824   emit_insn (gen_sse2_punpcklbw (t[11], t[9], t[8]));   /* ........BDFHJLNP */
2825
2826   op0 = operands[0];
2827   emit_insn (gen_sse2_punpcklbw (op0, t[11], t[10]));   /* ABCDEFGHIJKLMNOP */
2828   DONE;
2829 })
2830
2831 (define_expand "mulv8hi3"
2832   [(set (match_operand:V8HI 0 "register_operand" "")
2833         (mult:V8HI (match_operand:V8HI 1 "nonimmediate_operand" "")
2834                    (match_operand:V8HI 2 "nonimmediate_operand" "")))]
2835   "TARGET_SSE2"
2836   "ix86_fixup_binary_operands_no_copy (MULT, V8HImode, operands);")
2837
2838 (define_insn "*mulv8hi3"
2839   [(set (match_operand:V8HI 0 "register_operand" "=x")
2840         (mult:V8HI (match_operand:V8HI 1 "nonimmediate_operand" "%0")
2841                    (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
2842   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, V8HImode, operands)"
2843   "pmullw\t{%2, %0|%0, %2}"
2844   [(set_attr "type" "sseimul")
2845    (set_attr "prefix_data16" "1")
2846    (set_attr "mode" "TI")])
2847
2848 (define_expand "smulv8hi3_highpart"
2849   [(set (match_operand:V8HI 0 "register_operand" "")
2850         (truncate:V8HI
2851           (lshiftrt:V8SI 
2852             (mult:V8SI 
2853               (sign_extend:V8SI
2854                 (match_operand:V8HI 1 "nonimmediate_operand" ""))
2855               (sign_extend:V8SI
2856                 (match_operand:V8HI 2 "nonimmediate_operand" "")))
2857             (const_int 16))))]
2858   "TARGET_SSE2"
2859   "ix86_fixup_binary_operands_no_copy (MULT, V8HImode, operands);")
2860   
2861 (define_insn "*smulv8hi3_highpart"
2862   [(set (match_operand:V8HI 0 "register_operand" "=x")
2863         (truncate:V8HI
2864           (lshiftrt:V8SI
2865             (mult:V8SI
2866               (sign_extend:V8SI
2867                 (match_operand:V8HI 1 "nonimmediate_operand" "%0"))
2868               (sign_extend:V8SI
2869                 (match_operand:V8HI 2 "nonimmediate_operand" "xm")))
2870             (const_int 16))))]
2871   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, V8HImode, operands)"
2872   "pmulhw\t{%2, %0|%0, %2}"
2873   [(set_attr "type" "sseimul")
2874    (set_attr "prefix_data16" "1")
2875    (set_attr "mode" "TI")])
2876
2877 (define_expand "umulv8hi3_highpart"
2878   [(set (match_operand:V8HI 0 "register_operand" "")
2879         (truncate:V8HI
2880           (lshiftrt:V8SI
2881             (mult:V8SI
2882               (zero_extend:V8SI
2883                 (match_operand:V8HI 1 "nonimmediate_operand" ""))
2884               (zero_extend:V8SI
2885                 (match_operand:V8HI 2 "nonimmediate_operand" "")))
2886             (const_int 16))))]
2887   "TARGET_SSE2"
2888   "ix86_fixup_binary_operands_no_copy (MULT, V8HImode, operands);")
2889
2890 (define_insn "*umulv8hi3_highpart"
2891   [(set (match_operand:V8HI 0 "register_operand" "=x")
2892         (truncate:V8HI
2893           (lshiftrt:V8SI
2894             (mult:V8SI
2895               (zero_extend:V8SI
2896                 (match_operand:V8HI 1 "nonimmediate_operand" "%0"))
2897               (zero_extend:V8SI
2898                 (match_operand:V8HI 2 "nonimmediate_operand" "xm")))
2899             (const_int 16))))]
2900   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, V8HImode, operands)"
2901   "pmulhuw\t{%2, %0|%0, %2}"
2902   [(set_attr "type" "sseimul")
2903    (set_attr "prefix_data16" "1")
2904    (set_attr "mode" "TI")])
2905
2906 (define_insn "sse2_umulv2siv2di3"
2907   [(set (match_operand:V2DI 0 "register_operand" "=x")
2908         (mult:V2DI
2909           (zero_extend:V2DI
2910             (vec_select:V2SI
2911               (match_operand:V4SI 1 "nonimmediate_operand" "%0")
2912               (parallel [(const_int 0) (const_int 2)])))
2913           (zero_extend:V2DI
2914             (vec_select:V2SI
2915               (match_operand:V4SI 2 "nonimmediate_operand" "xm")
2916               (parallel [(const_int 0) (const_int 2)])))))]
2917   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, V4SImode, operands)"
2918   "pmuludq\t{%2, %0|%0, %2}"
2919   [(set_attr "type" "sseimul")
2920    (set_attr "prefix_data16" "1")
2921    (set_attr "mode" "TI")])
2922
2923 (define_insn "sse4_1_mulv2siv2di3"
2924   [(set (match_operand:V2DI 0 "register_operand" "=x")
2925         (mult:V2DI
2926           (sign_extend:V2DI
2927             (vec_select:V2SI
2928               (match_operand:V4SI 1 "nonimmediate_operand" "%0")
2929               (parallel [(const_int 0) (const_int 2)])))
2930           (sign_extend:V2DI
2931             (vec_select:V2SI
2932               (match_operand:V4SI 2 "nonimmediate_operand" "xm")
2933               (parallel [(const_int 0) (const_int 2)])))))]
2934   "TARGET_SSE4_1 && ix86_binary_operator_ok (MULT, V4SImode, operands)"
2935   "pmuldq\t{%2, %0|%0, %2}"
2936   [(set_attr "type" "sseimul")
2937    (set_attr "prefix_extra" "1")
2938    (set_attr "mode" "TI")])
2939
2940 (define_insn "sse2_pmaddwd"
2941   [(set (match_operand:V4SI 0 "register_operand" "=x")
2942         (plus:V4SI
2943           (mult:V4SI
2944             (sign_extend:V4SI
2945               (vec_select:V4HI
2946                 (match_operand:V8HI 1 "nonimmediate_operand" "%0")
2947                 (parallel [(const_int 0)
2948                            (const_int 2)
2949                            (const_int 4)
2950                            (const_int 6)])))
2951             (sign_extend:V4SI
2952               (vec_select:V4HI
2953                 (match_operand:V8HI 2 "nonimmediate_operand" "xm")
2954                 (parallel [(const_int 0)
2955                            (const_int 2)
2956                            (const_int 4)
2957                            (const_int 6)]))))
2958           (mult:V4SI
2959             (sign_extend:V4SI
2960               (vec_select:V4HI (match_dup 1)
2961                 (parallel [(const_int 1)
2962                            (const_int 3)
2963                            (const_int 5)
2964                            (const_int 7)])))
2965             (sign_extend:V4SI
2966               (vec_select:V4HI (match_dup 2)
2967                 (parallel [(const_int 1)
2968                            (const_int 3)
2969                            (const_int 5)
2970                            (const_int 7)]))))))]
2971   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, V8HImode, operands)"
2972   "pmaddwd\t{%2, %0|%0, %2}"
2973   [(set_attr "type" "sseiadd")
2974    (set_attr "prefix_data16" "1")
2975    (set_attr "mode" "TI")])
2976
2977 (define_expand "mulv4si3"
2978   [(set (match_operand:V4SI 0 "register_operand" "")
2979         (mult:V4SI (match_operand:V4SI 1 "register_operand" "")
2980                    (match_operand:V4SI 2 "register_operand" "")))]
2981   "TARGET_SSE2"
2982 {
2983   if (TARGET_SSE4_1)
2984     ix86_fixup_binary_operands_no_copy (MULT, V4SImode, operands);
2985  else
2986    {
2987      rtx t1, t2, t3, t4, t5, t6, thirtytwo;
2988      rtx op0, op1, op2;
2989
2990      op0 = operands[0];
2991      op1 = operands[1];
2992      op2 = operands[2];
2993      t1 = gen_reg_rtx (V4SImode);
2994      t2 = gen_reg_rtx (V4SImode);
2995      t3 = gen_reg_rtx (V4SImode);
2996      t4 = gen_reg_rtx (V4SImode);
2997      t5 = gen_reg_rtx (V4SImode);
2998      t6 = gen_reg_rtx (V4SImode);
2999      thirtytwo = GEN_INT (32);
3000
3001      /* Multiply elements 2 and 0.  */
3002      emit_insn (gen_sse2_umulv2siv2di3 (gen_lowpart (V2DImode, t1),
3003                                         op1, op2));
3004
3005      /* Shift both input vectors down one element, so that elements 3
3006         and 1 are now in the slots for elements 2 and 0.  For K8, at
3007         least, this is faster than using a shuffle.  */
3008      emit_insn (gen_sse2_lshrti3 (gen_lowpart (TImode, t2),
3009                                   gen_lowpart (TImode, op1),
3010                                   thirtytwo));
3011      emit_insn (gen_sse2_lshrti3 (gen_lowpart (TImode, t3),
3012                                   gen_lowpart (TImode, op2),
3013                                   thirtytwo)); 
3014      /* Multiply elements 3 and 1.  */
3015      emit_insn (gen_sse2_umulv2siv2di3 (gen_lowpart (V2DImode, t4),
3016                                         t2, t3));
3017
3018      /* Move the results in element 2 down to element 1; we don't care
3019         what goes in elements 2 and 3.  */
3020      emit_insn (gen_sse2_pshufd_1 (t5, t1, const0_rtx, const2_rtx,
3021                                 const0_rtx, const0_rtx));
3022      emit_insn (gen_sse2_pshufd_1 (t6, t4, const0_rtx, const2_rtx,
3023                                    const0_rtx, const0_rtx));
3024
3025     /* Merge the parts back together.  */
3026      emit_insn (gen_sse2_punpckldq (op0, t5, t6));
3027      DONE;
3028    }
3029 })
3030
3031 (define_insn "*sse4_1_mulv4si3"
3032   [(set (match_operand:V4SI 0 "register_operand" "=x")
3033         (mult:V4SI (match_operand:V4SI 1 "nonimmediate_operand" "%0")
3034                    (match_operand:V4SI 2 "nonimmediate_operand" "xm")))]
3035   "TARGET_SSE4_1 && ix86_binary_operator_ok (MULT, V4SImode, operands)"
3036   "pmulld\t{%2, %0|%0, %2}"
3037   [(set_attr "type" "sseimul")
3038    (set_attr "prefix_extra" "1")
3039    (set_attr "mode" "TI")])
3040
3041 (define_expand "mulv2di3"
3042   [(set (match_operand:V2DI 0 "register_operand" "")
3043         (mult:V2DI (match_operand:V2DI 1 "register_operand" "")
3044                    (match_operand:V2DI 2 "register_operand" "")))]
3045   "TARGET_SSE2"
3046 {
3047   rtx t1, t2, t3, t4, t5, t6, thirtytwo;
3048   rtx op0, op1, op2;
3049
3050   op0 = operands[0];
3051   op1 = operands[1];
3052   op2 = operands[2];
3053   t1 = gen_reg_rtx (V2DImode);
3054   t2 = gen_reg_rtx (V2DImode);
3055   t3 = gen_reg_rtx (V2DImode);
3056   t4 = gen_reg_rtx (V2DImode);
3057   t5 = gen_reg_rtx (V2DImode);
3058   t6 = gen_reg_rtx (V2DImode);
3059   thirtytwo = GEN_INT (32);
3060
3061   /* Multiply low parts.  */
3062   emit_insn (gen_sse2_umulv2siv2di3 (t1, gen_lowpart (V4SImode, op1),
3063                                      gen_lowpart (V4SImode, op2)));
3064
3065   /* Shift input vectors left 32 bits so we can multiply high parts.  */
3066   emit_insn (gen_lshrv2di3 (t2, op1, thirtytwo));
3067   emit_insn (gen_lshrv2di3 (t3, op2, thirtytwo));
3068
3069   /* Multiply high parts by low parts.  */
3070   emit_insn (gen_sse2_umulv2siv2di3 (t4, gen_lowpart (V4SImode, op1),
3071                                      gen_lowpart (V4SImode, t3)));
3072   emit_insn (gen_sse2_umulv2siv2di3 (t5, gen_lowpart (V4SImode, op2),
3073                                      gen_lowpart (V4SImode, t2)));
3074
3075   /* Shift them back.  */
3076   emit_insn (gen_ashlv2di3 (t4, t4, thirtytwo));
3077   emit_insn (gen_ashlv2di3 (t5, t5, thirtytwo));
3078
3079   /* Add the three parts together.  */
3080   emit_insn (gen_addv2di3 (t6, t1, t4));
3081   emit_insn (gen_addv2di3 (op0, t6, t5));
3082   DONE;
3083 })
3084
3085 (define_expand "vec_widen_smult_hi_v8hi"
3086   [(match_operand:V4SI 0 "register_operand" "")
3087    (match_operand:V8HI 1 "register_operand" "")
3088    (match_operand:V8HI 2 "register_operand" "")]
3089   "TARGET_SSE2"
3090 {
3091   rtx op1, op2, t1, t2, dest;
3092
3093   op1 = operands[1];
3094   op2 = operands[2];
3095   t1 = gen_reg_rtx (V8HImode);
3096   t2 = gen_reg_rtx (V8HImode);
3097   dest = gen_lowpart (V8HImode, operands[0]);
3098
3099   emit_insn (gen_mulv8hi3 (t1, op1, op2));
3100   emit_insn (gen_smulv8hi3_highpart (t2, op1, op2));
3101   emit_insn (gen_vec_interleave_highv8hi (dest, t1, t2));
3102   DONE;
3103 })
3104
3105 (define_expand "vec_widen_smult_lo_v8hi"
3106   [(match_operand:V4SI 0 "register_operand" "")
3107    (match_operand:V8HI 1 "register_operand" "")
3108    (match_operand:V8HI 2 "register_operand" "")]
3109   "TARGET_SSE2"
3110 {
3111   rtx op1, op2, t1, t2, dest;
3112
3113   op1 = operands[1];
3114   op2 = operands[2];
3115   t1 = gen_reg_rtx (V8HImode);
3116   t2 = gen_reg_rtx (V8HImode);
3117   dest = gen_lowpart (V8HImode, operands[0]);
3118
3119   emit_insn (gen_mulv8hi3 (t1, op1, op2));
3120   emit_insn (gen_smulv8hi3_highpart (t2, op1, op2));
3121   emit_insn (gen_vec_interleave_lowv8hi (dest, t1, t2));
3122   DONE;
3123 })
3124
3125 (define_expand "vec_widen_umult_hi_v8hi"
3126   [(match_operand:V4SI 0 "register_operand" "")
3127    (match_operand:V8HI 1 "register_operand" "")
3128    (match_operand:V8HI 2 "register_operand" "")]
3129   "TARGET_SSE2"
3130 {
3131   rtx op1, op2, t1, t2, dest;
3132
3133   op1 = operands[1];
3134   op2 = operands[2];
3135   t1 = gen_reg_rtx (V8HImode);
3136   t2 = gen_reg_rtx (V8HImode);
3137   dest = gen_lowpart (V8HImode, operands[0]);
3138
3139   emit_insn (gen_mulv8hi3 (t1, op1, op2));
3140   emit_insn (gen_umulv8hi3_highpart (t2, op1, op2));
3141   emit_insn (gen_vec_interleave_highv8hi (dest, t1, t2));
3142   DONE;
3143 })
3144
3145 (define_expand "vec_widen_umult_lo_v8hi"
3146   [(match_operand:V4SI 0 "register_operand" "")
3147    (match_operand:V8HI 1 "register_operand" "")
3148    (match_operand:V8HI 2 "register_operand" "")]
3149   "TARGET_SSE2"
3150 {
3151   rtx op1, op2, t1, t2, dest;
3152
3153   op1 = operands[1];
3154   op2 = operands[2];
3155   t1 = gen_reg_rtx (V8HImode);
3156   t2 = gen_reg_rtx (V8HImode);
3157   dest = gen_lowpart (V8HImode, operands[0]);
3158
3159   emit_insn (gen_mulv8hi3 (t1, op1, op2));
3160   emit_insn (gen_umulv8hi3_highpart (t2, op1, op2));
3161   emit_insn (gen_vec_interleave_lowv8hi (dest, t1, t2));
3162   DONE;
3163 })
3164
3165 (define_expand "vec_widen_smult_hi_v4si"
3166   [(match_operand:V2DI 0 "register_operand" "")
3167    (match_operand:V4SI 1 "register_operand" "")
3168    (match_operand:V4SI 2 "register_operand" "")]
3169   "TARGET_SSE2"
3170 {
3171   rtx op1, op2, t1, t2;
3172
3173   op1 = operands[1];
3174   op2 = operands[2];
3175   t1 = gen_reg_rtx (V4SImode);
3176   t2 = gen_reg_rtx (V4SImode);
3177
3178   emit_insn (gen_vec_interleave_highv4si (t1, op1, op1));
3179   emit_insn (gen_vec_interleave_highv4si (t2, op2, op2));
3180   emit_insn (gen_sse2_umulv2siv2di3 (operands[0], t1, t2));
3181   DONE;
3182 })
3183
3184 (define_expand "vec_widen_smult_lo_v4si"
3185   [(match_operand:V2DI 0 "register_operand" "")
3186    (match_operand:V4SI 1 "register_operand" "")
3187    (match_operand:V4SI 2 "register_operand" "")]
3188   "TARGET_SSE2"
3189 {
3190   rtx op1, op2, t1, t2;
3191
3192   op1 = operands[1];
3193   op2 = operands[2];
3194   t1 = gen_reg_rtx (V4SImode);
3195   t2 = gen_reg_rtx (V4SImode);
3196
3197   emit_insn (gen_vec_interleave_lowv4si (t1, op1, op1));
3198   emit_insn (gen_vec_interleave_lowv4si (t2, op2, op2));
3199   emit_insn (gen_sse2_umulv2siv2di3 (operands[0], t1, t2));
3200   DONE;
3201 })
3202
3203 (define_expand "vec_widen_umult_hi_v4si"
3204   [(match_operand:V2DI 0 "register_operand" "")
3205    (match_operand:V4SI 1 "register_operand" "")
3206    (match_operand:V4SI 2 "register_operand" "")]
3207   "TARGET_SSE2"
3208 {
3209   rtx op1, op2, t1, t2;
3210
3211   op1 = operands[1];
3212   op2 = operands[2];
3213   t1 = gen_reg_rtx (V4SImode);
3214   t2 = gen_reg_rtx (V4SImode);
3215
3216   emit_insn (gen_vec_interleave_highv4si (t1, op1, op1));
3217   emit_insn (gen_vec_interleave_highv4si (t2, op2, op2));
3218   emit_insn (gen_sse2_umulv2siv2di3 (operands[0], t1, t2));
3219   DONE;
3220 })
3221
3222 (define_expand "vec_widen_umult_lo_v4si"
3223   [(match_operand:V2DI 0 "register_operand" "")
3224    (match_operand:V4SI 1 "register_operand" "")
3225    (match_operand:V4SI 2 "register_operand" "")]
3226   "TARGET_SSE2"
3227 {
3228   rtx op1, op2, t1, t2;
3229
3230   op1 = operands[1];
3231   op2 = operands[2];
3232   t1 = gen_reg_rtx (V4SImode);
3233   t2 = gen_reg_rtx (V4SImode);
3234
3235   emit_insn (gen_vec_interleave_lowv4si (t1, op1, op1));
3236   emit_insn (gen_vec_interleave_lowv4si (t2, op2, op2));
3237   emit_insn (gen_sse2_umulv2siv2di3 (operands[0], t1, t2));
3238   DONE;
3239 })
3240
3241 (define_expand "sdot_prodv8hi"
3242   [(match_operand:V4SI 0 "register_operand" "")
3243    (match_operand:V8HI 1 "register_operand" "")
3244    (match_operand:V8HI 2 "register_operand" "")
3245    (match_operand:V4SI 3 "register_operand" "")]
3246   "TARGET_SSE2"
3247 {
3248   rtx t = gen_reg_rtx (V4SImode);
3249   emit_insn (gen_sse2_pmaddwd (t, operands[1], operands[2]));
3250   emit_insn (gen_addv4si3 (operands[0], operands[3], t));
3251   DONE;
3252 })
3253
3254 (define_expand "udot_prodv4si"
3255   [(match_operand:V2DI 0 "register_operand" "") 
3256    (match_operand:V4SI 1 "register_operand" "") 
3257    (match_operand:V4SI 2 "register_operand" "")
3258    (match_operand:V2DI 3 "register_operand" "")]
3259   "TARGET_SSE2"
3260 {
3261   rtx t1, t2, t3, t4;
3262
3263   t1 = gen_reg_rtx (V2DImode);
3264   emit_insn (gen_sse2_umulv2siv2di3 (t1, operands[1], operands[2]));
3265   emit_insn (gen_addv2di3 (t1, t1, operands[3]));
3266
3267   t2 = gen_reg_rtx (V4SImode);
3268   t3 = gen_reg_rtx (V4SImode);
3269   emit_insn (gen_sse2_lshrti3 (gen_lowpart (TImode, t2),
3270                                gen_lowpart (TImode, operands[1]),
3271                                GEN_INT (32)));
3272   emit_insn (gen_sse2_lshrti3 (gen_lowpart (TImode, t3),
3273                                gen_lowpart (TImode, operands[2]),
3274                                GEN_INT (32)));
3275
3276   t4 = gen_reg_rtx (V2DImode);
3277   emit_insn (gen_sse2_umulv2siv2di3 (t4, t2, t3));
3278
3279   emit_insn (gen_addv2di3 (operands[0], t1, t4));
3280   DONE;
3281 })
3282
3283 (define_insn "ashr<mode>3"
3284   [(set (match_operand:SSEMODE24 0 "register_operand" "=x")
3285         (ashiftrt:SSEMODE24
3286           (match_operand:SSEMODE24 1 "register_operand" "0")
3287           (match_operand:TI 2 "nonmemory_operand" "xn")))]
3288   "TARGET_SSE2"
3289   "psra<ssevecsize>\t{%2, %0|%0, %2}"
3290   [(set_attr "type" "sseishft")
3291    (set_attr "prefix_data16" "1")
3292    (set_attr "mode" "TI")])
3293
3294 (define_insn "lshr<mode>3"
3295   [(set (match_operand:SSEMODE248 0 "register_operand" "=x")
3296         (lshiftrt:SSEMODE248
3297           (match_operand:SSEMODE248 1 "register_operand" "0")
3298           (match_operand:TI 2 "nonmemory_operand" "xn")))]
3299   "TARGET_SSE2"
3300   "psrl<ssevecsize>\t{%2, %0|%0, %2}"
3301   [(set_attr "type" "sseishft")
3302    (set_attr "prefix_data16" "1")
3303    (set_attr "mode" "TI")])
3304
3305 (define_insn "ashl<mode>3"
3306   [(set (match_operand:SSEMODE248 0 "register_operand" "=x")
3307         (ashift:SSEMODE248
3308           (match_operand:SSEMODE248 1 "register_operand" "0")
3309           (match_operand:TI 2 "nonmemory_operand" "xn")))]
3310   "TARGET_SSE2"
3311   "psll<ssevecsize>\t{%2, %0|%0, %2}"
3312   [(set_attr "type" "sseishft")
3313    (set_attr "prefix_data16" "1")
3314    (set_attr "mode" "TI")])
3315
3316 (define_insn "sse2_ashlti3"
3317   [(set (match_operand:TI 0 "register_operand" "=x")
3318         (ashift:TI (match_operand:TI 1 "register_operand" "0")
3319                    (match_operand:SI 2 "const_0_to_255_mul_8_operand" "n")))]
3320   "TARGET_SSE2"
3321 {
3322   operands[2] = GEN_INT (INTVAL (operands[2]) / 8);
3323   return "pslldq\t{%2, %0|%0, %2}";
3324 }
3325   [(set_attr "type" "sseishft")
3326    (set_attr "prefix_data16" "1")
3327    (set_attr "mode" "TI")])
3328
3329 (define_expand "vec_shl_<mode>"
3330   [(set (match_operand:SSEMODEI 0 "register_operand" "")
3331         (ashift:TI (match_operand:SSEMODEI 1 "register_operand" "")
3332                    (match_operand:SI 2 "general_operand" "")))]
3333   "TARGET_SSE2"
3334 {
3335   if (!const_0_to_255_mul_8_operand (operands[2], SImode))
3336     FAIL;
3337   operands[0] = gen_lowpart (TImode, operands[0]);
3338   operands[1] = gen_lowpart (TImode, operands[1]);
3339 })
3340
3341 (define_insn "sse2_lshrti3"
3342   [(set (match_operand:TI 0 "register_operand" "=x")
3343         (lshiftrt:TI (match_operand:TI 1 "register_operand" "0")
3344                      (match_operand:SI 2 "const_0_to_255_mul_8_operand" "n")))]
3345   "TARGET_SSE2"
3346 {
3347   operands[2] = GEN_INT (INTVAL (operands[2]) / 8);
3348   return "psrldq\t{%2, %0|%0, %2}";
3349 }
3350   [(set_attr "type" "sseishft")
3351    (set_attr "prefix_data16" "1")
3352    (set_attr "mode" "TI")])
3353
3354 (define_expand "vec_shr_<mode>"
3355   [(set (match_operand:SSEMODEI 0 "register_operand" "")
3356         (lshiftrt:TI (match_operand:SSEMODEI 1 "register_operand" "")
3357                      (match_operand:SI 2 "general_operand" "")))]
3358   "TARGET_SSE2"
3359 {
3360   if (!const_0_to_255_mul_8_operand (operands[2], SImode))
3361     FAIL;
3362   operands[0] = gen_lowpart (TImode, operands[0]);
3363   operands[1] = gen_lowpart (TImode, operands[1]);
3364 })
3365
3366 (define_expand "umaxv16qi3"
3367   [(set (match_operand:V16QI 0 "register_operand" "")
3368         (umax:V16QI (match_operand:V16QI 1 "nonimmediate_operand" "")
3369                     (match_operand:V16QI 2 "nonimmediate_operand" "")))]
3370   "TARGET_SSE2"
3371   "ix86_fixup_binary_operands_no_copy (UMAX, V16QImode, operands);")
3372
3373 (define_insn "*umaxv16qi3"
3374   [(set (match_operand:V16QI 0 "register_operand" "=x")
3375         (umax:V16QI (match_operand:V16QI 1 "nonimmediate_operand" "%0")
3376                     (match_operand:V16QI 2 "nonimmediate_operand" "xm")))]
3377   "TARGET_SSE2 && ix86_binary_operator_ok (UMAX, V16QImode, operands)"
3378   "pmaxub\t{%2, %0|%0, %2}"
3379   [(set_attr "type" "sseiadd")
3380    (set_attr "prefix_data16" "1")
3381    (set_attr "mode" "TI")])
3382
3383 (define_expand "smaxv8hi3"
3384   [(set (match_operand:V8HI 0 "register_operand" "")
3385         (smax:V8HI (match_operand:V8HI 1 "nonimmediate_operand" "")
3386                    (match_operand:V8HI 2 "nonimmediate_operand" "")))]
3387   "TARGET_SSE2"
3388   "ix86_fixup_binary_operands_no_copy (SMAX, V8HImode, operands);")
3389
3390 (define_insn "*smaxv8hi3"
3391   [(set (match_operand:V8HI 0 "register_operand" "=x")
3392         (smax:V8HI (match_operand:V8HI 1 "nonimmediate_operand" "%0")
3393                    (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
3394   "TARGET_SSE2 && ix86_binary_operator_ok (SMAX, V8HImode, operands)"
3395   "pmaxsw\t{%2, %0|%0, %2}"
3396   [(set_attr "type" "sseiadd")
3397    (set_attr "prefix_data16" "1")
3398    (set_attr "mode" "TI")])
3399
3400 (define_expand "umaxv8hi3"
3401   [(set (match_operand:V8HI 0 "register_operand" "")
3402         (umax:V8HI (match_operand:V8HI 1 "register_operand" "")
3403                    (match_operand:V8HI 2 "nonimmediate_operand" "")))]
3404   "TARGET_SSE2"
3405 {
3406   if (TARGET_SSE4_1)
3407     ix86_fixup_binary_operands_no_copy (UMAX, V8HImode, operands);
3408   else
3409     {
3410       rtx op0 = operands[0], op2 = operands[2], op3 = op0;
3411       if (rtx_equal_p (op3, op2))
3412         op3 = gen_reg_rtx (V8HImode);
3413       emit_insn (gen_sse2_ussubv8hi3 (op3, operands[1], op2));
3414       emit_insn (gen_addv8hi3 (op0, op3, op2));
3415       DONE;
3416     }
3417 })
3418
3419 (define_expand "smax<mode>3"
3420   [(set (match_operand:SSEMODE14 0 "register_operand" "")
3421         (smax:SSEMODE14 (match_operand:SSEMODE14 1 "register_operand" "")
3422                         (match_operand:SSEMODE14 2 "register_operand" "")))]
3423   "TARGET_SSE2"
3424 {
3425   if (TARGET_SSE4_1)
3426     ix86_fixup_binary_operands_no_copy (SMAX, <MODE>mode, operands);
3427   else
3428   {
3429     rtx xops[6];
3430     bool ok;
3431
3432     xops[0] = operands[0];
3433     xops[1] = operands[1];
3434     xops[2] = operands[2];
3435     xops[3] = gen_rtx_GT (VOIDmode, operands[1], operands[2]);
3436     xops[4] = operands[1];
3437     xops[5] = operands[2];
3438     ok = ix86_expand_int_vcond (xops);
3439     gcc_assert (ok);
3440     DONE;
3441   }
3442 })
3443
3444 (define_insn "*sse4_1_smax<mode>3"
3445   [(set (match_operand:SSEMODE14 0 "register_operand" "=x")
3446         (smax:SSEMODE14
3447           (match_operand:SSEMODE14 1 "nonimmediate_operand" "%0")
3448           (match_operand:SSEMODE14 2 "nonimmediate_operand" "xm")))]
3449   "TARGET_SSE4_1 && ix86_binary_operator_ok (SMAX, <MODE>mode, operands)"
3450   "pmaxs<ssevecsize>\t{%2, %0|%0, %2}"
3451   [(set_attr "type" "sseiadd")
3452    (set_attr "prefix_extra" "1")
3453    (set_attr "mode" "TI")])
3454
3455 (define_expand "umaxv4si3"
3456   [(set (match_operand:V4SI 0 "register_operand" "")
3457         (umax:V4SI (match_operand:V4SI 1 "register_operand" "")
3458                    (match_operand:V4SI 2 "register_operand" "")))]
3459   "TARGET_SSE2"
3460 {
3461   if (TARGET_SSE4_1)
3462     ix86_fixup_binary_operands_no_copy (UMAX, V4SImode, operands);
3463   else
3464   {
3465     rtx xops[6];
3466     bool ok;
3467
3468     xops[0] = operands[0];
3469     xops[1] = operands[1];
3470     xops[2] = operands[2];
3471     xops[3] = gen_rtx_GTU (VOIDmode, operands[1], operands[2]);
3472     xops[4] = operands[1];
3473     xops[5] = operands[2];
3474     ok = ix86_expand_int_vcond (xops);
3475     gcc_assert (ok);
3476     DONE;
3477   }
3478 })
3479
3480 (define_insn "*sse4_1_umax<mode>3"
3481   [(set (match_operand:SSEMODE24 0 "register_operand" "=x")
3482         (umax:SSEMODE24
3483           (match_operand:SSEMODE24 1 "nonimmediate_operand" "%0")
3484           (match_operand:SSEMODE24 2 "nonimmediate_operand" "xm")))]
3485   "TARGET_SSE4_1 && ix86_binary_operator_ok (UMAX, <MODE>mode, operands)"
3486   "pmaxu<ssevecsize>\t{%2, %0|%0, %2}"
3487   [(set_attr "type" "sseiadd")
3488    (set_attr "prefix_extra" "1")
3489    (set_attr "mode" "TI")])
3490
3491 (define_expand "uminv16qi3"
3492   [(set (match_operand:V16QI 0 "register_operand" "")
3493         (umin:V16QI (match_operand:V16QI 1 "nonimmediate_operand" "")
3494                     (match_operand:V16QI 2 "nonimmediate_operand" "")))]
3495   "TARGET_SSE2"
3496   "ix86_fixup_binary_operands_no_copy (UMIN, V16QImode, operands);")
3497
3498 (define_insn "*uminv16qi3"
3499   [(set (match_operand:V16QI 0 "register_operand" "=x")
3500         (umin:V16QI (match_operand:V16QI 1 "nonimmediate_operand" "%0")
3501                     (match_operand:V16QI 2 "nonimmediate_operand" "xm")))]
3502   "TARGET_SSE2 && ix86_binary_operator_ok (UMIN, V16QImode, operands)"
3503   "pminub\t{%2, %0|%0, %2}"
3504   [(set_attr "type" "sseiadd")
3505    (set_attr "prefix_data16" "1")
3506    (set_attr "mode" "TI")])
3507
3508 (define_expand "sminv8hi3"
3509   [(set (match_operand:V8HI 0 "register_operand" "")
3510         (smin:V8HI (match_operand:V8HI 1 "nonimmediate_operand" "")
3511                    (match_operand:V8HI 2 "nonimmediate_operand" "")))]
3512   "TARGET_SSE2"
3513   "ix86_fixup_binary_operands_no_copy (SMIN, V8HImode, operands);")
3514
3515 (define_insn "*sminv8hi3"
3516   [(set (match_operand:V8HI 0 "register_operand" "=x")
3517         (smin:V8HI (match_operand:V8HI 1 "nonimmediate_operand" "%0")
3518                    (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
3519   "TARGET_SSE2 && ix86_binary_operator_ok (SMIN, V8HImode, operands)"
3520   "pminsw\t{%2, %0|%0, %2}"
3521   [(set_attr "type" "sseiadd")
3522    (set_attr "prefix_data16" "1")
3523    (set_attr "mode" "TI")])
3524
3525 (define_expand "smin<mode>3"
3526   [(set (match_operand:SSEMODE14 0 "register_operand" "")
3527         (smin:SSEMODE14 (match_operand:SSEMODE14 1 "register_operand" "")
3528                         (match_operand:SSEMODE14 2 "register_operand" "")))]
3529   "TARGET_SSE2"
3530 {
3531   if (TARGET_SSE4_1)
3532     ix86_fixup_binary_operands_no_copy (SMIN, <MODE>mode, operands);
3533   else
3534     {
3535       rtx xops[6];
3536       bool ok;
3537
3538       xops[0] = operands[0];
3539       xops[1] = operands[2];
3540       xops[2] = operands[1];
3541       xops[3] = gen_rtx_GT (VOIDmode, operands[1], operands[2]);
3542       xops[4] = operands[1];
3543       xops[5] = operands[2];
3544       ok = ix86_expand_int_vcond (xops);
3545       gcc_assert (ok);
3546       DONE;
3547     }
3548 })
3549
3550 (define_insn "*sse4_1_smin<mode>3"
3551   [(set (match_operand:SSEMODE14 0 "register_operand" "=x")
3552         (smin:SSEMODE14
3553           (match_operand:SSEMODE14 1 "nonimmediate_operand" "%0")
3554           (match_operand:SSEMODE14 2 "nonimmediate_operand" "xm")))]
3555   "TARGET_SSE4_1 && ix86_binary_operator_ok (SMIN, <MODE>mode, operands)"
3556   "pmins<ssevecsize>\t{%2, %0|%0, %2}"
3557   [(set_attr "type" "sseiadd")
3558    (set_attr "prefix_extra" "1")
3559    (set_attr "mode" "TI")])
3560
3561 (define_expand "umin<mode>3"
3562   [(set (match_operand:SSEMODE24 0 "register_operand" "")
3563         (umin:SSEMODE24 (match_operand:SSEMODE24 1 "register_operand" "")
3564                         (match_operand:SSEMODE24 2 "register_operand" "")))]
3565   "TARGET_SSE2"
3566 {
3567   if (TARGET_SSE4_1)
3568     ix86_fixup_binary_operands_no_copy (UMIN, <MODE>mode, operands);
3569   else
3570     {
3571       rtx xops[6];
3572       bool ok;
3573
3574       xops[0] = operands[0];
3575       xops[1] = operands[2];
3576       xops[2] = operands[1];
3577       xops[3] = gen_rtx_GTU (VOIDmode, operands[1], operands[2]);
3578       xops[4] = operands[1];
3579       xops[5] = operands[2];
3580       ok = ix86_expand_int_vcond (xops);
3581       gcc_assert (ok);
3582       DONE;
3583     }
3584 })
3585
3586 (define_insn "*sse4_1_umin<mode>3"
3587   [(set (match_operand:SSEMODE24 0 "register_operand" "=x")
3588         (umin:SSEMODE24
3589           (match_operand:SSEMODE24 1 "nonimmediate_operand" "%0")
3590           (match_operand:SSEMODE24 2 "nonimmediate_operand" "xm")))]
3591   "TARGET_SSE4_1 && ix86_binary_operator_ok (UMIN, <MODE>mode, operands)"
3592   "pminu<ssevecsize>\t{%2, %0|%0, %2}"
3593   [(set_attr "type" "sseiadd")
3594    (set_attr "prefix_extra" "1")
3595    (set_attr "mode" "TI")])
3596
3597 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3598 ;;
3599 ;; Parallel integral comparisons
3600 ;;
3601 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3602
3603 (define_insn "sse2_eq<mode>3"
3604   [(set (match_operand:SSEMODE124 0 "register_operand" "=x")
3605         (eq:SSEMODE124
3606           (match_operand:SSEMODE124 1 "nonimmediate_operand" "%0")
3607           (match_operand:SSEMODE124 2 "nonimmediate_operand" "xm")))]
3608   "TARGET_SSE2 && ix86_binary_operator_ok (EQ, <MODE>mode, operands)"
3609   "pcmpeq<ssevecsize>\t{%2, %0|%0, %2}"
3610   [(set_attr "type" "ssecmp")
3611    (set_attr "prefix_data16" "1")
3612    (set_attr "mode" "TI")])
3613
3614 (define_insn "sse4_1_eqv2di3"
3615   [(set (match_operand:V2DI 0 "register_operand" "=x")
3616         (eq:V2DI
3617           (match_operand:V2DI 1 "nonimmediate_operand" "%0")
3618           (match_operand:V2DI 2 "nonimmediate_operand" "xm")))]
3619   "TARGET_SSE4_1 && ix86_binary_operator_ok (EQ, V2DImode, operands)"
3620   "pcmpeqq\t{%2, %0|%0, %2}"
3621   [(set_attr "type" "ssecmp")
3622    (set_attr "prefix_extra" "1")
3623    (set_attr "mode" "TI")])
3624
3625 (define_insn "sse2_gt<mode>3"
3626   [(set (match_operand:SSEMODE124 0 "register_operand" "=x")
3627         (gt:SSEMODE124
3628           (match_operand:SSEMODE124 1 "register_operand" "0")
3629           (match_operand:SSEMODE124 2 "nonimmediate_operand" "xm")))]
3630   "TARGET_SSE2"
3631   "pcmpgt<ssevecsize>\t{%2, %0|%0, %2}"
3632   [(set_attr "type" "ssecmp")
3633    (set_attr "prefix_data16" "1")
3634    (set_attr "mode" "TI")])
3635
3636 (define_expand "vcond<mode>"
3637   [(set (match_operand:SSEMODE124 0 "register_operand" "")
3638         (if_then_else:SSEMODE124
3639           (match_operator 3 ""
3640             [(match_operand:SSEMODE124 4 "nonimmediate_operand" "")
3641              (match_operand:SSEMODE124 5 "nonimmediate_operand" "")])
3642           (match_operand:SSEMODE124 1 "general_operand" "")
3643           (match_operand:SSEMODE124 2 "general_operand" "")))]
3644   "TARGET_SSE2"
3645 {
3646   if (ix86_expand_int_vcond (operands))
3647     DONE;
3648   else
3649     FAIL;
3650 })
3651
3652 (define_expand "vcondu<mode>"
3653   [(set (match_operand:SSEMODE124 0 "register_operand" "")
3654         (if_then_else:SSEMODE124
3655           (match_operator 3 ""
3656             [(match_operand:SSEMODE124 4 "nonimmediate_operand" "")
3657              (match_operand:SSEMODE124 5 "nonimmediate_operand" "")])
3658           (match_operand:SSEMODE124 1 "general_operand" "")
3659           (match_operand:SSEMODE124 2 "general_operand" "")))]
3660   "TARGET_SSE2"
3661 {
3662   if (ix86_expand_int_vcond (operands))
3663     DONE;
3664   else
3665     FAIL;
3666 })
3667
3668 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3669 ;;
3670 ;; Parallel integral logical operations
3671 ;;
3672 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3673
3674 (define_expand "one_cmpl<mode>2"
3675   [(set (match_operand:SSEMODEI 0 "register_operand" "")
3676         (xor:SSEMODEI (match_operand:SSEMODEI 1 "nonimmediate_operand" "")
3677                       (match_dup 2)))]
3678   "TARGET_SSE2"
3679 {
3680   int i, n = GET_MODE_NUNITS (<MODE>mode);
3681   rtvec v = rtvec_alloc (n);
3682
3683   for (i = 0; i < n; ++i)
3684     RTVEC_ELT (v, i) = constm1_rtx;
3685
3686   operands[2] = force_reg (<MODE>mode, gen_rtx_CONST_VECTOR (<MODE>mode, v));
3687 })
3688
3689 (define_expand "and<mode>3"
3690   [(set (match_operand:SSEMODEI 0 "register_operand" "")
3691         (and:SSEMODEI (match_operand:SSEMODEI 1 "nonimmediate_operand" "")
3692                       (match_operand:SSEMODEI 2 "nonimmediate_operand" "")))]
3693   "TARGET_SSE2"
3694   "ix86_fixup_binary_operands_no_copy (AND, <MODE>mode, operands);")
3695
3696 (define_insn "*and<mode>3"
3697   [(set (match_operand:SSEMODEI 0 "register_operand" "=x")
3698         (and:SSEMODEI
3699           (match_operand:SSEMODEI 1 "nonimmediate_operand" "%0")
3700           (match_operand:SSEMODEI 2 "nonimmediate_operand" "xm")))]
3701   "TARGET_SSE2 && ix86_binary_operator_ok (AND, <MODE>mode, operands)"
3702   "pand\t{%2, %0|%0, %2}"
3703   [(set_attr "type" "sselog")
3704    (set_attr "prefix_data16" "1")
3705    (set_attr "mode" "TI")])
3706
3707 (define_insn "sse2_nand<mode>3"
3708   [(set (match_operand:SSEMODEI 0 "register_operand" "=x")
3709         (and:SSEMODEI
3710           (not:SSEMODEI (match_operand:SSEMODEI 1 "register_operand" "0"))
3711           (match_operand:SSEMODEI 2 "nonimmediate_operand" "xm")))]
3712   "TARGET_SSE2"
3713   "pandn\t{%2, %0|%0, %2}"
3714   [(set_attr "type" "sselog")
3715    (set_attr "prefix_data16" "1")
3716    (set_attr "mode" "TI")])
3717
3718 (define_expand "ior<mode>3"
3719   [(set (match_operand:SSEMODEI 0 "register_operand" "")
3720         (ior:SSEMODEI (match_operand:SSEMODEI 1 "nonimmediate_operand" "")
3721                       (match_operand:SSEMODEI 2 "nonimmediate_operand" "")))]
3722   "TARGET_SSE2"
3723   "ix86_fixup_binary_operands_no_copy (IOR, <MODE>mode, operands);")
3724
3725 (define_insn "*ior<mode>3"
3726   [(set (match_operand:SSEMODEI 0 "register_operand" "=x")
3727         (ior:SSEMODEI
3728           (match_operand:SSEMODEI 1 "nonimmediate_operand" "%0")
3729           (match_operand:SSEMODEI 2 "nonimmediate_operand" "xm")))]
3730   "TARGET_SSE2 && ix86_binary_operator_ok (IOR, <MODE>mode, operands)"
3731   "por\t{%2, %0|%0, %2}"
3732   [(set_attr "type" "sselog")
3733    (set_attr "prefix_data16" "1")
3734    (set_attr "mode" "TI")])
3735
3736 (define_expand "xor<mode>3"
3737   [(set (match_operand:SSEMODEI 0 "register_operand" "")
3738         (xor:SSEMODEI (match_operand:SSEMODEI 1 "nonimmediate_operand" "")
3739                       (match_operand:SSEMODEI 2 "nonimmediate_operand" "")))]
3740   "TARGET_SSE2"
3741   "ix86_fixup_binary_operands_no_copy (XOR, <MODE>mode, operands);")
3742
3743 (define_insn "*xor<mode>3"
3744   [(set (match_operand:SSEMODEI 0 "register_operand" "=x")
3745         (xor:SSEMODEI
3746           (match_operand:SSEMODEI 1 "nonimmediate_operand" "%0")
3747           (match_operand:SSEMODEI 2 "nonimmediate_operand" "xm")))]
3748   "TARGET_SSE2 && ix86_binary_operator_ok (XOR, <MODE>mode, operands)"
3749   "pxor\t{%2, %0|%0, %2}"
3750   [(set_attr "type" "sselog")
3751    (set_attr "prefix_data16" "1")
3752    (set_attr "mode" "TI")])
3753
3754 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3755 ;;
3756 ;; Parallel integral element swizzling
3757 ;;
3758 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3759
3760 ;; Reduce:
3761 ;;      op1 = abcdefghijklmnop
3762 ;;      op2 = qrstuvwxyz012345
3763 ;;       h1 = aqbrcsdteufvgwhx
3764 ;;       l1 = iyjzk0l1m2n3o4p5
3765 ;;       h2 = aiqybjrzcks0dlt1
3766 ;;       l2 = emu2fnv3gow4hpx5
3767 ;;       h3 = aeimquy2bfjnrvz3
3768 ;;       l3 = cgkosw04dhlptx15
3769 ;;   result = bdfhjlnprtvxz135
3770 (define_expand "vec_pack_trunc_v8hi"
3771   [(match_operand:V16QI 0 "register_operand" "")
3772    (match_operand:V8HI 1 "register_operand" "")
3773    (match_operand:V8HI 2 "register_operand" "")]
3774   "TARGET_SSE2"
3775 {
3776   rtx op1, op2, h1, l1, h2, l2, h3, l3;
3777
3778   op1 = gen_lowpart (V16QImode, operands[1]);
3779   op2 = gen_lowpart (V16QImode, operands[2]);
3780   h1 = gen_reg_rtx (V16QImode);
3781   l1 = gen_reg_rtx (V16QImode);
3782   h2 = gen_reg_rtx (V16QImode);
3783   l2 = gen_reg_rtx (V16QImode);
3784   h3 = gen_reg_rtx (V16QImode);
3785   l3 = gen_reg_rtx (V16QImode);
3786
3787   emit_insn (gen_vec_interleave_highv16qi (h1, op1, op2));
3788   emit_insn (gen_vec_interleave_lowv16qi (l1, op1, op2));
3789   emit_insn (gen_vec_interleave_highv16qi (h2, l1, h1));
3790   emit_insn (gen_vec_interleave_lowv16qi (l2, l1, h1));
3791   emit_insn (gen_vec_interleave_highv16qi (h3, l2, h2));
3792   emit_insn (gen_vec_interleave_lowv16qi (l3, l2, h2));
3793   emit_insn (gen_vec_interleave_lowv16qi (operands[0], l3, h3));
3794   DONE;
3795 })
3796
3797 ;; Reduce:
3798 ;;      op1 = abcdefgh
3799 ;;      op2 = ijklmnop
3800 ;;       h1 = aibjckdl
3801 ;;       l1 = emfngohp
3802 ;;       h2 = aeimbfjn
3803 ;;       l2 = cgkodhlp
3804 ;;   result = bdfhjlnp
3805 (define_expand "vec_pack_trunc_v4si"
3806   [(match_operand:V8HI 0 "register_operand" "")
3807    (match_operand:V4SI 1 "register_operand" "")
3808    (match_operand:V4SI 2 "register_operand" "")]
3809   "TARGET_SSE2"
3810 {
3811   rtx op1, op2, h1, l1, h2, l2;
3812
3813   op1 = gen_lowpart (V8HImode, operands[1]);
3814   op2 = gen_lowpart (V8HImode, operands[2]);
3815   h1 = gen_reg_rtx (V8HImode);
3816   l1 = gen_reg_rtx (V8HImode);
3817   h2 = gen_reg_rtx (V8HImode);
3818   l2 = gen_reg_rtx (V8HImode);
3819
3820   emit_insn (gen_vec_interleave_highv8hi (h1, op1, op2));
3821   emit_insn (gen_vec_interleave_lowv8hi (l1, op1, op2));
3822   emit_insn (gen_vec_interleave_highv8hi (h2, l1, h1));
3823   emit_insn (gen_vec_interleave_lowv8hi (l2, l1, h1));
3824   emit_insn (gen_vec_interleave_lowv8hi (operands[0], l2, h2));
3825   DONE;
3826 })
3827
3828 ;; Reduce:
3829 ;;     op1 = abcd
3830 ;;     op2 = efgh
3831 ;;      h1 = aebf
3832 ;;      l1 = cgdh
3833 ;;  result = bdfh
3834 (define_expand "vec_pack_trunc_v2di"
3835   [(match_operand:V4SI 0 "register_operand" "")
3836    (match_operand:V2DI 1 "register_operand" "")
3837    (match_operand:V2DI 2 "register_operand" "")]
3838   "TARGET_SSE2"
3839 {
3840   rtx op1, op2, h1, l1;
3841
3842   op1 = gen_lowpart (V4SImode, operands[1]);
3843   op2 = gen_lowpart (V4SImode, operands[2]);
3844   h1 = gen_reg_rtx (V4SImode);
3845   l1 = gen_reg_rtx (V4SImode);
3846
3847   emit_insn (gen_vec_interleave_highv4si (h1, op1, op2));
3848   emit_insn (gen_vec_interleave_lowv4si (l1, op1, op2));
3849   emit_insn (gen_vec_interleave_lowv4si (operands[0], l1, h1));
3850   DONE;
3851 })
3852
3853 (define_expand "vec_interleave_highv16qi"
3854   [(set (match_operand:V16QI 0 "register_operand" "=x")
3855         (vec_select:V16QI
3856           (vec_concat:V32QI
3857             (match_operand:V16QI 1 "register_operand" "0")
3858             (match_operand:V16QI 2 "nonimmediate_operand" "xm"))
3859           (parallel [(const_int 8)  (const_int 24)
3860                      (const_int 9)  (const_int 25)
3861                      (const_int 10) (const_int 26)
3862                      (const_int 11) (const_int 27)
3863                      (const_int 12) (const_int 28)
3864                      (const_int 13) (const_int 29)
3865                      (const_int 14) (const_int 30)
3866                      (const_int 15) (const_int 31)])))]
3867   "TARGET_SSE2"
3868 {
3869   emit_insn (gen_sse2_punpckhbw (operands[0], operands[1], operands[2]));
3870   DONE;
3871 })
3872
3873 (define_expand "vec_interleave_lowv16qi"
3874   [(set (match_operand:V16QI 0 "register_operand" "=x")
3875         (vec_select:V16QI
3876           (vec_concat:V32QI
3877             (match_operand:V16QI 1 "register_operand" "0")
3878             (match_operand:V16QI 2 "nonimmediate_operand" "xm"))
3879           (parallel [(const_int 0) (const_int 16)
3880                      (const_int 1) (const_int 17)
3881                      (const_int 2) (const_int 18)
3882                      (const_int 3) (const_int 19)
3883                      (const_int 4) (const_int 20)
3884                      (const_int 5) (const_int 21)
3885                      (const_int 6) (const_int 22)
3886                      (const_int 7) (const_int 23)])))]
3887   "TARGET_SSE2"
3888 {
3889   emit_insn (gen_sse2_punpcklbw (operands[0], operands[1], operands[2]));
3890   DONE;
3891 })
3892
3893 (define_expand "vec_interleave_highv8hi"
3894   [(set (match_operand:V8HI 0 "register_operand" "=x")
3895         (vec_select:V8HI
3896           (vec_concat:V16HI
3897             (match_operand:V8HI 1 "register_operand" "0")
3898             (match_operand:V8HI 2 "nonimmediate_operand" "xm"))
3899           (parallel [(const_int 4) (const_int 12)
3900                      (const_int 5) (const_int 13)
3901                      (const_int 6) (const_int 14)
3902                      (const_int 7) (const_int 15)])))]
3903   "TARGET_SSE2"
3904 {
3905   emit_insn (gen_sse2_punpckhwd (operands[0], operands[1], operands[2]));
3906   DONE;
3907 })
3908
3909 (define_expand "vec_interleave_lowv8hi"
3910   [(set (match_operand:V8HI 0 "register_operand" "=x")
3911         (vec_select:V8HI
3912           (vec_concat:V16HI
3913             (match_operand:V8HI 1 "register_operand" "0")
3914             (match_operand:V8HI 2 "nonimmediate_operand" "xm"))
3915           (parallel [(const_int 0) (const_int 8)
3916                      (const_int 1) (const_int 9)
3917                      (const_int 2) (const_int 10)
3918                      (const_int 3) (const_int 11)])))]
3919   "TARGET_SSE2"
3920 {
3921   emit_insn (gen_sse2_punpcklwd (operands[0], operands[1], operands[2]));
3922   DONE;
3923 })
3924
3925 (define_expand "vec_interleave_highv4si"
3926   [(set (match_operand:V4SI 0 "register_operand" "=x")
3927         (vec_select:V4SI
3928           (vec_concat:V8SI
3929             (match_operand:V4SI 1 "register_operand" "0")
3930             (match_operand:V4SI 2 "nonimmediate_operand" "xm"))
3931           (parallel [(const_int 2) (const_int 6)
3932                      (const_int 3) (const_int 7)])))]
3933   "TARGET_SSE2"
3934 {
3935   emit_insn (gen_sse2_punpckhdq (operands[0], operands[1], operands[2]));
3936   DONE;
3937 })
3938
3939 (define_expand "vec_interleave_lowv4si"
3940   [(set (match_operand:V4SI 0 "register_operand" "=x")
3941         (vec_select:V4SI
3942           (vec_concat:V8SI
3943             (match_operand:V4SI 1 "register_operand" "0")
3944             (match_operand:V4SI 2 "nonimmediate_operand" "xm"))
3945           (parallel [(const_int 0) (const_int 4)
3946                      (const_int 1) (const_int 5)])))]
3947   "TARGET_SSE2"
3948 {
3949   emit_insn (gen_sse2_punpckldq (operands[0], operands[1], operands[2]));
3950   DONE;
3951 })
3952
3953 (define_expand "vec_interleave_highv2di"
3954   [(set (match_operand:V2DI 0 "register_operand" "=x")
3955         (vec_select:V2DI
3956           (vec_concat:V4DI
3957             (match_operand:V2DI 1 "register_operand" "0")
3958             (match_operand:V2DI 2 "nonimmediate_operand" "xm"))
3959           (parallel [(const_int 1)
3960                      (const_int 3)])))]
3961   "TARGET_SSE2"
3962 {
3963   emit_insn (gen_sse2_punpckhqdq (operands[0], operands[1], operands[2]));
3964   DONE;
3965 })
3966
3967 (define_expand "vec_interleave_lowv2di"
3968   [(set (match_operand:V2DI 0 "register_operand" "=x")
3969         (vec_select:V2DI
3970           (vec_concat:V4DI
3971             (match_operand:V2DI 1 "register_operand" "0")
3972             (match_operand:V2DI 2 "nonimmediate_operand" "xm"))
3973           (parallel [(const_int 0)
3974                      (const_int 2)])))]
3975   "TARGET_SSE2"
3976 {
3977   emit_insn (gen_sse2_punpcklqdq (operands[0], operands[1], operands[2]));
3978   DONE;
3979 })
3980
3981 (define_insn "sse2_packsswb"
3982   [(set (match_operand:V16QI 0 "register_operand" "=x")
3983         (vec_concat:V16QI
3984           (ss_truncate:V8QI
3985             (match_operand:V8HI 1 "register_operand" "0"))
3986           (ss_truncate:V8QI
3987             (match_operand:V8HI 2 "nonimmediate_operand" "xm"))))]
3988   "TARGET_SSE2"
3989   "packsswb\t{%2, %0|%0, %2}"
3990   [(set_attr "type" "sselog")
3991    (set_attr "prefix_data16" "1")
3992    (set_attr "mode" "TI")])
3993
3994 (define_insn "sse2_packssdw"
3995   [(set (match_operand:V8HI 0 "register_operand" "=x")
3996         (vec_concat:V8HI
3997           (ss_truncate:V4HI
3998             (match_operand:V4SI 1 "register_operand" "0"))
3999           (ss_truncate:V4HI
4000             (match_operand:V4SI 2 "nonimmediate_operand" "xm"))))]
4001   "TARGET_SSE2"
4002   "packssdw\t{%2, %0|%0, %2}"
4003   [(set_attr "type" "sselog")
4004    (set_attr "prefix_data16" "1")
4005    (set_attr "mode" "TI")])
4006
4007 (define_insn "sse2_packuswb"
4008   [(set (match_operand:V16QI 0 "register_operand" "=x")
4009         (vec_concat:V16QI
4010           (us_truncate:V8QI
4011             (match_operand:V8HI 1 "register_operand" "0"))
4012           (us_truncate:V8QI
4013             (match_operand:V8HI 2 "nonimmediate_operand" "xm"))))]
4014   "TARGET_SSE2"
4015   "packuswb\t{%2, %0|%0, %2}"
4016   [(set_attr "type" "sselog")
4017    (set_attr "prefix_data16" "1")
4018    (set_attr "mode" "TI")])
4019
4020 (define_insn "sse2_punpckhbw"
4021   [(set (match_operand:V16QI 0 "register_operand" "=x")
4022         (vec_select:V16QI
4023           (vec_concat:V32QI
4024             (match_operand:V16QI 1 "register_operand" "0")
4025             (match_operand:V16QI 2 "nonimmediate_operand" "xm"))
4026           (parallel [(const_int 8)  (const_int 24)
4027                      (const_int 9)  (const_int 25)
4028                      (const_int 10) (const_int 26)
4029                      (const_int 11) (const_int 27)
4030                      (const_int 12) (const_int 28) 
4031                      (const_int 13) (const_int 29)
4032                      (const_int 14) (const_int 30)
4033                      (const_int 15) (const_int 31)])))]
4034   "TARGET_SSE2"
4035   "punpckhbw\t{%2, %0|%0, %2}"
4036   [(set_attr "type" "sselog")
4037    (set_attr "prefix_data16" "1")
4038    (set_attr "mode" "TI")])
4039
4040 (define_insn "sse2_punpcklbw"
4041   [(set (match_operand:V16QI 0 "register_operand" "=x")
4042         (vec_select:V16QI
4043           (vec_concat:V32QI
4044             (match_operand:V16QI 1 "register_operand" "0")
4045             (match_operand:V16QI 2 "nonimmediate_operand" "xm"))
4046           (parallel [(const_int 0) (const_int 16)
4047                      (const_int 1) (const_int 17)
4048                      (const_int 2) (const_int 18)
4049                      (const_int 3) (const_int 19)
4050                      (const_int 4) (const_int 20)
4051                      (const_int 5) (const_int 21)
4052                      (const_int 6) (const_int 22)
4053                      (const_int 7) (const_int 23)])))]
4054   "TARGET_SSE2"
4055   "punpcklbw\t{%2, %0|%0, %2}"
4056   [(set_attr "type" "sselog")
4057    (set_attr "prefix_data16" "1")
4058    (set_attr "mode" "TI")])
4059
4060 (define_insn "sse2_punpckhwd"
4061   [(set (match_operand:V8HI 0 "register_operand" "=x")
4062         (vec_select:V8HI
4063           (vec_concat:V16HI
4064             (match_operand:V8HI 1 "register_operand" "0")
4065             (match_operand:V8HI 2 "nonimmediate_operand" "xm"))
4066           (parallel [(const_int 4) (const_int 12)
4067                      (const_int 5) (const_int 13)
4068                      (const_int 6) (const_int 14)
4069                      (const_int 7) (const_int 15)])))]
4070   "TARGET_SSE2"
4071   "punpckhwd\t{%2, %0|%0, %2}"
4072   [(set_attr "type" "sselog")
4073    (set_attr "prefix_data16" "1")
4074    (set_attr "mode" "TI")])
4075
4076 (define_insn "sse2_punpcklwd"
4077   [(set (match_operand:V8HI 0 "register_operand" "=x")
4078         (vec_select:V8HI
4079           (vec_concat:V16HI
4080             (match_operand:V8HI 1 "register_operand" "0")
4081             (match_operand:V8HI 2 "nonimmediate_operand" "xm"))
4082           (parallel [(const_int 0) (const_int 8)
4083                      (const_int 1) (const_int 9)
4084                      (const_int 2) (const_int 10)
4085                      (const_int 3) (const_int 11)])))]
4086   "TARGET_SSE2"
4087   "punpcklwd\t{%2, %0|%0, %2}"
4088   [(set_attr "type" "sselog")
4089    (set_attr "prefix_data16" "1")
4090    (set_attr "mode" "TI")])
4091
4092 (define_insn "sse2_punpckhdq"
4093   [(set (match_operand:V4SI 0 "register_operand" "=x")
4094         (vec_select:V4SI
4095           (vec_concat:V8SI
4096             (match_operand:V4SI 1 "register_operand" "0")
4097             (match_operand:V4SI 2 "nonimmediate_operand" "xm"))
4098           (parallel [(const_int 2) (const_int 6)
4099                      (const_int 3) (const_int 7)])))]
4100   "TARGET_SSE2"
4101   "punpckhdq\t{%2, %0|%0, %2}"
4102   [(set_attr "type" "sselog")
4103    (set_attr "prefix_data16" "1")
4104    (set_attr "mode" "TI")])
4105
4106 (define_insn "sse2_punpckldq"
4107   [(set (match_operand:V4SI 0 "register_operand" "=x")
4108         (vec_select:V4SI
4109           (vec_concat:V8SI
4110             (match_operand:V4SI 1 "register_operand" "0")
4111             (match_operand:V4SI 2 "nonimmediate_operand" "xm"))
4112           (parallel [(const_int 0) (const_int 4)
4113                      (const_int 1) (const_int 5)])))]
4114   "TARGET_SSE2"
4115   "punpckldq\t{%2, %0|%0, %2}"
4116   [(set_attr "type" "sselog")
4117    (set_attr "prefix_data16" "1")
4118    (set_attr "mode" "TI")])
4119
4120 (define_insn "sse2_punpckhqdq"
4121   [(set (match_operand:V2DI 0 "register_operand" "=x")
4122         (vec_select:V2DI
4123           (vec_concat:V4DI
4124             (match_operand:V2DI 1 "register_operand" "0")
4125             (match_operand:V2DI 2 "nonimmediate_operand" "xm"))
4126           (parallel [(const_int 1)
4127                      (const_int 3)])))]
4128   "TARGET_SSE2"
4129   "punpckhqdq\t{%2, %0|%0, %2}"
4130   [(set_attr "type" "sselog")
4131    (set_attr "prefix_data16" "1")
4132    (set_attr "mode" "TI")])
4133
4134 (define_insn "sse2_punpcklqdq"
4135   [(set (match_operand:V2DI 0 "register_operand" "=x")
4136         (vec_select:V2DI
4137           (vec_concat:V4DI
4138             (match_operand:V2DI 1 "register_operand" "0")
4139             (match_operand:V2DI 2 "nonimmediate_operand" "xm"))
4140           (parallel [(const_int 0)
4141                      (const_int 2)])))]
4142   "TARGET_SSE2"
4143   "punpcklqdq\t{%2, %0|%0, %2}"
4144   [(set_attr "type" "sselog")
4145    (set_attr "prefix_data16" "1")
4146    (set_attr "mode" "TI")])
4147
4148 (define_insn "*sse4_1_pinsrb"
4149   [(set (match_operand:V16QI 0 "register_operand" "=x")
4150         (vec_merge:V16QI
4151           (vec_duplicate:V16QI
4152             (match_operand:QI 2 "nonimmediate_operand" "rm"))
4153           (match_operand:V16QI 1 "register_operand" "0")
4154           (match_operand:SI 3 "const_pow2_1_to_32768_operand" "n")))]
4155   "TARGET_SSE4_1"
4156 {
4157   operands[3] = GEN_INT (exact_log2 (INTVAL (operands[3])));
4158   return "pinsrb\t{%3, %k2, %0|%0, %k2, %3}";
4159 }
4160   [(set_attr "type" "sselog")
4161    (set_attr "prefix_extra" "1")
4162    (set_attr "mode" "TI")])
4163
4164 (define_insn "*sse2_pinsrw"
4165   [(set (match_operand:V8HI 0 "register_operand" "=x")
4166         (vec_merge:V8HI
4167           (vec_duplicate:V8HI
4168             (match_operand:HI 2 "nonimmediate_operand" "rm"))
4169           (match_operand:V8HI 1 "register_operand" "0")
4170           (match_operand:SI 3 "const_pow2_1_to_128_operand" "n")))]
4171   "TARGET_SSE2"
4172 {
4173   operands[3] = GEN_INT (exact_log2 (INTVAL (operands[3])));
4174   return "pinsrw\t{%3, %k2, %0|%0, %k2, %3}";
4175 }
4176   [(set_attr "type" "sselog")
4177    (set_attr "prefix_data16" "1")
4178    (set_attr "mode" "TI")])
4179
4180 ;; It must come before sse2_loadld since it is preferred.
4181 (define_insn "*sse4_1_pinsrd"
4182   [(set (match_operand:V4SI 0 "register_operand" "=x")
4183         (vec_merge:V4SI
4184           (vec_duplicate:V4SI
4185             (match_operand:SI 2 "nonimmediate_operand" "rm"))
4186           (match_operand:V4SI 1 "register_operand" "0")
4187           (match_operand:SI 3 "const_pow2_1_to_8_operand" "n")))]
4188   "TARGET_SSE4_1"
4189 {
4190   operands[3] = GEN_INT (exact_log2 (INTVAL (operands[3])));
4191   return "pinsrd\t{%3, %2, %0|%0, %2, %3}";
4192 }
4193   [(set_attr "type" "sselog")
4194    (set_attr "prefix_extra" "1")
4195    (set_attr "mode" "TI")])
4196
4197 (define_insn "*sse4_1_pinsrq"
4198   [(set (match_operand:V2DI 0 "register_operand" "=x")
4199         (vec_merge:V2DI
4200           (vec_duplicate:V2DI
4201             (match_operand:DI 2 "nonimmediate_operand" "rm"))
4202           (match_operand:V2DI 1 "register_operand" "0")
4203           (match_operand:SI 3 "const_pow2_1_to_2_operand" "n")))]
4204   "TARGET_SSE4_1"
4205 {
4206   operands[3] = GEN_INT (exact_log2 (INTVAL (operands[3])));
4207   return "pinsrq\t{%3, %2, %0|%0, %2, %3}";
4208 }
4209   [(set_attr "type" "sselog")
4210    (set_attr "prefix_extra" "1")
4211    (set_attr "mode" "TI")])
4212
4213 (define_insn "*sse4_1_pextrb"
4214   [(set (match_operand:SI 0 "register_operand" "=r")
4215         (zero_extend:SI
4216           (vec_select:QI
4217             (match_operand:V16QI 1 "register_operand" "x")
4218             (parallel [(match_operand:SI 2 "const_0_to_15_operand" "n")]))))]
4219   "TARGET_SSE4_1"
4220   "pextrb\t{%2, %1, %0|%0, %1, %2}"
4221   [(set_attr "type" "sselog")
4222    (set_attr "prefix_extra" "1")
4223    (set_attr "mode" "TI")])
4224
4225 (define_insn "*sse4_1_pextrb_memory"
4226   [(set (match_operand:QI 0 "memory_operand" "=m")
4227         (vec_select:QI
4228           (match_operand:V16QI 1 "register_operand" "x")
4229           (parallel [(match_operand:SI 2 "const_0_to_15_operand" "n")])))]
4230   "TARGET_SSE4_1"
4231   "pextrb\t{%2, %1, %0|%0, %1, %2}"
4232   [(set_attr "type" "sselog")
4233    (set_attr "prefix_extra" "1")
4234    (set_attr "mode" "TI")])
4235
4236 (define_insn "*sse2_pextrw"
4237   [(set (match_operand:SI 0 "register_operand" "=r")
4238         (zero_extend:SI
4239           (vec_select:HI
4240             (match_operand:V8HI 1 "register_operand" "x")
4241             (parallel [(match_operand:SI 2 "const_0_to_7_operand" "n")]))))]
4242   "TARGET_SSE2"
4243   "pextrw\t{%2, %1, %0|%0, %1, %2}"
4244   [(set_attr "type" "sselog")
4245    (set_attr "prefix_data16" "1")
4246    (set_attr "mode" "TI")])
4247
4248 (define_insn "*sse4_1_pextrw_memory"
4249   [(set (match_operand:HI 0 "memory_operand" "=m")
4250         (vec_select:HI
4251           (match_operand:V8HI 1 "register_operand" "x")
4252           (parallel [(match_operand:SI 2 "const_0_to_7_operand" "n")])))]
4253   "TARGET_SSE4_1"
4254   "pextrw\t{%2, %1, %0|%0, %1, %2}"
4255   [(set_attr "type" "sselog")
4256    (set_attr "prefix_extra" "1")
4257    (set_attr "mode" "TI")])
4258
4259 (define_insn "*sse4_1_pextrd"
4260   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
4261         (vec_select:SI
4262           (match_operand:V4SI 1 "register_operand" "x")
4263           (parallel [(match_operand:SI 2 "const_0_to_3_operand" "n")])))]
4264   "TARGET_SSE4_1"
4265   "pextrd\t{%2, %1, %0|%0, %1, %2}"
4266   [(set_attr "type" "sselog")
4267    (set_attr "prefix_extra" "1")
4268    (set_attr "mode" "TI")])
4269
4270 ;; It must come before *vec_extractv2di_1_sse since it is preferred.
4271 (define_insn "*sse4_1_pextrq"
4272   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
4273         (vec_select:DI
4274           (match_operand:V2DI 1 "register_operand" "x")
4275           (parallel [(match_operand:SI 2 "const_0_to_1_operand" "n")])))]
4276   "TARGET_SSE4_1 && TARGET_64BIT"
4277   "pextrq\t{%2, %1, %0|%0, %1, %2}"
4278   [(set_attr "type" "sselog")
4279    (set_attr "prefix_extra" "1")
4280    (set_attr "mode" "TI")])
4281
4282 (define_expand "sse2_pshufd"
4283   [(match_operand:V4SI 0 "register_operand" "")
4284    (match_operand:V4SI 1 "nonimmediate_operand" "")
4285    (match_operand:SI 2 "const_int_operand" "")]
4286   "TARGET_SSE2"
4287 {
4288   int mask = INTVAL (operands[2]);
4289   emit_insn (gen_sse2_pshufd_1 (operands[0], operands[1],
4290                                 GEN_INT ((mask >> 0) & 3),
4291                                 GEN_INT ((mask >> 2) & 3),
4292                                 GEN_INT ((mask >> 4) & 3),
4293                                 GEN_INT ((mask >> 6) & 3)));
4294   DONE;
4295 })
4296
4297 (define_insn "sse2_pshufd_1"
4298   [(set (match_operand:V4SI 0 "register_operand" "=x")
4299         (vec_select:V4SI
4300           (match_operand:V4SI 1 "nonimmediate_operand" "xm")
4301           (parallel [(match_operand 2 "const_0_to_3_operand" "")
4302                      (match_operand 3 "const_0_to_3_operand" "")
4303                      (match_operand 4 "const_0_to_3_operand" "")
4304                      (match_operand 5 "const_0_to_3_operand" "")])))]
4305   "TARGET_SSE2"
4306 {
4307   int mask = 0;
4308   mask |= INTVAL (operands[2]) << 0;
4309   mask |= INTVAL (operands[3]) << 2;
4310   mask |= INTVAL (operands[4]) << 4;
4311   mask |= INTVAL (operands[5]) << 6;
4312   operands[2] = GEN_INT (mask);
4313
4314   return "pshufd\t{%2, %1, %0|%0, %1, %2}";
4315 }
4316   [(set_attr "type" "sselog1")
4317    (set_attr "prefix_data16" "1")
4318    (set_attr "mode" "TI")])
4319
4320 (define_expand "sse2_pshuflw"
4321   [(match_operand:V8HI 0 "register_operand" "")
4322    (match_operand:V8HI 1 "nonimmediate_operand" "")
4323    (match_operand:SI 2 "const_int_operand" "")]
4324   "TARGET_SSE2"
4325 {
4326   int mask = INTVAL (operands[2]);
4327   emit_insn (gen_sse2_pshuflw_1 (operands[0], operands[1],
4328                                  GEN_INT ((mask >> 0) & 3),
4329                                  GEN_INT ((mask >> 2) & 3),
4330                                  GEN_INT ((mask >> 4) & 3),
4331                                  GEN_INT ((mask >> 6) & 3)));
4332   DONE;
4333 })
4334
4335 (define_insn "sse2_pshuflw_1"
4336   [(set (match_operand:V8HI 0 "register_operand" "=x")
4337         (vec_select:V8HI
4338           (match_operand:V8HI 1 "nonimmediate_operand" "xm")
4339           (parallel [(match_operand 2 "const_0_to_3_operand" "")
4340                      (match_operand 3 "const_0_to_3_operand" "")
4341                      (match_operand 4 "const_0_to_3_operand" "")
4342                      (match_operand 5 "const_0_to_3_operand" "")
4343                      (const_int 4)
4344                      (const_int 5)
4345                      (const_int 6)
4346                      (const_int 7)])))]
4347   "TARGET_SSE2"
4348 {
4349   int mask = 0;
4350   mask |= INTVAL (operands[2]) << 0;
4351   mask |= INTVAL (operands[3]) << 2;
4352   mask |= INTVAL (operands[4]) << 4;
4353   mask |= INTVAL (operands[5]) << 6;
4354   operands[2] = GEN_INT (mask);
4355
4356   return "pshuflw\t{%2, %1, %0|%0, %1, %2}";
4357 }
4358   [(set_attr "type" "sselog")
4359    (set_attr "prefix_rep" "1")
4360    (set_attr "mode" "TI")])
4361
4362 (define_expand "sse2_pshufhw"
4363   [(match_operand:V8HI 0 "register_operand" "")
4364    (match_operand:V8HI 1 "nonimmediate_operand" "")
4365    (match_operand:SI 2 "const_int_operand" "")]
4366   "TARGET_SSE2"
4367 {
4368   int mask = INTVAL (operands[2]);
4369   emit_insn (gen_sse2_pshufhw_1 (operands[0], operands[1],
4370                                  GEN_INT (((mask >> 0) & 3) + 4),
4371                                  GEN_INT (((mask >> 2) & 3) + 4),
4372                                  GEN_INT (((mask >> 4) & 3) + 4),
4373                                  GEN_INT (((mask >> 6) & 3) + 4)));
4374   DONE;
4375 })
4376
4377 (define_insn "sse2_pshufhw_1"
4378   [(set (match_operand:V8HI 0 "register_operand" "=x")
4379         (vec_select:V8HI
4380           (match_operand:V8HI 1 "nonimmediate_operand" "xm")
4381           (parallel [(const_int 0)
4382                      (const_int 1)
4383                      (const_int 2)
4384                      (const_int 3)
4385                      (match_operand 2 "const_4_to_7_operand" "")
4386                      (match_operand 3 "const_4_to_7_operand" "")
4387                      (match_operand 4 "const_4_to_7_operand" "")
4388                      (match_operand 5 "const_4_to_7_operand" "")])))]
4389   "TARGET_SSE2"
4390 {
4391   int mask = 0;
4392   mask |= (INTVAL (operands[2]) - 4) << 0;
4393   mask |= (INTVAL (operands[3]) - 4) << 2;
4394   mask |= (INTVAL (operands[4]) - 4) << 4;
4395   mask |= (INTVAL (operands[5]) - 4) << 6;
4396   operands[2] = GEN_INT (mask);
4397
4398   return "pshufhw\t{%2, %1, %0|%0, %1, %2}";
4399 }
4400   [(set_attr "type" "sselog")
4401    (set_attr "prefix_rep" "1")
4402    (set_attr "mode" "TI")])
4403
4404 (define_expand "sse2_loadd"
4405   [(set (match_operand:V4SI 0 "register_operand" "")
4406         (vec_merge:V4SI
4407           (vec_duplicate:V4SI
4408             (match_operand:SI 1 "nonimmediate_operand" ""))
4409           (match_dup 2)
4410           (const_int 1)))]
4411   "TARGET_SSE"
4412   "operands[2] = CONST0_RTX (V4SImode);")
4413
4414 (define_insn "sse2_loadld"
4415   [(set (match_operand:V4SI 0 "register_operand"       "=Y2,Yi,x,x")
4416         (vec_merge:V4SI
4417           (vec_duplicate:V4SI
4418             (match_operand:SI 2 "nonimmediate_operand" "m  ,r ,m,x"))
4419           (match_operand:V4SI 1 "reg_or_0_operand"     "C  ,C ,C,0")
4420           (const_int 1)))]
4421   "TARGET_SSE"
4422   "@
4423    movd\t{%2, %0|%0, %2}
4424    movd\t{%2, %0|%0, %2}
4425    movss\t{%2, %0|%0, %2}
4426    movss\t{%2, %0|%0, %2}"
4427   [(set_attr "type" "ssemov")
4428    (set_attr "mode" "TI,TI,V4SF,SF")])
4429
4430 (define_insn_and_split "sse2_stored"
4431   [(set (match_operand:SI 0 "nonimmediate_operand" "=mx,r")
4432         (vec_select:SI
4433           (match_operand:V4SI 1 "register_operand" "x,Yi")
4434           (parallel [(const_int 0)])))]
4435   "TARGET_SSE"
4436   "#"
4437   "&& reload_completed
4438    && (TARGET_INTER_UNIT_MOVES 
4439        || MEM_P (operands [0])
4440        || !GENERAL_REGNO_P (true_regnum (operands [0])))"
4441   [(set (match_dup 0) (match_dup 1))]
4442 {
4443   operands[1] = gen_rtx_REG (SImode, REGNO (operands[1]));
4444 })
4445
4446 (define_expand "sse_storeq"
4447   [(set (match_operand:DI 0 "nonimmediate_operand" "")
4448         (vec_select:DI
4449           (match_operand:V2DI 1 "register_operand" "")
4450           (parallel [(const_int 0)])))]
4451   "TARGET_SSE"
4452   "")
4453
4454 (define_insn "*sse2_storeq_rex64"
4455   [(set (match_operand:DI 0 "nonimmediate_operand" "=mx,r")
4456         (vec_select:DI
4457           (match_operand:V2DI 1 "register_operand" "x,Yi")
4458           (parallel [(const_int 0)])))]
4459   "TARGET_64BIT && TARGET_SSE"
4460   "#")
4461
4462 (define_insn "*sse2_storeq"
4463   [(set (match_operand:DI 0 "nonimmediate_operand" "=mx")
4464         (vec_select:DI
4465           (match_operand:V2DI 1 "register_operand" "x")
4466           (parallel [(const_int 0)])))]
4467   "TARGET_SSE"
4468   "#")
4469
4470 (define_split
4471   [(set (match_operand:DI 0 "nonimmediate_operand" "")
4472         (vec_select:DI
4473           (match_operand:V2DI 1 "register_operand" "")
4474           (parallel [(const_int 0)])))]
4475   "TARGET_SSE
4476    && reload_completed
4477    && (TARGET_INTER_UNIT_MOVES 
4478        || MEM_P (operands [0])
4479        || !GENERAL_REGNO_P (true_regnum (operands [0])))"
4480   [(set (match_dup 0) (match_dup 1))]
4481 {
4482   operands[1] = gen_rtx_REG (DImode, REGNO (operands[1]));
4483 })
4484
4485 (define_insn "*vec_extractv2di_1_sse2"
4486   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,x,x")
4487         (vec_select:DI
4488           (match_operand:V2DI 1 "nonimmediate_operand" "x,0,o")
4489           (parallel [(const_int 1)])))]
4490   "TARGET_SSE2 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4491   "@
4492    movhps\t{%1, %0|%0, %1}
4493    psrldq\t{$4, %0|%0, 4}
4494    movq\t{%H1, %0|%0, %H1}"
4495   [(set_attr "type" "ssemov,sseishft,ssemov")
4496    (set_attr "mode" "V2SF,TI,TI")])
4497
4498 ;; Not sure this is ever used, but it doesn't hurt to have it. -aoliva
4499 (define_insn "*vec_extractv2di_1_sse"
4500   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,x,x")
4501         (vec_select:DI
4502           (match_operand:V2DI 1 "nonimmediate_operand" "x,x,o")
4503           (parallel [(const_int 1)])))]
4504   "!TARGET_SSE2 && TARGET_SSE
4505    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4506   "@
4507    movhps\t{%1, %0|%0, %1}
4508    movhlps\t{%1, %0|%0, %1}
4509    movlps\t{%H1, %0|%0, %H1}"
4510   [(set_attr "type" "ssemov")
4511    (set_attr "mode" "V2SF,V4SF,V2SF")])
4512
4513 (define_insn "*vec_dupv4si"
4514   [(set (match_operand:V4SI 0 "register_operand" "=Y2,x")
4515         (vec_duplicate:V4SI
4516           (match_operand:SI 1 "register_operand" " Y2,0")))]
4517   "TARGET_SSE"
4518   "@
4519    pshufd\t{$0, %1, %0|%0, %1, 0}
4520    shufps\t{$0, %0, %0|%0, %0, 0}"
4521   [(set_attr "type" "sselog1")
4522    (set_attr "mode" "TI,V4SF")])
4523
4524 (define_insn "*vec_dupv2di"
4525   [(set (match_operand:V2DI 0 "register_operand" "=Y2,x")
4526         (vec_duplicate:V2DI
4527           (match_operand:DI 1 "register_operand" " 0 ,0")))]
4528   "TARGET_SSE"
4529   "@
4530    punpcklqdq\t%0, %0
4531    movlhps\t%0, %0"
4532   [(set_attr "type" "sselog1,ssemov")
4533    (set_attr "mode" "TI,V4SF")])
4534
4535 ;; ??? In theory we can match memory for the MMX alternative, but allowing
4536 ;; nonimmediate_operand for operand 2 and *not* allowing memory for the SSE
4537 ;; alternatives pretty much forces the MMX alternative to be chosen.
4538 (define_insn "*sse2_concatv2si"
4539   [(set (match_operand:V2SI 0 "register_operand"     "=Y2, Y2,*y,*y")
4540         (vec_concat:V2SI
4541           (match_operand:SI 1 "nonimmediate_operand" " 0 ,rm , 0,rm")
4542           (match_operand:SI 2 "reg_or_0_operand"     " Y2,C  ,*y, C")))]
4543   "TARGET_SSE2"
4544   "@
4545    punpckldq\t{%2, %0|%0, %2}
4546    movd\t{%1, %0|%0, %1}
4547    punpckldq\t{%2, %0|%0, %2}
4548    movd\t{%1, %0|%0, %1}"
4549   [(set_attr "type" "sselog,ssemov,mmxcvt,mmxmov")
4550    (set_attr "mode" "TI,TI,DI,DI")])
4551
4552 (define_insn "*sse1_concatv2si"
4553   [(set (match_operand:V2SI 0 "register_operand"     "=x,x,*y,*y")
4554         (vec_concat:V2SI
4555           (match_operand:SI 1 "nonimmediate_operand" " 0,m, 0,*rm")
4556           (match_operand:SI 2 "reg_or_0_operand"     " x,C,*y,C")))]
4557   "TARGET_SSE"
4558   "@
4559    unpcklps\t{%2, %0|%0, %2}
4560    movss\t{%1, %0|%0, %1}
4561    punpckldq\t{%2, %0|%0, %2}
4562    movd\t{%1, %0|%0, %1}"
4563   [(set_attr "type" "sselog,ssemov,mmxcvt,mmxmov")
4564    (set_attr "mode" "V4SF,V4SF,DI,DI")])
4565
4566 (define_insn "*vec_concatv4si_1"
4567   [(set (match_operand:V4SI 0 "register_operand"       "=Y2,x,x")
4568         (vec_concat:V4SI
4569           (match_operand:V2SI 1 "register_operand"     " 0 ,0,0")
4570           (match_operand:V2SI 2 "nonimmediate_operand" " Y2,x,m")))]
4571   "TARGET_SSE"
4572   "@
4573    punpcklqdq\t{%2, %0|%0, %2}
4574    movlhps\t{%2, %0|%0, %2}
4575    movhps\t{%2, %0|%0, %2}"
4576   [(set_attr "type" "sselog,ssemov,ssemov")
4577    (set_attr "mode" "TI,V4SF,V2SF")])
4578
4579 (define_insn "vec_concatv2di"
4580   [(set (match_operand:V2DI 0 "register_operand"     "=Y2,?Y2,Y2,x,x,x")
4581         (vec_concat:V2DI
4582           (match_operand:DI 1 "nonimmediate_operand" "  m,*y ,0 ,0,0,m")
4583           (match_operand:DI 2 "vector_move_operand"  "  C,  C,Y2,x,m,0")))]
4584   "TARGET_SSE"
4585   "@
4586    movq\t{%1, %0|%0, %1}
4587    movq2dq\t{%1, %0|%0, %1}
4588    punpcklqdq\t{%2, %0|%0, %2}
4589    movlhps\t{%2, %0|%0, %2}
4590    movhps\t{%2, %0|%0, %2}
4591    movlps\t{%1, %0|%0, %1}"
4592   [(set_attr "type" "ssemov,ssemov,sselog,ssemov,ssemov,ssemov")
4593    (set_attr "mode" "TI,TI,TI,V4SF,V2SF,V2SF")])
4594
4595 (define_expand "vec_setv2di"
4596   [(match_operand:V2DI 0 "register_operand" "")
4597    (match_operand:DI 1 "register_operand" "")
4598    (match_operand 2 "const_int_operand" "")]
4599   "TARGET_SSE"
4600 {
4601   ix86_expand_vector_set (false, operands[0], operands[1],
4602                           INTVAL (operands[2]));
4603   DONE;
4604 })
4605
4606 (define_expand "vec_extractv2di"
4607   [(match_operand:DI 0 "register_operand" "")
4608    (match_operand:V2DI 1 "register_operand" "")
4609    (match_operand 2 "const_int_operand" "")]
4610   "TARGET_SSE"
4611 {
4612   ix86_expand_vector_extract (false, operands[0], operands[1],
4613                               INTVAL (operands[2]));
4614   DONE;
4615 })
4616
4617 (define_expand "vec_initv2di"
4618   [(match_operand:V2DI 0 "register_operand" "")
4619    (match_operand 1 "" "")]
4620   "TARGET_SSE"
4621 {
4622   ix86_expand_vector_init (false, operands[0], operands[1]);
4623   DONE;
4624 })
4625
4626 (define_expand "vec_setv4si"
4627   [(match_operand:V4SI 0 "register_operand" "")
4628    (match_operand:SI 1 "register_operand" "")
4629    (match_operand 2 "const_int_operand" "")]
4630   "TARGET_SSE"
4631 {
4632   ix86_expand_vector_set (false, operands[0], operands[1],
4633                           INTVAL (operands[2]));
4634   DONE;
4635 })
4636
4637 (define_expand "vec_extractv4si"
4638   [(match_operand:SI 0 "register_operand" "")
4639    (match_operand:V4SI 1 "register_operand" "")
4640    (match_operand 2 "const_int_operand" "")]
4641   "TARGET_SSE"
4642 {
4643   ix86_expand_vector_extract (false, operands[0], operands[1],
4644                               INTVAL (operands[2]));
4645   DONE;
4646 })
4647
4648 (define_expand "vec_initv4si"
4649   [(match_operand:V4SI 0 "register_operand" "")
4650    (match_operand 1 "" "")]
4651   "TARGET_SSE"
4652 {
4653   ix86_expand_vector_init (false, operands[0], operands[1]);
4654   DONE;
4655 })
4656
4657 (define_expand "vec_setv8hi"
4658   [(match_operand:V8HI 0 "register_operand" "")
4659    (match_operand:HI 1 "register_operand" "")
4660    (match_operand 2 "const_int_operand" "")]
4661   "TARGET_SSE"
4662 {
4663   ix86_expand_vector_set (false, operands[0], operands[1],
4664                           INTVAL (operands[2]));
4665   DONE;
4666 })
4667
4668 (define_expand "vec_extractv8hi"
4669   [(match_operand:HI 0 "register_operand" "")
4670    (match_operand:V8HI 1 "register_operand" "")
4671    (match_operand 2 "const_int_operand" "")]
4672   "TARGET_SSE"
4673 {
4674   ix86_expand_vector_extract (false, operands[0], operands[1],
4675                               INTVAL (operands[2]));
4676   DONE;
4677 })
4678
4679 (define_expand "vec_initv8hi"
4680   [(match_operand:V8HI 0 "register_operand" "")
4681    (match_operand 1 "" "")]
4682   "TARGET_SSE"
4683 {
4684   ix86_expand_vector_init (false, operands[0], operands[1]);
4685   DONE;
4686 })
4687
4688 (define_expand "vec_setv16qi"
4689   [(match_operand:V16QI 0 "register_operand" "")
4690    (match_operand:QI 1 "register_operand" "")
4691    (match_operand 2 "const_int_operand" "")]
4692   "TARGET_SSE"
4693 {
4694   ix86_expand_vector_set (false, operands[0], operands[1],
4695                           INTVAL (operands[2]));
4696   DONE;
4697 })
4698
4699 (define_expand "vec_extractv16qi"
4700   [(match_operand:QI 0 "register_operand" "")
4701    (match_operand:V16QI 1 "register_operand" "")
4702    (match_operand 2 "const_int_operand" "")]
4703   "TARGET_SSE"
4704 {
4705   ix86_expand_vector_extract (false, operands[0], operands[1],
4706                               INTVAL (operands[2]));
4707   DONE;
4708 })
4709
4710 (define_expand "vec_initv16qi"
4711   [(match_operand:V16QI 0 "register_operand" "")
4712    (match_operand 1 "" "")]
4713   "TARGET_SSE"
4714 {
4715   ix86_expand_vector_init (false, operands[0], operands[1]);
4716   DONE;
4717 })
4718
4719 (define_expand "vec_unpacku_hi_v16qi"
4720   [(match_operand:V8HI 0 "register_operand" "")
4721    (match_operand:V16QI 1 "register_operand" "")]
4722   "TARGET_SSE2"
4723 {
4724   ix86_expand_sse_unpack (operands, true, true);
4725   DONE;
4726 })
4727
4728 (define_expand "vec_unpacks_hi_v16qi"
4729   [(match_operand:V8HI 0 "register_operand" "")
4730    (match_operand:V16QI 1 "register_operand" "")]
4731   "TARGET_SSE2"
4732 {
4733   ix86_expand_sse_unpack (operands, false, true);
4734   DONE;
4735 })
4736
4737 (define_expand "vec_unpacku_lo_v16qi"
4738   [(match_operand:V8HI 0 "register_operand" "")
4739    (match_operand:V16QI 1 "register_operand" "")]
4740   "TARGET_SSE2"
4741 {
4742   ix86_expand_sse_unpack (operands, true, false);
4743   DONE;
4744 })
4745
4746 (define_expand "vec_unpacks_lo_v16qi"
4747   [(match_operand:V8HI 0 "register_operand" "")
4748    (match_operand:V16QI 1 "register_operand" "")]
4749   "TARGET_SSE2"
4750 {
4751   ix86_expand_sse_unpack (operands, false, false);
4752   DONE;
4753 })
4754
4755 (define_expand "vec_unpacku_hi_v8hi"
4756   [(match_operand:V4SI 0 "register_operand" "")
4757    (match_operand:V8HI 1 "register_operand" "")]
4758   "TARGET_SSE2"
4759 {
4760   ix86_expand_sse_unpack (operands, true, true);
4761   DONE;
4762 })
4763
4764 (define_expand "vec_unpacks_hi_v8hi"
4765   [(match_operand:V4SI 0 "register_operand" "")
4766    (match_operand:V8HI 1 "register_operand" "")]
4767   "TARGET_SSE2"
4768 {
4769   ix86_expand_sse_unpack (operands, false, true);
4770   DONE;
4771 })
4772
4773 (define_expand "vec_unpacku_lo_v8hi"
4774   [(match_operand:V4SI 0 "register_operand" "")
4775    (match_operand:V8HI 1 "register_operand" "")]
4776   "TARGET_SSE2"
4777 {
4778   ix86_expand_sse_unpack (operands, true, false);
4779   DONE;
4780 })
4781
4782 (define_expand "vec_unpacks_lo_v8hi"
4783   [(match_operand:V4SI 0 "register_operand" "")
4784    (match_operand:V8HI 1 "register_operand" "")]
4785   "TARGET_SSE2"
4786 {
4787   ix86_expand_sse_unpack (operands, false, false);
4788   DONE;
4789 })
4790
4791 (define_expand "vec_unpacku_hi_v4si"
4792   [(match_operand:V2DI 0 "register_operand" "")
4793    (match_operand:V4SI 1 "register_operand" "")]
4794   "TARGET_SSE2"
4795 {
4796   ix86_expand_sse_unpack (operands, true, true);
4797   DONE;
4798 })
4799
4800 (define_expand "vec_unpacks_hi_v4si"
4801   [(match_operand:V2DI 0 "register_operand" "")
4802    (match_operand:V4SI 1 "register_operand" "")]
4803   "TARGET_SSE2"
4804 {
4805   ix86_expand_sse_unpack (operands, false, true);
4806   DONE;
4807 })
4808
4809 (define_expand "vec_unpacku_lo_v4si"
4810   [(match_operand:V2DI 0 "register_operand" "")
4811    (match_operand:V4SI 1 "register_operand" "")]
4812   "TARGET_SSE2"
4813 {
4814   ix86_expand_sse_unpack (operands, true, false);
4815   DONE;
4816 })
4817
4818 (define_expand "vec_unpacks_lo_v4si"
4819   [(match_operand:V2DI 0 "register_operand" "")
4820    (match_operand:V4SI 1 "register_operand" "")]
4821   "TARGET_SSE2"
4822 {
4823   ix86_expand_sse_unpack (operands, false, false);
4824   DONE;
4825 })
4826
4827 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4828 ;;
4829 ;; Miscellaneous
4830 ;;
4831 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4832
4833 (define_insn "sse2_uavgv16qi3"
4834   [(set (match_operand:V16QI 0 "register_operand" "=x")
4835         (truncate:V16QI
4836           (lshiftrt:V16HI
4837             (plus:V16HI
4838               (plus:V16HI
4839                 (zero_extend:V16HI
4840                   (match_operand:V16QI 1 "nonimmediate_operand" "%0"))
4841                 (zero_extend:V16HI
4842                   (match_operand:V16QI 2 "nonimmediate_operand" "xm")))
4843               (const_vector:V16QI [(const_int 1) (const_int 1)
4844                                    (const_int 1) (const_int 1)
4845                                    (const_int 1) (const_int 1)
4846                                    (const_int 1) (const_int 1)
4847                                    (const_int 1) (const_int 1)
4848                                    (const_int 1) (const_int 1)
4849                                    (const_int 1) (const_int 1)
4850                                    (const_int 1) (const_int 1)]))
4851             (const_int 1))))]
4852   "TARGET_SSE2 && ix86_binary_operator_ok (PLUS, V16QImode, operands)"
4853   "pavgb\t{%2, %0|%0, %2}"
4854   [(set_attr "type" "sseiadd")
4855    (set_attr "prefix_data16" "1")
4856    (set_attr "mode" "TI")])
4857
4858 (define_insn "sse2_uavgv8hi3"
4859   [(set (match_operand:V8HI 0 "register_operand" "=x")
4860         (truncate:V8HI
4861           (lshiftrt:V8SI
4862             (plus:V8SI
4863               (plus:V8SI
4864                 (zero_extend:V8SI
4865                   (match_operand:V8HI 1 "nonimmediate_operand" "%0"))
4866                 (zero_extend:V8SI
4867                   (match_operand:V8HI 2 "nonimmediate_operand" "xm")))
4868               (const_vector:V8HI [(const_int 1) (const_int 1)
4869                                   (const_int 1) (const_int 1)
4870                                   (const_int 1) (const_int 1)
4871                                   (const_int 1) (const_int 1)]))
4872             (const_int 1))))]
4873   "TARGET_SSE2 && ix86_binary_operator_ok (PLUS, V8HImode, operands)"
4874   "pavgw\t{%2, %0|%0, %2}"
4875   [(set_attr "type" "sseiadd")
4876    (set_attr "prefix_data16" "1")
4877    (set_attr "mode" "TI")])
4878
4879 ;; The correct representation for this is absolutely enormous, and 
4880 ;; surely not generally useful.
4881 (define_insn "sse2_psadbw"
4882   [(set (match_operand:V2DI 0 "register_operand" "=x")
4883         (unspec:V2DI [(match_operand:V16QI 1 "register_operand" "0")
4884                       (match_operand:V16QI 2 "nonimmediate_operand" "xm")]
4885                      UNSPEC_PSADBW))]
4886   "TARGET_SSE2"
4887   "psadbw\t{%2, %0|%0, %2}"
4888   [(set_attr "type" "sseiadd")
4889    (set_attr "prefix_data16" "1")
4890    (set_attr "mode" "TI")])
4891
4892 (define_insn "sse_movmskps"
4893   [(set (match_operand:SI 0 "register_operand" "=r")
4894         (unspec:SI [(match_operand:V4SF 1 "register_operand" "x")]
4895                    UNSPEC_MOVMSK))]
4896   "TARGET_SSE"
4897   "movmskps\t{%1, %0|%0, %1}"
4898   [(set_attr "type" "ssecvt")
4899    (set_attr "mode" "V4SF")])
4900
4901 (define_insn "sse2_movmskpd"
4902   [(set (match_operand:SI 0 "register_operand" "=r")
4903         (unspec:SI [(match_operand:V2DF 1 "register_operand" "x")]
4904                    UNSPEC_MOVMSK))]
4905   "TARGET_SSE2"
4906   "movmskpd\t{%1, %0|%0, %1}"
4907   [(set_attr "type" "ssecvt")
4908    (set_attr "mode" "V2DF")])
4909
4910 (define_insn "sse2_pmovmskb"
4911   [(set (match_operand:SI 0 "register_operand" "=r")
4912         (unspec:SI [(match_operand:V16QI 1 "register_operand" "x")]
4913                    UNSPEC_MOVMSK))]
4914   "TARGET_SSE2"
4915   "pmovmskb\t{%1, %0|%0, %1}"
4916   [(set_attr "type" "ssecvt")
4917    (set_attr "prefix_data16" "1")
4918    (set_attr "mode" "SI")])
4919
4920 (define_expand "sse2_maskmovdqu"
4921   [(set (match_operand:V16QI 0 "memory_operand" "")
4922         (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "x")
4923                        (match_operand:V16QI 2 "register_operand" "x")
4924                        (match_dup 0)]
4925                       UNSPEC_MASKMOV))]
4926   "TARGET_SSE2"
4927   "")
4928
4929 (define_insn "*sse2_maskmovdqu"
4930   [(set (mem:V16QI (match_operand:SI 0 "register_operand" "D"))
4931         (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "x")
4932                        (match_operand:V16QI 2 "register_operand" "x")
4933                        (mem:V16QI (match_dup 0))]
4934                       UNSPEC_MASKMOV))]
4935   "TARGET_SSE2 && !TARGET_64BIT"
4936   ;; @@@ check ordering of operands in intel/nonintel syntax
4937   "maskmovdqu\t{%2, %1|%1, %2}"
4938   [(set_attr "type" "ssecvt")
4939    (set_attr "prefix_data16" "1")
4940    (set_attr "mode" "TI")])
4941
4942 (define_insn "*sse2_maskmovdqu_rex64"
4943   [(set (mem:V16QI (match_operand:DI 0 "register_operand" "D"))
4944         (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "x")
4945                        (match_operand:V16QI 2 "register_operand" "x")
4946                        (mem:V16QI (match_dup 0))]
4947                       UNSPEC_MASKMOV))]
4948   "TARGET_SSE2 && TARGET_64BIT"
4949   ;; @@@ check ordering of operands in intel/nonintel syntax
4950   "maskmovdqu\t{%2, %1|%1, %2}"
4951   [(set_attr "type" "ssecvt")
4952    (set_attr "prefix_data16" "1")
4953    (set_attr "mode" "TI")])
4954
4955 (define_insn "sse_ldmxcsr"
4956   [(unspec_volatile [(match_operand:SI 0 "memory_operand" "m")]
4957                     UNSPECV_LDMXCSR)]
4958   "TARGET_SSE"
4959   "ldmxcsr\t%0"
4960   [(set_attr "type" "sse")
4961    (set_attr "memory" "load")])
4962
4963 (define_insn "sse_stmxcsr"
4964   [(set (match_operand:SI 0 "memory_operand" "=m")
4965         (unspec_volatile:SI [(const_int 0)] UNSPECV_STMXCSR))]
4966   "TARGET_SSE"
4967   "stmxcsr\t%0"
4968   [(set_attr "type" "sse")
4969    (set_attr "memory" "store")])
4970
4971 (define_expand "sse_sfence"
4972   [(set (match_dup 0)
4973         (unspec:BLK [(match_dup 0)] UNSPEC_SFENCE))]
4974   "TARGET_SSE || TARGET_3DNOW_A"
4975 {
4976   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
4977   MEM_VOLATILE_P (operands[0]) = 1;
4978 })
4979
4980 (define_insn "*sse_sfence"
4981   [(set (match_operand:BLK 0 "" "")
4982         (unspec:BLK [(match_dup 0)] UNSPEC_SFENCE))]
4983   "TARGET_SSE || TARGET_3DNOW_A"
4984   "sfence"
4985   [(set_attr "type" "sse")
4986    (set_attr "memory" "unknown")])
4987
4988 (define_insn "sse2_clflush"
4989   [(unspec_volatile [(match_operand 0 "address_operand" "p")]
4990                     UNSPECV_CLFLUSH)]
4991   "TARGET_SSE2"
4992   "clflush\t%a0"
4993   [(set_attr "type" "sse")
4994    (set_attr "memory" "unknown")])
4995
4996 (define_expand "sse2_mfence"
4997   [(set (match_dup 0)
4998         (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
4999   "TARGET_SSE2"
5000 {
5001   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
5002   MEM_VOLATILE_P (operands[0]) = 1;
5003 })
5004
5005 (define_insn "*sse2_mfence"
5006   [(set (match_operand:BLK 0 "" "")
5007         (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
5008   "TARGET_SSE2"
5009   "mfence"
5010   [(set_attr "type" "sse")
5011    (set_attr "memory" "unknown")])
5012
5013 (define_expand "sse2_lfence"
5014   [(set (match_dup 0)
5015         (unspec:BLK [(match_dup 0)] UNSPEC_LFENCE))]
5016   "TARGET_SSE2"
5017 {
5018   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
5019   MEM_VOLATILE_P (operands[0]) = 1;
5020 })
5021
5022 (define_insn "*sse2_lfence"
5023   [(set (match_operand:BLK 0 "" "")
5024         (unspec:BLK [(match_dup 0)] UNSPEC_LFENCE))]
5025   "TARGET_SSE2"
5026   "lfence"
5027   [(set_attr "type" "sse")
5028    (set_attr "memory" "unknown")])
5029
5030 (define_insn "sse3_mwait"
5031   [(unspec_volatile [(match_operand:SI 0 "register_operand" "a")
5032                      (match_operand:SI 1 "register_operand" "c")]
5033                     UNSPECV_MWAIT)]
5034   "TARGET_SSE3"
5035 ;; 64bit version is "mwait %rax,%rcx". But only lower 32bits are used.
5036 ;; Since 32bit register operands are implicitly zero extended to 64bit,
5037 ;; we only need to set up 32bit registers.
5038   "mwait"
5039   [(set_attr "length" "3")])
5040
5041 (define_insn "sse3_monitor"
5042   [(unspec_volatile [(match_operand:SI 0 "register_operand" "a")
5043                      (match_operand:SI 1 "register_operand" "c")
5044                      (match_operand:SI 2 "register_operand" "d")]
5045                     UNSPECV_MONITOR)]
5046   "TARGET_SSE3 && !TARGET_64BIT"
5047   "monitor\t%0, %1, %2"
5048   [(set_attr "length" "3")])
5049
5050 (define_insn "sse3_monitor64"
5051   [(unspec_volatile [(match_operand:DI 0 "register_operand" "a")
5052                      (match_operand:SI 1 "register_operand" "c")
5053                      (match_operand:SI 2 "register_operand" "d")]
5054                     UNSPECV_MONITOR)]
5055   "TARGET_SSE3 && TARGET_64BIT"
5056 ;; 64bit version is "monitor %rax,%rcx,%rdx". But only lower 32bits in
5057 ;; RCX and RDX are used.  Since 32bit register operands are implicitly
5058 ;; zero extended to 64bit, we only need to set up 32bit registers.
5059   "monitor"
5060   [(set_attr "length" "3")])
5061
5062 ;; SSSE3
5063 (define_insn "ssse3_phaddwv8hi3"
5064   [(set (match_operand:V8HI 0 "register_operand" "=x")
5065         (vec_concat:V8HI
5066           (vec_concat:V4HI
5067             (vec_concat:V2HI
5068               (plus:HI
5069                 (vec_select:HI
5070                   (match_operand:V8HI 1 "register_operand" "0")
5071                   (parallel [(const_int 0)]))
5072                 (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
5073               (plus:HI
5074                 (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
5075                 (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
5076             (vec_concat:V2HI
5077               (plus:HI
5078                 (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
5079                 (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
5080               (plus:HI
5081                 (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
5082                 (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
5083           (vec_concat:V4HI
5084             (vec_concat:V2HI
5085               (plus:HI
5086                 (vec_select:HI
5087                   (match_operand:V8HI 2 "nonimmediate_operand" "xm")
5088                   (parallel [(const_int 0)]))
5089                 (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
5090               (plus:HI
5091                 (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
5092                 (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
5093             (vec_concat:V2HI
5094               (plus:HI
5095                 (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
5096                 (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
5097               (plus:HI
5098                 (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
5099                 (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))))]
5100   "TARGET_SSSE3"
5101   "phaddw\t{%2, %0|%0, %2}"
5102   [(set_attr "type" "sseiadd")
5103    (set_attr "prefix_data16" "1")
5104    (set_attr "prefix_extra" "1")
5105    (set_attr "mode" "TI")])
5106
5107 (define_insn "ssse3_phaddwv4hi3"
5108   [(set (match_operand:V4HI 0 "register_operand" "=y")
5109         (vec_concat:V4HI
5110           (vec_concat:V2HI
5111             (plus:HI
5112               (vec_select:HI
5113                 (match_operand:V4HI 1 "register_operand" "0")
5114                 (parallel [(const_int 0)]))
5115               (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
5116             (plus:HI
5117               (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
5118               (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
5119           (vec_concat:V2HI
5120             (plus:HI
5121               (vec_select:HI
5122                 (match_operand:V4HI 2 "nonimmediate_operand" "ym")
5123                 (parallel [(const_int 0)]))
5124               (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
5125             (plus:HI
5126               (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
5127               (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))))]
5128   "TARGET_SSSE3"
5129   "phaddw\t{%2, %0|%0, %2}"
5130   [(set_attr "type" "sseiadd")
5131    (set_attr "prefix_extra" "1")
5132    (set_attr "mode" "DI")])
5133
5134 (define_insn "ssse3_phadddv4si3"
5135   [(set (match_operand:V4SI 0 "register_operand" "=x")
5136         (vec_concat:V4SI
5137           (vec_concat:V2SI
5138             (plus:SI
5139               (vec_select:SI
5140                 (match_operand:V4SI 1 "register_operand" "0")
5141                 (parallel [(const_int 0)]))
5142               (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
5143             (plus:SI
5144               (vec_select:SI (match_dup 1) (parallel [(const_int 2)]))
5145               (vec_select:SI (match_dup 1) (parallel [(const_int 3)]))))
5146           (vec_concat:V2SI
5147             (plus:SI
5148               (vec_select:SI
5149                 (match_operand:V4SI 2 "nonimmediate_operand" "xm")
5150                 (parallel [(const_int 0)]))
5151               (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))
5152             (plus:SI
5153               (vec_select:SI (match_dup 2) (parallel [(const_int 2)]))
5154               (vec_select:SI (match_dup 2) (parallel [(const_int 3)]))))))]
5155   "TARGET_SSSE3"
5156   "phaddd\t{%2, %0|%0, %2}"
5157   [(set_attr "type" "sseiadd")
5158    (set_attr "prefix_data16" "1")
5159    (set_attr "prefix_extra" "1")
5160    (set_attr "mode" "TI")])
5161
5162 (define_insn "ssse3_phadddv2si3"
5163   [(set (match_operand:V2SI 0 "register_operand" "=y")
5164         (vec_concat:V2SI
5165           (plus:SI
5166             (vec_select:SI
5167               (match_operand:V2SI 1 "register_operand" "0")
5168               (parallel [(const_int 0)]))
5169             (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
5170           (plus:SI
5171             (vec_select:SI
5172               (match_operand:V2SI 2 "nonimmediate_operand" "ym")
5173               (parallel [(const_int 0)]))
5174             (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))))]
5175   "TARGET_SSSE3"
5176   "phaddd\t{%2, %0|%0, %2}"
5177   [(set_attr "type" "sseiadd")
5178    (set_attr "prefix_extra" "1")
5179    (set_attr "mode" "DI")])
5180
5181 (define_insn "ssse3_phaddswv8hi3"
5182   [(set (match_operand:V8HI 0 "register_operand" "=x")
5183         (vec_concat:V8HI
5184           (vec_concat:V4HI
5185             (vec_concat:V2HI
5186               (ss_plus:HI
5187                 (vec_select:HI
5188                   (match_operand:V8HI 1 "register_operand" "0")
5189                   (parallel [(const_int 0)]))
5190                 (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
5191               (ss_plus:HI
5192                 (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
5193                 (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
5194             (vec_concat:V2HI
5195               (ss_plus:HI
5196                 (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
5197                 (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
5198               (ss_plus:HI
5199                 (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
5200                 (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
5201           (vec_concat:V4HI
5202             (vec_concat:V2HI
5203               (ss_plus:HI
5204                 (vec_select:HI
5205                   (match_operand:V8HI 2 "nonimmediate_operand" "xm")
5206                   (parallel [(const_int 0)]))
5207                 (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
5208               (ss_plus:HI
5209                 (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
5210                 (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
5211             (vec_concat:V2HI
5212               (ss_plus:HI
5213                 (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
5214                 (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
5215               (ss_plus:HI
5216                 (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
5217                 (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))))]
5218   "TARGET_SSSE3"
5219   "phaddsw\t{%2, %0|%0, %2}"
5220   [(set_attr "type" "sseiadd")
5221    (set_attr "prefix_data16" "1")
5222    (set_attr "prefix_extra" "1")
5223    (set_attr "mode" "TI")])
5224
5225 (define_insn "ssse3_phaddswv4hi3"
5226   [(set (match_operand:V4HI 0 "register_operand" "=y")
5227         (vec_concat:V4HI
5228           (vec_concat:V2HI
5229             (ss_plus:HI
5230               (vec_select:HI
5231                 (match_operand:V4HI 1 "register_operand" "0")
5232                 (parallel [(const_int 0)]))
5233               (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
5234             (ss_plus:HI
5235               (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
5236               (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
5237           (vec_concat:V2HI
5238             (ss_plus:HI
5239               (vec_select:HI
5240                 (match_operand:V4HI 2 "nonimmediate_operand" "ym")
5241                 (parallel [(const_int 0)]))
5242               (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
5243             (ss_plus:HI
5244               (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
5245               (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))))]
5246   "TARGET_SSSE3"
5247   "phaddsw\t{%2, %0|%0, %2}"
5248   [(set_attr "type" "sseiadd")
5249    (set_attr "prefix_extra" "1")
5250    (set_attr "mode" "DI")])
5251
5252 (define_insn "ssse3_phsubwv8hi3"
5253   [(set (match_operand:V8HI 0 "register_operand" "=x")
5254         (vec_concat:V8HI
5255           (vec_concat:V4HI
5256             (vec_concat:V2HI
5257               (minus:HI
5258                 (vec_select:HI
5259                   (match_operand:V8HI 1 "register_operand" "0")
5260                   (parallel [(const_int 0)]))
5261                 (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
5262               (minus:HI
5263                 (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
5264                 (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
5265             (vec_concat:V2HI
5266               (minus:HI
5267                 (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
5268                 (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
5269               (minus:HI
5270                 (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
5271                 (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
5272           (vec_concat:V4HI
5273             (vec_concat:V2HI
5274               (minus:HI
5275                 (vec_select:HI
5276                   (match_operand:V8HI 2 "nonimmediate_operand" "xm")
5277                   (parallel [(const_int 0)]))
5278                 (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
5279               (minus:HI
5280                 (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
5281                 (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
5282             (vec_concat:V2HI
5283               (minus:HI
5284                 (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
5285                 (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
5286               (minus:HI
5287                 (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
5288                 (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))))]
5289   "TARGET_SSSE3"
5290   "phsubw\t{%2, %0|%0, %2}"
5291   [(set_attr "type" "sseiadd")
5292    (set_attr "prefix_data16" "1")
5293    (set_attr "prefix_extra" "1")
5294    (set_attr "mode" "TI")])
5295
5296 (define_insn "ssse3_phsubwv4hi3"
5297   [(set (match_operand:V4HI 0 "register_operand" "=y")
5298         (vec_concat:V4HI
5299           (vec_concat:V2HI
5300             (minus:HI
5301               (vec_select:HI
5302                 (match_operand:V4HI 1 "register_operand" "0")
5303                 (parallel [(const_int 0)]))
5304               (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
5305             (minus:HI
5306               (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
5307               (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
5308           (vec_concat:V2HI
5309             (minus:HI
5310               (vec_select:HI
5311                 (match_operand:V4HI 2 "nonimmediate_operand" "ym")
5312                 (parallel [(const_int 0)]))
5313               (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
5314             (minus:HI
5315               (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
5316               (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))))]
5317   "TARGET_SSSE3"
5318   "phsubw\t{%2, %0|%0, %2}"
5319   [(set_attr "type" "sseiadd")
5320    (set_attr "prefix_extra" "1")
5321    (set_attr "mode" "DI")])
5322
5323 (define_insn "ssse3_phsubdv4si3"
5324   [(set (match_operand:V4SI 0 "register_operand" "=x")
5325         (vec_concat:V4SI
5326           (vec_concat:V2SI
5327             (minus:SI
5328               (vec_select:SI
5329                 (match_operand:V4SI 1 "register_operand" "0")
5330                 (parallel [(const_int 0)]))
5331               (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
5332             (minus:SI
5333               (vec_select:SI (match_dup 1) (parallel [(const_int 2)]))
5334               (vec_select:SI (match_dup 1) (parallel [(const_int 3)]))))
5335           (vec_concat:V2SI
5336             (minus:SI
5337               (vec_select:SI
5338                 (match_operand:V4SI 2 "nonimmediate_operand" "xm")
5339                 (parallel [(const_int 0)]))
5340               (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))
5341             (minus:SI
5342               (vec_select:SI (match_dup 2) (parallel [(const_int 2)]))
5343               (vec_select:SI (match_dup 2) (parallel [(const_int 3)]))))))]
5344   "TARGET_SSSE3"
5345   "phsubd\t{%2, %0|%0, %2}"
5346   [(set_attr "type" "sseiadd")
5347    (set_attr "prefix_data16" "1")
5348    (set_attr "prefix_extra" "1")
5349    (set_attr "mode" "TI")])
5350
5351 (define_insn "ssse3_phsubdv2si3"
5352   [(set (match_operand:V2SI 0 "register_operand" "=y")
5353         (vec_concat:V2SI
5354           (minus:SI
5355             (vec_select:SI
5356               (match_operand:V2SI 1 "register_operand" "0")
5357               (parallel [(const_int 0)]))
5358             (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
5359           (minus:SI
5360             (vec_select:SI
5361               (match_operand:V2SI 2 "nonimmediate_operand" "ym")
5362               (parallel [(const_int 0)]))
5363             (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))))]
5364   "TARGET_SSSE3"
5365   "phsubd\t{%2, %0|%0, %2}"
5366   [(set_attr "type" "sseiadd")
5367    (set_attr "prefix_extra" "1")
5368    (set_attr "mode" "DI")])
5369
5370 (define_insn "ssse3_phsubswv8hi3"
5371   [(set (match_operand:V8HI 0 "register_operand" "=x")
5372         (vec_concat:V8HI
5373           (vec_concat:V4HI
5374             (vec_concat:V2HI
5375               (ss_minus:HI
5376                 (vec_select:HI
5377                   (match_operand:V8HI 1 "register_operand" "0")
5378                   (parallel [(const_int 0)]))
5379                 (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
5380               (ss_minus:HI
5381                 (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
5382                 (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
5383             (vec_concat:V2HI
5384               (ss_minus:HI
5385                 (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
5386                 (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
5387               (ss_minus:HI
5388                 (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
5389                 (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
5390           (vec_concat:V4HI
5391             (vec_concat:V2HI
5392               (ss_minus:HI
5393                 (vec_select:HI
5394                   (match_operand:V8HI 2 "nonimmediate_operand" "xm")
5395                   (parallel [(const_int 0)]))
5396                 (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
5397               (ss_minus:HI
5398                 (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
5399                 (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
5400             (vec_concat:V2HI
5401               (ss_minus:HI
5402                 (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
5403                 (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
5404               (ss_minus:HI
5405                 (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
5406                 (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))))]
5407   "TARGET_SSSE3"
5408   "phsubsw\t{%2, %0|%0, %2}"
5409   [(set_attr "type" "sseiadd")
5410    (set_attr "prefix_data16" "1")
5411    (set_attr "prefix_extra" "1")
5412    (set_attr "mode" "TI")])
5413
5414 (define_insn "ssse3_phsubswv4hi3"
5415   [(set (match_operand:V4HI 0 "register_operand" "=y")
5416         (vec_concat:V4HI
5417           (vec_concat:V2HI
5418             (ss_minus:HI
5419               (vec_select:HI
5420                 (match_operand:V4HI 1 "register_operand" "0")
5421                 (parallel [(const_int 0)]))
5422               (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
5423             (ss_minus:HI
5424               (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
5425               (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
5426           (vec_concat:V2HI
5427             (ss_minus:HI
5428               (vec_select:HI
5429                 (match_operand:V4HI 2 "nonimmediate_operand" "ym")
5430                 (parallel [(const_int 0)]))
5431               (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
5432             (ss_minus:HI
5433               (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
5434               (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))))]
5435   "TARGET_SSSE3"
5436   "phsubsw\t{%2, %0|%0, %2}"
5437   [(set_attr "type" "sseiadd")
5438    (set_attr "prefix_extra" "1")
5439    (set_attr "mode" "DI")])
5440
5441 (define_insn "ssse3_pmaddubswv8hi3"
5442   [(set (match_operand:V8HI 0 "register_operand" "=x")
5443         (ss_plus:V8HI
5444           (mult:V8HI
5445             (zero_extend:V8HI
5446               (vec_select:V4QI
5447                 (match_operand:V16QI 1 "nonimmediate_operand" "%0")
5448                 (parallel [(const_int 0)
5449                            (const_int 2)
5450                            (const_int 4)
5451                            (const_int 6)
5452                            (const_int 8)
5453                            (const_int 10)
5454                            (const_int 12)
5455                            (const_int 14)])))
5456             (sign_extend:V8HI
5457               (vec_select:V8QI
5458                 (match_operand:V16QI 2 "nonimmediate_operand" "xm")
5459                 (parallel [(const_int 0)
5460                            (const_int 2)
5461                            (const_int 4)
5462                            (const_int 6)
5463                            (const_int 8)
5464                            (const_int 10)
5465                            (const_int 12)
5466                            (const_int 14)]))))
5467           (mult:V8HI
5468             (zero_extend:V8HI
5469               (vec_select:V16QI (match_dup 1)
5470                 (parallel [(const_int 1)
5471                            (const_int 3)
5472                            (const_int 5)
5473                            (const_int 7)
5474                            (const_int 9)
5475                            (const_int 11)
5476                            (const_int 13)
5477                            (const_int 15)])))
5478             (sign_extend:V8HI
5479               (vec_select:V16QI (match_dup 2)
5480                 (parallel [(const_int 1)
5481                            (const_int 3)
5482                            (const_int 5)
5483                            (const_int 7)
5484                            (const_int 9)
5485                            (const_int 11)
5486                            (const_int 13)
5487                            (const_int 15)]))))))]
5488   "TARGET_SSSE3"
5489   "pmaddubsw\t{%2, %0|%0, %2}"
5490   [(set_attr "type" "sseiadd")
5491    (set_attr "prefix_data16" "1")
5492    (set_attr "prefix_extra" "1")
5493    (set_attr "mode" "TI")])
5494
5495 (define_insn "ssse3_pmaddubswv4hi3"
5496   [(set (match_operand:V4HI 0 "register_operand" "=y")
5497         (ss_plus:V4HI
5498           (mult:V4HI
5499             (zero_extend:V4HI
5500               (vec_select:V4QI
5501                 (match_operand:V8QI 1 "nonimmediate_operand" "%0")
5502                 (parallel [(const_int 0)
5503                            (const_int 2)
5504                            (const_int 4)
5505                            (const_int 6)])))
5506             (sign_extend:V4HI
5507               (vec_select:V4QI
5508                 (match_operand:V8QI 2 "nonimmediate_operand" "ym")
5509                 (parallel [(const_int 0)
5510                            (const_int 2)
5511                            (const_int 4)
5512                            (const_int 6)]))))
5513           (mult:V4HI
5514             (zero_extend:V4HI
5515               (vec_select:V8QI (match_dup 1)
5516                 (parallel [(const_int 1)
5517                            (const_int 3)
5518                            (const_int 5)
5519                            (const_int 7)])))
5520             (sign_extend:V4HI
5521               (vec_select:V8QI (match_dup 2)
5522                 (parallel [(const_int 1)
5523                            (const_int 3)
5524                            (const_int 5)
5525                            (const_int 7)]))))))]
5526   "TARGET_SSSE3"
5527   "pmaddubsw\t{%2, %0|%0, %2}"
5528   [(set_attr "type" "sseiadd")
5529    (set_attr "prefix_extra" "1")
5530    (set_attr "mode" "DI")])
5531
5532 (define_insn "ssse3_pmulhrswv8hi3"
5533   [(set (match_operand:V8HI 0 "register_operand" "=x")
5534         (truncate:V8HI
5535           (lshiftrt:V8SI
5536             (plus:V8SI
5537               (lshiftrt:V8SI
5538                 (mult:V8SI
5539                   (sign_extend:V8SI
5540                     (match_operand:V8HI 1 "nonimmediate_operand" "%0"))
5541                   (sign_extend:V8SI
5542                     (match_operand:V8HI 2 "nonimmediate_operand" "xm")))
5543                 (const_int 14))
5544               (const_vector:V8HI [(const_int 1) (const_int 1)
5545                                   (const_int 1) (const_int 1)
5546                                   (const_int 1) (const_int 1)
5547                                   (const_int 1) (const_int 1)]))
5548             (const_int 1))))]
5549   "TARGET_SSSE3 && ix86_binary_operator_ok (MULT, V8HImode, operands)"
5550   "pmulhrsw\t{%2, %0|%0, %2}"
5551   [(set_attr "type" "sseimul")
5552    (set_attr "prefix_data16" "1")
5553    (set_attr "prefix_extra" "1")
5554    (set_attr "mode" "TI")])
5555
5556 (define_insn "ssse3_pmulhrswv4hi3"
5557   [(set (match_operand:V4HI 0 "register_operand" "=y")
5558         (truncate:V4HI
5559           (lshiftrt:V4SI
5560             (plus:V4SI
5561               (lshiftrt:V4SI
5562                 (mult:V4SI
5563                   (sign_extend:V4SI
5564                     (match_operand:V4HI 1 "nonimmediate_operand" "%0"))
5565                   (sign_extend:V4SI
5566                     (match_operand:V4HI 2 "nonimmediate_operand" "ym")))
5567                 (const_int 14))
5568               (const_vector:V4HI [(const_int 1) (const_int 1)
5569                                   (const_int 1) (const_int 1)]))
5570             (const_int 1))))]
5571   "TARGET_SSSE3 && ix86_binary_operator_ok (MULT, V4HImode, operands)"
5572   "pmulhrsw\t{%2, %0|%0, %2}"
5573   [(set_attr "type" "sseimul")
5574    (set_attr "prefix_extra" "1")
5575    (set_attr "mode" "DI")])
5576
5577 (define_insn "ssse3_pshufbv16qi3"
5578   [(set (match_operand:V16QI 0 "register_operand" "=x")
5579         (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "0")
5580                        (match_operand:V16QI 2 "nonimmediate_operand" "xm")]
5581                        UNSPEC_PSHUFB))]
5582   "TARGET_SSSE3"
5583   "pshufb\t{%2, %0|%0, %2}";
5584   [(set_attr "type" "sselog1")
5585    (set_attr "prefix_data16" "1")
5586    (set_attr "prefix_extra" "1")
5587    (set_attr "mode" "TI")])
5588
5589 (define_insn "ssse3_pshufbv8qi3"
5590   [(set (match_operand:V8QI 0 "register_operand" "=y")
5591         (unspec:V8QI [(match_operand:V8QI 1 "register_operand" "0")
5592                       (match_operand:V8QI 2 "nonimmediate_operand" "ym")]
5593                       UNSPEC_PSHUFB))]
5594   "TARGET_SSSE3"
5595   "pshufb\t{%2, %0|%0, %2}";
5596   [(set_attr "type" "sselog1")
5597    (set_attr "prefix_extra" "1")
5598    (set_attr "mode" "DI")])
5599
5600 (define_insn "ssse3_psign<mode>3"
5601   [(set (match_operand:SSEMODE124 0 "register_operand" "=x")
5602         (unspec:SSEMODE124 [(match_operand:SSEMODE124 1 "register_operand" "0")
5603                             (match_operand:SSEMODE124 2 "nonimmediate_operand" "xm")]
5604                             UNSPEC_PSIGN))]
5605   "TARGET_SSSE3"
5606   "psign<ssevecsize>\t{%2, %0|%0, %2}";
5607   [(set_attr "type" "sselog1")
5608    (set_attr "prefix_data16" "1")
5609    (set_attr "prefix_extra" "1")
5610    (set_attr "mode" "TI")])
5611
5612 (define_insn "ssse3_psign<mode>3"
5613   [(set (match_operand:MMXMODEI 0 "register_operand" "=y")
5614         (unspec:MMXMODEI [(match_operand:MMXMODEI 1 "register_operand" "0")
5615                           (match_operand:MMXMODEI 2 "nonimmediate_operand" "ym")]
5616                           UNSPEC_PSIGN))]
5617   "TARGET_SSSE3"
5618   "psign<mmxvecsize>\t{%2, %0|%0, %2}";
5619   [(set_attr "type" "sselog1")
5620    (set_attr "prefix_extra" "1")
5621    (set_attr "mode" "DI")])
5622
5623 (define_insn "ssse3_palignrti"
5624   [(set (match_operand:TI 0 "register_operand" "=x")
5625         (unspec:TI [(match_operand:TI 1 "register_operand" "0")
5626                     (match_operand:TI 2 "nonimmediate_operand" "xm")
5627                     (match_operand:SI 3 "const_0_to_255_mul_8_operand" "n")]
5628                     UNSPEC_PALIGNR))]
5629   "TARGET_SSSE3"
5630 {
5631   operands[3] = GEN_INT (INTVAL (operands[3]) / 8);
5632   return "palignr\t{%3, %2, %0|%0, %2, %3}";
5633 }
5634   [(set_attr "type" "sseishft")
5635    (set_attr "prefix_data16" "1")
5636    (set_attr "prefix_extra" "1")
5637    (set_attr "mode" "TI")])
5638
5639 (define_insn "ssse3_palignrdi"
5640   [(set (match_operand:DI 0 "register_operand" "=y")
5641         (unspec:DI [(match_operand:DI 1 "register_operand" "0")
5642                     (match_operand:DI 2 "nonimmediate_operand" "ym")
5643                     (match_operand:SI 3 "const_0_to_255_mul_8_operand" "n")]
5644                     UNSPEC_PALIGNR))]
5645   "TARGET_SSSE3"
5646 {
5647   operands[3] = GEN_INT (INTVAL (operands[3]) / 8);
5648   return "palignr\t{%3, %2, %0|%0, %2, %3}";
5649 }
5650   [(set_attr "type" "sseishft")
5651    (set_attr "prefix_extra" "1")
5652    (set_attr "mode" "DI")])
5653
5654 (define_insn "abs<mode>2"
5655   [(set (match_operand:SSEMODE124 0 "register_operand" "=x")
5656         (abs:SSEMODE124 (match_operand:SSEMODE124 1 "nonimmediate_operand" "xm")))]
5657   "TARGET_SSSE3"
5658   "pabs<ssevecsize>\t{%1, %0|%0, %1}";
5659   [(set_attr "type" "sselog1")
5660    (set_attr "prefix_data16" "1")
5661    (set_attr "prefix_extra" "1")
5662    (set_attr "mode" "TI")])
5663
5664 (define_insn "abs<mode>2"
5665   [(set (match_operand:MMXMODEI 0 "register_operand" "=y")
5666         (abs:MMXMODEI (match_operand:MMXMODEI 1 "nonimmediate_operand" "ym")))]
5667   "TARGET_SSSE3"
5668   "pabs<mmxvecsize>\t{%1, %0|%0, %1}";
5669   [(set_attr "type" "sselog1")
5670    (set_attr "prefix_extra" "1")
5671    (set_attr "mode" "DI")])
5672
5673 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5674 ;;
5675 ;; AMD SSE4A instructions
5676 ;;
5677 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5678
5679 (define_insn "sse4a_vmmovntv2df"
5680   [(set (match_operand:DF 0 "memory_operand" "=m")
5681         (unspec:DF [(vec_select:DF 
5682                       (match_operand:V2DF 1 "register_operand" "x")
5683                       (parallel [(const_int 0)]))]
5684                    UNSPEC_MOVNT))]
5685   "TARGET_SSE4A"
5686   "movntsd\t{%1, %0|%0, %1}"
5687   [(set_attr "type" "ssemov")
5688    (set_attr "mode" "DF")])
5689
5690 (define_insn "sse4a_movntdf"
5691   [(set (match_operand:DF 0 "memory_operand" "=m")
5692         (unspec:DF [(match_operand:DF 1 "register_operand" "x")]
5693                    UNSPEC_MOVNT))]
5694   "TARGET_SSE4A"
5695   "movntsd\t{%1, %0|%0, %1}"
5696   [(set_attr "type" "ssemov")
5697    (set_attr "mode" "DF")])
5698
5699 (define_insn "sse4a_vmmovntv4sf"
5700   [(set (match_operand:SF 0 "memory_operand" "=m")
5701         (unspec:SF [(vec_select:SF 
5702                       (match_operand:V4SF 1 "register_operand" "x")
5703                       (parallel [(const_int 0)]))]
5704                    UNSPEC_MOVNT))]
5705   "TARGET_SSE4A"
5706   "movntss\t{%1, %0|%0, %1}"
5707   [(set_attr "type" "ssemov")
5708    (set_attr "mode" "SF")])
5709
5710 (define_insn "sse4a_movntsf"
5711   [(set (match_operand:SF 0 "memory_operand" "=m")
5712         (unspec:SF [(match_operand:SF 1 "register_operand" "x")]
5713                    UNSPEC_MOVNT))]
5714   "TARGET_SSE4A"
5715   "movntss\t{%1, %0|%0, %1}"
5716   [(set_attr "type" "ssemov")
5717    (set_attr "mode" "SF")])
5718
5719 (define_insn "sse4a_extrqi"
5720   [(set (match_operand:V2DI 0 "register_operand" "=x")
5721         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
5722                       (match_operand 2 "const_int_operand" "")
5723                       (match_operand 3 "const_int_operand" "")]
5724                      UNSPEC_EXTRQI))]
5725   "TARGET_SSE4A"
5726   "extrq\t{%3, %2, %0|%0, %2, %3}"
5727   [(set_attr "type" "sse")
5728    (set_attr "prefix_data16" "1")
5729    (set_attr "mode" "TI")])
5730
5731 (define_insn "sse4a_extrq"
5732   [(set (match_operand:V2DI 0 "register_operand" "=x")
5733         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
5734                       (match_operand:V16QI 2 "register_operand" "x")]
5735                      UNSPEC_EXTRQ))]
5736   "TARGET_SSE4A"
5737   "extrq\t{%2, %0|%0, %2}"
5738   [(set_attr "type" "sse")
5739    (set_attr "prefix_data16" "1")
5740    (set_attr "mode" "TI")])
5741
5742 (define_insn "sse4a_insertqi"
5743   [(set (match_operand:V2DI 0 "register_operand" "=x")
5744         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
5745                       (match_operand:V2DI 2 "register_operand" "x")
5746                       (match_operand 3 "const_int_operand" "")
5747                       (match_operand 4 "const_int_operand" "")]
5748                      UNSPEC_INSERTQI))]
5749   "TARGET_SSE4A"
5750   "insertq\t{%4, %3, %2, %0|%0, %2, %3, %4}"
5751   [(set_attr "type" "sseins")
5752    (set_attr "prefix_rep" "1")
5753    (set_attr "mode" "TI")])
5754
5755 (define_insn "sse4a_insertq"
5756   [(set (match_operand:V2DI 0 "register_operand" "=x")
5757         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
5758                       (match_operand:V2DI 2 "register_operand" "x")]
5759                      UNSPEC_INSERTQ))]
5760   "TARGET_SSE4A"
5761   "insertq\t{%2, %0|%0, %2}"
5762   [(set_attr "type" "sseins")
5763    (set_attr "prefix_rep" "1")
5764    (set_attr "mode" "TI")])
5765
5766 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5767 ;;
5768 ;; Intel SSE4.1 instructions
5769 ;;
5770 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5771
5772 (define_insn "sse4_1_blendpd"
5773   [(set (match_operand:V2DF 0 "register_operand" "=x")
5774         (vec_merge:V2DF
5775           (match_operand:V2DF 2 "nonimmediate_operand" "xm")
5776           (match_operand:V2DF 1 "register_operand" "0")
5777           (match_operand:SI 3 "const_0_to_3_operand" "n")))]
5778   "TARGET_SSE4_1"
5779   "blendpd\t{%3, %2, %0|%0, %2, %3}"
5780   [(set_attr "type" "ssemov")
5781    (set_attr "prefix_extra" "1")
5782    (set_attr "mode" "V2DF")])
5783
5784 (define_insn "sse4_1_blendps"
5785   [(set (match_operand:V4SF 0 "register_operand" "=x")
5786         (vec_merge:V4SF
5787           (match_operand:V4SF 2 "nonimmediate_operand" "xm")
5788           (match_operand:V4SF 1 "register_operand" "0")
5789           (match_operand:SI 3 "const_0_to_15_operand" "n")))]
5790   "TARGET_SSE4_1"
5791   "blendps\t{%3, %2, %0|%0, %2, %3}"
5792   [(set_attr "type" "ssemov")
5793    (set_attr "prefix_extra" "1")
5794    (set_attr "mode" "V4SF")])
5795
5796 (define_insn "sse4_1_blendvpd"
5797   [(set (match_operand:V2DF 0 "register_operand" "=x")
5798         (unspec:V2DF [(match_operand:V2DF 1 "register_operand"  "0")
5799                       (match_operand:V2DF 2 "nonimmediate_operand" "xm")
5800                       (reg:V2DF 21)]
5801                      UNSPEC_BLENDV))]
5802   "TARGET_SSE4_1"
5803   "blendvpd\t{%%xmm0, %2, %0|%0, %2, %%xmm0}"
5804   [(set_attr "type" "ssemov")
5805    (set_attr "prefix_extra" "1")
5806    (set_attr "mode" "V2DF")])
5807
5808 (define_insn "sse4_1_blendvps"
5809   [(set (match_operand:V4SF 0 "register_operand" "=x")
5810         (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "0")
5811                       (match_operand:V4SF 2 "nonimmediate_operand" "xm")
5812                       (reg:V4SF 21)]
5813                      UNSPEC_BLENDV))]
5814   "TARGET_SSE4_1"
5815   "blendvps\t{%%xmm0, %2, %0|%0, %2, %%xmm0}"
5816   [(set_attr "type" "ssemov")
5817    (set_attr "prefix_extra" "1")
5818    (set_attr "mode" "V4SF")])
5819
5820 (define_insn "sse4_1_dppd"
5821   [(set (match_operand:V2DF 0 "register_operand" "=x")
5822         (unspec:V2DF [(match_operand:V2DF 1 "nonimmediate_operand" "%0")
5823                       (match_operand:V2DF 2 "nonimmediate_operand" "xm")
5824                       (match_operand:SI 3 "const_0_to_255_operand" "n")]
5825                       UNSPEC_DP))]
5826   "TARGET_SSE4_1"
5827   "dppd\t{%3, %2, %0|%0, %2, %3}"
5828   [(set_attr "type" "ssemul")
5829    (set_attr "prefix_extra" "1")
5830    (set_attr "mode" "V2DF")])
5831
5832 (define_insn "sse4_1_dpps"
5833   [(set (match_operand:V4SF 0 "register_operand" "=x")
5834         (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "%0")
5835                       (match_operand:V4SF 2 "nonimmediate_operand" "xm")
5836                       (match_operand:SI 3 "const_0_to_255_operand" "n")]
5837                      UNSPEC_DP))]
5838   "TARGET_SSE4_1"
5839   "dpps\t{%3, %2, %0|%0, %2, %3}"
5840   [(set_attr "type" "ssemul")
5841    (set_attr "prefix_extra" "1")
5842    (set_attr "mode" "V4SF")])
5843
5844 (define_insn "sse4_1_movntdqa"
5845   [(set (match_operand:V2DI 0 "register_operand" "=x")
5846         (unspec:V2DI [(match_operand:V2DI 1 "memory_operand" "m")]
5847                      UNSPEC_MOVNTDQA))]
5848   "TARGET_SSE4_1"
5849   "movntdqa\t{%1, %0|%0, %1}"
5850   [(set_attr "type" "ssecvt")
5851    (set_attr "prefix_extra" "1")
5852    (set_attr "mode" "TI")])
5853
5854 (define_insn "sse4_1_mpsadbw"
5855   [(set (match_operand:V16QI 0 "register_operand" "=x")
5856         (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "0")
5857                        (match_operand:V16QI 2 "nonimmediate_operand" "xm")
5858                        (match_operand:SI 3 "const_0_to_255_operand" "n")]
5859                       UNSPEC_MPSADBW))]
5860   "TARGET_SSE4_1"
5861   "mpsadbw\t{%3, %2, %0|%0, %2, %3}"
5862   [(set_attr "type" "sselog1")
5863    (set_attr "prefix_extra" "1")
5864    (set_attr "mode" "TI")])
5865
5866 (define_insn "sse4_1_packusdw"
5867   [(set (match_operand:V8HI 0 "register_operand" "=x")
5868         (vec_concat:V8HI
5869           (us_truncate:V4HI
5870             (match_operand:V4SI 1 "register_operand" "0"))
5871           (us_truncate:V4HI
5872             (match_operand:V4SI 2 "nonimmediate_operand" "xm"))))]
5873   "TARGET_SSE4_1"
5874   "packusdw\t{%2, %0|%0, %2}"
5875   [(set_attr "type" "sselog")
5876    (set_attr "prefix_extra" "1")
5877    (set_attr "mode" "TI")])
5878
5879 (define_insn "sse4_1_pblendvb"
5880   [(set (match_operand:V16QI 0 "register_operand" "=x")
5881         (unspec:V16QI [(match_operand:V16QI 1 "register_operand"  "0")
5882                        (match_operand:V16QI 2 "nonimmediate_operand" "xm")
5883                        (reg:V16QI 21)]
5884                       UNSPEC_BLENDV))]
5885   "TARGET_SSE4_1"
5886   "pblendvb\t{%%xmm0, %2, %0|%0, %2, %%xmm0}"
5887   [(set_attr "type" "ssemov")
5888    (set_attr "prefix_extra" "1")
5889    (set_attr "mode" "TI")])
5890
5891 (define_insn "sse4_1_pblendw"
5892   [(set (match_operand:V8HI 0 "register_operand" "=x")
5893         (vec_merge:V8HI
5894           (match_operand:V8HI 2 "nonimmediate_operand" "xm")
5895           (match_operand:V8HI 1 "register_operand" "0")
5896           (match_operand:SI 3 "const_0_to_255_operand" "n")))]
5897   "TARGET_SSE4_1"
5898   "pblendw\t{%3, %2, %0|%0, %2, %3}"
5899   [(set_attr "type" "ssemov")
5900    (set_attr "prefix_extra" "1")
5901    (set_attr "mode" "TI")])
5902
5903 (define_insn "sse4_1_phminposuw"
5904   [(set (match_operand:V8HI 0 "register_operand" "=x")
5905         (unspec:V8HI [(match_operand:V8HI 1 "nonimmediate_operand" "xm")]
5906                      UNSPEC_PHMINPOSUW))]
5907   "TARGET_SSE4_1"
5908   "phminposuw\t{%1, %0|%0, %1}"
5909   [(set_attr "type" "sselog1")
5910    (set_attr "prefix_extra" "1")
5911    (set_attr "mode" "TI")])
5912
5913 (define_insn "sse4_1_extendv8qiv8hi2"
5914   [(set (match_operand:V8HI 0 "register_operand" "=x")
5915         (sign_extend:V8HI
5916           (vec_select:V8QI
5917             (match_operand:V16QI 1 "register_operand" "x")
5918             (parallel [(const_int 0)
5919                        (const_int 1)
5920                        (const_int 2)
5921                        (const_int 3)
5922                        (const_int 4)
5923                        (const_int 5)
5924                        (const_int 6)
5925                        (const_int 7)]))))]
5926   "TARGET_SSE4_1"
5927   "pmovsxbw\t{%1, %0|%0, %1}"
5928   [(set_attr "type" "ssemov")
5929    (set_attr "prefix_extra" "1")
5930    (set_attr "mode" "TI")])
5931
5932 (define_insn "*sse4_1_extendv8qiv8hi2"
5933   [(set (match_operand:V8HI 0 "register_operand" "=x")
5934         (sign_extend:V8HI
5935           (vec_select:V8QI
5936             (vec_duplicate:V16QI
5937               (match_operand:V8QI 1 "nonimmediate_operand" "xm"))
5938             (parallel [(const_int 0)
5939                        (const_int 1)
5940                        (const_int 2)
5941                        (const_int 3)
5942                        (const_int 4)
5943                        (const_int 5)
5944                        (const_int 6)
5945                        (const_int 7)]))))]
5946   "TARGET_SSE4_1"
5947   "pmovsxbw\t{%1, %0|%0, %1}"
5948   [(set_attr "type" "ssemov")
5949    (set_attr "prefix_extra" "1")
5950    (set_attr "mode" "TI")])
5951
5952 (define_insn "sse4_1_extendv4qiv4si2"
5953   [(set (match_operand:V4SI 0 "register_operand" "=x")
5954         (sign_extend:V4SI
5955           (vec_select:V4QI
5956             (match_operand:V16QI 1 "register_operand" "x")
5957             (parallel [(const_int 0)
5958                        (const_int 1)
5959                        (const_int 2)
5960                        (const_int 3)]))))]
5961   "TARGET_SSE4_1"
5962   "pmovsxbd\t{%1, %0|%0, %1}"
5963   [(set_attr "type" "ssemov")
5964    (set_attr "prefix_extra" "1")
5965    (set_attr "mode" "TI")])
5966
5967 (define_insn "*sse4_1_extendv4qiv4si2"
5968   [(set (match_operand:V4SI 0 "register_operand" "=x")
5969         (sign_extend:V4SI
5970           (vec_select:V4QI
5971             (vec_duplicate:V16QI
5972               (match_operand:V4QI 1 "nonimmediate_operand" "xm"))
5973             (parallel [(const_int 0)
5974                        (const_int 1)
5975                        (const_int 2)
5976                        (const_int 3)]))))]
5977   "TARGET_SSE4_1"
5978   "pmovsxbd\t{%1, %0|%0, %1}"
5979   [(set_attr "type" "ssemov")
5980    (set_attr "prefix_extra" "1")
5981    (set_attr "mode" "TI")])
5982
5983 (define_insn "sse4_1_extendv2qiv2di2"
5984   [(set (match_operand:V2DI 0 "register_operand" "=x")
5985         (sign_extend:V2DI
5986           (vec_select:V2QI
5987             (match_operand:V16QI 1 "register_operand" "x")
5988             (parallel [(const_int 0)
5989                        (const_int 1)]))))]
5990   "TARGET_SSE4_1"
5991   "pmovsxbq\t{%1, %0|%0, %1}"
5992   [(set_attr "type" "ssemov")
5993    (set_attr "prefix_extra" "1")
5994    (set_attr "mode" "TI")])
5995
5996 (define_insn "*sse4_1_extendv2qiv2di2"
5997   [(set (match_operand:V2DI 0 "register_operand" "=x")
5998         (sign_extend:V2DI
5999           (vec_select:V2QI
6000             (vec_duplicate:V16QI
6001               (match_operand:V2QI 1 "nonimmediate_operand" "xm"))
6002             (parallel [(const_int 0)
6003                        (const_int 1)]))))]
6004   "TARGET_SSE4_1"
6005   "pmovsxbq\t{%1, %0|%0, %1}"
6006   [(set_attr "type" "ssemov")
6007    (set_attr "prefix_extra" "1")
6008    (set_attr "mode" "TI")])
6009
6010 (define_insn "sse4_1_extendv4hiv4si2"
6011   [(set (match_operand:V4SI 0 "register_operand" "=x")
6012         (sign_extend:V4SI
6013           (vec_select:V4HI
6014             (match_operand:V8HI 1 "register_operand" "x")
6015             (parallel [(const_int 0)
6016                        (const_int 1)
6017                        (const_int 2)
6018                        (const_int 3)]))))]
6019   "TARGET_SSE4_1"
6020   "pmovsxwd\t{%1, %0|%0, %1}"
6021   [(set_attr "type" "ssemov")
6022    (set_attr "prefix_extra" "1")
6023    (set_attr "mode" "TI")])
6024
6025 (define_insn "*sse4_1_extendv4hiv4si2"
6026   [(set (match_operand:V4SI 0 "register_operand" "=x")
6027         (sign_extend:V4SI
6028           (vec_select:V4HI
6029             (vec_duplicate:V8HI
6030               (match_operand:V2HI 1 "nonimmediate_operand" "xm"))
6031             (parallel [(const_int 0)
6032                        (const_int 1)
6033                        (const_int 2)
6034                        (const_int 3)]))))]
6035   "TARGET_SSE4_1"
6036   "pmovsxwd\t{%1, %0|%0, %1}"
6037   [(set_attr "type" "ssemov")
6038    (set_attr "prefix_extra" "1")
6039    (set_attr "mode" "TI")])
6040
6041 (define_insn "sse4_1_extendv2hiv2di2"
6042   [(set (match_operand:V2DI 0 "register_operand" "=x")
6043         (sign_extend:V2DI
6044           (vec_select:V2HI
6045             (match_operand:V8HI 1 "register_operand" "x")
6046             (parallel [(const_int 0)
6047                        (const_int 1)]))))]
6048   "TARGET_SSE4_1"
6049   "pmovsxwq\t{%1, %0|%0, %1}"
6050   [(set_attr "type" "ssemov")
6051    (set_attr "prefix_extra" "1")
6052    (set_attr "mode" "TI")])
6053
6054 (define_insn "*sse4_1_extendv2hiv2di2"
6055   [(set (match_operand:V2DI 0 "register_operand" "=x")
6056         (sign_extend:V2DI
6057           (vec_select:V2HI
6058             (vec_duplicate:V8HI
6059               (match_operand:V8HI 1 "nonimmediate_operand" "xm"))
6060             (parallel [(const_int 0)
6061                        (const_int 1)]))))]
6062   "TARGET_SSE4_1"
6063   "pmovsxwq\t{%1, %0|%0, %1}"
6064   [(set_attr "type" "ssemov")
6065    (set_attr "prefix_extra" "1")
6066    (set_attr "mode" "TI")])
6067
6068 (define_insn "sse4_1_extendv2siv2di2"
6069   [(set (match_operand:V2DI 0 "register_operand" "=x")
6070         (sign_extend:V2DI
6071           (vec_select:V2SI
6072             (match_operand:V4SI 1 "register_operand" "x")
6073             (parallel [(const_int 0)
6074                        (const_int 1)]))))]
6075   "TARGET_SSE4_1"
6076   "pmovsxdq\t{%1, %0|%0, %1}"
6077   [(set_attr "type" "ssemov")
6078    (set_attr "prefix_extra" "1")
6079    (set_attr "mode" "TI")])
6080
6081 (define_insn "*sse4_1_extendv2siv2di2"
6082   [(set (match_operand:V2DI 0 "register_operand" "=x")
6083         (sign_extend:V2DI
6084           (vec_select:V2SI
6085             (vec_duplicate:V4SI
6086               (match_operand:V2SI 1 "nonimmediate_operand" "xm"))
6087             (parallel [(const_int 0)
6088                        (const_int 1)]))))]
6089   "TARGET_SSE4_1"
6090   "pmovsxdq\t{%1, %0|%0, %1}"
6091   [(set_attr "type" "ssemov")
6092    (set_attr "prefix_extra" "1")
6093    (set_attr "mode" "TI")])
6094
6095 (define_insn "sse4_1_zero_extendv8qiv8hi2"
6096   [(set (match_operand:V8HI 0 "register_operand" "=x")
6097         (zero_extend:V8HI
6098           (vec_select:V8QI
6099             (match_operand:V16QI 1 "register_operand" "x")
6100             (parallel [(const_int 0)
6101                        (const_int 1)
6102                        (const_int 2)
6103                        (const_int 3)
6104                        (const_int 4)
6105                        (const_int 5)
6106                        (const_int 6)
6107                        (const_int 7)]))))]
6108   "TARGET_SSE4_1"
6109   "pmovzxbw\t{%1, %0|%0, %1}"
6110   [(set_attr "type" "ssemov")
6111    (set_attr "prefix_extra" "1")
6112    (set_attr "mode" "TI")])
6113
6114 (define_insn "*sse4_1_zero_extendv8qiv8hi2"
6115   [(set (match_operand:V8HI 0 "register_operand" "=x")
6116         (zero_extend:V8HI
6117           (vec_select:V8QI
6118             (vec_duplicate:V16QI
6119               (match_operand:V8QI 1 "nonimmediate_operand" "xm"))
6120             (parallel [(const_int 0)
6121                        (const_int 1)
6122                        (const_int 2)
6123                        (const_int 3)
6124                        (const_int 4)
6125                        (const_int 5)
6126                        (const_int 6)
6127                        (const_int 7)]))))]
6128   "TARGET_SSE4_1"
6129   "pmovzxbw\t{%1, %0|%0, %1}"
6130   [(set_attr "type" "ssemov")
6131    (set_attr "prefix_extra" "1")
6132    (set_attr "mode" "TI")])
6133
6134 (define_insn "sse4_1_zero_extendv4qiv4si2"
6135   [(set (match_operand:V4SI 0 "register_operand" "=x")
6136         (zero_extend:V4SI
6137           (vec_select:V4QI
6138             (match_operand:V16QI 1 "register_operand" "x")
6139             (parallel [(const_int 0)
6140                        (const_int 1)
6141                        (const_int 2)
6142                        (const_int 3)]))))]
6143   "TARGET_SSE4_1"
6144   "pmovzxbd\t{%1, %0|%0, %1}"
6145   [(set_attr "type" "ssemov")
6146    (set_attr "prefix_extra" "1")
6147    (set_attr "mode" "TI")])
6148
6149 (define_insn "*sse4_1_zero_extendv4qiv4si2"
6150   [(set (match_operand:V4SI 0 "register_operand" "=x")
6151         (zero_extend:V4SI
6152           (vec_select:V4QI
6153             (vec_duplicate:V16QI
6154               (match_operand:V4QI 1 "nonimmediate_operand" "xm"))
6155             (parallel [(const_int 0)
6156                        (const_int 1)
6157                        (const_int 2)
6158                        (const_int 3)]))))]
6159   "TARGET_SSE4_1"
6160   "pmovzxbd\t{%1, %0|%0, %1}"
6161   [(set_attr "type" "ssemov")
6162    (set_attr "prefix_extra" "1")
6163    (set_attr "mode" "TI")])
6164
6165 (define_insn "sse4_1_zero_extendv2qiv2di2"
6166   [(set (match_operand:V2DI 0 "register_operand" "=x")
6167         (zero_extend:V2DI
6168           (vec_select:V2QI
6169             (match_operand:V16QI 1 "register_operand" "x")
6170             (parallel [(const_int 0)
6171                        (const_int 1)]))))]
6172   "TARGET_SSE4_1"
6173   "pmovzxbq\t{%1, %0|%0, %1}"
6174   [(set_attr "type" "ssemov")
6175    (set_attr "prefix_extra" "1")
6176    (set_attr "mode" "TI")])
6177
6178 (define_insn "*sse4_1_zero_extendv2qiv2di2"
6179   [(set (match_operand:V2DI 0 "register_operand" "=x")
6180         (zero_extend:V2DI
6181           (vec_select:V2QI
6182             (vec_duplicate:V16QI
6183               (match_operand:V2QI 1 "nonimmediate_operand" "xm"))
6184             (parallel [(const_int 0)
6185                        (const_int 1)]))))]
6186   "TARGET_SSE4_1"
6187   "pmovzxbq\t{%1, %0|%0, %1}"
6188   [(set_attr "type" "ssemov")
6189    (set_attr "prefix_extra" "1")
6190    (set_attr "mode" "TI")])
6191
6192 (define_insn "sse4_1_zero_extendv4hiv4si2"
6193   [(set (match_operand:V4SI 0 "register_operand" "=x")
6194         (zero_extend:V4SI
6195           (vec_select:V4HI
6196             (match_operand:V8HI 1 "register_operand" "x")
6197             (parallel [(const_int 0)
6198                        (const_int 1)
6199                        (const_int 2)
6200                        (const_int 3)]))))]
6201   "TARGET_SSE4_1"
6202   "pmovzxwd\t{%1, %0|%0, %1}"
6203   [(set_attr "type" "ssemov")
6204    (set_attr "prefix_extra" "1")
6205    (set_attr "mode" "TI")])
6206
6207 (define_insn "*sse4_1_zero_extendv4hiv4si2"
6208   [(set (match_operand:V4SI 0 "register_operand" "=x")
6209         (zero_extend:V4SI
6210           (vec_select:V4HI
6211             (vec_duplicate:V8HI
6212               (match_operand:V4HI 1 "nonimmediate_operand" "xm"))
6213             (parallel [(const_int 0)
6214                        (const_int 1)
6215                        (const_int 2)
6216                        (const_int 3)]))))]
6217   "TARGET_SSE4_1"
6218   "pmovzxwd\t{%1, %0|%0, %1}"
6219   [(set_attr "type" "ssemov")
6220    (set_attr "prefix_extra" "1")
6221    (set_attr "mode" "TI")])
6222
6223 (define_insn "sse4_1_zero_extendv2hiv2di2"
6224   [(set (match_operand:V2DI 0 "register_operand" "=x")
6225         (zero_extend:V2DI
6226           (vec_select:V2HI
6227             (match_operand:V8HI 1 "register_operand" "x")
6228             (parallel [(const_int 0)
6229                        (const_int 1)]))))]
6230   "TARGET_SSE4_1"
6231   "pmovzxwq\t{%1, %0|%0, %1}"
6232   [(set_attr "type" "ssemov")
6233    (set_attr "prefix_extra" "1")
6234    (set_attr "mode" "TI")])
6235
6236 (define_insn "*sse4_1_zero_extendv2hiv2di2"
6237   [(set (match_operand:V2DI 0 "register_operand" "=x")
6238         (zero_extend:V2DI
6239           (vec_select:V2HI
6240             (vec_duplicate:V8HI
6241               (match_operand:V2HI 1 "nonimmediate_operand" "xm"))
6242             (parallel [(const_int 0)
6243                        (const_int 1)]))))]
6244   "TARGET_SSE4_1"
6245   "pmovzxwq\t{%1, %0|%0, %1}"
6246   [(set_attr "type" "ssemov")
6247    (set_attr "prefix_extra" "1")
6248    (set_attr "mode" "TI")])
6249
6250 (define_insn "sse4_1_zero_extendv2siv2di2"
6251   [(set (match_operand:V2DI 0 "register_operand" "=x")
6252         (zero_extend:V2DI
6253           (vec_select:V2SI
6254             (match_operand:V4SI 1 "register_operand" "x")
6255             (parallel [(const_int 0)
6256                        (const_int 1)]))))]
6257   "TARGET_SSE4_1"
6258   "pmovzxdq\t{%1, %0|%0, %1}"
6259   [(set_attr "type" "ssemov")
6260    (set_attr "prefix_extra" "1")
6261    (set_attr "mode" "TI")])
6262
6263 (define_insn "*sse4_1_zero_extendv2siv2di2"
6264   [(set (match_operand:V2DI 0 "register_operand" "=x")
6265         (zero_extend:V2DI
6266           (vec_select:V2SI
6267             (vec_duplicate:V4SI
6268               (match_operand:V2SI 1 "nonimmediate_operand" "xm"))
6269             (parallel [(const_int 0)
6270                        (const_int 1)]))))]
6271   "TARGET_SSE4_1"
6272   "pmovzxdq\t{%1, %0|%0, %1}"
6273   [(set_attr "type" "ssemov")
6274    (set_attr "prefix_extra" "1")
6275    (set_attr "mode" "TI")])
6276
6277 ;; ptest is very similar to comiss and ucomiss when setting FLAGS_REG.
6278 ;; But it is not a really compare instruction.
6279 (define_insn "sse4_1_ptest"
6280   [(set (reg:CC FLAGS_REG)
6281         (unspec:CC [(match_operand:V2DI 0 "register_operand" "x")
6282                     (match_operand:V2DI 1 "nonimmediate_operand" "xm")]
6283                    UNSPEC_PTEST))]
6284   "TARGET_SSE4_1"
6285   "ptest\t{%1, %0|%0, %1}"
6286   [(set_attr "type" "ssecomi")
6287    (set_attr "prefix_extra" "1")
6288    (set_attr "mode" "TI")])
6289
6290 (define_insn "sse4_1_roundpd"
6291   [(set (match_operand:V2DF 0 "register_operand" "=x")
6292         (unspec:V2DF [(match_operand:V2DF 1 "nonimmediate_operand" "xm")
6293                       (match_operand:SI 2 "const_0_to_15_operand" "n")]
6294                      UNSPEC_ROUNDP))]
6295   "TARGET_SSE4_1"
6296   "roundpd\t{%2, %1, %0|%0, %1, %2}"
6297   [(set_attr "type" "ssecvt")
6298    (set_attr "prefix_extra" "1")
6299    (set_attr "mode" "V2DF")])
6300
6301 (define_insn "sse4_1_roundps"
6302   [(set (match_operand:V4SF 0 "register_operand" "=x")
6303         (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "xm")
6304                       (match_operand:SI 2 "const_0_to_15_operand" "n")]
6305                      UNSPEC_ROUNDP))]
6306   "TARGET_SSE4_1"
6307   "roundps\t{%2, %1, %0|%0, %1, %2}"
6308   [(set_attr "type" "ssecvt")
6309    (set_attr "prefix_extra" "1")
6310    (set_attr "mode" "V4SF")])
6311
6312 (define_insn "sse4_1_roundsd"
6313   [(set (match_operand:V2DF 0 "register_operand" "=x")
6314         (vec_merge:V2DF
6315           (unspec:V2DF [(match_operand:V2DF 2 "register_operand" "x")
6316                         (match_operand:SI 3 "const_0_to_15_operand" "n")]
6317                        UNSPEC_ROUNDS)
6318           (match_operand:V2DF 1 "register_operand" "0")
6319           (const_int 1)))]
6320   "TARGET_SSE4_1"
6321   "roundsd\t{%3, %2, %0|%0, %2, %3}"
6322   [(set_attr "type" "ssecvt")
6323    (set_attr "prefix_extra" "1")
6324    (set_attr "mode" "V2DF")])
6325
6326 (define_insn "sse4_1_roundss"
6327   [(set (match_operand:V4SF 0 "register_operand" "=x")
6328         (vec_merge:V4SF
6329           (unspec:V4SF [(match_operand:V4SF 2 "register_operand" "x")
6330                         (match_operand:SI 3 "const_0_to_15_operand" "n")]
6331                        UNSPEC_ROUNDS)
6332           (match_operand:V4SF 1 "register_operand" "0")
6333           (const_int 1)))]
6334   "TARGET_SSE4_1"
6335   "roundss\t{%3, %2, %0|%0, %2, %3}"
6336   [(set_attr "type" "ssecvt")
6337    (set_attr "prefix_extra" "1")
6338    (set_attr "mode" "V4SF")])