OSDN Git Service

* config/i386/i386.md (lshlv16qi3): Remove expander.
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / sse.md
1 ;; GCC machine description for SSE instructions
2 ;; Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
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 3, 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 COPYING3.  If not see
19 ;; <http://www.gnu.org/licenses/>.
20
21 ;; All vector modes including V?TImode, used in move patterns.
22 (define_mode_iterator V16
23   [(V32QI "TARGET_AVX") V16QI
24    (V16HI "TARGET_AVX") V8HI
25    (V8SI "TARGET_AVX") V4SI
26    (V4DI "TARGET_AVX") V2DI
27    (V2TI "TARGET_AVX") V1TI
28    (V8SF "TARGET_AVX") V4SF
29    (V4DF "TARGET_AVX") V2DF])
30
31 ;; All vector modes
32 (define_mode_iterator V
33   [(V32QI "TARGET_AVX") V16QI
34    (V16HI "TARGET_AVX") V8HI
35    (V8SI "TARGET_AVX") V4SI
36    (V4DI "TARGET_AVX") V2DI
37    (V8SF "TARGET_AVX") V4SF
38    (V4DF "TARGET_AVX") (V2DF "TARGET_SSE2")])
39
40 ;; All 128bit vector modes
41 (define_mode_iterator V_128
42   [V16QI V8HI V4SI V2DI V4SF (V2DF "TARGET_SSE2")])
43
44 ;; All 256bit vector modes
45 (define_mode_iterator V_256
46   [V32QI V16HI V8SI V4DI V8SF V4DF])
47
48 ;; All vector float modes
49 (define_mode_iterator VF
50   [(V8SF "TARGET_AVX") V4SF
51    (V4DF "TARGET_AVX") (V2DF "TARGET_SSE2")])
52
53 ;; All SFmode vector float modes
54 (define_mode_iterator VF1
55   [(V8SF "TARGET_AVX") V4SF])
56
57 ;; All DFmode vector float modes
58 (define_mode_iterator VF2
59   [(V4DF "TARGET_AVX") V2DF])
60
61 ;; All 128bit vector float modes
62 (define_mode_iterator VF_128
63   [V4SF (V2DF "TARGET_SSE2")])
64
65 ;; All 256bit vector float modes
66 (define_mode_iterator VF_256
67   [V8SF V4DF])
68
69 ;; All vector integer modes
70 (define_mode_iterator VI
71   [(V32QI "TARGET_AVX") V16QI
72    (V16HI "TARGET_AVX") V8HI
73    (V8SI "TARGET_AVX") V4SI
74    (V4DI "TARGET_AVX") V2DI])
75
76 (define_mode_iterator VI_AVX2
77   [(V32QI "TARGET_AVX2") V16QI
78    (V16HI "TARGET_AVX2") V8HI
79    (V8SI "TARGET_AVX2") V4SI
80    (V4DI "TARGET_AVX2") V2DI])
81
82 ;; All QImode vector integer modes
83 (define_mode_iterator VI1
84   [(V32QI "TARGET_AVX") V16QI])
85
86 ;; All DImode vector integer modes
87 (define_mode_iterator VI8
88   [(V4DI "TARGET_AVX") V2DI])
89
90 (define_mode_iterator VI1_AVX2
91   [(V32QI "TARGET_AVX2") V16QI])
92
93 (define_mode_iterator VI2_AVX2
94   [(V16HI "TARGET_AVX2") V8HI])
95
96 (define_mode_iterator VI4_AVX2
97   [(V8SI "TARGET_AVX2") V4SI])
98
99 (define_mode_iterator VI8_AVX2
100   [(V4DI "TARGET_AVX2") V2DI])
101
102 ;; ??? We should probably use TImode instead.
103 (define_mode_iterator VIMAX_AVX2
104   [(V2TI "TARGET_AVX2") V1TI])
105
106 ;; ??? This should probably be dropped in favor of VIMAX_AVX2.
107 (define_mode_iterator SSESCALARMODE
108   [(V2TI "TARGET_AVX2") TI])
109
110 (define_mode_iterator VI12_AVX2
111   [(V32QI "TARGET_AVX2") V16QI
112    (V16HI "TARGET_AVX2") V8HI])
113
114 (define_mode_iterator VI24_AVX2
115   [(V16HI "TARGET_AVX2") V8HI
116    (V8SI "TARGET_AVX2") V4SI])
117
118 (define_mode_iterator VI124_AVX2
119   [(V32QI "TARGET_AVX2") V16QI
120    (V16HI "TARGET_AVX2") V8HI
121    (V8SI "TARGET_AVX2") V4SI])
122
123 (define_mode_iterator VI248_AVX2
124   [(V16HI "TARGET_AVX2") V8HI
125    (V8SI "TARGET_AVX2") V4SI
126    (V4DI "TARGET_AVX2") V2DI])
127
128 (define_mode_iterator VI48_AVX2
129   [(V8SI "TARGET_AVX2") V4SI
130    (V4DI "TARGET_AVX2") V2DI])
131
132 (define_mode_iterator V48_AVX2
133   [V4SF V2DF
134    V8SF V4DF
135    (V4SI "TARGET_AVX2") (V2DI "TARGET_AVX2")
136    (V8SI "TARGET_AVX2") (V4DI "TARGET_AVX2")])
137
138 (define_mode_attr sse2_avx2
139   [(V16QI "sse2") (V32QI "avx2")
140    (V8HI "sse2") (V16HI "avx2")
141    (V4SI "sse2") (V8SI "avx2")
142    (V2DI "sse2") (V4DI "avx2")
143    (V1TI "sse2") (V2TI "avx2")])
144
145 (define_mode_attr ssse3_avx2
146    [(V16QI "ssse3") (V32QI "avx2")
147     (V8HI "ssse3") (V16HI "avx2")
148     (V4SI "ssse3") (V8SI "avx2")
149     (V2DI "ssse3") (V4DI "avx2")
150     (TI "ssse3") (V2TI "avx2")])
151
152 (define_mode_attr sse4_1_avx2
153    [(V16QI "sse4_1") (V32QI "avx2")
154     (V8HI "sse4_1") (V16HI "avx2")
155     (V4SI "sse4_1") (V8SI "avx2")
156     (V2DI "sse4_1") (V4DI "avx2")])
157
158 (define_mode_attr avx_avx2
159   [(V4SF "avx") (V2DF "avx")
160    (V8SF "avx") (V4DF "avx")
161    (V4SI "avx2") (V2DI "avx2")
162    (V8SI "avx2") (V4DI "avx2")])
163
164 (define_mode_attr vec_avx2
165   [(V16QI "vec") (V32QI "avx2")
166    (V8HI "vec") (V16HI "avx2")
167    (V4SI "vec") (V8SI "avx2")
168    (V2DI "vec") (V4DI "avx2")])
169
170 (define_mode_attr ssedoublemode
171   [(V16HI "V16SI") (V8HI "V8SI")])
172
173 (define_mode_attr ssebytemode
174   [(V4DI "V32QI") (V2DI "V16QI")])
175
176 ;; All 128bit vector integer modes
177 (define_mode_iterator VI_128 [V16QI V8HI V4SI V2DI])
178
179 ;; All 256bit vector integer modes
180 (define_mode_iterator VI_256 [V32QI V16HI V8SI V4DI])
181
182 ;; Random 128bit vector integer mode combinations
183 (define_mode_iterator VI12_128 [V16QI V8HI])
184 (define_mode_iterator VI14_128 [V16QI V4SI])
185 (define_mode_iterator VI124_128 [V16QI V8HI V4SI])
186 (define_mode_iterator VI128_128 [V16QI V8HI V2DI])
187 (define_mode_iterator VI24_128 [V8HI V4SI])
188 (define_mode_iterator VI248_128 [V8HI V4SI V2DI])
189 (define_mode_iterator VI48_128 [V4SI V2DI])
190
191 ;; Random 256bit vector integer mode combinations
192 (define_mode_iterator VI124_256 [V32QI V16HI V8SI])
193 (define_mode_iterator VI48_256 [V8SI V4DI])
194
195 ;; Int-float size matches
196 (define_mode_iterator VI4F_128 [V4SI V4SF])
197 (define_mode_iterator VI8F_128 [V2DI V2DF])
198 (define_mode_iterator VI4F_256 [V8SI V8SF])
199 (define_mode_iterator VI8F_256 [V4DI V4DF])
200
201 ;; Mapping from float mode to required SSE level
202 (define_mode_attr sse
203   [(SF "sse") (DF "sse2")
204    (V4SF "sse") (V2DF "sse2")
205    (V8SF "avx") (V4DF "avx")])
206
207 (define_mode_attr sse2
208   [(V16QI "sse2") (V32QI "avx")
209    (V2DI "sse2") (V4DI "avx")])
210
211 (define_mode_attr sse3
212   [(V16QI "sse3") (V32QI "avx")])
213
214 (define_mode_attr sse4_1
215   [(V4SF "sse4_1") (V2DF "sse4_1")
216    (V8SF "avx") (V4DF "avx")])
217
218 (define_mode_attr avxsizesuffix
219   [(V32QI "256") (V16HI "256") (V8SI "256") (V4DI "256")
220    (V16QI "") (V8HI "") (V4SI "") (V2DI "")
221    (V8SF "256") (V4DF "256")
222    (V4SF "") (V2DF "")])
223
224 ;; SSE instruction mode
225 (define_mode_attr sseinsnmode
226   [(V32QI "OI") (V16HI "OI") (V8SI "OI") (V4DI "OI") (V2TI "OI")
227    (V16QI "TI") (V8HI "TI") (V4SI "TI") (V2DI "TI") (V1TI "TI")
228    (V8SF "V8SF") (V4DF "V4DF")
229    (V4SF "V4SF") (V2DF "V2DF")
230    (TI "TI")])
231
232 ;; Mapping of vector float modes to an integer mode of the same size
233 (define_mode_attr sseintvecmode
234   [(V8SF "V8SI") (V4DF "V4DI")
235    (V4SF "V4SI") (V2DF "V2DI")
236    (V4DF "V4DI") (V8SF "V8SI")
237    (V8SI "V8SI") (V4DI "V4DI")
238    (V4SI "V4SI") (V2DI "V2DI")
239    (V16HI "V16HI") (V8HI "V8HI")
240    (V32QI "V32QI") (V16QI "V16QI")])
241
242 ;; Mapping of vector modes to a vector mode of double size
243 (define_mode_attr ssedoublevecmode
244   [(V32QI "V64QI") (V16HI "V32HI") (V8SI "V16SI") (V4DI "V8DI")
245    (V16QI "V32QI") (V8HI "V16HI") (V4SI "V8SI") (V2DI "V4DI")
246    (V8SF "V16SF") (V4DF "V8DF")
247    (V4SF "V8SF") (V2DF "V4DF")])
248
249 ;; Mapping of vector modes to a vector mode of half size
250 (define_mode_attr ssehalfvecmode
251   [(V32QI "V16QI") (V16HI "V8HI") (V8SI "V4SI") (V4DI "V2DI")
252    (V16QI  "V8QI") (V8HI  "V4HI") (V4SI "V2SI")
253    (V8SF "V4SF") (V4DF "V2DF")
254    (V4SF "V2SF")])
255
256 ;; Mapping of vector modes back to the scalar modes
257 (define_mode_attr ssescalarmode
258   [(V32QI "QI") (V16HI "HI") (V8SI "SI") (V4DI "DI")
259    (V16QI "QI") (V8HI "HI") (V4SI "SI") (V2DI "DI")
260    (V8SF "SF") (V4DF "DF")
261    (V4SF "SF") (V2DF "DF")])
262
263 ;; Number of scalar elements in each vector type
264 (define_mode_attr ssescalarnum
265   [(V32QI "32") (V16HI "16") (V8SI "8") (V4DI "4")
266    (V16QI "16") (V8HI "8") (V4SI "4") (V2DI "2")
267    (V8SF "8") (V4DF "4")
268    (V4SF "4") (V2DF "2")])
269
270 ;; SSE prefix for integer vector modes
271 (define_mode_attr sseintprefix
272   [(V2DI "p") (V2DF "")
273    (V4DI "p") (V4DF "")
274    (V4SI "p") (V4SF "")
275    (V8SI "p") (V8SF "")])
276
277 ;; SSE scalar suffix for vector modes
278 (define_mode_attr ssescalarmodesuffix
279   [(SF "ss") (DF "sd")
280    (V8SF "ss") (V4DF "sd")
281    (V4SF "ss") (V2DF "sd")
282    (V8SI "ss") (V4DI "sd")
283    (V4SI "d")])
284
285 ;; Pack/unpack vector modes
286 (define_mode_attr sseunpackmode
287   [(V16QI "V8HI") (V8HI "V4SI") (V4SI "V2DI")
288    (V32QI "V16HI") (V16HI "V8SI") (V8SI "V4DI")])
289
290 (define_mode_attr ssepackmode
291   [(V8HI "V16QI") (V4SI "V8HI") (V2DI "V4SI")
292    (V16HI "V32QI") (V8SI "V16HI") (V4DI "V8SI")])
293
294 ;; Mapping of the max integer size for xop rotate immediate constraint
295 (define_mode_attr sserotatemax
296   [(V16QI "7") (V8HI "15") (V4SI "31") (V2DI "63")])
297
298 ;; Mapping of mode to cast intrinsic name
299 (define_mode_attr castmode [(V8SI "si") (V8SF "ps") (V4DF "pd")])
300
301 ;; Instruction suffix for sign and zero extensions.
302 (define_code_attr extsuffix [(sign_extend "sx") (zero_extend "zx")])
303
304 ;; i128 for integer vectors and TARGET_AVX2, f128 otherwise.
305 (define_mode_attr i128
306   [(V8SF "f128") (V4DF "f128") (V32QI "%~128") (V16HI "%~128")
307    (V8SI "%~128") (V4DI "%~128")])
308
309 ;; Mix-n-match
310 (define_mode_iterator AVX256MODE2P [V8SI V8SF V4DF])
311
312 (define_mode_iterator AVXMODE48P_DI
313                       [V2DI V2DF V4DI V4DF V4SF V4SI])
314 (define_mode_attr AVXMODE48P_DI
315                       [(V2DI "V2DI") (V2DF "V2DI")
316                        (V4DI "V4DI") (V4DF "V4DI")
317                        (V4SI "V2DI") (V4SF "V2DI")
318                        (V8SI "V4DI") (V8SF "V4DI")])
319
320 (define_mode_iterator FMAMODE [SF DF V4SF V2DF V8SF V4DF])
321
322 ;; Mapping of immediate bits for blend instructions
323 (define_mode_attr blendbits
324   [(V8SF "255") (V4SF "15") (V4DF "15") (V2DF "3")])
325
326 ;; Patterns whose name begins with "sse{,2,3}_" are invoked by intrinsics.
327
328 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
329 ;;
330 ;; Move patterns
331 ;;
332 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
333
334 ;; All of these patterns are enabled for SSE1 as well as SSE2.
335 ;; This is essential for maintaining stable calling conventions.
336
337 (define_expand "mov<mode>"
338   [(set (match_operand:V16 0 "nonimmediate_operand" "")
339         (match_operand:V16 1 "nonimmediate_operand" ""))]
340   "TARGET_SSE"
341 {
342   ix86_expand_vector_move (<MODE>mode, operands);
343   DONE;
344 })
345
346 (define_insn "*mov<mode>_internal"
347   [(set (match_operand:V16 0 "nonimmediate_operand" "=x,x ,m")
348         (match_operand:V16 1 "nonimmediate_or_sse_const_operand"  "C ,xm,x"))]
349   "TARGET_SSE
350    && (register_operand (operands[0], <MODE>mode)
351        || register_operand (operands[1], <MODE>mode))"
352 {
353   switch (which_alternative)
354     {
355     case 0:
356       return standard_sse_constant_opcode (insn, operands[1]);
357     case 1:
358     case 2:
359       switch (get_attr_mode (insn))
360         {
361         case MODE_V8SF:
362         case MODE_V4SF:
363           if (TARGET_AVX
364               && (misaligned_operand (operands[0], <MODE>mode)
365                   || misaligned_operand (operands[1], <MODE>mode)))
366             return "vmovups\t{%1, %0|%0, %1}";
367           else
368             return "%vmovaps\t{%1, %0|%0, %1}";
369
370         case MODE_V4DF:
371         case MODE_V2DF:
372           if (TARGET_AVX
373               && (misaligned_operand (operands[0], <MODE>mode)
374                   || misaligned_operand (operands[1], <MODE>mode)))
375             return "vmovupd\t{%1, %0|%0, %1}";
376           else if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
377             return "%vmovaps\t{%1, %0|%0, %1}";
378           else
379             return "%vmovapd\t{%1, %0|%0, %1}";
380
381         case MODE_OI:
382         case MODE_TI:
383           if (TARGET_AVX
384               && (misaligned_operand (operands[0], <MODE>mode)
385                   || misaligned_operand (operands[1], <MODE>mode)))
386             return "vmovdqu\t{%1, %0|%0, %1}";
387           else if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
388             return "%vmovaps\t{%1, %0|%0, %1}";
389           else
390             return "%vmovdqa\t{%1, %0|%0, %1}";
391
392         default:
393           gcc_unreachable ();
394         }
395     default:
396       gcc_unreachable ();
397     }
398 }
399   [(set_attr "type" "sselog1,ssemov,ssemov")
400    (set_attr "prefix" "maybe_vex")
401    (set (attr "mode")
402         (cond [(match_test "TARGET_AVX")
403                  (const_string "<sseinsnmode>")
404                (ior (ior (match_test "optimize_function_for_size_p (cfun)")
405                          (not (match_test "TARGET_SSE2")))
406                     (and (eq_attr "alternative" "2")
407                          (match_test "TARGET_SSE_TYPELESS_STORES")))
408                  (const_string "V4SF")
409                (eq (const_string "<MODE>mode") (const_string "V4SFmode"))
410                  (const_string "V4SF")
411                (eq (const_string "<MODE>mode") (const_string "V2DFmode"))
412                  (const_string "V2DF")
413               ]
414           (const_string "TI")))])
415
416 (define_insn "sse2_movq128"
417   [(set (match_operand:V2DI 0 "register_operand" "=x")
418         (vec_concat:V2DI
419           (vec_select:DI
420             (match_operand:V2DI 1 "nonimmediate_operand" "xm")
421             (parallel [(const_int 0)]))
422           (const_int 0)))]
423   "TARGET_SSE2"
424   "%vmovq\t{%1, %0|%0, %1}"
425   [(set_attr "type" "ssemov")
426    (set_attr "prefix" "maybe_vex")
427    (set_attr "mode" "TI")])
428
429 ;; Move a DI from a 32-bit register pair (e.g. %edx:%eax) to an xmm.
430 ;; We'd rather avoid this entirely; if the 32-bit reg pair was loaded
431 ;; from memory, we'd prefer to load the memory directly into the %xmm
432 ;; register.  To facilitate this happy circumstance, this pattern won't
433 ;; split until after register allocation.  If the 64-bit value didn't
434 ;; come from memory, this is the best we can do.  This is much better
435 ;; than storing %edx:%eax into a stack temporary and loading an %xmm
436 ;; from there.
437
438 (define_insn_and_split "movdi_to_sse"
439   [(parallel
440     [(set (match_operand:V4SI 0 "register_operand" "=?x,x")
441           (subreg:V4SI (match_operand:DI 1 "nonimmediate_operand" "r,m") 0))
442      (clobber (match_scratch:V4SI 2 "=&x,X"))])]
443   "!TARGET_64BIT && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES"
444   "#"
445   "&& reload_completed"
446   [(const_int 0)]
447 {
448  if (register_operand (operands[1], DImode))
449    {
450       /* The DImode arrived in a pair of integral registers (e.g. %edx:%eax).
451          Assemble the 64-bit DImode value in an xmm register.  */
452       emit_insn (gen_sse2_loadld (operands[0], CONST0_RTX (V4SImode),
453                                   gen_rtx_SUBREG (SImode, operands[1], 0)));
454       emit_insn (gen_sse2_loadld (operands[2], CONST0_RTX (V4SImode),
455                                   gen_rtx_SUBREG (SImode, operands[1], 4)));
456       emit_insn (gen_vec_interleave_lowv4si (operands[0], operands[0],
457                                              operands[2]));
458     }
459  else if (memory_operand (operands[1], DImode))
460    emit_insn (gen_vec_concatv2di (gen_lowpart (V2DImode, operands[0]),
461                                   operands[1], const0_rtx));
462  else
463    gcc_unreachable ();
464 })
465
466 (define_split
467   [(set (match_operand:V4SF 0 "register_operand" "")
468         (match_operand:V4SF 1 "zero_extended_scalar_load_operand" ""))]
469   "TARGET_SSE && reload_completed"
470   [(set (match_dup 0)
471         (vec_merge:V4SF
472           (vec_duplicate:V4SF (match_dup 1))
473           (match_dup 2)
474           (const_int 1)))]
475 {
476   operands[1] = simplify_gen_subreg (SFmode, operands[1], V4SFmode, 0);
477   operands[2] = CONST0_RTX (V4SFmode);
478 })
479
480 (define_split
481   [(set (match_operand:V2DF 0 "register_operand" "")
482         (match_operand:V2DF 1 "zero_extended_scalar_load_operand" ""))]
483   "TARGET_SSE2 && reload_completed"
484   [(set (match_dup 0) (vec_concat:V2DF (match_dup 1) (match_dup 2)))]
485 {
486   operands[1] = simplify_gen_subreg (DFmode, operands[1], V2DFmode, 0);
487   operands[2] = CONST0_RTX (DFmode);
488 })
489
490 (define_expand "push<mode>1"
491   [(match_operand:V16 0 "register_operand" "")]
492   "TARGET_SSE"
493 {
494   ix86_expand_push (<MODE>mode, operands[0]);
495   DONE;
496 })
497
498 (define_expand "movmisalign<mode>"
499   [(set (match_operand:V16 0 "nonimmediate_operand" "")
500         (match_operand:V16 1 "nonimmediate_operand" ""))]
501   "TARGET_SSE"
502 {
503   ix86_expand_vector_move_misalign (<MODE>mode, operands);
504   DONE;
505 })
506
507 (define_expand "<sse>_movu<ssemodesuffix><avxsizesuffix>"
508   [(set (match_operand:VF 0 "nonimmediate_operand" "")
509         (unspec:VF
510           [(match_operand:VF 1 "nonimmediate_operand" "")]
511           UNSPEC_MOVU))]
512   "TARGET_SSE"
513 {
514   if (MEM_P (operands[0]) && MEM_P (operands[1]))
515     operands[1] = force_reg (<MODE>mode, operands[1]);
516 })
517
518 (define_insn "*<sse>_movu<ssemodesuffix><avxsizesuffix>"
519   [(set (match_operand:VF 0 "nonimmediate_operand" "=x,m")
520         (unspec:VF
521           [(match_operand:VF 1 "nonimmediate_operand" "xm,x")]
522           UNSPEC_MOVU))]
523   "TARGET_SSE && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
524   "%vmovu<ssemodesuffix>\t{%1, %0|%0, %1}"
525   [(set_attr "type" "ssemov")
526    (set_attr "movu" "1")
527    (set_attr "prefix" "maybe_vex")
528    (set_attr "mode" "<MODE>")])
529
530 (define_expand "<sse2>_movdqu<avxsizesuffix>"
531   [(set (match_operand:VI1 0 "nonimmediate_operand" "")
532         (unspec:VI1 [(match_operand:VI1 1 "nonimmediate_operand" "")]
533                     UNSPEC_MOVU))]
534   "TARGET_SSE2"
535 {
536   if (MEM_P (operands[0]) && MEM_P (operands[1]))
537     operands[1] = force_reg (<MODE>mode, operands[1]);
538 })
539
540 (define_insn "*<sse2>_movdqu<avxsizesuffix>"
541   [(set (match_operand:VI1 0 "nonimmediate_operand" "=x,m")
542         (unspec:VI1 [(match_operand:VI1 1 "nonimmediate_operand" "xm,x")]
543                     UNSPEC_MOVU))]
544   "TARGET_SSE2 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
545   "%vmovdqu\t{%1, %0|%0, %1}"
546   [(set_attr "type" "ssemov")
547    (set_attr "movu" "1")
548    (set (attr "prefix_data16")
549      (if_then_else
550        (match_test "TARGET_AVX")
551      (const_string "*")
552      (const_string "1")))
553    (set_attr "prefix" "maybe_vex")
554    (set_attr "mode" "<sseinsnmode>")])
555
556 (define_insn "<sse3>_lddqu<avxsizesuffix>"
557   [(set (match_operand:VI1 0 "register_operand" "=x")
558         (unspec:VI1 [(match_operand:VI1 1 "memory_operand" "m")]
559                     UNSPEC_LDDQU))]
560   "TARGET_SSE3"
561   "%vlddqu\t{%1, %0|%0, %1}"
562   [(set_attr "type" "ssemov")
563    (set_attr "movu" "1")
564    (set (attr "prefix_data16")
565      (if_then_else
566        (match_test "TARGET_AVX")
567      (const_string "*")
568      (const_string "0")))
569    (set (attr "prefix_rep")
570      (if_then_else
571        (match_test "TARGET_AVX")
572      (const_string "*")
573      (const_string "1")))
574    (set_attr "prefix" "maybe_vex")
575    (set_attr "mode" "<sseinsnmode>")])
576
577 (define_insn "sse2_movntsi"
578   [(set (match_operand:SI 0 "memory_operand" "=m")
579         (unspec:SI [(match_operand:SI 1 "register_operand" "r")]
580                    UNSPEC_MOVNT))]
581   "TARGET_SSE2"
582   "movnti\t{%1, %0|%0, %1}"
583   [(set_attr "type" "ssemov")
584    (set_attr "prefix_data16" "0")
585    (set_attr "mode" "V2DF")])
586
587 (define_insn "<sse>_movnt<mode>"
588   [(set (match_operand:VF 0 "memory_operand" "=m")
589         (unspec:VF [(match_operand:VF 1 "register_operand" "x")]
590                    UNSPEC_MOVNT))]
591   "TARGET_SSE"
592   "%vmovnt<ssemodesuffix>\t{%1, %0|%0, %1}"
593   [(set_attr "type" "ssemov")
594    (set_attr "prefix" "maybe_vex")
595    (set_attr "mode" "<MODE>")])
596
597 (define_insn "<sse2>_movnt<mode>"
598   [(set (match_operand:VI8 0 "memory_operand" "=m")
599         (unspec:VI8 [(match_operand:VI8 1 "register_operand" "x")]
600                     UNSPEC_MOVNT))]
601   "TARGET_SSE2"
602   "%vmovntdq\t{%1, %0|%0, %1}"
603   [(set_attr "type" "ssecvt")
604    (set (attr "prefix_data16")
605      (if_then_else
606        (match_test "TARGET_AVX")
607      (const_string "*")
608      (const_string "1")))
609    (set_attr "prefix" "maybe_vex")
610    (set_attr "mode" "<sseinsnmode>")])
611
612 ; Expand patterns for non-temporal stores.  At the moment, only those
613 ; that directly map to insns are defined; it would be possible to
614 ; define patterns for other modes that would expand to several insns.
615
616 ;; Modes handled by storent patterns.
617 (define_mode_iterator STORENT_MODE
618   [(SI "TARGET_SSE2") (SF "TARGET_SSE4A") (DF "TARGET_SSE4A")
619    (V2DI "TARGET_SSE2")
620    (V8SF "TARGET_AVX") V4SF
621    (V4DF "TARGET_AVX") (V2DF "TARGET_SSE2")])
622
623 (define_expand "storent<mode>"
624   [(set (match_operand:STORENT_MODE 0 "memory_operand" "")
625         (unspec:STORENT_MODE
626           [(match_operand:STORENT_MODE 1 "register_operand" "")]
627           UNSPEC_MOVNT))]
628   "TARGET_SSE")
629
630 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
631 ;;
632 ;; Parallel floating point arithmetic
633 ;;
634 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
635
636 (define_expand "<code><mode>2"
637   [(set (match_operand:VF 0 "register_operand" "")
638         (absneg:VF
639           (match_operand:VF 1 "register_operand" "")))]
640   "TARGET_SSE"
641   "ix86_expand_fp_absneg_operator (<CODE>, <MODE>mode, operands); DONE;")
642
643 (define_insn_and_split "*absneg<mode>2"
644   [(set (match_operand:VF 0 "register_operand" "=x,x,x,x")
645         (match_operator:VF 3 "absneg_operator"
646           [(match_operand:VF 1 "nonimmediate_operand" "0, xm,x, m")]))
647    (use (match_operand:VF 2 "nonimmediate_operand"    "xm,0, xm,x"))]
648   "TARGET_SSE"
649   "#"
650   "&& reload_completed"
651   [(const_int 0)]
652 {
653   enum rtx_code absneg_op;
654   rtx op1, op2;
655   rtx t;
656
657   if (TARGET_AVX)
658     {
659       if (MEM_P (operands[1]))
660         op1 = operands[2], op2 = operands[1];
661       else
662         op1 = operands[1], op2 = operands[2];
663     }
664   else
665     {
666       op1 = operands[0];
667       if (rtx_equal_p (operands[0], operands[1]))
668         op2 = operands[2];
669       else
670         op2 = operands[1];
671     }
672
673   absneg_op = GET_CODE (operands[3]) == NEG ? XOR : AND;
674   t = gen_rtx_fmt_ee (absneg_op, <MODE>mode, op1, op2);
675   t = gen_rtx_SET (VOIDmode, operands[0], t);
676   emit_insn (t);
677   DONE;
678 }
679   [(set_attr "isa" "noavx,noavx,avx,avx")])
680
681 (define_expand "<plusminus_insn><mode>3"
682   [(set (match_operand:VF 0 "register_operand" "")
683         (plusminus:VF
684           (match_operand:VF 1 "nonimmediate_operand" "")
685           (match_operand:VF 2 "nonimmediate_operand" "")))]
686   "TARGET_SSE"
687   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
688
689 (define_insn "*<plusminus_insn><mode>3"
690   [(set (match_operand:VF 0 "register_operand" "=x,x")
691         (plusminus:VF
692           (match_operand:VF 1 "nonimmediate_operand" "<comm>0,x")
693           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
694   "TARGET_SSE && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
695   "@
696    <plusminus_mnemonic><ssemodesuffix>\t{%2, %0|%0, %2}
697    v<plusminus_mnemonic><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
698   [(set_attr "isa" "noavx,avx")
699    (set_attr "type" "sseadd")
700    (set_attr "prefix" "orig,vex")
701    (set_attr "mode" "<MODE>")])
702
703 (define_insn "<sse>_vm<plusminus_insn><mode>3"
704   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
705         (vec_merge:VF_128
706           (plusminus:VF_128
707             (match_operand:VF_128 1 "register_operand" "0,x")
708             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm"))
709           (match_dup 1)
710           (const_int 1)))]
711   "TARGET_SSE"
712   "@
713    <plusminus_mnemonic><ssescalarmodesuffix>\t{%2, %0|%0, %2}
714    v<plusminus_mnemonic><ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
715   [(set_attr "isa" "noavx,avx")
716    (set_attr "type" "sseadd")
717    (set_attr "prefix" "orig,vex")
718    (set_attr "mode" "<ssescalarmode>")])
719
720 (define_expand "mul<mode>3"
721   [(set (match_operand:VF 0 "register_operand" "")
722         (mult:VF
723           (match_operand:VF 1 "nonimmediate_operand" "")
724           (match_operand:VF 2 "nonimmediate_operand" "")))]
725   "TARGET_SSE"
726   "ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);")
727
728 (define_insn "*mul<mode>3"
729   [(set (match_operand:VF 0 "register_operand" "=x,x")
730         (mult:VF
731           (match_operand:VF 1 "nonimmediate_operand" "%0,x")
732           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
733   "TARGET_SSE && ix86_binary_operator_ok (MULT, <MODE>mode, operands)"
734   "@
735    mul<ssemodesuffix>\t{%2, %0|%0, %2}
736    vmul<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
737   [(set_attr "isa" "noavx,avx")
738    (set_attr "type" "ssemul")
739    (set_attr "prefix" "orig,vex")
740    (set_attr "mode" "<MODE>")])
741
742 (define_insn "<sse>_vmmul<mode>3"
743   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
744         (vec_merge:VF_128
745           (mult:VF_128
746             (match_operand:VF_128 1 "register_operand" "0,x")
747             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm"))
748           (match_dup 1)
749           (const_int 1)))]
750   "TARGET_SSE"
751   "@
752    mul<ssescalarmodesuffix>\t{%2, %0|%0, %2}
753    vmul<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
754   [(set_attr "isa" "noavx,avx")
755    (set_attr "type" "ssemul")
756    (set_attr "prefix" "orig,vex")
757    (set_attr "mode" "<ssescalarmode>")])
758
759 (define_expand "div<mode>3"
760   [(set (match_operand:VF2 0 "register_operand" "")
761         (div:VF2 (match_operand:VF2 1 "register_operand" "")
762                  (match_operand:VF2 2 "nonimmediate_operand" "")))]
763   "TARGET_SSE2"
764   "ix86_fixup_binary_operands_no_copy (DIV, <MODE>mode, operands);")
765
766 (define_expand "div<mode>3"
767   [(set (match_operand:VF1 0 "register_operand" "")
768         (div:VF1 (match_operand:VF1 1 "register_operand" "")
769                  (match_operand:VF1 2 "nonimmediate_operand" "")))]
770   "TARGET_SSE"
771 {
772   ix86_fixup_binary_operands_no_copy (DIV, <MODE>mode, operands);
773
774   if (TARGET_SSE_MATH
775       && TARGET_RECIP_VEC_DIV
776       && !optimize_insn_for_size_p ()
777       && flag_finite_math_only && !flag_trapping_math
778       && flag_unsafe_math_optimizations)
779     {
780       ix86_emit_swdivsf (operands[0], operands[1], operands[2], <MODE>mode);
781       DONE;
782     }
783 })
784
785 (define_insn "<sse>_div<mode>3"
786   [(set (match_operand:VF 0 "register_operand" "=x,x")
787         (div:VF
788           (match_operand:VF 1 "register_operand" "0,x")
789           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
790   "TARGET_SSE"
791   "@
792    div<ssemodesuffix>\t{%2, %0|%0, %2}
793    vdiv<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
794   [(set_attr "isa" "noavx,avx")
795    (set_attr "type" "ssediv")
796    (set_attr "prefix" "orig,vex")
797    (set_attr "mode" "<MODE>")])
798
799 (define_insn "<sse>_vmdiv<mode>3"
800   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
801         (vec_merge:VF_128
802           (div:VF_128
803             (match_operand:VF_128 1 "register_operand" "0,x")
804             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm"))
805           (match_dup 1)
806           (const_int 1)))]
807   "TARGET_SSE"
808   "@
809    div<ssescalarmodesuffix>\t{%2, %0|%0, %2}
810    vdiv<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
811   [(set_attr "isa" "noavx,avx")
812    (set_attr "type" "ssediv")
813    (set_attr "prefix" "orig,vex")
814    (set_attr "mode" "<ssescalarmode>")])
815
816 (define_insn "<sse>_rcp<mode>2"
817   [(set (match_operand:VF1 0 "register_operand" "=x")
818         (unspec:VF1
819           [(match_operand:VF1 1 "nonimmediate_operand" "xm")] UNSPEC_RCP))]
820   "TARGET_SSE"
821   "%vrcpps\t{%1, %0|%0, %1}"
822   [(set_attr "type" "sse")
823    (set_attr "atom_sse_attr" "rcp")
824    (set_attr "prefix" "maybe_vex")
825    (set_attr "mode" "<MODE>")])
826
827 (define_insn "sse_vmrcpv4sf2"
828   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
829         (vec_merge:V4SF
830           (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "xm,xm")]
831                        UNSPEC_RCP)
832           (match_operand:V4SF 2 "register_operand" "0,x")
833           (const_int 1)))]
834   "TARGET_SSE"
835   "@
836    rcpss\t{%1, %0|%0, %1}
837    vrcpss\t{%1, %2, %0|%0, %2, %1}"
838   [(set_attr "isa" "noavx,avx")
839    (set_attr "type" "sse")
840    (set_attr "atom_sse_attr" "rcp")
841    (set_attr "prefix" "orig,vex")
842    (set_attr "mode" "SF")])
843
844 (define_expand "sqrt<mode>2"
845   [(set (match_operand:VF2 0 "register_operand" "")
846         (sqrt:VF2 (match_operand:VF2 1 "nonimmediate_operand" "")))]
847   "TARGET_SSE2")
848
849 (define_expand "sqrt<mode>2"
850   [(set (match_operand:VF1 0 "register_operand" "")
851         (sqrt:VF1 (match_operand:VF1 1 "nonimmediate_operand" "")))]
852   "TARGET_SSE"
853 {
854   if (TARGET_SSE_MATH
855       && TARGET_RECIP_VEC_SQRT
856       && !optimize_insn_for_size_p ()
857       && flag_finite_math_only && !flag_trapping_math
858       && flag_unsafe_math_optimizations)
859     {
860       ix86_emit_swsqrtsf (operands[0], operands[1], <MODE>mode, false);
861       DONE;
862     }
863 })
864
865 (define_insn "<sse>_sqrt<mode>2"
866   [(set (match_operand:VF 0 "register_operand" "=x")
867         (sqrt:VF (match_operand:VF 1 "nonimmediate_operand" "xm")))]
868   "TARGET_SSE"
869   "%vsqrt<ssemodesuffix>\t{%1, %0|%0, %1}"
870   [(set_attr "type" "sse")
871    (set_attr "atom_sse_attr" "sqrt")
872    (set_attr "prefix" "maybe_vex")
873    (set_attr "mode" "<MODE>")])
874
875 (define_insn "<sse>_vmsqrt<mode>2"
876   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
877         (vec_merge:VF_128
878           (sqrt:VF_128
879             (match_operand:VF_128 1 "nonimmediate_operand" "xm,xm"))
880           (match_operand:VF_128 2 "register_operand" "0,x")
881           (const_int 1)))]
882   "TARGET_SSE"
883   "@
884    sqrt<ssescalarmodesuffix>\t{%1, %0|%0, %1}
885    vsqrt<ssescalarmodesuffix>\t{%1, %2, %0|%0, %2, %1}"
886   [(set_attr "isa" "noavx,avx")
887    (set_attr "type" "sse")
888    (set_attr "atom_sse_attr" "sqrt")
889    (set_attr "prefix" "orig,vex")
890    (set_attr "mode" "<ssescalarmode>")])
891
892 (define_expand "rsqrt<mode>2"
893   [(set (match_operand:VF1 0 "register_operand" "")
894         (unspec:VF1
895           [(match_operand:VF1 1 "nonimmediate_operand" "")] UNSPEC_RSQRT))]
896   "TARGET_SSE_MATH"
897 {
898   ix86_emit_swsqrtsf (operands[0], operands[1], <MODE>mode, true);
899   DONE;
900 })
901
902 (define_insn "<sse>_rsqrt<mode>2"
903   [(set (match_operand:VF1 0 "register_operand" "=x")
904         (unspec:VF1
905           [(match_operand:VF1 1 "nonimmediate_operand" "xm")] UNSPEC_RSQRT))]
906   "TARGET_SSE"
907   "%vrsqrtps\t{%1, %0|%0, %1}"
908   [(set_attr "type" "sse")
909    (set_attr "prefix" "maybe_vex")
910    (set_attr "mode" "<MODE>")])
911
912 (define_insn "sse_vmrsqrtv4sf2"
913   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
914         (vec_merge:V4SF
915           (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "xm,xm")]
916                        UNSPEC_RSQRT)
917           (match_operand:V4SF 2 "register_operand" "0,x")
918           (const_int 1)))]
919   "TARGET_SSE"
920   "@
921    rsqrtss\t{%1, %0|%0, %1}
922    vrsqrtss\t{%1, %2, %0|%0, %2, %1}"
923   [(set_attr "isa" "noavx,avx")
924    (set_attr "type" "sse")
925    (set_attr "prefix" "orig,vex")
926    (set_attr "mode" "SF")])
927
928 ;; ??? For !flag_finite_math_only, the representation with SMIN/SMAX
929 ;; isn't really correct, as those rtl operators aren't defined when
930 ;; applied to NaNs.  Hopefully the optimizers won't get too smart on us.
931
932 (define_expand "<code><mode>3"
933   [(set (match_operand:VF 0 "register_operand" "")
934         (smaxmin:VF
935           (match_operand:VF 1 "nonimmediate_operand" "")
936           (match_operand:VF 2 "nonimmediate_operand" "")))]
937   "TARGET_SSE"
938 {
939   if (!flag_finite_math_only)
940     operands[1] = force_reg (<MODE>mode, operands[1]);
941   ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);
942 })
943
944 (define_insn "*<code><mode>3_finite"
945   [(set (match_operand:VF 0 "register_operand" "=x,x")
946         (smaxmin:VF
947           (match_operand:VF 1 "nonimmediate_operand" "%0,x")
948           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
949   "TARGET_SSE && flag_finite_math_only
950    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
951   "@
952    <maxmin_float><ssemodesuffix>\t{%2, %0|%0, %2}
953    v<maxmin_float><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
954   [(set_attr "isa" "noavx,avx")
955    (set_attr "type" "sseadd")
956    (set_attr "prefix" "orig,vex")
957    (set_attr "mode" "<MODE>")])
958
959 (define_insn "*<code><mode>3"
960   [(set (match_operand:VF 0 "register_operand" "=x,x")
961         (smaxmin:VF
962           (match_operand:VF 1 "register_operand" "0,x")
963           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
964   "TARGET_SSE && !flag_finite_math_only"
965   "@
966    <maxmin_float><ssemodesuffix>\t{%2, %0|%0, %2}
967    v<maxmin_float><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
968   [(set_attr "isa" "noavx,avx")
969    (set_attr "type" "sseadd")
970    (set_attr "prefix" "orig,vex")
971    (set_attr "mode" "<MODE>")])
972
973 (define_insn "<sse>_vm<code><mode>3"
974   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
975         (vec_merge:VF_128
976           (smaxmin:VF_128
977             (match_operand:VF_128 1 "register_operand" "0,x")
978             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm"))
979          (match_dup 1)
980          (const_int 1)))]
981   "TARGET_SSE"
982   "@
983    <maxmin_float><ssescalarmodesuffix>\t{%2, %0|%0, %2}
984    v<maxmin_float><ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
985   [(set_attr "isa" "noavx,avx")
986    (set_attr "type" "sse")
987    (set_attr "prefix" "orig,vex")
988    (set_attr "mode" "<ssescalarmode>")])
989
990 ;; These versions of the min/max patterns implement exactly the operations
991 ;;   min = (op1 < op2 ? op1 : op2)
992 ;;   max = (!(op1 < op2) ? op1 : op2)
993 ;; Their operands are not commutative, and thus they may be used in the
994 ;; presence of -0.0 and NaN.
995
996 (define_insn "*ieee_smin<mode>3"
997   [(set (match_operand:VF 0 "register_operand" "=x,x")
998         (unspec:VF
999           [(match_operand:VF 1 "register_operand" "0,x")
1000            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")]
1001          UNSPEC_IEEE_MIN))]
1002   "TARGET_SSE"
1003   "@
1004    min<ssemodesuffix>\t{%2, %0|%0, %2}
1005    vmin<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1006   [(set_attr "isa" "noavx,avx")
1007    (set_attr "type" "sseadd")
1008    (set_attr "prefix" "orig,vex")
1009    (set_attr "mode" "<MODE>")])
1010
1011 (define_insn "*ieee_smax<mode>3"
1012   [(set (match_operand:VF 0 "register_operand" "=x,x")
1013         (unspec:VF
1014           [(match_operand:VF 1 "register_operand" "0,x")
1015            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")]
1016          UNSPEC_IEEE_MAX))]
1017   "TARGET_SSE"
1018   "@
1019    max<ssemodesuffix>\t{%2, %0|%0, %2}
1020    vmax<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1021   [(set_attr "isa" "noavx,avx")
1022    (set_attr "type" "sseadd")
1023    (set_attr "prefix" "orig,vex")
1024    (set_attr "mode" "<MODE>")])
1025
1026 (define_insn "avx_addsubv4df3"
1027   [(set (match_operand:V4DF 0 "register_operand" "=x")
1028         (vec_merge:V4DF
1029           (plus:V4DF
1030             (match_operand:V4DF 1 "register_operand" "x")
1031             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
1032           (minus:V4DF (match_dup 1) (match_dup 2))
1033           (const_int 10)))]
1034   "TARGET_AVX"
1035   "vaddsubpd\t{%2, %1, %0|%0, %1, %2}"
1036   [(set_attr "type" "sseadd")
1037    (set_attr "prefix" "vex")
1038    (set_attr "mode" "V4DF")])
1039
1040 (define_insn "sse3_addsubv2df3"
1041   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
1042         (vec_merge:V2DF
1043           (plus:V2DF
1044             (match_operand:V2DF 1 "register_operand" "0,x")
1045             (match_operand:V2DF 2 "nonimmediate_operand" "xm,xm"))
1046           (minus:V2DF (match_dup 1) (match_dup 2))
1047           (const_int 2)))]
1048   "TARGET_SSE3"
1049   "@
1050    addsubpd\t{%2, %0|%0, %2}
1051    vaddsubpd\t{%2, %1, %0|%0, %1, %2}"
1052   [(set_attr "isa" "noavx,avx")
1053    (set_attr "type" "sseadd")
1054    (set_attr "atom_unit" "complex")
1055    (set_attr "prefix" "orig,vex")
1056    (set_attr "mode" "V2DF")])
1057
1058 (define_insn "avx_addsubv8sf3"
1059   [(set (match_operand:V8SF 0 "register_operand" "=x")
1060         (vec_merge:V8SF
1061           (plus:V8SF
1062             (match_operand:V8SF 1 "register_operand" "x")
1063             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
1064           (minus:V8SF (match_dup 1) (match_dup 2))
1065           (const_int 170)))]
1066   "TARGET_AVX"
1067   "vaddsubps\t{%2, %1, %0|%0, %1, %2}"
1068   [(set_attr "type" "sseadd")
1069    (set_attr "prefix" "vex")
1070    (set_attr "mode" "V8SF")])
1071
1072 (define_insn "sse3_addsubv4sf3"
1073   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
1074         (vec_merge:V4SF
1075           (plus:V4SF
1076             (match_operand:V4SF 1 "register_operand" "0,x")
1077             (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm"))
1078           (minus:V4SF (match_dup 1) (match_dup 2))
1079           (const_int 10)))]
1080   "TARGET_SSE3"
1081   "@
1082    addsubps\t{%2, %0|%0, %2}
1083    vaddsubps\t{%2, %1, %0|%0, %1, %2}"
1084   [(set_attr "isa" "noavx,avx")
1085    (set_attr "type" "sseadd")
1086    (set_attr "prefix" "orig,vex")
1087    (set_attr "prefix_rep" "1,*")
1088    (set_attr "mode" "V4SF")])
1089
1090 (define_insn "avx_h<plusminus_insn>v4df3"
1091   [(set (match_operand:V4DF 0 "register_operand" "=x")
1092         (vec_concat:V4DF
1093           (vec_concat:V2DF
1094             (plusminus:DF
1095               (vec_select:DF
1096                 (match_operand:V4DF 1 "register_operand" "x")
1097                 (parallel [(const_int 0)]))
1098               (vec_select:DF (match_dup 1) (parallel [(const_int 1)])))
1099             (plusminus:DF
1100               (vec_select:DF (match_dup 1) (parallel [(const_int 2)]))
1101               (vec_select:DF (match_dup 1) (parallel [(const_int 3)]))))
1102           (vec_concat:V2DF
1103             (plusminus:DF
1104               (vec_select:DF
1105                 (match_operand:V4DF 2 "nonimmediate_operand" "xm")
1106                 (parallel [(const_int 0)]))
1107               (vec_select:DF (match_dup 2) (parallel [(const_int 1)])))
1108             (plusminus:DF
1109               (vec_select:DF (match_dup 2) (parallel [(const_int 2)]))
1110               (vec_select:DF (match_dup 2) (parallel [(const_int 3)]))))))]
1111   "TARGET_AVX"
1112   "vh<plusminus_mnemonic>pd\t{%2, %1, %0|%0, %1, %2}"
1113   [(set_attr "type" "sseadd")
1114    (set_attr "prefix" "vex")
1115    (set_attr "mode" "V4DF")])
1116
1117 (define_insn "sse3_h<plusminus_insn>v2df3"
1118   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
1119         (vec_concat:V2DF
1120           (plusminus:DF
1121             (vec_select:DF
1122               (match_operand:V2DF 1 "register_operand" "0,x")
1123               (parallel [(const_int 0)]))
1124             (vec_select:DF (match_dup 1) (parallel [(const_int 1)])))
1125           (plusminus:DF
1126             (vec_select:DF
1127               (match_operand:V2DF 2 "nonimmediate_operand" "xm,xm")
1128               (parallel [(const_int 0)]))
1129             (vec_select:DF (match_dup 2) (parallel [(const_int 1)])))))]
1130   "TARGET_SSE3"
1131   "@
1132    h<plusminus_mnemonic>pd\t{%2, %0|%0, %2}
1133    vh<plusminus_mnemonic>pd\t{%2, %1, %0|%0, %1, %2}"
1134   [(set_attr "isa" "noavx,avx")
1135    (set_attr "type" "sseadd")
1136    (set_attr "prefix" "orig,vex")
1137    (set_attr "mode" "V2DF")])
1138
1139 (define_insn "avx_h<plusminus_insn>v8sf3"
1140   [(set (match_operand:V8SF 0 "register_operand" "=x")
1141         (vec_concat:V8SF
1142           (vec_concat:V4SF
1143             (vec_concat:V2SF
1144               (plusminus:SF
1145                 (vec_select:SF
1146                   (match_operand:V8SF 1 "register_operand" "x")
1147                   (parallel [(const_int 0)]))
1148                 (vec_select:SF (match_dup 1) (parallel [(const_int 1)])))
1149               (plusminus:SF
1150                 (vec_select:SF (match_dup 1) (parallel [(const_int 2)]))
1151                 (vec_select:SF (match_dup 1) (parallel [(const_int 3)]))))
1152             (vec_concat:V2SF
1153               (plusminus:SF
1154                 (vec_select:SF
1155                   (match_operand:V8SF 2 "nonimmediate_operand" "xm")
1156                   (parallel [(const_int 0)]))
1157                 (vec_select:SF (match_dup 2) (parallel [(const_int 1)])))
1158               (plusminus:SF
1159                 (vec_select:SF (match_dup 2) (parallel [(const_int 2)]))
1160                 (vec_select:SF (match_dup 2) (parallel [(const_int 3)])))))
1161           (vec_concat:V4SF
1162             (vec_concat:V2SF
1163               (plusminus:SF
1164                 (vec_select:SF (match_dup 1) (parallel [(const_int 4)]))
1165                 (vec_select:SF (match_dup 1) (parallel [(const_int 5)])))
1166               (plusminus:SF
1167                 (vec_select:SF (match_dup 1) (parallel [(const_int 6)]))
1168                 (vec_select:SF (match_dup 1) (parallel [(const_int 7)]))))
1169             (vec_concat:V2SF
1170               (plusminus:SF
1171                 (vec_select:SF (match_dup 2) (parallel [(const_int 4)]))
1172                 (vec_select:SF (match_dup 2) (parallel [(const_int 5)])))
1173               (plusminus:SF
1174                 (vec_select:SF (match_dup 2) (parallel [(const_int 6)]))
1175                 (vec_select:SF (match_dup 2) (parallel [(const_int 7)])))))))]
1176   "TARGET_AVX"
1177   "vh<plusminus_mnemonic>ps\t{%2, %1, %0|%0, %1, %2}"
1178   [(set_attr "type" "sseadd")
1179    (set_attr "prefix" "vex")
1180    (set_attr "mode" "V8SF")])
1181
1182 (define_insn "sse3_h<plusminus_insn>v4sf3"
1183   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
1184         (vec_concat:V4SF
1185           (vec_concat:V2SF
1186             (plusminus:SF
1187               (vec_select:SF
1188                 (match_operand:V4SF 1 "register_operand" "0,x")
1189                 (parallel [(const_int 0)]))
1190               (vec_select:SF (match_dup 1) (parallel [(const_int 1)])))
1191             (plusminus:SF
1192               (vec_select:SF (match_dup 1) (parallel [(const_int 2)]))
1193               (vec_select:SF (match_dup 1) (parallel [(const_int 3)]))))
1194           (vec_concat:V2SF
1195             (plusminus:SF
1196               (vec_select:SF
1197                 (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm")
1198                 (parallel [(const_int 0)]))
1199               (vec_select:SF (match_dup 2) (parallel [(const_int 1)])))
1200             (plusminus:SF
1201               (vec_select:SF (match_dup 2) (parallel [(const_int 2)]))
1202               (vec_select:SF (match_dup 2) (parallel [(const_int 3)]))))))]
1203   "TARGET_SSE3"
1204   "@
1205    h<plusminus_mnemonic>ps\t{%2, %0|%0, %2}
1206    vh<plusminus_mnemonic>ps\t{%2, %1, %0|%0, %1, %2}"
1207   [(set_attr "isa" "noavx,avx")
1208    (set_attr "type" "sseadd")
1209    (set_attr "atom_unit" "complex")
1210    (set_attr "prefix" "orig,vex")
1211    (set_attr "prefix_rep" "1,*")
1212    (set_attr "mode" "V4SF")])
1213
1214 (define_expand "reduc_splus_v4df"
1215   [(match_operand:V4DF 0 "register_operand" "")
1216    (match_operand:V4DF 1 "register_operand" "")]
1217   "TARGET_AVX"
1218 {
1219   rtx tmp = gen_reg_rtx (V4DFmode);
1220   rtx tmp2 = gen_reg_rtx (V4DFmode);
1221   emit_insn (gen_avx_haddv4df3 (tmp, operands[1], operands[1]));
1222   emit_insn (gen_avx_vperm2f128v4df3 (tmp2, tmp, tmp, GEN_INT (1)));
1223   emit_insn (gen_addv4df3 (operands[0], tmp, tmp2));
1224   DONE;
1225 })
1226
1227 (define_expand "reduc_splus_v2df"
1228   [(match_operand:V2DF 0 "register_operand" "")
1229    (match_operand:V2DF 1 "register_operand" "")]
1230   "TARGET_SSE3"
1231 {
1232   emit_insn (gen_sse3_haddv2df3 (operands[0], operands[1], operands[1]));
1233   DONE;
1234 })
1235
1236 (define_expand "reduc_splus_v8sf"
1237   [(match_operand:V8SF 0 "register_operand" "")
1238    (match_operand:V8SF 1 "register_operand" "")]
1239   "TARGET_AVX"
1240 {
1241   rtx tmp = gen_reg_rtx (V8SFmode);
1242   rtx tmp2 = gen_reg_rtx (V8SFmode);
1243   emit_insn (gen_avx_haddv8sf3 (tmp, operands[1], operands[1]));
1244   emit_insn (gen_avx_haddv8sf3 (tmp2, tmp, tmp));
1245   emit_insn (gen_avx_vperm2f128v8sf3 (tmp, tmp2, tmp2, GEN_INT (1)));
1246   emit_insn (gen_addv8sf3 (operands[0], tmp, tmp2));
1247   DONE;
1248 })
1249
1250 (define_expand "reduc_splus_v4sf"
1251   [(match_operand:V4SF 0 "register_operand" "")
1252    (match_operand:V4SF 1 "register_operand" "")]
1253   "TARGET_SSE"
1254 {
1255   if (TARGET_SSE3)
1256     {
1257       rtx tmp = gen_reg_rtx (V4SFmode);
1258       emit_insn (gen_sse3_haddv4sf3 (tmp, operands[1], operands[1]));
1259       emit_insn (gen_sse3_haddv4sf3 (operands[0], tmp, tmp));
1260     }
1261   else
1262     ix86_expand_reduc (gen_addv4sf3, operands[0], operands[1]);
1263   DONE;
1264 })
1265
1266 ;; Modes handled by reduc_sm{in,ax}* patterns.
1267 (define_mode_iterator REDUC_SMINMAX_MODE
1268   [(V32QI "TARGET_AVX2") (V16HI "TARGET_AVX2")
1269    (V8SI "TARGET_AVX2") (V4DI "TARGET_AVX2")
1270    (V8SF "TARGET_AVX") (V4DF "TARGET_AVX")
1271    (V4SF "TARGET_SSE")])
1272
1273 (define_expand "reduc_<code>_<mode>"
1274   [(smaxmin:REDUC_SMINMAX_MODE
1275      (match_operand:REDUC_SMINMAX_MODE 0 "register_operand" "")
1276      (match_operand:REDUC_SMINMAX_MODE 1 "register_operand" ""))]
1277   ""
1278 {
1279   ix86_expand_reduc (gen_<code><mode>3, operands[0], operands[1]);
1280   DONE;
1281 })
1282
1283 (define_expand "reduc_<code>_<mode>"
1284   [(umaxmin:VI_256
1285      (match_operand:VI_256 0 "register_operand" "")
1286      (match_operand:VI_256 1 "register_operand" ""))]
1287   "TARGET_AVX2"
1288 {
1289   ix86_expand_reduc (gen_<code><mode>3, operands[0], operands[1]);
1290   DONE;
1291 })
1292
1293 (define_expand "reduc_umin_v8hi"
1294   [(umin:V8HI
1295      (match_operand:V8HI 0 "register_operand" "")
1296      (match_operand:V8HI 1 "register_operand" ""))]
1297   "TARGET_SSE4_1"
1298 {
1299   ix86_expand_reduc (gen_uminv8hi3, operands[0], operands[1]);
1300   DONE;
1301 })
1302
1303 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1304 ;;
1305 ;; Parallel floating point comparisons
1306 ;;
1307 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1308
1309 (define_insn "avx_cmp<mode>3"
1310   [(set (match_operand:VF 0 "register_operand" "=x")
1311         (unspec:VF
1312           [(match_operand:VF 1 "register_operand" "x")
1313            (match_operand:VF 2 "nonimmediate_operand" "xm")
1314            (match_operand:SI 3 "const_0_to_31_operand" "n")]
1315           UNSPEC_PCMP))]
1316   "TARGET_AVX"
1317   "vcmp<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1318   [(set_attr "type" "ssecmp")
1319    (set_attr "length_immediate" "1")
1320    (set_attr "prefix" "vex")
1321    (set_attr "mode" "<MODE>")])
1322
1323 (define_insn "avx_vmcmp<mode>3"
1324   [(set (match_operand:VF_128 0 "register_operand" "=x")
1325         (vec_merge:VF_128
1326           (unspec:VF_128
1327             [(match_operand:VF_128 1 "register_operand" "x")
1328              (match_operand:VF_128 2 "nonimmediate_operand" "xm")
1329              (match_operand:SI 3 "const_0_to_31_operand" "n")]
1330             UNSPEC_PCMP)
1331          (match_dup 1)
1332          (const_int 1)))]
1333   "TARGET_AVX"
1334   "vcmp<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1335   [(set_attr "type" "ssecmp")
1336    (set_attr "length_immediate" "1")
1337    (set_attr "prefix" "vex")
1338    (set_attr "mode" "<ssescalarmode>")])
1339
1340 (define_insn "*<sse>_maskcmp<mode>3_comm"
1341   [(set (match_operand:VF 0 "register_operand" "=x,x")
1342         (match_operator:VF 3 "sse_comparison_operator"
1343           [(match_operand:VF 1 "register_operand" "%0,x")
1344            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")]))]
1345   "TARGET_SSE
1346    && GET_RTX_CLASS (GET_CODE (operands[3])) == RTX_COMM_COMPARE"
1347   "@
1348    cmp%D3<ssemodesuffix>\t{%2, %0|%0, %2}
1349    vcmp%D3<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1350   [(set_attr "isa" "noavx,avx")
1351    (set_attr "type" "ssecmp")
1352    (set_attr "length_immediate" "1")
1353    (set_attr "prefix" "orig,vex")
1354    (set_attr "mode" "<MODE>")])
1355
1356 (define_insn "<sse>_maskcmp<mode>3"
1357   [(set (match_operand:VF 0 "register_operand" "=x,x")
1358         (match_operator:VF 3 "sse_comparison_operator"
1359           [(match_operand:VF 1 "register_operand" "0,x")
1360            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")]))]
1361   "TARGET_SSE"
1362   "@
1363    cmp%D3<ssemodesuffix>\t{%2, %0|%0, %2}
1364    vcmp%D3<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1365   [(set_attr "isa" "noavx,avx")
1366    (set_attr "type" "ssecmp")
1367    (set_attr "length_immediate" "1")
1368    (set_attr "prefix" "orig,vex")
1369    (set_attr "mode" "<MODE>")])
1370
1371 (define_insn "<sse>_vmmaskcmp<mode>3"
1372   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
1373         (vec_merge:VF_128
1374          (match_operator:VF_128 3 "sse_comparison_operator"
1375            [(match_operand:VF_128 1 "register_operand" "0,x")
1376             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm")])
1377          (match_dup 1)
1378          (const_int 1)))]
1379   "TARGET_SSE"
1380   "@
1381    cmp%D3<ssescalarmodesuffix>\t{%2, %0|%0, %2}
1382    vcmp%D3<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1383   [(set_attr "isa" "noavx,avx")
1384    (set_attr "type" "ssecmp")
1385    (set_attr "length_immediate" "1,*")
1386    (set_attr "prefix" "orig,vex")
1387    (set_attr "mode" "<ssescalarmode>")])
1388
1389 (define_insn "<sse>_comi"
1390   [(set (reg:CCFP FLAGS_REG)
1391         (compare:CCFP
1392           (vec_select:MODEF
1393             (match_operand:<ssevecmode> 0 "register_operand" "x")
1394             (parallel [(const_int 0)]))
1395           (vec_select:MODEF
1396             (match_operand:<ssevecmode> 1 "nonimmediate_operand" "xm")
1397             (parallel [(const_int 0)]))))]
1398   "SSE_FLOAT_MODE_P (<MODE>mode)"
1399   "%vcomi<ssemodesuffix>\t{%1, %0|%0, %1}"
1400   [(set_attr "type" "ssecomi")
1401    (set_attr "prefix" "maybe_vex")
1402    (set_attr "prefix_rep" "0")
1403    (set (attr "prefix_data16")
1404         (if_then_else (eq_attr "mode" "DF")
1405                       (const_string "1")
1406                       (const_string "0")))
1407    (set_attr "mode" "<MODE>")])
1408
1409 (define_insn "<sse>_ucomi"
1410   [(set (reg:CCFPU FLAGS_REG)
1411         (compare:CCFPU
1412           (vec_select:MODEF
1413             (match_operand:<ssevecmode> 0 "register_operand" "x")
1414             (parallel [(const_int 0)]))
1415           (vec_select:MODEF
1416             (match_operand:<ssevecmode> 1 "nonimmediate_operand" "xm")
1417             (parallel [(const_int 0)]))))]
1418   "SSE_FLOAT_MODE_P (<MODE>mode)"
1419   "%vucomi<ssemodesuffix>\t{%1, %0|%0, %1}"
1420   [(set_attr "type" "ssecomi")
1421    (set_attr "prefix" "maybe_vex")
1422    (set_attr "prefix_rep" "0")
1423    (set (attr "prefix_data16")
1424         (if_then_else (eq_attr "mode" "DF")
1425                       (const_string "1")
1426                       (const_string "0")))
1427    (set_attr "mode" "<MODE>")])
1428
1429 (define_expand "vcond<V_256:mode><VF_256:mode>"
1430   [(set (match_operand:V_256 0 "register_operand" "")
1431         (if_then_else:V_256
1432           (match_operator 3 ""
1433             [(match_operand:VF_256 4 "nonimmediate_operand" "")
1434              (match_operand:VF_256 5 "nonimmediate_operand" "")])
1435           (match_operand:V_256 1 "general_operand" "")
1436           (match_operand:V_256 2 "general_operand" "")))]
1437   "TARGET_AVX
1438    && (GET_MODE_NUNITS (<V_256:MODE>mode)
1439        == GET_MODE_NUNITS (<VF_256:MODE>mode))"
1440 {
1441   bool ok = ix86_expand_fp_vcond (operands);
1442   gcc_assert (ok);
1443   DONE;
1444 })
1445
1446 (define_expand "vcond<V_128:mode><VF_128:mode>"
1447   [(set (match_operand:V_128 0 "register_operand" "")
1448         (if_then_else:V_128
1449           (match_operator 3 ""
1450             [(match_operand:VF_128 4 "nonimmediate_operand" "")
1451              (match_operand:VF_128 5 "nonimmediate_operand" "")])
1452           (match_operand:V_128 1 "general_operand" "")
1453           (match_operand:V_128 2 "general_operand" "")))]
1454   "TARGET_SSE
1455    && (GET_MODE_NUNITS (<V_128:MODE>mode)
1456        == GET_MODE_NUNITS (<VF_128:MODE>mode))"
1457 {
1458   bool ok = ix86_expand_fp_vcond (operands);
1459   gcc_assert (ok);
1460   DONE;
1461 })
1462
1463 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1464 ;;
1465 ;; Parallel floating point logical operations
1466 ;;
1467 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1468
1469 (define_insn "<sse>_andnot<mode>3"
1470   [(set (match_operand:VF 0 "register_operand" "=x,x")
1471         (and:VF
1472           (not:VF
1473             (match_operand:VF 1 "register_operand" "0,x"))
1474           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
1475   "TARGET_SSE"
1476 {
1477   static char buf[32];
1478   const char *insn;
1479   const char *suffix
1480     = TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL ? "ps" : "<ssemodesuffix>";
1481
1482   switch (which_alternative)
1483     {
1484     case 0:
1485       insn = "andn%s\t{%%2, %%0|%%0, %%2}";
1486       break;
1487     case 1:
1488       insn = "vandn%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
1489       break;
1490     default:
1491       gcc_unreachable ();
1492     }
1493
1494   snprintf (buf, sizeof (buf), insn, suffix);
1495   return buf;
1496 }
1497   [(set_attr "isa" "noavx,avx")
1498    (set_attr "type" "sselog")
1499    (set_attr "prefix" "orig,vex")
1500    (set_attr "mode" "<MODE>")])
1501
1502 (define_expand "<code><mode>3"
1503   [(set (match_operand:VF 0 "register_operand" "")
1504         (any_logic:VF
1505           (match_operand:VF 1 "nonimmediate_operand" "")
1506           (match_operand:VF 2 "nonimmediate_operand" "")))]
1507   "TARGET_SSE"
1508   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
1509
1510 (define_insn "*<code><mode>3"
1511   [(set (match_operand:VF 0 "register_operand" "=x,x")
1512         (any_logic:VF
1513           (match_operand:VF 1 "nonimmediate_operand" "%0,x")
1514           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
1515   "TARGET_SSE && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
1516 {
1517   static char buf[32];
1518   const char *insn;
1519   const char *suffix
1520     = TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL ? "ps" : "<ssemodesuffix>";
1521
1522   switch (which_alternative)
1523     {
1524     case 0:
1525       insn = "<logic>%s\t{%%2, %%0|%%0, %%2}";
1526       break;
1527     case 1:
1528       insn = "v<logic>%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
1529       break;
1530     default:
1531       gcc_unreachable ();
1532     }
1533
1534   snprintf (buf, sizeof (buf), insn, suffix);
1535   return buf;
1536 }
1537   [(set_attr "isa" "noavx,avx")
1538    (set_attr "type" "sselog")
1539    (set_attr "prefix" "orig,vex")
1540    (set_attr "mode" "<MODE>")])
1541
1542 (define_expand "copysign<mode>3"
1543   [(set (match_dup 4)
1544         (and:VF
1545           (not:VF (match_dup 3))
1546           (match_operand:VF 1 "nonimmediate_operand" "")))
1547    (set (match_dup 5)
1548         (and:VF (match_dup 3)
1549                 (match_operand:VF 2 "nonimmediate_operand" "")))
1550    (set (match_operand:VF 0 "register_operand" "")
1551         (ior:VF (match_dup 4) (match_dup 5)))]
1552   "TARGET_SSE"
1553 {
1554   operands[3] = ix86_build_signbit_mask (<MODE>mode, 1, 0);
1555
1556   operands[4] = gen_reg_rtx (<MODE>mode);
1557   operands[5] = gen_reg_rtx (<MODE>mode);
1558 })
1559
1560 ;; Also define scalar versions.  These are used for abs, neg, and
1561 ;; conditional move.  Using subregs into vector modes causes register
1562 ;; allocation lossage.  These patterns do not allow memory operands
1563 ;; because the native instructions read the full 128-bits.
1564
1565 (define_insn "*andnot<mode>3"
1566   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
1567         (and:MODEF
1568           (not:MODEF
1569             (match_operand:MODEF 1 "register_operand" "0,x"))
1570             (match_operand:MODEF 2 "register_operand" "x,x")))]
1571   "SSE_FLOAT_MODE_P (<MODE>mode)"
1572 {
1573   static char buf[32];
1574   const char *insn;
1575   const char *suffix
1576     = TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL ? "ps" : "<ssevecmodesuffix>";
1577
1578   switch (which_alternative)
1579     {
1580     case 0:
1581       insn = "andn%s\t{%%2, %%0|%%0, %%2}";
1582       break;
1583     case 1:
1584       insn = "vandn%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
1585       break;
1586     default:
1587       gcc_unreachable ();
1588     }
1589
1590   snprintf (buf, sizeof (buf), insn, suffix);
1591   return buf;
1592 }
1593   [(set_attr "isa" "noavx,avx")
1594    (set_attr "type" "sselog")
1595    (set_attr "prefix" "orig,vex")
1596    (set_attr "mode" "<ssevecmode>")])
1597
1598 (define_insn "*<code><mode>3"
1599   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
1600         (any_logic:MODEF
1601           (match_operand:MODEF 1 "register_operand" "%0,x")
1602           (match_operand:MODEF 2 "register_operand" "x,x")))]
1603   "SSE_FLOAT_MODE_P (<MODE>mode)"
1604 {
1605   static char buf[32];
1606   const char *insn;
1607   const char *suffix
1608     = TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL ? "ps" : "<ssevecmodesuffix>";
1609
1610   switch (which_alternative)
1611     {
1612     case 0:
1613       insn = "<logic>%s\t{%%2, %%0|%%0, %%2}";
1614       break;
1615     case 1:
1616       insn = "v<logic>%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
1617       break;
1618     default:
1619       gcc_unreachable ();
1620     }
1621
1622   snprintf (buf, sizeof (buf), insn, suffix);
1623   return buf;
1624 }
1625   [(set_attr "isa" "noavx,avx")
1626    (set_attr "type" "sselog")
1627    (set_attr "prefix" "orig,vex")
1628    (set_attr "mode" "<ssevecmode>")])
1629
1630 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1631 ;;
1632 ;; FMA4 floating point multiply/accumulate instructions.  This
1633 ;; includes the scalar version of the instructions as well as the
1634 ;; vector.
1635 ;;
1636 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1637
1638 ;; In order to match (*a * *b) + *c, particularly when vectorizing, allow
1639 ;; combine to generate a multiply/add with two memory references.  We then
1640 ;; split this insn, into loading up the destination register with one of the
1641 ;; memory operations.  If we don't manage to split the insn, reload will
1642 ;; generate the appropriate moves.  The reason this is needed, is that combine
1643 ;; has already folded one of the memory references into both the multiply and
1644 ;; add insns, and it can't generate a new pseudo.  I.e.:
1645 ;;      (set (reg1) (mem (addr1)))
1646 ;;      (set (reg2) (mult (reg1) (mem (addr2))))
1647 ;;      (set (reg3) (plus (reg2) (mem (addr3))))
1648 ;;
1649 ;; ??? This is historic, pre-dating the gimple fma transformation.
1650 ;; We could now properly represent that only one memory operand is
1651 ;; allowed and not be penalized during optimization.
1652
1653 ;; Intrinsic FMA operations.
1654
1655 ;; The standard names for fma is only available with SSE math enabled.
1656 (define_expand "fma<mode>4"
1657   [(set (match_operand:FMAMODE 0 "register_operand")
1658         (fma:FMAMODE
1659           (match_operand:FMAMODE 1 "nonimmediate_operand")
1660           (match_operand:FMAMODE 2 "nonimmediate_operand")
1661           (match_operand:FMAMODE 3 "nonimmediate_operand")))]
1662   "(TARGET_FMA || TARGET_FMA4) && TARGET_SSE_MATH")
1663
1664 (define_expand "fms<mode>4"
1665   [(set (match_operand:FMAMODE 0 "register_operand")
1666         (fma:FMAMODE
1667           (match_operand:FMAMODE 1 "nonimmediate_operand")
1668           (match_operand:FMAMODE 2 "nonimmediate_operand")
1669           (neg:FMAMODE (match_operand:FMAMODE 3 "nonimmediate_operand"))))]
1670   "(TARGET_FMA || TARGET_FMA4) && TARGET_SSE_MATH")
1671
1672 (define_expand "fnma<mode>4"
1673   [(set (match_operand:FMAMODE 0 "register_operand")
1674         (fma:FMAMODE
1675           (neg:FMAMODE (match_operand:FMAMODE 1 "nonimmediate_operand"))
1676           (match_operand:FMAMODE 2 "nonimmediate_operand")
1677           (match_operand:FMAMODE 3 "nonimmediate_operand")))]
1678   "(TARGET_FMA || TARGET_FMA4) && TARGET_SSE_MATH")
1679
1680 (define_expand "fnms<mode>4"
1681   [(set (match_operand:FMAMODE 0 "register_operand")
1682         (fma:FMAMODE
1683           (neg:FMAMODE (match_operand:FMAMODE 1 "nonimmediate_operand"))
1684           (match_operand:FMAMODE 2 "nonimmediate_operand")
1685           (neg:FMAMODE (match_operand:FMAMODE 3 "nonimmediate_operand"))))]
1686   "(TARGET_FMA || TARGET_FMA4) && TARGET_SSE_MATH")
1687
1688 ;; The builtin for fma4intrin.h is not constrained by SSE math enabled.
1689 (define_expand "fma4i_fmadd_<mode>"
1690   [(set (match_operand:FMAMODE 0 "register_operand")
1691         (fma:FMAMODE
1692           (match_operand:FMAMODE 1 "nonimmediate_operand")
1693           (match_operand:FMAMODE 2 "nonimmediate_operand")
1694           (match_operand:FMAMODE 3 "nonimmediate_operand")))]
1695   "TARGET_FMA || TARGET_FMA4")
1696
1697 (define_insn "*fma4i_fmadd_<mode>"
1698   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x")
1699         (fma:FMAMODE
1700           (match_operand:FMAMODE 1 "nonimmediate_operand" "%x,x")
1701           (match_operand:FMAMODE 2 "nonimmediate_operand" " x,m")
1702           (match_operand:FMAMODE 3 "nonimmediate_operand" "xm,x")))]
1703   "TARGET_FMA4"
1704   "vfmadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1705   [(set_attr "type" "ssemuladd")
1706    (set_attr "mode" "<MODE>")])
1707
1708 (define_insn "*fma4i_fmsub_<mode>"
1709   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x")
1710         (fma:FMAMODE
1711           (match_operand:FMAMODE 1 "nonimmediate_operand" "%x,x")
1712           (match_operand:FMAMODE 2 "nonimmediate_operand" " x,m")
1713           (neg:FMAMODE
1714             (match_operand:FMAMODE 3 "nonimmediate_operand" "xm,x"))))]
1715   "TARGET_FMA4"
1716   "vfmsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1717   [(set_attr "type" "ssemuladd")
1718    (set_attr "mode" "<MODE>")])
1719
1720 (define_insn "*fma4i_fnmadd_<mode>"
1721   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x")
1722         (fma:FMAMODE
1723           (neg:FMAMODE
1724             (match_operand:FMAMODE 1 "nonimmediate_operand" "%x,x"))
1725           (match_operand:FMAMODE   2 "nonimmediate_operand" " x,m")
1726           (match_operand:FMAMODE   3 "nonimmediate_operand" "xm,x")))]
1727   "TARGET_FMA4"
1728   "vfnmadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1729   [(set_attr "type" "ssemuladd")
1730    (set_attr "mode" "<MODE>")])
1731
1732 (define_insn "*fma4i_fnmsub_<mode>"
1733   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x")
1734         (fma:FMAMODE
1735           (neg:FMAMODE
1736             (match_operand:FMAMODE 1 "nonimmediate_operand" "%x,x"))
1737           (match_operand:FMAMODE   2 "nonimmediate_operand" " x,m")
1738           (neg:FMAMODE
1739             (match_operand:FMAMODE 3 "nonimmediate_operand" "xm,x"))))]
1740   "TARGET_FMA4"
1741   "vfnmsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1742   [(set_attr "type" "ssemuladd")
1743    (set_attr "mode" "<MODE>")])
1744
1745 ;; Scalar versions of the above.  Unlike ADDSS et al, these write the
1746 ;; entire destination register, with the high-order elements zeroed.
1747
1748 (define_expand "fma4i_vmfmadd_<mode>"
1749   [(set (match_operand:VF_128 0 "register_operand")
1750         (vec_merge:VF_128
1751           (fma:VF_128
1752             (match_operand:VF_128 1 "nonimmediate_operand")
1753             (match_operand:VF_128 2 "nonimmediate_operand")
1754             (match_operand:VF_128 3 "nonimmediate_operand"))
1755           (match_dup 4)
1756           (const_int 1)))]
1757   "TARGET_FMA4"
1758 {
1759   operands[4] = CONST0_RTX (<MODE>mode);
1760 })
1761
1762 (define_expand "fmai_vmfmadd_<mode>"
1763   [(set (match_operand:VF_128 0 "register_operand")
1764         (vec_merge:VF_128
1765           (fma:VF_128
1766             (match_operand:VF_128 1 "nonimmediate_operand")
1767             (match_operand:VF_128 2 "nonimmediate_operand")
1768             (match_operand:VF_128 3 "nonimmediate_operand"))
1769           (match_dup 0)
1770           (const_int 1)))]
1771   "TARGET_FMA")
1772
1773 (define_insn "*fmai_fmadd_<mode>"
1774   [(set (match_operand:VF_128 0 "register_operand" "=x,x,x")
1775         (vec_merge:VF_128
1776           (fma:VF_128
1777             (match_operand:VF_128 1 "nonimmediate_operand" "%0, 0,x")
1778             (match_operand:VF_128 2 "nonimmediate_operand" "xm, x,xm")
1779             (match_operand:VF_128 3 "nonimmediate_operand" " x,xm,0"))
1780           (match_dup 0)
1781           (const_int 1)))]
1782   "TARGET_FMA"
1783   "@
1784    vfmadd132<ssescalarmodesuffix>\t{%2, %3, %0|%0, %3, %2}
1785    vfmadd213<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}
1786    vfmadd231<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1787   [(set_attr "type" "ssemuladd")
1788    (set_attr "mode" "<MODE>")])
1789
1790 (define_insn "*fmai_fmsub_<mode>"
1791   [(set (match_operand:VF_128 0 "register_operand" "=x,x,x")
1792         (vec_merge:VF_128
1793           (fma:VF_128
1794             (match_operand:VF_128   1 "nonimmediate_operand" "%0, 0,x")
1795             (match_operand:VF_128   2 "nonimmediate_operand" "xm, x,xm")
1796             (neg:VF_128
1797               (match_operand:VF_128 3 "nonimmediate_operand" " x,xm,0")))
1798           (match_dup 0)
1799           (const_int 1)))]
1800   "TARGET_FMA"
1801   "@
1802    vfmsub132<ssescalarmodesuffix>\t{%2, %3, %0|%0, %3, %2}
1803    vfmsub213<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}
1804    vfmsub231<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1805   [(set_attr "type" "ssemuladd")
1806    (set_attr "mode" "<MODE>")])
1807
1808 (define_insn "*fmai_fnmadd_<mode>"
1809   [(set (match_operand:VF_128 0 "register_operand" "=x,x,x")
1810         (vec_merge:VF_128
1811           (fma:VF_128
1812             (neg:VF_128
1813               (match_operand:VF_128 1 "nonimmediate_operand" "%0, 0,x"))
1814             (match_operand:VF_128   2 "nonimmediate_operand" "xm, x,xm")
1815             (match_operand:VF_128   3 "nonimmediate_operand" " x,xm,0"))
1816           (match_dup 0)
1817           (const_int 1)))]
1818   "TARGET_FMA"
1819   "@
1820    vfnmadd132<ssescalarmodesuffix>\t{%2, %3, %0|%0, %3, %2}
1821    vfnmadd213<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}
1822    vfnmadd231<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1823   [(set_attr "type" "ssemuladd")
1824    (set_attr "mode" "<MODE>")])
1825
1826 (define_insn "*fmai_fnmsub_<mode>"
1827   [(set (match_operand:VF_128 0 "register_operand" "=x,x,x")
1828         (vec_merge:VF_128
1829           (fma:VF_128
1830             (neg:VF_128
1831               (match_operand:VF_128 1 "nonimmediate_operand" "%0, 0,x"))
1832             (match_operand:VF_128   2 "nonimmediate_operand" "xm, x,xm")
1833             (neg:VF_128
1834               (match_operand:VF_128 3 "nonimmediate_operand" " x,xm,0")))
1835           (match_dup 0)
1836           (const_int 1)))]
1837   "TARGET_FMA"
1838   "@
1839    vfnmsub132<ssescalarmodesuffix>\t{%2, %3, %0|%0, %3, %2}
1840    vfnmsub213<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}
1841    vfnmsub231<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1842   [(set_attr "type" "ssemuladd")
1843    (set_attr "mode" "<MODE>")])
1844
1845 (define_insn "*fma4i_vmfmadd_<mode>"
1846   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
1847         (vec_merge:VF_128
1848           (fma:VF_128
1849             (match_operand:VF_128 1 "nonimmediate_operand" "%x,x")
1850             (match_operand:VF_128 2 "nonimmediate_operand" " x,m")
1851             (match_operand:VF_128 3 "nonimmediate_operand" "xm,x"))
1852           (match_operand:VF_128 4 "const0_operand" "")
1853           (const_int 1)))]
1854   "TARGET_FMA4"
1855   "vfmadd<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1856   [(set_attr "type" "ssemuladd")
1857    (set_attr "mode" "<MODE>")])
1858
1859 (define_insn "*fma4i_vmfmsub_<mode>"
1860   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
1861         (vec_merge:VF_128
1862           (fma:VF_128
1863             (match_operand:VF_128 1 "nonimmediate_operand" "%x,x")
1864             (match_operand:VF_128 2 "nonimmediate_operand" " x,m")
1865             (neg:VF_128
1866               (match_operand:VF_128 3 "nonimmediate_operand" "xm,x")))
1867           (match_operand:VF_128 4 "const0_operand" "")
1868           (const_int 1)))]
1869   "TARGET_FMA4"
1870   "vfmsub<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1871   [(set_attr "type" "ssemuladd")
1872    (set_attr "mode" "<MODE>")])
1873
1874 (define_insn "*fma4i_vmfnmadd_<mode>"
1875   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
1876         (vec_merge:VF_128
1877           (fma:VF_128
1878             (neg:VF_128
1879               (match_operand:VF_128 1 "nonimmediate_operand" "%x,x"))
1880             (match_operand:VF_128   2 "nonimmediate_operand" " x,m")
1881             (match_operand:VF_128   3 "nonimmediate_operand" "xm,x"))
1882           (match_operand:VF_128 4 "const0_operand" "")
1883           (const_int 1)))]
1884   "TARGET_FMA4"
1885   "vfnmadd<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1886   [(set_attr "type" "ssemuladd")
1887    (set_attr "mode" "<MODE>")])
1888
1889 (define_insn "*fma4i_vmfnmsub_<mode>"
1890   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
1891         (vec_merge:VF_128
1892           (fma:VF_128
1893             (neg:VF_128
1894               (match_operand:VF_128 1 "nonimmediate_operand" "%x,x"))
1895             (match_operand:VF_128   2 "nonimmediate_operand" " x,m")
1896             (neg:VF_128
1897               (match_operand:VF_128   3 "nonimmediate_operand" "xm,x")))
1898           (match_operand:VF_128 4 "const0_operand" "")
1899           (const_int 1)))]
1900   "TARGET_FMA4"
1901   "vfnmsub<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1902   [(set_attr "type" "ssemuladd")
1903    (set_attr "mode" "<MODE>")])
1904
1905 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1906 ;;
1907 ;; FMA4 Parallel floating point multiply addsub and subadd operations.
1908 ;;
1909 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1910
1911 ;; It would be possible to represent these without the UNSPEC as
1912 ;;
1913 ;; (vec_merge
1914 ;;   (fma op1 op2 op3)
1915 ;;   (fma op1 op2 (neg op3))
1916 ;;   (merge-const))
1917 ;;
1918 ;; But this doesn't seem useful in practice.
1919
1920 (define_expand "fmaddsub_<mode>"
1921   [(set (match_operand:VF 0 "register_operand")
1922         (unspec:VF
1923           [(match_operand:VF 1 "nonimmediate_operand")
1924            (match_operand:VF 2 "nonimmediate_operand")
1925            (match_operand:VF 3 "nonimmediate_operand")]
1926           UNSPEC_FMADDSUB))]
1927   "TARGET_FMA || TARGET_FMA4")
1928
1929 (define_insn "*fma4_fmaddsub_<mode>"
1930   [(set (match_operand:VF 0 "register_operand" "=x,x")
1931         (unspec:VF
1932           [(match_operand:VF 1 "nonimmediate_operand" "%x,x")
1933            (match_operand:VF 2 "nonimmediate_operand" " x,m")
1934            (match_operand:VF 3 "nonimmediate_operand" "xm,x")]
1935           UNSPEC_FMADDSUB))]
1936   "TARGET_FMA4"
1937   "vfmaddsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1938   [(set_attr "type" "ssemuladd")
1939    (set_attr "mode" "<MODE>")])
1940
1941 (define_insn "*fma4_fmsubadd_<mode>"
1942   [(set (match_operand:VF 0 "register_operand" "=x,x")
1943         (unspec:VF
1944           [(match_operand:VF 1 "nonimmediate_operand" "%x,x")
1945            (match_operand:VF 2 "nonimmediate_operand" " x,m")
1946            (neg:VF
1947              (match_operand:VF 3 "nonimmediate_operand" "xm,x"))]
1948           UNSPEC_FMADDSUB))]
1949   "TARGET_FMA4"
1950   "vfmsubadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1951   [(set_attr "type" "ssemuladd")
1952    (set_attr "mode" "<MODE>")])
1953
1954 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1955 ;;
1956 ;; FMA3 floating point multiply/accumulate instructions.
1957 ;;
1958 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1959
1960 (define_insn "*fma_fmadd_<mode>"
1961   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x,x")
1962         (fma:FMAMODE
1963           (match_operand:FMAMODE 1 "nonimmediate_operand" "%0, 0,x")
1964           (match_operand:FMAMODE 2 "nonimmediate_operand" "xm, x,xm")
1965           (match_operand:FMAMODE 3 "nonimmediate_operand" " x,xm,0")))]
1966   "TARGET_FMA"
1967   "@
1968    vfmadd132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
1969    vfmadd213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
1970    vfmadd231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1971   [(set_attr "type" "ssemuladd")
1972    (set_attr "mode" "<MODE>")])
1973
1974 (define_insn "*fma_fmsub_<mode>"
1975   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x,x")
1976         (fma:FMAMODE
1977           (match_operand:FMAMODE   1 "nonimmediate_operand" "%0, 0,x")
1978           (match_operand:FMAMODE   2 "nonimmediate_operand" "xm, x,xm")
1979           (neg:FMAMODE
1980             (match_operand:FMAMODE 3 "nonimmediate_operand" " x,xm,0"))))]
1981   "TARGET_FMA"
1982   "@
1983    vfmsub132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
1984    vfmsub213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
1985    vfmsub231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1986   [(set_attr "type" "ssemuladd")
1987    (set_attr "mode" "<MODE>")])
1988
1989 (define_insn "*fma_fnmadd_<mode>"
1990   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x,x")
1991         (fma:FMAMODE
1992           (neg:FMAMODE
1993             (match_operand:FMAMODE 1 "nonimmediate_operand" "%0, 0,x"))
1994           (match_operand:FMAMODE   2 "nonimmediate_operand" "xm, x,xm")
1995           (match_operand:FMAMODE   3 "nonimmediate_operand" " x,xm,0")))]
1996   "TARGET_FMA"
1997   "@
1998    vfnmadd132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
1999    vfnmadd213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
2000    vfnmadd231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
2001   [(set_attr "type" "ssemuladd")
2002    (set_attr "mode" "<MODE>")])
2003
2004 (define_insn "*fma_fnmsub_<mode>"
2005   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x,x")
2006         (fma:FMAMODE
2007           (neg:FMAMODE
2008             (match_operand:FMAMODE 1 "nonimmediate_operand" "%0, 0,x"))
2009           (match_operand:FMAMODE   2 "nonimmediate_operand" "xm, x,xm")
2010           (neg:FMAMODE
2011             (match_operand:FMAMODE 3 "nonimmediate_operand" " x,xm,0"))))]
2012   "TARGET_FMA"
2013   "@
2014    vfnmsub132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
2015    vfnmsub213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
2016    vfnmsub231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
2017   [(set_attr "type" "ssemuladd")
2018    (set_attr "mode" "<MODE>")])
2019
2020 (define_insn "*fma_fmaddsub_<mode>"
2021   [(set (match_operand:VF 0 "register_operand" "=x,x,x")
2022         (unspec:VF
2023           [(match_operand:VF 1 "nonimmediate_operand" "%0, 0,x")
2024            (match_operand:VF 2 "nonimmediate_operand" "xm, x,xm")
2025            (match_operand:VF 3 "nonimmediate_operand" " x,xm,0")]
2026           UNSPEC_FMADDSUB))]
2027   "TARGET_FMA"
2028   "@
2029    vfmaddsub132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
2030    vfmaddsub213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
2031    vfmaddsub231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
2032   [(set_attr "type" "ssemuladd")
2033    (set_attr "mode" "<MODE>")])
2034
2035 (define_insn "*fma_fmsubadd_<mode>"
2036   [(set (match_operand:VF 0 "register_operand" "=x,x,x")
2037         (unspec:VF
2038           [(match_operand:VF   1 "nonimmediate_operand" "%0, 0,x")
2039            (match_operand:VF   2 "nonimmediate_operand" "xm, x,xm")
2040            (neg:VF
2041              (match_operand:VF 3 "nonimmediate_operand" " x,xm,0"))]
2042           UNSPEC_FMADDSUB))]
2043   "TARGET_FMA"
2044   "@
2045    vfmsubadd132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
2046    vfmsubadd213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
2047    vfmsubadd231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
2048   [(set_attr "type" "ssemuladd")
2049    (set_attr "mode" "<MODE>")])
2050
2051 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2052 ;;
2053 ;; Parallel single-precision floating point conversion operations
2054 ;;
2055 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2056
2057 (define_insn "sse_cvtpi2ps"
2058   [(set (match_operand:V4SF 0 "register_operand" "=x")
2059         (vec_merge:V4SF
2060           (vec_duplicate:V4SF
2061             (float:V2SF (match_operand:V2SI 2 "nonimmediate_operand" "ym")))
2062           (match_operand:V4SF 1 "register_operand" "0")
2063           (const_int 3)))]
2064   "TARGET_SSE"
2065   "cvtpi2ps\t{%2, %0|%0, %2}"
2066   [(set_attr "type" "ssecvt")
2067    (set_attr "mode" "V4SF")])
2068
2069 (define_insn "sse_cvtps2pi"
2070   [(set (match_operand:V2SI 0 "register_operand" "=y")
2071         (vec_select:V2SI
2072           (unspec:V4SI [(match_operand:V4SF 1 "nonimmediate_operand" "xm")]
2073                        UNSPEC_FIX_NOTRUNC)
2074           (parallel [(const_int 0) (const_int 1)])))]
2075   "TARGET_SSE"
2076   "cvtps2pi\t{%1, %0|%0, %1}"
2077   [(set_attr "type" "ssecvt")
2078    (set_attr "unit" "mmx")
2079    (set_attr "mode" "DI")])
2080
2081 (define_insn "sse_cvttps2pi"
2082   [(set (match_operand:V2SI 0 "register_operand" "=y")
2083         (vec_select:V2SI
2084           (fix:V4SI (match_operand:V4SF 1 "nonimmediate_operand" "xm"))
2085           (parallel [(const_int 0) (const_int 1)])))]
2086   "TARGET_SSE"
2087   "cvttps2pi\t{%1, %0|%0, %1}"
2088   [(set_attr "type" "ssecvt")
2089    (set_attr "unit" "mmx")
2090    (set_attr "prefix_rep" "0")
2091    (set_attr "mode" "SF")])
2092
2093 (define_insn "sse_cvtsi2ss"
2094   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
2095         (vec_merge:V4SF
2096           (vec_duplicate:V4SF
2097             (float:SF (match_operand:SI 2 "nonimmediate_operand" "r,m,rm")))
2098           (match_operand:V4SF 1 "register_operand" "0,0,x")
2099           (const_int 1)))]
2100   "TARGET_SSE"
2101   "@
2102    cvtsi2ss\t{%2, %0|%0, %2}
2103    cvtsi2ss\t{%2, %0|%0, %2}
2104    vcvtsi2ss\t{%2, %1, %0|%0, %1, %2}"
2105   [(set_attr "isa" "noavx,noavx,avx")
2106    (set_attr "type" "sseicvt")
2107    (set_attr "athlon_decode" "vector,double,*")
2108    (set_attr "amdfam10_decode" "vector,double,*")
2109    (set_attr "bdver1_decode" "double,direct,*")
2110    (set_attr "prefix" "orig,orig,vex")
2111    (set_attr "mode" "SF")])
2112
2113 (define_insn "sse_cvtsi2ssq"
2114   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
2115         (vec_merge:V4SF
2116           (vec_duplicate:V4SF
2117             (float:SF (match_operand:DI 2 "nonimmediate_operand" "r,m,rm")))
2118           (match_operand:V4SF 1 "register_operand" "0,0,x")
2119           (const_int 1)))]
2120   "TARGET_SSE && TARGET_64BIT"
2121   "@
2122    cvtsi2ssq\t{%2, %0|%0, %2}
2123    cvtsi2ssq\t{%2, %0|%0, %2}
2124    vcvtsi2ssq\t{%2, %1, %0|%0, %1, %2}"
2125   [(set_attr "isa" "noavx,noavx,avx")
2126    (set_attr "type" "sseicvt")
2127    (set_attr "athlon_decode" "vector,double,*")
2128    (set_attr "amdfam10_decode" "vector,double,*")
2129    (set_attr "bdver1_decode" "double,direct,*")
2130    (set_attr "length_vex" "*,*,4")
2131    (set_attr "prefix_rex" "1,1,*")
2132    (set_attr "prefix" "orig,orig,vex")
2133    (set_attr "mode" "SF")])
2134
2135 (define_insn "sse_cvtss2si"
2136   [(set (match_operand:SI 0 "register_operand" "=r,r")
2137         (unspec:SI
2138           [(vec_select:SF
2139              (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
2140              (parallel [(const_int 0)]))]
2141           UNSPEC_FIX_NOTRUNC))]
2142   "TARGET_SSE"
2143   "%vcvtss2si\t{%1, %0|%0, %1}"
2144   [(set_attr "type" "sseicvt")
2145    (set_attr "athlon_decode" "double,vector")
2146    (set_attr "bdver1_decode" "double,double")
2147    (set_attr "prefix_rep" "1")
2148    (set_attr "prefix" "maybe_vex")
2149    (set_attr "mode" "SI")])
2150
2151 (define_insn "sse_cvtss2si_2"
2152   [(set (match_operand:SI 0 "register_operand" "=r,r")
2153         (unspec:SI [(match_operand:SF 1 "nonimmediate_operand" "x,m")]
2154                    UNSPEC_FIX_NOTRUNC))]
2155   "TARGET_SSE"
2156   "%vcvtss2si\t{%1, %0|%0, %1}"
2157   [(set_attr "type" "sseicvt")
2158    (set_attr "athlon_decode" "double,vector")
2159    (set_attr "amdfam10_decode" "double,double")
2160    (set_attr "bdver1_decode" "double,double")
2161    (set_attr "prefix_rep" "1")
2162    (set_attr "prefix" "maybe_vex")
2163    (set_attr "mode" "SI")])
2164
2165 (define_insn "sse_cvtss2siq"
2166   [(set (match_operand:DI 0 "register_operand" "=r,r")
2167         (unspec:DI
2168           [(vec_select:SF
2169              (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
2170              (parallel [(const_int 0)]))]
2171           UNSPEC_FIX_NOTRUNC))]
2172   "TARGET_SSE && TARGET_64BIT"
2173   "%vcvtss2si{q}\t{%1, %0|%0, %1}"
2174   [(set_attr "type" "sseicvt")
2175    (set_attr "athlon_decode" "double,vector")
2176    (set_attr "bdver1_decode" "double,double")
2177    (set_attr "prefix_rep" "1")
2178    (set_attr "prefix" "maybe_vex")
2179    (set_attr "mode" "DI")])
2180
2181 (define_insn "sse_cvtss2siq_2"
2182   [(set (match_operand:DI 0 "register_operand" "=r,r")
2183         (unspec:DI [(match_operand:SF 1 "nonimmediate_operand" "x,m")]
2184                    UNSPEC_FIX_NOTRUNC))]
2185   "TARGET_SSE && TARGET_64BIT"
2186   "%vcvtss2si{q}\t{%1, %0|%0, %1}"
2187   [(set_attr "type" "sseicvt")
2188    (set_attr "athlon_decode" "double,vector")
2189    (set_attr "amdfam10_decode" "double,double")
2190    (set_attr "bdver1_decode" "double,double")
2191    (set_attr "prefix_rep" "1")
2192    (set_attr "prefix" "maybe_vex")
2193    (set_attr "mode" "DI")])
2194
2195 (define_insn "sse_cvttss2si"
2196   [(set (match_operand:SI 0 "register_operand" "=r,r")
2197         (fix:SI
2198           (vec_select:SF
2199             (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
2200             (parallel [(const_int 0)]))))]
2201   "TARGET_SSE"
2202   "%vcvttss2si\t{%1, %0|%0, %1}"
2203   [(set_attr "type" "sseicvt")
2204    (set_attr "athlon_decode" "double,vector")
2205    (set_attr "amdfam10_decode" "double,double")
2206    (set_attr "bdver1_decode" "double,double")
2207    (set_attr "prefix_rep" "1")
2208    (set_attr "prefix" "maybe_vex")
2209    (set_attr "mode" "SI")])
2210
2211 (define_insn "sse_cvttss2siq"
2212   [(set (match_operand:DI 0 "register_operand" "=r,r")
2213         (fix:DI
2214           (vec_select:SF
2215             (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
2216             (parallel [(const_int 0)]))))]
2217   "TARGET_SSE && TARGET_64BIT"
2218   "%vcvttss2si{q}\t{%1, %0|%0, %1}"
2219   [(set_attr "type" "sseicvt")
2220    (set_attr "athlon_decode" "double,vector")
2221    (set_attr "amdfam10_decode" "double,double")
2222    (set_attr "bdver1_decode" "double,double")
2223    (set_attr "prefix_rep" "1")
2224    (set_attr "prefix" "maybe_vex")
2225    (set_attr "mode" "DI")])
2226
2227 (define_insn "avx_cvtdq2ps256"
2228   [(set (match_operand:V8SF 0 "register_operand" "=x")
2229         (float:V8SF (match_operand:V8SI 1 "nonimmediate_operand" "xm")))]
2230   "TARGET_AVX"
2231   "vcvtdq2ps\t{%1, %0|%0, %1}"
2232   [(set_attr "type" "ssecvt")
2233    (set_attr "prefix" "vex")
2234    (set_attr "mode" "V8SF")])
2235
2236 (define_insn "sse2_cvtdq2ps"
2237   [(set (match_operand:V4SF 0 "register_operand" "=x")
2238         (float:V4SF (match_operand:V4SI 1 "nonimmediate_operand" "xm")))]
2239   "TARGET_SSE2"
2240   "%vcvtdq2ps\t{%1, %0|%0, %1}"
2241   [(set_attr "type" "ssecvt")
2242    (set_attr "prefix" "maybe_vex")
2243    (set_attr "mode" "V4SF")])
2244
2245 (define_expand "sse2_cvtudq2ps"
2246   [(set (match_dup 5)
2247         (float:V4SF (match_operand:V4SI 1 "nonimmediate_operand" "")))
2248    (set (match_dup 6)
2249         (lt:V4SF (match_dup 5) (match_dup 3)))
2250    (set (match_dup 7)
2251         (and:V4SF (match_dup 6) (match_dup 4)))
2252    (set (match_operand:V4SF 0 "register_operand" "")
2253         (plus:V4SF (match_dup 5) (match_dup 7)))]
2254   "TARGET_SSE2"
2255 {
2256   REAL_VALUE_TYPE TWO32r;
2257   rtx x;
2258   int i;
2259
2260   real_ldexp (&TWO32r, &dconst1, 32);
2261   x = const_double_from_real_value (TWO32r, SFmode);
2262
2263   operands[3] = force_reg (V4SFmode, CONST0_RTX (V4SFmode));
2264   operands[4] = force_reg (V4SFmode,
2265                            ix86_build_const_vector (V4SFmode, 1, x));
2266
2267   for (i = 5; i < 8; i++)
2268     operands[i] = gen_reg_rtx (V4SFmode);
2269 })
2270
2271 (define_insn "avx_cvtps2dq256"
2272   [(set (match_operand:V8SI 0 "register_operand" "=x")
2273         (unspec:V8SI [(match_operand:V8SF 1 "nonimmediate_operand" "xm")]
2274                      UNSPEC_FIX_NOTRUNC))]
2275   "TARGET_AVX"
2276   "vcvtps2dq\t{%1, %0|%0, %1}"
2277   [(set_attr "type" "ssecvt")
2278    (set_attr "prefix" "vex")
2279    (set_attr "mode" "OI")])
2280
2281 (define_insn "sse2_cvtps2dq"
2282   [(set (match_operand:V4SI 0 "register_operand" "=x")
2283         (unspec:V4SI [(match_operand:V4SF 1 "nonimmediate_operand" "xm")]
2284                      UNSPEC_FIX_NOTRUNC))]
2285   "TARGET_SSE2"
2286   "%vcvtps2dq\t{%1, %0|%0, %1}"
2287   [(set_attr "type" "ssecvt")
2288    (set (attr "prefix_data16")
2289      (if_then_else
2290        (match_test "TARGET_AVX")
2291      (const_string "*")
2292      (const_string "1")))
2293    (set_attr "prefix" "maybe_vex")
2294    (set_attr "mode" "TI")])
2295
2296 (define_insn "avx_cvttps2dq256"
2297   [(set (match_operand:V8SI 0 "register_operand" "=x")
2298         (fix:V8SI (match_operand:V8SF 1 "nonimmediate_operand" "xm")))]
2299   "TARGET_AVX"
2300   "vcvttps2dq\t{%1, %0|%0, %1}"
2301   [(set_attr "type" "ssecvt")
2302    (set_attr "prefix" "vex")
2303    (set_attr "mode" "OI")])
2304
2305 (define_insn "sse2_cvttps2dq"
2306   [(set (match_operand:V4SI 0 "register_operand" "=x")
2307         (fix:V4SI (match_operand:V4SF 1 "nonimmediate_operand" "xm")))]
2308   "TARGET_SSE2"
2309   "%vcvttps2dq\t{%1, %0|%0, %1}"
2310   [(set_attr "type" "ssecvt")
2311    (set (attr "prefix_rep")
2312      (if_then_else
2313        (match_test "TARGET_AVX")
2314      (const_string "*")
2315      (const_string "1")))
2316    (set (attr "prefix_data16")
2317      (if_then_else
2318        (match_test "TARGET_AVX")
2319      (const_string "*")
2320      (const_string "0")))
2321    (set_attr "prefix_data16" "0")
2322    (set_attr "prefix" "maybe_vex")
2323    (set_attr "mode" "TI")])
2324
2325 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2326 ;;
2327 ;; Parallel double-precision floating point conversion operations
2328 ;;
2329 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2330
2331 (define_insn "sse2_cvtpi2pd"
2332   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
2333         (float:V2DF (match_operand:V2SI 1 "nonimmediate_operand" "y,m")))]
2334   "TARGET_SSE2"
2335   "cvtpi2pd\t{%1, %0|%0, %1}"
2336   [(set_attr "type" "ssecvt")
2337    (set_attr "unit" "mmx,*")
2338    (set_attr "prefix_data16" "1,*")
2339    (set_attr "mode" "V2DF")])
2340
2341 (define_insn "sse2_cvtpd2pi"
2342   [(set (match_operand:V2SI 0 "register_operand" "=y")
2343         (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand" "xm")]
2344                      UNSPEC_FIX_NOTRUNC))]
2345   "TARGET_SSE2"
2346   "cvtpd2pi\t{%1, %0|%0, %1}"
2347   [(set_attr "type" "ssecvt")
2348    (set_attr "unit" "mmx")
2349    (set_attr "bdver1_decode" "double")
2350    (set_attr "prefix_data16" "1")
2351    (set_attr "mode" "DI")])
2352
2353 (define_insn "sse2_cvttpd2pi"
2354   [(set (match_operand:V2SI 0 "register_operand" "=y")
2355         (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" "xm")))]
2356   "TARGET_SSE2"
2357   "cvttpd2pi\t{%1, %0|%0, %1}"
2358   [(set_attr "type" "ssecvt")
2359    (set_attr "unit" "mmx")
2360    (set_attr "bdver1_decode" "double")
2361    (set_attr "prefix_data16" "1")
2362    (set_attr "mode" "TI")])
2363
2364 (define_insn "sse2_cvtsi2sd"
2365   [(set (match_operand:V2DF 0 "register_operand" "=x,x,x")
2366         (vec_merge:V2DF
2367           (vec_duplicate:V2DF
2368             (float:DF (match_operand:SI 2 "nonimmediate_operand" "r,m,rm")))
2369           (match_operand:V2DF 1 "register_operand" "0,0,x")
2370           (const_int 1)))]
2371   "TARGET_SSE2"
2372   "@
2373    cvtsi2sd\t{%2, %0|%0, %2}
2374    cvtsi2sd\t{%2, %0|%0, %2}
2375    vcvtsi2sd\t{%2, %1, %0|%0, %1, %2}"
2376   [(set_attr "isa" "noavx,noavx,avx")
2377    (set_attr "type" "sseicvt")
2378    (set_attr "athlon_decode" "double,direct,*")
2379    (set_attr "amdfam10_decode" "vector,double,*")
2380    (set_attr "bdver1_decode" "double,direct,*")
2381    (set_attr "prefix" "orig,orig,vex")
2382    (set_attr "mode" "DF")])
2383
2384 (define_insn "sse2_cvtsi2sdq"
2385   [(set (match_operand:V2DF 0 "register_operand" "=x,x,x")
2386         (vec_merge:V2DF
2387           (vec_duplicate:V2DF
2388             (float:DF (match_operand:DI 2 "nonimmediate_operand" "r,m,rm")))
2389           (match_operand:V2DF 1 "register_operand" "0,0,x")
2390           (const_int 1)))]
2391   "TARGET_SSE2 && TARGET_64BIT"
2392   "@
2393    cvtsi2sdq\t{%2, %0|%0, %2}
2394    cvtsi2sdq\t{%2, %0|%0, %2}
2395    vcvtsi2sdq\t{%2, %1, %0|%0, %1, %2}"
2396   [(set_attr "isa" "noavx,noavx,avx")
2397    (set_attr "type" "sseicvt")
2398    (set_attr "athlon_decode" "double,direct,*")
2399    (set_attr "amdfam10_decode" "vector,double,*")
2400    (set_attr "bdver1_decode" "double,direct,*")
2401    (set_attr "length_vex" "*,*,4")
2402    (set_attr "prefix_rex" "1,1,*")
2403    (set_attr "prefix" "orig,orig,vex")
2404    (set_attr "mode" "DF")])
2405
2406 (define_insn "sse2_cvtsd2si"
2407   [(set (match_operand:SI 0 "register_operand" "=r,r")
2408         (unspec:SI
2409           [(vec_select:DF
2410              (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2411              (parallel [(const_int 0)]))]
2412           UNSPEC_FIX_NOTRUNC))]
2413   "TARGET_SSE2"
2414   "%vcvtsd2si\t{%1, %0|%0, %1}"
2415   [(set_attr "type" "sseicvt")
2416    (set_attr "athlon_decode" "double,vector")
2417    (set_attr "bdver1_decode" "double,double")
2418    (set_attr "prefix_rep" "1")
2419    (set_attr "prefix" "maybe_vex")
2420    (set_attr "mode" "SI")])
2421
2422 (define_insn "sse2_cvtsd2si_2"
2423   [(set (match_operand:SI 0 "register_operand" "=r,r")
2424         (unspec:SI [(match_operand:DF 1 "nonimmediate_operand" "x,m")]
2425                    UNSPEC_FIX_NOTRUNC))]
2426   "TARGET_SSE2"
2427   "%vcvtsd2si\t{%1, %0|%0, %1}"
2428   [(set_attr "type" "sseicvt")
2429    (set_attr "athlon_decode" "double,vector")
2430    (set_attr "amdfam10_decode" "double,double")
2431    (set_attr "bdver1_decode" "double,double")
2432    (set_attr "prefix_rep" "1")
2433    (set_attr "prefix" "maybe_vex")
2434    (set_attr "mode" "SI")])
2435
2436 (define_insn "sse2_cvtsd2siq"
2437   [(set (match_operand:DI 0 "register_operand" "=r,r")
2438         (unspec:DI
2439           [(vec_select:DF
2440              (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2441              (parallel [(const_int 0)]))]
2442           UNSPEC_FIX_NOTRUNC))]
2443   "TARGET_SSE2 && TARGET_64BIT"
2444   "%vcvtsd2si{q}\t{%1, %0|%0, %1}"
2445   [(set_attr "type" "sseicvt")
2446    (set_attr "athlon_decode" "double,vector")
2447    (set_attr "bdver1_decode" "double,double")
2448    (set_attr "prefix_rep" "1")
2449    (set_attr "prefix" "maybe_vex")
2450    (set_attr "mode" "DI")])
2451
2452 (define_insn "sse2_cvtsd2siq_2"
2453   [(set (match_operand:DI 0 "register_operand" "=r,r")
2454         (unspec:DI [(match_operand:DF 1 "nonimmediate_operand" "x,m")]
2455                    UNSPEC_FIX_NOTRUNC))]
2456   "TARGET_SSE2 && TARGET_64BIT"
2457   "%vcvtsd2si{q}\t{%1, %0|%0, %1}"
2458   [(set_attr "type" "sseicvt")
2459    (set_attr "athlon_decode" "double,vector")
2460    (set_attr "amdfam10_decode" "double,double")
2461    (set_attr "bdver1_decode" "double,double")
2462    (set_attr "prefix_rep" "1")
2463    (set_attr "prefix" "maybe_vex")
2464    (set_attr "mode" "DI")])
2465
2466 (define_insn "sse2_cvttsd2si"
2467   [(set (match_operand:SI 0 "register_operand" "=r,r")
2468         (fix:SI
2469           (vec_select:DF
2470             (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2471             (parallel [(const_int 0)]))))]
2472   "TARGET_SSE2"
2473   "%vcvttsd2si\t{%1, %0|%0, %1}"
2474   [(set_attr "type" "sseicvt")
2475    (set_attr "athlon_decode" "double,vector")
2476    (set_attr "amdfam10_decode" "double,double")
2477    (set_attr "bdver1_decode" "double,double")
2478    (set_attr "prefix_rep" "1")
2479    (set_attr "prefix" "maybe_vex")
2480    (set_attr "mode" "SI")])
2481
2482 (define_insn "sse2_cvttsd2siq"
2483   [(set (match_operand:DI 0 "register_operand" "=r,r")
2484         (fix:DI
2485           (vec_select:DF
2486             (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2487             (parallel [(const_int 0)]))))]
2488   "TARGET_SSE2 && TARGET_64BIT"
2489   "%vcvttsd2si{q}\t{%1, %0|%0, %1}"
2490   [(set_attr "type" "sseicvt")
2491    (set_attr "athlon_decode" "double,vector")
2492    (set_attr "amdfam10_decode" "double,double")
2493    (set_attr "bdver1_decode" "double,double")
2494    (set_attr "prefix_rep" "1")
2495    (set_attr "prefix" "maybe_vex")
2496    (set_attr "mode" "DI")])
2497
2498 (define_insn "avx_cvtdq2pd256"
2499   [(set (match_operand:V4DF 0 "register_operand" "=x")
2500         (float:V4DF (match_operand:V4SI 1 "nonimmediate_operand" "xm")))]
2501   "TARGET_AVX"
2502   "vcvtdq2pd\t{%1, %0|%0, %1}"
2503   [(set_attr "type" "ssecvt")
2504    (set_attr "prefix" "vex")
2505    (set_attr "mode" "V4DF")])
2506
2507 (define_insn "avx_cvtdq2pd256_2"
2508   [(set (match_operand:V4DF 0 "register_operand" "=x")
2509         (float:V4DF
2510           (vec_select:V4SI
2511             (match_operand:V8SI 1 "nonimmediate_operand" "xm")
2512             (parallel [(const_int 0) (const_int 1)
2513                        (const_int 2) (const_int 3)]))))]
2514   "TARGET_AVX"
2515   "vcvtdq2pd\t{%x1, %0|%0, %x1}"
2516   [(set_attr "type" "ssecvt")
2517    (set_attr "prefix" "vex")
2518    (set_attr "mode" "V4DF")])
2519
2520 (define_insn "sse2_cvtdq2pd"
2521   [(set (match_operand:V2DF 0 "register_operand" "=x")
2522         (float:V2DF
2523           (vec_select:V2SI
2524             (match_operand:V4SI 1 "nonimmediate_operand" "xm")
2525             (parallel [(const_int 0) (const_int 1)]))))]
2526   "TARGET_SSE2"
2527   "%vcvtdq2pd\t{%1, %0|%0, %q1}"
2528   [(set_attr "type" "ssecvt")
2529    (set_attr "prefix" "maybe_vex")
2530    (set_attr "mode" "V2DF")])
2531
2532 (define_insn "avx_cvtpd2dq256"
2533   [(set (match_operand:V4SI 0 "register_operand" "=x")
2534         (unspec:V4SI [(match_operand:V4DF 1 "nonimmediate_operand" "xm")]
2535                      UNSPEC_FIX_NOTRUNC))]
2536   "TARGET_AVX"
2537   "vcvtpd2dq{y}\t{%1, %0|%0, %1}"
2538   [(set_attr "type" "ssecvt")
2539    (set_attr "prefix" "vex")
2540    (set_attr "mode" "OI")])
2541
2542 (define_expand "avx_cvtpd2dq256_2"
2543   [(set (match_operand:V8SI 0 "register_operand" "")
2544         (vec_concat:V8SI
2545           (unspec:V4SI [(match_operand:V4DF 1 "nonimmediate_operand" "")]
2546                        UNSPEC_FIX_NOTRUNC)
2547           (match_dup 2)))]
2548   "TARGET_AVX"
2549   "operands[2] = CONST0_RTX (V4SImode);")
2550
2551 (define_insn "*avx_cvtpd2dq256_2"
2552   [(set (match_operand:V8SI 0 "register_operand" "=x")
2553         (vec_concat:V8SI
2554           (unspec:V4SI [(match_operand:V4DF 1 "nonimmediate_operand" "xm")]
2555                        UNSPEC_FIX_NOTRUNC)
2556           (match_operand:V4SI 2 "const0_operand" "")))]
2557   "TARGET_AVX"
2558   "vcvtpd2dq{y}\t{%1, %x0|%x0, %1}"
2559   [(set_attr "type" "ssecvt")
2560    (set_attr "prefix" "vex")
2561    (set_attr "mode" "OI")])
2562
2563 (define_expand "sse2_cvtpd2dq"
2564   [(set (match_operand:V4SI 0 "register_operand" "")
2565         (vec_concat:V4SI
2566           (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand" "")]
2567                        UNSPEC_FIX_NOTRUNC)
2568           (match_dup 2)))]
2569   "TARGET_SSE2"
2570   "operands[2] = CONST0_RTX (V2SImode);")
2571
2572 (define_insn "*sse2_cvtpd2dq"
2573   [(set (match_operand:V4SI 0 "register_operand" "=x")
2574         (vec_concat:V4SI
2575           (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand" "xm")]
2576                        UNSPEC_FIX_NOTRUNC)
2577           (match_operand:V2SI 2 "const0_operand" "")))]
2578   "TARGET_SSE2"
2579 {
2580   if (TARGET_AVX)
2581     return "vcvtpd2dq{x}\t{%1, %0|%0, %1}";
2582   else
2583     return "cvtpd2dq\t{%1, %0|%0, %1}";
2584 }
2585   [(set_attr "type" "ssecvt")
2586    (set_attr "prefix_rep" "1")
2587    (set_attr "prefix_data16" "0")
2588    (set_attr "prefix" "maybe_vex")
2589    (set_attr "mode" "TI")
2590    (set_attr "amdfam10_decode" "double")
2591    (set_attr "athlon_decode" "vector")
2592    (set_attr "bdver1_decode" "double")])
2593
2594 (define_insn "avx_cvttpd2dq256"
2595   [(set (match_operand:V4SI 0 "register_operand" "=x")
2596         (fix:V4SI (match_operand:V4DF 1 "nonimmediate_operand" "xm")))]
2597   "TARGET_AVX"
2598   "vcvttpd2dq{y}\t{%1, %0|%0, %1}"
2599   [(set_attr "type" "ssecvt")
2600    (set_attr "prefix" "vex")
2601    (set_attr "mode" "OI")])
2602
2603 (define_expand "avx_cvttpd2dq256_2"
2604   [(set (match_operand:V8SI 0 "register_operand" "")
2605         (vec_concat:V8SI
2606           (fix:V4SI (match_operand:V4DF 1 "nonimmediate_operand" ""))
2607           (match_dup 2)))]
2608   "TARGET_AVX"
2609   "operands[2] = CONST0_RTX (V4SImode);")
2610
2611 (define_insn "*avx_cvttpd2dq256_2"
2612   [(set (match_operand:V8SI 0 "register_operand" "=x")
2613         (vec_concat:V8SI
2614           (fix:V4SI (match_operand:V4DF 1 "nonimmediate_operand" "xm"))
2615           (match_operand:V4SI 2 "const0_operand" "")))]
2616   "TARGET_AVX"
2617   "vcvttpd2dq{y}\t{%1, %x0|%x0, %1}"
2618   [(set_attr "type" "ssecvt")
2619    (set_attr "prefix" "vex")
2620    (set_attr "mode" "OI")])
2621
2622 (define_expand "sse2_cvttpd2dq"
2623   [(set (match_operand:V4SI 0 "register_operand" "")
2624         (vec_concat:V4SI
2625           (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" ""))
2626           (match_dup 2)))]
2627   "TARGET_SSE2"
2628   "operands[2] = CONST0_RTX (V2SImode);")
2629
2630 (define_insn "*sse2_cvttpd2dq"
2631   [(set (match_operand:V4SI 0 "register_operand" "=x")
2632         (vec_concat:V4SI
2633           (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" "xm"))
2634           (match_operand:V2SI 2 "const0_operand" "")))]
2635   "TARGET_SSE2"
2636 {
2637   if (TARGET_AVX)
2638     return "vcvttpd2dq{x}\t{%1, %0|%0, %1}";
2639   else
2640     return "cvttpd2dq\t{%1, %0|%0, %1}";
2641 }
2642   [(set_attr "type" "ssecvt")
2643    (set_attr "amdfam10_decode" "double")
2644    (set_attr "athlon_decode" "vector")
2645    (set_attr "bdver1_decode" "double")
2646    (set_attr "prefix" "maybe_vex")
2647    (set_attr "mode" "TI")])
2648
2649 (define_insn "sse2_cvtsd2ss"
2650   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
2651         (vec_merge:V4SF
2652           (vec_duplicate:V4SF
2653             (float_truncate:V2SF
2654               (match_operand:V2DF 2 "nonimmediate_operand" "x,m,xm")))
2655           (match_operand:V4SF 1 "register_operand" "0,0,x")
2656           (const_int 1)))]
2657   "TARGET_SSE2"
2658   "@
2659    cvtsd2ss\t{%2, %0|%0, %2}
2660    cvtsd2ss\t{%2, %0|%0, %2}
2661    vcvtsd2ss\t{%2, %1, %0|%0, %1, %2}"
2662   [(set_attr "isa" "noavx,noavx,avx")
2663    (set_attr "type" "ssecvt")
2664    (set_attr "athlon_decode" "vector,double,*")
2665    (set_attr "amdfam10_decode" "vector,double,*")
2666    (set_attr "bdver1_decode" "direct,direct,*")
2667    (set_attr "prefix" "orig,orig,vex")
2668    (set_attr "mode" "SF")])
2669
2670 (define_insn "sse2_cvtss2sd"
2671   [(set (match_operand:V2DF 0 "register_operand" "=x,x,x")
2672         (vec_merge:V2DF
2673           (float_extend:V2DF
2674             (vec_select:V2SF
2675               (match_operand:V4SF 2 "nonimmediate_operand" "x,m,xm")
2676               (parallel [(const_int 0) (const_int 1)])))
2677           (match_operand:V2DF 1 "register_operand" "0,0,x")
2678           (const_int 1)))]
2679   "TARGET_SSE2"
2680   "@
2681    cvtss2sd\t{%2, %0|%0, %2}
2682    cvtss2sd\t{%2, %0|%0, %2}
2683    vcvtss2sd\t{%2, %1, %0|%0, %1, %2}"
2684   [(set_attr "isa" "noavx,noavx,avx")
2685    (set_attr "type" "ssecvt")
2686    (set_attr "amdfam10_decode" "vector,double,*")
2687    (set_attr "athlon_decode" "direct,direct,*")
2688    (set_attr "bdver1_decode" "direct,direct,*")
2689    (set_attr "prefix" "orig,orig,vex")
2690    (set_attr "mode" "DF")])
2691
2692 (define_insn "avx_cvtpd2ps256"
2693   [(set (match_operand:V4SF 0 "register_operand" "=x")
2694         (float_truncate:V4SF
2695           (match_operand:V4DF 1 "nonimmediate_operand" "xm")))]
2696   "TARGET_AVX"
2697   "vcvtpd2ps{y}\t{%1, %0|%0, %1}"
2698   [(set_attr "type" "ssecvt")
2699    (set_attr "prefix" "vex")
2700    (set_attr "mode" "V4SF")])
2701
2702 (define_expand "sse2_cvtpd2ps"
2703   [(set (match_operand:V4SF 0 "register_operand" "")
2704         (vec_concat:V4SF
2705           (float_truncate:V2SF
2706             (match_operand:V2DF 1 "nonimmediate_operand" ""))
2707           (match_dup 2)))]
2708   "TARGET_SSE2"
2709   "operands[2] = CONST0_RTX (V2SFmode);")
2710
2711 (define_insn "*sse2_cvtpd2ps"
2712   [(set (match_operand:V4SF 0 "register_operand" "=x")
2713         (vec_concat:V4SF
2714           (float_truncate:V2SF
2715             (match_operand:V2DF 1 "nonimmediate_operand" "xm"))
2716           (match_operand:V2SF 2 "const0_operand" "")))]
2717   "TARGET_SSE2"
2718 {
2719   if (TARGET_AVX)
2720     return "vcvtpd2ps{x}\t{%1, %0|%0, %1}";
2721   else
2722     return "cvtpd2ps\t{%1, %0|%0, %1}";
2723 }
2724   [(set_attr "type" "ssecvt")
2725    (set_attr "amdfam10_decode" "double")
2726    (set_attr "athlon_decode" "vector")
2727    (set_attr "bdver1_decode" "double")
2728    (set_attr "prefix_data16" "1")
2729    (set_attr "prefix" "maybe_vex")
2730    (set_attr "mode" "V4SF")])
2731
2732 (define_insn "avx_cvtps2pd256"
2733   [(set (match_operand:V4DF 0 "register_operand" "=x")
2734         (float_extend:V4DF
2735           (match_operand:V4SF 1 "nonimmediate_operand" "xm")))]
2736   "TARGET_AVX"
2737   "vcvtps2pd\t{%1, %0|%0, %1}"
2738   [(set_attr "type" "ssecvt")
2739    (set_attr "prefix" "vex")
2740    (set_attr "mode" "V4DF")])
2741
2742 (define_insn "*avx_cvtps2pd256_2"
2743   [(set (match_operand:V4DF 0 "register_operand" "=x")
2744         (float_extend:V4DF
2745           (vec_select:V4SF
2746             (match_operand:V8SF 1 "nonimmediate_operand" "xm")
2747             (parallel [(const_int 0) (const_int 1)
2748                        (const_int 2) (const_int 3)]))))]
2749   "TARGET_AVX"
2750   "vcvtps2pd\t{%x1, %0|%0, %x1}"
2751   [(set_attr "type" "ssecvt")
2752    (set_attr "prefix" "vex")
2753    (set_attr "mode" "V4DF")])
2754
2755 (define_insn "sse2_cvtps2pd"
2756   [(set (match_operand:V2DF 0 "register_operand" "=x")
2757         (float_extend:V2DF
2758           (vec_select:V2SF
2759             (match_operand:V4SF 1 "nonimmediate_operand" "xm")
2760             (parallel [(const_int 0) (const_int 1)]))))]
2761   "TARGET_SSE2"
2762   "%vcvtps2pd\t{%1, %0|%0, %q1}"
2763   [(set_attr "type" "ssecvt")
2764    (set_attr "amdfam10_decode" "direct")
2765    (set_attr "athlon_decode" "double")
2766    (set_attr "bdver1_decode" "double")
2767    (set_attr "prefix_data16" "0")
2768    (set_attr "prefix" "maybe_vex")
2769    (set_attr "mode" "V2DF")])
2770
2771 (define_expand "vec_unpacks_hi_v4sf"
2772   [(set (match_dup 2)
2773    (vec_select:V4SF
2774      (vec_concat:V8SF
2775        (match_dup 2)
2776        (match_operand:V4SF 1 "nonimmediate_operand" ""))
2777      (parallel [(const_int 6) (const_int 7)
2778                 (const_int 2) (const_int 3)])))
2779   (set (match_operand:V2DF 0 "register_operand" "")
2780    (float_extend:V2DF
2781      (vec_select:V2SF
2782        (match_dup 2)
2783        (parallel [(const_int 0) (const_int 1)]))))]
2784   "TARGET_SSE2"
2785   "operands[2] = gen_reg_rtx (V4SFmode);")
2786
2787 (define_expand "vec_unpacks_hi_v8sf"
2788   [(set (match_dup 2)
2789         (vec_select:V4SF
2790           (match_operand:V8SF 1 "nonimmediate_operand" "")
2791           (parallel [(const_int 4) (const_int 5)
2792                      (const_int 6) (const_int 7)])))
2793    (set (match_operand:V4DF 0 "register_operand" "")
2794         (float_extend:V4DF
2795           (match_dup 2)))]
2796   "TARGET_AVX"
2797   "operands[2] = gen_reg_rtx (V4SFmode);")
2798
2799 (define_expand "vec_unpacks_lo_v4sf"
2800   [(set (match_operand:V2DF 0 "register_operand" "")
2801         (float_extend:V2DF
2802           (vec_select:V2SF
2803             (match_operand:V4SF 1 "nonimmediate_operand" "")
2804             (parallel [(const_int 0) (const_int 1)]))))]
2805   "TARGET_SSE2")
2806
2807 (define_expand "vec_unpacks_lo_v8sf"
2808   [(set (match_operand:V4DF 0 "register_operand" "")
2809         (float_extend:V4DF
2810           (vec_select:V4SF
2811             (match_operand:V8SF 1 "nonimmediate_operand" "")
2812             (parallel [(const_int 0) (const_int 1)
2813                        (const_int 2) (const_int 3)]))))]
2814   "TARGET_AVX")
2815
2816 (define_mode_attr sseunpackfltmode
2817   [(V8HI "V4SF") (V4SI "V2DF") (V16HI "V8SF") (V8SI "V4DF")])
2818
2819 (define_expand "vec_unpacks_float_hi_<mode>"
2820   [(match_operand:<sseunpackfltmode> 0 "register_operand" "")
2821    (match_operand:VI2_AVX2 1 "register_operand" "")]
2822   "TARGET_SSE2"
2823 {
2824   rtx tmp = gen_reg_rtx (<sseunpackmode>mode);
2825
2826   emit_insn (gen_vec_unpacks_hi_<mode> (tmp, operands[1]));
2827   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2828                           gen_rtx_FLOAT (<sseunpackfltmode>mode, tmp)));
2829   DONE;
2830 })
2831
2832 (define_expand "vec_unpacks_float_lo_<mode>"
2833   [(match_operand:<sseunpackfltmode> 0 "register_operand" "")
2834    (match_operand:VI2_AVX2 1 "register_operand" "")]
2835   "TARGET_SSE2"
2836 {
2837   rtx tmp = gen_reg_rtx (<sseunpackmode>mode);
2838
2839   emit_insn (gen_vec_unpacks_lo_<mode> (tmp, operands[1]));
2840   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2841                           gen_rtx_FLOAT (<sseunpackfltmode>mode, tmp)));
2842   DONE;
2843 })
2844
2845 (define_expand "vec_unpacku_float_hi_<mode>"
2846   [(match_operand:<sseunpackfltmode> 0 "register_operand" "")
2847    (match_operand:VI2_AVX2 1 "register_operand" "")]
2848   "TARGET_SSE2"
2849 {
2850   rtx tmp = gen_reg_rtx (<sseunpackmode>mode);
2851
2852   emit_insn (gen_vec_unpacku_hi_<mode> (tmp, operands[1]));
2853   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2854                           gen_rtx_FLOAT (<sseunpackfltmode>mode, tmp)));
2855   DONE;
2856 })
2857
2858 (define_expand "vec_unpacku_float_lo_<mode>"
2859   [(match_operand:<sseunpackfltmode> 0 "register_operand" "")
2860    (match_operand:VI2_AVX2 1 "register_operand" "")]
2861   "TARGET_SSE2"
2862 {
2863   rtx tmp = gen_reg_rtx (<sseunpackmode>mode);
2864
2865   emit_insn (gen_vec_unpacku_lo_<mode> (tmp, operands[1]));
2866   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2867                           gen_rtx_FLOAT (<sseunpackfltmode>mode, tmp)));
2868   DONE;
2869 })
2870
2871 (define_expand "vec_unpacks_float_hi_v4si"
2872   [(set (match_dup 2)
2873         (vec_select:V4SI
2874           (match_operand:V4SI 1 "nonimmediate_operand" "")
2875           (parallel [(const_int 2) (const_int 3)
2876                      (const_int 2) (const_int 3)])))
2877    (set (match_operand:V2DF 0 "register_operand" "")
2878         (float:V2DF
2879           (vec_select:V2SI
2880           (match_dup 2)
2881             (parallel [(const_int 0) (const_int 1)]))))]
2882   "TARGET_SSE2"
2883   "operands[2] = gen_reg_rtx (V4SImode);")
2884
2885 (define_expand "vec_unpacks_float_lo_v4si"
2886   [(set (match_operand:V2DF 0 "register_operand" "")
2887         (float:V2DF
2888           (vec_select:V2SI
2889             (match_operand:V4SI 1 "nonimmediate_operand" "")
2890             (parallel [(const_int 0) (const_int 1)]))))]
2891   "TARGET_SSE2")
2892
2893 (define_expand "vec_unpacks_float_hi_v8si"
2894   [(set (match_dup 2)
2895         (vec_select:V4SI
2896           (match_operand:V8SI 1 "nonimmediate_operand" "")
2897           (parallel [(const_int 4) (const_int 5)
2898                      (const_int 6) (const_int 7)])))
2899    (set (match_operand:V4DF 0 "register_operand" "")
2900         (float:V4DF
2901           (match_dup 2)))]
2902   "TARGET_AVX"
2903   "operands[2] = gen_reg_rtx (V4SImode);")
2904
2905 (define_expand "vec_unpacks_float_lo_v8si"
2906   [(set (match_operand:V4DF 0 "register_operand" "")
2907         (float:V4DF
2908           (vec_select:V4SI
2909             (match_operand:V8SI 1 "nonimmediate_operand" "")
2910             (parallel [(const_int 0) (const_int 1)
2911                        (const_int 2) (const_int 3)]))))]
2912   "TARGET_AVX")
2913
2914 (define_expand "vec_unpacku_float_hi_v4si"
2915   [(set (match_dup 5)
2916         (vec_select:V4SI
2917           (match_operand:V4SI 1 "nonimmediate_operand" "")
2918           (parallel [(const_int 2) (const_int 3)
2919                      (const_int 2) (const_int 3)])))
2920    (set (match_dup 6)
2921         (float:V2DF
2922           (vec_select:V2SI
2923           (match_dup 5)
2924             (parallel [(const_int 0) (const_int 1)]))))
2925    (set (match_dup 7)
2926         (lt:V2DF (match_dup 6) (match_dup 3)))
2927    (set (match_dup 8)
2928         (and:V2DF (match_dup 7) (match_dup 4)))
2929    (set (match_operand:V2DF 0 "register_operand" "")
2930         (plus:V2DF (match_dup 6) (match_dup 8)))]
2931   "TARGET_SSE2"
2932 {
2933   REAL_VALUE_TYPE TWO32r;
2934   rtx x;
2935   int i;
2936
2937   real_ldexp (&TWO32r, &dconst1, 32);
2938   x = const_double_from_real_value (TWO32r, DFmode);
2939
2940   operands[3] = force_reg (V2DFmode, CONST0_RTX (V2DFmode));
2941   operands[4] = force_reg (V2DFmode,
2942                            ix86_build_const_vector (V2DFmode, 1, x));
2943
2944   operands[5] = gen_reg_rtx (V4SImode);
2945
2946   for (i = 6; i < 9; i++)
2947     operands[i] = gen_reg_rtx (V2DFmode);
2948 })
2949
2950 (define_expand "vec_unpacku_float_lo_v4si"
2951   [(set (match_dup 5)
2952         (float:V2DF
2953           (vec_select:V2SI
2954             (match_operand:V4SI 1 "nonimmediate_operand" "")
2955             (parallel [(const_int 0) (const_int 1)]))))
2956    (set (match_dup 6)
2957         (lt:V2DF (match_dup 5) (match_dup 3)))
2958    (set (match_dup 7)
2959         (and:V2DF (match_dup 6) (match_dup 4)))
2960    (set (match_operand:V2DF 0 "register_operand" "")
2961         (plus:V2DF (match_dup 5) (match_dup 7)))]
2962   "TARGET_SSE2"
2963 {
2964   REAL_VALUE_TYPE TWO32r;
2965   rtx x;
2966   int i;
2967
2968   real_ldexp (&TWO32r, &dconst1, 32);
2969   x = const_double_from_real_value (TWO32r, DFmode);
2970
2971   operands[3] = force_reg (V2DFmode, CONST0_RTX (V2DFmode));
2972   operands[4] = force_reg (V2DFmode,
2973                            ix86_build_const_vector (V2DFmode, 1, x));
2974
2975   for (i = 5; i < 8; i++)
2976     operands[i] = gen_reg_rtx (V2DFmode);
2977 })
2978
2979 (define_expand "vec_unpacku_float_hi_v8si"
2980   [(match_operand:V4DF 0 "register_operand" "")
2981    (match_operand:V8SI 1 "register_operand" "")]
2982   "TARGET_AVX"
2983 {
2984   REAL_VALUE_TYPE TWO32r;
2985   rtx x, tmp[6];
2986   int i;
2987
2988   real_ldexp (&TWO32r, &dconst1, 32);
2989   x = const_double_from_real_value (TWO32r, DFmode);
2990
2991   tmp[0] = force_reg (V4DFmode, CONST0_RTX (V4DFmode));
2992   tmp[1] = force_reg (V4DFmode, ix86_build_const_vector (V4DFmode, 1, x));
2993   tmp[5] = gen_reg_rtx (V4SImode);
2994
2995   for (i = 2; i < 5; i++)
2996     tmp[i] = gen_reg_rtx (V4DFmode);
2997   emit_insn (gen_vec_extract_hi_v8si (tmp[5], operands[1]));
2998   emit_insn (gen_avx_cvtdq2pd256 (tmp[2], tmp[5]));
2999   emit_insn (gen_rtx_SET (VOIDmode, tmp[3],
3000                           gen_rtx_LT (V4DFmode, tmp[2], tmp[0])));
3001   emit_insn (gen_andv4df3 (tmp[4], tmp[3], tmp[1]));
3002   emit_insn (gen_addv4df3 (operands[0], tmp[2], tmp[4]));
3003   DONE;
3004 })
3005
3006 (define_expand "vec_unpacku_float_lo_v8si"
3007   [(match_operand:V4DF 0 "register_operand" "")
3008    (match_operand:V8SI 1 "nonimmediate_operand" "")]
3009   "TARGET_AVX"
3010 {
3011   REAL_VALUE_TYPE TWO32r;
3012   rtx x, tmp[5];
3013   int i;
3014
3015   real_ldexp (&TWO32r, &dconst1, 32);
3016   x = const_double_from_real_value (TWO32r, DFmode);
3017
3018   tmp[0] = force_reg (V4DFmode, CONST0_RTX (V4DFmode));
3019   tmp[1] = force_reg (V4DFmode, ix86_build_const_vector (V4DFmode, 1, x));
3020
3021   for (i = 2; i < 5; i++)
3022     tmp[i] = gen_reg_rtx (V4DFmode);
3023   emit_insn (gen_avx_cvtdq2pd256_2 (tmp[2], operands[1]));
3024   emit_insn (gen_rtx_SET (VOIDmode, tmp[3],
3025                           gen_rtx_LT (V4DFmode, tmp[2], tmp[0])));
3026   emit_insn (gen_andv4df3 (tmp[4], tmp[3], tmp[1]));
3027   emit_insn (gen_addv4df3 (operands[0], tmp[2], tmp[4]));
3028   DONE;
3029 })
3030
3031 (define_expand "vec_pack_trunc_v4df"
3032   [(set (match_dup 3)
3033         (float_truncate:V4SF
3034           (match_operand:V4DF 1 "nonimmediate_operand" "")))
3035    (set (match_dup 4)
3036         (float_truncate:V4SF
3037           (match_operand:V4DF 2 "nonimmediate_operand" "")))
3038    (set (match_operand:V8SF 0 "register_operand" "")
3039         (vec_concat:V8SF
3040           (match_dup 3)
3041           (match_dup 4)))]
3042   "TARGET_AVX"
3043 {
3044   operands[3] = gen_reg_rtx (V4SFmode);
3045   operands[4] = gen_reg_rtx (V4SFmode);
3046 })
3047
3048 (define_expand "vec_pack_trunc_v2df"
3049   [(match_operand:V4SF 0 "register_operand" "")
3050    (match_operand:V2DF 1 "nonimmediate_operand" "")
3051    (match_operand:V2DF 2 "nonimmediate_operand" "")]
3052   "TARGET_SSE2"
3053 {
3054   rtx r1, r2;
3055
3056   r1 = gen_reg_rtx (V4SFmode);
3057   r2 = gen_reg_rtx (V4SFmode);
3058
3059   emit_insn (gen_sse2_cvtpd2ps (r1, operands[1]));
3060   emit_insn (gen_sse2_cvtpd2ps (r2, operands[2]));
3061   emit_insn (gen_sse_movlhps (operands[0], r1, r2));
3062   DONE;
3063 })
3064
3065 (define_expand "vec_pack_sfix_trunc_v4df"
3066   [(match_operand:V8SI 0 "register_operand" "")
3067    (match_operand:V4DF 1 "nonimmediate_operand" "")
3068    (match_operand:V4DF 2 "nonimmediate_operand" "")]
3069   "TARGET_AVX"
3070 {
3071   rtx r1, r2;
3072
3073   r1 = gen_reg_rtx (V8SImode);
3074   r2 = gen_reg_rtx (V8SImode);
3075
3076   emit_insn (gen_avx_cvttpd2dq256_2 (r1, operands[1]));
3077   emit_insn (gen_avx_cvttpd2dq256_2 (r2, operands[2]));
3078   emit_insn (gen_avx_vperm2f128v8si3 (operands[0], r1, r2, GEN_INT (0x20)));
3079   DONE;
3080 })
3081
3082 (define_expand "vec_pack_sfix_trunc_v2df"
3083   [(match_operand:V4SI 0 "register_operand" "")
3084    (match_operand:V2DF 1 "nonimmediate_operand" "")
3085    (match_operand:V2DF 2 "nonimmediate_operand" "")]
3086   "TARGET_SSE2"
3087 {
3088   rtx r1, r2;
3089
3090   r1 = gen_reg_rtx (V4SImode);
3091   r2 = gen_reg_rtx (V4SImode);
3092
3093   emit_insn (gen_sse2_cvttpd2dq (r1, operands[1]));
3094   emit_insn (gen_sse2_cvttpd2dq (r2, operands[2]));
3095   emit_insn (gen_vec_interleave_lowv2di (gen_lowpart (V2DImode, operands[0]),
3096                                          gen_lowpart (V2DImode, r1),
3097                                          gen_lowpart (V2DImode, r2)));
3098   DONE;
3099 })
3100
3101 (define_expand "vec_pack_sfix_v4df"
3102   [(match_operand:V8SI 0 "register_operand" "")
3103    (match_operand:V4DF 1 "nonimmediate_operand" "")
3104    (match_operand:V4DF 2 "nonimmediate_operand" "")]
3105   "TARGET_AVX"
3106 {
3107   rtx r1, r2;
3108
3109   r1 = gen_reg_rtx (V8SImode);
3110   r2 = gen_reg_rtx (V8SImode);
3111
3112   emit_insn (gen_avx_cvtpd2dq256_2 (r1, operands[1]));
3113   emit_insn (gen_avx_cvtpd2dq256_2 (r2, operands[2]));
3114   emit_insn (gen_avx_vperm2f128v8si3 (operands[0], r1, r2, GEN_INT (0x20)));
3115   DONE;
3116 })
3117
3118 (define_expand "vec_pack_sfix_v2df"
3119   [(match_operand:V4SI 0 "register_operand" "")
3120    (match_operand:V2DF 1 "nonimmediate_operand" "")
3121    (match_operand:V2DF 2 "nonimmediate_operand" "")]
3122   "TARGET_SSE2"
3123 {
3124   rtx r1, r2;
3125
3126   r1 = gen_reg_rtx (V4SImode);
3127   r2 = gen_reg_rtx (V4SImode);
3128
3129   emit_insn (gen_sse2_cvtpd2dq (r1, operands[1]));
3130   emit_insn (gen_sse2_cvtpd2dq (r2, operands[2]));
3131   emit_insn (gen_vec_interleave_lowv2di (gen_lowpart (V2DImode, operands[0]),
3132                                          gen_lowpart (V2DImode, r1),
3133                                          gen_lowpart (V2DImode, r2)));
3134   DONE;
3135 })
3136
3137 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3138 ;;
3139 ;; Parallel single-precision floating point element swizzling
3140 ;;
3141 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3142
3143 (define_expand "sse_movhlps_exp"
3144   [(set (match_operand:V4SF 0 "nonimmediate_operand" "")
3145         (vec_select:V4SF
3146           (vec_concat:V8SF
3147             (match_operand:V4SF 1 "nonimmediate_operand" "")
3148             (match_operand:V4SF 2 "nonimmediate_operand" ""))
3149           (parallel [(const_int 6)
3150                      (const_int 7)
3151                      (const_int 2)
3152                      (const_int 3)])))]
3153   "TARGET_SSE"
3154 {
3155   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
3156
3157   emit_insn (gen_sse_movhlps (dst, operands[1], operands[2]));
3158
3159   /* Fix up the destination if needed.  */
3160   if (dst != operands[0])
3161     emit_move_insn (operands[0], dst);
3162
3163   DONE;
3164 })
3165
3166 (define_insn "sse_movhlps"
3167   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,m")
3168         (vec_select:V4SF
3169           (vec_concat:V8SF
3170             (match_operand:V4SF 1 "nonimmediate_operand" " 0,x,0,x,0")
3171             (match_operand:V4SF 2 "nonimmediate_operand" " x,x,o,o,x"))
3172           (parallel [(const_int 6)
3173                      (const_int 7)
3174                      (const_int 2)
3175                      (const_int 3)])))]
3176   "TARGET_SSE && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
3177   "@
3178    movhlps\t{%2, %0|%0, %2}
3179    vmovhlps\t{%2, %1, %0|%0, %1, %2}
3180    movlps\t{%H2, %0|%0, %H2}
3181    vmovlps\t{%H2, %1, %0|%0, %1, %H2}
3182    %vmovhps\t{%2, %0|%0, %2}"
3183   [(set_attr "isa" "noavx,avx,noavx,avx,*")
3184    (set_attr "type" "ssemov")
3185    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
3186    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF,V2SF")])
3187
3188 (define_expand "sse_movlhps_exp"
3189   [(set (match_operand:V4SF 0 "nonimmediate_operand" "")
3190         (vec_select:V4SF
3191           (vec_concat:V8SF
3192             (match_operand:V4SF 1 "nonimmediate_operand" "")
3193             (match_operand:V4SF 2 "nonimmediate_operand" ""))
3194           (parallel [(const_int 0)
3195                      (const_int 1)
3196                      (const_int 4)
3197                      (const_int 5)])))]
3198   "TARGET_SSE"
3199 {
3200   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
3201
3202   emit_insn (gen_sse_movlhps (dst, operands[1], operands[2]));
3203
3204   /* Fix up the destination if needed.  */
3205   if (dst != operands[0])
3206     emit_move_insn (operands[0], dst);
3207
3208   DONE;
3209 })
3210
3211 (define_insn "sse_movlhps"
3212   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,o")
3213         (vec_select:V4SF
3214           (vec_concat:V8SF
3215             (match_operand:V4SF 1 "nonimmediate_operand" " 0,x,0,x,0")
3216             (match_operand:V4SF 2 "nonimmediate_operand" " x,x,m,x,x"))
3217           (parallel [(const_int 0)
3218                      (const_int 1)
3219                      (const_int 4)
3220                      (const_int 5)])))]
3221   "TARGET_SSE && ix86_binary_operator_ok (UNKNOWN, V4SFmode, operands)"
3222   "@
3223    movlhps\t{%2, %0|%0, %2}
3224    vmovlhps\t{%2, %1, %0|%0, %1, %2}
3225    movhps\t{%2, %0|%0, %2}
3226    vmovhps\t{%2, %1, %0|%0, %1, %2}
3227    %vmovlps\t{%2, %H0|%H0, %2}"
3228   [(set_attr "isa" "noavx,avx,noavx,avx,*")
3229    (set_attr "type" "ssemov")
3230    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
3231    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF,V2SF")])
3232
3233 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
3234 (define_insn "avx_unpckhps256"
3235   [(set (match_operand:V8SF 0 "register_operand" "=x")
3236         (vec_select:V8SF
3237           (vec_concat:V16SF
3238             (match_operand:V8SF 1 "register_operand" "x")
3239             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3240           (parallel [(const_int 2) (const_int 10)
3241                      (const_int 3) (const_int 11)
3242                      (const_int 6) (const_int 14)
3243                      (const_int 7) (const_int 15)])))]
3244   "TARGET_AVX"
3245   "vunpckhps\t{%2, %1, %0|%0, %1, %2}"
3246   [(set_attr "type" "sselog")
3247    (set_attr "prefix" "vex")
3248    (set_attr "mode" "V8SF")])
3249
3250 (define_expand "vec_interleave_highv8sf"
3251   [(set (match_dup 3)
3252         (vec_select:V8SF
3253           (vec_concat:V16SF
3254             (match_operand:V8SF 1 "register_operand" "x")
3255             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3256           (parallel [(const_int 0) (const_int 8)
3257                      (const_int 1) (const_int 9)
3258                      (const_int 4) (const_int 12)
3259                      (const_int 5) (const_int 13)])))
3260    (set (match_dup 4)
3261         (vec_select:V8SF
3262           (vec_concat:V16SF
3263             (match_dup 1)
3264             (match_dup 2))
3265           (parallel [(const_int 2) (const_int 10)
3266                      (const_int 3) (const_int 11)
3267                      (const_int 6) (const_int 14)
3268                      (const_int 7) (const_int 15)])))
3269    (set (match_operand:V8SF 0 "register_operand" "")
3270         (vec_select:V8SF
3271           (vec_concat:V16SF
3272             (match_dup 3)
3273             (match_dup 4))
3274           (parallel [(const_int 4) (const_int 5)
3275                      (const_int 6) (const_int 7)
3276                      (const_int 12) (const_int 13)
3277                      (const_int 14) (const_int 15)])))]
3278  "TARGET_AVX"
3279 {
3280   operands[3] = gen_reg_rtx (V8SFmode);
3281   operands[4] = gen_reg_rtx (V8SFmode);
3282 })
3283
3284 (define_insn "vec_interleave_highv4sf"
3285   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
3286         (vec_select:V4SF
3287           (vec_concat:V8SF
3288             (match_operand:V4SF 1 "register_operand" "0,x")
3289             (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm"))
3290           (parallel [(const_int 2) (const_int 6)
3291                      (const_int 3) (const_int 7)])))]
3292   "TARGET_SSE"
3293   "@
3294    unpckhps\t{%2, %0|%0, %2}
3295    vunpckhps\t{%2, %1, %0|%0, %1, %2}"
3296   [(set_attr "isa" "noavx,avx")
3297    (set_attr "type" "sselog")
3298    (set_attr "prefix" "orig,vex")
3299    (set_attr "mode" "V4SF")])
3300
3301 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
3302 (define_insn "avx_unpcklps256"
3303   [(set (match_operand:V8SF 0 "register_operand" "=x")
3304         (vec_select:V8SF
3305           (vec_concat:V16SF
3306             (match_operand:V8SF 1 "register_operand" "x")
3307             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3308           (parallel [(const_int 0) (const_int 8)
3309                      (const_int 1) (const_int 9)
3310                      (const_int 4) (const_int 12)
3311                      (const_int 5) (const_int 13)])))]
3312   "TARGET_AVX"
3313   "vunpcklps\t{%2, %1, %0|%0, %1, %2}"
3314   [(set_attr "type" "sselog")
3315    (set_attr "prefix" "vex")
3316    (set_attr "mode" "V8SF")])
3317
3318 (define_expand "vec_interleave_lowv8sf"
3319   [(set (match_dup 3)
3320         (vec_select:V8SF
3321           (vec_concat:V16SF
3322             (match_operand:V8SF 1 "register_operand" "x")
3323             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3324           (parallel [(const_int 0) (const_int 8)
3325                      (const_int 1) (const_int 9)
3326                      (const_int 4) (const_int 12)
3327                      (const_int 5) (const_int 13)])))
3328    (set (match_dup 4)
3329         (vec_select:V8SF
3330           (vec_concat:V16SF
3331             (match_dup 1)
3332             (match_dup 2))
3333           (parallel [(const_int 2) (const_int 10)
3334                      (const_int 3) (const_int 11)
3335                      (const_int 6) (const_int 14)
3336                      (const_int 7) (const_int 15)])))
3337    (set (match_operand:V8SF 0 "register_operand" "")
3338         (vec_select:V8SF
3339           (vec_concat:V16SF
3340             (match_dup 3)
3341             (match_dup 4))
3342           (parallel [(const_int 0) (const_int 1)
3343                      (const_int 2) (const_int 3)
3344                      (const_int 8) (const_int 9)
3345                      (const_int 10) (const_int 11)])))]
3346  "TARGET_AVX"
3347 {
3348   operands[3] = gen_reg_rtx (V8SFmode);
3349   operands[4] = gen_reg_rtx (V8SFmode);
3350 })
3351
3352 (define_insn "vec_interleave_lowv4sf"
3353   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
3354         (vec_select:V4SF
3355           (vec_concat:V8SF
3356             (match_operand:V4SF 1 "register_operand" "0,x")
3357             (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm"))
3358           (parallel [(const_int 0) (const_int 4)
3359                      (const_int 1) (const_int 5)])))]
3360   "TARGET_SSE"
3361   "@
3362    unpcklps\t{%2, %0|%0, %2}
3363    vunpcklps\t{%2, %1, %0|%0, %1, %2}"
3364   [(set_attr "isa" "noavx,avx")
3365    (set_attr "type" "sselog")
3366    (set_attr "prefix" "orig,vex")
3367    (set_attr "mode" "V4SF")])
3368
3369 ;; These are modeled with the same vec_concat as the others so that we
3370 ;; capture users of shufps that can use the new instructions
3371 (define_insn "avx_movshdup256"
3372   [(set (match_operand:V8SF 0 "register_operand" "=x")
3373         (vec_select:V8SF
3374           (vec_concat:V16SF
3375             (match_operand:V8SF 1 "nonimmediate_operand" "xm")
3376             (match_dup 1))
3377           (parallel [(const_int 1) (const_int 1)
3378                      (const_int 3) (const_int 3)
3379                      (const_int 5) (const_int 5)
3380                      (const_int 7) (const_int 7)])))]
3381   "TARGET_AVX"
3382   "vmovshdup\t{%1, %0|%0, %1}"
3383   [(set_attr "type" "sse")
3384    (set_attr "prefix" "vex")
3385    (set_attr "mode" "V8SF")])
3386
3387 (define_insn "sse3_movshdup"
3388   [(set (match_operand:V4SF 0 "register_operand" "=x")
3389         (vec_select:V4SF
3390           (vec_concat:V8SF
3391             (match_operand:V4SF 1 "nonimmediate_operand" "xm")
3392             (match_dup 1))
3393           (parallel [(const_int 1)
3394                      (const_int 1)
3395                      (const_int 7)
3396                      (const_int 7)])))]
3397   "TARGET_SSE3"
3398   "%vmovshdup\t{%1, %0|%0, %1}"
3399   [(set_attr "type" "sse")
3400    (set_attr "prefix_rep" "1")
3401    (set_attr "prefix" "maybe_vex")
3402    (set_attr "mode" "V4SF")])
3403
3404 (define_insn "avx_movsldup256"
3405   [(set (match_operand:V8SF 0 "register_operand" "=x")
3406         (vec_select:V8SF
3407           (vec_concat:V16SF
3408             (match_operand:V8SF 1 "nonimmediate_operand" "xm")
3409             (match_dup 1))
3410           (parallel [(const_int 0) (const_int 0)
3411                      (const_int 2) (const_int 2)
3412                      (const_int 4) (const_int 4)
3413                      (const_int 6) (const_int 6)])))]
3414   "TARGET_AVX"
3415   "vmovsldup\t{%1, %0|%0, %1}"
3416   [(set_attr "type" "sse")
3417    (set_attr "prefix" "vex")
3418    (set_attr "mode" "V8SF")])
3419
3420 (define_insn "sse3_movsldup"
3421   [(set (match_operand:V4SF 0 "register_operand" "=x")
3422         (vec_select:V4SF
3423           (vec_concat:V8SF
3424             (match_operand:V4SF 1 "nonimmediate_operand" "xm")
3425             (match_dup 1))
3426           (parallel [(const_int 0)
3427                      (const_int 0)
3428                      (const_int 6)
3429                      (const_int 6)])))]
3430   "TARGET_SSE3"
3431   "%vmovsldup\t{%1, %0|%0, %1}"
3432   [(set_attr "type" "sse")
3433    (set_attr "prefix_rep" "1")
3434    (set_attr "prefix" "maybe_vex")
3435    (set_attr "mode" "V4SF")])
3436
3437 (define_expand "avx_shufps256"
3438   [(match_operand:V8SF 0 "register_operand" "")
3439    (match_operand:V8SF 1 "register_operand" "")
3440    (match_operand:V8SF 2 "nonimmediate_operand" "")
3441    (match_operand:SI 3 "const_int_operand" "")]
3442   "TARGET_AVX"
3443 {
3444   int mask = INTVAL (operands[3]);
3445   emit_insn (gen_avx_shufps256_1 (operands[0], operands[1], operands[2],
3446                                   GEN_INT ((mask >> 0) & 3),
3447                                   GEN_INT ((mask >> 2) & 3),
3448                                   GEN_INT (((mask >> 4) & 3) + 8),
3449                                   GEN_INT (((mask >> 6) & 3) + 8),
3450                                   GEN_INT (((mask >> 0) & 3) + 4),
3451                                   GEN_INT (((mask >> 2) & 3) + 4),
3452                                   GEN_INT (((mask >> 4) & 3) + 12),
3453                                   GEN_INT (((mask >> 6) & 3) + 12)));
3454   DONE;
3455 })
3456
3457 ;; One bit in mask selects 2 elements.
3458 (define_insn "avx_shufps256_1"
3459   [(set (match_operand:V8SF 0 "register_operand" "=x")
3460         (vec_select:V8SF
3461           (vec_concat:V16SF
3462             (match_operand:V8SF 1 "register_operand" "x")
3463             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3464           (parallel [(match_operand 3  "const_0_to_3_operand"   "")
3465                      (match_operand 4  "const_0_to_3_operand"   "")
3466                      (match_operand 5  "const_8_to_11_operand"  "")
3467                      (match_operand 6  "const_8_to_11_operand"  "")
3468                      (match_operand 7  "const_4_to_7_operand"   "")
3469                      (match_operand 8  "const_4_to_7_operand"   "")
3470                      (match_operand 9  "const_12_to_15_operand" "")
3471                      (match_operand 10 "const_12_to_15_operand" "")])))]
3472   "TARGET_AVX
3473    && (INTVAL (operands[3]) == (INTVAL (operands[7]) - 4)
3474        && INTVAL (operands[4]) == (INTVAL (operands[8]) - 4)
3475        && INTVAL (operands[5]) == (INTVAL (operands[9]) - 4)
3476        && INTVAL (operands[6]) == (INTVAL (operands[10]) - 4))"
3477 {
3478   int mask;
3479   mask = INTVAL (operands[3]);
3480   mask |= INTVAL (operands[4]) << 2;
3481   mask |= (INTVAL (operands[5]) - 8) << 4;
3482   mask |= (INTVAL (operands[6]) - 8) << 6;
3483   operands[3] = GEN_INT (mask);
3484
3485   return "vshufps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
3486 }
3487   [(set_attr "type" "sselog")
3488    (set_attr "length_immediate" "1")
3489    (set_attr "prefix" "vex")
3490    (set_attr "mode" "V8SF")])
3491
3492 (define_expand "sse_shufps"
3493   [(match_operand:V4SF 0 "register_operand" "")
3494    (match_operand:V4SF 1 "register_operand" "")
3495    (match_operand:V4SF 2 "nonimmediate_operand" "")
3496    (match_operand:SI 3 "const_int_operand" "")]
3497   "TARGET_SSE"
3498 {
3499   int mask = INTVAL (operands[3]);
3500   emit_insn (gen_sse_shufps_v4sf (operands[0], operands[1], operands[2],
3501                                GEN_INT ((mask >> 0) & 3),
3502                                GEN_INT ((mask >> 2) & 3),
3503                                GEN_INT (((mask >> 4) & 3) + 4),
3504                                GEN_INT (((mask >> 6) & 3) + 4)));
3505   DONE;
3506 })
3507
3508 (define_insn "sse_shufps_<mode>"
3509   [(set (match_operand:VI4F_128 0 "register_operand" "=x,x")
3510         (vec_select:VI4F_128
3511           (vec_concat:<ssedoublevecmode>
3512             (match_operand:VI4F_128 1 "register_operand" "0,x")
3513             (match_operand:VI4F_128 2 "nonimmediate_operand" "xm,xm"))
3514           (parallel [(match_operand 3 "const_0_to_3_operand" "")
3515                      (match_operand 4 "const_0_to_3_operand" "")
3516                      (match_operand 5 "const_4_to_7_operand" "")
3517                      (match_operand 6 "const_4_to_7_operand" "")])))]
3518   "TARGET_SSE"
3519 {
3520   int mask = 0;
3521   mask |= INTVAL (operands[3]) << 0;
3522   mask |= INTVAL (operands[4]) << 2;
3523   mask |= (INTVAL (operands[5]) - 4) << 4;
3524   mask |= (INTVAL (operands[6]) - 4) << 6;
3525   operands[3] = GEN_INT (mask);
3526
3527   switch (which_alternative)
3528     {
3529     case 0:
3530       return "shufps\t{%3, %2, %0|%0, %2, %3}";
3531     case 1:
3532       return "vshufps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
3533     default:
3534       gcc_unreachable ();
3535     }
3536 }
3537   [(set_attr "isa" "noavx,avx")
3538    (set_attr "type" "sselog")
3539    (set_attr "length_immediate" "1")
3540    (set_attr "prefix" "orig,vex")
3541    (set_attr "mode" "V4SF")])
3542
3543 (define_insn "sse_storehps"
3544   [(set (match_operand:V2SF 0 "nonimmediate_operand" "=m,x,x")
3545         (vec_select:V2SF
3546           (match_operand:V4SF 1 "nonimmediate_operand" "x,x,o")
3547           (parallel [(const_int 2) (const_int 3)])))]
3548   "TARGET_SSE"
3549   "@
3550    %vmovhps\t{%1, %0|%0, %1}
3551    %vmovhlps\t{%1, %d0|%d0, %1}
3552    %vmovlps\t{%H1, %d0|%d0, %H1}"
3553   [(set_attr "type" "ssemov")
3554    (set_attr "prefix" "maybe_vex")
3555    (set_attr "mode" "V2SF,V4SF,V2SF")])
3556
3557 (define_expand "sse_loadhps_exp"
3558   [(set (match_operand:V4SF 0 "nonimmediate_operand" "")
3559         (vec_concat:V4SF
3560           (vec_select:V2SF
3561             (match_operand:V4SF 1 "nonimmediate_operand" "")
3562             (parallel [(const_int 0) (const_int 1)]))
3563           (match_operand:V2SF 2 "nonimmediate_operand" "")))]
3564   "TARGET_SSE"
3565 {
3566   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
3567
3568   emit_insn (gen_sse_loadhps (dst, operands[1], operands[2]));
3569
3570   /* Fix up the destination if needed.  */
3571   if (dst != operands[0])
3572     emit_move_insn (operands[0], dst);
3573
3574   DONE;
3575 })
3576
3577 (define_insn "sse_loadhps"
3578   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,o")
3579         (vec_concat:V4SF
3580           (vec_select:V2SF
3581             (match_operand:V4SF 1 "nonimmediate_operand" " 0,x,0,x,0")
3582             (parallel [(const_int 0) (const_int 1)]))
3583           (match_operand:V2SF 2 "nonimmediate_operand"   " m,m,x,x,x")))]
3584   "TARGET_SSE"
3585   "@
3586    movhps\t{%2, %0|%0, %2}
3587    vmovhps\t{%2, %1, %0|%0, %1, %2}
3588    movlhps\t{%2, %0|%0, %2}
3589    vmovlhps\t{%2, %1, %0|%0, %1, %2}
3590    %vmovlps\t{%2, %H0|%H0, %2}"
3591   [(set_attr "isa" "noavx,avx,noavx,avx,*")
3592    (set_attr "type" "ssemov")
3593    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
3594    (set_attr "mode" "V2SF,V2SF,V4SF,V4SF,V2SF")])
3595
3596 (define_insn "sse_storelps"
3597   [(set (match_operand:V2SF 0 "nonimmediate_operand"   "=m,x,x")
3598         (vec_select:V2SF
3599           (match_operand:V4SF 1 "nonimmediate_operand" " x,x,m")
3600           (parallel [(const_int 0) (const_int 1)])))]
3601   "TARGET_SSE"
3602   "@
3603    %vmovlps\t{%1, %0|%0, %1}
3604    %vmovaps\t{%1, %0|%0, %1}
3605    %vmovlps\t{%1, %d0|%d0, %1}"
3606   [(set_attr "type" "ssemov")
3607    (set_attr "prefix" "maybe_vex")
3608    (set_attr "mode" "V2SF,V4SF,V2SF")])
3609
3610 (define_expand "sse_loadlps_exp"
3611   [(set (match_operand:V4SF 0 "nonimmediate_operand" "")
3612         (vec_concat:V4SF
3613           (match_operand:V2SF 2 "nonimmediate_operand" "")
3614           (vec_select:V2SF
3615             (match_operand:V4SF 1 "nonimmediate_operand" "")
3616             (parallel [(const_int 2) (const_int 3)]))))]
3617   "TARGET_SSE"
3618 {
3619   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
3620
3621   emit_insn (gen_sse_loadlps (dst, operands[1], operands[2]));
3622
3623   /* Fix up the destination if needed.  */
3624   if (dst != operands[0])
3625     emit_move_insn (operands[0], dst);
3626
3627   DONE;
3628 })
3629
3630 (define_insn "sse_loadlps"
3631   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,m")
3632         (vec_concat:V4SF
3633           (match_operand:V2SF 2 "nonimmediate_operand"   " 0,x,m,x,x")
3634           (vec_select:V2SF
3635             (match_operand:V4SF 1 "nonimmediate_operand" " x,x,0,x,0")
3636             (parallel [(const_int 2) (const_int 3)]))))]
3637   "TARGET_SSE"
3638   "@
3639    shufps\t{$0xe4, %1, %0|%0, %1, 0xe4}
3640    vshufps\t{$0xe4, %1, %2, %0|%0, %2, %1, 0xe4}
3641    movlps\t{%2, %0|%0, %2}
3642    vmovlps\t{%2, %1, %0|%0, %1, %2}
3643    %vmovlps\t{%2, %0|%0, %2}"
3644   [(set_attr "isa" "noavx,avx,noavx,avx,*")
3645    (set_attr "type" "sselog,sselog,ssemov,ssemov,ssemov")
3646    (set_attr "length_immediate" "1,1,*,*,*")
3647    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
3648    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF,V2SF")])
3649
3650 (define_insn "sse_movss"
3651   [(set (match_operand:V4SF 0 "register_operand"   "=x,x")
3652         (vec_merge:V4SF
3653           (match_operand:V4SF 2 "register_operand" " x,x")
3654           (match_operand:V4SF 1 "register_operand" " 0,x")
3655           (const_int 1)))]
3656   "TARGET_SSE"
3657   "@
3658    movss\t{%2, %0|%0, %2}
3659    vmovss\t{%2, %1, %0|%0, %1, %2}"
3660   [(set_attr "isa" "noavx,avx")
3661    (set_attr "type" "ssemov")
3662    (set_attr "prefix" "orig,vex")
3663    (set_attr "mode" "SF")])
3664
3665 (define_expand "vec_dupv4sf"
3666   [(set (match_operand:V4SF 0 "register_operand" "")
3667         (vec_duplicate:V4SF
3668           (match_operand:SF 1 "nonimmediate_operand" "")))]
3669   "TARGET_SSE"
3670 {
3671   if (!TARGET_AVX)
3672     operands[1] = force_reg (SFmode, operands[1]);
3673 })
3674
3675 (define_insn "avx2_vec_dupv4sf"
3676   [(set (match_operand:V4SF 0 "register_operand" "=x")
3677         (vec_duplicate:V4SF
3678           (vec_select:SF
3679             (match_operand:V4SF 1 "register_operand" "x")
3680             (parallel [(const_int 0)]))))]
3681   "TARGET_AVX2"
3682   "vbroadcastss\t{%1, %0|%0, %1}"
3683   [(set_attr "type" "sselog1")
3684     (set_attr "prefix" "vex")
3685     (set_attr "mode" "V4SF")])
3686
3687 (define_insn "*vec_dupv4sf_avx"
3688   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
3689         (vec_duplicate:V4SF
3690           (match_operand:SF 1 "nonimmediate_operand" "x,m")))]
3691   "TARGET_AVX"
3692   "@
3693    vshufps\t{$0, %1, %1, %0|%0, %1, %1, 0}
3694    vbroadcastss\t{%1, %0|%0, %1}"
3695   [(set_attr "type" "sselog1,ssemov")
3696    (set_attr "length_immediate" "1,0")
3697    (set_attr "prefix_extra" "0,1")
3698    (set_attr "prefix" "vex")
3699    (set_attr "mode" "V4SF")])
3700
3701 (define_insn "avx2_vec_dupv8sf"
3702   [(set (match_operand:V8SF 0 "register_operand" "=x")
3703         (vec_duplicate:V8SF
3704           (vec_select:SF
3705             (match_operand:V4SF 1 "register_operand" "x")
3706             (parallel [(const_int 0)]))))]
3707   "TARGET_AVX2"
3708   "vbroadcastss\t{%1, %0|%0, %1}"
3709   [(set_attr "type" "sselog1")
3710    (set_attr "prefix" "vex")
3711    (set_attr "mode" "V8SF")])
3712
3713 (define_insn "*vec_dupv4sf"
3714   [(set (match_operand:V4SF 0 "register_operand" "=x")
3715         (vec_duplicate:V4SF
3716           (match_operand:SF 1 "register_operand" "0")))]
3717   "TARGET_SSE"
3718   "shufps\t{$0, %0, %0|%0, %0, 0}"
3719   [(set_attr "type" "sselog1")
3720    (set_attr "length_immediate" "1")
3721    (set_attr "mode" "V4SF")])
3722
3723 ;; Although insertps takes register source, we prefer
3724 ;; unpcklps with register source since it is shorter.
3725 (define_insn "*vec_concatv2sf_sse4_1"
3726   [(set (match_operand:V2SF 0 "register_operand"     "=x,x,x,x,x,*y ,*y")
3727         (vec_concat:V2SF
3728           (match_operand:SF 1 "nonimmediate_operand" " 0,x,0,x,m, 0 , m")
3729           (match_operand:SF 2 "vector_move_operand"  " x,x,m,m,C,*ym, C")))]
3730   "TARGET_SSE4_1"
3731   "@
3732    unpcklps\t{%2, %0|%0, %2}
3733    vunpcklps\t{%2, %1, %0|%0, %1, %2}
3734    insertps\t{$0x10, %2, %0|%0, %2, 0x10}
3735    vinsertps\t{$0x10, %2, %1, %0|%0, %1, %2, 0x10}
3736    %vmovss\t{%1, %0|%0, %1}
3737    punpckldq\t{%2, %0|%0, %2}
3738    movd\t{%1, %0|%0, %1}"
3739   [(set_attr "isa" "noavx,avx,noavx,avx,*,*,*")
3740    (set_attr "type" "sselog,sselog,sselog,sselog,ssemov,mmxcvt,mmxmov")
3741    (set_attr "prefix_data16" "*,*,1,*,*,*,*")
3742    (set_attr "prefix_extra" "*,*,1,1,*,*,*")
3743    (set_attr "length_immediate" "*,*,1,1,*,*,*")
3744    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex,orig,orig")
3745    (set_attr "mode" "V4SF,V4SF,V4SF,V4SF,SF,DI,DI")])
3746
3747 ;; ??? In theory we can match memory for the MMX alternative, but allowing
3748 ;; nonimmediate_operand for operand 2 and *not* allowing memory for the SSE
3749 ;; alternatives pretty much forces the MMX alternative to be chosen.
3750 (define_insn "*vec_concatv2sf_sse"
3751   [(set (match_operand:V2SF 0 "register_operand"     "=x,x,*y,*y")
3752         (vec_concat:V2SF
3753           (match_operand:SF 1 "nonimmediate_operand" " 0,m, 0, m")
3754           (match_operand:SF 2 "reg_or_0_operand"     " x,C,*y, C")))]
3755   "TARGET_SSE"
3756   "@
3757    unpcklps\t{%2, %0|%0, %2}
3758    movss\t{%1, %0|%0, %1}
3759    punpckldq\t{%2, %0|%0, %2}
3760    movd\t{%1, %0|%0, %1}"
3761   [(set_attr "type" "sselog,ssemov,mmxcvt,mmxmov")
3762    (set_attr "mode" "V4SF,SF,DI,DI")])
3763
3764 (define_insn "*vec_concatv4sf"
3765   [(set (match_operand:V4SF 0 "register_operand"       "=x,x,x,x")
3766         (vec_concat:V4SF
3767           (match_operand:V2SF 1 "register_operand"     " 0,x,0,x")
3768           (match_operand:V2SF 2 "nonimmediate_operand" " x,x,m,m")))]
3769   "TARGET_SSE"
3770   "@
3771    movlhps\t{%2, %0|%0, %2}
3772    vmovlhps\t{%2, %1, %0|%0, %1, %2}
3773    movhps\t{%2, %0|%0, %2}
3774    vmovhps\t{%2, %1, %0|%0, %1, %2}"
3775   [(set_attr "isa" "noavx,avx,noavx,avx")
3776    (set_attr "type" "ssemov")
3777    (set_attr "prefix" "orig,vex,orig,vex")
3778    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF")])
3779
3780 (define_expand "vec_init<mode>"
3781   [(match_operand:V_128 0 "register_operand" "")
3782    (match_operand 1 "" "")]
3783   "TARGET_SSE"
3784 {
3785   ix86_expand_vector_init (false, operands[0], operands[1]);
3786   DONE;
3787 })
3788
3789 ;; Avoid combining registers from different units in a single alternative,
3790 ;; see comment above inline_secondary_memory_needed function in i386.c
3791 (define_insn "vec_set<mode>_0"
3792   [(set (match_operand:VI4F_128 0 "nonimmediate_operand"
3793           "=x,x,x ,x,x,x,x  ,x  ,m,m ,m")
3794         (vec_merge:VI4F_128
3795           (vec_duplicate:VI4F_128
3796             (match_operand:<ssescalarmode> 2 "general_operand"
3797           " x,m,*r,m,x,x,*rm,*rm,x,fF,*r"))
3798           (match_operand:VI4F_128 1 "vector_move_operand"
3799           " C,C,C ,C,0,x,0  ,x  ,0,0 ,0")
3800           (const_int 1)))]
3801   "TARGET_SSE"
3802   "@
3803    %vinsertps\t{$0xe, %d2, %0|%0, %d2, 0xe}
3804    %vmov<ssescalarmodesuffix>\t{%2, %0|%0, %2}
3805    %vmovd\t{%2, %0|%0, %2}
3806    movss\t{%2, %0|%0, %2}
3807    movss\t{%2, %0|%0, %2}
3808    vmovss\t{%2, %1, %0|%0, %1, %2}
3809    pinsrd\t{$0, %2, %0|%0, %2, 0}
3810    vpinsrd\t{$0, %2, %1, %0|%0, %1, %2, 0}
3811    #
3812    #
3813    #"
3814   [(set_attr "isa" "sse4,sse2,sse2,noavx,noavx,avx,sse4_noavx,avx,*,*,*")
3815    (set (attr "type")
3816      (cond [(eq_attr "alternative" "0,6,7")
3817               (const_string "sselog")
3818             (eq_attr "alternative" "9")
3819               (const_string "fmov")
3820             (eq_attr "alternative" "10")
3821               (const_string "imov")
3822            ]
3823            (const_string "ssemov")))
3824    (set_attr "prefix_extra" "*,*,*,*,*,*,1,1,*,*,*")
3825    (set_attr "length_immediate" "*,*,*,*,*,*,1,1,*,*,*")
3826    (set_attr "prefix" "maybe_vex,maybe_vex,maybe_vex,orig,orig,vex,orig,vex,*,*,*")
3827    (set_attr "mode" "SF,<ssescalarmode>,SI,SF,SF,SF,TI,TI,*,*,*")])
3828
3829 ;; A subset is vec_setv4sf.
3830 (define_insn "*vec_setv4sf_sse4_1"
3831   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
3832         (vec_merge:V4SF
3833           (vec_duplicate:V4SF
3834             (match_operand:SF 2 "nonimmediate_operand" "xm,xm"))
3835           (match_operand:V4SF 1 "register_operand" "0,x")
3836           (match_operand:SI 3 "const_int_operand" "")))]
3837   "TARGET_SSE4_1
3838    && ((unsigned) exact_log2 (INTVAL (operands[3]))
3839        < GET_MODE_NUNITS (V4SFmode))"
3840 {
3841   operands[3] = GEN_INT (exact_log2 (INTVAL (operands[3])) << 4);
3842   switch (which_alternative)
3843     {
3844     case 0:
3845       return "insertps\t{%3, %2, %0|%0, %2, %3}";
3846     case 1:
3847       return "vinsertps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
3848     default:
3849       gcc_unreachable ();
3850     }
3851 }
3852   [(set_attr "isa" "noavx,avx")
3853    (set_attr "type" "sselog")
3854    (set_attr "prefix_data16" "1,*")
3855    (set_attr "prefix_extra" "1")
3856    (set_attr "length_immediate" "1")
3857    (set_attr "prefix" "orig,vex")
3858    (set_attr "mode" "V4SF")])
3859
3860 (define_insn "sse4_1_insertps"
3861   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
3862         (unspec:V4SF [(match_operand:V4SF 2 "nonimmediate_operand" "xm,xm")
3863                       (match_operand:V4SF 1 "register_operand" "0,x")
3864                       (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
3865                      UNSPEC_INSERTPS))]
3866   "TARGET_SSE4_1"
3867 {
3868   if (MEM_P (operands[2]))
3869     {
3870       unsigned count_s = INTVAL (operands[3]) >> 6;
3871       if (count_s)
3872         operands[3] = GEN_INT (INTVAL (operands[3]) & 0x3f);
3873       operands[2] = adjust_address_nv (operands[2], SFmode, count_s * 4);
3874     }
3875   switch (which_alternative)
3876     {
3877     case 0:
3878       return "insertps\t{%3, %2, %0|%0, %2, %3}";
3879     case 1:
3880       return "vinsertps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
3881     default:
3882       gcc_unreachable ();
3883     }
3884 }
3885   [(set_attr "isa" "noavx,avx")
3886    (set_attr "type" "sselog")
3887    (set_attr "prefix_data16" "1,*")
3888    (set_attr "prefix_extra" "1")
3889    (set_attr "length_immediate" "1")
3890    (set_attr "prefix" "orig,vex")
3891    (set_attr "mode" "V4SF")])
3892
3893 (define_split
3894   [(set (match_operand:VI4F_128 0 "memory_operand" "")
3895         (vec_merge:VI4F_128
3896           (vec_duplicate:VI4F_128
3897             (match_operand:<ssescalarmode> 1 "nonmemory_operand" ""))
3898           (match_dup 0)
3899           (const_int 1)))]
3900   "TARGET_SSE && reload_completed"
3901   [(const_int 0)]
3902 {
3903   emit_move_insn (adjust_address (operands[0], <ssescalarmode>mode, 0),
3904                   operands[1]);
3905   DONE;
3906 })
3907
3908 (define_expand "vec_set<mode>"
3909   [(match_operand:V 0 "register_operand" "")
3910    (match_operand:<ssescalarmode> 1 "register_operand" "")
3911    (match_operand 2 "const_int_operand" "")]
3912   "TARGET_SSE"
3913 {
3914   ix86_expand_vector_set (false, operands[0], operands[1],
3915                           INTVAL (operands[2]));
3916   DONE;
3917 })
3918
3919 (define_insn_and_split "*vec_extractv4sf_0"
3920   [(set (match_operand:SF 0 "nonimmediate_operand" "=x,m,f,r")
3921         (vec_select:SF
3922           (match_operand:V4SF 1 "nonimmediate_operand" "xm,x,m,m")
3923           (parallel [(const_int 0)])))]
3924   "TARGET_SSE && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
3925   "#"
3926   "&& reload_completed"
3927   [(const_int 0)]
3928 {
3929   rtx op1 = operands[1];
3930   if (REG_P (op1))
3931     op1 = gen_rtx_REG (SFmode, REGNO (op1));
3932   else
3933     op1 = gen_lowpart (SFmode, op1);
3934   emit_move_insn (operands[0], op1);
3935   DONE;
3936 })
3937
3938 (define_insn_and_split "*sse4_1_extractps"
3939   [(set (match_operand:SF 0 "nonimmediate_operand" "=rm,x,x")
3940         (vec_select:SF
3941           (match_operand:V4SF 1 "register_operand" "x,0,x")
3942           (parallel [(match_operand:SI 2 "const_0_to_3_operand" "n,n,n")])))]
3943   "TARGET_SSE4_1"
3944   "@
3945    %vextractps\t{%2, %1, %0|%0, %1, %2}
3946    #
3947    #"
3948   "&& reload_completed && SSE_REG_P (operands[0])"
3949   [(const_int 0)]
3950 {
3951   rtx dest = gen_rtx_REG (V4SFmode, REGNO (operands[0]));
3952   switch (INTVAL (operands[2]))
3953     {
3954     case 1:
3955     case 3:
3956       emit_insn (gen_sse_shufps_v4sf (dest, operands[1], operands[1],
3957                                       operands[2], operands[2],
3958                                       GEN_INT (INTVAL (operands[2]) + 4),
3959                                       GEN_INT (INTVAL (operands[2]) + 4)));
3960       break;
3961     case 2:
3962       emit_insn (gen_vec_interleave_highv4sf (dest, operands[1], operands[1]));
3963       break;
3964     default:
3965       /* 0 should be handled by the *vec_extractv4sf_0 pattern above.  */
3966       gcc_unreachable ();
3967     }
3968   DONE;
3969 }
3970   [(set_attr "isa" "*,noavx,avx")
3971    (set_attr "type" "sselog,*,*")
3972    (set_attr "prefix_data16" "1,*,*")
3973    (set_attr "prefix_extra" "1,*,*")
3974    (set_attr "length_immediate" "1,*,*")
3975    (set_attr "prefix" "maybe_vex,*,*")
3976    (set_attr "mode" "V4SF,*,*")])
3977
3978 (define_insn_and_split "*vec_extract_v4sf_mem"
3979   [(set (match_operand:SF 0 "register_operand" "=x,*r,f")
3980        (vec_select:SF
3981          (match_operand:V4SF 1 "memory_operand" "o,o,o")
3982          (parallel [(match_operand 2 "const_0_to_3_operand" "n,n,n")])))]
3983   "TARGET_SSE"
3984   "#"
3985   "&& reload_completed"
3986   [(const_int 0)]
3987 {
3988   int i = INTVAL (operands[2]);
3989
3990   emit_move_insn (operands[0], adjust_address (operands[1], SFmode, i*4));
3991   DONE;
3992 })
3993
3994 (define_expand "avx_vextractf128<mode>"
3995   [(match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "")
3996    (match_operand:V_256 1 "register_operand" "")
3997    (match_operand:SI 2 "const_0_to_1_operand" "")]
3998   "TARGET_AVX"
3999 {
4000   rtx (*insn)(rtx, rtx);
4001
4002   switch (INTVAL (operands[2]))
4003     {
4004     case 0:
4005       insn = gen_vec_extract_lo_<mode>;
4006       break;
4007     case 1:
4008       insn = gen_vec_extract_hi_<mode>;
4009       break;
4010     default:
4011       gcc_unreachable ();
4012     }
4013
4014   emit_insn (insn (operands[0], operands[1]));
4015   DONE;
4016 })
4017
4018 (define_insn_and_split "vec_extract_lo_<mode>"
4019   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "=x,m")
4020         (vec_select:<ssehalfvecmode>
4021           (match_operand:VI8F_256 1 "nonimmediate_operand" "xm,x")
4022           (parallel [(const_int 0) (const_int 1)])))]
4023   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4024   "#"
4025   "&& reload_completed"
4026   [(const_int 0)]
4027 {
4028   rtx op1 = operands[1];
4029   if (REG_P (op1))
4030     op1 = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (op1));
4031   else
4032     op1 = gen_lowpart (<ssehalfvecmode>mode, op1);
4033   emit_move_insn (operands[0], op1);
4034   DONE;
4035 })
4036
4037 (define_insn "vec_extract_hi_<mode>"
4038   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "=x,m")
4039         (vec_select:<ssehalfvecmode>
4040           (match_operand:VI8F_256 1 "register_operand" "x,x")
4041           (parallel [(const_int 2) (const_int 3)])))]
4042   "TARGET_AVX"
4043   "vextract<i128>\t{$0x1, %1, %0|%0, %1, 0x1}"
4044   [(set_attr "type" "sselog")
4045    (set_attr "prefix_extra" "1")
4046    (set_attr "length_immediate" "1")
4047    (set_attr "memory" "none,store")
4048    (set_attr "prefix" "vex")
4049    (set_attr "mode" "<sseinsnmode>")])
4050
4051 (define_insn_and_split "vec_extract_lo_<mode>"
4052   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "=x,m")
4053         (vec_select:<ssehalfvecmode>
4054           (match_operand:VI4F_256 1 "nonimmediate_operand" "xm,x")
4055           (parallel [(const_int 0) (const_int 1)
4056                      (const_int 2) (const_int 3)])))]
4057   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4058   "#"
4059   "&& reload_completed"
4060   [(const_int 0)]
4061 {
4062   rtx op1 = operands[1];
4063   if (REG_P (op1))
4064     op1 = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (op1));
4065   else
4066     op1 = gen_lowpart (<ssehalfvecmode>mode, op1);
4067   emit_move_insn (operands[0], op1);
4068   DONE;
4069 })
4070
4071 (define_insn "vec_extract_hi_<mode>"
4072   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "=x,m")
4073         (vec_select:<ssehalfvecmode>
4074           (match_operand:VI4F_256 1 "register_operand" "x,x")
4075           (parallel [(const_int 4) (const_int 5)
4076                      (const_int 6) (const_int 7)])))]
4077   "TARGET_AVX"
4078   "vextract<i128>\t{$0x1, %1, %0|%0, %1, 0x1}"
4079   [(set_attr "type" "sselog")
4080    (set_attr "prefix_extra" "1")
4081    (set_attr "length_immediate" "1")
4082    (set_attr "memory" "none,store")
4083    (set_attr "prefix" "vex")
4084    (set_attr "mode" "<sseinsnmode>")])
4085
4086 (define_insn_and_split "vec_extract_lo_v16hi"
4087   [(set (match_operand:V8HI 0 "nonimmediate_operand" "=x,m")
4088         (vec_select:V8HI
4089           (match_operand:V16HI 1 "nonimmediate_operand" "xm,x")
4090           (parallel [(const_int 0) (const_int 1)
4091                      (const_int 2) (const_int 3)
4092                      (const_int 4) (const_int 5)
4093                      (const_int 6) (const_int 7)])))]
4094   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4095   "#"
4096   "&& reload_completed"
4097   [(const_int 0)]
4098 {
4099   rtx op1 = operands[1];
4100   if (REG_P (op1))
4101     op1 = gen_rtx_REG (V8HImode, REGNO (op1));
4102   else
4103     op1 = gen_lowpart (V8HImode, op1);
4104   emit_move_insn (operands[0], op1);
4105   DONE;
4106 })
4107
4108 (define_insn "vec_extract_hi_v16hi"
4109   [(set (match_operand:V8HI 0 "nonimmediate_operand" "=x,m")
4110         (vec_select:V8HI
4111           (match_operand:V16HI 1 "register_operand" "x,x")
4112           (parallel [(const_int 8) (const_int 9)
4113                      (const_int 10) (const_int 11)
4114                      (const_int 12) (const_int 13)
4115                      (const_int 14) (const_int 15)])))]
4116   "TARGET_AVX"
4117   "vextract%~128\t{$0x1, %1, %0|%0, %1, 0x1}"
4118   [(set_attr "type" "sselog")
4119    (set_attr "prefix_extra" "1")
4120    (set_attr "length_immediate" "1")
4121    (set_attr "memory" "none,store")
4122    (set_attr "prefix" "vex")
4123    (set_attr "mode" "OI")])
4124
4125 (define_insn_and_split "vec_extract_lo_v32qi"
4126   [(set (match_operand:V16QI 0 "nonimmediate_operand" "=x,m")
4127         (vec_select:V16QI
4128           (match_operand:V32QI 1 "nonimmediate_operand" "xm,x")
4129           (parallel [(const_int 0) (const_int 1)
4130                      (const_int 2) (const_int 3)
4131                      (const_int 4) (const_int 5)
4132                      (const_int 6) (const_int 7)
4133                      (const_int 8) (const_int 9)
4134                      (const_int 10) (const_int 11)
4135                      (const_int 12) (const_int 13)
4136                      (const_int 14) (const_int 15)])))]
4137   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4138   "#"
4139   "&& reload_completed"
4140   [(const_int 0)]
4141 {
4142   rtx op1 = operands[1];
4143   if (REG_P (op1))
4144     op1 = gen_rtx_REG (V16QImode, REGNO (op1));
4145   else
4146     op1 = gen_lowpart (V16QImode, op1);
4147   emit_move_insn (operands[0], op1);
4148   DONE;
4149 })
4150
4151 (define_insn "vec_extract_hi_v32qi"
4152   [(set (match_operand:V16QI 0 "nonimmediate_operand" "=x,m")
4153         (vec_select:V16QI
4154           (match_operand:V32QI 1 "register_operand" "x,x")
4155           (parallel [(const_int 16) (const_int 17)
4156                      (const_int 18) (const_int 19)
4157                      (const_int 20) (const_int 21)
4158                      (const_int 22) (const_int 23)
4159                      (const_int 24) (const_int 25)
4160                      (const_int 26) (const_int 27)
4161                      (const_int 28) (const_int 29)
4162                      (const_int 30) (const_int 31)])))]
4163   "TARGET_AVX"
4164   "vextract%~128\t{$0x1, %1, %0|%0, %1, 0x1}"
4165   [(set_attr "type" "sselog")
4166    (set_attr "prefix_extra" "1")
4167    (set_attr "length_immediate" "1")
4168    (set_attr "memory" "none,store")
4169    (set_attr "prefix" "vex")
4170    (set_attr "mode" "OI")])
4171
4172 ;; Modes handled by vec_extract patterns.
4173 (define_mode_iterator VEC_EXTRACT_MODE
4174   [(V32QI "TARGET_AVX") V16QI
4175    (V16HI "TARGET_AVX") V8HI
4176    (V8SI "TARGET_AVX") V4SI
4177    (V4DI "TARGET_AVX") V2DI
4178    (V8SF "TARGET_AVX") V4SF
4179    (V4DF "TARGET_AVX") V2DF])
4180
4181 (define_expand "vec_extract<mode>"
4182   [(match_operand:<ssescalarmode> 0 "register_operand" "")
4183    (match_operand:VEC_EXTRACT_MODE 1 "register_operand" "")
4184    (match_operand 2 "const_int_operand" "")]
4185   "TARGET_SSE"
4186 {
4187   ix86_expand_vector_extract (false, operands[0], operands[1],
4188                               INTVAL (operands[2]));
4189   DONE;
4190 })
4191
4192 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4193 ;;
4194 ;; Parallel double-precision floating point element swizzling
4195 ;;
4196 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4197
4198 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
4199 (define_insn "avx_unpckhpd256"
4200   [(set (match_operand:V4DF 0 "register_operand" "=x")
4201         (vec_select:V4DF
4202           (vec_concat:V8DF
4203             (match_operand:V4DF 1 "register_operand" "x")
4204             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
4205           (parallel [(const_int 1) (const_int 5)
4206                      (const_int 3) (const_int 7)])))]
4207   "TARGET_AVX"
4208   "vunpckhpd\t{%2, %1, %0|%0, %1, %2}"
4209   [(set_attr "type" "sselog")
4210    (set_attr "prefix" "vex")
4211    (set_attr "mode" "V4DF")])
4212
4213 (define_expand "vec_interleave_highv4df"
4214   [(set (match_dup 3)
4215         (vec_select:V4DF
4216           (vec_concat:V8DF
4217             (match_operand:V4DF 1 "register_operand" "x")
4218             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
4219           (parallel [(const_int 0) (const_int 4)
4220                      (const_int 2) (const_int 6)])))
4221    (set (match_dup 4)
4222         (vec_select:V4DF
4223           (vec_concat:V8DF
4224             (match_dup 1)
4225             (match_dup 2))
4226           (parallel [(const_int 1) (const_int 5)
4227                      (const_int 3) (const_int 7)])))
4228    (set (match_operand:V4DF 0 "register_operand" "")
4229         (vec_select:V4DF
4230           (vec_concat:V8DF
4231             (match_dup 3)
4232             (match_dup 4))
4233           (parallel [(const_int 2) (const_int 3)
4234                      (const_int 6) (const_int 7)])))]
4235  "TARGET_AVX"
4236 {
4237   operands[3] = gen_reg_rtx (V4DFmode);
4238   operands[4] = gen_reg_rtx (V4DFmode);
4239 })
4240
4241
4242 (define_expand "vec_interleave_highv2df"
4243   [(set (match_operand:V2DF 0 "register_operand" "")
4244         (vec_select:V2DF
4245           (vec_concat:V4DF
4246             (match_operand:V2DF 1 "nonimmediate_operand" "")
4247             (match_operand:V2DF 2 "nonimmediate_operand" ""))
4248           (parallel [(const_int 1)
4249                      (const_int 3)])))]
4250   "TARGET_SSE2"
4251 {
4252   if (!ix86_vec_interleave_v2df_operator_ok (operands, 1))
4253     operands[2] = force_reg (V2DFmode, operands[2]);
4254 })
4255
4256 (define_insn "*vec_interleave_highv2df"
4257   [(set (match_operand:V2DF 0 "nonimmediate_operand"     "=x,x,x,x,x,m")
4258         (vec_select:V2DF
4259           (vec_concat:V4DF
4260             (match_operand:V2DF 1 "nonimmediate_operand" " 0,x,o,o,o,x")
4261             (match_operand:V2DF 2 "nonimmediate_operand" " x,x,1,0,x,0"))
4262           (parallel [(const_int 1)
4263                      (const_int 3)])))]
4264   "TARGET_SSE2 && ix86_vec_interleave_v2df_operator_ok (operands, 1)"
4265   "@
4266    unpckhpd\t{%2, %0|%0, %2}
4267    vunpckhpd\t{%2, %1, %0|%0, %1, %2}
4268    %vmovddup\t{%H1, %0|%0, %H1}
4269    movlpd\t{%H1, %0|%0, %H1}
4270    vmovlpd\t{%H1, %2, %0|%0, %2, %H1}
4271    %vmovhpd\t{%1, %0|%0, %1}"
4272   [(set_attr "isa" "noavx,avx,sse3,noavx,avx,*")
4273   (set_attr "type" "sselog,sselog,sselog,ssemov,ssemov,ssemov")
4274    (set_attr "prefix_data16" "*,*,*,1,*,1")
4275    (set_attr "prefix" "orig,vex,maybe_vex,orig,vex,maybe_vex")
4276    (set_attr "mode" "V2DF,V2DF,V2DF,V1DF,V1DF,V1DF")])
4277
4278 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
4279 (define_expand "avx_movddup256"
4280   [(set (match_operand:V4DF 0 "register_operand" "")
4281         (vec_select:V4DF
4282           (vec_concat:V8DF
4283             (match_operand:V4DF 1 "nonimmediate_operand" "")
4284             (match_dup 1))
4285           (parallel [(const_int 0) (const_int 4)
4286                      (const_int 2) (const_int 6)])))]
4287   "TARGET_AVX")
4288
4289 (define_expand "avx_unpcklpd256"
4290   [(set (match_operand:V4DF 0 "register_operand" "")
4291         (vec_select:V4DF
4292           (vec_concat:V8DF
4293             (match_operand:V4DF 1 "register_operand" "")
4294             (match_operand:V4DF 2 "nonimmediate_operand" ""))
4295           (parallel [(const_int 0) (const_int 4)
4296                      (const_int 2) (const_int 6)])))]
4297   "TARGET_AVX")
4298
4299 (define_insn "*avx_unpcklpd256"
4300   [(set (match_operand:V4DF 0 "register_operand"         "=x,x")
4301         (vec_select:V4DF
4302           (vec_concat:V8DF
4303             (match_operand:V4DF 1 "nonimmediate_operand" " x,m")
4304             (match_operand:V4DF 2 "nonimmediate_operand" "xm,1"))
4305           (parallel [(const_int 0) (const_int 4)
4306                      (const_int 2) (const_int 6)])))]
4307   "TARGET_AVX"
4308   "@
4309    vunpcklpd\t{%2, %1, %0|%0, %1, %2}
4310    vmovddup\t{%1, %0|%0, %1}"
4311   [(set_attr "type" "sselog")
4312    (set_attr "prefix" "vex")
4313    (set_attr "mode" "V4DF")])
4314
4315 (define_expand "vec_interleave_lowv4df"
4316   [(set (match_dup 3)
4317         (vec_select:V4DF
4318           (vec_concat:V8DF
4319             (match_operand:V4DF 1 "register_operand" "x")
4320             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
4321           (parallel [(const_int 0) (const_int 4)
4322                      (const_int 2) (const_int 6)])))
4323    (set (match_dup 4)
4324         (vec_select:V4DF
4325           (vec_concat:V8DF
4326             (match_dup 1)
4327             (match_dup 2))
4328           (parallel [(const_int 1) (const_int 5)
4329                      (const_int 3) (const_int 7)])))
4330    (set (match_operand:V4DF 0 "register_operand" "")
4331         (vec_select:V4DF
4332           (vec_concat:V8DF
4333             (match_dup 3)
4334             (match_dup 4))
4335           (parallel [(const_int 0) (const_int 1)
4336                      (const_int 4) (const_int 5)])))]
4337  "TARGET_AVX"
4338 {
4339   operands[3] = gen_reg_rtx (V4DFmode);
4340   operands[4] = gen_reg_rtx (V4DFmode);
4341 })
4342
4343 (define_expand "vec_interleave_lowv2df"
4344   [(set (match_operand:V2DF 0 "register_operand" "")
4345         (vec_select:V2DF
4346           (vec_concat:V4DF
4347             (match_operand:V2DF 1 "nonimmediate_operand" "")
4348             (match_operand:V2DF 2 "nonimmediate_operand" ""))
4349           (parallel [(const_int 0)
4350                      (const_int 2)])))]
4351   "TARGET_SSE2"
4352 {
4353   if (!ix86_vec_interleave_v2df_operator_ok (operands, 0))
4354     operands[1] = force_reg (V2DFmode, operands[1]);
4355 })
4356
4357 (define_insn "*vec_interleave_lowv2df"
4358   [(set (match_operand:V2DF 0 "nonimmediate_operand"     "=x,x,x,x,x,o")
4359         (vec_select:V2DF
4360           (vec_concat:V4DF
4361             (match_operand:V2DF 1 "nonimmediate_operand" " 0,x,m,0,x,0")
4362             (match_operand:V2DF 2 "nonimmediate_operand" " x,x,1,m,m,x"))
4363           (parallel [(const_int 0)
4364                      (const_int 2)])))]
4365   "TARGET_SSE2 && ix86_vec_interleave_v2df_operator_ok (operands, 0)"
4366   "@
4367    unpcklpd\t{%2, %0|%0, %2}
4368    vunpcklpd\t{%2, %1, %0|%0, %1, %2}
4369    %vmovddup\t{%1, %0|%0, %1}
4370    movhpd\t{%2, %0|%0, %2}
4371    vmovhpd\t{%2, %1, %0|%0, %1, %2}
4372    %vmovlpd\t{%2, %H0|%H0, %2}"
4373   [(set_attr "isa" "noavx,avx,sse3,noavx,avx,*")
4374    (set_attr "type" "sselog,sselog,sselog,ssemov,ssemov,ssemov")
4375    (set_attr "prefix_data16" "*,*,*,1,*,1")
4376    (set_attr "prefix" "orig,vex,maybe_vex,orig,vex,maybe_vex")
4377    (set_attr "mode" "V2DF,V2DF,V2DF,V1DF,V1DF,V1DF")])
4378
4379 (define_split
4380   [(set (match_operand:V2DF 0 "memory_operand" "")
4381         (vec_select:V2DF
4382           (vec_concat:V4DF
4383             (match_operand:V2DF 1 "register_operand" "")
4384             (match_dup 1))
4385           (parallel [(const_int 0)
4386                      (const_int 2)])))]
4387   "TARGET_SSE3 && reload_completed"
4388   [(const_int 0)]
4389 {
4390   rtx low = gen_rtx_REG (DFmode, REGNO (operands[1]));
4391   emit_move_insn (adjust_address (operands[0], DFmode, 0), low);
4392   emit_move_insn (adjust_address (operands[0], DFmode, 8), low);
4393   DONE;
4394 })
4395
4396 (define_split
4397   [(set (match_operand:V2DF 0 "register_operand" "")
4398         (vec_select:V2DF
4399           (vec_concat:V4DF
4400             (match_operand:V2DF 1 "memory_operand" "")
4401             (match_dup 1))
4402           (parallel [(match_operand:SI 2 "const_0_to_1_operand" "")
4403                      (match_operand:SI 3 "const_int_operand" "")])))]
4404   "TARGET_SSE3 && INTVAL (operands[2]) + 2 == INTVAL (operands[3])"
4405   [(set (match_dup 0) (vec_duplicate:V2DF (match_dup 1)))]
4406 {
4407   operands[1] = adjust_address (operands[1], DFmode, INTVAL (operands[2]) * 8);
4408 })
4409
4410 (define_expand "avx_shufpd256"
4411   [(match_operand:V4DF 0 "register_operand" "")
4412    (match_operand:V4DF 1 "register_operand" "")
4413    (match_operand:V4DF 2 "nonimmediate_operand" "")
4414    (match_operand:SI 3 "const_int_operand" "")]
4415   "TARGET_AVX"
4416 {
4417   int mask = INTVAL (operands[3]);
4418   emit_insn (gen_avx_shufpd256_1 (operands[0], operands[1], operands[2],
4419                                    GEN_INT (mask & 1),
4420                                    GEN_INT (mask & 2 ? 5 : 4),
4421                                    GEN_INT (mask & 4 ? 3 : 2),
4422                                    GEN_INT (mask & 8 ? 7 : 6)));
4423   DONE;
4424 })
4425
4426 (define_insn "avx_shufpd256_1"
4427   [(set (match_operand:V4DF 0 "register_operand" "=x")
4428         (vec_select:V4DF
4429           (vec_concat:V8DF
4430             (match_operand:V4DF 1 "register_operand" "x")
4431             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
4432           (parallel [(match_operand 3 "const_0_to_1_operand" "")
4433                      (match_operand 4 "const_4_to_5_operand" "")
4434                      (match_operand 5 "const_2_to_3_operand" "")
4435                      (match_operand 6 "const_6_to_7_operand" "")])))]
4436   "TARGET_AVX"
4437 {
4438   int mask;
4439   mask = INTVAL (operands[3]);
4440   mask |= (INTVAL (operands[4]) - 4) << 1;
4441   mask |= (INTVAL (operands[5]) - 2) << 2;
4442   mask |= (INTVAL (operands[6]) - 6) << 3;
4443   operands[3] = GEN_INT (mask);
4444
4445   return "vshufpd\t{%3, %2, %1, %0|%0, %1, %2, %3}";
4446 }
4447   [(set_attr "type" "sselog")
4448    (set_attr "length_immediate" "1")
4449    (set_attr "prefix" "vex")
4450    (set_attr "mode" "V4DF")])
4451
4452 (define_expand "sse2_shufpd"
4453   [(match_operand:V2DF 0 "register_operand" "")
4454    (match_operand:V2DF 1 "register_operand" "")
4455    (match_operand:V2DF 2 "nonimmediate_operand" "")
4456    (match_operand:SI 3 "const_int_operand" "")]
4457   "TARGET_SSE2"
4458 {
4459   int mask = INTVAL (operands[3]);
4460   emit_insn (gen_sse2_shufpd_v2df (operands[0], operands[1], operands[2],
4461                                 GEN_INT (mask & 1),
4462                                 GEN_INT (mask & 2 ? 3 : 2)));
4463   DONE;
4464 })
4465
4466 ;; punpcklqdq and punpckhqdq are shorter than shufpd.
4467 (define_insn "avx2_interleave_highv4di"
4468   [(set (match_operand:V4DI 0 "register_operand" "=x")
4469         (vec_select:V4DI
4470           (vec_concat:V8DI
4471             (match_operand:V4DI 1 "register_operand" "x")
4472             (match_operand:V4DI 2 "nonimmediate_operand" "xm"))
4473           (parallel [(const_int 1)
4474                      (const_int 5)
4475                      (const_int 3)
4476                      (const_int 7)])))]
4477   "TARGET_AVX2"
4478   "vpunpckhqdq\t{%2, %1, %0|%0, %1, %2}"
4479   [(set_attr "type" "sselog")
4480    (set_attr "prefix" "vex")
4481    (set_attr "mode" "OI")])
4482
4483 (define_insn "vec_interleave_highv2di"
4484   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
4485         (vec_select:V2DI
4486           (vec_concat:V4DI
4487             (match_operand:V2DI 1 "register_operand" "0,x")
4488             (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm"))
4489           (parallel [(const_int 1)
4490                      (const_int 3)])))]
4491   "TARGET_SSE2"
4492   "@
4493    punpckhqdq\t{%2, %0|%0, %2}
4494    vpunpckhqdq\t{%2, %1, %0|%0, %1, %2}"
4495   [(set_attr "isa" "noavx,avx")
4496    (set_attr "type" "sselog")
4497    (set_attr "prefix_data16" "1,*")
4498    (set_attr "prefix" "orig,vex")
4499    (set_attr "mode" "TI")])
4500
4501 (define_insn "avx2_interleave_lowv4di"
4502   [(set (match_operand:V4DI 0 "register_operand" "=x")
4503         (vec_select:V4DI
4504           (vec_concat:V8DI
4505             (match_operand:V4DI 1 "register_operand" "x")
4506             (match_operand:V4DI 2 "nonimmediate_operand" "xm"))
4507           (parallel [(const_int 0)
4508                      (const_int 4)
4509                      (const_int 2)
4510                      (const_int 6)])))]
4511   "TARGET_AVX2"
4512   "vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}"
4513   [(set_attr "type" "sselog")
4514    (set_attr "prefix" "vex")
4515    (set_attr "mode" "OI")])
4516
4517 (define_insn "vec_interleave_lowv2di"
4518   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
4519         (vec_select:V2DI
4520           (vec_concat:V4DI
4521             (match_operand:V2DI 1 "register_operand" "0,x")
4522             (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm"))
4523           (parallel [(const_int 0)
4524                      (const_int 2)])))]
4525   "TARGET_SSE2"
4526   "@
4527    punpcklqdq\t{%2, %0|%0, %2}
4528    vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}"
4529   [(set_attr "isa" "noavx,avx")
4530    (set_attr "type" "sselog")
4531    (set_attr "prefix_data16" "1,*")
4532    (set_attr "prefix" "orig,vex")
4533    (set_attr "mode" "TI")])
4534
4535 (define_insn "sse2_shufpd_<mode>"
4536   [(set (match_operand:VI8F_128 0 "register_operand" "=x,x")
4537         (vec_select:VI8F_128
4538           (vec_concat:<ssedoublevecmode>
4539             (match_operand:VI8F_128 1 "register_operand" "0,x")
4540             (match_operand:VI8F_128 2 "nonimmediate_operand" "xm,xm"))
4541           (parallel [(match_operand 3 "const_0_to_1_operand" "")
4542                      (match_operand 4 "const_2_to_3_operand" "")])))]
4543   "TARGET_SSE2"
4544 {
4545   int mask;
4546   mask = INTVAL (operands[3]);
4547   mask |= (INTVAL (operands[4]) - 2) << 1;
4548   operands[3] = GEN_INT (mask);
4549
4550   switch (which_alternative)
4551     {
4552     case 0:
4553       return "shufpd\t{%3, %2, %0|%0, %2, %3}";
4554     case 1:
4555       return "vshufpd\t{%3, %2, %1, %0|%0, %1, %2, %3}";
4556     default:
4557       gcc_unreachable ();
4558     }
4559 }
4560   [(set_attr "isa" "noavx,avx")
4561    (set_attr "type" "sselog")
4562    (set_attr "length_immediate" "1")
4563    (set_attr "prefix" "orig,vex")
4564    (set_attr "mode" "V2DF")])
4565
4566 ;; Avoid combining registers from different units in a single alternative,
4567 ;; see comment above inline_secondary_memory_needed function in i386.c
4568 (define_insn "sse2_storehpd"
4569   [(set (match_operand:DF 0 "nonimmediate_operand"     "=m,x,x,x,*f,r")
4570         (vec_select:DF
4571           (match_operand:V2DF 1 "nonimmediate_operand" " x,0,x,o,o,o")
4572           (parallel [(const_int 1)])))]
4573   "TARGET_SSE2 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4574   "@
4575    %vmovhpd\t{%1, %0|%0, %1}
4576    unpckhpd\t%0, %0
4577    vunpckhpd\t{%d1, %0|%0, %d1}
4578    #
4579    #
4580    #"
4581   [(set_attr "isa" "*,noavx,avx,*,*,*")
4582    (set_attr "type" "ssemov,sselog1,sselog1,ssemov,fmov,imov")
4583    (set (attr "prefix_data16")
4584      (if_then_else
4585        (and (eq_attr "alternative" "0")
4586             (not (match_test "TARGET_AVX")))
4587        (const_string "1")
4588        (const_string "*")))
4589    (set_attr "prefix" "maybe_vex,orig,vex,*,*,*")
4590    (set_attr "mode" "V1DF,V1DF,V2DF,DF,DF,DF")])
4591
4592 (define_split
4593   [(set (match_operand:DF 0 "register_operand" "")
4594         (vec_select:DF
4595           (match_operand:V2DF 1 "memory_operand" "")
4596           (parallel [(const_int 1)])))]
4597   "TARGET_SSE2 && reload_completed"
4598   [(set (match_dup 0) (match_dup 1))]
4599   "operands[1] = adjust_address (operands[1], DFmode, 8);")
4600
4601 (define_insn "*vec_extractv2df_1_sse"
4602   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,x,x")
4603         (vec_select:DF
4604           (match_operand:V2DF 1 "nonimmediate_operand" "x,x,o")
4605           (parallel [(const_int 1)])))]
4606   "!TARGET_SSE2 && TARGET_SSE
4607    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4608   "@
4609    movhps\t{%1, %0|%0, %1}
4610    movhlps\t{%1, %0|%0, %1}
4611    movlps\t{%H1, %0|%0, %H1}"
4612   [(set_attr "type" "ssemov")
4613    (set_attr "mode" "V2SF,V4SF,V2SF")])
4614
4615 ;; Avoid combining registers from different units in a single alternative,
4616 ;; see comment above inline_secondary_memory_needed function in i386.c
4617 (define_insn "sse2_storelpd"
4618   [(set (match_operand:DF 0 "nonimmediate_operand"     "=m,x,x,*f,r")
4619         (vec_select:DF
4620           (match_operand:V2DF 1 "nonimmediate_operand" " x,x,m,m,m")
4621           (parallel [(const_int 0)])))]
4622   "TARGET_SSE2 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4623   "@
4624    %vmovlpd\t{%1, %0|%0, %1}
4625    #
4626    #
4627    #
4628    #"
4629   [(set_attr "type" "ssemov,ssemov,ssemov,fmov,imov")
4630    (set_attr "prefix_data16" "1,*,*,*,*")
4631    (set_attr "prefix" "maybe_vex")
4632    (set_attr "mode" "V1DF,DF,DF,DF,DF")])
4633
4634 (define_split
4635   [(set (match_operand:DF 0 "register_operand" "")
4636         (vec_select:DF
4637           (match_operand:V2DF 1 "nonimmediate_operand" "")
4638           (parallel [(const_int 0)])))]
4639   "TARGET_SSE2 && reload_completed"
4640   [(const_int 0)]
4641 {
4642   rtx op1 = operands[1];
4643   if (REG_P (op1))
4644     op1 = gen_rtx_REG (DFmode, REGNO (op1));
4645   else
4646     op1 = gen_lowpart (DFmode, op1);
4647   emit_move_insn (operands[0], op1);
4648   DONE;
4649 })
4650
4651 (define_insn "*vec_extractv2df_0_sse"
4652   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,x,x")
4653         (vec_select:DF
4654           (match_operand:V2DF 1 "nonimmediate_operand" "x,x,m")
4655           (parallel [(const_int 0)])))]
4656   "!TARGET_SSE2 && TARGET_SSE
4657    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4658   "@
4659    movlps\t{%1, %0|%0, %1}
4660    movaps\t{%1, %0|%0, %1}
4661    movlps\t{%1, %0|%0, %1}"
4662   [(set_attr "type" "ssemov")
4663    (set_attr "mode" "V2SF,V4SF,V2SF")])
4664
4665 (define_expand "sse2_loadhpd_exp"
4666   [(set (match_operand:V2DF 0 "nonimmediate_operand" "")
4667         (vec_concat:V2DF
4668           (vec_select:DF
4669             (match_operand:V2DF 1 "nonimmediate_operand" "")
4670             (parallel [(const_int 0)]))
4671           (match_operand:DF 2 "nonimmediate_operand" "")))]
4672   "TARGET_SSE2"
4673 {
4674   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V2DFmode, operands);
4675
4676   emit_insn (gen_sse2_loadhpd (dst, operands[1], operands[2]));
4677
4678   /* Fix up the destination if needed.  */
4679   if (dst != operands[0])
4680     emit_move_insn (operands[0], dst);
4681
4682   DONE;
4683 })
4684
4685 ;; Avoid combining registers from different units in a single alternative,
4686 ;; see comment above inline_secondary_memory_needed function in i386.c
4687 (define_insn "sse2_loadhpd"
4688   [(set (match_operand:V2DF 0 "nonimmediate_operand"
4689           "=x,x,x,x,o,o ,o")
4690         (vec_concat:V2DF
4691           (vec_select:DF
4692             (match_operand:V2DF 1 "nonimmediate_operand"
4693           " 0,x,0,x,0,0 ,0")
4694             (parallel [(const_int 0)]))
4695           (match_operand:DF 2 "nonimmediate_operand"
4696           " m,m,x,x,x,*f,r")))]
4697   "TARGET_SSE2 && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
4698   "@
4699    movhpd\t{%2, %0|%0, %2}
4700    vmovhpd\t{%2, %1, %0|%0, %1, %2}
4701    unpcklpd\t{%2, %0|%0, %2}
4702    vunpcklpd\t{%2, %1, %0|%0, %1, %2}
4703    #
4704    #
4705    #"
4706   [(set_attr "isa" "noavx,avx,noavx,avx,*,*,*")
4707    (set_attr "type" "ssemov,ssemov,sselog,sselog,ssemov,fmov,imov")
4708    (set_attr "prefix_data16" "1,*,*,*,*,*,*")
4709    (set_attr "prefix" "orig,vex,orig,vex,*,*,*")
4710    (set_attr "mode" "V1DF,V1DF,V2DF,V2DF,DF,DF,DF")])
4711
4712 (define_split
4713   [(set (match_operand:V2DF 0 "memory_operand" "")
4714         (vec_concat:V2DF
4715           (vec_select:DF (match_dup 0) (parallel [(const_int 0)]))
4716           (match_operand:DF 1 "register_operand" "")))]
4717   "TARGET_SSE2 && reload_completed"
4718   [(set (match_dup 0) (match_dup 1))]
4719   "operands[0] = adjust_address (operands[0], DFmode, 8);")
4720
4721 (define_expand "sse2_loadlpd_exp"
4722   [(set (match_operand:V2DF 0 "nonimmediate_operand" "")
4723         (vec_concat:V2DF
4724           (match_operand:DF 2 "nonimmediate_operand" "")
4725           (vec_select:DF
4726             (match_operand:V2DF 1 "nonimmediate_operand" "")
4727             (parallel [(const_int 1)]))))]
4728   "TARGET_SSE2"
4729 {
4730   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V2DFmode, operands);
4731
4732   emit_insn (gen_sse2_loadlpd (dst, operands[1], operands[2]));
4733
4734   /* Fix up the destination if needed.  */
4735   if (dst != operands[0])
4736     emit_move_insn (operands[0], dst);
4737
4738   DONE;
4739 })
4740
4741 ;; Avoid combining registers from different units in a single alternative,
4742 ;; see comment above inline_secondary_memory_needed function in i386.c
4743 (define_insn "sse2_loadlpd"
4744   [(set (match_operand:V2DF 0 "nonimmediate_operand"
4745           "=x,x,x,x,x,x,x,x,m,m ,m")
4746         (vec_concat:V2DF
4747           (match_operand:DF 2 "nonimmediate_operand"
4748           " m,m,m,x,x,0,0,x,x,*f,r")
4749           (vec_select:DF
4750             (match_operand:V2DF 1 "vector_move_operand"
4751           " C,0,x,0,x,x,o,o,0,0 ,0")
4752             (parallel [(const_int 1)]))))]
4753   "TARGET_SSE2 && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
4754   "@
4755    %vmovsd\t{%2, %0|%0, %2}
4756    movlpd\t{%2, %0|%0, %2}
4757    vmovlpd\t{%2, %1, %0|%0, %1, %2}
4758    movsd\t{%2, %0|%0, %2}
4759    vmovsd\t{%2, %1, %0|%0, %1, %2}
4760    shufpd\t{$2, %1, %0|%0, %1, 2}
4761    movhpd\t{%H1, %0|%0, %H1}
4762    vmovhpd\t{%H1, %2, %0|%0, %2, %H1}
4763    #
4764    #
4765    #"
4766   [(set_attr "isa" "*,noavx,avx,noavx,avx,noavx,noavx,avx,*,*,*")
4767    (set (attr "type")
4768      (cond [(eq_attr "alternative" "5")
4769               (const_string "sselog")
4770             (eq_attr "alternative" "9")
4771               (const_string "fmov")
4772             (eq_attr "alternative" "10")
4773               (const_string "imov")
4774            ]
4775            (const_string "ssemov")))
4776    (set_attr "prefix_data16" "*,1,*,*,*,*,1,*,*,*,*")
4777    (set_attr "length_immediate" "*,*,*,*,*,1,*,*,*,*,*")
4778    (set_attr "prefix" "maybe_vex,orig,vex,orig,vex,orig,orig,vex,*,*,*")
4779    (set_attr "mode" "DF,V1DF,V1DF,V1DF,V1DF,V2DF,V1DF,V1DF,DF,DF,DF")])
4780
4781 (define_split
4782   [(set (match_operand:V2DF 0 "memory_operand" "")
4783         (vec_concat:V2DF
4784           (match_operand:DF 1 "register_operand" "")
4785           (vec_select:DF (match_dup 0) (parallel [(const_int 1)]))))]
4786   "TARGET_SSE2 && reload_completed"
4787   [(set (match_dup 0) (match_dup 1))]
4788   "operands[0] = adjust_address (operands[0], DFmode, 8);")
4789
4790 (define_insn "sse2_movsd"
4791   [(set (match_operand:V2DF 0 "nonimmediate_operand"   "=x,x,x,x,m,x,x,x,o")
4792         (vec_merge:V2DF
4793           (match_operand:V2DF 2 "nonimmediate_operand" " x,x,m,m,x,0,0,x,0")
4794           (match_operand:V2DF 1 "nonimmediate_operand" " 0,x,0,x,0,x,o,o,x")
4795           (const_int 1)))]
4796   "TARGET_SSE2"
4797   "@
4798    movsd\t{%2, %0|%0, %2}
4799    vmovsd\t{%2, %1, %0|%0, %1, %2}
4800    movlpd\t{%2, %0|%0, %2}
4801    vmovlpd\t{%2, %1, %0|%0, %1, %2}
4802    %vmovlpd\t{%2, %0|%0, %2}
4803    shufpd\t{$2, %1, %0|%0, %1, 2}
4804    movhps\t{%H1, %0|%0, %H1}
4805    vmovhps\t{%H1, %2, %0|%0, %2, %H1}
4806    %vmovhps\t{%1, %H0|%H0, %1}"
4807   [(set_attr "isa" "noavx,avx,noavx,avx,*,noavx,noavx,avx,*")
4808    (set (attr "type")
4809      (if_then_else
4810        (eq_attr "alternative" "5")
4811        (const_string "sselog")
4812        (const_string "ssemov")))
4813    (set (attr "prefix_data16")
4814      (if_then_else
4815        (and (eq_attr "alternative" "2,4")
4816             (not (match_test "TARGET_AVX")))
4817        (const_string "1")
4818        (const_string "*")))
4819    (set_attr "length_immediate" "*,*,*,*,*,1,*,*,*")
4820    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex,orig,orig,vex,maybe_vex")
4821    (set_attr "mode" "DF,DF,V1DF,V1DF,V1DF,V2DF,V1DF,V1DF,V1DF")])
4822
4823 (define_expand "vec_dupv2df"
4824   [(set (match_operand:V2DF 0 "register_operand" "")
4825         (vec_duplicate:V2DF
4826           (match_operand:DF 1 "nonimmediate_operand" "")))]
4827   "TARGET_SSE2"
4828 {
4829   if (!TARGET_SSE3)
4830     operands[1] = force_reg (DFmode, operands[1]);
4831 })
4832
4833 (define_insn "*vec_dupv2df_sse3"
4834   [(set (match_operand:V2DF 0 "register_operand" "=x")
4835         (vec_duplicate:V2DF
4836           (match_operand:DF 1 "nonimmediate_operand" "xm")))]
4837   "TARGET_SSE3"
4838   "%vmovddup\t{%1, %0|%0, %1}"
4839   [(set_attr "type" "sselog1")
4840    (set_attr "prefix" "maybe_vex")
4841    (set_attr "mode" "DF")])
4842
4843 (define_insn "*vec_dupv2df"
4844   [(set (match_operand:V2DF 0 "register_operand" "=x")
4845         (vec_duplicate:V2DF
4846           (match_operand:DF 1 "register_operand" "0")))]
4847   "TARGET_SSE2"
4848   "unpcklpd\t%0, %0"
4849   [(set_attr "type" "sselog1")
4850    (set_attr "mode" "V2DF")])
4851
4852 (define_insn "*vec_concatv2df_sse3"
4853   [(set (match_operand:V2DF 0 "register_operand" "=x")
4854         (vec_concat:V2DF
4855           (match_operand:DF 1 "nonimmediate_operand" "xm")
4856           (match_dup 1)))]
4857   "TARGET_SSE3"
4858   "%vmovddup\t{%1, %0|%0, %1}"
4859   [(set_attr "type" "sselog1")
4860    (set_attr "prefix" "maybe_vex")
4861    (set_attr "mode" "DF")])
4862
4863 (define_insn "*vec_concatv2df"
4864   [(set (match_operand:V2DF 0 "register_operand"     "=x,x,x,x,x,x,x")
4865         (vec_concat:V2DF
4866           (match_operand:DF 1 "nonimmediate_operand" " 0,x,0,x,m,0,0")
4867           (match_operand:DF 2 "vector_move_operand"  " x,x,m,m,C,x,m")))]
4868   "TARGET_SSE"
4869   "@
4870    unpcklpd\t{%2, %0|%0, %2}
4871    vunpcklpd\t{%2, %1, %0|%0, %1, %2}
4872    movhpd\t{%2, %0|%0, %2}
4873    vmovhpd\t{%2, %1, %0|%0, %1, %2}
4874    %vmovsd\t{%1, %0|%0, %1}
4875    movlhps\t{%2, %0|%0, %2}
4876    movhps\t{%2, %0|%0, %2}"
4877   [(set_attr "isa" "sse2_noavx,avx,sse2_noavx,avx,sse2,noavx,noavx")
4878    (set (attr "type")
4879      (if_then_else
4880        (eq_attr "alternative" "0,1")
4881        (const_string "sselog")
4882        (const_string "ssemov")))
4883    (set_attr "prefix_data16" "*,*,1,*,*,*,*")
4884    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex,orig,orig")
4885    (set_attr "mode" "V2DF,V2DF,V1DF,V1DF,DF,V4SF,V2SF")])
4886
4887 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4888 ;;
4889 ;; Parallel integral arithmetic
4890 ;;
4891 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4892
4893 (define_expand "neg<mode>2"
4894   [(set (match_operand:VI_AVX2 0 "register_operand" "")
4895         (minus:VI_AVX2
4896           (match_dup 2)
4897           (match_operand:VI_AVX2 1 "nonimmediate_operand" "")))]
4898   "TARGET_SSE2"
4899   "operands[2] = force_reg (<MODE>mode, CONST0_RTX (<MODE>mode));")
4900
4901 (define_expand "<plusminus_insn><mode>3"
4902   [(set (match_operand:VI_AVX2 0 "register_operand" "")
4903         (plusminus:VI_AVX2
4904           (match_operand:VI_AVX2 1 "nonimmediate_operand" "")
4905           (match_operand:VI_AVX2 2 "nonimmediate_operand" "")))]
4906   "TARGET_SSE2"
4907   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
4908
4909 (define_insn "*<plusminus_insn><mode>3"
4910   [(set (match_operand:VI_AVX2 0 "register_operand" "=x,x")
4911         (plusminus:VI_AVX2
4912           (match_operand:VI_AVX2 1 "nonimmediate_operand" "<comm>0,x")
4913           (match_operand:VI_AVX2 2 "nonimmediate_operand" "xm,xm")))]
4914   "TARGET_SSE2 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
4915   "@
4916    p<plusminus_mnemonic><ssemodesuffix>\t{%2, %0|%0, %2}
4917    vp<plusminus_mnemonic><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
4918   [(set_attr "isa" "noavx,avx")
4919    (set_attr "type" "sseiadd")
4920    (set_attr "prefix_data16" "1,*")
4921    (set_attr "prefix" "orig,vex")
4922    (set_attr "mode" "<sseinsnmode>")])
4923
4924 (define_expand "<sse2_avx2>_<plusminus_insn><mode>3"
4925   [(set (match_operand:VI12_AVX2 0 "register_operand" "")
4926         (sat_plusminus:VI12_AVX2
4927           (match_operand:VI12_AVX2 1 "nonimmediate_operand" "")
4928           (match_operand:VI12_AVX2 2 "nonimmediate_operand" "")))]
4929   "TARGET_SSE2"
4930   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
4931
4932 (define_insn "*<sse2_avx2>_<plusminus_insn><mode>3"
4933   [(set (match_operand:VI12_AVX2 0 "register_operand" "=x,x")
4934         (sat_plusminus:VI12_AVX2
4935           (match_operand:VI12_AVX2 1 "nonimmediate_operand" "<comm>0,x")
4936           (match_operand:VI12_AVX2 2 "nonimmediate_operand" "xm,xm")))]
4937   "TARGET_SSE2 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
4938   "@
4939    p<plusminus_mnemonic><ssemodesuffix>\t{%2, %0|%0, %2}
4940    vp<plusminus_mnemonic><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
4941   [(set_attr "isa" "noavx,avx")
4942    (set_attr "type" "sseiadd")
4943    (set_attr "prefix_data16" "1,*")
4944    (set_attr "prefix" "orig,vex")
4945    (set_attr "mode" "TI")])
4946
4947 (define_insn_and_split "mul<mode>3"
4948   [(set (match_operand:VI1_AVX2 0 "register_operand" "")
4949         (mult:VI1_AVX2 (match_operand:VI1_AVX2 1 "register_operand" "")
4950                        (match_operand:VI1_AVX2 2 "register_operand" "")))]
4951   "TARGET_SSE2
4952    && can_create_pseudo_p ()"
4953   "#"
4954   "&& 1"
4955   [(const_int 0)]
4956 {
4957   rtx t[6];
4958   int i;
4959   enum machine_mode mulmode = <sseunpackmode>mode;
4960
4961   for (i = 0; i < 6; ++i)
4962     t[i] = gen_reg_rtx (<MODE>mode);
4963
4964   /* Unpack data such that we've got a source byte in each low byte of
4965      each word.  We don't care what goes into the high byte of each word.
4966      Rather than trying to get zero in there, most convenient is to let
4967      it be a copy of the low byte.  */
4968   emit_insn (gen_<vec_avx2>_interleave_high<mode> (t[0], operands[1],
4969                                                    operands[1]));
4970   emit_insn (gen_<vec_avx2>_interleave_high<mode> (t[1], operands[2],
4971                                                    operands[2]));
4972   emit_insn (gen_<vec_avx2>_interleave_low<mode> (t[2], operands[1],
4973                                                   operands[1]));
4974   emit_insn (gen_<vec_avx2>_interleave_low<mode> (t[3], operands[2],
4975                                                   operands[2]));
4976
4977   /* Multiply words.  The end-of-line annotations here give a picture of what
4978      the output of that instruction looks like.  Dot means don't care; the
4979      letters are the bytes of the result with A being the most significant.  */
4980   emit_insn (gen_rtx_SET (VOIDmode, gen_lowpart (mulmode, t[4]),
4981                           gen_rtx_MULT (mulmode,        /* .A.B.C.D.E.F.G.H */
4982                                         gen_lowpart (mulmode, t[0]),
4983                                         gen_lowpart (mulmode, t[1]))));
4984   emit_insn (gen_rtx_SET (VOIDmode, gen_lowpart (mulmode, t[5]),
4985                           gen_rtx_MULT (mulmode,        /* .I.J.K.L.M.N.O.P */
4986                                         gen_lowpart (mulmode, t[2]),
4987                                         gen_lowpart (mulmode, t[3]))));
4988
4989   /* Extract the even bytes and merge them back together.  */
4990   ix86_expand_vec_extract_even_odd (operands[0], t[5], t[4], 0);
4991
4992   set_unique_reg_note (get_last_insn (), REG_EQUAL,
4993                        gen_rtx_MULT (<MODE>mode, operands[1], operands[2]));
4994   DONE;
4995 })
4996
4997 (define_expand "mul<mode>3"
4998   [(set (match_operand:VI2_AVX2 0 "register_operand" "")
4999         (mult:VI2_AVX2 (match_operand:VI2_AVX2 1 "nonimmediate_operand" "")
5000                        (match_operand:VI2_AVX2 2 "nonimmediate_operand" "")))]
5001   "TARGET_SSE2"
5002   "ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);")
5003
5004 (define_insn "*mul<mode>3"
5005   [(set (match_operand:VI2_AVX2 0 "register_operand" "=x,x")
5006         (mult:VI2_AVX2 (match_operand:VI2_AVX2 1 "nonimmediate_operand" "%0,x")
5007                        (match_operand:VI2_AVX2 2 "nonimmediate_operand" "xm,xm")))]
5008   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, <MODE>mode, operands)"
5009   "@
5010    pmullw\t{%2, %0|%0, %2}
5011    vpmullw\t{%2, %1, %0|%0, %1, %2}"
5012   [(set_attr "isa" "noavx,avx")
5013    (set_attr "type" "sseimul")
5014    (set_attr "prefix_data16" "1,*")
5015    (set_attr "prefix" "orig,vex")
5016    (set_attr "mode" "<sseinsnmode>")])
5017
5018 (define_expand "<s>mul<mode>3_highpart"
5019   [(set (match_operand:VI2_AVX2 0 "register_operand" "")
5020         (truncate:VI2_AVX2
5021           (lshiftrt:<ssedoublemode>
5022             (mult:<ssedoublemode>
5023               (any_extend:<ssedoublemode>
5024                 (match_operand:VI2_AVX2 1 "nonimmediate_operand" ""))
5025               (any_extend:<ssedoublemode>
5026                 (match_operand:VI2_AVX2 2 "nonimmediate_operand" "")))
5027             (const_int 16))))]
5028   "TARGET_SSE2"
5029   "ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);")
5030
5031 (define_insn "*<s>mul<mode>3_highpart"
5032   [(set (match_operand:VI2_AVX2 0 "register_operand" "=x,x")
5033         (truncate:VI2_AVX2
5034           (lshiftrt:<ssedoublemode>
5035             (mult:<ssedoublemode>
5036               (any_extend:<ssedoublemode>
5037                 (match_operand:VI2_AVX2 1 "nonimmediate_operand" "%0,x"))
5038               (any_extend:<ssedoublemode>
5039                 (match_operand:VI2_AVX2 2 "nonimmediate_operand" "xm,xm")))
5040             (const_int 16))))]
5041   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, <MODE>mode, operands)"
5042   "@
5043    pmulh<u>w\t{%2, %0|%0, %2}
5044    vpmulh<u>w\t{%2, %1, %0|%0, %1, %2}"
5045   [(set_attr "isa" "noavx,avx")
5046    (set_attr "type" "sseimul")
5047    (set_attr "prefix_data16" "1,*")
5048    (set_attr "prefix" "orig,vex")
5049    (set_attr "mode" "<sseinsnmode>")])
5050
5051 (define_expand "avx2_umulv4siv4di3"
5052   [(set (match_operand:V4DI 0 "register_operand" "")
5053         (mult:V4DI
5054           (zero_extend:V4DI
5055             (vec_select:V4SI
5056               (match_operand:V8SI 1 "nonimmediate_operand" "")
5057               (parallel [(const_int 0) (const_int 2)
5058                          (const_int 4) (const_int 6)])))
5059           (zero_extend:V4DI
5060             (vec_select:V4SI
5061               (match_operand:V8SI 2 "nonimmediate_operand" "")
5062               (parallel [(const_int 0) (const_int 2)
5063                          (const_int 4) (const_int 6)])))))]
5064   "TARGET_AVX2"
5065   "ix86_fixup_binary_operands_no_copy (MULT, V8SImode, operands);")
5066
5067 (define_insn "*avx_umulv4siv4di3"
5068   [(set (match_operand:V4DI 0 "register_operand" "=x")
5069         (mult:V4DI
5070           (zero_extend:V4DI
5071             (vec_select:V4SI
5072               (match_operand:V8SI 1 "nonimmediate_operand" "%x")
5073               (parallel [(const_int 0) (const_int 2)
5074                          (const_int 4) (const_int 6)])))
5075           (zero_extend:V4DI
5076             (vec_select:V4SI
5077               (match_operand:V8SI 2 "nonimmediate_operand" "xm")
5078               (parallel [(const_int 0) (const_int 2)
5079                          (const_int 4) (const_int 6)])))))]
5080   "TARGET_AVX2 && ix86_binary_operator_ok (MULT, V8SImode, operands)"
5081   "vpmuludq\t{%2, %1, %0|%0, %1, %2}"
5082   [(set_attr "type" "sseimul")
5083    (set_attr "prefix" "vex")
5084    (set_attr "mode" "OI")])
5085
5086 (define_expand "sse2_umulv2siv2di3"
5087   [(set (match_operand:V2DI 0 "register_operand" "")
5088         (mult:V2DI
5089           (zero_extend:V2DI
5090             (vec_select:V2SI
5091               (match_operand:V4SI 1 "nonimmediate_operand" "")
5092               (parallel [(const_int 0) (const_int 2)])))
5093           (zero_extend:V2DI
5094             (vec_select:V2SI
5095               (match_operand:V4SI 2 "nonimmediate_operand" "")
5096               (parallel [(const_int 0) (const_int 2)])))))]
5097   "TARGET_SSE2"
5098   "ix86_fixup_binary_operands_no_copy (MULT, V4SImode, operands);")
5099
5100 (define_insn "*sse2_umulv2siv2di3"
5101   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
5102         (mult:V2DI
5103           (zero_extend:V2DI
5104             (vec_select:V2SI
5105               (match_operand:V4SI 1 "nonimmediate_operand" "%0,x")
5106               (parallel [(const_int 0) (const_int 2)])))
5107           (zero_extend:V2DI
5108             (vec_select:V2SI
5109               (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm")
5110               (parallel [(const_int 0) (const_int 2)])))))]
5111   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, V4SImode, operands)"
5112   "@
5113    pmuludq\t{%2, %0|%0, %2}
5114    vpmuludq\t{%2, %1, %0|%0, %1, %2}"
5115   [(set_attr "isa" "noavx,avx")
5116    (set_attr "type" "sseimul")
5117    (set_attr "prefix_data16" "1,*")
5118    (set_attr "prefix" "orig,vex")
5119    (set_attr "mode" "TI")])
5120
5121 (define_expand "avx2_mulv4siv4di3"
5122   [(set (match_operand:V4DI 0 "register_operand" "")
5123         (mult:V4DI
5124           (sign_extend:V4DI
5125             (vec_select:V4SI
5126               (match_operand:V8SI 1 "nonimmediate_operand" "")
5127               (parallel [(const_int 0) (const_int 2)
5128                          (const_int 4) (const_int 6)])))
5129           (sign_extend:V4DI
5130             (vec_select:V4SI
5131               (match_operand:V8SI 2 "nonimmediate_operand" "")
5132               (parallel [(const_int 0) (const_int 2)
5133                          (const_int 4) (const_int 6)])))))]
5134   "TARGET_AVX2"
5135   "ix86_fixup_binary_operands_no_copy (MULT, V8SImode, operands);")
5136
5137 (define_insn "*avx2_mulv4siv4di3"
5138   [(set (match_operand:V4DI 0 "register_operand" "=x")
5139         (mult:V4DI
5140           (sign_extend:V4DI
5141             (vec_select:V4SI
5142               (match_operand:V8SI 1 "nonimmediate_operand" "x")
5143               (parallel [(const_int 0) (const_int 2)
5144                          (const_int 4) (const_int 6)])))
5145           (sign_extend:V4DI
5146             (vec_select:V4SI
5147               (match_operand:V8SI 2 "nonimmediate_operand" "xm")
5148               (parallel [(const_int 0) (const_int 2)
5149                          (const_int 4) (const_int 6)])))))]
5150   "TARGET_AVX2 && ix86_binary_operator_ok (MULT, V8SImode, operands)"
5151   "vpmuldq\t{%2, %1, %0|%0, %1, %2}"
5152   [(set_attr "isa" "avx")
5153    (set_attr "type" "sseimul")
5154    (set_attr "prefix_extra" "1")
5155    (set_attr "prefix" "vex")
5156    (set_attr "mode" "OI")])
5157
5158 (define_expand "sse4_1_mulv2siv2di3"
5159   [(set (match_operand:V2DI 0 "register_operand" "")
5160         (mult:V2DI
5161           (sign_extend:V2DI
5162             (vec_select:V2SI
5163               (match_operand:V4SI 1 "nonimmediate_operand" "")
5164               (parallel [(const_int 0) (const_int 2)])))
5165           (sign_extend:V2DI
5166             (vec_select:V2SI
5167               (match_operand:V4SI 2 "nonimmediate_operand" "")
5168               (parallel [(const_int 0) (const_int 2)])))))]
5169   "TARGET_SSE4_1"
5170   "ix86_fixup_binary_operands_no_copy (MULT, V4SImode, operands);")
5171
5172 (define_insn "*sse4_1_mulv2siv2di3"
5173   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
5174         (mult:V2DI
5175           (sign_extend:V2DI
5176             (vec_select:V2SI
5177               (match_operand:V4SI 1 "nonimmediate_operand" "%0,x")
5178               (parallel [(const_int 0) (const_int 2)])))
5179           (sign_extend:V2DI
5180             (vec_select:V2SI
5181               (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm")
5182               (parallel [(const_int 0) (const_int 2)])))))]
5183   "TARGET_SSE4_1 && ix86_binary_operator_ok (MULT, V4SImode, operands)"
5184   "@
5185    pmuldq\t{%2, %0|%0, %2}
5186    vpmuldq\t{%2, %1, %0|%0, %1, %2}"
5187   [(set_attr "isa" "noavx,avx")
5188    (set_attr "type" "sseimul")
5189    (set_attr "prefix_data16" "1,*")
5190    (set_attr "prefix_extra" "1")
5191    (set_attr "prefix" "orig,vex")
5192    (set_attr "mode" "TI")])
5193
5194 (define_expand "avx2_pmaddwd"
5195   [(set (match_operand:V8SI 0 "register_operand" "")
5196         (plus:V8SI
5197           (mult:V8SI
5198             (sign_extend:V8SI
5199               (vec_select:V8HI
5200                 (match_operand:V16HI 1 "nonimmediate_operand" "")
5201                 (parallel [(const_int 0)
5202                            (const_int 2)
5203                            (const_int 4)
5204                            (const_int 6)
5205                            (const_int 8)
5206                            (const_int 10)
5207                            (const_int 12)
5208                            (const_int 14)])))
5209             (sign_extend:V8SI
5210               (vec_select:V8HI
5211                 (match_operand:V16HI 2 "nonimmediate_operand" "")
5212                 (parallel [(const_int 0)
5213                            (const_int 2)
5214                            (const_int 4)
5215                            (const_int 6)
5216                            (const_int 8)
5217                            (const_int 10)
5218                            (const_int 12)
5219                            (const_int 14)]))))
5220           (mult:V8SI
5221             (sign_extend:V8SI
5222               (vec_select:V8HI (match_dup 1)
5223                 (parallel [(const_int 1)
5224                            (const_int 3)
5225                            (const_int 5)
5226                            (const_int 7)
5227                            (const_int 9)
5228                            (const_int 11)
5229                            (const_int 13)
5230                            (const_int 15)])))
5231             (sign_extend:V8SI
5232               (vec_select:V8HI (match_dup 2)
5233                 (parallel [(const_int 1)
5234                            (const_int 3)
5235                            (const_int 5)
5236                            (const_int 7)
5237                            (const_int 9)
5238                            (const_int 11)
5239                            (const_int 13)
5240                            (const_int 15)]))))))]
5241   "TARGET_AVX2"
5242   "ix86_fixup_binary_operands_no_copy (MULT, V16HImode, operands);")
5243
5244 (define_expand "sse2_pmaddwd"
5245   [(set (match_operand:V4SI 0 "register_operand" "")
5246         (plus:V4SI
5247           (mult:V4SI
5248             (sign_extend:V4SI
5249               (vec_select:V4HI
5250                 (match_operand:V8HI 1 "nonimmediate_operand" "")
5251                 (parallel [(const_int 0)
5252                            (const_int 2)
5253                            (const_int 4)
5254                            (const_int 6)])))
5255             (sign_extend:V4SI
5256               (vec_select:V4HI
5257                 (match_operand:V8HI 2 "nonimmediate_operand" "")
5258                 (parallel [(const_int 0)
5259                            (const_int 2)
5260                            (const_int 4)
5261                            (const_int 6)]))))
5262           (mult:V4SI
5263             (sign_extend:V4SI
5264               (vec_select:V4HI (match_dup 1)
5265                 (parallel [(const_int 1)
5266                            (const_int 3)
5267                            (const_int 5)
5268                            (const_int 7)])))
5269             (sign_extend:V4SI
5270               (vec_select:V4HI (match_dup 2)
5271                 (parallel [(const_int 1)
5272                            (const_int 3)
5273                            (const_int 5)
5274                            (const_int 7)]))))))]
5275   "TARGET_SSE2"
5276   "ix86_fixup_binary_operands_no_copy (MULT, V8HImode, operands);")
5277
5278 (define_insn "*avx2_pmaddwd"
5279   [(set (match_operand:V8SI 0 "register_operand" "=x")
5280         (plus:V8SI
5281           (mult:V8SI
5282             (sign_extend:V8SI
5283               (vec_select:V8HI
5284                 (match_operand:V16HI 1 "nonimmediate_operand" "%x")
5285                 (parallel [(const_int 0)
5286                            (const_int 2)
5287                            (const_int 4)
5288                            (const_int 6)
5289                            (const_int 8)
5290                            (const_int 10)
5291                            (const_int 12)
5292                            (const_int 14)])))
5293             (sign_extend:V8SI
5294               (vec_select:V8HI
5295                 (match_operand:V16HI 2 "nonimmediate_operand" "xm")
5296                 (parallel [(const_int 0)
5297                            (const_int 2)
5298                            (const_int 4)
5299                            (const_int 6)
5300                            (const_int 8)
5301                            (const_int 10)
5302                            (const_int 12)
5303                            (const_int 14)]))))
5304           (mult:V8SI
5305             (sign_extend:V8SI
5306               (vec_select:V8HI (match_dup 1)
5307                 (parallel [(const_int 1)
5308                            (const_int 3)
5309                            (const_int 5)
5310                            (const_int 7)
5311                            (const_int 9)
5312                            (const_int 11)
5313                            (const_int 13)
5314                            (const_int 15)])))
5315             (sign_extend:V8SI
5316               (vec_select:V8HI (match_dup 2)
5317                 (parallel [(const_int 1)
5318                            (const_int 3)
5319                            (const_int 5)
5320                            (const_int 7)
5321                            (const_int 9)
5322                            (const_int 11)
5323                            (const_int 13)
5324                            (const_int 15)]))))))]
5325   "TARGET_AVX2 && ix86_binary_operator_ok (MULT, V16HImode, operands)"
5326   "vpmaddwd\t{%2, %1, %0|%0, %1, %2}"
5327   [(set_attr "type" "sseiadd")
5328    (set_attr "prefix" "vex")
5329    (set_attr "mode" "OI")])
5330
5331 (define_insn "*sse2_pmaddwd"
5332   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
5333         (plus:V4SI
5334           (mult:V4SI
5335             (sign_extend:V4SI
5336               (vec_select:V4HI
5337                 (match_operand:V8HI 1 "nonimmediate_operand" "%0,x")
5338                 (parallel [(const_int 0)
5339                            (const_int 2)
5340                            (const_int 4)
5341                            (const_int 6)])))
5342             (sign_extend:V4SI
5343               (vec_select:V4HI
5344                 (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
5345                 (parallel [(const_int 0)
5346                            (const_int 2)
5347                            (const_int 4)
5348                            (const_int 6)]))))
5349           (mult:V4SI
5350             (sign_extend:V4SI
5351               (vec_select:V4HI (match_dup 1)
5352                 (parallel [(const_int 1)
5353                            (const_int 3)
5354                            (const_int 5)
5355                            (const_int 7)])))
5356             (sign_extend:V4SI
5357               (vec_select:V4HI (match_dup 2)
5358                 (parallel [(const_int 1)
5359                            (const_int 3)
5360                            (const_int 5)
5361                            (const_int 7)]))))))]
5362   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, V8HImode, operands)"
5363   "@
5364    pmaddwd\t{%2, %0|%0, %2}
5365    vpmaddwd\t{%2, %1, %0|%0, %1, %2}"
5366   [(set_attr "isa" "noavx,avx")
5367    (set_attr "type" "sseiadd")
5368    (set_attr "atom_unit" "simul")
5369    (set_attr "prefix_data16" "1,*")
5370    (set_attr "prefix" "orig,vex")
5371    (set_attr "mode" "TI")])
5372
5373 (define_expand "mul<mode>3"
5374   [(set (match_operand:VI4_AVX2 0 "register_operand" "")
5375         (mult:VI4_AVX2 (match_operand:VI4_AVX2 1 "register_operand" "")
5376                        (match_operand:VI4_AVX2 2 "register_operand" "")))]
5377   "TARGET_SSE2"
5378 {
5379   if (TARGET_SSE4_1 || TARGET_AVX)
5380     ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);
5381 })
5382
5383 (define_insn "*<sse4_1_avx2>_mul<mode>3"
5384   [(set (match_operand:VI4_AVX2 0 "register_operand" "=x,x")
5385         (mult:VI4_AVX2 (match_operand:VI4_AVX2 1 "nonimmediate_operand" "%0,x")
5386                        (match_operand:VI4_AVX2 2 "nonimmediate_operand" "xm,xm")))]
5387   "TARGET_SSE4_1 && ix86_binary_operator_ok (MULT, <MODE>mode, operands)"
5388   "@
5389    pmulld\t{%2, %0|%0, %2}
5390    vpmulld\t{%2, %1, %0|%0, %1, %2}"
5391   [(set_attr "isa" "noavx,avx")
5392    (set_attr "type" "sseimul")
5393    (set_attr "prefix_extra" "1")
5394    (set_attr "prefix" "orig,vex")
5395    (set_attr "mode" "<sseinsnmode>")])
5396
5397 (define_insn_and_split "*sse2_mulv4si3"
5398   [(set (match_operand:V4SI 0 "register_operand" "")
5399         (mult:V4SI (match_operand:V4SI 1 "register_operand" "")
5400                    (match_operand:V4SI 2 "register_operand" "")))]
5401   "TARGET_SSE2 && !TARGET_SSE4_1 && !TARGET_AVX
5402    && can_create_pseudo_p ()"
5403   "#"
5404   "&& 1"
5405   [(const_int 0)]
5406 {
5407   rtx t1, t2, t3, t4, t5, t6, thirtytwo;
5408   rtx op0, op1, op2;
5409
5410   op0 = operands[0];
5411   op1 = operands[1];
5412   op2 = operands[2];
5413   t1 = gen_reg_rtx (V4SImode);
5414   t2 = gen_reg_rtx (V4SImode);
5415   t3 = gen_reg_rtx (V4SImode);
5416   t4 = gen_reg_rtx (V4SImode);
5417   t5 = gen_reg_rtx (V4SImode);
5418   t6 = gen_reg_rtx (V4SImode);
5419   thirtytwo = GEN_INT (32);
5420
5421   /* Multiply elements 2 and 0.  */
5422   emit_insn (gen_sse2_umulv2siv2di3 (gen_lowpart (V2DImode, t1),
5423                                      op1, op2));
5424
5425   /* Shift both input vectors down one element, so that elements 3
5426      and 1 are now in the slots for elements 2 and 0.  For K8, at
5427      least, this is faster than using a shuffle.  */
5428   emit_insn (gen_sse2_lshrv1ti3 (gen_lowpart (V1TImode, t2),
5429                                  gen_lowpart (V1TImode, op1),
5430                                  thirtytwo));
5431   emit_insn (gen_sse2_lshrv1ti3 (gen_lowpart (V1TImode, t3),
5432                                  gen_lowpart (V1TImode, op2),
5433                                  thirtytwo));
5434   /* Multiply elements 3 and 1.  */
5435   emit_insn (gen_sse2_umulv2siv2di3 (gen_lowpart (V2DImode, t4),
5436                                      t2, t3));
5437
5438   /* Move the results in element 2 down to element 1; we don't care
5439      what goes in elements 2 and 3.  */
5440   emit_insn (gen_sse2_pshufd_1 (t5, t1, const0_rtx, const2_rtx,
5441                                 const0_rtx, const0_rtx));
5442   emit_insn (gen_sse2_pshufd_1 (t6, t4, const0_rtx, const2_rtx,
5443                                 const0_rtx, const0_rtx));
5444
5445   /* Merge the parts back together.  */
5446   emit_insn (gen_vec_interleave_lowv4si (op0, t5, t6));
5447
5448   set_unique_reg_note (get_last_insn (), REG_EQUAL,
5449                        gen_rtx_MULT (V4SImode, operands[1], operands[2]));
5450   DONE;
5451 })
5452
5453 (define_insn_and_split "mul<mode>3"
5454   [(set (match_operand:VI8_AVX2 0 "register_operand" "")
5455         (mult:VI8_AVX2 (match_operand:VI8_AVX2 1 "register_operand" "")
5456                        (match_operand:VI8_AVX2 2 "register_operand" "")))]
5457   "TARGET_SSE2
5458    && can_create_pseudo_p ()"
5459   "#"
5460   "&& 1"
5461   [(const_int 0)]
5462 {
5463   rtx t1, t2, t3, t4, t5, t6, thirtytwo;
5464   rtx op0, op1, op2;
5465
5466   op0 = operands[0];
5467   op1 = operands[1];
5468   op2 = operands[2];
5469
5470   if (TARGET_XOP && <MODE>mode == V2DImode)
5471     {
5472       /* op1: A,B,C,D, op2: E,F,G,H */
5473       op1 = gen_lowpart (V4SImode, op1);
5474       op2 = gen_lowpart (V4SImode, op2);
5475
5476       t1 = gen_reg_rtx (V4SImode);
5477       t2 = gen_reg_rtx (V4SImode);
5478       t3 = gen_reg_rtx (V2DImode);
5479       t4 = gen_reg_rtx (V2DImode);
5480
5481       /* t1: B,A,D,C */
5482       emit_insn (gen_sse2_pshufd_1 (t1, op1,
5483                                     GEN_INT (1),
5484                                     GEN_INT (0),
5485                                     GEN_INT (3),
5486                                     GEN_INT (2)));
5487
5488       /* t2: (B*E),(A*F),(D*G),(C*H) */
5489       emit_insn (gen_mulv4si3 (t2, t1, op2));
5490
5491       /* t4: (B*E)+(A*F), (D*G)+(C*H) */
5492       emit_insn (gen_xop_phadddq (t3, t2));
5493
5494       /* t5: ((B*E)+(A*F))<<32, ((D*G)+(C*H))<<32 */
5495       emit_insn (gen_ashlv2di3 (t4, t3, GEN_INT (32)));
5496
5497       /* op0: (((B*E)+(A*F))<<32)+(B*F), (((D*G)+(C*H))<<32)+(D*H) */
5498       emit_insn (gen_xop_pmacsdql (op0, op1, op2, t4));
5499     }
5500   else
5501     {
5502       t1 = gen_reg_rtx (<MODE>mode);
5503       t2 = gen_reg_rtx (<MODE>mode);
5504       t3 = gen_reg_rtx (<MODE>mode);
5505       t4 = gen_reg_rtx (<MODE>mode);
5506       t5 = gen_reg_rtx (<MODE>mode);
5507       t6 = gen_reg_rtx (<MODE>mode);
5508       thirtytwo = GEN_INT (32);
5509
5510       /* Multiply low parts.  */
5511       emit_insn (gen_<sse2_avx2>_umulv<ssescalarnum>si<mode>3
5512                   (t1, gen_lowpart (<ssepackmode>mode, op1),
5513                    gen_lowpart (<ssepackmode>mode, op2)));
5514
5515       /* Shift input vectors right 32 bits so we can multiply high parts.  */
5516       emit_insn (gen_lshr<mode>3 (t2, op1, thirtytwo));
5517       emit_insn (gen_lshr<mode>3 (t3, op2, thirtytwo));
5518
5519       /* Multiply high parts by low parts.  */
5520       emit_insn (gen_<sse2_avx2>_umulv<ssescalarnum>si<mode>3
5521                   (t4, gen_lowpart (<ssepackmode>mode, op1),
5522                    gen_lowpart (<ssepackmode>mode, t3)));
5523       emit_insn (gen_<sse2_avx2>_umulv<ssescalarnum>si<mode>3
5524                   (t5, gen_lowpart (<ssepackmode>mode, op2),
5525                    gen_lowpart (<ssepackmode>mode, t2)));
5526
5527       /* Shift them back.  */
5528       emit_insn (gen_ashl<mode>3 (t4, t4, thirtytwo));
5529       emit_insn (gen_ashl<mode>3 (t5, t5, thirtytwo));
5530
5531       /* Add the three parts together.  */
5532       emit_insn (gen_add<mode>3 (t6, t1, t4));
5533       emit_insn (gen_add<mode>3 (op0, t6, t5));
5534     }
5535
5536   set_unique_reg_note (get_last_insn (), REG_EQUAL,
5537                        gen_rtx_MULT (<MODE>mode, operands[1], operands[2]));
5538   DONE;
5539 })
5540
5541 (define_expand "vec_widen_<s>mult_hi_<mode>"
5542   [(match_operand:<sseunpackmode> 0 "register_operand" "")
5543    (any_extend:<sseunpackmode>
5544      (match_operand:VI2_AVX2 1 "register_operand" ""))
5545    (match_operand:VI2_AVX2 2 "register_operand" "")]
5546   "TARGET_SSE2"
5547 {
5548   rtx op1, op2, t1, t2, dest;
5549
5550   op1 = operands[1];
5551   op2 = operands[2];
5552   t1 = gen_reg_rtx (<MODE>mode);
5553   t2 = gen_reg_rtx (<MODE>mode);
5554   dest = gen_lowpart (<MODE>mode, operands[0]);
5555
5556   emit_insn (gen_mul<mode>3 (t1, op1, op2));
5557   emit_insn (gen_<s>mul<mode>3_highpart (t2, op1, op2));
5558   emit_insn (gen_vec_interleave_high<mode> (dest, t1, t2));
5559   DONE;
5560 })
5561
5562 (define_expand "vec_widen_<s>mult_lo_<mode>"
5563   [(match_operand:<sseunpackmode> 0 "register_operand" "")
5564    (any_extend:<sseunpackmode>
5565      (match_operand:VI2_AVX2 1 "register_operand" ""))
5566    (match_operand:VI2_AVX2 2 "register_operand" "")]
5567   "TARGET_SSE2"
5568 {
5569   rtx op1, op2, t1, t2, dest;
5570
5571   op1 = operands[1];
5572   op2 = operands[2];
5573   t1 = gen_reg_rtx (<MODE>mode);
5574   t2 = gen_reg_rtx (<MODE>mode);
5575   dest = gen_lowpart (<MODE>mode, operands[0]);
5576
5577   emit_insn (gen_mul<mode>3 (t1, op1, op2));
5578   emit_insn (gen_<s>mul<mode>3_highpart (t2, op1, op2));
5579   emit_insn (gen_vec_interleave_low<mode> (dest, t1, t2));
5580   DONE;
5581 })
5582
5583 (define_expand "vec_widen_<s>mult_hi_v8si"
5584   [(match_operand:V4DI 0 "register_operand" "")
5585    (any_extend:V4DI (match_operand:V8SI 1 "nonimmediate_operand" ""))
5586    (match_operand:V8SI 2 "nonimmediate_operand" "")]
5587   "TARGET_AVX2"
5588 {
5589   rtx t1, t2, t3, t4;
5590
5591   t1 = gen_reg_rtx (V4DImode);
5592   t2 = gen_reg_rtx (V4DImode);
5593   t3 = gen_reg_rtx (V8SImode);
5594   t4 = gen_reg_rtx (V8SImode);
5595   emit_insn (gen_avx2_permv4di_1 (t1, gen_lowpart (V4DImode, operands[1]),
5596                                   const0_rtx, const2_rtx,
5597                                   const1_rtx, GEN_INT (3)));
5598   emit_insn (gen_avx2_permv4di_1 (t2, gen_lowpart (V4DImode, operands[2]),
5599                                   const0_rtx, const2_rtx,
5600                                   const1_rtx, GEN_INT (3)));
5601   emit_insn (gen_avx2_pshufdv3 (t3, gen_lowpart (V8SImode, t1),
5602                                 GEN_INT (2 + (2 << 2) + (3 << 4) + (3 << 6))));
5603   emit_insn (gen_avx2_pshufdv3 (t4, gen_lowpart (V8SImode, t2),
5604                                 GEN_INT (2 + (2 << 2) + (3 << 4) + (3 << 6))));
5605   emit_insn (gen_avx2_<u>mulv4siv4di3 (operands[0], t3, t4));
5606   DONE;
5607 })
5608
5609 (define_expand "vec_widen_<s>mult_lo_v8si"
5610   [(match_operand:V4DI 0 "register_operand" "")
5611    (any_extend:V4DI (match_operand:V8SI 1 "nonimmediate_operand" ""))
5612    (match_operand:V8SI 2 "nonimmediate_operand" "")]
5613   "TARGET_AVX2"
5614 {
5615   rtx t1, t2, t3, t4;
5616
5617   t1 = gen_reg_rtx (V4DImode);
5618   t2 = gen_reg_rtx (V4DImode);
5619   t3 = gen_reg_rtx (V8SImode);
5620   t4 = gen_reg_rtx (V8SImode);
5621   emit_insn (gen_avx2_permv4di_1 (t1, gen_lowpart (V4DImode, operands[1]),
5622                                   const0_rtx, const2_rtx,
5623                                   const1_rtx, GEN_INT (3)));
5624   emit_insn (gen_avx2_permv4di_1 (t2,  gen_lowpart (V4DImode, operands[2]),
5625                                   const0_rtx, const2_rtx,
5626                                   const1_rtx, GEN_INT (3)));
5627   emit_insn (gen_avx2_pshufdv3 (t3, gen_lowpart (V8SImode, t1),
5628                                 GEN_INT (0 + (0 << 2) + (1 << 4) + (1 << 6))));
5629   emit_insn (gen_avx2_pshufdv3 (t4, gen_lowpart (V8SImode, t2),
5630                                 GEN_INT (0 + (0 << 2) + (1 << 4) + (1 << 6))));
5631   emit_insn (gen_avx2_<u>mulv4siv4di3 (operands[0], t3, t4));
5632   DONE;
5633 })
5634
5635 (define_expand "vec_widen_smult_hi_v4si"
5636   [(match_operand:V2DI 0 "register_operand" "")
5637    (match_operand:V4SI 1 "register_operand" "")
5638    (match_operand:V4SI 2 "register_operand" "")]
5639   "TARGET_SSE4_1"
5640 {
5641   rtx op1, op2, t1, t2;
5642
5643   op1 = operands[1];
5644   op2 = operands[2];
5645   t1 = gen_reg_rtx (V4SImode);
5646   t2 = gen_reg_rtx (V4SImode);
5647
5648   if (TARGET_XOP)
5649     {
5650       emit_insn (gen_sse2_pshufd_1 (t1, op1, GEN_INT (0), GEN_INT (2),
5651                                     GEN_INT (1), GEN_INT (3)));
5652       emit_insn (gen_sse2_pshufd_1 (t2, op2, GEN_INT (0), GEN_INT (2),
5653                                     GEN_INT (1), GEN_INT (3)));
5654       emit_insn (gen_xop_mulv2div2di3_high (operands[0], t1, t2));
5655       DONE;
5656     }
5657
5658   emit_insn (gen_vec_interleave_highv4si (t1, op1, op1));
5659   emit_insn (gen_vec_interleave_highv4si (t2, op2, op2));
5660   emit_insn (gen_sse4_1_mulv2siv2di3 (operands[0], t1, t2));
5661   DONE;
5662 })
5663
5664 (define_expand "vec_widen_smult_lo_v4si"
5665   [(match_operand:V2DI 0 "register_operand" "")
5666    (match_operand:V4SI 1 "register_operand" "")
5667    (match_operand:V4SI 2 "register_operand" "")]
5668   "TARGET_SSE4_1"
5669 {
5670   rtx op1, op2, t1, t2;
5671
5672   op1 = operands[1];
5673   op2 = operands[2];
5674   t1 = gen_reg_rtx (V4SImode);
5675   t2 = gen_reg_rtx (V4SImode);
5676
5677   if (TARGET_XOP)
5678     {
5679       emit_insn (gen_sse2_pshufd_1 (t1, op1, GEN_INT (0), GEN_INT (2),
5680                                     GEN_INT (1), GEN_INT (3)));
5681       emit_insn (gen_sse2_pshufd_1 (t2, op2, GEN_INT (0), GEN_INT (2),
5682                                     GEN_INT (1), GEN_INT (3)));
5683       emit_insn (gen_xop_mulv2div2di3_low (operands[0], t1, t2));
5684       DONE;
5685     }
5686
5687   emit_insn (gen_vec_interleave_lowv4si (t1, op1, op1));
5688   emit_insn (gen_vec_interleave_lowv4si (t2, op2, op2));
5689   emit_insn (gen_sse4_1_mulv2siv2di3 (operands[0], t1, t2));
5690   DONE;
5691 })
5692
5693 (define_expand "vec_widen_umult_hi_v4si"
5694   [(match_operand:V2DI 0 "register_operand" "")
5695    (match_operand:V4SI 1 "register_operand" "")
5696    (match_operand:V4SI 2 "register_operand" "")]
5697   "TARGET_SSE2"
5698 {
5699   rtx op1, op2, t1, t2;
5700
5701   op1 = operands[1];
5702   op2 = operands[2];
5703   t1 = gen_reg_rtx (V4SImode);
5704   t2 = gen_reg_rtx (V4SImode);
5705
5706   emit_insn (gen_vec_interleave_highv4si (t1, op1, op1));
5707   emit_insn (gen_vec_interleave_highv4si (t2, op2, op2));
5708   emit_insn (gen_sse2_umulv2siv2di3 (operands[0], t1, t2));
5709   DONE;
5710 })
5711
5712 (define_expand "vec_widen_umult_lo_v4si"
5713   [(match_operand:V2DI 0 "register_operand" "")
5714    (match_operand:V4SI 1 "register_operand" "")
5715    (match_operand:V4SI 2 "register_operand" "")]
5716   "TARGET_SSE2"
5717 {
5718   rtx op1, op2, t1, t2;
5719
5720   op1 = operands[1];
5721   op2 = operands[2];
5722   t1 = gen_reg_rtx (V4SImode);
5723   t2 = gen_reg_rtx (V4SImode);
5724
5725   emit_insn (gen_vec_interleave_lowv4si (t1, op1, op1));
5726   emit_insn (gen_vec_interleave_lowv4si (t2, op2, op2));
5727   emit_insn (gen_sse2_umulv2siv2di3 (operands[0], t1, t2));
5728   DONE;
5729 })
5730
5731 (define_expand "sdot_prod<mode>"
5732   [(match_operand:<sseunpackmode> 0 "register_operand" "")
5733    (match_operand:VI2_AVX2 1 "register_operand" "")
5734    (match_operand:VI2_AVX2 2 "register_operand" "")
5735    (match_operand:<sseunpackmode> 3 "register_operand" "")]
5736   "TARGET_SSE2"
5737 {
5738   rtx t = gen_reg_rtx (<sseunpackmode>mode);
5739   emit_insn (gen_<sse2_avx2>_pmaddwd (t, operands[1], operands[2]));
5740   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
5741                           gen_rtx_PLUS (<sseunpackmode>mode,
5742                                         operands[3], t)));
5743   DONE;
5744 })
5745
5746 (define_code_attr sse2_sse4_1
5747    [(zero_extend "sse2") (sign_extend "sse4_1")])
5748
5749 (define_expand "<s>dot_prodv4si"
5750   [(match_operand:V2DI 0 "register_operand" "")
5751    (any_extend:V2DI (match_operand:V4SI 1 "register_operand" ""))
5752    (match_operand:V4SI 2 "register_operand" "")
5753    (match_operand:V2DI 3 "register_operand" "")]
5754   "<CODE> == ZERO_EXTEND ? TARGET_SSE2 : TARGET_SSE4_1"
5755 {
5756   rtx t1, t2, t3, t4;
5757
5758   t1 = gen_reg_rtx (V2DImode);
5759   emit_insn (gen_<sse2_sse4_1>_<u>mulv2siv2di3 (t1, operands[1], operands[2]));
5760   emit_insn (gen_addv2di3 (t1, t1, operands[3]));
5761
5762   t2 = gen_reg_rtx (V4SImode);
5763   t3 = gen_reg_rtx (V4SImode);
5764   emit_insn (gen_sse2_lshrv1ti3 (gen_lowpart (V1TImode, t2),
5765                                  gen_lowpart (V1TImode, operands[1]),
5766                                  GEN_INT (32)));
5767   emit_insn (gen_sse2_lshrv1ti3 (gen_lowpart (V1TImode, t3),
5768                                  gen_lowpart (V1TImode, operands[2]),
5769                                  GEN_INT (32)));
5770
5771   t4 = gen_reg_rtx (V2DImode);
5772   emit_insn (gen_<sse2_sse4_1>_<u>mulv2siv2di3 (t4, t2, t3));
5773
5774   emit_insn (gen_addv2di3 (operands[0], t1, t4));
5775   DONE;
5776 })
5777
5778 (define_expand "<s>dot_prodv8si"
5779   [(match_operand:V4DI 0 "register_operand" "")
5780    (any_extend:V4DI (match_operand:V8SI 1 "register_operand" ""))
5781    (match_operand:V8SI 2 "register_operand" "")
5782    (match_operand:V4DI 3 "register_operand" "")]
5783   "TARGET_AVX2"
5784 {
5785   rtx t1, t2, t3, t4;
5786
5787   t1 = gen_reg_rtx (V4DImode);
5788   emit_insn (gen_avx2_<u>mulv4siv4di3 (t1, operands[1], operands[2]));
5789   emit_insn (gen_addv4di3 (t1, t1, operands[3]));
5790
5791   t2 = gen_reg_rtx (V8SImode);
5792   t3 = gen_reg_rtx (V8SImode);
5793   emit_insn (gen_avx2_lshrv2ti3 (gen_lowpart (V2TImode, t2),
5794                                  gen_lowpart (V2TImode, operands[1]),
5795                                  GEN_INT (32)));
5796   emit_insn (gen_avx2_lshrv2ti3 (gen_lowpart (V2TImode, t3),
5797                                  gen_lowpart (V2TImode, operands[2]),
5798                                  GEN_INT (32)));
5799
5800   t4 = gen_reg_rtx (V4DImode);
5801   emit_insn (gen_avx2_<u>mulv4siv4di3 (t4, t2, t3));
5802
5803   emit_insn (gen_addv4di3 (operands[0], t1, t4));
5804   DONE;
5805 })
5806
5807 (define_insn "ashr<mode>3"
5808   [(set (match_operand:VI24_AVX2 0 "register_operand" "=x,x")
5809         (ashiftrt:VI24_AVX2
5810           (match_operand:VI24_AVX2 1 "register_operand" "0,x")
5811           (match_operand:SI 2 "nonmemory_operand" "xN,xN")))]
5812   "TARGET_SSE2"
5813   "@
5814    psra<ssemodesuffix>\t{%2, %0|%0, %2}
5815    vpsra<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5816   [(set_attr "isa" "noavx,avx")
5817    (set_attr "type" "sseishft")
5818    (set (attr "length_immediate")
5819      (if_then_else (match_operand 2 "const_int_operand" "")
5820        (const_string "1")
5821        (const_string "0")))
5822    (set_attr "prefix_data16" "1,*")
5823    (set_attr "prefix" "orig,vex")
5824    (set_attr "mode" "<sseinsnmode>")])
5825
5826 (define_insn "<shift_insn><mode>3"
5827   [(set (match_operand:VI248_AVX2 0 "register_operand" "=x,x")
5828         (any_lshift:VI248_AVX2
5829           (match_operand:VI248_AVX2 1 "register_operand" "0,x")
5830           (match_operand:SI 2 "nonmemory_operand" "xN,xN")))]
5831   "TARGET_SSE2"
5832   "@
5833    p<vshift><ssemodesuffix>\t{%2, %0|%0, %2}
5834    vp<vshift><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5835   [(set_attr "isa" "noavx,avx")
5836    (set_attr "type" "sseishft")
5837    (set (attr "length_immediate")
5838      (if_then_else (match_operand 2 "const_int_operand" "")
5839        (const_string "1")
5840        (const_string "0")))
5841    (set_attr "prefix_data16" "1,*")
5842    (set_attr "prefix" "orig,vex")
5843    (set_attr "mode" "<sseinsnmode>")])
5844
5845 (define_expand "vec_shl_<mode>"
5846   [(set (match_operand:VI_128 0 "register_operand" "")
5847         (ashift:V1TI
5848          (match_operand:VI_128 1 "register_operand" "")
5849          (match_operand:SI 2 "const_0_to_255_mul_8_operand" "")))]
5850   "TARGET_SSE2"
5851 {
5852   operands[0] = gen_lowpart (V1TImode, operands[0]);
5853   operands[1] = gen_lowpart (V1TImode, operands[1]);
5854 })
5855
5856 (define_insn "<sse2_avx2>_ashl<mode>3"
5857   [(set (match_operand:VIMAX_AVX2 0 "register_operand" "=x,x")
5858         (ashift:VIMAX_AVX2
5859          (match_operand:VIMAX_AVX2 1 "register_operand" "0,x")
5860          (match_operand:SI 2 "const_0_to_255_mul_8_operand" "n,n")))]
5861   "TARGET_SSE2"
5862 {
5863   operands[2] = GEN_INT (INTVAL (operands[2]) / 8);
5864
5865   switch (which_alternative)
5866     {
5867     case 0:
5868       return "pslldq\t{%2, %0|%0, %2}";
5869     case 1:
5870       return "vpslldq\t{%2, %1, %0|%0, %1, %2}";
5871     default:
5872       gcc_unreachable ();
5873     }
5874 }
5875   [(set_attr "isa" "noavx,avx")
5876    (set_attr "type" "sseishft")
5877    (set_attr "length_immediate" "1")
5878    (set_attr "prefix_data16" "1,*")
5879    (set_attr "prefix" "orig,vex")
5880    (set_attr "mode" "<sseinsnmode>")])
5881
5882 (define_expand "vec_shr_<mode>"
5883   [(set (match_operand:VI_128 0 "register_operand" "")
5884         (lshiftrt:V1TI
5885          (match_operand:VI_128 1 "register_operand" "")
5886          (match_operand:SI 2 "const_0_to_255_mul_8_operand" "")))]
5887   "TARGET_SSE2"
5888 {
5889   operands[0] = gen_lowpart (V1TImode, operands[0]);
5890   operands[1] = gen_lowpart (V1TImode, operands[1]);
5891 })
5892
5893 (define_insn "<sse2_avx2>_lshr<mode>3"
5894   [(set (match_operand:VIMAX_AVX2 0 "register_operand" "=x,x")
5895         (lshiftrt:VIMAX_AVX2
5896          (match_operand:VIMAX_AVX2 1 "register_operand" "0,x")
5897          (match_operand:SI 2 "const_0_to_255_mul_8_operand" "n,n")))]
5898   "TARGET_SSE2"
5899 {
5900   operands[2] = GEN_INT (INTVAL (operands[2]) / 8);
5901
5902   switch (which_alternative)
5903     {
5904     case 0:
5905       return "psrldq\t{%2, %0|%0, %2}";
5906     case 1:
5907       return "vpsrldq\t{%2, %1, %0|%0, %1, %2}";
5908     default:
5909       gcc_unreachable ();
5910     }
5911 }
5912   [(set_attr "isa" "noavx,avx")
5913    (set_attr "type" "sseishft")
5914    (set_attr "length_immediate" "1")
5915    (set_attr "atom_unit" "sishuf")
5916    (set_attr "prefix_data16" "1,*")
5917    (set_attr "prefix" "orig,vex")
5918    (set_attr "mode" "<sseinsnmode>")])
5919
5920
5921 (define_expand "<code><mode>3"
5922   [(set (match_operand:VI124_256 0 "register_operand" "")
5923         (maxmin:VI124_256
5924           (match_operand:VI124_256 1 "nonimmediate_operand" "")
5925           (match_operand:VI124_256 2 "nonimmediate_operand" "")))]
5926   "TARGET_AVX2"
5927   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
5928
5929 (define_insn "*avx2_<code><mode>3"
5930   [(set (match_operand:VI124_256 0 "register_operand" "=x")
5931         (maxmin:VI124_256
5932           (match_operand:VI124_256 1 "nonimmediate_operand" "%x")
5933           (match_operand:VI124_256 2 "nonimmediate_operand" "xm")))]
5934   "TARGET_AVX2 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
5935   "vp<maxmin_int><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5936   [(set_attr "type" "sseiadd")
5937    (set_attr "prefix_extra" "1")
5938    (set_attr "prefix" "vex")
5939    (set_attr "mode" "OI")])
5940
5941 (define_expand "<code><mode>3"
5942   [(set (match_operand:VI8_AVX2 0 "register_operand" "")
5943         (maxmin:VI8_AVX2
5944           (match_operand:VI8_AVX2 1 "register_operand" "")
5945           (match_operand:VI8_AVX2 2 "register_operand" "")))]
5946   "TARGET_SSE4_2"
5947 {
5948   enum rtx_code code;
5949   rtx xops[6];
5950   bool ok;
5951
5952   xops[0] = operands[0];
5953
5954   if (<CODE> == SMAX || <CODE> == UMAX)
5955     {
5956       xops[1] = operands[1];
5957       xops[2] = operands[2];
5958     }
5959   else
5960     {
5961       xops[1] = operands[2];
5962       xops[2] = operands[1];
5963     }
5964
5965   code = (<CODE> == UMAX || <CODE> == UMIN) ? GTU : GT;
5966
5967   xops[3] = gen_rtx_fmt_ee (code, VOIDmode, operands[1], operands[2]);
5968   xops[4] = operands[1];
5969   xops[5] = operands[2];
5970
5971   ok = ix86_expand_int_vcond (xops);
5972   gcc_assert (ok);
5973   DONE;
5974 })
5975
5976 (define_expand "<code><mode>3"
5977   [(set (match_operand:VI124_128 0 "register_operand" "")
5978         (smaxmin:VI124_128
5979           (match_operand:VI124_128 1 "nonimmediate_operand" "")
5980           (match_operand:VI124_128 2 "nonimmediate_operand" "")))]
5981   "TARGET_SSE2"
5982 {
5983   if (TARGET_SSE4_1 || <MODE>mode == V8HImode)
5984     ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);
5985   else
5986     {
5987       rtx xops[6];
5988       bool ok;
5989
5990       xops[0] = operands[0];
5991       operands[1] = force_reg (<MODE>mode, operands[1]);
5992       operands[2] = force_reg (<MODE>mode, operands[2]);
5993
5994       if (<CODE> == SMAX)
5995         {
5996           xops[1] = operands[1];
5997           xops[2] = operands[2];
5998         }
5999       else
6000         {
6001           xops[1] = operands[2];
6002           xops[2] = operands[1];
6003         }
6004
6005       xops[3] = gen_rtx_GT (VOIDmode, operands[1], operands[2]);
6006       xops[4] = operands[1];
6007       xops[5] = operands[2];
6008
6009       ok = ix86_expand_int_vcond (xops);
6010       gcc_assert (ok);
6011       DONE;
6012     }
6013 })
6014
6015 (define_insn "*sse4_1_<code><mode>3"
6016   [(set (match_operand:VI14_128 0 "register_operand" "=x,x")
6017         (smaxmin:VI14_128
6018           (match_operand:VI14_128 1 "nonimmediate_operand" "%0,x")
6019           (match_operand:VI14_128 2 "nonimmediate_operand" "xm,xm")))]
6020   "TARGET_SSE4_1 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
6021   "@
6022    p<maxmin_int><ssemodesuffix>\t{%2, %0|%0, %2}
6023    vp<maxmin_int><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6024   [(set_attr "isa" "noavx,avx")
6025    (set_attr "type" "sseiadd")
6026    (set_attr "prefix_extra" "1,*")
6027    (set_attr "prefix" "orig,vex")
6028    (set_attr "mode" "TI")])
6029
6030 (define_insn "*<code>v8hi3"
6031   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
6032         (smaxmin:V8HI
6033           (match_operand:V8HI 1 "nonimmediate_operand" "%0,x")
6034           (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")))]
6035   "TARGET_SSE2 && ix86_binary_operator_ok (<CODE>, V8HImode, operands)"
6036   "@
6037    p<maxmin_int>w\t{%2, %0|%0, %2}
6038    vp<maxmin_int>w\t{%2, %1, %0|%0, %1, %2}"
6039   [(set_attr "isa" "noavx,avx")
6040    (set_attr "type" "sseiadd")
6041    (set_attr "prefix_data16" "1,*")
6042    (set_attr "prefix_extra" "*,1")
6043    (set_attr "prefix" "orig,vex")
6044    (set_attr "mode" "TI")])
6045
6046 (define_expand "<code><mode>3"
6047   [(set (match_operand:VI124_128 0 "register_operand" "")
6048         (umaxmin:VI124_128
6049           (match_operand:VI124_128 1 "nonimmediate_operand" "")
6050           (match_operand:VI124_128 2 "nonimmediate_operand" "")))]
6051   "TARGET_SSE2"
6052 {
6053   if (TARGET_SSE4_1 || <MODE>mode == V16QImode)
6054     ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);
6055   else if (<CODE> == UMAX && <MODE>mode == V8HImode)
6056     {
6057       rtx op0 = operands[0], op2 = operands[2], op3 = op0;
6058       operands[1] = force_reg (<MODE>mode, operands[1]);
6059       if (rtx_equal_p (op3, op2))
6060         op3 = gen_reg_rtx (V8HImode);
6061       emit_insn (gen_sse2_ussubv8hi3 (op3, operands[1], op2));
6062       emit_insn (gen_addv8hi3 (op0, op3, op2));
6063       DONE;
6064     }
6065   else
6066     {
6067       rtx xops[6];
6068       bool ok;
6069
6070       operands[1] = force_reg (<MODE>mode, operands[1]);
6071       operands[2] = force_reg (<MODE>mode, operands[2]);
6072
6073       xops[0] = operands[0];
6074
6075       if (<CODE> == UMAX)
6076         {
6077           xops[1] = operands[1];
6078           xops[2] = operands[2];
6079         }
6080       else
6081         {
6082           xops[1] = operands[2];
6083           xops[2] = operands[1];
6084         }
6085
6086       xops[3] = gen_rtx_GTU (VOIDmode, operands[1], operands[2]);
6087       xops[4] = operands[1];
6088       xops[5] = operands[2];
6089
6090       ok = ix86_expand_int_vcond (xops);
6091       gcc_assert (ok);
6092       DONE;
6093     }
6094 })
6095
6096 (define_insn "*sse4_1_<code><mode>3"
6097   [(set (match_operand:VI24_128 0 "register_operand" "=x,x")
6098         (umaxmin:VI24_128
6099           (match_operand:VI24_128 1 "nonimmediate_operand" "%0,x")
6100           (match_operand:VI24_128 2 "nonimmediate_operand" "xm,xm")))]
6101   "TARGET_SSE4_1 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
6102   "@
6103    p<maxmin_int><ssemodesuffix>\t{%2, %0|%0, %2}
6104    vp<maxmin_int><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6105   [(set_attr "isa" "noavx,avx")
6106    (set_attr "type" "sseiadd")
6107    (set_attr "prefix_extra" "1,*")
6108    (set_attr "prefix" "orig,vex")
6109    (set_attr "mode" "TI")])
6110
6111 (define_insn "*<code>v16qi3"
6112   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
6113         (umaxmin:V16QI
6114           (match_operand:V16QI 1 "nonimmediate_operand" "%0,x")
6115           (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm")))]
6116   "TARGET_SSE2 && ix86_binary_operator_ok (<CODE>, V16QImode, operands)"
6117   "@
6118    p<maxmin_int>b\t{%2, %0|%0, %2}
6119    vp<maxmin_int>b\t{%2, %1, %0|%0, %1, %2}"
6120   [(set_attr "isa" "noavx,avx")
6121    (set_attr "type" "sseiadd")
6122    (set_attr "prefix_data16" "1,*")
6123    (set_attr "prefix_extra" "*,1")
6124    (set_attr "prefix" "orig,vex")
6125    (set_attr "mode" "TI")])
6126
6127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6128 ;;
6129 ;; Parallel integral comparisons
6130 ;;
6131 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6132
6133 (define_expand "avx2_eq<mode>3"
6134   [(set (match_operand:VI_256 0 "register_operand" "")
6135         (eq:VI_256
6136           (match_operand:VI_256 1 "nonimmediate_operand" "")
6137           (match_operand:VI_256 2 "nonimmediate_operand" "")))]
6138   "TARGET_AVX2"
6139   "ix86_fixup_binary_operands_no_copy (EQ, <MODE>mode, operands);")
6140
6141 (define_insn "*avx2_eq<mode>3"
6142   [(set (match_operand:VI_256 0 "register_operand" "=x")
6143         (eq:VI_256
6144           (match_operand:VI_256 1 "nonimmediate_operand" "%x")
6145           (match_operand:VI_256 2 "nonimmediate_operand" "xm")))]
6146   "TARGET_AVX2 && ix86_binary_operator_ok (EQ, <MODE>mode, operands)"
6147   "vpcmpeq<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6148   [(set_attr "type" "ssecmp")
6149    (set_attr "prefix_extra" "1")
6150    (set_attr "prefix" "vex")
6151    (set_attr "mode" "OI")])
6152
6153 (define_insn "*sse4_1_eqv2di3"
6154   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
6155         (eq:V2DI
6156           (match_operand:V2DI 1 "nonimmediate_operand" "%0,x")
6157           (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")))]
6158   "TARGET_SSE4_1 && ix86_binary_operator_ok (EQ, V2DImode, operands)"
6159   "@
6160    pcmpeqq\t{%2, %0|%0, %2}
6161    vpcmpeqq\t{%2, %1, %0|%0, %1, %2}"
6162   [(set_attr "isa" "noavx,avx")
6163    (set_attr "type" "ssecmp")
6164    (set_attr "prefix_extra" "1")
6165    (set_attr "prefix" "orig,vex")
6166    (set_attr "mode" "TI")])
6167
6168 (define_insn "*sse2_eq<mode>3"
6169   [(set (match_operand:VI124_128 0 "register_operand" "=x,x")
6170         (eq:VI124_128
6171           (match_operand:VI124_128 1 "nonimmediate_operand" "%0,x")
6172           (match_operand:VI124_128 2 "nonimmediate_operand" "xm,xm")))]
6173   "TARGET_SSE2 && !TARGET_XOP
6174    && ix86_binary_operator_ok (EQ, <MODE>mode, operands)"
6175   "@
6176    pcmpeq<ssemodesuffix>\t{%2, %0|%0, %2}
6177    vpcmpeq<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6178   [(set_attr "isa" "noavx,avx")
6179    (set_attr "type" "ssecmp")
6180    (set_attr "prefix_data16" "1,*")
6181    (set_attr "prefix" "orig,vex")
6182    (set_attr "mode" "TI")])
6183
6184 (define_expand "sse2_eq<mode>3"
6185   [(set (match_operand:VI124_128 0 "register_operand" "")
6186         (eq:VI124_128
6187           (match_operand:VI124_128 1 "nonimmediate_operand" "")
6188           (match_operand:VI124_128 2 "nonimmediate_operand" "")))]
6189   "TARGET_SSE2 && !TARGET_XOP "
6190   "ix86_fixup_binary_operands_no_copy (EQ, <MODE>mode, operands);")
6191
6192 (define_expand "sse4_1_eqv2di3"
6193   [(set (match_operand:V2DI 0 "register_operand" "")
6194         (eq:V2DI
6195           (match_operand:V2DI 1 "nonimmediate_operand" "")
6196           (match_operand:V2DI 2 "nonimmediate_operand" "")))]
6197   "TARGET_SSE4_1"
6198   "ix86_fixup_binary_operands_no_copy (EQ, V2DImode, operands);")
6199
6200 (define_insn "sse4_2_gtv2di3"
6201   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
6202         (gt:V2DI
6203           (match_operand:V2DI 1 "register_operand" "0,x")
6204           (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")))]
6205   "TARGET_SSE4_2"
6206   "@
6207    pcmpgtq\t{%2, %0|%0, %2}
6208    vpcmpgtq\t{%2, %1, %0|%0, %1, %2}"
6209   [(set_attr "isa" "noavx,avx")
6210    (set_attr "type" "ssecmp")
6211    (set_attr "prefix_extra" "1")
6212    (set_attr "prefix" "orig,vex")
6213    (set_attr "mode" "TI")])
6214
6215 (define_insn "avx2_gt<mode>3"
6216   [(set (match_operand:VI_256 0 "register_operand" "=x")
6217         (gt:VI_256
6218           (match_operand:VI_256 1 "register_operand" "x")
6219           (match_operand:VI_256 2 "nonimmediate_operand" "xm")))]
6220   "TARGET_AVX2"
6221   "vpcmpgt<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6222   [(set_attr "type" "ssecmp")
6223    (set_attr "prefix_extra" "1")
6224    (set_attr "prefix" "vex")
6225    (set_attr "mode" "OI")])
6226
6227 (define_insn "sse2_gt<mode>3"
6228   [(set (match_operand:VI124_128 0 "register_operand" "=x,x")
6229         (gt:VI124_128
6230           (match_operand:VI124_128 1 "register_operand" "0,x")
6231           (match_operand:VI124_128 2 "nonimmediate_operand" "xm,xm")))]
6232   "TARGET_SSE2 && !TARGET_XOP"
6233   "@
6234    pcmpgt<ssemodesuffix>\t{%2, %0|%0, %2}
6235    vpcmpgt<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6236   [(set_attr "isa" "noavx,avx")
6237    (set_attr "type" "ssecmp")
6238    (set_attr "prefix_data16" "1,*")
6239    (set_attr "prefix" "orig,vex")
6240    (set_attr "mode" "TI")])
6241
6242 (define_expand "vcond<V_256:mode><VI_256:mode>"
6243   [(set (match_operand:V_256 0 "register_operand" "")
6244         (if_then_else:V_256
6245           (match_operator 3 ""
6246             [(match_operand:VI_256 4 "nonimmediate_operand" "")
6247              (match_operand:VI_256 5 "nonimmediate_operand" "")])
6248           (match_operand:V_256 1 "general_operand" "")
6249           (match_operand:V_256 2 "general_operand" "")))]
6250   "TARGET_AVX2
6251    && (GET_MODE_NUNITS (<V_256:MODE>mode)
6252        == GET_MODE_NUNITS (<VI_256:MODE>mode))"
6253 {
6254   bool ok = ix86_expand_int_vcond (operands);
6255   gcc_assert (ok);
6256   DONE;
6257 })
6258
6259 (define_expand "vcond<V_128:mode><VI124_128:mode>"
6260   [(set (match_operand:V_128 0 "register_operand" "")
6261         (if_then_else:V_128
6262           (match_operator 3 ""
6263             [(match_operand:VI124_128 4 "nonimmediate_operand" "")
6264              (match_operand:VI124_128 5 "nonimmediate_operand" "")])
6265           (match_operand:V_128 1 "general_operand" "")
6266           (match_operand:V_128 2 "general_operand" "")))]
6267   "TARGET_SSE2
6268    && (GET_MODE_NUNITS (<V_128:MODE>mode)
6269        == GET_MODE_NUNITS (<VI124_128:MODE>mode))"
6270 {
6271   bool ok = ix86_expand_int_vcond (operands);
6272   gcc_assert (ok);
6273   DONE;
6274 })
6275
6276 (define_expand "vcond<VI8F_128:mode>v2di"
6277   [(set (match_operand:VI8F_128 0 "register_operand" "")
6278         (if_then_else:VI8F_128
6279           (match_operator 3 ""
6280             [(match_operand:V2DI 4 "nonimmediate_operand" "")
6281              (match_operand:V2DI 5 "nonimmediate_operand" "")])
6282           (match_operand:VI8F_128 1 "general_operand" "")
6283           (match_operand:VI8F_128 2 "general_operand" "")))]
6284   "TARGET_SSE4_2"
6285 {
6286   bool ok = ix86_expand_int_vcond (operands);
6287   gcc_assert (ok);
6288   DONE;
6289 })
6290
6291 (define_expand "vcondu<V_256:mode><VI_256:mode>"
6292   [(set (match_operand:V_256 0 "register_operand" "")
6293         (if_then_else:V_256
6294           (match_operator 3 ""
6295             [(match_operand:VI_256 4 "nonimmediate_operand" "")
6296              (match_operand:VI_256 5 "nonimmediate_operand" "")])
6297           (match_operand:V_256 1 "general_operand" "")
6298           (match_operand:V_256 2 "general_operand" "")))]
6299   "TARGET_AVX2
6300    && (GET_MODE_NUNITS (<V_256:MODE>mode)
6301        == GET_MODE_NUNITS (<VI_256:MODE>mode))"
6302 {
6303   bool ok = ix86_expand_int_vcond (operands);
6304   gcc_assert (ok);
6305   DONE;
6306 })
6307
6308 (define_expand "vcondu<V_128:mode><VI124_128:mode>"
6309   [(set (match_operand:V_128 0 "register_operand" "")
6310         (if_then_else:V_128
6311           (match_operator 3 ""
6312             [(match_operand:VI124_128 4 "nonimmediate_operand" "")
6313              (match_operand:VI124_128 5 "nonimmediate_operand" "")])
6314           (match_operand:V_128 1 "general_operand" "")
6315           (match_operand:V_128 2 "general_operand" "")))]
6316   "TARGET_SSE2
6317    && (GET_MODE_NUNITS (<V_128:MODE>mode)
6318        == GET_MODE_NUNITS (<VI124_128:MODE>mode))"
6319 {
6320   bool ok = ix86_expand_int_vcond (operands);
6321   gcc_assert (ok);
6322   DONE;
6323 })
6324
6325 (define_expand "vcondu<VI8F_128:mode>v2di"
6326   [(set (match_operand:VI8F_128 0 "register_operand" "")
6327         (if_then_else:VI8F_128
6328           (match_operator 3 ""
6329             [(match_operand:V2DI 4 "nonimmediate_operand" "")
6330              (match_operand:V2DI 5 "nonimmediate_operand" "")])
6331           (match_operand:VI8F_128 1 "general_operand" "")
6332           (match_operand:VI8F_128 2 "general_operand" "")))]
6333   "TARGET_SSE4_2"
6334 {
6335   bool ok = ix86_expand_int_vcond (operands);
6336   gcc_assert (ok);
6337   DONE;
6338 })
6339
6340 (define_mode_iterator VEC_PERM_AVX2
6341   [V16QI V8HI V4SI V2DI V4SF V2DF
6342    (V32QI "TARGET_AVX2") (V16HI "TARGET_AVX2")
6343    (V8SI "TARGET_AVX2") (V4DI "TARGET_AVX2")
6344    (V8SF "TARGET_AVX2") (V4DF "TARGET_AVX2")])
6345
6346 (define_expand "vec_perm<mode>"
6347   [(match_operand:VEC_PERM_AVX2 0 "register_operand" "")
6348    (match_operand:VEC_PERM_AVX2 1 "register_operand" "")
6349    (match_operand:VEC_PERM_AVX2 2 "register_operand" "")
6350    (match_operand:<sseintvecmode> 3 "register_operand" "")]
6351   "TARGET_SSSE3 || TARGET_AVX || TARGET_XOP"
6352 {
6353   ix86_expand_vec_perm (operands);
6354   DONE;
6355 })
6356
6357 (define_mode_iterator VEC_PERM_CONST
6358   [(V4SF "TARGET_SSE") (V4SI "TARGET_SSE")
6359    (V2DF "TARGET_SSE") (V2DI "TARGET_SSE")
6360    (V16QI "TARGET_SSE2") (V8HI "TARGET_SSE2")
6361    (V8SF "TARGET_AVX") (V4DF "TARGET_AVX")
6362    (V8SI "TARGET_AVX") (V4DI "TARGET_AVX")
6363    (V32QI "TARGET_AVX2") (V16HI "TARGET_AVX2")])
6364
6365 (define_expand "vec_perm_const<mode>"
6366   [(match_operand:VEC_PERM_CONST 0 "register_operand" "")
6367    (match_operand:VEC_PERM_CONST 1 "register_operand" "")
6368    (match_operand:VEC_PERM_CONST 2 "register_operand" "")
6369    (match_operand:<sseintvecmode> 3 "" "")]
6370   ""
6371 {
6372   if (ix86_expand_vec_perm_const (operands))
6373     DONE;
6374   else
6375     FAIL;
6376 })
6377
6378 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6379 ;;
6380 ;; Parallel bitwise logical operations
6381 ;;
6382 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6383
6384 (define_expand "one_cmpl<mode>2"
6385   [(set (match_operand:VI 0 "register_operand" "")
6386         (xor:VI (match_operand:VI 1 "nonimmediate_operand" "")
6387                 (match_dup 2)))]
6388   "TARGET_SSE"
6389 {
6390   int i, n = GET_MODE_NUNITS (<MODE>mode);
6391   rtvec v = rtvec_alloc (n);
6392
6393   for (i = 0; i < n; ++i)
6394     RTVEC_ELT (v, i) = constm1_rtx;
6395
6396   operands[2] = force_reg (<MODE>mode, gen_rtx_CONST_VECTOR (<MODE>mode, v));
6397 })
6398
6399 (define_expand "<sse2_avx2>_andnot<mode>3"
6400   [(set (match_operand:VI_AVX2 0 "register_operand" "")
6401         (and:VI_AVX2
6402           (not:VI_AVX2 (match_operand:VI_AVX2 1 "register_operand" ""))
6403           (match_operand:VI_AVX2 2 "nonimmediate_operand" "")))]
6404   "TARGET_SSE2")
6405
6406 (define_insn "*andnot<mode>3"
6407   [(set (match_operand:VI 0 "register_operand" "=x,x")
6408         (and:VI
6409           (not:VI (match_operand:VI 1 "register_operand" "0,x"))
6410           (match_operand:VI 2 "nonimmediate_operand" "xm,xm")))]
6411   "TARGET_SSE"
6412 {
6413   static char buf[32];
6414   const char *ops;
6415   const char *tmp;
6416
6417   switch (get_attr_mode (insn))
6418     {
6419     case MODE_OI:
6420       gcc_assert (TARGET_AVX2);
6421     case MODE_TI:
6422       gcc_assert (TARGET_SSE2);
6423
6424       tmp = "pandn";
6425       break;
6426
6427    case MODE_V8SF:
6428       gcc_assert (TARGET_AVX);
6429    case MODE_V4SF:
6430       gcc_assert (TARGET_SSE);
6431
6432       tmp = "andnps";
6433       break;
6434
6435    default:
6436       gcc_unreachable ();
6437    }
6438
6439   switch (which_alternative)
6440     {
6441     case 0:
6442       ops = "%s\t{%%2, %%0|%%0, %%2}";
6443       break;
6444     case 1:
6445       ops = "v%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
6446       break;
6447     default:
6448       gcc_unreachable ();
6449     }
6450
6451   snprintf (buf, sizeof (buf), ops, tmp);
6452   return buf;
6453 }
6454   [(set_attr "isa" "noavx,avx")
6455    (set_attr "type" "sselog")
6456    (set (attr "prefix_data16")
6457      (if_then_else
6458        (and (eq_attr "alternative" "0")
6459             (eq_attr "mode" "TI"))
6460        (const_string "1")
6461        (const_string "*")))
6462    (set_attr "prefix" "orig,vex")
6463    (set (attr "mode")
6464      (cond [(and (not (match_test "TARGET_AVX2"))
6465                  (match_test "GET_MODE_SIZE (<MODE>mode) > 16"))
6466               (const_string "V8SF")
6467             (not (match_test "TARGET_SSE2"))
6468               (const_string "V4SF")
6469            ]
6470            (const_string "<sseinsnmode>")))])
6471
6472 (define_expand "<code><mode>3"
6473   [(set (match_operand:VI 0 "register_operand" "")
6474         (any_logic:VI
6475           (match_operand:VI 1 "nonimmediate_operand" "")
6476           (match_operand:VI 2 "nonimmediate_operand" "")))]
6477   "TARGET_SSE"
6478   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
6479
6480 (define_insn "*<code><mode>3"
6481   [(set (match_operand:VI 0 "register_operand" "=x,x")
6482         (any_logic:VI
6483           (match_operand:VI 1 "nonimmediate_operand" "%0,x")
6484           (match_operand:VI 2 "nonimmediate_operand" "xm,xm")))]
6485   "TARGET_SSE
6486    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
6487 {
6488   static char buf[32];
6489   const char *ops;
6490   const char *tmp;
6491
6492   switch (get_attr_mode (insn))
6493     {
6494     case MODE_OI:
6495       gcc_assert (TARGET_AVX2);
6496     case MODE_TI:
6497       gcc_assert (TARGET_SSE2);
6498
6499       tmp = "p<logic>";
6500       break;
6501
6502    case MODE_V8SF:
6503       gcc_assert (TARGET_AVX);
6504    case MODE_V4SF:
6505       gcc_assert (TARGET_SSE);
6506
6507       tmp = "<logic>ps";
6508       break;
6509
6510    default:
6511       gcc_unreachable ();
6512    }
6513
6514   switch (which_alternative)
6515     {
6516     case 0:
6517       ops = "%s\t{%%2, %%0|%%0, %%2}";
6518       break;
6519     case 1:
6520       ops = "v%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
6521       break;
6522     default:
6523       gcc_unreachable ();
6524     }
6525
6526   snprintf (buf, sizeof (buf), ops, tmp);
6527   return buf;
6528 }
6529   [(set_attr "isa" "noavx,avx")
6530    (set_attr "type" "sselog")
6531    (set (attr "prefix_data16")
6532      (if_then_else
6533        (and (eq_attr "alternative" "0")
6534             (eq_attr "mode" "TI"))
6535        (const_string "1")
6536        (const_string "*")))
6537    (set_attr "prefix" "orig,vex")
6538    (set (attr "mode")
6539      (cond [(and (not (match_test "TARGET_AVX2"))
6540                  (match_test "GET_MODE_SIZE (<MODE>mode) > 16"))
6541               (const_string "V8SF")
6542             (not (match_test "TARGET_SSE2"))
6543               (const_string "V4SF")
6544            ]
6545            (const_string "<sseinsnmode>")))])
6546
6547 (define_insn "*andnottf3"
6548   [(set (match_operand:TF 0 "register_operand" "=x,x")
6549         (and:TF
6550           (not:TF (match_operand:TF 1 "register_operand" "0,x"))
6551           (match_operand:TF 2 "nonimmediate_operand" "xm,xm")))]
6552   "TARGET_SSE2"
6553   "@
6554    pandn\t{%2, %0|%0, %2}
6555    vpandn\t{%2, %1, %0|%0, %1, %2}"
6556   [(set_attr "isa" "noavx,avx")
6557    (set_attr "type" "sselog")
6558    (set_attr "prefix_data16" "1,*")
6559    (set_attr "prefix" "orig,vex")
6560    (set_attr "mode" "TI")])
6561
6562 (define_expand "<code>tf3"
6563   [(set (match_operand:TF 0 "register_operand" "")
6564         (any_logic:TF
6565           (match_operand:TF 1 "nonimmediate_operand" "")
6566           (match_operand:TF 2 "nonimmediate_operand" "")))]
6567   "TARGET_SSE2"
6568   "ix86_fixup_binary_operands_no_copy (<CODE>, TFmode, operands);")
6569
6570 (define_insn "*<code>tf3"
6571   [(set (match_operand:TF 0 "register_operand" "=x,x")
6572         (any_logic:TF
6573           (match_operand:TF 1 "nonimmediate_operand" "%0,x")
6574           (match_operand:TF 2 "nonimmediate_operand" "xm,xm")))]
6575   "TARGET_SSE2
6576    && ix86_binary_operator_ok (<CODE>, TFmode, operands)"
6577   "@
6578    p<logic>\t{%2, %0|%0, %2}
6579    vp<logic>\t{%2, %1, %0|%0, %1, %2}"
6580   [(set_attr "isa" "noavx,avx")
6581    (set_attr "type" "sselog")
6582    (set_attr "prefix_data16" "1,*")
6583    (set_attr "prefix" "orig,vex")
6584    (set_attr "mode" "TI")])
6585
6586 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6587 ;;
6588 ;; Parallel integral element swizzling
6589 ;;
6590 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6591
6592 (define_expand "vec_pack_trunc_<mode>"
6593   [(match_operand:<ssepackmode> 0 "register_operand" "")
6594    (match_operand:VI248_AVX2 1 "register_operand" "")
6595    (match_operand:VI248_AVX2 2 "register_operand" "")]
6596   "TARGET_SSE2"
6597 {
6598   rtx op1 = gen_lowpart (<ssepackmode>mode, operands[1]);
6599   rtx op2 = gen_lowpart (<ssepackmode>mode, operands[2]);
6600   ix86_expand_vec_extract_even_odd (operands[0], op1, op2, 0);
6601   DONE;
6602 })
6603
6604 (define_insn "<sse2_avx2>_packsswb"
6605   [(set (match_operand:VI1_AVX2 0 "register_operand" "=x,x")
6606         (vec_concat:VI1_AVX2
6607           (ss_truncate:<ssehalfvecmode>
6608             (match_operand:<sseunpackmode> 1 "register_operand" "0,x"))
6609           (ss_truncate:<ssehalfvecmode>
6610             (match_operand:<sseunpackmode> 2 "nonimmediate_operand" "xm,xm"))))]
6611   "TARGET_SSE2"
6612   "@
6613    packsswb\t{%2, %0|%0, %2}
6614    vpacksswb\t{%2, %1, %0|%0, %1, %2}"
6615   [(set_attr "isa" "noavx,avx")
6616    (set_attr "type" "sselog")
6617    (set_attr "prefix_data16" "1,*")
6618    (set_attr "prefix" "orig,vex")
6619    (set_attr "mode" "<sseinsnmode>")])
6620
6621 (define_insn "<sse2_avx2>_packssdw"
6622   [(set (match_operand:VI2_AVX2 0 "register_operand" "=x,x")
6623         (vec_concat:VI2_AVX2
6624           (ss_truncate:<ssehalfvecmode>
6625             (match_operand:<sseunpackmode> 1 "register_operand" "0,x"))
6626           (ss_truncate:<ssehalfvecmode>
6627             (match_operand:<sseunpackmode> 2 "nonimmediate_operand" "xm,xm"))))]
6628   "TARGET_SSE2"
6629   "@
6630    packssdw\t{%2, %0|%0, %2}
6631    vpackssdw\t{%2, %1, %0|%0, %1, %2}"
6632   [(set_attr "isa" "noavx,avx")
6633    (set_attr "type" "sselog")
6634    (set_attr "prefix_data16" "1,*")
6635    (set_attr "prefix" "orig,vex")
6636    (set_attr "mode" "<sseinsnmode>")])
6637
6638 (define_insn "<sse2_avx2>_packuswb"
6639   [(set (match_operand:VI1_AVX2 0 "register_operand" "=x,x")
6640         (vec_concat:VI1_AVX2
6641           (us_truncate:<ssehalfvecmode>
6642             (match_operand:<sseunpackmode> 1 "register_operand" "0,x"))
6643           (us_truncate:<ssehalfvecmode>
6644             (match_operand:<sseunpackmode> 2 "nonimmediate_operand" "xm,xm"))))]
6645   "TARGET_SSE2"
6646   "@
6647    packuswb\t{%2, %0|%0, %2}
6648    vpackuswb\t{%2, %1, %0|%0, %1, %2}"
6649   [(set_attr "isa" "noavx,avx")
6650    (set_attr "type" "sselog")
6651    (set_attr "prefix_data16" "1,*")
6652    (set_attr "prefix" "orig,vex")
6653    (set_attr "mode" "<sseinsnmode>")])
6654
6655 (define_insn "avx2_interleave_highv32qi"
6656   [(set (match_operand:V32QI 0 "register_operand" "=x")
6657         (vec_select:V32QI
6658           (vec_concat:V64QI
6659             (match_operand:V32QI 1 "register_operand" "x")
6660             (match_operand:V32QI 2 "nonimmediate_operand" "xm"))
6661           (parallel [(const_int 8)  (const_int 40)
6662                      (const_int 9)  (const_int 41)
6663                      (const_int 10) (const_int 42)
6664                      (const_int 11) (const_int 43)
6665                      (const_int 12) (const_int 44)
6666                      (const_int 13) (const_int 45)
6667                      (const_int 14) (const_int 46)
6668                      (const_int 15) (const_int 47)
6669                      (const_int 24) (const_int 56)
6670                      (const_int 25) (const_int 57)
6671                      (const_int 26) (const_int 58)
6672                      (const_int 27) (const_int 59)
6673                      (const_int 28) (const_int 60)
6674                      (const_int 29) (const_int 61)
6675                      (const_int 30) (const_int 62)
6676                      (const_int 31) (const_int 63)])))]
6677   "TARGET_AVX2"
6678   "vpunpckhbw\t{%2, %1, %0|%0, %1, %2}"
6679   [(set_attr "type" "sselog")
6680    (set_attr "prefix" "vex")
6681    (set_attr "mode" "OI")])
6682
6683 (define_insn "vec_interleave_highv16qi"
6684   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
6685         (vec_select:V16QI
6686           (vec_concat:V32QI
6687             (match_operand:V16QI 1 "register_operand" "0,x")
6688             (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm"))
6689           (parallel [(const_int 8)  (const_int 24)
6690                      (const_int 9)  (const_int 25)
6691                      (const_int 10) (const_int 26)
6692                      (const_int 11) (const_int 27)
6693                      (const_int 12) (const_int 28)
6694                      (const_int 13) (const_int 29)
6695                      (const_int 14) (const_int 30)
6696                      (const_int 15) (const_int 31)])))]
6697   "TARGET_SSE2"
6698   "@
6699    punpckhbw\t{%2, %0|%0, %2}
6700    vpunpckhbw\t{%2, %1, %0|%0, %1, %2}"
6701   [(set_attr "isa" "noavx,avx")
6702    (set_attr "type" "sselog")
6703    (set_attr "prefix_data16" "1,*")
6704    (set_attr "prefix" "orig,vex")
6705    (set_attr "mode" "TI")])
6706
6707 (define_insn "avx2_interleave_lowv32qi"
6708   [(set (match_operand:V32QI 0 "register_operand" "=x")
6709         (vec_select:V32QI
6710           (vec_concat:V64QI
6711             (match_operand:V32QI 1 "register_operand" "x")
6712             (match_operand:V32QI 2 "nonimmediate_operand" "xm"))
6713           (parallel [(const_int 0) (const_int 32)
6714                      (const_int 1) (const_int 33)
6715                      (const_int 2) (const_int 34)
6716                      (const_int 3) (const_int 35)
6717                      (const_int 4) (const_int 36)
6718                      (const_int 5) (const_int 37)
6719                      (const_int 6) (const_int 38)
6720                      (const_int 7) (const_int 39)
6721                      (const_int 16) (const_int 48)
6722                      (const_int 17) (const_int 49)
6723                      (const_int 18) (const_int 50)
6724                      (const_int 19) (const_int 51)
6725                      (const_int 20) (const_int 52)
6726                      (const_int 21) (const_int 53)
6727                      (const_int 22) (const_int 54)
6728                      (const_int 23) (const_int 55)])))]
6729   "TARGET_AVX2"
6730   "vpunpcklbw\t{%2, %1, %0|%0, %1, %2}"
6731   [(set_attr "type" "sselog")
6732    (set_attr "prefix" "vex")
6733    (set_attr "mode" "OI")])
6734
6735 (define_insn "vec_interleave_lowv16qi"
6736   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
6737         (vec_select:V16QI
6738           (vec_concat:V32QI
6739             (match_operand:V16QI 1 "register_operand" "0,x")
6740             (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm"))
6741           (parallel [(const_int 0) (const_int 16)
6742                      (const_int 1) (const_int 17)
6743                      (const_int 2) (const_int 18)
6744                      (const_int 3) (const_int 19)
6745                      (const_int 4) (const_int 20)
6746                      (const_int 5) (const_int 21)
6747                      (const_int 6) (const_int 22)
6748                      (const_int 7) (const_int 23)])))]
6749   "TARGET_SSE2"
6750   "@
6751    punpcklbw\t{%2, %0|%0, %2}
6752    vpunpcklbw\t{%2, %1, %0|%0, %1, %2}"
6753   [(set_attr "isa" "noavx,avx")
6754    (set_attr "type" "sselog")
6755    (set_attr "prefix_data16" "1,*")
6756    (set_attr "prefix" "orig,vex")
6757    (set_attr "mode" "TI")])
6758
6759 (define_insn "avx2_interleave_highv16hi"
6760   [(set (match_operand:V16HI 0 "register_operand" "=x")
6761         (vec_select:V16HI
6762           (vec_concat:V32HI
6763             (match_operand:V16HI 1 "register_operand" "x")
6764             (match_operand:V16HI 2 "nonimmediate_operand" "xm"))
6765           (parallel [(const_int 4) (const_int 20)
6766                      (const_int 5) (const_int 21)
6767                      (const_int 6) (const_int 22)
6768                      (const_int 7) (const_int 23)
6769                      (const_int 12) (const_int 28)
6770                      (const_int 13) (const_int 29)
6771                      (const_int 14) (const_int 30)
6772                      (const_int 15) (const_int 31)])))]
6773   "TARGET_AVX2"
6774   "vpunpckhwd\t{%2, %1, %0|%0, %1, %2}"
6775   [(set_attr "type" "sselog")
6776    (set_attr "prefix" "vex")
6777    (set_attr "mode" "OI")])
6778
6779 (define_insn "vec_interleave_highv8hi"
6780   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
6781         (vec_select:V8HI
6782           (vec_concat:V16HI
6783             (match_operand:V8HI 1 "register_operand" "0,x")
6784             (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm"))
6785           (parallel [(const_int 4) (const_int 12)
6786                      (const_int 5) (const_int 13)
6787                      (const_int 6) (const_int 14)
6788                      (const_int 7) (const_int 15)])))]
6789   "TARGET_SSE2"
6790   "@
6791    punpckhwd\t{%2, %0|%0, %2}
6792    vpunpckhwd\t{%2, %1, %0|%0, %1, %2}"
6793   [(set_attr "isa" "noavx,avx")
6794    (set_attr "type" "sselog")
6795    (set_attr "prefix_data16" "1,*")
6796    (set_attr "prefix" "orig,vex")
6797    (set_attr "mode" "TI")])
6798
6799 (define_insn "avx2_interleave_lowv16hi"
6800   [(set (match_operand:V16HI 0 "register_operand" "=x")
6801         (vec_select:V16HI
6802           (vec_concat:V32HI
6803             (match_operand:V16HI 1 "register_operand" "x")
6804             (match_operand:V16HI 2 "nonimmediate_operand" "xm"))
6805           (parallel [(const_int 0) (const_int 16)
6806                      (const_int 1) (const_int 17)
6807                      (const_int 2) (const_int 18)
6808                      (const_int 3) (const_int 19)
6809                      (const_int 8) (const_int 24)
6810                      (const_int 9) (const_int 25)
6811                      (const_int 10) (const_int 26)
6812                      (const_int 11) (const_int 27)])))]
6813   "TARGET_AVX2"
6814   "vpunpcklwd\t{%2, %1, %0|%0, %1, %2}"
6815   [(set_attr "type" "sselog")
6816    (set_attr "prefix" "vex")
6817    (set_attr "mode" "OI")])
6818
6819 (define_insn "vec_interleave_lowv8hi"
6820   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
6821         (vec_select:V8HI
6822           (vec_concat:V16HI
6823             (match_operand:V8HI 1 "register_operand" "0,x")
6824             (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm"))
6825           (parallel [(const_int 0) (const_int 8)
6826                      (const_int 1) (const_int 9)
6827                      (const_int 2) (const_int 10)
6828                      (const_int 3) (const_int 11)])))]
6829   "TARGET_SSE2"
6830   "@
6831    punpcklwd\t{%2, %0|%0, %2}
6832    vpunpcklwd\t{%2, %1, %0|%0, %1, %2}"
6833   [(set_attr "isa" "noavx,avx")
6834    (set_attr "type" "sselog")
6835    (set_attr "prefix_data16" "1,*")
6836    (set_attr "prefix" "orig,vex")
6837    (set_attr "mode" "TI")])
6838
6839 (define_insn "avx2_interleave_highv8si"
6840   [(set (match_operand:V8SI 0 "register_operand" "=x")
6841         (vec_select:V8SI
6842           (vec_concat:V16SI
6843             (match_operand:V8SI 1 "register_operand" "x")
6844             (match_operand:V8SI 2 "nonimmediate_operand" "xm"))
6845           (parallel [(const_int 2) (const_int 10)
6846                      (const_int 3) (const_int 11)
6847                      (const_int 6) (const_int 14)
6848                      (const_int 7) (const_int 15)])))]
6849   "TARGET_AVX2"
6850   "vpunpckhdq\t{%2, %1, %0|%0, %1, %2}"
6851   [(set_attr "type" "sselog")
6852    (set_attr "prefix" "vex")
6853    (set_attr "mode" "OI")])
6854
6855 (define_insn "vec_interleave_highv4si"
6856   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
6857         (vec_select:V4SI
6858           (vec_concat:V8SI
6859             (match_operand:V4SI 1 "register_operand" "0,x")
6860             (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm"))
6861           (parallel [(const_int 2) (const_int 6)
6862                      (const_int 3) (const_int 7)])))]
6863   "TARGET_SSE2"
6864   "@
6865    punpckhdq\t{%2, %0|%0, %2}
6866    vpunpckhdq\t{%2, %1, %0|%0, %1, %2}"
6867   [(set_attr "isa" "noavx,avx")
6868    (set_attr "type" "sselog")
6869    (set_attr "prefix_data16" "1,*")
6870    (set_attr "prefix" "orig,vex")
6871    (set_attr "mode" "TI")])
6872
6873 (define_insn "avx2_interleave_lowv8si"
6874   [(set (match_operand:V8SI 0 "register_operand" "=x")
6875         (vec_select:V8SI
6876           (vec_concat:V16SI
6877             (match_operand:V8SI 1 "register_operand" "x")
6878             (match_operand:V8SI 2 "nonimmediate_operand" "xm"))
6879           (parallel [(const_int 0) (const_int 8)
6880                      (const_int 1) (const_int 9)
6881                      (const_int 4) (const_int 12)
6882                      (const_int 5) (const_int 13)])))]
6883   "TARGET_AVX2"
6884   "vpunpckldq\t{%2, %1, %0|%0, %1, %2}"
6885   [(set_attr "type" "sselog")
6886    (set_attr "prefix" "vex")
6887    (set_attr "mode" "OI")])
6888
6889 (define_insn "vec_interleave_lowv4si"
6890   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
6891         (vec_select:V4SI
6892           (vec_concat:V8SI
6893             (match_operand:V4SI 1 "register_operand" "0,x")
6894             (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm"))
6895           (parallel [(const_int 0) (const_int 4)
6896                      (const_int 1) (const_int 5)])))]
6897   "TARGET_SSE2"
6898   "@
6899    punpckldq\t{%2, %0|%0, %2}
6900    vpunpckldq\t{%2, %1, %0|%0, %1, %2}"
6901   [(set_attr "isa" "noavx,avx")
6902    (set_attr "type" "sselog")
6903    (set_attr "prefix_data16" "1,*")
6904    (set_attr "prefix" "orig,vex")
6905    (set_attr "mode" "TI")])
6906
6907 (define_expand "vec_interleave_high<mode>"
6908   [(match_operand:VI_256 0 "register_operand" "=x")
6909    (match_operand:VI_256 1 "register_operand" "x")
6910    (match_operand:VI_256 2 "nonimmediate_operand" "xm")]
6911  "TARGET_AVX2"
6912 {
6913   rtx t1 = gen_reg_rtx (<MODE>mode);
6914   rtx t2 = gen_reg_rtx (<MODE>mode);
6915   emit_insn (gen_avx2_interleave_low<mode> (t1, operands[1], operands[2]));
6916   emit_insn (gen_avx2_interleave_high<mode> (t2,  operands[1], operands[2]));
6917   emit_insn (gen_avx2_permv2ti (gen_lowpart (V4DImode, operands[0]),
6918                                 gen_lowpart (V4DImode, t1),
6919                                 gen_lowpart (V4DImode, t2), GEN_INT (1 + (3 << 4))));
6920   DONE;
6921 })
6922
6923 (define_expand "vec_interleave_low<mode>"
6924   [(match_operand:VI_256 0 "register_operand" "=x")
6925    (match_operand:VI_256 1 "register_operand" "x")
6926    (match_operand:VI_256 2 "nonimmediate_operand" "xm")]
6927  "TARGET_AVX2"
6928 {
6929   rtx t1 = gen_reg_rtx (<MODE>mode);
6930   rtx t2 = gen_reg_rtx (<MODE>mode);
6931   emit_insn (gen_avx2_interleave_low<mode> (t1, operands[1], operands[2]));
6932   emit_insn (gen_avx2_interleave_high<mode> (t2, operands[1], operands[2]));
6933   emit_insn (gen_avx2_permv2ti (gen_lowpart (V4DImode, operands[0]),
6934                                 gen_lowpart (V4DImode, t1),
6935                                 gen_lowpart (V4DImode, t2), GEN_INT (0 + (2 << 4))));
6936   DONE;
6937 })
6938
6939 ;; Modes handled by pinsr patterns.
6940 (define_mode_iterator PINSR_MODE
6941   [(V16QI "TARGET_SSE4_1") V8HI
6942    (V4SI "TARGET_SSE4_1")
6943    (V2DI "TARGET_SSE4_1 && TARGET_64BIT")])
6944
6945 (define_mode_attr sse2p4_1
6946   [(V16QI "sse4_1") (V8HI "sse2")
6947    (V4SI "sse4_1") (V2DI "sse4_1")])
6948
6949 ;; sse4_1_pinsrd must come before sse2_loadld since it is preferred.
6950 (define_insn "<sse2p4_1>_pinsr<ssemodesuffix>"
6951   [(set (match_operand:PINSR_MODE 0 "register_operand" "=x,x,x,x")
6952         (vec_merge:PINSR_MODE
6953           (vec_duplicate:PINSR_MODE
6954             (match_operand:<ssescalarmode> 2 "nonimmediate_operand" "r,m,r,m"))
6955           (match_operand:PINSR_MODE 1 "register_operand" "0,0,x,x")
6956           (match_operand:SI 3 "const_int_operand" "")))]
6957   "TARGET_SSE2
6958    && ((unsigned) exact_log2 (INTVAL (operands[3]))
6959        < GET_MODE_NUNITS (<MODE>mode))"
6960 {
6961   operands[3] = GEN_INT (exact_log2 (INTVAL (operands[3])));
6962
6963   switch (which_alternative)
6964     {
6965     case 0:
6966       if (GET_MODE_SIZE (<ssescalarmode>mode) < GET_MODE_SIZE (SImode))
6967         return "pinsr<ssemodesuffix>\t{%3, %k2, %0|%0, %k2, %3}";
6968       /* FALLTHRU */
6969     case 1:
6970       return "pinsr<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}";
6971     case 2:
6972       if (GET_MODE_SIZE (<ssescalarmode>mode) < GET_MODE_SIZE (SImode))
6973         return "vpinsr<ssemodesuffix>\t{%3, %k2, %1, %0|%0, %1, %k2, %3}";
6974       /* FALLTHRU */
6975     case 3:
6976       return "vpinsr<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}";
6977     default:
6978       gcc_unreachable ();
6979     }
6980 }
6981   [(set_attr "isa" "noavx,noavx,avx,avx")
6982    (set_attr "type" "sselog")
6983    (set (attr "prefix_rex")
6984      (if_then_else
6985        (and (not (match_test "TARGET_AVX"))
6986             (eq (const_string "<MODE>mode") (const_string "V2DImode")))
6987        (const_string "1")
6988        (const_string "*")))
6989    (set (attr "prefix_data16")
6990      (if_then_else
6991        (and (not (match_test "TARGET_AVX"))
6992             (eq (const_string "<MODE>mode") (const_string "V8HImode")))
6993        (const_string "1")
6994        (const_string "*")))
6995    (set (attr "prefix_extra")
6996      (if_then_else
6997        (and (not (match_test "TARGET_AVX"))
6998             (eq (const_string "<MODE>mode") (const_string "V8HImode")))
6999        (const_string "*")
7000        (const_string "1")))
7001    (set_attr "length_immediate" "1")
7002    (set_attr "prefix" "orig,orig,vex,vex")
7003    (set_attr "mode" "TI")])
7004
7005 (define_insn "*sse4_1_pextrb_<mode>"
7006   [(set (match_operand:SWI48 0 "register_operand" "=r")
7007         (zero_extend:SWI48
7008           (vec_select:QI
7009             (match_operand:V16QI 1 "register_operand" "x")
7010             (parallel [(match_operand:SI 2 "const_0_to_15_operand" "n")]))))]
7011   "TARGET_SSE4_1"
7012   "%vpextrb\t{%2, %1, %k0|%k0, %1, %2}"
7013   [(set_attr "type" "sselog")
7014    (set_attr "prefix_extra" "1")
7015    (set_attr "length_immediate" "1")
7016    (set_attr "prefix" "maybe_vex")
7017    (set_attr "mode" "TI")])
7018
7019 (define_insn "*sse4_1_pextrb_memory"
7020   [(set (match_operand:QI 0 "memory_operand" "=m")
7021         (vec_select:QI
7022           (match_operand:V16QI 1 "register_operand" "x")
7023           (parallel [(match_operand:SI 2 "const_0_to_15_operand" "n")])))]
7024   "TARGET_SSE4_1"
7025   "%vpextrb\t{%2, %1, %0|%0, %1, %2}"
7026   [(set_attr "type" "sselog")
7027    (set_attr "prefix_extra" "1")
7028    (set_attr "length_immediate" "1")
7029    (set_attr "prefix" "maybe_vex")
7030    (set_attr "mode" "TI")])
7031
7032 (define_insn "*sse2_pextrw_<mode>"
7033   [(set (match_operand:SWI48 0 "register_operand" "=r")
7034         (zero_extend:SWI48
7035           (vec_select:HI
7036             (match_operand:V8HI 1 "register_operand" "x")
7037             (parallel [(match_operand:SI 2 "const_0_to_7_operand" "n")]))))]
7038   "TARGET_SSE2"
7039   "%vpextrw\t{%2, %1, %k0|%k0, %1, %2}"
7040   [(set_attr "type" "sselog")
7041    (set_attr "prefix_data16" "1")
7042    (set_attr "length_immediate" "1")
7043    (set_attr "prefix" "maybe_vex")
7044    (set_attr "mode" "TI")])
7045
7046 (define_insn "*sse4_1_pextrw_memory"
7047   [(set (match_operand:HI 0 "memory_operand" "=m")
7048         (vec_select:HI
7049           (match_operand:V8HI 1 "register_operand" "x")
7050           (parallel [(match_operand:SI 2 "const_0_to_7_operand" "n")])))]
7051   "TARGET_SSE4_1"
7052   "%vpextrw\t{%2, %1, %0|%0, %1, %2}"
7053   [(set_attr "type" "sselog")
7054    (set_attr "prefix_extra" "1")
7055    (set_attr "length_immediate" "1")
7056    (set_attr "prefix" "maybe_vex")
7057    (set_attr "mode" "TI")])
7058
7059 (define_insn "*sse4_1_pextrd"
7060   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
7061         (vec_select:SI
7062           (match_operand:V4SI 1 "register_operand" "x")
7063           (parallel [(match_operand:SI 2 "const_0_to_3_operand" "n")])))]
7064   "TARGET_SSE4_1"
7065   "%vpextrd\t{%2, %1, %0|%0, %1, %2}"
7066   [(set_attr "type" "sselog")
7067    (set_attr "prefix_extra" "1")
7068    (set_attr "length_immediate" "1")
7069    (set_attr "prefix" "maybe_vex")
7070    (set_attr "mode" "TI")])
7071
7072 (define_insn "*sse4_1_pextrd_zext"
7073   [(set (match_operand:DI 0 "register_operand" "=r")
7074         (zero_extend:DI
7075           (vec_select:SI
7076             (match_operand:V4SI 1 "register_operand" "x")
7077             (parallel [(match_operand:SI 2 "const_0_to_3_operand" "n")]))))]
7078   "TARGET_64BIT && TARGET_SSE4_1"
7079   "%vpextrd\t{%2, %1, %k0|%k0, %1, %2}"
7080   [(set_attr "type" "sselog")
7081    (set_attr "prefix_extra" "1")
7082    (set_attr "length_immediate" "1")
7083    (set_attr "prefix" "maybe_vex")
7084    (set_attr "mode" "TI")])
7085
7086 ;; It must come before *vec_extractv2di_1_rex64 since it is preferred.
7087 (define_insn "*sse4_1_pextrq"
7088   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
7089         (vec_select:DI
7090           (match_operand:V2DI 1 "register_operand" "x")
7091           (parallel [(match_operand:SI 2 "const_0_to_1_operand" "n")])))]
7092   "TARGET_SSE4_1 && TARGET_64BIT"
7093   "%vpextrq\t{%2, %1, %0|%0, %1, %2}"
7094   [(set_attr "type" "sselog")
7095    (set_attr "prefix_rex" "1")
7096    (set_attr "prefix_extra" "1")
7097    (set_attr "length_immediate" "1")
7098    (set_attr "prefix" "maybe_vex")
7099    (set_attr "mode" "TI")])
7100
7101 (define_expand "avx2_pshufdv3"
7102   [(match_operand:V8SI 0 "register_operand" "")
7103    (match_operand:V8SI 1 "nonimmediate_operand" "")
7104    (match_operand:SI 2 "const_0_to_255_operand" "")]
7105   "TARGET_AVX2"
7106 {
7107   int mask = INTVAL (operands[2]);
7108   emit_insn (gen_avx2_pshufd_1 (operands[0], operands[1],
7109                                 GEN_INT ((mask >> 0) & 3),
7110                                 GEN_INT ((mask >> 2) & 3),
7111                                 GEN_INT ((mask >> 4) & 3),
7112                                 GEN_INT ((mask >> 6) & 3),
7113                                 GEN_INT (((mask >> 0) & 3) + 4),
7114                                 GEN_INT (((mask >> 2) & 3) + 4),
7115                                 GEN_INT (((mask >> 4) & 3) + 4),
7116                                 GEN_INT (((mask >> 6) & 3) + 4)));
7117   DONE;
7118 })
7119
7120 (define_insn "avx2_pshufd_1"
7121   [(set (match_operand:V8SI 0 "register_operand" "=x")
7122         (vec_select:V8SI
7123           (match_operand:V8SI 1 "nonimmediate_operand" "xm")
7124           (parallel [(match_operand 2 "const_0_to_3_operand" "")
7125                      (match_operand 3 "const_0_to_3_operand" "")
7126                      (match_operand 4 "const_0_to_3_operand" "")
7127                      (match_operand 5 "const_0_to_3_operand" "")
7128                      (match_operand 6 "const_4_to_7_operand" "")
7129                      (match_operand 7 "const_4_to_7_operand" "")
7130                      (match_operand 8 "const_4_to_7_operand" "")
7131                      (match_operand 9 "const_4_to_7_operand" "")])))]
7132   "TARGET_AVX2
7133    && INTVAL (operands[2]) + 4 == INTVAL (operands[6])
7134    && INTVAL (operands[3]) + 4 == INTVAL (operands[7])
7135    && INTVAL (operands[4]) + 4 == INTVAL (operands[8])
7136    && INTVAL (operands[5]) + 4 == INTVAL (operands[9])"
7137 {
7138   int mask = 0;
7139   mask |= INTVAL (operands[2]) << 0;
7140   mask |= INTVAL (operands[3]) << 2;
7141   mask |= INTVAL (operands[4]) << 4;
7142   mask |= INTVAL (operands[5]) << 6;
7143   operands[2] = GEN_INT (mask);
7144
7145   return "vpshufd\t{%2, %1, %0|%0, %1, %2}";
7146 }
7147   [(set_attr "type" "sselog1")
7148    (set_attr "prefix" "vex")
7149    (set_attr "length_immediate" "1")
7150    (set_attr "mode" "OI")])
7151
7152 (define_expand "sse2_pshufd"
7153   [(match_operand:V4SI 0 "register_operand" "")
7154    (match_operand:V4SI 1 "nonimmediate_operand" "")
7155    (match_operand:SI 2 "const_int_operand" "")]
7156   "TARGET_SSE2"
7157 {
7158   int mask = INTVAL (operands[2]);
7159   emit_insn (gen_sse2_pshufd_1 (operands[0], operands[1],
7160                                 GEN_INT ((mask >> 0) & 3),
7161                                 GEN_INT ((mask >> 2) & 3),
7162                                 GEN_INT ((mask >> 4) & 3),
7163                                 GEN_INT ((mask >> 6) & 3)));
7164   DONE;
7165 })
7166
7167 (define_insn "sse2_pshufd_1"
7168   [(set (match_operand:V4SI 0 "register_operand" "=x")
7169         (vec_select:V4SI
7170           (match_operand:V4SI 1 "nonimmediate_operand" "xm")
7171           (parallel [(match_operand 2 "const_0_to_3_operand" "")
7172                      (match_operand 3 "const_0_to_3_operand" "")
7173                      (match_operand 4 "const_0_to_3_operand" "")
7174                      (match_operand 5 "const_0_to_3_operand" "")])))]
7175   "TARGET_SSE2"
7176 {
7177   int mask = 0;
7178   mask |= INTVAL (operands[2]) << 0;
7179   mask |= INTVAL (operands[3]) << 2;
7180   mask |= INTVAL (operands[4]) << 4;
7181   mask |= INTVAL (operands[5]) << 6;
7182   operands[2] = GEN_INT (mask);
7183
7184   return "%vpshufd\t{%2, %1, %0|%0, %1, %2}";
7185 }
7186   [(set_attr "type" "sselog1")
7187    (set_attr "prefix_data16" "1")
7188    (set_attr "prefix" "maybe_vex")
7189    (set_attr "length_immediate" "1")
7190    (set_attr "mode" "TI")])
7191
7192 (define_expand "avx2_pshuflwv3"
7193   [(match_operand:V16HI 0 "register_operand" "")
7194    (match_operand:V16HI 1 "nonimmediate_operand" "")
7195    (match_operand:SI 2 "const_0_to_255_operand" "")]
7196   "TARGET_AVX2"
7197 {
7198   int mask = INTVAL (operands[2]);
7199   emit_insn (gen_avx2_pshuflw_1 (operands[0], operands[1],
7200                                  GEN_INT ((mask >> 0) & 3),
7201                                  GEN_INT ((mask >> 2) & 3),
7202                                  GEN_INT ((mask >> 4) & 3),
7203                                  GEN_INT ((mask >> 6) & 3),
7204                                  GEN_INT (((mask >> 0) & 3) + 8),
7205                                  GEN_INT (((mask >> 2) & 3) + 8),
7206                                  GEN_INT (((mask >> 4) & 3) + 8),
7207                                  GEN_INT (((mask >> 6) & 3) + 8)));
7208   DONE;
7209 })
7210
7211 (define_insn "avx2_pshuflw_1"
7212   [(set (match_operand:V16HI 0 "register_operand" "=x")
7213         (vec_select:V16HI
7214           (match_operand:V16HI 1 "nonimmediate_operand" "xm")
7215           (parallel [(match_operand 2 "const_0_to_3_operand" "")
7216                      (match_operand 3 "const_0_to_3_operand" "")
7217                      (match_operand 4 "const_0_to_3_operand" "")
7218                      (match_operand 5 "const_0_to_3_operand" "")
7219                      (const_int 4)
7220                      (const_int 5)
7221                      (const_int 6)
7222                      (const_int 7)
7223                      (match_operand 6 "const_8_to_11_operand" "")
7224                      (match_operand 7 "const_8_to_11_operand" "")
7225                      (match_operand 8 "const_8_to_11_operand" "")
7226                      (match_operand 9 "const_8_to_11_operand" "")
7227                      (const_int 12)
7228                      (const_int 13)
7229                      (const_int 14)
7230                      (const_int 15)])))]
7231   "TARGET_AVX2
7232    && INTVAL (operands[2]) + 8 == INTVAL (operands[6])
7233    && INTVAL (operands[3]) + 8 == INTVAL (operands[7])
7234    && INTVAL (operands[4]) + 8 == INTVAL (operands[8])
7235    && INTVAL (operands[5]) + 8 == INTVAL (operands[9])"
7236 {
7237   int mask = 0;
7238   mask |= INTVAL (operands[2]) << 0;
7239   mask |= INTVAL (operands[3]) << 2;
7240   mask |= INTVAL (operands[4]) << 4;
7241   mask |= INTVAL (operands[5]) << 6;
7242   operands[2] = GEN_INT (mask);
7243
7244   return "vpshuflw\t{%2, %1, %0|%0, %1, %2}";
7245 }
7246   [(set_attr "type" "sselog")
7247    (set_attr "prefix" "vex")
7248    (set_attr "length_immediate" "1")
7249    (set_attr "mode" "OI")])
7250
7251 (define_expand "sse2_pshuflw"
7252   [(match_operand:V8HI 0 "register_operand" "")
7253    (match_operand:V8HI 1 "nonimmediate_operand" "")
7254    (match_operand:SI 2 "const_int_operand" "")]
7255   "TARGET_SSE2"
7256 {
7257   int mask = INTVAL (operands[2]);
7258   emit_insn (gen_sse2_pshuflw_1 (operands[0], operands[1],
7259                                  GEN_INT ((mask >> 0) & 3),
7260                                  GEN_INT ((mask >> 2) & 3),
7261                                  GEN_INT ((mask >> 4) & 3),
7262                                  GEN_INT ((mask >> 6) & 3)));
7263   DONE;
7264 })
7265
7266 (define_insn "sse2_pshuflw_1"
7267   [(set (match_operand:V8HI 0 "register_operand" "=x")
7268         (vec_select:V8HI
7269           (match_operand:V8HI 1 "nonimmediate_operand" "xm")
7270           (parallel [(match_operand 2 "const_0_to_3_operand" "")
7271                      (match_operand 3 "const_0_to_3_operand" "")
7272                      (match_operand 4 "const_0_to_3_operand" "")
7273                      (match_operand 5 "const_0_to_3_operand" "")
7274                      (const_int 4)
7275                      (const_int 5)
7276                      (const_int 6)
7277                      (const_int 7)])))]
7278   "TARGET_SSE2"
7279 {
7280   int mask = 0;
7281   mask |= INTVAL (operands[2]) << 0;
7282   mask |= INTVAL (operands[3]) << 2;
7283   mask |= INTVAL (operands[4]) << 4;
7284   mask |= INTVAL (operands[5]) << 6;
7285   operands[2] = GEN_INT (mask);
7286
7287   return "%vpshuflw\t{%2, %1, %0|%0, %1, %2}";
7288 }
7289   [(set_attr "type" "sselog")
7290    (set_attr "prefix_data16" "0")
7291    (set_attr "prefix_rep" "1")
7292    (set_attr "prefix" "maybe_vex")
7293    (set_attr "length_immediate" "1")
7294    (set_attr "mode" "TI")])
7295
7296 (define_expand "avx2_pshufhwv3"
7297   [(match_operand:V16HI 0 "register_operand" "")
7298    (match_operand:V16HI 1 "nonimmediate_operand" "")
7299    (match_operand:SI 2 "const_0_to_255_operand" "")]
7300   "TARGET_AVX2"
7301 {
7302   int mask = INTVAL (operands[2]);
7303   emit_insn (gen_avx2_pshufhw_1 (operands[0], operands[1],
7304                                  GEN_INT (((mask >> 0) & 3) + 4),
7305                                  GEN_INT (((mask >> 2) & 3) + 4),
7306                                  GEN_INT (((mask >> 4) & 3) + 4),
7307                                  GEN_INT (((mask >> 6) & 3) + 4),
7308                                  GEN_INT (((mask >> 0) & 3) + 12),
7309                                  GEN_INT (((mask >> 2) & 3) + 12),
7310                                  GEN_INT (((mask >> 4) & 3) + 12),
7311                                  GEN_INT (((mask >> 6) & 3) + 12)));
7312   DONE;
7313 })
7314
7315 (define_insn "avx2_pshufhw_1"
7316   [(set (match_operand:V16HI 0 "register_operand" "=x")
7317         (vec_select:V16HI
7318           (match_operand:V16HI 1 "nonimmediate_operand" "xm")
7319           (parallel [(const_int 0)
7320                      (const_int 1)
7321                      (const_int 2)
7322                      (const_int 3)
7323                      (match_operand 2 "const_4_to_7_operand" "")
7324                      (match_operand 3 "const_4_to_7_operand" "")
7325                      (match_operand 4 "const_4_to_7_operand" "")
7326                      (match_operand 5 "const_4_to_7_operand" "")
7327                      (const_int 8)
7328                      (const_int 9)
7329                      (const_int 10)
7330                      (const_int 11)
7331                      (match_operand 6 "const_12_to_15_operand" "")
7332                      (match_operand 7 "const_12_to_15_operand" "")
7333                      (match_operand 8 "const_12_to_15_operand" "")
7334                      (match_operand 9 "const_12_to_15_operand" "")])))]
7335   "TARGET_AVX2
7336    && INTVAL (operands[2]) + 8 == INTVAL (operands[6])
7337    && INTVAL (operands[3]) + 8 == INTVAL (operands[7])
7338    && INTVAL (operands[4]) + 8 == INTVAL (operands[8])
7339    && INTVAL (operands[5]) + 8 == INTVAL (operands[9])"
7340 {
7341   int mask = 0;
7342   mask |= (INTVAL (operands[2]) - 4) << 0;
7343   mask |= (INTVAL (operands[3]) - 4) << 2;
7344   mask |= (INTVAL (operands[4]) - 4) << 4;
7345   mask |= (INTVAL (operands[5]) - 4) << 6;
7346   operands[2] = GEN_INT (mask);
7347
7348   return "vpshufhw\t{%2, %1, %0|%0, %1, %2}";
7349 }
7350   [(set_attr "type" "sselog")
7351    (set_attr "prefix" "vex")
7352    (set_attr "length_immediate" "1")
7353    (set_attr "mode" "OI")])
7354
7355 (define_expand "sse2_pshufhw"
7356   [(match_operand:V8HI 0 "register_operand" "")
7357    (match_operand:V8HI 1 "nonimmediate_operand" "")
7358    (match_operand:SI 2 "const_int_operand" "")]
7359   "TARGET_SSE2"
7360 {
7361   int mask = INTVAL (operands[2]);
7362   emit_insn (gen_sse2_pshufhw_1 (operands[0], operands[1],
7363                                  GEN_INT (((mask >> 0) & 3) + 4),
7364                                  GEN_INT (((mask >> 2) & 3) + 4),
7365                                  GEN_INT (((mask >> 4) & 3) + 4),
7366                                  GEN_INT (((mask >> 6) & 3) + 4)));
7367   DONE;
7368 })
7369
7370 (define_insn "sse2_pshufhw_1"
7371   [(set (match_operand:V8HI 0 "register_operand" "=x")
7372         (vec_select:V8HI
7373           (match_operand:V8HI 1 "nonimmediate_operand" "xm")
7374           (parallel [(const_int 0)
7375                      (const_int 1)
7376                      (const_int 2)
7377                      (const_int 3)
7378                      (match_operand 2 "const_4_to_7_operand" "")
7379                      (match_operand 3 "const_4_to_7_operand" "")
7380                      (match_operand 4 "const_4_to_7_operand" "")
7381                      (match_operand 5 "const_4_to_7_operand" "")])))]
7382   "TARGET_SSE2"
7383 {
7384   int mask = 0;
7385   mask |= (INTVAL (operands[2]) - 4) << 0;
7386   mask |= (INTVAL (operands[3]) - 4) << 2;
7387   mask |= (INTVAL (operands[4]) - 4) << 4;
7388   mask |= (INTVAL (operands[5]) - 4) << 6;
7389   operands[2] = GEN_INT (mask);
7390
7391   return "%vpshufhw\t{%2, %1, %0|%0, %1, %2}";
7392 }
7393   [(set_attr "type" "sselog")
7394    (set_attr "prefix_rep" "1")
7395    (set_attr "prefix_data16" "0")
7396    (set_attr "prefix" "maybe_vex")
7397    (set_attr "length_immediate" "1")
7398    (set_attr "mode" "TI")])
7399
7400 (define_expand "sse2_loadd"
7401   [(set (match_operand:V4SI 0 "register_operand" "")
7402         (vec_merge:V4SI
7403           (vec_duplicate:V4SI
7404             (match_operand:SI 1 "nonimmediate_operand" ""))
7405           (match_dup 2)
7406           (const_int 1)))]
7407   "TARGET_SSE"
7408   "operands[2] = CONST0_RTX (V4SImode);")
7409
7410 (define_insn "sse2_loadld"
7411   [(set (match_operand:V4SI 0 "register_operand"       "=x,Yi,x,x,x")
7412         (vec_merge:V4SI
7413           (vec_duplicate:V4SI
7414             (match_operand:SI 2 "nonimmediate_operand" "m ,r ,m,x,x"))
7415           (match_operand:V4SI 1 "reg_or_0_operand"     "C ,C ,C,0,x")
7416           (const_int 1)))]
7417   "TARGET_SSE"
7418   "@
7419    %vmovd\t{%2, %0|%0, %2}
7420    %vmovd\t{%2, %0|%0, %2}
7421    movss\t{%2, %0|%0, %2}
7422    movss\t{%2, %0|%0, %2}
7423    vmovss\t{%2, %1, %0|%0, %1, %2}"
7424   [(set_attr "isa" "sse2,*,noavx,noavx,avx")
7425    (set_attr "type" "ssemov")
7426    (set_attr "prefix" "maybe_vex,maybe_vex,orig,orig,vex")
7427    (set_attr "mode" "TI,TI,V4SF,SF,SF")])
7428
7429 (define_insn_and_split "sse2_stored"
7430   [(set (match_operand:SI 0 "nonimmediate_operand" "=xm,r")
7431         (vec_select:SI
7432           (match_operand:V4SI 1 "register_operand" "x,Yi")
7433           (parallel [(const_int 0)])))]
7434   "TARGET_SSE"
7435   "#"
7436   "&& reload_completed
7437    && (TARGET_INTER_UNIT_MOVES
7438        || MEM_P (operands [0])
7439        || !GENERAL_REGNO_P (true_regnum (operands [0])))"
7440   [(set (match_dup 0) (match_dup 1))]
7441   "operands[1] = gen_rtx_REG (SImode, REGNO (operands[1]));")
7442
7443 (define_insn_and_split "*vec_ext_v4si_mem"
7444   [(set (match_operand:SI 0 "register_operand" "=r")
7445         (vec_select:SI
7446           (match_operand:V4SI 1 "memory_operand" "o")
7447           (parallel [(match_operand 2 "const_0_to_3_operand" "")])))]
7448   ""
7449   "#"
7450   "reload_completed"
7451   [(const_int 0)]
7452 {
7453   int i = INTVAL (operands[2]);
7454
7455   emit_move_insn (operands[0], adjust_address (operands[1], SImode, i*4));
7456   DONE;
7457 })
7458
7459 (define_expand "sse_storeq"
7460   [(set (match_operand:DI 0 "nonimmediate_operand" "")
7461         (vec_select:DI
7462           (match_operand:V2DI 1 "register_operand" "")
7463           (parallel [(const_int 0)])))]
7464   "TARGET_SSE")
7465
7466 (define_insn "*sse2_storeq_rex64"
7467   [(set (match_operand:DI 0 "nonimmediate_operand" "=xm,*r,r")
7468         (vec_select:DI
7469           (match_operand:V2DI 1 "nonimmediate_operand" "x,Yi,o")
7470           (parallel [(const_int 0)])))]
7471   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7472   "@
7473    #
7474    #
7475    mov{q}\t{%1, %0|%0, %1}"
7476   [(set_attr "type" "*,*,imov")
7477    (set_attr "mode" "*,*,DI")])
7478
7479 (define_insn "*sse2_storeq"
7480   [(set (match_operand:DI 0 "nonimmediate_operand" "=xm")
7481         (vec_select:DI
7482           (match_operand:V2DI 1 "register_operand" "x")
7483           (parallel [(const_int 0)])))]
7484   "TARGET_SSE"
7485   "#")
7486
7487 (define_split
7488   [(set (match_operand:DI 0 "nonimmediate_operand" "")
7489         (vec_select:DI
7490           (match_operand:V2DI 1 "register_operand" "")
7491           (parallel [(const_int 0)])))]
7492   "TARGET_SSE
7493    && reload_completed
7494    && (TARGET_INTER_UNIT_MOVES
7495        || MEM_P (operands [0])
7496        || !GENERAL_REGNO_P (true_regnum (operands [0])))"
7497   [(set (match_dup 0) (match_dup 1))]
7498   "operands[1] = gen_rtx_REG (DImode, REGNO (operands[1]));")
7499
7500 (define_insn "*vec_extractv2di_1_rex64"
7501   [(set (match_operand:DI 0 "nonimmediate_operand"     "=m,x,x,x,r")
7502         (vec_select:DI
7503           (match_operand:V2DI 1 "nonimmediate_operand" " x,0,x,o,o")
7504           (parallel [(const_int 1)])))]
7505   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7506   "@
7507    %vmovhps\t{%1, %0|%0, %1}
7508    psrldq\t{$8, %0|%0, 8}
7509    vpsrldq\t{$8, %1, %0|%0, %1, 8}
7510    %vmovq\t{%H1, %0|%0, %H1}
7511    mov{q}\t{%H1, %0|%0, %H1}"
7512   [(set_attr "isa" "*,noavx,avx,*,*")
7513    (set_attr "type" "ssemov,sseishft1,sseishft1,ssemov,imov")
7514    (set_attr "length_immediate" "*,1,1,*,*")
7515    (set_attr "memory" "*,none,none,*,*")
7516    (set_attr "prefix" "maybe_vex,orig,vex,maybe_vex,orig")
7517    (set_attr "mode" "V2SF,TI,TI,TI,DI")])
7518
7519 (define_insn "*vec_extractv2di_1"
7520   [(set (match_operand:DI 0 "nonimmediate_operand"     "=m,x,x,x,x,x")
7521         (vec_select:DI
7522           (match_operand:V2DI 1 "nonimmediate_operand" " x,0,x,o,x,o")
7523           (parallel [(const_int 1)])))]
7524   "!TARGET_64BIT && TARGET_SSE
7525    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7526   "@
7527    %vmovhps\t{%1, %0|%0, %1}
7528    psrldq\t{$8, %0|%0, 8}
7529    vpsrldq\t{$8, %1, %0|%0, %1, 8}
7530    %vmovq\t{%H1, %0|%0, %H1}
7531    movhlps\t{%1, %0|%0, %1}
7532    movlps\t{%H1, %0|%0, %H1}"
7533   [(set_attr "isa" "*,sse2_noavx,avx,sse2,noavx,noavx")
7534    (set_attr "type" "ssemov,sseishft1,sseishft1,ssemov,ssemov,ssemov")
7535    (set_attr "length_immediate" "*,1,1,*,*,*")
7536    (set_attr "memory" "*,none,none,*,*,*")
7537    (set_attr "prefix" "maybe_vex,orig,vex,maybe_vex,orig,orig")
7538    (set_attr "mode" "V2SF,TI,TI,TI,V4SF,V2SF")])
7539
7540 (define_insn "*vec_dupv4si_avx"
7541   [(set (match_operand:V4SI 0 "register_operand"     "=x,x")
7542         (vec_duplicate:V4SI
7543           (match_operand:SI 1 "nonimmediate_operand" " x,m")))]
7544   "TARGET_AVX"
7545   "@
7546    vpshufd\t{$0, %1, %0|%0, %1, 0}
7547    vbroadcastss\t{%1, %0|%0, %1}"
7548   [(set_attr "type" "sselog1,ssemov")
7549    (set_attr "length_immediate" "1,0")
7550    (set_attr "prefix_extra" "0,1")
7551    (set_attr "prefix" "vex")
7552    (set_attr "mode" "TI,V4SF")])
7553
7554 (define_insn "*vec_dupv4si"
7555   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
7556         (vec_duplicate:V4SI
7557           (match_operand:SI 1 "register_operand" " x,0")))]
7558   "TARGET_SSE"
7559   "@
7560    pshufd\t{$0, %1, %0|%0, %1, 0}
7561    shufps\t{$0, %0, %0|%0, %0, 0}"
7562   [(set_attr "isa" "sse2,*")
7563    (set_attr "type" "sselog1")
7564    (set_attr "length_immediate" "1")
7565    (set_attr "mode" "TI,V4SF")])
7566
7567 (define_insn "*vec_dupv2di_sse3"
7568   [(set (match_operand:V2DI 0 "register_operand"     "=x,x,x")
7569         (vec_duplicate:V2DI
7570           (match_operand:DI 1 "nonimmediate_operand" " 0,x,m")))]
7571   "TARGET_SSE3"
7572   "@
7573    punpcklqdq\t%0, %0
7574    vpunpcklqdq\t{%d1, %0|%0, %d1}
7575    %vmovddup\t{%1, %0|%0, %1}"
7576   [(set_attr "isa" "noavx,avx,*")
7577    (set_attr "type" "sselog1")
7578    (set_attr "prefix" "orig,vex,maybe_vex")
7579    (set_attr "mode" "TI,TI,DF")])
7580
7581 (define_insn "*vec_dupv2di"
7582   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
7583         (vec_duplicate:V2DI
7584           (match_operand:DI 1 "register_operand" " 0,0")))]
7585   "TARGET_SSE"
7586   "@
7587    punpcklqdq\t%0, %0
7588    movlhps\t%0, %0"
7589   [(set_attr "isa" "sse2,*")
7590    (set_attr "type" "sselog1,ssemov")
7591    (set_attr "mode" "TI,V4SF")])
7592
7593 (define_insn "*vec_concatv2si_sse4_1"
7594   [(set (match_operand:V2SI 0 "register_operand"     "=x, x,x,x, x, *y,*y")
7595         (vec_concat:V2SI
7596           (match_operand:SI 1 "nonimmediate_operand" " 0, x,0,x,rm,  0,rm")
7597           (match_operand:SI 2 "vector_move_operand"  "rm,rm,x,x, C,*ym, C")))]
7598   "TARGET_SSE4_1"
7599   "@
7600    pinsrd\t{$1, %2, %0|%0, %2, 1}
7601    vpinsrd\t{$1, %2, %1, %0|%0, %1, %2, 1}
7602    punpckldq\t{%2, %0|%0, %2}
7603    vpunpckldq\t{%2, %1, %0|%0, %1, %2}
7604    %vmovd\t{%1, %0|%0, %1}
7605    punpckldq\t{%2, %0|%0, %2}
7606    movd\t{%1, %0|%0, %1}"
7607   [(set_attr "isa" "noavx,avx,noavx,avx,*,*,*")
7608    (set_attr "type" "sselog,sselog,sselog,sselog,ssemov,mmxcvt,mmxmov")
7609    (set_attr "prefix_extra" "1,1,*,*,*,*,*")
7610    (set_attr "length_immediate" "1,1,*,*,*,*,*")
7611    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex,orig,orig")
7612    (set_attr "mode" "TI,TI,TI,TI,TI,DI,DI")])
7613
7614 ;; ??? In theory we can match memory for the MMX alternative, but allowing
7615 ;; nonimmediate_operand for operand 2 and *not* allowing memory for the SSE
7616 ;; alternatives pretty much forces the MMX alternative to be chosen.
7617 (define_insn "*vec_concatv2si_sse2"
7618   [(set (match_operand:V2SI 0 "register_operand"     "=x,x ,*y,*y")
7619         (vec_concat:V2SI
7620           (match_operand:SI 1 "nonimmediate_operand" " 0,rm, 0,rm")
7621           (match_operand:SI 2 "reg_or_0_operand"     " x,C ,*y, C")))]
7622   "TARGET_SSE2"
7623   "@
7624    punpckldq\t{%2, %0|%0, %2}
7625    movd\t{%1, %0|%0, %1}
7626    punpckldq\t{%2, %0|%0, %2}
7627    movd\t{%1, %0|%0, %1}"
7628   [(set_attr "type" "sselog,ssemov,mmxcvt,mmxmov")
7629    (set_attr "mode" "TI,TI,DI,DI")])
7630
7631 (define_insn "*vec_concatv2si_sse"
7632   [(set (match_operand:V2SI 0 "register_operand"     "=x,x,*y,*y")
7633         (vec_concat:V2SI
7634           (match_operand:SI 1 "nonimmediate_operand" " 0,m, 0,*rm")
7635           (match_operand:SI 2 "reg_or_0_operand"     " x,C,*y,C")))]
7636   "TARGET_SSE"
7637   "@
7638    unpcklps\t{%2, %0|%0, %2}
7639    movss\t{%1, %0|%0, %1}
7640    punpckldq\t{%2, %0|%0, %2}
7641    movd\t{%1, %0|%0, %1}"
7642   [(set_attr "type" "sselog,ssemov,mmxcvt,mmxmov")
7643    (set_attr "mode" "V4SF,V4SF,DI,DI")])
7644
7645 (define_insn "*vec_concatv4si"
7646   [(set (match_operand:V4SI 0 "register_operand"       "=x,x,x,x,x")
7647         (vec_concat:V4SI
7648           (match_operand:V2SI 1 "register_operand"     " 0,x,0,0,x")
7649           (match_operand:V2SI 2 "nonimmediate_operand" " x,x,x,m,m")))]
7650   "TARGET_SSE"
7651   "@
7652    punpcklqdq\t{%2, %0|%0, %2}
7653    vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}
7654    movlhps\t{%2, %0|%0, %2}
7655    movhps\t{%2, %0|%0, %2}
7656    vmovhps\t{%2, %1, %0|%0, %1, %2}"
7657   [(set_attr "isa" "sse2_noavx,avx,noavx,noavx,avx")
7658    (set_attr "type" "sselog,sselog,ssemov,ssemov,ssemov")
7659    (set_attr "prefix" "orig,vex,orig,orig,vex")
7660    (set_attr "mode" "TI,TI,V4SF,V2SF,V2SF")])
7661
7662 ;; movd instead of movq is required to handle broken assemblers.
7663 (define_insn "*vec_concatv2di_rex64"
7664   [(set (match_operand:V2DI 0 "register_operand"
7665           "=x,x ,x ,Yi,!x,x,x,x,x")
7666         (vec_concat:V2DI
7667           (match_operand:DI 1 "nonimmediate_operand"
7668           " 0,x ,xm,r ,*y,0,x,0,x")
7669           (match_operand:DI 2 "vector_move_operand"
7670           "rm,rm,C ,C ,C ,x,x,m,m")))]
7671   "TARGET_64BIT"
7672   "@
7673    pinsrq\t{$1, %2, %0|%0, %2, 1}
7674    vpinsrq\t{$1, %2, %1, %0|%0, %1, %2, 1}
7675    %vmovq\t{%1, %0|%0, %1}
7676    %vmovd\t{%1, %0|%0, %1}
7677    movq2dq\t{%1, %0|%0, %1}
7678    punpcklqdq\t{%2, %0|%0, %2}
7679    vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}
7680    movhps\t{%2, %0|%0, %2}
7681    vmovhps\t{%2, %1, %0|%0, %1, %2}"
7682   [(set_attr "isa" "sse4_noavx,avx,*,*,*,noavx,avx,noavx,avx")
7683    (set (attr "type")
7684      (if_then_else
7685        (eq_attr "alternative" "0,1,5,6")
7686        (const_string "sselog")
7687        (const_string "ssemov")))
7688    (set (attr "prefix_rex")
7689      (if_then_else
7690        (and (eq_attr "alternative" "0,3")
7691             (not (match_test "TARGET_AVX")))
7692        (const_string "1")
7693        (const_string "*")))
7694    (set_attr "prefix_extra" "1,1,*,*,*,*,*,*,*")
7695    (set_attr "length_immediate" "1,1,*,*,*,*,*,*,*")
7696    (set_attr "prefix" "orig,vex,maybe_vex,maybe_vex,orig,orig,vex,orig,vex")
7697    (set_attr "mode" "TI,TI,TI,TI,TI,TI,TI,V2SF,V2SF")])
7698
7699 (define_insn "vec_concatv2di"
7700   [(set (match_operand:V2DI 0 "register_operand"     "=x,?x,x,x,x,x,x")
7701         (vec_concat:V2DI
7702           (match_operand:DI 1 "nonimmediate_operand" "xm,*y,0,x,0,0,x")
7703           (match_operand:DI 2 "vector_move_operand"  " C, C,x,x,x,m,m")))]
7704   "!TARGET_64BIT && TARGET_SSE"
7705   "@
7706    %vmovq\t{%1, %0|%0, %1}
7707    movq2dq\t{%1, %0|%0, %1}
7708    punpcklqdq\t{%2, %0|%0, %2}
7709    vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}
7710    movlhps\t{%2, %0|%0, %2}
7711    movhps\t{%2, %0|%0, %2}
7712    vmovhps\t{%2, %1, %0|%0, %1, %2}"
7713   [(set_attr "isa" "sse2,sse2,sse2_noavx,avx,noavx,noavx,avx")
7714    (set_attr "type" "ssemov,ssemov,sselog,sselog,ssemov,ssemov,ssemov")
7715    (set_attr "prefix" "maybe_vex,orig,orig,vex,orig,orig,vex")
7716    (set_attr "mode" "TI,TI,TI,TI,V4SF,V2SF,V2SF")])
7717
7718 (define_expand "vec_unpacks_lo_<mode>"
7719   [(match_operand:<sseunpackmode> 0 "register_operand" "")
7720    (match_operand:VI124_AVX2 1 "register_operand" "")]
7721   "TARGET_SSE2"
7722   "ix86_expand_sse_unpack (operands, false, false); DONE;")
7723
7724 (define_expand "vec_unpacks_hi_<mode>"
7725   [(match_operand:<sseunpackmode> 0 "register_operand" "")
7726    (match_operand:VI124_AVX2 1 "register_operand" "")]
7727   "TARGET_SSE2"
7728   "ix86_expand_sse_unpack (operands, false, true); DONE;")
7729
7730 (define_expand "vec_unpacku_lo_<mode>"
7731   [(match_operand:<sseunpackmode> 0 "register_operand" "")
7732    (match_operand:VI124_AVX2 1 "register_operand" "")]
7733   "TARGET_SSE2"
7734   "ix86_expand_sse_unpack (operands, true, false); DONE;")
7735
7736 (define_expand "vec_unpacku_hi_<mode>"
7737   [(match_operand:<sseunpackmode> 0 "register_operand" "")
7738    (match_operand:VI124_AVX2 1 "register_operand" "")]
7739   "TARGET_SSE2"
7740   "ix86_expand_sse_unpack (operands, true, true); DONE;")
7741
7742 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7743 ;;
7744 ;; Miscellaneous
7745 ;;
7746 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7747
7748 (define_expand "avx2_uavgv32qi3"
7749   [(set (match_operand:V32QI 0 "register_operand" "")
7750         (truncate:V32QI
7751           (lshiftrt:V32HI
7752             (plus:V32HI
7753               (plus:V32HI
7754                 (zero_extend:V32HI
7755                   (match_operand:V32QI 1 "nonimmediate_operand" ""))
7756                 (zero_extend:V32HI
7757                   (match_operand:V32QI 2 "nonimmediate_operand" "")))
7758               (const_vector:V32QI [(const_int 1) (const_int 1)
7759                                    (const_int 1) (const_int 1)
7760                                    (const_int 1) (const_int 1)
7761                                    (const_int 1) (const_int 1)
7762                                    (const_int 1) (const_int 1)
7763                                    (const_int 1) (const_int 1)
7764                                    (const_int 1) (const_int 1)
7765                                    (const_int 1) (const_int 1)
7766                                    (const_int 1) (const_int 1)
7767                                    (const_int 1) (const_int 1)
7768                                    (const_int 1) (const_int 1)
7769                                    (const_int 1) (const_int 1)
7770                                    (const_int 1) (const_int 1)
7771                                    (const_int 1) (const_int 1)
7772                                    (const_int 1) (const_int 1)
7773                                    (const_int 1) (const_int 1)]))
7774             (const_int 1))))]
7775   "TARGET_AVX2"
7776   "ix86_fixup_binary_operands_no_copy (PLUS, V32QImode, operands);")
7777
7778 (define_expand "sse2_uavgv16qi3"
7779   [(set (match_operand:V16QI 0 "register_operand" "")
7780         (truncate:V16QI
7781           (lshiftrt:V16HI
7782             (plus:V16HI
7783               (plus:V16HI
7784                 (zero_extend:V16HI
7785                   (match_operand:V16QI 1 "nonimmediate_operand" ""))
7786                 (zero_extend:V16HI
7787                   (match_operand:V16QI 2 "nonimmediate_operand" "")))
7788               (const_vector:V16QI [(const_int 1) (const_int 1)
7789                                    (const_int 1) (const_int 1)
7790                                    (const_int 1) (const_int 1)
7791                                    (const_int 1) (const_int 1)
7792                                    (const_int 1) (const_int 1)
7793                                    (const_int 1) (const_int 1)
7794                                    (const_int 1) (const_int 1)
7795                                    (const_int 1) (const_int 1)]))
7796             (const_int 1))))]
7797   "TARGET_SSE2"
7798   "ix86_fixup_binary_operands_no_copy (PLUS, V16QImode, operands);")
7799
7800 (define_insn "*avx2_uavgv32qi3"
7801   [(set (match_operand:V32QI 0 "register_operand" "=x")
7802         (truncate:V32QI
7803           (lshiftrt:V32HI
7804             (plus:V32HI
7805               (plus:V32HI
7806                 (zero_extend:V32HI
7807                   (match_operand:V32QI 1 "nonimmediate_operand" "%x"))
7808                 (zero_extend:V32HI
7809                   (match_operand:V32QI 2 "nonimmediate_operand" "xm")))
7810               (const_vector:V32QI [(const_int 1) (const_int 1)
7811                                    (const_int 1) (const_int 1)
7812                                    (const_int 1) (const_int 1)
7813                                    (const_int 1) (const_int 1)
7814                                    (const_int 1) (const_int 1)
7815                                    (const_int 1) (const_int 1)
7816                                    (const_int 1) (const_int 1)
7817                                    (const_int 1) (const_int 1)
7818                                    (const_int 1) (const_int 1)
7819                                    (const_int 1) (const_int 1)
7820                                    (const_int 1) (const_int 1)
7821                                    (const_int 1) (const_int 1)
7822                                    (const_int 1) (const_int 1)
7823                                    (const_int 1) (const_int 1)
7824                                    (const_int 1) (const_int 1)
7825                                    (const_int 1) (const_int 1)]))
7826             (const_int 1))))]
7827   "TARGET_AVX2 && ix86_binary_operator_ok (PLUS, V32QImode, operands)"
7828   "vpavgb\t{%2, %1, %0|%0, %1, %2}"
7829   [(set_attr "type" "sseiadd")
7830    (set_attr "prefix" "vex")
7831    (set_attr "mode" "OI")])
7832
7833 (define_insn "*sse2_uavgv16qi3"
7834   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
7835         (truncate:V16QI
7836           (lshiftrt:V16HI
7837             (plus:V16HI
7838               (plus:V16HI
7839                 (zero_extend:V16HI
7840                   (match_operand:V16QI 1 "nonimmediate_operand" "%0,x"))
7841                 (zero_extend:V16HI
7842                   (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm")))
7843               (const_vector:V16QI [(const_int 1) (const_int 1)
7844                                    (const_int 1) (const_int 1)
7845                                    (const_int 1) (const_int 1)
7846                                    (const_int 1) (const_int 1)
7847                                    (const_int 1) (const_int 1)
7848                                    (const_int 1) (const_int 1)
7849                                    (const_int 1) (const_int 1)
7850                                    (const_int 1) (const_int 1)]))
7851             (const_int 1))))]
7852   "TARGET_SSE2 && ix86_binary_operator_ok (PLUS, V16QImode, operands)"
7853   "@
7854    pavgb\t{%2, %0|%0, %2}
7855    vpavgb\t{%2, %1, %0|%0, %1, %2}"
7856   [(set_attr "isa" "noavx,avx")
7857    (set_attr "type" "sseiadd")
7858    (set_attr "prefix_data16" "1,*")
7859    (set_attr "prefix" "orig,vex")
7860    (set_attr "mode" "TI")])
7861
7862 (define_expand "avx2_uavgv16hi3"
7863   [(set (match_operand:V16HI 0 "register_operand" "")
7864         (truncate:V16HI
7865           (lshiftrt:V16SI
7866             (plus:V16SI
7867               (plus:V16SI
7868                 (zero_extend:V16SI
7869                   (match_operand:V16HI 1 "nonimmediate_operand" ""))
7870                 (zero_extend:V16SI
7871                   (match_operand:V16HI 2 "nonimmediate_operand" "")))
7872               (const_vector:V16HI [(const_int 1) (const_int 1)
7873                                    (const_int 1) (const_int 1)
7874                                    (const_int 1) (const_int 1)
7875                                    (const_int 1) (const_int 1)
7876                                    (const_int 1) (const_int 1)
7877                                    (const_int 1) (const_int 1)
7878                                    (const_int 1) (const_int 1)
7879                                    (const_int 1) (const_int 1)]))
7880             (const_int 1))))]
7881   "TARGET_AVX2"
7882   "ix86_fixup_binary_operands_no_copy (PLUS, V16HImode, operands);")
7883
7884 (define_expand "sse2_uavgv8hi3"
7885   [(set (match_operand:V8HI 0 "register_operand" "")
7886         (truncate:V8HI
7887           (lshiftrt:V8SI
7888             (plus:V8SI
7889               (plus:V8SI
7890                 (zero_extend:V8SI
7891                   (match_operand:V8HI 1 "nonimmediate_operand" ""))
7892                 (zero_extend:V8SI
7893                   (match_operand:V8HI 2 "nonimmediate_operand" "")))
7894               (const_vector:V8HI [(const_int 1) (const_int 1)
7895                                   (const_int 1) (const_int 1)
7896                                   (const_int 1) (const_int 1)
7897                                   (const_int 1) (const_int 1)]))
7898             (const_int 1))))]
7899   "TARGET_SSE2"
7900   "ix86_fixup_binary_operands_no_copy (PLUS, V8HImode, operands);")
7901
7902 (define_insn "*avx2_uavgv16hi3"
7903   [(set (match_operand:V16HI 0 "register_operand" "=x")
7904         (truncate:V16HI
7905           (lshiftrt:V16SI
7906             (plus:V16SI
7907               (plus:V16SI
7908                 (zero_extend:V16SI
7909                   (match_operand:V16HI 1 "nonimmediate_operand" "%x"))
7910                 (zero_extend:V16SI
7911                   (match_operand:V16HI 2 "nonimmediate_operand" "xm")))
7912               (const_vector:V16HI [(const_int 1) (const_int 1)
7913                                    (const_int 1) (const_int 1)
7914                                    (const_int 1) (const_int 1)
7915                                    (const_int 1) (const_int 1)
7916                                    (const_int 1) (const_int 1)
7917                                    (const_int 1) (const_int 1)
7918                                    (const_int 1) (const_int 1)
7919                                    (const_int 1) (const_int 1)]))
7920             (const_int 1))))]
7921   "TARGET_AVX2 && ix86_binary_operator_ok (PLUS, V16HImode, operands)"
7922   "vpavgw\t{%2, %1, %0|%0, %1, %2}"
7923   [(set_attr "type" "sseiadd")
7924    (set_attr "prefix" "vex")
7925    (set_attr "mode" "OI")])
7926
7927 (define_insn "*sse2_uavgv8hi3"
7928   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
7929         (truncate:V8HI
7930           (lshiftrt:V8SI
7931             (plus:V8SI
7932               (plus:V8SI
7933                 (zero_extend:V8SI
7934                   (match_operand:V8HI 1 "nonimmediate_operand" "%0,x"))
7935                 (zero_extend:V8SI
7936                   (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")))
7937               (const_vector:V8HI [(const_int 1) (const_int 1)
7938                                   (const_int 1) (const_int 1)
7939                                   (const_int 1) (const_int 1)
7940                                   (const_int 1) (const_int 1)]))
7941             (const_int 1))))]
7942   "TARGET_SSE2 && ix86_binary_operator_ok (PLUS, V8HImode, operands)"
7943   "@
7944    pavgw\t{%2, %0|%0, %2}
7945    vpavgw\t{%2, %1, %0|%0, %1, %2}"
7946   [(set_attr "isa" "noavx,avx")
7947    (set_attr "type" "sseiadd")
7948    (set_attr "prefix_data16" "1,*")
7949    (set_attr "prefix" "orig,vex")
7950    (set_attr "mode" "TI")])
7951
7952 ;; The correct representation for this is absolutely enormous, and
7953 ;; surely not generally useful.
7954 (define_insn "<sse2_avx2>_psadbw"
7955   [(set (match_operand:VI8_AVX2 0 "register_operand" "=x,x")
7956         (unspec:VI8_AVX2 [(match_operand:<ssebytemode> 1 "register_operand" "0,x")
7957                           (match_operand:<ssebytemode> 2 "nonimmediate_operand" "xm,xm")]
7958                           UNSPEC_PSADBW))]
7959   "TARGET_SSE2"
7960   "@
7961    psadbw\t{%2, %0|%0, %2}
7962    vpsadbw\t{%2, %1, %0|%0, %1, %2}"
7963   [(set_attr "isa" "noavx,avx")
7964    (set_attr "type" "sseiadd")
7965    (set_attr "atom_unit" "simul")
7966    (set_attr "prefix_data16" "1,*")
7967    (set_attr "prefix" "orig,vex")
7968    (set_attr "mode" "<sseinsnmode>")])
7969
7970 (define_insn "<sse>_movmsk<ssemodesuffix><avxsizesuffix>"
7971   [(set (match_operand:SI 0 "register_operand" "=r")
7972         (unspec:SI
7973           [(match_operand:VF 1 "register_operand" "x")]
7974           UNSPEC_MOVMSK))]
7975   "TARGET_SSE"
7976   "%vmovmsk<ssemodesuffix>\t{%1, %0|%0, %1}"
7977   [(set_attr "type" "ssemov")
7978    (set_attr "prefix" "maybe_vex")
7979    (set_attr "mode" "<MODE>")])
7980
7981 (define_insn "avx2_pmovmskb"
7982   [(set (match_operand:SI 0 "register_operand" "=r")
7983         (unspec:SI [(match_operand:V32QI 1 "register_operand" "x")]
7984                    UNSPEC_MOVMSK))]
7985   "TARGET_AVX2"
7986   "vpmovmskb\t{%1, %0|%0, %1}"
7987   [(set_attr "type" "ssemov")
7988    (set_attr "prefix" "vex")
7989    (set_attr "mode" "DI")])
7990
7991 (define_insn "sse2_pmovmskb"
7992   [(set (match_operand:SI 0 "register_operand" "=r")
7993         (unspec:SI [(match_operand:V16QI 1 "register_operand" "x")]
7994                    UNSPEC_MOVMSK))]
7995   "TARGET_SSE2"
7996   "%vpmovmskb\t{%1, %0|%0, %1}"
7997   [(set_attr "type" "ssemov")
7998    (set_attr "prefix_data16" "1")
7999    (set_attr "prefix" "maybe_vex")
8000    (set_attr "mode" "SI")])
8001
8002 (define_expand "sse2_maskmovdqu"
8003   [(set (match_operand:V16QI 0 "memory_operand" "")
8004         (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "")
8005                        (match_operand:V16QI 2 "register_operand" "")
8006                        (match_dup 0)]
8007                       UNSPEC_MASKMOV))]
8008   "TARGET_SSE2")
8009
8010 (define_insn "*sse2_maskmovdqu"
8011   [(set (mem:V16QI (match_operand:P 0 "register_operand" "D"))
8012         (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "x")
8013                        (match_operand:V16QI 2 "register_operand" "x")
8014                        (mem:V16QI (match_dup 0))]
8015                       UNSPEC_MASKMOV))]
8016   "TARGET_SSE2"
8017   "%vmaskmovdqu\t{%2, %1|%1, %2}"
8018   [(set_attr "type" "ssemov")
8019    (set_attr "prefix_data16" "1")
8020    ;; The implicit %rdi operand confuses default length_vex computation.
8021    (set (attr "length_vex")
8022      (symbol_ref ("3 + REX_SSE_REGNO_P (REGNO (operands[2]))")))
8023    (set_attr "prefix" "maybe_vex")
8024    (set_attr "mode" "TI")])
8025
8026 (define_insn "sse_ldmxcsr"
8027   [(unspec_volatile [(match_operand:SI 0 "memory_operand" "m")]
8028                     UNSPECV_LDMXCSR)]
8029   "TARGET_SSE"
8030   "%vldmxcsr\t%0"
8031   [(set_attr "type" "sse")
8032    (set_attr "atom_sse_attr" "mxcsr")
8033    (set_attr "prefix" "maybe_vex")
8034    (set_attr "memory" "load")])
8035
8036 (define_insn "sse_stmxcsr"
8037   [(set (match_operand:SI 0 "memory_operand" "=m")
8038         (unspec_volatile:SI [(const_int 0)] UNSPECV_STMXCSR))]
8039   "TARGET_SSE"
8040   "%vstmxcsr\t%0"
8041   [(set_attr "type" "sse")
8042    (set_attr "atom_sse_attr" "mxcsr")
8043    (set_attr "prefix" "maybe_vex")
8044    (set_attr "memory" "store")])
8045
8046 (define_expand "sse_sfence"
8047   [(set (match_dup 0)
8048         (unspec:BLK [(match_dup 0)] UNSPEC_SFENCE))]
8049   "TARGET_SSE || TARGET_3DNOW_A"
8050 {
8051   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
8052   MEM_VOLATILE_P (operands[0]) = 1;
8053 })
8054
8055 (define_insn "*sse_sfence"
8056   [(set (match_operand:BLK 0 "" "")
8057         (unspec:BLK [(match_dup 0)] UNSPEC_SFENCE))]
8058   "TARGET_SSE || TARGET_3DNOW_A"
8059   "sfence"
8060   [(set_attr "type" "sse")
8061    (set_attr "length_address" "0")
8062    (set_attr "atom_sse_attr" "fence")
8063    (set_attr "memory" "unknown")])
8064
8065 (define_insn "sse2_clflush"
8066   [(unspec_volatile [(match_operand 0 "address_operand" "p")]
8067                     UNSPECV_CLFLUSH)]
8068   "TARGET_SSE2"
8069   "clflush\t%a0"
8070   [(set_attr "type" "sse")
8071    (set_attr "atom_sse_attr" "fence")
8072    (set_attr "memory" "unknown")])
8073
8074 (define_expand "sse2_mfence"
8075   [(set (match_dup 0)
8076         (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
8077   "TARGET_SSE2"
8078 {
8079   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
8080   MEM_VOLATILE_P (operands[0]) = 1;
8081 })
8082
8083 (define_insn "*sse2_mfence"
8084   [(set (match_operand:BLK 0 "" "")
8085         (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
8086   "TARGET_64BIT || TARGET_SSE2"
8087   "mfence"
8088   [(set_attr "type" "sse")
8089    (set_attr "length_address" "0")
8090    (set_attr "atom_sse_attr" "fence")
8091    (set_attr "memory" "unknown")])
8092
8093 (define_expand "sse2_lfence"
8094   [(set (match_dup 0)
8095         (unspec:BLK [(match_dup 0)] UNSPEC_LFENCE))]
8096   "TARGET_SSE2"
8097 {
8098   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
8099   MEM_VOLATILE_P (operands[0]) = 1;
8100 })
8101
8102 (define_insn "*sse2_lfence"
8103   [(set (match_operand:BLK 0 "" "")
8104         (unspec:BLK [(match_dup 0)] UNSPEC_LFENCE))]
8105   "TARGET_SSE2"
8106   "lfence"
8107   [(set_attr "type" "sse")
8108    (set_attr "length_address" "0")
8109    (set_attr "atom_sse_attr" "lfence")
8110    (set_attr "memory" "unknown")])
8111
8112 (define_insn "sse3_mwait"
8113   [(unspec_volatile [(match_operand:SI 0 "register_operand" "a")
8114                      (match_operand:SI 1 "register_operand" "c")]
8115                     UNSPECV_MWAIT)]
8116   "TARGET_SSE3"
8117 ;; 64bit version is "mwait %rax,%rcx". But only lower 32bits are used.
8118 ;; Since 32bit register operands are implicitly zero extended to 64bit,
8119 ;; we only need to set up 32bit registers.
8120   "mwait"
8121   [(set_attr "length" "3")])
8122
8123 (define_insn "sse3_monitor"
8124   [(unspec_volatile [(match_operand:SI 0 "register_operand" "a")
8125                      (match_operand:SI 1 "register_operand" "c")
8126                      (match_operand:SI 2 "register_operand" "d")]
8127                     UNSPECV_MONITOR)]
8128   "TARGET_SSE3 && !TARGET_64BIT"
8129   "monitor\t%0, %1, %2"
8130   [(set_attr "length" "3")])
8131
8132 (define_insn "sse3_monitor64"
8133   [(unspec_volatile [(match_operand:DI 0 "register_operand" "a")
8134                      (match_operand:SI 1 "register_operand" "c")
8135                      (match_operand:SI 2 "register_operand" "d")]
8136                     UNSPECV_MONITOR)]
8137   "TARGET_SSE3 && TARGET_64BIT"
8138 ;; 64bit version is "monitor %rax,%rcx,%rdx". But only lower 32bits in
8139 ;; RCX and RDX are used.  Since 32bit register operands are implicitly
8140 ;; zero extended to 64bit, we only need to set up 32bit registers.
8141   "monitor"
8142   [(set_attr "length" "3")])
8143
8144 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8145 ;;
8146 ;; SSSE3 instructions
8147 ;;
8148 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8149
8150 (define_insn "avx2_phaddwv16hi3"
8151   [(set (match_operand:V16HI 0 "register_operand" "=x")
8152         (vec_concat:V16HI
8153           (vec_concat:V8HI
8154             (vec_concat:V4HI
8155               (vec_concat:V2HI
8156                 (plus:HI
8157                   (vec_select:HI
8158                     (match_operand:V16HI 1 "register_operand" "x")
8159                     (parallel [(const_int 0)]))
8160                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8161                 (plus:HI
8162                   (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8163                   (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8164               (vec_concat:V2HI
8165                 (plus:HI
8166                   (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8167                   (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8168                 (plus:HI
8169                   (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8170                   (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8171             (vec_concat:V4HI
8172               (vec_concat:V2HI
8173                 (plus:HI
8174                   (vec_select:HI (match_dup 1) (parallel [(const_int 8)]))
8175                   (vec_select:HI (match_dup 1) (parallel [(const_int 9)])))
8176                 (plus:HI
8177                   (vec_select:HI (match_dup 1) (parallel [(const_int 10)]))
8178                   (vec_select:HI (match_dup 1) (parallel [(const_int 11)]))))
8179               (vec_concat:V2HI
8180                 (plus:HI
8181                   (vec_select:HI (match_dup 1) (parallel [(const_int 12)]))
8182                   (vec_select:HI (match_dup 1) (parallel [(const_int 13)])))
8183                 (plus:HI
8184                   (vec_select:HI (match_dup 1) (parallel [(const_int 14)]))
8185                   (vec_select:HI (match_dup 1) (parallel [(const_int 15)]))))))
8186           (vec_concat:V8HI
8187             (vec_concat:V4HI
8188               (vec_concat:V2HI
8189                 (plus:HI
8190                   (vec_select:HI
8191                     (match_operand:V16HI 2 "nonimmediate_operand" "xm")
8192                     (parallel [(const_int 0)]))
8193                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8194                 (plus:HI
8195                   (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8196                   (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8197               (vec_concat:V2HI
8198                 (plus:HI
8199                   (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8200                   (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8201                 (plus:HI
8202                   (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8203                   (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))
8204             (vec_concat:V4HI
8205               (vec_concat:V2HI
8206                 (plus:HI
8207                   (vec_select:HI (match_dup 2) (parallel [(const_int 8)]))
8208                   (vec_select:HI (match_dup 2) (parallel [(const_int 9)])))
8209                 (plus:HI
8210                   (vec_select:HI (match_dup 2) (parallel [(const_int 10)]))
8211                   (vec_select:HI (match_dup 2) (parallel [(const_int 11)]))))
8212               (vec_concat:V2HI
8213                 (plus:HI
8214                   (vec_select:HI (match_dup 2) (parallel [(const_int 12)]))
8215                   (vec_select:HI (match_dup 2) (parallel [(const_int 13)])))
8216                 (plus:HI
8217                   (vec_select:HI (match_dup 2) (parallel [(const_int 14)]))
8218                   (vec_select:HI (match_dup 2) (parallel [(const_int 15)]))))))))]
8219   "TARGET_AVX2"
8220   "vphaddw\t{%2, %1, %0|%0, %1, %2}"
8221   [(set_attr "type" "sseiadd")
8222    (set_attr "prefix_extra" "1")
8223    (set_attr "prefix" "vex")
8224    (set_attr "mode" "OI")])
8225
8226 (define_insn "ssse3_phaddwv8hi3"
8227   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
8228         (vec_concat:V8HI
8229           (vec_concat:V4HI
8230             (vec_concat:V2HI
8231               (plus:HI
8232                 (vec_select:HI
8233                   (match_operand:V8HI 1 "register_operand" "0,x")
8234                   (parallel [(const_int 0)]))
8235                 (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8236               (plus:HI
8237                 (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8238                 (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8239             (vec_concat:V2HI
8240               (plus:HI
8241                 (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8242                 (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8243               (plus:HI
8244                 (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8245                 (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8246           (vec_concat:V4HI
8247             (vec_concat:V2HI
8248               (plus:HI
8249                 (vec_select:HI
8250                   (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
8251                   (parallel [(const_int 0)]))
8252                 (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8253               (plus:HI
8254                 (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8255                 (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8256             (vec_concat:V2HI
8257               (plus:HI
8258                 (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8259                 (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8260               (plus:HI
8261                 (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8262                 (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))))]
8263   "TARGET_SSSE3"
8264   "@
8265    phaddw\t{%2, %0|%0, %2}
8266    vphaddw\t{%2, %1, %0|%0, %1, %2}"
8267   [(set_attr "isa" "noavx,avx")
8268    (set_attr "type" "sseiadd")
8269    (set_attr "atom_unit" "complex")
8270    (set_attr "prefix_data16" "1,*")
8271    (set_attr "prefix_extra" "1")
8272    (set_attr "prefix" "orig,vex")
8273    (set_attr "mode" "TI")])
8274
8275 (define_insn "ssse3_phaddwv4hi3"
8276   [(set (match_operand:V4HI 0 "register_operand" "=y")
8277         (vec_concat:V4HI
8278           (vec_concat:V2HI
8279             (plus:HI
8280               (vec_select:HI
8281                 (match_operand:V4HI 1 "register_operand" "0")
8282                 (parallel [(const_int 0)]))
8283               (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8284             (plus:HI
8285               (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8286               (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8287           (vec_concat:V2HI
8288             (plus:HI
8289               (vec_select:HI
8290                 (match_operand:V4HI 2 "nonimmediate_operand" "ym")
8291                 (parallel [(const_int 0)]))
8292               (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8293             (plus:HI
8294               (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8295               (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))))]
8296   "TARGET_SSSE3"
8297   "phaddw\t{%2, %0|%0, %2}"
8298   [(set_attr "type" "sseiadd")
8299    (set_attr "atom_unit" "complex")
8300    (set_attr "prefix_extra" "1")
8301    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8302    (set_attr "mode" "DI")])
8303
8304 (define_insn "avx2_phadddv8si3"
8305   [(set (match_operand:V8SI 0 "register_operand" "=x")
8306         (vec_concat:V8SI
8307           (vec_concat:V4SI
8308             (vec_concat:V2SI
8309               (plus:SI
8310                 (vec_select:SI
8311                   (match_operand:V8SI 1 "register_operand" "x")
8312                   (parallel [(const_int 0)]))
8313                 (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8314               (plus:SI
8315                 (vec_select:SI (match_dup 1) (parallel [(const_int 2)]))
8316                 (vec_select:SI (match_dup 1) (parallel [(const_int 3)]))))
8317             (vec_concat:V2SI
8318               (plus:SI
8319                 (vec_select:SI (match_dup 1) (parallel [(const_int 4)]))
8320                 (vec_select:SI (match_dup 1) (parallel [(const_int 5)])))
8321               (plus:SI
8322                 (vec_select:SI (match_dup 1) (parallel [(const_int 6)]))
8323                 (vec_select:SI (match_dup 1) (parallel [(const_int 7)])))))
8324           (vec_concat:V4SI
8325             (vec_concat:V2SI
8326               (plus:SI
8327                 (vec_select:SI
8328                   (match_operand:V8SI 2 "nonimmediate_operand" "xm")
8329                   (parallel [(const_int 0)]))
8330                 (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))
8331               (plus:SI
8332                 (vec_select:SI (match_dup 2) (parallel [(const_int 2)]))
8333                 (vec_select:SI (match_dup 2) (parallel [(const_int 3)]))))
8334             (vec_concat:V2SI
8335               (plus:SI
8336                 (vec_select:SI (match_dup 2) (parallel [(const_int 4)]))
8337                 (vec_select:SI (match_dup 2) (parallel [(const_int 5)])))
8338               (plus:SI
8339                 (vec_select:SI (match_dup 2) (parallel [(const_int 6)]))
8340                 (vec_select:SI (match_dup 2) (parallel [(const_int 7)])))))))]
8341   "TARGET_AVX2"
8342   "vphaddd\t{%2, %1, %0|%0, %1, %2}"
8343   [(set_attr "type" "sseiadd")
8344    (set_attr "prefix_extra" "1")
8345    (set_attr "prefix" "vex")
8346    (set_attr "mode" "OI")])
8347
8348 (define_insn "ssse3_phadddv4si3"
8349   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
8350         (vec_concat:V4SI
8351           (vec_concat:V2SI
8352             (plus:SI
8353               (vec_select:SI
8354                 (match_operand:V4SI 1 "register_operand" "0,x")
8355                 (parallel [(const_int 0)]))
8356               (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8357             (plus:SI
8358               (vec_select:SI (match_dup 1) (parallel [(const_int 2)]))
8359               (vec_select:SI (match_dup 1) (parallel [(const_int 3)]))))
8360           (vec_concat:V2SI
8361             (plus:SI
8362               (vec_select:SI
8363                 (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm")
8364                 (parallel [(const_int 0)]))
8365               (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))
8366             (plus:SI
8367               (vec_select:SI (match_dup 2) (parallel [(const_int 2)]))
8368               (vec_select:SI (match_dup 2) (parallel [(const_int 3)]))))))]
8369   "TARGET_SSSE3"
8370   "@
8371    phaddd\t{%2, %0|%0, %2}
8372    vphaddd\t{%2, %1, %0|%0, %1, %2}"
8373   [(set_attr "isa" "noavx,avx")
8374    (set_attr "type" "sseiadd")
8375    (set_attr "atom_unit" "complex")
8376    (set_attr "prefix_data16" "1,*")
8377    (set_attr "prefix_extra" "1")
8378    (set_attr "prefix" "orig,vex")
8379    (set_attr "mode" "TI")])
8380
8381 (define_insn "ssse3_phadddv2si3"
8382   [(set (match_operand:V2SI 0 "register_operand" "=y")
8383         (vec_concat:V2SI
8384           (plus:SI
8385             (vec_select:SI
8386               (match_operand:V2SI 1 "register_operand" "0")
8387               (parallel [(const_int 0)]))
8388             (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8389           (plus:SI
8390             (vec_select:SI
8391               (match_operand:V2SI 2 "nonimmediate_operand" "ym")
8392               (parallel [(const_int 0)]))
8393             (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))))]
8394   "TARGET_SSSE3"
8395   "phaddd\t{%2, %0|%0, %2}"
8396   [(set_attr "type" "sseiadd")
8397    (set_attr "atom_unit" "complex")
8398    (set_attr "prefix_extra" "1")
8399    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8400    (set_attr "mode" "DI")])
8401
8402 (define_insn "avx2_phaddswv16hi3"
8403   [(set (match_operand:V16HI 0 "register_operand" "=x")
8404         (vec_concat:V16HI
8405           (vec_concat:V8HI
8406             (vec_concat:V4HI
8407               (vec_concat:V2HI
8408                 (ss_plus:HI
8409                   (vec_select:HI
8410                     (match_operand:V16HI 1 "register_operand" "x")
8411                     (parallel [(const_int 0)]))
8412                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8413                 (ss_plus:HI
8414                   (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8415                   (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8416               (vec_concat:V2HI
8417                 (ss_plus:HI
8418                   (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8419                   (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8420                 (ss_plus:HI
8421                   (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8422                   (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8423             (vec_concat:V4HI
8424               (vec_concat:V2HI
8425                 (ss_plus:HI
8426                   (vec_select:HI (match_dup 1) (parallel [(const_int 8)]))
8427                   (vec_select:HI (match_dup 1) (parallel [(const_int 9)])))
8428                 (ss_plus:HI
8429                   (vec_select:HI (match_dup 1) (parallel [(const_int 10)]))
8430                   (vec_select:HI (match_dup 1) (parallel [(const_int 11)]))))
8431               (vec_concat:V2HI
8432                 (ss_plus:HI
8433                   (vec_select:HI (match_dup 1) (parallel [(const_int 12)]))
8434                   (vec_select:HI (match_dup 1) (parallel [(const_int 13)])))
8435                 (ss_plus:HI
8436                   (vec_select:HI (match_dup 1) (parallel [(const_int 14)]))
8437                   (vec_select:HI (match_dup 1) (parallel [(const_int 15)]))))))
8438           (vec_concat:V8HI
8439             (vec_concat:V4HI
8440               (vec_concat:V2HI
8441                 (ss_plus:HI
8442                   (vec_select:HI
8443                     (match_operand:V16HI 2 "nonimmediate_operand" "xm")
8444                     (parallel [(const_int 0)]))
8445                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8446                 (ss_plus:HI
8447                   (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8448                   (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8449               (vec_concat:V2HI
8450                 (ss_plus:HI
8451                   (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8452                   (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8453                 (ss_plus:HI
8454                   (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8455                   (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))
8456             (vec_concat:V4HI
8457               (vec_concat:V2HI
8458                 (ss_plus:HI
8459                   (vec_select:HI (match_dup 2) (parallel [(const_int 8)]))
8460                   (vec_select:HI (match_dup 2) (parallel [(const_int 9)])))
8461                 (ss_plus:HI
8462                   (vec_select:HI (match_dup 2) (parallel [(const_int 10)]))
8463                   (vec_select:HI (match_dup 2) (parallel [(const_int 11)]))))
8464               (vec_concat:V2HI
8465                 (ss_plus:HI
8466                   (vec_select:HI (match_dup 2) (parallel [(const_int 12)]))
8467                   (vec_select:HI (match_dup 2) (parallel [(const_int 13)])))
8468                 (ss_plus:HI
8469                   (vec_select:HI (match_dup 2) (parallel [(const_int 14)]))
8470                   (vec_select:HI (match_dup 2) (parallel [(const_int 15)]))))))))]
8471   "TARGET_AVX2"
8472   "vphaddsw\t{%2, %1, %0|%0, %1, %2}"
8473   [(set_attr "type" "sseiadd")
8474    (set_attr "prefix_extra" "1")
8475    (set_attr "prefix" "vex")
8476    (set_attr "mode" "OI")])
8477
8478 (define_insn "ssse3_phaddswv8hi3"
8479   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
8480         (vec_concat:V8HI
8481           (vec_concat:V4HI
8482             (vec_concat:V2HI
8483               (ss_plus:HI
8484                 (vec_select:HI
8485                   (match_operand:V8HI 1 "register_operand" "0,x")
8486                   (parallel [(const_int 0)]))
8487                 (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8488               (ss_plus:HI
8489                 (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8490                 (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8491             (vec_concat:V2HI
8492               (ss_plus:HI
8493                 (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8494                 (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8495               (ss_plus:HI
8496                 (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8497                 (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8498           (vec_concat:V4HI
8499             (vec_concat:V2HI
8500               (ss_plus:HI
8501                 (vec_select:HI
8502                   (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
8503                   (parallel [(const_int 0)]))
8504                 (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8505               (ss_plus:HI
8506                 (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8507                 (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8508             (vec_concat:V2HI
8509               (ss_plus:HI
8510                 (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8511                 (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8512               (ss_plus:HI
8513                 (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8514                 (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))))]
8515   "TARGET_SSSE3"
8516   "@
8517    phaddsw\t{%2, %0|%0, %2}
8518    vphaddsw\t{%2, %1, %0|%0, %1, %2}"
8519   [(set_attr "isa" "noavx,avx")
8520    (set_attr "type" "sseiadd")
8521    (set_attr "atom_unit" "complex")
8522    (set_attr "prefix_data16" "1,*")
8523    (set_attr "prefix_extra" "1")
8524    (set_attr "prefix" "orig,vex")
8525    (set_attr "mode" "TI")])
8526
8527 (define_insn "ssse3_phaddswv4hi3"
8528   [(set (match_operand:V4HI 0 "register_operand" "=y")
8529         (vec_concat:V4HI
8530           (vec_concat:V2HI
8531             (ss_plus:HI
8532               (vec_select:HI
8533                 (match_operand:V4HI 1 "register_operand" "0")
8534                 (parallel [(const_int 0)]))
8535               (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8536             (ss_plus:HI
8537               (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8538               (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8539           (vec_concat:V2HI
8540             (ss_plus:HI
8541               (vec_select:HI
8542                 (match_operand:V4HI 2 "nonimmediate_operand" "ym")
8543                 (parallel [(const_int 0)]))
8544               (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8545             (ss_plus:HI
8546               (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8547               (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))))]
8548   "TARGET_SSSE3"
8549   "phaddsw\t{%2, %0|%0, %2}"
8550   [(set_attr "type" "sseiadd")
8551    (set_attr "atom_unit" "complex")
8552    (set_attr "prefix_extra" "1")
8553    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8554    (set_attr "mode" "DI")])
8555
8556 (define_insn "avx2_phsubwv16hi3"
8557   [(set (match_operand:V16HI 0 "register_operand" "=x")
8558         (vec_concat:V16HI
8559           (vec_concat:V8HI
8560             (vec_concat:V4HI
8561               (vec_concat:V2HI
8562                 (minus:HI
8563                   (vec_select:HI
8564                     (match_operand:V16HI 1 "register_operand" "x")
8565                     (parallel [(const_int 0)]))
8566                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8567                 (minus:HI
8568                   (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8569                   (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8570               (vec_concat:V2HI
8571                 (minus:HI
8572                   (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8573                   (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8574                 (minus:HI
8575                   (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8576                   (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8577             (vec_concat:V4HI
8578               (vec_concat:V2HI
8579                 (minus:HI
8580                   (vec_select:HI (match_dup 1) (parallel [(const_int 8)]))
8581                   (vec_select:HI (match_dup 1) (parallel [(const_int 9)])))
8582                 (minus:HI
8583                   (vec_select:HI (match_dup 1) (parallel [(const_int 10)]))
8584                   (vec_select:HI (match_dup 1) (parallel [(const_int 11)]))))
8585               (vec_concat:V2HI
8586                 (minus:HI
8587                   (vec_select:HI (match_dup 1) (parallel [(const_int 12)]))
8588                   (vec_select:HI (match_dup 1) (parallel [(const_int 13)])))
8589                 (minus:HI
8590                   (vec_select:HI (match_dup 1) (parallel [(const_int 14)]))
8591                   (vec_select:HI (match_dup 1) (parallel [(const_int 15)]))))))
8592           (vec_concat:V8HI
8593             (vec_concat:V4HI
8594               (vec_concat:V2HI
8595                 (minus:HI
8596                   (vec_select:HI
8597                     (match_operand:V16HI 2 "nonimmediate_operand" "xm")
8598                     (parallel [(const_int 0)]))
8599                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8600                 (minus:HI
8601                   (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8602                   (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8603               (vec_concat:V2HI
8604                 (minus:HI
8605                   (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8606                   (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8607                 (minus:HI
8608                   (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8609                   (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))
8610             (vec_concat:V4HI
8611               (vec_concat:V2HI
8612                 (minus:HI
8613                   (vec_select:HI (match_dup 2) (parallel [(const_int 8)]))
8614                   (vec_select:HI (match_dup 2) (parallel [(const_int 9)])))
8615                 (minus:HI
8616                   (vec_select:HI (match_dup 2) (parallel [(const_int 10)]))
8617                   (vec_select:HI (match_dup 2) (parallel [(const_int 11)]))))
8618               (vec_concat:V2HI
8619                 (minus:HI
8620                   (vec_select:HI (match_dup 2) (parallel [(const_int 12)]))
8621                   (vec_select:HI (match_dup 2) (parallel [(const_int 13)])))
8622                 (minus:HI
8623                   (vec_select:HI (match_dup 2) (parallel [(const_int 14)]))
8624                   (vec_select:HI (match_dup 2) (parallel [(const_int 15)]))))))))]
8625   "TARGET_AVX2"
8626   "vphsubw\t{%2, %1, %0|%0, %1, %2}"
8627   [(set_attr "type" "sseiadd")
8628    (set_attr "prefix_extra" "1")
8629    (set_attr "prefix" "vex")
8630    (set_attr "mode" "OI")])
8631
8632 (define_insn "ssse3_phsubwv8hi3"
8633   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
8634         (vec_concat:V8HI
8635           (vec_concat:V4HI
8636             (vec_concat:V2HI
8637               (minus:HI
8638                 (vec_select:HI
8639                   (match_operand:V8HI 1 "register_operand" "0,x")
8640                   (parallel [(const_int 0)]))
8641                 (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8642               (minus:HI
8643                 (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8644                 (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8645             (vec_concat:V2HI
8646               (minus:HI
8647                 (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8648                 (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8649               (minus:HI
8650                 (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8651                 (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8652           (vec_concat:V4HI
8653             (vec_concat:V2HI
8654               (minus:HI
8655                 (vec_select:HI
8656                   (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
8657                   (parallel [(const_int 0)]))
8658                 (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8659               (minus:HI
8660                 (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8661                 (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8662             (vec_concat:V2HI
8663               (minus:HI
8664                 (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8665                 (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8666               (minus:HI
8667                 (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8668                 (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))))]
8669   "TARGET_SSSE3"
8670   "@
8671    phsubw\t{%2, %0|%0, %2}
8672    vphsubw\t{%2, %1, %0|%0, %1, %2}"
8673   [(set_attr "isa" "noavx,avx")
8674    (set_attr "type" "sseiadd")
8675    (set_attr "atom_unit" "complex")
8676    (set_attr "prefix_data16" "1,*")
8677    (set_attr "prefix_extra" "1")
8678    (set_attr "prefix" "orig,vex")
8679    (set_attr "mode" "TI")])
8680
8681 (define_insn "ssse3_phsubwv4hi3"
8682   [(set (match_operand:V4HI 0 "register_operand" "=y")
8683         (vec_concat:V4HI
8684           (vec_concat:V2HI
8685             (minus:HI
8686               (vec_select:HI
8687                 (match_operand:V4HI 1 "register_operand" "0")
8688                 (parallel [(const_int 0)]))
8689               (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8690             (minus:HI
8691               (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8692               (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8693           (vec_concat:V2HI
8694             (minus:HI
8695               (vec_select:HI
8696                 (match_operand:V4HI 2 "nonimmediate_operand" "ym")
8697                 (parallel [(const_int 0)]))
8698               (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8699             (minus:HI
8700               (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8701               (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))))]
8702   "TARGET_SSSE3"
8703   "phsubw\t{%2, %0|%0, %2}"
8704   [(set_attr "type" "sseiadd")
8705    (set_attr "atom_unit" "complex")
8706    (set_attr "prefix_extra" "1")
8707    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8708    (set_attr "mode" "DI")])
8709
8710 (define_insn "avx2_phsubdv8si3"
8711   [(set (match_operand:V8SI 0 "register_operand" "=x")
8712         (vec_concat:V8SI
8713           (vec_concat:V4SI
8714             (vec_concat:V2SI
8715               (minus:SI
8716                 (vec_select:SI
8717                   (match_operand:V8SI 1 "register_operand" "x")
8718                   (parallel [(const_int 0)]))
8719                 (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8720               (minus:SI
8721                 (vec_select:SI (match_dup 1) (parallel [(const_int 2)]))
8722                 (vec_select:SI (match_dup 1) (parallel [(const_int 3)]))))
8723             (vec_concat:V2SI
8724               (minus:SI
8725                 (vec_select:SI (match_dup 1) (parallel [(const_int 4)]))
8726                 (vec_select:SI (match_dup 1) (parallel [(const_int 5)])))
8727               (minus:SI
8728                 (vec_select:SI (match_dup 1) (parallel [(const_int 6)]))
8729                 (vec_select:SI (match_dup 1) (parallel [(const_int 7)])))))
8730           (vec_concat:V4SI
8731             (vec_concat:V2SI
8732               (minus:SI
8733                 (vec_select:SI
8734                   (match_operand:V8SI 2 "nonimmediate_operand" "xm")
8735                   (parallel [(const_int 0)]))
8736                 (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))
8737               (minus:SI
8738                 (vec_select:SI (match_dup 2) (parallel [(const_int 2)]))
8739                 (vec_select:SI (match_dup 2) (parallel [(const_int 3)]))))
8740             (vec_concat:V2SI
8741               (minus:SI
8742                 (vec_select:SI (match_dup 2) (parallel [(const_int 4)]))
8743                 (vec_select:SI (match_dup 2) (parallel [(const_int 5)])))
8744               (minus:SI
8745                 (vec_select:SI (match_dup 2) (parallel [(const_int 6)]))
8746                 (vec_select:SI (match_dup 2) (parallel [(const_int 7)])))))))]
8747   "TARGET_AVX2"
8748   "vphsubd\t{%2, %1, %0|%0, %1, %2}"
8749   [(set_attr "type" "sseiadd")
8750    (set_attr "prefix_extra" "1")
8751    (set_attr "prefix" "vex")
8752    (set_attr "mode" "OI")])
8753
8754 (define_insn "ssse3_phsubdv4si3"
8755   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
8756         (vec_concat:V4SI
8757           (vec_concat:V2SI
8758             (minus:SI
8759               (vec_select:SI
8760                 (match_operand:V4SI 1 "register_operand" "0,x")
8761                 (parallel [(const_int 0)]))
8762               (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8763             (minus:SI
8764               (vec_select:SI (match_dup 1) (parallel [(const_int 2)]))
8765               (vec_select:SI (match_dup 1) (parallel [(const_int 3)]))))
8766           (vec_concat:V2SI
8767             (minus:SI
8768               (vec_select:SI
8769                 (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm")
8770                 (parallel [(const_int 0)]))
8771               (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))
8772             (minus:SI
8773               (vec_select:SI (match_dup 2) (parallel [(const_int 2)]))
8774               (vec_select:SI (match_dup 2) (parallel [(const_int 3)]))))))]
8775   "TARGET_SSSE3"
8776   "@
8777    phsubd\t{%2, %0|%0, %2}
8778    vphsubd\t{%2, %1, %0|%0, %1, %2}"
8779
8780   [(set_attr "isa" "noavx,avx")
8781    (set_attr "type" "sseiadd")
8782    (set_attr "atom_unit" "complex")
8783    (set_attr "prefix_data16" "1,*")
8784    (set_attr "prefix_extra" "1")
8785    (set_attr "prefix" "orig,vex")
8786    (set_attr "mode" "TI")])
8787
8788 (define_insn "ssse3_phsubdv2si3"
8789   [(set (match_operand:V2SI 0 "register_operand" "=y")
8790         (vec_concat:V2SI
8791           (minus:SI
8792             (vec_select:SI
8793               (match_operand:V2SI 1 "register_operand" "0")
8794               (parallel [(const_int 0)]))
8795             (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8796           (minus:SI
8797             (vec_select:SI
8798               (match_operand:V2SI 2 "nonimmediate_operand" "ym")
8799               (parallel [(const_int 0)]))
8800             (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))))]
8801   "TARGET_SSSE3"
8802   "phsubd\t{%2, %0|%0, %2}"
8803   [(set_attr "type" "sseiadd")
8804    (set_attr "atom_unit" "complex")
8805    (set_attr "prefix_extra" "1")
8806    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8807    (set_attr "mode" "DI")])
8808
8809 (define_insn "avx2_phsubswv16hi3"
8810   [(set (match_operand:V16HI 0 "register_operand" "=x")
8811         (vec_concat:V16HI
8812           (vec_concat:V8HI
8813             (vec_concat:V4HI
8814               (vec_concat:V2HI
8815                 (ss_minus:HI
8816                   (vec_select:HI
8817                     (match_operand:V16HI 1 "register_operand" "x")
8818                     (parallel [(const_int 0)]))
8819                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8820                 (ss_minus:HI
8821                   (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8822                   (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8823               (vec_concat:V2HI
8824                 (ss_minus:HI
8825                   (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8826                   (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8827                 (ss_minus:HI
8828                   (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8829                   (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8830             (vec_concat:V4HI
8831               (vec_concat:V2HI
8832                 (ss_minus:HI
8833                   (vec_select:HI (match_dup 1) (parallel [(const_int 8)]))
8834                   (vec_select:HI (match_dup 1) (parallel [(const_int 9)])))
8835                 (ss_minus:HI
8836                   (vec_select:HI (match_dup 1) (parallel [(const_int 10)]))
8837                   (vec_select:HI (match_dup 1) (parallel [(const_int 11)]))))
8838               (vec_concat:V2HI
8839                 (ss_minus:HI
8840                   (vec_select:HI (match_dup 1) (parallel [(const_int 12)]))
8841                   (vec_select:HI (match_dup 1) (parallel [(const_int 13)])))
8842                 (ss_minus:HI
8843                   (vec_select:HI (match_dup 1) (parallel [(const_int 14)]))
8844                   (vec_select:HI (match_dup 1) (parallel [(const_int 15)]))))))
8845           (vec_concat:V8HI
8846             (vec_concat:V4HI
8847               (vec_concat:V2HI
8848                 (ss_minus:HI
8849                   (vec_select:HI
8850                     (match_operand:V16HI 2 "nonimmediate_operand" "xm")
8851                     (parallel [(const_int 0)]))
8852                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8853                 (ss_minus:HI
8854                   (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8855                   (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8856               (vec_concat:V2HI
8857                 (ss_minus:HI
8858                   (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8859                   (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8860                 (ss_minus:HI
8861                   (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8862                   (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))
8863             (vec_concat:V4HI
8864               (vec_concat:V2HI
8865                 (ss_minus:HI
8866                   (vec_select:HI (match_dup 2) (parallel [(const_int 8)]))
8867                   (vec_select:HI (match_dup 2) (parallel [(const_int 9)])))
8868                 (ss_minus:HI
8869                   (vec_select:HI (match_dup 2) (parallel [(const_int 10)]))
8870                   (vec_select:HI (match_dup 2) (parallel [(const_int 11)]))))
8871               (vec_concat:V2HI
8872                 (ss_minus:HI
8873                   (vec_select:HI (match_dup 2) (parallel [(const_int 12)]))
8874                   (vec_select:HI (match_dup 2) (parallel [(const_int 13)])))
8875                 (ss_minus:HI
8876                   (vec_select:HI (match_dup 2) (parallel [(const_int 14)]))
8877                   (vec_select:HI (match_dup 2) (parallel [(const_int 15)]))))))))]
8878   "TARGET_AVX2"
8879   "vphsubsw\t{%2, %1, %0|%0, %1, %2}"
8880   [(set_attr "type" "sseiadd")
8881    (set_attr "prefix_extra" "1")
8882    (set_attr "prefix" "vex")
8883    (set_attr "mode" "OI")])
8884
8885 (define_insn "ssse3_phsubswv8hi3"
8886   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
8887         (vec_concat:V8HI
8888           (vec_concat:V4HI
8889             (vec_concat:V2HI
8890               (ss_minus:HI
8891                 (vec_select:HI
8892                   (match_operand:V8HI 1 "register_operand" "0,x")
8893                   (parallel [(const_int 0)]))
8894                 (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8895               (ss_minus:HI
8896                 (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8897                 (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8898             (vec_concat:V2HI
8899               (ss_minus:HI
8900                 (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8901                 (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8902               (ss_minus:HI
8903                 (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8904                 (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8905           (vec_concat:V4HI
8906             (vec_concat:V2HI
8907               (ss_minus:HI
8908                 (vec_select:HI
8909                   (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
8910                   (parallel [(const_int 0)]))
8911                 (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8912               (ss_minus:HI
8913                 (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8914                 (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8915             (vec_concat:V2HI
8916               (ss_minus:HI
8917                 (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8918                 (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8919               (ss_minus:HI
8920                 (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8921                 (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))))]
8922   "TARGET_SSSE3"
8923   "@
8924    phsubsw\t{%2, %0|%0, %2}
8925    vphsubsw\t{%2, %1, %0|%0, %1, %2}"
8926   [(set_attr "isa" "noavx,avx")
8927    (set_attr "type" "sseiadd")
8928    (set_attr "atom_unit" "complex")
8929    (set_attr "prefix_data16" "1,*")
8930    (set_attr "prefix_extra" "1")
8931    (set_attr "prefix" "orig,vex")
8932    (set_attr "mode" "TI")])
8933
8934 (define_insn "ssse3_phsubswv4hi3"
8935   [(set (match_operand:V4HI 0 "register_operand" "=y")
8936         (vec_concat:V4HI
8937           (vec_concat:V2HI
8938             (ss_minus:HI
8939               (vec_select:HI
8940                 (match_operand:V4HI 1 "register_operand" "0")
8941                 (parallel [(const_int 0)]))
8942               (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8943             (ss_minus:HI
8944               (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8945               (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8946           (vec_concat:V2HI
8947             (ss_minus:HI
8948               (vec_select:HI
8949                 (match_operand:V4HI 2 "nonimmediate_operand" "ym")
8950                 (parallel [(const_int 0)]))
8951               (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8952             (ss_minus:HI
8953               (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8954               (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))))]
8955   "TARGET_SSSE3"
8956   "phsubsw\t{%2, %0|%0, %2}"
8957   [(set_attr "type" "sseiadd")
8958    (set_attr "atom_unit" "complex")
8959    (set_attr "prefix_extra" "1")
8960    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8961    (set_attr "mode" "DI")])
8962
8963 (define_insn "avx2_pmaddubsw256"
8964   [(set (match_operand:V16HI 0 "register_operand" "=x")
8965         (ss_plus:V16HI
8966           (mult:V16HI
8967             (zero_extend:V16HI
8968               (vec_select:V16QI
8969                 (match_operand:V32QI 1 "register_operand" "x")
8970                 (parallel [(const_int 0)
8971                            (const_int 2)
8972                            (const_int 4)
8973                            (const_int 6)
8974                            (const_int 8)
8975                            (const_int 10)
8976                            (const_int 12)
8977                            (const_int 14)
8978                            (const_int 16)
8979                            (const_int 18)
8980                            (const_int 20)
8981                            (const_int 22)
8982                            (const_int 24)
8983                            (const_int 26)
8984                            (const_int 28)
8985                            (const_int 30)])))
8986             (sign_extend:V16HI
8987               (vec_select:V16QI
8988                 (match_operand:V32QI 2 "nonimmediate_operand" "xm")
8989                 (parallel [(const_int 0)
8990                            (const_int 2)
8991                            (const_int 4)
8992                            (const_int 6)
8993                            (const_int 8)
8994                            (const_int 10)
8995                            (const_int 12)
8996                            (const_int 14)
8997                            (const_int 16)
8998                            (const_int 18)
8999                            (const_int 20)
9000                            (const_int 22)
9001                            (const_int 24)
9002                            (const_int 26)
9003                            (const_int 28)
9004                            (const_int 30)]))))
9005           (mult:V16HI
9006             (zero_extend:V16HI
9007               (vec_select:V16QI (match_dup 1)
9008                 (parallel [(const_int 1)
9009                            (const_int 3)
9010                            (const_int 5)
9011                            (const_int 7)
9012                            (const_int 9)
9013                            (const_int 11)
9014                            (const_int 13)
9015                            (const_int 15)
9016                            (const_int 17)
9017                            (const_int 19)
9018                            (const_int 21)
9019                            (const_int 23)
9020                            (const_int 25)
9021                            (const_int 27)
9022                            (const_int 29)
9023                            (const_int 31)])))
9024             (sign_extend:V16HI
9025               (vec_select:V16QI (match_dup 2)
9026                 (parallel [(const_int 1)
9027                            (const_int 3)
9028                            (const_int 5)
9029                            (const_int 7)
9030                            (const_int 9)
9031                            (const_int 11)
9032                            (const_int 13)
9033                            (const_int 15)
9034                            (const_int 17)
9035                            (const_int 19)
9036                            (const_int 21)
9037                            (const_int 23)
9038                            (const_int 25)
9039                            (const_int 27)
9040                            (const_int 29)
9041                            (const_int 31)]))))))]
9042   "TARGET_AVX2"
9043   "vpmaddubsw\t{%2, %1, %0|%0, %1, %2}"
9044   [(set_attr "type" "sseiadd")
9045    (set_attr "prefix_extra" "1")
9046    (set_attr "prefix" "vex")
9047    (set_attr "mode" "OI")])
9048
9049 (define_insn "ssse3_pmaddubsw128"
9050   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
9051         (ss_plus:V8HI
9052           (mult:V8HI
9053             (zero_extend:V8HI
9054               (vec_select:V8QI
9055                 (match_operand:V16QI 1 "register_operand" "0,x")
9056                 (parallel [(const_int 0)
9057                            (const_int 2)
9058                            (const_int 4)
9059                            (const_int 6)
9060                            (const_int 8)
9061                            (const_int 10)
9062                            (const_int 12)
9063                            (const_int 14)])))
9064             (sign_extend:V8HI
9065               (vec_select:V8QI
9066                 (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm")
9067                 (parallel [(const_int 0)
9068                            (const_int 2)
9069                            (const_int 4)
9070                            (const_int 6)
9071                            (const_int 8)
9072                            (const_int 10)
9073                            (const_int 12)
9074                            (const_int 14)]))))
9075           (mult:V8HI
9076             (zero_extend:V8HI
9077               (vec_select:V8QI (match_dup 1)
9078                 (parallel [(const_int 1)
9079                            (const_int 3)
9080                            (const_int 5)
9081                            (const_int 7)
9082                            (const_int 9)
9083                            (const_int 11)
9084                            (const_int 13)
9085                            (const_int 15)])))
9086             (sign_extend:V8HI
9087               (vec_select:V8QI (match_dup 2)
9088                 (parallel [(const_int 1)
9089                            (const_int 3)
9090                            (const_int 5)
9091                            (const_int 7)
9092                            (const_int 9)
9093                            (const_int 11)
9094                            (const_int 13)
9095                            (const_int 15)]))))))]
9096   "TARGET_SSSE3"
9097   "@
9098    pmaddubsw\t{%2, %0|%0, %2}
9099    vpmaddubsw\t{%2, %1, %0|%0, %1, %2}"
9100   [(set_attr "isa" "noavx,avx")
9101    (set_attr "type" "sseiadd")
9102    (set_attr "atom_unit" "simul")
9103    (set_attr "prefix_data16" "1,*")
9104    (set_attr "prefix_extra" "1")
9105    (set_attr "prefix" "orig,vex")
9106    (set_attr "mode" "TI")])
9107
9108 (define_insn "ssse3_pmaddubsw"
9109   [(set (match_operand:V4HI 0 "register_operand" "=y")
9110         (ss_plus:V4HI
9111           (mult:V4HI
9112             (zero_extend:V4HI
9113               (vec_select:V4QI
9114                 (match_operand:V8QI 1 "register_operand" "0")
9115                 (parallel [(const_int 0)
9116                            (const_int 2)
9117                            (const_int 4)
9118                            (const_int 6)])))
9119             (sign_extend:V4HI
9120               (vec_select:V4QI
9121                 (match_operand:V8QI 2 "nonimmediate_operand" "ym")
9122                 (parallel [(const_int 0)
9123                            (const_int 2)
9124                            (const_int 4)
9125                            (const_int 6)]))))
9126           (mult:V4HI
9127             (zero_extend:V4HI
9128               (vec_select:V4QI (match_dup 1)
9129                 (parallel [(const_int 1)
9130                            (const_int 3)
9131                            (const_int 5)
9132                            (const_int 7)])))
9133             (sign_extend:V4HI
9134               (vec_select:V4QI (match_dup 2)
9135                 (parallel [(const_int 1)
9136                            (const_int 3)
9137                            (const_int 5)
9138                            (const_int 7)]))))))]
9139   "TARGET_SSSE3"
9140   "pmaddubsw\t{%2, %0|%0, %2}"
9141   [(set_attr "type" "sseiadd")
9142    (set_attr "atom_unit" "simul")
9143    (set_attr "prefix_extra" "1")
9144    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
9145    (set_attr "mode" "DI")])
9146
9147 (define_expand "avx2_umulhrswv16hi3"
9148   [(set (match_operand:V16HI 0 "register_operand" "")
9149         (truncate:V16HI
9150           (lshiftrt:V16SI
9151             (plus:V16SI
9152               (lshiftrt:V16SI
9153                 (mult:V16SI
9154                   (sign_extend:V16SI
9155                     (match_operand:V16HI 1 "nonimmediate_operand" ""))
9156                   (sign_extend:V16SI
9157                     (match_operand:V16HI 2 "nonimmediate_operand" "")))
9158                 (const_int 14))
9159               (const_vector:V16HI [(const_int 1) (const_int 1)
9160                                    (const_int 1) (const_int 1)
9161                                    (const_int 1) (const_int 1)
9162                                    (const_int 1) (const_int 1)
9163                                    (const_int 1) (const_int 1)
9164                                    (const_int 1) (const_int 1)
9165                                    (const_int 1) (const_int 1)
9166                                    (const_int 1) (const_int 1)]))
9167             (const_int 1))))]
9168   "TARGET_AVX2"
9169   "ix86_fixup_binary_operands_no_copy (MULT, V16HImode, operands);")
9170
9171 (define_insn "*avx2_umulhrswv16hi3"
9172   [(set (match_operand:V16HI 0 "register_operand" "=x")
9173         (truncate:V16HI
9174           (lshiftrt:V16SI
9175             (plus:V16SI
9176               (lshiftrt:V16SI
9177                 (mult:V16SI
9178                   (sign_extend:V16SI
9179                     (match_operand:V16HI 1 "nonimmediate_operand" "%x"))
9180                   (sign_extend:V16SI
9181                     (match_operand:V16HI 2 "nonimmediate_operand" "xm")))
9182                 (const_int 14))
9183               (const_vector:V16HI [(const_int 1) (const_int 1)
9184                                    (const_int 1) (const_int 1)
9185                                    (const_int 1) (const_int 1)
9186                                    (const_int 1) (const_int 1)
9187                                    (const_int 1) (const_int 1)
9188                                    (const_int 1) (const_int 1)
9189                                    (const_int 1) (const_int 1)
9190                                    (const_int 1) (const_int 1)]))
9191             (const_int 1))))]
9192   "TARGET_AVX2 && ix86_binary_operator_ok (MULT, V16HImode, operands)"
9193   "vpmulhrsw\t{%2, %1, %0|%0, %1, %2}"
9194   [(set_attr "type" "sseimul")
9195    (set_attr "prefix_extra" "1")
9196    (set_attr "prefix" "vex")
9197    (set_attr "mode" "OI")])
9198
9199 (define_expand "ssse3_pmulhrswv8hi3"
9200   [(set (match_operand:V8HI 0 "register_operand" "")
9201         (truncate:V8HI
9202           (lshiftrt:V8SI
9203             (plus:V8SI
9204               (lshiftrt:V8SI
9205                 (mult:V8SI
9206                   (sign_extend:V8SI
9207                     (match_operand:V8HI 1 "nonimmediate_operand" ""))
9208                   (sign_extend:V8SI
9209                     (match_operand:V8HI 2 "nonimmediate_operand" "")))
9210                 (const_int 14))
9211               (const_vector:V8HI [(const_int 1) (const_int 1)
9212                                   (const_int 1) (const_int 1)
9213                                   (const_int 1) (const_int 1)
9214                                   (const_int 1) (const_int 1)]))
9215             (const_int 1))))]
9216   "TARGET_SSSE3"
9217   "ix86_fixup_binary_operands_no_copy (MULT, V8HImode, operands);")
9218
9219 (define_insn "*ssse3_pmulhrswv8hi3"
9220   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
9221         (truncate:V8HI
9222           (lshiftrt:V8SI
9223             (plus:V8SI
9224               (lshiftrt:V8SI
9225                 (mult:V8SI
9226                   (sign_extend:V8SI
9227                     (match_operand:V8HI 1 "nonimmediate_operand" "%0,x"))
9228                   (sign_extend:V8SI
9229                     (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")))
9230                 (const_int 14))
9231               (const_vector:V8HI [(const_int 1) (const_int 1)
9232                                   (const_int 1) (const_int 1)
9233                                   (const_int 1) (const_int 1)
9234                                   (const_int 1) (const_int 1)]))
9235             (const_int 1))))]
9236   "TARGET_SSSE3 && ix86_binary_operator_ok (MULT, V8HImode, operands)"
9237   "@
9238    pmulhrsw\t{%2, %0|%0, %2}
9239    vpmulhrsw\t{%2, %1, %0|%0, %1, %2}"
9240   [(set_attr "isa" "noavx,avx")
9241    (set_attr "type" "sseimul")
9242    (set_attr "prefix_data16" "1,*")
9243    (set_attr "prefix_extra" "1")
9244    (set_attr "prefix" "orig,vex")
9245    (set_attr "mode" "TI")])
9246
9247 (define_expand "ssse3_pmulhrswv4hi3"
9248   [(set (match_operand:V4HI 0 "register_operand" "")
9249         (truncate:V4HI
9250           (lshiftrt:V4SI
9251             (plus:V4SI
9252               (lshiftrt:V4SI
9253                 (mult:V4SI
9254                   (sign_extend:V4SI
9255                     (match_operand:V4HI 1 "nonimmediate_operand" ""))
9256                   (sign_extend:V4SI
9257                     (match_operand:V4HI 2 "nonimmediate_operand" "")))
9258                 (const_int 14))
9259               (const_vector:V4HI [(const_int 1) (const_int 1)
9260                                   (const_int 1) (const_int 1)]))
9261             (const_int 1))))]
9262   "TARGET_SSSE3"
9263   "ix86_fixup_binary_operands_no_copy (MULT, V4HImode, operands);")
9264
9265 (define_insn "*ssse3_pmulhrswv4hi3"
9266   [(set (match_operand:V4HI 0 "register_operand" "=y")
9267         (truncate:V4HI
9268           (lshiftrt:V4SI
9269             (plus:V4SI
9270               (lshiftrt:V4SI
9271                 (mult:V4SI
9272                   (sign_extend:V4SI
9273                     (match_operand:V4HI 1 "nonimmediate_operand" "%0"))
9274                   (sign_extend:V4SI
9275                     (match_operand:V4HI 2 "nonimmediate_operand" "ym")))
9276                 (const_int 14))
9277               (const_vector:V4HI [(const_int 1) (const_int 1)
9278                                   (const_int 1) (const_int 1)]))
9279             (const_int 1))))]
9280   "TARGET_SSSE3 && ix86_binary_operator_ok (MULT, V4HImode, operands)"
9281   "pmulhrsw\t{%2, %0|%0, %2}"
9282   [(set_attr "type" "sseimul")
9283    (set_attr "prefix_extra" "1")
9284    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
9285    (set_attr "mode" "DI")])
9286
9287 (define_insn "<ssse3_avx2>_pshufb<mode>3"
9288   [(set (match_operand:VI1_AVX2 0 "register_operand" "=x,x")
9289         (unspec:VI1_AVX2 [(match_operand:VI1_AVX2 1 "register_operand" "0,x")
9290                           (match_operand:VI1_AVX2 2 "nonimmediate_operand" "xm,xm")]
9291                          UNSPEC_PSHUFB))]
9292   "TARGET_SSSE3"
9293   "@
9294    pshufb\t{%2, %0|%0, %2}
9295    vpshufb\t{%2, %1, %0|%0, %1, %2}"
9296   [(set_attr "isa" "noavx,avx")
9297    (set_attr "type" "sselog1")
9298    (set_attr "prefix_data16" "1,*")
9299    (set_attr "prefix_extra" "1")
9300    (set_attr "prefix" "orig,vex")
9301    (set_attr "mode" "<sseinsnmode>")])
9302
9303 (define_insn "ssse3_pshufbv8qi3"
9304   [(set (match_operand:V8QI 0 "register_operand" "=y")
9305         (unspec:V8QI [(match_operand:V8QI 1 "register_operand" "0")
9306                       (match_operand:V8QI 2 "nonimmediate_operand" "ym")]
9307                      UNSPEC_PSHUFB))]
9308   "TARGET_SSSE3"
9309   "pshufb\t{%2, %0|%0, %2}";
9310   [(set_attr "type" "sselog1")
9311    (set_attr "prefix_extra" "1")
9312    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
9313    (set_attr "mode" "DI")])
9314
9315 (define_insn "<ssse3_avx2>_psign<mode>3"
9316   [(set (match_operand:VI124_AVX2 0 "register_operand" "=x,x")
9317         (unspec:VI124_AVX2
9318           [(match_operand:VI124_AVX2 1 "register_operand" "0,x")
9319            (match_operand:VI124_AVX2 2 "nonimmediate_operand" "xm,xm")]
9320           UNSPEC_PSIGN))]
9321   "TARGET_SSSE3"
9322   "@
9323    psign<ssemodesuffix>\t{%2, %0|%0, %2}
9324    vpsign<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
9325   [(set_attr "isa" "noavx,avx")
9326    (set_attr "type" "sselog1")
9327    (set_attr "prefix_data16" "1,*")
9328    (set_attr "prefix_extra" "1")
9329    (set_attr "prefix" "orig,vex")
9330    (set_attr "mode" "<sseinsnmode>")])
9331
9332 (define_insn "ssse3_psign<mode>3"
9333   [(set (match_operand:MMXMODEI 0 "register_operand" "=y")
9334         (unspec:MMXMODEI
9335           [(match_operand:MMXMODEI 1 "register_operand" "0")
9336            (match_operand:MMXMODEI 2 "nonimmediate_operand" "ym")]
9337           UNSPEC_PSIGN))]
9338   "TARGET_SSSE3"
9339   "psign<mmxvecsize>\t{%2, %0|%0, %2}";
9340   [(set_attr "type" "sselog1")
9341    (set_attr "prefix_extra" "1")
9342    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
9343    (set_attr "mode" "DI")])
9344
9345 (define_insn "<ssse3_avx2>_palignr<mode>"
9346   [(set (match_operand:SSESCALARMODE 0 "register_operand" "=x,x")
9347         (unspec:SSESCALARMODE [(match_operand:SSESCALARMODE 1 "register_operand" "0,x")
9348                                (match_operand:SSESCALARMODE 2 "nonimmediate_operand" "xm,xm")
9349                                (match_operand:SI 3 "const_0_to_255_mul_8_operand" "n,n")]
9350                               UNSPEC_PALIGNR))]
9351   "TARGET_SSSE3"
9352 {
9353   operands[3] = GEN_INT (INTVAL (operands[3]) / 8);
9354
9355   switch (which_alternative)
9356     {
9357     case 0:
9358       return "palignr\t{%3, %2, %0|%0, %2, %3}";
9359     case 1:
9360       return "vpalignr\t{%3, %2, %1, %0|%0, %1, %2, %3}";
9361     default:
9362       gcc_unreachable ();
9363     }
9364 }
9365   [(set_attr "isa" "noavx,avx")
9366    (set_attr "type" "sseishft")
9367    (set_attr "atom_unit" "sishuf")
9368    (set_attr "prefix_data16" "1,*")
9369    (set_attr "prefix_extra" "1")
9370    (set_attr "length_immediate" "1")
9371    (set_attr "prefix" "orig,vex")
9372    (set_attr "mode" "<sseinsnmode>")])
9373
9374 (define_insn "ssse3_palignrdi"
9375   [(set (match_operand:DI 0 "register_operand" "=y")
9376         (unspec:DI [(match_operand:DI 1 "register_operand" "0")
9377                     (match_operand:DI 2 "nonimmediate_operand" "ym")
9378                     (match_operand:SI 3 "const_0_to_255_mul_8_operand" "n")]
9379                    UNSPEC_PALIGNR))]
9380   "TARGET_SSSE3"
9381 {
9382   operands[3] = GEN_INT (INTVAL (operands[3]) / 8);
9383   return "palignr\t{%3, %2, %0|%0, %2, %3}";
9384 }
9385   [(set_attr "type" "sseishft")
9386    (set_attr "atom_unit" "sishuf")
9387    (set_attr "prefix_extra" "1")
9388    (set_attr "length_immediate" "1")
9389    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
9390    (set_attr "mode" "DI")])
9391
9392 (define_insn "abs<mode>2"
9393   [(set (match_operand:VI124_AVX2 0 "register_operand" "=x")
9394         (abs:VI124_AVX2
9395           (match_operand:VI124_AVX2 1 "nonimmediate_operand" "xm")))]
9396   "TARGET_SSSE3"
9397   "%vpabs<ssemodesuffix>\t{%1, %0|%0, %1}"
9398   [(set_attr "type" "sselog1")
9399    (set_attr "prefix_data16" "1")
9400    (set_attr "prefix_extra" "1")
9401    (set_attr "prefix" "maybe_vex")
9402    (set_attr "mode" "<sseinsnmode>")])
9403
9404 (define_insn "abs<mode>2"
9405   [(set (match_operand:MMXMODEI 0 "register_operand" "=y")
9406         (abs:MMXMODEI
9407           (match_operand:MMXMODEI 1 "nonimmediate_operand" "ym")))]
9408   "TARGET_SSSE3"
9409   "pabs<mmxvecsize>\t{%1, %0|%0, %1}";
9410   [(set_attr "type" "sselog1")
9411    (set_attr "prefix_rep" "0")
9412    (set_attr "prefix_extra" "1")
9413    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
9414    (set_attr "mode" "DI")])
9415
9416 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9417 ;;
9418 ;; AMD SSE4A instructions
9419 ;;
9420 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9421
9422 (define_insn "sse4a_movnt<mode>"
9423   [(set (match_operand:MODEF 0 "memory_operand" "=m")
9424         (unspec:MODEF
9425           [(match_operand:MODEF 1 "register_operand" "x")]
9426           UNSPEC_MOVNT))]
9427   "TARGET_SSE4A"
9428   "movnt<ssemodesuffix>\t{%1, %0|%0, %1}"
9429   [(set_attr "type" "ssemov")
9430    (set_attr "mode" "<MODE>")])
9431
9432 (define_insn "sse4a_vmmovnt<mode>"
9433   [(set (match_operand:<ssescalarmode> 0 "memory_operand" "=m")
9434         (unspec:<ssescalarmode>
9435           [(vec_select:<ssescalarmode>
9436              (match_operand:VF_128 1 "register_operand" "x")
9437              (parallel [(const_int 0)]))]
9438           UNSPEC_MOVNT))]
9439   "TARGET_SSE4A"
9440   "movnt<ssescalarmodesuffix>\t{%1, %0|%0, %1}"
9441   [(set_attr "type" "ssemov")
9442    (set_attr "mode" "<ssescalarmode>")])
9443
9444 (define_insn "sse4a_extrqi"
9445   [(set (match_operand:V2DI 0 "register_operand" "=x")
9446         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
9447                       (match_operand 2 "const_0_to_255_operand" "")
9448                       (match_operand 3 "const_0_to_255_operand" "")]
9449                      UNSPEC_EXTRQI))]
9450   "TARGET_SSE4A"
9451   "extrq\t{%3, %2, %0|%0, %2, %3}"
9452   [(set_attr "type" "sse")
9453    (set_attr "prefix_data16" "1")
9454    (set_attr "length_immediate" "2")
9455    (set_attr "mode" "TI")])
9456
9457 (define_insn "sse4a_extrq"
9458   [(set (match_operand:V2DI 0 "register_operand" "=x")
9459         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
9460                       (match_operand:V16QI 2 "register_operand" "x")]
9461                      UNSPEC_EXTRQ))]
9462   "TARGET_SSE4A"
9463   "extrq\t{%2, %0|%0, %2}"
9464   [(set_attr "type" "sse")
9465    (set_attr "prefix_data16" "1")
9466    (set_attr "mode" "TI")])
9467
9468 (define_insn "sse4a_insertqi"
9469   [(set (match_operand:V2DI 0 "register_operand" "=x")
9470         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
9471                       (match_operand:V2DI 2 "register_operand" "x")
9472                       (match_operand 3 "const_0_to_255_operand" "")
9473                       (match_operand 4 "const_0_to_255_operand" "")]
9474                      UNSPEC_INSERTQI))]
9475   "TARGET_SSE4A"
9476   "insertq\t{%4, %3, %2, %0|%0, %2, %3, %4}"
9477   [(set_attr "type" "sseins")
9478    (set_attr "prefix_data16" "0")
9479    (set_attr "prefix_rep" "1")
9480    (set_attr "length_immediate" "2")
9481    (set_attr "mode" "TI")])
9482
9483 (define_insn "sse4a_insertq"
9484   [(set (match_operand:V2DI 0 "register_operand" "=x")
9485         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
9486                       (match_operand:V2DI 2 "register_operand" "x")]
9487                      UNSPEC_INSERTQ))]
9488   "TARGET_SSE4A"
9489   "insertq\t{%2, %0|%0, %2}"
9490   [(set_attr "type" "sseins")
9491    (set_attr "prefix_data16" "0")
9492    (set_attr "prefix_rep" "1")
9493    (set_attr "mode" "TI")])
9494
9495 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9496 ;;
9497 ;; Intel SSE4.1 instructions
9498 ;;
9499 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9500
9501 (define_insn "<sse4_1>_blend<ssemodesuffix><avxsizesuffix>"
9502   [(set (match_operand:VF 0 "register_operand" "=x,x")
9503         (vec_merge:VF
9504           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")
9505           (match_operand:VF 1 "register_operand" "0,x")
9506           (match_operand:SI 3 "const_0_to_<blendbits>_operand" "")))]
9507   "TARGET_SSE4_1"
9508   "@
9509    blend<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
9510    vblend<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9511   [(set_attr "isa" "noavx,avx")
9512    (set_attr "type" "ssemov")
9513    (set_attr "length_immediate" "1")
9514    (set_attr "prefix_data16" "1,*")
9515    (set_attr "prefix_extra" "1")
9516    (set_attr "prefix" "orig,vex")
9517    (set_attr "mode" "<MODE>")])
9518
9519 (define_insn "<sse4_1>_blendv<ssemodesuffix><avxsizesuffix>"
9520   [(set (match_operand:VF 0 "reg_not_xmm0_operand_maybe_avx" "=x,x")
9521         (unspec:VF
9522           [(match_operand:VF 1 "reg_not_xmm0_operand_maybe_avx" "0,x")
9523            (match_operand:VF 2 "nonimm_not_xmm0_operand_maybe_avx" "xm,xm")
9524            (match_operand:VF 3 "register_operand" "Yz,x")]
9525           UNSPEC_BLENDV))]
9526   "TARGET_SSE4_1"
9527   "@
9528    blendv<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
9529    vblendv<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9530   [(set_attr "isa" "noavx,avx")
9531    (set_attr "type" "ssemov")
9532    (set_attr "length_immediate" "1")
9533    (set_attr "prefix_data16" "1,*")
9534    (set_attr "prefix_extra" "1")
9535    (set_attr "prefix" "orig,vex")
9536    (set_attr "mode" "<MODE>")])
9537
9538 (define_insn "<sse4_1>_dp<ssemodesuffix><avxsizesuffix>"
9539   [(set (match_operand:VF 0 "register_operand" "=x,x")
9540         (unspec:VF
9541           [(match_operand:VF 1 "nonimmediate_operand" "%0,x")
9542            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")
9543            (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
9544           UNSPEC_DP))]
9545   "TARGET_SSE4_1"
9546   "@
9547    dp<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
9548    vdp<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9549   [(set_attr "isa" "noavx,avx")
9550    (set_attr "type" "ssemul")
9551    (set_attr "length_immediate" "1")
9552    (set_attr "prefix_data16" "1,*")
9553    (set_attr "prefix_extra" "1")
9554    (set_attr "prefix" "orig,vex")
9555    (set_attr "mode" "<MODE>")])
9556
9557 (define_insn "<sse4_1_avx2>_movntdqa"
9558   [(set (match_operand:VI8_AVX2 0 "register_operand" "=x")
9559         (unspec:VI8_AVX2 [(match_operand:VI8_AVX2 1 "memory_operand" "m")]
9560                      UNSPEC_MOVNTDQA))]
9561   "TARGET_SSE4_1"
9562   "%vmovntdqa\t{%1, %0|%0, %1}"
9563   [(set_attr "type" "ssemov")
9564    (set_attr "prefix_extra" "1")
9565    (set_attr "prefix" "maybe_vex")
9566    (set_attr "mode" "<sseinsnmode>")])
9567
9568 (define_insn "<sse4_1_avx2>_mpsadbw"
9569   [(set (match_operand:VI1_AVX2 0 "register_operand" "=x,x")
9570         (unspec:VI1_AVX2 [(match_operand:VI1_AVX2 1 "register_operand" "0,x")
9571                           (match_operand:VI1_AVX2 2 "nonimmediate_operand" "xm,xm")
9572                           (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
9573                          UNSPEC_MPSADBW))]
9574   "TARGET_SSE4_1"
9575   "@
9576    mpsadbw\t{%3, %2, %0|%0, %2, %3}
9577    vmpsadbw\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9578   [(set_attr "isa" "noavx,avx")
9579    (set_attr "type" "sselog1")
9580    (set_attr "length_immediate" "1")
9581    (set_attr "prefix_extra" "1")
9582    (set_attr "prefix" "orig,vex")
9583    (set_attr "mode" "<sseinsnmode>")])
9584
9585 (define_insn "avx2_packusdw"
9586   [(set (match_operand:V16HI 0 "register_operand" "=x")
9587         (vec_concat:V16HI
9588           (us_truncate:V8HI
9589             (match_operand:V8SI 1 "register_operand" "x"))
9590           (us_truncate:V8HI
9591             (match_operand:V8SI 2 "nonimmediate_operand" "xm"))))]
9592   "TARGET_AVX2"
9593   "vpackusdw\t{%2, %1, %0|%0, %1, %2}"
9594   [(set_attr "type" "sselog")
9595    (set_attr "prefix_extra" "1")
9596    (set_attr "prefix" "vex")
9597    (set_attr "mode" "OI")])
9598
9599 (define_insn "sse4_1_packusdw"
9600   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
9601         (vec_concat:V8HI
9602           (us_truncate:V4HI
9603             (match_operand:V4SI 1 "register_operand" "0,x"))
9604           (us_truncate:V4HI
9605             (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm"))))]
9606   "TARGET_SSE4_1"
9607   "@
9608    packusdw\t{%2, %0|%0, %2}
9609    vpackusdw\t{%2, %1, %0|%0, %1, %2}"
9610   [(set_attr "isa" "noavx,avx")
9611    (set_attr "type" "sselog")
9612    (set_attr "prefix_extra" "1")
9613    (set_attr "prefix" "orig,vex")
9614    (set_attr "mode" "TI")])
9615
9616 (define_insn "<sse4_1_avx2>_pblendvb"
9617   [(set (match_operand:VI1_AVX2 0 "reg_not_xmm0_operand" "=x,x")
9618         (unspec:VI1_AVX2
9619           [(match_operand:VI1_AVX2 1 "reg_not_xmm0_operand_maybe_avx"  "0,x")
9620            (match_operand:VI1_AVX2 2 "nonimm_not_xmm0_operand_maybe_avx" "xm,xm")
9621            (match_operand:VI1_AVX2 3 "register_operand" "Yz,x")]
9622           UNSPEC_BLENDV))]
9623   "TARGET_SSE4_1"
9624   "@
9625    pblendvb\t{%3, %2, %0|%0, %2, %3}
9626    vpblendvb\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9627   [(set_attr "isa" "noavx,avx")
9628    (set_attr "type" "ssemov")
9629    (set_attr "prefix_extra" "1")
9630    (set_attr "length_immediate" "*,1")
9631    (set_attr "prefix" "orig,vex")
9632    (set_attr "mode" "<sseinsnmode>")])
9633
9634 (define_insn "sse4_1_pblendw"
9635   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
9636         (vec_merge:V8HI
9637           (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
9638           (match_operand:V8HI 1 "register_operand" "0,x")
9639           (match_operand:SI 3 "const_0_to_255_operand" "n,n")))]
9640   "TARGET_SSE4_1"
9641   "@
9642    pblendw\t{%3, %2, %0|%0, %2, %3}
9643    vpblendw\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9644   [(set_attr "isa" "noavx,avx")
9645    (set_attr "type" "ssemov")
9646    (set_attr "prefix_extra" "1")
9647    (set_attr "length_immediate" "1")
9648    (set_attr "prefix" "orig,vex")
9649    (set_attr "mode" "TI")])
9650
9651 ;; The builtin uses an 8-bit immediate.  Expand that.
9652 (define_expand "avx2_pblendw"
9653   [(set (match_operand:V16HI 0 "register_operand" "")
9654         (vec_merge:V16HI
9655           (match_operand:V16HI 2 "nonimmediate_operand" "")
9656           (match_operand:V16HI 1 "register_operand" "")
9657           (match_operand:SI 3 "const_0_to_255_operand" "")))]
9658   "TARGET_AVX2"
9659 {
9660   HOST_WIDE_INT val = INTVAL (operands[3]) & 0xff;
9661   operands[3] = GEN_INT (val << 8 | val);
9662 })
9663
9664 (define_insn "*avx2_pblendw"
9665   [(set (match_operand:V16HI 0 "register_operand" "=x")
9666         (vec_merge:V16HI
9667           (match_operand:V16HI 2 "nonimmediate_operand" "xm")
9668           (match_operand:V16HI 1 "register_operand" "x")
9669           (match_operand:SI 3 "avx2_pblendw_operand" "n")))]
9670   "TARGET_AVX2"
9671 {
9672   operands[3] = GEN_INT (INTVAL (operands[3]) & 0xff);
9673   return "vpblendw\t{%3, %2, %1, %0|%0, %1, %2, %3}";
9674 }
9675   [(set_attr "type" "ssemov")
9676    (set_attr "prefix_extra" "1")
9677    (set_attr "length_immediate" "1")
9678    (set_attr "prefix" "vex")
9679    (set_attr "mode" "OI")])
9680
9681 (define_insn "avx2_pblendd<mode>"
9682   [(set (match_operand:VI4_AVX2 0 "register_operand" "=x")
9683         (vec_merge:VI4_AVX2
9684           (match_operand:VI4_AVX2 2 "nonimmediate_operand" "xm")
9685           (match_operand:VI4_AVX2 1 "register_operand" "x")
9686           (match_operand:SI 3 "const_0_to_255_operand" "n")))]
9687   "TARGET_AVX2"
9688   "vpblendd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9689   [(set_attr "type" "ssemov")
9690    (set_attr "prefix_extra" "1")
9691    (set_attr "length_immediate" "1")
9692    (set_attr "prefix" "vex")
9693    (set_attr "mode" "<sseinsnmode>")])
9694
9695 (define_insn "sse4_1_phminposuw"
9696   [(set (match_operand:V8HI 0 "register_operand" "=x")
9697         (unspec:V8HI [(match_operand:V8HI 1 "nonimmediate_operand" "xm")]
9698                      UNSPEC_PHMINPOSUW))]
9699   "TARGET_SSE4_1"
9700   "%vphminposuw\t{%1, %0|%0, %1}"
9701   [(set_attr "type" "sselog1")
9702    (set_attr "prefix_extra" "1")
9703    (set_attr "prefix" "maybe_vex")
9704    (set_attr "mode" "TI")])
9705
9706 (define_insn "avx2_<code>v16qiv16hi2"
9707   [(set (match_operand:V16HI 0 "register_operand" "=x")
9708         (any_extend:V16HI
9709           (match_operand:V16QI 1 "nonimmediate_operand" "xm")))]
9710   "TARGET_AVX2"
9711   "vpmov<extsuffix>bw\t{%1, %0|%0, %1}"
9712   [(set_attr "type" "ssemov")
9713    (set_attr "prefix_extra" "1")
9714    (set_attr "prefix" "vex")
9715    (set_attr "mode" "OI")])
9716
9717 (define_insn "sse4_1_<code>v8qiv8hi2"
9718   [(set (match_operand:V8HI 0 "register_operand" "=x")
9719         (any_extend:V8HI
9720           (vec_select:V8QI
9721             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9722             (parallel [(const_int 0)
9723                        (const_int 1)
9724                        (const_int 2)
9725                        (const_int 3)
9726                        (const_int 4)
9727                        (const_int 5)
9728                        (const_int 6)
9729                        (const_int 7)]))))]
9730   "TARGET_SSE4_1"
9731   "%vpmov<extsuffix>bw\t{%1, %0|%0, %q1}"
9732   [(set_attr "type" "ssemov")
9733    (set_attr "prefix_extra" "1")
9734    (set_attr "prefix" "maybe_vex")
9735    (set_attr "mode" "TI")])
9736
9737 (define_insn "avx2_<code>v8qiv8si2"
9738   [(set (match_operand:V8SI 0 "register_operand" "=x")
9739         (any_extend:V8SI
9740           (vec_select:V8QI
9741             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9742             (parallel [(const_int 0)
9743                        (const_int 1)
9744                        (const_int 2)
9745                        (const_int 3)
9746                        (const_int 4)
9747                        (const_int 5)
9748                        (const_int 6)
9749                        (const_int 7)]))))]
9750   "TARGET_AVX2"
9751   "vpmov<extsuffix>bd\t{%1, %0|%0, %q1}"
9752   [(set_attr "type" "ssemov")
9753    (set_attr "prefix_extra" "1")
9754    (set_attr "prefix" "vex")
9755    (set_attr "mode" "OI")])
9756
9757 (define_insn "sse4_1_<code>v4qiv4si2"
9758   [(set (match_operand:V4SI 0 "register_operand" "=x")
9759         (any_extend:V4SI
9760           (vec_select:V4QI
9761             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9762             (parallel [(const_int 0)
9763                        (const_int 1)
9764                        (const_int 2)
9765                        (const_int 3)]))))]
9766   "TARGET_SSE4_1"
9767   "%vpmov<extsuffix>bd\t{%1, %0|%0, %k1}"
9768   [(set_attr "type" "ssemov")
9769    (set_attr "prefix_extra" "1")
9770    (set_attr "prefix" "maybe_vex")
9771    (set_attr "mode" "TI")])
9772
9773 (define_insn "avx2_<code>v8hiv8si2"
9774   [(set (match_operand:V8SI 0 "register_operand" "=x")
9775         (any_extend:V8SI
9776             (match_operand:V8HI 1 "nonimmediate_operand" "xm")))]
9777   "TARGET_AVX2"
9778   "vpmov<extsuffix>wd\t{%1, %0|%0, %1}"
9779   [(set_attr "type" "ssemov")
9780    (set_attr "prefix_extra" "1")
9781    (set_attr "prefix" "vex")
9782    (set_attr "mode" "OI")])
9783
9784 (define_insn "sse4_1_<code>v4hiv4si2"
9785   [(set (match_operand:V4SI 0 "register_operand" "=x")
9786         (any_extend:V4SI
9787           (vec_select:V4HI
9788             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
9789             (parallel [(const_int 0)
9790                        (const_int 1)
9791                        (const_int 2)
9792                        (const_int 3)]))))]
9793   "TARGET_SSE4_1"
9794   "%vpmov<extsuffix>wd\t{%1, %0|%0, %q1}"
9795   [(set_attr "type" "ssemov")
9796    (set_attr "prefix_extra" "1")
9797    (set_attr "prefix" "maybe_vex")
9798    (set_attr "mode" "TI")])
9799
9800 (define_insn "avx2_<code>v4qiv4di2"
9801   [(set (match_operand:V4DI 0 "register_operand" "=x")
9802         (any_extend:V4DI
9803           (vec_select:V4QI
9804             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9805             (parallel [(const_int 0)
9806                        (const_int 1)
9807                        (const_int 2)
9808                        (const_int 3)]))))]
9809   "TARGET_AVX2"
9810   "vpmov<extsuffix>bq\t{%1, %0|%0, %k1}"
9811   [(set_attr "type" "ssemov")
9812    (set_attr "prefix_extra" "1")
9813    (set_attr "prefix" "vex")
9814    (set_attr "mode" "OI")])
9815
9816 (define_insn "sse4_1_<code>v2qiv2di2"
9817   [(set (match_operand:V2DI 0 "register_operand" "=x")
9818         (any_extend:V2DI
9819           (vec_select:V2QI
9820             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9821             (parallel [(const_int 0)
9822                        (const_int 1)]))))]
9823   "TARGET_SSE4_1"
9824   "%vpmov<extsuffix>bq\t{%1, %0|%0, %w1}"
9825   [(set_attr "type" "ssemov")
9826    (set_attr "prefix_extra" "1")
9827    (set_attr "prefix" "maybe_vex")
9828    (set_attr "mode" "TI")])
9829
9830 (define_insn "avx2_<code>v4hiv4di2"
9831   [(set (match_operand:V4DI 0 "register_operand" "=x")
9832         (any_extend:V4DI
9833           (vec_select:V4HI
9834             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
9835             (parallel [(const_int 0)
9836                        (const_int 1)
9837                        (const_int 2)
9838                        (const_int 3)]))))]
9839   "TARGET_AVX2"
9840   "vpmov<extsuffix>wq\t{%1, %0|%0, %q1}"
9841   [(set_attr "type" "ssemov")
9842    (set_attr "prefix_extra" "1")
9843    (set_attr "prefix" "vex")
9844    (set_attr "mode" "OI")])
9845
9846 (define_insn "sse4_1_<code>v2hiv2di2"
9847   [(set (match_operand:V2DI 0 "register_operand" "=x")
9848         (any_extend:V2DI
9849           (vec_select:V2HI
9850             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
9851             (parallel [(const_int 0)
9852                        (const_int 1)]))))]
9853   "TARGET_SSE4_1"
9854   "%vpmov<extsuffix>wq\t{%1, %0|%0, %k1}"
9855   [(set_attr "type" "ssemov")
9856    (set_attr "prefix_extra" "1")
9857    (set_attr "prefix" "maybe_vex")
9858    (set_attr "mode" "TI")])
9859
9860 (define_insn "avx2_<code>v4siv4di2"
9861   [(set (match_operand:V4DI 0 "register_operand" "=x")
9862         (any_extend:V4DI
9863             (match_operand:V4SI 1 "nonimmediate_operand" "xm")))]
9864   "TARGET_AVX2"
9865   "vpmov<extsuffix>dq\t{%1, %0|%0, %1}"
9866   [(set_attr "type" "ssemov")
9867    (set_attr "prefix_extra" "1")
9868    (set_attr "mode" "OI")])
9869
9870 (define_insn "sse4_1_<code>v2siv2di2"
9871   [(set (match_operand:V2DI 0 "register_operand" "=x")
9872         (any_extend:V2DI
9873           (vec_select:V2SI
9874             (match_operand:V4SI 1 "nonimmediate_operand" "xm")
9875             (parallel [(const_int 0)
9876                        (const_int 1)]))))]
9877   "TARGET_SSE4_1"
9878   "%vpmov<extsuffix>dq\t{%1, %0|%0, %q1}"
9879   [(set_attr "type" "ssemov")
9880    (set_attr "prefix_extra" "1")
9881    (set_attr "prefix" "maybe_vex")
9882    (set_attr "mode" "TI")])
9883
9884 ;; ptestps/ptestpd are very similar to comiss and ucomiss when
9885 ;; setting FLAGS_REG. But it is not a really compare instruction.
9886 (define_insn "avx_vtest<ssemodesuffix><avxsizesuffix>"
9887   [(set (reg:CC FLAGS_REG)
9888         (unspec:CC [(match_operand:VF 0 "register_operand" "x")
9889                     (match_operand:VF 1 "nonimmediate_operand" "xm")]
9890                    UNSPEC_VTESTP))]
9891   "TARGET_AVX"
9892   "vtest<ssemodesuffix>\t{%1, %0|%0, %1}"
9893   [(set_attr "type" "ssecomi")
9894    (set_attr "prefix_extra" "1")
9895    (set_attr "prefix" "vex")
9896    (set_attr "mode" "<MODE>")])
9897
9898 ;; ptest is very similar to comiss and ucomiss when setting FLAGS_REG.
9899 ;; But it is not a really compare instruction.
9900 (define_insn "avx_ptest256"
9901   [(set (reg:CC FLAGS_REG)
9902         (unspec:CC [(match_operand:V4DI 0 "register_operand" "x")
9903                     (match_operand:V4DI 1 "nonimmediate_operand" "xm")]
9904                    UNSPEC_PTEST))]
9905   "TARGET_AVX"
9906   "vptest\t{%1, %0|%0, %1}"
9907   [(set_attr "type" "ssecomi")
9908    (set_attr "prefix_extra" "1")
9909    (set_attr "prefix" "vex")
9910    (set_attr "mode" "OI")])
9911
9912 (define_insn "sse4_1_ptest"
9913   [(set (reg:CC FLAGS_REG)
9914         (unspec:CC [(match_operand:V2DI 0 "register_operand" "x")
9915                     (match_operand:V2DI 1 "nonimmediate_operand" "xm")]
9916                    UNSPEC_PTEST))]
9917   "TARGET_SSE4_1"
9918   "%vptest\t{%1, %0|%0, %1}"
9919   [(set_attr "type" "ssecomi")
9920    (set_attr "prefix_extra" "1")
9921    (set_attr "prefix" "maybe_vex")
9922    (set_attr "mode" "TI")])
9923
9924 (define_insn "<sse4_1>_round<ssemodesuffix><avxsizesuffix>"
9925   [(set (match_operand:VF 0 "register_operand" "=x")
9926         (unspec:VF
9927           [(match_operand:VF 1 "nonimmediate_operand" "xm")
9928            (match_operand:SI 2 "const_0_to_15_operand" "n")]
9929           UNSPEC_ROUND))]
9930   "TARGET_ROUND"
9931   "%vround<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
9932   [(set_attr "type" "ssecvt")
9933    (set (attr "prefix_data16")
9934      (if_then_else
9935        (match_test "TARGET_AVX")
9936      (const_string "*")
9937      (const_string "1")))
9938    (set_attr "prefix_extra" "1")
9939    (set_attr "length_immediate" "1")
9940    (set_attr "prefix" "maybe_vex")
9941    (set_attr "mode" "<MODE>")])
9942
9943 (define_insn "sse4_1_round<ssescalarmodesuffix>"
9944   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
9945         (vec_merge:VF_128
9946           (unspec:VF_128
9947             [(match_operand:VF_128 2 "register_operand" "x,x")
9948              (match_operand:SI 3 "const_0_to_15_operand" "n,n")]
9949             UNSPEC_ROUND)
9950           (match_operand:VF_128 1 "register_operand" "0,x")
9951           (const_int 1)))]
9952   "TARGET_ROUND"
9953   "@
9954    round<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}
9955    vround<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9956   [(set_attr "isa" "noavx,avx")
9957    (set_attr "type" "ssecvt")
9958    (set_attr "length_immediate" "1")
9959    (set_attr "prefix_data16" "1,*")
9960    (set_attr "prefix_extra" "1")
9961    (set_attr "prefix" "orig,vex")
9962    (set_attr "mode" "<MODE>")])
9963
9964 (define_expand "round<mode>2"
9965   [(set (match_dup 4)
9966         (plus:VF
9967           (match_operand:VF 1 "nonimmediate_operand" "")
9968           (match_dup 3)))
9969    (set (match_operand:VF 0 "register_operand" "")
9970         (unspec:VF
9971           [(match_dup 4) (match_dup 5)]
9972           UNSPEC_ROUND))]
9973   "TARGET_ROUND && !flag_trapping_math"
9974 {
9975   enum machine_mode scalar_mode;
9976   const struct real_format *fmt;
9977   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
9978   rtx half, vec_half;
9979
9980   scalar_mode = GET_MODE_INNER (<MODE>mode);
9981
9982   /* load nextafter (0.5, 0.0) */
9983   fmt = REAL_MODE_FORMAT (scalar_mode);
9984   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, scalar_mode);
9985   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
9986   half = const_double_from_real_value (pred_half, scalar_mode);
9987
9988   vec_half = ix86_build_const_vector (<MODE>mode, true, half);
9989   vec_half = force_reg (<MODE>mode, vec_half);
9990
9991   operands[3] = gen_reg_rtx (<MODE>mode);
9992   emit_insn (gen_copysign<mode>3 (operands[3], vec_half, operands[1]));
9993
9994   operands[4] = gen_reg_rtx (<MODE>mode);
9995   operands[5] = GEN_INT (ROUND_TRUNC);
9996 })
9997
9998 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9999 ;;
10000 ;; Intel SSE4.2 string/text processing instructions
10001 ;;
10002 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10003
10004 (define_insn_and_split "sse4_2_pcmpestr"
10005   [(set (match_operand:SI 0 "register_operand" "=c,c")
10006         (unspec:SI
10007           [(match_operand:V16QI 2 "reg_not_xmm0_operand" "x,x")
10008            (match_operand:SI 3 "register_operand" "a,a")
10009            (match_operand:V16QI 4 "nonimm_not_xmm0_operand" "x,m")
10010            (match_operand:SI 5 "register_operand" "d,d")
10011            (match_operand:SI 6 "const_0_to_255_operand" "n,n")]
10012           UNSPEC_PCMPESTR))
10013    (set (match_operand:V16QI 1 "register_operand" "=Yz,Yz")
10014         (unspec:V16QI
10015           [(match_dup 2)
10016            (match_dup 3)
10017            (match_dup 4)
10018            (match_dup 5)
10019            (match_dup 6)]
10020           UNSPEC_PCMPESTR))
10021    (set (reg:CC FLAGS_REG)
10022         (unspec:CC
10023           [(match_dup 2)
10024            (match_dup 3)
10025            (match_dup 4)
10026            (match_dup 5)
10027            (match_dup 6)]
10028           UNSPEC_PCMPESTR))]
10029   "TARGET_SSE4_2
10030    && can_create_pseudo_p ()"
10031   "#"
10032   "&& 1"
10033   [(const_int 0)]
10034 {
10035   int ecx = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[0]));
10036   int xmm0 = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[1]));
10037   int flags = !find_regno_note (curr_insn, REG_UNUSED, FLAGS_REG);
10038
10039   if (ecx)
10040     emit_insn (gen_sse4_2_pcmpestri (operands[0], operands[2],
10041                                      operands[3], operands[4],
10042                                      operands[5], operands[6]));
10043   if (xmm0)
10044     emit_insn (gen_sse4_2_pcmpestrm (operands[1], operands[2],
10045                                      operands[3], operands[4],
10046                                      operands[5], operands[6]));
10047   if (flags && !(ecx || xmm0))
10048     emit_insn (gen_sse4_2_pcmpestr_cconly (NULL, NULL,
10049                                            operands[2], operands[3],
10050                                            operands[4], operands[5],
10051                                            operands[6]));
10052   if (!(flags || ecx || xmm0))
10053     emit_note (NOTE_INSN_DELETED);
10054
10055   DONE;
10056 }
10057   [(set_attr "type" "sselog")
10058    (set_attr "prefix_data16" "1")
10059    (set_attr "prefix_extra" "1")
10060    (set_attr "length_immediate" "1")
10061    (set_attr "memory" "none,load")
10062    (set_attr "mode" "TI")])
10063
10064 (define_insn "sse4_2_pcmpestri"
10065   [(set (match_operand:SI 0 "register_operand" "=c,c")
10066         (unspec:SI
10067           [(match_operand:V16QI 1 "register_operand" "x,x")
10068            (match_operand:SI 2 "register_operand" "a,a")
10069            (match_operand:V16QI 3 "nonimmediate_operand" "x,m")
10070            (match_operand:SI 4 "register_operand" "d,d")
10071            (match_operand:SI 5 "const_0_to_255_operand" "n,n")]
10072           UNSPEC_PCMPESTR))
10073    (set (reg:CC FLAGS_REG)
10074         (unspec:CC
10075           [(match_dup 1)
10076            (match_dup 2)
10077            (match_dup 3)
10078            (match_dup 4)
10079            (match_dup 5)]
10080           UNSPEC_PCMPESTR))]
10081   "TARGET_SSE4_2"
10082   "%vpcmpestri\t{%5, %3, %1|%1, %3, %5}"
10083   [(set_attr "type" "sselog")
10084    (set_attr "prefix_data16" "1")
10085    (set_attr "prefix_extra" "1")
10086    (set_attr "prefix" "maybe_vex")
10087    (set_attr "length_immediate" "1")
10088    (set_attr "memory" "none,load")
10089    (set_attr "mode" "TI")])
10090
10091 (define_insn "sse4_2_pcmpestrm"
10092   [(set (match_operand:V16QI 0 "register_operand" "=Yz,Yz")
10093         (unspec:V16QI
10094           [(match_operand:V16QI 1 "register_operand" "x,x")
10095            (match_operand:SI 2 "register_operand" "a,a")
10096            (match_operand:V16QI 3 "nonimmediate_operand" "x,m")
10097            (match_operand:SI 4 "register_operand" "d,d")
10098            (match_operand:SI 5 "const_0_to_255_operand" "n,n")]
10099           UNSPEC_PCMPESTR))
10100    (set (reg:CC FLAGS_REG)
10101         (unspec:CC
10102           [(match_dup 1)
10103            (match_dup 2)
10104            (match_dup 3)
10105            (match_dup 4)
10106            (match_dup 5)]
10107           UNSPEC_PCMPESTR))]
10108   "TARGET_SSE4_2"
10109   "%vpcmpestrm\t{%5, %3, %1|%1, %3, %5}"
10110   [(set_attr "type" "sselog")
10111    (set_attr "prefix_data16" "1")
10112    (set_attr "prefix_extra" "1")
10113    (set_attr "length_immediate" "1")
10114    (set_attr "prefix" "maybe_vex")
10115    (set_attr "memory" "none,load")
10116    (set_attr "mode" "TI")])
10117
10118 (define_insn "sse4_2_pcmpestr_cconly"
10119   [(set (reg:CC FLAGS_REG)
10120         (unspec:CC
10121           [(match_operand:V16QI 2 "register_operand" "x,x,x,x")
10122            (match_operand:SI 3 "register_operand" "a,a,a,a")
10123            (match_operand:V16QI 4 "nonimmediate_operand" "x,m,x,m")
10124            (match_operand:SI 5 "register_operand" "d,d,d,d")
10125            (match_operand:SI 6 "const_0_to_255_operand" "n,n,n,n")]
10126           UNSPEC_PCMPESTR))
10127    (clobber (match_scratch:V16QI 0 "=Yz,Yz,X,X"))
10128    (clobber (match_scratch:SI    1 "= X, X,c,c"))]
10129   "TARGET_SSE4_2"
10130   "@
10131    %vpcmpestrm\t{%6, %4, %2|%2, %4, %6}
10132    %vpcmpestrm\t{%6, %4, %2|%2, %4, %6}
10133    %vpcmpestri\t{%6, %4, %2|%2, %4, %6}
10134    %vpcmpestri\t{%6, %4, %2|%2, %4, %6}"
10135   [(set_attr "type" "sselog")
10136    (set_attr "prefix_data16" "1")
10137    (set_attr "prefix_extra" "1")
10138    (set_attr "length_immediate" "1")
10139    (set_attr "memory" "none,load,none,load")
10140    (set_attr "prefix" "maybe_vex")
10141    (set_attr "mode" "TI")])
10142
10143 (define_insn_and_split "sse4_2_pcmpistr"
10144   [(set (match_operand:SI 0 "register_operand" "=c,c")
10145         (unspec:SI
10146           [(match_operand:V16QI 2 "reg_not_xmm0_operand" "x,x")
10147            (match_operand:V16QI 3 "nonimm_not_xmm0_operand" "x,m")
10148            (match_operand:SI 4 "const_0_to_255_operand" "n,n")]
10149           UNSPEC_PCMPISTR))
10150    (set (match_operand:V16QI 1 "register_operand" "=Yz,Yz")
10151         (unspec:V16QI
10152           [(match_dup 2)
10153            (match_dup 3)
10154            (match_dup 4)]
10155           UNSPEC_PCMPISTR))
10156    (set (reg:CC FLAGS_REG)
10157         (unspec:CC
10158           [(match_dup 2)
10159            (match_dup 3)
10160            (match_dup 4)]
10161           UNSPEC_PCMPISTR))]
10162   "TARGET_SSE4_2
10163    && can_create_pseudo_p ()"
10164   "#"
10165   "&& 1"
10166   [(const_int 0)]
10167 {
10168   int ecx = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[0]));
10169   int xmm0 = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[1]));
10170   int flags = !find_regno_note (curr_insn, REG_UNUSED, FLAGS_REG);
10171
10172   if (ecx)
10173     emit_insn (gen_sse4_2_pcmpistri (operands[0], operands[2],
10174                                      operands[3], operands[4]));
10175   if (xmm0)
10176     emit_insn (gen_sse4_2_pcmpistrm (operands[1], operands[2],
10177                                      operands[3], operands[4]));
10178   if (flags && !(ecx || xmm0))
10179     emit_insn (gen_sse4_2_pcmpistr_cconly (NULL, NULL,
10180                                            operands[2], operands[3],
10181                                            operands[4]));
10182   if (!(flags || ecx || xmm0))
10183     emit_note (NOTE_INSN_DELETED);
10184
10185   DONE;
10186 }
10187   [(set_attr "type" "sselog")
10188    (set_attr "prefix_data16" "1")
10189    (set_attr "prefix_extra" "1")
10190    (set_attr "length_immediate" "1")
10191    (set_attr "memory" "none,load")
10192    (set_attr "mode" "TI")])
10193
10194 (define_insn "sse4_2_pcmpistri"
10195   [(set (match_operand:SI 0 "register_operand" "=c,c")
10196         (unspec:SI
10197           [(match_operand:V16QI 1 "register_operand" "x,x")
10198            (match_operand:V16QI 2 "nonimmediate_operand" "x,m")
10199            (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
10200           UNSPEC_PCMPISTR))
10201    (set (reg:CC FLAGS_REG)
10202         (unspec:CC
10203           [(match_dup 1)
10204            (match_dup 2)
10205            (match_dup 3)]
10206           UNSPEC_PCMPISTR))]
10207   "TARGET_SSE4_2"
10208   "%vpcmpistri\t{%3, %2, %1|%1, %2, %3}"
10209   [(set_attr "type" "sselog")
10210    (set_attr "prefix_data16" "1")
10211    (set_attr "prefix_extra" "1")
10212    (set_attr "length_immediate" "1")
10213    (set_attr "prefix" "maybe_vex")
10214    (set_attr "memory" "none,load")
10215    (set_attr "mode" "TI")])
10216
10217 (define_insn "sse4_2_pcmpistrm"
10218   [(set (match_operand:V16QI 0 "register_operand" "=Yz,Yz")
10219         (unspec:V16QI
10220           [(match_operand:V16QI 1 "register_operand" "x,x")
10221            (match_operand:V16QI 2 "nonimmediate_operand" "x,m")
10222            (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
10223           UNSPEC_PCMPISTR))
10224    (set (reg:CC FLAGS_REG)
10225         (unspec:CC
10226           [(match_dup 1)
10227            (match_dup 2)
10228            (match_dup 3)]
10229           UNSPEC_PCMPISTR))]
10230   "TARGET_SSE4_2"
10231   "%vpcmpistrm\t{%3, %2, %1|%1, %2, %3}"
10232   [(set_attr "type" "sselog")
10233    (set_attr "prefix_data16" "1")
10234    (set_attr "prefix_extra" "1")
10235    (set_attr "length_immediate" "1")
10236    (set_attr "prefix" "maybe_vex")
10237    (set_attr "memory" "none,load")
10238    (set_attr "mode" "TI")])
10239
10240 (define_insn "sse4_2_pcmpistr_cconly"
10241   [(set (reg:CC FLAGS_REG)
10242         (unspec:CC
10243           [(match_operand:V16QI 2 "register_operand" "x,x,x,x")
10244            (match_operand:V16QI 3 "nonimmediate_operand" "x,m,x,m")
10245            (match_operand:SI 4 "const_0_to_255_operand" "n,n,n,n")]
10246           UNSPEC_PCMPISTR))
10247    (clobber (match_scratch:V16QI 0 "=Yz,Yz,X,X"))
10248    (clobber (match_scratch:SI    1 "= X, X,c,c"))]
10249   "TARGET_SSE4_2"
10250   "@
10251    %vpcmpistrm\t{%4, %3, %2|%2, %3, %4}
10252    %vpcmpistrm\t{%4, %3, %2|%2, %3, %4}
10253    %vpcmpistri\t{%4, %3, %2|%2, %3, %4}
10254    %vpcmpistri\t{%4, %3, %2|%2, %3, %4}"
10255   [(set_attr "type" "sselog")
10256    (set_attr "prefix_data16" "1")
10257    (set_attr "prefix_extra" "1")
10258    (set_attr "length_immediate" "1")
10259    (set_attr "memory" "none,load,none,load")
10260    (set_attr "prefix" "maybe_vex")
10261    (set_attr "mode" "TI")])
10262
10263 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10264 ;;
10265 ;; XOP instructions
10266 ;;
10267 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10268
10269 ;; XOP parallel integer multiply/add instructions.
10270 ;; Note the XOP multiply/add instructions
10271 ;;     a[i] = b[i] * c[i] + d[i];
10272 ;; do not allow the value being added to be a memory operation.
10273 (define_insn "xop_pmacsww"
10274   [(set (match_operand:V8HI 0 "register_operand" "=x")
10275         (plus:V8HI
10276          (mult:V8HI
10277           (match_operand:V8HI 1 "nonimmediate_operand" "%x")
10278           (match_operand:V8HI 2 "nonimmediate_operand" "xm"))
10279          (match_operand:V8HI 3 "nonimmediate_operand" "x")))]
10280   "TARGET_XOP"
10281   "vpmacsww\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10282   [(set_attr "type" "ssemuladd")
10283    (set_attr "mode" "TI")])
10284
10285 (define_insn "xop_pmacssww"
10286   [(set (match_operand:V8HI 0 "register_operand" "=x")
10287         (ss_plus:V8HI
10288          (mult:V8HI (match_operand:V8HI 1 "nonimmediate_operand" "%x")
10289                     (match_operand:V8HI 2 "nonimmediate_operand" "xm"))
10290          (match_operand:V8HI 3 "nonimmediate_operand" "x")))]
10291   "TARGET_XOP"
10292   "vpmacssww\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10293   [(set_attr "type" "ssemuladd")
10294    (set_attr "mode" "TI")])
10295
10296 (define_insn "xop_pmacsdd"
10297   [(set (match_operand:V4SI 0 "register_operand" "=x")
10298         (plus:V4SI
10299          (mult:V4SI
10300           (match_operand:V4SI 1 "nonimmediate_operand" "%x")
10301           (match_operand:V4SI 2 "nonimmediate_operand" "xm"))
10302          (match_operand:V4SI 3 "nonimmediate_operand" "x")))]
10303   "TARGET_XOP"
10304   "vpmacsdd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10305   [(set_attr "type" "ssemuladd")
10306    (set_attr "mode" "TI")])
10307
10308 (define_insn "xop_pmacssdd"
10309   [(set (match_operand:V4SI 0 "register_operand" "=x")
10310         (ss_plus:V4SI
10311          (mult:V4SI (match_operand:V4SI 1 "nonimmediate_operand" "%x")
10312                     (match_operand:V4SI 2 "nonimmediate_operand" "xm"))
10313          (match_operand:V4SI 3 "nonimmediate_operand" "x")))]
10314   "TARGET_XOP"
10315   "vpmacssdd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10316   [(set_attr "type" "ssemuladd")
10317    (set_attr "mode" "TI")])
10318
10319 (define_insn "xop_pmacssdql"
10320   [(set (match_operand:V2DI 0 "register_operand" "=x")
10321         (ss_plus:V2DI
10322          (mult:V2DI
10323           (sign_extend:V2DI
10324            (vec_select:V2SI
10325             (match_operand:V4SI 1 "nonimmediate_operand" "%x")
10326             (parallel [(const_int 1)
10327                        (const_int 3)])))
10328           (vec_select:V2SI
10329            (match_operand:V4SI 2 "nonimmediate_operand" "xm")
10330            (parallel [(const_int 1)
10331                       (const_int 3)])))
10332          (match_operand:V2DI 3 "nonimmediate_operand" "x")))]
10333   "TARGET_XOP"
10334   "vpmacssdql\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10335   [(set_attr "type" "ssemuladd")
10336    (set_attr "mode" "TI")])
10337
10338 (define_insn "xop_pmacssdqh"
10339   [(set (match_operand:V2DI 0 "register_operand" "=x")
10340         (ss_plus:V2DI
10341          (mult:V2DI
10342           (sign_extend:V2DI
10343            (vec_select:V2SI
10344             (match_operand:V4SI 1 "nonimmediate_operand" "%x")
10345             (parallel [(const_int 0)
10346                        (const_int 2)])))
10347           (sign_extend:V2DI
10348            (vec_select:V2SI
10349             (match_operand:V4SI 2 "nonimmediate_operand" "xm")
10350             (parallel [(const_int 0)
10351                        (const_int 2)]))))
10352          (match_operand:V2DI 3 "nonimmediate_operand" "x")))]
10353   "TARGET_XOP"
10354   "vpmacssdqh\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10355   [(set_attr "type" "ssemuladd")
10356    (set_attr "mode" "TI")])
10357
10358 (define_insn "xop_pmacsdql"
10359   [(set (match_operand:V2DI 0 "register_operand" "=x")
10360         (plus:V2DI
10361          (mult:V2DI
10362           (sign_extend:V2DI
10363            (vec_select:V2SI
10364             (match_operand:V4SI 1 "nonimmediate_operand" "%x")
10365             (parallel [(const_int 1)
10366                        (const_int 3)])))
10367           (sign_extend:V2DI
10368            (vec_select:V2SI
10369             (match_operand:V4SI 2 "nonimmediate_operand" "xm")
10370             (parallel [(const_int 1)
10371                        (const_int 3)]))))
10372          (match_operand:V2DI 3 "nonimmediate_operand" "x")))]
10373   "TARGET_XOP"
10374   "vpmacsdql\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10375   [(set_attr "type" "ssemuladd")
10376    (set_attr "mode" "TI")])
10377
10378 ;; We don't have a straight 32-bit parallel multiply and extend on XOP, so
10379 ;; fake it with a multiply/add.  In general, we expect the define_split to
10380 ;; occur before register allocation, so we have to handle the corner case where
10381 ;; the target is the same as operands 1/2
10382 (define_insn_and_split "xop_mulv2div2di3_low"
10383   [(set (match_operand:V2DI 0 "register_operand" "=&x")
10384         (mult:V2DI
10385           (sign_extend:V2DI
10386             (vec_select:V2SI
10387               (match_operand:V4SI 1 "register_operand" "%x")
10388               (parallel [(const_int 1)
10389                          (const_int 3)])))
10390           (sign_extend:V2DI
10391             (vec_select:V2SI
10392               (match_operand:V4SI 2 "nonimmediate_operand" "xm")
10393               (parallel [(const_int 1)
10394                          (const_int 3)])))))]
10395   "TARGET_XOP"
10396   "#"
10397   "&& reload_completed"
10398   [(set (match_dup 0)
10399         (match_dup 3))
10400    (set (match_dup 0)
10401         (plus:V2DI
10402          (mult:V2DI
10403           (sign_extend:V2DI
10404            (vec_select:V2SI
10405             (match_dup 1)
10406             (parallel [(const_int 1)
10407                        (const_int 3)])))
10408           (sign_extend:V2DI
10409            (vec_select:V2SI
10410             (match_dup 2)
10411             (parallel [(const_int 1)
10412                        (const_int 3)]))))
10413          (match_dup 0)))]
10414 {
10415   operands[3] = CONST0_RTX (V2DImode);
10416 }
10417   [(set_attr "type" "ssemul")
10418    (set_attr "mode" "TI")])
10419
10420 (define_insn "xop_pmacsdqh"
10421   [(set (match_operand:V2DI 0 "register_operand" "=x")
10422         (plus:V2DI
10423          (mult:V2DI
10424           (sign_extend:V2DI
10425            (vec_select:V2SI
10426             (match_operand:V4SI 1 "nonimmediate_operand" "%x")
10427             (parallel [(const_int 0)
10428                        (const_int 2)])))
10429           (sign_extend:V2DI
10430            (vec_select:V2SI
10431             (match_operand:V4SI 2 "nonimmediate_operand" "xm")
10432             (parallel [(const_int 0)
10433                        (const_int 2)]))))
10434          (match_operand:V2DI 3 "nonimmediate_operand" "x")))]
10435   "TARGET_XOP"
10436   "vpmacsdqh\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10437   [(set_attr "type" "ssemuladd")
10438    (set_attr "mode" "TI")])
10439
10440 ;; We don't have a straight 32-bit parallel multiply and extend on XOP, so
10441 ;; fake it with a multiply/add.  In general, we expect the define_split to
10442 ;; occur before register allocation, so we have to handle the corner case where
10443 ;; the target is the same as either operands[1] or operands[2]
10444 (define_insn_and_split "xop_mulv2div2di3_high"
10445   [(set (match_operand:V2DI 0 "register_operand" "=&x")
10446         (mult:V2DI
10447           (sign_extend:V2DI
10448             (vec_select:V2SI
10449               (match_operand:V4SI 1 "register_operand" "%x")
10450               (parallel [(const_int 0)
10451                          (const_int 2)])))
10452           (sign_extend:V2DI
10453             (vec_select:V2SI
10454               (match_operand:V4SI 2 "nonimmediate_operand" "xm")
10455               (parallel [(const_int 0)
10456                          (const_int 2)])))))]
10457   "TARGET_XOP"
10458   "#"
10459   "&& reload_completed"
10460   [(set (match_dup 0)
10461         (match_dup 3))
10462    (set (match_dup 0)
10463         (plus:V2DI
10464          (mult:V2DI
10465           (sign_extend:V2DI
10466            (vec_select:V2SI
10467             (match_dup 1)
10468             (parallel [(const_int 0)
10469                        (const_int 2)])))
10470           (sign_extend:V2DI
10471            (vec_select:V2SI
10472             (match_dup 2)
10473             (parallel [(const_int 0)
10474                        (const_int 2)]))))
10475          (match_dup 0)))]
10476 {
10477   operands[3] = CONST0_RTX (V2DImode);
10478 }
10479   [(set_attr "type" "ssemul")
10480    (set_attr "mode" "TI")])
10481
10482 ;; XOP parallel integer multiply/add instructions for the intrinisics
10483 (define_insn "xop_pmacsswd"
10484   [(set (match_operand:V4SI 0 "register_operand" "=x")
10485         (ss_plus:V4SI
10486          (mult:V4SI
10487           (sign_extend:V4SI
10488            (vec_select:V4HI
10489             (match_operand:V8HI 1 "nonimmediate_operand" "%x")
10490             (parallel [(const_int 1)
10491                        (const_int 3)
10492                        (const_int 5)
10493                        (const_int 7)])))
10494           (sign_extend:V4SI
10495            (vec_select:V4HI
10496             (match_operand:V8HI 2 "nonimmediate_operand" "xm")
10497             (parallel [(const_int 1)
10498                        (const_int 3)
10499                        (const_int 5)
10500                        (const_int 7)]))))
10501          (match_operand:V4SI 3 "nonimmediate_operand" "x")))]
10502   "TARGET_XOP"
10503   "vpmacsswd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10504   [(set_attr "type" "ssemuladd")
10505    (set_attr "mode" "TI")])
10506
10507 (define_insn "xop_pmacswd"
10508   [(set (match_operand:V4SI 0 "register_operand" "=x")
10509         (plus:V4SI
10510          (mult:V4SI
10511           (sign_extend:V4SI
10512            (vec_select:V4HI
10513             (match_operand:V8HI 1 "nonimmediate_operand" "%x")
10514             (parallel [(const_int 1)
10515                        (const_int 3)
10516                        (const_int 5)
10517                        (const_int 7)])))
10518           (sign_extend:V4SI
10519            (vec_select:V4HI
10520             (match_operand:V8HI 2 "nonimmediate_operand" "xm")
10521             (parallel [(const_int 1)
10522                        (const_int 3)
10523                        (const_int 5)
10524                        (const_int 7)]))))
10525          (match_operand:V4SI 3 "nonimmediate_operand" "x")))]
10526   "TARGET_XOP"
10527   "vpmacswd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10528   [(set_attr "type" "ssemuladd")
10529    (set_attr "mode" "TI")])
10530
10531 (define_insn "xop_pmadcsswd"
10532   [(set (match_operand:V4SI 0 "register_operand" "=x")
10533         (ss_plus:V4SI
10534          (plus:V4SI
10535           (mult:V4SI
10536            (sign_extend:V4SI
10537             (vec_select:V4HI
10538              (match_operand:V8HI 1 "nonimmediate_operand" "%x")
10539              (parallel [(const_int 0)
10540                         (const_int 2)
10541                         (const_int 4)
10542                         (const_int 6)])))
10543            (sign_extend:V4SI
10544             (vec_select:V4HI
10545              (match_operand:V8HI 2 "nonimmediate_operand" "xm")
10546              (parallel [(const_int 0)
10547                         (const_int 2)
10548                         (const_int 4)
10549                         (const_int 6)]))))
10550           (mult:V4SI
10551            (sign_extend:V4SI
10552             (vec_select:V4HI
10553              (match_dup 1)
10554              (parallel [(const_int 1)
10555                         (const_int 3)
10556                         (const_int 5)
10557                         (const_int 7)])))
10558            (sign_extend:V4SI
10559             (vec_select:V4HI
10560              (match_dup 2)
10561              (parallel [(const_int 1)
10562                         (const_int 3)
10563                         (const_int 5)
10564                         (const_int 7)])))))
10565          (match_operand:V4SI 3 "nonimmediate_operand" "x")))]
10566   "TARGET_XOP"
10567   "vpmadcsswd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10568   [(set_attr "type" "ssemuladd")
10569    (set_attr "mode" "TI")])
10570
10571 (define_insn "xop_pmadcswd"
10572   [(set (match_operand:V4SI 0 "register_operand" "=x")
10573         (plus:V4SI
10574          (plus:V4SI
10575           (mult:V4SI
10576            (sign_extend:V4SI
10577             (vec_select:V4HI
10578              (match_operand:V8HI 1 "nonimmediate_operand" "%x")
10579              (parallel [(const_int 0)
10580                         (const_int 2)
10581                         (const_int 4)
10582                         (const_int 6)])))
10583            (sign_extend:V4SI
10584             (vec_select:V4HI
10585              (match_operand:V8HI 2 "nonimmediate_operand" "xm")
10586              (parallel [(const_int 0)
10587                         (const_int 2)
10588                         (const_int 4)
10589                         (const_int 6)]))))
10590           (mult:V4SI
10591            (sign_extend:V4SI
10592             (vec_select:V4HI
10593              (match_dup 1)
10594              (parallel [(const_int 1)
10595                         (const_int 3)
10596                         (const_int 5)
10597                         (const_int 7)])))
10598            (sign_extend:V4SI
10599             (vec_select:V4HI
10600              (match_dup 2)
10601              (parallel [(const_int 1)
10602                         (const_int 3)
10603                         (const_int 5)
10604                         (const_int 7)])))))
10605          (match_operand:V4SI 3 "nonimmediate_operand" "x")))]
10606   "TARGET_XOP"
10607   "vpmadcswd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10608   [(set_attr "type" "ssemuladd")
10609    (set_attr "mode" "TI")])
10610
10611 ;; XOP parallel XMM conditional moves
10612 (define_insn "xop_pcmov_<mode><avxsizesuffix>"
10613   [(set (match_operand:V 0 "register_operand" "=x,x")
10614         (if_then_else:V
10615           (match_operand:V 3 "nonimmediate_operand" "x,m")
10616           (match_operand:V 1 "register_operand" "x,x")
10617           (match_operand:V 2 "nonimmediate_operand" "xm,x")))]
10618   "TARGET_XOP"
10619   "vpcmov\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10620   [(set_attr "type" "sse4arg")])
10621
10622 ;; XOP horizontal add/subtract instructions
10623 (define_insn "xop_phaddbw"
10624   [(set (match_operand:V8HI 0 "register_operand" "=x")
10625         (plus:V8HI
10626          (sign_extend:V8HI
10627           (vec_select:V8QI
10628            (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10629            (parallel [(const_int 0)
10630                       (const_int 2)
10631                       (const_int 4)
10632                       (const_int 6)
10633                       (const_int 8)
10634                       (const_int 10)
10635                       (const_int 12)
10636                       (const_int 14)])))
10637          (sign_extend:V8HI
10638           (vec_select:V8QI
10639            (match_dup 1)
10640            (parallel [(const_int 1)
10641                       (const_int 3)
10642                       (const_int 5)
10643                       (const_int 7)
10644                       (const_int 9)
10645                       (const_int 11)
10646                       (const_int 13)
10647                       (const_int 15)])))))]
10648   "TARGET_XOP"
10649   "vphaddbw\t{%1, %0|%0, %1}"
10650   [(set_attr "type" "sseiadd1")])
10651
10652 (define_insn "xop_phaddbd"
10653   [(set (match_operand:V4SI 0 "register_operand" "=x")
10654         (plus:V4SI
10655          (plus:V4SI
10656           (sign_extend:V4SI
10657            (vec_select:V4QI
10658             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10659             (parallel [(const_int 0)
10660                        (const_int 4)
10661                        (const_int 8)
10662                        (const_int 12)])))
10663           (sign_extend:V4SI
10664            (vec_select:V4QI
10665             (match_dup 1)
10666             (parallel [(const_int 1)
10667                        (const_int 5)
10668                        (const_int 9)
10669                        (const_int 13)]))))
10670          (plus:V4SI
10671           (sign_extend:V4SI
10672            (vec_select:V4QI
10673             (match_dup 1)
10674             (parallel [(const_int 2)
10675                        (const_int 6)
10676                        (const_int 10)
10677                        (const_int 14)])))
10678           (sign_extend:V4SI
10679            (vec_select:V4QI
10680             (match_dup 1)
10681             (parallel [(const_int 3)
10682                        (const_int 7)
10683                        (const_int 11)
10684                        (const_int 15)]))))))]
10685   "TARGET_XOP"
10686   "vphaddbd\t{%1, %0|%0, %1}"
10687   [(set_attr "type" "sseiadd1")])
10688
10689 (define_insn "xop_phaddbq"
10690   [(set (match_operand:V2DI 0 "register_operand" "=x")
10691         (plus:V2DI
10692          (plus:V2DI
10693           (plus:V2DI
10694            (sign_extend:V2DI
10695             (vec_select:V2QI
10696              (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10697              (parallel [(const_int 0)
10698                         (const_int 4)])))
10699            (sign_extend:V2DI
10700             (vec_select:V2QI
10701              (match_dup 1)
10702              (parallel [(const_int 1)
10703                         (const_int 5)]))))
10704           (plus:V2DI
10705            (sign_extend:V2DI
10706             (vec_select:V2QI
10707              (match_dup 1)
10708              (parallel [(const_int 2)
10709                         (const_int 6)])))
10710            (sign_extend:V2DI
10711             (vec_select:V2QI
10712              (match_dup 1)
10713              (parallel [(const_int 3)
10714                         (const_int 7)])))))
10715          (plus:V2DI
10716           (plus:V2DI
10717            (sign_extend:V2DI
10718             (vec_select:V2QI
10719              (match_dup 1)
10720              (parallel [(const_int 8)
10721                         (const_int 12)])))
10722            (sign_extend:V2DI
10723             (vec_select:V2QI
10724              (match_dup 1)
10725              (parallel [(const_int 9)
10726                         (const_int 13)]))))
10727           (plus:V2DI
10728            (sign_extend:V2DI
10729             (vec_select:V2QI
10730              (match_dup 1)
10731              (parallel [(const_int 10)
10732                         (const_int 14)])))
10733            (sign_extend:V2DI
10734             (vec_select:V2QI
10735              (match_dup 1)
10736              (parallel [(const_int 11)
10737                         (const_int 15)])))))))]
10738   "TARGET_XOP"
10739   "vphaddbq\t{%1, %0|%0, %1}"
10740   [(set_attr "type" "sseiadd1")])
10741
10742 (define_insn "xop_phaddwd"
10743   [(set (match_operand:V4SI 0 "register_operand" "=x")
10744         (plus:V4SI
10745          (sign_extend:V4SI
10746           (vec_select:V4HI
10747            (match_operand:V8HI 1 "nonimmediate_operand" "xm")
10748            (parallel [(const_int 0)
10749                       (const_int 2)
10750                       (const_int 4)
10751                       (const_int 6)])))
10752          (sign_extend:V4SI
10753           (vec_select:V4HI
10754            (match_dup 1)
10755            (parallel [(const_int 1)
10756                       (const_int 3)
10757                       (const_int 5)
10758                       (const_int 7)])))))]
10759   "TARGET_XOP"
10760   "vphaddwd\t{%1, %0|%0, %1}"
10761   [(set_attr "type" "sseiadd1")])
10762
10763 (define_insn "xop_phaddwq"
10764   [(set (match_operand:V2DI 0 "register_operand" "=x")
10765         (plus:V2DI
10766          (plus:V2DI
10767           (sign_extend:V2DI
10768            (vec_select:V2HI
10769             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
10770             (parallel [(const_int 0)
10771                        (const_int 4)])))
10772           (sign_extend:V2DI
10773            (vec_select:V2HI
10774             (match_dup 1)
10775             (parallel [(const_int 1)
10776                        (const_int 5)]))))
10777          (plus:V2DI
10778           (sign_extend:V2DI
10779            (vec_select:V2HI
10780             (match_dup 1)
10781             (parallel [(const_int 2)
10782                        (const_int 6)])))
10783           (sign_extend:V2DI
10784            (vec_select:V2HI
10785             (match_dup 1)
10786             (parallel [(const_int 3)
10787                        (const_int 7)]))))))]
10788   "TARGET_XOP"
10789   "vphaddwq\t{%1, %0|%0, %1}"
10790   [(set_attr "type" "sseiadd1")])
10791
10792 (define_insn "xop_phadddq"
10793   [(set (match_operand:V2DI 0 "register_operand" "=x")
10794         (plus:V2DI
10795          (sign_extend:V2DI
10796           (vec_select:V2SI
10797            (match_operand:V4SI 1 "nonimmediate_operand" "xm")
10798            (parallel [(const_int 0)
10799                       (const_int 2)])))
10800          (sign_extend:V2DI
10801           (vec_select:V2SI
10802            (match_dup 1)
10803            (parallel [(const_int 1)
10804                       (const_int 3)])))))]
10805   "TARGET_XOP"
10806   "vphadddq\t{%1, %0|%0, %1}"
10807   [(set_attr "type" "sseiadd1")])
10808
10809 (define_insn "xop_phaddubw"
10810   [(set (match_operand:V8HI 0 "register_operand" "=x")
10811         (plus:V8HI
10812          (zero_extend:V8HI
10813           (vec_select:V8QI
10814            (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10815            (parallel [(const_int 0)
10816                       (const_int 2)
10817                       (const_int 4)
10818                       (const_int 6)
10819                       (const_int 8)
10820                       (const_int 10)
10821                       (const_int 12)
10822                       (const_int 14)])))
10823          (zero_extend:V8HI
10824           (vec_select:V8QI
10825            (match_dup 1)
10826            (parallel [(const_int 1)
10827                       (const_int 3)
10828                       (const_int 5)
10829                       (const_int 7)
10830                       (const_int 9)
10831                       (const_int 11)
10832                       (const_int 13)
10833                       (const_int 15)])))))]
10834   "TARGET_XOP"
10835   "vphaddubw\t{%1, %0|%0, %1}"
10836   [(set_attr "type" "sseiadd1")])
10837
10838 (define_insn "xop_phaddubd"
10839   [(set (match_operand:V4SI 0 "register_operand" "=x")
10840         (plus:V4SI
10841          (plus:V4SI
10842           (zero_extend:V4SI
10843            (vec_select:V4QI
10844             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10845             (parallel [(const_int 0)
10846                        (const_int 4)
10847                        (const_int 8)
10848                        (const_int 12)])))
10849           (zero_extend:V4SI
10850            (vec_select:V4QI
10851             (match_dup 1)
10852             (parallel [(const_int 1)
10853                        (const_int 5)
10854                        (const_int 9)
10855                        (const_int 13)]))))
10856          (plus:V4SI
10857           (zero_extend:V4SI
10858            (vec_select:V4QI
10859             (match_dup 1)
10860             (parallel [(const_int 2)
10861                        (const_int 6)
10862                        (const_int 10)
10863                        (const_int 14)])))
10864           (zero_extend:V4SI
10865            (vec_select:V4QI
10866             (match_dup 1)
10867             (parallel [(const_int 3)
10868                        (const_int 7)
10869                        (const_int 11)
10870                        (const_int 15)]))))))]
10871   "TARGET_XOP"
10872   "vphaddubd\t{%1, %0|%0, %1}"
10873   [(set_attr "type" "sseiadd1")])
10874
10875 (define_insn "xop_phaddubq"
10876   [(set (match_operand:V2DI 0 "register_operand" "=x")
10877         (plus:V2DI
10878          (plus:V2DI
10879           (plus:V2DI
10880            (zero_extend:V2DI
10881             (vec_select:V2QI
10882              (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10883              (parallel [(const_int 0)
10884                         (const_int 4)])))
10885            (sign_extend:V2DI
10886             (vec_select:V2QI
10887              (match_dup 1)
10888              (parallel [(const_int 1)
10889                         (const_int 5)]))))
10890           (plus:V2DI
10891            (zero_extend:V2DI
10892             (vec_select:V2QI
10893              (match_dup 1)
10894              (parallel [(const_int 2)
10895                         (const_int 6)])))
10896            (zero_extend:V2DI
10897             (vec_select:V2QI
10898              (match_dup 1)
10899              (parallel [(const_int 3)
10900                         (const_int 7)])))))
10901          (plus:V2DI
10902           (plus:V2DI
10903            (zero_extend:V2DI
10904             (vec_select:V2QI
10905              (match_dup 1)
10906              (parallel [(const_int 8)
10907                         (const_int 12)])))
10908            (sign_extend:V2DI
10909             (vec_select:V2QI
10910              (match_dup 1)
10911              (parallel [(const_int 9)
10912                         (const_int 13)]))))
10913           (plus:V2DI
10914            (zero_extend:V2DI
10915             (vec_select:V2QI
10916              (match_dup 1)
10917              (parallel [(const_int 10)
10918                         (const_int 14)])))
10919            (zero_extend:V2DI
10920             (vec_select:V2QI
10921              (match_dup 1)
10922              (parallel [(const_int 11)
10923                         (const_int 15)])))))))]
10924   "TARGET_XOP"
10925   "vphaddubq\t{%1, %0|%0, %1}"
10926   [(set_attr "type" "sseiadd1")])
10927
10928 (define_insn "xop_phadduwd"
10929   [(set (match_operand:V4SI 0 "register_operand" "=x")
10930         (plus:V4SI
10931          (zero_extend:V4SI
10932           (vec_select:V4HI
10933            (match_operand:V8HI 1 "nonimmediate_operand" "xm")
10934            (parallel [(const_int 0)
10935                       (const_int 2)
10936                       (const_int 4)
10937                       (const_int 6)])))
10938          (zero_extend:V4SI
10939           (vec_select:V4HI
10940            (match_dup 1)
10941            (parallel [(const_int 1)
10942                       (const_int 3)
10943                       (const_int 5)
10944                       (const_int 7)])))))]
10945   "TARGET_XOP"
10946   "vphadduwd\t{%1, %0|%0, %1}"
10947   [(set_attr "type" "sseiadd1")])
10948
10949 (define_insn "xop_phadduwq"
10950   [(set (match_operand:V2DI 0 "register_operand" "=x")
10951         (plus:V2DI
10952          (plus:V2DI
10953           (zero_extend:V2DI
10954            (vec_select:V2HI
10955             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
10956             (parallel [(const_int 0)
10957                        (const_int 4)])))
10958           (zero_extend:V2DI
10959            (vec_select:V2HI
10960             (match_dup 1)
10961             (parallel [(const_int 1)
10962                        (const_int 5)]))))
10963          (plus:V2DI
10964           (zero_extend:V2DI
10965            (vec_select:V2HI
10966             (match_dup 1)
10967             (parallel [(const_int 2)
10968                        (const_int 6)])))
10969           (zero_extend:V2DI
10970            (vec_select:V2HI
10971             (match_dup 1)
10972             (parallel [(const_int 3)
10973                        (const_int 7)]))))))]
10974   "TARGET_XOP"
10975   "vphadduwq\t{%1, %0|%0, %1}"
10976   [(set_attr "type" "sseiadd1")])
10977
10978 (define_insn "xop_phaddudq"
10979   [(set (match_operand:V2DI 0 "register_operand" "=x")
10980         (plus:V2DI
10981          (zero_extend:V2DI
10982           (vec_select:V2SI
10983            (match_operand:V4SI 1 "nonimmediate_operand" "xm")
10984            (parallel [(const_int 0)
10985                       (const_int 2)])))
10986          (zero_extend:V2DI
10987           (vec_select:V2SI
10988            (match_dup 1)
10989            (parallel [(const_int 1)
10990                       (const_int 3)])))))]
10991   "TARGET_XOP"
10992   "vphaddudq\t{%1, %0|%0, %1}"
10993   [(set_attr "type" "sseiadd1")])
10994
10995 (define_insn "xop_phsubbw"
10996   [(set (match_operand:V8HI 0 "register_operand" "=x")
10997         (minus:V8HI
10998          (sign_extend:V8HI
10999           (vec_select:V8QI
11000            (match_operand:V16QI 1 "nonimmediate_operand" "xm")
11001            (parallel [(const_int 0)
11002                       (const_int 2)
11003                       (const_int 4)
11004                       (const_int 6)
11005                       (const_int 8)
11006                       (const_int 10)
11007                       (const_int 12)
11008                       (const_int 14)])))
11009          (sign_extend:V8HI
11010           (vec_select:V8QI
11011            (match_dup 1)
11012            (parallel [(const_int 1)
11013                       (const_int 3)
11014                       (const_int 5)
11015                       (const_int 7)
11016                       (const_int 9)
11017                       (const_int 11)
11018                       (const_int 13)
11019                       (const_int 15)])))))]
11020   "TARGET_XOP"
11021   "vphsubbw\t{%1, %0|%0, %1}"
11022   [(set_attr "type" "sseiadd1")])
11023
11024 (define_insn "xop_phsubwd"
11025   [(set (match_operand:V4SI 0 "register_operand" "=x")
11026         (minus:V4SI
11027          (sign_extend:V4SI
11028           (vec_select:V4HI
11029            (match_operand:V8HI 1 "nonimmediate_operand" "xm")
11030            (parallel [(const_int 0)
11031                       (const_int 2)
11032                       (const_int 4)
11033                       (const_int 6)])))
11034          (sign_extend:V4SI
11035           (vec_select:V4HI
11036            (match_dup 1)
11037            (parallel [(const_int 1)
11038                       (const_int 3)
11039                       (const_int 5)
11040                       (const_int 7)])))))]
11041   "TARGET_XOP"
11042   "vphsubwd\t{%1, %0|%0, %1}"
11043   [(set_attr "type" "sseiadd1")])
11044
11045 (define_insn "xop_phsubdq"
11046   [(set (match_operand:V2DI 0 "register_operand" "=x")
11047         (minus:V2DI
11048          (sign_extend:V2DI
11049           (vec_select:V2SI
11050            (match_operand:V4SI 1 "nonimmediate_operand" "xm")
11051            (parallel [(const_int 0)
11052                       (const_int 2)])))
11053          (sign_extend:V2DI
11054           (vec_select:V2SI
11055            (match_dup 1)
11056            (parallel [(const_int 1)
11057                       (const_int 3)])))))]
11058   "TARGET_XOP"
11059   "vphsubdq\t{%1, %0|%0, %1}"
11060   [(set_attr "type" "sseiadd1")])
11061
11062 ;; XOP permute instructions
11063 (define_insn "xop_pperm"
11064   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
11065         (unspec:V16QI
11066           [(match_operand:V16QI 1 "register_operand" "x,x")
11067            (match_operand:V16QI 2 "nonimmediate_operand" "x,m")
11068            (match_operand:V16QI 3 "nonimmediate_operand" "xm,x")]
11069           UNSPEC_XOP_PERMUTE))]
11070   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
11071   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
11072   [(set_attr "type" "sse4arg")
11073    (set_attr "mode" "TI")])
11074
11075 ;; XOP pack instructions that combine two vectors into a smaller vector
11076 (define_insn "xop_pperm_pack_v2di_v4si"
11077   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
11078         (vec_concat:V4SI
11079          (truncate:V2SI
11080           (match_operand:V2DI 1 "register_operand" "x,x"))
11081          (truncate:V2SI
11082           (match_operand:V2DI 2 "nonimmediate_operand" "x,m"))))
11083    (use (match_operand:V16QI 3 "nonimmediate_operand" "xm,x"))]
11084   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
11085   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
11086   [(set_attr "type" "sse4arg")
11087    (set_attr "mode" "TI")])
11088
11089 (define_insn "xop_pperm_pack_v4si_v8hi"
11090   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
11091         (vec_concat:V8HI
11092          (truncate:V4HI
11093           (match_operand:V4SI 1 "register_operand" "x,x"))
11094          (truncate:V4HI
11095           (match_operand:V4SI 2 "nonimmediate_operand" "x,m"))))
11096    (use (match_operand:V16QI 3 "nonimmediate_operand" "xm,x"))]
11097   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
11098   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
11099   [(set_attr "type" "sse4arg")
11100    (set_attr "mode" "TI")])
11101
11102 (define_insn "xop_pperm_pack_v8hi_v16qi"
11103   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
11104         (vec_concat:V16QI
11105          (truncate:V8QI
11106           (match_operand:V8HI 1 "register_operand" "x,x"))
11107          (truncate:V8QI
11108           (match_operand:V8HI 2 "nonimmediate_operand" "x,m"))))
11109    (use (match_operand:V16QI 3 "nonimmediate_operand" "xm,x"))]
11110   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
11111   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
11112   [(set_attr "type" "sse4arg")
11113    (set_attr "mode" "TI")])
11114
11115 ;; XOP packed rotate instructions
11116 (define_expand "rotl<mode>3"
11117   [(set (match_operand:VI_128 0 "register_operand" "")
11118         (rotate:VI_128
11119          (match_operand:VI_128 1 "nonimmediate_operand" "")
11120          (match_operand:SI 2 "general_operand")))]
11121   "TARGET_XOP"
11122 {
11123   /* If we were given a scalar, convert it to parallel */
11124   if (! const_0_to_<sserotatemax>_operand (operands[2], SImode))
11125     {
11126       rtvec vs = rtvec_alloc (<ssescalarnum>);
11127       rtx par = gen_rtx_PARALLEL (<MODE>mode, vs);
11128       rtx reg = gen_reg_rtx (<MODE>mode);
11129       rtx op2 = operands[2];
11130       int i;
11131
11132       if (GET_MODE (op2) != <ssescalarmode>mode)
11133         {
11134           op2 = gen_reg_rtx (<ssescalarmode>mode);
11135           convert_move (op2, operands[2], false);
11136         }
11137
11138       for (i = 0; i < <ssescalarnum>; i++)
11139         RTVEC_ELT (vs, i) = op2;
11140
11141       emit_insn (gen_vec_init<mode> (reg, par));
11142       emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], reg));
11143       DONE;
11144     }
11145 })
11146
11147 (define_expand "rotr<mode>3"
11148   [(set (match_operand:VI_128 0 "register_operand" "")
11149         (rotatert:VI_128
11150          (match_operand:VI_128 1 "nonimmediate_operand" "")
11151          (match_operand:SI 2 "general_operand")))]
11152   "TARGET_XOP"
11153 {
11154   /* If we were given a scalar, convert it to parallel */
11155   if (! const_0_to_<sserotatemax>_operand (operands[2], SImode))
11156     {
11157       rtvec vs = rtvec_alloc (<ssescalarnum>);
11158       rtx par = gen_rtx_PARALLEL (<MODE>mode, vs);
11159       rtx neg = gen_reg_rtx (<MODE>mode);
11160       rtx reg = gen_reg_rtx (<MODE>mode);
11161       rtx op2 = operands[2];
11162       int i;
11163
11164       if (GET_MODE (op2) != <ssescalarmode>mode)
11165         {
11166           op2 = gen_reg_rtx (<ssescalarmode>mode);
11167           convert_move (op2, operands[2], false);
11168         }
11169
11170       for (i = 0; i < <ssescalarnum>; i++)
11171         RTVEC_ELT (vs, i) = op2;
11172
11173       emit_insn (gen_vec_init<mode> (reg, par));
11174       emit_insn (gen_neg<mode>2 (neg, reg));
11175       emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], neg));
11176       DONE;
11177     }
11178 })
11179
11180 (define_insn "xop_rotl<mode>3"
11181   [(set (match_operand:VI_128 0 "register_operand" "=x")
11182         (rotate:VI_128
11183          (match_operand:VI_128 1 "nonimmediate_operand" "xm")
11184          (match_operand:SI 2 "const_0_to_<sserotatemax>_operand" "n")))]
11185   "TARGET_XOP"
11186   "vprot<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11187   [(set_attr "type" "sseishft")
11188    (set_attr "length_immediate" "1")
11189    (set_attr "mode" "TI")])
11190
11191 (define_insn "xop_rotr<mode>3"
11192   [(set (match_operand:VI_128 0 "register_operand" "=x")
11193         (rotatert:VI_128
11194          (match_operand:VI_128 1 "nonimmediate_operand" "xm")
11195          (match_operand:SI 2 "const_0_to_<sserotatemax>_operand" "n")))]
11196   "TARGET_XOP"
11197 {
11198   operands[3] = GEN_INT ((<ssescalarnum> * 8) - INTVAL (operands[2]));
11199   return \"vprot<ssemodesuffix>\t{%3, %1, %0|%0, %1, %3}\";
11200 }
11201   [(set_attr "type" "sseishft")
11202    (set_attr "length_immediate" "1")
11203    (set_attr "mode" "TI")])
11204
11205 (define_expand "vrotr<mode>3"
11206   [(match_operand:VI_128 0 "register_operand" "")
11207    (match_operand:VI_128 1 "register_operand" "")
11208    (match_operand:VI_128 2 "register_operand" "")]
11209   "TARGET_XOP"
11210 {
11211   rtx reg = gen_reg_rtx (<MODE>mode);
11212   emit_insn (gen_neg<mode>2 (reg, operands[2]));
11213   emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], reg));
11214   DONE;
11215 })
11216
11217 (define_expand "vrotl<mode>3"
11218   [(match_operand:VI_128 0 "register_operand" "")
11219    (match_operand:VI_128 1 "register_operand" "")
11220    (match_operand:VI_128 2 "register_operand" "")]
11221   "TARGET_XOP"
11222 {
11223   emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], operands[2]));
11224   DONE;
11225 })
11226
11227 (define_insn "xop_vrotl<mode>3"
11228   [(set (match_operand:VI_128 0 "register_operand" "=x,x")
11229         (if_then_else:VI_128
11230          (ge:VI_128
11231           (match_operand:VI_128 2 "nonimmediate_operand" "x,m")
11232           (const_int 0))
11233          (rotate:VI_128
11234           (match_operand:VI_128 1 "nonimmediate_operand" "xm,x")
11235           (match_dup 2))
11236          (rotatert:VI_128
11237           (match_dup 1)
11238           (neg:VI_128 (match_dup 2)))))]
11239   "TARGET_XOP && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
11240   "vprot<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11241   [(set_attr "type" "sseishft")
11242    (set_attr "prefix_data16" "0")
11243    (set_attr "prefix_extra" "2")
11244    (set_attr "mode" "TI")])
11245
11246 ;; XOP packed shift instructions.
11247 (define_expand "vlshr<mode>3"
11248   [(set (match_operand:VI12_128 0 "register_operand" "")
11249         (lshiftrt:VI12_128
11250           (match_operand:VI12_128 1 "register_operand" "")
11251           (match_operand:VI12_128 2 "nonimmediate_operand" "")))]
11252   "TARGET_XOP"
11253 {
11254   rtx neg = gen_reg_rtx (<MODE>mode);
11255   emit_insn (gen_neg<mode>2 (neg, operands[2]));
11256   emit_insn (gen_xop_lshl<mode>3 (operands[0], operands[1], neg));
11257   DONE;
11258 })
11259
11260 (define_expand "vlshr<mode>3"
11261   [(set (match_operand:VI48_128 0 "register_operand" "")
11262         (lshiftrt:VI48_128
11263           (match_operand:VI48_128 1 "register_operand" "")
11264           (match_operand:VI48_128 2 "nonimmediate_operand" "")))]
11265   "TARGET_AVX2 || TARGET_XOP"
11266 {
11267   if (!TARGET_AVX2)
11268     {
11269       rtx neg = gen_reg_rtx (<MODE>mode);
11270       emit_insn (gen_neg<mode>2 (neg, operands[2]));
11271       emit_insn (gen_xop_lshl<mode>3 (operands[0], operands[1], neg));
11272       DONE;
11273     }
11274 })
11275
11276 (define_expand "vlshr<mode>3"
11277   [(set (match_operand:VI48_256 0 "register_operand" "")
11278         (lshiftrt:VI48_256
11279           (match_operand:VI48_256 1 "register_operand" "")
11280           (match_operand:VI48_256 2 "nonimmediate_operand" "")))]
11281   "TARGET_AVX2")
11282
11283 (define_expand "vashr<mode>3"
11284   [(set (match_operand:VI128_128 0 "register_operand" "")
11285         (ashiftrt:VI128_128
11286           (match_operand:VI128_128 1 "register_operand" "")
11287           (match_operand:VI128_128 2 "nonimmediate_operand" "")))]
11288   "TARGET_XOP"
11289 {
11290   rtx neg = gen_reg_rtx (<MODE>mode);
11291   emit_insn (gen_neg<mode>2 (neg, operands[2]));
11292   emit_insn (gen_xop_ashl<mode>3 (operands[0], operands[1], neg));
11293   DONE;
11294 })
11295
11296 (define_expand "vashrv4si3"
11297   [(set (match_operand:V4SI 0 "register_operand" "")
11298         (ashiftrt:V4SI (match_operand:V4SI 1 "register_operand" "")
11299                        (match_operand:V4SI 2 "nonimmediate_operand" "")))]
11300   "TARGET_AVX2 || TARGET_XOP"
11301 {
11302   if (!TARGET_AVX2)
11303     {
11304       rtx neg = gen_reg_rtx (V4SImode);
11305       emit_insn (gen_negv4si2 (neg, operands[2]));
11306       emit_insn (gen_xop_ashlv4si3 (operands[0], operands[1], neg));
11307       DONE;
11308     }
11309 })
11310
11311 (define_expand "vashrv8si3"
11312   [(set (match_operand:V8SI 0 "register_operand" "")
11313         (ashiftrt:V8SI (match_operand:V8SI 1 "register_operand" "")
11314                        (match_operand:V8SI 2 "nonimmediate_operand" "")))]
11315   "TARGET_AVX2")
11316
11317 (define_expand "vashl<mode>3"
11318   [(set (match_operand:VI12_128 0 "register_operand" "")
11319         (ashift:VI12_128
11320           (match_operand:VI12_128 1 "register_operand" "")
11321           (match_operand:VI12_128 2 "nonimmediate_operand" "")))]
11322   "TARGET_XOP"
11323 {
11324   emit_insn (gen_xop_ashl<mode>3 (operands[0], operands[1], operands[2]));
11325   DONE;
11326 })
11327
11328 (define_expand "vashl<mode>3"
11329   [(set (match_operand:VI48_128 0 "register_operand" "")
11330         (ashift:VI48_128
11331           (match_operand:VI48_128 1 "register_operand" "")
11332           (match_operand:VI48_128 2 "nonimmediate_operand" "")))]
11333   "TARGET_AVX2 || TARGET_XOP"
11334 {
11335   if (!TARGET_AVX2)
11336     {
11337       operands[2] = force_reg (<MODE>mode, operands[2]);
11338       emit_insn (gen_xop_ashl<mode>3 (operands[0], operands[1], operands[2]));
11339       DONE;
11340     }
11341 })
11342
11343 (define_expand "vashl<mode>3"
11344   [(set (match_operand:VI48_256 0 "register_operand" "")
11345         (ashift:VI48_256
11346           (match_operand:VI48_256 1 "register_operand" "")
11347           (match_operand:VI48_256 2 "nonimmediate_operand" "")))]
11348   "TARGET_AVX2")
11349
11350 (define_insn "xop_ashl<mode>3"
11351   [(set (match_operand:VI_128 0 "register_operand" "=x,x")
11352         (if_then_else:VI_128
11353          (ge:VI_128
11354           (match_operand:VI_128 2 "nonimmediate_operand" "x,m")
11355           (const_int 0))
11356          (ashift:VI_128
11357           (match_operand:VI_128 1 "nonimmediate_operand" "xm,x")
11358           (match_dup 2))
11359          (ashiftrt:VI_128
11360           (match_dup 1)
11361           (neg:VI_128 (match_dup 2)))))]
11362   "TARGET_XOP && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
11363   "vpsha<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11364   [(set_attr "type" "sseishft")
11365    (set_attr "prefix_data16" "0")
11366    (set_attr "prefix_extra" "2")
11367    (set_attr "mode" "TI")])
11368
11369 (define_insn "xop_lshl<mode>3"
11370   [(set (match_operand:VI_128 0 "register_operand" "=x,x")
11371         (if_then_else:VI_128
11372          (ge:VI_128
11373           (match_operand:VI_128 2 "nonimmediate_operand" "x,m")
11374           (const_int 0))
11375          (ashift:VI_128
11376           (match_operand:VI_128 1 "nonimmediate_operand" "xm,x")
11377           (match_dup 2))
11378          (lshiftrt:VI_128
11379           (match_dup 1)
11380           (neg:VI_128 (match_dup 2)))))]
11381   "TARGET_XOP && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
11382   "vpshl<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11383   [(set_attr "type" "sseishft")
11384    (set_attr "prefix_data16" "0")
11385    (set_attr "prefix_extra" "2")
11386    (set_attr "mode" "TI")])
11387
11388 ;; SSE2 doesn't have some shift variants, so define versions for XOP
11389 (define_expand "ashlv16qi3"
11390   [(set (match_operand:V16QI 0 "register_operand" "")
11391         (ashift:V16QI
11392           (match_operand:V16QI 1 "register_operand" "")
11393           (match_operand:SI 2 "nonmemory_operand" "")))]
11394   "TARGET_XOP"
11395 {
11396   rtx reg = gen_reg_rtx (V16QImode);
11397   rtx par;
11398   int i;
11399
11400   par = gen_rtx_PARALLEL (V16QImode, rtvec_alloc (16));
11401   for (i = 0; i < 16; i++)
11402     XVECEXP (par, 0, i) = operands[2];
11403
11404   emit_insn (gen_vec_initv16qi (reg, par));
11405   emit_insn (gen_xop_ashlv16qi3 (operands[0], operands[1], reg));
11406   DONE;
11407 })
11408
11409 (define_expand "<shift_insn>v16qi3"
11410   [(set (match_operand:V16QI 0 "register_operand" "")
11411         (any_shiftrt:V16QI
11412           (match_operand:V16QI 1 "register_operand" "")
11413           (match_operand:SI 2 "nonmemory_operand" "")))]
11414   "TARGET_XOP"
11415 {
11416   rtx reg = gen_reg_rtx (V16QImode);
11417   rtx par;
11418   bool negate = false;
11419   rtx (*shift_insn)(rtx, rtx, rtx);
11420   int i;
11421
11422   if (CONST_INT_P (operands[2]))
11423     operands[2] = GEN_INT (-INTVAL (operands[2]));
11424   else
11425     negate = true;
11426
11427   par = gen_rtx_PARALLEL (V16QImode, rtvec_alloc (16));
11428   for (i = 0; i < 16; i++)
11429     XVECEXP (par, 0, i) = operands[2];
11430
11431   emit_insn (gen_vec_initv16qi (reg, par));
11432
11433   if (negate)
11434     emit_insn (gen_negv16qi2 (reg, reg));
11435
11436   if (<CODE> == LSHIFTRT)
11437     shift_insn = gen_xop_lshlv16qi3;
11438   else
11439     shift_insn = gen_xop_ashlv16qi3;
11440
11441   emit_insn (shift_insn (operands[0], operands[1], reg));
11442   DONE;
11443 })
11444
11445 (define_expand "ashrv2di3"
11446   [(set (match_operand:V2DI 0 "register_operand" "")
11447         (ashiftrt:V2DI
11448           (match_operand:V2DI 1 "register_operand" "")
11449           (match_operand:DI 2 "nonmemory_operand" "")))]
11450   "TARGET_XOP"
11451 {
11452   rtx reg = gen_reg_rtx (V2DImode);
11453   rtx par;
11454   bool negate = false;
11455   int i;
11456
11457   if (CONST_INT_P (operands[2]))
11458     operands[2] = GEN_INT (-INTVAL (operands[2]));
11459   else
11460     negate = true;
11461
11462   par = gen_rtx_PARALLEL (V2DImode, rtvec_alloc (2));
11463   for (i = 0; i < 2; i++)
11464     XVECEXP (par, 0, i) = operands[2];
11465
11466   emit_insn (gen_vec_initv2di (reg, par));
11467
11468   if (negate)
11469     emit_insn (gen_negv2di2 (reg, reg));
11470
11471   emit_insn (gen_xop_ashlv2di3 (operands[0], operands[1], reg));
11472   DONE;
11473 })
11474
11475 ;; XOP FRCZ support
11476 (define_insn "xop_frcz<mode>2"
11477   [(set (match_operand:FMAMODE 0 "register_operand" "=x")
11478         (unspec:FMAMODE
11479          [(match_operand:FMAMODE 1 "nonimmediate_operand" "xm")]
11480          UNSPEC_FRCZ))]
11481   "TARGET_XOP"
11482   "vfrcz<ssemodesuffix>\t{%1, %0|%0, %1}"
11483   [(set_attr "type" "ssecvt1")
11484    (set_attr "mode" "<MODE>")])
11485
11486 ;; scalar insns
11487 (define_expand "xop_vmfrcz<mode>2"
11488   [(set (match_operand:VF_128 0 "register_operand")
11489         (vec_merge:VF_128
11490           (unspec:VF_128
11491            [(match_operand:VF_128 1 "nonimmediate_operand")]
11492            UNSPEC_FRCZ)
11493           (match_dup 3)
11494           (const_int 1)))]
11495   "TARGET_XOP"
11496 {
11497   operands[3] = CONST0_RTX (<MODE>mode);
11498 })
11499
11500 (define_insn "*xop_vmfrcz_<mode>"
11501   [(set (match_operand:VF_128 0 "register_operand" "=x")
11502         (vec_merge:VF_128
11503           (unspec:VF_128
11504            [(match_operand:VF_128 1 "nonimmediate_operand" "xm")]
11505            UNSPEC_FRCZ)
11506           (match_operand:VF_128 2 "const0_operand")
11507           (const_int 1)))]
11508   "TARGET_XOP"
11509   "vfrcz<ssescalarmodesuffix>\t{%1, %0|%0, %1}"
11510   [(set_attr "type" "ssecvt1")
11511    (set_attr "mode" "<MODE>")])
11512
11513 (define_insn "xop_maskcmp<mode>3"
11514   [(set (match_operand:VI_128 0 "register_operand" "=x")
11515         (match_operator:VI_128 1 "ix86_comparison_int_operator"
11516          [(match_operand:VI_128 2 "register_operand" "x")
11517           (match_operand:VI_128 3 "nonimmediate_operand" "xm")]))]
11518   "TARGET_XOP"
11519   "vpcom%Y1<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}"
11520   [(set_attr "type" "sse4arg")
11521    (set_attr "prefix_data16" "0")
11522    (set_attr "prefix_rep" "0")
11523    (set_attr "prefix_extra" "2")
11524    (set_attr "length_immediate" "1")
11525    (set_attr "mode" "TI")])
11526
11527 (define_insn "xop_maskcmp_uns<mode>3"
11528   [(set (match_operand:VI_128 0 "register_operand" "=x")
11529         (match_operator:VI_128 1 "ix86_comparison_uns_operator"
11530          [(match_operand:VI_128 2 "register_operand" "x")
11531           (match_operand:VI_128 3 "nonimmediate_operand" "xm")]))]
11532   "TARGET_XOP"
11533   "vpcom%Y1u<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}"
11534   [(set_attr "type" "ssecmp")
11535    (set_attr "prefix_data16" "0")
11536    (set_attr "prefix_rep" "0")
11537    (set_attr "prefix_extra" "2")
11538    (set_attr "length_immediate" "1")
11539    (set_attr "mode" "TI")])
11540
11541 ;; Version of pcom*u* that is called from the intrinsics that allows pcomequ*
11542 ;; and pcomneu* not to be converted to the signed ones in case somebody needs
11543 ;; the exact instruction generated for the intrinsic.
11544 (define_insn "xop_maskcmp_uns2<mode>3"
11545   [(set (match_operand:VI_128 0 "register_operand" "=x")
11546         (unspec:VI_128
11547          [(match_operator:VI_128 1 "ix86_comparison_uns_operator"
11548           [(match_operand:VI_128 2 "register_operand" "x")
11549            (match_operand:VI_128 3 "nonimmediate_operand" "xm")])]
11550          UNSPEC_XOP_UNSIGNED_CMP))]
11551   "TARGET_XOP"
11552   "vpcom%Y1u<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}"
11553   [(set_attr "type" "ssecmp")
11554    (set_attr "prefix_data16" "0")
11555    (set_attr "prefix_extra" "2")
11556    (set_attr "length_immediate" "1")
11557    (set_attr "mode" "TI")])
11558
11559 ;; Pcomtrue and pcomfalse support.  These are useless instructions, but are
11560 ;; being added here to be complete.
11561 (define_insn "xop_pcom_tf<mode>3"
11562   [(set (match_operand:VI_128 0 "register_operand" "=x")
11563         (unspec:VI_128
11564           [(match_operand:VI_128 1 "register_operand" "x")
11565            (match_operand:VI_128 2 "nonimmediate_operand" "xm")
11566            (match_operand:SI 3 "const_int_operand" "n")]
11567           UNSPEC_XOP_TRUEFALSE))]
11568   "TARGET_XOP"
11569 {
11570   return ((INTVAL (operands[3]) != 0)
11571           ? "vpcomtrue<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11572           : "vpcomfalse<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}");
11573 }
11574   [(set_attr "type" "ssecmp")
11575    (set_attr "prefix_data16" "0")
11576    (set_attr "prefix_extra" "2")
11577    (set_attr "length_immediate" "1")
11578    (set_attr "mode" "TI")])
11579
11580 (define_insn "xop_vpermil2<mode>3"
11581   [(set (match_operand:VF 0 "register_operand" "=x")
11582         (unspec:VF
11583           [(match_operand:VF 1 "register_operand" "x")
11584            (match_operand:VF 2 "nonimmediate_operand" "%x")
11585            (match_operand:<sseintvecmode> 3 "nonimmediate_operand" "xm")
11586            (match_operand:SI 4 "const_0_to_3_operand" "n")]
11587           UNSPEC_VPERMIL2))]
11588   "TARGET_XOP"
11589   "vpermil2<ssemodesuffix>\t{%4, %3, %2, %1, %0|%0, %1, %2, %3, %4}"
11590   [(set_attr "type" "sse4arg")
11591    (set_attr "length_immediate" "1")
11592    (set_attr "mode" "<MODE>")])
11593
11594 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11595
11596 (define_insn "aesenc"
11597   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
11598         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
11599                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
11600                       UNSPEC_AESENC))]
11601   "TARGET_AES"
11602   "@
11603    aesenc\t{%2, %0|%0, %2}
11604    vaesenc\t{%2, %1, %0|%0, %1, %2}"
11605   [(set_attr "isa" "noavx,avx")
11606    (set_attr "type" "sselog1")
11607    (set_attr "prefix_extra" "1")
11608    (set_attr "prefix" "orig,vex")
11609    (set_attr "mode" "TI")])
11610
11611 (define_insn "aesenclast"
11612   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
11613         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
11614                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
11615                       UNSPEC_AESENCLAST))]
11616   "TARGET_AES"
11617   "@
11618    aesenclast\t{%2, %0|%0, %2}
11619    vaesenclast\t{%2, %1, %0|%0, %1, %2}"
11620   [(set_attr "isa" "noavx,avx")
11621    (set_attr "type" "sselog1")
11622    (set_attr "prefix_extra" "1")
11623    (set_attr "prefix" "orig,vex")
11624    (set_attr "mode" "TI")])
11625
11626 (define_insn "aesdec"
11627   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
11628         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
11629                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
11630                       UNSPEC_AESDEC))]
11631   "TARGET_AES"
11632   "@
11633    aesdec\t{%2, %0|%0, %2}
11634    vaesdec\t{%2, %1, %0|%0, %1, %2}"
11635   [(set_attr "isa" "noavx,avx")
11636    (set_attr "type" "sselog1")
11637    (set_attr "prefix_extra" "1")
11638    (set_attr "prefix" "orig,vex")
11639    (set_attr "mode" "TI")])
11640
11641 (define_insn "aesdeclast"
11642   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
11643         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
11644                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
11645                       UNSPEC_AESDECLAST))]
11646   "TARGET_AES"
11647   "@
11648    aesdeclast\t{%2, %0|%0, %2}
11649    vaesdeclast\t{%2, %1, %0|%0, %1, %2}"
11650   [(set_attr "isa" "noavx,avx")
11651    (set_attr "type" "sselog1")
11652    (set_attr "prefix_extra" "1")
11653    (set_attr "prefix" "orig,vex")
11654    (set_attr "mode" "TI")])
11655
11656 (define_insn "aesimc"
11657   [(set (match_operand:V2DI 0 "register_operand" "=x")
11658         (unspec:V2DI [(match_operand:V2DI 1 "nonimmediate_operand" "xm")]
11659                       UNSPEC_AESIMC))]
11660   "TARGET_AES"
11661   "%vaesimc\t{%1, %0|%0, %1}"
11662   [(set_attr "type" "sselog1")
11663    (set_attr "prefix_extra" "1")
11664    (set_attr "prefix" "maybe_vex")
11665    (set_attr "mode" "TI")])
11666
11667 (define_insn "aeskeygenassist"
11668   [(set (match_operand:V2DI 0 "register_operand" "=x")
11669         (unspec:V2DI [(match_operand:V2DI 1 "nonimmediate_operand" "xm")
11670                       (match_operand:SI 2 "const_0_to_255_operand" "n")]
11671                      UNSPEC_AESKEYGENASSIST))]
11672   "TARGET_AES"
11673   "%vaeskeygenassist\t{%2, %1, %0|%0, %1, %2}"
11674   [(set_attr "type" "sselog1")
11675    (set_attr "prefix_extra" "1")
11676    (set_attr "length_immediate" "1")
11677    (set_attr "prefix" "maybe_vex")
11678    (set_attr "mode" "TI")])
11679
11680 (define_insn "pclmulqdq"
11681   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
11682         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
11683                       (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")
11684                       (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
11685                      UNSPEC_PCLMUL))]
11686   "TARGET_PCLMUL"
11687   "@
11688    pclmulqdq\t{%3, %2, %0|%0, %2, %3}
11689    vpclmulqdq\t{%3, %2, %1, %0|%0, %1, %2, %3}"
11690   [(set_attr "isa" "noavx,avx")
11691    (set_attr "type" "sselog1")
11692    (set_attr "prefix_extra" "1")
11693    (set_attr "length_immediate" "1")
11694    (set_attr "prefix" "orig,vex")
11695    (set_attr "mode" "TI")])
11696
11697 (define_expand "avx_vzeroall"
11698   [(match_par_dup 0 [(const_int 0)])]
11699   "TARGET_AVX"
11700 {
11701   int nregs = TARGET_64BIT ? 16 : 8;
11702   int regno;
11703
11704   operands[0] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nregs + 1));
11705
11706   XVECEXP (operands[0], 0, 0)
11707     = gen_rtx_UNSPEC_VOLATILE (VOIDmode, gen_rtvec (1, const0_rtx),
11708                                UNSPECV_VZEROALL);
11709
11710   for (regno = 0; regno < nregs; regno++)
11711     XVECEXP (operands[0], 0, regno + 1)
11712       = gen_rtx_SET (VOIDmode,
11713                      gen_rtx_REG (V8SImode, SSE_REGNO (regno)),
11714                      CONST0_RTX (V8SImode));
11715 })
11716
11717 (define_insn "*avx_vzeroall"
11718   [(match_parallel 0 "vzeroall_operation"
11719     [(unspec_volatile [(const_int 0)] UNSPECV_VZEROALL)])]
11720   "TARGET_AVX"
11721   "vzeroall"
11722   [(set_attr "type" "sse")
11723    (set_attr "modrm" "0")
11724    (set_attr "memory" "none")
11725    (set_attr "prefix" "vex")
11726    (set_attr "mode" "OI")])
11727
11728 ;; Clear the upper 128bits of AVX registers, equivalent to a NOP
11729 ;; if the upper 128bits are unused.
11730 (define_insn "avx_vzeroupper"
11731   [(unspec_volatile [(match_operand 0 "const_int_operand" "")]
11732                     UNSPECV_VZEROUPPER)]
11733   "TARGET_AVX"
11734   "vzeroupper"
11735   [(set_attr "type" "sse")
11736    (set_attr "modrm" "0")
11737    (set_attr "memory" "none")
11738    (set_attr "prefix" "vex")
11739    (set_attr "mode" "OI")])
11740
11741 (define_mode_attr AVXTOSSEMODE
11742   [(V4DI "V2DI") (V2DI "V2DI")
11743    (V8SI "V4SI") (V4SI "V4SI")
11744    (V16HI "V8HI") (V8HI "V8HI")
11745    (V32QI "V16QI") (V16QI "V16QI")])
11746
11747 (define_insn "avx2_pbroadcast<mode>"
11748   [(set (match_operand:VI 0 "register_operand" "=x")
11749         (vec_duplicate:VI
11750           (vec_select:<ssescalarmode>
11751             (match_operand:<AVXTOSSEMODE> 1 "nonimmediate_operand" "xm")
11752             (parallel [(const_int 0)]))))]
11753   "TARGET_AVX2"
11754   "vpbroadcast<ssemodesuffix>\t{%1, %0|%0, %1}"
11755   [(set_attr "type" "ssemov")
11756    (set_attr "prefix_extra" "1")
11757    (set_attr "prefix" "vex")
11758    (set_attr "mode" "<sseinsnmode>")])
11759
11760 (define_insn "avx2_permvarv8si"
11761   [(set (match_operand:V8SI 0 "register_operand" "=x")
11762         (unspec:V8SI
11763           [(match_operand:V8SI 1 "register_operand" "x")
11764            (match_operand:V8SI 2 "nonimmediate_operand" "xm")]
11765           UNSPEC_VPERMSI))]
11766   "TARGET_AVX2"
11767   "vpermd\t{%2, %1, %0|%0, %1, %2}"
11768   [(set_attr "type" "sselog")
11769    (set_attr "prefix" "vex")
11770    (set_attr "mode" "OI")])
11771
11772 (define_insn "avx2_permv4df"
11773   [(set (match_operand:V4DF 0 "register_operand" "=x")
11774         (unspec:V4DF
11775           [(match_operand:V4DF 1 "register_operand" "xm")
11776            (match_operand:SI 2 "const_0_to_255_operand" "n")]
11777           UNSPEC_VPERMDF))]
11778   "TARGET_AVX2"
11779   "vpermpd\t{%2, %1, %0|%0, %1, %2}"
11780   [(set_attr "type" "sselog")
11781    (set_attr "prefix_extra" "1")
11782    (set_attr "prefix" "vex")
11783    (set_attr "mode" "OI")])
11784
11785 (define_insn "avx2_permvarv8sf"
11786   [(set (match_operand:V8SF 0 "register_operand" "=x")
11787         (unspec:V8SF
11788           [(match_operand:V8SF 1 "register_operand" "x")
11789            (match_operand:V8SF 2 "nonimmediate_operand" "xm")]
11790           UNSPEC_VPERMSF))]
11791   "TARGET_AVX2"
11792   "vpermps\t{%2, %1, %0|%0, %1, %2}"
11793   [(set_attr "type" "sselog")
11794    (set_attr "prefix" "vex")
11795    (set_attr "mode" "OI")])
11796
11797 (define_expand "avx2_permv4di"
11798   [(match_operand:V4DI 0 "register_operand" "")
11799    (match_operand:V4DI 1 "nonimmediate_operand" "")
11800    (match_operand:SI 2 "const_0_to_255_operand" "")]
11801   "TARGET_AVX2"
11802 {
11803   int mask = INTVAL (operands[2]);
11804   emit_insn (gen_avx2_permv4di_1 (operands[0], operands[1],
11805                                   GEN_INT ((mask >> 0) & 3),
11806                                   GEN_INT ((mask >> 2) & 3),
11807                                   GEN_INT ((mask >> 4) & 3),
11808                                   GEN_INT ((mask >> 6) & 3)));
11809   DONE;
11810 })
11811
11812 (define_insn "avx2_permv4di_1"
11813   [(set (match_operand:V4DI 0 "register_operand" "=x")
11814         (vec_select:V4DI
11815           (match_operand:V4DI 1 "nonimmediate_operand" "xm")
11816           (parallel [(match_operand 2 "const_0_to_3_operand" "")
11817                      (match_operand 3 "const_0_to_3_operand" "")
11818                      (match_operand 4 "const_0_to_3_operand" "")
11819                      (match_operand 5 "const_0_to_3_operand" "")])))]
11820   "TARGET_AVX2"
11821 {
11822   int mask = 0;
11823   mask |= INTVAL (operands[2]) << 0;
11824   mask |= INTVAL (operands[3]) << 2;
11825   mask |= INTVAL (operands[4]) << 4;
11826   mask |= INTVAL (operands[5]) << 6;
11827   operands[2] = GEN_INT (mask);
11828   return "vpermq\t{%2, %1, %0|%0, %1, %2}";
11829 }
11830   [(set_attr "type" "sselog")
11831    (set_attr "prefix" "vex")
11832    (set_attr "mode" "OI")])
11833
11834 (define_insn "avx2_permv2ti"
11835   [(set (match_operand:V4DI 0 "register_operand" "=x")
11836         (unspec:V4DI
11837           [(match_operand:V4DI 1 "register_operand" "x")
11838            (match_operand:V4DI 2 "nonimmediate_operand" "xm")
11839            (match_operand:SI 3 "const_0_to_255_operand" "n")]
11840           UNSPEC_VPERMTI))]
11841   "TARGET_AVX2"
11842   "vperm2i128\t{%3, %2, %1, %0|%0, %1, %2, %3}"
11843   [(set_attr "type" "sselog")
11844    (set_attr "prefix" "vex")
11845    (set_attr "mode" "OI")])
11846
11847 (define_insn "avx2_vec_dupv4df"
11848   [(set (match_operand:V4DF 0 "register_operand" "=x")
11849         (vec_duplicate:V4DF
11850           (vec_select:DF
11851             (match_operand:V2DF 1 "register_operand" "x")
11852             (parallel [(const_int 0)]))))]
11853   "TARGET_AVX2"
11854   "vbroadcastsd\t{%1, %0|%0, %1}"
11855   [(set_attr "type" "sselog1")
11856    (set_attr "prefix" "vex")
11857    (set_attr "mode" "V4DF")])
11858
11859 ;; Modes handled by AVX vec_dup patterns.
11860 (define_mode_iterator AVX_VEC_DUP_MODE
11861   [V8SI V8SF V4DI V4DF])
11862
11863 (define_insn "vec_dup<mode>"
11864   [(set (match_operand:AVX_VEC_DUP_MODE 0 "register_operand" "=x,x")
11865         (vec_duplicate:AVX_VEC_DUP_MODE
11866           (match_operand:<ssescalarmode> 1 "nonimmediate_operand" "m,?x")))]
11867   "TARGET_AVX"
11868   "@
11869    vbroadcast<ssescalarmodesuffix>\t{%1, %0|%0, %1}
11870    #"
11871   [(set_attr "type" "ssemov")
11872    (set_attr "prefix_extra" "1")
11873    (set_attr "prefix" "vex")
11874    (set_attr "mode" "V8SF")])
11875
11876 (define_insn "avx2_vbroadcasti128_<mode>"
11877   [(set (match_operand:VI_256 0 "register_operand" "=x")
11878         (vec_concat:VI_256
11879           (match_operand:<ssehalfvecmode> 1 "memory_operand" "m")
11880           (match_dup 1)))]
11881   "TARGET_AVX2"
11882   "vbroadcasti128\t{%1, %0|%0, %1}"
11883   [(set_attr "type" "ssemov")
11884    (set_attr "prefix_extra" "1")
11885    (set_attr "prefix" "vex")
11886    (set_attr "mode" "OI")])
11887
11888 (define_split
11889   [(set (match_operand:AVX_VEC_DUP_MODE 0 "register_operand" "")
11890         (vec_duplicate:AVX_VEC_DUP_MODE
11891           (match_operand:<ssescalarmode> 1 "register_operand" "")))]
11892   "TARGET_AVX && reload_completed"
11893   [(set (match_dup 2)
11894         (vec_duplicate:<ssehalfvecmode> (match_dup 1)))
11895    (set (match_dup 0)
11896         (vec_concat:AVX_VEC_DUP_MODE (match_dup 2) (match_dup 2)))]
11897   "operands[2] = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (operands[0]));")
11898
11899 (define_insn "avx_vbroadcastf128_<mode>"
11900   [(set (match_operand:V_256 0 "register_operand" "=x,x,x")
11901         (vec_concat:V_256
11902           (match_operand:<ssehalfvecmode> 1 "nonimmediate_operand" "m,0,?x")
11903           (match_dup 1)))]
11904   "TARGET_AVX"
11905   "@
11906    vbroadcast<i128>\t{%1, %0|%0, %1}
11907    vinsert<i128>\t{$1, %1, %0, %0|%0, %0, %1, 1}
11908    vperm2<i128>\t{$0, %t1, %t1, %0|%0, %t1, %t1, 0}"
11909   [(set_attr "type" "ssemov,sselog1,sselog1")
11910    (set_attr "prefix_extra" "1")
11911    (set_attr "length_immediate" "0,1,1")
11912    (set_attr "prefix" "vex")
11913    (set_attr "mode" "<sseinsnmode>")])
11914
11915 ;; Recognize broadcast as a vec_select as produced by builtin_vec_perm.
11916 ;; If it so happens that the input is in memory, use vbroadcast.
11917 ;; Otherwise use vpermilp (and in the case of 256-bit modes, vperm2f128).
11918 (define_insn "*avx_vperm_broadcast_v4sf"
11919   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
11920         (vec_select:V4SF
11921           (match_operand:V4SF 1 "nonimmediate_operand" "m,o,x")
11922           (match_parallel 2 "avx_vbroadcast_operand"
11923             [(match_operand 3 "const_int_operand" "C,n,n")])))]
11924   "TARGET_AVX"
11925 {
11926   int elt = INTVAL (operands[3]);
11927   switch (which_alternative)
11928     {
11929     case 0:
11930     case 1:
11931       operands[1] = adjust_address_nv (operands[1], SFmode, elt * 4);
11932       return "vbroadcastss\t{%1, %0|%0, %1}";
11933     case 2:
11934       operands[2] = GEN_INT (elt * 0x55);
11935       return "vpermilps\t{%2, %1, %0|%0, %1, %2}";
11936     default:
11937       gcc_unreachable ();
11938     }
11939 }
11940   [(set_attr "type" "ssemov,ssemov,sselog1")
11941    (set_attr "prefix_extra" "1")
11942    (set_attr "length_immediate" "0,0,1")
11943    (set_attr "prefix" "vex")
11944    (set_attr "mode" "SF,SF,V4SF")])
11945
11946 (define_insn_and_split "*avx_vperm_broadcast_<mode>"
11947   [(set (match_operand:VF_256 0 "register_operand" "=x,x,x")
11948         (vec_select:VF_256
11949           (match_operand:VF_256 1 "nonimmediate_operand" "m,o,?x")
11950           (match_parallel 2 "avx_vbroadcast_operand"
11951             [(match_operand 3 "const_int_operand" "C,n,n")])))]
11952   "TARGET_AVX"
11953   "#"
11954   "&& reload_completed"
11955   [(set (match_dup 0) (vec_duplicate:VF_256 (match_dup 1)))]
11956 {
11957   rtx op0 = operands[0], op1 = operands[1];
11958   int elt = INTVAL (operands[3]);
11959
11960   if (REG_P (op1))
11961     {
11962       int mask;
11963
11964       /* Shuffle element we care about into all elements of the 128-bit lane.
11965          The other lane gets shuffled too, but we don't care.  */
11966       if (<MODE>mode == V4DFmode)
11967         mask = (elt & 1 ? 15 : 0);
11968       else
11969         mask = (elt & 3) * 0x55;
11970       emit_insn (gen_avx_vpermil<mode> (op0, op1, GEN_INT (mask)));
11971
11972       /* Shuffle the lane we care about into both lanes of the dest.  */
11973       mask = (elt / (<ssescalarnum> / 2)) * 0x11;
11974       emit_insn (gen_avx_vperm2f128<mode>3 (op0, op0, op0, GEN_INT (mask)));
11975       DONE;
11976     }
11977
11978   operands[1] = adjust_address_nv (op1, <ssescalarmode>mode,
11979                                    elt * GET_MODE_SIZE (<ssescalarmode>mode));
11980 })
11981
11982 (define_expand "avx_vpermil<mode>"
11983   [(set (match_operand:VF2 0 "register_operand" "")
11984         (vec_select:VF2
11985           (match_operand:VF2 1 "nonimmediate_operand" "")
11986           (match_operand:SI 2 "const_0_to_255_operand" "")))]
11987   "TARGET_AVX"
11988 {
11989   int mask = INTVAL (operands[2]);
11990   rtx perm[<ssescalarnum>];
11991
11992   perm[0] = GEN_INT (mask & 1);
11993   perm[1] = GEN_INT ((mask >> 1) & 1);
11994   if (<MODE>mode == V4DFmode)
11995     {
11996       perm[2] = GEN_INT (((mask >> 2) & 1) + 2);
11997       perm[3] = GEN_INT (((mask >> 3) & 1) + 2);
11998     }
11999
12000   operands[2]
12001     = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (<ssescalarnum>, perm));
12002 })
12003
12004 (define_expand "avx_vpermil<mode>"
12005   [(set (match_operand:VF1 0 "register_operand" "")
12006         (vec_select:VF1
12007           (match_operand:VF1 1 "nonimmediate_operand" "")
12008           (match_operand:SI 2 "const_0_to_255_operand" "")))]
12009   "TARGET_AVX"
12010 {
12011   int mask = INTVAL (operands[2]);
12012   rtx perm[<ssescalarnum>];
12013
12014   perm[0] = GEN_INT (mask & 3);
12015   perm[1] = GEN_INT ((mask >> 2) & 3);
12016   perm[2] = GEN_INT ((mask >> 4) & 3);
12017   perm[3] = GEN_INT ((mask >> 6) & 3);
12018   if (<MODE>mode == V8SFmode)
12019     {
12020       perm[4] = GEN_INT ((mask & 3) + 4);
12021       perm[5] = GEN_INT (((mask >> 2) & 3) + 4);
12022       perm[6] = GEN_INT (((mask >> 4) & 3) + 4);
12023       perm[7] = GEN_INT (((mask >> 6) & 3) + 4);
12024     }
12025
12026   operands[2]
12027     = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (<ssescalarnum>, perm));
12028 })
12029
12030 (define_insn "*avx_vpermilp<mode>"
12031   [(set (match_operand:VF 0 "register_operand" "=x")
12032         (vec_select:VF
12033           (match_operand:VF 1 "nonimmediate_operand" "xm")
12034           (match_parallel 2 ""
12035             [(match_operand 3 "const_int_operand" "")])))]
12036   "TARGET_AVX
12037    && avx_vpermilp_parallel (operands[2], <MODE>mode)"
12038 {
12039   int mask = avx_vpermilp_parallel (operands[2], <MODE>mode) - 1;
12040   operands[2] = GEN_INT (mask);
12041   return "vpermil<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}";
12042 }
12043   [(set_attr "type" "sselog")
12044    (set_attr "prefix_extra" "1")
12045    (set_attr "length_immediate" "1")
12046    (set_attr "prefix" "vex")
12047    (set_attr "mode" "<MODE>")])
12048
12049 (define_insn "avx_vpermilvar<mode>3"
12050   [(set (match_operand:VF 0 "register_operand" "=x")
12051         (unspec:VF
12052           [(match_operand:VF 1 "register_operand" "x")
12053            (match_operand:<sseintvecmode> 2 "nonimmediate_operand" "xm")]
12054           UNSPEC_VPERMIL))]
12055   "TARGET_AVX"
12056   "vpermil<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
12057   [(set_attr "type" "sselog")
12058    (set_attr "prefix_extra" "1")
12059    (set_attr "prefix" "vex")
12060    (set_attr "mode" "<MODE>")])
12061
12062 (define_expand "avx_vperm2f128<mode>3"
12063   [(set (match_operand:AVX256MODE2P 0 "register_operand" "")
12064         (unspec:AVX256MODE2P
12065           [(match_operand:AVX256MODE2P 1 "register_operand" "")
12066            (match_operand:AVX256MODE2P 2 "nonimmediate_operand" "")
12067            (match_operand:SI 3 "const_0_to_255_operand" "")]
12068           UNSPEC_VPERMIL2F128))]
12069   "TARGET_AVX"
12070 {
12071   int mask = INTVAL (operands[3]);
12072   if ((mask & 0x88) == 0)
12073     {
12074       rtx perm[<ssescalarnum>], t1, t2;
12075       int i, base, nelt = <ssescalarnum>, nelt2 = nelt / 2;
12076
12077       base = (mask & 3) * nelt2;
12078       for (i = 0; i < nelt2; ++i)
12079         perm[i] = GEN_INT (base + i);
12080
12081       base = ((mask >> 4) & 3) * nelt2;
12082       for (i = 0; i < nelt2; ++i)
12083         perm[i + nelt2] = GEN_INT (base + i);
12084
12085       t2 = gen_rtx_VEC_CONCAT (<ssedoublevecmode>mode,
12086                                operands[1], operands[2]);
12087       t1 = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nelt, perm));
12088       t2 = gen_rtx_VEC_SELECT (<MODE>mode, t2, t1);
12089       t2 = gen_rtx_SET (VOIDmode, operands[0], t2);
12090       emit_insn (t2);
12091       DONE;
12092     }
12093 })
12094
12095 ;; Note that bits 7 and 3 of the imm8 allow lanes to be zeroed, which
12096 ;; means that in order to represent this properly in rtl we'd have to
12097 ;; nest *another* vec_concat with a zero operand and do the select from
12098 ;; a 4x wide vector.  That doesn't seem very nice.
12099 (define_insn "*avx_vperm2f128<mode>_full"
12100   [(set (match_operand:AVX256MODE2P 0 "register_operand" "=x")
12101         (unspec:AVX256MODE2P
12102           [(match_operand:AVX256MODE2P 1 "register_operand" "x")
12103            (match_operand:AVX256MODE2P 2 "nonimmediate_operand" "xm")
12104            (match_operand:SI 3 "const_0_to_255_operand" "n")]
12105           UNSPEC_VPERMIL2F128))]
12106   "TARGET_AVX"
12107   "vperm2<i128>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
12108   [(set_attr "type" "sselog")
12109    (set_attr "prefix_extra" "1")
12110    (set_attr "length_immediate" "1")
12111    (set_attr "prefix" "vex")
12112    (set_attr "mode" "<sseinsnmode>")])
12113
12114 (define_insn "*avx_vperm2f128<mode>_nozero"
12115   [(set (match_operand:AVX256MODE2P 0 "register_operand" "=x")
12116         (vec_select:AVX256MODE2P
12117           (vec_concat:<ssedoublevecmode>
12118             (match_operand:AVX256MODE2P 1 "register_operand" "x")
12119             (match_operand:AVX256MODE2P 2 "nonimmediate_operand" "xm"))
12120           (match_parallel 3 ""
12121             [(match_operand 4 "const_int_operand" "")])))]
12122   "TARGET_AVX
12123    && avx_vperm2f128_parallel (operands[3], <MODE>mode)"
12124 {
12125   int mask = avx_vperm2f128_parallel (operands[3], <MODE>mode) - 1;
12126   operands[3] = GEN_INT (mask);
12127   return "vperm2<i128>\t{%3, %2, %1, %0|%0, %1, %2, %3}";
12128 }
12129   [(set_attr "type" "sselog")
12130    (set_attr "prefix_extra" "1")
12131    (set_attr "length_immediate" "1")
12132    (set_attr "prefix" "vex")
12133    (set_attr "mode" "<sseinsnmode>")])
12134
12135 (define_expand "avx_vinsertf128<mode>"
12136   [(match_operand:V_256 0 "register_operand" "")
12137    (match_operand:V_256 1 "register_operand" "")
12138    (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "")
12139    (match_operand:SI 3 "const_0_to_1_operand" "")]
12140   "TARGET_AVX"
12141 {
12142   rtx (*insn)(rtx, rtx, rtx);
12143
12144   switch (INTVAL (operands[3]))
12145     {
12146     case 0:
12147       insn = gen_vec_set_lo_<mode>;
12148       break;
12149     case 1:
12150       insn = gen_vec_set_hi_<mode>;
12151       break;
12152     default:
12153       gcc_unreachable ();
12154     }
12155
12156   emit_insn (insn (operands[0], operands[1], operands[2]));
12157   DONE;
12158 })
12159
12160 (define_insn "avx2_vec_set_lo_v4di"
12161   [(set (match_operand:V4DI 0 "register_operand" "=x")
12162         (vec_concat:V4DI
12163           (match_operand:V2DI 2 "nonimmediate_operand" "xm")
12164           (vec_select:V2DI
12165             (match_operand:V4DI 1 "register_operand" "x")
12166             (parallel [(const_int 2) (const_int 3)]))))]
12167   "TARGET_AVX2"
12168   "vinserti128\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
12169   [(set_attr "type" "sselog")
12170    (set_attr "prefix_extra" "1")
12171    (set_attr "length_immediate" "1")
12172    (set_attr "prefix" "vex")
12173    (set_attr "mode" "OI")])
12174
12175 (define_insn "avx2_vec_set_hi_v4di"
12176   [(set (match_operand:V4DI 0 "register_operand" "=x")
12177         (vec_concat:V4DI
12178           (vec_select:V2DI
12179             (match_operand:V4DI 1 "register_operand" "x")
12180             (parallel [(const_int 0) (const_int 1)]))
12181           (match_operand:V2DI 2 "nonimmediate_operand" "xm")))]
12182   "TARGET_AVX2"
12183   "vinserti128\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
12184   [(set_attr "type" "sselog")
12185    (set_attr "prefix_extra" "1")
12186    (set_attr "length_immediate" "1")
12187    (set_attr "prefix" "vex")
12188    (set_attr "mode" "OI")])
12189
12190 (define_insn "vec_set_lo_<mode>"
12191   [(set (match_operand:VI8F_256 0 "register_operand" "=x")
12192         (vec_concat:VI8F_256
12193           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "xm")
12194           (vec_select:<ssehalfvecmode>
12195             (match_operand:VI8F_256 1 "register_operand" "x")
12196             (parallel [(const_int 2) (const_int 3)]))))]
12197   "TARGET_AVX"
12198   "vinsert<i128>\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
12199   [(set_attr "type" "sselog")
12200    (set_attr "prefix_extra" "1")
12201    (set_attr "length_immediate" "1")
12202    (set_attr "prefix" "vex")
12203    (set_attr "mode" "<sseinsnmode>")])
12204
12205 (define_insn "vec_set_hi_<mode>"
12206   [(set (match_operand:VI8F_256 0 "register_operand" "=x")
12207         (vec_concat:VI8F_256
12208           (vec_select:<ssehalfvecmode>
12209             (match_operand:VI8F_256 1 "register_operand" "x")
12210             (parallel [(const_int 0) (const_int 1)]))
12211           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "xm")))]
12212   "TARGET_AVX"
12213   "vinsert<i128>\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
12214   [(set_attr "type" "sselog")
12215    (set_attr "prefix_extra" "1")
12216    (set_attr "length_immediate" "1")
12217    (set_attr "prefix" "vex")
12218    (set_attr "mode" "<sseinsnmode>")])
12219
12220 (define_insn "vec_set_lo_<mode>"
12221   [(set (match_operand:VI4F_256 0 "register_operand" "=x")
12222         (vec_concat:VI4F_256
12223           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "xm")
12224           (vec_select:<ssehalfvecmode>
12225             (match_operand:VI4F_256 1 "register_operand" "x")
12226             (parallel [(const_int 4) (const_int 5)
12227                        (const_int 6) (const_int 7)]))))]
12228   "TARGET_AVX"
12229   "vinsert<i128>\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
12230   [(set_attr "type" "sselog")
12231    (set_attr "prefix_extra" "1")
12232    (set_attr "length_immediate" "1")
12233    (set_attr "prefix" "vex")
12234    (set_attr "mode" "<sseinsnmode>")])
12235
12236 (define_insn "vec_set_hi_<mode>"
12237   [(set (match_operand:VI4F_256 0 "register_operand" "=x")
12238         (vec_concat:VI4F_256
12239           (vec_select:<ssehalfvecmode>
12240             (match_operand:VI4F_256 1 "register_operand" "x")
12241             (parallel [(const_int 0) (const_int 1)
12242                        (const_int 2) (const_int 3)]))
12243           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "xm")))]
12244   "TARGET_AVX"
12245   "vinsert<i128>\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
12246   [(set_attr "type" "sselog")
12247    (set_attr "prefix_extra" "1")
12248    (set_attr "length_immediate" "1")
12249    (set_attr "prefix" "vex")
12250    (set_attr "mode" "<sseinsnmode>")])
12251
12252 (define_insn "vec_set_lo_v16hi"
12253   [(set (match_operand:V16HI 0 "register_operand" "=x")
12254         (vec_concat:V16HI
12255           (match_operand:V8HI 2 "nonimmediate_operand" "xm")
12256           (vec_select:V8HI
12257             (match_operand:V16HI 1 "register_operand" "x")
12258             (parallel [(const_int 8) (const_int 9)
12259                        (const_int 10) (const_int 11)
12260                        (const_int 12) (const_int 13)
12261                        (const_int 14) (const_int 15)]))))]
12262   "TARGET_AVX"
12263   "vinsert%~128\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
12264   [(set_attr "type" "sselog")
12265    (set_attr "prefix_extra" "1")
12266    (set_attr "length_immediate" "1")
12267    (set_attr "prefix" "vex")
12268    (set_attr "mode" "OI")])
12269
12270 (define_insn "vec_set_hi_v16hi"
12271   [(set (match_operand:V16HI 0 "register_operand" "=x")
12272         (vec_concat:V16HI
12273           (vec_select:V8HI
12274             (match_operand:V16HI 1 "register_operand" "x")
12275             (parallel [(const_int 0) (const_int 1)
12276                        (const_int 2) (const_int 3)
12277                        (const_int 4) (const_int 5)
12278                        (const_int 6) (const_int 7)]))
12279           (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
12280   "TARGET_AVX"
12281   "vinsert%~128\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
12282   [(set_attr "type" "sselog")
12283    (set_attr "prefix_extra" "1")
12284    (set_attr "length_immediate" "1")
12285    (set_attr "prefix" "vex")
12286    (set_attr "mode" "OI")])
12287
12288 (define_insn "vec_set_lo_v32qi"
12289   [(set (match_operand:V32QI 0 "register_operand" "=x")
12290         (vec_concat:V32QI
12291           (match_operand:V16QI 2 "nonimmediate_operand" "xm")
12292           (vec_select:V16QI
12293             (match_operand:V32QI 1 "register_operand" "x")
12294             (parallel [(const_int 16) (const_int 17)
12295                        (const_int 18) (const_int 19)
12296                        (const_int 20) (const_int 21)
12297                        (const_int 22) (const_int 23)
12298                        (const_int 24) (const_int 25)
12299                        (const_int 26) (const_int 27)
12300                        (const_int 28) (const_int 29)
12301                        (const_int 30) (const_int 31)]))))]
12302   "TARGET_AVX"
12303   "vinsert%~128\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
12304   [(set_attr "type" "sselog")
12305    (set_attr "prefix_extra" "1")
12306    (set_attr "length_immediate" "1")
12307    (set_attr "prefix" "vex")
12308    (set_attr "mode" "OI")])
12309
12310 (define_insn "vec_set_hi_v32qi"
12311   [(set (match_operand:V32QI 0 "register_operand" "=x")
12312         (vec_concat:V32QI
12313           (vec_select:V16QI
12314             (match_operand:V32QI 1 "register_operand" "x")
12315             (parallel [(const_int 0) (const_int 1)
12316                        (const_int 2) (const_int 3)
12317                        (const_int 4) (const_int 5)
12318                        (const_int 6) (const_int 7)
12319                        (const_int 8) (const_int 9)
12320                        (const_int 10) (const_int 11)
12321                        (const_int 12) (const_int 13)
12322                        (const_int 14) (const_int 15)]))
12323           (match_operand:V16QI 2 "nonimmediate_operand" "xm")))]
12324   "TARGET_AVX"
12325   "vinsert%~128\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
12326   [(set_attr "type" "sselog")
12327    (set_attr "prefix_extra" "1")
12328    (set_attr "length_immediate" "1")
12329    (set_attr "prefix" "vex")
12330    (set_attr "mode" "OI")])
12331
12332 (define_insn "<avx_avx2>_maskload<ssemodesuffix><avxsizesuffix>"
12333   [(set (match_operand:V48_AVX2 0 "register_operand" "=x")
12334         (unspec:V48_AVX2
12335           [(match_operand:<sseintvecmode> 2 "register_operand" "x")
12336            (match_operand:V48_AVX2 1 "memory_operand" "m")]
12337           UNSPEC_MASKMOV))]
12338   "TARGET_AVX"
12339   "v<sseintprefix>maskmov<ssemodesuffix>\t{%1, %2, %0|%0, %2, %1}"
12340   [(set_attr "type" "sselog1")
12341    (set_attr "prefix_extra" "1")
12342    (set_attr "prefix" "vex")
12343    (set_attr "mode" "<sseinsnmode>")])
12344
12345 (define_insn "<avx_avx2>_maskstore<ssemodesuffix><avxsizesuffix>"
12346   [(set (match_operand:V48_AVX2 0 "memory_operand" "=m")
12347         (unspec:V48_AVX2
12348           [(match_operand:<sseintvecmode> 1 "register_operand" "x")
12349            (match_operand:V48_AVX2 2 "register_operand" "x")
12350            (match_dup 0)]
12351           UNSPEC_MASKMOV))]
12352   "TARGET_AVX"
12353   "v<sseintprefix>maskmov<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
12354   [(set_attr "type" "sselog1")
12355    (set_attr "prefix_extra" "1")
12356    (set_attr "prefix" "vex")
12357    (set_attr "mode" "<sseinsnmode>")])
12358
12359 (define_insn_and_split "avx_<castmode><avxsizesuffix>_<castmode>"
12360   [(set (match_operand:AVX256MODE2P 0 "nonimmediate_operand" "=x,m")
12361         (unspec:AVX256MODE2P
12362           [(match_operand:<ssehalfvecmode> 1 "nonimmediate_operand" "xm,x")]
12363           UNSPEC_CAST))]
12364   "TARGET_AVX"
12365   "#"
12366   "&& reload_completed"
12367   [(const_int 0)]
12368 {
12369   rtx op0 = operands[0];
12370   rtx op1 = operands[1];
12371   if (REG_P (op0))
12372     op0 = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (op0));
12373   else
12374     op1 = gen_rtx_REG (<MODE>mode, REGNO (op1));
12375   emit_move_insn (op0, op1);
12376   DONE;
12377 })
12378
12379 (define_expand "vec_init<mode>"
12380   [(match_operand:V_256 0 "register_operand" "")
12381    (match_operand 1 "" "")]
12382   "TARGET_AVX"
12383 {
12384   ix86_expand_vector_init (false, operands[0], operands[1]);
12385   DONE;
12386 })
12387
12388 (define_expand "avx2_extracti128"
12389   [(match_operand:V2DI 0 "nonimmediate_operand" "")
12390    (match_operand:V4DI 1 "register_operand" "")
12391    (match_operand:SI 2 "const_0_to_1_operand" "")]
12392   "TARGET_AVX2"
12393 {
12394   rtx (*insn)(rtx, rtx);
12395
12396   switch (INTVAL (operands[2]))
12397     {
12398     case 0:
12399       insn = gen_vec_extract_lo_v4di;
12400       break;
12401     case 1:
12402       insn = gen_vec_extract_hi_v4di;
12403       break;
12404     default:
12405       gcc_unreachable ();
12406     }
12407
12408   emit_insn (insn (operands[0], operands[1]));
12409   DONE;
12410 })
12411
12412 (define_expand "avx2_inserti128"
12413   [(match_operand:V4DI 0 "register_operand" "")
12414    (match_operand:V4DI 1 "register_operand" "")
12415    (match_operand:V2DI 2 "nonimmediate_operand" "")
12416    (match_operand:SI 3 "const_0_to_1_operand" "")]
12417   "TARGET_AVX2"
12418 {
12419   rtx (*insn)(rtx, rtx, rtx);
12420
12421   switch (INTVAL (operands[3]))
12422     {
12423     case 0:
12424       insn = gen_avx2_vec_set_lo_v4di;
12425       break;
12426     case 1:
12427       insn = gen_avx2_vec_set_hi_v4di;
12428       break;
12429     default:
12430       gcc_unreachable ();
12431     }
12432
12433   emit_insn (insn (operands[0], operands[1], operands[2]));
12434   DONE;
12435 })
12436
12437 (define_insn "avx2_ashrv<mode>"
12438   [(set (match_operand:VI4_AVX2 0 "register_operand" "=x")
12439         (ashiftrt:VI4_AVX2
12440           (match_operand:VI4_AVX2 1 "register_operand" "x")
12441           (match_operand:VI4_AVX2 2 "nonimmediate_operand" "xm")))]
12442   "TARGET_AVX2"
12443   "vpsravd\t{%2, %1, %0|%0, %1, %2}"
12444   [(set_attr "type" "sseishft")
12445    (set_attr "prefix" "vex")
12446    (set_attr "mode" "<sseinsnmode>")])
12447
12448 (define_insn "avx2_<shift_insn>v<mode>"
12449   [(set (match_operand:VI48_AVX2 0 "register_operand" "=x")
12450         (any_lshift:VI48_AVX2
12451           (match_operand:VI48_AVX2 1 "register_operand" "x")
12452           (match_operand:VI48_AVX2 2 "nonimmediate_operand" "xm")))]
12453   "TARGET_AVX2"
12454   "vp<vshift>v<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
12455   [(set_attr "type" "sseishft")
12456    (set_attr "prefix" "vex")
12457    (set_attr "mode" "<sseinsnmode>")])
12458
12459 (define_insn "avx_vec_concat<mode>"
12460   [(set (match_operand:V_256 0 "register_operand" "=x,x")
12461         (vec_concat:V_256
12462           (match_operand:<ssehalfvecmode> 1 "register_operand" "x,x")
12463           (match_operand:<ssehalfvecmode> 2 "vector_move_operand" "xm,C")))]
12464   "TARGET_AVX"
12465 {
12466   switch (which_alternative)
12467     {
12468     case 0:
12469       return "vinsert<i128>\t{$0x1, %2, %t1, %0|%0, %t1, %2, 0x1}";
12470     case 1:
12471       switch (get_attr_mode (insn))
12472         {
12473         case MODE_V8SF:
12474           return "vmovaps\t{%1, %x0|%x0, %1}";
12475         case MODE_V4DF:
12476           return "vmovapd\t{%1, %x0|%x0, %1}";
12477         default:
12478           return "vmovdqa\t{%1, %x0|%x0, %1}";
12479         }
12480     default:
12481       gcc_unreachable ();
12482     }
12483 }
12484   [(set_attr "type" "sselog,ssemov")
12485    (set_attr "prefix_extra" "1,*")
12486    (set_attr "length_immediate" "1,*")
12487    (set_attr "prefix" "vex")
12488    (set_attr "mode" "<sseinsnmode>")])
12489
12490 (define_insn "vcvtph2ps"
12491   [(set (match_operand:V4SF 0 "register_operand" "=x")
12492         (vec_select:V4SF
12493           (unspec:V8SF [(match_operand:V8HI 1 "register_operand" "x")]
12494                        UNSPEC_VCVTPH2PS)
12495           (parallel [(const_int 0) (const_int 1)
12496                      (const_int 1) (const_int 2)])))]
12497   "TARGET_F16C"
12498   "vcvtph2ps\t{%1, %0|%0, %1}"
12499   [(set_attr "type" "ssecvt")
12500    (set_attr "prefix" "vex")
12501    (set_attr "mode" "V4SF")])
12502
12503 (define_insn "*vcvtph2ps_load"
12504   [(set (match_operand:V4SF 0 "register_operand" "=x")
12505         (unspec:V4SF [(match_operand:V4HI 1 "memory_operand" "m")]
12506                      UNSPEC_VCVTPH2PS))]
12507   "TARGET_F16C"
12508   "vcvtph2ps\t{%1, %0|%0, %1}"
12509   [(set_attr "type" "ssecvt")
12510    (set_attr "prefix" "vex")
12511    (set_attr "mode" "V8SF")])
12512
12513 (define_insn "vcvtph2ps256"
12514   [(set (match_operand:V8SF 0 "register_operand" "=x")
12515         (unspec:V8SF [(match_operand:V8HI 1 "nonimmediate_operand" "xm")]
12516                      UNSPEC_VCVTPH2PS))]
12517   "TARGET_F16C"
12518   "vcvtph2ps\t{%1, %0|%0, %1}"
12519   [(set_attr "type" "ssecvt")
12520    (set_attr "prefix" "vex")
12521    (set_attr "mode" "V8SF")])
12522
12523 (define_expand "vcvtps2ph"
12524   [(set (match_operand:V8HI 0 "register_operand" "")
12525         (vec_concat:V8HI
12526           (unspec:V4HI [(match_operand:V4SF 1 "register_operand" "")
12527                         (match_operand:SI 2 "const_0_to_255_operand" "")]
12528                        UNSPEC_VCVTPS2PH)
12529           (match_dup 3)))]
12530   "TARGET_F16C"
12531   "operands[3] = CONST0_RTX (V4HImode);")
12532
12533 (define_insn "*vcvtps2ph"
12534   [(set (match_operand:V8HI 0 "register_operand" "=x")
12535         (vec_concat:V8HI
12536           (unspec:V4HI [(match_operand:V4SF 1 "register_operand" "x")
12537                         (match_operand:SI 2 "const_0_to_255_operand" "N")]
12538                        UNSPEC_VCVTPS2PH)
12539           (match_operand:V4HI 3 "const0_operand" "")))]
12540   "TARGET_F16C"
12541   "vcvtps2ph\t{%2, %1, %0|%0, %1, %2}"
12542   [(set_attr "type" "ssecvt")
12543    (set_attr "prefix" "vex")
12544    (set_attr "mode" "V4SF")])
12545
12546 (define_insn "*vcvtps2ph_store"
12547   [(set (match_operand:V4HI 0 "memory_operand" "=m")
12548         (unspec:V4HI [(match_operand:V4SF 1 "register_operand" "x")
12549                       (match_operand:SI 2 "const_0_to_255_operand" "N")]
12550                      UNSPEC_VCVTPS2PH))]
12551   "TARGET_F16C"
12552   "vcvtps2ph\t{%2, %1, %0|%0, %1, %2}"
12553   [(set_attr "type" "ssecvt")
12554    (set_attr "prefix" "vex")
12555    (set_attr "mode" "V4SF")])
12556
12557 (define_insn "vcvtps2ph256"
12558   [(set (match_operand:V8HI 0 "nonimmediate_operand" "=xm")
12559         (unspec:V8HI [(match_operand:V8SF 1 "register_operand" "x")
12560                       (match_operand:SI 2 "const_0_to_255_operand" "N")]
12561                      UNSPEC_VCVTPS2PH))]
12562   "TARGET_F16C"
12563   "vcvtps2ph\t{%2, %1, %0|%0, %1, %2}"
12564   [(set_attr "type" "ssecvt")
12565    (set_attr "prefix" "vex")
12566    (set_attr "mode" "V8SF")])
12567
12568 ;; For gather* insn patterns
12569 (define_mode_iterator VEC_GATHER_MODE
12570                       [V2DI V2DF V4DI V4DF V4SI V4SF V8SI V8SF])
12571 (define_mode_attr VEC_GATHER_MODE
12572                       [(V2DI "V4SI") (V2DF "V4SI")
12573                        (V4DI "V4SI") (V4DF "V4SI")
12574                        (V4SI "V4SI") (V4SF "V4SI")
12575                        (V8SI "V8SI") (V8SF "V8SI")])
12576
12577 (define_expand "avx2_gathersi<mode>"
12578   [(parallel [(set (match_operand:VEC_GATHER_MODE 0 "register_operand" "")
12579                    (unspec:VEC_GATHER_MODE
12580                      [(match_operand:VEC_GATHER_MODE 1 "register_operand" "")
12581                       (mem:<ssescalarmode>
12582                         (match_par_dup 7
12583                           [(match_operand 2 "vsib_address_operand" "")
12584                            (match_operand:<VEC_GATHER_MODE> 3 "register_operand" "")
12585                            (match_operand:SI 5 "const1248_operand " "")]))
12586                       (mem:BLK (scratch))
12587                       (match_operand:VEC_GATHER_MODE 4 "register_operand" "")]
12588                      UNSPEC_GATHER))
12589               (clobber (match_scratch:VEC_GATHER_MODE 6 ""))])]
12590   "TARGET_AVX2"
12591 {
12592   operands[7]
12593     = gen_rtx_UNSPEC (Pmode, gen_rtvec (3, operands[2], operands[3],
12594                                         operands[5]), UNSPEC_VSIBADDR);
12595 })
12596
12597 (define_insn "*avx2_gathersi<mode>"
12598   [(set (match_operand:VEC_GATHER_MODE 0 "register_operand" "=&x")
12599         (unspec:VEC_GATHER_MODE
12600           [(match_operand:VEC_GATHER_MODE 2 "register_operand" "0")
12601            (match_operator:<ssescalarmode> 7 "vsib_mem_operator"
12602              [(unspec:P
12603                 [(match_operand:P 3 "vsib_address_operand" "p")
12604                  (match_operand:<VEC_GATHER_MODE> 4 "register_operand" "x")
12605                  (match_operand:SI 6 "const1248_operand" "n")]
12606                 UNSPEC_VSIBADDR)])
12607            (mem:BLK (scratch))
12608            (match_operand:VEC_GATHER_MODE 5 "register_operand" "1")]
12609           UNSPEC_GATHER))
12610    (clobber (match_scratch:VEC_GATHER_MODE 1 "=&x"))]
12611   "TARGET_AVX2"
12612   "v<sseintprefix>gatherd<ssemodesuffix>\t{%1, %7, %0|%0, %7, %1}"
12613   [(set_attr "type" "ssemov")
12614    (set_attr "prefix" "vex")
12615    (set_attr "mode" "<sseinsnmode>")])
12616
12617 (define_expand "avx2_gatherdi<mode>"
12618   [(parallel [(set (match_operand:VEC_GATHER_MODE 0 "register_operand" "")
12619                    (unspec:VEC_GATHER_MODE
12620                      [(match_operand:VEC_GATHER_MODE 1 "register_operand" "")
12621                       (mem:<ssescalarmode>
12622                         (match_par_dup 7
12623                           [(match_operand 2 "vsib_address_operand" "")
12624                            (match_operand:<AVXMODE48P_DI> 3 "register_operand" "")
12625                            (match_operand:SI 5 "const1248_operand " "")]))
12626                       (mem:BLK (scratch))
12627                       (match_operand:VEC_GATHER_MODE 4 "register_operand" "")]
12628                      UNSPEC_GATHER))
12629               (clobber (match_scratch:VEC_GATHER_MODE 6 ""))])]
12630   "TARGET_AVX2"
12631 {
12632   operands[7]
12633     = gen_rtx_UNSPEC (Pmode, gen_rtvec (3, operands[2], operands[3],
12634                                         operands[5]), UNSPEC_VSIBADDR);
12635 })
12636
12637 (define_insn "*avx2_gatherdi<mode>"
12638   [(set (match_operand:AVXMODE48P_DI 0 "register_operand" "=&x")
12639         (unspec:AVXMODE48P_DI
12640           [(match_operand:AVXMODE48P_DI 2 "register_operand" "0")
12641            (match_operator:<ssescalarmode> 7 "vsib_mem_operator"
12642              [(unspec:P
12643                 [(match_operand:P 3 "vsib_address_operand" "p")
12644                  (match_operand:<AVXMODE48P_DI> 4 "register_operand" "x")
12645                  (match_operand:SI 6 "const1248_operand" "n")]
12646                 UNSPEC_VSIBADDR)])
12647            (mem:BLK (scratch))
12648            (match_operand:AVXMODE48P_DI 5 "register_operand" "1")]
12649           UNSPEC_GATHER))
12650    (clobber (match_scratch:AVXMODE48P_DI 1 "=&x"))]
12651   "TARGET_AVX2"
12652   "v<sseintprefix>gatherq<ssemodesuffix>\t{%1, %7, %0|%0, %7, %1}"
12653   [(set_attr "type" "ssemov")
12654    (set_attr "prefix" "vex")
12655    (set_attr "mode" "<sseinsnmode>")])
12656
12657 ;; Special handling for VEX.256 with float arguments
12658 ;; since there're still xmms as operands
12659 (define_expand "avx2_gatherdi<mode>256"
12660   [(parallel [(set (match_operand:VI4F_128 0 "register_operand" "")
12661                    (unspec:VI4F_128
12662                      [(match_operand:VI4F_128 1 "register_operand" "")
12663                       (mem:<ssescalarmode>
12664                         (match_par_dup 7
12665                           [(match_operand 2 "vsib_address_operand" "")
12666                            (match_operand:V4DI 3 "register_operand" "")
12667                            (match_operand:SI 5 "const1248_operand " "")]))
12668                       (mem:BLK (scratch))
12669                       (match_operand:VI4F_128 4 "register_operand" "")]
12670                      UNSPEC_GATHER))
12671               (clobber (match_scratch:VI4F_128 6 ""))])]
12672   "TARGET_AVX2"
12673 {
12674   operands[7]
12675     = gen_rtx_UNSPEC (Pmode, gen_rtvec (3, operands[2], operands[3],
12676                                         operands[5]), UNSPEC_VSIBADDR);
12677 })
12678
12679 (define_insn "*avx2_gatherdi<mode>256"
12680   [(set (match_operand:VI4F_128 0 "register_operand" "=x")
12681         (unspec:VI4F_128
12682           [(match_operand:VI4F_128 2 "register_operand" "0")
12683            (match_operator:<ssescalarmode> 7 "vsib_mem_operator"
12684              [(unspec:P
12685                 [(match_operand:P 3 "vsib_address_operand" "p")
12686                  (match_operand:V4DI 4 "register_operand" "x")
12687                  (match_operand:SI 6 "const1248_operand" "n")]
12688                 UNSPEC_VSIBADDR)])
12689            (mem:BLK (scratch))
12690            (match_operand:VI4F_128 5 "register_operand" "1")]
12691           UNSPEC_GATHER)) 
12692    (clobber (match_scratch:VI4F_128 1 "=&x"))]
12693   "TARGET_AVX2"
12694   "v<sseintprefix>gatherq<ssemodesuffix>\t{%1, %7, %0|%0, %7, %1}"
12695   [(set_attr "type" "ssemov")
12696    (set_attr "prefix" "vex")
12697    (set_attr "mode" "<sseinsnmode>")])