OSDN Git Service

* config/i386/sse.md (vec_set<mode>): Change V_128 iterator mode
[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 V4SI V4DI V2DI])
130
131 (define_mode_iterator VI4SD_AVX2
132   [V4SI V4DI])
133
134 (define_mode_iterator V48_AVX2
135   [V4SF V2DF
136    V8SF V4DF
137    (V4SI "TARGET_AVX2") (V2DI "TARGET_AVX2")
138    (V8SI "TARGET_AVX2") (V4DI "TARGET_AVX2")])
139
140 (define_mode_attr sse2_avx2
141   [(V16QI "sse2") (V32QI "avx2")
142    (V8HI "sse2") (V16HI "avx2")
143    (V4SI "sse2") (V8SI "avx2")
144    (V2DI "sse2") (V4DI "avx2")
145    (V1TI "sse2") (V2TI "avx2")])
146
147 (define_mode_attr ssse3_avx2
148    [(V16QI "ssse3") (V32QI "avx2")
149     (V8HI "ssse3") (V16HI "avx2")
150     (V4SI "ssse3") (V8SI "avx2")
151     (V2DI "ssse3") (V4DI "avx2")
152     (TI "ssse3") (V2TI "avx2")])
153
154 (define_mode_attr sse4_1_avx2
155    [(V16QI "sse4_1") (V32QI "avx2")
156     (V8HI "sse4_1") (V16HI "avx2")
157     (V4SI "sse4_1") (V8SI "avx2")
158     (V2DI "sse4_1") (V4DI "avx2")])
159
160 (define_mode_attr avx_avx2
161   [(V4SF "avx") (V2DF "avx")
162    (V8SF "avx") (V4DF "avx")
163    (V4SI "avx2") (V2DI "avx2")
164    (V8SI "avx2") (V4DI "avx2")])
165
166 (define_mode_attr vec_avx2
167   [(V16QI "vec") (V32QI "avx2")
168    (V8HI "vec") (V16HI "avx2")
169    (V4SI "vec") (V8SI "avx2")
170    (V2DI "vec") (V4DI "avx2")])
171
172 ;; Mapping of logic-shift operators
173 (define_code_iterator lshift [lshiftrt ashift])
174
175 ;; Base name for define_insn
176 (define_code_attr lshift_insn [(lshiftrt "srl") (ashift "sll")])
177
178 ;; Base name for insn mnemonic
179 (define_code_attr lshift [(lshiftrt "lshr") (ashift "lshl")])
180
181 (define_mode_attr ssedoublemode
182   [(V16HI "V16SI") (V8HI "V8SI")])
183
184 (define_mode_attr ssebytemode
185   [(V4DI "V32QI") (V2DI "V16QI")])
186
187 ;; All 128bit vector integer modes
188 (define_mode_iterator VI_128 [V16QI V8HI V4SI V2DI])
189
190 ;; All 256bit vector integer modes
191 (define_mode_iterator VI_256 [V32QI V16HI V8SI V4DI])
192
193 ;; Random 128bit vector integer mode combinations
194 (define_mode_iterator VI12_128 [V16QI V8HI])
195 (define_mode_iterator VI14_128 [V16QI V4SI])
196 (define_mode_iterator VI124_128 [V16QI V8HI V4SI])
197 (define_mode_iterator VI24_128 [V8HI V4SI])
198 (define_mode_iterator VI248_128 [V8HI V4SI V2DI])
199
200 ;; Random 256bit vector integer mode combinations
201 (define_mode_iterator VI124_256 [V32QI V16HI V8SI])
202 (define_mode_iterator VI248_256 [V16HI V8SI V4DI])
203
204 ;; Int-float size matches
205 (define_mode_iterator VI4F_128 [V4SI V4SF])
206 (define_mode_iterator VI8F_128 [V2DI V2DF])
207 (define_mode_iterator VI4F_256 [V8SI V8SF])
208 (define_mode_iterator VI8F_256 [V4DI V4DF])
209
210 ;; Mapping from float mode to required SSE level
211 (define_mode_attr sse
212   [(SF "sse") (DF "sse2")
213    (V4SF "sse") (V2DF "sse2")
214    (V8SF "avx") (V4DF "avx")])
215
216 (define_mode_attr sse2
217   [(V16QI "sse2") (V32QI "avx")
218    (V2DI "sse2") (V4DI "avx")])
219
220 (define_mode_attr sse3
221   [(V16QI "sse3") (V32QI "avx")])
222
223 (define_mode_attr sse4_1
224   [(V4SF "sse4_1") (V2DF "sse4_1")
225    (V8SF "avx") (V4DF "avx")])
226
227 (define_mode_attr avxsizesuffix
228   [(V32QI "256") (V16HI "256") (V8SI "256") (V4DI "256")
229    (V16QI "") (V8HI "") (V4SI "") (V2DI "")
230    (V8SF "256") (V4DF "256")
231    (V4SF "") (V2DF "")])
232
233 ;; SSE instruction mode
234 (define_mode_attr sseinsnmode
235   [(V32QI "OI") (V16HI "OI") (V8SI "OI") (V4DI "OI") (V2TI "OI")
236    (V16QI "TI") (V8HI "TI") (V4SI "TI") (V2DI "TI") (V1TI "TI")
237    (V8SF "V8SF") (V4DF "V4DF")
238    (V4SF "V4SF") (V2DF "V2DF")
239    (TI "TI")])
240
241 ;; Mapping of vector float modes to an integer mode of the same size
242 (define_mode_attr sseintvecmode
243   [(V8SF "V8SI") (V4DF "V4DI")
244    (V4SF "V4SI") (V2DF "V2DI")
245    (V4DF "V4DI") (V8SF "V8SI")
246    (V8SI "V8SI") (V4DI "V4DI")
247    (V4SI "V4SI") (V2DI "V2DI")
248    (V16HI "V16HI") (V8HI "V8HI")
249    (V32QI "V32QI") (V16QI "V16QI")
250   ])
251
252 ;; Mapping of vector modes to a vector mode of double size
253 (define_mode_attr ssedoublevecmode
254   [(V32QI "V64QI") (V16HI "V32HI") (V8SI "V16SI") (V4DI "V8DI")
255    (V16QI "V32QI") (V8HI "V16HI") (V4SI "V8SI") (V2DI "V4DI")
256    (V8SF "V16SF") (V4DF "V8DF")
257    (V4SF "V8SF") (V2DF "V4DF")])
258
259 ;; Mapping of vector modes to a vector mode of half size
260 (define_mode_attr ssehalfvecmode
261   [(V32QI "V16QI") (V16HI "V8HI") (V8SI "V4SI") (V4DI "V2DI")
262    (V16QI  "V8QI") (V8HI  "V4HI") (V4SI "V2SI")
263    (V8SF "V4SF") (V4DF "V2DF")
264    (V4SF "V2SF")])
265
266 ;; Mapping of vector modes back to the scalar modes
267 (define_mode_attr ssescalarmode
268   [(V32QI "QI") (V16HI "HI") (V8SI "SI") (V4DI "DI")
269    (V16QI "QI") (V8HI "HI") (V4SI "SI") (V2DI "DI")
270    (V8SF "SF") (V4DF "DF")
271    (V4SF "SF") (V2DF "DF")])
272
273 ;; Number of scalar elements in each vector type
274 (define_mode_attr ssescalarnum
275   [(V32QI "32") (V16HI "16") (V8SI "8") (V4DI "4")
276    (V16QI "16") (V8HI "8") (V4SI "4") (V2DI "2")
277    (V8SF "8") (V4DF "4")
278    (V4SF "4") (V2DF "2")])
279
280 ;; SSE scalar suffix for vector modes
281 (define_mode_attr ssescalarmodesuffix
282   [(SF "ss") (DF "sd")
283    (V8SF "ss") (V4DF "sd")
284    (V4SF "ss") (V2DF "sd")
285    (V8SI "ss") (V4DI "sd")
286    (V4SI "d")])
287
288 ;; Pack/unpack vector modes
289 (define_mode_attr sseunpackmode
290   [(V16QI "V8HI") (V8HI "V4SI") (V4SI "V2DI")
291    (V32QI "V16HI") (V16HI "V8SI") (V8SI "V4DI")])
292
293 (define_mode_attr ssepackmode
294   [(V8HI "V16QI") (V4SI "V8HI") (V2DI "V4SI")
295    (V16HI "V32QI") (V8SI "V16HI") (V4DI "V8SI")])
296
297 ;; Mapping of the max integer size for xop rotate immediate constraint
298 (define_mode_attr sserotatemax
299   [(V16QI "7") (V8HI "15") (V4SI "31") (V2DI "63")])
300
301 ;; Mapping of mode to cast intrinsic name
302 (define_mode_attr castmode [(V8SI "si") (V8SF "ps") (V4DF "pd")])
303
304 ;; Instruction suffix for sign and zero extensions.
305 (define_code_attr extsuffix [(sign_extend "sx") (zero_extend "zx")])
306
307 ;; i128 for integer vectors and TARGET_AVX2, f128 otherwise.
308 (define_mode_attr i128
309   [(V8SF "f128") (V4DF "f128") (V32QI "%~128") (V16HI "%~128")
310    (V8SI "%~128") (V4DI "%~128")])
311
312 ;; Mix-n-match
313 (define_mode_iterator AVX256MODE2P [V8SI V8SF V4DF])
314
315 (define_mode_iterator AVXMODE48P_DI
316                       [V2DI V2DF V4DI V4DF V4SF V4SI])
317 (define_mode_attr AVXMODE48P_DI
318                       [(V2DI "V2DI") (V2DF "V2DI")
319                        (V4DI "V4DI") (V4DF "V4DI")
320                        (V4SI "V2DI") (V4SF "V2DI")
321                        (V8SI "V4DI") (V8SF "V4DI")])
322 (define_mode_attr gthrfirstp
323                       [(V2DI "p") (V2DF "")
324                        (V4DI "p") (V4DF "")
325                        (V4SI "p") (V4SF "")
326                        (V8SI "p") (V8SF "")])
327 (define_mode_attr gthrlastp
328                       [(V2DI "q") (V2DF "pd")
329                        (V4DI "q") (V4DF "pd")
330                        (V4SI "d") (V4SF "ps")
331                        (V8SI "d") (V8SF "ps")])
332
333 (define_mode_iterator FMAMODE [SF DF V4SF V2DF V8SF V4DF])
334
335 ;; Mapping of immediate bits for blend instructions
336 (define_mode_attr blendbits
337   [(V8SF "255") (V4SF "15") (V4DF "15") (V2DF "3")])
338
339 ;; Patterns whose name begins with "sse{,2,3}_" are invoked by intrinsics.
340
341 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
342 ;;
343 ;; Move patterns
344 ;;
345 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
346
347 ;; All of these patterns are enabled for SSE1 as well as SSE2.
348 ;; This is essential for maintaining stable calling conventions.
349
350 (define_expand "mov<mode>"
351   [(set (match_operand:V16 0 "nonimmediate_operand" "")
352         (match_operand:V16 1 "nonimmediate_operand" ""))]
353   "TARGET_SSE"
354 {
355   ix86_expand_vector_move (<MODE>mode, operands);
356   DONE;
357 })
358
359 (define_insn "*mov<mode>_internal"
360   [(set (match_operand:V16 0 "nonimmediate_operand" "=x,x ,m")
361         (match_operand:V16 1 "nonimmediate_or_sse_const_operand"  "C ,xm,x"))]
362   "TARGET_SSE
363    && (register_operand (operands[0], <MODE>mode)
364        || register_operand (operands[1], <MODE>mode))"
365 {
366   switch (which_alternative)
367     {
368     case 0:
369       return standard_sse_constant_opcode (insn, operands[1]);
370     case 1:
371     case 2:
372       switch (get_attr_mode (insn))
373         {
374         case MODE_V8SF:
375         case MODE_V4SF:
376           if (TARGET_AVX
377               && (misaligned_operand (operands[0], <MODE>mode)
378                   || misaligned_operand (operands[1], <MODE>mode)))
379             return "vmovups\t{%1, %0|%0, %1}";
380           else
381             return "%vmovaps\t{%1, %0|%0, %1}";
382
383         case MODE_V4DF:
384         case MODE_V2DF:
385           if (TARGET_AVX
386               && (misaligned_operand (operands[0], <MODE>mode)
387                   || misaligned_operand (operands[1], <MODE>mode)))
388             return "vmovupd\t{%1, %0|%0, %1}";
389           else if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
390             return "%vmovaps\t{%1, %0|%0, %1}";
391           else
392             return "%vmovapd\t{%1, %0|%0, %1}";
393
394         case MODE_OI:
395         case MODE_TI:
396           if (TARGET_AVX
397               && (misaligned_operand (operands[0], <MODE>mode)
398                   || misaligned_operand (operands[1], <MODE>mode)))
399             return "vmovdqu\t{%1, %0|%0, %1}";
400           else if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
401             return "%vmovaps\t{%1, %0|%0, %1}";
402           else
403             return "%vmovdqa\t{%1, %0|%0, %1}";
404
405         default:
406           gcc_unreachable ();
407         }
408     default:
409       gcc_unreachable ();
410     }
411 }
412   [(set_attr "type" "sselog1,ssemov,ssemov")
413    (set_attr "prefix" "maybe_vex")
414    (set (attr "mode")
415         (cond [(match_test "TARGET_AVX")
416                  (const_string "<sseinsnmode>")
417                (ior (ior (match_test "optimize_function_for_size_p (cfun)")
418                          (not (match_test "TARGET_SSE2")))
419                     (and (eq_attr "alternative" "2")
420                          (match_test "TARGET_SSE_TYPELESS_STORES")))
421                  (const_string "V4SF")
422                (eq (const_string "<MODE>mode") (const_string "V4SFmode"))
423                  (const_string "V4SF")
424                (eq (const_string "<MODE>mode") (const_string "V2DFmode"))
425                  (const_string "V2DF")
426               ]
427           (const_string "TI")))])
428
429 (define_insn "sse2_movq128"
430   [(set (match_operand:V2DI 0 "register_operand" "=x")
431         (vec_concat:V2DI
432           (vec_select:DI
433             (match_operand:V2DI 1 "nonimmediate_operand" "xm")
434             (parallel [(const_int 0)]))
435           (const_int 0)))]
436   "TARGET_SSE2"
437   "%vmovq\t{%1, %0|%0, %1}"
438   [(set_attr "type" "ssemov")
439    (set_attr "prefix" "maybe_vex")
440    (set_attr "mode" "TI")])
441
442 ;; Move a DI from a 32-bit register pair (e.g. %edx:%eax) to an xmm.
443 ;; We'd rather avoid this entirely; if the 32-bit reg pair was loaded
444 ;; from memory, we'd prefer to load the memory directly into the %xmm
445 ;; register.  To facilitate this happy circumstance, this pattern won't
446 ;; split until after register allocation.  If the 64-bit value didn't
447 ;; come from memory, this is the best we can do.  This is much better
448 ;; than storing %edx:%eax into a stack temporary and loading an %xmm
449 ;; from there.
450
451 (define_insn_and_split "movdi_to_sse"
452   [(parallel
453     [(set (match_operand:V4SI 0 "register_operand" "=?x,x")
454           (subreg:V4SI (match_operand:DI 1 "nonimmediate_operand" "r,m") 0))
455      (clobber (match_scratch:V4SI 2 "=&x,X"))])]
456   "!TARGET_64BIT && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES"
457   "#"
458   "&& reload_completed"
459   [(const_int 0)]
460 {
461  if (register_operand (operands[1], DImode))
462    {
463       /* The DImode arrived in a pair of integral registers (e.g. %edx:%eax).
464          Assemble the 64-bit DImode value in an xmm register.  */
465       emit_insn (gen_sse2_loadld (operands[0], CONST0_RTX (V4SImode),
466                                   gen_rtx_SUBREG (SImode, operands[1], 0)));
467       emit_insn (gen_sse2_loadld (operands[2], CONST0_RTX (V4SImode),
468                                   gen_rtx_SUBREG (SImode, operands[1], 4)));
469       emit_insn (gen_vec_interleave_lowv4si (operands[0], operands[0],
470                                              operands[2]));
471     }
472  else if (memory_operand (operands[1], DImode))
473    emit_insn (gen_vec_concatv2di (gen_lowpart (V2DImode, operands[0]),
474                                   operands[1], const0_rtx));
475  else
476    gcc_unreachable ();
477 })
478
479 (define_split
480   [(set (match_operand:V4SF 0 "register_operand" "")
481         (match_operand:V4SF 1 "zero_extended_scalar_load_operand" ""))]
482   "TARGET_SSE && reload_completed"
483   [(set (match_dup 0)
484         (vec_merge:V4SF
485           (vec_duplicate:V4SF (match_dup 1))
486           (match_dup 2)
487           (const_int 1)))]
488 {
489   operands[1] = simplify_gen_subreg (SFmode, operands[1], V4SFmode, 0);
490   operands[2] = CONST0_RTX (V4SFmode);
491 })
492
493 (define_split
494   [(set (match_operand:V2DF 0 "register_operand" "")
495         (match_operand:V2DF 1 "zero_extended_scalar_load_operand" ""))]
496   "TARGET_SSE2 && reload_completed"
497   [(set (match_dup 0) (vec_concat:V2DF (match_dup 1) (match_dup 2)))]
498 {
499   operands[1] = simplify_gen_subreg (DFmode, operands[1], V2DFmode, 0);
500   operands[2] = CONST0_RTX (DFmode);
501 })
502
503 (define_expand "push<mode>1"
504   [(match_operand:V16 0 "register_operand" "")]
505   "TARGET_SSE"
506 {
507   ix86_expand_push (<MODE>mode, operands[0]);
508   DONE;
509 })
510
511 (define_expand "movmisalign<mode>"
512   [(set (match_operand:V16 0 "nonimmediate_operand" "")
513         (match_operand:V16 1 "nonimmediate_operand" ""))]
514   "TARGET_SSE"
515 {
516   ix86_expand_vector_move_misalign (<MODE>mode, operands);
517   DONE;
518 })
519
520 (define_expand "<sse>_movu<ssemodesuffix><avxsizesuffix>"
521   [(set (match_operand:VF 0 "nonimmediate_operand" "")
522         (unspec:VF
523           [(match_operand:VF 1 "nonimmediate_operand" "")]
524           UNSPEC_MOVU))]
525   "TARGET_SSE"
526 {
527   if (MEM_P (operands[0]) && MEM_P (operands[1]))
528     operands[1] = force_reg (<MODE>mode, operands[1]);
529 })
530
531 (define_insn "*<sse>_movu<ssemodesuffix><avxsizesuffix>"
532   [(set (match_operand:VF 0 "nonimmediate_operand" "=x,m")
533         (unspec:VF
534           [(match_operand:VF 1 "nonimmediate_operand" "xm,x")]
535           UNSPEC_MOVU))]
536   "TARGET_SSE && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
537   "%vmovu<ssemodesuffix>\t{%1, %0|%0, %1}"
538   [(set_attr "type" "ssemov")
539    (set_attr "movu" "1")
540    (set_attr "prefix" "maybe_vex")
541    (set_attr "mode" "<MODE>")])
542
543 (define_expand "<sse2>_movdqu<avxsizesuffix>"
544   [(set (match_operand:VI1 0 "nonimmediate_operand" "")
545         (unspec:VI1 [(match_operand:VI1 1 "nonimmediate_operand" "")]
546                     UNSPEC_MOVU))]
547   "TARGET_SSE2"
548 {
549   if (MEM_P (operands[0]) && MEM_P (operands[1]))
550     operands[1] = force_reg (<MODE>mode, operands[1]);
551 })
552
553 (define_insn "*<sse2>_movdqu<avxsizesuffix>"
554   [(set (match_operand:VI1 0 "nonimmediate_operand" "=x,m")
555         (unspec:VI1 [(match_operand:VI1 1 "nonimmediate_operand" "xm,x")]
556                     UNSPEC_MOVU))]
557   "TARGET_SSE2 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
558   "%vmovdqu\t{%1, %0|%0, %1}"
559   [(set_attr "type" "ssemov")
560    (set_attr "movu" "1")
561    (set (attr "prefix_data16")
562      (if_then_else
563        (match_test "TARGET_AVX")
564      (const_string "*")
565      (const_string "1")))
566    (set_attr "prefix" "maybe_vex")
567    (set_attr "mode" "<sseinsnmode>")])
568
569 (define_insn "<sse3>_lddqu<avxsizesuffix>"
570   [(set (match_operand:VI1 0 "register_operand" "=x")
571         (unspec:VI1 [(match_operand:VI1 1 "memory_operand" "m")]
572                     UNSPEC_LDDQU))]
573   "TARGET_SSE3"
574   "%vlddqu\t{%1, %0|%0, %1}"
575   [(set_attr "type" "ssemov")
576    (set_attr "movu" "1")
577    (set (attr "prefix_data16")
578      (if_then_else
579        (match_test "TARGET_AVX")
580      (const_string "*")
581      (const_string "0")))
582    (set (attr "prefix_rep")
583      (if_then_else
584        (match_test "TARGET_AVX")
585      (const_string "*")
586      (const_string "1")))
587    (set_attr "prefix" "maybe_vex")
588    (set_attr "mode" "<sseinsnmode>")])
589
590 (define_insn "sse2_movntsi"
591   [(set (match_operand:SI 0 "memory_operand" "=m")
592         (unspec:SI [(match_operand:SI 1 "register_operand" "r")]
593                    UNSPEC_MOVNT))]
594   "TARGET_SSE2"
595   "movnti\t{%1, %0|%0, %1}"
596   [(set_attr "type" "ssemov")
597    (set_attr "prefix_data16" "0")
598    (set_attr "mode" "V2DF")])
599
600 (define_insn "<sse>_movnt<mode>"
601   [(set (match_operand:VF 0 "memory_operand" "=m")
602         (unspec:VF [(match_operand:VF 1 "register_operand" "x")]
603                    UNSPEC_MOVNT))]
604   "TARGET_SSE"
605   "%vmovnt<ssemodesuffix>\t{%1, %0|%0, %1}"
606   [(set_attr "type" "ssemov")
607    (set_attr "prefix" "maybe_vex")
608    (set_attr "mode" "<MODE>")])
609
610 (define_insn "<sse2>_movnt<mode>"
611   [(set (match_operand:VI8 0 "memory_operand" "=m")
612         (unspec:VI8 [(match_operand:VI8 1 "register_operand" "x")]
613                     UNSPEC_MOVNT))]
614   "TARGET_SSE2"
615   "%vmovntdq\t{%1, %0|%0, %1}"
616   [(set_attr "type" "ssecvt")
617    (set (attr "prefix_data16")
618      (if_then_else
619        (match_test "TARGET_AVX")
620      (const_string "*")
621      (const_string "1")))
622    (set_attr "prefix" "maybe_vex")
623    (set_attr "mode" "<sseinsnmode>")])
624
625 ; Expand patterns for non-temporal stores.  At the moment, only those
626 ; that directly map to insns are defined; it would be possible to
627 ; define patterns for other modes that would expand to several insns.
628
629 ;; Modes handled by storent patterns.
630 (define_mode_iterator STORENT_MODE
631   [(SI "TARGET_SSE2") (SF "TARGET_SSE4A") (DF "TARGET_SSE4A")
632    (V2DI "TARGET_SSE2")
633    (V8SF "TARGET_AVX") V4SF
634    (V4DF "TARGET_AVX") (V2DF "TARGET_SSE2")])
635
636 (define_expand "storent<mode>"
637   [(set (match_operand:STORENT_MODE 0 "memory_operand" "")
638         (unspec:STORENT_MODE
639           [(match_operand:STORENT_MODE 1 "register_operand" "")]
640           UNSPEC_MOVNT))]
641   "TARGET_SSE")
642
643 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
644 ;;
645 ;; Parallel floating point arithmetic
646 ;;
647 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
648
649 (define_expand "<code><mode>2"
650   [(set (match_operand:VF 0 "register_operand" "")
651         (absneg:VF
652           (match_operand:VF 1 "register_operand" "")))]
653   "TARGET_SSE"
654   "ix86_expand_fp_absneg_operator (<CODE>, <MODE>mode, operands); DONE;")
655
656 (define_insn_and_split "*absneg<mode>2"
657   [(set (match_operand:VF 0 "register_operand" "=x,x,x,x")
658         (match_operator:VF 3 "absneg_operator"
659           [(match_operand:VF 1 "nonimmediate_operand" "0, xm,x, m")]))
660    (use (match_operand:VF 2 "nonimmediate_operand"    "xm,0, xm,x"))]
661   "TARGET_SSE"
662   "#"
663   "&& reload_completed"
664   [(const_int 0)]
665 {
666   enum rtx_code absneg_op;
667   rtx op1, op2;
668   rtx t;
669
670   if (TARGET_AVX)
671     {
672       if (MEM_P (operands[1]))
673         op1 = operands[2], op2 = operands[1];
674       else
675         op1 = operands[1], op2 = operands[2];
676     }
677   else
678     {
679       op1 = operands[0];
680       if (rtx_equal_p (operands[0], operands[1]))
681         op2 = operands[2];
682       else
683         op2 = operands[1];
684     }
685
686   absneg_op = GET_CODE (operands[3]) == NEG ? XOR : AND;
687   t = gen_rtx_fmt_ee (absneg_op, <MODE>mode, op1, op2);
688   t = gen_rtx_SET (VOIDmode, operands[0], t);
689   emit_insn (t);
690   DONE;
691 }
692   [(set_attr "isa" "noavx,noavx,avx,avx")])
693
694 (define_expand "<plusminus_insn><mode>3"
695   [(set (match_operand:VF 0 "register_operand" "")
696         (plusminus:VF
697           (match_operand:VF 1 "nonimmediate_operand" "")
698           (match_operand:VF 2 "nonimmediate_operand" "")))]
699   "TARGET_SSE"
700   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
701
702 (define_insn "*<plusminus_insn><mode>3"
703   [(set (match_operand:VF 0 "register_operand" "=x,x")
704         (plusminus:VF
705           (match_operand:VF 1 "nonimmediate_operand" "<comm>0,x")
706           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
707   "TARGET_SSE && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
708   "@
709    <plusminus_mnemonic><ssemodesuffix>\t{%2, %0|%0, %2}
710    v<plusminus_mnemonic><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
711   [(set_attr "isa" "noavx,avx")
712    (set_attr "type" "sseadd")
713    (set_attr "prefix" "orig,vex")
714    (set_attr "mode" "<MODE>")])
715
716 (define_insn "<sse>_vm<plusminus_insn><mode>3"
717   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
718         (vec_merge:VF_128
719           (plusminus:VF_128
720             (match_operand:VF_128 1 "register_operand" "0,x")
721             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm"))
722           (match_dup 1)
723           (const_int 1)))]
724   "TARGET_SSE"
725   "@
726    <plusminus_mnemonic><ssescalarmodesuffix>\t{%2, %0|%0, %2}
727    v<plusminus_mnemonic><ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
728   [(set_attr "isa" "noavx,avx")
729    (set_attr "type" "sseadd")
730    (set_attr "prefix" "orig,vex")
731    (set_attr "mode" "<ssescalarmode>")])
732
733 (define_expand "mul<mode>3"
734   [(set (match_operand:VF 0 "register_operand" "")
735         (mult:VF
736           (match_operand:VF 1 "nonimmediate_operand" "")
737           (match_operand:VF 2 "nonimmediate_operand" "")))]
738   "TARGET_SSE"
739   "ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);")
740
741 (define_insn "*mul<mode>3"
742   [(set (match_operand:VF 0 "register_operand" "=x,x")
743         (mult:VF
744           (match_operand:VF 1 "nonimmediate_operand" "%0,x")
745           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
746   "TARGET_SSE && ix86_binary_operator_ok (MULT, <MODE>mode, operands)"
747   "@
748    mul<ssemodesuffix>\t{%2, %0|%0, %2}
749    vmul<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
750   [(set_attr "isa" "noavx,avx")
751    (set_attr "type" "ssemul")
752    (set_attr "prefix" "orig,vex")
753    (set_attr "mode" "<MODE>")])
754
755 (define_insn "<sse>_vmmul<mode>3"
756   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
757         (vec_merge:VF_128
758           (mult:VF_128
759             (match_operand:VF_128 1 "register_operand" "0,x")
760             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm"))
761           (match_dup 1)
762           (const_int 1)))]
763   "TARGET_SSE"
764   "@
765    mul<ssescalarmodesuffix>\t{%2, %0|%0, %2}
766    vmul<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
767   [(set_attr "isa" "noavx,avx")
768    (set_attr "type" "ssemul")
769    (set_attr "prefix" "orig,vex")
770    (set_attr "mode" "<ssescalarmode>")])
771
772 (define_expand "div<mode>3"
773   [(set (match_operand:VF2 0 "register_operand" "")
774         (div:VF2 (match_operand:VF2 1 "register_operand" "")
775                  (match_operand:VF2 2 "nonimmediate_operand" "")))]
776   "TARGET_SSE2"
777   "ix86_fixup_binary_operands_no_copy (DIV, <MODE>mode, operands);")
778
779 (define_expand "div<mode>3"
780   [(set (match_operand:VF1 0 "register_operand" "")
781         (div:VF1 (match_operand:VF1 1 "register_operand" "")
782                  (match_operand:VF1 2 "nonimmediate_operand" "")))]
783   "TARGET_SSE"
784 {
785   ix86_fixup_binary_operands_no_copy (DIV, <MODE>mode, operands);
786
787   if (TARGET_SSE_MATH
788       && TARGET_RECIP_VEC_DIV
789       && !optimize_insn_for_size_p ()
790       && flag_finite_math_only && !flag_trapping_math
791       && flag_unsafe_math_optimizations)
792     {
793       ix86_emit_swdivsf (operands[0], operands[1], operands[2], <MODE>mode);
794       DONE;
795     }
796 })
797
798 (define_insn "<sse>_div<mode>3"
799   [(set (match_operand:VF 0 "register_operand" "=x,x")
800         (div:VF
801           (match_operand:VF 1 "register_operand" "0,x")
802           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
803   "TARGET_SSE"
804   "@
805    div<ssemodesuffix>\t{%2, %0|%0, %2}
806    vdiv<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
807   [(set_attr "isa" "noavx,avx")
808    (set_attr "type" "ssediv")
809    (set_attr "prefix" "orig,vex")
810    (set_attr "mode" "<MODE>")])
811
812 (define_insn "<sse>_vmdiv<mode>3"
813   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
814         (vec_merge:VF_128
815           (div:VF_128
816             (match_operand:VF_128 1 "register_operand" "0,x")
817             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm"))
818           (match_dup 1)
819           (const_int 1)))]
820   "TARGET_SSE"
821   "@
822    div<ssescalarmodesuffix>\t{%2, %0|%0, %2}
823    vdiv<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
824   [(set_attr "isa" "noavx,avx")
825    (set_attr "type" "ssediv")
826    (set_attr "prefix" "orig,vex")
827    (set_attr "mode" "<ssescalarmode>")])
828
829 (define_insn "<sse>_rcp<mode>2"
830   [(set (match_operand:VF1 0 "register_operand" "=x")
831         (unspec:VF1
832           [(match_operand:VF1 1 "nonimmediate_operand" "xm")] UNSPEC_RCP))]
833   "TARGET_SSE"
834   "%vrcpps\t{%1, %0|%0, %1}"
835   [(set_attr "type" "sse")
836    (set_attr "atom_sse_attr" "rcp")
837    (set_attr "prefix" "maybe_vex")
838    (set_attr "mode" "<MODE>")])
839
840 (define_insn "sse_vmrcpv4sf2"
841   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
842         (vec_merge:V4SF
843           (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "xm,xm")]
844                        UNSPEC_RCP)
845           (match_operand:V4SF 2 "register_operand" "0,x")
846           (const_int 1)))]
847   "TARGET_SSE"
848   "@
849    rcpss\t{%1, %0|%0, %1}
850    vrcpss\t{%1, %2, %0|%0, %2, %1}"
851   [(set_attr "isa" "noavx,avx")
852    (set_attr "type" "sse")
853    (set_attr "atom_sse_attr" "rcp")
854    (set_attr "prefix" "orig,vex")
855    (set_attr "mode" "SF")])
856
857 (define_expand "sqrt<mode>2"
858   [(set (match_operand:VF2 0 "register_operand" "")
859         (sqrt:VF2 (match_operand:VF2 1 "nonimmediate_operand" "")))]
860   "TARGET_SSE2")
861
862 (define_expand "sqrt<mode>2"
863   [(set (match_operand:VF1 0 "register_operand" "")
864         (sqrt:VF1 (match_operand:VF1 1 "nonimmediate_operand" "")))]
865   "TARGET_SSE"
866 {
867   if (TARGET_SSE_MATH
868       && TARGET_RECIP_VEC_SQRT
869       && !optimize_insn_for_size_p ()
870       && flag_finite_math_only && !flag_trapping_math
871       && flag_unsafe_math_optimizations)
872     {
873       ix86_emit_swsqrtsf (operands[0], operands[1], <MODE>mode, false);
874       DONE;
875     }
876 })
877
878 (define_insn "<sse>_sqrt<mode>2"
879   [(set (match_operand:VF 0 "register_operand" "=x")
880         (sqrt:VF (match_operand:VF 1 "nonimmediate_operand" "xm")))]
881   "TARGET_SSE"
882   "%vsqrt<ssemodesuffix>\t{%1, %0|%0, %1}"
883   [(set_attr "type" "sse")
884    (set_attr "atom_sse_attr" "sqrt")
885    (set_attr "prefix" "maybe_vex")
886    (set_attr "mode" "<MODE>")])
887
888 (define_insn "<sse>_vmsqrt<mode>2"
889   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
890         (vec_merge:VF_128
891           (sqrt:VF_128
892             (match_operand:VF_128 1 "nonimmediate_operand" "xm,xm"))
893           (match_operand:VF_128 2 "register_operand" "0,x")
894           (const_int 1)))]
895   "TARGET_SSE"
896   "@
897    sqrt<ssescalarmodesuffix>\t{%1, %0|%0, %1}
898    vsqrt<ssescalarmodesuffix>\t{%1, %2, %0|%0, %2, %1}"
899   [(set_attr "isa" "noavx,avx")
900    (set_attr "type" "sse")
901    (set_attr "atom_sse_attr" "sqrt")
902    (set_attr "prefix" "orig,vex")
903    (set_attr "mode" "<ssescalarmode>")])
904
905 (define_expand "rsqrt<mode>2"
906   [(set (match_operand:VF1 0 "register_operand" "")
907         (unspec:VF1
908           [(match_operand:VF1 1 "nonimmediate_operand" "")] UNSPEC_RSQRT))]
909   "TARGET_SSE_MATH"
910 {
911   ix86_emit_swsqrtsf (operands[0], operands[1], <MODE>mode, true);
912   DONE;
913 })
914
915 (define_insn "<sse>_rsqrt<mode>2"
916   [(set (match_operand:VF1 0 "register_operand" "=x")
917         (unspec:VF1
918           [(match_operand:VF1 1 "nonimmediate_operand" "xm")] UNSPEC_RSQRT))]
919   "TARGET_SSE"
920   "%vrsqrtps\t{%1, %0|%0, %1}"
921   [(set_attr "type" "sse")
922    (set_attr "prefix" "maybe_vex")
923    (set_attr "mode" "<MODE>")])
924
925 (define_insn "sse_vmrsqrtv4sf2"
926   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
927         (vec_merge:V4SF
928           (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "xm,xm")]
929                        UNSPEC_RSQRT)
930           (match_operand:V4SF 2 "register_operand" "0,x")
931           (const_int 1)))]
932   "TARGET_SSE"
933   "@
934    rsqrtss\t{%1, %0|%0, %1}
935    vrsqrtss\t{%1, %2, %0|%0, %2, %1}"
936   [(set_attr "isa" "noavx,avx")
937    (set_attr "type" "sse")
938    (set_attr "prefix" "orig,vex")
939    (set_attr "mode" "SF")])
940
941 ;; ??? For !flag_finite_math_only, the representation with SMIN/SMAX
942 ;; isn't really correct, as those rtl operators aren't defined when
943 ;; applied to NaNs.  Hopefully the optimizers won't get too smart on us.
944
945 (define_expand "<code><mode>3"
946   [(set (match_operand:VF 0 "register_operand" "")
947         (smaxmin:VF
948           (match_operand:VF 1 "nonimmediate_operand" "")
949           (match_operand:VF 2 "nonimmediate_operand" "")))]
950   "TARGET_SSE"
951 {
952   if (!flag_finite_math_only)
953     operands[1] = force_reg (<MODE>mode, operands[1]);
954   ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);
955 })
956
957 (define_insn "*<code><mode>3_finite"
958   [(set (match_operand:VF 0 "register_operand" "=x,x")
959         (smaxmin:VF
960           (match_operand:VF 1 "nonimmediate_operand" "%0,x")
961           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
962   "TARGET_SSE && flag_finite_math_only
963    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
964   "@
965    <maxmin_float><ssemodesuffix>\t{%2, %0|%0, %2}
966    v<maxmin_float><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
967   [(set_attr "isa" "noavx,avx")
968    (set_attr "type" "sseadd")
969    (set_attr "prefix" "orig,vex")
970    (set_attr "mode" "<MODE>")])
971
972 (define_insn "*<code><mode>3"
973   [(set (match_operand:VF 0 "register_operand" "=x,x")
974         (smaxmin:VF
975           (match_operand:VF 1 "register_operand" "0,x")
976           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
977   "TARGET_SSE && !flag_finite_math_only"
978   "@
979    <maxmin_float><ssemodesuffix>\t{%2, %0|%0, %2}
980    v<maxmin_float><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
981   [(set_attr "isa" "noavx,avx")
982    (set_attr "type" "sseadd")
983    (set_attr "prefix" "orig,vex")
984    (set_attr "mode" "<MODE>")])
985
986 (define_insn "<sse>_vm<code><mode>3"
987   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
988         (vec_merge:VF_128
989           (smaxmin:VF_128
990             (match_operand:VF_128 1 "register_operand" "0,x")
991             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm"))
992          (match_dup 1)
993          (const_int 1)))]
994   "TARGET_SSE"
995   "@
996    <maxmin_float><ssescalarmodesuffix>\t{%2, %0|%0, %2}
997    v<maxmin_float><ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
998   [(set_attr "isa" "noavx,avx")
999    (set_attr "type" "sse")
1000    (set_attr "prefix" "orig,vex")
1001    (set_attr "mode" "<ssescalarmode>")])
1002
1003 ;; These versions of the min/max patterns implement exactly the operations
1004 ;;   min = (op1 < op2 ? op1 : op2)
1005 ;;   max = (!(op1 < op2) ? op1 : op2)
1006 ;; Their operands are not commutative, and thus they may be used in the
1007 ;; presence of -0.0 and NaN.
1008
1009 (define_insn "*ieee_smin<mode>3"
1010   [(set (match_operand:VF 0 "register_operand" "=x,x")
1011         (unspec:VF
1012           [(match_operand:VF 1 "register_operand" "0,x")
1013            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")]
1014          UNSPEC_IEEE_MIN))]
1015   "TARGET_SSE"
1016   "@
1017    min<ssemodesuffix>\t{%2, %0|%0, %2}
1018    vmin<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1019   [(set_attr "isa" "noavx,avx")
1020    (set_attr "type" "sseadd")
1021    (set_attr "prefix" "orig,vex")
1022    (set_attr "mode" "<MODE>")])
1023
1024 (define_insn "*ieee_smax<mode>3"
1025   [(set (match_operand:VF 0 "register_operand" "=x,x")
1026         (unspec:VF
1027           [(match_operand:VF 1 "register_operand" "0,x")
1028            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")]
1029          UNSPEC_IEEE_MAX))]
1030   "TARGET_SSE"
1031   "@
1032    max<ssemodesuffix>\t{%2, %0|%0, %2}
1033    vmax<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1034   [(set_attr "isa" "noavx,avx")
1035    (set_attr "type" "sseadd")
1036    (set_attr "prefix" "orig,vex")
1037    (set_attr "mode" "<MODE>")])
1038
1039 (define_insn "avx_addsubv4df3"
1040   [(set (match_operand:V4DF 0 "register_operand" "=x")
1041         (vec_merge:V4DF
1042           (plus:V4DF
1043             (match_operand:V4DF 1 "register_operand" "x")
1044             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
1045           (minus:V4DF (match_dup 1) (match_dup 2))
1046           (const_int 10)))]
1047   "TARGET_AVX"
1048   "vaddsubpd\t{%2, %1, %0|%0, %1, %2}"
1049   [(set_attr "type" "sseadd")
1050    (set_attr "prefix" "vex")
1051    (set_attr "mode" "V4DF")])
1052
1053 (define_insn "sse3_addsubv2df3"
1054   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
1055         (vec_merge:V2DF
1056           (plus:V2DF
1057             (match_operand:V2DF 1 "register_operand" "0,x")
1058             (match_operand:V2DF 2 "nonimmediate_operand" "xm,xm"))
1059           (minus:V2DF (match_dup 1) (match_dup 2))
1060           (const_int 2)))]
1061   "TARGET_SSE3"
1062   "@
1063    addsubpd\t{%2, %0|%0, %2}
1064    vaddsubpd\t{%2, %1, %0|%0, %1, %2}"
1065   [(set_attr "isa" "noavx,avx")
1066    (set_attr "type" "sseadd")
1067    (set_attr "atom_unit" "complex")
1068    (set_attr "prefix" "orig,vex")
1069    (set_attr "mode" "V2DF")])
1070
1071 (define_insn "avx_addsubv8sf3"
1072   [(set (match_operand:V8SF 0 "register_operand" "=x")
1073         (vec_merge:V8SF
1074           (plus:V8SF
1075             (match_operand:V8SF 1 "register_operand" "x")
1076             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
1077           (minus:V8SF (match_dup 1) (match_dup 2))
1078           (const_int 170)))]
1079   "TARGET_AVX"
1080   "vaddsubps\t{%2, %1, %0|%0, %1, %2}"
1081   [(set_attr "type" "sseadd")
1082    (set_attr "prefix" "vex")
1083    (set_attr "mode" "V8SF")])
1084
1085 (define_insn "sse3_addsubv4sf3"
1086   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
1087         (vec_merge:V4SF
1088           (plus:V4SF
1089             (match_operand:V4SF 1 "register_operand" "0,x")
1090             (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm"))
1091           (minus:V4SF (match_dup 1) (match_dup 2))
1092           (const_int 10)))]
1093   "TARGET_SSE3"
1094   "@
1095    addsubps\t{%2, %0|%0, %2}
1096    vaddsubps\t{%2, %1, %0|%0, %1, %2}"
1097   [(set_attr "isa" "noavx,avx")
1098    (set_attr "type" "sseadd")
1099    (set_attr "prefix" "orig,vex")
1100    (set_attr "prefix_rep" "1,*")
1101    (set_attr "mode" "V4SF")])
1102
1103 (define_insn "avx_h<plusminus_insn>v4df3"
1104   [(set (match_operand:V4DF 0 "register_operand" "=x")
1105         (vec_concat:V4DF
1106           (vec_concat:V2DF
1107             (plusminus:DF
1108               (vec_select:DF
1109                 (match_operand:V4DF 1 "register_operand" "x")
1110                 (parallel [(const_int 0)]))
1111               (vec_select:DF (match_dup 1) (parallel [(const_int 1)])))
1112             (plusminus:DF
1113               (vec_select:DF (match_dup 1) (parallel [(const_int 2)]))
1114               (vec_select:DF (match_dup 1) (parallel [(const_int 3)]))))
1115           (vec_concat:V2DF
1116             (plusminus:DF
1117               (vec_select:DF
1118                 (match_operand:V4DF 2 "nonimmediate_operand" "xm")
1119                 (parallel [(const_int 0)]))
1120               (vec_select:DF (match_dup 2) (parallel [(const_int 1)])))
1121             (plusminus:DF
1122               (vec_select:DF (match_dup 2) (parallel [(const_int 2)]))
1123               (vec_select:DF (match_dup 2) (parallel [(const_int 3)]))))))]
1124   "TARGET_AVX"
1125   "vh<plusminus_mnemonic>pd\t{%2, %1, %0|%0, %1, %2}"
1126   [(set_attr "type" "sseadd")
1127    (set_attr "prefix" "vex")
1128    (set_attr "mode" "V4DF")])
1129
1130 (define_insn "sse3_h<plusminus_insn>v2df3"
1131   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
1132         (vec_concat:V2DF
1133           (plusminus:DF
1134             (vec_select:DF
1135               (match_operand:V2DF 1 "register_operand" "0,x")
1136               (parallel [(const_int 0)]))
1137             (vec_select:DF (match_dup 1) (parallel [(const_int 1)])))
1138           (plusminus:DF
1139             (vec_select:DF
1140               (match_operand:V2DF 2 "nonimmediate_operand" "xm,xm")
1141               (parallel [(const_int 0)]))
1142             (vec_select:DF (match_dup 2) (parallel [(const_int 1)])))))]
1143   "TARGET_SSE3"
1144   "@
1145    h<plusminus_mnemonic>pd\t{%2, %0|%0, %2}
1146    vh<plusminus_mnemonic>pd\t{%2, %1, %0|%0, %1, %2}"
1147   [(set_attr "isa" "noavx,avx")
1148    (set_attr "type" "sseadd")
1149    (set_attr "prefix" "orig,vex")
1150    (set_attr "mode" "V2DF")])
1151
1152 (define_insn "avx_h<plusminus_insn>v8sf3"
1153   [(set (match_operand:V8SF 0 "register_operand" "=x")
1154         (vec_concat:V8SF
1155           (vec_concat:V4SF
1156             (vec_concat:V2SF
1157               (plusminus:SF
1158                 (vec_select:SF
1159                   (match_operand:V8SF 1 "register_operand" "x")
1160                   (parallel [(const_int 0)]))
1161                 (vec_select:SF (match_dup 1) (parallel [(const_int 1)])))
1162               (plusminus:SF
1163                 (vec_select:SF (match_dup 1) (parallel [(const_int 2)]))
1164                 (vec_select:SF (match_dup 1) (parallel [(const_int 3)]))))
1165             (vec_concat:V2SF
1166               (plusminus:SF
1167                 (vec_select:SF
1168                   (match_operand:V8SF 2 "nonimmediate_operand" "xm")
1169                   (parallel [(const_int 0)]))
1170                 (vec_select:SF (match_dup 2) (parallel [(const_int 1)])))
1171               (plusminus:SF
1172                 (vec_select:SF (match_dup 2) (parallel [(const_int 2)]))
1173                 (vec_select:SF (match_dup 2) (parallel [(const_int 3)])))))
1174           (vec_concat:V4SF
1175             (vec_concat:V2SF
1176               (plusminus:SF
1177                 (vec_select:SF (match_dup 1) (parallel [(const_int 4)]))
1178                 (vec_select:SF (match_dup 1) (parallel [(const_int 5)])))
1179               (plusminus:SF
1180                 (vec_select:SF (match_dup 1) (parallel [(const_int 6)]))
1181                 (vec_select:SF (match_dup 1) (parallel [(const_int 7)]))))
1182             (vec_concat:V2SF
1183               (plusminus:SF
1184                 (vec_select:SF (match_dup 2) (parallel [(const_int 4)]))
1185                 (vec_select:SF (match_dup 2) (parallel [(const_int 5)])))
1186               (plusminus:SF
1187                 (vec_select:SF (match_dup 2) (parallel [(const_int 6)]))
1188                 (vec_select:SF (match_dup 2) (parallel [(const_int 7)])))))))]
1189   "TARGET_AVX"
1190   "vh<plusminus_mnemonic>ps\t{%2, %1, %0|%0, %1, %2}"
1191   [(set_attr "type" "sseadd")
1192    (set_attr "prefix" "vex")
1193    (set_attr "mode" "V8SF")])
1194
1195 (define_insn "sse3_h<plusminus_insn>v4sf3"
1196   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
1197         (vec_concat:V4SF
1198           (vec_concat:V2SF
1199             (plusminus:SF
1200               (vec_select:SF
1201                 (match_operand:V4SF 1 "register_operand" "0,x")
1202                 (parallel [(const_int 0)]))
1203               (vec_select:SF (match_dup 1) (parallel [(const_int 1)])))
1204             (plusminus:SF
1205               (vec_select:SF (match_dup 1) (parallel [(const_int 2)]))
1206               (vec_select:SF (match_dup 1) (parallel [(const_int 3)]))))
1207           (vec_concat:V2SF
1208             (plusminus:SF
1209               (vec_select:SF
1210                 (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm")
1211                 (parallel [(const_int 0)]))
1212               (vec_select:SF (match_dup 2) (parallel [(const_int 1)])))
1213             (plusminus:SF
1214               (vec_select:SF (match_dup 2) (parallel [(const_int 2)]))
1215               (vec_select:SF (match_dup 2) (parallel [(const_int 3)]))))))]
1216   "TARGET_SSE3"
1217   "@
1218    h<plusminus_mnemonic>ps\t{%2, %0|%0, %2}
1219    vh<plusminus_mnemonic>ps\t{%2, %1, %0|%0, %1, %2}"
1220   [(set_attr "isa" "noavx,avx")
1221    (set_attr "type" "sseadd")
1222    (set_attr "atom_unit" "complex")
1223    (set_attr "prefix" "orig,vex")
1224    (set_attr "prefix_rep" "1,*")
1225    (set_attr "mode" "V4SF")])
1226
1227 (define_expand "reduc_splus_v4df"
1228   [(match_operand:V4DF 0 "register_operand" "")
1229    (match_operand:V4DF 1 "register_operand" "")]
1230   "TARGET_AVX"
1231 {
1232   rtx tmp = gen_reg_rtx (V4DFmode);
1233   rtx tmp2 = gen_reg_rtx (V4DFmode);
1234   emit_insn (gen_avx_haddv4df3 (tmp, operands[1], operands[1]));
1235   emit_insn (gen_avx_vperm2f128v4df3 (tmp2, tmp, tmp, GEN_INT (1)));
1236   emit_insn (gen_addv4df3 (operands[0], tmp, tmp2));
1237   DONE;
1238 })
1239
1240 (define_expand "reduc_splus_v2df"
1241   [(match_operand:V2DF 0 "register_operand" "")
1242    (match_operand:V2DF 1 "register_operand" "")]
1243   "TARGET_SSE3"
1244 {
1245   emit_insn (gen_sse3_haddv2df3 (operands[0], operands[1], operands[1]));
1246   DONE;
1247 })
1248
1249 (define_expand "reduc_splus_v8sf"
1250   [(match_operand:V8SF 0 "register_operand" "")
1251    (match_operand:V8SF 1 "register_operand" "")]
1252   "TARGET_AVX"
1253 {
1254   rtx tmp = gen_reg_rtx (V8SFmode);
1255   rtx tmp2 = gen_reg_rtx (V8SFmode);
1256   emit_insn (gen_avx_haddv8sf3 (tmp, operands[1], operands[1]));
1257   emit_insn (gen_avx_haddv8sf3 (tmp2, tmp, tmp));
1258   emit_insn (gen_avx_vperm2f128v8sf3 (tmp, tmp2, tmp2, GEN_INT (1)));
1259   emit_insn (gen_addv8sf3 (operands[0], tmp, tmp2));
1260   DONE;
1261 })
1262
1263 (define_expand "reduc_splus_v4sf"
1264   [(match_operand:V4SF 0 "register_operand" "")
1265    (match_operand:V4SF 1 "register_operand" "")]
1266   "TARGET_SSE"
1267 {
1268   if (TARGET_SSE3)
1269     {
1270       rtx tmp = gen_reg_rtx (V4SFmode);
1271       emit_insn (gen_sse3_haddv4sf3 (tmp, operands[1], operands[1]));
1272       emit_insn (gen_sse3_haddv4sf3 (operands[0], tmp, tmp));
1273     }
1274   else
1275     ix86_expand_reduc (gen_addv4sf3, operands[0], operands[1]);
1276   DONE;
1277 })
1278
1279 ;; Modes handled by reduc_sm{in,ax}* patterns.
1280 (define_mode_iterator REDUC_SMINMAX_MODE
1281   [(V32QI "TARGET_AVX2") (V16HI "TARGET_AVX2")
1282    (V8SI "TARGET_AVX2") (V4DI "TARGET_AVX2")
1283    (V8SF "TARGET_AVX") (V4DF "TARGET_AVX")
1284    (V4SF "TARGET_SSE")])
1285
1286 (define_expand "reduc_<code>_<mode>"
1287   [(smaxmin:REDUC_SMINMAX_MODE
1288      (match_operand:REDUC_SMINMAX_MODE 0 "register_operand" "")
1289      (match_operand:REDUC_SMINMAX_MODE 1 "register_operand" ""))]
1290   ""
1291 {
1292   ix86_expand_reduc (gen_<code><mode>3, operands[0], operands[1]);
1293   DONE;
1294 })
1295
1296 (define_expand "reduc_<code>_<mode>"
1297   [(umaxmin:VI_256
1298      (match_operand:VI_256 0 "register_operand" "")
1299      (match_operand:VI_256 1 "register_operand" ""))]
1300   "TARGET_AVX2"
1301 {
1302   ix86_expand_reduc (gen_<code><mode>3, operands[0], operands[1]);
1303   DONE;
1304 })
1305
1306 (define_expand "reduc_umin_v8hi"
1307   [(umin:V8HI
1308      (match_operand:V8HI 0 "register_operand" "")
1309      (match_operand:V8HI 1 "register_operand" ""))]
1310   "TARGET_SSE4_1"
1311 {
1312   ix86_expand_reduc (gen_uminv8hi3, operands[0], operands[1]);
1313   DONE;
1314 })
1315
1316 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1317 ;;
1318 ;; Parallel floating point comparisons
1319 ;;
1320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1321
1322 (define_insn "avx_cmp<mode>3"
1323   [(set (match_operand:VF 0 "register_operand" "=x")
1324         (unspec:VF
1325           [(match_operand:VF 1 "register_operand" "x")
1326            (match_operand:VF 2 "nonimmediate_operand" "xm")
1327            (match_operand:SI 3 "const_0_to_31_operand" "n")]
1328           UNSPEC_PCMP))]
1329   "TARGET_AVX"
1330   "vcmp<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1331   [(set_attr "type" "ssecmp")
1332    (set_attr "length_immediate" "1")
1333    (set_attr "prefix" "vex")
1334    (set_attr "mode" "<MODE>")])
1335
1336 (define_insn "avx_vmcmp<mode>3"
1337   [(set (match_operand:VF_128 0 "register_operand" "=x")
1338         (vec_merge:VF_128
1339           (unspec:VF_128
1340             [(match_operand:VF_128 1 "register_operand" "x")
1341              (match_operand:VF_128 2 "nonimmediate_operand" "xm")
1342              (match_operand:SI 3 "const_0_to_31_operand" "n")]
1343             UNSPEC_PCMP)
1344          (match_dup 1)
1345          (const_int 1)))]
1346   "TARGET_AVX"
1347   "vcmp<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1348   [(set_attr "type" "ssecmp")
1349    (set_attr "length_immediate" "1")
1350    (set_attr "prefix" "vex")
1351    (set_attr "mode" "<ssescalarmode>")])
1352
1353 (define_insn "*<sse>_maskcmp<mode>3_comm"
1354   [(set (match_operand:VF 0 "register_operand" "=x,x")
1355         (match_operator:VF 3 "sse_comparison_operator"
1356           [(match_operand:VF 1 "register_operand" "%0,x")
1357            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")]))]
1358   "TARGET_SSE
1359    && GET_RTX_CLASS (GET_CODE (operands[3])) == RTX_COMM_COMPARE"
1360   "@
1361    cmp%D3<ssemodesuffix>\t{%2, %0|%0, %2}
1362    vcmp%D3<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1363   [(set_attr "isa" "noavx,avx")
1364    (set_attr "type" "ssecmp")
1365    (set_attr "length_immediate" "1")
1366    (set_attr "prefix" "orig,vex")
1367    (set_attr "mode" "<MODE>")])
1368
1369 (define_insn "<sse>_maskcmp<mode>3"
1370   [(set (match_operand:VF 0 "register_operand" "=x,x")
1371         (match_operator:VF 3 "sse_comparison_operator"
1372           [(match_operand:VF 1 "register_operand" "0,x")
1373            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")]))]
1374   "TARGET_SSE"
1375   "@
1376    cmp%D3<ssemodesuffix>\t{%2, %0|%0, %2}
1377    vcmp%D3<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1378   [(set_attr "isa" "noavx,avx")
1379    (set_attr "type" "ssecmp")
1380    (set_attr "length_immediate" "1")
1381    (set_attr "prefix" "orig,vex")
1382    (set_attr "mode" "<MODE>")])
1383
1384 (define_insn "<sse>_vmmaskcmp<mode>3"
1385   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
1386         (vec_merge:VF_128
1387          (match_operator:VF_128 3 "sse_comparison_operator"
1388            [(match_operand:VF_128 1 "register_operand" "0,x")
1389             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm")])
1390          (match_dup 1)
1391          (const_int 1)))]
1392   "TARGET_SSE"
1393   "@
1394    cmp%D3<ssescalarmodesuffix>\t{%2, %0|%0, %2}
1395    vcmp%D3<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1396   [(set_attr "isa" "noavx,avx")
1397    (set_attr "type" "ssecmp")
1398    (set_attr "length_immediate" "1,*")
1399    (set_attr "prefix" "orig,vex")
1400    (set_attr "mode" "<ssescalarmode>")])
1401
1402 (define_insn "<sse>_comi"
1403   [(set (reg:CCFP FLAGS_REG)
1404         (compare:CCFP
1405           (vec_select:MODEF
1406             (match_operand:<ssevecmode> 0 "register_operand" "x")
1407             (parallel [(const_int 0)]))
1408           (vec_select:MODEF
1409             (match_operand:<ssevecmode> 1 "nonimmediate_operand" "xm")
1410             (parallel [(const_int 0)]))))]
1411   "SSE_FLOAT_MODE_P (<MODE>mode)"
1412   "%vcomi<ssemodesuffix>\t{%1, %0|%0, %1}"
1413   [(set_attr "type" "ssecomi")
1414    (set_attr "prefix" "maybe_vex")
1415    (set_attr "prefix_rep" "0")
1416    (set (attr "prefix_data16")
1417         (if_then_else (eq_attr "mode" "DF")
1418                       (const_string "1")
1419                       (const_string "0")))
1420    (set_attr "mode" "<MODE>")])
1421
1422 (define_insn "<sse>_ucomi"
1423   [(set (reg:CCFPU FLAGS_REG)
1424         (compare:CCFPU
1425           (vec_select:MODEF
1426             (match_operand:<ssevecmode> 0 "register_operand" "x")
1427             (parallel [(const_int 0)]))
1428           (vec_select:MODEF
1429             (match_operand:<ssevecmode> 1 "nonimmediate_operand" "xm")
1430             (parallel [(const_int 0)]))))]
1431   "SSE_FLOAT_MODE_P (<MODE>mode)"
1432   "%vucomi<ssemodesuffix>\t{%1, %0|%0, %1}"
1433   [(set_attr "type" "ssecomi")
1434    (set_attr "prefix" "maybe_vex")
1435    (set_attr "prefix_rep" "0")
1436    (set (attr "prefix_data16")
1437         (if_then_else (eq_attr "mode" "DF")
1438                       (const_string "1")
1439                       (const_string "0")))
1440    (set_attr "mode" "<MODE>")])
1441
1442 (define_expand "vcond<V_256:mode><VF_256:mode>"
1443   [(set (match_operand:V_256 0 "register_operand" "")
1444         (if_then_else:V_256
1445           (match_operator 3 ""
1446             [(match_operand:VF_256 4 "nonimmediate_operand" "")
1447              (match_operand:VF_256 5 "nonimmediate_operand" "")])
1448           (match_operand:V_256 1 "general_operand" "")
1449           (match_operand:V_256 2 "general_operand" "")))]
1450   "TARGET_AVX
1451    && (GET_MODE_NUNITS (<V_256:MODE>mode)
1452        == GET_MODE_NUNITS (<VF_256:MODE>mode))"
1453 {
1454   bool ok = ix86_expand_fp_vcond (operands);
1455   gcc_assert (ok);
1456   DONE;
1457 })
1458
1459 (define_expand "vcond<V_128:mode><VF_128:mode>"
1460   [(set (match_operand:V_128 0 "register_operand" "")
1461         (if_then_else:V_128
1462           (match_operator 3 ""
1463             [(match_operand:VF_128 4 "nonimmediate_operand" "")
1464              (match_operand:VF_128 5 "nonimmediate_operand" "")])
1465           (match_operand:V_128 1 "general_operand" "")
1466           (match_operand:V_128 2 "general_operand" "")))]
1467   "TARGET_SSE
1468    && (GET_MODE_NUNITS (<V_128:MODE>mode)
1469        == GET_MODE_NUNITS (<VF_128:MODE>mode))"
1470 {
1471   bool ok = ix86_expand_fp_vcond (operands);
1472   gcc_assert (ok);
1473   DONE;
1474 })
1475
1476 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1477 ;;
1478 ;; Parallel floating point logical operations
1479 ;;
1480 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1481
1482 (define_insn "<sse>_andnot<mode>3"
1483   [(set (match_operand:VF 0 "register_operand" "=x,x")
1484         (and:VF
1485           (not:VF
1486             (match_operand:VF 1 "register_operand" "0,x"))
1487           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
1488   "TARGET_SSE"
1489 {
1490   static char buf[32];
1491   const char *insn;
1492   const char *suffix
1493     = TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL ? "ps" : "<ssemodesuffix>";
1494
1495   switch (which_alternative)
1496     {
1497     case 0:
1498       insn = "andn%s\t{%%2, %%0|%%0, %%2}";
1499       break;
1500     case 1:
1501       insn = "vandn%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
1502       break;
1503     default:
1504       gcc_unreachable ();
1505     }
1506
1507   snprintf (buf, sizeof (buf), insn, suffix);
1508   return buf;
1509 }
1510   [(set_attr "isa" "noavx,avx")
1511    (set_attr "type" "sselog")
1512    (set_attr "prefix" "orig,vex")
1513    (set_attr "mode" "<MODE>")])
1514
1515 (define_expand "<code><mode>3"
1516   [(set (match_operand:VF 0 "register_operand" "")
1517         (any_logic:VF
1518           (match_operand:VF 1 "nonimmediate_operand" "")
1519           (match_operand:VF 2 "nonimmediate_operand" "")))]
1520   "TARGET_SSE"
1521   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
1522
1523 (define_insn "*<code><mode>3"
1524   [(set (match_operand:VF 0 "register_operand" "=x,x")
1525         (any_logic:VF
1526           (match_operand:VF 1 "nonimmediate_operand" "%0,x")
1527           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
1528   "TARGET_SSE && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
1529 {
1530   static char buf[32];
1531   const char *insn;
1532   const char *suffix
1533     = TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL ? "ps" : "<ssemodesuffix>";
1534
1535   switch (which_alternative)
1536     {
1537     case 0:
1538       insn = "<logic>%s\t{%%2, %%0|%%0, %%2}";
1539       break;
1540     case 1:
1541       insn = "v<logic>%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
1542       break;
1543     default:
1544       gcc_unreachable ();
1545     }
1546
1547   snprintf (buf, sizeof (buf), insn, suffix);
1548   return buf;
1549 }
1550   [(set_attr "isa" "noavx,avx")
1551    (set_attr "type" "sselog")
1552    (set_attr "prefix" "orig,vex")
1553    (set_attr "mode" "<MODE>")])
1554
1555 (define_expand "copysign<mode>3"
1556   [(set (match_dup 4)
1557         (and:VF
1558           (not:VF (match_dup 3))
1559           (match_operand:VF 1 "nonimmediate_operand" "")))
1560    (set (match_dup 5)
1561         (and:VF (match_dup 3)
1562                 (match_operand:VF 2 "nonimmediate_operand" "")))
1563    (set (match_operand:VF 0 "register_operand" "")
1564         (ior:VF (match_dup 4) (match_dup 5)))]
1565   "TARGET_SSE"
1566 {
1567   operands[3] = ix86_build_signbit_mask (<MODE>mode, 1, 0);
1568
1569   operands[4] = gen_reg_rtx (<MODE>mode);
1570   operands[5] = gen_reg_rtx (<MODE>mode);
1571 })
1572
1573 ;; Also define scalar versions.  These are used for abs, neg, and
1574 ;; conditional move.  Using subregs into vector modes causes register
1575 ;; allocation lossage.  These patterns do not allow memory operands
1576 ;; because the native instructions read the full 128-bits.
1577
1578 (define_insn "*andnot<mode>3"
1579   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
1580         (and:MODEF
1581           (not:MODEF
1582             (match_operand:MODEF 1 "register_operand" "0,x"))
1583             (match_operand:MODEF 2 "register_operand" "x,x")))]
1584   "SSE_FLOAT_MODE_P (<MODE>mode)"
1585 {
1586   static char buf[32];
1587   const char *insn;
1588   const char *suffix
1589     = TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL ? "ps" : "<ssevecmodesuffix>";
1590
1591   switch (which_alternative)
1592     {
1593     case 0:
1594       insn = "andn%s\t{%%2, %%0|%%0, %%2}";
1595       break;
1596     case 1:
1597       insn = "vandn%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
1598       break;
1599     default:
1600       gcc_unreachable ();
1601     }
1602
1603   snprintf (buf, sizeof (buf), insn, suffix);
1604   return buf;
1605 }
1606   [(set_attr "isa" "noavx,avx")
1607    (set_attr "type" "sselog")
1608    (set_attr "prefix" "orig,vex")
1609    (set_attr "mode" "<ssevecmode>")])
1610
1611 (define_insn "*<code><mode>3"
1612   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
1613         (any_logic:MODEF
1614           (match_operand:MODEF 1 "register_operand" "%0,x")
1615           (match_operand:MODEF 2 "register_operand" "x,x")))]
1616   "SSE_FLOAT_MODE_P (<MODE>mode)"
1617 {
1618   static char buf[32];
1619   const char *insn;
1620   const char *suffix
1621     = TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL ? "ps" : "<ssevecmodesuffix>";
1622
1623   switch (which_alternative)
1624     {
1625     case 0:
1626       insn = "<logic>%s\t{%%2, %%0|%%0, %%2}";
1627       break;
1628     case 1:
1629       insn = "v<logic>%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
1630       break;
1631     default:
1632       gcc_unreachable ();
1633     }
1634
1635   snprintf (buf, sizeof (buf), insn, suffix);
1636   return buf;
1637 }
1638   [(set_attr "isa" "noavx,avx")
1639    (set_attr "type" "sselog")
1640    (set_attr "prefix" "orig,vex")
1641    (set_attr "mode" "<ssevecmode>")])
1642
1643 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1644 ;;
1645 ;; FMA4 floating point multiply/accumulate instructions.  This
1646 ;; includes the scalar version of the instructions as well as the
1647 ;; vector.
1648 ;;
1649 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1650
1651 ;; In order to match (*a * *b) + *c, particularly when vectorizing, allow
1652 ;; combine to generate a multiply/add with two memory references.  We then
1653 ;; split this insn, into loading up the destination register with one of the
1654 ;; memory operations.  If we don't manage to split the insn, reload will
1655 ;; generate the appropriate moves.  The reason this is needed, is that combine
1656 ;; has already folded one of the memory references into both the multiply and
1657 ;; add insns, and it can't generate a new pseudo.  I.e.:
1658 ;;      (set (reg1) (mem (addr1)))
1659 ;;      (set (reg2) (mult (reg1) (mem (addr2))))
1660 ;;      (set (reg3) (plus (reg2) (mem (addr3))))
1661 ;;
1662 ;; ??? This is historic, pre-dating the gimple fma transformation.
1663 ;; We could now properly represent that only one memory operand is
1664 ;; allowed and not be penalized during optimization.
1665
1666 ;; Intrinsic FMA operations.
1667
1668 ;; The standard names for fma is only available with SSE math enabled.
1669 (define_expand "fma<mode>4"
1670   [(set (match_operand:FMAMODE 0 "register_operand")
1671         (fma:FMAMODE
1672           (match_operand:FMAMODE 1 "nonimmediate_operand")
1673           (match_operand:FMAMODE 2 "nonimmediate_operand")
1674           (match_operand:FMAMODE 3 "nonimmediate_operand")))]
1675   "(TARGET_FMA || TARGET_FMA4) && TARGET_SSE_MATH")
1676
1677 (define_expand "fms<mode>4"
1678   [(set (match_operand:FMAMODE 0 "register_operand")
1679         (fma:FMAMODE
1680           (match_operand:FMAMODE 1 "nonimmediate_operand")
1681           (match_operand:FMAMODE 2 "nonimmediate_operand")
1682           (neg:FMAMODE (match_operand:FMAMODE 3 "nonimmediate_operand"))))]
1683   "(TARGET_FMA || TARGET_FMA4) && TARGET_SSE_MATH")
1684
1685 (define_expand "fnma<mode>4"
1686   [(set (match_operand:FMAMODE 0 "register_operand")
1687         (fma:FMAMODE
1688           (neg:FMAMODE (match_operand:FMAMODE 1 "nonimmediate_operand"))
1689           (match_operand:FMAMODE 2 "nonimmediate_operand")
1690           (match_operand:FMAMODE 3 "nonimmediate_operand")))]
1691   "(TARGET_FMA || TARGET_FMA4) && TARGET_SSE_MATH")
1692
1693 (define_expand "fnms<mode>4"
1694   [(set (match_operand:FMAMODE 0 "register_operand")
1695         (fma:FMAMODE
1696           (neg:FMAMODE (match_operand:FMAMODE 1 "nonimmediate_operand"))
1697           (match_operand:FMAMODE 2 "nonimmediate_operand")
1698           (neg:FMAMODE (match_operand:FMAMODE 3 "nonimmediate_operand"))))]
1699   "(TARGET_FMA || TARGET_FMA4) && TARGET_SSE_MATH")
1700
1701 ;; The builtin for fma4intrin.h is not constrained by SSE math enabled.
1702 (define_expand "fma4i_fmadd_<mode>"
1703   [(set (match_operand:FMAMODE 0 "register_operand")
1704         (fma:FMAMODE
1705           (match_operand:FMAMODE 1 "nonimmediate_operand")
1706           (match_operand:FMAMODE 2 "nonimmediate_operand")
1707           (match_operand:FMAMODE 3 "nonimmediate_operand")))]
1708   "TARGET_FMA || TARGET_FMA4")
1709
1710 (define_insn "*fma4i_fmadd_<mode>"
1711   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x")
1712         (fma:FMAMODE
1713           (match_operand:FMAMODE 1 "nonimmediate_operand" "%x,x")
1714           (match_operand:FMAMODE 2 "nonimmediate_operand" " x,m")
1715           (match_operand:FMAMODE 3 "nonimmediate_operand" "xm,x")))]
1716   "TARGET_FMA4"
1717   "vfmadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1718   [(set_attr "type" "ssemuladd")
1719    (set_attr "mode" "<MODE>")])
1720
1721 (define_insn "*fma4i_fmsub_<mode>"
1722   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x")
1723         (fma:FMAMODE
1724           (match_operand:FMAMODE 1 "nonimmediate_operand" "%x,x")
1725           (match_operand:FMAMODE 2 "nonimmediate_operand" " x,m")
1726           (neg:FMAMODE
1727             (match_operand:FMAMODE 3 "nonimmediate_operand" "xm,x"))))]
1728   "TARGET_FMA4"
1729   "vfmsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1730   [(set_attr "type" "ssemuladd")
1731    (set_attr "mode" "<MODE>")])
1732
1733 (define_insn "*fma4i_fnmadd_<mode>"
1734   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x")
1735         (fma:FMAMODE
1736           (neg:FMAMODE
1737             (match_operand:FMAMODE 1 "nonimmediate_operand" "%x,x"))
1738           (match_operand:FMAMODE   2 "nonimmediate_operand" " x,m")
1739           (match_operand:FMAMODE   3 "nonimmediate_operand" "xm,x")))]
1740   "TARGET_FMA4"
1741   "vfnmadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1742   [(set_attr "type" "ssemuladd")
1743    (set_attr "mode" "<MODE>")])
1744
1745 (define_insn "*fma4i_fnmsub_<mode>"
1746   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x")
1747         (fma:FMAMODE
1748           (neg:FMAMODE
1749             (match_operand:FMAMODE 1 "nonimmediate_operand" "%x,x"))
1750           (match_operand:FMAMODE   2 "nonimmediate_operand" " x,m")
1751           (neg:FMAMODE
1752             (match_operand:FMAMODE 3 "nonimmediate_operand" "xm,x"))))]
1753   "TARGET_FMA4"
1754   "vfnmsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1755   [(set_attr "type" "ssemuladd")
1756    (set_attr "mode" "<MODE>")])
1757
1758 ;; Scalar versions of the above.  Unlike ADDSS et al, these write the
1759 ;; entire destination register, with the high-order elements zeroed.
1760
1761 (define_expand "fma4i_vmfmadd_<mode>"
1762   [(set (match_operand:VF_128 0 "register_operand")
1763         (vec_merge:VF_128
1764           (fma:VF_128
1765             (match_operand:VF_128 1 "nonimmediate_operand")
1766             (match_operand:VF_128 2 "nonimmediate_operand")
1767             (match_operand:VF_128 3 "nonimmediate_operand"))
1768           (match_dup 4)
1769           (const_int 1)))]
1770   "TARGET_FMA4"
1771 {
1772   operands[4] = CONST0_RTX (<MODE>mode);
1773 })
1774
1775 (define_expand "fmai_vmfmadd_<mode>"
1776   [(set (match_operand:VF_128 0 "register_operand")
1777         (vec_merge:VF_128
1778           (fma:VF_128
1779             (match_operand:VF_128 1 "nonimmediate_operand")
1780             (match_operand:VF_128 2 "nonimmediate_operand")
1781             (match_operand:VF_128 3 "nonimmediate_operand"))
1782           (match_dup 0)
1783           (const_int 1)))]
1784   "TARGET_FMA")
1785
1786 (define_insn "*fmai_fmadd_<mode>"
1787   [(set (match_operand:VF_128 0 "register_operand" "=x,x,x")
1788         (vec_merge:VF_128
1789           (fma:VF_128
1790             (match_operand:VF_128 1 "nonimmediate_operand" "%0, 0,x")
1791             (match_operand:VF_128 2 "nonimmediate_operand" "xm, x,xm")
1792             (match_operand:VF_128 3 "nonimmediate_operand" " x,xm,0"))
1793           (match_dup 0)
1794           (const_int 1)))]
1795   "TARGET_FMA"
1796   "@
1797    vfmadd132<ssescalarmodesuffix>\t{%2, %3, %0|%0, %3, %2}
1798    vfmadd213<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}
1799    vfmadd231<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1800   [(set_attr "type" "ssemuladd")
1801    (set_attr "mode" "<MODE>")])
1802
1803 (define_insn "*fmai_fmsub_<mode>"
1804   [(set (match_operand:VF_128 0 "register_operand" "=x,x,x")
1805         (vec_merge:VF_128
1806           (fma:VF_128
1807             (match_operand:VF_128   1 "nonimmediate_operand" "%0, 0,x")
1808             (match_operand:VF_128   2 "nonimmediate_operand" "xm, x,xm")
1809             (neg:VF_128
1810               (match_operand:VF_128 3 "nonimmediate_operand" " x,xm,0")))
1811           (match_dup 0)
1812           (const_int 1)))]
1813   "TARGET_FMA"
1814   "@
1815    vfmsub132<ssescalarmodesuffix>\t{%2, %3, %0|%0, %3, %2}
1816    vfmsub213<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}
1817    vfmsub231<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1818   [(set_attr "type" "ssemuladd")
1819    (set_attr "mode" "<MODE>")])
1820
1821 (define_insn "*fmai_fnmadd_<mode>"
1822   [(set (match_operand:VF_128 0 "register_operand" "=x,x,x")
1823         (vec_merge:VF_128
1824           (fma:VF_128
1825             (neg:VF_128
1826               (match_operand:VF_128 1 "nonimmediate_operand" "%0, 0,x"))
1827             (match_operand:VF_128   2 "nonimmediate_operand" "xm, x,xm")
1828             (match_operand:VF_128   3 "nonimmediate_operand" " x,xm,0"))
1829           (match_dup 0)
1830           (const_int 1)))]
1831   "TARGET_FMA"
1832   "@
1833    vfnmadd132<ssescalarmodesuffix>\t{%2, %3, %0|%0, %3, %2}
1834    vfnmadd213<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}
1835    vfnmadd231<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1836   [(set_attr "type" "ssemuladd")
1837    (set_attr "mode" "<MODE>")])
1838
1839 (define_insn "*fmai_fnmsub_<mode>"
1840   [(set (match_operand:VF_128 0 "register_operand" "=x,x,x")
1841         (vec_merge:VF_128
1842           (fma:VF_128
1843             (neg:VF_128
1844               (match_operand:VF_128 1 "nonimmediate_operand" "%0, 0,x"))
1845             (match_operand:VF_128   2 "nonimmediate_operand" "xm, x,xm")
1846             (neg:VF_128
1847               (match_operand:VF_128 3 "nonimmediate_operand" " x,xm,0")))
1848           (match_dup 0)
1849           (const_int 1)))]
1850   "TARGET_FMA"
1851   "@
1852    vfnmsub132<ssescalarmodesuffix>\t{%2, %3, %0|%0, %3, %2}
1853    vfnmsub213<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}
1854    vfnmsub231<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1855   [(set_attr "type" "ssemuladd")
1856    (set_attr "mode" "<MODE>")])
1857
1858 (define_insn "*fma4i_vmfmadd_<mode>"
1859   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
1860         (vec_merge:VF_128
1861           (fma:VF_128
1862             (match_operand:VF_128 1 "nonimmediate_operand" "%x,x")
1863             (match_operand:VF_128 2 "nonimmediate_operand" " x,m")
1864             (match_operand:VF_128 3 "nonimmediate_operand" "xm,x"))
1865           (match_operand:VF_128 4 "const0_operand" "")
1866           (const_int 1)))]
1867   "TARGET_FMA4"
1868   "vfmadd<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1869   [(set_attr "type" "ssemuladd")
1870    (set_attr "mode" "<MODE>")])
1871
1872 (define_insn "*fma4i_vmfmsub_<mode>"
1873   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
1874         (vec_merge:VF_128
1875           (fma:VF_128
1876             (match_operand:VF_128 1 "nonimmediate_operand" "%x,x")
1877             (match_operand:VF_128 2 "nonimmediate_operand" " x,m")
1878             (neg:VF_128
1879               (match_operand:VF_128 3 "nonimmediate_operand" "xm,x")))
1880           (match_operand:VF_128 4 "const0_operand" "")
1881           (const_int 1)))]
1882   "TARGET_FMA4"
1883   "vfmsub<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1884   [(set_attr "type" "ssemuladd")
1885    (set_attr "mode" "<MODE>")])
1886
1887 (define_insn "*fma4i_vmfnmadd_<mode>"
1888   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
1889         (vec_merge:VF_128
1890           (fma:VF_128
1891             (neg:VF_128
1892               (match_operand:VF_128 1 "nonimmediate_operand" "%x,x"))
1893             (match_operand:VF_128   2 "nonimmediate_operand" " x,m")
1894             (match_operand:VF_128   3 "nonimmediate_operand" "xm,x"))
1895           (match_operand:VF_128 4 "const0_operand" "")
1896           (const_int 1)))]
1897   "TARGET_FMA4"
1898   "vfnmadd<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1899   [(set_attr "type" "ssemuladd")
1900    (set_attr "mode" "<MODE>")])
1901
1902 (define_insn "*fma4i_vmfnmsub_<mode>"
1903   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
1904         (vec_merge:VF_128
1905           (fma:VF_128
1906             (neg:VF_128
1907               (match_operand:VF_128 1 "nonimmediate_operand" "%x,x"))
1908             (match_operand:VF_128   2 "nonimmediate_operand" " x,m")
1909             (neg:VF_128
1910               (match_operand:VF_128   3 "nonimmediate_operand" "xm,x")))
1911           (match_operand:VF_128 4 "const0_operand" "")
1912           (const_int 1)))]
1913   "TARGET_FMA4"
1914   "vfnmsub<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1915   [(set_attr "type" "ssemuladd")
1916    (set_attr "mode" "<MODE>")])
1917
1918 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1919 ;;
1920 ;; FMA4 Parallel floating point multiply addsub and subadd operations.
1921 ;;
1922 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1923
1924 ;; It would be possible to represent these without the UNSPEC as
1925 ;;
1926 ;; (vec_merge
1927 ;;   (fma op1 op2 op3)
1928 ;;   (fma op1 op2 (neg op3))
1929 ;;   (merge-const))
1930 ;;
1931 ;; But this doesn't seem useful in practice.
1932
1933 (define_expand "fmaddsub_<mode>"
1934   [(set (match_operand:VF 0 "register_operand")
1935         (unspec:VF
1936           [(match_operand:VF 1 "nonimmediate_operand")
1937            (match_operand:VF 2 "nonimmediate_operand")
1938            (match_operand:VF 3 "nonimmediate_operand")]
1939           UNSPEC_FMADDSUB))]
1940   "TARGET_FMA || TARGET_FMA4")
1941
1942 (define_insn "*fma4_fmaddsub_<mode>"
1943   [(set (match_operand:VF 0 "register_operand" "=x,x")
1944         (unspec:VF
1945           [(match_operand:VF 1 "nonimmediate_operand" "%x,x")
1946            (match_operand:VF 2 "nonimmediate_operand" " x,m")
1947            (match_operand:VF 3 "nonimmediate_operand" "xm,x")]
1948           UNSPEC_FMADDSUB))]
1949   "TARGET_FMA4"
1950   "vfmaddsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1951   [(set_attr "type" "ssemuladd")
1952    (set_attr "mode" "<MODE>")])
1953
1954 (define_insn "*fma4_fmsubadd_<mode>"
1955   [(set (match_operand:VF 0 "register_operand" "=x,x")
1956         (unspec:VF
1957           [(match_operand:VF 1 "nonimmediate_operand" "%x,x")
1958            (match_operand:VF 2 "nonimmediate_operand" " x,m")
1959            (neg:VF
1960              (match_operand:VF 3 "nonimmediate_operand" "xm,x"))]
1961           UNSPEC_FMADDSUB))]
1962   "TARGET_FMA4"
1963   "vfmsubadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1964   [(set_attr "type" "ssemuladd")
1965    (set_attr "mode" "<MODE>")])
1966
1967 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1968 ;;
1969 ;; FMA3 floating point multiply/accumulate instructions.
1970 ;;
1971 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1972
1973 (define_insn "*fma_fmadd_<mode>"
1974   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x,x")
1975         (fma:FMAMODE
1976           (match_operand:FMAMODE 1 "nonimmediate_operand" "%0, 0,x")
1977           (match_operand:FMAMODE 2 "nonimmediate_operand" "xm, x,xm")
1978           (match_operand:FMAMODE 3 "nonimmediate_operand" " x,xm,0")))]
1979   "TARGET_FMA"
1980   "@
1981    vfmadd132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
1982    vfmadd213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
1983    vfmadd231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1984   [(set_attr "type" "ssemuladd")
1985    (set_attr "mode" "<MODE>")])
1986
1987 (define_insn "*fma_fmsub_<mode>"
1988   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x,x")
1989         (fma:FMAMODE
1990           (match_operand:FMAMODE   1 "nonimmediate_operand" "%0, 0,x")
1991           (match_operand:FMAMODE   2 "nonimmediate_operand" "xm, x,xm")
1992           (neg:FMAMODE
1993             (match_operand:FMAMODE 3 "nonimmediate_operand" " x,xm,0"))))]
1994   "TARGET_FMA"
1995   "@
1996    vfmsub132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
1997    vfmsub213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
1998    vfmsub231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1999   [(set_attr "type" "ssemuladd")
2000    (set_attr "mode" "<MODE>")])
2001
2002 (define_insn "*fma_fnmadd_<mode>"
2003   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x,x")
2004         (fma:FMAMODE
2005           (neg:FMAMODE
2006             (match_operand:FMAMODE 1 "nonimmediate_operand" "%0, 0,x"))
2007           (match_operand:FMAMODE   2 "nonimmediate_operand" "xm, x,xm")
2008           (match_operand:FMAMODE   3 "nonimmediate_operand" " x,xm,0")))]
2009   "TARGET_FMA"
2010   "@
2011    vfnmadd132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
2012    vfnmadd213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
2013    vfnmadd231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
2014   [(set_attr "type" "ssemuladd")
2015    (set_attr "mode" "<MODE>")])
2016
2017 (define_insn "*fma_fnmsub_<mode>"
2018   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x,x")
2019         (fma:FMAMODE
2020           (neg:FMAMODE
2021             (match_operand:FMAMODE 1 "nonimmediate_operand" "%0, 0,x"))
2022           (match_operand:FMAMODE   2 "nonimmediate_operand" "xm, x,xm")
2023           (neg:FMAMODE
2024             (match_operand:FMAMODE 3 "nonimmediate_operand" " x,xm,0"))))]
2025   "TARGET_FMA"
2026   "@
2027    vfnmsub132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
2028    vfnmsub213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
2029    vfnmsub231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
2030   [(set_attr "type" "ssemuladd")
2031    (set_attr "mode" "<MODE>")])
2032
2033 (define_insn "*fma_fmaddsub_<mode>"
2034   [(set (match_operand:VF 0 "register_operand" "=x,x,x")
2035         (unspec:VF
2036           [(match_operand:VF 1 "nonimmediate_operand" "%0, 0,x")
2037            (match_operand:VF 2 "nonimmediate_operand" "xm, x,xm")
2038            (match_operand:VF 3 "nonimmediate_operand" " x,xm,0")]
2039           UNSPEC_FMADDSUB))]
2040   "TARGET_FMA"
2041   "@
2042    vfmaddsub132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
2043    vfmaddsub213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
2044    vfmaddsub231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
2045   [(set_attr "type" "ssemuladd")
2046    (set_attr "mode" "<MODE>")])
2047
2048 (define_insn "*fma_fmsubadd_<mode>"
2049   [(set (match_operand:VF 0 "register_operand" "=x,x,x")
2050         (unspec:VF
2051           [(match_operand:VF   1 "nonimmediate_operand" "%0, 0,x")
2052            (match_operand:VF   2 "nonimmediate_operand" "xm, x,xm")
2053            (neg:VF
2054              (match_operand:VF 3 "nonimmediate_operand" " x,xm,0"))]
2055           UNSPEC_FMADDSUB))]
2056   "TARGET_FMA"
2057   "@
2058    vfmsubadd132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
2059    vfmsubadd213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
2060    vfmsubadd231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
2061   [(set_attr "type" "ssemuladd")
2062    (set_attr "mode" "<MODE>")])
2063
2064 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2065 ;;
2066 ;; Parallel single-precision floating point conversion operations
2067 ;;
2068 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2069
2070 (define_insn "sse_cvtpi2ps"
2071   [(set (match_operand:V4SF 0 "register_operand" "=x")
2072         (vec_merge:V4SF
2073           (vec_duplicate:V4SF
2074             (float:V2SF (match_operand:V2SI 2 "nonimmediate_operand" "ym")))
2075           (match_operand:V4SF 1 "register_operand" "0")
2076           (const_int 3)))]
2077   "TARGET_SSE"
2078   "cvtpi2ps\t{%2, %0|%0, %2}"
2079   [(set_attr "type" "ssecvt")
2080    (set_attr "mode" "V4SF")])
2081
2082 (define_insn "sse_cvtps2pi"
2083   [(set (match_operand:V2SI 0 "register_operand" "=y")
2084         (vec_select:V2SI
2085           (unspec:V4SI [(match_operand:V4SF 1 "nonimmediate_operand" "xm")]
2086                        UNSPEC_FIX_NOTRUNC)
2087           (parallel [(const_int 0) (const_int 1)])))]
2088   "TARGET_SSE"
2089   "cvtps2pi\t{%1, %0|%0, %1}"
2090   [(set_attr "type" "ssecvt")
2091    (set_attr "unit" "mmx")
2092    (set_attr "mode" "DI")])
2093
2094 (define_insn "sse_cvttps2pi"
2095   [(set (match_operand:V2SI 0 "register_operand" "=y")
2096         (vec_select:V2SI
2097           (fix:V4SI (match_operand:V4SF 1 "nonimmediate_operand" "xm"))
2098           (parallel [(const_int 0) (const_int 1)])))]
2099   "TARGET_SSE"
2100   "cvttps2pi\t{%1, %0|%0, %1}"
2101   [(set_attr "type" "ssecvt")
2102    (set_attr "unit" "mmx")
2103    (set_attr "prefix_rep" "0")
2104    (set_attr "mode" "SF")])
2105
2106 (define_insn "sse_cvtsi2ss"
2107   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
2108         (vec_merge:V4SF
2109           (vec_duplicate:V4SF
2110             (float:SF (match_operand:SI 2 "nonimmediate_operand" "r,m,rm")))
2111           (match_operand:V4SF 1 "register_operand" "0,0,x")
2112           (const_int 1)))]
2113   "TARGET_SSE"
2114   "@
2115    cvtsi2ss\t{%2, %0|%0, %2}
2116    cvtsi2ss\t{%2, %0|%0, %2}
2117    vcvtsi2ss\t{%2, %1, %0|%0, %1, %2}"
2118   [(set_attr "isa" "noavx,noavx,avx")
2119    (set_attr "type" "sseicvt")
2120    (set_attr "athlon_decode" "vector,double,*")
2121    (set_attr "amdfam10_decode" "vector,double,*")
2122    (set_attr "bdver1_decode" "double,direct,*")
2123    (set_attr "prefix" "orig,orig,vex")
2124    (set_attr "mode" "SF")])
2125
2126 (define_insn "sse_cvtsi2ssq"
2127   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
2128         (vec_merge:V4SF
2129           (vec_duplicate:V4SF
2130             (float:SF (match_operand:DI 2 "nonimmediate_operand" "r,m,rm")))
2131           (match_operand:V4SF 1 "register_operand" "0,0,x")
2132           (const_int 1)))]
2133   "TARGET_SSE && TARGET_64BIT"
2134   "@
2135    cvtsi2ssq\t{%2, %0|%0, %2}
2136    cvtsi2ssq\t{%2, %0|%0, %2}
2137    vcvtsi2ssq\t{%2, %1, %0|%0, %1, %2}"
2138   [(set_attr "isa" "noavx,noavx,avx")
2139    (set_attr "type" "sseicvt")
2140    (set_attr "athlon_decode" "vector,double,*")
2141    (set_attr "amdfam10_decode" "vector,double,*")
2142    (set_attr "bdver1_decode" "double,direct,*")
2143    (set_attr "length_vex" "*,*,4")
2144    (set_attr "prefix_rex" "1,1,*")
2145    (set_attr "prefix" "orig,orig,vex")
2146    (set_attr "mode" "SF")])
2147
2148 (define_insn "sse_cvtss2si"
2149   [(set (match_operand:SI 0 "register_operand" "=r,r")
2150         (unspec:SI
2151           [(vec_select:SF
2152              (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
2153              (parallel [(const_int 0)]))]
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 "bdver1_decode" "double,double")
2160    (set_attr "prefix_rep" "1")
2161    (set_attr "prefix" "maybe_vex")
2162    (set_attr "mode" "SI")])
2163
2164 (define_insn "sse_cvtss2si_2"
2165   [(set (match_operand:SI 0 "register_operand" "=r,r")
2166         (unspec:SI [(match_operand:SF 1 "nonimmediate_operand" "x,m")]
2167                    UNSPEC_FIX_NOTRUNC))]
2168   "TARGET_SSE"
2169   "%vcvtss2si\t{%1, %0|%0, %1}"
2170   [(set_attr "type" "sseicvt")
2171    (set_attr "athlon_decode" "double,vector")
2172    (set_attr "amdfam10_decode" "double,double")
2173    (set_attr "bdver1_decode" "double,double")
2174    (set_attr "prefix_rep" "1")
2175    (set_attr "prefix" "maybe_vex")
2176    (set_attr "mode" "SI")])
2177
2178 (define_insn "sse_cvtss2siq"
2179   [(set (match_operand:DI 0 "register_operand" "=r,r")
2180         (unspec:DI
2181           [(vec_select:SF
2182              (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
2183              (parallel [(const_int 0)]))]
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 "bdver1_decode" "double,double")
2190    (set_attr "prefix_rep" "1")
2191    (set_attr "prefix" "maybe_vex")
2192    (set_attr "mode" "DI")])
2193
2194 (define_insn "sse_cvtss2siq_2"
2195   [(set (match_operand:DI 0 "register_operand" "=r,r")
2196         (unspec:DI [(match_operand:SF 1 "nonimmediate_operand" "x,m")]
2197                    UNSPEC_FIX_NOTRUNC))]
2198   "TARGET_SSE && TARGET_64BIT"
2199   "%vcvtss2si{q}\t{%1, %0|%0, %1}"
2200   [(set_attr "type" "sseicvt")
2201    (set_attr "athlon_decode" "double,vector")
2202    (set_attr "amdfam10_decode" "double,double")
2203    (set_attr "bdver1_decode" "double,double")
2204    (set_attr "prefix_rep" "1")
2205    (set_attr "prefix" "maybe_vex")
2206    (set_attr "mode" "DI")])
2207
2208 (define_insn "sse_cvttss2si"
2209   [(set (match_operand:SI 0 "register_operand" "=r,r")
2210         (fix:SI
2211           (vec_select:SF
2212             (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
2213             (parallel [(const_int 0)]))))]
2214   "TARGET_SSE"
2215   "%vcvttss2si\t{%1, %0|%0, %1}"
2216   [(set_attr "type" "sseicvt")
2217    (set_attr "athlon_decode" "double,vector")
2218    (set_attr "amdfam10_decode" "double,double")
2219    (set_attr "bdver1_decode" "double,double")
2220    (set_attr "prefix_rep" "1")
2221    (set_attr "prefix" "maybe_vex")
2222    (set_attr "mode" "SI")])
2223
2224 (define_insn "sse_cvttss2siq"
2225   [(set (match_operand:DI 0 "register_operand" "=r,r")
2226         (fix:DI
2227           (vec_select:SF
2228             (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
2229             (parallel [(const_int 0)]))))]
2230   "TARGET_SSE && TARGET_64BIT"
2231   "%vcvttss2si{q}\t{%1, %0|%0, %1}"
2232   [(set_attr "type" "sseicvt")
2233    (set_attr "athlon_decode" "double,vector")
2234    (set_attr "amdfam10_decode" "double,double")
2235    (set_attr "bdver1_decode" "double,double")
2236    (set_attr "prefix_rep" "1")
2237    (set_attr "prefix" "maybe_vex")
2238    (set_attr "mode" "DI")])
2239
2240 (define_insn "avx_cvtdq2ps256"
2241   [(set (match_operand:V8SF 0 "register_operand" "=x")
2242         (float:V8SF (match_operand:V8SI 1 "nonimmediate_operand" "xm")))]
2243   "TARGET_AVX"
2244   "vcvtdq2ps\t{%1, %0|%0, %1}"
2245   [(set_attr "type" "ssecvt")
2246    (set_attr "prefix" "vex")
2247    (set_attr "mode" "V8SF")])
2248
2249 (define_insn "sse2_cvtdq2ps"
2250   [(set (match_operand:V4SF 0 "register_operand" "=x")
2251         (float:V4SF (match_operand:V4SI 1 "nonimmediate_operand" "xm")))]
2252   "TARGET_SSE2"
2253   "%vcvtdq2ps\t{%1, %0|%0, %1}"
2254   [(set_attr "type" "ssecvt")
2255    (set_attr "prefix" "maybe_vex")
2256    (set_attr "mode" "V4SF")])
2257
2258 (define_expand "sse2_cvtudq2ps"
2259   [(set (match_dup 5)
2260         (float:V4SF (match_operand:V4SI 1 "nonimmediate_operand" "")))
2261    (set (match_dup 6)
2262         (lt:V4SF (match_dup 5) (match_dup 3)))
2263    (set (match_dup 7)
2264         (and:V4SF (match_dup 6) (match_dup 4)))
2265    (set (match_operand:V4SF 0 "register_operand" "")
2266         (plus:V4SF (match_dup 5) (match_dup 7)))]
2267   "TARGET_SSE2"
2268 {
2269   REAL_VALUE_TYPE TWO32r;
2270   rtx x;
2271   int i;
2272
2273   real_ldexp (&TWO32r, &dconst1, 32);
2274   x = const_double_from_real_value (TWO32r, SFmode);
2275
2276   operands[3] = force_reg (V4SFmode, CONST0_RTX (V4SFmode));
2277   operands[4] = force_reg (V4SFmode,
2278                            ix86_build_const_vector (V4SFmode, 1, x));
2279
2280   for (i = 5; i < 8; i++)
2281     operands[i] = gen_reg_rtx (V4SFmode);
2282 })
2283
2284 (define_insn "avx_cvtps2dq256"
2285   [(set (match_operand:V8SI 0 "register_operand" "=x")
2286         (unspec:V8SI [(match_operand:V8SF 1 "nonimmediate_operand" "xm")]
2287                      UNSPEC_FIX_NOTRUNC))]
2288   "TARGET_AVX"
2289   "vcvtps2dq\t{%1, %0|%0, %1}"
2290   [(set_attr "type" "ssecvt")
2291    (set_attr "prefix" "vex")
2292    (set_attr "mode" "OI")])
2293
2294 (define_insn "sse2_cvtps2dq"
2295   [(set (match_operand:V4SI 0 "register_operand" "=x")
2296         (unspec:V4SI [(match_operand:V4SF 1 "nonimmediate_operand" "xm")]
2297                      UNSPEC_FIX_NOTRUNC))]
2298   "TARGET_SSE2"
2299   "%vcvtps2dq\t{%1, %0|%0, %1}"
2300   [(set_attr "type" "ssecvt")
2301    (set (attr "prefix_data16")
2302      (if_then_else
2303        (match_test "TARGET_AVX")
2304      (const_string "*")
2305      (const_string "1")))
2306    (set_attr "prefix" "maybe_vex")
2307    (set_attr "mode" "TI")])
2308
2309 (define_insn "avx_cvttps2dq256"
2310   [(set (match_operand:V8SI 0 "register_operand" "=x")
2311         (fix:V8SI (match_operand:V8SF 1 "nonimmediate_operand" "xm")))]
2312   "TARGET_AVX"
2313   "vcvttps2dq\t{%1, %0|%0, %1}"
2314   [(set_attr "type" "ssecvt")
2315    (set_attr "prefix" "vex")
2316    (set_attr "mode" "OI")])
2317
2318 (define_insn "sse2_cvttps2dq"
2319   [(set (match_operand:V4SI 0 "register_operand" "=x")
2320         (fix:V4SI (match_operand:V4SF 1 "nonimmediate_operand" "xm")))]
2321   "TARGET_SSE2"
2322   "%vcvttps2dq\t{%1, %0|%0, %1}"
2323   [(set_attr "type" "ssecvt")
2324    (set (attr "prefix_rep")
2325      (if_then_else
2326        (match_test "TARGET_AVX")
2327      (const_string "*")
2328      (const_string "1")))
2329    (set (attr "prefix_data16")
2330      (if_then_else
2331        (match_test "TARGET_AVX")
2332      (const_string "*")
2333      (const_string "0")))
2334    (set_attr "prefix_data16" "0")
2335    (set_attr "prefix" "maybe_vex")
2336    (set_attr "mode" "TI")])
2337
2338 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2339 ;;
2340 ;; Parallel double-precision floating point conversion operations
2341 ;;
2342 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2343
2344 (define_insn "sse2_cvtpi2pd"
2345   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
2346         (float:V2DF (match_operand:V2SI 1 "nonimmediate_operand" "y,m")))]
2347   "TARGET_SSE2"
2348   "cvtpi2pd\t{%1, %0|%0, %1}"
2349   [(set_attr "type" "ssecvt")
2350    (set_attr "unit" "mmx,*")
2351    (set_attr "prefix_data16" "1,*")
2352    (set_attr "mode" "V2DF")])
2353
2354 (define_insn "sse2_cvtpd2pi"
2355   [(set (match_operand:V2SI 0 "register_operand" "=y")
2356         (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand" "xm")]
2357                      UNSPEC_FIX_NOTRUNC))]
2358   "TARGET_SSE2"
2359   "cvtpd2pi\t{%1, %0|%0, %1}"
2360   [(set_attr "type" "ssecvt")
2361    (set_attr "unit" "mmx")
2362    (set_attr "bdver1_decode" "double")
2363    (set_attr "prefix_data16" "1")
2364    (set_attr "mode" "DI")])
2365
2366 (define_insn "sse2_cvttpd2pi"
2367   [(set (match_operand:V2SI 0 "register_operand" "=y")
2368         (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" "xm")))]
2369   "TARGET_SSE2"
2370   "cvttpd2pi\t{%1, %0|%0, %1}"
2371   [(set_attr "type" "ssecvt")
2372    (set_attr "unit" "mmx")
2373    (set_attr "bdver1_decode" "double")
2374    (set_attr "prefix_data16" "1")
2375    (set_attr "mode" "TI")])
2376
2377 (define_insn "sse2_cvtsi2sd"
2378   [(set (match_operand:V2DF 0 "register_operand" "=x,x,x")
2379         (vec_merge:V2DF
2380           (vec_duplicate:V2DF
2381             (float:DF (match_operand:SI 2 "nonimmediate_operand" "r,m,rm")))
2382           (match_operand:V2DF 1 "register_operand" "0,0,x")
2383           (const_int 1)))]
2384   "TARGET_SSE2"
2385   "@
2386    cvtsi2sd\t{%2, %0|%0, %2}
2387    cvtsi2sd\t{%2, %0|%0, %2}
2388    vcvtsi2sd\t{%2, %1, %0|%0, %1, %2}"
2389   [(set_attr "isa" "noavx,noavx,avx")
2390    (set_attr "type" "sseicvt")
2391    (set_attr "athlon_decode" "double,direct,*")
2392    (set_attr "amdfam10_decode" "vector,double,*")
2393    (set_attr "bdver1_decode" "double,direct,*")
2394    (set_attr "prefix" "orig,orig,vex")
2395    (set_attr "mode" "DF")])
2396
2397 (define_insn "sse2_cvtsi2sdq"
2398   [(set (match_operand:V2DF 0 "register_operand" "=x,x,x")
2399         (vec_merge:V2DF
2400           (vec_duplicate:V2DF
2401             (float:DF (match_operand:DI 2 "nonimmediate_operand" "r,m,rm")))
2402           (match_operand:V2DF 1 "register_operand" "0,0,x")
2403           (const_int 1)))]
2404   "TARGET_SSE2 && TARGET_64BIT"
2405   "@
2406    cvtsi2sdq\t{%2, %0|%0, %2}
2407    cvtsi2sdq\t{%2, %0|%0, %2}
2408    vcvtsi2sdq\t{%2, %1, %0|%0, %1, %2}"
2409   [(set_attr "isa" "noavx,noavx,avx")
2410    (set_attr "type" "sseicvt")
2411    (set_attr "athlon_decode" "double,direct,*")
2412    (set_attr "amdfam10_decode" "vector,double,*")
2413    (set_attr "bdver1_decode" "double,direct,*")
2414    (set_attr "length_vex" "*,*,4")
2415    (set_attr "prefix_rex" "1,1,*")
2416    (set_attr "prefix" "orig,orig,vex")
2417    (set_attr "mode" "DF")])
2418
2419 (define_insn "sse2_cvtsd2si"
2420   [(set (match_operand:SI 0 "register_operand" "=r,r")
2421         (unspec:SI
2422           [(vec_select:DF
2423              (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2424              (parallel [(const_int 0)]))]
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 "bdver1_decode" "double,double")
2431    (set_attr "prefix_rep" "1")
2432    (set_attr "prefix" "maybe_vex")
2433    (set_attr "mode" "SI")])
2434
2435 (define_insn "sse2_cvtsd2si_2"
2436   [(set (match_operand:SI 0 "register_operand" "=r,r")
2437         (unspec:SI [(match_operand:DF 1 "nonimmediate_operand" "x,m")]
2438                    UNSPEC_FIX_NOTRUNC))]
2439   "TARGET_SSE2"
2440   "%vcvtsd2si\t{%1, %0|%0, %1}"
2441   [(set_attr "type" "sseicvt")
2442    (set_attr "athlon_decode" "double,vector")
2443    (set_attr "amdfam10_decode" "double,double")
2444    (set_attr "bdver1_decode" "double,double")
2445    (set_attr "prefix_rep" "1")
2446    (set_attr "prefix" "maybe_vex")
2447    (set_attr "mode" "SI")])
2448
2449 (define_insn "sse2_cvtsd2siq"
2450   [(set (match_operand:DI 0 "register_operand" "=r,r")
2451         (unspec:DI
2452           [(vec_select:DF
2453              (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2454              (parallel [(const_int 0)]))]
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 "bdver1_decode" "double,double")
2461    (set_attr "prefix_rep" "1")
2462    (set_attr "prefix" "maybe_vex")
2463    (set_attr "mode" "DI")])
2464
2465 (define_insn "sse2_cvtsd2siq_2"
2466   [(set (match_operand:DI 0 "register_operand" "=r,r")
2467         (unspec:DI [(match_operand:DF 1 "nonimmediate_operand" "x,m")]
2468                    UNSPEC_FIX_NOTRUNC))]
2469   "TARGET_SSE2 && TARGET_64BIT"
2470   "%vcvtsd2si{q}\t{%1, %0|%0, %1}"
2471   [(set_attr "type" "sseicvt")
2472    (set_attr "athlon_decode" "double,vector")
2473    (set_attr "amdfam10_decode" "double,double")
2474    (set_attr "bdver1_decode" "double,double")
2475    (set_attr "prefix_rep" "1")
2476    (set_attr "prefix" "maybe_vex")
2477    (set_attr "mode" "DI")])
2478
2479 (define_insn "sse2_cvttsd2si"
2480   [(set (match_operand:SI 0 "register_operand" "=r,r")
2481         (fix:SI
2482           (vec_select:DF
2483             (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2484             (parallel [(const_int 0)]))))]
2485   "TARGET_SSE2"
2486   "%vcvttsd2si\t{%1, %0|%0, %1}"
2487   [(set_attr "type" "sseicvt")
2488    (set_attr "athlon_decode" "double,vector")
2489    (set_attr "amdfam10_decode" "double,double")
2490    (set_attr "bdver1_decode" "double,double")
2491    (set_attr "prefix_rep" "1")
2492    (set_attr "prefix" "maybe_vex")
2493    (set_attr "mode" "SI")])
2494
2495 (define_insn "sse2_cvttsd2siq"
2496   [(set (match_operand:DI 0 "register_operand" "=r,r")
2497         (fix:DI
2498           (vec_select:DF
2499             (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2500             (parallel [(const_int 0)]))))]
2501   "TARGET_SSE2 && TARGET_64BIT"
2502   "%vcvttsd2si{q}\t{%1, %0|%0, %1}"
2503   [(set_attr "type" "sseicvt")
2504    (set_attr "athlon_decode" "double,vector")
2505    (set_attr "amdfam10_decode" "double,double")
2506    (set_attr "bdver1_decode" "double,double")
2507    (set_attr "prefix_rep" "1")
2508    (set_attr "prefix" "maybe_vex")
2509    (set_attr "mode" "DI")])
2510
2511 (define_insn "avx_cvtdq2pd256"
2512   [(set (match_operand:V4DF 0 "register_operand" "=x")
2513         (float:V4DF (match_operand:V4SI 1 "nonimmediate_operand" "xm")))]
2514   "TARGET_AVX"
2515   "vcvtdq2pd\t{%1, %0|%0, %1}"
2516   [(set_attr "type" "ssecvt")
2517    (set_attr "prefix" "vex")
2518    (set_attr "mode" "V4DF")])
2519
2520 (define_insn "*avx_cvtdq2pd256_2"
2521   [(set (match_operand:V4DF 0 "register_operand" "=x")
2522         (float:V4DF
2523           (vec_select:V4SI
2524             (match_operand:V8SI 1 "nonimmediate_operand" "xm")
2525             (parallel [(const_int 0) (const_int 1)
2526                        (const_int 2) (const_int 3)]))))]
2527   "TARGET_AVX"
2528   "vcvtdq2pd\t{%x1, %0|%0, %x1}"
2529   [(set_attr "type" "ssecvt")
2530    (set_attr "prefix" "vex")
2531    (set_attr "mode" "V4DF")])
2532
2533 (define_insn "sse2_cvtdq2pd"
2534   [(set (match_operand:V2DF 0 "register_operand" "=x")
2535         (float:V2DF
2536           (vec_select:V2SI
2537             (match_operand:V4SI 1 "nonimmediate_operand" "xm")
2538             (parallel [(const_int 0) (const_int 1)]))))]
2539   "TARGET_SSE2"
2540   "%vcvtdq2pd\t{%1, %0|%0, %1}"
2541   [(set_attr "type" "ssecvt")
2542    (set_attr "prefix" "maybe_vex")
2543    (set_attr "mode" "V2DF")])
2544
2545 (define_insn "avx_cvtpd2dq256"
2546   [(set (match_operand:V4SI 0 "register_operand" "=x")
2547         (unspec:V4SI [(match_operand:V4DF 1 "nonimmediate_operand" "xm")]
2548                      UNSPEC_FIX_NOTRUNC))]
2549   "TARGET_AVX"
2550   "vcvtpd2dq{y}\t{%1, %0|%0, %1}"
2551   [(set_attr "type" "ssecvt")
2552    (set_attr "prefix" "vex")
2553    (set_attr "mode" "OI")])
2554
2555 (define_expand "sse2_cvtpd2dq"
2556   [(set (match_operand:V4SI 0 "register_operand" "")
2557         (vec_concat:V4SI
2558           (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand" "")]
2559                        UNSPEC_FIX_NOTRUNC)
2560           (match_dup 2)))]
2561   "TARGET_SSE2"
2562   "operands[2] = CONST0_RTX (V2SImode);")
2563
2564 (define_insn "*sse2_cvtpd2dq"
2565   [(set (match_operand:V4SI 0 "register_operand" "=x")
2566         (vec_concat:V4SI
2567           (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand" "xm")]
2568                        UNSPEC_FIX_NOTRUNC)
2569           (match_operand:V2SI 2 "const0_operand" "")))]
2570   "TARGET_SSE2"
2571 {
2572   if (TARGET_AVX)
2573     return "vcvtpd2dq{x}\t{%1, %0|%0, %1}";
2574   else
2575     return "cvtpd2dq\t{%1, %0|%0, %1}";
2576 }
2577   [(set_attr "type" "ssecvt")
2578    (set_attr "prefix_rep" "1")
2579    (set_attr "prefix_data16" "0")
2580    (set_attr "prefix" "maybe_vex")
2581    (set_attr "mode" "TI")
2582    (set_attr "amdfam10_decode" "double")
2583    (set_attr "athlon_decode" "vector")
2584    (set_attr "bdver1_decode" "double")])
2585
2586 (define_insn "avx_cvttpd2dq256"
2587   [(set (match_operand:V4SI 0 "register_operand" "=x")
2588         (fix:V4SI (match_operand:V4DF 1 "nonimmediate_operand" "xm")))]
2589   "TARGET_AVX"
2590   "vcvttpd2dq{y}\t{%1, %0|%0, %1}"
2591   [(set_attr "type" "ssecvt")
2592    (set_attr "prefix" "vex")
2593    (set_attr "mode" "OI")])
2594
2595 (define_expand "sse2_cvttpd2dq"
2596   [(set (match_operand:V4SI 0 "register_operand" "")
2597         (vec_concat:V4SI
2598           (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" ""))
2599           (match_dup 2)))]
2600   "TARGET_SSE2"
2601   "operands[2] = CONST0_RTX (V2SImode);")
2602
2603 (define_insn "*sse2_cvttpd2dq"
2604   [(set (match_operand:V4SI 0 "register_operand" "=x")
2605         (vec_concat:V4SI
2606           (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" "xm"))
2607           (match_operand:V2SI 2 "const0_operand" "")))]
2608   "TARGET_SSE2"
2609 {
2610   if (TARGET_AVX)
2611     return "vcvttpd2dq{x}\t{%1, %0|%0, %1}";
2612   else
2613     return "cvttpd2dq\t{%1, %0|%0, %1}";
2614 }
2615   [(set_attr "type" "ssecvt")
2616    (set_attr "amdfam10_decode" "double")
2617    (set_attr "athlon_decode" "vector")
2618    (set_attr "bdver1_decode" "double")
2619    (set_attr "prefix" "maybe_vex")
2620    (set_attr "mode" "TI")])
2621
2622 (define_insn "sse2_cvtsd2ss"
2623   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
2624         (vec_merge:V4SF
2625           (vec_duplicate:V4SF
2626             (float_truncate:V2SF
2627               (match_operand:V2DF 2 "nonimmediate_operand" "x,m,xm")))
2628           (match_operand:V4SF 1 "register_operand" "0,0,x")
2629           (const_int 1)))]
2630   "TARGET_SSE2"
2631   "@
2632    cvtsd2ss\t{%2, %0|%0, %2}
2633    cvtsd2ss\t{%2, %0|%0, %2}
2634    vcvtsd2ss\t{%2, %1, %0|%0, %1, %2}"
2635   [(set_attr "isa" "noavx,noavx,avx")
2636    (set_attr "type" "ssecvt")
2637    (set_attr "athlon_decode" "vector,double,*")
2638    (set_attr "amdfam10_decode" "vector,double,*")
2639    (set_attr "bdver1_decode" "direct,direct,*")
2640    (set_attr "prefix" "orig,orig,vex")
2641    (set_attr "mode" "SF")])
2642
2643 (define_insn "sse2_cvtss2sd"
2644   [(set (match_operand:V2DF 0 "register_operand" "=x,x,x")
2645         (vec_merge:V2DF
2646           (float_extend:V2DF
2647             (vec_select:V2SF
2648               (match_operand:V4SF 2 "nonimmediate_operand" "x,m,xm")
2649               (parallel [(const_int 0) (const_int 1)])))
2650           (match_operand:V2DF 1 "register_operand" "0,0,x")
2651           (const_int 1)))]
2652   "TARGET_SSE2"
2653   "@
2654    cvtss2sd\t{%2, %0|%0, %2}
2655    cvtss2sd\t{%2, %0|%0, %2}
2656    vcvtss2sd\t{%2, %1, %0|%0, %1, %2}"
2657   [(set_attr "isa" "noavx,noavx,avx")
2658    (set_attr "type" "ssecvt")
2659    (set_attr "amdfam10_decode" "vector,double,*")
2660    (set_attr "athlon_decode" "direct,direct,*")
2661    (set_attr "bdver1_decode" "direct,direct,*")
2662    (set_attr "prefix" "orig,orig,vex")
2663    (set_attr "mode" "DF")])
2664
2665 (define_insn "avx_cvtpd2ps256"
2666   [(set (match_operand:V4SF 0 "register_operand" "=x")
2667         (float_truncate:V4SF
2668           (match_operand:V4DF 1 "nonimmediate_operand" "xm")))]
2669   "TARGET_AVX"
2670   "vcvtpd2ps{y}\t{%1, %0|%0, %1}"
2671   [(set_attr "type" "ssecvt")
2672    (set_attr "prefix" "vex")
2673    (set_attr "mode" "V4SF")])
2674
2675 (define_expand "sse2_cvtpd2ps"
2676   [(set (match_operand:V4SF 0 "register_operand" "")
2677         (vec_concat:V4SF
2678           (float_truncate:V2SF
2679             (match_operand:V2DF 1 "nonimmediate_operand" ""))
2680           (match_dup 2)))]
2681   "TARGET_SSE2"
2682   "operands[2] = CONST0_RTX (V2SFmode);")
2683
2684 (define_insn "*sse2_cvtpd2ps"
2685   [(set (match_operand:V4SF 0 "register_operand" "=x")
2686         (vec_concat:V4SF
2687           (float_truncate:V2SF
2688             (match_operand:V2DF 1 "nonimmediate_operand" "xm"))
2689           (match_operand:V2SF 2 "const0_operand" "")))]
2690   "TARGET_SSE2"
2691 {
2692   if (TARGET_AVX)
2693     return "vcvtpd2ps{x}\t{%1, %0|%0, %1}";
2694   else
2695     return "cvtpd2ps\t{%1, %0|%0, %1}";
2696 }
2697   [(set_attr "type" "ssecvt")
2698    (set_attr "amdfam10_decode" "double")
2699    (set_attr "athlon_decode" "vector")
2700    (set_attr "bdver1_decode" "double")
2701    (set_attr "prefix_data16" "1")
2702    (set_attr "prefix" "maybe_vex")
2703    (set_attr "mode" "V4SF")])
2704
2705 (define_insn "avx_cvtps2pd256"
2706   [(set (match_operand:V4DF 0 "register_operand" "=x")
2707         (float_extend:V4DF
2708           (match_operand:V4SF 1 "nonimmediate_operand" "xm")))]
2709   "TARGET_AVX"
2710   "vcvtps2pd\t{%1, %0|%0, %1}"
2711   [(set_attr "type" "ssecvt")
2712    (set_attr "prefix" "vex")
2713    (set_attr "mode" "V4DF")])
2714
2715 (define_insn "*avx_cvtps2pd256_2"
2716   [(set (match_operand:V4DF 0 "register_operand" "=x")
2717         (float_extend:V4DF
2718           (vec_select:V4SF
2719             (match_operand:V8SF 1 "nonimmediate_operand" "xm")
2720             (parallel [(const_int 0) (const_int 1)
2721                        (const_int 2) (const_int 3)]))))]
2722   "TARGET_AVX"
2723   "vcvtps2pd\t{%x1, %0|%0, %x1}"
2724   [(set_attr "type" "ssecvt")
2725    (set_attr "prefix" "vex")
2726    (set_attr "mode" "V4DF")])
2727
2728 (define_insn "sse2_cvtps2pd"
2729   [(set (match_operand:V2DF 0 "register_operand" "=x")
2730         (float_extend:V2DF
2731           (vec_select:V2SF
2732             (match_operand:V4SF 1 "nonimmediate_operand" "xm")
2733             (parallel [(const_int 0) (const_int 1)]))))]
2734   "TARGET_SSE2"
2735   "%vcvtps2pd\t{%1, %0|%0, %1}"
2736   [(set_attr "type" "ssecvt")
2737    (set_attr "amdfam10_decode" "direct")
2738    (set_attr "athlon_decode" "double")
2739    (set_attr "bdver1_decode" "double")
2740    (set_attr "prefix_data16" "0")
2741    (set_attr "prefix" "maybe_vex")
2742    (set_attr "mode" "V2DF")])
2743
2744 (define_expand "vec_unpacks_hi_v4sf"
2745   [(set (match_dup 2)
2746    (vec_select:V4SF
2747      (vec_concat:V8SF
2748        (match_dup 2)
2749        (match_operand:V4SF 1 "nonimmediate_operand" ""))
2750      (parallel [(const_int 6) (const_int 7)
2751                 (const_int 2) (const_int 3)])))
2752   (set (match_operand:V2DF 0 "register_operand" "")
2753    (float_extend:V2DF
2754      (vec_select:V2SF
2755        (match_dup 2)
2756        (parallel [(const_int 0) (const_int 1)]))))]
2757   "TARGET_SSE2"
2758   "operands[2] = gen_reg_rtx (V4SFmode);")
2759
2760 (define_expand "vec_unpacks_hi_v8sf"
2761   [(set (match_dup 2)
2762         (vec_select:V4SF
2763           (match_operand:V8SF 1 "nonimmediate_operand" "")
2764           (parallel [(const_int 4) (const_int 5)
2765                      (const_int 6) (const_int 7)])))
2766    (set (match_operand:V4DF 0 "register_operand" "")
2767         (float_extend:V4DF
2768           (match_dup 2)))]
2769   "TARGET_AVX"
2770   "operands[2] = gen_reg_rtx (V4SFmode);")
2771
2772 (define_expand "vec_unpacks_lo_v4sf"
2773   [(set (match_operand:V2DF 0 "register_operand" "")
2774         (float_extend:V2DF
2775           (vec_select:V2SF
2776             (match_operand:V4SF 1 "nonimmediate_operand" "")
2777             (parallel [(const_int 0) (const_int 1)]))))]
2778   "TARGET_SSE2")
2779
2780 (define_expand "vec_unpacks_lo_v8sf"
2781   [(set (match_operand:V4DF 0 "register_operand" "")
2782         (float_extend:V4DF
2783           (vec_select:V4SF
2784             (match_operand:V8SF 1 "nonimmediate_operand" "")
2785             (parallel [(const_int 0) (const_int 1)
2786                        (const_int 2) (const_int 3)]))))]
2787   "TARGET_AVX")
2788
2789 (define_expand "vec_unpacks_float_hi_v8hi"
2790   [(match_operand:V4SF 0 "register_operand" "")
2791    (match_operand:V8HI 1 "register_operand" "")]
2792   "TARGET_SSE2"
2793 {
2794   rtx tmp = gen_reg_rtx (V4SImode);
2795
2796   emit_insn (gen_vec_unpacks_hi_v8hi (tmp, operands[1]));
2797   emit_insn (gen_sse2_cvtdq2ps (operands[0], tmp));
2798   DONE;
2799 })
2800
2801 (define_expand "vec_unpacks_float_lo_v8hi"
2802   [(match_operand:V4SF 0 "register_operand" "")
2803    (match_operand:V8HI 1 "register_operand" "")]
2804   "TARGET_SSE2"
2805 {
2806   rtx tmp = gen_reg_rtx (V4SImode);
2807
2808   emit_insn (gen_vec_unpacks_lo_v8hi (tmp, operands[1]));
2809   emit_insn (gen_sse2_cvtdq2ps (operands[0], tmp));
2810   DONE;
2811 })
2812
2813 (define_expand "vec_unpacku_float_hi_v8hi"
2814   [(match_operand:V4SF 0 "register_operand" "")
2815    (match_operand:V8HI 1 "register_operand" "")]
2816   "TARGET_SSE2"
2817 {
2818   rtx tmp = gen_reg_rtx (V4SImode);
2819
2820   emit_insn (gen_vec_unpacku_hi_v8hi (tmp, operands[1]));
2821   emit_insn (gen_sse2_cvtdq2ps (operands[0], tmp));
2822   DONE;
2823 })
2824
2825 (define_expand "vec_unpacku_float_lo_v8hi"
2826   [(match_operand:V4SF 0 "register_operand" "")
2827    (match_operand:V8HI 1 "register_operand" "")]
2828   "TARGET_SSE2"
2829 {
2830   rtx tmp = gen_reg_rtx (V4SImode);
2831
2832   emit_insn (gen_vec_unpacku_lo_v8hi (tmp, operands[1]));
2833   emit_insn (gen_sse2_cvtdq2ps (operands[0], tmp));
2834   DONE;
2835 })
2836
2837 (define_expand "vec_unpacks_float_hi_v4si"
2838   [(set (match_dup 2)
2839         (vec_select:V4SI
2840           (match_operand:V4SI 1 "nonimmediate_operand" "")
2841           (parallel [(const_int 2) (const_int 3)
2842                      (const_int 2) (const_int 3)])))
2843    (set (match_operand:V2DF 0 "register_operand" "")
2844         (float:V2DF
2845           (vec_select:V2SI
2846           (match_dup 2)
2847             (parallel [(const_int 0) (const_int 1)]))))]
2848   "TARGET_SSE2"
2849   "operands[2] = gen_reg_rtx (V4SImode);")
2850
2851 (define_expand "vec_unpacks_float_lo_v4si"
2852   [(set (match_operand:V2DF 0 "register_operand" "")
2853         (float:V2DF
2854           (vec_select:V2SI
2855             (match_operand:V4SI 1 "nonimmediate_operand" "")
2856             (parallel [(const_int 0) (const_int 1)]))))]
2857   "TARGET_SSE2")
2858
2859 (define_expand "vec_unpacks_float_hi_v8si"
2860   [(set (match_dup 2)
2861         (vec_select:V4SI
2862           (match_operand:V8SI 1 "nonimmediate_operand" "")
2863           (parallel [(const_int 4) (const_int 5)
2864                      (const_int 6) (const_int 7)])))
2865    (set (match_operand:V4DF 0 "register_operand" "")
2866         (float:V4DF
2867           (match_dup 2)))]
2868   "TARGET_AVX"
2869   "operands[2] = gen_reg_rtx (V4SImode);")
2870
2871 (define_expand "vec_unpacks_float_lo_v8si"
2872   [(set (match_operand:V4DF 0 "register_operand" "")
2873         (float:V4DF
2874           (vec_select:V4SI
2875             (match_operand:V8SI 1 "nonimmediate_operand" "")
2876             (parallel [(const_int 0) (const_int 1)
2877                        (const_int 2) (const_int 3)]))))]
2878   "TARGET_AVX")
2879
2880 (define_expand "vec_unpacku_float_hi_v4si"
2881   [(set (match_dup 5)
2882         (vec_select:V4SI
2883           (match_operand:V4SI 1 "nonimmediate_operand" "")
2884           (parallel [(const_int 2) (const_int 3)
2885                      (const_int 2) (const_int 3)])))
2886    (set (match_dup 6)
2887         (float:V2DF
2888           (vec_select:V2SI
2889           (match_dup 5)
2890             (parallel [(const_int 0) (const_int 1)]))))
2891    (set (match_dup 7)
2892         (lt:V2DF (match_dup 6) (match_dup 3)))
2893    (set (match_dup 8)
2894         (and:V2DF (match_dup 7) (match_dup 4)))
2895    (set (match_operand:V2DF 0 "register_operand" "")
2896         (plus:V2DF (match_dup 6) (match_dup 8)))]
2897   "TARGET_SSE2"
2898 {
2899   REAL_VALUE_TYPE TWO32r;
2900   rtx x;
2901   int i;
2902
2903   real_ldexp (&TWO32r, &dconst1, 32);
2904   x = const_double_from_real_value (TWO32r, DFmode);
2905
2906   operands[3] = force_reg (V2DFmode, CONST0_RTX (V2DFmode));
2907   operands[4] = force_reg (V2DFmode,
2908                            ix86_build_const_vector (V2DFmode, 1, x));
2909
2910   operands[5] = gen_reg_rtx (V4SImode);
2911
2912   for (i = 6; i < 9; i++)
2913     operands[i] = gen_reg_rtx (V2DFmode);
2914 })
2915
2916 (define_expand "vec_unpacku_float_lo_v4si"
2917   [(set (match_dup 5)
2918         (float:V2DF
2919           (vec_select:V2SI
2920             (match_operand:V4SI 1 "nonimmediate_operand" "")
2921             (parallel [(const_int 0) (const_int 1)]))))
2922    (set (match_dup 6)
2923         (lt:V2DF (match_dup 5) (match_dup 3)))
2924    (set (match_dup 7)
2925         (and:V2DF (match_dup 6) (match_dup 4)))
2926    (set (match_operand:V2DF 0 "register_operand" "")
2927         (plus:V2DF (match_dup 5) (match_dup 7)))]
2928   "TARGET_SSE2"
2929 {
2930   REAL_VALUE_TYPE TWO32r;
2931   rtx x;
2932   int i;
2933
2934   real_ldexp (&TWO32r, &dconst1, 32);
2935   x = const_double_from_real_value (TWO32r, DFmode);
2936
2937   operands[3] = force_reg (V2DFmode, CONST0_RTX (V2DFmode));
2938   operands[4] = force_reg (V2DFmode,
2939                            ix86_build_const_vector (V2DFmode, 1, x));
2940
2941   for (i = 5; i < 8; i++)
2942     operands[i] = gen_reg_rtx (V2DFmode);
2943 })
2944
2945 (define_expand "vec_pack_trunc_v4df"
2946   [(set (match_dup 3)
2947         (float_truncate:V4SF
2948           (match_operand:V4DF 1 "nonimmediate_operand" "")))
2949    (set (match_dup 4)
2950         (float_truncate:V4SF
2951           (match_operand:V4DF 2 "nonimmediate_operand" "")))
2952    (set (match_operand:V8SF 0 "register_operand" "")
2953         (vec_concat:V8SF
2954           (match_dup 3)
2955           (match_dup 4)))]
2956   "TARGET_AVX"
2957 {
2958   operands[3] = gen_reg_rtx (V4SFmode);
2959   operands[4] = gen_reg_rtx (V4SFmode);
2960 })
2961
2962 (define_expand "vec_pack_trunc_v2df"
2963   [(match_operand:V4SF 0 "register_operand" "")
2964    (match_operand:V2DF 1 "nonimmediate_operand" "")
2965    (match_operand:V2DF 2 "nonimmediate_operand" "")]
2966   "TARGET_SSE2"
2967 {
2968   rtx r1, r2;
2969
2970   r1 = gen_reg_rtx (V4SFmode);
2971   r2 = gen_reg_rtx (V4SFmode);
2972
2973   emit_insn (gen_sse2_cvtpd2ps (r1, operands[1]));
2974   emit_insn (gen_sse2_cvtpd2ps (r2, operands[2]));
2975   emit_insn (gen_sse_movlhps (operands[0], r1, r2));
2976   DONE;
2977 })
2978
2979 (define_expand "vec_pack_sfix_trunc_v2df"
2980   [(match_operand:V4SI 0 "register_operand" "")
2981    (match_operand:V2DF 1 "nonimmediate_operand" "")
2982    (match_operand:V2DF 2 "nonimmediate_operand" "")]
2983   "TARGET_SSE2"
2984 {
2985   rtx r1, r2;
2986
2987   r1 = gen_reg_rtx (V4SImode);
2988   r2 = gen_reg_rtx (V4SImode);
2989
2990   emit_insn (gen_sse2_cvttpd2dq (r1, operands[1]));
2991   emit_insn (gen_sse2_cvttpd2dq (r2, operands[2]));
2992   emit_insn (gen_vec_interleave_lowv2di (gen_lowpart (V2DImode, operands[0]),
2993                                          gen_lowpart (V2DImode, r1),
2994                                          gen_lowpart (V2DImode, r2)));
2995   DONE;
2996 })
2997
2998 (define_expand "vec_pack_sfix_v2df"
2999   [(match_operand:V4SI 0 "register_operand" "")
3000    (match_operand:V2DF 1 "nonimmediate_operand" "")
3001    (match_operand:V2DF 2 "nonimmediate_operand" "")]
3002   "TARGET_SSE2"
3003 {
3004   rtx r1, r2;
3005
3006   r1 = gen_reg_rtx (V4SImode);
3007   r2 = gen_reg_rtx (V4SImode);
3008
3009   emit_insn (gen_sse2_cvtpd2dq (r1, operands[1]));
3010   emit_insn (gen_sse2_cvtpd2dq (r2, operands[2]));
3011   emit_insn (gen_vec_interleave_lowv2di (gen_lowpart (V2DImode, operands[0]),
3012                                          gen_lowpart (V2DImode, r1),
3013                                          gen_lowpart (V2DImode, r2)));
3014   DONE;
3015 })
3016
3017 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3018 ;;
3019 ;; Parallel single-precision floating point element swizzling
3020 ;;
3021 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3022
3023 (define_expand "sse_movhlps_exp"
3024   [(set (match_operand:V4SF 0 "nonimmediate_operand" "")
3025         (vec_select:V4SF
3026           (vec_concat:V8SF
3027             (match_operand:V4SF 1 "nonimmediate_operand" "")
3028             (match_operand:V4SF 2 "nonimmediate_operand" ""))
3029           (parallel [(const_int 6)
3030                      (const_int 7)
3031                      (const_int 2)
3032                      (const_int 3)])))]
3033   "TARGET_SSE"
3034 {
3035   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
3036
3037   emit_insn (gen_sse_movhlps (dst, operands[1], operands[2]));
3038
3039   /* Fix up the destination if needed.  */
3040   if (dst != operands[0])
3041     emit_move_insn (operands[0], dst);
3042
3043   DONE;
3044 })
3045
3046 (define_insn "sse_movhlps"
3047   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,m")
3048         (vec_select:V4SF
3049           (vec_concat:V8SF
3050             (match_operand:V4SF 1 "nonimmediate_operand" " 0,x,0,x,0")
3051             (match_operand:V4SF 2 "nonimmediate_operand" " x,x,o,o,x"))
3052           (parallel [(const_int 6)
3053                      (const_int 7)
3054                      (const_int 2)
3055                      (const_int 3)])))]
3056   "TARGET_SSE && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
3057   "@
3058    movhlps\t{%2, %0|%0, %2}
3059    vmovhlps\t{%2, %1, %0|%0, %1, %2}
3060    movlps\t{%H2, %0|%0, %H2}
3061    vmovlps\t{%H2, %1, %0|%0, %1, %H2}
3062    %vmovhps\t{%2, %0|%0, %2}"
3063   [(set_attr "isa" "noavx,avx,noavx,avx,*")
3064    (set_attr "type" "ssemov")
3065    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
3066    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF,V2SF")])
3067
3068 (define_expand "sse_movlhps_exp"
3069   [(set (match_operand:V4SF 0 "nonimmediate_operand" "")
3070         (vec_select:V4SF
3071           (vec_concat:V8SF
3072             (match_operand:V4SF 1 "nonimmediate_operand" "")
3073             (match_operand:V4SF 2 "nonimmediate_operand" ""))
3074           (parallel [(const_int 0)
3075                      (const_int 1)
3076                      (const_int 4)
3077                      (const_int 5)])))]
3078   "TARGET_SSE"
3079 {
3080   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
3081
3082   emit_insn (gen_sse_movlhps (dst, operands[1], operands[2]));
3083
3084   /* Fix up the destination if needed.  */
3085   if (dst != operands[0])
3086     emit_move_insn (operands[0], dst);
3087
3088   DONE;
3089 })
3090
3091 (define_insn "sse_movlhps"
3092   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,o")
3093         (vec_select:V4SF
3094           (vec_concat:V8SF
3095             (match_operand:V4SF 1 "nonimmediate_operand" " 0,x,0,x,0")
3096             (match_operand:V4SF 2 "nonimmediate_operand" " x,x,m,x,x"))
3097           (parallel [(const_int 0)
3098                      (const_int 1)
3099                      (const_int 4)
3100                      (const_int 5)])))]
3101   "TARGET_SSE && ix86_binary_operator_ok (UNKNOWN, V4SFmode, operands)"
3102   "@
3103    movlhps\t{%2, %0|%0, %2}
3104    vmovlhps\t{%2, %1, %0|%0, %1, %2}
3105    movhps\t{%2, %0|%0, %2}
3106    vmovhps\t{%2, %1, %0|%0, %1, %2}
3107    %vmovlps\t{%2, %H0|%H0, %2}"
3108   [(set_attr "isa" "noavx,avx,noavx,avx,*")
3109    (set_attr "type" "ssemov")
3110    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
3111    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF,V2SF")])
3112
3113 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
3114 (define_insn "avx_unpckhps256"
3115   [(set (match_operand:V8SF 0 "register_operand" "=x")
3116         (vec_select:V8SF
3117           (vec_concat:V16SF
3118             (match_operand:V8SF 1 "register_operand" "x")
3119             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3120           (parallel [(const_int 2) (const_int 10)
3121                      (const_int 3) (const_int 11)
3122                      (const_int 6) (const_int 14)
3123                      (const_int 7) (const_int 15)])))]
3124   "TARGET_AVX"
3125   "vunpckhps\t{%2, %1, %0|%0, %1, %2}"
3126   [(set_attr "type" "sselog")
3127    (set_attr "prefix" "vex")
3128    (set_attr "mode" "V8SF")])
3129
3130 (define_expand "vec_interleave_highv8sf"
3131   [(set (match_dup 3)
3132         (vec_select:V8SF
3133           (vec_concat:V16SF
3134             (match_operand:V8SF 1 "register_operand" "x")
3135             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3136           (parallel [(const_int 0) (const_int 8)
3137                      (const_int 1) (const_int 9)
3138                      (const_int 4) (const_int 12)
3139                      (const_int 5) (const_int 13)])))
3140    (set (match_dup 4)
3141         (vec_select:V8SF
3142           (vec_concat:V16SF
3143             (match_dup 1)
3144             (match_dup 2))
3145           (parallel [(const_int 2) (const_int 10)
3146                      (const_int 3) (const_int 11)
3147                      (const_int 6) (const_int 14)
3148                      (const_int 7) (const_int 15)])))
3149    (set (match_operand:V8SF 0 "register_operand" "")
3150         (vec_select:V8SF
3151           (vec_concat:V16SF
3152             (match_dup 3)
3153             (match_dup 4))
3154           (parallel [(const_int 4) (const_int 5)
3155                      (const_int 6) (const_int 7)
3156                      (const_int 12) (const_int 13)
3157                      (const_int 14) (const_int 15)])))]
3158  "TARGET_AVX"
3159 {
3160   operands[3] = gen_reg_rtx (V8SFmode);
3161   operands[4] = gen_reg_rtx (V8SFmode);
3162 })
3163
3164 (define_insn "vec_interleave_highv4sf"
3165   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
3166         (vec_select:V4SF
3167           (vec_concat:V8SF
3168             (match_operand:V4SF 1 "register_operand" "0,x")
3169             (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm"))
3170           (parallel [(const_int 2) (const_int 6)
3171                      (const_int 3) (const_int 7)])))]
3172   "TARGET_SSE"
3173   "@
3174    unpckhps\t{%2, %0|%0, %2}
3175    vunpckhps\t{%2, %1, %0|%0, %1, %2}"
3176   [(set_attr "isa" "noavx,avx")
3177    (set_attr "type" "sselog")
3178    (set_attr "prefix" "orig,vex")
3179    (set_attr "mode" "V4SF")])
3180
3181 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
3182 (define_insn "avx_unpcklps256"
3183   [(set (match_operand:V8SF 0 "register_operand" "=x")
3184         (vec_select:V8SF
3185           (vec_concat:V16SF
3186             (match_operand:V8SF 1 "register_operand" "x")
3187             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3188           (parallel [(const_int 0) (const_int 8)
3189                      (const_int 1) (const_int 9)
3190                      (const_int 4) (const_int 12)
3191                      (const_int 5) (const_int 13)])))]
3192   "TARGET_AVX"
3193   "vunpcklps\t{%2, %1, %0|%0, %1, %2}"
3194   [(set_attr "type" "sselog")
3195    (set_attr "prefix" "vex")
3196    (set_attr "mode" "V8SF")])
3197
3198 (define_expand "vec_interleave_lowv8sf"
3199   [(set (match_dup 3)
3200         (vec_select:V8SF
3201           (vec_concat:V16SF
3202             (match_operand:V8SF 1 "register_operand" "x")
3203             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3204           (parallel [(const_int 0) (const_int 8)
3205                      (const_int 1) (const_int 9)
3206                      (const_int 4) (const_int 12)
3207                      (const_int 5) (const_int 13)])))
3208    (set (match_dup 4)
3209         (vec_select:V8SF
3210           (vec_concat:V16SF
3211             (match_dup 1)
3212             (match_dup 2))
3213           (parallel [(const_int 2) (const_int 10)
3214                      (const_int 3) (const_int 11)
3215                      (const_int 6) (const_int 14)
3216                      (const_int 7) (const_int 15)])))
3217    (set (match_operand:V8SF 0 "register_operand" "")
3218         (vec_select:V8SF
3219           (vec_concat:V16SF
3220             (match_dup 3)
3221             (match_dup 4))
3222           (parallel [(const_int 0) (const_int 1)
3223                      (const_int 2) (const_int 3)
3224                      (const_int 8) (const_int 9)
3225                      (const_int 10) (const_int 11)])))]
3226  "TARGET_AVX"
3227 {
3228   operands[3] = gen_reg_rtx (V8SFmode);
3229   operands[4] = gen_reg_rtx (V8SFmode);
3230 })
3231
3232 (define_insn "vec_interleave_lowv4sf"
3233   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
3234         (vec_select:V4SF
3235           (vec_concat:V8SF
3236             (match_operand:V4SF 1 "register_operand" "0,x")
3237             (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm"))
3238           (parallel [(const_int 0) (const_int 4)
3239                      (const_int 1) (const_int 5)])))]
3240   "TARGET_SSE"
3241   "@
3242    unpcklps\t{%2, %0|%0, %2}
3243    vunpcklps\t{%2, %1, %0|%0, %1, %2}"
3244   [(set_attr "isa" "noavx,avx")
3245    (set_attr "type" "sselog")
3246    (set_attr "prefix" "orig,vex")
3247    (set_attr "mode" "V4SF")])
3248
3249 ;; These are modeled with the same vec_concat as the others so that we
3250 ;; capture users of shufps that can use the new instructions
3251 (define_insn "avx_movshdup256"
3252   [(set (match_operand:V8SF 0 "register_operand" "=x")
3253         (vec_select:V8SF
3254           (vec_concat:V16SF
3255             (match_operand:V8SF 1 "nonimmediate_operand" "xm")
3256             (match_dup 1))
3257           (parallel [(const_int 1) (const_int 1)
3258                      (const_int 3) (const_int 3)
3259                      (const_int 5) (const_int 5)
3260                      (const_int 7) (const_int 7)])))]
3261   "TARGET_AVX"
3262   "vmovshdup\t{%1, %0|%0, %1}"
3263   [(set_attr "type" "sse")
3264    (set_attr "prefix" "vex")
3265    (set_attr "mode" "V8SF")])
3266
3267 (define_insn "sse3_movshdup"
3268   [(set (match_operand:V4SF 0 "register_operand" "=x")
3269         (vec_select:V4SF
3270           (vec_concat:V8SF
3271             (match_operand:V4SF 1 "nonimmediate_operand" "xm")
3272             (match_dup 1))
3273           (parallel [(const_int 1)
3274                      (const_int 1)
3275                      (const_int 7)
3276                      (const_int 7)])))]
3277   "TARGET_SSE3"
3278   "%vmovshdup\t{%1, %0|%0, %1}"
3279   [(set_attr "type" "sse")
3280    (set_attr "prefix_rep" "1")
3281    (set_attr "prefix" "maybe_vex")
3282    (set_attr "mode" "V4SF")])
3283
3284 (define_insn "avx_movsldup256"
3285   [(set (match_operand:V8SF 0 "register_operand" "=x")
3286         (vec_select:V8SF
3287           (vec_concat:V16SF
3288             (match_operand:V8SF 1 "nonimmediate_operand" "xm")
3289             (match_dup 1))
3290           (parallel [(const_int 0) (const_int 0)
3291                      (const_int 2) (const_int 2)
3292                      (const_int 4) (const_int 4)
3293                      (const_int 6) (const_int 6)])))]
3294   "TARGET_AVX"
3295   "vmovsldup\t{%1, %0|%0, %1}"
3296   [(set_attr "type" "sse")
3297    (set_attr "prefix" "vex")
3298    (set_attr "mode" "V8SF")])
3299
3300 (define_insn "sse3_movsldup"
3301   [(set (match_operand:V4SF 0 "register_operand" "=x")
3302         (vec_select:V4SF
3303           (vec_concat:V8SF
3304             (match_operand:V4SF 1 "nonimmediate_operand" "xm")
3305             (match_dup 1))
3306           (parallel [(const_int 0)
3307                      (const_int 0)
3308                      (const_int 6)
3309                      (const_int 6)])))]
3310   "TARGET_SSE3"
3311   "%vmovsldup\t{%1, %0|%0, %1}"
3312   [(set_attr "type" "sse")
3313    (set_attr "prefix_rep" "1")
3314    (set_attr "prefix" "maybe_vex")
3315    (set_attr "mode" "V4SF")])
3316
3317 (define_expand "avx_shufps256"
3318   [(match_operand:V8SF 0 "register_operand" "")
3319    (match_operand:V8SF 1 "register_operand" "")
3320    (match_operand:V8SF 2 "nonimmediate_operand" "")
3321    (match_operand:SI 3 "const_int_operand" "")]
3322   "TARGET_AVX"
3323 {
3324   int mask = INTVAL (operands[3]);
3325   emit_insn (gen_avx_shufps256_1 (operands[0], operands[1], operands[2],
3326                                   GEN_INT ((mask >> 0) & 3),
3327                                   GEN_INT ((mask >> 2) & 3),
3328                                   GEN_INT (((mask >> 4) & 3) + 8),
3329                                   GEN_INT (((mask >> 6) & 3) + 8),
3330                                   GEN_INT (((mask >> 0) & 3) + 4),
3331                                   GEN_INT (((mask >> 2) & 3) + 4),
3332                                   GEN_INT (((mask >> 4) & 3) + 12),
3333                                   GEN_INT (((mask >> 6) & 3) + 12)));
3334   DONE;
3335 })
3336
3337 ;; One bit in mask selects 2 elements.
3338 (define_insn "avx_shufps256_1"
3339   [(set (match_operand:V8SF 0 "register_operand" "=x")
3340         (vec_select:V8SF
3341           (vec_concat:V16SF
3342             (match_operand:V8SF 1 "register_operand" "x")
3343             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3344           (parallel [(match_operand 3  "const_0_to_3_operand"   "")
3345                      (match_operand 4  "const_0_to_3_operand"   "")
3346                      (match_operand 5  "const_8_to_11_operand"  "")
3347                      (match_operand 6  "const_8_to_11_operand"  "")
3348                      (match_operand 7  "const_4_to_7_operand"   "")
3349                      (match_operand 8  "const_4_to_7_operand"   "")
3350                      (match_operand 9  "const_12_to_15_operand" "")
3351                      (match_operand 10 "const_12_to_15_operand" "")])))]
3352   "TARGET_AVX
3353    && (INTVAL (operands[3]) == (INTVAL (operands[7]) - 4)
3354        && INTVAL (operands[4]) == (INTVAL (operands[8]) - 4)
3355        && INTVAL (operands[5]) == (INTVAL (operands[9]) - 4)
3356        && INTVAL (operands[6]) == (INTVAL (operands[10]) - 4))"
3357 {
3358   int mask;
3359   mask = INTVAL (operands[3]);
3360   mask |= INTVAL (operands[4]) << 2;
3361   mask |= (INTVAL (operands[5]) - 8) << 4;
3362   mask |= (INTVAL (operands[6]) - 8) << 6;
3363   operands[3] = GEN_INT (mask);
3364
3365   return "vshufps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
3366 }
3367   [(set_attr "type" "sselog")
3368    (set_attr "length_immediate" "1")
3369    (set_attr "prefix" "vex")
3370    (set_attr "mode" "V8SF")])
3371
3372 (define_expand "sse_shufps"
3373   [(match_operand:V4SF 0 "register_operand" "")
3374    (match_operand:V4SF 1 "register_operand" "")
3375    (match_operand:V4SF 2 "nonimmediate_operand" "")
3376    (match_operand:SI 3 "const_int_operand" "")]
3377   "TARGET_SSE"
3378 {
3379   int mask = INTVAL (operands[3]);
3380   emit_insn (gen_sse_shufps_v4sf (operands[0], operands[1], operands[2],
3381                                GEN_INT ((mask >> 0) & 3),
3382                                GEN_INT ((mask >> 2) & 3),
3383                                GEN_INT (((mask >> 4) & 3) + 4),
3384                                GEN_INT (((mask >> 6) & 3) + 4)));
3385   DONE;
3386 })
3387
3388 (define_insn "sse_shufps_<mode>"
3389   [(set (match_operand:VI4F_128 0 "register_operand" "=x,x")
3390         (vec_select:VI4F_128
3391           (vec_concat:<ssedoublevecmode>
3392             (match_operand:VI4F_128 1 "register_operand" "0,x")
3393             (match_operand:VI4F_128 2 "nonimmediate_operand" "xm,xm"))
3394           (parallel [(match_operand 3 "const_0_to_3_operand" "")
3395                      (match_operand 4 "const_0_to_3_operand" "")
3396                      (match_operand 5 "const_4_to_7_operand" "")
3397                      (match_operand 6 "const_4_to_7_operand" "")])))]
3398   "TARGET_SSE"
3399 {
3400   int mask = 0;
3401   mask |= INTVAL (operands[3]) << 0;
3402   mask |= INTVAL (operands[4]) << 2;
3403   mask |= (INTVAL (operands[5]) - 4) << 4;
3404   mask |= (INTVAL (operands[6]) - 4) << 6;
3405   operands[3] = GEN_INT (mask);
3406
3407   switch (which_alternative)
3408     {
3409     case 0:
3410       return "shufps\t{%3, %2, %0|%0, %2, %3}";
3411     case 1:
3412       return "vshufps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
3413     default:
3414       gcc_unreachable ();
3415     }
3416 }
3417   [(set_attr "isa" "noavx,avx")
3418    (set_attr "type" "sselog")
3419    (set_attr "length_immediate" "1")
3420    (set_attr "prefix" "orig,vex")
3421    (set_attr "mode" "V4SF")])
3422
3423 (define_insn "sse_storehps"
3424   [(set (match_operand:V2SF 0 "nonimmediate_operand" "=m,x,x")
3425         (vec_select:V2SF
3426           (match_operand:V4SF 1 "nonimmediate_operand" "x,x,o")
3427           (parallel [(const_int 2) (const_int 3)])))]
3428   "TARGET_SSE"
3429   "@
3430    %vmovhps\t{%1, %0|%0, %1}
3431    %vmovhlps\t{%1, %d0|%d0, %1}
3432    %vmovlps\t{%H1, %d0|%d0, %H1}"
3433   [(set_attr "type" "ssemov")
3434    (set_attr "prefix" "maybe_vex")
3435    (set_attr "mode" "V2SF,V4SF,V2SF")])
3436
3437 (define_expand "sse_loadhps_exp"
3438   [(set (match_operand:V4SF 0 "nonimmediate_operand" "")
3439         (vec_concat:V4SF
3440           (vec_select:V2SF
3441             (match_operand:V4SF 1 "nonimmediate_operand" "")
3442             (parallel [(const_int 0) (const_int 1)]))
3443           (match_operand:V2SF 2 "nonimmediate_operand" "")))]
3444   "TARGET_SSE"
3445 {
3446   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
3447
3448   emit_insn (gen_sse_loadhps (dst, operands[1], operands[2]));
3449
3450   /* Fix up the destination if needed.  */
3451   if (dst != operands[0])
3452     emit_move_insn (operands[0], dst);
3453
3454   DONE;
3455 })
3456
3457 (define_insn "sse_loadhps"
3458   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,o")
3459         (vec_concat:V4SF
3460           (vec_select:V2SF
3461             (match_operand:V4SF 1 "nonimmediate_operand" " 0,x,0,x,0")
3462             (parallel [(const_int 0) (const_int 1)]))
3463           (match_operand:V2SF 2 "nonimmediate_operand"   " m,m,x,x,x")))]
3464   "TARGET_SSE"
3465   "@
3466    movhps\t{%2, %0|%0, %2}
3467    vmovhps\t{%2, %1, %0|%0, %1, %2}
3468    movlhps\t{%2, %0|%0, %2}
3469    vmovlhps\t{%2, %1, %0|%0, %1, %2}
3470    %vmovlps\t{%2, %H0|%H0, %2}"
3471   [(set_attr "isa" "noavx,avx,noavx,avx,*")
3472    (set_attr "type" "ssemov")
3473    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
3474    (set_attr "mode" "V2SF,V2SF,V4SF,V4SF,V2SF")])
3475
3476 (define_insn "sse_storelps"
3477   [(set (match_operand:V2SF 0 "nonimmediate_operand"   "=m,x,x")
3478         (vec_select:V2SF
3479           (match_operand:V4SF 1 "nonimmediate_operand" " x,x,m")
3480           (parallel [(const_int 0) (const_int 1)])))]
3481   "TARGET_SSE"
3482   "@
3483    %vmovlps\t{%1, %0|%0, %1}
3484    %vmovaps\t{%1, %0|%0, %1}
3485    %vmovlps\t{%1, %d0|%d0, %1}"
3486   [(set_attr "type" "ssemov")
3487    (set_attr "prefix" "maybe_vex")
3488    (set_attr "mode" "V2SF,V4SF,V2SF")])
3489
3490 (define_expand "sse_loadlps_exp"
3491   [(set (match_operand:V4SF 0 "nonimmediate_operand" "")
3492         (vec_concat:V4SF
3493           (match_operand:V2SF 2 "nonimmediate_operand" "")
3494           (vec_select:V2SF
3495             (match_operand:V4SF 1 "nonimmediate_operand" "")
3496             (parallel [(const_int 2) (const_int 3)]))))]
3497   "TARGET_SSE"
3498 {
3499   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
3500
3501   emit_insn (gen_sse_loadlps (dst, operands[1], operands[2]));
3502
3503   /* Fix up the destination if needed.  */
3504   if (dst != operands[0])
3505     emit_move_insn (operands[0], dst);
3506
3507   DONE;
3508 })
3509
3510 (define_insn "sse_loadlps"
3511   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,m")
3512         (vec_concat:V4SF
3513           (match_operand:V2SF 2 "nonimmediate_operand"   " 0,x,m,x,x")
3514           (vec_select:V2SF
3515             (match_operand:V4SF 1 "nonimmediate_operand" " x,x,0,x,0")
3516             (parallel [(const_int 2) (const_int 3)]))))]
3517   "TARGET_SSE"
3518   "@
3519    shufps\t{$0xe4, %1, %0|%0, %1, 0xe4}
3520    vshufps\t{$0xe4, %1, %2, %0|%0, %2, %1, 0xe4}
3521    movlps\t{%2, %0|%0, %2}
3522    vmovlps\t{%2, %1, %0|%0, %1, %2}
3523    %vmovlps\t{%2, %0|%0, %2}"
3524   [(set_attr "isa" "noavx,avx,noavx,avx,*")
3525    (set_attr "type" "sselog,sselog,ssemov,ssemov,ssemov")
3526    (set_attr "length_immediate" "1,1,*,*,*")
3527    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
3528    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF,V2SF")])
3529
3530 (define_insn "sse_movss"
3531   [(set (match_operand:V4SF 0 "register_operand"   "=x,x")
3532         (vec_merge:V4SF
3533           (match_operand:V4SF 2 "register_operand" " x,x")
3534           (match_operand:V4SF 1 "register_operand" " 0,x")
3535           (const_int 1)))]
3536   "TARGET_SSE"
3537   "@
3538    movss\t{%2, %0|%0, %2}
3539    vmovss\t{%2, %1, %0|%0, %1, %2}"
3540   [(set_attr "isa" "noavx,avx")
3541    (set_attr "type" "ssemov")
3542    (set_attr "prefix" "orig,vex")
3543    (set_attr "mode" "SF")])
3544
3545 (define_expand "vec_dupv4sf"
3546   [(set (match_operand:V4SF 0 "register_operand" "")
3547         (vec_duplicate:V4SF
3548           (match_operand:SF 1 "nonimmediate_operand" "")))]
3549   "TARGET_SSE"
3550 {
3551   if (!TARGET_AVX)
3552     operands[1] = force_reg (SFmode, operands[1]);
3553 })
3554
3555 (define_insn "avx2_vec_dupv4sf"
3556   [(set (match_operand:V4SF 0 "register_operand" "=x")
3557         (vec_duplicate:V4SF
3558           (vec_select:SF
3559             (match_operand:V4SF 1 "register_operand" "x")
3560             (parallel [(const_int 0)]))))]
3561   "TARGET_AVX2"
3562   "vbroadcastss\t{%1, %0|%0, %1}"
3563   [(set_attr "type" "sselog1")
3564     (set_attr "prefix" "vex")
3565     (set_attr "mode" "V4SF")])
3566
3567 (define_insn "*vec_dupv4sf_avx"
3568   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
3569         (vec_duplicate:V4SF
3570           (match_operand:SF 1 "nonimmediate_operand" "x,m")))]
3571   "TARGET_AVX"
3572   "@
3573    vshufps\t{$0, %1, %1, %0|%0, %1, %1, 0}
3574    vbroadcastss\t{%1, %0|%0, %1}"
3575   [(set_attr "type" "sselog1,ssemov")
3576    (set_attr "length_immediate" "1,0")
3577    (set_attr "prefix_extra" "0,1")
3578    (set_attr "prefix" "vex")
3579    (set_attr "mode" "V4SF")])
3580
3581 (define_insn "avx2_vec_dupv8sf"
3582   [(set (match_operand:V8SF 0 "register_operand" "=x")
3583         (vec_duplicate:V8SF
3584           (vec_select:SF
3585             (match_operand:V4SF 1 "register_operand" "x")
3586             (parallel [(const_int 0)]))))]
3587   "TARGET_AVX2"
3588   "vbroadcastss\t{%1, %0|%0, %1}"
3589   [(set_attr "type" "sselog1")
3590    (set_attr "prefix" "vex")
3591    (set_attr "mode" "V8SF")])
3592
3593 (define_insn "*vec_dupv4sf"
3594   [(set (match_operand:V4SF 0 "register_operand" "=x")
3595         (vec_duplicate:V4SF
3596           (match_operand:SF 1 "register_operand" "0")))]
3597   "TARGET_SSE"
3598   "shufps\t{$0, %0, %0|%0, %0, 0}"
3599   [(set_attr "type" "sselog1")
3600    (set_attr "length_immediate" "1")
3601    (set_attr "mode" "V4SF")])
3602
3603 ;; Although insertps takes register source, we prefer
3604 ;; unpcklps with register source since it is shorter.
3605 (define_insn "*vec_concatv2sf_sse4_1"
3606   [(set (match_operand:V2SF 0 "register_operand"     "=x,x,x,x,x,*y ,*y")
3607         (vec_concat:V2SF
3608           (match_operand:SF 1 "nonimmediate_operand" " 0,x,0,x,m, 0 , m")
3609           (match_operand:SF 2 "vector_move_operand"  " x,x,m,m,C,*ym, C")))]
3610   "TARGET_SSE4_1"
3611   "@
3612    unpcklps\t{%2, %0|%0, %2}
3613    vunpcklps\t{%2, %1, %0|%0, %1, %2}
3614    insertps\t{$0x10, %2, %0|%0, %2, 0x10}
3615    vinsertps\t{$0x10, %2, %1, %0|%0, %1, %2, 0x10}
3616    %vmovss\t{%1, %0|%0, %1}
3617    punpckldq\t{%2, %0|%0, %2}
3618    movd\t{%1, %0|%0, %1}"
3619   [(set_attr "isa" "noavx,avx,noavx,avx,*,*,*")
3620    (set_attr "type" "sselog,sselog,sselog,sselog,ssemov,mmxcvt,mmxmov")
3621    (set_attr "prefix_data16" "*,*,1,*,*,*,*")
3622    (set_attr "prefix_extra" "*,*,1,1,*,*,*")
3623    (set_attr "length_immediate" "*,*,1,1,*,*,*")
3624    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex,orig,orig")
3625    (set_attr "mode" "V4SF,V4SF,V4SF,V4SF,SF,DI,DI")])
3626
3627 ;; ??? In theory we can match memory for the MMX alternative, but allowing
3628 ;; nonimmediate_operand for operand 2 and *not* allowing memory for the SSE
3629 ;; alternatives pretty much forces the MMX alternative to be chosen.
3630 (define_insn "*vec_concatv2sf_sse"
3631   [(set (match_operand:V2SF 0 "register_operand"     "=x,x,*y,*y")
3632         (vec_concat:V2SF
3633           (match_operand:SF 1 "nonimmediate_operand" " 0,m, 0, m")
3634           (match_operand:SF 2 "reg_or_0_operand"     " x,C,*y, C")))]
3635   "TARGET_SSE"
3636   "@
3637    unpcklps\t{%2, %0|%0, %2}
3638    movss\t{%1, %0|%0, %1}
3639    punpckldq\t{%2, %0|%0, %2}
3640    movd\t{%1, %0|%0, %1}"
3641   [(set_attr "type" "sselog,ssemov,mmxcvt,mmxmov")
3642    (set_attr "mode" "V4SF,SF,DI,DI")])
3643
3644 (define_insn "*vec_concatv4sf"
3645   [(set (match_operand:V4SF 0 "register_operand"       "=x,x,x,x")
3646         (vec_concat:V4SF
3647           (match_operand:V2SF 1 "register_operand"     " 0,x,0,x")
3648           (match_operand:V2SF 2 "nonimmediate_operand" " x,x,m,m")))]
3649   "TARGET_SSE"
3650   "@
3651    movlhps\t{%2, %0|%0, %2}
3652    vmovlhps\t{%2, %1, %0|%0, %1, %2}
3653    movhps\t{%2, %0|%0, %2}
3654    vmovhps\t{%2, %1, %0|%0, %1, %2}"
3655   [(set_attr "isa" "noavx,avx,noavx,avx")
3656    (set_attr "type" "ssemov")
3657    (set_attr "prefix" "orig,vex,orig,vex")
3658    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF")])
3659
3660 (define_expand "vec_init<mode>"
3661   [(match_operand:V_128 0 "register_operand" "")
3662    (match_operand 1 "" "")]
3663   "TARGET_SSE"
3664 {
3665   ix86_expand_vector_init (false, operands[0], operands[1]);
3666   DONE;
3667 })
3668
3669 ;; Avoid combining registers from different units in a single alternative,
3670 ;; see comment above inline_secondary_memory_needed function in i386.c
3671 (define_insn "vec_set<mode>_0"
3672   [(set (match_operand:VI4F_128 0 "nonimmediate_operand"
3673           "=x,x,x ,x,x,x,x  ,x  ,m,m ,m")
3674         (vec_merge:VI4F_128
3675           (vec_duplicate:VI4F_128
3676             (match_operand:<ssescalarmode> 2 "general_operand"
3677           " x,m,*r,m,x,x,*rm,*rm,x,fF,*r"))
3678           (match_operand:VI4F_128 1 "vector_move_operand"
3679           " C,C,C ,C,0,x,0  ,x  ,0,0 ,0")
3680           (const_int 1)))]
3681   "TARGET_SSE"
3682   "@
3683    %vinsertps\t{$0xe, %d2, %0|%0, %d2, 0xe}
3684    %vmov<ssescalarmodesuffix>\t{%2, %0|%0, %2}
3685    %vmovd\t{%2, %0|%0, %2}
3686    movss\t{%2, %0|%0, %2}
3687    movss\t{%2, %0|%0, %2}
3688    vmovss\t{%2, %1, %0|%0, %1, %2}
3689    pinsrd\t{$0, %2, %0|%0, %2, 0}
3690    vpinsrd\t{$0, %2, %1, %0|%0, %1, %2, 0}
3691    #
3692    #
3693    #"
3694   [(set_attr "isa" "sse4,sse2,sse2,noavx,noavx,avx,sse4_noavx,avx,*,*,*")
3695    (set (attr "type")
3696      (cond [(eq_attr "alternative" "0,6,7")
3697               (const_string "sselog")
3698             (eq_attr "alternative" "9")
3699               (const_string "fmov")
3700             (eq_attr "alternative" "10")
3701               (const_string "imov")
3702            ]
3703            (const_string "ssemov")))
3704    (set_attr "prefix_extra" "*,*,*,*,*,*,1,1,*,*,*")
3705    (set_attr "length_immediate" "*,*,*,*,*,*,1,1,*,*,*")
3706    (set_attr "prefix" "maybe_vex,maybe_vex,maybe_vex,orig,orig,vex,orig,vex,*,*,*")
3707    (set_attr "mode" "SF,<ssescalarmode>,SI,SF,SF,SF,TI,TI,*,*,*")])
3708
3709 ;; A subset is vec_setv4sf.
3710 (define_insn "*vec_setv4sf_sse4_1"
3711   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
3712         (vec_merge:V4SF
3713           (vec_duplicate:V4SF
3714             (match_operand:SF 2 "nonimmediate_operand" "xm,xm"))
3715           (match_operand:V4SF 1 "register_operand" "0,x")
3716           (match_operand:SI 3 "const_int_operand" "")))]
3717   "TARGET_SSE4_1
3718    && ((unsigned) exact_log2 (INTVAL (operands[3]))
3719        < GET_MODE_NUNITS (V4SFmode))"
3720 {
3721   operands[3] = GEN_INT (exact_log2 (INTVAL (operands[3])) << 4);
3722   switch (which_alternative)
3723     {
3724     case 0:
3725       return "insertps\t{%3, %2, %0|%0, %2, %3}";
3726     case 1:
3727       return "vinsertps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
3728     default:
3729       gcc_unreachable ();
3730     }
3731 }
3732   [(set_attr "isa" "noavx,avx")
3733    (set_attr "type" "sselog")
3734    (set_attr "prefix_data16" "1,*")
3735    (set_attr "prefix_extra" "1")
3736    (set_attr "length_immediate" "1")
3737    (set_attr "prefix" "orig,vex")
3738    (set_attr "mode" "V4SF")])
3739
3740 (define_insn "sse4_1_insertps"
3741   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
3742         (unspec:V4SF [(match_operand:V4SF 2 "nonimmediate_operand" "xm,xm")
3743                       (match_operand:V4SF 1 "register_operand" "0,x")
3744                       (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
3745                      UNSPEC_INSERTPS))]
3746   "TARGET_SSE4_1"
3747 {
3748   if (MEM_P (operands[2]))
3749     {
3750       unsigned count_s = INTVAL (operands[3]) >> 6;
3751       if (count_s)
3752         operands[3] = GEN_INT (INTVAL (operands[3]) & 0x3f);
3753       operands[2] = adjust_address_nv (operands[2], SFmode, count_s * 4);
3754     }
3755   switch (which_alternative)
3756     {
3757     case 0:
3758       return "insertps\t{%3, %2, %0|%0, %2, %3}";
3759     case 1:
3760       return "vinsertps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
3761     default:
3762       gcc_unreachable ();
3763     }
3764 }
3765   [(set_attr "isa" "noavx,avx")
3766    (set_attr "type" "sselog")
3767    (set_attr "prefix_data16" "1,*")
3768    (set_attr "prefix_extra" "1")
3769    (set_attr "length_immediate" "1")
3770    (set_attr "prefix" "orig,vex")
3771    (set_attr "mode" "V4SF")])
3772
3773 (define_split
3774   [(set (match_operand:VI4F_128 0 "memory_operand" "")
3775         (vec_merge:VI4F_128
3776           (vec_duplicate:VI4F_128
3777             (match_operand:<ssescalarmode> 1 "nonmemory_operand" ""))
3778           (match_dup 0)
3779           (const_int 1)))]
3780   "TARGET_SSE && reload_completed"
3781   [(const_int 0)]
3782 {
3783   emit_move_insn (adjust_address (operands[0], <ssescalarmode>mode, 0),
3784                   operands[1]);
3785   DONE;
3786 })
3787
3788 (define_expand "vec_set<mode>"
3789   [(match_operand:V 0 "register_operand" "")
3790    (match_operand:<ssescalarmode> 1 "register_operand" "")
3791    (match_operand 2 "const_int_operand" "")]
3792   "TARGET_SSE"
3793 {
3794   ix86_expand_vector_set (false, operands[0], operands[1],
3795                           INTVAL (operands[2]));
3796   DONE;
3797 })
3798
3799 (define_insn_and_split "*vec_extractv4sf_0"
3800   [(set (match_operand:SF 0 "nonimmediate_operand" "=x,m,f,r")
3801         (vec_select:SF
3802           (match_operand:V4SF 1 "nonimmediate_operand" "xm,x,m,m")
3803           (parallel [(const_int 0)])))]
3804   "TARGET_SSE && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
3805   "#"
3806   "&& reload_completed"
3807   [(const_int 0)]
3808 {
3809   rtx op1 = operands[1];
3810   if (REG_P (op1))
3811     op1 = gen_rtx_REG (SFmode, REGNO (op1));
3812   else
3813     op1 = gen_lowpart (SFmode, op1);
3814   emit_move_insn (operands[0], op1);
3815   DONE;
3816 })
3817
3818 (define_expand "avx_vextractf128<mode>"
3819   [(match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "")
3820    (match_operand:V_256 1 "register_operand" "")
3821    (match_operand:SI 2 "const_0_to_1_operand" "")]
3822   "TARGET_AVX"
3823 {
3824   rtx (*insn)(rtx, rtx);
3825
3826   switch (INTVAL (operands[2]))
3827     {
3828     case 0:
3829       insn = gen_vec_extract_lo_<mode>;
3830       break;
3831     case 1:
3832       insn = gen_vec_extract_hi_<mode>;
3833       break;
3834     default:
3835       gcc_unreachable ();
3836     }
3837
3838   emit_insn (insn (operands[0], operands[1]));
3839   DONE;
3840 })
3841
3842 (define_insn_and_split "vec_extract_lo_<mode>"
3843   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "=x,m")
3844         (vec_select:<ssehalfvecmode>
3845           (match_operand:VI8F_256 1 "nonimmediate_operand" "xm,x")
3846           (parallel [(const_int 0) (const_int 1)])))]
3847   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
3848   "#"
3849   "&& reload_completed"
3850   [(const_int 0)]
3851 {
3852   rtx op1 = operands[1];
3853   if (REG_P (op1))
3854     op1 = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (op1));
3855   else
3856     op1 = gen_lowpart (<ssehalfvecmode>mode, op1);
3857   emit_move_insn (operands[0], op1);
3858   DONE;
3859 })
3860
3861 (define_insn "vec_extract_hi_<mode>"
3862   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "=x,m")
3863         (vec_select:<ssehalfvecmode>
3864           (match_operand:VI8F_256 1 "register_operand" "x,x")
3865           (parallel [(const_int 2) (const_int 3)])))]
3866   "TARGET_AVX"
3867   "vextract<i128>\t{$0x1, %1, %0|%0, %1, 0x1}"
3868   [(set_attr "type" "sselog")
3869    (set_attr "prefix_extra" "1")
3870    (set_attr "length_immediate" "1")
3871    (set_attr "memory" "none,store")
3872    (set_attr "prefix" "vex")
3873    (set_attr "mode" "<sseinsnmode>")])
3874
3875 (define_insn_and_split "vec_extract_lo_<mode>"
3876   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "=x,m")
3877         (vec_select:<ssehalfvecmode>
3878           (match_operand:VI4F_256 1 "nonimmediate_operand" "xm,x")
3879           (parallel [(const_int 0) (const_int 1)
3880                      (const_int 2) (const_int 3)])))]
3881   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
3882   "#"
3883   "&& reload_completed"
3884   [(const_int 0)]
3885 {
3886   rtx op1 = operands[1];
3887   if (REG_P (op1))
3888     op1 = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (op1));
3889   else
3890     op1 = gen_lowpart (<ssehalfvecmode>mode, op1);
3891   emit_move_insn (operands[0], op1);
3892   DONE;
3893 })
3894
3895 (define_insn "vec_extract_hi_<mode>"
3896   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "=x,m")
3897         (vec_select:<ssehalfvecmode>
3898           (match_operand:VI4F_256 1 "register_operand" "x,x")
3899           (parallel [(const_int 4) (const_int 5)
3900                      (const_int 6) (const_int 7)])))]
3901   "TARGET_AVX"
3902   "vextract<i128>\t{$0x1, %1, %0|%0, %1, 0x1}"
3903   [(set_attr "type" "sselog")
3904    (set_attr "prefix_extra" "1")
3905    (set_attr "length_immediate" "1")
3906    (set_attr "memory" "none,store")
3907    (set_attr "prefix" "vex")
3908    (set_attr "mode" "<sseinsnmode>")])
3909
3910 (define_insn_and_split "vec_extract_lo_v16hi"
3911   [(set (match_operand:V8HI 0 "nonimmediate_operand" "=x,m")
3912         (vec_select:V8HI
3913           (match_operand:V16HI 1 "nonimmediate_operand" "xm,x")
3914           (parallel [(const_int 0) (const_int 1)
3915                      (const_int 2) (const_int 3)
3916                      (const_int 4) (const_int 5)
3917                      (const_int 6) (const_int 7)])))]
3918   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
3919   "#"
3920   "&& reload_completed"
3921   [(const_int 0)]
3922 {
3923   rtx op1 = operands[1];
3924   if (REG_P (op1))
3925     op1 = gen_rtx_REG (V8HImode, REGNO (op1));
3926   else
3927     op1 = gen_lowpart (V8HImode, op1);
3928   emit_move_insn (operands[0], op1);
3929   DONE;
3930 })
3931
3932 (define_insn "vec_extract_hi_v16hi"
3933   [(set (match_operand:V8HI 0 "nonimmediate_operand" "=x,m")
3934         (vec_select:V8HI
3935           (match_operand:V16HI 1 "register_operand" "x,x")
3936           (parallel [(const_int 8) (const_int 9)
3937                      (const_int 10) (const_int 11)
3938                      (const_int 12) (const_int 13)
3939                      (const_int 14) (const_int 15)])))]
3940   "TARGET_AVX"
3941   "vextract%~128\t{$0x1, %1, %0|%0, %1, 0x1}"
3942   [(set_attr "type" "sselog")
3943    (set_attr "prefix_extra" "1")
3944    (set_attr "length_immediate" "1")
3945    (set_attr "memory" "none,store")
3946    (set_attr "prefix" "vex")
3947    (set_attr "mode" "OI")])
3948
3949 (define_insn_and_split "vec_extract_lo_v32qi"
3950   [(set (match_operand:V16QI 0 "nonimmediate_operand" "=x,m")
3951         (vec_select:V16QI
3952           (match_operand:V32QI 1 "nonimmediate_operand" "xm,x")
3953           (parallel [(const_int 0) (const_int 1)
3954                      (const_int 2) (const_int 3)
3955                      (const_int 4) (const_int 5)
3956                      (const_int 6) (const_int 7)
3957                      (const_int 8) (const_int 9)
3958                      (const_int 10) (const_int 11)
3959                      (const_int 12) (const_int 13)
3960                      (const_int 14) (const_int 15)])))]
3961   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
3962   "#"
3963   "&& reload_completed"
3964   [(const_int 0)]
3965 {
3966   rtx op1 = operands[1];
3967   if (REG_P (op1))
3968     op1 = gen_rtx_REG (V16QImode, REGNO (op1));
3969   else
3970     op1 = gen_lowpart (V16QImode, op1);
3971   emit_move_insn (operands[0], op1);
3972   DONE;
3973 })
3974
3975 (define_insn "vec_extract_hi_v32qi"
3976   [(set (match_operand:V16QI 0 "nonimmediate_operand" "=x,m")
3977         (vec_select:V16QI
3978           (match_operand:V32QI 1 "register_operand" "x,x")
3979           (parallel [(const_int 16) (const_int 17)
3980                      (const_int 18) (const_int 19)
3981                      (const_int 20) (const_int 21)
3982                      (const_int 22) (const_int 23)
3983                      (const_int 24) (const_int 25)
3984                      (const_int 26) (const_int 27)
3985                      (const_int 28) (const_int 29)
3986                      (const_int 30) (const_int 31)])))]
3987   "TARGET_AVX"
3988   "vextract%~128\t{$0x1, %1, %0|%0, %1, 0x1}"
3989   [(set_attr "type" "sselog")
3990    (set_attr "prefix_extra" "1")
3991    (set_attr "length_immediate" "1")
3992    (set_attr "memory" "none,store")
3993    (set_attr "prefix" "vex")
3994    (set_attr "mode" "OI")])
3995
3996 (define_insn_and_split "*sse4_1_extractps"
3997   [(set (match_operand:SF 0 "nonimmediate_operand" "=rm,x,x")
3998         (vec_select:SF
3999           (match_operand:V4SF 1 "register_operand" "x,0,x")
4000           (parallel [(match_operand:SI 2 "const_0_to_3_operand" "n,n,n")])))]
4001   "TARGET_SSE4_1"
4002   "@
4003    %vextractps\t{%2, %1, %0|%0, %1, %2}
4004    #
4005    #"
4006   "&& reload_completed && SSE_REG_P (operands[0])"
4007   [(const_int 0)]
4008 {
4009   rtx dest = gen_rtx_REG (V4SFmode, REGNO (operands[0]));
4010   switch (INTVAL (operands[2]))
4011     {
4012     case 1:
4013     case 3:
4014       emit_insn (gen_sse_shufps_v4sf (dest, operands[1], operands[1],
4015                                       operands[2], operands[2],
4016                                       GEN_INT (INTVAL (operands[2]) + 4),
4017                                       GEN_INT (INTVAL (operands[2]) + 4)));
4018       break;
4019     case 2:
4020       emit_insn (gen_vec_interleave_highv4sf (dest, operands[1], operands[1]));
4021       break;
4022     default:
4023       /* 0 should be handled by the *vec_extractv4sf_0 pattern above.  */
4024       gcc_unreachable ();
4025     }
4026   DONE;
4027 }
4028   [(set_attr "isa" "*,noavx,avx")
4029    (set_attr "type" "sselog,*,*")
4030    (set_attr "prefix_data16" "1,*,*")
4031    (set_attr "prefix_extra" "1,*,*")
4032    (set_attr "length_immediate" "1,*,*")
4033    (set_attr "prefix" "maybe_vex,*,*")
4034    (set_attr "mode" "V4SF,*,*")])
4035
4036 (define_insn_and_split "*vec_extract_v4sf_mem"
4037   [(set (match_operand:SF 0 "register_operand" "=x*rf")
4038        (vec_select:SF
4039          (match_operand:V4SF 1 "memory_operand" "o")
4040          (parallel [(match_operand 2 "const_0_to_3_operand" "n")])))]
4041   "TARGET_SSE"
4042   "#"
4043   "&& reload_completed"
4044   [(const_int 0)]
4045 {
4046   int i = INTVAL (operands[2]);
4047
4048   emit_move_insn (operands[0], adjust_address (operands[1], SFmode, i*4));
4049   DONE;
4050 })
4051
4052 ;; Modes handled by vec_extract patterns.
4053 (define_mode_iterator VEC_EXTRACT_MODE
4054   [(V32QI "TARGET_AVX") V16QI
4055    (V16HI "TARGET_AVX") V8HI
4056    (V8SI "TARGET_AVX") V4SI
4057    (V4DI "TARGET_AVX") V2DI
4058    (V8SF "TARGET_AVX") V4SF
4059    (V4DF "TARGET_AVX") V2DF])
4060
4061 (define_expand "vec_extract<mode>"
4062   [(match_operand:<ssescalarmode> 0 "register_operand" "")
4063    (match_operand:VEC_EXTRACT_MODE 1 "register_operand" "")
4064    (match_operand 2 "const_int_operand" "")]
4065   "TARGET_SSE"
4066 {
4067   ix86_expand_vector_extract (false, operands[0], operands[1],
4068                               INTVAL (operands[2]));
4069   DONE;
4070 })
4071
4072 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4073 ;;
4074 ;; Parallel double-precision floating point element swizzling
4075 ;;
4076 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4077
4078 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
4079 (define_insn "avx_unpckhpd256"
4080   [(set (match_operand:V4DF 0 "register_operand" "=x")
4081         (vec_select:V4DF
4082           (vec_concat:V8DF
4083             (match_operand:V4DF 1 "register_operand" "x")
4084             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
4085           (parallel [(const_int 1) (const_int 5)
4086                      (const_int 3) (const_int 7)])))]
4087   "TARGET_AVX"
4088   "vunpckhpd\t{%2, %1, %0|%0, %1, %2}"
4089   [(set_attr "type" "sselog")
4090    (set_attr "prefix" "vex")
4091    (set_attr "mode" "V4DF")])
4092
4093 (define_expand "vec_interleave_highv4df"
4094   [(set (match_dup 3)
4095         (vec_select:V4DF
4096           (vec_concat:V8DF
4097             (match_operand:V4DF 1 "register_operand" "x")
4098             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
4099           (parallel [(const_int 0) (const_int 4)
4100                      (const_int 2) (const_int 6)])))
4101    (set (match_dup 4)
4102         (vec_select:V4DF
4103           (vec_concat:V8DF
4104             (match_dup 1)
4105             (match_dup 2))
4106           (parallel [(const_int 1) (const_int 5)
4107                      (const_int 3) (const_int 7)])))
4108    (set (match_operand:V4DF 0 "register_operand" "")
4109         (vec_select:V4DF
4110           (vec_concat:V8DF
4111             (match_dup 3)
4112             (match_dup 4))
4113           (parallel [(const_int 2) (const_int 3)
4114                      (const_int 6) (const_int 7)])))]
4115  "TARGET_AVX"
4116 {
4117   operands[3] = gen_reg_rtx (V4DFmode);
4118   operands[4] = gen_reg_rtx (V4DFmode);
4119 })
4120
4121
4122 (define_expand "vec_interleave_highv2df"
4123   [(set (match_operand:V2DF 0 "register_operand" "")
4124         (vec_select:V2DF
4125           (vec_concat:V4DF
4126             (match_operand:V2DF 1 "nonimmediate_operand" "")
4127             (match_operand:V2DF 2 "nonimmediate_operand" ""))
4128           (parallel [(const_int 1)
4129                      (const_int 3)])))]
4130   "TARGET_SSE2"
4131 {
4132   if (!ix86_vec_interleave_v2df_operator_ok (operands, 1))
4133     operands[2] = force_reg (V2DFmode, operands[2]);
4134 })
4135
4136 (define_insn "*vec_interleave_highv2df"
4137   [(set (match_operand:V2DF 0 "nonimmediate_operand"     "=x,x,x,x,x,m")
4138         (vec_select:V2DF
4139           (vec_concat:V4DF
4140             (match_operand:V2DF 1 "nonimmediate_operand" " 0,x,o,o,o,x")
4141             (match_operand:V2DF 2 "nonimmediate_operand" " x,x,1,0,x,0"))
4142           (parallel [(const_int 1)
4143                      (const_int 3)])))]
4144   "TARGET_SSE2 && ix86_vec_interleave_v2df_operator_ok (operands, 1)"
4145   "@
4146    unpckhpd\t{%2, %0|%0, %2}
4147    vunpckhpd\t{%2, %1, %0|%0, %1, %2}
4148    %vmovddup\t{%H1, %0|%0, %H1}
4149    movlpd\t{%H1, %0|%0, %H1}
4150    vmovlpd\t{%H1, %2, %0|%0, %2, %H1}
4151    %vmovhpd\t{%1, %0|%0, %1}"
4152   [(set_attr "isa" "noavx,avx,sse3,noavx,avx,*")
4153   (set_attr "type" "sselog,sselog,sselog,ssemov,ssemov,ssemov")
4154    (set_attr "prefix_data16" "*,*,*,1,*,1")
4155    (set_attr "prefix" "orig,vex,maybe_vex,orig,vex,maybe_vex")
4156    (set_attr "mode" "V2DF,V2DF,V2DF,V1DF,V1DF,V1DF")])
4157
4158 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
4159 (define_expand "avx_movddup256"
4160   [(set (match_operand:V4DF 0 "register_operand" "")
4161         (vec_select:V4DF
4162           (vec_concat:V8DF
4163             (match_operand:V4DF 1 "nonimmediate_operand" "")
4164             (match_dup 1))
4165           (parallel [(const_int 0) (const_int 4)
4166                      (const_int 2) (const_int 6)])))]
4167   "TARGET_AVX")
4168
4169 (define_expand "avx_unpcklpd256"
4170   [(set (match_operand:V4DF 0 "register_operand" "")
4171         (vec_select:V4DF
4172           (vec_concat:V8DF
4173             (match_operand:V4DF 1 "register_operand" "")
4174             (match_operand:V4DF 2 "nonimmediate_operand" ""))
4175           (parallel [(const_int 0) (const_int 4)
4176                      (const_int 2) (const_int 6)])))]
4177   "TARGET_AVX")
4178
4179 (define_insn "*avx_unpcklpd256"
4180   [(set (match_operand:V4DF 0 "register_operand"         "=x,x")
4181         (vec_select:V4DF
4182           (vec_concat:V8DF
4183             (match_operand:V4DF 1 "nonimmediate_operand" "xm,x")
4184             (match_operand:V4DF 2 "nonimmediate_operand" " 1,xm"))
4185           (parallel [(const_int 0) (const_int 4)
4186                      (const_int 2) (const_int 6)])))]
4187   "TARGET_AVX
4188    && (!MEM_P (operands[1]) || rtx_equal_p (operands[1], operands[2]))"
4189   "@
4190    vmovddup\t{%1, %0|%0, %1}
4191    vunpcklpd\t{%2, %1, %0|%0, %1, %2}"
4192   [(set_attr "type" "sselog")
4193    (set_attr "prefix" "vex")
4194    (set_attr "mode" "V4DF")])
4195
4196 (define_expand "vec_interleave_lowv4df"
4197   [(set (match_dup 3)
4198         (vec_select:V4DF
4199           (vec_concat:V8DF
4200             (match_operand:V4DF 1 "register_operand" "x")
4201             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
4202           (parallel [(const_int 0) (const_int 4)
4203                      (const_int 2) (const_int 6)])))
4204    (set (match_dup 4)
4205         (vec_select:V4DF
4206           (vec_concat:V8DF
4207             (match_dup 1)
4208             (match_dup 2))
4209           (parallel [(const_int 1) (const_int 5)
4210                      (const_int 3) (const_int 7)])))
4211    (set (match_operand:V4DF 0 "register_operand" "")
4212         (vec_select:V4DF
4213           (vec_concat:V8DF
4214             (match_dup 3)
4215             (match_dup 4))
4216           (parallel [(const_int 0) (const_int 1)
4217                      (const_int 4) (const_int 5)])))]
4218  "TARGET_AVX"
4219 {
4220   operands[3] = gen_reg_rtx (V4DFmode);
4221   operands[4] = gen_reg_rtx (V4DFmode);
4222 })
4223
4224 (define_expand "vec_interleave_lowv2df"
4225   [(set (match_operand:V2DF 0 "register_operand" "")
4226         (vec_select:V2DF
4227           (vec_concat:V4DF
4228             (match_operand:V2DF 1 "nonimmediate_operand" "")
4229             (match_operand:V2DF 2 "nonimmediate_operand" ""))
4230           (parallel [(const_int 0)
4231                      (const_int 2)])))]
4232   "TARGET_SSE2"
4233 {
4234   if (!ix86_vec_interleave_v2df_operator_ok (operands, 0))
4235     operands[1] = force_reg (V2DFmode, operands[1]);
4236 })
4237
4238 (define_insn "*vec_interleave_lowv2df"
4239   [(set (match_operand:V2DF 0 "nonimmediate_operand"     "=x,x,x,x,x,o")
4240         (vec_select:V2DF
4241           (vec_concat:V4DF
4242             (match_operand:V2DF 1 "nonimmediate_operand" " 0,x,m,0,x,0")
4243             (match_operand:V2DF 2 "nonimmediate_operand" " x,x,1,m,m,x"))
4244           (parallel [(const_int 0)
4245                      (const_int 2)])))]
4246   "TARGET_SSE2 && ix86_vec_interleave_v2df_operator_ok (operands, 0)"
4247   "@
4248    unpcklpd\t{%2, %0|%0, %2}
4249    vunpcklpd\t{%2, %1, %0|%0, %1, %2}
4250    %vmovddup\t{%1, %0|%0, %1}
4251    movhpd\t{%2, %0|%0, %2}
4252    vmovhpd\t{%2, %1, %0|%0, %1, %2}
4253    %vmovlpd\t{%2, %H0|%H0, %2}"
4254   [(set_attr "isa" "noavx,avx,sse3,noavx,avx,*")
4255    (set_attr "type" "sselog,sselog,sselog,ssemov,ssemov,ssemov")
4256    (set_attr "prefix_data16" "*,*,*,1,*,1")
4257    (set_attr "prefix" "orig,vex,maybe_vex,orig,vex,maybe_vex")
4258    (set_attr "mode" "V2DF,V2DF,V2DF,V1DF,V1DF,V1DF")])
4259
4260 (define_split
4261   [(set (match_operand:V2DF 0 "memory_operand" "")
4262         (vec_select:V2DF
4263           (vec_concat:V4DF
4264             (match_operand:V2DF 1 "register_operand" "")
4265             (match_dup 1))
4266           (parallel [(const_int 0)
4267                      (const_int 2)])))]
4268   "TARGET_SSE3 && reload_completed"
4269   [(const_int 0)]
4270 {
4271   rtx low = gen_rtx_REG (DFmode, REGNO (operands[1]));
4272   emit_move_insn (adjust_address (operands[0], DFmode, 0), low);
4273   emit_move_insn (adjust_address (operands[0], DFmode, 8), low);
4274   DONE;
4275 })
4276
4277 (define_split
4278   [(set (match_operand:V2DF 0 "register_operand" "")
4279         (vec_select:V2DF
4280           (vec_concat:V4DF
4281             (match_operand:V2DF 1 "memory_operand" "")
4282             (match_dup 1))
4283           (parallel [(match_operand:SI 2 "const_0_to_1_operand" "")
4284                      (match_operand:SI 3 "const_int_operand" "")])))]
4285   "TARGET_SSE3 && INTVAL (operands[2]) + 2 == INTVAL (operands[3])"
4286   [(set (match_dup 0) (vec_duplicate:V2DF (match_dup 1)))]
4287 {
4288   operands[1] = adjust_address (operands[1], DFmode, INTVAL (operands[2]) * 8);
4289 })
4290
4291 (define_expand "avx_shufpd256"
4292   [(match_operand:V4DF 0 "register_operand" "")
4293    (match_operand:V4DF 1 "register_operand" "")
4294    (match_operand:V4DF 2 "nonimmediate_operand" "")
4295    (match_operand:SI 3 "const_int_operand" "")]
4296   "TARGET_AVX"
4297 {
4298   int mask = INTVAL (operands[3]);
4299   emit_insn (gen_avx_shufpd256_1 (operands[0], operands[1], operands[2],
4300                                    GEN_INT (mask & 1),
4301                                    GEN_INT (mask & 2 ? 5 : 4),
4302                                    GEN_INT (mask & 4 ? 3 : 2),
4303                                    GEN_INT (mask & 8 ? 7 : 6)));
4304   DONE;
4305 })
4306
4307 (define_insn "avx_shufpd256_1"
4308   [(set (match_operand:V4DF 0 "register_operand" "=x")
4309         (vec_select:V4DF
4310           (vec_concat:V8DF
4311             (match_operand:V4DF 1 "register_operand" "x")
4312             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
4313           (parallel [(match_operand 3 "const_0_to_1_operand" "")
4314                      (match_operand 4 "const_4_to_5_operand" "")
4315                      (match_operand 5 "const_2_to_3_operand" "")
4316                      (match_operand 6 "const_6_to_7_operand" "")])))]
4317   "TARGET_AVX"
4318 {
4319   int mask;
4320   mask = INTVAL (operands[3]);
4321   mask |= (INTVAL (operands[4]) - 4) << 1;
4322   mask |= (INTVAL (operands[5]) - 2) << 2;
4323   mask |= (INTVAL (operands[6]) - 6) << 3;
4324   operands[3] = GEN_INT (mask);
4325
4326   return "vshufpd\t{%3, %2, %1, %0|%0, %1, %2, %3}";
4327 }
4328   [(set_attr "type" "sselog")
4329    (set_attr "length_immediate" "1")
4330    (set_attr "prefix" "vex")
4331    (set_attr "mode" "V4DF")])
4332
4333 (define_expand "sse2_shufpd"
4334   [(match_operand:V2DF 0 "register_operand" "")
4335    (match_operand:V2DF 1 "register_operand" "")
4336    (match_operand:V2DF 2 "nonimmediate_operand" "")
4337    (match_operand:SI 3 "const_int_operand" "")]
4338   "TARGET_SSE2"
4339 {
4340   int mask = INTVAL (operands[3]);
4341   emit_insn (gen_sse2_shufpd_v2df (operands[0], operands[1], operands[2],
4342                                 GEN_INT (mask & 1),
4343                                 GEN_INT (mask & 2 ? 3 : 2)));
4344   DONE;
4345 })
4346
4347 ;; Modes handled by vec_extract_even/odd pattern.
4348 (define_mode_iterator VEC_EXTRACT_EVENODD_MODE
4349   [(V32QI "TARGET_AVX2") (V16QI "TARGET_SSE2")
4350    (V16HI "TARGET_AVX2") (V8HI "TARGET_SSE2")
4351    (V8SI "TARGET_AVX2") (V4SI "TARGET_SSE2")
4352    (V4DI "TARGET_AVX2") (V2DI "TARGET_SSE2")
4353    (V8SF "TARGET_AVX") V4SF
4354    (V4DF "TARGET_AVX") (V2DF "TARGET_SSE2")])
4355
4356 (define_expand "vec_extract_even<mode>"
4357   [(match_operand:VEC_EXTRACT_EVENODD_MODE 0 "register_operand" "")
4358    (match_operand:VEC_EXTRACT_EVENODD_MODE 1 "register_operand" "")
4359    (match_operand:VEC_EXTRACT_EVENODD_MODE 2 "register_operand" "")]
4360   "TARGET_SSE"
4361 {
4362   ix86_expand_vec_extract_even_odd (operands[0], operands[1], operands[2], 0);
4363   DONE;
4364 })
4365
4366 (define_expand "vec_extract_odd<mode>"
4367   [(match_operand:VEC_EXTRACT_EVENODD_MODE 0 "register_operand" "")
4368    (match_operand:VEC_EXTRACT_EVENODD_MODE 1 "register_operand" "")
4369    (match_operand:VEC_EXTRACT_EVENODD_MODE 2 "register_operand" "")]
4370   "TARGET_SSE"
4371 {
4372   ix86_expand_vec_extract_even_odd (operands[0], operands[1], operands[2], 1);
4373   DONE;
4374 })
4375
4376 ;; punpcklqdq and punpckhqdq are shorter than shufpd.
4377 (define_insn "avx2_interleave_highv4di"
4378   [(set (match_operand:V4DI 0 "register_operand" "=x")
4379         (vec_select:V4DI
4380           (vec_concat:V8DI
4381             (match_operand:V4DI 1 "register_operand" "x")
4382             (match_operand:V4DI 2 "nonimmediate_operand" "xm"))
4383           (parallel [(const_int 1)
4384                      (const_int 5)
4385                      (const_int 3)
4386                      (const_int 7)])))]
4387   "TARGET_AVX2"
4388   "vpunpckhqdq\t{%2, %1, %0|%0, %1, %2}"
4389   [(set_attr "type" "sselog")
4390    (set_attr "prefix" "vex")
4391    (set_attr "mode" "OI")])
4392
4393 (define_insn "vec_interleave_highv2di"
4394   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
4395         (vec_select:V2DI
4396           (vec_concat:V4DI
4397             (match_operand:V2DI 1 "register_operand" "0,x")
4398             (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm"))
4399           (parallel [(const_int 1)
4400                      (const_int 3)])))]
4401   "TARGET_SSE2"
4402   "@
4403    punpckhqdq\t{%2, %0|%0, %2}
4404    vpunpckhqdq\t{%2, %1, %0|%0, %1, %2}"
4405   [(set_attr "isa" "noavx,avx")
4406    (set_attr "type" "sselog")
4407    (set_attr "prefix_data16" "1,*")
4408    (set_attr "prefix" "orig,vex")
4409    (set_attr "mode" "TI")])
4410
4411 (define_insn "avx2_interleave_lowv4di"
4412   [(set (match_operand:V4DI 0 "register_operand" "=x")
4413         (vec_select:V4DI
4414           (vec_concat:V8DI
4415             (match_operand:V4DI 1 "register_operand" "x")
4416             (match_operand:V4DI 2 "nonimmediate_operand" "xm"))
4417           (parallel [(const_int 0)
4418                      (const_int 4)
4419                      (const_int 2)
4420                      (const_int 6)])))]
4421   "TARGET_AVX2"
4422   "vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}"
4423   [(set_attr "type" "sselog")
4424    (set_attr "prefix" "vex")
4425    (set_attr "mode" "OI")])
4426
4427 (define_insn "vec_interleave_lowv2di"
4428   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
4429         (vec_select:V2DI
4430           (vec_concat:V4DI
4431             (match_operand:V2DI 1 "register_operand" "0,x")
4432             (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm"))
4433           (parallel [(const_int 0)
4434                      (const_int 2)])))]
4435   "TARGET_SSE2"
4436   "@
4437    punpcklqdq\t{%2, %0|%0, %2}
4438    vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}"
4439   [(set_attr "isa" "noavx,avx")
4440    (set_attr "type" "sselog")
4441    (set_attr "prefix_data16" "1,*")
4442    (set_attr "prefix" "orig,vex")
4443    (set_attr "mode" "TI")])
4444
4445 (define_insn "sse2_shufpd_<mode>"
4446   [(set (match_operand:VI8F_128 0 "register_operand" "=x,x")
4447         (vec_select:VI8F_128
4448           (vec_concat:<ssedoublevecmode>
4449             (match_operand:VI8F_128 1 "register_operand" "0,x")
4450             (match_operand:VI8F_128 2 "nonimmediate_operand" "xm,xm"))
4451           (parallel [(match_operand 3 "const_0_to_1_operand" "")
4452                      (match_operand 4 "const_2_to_3_operand" "")])))]
4453   "TARGET_SSE2"
4454 {
4455   int mask;
4456   mask = INTVAL (operands[3]);
4457   mask |= (INTVAL (operands[4]) - 2) << 1;
4458   operands[3] = GEN_INT (mask);
4459
4460   switch (which_alternative)
4461     {
4462     case 0:
4463       return "shufpd\t{%3, %2, %0|%0, %2, %3}";
4464     case 1:
4465       return "vshufpd\t{%3, %2, %1, %0|%0, %1, %2, %3}";
4466     default:
4467       gcc_unreachable ();
4468     }
4469 }
4470   [(set_attr "isa" "noavx,avx")
4471    (set_attr "type" "sselog")
4472    (set_attr "length_immediate" "1")
4473    (set_attr "prefix" "orig,vex")
4474    (set_attr "mode" "V2DF")])
4475
4476 ;; Avoid combining registers from different units in a single alternative,
4477 ;; see comment above inline_secondary_memory_needed function in i386.c
4478 (define_insn "sse2_storehpd"
4479   [(set (match_operand:DF 0 "nonimmediate_operand"     "=m,x,x,x,*f,r")
4480         (vec_select:DF
4481           (match_operand:V2DF 1 "nonimmediate_operand" " x,0,x,o,o,o")
4482           (parallel [(const_int 1)])))]
4483   "TARGET_SSE2 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4484   "@
4485    %vmovhpd\t{%1, %0|%0, %1}
4486    unpckhpd\t%0, %0
4487    vunpckhpd\t{%d1, %0|%0, %d1}
4488    #
4489    #
4490    #"
4491   [(set_attr "isa" "*,noavx,avx,*,*,*")
4492    (set_attr "type" "ssemov,sselog1,sselog1,ssemov,fmov,imov")
4493    (set (attr "prefix_data16")
4494      (if_then_else
4495        (and (eq_attr "alternative" "0")
4496             (not (match_test "TARGET_AVX")))
4497        (const_string "1")
4498        (const_string "*")))
4499    (set_attr "prefix" "maybe_vex,orig,vex,*,*,*")
4500    (set_attr "mode" "V1DF,V1DF,V2DF,DF,DF,DF")])
4501
4502 (define_split
4503   [(set (match_operand:DF 0 "register_operand" "")
4504         (vec_select:DF
4505           (match_operand:V2DF 1 "memory_operand" "")
4506           (parallel [(const_int 1)])))]
4507   "TARGET_SSE2 && reload_completed"
4508   [(set (match_dup 0) (match_dup 1))]
4509   "operands[1] = adjust_address (operands[1], DFmode, 8);")
4510
4511 (define_insn "*vec_extractv2df_1_sse"
4512   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,x,x")
4513         (vec_select:DF
4514           (match_operand:V2DF 1 "nonimmediate_operand" "x,x,o")
4515           (parallel [(const_int 1)])))]
4516   "!TARGET_SSE2 && TARGET_SSE
4517    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4518   "@
4519    movhps\t{%1, %0|%0, %1}
4520    movhlps\t{%1, %0|%0, %1}
4521    movlps\t{%H1, %0|%0, %H1}"
4522   [(set_attr "type" "ssemov")
4523    (set_attr "mode" "V2SF,V4SF,V2SF")])
4524
4525 ;; Avoid combining registers from different units in a single alternative,
4526 ;; see comment above inline_secondary_memory_needed function in i386.c
4527 (define_insn "sse2_storelpd"
4528   [(set (match_operand:DF 0 "nonimmediate_operand"     "=m,x,x,*f,r")
4529         (vec_select:DF
4530           (match_operand:V2DF 1 "nonimmediate_operand" " x,x,m,m,m")
4531           (parallel [(const_int 0)])))]
4532   "TARGET_SSE2 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4533   "@
4534    %vmovlpd\t{%1, %0|%0, %1}
4535    #
4536    #
4537    #
4538    #"
4539   [(set_attr "type" "ssemov,ssemov,ssemov,fmov,imov")
4540    (set_attr "prefix_data16" "1,*,*,*,*")
4541    (set_attr "prefix" "maybe_vex")
4542    (set_attr "mode" "V1DF,DF,DF,DF,DF")])
4543
4544 (define_split
4545   [(set (match_operand:DF 0 "register_operand" "")
4546         (vec_select:DF
4547           (match_operand:V2DF 1 "nonimmediate_operand" "")
4548           (parallel [(const_int 0)])))]
4549   "TARGET_SSE2 && reload_completed"
4550   [(const_int 0)]
4551 {
4552   rtx op1 = operands[1];
4553   if (REG_P (op1))
4554     op1 = gen_rtx_REG (DFmode, REGNO (op1));
4555   else
4556     op1 = gen_lowpart (DFmode, op1);
4557   emit_move_insn (operands[0], op1);
4558   DONE;
4559 })
4560
4561 (define_insn "*vec_extractv2df_0_sse"
4562   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,x,x")
4563         (vec_select:DF
4564           (match_operand:V2DF 1 "nonimmediate_operand" "x,x,m")
4565           (parallel [(const_int 0)])))]
4566   "!TARGET_SSE2 && TARGET_SSE
4567    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4568   "@
4569    movlps\t{%1, %0|%0, %1}
4570    movaps\t{%1, %0|%0, %1}
4571    movlps\t{%1, %0|%0, %1}"
4572   [(set_attr "type" "ssemov")
4573    (set_attr "mode" "V2SF,V4SF,V2SF")])
4574
4575 (define_expand "sse2_loadhpd_exp"
4576   [(set (match_operand:V2DF 0 "nonimmediate_operand" "")
4577         (vec_concat:V2DF
4578           (vec_select:DF
4579             (match_operand:V2DF 1 "nonimmediate_operand" "")
4580             (parallel [(const_int 0)]))
4581           (match_operand:DF 2 "nonimmediate_operand" "")))]
4582   "TARGET_SSE2"
4583 {
4584   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V2DFmode, operands);
4585
4586   emit_insn (gen_sse2_loadhpd (dst, operands[1], operands[2]));
4587
4588   /* Fix up the destination if needed.  */
4589   if (dst != operands[0])
4590     emit_move_insn (operands[0], dst);
4591
4592   DONE;
4593 })
4594
4595 ;; Avoid combining registers from different units in a single alternative,
4596 ;; see comment above inline_secondary_memory_needed function in i386.c
4597 (define_insn "sse2_loadhpd"
4598   [(set (match_operand:V2DF 0 "nonimmediate_operand"
4599           "=x,x,x,x,o,o ,o")
4600         (vec_concat:V2DF
4601           (vec_select:DF
4602             (match_operand:V2DF 1 "nonimmediate_operand"
4603           " 0,x,0,x,0,0 ,0")
4604             (parallel [(const_int 0)]))
4605           (match_operand:DF 2 "nonimmediate_operand"
4606           " m,m,x,x,x,*f,r")))]
4607   "TARGET_SSE2 && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
4608   "@
4609    movhpd\t{%2, %0|%0, %2}
4610    vmovhpd\t{%2, %1, %0|%0, %1, %2}
4611    unpcklpd\t{%2, %0|%0, %2}
4612    vunpcklpd\t{%2, %1, %0|%0, %1, %2}
4613    #
4614    #
4615    #"
4616   [(set_attr "isa" "noavx,avx,noavx,avx,*,*,*")
4617    (set_attr "type" "ssemov,ssemov,sselog,sselog,ssemov,fmov,imov")
4618    (set_attr "prefix_data16" "1,*,*,*,*,*,*")
4619    (set_attr "prefix" "orig,vex,orig,vex,*,*,*")
4620    (set_attr "mode" "V1DF,V1DF,V2DF,V2DF,DF,DF,DF")])
4621
4622 (define_split
4623   [(set (match_operand:V2DF 0 "memory_operand" "")
4624         (vec_concat:V2DF
4625           (vec_select:DF (match_dup 0) (parallel [(const_int 0)]))
4626           (match_operand:DF 1 "register_operand" "")))]
4627   "TARGET_SSE2 && reload_completed"
4628   [(set (match_dup 0) (match_dup 1))]
4629   "operands[0] = adjust_address (operands[0], DFmode, 8);")
4630
4631 (define_expand "sse2_loadlpd_exp"
4632   [(set (match_operand:V2DF 0 "nonimmediate_operand" "")
4633         (vec_concat:V2DF
4634           (match_operand:DF 2 "nonimmediate_operand" "")
4635           (vec_select:DF
4636             (match_operand:V2DF 1 "nonimmediate_operand" "")
4637             (parallel [(const_int 1)]))))]
4638   "TARGET_SSE2"
4639 {
4640   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V2DFmode, operands);
4641
4642   emit_insn (gen_sse2_loadlpd (dst, operands[1], operands[2]));
4643
4644   /* Fix up the destination if needed.  */
4645   if (dst != operands[0])
4646     emit_move_insn (operands[0], dst);
4647
4648   DONE;
4649 })
4650
4651 ;; Avoid combining registers from different units in a single alternative,
4652 ;; see comment above inline_secondary_memory_needed function in i386.c
4653 (define_insn "sse2_loadlpd"
4654   [(set (match_operand:V2DF 0 "nonimmediate_operand"
4655           "=x,x,x,x,x,x,x,x,m,m ,m")
4656         (vec_concat:V2DF
4657           (match_operand:DF 2 "nonimmediate_operand"
4658           " m,m,m,x,x,0,0,x,x,*f,r")
4659           (vec_select:DF
4660             (match_operand:V2DF 1 "vector_move_operand"
4661           " C,0,x,0,x,x,o,o,0,0 ,0")
4662             (parallel [(const_int 1)]))))]
4663   "TARGET_SSE2 && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
4664   "@
4665    %vmovsd\t{%2, %0|%0, %2}
4666    movlpd\t{%2, %0|%0, %2}
4667    vmovlpd\t{%2, %1, %0|%0, %1, %2}
4668    movsd\t{%2, %0|%0, %2}
4669    vmovsd\t{%2, %1, %0|%0, %1, %2}
4670    shufpd\t{$2, %1, %0|%0, %1, 2}
4671    movhpd\t{%H1, %0|%0, %H1}
4672    vmovhpd\t{%H1, %2, %0|%0, %2, %H1}
4673    #
4674    #
4675    #"
4676   [(set_attr "isa" "*,noavx,avx,noavx,avx,noavx,noavx,avx,*,*,*")
4677    (set (attr "type")
4678      (cond [(eq_attr "alternative" "5")
4679               (const_string "sselog")
4680             (eq_attr "alternative" "9")
4681               (const_string "fmov")
4682             (eq_attr "alternative" "10")
4683               (const_string "imov")
4684            ]
4685            (const_string "ssemov")))
4686    (set_attr "prefix_data16" "*,1,*,*,*,*,1,*,*,*,*")
4687    (set_attr "length_immediate" "*,*,*,*,*,1,*,*,*,*,*")
4688    (set_attr "prefix" "maybe_vex,orig,vex,orig,vex,orig,orig,vex,*,*,*")
4689    (set_attr "mode" "DF,V1DF,V1DF,V1DF,V1DF,V2DF,V1DF,V1DF,DF,DF,DF")])
4690
4691 (define_split
4692   [(set (match_operand:V2DF 0 "memory_operand" "")
4693         (vec_concat:V2DF
4694           (match_operand:DF 1 "register_operand" "")
4695           (vec_select:DF (match_dup 0) (parallel [(const_int 1)]))))]
4696   "TARGET_SSE2 && reload_completed"
4697   [(set (match_dup 0) (match_dup 1))]
4698   "operands[0] = adjust_address (operands[0], DFmode, 8);")
4699
4700 (define_insn "sse2_movsd"
4701   [(set (match_operand:V2DF 0 "nonimmediate_operand"   "=x,x,x,x,m,x,x,x,o")
4702         (vec_merge:V2DF
4703           (match_operand:V2DF 2 "nonimmediate_operand" " x,x,m,m,x,0,0,x,0")
4704           (match_operand:V2DF 1 "nonimmediate_operand" " 0,x,0,x,0,x,o,o,x")
4705           (const_int 1)))]
4706   "TARGET_SSE2"
4707   "@
4708    movsd\t{%2, %0|%0, %2}
4709    vmovsd\t{%2, %1, %0|%0, %1, %2}
4710    movlpd\t{%2, %0|%0, %2}
4711    vmovlpd\t{%2, %1, %0|%0, %1, %2}
4712    %vmovlpd\t{%2, %0|%0, %2}
4713    shufpd\t{$2, %1, %0|%0, %1, 2}
4714    movhps\t{%H1, %0|%0, %H1}
4715    vmovhps\t{%H1, %2, %0|%0, %2, %H1}
4716    %vmovhps\t{%1, %H0|%H0, %1}"
4717   [(set_attr "isa" "noavx,avx,noavx,avx,*,noavx,noavx,avx,*")
4718    (set (attr "type")
4719      (if_then_else
4720        (eq_attr "alternative" "5")
4721        (const_string "sselog")
4722        (const_string "ssemov")))
4723    (set (attr "prefix_data16")
4724      (if_then_else
4725        (and (eq_attr "alternative" "2,4")
4726             (not (match_test "TARGET_AVX")))
4727        (const_string "1")
4728        (const_string "*")))
4729    (set_attr "length_immediate" "*,*,*,*,*,1,*,*,*")
4730    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex,orig,orig,vex,maybe_vex")
4731    (set_attr "mode" "DF,DF,V1DF,V1DF,V1DF,V2DF,V1DF,V1DF,V1DF")])
4732
4733 (define_expand "vec_dupv2df"
4734   [(set (match_operand:V2DF 0 "register_operand" "")
4735         (vec_duplicate:V2DF
4736           (match_operand:DF 1 "nonimmediate_operand" "")))]
4737   "TARGET_SSE2"
4738 {
4739   if (!TARGET_SSE3)
4740     operands[1] = force_reg (DFmode, operands[1]);
4741 })
4742
4743 (define_insn "*vec_dupv2df_sse3"
4744   [(set (match_operand:V2DF 0 "register_operand" "=x")
4745         (vec_duplicate:V2DF
4746           (match_operand:DF 1 "nonimmediate_operand" "xm")))]
4747   "TARGET_SSE3"
4748   "%vmovddup\t{%1, %0|%0, %1}"
4749   [(set_attr "type" "sselog1")
4750    (set_attr "prefix" "maybe_vex")
4751    (set_attr "mode" "DF")])
4752
4753 (define_insn "*vec_dupv2df"
4754   [(set (match_operand:V2DF 0 "register_operand" "=x")
4755         (vec_duplicate:V2DF
4756           (match_operand:DF 1 "register_operand" "0")))]
4757   "TARGET_SSE2"
4758   "unpcklpd\t%0, %0"
4759   [(set_attr "type" "sselog1")
4760    (set_attr "mode" "V2DF")])
4761
4762 (define_insn "*vec_concatv2df_sse3"
4763   [(set (match_operand:V2DF 0 "register_operand" "=x")
4764         (vec_concat:V2DF
4765           (match_operand:DF 1 "nonimmediate_operand" "xm")
4766           (match_dup 1)))]
4767   "TARGET_SSE3"
4768   "%vmovddup\t{%1, %0|%0, %1}"
4769   [(set_attr "type" "sselog1")
4770    (set_attr "prefix" "maybe_vex")
4771    (set_attr "mode" "DF")])
4772
4773 (define_insn "*vec_concatv2df"
4774   [(set (match_operand:V2DF 0 "register_operand"     "=x,x,x,x,x,x,x")
4775         (vec_concat:V2DF
4776           (match_operand:DF 1 "nonimmediate_operand" " 0,x,0,x,m,0,0")
4777           (match_operand:DF 2 "vector_move_operand"  " x,x,m,m,C,x,m")))]
4778   "TARGET_SSE"
4779   "@
4780    unpcklpd\t{%2, %0|%0, %2}
4781    vunpcklpd\t{%2, %1, %0|%0, %1, %2}
4782    movhpd\t{%2, %0|%0, %2}
4783    vmovhpd\t{%2, %1, %0|%0, %1, %2}
4784    %vmovsd\t{%1, %0|%0, %1}
4785    movlhps\t{%2, %0|%0, %2}
4786    movhps\t{%2, %0|%0, %2}"
4787   [(set_attr "isa" "sse2_noavx,avx,sse2_noavx,avx,sse2,noavx,noavx")
4788    (set (attr "type")
4789      (if_then_else
4790        (eq_attr "alternative" "0,1")
4791        (const_string "sselog")
4792        (const_string "ssemov")))
4793    (set_attr "prefix_data16" "*,*,1,*,*,*,*")
4794    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex,orig,orig")
4795    (set_attr "mode" "V2DF,V2DF,V1DF,V1DF,DF,V4SF,V2SF")])
4796
4797 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4798 ;;
4799 ;; Parallel integral arithmetic
4800 ;;
4801 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4802
4803 (define_expand "neg<mode>2"
4804   [(set (match_operand:VI_128 0 "register_operand" "")
4805         (minus:VI_128
4806           (match_dup 2)
4807           (match_operand:VI_128 1 "nonimmediate_operand" "")))]
4808   "TARGET_SSE2"
4809   "operands[2] = force_reg (<MODE>mode, CONST0_RTX (<MODE>mode));")
4810
4811 (define_expand "<plusminus_insn><mode>3"
4812   [(set (match_operand:VI_AVX2 0 "register_operand" "")
4813         (plusminus:VI_AVX2
4814           (match_operand:VI_AVX2 1 "nonimmediate_operand" "")
4815           (match_operand:VI_AVX2 2 "nonimmediate_operand" "")))]
4816   "TARGET_SSE2"
4817   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
4818
4819 (define_insn "*<plusminus_insn><mode>3"
4820   [(set (match_operand:VI_AVX2 0 "register_operand" "=x,x")
4821         (plusminus:VI_AVX2
4822           (match_operand:VI_AVX2 1 "nonimmediate_operand" "<comm>0,x")
4823           (match_operand:VI_AVX2 2 "nonimmediate_operand" "xm,xm")))]
4824   "TARGET_SSE2 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
4825   "@
4826    p<plusminus_mnemonic><ssemodesuffix>\t{%2, %0|%0, %2}
4827    vp<plusminus_mnemonic><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
4828   [(set_attr "isa" "noavx,avx")
4829    (set_attr "type" "sseiadd")
4830    (set_attr "prefix_data16" "1,*")
4831    (set_attr "prefix" "orig,vex")
4832    (set_attr "mode" "<sseinsnmode>")])
4833
4834 (define_expand "<sse2_avx2>_<plusminus_insn><mode>3"
4835   [(set (match_operand:VI12_AVX2 0 "register_operand" "")
4836         (sat_plusminus:VI12_AVX2
4837           (match_operand:VI12_AVX2 1 "nonimmediate_operand" "")
4838           (match_operand:VI12_AVX2 2 "nonimmediate_operand" "")))]
4839   "TARGET_SSE2"
4840   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
4841
4842 (define_insn "*<sse2_avx2>_<plusminus_insn><mode>3"
4843   [(set (match_operand:VI12_AVX2 0 "register_operand" "=x,x")
4844         (sat_plusminus:VI12_AVX2
4845           (match_operand:VI12_AVX2 1 "nonimmediate_operand" "<comm>0,x")
4846           (match_operand:VI12_AVX2 2 "nonimmediate_operand" "xm,xm")))]
4847   "TARGET_SSE2 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
4848   "@
4849    p<plusminus_mnemonic><ssemodesuffix>\t{%2, %0|%0, %2}
4850    vp<plusminus_mnemonic><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
4851   [(set_attr "isa" "noavx,avx")
4852    (set_attr "type" "sseiadd")
4853    (set_attr "prefix_data16" "1,*")
4854    (set_attr "prefix" "orig,vex")
4855    (set_attr "mode" "TI")])
4856
4857 (define_insn_and_split "mul<mode>3"
4858   [(set (match_operand:VI1_AVX2 0 "register_operand" "")
4859         (mult:VI1_AVX2 (match_operand:VI1_AVX2 1 "register_operand" "")
4860                        (match_operand:VI1_AVX2 2 "register_operand" "")))]
4861   "TARGET_SSE2
4862    && can_create_pseudo_p ()"
4863   "#"
4864   "&& 1"
4865   [(const_int 0)]
4866 {
4867   rtx t[6];
4868   int i;
4869   enum machine_mode mulmode = <sseunpackmode>mode;
4870
4871   for (i = 0; i < 6; ++i)
4872     t[i] = gen_reg_rtx (<MODE>mode);
4873
4874   /* Unpack data such that we've got a source byte in each low byte of
4875      each word.  We don't care what goes into the high byte of each word.
4876      Rather than trying to get zero in there, most convenient is to let
4877      it be a copy of the low byte.  */
4878   emit_insn (gen_<vec_avx2>_interleave_high<mode> (t[0], operands[1],
4879                                                    operands[1]));
4880   emit_insn (gen_<vec_avx2>_interleave_high<mode> (t[1], operands[2],
4881                                                    operands[2]));
4882   emit_insn (gen_<vec_avx2>_interleave_low<mode> (t[2], operands[1],
4883                                                   operands[1]));
4884   emit_insn (gen_<vec_avx2>_interleave_low<mode> (t[3], operands[2],
4885                                                   operands[2]));
4886
4887   /* Multiply words.  The end-of-line annotations here give a picture of what
4888      the output of that instruction looks like.  Dot means don't care; the
4889      letters are the bytes of the result with A being the most significant.  */
4890   emit_insn (gen_rtx_SET (VOIDmode, gen_lowpart (mulmode, t[4]),
4891                           gen_rtx_MULT (mulmode,        /* .A.B.C.D.E.F.G.H */
4892                                         gen_lowpart (mulmode, t[0]),
4893                                         gen_lowpart (mulmode, t[1]))));
4894   emit_insn (gen_rtx_SET (VOIDmode, gen_lowpart (mulmode, t[5]),
4895                           gen_rtx_MULT (mulmode,        /* .I.J.K.L.M.N.O.P */
4896                                         gen_lowpart (mulmode, t[2]),
4897                                         gen_lowpart (mulmode, t[3]))));
4898
4899   /* Extract the even bytes and merge them back together.  */
4900   ix86_expand_vec_extract_even_odd (operands[0], t[5], t[4], 0);
4901
4902   set_unique_reg_note (get_last_insn (), REG_EQUAL,
4903                        gen_rtx_MULT (<MODE>mode, operands[1], operands[2]));
4904   DONE;
4905 })
4906
4907 (define_expand "mul<mode>3"
4908   [(set (match_operand:VI2_AVX2 0 "register_operand" "")
4909         (mult:VI2_AVX2 (match_operand:VI2_AVX2 1 "nonimmediate_operand" "")
4910                        (match_operand:VI2_AVX2 2 "nonimmediate_operand" "")))]
4911   "TARGET_SSE2"
4912   "ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);")
4913
4914 (define_insn "*mul<mode>3"
4915   [(set (match_operand:VI2_AVX2 0 "register_operand" "=x,x")
4916         (mult:VI2_AVX2 (match_operand:VI2_AVX2 1 "nonimmediate_operand" "%0,x")
4917                        (match_operand:VI2_AVX2 2 "nonimmediate_operand" "xm,xm")))]
4918   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, <MODE>mode, operands)"
4919   "@
4920    pmullw\t{%2, %0|%0, %2}
4921    vpmullw\t{%2, %1, %0|%0, %1, %2}"
4922   [(set_attr "isa" "noavx,avx")
4923    (set_attr "type" "sseimul")
4924    (set_attr "prefix_data16" "1,*")
4925    (set_attr "prefix" "orig,vex")
4926    (set_attr "mode" "<sseinsnmode>")])
4927
4928 (define_expand "<s>mul<mode>3_highpart"
4929   [(set (match_operand:VI2_AVX2 0 "register_operand" "")
4930         (truncate:VI2_AVX2
4931           (lshiftrt:<ssedoublemode>
4932             (mult:<ssedoublemode>
4933               (any_extend:<ssedoublemode>
4934                 (match_operand:VI2_AVX2 1 "nonimmediate_operand" ""))
4935               (any_extend:<ssedoublemode>
4936                 (match_operand:VI2_AVX2 2 "nonimmediate_operand" "")))
4937             (const_int 16))))]
4938   "TARGET_SSE2"
4939   "ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);")
4940
4941 (define_insn "*<s>mul<mode>3_highpart"
4942   [(set (match_operand:VI2_AVX2 0 "register_operand" "=x,x")
4943         (truncate:VI2_AVX2
4944           (lshiftrt:<ssedoublemode>
4945             (mult:<ssedoublemode>
4946               (any_extend:<ssedoublemode>
4947                 (match_operand:VI2_AVX2 1 "nonimmediate_operand" "%0,x"))
4948               (any_extend:<ssedoublemode>
4949                 (match_operand:VI2_AVX2 2 "nonimmediate_operand" "xm,xm")))
4950             (const_int 16))))]
4951   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, <MODE>mode, operands)"
4952   "@
4953    pmulh<u>w\t{%2, %0|%0, %2}
4954    vpmulh<u>w\t{%2, %1, %0|%0, %1, %2}"
4955   [(set_attr "isa" "noavx,avx")
4956    (set_attr "type" "sseimul")
4957    (set_attr "prefix_data16" "1,*")
4958    (set_attr "prefix" "orig,vex")
4959    (set_attr "mode" "<sseinsnmode>")])
4960
4961 (define_expand "avx2_umulv4siv4di3"
4962   [(set (match_operand:V4DI 0 "register_operand" "")
4963         (mult:V4DI
4964           (zero_extend:V4DI
4965             (vec_select:V4SI
4966               (match_operand:V8SI 1 "nonimmediate_operand" "")
4967               (parallel [(const_int 0) (const_int 2)
4968                          (const_int 4) (const_int 6)])))
4969           (zero_extend:V4DI
4970             (vec_select:V4SI
4971               (match_operand:V8SI 2 "nonimmediate_operand" "")
4972               (parallel [(const_int 0) (const_int 2)
4973                          (const_int 4) (const_int 6)])))))]
4974   "TARGET_AVX2"
4975   "ix86_fixup_binary_operands_no_copy (MULT, V8SImode, operands);")
4976
4977 (define_insn "*avx_umulv4siv4di3"
4978   [(set (match_operand:V4DI 0 "register_operand" "=x")
4979         (mult:V4DI
4980           (zero_extend:V4DI
4981             (vec_select:V4SI
4982               (match_operand:V8SI 1 "nonimmediate_operand" "%x")
4983               (parallel [(const_int 0) (const_int 2)
4984                          (const_int 4) (const_int 6)])))
4985           (zero_extend:V4DI
4986             (vec_select:V4SI
4987               (match_operand:V8SI 2 "nonimmediate_operand" "xm")
4988               (parallel [(const_int 0) (const_int 2)
4989                          (const_int 4) (const_int 6)])))))]
4990   "TARGET_AVX2 && ix86_binary_operator_ok (MULT, V8SImode, operands)"
4991   "vpmuludq\t{%2, %1, %0|%0, %1, %2}"
4992   [(set_attr "type" "sseimul")
4993    (set_attr "prefix" "vex")
4994    (set_attr "mode" "OI")])
4995
4996 (define_expand "sse2_umulv2siv2di3"
4997   [(set (match_operand:V2DI 0 "register_operand" "")
4998         (mult:V2DI
4999           (zero_extend:V2DI
5000             (vec_select:V2SI
5001               (match_operand:V4SI 1 "nonimmediate_operand" "")
5002               (parallel [(const_int 0) (const_int 2)])))
5003           (zero_extend:V2DI
5004             (vec_select:V2SI
5005               (match_operand:V4SI 2 "nonimmediate_operand" "")
5006               (parallel [(const_int 0) (const_int 2)])))))]
5007   "TARGET_SSE2"
5008   "ix86_fixup_binary_operands_no_copy (MULT, V4SImode, operands);")
5009
5010 (define_insn "*sse2_umulv2siv2di3"
5011   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
5012         (mult:V2DI
5013           (zero_extend:V2DI
5014             (vec_select:V2SI
5015               (match_operand:V4SI 1 "nonimmediate_operand" "%0,x")
5016               (parallel [(const_int 0) (const_int 2)])))
5017           (zero_extend:V2DI
5018             (vec_select:V2SI
5019               (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm")
5020               (parallel [(const_int 0) (const_int 2)])))))]
5021   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, V4SImode, operands)"
5022   "@
5023    pmuludq\t{%2, %0|%0, %2}
5024    vpmuludq\t{%2, %1, %0|%0, %1, %2}"
5025   [(set_attr "isa" "noavx,avx")
5026    (set_attr "type" "sseimul")
5027    (set_attr "prefix_data16" "1,*")
5028    (set_attr "prefix" "orig,vex")
5029    (set_attr "mode" "TI")])
5030
5031 (define_expand "avx2_mulv4siv4di3"
5032   [(set (match_operand:V4DI 0 "register_operand" "")
5033         (mult:V4DI
5034           (sign_extend:V4DI
5035             (vec_select:V4SI
5036               (match_operand:V8SI 1 "nonimmediate_operand" "")
5037               (parallel [(const_int 0) (const_int 2)
5038                          (const_int 4) (const_int 6)])))
5039           (sign_extend:V4DI
5040             (vec_select:V4SI
5041               (match_operand:V8SI 2 "nonimmediate_operand" "")
5042               (parallel [(const_int 0) (const_int 2)
5043                          (const_int 4) (const_int 6)])))))]
5044   "TARGET_AVX2"
5045   "ix86_fixup_binary_operands_no_copy (MULT, V8SImode, operands);")
5046
5047 (define_insn "*avx2_mulv4siv4di3"
5048   [(set (match_operand:V4DI 0 "register_operand" "=x")
5049         (mult:V4DI
5050           (sign_extend:V4DI
5051             (vec_select:V4SI
5052               (match_operand:V8SI 1 "nonimmediate_operand" "x")
5053               (parallel [(const_int 0) (const_int 2)
5054                          (const_int 4) (const_int 6)])))
5055           (sign_extend:V4DI
5056             (vec_select:V4SI
5057               (match_operand:V8SI 2 "nonimmediate_operand" "xm")
5058               (parallel [(const_int 0) (const_int 2)
5059                          (const_int 4) (const_int 6)])))))]
5060   "TARGET_AVX2 && ix86_binary_operator_ok (MULT, V8SImode, operands)"
5061   "vpmuldq\t{%2, %1, %0|%0, %1, %2}"
5062   [(set_attr "isa" "avx")
5063    (set_attr "type" "sseimul")
5064    (set_attr "prefix_extra" "1")
5065    (set_attr "prefix" "vex")
5066    (set_attr "mode" "OI")])
5067
5068 (define_expand "sse4_1_mulv2siv2di3"
5069   [(set (match_operand:V2DI 0 "register_operand" "")
5070         (mult:V2DI
5071           (sign_extend:V2DI
5072             (vec_select:V2SI
5073               (match_operand:V4SI 1 "nonimmediate_operand" "")
5074               (parallel [(const_int 0) (const_int 2)])))
5075           (sign_extend:V2DI
5076             (vec_select:V2SI
5077               (match_operand:V4SI 2 "nonimmediate_operand" "")
5078               (parallel [(const_int 0) (const_int 2)])))))]
5079   "TARGET_SSE4_1"
5080   "ix86_fixup_binary_operands_no_copy (MULT, V4SImode, operands);")
5081
5082 (define_insn "*sse4_1_mulv2siv2di3"
5083   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
5084         (mult:V2DI
5085           (sign_extend:V2DI
5086             (vec_select:V2SI
5087               (match_operand:V4SI 1 "nonimmediate_operand" "%0,x")
5088               (parallel [(const_int 0) (const_int 2)])))
5089           (sign_extend:V2DI
5090             (vec_select:V2SI
5091               (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm")
5092               (parallel [(const_int 0) (const_int 2)])))))]
5093   "TARGET_SSE4_1 && ix86_binary_operator_ok (MULT, V4SImode, operands)"
5094   "@
5095    pmuldq\t{%2, %0|%0, %2}
5096    vpmuldq\t{%2, %1, %0|%0, %1, %2}"
5097   [(set_attr "isa" "noavx,avx")
5098    (set_attr "type" "sseimul")
5099    (set_attr "prefix_data16" "1,*")
5100    (set_attr "prefix_extra" "1")
5101    (set_attr "prefix" "orig,vex")
5102    (set_attr "mode" "TI")])
5103
5104 (define_expand "avx2_pmaddwd"
5105   [(set (match_operand:V8SI 0 "register_operand" "")
5106         (plus:V8SI
5107           (mult:V8SI
5108             (sign_extend:V8SI
5109               (vec_select:V8HI
5110                 (match_operand:V16HI 1 "nonimmediate_operand" "")
5111                 (parallel [(const_int 0)
5112                            (const_int 2)
5113                            (const_int 4)
5114                            (const_int 6)
5115                            (const_int 8)
5116                            (const_int 10)
5117                            (const_int 12)
5118                            (const_int 14)])))
5119             (sign_extend:V8SI
5120               (vec_select:V8HI
5121                 (match_operand:V16HI 2 "nonimmediate_operand" "")
5122                 (parallel [(const_int 0)
5123                            (const_int 2)
5124                            (const_int 4)
5125                            (const_int 6)
5126                            (const_int 8)
5127                            (const_int 10)
5128                            (const_int 12)
5129                            (const_int 14)]))))
5130           (mult:V8SI
5131             (sign_extend:V8SI
5132               (vec_select:V8HI (match_dup 1)
5133                 (parallel [(const_int 1)
5134                            (const_int 3)
5135                            (const_int 5)
5136                            (const_int 7)
5137                            (const_int 9)
5138                            (const_int 11)
5139                            (const_int 13)
5140                            (const_int 15)])))
5141             (sign_extend:V8SI
5142               (vec_select:V8HI (match_dup 2)
5143                 (parallel [(const_int 1)
5144                            (const_int 3)
5145                            (const_int 5)
5146                            (const_int 7)
5147                            (const_int 9)
5148                            (const_int 11)
5149                            (const_int 13)
5150                            (const_int 15)]))))))]
5151   "TARGET_AVX2"
5152   "ix86_fixup_binary_operands_no_copy (MULT, V16HImode, operands);")
5153
5154 (define_expand "sse2_pmaddwd"
5155   [(set (match_operand:V4SI 0 "register_operand" "")
5156         (plus:V4SI
5157           (mult:V4SI
5158             (sign_extend:V4SI
5159               (vec_select:V4HI
5160                 (match_operand:V8HI 1 "nonimmediate_operand" "")
5161                 (parallel [(const_int 0)
5162                            (const_int 2)
5163                            (const_int 4)
5164                            (const_int 6)])))
5165             (sign_extend:V4SI
5166               (vec_select:V4HI
5167                 (match_operand:V8HI 2 "nonimmediate_operand" "")
5168                 (parallel [(const_int 0)
5169                            (const_int 2)
5170                            (const_int 4)
5171                            (const_int 6)]))))
5172           (mult:V4SI
5173             (sign_extend:V4SI
5174               (vec_select:V4HI (match_dup 1)
5175                 (parallel [(const_int 1)
5176                            (const_int 3)
5177                            (const_int 5)
5178                            (const_int 7)])))
5179             (sign_extend:V4SI
5180               (vec_select:V4HI (match_dup 2)
5181                 (parallel [(const_int 1)
5182                            (const_int 3)
5183                            (const_int 5)
5184                            (const_int 7)]))))))]
5185   "TARGET_SSE2"
5186   "ix86_fixup_binary_operands_no_copy (MULT, V8HImode, operands);")
5187
5188 (define_insn "*avx2_pmaddwd"
5189   [(set (match_operand:V8SI 0 "register_operand" "=x")
5190         (plus:V8SI
5191           (mult:V8SI
5192             (sign_extend:V8SI
5193               (vec_select:V8HI
5194                 (match_operand:V16HI 1 "nonimmediate_operand" "%x")
5195                 (parallel [(const_int 0)
5196                            (const_int 2)
5197                            (const_int 4)
5198                            (const_int 6)
5199                            (const_int 8)
5200                            (const_int 10)
5201                            (const_int 12)
5202                            (const_int 14)])))
5203             (sign_extend:V8SI
5204               (vec_select:V8HI
5205                 (match_operand:V16HI 2 "nonimmediate_operand" "xm")
5206                 (parallel [(const_int 0)
5207                            (const_int 2)
5208                            (const_int 4)
5209                            (const_int 6)
5210                            (const_int 8)
5211                            (const_int 10)
5212                            (const_int 12)
5213                            (const_int 14)]))))
5214           (mult:V8SI
5215             (sign_extend:V8SI
5216               (vec_select:V8HI (match_dup 1)
5217                 (parallel [(const_int 1)
5218                            (const_int 3)
5219                            (const_int 5)
5220                            (const_int 7)
5221                            (const_int 9)
5222                            (const_int 11)
5223                            (const_int 13)
5224                            (const_int 15)])))
5225             (sign_extend:V8SI
5226               (vec_select:V8HI (match_dup 2)
5227                 (parallel [(const_int 1)
5228                            (const_int 3)
5229                            (const_int 5)
5230                            (const_int 7)
5231                            (const_int 9)
5232                            (const_int 11)
5233                            (const_int 13)
5234                            (const_int 15)]))))))]
5235   "TARGET_AVX2 && ix86_binary_operator_ok (MULT, V16HImode, operands)"
5236   "vpmaddwd\t{%2, %1, %0|%0, %1, %2}"
5237   [(set_attr "type" "sseiadd")
5238    (set_attr "prefix" "vex")
5239    (set_attr "mode" "OI")])
5240
5241 (define_insn "*sse2_pmaddwd"
5242   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
5243         (plus:V4SI
5244           (mult:V4SI
5245             (sign_extend:V4SI
5246               (vec_select:V4HI
5247                 (match_operand:V8HI 1 "nonimmediate_operand" "%0,x")
5248                 (parallel [(const_int 0)
5249                            (const_int 2)
5250                            (const_int 4)
5251                            (const_int 6)])))
5252             (sign_extend:V4SI
5253               (vec_select:V4HI
5254                 (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
5255                 (parallel [(const_int 0)
5256                            (const_int 2)
5257                            (const_int 4)
5258                            (const_int 6)]))))
5259           (mult:V4SI
5260             (sign_extend:V4SI
5261               (vec_select:V4HI (match_dup 1)
5262                 (parallel [(const_int 1)
5263                            (const_int 3)
5264                            (const_int 5)
5265                            (const_int 7)])))
5266             (sign_extend:V4SI
5267               (vec_select:V4HI (match_dup 2)
5268                 (parallel [(const_int 1)
5269                            (const_int 3)
5270                            (const_int 5)
5271                            (const_int 7)]))))))]
5272   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, V8HImode, operands)"
5273   "@
5274    pmaddwd\t{%2, %0|%0, %2}
5275    vpmaddwd\t{%2, %1, %0|%0, %1, %2}"
5276   [(set_attr "isa" "noavx,avx")
5277    (set_attr "type" "sseiadd")
5278    (set_attr "atom_unit" "simul")
5279    (set_attr "prefix_data16" "1,*")
5280    (set_attr "prefix" "orig,vex")
5281    (set_attr "mode" "TI")])
5282
5283 (define_expand "mul<mode>3"
5284   [(set (match_operand:VI4_AVX2 0 "register_operand" "")
5285         (mult:VI4_AVX2 (match_operand:VI4_AVX2 1 "register_operand" "")
5286                        (match_operand:VI4_AVX2 2 "register_operand" "")))]
5287   "TARGET_SSE2"
5288 {
5289   if (TARGET_SSE4_1 || TARGET_AVX)
5290     ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);
5291 })
5292
5293 (define_insn "*<sse4_1_avx2>_mul<mode>3"
5294   [(set (match_operand:VI4_AVX2 0 "register_operand" "=x,x")
5295         (mult:VI4_AVX2 (match_operand:VI4_AVX2 1 "nonimmediate_operand" "%0,x")
5296                        (match_operand:VI4_AVX2 2 "nonimmediate_operand" "xm,xm")))]
5297   "TARGET_SSE4_1 && ix86_binary_operator_ok (MULT, <MODE>mode, operands)"
5298   "@
5299    pmulld\t{%2, %0|%0, %2}
5300    vpmulld\t{%2, %1, %0|%0, %1, %2}"
5301   [(set_attr "isa" "noavx,avx")
5302    (set_attr "type" "sseimul")
5303    (set_attr "prefix_extra" "1")
5304    (set_attr "prefix" "orig,vex")
5305    (set_attr "mode" "<sseinsnmode>")])
5306
5307 (define_insn_and_split "*sse2_mulv4si3"
5308   [(set (match_operand:V4SI 0 "register_operand" "")
5309         (mult:V4SI (match_operand:V4SI 1 "register_operand" "")
5310                    (match_operand:V4SI 2 "register_operand" "")))]
5311   "TARGET_SSE2 && !TARGET_SSE4_1 && !TARGET_AVX
5312    && can_create_pseudo_p ()"
5313   "#"
5314   "&& 1"
5315   [(const_int 0)]
5316 {
5317   rtx t1, t2, t3, t4, t5, t6, thirtytwo;
5318   rtx op0, op1, op2;
5319
5320   op0 = operands[0];
5321   op1 = operands[1];
5322   op2 = operands[2];
5323   t1 = gen_reg_rtx (V4SImode);
5324   t2 = gen_reg_rtx (V4SImode);
5325   t3 = gen_reg_rtx (V4SImode);
5326   t4 = gen_reg_rtx (V4SImode);
5327   t5 = gen_reg_rtx (V4SImode);
5328   t6 = gen_reg_rtx (V4SImode);
5329   thirtytwo = GEN_INT (32);
5330
5331   /* Multiply elements 2 and 0.  */
5332   emit_insn (gen_sse2_umulv2siv2di3 (gen_lowpart (V2DImode, t1),
5333                                      op1, op2));
5334
5335   /* Shift both input vectors down one element, so that elements 3
5336      and 1 are now in the slots for elements 2 and 0.  For K8, at
5337      least, this is faster than using a shuffle.  */
5338   emit_insn (gen_sse2_lshrv1ti3 (gen_lowpart (V1TImode, t2),
5339                                  gen_lowpart (V1TImode, op1),
5340                                  thirtytwo));
5341   emit_insn (gen_sse2_lshrv1ti3 (gen_lowpart (V1TImode, t3),
5342                                  gen_lowpart (V1TImode, op2),
5343                                  thirtytwo));
5344   /* Multiply elements 3 and 1.  */
5345   emit_insn (gen_sse2_umulv2siv2di3 (gen_lowpart (V2DImode, t4),
5346                                      t2, t3));
5347
5348   /* Move the results in element 2 down to element 1; we don't care
5349      what goes in elements 2 and 3.  */
5350   emit_insn (gen_sse2_pshufd_1 (t5, t1, const0_rtx, const2_rtx,
5351                                 const0_rtx, const0_rtx));
5352   emit_insn (gen_sse2_pshufd_1 (t6, t4, const0_rtx, const2_rtx,
5353                                 const0_rtx, const0_rtx));
5354
5355   /* Merge the parts back together.  */
5356   emit_insn (gen_vec_interleave_lowv4si (op0, t5, t6));
5357
5358   set_unique_reg_note (get_last_insn (), REG_EQUAL,
5359                        gen_rtx_MULT (V4SImode, operands[1], operands[2]));
5360   DONE;
5361 })
5362
5363 (define_insn_and_split "mulv2di3"
5364   [(set (match_operand:V2DI 0 "register_operand" "")
5365         (mult:V2DI (match_operand:V2DI 1 "register_operand" "")
5366                    (match_operand:V2DI 2 "register_operand" "")))]
5367   "TARGET_SSE2
5368    && can_create_pseudo_p ()"
5369   "#"
5370   "&& 1"
5371   [(const_int 0)]
5372 {
5373   rtx t1, t2, t3, t4, t5, t6, thirtytwo;
5374   rtx op0, op1, op2;
5375
5376   op0 = operands[0];
5377   op1 = operands[1];
5378   op2 = operands[2];
5379
5380   if (TARGET_XOP)
5381     {
5382       /* op1: A,B,C,D, op2: E,F,G,H */
5383       op1 = gen_lowpart (V4SImode, op1);
5384       op2 = gen_lowpart (V4SImode, op2);
5385
5386       t1 = gen_reg_rtx (V4SImode);
5387       t2 = gen_reg_rtx (V4SImode);
5388       t3 = gen_reg_rtx (V2DImode);
5389       t4 = gen_reg_rtx (V2DImode);
5390
5391       /* t1: B,A,D,C */
5392       emit_insn (gen_sse2_pshufd_1 (t1, op1,
5393                                     GEN_INT (1),
5394                                     GEN_INT (0),
5395                                     GEN_INT (3),
5396                                     GEN_INT (2)));
5397
5398       /* t2: (B*E),(A*F),(D*G),(C*H) */
5399       emit_insn (gen_mulv4si3 (t2, t1, op2));
5400
5401       /* t4: (B*E)+(A*F), (D*G)+(C*H) */
5402       emit_insn (gen_xop_phadddq (t3, t2));
5403
5404       /* t5: ((B*E)+(A*F))<<32, ((D*G)+(C*H))<<32 */
5405       emit_insn (gen_ashlv2di3 (t4, t3, GEN_INT (32)));
5406
5407       /* op0: (((B*E)+(A*F))<<32)+(B*F), (((D*G)+(C*H))<<32)+(D*H) */
5408       emit_insn (gen_xop_pmacsdql (op0, op1, op2, t4));
5409     }
5410   else
5411     {
5412       t1 = gen_reg_rtx (V2DImode);
5413       t2 = gen_reg_rtx (V2DImode);
5414       t3 = gen_reg_rtx (V2DImode);
5415       t4 = gen_reg_rtx (V2DImode);
5416       t5 = gen_reg_rtx (V2DImode);
5417       t6 = gen_reg_rtx (V2DImode);
5418       thirtytwo = GEN_INT (32);
5419
5420       /* Multiply low parts.  */
5421       emit_insn (gen_sse2_umulv2siv2di3 (t1, gen_lowpart (V4SImode, op1),
5422                                          gen_lowpart (V4SImode, op2)));
5423
5424       /* Shift input vectors left 32 bits so we can multiply high parts.  */
5425       emit_insn (gen_lshrv2di3 (t2, op1, thirtytwo));
5426       emit_insn (gen_lshrv2di3 (t3, op2, thirtytwo));
5427
5428       /* Multiply high parts by low parts.  */
5429       emit_insn (gen_sse2_umulv2siv2di3 (t4, gen_lowpart (V4SImode, op1),
5430                                          gen_lowpart (V4SImode, t3)));
5431       emit_insn (gen_sse2_umulv2siv2di3 (t5, gen_lowpart (V4SImode, op2),
5432                                          gen_lowpart (V4SImode, t2)));
5433
5434       /* Shift them back.  */
5435       emit_insn (gen_ashlv2di3 (t4, t4, thirtytwo));
5436       emit_insn (gen_ashlv2di3 (t5, t5, thirtytwo));
5437
5438       /* Add the three parts together.  */
5439       emit_insn (gen_addv2di3 (t6, t1, t4));
5440       emit_insn (gen_addv2di3 (op0, t6, t5));
5441     }
5442
5443   set_unique_reg_note (get_last_insn (), REG_EQUAL,
5444                        gen_rtx_MULT (V2DImode, operands[1], operands[2]));
5445   DONE;
5446 })
5447
5448 (define_expand "vec_widen_smult_hi_v8hi"
5449   [(match_operand:V4SI 0 "register_operand" "")
5450    (match_operand:V8HI 1 "register_operand" "")
5451    (match_operand:V8HI 2 "register_operand" "")]
5452   "TARGET_SSE2"
5453 {
5454   rtx op1, op2, t1, t2, dest;
5455
5456   op1 = operands[1];
5457   op2 = operands[2];
5458   t1 = gen_reg_rtx (V8HImode);
5459   t2 = gen_reg_rtx (V8HImode);
5460   dest = gen_lowpart (V8HImode, operands[0]);
5461
5462   emit_insn (gen_mulv8hi3 (t1, op1, op2));
5463   emit_insn (gen_smulv8hi3_highpart (t2, op1, op2));
5464   emit_insn (gen_vec_interleave_highv8hi (dest, t1, t2));
5465   DONE;
5466 })
5467
5468 (define_expand "vec_widen_smult_lo_v8hi"
5469   [(match_operand:V4SI 0 "register_operand" "")
5470    (match_operand:V8HI 1 "register_operand" "")
5471    (match_operand:V8HI 2 "register_operand" "")]
5472   "TARGET_SSE2"
5473 {
5474   rtx op1, op2, t1, t2, dest;
5475
5476   op1 = operands[1];
5477   op2 = operands[2];
5478   t1 = gen_reg_rtx (V8HImode);
5479   t2 = gen_reg_rtx (V8HImode);
5480   dest = gen_lowpart (V8HImode, operands[0]);
5481
5482   emit_insn (gen_mulv8hi3 (t1, op1, op2));
5483   emit_insn (gen_smulv8hi3_highpart (t2, op1, op2));
5484   emit_insn (gen_vec_interleave_lowv8hi (dest, t1, t2));
5485   DONE;
5486 })
5487
5488 (define_expand "vec_widen_umult_hi_v8hi"
5489   [(match_operand:V4SI 0 "register_operand" "")
5490    (match_operand:V8HI 1 "register_operand" "")
5491    (match_operand:V8HI 2 "register_operand" "")]
5492   "TARGET_SSE2"
5493 {
5494   rtx op1, op2, t1, t2, dest;
5495
5496   op1 = operands[1];
5497   op2 = operands[2];
5498   t1 = gen_reg_rtx (V8HImode);
5499   t2 = gen_reg_rtx (V8HImode);
5500   dest = gen_lowpart (V8HImode, operands[0]);
5501
5502   emit_insn (gen_mulv8hi3 (t1, op1, op2));
5503   emit_insn (gen_umulv8hi3_highpart (t2, op1, op2));
5504   emit_insn (gen_vec_interleave_highv8hi (dest, t1, t2));
5505   DONE;
5506 })
5507
5508 (define_expand "vec_widen_umult_lo_v8hi"
5509   [(match_operand:V4SI 0 "register_operand" "")
5510    (match_operand:V8HI 1 "register_operand" "")
5511    (match_operand:V8HI 2 "register_operand" "")]
5512   "TARGET_SSE2"
5513 {
5514   rtx op1, op2, t1, t2, dest;
5515
5516   op1 = operands[1];
5517   op2 = operands[2];
5518   t1 = gen_reg_rtx (V8HImode);
5519   t2 = gen_reg_rtx (V8HImode);
5520   dest = gen_lowpart (V8HImode, operands[0]);
5521
5522   emit_insn (gen_mulv8hi3 (t1, op1, op2));
5523   emit_insn (gen_umulv8hi3_highpart (t2, op1, op2));
5524   emit_insn (gen_vec_interleave_lowv8hi (dest, t1, t2));
5525   DONE;
5526 })
5527
5528 (define_expand "vec_widen_smult_hi_v4si"
5529   [(match_operand:V2DI 0 "register_operand" "")
5530    (match_operand:V4SI 1 "register_operand" "")
5531    (match_operand:V4SI 2 "register_operand" "")]
5532   "TARGET_XOP"
5533 {
5534   rtx t1, t2;
5535
5536   t1 = gen_reg_rtx (V4SImode);
5537   t2 = gen_reg_rtx (V4SImode);
5538
5539   emit_insn (gen_sse2_pshufd_1 (t1, operands[1],
5540                                 GEN_INT (0),
5541                                 GEN_INT (2),
5542                                 GEN_INT (1),
5543                                 GEN_INT (3)));
5544   emit_insn (gen_sse2_pshufd_1 (t2, operands[2],
5545                                 GEN_INT (0),
5546                                 GEN_INT (2),
5547                                 GEN_INT (1),
5548                                 GEN_INT (3)));
5549   emit_insn (gen_xop_mulv2div2di3_high (operands[0], t1, t2));
5550   DONE;
5551 })
5552
5553 (define_expand "vec_widen_smult_lo_v4si"
5554   [(match_operand:V2DI 0 "register_operand" "")
5555    (match_operand:V4SI 1 "register_operand" "")
5556    (match_operand:V4SI 2 "register_operand" "")]
5557   "TARGET_XOP"
5558 {
5559   rtx t1, t2;
5560
5561   t1 = gen_reg_rtx (V4SImode);
5562   t2 = gen_reg_rtx (V4SImode);
5563
5564   emit_insn (gen_sse2_pshufd_1 (t1, operands[1],
5565                                 GEN_INT (0),
5566                                 GEN_INT (2),
5567                                 GEN_INT (1),
5568                                 GEN_INT (3)));
5569   emit_insn (gen_sse2_pshufd_1 (t2, operands[2],
5570                                 GEN_INT (0),
5571                                 GEN_INT (2),
5572                                 GEN_INT (1),
5573                                 GEN_INT (3)));
5574   emit_insn (gen_xop_mulv2div2di3_low (operands[0], t1, t2));
5575   DONE;
5576 })
5577
5578 (define_expand "vec_widen_umult_hi_v4si"
5579   [(match_operand:V2DI 0 "register_operand" "")
5580    (match_operand:V4SI 1 "register_operand" "")
5581    (match_operand:V4SI 2 "register_operand" "")]
5582   "TARGET_SSE2"
5583 {
5584   rtx op1, op2, t1, t2;
5585
5586   op1 = operands[1];
5587   op2 = operands[2];
5588   t1 = gen_reg_rtx (V4SImode);
5589   t2 = gen_reg_rtx (V4SImode);
5590
5591   emit_insn (gen_vec_interleave_highv4si (t1, op1, op1));
5592   emit_insn (gen_vec_interleave_highv4si (t2, op2, op2));
5593   emit_insn (gen_sse2_umulv2siv2di3 (operands[0], t1, t2));
5594   DONE;
5595 })
5596
5597 (define_expand "vec_widen_umult_lo_v4si"
5598   [(match_operand:V2DI 0 "register_operand" "")
5599    (match_operand:V4SI 1 "register_operand" "")
5600    (match_operand:V4SI 2 "register_operand" "")]
5601   "TARGET_SSE2"
5602 {
5603   rtx op1, op2, t1, t2;
5604
5605   op1 = operands[1];
5606   op2 = operands[2];
5607   t1 = gen_reg_rtx (V4SImode);
5608   t2 = gen_reg_rtx (V4SImode);
5609
5610   emit_insn (gen_vec_interleave_lowv4si (t1, op1, op1));
5611   emit_insn (gen_vec_interleave_lowv4si (t2, op2, op2));
5612   emit_insn (gen_sse2_umulv2siv2di3 (operands[0], t1, t2));
5613   DONE;
5614 })
5615
5616 (define_expand "sdot_prodv8hi"
5617   [(match_operand:V4SI 0 "register_operand" "")
5618    (match_operand:V8HI 1 "register_operand" "")
5619    (match_operand:V8HI 2 "register_operand" "")
5620    (match_operand:V4SI 3 "register_operand" "")]
5621   "TARGET_SSE2"
5622 {
5623   rtx t = gen_reg_rtx (V4SImode);
5624   emit_insn (gen_sse2_pmaddwd (t, operands[1], operands[2]));
5625   emit_insn (gen_addv4si3 (operands[0], operands[3], t));
5626   DONE;
5627 })
5628
5629 (define_expand "udot_prodv4si"
5630   [(match_operand:V2DI 0 "register_operand" "")
5631    (match_operand:V4SI 1 "register_operand" "")
5632    (match_operand:V4SI 2 "register_operand" "")
5633    (match_operand:V2DI 3 "register_operand" "")]
5634   "TARGET_SSE2"
5635 {
5636   rtx t1, t2, t3, t4;
5637
5638   t1 = gen_reg_rtx (V2DImode);
5639   emit_insn (gen_sse2_umulv2siv2di3 (t1, operands[1], operands[2]));
5640   emit_insn (gen_addv2di3 (t1, t1, operands[3]));
5641
5642   t2 = gen_reg_rtx (V4SImode);
5643   t3 = gen_reg_rtx (V4SImode);
5644   emit_insn (gen_sse2_lshrv1ti3 (gen_lowpart (V1TImode, t2),
5645                                  gen_lowpart (V1TImode, operands[1]),
5646                                  GEN_INT (32)));
5647   emit_insn (gen_sse2_lshrv1ti3 (gen_lowpart (V1TImode, t3),
5648                                  gen_lowpart (V1TImode, operands[2]),
5649                                  GEN_INT (32)));
5650
5651   t4 = gen_reg_rtx (V2DImode);
5652   emit_insn (gen_sse2_umulv2siv2di3 (t4, t2, t3));
5653
5654   emit_insn (gen_addv2di3 (operands[0], t1, t4));
5655   DONE;
5656 })
5657
5658 (define_insn "ashr<mode>3"
5659   [(set (match_operand:VI24_AVX2 0 "register_operand" "=x,x")
5660         (ashiftrt:VI24_AVX2
5661           (match_operand:VI24_AVX2 1 "register_operand" "0,x")
5662           (match_operand:SI 2 "nonmemory_operand" "xN,xN")))]
5663   "TARGET_SSE2"
5664   "@
5665    psra<ssemodesuffix>\t{%2, %0|%0, %2}
5666    vpsra<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5667   [(set_attr "isa" "noavx,avx")
5668    (set_attr "type" "sseishft")
5669    (set (attr "length_immediate")
5670      (if_then_else (match_operand 2 "const_int_operand" "")
5671        (const_string "1")
5672        (const_string "0")))
5673    (set_attr "prefix_data16" "1,*")
5674    (set_attr "prefix" "orig,vex")
5675    (set_attr "mode" "<sseinsnmode>")])
5676
5677 (define_insn "lshr<mode>3"
5678   [(set (match_operand:VI248_AVX2 0 "register_operand" "=x,x")
5679         (lshiftrt:VI248_AVX2
5680           (match_operand:VI248_AVX2 1 "register_operand" "0,x")
5681           (match_operand:SI 2 "nonmemory_operand" "xN,xN")))]
5682   "TARGET_SSE2"
5683   "@
5684    psrl<ssemodesuffix>\t{%2, %0|%0, %2}
5685    vpsrl<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5686   [(set_attr "isa" "noavx,avx")
5687    (set_attr "type" "sseishft")
5688    (set (attr "length_immediate")
5689      (if_then_else (match_operand 2 "const_int_operand" "")
5690        (const_string "1")
5691        (const_string "0")))
5692    (set_attr "prefix_data16" "1,*")
5693    (set_attr "prefix" "orig,vex")
5694    (set_attr "mode" "<sseinsnmode>")])
5695
5696 (define_insn "avx2_lshl<mode>3"
5697   [(set (match_operand:VI248_256 0 "register_operand" "=x")
5698         (ashift:VI248_256
5699           (match_operand:VI248_256 1 "register_operand" "x")
5700           (match_operand:SI 2 "nonmemory_operand" "xN")))]
5701   "TARGET_AVX2"
5702   "vpsll<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5703   [(set_attr "type" "sseishft")
5704    (set_attr "prefix" "vex")
5705    (set (attr "length_immediate")
5706      (if_then_else (match_operand 2 "const_int_operand" "")
5707        (const_string "1")
5708        (const_string "0")))
5709    (set_attr "mode" "OI")])
5710
5711 (define_insn "ashl<mode>3"
5712   [(set (match_operand:VI248_128 0 "register_operand" "=x,x")
5713         (ashift:VI248_128
5714           (match_operand:VI248_128 1 "register_operand" "0,x")
5715           (match_operand:SI 2 "nonmemory_operand" "xN,xN")))]
5716   "TARGET_SSE2"
5717   "@
5718    psll<ssemodesuffix>\t{%2, %0|%0, %2}
5719    vpsll<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5720   [(set_attr "isa" "noavx,avx")
5721    (set_attr "type" "sseishft")
5722    (set (attr "length_immediate")
5723      (if_then_else (match_operand 2 "const_int_operand" "")
5724        (const_string "1")
5725        (const_string "0")))
5726    (set_attr "prefix_data16" "1,*")
5727    (set_attr "prefix" "orig,vex")
5728    (set_attr "mode" "TI")])
5729
5730 (define_expand "vec_shl_<mode>"
5731   [(set (match_operand:VI_128 0 "register_operand" "")
5732         (ashift:V1TI
5733          (match_operand:VI_128 1 "register_operand" "")
5734          (match_operand:SI 2 "const_0_to_255_mul_8_operand" "")))]
5735   "TARGET_SSE2"
5736 {
5737   operands[0] = gen_lowpart (V1TImode, operands[0]);
5738   operands[1] = gen_lowpart (V1TImode, operands[1]);
5739 })
5740
5741 (define_insn "<sse2_avx2>_ashl<mode>3"
5742   [(set (match_operand:VIMAX_AVX2 0 "register_operand" "=x,x")
5743         (ashift:VIMAX_AVX2
5744          (match_operand:VIMAX_AVX2 1 "register_operand" "0,x")
5745          (match_operand:SI 2 "const_0_to_255_mul_8_operand" "n,n")))]
5746   "TARGET_SSE2"
5747 {
5748   operands[2] = GEN_INT (INTVAL (operands[2]) / 8);
5749
5750   switch (which_alternative)
5751     {
5752     case 0:
5753       return "pslldq\t{%2, %0|%0, %2}";
5754     case 1:
5755       return "vpslldq\t{%2, %1, %0|%0, %1, %2}";
5756     default:
5757       gcc_unreachable ();
5758     }
5759 }
5760   [(set_attr "isa" "noavx,avx")
5761    (set_attr "type" "sseishft")
5762    (set_attr "length_immediate" "1")
5763    (set_attr "prefix_data16" "1,*")
5764    (set_attr "prefix" "orig,vex")
5765    (set_attr "mode" "<sseinsnmode>")])
5766
5767 (define_expand "vec_shr_<mode>"
5768   [(set (match_operand:VI_128 0 "register_operand" "")
5769         (lshiftrt:V1TI
5770          (match_operand:VI_128 1 "register_operand" "")
5771          (match_operand:SI 2 "const_0_to_255_mul_8_operand" "")))]
5772   "TARGET_SSE2"
5773 {
5774   operands[0] = gen_lowpart (V1TImode, operands[0]);
5775   operands[1] = gen_lowpart (V1TImode, operands[1]);
5776 })
5777
5778 (define_insn "<sse2_avx2>_lshr<mode>3"
5779   [(set (match_operand:VIMAX_AVX2 0 "register_operand" "=x,x")
5780         (lshiftrt:VIMAX_AVX2
5781          (match_operand:VIMAX_AVX2 1 "register_operand" "0,x")
5782          (match_operand:SI 2 "const_0_to_255_mul_8_operand" "n,n")))]
5783   "TARGET_SSE2"
5784 {
5785   operands[2] = GEN_INT (INTVAL (operands[2]) / 8);
5786
5787   switch (which_alternative)
5788     {
5789     case 0:
5790       return "psrldq\t{%2, %0|%0, %2}";
5791     case 1:
5792       return "vpsrldq\t{%2, %1, %0|%0, %1, %2}";
5793     default:
5794       gcc_unreachable ();
5795     }
5796 }
5797   [(set_attr "isa" "noavx,avx")
5798    (set_attr "type" "sseishft")
5799    (set_attr "length_immediate" "1")
5800    (set_attr "atom_unit" "sishuf")
5801    (set_attr "prefix_data16" "1,*")
5802    (set_attr "prefix" "orig,vex")
5803    (set_attr "mode" "<sseinsnmode>")])
5804
5805
5806 (define_expand "<code><mode>3"
5807   [(set (match_operand:VI124_256 0 "register_operand" "")
5808         (maxmin:VI124_256
5809           (match_operand:VI124_256 1 "nonimmediate_operand" "")
5810           (match_operand:VI124_256 2 "nonimmediate_operand" "")))]
5811   "TARGET_AVX2"
5812   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
5813
5814 (define_insn "*avx2_<code><mode>3"
5815   [(set (match_operand:VI124_256 0 "register_operand" "=x")
5816         (maxmin:VI124_256
5817           (match_operand:VI124_256 1 "nonimmediate_operand" "%x")
5818           (match_operand:VI124_256 2 "nonimmediate_operand" "xm")))]
5819   "TARGET_AVX2 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
5820   "vp<maxmin_int><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5821   [(set_attr "type" "sseiadd")
5822    (set_attr "prefix_extra" "1")
5823    (set_attr "prefix" "vex")
5824    (set_attr "mode" "OI")])
5825
5826 (define_expand "<code><mode>3"
5827   [(set (match_operand:VI8_AVX2 0 "register_operand" "")
5828         (maxmin:VI8_AVX2 (match_operand:VI8_AVX2 1 "register_operand" "")
5829                          (match_operand:VI8_AVX2 2 "register_operand" "")))]
5830   "TARGET_SSE4_2"
5831 {
5832   enum rtx_code code;
5833   rtx xops[6];
5834   bool ok;
5835
5836   xops[0] = operands[0];
5837
5838   if (<CODE> == SMAX || <CODE> == UMAX)
5839     {
5840       xops[1] = operands[1];
5841       xops[2] = operands[2];
5842     }
5843   else
5844     {
5845       xops[1] = operands[2];
5846       xops[2] = operands[1];
5847     }
5848
5849   code = (<CODE> == UMAX || <CODE> == UMIN) ? GTU : GT;
5850
5851   xops[3] = gen_rtx_fmt_ee (code, VOIDmode, operands[1], operands[2]);
5852   xops[4] = operands[1];
5853   xops[5] = operands[2];
5854
5855   ok = ix86_expand_int_vcond (xops);
5856   gcc_assert (ok);
5857   DONE;
5858 })
5859
5860 (define_expand "<code><mode>3"
5861   [(set (match_operand:VI124_128 0 "register_operand" "")
5862         (smaxmin:VI124_128 (match_operand:VI124_128 1 "nonimmediate_operand" "")
5863                            (match_operand:VI124_128 2 "nonimmediate_operand" "")))]
5864   "TARGET_SSE2"
5865 {
5866   if (TARGET_SSE4_1 || <MODE>mode == V8HImode)
5867     ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);
5868   else
5869     {
5870       rtx xops[6];
5871       bool ok;
5872
5873       xops[0] = operands[0];
5874       operands[1] = force_reg (<MODE>mode, operands[1]);
5875       operands[2] = force_reg (<MODE>mode, operands[2]);
5876
5877       if (<CODE> == SMAX)
5878         {
5879           xops[1] = operands[1];
5880           xops[2] = operands[2];
5881         }
5882       else
5883         {
5884           xops[1] = operands[2];
5885           xops[2] = operands[1];
5886         }
5887
5888       xops[3] = gen_rtx_GT (VOIDmode, operands[1], operands[2]);
5889       xops[4] = operands[1];
5890       xops[5] = operands[2];
5891
5892       ok = ix86_expand_int_vcond (xops);
5893       gcc_assert (ok);
5894       DONE;
5895     }
5896 })
5897
5898 (define_insn "*sse4_1_<code><mode>3"
5899   [(set (match_operand:VI14_128 0 "register_operand" "=x,x")
5900         (smaxmin:VI14_128
5901           (match_operand:VI14_128 1 "nonimmediate_operand" "%0,x")
5902           (match_operand:VI14_128 2 "nonimmediate_operand" "xm,xm")))]
5903   "TARGET_SSE4_1 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
5904   "@
5905    p<maxmin_int><ssemodesuffix>\t{%2, %0|%0, %2}
5906    vp<maxmin_int><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5907   [(set_attr "isa" "noavx,avx")
5908    (set_attr "type" "sseiadd")
5909    (set_attr "prefix_extra" "1,*")
5910    (set_attr "prefix" "orig,vex")
5911    (set_attr "mode" "TI")])
5912
5913 (define_insn "*<code>v8hi3"
5914   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
5915         (smaxmin:V8HI
5916           (match_operand:V8HI 1 "nonimmediate_operand" "%0,x")
5917           (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")))]
5918   "TARGET_SSE2 && ix86_binary_operator_ok (<CODE>, V8HImode, operands)"
5919   "@
5920    p<maxmin_int>w\t{%2, %0|%0, %2}
5921    vp<maxmin_int>w\t{%2, %1, %0|%0, %1, %2}"
5922   [(set_attr "isa" "noavx,avx")
5923    (set_attr "type" "sseiadd")
5924    (set_attr "prefix_data16" "1,*")
5925    (set_attr "prefix_extra" "*,1")
5926    (set_attr "prefix" "orig,vex")
5927    (set_attr "mode" "TI")])
5928
5929 (define_expand "<code><mode>3"
5930   [(set (match_operand:VI124_128 0 "register_operand" "")
5931         (umaxmin:VI124_128 (match_operand:VI124_128 1 "nonimmediate_operand" "")
5932                            (match_operand:VI124_128 2 "nonimmediate_operand" "")))]
5933   "TARGET_SSE2"
5934 {
5935   if (TARGET_SSE4_1 || <MODE>mode == V16QImode)
5936     ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);
5937   else if (<CODE> == UMAX && <MODE>mode == V8HImode)
5938     {
5939       rtx op0 = operands[0], op2 = operands[2], op3 = op0;
5940       operands[1] = force_reg (<MODE>mode, operands[1]);
5941       if (rtx_equal_p (op3, op2))
5942         op3 = gen_reg_rtx (V8HImode);
5943       emit_insn (gen_sse2_ussubv8hi3 (op3, operands[1], op2));
5944       emit_insn (gen_addv8hi3 (op0, op3, op2));
5945       DONE;
5946     }
5947   else
5948     {
5949       rtx xops[6];
5950       bool ok;
5951
5952       operands[1] = force_reg (<MODE>mode, operands[1]);
5953       operands[2] = force_reg (<MODE>mode, operands[2]);
5954
5955       xops[0] = operands[0];
5956
5957       if (<CODE> == UMAX)
5958         {
5959           xops[1] = operands[1];
5960           xops[2] = operands[2];
5961         }
5962       else
5963         {
5964           xops[1] = operands[2];
5965           xops[2] = operands[1];
5966         }
5967
5968       xops[3] = gen_rtx_GTU (VOIDmode, operands[1], operands[2]);
5969       xops[4] = operands[1];
5970       xops[5] = operands[2];
5971
5972       ok = ix86_expand_int_vcond (xops);
5973       gcc_assert (ok);
5974       DONE;
5975     }
5976 })
5977
5978 (define_insn "*sse4_1_<code><mode>3"
5979   [(set (match_operand:VI24_128 0 "register_operand" "=x,x")
5980         (umaxmin:VI24_128
5981           (match_operand:VI24_128 1 "nonimmediate_operand" "%0,x")
5982           (match_operand:VI24_128 2 "nonimmediate_operand" "xm,xm")))]
5983   "TARGET_SSE4_1 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
5984   "@
5985    p<maxmin_int><ssemodesuffix>\t{%2, %0|%0, %2}
5986    vp<maxmin_int><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5987   [(set_attr "isa" "noavx,avx")
5988    (set_attr "type" "sseiadd")
5989    (set_attr "prefix_extra" "1,*")
5990    (set_attr "prefix" "orig,vex")
5991    (set_attr "mode" "TI")])
5992
5993 (define_insn "*<code>v16qi3"
5994   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
5995         (umaxmin:V16QI
5996           (match_operand:V16QI 1 "nonimmediate_operand" "%0,x")
5997           (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm")))]
5998   "TARGET_SSE2 && ix86_binary_operator_ok (<CODE>, V16QImode, operands)"
5999   "@
6000    p<maxmin_int>b\t{%2, %0|%0, %2}
6001    vp<maxmin_int>b\t{%2, %1, %0|%0, %1, %2}"
6002   [(set_attr "isa" "noavx,avx")
6003    (set_attr "type" "sseiadd")
6004    (set_attr "prefix_data16" "1,*")
6005    (set_attr "prefix_extra" "*,1")
6006    (set_attr "prefix" "orig,vex")
6007    (set_attr "mode" "TI")])
6008
6009 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6010 ;;
6011 ;; Parallel integral comparisons
6012 ;;
6013 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6014
6015 (define_expand "avx2_eq<mode>3"
6016   [(set (match_operand:VI_256 0 "register_operand" "")
6017         (eq:VI_256
6018           (match_operand:VI_256 1 "nonimmediate_operand" "")
6019           (match_operand:VI_256 2 "nonimmediate_operand" "")))]
6020   "TARGET_AVX2"
6021   "ix86_fixup_binary_operands_no_copy (EQ, <MODE>mode, operands);")
6022
6023 (define_insn "*avx2_eq<mode>3"
6024   [(set (match_operand:VI_256 0 "register_operand" "=x")
6025         (eq:VI_256
6026           (match_operand:VI_256 1 "nonimmediate_operand" "%x")
6027           (match_operand:VI_256 2 "nonimmediate_operand" "xm")))]
6028   "TARGET_AVX2 && ix86_binary_operator_ok (EQ, <MODE>mode, operands)"
6029   "vpcmpeq<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6030   [(set_attr "type" "ssecmp")
6031    (set_attr "prefix_extra" "1")
6032    (set_attr "prefix" "vex")
6033    (set_attr "mode" "OI")])
6034
6035 (define_insn "*sse4_1_eqv2di3"
6036   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
6037         (eq:V2DI
6038           (match_operand:V2DI 1 "nonimmediate_operand" "%0,x")
6039           (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")))]
6040   "TARGET_SSE4_1 && ix86_binary_operator_ok (EQ, V2DImode, operands)"
6041   "@
6042    pcmpeqq\t{%2, %0|%0, %2}
6043    vpcmpeqq\t{%2, %1, %0|%0, %1, %2}"
6044   [(set_attr "isa" "noavx,avx")
6045    (set_attr "type" "ssecmp")
6046    (set_attr "prefix_extra" "1")
6047    (set_attr "prefix" "orig,vex")
6048    (set_attr "mode" "TI")])
6049
6050 (define_insn "*sse2_eq<mode>3"
6051   [(set (match_operand:VI124_128 0 "register_operand" "=x,x")
6052         (eq:VI124_128
6053           (match_operand:VI124_128 1 "nonimmediate_operand" "%0,x")
6054           (match_operand:VI124_128 2 "nonimmediate_operand" "xm,xm")))]
6055   "TARGET_SSE2 && !TARGET_XOP
6056    && ix86_binary_operator_ok (EQ, <MODE>mode, operands)"
6057   "@
6058    pcmpeq<ssemodesuffix>\t{%2, %0|%0, %2}
6059    vpcmpeq<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6060   [(set_attr "isa" "noavx,avx")
6061    (set_attr "type" "ssecmp")
6062    (set_attr "prefix_data16" "1,*")
6063    (set_attr "prefix" "orig,vex")
6064    (set_attr "mode" "TI")])
6065
6066 (define_expand "sse2_eq<mode>3"
6067   [(set (match_operand:VI124_128 0 "register_operand" "")
6068         (eq:VI124_128
6069           (match_operand:VI124_128 1 "nonimmediate_operand" "")
6070           (match_operand:VI124_128 2 "nonimmediate_operand" "")))]
6071   "TARGET_SSE2 && !TARGET_XOP "
6072   "ix86_fixup_binary_operands_no_copy (EQ, <MODE>mode, operands);")
6073
6074 (define_expand "sse4_1_eqv2di3"
6075   [(set (match_operand:V2DI 0 "register_operand" "")
6076         (eq:V2DI
6077           (match_operand:V2DI 1 "nonimmediate_operand" "")
6078           (match_operand:V2DI 2 "nonimmediate_operand" "")))]
6079   "TARGET_SSE4_1"
6080   "ix86_fixup_binary_operands_no_copy (EQ, V2DImode, operands);")
6081
6082 (define_insn "sse4_2_gtv2di3"
6083   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
6084         (gt:V2DI
6085           (match_operand:V2DI 1 "register_operand" "0,x")
6086           (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")))]
6087   "TARGET_SSE4_2"
6088   "@
6089    pcmpgtq\t{%2, %0|%0, %2}
6090    vpcmpgtq\t{%2, %1, %0|%0, %1, %2}"
6091   [(set_attr "isa" "noavx,avx")
6092    (set_attr "type" "ssecmp")
6093    (set_attr "prefix_extra" "1")
6094    (set_attr "prefix" "orig,vex")
6095    (set_attr "mode" "TI")])
6096
6097 (define_insn "avx2_gt<mode>3"
6098   [(set (match_operand:VI_256 0 "register_operand" "=x")
6099         (gt:VI_256
6100           (match_operand:VI_256 1 "register_operand" "x")
6101           (match_operand:VI_256 2 "nonimmediate_operand" "xm")))]
6102   "TARGET_AVX2"
6103   "vpcmpgt<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6104   [(set_attr "type" "ssecmp")
6105    (set_attr "prefix_extra" "1")
6106    (set_attr "prefix" "vex")
6107    (set_attr "mode" "OI")])
6108
6109 (define_insn "sse2_gt<mode>3"
6110   [(set (match_operand:VI124_128 0 "register_operand" "=x,x")
6111         (gt:VI124_128
6112           (match_operand:VI124_128 1 "register_operand" "0,x")
6113           (match_operand:VI124_128 2 "nonimmediate_operand" "xm,xm")))]
6114   "TARGET_SSE2 && !TARGET_XOP"
6115   "@
6116    pcmpgt<ssemodesuffix>\t{%2, %0|%0, %2}
6117    vpcmpgt<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6118   [(set_attr "isa" "noavx,avx")
6119    (set_attr "type" "ssecmp")
6120    (set_attr "prefix_data16" "1,*")
6121    (set_attr "prefix" "orig,vex")
6122    (set_attr "mode" "TI")])
6123
6124 (define_expand "vcond<V_256:mode><VI_256:mode>"
6125   [(set (match_operand:V_256 0 "register_operand" "")
6126         (if_then_else:V_256
6127           (match_operator 3 ""
6128             [(match_operand:VI_256 4 "nonimmediate_operand" "")
6129              (match_operand:VI_256 5 "nonimmediate_operand" "")])
6130           (match_operand:V_256 1 "general_operand" "")
6131           (match_operand:V_256 2 "general_operand" "")))]
6132   "TARGET_AVX2
6133    && (GET_MODE_NUNITS (<V_256:MODE>mode)
6134        == GET_MODE_NUNITS (<VI_256:MODE>mode))"
6135 {
6136   bool ok = ix86_expand_int_vcond (operands);
6137   gcc_assert (ok);
6138   DONE;
6139 })
6140
6141 (define_expand "vcond<V_128:mode><VI124_128:mode>"
6142   [(set (match_operand:V_128 0 "register_operand" "")
6143         (if_then_else:V_128
6144           (match_operator 3 ""
6145             [(match_operand:VI124_128 4 "nonimmediate_operand" "")
6146              (match_operand:VI124_128 5 "nonimmediate_operand" "")])
6147           (match_operand:V_128 1 "general_operand" "")
6148           (match_operand:V_128 2 "general_operand" "")))]
6149   "TARGET_SSE2
6150    && (GET_MODE_NUNITS (<V_128:MODE>mode)
6151        == GET_MODE_NUNITS (<VI124_128:MODE>mode))"
6152 {
6153   bool ok = ix86_expand_int_vcond (operands);
6154   gcc_assert (ok);
6155   DONE;
6156 })
6157
6158 (define_expand "vcond<VI8F_128:mode>v2di"
6159   [(set (match_operand:VI8F_128 0 "register_operand" "")
6160         (if_then_else:VI8F_128
6161           (match_operator 3 ""
6162             [(match_operand:V2DI 4 "nonimmediate_operand" "")
6163              (match_operand:V2DI 5 "nonimmediate_operand" "")])
6164           (match_operand:VI8F_128 1 "general_operand" "")
6165           (match_operand:VI8F_128 2 "general_operand" "")))]
6166   "TARGET_SSE4_2"
6167 {
6168   bool ok = ix86_expand_int_vcond (operands);
6169   gcc_assert (ok);
6170   DONE;
6171 })
6172
6173 (define_expand "vcondu<V_256:mode><VI_256:mode>"
6174   [(set (match_operand:V_256 0 "register_operand" "")
6175         (if_then_else:V_256
6176           (match_operator 3 ""
6177             [(match_operand:VI_256 4 "nonimmediate_operand" "")
6178              (match_operand:VI_256 5 "nonimmediate_operand" "")])
6179           (match_operand:V_256 1 "general_operand" "")
6180           (match_operand:V_256 2 "general_operand" "")))]
6181   "TARGET_AVX2
6182    && (GET_MODE_NUNITS (<V_256:MODE>mode)
6183        == GET_MODE_NUNITS (<VI_256:MODE>mode))"
6184 {
6185   bool ok = ix86_expand_int_vcond (operands);
6186   gcc_assert (ok);
6187   DONE;
6188 })
6189
6190 (define_expand "vcondu<V_128:mode><VI124_128:mode>"
6191   [(set (match_operand:V_128 0 "register_operand" "")
6192         (if_then_else:V_128
6193           (match_operator 3 ""
6194             [(match_operand:VI124_128 4 "nonimmediate_operand" "")
6195              (match_operand:VI124_128 5 "nonimmediate_operand" "")])
6196           (match_operand:V_128 1 "general_operand" "")
6197           (match_operand:V_128 2 "general_operand" "")))]
6198   "TARGET_SSE2
6199    && (GET_MODE_NUNITS (<V_128:MODE>mode)
6200        == GET_MODE_NUNITS (<VI124_128:MODE>mode))"
6201 {
6202   bool ok = ix86_expand_int_vcond (operands);
6203   gcc_assert (ok);
6204   DONE;
6205 })
6206
6207 (define_expand "vcondu<VI8F_128:mode>v2di"
6208   [(set (match_operand:VI8F_128 0 "register_operand" "")
6209         (if_then_else:VI8F_128
6210           (match_operator 3 ""
6211             [(match_operand:V2DI 4 "nonimmediate_operand" "")
6212              (match_operand:V2DI 5 "nonimmediate_operand" "")])
6213           (match_operand:VI8F_128 1 "general_operand" "")
6214           (match_operand:VI8F_128 2 "general_operand" "")))]
6215   "TARGET_SSE4_2"
6216 {
6217   bool ok = ix86_expand_int_vcond (operands);
6218   gcc_assert (ok);
6219   DONE;
6220 })
6221
6222 (define_mode_iterator VEC_PERM_AVX2
6223   [V16QI V8HI V4SI V2DI V4SF V2DF
6224    (V32QI "TARGET_AVX2") (V16HI "TARGET_AVX2")
6225    (V8SI "TARGET_AVX2") (V4DI "TARGET_AVX2")
6226    (V8SF "TARGET_AVX2") (V4DF "TARGET_AVX2")])
6227
6228 (define_expand "vec_perm<mode>"
6229   [(match_operand:VEC_PERM_AVX2 0 "register_operand" "")
6230    (match_operand:VEC_PERM_AVX2 1 "register_operand" "")
6231    (match_operand:VEC_PERM_AVX2 2 "register_operand" "")
6232    (match_operand:<sseintvecmode> 3 "register_operand" "")]
6233   "TARGET_SSSE3 || TARGET_AVX || TARGET_XOP"
6234 {
6235   ix86_expand_vec_perm (operands);
6236   DONE;
6237 })
6238
6239 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6240 ;;
6241 ;; Parallel bitwise logical operations
6242 ;;
6243 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6244
6245 (define_expand "one_cmpl<mode>2"
6246   [(set (match_operand:VI 0 "register_operand" "")
6247         (xor:VI (match_operand:VI 1 "nonimmediate_operand" "")
6248                 (match_dup 2)))]
6249   "TARGET_SSE"
6250 {
6251   int i, n = GET_MODE_NUNITS (<MODE>mode);
6252   rtvec v = rtvec_alloc (n);
6253
6254   for (i = 0; i < n; ++i)
6255     RTVEC_ELT (v, i) = constm1_rtx;
6256
6257   operands[2] = force_reg (<MODE>mode, gen_rtx_CONST_VECTOR (<MODE>mode, v));
6258 })
6259
6260 (define_expand "<sse2_avx2>_andnot<mode>3"
6261   [(set (match_operand:VI_AVX2 0 "register_operand" "")
6262         (and:VI_AVX2
6263           (not:VI_AVX2 (match_operand:VI_AVX2 1 "register_operand" ""))
6264           (match_operand:VI_AVX2 2 "nonimmediate_operand" "")))]
6265   "TARGET_SSE2")
6266
6267 (define_insn "*andnot<mode>3"
6268   [(set (match_operand:VI 0 "register_operand" "=x,x")
6269         (and:VI
6270           (not:VI (match_operand:VI 1 "register_operand" "0,x"))
6271           (match_operand:VI 2 "nonimmediate_operand" "xm,xm")))]
6272   "TARGET_SSE"
6273 {
6274   static char buf[32];
6275   const char *ops;
6276   const char *tmp;
6277
6278   switch (get_attr_mode (insn))
6279     {
6280     case MODE_OI:
6281       gcc_assert (TARGET_AVX2);
6282     case MODE_TI:
6283       gcc_assert (TARGET_SSE2);
6284
6285       tmp = "pandn";
6286       break;
6287
6288    case MODE_V8SF:
6289       gcc_assert (TARGET_AVX);
6290    case MODE_V4SF:
6291       gcc_assert (TARGET_SSE);
6292
6293       tmp = "andnps";
6294       break;
6295
6296    default:
6297       gcc_unreachable ();
6298    }
6299
6300   switch (which_alternative)
6301     {
6302     case 0:
6303       ops = "%s\t{%%2, %%0|%%0, %%2}";
6304       break;
6305     case 1:
6306       ops = "v%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
6307       break;
6308     default:
6309       gcc_unreachable ();
6310     }
6311
6312   snprintf (buf, sizeof (buf), ops, tmp);
6313   return buf;
6314 }
6315   [(set_attr "isa" "noavx,avx")
6316    (set_attr "type" "sselog")
6317    (set (attr "prefix_data16")
6318      (if_then_else
6319        (and (eq_attr "alternative" "0")
6320             (eq_attr "mode" "TI"))
6321        (const_string "1")
6322        (const_string "*")))
6323    (set_attr "prefix" "orig,vex")
6324    (set (attr "mode")
6325      (cond [(and (not (match_test "TARGET_AVX2"))
6326                  (match_test "GET_MODE_SIZE (<MODE>mode) > 16"))
6327               (const_string "V8SF")
6328             (not (match_test "TARGET_SSE2"))
6329               (const_string "V4SF")
6330            ]
6331            (const_string "<sseinsnmode>")))])
6332
6333 (define_expand "<code><mode>3"
6334   [(set (match_operand:VI 0 "register_operand" "")
6335         (any_logic:VI
6336           (match_operand:VI 1 "nonimmediate_operand" "")
6337           (match_operand:VI 2 "nonimmediate_operand" "")))]
6338   "TARGET_SSE"
6339   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
6340
6341 (define_insn "*<code><mode>3"
6342   [(set (match_operand:VI 0 "register_operand" "=x,x")
6343         (any_logic:VI
6344           (match_operand:VI 1 "nonimmediate_operand" "%0,x")
6345           (match_operand:VI 2 "nonimmediate_operand" "xm,xm")))]
6346   "TARGET_SSE
6347    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
6348 {
6349   static char buf[32];
6350   const char *ops;
6351   const char *tmp;
6352
6353   switch (get_attr_mode (insn))
6354     {
6355     case MODE_OI:
6356       gcc_assert (TARGET_AVX2);
6357     case MODE_TI:
6358       gcc_assert (TARGET_SSE2);
6359
6360       tmp = "p<logic>";
6361       break;
6362
6363    case MODE_V8SF:
6364       gcc_assert (TARGET_AVX);
6365    case MODE_V4SF:
6366       gcc_assert (TARGET_SSE);
6367
6368       tmp = "<logic>ps";
6369       break;
6370
6371    default:
6372       gcc_unreachable ();
6373    }
6374
6375   switch (which_alternative)
6376     {
6377     case 0:
6378       ops = "%s\t{%%2, %%0|%%0, %%2}";
6379       break;
6380     case 1:
6381       ops = "v%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
6382       break;
6383     default:
6384       gcc_unreachable ();
6385     }
6386
6387   snprintf (buf, sizeof (buf), ops, tmp);
6388   return buf;
6389 }
6390   [(set_attr "isa" "noavx,avx")
6391    (set_attr "type" "sselog")
6392    (set (attr "prefix_data16")
6393      (if_then_else
6394        (and (eq_attr "alternative" "0")
6395             (eq_attr "mode" "TI"))
6396        (const_string "1")
6397        (const_string "*")))
6398    (set_attr "prefix" "orig,vex")
6399    (set (attr "mode")
6400      (cond [(and (not (match_test "TARGET_AVX2"))
6401                  (match_test "GET_MODE_SIZE (<MODE>mode) > 16"))
6402               (const_string "V8SF")
6403             (not (match_test "TARGET_SSE2"))
6404               (const_string "V4SF")
6405            ]
6406            (const_string "<sseinsnmode>")))])
6407
6408 (define_insn "*andnottf3"
6409   [(set (match_operand:TF 0 "register_operand" "=x,x")
6410         (and:TF
6411           (not:TF (match_operand:TF 1 "register_operand" "0,x"))
6412           (match_operand:TF 2 "nonimmediate_operand" "xm,xm")))]
6413   "TARGET_SSE2"
6414   "@
6415    pandn\t{%2, %0|%0, %2}
6416    vpandn\t{%2, %1, %0|%0, %1, %2}"
6417   [(set_attr "isa" "noavx,avx")
6418    (set_attr "type" "sselog")
6419    (set_attr "prefix_data16" "1,*")
6420    (set_attr "prefix" "orig,vex")
6421    (set_attr "mode" "TI")])
6422
6423 (define_expand "<code>tf3"
6424   [(set (match_operand:TF 0 "register_operand" "")
6425         (any_logic:TF
6426           (match_operand:TF 1 "nonimmediate_operand" "")
6427           (match_operand:TF 2 "nonimmediate_operand" "")))]
6428   "TARGET_SSE2"
6429   "ix86_fixup_binary_operands_no_copy (<CODE>, TFmode, operands);")
6430
6431 (define_insn "*<code>tf3"
6432   [(set (match_operand:TF 0 "register_operand" "=x,x")
6433         (any_logic:TF
6434           (match_operand:TF 1 "nonimmediate_operand" "%0,x")
6435           (match_operand:TF 2 "nonimmediate_operand" "xm,xm")))]
6436   "TARGET_SSE2
6437    && ix86_binary_operator_ok (<CODE>, TFmode, operands)"
6438   "@
6439    p<logic>\t{%2, %0|%0, %2}
6440    vp<logic>\t{%2, %1, %0|%0, %1, %2}"
6441   [(set_attr "isa" "noavx,avx")
6442    (set_attr "type" "sselog")
6443    (set_attr "prefix_data16" "1,*")
6444    (set_attr "prefix" "orig,vex")
6445    (set_attr "mode" "TI")])
6446
6447 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6448 ;;
6449 ;; Parallel integral element swizzling
6450 ;;
6451 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6452
6453 (define_expand "vec_pack_trunc_<mode>"
6454   [(match_operand:<ssepackmode> 0 "register_operand" "")
6455    (match_operand:VI248_AVX2 1 "register_operand" "")
6456    (match_operand:VI248_AVX2 2 "register_operand" "")]
6457   "TARGET_SSE2"
6458 {
6459   rtx op1 = gen_lowpart (<ssepackmode>mode, operands[1]);
6460   rtx op2 = gen_lowpart (<ssepackmode>mode, operands[2]);
6461   ix86_expand_vec_extract_even_odd (operands[0], op1, op2, 0);
6462   DONE;
6463 })
6464
6465 (define_insn "<sse2_avx2>_packsswb"
6466   [(set (match_operand:VI1_AVX2 0 "register_operand" "=x,x")
6467         (vec_concat:VI1_AVX2
6468           (ss_truncate:<ssehalfvecmode>
6469             (match_operand:<sseunpackmode> 1 "register_operand" "0,x"))
6470           (ss_truncate:<ssehalfvecmode>
6471             (match_operand:<sseunpackmode> 2 "nonimmediate_operand" "xm,xm"))))]
6472   "TARGET_SSE2"
6473   "@
6474    packsswb\t{%2, %0|%0, %2}
6475    vpacksswb\t{%2, %1, %0|%0, %1, %2}"
6476   [(set_attr "isa" "noavx,avx")
6477    (set_attr "type" "sselog")
6478    (set_attr "prefix_data16" "1,*")
6479    (set_attr "prefix" "orig,vex")
6480    (set_attr "mode" "<sseinsnmode>")])
6481
6482 (define_insn "<sse2_avx2>_packssdw"
6483   [(set (match_operand:VI2_AVX2 0 "register_operand" "=x,x")
6484         (vec_concat:VI2_AVX2
6485           (ss_truncate:<ssehalfvecmode>
6486             (match_operand:<sseunpackmode> 1 "register_operand" "0,x"))
6487           (ss_truncate:<ssehalfvecmode>
6488             (match_operand:<sseunpackmode> 2 "nonimmediate_operand" "xm,xm"))))]
6489   "TARGET_SSE2"
6490   "@
6491    packssdw\t{%2, %0|%0, %2}
6492    vpackssdw\t{%2, %1, %0|%0, %1, %2}"
6493   [(set_attr "isa" "noavx,avx")
6494    (set_attr "type" "sselog")
6495    (set_attr "prefix_data16" "1,*")
6496    (set_attr "prefix" "orig,vex")
6497    (set_attr "mode" "<sseinsnmode>")])
6498
6499 (define_insn "<sse2_avx2>_packuswb"
6500   [(set (match_operand:VI1_AVX2 0 "register_operand" "=x,x")
6501         (vec_concat:VI1_AVX2
6502           (us_truncate:<ssehalfvecmode>
6503             (match_operand:<sseunpackmode> 1 "register_operand" "0,x"))
6504           (us_truncate:<ssehalfvecmode>
6505             (match_operand:<sseunpackmode> 2 "nonimmediate_operand" "xm,xm"))))]
6506   "TARGET_SSE2"
6507   "@
6508    packuswb\t{%2, %0|%0, %2}
6509    vpackuswb\t{%2, %1, %0|%0, %1, %2}"
6510   [(set_attr "isa" "noavx,avx")
6511    (set_attr "type" "sselog")
6512    (set_attr "prefix_data16" "1,*")
6513    (set_attr "prefix" "orig,vex")
6514    (set_attr "mode" "<sseinsnmode>")])
6515
6516 (define_insn "avx2_interleave_highv32qi"
6517   [(set (match_operand:V32QI 0 "register_operand" "=x")
6518         (vec_select:V32QI
6519           (vec_concat:V64QI
6520             (match_operand:V32QI 1 "register_operand" "x")
6521             (match_operand:V32QI 2 "nonimmediate_operand" "xm"))
6522           (parallel [(const_int 8)  (const_int 40)
6523                      (const_int 9)  (const_int 41)
6524                      (const_int 10) (const_int 42)
6525                      (const_int 11) (const_int 43)
6526                      (const_int 12) (const_int 44)
6527                      (const_int 13) (const_int 45)
6528                      (const_int 14) (const_int 46)
6529                      (const_int 15) (const_int 47)
6530                      (const_int 24) (const_int 56)
6531                      (const_int 25) (const_int 57)
6532                      (const_int 26) (const_int 58)
6533                      (const_int 27) (const_int 59)
6534                      (const_int 28) (const_int 60)
6535                      (const_int 29) (const_int 61)
6536                      (const_int 30) (const_int 62)
6537                      (const_int 31) (const_int 63)])))]
6538   "TARGET_AVX2"
6539   "vpunpckhbw\t{%2, %1, %0|%0, %1, %2}"
6540   [(set_attr "type" "sselog")
6541    (set_attr "prefix" "vex")
6542    (set_attr "mode" "OI")])
6543
6544 (define_insn "vec_interleave_highv16qi"
6545   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
6546         (vec_select:V16QI
6547           (vec_concat:V32QI
6548             (match_operand:V16QI 1 "register_operand" "0,x")
6549             (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm"))
6550           (parallel [(const_int 8)  (const_int 24)
6551                      (const_int 9)  (const_int 25)
6552                      (const_int 10) (const_int 26)
6553                      (const_int 11) (const_int 27)
6554                      (const_int 12) (const_int 28)
6555                      (const_int 13) (const_int 29)
6556                      (const_int 14) (const_int 30)
6557                      (const_int 15) (const_int 31)])))]
6558   "TARGET_SSE2"
6559   "@
6560    punpckhbw\t{%2, %0|%0, %2}
6561    vpunpckhbw\t{%2, %1, %0|%0, %1, %2}"
6562   [(set_attr "isa" "noavx,avx")
6563    (set_attr "type" "sselog")
6564    (set_attr "prefix_data16" "1,*")
6565    (set_attr "prefix" "orig,vex")
6566    (set_attr "mode" "TI")])
6567
6568 (define_insn "avx2_interleave_lowv32qi"
6569   [(set (match_operand:V32QI 0 "register_operand" "=x")
6570         (vec_select:V32QI
6571           (vec_concat:V64QI
6572             (match_operand:V32QI 1 "register_operand" "x")
6573             (match_operand:V32QI 2 "nonimmediate_operand" "xm"))
6574           (parallel [(const_int 0) (const_int 32)
6575                      (const_int 1) (const_int 33)
6576                      (const_int 2) (const_int 34)
6577                      (const_int 3) (const_int 35)
6578                      (const_int 4) (const_int 36)
6579                      (const_int 5) (const_int 37)
6580                      (const_int 6) (const_int 38)
6581                      (const_int 7) (const_int 39)
6582                      (const_int 16) (const_int 48)
6583                      (const_int 17) (const_int 49)
6584                      (const_int 18) (const_int 50)
6585                      (const_int 19) (const_int 51)
6586                      (const_int 20) (const_int 52)
6587                      (const_int 21) (const_int 53)
6588                      (const_int 22) (const_int 54)
6589                      (const_int 23) (const_int 55)])))]
6590   "TARGET_AVX2"
6591   "vpunpcklbw\t{%2, %1, %0|%0, %1, %2}"
6592   [(set_attr "type" "sselog")
6593    (set_attr "prefix" "vex")
6594    (set_attr "mode" "OI")])
6595
6596 (define_insn "vec_interleave_lowv16qi"
6597   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
6598         (vec_select:V16QI
6599           (vec_concat:V32QI
6600             (match_operand:V16QI 1 "register_operand" "0,x")
6601             (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm"))
6602           (parallel [(const_int 0) (const_int 16)
6603                      (const_int 1) (const_int 17)
6604                      (const_int 2) (const_int 18)
6605                      (const_int 3) (const_int 19)
6606                      (const_int 4) (const_int 20)
6607                      (const_int 5) (const_int 21)
6608                      (const_int 6) (const_int 22)
6609                      (const_int 7) (const_int 23)])))]
6610   "TARGET_SSE2"
6611   "@
6612    punpcklbw\t{%2, %0|%0, %2}
6613    vpunpcklbw\t{%2, %1, %0|%0, %1, %2}"
6614   [(set_attr "isa" "noavx,avx")
6615    (set_attr "type" "sselog")
6616    (set_attr "prefix_data16" "1,*")
6617    (set_attr "prefix" "orig,vex")
6618    (set_attr "mode" "TI")])
6619
6620 (define_insn "avx2_interleave_highv16hi"
6621   [(set (match_operand:V16HI 0 "register_operand" "=x")
6622         (vec_select:V16HI
6623           (vec_concat:V32HI
6624             (match_operand:V16HI 1 "register_operand" "x")
6625             (match_operand:V16HI 2 "nonimmediate_operand" "xm"))
6626           (parallel [(const_int 4) (const_int 20)
6627                      (const_int 5) (const_int 21)
6628                      (const_int 6) (const_int 22)
6629                      (const_int 7) (const_int 23)
6630                      (const_int 12) (const_int 28)
6631                      (const_int 13) (const_int 29)
6632                      (const_int 14) (const_int 30)
6633                      (const_int 15) (const_int 31)])))]
6634   "TARGET_AVX2"
6635   "vpunpckhwd\t{%2, %1, %0|%0, %1, %2}"
6636   [(set_attr "type" "sselog")
6637    (set_attr "prefix" "vex")
6638    (set_attr "mode" "OI")])
6639
6640 (define_insn "vec_interleave_highv8hi"
6641   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
6642         (vec_select:V8HI
6643           (vec_concat:V16HI
6644             (match_operand:V8HI 1 "register_operand" "0,x")
6645             (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm"))
6646           (parallel [(const_int 4) (const_int 12)
6647                      (const_int 5) (const_int 13)
6648                      (const_int 6) (const_int 14)
6649                      (const_int 7) (const_int 15)])))]
6650   "TARGET_SSE2"
6651   "@
6652    punpckhwd\t{%2, %0|%0, %2}
6653    vpunpckhwd\t{%2, %1, %0|%0, %1, %2}"
6654   [(set_attr "isa" "noavx,avx")
6655    (set_attr "type" "sselog")
6656    (set_attr "prefix_data16" "1,*")
6657    (set_attr "prefix" "orig,vex")
6658    (set_attr "mode" "TI")])
6659
6660 (define_insn "avx2_interleave_lowv16hi"
6661   [(set (match_operand:V16HI 0 "register_operand" "=x")
6662         (vec_select:V16HI
6663           (vec_concat:V32HI
6664             (match_operand:V16HI 1 "register_operand" "x")
6665             (match_operand:V16HI 2 "nonimmediate_operand" "xm"))
6666           (parallel [(const_int 0) (const_int 16)
6667                      (const_int 1) (const_int 17)
6668                      (const_int 2) (const_int 18)
6669                      (const_int 3) (const_int 19)
6670                      (const_int 8) (const_int 24)
6671                      (const_int 9) (const_int 25)
6672                      (const_int 10) (const_int 26)
6673                      (const_int 11) (const_int 27)])))]
6674   "TARGET_AVX2"
6675   "vpunpcklwd\t{%2, %1, %0|%0, %1, %2}"
6676   [(set_attr "type" "sselog")
6677    (set_attr "prefix" "vex")
6678    (set_attr "mode" "OI")])
6679
6680 (define_insn "vec_interleave_lowv8hi"
6681   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
6682         (vec_select:V8HI
6683           (vec_concat:V16HI
6684             (match_operand:V8HI 1 "register_operand" "0,x")
6685             (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm"))
6686           (parallel [(const_int 0) (const_int 8)
6687                      (const_int 1) (const_int 9)
6688                      (const_int 2) (const_int 10)
6689                      (const_int 3) (const_int 11)])))]
6690   "TARGET_SSE2"
6691   "@
6692    punpcklwd\t{%2, %0|%0, %2}
6693    vpunpcklwd\t{%2, %1, %0|%0, %1, %2}"
6694   [(set_attr "isa" "noavx,avx")
6695    (set_attr "type" "sselog")
6696    (set_attr "prefix_data16" "1,*")
6697    (set_attr "prefix" "orig,vex")
6698    (set_attr "mode" "TI")])
6699
6700 (define_insn "avx2_interleave_highv8si"
6701   [(set (match_operand:V8SI 0 "register_operand" "=x")
6702         (vec_select:V8SI
6703           (vec_concat:V16SI
6704             (match_operand:V8SI 1 "register_operand" "x")
6705             (match_operand:V8SI 2 "nonimmediate_operand" "xm"))
6706           (parallel [(const_int 2) (const_int 10)
6707                      (const_int 3) (const_int 11)
6708                      (const_int 6) (const_int 14)
6709                      (const_int 7) (const_int 15)])))]
6710   "TARGET_AVX2"
6711   "vpunpckhdq\t{%2, %1, %0|%0, %1, %2}"
6712   [(set_attr "type" "sselog")
6713    (set_attr "prefix" "vex")
6714    (set_attr "mode" "OI")])
6715
6716 (define_insn "vec_interleave_highv4si"
6717   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
6718         (vec_select:V4SI
6719           (vec_concat:V8SI
6720             (match_operand:V4SI 1 "register_operand" "0,x")
6721             (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm"))
6722           (parallel [(const_int 2) (const_int 6)
6723                      (const_int 3) (const_int 7)])))]
6724   "TARGET_SSE2"
6725   "@
6726    punpckhdq\t{%2, %0|%0, %2}
6727    vpunpckhdq\t{%2, %1, %0|%0, %1, %2}"
6728   [(set_attr "isa" "noavx,avx")
6729    (set_attr "type" "sselog")
6730    (set_attr "prefix_data16" "1,*")
6731    (set_attr "prefix" "orig,vex")
6732    (set_attr "mode" "TI")])
6733
6734 (define_insn "avx2_interleave_lowv8si"
6735   [(set (match_operand:V8SI 0 "register_operand" "=x")
6736         (vec_select:V8SI
6737           (vec_concat:V16SI
6738             (match_operand:V8SI 1 "register_operand" "x")
6739             (match_operand:V8SI 2 "nonimmediate_operand" "xm"))
6740           (parallel [(const_int 0) (const_int 8)
6741                      (const_int 1) (const_int 9)
6742                      (const_int 4) (const_int 12)
6743                      (const_int 5) (const_int 13)])))]
6744   "TARGET_AVX2"
6745   "vpunpckldq\t{%2, %1, %0|%0, %1, %2}"
6746   [(set_attr "type" "sselog")
6747    (set_attr "prefix" "vex")
6748    (set_attr "mode" "OI")])
6749
6750 (define_insn "vec_interleave_lowv4si"
6751   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
6752         (vec_select:V4SI
6753           (vec_concat:V8SI
6754             (match_operand:V4SI 1 "register_operand" "0,x")
6755             (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm"))
6756           (parallel [(const_int 0) (const_int 4)
6757                      (const_int 1) (const_int 5)])))]
6758   "TARGET_SSE2"
6759   "@
6760    punpckldq\t{%2, %0|%0, %2}
6761    vpunpckldq\t{%2, %1, %0|%0, %1, %2}"
6762   [(set_attr "isa" "noavx,avx")
6763    (set_attr "type" "sselog")
6764    (set_attr "prefix_data16" "1,*")
6765    (set_attr "prefix" "orig,vex")
6766    (set_attr "mode" "TI")])
6767
6768 ;; Modes handled by pinsr patterns.
6769 (define_mode_iterator PINSR_MODE
6770   [(V16QI "TARGET_SSE4_1") V8HI
6771    (V4SI "TARGET_SSE4_1")
6772    (V2DI "TARGET_SSE4_1 && TARGET_64BIT")])
6773
6774 (define_mode_attr sse2p4_1
6775   [(V16QI "sse4_1") (V8HI "sse2")
6776    (V4SI "sse4_1") (V2DI "sse4_1")])
6777
6778 ;; sse4_1_pinsrd must come before sse2_loadld since it is preferred.
6779 (define_insn "<sse2p4_1>_pinsr<ssemodesuffix>"
6780   [(set (match_operand:PINSR_MODE 0 "register_operand" "=x,x,x,x")
6781         (vec_merge:PINSR_MODE
6782           (vec_duplicate:PINSR_MODE
6783             (match_operand:<ssescalarmode> 2 "nonimmediate_operand" "r,m,r,m"))
6784           (match_operand:PINSR_MODE 1 "register_operand" "0,0,x,x")
6785           (match_operand:SI 3 "const_int_operand" "")))]
6786   "TARGET_SSE2
6787    && ((unsigned) exact_log2 (INTVAL (operands[3]))
6788        < GET_MODE_NUNITS (<MODE>mode))"
6789 {
6790   operands[3] = GEN_INT (exact_log2 (INTVAL (operands[3])));
6791
6792   switch (which_alternative)
6793     {
6794     case 0:
6795       if (GET_MODE_SIZE (<ssescalarmode>mode) < GET_MODE_SIZE (SImode))
6796         return "pinsr<ssemodesuffix>\t{%3, %k2, %0|%0, %k2, %3}";
6797       /* FALLTHRU */
6798     case 1:
6799       return "pinsr<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}";
6800     case 2:
6801       if (GET_MODE_SIZE (<ssescalarmode>mode) < GET_MODE_SIZE (SImode))
6802         return "vpinsr<ssemodesuffix>\t{%3, %k2, %1, %0|%0, %1, %k2, %3}";
6803       /* FALLTHRU */
6804     case 3:
6805       return "vpinsr<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}";
6806     default:
6807       gcc_unreachable ();
6808     }
6809 }
6810   [(set_attr "isa" "noavx,noavx,avx,avx")
6811    (set_attr "type" "sselog")
6812    (set (attr "prefix_rex")
6813      (if_then_else
6814        (and (not (match_test "TARGET_AVX"))
6815             (eq (const_string "<MODE>mode") (const_string "V2DImode")))
6816        (const_string "1")
6817        (const_string "*")))
6818    (set (attr "prefix_data16")
6819      (if_then_else
6820        (and (not (match_test "TARGET_AVX"))
6821             (eq (const_string "<MODE>mode") (const_string "V8HImode")))
6822        (const_string "1")
6823        (const_string "*")))
6824    (set (attr "prefix_extra")
6825      (if_then_else
6826        (and (not (match_test "TARGET_AVX"))
6827             (eq (const_string "<MODE>mode") (const_string "V8HImode")))
6828        (const_string "*")
6829        (const_string "1")))
6830    (set_attr "length_immediate" "1")
6831    (set_attr "prefix" "orig,orig,vex,vex")
6832    (set_attr "mode" "TI")])
6833
6834 (define_insn "*sse4_1_pextrb_<mode>"
6835   [(set (match_operand:SWI48 0 "register_operand" "=r")
6836         (zero_extend:SWI48
6837           (vec_select:QI
6838             (match_operand:V16QI 1 "register_operand" "x")
6839             (parallel [(match_operand:SI 2 "const_0_to_15_operand" "n")]))))]
6840   "TARGET_SSE4_1"
6841   "%vpextrb\t{%2, %1, %k0|%k0, %1, %2}"
6842   [(set_attr "type" "sselog")
6843    (set_attr "prefix_extra" "1")
6844    (set_attr "length_immediate" "1")
6845    (set_attr "prefix" "maybe_vex")
6846    (set_attr "mode" "TI")])
6847
6848 (define_insn "*sse4_1_pextrb_memory"
6849   [(set (match_operand:QI 0 "memory_operand" "=m")
6850         (vec_select:QI
6851           (match_operand:V16QI 1 "register_operand" "x")
6852           (parallel [(match_operand:SI 2 "const_0_to_15_operand" "n")])))]
6853   "TARGET_SSE4_1"
6854   "%vpextrb\t{%2, %1, %0|%0, %1, %2}"
6855   [(set_attr "type" "sselog")
6856    (set_attr "prefix_extra" "1")
6857    (set_attr "length_immediate" "1")
6858    (set_attr "prefix" "maybe_vex")
6859    (set_attr "mode" "TI")])
6860
6861 (define_insn "*sse2_pextrw_<mode>"
6862   [(set (match_operand:SWI48 0 "register_operand" "=r")
6863         (zero_extend:SWI48
6864           (vec_select:HI
6865             (match_operand:V8HI 1 "register_operand" "x")
6866             (parallel [(match_operand:SI 2 "const_0_to_7_operand" "n")]))))]
6867   "TARGET_SSE2"
6868   "%vpextrw\t{%2, %1, %k0|%k0, %1, %2}"
6869   [(set_attr "type" "sselog")
6870    (set_attr "prefix_data16" "1")
6871    (set_attr "length_immediate" "1")
6872    (set_attr "prefix" "maybe_vex")
6873    (set_attr "mode" "TI")])
6874
6875 (define_insn "*sse4_1_pextrw_memory"
6876   [(set (match_operand:HI 0 "memory_operand" "=m")
6877         (vec_select:HI
6878           (match_operand:V8HI 1 "register_operand" "x")
6879           (parallel [(match_operand:SI 2 "const_0_to_7_operand" "n")])))]
6880   "TARGET_SSE4_1"
6881   "%vpextrw\t{%2, %1, %0|%0, %1, %2}"
6882   [(set_attr "type" "sselog")
6883    (set_attr "prefix_extra" "1")
6884    (set_attr "length_immediate" "1")
6885    (set_attr "prefix" "maybe_vex")
6886    (set_attr "mode" "TI")])
6887
6888 (define_insn "*sse4_1_pextrd"
6889   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
6890         (vec_select:SI
6891           (match_operand:V4SI 1 "register_operand" "x")
6892           (parallel [(match_operand:SI 2 "const_0_to_3_operand" "n")])))]
6893   "TARGET_SSE4_1"
6894   "%vpextrd\t{%2, %1, %0|%0, %1, %2}"
6895   [(set_attr "type" "sselog")
6896    (set_attr "prefix_extra" "1")
6897    (set_attr "length_immediate" "1")
6898    (set_attr "prefix" "maybe_vex")
6899    (set_attr "mode" "TI")])
6900
6901 (define_insn "*sse4_1_pextrd_zext"
6902   [(set (match_operand:DI 0 "register_operand" "=r")
6903         (zero_extend:DI
6904           (vec_select:SI
6905             (match_operand:V4SI 1 "register_operand" "x")
6906             (parallel [(match_operand:SI 2 "const_0_to_3_operand" "n")]))))]
6907   "TARGET_64BIT && TARGET_SSE4_1"
6908   "%vpextrd\t{%2, %1, %k0|%k0, %1, %2}"
6909   [(set_attr "type" "sselog")
6910    (set_attr "prefix_extra" "1")
6911    (set_attr "length_immediate" "1")
6912    (set_attr "prefix" "maybe_vex")
6913    (set_attr "mode" "TI")])
6914
6915 ;; It must come before *vec_extractv2di_1_rex64 since it is preferred.
6916 (define_insn "*sse4_1_pextrq"
6917   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
6918         (vec_select:DI
6919           (match_operand:V2DI 1 "register_operand" "x")
6920           (parallel [(match_operand:SI 2 "const_0_to_1_operand" "n")])))]
6921   "TARGET_SSE4_1 && TARGET_64BIT"
6922   "%vpextrq\t{%2, %1, %0|%0, %1, %2}"
6923   [(set_attr "type" "sselog")
6924    (set_attr "prefix_rex" "1")
6925    (set_attr "prefix_extra" "1")
6926    (set_attr "length_immediate" "1")
6927    (set_attr "prefix" "maybe_vex")
6928    (set_attr "mode" "TI")])
6929
6930 (define_expand "avx2_pshufdv3"
6931   [(match_operand:V8SI 0 "register_operand" "")
6932    (match_operand:V8SI 1 "nonimmediate_operand" "")
6933    (match_operand:SI 2 "const_0_to_255_operand" "")]
6934   "TARGET_AVX2"
6935 {
6936   int mask = INTVAL (operands[2]);
6937   emit_insn (gen_avx2_pshufd_1 (operands[0], operands[1],
6938                                 GEN_INT ((mask >> 0) & 3),
6939                                 GEN_INT ((mask >> 2) & 3),
6940                                 GEN_INT ((mask >> 4) & 3),
6941                                 GEN_INT ((mask >> 6) & 3),
6942                                 GEN_INT (((mask >> 0) & 3) + 4),
6943                                 GEN_INT (((mask >> 2) & 3) + 4),
6944                                 GEN_INT (((mask >> 4) & 3) + 4),
6945                                 GEN_INT (((mask >> 6) & 3) + 4)));
6946   DONE;
6947 })
6948
6949 (define_insn "avx2_pshufd_1"
6950   [(set (match_operand:V8SI 0 "register_operand" "=x")
6951         (vec_select:V8SI
6952           (match_operand:V8SI 1 "nonimmediate_operand" "xm")
6953           (parallel [(match_operand 2 "const_0_to_3_operand" "")
6954                      (match_operand 3 "const_0_to_3_operand" "")
6955                      (match_operand 4 "const_0_to_3_operand" "")
6956                      (match_operand 5 "const_0_to_3_operand" "")
6957                      (match_operand 6 "const_4_to_7_operand" "")
6958                      (match_operand 7 "const_4_to_7_operand" "")
6959                      (match_operand 8 "const_4_to_7_operand" "")
6960                      (match_operand 9 "const_4_to_7_operand" "")])))]
6961   "TARGET_AVX2
6962    && INTVAL (operands[2]) + 4 == INTVAL (operands[6])
6963    && INTVAL (operands[3]) + 4 == INTVAL (operands[7])
6964    && INTVAL (operands[4]) + 4 == INTVAL (operands[8])
6965    && INTVAL (operands[5]) + 4 == INTVAL (operands[9])"
6966 {
6967   int mask = 0;
6968   mask |= INTVAL (operands[2]) << 0;
6969   mask |= INTVAL (operands[3]) << 2;
6970   mask |= INTVAL (operands[4]) << 4;
6971   mask |= INTVAL (operands[5]) << 6;
6972   operands[2] = GEN_INT (mask);
6973
6974   return "vpshufd\t{%2, %1, %0|%0, %1, %2}";
6975 }
6976   [(set_attr "type" "sselog1")
6977    (set_attr "prefix" "vex")
6978    (set_attr "length_immediate" "1")
6979    (set_attr "mode" "OI")])
6980
6981 (define_expand "sse2_pshufd"
6982   [(match_operand:V4SI 0 "register_operand" "")
6983    (match_operand:V4SI 1 "nonimmediate_operand" "")
6984    (match_operand:SI 2 "const_int_operand" "")]
6985   "TARGET_SSE2"
6986 {
6987   int mask = INTVAL (operands[2]);
6988   emit_insn (gen_sse2_pshufd_1 (operands[0], operands[1],
6989                                 GEN_INT ((mask >> 0) & 3),
6990                                 GEN_INT ((mask >> 2) & 3),
6991                                 GEN_INT ((mask >> 4) & 3),
6992                                 GEN_INT ((mask >> 6) & 3)));
6993   DONE;
6994 })
6995
6996 (define_insn "sse2_pshufd_1"
6997   [(set (match_operand:V4SI 0 "register_operand" "=x")
6998         (vec_select:V4SI
6999           (match_operand:V4SI 1 "nonimmediate_operand" "xm")
7000           (parallel [(match_operand 2 "const_0_to_3_operand" "")
7001                      (match_operand 3 "const_0_to_3_operand" "")
7002                      (match_operand 4 "const_0_to_3_operand" "")
7003                      (match_operand 5 "const_0_to_3_operand" "")])))]
7004   "TARGET_SSE2"
7005 {
7006   int mask = 0;
7007   mask |= INTVAL (operands[2]) << 0;
7008   mask |= INTVAL (operands[3]) << 2;
7009   mask |= INTVAL (operands[4]) << 4;
7010   mask |= INTVAL (operands[5]) << 6;
7011   operands[2] = GEN_INT (mask);
7012
7013   return "%vpshufd\t{%2, %1, %0|%0, %1, %2}";
7014 }
7015   [(set_attr "type" "sselog1")
7016    (set_attr "prefix_data16" "1")
7017    (set_attr "prefix" "maybe_vex")
7018    (set_attr "length_immediate" "1")
7019    (set_attr "mode" "TI")])
7020
7021 (define_expand "avx2_pshuflwv3"
7022   [(match_operand:V16HI 0 "register_operand" "")
7023    (match_operand:V16HI 1 "nonimmediate_operand" "")
7024    (match_operand:SI 2 "const_0_to_255_operand" "")]
7025   "TARGET_AVX2"
7026 {
7027   int mask = INTVAL (operands[2]);
7028   emit_insn (gen_avx2_pshuflw_1 (operands[0], operands[1],
7029                                  GEN_INT ((mask >> 0) & 3),
7030                                  GEN_INT ((mask >> 2) & 3),
7031                                  GEN_INT ((mask >> 4) & 3),
7032                                  GEN_INT ((mask >> 6) & 3),
7033                                  GEN_INT (((mask >> 0) & 3) + 8),
7034                                  GEN_INT (((mask >> 2) & 3) + 8),
7035                                  GEN_INT (((mask >> 4) & 3) + 8),
7036                                  GEN_INT (((mask >> 6) & 3) + 8)));
7037   DONE;
7038 })
7039
7040 (define_insn "avx2_pshuflw_1"
7041   [(set (match_operand:V16HI 0 "register_operand" "=x")
7042         (vec_select:V16HI
7043           (match_operand:V16HI 1 "nonimmediate_operand" "xm")
7044           (parallel [(match_operand 2 "const_0_to_3_operand" "")
7045                      (match_operand 3 "const_0_to_3_operand" "")
7046                      (match_operand 4 "const_0_to_3_operand" "")
7047                      (match_operand 5 "const_0_to_3_operand" "")
7048                      (const_int 4)
7049                      (const_int 5)
7050                      (const_int 6)
7051                      (const_int 7)
7052                      (match_operand 6 "const_8_to_11_operand" "")
7053                      (match_operand 7 "const_8_to_11_operand" "")
7054                      (match_operand 8 "const_8_to_11_operand" "")
7055                      (match_operand 9 "const_8_to_11_operand" "")
7056                      (const_int 12)
7057                      (const_int 13)
7058                      (const_int 14)
7059                      (const_int 15)])))]
7060   "TARGET_AVX2
7061    && INTVAL (operands[2]) + 8 == INTVAL (operands[6])
7062    && INTVAL (operands[3]) + 8 == INTVAL (operands[7])
7063    && INTVAL (operands[4]) + 8 == INTVAL (operands[8])
7064    && INTVAL (operands[5]) + 8 == INTVAL (operands[9])"
7065 {
7066   int mask = 0;
7067   mask |= INTVAL (operands[2]) << 0;
7068   mask |= INTVAL (operands[3]) << 2;
7069   mask |= INTVAL (operands[4]) << 4;
7070   mask |= INTVAL (operands[5]) << 6;
7071   operands[2] = GEN_INT (mask);
7072
7073   return "vpshuflw\t{%2, %1, %0|%0, %1, %2}";
7074 }
7075   [(set_attr "type" "sselog")
7076    (set_attr "prefix" "vex")
7077    (set_attr "length_immediate" "1")
7078    (set_attr "mode" "OI")])
7079
7080 (define_expand "sse2_pshuflw"
7081   [(match_operand:V8HI 0 "register_operand" "")
7082    (match_operand:V8HI 1 "nonimmediate_operand" "")
7083    (match_operand:SI 2 "const_int_operand" "")]
7084   "TARGET_SSE2"
7085 {
7086   int mask = INTVAL (operands[2]);
7087   emit_insn (gen_sse2_pshuflw_1 (operands[0], operands[1],
7088                                  GEN_INT ((mask >> 0) & 3),
7089                                  GEN_INT ((mask >> 2) & 3),
7090                                  GEN_INT ((mask >> 4) & 3),
7091                                  GEN_INT ((mask >> 6) & 3)));
7092   DONE;
7093 })
7094
7095 (define_insn "sse2_pshuflw_1"
7096   [(set (match_operand:V8HI 0 "register_operand" "=x")
7097         (vec_select:V8HI
7098           (match_operand:V8HI 1 "nonimmediate_operand" "xm")
7099           (parallel [(match_operand 2 "const_0_to_3_operand" "")
7100                      (match_operand 3 "const_0_to_3_operand" "")
7101                      (match_operand 4 "const_0_to_3_operand" "")
7102                      (match_operand 5 "const_0_to_3_operand" "")
7103                      (const_int 4)
7104                      (const_int 5)
7105                      (const_int 6)
7106                      (const_int 7)])))]
7107   "TARGET_SSE2"
7108 {
7109   int mask = 0;
7110   mask |= INTVAL (operands[2]) << 0;
7111   mask |= INTVAL (operands[3]) << 2;
7112   mask |= INTVAL (operands[4]) << 4;
7113   mask |= INTVAL (operands[5]) << 6;
7114   operands[2] = GEN_INT (mask);
7115
7116   return "%vpshuflw\t{%2, %1, %0|%0, %1, %2}";
7117 }
7118   [(set_attr "type" "sselog")
7119    (set_attr "prefix_data16" "0")
7120    (set_attr "prefix_rep" "1")
7121    (set_attr "prefix" "maybe_vex")
7122    (set_attr "length_immediate" "1")
7123    (set_attr "mode" "TI")])
7124
7125 (define_expand "avx2_pshufhwv3"
7126   [(match_operand:V16HI 0 "register_operand" "")
7127    (match_operand:V16HI 1 "nonimmediate_operand" "")
7128    (match_operand:SI 2 "const_0_to_255_operand" "")]
7129   "TARGET_AVX2"
7130 {
7131   int mask = INTVAL (operands[2]);
7132   emit_insn (gen_avx2_pshufhw_1 (operands[0], operands[1],
7133                                  GEN_INT (((mask >> 0) & 3) + 4),
7134                                  GEN_INT (((mask >> 2) & 3) + 4),
7135                                  GEN_INT (((mask >> 4) & 3) + 4),
7136                                  GEN_INT (((mask >> 6) & 3) + 4),
7137                                  GEN_INT (((mask >> 0) & 3) + 12),
7138                                  GEN_INT (((mask >> 2) & 3) + 12),
7139                                  GEN_INT (((mask >> 4) & 3) + 12),
7140                                  GEN_INT (((mask >> 6) & 3) + 12)));
7141   DONE;
7142 })
7143
7144 (define_insn "avx2_pshufhw_1"
7145   [(set (match_operand:V16HI 0 "register_operand" "=x")
7146         (vec_select:V16HI
7147           (match_operand:V16HI 1 "nonimmediate_operand" "xm")
7148           (parallel [(const_int 0)
7149                      (const_int 1)
7150                      (const_int 2)
7151                      (const_int 3)
7152                      (match_operand 2 "const_4_to_7_operand" "")
7153                      (match_operand 3 "const_4_to_7_operand" "")
7154                      (match_operand 4 "const_4_to_7_operand" "")
7155                      (match_operand 5 "const_4_to_7_operand" "")
7156                      (const_int 8)
7157                      (const_int 9)
7158                      (const_int 10)
7159                      (const_int 11)
7160                      (match_operand 6 "const_12_to_15_operand" "")
7161                      (match_operand 7 "const_12_to_15_operand" "")
7162                      (match_operand 8 "const_12_to_15_operand" "")
7163                      (match_operand 9 "const_12_to_15_operand" "")])))]
7164   "TARGET_AVX2
7165    && INTVAL (operands[2]) + 8 == INTVAL (operands[6])
7166    && INTVAL (operands[3]) + 8 == INTVAL (operands[7])
7167    && INTVAL (operands[4]) + 8 == INTVAL (operands[8])
7168    && INTVAL (operands[5]) + 8 == INTVAL (operands[9])"
7169 {
7170   int mask = 0;
7171   mask |= (INTVAL (operands[2]) - 4) << 0;
7172   mask |= (INTVAL (operands[3]) - 4) << 2;
7173   mask |= (INTVAL (operands[4]) - 4) << 4;
7174   mask |= (INTVAL (operands[5]) - 4) << 6;
7175   operands[2] = GEN_INT (mask);
7176
7177   return "vpshufhw\t{%2, %1, %0|%0, %1, %2}";
7178 }
7179   [(set_attr "type" "sselog")
7180    (set_attr "prefix" "vex")
7181    (set_attr "length_immediate" "1")
7182    (set_attr "mode" "OI")])
7183
7184 (define_expand "sse2_pshufhw"
7185   [(match_operand:V8HI 0 "register_operand" "")
7186    (match_operand:V8HI 1 "nonimmediate_operand" "")
7187    (match_operand:SI 2 "const_int_operand" "")]
7188   "TARGET_SSE2"
7189 {
7190   int mask = INTVAL (operands[2]);
7191   emit_insn (gen_sse2_pshufhw_1 (operands[0], operands[1],
7192                                  GEN_INT (((mask >> 0) & 3) + 4),
7193                                  GEN_INT (((mask >> 2) & 3) + 4),
7194                                  GEN_INT (((mask >> 4) & 3) + 4),
7195                                  GEN_INT (((mask >> 6) & 3) + 4)));
7196   DONE;
7197 })
7198
7199 (define_insn "sse2_pshufhw_1"
7200   [(set (match_operand:V8HI 0 "register_operand" "=x")
7201         (vec_select:V8HI
7202           (match_operand:V8HI 1 "nonimmediate_operand" "xm")
7203           (parallel [(const_int 0)
7204                      (const_int 1)
7205                      (const_int 2)
7206                      (const_int 3)
7207                      (match_operand 2 "const_4_to_7_operand" "")
7208                      (match_operand 3 "const_4_to_7_operand" "")
7209                      (match_operand 4 "const_4_to_7_operand" "")
7210                      (match_operand 5 "const_4_to_7_operand" "")])))]
7211   "TARGET_SSE2"
7212 {
7213   int mask = 0;
7214   mask |= (INTVAL (operands[2]) - 4) << 0;
7215   mask |= (INTVAL (operands[3]) - 4) << 2;
7216   mask |= (INTVAL (operands[4]) - 4) << 4;
7217   mask |= (INTVAL (operands[5]) - 4) << 6;
7218   operands[2] = GEN_INT (mask);
7219
7220   return "%vpshufhw\t{%2, %1, %0|%0, %1, %2}";
7221 }
7222   [(set_attr "type" "sselog")
7223    (set_attr "prefix_rep" "1")
7224    (set_attr "prefix_data16" "0")
7225    (set_attr "prefix" "maybe_vex")
7226    (set_attr "length_immediate" "1")
7227    (set_attr "mode" "TI")])
7228
7229 (define_expand "sse2_loadd"
7230   [(set (match_operand:V4SI 0 "register_operand" "")
7231         (vec_merge:V4SI
7232           (vec_duplicate:V4SI
7233             (match_operand:SI 1 "nonimmediate_operand" ""))
7234           (match_dup 2)
7235           (const_int 1)))]
7236   "TARGET_SSE"
7237   "operands[2] = CONST0_RTX (V4SImode);")
7238
7239 (define_insn "sse2_loadld"
7240   [(set (match_operand:V4SI 0 "register_operand"       "=x,Yi,x,x,x")
7241         (vec_merge:V4SI
7242           (vec_duplicate:V4SI
7243             (match_operand:SI 2 "nonimmediate_operand" "m ,r ,m,x,x"))
7244           (match_operand:V4SI 1 "reg_or_0_operand"     "C ,C ,C,0,x")
7245           (const_int 1)))]
7246   "TARGET_SSE"
7247   "@
7248    %vmovd\t{%2, %0|%0, %2}
7249    %vmovd\t{%2, %0|%0, %2}
7250    movss\t{%2, %0|%0, %2}
7251    movss\t{%2, %0|%0, %2}
7252    vmovss\t{%2, %1, %0|%0, %1, %2}"
7253   [(set_attr "isa" "sse2,*,noavx,noavx,avx")
7254    (set_attr "type" "ssemov")
7255    (set_attr "prefix" "maybe_vex,maybe_vex,orig,orig,vex")
7256    (set_attr "mode" "TI,TI,V4SF,SF,SF")])
7257
7258 (define_insn_and_split "sse2_stored"
7259   [(set (match_operand:SI 0 "nonimmediate_operand" "=xm,r")
7260         (vec_select:SI
7261           (match_operand:V4SI 1 "register_operand" "x,Yi")
7262           (parallel [(const_int 0)])))]
7263   "TARGET_SSE"
7264   "#"
7265   "&& reload_completed
7266    && (TARGET_INTER_UNIT_MOVES
7267        || MEM_P (operands [0])
7268        || !GENERAL_REGNO_P (true_regnum (operands [0])))"
7269   [(set (match_dup 0) (match_dup 1))]
7270   "operands[1] = gen_rtx_REG (SImode, REGNO (operands[1]));")
7271
7272 (define_insn_and_split "*vec_ext_v4si_mem"
7273   [(set (match_operand:SI 0 "register_operand" "=r")
7274         (vec_select:SI
7275           (match_operand:V4SI 1 "memory_operand" "o")
7276           (parallel [(match_operand 2 "const_0_to_3_operand" "")])))]
7277   ""
7278   "#"
7279   "reload_completed"
7280   [(const_int 0)]
7281 {
7282   int i = INTVAL (operands[2]);
7283
7284   emit_move_insn (operands[0], adjust_address (operands[1], SImode, i*4));
7285   DONE;
7286 })
7287
7288 (define_expand "sse_storeq"
7289   [(set (match_operand:DI 0 "nonimmediate_operand" "")
7290         (vec_select:DI
7291           (match_operand:V2DI 1 "register_operand" "")
7292           (parallel [(const_int 0)])))]
7293   "TARGET_SSE")
7294
7295 (define_insn "*sse2_storeq_rex64"
7296   [(set (match_operand:DI 0 "nonimmediate_operand" "=xm,*r,r")
7297         (vec_select:DI
7298           (match_operand:V2DI 1 "nonimmediate_operand" "x,Yi,o")
7299           (parallel [(const_int 0)])))]
7300   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7301   "@
7302    #
7303    #
7304    mov{q}\t{%1, %0|%0, %1}"
7305   [(set_attr "type" "*,*,imov")
7306    (set_attr "mode" "*,*,DI")])
7307
7308 (define_insn "*sse2_storeq"
7309   [(set (match_operand:DI 0 "nonimmediate_operand" "=xm")
7310         (vec_select:DI
7311           (match_operand:V2DI 1 "register_operand" "x")
7312           (parallel [(const_int 0)])))]
7313   "TARGET_SSE"
7314   "#")
7315
7316 (define_split
7317   [(set (match_operand:DI 0 "nonimmediate_operand" "")
7318         (vec_select:DI
7319           (match_operand:V2DI 1 "register_operand" "")
7320           (parallel [(const_int 0)])))]
7321   "TARGET_SSE
7322    && reload_completed
7323    && (TARGET_INTER_UNIT_MOVES
7324        || MEM_P (operands [0])
7325        || !GENERAL_REGNO_P (true_regnum (operands [0])))"
7326   [(set (match_dup 0) (match_dup 1))]
7327   "operands[1] = gen_rtx_REG (DImode, REGNO (operands[1]));")
7328
7329 (define_insn "*vec_extractv2di_1_rex64"
7330   [(set (match_operand:DI 0 "nonimmediate_operand"     "=m,x,x,x,r")
7331         (vec_select:DI
7332           (match_operand:V2DI 1 "nonimmediate_operand" " x,0,x,o,o")
7333           (parallel [(const_int 1)])))]
7334   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7335   "@
7336    %vmovhps\t{%1, %0|%0, %1}
7337    psrldq\t{$8, %0|%0, 8}
7338    vpsrldq\t{$8, %1, %0|%0, %1, 8}
7339    %vmovq\t{%H1, %0|%0, %H1}
7340    mov{q}\t{%H1, %0|%0, %H1}"
7341   [(set_attr "isa" "*,noavx,avx,*,*")
7342    (set_attr "type" "ssemov,sseishft1,sseishft1,ssemov,imov")
7343    (set_attr "length_immediate" "*,1,1,*,*")
7344    (set_attr "memory" "*,none,none,*,*")
7345    (set_attr "prefix" "maybe_vex,orig,vex,maybe_vex,orig")
7346    (set_attr "mode" "V2SF,TI,TI,TI,DI")])
7347
7348 (define_insn "*vec_extractv2di_1"
7349   [(set (match_operand:DI 0 "nonimmediate_operand"     "=m,x,x,x,x,x")
7350         (vec_select:DI
7351           (match_operand:V2DI 1 "nonimmediate_operand" " x,0,x,o,x,o")
7352           (parallel [(const_int 1)])))]
7353   "!TARGET_64BIT && TARGET_SSE
7354    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7355   "@
7356    %vmovhps\t{%1, %0|%0, %1}
7357    psrldq\t{$8, %0|%0, 8}
7358    vpsrldq\t{$8, %1, %0|%0, %1, 8}
7359    %vmovq\t{%H1, %0|%0, %H1}
7360    movhlps\t{%1, %0|%0, %1}
7361    movlps\t{%H1, %0|%0, %H1}"
7362   [(set_attr "isa" "*,sse2_noavx,avx,sse2,noavx,noavx")
7363    (set_attr "type" "ssemov,sseishft1,sseishft1,ssemov,ssemov,ssemov")
7364    (set_attr "length_immediate" "*,1,1,*,*,*")
7365    (set_attr "memory" "*,none,none,*,*,*")
7366    (set_attr "prefix" "maybe_vex,orig,vex,maybe_vex,orig,orig")
7367    (set_attr "mode" "V2SF,TI,TI,TI,V4SF,V2SF")])
7368
7369 (define_insn "*vec_dupv4si_avx"
7370   [(set (match_operand:V4SI 0 "register_operand"     "=x,x")
7371         (vec_duplicate:V4SI
7372           (match_operand:SI 1 "nonimmediate_operand" " x,m")))]
7373   "TARGET_AVX"
7374   "@
7375    vpshufd\t{$0, %1, %0|%0, %1, 0}
7376    vbroadcastss\t{%1, %0|%0, %1}"
7377   [(set_attr "type" "sselog1,ssemov")
7378    (set_attr "length_immediate" "1,0")
7379    (set_attr "prefix_extra" "0,1")
7380    (set_attr "prefix" "vex")
7381    (set_attr "mode" "TI,V4SF")])
7382
7383 (define_insn "*vec_dupv4si"
7384   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
7385         (vec_duplicate:V4SI
7386           (match_operand:SI 1 "register_operand" " x,0")))]
7387   "TARGET_SSE"
7388   "@
7389    pshufd\t{$0, %1, %0|%0, %1, 0}
7390    shufps\t{$0, %0, %0|%0, %0, 0}"
7391   [(set_attr "isa" "sse2,*")
7392    (set_attr "type" "sselog1")
7393    (set_attr "length_immediate" "1")
7394    (set_attr "mode" "TI,V4SF")])
7395
7396 (define_insn "*vec_dupv2di_sse3"
7397   [(set (match_operand:V2DI 0 "register_operand"     "=x,x,x")
7398         (vec_duplicate:V2DI
7399           (match_operand:DI 1 "nonimmediate_operand" " 0,x,m")))]
7400   "TARGET_SSE3"
7401   "@
7402    punpcklqdq\t%0, %0
7403    vpunpcklqdq\t{%d1, %0|%0, %d1}
7404    %vmovddup\t{%1, %0|%0, %1}"
7405   [(set_attr "isa" "noavx,avx,*")
7406    (set_attr "type" "sselog1")
7407    (set_attr "prefix" "orig,vex,maybe_vex")
7408    (set_attr "mode" "TI,TI,DF")])
7409
7410 (define_insn "*vec_dupv2di"
7411   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
7412         (vec_duplicate:V2DI
7413           (match_operand:DI 1 "register_operand" " 0,0")))]
7414   "TARGET_SSE"
7415   "@
7416    punpcklqdq\t%0, %0
7417    movlhps\t%0, %0"
7418   [(set_attr "isa" "sse2,*")
7419    (set_attr "type" "sselog1,ssemov")
7420    (set_attr "mode" "TI,V4SF")])
7421
7422 (define_insn "*vec_concatv2si_sse4_1"
7423   [(set (match_operand:V2SI 0 "register_operand"     "=x, x,x,x, x, *y,*y")
7424         (vec_concat:V2SI
7425           (match_operand:SI 1 "nonimmediate_operand" " 0, x,0,x,rm,  0,rm")
7426           (match_operand:SI 2 "vector_move_operand"  "rm,rm,x,x, C,*ym, C")))]
7427   "TARGET_SSE4_1"
7428   "@
7429    pinsrd\t{$1, %2, %0|%0, %2, 1}
7430    vpinsrd\t{$1, %2, %1, %0|%0, %1, %2, 1}
7431    punpckldq\t{%2, %0|%0, %2}
7432    vpunpckldq\t{%2, %1, %0|%0, %1, %2}
7433    %vmovd\t{%1, %0|%0, %1}
7434    punpckldq\t{%2, %0|%0, %2}
7435    movd\t{%1, %0|%0, %1}"
7436   [(set_attr "isa" "noavx,avx,noavx,avx,*,*,*")
7437    (set_attr "type" "sselog,sselog,sselog,sselog,ssemov,mmxcvt,mmxmov")
7438    (set_attr "prefix_extra" "1,1,*,*,*,*,*")
7439    (set_attr "length_immediate" "1,1,*,*,*,*,*")
7440    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex,orig,orig")
7441    (set_attr "mode" "TI,TI,TI,TI,TI,DI,DI")])
7442
7443 ;; ??? In theory we can match memory for the MMX alternative, but allowing
7444 ;; nonimmediate_operand for operand 2 and *not* allowing memory for the SSE
7445 ;; alternatives pretty much forces the MMX alternative to be chosen.
7446 (define_insn "*vec_concatv2si_sse2"
7447   [(set (match_operand:V2SI 0 "register_operand"     "=x,x ,*y,*y")
7448         (vec_concat:V2SI
7449           (match_operand:SI 1 "nonimmediate_operand" " 0,rm, 0,rm")
7450           (match_operand:SI 2 "reg_or_0_operand"     " x,C ,*y, C")))]
7451   "TARGET_SSE2"
7452   "@
7453    punpckldq\t{%2, %0|%0, %2}
7454    movd\t{%1, %0|%0, %1}
7455    punpckldq\t{%2, %0|%0, %2}
7456    movd\t{%1, %0|%0, %1}"
7457   [(set_attr "type" "sselog,ssemov,mmxcvt,mmxmov")
7458    (set_attr "mode" "TI,TI,DI,DI")])
7459
7460 (define_insn "*vec_concatv2si_sse"
7461   [(set (match_operand:V2SI 0 "register_operand"     "=x,x,*y,*y")
7462         (vec_concat:V2SI
7463           (match_operand:SI 1 "nonimmediate_operand" " 0,m, 0,*rm")
7464           (match_operand:SI 2 "reg_or_0_operand"     " x,C,*y,C")))]
7465   "TARGET_SSE"
7466   "@
7467    unpcklps\t{%2, %0|%0, %2}
7468    movss\t{%1, %0|%0, %1}
7469    punpckldq\t{%2, %0|%0, %2}
7470    movd\t{%1, %0|%0, %1}"
7471   [(set_attr "type" "sselog,ssemov,mmxcvt,mmxmov")
7472    (set_attr "mode" "V4SF,V4SF,DI,DI")])
7473
7474 (define_insn "*vec_concatv4si"
7475   [(set (match_operand:V4SI 0 "register_operand"       "=x,x,x,x,x")
7476         (vec_concat:V4SI
7477           (match_operand:V2SI 1 "register_operand"     " 0,x,0,0,x")
7478           (match_operand:V2SI 2 "nonimmediate_operand" " x,x,x,m,m")))]
7479   "TARGET_SSE"
7480   "@
7481    punpcklqdq\t{%2, %0|%0, %2}
7482    vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}
7483    movlhps\t{%2, %0|%0, %2}
7484    movhps\t{%2, %0|%0, %2}
7485    vmovhps\t{%2, %1, %0|%0, %1, %2}"
7486   [(set_attr "isa" "sse2_noavx,avx,noavx,noavx,avx")
7487    (set_attr "type" "sselog,sselog,ssemov,ssemov,ssemov")
7488    (set_attr "prefix" "orig,vex,orig,orig,vex")
7489    (set_attr "mode" "TI,TI,V4SF,V2SF,V2SF")])
7490
7491 ;; movd instead of movq is required to handle broken assemblers.
7492 (define_insn "*vec_concatv2di_rex64"
7493   [(set (match_operand:V2DI 0 "register_operand"
7494           "=x,x ,x ,Yi,!x,x,x,x,x")
7495         (vec_concat:V2DI
7496           (match_operand:DI 1 "nonimmediate_operand"
7497           " 0,x ,xm,r ,*y,0,x,0,x")
7498           (match_operand:DI 2 "vector_move_operand"
7499           "rm,rm,C ,C ,C ,x,x,m,m")))]
7500   "TARGET_64BIT"
7501   "@
7502    pinsrq\t{$1, %2, %0|%0, %2, 1}
7503    vpinsrq\t{$1, %2, %1, %0|%0, %1, %2, 1}
7504    %vmovq\t{%1, %0|%0, %1}
7505    %vmovd\t{%1, %0|%0, %1}
7506    movq2dq\t{%1, %0|%0, %1}
7507    punpcklqdq\t{%2, %0|%0, %2}
7508    vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}
7509    movhps\t{%2, %0|%0, %2}
7510    vmovhps\t{%2, %1, %0|%0, %1, %2}"
7511   [(set_attr "isa" "sse4_noavx,avx,*,*,*,noavx,avx,noavx,avx")
7512    (set (attr "type")
7513      (if_then_else
7514        (eq_attr "alternative" "0,1,5,6")
7515        (const_string "sselog")
7516        (const_string "ssemov")))
7517    (set (attr "prefix_rex")
7518      (if_then_else
7519        (and (eq_attr "alternative" "0,3")
7520             (not (match_test "TARGET_AVX")))
7521        (const_string "1")
7522        (const_string "*")))
7523    (set_attr "prefix_extra" "1,1,*,*,*,*,*,*,*")
7524    (set_attr "length_immediate" "1,1,*,*,*,*,*,*,*")
7525    (set_attr "prefix" "orig,vex,maybe_vex,maybe_vex,orig,orig,vex,orig,vex")
7526    (set_attr "mode" "TI,TI,TI,TI,TI,TI,TI,V2SF,V2SF")])
7527
7528 (define_insn "vec_concatv2di"
7529   [(set (match_operand:V2DI 0 "register_operand"     "=x,?x,x,x,x,x,x")
7530         (vec_concat:V2DI
7531           (match_operand:DI 1 "nonimmediate_operand" "xm,*y,0,x,0,0,x")
7532           (match_operand:DI 2 "vector_move_operand"  " C, C,x,x,x,m,m")))]
7533   "!TARGET_64BIT && TARGET_SSE"
7534   "@
7535    %vmovq\t{%1, %0|%0, %1}
7536    movq2dq\t{%1, %0|%0, %1}
7537    punpcklqdq\t{%2, %0|%0, %2}
7538    vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}
7539    movlhps\t{%2, %0|%0, %2}
7540    movhps\t{%2, %0|%0, %2}
7541    vmovhps\t{%2, %1, %0|%0, %1, %2}"
7542   [(set_attr "isa" "sse2,sse2,sse2_noavx,avx,noavx,noavx,avx")
7543    (set_attr "type" "ssemov,ssemov,sselog,sselog,ssemov,ssemov,ssemov")
7544    (set_attr "prefix" "maybe_vex,orig,orig,vex,orig,orig,vex")
7545    (set_attr "mode" "TI,TI,TI,TI,V4SF,V2SF,V2SF")])
7546
7547 (define_expand "vec_unpacks_lo_<mode>"
7548   [(match_operand:<sseunpackmode> 0 "register_operand" "")
7549    (match_operand:VI124_AVX2 1 "register_operand" "")]
7550   "TARGET_SSE2"
7551   "ix86_expand_sse_unpack (operands, false, false); DONE;")
7552
7553 (define_expand "vec_unpacks_hi_<mode>"
7554   [(match_operand:<sseunpackmode> 0 "register_operand" "")
7555    (match_operand:VI124_AVX2 1 "register_operand" "")]
7556   "TARGET_SSE2"
7557   "ix86_expand_sse_unpack (operands, false, true); DONE;")
7558
7559 (define_expand "vec_unpacku_lo_<mode>"
7560   [(match_operand:<sseunpackmode> 0 "register_operand" "")
7561    (match_operand:VI124_AVX2 1 "register_operand" "")]
7562   "TARGET_SSE2"
7563   "ix86_expand_sse_unpack (operands, true, false); DONE;")
7564
7565 (define_expand "vec_unpacku_hi_<mode>"
7566   [(match_operand:<sseunpackmode> 0 "register_operand" "")
7567    (match_operand:VI124_AVX2 1 "register_operand" "")]
7568   "TARGET_SSE2"
7569   "ix86_expand_sse_unpack (operands, true, true); DONE;")
7570
7571 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7572 ;;
7573 ;; Miscellaneous
7574 ;;
7575 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7576
7577 (define_expand "avx2_uavgv32qi3"
7578   [(set (match_operand:V32QI 0 "register_operand" "")
7579         (truncate:V32QI
7580           (lshiftrt:V32HI
7581             (plus:V32HI
7582               (plus:V32HI
7583                 (zero_extend:V32HI
7584                   (match_operand:V32QI 1 "nonimmediate_operand" ""))
7585                 (zero_extend:V32HI
7586                   (match_operand:V32QI 2 "nonimmediate_operand" "")))
7587               (const_vector:V32QI [(const_int 1) (const_int 1)
7588                                    (const_int 1) (const_int 1)
7589                                    (const_int 1) (const_int 1)
7590                                    (const_int 1) (const_int 1)
7591                                    (const_int 1) (const_int 1)
7592                                    (const_int 1) (const_int 1)
7593                                    (const_int 1) (const_int 1)
7594                                    (const_int 1) (const_int 1)
7595                                    (const_int 1) (const_int 1)
7596                                    (const_int 1) (const_int 1)
7597                                    (const_int 1) (const_int 1)
7598                                    (const_int 1) (const_int 1)
7599                                    (const_int 1) (const_int 1)
7600                                    (const_int 1) (const_int 1)
7601                                    (const_int 1) (const_int 1)
7602                                    (const_int 1) (const_int 1)]))
7603             (const_int 1))))]
7604   "TARGET_AVX2"
7605   "ix86_fixup_binary_operands_no_copy (PLUS, V32QImode, operands);")
7606
7607 (define_expand "sse2_uavgv16qi3"
7608   [(set (match_operand:V16QI 0 "register_operand" "")
7609         (truncate:V16QI
7610           (lshiftrt:V16HI
7611             (plus:V16HI
7612               (plus:V16HI
7613                 (zero_extend:V16HI
7614                   (match_operand:V16QI 1 "nonimmediate_operand" ""))
7615                 (zero_extend:V16HI
7616                   (match_operand:V16QI 2 "nonimmediate_operand" "")))
7617               (const_vector:V16QI [(const_int 1) (const_int 1)
7618                                    (const_int 1) (const_int 1)
7619                                    (const_int 1) (const_int 1)
7620                                    (const_int 1) (const_int 1)
7621                                    (const_int 1) (const_int 1)
7622                                    (const_int 1) (const_int 1)
7623                                    (const_int 1) (const_int 1)
7624                                    (const_int 1) (const_int 1)]))
7625             (const_int 1))))]
7626   "TARGET_SSE2"
7627   "ix86_fixup_binary_operands_no_copy (PLUS, V16QImode, operands);")
7628
7629 (define_insn "*avx2_uavgv32qi3"
7630   [(set (match_operand:V32QI 0 "register_operand" "=x")
7631         (truncate:V32QI
7632           (lshiftrt:V32HI
7633             (plus:V32HI
7634               (plus:V32HI
7635                 (zero_extend:V32HI
7636                   (match_operand:V32QI 1 "nonimmediate_operand" "%x"))
7637                 (zero_extend:V32HI
7638                   (match_operand:V32QI 2 "nonimmediate_operand" "xm")))
7639               (const_vector:V32QI [(const_int 1) (const_int 1)
7640                                    (const_int 1) (const_int 1)
7641                                    (const_int 1) (const_int 1)
7642                                    (const_int 1) (const_int 1)
7643                                    (const_int 1) (const_int 1)
7644                                    (const_int 1) (const_int 1)
7645                                    (const_int 1) (const_int 1)
7646                                    (const_int 1) (const_int 1)
7647                                    (const_int 1) (const_int 1)
7648                                    (const_int 1) (const_int 1)
7649                                    (const_int 1) (const_int 1)
7650                                    (const_int 1) (const_int 1)
7651                                    (const_int 1) (const_int 1)
7652                                    (const_int 1) (const_int 1)
7653                                    (const_int 1) (const_int 1)
7654                                    (const_int 1) (const_int 1)]))
7655             (const_int 1))))]
7656   "TARGET_AVX2 && ix86_binary_operator_ok (PLUS, V32QImode, operands)"
7657   "vpavgb\t{%2, %1, %0|%0, %1, %2}"
7658   [(set_attr "type" "sseiadd")
7659    (set_attr "prefix" "vex")
7660    (set_attr "mode" "OI")])
7661
7662 (define_insn "*sse2_uavgv16qi3"
7663   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
7664         (truncate:V16QI
7665           (lshiftrt:V16HI
7666             (plus:V16HI
7667               (plus:V16HI
7668                 (zero_extend:V16HI
7669                   (match_operand:V16QI 1 "nonimmediate_operand" "%0,x"))
7670                 (zero_extend:V16HI
7671                   (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm")))
7672               (const_vector:V16QI [(const_int 1) (const_int 1)
7673                                    (const_int 1) (const_int 1)
7674                                    (const_int 1) (const_int 1)
7675                                    (const_int 1) (const_int 1)
7676                                    (const_int 1) (const_int 1)
7677                                    (const_int 1) (const_int 1)
7678                                    (const_int 1) (const_int 1)
7679                                    (const_int 1) (const_int 1)]))
7680             (const_int 1))))]
7681   "TARGET_SSE2 && ix86_binary_operator_ok (PLUS, V16QImode, operands)"
7682   "@
7683    pavgb\t{%2, %0|%0, %2}
7684    vpavgb\t{%2, %1, %0|%0, %1, %2}"
7685   [(set_attr "isa" "noavx,avx")
7686    (set_attr "type" "sseiadd")
7687    (set_attr "prefix_data16" "1,*")
7688    (set_attr "prefix" "orig,vex")
7689    (set_attr "mode" "TI")])
7690
7691 (define_expand "avx2_uavgv16hi3"
7692   [(set (match_operand:V16HI 0 "register_operand" "")
7693         (truncate:V16HI
7694           (lshiftrt:V16SI
7695             (plus:V16SI
7696               (plus:V16SI
7697                 (zero_extend:V16SI
7698                   (match_operand:V16HI 1 "nonimmediate_operand" ""))
7699                 (zero_extend:V16SI
7700                   (match_operand:V16HI 2 "nonimmediate_operand" "")))
7701               (const_vector:V16HI [(const_int 1) (const_int 1)
7702                                    (const_int 1) (const_int 1)
7703                                    (const_int 1) (const_int 1)
7704                                    (const_int 1) (const_int 1)
7705                                    (const_int 1) (const_int 1)
7706                                    (const_int 1) (const_int 1)
7707                                    (const_int 1) (const_int 1)
7708                                    (const_int 1) (const_int 1)]))
7709             (const_int 1))))]
7710   "TARGET_AVX2"
7711   "ix86_fixup_binary_operands_no_copy (PLUS, V16HImode, operands);")
7712
7713 (define_expand "sse2_uavgv8hi3"
7714   [(set (match_operand:V8HI 0 "register_operand" "")
7715         (truncate:V8HI
7716           (lshiftrt:V8SI
7717             (plus:V8SI
7718               (plus:V8SI
7719                 (zero_extend:V8SI
7720                   (match_operand:V8HI 1 "nonimmediate_operand" ""))
7721                 (zero_extend:V8SI
7722                   (match_operand:V8HI 2 "nonimmediate_operand" "")))
7723               (const_vector:V8HI [(const_int 1) (const_int 1)
7724                                   (const_int 1) (const_int 1)
7725                                   (const_int 1) (const_int 1)
7726                                   (const_int 1) (const_int 1)]))
7727             (const_int 1))))]
7728   "TARGET_SSE2"
7729   "ix86_fixup_binary_operands_no_copy (PLUS, V8HImode, operands);")
7730
7731 (define_insn "*avx2_uavgv16hi3"
7732   [(set (match_operand:V16HI 0 "register_operand" "=x")
7733         (truncate:V16HI
7734           (lshiftrt:V16SI
7735             (plus:V16SI
7736               (plus:V16SI
7737                 (zero_extend:V16SI
7738                   (match_operand:V16HI 1 "nonimmediate_operand" "%x"))
7739                 (zero_extend:V16SI
7740                   (match_operand:V16HI 2 "nonimmediate_operand" "xm")))
7741               (const_vector:V16HI [(const_int 1) (const_int 1)
7742                                    (const_int 1) (const_int 1)
7743                                    (const_int 1) (const_int 1)
7744                                    (const_int 1) (const_int 1)
7745                                    (const_int 1) (const_int 1)
7746                                    (const_int 1) (const_int 1)
7747                                    (const_int 1) (const_int 1)
7748                                    (const_int 1) (const_int 1)]))
7749             (const_int 1))))]
7750   "TARGET_AVX2 && ix86_binary_operator_ok (PLUS, V16HImode, operands)"
7751   "vpavgw\t{%2, %1, %0|%0, %1, %2}"
7752   [(set_attr "type" "sseiadd")
7753    (set_attr "prefix" "vex")
7754    (set_attr "mode" "OI")])
7755
7756 (define_insn "*sse2_uavgv8hi3"
7757   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
7758         (truncate:V8HI
7759           (lshiftrt:V8SI
7760             (plus:V8SI
7761               (plus:V8SI
7762                 (zero_extend:V8SI
7763                   (match_operand:V8HI 1 "nonimmediate_operand" "%0,x"))
7764                 (zero_extend:V8SI
7765                   (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")))
7766               (const_vector:V8HI [(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))))]
7771   "TARGET_SSE2 && ix86_binary_operator_ok (PLUS, V8HImode, operands)"
7772   "@
7773    pavgw\t{%2, %0|%0, %2}
7774    vpavgw\t{%2, %1, %0|%0, %1, %2}"
7775   [(set_attr "isa" "noavx,avx")
7776    (set_attr "type" "sseiadd")
7777    (set_attr "prefix_data16" "1,*")
7778    (set_attr "prefix" "orig,vex")
7779    (set_attr "mode" "TI")])
7780
7781 ;; The correct representation for this is absolutely enormous, and
7782 ;; surely not generally useful.
7783 (define_insn "<sse2_avx2>_psadbw"
7784   [(set (match_operand:VI8_AVX2 0 "register_operand" "=x,x")
7785         (unspec:VI8_AVX2 [(match_operand:<ssebytemode> 1 "register_operand" "0,x")
7786                           (match_operand:<ssebytemode> 2 "nonimmediate_operand" "xm,xm")]
7787                           UNSPEC_PSADBW))]
7788   "TARGET_SSE2"
7789   "@
7790    psadbw\t{%2, %0|%0, %2}
7791    vpsadbw\t{%2, %1, %0|%0, %1, %2}"
7792   [(set_attr "isa" "noavx,avx")
7793    (set_attr "type" "sseiadd")
7794    (set_attr "atom_unit" "simul")
7795    (set_attr "prefix_data16" "1,*")
7796    (set_attr "prefix" "orig,vex")
7797    (set_attr "mode" "<sseinsnmode>")])
7798
7799 (define_insn "<sse>_movmsk<ssemodesuffix><avxsizesuffix>"
7800   [(set (match_operand:SI 0 "register_operand" "=r")
7801         (unspec:SI
7802           [(match_operand:VF 1 "register_operand" "x")]
7803           UNSPEC_MOVMSK))]
7804   "TARGET_SSE"
7805   "%vmovmsk<ssemodesuffix>\t{%1, %0|%0, %1}"
7806   [(set_attr "type" "ssemov")
7807    (set_attr "prefix" "maybe_vex")
7808    (set_attr "mode" "<MODE>")])
7809
7810 (define_insn "avx2_pmovmskb"
7811   [(set (match_operand:SI 0 "register_operand" "=r")
7812         (unspec:SI [(match_operand:V32QI 1 "register_operand" "x")]
7813                    UNSPEC_MOVMSK))]
7814   "TARGET_AVX2"
7815   "vpmovmskb\t{%1, %0|%0, %1}"
7816   [(set_attr "type" "ssemov")
7817    (set_attr "prefix" "vex")
7818    (set_attr "mode" "DI")])
7819
7820 (define_insn "sse2_pmovmskb"
7821   [(set (match_operand:SI 0 "register_operand" "=r")
7822         (unspec:SI [(match_operand:V16QI 1 "register_operand" "x")]
7823                    UNSPEC_MOVMSK))]
7824   "TARGET_SSE2"
7825   "%vpmovmskb\t{%1, %0|%0, %1}"
7826   [(set_attr "type" "ssemov")
7827    (set_attr "prefix_data16" "1")
7828    (set_attr "prefix" "maybe_vex")
7829    (set_attr "mode" "SI")])
7830
7831 (define_expand "sse2_maskmovdqu"
7832   [(set (match_operand:V16QI 0 "memory_operand" "")
7833         (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "")
7834                        (match_operand:V16QI 2 "register_operand" "")
7835                        (match_dup 0)]
7836                       UNSPEC_MASKMOV))]
7837   "TARGET_SSE2")
7838
7839 (define_insn "*sse2_maskmovdqu"
7840   [(set (mem:V16QI (match_operand:P 0 "register_operand" "D"))
7841         (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "x")
7842                        (match_operand:V16QI 2 "register_operand" "x")
7843                        (mem:V16QI (match_dup 0))]
7844                       UNSPEC_MASKMOV))]
7845   "TARGET_SSE2"
7846   "%vmaskmovdqu\t{%2, %1|%1, %2}"
7847   [(set_attr "type" "ssemov")
7848    (set_attr "prefix_data16" "1")
7849    ;; The implicit %rdi operand confuses default length_vex computation.
7850    (set (attr "length_vex")
7851      (symbol_ref ("3 + REX_SSE_REGNO_P (REGNO (operands[2]))")))
7852    (set_attr "prefix" "maybe_vex")
7853    (set_attr "mode" "TI")])
7854
7855 (define_insn "sse_ldmxcsr"
7856   [(unspec_volatile [(match_operand:SI 0 "memory_operand" "m")]
7857                     UNSPECV_LDMXCSR)]
7858   "TARGET_SSE"
7859   "%vldmxcsr\t%0"
7860   [(set_attr "type" "sse")
7861    (set_attr "atom_sse_attr" "mxcsr")
7862    (set_attr "prefix" "maybe_vex")
7863    (set_attr "memory" "load")])
7864
7865 (define_insn "sse_stmxcsr"
7866   [(set (match_operand:SI 0 "memory_operand" "=m")
7867         (unspec_volatile:SI [(const_int 0)] UNSPECV_STMXCSR))]
7868   "TARGET_SSE"
7869   "%vstmxcsr\t%0"
7870   [(set_attr "type" "sse")
7871    (set_attr "atom_sse_attr" "mxcsr")
7872    (set_attr "prefix" "maybe_vex")
7873    (set_attr "memory" "store")])
7874
7875 (define_expand "sse_sfence"
7876   [(set (match_dup 0)
7877         (unspec:BLK [(match_dup 0)] UNSPEC_SFENCE))]
7878   "TARGET_SSE || TARGET_3DNOW_A"
7879 {
7880   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
7881   MEM_VOLATILE_P (operands[0]) = 1;
7882 })
7883
7884 (define_insn "*sse_sfence"
7885   [(set (match_operand:BLK 0 "" "")
7886         (unspec:BLK [(match_dup 0)] UNSPEC_SFENCE))]
7887   "TARGET_SSE || TARGET_3DNOW_A"
7888   "sfence"
7889   [(set_attr "type" "sse")
7890    (set_attr "length_address" "0")
7891    (set_attr "atom_sse_attr" "fence")
7892    (set_attr "memory" "unknown")])
7893
7894 (define_insn "sse2_clflush"
7895   [(unspec_volatile [(match_operand 0 "address_operand" "p")]
7896                     UNSPECV_CLFLUSH)]
7897   "TARGET_SSE2"
7898   "clflush\t%a0"
7899   [(set_attr "type" "sse")
7900    (set_attr "atom_sse_attr" "fence")
7901    (set_attr "memory" "unknown")])
7902
7903 (define_expand "sse2_mfence"
7904   [(set (match_dup 0)
7905         (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
7906   "TARGET_SSE2"
7907 {
7908   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
7909   MEM_VOLATILE_P (operands[0]) = 1;
7910 })
7911
7912 (define_insn "*sse2_mfence"
7913   [(set (match_operand:BLK 0 "" "")
7914         (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
7915   "TARGET_64BIT || TARGET_SSE2"
7916   "mfence"
7917   [(set_attr "type" "sse")
7918    (set_attr "length_address" "0")
7919    (set_attr "atom_sse_attr" "fence")
7920    (set_attr "memory" "unknown")])
7921
7922 (define_expand "sse2_lfence"
7923   [(set (match_dup 0)
7924         (unspec:BLK [(match_dup 0)] UNSPEC_LFENCE))]
7925   "TARGET_SSE2"
7926 {
7927   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
7928   MEM_VOLATILE_P (operands[0]) = 1;
7929 })
7930
7931 (define_insn "*sse2_lfence"
7932   [(set (match_operand:BLK 0 "" "")
7933         (unspec:BLK [(match_dup 0)] UNSPEC_LFENCE))]
7934   "TARGET_SSE2"
7935   "lfence"
7936   [(set_attr "type" "sse")
7937    (set_attr "length_address" "0")
7938    (set_attr "atom_sse_attr" "lfence")
7939    (set_attr "memory" "unknown")])
7940
7941 (define_insn "sse3_mwait"
7942   [(unspec_volatile [(match_operand:SI 0 "register_operand" "a")
7943                      (match_operand:SI 1 "register_operand" "c")]
7944                     UNSPECV_MWAIT)]
7945   "TARGET_SSE3"
7946 ;; 64bit version is "mwait %rax,%rcx". But only lower 32bits are used.
7947 ;; Since 32bit register operands are implicitly zero extended to 64bit,
7948 ;; we only need to set up 32bit registers.
7949   "mwait"
7950   [(set_attr "length" "3")])
7951
7952 (define_insn "sse3_monitor"
7953   [(unspec_volatile [(match_operand:SI 0 "register_operand" "a")
7954                      (match_operand:SI 1 "register_operand" "c")
7955                      (match_operand:SI 2 "register_operand" "d")]
7956                     UNSPECV_MONITOR)]
7957   "TARGET_SSE3 && !TARGET_64BIT"
7958   "monitor\t%0, %1, %2"
7959   [(set_attr "length" "3")])
7960
7961 (define_insn "sse3_monitor64"
7962   [(unspec_volatile [(match_operand:DI 0 "register_operand" "a")
7963                      (match_operand:SI 1 "register_operand" "c")
7964                      (match_operand:SI 2 "register_operand" "d")]
7965                     UNSPECV_MONITOR)]
7966   "TARGET_SSE3 && TARGET_64BIT"
7967 ;; 64bit version is "monitor %rax,%rcx,%rdx". But only lower 32bits in
7968 ;; RCX and RDX are used.  Since 32bit register operands are implicitly
7969 ;; zero extended to 64bit, we only need to set up 32bit registers.
7970   "monitor"
7971   [(set_attr "length" "3")])
7972
7973 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7974 ;;
7975 ;; SSSE3 instructions
7976 ;;
7977 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7978
7979 (define_insn "avx2_phaddwv16hi3"
7980   [(set (match_operand:V16HI 0 "register_operand" "=x")
7981         (vec_concat:V16HI
7982           (vec_concat:V8HI
7983             (vec_concat:V4HI
7984               (vec_concat:V2HI
7985                 (plus:HI
7986                   (vec_select:HI
7987                     (match_operand:V16HI 1 "register_operand" "x")
7988                     (parallel [(const_int 0)]))
7989                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
7990                 (plus:HI
7991                   (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
7992                   (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
7993               (vec_concat:V2HI
7994                 (plus:HI
7995                   (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
7996                   (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
7997                 (plus:HI
7998                   (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
7999                   (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8000             (vec_concat:V4HI
8001               (vec_concat:V2HI
8002                 (plus:HI
8003                   (vec_select:HI (match_dup 1) (parallel [(const_int 8)]))
8004                   (vec_select:HI (match_dup 1) (parallel [(const_int 9)])))
8005                 (plus:HI
8006                   (vec_select:HI (match_dup 1) (parallel [(const_int 10)]))
8007                   (vec_select:HI (match_dup 1) (parallel [(const_int 11)]))))
8008               (vec_concat:V2HI
8009                 (plus:HI
8010                   (vec_select:HI (match_dup 1) (parallel [(const_int 12)]))
8011                   (vec_select:HI (match_dup 1) (parallel [(const_int 13)])))
8012                 (plus:HI
8013                   (vec_select:HI (match_dup 1) (parallel [(const_int 14)]))
8014                   (vec_select:HI (match_dup 1) (parallel [(const_int 15)]))))))
8015           (vec_concat:V8HI
8016             (vec_concat:V4HI
8017               (vec_concat:V2HI
8018                 (plus:HI
8019                   (vec_select:HI
8020                     (match_operand:V16HI 2 "nonimmediate_operand" "xm")
8021                     (parallel [(const_int 0)]))
8022                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8023                 (plus:HI
8024                   (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8025                   (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8026               (vec_concat:V2HI
8027                 (plus:HI
8028                   (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8029                   (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8030                 (plus:HI
8031                   (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8032                   (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))
8033             (vec_concat:V4HI
8034               (vec_concat:V2HI
8035                 (plus:HI
8036                   (vec_select:HI (match_dup 2) (parallel [(const_int 8)]))
8037                   (vec_select:HI (match_dup 2) (parallel [(const_int 9)])))
8038                 (plus:HI
8039                   (vec_select:HI (match_dup 2) (parallel [(const_int 10)]))
8040                   (vec_select:HI (match_dup 2) (parallel [(const_int 11)]))))
8041               (vec_concat:V2HI
8042                 (plus:HI
8043                   (vec_select:HI (match_dup 2) (parallel [(const_int 12)]))
8044                   (vec_select:HI (match_dup 2) (parallel [(const_int 13)])))
8045                 (plus:HI
8046                   (vec_select:HI (match_dup 2) (parallel [(const_int 14)]))
8047                   (vec_select:HI (match_dup 2) (parallel [(const_int 15)]))))))))]
8048   "TARGET_AVX2"
8049   "vphaddw\t{%2, %1, %0|%0, %1, %2}"
8050   [(set_attr "type" "sseiadd")
8051    (set_attr "prefix_extra" "1")
8052    (set_attr "prefix" "vex")
8053    (set_attr "mode" "OI")])
8054
8055 (define_insn "ssse3_phaddwv8hi3"
8056   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
8057         (vec_concat:V8HI
8058           (vec_concat:V4HI
8059             (vec_concat:V2HI
8060               (plus:HI
8061                 (vec_select:HI
8062                   (match_operand:V8HI 1 "register_operand" "0,x")
8063                   (parallel [(const_int 0)]))
8064                 (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8065               (plus:HI
8066                 (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8067                 (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8068             (vec_concat:V2HI
8069               (plus:HI
8070                 (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8071                 (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8072               (plus:HI
8073                 (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8074                 (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8075           (vec_concat:V4HI
8076             (vec_concat:V2HI
8077               (plus:HI
8078                 (vec_select:HI
8079                   (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
8080                   (parallel [(const_int 0)]))
8081                 (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8082               (plus:HI
8083                 (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8084                 (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8085             (vec_concat:V2HI
8086               (plus:HI
8087                 (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8088                 (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8089               (plus:HI
8090                 (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8091                 (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))))]
8092   "TARGET_SSSE3"
8093   "@
8094    phaddw\t{%2, %0|%0, %2}
8095    vphaddw\t{%2, %1, %0|%0, %1, %2}"
8096   [(set_attr "isa" "noavx,avx")
8097    (set_attr "type" "sseiadd")
8098    (set_attr "atom_unit" "complex")
8099    (set_attr "prefix_data16" "1,*")
8100    (set_attr "prefix_extra" "1")
8101    (set_attr "prefix" "orig,vex")
8102    (set_attr "mode" "TI")])
8103
8104 (define_insn "ssse3_phaddwv4hi3"
8105   [(set (match_operand:V4HI 0 "register_operand" "=y")
8106         (vec_concat:V4HI
8107           (vec_concat:V2HI
8108             (plus:HI
8109               (vec_select:HI
8110                 (match_operand:V4HI 1 "register_operand" "0")
8111                 (parallel [(const_int 0)]))
8112               (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8113             (plus:HI
8114               (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8115               (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8116           (vec_concat:V2HI
8117             (plus:HI
8118               (vec_select:HI
8119                 (match_operand:V4HI 2 "nonimmediate_operand" "ym")
8120                 (parallel [(const_int 0)]))
8121               (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8122             (plus:HI
8123               (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8124               (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))))]
8125   "TARGET_SSSE3"
8126   "phaddw\t{%2, %0|%0, %2}"
8127   [(set_attr "type" "sseiadd")
8128    (set_attr "atom_unit" "complex")
8129    (set_attr "prefix_extra" "1")
8130    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8131    (set_attr "mode" "DI")])
8132
8133 (define_insn "avx2_phadddv8si3"
8134   [(set (match_operand:V8SI 0 "register_operand" "=x")
8135         (vec_concat:V8SI
8136           (vec_concat:V4SI
8137             (vec_concat:V2SI
8138               (plus:SI
8139                 (vec_select:SI
8140                   (match_operand:V8SI 1 "register_operand" "x")
8141                   (parallel [(const_int 0)]))
8142                 (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8143               (plus:SI
8144                 (vec_select:SI (match_dup 1) (parallel [(const_int 2)]))
8145                 (vec_select:SI (match_dup 1) (parallel [(const_int 3)]))))
8146             (vec_concat:V2SI
8147               (plus:SI
8148                 (vec_select:SI (match_dup 1) (parallel [(const_int 4)]))
8149                 (vec_select:SI (match_dup 1) (parallel [(const_int 5)])))
8150               (plus:SI
8151                 (vec_select:SI (match_dup 1) (parallel [(const_int 6)]))
8152                 (vec_select:SI (match_dup 1) (parallel [(const_int 7)])))))
8153           (vec_concat:V4SI
8154             (vec_concat:V2SI
8155               (plus:SI
8156                 (vec_select:SI
8157                   (match_operand:V8SI 2 "nonimmediate_operand" "xm")
8158                   (parallel [(const_int 0)]))
8159                 (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))
8160               (plus:SI
8161                 (vec_select:SI (match_dup 2) (parallel [(const_int 2)]))
8162                 (vec_select:SI (match_dup 2) (parallel [(const_int 3)]))))
8163             (vec_concat:V2SI
8164               (plus:SI
8165                 (vec_select:SI (match_dup 2) (parallel [(const_int 4)]))
8166                 (vec_select:SI (match_dup 2) (parallel [(const_int 5)])))
8167               (plus:SI
8168                 (vec_select:SI (match_dup 2) (parallel [(const_int 6)]))
8169                 (vec_select:SI (match_dup 2) (parallel [(const_int 7)])))))))]
8170   "TARGET_AVX2"
8171   "vphaddd\t{%2, %1, %0|%0, %1, %2}"
8172   [(set_attr "type" "sseiadd")
8173    (set_attr "prefix_extra" "1")
8174    (set_attr "prefix" "vex")
8175    (set_attr "mode" "OI")])
8176
8177 (define_insn "ssse3_phadddv4si3"
8178   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
8179         (vec_concat:V4SI
8180           (vec_concat:V2SI
8181             (plus:SI
8182               (vec_select:SI
8183                 (match_operand:V4SI 1 "register_operand" "0,x")
8184                 (parallel [(const_int 0)]))
8185               (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8186             (plus:SI
8187               (vec_select:SI (match_dup 1) (parallel [(const_int 2)]))
8188               (vec_select:SI (match_dup 1) (parallel [(const_int 3)]))))
8189           (vec_concat:V2SI
8190             (plus:SI
8191               (vec_select:SI
8192                 (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm")
8193                 (parallel [(const_int 0)]))
8194               (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))
8195             (plus:SI
8196               (vec_select:SI (match_dup 2) (parallel [(const_int 2)]))
8197               (vec_select:SI (match_dup 2) (parallel [(const_int 3)]))))))]
8198   "TARGET_SSSE3"
8199   "@
8200    phaddd\t{%2, %0|%0, %2}
8201    vphaddd\t{%2, %1, %0|%0, %1, %2}"
8202   [(set_attr "isa" "noavx,avx")
8203    (set_attr "type" "sseiadd")
8204    (set_attr "atom_unit" "complex")
8205    (set_attr "prefix_data16" "1,*")
8206    (set_attr "prefix_extra" "1")
8207    (set_attr "prefix" "orig,vex")
8208    (set_attr "mode" "TI")])
8209
8210 (define_insn "ssse3_phadddv2si3"
8211   [(set (match_operand:V2SI 0 "register_operand" "=y")
8212         (vec_concat:V2SI
8213           (plus:SI
8214             (vec_select:SI
8215               (match_operand:V2SI 1 "register_operand" "0")
8216               (parallel [(const_int 0)]))
8217             (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8218           (plus:SI
8219             (vec_select:SI
8220               (match_operand:V2SI 2 "nonimmediate_operand" "ym")
8221               (parallel [(const_int 0)]))
8222             (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))))]
8223   "TARGET_SSSE3"
8224   "phaddd\t{%2, %0|%0, %2}"
8225   [(set_attr "type" "sseiadd")
8226    (set_attr "atom_unit" "complex")
8227    (set_attr "prefix_extra" "1")
8228    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8229    (set_attr "mode" "DI")])
8230
8231 (define_insn "avx2_phaddswv16hi3"
8232   [(set (match_operand:V16HI 0 "register_operand" "=x")
8233         (vec_concat:V16HI
8234           (vec_concat:V8HI
8235             (vec_concat:V4HI
8236               (vec_concat:V2HI
8237                 (ss_plus:HI
8238                   (vec_select:HI
8239                     (match_operand:V16HI 1 "register_operand" "x")
8240                     (parallel [(const_int 0)]))
8241                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8242                 (ss_plus:HI
8243                   (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8244                   (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8245               (vec_concat:V2HI
8246                 (ss_plus:HI
8247                   (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8248                   (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8249                 (ss_plus:HI
8250                   (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8251                   (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8252             (vec_concat:V4HI
8253               (vec_concat:V2HI
8254                 (ss_plus:HI
8255                   (vec_select:HI (match_dup 1) (parallel [(const_int 8)]))
8256                   (vec_select:HI (match_dup 1) (parallel [(const_int 9)])))
8257                 (ss_plus:HI
8258                   (vec_select:HI (match_dup 1) (parallel [(const_int 10)]))
8259                   (vec_select:HI (match_dup 1) (parallel [(const_int 11)]))))
8260               (vec_concat:V2HI
8261                 (ss_plus:HI
8262                   (vec_select:HI (match_dup 1) (parallel [(const_int 12)]))
8263                   (vec_select:HI (match_dup 1) (parallel [(const_int 13)])))
8264                 (ss_plus:HI
8265                   (vec_select:HI (match_dup 1) (parallel [(const_int 14)]))
8266                   (vec_select:HI (match_dup 1) (parallel [(const_int 15)]))))))
8267           (vec_concat:V8HI
8268             (vec_concat:V4HI
8269               (vec_concat:V2HI
8270                 (ss_plus:HI
8271                   (vec_select:HI
8272                     (match_operand:V16HI 2 "nonimmediate_operand" "xm")
8273                     (parallel [(const_int 0)]))
8274                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8275                 (ss_plus:HI
8276                   (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8277                   (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8278               (vec_concat:V2HI
8279                 (ss_plus:HI
8280                   (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8281                   (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8282                 (ss_plus:HI
8283                   (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8284                   (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))
8285             (vec_concat:V4HI
8286               (vec_concat:V2HI
8287                 (ss_plus:HI
8288                   (vec_select:HI (match_dup 2) (parallel [(const_int 8)]))
8289                   (vec_select:HI (match_dup 2) (parallel [(const_int 9)])))
8290                 (ss_plus:HI
8291                   (vec_select:HI (match_dup 2) (parallel [(const_int 10)]))
8292                   (vec_select:HI (match_dup 2) (parallel [(const_int 11)]))))
8293               (vec_concat:V2HI
8294                 (ss_plus:HI
8295                   (vec_select:HI (match_dup 2) (parallel [(const_int 12)]))
8296                   (vec_select:HI (match_dup 2) (parallel [(const_int 13)])))
8297                 (ss_plus:HI
8298                   (vec_select:HI (match_dup 2) (parallel [(const_int 14)]))
8299                   (vec_select:HI (match_dup 2) (parallel [(const_int 15)]))))))))]
8300   "TARGET_AVX2"
8301   "vphaddsw\t{%2, %1, %0|%0, %1, %2}"
8302   [(set_attr "type" "sseiadd")
8303    (set_attr "prefix_extra" "1")
8304    (set_attr "prefix" "vex")
8305    (set_attr "mode" "OI")])
8306
8307 (define_insn "ssse3_phaddswv8hi3"
8308   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
8309         (vec_concat:V8HI
8310           (vec_concat:V4HI
8311             (vec_concat:V2HI
8312               (ss_plus:HI
8313                 (vec_select:HI
8314                   (match_operand:V8HI 1 "register_operand" "0,x")
8315                   (parallel [(const_int 0)]))
8316                 (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8317               (ss_plus:HI
8318                 (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8319                 (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8320             (vec_concat:V2HI
8321               (ss_plus:HI
8322                 (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8323                 (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8324               (ss_plus:HI
8325                 (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8326                 (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8327           (vec_concat:V4HI
8328             (vec_concat:V2HI
8329               (ss_plus:HI
8330                 (vec_select:HI
8331                   (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
8332                   (parallel [(const_int 0)]))
8333                 (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8334               (ss_plus:HI
8335                 (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8336                 (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8337             (vec_concat:V2HI
8338               (ss_plus:HI
8339                 (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8340                 (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8341               (ss_plus:HI
8342                 (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8343                 (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))))]
8344   "TARGET_SSSE3"
8345   "@
8346    phaddsw\t{%2, %0|%0, %2}
8347    vphaddsw\t{%2, %1, %0|%0, %1, %2}"
8348   [(set_attr "isa" "noavx,avx")
8349    (set_attr "type" "sseiadd")
8350    (set_attr "atom_unit" "complex")
8351    (set_attr "prefix_data16" "1,*")
8352    (set_attr "prefix_extra" "1")
8353    (set_attr "prefix" "orig,vex")
8354    (set_attr "mode" "TI")])
8355
8356 (define_insn "ssse3_phaddswv4hi3"
8357   [(set (match_operand:V4HI 0 "register_operand" "=y")
8358         (vec_concat:V4HI
8359           (vec_concat:V2HI
8360             (ss_plus:HI
8361               (vec_select:HI
8362                 (match_operand:V4HI 1 "register_operand" "0")
8363                 (parallel [(const_int 0)]))
8364               (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8365             (ss_plus:HI
8366               (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8367               (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8368           (vec_concat:V2HI
8369             (ss_plus:HI
8370               (vec_select:HI
8371                 (match_operand:V4HI 2 "nonimmediate_operand" "ym")
8372                 (parallel [(const_int 0)]))
8373               (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8374             (ss_plus:HI
8375               (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8376               (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))))]
8377   "TARGET_SSSE3"
8378   "phaddsw\t{%2, %0|%0, %2}"
8379   [(set_attr "type" "sseiadd")
8380    (set_attr "atom_unit" "complex")
8381    (set_attr "prefix_extra" "1")
8382    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8383    (set_attr "mode" "DI")])
8384
8385 (define_insn "avx2_phsubwv16hi3"
8386   [(set (match_operand:V16HI 0 "register_operand" "=x")
8387         (vec_concat:V16HI
8388           (vec_concat:V8HI
8389             (vec_concat:V4HI
8390               (vec_concat:V2HI
8391                 (minus:HI
8392                   (vec_select:HI
8393                     (match_operand:V16HI 1 "register_operand" "x")
8394                     (parallel [(const_int 0)]))
8395                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8396                 (minus:HI
8397                   (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8398                   (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8399               (vec_concat:V2HI
8400                 (minus:HI
8401                   (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8402                   (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8403                 (minus:HI
8404                   (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8405                   (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8406             (vec_concat:V4HI
8407               (vec_concat:V2HI
8408                 (minus:HI
8409                   (vec_select:HI (match_dup 1) (parallel [(const_int 8)]))
8410                   (vec_select:HI (match_dup 1) (parallel [(const_int 9)])))
8411                 (minus:HI
8412                   (vec_select:HI (match_dup 1) (parallel [(const_int 10)]))
8413                   (vec_select:HI (match_dup 1) (parallel [(const_int 11)]))))
8414               (vec_concat:V2HI
8415                 (minus:HI
8416                   (vec_select:HI (match_dup 1) (parallel [(const_int 12)]))
8417                   (vec_select:HI (match_dup 1) (parallel [(const_int 13)])))
8418                 (minus:HI
8419                   (vec_select:HI (match_dup 1) (parallel [(const_int 14)]))
8420                   (vec_select:HI (match_dup 1) (parallel [(const_int 15)]))))))
8421           (vec_concat:V8HI
8422             (vec_concat:V4HI
8423               (vec_concat:V2HI
8424                 (minus:HI
8425                   (vec_select:HI
8426                     (match_operand:V16HI 2 "nonimmediate_operand" "xm")
8427                     (parallel [(const_int 0)]))
8428                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8429                 (minus:HI
8430                   (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8431                   (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8432               (vec_concat:V2HI
8433                 (minus:HI
8434                   (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8435                   (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8436                 (minus:HI
8437                   (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8438                   (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))
8439             (vec_concat:V4HI
8440               (vec_concat:V2HI
8441                 (minus:HI
8442                   (vec_select:HI (match_dup 2) (parallel [(const_int 8)]))
8443                   (vec_select:HI (match_dup 2) (parallel [(const_int 9)])))
8444                 (minus:HI
8445                   (vec_select:HI (match_dup 2) (parallel [(const_int 10)]))
8446                   (vec_select:HI (match_dup 2) (parallel [(const_int 11)]))))
8447               (vec_concat:V2HI
8448                 (minus:HI
8449                   (vec_select:HI (match_dup 2) (parallel [(const_int 12)]))
8450                   (vec_select:HI (match_dup 2) (parallel [(const_int 13)])))
8451                 (minus:HI
8452                   (vec_select:HI (match_dup 2) (parallel [(const_int 14)]))
8453                   (vec_select:HI (match_dup 2) (parallel [(const_int 15)]))))))))]
8454   "TARGET_AVX2"
8455   "vphsubw\t{%2, %1, %0|%0, %1, %2}"
8456   [(set_attr "type" "sseiadd")
8457    (set_attr "prefix_extra" "1")
8458    (set_attr "prefix" "vex")
8459    (set_attr "mode" "OI")])
8460
8461 (define_insn "ssse3_phsubwv8hi3"
8462   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
8463         (vec_concat:V8HI
8464           (vec_concat:V4HI
8465             (vec_concat:V2HI
8466               (minus:HI
8467                 (vec_select:HI
8468                   (match_operand:V8HI 1 "register_operand" "0,x")
8469                   (parallel [(const_int 0)]))
8470                 (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8471               (minus:HI
8472                 (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8473                 (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8474             (vec_concat:V2HI
8475               (minus:HI
8476                 (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8477                 (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8478               (minus:HI
8479                 (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8480                 (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8481           (vec_concat:V4HI
8482             (vec_concat:V2HI
8483               (minus:HI
8484                 (vec_select:HI
8485                   (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
8486                   (parallel [(const_int 0)]))
8487                 (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8488               (minus:HI
8489                 (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8490                 (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8491             (vec_concat:V2HI
8492               (minus:HI
8493                 (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8494                 (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8495               (minus:HI
8496                 (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8497                 (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))))]
8498   "TARGET_SSSE3"
8499   "@
8500    phsubw\t{%2, %0|%0, %2}
8501    vphsubw\t{%2, %1, %0|%0, %1, %2}"
8502   [(set_attr "isa" "noavx,avx")
8503    (set_attr "type" "sseiadd")
8504    (set_attr "atom_unit" "complex")
8505    (set_attr "prefix_data16" "1,*")
8506    (set_attr "prefix_extra" "1")
8507    (set_attr "prefix" "orig,vex")
8508    (set_attr "mode" "TI")])
8509
8510 (define_insn "ssse3_phsubwv4hi3"
8511   [(set (match_operand:V4HI 0 "register_operand" "=y")
8512         (vec_concat:V4HI
8513           (vec_concat:V2HI
8514             (minus:HI
8515               (vec_select:HI
8516                 (match_operand:V4HI 1 "register_operand" "0")
8517                 (parallel [(const_int 0)]))
8518               (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8519             (minus:HI
8520               (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8521               (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8522           (vec_concat:V2HI
8523             (minus:HI
8524               (vec_select:HI
8525                 (match_operand:V4HI 2 "nonimmediate_operand" "ym")
8526                 (parallel [(const_int 0)]))
8527               (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8528             (minus:HI
8529               (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8530               (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))))]
8531   "TARGET_SSSE3"
8532   "phsubw\t{%2, %0|%0, %2}"
8533   [(set_attr "type" "sseiadd")
8534    (set_attr "atom_unit" "complex")
8535    (set_attr "prefix_extra" "1")
8536    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8537    (set_attr "mode" "DI")])
8538
8539 (define_insn "avx2_phsubdv8si3"
8540   [(set (match_operand:V8SI 0 "register_operand" "=x")
8541         (vec_concat:V8SI
8542           (vec_concat:V4SI
8543             (vec_concat:V2SI
8544               (minus:SI
8545                 (vec_select:SI
8546                   (match_operand:V8SI 1 "register_operand" "x")
8547                   (parallel [(const_int 0)]))
8548                 (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8549               (minus:SI
8550                 (vec_select:SI (match_dup 1) (parallel [(const_int 2)]))
8551                 (vec_select:SI (match_dup 1) (parallel [(const_int 3)]))))
8552             (vec_concat:V2SI
8553               (minus:SI
8554                 (vec_select:SI (match_dup 1) (parallel [(const_int 4)]))
8555                 (vec_select:SI (match_dup 1) (parallel [(const_int 5)])))
8556               (minus:SI
8557                 (vec_select:SI (match_dup 1) (parallel [(const_int 6)]))
8558                 (vec_select:SI (match_dup 1) (parallel [(const_int 7)])))))
8559           (vec_concat:V4SI
8560             (vec_concat:V2SI
8561               (minus:SI
8562                 (vec_select:SI
8563                   (match_operand:V8SI 2 "nonimmediate_operand" "xm")
8564                   (parallel [(const_int 0)]))
8565                 (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))
8566               (minus:SI
8567                 (vec_select:SI (match_dup 2) (parallel [(const_int 2)]))
8568                 (vec_select:SI (match_dup 2) (parallel [(const_int 3)]))))
8569             (vec_concat:V2SI
8570               (minus:SI
8571                 (vec_select:SI (match_dup 2) (parallel [(const_int 4)]))
8572                 (vec_select:SI (match_dup 2) (parallel [(const_int 5)])))
8573               (minus:SI
8574                 (vec_select:SI (match_dup 2) (parallel [(const_int 6)]))
8575                 (vec_select:SI (match_dup 2) (parallel [(const_int 7)])))))))]
8576   "TARGET_AVX2"
8577   "vphsubd\t{%2, %1, %0|%0, %1, %2}"
8578   [(set_attr "type" "sseiadd")
8579    (set_attr "prefix_extra" "1")
8580    (set_attr "prefix" "vex")
8581    (set_attr "mode" "OI")])
8582
8583 (define_insn "ssse3_phsubdv4si3"
8584   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
8585         (vec_concat:V4SI
8586           (vec_concat:V2SI
8587             (minus:SI
8588               (vec_select:SI
8589                 (match_operand:V4SI 1 "register_operand" "0,x")
8590                 (parallel [(const_int 0)]))
8591               (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8592             (minus:SI
8593               (vec_select:SI (match_dup 1) (parallel [(const_int 2)]))
8594               (vec_select:SI (match_dup 1) (parallel [(const_int 3)]))))
8595           (vec_concat:V2SI
8596             (minus:SI
8597               (vec_select:SI
8598                 (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm")
8599                 (parallel [(const_int 0)]))
8600               (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))
8601             (minus:SI
8602               (vec_select:SI (match_dup 2) (parallel [(const_int 2)]))
8603               (vec_select:SI (match_dup 2) (parallel [(const_int 3)]))))))]
8604   "TARGET_SSSE3"
8605   "@
8606    phsubd\t{%2, %0|%0, %2}
8607    vphsubd\t{%2, %1, %0|%0, %1, %2}"
8608
8609   [(set_attr "isa" "noavx,avx")
8610    (set_attr "type" "sseiadd")
8611    (set_attr "atom_unit" "complex")
8612    (set_attr "prefix_data16" "1,*")
8613    (set_attr "prefix_extra" "1")
8614    (set_attr "prefix" "orig,vex")
8615    (set_attr "mode" "TI")])
8616
8617 (define_insn "ssse3_phsubdv2si3"
8618   [(set (match_operand:V2SI 0 "register_operand" "=y")
8619         (vec_concat:V2SI
8620           (minus:SI
8621             (vec_select:SI
8622               (match_operand:V2SI 1 "register_operand" "0")
8623               (parallel [(const_int 0)]))
8624             (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8625           (minus:SI
8626             (vec_select:SI
8627               (match_operand:V2SI 2 "nonimmediate_operand" "ym")
8628               (parallel [(const_int 0)]))
8629             (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))))]
8630   "TARGET_SSSE3"
8631   "phsubd\t{%2, %0|%0, %2}"
8632   [(set_attr "type" "sseiadd")
8633    (set_attr "atom_unit" "complex")
8634    (set_attr "prefix_extra" "1")
8635    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8636    (set_attr "mode" "DI")])
8637
8638 (define_insn "avx2_phsubswv16hi3"
8639   [(set (match_operand:V16HI 0 "register_operand" "=x")
8640         (vec_concat:V16HI
8641           (vec_concat:V8HI
8642             (vec_concat:V4HI
8643               (vec_concat:V2HI
8644                 (ss_minus:HI
8645                   (vec_select:HI
8646                     (match_operand:V16HI 1 "register_operand" "x")
8647                     (parallel [(const_int 0)]))
8648                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8649                 (ss_minus:HI
8650                   (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8651                   (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8652               (vec_concat:V2HI
8653                 (ss_minus:HI
8654                   (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8655                   (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8656                 (ss_minus:HI
8657                   (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8658                   (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8659             (vec_concat:V4HI
8660               (vec_concat:V2HI
8661                 (ss_minus:HI
8662                   (vec_select:HI (match_dup 1) (parallel [(const_int 8)]))
8663                   (vec_select:HI (match_dup 1) (parallel [(const_int 9)])))
8664                 (ss_minus:HI
8665                   (vec_select:HI (match_dup 1) (parallel [(const_int 10)]))
8666                   (vec_select:HI (match_dup 1) (parallel [(const_int 11)]))))
8667               (vec_concat:V2HI
8668                 (ss_minus:HI
8669                   (vec_select:HI (match_dup 1) (parallel [(const_int 12)]))
8670                   (vec_select:HI (match_dup 1) (parallel [(const_int 13)])))
8671                 (ss_minus:HI
8672                   (vec_select:HI (match_dup 1) (parallel [(const_int 14)]))
8673                   (vec_select:HI (match_dup 1) (parallel [(const_int 15)]))))))
8674           (vec_concat:V8HI
8675             (vec_concat:V4HI
8676               (vec_concat:V2HI
8677                 (ss_minus:HI
8678                   (vec_select:HI
8679                     (match_operand:V16HI 2 "nonimmediate_operand" "xm")
8680                     (parallel [(const_int 0)]))
8681                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8682                 (ss_minus:HI
8683                   (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8684                   (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8685               (vec_concat:V2HI
8686                 (ss_minus:HI
8687                   (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8688                   (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8689                 (ss_minus:HI
8690                   (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8691                   (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))
8692             (vec_concat:V4HI
8693               (vec_concat:V2HI
8694                 (ss_minus:HI
8695                   (vec_select:HI (match_dup 2) (parallel [(const_int 8)]))
8696                   (vec_select:HI (match_dup 2) (parallel [(const_int 9)])))
8697                 (ss_minus:HI
8698                   (vec_select:HI (match_dup 2) (parallel [(const_int 10)]))
8699                   (vec_select:HI (match_dup 2) (parallel [(const_int 11)]))))
8700               (vec_concat:V2HI
8701                 (ss_minus:HI
8702                   (vec_select:HI (match_dup 2) (parallel [(const_int 12)]))
8703                   (vec_select:HI (match_dup 2) (parallel [(const_int 13)])))
8704                 (ss_minus:HI
8705                   (vec_select:HI (match_dup 2) (parallel [(const_int 14)]))
8706                   (vec_select:HI (match_dup 2) (parallel [(const_int 15)]))))))))]
8707   "TARGET_AVX2"
8708   "vphsubsw\t{%2, %1, %0|%0, %1, %2}"
8709   [(set_attr "type" "sseiadd")
8710    (set_attr "prefix_extra" "1")
8711    (set_attr "prefix" "vex")
8712    (set_attr "mode" "OI")])
8713
8714 (define_insn "ssse3_phsubswv8hi3"
8715   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
8716         (vec_concat:V8HI
8717           (vec_concat:V4HI
8718             (vec_concat:V2HI
8719               (ss_minus:HI
8720                 (vec_select:HI
8721                   (match_operand:V8HI 1 "register_operand" "0,x")
8722                   (parallel [(const_int 0)]))
8723                 (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8724               (ss_minus:HI
8725                 (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8726                 (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8727             (vec_concat:V2HI
8728               (ss_minus:HI
8729                 (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8730                 (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8731               (ss_minus:HI
8732                 (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8733                 (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8734           (vec_concat:V4HI
8735             (vec_concat:V2HI
8736               (ss_minus:HI
8737                 (vec_select:HI
8738                   (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
8739                   (parallel [(const_int 0)]))
8740                 (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8741               (ss_minus:HI
8742                 (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8743                 (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8744             (vec_concat:V2HI
8745               (ss_minus:HI
8746                 (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8747                 (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8748               (ss_minus:HI
8749                 (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8750                 (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))))]
8751   "TARGET_SSSE3"
8752   "@
8753    phsubsw\t{%2, %0|%0, %2}
8754    vphsubsw\t{%2, %1, %0|%0, %1, %2}"
8755   [(set_attr "isa" "noavx,avx")
8756    (set_attr "type" "sseiadd")
8757    (set_attr "atom_unit" "complex")
8758    (set_attr "prefix_data16" "1,*")
8759    (set_attr "prefix_extra" "1")
8760    (set_attr "prefix" "orig,vex")
8761    (set_attr "mode" "TI")])
8762
8763 (define_insn "ssse3_phsubswv4hi3"
8764   [(set (match_operand:V4HI 0 "register_operand" "=y")
8765         (vec_concat:V4HI
8766           (vec_concat:V2HI
8767             (ss_minus:HI
8768               (vec_select:HI
8769                 (match_operand:V4HI 1 "register_operand" "0")
8770                 (parallel [(const_int 0)]))
8771               (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8772             (ss_minus:HI
8773               (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8774               (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8775           (vec_concat:V2HI
8776             (ss_minus:HI
8777               (vec_select:HI
8778                 (match_operand:V4HI 2 "nonimmediate_operand" "ym")
8779                 (parallel [(const_int 0)]))
8780               (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8781             (ss_minus:HI
8782               (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8783               (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))))]
8784   "TARGET_SSSE3"
8785   "phsubsw\t{%2, %0|%0, %2}"
8786   [(set_attr "type" "sseiadd")
8787    (set_attr "atom_unit" "complex")
8788    (set_attr "prefix_extra" "1")
8789    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8790    (set_attr "mode" "DI")])
8791
8792 (define_insn "avx2_pmaddubsw256"
8793   [(set (match_operand:V16HI 0 "register_operand" "=x")
8794         (ss_plus:V16HI
8795           (mult:V16HI
8796             (zero_extend:V16HI
8797               (vec_select:V16QI
8798                 (match_operand:V32QI 1 "register_operand" "x")
8799                 (parallel [(const_int 0)
8800                            (const_int 2)
8801                            (const_int 4)
8802                            (const_int 6)
8803                            (const_int 8)
8804                            (const_int 10)
8805                            (const_int 12)
8806                            (const_int 14)
8807                            (const_int 16)
8808                            (const_int 18)
8809                            (const_int 20)
8810                            (const_int 22)
8811                            (const_int 24)
8812                            (const_int 26)
8813                            (const_int 28)
8814                            (const_int 30)])))
8815             (sign_extend:V16HI
8816               (vec_select:V16QI
8817                 (match_operand:V32QI 2 "nonimmediate_operand" "xm")
8818                 (parallel [(const_int 0)
8819                            (const_int 2)
8820                            (const_int 4)
8821                            (const_int 6)
8822                            (const_int 8)
8823                            (const_int 10)
8824                            (const_int 12)
8825                            (const_int 14)
8826                            (const_int 16)
8827                            (const_int 18)
8828                            (const_int 20)
8829                            (const_int 22)
8830                            (const_int 24)
8831                            (const_int 26)
8832                            (const_int 28)
8833                            (const_int 30)]))))
8834           (mult:V16HI
8835             (zero_extend:V16HI
8836               (vec_select:V16QI (match_dup 1)
8837                 (parallel [(const_int 1)
8838                            (const_int 3)
8839                            (const_int 5)
8840                            (const_int 7)
8841                            (const_int 9)
8842                            (const_int 11)
8843                            (const_int 13)
8844                            (const_int 15)
8845                            (const_int 17)
8846                            (const_int 19)
8847                            (const_int 21)
8848                            (const_int 23)
8849                            (const_int 25)
8850                            (const_int 27)
8851                            (const_int 29)
8852                            (const_int 31)])))
8853             (sign_extend:V16HI
8854               (vec_select:V16QI (match_dup 2)
8855                 (parallel [(const_int 1)
8856                            (const_int 3)
8857                            (const_int 5)
8858                            (const_int 7)
8859                            (const_int 9)
8860                            (const_int 11)
8861                            (const_int 13)
8862                            (const_int 15)
8863                            (const_int 17)
8864                            (const_int 19)
8865                            (const_int 21)
8866                            (const_int 23)
8867                            (const_int 25)
8868                            (const_int 27)
8869                            (const_int 29)
8870                            (const_int 31)]))))))]
8871   "TARGET_AVX2"
8872   "vpmaddubsw\t{%2, %1, %0|%0, %1, %2}"
8873   [(set_attr "type" "sseiadd")
8874    (set_attr "prefix_extra" "1")
8875    (set_attr "prefix" "vex")
8876    (set_attr "mode" "OI")])
8877
8878 (define_insn "ssse3_pmaddubsw128"
8879   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
8880         (ss_plus:V8HI
8881           (mult:V8HI
8882             (zero_extend:V8HI
8883               (vec_select:V8QI
8884                 (match_operand:V16QI 1 "register_operand" "0,x")
8885                 (parallel [(const_int 0)
8886                            (const_int 2)
8887                            (const_int 4)
8888                            (const_int 6)
8889                            (const_int 8)
8890                            (const_int 10)
8891                            (const_int 12)
8892                            (const_int 14)])))
8893             (sign_extend:V8HI
8894               (vec_select:V8QI
8895                 (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm")
8896                 (parallel [(const_int 0)
8897                            (const_int 2)
8898                            (const_int 4)
8899                            (const_int 6)
8900                            (const_int 8)
8901                            (const_int 10)
8902                            (const_int 12)
8903                            (const_int 14)]))))
8904           (mult:V8HI
8905             (zero_extend:V8HI
8906               (vec_select:V8QI (match_dup 1)
8907                 (parallel [(const_int 1)
8908                            (const_int 3)
8909                            (const_int 5)
8910                            (const_int 7)
8911                            (const_int 9)
8912                            (const_int 11)
8913                            (const_int 13)
8914                            (const_int 15)])))
8915             (sign_extend:V8HI
8916               (vec_select:V8QI (match_dup 2)
8917                 (parallel [(const_int 1)
8918                            (const_int 3)
8919                            (const_int 5)
8920                            (const_int 7)
8921                            (const_int 9)
8922                            (const_int 11)
8923                            (const_int 13)
8924                            (const_int 15)]))))))]
8925   "TARGET_SSSE3"
8926   "@
8927    pmaddubsw\t{%2, %0|%0, %2}
8928    vpmaddubsw\t{%2, %1, %0|%0, %1, %2}"
8929   [(set_attr "isa" "noavx,avx")
8930    (set_attr "type" "sseiadd")
8931    (set_attr "atom_unit" "simul")
8932    (set_attr "prefix_data16" "1,*")
8933    (set_attr "prefix_extra" "1")
8934    (set_attr "prefix" "orig,vex")
8935    (set_attr "mode" "TI")])
8936
8937 (define_insn "ssse3_pmaddubsw"
8938   [(set (match_operand:V4HI 0 "register_operand" "=y")
8939         (ss_plus:V4HI
8940           (mult:V4HI
8941             (zero_extend:V4HI
8942               (vec_select:V4QI
8943                 (match_operand:V8QI 1 "register_operand" "0")
8944                 (parallel [(const_int 0)
8945                            (const_int 2)
8946                            (const_int 4)
8947                            (const_int 6)])))
8948             (sign_extend:V4HI
8949               (vec_select:V4QI
8950                 (match_operand:V8QI 2 "nonimmediate_operand" "ym")
8951                 (parallel [(const_int 0)
8952                            (const_int 2)
8953                            (const_int 4)
8954                            (const_int 6)]))))
8955           (mult:V4HI
8956             (zero_extend:V4HI
8957               (vec_select:V4QI (match_dup 1)
8958                 (parallel [(const_int 1)
8959                            (const_int 3)
8960                            (const_int 5)
8961                            (const_int 7)])))
8962             (sign_extend:V4HI
8963               (vec_select:V4QI (match_dup 2)
8964                 (parallel [(const_int 1)
8965                            (const_int 3)
8966                            (const_int 5)
8967                            (const_int 7)]))))))]
8968   "TARGET_SSSE3"
8969   "pmaddubsw\t{%2, %0|%0, %2}"
8970   [(set_attr "type" "sseiadd")
8971    (set_attr "atom_unit" "simul")
8972    (set_attr "prefix_extra" "1")
8973    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8974    (set_attr "mode" "DI")])
8975
8976 (define_expand "avx2_umulhrswv16hi3"
8977   [(set (match_operand:V16HI 0 "register_operand" "")
8978         (truncate:V16HI
8979           (lshiftrt:V16SI
8980             (plus:V16SI
8981               (lshiftrt:V16SI
8982                 (mult:V16SI
8983                   (sign_extend:V16SI
8984                     (match_operand:V16HI 1 "nonimmediate_operand" ""))
8985                   (sign_extend:V16SI
8986                     (match_operand:V16HI 2 "nonimmediate_operand" "")))
8987                 (const_int 14))
8988               (const_vector:V16HI [(const_int 1) (const_int 1)
8989                                    (const_int 1) (const_int 1)
8990                                    (const_int 1) (const_int 1)
8991                                    (const_int 1) (const_int 1)
8992                                    (const_int 1) (const_int 1)
8993                                    (const_int 1) (const_int 1)
8994                                    (const_int 1) (const_int 1)
8995                                    (const_int 1) (const_int 1)]))
8996             (const_int 1))))]
8997   "TARGET_AVX2"
8998   "ix86_fixup_binary_operands_no_copy (MULT, V16HImode, operands);")
8999
9000 (define_insn "*avx2_umulhrswv16hi3"
9001   [(set (match_operand:V16HI 0 "register_operand" "=x")
9002         (truncate:V16HI
9003           (lshiftrt:V16SI
9004             (plus:V16SI
9005               (lshiftrt:V16SI
9006                 (mult:V16SI
9007                   (sign_extend:V16SI
9008                     (match_operand:V16HI 1 "nonimmediate_operand" "%x"))
9009                   (sign_extend:V16SI
9010                     (match_operand:V16HI 2 "nonimmediate_operand" "xm")))
9011                 (const_int 14))
9012               (const_vector:V16HI [(const_int 1) (const_int 1)
9013                                    (const_int 1) (const_int 1)
9014                                    (const_int 1) (const_int 1)
9015                                    (const_int 1) (const_int 1)
9016                                    (const_int 1) (const_int 1)
9017                                    (const_int 1) (const_int 1)
9018                                    (const_int 1) (const_int 1)
9019                                    (const_int 1) (const_int 1)]))
9020             (const_int 1))))]
9021   "TARGET_AVX2 && ix86_binary_operator_ok (MULT, V16HImode, operands)"
9022   "vpmulhrsw\t{%2, %1, %0|%0, %1, %2}"
9023   [(set_attr "type" "sseimul")
9024    (set_attr "prefix_extra" "1")
9025    (set_attr "prefix" "vex")
9026    (set_attr "mode" "OI")])
9027
9028 (define_expand "ssse3_pmulhrswv8hi3"
9029   [(set (match_operand:V8HI 0 "register_operand" "")
9030         (truncate:V8HI
9031           (lshiftrt:V8SI
9032             (plus:V8SI
9033               (lshiftrt:V8SI
9034                 (mult:V8SI
9035                   (sign_extend:V8SI
9036                     (match_operand:V8HI 1 "nonimmediate_operand" ""))
9037                   (sign_extend:V8SI
9038                     (match_operand:V8HI 2 "nonimmediate_operand" "")))
9039                 (const_int 14))
9040               (const_vector:V8HI [(const_int 1) (const_int 1)
9041                                   (const_int 1) (const_int 1)
9042                                   (const_int 1) (const_int 1)
9043                                   (const_int 1) (const_int 1)]))
9044             (const_int 1))))]
9045   "TARGET_SSSE3"
9046   "ix86_fixup_binary_operands_no_copy (MULT, V8HImode, operands);")
9047
9048 (define_insn "*ssse3_pmulhrswv8hi3"
9049   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
9050         (truncate:V8HI
9051           (lshiftrt:V8SI
9052             (plus:V8SI
9053               (lshiftrt:V8SI
9054                 (mult:V8SI
9055                   (sign_extend:V8SI
9056                     (match_operand:V8HI 1 "nonimmediate_operand" "%0,x"))
9057                   (sign_extend:V8SI
9058                     (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")))
9059                 (const_int 14))
9060               (const_vector:V8HI [(const_int 1) (const_int 1)
9061                                   (const_int 1) (const_int 1)
9062                                   (const_int 1) (const_int 1)
9063                                   (const_int 1) (const_int 1)]))
9064             (const_int 1))))]
9065   "TARGET_SSSE3 && ix86_binary_operator_ok (MULT, V8HImode, operands)"
9066   "@
9067    pmulhrsw\t{%2, %0|%0, %2}
9068    vpmulhrsw\t{%2, %1, %0|%0, %1, %2}"
9069   [(set_attr "isa" "noavx,avx")
9070    (set_attr "type" "sseimul")
9071    (set_attr "prefix_data16" "1,*")
9072    (set_attr "prefix_extra" "1")
9073    (set_attr "prefix" "orig,vex")
9074    (set_attr "mode" "TI")])
9075
9076 (define_expand "ssse3_pmulhrswv4hi3"
9077   [(set (match_operand:V4HI 0 "register_operand" "")
9078         (truncate:V4HI
9079           (lshiftrt:V4SI
9080             (plus:V4SI
9081               (lshiftrt:V4SI
9082                 (mult:V4SI
9083                   (sign_extend:V4SI
9084                     (match_operand:V4HI 1 "nonimmediate_operand" ""))
9085                   (sign_extend:V4SI
9086                     (match_operand:V4HI 2 "nonimmediate_operand" "")))
9087                 (const_int 14))
9088               (const_vector:V4HI [(const_int 1) (const_int 1)
9089                                   (const_int 1) (const_int 1)]))
9090             (const_int 1))))]
9091   "TARGET_SSSE3"
9092   "ix86_fixup_binary_operands_no_copy (MULT, V4HImode, operands);")
9093
9094 (define_insn "*ssse3_pmulhrswv4hi3"
9095   [(set (match_operand:V4HI 0 "register_operand" "=y")
9096         (truncate:V4HI
9097           (lshiftrt:V4SI
9098             (plus:V4SI
9099               (lshiftrt:V4SI
9100                 (mult:V4SI
9101                   (sign_extend:V4SI
9102                     (match_operand:V4HI 1 "nonimmediate_operand" "%0"))
9103                   (sign_extend:V4SI
9104                     (match_operand:V4HI 2 "nonimmediate_operand" "ym")))
9105                 (const_int 14))
9106               (const_vector:V4HI [(const_int 1) (const_int 1)
9107                                   (const_int 1) (const_int 1)]))
9108             (const_int 1))))]
9109   "TARGET_SSSE3 && ix86_binary_operator_ok (MULT, V4HImode, operands)"
9110   "pmulhrsw\t{%2, %0|%0, %2}"
9111   [(set_attr "type" "sseimul")
9112    (set_attr "prefix_extra" "1")
9113    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
9114    (set_attr "mode" "DI")])
9115
9116 (define_insn "<ssse3_avx2>_pshufb<mode>3"
9117   [(set (match_operand:VI1_AVX2 0 "register_operand" "=x,x")
9118         (unspec:VI1_AVX2 [(match_operand:VI1_AVX2 1 "register_operand" "0,x")
9119                           (match_operand:VI1_AVX2 2 "nonimmediate_operand" "xm,xm")]
9120                          UNSPEC_PSHUFB))]
9121   "TARGET_SSSE3"
9122   "@
9123    pshufb\t{%2, %0|%0, %2}
9124    vpshufb\t{%2, %1, %0|%0, %1, %2}"
9125   [(set_attr "isa" "noavx,avx")
9126    (set_attr "type" "sselog1")
9127    (set_attr "prefix_data16" "1,*")
9128    (set_attr "prefix_extra" "1")
9129    (set_attr "prefix" "orig,vex")
9130    (set_attr "mode" "<sseinsnmode>")])
9131
9132 (define_insn "ssse3_pshufbv8qi3"
9133   [(set (match_operand:V8QI 0 "register_operand" "=y")
9134         (unspec:V8QI [(match_operand:V8QI 1 "register_operand" "0")
9135                       (match_operand:V8QI 2 "nonimmediate_operand" "ym")]
9136                      UNSPEC_PSHUFB))]
9137   "TARGET_SSSE3"
9138   "pshufb\t{%2, %0|%0, %2}";
9139   [(set_attr "type" "sselog1")
9140    (set_attr "prefix_extra" "1")
9141    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
9142    (set_attr "mode" "DI")])
9143
9144 (define_insn "<ssse3_avx2>_psign<mode>3"
9145   [(set (match_operand:VI124_AVX2 0 "register_operand" "=x,x")
9146         (unspec:VI124_AVX2
9147           [(match_operand:VI124_AVX2 1 "register_operand" "0,x")
9148            (match_operand:VI124_AVX2 2 "nonimmediate_operand" "xm,xm")]
9149           UNSPEC_PSIGN))]
9150   "TARGET_SSSE3"
9151   "@
9152    psign<ssemodesuffix>\t{%2, %0|%0, %2}
9153    vpsign<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
9154   [(set_attr "isa" "noavx,avx")
9155    (set_attr "type" "sselog1")
9156    (set_attr "prefix_data16" "1,*")
9157    (set_attr "prefix_extra" "1")
9158    (set_attr "prefix" "orig,vex")
9159    (set_attr "mode" "<sseinsnmode>")])
9160
9161 (define_insn "ssse3_psign<mode>3"
9162   [(set (match_operand:MMXMODEI 0 "register_operand" "=y")
9163         (unspec:MMXMODEI
9164           [(match_operand:MMXMODEI 1 "register_operand" "0")
9165            (match_operand:MMXMODEI 2 "nonimmediate_operand" "ym")]
9166           UNSPEC_PSIGN))]
9167   "TARGET_SSSE3"
9168   "psign<mmxvecsize>\t{%2, %0|%0, %2}";
9169   [(set_attr "type" "sselog1")
9170    (set_attr "prefix_extra" "1")
9171    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
9172    (set_attr "mode" "DI")])
9173
9174 (define_insn "<ssse3_avx2>_palignr<mode>"
9175   [(set (match_operand:SSESCALARMODE 0 "register_operand" "=x,x")
9176         (unspec:SSESCALARMODE [(match_operand:SSESCALARMODE 1 "register_operand" "0,x")
9177                                (match_operand:SSESCALARMODE 2 "nonimmediate_operand" "xm,xm")
9178                                (match_operand:SI 3 "const_0_to_255_mul_8_operand" "n,n")]
9179                               UNSPEC_PALIGNR))]
9180   "TARGET_SSSE3"
9181 {
9182   operands[3] = GEN_INT (INTVAL (operands[3]) / 8);
9183
9184   switch (which_alternative)
9185     {
9186     case 0:
9187       return "palignr\t{%3, %2, %0|%0, %2, %3}";
9188     case 1:
9189       return "vpalignr\t{%3, %2, %1, %0|%0, %1, %2, %3}";
9190     default:
9191       gcc_unreachable ();
9192     }
9193 }
9194   [(set_attr "isa" "noavx,avx")
9195    (set_attr "type" "sseishft")
9196    (set_attr "atom_unit" "sishuf")
9197    (set_attr "prefix_data16" "1,*")
9198    (set_attr "prefix_extra" "1")
9199    (set_attr "length_immediate" "1")
9200    (set_attr "prefix" "orig,vex")
9201    (set_attr "mode" "<sseinsnmode>")])
9202
9203 (define_insn "ssse3_palignrdi"
9204   [(set (match_operand:DI 0 "register_operand" "=y")
9205         (unspec:DI [(match_operand:DI 1 "register_operand" "0")
9206                     (match_operand:DI 2 "nonimmediate_operand" "ym")
9207                     (match_operand:SI 3 "const_0_to_255_mul_8_operand" "n")]
9208                    UNSPEC_PALIGNR))]
9209   "TARGET_SSSE3"
9210 {
9211   operands[3] = GEN_INT (INTVAL (operands[3]) / 8);
9212   return "palignr\t{%3, %2, %0|%0, %2, %3}";
9213 }
9214   [(set_attr "type" "sseishft")
9215    (set_attr "atom_unit" "sishuf")
9216    (set_attr "prefix_extra" "1")
9217    (set_attr "length_immediate" "1")
9218    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
9219    (set_attr "mode" "DI")])
9220
9221 (define_insn "abs<mode>2"
9222   [(set (match_operand:VI124_AVX2 0 "register_operand" "=x")
9223         (abs:VI124_AVX2
9224           (match_operand:VI124_AVX2 1 "nonimmediate_operand" "xm")))]
9225   "TARGET_SSSE3"
9226   "%vpabs<ssemodesuffix>\t{%1, %0|%0, %1}"
9227   [(set_attr "type" "sselog1")
9228    (set_attr "prefix_data16" "1")
9229    (set_attr "prefix_extra" "1")
9230    (set_attr "prefix" "maybe_vex")
9231    (set_attr "mode" "<sseinsnmode>")])
9232
9233 (define_insn "abs<mode>2"
9234   [(set (match_operand:MMXMODEI 0 "register_operand" "=y")
9235         (abs:MMXMODEI
9236           (match_operand:MMXMODEI 1 "nonimmediate_operand" "ym")))]
9237   "TARGET_SSSE3"
9238   "pabs<mmxvecsize>\t{%1, %0|%0, %1}";
9239   [(set_attr "type" "sselog1")
9240    (set_attr "prefix_rep" "0")
9241    (set_attr "prefix_extra" "1")
9242    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
9243    (set_attr "mode" "DI")])
9244
9245 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9246 ;;
9247 ;; AMD SSE4A instructions
9248 ;;
9249 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9250
9251 (define_insn "sse4a_movnt<mode>"
9252   [(set (match_operand:MODEF 0 "memory_operand" "=m")
9253         (unspec:MODEF
9254           [(match_operand:MODEF 1 "register_operand" "x")]
9255           UNSPEC_MOVNT))]
9256   "TARGET_SSE4A"
9257   "movnt<ssemodesuffix>\t{%1, %0|%0, %1}"
9258   [(set_attr "type" "ssemov")
9259    (set_attr "mode" "<MODE>")])
9260
9261 (define_insn "sse4a_vmmovnt<mode>"
9262   [(set (match_operand:<ssescalarmode> 0 "memory_operand" "=m")
9263         (unspec:<ssescalarmode>
9264           [(vec_select:<ssescalarmode>
9265              (match_operand:VF_128 1 "register_operand" "x")
9266              (parallel [(const_int 0)]))]
9267           UNSPEC_MOVNT))]
9268   "TARGET_SSE4A"
9269   "movnt<ssescalarmodesuffix>\t{%1, %0|%0, %1}"
9270   [(set_attr "type" "ssemov")
9271    (set_attr "mode" "<ssescalarmode>")])
9272
9273 (define_insn "sse4a_extrqi"
9274   [(set (match_operand:V2DI 0 "register_operand" "=x")
9275         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
9276                       (match_operand 2 "const_0_to_255_operand" "")
9277                       (match_operand 3 "const_0_to_255_operand" "")]
9278                      UNSPEC_EXTRQI))]
9279   "TARGET_SSE4A"
9280   "extrq\t{%3, %2, %0|%0, %2, %3}"
9281   [(set_attr "type" "sse")
9282    (set_attr "prefix_data16" "1")
9283    (set_attr "length_immediate" "2")
9284    (set_attr "mode" "TI")])
9285
9286 (define_insn "sse4a_extrq"
9287   [(set (match_operand:V2DI 0 "register_operand" "=x")
9288         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
9289                       (match_operand:V16QI 2 "register_operand" "x")]
9290                      UNSPEC_EXTRQ))]
9291   "TARGET_SSE4A"
9292   "extrq\t{%2, %0|%0, %2}"
9293   [(set_attr "type" "sse")
9294    (set_attr "prefix_data16" "1")
9295    (set_attr "mode" "TI")])
9296
9297 (define_insn "sse4a_insertqi"
9298   [(set (match_operand:V2DI 0 "register_operand" "=x")
9299         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
9300                       (match_operand:V2DI 2 "register_operand" "x")
9301                       (match_operand 3 "const_0_to_255_operand" "")
9302                       (match_operand 4 "const_0_to_255_operand" "")]
9303                      UNSPEC_INSERTQI))]
9304   "TARGET_SSE4A"
9305   "insertq\t{%4, %3, %2, %0|%0, %2, %3, %4}"
9306   [(set_attr "type" "sseins")
9307    (set_attr "prefix_data16" "0")
9308    (set_attr "prefix_rep" "1")
9309    (set_attr "length_immediate" "2")
9310    (set_attr "mode" "TI")])
9311
9312 (define_insn "sse4a_insertq"
9313   [(set (match_operand:V2DI 0 "register_operand" "=x")
9314         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
9315                       (match_operand:V2DI 2 "register_operand" "x")]
9316                      UNSPEC_INSERTQ))]
9317   "TARGET_SSE4A"
9318   "insertq\t{%2, %0|%0, %2}"
9319   [(set_attr "type" "sseins")
9320    (set_attr "prefix_data16" "0")
9321    (set_attr "prefix_rep" "1")
9322    (set_attr "mode" "TI")])
9323
9324 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9325 ;;
9326 ;; Intel SSE4.1 instructions
9327 ;;
9328 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9329
9330 (define_insn "<sse4_1>_blend<ssemodesuffix><avxsizesuffix>"
9331   [(set (match_operand:VF 0 "register_operand" "=x,x")
9332         (vec_merge:VF
9333           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")
9334           (match_operand:VF 1 "register_operand" "0,x")
9335           (match_operand:SI 3 "const_0_to_<blendbits>_operand" "")))]
9336   "TARGET_SSE4_1"
9337   "@
9338    blend<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
9339    vblend<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9340   [(set_attr "isa" "noavx,avx")
9341    (set_attr "type" "ssemov")
9342    (set_attr "length_immediate" "1")
9343    (set_attr "prefix_data16" "1,*")
9344    (set_attr "prefix_extra" "1")
9345    (set_attr "prefix" "orig,vex")
9346    (set_attr "mode" "<MODE>")])
9347
9348 (define_insn "<sse4_1>_blendv<ssemodesuffix><avxsizesuffix>"
9349   [(set (match_operand:VF 0 "reg_not_xmm0_operand_maybe_avx" "=x,x")
9350         (unspec:VF
9351           [(match_operand:VF 1 "reg_not_xmm0_operand_maybe_avx" "0,x")
9352            (match_operand:VF 2 "nonimm_not_xmm0_operand_maybe_avx" "xm,xm")
9353            (match_operand:VF 3 "register_operand" "Yz,x")]
9354           UNSPEC_BLENDV))]
9355   "TARGET_SSE4_1"
9356   "@
9357    blendv<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
9358    vblendv<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9359   [(set_attr "isa" "noavx,avx")
9360    (set_attr "type" "ssemov")
9361    (set_attr "length_immediate" "1")
9362    (set_attr "prefix_data16" "1,*")
9363    (set_attr "prefix_extra" "1")
9364    (set_attr "prefix" "orig,vex")
9365    (set_attr "mode" "<MODE>")])
9366
9367 (define_insn "<sse4_1>_dp<ssemodesuffix><avxsizesuffix>"
9368   [(set (match_operand:VF 0 "register_operand" "=x,x")
9369         (unspec:VF
9370           [(match_operand:VF 1 "nonimmediate_operand" "%0,x")
9371            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")
9372            (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
9373           UNSPEC_DP))]
9374   "TARGET_SSE4_1"
9375   "@
9376    dp<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
9377    vdp<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9378   [(set_attr "isa" "noavx,avx")
9379    (set_attr "type" "ssemul")
9380    (set_attr "length_immediate" "1")
9381    (set_attr "prefix_data16" "1,*")
9382    (set_attr "prefix_extra" "1")
9383    (set_attr "prefix" "orig,vex")
9384    (set_attr "mode" "<MODE>")])
9385
9386 (define_insn "<sse4_1_avx2>_movntdqa"
9387   [(set (match_operand:VI8_AVX2 0 "register_operand" "=x")
9388         (unspec:VI8_AVX2 [(match_operand:VI8_AVX2 1 "memory_operand" "m")]
9389                      UNSPEC_MOVNTDQA))]
9390   "TARGET_SSE4_1"
9391   "%vmovntdqa\t{%1, %0|%0, %1}"
9392   [(set_attr "type" "ssemov")
9393    (set_attr "prefix_extra" "1")
9394    (set_attr "prefix" "maybe_vex")
9395    (set_attr "mode" "<sseinsnmode>")])
9396
9397 (define_insn "<sse4_1_avx2>_mpsadbw"
9398   [(set (match_operand:VI1_AVX2 0 "register_operand" "=x,x")
9399         (unspec:VI1_AVX2 [(match_operand:VI1_AVX2 1 "register_operand" "0,x")
9400                           (match_operand:VI1_AVX2 2 "nonimmediate_operand" "xm,xm")
9401                           (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
9402                          UNSPEC_MPSADBW))]
9403   "TARGET_SSE4_1"
9404   "@
9405    mpsadbw\t{%3, %2, %0|%0, %2, %3}
9406    vmpsadbw\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9407   [(set_attr "isa" "noavx,avx")
9408    (set_attr "type" "sselog1")
9409    (set_attr "length_immediate" "1")
9410    (set_attr "prefix_extra" "1")
9411    (set_attr "prefix" "orig,vex")
9412    (set_attr "mode" "<sseinsnmode>")])
9413
9414 (define_insn "avx2_packusdw"
9415   [(set (match_operand:V16HI 0 "register_operand" "=x")
9416         (vec_concat:V16HI
9417           (us_truncate:V8HI
9418             (match_operand:V8SI 1 "register_operand" "x"))
9419           (us_truncate:V8HI
9420             (match_operand:V8SI 2 "nonimmediate_operand" "xm"))))]
9421   "TARGET_AVX2"
9422   "vpackusdw\t{%2, %1, %0|%0, %1, %2}"
9423   [(set_attr "type" "sselog")
9424    (set_attr "prefix_extra" "1")
9425    (set_attr "prefix" "vex")
9426    (set_attr "mode" "OI")])
9427
9428 (define_insn "sse4_1_packusdw"
9429   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
9430         (vec_concat:V8HI
9431           (us_truncate:V4HI
9432             (match_operand:V4SI 1 "register_operand" "0,x"))
9433           (us_truncate:V4HI
9434             (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm"))))]
9435   "TARGET_SSE4_1"
9436   "@
9437    packusdw\t{%2, %0|%0, %2}
9438    vpackusdw\t{%2, %1, %0|%0, %1, %2}"
9439   [(set_attr "isa" "noavx,avx")
9440    (set_attr "type" "sselog")
9441    (set_attr "prefix_extra" "1")
9442    (set_attr "prefix" "orig,vex")
9443    (set_attr "mode" "TI")])
9444
9445 (define_insn "<sse4_1_avx2>_pblendvb"
9446   [(set (match_operand:VI1_AVX2 0 "reg_not_xmm0_operand" "=x,x")
9447         (unspec:VI1_AVX2
9448           [(match_operand:VI1_AVX2 1 "reg_not_xmm0_operand_maybe_avx"  "0,x")
9449            (match_operand:VI1_AVX2 2 "nonimm_not_xmm0_operand_maybe_avx" "xm,xm")
9450            (match_operand:VI1_AVX2 3 "register_operand" "Yz,x")]
9451           UNSPEC_BLENDV))]
9452   "TARGET_SSE4_1"
9453   "@
9454    pblendvb\t{%3, %2, %0|%0, %2, %3}
9455    vpblendvb\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9456   [(set_attr "isa" "noavx,avx")
9457    (set_attr "type" "ssemov")
9458    (set_attr "prefix_extra" "1")
9459    (set_attr "length_immediate" "*,1")
9460    (set_attr "prefix" "orig,vex")
9461    (set_attr "mode" "<sseinsnmode>")])
9462
9463 (define_insn "sse4_1_pblendw"
9464   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
9465         (vec_merge:V8HI
9466           (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
9467           (match_operand:V8HI 1 "register_operand" "0,x")
9468           (match_operand:SI 3 "const_0_to_255_operand" "n,n")))]
9469   "TARGET_SSE4_1"
9470   "@
9471    pblendw\t{%3, %2, %0|%0, %2, %3}
9472    vpblendw\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9473   [(set_attr "isa" "noavx,avx")
9474    (set_attr "type" "ssemov")
9475    (set_attr "prefix_extra" "1")
9476    (set_attr "length_immediate" "1")
9477    (set_attr "prefix" "orig,vex")
9478    (set_attr "mode" "TI")])
9479
9480 ;; The builtin uses an 8-bit immediate.  Expand that.
9481 (define_expand "avx2_pblendw"
9482   [(set (match_operand:V16HI 0 "register_operand" "")
9483         (vec_merge:V16HI
9484           (match_operand:V16HI 2 "nonimmediate_operand" "")
9485           (match_operand:V16HI 1 "register_operand" "")
9486           (match_operand:SI 3 "const_0_to_255_operand" "")))]
9487   "TARGET_AVX2"
9488 {
9489   HOST_WIDE_INT val = INTVAL (operands[3]) & 0xff;
9490   operands[3] = GEN_INT (val << 8 | val);
9491 })
9492
9493 (define_insn "*avx2_pblendw"
9494   [(set (match_operand:V16HI 0 "register_operand" "=x")
9495         (vec_merge:V16HI
9496           (match_operand:V16HI 2 "nonimmediate_operand" "xm")
9497           (match_operand:V16HI 1 "register_operand" "x")
9498           (match_operand:SI 3 "avx2_pblendw_operand" "n")))]
9499   "TARGET_AVX2"
9500 {
9501   operands[3] = GEN_INT (INTVAL (operands[3]) & 0xff);
9502   return "vpblendw\t{%3, %2, %1, %0|%0, %1, %2, %3}";
9503 }
9504   [(set_attr "type" "ssemov")
9505    (set_attr "prefix_extra" "1")
9506    (set_attr "length_immediate" "1")
9507    (set_attr "prefix" "vex")
9508    (set_attr "mode" "OI")])
9509
9510 (define_insn "avx2_pblendd<mode>"
9511   [(set (match_operand:VI4_AVX2 0 "register_operand" "=x")
9512         (vec_merge:VI4_AVX2
9513           (match_operand:VI4_AVX2 2 "nonimmediate_operand" "xm")
9514           (match_operand:VI4_AVX2 1 "register_operand" "x")
9515           (match_operand:SI 3 "const_0_to_255_operand" "n")))]
9516   "TARGET_AVX2"
9517   "vpblendd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9518   [(set_attr "type" "ssemov")
9519    (set_attr "prefix_extra" "1")
9520    (set_attr "length_immediate" "1")
9521    (set_attr "prefix" "vex")
9522    (set_attr "mode" "<sseinsnmode>")])
9523
9524 (define_insn "sse4_1_phminposuw"
9525   [(set (match_operand:V8HI 0 "register_operand" "=x")
9526         (unspec:V8HI [(match_operand:V8HI 1 "nonimmediate_operand" "xm")]
9527                      UNSPEC_PHMINPOSUW))]
9528   "TARGET_SSE4_1"
9529   "%vphminposuw\t{%1, %0|%0, %1}"
9530   [(set_attr "type" "sselog1")
9531    (set_attr "prefix_extra" "1")
9532    (set_attr "prefix" "maybe_vex")
9533    (set_attr "mode" "TI")])
9534
9535 (define_insn "avx2_<code>v16qiv16hi2"
9536   [(set (match_operand:V16HI 0 "register_operand" "=x")
9537         (any_extend:V16HI
9538           (match_operand:V16QI 1 "nonimmediate_operand" "xm")))]
9539   "TARGET_AVX2"
9540   "vpmov<extsuffix>bw\t{%1, %0|%0, %1}"
9541   [(set_attr "type" "ssemov")
9542    (set_attr "prefix_extra" "1")
9543    (set_attr "prefix" "vex")
9544    (set_attr "mode" "OI")])
9545
9546 (define_insn "sse4_1_<code>v8qiv8hi2"
9547   [(set (match_operand:V8HI 0 "register_operand" "=x")
9548         (any_extend:V8HI
9549           (vec_select:V8QI
9550             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9551             (parallel [(const_int 0)
9552                        (const_int 1)
9553                        (const_int 2)
9554                        (const_int 3)
9555                        (const_int 4)
9556                        (const_int 5)
9557                        (const_int 6)
9558                        (const_int 7)]))))]
9559   "TARGET_SSE4_1"
9560   "%vpmov<extsuffix>bw\t{%1, %0|%0, %1}"
9561   [(set_attr "type" "ssemov")
9562    (set_attr "prefix_extra" "1")
9563    (set_attr "prefix" "maybe_vex")
9564    (set_attr "mode" "TI")])
9565
9566 (define_insn "avx2_<code>v8qiv8si2"
9567   [(set (match_operand:V8SI 0 "register_operand" "=x")
9568         (any_extend:V8SI
9569           (vec_select:V8QI
9570             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9571             (parallel [(const_int 0)
9572                        (const_int 1)
9573                        (const_int 2)
9574                        (const_int 3)
9575                        (const_int 4)
9576                        (const_int 5)
9577                        (const_int 6)
9578                        (const_int 7)]))))]
9579   "TARGET_AVX2"
9580   "vpmov<extsuffix>bd\t{%1, %0|%0, %1}"
9581   [(set_attr "type" "ssemov")
9582    (set_attr "prefix_extra" "1")
9583    (set_attr "prefix" "vex")
9584    (set_attr "mode" "OI")])
9585
9586 (define_insn "sse4_1_<code>v4qiv4si2"
9587   [(set (match_operand:V4SI 0 "register_operand" "=x")
9588         (any_extend:V4SI
9589           (vec_select:V4QI
9590             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9591             (parallel [(const_int 0)
9592                        (const_int 1)
9593                        (const_int 2)
9594                        (const_int 3)]))))]
9595   "TARGET_SSE4_1"
9596   "%vpmov<extsuffix>bd\t{%1, %0|%0, %1}"
9597   [(set_attr "type" "ssemov")
9598    (set_attr "prefix_extra" "1")
9599    (set_attr "prefix" "maybe_vex")
9600    (set_attr "mode" "TI")])
9601
9602 (define_insn "avx2_<code>v8hiv8si2"
9603   [(set (match_operand:V8SI 0 "register_operand" "=x")
9604         (any_extend:V8SI
9605             (match_operand:V8HI 1 "nonimmediate_operand" "xm")))]
9606   "TARGET_AVX2"
9607   "vpmov<extsuffix>wd\t{%1, %0|%0, %1}"
9608   [(set_attr "type" "ssemov")
9609    (set_attr "prefix_extra" "1")
9610    (set_attr "prefix" "vex")
9611    (set_attr "mode" "OI")])
9612
9613 (define_insn "sse4_1_<code>v4hiv4si2"
9614   [(set (match_operand:V4SI 0 "register_operand" "=x")
9615         (any_extend:V4SI
9616           (vec_select:V4HI
9617             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
9618             (parallel [(const_int 0)
9619                        (const_int 1)
9620                        (const_int 2)
9621                        (const_int 3)]))))]
9622   "TARGET_SSE4_1"
9623   "%vpmov<extsuffix>wd\t{%1, %0|%0, %1}"
9624   [(set_attr "type" "ssemov")
9625    (set_attr "prefix_extra" "1")
9626    (set_attr "prefix" "maybe_vex")
9627    (set_attr "mode" "TI")])
9628
9629 (define_insn "avx2_<code>v4qiv4di2"
9630   [(set (match_operand:V4DI 0 "register_operand" "=x")
9631         (any_extend:V4DI
9632           (vec_select:V4QI
9633             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9634             (parallel [(const_int 0)
9635                        (const_int 1)
9636                        (const_int 2)
9637                        (const_int 3)]))))]
9638   "TARGET_AVX2"
9639   "vpmov<extsuffix>bq\t{%1, %0|%0, %1}"
9640   [(set_attr "type" "ssemov")
9641    (set_attr "prefix_extra" "1")
9642    (set_attr "prefix" "vex")
9643    (set_attr "mode" "OI")])
9644
9645 (define_insn "sse4_1_<code>v2qiv2di2"
9646   [(set (match_operand:V2DI 0 "register_operand" "=x")
9647         (any_extend:V2DI
9648           (vec_select:V2QI
9649             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9650             (parallel [(const_int 0)
9651                        (const_int 1)]))))]
9652   "TARGET_SSE4_1"
9653   "%vpmov<extsuffix>bq\t{%1, %0|%0, %1}"
9654   [(set_attr "type" "ssemov")
9655    (set_attr "prefix_extra" "1")
9656    (set_attr "prefix" "maybe_vex")
9657    (set_attr "mode" "TI")])
9658
9659 (define_insn "avx2_<code>v4hiv4di2"
9660   [(set (match_operand:V4DI 0 "register_operand" "=x")
9661         (any_extend:V4DI
9662           (vec_select:V4HI
9663             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
9664             (parallel [(const_int 0)
9665                        (const_int 1)
9666                        (const_int 2)
9667                        (const_int 3)]))))]
9668   "TARGET_AVX2"
9669   "vpmov<extsuffix>wq\t{%1, %0|%0, %1}"
9670   [(set_attr "type" "ssemov")
9671    (set_attr "prefix_extra" "1")
9672    (set_attr "prefix" "vex")
9673    (set_attr "mode" "OI")])
9674
9675 (define_insn "sse4_1_<code>v2hiv2di2"
9676   [(set (match_operand:V2DI 0 "register_operand" "=x")
9677         (any_extend:V2DI
9678           (vec_select:V2HI
9679             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
9680             (parallel [(const_int 0)
9681                        (const_int 1)]))))]
9682   "TARGET_SSE4_1"
9683   "%vpmov<extsuffix>wq\t{%1, %0|%0, %1}"
9684   [(set_attr "type" "ssemov")
9685    (set_attr "prefix_extra" "1")
9686    (set_attr "prefix" "maybe_vex")
9687    (set_attr "mode" "TI")])
9688
9689 (define_insn "avx2_<code>v4siv4di2"
9690   [(set (match_operand:V4DI 0 "register_operand" "=x")
9691         (any_extend:V4DI
9692             (match_operand:V4SI 1 "nonimmediate_operand" "xm")))]
9693   "TARGET_AVX2"
9694   "vpmov<extsuffix>dq\t{%1, %0|%0, %1}"
9695   [(set_attr "type" "ssemov")
9696    (set_attr "prefix_extra" "1")
9697    (set_attr "mode" "OI")])
9698
9699 (define_insn "sse4_1_<code>v2siv2di2"
9700   [(set (match_operand:V2DI 0 "register_operand" "=x")
9701         (any_extend:V2DI
9702           (vec_select:V2SI
9703             (match_operand:V4SI 1 "nonimmediate_operand" "xm")
9704             (parallel [(const_int 0)
9705                        (const_int 1)]))))]
9706   "TARGET_SSE4_1"
9707   "%vpmov<extsuffix>dq\t{%1, %0|%0, %1}"
9708   [(set_attr "type" "ssemov")
9709    (set_attr "prefix_extra" "1")
9710    (set_attr "prefix" "maybe_vex")
9711    (set_attr "mode" "TI")])
9712
9713 ;; ptestps/ptestpd are very similar to comiss and ucomiss when
9714 ;; setting FLAGS_REG. But it is not a really compare instruction.
9715 (define_insn "avx_vtest<ssemodesuffix><avxsizesuffix>"
9716   [(set (reg:CC FLAGS_REG)
9717         (unspec:CC [(match_operand:VF 0 "register_operand" "x")
9718                     (match_operand:VF 1 "nonimmediate_operand" "xm")]
9719                    UNSPEC_VTESTP))]
9720   "TARGET_AVX"
9721   "vtest<ssemodesuffix>\t{%1, %0|%0, %1}"
9722   [(set_attr "type" "ssecomi")
9723    (set_attr "prefix_extra" "1")
9724    (set_attr "prefix" "vex")
9725    (set_attr "mode" "<MODE>")])
9726
9727 ;; ptest is very similar to comiss and ucomiss when setting FLAGS_REG.
9728 ;; But it is not a really compare instruction.
9729 (define_insn "avx_ptest256"
9730   [(set (reg:CC FLAGS_REG)
9731         (unspec:CC [(match_operand:V4DI 0 "register_operand" "x")
9732                     (match_operand:V4DI 1 "nonimmediate_operand" "xm")]
9733                    UNSPEC_PTEST))]
9734   "TARGET_AVX"
9735   "vptest\t{%1, %0|%0, %1}"
9736   [(set_attr "type" "ssecomi")
9737    (set_attr "prefix_extra" "1")
9738    (set_attr "prefix" "vex")
9739    (set_attr "mode" "OI")])
9740
9741 (define_insn "sse4_1_ptest"
9742   [(set (reg:CC FLAGS_REG)
9743         (unspec:CC [(match_operand:V2DI 0 "register_operand" "x")
9744                     (match_operand:V2DI 1 "nonimmediate_operand" "xm")]
9745                    UNSPEC_PTEST))]
9746   "TARGET_SSE4_1"
9747   "%vptest\t{%1, %0|%0, %1}"
9748   [(set_attr "type" "ssecomi")
9749    (set_attr "prefix_extra" "1")
9750    (set_attr "prefix" "maybe_vex")
9751    (set_attr "mode" "TI")])
9752
9753 (define_insn "<sse4_1>_round<ssemodesuffix><avxsizesuffix>"
9754   [(set (match_operand:VF 0 "register_operand" "=x")
9755         (unspec:VF
9756           [(match_operand:VF 1 "nonimmediate_operand" "xm")
9757            (match_operand:SI 2 "const_0_to_15_operand" "n")]
9758           UNSPEC_ROUND))]
9759   "TARGET_ROUND"
9760   "%vround<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
9761   [(set_attr "type" "ssecvt")
9762    (set (attr "prefix_data16")
9763      (if_then_else
9764        (match_test "TARGET_AVX")
9765      (const_string "*")
9766      (const_string "1")))
9767    (set_attr "prefix_extra" "1")
9768    (set_attr "length_immediate" "1")
9769    (set_attr "prefix" "maybe_vex")
9770    (set_attr "mode" "<MODE>")])
9771
9772 (define_insn "sse4_1_round<ssescalarmodesuffix>"
9773   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
9774         (vec_merge:VF_128
9775           (unspec:VF_128
9776             [(match_operand:VF_128 2 "register_operand" "x,x")
9777              (match_operand:SI 3 "const_0_to_15_operand" "n,n")]
9778             UNSPEC_ROUND)
9779           (match_operand:VF_128 1 "register_operand" "0,x")
9780           (const_int 1)))]
9781   "TARGET_ROUND"
9782   "@
9783    round<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}
9784    vround<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9785   [(set_attr "isa" "noavx,avx")
9786    (set_attr "type" "ssecvt")
9787    (set_attr "length_immediate" "1")
9788    (set_attr "prefix_data16" "1,*")
9789    (set_attr "prefix_extra" "1")
9790    (set_attr "prefix" "orig,vex")
9791    (set_attr "mode" "<MODE>")])
9792
9793 (define_expand "round<mode>2"
9794   [(set (match_dup 4)
9795         (plus:VF
9796           (match_operand:VF 1 "nonimmediate_operand" "")
9797           (match_dup 3)))
9798    (set (match_operand:VF 0 "register_operand" "")
9799         (unspec:VF
9800           [(match_dup 4) (match_dup 5)]
9801           UNSPEC_ROUND))]
9802   "TARGET_ROUND && !flag_trapping_math"
9803 {
9804   enum machine_mode scalar_mode;
9805   const struct real_format *fmt;
9806   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
9807   rtx half, vec_half;
9808
9809   scalar_mode = GET_MODE_INNER (<MODE>mode);
9810
9811   /* load nextafter (0.5, 0.0) */
9812   fmt = REAL_MODE_FORMAT (scalar_mode);
9813   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, scalar_mode);
9814   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
9815   half = const_double_from_real_value (pred_half, scalar_mode);
9816
9817   vec_half = ix86_build_const_vector (<MODE>mode, true, half);
9818   vec_half = force_reg (<MODE>mode, vec_half);
9819
9820   operands[3] = gen_reg_rtx (<MODE>mode);
9821   emit_insn (gen_copysign<mode>3 (operands[3], vec_half, operands[1]));
9822
9823   operands[4] = gen_reg_rtx (<MODE>mode);
9824   operands[5] = GEN_INT (ROUND_TRUNC);
9825 })
9826
9827 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9828 ;;
9829 ;; Intel SSE4.2 string/text processing instructions
9830 ;;
9831 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9832
9833 (define_insn_and_split "sse4_2_pcmpestr"
9834   [(set (match_operand:SI 0 "register_operand" "=c,c")
9835         (unspec:SI
9836           [(match_operand:V16QI 2 "reg_not_xmm0_operand" "x,x")
9837            (match_operand:SI 3 "register_operand" "a,a")
9838            (match_operand:V16QI 4 "nonimm_not_xmm0_operand" "x,m")
9839            (match_operand:SI 5 "register_operand" "d,d")
9840            (match_operand:SI 6 "const_0_to_255_operand" "n,n")]
9841           UNSPEC_PCMPESTR))
9842    (set (match_operand:V16QI 1 "register_operand" "=Yz,Yz")
9843         (unspec:V16QI
9844           [(match_dup 2)
9845            (match_dup 3)
9846            (match_dup 4)
9847            (match_dup 5)
9848            (match_dup 6)]
9849           UNSPEC_PCMPESTR))
9850    (set (reg:CC FLAGS_REG)
9851         (unspec:CC
9852           [(match_dup 2)
9853            (match_dup 3)
9854            (match_dup 4)
9855            (match_dup 5)
9856            (match_dup 6)]
9857           UNSPEC_PCMPESTR))]
9858   "TARGET_SSE4_2
9859    && can_create_pseudo_p ()"
9860   "#"
9861   "&& 1"
9862   [(const_int 0)]
9863 {
9864   int ecx = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[0]));
9865   int xmm0 = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[1]));
9866   int flags = !find_regno_note (curr_insn, REG_UNUSED, FLAGS_REG);
9867
9868   if (ecx)
9869     emit_insn (gen_sse4_2_pcmpestri (operands[0], operands[2],
9870                                      operands[3], operands[4],
9871                                      operands[5], operands[6]));
9872   if (xmm0)
9873     emit_insn (gen_sse4_2_pcmpestrm (operands[1], operands[2],
9874                                      operands[3], operands[4],
9875                                      operands[5], operands[6]));
9876   if (flags && !(ecx || xmm0))
9877     emit_insn (gen_sse4_2_pcmpestr_cconly (NULL, NULL,
9878                                            operands[2], operands[3],
9879                                            operands[4], operands[5],
9880                                            operands[6]));
9881   if (!(flags || ecx || xmm0))
9882     emit_note (NOTE_INSN_DELETED);
9883
9884   DONE;
9885 }
9886   [(set_attr "type" "sselog")
9887    (set_attr "prefix_data16" "1")
9888    (set_attr "prefix_extra" "1")
9889    (set_attr "length_immediate" "1")
9890    (set_attr "memory" "none,load")
9891    (set_attr "mode" "TI")])
9892
9893 (define_insn "sse4_2_pcmpestri"
9894   [(set (match_operand:SI 0 "register_operand" "=c,c")
9895         (unspec:SI
9896           [(match_operand:V16QI 1 "register_operand" "x,x")
9897            (match_operand:SI 2 "register_operand" "a,a")
9898            (match_operand:V16QI 3 "nonimmediate_operand" "x,m")
9899            (match_operand:SI 4 "register_operand" "d,d")
9900            (match_operand:SI 5 "const_0_to_255_operand" "n,n")]
9901           UNSPEC_PCMPESTR))
9902    (set (reg:CC FLAGS_REG)
9903         (unspec:CC
9904           [(match_dup 1)
9905            (match_dup 2)
9906            (match_dup 3)
9907            (match_dup 4)
9908            (match_dup 5)]
9909           UNSPEC_PCMPESTR))]
9910   "TARGET_SSE4_2"
9911   "%vpcmpestri\t{%5, %3, %1|%1, %3, %5}"
9912   [(set_attr "type" "sselog")
9913    (set_attr "prefix_data16" "1")
9914    (set_attr "prefix_extra" "1")
9915    (set_attr "prefix" "maybe_vex")
9916    (set_attr "length_immediate" "1")
9917    (set_attr "memory" "none,load")
9918    (set_attr "mode" "TI")])
9919
9920 (define_insn "sse4_2_pcmpestrm"
9921   [(set (match_operand:V16QI 0 "register_operand" "=Yz,Yz")
9922         (unspec:V16QI
9923           [(match_operand:V16QI 1 "register_operand" "x,x")
9924            (match_operand:SI 2 "register_operand" "a,a")
9925            (match_operand:V16QI 3 "nonimmediate_operand" "x,m")
9926            (match_operand:SI 4 "register_operand" "d,d")
9927            (match_operand:SI 5 "const_0_to_255_operand" "n,n")]
9928           UNSPEC_PCMPESTR))
9929    (set (reg:CC FLAGS_REG)
9930         (unspec:CC
9931           [(match_dup 1)
9932            (match_dup 2)
9933            (match_dup 3)
9934            (match_dup 4)
9935            (match_dup 5)]
9936           UNSPEC_PCMPESTR))]
9937   "TARGET_SSE4_2"
9938   "%vpcmpestrm\t{%5, %3, %1|%1, %3, %5}"
9939   [(set_attr "type" "sselog")
9940    (set_attr "prefix_data16" "1")
9941    (set_attr "prefix_extra" "1")
9942    (set_attr "length_immediate" "1")
9943    (set_attr "prefix" "maybe_vex")
9944    (set_attr "memory" "none,load")
9945    (set_attr "mode" "TI")])
9946
9947 (define_insn "sse4_2_pcmpestr_cconly"
9948   [(set (reg:CC FLAGS_REG)
9949         (unspec:CC
9950           [(match_operand:V16QI 2 "register_operand" "x,x,x,x")
9951            (match_operand:SI 3 "register_operand" "a,a,a,a")
9952            (match_operand:V16QI 4 "nonimmediate_operand" "x,m,x,m")
9953            (match_operand:SI 5 "register_operand" "d,d,d,d")
9954            (match_operand:SI 6 "const_0_to_255_operand" "n,n,n,n")]
9955           UNSPEC_PCMPESTR))
9956    (clobber (match_scratch:V16QI 0 "=Yz,Yz,X,X"))
9957    (clobber (match_scratch:SI    1 "= X, X,c,c"))]
9958   "TARGET_SSE4_2"
9959   "@
9960    %vpcmpestrm\t{%6, %4, %2|%2, %4, %6}
9961    %vpcmpestrm\t{%6, %4, %2|%2, %4, %6}
9962    %vpcmpestri\t{%6, %4, %2|%2, %4, %6}
9963    %vpcmpestri\t{%6, %4, %2|%2, %4, %6}"
9964   [(set_attr "type" "sselog")
9965    (set_attr "prefix_data16" "1")
9966    (set_attr "prefix_extra" "1")
9967    (set_attr "length_immediate" "1")
9968    (set_attr "memory" "none,load,none,load")
9969    (set_attr "prefix" "maybe_vex")
9970    (set_attr "mode" "TI")])
9971
9972 (define_insn_and_split "sse4_2_pcmpistr"
9973   [(set (match_operand:SI 0 "register_operand" "=c,c")
9974         (unspec:SI
9975           [(match_operand:V16QI 2 "reg_not_xmm0_operand" "x,x")
9976            (match_operand:V16QI 3 "nonimm_not_xmm0_operand" "x,m")
9977            (match_operand:SI 4 "const_0_to_255_operand" "n,n")]
9978           UNSPEC_PCMPISTR))
9979    (set (match_operand:V16QI 1 "register_operand" "=Yz,Yz")
9980         (unspec:V16QI
9981           [(match_dup 2)
9982            (match_dup 3)
9983            (match_dup 4)]
9984           UNSPEC_PCMPISTR))
9985    (set (reg:CC FLAGS_REG)
9986         (unspec:CC
9987           [(match_dup 2)
9988            (match_dup 3)
9989            (match_dup 4)]
9990           UNSPEC_PCMPISTR))]
9991   "TARGET_SSE4_2
9992    && can_create_pseudo_p ()"
9993   "#"
9994   "&& 1"
9995   [(const_int 0)]
9996 {
9997   int ecx = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[0]));
9998   int xmm0 = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[1]));
9999   int flags = !find_regno_note (curr_insn, REG_UNUSED, FLAGS_REG);
10000
10001   if (ecx)
10002     emit_insn (gen_sse4_2_pcmpistri (operands[0], operands[2],
10003                                      operands[3], operands[4]));
10004   if (xmm0)
10005     emit_insn (gen_sse4_2_pcmpistrm (operands[1], operands[2],
10006                                      operands[3], operands[4]));
10007   if (flags && !(ecx || xmm0))
10008     emit_insn (gen_sse4_2_pcmpistr_cconly (NULL, NULL,
10009                                            operands[2], operands[3],
10010                                            operands[4]));
10011   if (!(flags || ecx || xmm0))
10012     emit_note (NOTE_INSN_DELETED);
10013
10014   DONE;
10015 }
10016   [(set_attr "type" "sselog")
10017    (set_attr "prefix_data16" "1")
10018    (set_attr "prefix_extra" "1")
10019    (set_attr "length_immediate" "1")
10020    (set_attr "memory" "none,load")
10021    (set_attr "mode" "TI")])
10022
10023 (define_insn "sse4_2_pcmpistri"
10024   [(set (match_operand:SI 0 "register_operand" "=c,c")
10025         (unspec:SI
10026           [(match_operand:V16QI 1 "register_operand" "x,x")
10027            (match_operand:V16QI 2 "nonimmediate_operand" "x,m")
10028            (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
10029           UNSPEC_PCMPISTR))
10030    (set (reg:CC FLAGS_REG)
10031         (unspec:CC
10032           [(match_dup 1)
10033            (match_dup 2)
10034            (match_dup 3)]
10035           UNSPEC_PCMPISTR))]
10036   "TARGET_SSE4_2"
10037   "%vpcmpistri\t{%3, %2, %1|%1, %2, %3}"
10038   [(set_attr "type" "sselog")
10039    (set_attr "prefix_data16" "1")
10040    (set_attr "prefix_extra" "1")
10041    (set_attr "length_immediate" "1")
10042    (set_attr "prefix" "maybe_vex")
10043    (set_attr "memory" "none,load")
10044    (set_attr "mode" "TI")])
10045
10046 (define_insn "sse4_2_pcmpistrm"
10047   [(set (match_operand:V16QI 0 "register_operand" "=Yz,Yz")
10048         (unspec:V16QI
10049           [(match_operand:V16QI 1 "register_operand" "x,x")
10050            (match_operand:V16QI 2 "nonimmediate_operand" "x,m")
10051            (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
10052           UNSPEC_PCMPISTR))
10053    (set (reg:CC FLAGS_REG)
10054         (unspec:CC
10055           [(match_dup 1)
10056            (match_dup 2)
10057            (match_dup 3)]
10058           UNSPEC_PCMPISTR))]
10059   "TARGET_SSE4_2"
10060   "%vpcmpistrm\t{%3, %2, %1|%1, %2, %3}"
10061   [(set_attr "type" "sselog")
10062    (set_attr "prefix_data16" "1")
10063    (set_attr "prefix_extra" "1")
10064    (set_attr "length_immediate" "1")
10065    (set_attr "prefix" "maybe_vex")
10066    (set_attr "memory" "none,load")
10067    (set_attr "mode" "TI")])
10068
10069 (define_insn "sse4_2_pcmpistr_cconly"
10070   [(set (reg:CC FLAGS_REG)
10071         (unspec:CC
10072           [(match_operand:V16QI 2 "register_operand" "x,x,x,x")
10073            (match_operand:V16QI 3 "nonimmediate_operand" "x,m,x,m")
10074            (match_operand:SI 4 "const_0_to_255_operand" "n,n,n,n")]
10075           UNSPEC_PCMPISTR))
10076    (clobber (match_scratch:V16QI 0 "=Yz,Yz,X,X"))
10077    (clobber (match_scratch:SI    1 "= X, X,c,c"))]
10078   "TARGET_SSE4_2"
10079   "@
10080    %vpcmpistrm\t{%4, %3, %2|%2, %3, %4}
10081    %vpcmpistrm\t{%4, %3, %2|%2, %3, %4}
10082    %vpcmpistri\t{%4, %3, %2|%2, %3, %4}
10083    %vpcmpistri\t{%4, %3, %2|%2, %3, %4}"
10084   [(set_attr "type" "sselog")
10085    (set_attr "prefix_data16" "1")
10086    (set_attr "prefix_extra" "1")
10087    (set_attr "length_immediate" "1")
10088    (set_attr "memory" "none,load,none,load")
10089    (set_attr "prefix" "maybe_vex")
10090    (set_attr "mode" "TI")])
10091
10092 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10093 ;;
10094 ;; XOP instructions
10095 ;;
10096 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10097
10098 ;; XOP parallel integer multiply/add instructions.
10099 ;; Note the XOP multiply/add instructions
10100 ;;     a[i] = b[i] * c[i] + d[i];
10101 ;; do not allow the value being added to be a memory operation.
10102 (define_insn "xop_pmacsww"
10103   [(set (match_operand:V8HI 0 "register_operand" "=x")
10104         (plus:V8HI
10105          (mult:V8HI
10106           (match_operand:V8HI 1 "nonimmediate_operand" "%x")
10107           (match_operand:V8HI 2 "nonimmediate_operand" "xm"))
10108          (match_operand:V8HI 3 "nonimmediate_operand" "x")))]
10109   "TARGET_XOP"
10110   "vpmacsww\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10111   [(set_attr "type" "ssemuladd")
10112    (set_attr "mode" "TI")])
10113
10114 (define_insn "xop_pmacssww"
10115   [(set (match_operand:V8HI 0 "register_operand" "=x")
10116         (ss_plus:V8HI
10117          (mult:V8HI (match_operand:V8HI 1 "nonimmediate_operand" "%x")
10118                     (match_operand:V8HI 2 "nonimmediate_operand" "xm"))
10119          (match_operand:V8HI 3 "nonimmediate_operand" "x")))]
10120   "TARGET_XOP"
10121   "vpmacssww\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10122   [(set_attr "type" "ssemuladd")
10123    (set_attr "mode" "TI")])
10124
10125 (define_insn "xop_pmacsdd"
10126   [(set (match_operand:V4SI 0 "register_operand" "=x")
10127         (plus:V4SI
10128          (mult:V4SI
10129           (match_operand:V4SI 1 "nonimmediate_operand" "%x")
10130           (match_operand:V4SI 2 "nonimmediate_operand" "xm"))
10131          (match_operand:V4SI 3 "nonimmediate_operand" "x")))]
10132   "TARGET_XOP"
10133   "vpmacsdd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10134   [(set_attr "type" "ssemuladd")
10135    (set_attr "mode" "TI")])
10136
10137 (define_insn "xop_pmacssdd"
10138   [(set (match_operand:V4SI 0 "register_operand" "=x")
10139         (ss_plus:V4SI
10140          (mult:V4SI (match_operand:V4SI 1 "nonimmediate_operand" "%x")
10141                     (match_operand:V4SI 2 "nonimmediate_operand" "xm"))
10142          (match_operand:V4SI 3 "nonimmediate_operand" "x")))]
10143   "TARGET_XOP"
10144   "vpmacssdd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10145   [(set_attr "type" "ssemuladd")
10146    (set_attr "mode" "TI")])
10147
10148 (define_insn "xop_pmacssdql"
10149   [(set (match_operand:V2DI 0 "register_operand" "=x")
10150         (ss_plus:V2DI
10151          (mult:V2DI
10152           (sign_extend:V2DI
10153            (vec_select:V2SI
10154             (match_operand:V4SI 1 "nonimmediate_operand" "%x")
10155             (parallel [(const_int 1)
10156                        (const_int 3)])))
10157           (vec_select:V2SI
10158            (match_operand:V4SI 2 "nonimmediate_operand" "xm")
10159            (parallel [(const_int 1)
10160                       (const_int 3)])))
10161          (match_operand:V2DI 3 "nonimmediate_operand" "x")))]
10162   "TARGET_XOP"
10163   "vpmacssdql\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10164   [(set_attr "type" "ssemuladd")
10165    (set_attr "mode" "TI")])
10166
10167 (define_insn "xop_pmacssdqh"
10168   [(set (match_operand:V2DI 0 "register_operand" "=x")
10169         (ss_plus:V2DI
10170          (mult:V2DI
10171           (sign_extend:V2DI
10172            (vec_select:V2SI
10173             (match_operand:V4SI 1 "nonimmediate_operand" "%x")
10174             (parallel [(const_int 0)
10175                        (const_int 2)])))
10176           (sign_extend:V2DI
10177            (vec_select:V2SI
10178             (match_operand:V4SI 2 "nonimmediate_operand" "xm")
10179             (parallel [(const_int 0)
10180                        (const_int 2)]))))
10181          (match_operand:V2DI 3 "nonimmediate_operand" "x")))]
10182   "TARGET_XOP"
10183   "vpmacssdqh\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10184   [(set_attr "type" "ssemuladd")
10185    (set_attr "mode" "TI")])
10186
10187 (define_insn "xop_pmacsdql"
10188   [(set (match_operand:V2DI 0 "register_operand" "=x")
10189         (plus:V2DI
10190          (mult:V2DI
10191           (sign_extend:V2DI
10192            (vec_select:V2SI
10193             (match_operand:V4SI 1 "nonimmediate_operand" "%x")
10194             (parallel [(const_int 1)
10195                        (const_int 3)])))
10196           (sign_extend:V2DI
10197            (vec_select:V2SI
10198             (match_operand:V4SI 2 "nonimmediate_operand" "xm")
10199             (parallel [(const_int 1)
10200                        (const_int 3)]))))
10201          (match_operand:V2DI 3 "nonimmediate_operand" "x")))]
10202   "TARGET_XOP"
10203   "vpmacsdql\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10204   [(set_attr "type" "ssemuladd")
10205    (set_attr "mode" "TI")])
10206
10207 ;; We don't have a straight 32-bit parallel multiply and extend on XOP, so
10208 ;; fake it with a multiply/add.  In general, we expect the define_split to
10209 ;; occur before register allocation, so we have to handle the corner case where
10210 ;; the target is the same as operands 1/2
10211 (define_insn_and_split "xop_mulv2div2di3_low"
10212   [(set (match_operand:V2DI 0 "register_operand" "=&x")
10213         (mult:V2DI
10214           (sign_extend:V2DI
10215             (vec_select:V2SI
10216               (match_operand:V4SI 1 "register_operand" "%x")
10217               (parallel [(const_int 1)
10218                          (const_int 3)])))
10219           (sign_extend:V2DI
10220             (vec_select:V2SI
10221               (match_operand:V4SI 2 "nonimmediate_operand" "xm")
10222               (parallel [(const_int 1)
10223                          (const_int 3)])))))]
10224   "TARGET_XOP"
10225   "#"
10226   "&& reload_completed"
10227   [(set (match_dup 0)
10228         (match_dup 3))
10229    (set (match_dup 0)
10230         (plus:V2DI
10231          (mult:V2DI
10232           (sign_extend:V2DI
10233            (vec_select:V2SI
10234             (match_dup 1)
10235             (parallel [(const_int 1)
10236                        (const_int 3)])))
10237           (sign_extend:V2DI
10238            (vec_select:V2SI
10239             (match_dup 2)
10240             (parallel [(const_int 1)
10241                        (const_int 3)]))))
10242          (match_dup 0)))]
10243 {
10244   operands[3] = CONST0_RTX (V2DImode);
10245 }
10246   [(set_attr "type" "ssemul")
10247    (set_attr "mode" "TI")])
10248
10249 (define_insn "xop_pmacsdqh"
10250   [(set (match_operand:V2DI 0 "register_operand" "=x")
10251         (plus:V2DI
10252          (mult:V2DI
10253           (sign_extend:V2DI
10254            (vec_select:V2SI
10255             (match_operand:V4SI 1 "nonimmediate_operand" "%x")
10256             (parallel [(const_int 0)
10257                        (const_int 2)])))
10258           (sign_extend:V2DI
10259            (vec_select:V2SI
10260             (match_operand:V4SI 2 "nonimmediate_operand" "xm")
10261             (parallel [(const_int 0)
10262                        (const_int 2)]))))
10263          (match_operand:V2DI 3 "nonimmediate_operand" "x")))]
10264   "TARGET_XOP"
10265   "vpmacsdqh\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10266   [(set_attr "type" "ssemuladd")
10267    (set_attr "mode" "TI")])
10268
10269 ;; We don't have a straight 32-bit parallel multiply and extend on XOP, so
10270 ;; fake it with a multiply/add.  In general, we expect the define_split to
10271 ;; occur before register allocation, so we have to handle the corner case where
10272 ;; the target is the same as either operands[1] or operands[2]
10273 (define_insn_and_split "xop_mulv2div2di3_high"
10274   [(set (match_operand:V2DI 0 "register_operand" "=&x")
10275         (mult:V2DI
10276           (sign_extend:V2DI
10277             (vec_select:V2SI
10278               (match_operand:V4SI 1 "register_operand" "%x")
10279               (parallel [(const_int 0)
10280                          (const_int 2)])))
10281           (sign_extend:V2DI
10282             (vec_select:V2SI
10283               (match_operand:V4SI 2 "nonimmediate_operand" "xm")
10284               (parallel [(const_int 0)
10285                          (const_int 2)])))))]
10286   "TARGET_XOP"
10287   "#"
10288   "&& reload_completed"
10289   [(set (match_dup 0)
10290         (match_dup 3))
10291    (set (match_dup 0)
10292         (plus:V2DI
10293          (mult:V2DI
10294           (sign_extend:V2DI
10295            (vec_select:V2SI
10296             (match_dup 1)
10297             (parallel [(const_int 0)
10298                        (const_int 2)])))
10299           (sign_extend:V2DI
10300            (vec_select:V2SI
10301             (match_dup 2)
10302             (parallel [(const_int 0)
10303                        (const_int 2)]))))
10304          (match_dup 0)))]
10305 {
10306   operands[3] = CONST0_RTX (V2DImode);
10307 }
10308   [(set_attr "type" "ssemul")
10309    (set_attr "mode" "TI")])
10310
10311 ;; XOP parallel integer multiply/add instructions for the intrinisics
10312 (define_insn "xop_pmacsswd"
10313   [(set (match_operand:V4SI 0 "register_operand" "=x")
10314         (ss_plus:V4SI
10315          (mult:V4SI
10316           (sign_extend:V4SI
10317            (vec_select:V4HI
10318             (match_operand:V8HI 1 "nonimmediate_operand" "%x")
10319             (parallel [(const_int 1)
10320                        (const_int 3)
10321                        (const_int 5)
10322                        (const_int 7)])))
10323           (sign_extend:V4SI
10324            (vec_select:V4HI
10325             (match_operand:V8HI 2 "nonimmediate_operand" "xm")
10326             (parallel [(const_int 1)
10327                        (const_int 3)
10328                        (const_int 5)
10329                        (const_int 7)]))))
10330          (match_operand:V4SI 3 "nonimmediate_operand" "x")))]
10331   "TARGET_XOP"
10332   "vpmacsswd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10333   [(set_attr "type" "ssemuladd")
10334    (set_attr "mode" "TI")])
10335
10336 (define_insn "xop_pmacswd"
10337   [(set (match_operand:V4SI 0 "register_operand" "=x")
10338         (plus:V4SI
10339          (mult:V4SI
10340           (sign_extend:V4SI
10341            (vec_select:V4HI
10342             (match_operand:V8HI 1 "nonimmediate_operand" "%x")
10343             (parallel [(const_int 1)
10344                        (const_int 3)
10345                        (const_int 5)
10346                        (const_int 7)])))
10347           (sign_extend:V4SI
10348            (vec_select:V4HI
10349             (match_operand:V8HI 2 "nonimmediate_operand" "xm")
10350             (parallel [(const_int 1)
10351                        (const_int 3)
10352                        (const_int 5)
10353                        (const_int 7)]))))
10354          (match_operand:V4SI 3 "nonimmediate_operand" "x")))]
10355   "TARGET_XOP"
10356   "vpmacswd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10357   [(set_attr "type" "ssemuladd")
10358    (set_attr "mode" "TI")])
10359
10360 (define_insn "xop_pmadcsswd"
10361   [(set (match_operand:V4SI 0 "register_operand" "=x")
10362         (ss_plus:V4SI
10363          (plus:V4SI
10364           (mult:V4SI
10365            (sign_extend:V4SI
10366             (vec_select:V4HI
10367              (match_operand:V8HI 1 "nonimmediate_operand" "%x")
10368              (parallel [(const_int 0)
10369                         (const_int 2)
10370                         (const_int 4)
10371                         (const_int 6)])))
10372            (sign_extend:V4SI
10373             (vec_select:V4HI
10374              (match_operand:V8HI 2 "nonimmediate_operand" "xm")
10375              (parallel [(const_int 0)
10376                         (const_int 2)
10377                         (const_int 4)
10378                         (const_int 6)]))))
10379           (mult:V4SI
10380            (sign_extend:V4SI
10381             (vec_select:V4HI
10382              (match_dup 1)
10383              (parallel [(const_int 1)
10384                         (const_int 3)
10385                         (const_int 5)
10386                         (const_int 7)])))
10387            (sign_extend:V4SI
10388             (vec_select:V4HI
10389              (match_dup 2)
10390              (parallel [(const_int 1)
10391                         (const_int 3)
10392                         (const_int 5)
10393                         (const_int 7)])))))
10394          (match_operand:V4SI 3 "nonimmediate_operand" "x")))]
10395   "TARGET_XOP"
10396   "vpmadcsswd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10397   [(set_attr "type" "ssemuladd")
10398    (set_attr "mode" "TI")])
10399
10400 (define_insn "xop_pmadcswd"
10401   [(set (match_operand:V4SI 0 "register_operand" "=x")
10402         (plus:V4SI
10403          (plus:V4SI
10404           (mult:V4SI
10405            (sign_extend:V4SI
10406             (vec_select:V4HI
10407              (match_operand:V8HI 1 "nonimmediate_operand" "%x")
10408              (parallel [(const_int 0)
10409                         (const_int 2)
10410                         (const_int 4)
10411                         (const_int 6)])))
10412            (sign_extend:V4SI
10413             (vec_select:V4HI
10414              (match_operand:V8HI 2 "nonimmediate_operand" "xm")
10415              (parallel [(const_int 0)
10416                         (const_int 2)
10417                         (const_int 4)
10418                         (const_int 6)]))))
10419           (mult:V4SI
10420            (sign_extend:V4SI
10421             (vec_select:V4HI
10422              (match_dup 1)
10423              (parallel [(const_int 1)
10424                         (const_int 3)
10425                         (const_int 5)
10426                         (const_int 7)])))
10427            (sign_extend:V4SI
10428             (vec_select:V4HI
10429              (match_dup 2)
10430              (parallel [(const_int 1)
10431                         (const_int 3)
10432                         (const_int 5)
10433                         (const_int 7)])))))
10434          (match_operand:V4SI 3 "nonimmediate_operand" "x")))]
10435   "TARGET_XOP"
10436   "vpmadcswd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10437   [(set_attr "type" "ssemuladd")
10438    (set_attr "mode" "TI")])
10439
10440 ;; XOP parallel XMM conditional moves
10441 (define_insn "xop_pcmov_<mode><avxsizesuffix>"
10442   [(set (match_operand:V 0 "register_operand" "=x,x")
10443         (if_then_else:V
10444           (match_operand:V 3 "nonimmediate_operand" "x,m")
10445           (match_operand:V 1 "register_operand" "x,x")
10446           (match_operand:V 2 "nonimmediate_operand" "xm,x")))]
10447   "TARGET_XOP"
10448   "vpcmov\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10449   [(set_attr "type" "sse4arg")])
10450
10451 ;; XOP horizontal add/subtract instructions
10452 (define_insn "xop_phaddbw"
10453   [(set (match_operand:V8HI 0 "register_operand" "=x")
10454         (plus:V8HI
10455          (sign_extend:V8HI
10456           (vec_select:V8QI
10457            (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10458            (parallel [(const_int 0)
10459                       (const_int 2)
10460                       (const_int 4)
10461                       (const_int 6)
10462                       (const_int 8)
10463                       (const_int 10)
10464                       (const_int 12)
10465                       (const_int 14)])))
10466          (sign_extend:V8HI
10467           (vec_select:V8QI
10468            (match_dup 1)
10469            (parallel [(const_int 1)
10470                       (const_int 3)
10471                       (const_int 5)
10472                       (const_int 7)
10473                       (const_int 9)
10474                       (const_int 11)
10475                       (const_int 13)
10476                       (const_int 15)])))))]
10477   "TARGET_XOP"
10478   "vphaddbw\t{%1, %0|%0, %1}"
10479   [(set_attr "type" "sseiadd1")])
10480
10481 (define_insn "xop_phaddbd"
10482   [(set (match_operand:V4SI 0 "register_operand" "=x")
10483         (plus:V4SI
10484          (plus:V4SI
10485           (sign_extend:V4SI
10486            (vec_select:V4QI
10487             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10488             (parallel [(const_int 0)
10489                        (const_int 4)
10490                        (const_int 8)
10491                        (const_int 12)])))
10492           (sign_extend:V4SI
10493            (vec_select:V4QI
10494             (match_dup 1)
10495             (parallel [(const_int 1)
10496                        (const_int 5)
10497                        (const_int 9)
10498                        (const_int 13)]))))
10499          (plus:V4SI
10500           (sign_extend:V4SI
10501            (vec_select:V4QI
10502             (match_dup 1)
10503             (parallel [(const_int 2)
10504                        (const_int 6)
10505                        (const_int 10)
10506                        (const_int 14)])))
10507           (sign_extend:V4SI
10508            (vec_select:V4QI
10509             (match_dup 1)
10510             (parallel [(const_int 3)
10511                        (const_int 7)
10512                        (const_int 11)
10513                        (const_int 15)]))))))]
10514   "TARGET_XOP"
10515   "vphaddbd\t{%1, %0|%0, %1}"
10516   [(set_attr "type" "sseiadd1")])
10517
10518 (define_insn "xop_phaddbq"
10519   [(set (match_operand:V2DI 0 "register_operand" "=x")
10520         (plus:V2DI
10521          (plus:V2DI
10522           (plus:V2DI
10523            (sign_extend:V2DI
10524             (vec_select:V2QI
10525              (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10526              (parallel [(const_int 0)
10527                         (const_int 4)])))
10528            (sign_extend:V2DI
10529             (vec_select:V2QI
10530              (match_dup 1)
10531              (parallel [(const_int 1)
10532                         (const_int 5)]))))
10533           (plus:V2DI
10534            (sign_extend:V2DI
10535             (vec_select:V2QI
10536              (match_dup 1)
10537              (parallel [(const_int 2)
10538                         (const_int 6)])))
10539            (sign_extend:V2DI
10540             (vec_select:V2QI
10541              (match_dup 1)
10542              (parallel [(const_int 3)
10543                         (const_int 7)])))))
10544          (plus:V2DI
10545           (plus:V2DI
10546            (sign_extend:V2DI
10547             (vec_select:V2QI
10548              (match_dup 1)
10549              (parallel [(const_int 8)
10550                         (const_int 12)])))
10551            (sign_extend:V2DI
10552             (vec_select:V2QI
10553              (match_dup 1)
10554              (parallel [(const_int 9)
10555                         (const_int 13)]))))
10556           (plus:V2DI
10557            (sign_extend:V2DI
10558             (vec_select:V2QI
10559              (match_dup 1)
10560              (parallel [(const_int 10)
10561                         (const_int 14)])))
10562            (sign_extend:V2DI
10563             (vec_select:V2QI
10564              (match_dup 1)
10565              (parallel [(const_int 11)
10566                         (const_int 15)])))))))]
10567   "TARGET_XOP"
10568   "vphaddbq\t{%1, %0|%0, %1}"
10569   [(set_attr "type" "sseiadd1")])
10570
10571 (define_insn "xop_phaddwd"
10572   [(set (match_operand:V4SI 0 "register_operand" "=x")
10573         (plus:V4SI
10574          (sign_extend:V4SI
10575           (vec_select:V4HI
10576            (match_operand:V8HI 1 "nonimmediate_operand" "xm")
10577            (parallel [(const_int 0)
10578                       (const_int 2)
10579                       (const_int 4)
10580                       (const_int 6)])))
10581          (sign_extend:V4SI
10582           (vec_select:V4HI
10583            (match_dup 1)
10584            (parallel [(const_int 1)
10585                       (const_int 3)
10586                       (const_int 5)
10587                       (const_int 7)])))))]
10588   "TARGET_XOP"
10589   "vphaddwd\t{%1, %0|%0, %1}"
10590   [(set_attr "type" "sseiadd1")])
10591
10592 (define_insn "xop_phaddwq"
10593   [(set (match_operand:V2DI 0 "register_operand" "=x")
10594         (plus:V2DI
10595          (plus:V2DI
10596           (sign_extend:V2DI
10597            (vec_select:V2HI
10598             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
10599             (parallel [(const_int 0)
10600                        (const_int 4)])))
10601           (sign_extend:V2DI
10602            (vec_select:V2HI
10603             (match_dup 1)
10604             (parallel [(const_int 1)
10605                        (const_int 5)]))))
10606          (plus:V2DI
10607           (sign_extend:V2DI
10608            (vec_select:V2HI
10609             (match_dup 1)
10610             (parallel [(const_int 2)
10611                        (const_int 6)])))
10612           (sign_extend:V2DI
10613            (vec_select:V2HI
10614             (match_dup 1)
10615             (parallel [(const_int 3)
10616                        (const_int 7)]))))))]
10617   "TARGET_XOP"
10618   "vphaddwq\t{%1, %0|%0, %1}"
10619   [(set_attr "type" "sseiadd1")])
10620
10621 (define_insn "xop_phadddq"
10622   [(set (match_operand:V2DI 0 "register_operand" "=x")
10623         (plus:V2DI
10624          (sign_extend:V2DI
10625           (vec_select:V2SI
10626            (match_operand:V4SI 1 "nonimmediate_operand" "xm")
10627            (parallel [(const_int 0)
10628                       (const_int 2)])))
10629          (sign_extend:V2DI
10630           (vec_select:V2SI
10631            (match_dup 1)
10632            (parallel [(const_int 1)
10633                       (const_int 3)])))))]
10634   "TARGET_XOP"
10635   "vphadddq\t{%1, %0|%0, %1}"
10636   [(set_attr "type" "sseiadd1")])
10637
10638 (define_insn "xop_phaddubw"
10639   [(set (match_operand:V8HI 0 "register_operand" "=x")
10640         (plus:V8HI
10641          (zero_extend:V8HI
10642           (vec_select:V8QI
10643            (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10644            (parallel [(const_int 0)
10645                       (const_int 2)
10646                       (const_int 4)
10647                       (const_int 6)
10648                       (const_int 8)
10649                       (const_int 10)
10650                       (const_int 12)
10651                       (const_int 14)])))
10652          (zero_extend:V8HI
10653           (vec_select:V8QI
10654            (match_dup 1)
10655            (parallel [(const_int 1)
10656                       (const_int 3)
10657                       (const_int 5)
10658                       (const_int 7)
10659                       (const_int 9)
10660                       (const_int 11)
10661                       (const_int 13)
10662                       (const_int 15)])))))]
10663   "TARGET_XOP"
10664   "vphaddubw\t{%1, %0|%0, %1}"
10665   [(set_attr "type" "sseiadd1")])
10666
10667 (define_insn "xop_phaddubd"
10668   [(set (match_operand:V4SI 0 "register_operand" "=x")
10669         (plus:V4SI
10670          (plus:V4SI
10671           (zero_extend:V4SI
10672            (vec_select:V4QI
10673             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10674             (parallel [(const_int 0)
10675                        (const_int 4)
10676                        (const_int 8)
10677                        (const_int 12)])))
10678           (zero_extend:V4SI
10679            (vec_select:V4QI
10680             (match_dup 1)
10681             (parallel [(const_int 1)
10682                        (const_int 5)
10683                        (const_int 9)
10684                        (const_int 13)]))))
10685          (plus:V4SI
10686           (zero_extend:V4SI
10687            (vec_select:V4QI
10688             (match_dup 1)
10689             (parallel [(const_int 2)
10690                        (const_int 6)
10691                        (const_int 10)
10692                        (const_int 14)])))
10693           (zero_extend:V4SI
10694            (vec_select:V4QI
10695             (match_dup 1)
10696             (parallel [(const_int 3)
10697                        (const_int 7)
10698                        (const_int 11)
10699                        (const_int 15)]))))))]
10700   "TARGET_XOP"
10701   "vphaddubd\t{%1, %0|%0, %1}"
10702   [(set_attr "type" "sseiadd1")])
10703
10704 (define_insn "xop_phaddubq"
10705   [(set (match_operand:V2DI 0 "register_operand" "=x")
10706         (plus:V2DI
10707          (plus:V2DI
10708           (plus:V2DI
10709            (zero_extend:V2DI
10710             (vec_select:V2QI
10711              (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10712              (parallel [(const_int 0)
10713                         (const_int 4)])))
10714            (sign_extend:V2DI
10715             (vec_select:V2QI
10716              (match_dup 1)
10717              (parallel [(const_int 1)
10718                         (const_int 5)]))))
10719           (plus:V2DI
10720            (zero_extend:V2DI
10721             (vec_select:V2QI
10722              (match_dup 1)
10723              (parallel [(const_int 2)
10724                         (const_int 6)])))
10725            (zero_extend:V2DI
10726             (vec_select:V2QI
10727              (match_dup 1)
10728              (parallel [(const_int 3)
10729                         (const_int 7)])))))
10730          (plus:V2DI
10731           (plus:V2DI
10732            (zero_extend:V2DI
10733             (vec_select:V2QI
10734              (match_dup 1)
10735              (parallel [(const_int 8)
10736                         (const_int 12)])))
10737            (sign_extend:V2DI
10738             (vec_select:V2QI
10739              (match_dup 1)
10740              (parallel [(const_int 9)
10741                         (const_int 13)]))))
10742           (plus:V2DI
10743            (zero_extend:V2DI
10744             (vec_select:V2QI
10745              (match_dup 1)
10746              (parallel [(const_int 10)
10747                         (const_int 14)])))
10748            (zero_extend:V2DI
10749             (vec_select:V2QI
10750              (match_dup 1)
10751              (parallel [(const_int 11)
10752                         (const_int 15)])))))))]
10753   "TARGET_XOP"
10754   "vphaddubq\t{%1, %0|%0, %1}"
10755   [(set_attr "type" "sseiadd1")])
10756
10757 (define_insn "xop_phadduwd"
10758   [(set (match_operand:V4SI 0 "register_operand" "=x")
10759         (plus:V4SI
10760          (zero_extend:V4SI
10761           (vec_select:V4HI
10762            (match_operand:V8HI 1 "nonimmediate_operand" "xm")
10763            (parallel [(const_int 0)
10764                       (const_int 2)
10765                       (const_int 4)
10766                       (const_int 6)])))
10767          (zero_extend:V4SI
10768           (vec_select:V4HI
10769            (match_dup 1)
10770            (parallel [(const_int 1)
10771                       (const_int 3)
10772                       (const_int 5)
10773                       (const_int 7)])))))]
10774   "TARGET_XOP"
10775   "vphadduwd\t{%1, %0|%0, %1}"
10776   [(set_attr "type" "sseiadd1")])
10777
10778 (define_insn "xop_phadduwq"
10779   [(set (match_operand:V2DI 0 "register_operand" "=x")
10780         (plus:V2DI
10781          (plus:V2DI
10782           (zero_extend:V2DI
10783            (vec_select:V2HI
10784             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
10785             (parallel [(const_int 0)
10786                        (const_int 4)])))
10787           (zero_extend:V2DI
10788            (vec_select:V2HI
10789             (match_dup 1)
10790             (parallel [(const_int 1)
10791                        (const_int 5)]))))
10792          (plus:V2DI
10793           (zero_extend:V2DI
10794            (vec_select:V2HI
10795             (match_dup 1)
10796             (parallel [(const_int 2)
10797                        (const_int 6)])))
10798           (zero_extend:V2DI
10799            (vec_select:V2HI
10800             (match_dup 1)
10801             (parallel [(const_int 3)
10802                        (const_int 7)]))))))]
10803   "TARGET_XOP"
10804   "vphadduwq\t{%1, %0|%0, %1}"
10805   [(set_attr "type" "sseiadd1")])
10806
10807 (define_insn "xop_phaddudq"
10808   [(set (match_operand:V2DI 0 "register_operand" "=x")
10809         (plus:V2DI
10810          (zero_extend:V2DI
10811           (vec_select:V2SI
10812            (match_operand:V4SI 1 "nonimmediate_operand" "xm")
10813            (parallel [(const_int 0)
10814                       (const_int 2)])))
10815          (zero_extend:V2DI
10816           (vec_select:V2SI
10817            (match_dup 1)
10818            (parallel [(const_int 1)
10819                       (const_int 3)])))))]
10820   "TARGET_XOP"
10821   "vphaddudq\t{%1, %0|%0, %1}"
10822   [(set_attr "type" "sseiadd1")])
10823
10824 (define_insn "xop_phsubbw"
10825   [(set (match_operand:V8HI 0 "register_operand" "=x")
10826         (minus:V8HI
10827          (sign_extend:V8HI
10828           (vec_select:V8QI
10829            (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10830            (parallel [(const_int 0)
10831                       (const_int 2)
10832                       (const_int 4)
10833                       (const_int 6)
10834                       (const_int 8)
10835                       (const_int 10)
10836                       (const_int 12)
10837                       (const_int 14)])))
10838          (sign_extend:V8HI
10839           (vec_select:V8QI
10840            (match_dup 1)
10841            (parallel [(const_int 1)
10842                       (const_int 3)
10843                       (const_int 5)
10844                       (const_int 7)
10845                       (const_int 9)
10846                       (const_int 11)
10847                       (const_int 13)
10848                       (const_int 15)])))))]
10849   "TARGET_XOP"
10850   "vphsubbw\t{%1, %0|%0, %1}"
10851   [(set_attr "type" "sseiadd1")])
10852
10853 (define_insn "xop_phsubwd"
10854   [(set (match_operand:V4SI 0 "register_operand" "=x")
10855         (minus:V4SI
10856          (sign_extend:V4SI
10857           (vec_select:V4HI
10858            (match_operand:V8HI 1 "nonimmediate_operand" "xm")
10859            (parallel [(const_int 0)
10860                       (const_int 2)
10861                       (const_int 4)
10862                       (const_int 6)])))
10863          (sign_extend:V4SI
10864           (vec_select:V4HI
10865            (match_dup 1)
10866            (parallel [(const_int 1)
10867                       (const_int 3)
10868                       (const_int 5)
10869                       (const_int 7)])))))]
10870   "TARGET_XOP"
10871   "vphsubwd\t{%1, %0|%0, %1}"
10872   [(set_attr "type" "sseiadd1")])
10873
10874 (define_insn "xop_phsubdq"
10875   [(set (match_operand:V2DI 0 "register_operand" "=x")
10876         (minus:V2DI
10877          (sign_extend:V2DI
10878           (vec_select:V2SI
10879            (match_operand:V4SI 1 "nonimmediate_operand" "xm")
10880            (parallel [(const_int 0)
10881                       (const_int 2)])))
10882          (sign_extend:V2DI
10883           (vec_select:V2SI
10884            (match_dup 1)
10885            (parallel [(const_int 1)
10886                       (const_int 3)])))))]
10887   "TARGET_XOP"
10888   "vphsubdq\t{%1, %0|%0, %1}"
10889   [(set_attr "type" "sseiadd1")])
10890
10891 ;; XOP permute instructions
10892 (define_insn "xop_pperm"
10893   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
10894         (unspec:V16QI
10895           [(match_operand:V16QI 1 "register_operand" "x,x")
10896            (match_operand:V16QI 2 "nonimmediate_operand" "x,m")
10897            (match_operand:V16QI 3 "nonimmediate_operand" "xm,x")]
10898           UNSPEC_XOP_PERMUTE))]
10899   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
10900   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10901   [(set_attr "type" "sse4arg")
10902    (set_attr "mode" "TI")])
10903
10904 ;; XOP pack instructions that combine two vectors into a smaller vector
10905 (define_insn "xop_pperm_pack_v2di_v4si"
10906   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
10907         (vec_concat:V4SI
10908          (truncate:V2SI
10909           (match_operand:V2DI 1 "register_operand" "x,x"))
10910          (truncate:V2SI
10911           (match_operand:V2DI 2 "nonimmediate_operand" "x,m"))))
10912    (use (match_operand:V16QI 3 "nonimmediate_operand" "xm,x"))]
10913   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
10914   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10915   [(set_attr "type" "sse4arg")
10916    (set_attr "mode" "TI")])
10917
10918 (define_insn "xop_pperm_pack_v4si_v8hi"
10919   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
10920         (vec_concat:V8HI
10921          (truncate:V4HI
10922           (match_operand:V4SI 1 "register_operand" "x,x"))
10923          (truncate:V4HI
10924           (match_operand:V4SI 2 "nonimmediate_operand" "x,m"))))
10925    (use (match_operand:V16QI 3 "nonimmediate_operand" "xm,x"))]
10926   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
10927   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10928   [(set_attr "type" "sse4arg")
10929    (set_attr "mode" "TI")])
10930
10931 (define_insn "xop_pperm_pack_v8hi_v16qi"
10932   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
10933         (vec_concat:V16QI
10934          (truncate:V8QI
10935           (match_operand:V8HI 1 "register_operand" "x,x"))
10936          (truncate:V8QI
10937           (match_operand:V8HI 2 "nonimmediate_operand" "x,m"))))
10938    (use (match_operand:V16QI 3 "nonimmediate_operand" "xm,x"))]
10939   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
10940   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10941   [(set_attr "type" "sse4arg")
10942    (set_attr "mode" "TI")])
10943
10944 ;; XOP packed rotate instructions
10945 (define_expand "rotl<mode>3"
10946   [(set (match_operand:VI_128 0 "register_operand" "")
10947         (rotate:VI_128
10948          (match_operand:VI_128 1 "nonimmediate_operand" "")
10949          (match_operand:SI 2 "general_operand")))]
10950   "TARGET_XOP"
10951 {
10952   /* If we were given a scalar, convert it to parallel */
10953   if (! const_0_to_<sserotatemax>_operand (operands[2], SImode))
10954     {
10955       rtvec vs = rtvec_alloc (<ssescalarnum>);
10956       rtx par = gen_rtx_PARALLEL (<MODE>mode, vs);
10957       rtx reg = gen_reg_rtx (<MODE>mode);
10958       rtx op2 = operands[2];
10959       int i;
10960
10961       if (GET_MODE (op2) != <ssescalarmode>mode)
10962         {
10963           op2 = gen_reg_rtx (<ssescalarmode>mode);
10964           convert_move (op2, operands[2], false);
10965         }
10966
10967       for (i = 0; i < <ssescalarnum>; i++)
10968         RTVEC_ELT (vs, i) = op2;
10969
10970       emit_insn (gen_vec_init<mode> (reg, par));
10971       emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], reg));
10972       DONE;
10973     }
10974 })
10975
10976 (define_expand "rotr<mode>3"
10977   [(set (match_operand:VI_128 0 "register_operand" "")
10978         (rotatert:VI_128
10979          (match_operand:VI_128 1 "nonimmediate_operand" "")
10980          (match_operand:SI 2 "general_operand")))]
10981   "TARGET_XOP"
10982 {
10983   /* If we were given a scalar, convert it to parallel */
10984   if (! const_0_to_<sserotatemax>_operand (operands[2], SImode))
10985     {
10986       rtvec vs = rtvec_alloc (<ssescalarnum>);
10987       rtx par = gen_rtx_PARALLEL (<MODE>mode, vs);
10988       rtx neg = gen_reg_rtx (<MODE>mode);
10989       rtx reg = gen_reg_rtx (<MODE>mode);
10990       rtx op2 = operands[2];
10991       int i;
10992
10993       if (GET_MODE (op2) != <ssescalarmode>mode)
10994         {
10995           op2 = gen_reg_rtx (<ssescalarmode>mode);
10996           convert_move (op2, operands[2], false);
10997         }
10998
10999       for (i = 0; i < <ssescalarnum>; i++)
11000         RTVEC_ELT (vs, i) = op2;
11001
11002       emit_insn (gen_vec_init<mode> (reg, par));
11003       emit_insn (gen_neg<mode>2 (neg, reg));
11004       emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], neg));
11005       DONE;
11006     }
11007 })
11008
11009 (define_insn "xop_rotl<mode>3"
11010   [(set (match_operand:VI_128 0 "register_operand" "=x")
11011         (rotate:VI_128
11012          (match_operand:VI_128 1 "nonimmediate_operand" "xm")
11013          (match_operand:SI 2 "const_0_to_<sserotatemax>_operand" "n")))]
11014   "TARGET_XOP"
11015   "vprot<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11016   [(set_attr "type" "sseishft")
11017    (set_attr "length_immediate" "1")
11018    (set_attr "mode" "TI")])
11019
11020 (define_insn "xop_rotr<mode>3"
11021   [(set (match_operand:VI_128 0 "register_operand" "=x")
11022         (rotatert:VI_128
11023          (match_operand:VI_128 1 "nonimmediate_operand" "xm")
11024          (match_operand:SI 2 "const_0_to_<sserotatemax>_operand" "n")))]
11025   "TARGET_XOP"
11026 {
11027   operands[3] = GEN_INT ((<ssescalarnum> * 8) - INTVAL (operands[2]));
11028   return \"vprot<ssemodesuffix>\t{%3, %1, %0|%0, %1, %3}\";
11029 }
11030   [(set_attr "type" "sseishft")
11031    (set_attr "length_immediate" "1")
11032    (set_attr "mode" "TI")])
11033
11034 (define_expand "vrotr<mode>3"
11035   [(match_operand:VI_128 0 "register_operand" "")
11036    (match_operand:VI_128 1 "register_operand" "")
11037    (match_operand:VI_128 2 "register_operand" "")]
11038   "TARGET_XOP"
11039 {
11040   rtx reg = gen_reg_rtx (<MODE>mode);
11041   emit_insn (gen_neg<mode>2 (reg, operands[2]));
11042   emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], reg));
11043   DONE;
11044 })
11045
11046 (define_expand "vrotl<mode>3"
11047   [(match_operand:VI_128 0 "register_operand" "")
11048    (match_operand:VI_128 1 "register_operand" "")
11049    (match_operand:VI_128 2 "register_operand" "")]
11050   "TARGET_XOP"
11051 {
11052   emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], operands[2]));
11053   DONE;
11054 })
11055
11056 (define_insn "xop_vrotl<mode>3"
11057   [(set (match_operand:VI_128 0 "register_operand" "=x,x")
11058         (if_then_else:VI_128
11059          (ge:VI_128
11060           (match_operand:VI_128 2 "nonimmediate_operand" "x,m")
11061           (const_int 0))
11062          (rotate:VI_128
11063           (match_operand:VI_128 1 "nonimmediate_operand" "xm,x")
11064           (match_dup 2))
11065          (rotatert:VI_128
11066           (match_dup 1)
11067           (neg:VI_128 (match_dup 2)))))]
11068   "TARGET_XOP && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
11069   "vprot<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11070   [(set_attr "type" "sseishft")
11071    (set_attr "prefix_data16" "0")
11072    (set_attr "prefix_extra" "2")
11073    (set_attr "mode" "TI")])
11074
11075 ;; XOP packed shift instructions.
11076 ;; FIXME: add V2DI back in
11077 (define_expand "vlshr<mode>3"
11078   [(match_operand:VI124_128 0 "register_operand" "")
11079    (match_operand:VI124_128 1 "register_operand" "")
11080    (match_operand:VI124_128 2 "register_operand" "")]
11081   "TARGET_XOP"
11082 {
11083   rtx neg = gen_reg_rtx (<MODE>mode);
11084   emit_insn (gen_neg<mode>2 (neg, operands[2]));
11085   emit_insn (gen_xop_lshl<mode>3 (operands[0], operands[1], neg));
11086   DONE;
11087 })
11088
11089 (define_expand "vashr<mode>3"
11090   [(match_operand:VI124_128 0 "register_operand" "")
11091    (match_operand:VI124_128 1 "register_operand" "")
11092    (match_operand:VI124_128 2 "register_operand" "")]
11093   "TARGET_XOP"
11094 {
11095   rtx neg = gen_reg_rtx (<MODE>mode);
11096   emit_insn (gen_neg<mode>2 (neg, operands[2]));
11097   emit_insn (gen_xop_ashl<mode>3 (operands[0], operands[1], neg));
11098   DONE;
11099 })
11100
11101 (define_expand "vashl<mode>3"
11102   [(match_operand:VI124_128 0 "register_operand" "")
11103    (match_operand:VI124_128 1 "register_operand" "")
11104    (match_operand:VI124_128 2 "register_operand" "")]
11105   "TARGET_XOP"
11106 {
11107   emit_insn (gen_xop_ashl<mode>3 (operands[0], operands[1], operands[2]));
11108   DONE;
11109 })
11110
11111 (define_insn "xop_ashl<mode>3"
11112   [(set (match_operand:VI_128 0 "register_operand" "=x,x")
11113         (if_then_else:VI_128
11114          (ge:VI_128
11115           (match_operand:VI_128 2 "nonimmediate_operand" "x,m")
11116           (const_int 0))
11117          (ashift:VI_128
11118           (match_operand:VI_128 1 "nonimmediate_operand" "xm,x")
11119           (match_dup 2))
11120          (ashiftrt:VI_128
11121           (match_dup 1)
11122           (neg:VI_128 (match_dup 2)))))]
11123   "TARGET_XOP && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
11124   "vpsha<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11125   [(set_attr "type" "sseishft")
11126    (set_attr "prefix_data16" "0")
11127    (set_attr "prefix_extra" "2")
11128    (set_attr "mode" "TI")])
11129
11130 (define_insn "xop_lshl<mode>3"
11131   [(set (match_operand:VI_128 0 "register_operand" "=x,x")
11132         (if_then_else:VI_128
11133          (ge:VI_128
11134           (match_operand:VI_128 2 "nonimmediate_operand" "x,m")
11135           (const_int 0))
11136          (ashift:VI_128
11137           (match_operand:VI_128 1 "nonimmediate_operand" "xm,x")
11138           (match_dup 2))
11139          (lshiftrt:VI_128
11140           (match_dup 1)
11141           (neg:VI_128 (match_dup 2)))))]
11142   "TARGET_XOP && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
11143   "vpshl<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11144   [(set_attr "type" "sseishft")
11145    (set_attr "prefix_data16" "0")
11146    (set_attr "prefix_extra" "2")
11147    (set_attr "mode" "TI")])
11148
11149 ;; SSE2 doesn't have some shift varients, so define versions for XOP
11150 (define_expand "ashlv16qi3"
11151   [(match_operand:V16QI 0 "register_operand" "")
11152    (match_operand:V16QI 1 "register_operand" "")
11153    (match_operand:SI 2 "nonmemory_operand" "")]
11154   "TARGET_XOP"
11155 {
11156   rtvec vs = rtvec_alloc (16);
11157   rtx par = gen_rtx_PARALLEL (V16QImode, vs);
11158   rtx reg = gen_reg_rtx (V16QImode);
11159   int i;
11160   for (i = 0; i < 16; i++)
11161     RTVEC_ELT (vs, i) = operands[2];
11162
11163   emit_insn (gen_vec_initv16qi (reg, par));
11164   emit_insn (gen_xop_ashlv16qi3 (operands[0], operands[1], reg));
11165   DONE;
11166 })
11167
11168 (define_expand "lshlv16qi3"
11169   [(match_operand:V16QI 0 "register_operand" "")
11170    (match_operand:V16QI 1 "register_operand" "")
11171    (match_operand:SI 2 "nonmemory_operand" "")]
11172   "TARGET_XOP"
11173 {
11174   rtvec vs = rtvec_alloc (16);
11175   rtx par = gen_rtx_PARALLEL (V16QImode, vs);
11176   rtx reg = gen_reg_rtx (V16QImode);
11177   int i;
11178   for (i = 0; i < 16; i++)
11179     RTVEC_ELT (vs, i) = operands[2];
11180
11181   emit_insn (gen_vec_initv16qi (reg, par));
11182   emit_insn (gen_xop_lshlv16qi3 (operands[0], operands[1], reg));
11183   DONE;
11184 })
11185
11186 (define_expand "ashrv16qi3"
11187   [(match_operand:V16QI 0 "register_operand" "")
11188    (match_operand:V16QI 1 "register_operand" "")
11189    (match_operand:SI 2 "nonmemory_operand" "")]
11190   "TARGET_XOP"
11191 {
11192   rtvec vs = rtvec_alloc (16);
11193   rtx par = gen_rtx_PARALLEL (V16QImode, vs);
11194   rtx reg = gen_reg_rtx (V16QImode);
11195   int i;
11196   rtx ele = ((CONST_INT_P (operands[2]))
11197              ? GEN_INT (- INTVAL (operands[2]))
11198              : operands[2]);
11199
11200   for (i = 0; i < 16; i++)
11201     RTVEC_ELT (vs, i) = ele;
11202
11203   emit_insn (gen_vec_initv16qi (reg, par));
11204
11205   if (!CONST_INT_P (operands[2]))
11206     {
11207       rtx neg = gen_reg_rtx (V16QImode);
11208       emit_insn (gen_negv16qi2 (neg, reg));
11209       emit_insn (gen_xop_ashlv16qi3 (operands[0], operands[1], neg));
11210     }
11211   else
11212     emit_insn (gen_xop_ashlv16qi3 (operands[0], operands[1], reg));
11213
11214   DONE;
11215 })
11216
11217 (define_expand "ashrv2di3"
11218   [(match_operand:V2DI 0 "register_operand" "")
11219    (match_operand:V2DI 1 "register_operand" "")
11220    (match_operand:DI 2 "nonmemory_operand" "")]
11221   "TARGET_XOP"
11222 {
11223   rtvec vs = rtvec_alloc (2);
11224   rtx par = gen_rtx_PARALLEL (V2DImode, vs);
11225   rtx reg = gen_reg_rtx (V2DImode);
11226   rtx ele;
11227
11228   if (CONST_INT_P (operands[2]))
11229     ele = GEN_INT (- INTVAL (operands[2]));
11230   else if (GET_MODE (operands[2]) != DImode)
11231     {
11232       rtx move = gen_reg_rtx (DImode);
11233       ele = gen_reg_rtx (DImode);
11234       convert_move (move, operands[2], false);
11235       emit_insn (gen_negdi2 (ele, move));
11236     }
11237   else
11238     {
11239       ele = gen_reg_rtx (DImode);
11240       emit_insn (gen_negdi2 (ele, operands[2]));
11241     }
11242
11243   RTVEC_ELT (vs, 0) = ele;
11244   RTVEC_ELT (vs, 1) = ele;
11245   emit_insn (gen_vec_initv2di (reg, par));
11246   emit_insn (gen_xop_ashlv2di3 (operands[0], operands[1], reg));
11247   DONE;
11248 })
11249
11250 ;; XOP FRCZ support
11251 (define_insn "xop_frcz<mode>2"
11252   [(set (match_operand:FMAMODE 0 "register_operand" "=x")
11253         (unspec:FMAMODE
11254          [(match_operand:FMAMODE 1 "nonimmediate_operand" "xm")]
11255          UNSPEC_FRCZ))]
11256   "TARGET_XOP"
11257   "vfrcz<ssemodesuffix>\t{%1, %0|%0, %1}"
11258   [(set_attr "type" "ssecvt1")
11259    (set_attr "mode" "<MODE>")])
11260
11261 ;; scalar insns
11262 (define_expand "xop_vmfrcz<mode>2"
11263   [(set (match_operand:VF_128 0 "register_operand")
11264         (vec_merge:VF_128
11265           (unspec:VF_128
11266            [(match_operand:VF_128 1 "nonimmediate_operand")]
11267            UNSPEC_FRCZ)
11268           (match_dup 3)
11269           (const_int 1)))]
11270   "TARGET_XOP"
11271 {
11272   operands[3] = CONST0_RTX (<MODE>mode);
11273 })
11274
11275 (define_insn "*xop_vmfrcz_<mode>"
11276   [(set (match_operand:VF_128 0 "register_operand" "=x")
11277         (vec_merge:VF_128
11278           (unspec:VF_128
11279            [(match_operand:VF_128 1 "nonimmediate_operand" "xm")]
11280            UNSPEC_FRCZ)
11281           (match_operand:VF_128 2 "const0_operand")
11282           (const_int 1)))]
11283   "TARGET_XOP"
11284   "vfrcz<ssescalarmodesuffix>\t{%1, %0|%0, %1}"
11285   [(set_attr "type" "ssecvt1")
11286    (set_attr "mode" "<MODE>")])
11287
11288 (define_insn "xop_maskcmp<mode>3"
11289   [(set (match_operand:VI_128 0 "register_operand" "=x")
11290         (match_operator:VI_128 1 "ix86_comparison_int_operator"
11291          [(match_operand:VI_128 2 "register_operand" "x")
11292           (match_operand:VI_128 3 "nonimmediate_operand" "xm")]))]
11293   "TARGET_XOP"
11294   "vpcom%Y1<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}"
11295   [(set_attr "type" "sse4arg")
11296    (set_attr "prefix_data16" "0")
11297    (set_attr "prefix_rep" "0")
11298    (set_attr "prefix_extra" "2")
11299    (set_attr "length_immediate" "1")
11300    (set_attr "mode" "TI")])
11301
11302 (define_insn "xop_maskcmp_uns<mode>3"
11303   [(set (match_operand:VI_128 0 "register_operand" "=x")
11304         (match_operator:VI_128 1 "ix86_comparison_uns_operator"
11305          [(match_operand:VI_128 2 "register_operand" "x")
11306           (match_operand:VI_128 3 "nonimmediate_operand" "xm")]))]
11307   "TARGET_XOP"
11308   "vpcom%Y1u<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}"
11309   [(set_attr "type" "ssecmp")
11310    (set_attr "prefix_data16" "0")
11311    (set_attr "prefix_rep" "0")
11312    (set_attr "prefix_extra" "2")
11313    (set_attr "length_immediate" "1")
11314    (set_attr "mode" "TI")])
11315
11316 ;; Version of pcom*u* that is called from the intrinsics that allows pcomequ*
11317 ;; and pcomneu* not to be converted to the signed ones in case somebody needs
11318 ;; the exact instruction generated for the intrinsic.
11319 (define_insn "xop_maskcmp_uns2<mode>3"
11320   [(set (match_operand:VI_128 0 "register_operand" "=x")
11321         (unspec:VI_128
11322          [(match_operator:VI_128 1 "ix86_comparison_uns_operator"
11323           [(match_operand:VI_128 2 "register_operand" "x")
11324            (match_operand:VI_128 3 "nonimmediate_operand" "xm")])]
11325          UNSPEC_XOP_UNSIGNED_CMP))]
11326   "TARGET_XOP"
11327   "vpcom%Y1u<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}"
11328   [(set_attr "type" "ssecmp")
11329    (set_attr "prefix_data16" "0")
11330    (set_attr "prefix_extra" "2")
11331    (set_attr "length_immediate" "1")
11332    (set_attr "mode" "TI")])
11333
11334 ;; Pcomtrue and pcomfalse support.  These are useless instructions, but are
11335 ;; being added here to be complete.
11336 (define_insn "xop_pcom_tf<mode>3"
11337   [(set (match_operand:VI_128 0 "register_operand" "=x")
11338         (unspec:VI_128
11339           [(match_operand:VI_128 1 "register_operand" "x")
11340            (match_operand:VI_128 2 "nonimmediate_operand" "xm")
11341            (match_operand:SI 3 "const_int_operand" "n")]
11342           UNSPEC_XOP_TRUEFALSE))]
11343   "TARGET_XOP"
11344 {
11345   return ((INTVAL (operands[3]) != 0)
11346           ? "vpcomtrue<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11347           : "vpcomfalse<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}");
11348 }
11349   [(set_attr "type" "ssecmp")
11350    (set_attr "prefix_data16" "0")
11351    (set_attr "prefix_extra" "2")
11352    (set_attr "length_immediate" "1")
11353    (set_attr "mode" "TI")])
11354
11355 (define_insn "xop_vpermil2<mode>3"
11356   [(set (match_operand:VF 0 "register_operand" "=x")
11357         (unspec:VF
11358           [(match_operand:VF 1 "register_operand" "x")
11359            (match_operand:VF 2 "nonimmediate_operand" "%x")
11360            (match_operand:<sseintvecmode> 3 "nonimmediate_operand" "xm")
11361            (match_operand:SI 4 "const_0_to_3_operand" "n")]
11362           UNSPEC_VPERMIL2))]
11363   "TARGET_XOP"
11364   "vpermil2<ssemodesuffix>\t{%4, %3, %2, %1, %0|%0, %1, %2, %3, %4}"
11365   [(set_attr "type" "sse4arg")
11366    (set_attr "length_immediate" "1")
11367    (set_attr "mode" "<MODE>")])
11368
11369 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11370
11371 (define_insn "aesenc"
11372   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
11373         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
11374                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
11375                       UNSPEC_AESENC))]
11376   "TARGET_AES"
11377   "@
11378    aesenc\t{%2, %0|%0, %2}
11379    vaesenc\t{%2, %1, %0|%0, %1, %2}"
11380   [(set_attr "isa" "noavx,avx")
11381    (set_attr "type" "sselog1")
11382    (set_attr "prefix_extra" "1")
11383    (set_attr "prefix" "orig,vex")
11384    (set_attr "mode" "TI")])
11385
11386 (define_insn "aesenclast"
11387   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
11388         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
11389                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
11390                       UNSPEC_AESENCLAST))]
11391   "TARGET_AES"
11392   "@
11393    aesenclast\t{%2, %0|%0, %2}
11394    vaesenclast\t{%2, %1, %0|%0, %1, %2}"
11395   [(set_attr "isa" "noavx,avx")
11396    (set_attr "type" "sselog1")
11397    (set_attr "prefix_extra" "1")
11398    (set_attr "prefix" "orig,vex")
11399    (set_attr "mode" "TI")])
11400
11401 (define_insn "aesdec"
11402   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
11403         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
11404                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
11405                       UNSPEC_AESDEC))]
11406   "TARGET_AES"
11407   "@
11408    aesdec\t{%2, %0|%0, %2}
11409    vaesdec\t{%2, %1, %0|%0, %1, %2}"
11410   [(set_attr "isa" "noavx,avx")
11411    (set_attr "type" "sselog1")
11412    (set_attr "prefix_extra" "1")
11413    (set_attr "prefix" "orig,vex")
11414    (set_attr "mode" "TI")])
11415
11416 (define_insn "aesdeclast"
11417   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
11418         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
11419                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
11420                       UNSPEC_AESDECLAST))]
11421   "TARGET_AES"
11422   "@
11423    aesdeclast\t{%2, %0|%0, %2}
11424    vaesdeclast\t{%2, %1, %0|%0, %1, %2}"
11425   [(set_attr "isa" "noavx,avx")
11426    (set_attr "type" "sselog1")
11427    (set_attr "prefix_extra" "1")
11428    (set_attr "prefix" "orig,vex")
11429    (set_attr "mode" "TI")])
11430
11431 (define_insn "aesimc"
11432   [(set (match_operand:V2DI 0 "register_operand" "=x")
11433         (unspec:V2DI [(match_operand:V2DI 1 "nonimmediate_operand" "xm")]
11434                       UNSPEC_AESIMC))]
11435   "TARGET_AES"
11436   "%vaesimc\t{%1, %0|%0, %1}"
11437   [(set_attr "type" "sselog1")
11438    (set_attr "prefix_extra" "1")
11439    (set_attr "prefix" "maybe_vex")
11440    (set_attr "mode" "TI")])
11441
11442 (define_insn "aeskeygenassist"
11443   [(set (match_operand:V2DI 0 "register_operand" "=x")
11444         (unspec:V2DI [(match_operand:V2DI 1 "nonimmediate_operand" "xm")
11445                       (match_operand:SI 2 "const_0_to_255_operand" "n")]
11446                      UNSPEC_AESKEYGENASSIST))]
11447   "TARGET_AES"
11448   "%vaeskeygenassist\t{%2, %1, %0|%0, %1, %2}"
11449   [(set_attr "type" "sselog1")
11450    (set_attr "prefix_extra" "1")
11451    (set_attr "length_immediate" "1")
11452    (set_attr "prefix" "maybe_vex")
11453    (set_attr "mode" "TI")])
11454
11455 (define_insn "pclmulqdq"
11456   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
11457         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
11458                       (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")
11459                       (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
11460                      UNSPEC_PCLMUL))]
11461   "TARGET_PCLMUL"
11462   "@
11463    pclmulqdq\t{%3, %2, %0|%0, %2, %3}
11464    vpclmulqdq\t{%3, %2, %1, %0|%0, %1, %2, %3}"
11465   [(set_attr "isa" "noavx,avx")
11466    (set_attr "type" "sselog1")
11467    (set_attr "prefix_extra" "1")
11468    (set_attr "length_immediate" "1")
11469    (set_attr "prefix" "orig,vex")
11470    (set_attr "mode" "TI")])
11471
11472 (define_expand "avx_vzeroall"
11473   [(match_par_dup 0 [(const_int 0)])]
11474   "TARGET_AVX"
11475 {
11476   int nregs = TARGET_64BIT ? 16 : 8;
11477   int regno;
11478
11479   operands[0] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nregs + 1));
11480
11481   XVECEXP (operands[0], 0, 0)
11482     = gen_rtx_UNSPEC_VOLATILE (VOIDmode, gen_rtvec (1, const0_rtx),
11483                                UNSPECV_VZEROALL);
11484
11485   for (regno = 0; regno < nregs; regno++)
11486     XVECEXP (operands[0], 0, regno + 1)
11487       = gen_rtx_SET (VOIDmode,
11488                      gen_rtx_REG (V8SImode, SSE_REGNO (regno)),
11489                      CONST0_RTX (V8SImode));
11490 })
11491
11492 (define_insn "*avx_vzeroall"
11493   [(match_parallel 0 "vzeroall_operation"
11494     [(unspec_volatile [(const_int 0)] UNSPECV_VZEROALL)])]
11495   "TARGET_AVX"
11496   "vzeroall"
11497   [(set_attr "type" "sse")
11498    (set_attr "modrm" "0")
11499    (set_attr "memory" "none")
11500    (set_attr "prefix" "vex")
11501    (set_attr "mode" "OI")])
11502
11503 ;; Clear the upper 128bits of AVX registers, equivalent to a NOP
11504 ;; if the upper 128bits are unused.
11505 (define_insn "avx_vzeroupper"
11506   [(unspec_volatile [(match_operand 0 "const_int_operand" "")]
11507                     UNSPECV_VZEROUPPER)]
11508   "TARGET_AVX"
11509   "vzeroupper"
11510   [(set_attr "type" "sse")
11511    (set_attr "modrm" "0")
11512    (set_attr "memory" "none")
11513    (set_attr "prefix" "vex")
11514    (set_attr "mode" "OI")])
11515
11516 (define_mode_attr AVXTOSSEMODE
11517   [(V4DI "V2DI") (V2DI "V2DI")
11518    (V8SI "V4SI") (V4SI "V4SI")
11519    (V16HI "V8HI") (V8HI "V8HI")
11520    (V32QI "V16QI") (V16QI "V16QI")])
11521
11522 (define_insn "avx2_pbroadcast<mode>"
11523   [(set (match_operand:VI 0 "register_operand" "=x")
11524         (vec_duplicate:VI
11525           (vec_select:<ssescalarmode>
11526             (match_operand:<AVXTOSSEMODE> 1 "nonimmediate_operand" "xm")
11527             (parallel [(const_int 0)]))))]
11528   "TARGET_AVX2"
11529   "vpbroadcast<ssemodesuffix>\t{%1, %0|%0, %1}"
11530   [(set_attr "type" "ssemov")
11531    (set_attr "prefix_extra" "1")
11532    (set_attr "prefix" "vex")
11533    (set_attr "mode" "<sseinsnmode>")])
11534
11535 (define_insn "avx2_permvarv8si"
11536   [(set (match_operand:V8SI 0 "register_operand" "=x")
11537         (unspec:V8SI
11538           [(match_operand:V8SI 1 "register_operand" "x")
11539            (match_operand:V8SI 2 "nonimmediate_operand" "xm")]
11540           UNSPEC_VPERMSI))]
11541   "TARGET_AVX2"
11542   "vpermd\t{%2, %1, %0|%0, %1, %2}"
11543   [(set_attr "type" "sselog")
11544    (set_attr "prefix" "vex")
11545    (set_attr "mode" "OI")])
11546
11547 (define_insn "avx2_permv4df"
11548   [(set (match_operand:V4DF 0 "register_operand" "=x")
11549         (unspec:V4DF
11550           [(match_operand:V4DF 1 "register_operand" "xm")
11551            (match_operand:SI 2 "const_0_to_255_operand" "n")]
11552           UNSPEC_VPERMDF))]
11553   "TARGET_AVX2"
11554   "vpermpd\t{%2, %1, %0|%0, %1, %2}"
11555   [(set_attr "type" "sselog")
11556    (set_attr "prefix_extra" "1")
11557    (set_attr "prefix" "vex")
11558    (set_attr "mode" "OI")])
11559
11560 (define_insn "avx2_permvarv8sf"
11561   [(set (match_operand:V8SF 0 "register_operand" "=x")
11562         (unspec:V8SF
11563           [(match_operand:V8SF 1 "register_operand" "x")
11564            (match_operand:V8SF 2 "nonimmediate_operand" "xm")]
11565           UNSPEC_VPERMSF))]
11566   "TARGET_AVX2"
11567   "vpermps\t{%2, %1, %0|%0, %1, %2}"
11568   [(set_attr "type" "sselog")
11569    (set_attr "prefix" "vex")
11570    (set_attr "mode" "OI")])
11571
11572 (define_expand "avx2_permv4di"
11573   [(match_operand:V4DI 0 "register_operand" "")
11574    (match_operand:V4DI 1 "nonimmediate_operand" "")
11575    (match_operand:SI 2 "const_0_to_255_operand" "")]
11576   "TARGET_AVX2"
11577 {
11578   int mask = INTVAL (operands[2]);
11579   emit_insn (gen_avx2_permv4di_1 (operands[0], operands[1],
11580                                   GEN_INT ((mask >> 0) & 3),
11581                                   GEN_INT ((mask >> 2) & 3),
11582                                   GEN_INT ((mask >> 4) & 3),
11583                                   GEN_INT ((mask >> 6) & 3)));
11584   DONE;
11585 })
11586
11587 (define_insn "avx2_permv4di_1"
11588   [(set (match_operand:V4DI 0 "register_operand" "=x")
11589         (vec_select:V4DI
11590           (match_operand:V4DI 1 "nonimmediate_operand" "xm")
11591           (parallel [(match_operand 2 "const_0_to_3_operand" "")
11592                      (match_operand 3 "const_0_to_3_operand" "")
11593                      (match_operand 4 "const_0_to_3_operand" "")
11594                      (match_operand 5 "const_0_to_3_operand" "")])))]
11595   "TARGET_AVX2"
11596 {
11597   int mask = 0;
11598   mask |= INTVAL (operands[2]) << 0;
11599   mask |= INTVAL (operands[3]) << 2;
11600   mask |= INTVAL (operands[4]) << 4;
11601   mask |= INTVAL (operands[5]) << 6;
11602   operands[2] = GEN_INT (mask);
11603   return "vpermq\t{%2, %1, %0|%0, %1, %2}";
11604 }
11605   [(set_attr "type" "sselog")
11606    (set_attr "prefix" "vex")
11607    (set_attr "mode" "OI")])
11608
11609 (define_insn "avx2_permv2ti"
11610   [(set (match_operand:V4DI 0 "register_operand" "=x")
11611         (unspec:V4DI
11612           [(match_operand:V4DI 1 "register_operand" "x")
11613            (match_operand:V4DI 2 "nonimmediate_operand" "xm")
11614            (match_operand:SI 3 "const_0_to_255_operand" "n")]
11615           UNSPEC_VPERMTI))]
11616   "TARGET_AVX2"
11617   "vperm2i128\t{%3, %2, %1, %0|%0, %1, %2, %3}"
11618   [(set_attr "type" "sselog")
11619    (set_attr "prefix" "vex")
11620    (set_attr "mode" "OI")])
11621
11622 (define_insn "avx2_vec_dupv4df"
11623   [(set (match_operand:V4DF 0 "register_operand" "=x")
11624         (vec_duplicate:V4DF
11625           (vec_select:DF
11626             (match_operand:V2DF 1 "register_operand" "x")
11627             (parallel [(const_int 0)]))))]
11628   "TARGET_AVX2"
11629   "vbroadcastsd\t{%1, %0|%0, %1}"
11630   [(set_attr "type" "sselog1")
11631    (set_attr "prefix" "vex")
11632    (set_attr "mode" "V4DF")])
11633
11634 ;; Modes handled by AVX vec_dup patterns.
11635 (define_mode_iterator AVX_VEC_DUP_MODE
11636   [V8SI V8SF V4DI V4DF])
11637
11638 (define_insn "vec_dup<mode>"
11639   [(set (match_operand:AVX_VEC_DUP_MODE 0 "register_operand" "=x,x")
11640         (vec_duplicate:AVX_VEC_DUP_MODE
11641           (match_operand:<ssescalarmode> 1 "nonimmediate_operand" "m,?x")))]
11642   "TARGET_AVX"
11643   "@
11644    vbroadcast<ssescalarmodesuffix>\t{%1, %0|%0, %1}
11645    #"
11646   [(set_attr "type" "ssemov")
11647    (set_attr "prefix_extra" "1")
11648    (set_attr "prefix" "vex")
11649    (set_attr "mode" "V8SF")])
11650
11651 (define_insn "avx2_vbroadcasti128_<mode>"
11652   [(set (match_operand:VI_256 0 "register_operand" "=x")
11653         (vec_concat:VI_256
11654           (match_operand:<ssehalfvecmode> 1 "memory_operand" "m")
11655           (match_dup 1)))]
11656   "TARGET_AVX2"
11657   "vbroadcasti128\t{%1, %0|%0, %1}"
11658   [(set_attr "type" "ssemov")
11659    (set_attr "prefix_extra" "1")
11660    (set_attr "prefix" "vex")
11661    (set_attr "mode" "OI")])
11662
11663 (define_split
11664   [(set (match_operand:AVX_VEC_DUP_MODE 0 "register_operand" "")
11665         (vec_duplicate:AVX_VEC_DUP_MODE
11666           (match_operand:<ssescalarmode> 1 "register_operand" "")))]
11667   "TARGET_AVX && reload_completed"
11668   [(set (match_dup 2)
11669         (vec_duplicate:<ssehalfvecmode> (match_dup 1)))
11670    (set (match_dup 0)
11671         (vec_concat:AVX_VEC_DUP_MODE (match_dup 2) (match_dup 2)))]
11672   "operands[2] = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (operands[0]));")
11673
11674 (define_insn "avx_vbroadcastf128_<mode>"
11675   [(set (match_operand:V_256 0 "register_operand" "=x,x,x")
11676         (vec_concat:V_256
11677           (match_operand:<ssehalfvecmode> 1 "nonimmediate_operand" "m,0,?x")
11678           (match_dup 1)))]
11679   "TARGET_AVX"
11680   "@
11681    vbroadcast<i128>\t{%1, %0|%0, %1}
11682    vinsert<i128>\t{$1, %1, %0, %0|%0, %0, %1, 1}
11683    vperm2<i128>\t{$0, %t1, %t1, %0|%0, %t1, %t1, 0}"
11684   [(set_attr "type" "ssemov,sselog1,sselog1")
11685    (set_attr "prefix_extra" "1")
11686    (set_attr "length_immediate" "0,1,1")
11687    (set_attr "prefix" "vex")
11688    (set_attr "mode" "<sseinsnmode>")])
11689
11690 ;; Recognize broadcast as a vec_select as produced by builtin_vec_perm.
11691 ;; If it so happens that the input is in memory, use vbroadcast.
11692 ;; Otherwise use vpermilp (and in the case of 256-bit modes, vperm2f128).
11693 (define_insn "*avx_vperm_broadcast_v4sf"
11694   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
11695         (vec_select:V4SF
11696           (match_operand:V4SF 1 "nonimmediate_operand" "m,o,x")
11697           (match_parallel 2 "avx_vbroadcast_operand"
11698             [(match_operand 3 "const_int_operand" "C,n,n")])))]
11699   "TARGET_AVX"
11700 {
11701   int elt = INTVAL (operands[3]);
11702   switch (which_alternative)
11703     {
11704     case 0:
11705     case 1:
11706       operands[1] = adjust_address_nv (operands[1], SFmode, elt * 4);
11707       return "vbroadcastss\t{%1, %0|%0, %1}";
11708     case 2:
11709       operands[2] = GEN_INT (elt * 0x55);
11710       return "vpermilps\t{%2, %1, %0|%0, %1, %2}";
11711     default:
11712       gcc_unreachable ();
11713     }
11714 }
11715   [(set_attr "type" "ssemov,ssemov,sselog1")
11716    (set_attr "prefix_extra" "1")
11717    (set_attr "length_immediate" "0,0,1")
11718    (set_attr "prefix" "vex")
11719    (set_attr "mode" "SF,SF,V4SF")])
11720
11721 (define_insn_and_split "*avx_vperm_broadcast_<mode>"
11722   [(set (match_operand:VF_256 0 "register_operand" "=x,x,x")
11723         (vec_select:VF_256
11724           (match_operand:VF_256 1 "nonimmediate_operand" "m,o,?x")
11725           (match_parallel 2 "avx_vbroadcast_operand"
11726             [(match_operand 3 "const_int_operand" "C,n,n")])))]
11727   "TARGET_AVX"
11728   "#"
11729   "&& reload_completed"
11730   [(set (match_dup 0) (vec_duplicate:VF_256 (match_dup 1)))]
11731 {
11732   rtx op0 = operands[0], op1 = operands[1];
11733   int elt = INTVAL (operands[3]);
11734
11735   if (REG_P (op1))
11736     {
11737       int mask;
11738
11739       /* Shuffle element we care about into all elements of the 128-bit lane.
11740          The other lane gets shuffled too, but we don't care.  */
11741       if (<MODE>mode == V4DFmode)
11742         mask = (elt & 1 ? 15 : 0);
11743       else
11744         mask = (elt & 3) * 0x55;
11745       emit_insn (gen_avx_vpermil<mode> (op0, op1, GEN_INT (mask)));
11746
11747       /* Shuffle the lane we care about into both lanes of the dest.  */
11748       mask = (elt / (<ssescalarnum> / 2)) * 0x11;
11749       emit_insn (gen_avx_vperm2f128<mode>3 (op0, op0, op0, GEN_INT (mask)));
11750       DONE;
11751     }
11752
11753   operands[1] = adjust_address_nv (op1, <ssescalarmode>mode,
11754                                    elt * GET_MODE_SIZE (<ssescalarmode>mode));
11755 })
11756
11757 (define_expand "avx_vpermil<mode>"
11758   [(set (match_operand:VF2 0 "register_operand" "")
11759         (vec_select:VF2
11760           (match_operand:VF2 1 "nonimmediate_operand" "")
11761           (match_operand:SI 2 "const_0_to_255_operand" "")))]
11762   "TARGET_AVX"
11763 {
11764   int mask = INTVAL (operands[2]);
11765   rtx perm[<ssescalarnum>];
11766
11767   perm[0] = GEN_INT (mask & 1);
11768   perm[1] = GEN_INT ((mask >> 1) & 1);
11769   if (<MODE>mode == V4DFmode)
11770     {
11771       perm[2] = GEN_INT (((mask >> 2) & 1) + 2);
11772       perm[3] = GEN_INT (((mask >> 3) & 1) + 2);
11773     }
11774
11775   operands[2]
11776     = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (<ssescalarnum>, perm));
11777 })
11778
11779 (define_expand "avx_vpermil<mode>"
11780   [(set (match_operand:VF1 0 "register_operand" "")
11781         (vec_select:VF1
11782           (match_operand:VF1 1 "nonimmediate_operand" "")
11783           (match_operand:SI 2 "const_0_to_255_operand" "")))]
11784   "TARGET_AVX"
11785 {
11786   int mask = INTVAL (operands[2]);
11787   rtx perm[<ssescalarnum>];
11788
11789   perm[0] = GEN_INT (mask & 3);
11790   perm[1] = GEN_INT ((mask >> 2) & 3);
11791   perm[2] = GEN_INT ((mask >> 4) & 3);
11792   perm[3] = GEN_INT ((mask >> 6) & 3);
11793   if (<MODE>mode == V8SFmode)
11794     {
11795       perm[4] = GEN_INT ((mask & 3) + 4);
11796       perm[5] = GEN_INT (((mask >> 2) & 3) + 4);
11797       perm[6] = GEN_INT (((mask >> 4) & 3) + 4);
11798       perm[7] = GEN_INT (((mask >> 6) & 3) + 4);
11799     }
11800
11801   operands[2]
11802     = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (<ssescalarnum>, perm));
11803 })
11804
11805 (define_insn "*avx_vpermilp<mode>"
11806   [(set (match_operand:VF 0 "register_operand" "=x")
11807         (vec_select:VF
11808           (match_operand:VF 1 "nonimmediate_operand" "xm")
11809           (match_parallel 2 ""
11810             [(match_operand 3 "const_int_operand" "")])))]
11811   "TARGET_AVX
11812    && avx_vpermilp_parallel (operands[2], <MODE>mode)"
11813 {
11814   int mask = avx_vpermilp_parallel (operands[2], <MODE>mode) - 1;
11815   operands[2] = GEN_INT (mask);
11816   return "vpermil<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}";
11817 }
11818   [(set_attr "type" "sselog")
11819    (set_attr "prefix_extra" "1")
11820    (set_attr "length_immediate" "1")
11821    (set_attr "prefix" "vex")
11822    (set_attr "mode" "<MODE>")])
11823
11824 (define_insn "avx_vpermilvar<mode>3"
11825   [(set (match_operand:VF 0 "register_operand" "=x")
11826         (unspec:VF
11827           [(match_operand:VF 1 "register_operand" "x")
11828            (match_operand:<sseintvecmode> 2 "nonimmediate_operand" "xm")]
11829           UNSPEC_VPERMIL))]
11830   "TARGET_AVX"
11831   "vpermil<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11832   [(set_attr "type" "sselog")
11833    (set_attr "prefix_extra" "1")
11834    (set_attr "prefix" "vex")
11835    (set_attr "mode" "<MODE>")])
11836
11837 (define_expand "avx_vperm2f128<mode>3"
11838   [(set (match_operand:AVX256MODE2P 0 "register_operand" "")
11839         (unspec:AVX256MODE2P
11840           [(match_operand:AVX256MODE2P 1 "register_operand" "")
11841            (match_operand:AVX256MODE2P 2 "nonimmediate_operand" "")
11842            (match_operand:SI 3 "const_0_to_255_operand" "")]
11843           UNSPEC_VPERMIL2F128))]
11844   "TARGET_AVX"
11845 {
11846   int mask = INTVAL (operands[3]);
11847   if ((mask & 0x88) == 0)
11848     {
11849       rtx perm[<ssescalarnum>], t1, t2;
11850       int i, base, nelt = <ssescalarnum>, nelt2 = nelt / 2;
11851
11852       base = (mask & 3) * nelt2;
11853       for (i = 0; i < nelt2; ++i)
11854         perm[i] = GEN_INT (base + i);
11855
11856       base = ((mask >> 4) & 3) * nelt2;
11857       for (i = 0; i < nelt2; ++i)
11858         perm[i + nelt2] = GEN_INT (base + i);
11859
11860       t2 = gen_rtx_VEC_CONCAT (<ssedoublevecmode>mode,
11861                                operands[1], operands[2]);
11862       t1 = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nelt, perm));
11863       t2 = gen_rtx_VEC_SELECT (<MODE>mode, t2, t1);
11864       t2 = gen_rtx_SET (VOIDmode, operands[0], t2);
11865       emit_insn (t2);
11866       DONE;
11867     }
11868 })
11869
11870 ;; Note that bits 7 and 3 of the imm8 allow lanes to be zeroed, which
11871 ;; means that in order to represent this properly in rtl we'd have to
11872 ;; nest *another* vec_concat with a zero operand and do the select from
11873 ;; a 4x wide vector.  That doesn't seem very nice.
11874 (define_insn "*avx_vperm2f128<mode>_full"
11875   [(set (match_operand:AVX256MODE2P 0 "register_operand" "=x")
11876         (unspec:AVX256MODE2P
11877           [(match_operand:AVX256MODE2P 1 "register_operand" "x")
11878            (match_operand:AVX256MODE2P 2 "nonimmediate_operand" "xm")
11879            (match_operand:SI 3 "const_0_to_255_operand" "n")]
11880           UNSPEC_VPERMIL2F128))]
11881   "TARGET_AVX"
11882   "vperm2<i128>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
11883   [(set_attr "type" "sselog")
11884    (set_attr "prefix_extra" "1")
11885    (set_attr "length_immediate" "1")
11886    (set_attr "prefix" "vex")
11887    (set_attr "mode" "<sseinsnmode>")])
11888
11889 (define_insn "*avx_vperm2f128<mode>_nozero"
11890   [(set (match_operand:AVX256MODE2P 0 "register_operand" "=x")
11891         (vec_select:AVX256MODE2P
11892           (vec_concat:<ssedoublevecmode>
11893             (match_operand:AVX256MODE2P 1 "register_operand" "x")
11894             (match_operand:AVX256MODE2P 2 "nonimmediate_operand" "xm"))
11895           (match_parallel 3 ""
11896             [(match_operand 4 "const_int_operand" "")])))]
11897   "TARGET_AVX
11898    && avx_vperm2f128_parallel (operands[3], <MODE>mode)"
11899 {
11900   int mask = avx_vperm2f128_parallel (operands[3], <MODE>mode) - 1;
11901   operands[3] = GEN_INT (mask);
11902   return "vperm2<i128>\t{%3, %2, %1, %0|%0, %1, %2, %3}";
11903 }
11904   [(set_attr "type" "sselog")
11905    (set_attr "prefix_extra" "1")
11906    (set_attr "length_immediate" "1")
11907    (set_attr "prefix" "vex")
11908    (set_attr "mode" "<sseinsnmode>")])
11909
11910 (define_expand "avx_vinsertf128<mode>"
11911   [(match_operand:V_256 0 "register_operand" "")
11912    (match_operand:V_256 1 "register_operand" "")
11913    (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "")
11914    (match_operand:SI 3 "const_0_to_1_operand" "")]
11915   "TARGET_AVX"
11916 {
11917   rtx (*insn)(rtx, rtx, rtx);
11918
11919   switch (INTVAL (operands[3]))
11920     {
11921     case 0:
11922       insn = gen_vec_set_lo_<mode>;
11923       break;
11924     case 1:
11925       insn = gen_vec_set_hi_<mode>;
11926       break;
11927     default:
11928       gcc_unreachable ();
11929     }
11930
11931   emit_insn (insn (operands[0], operands[1], operands[2]));
11932   DONE;
11933 })
11934
11935 (define_insn "avx2_vec_set_lo_v4di"
11936   [(set (match_operand:V4DI 0 "register_operand" "=x")
11937         (vec_concat:V4DI
11938           (match_operand:V2DI 2 "nonimmediate_operand" "xm")
11939           (vec_select:V2DI
11940             (match_operand:V4DI 1 "register_operand" "x")
11941             (parallel [(const_int 2) (const_int 3)]))))]
11942   "TARGET_AVX2"
11943   "vinserti128\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
11944   [(set_attr "type" "sselog")
11945    (set_attr "prefix_extra" "1")
11946    (set_attr "length_immediate" "1")
11947    (set_attr "prefix" "vex")
11948    (set_attr "mode" "OI")])
11949
11950 (define_insn "avx2_vec_set_hi_v4di"
11951   [(set (match_operand:V4DI 0 "register_operand" "=x")
11952         (vec_concat:V4DI
11953           (vec_select:V2DI
11954             (match_operand:V4DI 1 "register_operand" "x")
11955             (parallel [(const_int 0) (const_int 1)]))
11956           (match_operand:V2DI 2 "nonimmediate_operand" "xm")))]
11957   "TARGET_AVX2"
11958   "vinserti128\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
11959   [(set_attr "type" "sselog")
11960    (set_attr "prefix_extra" "1")
11961    (set_attr "length_immediate" "1")
11962    (set_attr "prefix" "vex")
11963    (set_attr "mode" "OI")])
11964
11965 (define_insn "vec_set_lo_<mode>"
11966   [(set (match_operand:VI8F_256 0 "register_operand" "=x")
11967         (vec_concat:VI8F_256
11968           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "xm")
11969           (vec_select:<ssehalfvecmode>
11970             (match_operand:VI8F_256 1 "register_operand" "x")
11971             (parallel [(const_int 2) (const_int 3)]))))]
11972   "TARGET_AVX"
11973   "vinsert<i128>\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
11974   [(set_attr "type" "sselog")
11975    (set_attr "prefix_extra" "1")
11976    (set_attr "length_immediate" "1")
11977    (set_attr "prefix" "vex")
11978    (set_attr "mode" "<sseinsnmode>")])
11979
11980 (define_insn "vec_set_hi_<mode>"
11981   [(set (match_operand:VI8F_256 0 "register_operand" "=x")
11982         (vec_concat:VI8F_256
11983           (vec_select:<ssehalfvecmode>
11984             (match_operand:VI8F_256 1 "register_operand" "x")
11985             (parallel [(const_int 0) (const_int 1)]))
11986           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "xm")))]
11987   "TARGET_AVX"
11988   "vinsert<i128>\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
11989   [(set_attr "type" "sselog")
11990    (set_attr "prefix_extra" "1")
11991    (set_attr "length_immediate" "1")
11992    (set_attr "prefix" "vex")
11993    (set_attr "mode" "<sseinsnmode>")])
11994
11995 (define_insn "vec_set_lo_<mode>"
11996   [(set (match_operand:VI4F_256 0 "register_operand" "=x")
11997         (vec_concat:VI4F_256
11998           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "xm")
11999           (vec_select:<ssehalfvecmode>
12000             (match_operand:VI4F_256 1 "register_operand" "x")
12001             (parallel [(const_int 4) (const_int 5)
12002                        (const_int 6) (const_int 7)]))))]
12003   "TARGET_AVX"
12004   "vinsert<i128>\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
12005   [(set_attr "type" "sselog")
12006    (set_attr "prefix_extra" "1")
12007    (set_attr "length_immediate" "1")
12008    (set_attr "prefix" "vex")
12009    (set_attr "mode" "<sseinsnmode>")])
12010
12011 (define_insn "vec_set_hi_<mode>"
12012   [(set (match_operand:VI4F_256 0 "register_operand" "=x")
12013         (vec_concat:VI4F_256
12014           (vec_select:<ssehalfvecmode>
12015             (match_operand:VI4F_256 1 "register_operand" "x")
12016             (parallel [(const_int 0) (const_int 1)
12017                        (const_int 2) (const_int 3)]))
12018           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "xm")))]
12019   "TARGET_AVX"
12020   "vinsert<i128>\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
12021   [(set_attr "type" "sselog")
12022    (set_attr "prefix_extra" "1")
12023    (set_attr "length_immediate" "1")
12024    (set_attr "prefix" "vex")
12025    (set_attr "mode" "<sseinsnmode>")])
12026
12027 (define_insn "vec_set_lo_v16hi"
12028   [(set (match_operand:V16HI 0 "register_operand" "=x")
12029         (vec_concat:V16HI
12030           (match_operand:V8HI 2 "nonimmediate_operand" "xm")
12031           (vec_select:V8HI
12032             (match_operand:V16HI 1 "register_operand" "x")
12033             (parallel [(const_int 8) (const_int 9)
12034                        (const_int 10) (const_int 11)
12035                        (const_int 12) (const_int 13)
12036                        (const_int 14) (const_int 15)]))))]
12037   "TARGET_AVX"
12038   "vinsert%~128\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
12039   [(set_attr "type" "sselog")
12040    (set_attr "prefix_extra" "1")
12041    (set_attr "length_immediate" "1")
12042    (set_attr "prefix" "vex")
12043    (set_attr "mode" "OI")])
12044
12045 (define_insn "vec_set_hi_v16hi"
12046   [(set (match_operand:V16HI 0 "register_operand" "=x")
12047         (vec_concat:V16HI
12048           (vec_select:V8HI
12049             (match_operand:V16HI 1 "register_operand" "x")
12050             (parallel [(const_int 0) (const_int 1)
12051                        (const_int 2) (const_int 3)
12052                        (const_int 4) (const_int 5)
12053                        (const_int 6) (const_int 7)]))
12054           (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
12055   "TARGET_AVX"
12056   "vinsert%~128\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
12057   [(set_attr "type" "sselog")
12058    (set_attr "prefix_extra" "1")
12059    (set_attr "length_immediate" "1")
12060    (set_attr "prefix" "vex")
12061    (set_attr "mode" "OI")])
12062
12063 (define_insn "vec_set_lo_v32qi"
12064   [(set (match_operand:V32QI 0 "register_operand" "=x")
12065         (vec_concat:V32QI
12066           (match_operand:V16QI 2 "nonimmediate_operand" "xm")
12067           (vec_select:V16QI
12068             (match_operand:V32QI 1 "register_operand" "x")
12069             (parallel [(const_int 16) (const_int 17)
12070                        (const_int 18) (const_int 19)
12071                        (const_int 20) (const_int 21)
12072                        (const_int 22) (const_int 23)
12073                        (const_int 24) (const_int 25)
12074                        (const_int 26) (const_int 27)
12075                        (const_int 28) (const_int 29)
12076                        (const_int 30) (const_int 31)]))))]
12077   "TARGET_AVX"
12078   "vinsert%~128\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
12079   [(set_attr "type" "sselog")
12080    (set_attr "prefix_extra" "1")
12081    (set_attr "length_immediate" "1")
12082    (set_attr "prefix" "vex")
12083    (set_attr "mode" "OI")])
12084
12085 (define_insn "vec_set_hi_v32qi"
12086   [(set (match_operand:V32QI 0 "register_operand" "=x")
12087         (vec_concat:V32QI
12088           (vec_select:V16QI
12089             (match_operand:V32QI 1 "register_operand" "x")
12090             (parallel [(const_int 0) (const_int 1)
12091                        (const_int 2) (const_int 3)
12092                        (const_int 4) (const_int 5)
12093                        (const_int 6) (const_int 7)
12094                        (const_int 8) (const_int 9)
12095                        (const_int 10) (const_int 11)
12096                        (const_int 12) (const_int 13)
12097                        (const_int 14) (const_int 15)]))
12098           (match_operand:V16QI 2 "nonimmediate_operand" "xm")))]
12099   "TARGET_AVX"
12100   "vinsert%~128\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
12101   [(set_attr "type" "sselog")
12102    (set_attr "prefix_extra" "1")
12103    (set_attr "length_immediate" "1")
12104    (set_attr "prefix" "vex")
12105    (set_attr "mode" "OI")])
12106
12107 (define_expand "<avx_avx2>_maskload<ssemodesuffix><avxsizesuffix>"
12108   [(set (match_operand:V48_AVX2 0 "register_operand" "")
12109         (unspec:V48_AVX2
12110           [(match_operand:<sseintvecmode> 2 "register_operand" "")
12111            (match_operand:V48_AVX2 1 "memory_operand" "")
12112            (match_dup 0)]
12113           UNSPEC_MASKMOV))]
12114   "TARGET_AVX")
12115
12116 (define_expand "<avx_avx2>_maskstore<ssemodesuffix><avxsizesuffix>"
12117   [(set (match_operand:V48_AVX2 0 "memory_operand" "")
12118         (unspec:V48_AVX2
12119           [(match_operand:<sseintvecmode> 1 "register_operand" "")
12120            (match_operand:V48_AVX2 2 "register_operand" "")
12121            (match_dup 0)]
12122           UNSPEC_MASKMOV))]
12123   "TARGET_AVX")
12124
12125 (define_insn "*avx2_maskmov<ssemodesuffix><avxsizesuffix>"
12126   [(set (match_operand:VI48_AVX2 0 "nonimmediate_operand" "=x,m")
12127         (unspec:VI48_AVX2
12128           [(match_operand:<sseintvecmode> 1 "register_operand" "x,x")
12129            (match_operand:VI48_AVX2 2 "nonimmediate_operand" "m,x")
12130            (match_dup 0)]
12131           UNSPEC_MASKMOV))]
12132   "TARGET_AVX2
12133    && (REG_P (operands[0]) == MEM_P (operands[2]))"
12134   "vpmaskmov<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
12135   [(set_attr "type" "sselog1")
12136    (set_attr "prefix_extra" "1")
12137    (set_attr "prefix" "vex")
12138    (set_attr "mode" "<sseinsnmode>")])
12139
12140 (define_insn "*avx_maskmov<ssemodesuffix><avxsizesuffix>"
12141   [(set (match_operand:VF 0 "nonimmediate_operand" "=x,m")
12142         (unspec:VF
12143           [(match_operand:<sseintvecmode> 1 "register_operand" "x,x")
12144            (match_operand:VF 2 "nonimmediate_operand" "m,x")
12145            (match_dup 0)]
12146           UNSPEC_MASKMOV))]
12147   "TARGET_AVX
12148    && (REG_P (operands[0]) == MEM_P (operands[2]))"
12149   "vmaskmov<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
12150   [(set_attr "type" "sselog1")
12151    (set_attr "prefix_extra" "1")
12152    (set_attr "prefix" "vex")
12153    (set_attr "mode" "<MODE>")])
12154
12155 (define_insn_and_split "avx_<castmode><avxsizesuffix>_<castmode>"
12156   [(set (match_operand:AVX256MODE2P 0 "nonimmediate_operand" "=x,m")
12157         (unspec:AVX256MODE2P
12158           [(match_operand:<ssehalfvecmode> 1 "nonimmediate_operand" "xm,x")]
12159           UNSPEC_CAST))]
12160   "TARGET_AVX"
12161   "#"
12162   "&& reload_completed"
12163   [(const_int 0)]
12164 {
12165   rtx op0 = operands[0];
12166   rtx op1 = operands[1];
12167   if (REG_P (op0))
12168     op0 = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (op0));
12169   else
12170     op1 = gen_rtx_REG (<MODE>mode, REGNO (op1));
12171   emit_move_insn (op0, op1);
12172   DONE;
12173 })
12174
12175 (define_expand "vec_init<mode>"
12176   [(match_operand:V_256 0 "register_operand" "")
12177    (match_operand 1 "" "")]
12178   "TARGET_AVX"
12179 {
12180   ix86_expand_vector_init (false, operands[0], operands[1]);
12181   DONE;
12182 })
12183
12184 (define_expand "avx2_extracti128"
12185   [(match_operand:V2DI 0 "nonimmediate_operand" "")
12186    (match_operand:V4DI 1 "register_operand" "")
12187    (match_operand:SI 2 "const_0_to_1_operand" "")]
12188   "TARGET_AVX2"
12189 {
12190   rtx (*insn)(rtx, rtx);
12191
12192   switch (INTVAL (operands[2]))
12193     {
12194     case 0:
12195       insn = gen_vec_extract_lo_v4di;
12196       break;
12197     case 1:
12198       insn = gen_vec_extract_hi_v4di;
12199       break;
12200     default:
12201       gcc_unreachable ();
12202     }
12203
12204   emit_insn (insn (operands[0], operands[1]));
12205   DONE;
12206 })
12207
12208 (define_expand "avx2_inserti128"
12209   [(match_operand:V4DI 0 "register_operand" "")
12210    (match_operand:V4DI 1 "register_operand" "")
12211    (match_operand:V2DI 2 "nonimmediate_operand" "")
12212    (match_operand:SI 3 "const_0_to_1_operand" "")]
12213   "TARGET_AVX2"
12214 {
12215   rtx (*insn)(rtx, rtx, rtx);
12216
12217   switch (INTVAL (operands[3]))
12218     {
12219     case 0:
12220       insn = gen_avx2_vec_set_lo_v4di;
12221       break;
12222     case 1:
12223       insn = gen_avx2_vec_set_hi_v4di;
12224       break;
12225     default:
12226       gcc_unreachable ();
12227     }
12228
12229   emit_insn (insn (operands[0], operands[1], operands[2]));
12230   DONE;
12231 })
12232
12233 (define_insn "avx2_ashrvv8si"
12234   [(set (match_operand:V8SI 0 "register_operand" "=x")
12235         (vec_concat:V8SI
12236           (vec_concat:V4SI
12237             (vec_concat:V2SI
12238               (ashiftrt:SI
12239                 (vec_select:SI
12240                   (match_operand:V8SI 1 "register_operand" "x")
12241                   (parallel [(const_int 0)]))
12242                 (vec_select:SI
12243                   (match_operand:V8SI 2 "nonimmediate_operand" "xm")
12244                   (parallel [(const_int 0)])))
12245               (ashiftrt:SI
12246                 (vec_select:SI
12247                   (match_dup 1)
12248                   (parallel [(const_int 1)]))
12249                 (vec_select:SI
12250                   (match_dup 2)
12251                   (parallel [(const_int 1)]))))
12252             (vec_concat:V2SI
12253               (ashiftrt:SI
12254                 (vec_select:SI
12255                   (match_dup 1)
12256                   (parallel [(const_int 2)]))
12257                 (vec_select:SI
12258                   (match_dup 2)
12259                   (parallel [(const_int 2)])))
12260               (ashiftrt:SI
12261                 (vec_select:SI
12262                   (match_dup 1)
12263                   (parallel [(const_int 3)]))
12264                 (vec_select:SI
12265                   (match_dup 2)
12266                   (parallel [(const_int 3)])))))
12267           (vec_concat:V4SI
12268             (vec_concat:V2SI
12269               (ashiftrt:SI
12270                 (vec_select:SI
12271                   (match_dup 1)
12272                   (parallel [(const_int 0)]))
12273                 (vec_select:SI
12274                   (match_dup 2)
12275                   (parallel [(const_int 0)])))
12276               (ashiftrt:SI
12277                 (vec_select:SI
12278                   (match_dup 1)
12279                   (parallel [(const_int 1)]))
12280                 (vec_select:SI
12281                   (match_dup 2)
12282                   (parallel [(const_int 1)]))))
12283             (vec_concat:V2SI
12284               (ashiftrt:SI
12285                 (vec_select:SI
12286                   (match_dup 1)
12287                   (parallel [(const_int 2)]))
12288                 (vec_select:SI
12289                   (match_dup 2)
12290                   (parallel [(const_int 2)])))
12291               (ashiftrt:SI
12292                 (vec_select:SI
12293                   (match_dup 1)
12294                   (parallel [(const_int 3)]))
12295                 (vec_select:SI
12296                   (match_dup 2)
12297                   (parallel [(const_int 3)])))))))]
12298   "TARGET_AVX2"
12299   "vpsravd\t{%2, %1, %0|%0, %1, %2}"
12300   [(set_attr "type" "sseishft")
12301    (set_attr "prefix" "vex")
12302    (set_attr "mode" "OI")])
12303
12304 (define_insn "avx2_ashrvv4si"
12305   [(set (match_operand:V4SI 0 "register_operand" "=x")
12306         (vec_concat:V4SI
12307           (vec_concat:V2SI
12308             (ashiftrt:SI
12309               (vec_select:SI
12310                 (match_operand:V4SI 1 "register_operand" "x")
12311                 (parallel [(const_int 0)]))
12312               (vec_select:SI
12313                 (match_operand:V4SI 2 "nonimmediate_operand" "xm")
12314                 (parallel [(const_int 0)])))
12315             (ashiftrt:SI
12316               (vec_select:SI
12317                 (match_dup 1)
12318                 (parallel [(const_int 1)]))
12319               (vec_select:SI
12320                 (match_dup 2)
12321                 (parallel [(const_int 1)]))))
12322           (vec_concat:V2SI
12323             (ashiftrt:SI
12324               (vec_select:SI
12325                 (match_dup 1)
12326                 (parallel [(const_int 2)]))
12327               (vec_select:SI
12328                 (match_dup 2)
12329                 (parallel [(const_int 2)])))
12330             (ashiftrt:SI
12331               (vec_select:SI
12332                 (match_dup 1)
12333                 (parallel [(const_int 3)]))
12334               (vec_select:SI
12335                 (match_dup 2)
12336                 (parallel [(const_int 3)]))))))]
12337   "TARGET_AVX2"
12338   "vpsravd\t{%2, %1, %0|%0, %1, %2}"
12339   [(set_attr "type" "sseishft")
12340    (set_attr "prefix" "vex")
12341    (set_attr "mode" "TI")])
12342
12343 (define_insn "avx2_<lshift>vv8si"
12344   [(set (match_operand:V8SI 0 "register_operand" "=x")
12345         (vec_concat:V8SI
12346           (vec_concat:V4SI
12347             (vec_concat:V2SI
12348               (lshift:SI
12349                 (vec_select:SI
12350                   (match_operand:V8SI 1 "register_operand" "x")
12351                   (parallel [(const_int 0)]))
12352                 (vec_select:SI
12353                   (match_operand:V8SI 2 "nonimmediate_operand" "xm")
12354                   (parallel [(const_int 0)])))
12355               (lshift:SI
12356                 (vec_select:SI
12357                   (match_dup 1)
12358                   (parallel [(const_int 1)]))
12359                 (vec_select:SI
12360                   (match_dup 2)
12361                   (parallel [(const_int 1)]))))
12362             (vec_concat:V2SI
12363               (lshift:SI
12364                 (vec_select:SI
12365                   (match_dup 1)
12366                   (parallel [(const_int 2)]))
12367                 (vec_select:SI
12368                   (match_dup 2)
12369                   (parallel [(const_int 2)])))
12370               (lshift:SI
12371                 (vec_select:SI
12372                   (match_dup 1)
12373                   (parallel [(const_int 3)]))
12374                 (vec_select:SI
12375                   (match_dup 2)
12376                   (parallel [(const_int 3)])))))
12377           (vec_concat:V4SI
12378             (vec_concat:V2SI
12379               (lshift:SI
12380                 (vec_select:SI
12381                   (match_dup 1)
12382                   (parallel [(const_int 0)]))
12383                 (vec_select:SI
12384                   (match_dup 2)
12385                   (parallel [(const_int 0)])))
12386               (lshift:SI
12387                 (vec_select:SI
12388                   (match_dup 1)
12389                   (parallel [(const_int 1)]))
12390                 (vec_select:SI
12391                   (match_dup 2)
12392                   (parallel [(const_int 1)]))))
12393             (vec_concat:V2SI
12394               (lshift:SI
12395                 (vec_select:SI
12396                   (match_dup 1)
12397                   (parallel [(const_int 2)]))
12398                 (vec_select:SI
12399                   (match_dup 2)
12400                   (parallel [(const_int 2)])))
12401               (lshift:SI
12402                 (vec_select:SI
12403                   (match_dup 1)
12404                   (parallel [(const_int 3)]))
12405                 (vec_select:SI
12406                   (match_dup 2)
12407                   (parallel [(const_int 3)])))))))]
12408   "TARGET_AVX2"
12409   "vp<lshift_insn>vd\t{%2, %1, %0|%0, %1, %2}"
12410   [(set_attr "type" "sseishft")
12411    (set_attr "prefix" "vex")
12412    (set_attr "mode" "OI")])
12413
12414 (define_insn "avx2_<lshift>v<mode>"
12415   [(set (match_operand:VI4SD_AVX2 0 "register_operand" "=x")
12416         (vec_concat:VI4SD_AVX2
12417           (vec_concat:<ssehalfvecmode>
12418             (lshift:<ssescalarmode>
12419               (vec_select:<ssescalarmode>
12420                 (match_operand:VI4SD_AVX2 1 "register_operand" "x")
12421                 (parallel [(const_int 0)]))
12422               (vec_select:<ssescalarmode>
12423                 (match_operand:VI4SD_AVX2 2 "nonimmediate_operand" "xm")
12424                 (parallel [(const_int 0)])))
12425             (lshift:<ssescalarmode>
12426               (vec_select:<ssescalarmode>
12427                 (match_dup 1)
12428                 (parallel [(const_int 1)]))
12429               (vec_select:<ssescalarmode>
12430                 (match_dup 2)
12431                 (parallel [(const_int 1)]))))
12432           (vec_concat:<ssehalfvecmode>
12433             (lshift:<ssescalarmode>
12434               (vec_select:<ssescalarmode>
12435                 (match_dup 1)
12436                 (parallel [(const_int 2)]))
12437               (vec_select:<ssescalarmode>
12438                 (match_dup 2)
12439                 (parallel [(const_int 2)])))
12440             (lshift:<ssescalarmode>
12441               (vec_select:<ssescalarmode>
12442                 (match_dup 1)
12443                 (parallel [(const_int 3)]))
12444               (vec_select:<ssescalarmode>
12445                 (match_dup 2)
12446                 (parallel [(const_int 3)]))))))]
12447   "TARGET_AVX2"
12448   "vp<lshift_insn>v<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
12449   [(set_attr "type" "sseishft")
12450    (set_attr "prefix" "vex")
12451    (set_attr "mode" "<sseinsnmode>")])
12452
12453 (define_insn "avx2_<lshift>vv2di"
12454   [(set (match_operand:V2DI 0 "register_operand" "=x")
12455         (vec_concat:V2DI
12456           (lshift:DI
12457             (vec_select:DI
12458               (match_operand:V2DI 1 "register_operand" "x")
12459               (parallel [(const_int 0)]))
12460             (vec_select:DI
12461               (match_operand:V2DI 2 "nonimmediate_operand" "xm")
12462               (parallel [(const_int 0)])))
12463           (lshift:DI
12464             (vec_select:DI
12465               (match_dup 1)
12466               (parallel [(const_int 1)]))
12467             (vec_select:DI
12468               (match_dup 2)
12469               (parallel [(const_int 1)])))))]
12470   "TARGET_AVX2"
12471   "vp<lshift_insn>vq\t{%2, %1, %0|%0, %1, %2}"
12472   [(set_attr "type" "sseishft")
12473    (set_attr "prefix" "vex")
12474    (set_attr "mode" "TI")])
12475
12476 (define_insn "avx_vec_concat<mode>"
12477   [(set (match_operand:V_256 0 "register_operand" "=x,x")
12478         (vec_concat:V_256
12479           (match_operand:<ssehalfvecmode> 1 "register_operand" "x,x")
12480           (match_operand:<ssehalfvecmode> 2 "vector_move_operand" "xm,C")))]
12481   "TARGET_AVX"
12482 {
12483   switch (which_alternative)
12484     {
12485     case 0:
12486       return "vinsert<i128>\t{$0x1, %2, %t1, %0|%0, %t1, %2, 0x1}";
12487     case 1:
12488       switch (get_attr_mode (insn))
12489         {
12490         case MODE_V8SF:
12491           return "vmovaps\t{%1, %x0|%x0, %1}";
12492         case MODE_V4DF:
12493           return "vmovapd\t{%1, %x0|%x0, %1}";
12494         default:
12495           return "vmovdqa\t{%1, %x0|%x0, %1}";
12496         }
12497     default:
12498       gcc_unreachable ();
12499     }
12500 }
12501   [(set_attr "type" "sselog,ssemov")
12502    (set_attr "prefix_extra" "1,*")
12503    (set_attr "length_immediate" "1,*")
12504    (set_attr "prefix" "vex")
12505    (set_attr "mode" "<sseinsnmode>")])
12506
12507 (define_insn "vcvtph2ps"
12508   [(set (match_operand:V4SF 0 "register_operand" "=x")
12509         (vec_select:V4SF
12510           (unspec:V8SF [(match_operand:V8HI 1 "register_operand" "x")]
12511                        UNSPEC_VCVTPH2PS)
12512           (parallel [(const_int 0) (const_int 1)
12513                      (const_int 1) (const_int 2)])))]
12514   "TARGET_F16C"
12515   "vcvtph2ps\t{%1, %0|%0, %1}"
12516   [(set_attr "type" "ssecvt")
12517    (set_attr "prefix" "vex")
12518    (set_attr "mode" "V4SF")])
12519
12520 (define_insn "*vcvtph2ps_load"
12521   [(set (match_operand:V4SF 0 "register_operand" "=x")
12522         (unspec:V4SF [(match_operand:V4HI 1 "memory_operand" "m")]
12523                      UNSPEC_VCVTPH2PS))]
12524   "TARGET_F16C"
12525   "vcvtph2ps\t{%1, %0|%0, %1}"
12526   [(set_attr "type" "ssecvt")
12527    (set_attr "prefix" "vex")
12528    (set_attr "mode" "V8SF")])
12529
12530 (define_insn "vcvtph2ps256"
12531   [(set (match_operand:V8SF 0 "register_operand" "=x")
12532         (unspec:V8SF [(match_operand:V8HI 1 "nonimmediate_operand" "xm")]
12533                      UNSPEC_VCVTPH2PS))]
12534   "TARGET_F16C"
12535   "vcvtph2ps\t{%1, %0|%0, %1}"
12536   [(set_attr "type" "ssecvt")
12537    (set_attr "prefix" "vex")
12538    (set_attr "mode" "V8SF")])
12539
12540 (define_expand "vcvtps2ph"
12541   [(set (match_operand:V8HI 0 "register_operand" "")
12542         (vec_concat:V8HI
12543           (unspec:V4HI [(match_operand:V4SF 1 "register_operand" "")
12544                         (match_operand:SI 2 "const_0_to_255_operand" "")]
12545                        UNSPEC_VCVTPS2PH)
12546           (match_dup 3)))]
12547   "TARGET_F16C"
12548   "operands[3] = CONST0_RTX (V4HImode);")
12549
12550 (define_insn "*vcvtps2ph"
12551   [(set (match_operand:V8HI 0 "register_operand" "=x")
12552         (vec_concat:V8HI
12553           (unspec:V4HI [(match_operand:V4SF 1 "register_operand" "x")
12554                         (match_operand:SI 2 "const_0_to_255_operand" "N")]
12555                        UNSPEC_VCVTPS2PH)
12556           (match_operand:V4HI 3 "const0_operand" "")))]
12557   "TARGET_F16C"
12558   "vcvtps2ph\t{%2, %1, %0|%0, %1, %2}"
12559   [(set_attr "type" "ssecvt")
12560    (set_attr "prefix" "vex")
12561    (set_attr "mode" "V4SF")])
12562
12563 (define_insn "*vcvtps2ph_store"
12564   [(set (match_operand:V4HI 0 "memory_operand" "=m")
12565         (unspec:V4HI [(match_operand:V4SF 1 "register_operand" "x")
12566                       (match_operand:SI 2 "const_0_to_255_operand" "N")]
12567                      UNSPEC_VCVTPS2PH))]
12568   "TARGET_F16C"
12569   "vcvtps2ph\t{%2, %1, %0|%0, %1, %2}"
12570   [(set_attr "type" "ssecvt")
12571    (set_attr "prefix" "vex")
12572    (set_attr "mode" "V4SF")])
12573
12574 (define_insn "vcvtps2ph256"
12575   [(set (match_operand:V8HI 0 "nonimmediate_operand" "=xm")
12576         (unspec:V8HI [(match_operand:V8SF 1 "register_operand" "x")
12577                       (match_operand:SI 2 "const_0_to_255_operand" "N")]
12578                      UNSPEC_VCVTPS2PH))]
12579   "TARGET_F16C"
12580   "vcvtps2ph\t{%2, %1, %0|%0, %1, %2}"
12581   [(set_attr "type" "ssecvt")
12582    (set_attr "prefix" "vex")
12583    (set_attr "mode" "V8SF")])
12584
12585 ;; For gather* insn patterns
12586 (define_mode_iterator VEC_GATHER_MODE
12587                       [V2DI V2DF V4DI V4DF V4SI V4SF V8SI V8SF])
12588 (define_mode_attr VEC_GATHER_MODE
12589                       [(V2DI "V4SI") (V2DF "V4SI")
12590                        (V4DI "V4SI") (V4DF "V4SI")
12591                        (V4SI "V4SI") (V4SF "V4SI")
12592                        (V8SI "V8SI") (V8SF "V8SI")])
12593
12594 (define_expand "avx2_gathersi<mode>"
12595   [(parallel [(set (match_operand:VEC_GATHER_MODE 0 "register_operand" "")
12596                    (unspec:VEC_GATHER_MODE
12597                      [(match_operand:VEC_GATHER_MODE 1 "register_operand" "")
12598                       (match_operand 2 "register_operand" "")
12599                       (mem:BLK (scratch))
12600                       (match_operand:<VEC_GATHER_MODE> 3 "register_operand" "")
12601                       (match_operand:VEC_GATHER_MODE 4 "register_operand" "")
12602                       (match_operand:SI 5 "const1248_operand " "")]
12603                      UNSPEC_GATHER))
12604               (clobber (match_scratch:VEC_GATHER_MODE 6 ""))])]
12605   "TARGET_AVX2")
12606
12607 (define_insn "*avx2_gathersi<mode>"
12608   [(set (match_operand:VEC_GATHER_MODE 0 "register_operand" "=&x")
12609         (unspec:VEC_GATHER_MODE
12610           [(match_operand:VEC_GATHER_MODE 2 "register_operand" "0")
12611            (match_operand:P 3 "register_operand" "r")
12612            (mem:BLK (scratch))
12613            (match_operand:<VEC_GATHER_MODE> 4 "register_operand" "x")
12614            (match_operand:VEC_GATHER_MODE 5 "register_operand" "1")
12615            (match_operand:SI 6 "const1248_operand" "n")]
12616           UNSPEC_GATHER))
12617    (clobber (match_scratch:VEC_GATHER_MODE 1 "=&x"))]
12618   "TARGET_AVX2"
12619   "v<gthrfirstp>gatherd<gthrlastp>\t{%1, (%3, %4, %p6), %0|%0, (%3, %4, %p6), %1}"
12620   [(set_attr "type" "ssemov")
12621    (set_attr "prefix" "vex")
12622    (set_attr "mode" "<sseinsnmode>")])
12623
12624 (define_expand "avx2_gatherdi<mode>"
12625   [(parallel [(set (match_operand:VEC_GATHER_MODE 0 "register_operand" "")
12626                    (unspec:VEC_GATHER_MODE
12627                      [(match_operand:VEC_GATHER_MODE 1 "register_operand" "")
12628                       (match_operand 2 "register_operand" "")
12629                       (mem:BLK (scratch))
12630                       (match_operand:<AVXMODE48P_DI> 3 "register_operand" "")
12631                       (match_operand:VEC_GATHER_MODE 4 "register_operand" "")
12632                       (match_operand:SI 5 "const1248_operand " "")]
12633                      UNSPEC_GATHER))
12634               (clobber (match_scratch:VEC_GATHER_MODE 6 ""))])]
12635   "TARGET_AVX2")
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_operand:P 3 "register_operand" "r")
12642            (mem:BLK (scratch))
12643            (match_operand:<AVXMODE48P_DI> 4 "register_operand" "x")
12644            (match_operand:AVXMODE48P_DI 5 "register_operand" "1")
12645            (match_operand:SI 6 "const1248_operand" "n")]
12646           UNSPEC_GATHER))
12647    (clobber (match_scratch:AVXMODE48P_DI 1 "=&x"))]
12648   "TARGET_AVX2"
12649   "v<gthrfirstp>gatherq<gthrlastp>\t{%1, (%3, %4, %p6), %0|%0, (%3, %4, %p6), %1}"
12650   [(set_attr "type" "ssemov")
12651    (set_attr "prefix" "vex")
12652    (set_attr "mode" "<sseinsnmode>")])
12653
12654 ;; Special handling for VEX.256 with float arguments
12655 ;; since there're still xmms as operands
12656 (define_expand "avx2_gatherdi<mode>256"
12657   [(parallel [(set (match_operand:VI4F_128 0 "register_operand" "")
12658                    (unspec:VI4F_128
12659                      [(match_operand:VI4F_128 1 "register_operand" "")
12660                       (match_operand 2 "register_operand" "")
12661                       (mem:BLK (scratch))
12662                       (match_operand:V4DI 3 "register_operand" "")
12663                       (match_operand:VI4F_128 4 "register_operand" "")
12664                       (match_operand:SI 5 "const1248_operand " "")]
12665                      UNSPEC_GATHER))
12666               (clobber (match_scratch:VI4F_128 6 ""))])]
12667   "TARGET_AVX2")
12668
12669 (define_insn "*avx2_gatherdi<mode>256"
12670   [(set (match_operand:VI4F_128 0 "register_operand" "=x")
12671         (unspec:VI4F_128
12672           [(match_operand:VI4F_128 2 "register_operand" "0")
12673            (match_operand:P 3 "register_operand" "r")
12674            (mem:BLK (scratch))
12675            (match_operand:V4DI 4 "register_operand" "x")
12676            (match_operand:VI4F_128 5 "register_operand" "1")
12677            (match_operand:SI 6 "const1248_operand" "n")]
12678           UNSPEC_GATHER)) 
12679    (clobber (match_scratch:VI4F_128 1 "=&x"))]
12680   "TARGET_AVX2"
12681   "v<gthrfirstp>gatherq<gthrlastp>\t{%1, (%3, %4, %p6), %0|%0, (%3, %4, %p6), %1}"
12682   [(set_attr "type" "ssemov")
12683    (set_attr "prefix" "vex")
12684    (set_attr "mode" "<sseinsnmode>")])