Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / gcc / config / i386 / sse.md
1 ;; GCC machine description for SSE instructions
2 ;; Copyright (C) 2005-2013 Free Software Foundation, Inc.
3 ;;
4 ;; This file is part of GCC.
5 ;;
6 ;; GCC is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 3, or (at your option)
9 ;; any later version.
10 ;;
11 ;; GCC is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;; GNU General Public License for more details.
15 ;;
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GCC; see the file COPYING3.  If not see
18 ;; <http://www.gnu.org/licenses/>.
19
20 (define_c_enum "unspec" [
21   ;; SSE
22   UNSPEC_MOVNT
23   UNSPEC_LOADU
24   UNSPEC_STOREU
25
26   ;; SSE3
27   UNSPEC_LDDQU
28
29   ;; SSSE3
30   UNSPEC_PSHUFB
31   UNSPEC_PSIGN
32   UNSPEC_PALIGNR
33
34   ;; For SSE4A support
35   UNSPEC_EXTRQI
36   UNSPEC_EXTRQ
37   UNSPEC_INSERTQI
38   UNSPEC_INSERTQ
39
40   ;; For SSE4.1 support
41   UNSPEC_BLENDV
42   UNSPEC_INSERTPS
43   UNSPEC_DP
44   UNSPEC_MOVNTDQA
45   UNSPEC_MPSADBW
46   UNSPEC_PHMINPOSUW
47   UNSPEC_PTEST
48
49   ;; For SSE4.2 support
50   UNSPEC_PCMPESTR
51   UNSPEC_PCMPISTR
52
53   ;; For FMA4 support
54   UNSPEC_FMADDSUB
55   UNSPEC_XOP_UNSIGNED_CMP
56   UNSPEC_XOP_TRUEFALSE
57   UNSPEC_XOP_PERMUTE
58   UNSPEC_FRCZ
59
60   ;; For AES support
61   UNSPEC_AESENC
62   UNSPEC_AESENCLAST
63   UNSPEC_AESDEC
64   UNSPEC_AESDECLAST
65   UNSPEC_AESIMC
66   UNSPEC_AESKEYGENASSIST
67
68   ;; For PCLMUL support
69   UNSPEC_PCLMUL
70
71   ;; For AVX support
72   UNSPEC_PCMP
73   UNSPEC_VPERMIL
74   UNSPEC_VPERMIL2
75   UNSPEC_VPERMIL2F128
76   UNSPEC_CAST
77   UNSPEC_VTESTP
78   UNSPEC_VCVTPH2PS
79   UNSPEC_VCVTPS2PH
80
81   ;; For AVX2 support
82   UNSPEC_VPERMVAR
83   UNSPEC_VPERMTI
84   UNSPEC_GATHER
85   UNSPEC_VSIBADDR
86 ])
87
88 (define_c_enum "unspecv" [
89   UNSPECV_LDMXCSR
90   UNSPECV_STMXCSR
91   UNSPECV_CLFLUSH
92   UNSPECV_MONITOR
93   UNSPECV_MWAIT
94   UNSPECV_VZEROALL
95   UNSPECV_VZEROUPPER
96 ])
97
98 ;; All vector modes including V?TImode, used in move patterns.
99 (define_mode_iterator V16
100   [(V32QI "TARGET_AVX") V16QI
101    (V16HI "TARGET_AVX") V8HI
102    (V8SI "TARGET_AVX") V4SI
103    (V4DI "TARGET_AVX") V2DI
104    (V2TI "TARGET_AVX") V1TI
105    (V8SF "TARGET_AVX") V4SF
106    (V4DF "TARGET_AVX") V2DF])
107
108 ;; All vector modes
109 (define_mode_iterator V
110   [(V32QI "TARGET_AVX") V16QI
111    (V16HI "TARGET_AVX") V8HI
112    (V8SI "TARGET_AVX") V4SI
113    (V4DI "TARGET_AVX") V2DI
114    (V8SF "TARGET_AVX") V4SF
115    (V4DF "TARGET_AVX") (V2DF "TARGET_SSE2")])
116
117 ;; All 128bit vector modes
118 (define_mode_iterator V_128
119   [V16QI V8HI V4SI V2DI V4SF (V2DF "TARGET_SSE2")])
120
121 ;; All 256bit vector modes
122 (define_mode_iterator V_256
123   [V32QI V16HI V8SI V4DI V8SF V4DF])
124
125 ;; All vector float modes
126 (define_mode_iterator VF
127   [(V8SF "TARGET_AVX") V4SF
128    (V4DF "TARGET_AVX") (V2DF "TARGET_SSE2")])
129
130 ;; All SFmode vector float modes
131 (define_mode_iterator VF1
132   [(V8SF "TARGET_AVX") V4SF])
133
134 ;; All DFmode vector float modes
135 (define_mode_iterator VF2
136   [(V4DF "TARGET_AVX") V2DF])
137
138 ;; All 128bit vector float modes
139 (define_mode_iterator VF_128
140   [V4SF (V2DF "TARGET_SSE2")])
141
142 ;; All 256bit vector float modes
143 (define_mode_iterator VF_256
144   [V8SF V4DF])
145
146 ;; All vector integer modes
147 (define_mode_iterator VI
148   [(V32QI "TARGET_AVX") V16QI
149    (V16HI "TARGET_AVX") V8HI
150    (V8SI "TARGET_AVX") V4SI
151    (V4DI "TARGET_AVX") V2DI])
152
153 (define_mode_iterator VI_AVX2
154   [(V32QI "TARGET_AVX2") V16QI
155    (V16HI "TARGET_AVX2") V8HI
156    (V8SI "TARGET_AVX2") V4SI
157    (V4DI "TARGET_AVX2") V2DI])
158
159 ;; All QImode vector integer modes
160 (define_mode_iterator VI1
161   [(V32QI "TARGET_AVX") V16QI])
162
163 ;; All DImode vector integer modes
164 (define_mode_iterator VI8
165   [(V4DI "TARGET_AVX") V2DI])
166
167 (define_mode_iterator VI1_AVX2
168   [(V32QI "TARGET_AVX2") V16QI])
169
170 (define_mode_iterator VI2_AVX2
171   [(V16HI "TARGET_AVX2") V8HI])
172
173 (define_mode_iterator VI4_AVX2
174   [(V8SI "TARGET_AVX2") V4SI])
175
176 (define_mode_iterator VI8_AVX2
177   [(V4DI "TARGET_AVX2") V2DI])
178
179 ;; ??? We should probably use TImode instead.
180 (define_mode_iterator VIMAX_AVX2
181   [(V2TI "TARGET_AVX2") V1TI])
182
183 ;; ??? This should probably be dropped in favor of VIMAX_AVX2.
184 (define_mode_iterator SSESCALARMODE
185   [(V2TI "TARGET_AVX2") TI])
186
187 (define_mode_iterator VI12_AVX2
188   [(V32QI "TARGET_AVX2") V16QI
189    (V16HI "TARGET_AVX2") V8HI])
190
191 (define_mode_iterator VI24_AVX2
192   [(V16HI "TARGET_AVX2") V8HI
193    (V8SI "TARGET_AVX2") V4SI])
194
195 (define_mode_iterator VI124_AVX2
196   [(V32QI "TARGET_AVX2") V16QI
197    (V16HI "TARGET_AVX2") V8HI
198    (V8SI "TARGET_AVX2") V4SI])
199
200 (define_mode_iterator VI248_AVX2
201   [(V16HI "TARGET_AVX2") V8HI
202    (V8SI "TARGET_AVX2") V4SI
203    (V4DI "TARGET_AVX2") V2DI])
204
205 (define_mode_iterator VI48_AVX2
206   [(V8SI "TARGET_AVX2") V4SI
207    (V4DI "TARGET_AVX2") V2DI])
208
209 (define_mode_iterator V48_AVX2
210   [V4SF V2DF
211    V8SF V4DF
212    (V4SI "TARGET_AVX2") (V2DI "TARGET_AVX2")
213    (V8SI "TARGET_AVX2") (V4DI "TARGET_AVX2")])
214
215 (define_mode_attr sse2_avx2
216   [(V16QI "sse2") (V32QI "avx2")
217    (V8HI "sse2") (V16HI "avx2")
218    (V4SI "sse2") (V8SI "avx2")
219    (V2DI "sse2") (V4DI "avx2")
220    (V1TI "sse2") (V2TI "avx2")])
221
222 (define_mode_attr ssse3_avx2
223    [(V16QI "ssse3") (V32QI "avx2")
224     (V4HI "ssse3") (V8HI "ssse3") (V16HI "avx2")
225     (V4SI "ssse3") (V8SI "avx2")
226     (V2DI "ssse3") (V4DI "avx2")
227     (TI "ssse3") (V2TI "avx2")])
228
229 (define_mode_attr sse4_1_avx2
230    [(V16QI "sse4_1") (V32QI "avx2")
231     (V8HI "sse4_1") (V16HI "avx2")
232     (V4SI "sse4_1") (V8SI "avx2")
233     (V2DI "sse4_1") (V4DI "avx2")])
234
235 (define_mode_attr avx_avx2
236   [(V4SF "avx") (V2DF "avx")
237    (V8SF "avx") (V4DF "avx")
238    (V4SI "avx2") (V2DI "avx2")
239    (V8SI "avx2") (V4DI "avx2")])
240
241 (define_mode_attr vec_avx2
242   [(V16QI "vec") (V32QI "avx2")
243    (V8HI "vec") (V16HI "avx2")
244    (V4SI "vec") (V8SI "avx2")
245    (V2DI "vec") (V4DI "avx2")])
246
247 (define_mode_attr ssedoublemode
248   [(V16HI "V16SI") (V8HI "V8SI") (V4HI "V4SI")
249    (V32QI "V32HI") (V16QI "V16HI")])
250
251 (define_mode_attr ssebytemode
252   [(V4DI "V32QI") (V2DI "V16QI")])
253
254 ;; All 128bit vector integer modes
255 (define_mode_iterator VI_128 [V16QI V8HI V4SI V2DI])
256
257 ;; All 256bit vector integer modes
258 (define_mode_iterator VI_256 [V32QI V16HI V8SI V4DI])
259
260 ;; Random 128bit vector integer mode combinations
261 (define_mode_iterator VI12_128 [V16QI V8HI])
262 (define_mode_iterator VI14_128 [V16QI V4SI])
263 (define_mode_iterator VI124_128 [V16QI V8HI V4SI])
264 (define_mode_iterator VI128_128 [V16QI V8HI V2DI])
265 (define_mode_iterator VI24_128 [V8HI V4SI])
266 (define_mode_iterator VI248_128 [V8HI V4SI V2DI])
267 (define_mode_iterator VI48_128 [V4SI V2DI])
268
269 ;; Random 256bit vector integer mode combinations
270 (define_mode_iterator VI124_256 [V32QI V16HI V8SI])
271 (define_mode_iterator VI48_256 [V8SI V4DI])
272
273 ;; Int-float size matches
274 (define_mode_iterator VI4F_128 [V4SI V4SF])
275 (define_mode_iterator VI8F_128 [V2DI V2DF])
276 (define_mode_iterator VI4F_256 [V8SI V8SF])
277 (define_mode_iterator VI8F_256 [V4DI V4DF])
278
279 ;; Mapping from float mode to required SSE level
280 (define_mode_attr sse
281   [(SF "sse") (DF "sse2")
282    (V4SF "sse") (V2DF "sse2")
283    (V8SF "avx") (V4DF "avx")])
284
285 (define_mode_attr sse2
286   [(V16QI "sse2") (V32QI "avx")
287    (V2DI "sse2") (V4DI "avx")])
288
289 (define_mode_attr sse3
290   [(V16QI "sse3") (V32QI "avx")])
291
292 (define_mode_attr sse4_1
293   [(V4SF "sse4_1") (V2DF "sse4_1")
294    (V8SF "avx") (V4DF "avx")])
295
296 (define_mode_attr avxsizesuffix
297   [(V32QI "256") (V16HI "256") (V8SI "256") (V4DI "256")
298    (V16QI "") (V8HI "") (V4SI "") (V2DI "")
299    (V8SF "256") (V4DF "256")
300    (V4SF "") (V2DF "")])
301
302 ;; SSE instruction mode
303 (define_mode_attr sseinsnmode
304   [(V32QI "OI") (V16HI "OI") (V8SI "OI") (V4DI "OI") (V2TI "OI")
305    (V16QI "TI") (V8HI "TI") (V4SI "TI") (V2DI "TI") (V1TI "TI")
306    (V8SF "V8SF") (V4DF "V4DF")
307    (V4SF "V4SF") (V2DF "V2DF")
308    (TI "TI")])
309
310 ;; Mapping of vector float modes to an integer mode of the same size
311 (define_mode_attr sseintvecmode
312   [(V8SF "V8SI") (V4DF "V4DI")
313    (V4SF "V4SI") (V2DF "V2DI")
314    (V8SI "V8SI") (V4DI "V4DI")
315    (V4SI "V4SI") (V2DI "V2DI")
316    (V16HI "V16HI") (V8HI "V8HI")
317    (V32QI "V32QI") (V16QI "V16QI")])
318
319 (define_mode_attr sseintvecmodelower
320   [(V8SF "v8si") (V4DF "v4di")
321    (V4SF "v4si") (V2DF "v2di")
322    (V8SI "v8si") (V4DI "v4di")
323    (V4SI "v4si") (V2DI "v2di")
324    (V16HI "v16hi") (V8HI "v8hi")
325    (V32QI "v32qi") (V16QI "v16qi")])
326
327 ;; Mapping of vector modes to a vector mode of double size
328 (define_mode_attr ssedoublevecmode
329   [(V32QI "V64QI") (V16HI "V32HI") (V8SI "V16SI") (V4DI "V8DI")
330    (V16QI "V32QI") (V8HI "V16HI") (V4SI "V8SI") (V2DI "V4DI")
331    (V8SF "V16SF") (V4DF "V8DF")
332    (V4SF "V8SF") (V2DF "V4DF")])
333
334 ;; Mapping of vector modes to a vector mode of half size
335 (define_mode_attr ssehalfvecmode
336   [(V32QI "V16QI") (V16HI "V8HI") (V8SI "V4SI") (V4DI "V2DI")
337    (V16QI  "V8QI") (V8HI  "V4HI") (V4SI "V2SI")
338    (V8SF "V4SF") (V4DF "V2DF")
339    (V4SF "V2SF")])
340
341 ;; Mapping of vector modes ti packed single mode of the same size
342 (define_mode_attr ssePSmode
343   [(V32QI "V8SF") (V16QI "V4SF")
344    (V16HI "V8SF") (V8HI "V4SF")
345    (V8SI "V8SF") (V4SI "V4SF")
346    (V4DI "V8SF") (V2DI "V4SF")
347    (V2TI "V8SF") (V1TI "V4SF")
348    (V8SF "V8SF") (V4SF "V4SF")
349    (V4DF "V8SF") (V2DF "V4SF")])
350
351 ;; Mapping of vector modes back to the scalar modes
352 (define_mode_attr ssescalarmode
353   [(V32QI "QI") (V16HI "HI") (V8SI "SI") (V4DI "DI")
354    (V16QI "QI") (V8HI "HI") (V4SI "SI") (V2DI "DI")
355    (V8SF "SF") (V4DF "DF")
356    (V4SF "SF") (V2DF "DF")])
357
358 ;; Number of scalar elements in each vector type
359 (define_mode_attr ssescalarnum
360   [(V32QI "32") (V16HI "16") (V8SI "8") (V4DI "4")
361    (V16QI "16") (V8HI "8") (V4SI "4") (V2DI "2")
362    (V8SF "8") (V4DF "4")
363    (V4SF "4") (V2DF "2")])
364
365 ;; SSE prefix for integer vector modes
366 (define_mode_attr sseintprefix
367   [(V2DI "p") (V2DF "")
368    (V4DI "p") (V4DF "")
369    (V4SI "p") (V4SF "")
370    (V8SI "p") (V8SF "")])
371
372 ;; SSE scalar suffix for vector modes
373 (define_mode_attr ssescalarmodesuffix
374   [(SF "ss") (DF "sd")
375    (V8SF "ss") (V4DF "sd")
376    (V4SF "ss") (V2DF "sd")
377    (V8SI "ss") (V4DI "sd")
378    (V4SI "d")])
379
380 ;; Pack/unpack vector modes
381 (define_mode_attr sseunpackmode
382   [(V16QI "V8HI") (V8HI "V4SI") (V4SI "V2DI")
383    (V32QI "V16HI") (V16HI "V8SI") (V8SI "V4DI")])
384
385 (define_mode_attr ssepackmode
386   [(V8HI "V16QI") (V4SI "V8HI") (V2DI "V4SI")
387    (V16HI "V32QI") (V8SI "V16HI") (V4DI "V8SI")])
388
389 ;; Mapping of the max integer size for xop rotate immediate constraint
390 (define_mode_attr sserotatemax
391   [(V16QI "7") (V8HI "15") (V4SI "31") (V2DI "63")])
392
393 ;; Mapping of mode to cast intrinsic name
394 (define_mode_attr castmode [(V8SI "si") (V8SF "ps") (V4DF "pd")])
395
396 ;; Instruction suffix for sign and zero extensions.
397 (define_code_attr extsuffix [(sign_extend "sx") (zero_extend "zx")])
398
399 ;; i128 for integer vectors and TARGET_AVX2, f128 otherwise.
400 (define_mode_attr i128
401   [(V8SF "f128") (V4DF "f128") (V32QI "%~128") (V16HI "%~128")
402    (V8SI "%~128") (V4DI "%~128")])
403
404 ;; Mix-n-match
405 (define_mode_iterator AVX256MODE2P [V8SI V8SF V4DF])
406
407 ;; Mapping of immediate bits for blend instructions
408 (define_mode_attr blendbits
409   [(V8SF "255") (V4SF "15") (V4DF "15") (V2DF "3")])
410
411 ;; Patterns whose name begins with "sse{,2,3}_" are invoked by intrinsics.
412
413 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
414 ;;
415 ;; Move patterns
416 ;;
417 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
418
419 ;; All of these patterns are enabled for SSE1 as well as SSE2.
420 ;; This is essential for maintaining stable calling conventions.
421
422 (define_expand "mov<mode>"
423   [(set (match_operand:V16 0 "nonimmediate_operand")
424         (match_operand:V16 1 "nonimmediate_operand"))]
425   "TARGET_SSE"
426 {
427   ix86_expand_vector_move (<MODE>mode, operands);
428   DONE;
429 })
430
431 (define_insn "*mov<mode>_internal"
432   [(set (match_operand:V16 0 "nonimmediate_operand"               "=x,x ,m")
433         (match_operand:V16 1 "nonimmediate_or_sse_const_operand"  "C ,xm,x"))]
434   "TARGET_SSE
435    && (register_operand (operands[0], <MODE>mode)
436        || register_operand (operands[1], <MODE>mode))"
437 {
438   switch (which_alternative)
439     {
440     case 0:
441       return standard_sse_constant_opcode (insn, operands[1]);
442     case 1:
443     case 2:
444       switch (get_attr_mode (insn))
445         {
446         case MODE_V8SF:
447         case MODE_V4SF:
448           if (TARGET_AVX
449               && (misaligned_operand (operands[0], <MODE>mode)
450                   || misaligned_operand (operands[1], <MODE>mode)))
451             return "vmovups\t{%1, %0|%0, %1}";
452           else
453             return "%vmovaps\t{%1, %0|%0, %1}";
454
455         case MODE_V4DF:
456         case MODE_V2DF:
457           if (TARGET_AVX
458               && (misaligned_operand (operands[0], <MODE>mode)
459                   || misaligned_operand (operands[1], <MODE>mode)))
460             return "vmovupd\t{%1, %0|%0, %1}";
461           else
462             return "%vmovapd\t{%1, %0|%0, %1}";
463
464         case MODE_OI:
465         case MODE_TI:
466           if (TARGET_AVX
467               && (misaligned_operand (operands[0], <MODE>mode)
468                   || misaligned_operand (operands[1], <MODE>mode)))
469             return "vmovdqu\t{%1, %0|%0, %1}";
470           else
471             return "%vmovdqa\t{%1, %0|%0, %1}";
472
473         default:
474           gcc_unreachable ();
475         }
476     default:
477       gcc_unreachable ();
478     }
479 }
480   [(set_attr "type" "sselog1,ssemov,ssemov")
481    (set_attr "prefix" "maybe_vex")
482    (set (attr "mode")
483         (cond [(match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
484                  (const_string "<ssePSmode>")
485                (and (eq_attr "alternative" "2")
486                     (match_test "TARGET_SSE_TYPELESS_STORES"))
487                  (const_string "<ssePSmode>")
488                (match_test "TARGET_AVX")
489                  (const_string "<sseinsnmode>")
490                (ior (not (match_test "TARGET_SSE2"))
491                     (match_test "optimize_function_for_size_p (cfun)"))
492                  (const_string "V4SF")
493                (and (eq_attr "alternative" "0")
494                     (match_test "TARGET_SSE_LOAD0_BY_PXOR"))
495                  (const_string "TI")
496               ]
497               (const_string "<sseinsnmode>")))])
498
499 (define_insn "sse2_movq128"
500   [(set (match_operand:V2DI 0 "register_operand" "=x")
501         (vec_concat:V2DI
502           (vec_select:DI
503             (match_operand:V2DI 1 "nonimmediate_operand" "xm")
504             (parallel [(const_int 0)]))
505           (const_int 0)))]
506   "TARGET_SSE2"
507   "%vmovq\t{%1, %0|%0, %1}"
508   [(set_attr "type" "ssemov")
509    (set_attr "prefix" "maybe_vex")
510    (set_attr "mode" "TI")])
511
512 ;; Move a DI from a 32-bit register pair (e.g. %edx:%eax) to an xmm.
513 ;; We'd rather avoid this entirely; if the 32-bit reg pair was loaded
514 ;; from memory, we'd prefer to load the memory directly into the %xmm
515 ;; register.  To facilitate this happy circumstance, this pattern won't
516 ;; split until after register allocation.  If the 64-bit value didn't
517 ;; come from memory, this is the best we can do.  This is much better
518 ;; than storing %edx:%eax into a stack temporary and loading an %xmm
519 ;; from there.
520
521 (define_insn_and_split "movdi_to_sse"
522   [(parallel
523     [(set (match_operand:V4SI 0 "register_operand" "=?x,x")
524           (subreg:V4SI (match_operand:DI 1 "nonimmediate_operand" "r,m") 0))
525      (clobber (match_scratch:V4SI 2 "=&x,X"))])]
526   "!TARGET_64BIT && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES"
527   "#"
528   "&& reload_completed"
529   [(const_int 0)]
530 {
531  if (register_operand (operands[1], DImode))
532    {
533       /* The DImode arrived in a pair of integral registers (e.g. %edx:%eax).
534          Assemble the 64-bit DImode value in an xmm register.  */
535       emit_insn (gen_sse2_loadld (operands[0], CONST0_RTX (V4SImode),
536                                   gen_rtx_SUBREG (SImode, operands[1], 0)));
537       emit_insn (gen_sse2_loadld (operands[2], CONST0_RTX (V4SImode),
538                                   gen_rtx_SUBREG (SImode, operands[1], 4)));
539       emit_insn (gen_vec_interleave_lowv4si (operands[0], operands[0],
540                                              operands[2]));
541     }
542  else if (memory_operand (operands[1], DImode))
543    emit_insn (gen_vec_concatv2di (gen_lowpart (V2DImode, operands[0]),
544                                   operands[1], const0_rtx));
545  else
546    gcc_unreachable ();
547 })
548
549 (define_split
550   [(set (match_operand:V4SF 0 "register_operand")
551         (match_operand:V4SF 1 "zero_extended_scalar_load_operand"))]
552   "TARGET_SSE && reload_completed"
553   [(set (match_dup 0)
554         (vec_merge:V4SF
555           (vec_duplicate:V4SF (match_dup 1))
556           (match_dup 2)
557           (const_int 1)))]
558 {
559   operands[1] = simplify_gen_subreg (SFmode, operands[1], V4SFmode, 0);
560   operands[2] = CONST0_RTX (V4SFmode);
561 })
562
563 (define_split
564   [(set (match_operand:V2DF 0 "register_operand")
565         (match_operand:V2DF 1 "zero_extended_scalar_load_operand"))]
566   "TARGET_SSE2 && reload_completed"
567   [(set (match_dup 0) (vec_concat:V2DF (match_dup 1) (match_dup 2)))]
568 {
569   operands[1] = simplify_gen_subreg (DFmode, operands[1], V2DFmode, 0);
570   operands[2] = CONST0_RTX (DFmode);
571 })
572
573 (define_expand "push<mode>1"
574   [(match_operand:V16 0 "register_operand")]
575   "TARGET_SSE"
576 {
577   ix86_expand_push (<MODE>mode, operands[0]);
578   DONE;
579 })
580
581 (define_expand "movmisalign<mode>"
582   [(set (match_operand:V16 0 "nonimmediate_operand")
583         (match_operand:V16 1 "nonimmediate_operand"))]
584   "TARGET_SSE"
585 {
586   ix86_expand_vector_move_misalign (<MODE>mode, operands);
587   DONE;
588 })
589
590 (define_insn "<sse>_loadu<ssemodesuffix><avxsizesuffix>"
591   [(set (match_operand:VF 0 "register_operand" "=x")
592         (unspec:VF
593           [(match_operand:VF 1 "memory_operand" "m")]
594           UNSPEC_LOADU))]
595   "TARGET_SSE"
596 {
597   switch (get_attr_mode (insn))
598     {
599     case MODE_V8SF:
600     case MODE_V4SF:
601       return "%vmovups\t{%1, %0|%0, %1}";
602     default:
603       return "%vmovu<ssemodesuffix>\t{%1, %0|%0, %1}";
604     }
605 }
606   [(set_attr "type" "ssemov")
607    (set_attr "movu" "1")
608    (set_attr "prefix" "maybe_vex")
609    (set (attr "mode")
610         (cond [(match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
611                  (const_string "<ssePSmode>")
612                (match_test "TARGET_AVX")
613                  (const_string "<MODE>")
614                (match_test "optimize_function_for_size_p (cfun)")
615                  (const_string "V4SF")
616               ]
617               (const_string "<MODE>")))])
618
619 (define_insn "<sse>_storeu<ssemodesuffix><avxsizesuffix>"
620   [(set (match_operand:VF 0 "memory_operand" "=m")
621         (unspec:VF
622           [(match_operand:VF 1 "register_operand" "x")]
623           UNSPEC_STOREU))]
624   "TARGET_SSE"
625 {
626   switch (get_attr_mode (insn))
627     {
628     case MODE_V8SF:
629     case MODE_V4SF:
630       return "%vmovups\t{%1, %0|%0, %1}";
631     default:
632       return "%vmovu<ssemodesuffix>\t{%1, %0|%0, %1}";
633     }
634 }
635   [(set_attr "type" "ssemov")
636    (set_attr "movu" "1")
637    (set_attr "prefix" "maybe_vex")
638    (set (attr "mode")
639         (cond [(ior (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
640                     (match_test "TARGET_SSE_TYPELESS_STORES"))
641                  (const_string "<ssePSmode>")
642                (match_test "TARGET_AVX")
643                  (const_string "<MODE>")
644                (match_test "optimize_function_for_size_p (cfun)")
645                  (const_string "V4SF")
646               ]
647               (const_string "<MODE>")))])
648
649 (define_insn "<sse2>_loaddqu<avxsizesuffix>"
650   [(set (match_operand:VI1 0 "register_operand" "=x")
651         (unspec:VI1 [(match_operand:VI1 1 "memory_operand" "m")]
652                     UNSPEC_LOADU))]
653   "TARGET_SSE2"
654 {
655   switch (get_attr_mode (insn))
656     {
657     case MODE_V8SF:
658     case MODE_V4SF:
659       return "%vmovups\t{%1, %0|%0, %1}";
660     default:
661       return "%vmovdqu\t{%1, %0|%0, %1}";
662     }
663 }
664   [(set_attr "type" "ssemov")
665    (set_attr "movu" "1")
666    (set (attr "prefix_data16")
667      (if_then_else
668        (match_test "TARGET_AVX")
669      (const_string "*")
670      (const_string "1")))
671    (set_attr "prefix" "maybe_vex")
672    (set (attr "mode")
673         (cond [(match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
674                  (const_string "<ssePSmode>")
675                (match_test "TARGET_AVX")
676                  (const_string "<sseinsnmode>")
677                (match_test "optimize_function_for_size_p (cfun)")
678                  (const_string "V4SF")
679               ]
680               (const_string "<sseinsnmode>")))])
681
682 (define_insn "<sse2>_storedqu<avxsizesuffix>"
683   [(set (match_operand:VI1 0 "memory_operand" "=m")
684         (unspec:VI1 [(match_operand:VI1 1 "register_operand" "x")]
685                     UNSPEC_STOREU))]
686   "TARGET_SSE2"
687 {
688   switch (get_attr_mode (insn))
689     {
690     case MODE_V8SF:
691     case MODE_V4SF:
692       return "%vmovups\t{%1, %0|%0, %1}";
693     default:
694       return "%vmovdqu\t{%1, %0|%0, %1}";
695     }
696 }
697   [(set_attr "type" "ssemov")
698    (set_attr "movu" "1")
699    (set (attr "prefix_data16")
700      (if_then_else
701        (match_test "TARGET_AVX")
702      (const_string "*")
703      (const_string "1")))
704    (set_attr "prefix" "maybe_vex")
705    (set (attr "mode")
706         (cond [(ior (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
707                     (match_test "TARGET_SSE_TYPELESS_STORES"))
708                  (const_string "<ssePSmode>")
709                (match_test "TARGET_AVX")
710                  (const_string "<sseinsnmode>")
711                (match_test "optimize_function_for_size_p (cfun)")
712                  (const_string "V4SF")
713               ]
714               (const_string "<sseinsnmode>")))])
715
716 (define_insn "<sse3>_lddqu<avxsizesuffix>"
717   [(set (match_operand:VI1 0 "register_operand" "=x")
718         (unspec:VI1 [(match_operand:VI1 1 "memory_operand" "m")]
719                     UNSPEC_LDDQU))]
720   "TARGET_SSE3"
721   "%vlddqu\t{%1, %0|%0, %1}"
722   [(set_attr "type" "ssemov")
723    (set_attr "movu" "1")
724    (set (attr "prefix_data16")
725      (if_then_else
726        (match_test "TARGET_AVX")
727      (const_string "*")
728      (const_string "0")))
729    (set (attr "prefix_rep")
730      (if_then_else
731        (match_test "TARGET_AVX")
732      (const_string "*")
733      (const_string "1")))
734    (set_attr "prefix" "maybe_vex")
735    (set_attr "mode" "<sseinsnmode>")])
736
737 (define_insn "sse2_movnti<mode>"
738   [(set (match_operand:SWI48 0 "memory_operand" "=m")
739         (unspec:SWI48 [(match_operand:SWI48 1 "register_operand" "r")]
740                       UNSPEC_MOVNT))]
741   "TARGET_SSE2"
742   "movnti\t{%1, %0|%0, %1}"
743   [(set_attr "type" "ssemov")
744    (set_attr "prefix_data16" "0")
745    (set_attr "mode" "<MODE>")])
746
747 (define_insn "<sse>_movnt<mode>"
748   [(set (match_operand:VF 0 "memory_operand" "=m")
749         (unspec:VF [(match_operand:VF 1 "register_operand" "x")]
750                    UNSPEC_MOVNT))]
751   "TARGET_SSE"
752   "%vmovnt<ssemodesuffix>\t{%1, %0|%0, %1}"
753   [(set_attr "type" "ssemov")
754    (set_attr "prefix" "maybe_vex")
755    (set_attr "mode" "<MODE>")])
756
757 (define_insn "<sse2>_movnt<mode>"
758   [(set (match_operand:VI8 0 "memory_operand" "=m")
759         (unspec:VI8 [(match_operand:VI8 1 "register_operand" "x")]
760                     UNSPEC_MOVNT))]
761   "TARGET_SSE2"
762   "%vmovntdq\t{%1, %0|%0, %1}"
763   [(set_attr "type" "ssecvt")
764    (set (attr "prefix_data16")
765      (if_then_else
766        (match_test "TARGET_AVX")
767      (const_string "*")
768      (const_string "1")))
769    (set_attr "prefix" "maybe_vex")
770    (set_attr "mode" "<sseinsnmode>")])
771
772 ; Expand patterns for non-temporal stores.  At the moment, only those
773 ; that directly map to insns are defined; it would be possible to
774 ; define patterns for other modes that would expand to several insns.
775
776 ;; Modes handled by storent patterns.
777 (define_mode_iterator STORENT_MODE
778   [(DI "TARGET_SSE2 && TARGET_64BIT") (SI "TARGET_SSE2")
779    (SF "TARGET_SSE4A") (DF "TARGET_SSE4A")
780    (V4DI "TARGET_AVX") (V2DI "TARGET_SSE2")
781    (V8SF "TARGET_AVX") V4SF
782    (V4DF "TARGET_AVX") (V2DF "TARGET_SSE2")])
783
784 (define_expand "storent<mode>"
785   [(set (match_operand:STORENT_MODE 0 "memory_operand")
786         (unspec:STORENT_MODE
787           [(match_operand:STORENT_MODE 1 "register_operand")]
788           UNSPEC_MOVNT))]
789   "TARGET_SSE")
790
791 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
792 ;;
793 ;; Parallel floating point arithmetic
794 ;;
795 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
796
797 (define_expand "<code><mode>2"
798   [(set (match_operand:VF 0 "register_operand")
799         (absneg:VF
800           (match_operand:VF 1 "register_operand")))]
801   "TARGET_SSE"
802   "ix86_expand_fp_absneg_operator (<CODE>, <MODE>mode, operands); DONE;")
803
804 (define_insn_and_split "*absneg<mode>2"
805   [(set (match_operand:VF 0 "register_operand" "=x,x,x,x")
806         (match_operator:VF 3 "absneg_operator"
807           [(match_operand:VF 1 "nonimmediate_operand" "0, xm,x, m")]))
808    (use (match_operand:VF 2 "nonimmediate_operand"    "xm,0, xm,x"))]
809   "TARGET_SSE"
810   "#"
811   "&& reload_completed"
812   [(const_int 0)]
813 {
814   enum rtx_code absneg_op;
815   rtx op1, op2;
816   rtx t;
817
818   if (TARGET_AVX)
819     {
820       if (MEM_P (operands[1]))
821         op1 = operands[2], op2 = operands[1];
822       else
823         op1 = operands[1], op2 = operands[2];
824     }
825   else
826     {
827       op1 = operands[0];
828       if (rtx_equal_p (operands[0], operands[1]))
829         op2 = operands[2];
830       else
831         op2 = operands[1];
832     }
833
834   absneg_op = GET_CODE (operands[3]) == NEG ? XOR : AND;
835   t = gen_rtx_fmt_ee (absneg_op, <MODE>mode, op1, op2);
836   t = gen_rtx_SET (VOIDmode, operands[0], t);
837   emit_insn (t);
838   DONE;
839 }
840   [(set_attr "isa" "noavx,noavx,avx,avx")])
841
842 (define_expand "<plusminus_insn><mode>3"
843   [(set (match_operand:VF 0 "register_operand")
844         (plusminus:VF
845           (match_operand:VF 1 "nonimmediate_operand")
846           (match_operand:VF 2 "nonimmediate_operand")))]
847   "TARGET_SSE"
848   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
849
850 (define_insn "*<plusminus_insn><mode>3"
851   [(set (match_operand:VF 0 "register_operand" "=x,x")
852         (plusminus:VF
853           (match_operand:VF 1 "nonimmediate_operand" "<comm>0,x")
854           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
855   "TARGET_SSE && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
856   "@
857    <plusminus_mnemonic><ssemodesuffix>\t{%2, %0|%0, %2}
858    v<plusminus_mnemonic><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
859   [(set_attr "isa" "noavx,avx")
860    (set_attr "type" "sseadd")
861    (set_attr "prefix" "orig,vex")
862    (set_attr "mode" "<MODE>")])
863
864 (define_insn "<sse>_vm<plusminus_insn><mode>3"
865   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
866         (vec_merge:VF_128
867           (plusminus:VF_128
868             (match_operand:VF_128 1 "register_operand" "0,x")
869             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm"))
870           (match_dup 1)
871           (const_int 1)))]
872   "TARGET_SSE"
873   "@
874    <plusminus_mnemonic><ssescalarmodesuffix>\t{%2, %0|%0, %2}
875    v<plusminus_mnemonic><ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
876   [(set_attr "isa" "noavx,avx")
877    (set_attr "type" "sseadd")
878    (set_attr "prefix" "orig,vex")
879    (set_attr "mode" "<ssescalarmode>")])
880
881 (define_expand "mul<mode>3"
882   [(set (match_operand:VF 0 "register_operand")
883         (mult:VF
884           (match_operand:VF 1 "nonimmediate_operand")
885           (match_operand:VF 2 "nonimmediate_operand")))]
886   "TARGET_SSE"
887   "ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);")
888
889 (define_insn "*mul<mode>3"
890   [(set (match_operand:VF 0 "register_operand" "=x,x")
891         (mult:VF
892           (match_operand:VF 1 "nonimmediate_operand" "%0,x")
893           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
894   "TARGET_SSE && ix86_binary_operator_ok (MULT, <MODE>mode, operands)"
895   "@
896    mul<ssemodesuffix>\t{%2, %0|%0, %2}
897    vmul<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
898   [(set_attr "isa" "noavx,avx")
899    (set_attr "type" "ssemul")
900    (set_attr "prefix" "orig,vex")
901    (set_attr "btver2_decode" "direct,double")
902    (set_attr "mode" "<MODE>")])
903
904 (define_insn "<sse>_vmmul<mode>3"
905   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
906         (vec_merge:VF_128
907           (mult:VF_128
908             (match_operand:VF_128 1 "register_operand" "0,x")
909             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm"))
910           (match_dup 1)
911           (const_int 1)))]
912   "TARGET_SSE"
913   "@
914    mul<ssescalarmodesuffix>\t{%2, %0|%0, %2}
915    vmul<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
916   [(set_attr "isa" "noavx,avx")
917    (set_attr "type" "ssemul")
918    (set_attr "prefix" "orig,vex")
919    (set_attr "mode" "<ssescalarmode>")])
920
921 (define_expand "div<mode>3"
922   [(set (match_operand:VF2 0 "register_operand")
923         (div:VF2 (match_operand:VF2 1 "register_operand")
924                  (match_operand:VF2 2 "nonimmediate_operand")))]
925   "TARGET_SSE2"
926   "ix86_fixup_binary_operands_no_copy (DIV, <MODE>mode, operands);")
927
928 (define_expand "div<mode>3"
929   [(set (match_operand:VF1 0 "register_operand")
930         (div:VF1 (match_operand:VF1 1 "register_operand")
931                  (match_operand:VF1 2 "nonimmediate_operand")))]
932   "TARGET_SSE"
933 {
934   ix86_fixup_binary_operands_no_copy (DIV, <MODE>mode, operands);
935
936   if (TARGET_SSE_MATH
937       && TARGET_RECIP_VEC_DIV
938       && !optimize_insn_for_size_p ()
939       && flag_finite_math_only && !flag_trapping_math
940       && flag_unsafe_math_optimizations)
941     {
942       ix86_emit_swdivsf (operands[0], operands[1], operands[2], <MODE>mode);
943       DONE;
944     }
945 })
946
947 (define_insn "<sse>_div<mode>3"
948   [(set (match_operand:VF 0 "register_operand" "=x,x")
949         (div:VF
950           (match_operand:VF 1 "register_operand" "0,x")
951           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
952   "TARGET_SSE"
953   "@
954    div<ssemodesuffix>\t{%2, %0|%0, %2}
955    vdiv<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
956   [(set_attr "isa" "noavx,avx")
957    (set_attr "type" "ssediv")
958    (set_attr "prefix" "orig,vex")
959    (set_attr "mode" "<MODE>")])
960
961 (define_insn "<sse>_vmdiv<mode>3"
962   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
963         (vec_merge:VF_128
964           (div:VF_128
965             (match_operand:VF_128 1 "register_operand" "0,x")
966             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm"))
967           (match_dup 1)
968           (const_int 1)))]
969   "TARGET_SSE"
970   "@
971    div<ssescalarmodesuffix>\t{%2, %0|%0, %2}
972    vdiv<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
973   [(set_attr "isa" "noavx,avx")
974    (set_attr "type" "ssediv")
975    (set_attr "prefix" "orig,vex")
976    (set_attr "btver2_decode" "direct,double")
977    (set_attr "mode" "<ssescalarmode>")])
978
979 (define_insn "<sse>_rcp<mode>2"
980   [(set (match_operand:VF1 0 "register_operand" "=x")
981         (unspec:VF1
982           [(match_operand:VF1 1 "nonimmediate_operand" "xm")] UNSPEC_RCP))]
983   "TARGET_SSE"
984   "%vrcpps\t{%1, %0|%0, %1}"
985   [(set_attr "type" "sse")
986    (set_attr "atom_sse_attr" "rcp")
987    (set_attr "btver2_sse_attr" "rcp")
988    (set_attr "prefix" "maybe_vex")
989    (set_attr "mode" "<MODE>")])
990
991 (define_insn "sse_vmrcpv4sf2"
992   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
993         (vec_merge:V4SF
994           (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "xm,xm")]
995                        UNSPEC_RCP)
996           (match_operand:V4SF 2 "register_operand" "0,x")
997           (const_int 1)))]
998   "TARGET_SSE"
999   "@
1000    rcpss\t{%1, %0|%0, %1}
1001    vrcpss\t{%1, %2, %0|%0, %2, %1}"
1002   [(set_attr "isa" "noavx,avx")
1003    (set_attr "type" "sse")
1004    (set_attr "atom_sse_attr" "rcp")
1005    (set_attr "btver2_sse_attr" "rcp")
1006    (set_attr "prefix" "orig,vex")
1007    (set_attr "mode" "SF")])
1008
1009 (define_expand "sqrt<mode>2"
1010   [(set (match_operand:VF2 0 "register_operand")
1011         (sqrt:VF2 (match_operand:VF2 1 "nonimmediate_operand")))]
1012   "TARGET_SSE2")
1013
1014 (define_expand "sqrt<mode>2"
1015   [(set (match_operand:VF1 0 "register_operand")
1016         (sqrt:VF1 (match_operand:VF1 1 "nonimmediate_operand")))]
1017   "TARGET_SSE"
1018 {
1019   if (TARGET_SSE_MATH
1020       && TARGET_RECIP_VEC_SQRT
1021       && !optimize_insn_for_size_p ()
1022       && flag_finite_math_only && !flag_trapping_math
1023       && flag_unsafe_math_optimizations)
1024     {
1025       ix86_emit_swsqrtsf (operands[0], operands[1], <MODE>mode, false);
1026       DONE;
1027     }
1028 })
1029
1030 (define_insn "<sse>_sqrt<mode>2"
1031   [(set (match_operand:VF 0 "register_operand" "=x")
1032         (sqrt:VF (match_operand:VF 1 "nonimmediate_operand" "xm")))]
1033   "TARGET_SSE"
1034   "%vsqrt<ssemodesuffix>\t{%1, %0|%0, %1}"
1035   [(set_attr "type" "sse")
1036    (set_attr "atom_sse_attr" "sqrt")
1037    (set_attr "btver2_sse_attr" "sqrt")
1038    (set_attr "prefix" "maybe_vex")
1039    (set_attr "mode" "<MODE>")])
1040
1041 (define_insn "<sse>_vmsqrt<mode>2"
1042   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
1043         (vec_merge:VF_128
1044           (sqrt:VF_128
1045             (match_operand:VF_128 1 "nonimmediate_operand" "xm,xm"))
1046           (match_operand:VF_128 2 "register_operand" "0,x")
1047           (const_int 1)))]
1048   "TARGET_SSE"
1049   "@
1050    sqrt<ssescalarmodesuffix>\t{%1, %0|%0, %1}
1051    vsqrt<ssescalarmodesuffix>\t{%1, %2, %0|%0, %2, %1}"
1052   [(set_attr "isa" "noavx,avx")
1053    (set_attr "type" "sse")
1054    (set_attr "atom_sse_attr" "sqrt")
1055    (set_attr "btver2_sse_attr" "sqrt")
1056    (set_attr "prefix" "orig,vex")
1057    (set_attr "mode" "<ssescalarmode>")])
1058
1059 (define_expand "rsqrt<mode>2"
1060   [(set (match_operand:VF1 0 "register_operand")
1061         (unspec:VF1
1062           [(match_operand:VF1 1 "nonimmediate_operand")] UNSPEC_RSQRT))]
1063   "TARGET_SSE_MATH"
1064 {
1065   ix86_emit_swsqrtsf (operands[0], operands[1], <MODE>mode, true);
1066   DONE;
1067 })
1068
1069 (define_insn "<sse>_rsqrt<mode>2"
1070   [(set (match_operand:VF1 0 "register_operand" "=x")
1071         (unspec:VF1
1072           [(match_operand:VF1 1 "nonimmediate_operand" "xm")] UNSPEC_RSQRT))]
1073   "TARGET_SSE"
1074   "%vrsqrtps\t{%1, %0|%0, %1}"
1075   [(set_attr "type" "sse")
1076    (set_attr "prefix" "maybe_vex")
1077    (set_attr "mode" "<MODE>")])
1078
1079 (define_insn "sse_vmrsqrtv4sf2"
1080   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
1081         (vec_merge:V4SF
1082           (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "xm,xm")]
1083                        UNSPEC_RSQRT)
1084           (match_operand:V4SF 2 "register_operand" "0,x")
1085           (const_int 1)))]
1086   "TARGET_SSE"
1087   "@
1088    rsqrtss\t{%1, %0|%0, %1}
1089    vrsqrtss\t{%1, %2, %0|%0, %2, %1}"
1090   [(set_attr "isa" "noavx,avx")
1091    (set_attr "type" "sse")
1092    (set_attr "prefix" "orig,vex")
1093    (set_attr "mode" "SF")])
1094
1095 ;; ??? For !flag_finite_math_only, the representation with SMIN/SMAX
1096 ;; isn't really correct, as those rtl operators aren't defined when
1097 ;; applied to NaNs.  Hopefully the optimizers won't get too smart on us.
1098
1099 (define_expand "<code><mode>3"
1100   [(set (match_operand:VF 0 "register_operand")
1101         (smaxmin:VF
1102           (match_operand:VF 1 "nonimmediate_operand")
1103           (match_operand:VF 2 "nonimmediate_operand")))]
1104   "TARGET_SSE"
1105 {
1106   if (!flag_finite_math_only)
1107     operands[1] = force_reg (<MODE>mode, operands[1]);
1108   ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);
1109 })
1110
1111 (define_insn "*<code><mode>3_finite"
1112   [(set (match_operand:VF 0 "register_operand" "=x,x")
1113         (smaxmin:VF
1114           (match_operand:VF 1 "nonimmediate_operand" "%0,x")
1115           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
1116   "TARGET_SSE && flag_finite_math_only
1117    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
1118   "@
1119    <maxmin_float><ssemodesuffix>\t{%2, %0|%0, %2}
1120    v<maxmin_float><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1121   [(set_attr "isa" "noavx,avx")
1122    (set_attr "type" "sseadd")
1123    (set_attr "btver2_sse_attr" "maxmin")
1124    (set_attr "prefix" "orig,vex")
1125    (set_attr "mode" "<MODE>")])
1126
1127 (define_insn "*<code><mode>3"
1128   [(set (match_operand:VF 0 "register_operand" "=x,x")
1129         (smaxmin:VF
1130           (match_operand:VF 1 "register_operand" "0,x")
1131           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
1132   "TARGET_SSE && !flag_finite_math_only"
1133   "@
1134    <maxmin_float><ssemodesuffix>\t{%2, %0|%0, %2}
1135    v<maxmin_float><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1136   [(set_attr "isa" "noavx,avx")
1137    (set_attr "type" "sseadd")
1138    (set_attr "btver2_sse_attr" "maxmin")
1139    (set_attr "prefix" "orig,vex")
1140    (set_attr "mode" "<MODE>")])
1141
1142 (define_insn "<sse>_vm<code><mode>3"
1143   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
1144         (vec_merge:VF_128
1145           (smaxmin:VF_128
1146             (match_operand:VF_128 1 "register_operand" "0,x")
1147             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm"))
1148          (match_dup 1)
1149          (const_int 1)))]
1150   "TARGET_SSE"
1151   "@
1152    <maxmin_float><ssescalarmodesuffix>\t{%2, %0|%0, %2}
1153    v<maxmin_float><ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1154   [(set_attr "isa" "noavx,avx")
1155    (set_attr "type" "sse")
1156    (set_attr "btver2_sse_attr" "maxmin")
1157    (set_attr "prefix" "orig,vex")
1158    (set_attr "mode" "<ssescalarmode>")])
1159
1160 ;; These versions of the min/max patterns implement exactly the operations
1161 ;;   min = (op1 < op2 ? op1 : op2)
1162 ;;   max = (!(op1 < op2) ? op1 : op2)
1163 ;; Their operands are not commutative, and thus they may be used in the
1164 ;; presence of -0.0 and NaN.
1165
1166 (define_insn "*ieee_smin<mode>3"
1167   [(set (match_operand:VF 0 "register_operand" "=x,x")
1168         (unspec:VF
1169           [(match_operand:VF 1 "register_operand" "0,x")
1170            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")]
1171          UNSPEC_IEEE_MIN))]
1172   "TARGET_SSE"
1173   "@
1174    min<ssemodesuffix>\t{%2, %0|%0, %2}
1175    vmin<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1176   [(set_attr "isa" "noavx,avx")
1177    (set_attr "type" "sseadd")
1178    (set_attr "prefix" "orig,vex")
1179    (set_attr "mode" "<MODE>")])
1180
1181 (define_insn "*ieee_smax<mode>3"
1182   [(set (match_operand:VF 0 "register_operand" "=x,x")
1183         (unspec:VF
1184           [(match_operand:VF 1 "register_operand" "0,x")
1185            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")]
1186          UNSPEC_IEEE_MAX))]
1187   "TARGET_SSE"
1188   "@
1189    max<ssemodesuffix>\t{%2, %0|%0, %2}
1190    vmax<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1191   [(set_attr "isa" "noavx,avx")
1192    (set_attr "type" "sseadd")
1193    (set_attr "prefix" "orig,vex")
1194    (set_attr "mode" "<MODE>")])
1195
1196 (define_insn "avx_addsubv4df3"
1197   [(set (match_operand:V4DF 0 "register_operand" "=x")
1198         (vec_merge:V4DF
1199           (plus:V4DF
1200             (match_operand:V4DF 1 "register_operand" "x")
1201             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
1202           (minus:V4DF (match_dup 1) (match_dup 2))
1203           (const_int 10)))]
1204   "TARGET_AVX"
1205   "vaddsubpd\t{%2, %1, %0|%0, %1, %2}"
1206   [(set_attr "type" "sseadd")
1207    (set_attr "prefix" "vex")
1208    (set_attr "mode" "V4DF")])
1209
1210 (define_insn "sse3_addsubv2df3"
1211   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
1212         (vec_merge:V2DF
1213           (plus:V2DF
1214             (match_operand:V2DF 1 "register_operand" "0,x")
1215             (match_operand:V2DF 2 "nonimmediate_operand" "xm,xm"))
1216           (minus:V2DF (match_dup 1) (match_dup 2))
1217           (const_int 2)))]
1218   "TARGET_SSE3"
1219   "@
1220    addsubpd\t{%2, %0|%0, %2}
1221    vaddsubpd\t{%2, %1, %0|%0, %1, %2}"
1222   [(set_attr "isa" "noavx,avx")
1223    (set_attr "type" "sseadd")
1224    (set_attr "atom_unit" "complex")
1225    (set_attr "prefix" "orig,vex")
1226    (set_attr "mode" "V2DF")])
1227
1228 (define_insn "avx_addsubv8sf3"
1229   [(set (match_operand:V8SF 0 "register_operand" "=x")
1230         (vec_merge:V8SF
1231           (plus:V8SF
1232             (match_operand:V8SF 1 "register_operand" "x")
1233             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
1234           (minus:V8SF (match_dup 1) (match_dup 2))
1235           (const_int 170)))]
1236   "TARGET_AVX"
1237   "vaddsubps\t{%2, %1, %0|%0, %1, %2}"
1238   [(set_attr "type" "sseadd")
1239    (set_attr "prefix" "vex")
1240    (set_attr "mode" "V8SF")])
1241
1242 (define_insn "sse3_addsubv4sf3"
1243   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
1244         (vec_merge:V4SF
1245           (plus:V4SF
1246             (match_operand:V4SF 1 "register_operand" "0,x")
1247             (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm"))
1248           (minus:V4SF (match_dup 1) (match_dup 2))
1249           (const_int 10)))]
1250   "TARGET_SSE3"
1251   "@
1252    addsubps\t{%2, %0|%0, %2}
1253    vaddsubps\t{%2, %1, %0|%0, %1, %2}"
1254   [(set_attr "isa" "noavx,avx")
1255    (set_attr "type" "sseadd")
1256    (set_attr "prefix" "orig,vex")
1257    (set_attr "prefix_rep" "1,*")
1258    (set_attr "mode" "V4SF")])
1259
1260 (define_insn "avx_h<plusminus_insn>v4df3"
1261   [(set (match_operand:V4DF 0 "register_operand" "=x")
1262         (vec_concat:V4DF
1263           (vec_concat:V2DF
1264             (plusminus:DF
1265               (vec_select:DF
1266                 (match_operand:V4DF 1 "register_operand" "x")
1267                 (parallel [(const_int 0)]))
1268               (vec_select:DF (match_dup 1) (parallel [(const_int 1)])))
1269             (plusminus:DF
1270               (vec_select:DF
1271                 (match_operand:V4DF 2 "nonimmediate_operand" "xm")
1272                 (parallel [(const_int 0)]))
1273               (vec_select:DF (match_dup 2) (parallel [(const_int 1)]))))
1274           (vec_concat:V2DF
1275             (plusminus:DF
1276               (vec_select:DF (match_dup 1) (parallel [(const_int 2)]))
1277               (vec_select:DF (match_dup 1) (parallel [(const_int 3)])))
1278             (plusminus:DF
1279               (vec_select:DF (match_dup 2) (parallel [(const_int 2)]))
1280               (vec_select:DF (match_dup 2) (parallel [(const_int 3)]))))))]
1281   "TARGET_AVX"
1282   "vh<plusminus_mnemonic>pd\t{%2, %1, %0|%0, %1, %2}"
1283   [(set_attr "type" "sseadd")
1284    (set_attr "prefix" "vex")
1285    (set_attr "mode" "V4DF")])
1286
1287 (define_expand "sse3_haddv2df3"
1288   [(set (match_operand:V2DF 0 "register_operand")
1289         (vec_concat:V2DF
1290           (plus:DF
1291             (vec_select:DF
1292               (match_operand:V2DF 1 "register_operand")
1293               (parallel [(const_int 0)]))
1294             (vec_select:DF (match_dup 1) (parallel [(const_int 1)])))
1295           (plus:DF
1296             (vec_select:DF
1297               (match_operand:V2DF 2 "nonimmediate_operand")
1298               (parallel [(const_int 0)]))
1299             (vec_select:DF (match_dup 2) (parallel [(const_int 1)])))))]
1300   "TARGET_SSE3")
1301
1302 (define_insn "*sse3_haddv2df3"
1303   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
1304         (vec_concat:V2DF
1305           (plus:DF
1306             (vec_select:DF
1307               (match_operand:V2DF 1 "register_operand" "0,x")
1308               (parallel [(match_operand:SI 3 "const_0_to_1_operand")]))
1309             (vec_select:DF
1310               (match_dup 1)
1311               (parallel [(match_operand:SI 4 "const_0_to_1_operand")])))
1312           (plus:DF
1313             (vec_select:DF
1314               (match_operand:V2DF 2 "nonimmediate_operand" "xm,xm")
1315               (parallel [(match_operand:SI 5 "const_0_to_1_operand")]))
1316             (vec_select:DF
1317               (match_dup 2)
1318               (parallel [(match_operand:SI 6 "const_0_to_1_operand")])))))]
1319   "TARGET_SSE3
1320    && INTVAL (operands[3]) != INTVAL (operands[4])
1321    && INTVAL (operands[5]) != INTVAL (operands[6])"
1322   "@
1323    haddpd\t{%2, %0|%0, %2}
1324    vhaddpd\t{%2, %1, %0|%0, %1, %2}"
1325   [(set_attr "isa" "noavx,avx")
1326    (set_attr "type" "sseadd")
1327    (set_attr "prefix" "orig,vex")
1328    (set_attr "mode" "V2DF")])
1329
1330 (define_insn "sse3_hsubv2df3"
1331   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
1332         (vec_concat:V2DF
1333           (minus:DF
1334             (vec_select:DF
1335               (match_operand:V2DF 1 "register_operand" "0,x")
1336               (parallel [(const_int 0)]))
1337             (vec_select:DF (match_dup 1) (parallel [(const_int 1)])))
1338           (minus:DF
1339             (vec_select:DF
1340               (match_operand:V2DF 2 "nonimmediate_operand" "xm,xm")
1341               (parallel [(const_int 0)]))
1342             (vec_select:DF (match_dup 2) (parallel [(const_int 1)])))))]
1343   "TARGET_SSE3"
1344   "@
1345    hsubpd\t{%2, %0|%0, %2}
1346    vhsubpd\t{%2, %1, %0|%0, %1, %2}"
1347   [(set_attr "isa" "noavx,avx")
1348    (set_attr "type" "sseadd")
1349    (set_attr "prefix" "orig,vex")
1350    (set_attr "mode" "V2DF")])
1351
1352 (define_insn "*sse3_haddv2df3_low"
1353   [(set (match_operand:DF 0 "register_operand" "=x,x")
1354         (plus:DF
1355           (vec_select:DF
1356             (match_operand:V2DF 1 "register_operand" "0,x")
1357             (parallel [(match_operand:SI 2 "const_0_to_1_operand")]))
1358           (vec_select:DF
1359             (match_dup 1)
1360             (parallel [(match_operand:SI 3 "const_0_to_1_operand")]))))]
1361   "TARGET_SSE3
1362    && INTVAL (operands[2]) != INTVAL (operands[3])"
1363   "@
1364    haddpd\t{%0, %0|%0, %0}
1365    vhaddpd\t{%1, %1, %0|%0, %1, %1}"
1366   [(set_attr "isa" "noavx,avx")
1367    (set_attr "type" "sseadd1")
1368    (set_attr "prefix" "orig,vex")
1369    (set_attr "mode" "V2DF")])
1370
1371 (define_insn "*sse3_hsubv2df3_low"
1372   [(set (match_operand:DF 0 "register_operand" "=x,x")
1373         (minus:DF
1374           (vec_select:DF
1375             (match_operand:V2DF 1 "register_operand" "0,x")
1376             (parallel [(const_int 0)]))
1377           (vec_select:DF
1378             (match_dup 1)
1379             (parallel [(const_int 1)]))))]
1380   "TARGET_SSE3"
1381   "@
1382    hsubpd\t{%0, %0|%0, %0}
1383    vhsubpd\t{%1, %1, %0|%0, %1, %1}"
1384   [(set_attr "isa" "noavx,avx")
1385    (set_attr "type" "sseadd1")
1386    (set_attr "prefix" "orig,vex")
1387    (set_attr "mode" "V2DF")])
1388
1389 (define_insn "avx_h<plusminus_insn>v8sf3"
1390   [(set (match_operand:V8SF 0 "register_operand" "=x")
1391         (vec_concat:V8SF
1392           (vec_concat:V4SF
1393             (vec_concat:V2SF
1394               (plusminus:SF
1395                 (vec_select:SF
1396                   (match_operand:V8SF 1 "register_operand" "x")
1397                   (parallel [(const_int 0)]))
1398                 (vec_select:SF (match_dup 1) (parallel [(const_int 1)])))
1399               (plusminus:SF
1400                 (vec_select:SF (match_dup 1) (parallel [(const_int 2)]))
1401                 (vec_select:SF (match_dup 1) (parallel [(const_int 3)]))))
1402             (vec_concat:V2SF
1403               (plusminus:SF
1404                 (vec_select:SF
1405                   (match_operand:V8SF 2 "nonimmediate_operand" "xm")
1406                   (parallel [(const_int 0)]))
1407                 (vec_select:SF (match_dup 2) (parallel [(const_int 1)])))
1408               (plusminus:SF
1409                 (vec_select:SF (match_dup 2) (parallel [(const_int 2)]))
1410                 (vec_select:SF (match_dup 2) (parallel [(const_int 3)])))))
1411           (vec_concat:V4SF
1412             (vec_concat:V2SF
1413               (plusminus:SF
1414                 (vec_select:SF (match_dup 1) (parallel [(const_int 4)]))
1415                 (vec_select:SF (match_dup 1) (parallel [(const_int 5)])))
1416               (plusminus:SF
1417                 (vec_select:SF (match_dup 1) (parallel [(const_int 6)]))
1418                 (vec_select:SF (match_dup 1) (parallel [(const_int 7)]))))
1419             (vec_concat:V2SF
1420               (plusminus:SF
1421                 (vec_select:SF (match_dup 2) (parallel [(const_int 4)]))
1422                 (vec_select:SF (match_dup 2) (parallel [(const_int 5)])))
1423               (plusminus:SF
1424                 (vec_select:SF (match_dup 2) (parallel [(const_int 6)]))
1425                 (vec_select:SF (match_dup 2) (parallel [(const_int 7)])))))))]
1426   "TARGET_AVX"
1427   "vh<plusminus_mnemonic>ps\t{%2, %1, %0|%0, %1, %2}"
1428   [(set_attr "type" "sseadd")
1429    (set_attr "prefix" "vex")
1430    (set_attr "mode" "V8SF")])
1431
1432 (define_insn "sse3_h<plusminus_insn>v4sf3"
1433   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
1434         (vec_concat:V4SF
1435           (vec_concat:V2SF
1436             (plusminus:SF
1437               (vec_select:SF
1438                 (match_operand:V4SF 1 "register_operand" "0,x")
1439                 (parallel [(const_int 0)]))
1440               (vec_select:SF (match_dup 1) (parallel [(const_int 1)])))
1441             (plusminus:SF
1442               (vec_select:SF (match_dup 1) (parallel [(const_int 2)]))
1443               (vec_select:SF (match_dup 1) (parallel [(const_int 3)]))))
1444           (vec_concat:V2SF
1445             (plusminus:SF
1446               (vec_select:SF
1447                 (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm")
1448                 (parallel [(const_int 0)]))
1449               (vec_select:SF (match_dup 2) (parallel [(const_int 1)])))
1450             (plusminus:SF
1451               (vec_select:SF (match_dup 2) (parallel [(const_int 2)]))
1452               (vec_select:SF (match_dup 2) (parallel [(const_int 3)]))))))]
1453   "TARGET_SSE3"
1454   "@
1455    h<plusminus_mnemonic>ps\t{%2, %0|%0, %2}
1456    vh<plusminus_mnemonic>ps\t{%2, %1, %0|%0, %1, %2}"
1457   [(set_attr "isa" "noavx,avx")
1458    (set_attr "type" "sseadd")
1459    (set_attr "atom_unit" "complex")
1460    (set_attr "prefix" "orig,vex")
1461    (set_attr "prefix_rep" "1,*")
1462    (set_attr "mode" "V4SF")])
1463
1464 (define_expand "reduc_splus_v4df"
1465   [(match_operand:V4DF 0 "register_operand")
1466    (match_operand:V4DF 1 "register_operand")]
1467   "TARGET_AVX"
1468 {
1469   rtx tmp = gen_reg_rtx (V4DFmode);
1470   rtx tmp2 = gen_reg_rtx (V4DFmode);
1471   emit_insn (gen_avx_haddv4df3 (tmp, operands[1], operands[1]));
1472   emit_insn (gen_avx_vperm2f128v4df3 (tmp2, tmp, tmp, GEN_INT (1)));
1473   emit_insn (gen_addv4df3 (operands[0], tmp, tmp2));
1474   DONE;
1475 })
1476
1477 (define_expand "reduc_splus_v2df"
1478   [(match_operand:V2DF 0 "register_operand")
1479    (match_operand:V2DF 1 "register_operand")]
1480   "TARGET_SSE3"
1481 {
1482   emit_insn (gen_sse3_haddv2df3 (operands[0], operands[1], operands[1]));
1483   DONE;
1484 })
1485
1486 (define_expand "reduc_splus_v8sf"
1487   [(match_operand:V8SF 0 "register_operand")
1488    (match_operand:V8SF 1 "register_operand")]
1489   "TARGET_AVX"
1490 {
1491   rtx tmp = gen_reg_rtx (V8SFmode);
1492   rtx tmp2 = gen_reg_rtx (V8SFmode);
1493   emit_insn (gen_avx_haddv8sf3 (tmp, operands[1], operands[1]));
1494   emit_insn (gen_avx_haddv8sf3 (tmp2, tmp, tmp));
1495   emit_insn (gen_avx_vperm2f128v8sf3 (tmp, tmp2, tmp2, GEN_INT (1)));
1496   emit_insn (gen_addv8sf3 (operands[0], tmp, tmp2));
1497   DONE;
1498 })
1499
1500 (define_expand "reduc_splus_v4sf"
1501   [(match_operand:V4SF 0 "register_operand")
1502    (match_operand:V4SF 1 "register_operand")]
1503   "TARGET_SSE"
1504 {
1505   if (TARGET_SSE3)
1506     {
1507       rtx tmp = gen_reg_rtx (V4SFmode);
1508       emit_insn (gen_sse3_haddv4sf3 (tmp, operands[1], operands[1]));
1509       emit_insn (gen_sse3_haddv4sf3 (operands[0], tmp, tmp));
1510     }
1511   else
1512     ix86_expand_reduc (gen_addv4sf3, operands[0], operands[1]);
1513   DONE;
1514 })
1515
1516 ;; Modes handled by reduc_sm{in,ax}* patterns.
1517 (define_mode_iterator REDUC_SMINMAX_MODE
1518   [(V32QI "TARGET_AVX2") (V16HI "TARGET_AVX2")
1519    (V8SI "TARGET_AVX2") (V4DI "TARGET_AVX2")
1520    (V8SF "TARGET_AVX") (V4DF "TARGET_AVX")
1521    (V4SF "TARGET_SSE")])
1522
1523 (define_expand "reduc_<code>_<mode>"
1524   [(smaxmin:REDUC_SMINMAX_MODE
1525      (match_operand:REDUC_SMINMAX_MODE 0 "register_operand")
1526      (match_operand:REDUC_SMINMAX_MODE 1 "register_operand"))]
1527   ""
1528 {
1529   ix86_expand_reduc (gen_<code><mode>3, operands[0], operands[1]);
1530   DONE;
1531 })
1532
1533 (define_expand "reduc_<code>_<mode>"
1534   [(umaxmin:VI_256
1535      (match_operand:VI_256 0 "register_operand")
1536      (match_operand:VI_256 1 "register_operand"))]
1537   "TARGET_AVX2"
1538 {
1539   ix86_expand_reduc (gen_<code><mode>3, operands[0], operands[1]);
1540   DONE;
1541 })
1542
1543 (define_expand "reduc_umin_v8hi"
1544   [(umin:V8HI
1545      (match_operand:V8HI 0 "register_operand")
1546      (match_operand:V8HI 1 "register_operand"))]
1547   "TARGET_SSE4_1"
1548 {
1549   ix86_expand_reduc (gen_uminv8hi3, operands[0], operands[1]);
1550   DONE;
1551 })
1552
1553 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1554 ;;
1555 ;; Parallel floating point comparisons
1556 ;;
1557 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1558
1559 (define_insn "avx_cmp<mode>3"
1560   [(set (match_operand:VF 0 "register_operand" "=x")
1561         (unspec:VF
1562           [(match_operand:VF 1 "register_operand" "x")
1563            (match_operand:VF 2 "nonimmediate_operand" "xm")
1564            (match_operand:SI 3 "const_0_to_31_operand" "n")]
1565           UNSPEC_PCMP))]
1566   "TARGET_AVX"
1567   "vcmp<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1568   [(set_attr "type" "ssecmp")
1569    (set_attr "length_immediate" "1")
1570    (set_attr "prefix" "vex")
1571    (set_attr "mode" "<MODE>")])
1572
1573 (define_insn "avx_vmcmp<mode>3"
1574   [(set (match_operand:VF_128 0 "register_operand" "=x")
1575         (vec_merge:VF_128
1576           (unspec:VF_128
1577             [(match_operand:VF_128 1 "register_operand" "x")
1578              (match_operand:VF_128 2 "nonimmediate_operand" "xm")
1579              (match_operand:SI 3 "const_0_to_31_operand" "n")]
1580             UNSPEC_PCMP)
1581          (match_dup 1)
1582          (const_int 1)))]
1583   "TARGET_AVX"
1584   "vcmp<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1585   [(set_attr "type" "ssecmp")
1586    (set_attr "length_immediate" "1")
1587    (set_attr "prefix" "vex")
1588    (set_attr "mode" "<ssescalarmode>")])
1589
1590 (define_insn "*<sse>_maskcmp<mode>3_comm"
1591   [(set (match_operand:VF 0 "register_operand" "=x,x")
1592         (match_operator:VF 3 "sse_comparison_operator"
1593           [(match_operand:VF 1 "register_operand" "%0,x")
1594            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")]))]
1595   "TARGET_SSE
1596    && GET_RTX_CLASS (GET_CODE (operands[3])) == RTX_COMM_COMPARE"
1597   "@
1598    cmp%D3<ssemodesuffix>\t{%2, %0|%0, %2}
1599    vcmp%D3<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1600   [(set_attr "isa" "noavx,avx")
1601    (set_attr "type" "ssecmp")
1602    (set_attr "length_immediate" "1")
1603    (set_attr "prefix" "orig,vex")
1604    (set_attr "mode" "<MODE>")])
1605
1606 (define_insn "<sse>_maskcmp<mode>3"
1607   [(set (match_operand:VF 0 "register_operand" "=x,x")
1608         (match_operator:VF 3 "sse_comparison_operator"
1609           [(match_operand:VF 1 "register_operand" "0,x")
1610            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")]))]
1611   "TARGET_SSE"
1612   "@
1613    cmp%D3<ssemodesuffix>\t{%2, %0|%0, %2}
1614    vcmp%D3<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1615   [(set_attr "isa" "noavx,avx")
1616    (set_attr "type" "ssecmp")
1617    (set_attr "length_immediate" "1")
1618    (set_attr "prefix" "orig,vex")
1619    (set_attr "mode" "<MODE>")])
1620
1621 (define_insn "<sse>_vmmaskcmp<mode>3"
1622   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
1623         (vec_merge:VF_128
1624          (match_operator:VF_128 3 "sse_comparison_operator"
1625            [(match_operand:VF_128 1 "register_operand" "0,x")
1626             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm")])
1627          (match_dup 1)
1628          (const_int 1)))]
1629   "TARGET_SSE"
1630   "@
1631    cmp%D3<ssescalarmodesuffix>\t{%2, %0|%0, %2}
1632    vcmp%D3<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1633   [(set_attr "isa" "noavx,avx")
1634    (set_attr "type" "ssecmp")
1635    (set_attr "length_immediate" "1,*")
1636    (set_attr "prefix" "orig,vex")
1637    (set_attr "mode" "<ssescalarmode>")])
1638
1639 (define_insn "<sse>_comi"
1640   [(set (reg:CCFP FLAGS_REG)
1641         (compare:CCFP
1642           (vec_select:MODEF
1643             (match_operand:<ssevecmode> 0 "register_operand" "x")
1644             (parallel [(const_int 0)]))
1645           (vec_select:MODEF
1646             (match_operand:<ssevecmode> 1 "nonimmediate_operand" "xm")
1647             (parallel [(const_int 0)]))))]
1648   "SSE_FLOAT_MODE_P (<MODE>mode)"
1649   "%vcomi<ssemodesuffix>\t{%1, %0|%0, %1}"
1650   [(set_attr "type" "ssecomi")
1651    (set_attr "prefix" "maybe_vex")
1652    (set_attr "prefix_rep" "0")
1653    (set (attr "prefix_data16")
1654         (if_then_else (eq_attr "mode" "DF")
1655                       (const_string "1")
1656                       (const_string "0")))
1657    (set_attr "mode" "<MODE>")])
1658
1659 (define_insn "<sse>_ucomi"
1660   [(set (reg:CCFPU FLAGS_REG)
1661         (compare:CCFPU
1662           (vec_select:MODEF
1663             (match_operand:<ssevecmode> 0 "register_operand" "x")
1664             (parallel [(const_int 0)]))
1665           (vec_select:MODEF
1666             (match_operand:<ssevecmode> 1 "nonimmediate_operand" "xm")
1667             (parallel [(const_int 0)]))))]
1668   "SSE_FLOAT_MODE_P (<MODE>mode)"
1669   "%vucomi<ssemodesuffix>\t{%1, %0|%0, %1}"
1670   [(set_attr "type" "ssecomi")
1671    (set_attr "prefix" "maybe_vex")
1672    (set_attr "prefix_rep" "0")
1673    (set (attr "prefix_data16")
1674         (if_then_else (eq_attr "mode" "DF")
1675                       (const_string "1")
1676                       (const_string "0")))
1677    (set_attr "mode" "<MODE>")])
1678
1679 (define_expand "vcond<V_256:mode><VF_256:mode>"
1680   [(set (match_operand:V_256 0 "register_operand")
1681         (if_then_else:V_256
1682           (match_operator 3 ""
1683             [(match_operand:VF_256 4 "nonimmediate_operand")
1684              (match_operand:VF_256 5 "nonimmediate_operand")])
1685           (match_operand:V_256 1 "general_operand")
1686           (match_operand:V_256 2 "general_operand")))]
1687   "TARGET_AVX
1688    && (GET_MODE_NUNITS (<V_256:MODE>mode)
1689        == GET_MODE_NUNITS (<VF_256:MODE>mode))"
1690 {
1691   bool ok = ix86_expand_fp_vcond (operands);
1692   gcc_assert (ok);
1693   DONE;
1694 })
1695
1696 (define_expand "vcond<V_128:mode><VF_128:mode>"
1697   [(set (match_operand:V_128 0 "register_operand")
1698         (if_then_else:V_128
1699           (match_operator 3 ""
1700             [(match_operand:VF_128 4 "nonimmediate_operand")
1701              (match_operand:VF_128 5 "nonimmediate_operand")])
1702           (match_operand:V_128 1 "general_operand")
1703           (match_operand:V_128 2 "general_operand")))]
1704   "TARGET_SSE
1705    && (GET_MODE_NUNITS (<V_128:MODE>mode)
1706        == GET_MODE_NUNITS (<VF_128:MODE>mode))"
1707 {
1708   bool ok = ix86_expand_fp_vcond (operands);
1709   gcc_assert (ok);
1710   DONE;
1711 })
1712
1713 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1714 ;;
1715 ;; Parallel floating point logical operations
1716 ;;
1717 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1718
1719 (define_insn "<sse>_andnot<mode>3"
1720   [(set (match_operand:VF 0 "register_operand" "=x,x")
1721         (and:VF
1722           (not:VF
1723             (match_operand:VF 1 "register_operand" "0,x"))
1724           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
1725   "TARGET_SSE"
1726 {
1727   static char buf[32];
1728   const char *ops;
1729   const char *suffix;
1730
1731   switch (get_attr_mode (insn))
1732     {
1733     case MODE_V8SF:
1734     case MODE_V4SF:
1735       suffix = "ps";
1736       break;
1737     default:
1738       suffix = "<ssemodesuffix>";
1739     }
1740
1741   switch (which_alternative)
1742     {
1743     case 0:
1744       ops = "andn%s\t{%%2, %%0|%%0, %%2}";
1745       break;
1746     case 1:
1747       ops = "vandn%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
1748       break;
1749     default:
1750       gcc_unreachable ();
1751     }
1752
1753   snprintf (buf, sizeof (buf), ops, suffix);
1754   return buf;
1755 }
1756   [(set_attr "isa" "noavx,avx")
1757    (set_attr "type" "sselog")
1758    (set_attr "prefix" "orig,vex")
1759    (set (attr "mode")
1760         (cond [(match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
1761                  (const_string "<ssePSmode>")
1762                (match_test "TARGET_AVX")
1763                  (const_string "<MODE>")
1764                (match_test "optimize_function_for_size_p (cfun)")
1765                  (const_string "V4SF")
1766                ]
1767                (const_string "<MODE>")))])
1768
1769 (define_expand "<code><mode>3"
1770   [(set (match_operand:VF 0 "register_operand")
1771         (any_logic:VF
1772           (match_operand:VF 1 "nonimmediate_operand")
1773           (match_operand:VF 2 "nonimmediate_operand")))]
1774   "TARGET_SSE"
1775   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
1776
1777 (define_insn "*<code><mode>3"
1778   [(set (match_operand:VF 0 "register_operand" "=x,x")
1779         (any_logic:VF
1780           (match_operand:VF 1 "nonimmediate_operand" "%0,x")
1781           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
1782   "TARGET_SSE && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
1783 {
1784   static char buf[32];
1785   const char *ops;
1786   const char *suffix;
1787
1788   switch (get_attr_mode (insn))
1789     {
1790     case MODE_V8SF:
1791     case MODE_V4SF:
1792       suffix = "ps";
1793       break;
1794     default:
1795       suffix = "<ssemodesuffix>";
1796     }
1797
1798   switch (which_alternative)
1799     {
1800     case 0:
1801       ops = "<logic>%s\t{%%2, %%0|%%0, %%2}";
1802       break;
1803     case 1:
1804       ops = "v<logic>%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
1805       break;
1806     default:
1807       gcc_unreachable ();
1808     }
1809
1810   snprintf (buf, sizeof (buf), ops, suffix);
1811   return buf;
1812 }
1813   [(set_attr "isa" "noavx,avx")
1814    (set_attr "type" "sselog")
1815    (set_attr "prefix" "orig,vex")
1816    (set (attr "mode")
1817         (cond [(match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
1818                  (const_string "<ssePSmode>")
1819                (match_test "TARGET_AVX")
1820                  (const_string "<MODE>")
1821                (match_test "optimize_function_for_size_p (cfun)")
1822                  (const_string "V4SF")
1823                ]
1824                (const_string "<MODE>")))])
1825
1826 (define_expand "copysign<mode>3"
1827   [(set (match_dup 4)
1828         (and:VF
1829           (not:VF (match_dup 3))
1830           (match_operand:VF 1 "nonimmediate_operand")))
1831    (set (match_dup 5)
1832         (and:VF (match_dup 3)
1833                 (match_operand:VF 2 "nonimmediate_operand")))
1834    (set (match_operand:VF 0 "register_operand")
1835         (ior:VF (match_dup 4) (match_dup 5)))]
1836   "TARGET_SSE"
1837 {
1838   operands[3] = ix86_build_signbit_mask (<MODE>mode, 1, 0);
1839
1840   operands[4] = gen_reg_rtx (<MODE>mode);
1841   operands[5] = gen_reg_rtx (<MODE>mode);
1842 })
1843
1844 ;; Also define scalar versions.  These are used for abs, neg, and
1845 ;; conditional move.  Using subregs into vector modes causes register
1846 ;; allocation lossage.  These patterns do not allow memory operands
1847 ;; because the native instructions read the full 128-bits.
1848
1849 (define_insn "*andnot<mode>3"
1850   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
1851         (and:MODEF
1852           (not:MODEF
1853             (match_operand:MODEF 1 "register_operand" "0,x"))
1854             (match_operand:MODEF 2 "register_operand" "x,x")))]
1855   "SSE_FLOAT_MODE_P (<MODE>mode)"
1856 {
1857   static char buf[32];
1858   const char *ops;
1859   const char *suffix
1860     = (get_attr_mode (insn) == MODE_V4SF) ? "ps" : "<ssevecmodesuffix>";
1861
1862   switch (which_alternative)
1863     {
1864     case 0:
1865       ops = "andn%s\t{%%2, %%0|%%0, %%2}";
1866       break;
1867     case 1:
1868       ops = "vandn%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
1869       break;
1870     default:
1871       gcc_unreachable ();
1872     }
1873
1874   snprintf (buf, sizeof (buf), ops, suffix);
1875   return buf;
1876 }
1877   [(set_attr "isa" "noavx,avx")
1878    (set_attr "type" "sselog")
1879    (set_attr "prefix" "orig,vex")
1880    (set (attr "mode")
1881         (cond [(match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
1882                  (const_string "V4SF")
1883                (match_test "TARGET_AVX")
1884                  (const_string "<ssevecmode>")
1885                (match_test "optimize_function_for_size_p (cfun)")
1886                  (const_string "V4SF")
1887                ]
1888                (const_string "<ssevecmode>")))])
1889
1890 (define_insn "*andnottf3"
1891   [(set (match_operand:TF 0 "register_operand" "=x,x")
1892         (and:TF
1893           (not:TF (match_operand:TF 1 "register_operand" "0,x"))
1894           (match_operand:TF 2 "nonimmediate_operand" "xm,xm")))]
1895   "TARGET_SSE"
1896 {
1897   static char buf[32];
1898   const char *ops;
1899   const char *tmp
1900     = (get_attr_mode (insn) == MODE_V4SF) ? "andnps" : "pandn";
1901
1902   switch (which_alternative)
1903     {
1904     case 0:
1905       ops = "%s\t{%%2, %%0|%%0, %%2}";
1906       break;
1907     case 1:
1908       ops = "v%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
1909       break;
1910     default:
1911       gcc_unreachable ();
1912     }
1913
1914   snprintf (buf, sizeof (buf), ops, tmp);
1915   return buf;
1916 }
1917   [(set_attr "isa" "noavx,avx")
1918    (set_attr "type" "sselog")
1919    (set (attr "prefix_data16")
1920      (if_then_else
1921        (and (eq_attr "alternative" "0")
1922             (eq_attr "mode" "TI"))
1923        (const_string "1")
1924        (const_string "*")))
1925    (set_attr "prefix" "orig,vex")
1926    (set (attr "mode")
1927         (cond [(match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
1928                  (const_string "V4SF")
1929                (match_test "TARGET_AVX")
1930                  (const_string "TI")
1931                (ior (not (match_test "TARGET_SSE2"))
1932                     (match_test "optimize_function_for_size_p (cfun)"))
1933                  (const_string "V4SF")
1934                ]
1935                (const_string "TI")))])
1936
1937 (define_insn "*<code><mode>3"
1938   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
1939         (any_logic:MODEF
1940           (match_operand:MODEF 1 "register_operand" "%0,x")
1941           (match_operand:MODEF 2 "register_operand" "x,x")))]
1942   "SSE_FLOAT_MODE_P (<MODE>mode)"
1943 {
1944   static char buf[32];
1945   const char *ops;
1946   const char *suffix
1947     = (get_attr_mode (insn) == MODE_V4SF) ? "ps" : "<ssevecmodesuffix>";
1948
1949   switch (which_alternative)
1950     {
1951     case 0:
1952       ops = "<logic>%s\t{%%2, %%0|%%0, %%2}";
1953       break;
1954     case 1:
1955       ops = "v<logic>%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
1956       break;
1957     default:
1958       gcc_unreachable ();
1959     }
1960
1961   snprintf (buf, sizeof (buf), ops, suffix);
1962   return buf;
1963 }
1964   [(set_attr "isa" "noavx,avx")
1965    (set_attr "type" "sselog")
1966    (set_attr "prefix" "orig,vex")
1967    (set (attr "mode")
1968         (cond [(match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
1969                  (const_string "V4SF")
1970                (match_test "TARGET_AVX")
1971                  (const_string "<ssevecmode>")
1972                (match_test "optimize_function_for_size_p (cfun)")
1973                  (const_string "V4SF")
1974                ]
1975                (const_string "<ssevecmode>")))])
1976
1977 (define_expand "<code>tf3"
1978   [(set (match_operand:TF 0 "register_operand")
1979         (any_logic:TF
1980           (match_operand:TF 1 "nonimmediate_operand")
1981           (match_operand:TF 2 "nonimmediate_operand")))]
1982   "TARGET_SSE"
1983   "ix86_fixup_binary_operands_no_copy (<CODE>, TFmode, operands);")
1984
1985 (define_insn "*<code>tf3"
1986   [(set (match_operand:TF 0 "register_operand" "=x,x")
1987         (any_logic:TF
1988           (match_operand:TF 1 "nonimmediate_operand" "%0,x")
1989           (match_operand:TF 2 "nonimmediate_operand" "xm,xm")))]
1990   "TARGET_SSE
1991    && ix86_binary_operator_ok (<CODE>, TFmode, operands)"
1992 {
1993   static char buf[32];
1994   const char *ops;
1995   const char *tmp
1996     = (get_attr_mode (insn) == MODE_V4SF) ? "<logic>ps" : "p<logic>";
1997
1998   switch (which_alternative)
1999     {
2000     case 0:
2001       ops = "%s\t{%%2, %%0|%%0, %%2}";
2002       break;
2003     case 1:
2004       ops = "v%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
2005       break;
2006     default:
2007       gcc_unreachable ();
2008     }
2009
2010   snprintf (buf, sizeof (buf), ops, tmp);
2011   return buf;
2012 }
2013   [(set_attr "isa" "noavx,avx")
2014    (set_attr "type" "sselog")
2015    (set (attr "prefix_data16")
2016      (if_then_else
2017        (and (eq_attr "alternative" "0")
2018             (eq_attr "mode" "TI"))
2019        (const_string "1")
2020        (const_string "*")))
2021    (set_attr "prefix" "orig,vex")
2022    (set (attr "mode")
2023         (cond [(match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
2024                  (const_string "V4SF")
2025                (match_test "TARGET_AVX")
2026                  (const_string "TI")
2027                (ior (not (match_test "TARGET_SSE2"))
2028                     (match_test "optimize_function_for_size_p (cfun)"))
2029                  (const_string "V4SF")
2030                ]
2031                (const_string "TI")))])
2032
2033 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2034 ;;
2035 ;; FMA floating point multiply/accumulate instructions.  These include
2036 ;; scalar versions of the instructions as well as vector versions.
2037 ;;
2038 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2039
2040 ;; The standard names for scalar FMA are only available with SSE math enabled.
2041 (define_mode_iterator FMAMODEM [(SF "TARGET_SSE_MATH")
2042                                 (DF "TARGET_SSE_MATH")
2043                                 V4SF V2DF V8SF V4DF])
2044
2045 (define_expand "fma<mode>4"
2046   [(set (match_operand:FMAMODEM 0 "register_operand")
2047         (fma:FMAMODEM
2048           (match_operand:FMAMODEM 1 "nonimmediate_operand")
2049           (match_operand:FMAMODEM 2 "nonimmediate_operand")
2050           (match_operand:FMAMODEM 3 "nonimmediate_operand")))]
2051   "TARGET_FMA || TARGET_FMA4")
2052
2053 (define_expand "fms<mode>4"
2054   [(set (match_operand:FMAMODEM 0 "register_operand")
2055         (fma:FMAMODEM
2056           (match_operand:FMAMODEM 1 "nonimmediate_operand")
2057           (match_operand:FMAMODEM 2 "nonimmediate_operand")
2058           (neg:FMAMODEM (match_operand:FMAMODEM 3 "nonimmediate_operand"))))]
2059   "TARGET_FMA || TARGET_FMA4")
2060
2061 (define_expand "fnma<mode>4"
2062   [(set (match_operand:FMAMODEM 0 "register_operand")
2063         (fma:FMAMODEM
2064           (neg:FMAMODEM (match_operand:FMAMODEM 1 "nonimmediate_operand"))
2065           (match_operand:FMAMODEM 2 "nonimmediate_operand")
2066           (match_operand:FMAMODEM 3 "nonimmediate_operand")))]
2067   "TARGET_FMA || TARGET_FMA4")
2068
2069 (define_expand "fnms<mode>4"
2070   [(set (match_operand:FMAMODEM 0 "register_operand")
2071         (fma:FMAMODEM
2072           (neg:FMAMODEM (match_operand:FMAMODEM 1 "nonimmediate_operand"))
2073           (match_operand:FMAMODEM 2 "nonimmediate_operand")
2074           (neg:FMAMODEM (match_operand:FMAMODEM 3 "nonimmediate_operand"))))]
2075   "TARGET_FMA || TARGET_FMA4")
2076
2077 ;; The builtins for intrinsics are not constrained by SSE math enabled.
2078 (define_mode_iterator FMAMODE [SF DF V4SF V2DF V8SF V4DF])
2079
2080 (define_expand "fma4i_fmadd_<mode>"
2081   [(set (match_operand:FMAMODE 0 "register_operand")
2082         (fma:FMAMODE
2083           (match_operand:FMAMODE 1 "nonimmediate_operand")
2084           (match_operand:FMAMODE 2 "nonimmediate_operand")
2085           (match_operand:FMAMODE 3 "nonimmediate_operand")))]
2086   "TARGET_FMA || TARGET_FMA4")
2087
2088 (define_insn "*fma_fmadd_<mode>"
2089   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x,x,x,x")
2090         (fma:FMAMODE
2091           (match_operand:FMAMODE 1 "nonimmediate_operand" "%0, 0,x, x,x")
2092           (match_operand:FMAMODE 2 "nonimmediate_operand" "xm, x,xm,x,m")
2093           (match_operand:FMAMODE 3 "nonimmediate_operand" " x,xm,0,xm,x")))]
2094   "TARGET_FMA || TARGET_FMA4"
2095   "@
2096    vfmadd132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
2097    vfmadd213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
2098    vfmadd231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}
2099    vfmadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}
2100    vfmadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
2101   [(set_attr "isa" "fma,fma,fma,fma4,fma4")
2102    (set_attr "type" "ssemuladd")
2103    (set_attr "mode" "<MODE>")])
2104
2105 (define_insn "*fma_fmsub_<mode>"
2106   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x,x,x,x")
2107         (fma:FMAMODE
2108           (match_operand:FMAMODE   1 "nonimmediate_operand" "%0, 0,x, x,x")
2109           (match_operand:FMAMODE   2 "nonimmediate_operand" "xm, x,xm,x,m")
2110           (neg:FMAMODE
2111             (match_operand:FMAMODE 3 "nonimmediate_operand" " x,xm,0,xm,x"))))]
2112   "TARGET_FMA || TARGET_FMA4"
2113   "@
2114    vfmsub132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
2115    vfmsub213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
2116    vfmsub231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}
2117    vfmsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}
2118    vfmsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
2119   [(set_attr "isa" "fma,fma,fma,fma4,fma4")
2120    (set_attr "type" "ssemuladd")
2121    (set_attr "mode" "<MODE>")])
2122
2123 (define_insn "*fma_fnmadd_<mode>"
2124   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x,x,x,x")
2125         (fma:FMAMODE
2126           (neg:FMAMODE
2127             (match_operand:FMAMODE 1 "nonimmediate_operand" "%0, 0,x, x,x"))
2128           (match_operand:FMAMODE   2 "nonimmediate_operand" "xm, x,xm,x,m")
2129           (match_operand:FMAMODE   3 "nonimmediate_operand" " x,xm,0,xm,x")))]
2130   "TARGET_FMA || TARGET_FMA4"
2131   "@
2132    vfnmadd132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
2133    vfnmadd213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
2134    vfnmadd231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}
2135    vfnmadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}
2136    vfnmadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
2137   [(set_attr "isa" "fma,fma,fma,fma4,fma4")
2138    (set_attr "type" "ssemuladd")
2139    (set_attr "mode" "<MODE>")])
2140
2141 (define_insn "*fma_fnmsub_<mode>"
2142   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x,x,x,x")
2143         (fma:FMAMODE
2144           (neg:FMAMODE
2145             (match_operand:FMAMODE 1 "nonimmediate_operand" "%0, 0,x, x,x"))
2146           (match_operand:FMAMODE   2 "nonimmediate_operand" "xm, x,xm,x,m")
2147           (neg:FMAMODE
2148             (match_operand:FMAMODE 3 "nonimmediate_operand" " x,xm,0,xm,x"))))]
2149   "TARGET_FMA || TARGET_FMA4"
2150   "@
2151    vfnmsub132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
2152    vfnmsub213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
2153    vfnmsub231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}
2154    vfnmsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}
2155    vfnmsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
2156   [(set_attr "isa" "fma,fma,fma,fma4,fma4")
2157    (set_attr "type" "ssemuladd")
2158    (set_attr "mode" "<MODE>")])
2159
2160 ;; FMA parallel floating point multiply addsub and subadd operations.
2161
2162 ;; It would be possible to represent these without the UNSPEC as
2163 ;;
2164 ;; (vec_merge
2165 ;;   (fma op1 op2 op3)
2166 ;;   (fma op1 op2 (neg op3))
2167 ;;   (merge-const))
2168 ;;
2169 ;; But this doesn't seem useful in practice.
2170
2171 (define_expand "fmaddsub_<mode>"
2172   [(set (match_operand:VF 0 "register_operand")
2173         (unspec:VF
2174           [(match_operand:VF 1 "nonimmediate_operand")
2175            (match_operand:VF 2 "nonimmediate_operand")
2176            (match_operand:VF 3 "nonimmediate_operand")]
2177           UNSPEC_FMADDSUB))]
2178   "TARGET_FMA || TARGET_FMA4")
2179
2180 (define_insn "*fma_fmaddsub_<mode>"
2181   [(set (match_operand:VF 0 "register_operand" "=x,x,x,x,x")
2182         (unspec:VF
2183           [(match_operand:VF 1 "nonimmediate_operand" "%0, 0,x, x,x")
2184            (match_operand:VF 2 "nonimmediate_operand" "xm, x,xm,x,m")
2185            (match_operand:VF 3 "nonimmediate_operand" " x,xm,0,xm,x")]
2186           UNSPEC_FMADDSUB))]
2187   "TARGET_FMA || TARGET_FMA4"
2188   "@
2189    vfmaddsub132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
2190    vfmaddsub213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
2191    vfmaddsub231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}
2192    vfmaddsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}
2193    vfmaddsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
2194   [(set_attr "isa" "fma,fma,fma,fma4,fma4")
2195    (set_attr "type" "ssemuladd")
2196    (set_attr "mode" "<MODE>")])
2197
2198 (define_insn "*fma_fmsubadd_<mode>"
2199   [(set (match_operand:VF 0 "register_operand" "=x,x,x,x,x")
2200         (unspec:VF
2201           [(match_operand:VF   1 "nonimmediate_operand" "%0, 0,x, x,x")
2202            (match_operand:VF   2 "nonimmediate_operand" "xm, x,xm,x,m")
2203            (neg:VF
2204              (match_operand:VF 3 "nonimmediate_operand" " x,xm,0,xm,x"))]
2205           UNSPEC_FMADDSUB))]
2206   "TARGET_FMA || TARGET_FMA4"
2207   "@
2208    vfmsubadd132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
2209    vfmsubadd213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
2210    vfmsubadd231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}
2211    vfmsubadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}
2212    vfmsubadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
2213   [(set_attr "isa" "fma,fma,fma,fma4,fma4")
2214    (set_attr "type" "ssemuladd")
2215    (set_attr "mode" "<MODE>")])
2216
2217 ;; FMA3 floating point scalar intrinsics. These merge result with
2218 ;; high-order elements from the destination register.
2219
2220 (define_expand "fmai_vmfmadd_<mode>"
2221   [(set (match_operand:VF_128 0 "register_operand")
2222         (vec_merge:VF_128
2223           (fma:VF_128
2224             (match_operand:VF_128 1 "nonimmediate_operand")
2225             (match_operand:VF_128 2 "nonimmediate_operand")
2226             (match_operand:VF_128 3 "nonimmediate_operand"))
2227           (match_dup 1)
2228           (const_int 1)))]
2229   "TARGET_FMA")
2230
2231 (define_insn "*fmai_fmadd_<mode>"
2232   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
2233         (vec_merge:VF_128
2234           (fma:VF_128
2235             (match_operand:VF_128 1 "nonimmediate_operand" " 0, 0")
2236             (match_operand:VF_128 2 "nonimmediate_operand" "xm, x")
2237             (match_operand:VF_128 3 "nonimmediate_operand" " x,xm"))
2238           (match_dup 1)
2239           (const_int 1)))]
2240   "TARGET_FMA"
2241   "@
2242    vfmadd132<ssescalarmodesuffix>\t{%2, %3, %0|%0, %3, %2}
2243    vfmadd213<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}"
2244   [(set_attr "type" "ssemuladd")
2245    (set_attr "mode" "<MODE>")])
2246
2247 (define_insn "*fmai_fmsub_<mode>"
2248   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
2249         (vec_merge:VF_128
2250           (fma:VF_128
2251             (match_operand:VF_128   1 "nonimmediate_operand" " 0, 0")
2252             (match_operand:VF_128   2 "nonimmediate_operand" "xm, x")
2253             (neg:VF_128
2254               (match_operand:VF_128 3 "nonimmediate_operand" " x,xm")))
2255           (match_dup 1)
2256           (const_int 1)))]
2257   "TARGET_FMA"
2258   "@
2259    vfmsub132<ssescalarmodesuffix>\t{%2, %3, %0|%0, %3, %2}
2260    vfmsub213<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}"
2261   [(set_attr "type" "ssemuladd")
2262    (set_attr "mode" "<MODE>")])
2263
2264 (define_insn "*fmai_fnmadd_<mode>"
2265   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
2266         (vec_merge:VF_128
2267           (fma:VF_128
2268             (neg:VF_128
2269               (match_operand:VF_128 2 "nonimmediate_operand" "xm, x"))
2270             (match_operand:VF_128   1 "nonimmediate_operand" " 0, 0")
2271             (match_operand:VF_128   3 "nonimmediate_operand" " x,xm"))
2272           (match_dup 1)
2273           (const_int 1)))]
2274   "TARGET_FMA"
2275   "@
2276    vfnmadd132<ssescalarmodesuffix>\t{%2, %3, %0|%0, %3, %2}
2277    vfnmadd213<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}"
2278   [(set_attr "type" "ssemuladd")
2279    (set_attr "mode" "<MODE>")])
2280
2281 (define_insn "*fmai_fnmsub_<mode>"
2282   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
2283         (vec_merge:VF_128
2284           (fma:VF_128
2285             (neg:VF_128
2286               (match_operand:VF_128 2 "nonimmediate_operand" "xm, x"))
2287             (match_operand:VF_128   1 "nonimmediate_operand" " 0, 0")
2288             (neg:VF_128
2289               (match_operand:VF_128 3 "nonimmediate_operand" " x,xm")))
2290           (match_dup 1)
2291           (const_int 1)))]
2292   "TARGET_FMA"
2293   "@
2294    vfnmsub132<ssescalarmodesuffix>\t{%2, %3, %0|%0, %3, %2}
2295    vfnmsub213<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}"
2296   [(set_attr "type" "ssemuladd")
2297    (set_attr "mode" "<MODE>")])
2298
2299 ;; FMA4 floating point scalar intrinsics.  These write the
2300 ;; entire destination register, with the high-order elements zeroed.
2301
2302 (define_expand "fma4i_vmfmadd_<mode>"
2303   [(set (match_operand:VF_128 0 "register_operand")
2304         (vec_merge:VF_128
2305           (fma:VF_128
2306             (match_operand:VF_128 1 "nonimmediate_operand")
2307             (match_operand:VF_128 2 "nonimmediate_operand")
2308             (match_operand:VF_128 3 "nonimmediate_operand"))
2309           (match_dup 4)
2310           (const_int 1)))]
2311   "TARGET_FMA4"
2312   "operands[4] = CONST0_RTX (<MODE>mode);")
2313
2314 (define_insn "*fma4i_vmfmadd_<mode>"
2315   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
2316         (vec_merge:VF_128
2317           (fma:VF_128
2318             (match_operand:VF_128 1 "nonimmediate_operand" "%x,x")
2319             (match_operand:VF_128 2 "nonimmediate_operand" " x,m")
2320             (match_operand:VF_128 3 "nonimmediate_operand" "xm,x"))
2321           (match_operand:VF_128 4 "const0_operand")
2322           (const_int 1)))]
2323   "TARGET_FMA4"
2324   "vfmadd<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
2325   [(set_attr "type" "ssemuladd")
2326    (set_attr "mode" "<MODE>")])
2327
2328 (define_insn "*fma4i_vmfmsub_<mode>"
2329   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
2330         (vec_merge:VF_128
2331           (fma:VF_128
2332             (match_operand:VF_128 1 "nonimmediate_operand" "%x,x")
2333             (match_operand:VF_128 2 "nonimmediate_operand" " x,m")
2334             (neg:VF_128
2335               (match_operand:VF_128 3 "nonimmediate_operand" "xm,x")))
2336           (match_operand:VF_128 4 "const0_operand")
2337           (const_int 1)))]
2338   "TARGET_FMA4"
2339   "vfmsub<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
2340   [(set_attr "type" "ssemuladd")
2341    (set_attr "mode" "<MODE>")])
2342
2343 (define_insn "*fma4i_vmfnmadd_<mode>"
2344   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
2345         (vec_merge:VF_128
2346           (fma:VF_128
2347             (neg:VF_128
2348               (match_operand:VF_128 1 "nonimmediate_operand" "%x,x"))
2349             (match_operand:VF_128   2 "nonimmediate_operand" " x,m")
2350             (match_operand:VF_128   3 "nonimmediate_operand" "xm,x"))
2351           (match_operand:VF_128 4 "const0_operand")
2352           (const_int 1)))]
2353   "TARGET_FMA4"
2354   "vfnmadd<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
2355   [(set_attr "type" "ssemuladd")
2356    (set_attr "mode" "<MODE>")])
2357
2358 (define_insn "*fma4i_vmfnmsub_<mode>"
2359   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
2360         (vec_merge:VF_128
2361           (fma:VF_128
2362             (neg:VF_128
2363               (match_operand:VF_128 1 "nonimmediate_operand" "%x,x"))
2364             (match_operand:VF_128   2 "nonimmediate_operand" " x,m")
2365             (neg:VF_128
2366               (match_operand:VF_128   3 "nonimmediate_operand" "xm,x")))
2367           (match_operand:VF_128 4 "const0_operand")
2368           (const_int 1)))]
2369   "TARGET_FMA4"
2370   "vfnmsub<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
2371   [(set_attr "type" "ssemuladd")
2372    (set_attr "mode" "<MODE>")])
2373
2374 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2375 ;;
2376 ;; Parallel single-precision floating point conversion operations
2377 ;;
2378 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2379
2380 (define_insn "sse_cvtpi2ps"
2381   [(set (match_operand:V4SF 0 "register_operand" "=x")
2382         (vec_merge:V4SF
2383           (vec_duplicate:V4SF
2384             (float:V2SF (match_operand:V2SI 2 "nonimmediate_operand" "ym")))
2385           (match_operand:V4SF 1 "register_operand" "0")
2386           (const_int 3)))]
2387   "TARGET_SSE"
2388   "cvtpi2ps\t{%2, %0|%0, %2}"
2389   [(set_attr "type" "ssecvt")
2390    (set_attr "mode" "V4SF")])
2391
2392 (define_insn "sse_cvtps2pi"
2393   [(set (match_operand:V2SI 0 "register_operand" "=y")
2394         (vec_select:V2SI
2395           (unspec:V4SI [(match_operand:V4SF 1 "nonimmediate_operand" "xm")]
2396                        UNSPEC_FIX_NOTRUNC)
2397           (parallel [(const_int 0) (const_int 1)])))]
2398   "TARGET_SSE"
2399   "cvtps2pi\t{%1, %0|%0, %1}"
2400   [(set_attr "type" "ssecvt")
2401    (set_attr "unit" "mmx")
2402    (set_attr "mode" "DI")])
2403
2404 (define_insn "sse_cvttps2pi"
2405   [(set (match_operand:V2SI 0 "register_operand" "=y")
2406         (vec_select:V2SI
2407           (fix:V4SI (match_operand:V4SF 1 "nonimmediate_operand" "xm"))
2408           (parallel [(const_int 0) (const_int 1)])))]
2409   "TARGET_SSE"
2410   "cvttps2pi\t{%1, %0|%0, %1}"
2411   [(set_attr "type" "ssecvt")
2412    (set_attr "unit" "mmx")
2413    (set_attr "prefix_rep" "0")
2414    (set_attr "mode" "SF")])
2415
2416 (define_insn "sse_cvtsi2ss"
2417   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
2418         (vec_merge:V4SF
2419           (vec_duplicate:V4SF
2420             (float:SF (match_operand:SI 2 "nonimmediate_operand" "r,m,rm")))
2421           (match_operand:V4SF 1 "register_operand" "0,0,x")
2422           (const_int 1)))]
2423   "TARGET_SSE"
2424   "@
2425    cvtsi2ss\t{%2, %0|%0, %2}
2426    cvtsi2ss\t{%2, %0|%0, %2}
2427    vcvtsi2ss\t{%2, %1, %0|%0, %1, %2}"
2428   [(set_attr "isa" "noavx,noavx,avx")
2429    (set_attr "type" "sseicvt")
2430    (set_attr "athlon_decode" "vector,double,*")
2431    (set_attr "amdfam10_decode" "vector,double,*")
2432    (set_attr "bdver1_decode" "double,direct,*")
2433    (set_attr "btver2_decode" "double,double,double")
2434    (set_attr "prefix" "orig,orig,vex")
2435    (set_attr "mode" "SF")])
2436
2437 (define_insn "sse_cvtsi2ssq"
2438   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
2439         (vec_merge:V4SF
2440           (vec_duplicate:V4SF
2441             (float:SF (match_operand:DI 2 "nonimmediate_operand" "r,m,rm")))
2442           (match_operand:V4SF 1 "register_operand" "0,0,x")
2443           (const_int 1)))]
2444   "TARGET_SSE && TARGET_64BIT"
2445   "@
2446    cvtsi2ssq\t{%2, %0|%0, %2}
2447    cvtsi2ssq\t{%2, %0|%0, %2}
2448    vcvtsi2ssq\t{%2, %1, %0|%0, %1, %2}"
2449   [(set_attr "isa" "noavx,noavx,avx")
2450    (set_attr "type" "sseicvt")
2451    (set_attr "athlon_decode" "vector,double,*")
2452    (set_attr "amdfam10_decode" "vector,double,*")
2453    (set_attr "bdver1_decode" "double,direct,*")
2454    (set_attr "btver2_decode" "double,double,double")
2455    (set_attr "length_vex" "*,*,4")
2456    (set_attr "prefix_rex" "1,1,*")
2457    (set_attr "prefix" "orig,orig,vex")
2458    (set_attr "mode" "SF")])
2459
2460 (define_insn "sse_cvtss2si"
2461   [(set (match_operand:SI 0 "register_operand" "=r,r")
2462         (unspec:SI
2463           [(vec_select:SF
2464              (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
2465              (parallel [(const_int 0)]))]
2466           UNSPEC_FIX_NOTRUNC))]
2467   "TARGET_SSE"
2468   "%vcvtss2si\t{%1, %0|%0, %1}"
2469   [(set_attr "type" "sseicvt")
2470    (set_attr "athlon_decode" "double,vector")
2471    (set_attr "bdver1_decode" "double,double")
2472    (set_attr "prefix_rep" "1")
2473    (set_attr "prefix" "maybe_vex")
2474    (set_attr "mode" "SI")])
2475
2476 (define_insn "sse_cvtss2si_2"
2477   [(set (match_operand:SI 0 "register_operand" "=r,r")
2478         (unspec:SI [(match_operand:SF 1 "nonimmediate_operand" "x,m")]
2479                    UNSPEC_FIX_NOTRUNC))]
2480   "TARGET_SSE"
2481   "%vcvtss2si\t{%1, %0|%0, %1}"
2482   [(set_attr "type" "sseicvt")
2483    (set_attr "athlon_decode" "double,vector")
2484    (set_attr "amdfam10_decode" "double,double")
2485    (set_attr "bdver1_decode" "double,double")
2486    (set_attr "prefix_rep" "1")
2487    (set_attr "prefix" "maybe_vex")
2488    (set_attr "mode" "SI")])
2489
2490 (define_insn "sse_cvtss2siq"
2491   [(set (match_operand:DI 0 "register_operand" "=r,r")
2492         (unspec:DI
2493           [(vec_select:SF
2494              (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
2495              (parallel [(const_int 0)]))]
2496           UNSPEC_FIX_NOTRUNC))]
2497   "TARGET_SSE && TARGET_64BIT"
2498   "%vcvtss2si{q}\t{%1, %0|%0, %1}"
2499   [(set_attr "type" "sseicvt")
2500    (set_attr "athlon_decode" "double,vector")
2501    (set_attr "bdver1_decode" "double,double")
2502    (set_attr "prefix_rep" "1")
2503    (set_attr "prefix" "maybe_vex")
2504    (set_attr "mode" "DI")])
2505
2506 (define_insn "sse_cvtss2siq_2"
2507   [(set (match_operand:DI 0 "register_operand" "=r,r")
2508         (unspec:DI [(match_operand:SF 1 "nonimmediate_operand" "x,m")]
2509                    UNSPEC_FIX_NOTRUNC))]
2510   "TARGET_SSE && TARGET_64BIT"
2511   "%vcvtss2si{q}\t{%1, %0|%0, %1}"
2512   [(set_attr "type" "sseicvt")
2513    (set_attr "athlon_decode" "double,vector")
2514    (set_attr "amdfam10_decode" "double,double")
2515    (set_attr "bdver1_decode" "double,double")
2516    (set_attr "prefix_rep" "1")
2517    (set_attr "prefix" "maybe_vex")
2518    (set_attr "mode" "DI")])
2519
2520 (define_insn "sse_cvttss2si"
2521   [(set (match_operand:SI 0 "register_operand" "=r,r")
2522         (fix:SI
2523           (vec_select:SF
2524             (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
2525             (parallel [(const_int 0)]))))]
2526   "TARGET_SSE"
2527   "%vcvttss2si\t{%1, %0|%0, %1}"
2528   [(set_attr "type" "sseicvt")
2529    (set_attr "athlon_decode" "double,vector")
2530    (set_attr "amdfam10_decode" "double,double")
2531    (set_attr "bdver1_decode" "double,double")
2532    (set_attr "prefix_rep" "1")
2533    (set_attr "prefix" "maybe_vex")
2534    (set_attr "mode" "SI")])
2535
2536 (define_insn "sse_cvttss2siq"
2537   [(set (match_operand:DI 0 "register_operand" "=r,r")
2538         (fix:DI
2539           (vec_select:SF
2540             (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
2541             (parallel [(const_int 0)]))))]
2542   "TARGET_SSE && TARGET_64BIT"
2543   "%vcvttss2si{q}\t{%1, %0|%0, %1}"
2544   [(set_attr "type" "sseicvt")
2545    (set_attr "athlon_decode" "double,vector")
2546    (set_attr "amdfam10_decode" "double,double")
2547    (set_attr "bdver1_decode" "double,double")
2548    (set_attr "prefix_rep" "1")
2549    (set_attr "prefix" "maybe_vex")
2550    (set_attr "mode" "DI")])
2551
2552 (define_insn "float<sseintvecmodelower><mode>2"
2553   [(set (match_operand:VF1 0 "register_operand" "=x")
2554         (float:VF1
2555           (match_operand:<sseintvecmode> 1 "nonimmediate_operand" "xm")))]
2556   "TARGET_SSE2"
2557   "%vcvtdq2ps\t{%1, %0|%0, %1}"
2558   [(set_attr "type" "ssecvt")
2559    (set_attr "prefix" "maybe_vex")
2560    (set_attr "mode" "<sseinsnmode>")])
2561
2562 (define_expand "floatuns<sseintvecmodelower><mode>2"
2563   [(match_operand:VF1 0 "register_operand")
2564    (match_operand:<sseintvecmode> 1 "register_operand")]
2565   "TARGET_SSE2 && (<MODE>mode == V4SFmode || TARGET_AVX2)"
2566 {
2567   ix86_expand_vector_convert_uns_vsivsf (operands[0], operands[1]);
2568   DONE;
2569 })
2570
2571 (define_insn "avx_cvtps2dq256"
2572   [(set (match_operand:V8SI 0 "register_operand" "=x")
2573         (unspec:V8SI [(match_operand:V8SF 1 "nonimmediate_operand" "xm")]
2574                      UNSPEC_FIX_NOTRUNC))]
2575   "TARGET_AVX"
2576   "vcvtps2dq\t{%1, %0|%0, %1}"
2577   [(set_attr "type" "ssecvt")
2578    (set_attr "prefix" "vex")
2579    (set_attr "mode" "OI")])
2580
2581 (define_insn "sse2_cvtps2dq"
2582   [(set (match_operand:V4SI 0 "register_operand" "=x")
2583         (unspec:V4SI [(match_operand:V4SF 1 "nonimmediate_operand" "xm")]
2584                      UNSPEC_FIX_NOTRUNC))]
2585   "TARGET_SSE2"
2586   "%vcvtps2dq\t{%1, %0|%0, %1}"
2587   [(set_attr "type" "ssecvt")
2588    (set (attr "prefix_data16")
2589      (if_then_else
2590        (match_test "TARGET_AVX")
2591      (const_string "*")
2592      (const_string "1")))
2593    (set_attr "prefix" "maybe_vex")
2594    (set_attr "mode" "TI")])
2595
2596 (define_insn "fix_truncv8sfv8si2"
2597   [(set (match_operand:V8SI 0 "register_operand" "=x")
2598         (fix:V8SI (match_operand:V8SF 1 "nonimmediate_operand" "xm")))]
2599   "TARGET_AVX"
2600   "vcvttps2dq\t{%1, %0|%0, %1}"
2601   [(set_attr "type" "ssecvt")
2602    (set_attr "prefix" "vex")
2603    (set_attr "mode" "OI")])
2604
2605 (define_insn "fix_truncv4sfv4si2"
2606   [(set (match_operand:V4SI 0 "register_operand" "=x")
2607         (fix:V4SI (match_operand:V4SF 1 "nonimmediate_operand" "xm")))]
2608   "TARGET_SSE2"
2609   "%vcvttps2dq\t{%1, %0|%0, %1}"
2610   [(set_attr "type" "ssecvt")
2611    (set (attr "prefix_rep")
2612      (if_then_else
2613        (match_test "TARGET_AVX")
2614      (const_string "*")
2615      (const_string "1")))
2616    (set (attr "prefix_data16")
2617      (if_then_else
2618        (match_test "TARGET_AVX")
2619      (const_string "*")
2620      (const_string "0")))
2621    (set_attr "prefix_data16" "0")
2622    (set_attr "prefix" "maybe_vex")
2623    (set_attr "mode" "TI")])
2624
2625 (define_expand "fixuns_trunc<mode><sseintvecmodelower>2"
2626   [(match_operand:<sseintvecmode> 0 "register_operand")
2627    (match_operand:VF1 1 "register_operand")]
2628   "TARGET_SSE2"
2629 {
2630   rtx tmp[3];
2631   tmp[0] = ix86_expand_adjust_ufix_to_sfix_si (operands[1], &tmp[2]);
2632   tmp[1] = gen_reg_rtx (<sseintvecmode>mode);
2633   emit_insn (gen_fix_trunc<mode><sseintvecmodelower>2 (tmp[1], tmp[0]));
2634   emit_insn (gen_xor<sseintvecmodelower>3 (operands[0], tmp[1], tmp[2]));
2635   DONE;
2636 })
2637
2638 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2639 ;;
2640 ;; Parallel double-precision floating point conversion operations
2641 ;;
2642 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2643
2644 (define_insn "sse2_cvtpi2pd"
2645   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
2646         (float:V2DF (match_operand:V2SI 1 "nonimmediate_operand" "y,m")))]
2647   "TARGET_SSE2"
2648   "cvtpi2pd\t{%1, %0|%0, %1}"
2649   [(set_attr "type" "ssecvt")
2650    (set_attr "unit" "mmx,*")
2651    (set_attr "prefix_data16" "1,*")
2652    (set_attr "mode" "V2DF")])
2653
2654 (define_insn "sse2_cvtpd2pi"
2655   [(set (match_operand:V2SI 0 "register_operand" "=y")
2656         (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand" "xm")]
2657                      UNSPEC_FIX_NOTRUNC))]
2658   "TARGET_SSE2"
2659   "cvtpd2pi\t{%1, %0|%0, %1}"
2660   [(set_attr "type" "ssecvt")
2661    (set_attr "unit" "mmx")
2662    (set_attr "bdver1_decode" "double")
2663    (set_attr "btver2_decode" "direct")
2664    (set_attr "prefix_data16" "1")
2665    (set_attr "mode" "DI")])
2666
2667 (define_insn "sse2_cvttpd2pi"
2668   [(set (match_operand:V2SI 0 "register_operand" "=y")
2669         (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" "xm")))]
2670   "TARGET_SSE2"
2671   "cvttpd2pi\t{%1, %0|%0, %1}"
2672   [(set_attr "type" "ssecvt")
2673    (set_attr "unit" "mmx")
2674    (set_attr "bdver1_decode" "double")
2675    (set_attr "prefix_data16" "1")
2676    (set_attr "mode" "TI")])
2677
2678 (define_insn "sse2_cvtsi2sd"
2679   [(set (match_operand:V2DF 0 "register_operand" "=x,x,x")
2680         (vec_merge:V2DF
2681           (vec_duplicate:V2DF
2682             (float:DF (match_operand:SI 2 "nonimmediate_operand" "r,m,rm")))
2683           (match_operand:V2DF 1 "register_operand" "0,0,x")
2684           (const_int 1)))]
2685   "TARGET_SSE2"
2686   "@
2687    cvtsi2sd\t{%2, %0|%0, %2}
2688    cvtsi2sd\t{%2, %0|%0, %2}
2689    vcvtsi2sd\t{%2, %1, %0|%0, %1, %2}"
2690   [(set_attr "isa" "noavx,noavx,avx")
2691    (set_attr "type" "sseicvt")
2692    (set_attr "athlon_decode" "double,direct,*")
2693    (set_attr "amdfam10_decode" "vector,double,*")
2694    (set_attr "bdver1_decode" "double,direct,*")
2695    (set_attr "btver2_decode" "double,double,double")
2696    (set_attr "prefix" "orig,orig,vex")
2697    (set_attr "mode" "DF")])
2698
2699 (define_insn "sse2_cvtsi2sdq"
2700   [(set (match_operand:V2DF 0 "register_operand" "=x,x,x")
2701         (vec_merge:V2DF
2702           (vec_duplicate:V2DF
2703             (float:DF (match_operand:DI 2 "nonimmediate_operand" "r,m,rm")))
2704           (match_operand:V2DF 1 "register_operand" "0,0,x")
2705           (const_int 1)))]
2706   "TARGET_SSE2 && TARGET_64BIT"
2707   "@
2708    cvtsi2sdq\t{%2, %0|%0, %2}
2709    cvtsi2sdq\t{%2, %0|%0, %2}
2710    vcvtsi2sdq\t{%2, %1, %0|%0, %1, %2}"
2711   [(set_attr "isa" "noavx,noavx,avx")
2712    (set_attr "type" "sseicvt")
2713    (set_attr "athlon_decode" "double,direct,*")
2714    (set_attr "amdfam10_decode" "vector,double,*")
2715    (set_attr "bdver1_decode" "double,direct,*")
2716    (set_attr "length_vex" "*,*,4")
2717    (set_attr "prefix_rex" "1,1,*")
2718    (set_attr "prefix" "orig,orig,vex")
2719    (set_attr "mode" "DF")])
2720
2721 (define_insn "sse2_cvtsd2si"
2722   [(set (match_operand:SI 0 "register_operand" "=r,r")
2723         (unspec:SI
2724           [(vec_select:DF
2725              (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2726              (parallel [(const_int 0)]))]
2727           UNSPEC_FIX_NOTRUNC))]
2728   "TARGET_SSE2"
2729   "%vcvtsd2si\t{%1, %0|%0, %1}"
2730   [(set_attr "type" "sseicvt")
2731    (set_attr "athlon_decode" "double,vector")
2732    (set_attr "bdver1_decode" "double,double")
2733    (set_attr "btver2_decode" "double,double")
2734    (set_attr "prefix_rep" "1")
2735    (set_attr "prefix" "maybe_vex")
2736    (set_attr "mode" "SI")])
2737
2738 (define_insn "sse2_cvtsd2si_2"
2739   [(set (match_operand:SI 0 "register_operand" "=r,r")
2740         (unspec:SI [(match_operand:DF 1 "nonimmediate_operand" "x,m")]
2741                    UNSPEC_FIX_NOTRUNC))]
2742   "TARGET_SSE2"
2743   "%vcvtsd2si\t{%1, %0|%0, %1}"
2744   [(set_attr "type" "sseicvt")
2745    (set_attr "athlon_decode" "double,vector")
2746    (set_attr "amdfam10_decode" "double,double")
2747    (set_attr "bdver1_decode" "double,double")
2748    (set_attr "prefix_rep" "1")
2749    (set_attr "prefix" "maybe_vex")
2750    (set_attr "mode" "SI")])
2751
2752 (define_insn "sse2_cvtsd2siq"
2753   [(set (match_operand:DI 0 "register_operand" "=r,r")
2754         (unspec:DI
2755           [(vec_select:DF
2756              (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2757              (parallel [(const_int 0)]))]
2758           UNSPEC_FIX_NOTRUNC))]
2759   "TARGET_SSE2 && TARGET_64BIT"
2760   "%vcvtsd2si{q}\t{%1, %0|%0, %1}"
2761   [(set_attr "type" "sseicvt")
2762    (set_attr "athlon_decode" "double,vector")
2763    (set_attr "bdver1_decode" "double,double")
2764    (set_attr "prefix_rep" "1")
2765    (set_attr "prefix" "maybe_vex")
2766    (set_attr "mode" "DI")])
2767
2768 (define_insn "sse2_cvtsd2siq_2"
2769   [(set (match_operand:DI 0 "register_operand" "=r,r")
2770         (unspec:DI [(match_operand:DF 1 "nonimmediate_operand" "x,m")]
2771                    UNSPEC_FIX_NOTRUNC))]
2772   "TARGET_SSE2 && TARGET_64BIT"
2773   "%vcvtsd2si{q}\t{%1, %0|%0, %1}"
2774   [(set_attr "type" "sseicvt")
2775    (set_attr "athlon_decode" "double,vector")
2776    (set_attr "amdfam10_decode" "double,double")
2777    (set_attr "bdver1_decode" "double,double")
2778    (set_attr "prefix_rep" "1")
2779    (set_attr "prefix" "maybe_vex")
2780    (set_attr "mode" "DI")])
2781
2782 (define_insn "sse2_cvttsd2si"
2783   [(set (match_operand:SI 0 "register_operand" "=r,r")
2784         (fix:SI
2785           (vec_select:DF
2786             (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2787             (parallel [(const_int 0)]))))]
2788   "TARGET_SSE2"
2789   "%vcvttsd2si\t{%1, %0|%0, %1}"
2790   [(set_attr "type" "sseicvt")
2791    (set_attr "athlon_decode" "double,vector")
2792    (set_attr "amdfam10_decode" "double,double")
2793    (set_attr "bdver1_decode" "double,double")
2794    (set_attr "btver2_decode" "double,double")
2795    (set_attr "prefix_rep" "1")
2796    (set_attr "prefix" "maybe_vex")
2797    (set_attr "mode" "SI")])
2798
2799 (define_insn "sse2_cvttsd2siq"
2800   [(set (match_operand:DI 0 "register_operand" "=r,r")
2801         (fix:DI
2802           (vec_select:DF
2803             (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2804             (parallel [(const_int 0)]))))]
2805   "TARGET_SSE2 && TARGET_64BIT"
2806   "%vcvttsd2si{q}\t{%1, %0|%0, %1}"
2807   [(set_attr "type" "sseicvt")
2808    (set_attr "athlon_decode" "double,vector")
2809    (set_attr "amdfam10_decode" "double,double")
2810    (set_attr "bdver1_decode" "double,double")
2811    (set_attr "prefix_rep" "1")
2812    (set_attr "prefix" "maybe_vex")
2813    (set_attr "mode" "DI")])
2814
2815 (define_insn "floatv4siv4df2"
2816   [(set (match_operand:V4DF 0 "register_operand" "=x")
2817         (float:V4DF (match_operand:V4SI 1 "nonimmediate_operand" "xm")))]
2818   "TARGET_AVX"
2819   "vcvtdq2pd\t{%1, %0|%0, %1}"
2820   [(set_attr "type" "ssecvt")
2821    (set_attr "prefix" "vex")
2822    (set_attr "mode" "V4DF")])
2823
2824 (define_insn "avx_cvtdq2pd256_2"
2825   [(set (match_operand:V4DF 0 "register_operand" "=x")
2826         (float:V4DF
2827           (vec_select:V4SI
2828             (match_operand:V8SI 1 "nonimmediate_operand" "xm")
2829             (parallel [(const_int 0) (const_int 1)
2830                        (const_int 2) (const_int 3)]))))]
2831   "TARGET_AVX"
2832   "vcvtdq2pd\t{%x1, %0|%0, %x1}"
2833   [(set_attr "type" "ssecvt")
2834    (set_attr "prefix" "vex")
2835    (set_attr "mode" "V4DF")])
2836
2837 (define_insn "sse2_cvtdq2pd"
2838   [(set (match_operand:V2DF 0 "register_operand" "=x")
2839         (float:V2DF
2840           (vec_select:V2SI
2841             (match_operand:V4SI 1 "nonimmediate_operand" "xm")
2842             (parallel [(const_int 0) (const_int 1)]))))]
2843   "TARGET_SSE2"
2844   "%vcvtdq2pd\t{%1, %0|%0, %q1}"
2845   [(set_attr "type" "ssecvt")
2846    (set_attr "prefix" "maybe_vex")
2847    (set_attr "mode" "V2DF")])
2848
2849 (define_insn "avx_cvtpd2dq256"
2850   [(set (match_operand:V4SI 0 "register_operand" "=x")
2851         (unspec:V4SI [(match_operand:V4DF 1 "nonimmediate_operand" "xm")]
2852                      UNSPEC_FIX_NOTRUNC))]
2853   "TARGET_AVX"
2854   "vcvtpd2dq{y}\t{%1, %0|%0, %1}"
2855   [(set_attr "type" "ssecvt")
2856    (set_attr "prefix" "vex")
2857    (set_attr "mode" "OI")])
2858
2859 (define_expand "avx_cvtpd2dq256_2"
2860   [(set (match_operand:V8SI 0 "register_operand")
2861         (vec_concat:V8SI
2862           (unspec:V4SI [(match_operand:V4DF 1 "nonimmediate_operand")]
2863                        UNSPEC_FIX_NOTRUNC)
2864           (match_dup 2)))]
2865   "TARGET_AVX"
2866   "operands[2] = CONST0_RTX (V4SImode);")
2867
2868 (define_insn "*avx_cvtpd2dq256_2"
2869   [(set (match_operand:V8SI 0 "register_operand" "=x")
2870         (vec_concat:V8SI
2871           (unspec:V4SI [(match_operand:V4DF 1 "nonimmediate_operand" "xm")]
2872                        UNSPEC_FIX_NOTRUNC)
2873           (match_operand:V4SI 2 "const0_operand")))]
2874   "TARGET_AVX"
2875   "vcvtpd2dq{y}\t{%1, %x0|%x0, %1}"
2876   [(set_attr "type" "ssecvt")
2877    (set_attr "prefix" "vex")
2878    (set_attr "btver2_decode" "vector")
2879    (set_attr "mode" "OI")])
2880
2881 (define_expand "sse2_cvtpd2dq"
2882   [(set (match_operand:V4SI 0 "register_operand")
2883         (vec_concat:V4SI
2884           (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand")]
2885                        UNSPEC_FIX_NOTRUNC)
2886           (match_dup 2)))]
2887   "TARGET_SSE2"
2888   "operands[2] = CONST0_RTX (V2SImode);")
2889
2890 (define_insn "*sse2_cvtpd2dq"
2891   [(set (match_operand:V4SI 0 "register_operand" "=x")
2892         (vec_concat:V4SI
2893           (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand" "xm")]
2894                        UNSPEC_FIX_NOTRUNC)
2895           (match_operand:V2SI 2 "const0_operand")))]
2896   "TARGET_SSE2"
2897 {
2898   if (TARGET_AVX)
2899     return "vcvtpd2dq{x}\t{%1, %0|%0, %1}";
2900   else
2901     return "cvtpd2dq\t{%1, %0|%0, %1}";
2902 }
2903   [(set_attr "type" "ssecvt")
2904    (set_attr "prefix_rep" "1")
2905    (set_attr "prefix_data16" "0")
2906    (set_attr "prefix" "maybe_vex")
2907    (set_attr "mode" "TI")
2908    (set_attr "amdfam10_decode" "double")
2909    (set_attr "athlon_decode" "vector")
2910    (set_attr "bdver1_decode" "double")])
2911
2912 (define_insn "fix_truncv4dfv4si2"
2913   [(set (match_operand:V4SI 0 "register_operand" "=x")
2914         (fix:V4SI (match_operand:V4DF 1 "nonimmediate_operand" "xm")))]
2915   "TARGET_AVX"
2916   "vcvttpd2dq{y}\t{%1, %0|%0, %1}"
2917   [(set_attr "type" "ssecvt")
2918    (set_attr "prefix" "vex")
2919    (set_attr "mode" "OI")])
2920
2921 (define_expand "avx_cvttpd2dq256_2"
2922   [(set (match_operand:V8SI 0 "register_operand")
2923         (vec_concat:V8SI
2924           (fix:V4SI (match_operand:V4DF 1 "nonimmediate_operand"))
2925           (match_dup 2)))]
2926   "TARGET_AVX"
2927   "operands[2] = CONST0_RTX (V4SImode);")
2928
2929 (define_insn "*avx_cvttpd2dq256_2"
2930   [(set (match_operand:V8SI 0 "register_operand" "=x")
2931         (vec_concat:V8SI
2932           (fix:V4SI (match_operand:V4DF 1 "nonimmediate_operand" "xm"))
2933           (match_operand:V4SI 2 "const0_operand")))]
2934   "TARGET_AVX"
2935   "vcvttpd2dq{y}\t{%1, %x0|%x0, %1}"
2936   [(set_attr "type" "ssecvt")
2937    (set_attr "prefix" "vex")
2938    (set_attr "btver2_decode" "vector")
2939    (set_attr "mode" "OI")])
2940
2941 (define_expand "sse2_cvttpd2dq"
2942   [(set (match_operand:V4SI 0 "register_operand")
2943         (vec_concat:V4SI
2944           (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand"))
2945           (match_dup 2)))]
2946   "TARGET_SSE2"
2947   "operands[2] = CONST0_RTX (V2SImode);")
2948
2949 (define_insn "*sse2_cvttpd2dq"
2950   [(set (match_operand:V4SI 0 "register_operand" "=x")
2951         (vec_concat:V4SI
2952           (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" "xm"))
2953           (match_operand:V2SI 2 "const0_operand")))]
2954   "TARGET_SSE2"
2955 {
2956   if (TARGET_AVX)
2957     return "vcvttpd2dq{x}\t{%1, %0|%0, %1}";
2958   else
2959     return "cvttpd2dq\t{%1, %0|%0, %1}";
2960 }
2961   [(set_attr "type" "ssecvt")
2962    (set_attr "amdfam10_decode" "double")
2963    (set_attr "athlon_decode" "vector")
2964    (set_attr "bdver1_decode" "double")
2965    (set_attr "prefix" "maybe_vex")
2966    (set_attr "mode" "TI")])
2967
2968 (define_insn "sse2_cvtsd2ss"
2969   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
2970         (vec_merge:V4SF
2971           (vec_duplicate:V4SF
2972             (float_truncate:V2SF
2973               (match_operand:V2DF 2 "nonimmediate_operand" "x,m,xm")))
2974           (match_operand:V4SF 1 "register_operand" "0,0,x")
2975           (const_int 1)))]
2976   "TARGET_SSE2"
2977   "@
2978    cvtsd2ss\t{%2, %0|%0, %2}
2979    cvtsd2ss\t{%2, %0|%0, %2}
2980    vcvtsd2ss\t{%2, %1, %0|%0, %1, %2}"
2981   [(set_attr "isa" "noavx,noavx,avx")
2982    (set_attr "type" "ssecvt")
2983    (set_attr "athlon_decode" "vector,double,*")
2984    (set_attr "amdfam10_decode" "vector,double,*")
2985    (set_attr "bdver1_decode" "direct,direct,*")
2986    (set_attr "btver2_decode" "double,double,double")
2987    (set_attr "prefix" "orig,orig,vex")
2988    (set_attr "mode" "SF")])
2989
2990 (define_insn "sse2_cvtss2sd"
2991   [(set (match_operand:V2DF 0 "register_operand" "=x,x,x")
2992         (vec_merge:V2DF
2993           (float_extend:V2DF
2994             (vec_select:V2SF
2995               (match_operand:V4SF 2 "nonimmediate_operand" "x,m,xm")
2996               (parallel [(const_int 0) (const_int 1)])))
2997           (match_operand:V2DF 1 "register_operand" "0,0,x")
2998           (const_int 1)))]
2999   "TARGET_SSE2"
3000   "@
3001    cvtss2sd\t{%2, %0|%0, %2}
3002    cvtss2sd\t{%2, %0|%0, %2}
3003    vcvtss2sd\t{%2, %1, %0|%0, %1, %2}"
3004   [(set_attr "isa" "noavx,noavx,avx")
3005    (set_attr "type" "ssecvt")
3006    (set_attr "amdfam10_decode" "vector,double,*")
3007    (set_attr "athlon_decode" "direct,direct,*")
3008    (set_attr "bdver1_decode" "direct,direct,*")
3009    (set_attr "btver2_decode" "double,double,double")
3010    (set_attr "prefix" "orig,orig,vex")
3011    (set_attr "mode" "DF")])
3012
3013 (define_insn "avx_cvtpd2ps256"
3014   [(set (match_operand:V4SF 0 "register_operand" "=x")
3015         (float_truncate:V4SF
3016           (match_operand:V4DF 1 "nonimmediate_operand" "xm")))]
3017   "TARGET_AVX"
3018   "vcvtpd2ps{y}\t{%1, %0|%0, %1}"
3019   [(set_attr "type" "ssecvt")
3020    (set_attr "prefix" "vex")
3021    (set_attr "btver2_decode" "vector")
3022    (set_attr "mode" "V4SF")])
3023
3024 (define_expand "sse2_cvtpd2ps"
3025   [(set (match_operand:V4SF 0 "register_operand")
3026         (vec_concat:V4SF
3027           (float_truncate:V2SF
3028             (match_operand:V2DF 1 "nonimmediate_operand"))
3029           (match_dup 2)))]
3030   "TARGET_SSE2"
3031   "operands[2] = CONST0_RTX (V2SFmode);")
3032
3033 (define_insn "*sse2_cvtpd2ps"
3034   [(set (match_operand:V4SF 0 "register_operand" "=x")
3035         (vec_concat:V4SF
3036           (float_truncate:V2SF
3037             (match_operand:V2DF 1 "nonimmediate_operand" "xm"))
3038           (match_operand:V2SF 2 "const0_operand")))]
3039   "TARGET_SSE2"
3040 {
3041   if (TARGET_AVX)
3042     return "vcvtpd2ps{x}\t{%1, %0|%0, %1}";
3043   else
3044     return "cvtpd2ps\t{%1, %0|%0, %1}";
3045 }
3046   [(set_attr "type" "ssecvt")
3047    (set_attr "amdfam10_decode" "double")
3048    (set_attr "athlon_decode" "vector")
3049    (set_attr "bdver1_decode" "double")
3050    (set_attr "prefix_data16" "1")
3051    (set_attr "prefix" "maybe_vex")
3052    (set_attr "mode" "V4SF")])
3053
3054 (define_insn "avx_cvtps2pd256"
3055   [(set (match_operand:V4DF 0 "register_operand" "=x")
3056         (float_extend:V4DF
3057           (match_operand:V4SF 1 "nonimmediate_operand" "xm")))]
3058   "TARGET_AVX"
3059   "vcvtps2pd\t{%1, %0|%0, %1}"
3060   [(set_attr "type" "ssecvt")
3061    (set_attr "prefix" "vex")
3062    (set_attr "mode" "V4DF")])
3063
3064 (define_insn "*avx_cvtps2pd256_2"
3065   [(set (match_operand:V4DF 0 "register_operand" "=x")
3066         (float_extend:V4DF
3067           (vec_select:V4SF
3068             (match_operand:V8SF 1 "nonimmediate_operand" "xm")
3069             (parallel [(const_int 0) (const_int 1)
3070                        (const_int 2) (const_int 3)]))))]
3071   "TARGET_AVX"
3072   "vcvtps2pd\t{%x1, %0|%0, %x1}"
3073   [(set_attr "type" "ssecvt")
3074    (set_attr "prefix" "vex")
3075    (set_attr "mode" "V4DF")])
3076
3077 (define_insn "sse2_cvtps2pd"
3078   [(set (match_operand:V2DF 0 "register_operand" "=x")
3079         (float_extend:V2DF
3080           (vec_select:V2SF
3081             (match_operand:V4SF 1 "nonimmediate_operand" "xm")
3082             (parallel [(const_int 0) (const_int 1)]))))]
3083   "TARGET_SSE2"
3084   "%vcvtps2pd\t{%1, %0|%0, %q1}"
3085   [(set_attr "type" "ssecvt")
3086    (set_attr "amdfam10_decode" "direct")
3087    (set_attr "athlon_decode" "double")
3088    (set_attr "bdver1_decode" "double")
3089    (set_attr "prefix_data16" "0")
3090    (set_attr "prefix" "maybe_vex")
3091    (set_attr "mode" "V2DF")])
3092
3093 (define_expand "vec_unpacks_hi_v4sf"
3094   [(set (match_dup 2)
3095    (vec_select:V4SF
3096      (vec_concat:V8SF
3097        (match_dup 2)
3098        (match_operand:V4SF 1 "nonimmediate_operand"))
3099      (parallel [(const_int 6) (const_int 7)
3100                 (const_int 2) (const_int 3)])))
3101   (set (match_operand:V2DF 0 "register_operand")
3102    (float_extend:V2DF
3103      (vec_select:V2SF
3104        (match_dup 2)
3105        (parallel [(const_int 0) (const_int 1)]))))]
3106   "TARGET_SSE2"
3107   "operands[2] = gen_reg_rtx (V4SFmode);")
3108
3109 (define_expand "vec_unpacks_hi_v8sf"
3110   [(set (match_dup 2)
3111         (vec_select:V4SF
3112           (match_operand:V8SF 1 "nonimmediate_operand")
3113           (parallel [(const_int 4) (const_int 5)
3114                      (const_int 6) (const_int 7)])))
3115    (set (match_operand:V4DF 0 "register_operand")
3116         (float_extend:V4DF
3117           (match_dup 2)))]
3118   "TARGET_AVX"
3119   "operands[2] = gen_reg_rtx (V4SFmode);")
3120
3121 (define_expand "vec_unpacks_lo_v4sf"
3122   [(set (match_operand:V2DF 0 "register_operand")
3123         (float_extend:V2DF
3124           (vec_select:V2SF
3125             (match_operand:V4SF 1 "nonimmediate_operand")
3126             (parallel [(const_int 0) (const_int 1)]))))]
3127   "TARGET_SSE2")
3128
3129 (define_expand "vec_unpacks_lo_v8sf"
3130   [(set (match_operand:V4DF 0 "register_operand")
3131         (float_extend:V4DF
3132           (vec_select:V4SF
3133             (match_operand:V8SF 1 "nonimmediate_operand")
3134             (parallel [(const_int 0) (const_int 1)
3135                        (const_int 2) (const_int 3)]))))]
3136   "TARGET_AVX")
3137
3138 (define_mode_attr sseunpackfltmode
3139   [(V8HI "V4SF") (V4SI "V2DF") (V16HI "V8SF") (V8SI "V4DF")])
3140
3141 (define_expand "vec_unpacks_float_hi_<mode>"
3142   [(match_operand:<sseunpackfltmode> 0 "register_operand")
3143    (match_operand:VI2_AVX2 1 "register_operand")]
3144   "TARGET_SSE2"
3145 {
3146   rtx tmp = gen_reg_rtx (<sseunpackmode>mode);
3147
3148   emit_insn (gen_vec_unpacks_hi_<mode> (tmp, operands[1]));
3149   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
3150                           gen_rtx_FLOAT (<sseunpackfltmode>mode, tmp)));
3151   DONE;
3152 })
3153
3154 (define_expand "vec_unpacks_float_lo_<mode>"
3155   [(match_operand:<sseunpackfltmode> 0 "register_operand")
3156    (match_operand:VI2_AVX2 1 "register_operand")]
3157   "TARGET_SSE2"
3158 {
3159   rtx tmp = gen_reg_rtx (<sseunpackmode>mode);
3160
3161   emit_insn (gen_vec_unpacks_lo_<mode> (tmp, operands[1]));
3162   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
3163                           gen_rtx_FLOAT (<sseunpackfltmode>mode, tmp)));
3164   DONE;
3165 })
3166
3167 (define_expand "vec_unpacku_float_hi_<mode>"
3168   [(match_operand:<sseunpackfltmode> 0 "register_operand")
3169    (match_operand:VI2_AVX2 1 "register_operand")]
3170   "TARGET_SSE2"
3171 {
3172   rtx tmp = gen_reg_rtx (<sseunpackmode>mode);
3173
3174   emit_insn (gen_vec_unpacku_hi_<mode> (tmp, operands[1]));
3175   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
3176                           gen_rtx_FLOAT (<sseunpackfltmode>mode, tmp)));
3177   DONE;
3178 })
3179
3180 (define_expand "vec_unpacku_float_lo_<mode>"
3181   [(match_operand:<sseunpackfltmode> 0 "register_operand")
3182    (match_operand:VI2_AVX2 1 "register_operand")]
3183   "TARGET_SSE2"
3184 {
3185   rtx tmp = gen_reg_rtx (<sseunpackmode>mode);
3186
3187   emit_insn (gen_vec_unpacku_lo_<mode> (tmp, operands[1]));
3188   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
3189                           gen_rtx_FLOAT (<sseunpackfltmode>mode, tmp)));
3190   DONE;
3191 })
3192
3193 (define_expand "vec_unpacks_float_hi_v4si"
3194   [(set (match_dup 2)
3195         (vec_select:V4SI
3196           (match_operand:V4SI 1 "nonimmediate_operand")
3197           (parallel [(const_int 2) (const_int 3)
3198                      (const_int 2) (const_int 3)])))
3199    (set (match_operand:V2DF 0 "register_operand")
3200         (float:V2DF
3201           (vec_select:V2SI
3202           (match_dup 2)
3203             (parallel [(const_int 0) (const_int 1)]))))]
3204   "TARGET_SSE2"
3205   "operands[2] = gen_reg_rtx (V4SImode);")
3206
3207 (define_expand "vec_unpacks_float_lo_v4si"
3208   [(set (match_operand:V2DF 0 "register_operand")
3209         (float:V2DF
3210           (vec_select:V2SI
3211             (match_operand:V4SI 1 "nonimmediate_operand")
3212             (parallel [(const_int 0) (const_int 1)]))))]
3213   "TARGET_SSE2")
3214
3215 (define_expand "vec_unpacks_float_hi_v8si"
3216   [(set (match_dup 2)
3217         (vec_select:V4SI
3218           (match_operand:V8SI 1 "nonimmediate_operand")
3219           (parallel [(const_int 4) (const_int 5)
3220                      (const_int 6) (const_int 7)])))
3221    (set (match_operand:V4DF 0 "register_operand")
3222         (float:V4DF
3223           (match_dup 2)))]
3224   "TARGET_AVX"
3225   "operands[2] = gen_reg_rtx (V4SImode);")
3226
3227 (define_expand "vec_unpacks_float_lo_v8si"
3228   [(set (match_operand:V4DF 0 "register_operand")
3229         (float:V4DF
3230           (vec_select:V4SI
3231             (match_operand:V8SI 1 "nonimmediate_operand")
3232             (parallel [(const_int 0) (const_int 1)
3233                        (const_int 2) (const_int 3)]))))]
3234   "TARGET_AVX")
3235
3236 (define_expand "vec_unpacku_float_hi_v4si"
3237   [(set (match_dup 5)
3238         (vec_select:V4SI
3239           (match_operand:V4SI 1 "nonimmediate_operand")
3240           (parallel [(const_int 2) (const_int 3)
3241                      (const_int 2) (const_int 3)])))
3242    (set (match_dup 6)
3243         (float:V2DF
3244           (vec_select:V2SI
3245           (match_dup 5)
3246             (parallel [(const_int 0) (const_int 1)]))))
3247    (set (match_dup 7)
3248         (lt:V2DF (match_dup 6) (match_dup 3)))
3249    (set (match_dup 8)
3250         (and:V2DF (match_dup 7) (match_dup 4)))
3251    (set (match_operand:V2DF 0 "register_operand")
3252         (plus:V2DF (match_dup 6) (match_dup 8)))]
3253   "TARGET_SSE2"
3254 {
3255   REAL_VALUE_TYPE TWO32r;
3256   rtx x;
3257   int i;
3258
3259   real_ldexp (&TWO32r, &dconst1, 32);
3260   x = const_double_from_real_value (TWO32r, DFmode);
3261
3262   operands[3] = force_reg (V2DFmode, CONST0_RTX (V2DFmode));
3263   operands[4] = force_reg (V2DFmode,
3264                            ix86_build_const_vector (V2DFmode, 1, x));
3265
3266   operands[5] = gen_reg_rtx (V4SImode);
3267
3268   for (i = 6; i < 9; i++)
3269     operands[i] = gen_reg_rtx (V2DFmode);
3270 })
3271
3272 (define_expand "vec_unpacku_float_lo_v4si"
3273   [(set (match_dup 5)
3274         (float:V2DF
3275           (vec_select:V2SI
3276             (match_operand:V4SI 1 "nonimmediate_operand")
3277             (parallel [(const_int 0) (const_int 1)]))))
3278    (set (match_dup 6)
3279         (lt:V2DF (match_dup 5) (match_dup 3)))
3280    (set (match_dup 7)
3281         (and:V2DF (match_dup 6) (match_dup 4)))
3282    (set (match_operand:V2DF 0 "register_operand")
3283         (plus:V2DF (match_dup 5) (match_dup 7)))]
3284   "TARGET_SSE2"
3285 {
3286   REAL_VALUE_TYPE TWO32r;
3287   rtx x;
3288   int i;
3289
3290   real_ldexp (&TWO32r, &dconst1, 32);
3291   x = const_double_from_real_value (TWO32r, DFmode);
3292
3293   operands[3] = force_reg (V2DFmode, CONST0_RTX (V2DFmode));
3294   operands[4] = force_reg (V2DFmode,
3295                            ix86_build_const_vector (V2DFmode, 1, x));
3296
3297   for (i = 5; i < 8; i++)
3298     operands[i] = gen_reg_rtx (V2DFmode);
3299 })
3300
3301 (define_expand "vec_unpacku_float_hi_v8si"
3302   [(match_operand:V4DF 0 "register_operand")
3303    (match_operand:V8SI 1 "register_operand")]
3304   "TARGET_AVX"
3305 {
3306   REAL_VALUE_TYPE TWO32r;
3307   rtx x, tmp[6];
3308   int i;
3309
3310   real_ldexp (&TWO32r, &dconst1, 32);
3311   x = const_double_from_real_value (TWO32r, DFmode);
3312
3313   tmp[0] = force_reg (V4DFmode, CONST0_RTX (V4DFmode));
3314   tmp[1] = force_reg (V4DFmode, ix86_build_const_vector (V4DFmode, 1, x));
3315   tmp[5] = gen_reg_rtx (V4SImode);
3316
3317   for (i = 2; i < 5; i++)
3318     tmp[i] = gen_reg_rtx (V4DFmode);
3319   emit_insn (gen_vec_extract_hi_v8si (tmp[5], operands[1]));
3320   emit_insn (gen_floatv4siv4df2 (tmp[2], tmp[5]));
3321   emit_insn (gen_rtx_SET (VOIDmode, tmp[3],
3322                           gen_rtx_LT (V4DFmode, tmp[2], tmp[0])));
3323   emit_insn (gen_andv4df3 (tmp[4], tmp[3], tmp[1]));
3324   emit_insn (gen_addv4df3 (operands[0], tmp[2], tmp[4]));
3325   DONE;
3326 })
3327
3328 (define_expand "vec_unpacku_float_lo_v8si"
3329   [(match_operand:V4DF 0 "register_operand")
3330    (match_operand:V8SI 1 "nonimmediate_operand")]
3331   "TARGET_AVX"
3332 {
3333   REAL_VALUE_TYPE TWO32r;
3334   rtx x, tmp[5];
3335   int i;
3336
3337   real_ldexp (&TWO32r, &dconst1, 32);
3338   x = const_double_from_real_value (TWO32r, DFmode);
3339
3340   tmp[0] = force_reg (V4DFmode, CONST0_RTX (V4DFmode));
3341   tmp[1] = force_reg (V4DFmode, ix86_build_const_vector (V4DFmode, 1, x));
3342
3343   for (i = 2; i < 5; i++)
3344     tmp[i] = gen_reg_rtx (V4DFmode);
3345   emit_insn (gen_avx_cvtdq2pd256_2 (tmp[2], operands[1]));
3346   emit_insn (gen_rtx_SET (VOIDmode, tmp[3],
3347                           gen_rtx_LT (V4DFmode, tmp[2], tmp[0])));
3348   emit_insn (gen_andv4df3 (tmp[4], tmp[3], tmp[1]));
3349   emit_insn (gen_addv4df3 (operands[0], tmp[2], tmp[4]));
3350   DONE;
3351 })
3352
3353 (define_expand "vec_pack_trunc_v4df"
3354   [(set (match_dup 3)
3355         (float_truncate:V4SF
3356           (match_operand:V4DF 1 "nonimmediate_operand")))
3357    (set (match_dup 4)
3358         (float_truncate:V4SF
3359           (match_operand:V4DF 2 "nonimmediate_operand")))
3360    (set (match_operand:V8SF 0 "register_operand")
3361         (vec_concat:V8SF
3362           (match_dup 3)
3363           (match_dup 4)))]
3364   "TARGET_AVX"
3365 {
3366   operands[3] = gen_reg_rtx (V4SFmode);
3367   operands[4] = gen_reg_rtx (V4SFmode);
3368 })
3369
3370 (define_expand "vec_pack_trunc_v2df"
3371   [(match_operand:V4SF 0 "register_operand")
3372    (match_operand:V2DF 1 "nonimmediate_operand")
3373    (match_operand:V2DF 2 "nonimmediate_operand")]
3374   "TARGET_SSE2"
3375 {
3376   rtx tmp0, tmp1;
3377
3378   if (TARGET_AVX && !TARGET_PREFER_AVX128)
3379     {
3380       tmp0 = gen_reg_rtx (V4DFmode);
3381       tmp1 = force_reg (V2DFmode, operands[1]);
3382
3383       emit_insn (gen_avx_vec_concatv4df (tmp0, tmp1, operands[2]));
3384       emit_insn (gen_avx_cvtpd2ps256 (operands[0], tmp0));
3385     }
3386   else
3387     {
3388       tmp0 = gen_reg_rtx (V4SFmode);
3389       tmp1 = gen_reg_rtx (V4SFmode);
3390
3391       emit_insn (gen_sse2_cvtpd2ps (tmp0, operands[1]));
3392       emit_insn (gen_sse2_cvtpd2ps (tmp1, operands[2]));
3393       emit_insn (gen_sse_movlhps (operands[0], tmp0, tmp1));
3394     }
3395   DONE;
3396 })
3397
3398 (define_expand "vec_pack_sfix_trunc_v4df"
3399   [(match_operand:V8SI 0 "register_operand")
3400    (match_operand:V4DF 1 "nonimmediate_operand")
3401    (match_operand:V4DF 2 "nonimmediate_operand")]
3402   "TARGET_AVX"
3403 {
3404   rtx r1, r2;
3405
3406   r1 = gen_reg_rtx (V4SImode);
3407   r2 = gen_reg_rtx (V4SImode);
3408
3409   emit_insn (gen_fix_truncv4dfv4si2 (r1, operands[1]));
3410   emit_insn (gen_fix_truncv4dfv4si2 (r2, operands[2]));
3411   emit_insn (gen_avx_vec_concatv8si (operands[0], r1, r2));
3412   DONE;
3413 })
3414
3415 (define_expand "vec_pack_sfix_trunc_v2df"
3416   [(match_operand:V4SI 0 "register_operand")
3417    (match_operand:V2DF 1 "nonimmediate_operand")
3418    (match_operand:V2DF 2 "nonimmediate_operand")]
3419   "TARGET_SSE2"
3420 {
3421   rtx tmp0, tmp1;
3422
3423   if (TARGET_AVX && !TARGET_PREFER_AVX128)
3424     {
3425       tmp0 = gen_reg_rtx (V4DFmode);
3426       tmp1 = force_reg (V2DFmode, operands[1]);
3427
3428       emit_insn (gen_avx_vec_concatv4df (tmp0, tmp1, operands[2]));
3429       emit_insn (gen_fix_truncv4dfv4si2 (operands[0], tmp0));
3430     }
3431   else
3432     {
3433       tmp0 = gen_reg_rtx (V4SImode);
3434       tmp1 = gen_reg_rtx (V4SImode);
3435
3436       emit_insn (gen_sse2_cvttpd2dq (tmp0, operands[1]));
3437       emit_insn (gen_sse2_cvttpd2dq (tmp1, operands[2]));
3438       emit_insn
3439        (gen_vec_interleave_lowv2di (gen_lowpart (V2DImode, operands[0]),
3440                                     gen_lowpart (V2DImode, tmp0),
3441                                     gen_lowpart (V2DImode, tmp1)));
3442     }
3443   DONE;
3444 })
3445
3446 (define_mode_attr ssepackfltmode
3447   [(V4DF "V8SI") (V2DF "V4SI")])
3448
3449 (define_expand "vec_pack_ufix_trunc_<mode>"
3450   [(match_operand:<ssepackfltmode> 0 "register_operand")
3451    (match_operand:VF2 1 "register_operand")
3452    (match_operand:VF2 2 "register_operand")]
3453   "TARGET_SSE2"
3454 {
3455   rtx tmp[7];
3456   tmp[0] = ix86_expand_adjust_ufix_to_sfix_si (operands[1], &tmp[2]);
3457   tmp[1] = ix86_expand_adjust_ufix_to_sfix_si (operands[2], &tmp[3]);
3458   tmp[4] = gen_reg_rtx (<ssepackfltmode>mode);
3459   emit_insn (gen_vec_pack_sfix_trunc_<mode> (tmp[4], tmp[0], tmp[1]));
3460   if (<ssepackfltmode>mode == V4SImode || TARGET_AVX2)
3461     {
3462       tmp[5] = gen_reg_rtx (<ssepackfltmode>mode);
3463       ix86_expand_vec_extract_even_odd (tmp[5], tmp[2], tmp[3], 0);
3464     }
3465   else
3466     {
3467       tmp[5] = gen_reg_rtx (V8SFmode);
3468       ix86_expand_vec_extract_even_odd (tmp[5], gen_lowpart (V8SFmode, tmp[2]),
3469                                         gen_lowpart (V8SFmode, tmp[3]), 0);
3470       tmp[5] = gen_lowpart (V8SImode, tmp[5]);
3471     }
3472   tmp[6] = expand_simple_binop (<ssepackfltmode>mode, XOR, tmp[4], tmp[5],
3473                                 operands[0], 0, OPTAB_DIRECT);
3474   if (tmp[6] != operands[0])
3475     emit_move_insn (operands[0], tmp[6]);
3476   DONE;
3477 })
3478
3479 (define_expand "vec_pack_sfix_v4df"
3480   [(match_operand:V8SI 0 "register_operand")
3481    (match_operand:V4DF 1 "nonimmediate_operand")
3482    (match_operand:V4DF 2 "nonimmediate_operand")]
3483   "TARGET_AVX"
3484 {
3485   rtx r1, r2;
3486
3487   r1 = gen_reg_rtx (V4SImode);
3488   r2 = gen_reg_rtx (V4SImode);
3489
3490   emit_insn (gen_avx_cvtpd2dq256 (r1, operands[1]));
3491   emit_insn (gen_avx_cvtpd2dq256 (r2, operands[2]));
3492   emit_insn (gen_avx_vec_concatv8si (operands[0], r1, r2));
3493   DONE;
3494 })
3495
3496 (define_expand "vec_pack_sfix_v2df"
3497   [(match_operand:V4SI 0 "register_operand")
3498    (match_operand:V2DF 1 "nonimmediate_operand")
3499    (match_operand:V2DF 2 "nonimmediate_operand")]
3500   "TARGET_SSE2"
3501 {
3502   rtx tmp0, tmp1;
3503
3504   if (TARGET_AVX && !TARGET_PREFER_AVX128)
3505     {
3506       tmp0 = gen_reg_rtx (V4DFmode);
3507       tmp1 = force_reg (V2DFmode, operands[1]);
3508
3509       emit_insn (gen_avx_vec_concatv4df (tmp0, tmp1, operands[2]));
3510       emit_insn (gen_avx_cvtpd2dq256 (operands[0], tmp0));
3511     }
3512   else
3513     {
3514       tmp0 = gen_reg_rtx (V4SImode);
3515       tmp1 = gen_reg_rtx (V4SImode);
3516
3517       emit_insn (gen_sse2_cvtpd2dq (tmp0, operands[1]));
3518       emit_insn (gen_sse2_cvtpd2dq (tmp1, operands[2]));
3519       emit_insn
3520        (gen_vec_interleave_lowv2di (gen_lowpart (V2DImode, operands[0]),
3521                                     gen_lowpart (V2DImode, tmp0),
3522                                     gen_lowpart (V2DImode, tmp1)));
3523     }
3524   DONE;
3525 })
3526
3527 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3528 ;;
3529 ;; Parallel single-precision floating point element swizzling
3530 ;;
3531 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3532
3533 (define_expand "sse_movhlps_exp"
3534   [(set (match_operand:V4SF 0 "nonimmediate_operand")
3535         (vec_select:V4SF
3536           (vec_concat:V8SF
3537             (match_operand:V4SF 1 "nonimmediate_operand")
3538             (match_operand:V4SF 2 "nonimmediate_operand"))
3539           (parallel [(const_int 6)
3540                      (const_int 7)
3541                      (const_int 2)
3542                      (const_int 3)])))]
3543   "TARGET_SSE"
3544 {
3545   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
3546
3547   emit_insn (gen_sse_movhlps (dst, operands[1], operands[2]));
3548
3549   /* Fix up the destination if needed.  */
3550   if (dst != operands[0])
3551     emit_move_insn (operands[0], dst);
3552
3553   DONE;
3554 })
3555
3556 (define_insn "sse_movhlps"
3557   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,m")
3558         (vec_select:V4SF
3559           (vec_concat:V8SF
3560             (match_operand:V4SF 1 "nonimmediate_operand" " 0,x,0,x,0")
3561             (match_operand:V4SF 2 "nonimmediate_operand" " x,x,o,o,x"))
3562           (parallel [(const_int 6)
3563                      (const_int 7)
3564                      (const_int 2)
3565                      (const_int 3)])))]
3566   "TARGET_SSE && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
3567   "@
3568    movhlps\t{%2, %0|%0, %2}
3569    vmovhlps\t{%2, %1, %0|%0, %1, %2}
3570    movlps\t{%H2, %0|%0, %H2}
3571    vmovlps\t{%H2, %1, %0|%0, %1, %H2}
3572    %vmovhps\t{%2, %0|%0, %2}"
3573   [(set_attr "isa" "noavx,avx,noavx,avx,*")
3574    (set_attr "type" "ssemov")
3575    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
3576    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF,V2SF")])
3577
3578 (define_expand "sse_movlhps_exp"
3579   [(set (match_operand:V4SF 0 "nonimmediate_operand")
3580         (vec_select:V4SF
3581           (vec_concat:V8SF
3582             (match_operand:V4SF 1 "nonimmediate_operand")
3583             (match_operand:V4SF 2 "nonimmediate_operand"))
3584           (parallel [(const_int 0)
3585                      (const_int 1)
3586                      (const_int 4)
3587                      (const_int 5)])))]
3588   "TARGET_SSE"
3589 {
3590   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
3591
3592   emit_insn (gen_sse_movlhps (dst, operands[1], operands[2]));
3593
3594   /* Fix up the destination if needed.  */
3595   if (dst != operands[0])
3596     emit_move_insn (operands[0], dst);
3597
3598   DONE;
3599 })
3600
3601 (define_insn "sse_movlhps"
3602   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,o")
3603         (vec_select:V4SF
3604           (vec_concat:V8SF
3605             (match_operand:V4SF 1 "nonimmediate_operand" " 0,x,0,x,0")
3606             (match_operand:V4SF 2 "nonimmediate_operand" " x,x,m,x,x"))
3607           (parallel [(const_int 0)
3608                      (const_int 1)
3609                      (const_int 4)
3610                      (const_int 5)])))]
3611   "TARGET_SSE && ix86_binary_operator_ok (UNKNOWN, V4SFmode, operands)"
3612   "@
3613    movlhps\t{%2, %0|%0, %2}
3614    vmovlhps\t{%2, %1, %0|%0, %1, %2}
3615    movhps\t{%2, %0|%0, %2}
3616    vmovhps\t{%2, %1, %0|%0, %1, %2}
3617    %vmovlps\t{%2, %H0|%H0, %2}"
3618   [(set_attr "isa" "noavx,avx,noavx,avx,*")
3619    (set_attr "type" "ssemov")
3620    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
3621    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF,V2SF")])
3622
3623 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
3624 (define_insn "avx_unpckhps256"
3625   [(set (match_operand:V8SF 0 "register_operand" "=x")
3626         (vec_select:V8SF
3627           (vec_concat:V16SF
3628             (match_operand:V8SF 1 "register_operand" "x")
3629             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3630           (parallel [(const_int 2) (const_int 10)
3631                      (const_int 3) (const_int 11)
3632                      (const_int 6) (const_int 14)
3633                      (const_int 7) (const_int 15)])))]
3634   "TARGET_AVX"
3635   "vunpckhps\t{%2, %1, %0|%0, %1, %2}"
3636   [(set_attr "type" "sselog")
3637    (set_attr "prefix" "vex")
3638    (set_attr "mode" "V8SF")])
3639
3640 (define_expand "vec_interleave_highv8sf"
3641   [(set (match_dup 3)
3642         (vec_select:V8SF
3643           (vec_concat:V16SF
3644             (match_operand:V8SF 1 "register_operand" "x")
3645             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3646           (parallel [(const_int 0) (const_int 8)
3647                      (const_int 1) (const_int 9)
3648                      (const_int 4) (const_int 12)
3649                      (const_int 5) (const_int 13)])))
3650    (set (match_dup 4)
3651         (vec_select:V8SF
3652           (vec_concat:V16SF
3653             (match_dup 1)
3654             (match_dup 2))
3655           (parallel [(const_int 2) (const_int 10)
3656                      (const_int 3) (const_int 11)
3657                      (const_int 6) (const_int 14)
3658                      (const_int 7) (const_int 15)])))
3659    (set (match_operand:V8SF 0 "register_operand")
3660         (vec_select:V8SF
3661           (vec_concat:V16SF
3662             (match_dup 3)
3663             (match_dup 4))
3664           (parallel [(const_int 4) (const_int 5)
3665                      (const_int 6) (const_int 7)
3666                      (const_int 12) (const_int 13)
3667                      (const_int 14) (const_int 15)])))]
3668  "TARGET_AVX"
3669 {
3670   operands[3] = gen_reg_rtx (V8SFmode);
3671   operands[4] = gen_reg_rtx (V8SFmode);
3672 })
3673
3674 (define_insn "vec_interleave_highv4sf"
3675   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
3676         (vec_select:V4SF
3677           (vec_concat:V8SF
3678             (match_operand:V4SF 1 "register_operand" "0,x")
3679             (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm"))
3680           (parallel [(const_int 2) (const_int 6)
3681                      (const_int 3) (const_int 7)])))]
3682   "TARGET_SSE"
3683   "@
3684    unpckhps\t{%2, %0|%0, %2}
3685    vunpckhps\t{%2, %1, %0|%0, %1, %2}"
3686   [(set_attr "isa" "noavx,avx")
3687    (set_attr "type" "sselog")
3688    (set_attr "prefix" "orig,vex")
3689    (set_attr "mode" "V4SF")])
3690
3691 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
3692 (define_insn "avx_unpcklps256"
3693   [(set (match_operand:V8SF 0 "register_operand" "=x")
3694         (vec_select:V8SF
3695           (vec_concat:V16SF
3696             (match_operand:V8SF 1 "register_operand" "x")
3697             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3698           (parallel [(const_int 0) (const_int 8)
3699                      (const_int 1) (const_int 9)
3700                      (const_int 4) (const_int 12)
3701                      (const_int 5) (const_int 13)])))]
3702   "TARGET_AVX"
3703   "vunpcklps\t{%2, %1, %0|%0, %1, %2}"
3704   [(set_attr "type" "sselog")
3705    (set_attr "prefix" "vex")
3706    (set_attr "mode" "V8SF")])
3707
3708 (define_expand "vec_interleave_lowv8sf"
3709   [(set (match_dup 3)
3710         (vec_select:V8SF
3711           (vec_concat:V16SF
3712             (match_operand:V8SF 1 "register_operand" "x")
3713             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3714           (parallel [(const_int 0) (const_int 8)
3715                      (const_int 1) (const_int 9)
3716                      (const_int 4) (const_int 12)
3717                      (const_int 5) (const_int 13)])))
3718    (set (match_dup 4)
3719         (vec_select:V8SF
3720           (vec_concat:V16SF
3721             (match_dup 1)
3722             (match_dup 2))
3723           (parallel [(const_int 2) (const_int 10)
3724                      (const_int 3) (const_int 11)
3725                      (const_int 6) (const_int 14)
3726                      (const_int 7) (const_int 15)])))
3727    (set (match_operand:V8SF 0 "register_operand")
3728         (vec_select:V8SF
3729           (vec_concat:V16SF
3730             (match_dup 3)
3731             (match_dup 4))
3732           (parallel [(const_int 0) (const_int 1)
3733                      (const_int 2) (const_int 3)
3734                      (const_int 8) (const_int 9)
3735                      (const_int 10) (const_int 11)])))]
3736  "TARGET_AVX"
3737 {
3738   operands[3] = gen_reg_rtx (V8SFmode);
3739   operands[4] = gen_reg_rtx (V8SFmode);
3740 })
3741
3742 (define_insn "vec_interleave_lowv4sf"
3743   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
3744         (vec_select:V4SF
3745           (vec_concat:V8SF
3746             (match_operand:V4SF 1 "register_operand" "0,x")
3747             (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm"))
3748           (parallel [(const_int 0) (const_int 4)
3749                      (const_int 1) (const_int 5)])))]
3750   "TARGET_SSE"
3751   "@
3752    unpcklps\t{%2, %0|%0, %2}
3753    vunpcklps\t{%2, %1, %0|%0, %1, %2}"
3754   [(set_attr "isa" "noavx,avx")
3755    (set_attr "type" "sselog")
3756    (set_attr "prefix" "orig,vex")
3757    (set_attr "mode" "V4SF")])
3758
3759 ;; These are modeled with the same vec_concat as the others so that we
3760 ;; capture users of shufps that can use the new instructions
3761 (define_insn "avx_movshdup256"
3762   [(set (match_operand:V8SF 0 "register_operand" "=x")
3763         (vec_select:V8SF
3764           (vec_concat:V16SF
3765             (match_operand:V8SF 1 "nonimmediate_operand" "xm")
3766             (match_dup 1))
3767           (parallel [(const_int 1) (const_int 1)
3768                      (const_int 3) (const_int 3)
3769                      (const_int 5) (const_int 5)
3770                      (const_int 7) (const_int 7)])))]
3771   "TARGET_AVX"
3772   "vmovshdup\t{%1, %0|%0, %1}"
3773   [(set_attr "type" "sse")
3774    (set_attr "prefix" "vex")
3775    (set_attr "mode" "V8SF")])
3776
3777 (define_insn "sse3_movshdup"
3778   [(set (match_operand:V4SF 0 "register_operand" "=x")
3779         (vec_select:V4SF
3780           (vec_concat:V8SF
3781             (match_operand:V4SF 1 "nonimmediate_operand" "xm")
3782             (match_dup 1))
3783           (parallel [(const_int 1)
3784                      (const_int 1)
3785                      (const_int 7)
3786                      (const_int 7)])))]
3787   "TARGET_SSE3"
3788   "%vmovshdup\t{%1, %0|%0, %1}"
3789   [(set_attr "type" "sse")
3790    (set_attr "prefix_rep" "1")
3791    (set_attr "prefix" "maybe_vex")
3792    (set_attr "mode" "V4SF")])
3793
3794 (define_insn "avx_movsldup256"
3795   [(set (match_operand:V8SF 0 "register_operand" "=x")
3796         (vec_select:V8SF
3797           (vec_concat:V16SF
3798             (match_operand:V8SF 1 "nonimmediate_operand" "xm")
3799             (match_dup 1))
3800           (parallel [(const_int 0) (const_int 0)
3801                      (const_int 2) (const_int 2)
3802                      (const_int 4) (const_int 4)
3803                      (const_int 6) (const_int 6)])))]
3804   "TARGET_AVX"
3805   "vmovsldup\t{%1, %0|%0, %1}"
3806   [(set_attr "type" "sse")
3807    (set_attr "prefix" "vex")
3808    (set_attr "mode" "V8SF")])
3809
3810 (define_insn "sse3_movsldup"
3811   [(set (match_operand:V4SF 0 "register_operand" "=x")
3812         (vec_select:V4SF
3813           (vec_concat:V8SF
3814             (match_operand:V4SF 1 "nonimmediate_operand" "xm")
3815             (match_dup 1))
3816           (parallel [(const_int 0)
3817                      (const_int 0)
3818                      (const_int 6)
3819                      (const_int 6)])))]
3820   "TARGET_SSE3"
3821   "%vmovsldup\t{%1, %0|%0, %1}"
3822   [(set_attr "type" "sse")
3823    (set_attr "prefix_rep" "1")
3824    (set_attr "prefix" "maybe_vex")
3825    (set_attr "mode" "V4SF")])
3826
3827 (define_expand "avx_shufps256"
3828   [(match_operand:V8SF 0 "register_operand")
3829    (match_operand:V8SF 1 "register_operand")
3830    (match_operand:V8SF 2 "nonimmediate_operand")
3831    (match_operand:SI 3 "const_int_operand")]
3832   "TARGET_AVX"
3833 {
3834   int mask = INTVAL (operands[3]);
3835   emit_insn (gen_avx_shufps256_1 (operands[0], operands[1], operands[2],
3836                                   GEN_INT ((mask >> 0) & 3),
3837                                   GEN_INT ((mask >> 2) & 3),
3838                                   GEN_INT (((mask >> 4) & 3) + 8),
3839                                   GEN_INT (((mask >> 6) & 3) + 8),
3840                                   GEN_INT (((mask >> 0) & 3) + 4),
3841                                   GEN_INT (((mask >> 2) & 3) + 4),
3842                                   GEN_INT (((mask >> 4) & 3) + 12),
3843                                   GEN_INT (((mask >> 6) & 3) + 12)));
3844   DONE;
3845 })
3846
3847 ;; One bit in mask selects 2 elements.
3848 (define_insn "avx_shufps256_1"
3849   [(set (match_operand:V8SF 0 "register_operand" "=x")
3850         (vec_select:V8SF
3851           (vec_concat:V16SF
3852             (match_operand:V8SF 1 "register_operand" "x")
3853             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3854           (parallel [(match_operand 3  "const_0_to_3_operand"  )
3855                      (match_operand 4  "const_0_to_3_operand"  )
3856                      (match_operand 5  "const_8_to_11_operand" )
3857                      (match_operand 6  "const_8_to_11_operand" )
3858                      (match_operand 7  "const_4_to_7_operand"  )
3859                      (match_operand 8  "const_4_to_7_operand"  )
3860                      (match_operand 9  "const_12_to_15_operand")
3861                      (match_operand 10 "const_12_to_15_operand")])))]
3862   "TARGET_AVX
3863    && (INTVAL (operands[3]) == (INTVAL (operands[7]) - 4)
3864        && INTVAL (operands[4]) == (INTVAL (operands[8]) - 4)
3865        && INTVAL (operands[5]) == (INTVAL (operands[9]) - 4)
3866        && INTVAL (operands[6]) == (INTVAL (operands[10]) - 4))"
3867 {
3868   int mask;
3869   mask = INTVAL (operands[3]);
3870   mask |= INTVAL (operands[4]) << 2;
3871   mask |= (INTVAL (operands[5]) - 8) << 4;
3872   mask |= (INTVAL (operands[6]) - 8) << 6;
3873   operands[3] = GEN_INT (mask);
3874
3875   return "vshufps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
3876 }
3877   [(set_attr "type" "sseshuf")
3878    (set_attr "length_immediate" "1")
3879    (set_attr "prefix" "vex")
3880    (set_attr "mode" "V8SF")])
3881
3882 (define_expand "sse_shufps"
3883   [(match_operand:V4SF 0 "register_operand")
3884    (match_operand:V4SF 1 "register_operand")
3885    (match_operand:V4SF 2 "nonimmediate_operand")
3886    (match_operand:SI 3 "const_int_operand")]
3887   "TARGET_SSE"
3888 {
3889   int mask = INTVAL (operands[3]);
3890   emit_insn (gen_sse_shufps_v4sf (operands[0], operands[1], operands[2],
3891                                GEN_INT ((mask >> 0) & 3),
3892                                GEN_INT ((mask >> 2) & 3),
3893                                GEN_INT (((mask >> 4) & 3) + 4),
3894                                GEN_INT (((mask >> 6) & 3) + 4)));
3895   DONE;
3896 })
3897
3898 (define_insn "sse_shufps_<mode>"
3899   [(set (match_operand:VI4F_128 0 "register_operand" "=x,x")
3900         (vec_select:VI4F_128
3901           (vec_concat:<ssedoublevecmode>
3902             (match_operand:VI4F_128 1 "register_operand" "0,x")
3903             (match_operand:VI4F_128 2 "nonimmediate_operand" "xm,xm"))
3904           (parallel [(match_operand 3 "const_0_to_3_operand")
3905                      (match_operand 4 "const_0_to_3_operand")
3906                      (match_operand 5 "const_4_to_7_operand")
3907                      (match_operand 6 "const_4_to_7_operand")])))]
3908   "TARGET_SSE"
3909 {
3910   int mask = 0;
3911   mask |= INTVAL (operands[3]) << 0;
3912   mask |= INTVAL (operands[4]) << 2;
3913   mask |= (INTVAL (operands[5]) - 4) << 4;
3914   mask |= (INTVAL (operands[6]) - 4) << 6;
3915   operands[3] = GEN_INT (mask);
3916
3917   switch (which_alternative)
3918     {
3919     case 0:
3920       return "shufps\t{%3, %2, %0|%0, %2, %3}";
3921     case 1:
3922       return "vshufps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
3923     default:
3924       gcc_unreachable ();
3925     }
3926 }
3927   [(set_attr "isa" "noavx,avx")
3928    (set_attr "type" "sseshuf")
3929    (set_attr "length_immediate" "1")
3930    (set_attr "prefix" "orig,vex")
3931    (set_attr "mode" "V4SF")])
3932
3933 (define_insn "sse_storehps"
3934   [(set (match_operand:V2SF 0 "nonimmediate_operand" "=m,x,x")
3935         (vec_select:V2SF
3936           (match_operand:V4SF 1 "nonimmediate_operand" "x,x,o")
3937           (parallel [(const_int 2) (const_int 3)])))]
3938   "TARGET_SSE"
3939   "@
3940    %vmovhps\t{%1, %0|%0, %1}
3941    %vmovhlps\t{%1, %d0|%d0, %1}
3942    %vmovlps\t{%H1, %d0|%d0, %H1}"
3943   [(set_attr "type" "ssemov")
3944    (set_attr "prefix" "maybe_vex")
3945    (set_attr "mode" "V2SF,V4SF,V2SF")])
3946
3947 (define_expand "sse_loadhps_exp"
3948   [(set (match_operand:V4SF 0 "nonimmediate_operand")
3949         (vec_concat:V4SF
3950           (vec_select:V2SF
3951             (match_operand:V4SF 1 "nonimmediate_operand")
3952             (parallel [(const_int 0) (const_int 1)]))
3953           (match_operand:V2SF 2 "nonimmediate_operand")))]
3954   "TARGET_SSE"
3955 {
3956   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
3957
3958   emit_insn (gen_sse_loadhps (dst, operands[1], operands[2]));
3959
3960   /* Fix up the destination if needed.  */
3961   if (dst != operands[0])
3962     emit_move_insn (operands[0], dst);
3963
3964   DONE;
3965 })
3966
3967 (define_insn "sse_loadhps"
3968   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,o")
3969         (vec_concat:V4SF
3970           (vec_select:V2SF
3971             (match_operand:V4SF 1 "nonimmediate_operand" " 0,x,0,x,0")
3972             (parallel [(const_int 0) (const_int 1)]))
3973           (match_operand:V2SF 2 "nonimmediate_operand"   " m,m,x,x,x")))]
3974   "TARGET_SSE"
3975   "@
3976    movhps\t{%2, %0|%0, %2}
3977    vmovhps\t{%2, %1, %0|%0, %1, %2}
3978    movlhps\t{%2, %0|%0, %2}
3979    vmovlhps\t{%2, %1, %0|%0, %1, %2}
3980    %vmovlps\t{%2, %H0|%H0, %2}"
3981   [(set_attr "isa" "noavx,avx,noavx,avx,*")
3982    (set_attr "type" "ssemov")
3983    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
3984    (set_attr "mode" "V2SF,V2SF,V4SF,V4SF,V2SF")])
3985
3986 (define_insn "sse_storelps"
3987   [(set (match_operand:V2SF 0 "nonimmediate_operand"   "=m,x,x")
3988         (vec_select:V2SF
3989           (match_operand:V4SF 1 "nonimmediate_operand" " x,x,m")
3990           (parallel [(const_int 0) (const_int 1)])))]
3991   "TARGET_SSE"
3992   "@
3993    %vmovlps\t{%1, %0|%0, %1}
3994    %vmovaps\t{%1, %0|%0, %1}
3995    %vmovlps\t{%1, %d0|%d0, %1}"
3996   [(set_attr "type" "ssemov")
3997    (set_attr "prefix" "maybe_vex")
3998    (set_attr "mode" "V2SF,V4SF,V2SF")])
3999
4000 (define_expand "sse_loadlps_exp"
4001   [(set (match_operand:V4SF 0 "nonimmediate_operand")
4002         (vec_concat:V4SF
4003           (match_operand:V2SF 2 "nonimmediate_operand")
4004           (vec_select:V2SF
4005             (match_operand:V4SF 1 "nonimmediate_operand")
4006             (parallel [(const_int 2) (const_int 3)]))))]
4007   "TARGET_SSE"
4008 {
4009   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
4010
4011   emit_insn (gen_sse_loadlps (dst, operands[1], operands[2]));
4012
4013   /* Fix up the destination if needed.  */
4014   if (dst != operands[0])
4015     emit_move_insn (operands[0], dst);
4016
4017   DONE;
4018 })
4019
4020 (define_insn "sse_loadlps"
4021   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,m")
4022         (vec_concat:V4SF
4023           (match_operand:V2SF 2 "nonimmediate_operand"   " 0,x,m,m,x")
4024           (vec_select:V2SF
4025             (match_operand:V4SF 1 "nonimmediate_operand" " x,x,0,x,0")
4026             (parallel [(const_int 2) (const_int 3)]))))]
4027   "TARGET_SSE"
4028   "@
4029    shufps\t{$0xe4, %1, %0|%0, %1, 0xe4}
4030    vshufps\t{$0xe4, %1, %2, %0|%0, %2, %1, 0xe4}
4031    movlps\t{%2, %0|%0, %2}
4032    vmovlps\t{%2, %1, %0|%0, %1, %2}
4033    %vmovlps\t{%2, %0|%0, %2}"
4034   [(set_attr "isa" "noavx,avx,noavx,avx,*")
4035    (set_attr "type" "sseshuf,sseshuf,ssemov,ssemov,ssemov")
4036    (set_attr "length_immediate" "1,1,*,*,*")
4037    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
4038    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF,V2SF")])
4039
4040 (define_insn "sse_movss"
4041   [(set (match_operand:V4SF 0 "register_operand"   "=x,x")
4042         (vec_merge:V4SF
4043           (match_operand:V4SF 2 "register_operand" " x,x")
4044           (match_operand:V4SF 1 "register_operand" " 0,x")
4045           (const_int 1)))]
4046   "TARGET_SSE"
4047   "@
4048    movss\t{%2, %0|%0, %2}
4049    vmovss\t{%2, %1, %0|%0, %1, %2}"
4050   [(set_attr "isa" "noavx,avx")
4051    (set_attr "type" "ssemov")
4052    (set_attr "prefix" "orig,vex")
4053    (set_attr "mode" "SF")])
4054
4055 (define_insn "avx2_vec_dup<mode>"
4056   [(set (match_operand:VF1 0 "register_operand" "=x")
4057         (vec_duplicate:VF1
4058           (vec_select:SF
4059             (match_operand:V4SF 1 "register_operand" "x")
4060             (parallel [(const_int 0)]))))]
4061   "TARGET_AVX2"
4062   "vbroadcastss\t{%1, %0|%0, %1}"
4063   [(set_attr "type" "sselog1")
4064     (set_attr "prefix" "vex")
4065     (set_attr "mode" "<MODE>")])
4066
4067 (define_insn "avx2_vec_dupv8sf_1"
4068   [(set (match_operand:V8SF 0 "register_operand" "=x")
4069         (vec_duplicate:V8SF
4070           (vec_select:SF
4071             (match_operand:V8SF 1 "register_operand" "x")
4072             (parallel [(const_int 0)]))))]
4073   "TARGET_AVX2"
4074   "vbroadcastss\t{%x1, %0|%0, %x1}"
4075   [(set_attr "type" "sselog1")
4076     (set_attr "prefix" "vex")
4077     (set_attr "mode" "V8SF")])
4078
4079 (define_insn "vec_dupv4sf"
4080   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
4081         (vec_duplicate:V4SF
4082           (match_operand:SF 1 "nonimmediate_operand" "x,m,0")))]
4083   "TARGET_SSE"
4084   "@
4085    vshufps\t{$0, %1, %1, %0|%0, %1, %1, 0}
4086    vbroadcastss\t{%1, %0|%0, %1}
4087    shufps\t{$0, %0, %0|%0, %0, 0}"
4088   [(set_attr "isa" "avx,avx,noavx")
4089    (set_attr "type" "sseshuf1,ssemov,sseshuf1")
4090    (set_attr "length_immediate" "1,0,1")
4091    (set_attr "prefix_extra" "0,1,*")
4092    (set_attr "prefix" "vex,vex,orig")
4093    (set_attr "mode" "V4SF")])
4094
4095 ;; Although insertps takes register source, we prefer
4096 ;; unpcklps with register source since it is shorter.
4097 (define_insn "*vec_concatv2sf_sse4_1"
4098   [(set (match_operand:V2SF 0 "register_operand"     "=x,x,x,x,x,*y ,*y")
4099         (vec_concat:V2SF
4100           (match_operand:SF 1 "nonimmediate_operand" " 0,x,0,x,m, 0 , m")
4101           (match_operand:SF 2 "vector_move_operand"  " x,x,m,m,C,*ym, C")))]
4102   "TARGET_SSE4_1"
4103   "@
4104    unpcklps\t{%2, %0|%0, %2}
4105    vunpcklps\t{%2, %1, %0|%0, %1, %2}
4106    insertps\t{$0x10, %2, %0|%0, %2, 0x10}
4107    vinsertps\t{$0x10, %2, %1, %0|%0, %1, %2, 0x10}
4108    %vmovss\t{%1, %0|%0, %1}
4109    punpckldq\t{%2, %0|%0, %2}
4110    movd\t{%1, %0|%0, %1}"
4111   [(set_attr "isa" "noavx,avx,noavx,avx,*,*,*")
4112    (set_attr "type" "sselog,sselog,sselog,sselog,ssemov,mmxcvt,mmxmov")
4113    (set_attr "prefix_data16" "*,*,1,*,*,*,*")
4114    (set_attr "prefix_extra" "*,*,1,1,*,*,*")
4115    (set_attr "length_immediate" "*,*,1,1,*,*,*")
4116    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex,orig,orig")
4117    (set_attr "mode" "V4SF,V4SF,V4SF,V4SF,SF,DI,DI")])
4118
4119 ;; ??? In theory we can match memory for the MMX alternative, but allowing
4120 ;; nonimmediate_operand for operand 2 and *not* allowing memory for the SSE
4121 ;; alternatives pretty much forces the MMX alternative to be chosen.
4122 (define_insn "*vec_concatv2sf_sse"
4123   [(set (match_operand:V2SF 0 "register_operand"     "=x,x,*y,*y")
4124         (vec_concat:V2SF
4125           (match_operand:SF 1 "nonimmediate_operand" " 0,m, 0, m")
4126           (match_operand:SF 2 "reg_or_0_operand"     " x,C,*y, C")))]
4127   "TARGET_SSE"
4128   "@
4129    unpcklps\t{%2, %0|%0, %2}
4130    movss\t{%1, %0|%0, %1}
4131    punpckldq\t{%2, %0|%0, %2}
4132    movd\t{%1, %0|%0, %1}"
4133   [(set_attr "type" "sselog,ssemov,mmxcvt,mmxmov")
4134    (set_attr "mode" "V4SF,SF,DI,DI")])
4135
4136 (define_insn "*vec_concatv4sf"
4137   [(set (match_operand:V4SF 0 "register_operand"       "=x,x,x,x")
4138         (vec_concat:V4SF
4139           (match_operand:V2SF 1 "register_operand"     " 0,x,0,x")
4140           (match_operand:V2SF 2 "nonimmediate_operand" " x,x,m,m")))]
4141   "TARGET_SSE"
4142   "@
4143    movlhps\t{%2, %0|%0, %2}
4144    vmovlhps\t{%2, %1, %0|%0, %1, %2}
4145    movhps\t{%2, %0|%0, %2}
4146    vmovhps\t{%2, %1, %0|%0, %1, %2}"
4147   [(set_attr "isa" "noavx,avx,noavx,avx")
4148    (set_attr "type" "ssemov")
4149    (set_attr "prefix" "orig,vex,orig,vex")
4150    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF")])
4151
4152 (define_expand "vec_init<mode>"
4153   [(match_operand:V_128 0 "register_operand")
4154    (match_operand 1)]
4155   "TARGET_SSE"
4156 {
4157   ix86_expand_vector_init (false, operands[0], operands[1]);
4158   DONE;
4159 })
4160
4161 ;; Avoid combining registers from different units in a single alternative,
4162 ;; see comment above inline_secondary_memory_needed function in i386.c
4163 (define_insn "vec_set<mode>_0"
4164   [(set (match_operand:VI4F_128 0 "nonimmediate_operand"
4165           "=x,x,x ,x,x,x,x  ,x  ,m ,m   ,m")
4166         (vec_merge:VI4F_128
4167           (vec_duplicate:VI4F_128
4168             (match_operand:<ssescalarmode> 2 "general_operand"
4169           " x,m,*r,m,x,x,*rm,*rm,!x,!*re,!*fF"))
4170           (match_operand:VI4F_128 1 "vector_move_operand"
4171           " C,C,C ,C,0,x,0  ,x  ,0 ,0   ,0")
4172           (const_int 1)))]
4173   "TARGET_SSE"
4174   "@
4175    %vinsertps\t{$0xe, %d2, %0|%0, %d2, 0xe}
4176    %vmov<ssescalarmodesuffix>\t{%2, %0|%0, %2}
4177    %vmovd\t{%2, %0|%0, %2}
4178    movss\t{%2, %0|%0, %2}
4179    movss\t{%2, %0|%0, %2}
4180    vmovss\t{%2, %1, %0|%0, %1, %2}
4181    pinsrd\t{$0, %2, %0|%0, %2, 0}
4182    vpinsrd\t{$0, %2, %1, %0|%0, %1, %2, 0}
4183    #
4184    #
4185    #"
4186   [(set_attr "isa" "sse4,sse2,sse2,noavx,noavx,avx,sse4_noavx,avx,*,*,*")
4187    (set (attr "type")
4188      (cond [(eq_attr "alternative" "0,6,7")
4189               (const_string "sselog")
4190             (eq_attr "alternative" "9")
4191               (const_string "imov")
4192             (eq_attr "alternative" "10")
4193               (const_string "fmov")
4194            ]
4195            (const_string "ssemov")))
4196    (set_attr "prefix_extra" "*,*,*,*,*,*,1,1,*,*,*")
4197    (set_attr "length_immediate" "*,*,*,*,*,*,1,1,*,*,*")
4198    (set_attr "prefix" "maybe_vex,maybe_vex,maybe_vex,orig,orig,vex,orig,vex,*,*,*")
4199    (set_attr "mode" "SF,<ssescalarmode>,SI,SF,SF,SF,TI,TI,*,*,*")])
4200
4201 ;; A subset is vec_setv4sf.
4202 (define_insn "*vec_setv4sf_sse4_1"
4203   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
4204         (vec_merge:V4SF
4205           (vec_duplicate:V4SF
4206             (match_operand:SF 2 "nonimmediate_operand" "xm,xm"))
4207           (match_operand:V4SF 1 "register_operand" "0,x")
4208           (match_operand:SI 3 "const_int_operand")))]
4209   "TARGET_SSE4_1
4210    && ((unsigned) exact_log2 (INTVAL (operands[3]))
4211        < GET_MODE_NUNITS (V4SFmode))"
4212 {
4213   operands[3] = GEN_INT (exact_log2 (INTVAL (operands[3])) << 4);
4214   switch (which_alternative)
4215     {
4216     case 0:
4217       return "insertps\t{%3, %2, %0|%0, %2, %3}";
4218     case 1:
4219       return "vinsertps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
4220     default:
4221       gcc_unreachable ();
4222     }
4223 }
4224   [(set_attr "isa" "noavx,avx")
4225    (set_attr "type" "sselog")
4226    (set_attr "prefix_data16" "1,*")
4227    (set_attr "prefix_extra" "1")
4228    (set_attr "length_immediate" "1")
4229    (set_attr "prefix" "orig,vex")
4230    (set_attr "mode" "V4SF")])
4231
4232 (define_insn "sse4_1_insertps"
4233   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
4234         (unspec:V4SF [(match_operand:V4SF 2 "nonimmediate_operand" "xm,xm")
4235                       (match_operand:V4SF 1 "register_operand" "0,x")
4236                       (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
4237                      UNSPEC_INSERTPS))]
4238   "TARGET_SSE4_1"
4239 {
4240   if (MEM_P (operands[2]))
4241     {
4242       unsigned count_s = INTVAL (operands[3]) >> 6;
4243       if (count_s)
4244         operands[3] = GEN_INT (INTVAL (operands[3]) & 0x3f);
4245       operands[2] = adjust_address_nv (operands[2], SFmode, count_s * 4);
4246     }
4247   switch (which_alternative)
4248     {
4249     case 0:
4250       return "insertps\t{%3, %2, %0|%0, %2, %3}";
4251     case 1:
4252       return "vinsertps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
4253     default:
4254       gcc_unreachable ();
4255     }
4256 }
4257   [(set_attr "isa" "noavx,avx")
4258    (set_attr "type" "sselog")
4259    (set_attr "prefix_data16" "1,*")
4260    (set_attr "prefix_extra" "1")
4261    (set_attr "length_immediate" "1")
4262    (set_attr "prefix" "orig,vex")
4263    (set_attr "mode" "V4SF")])
4264
4265 (define_split
4266   [(set (match_operand:VI4F_128 0 "memory_operand")
4267         (vec_merge:VI4F_128
4268           (vec_duplicate:VI4F_128
4269             (match_operand:<ssescalarmode> 1 "nonmemory_operand"))
4270           (match_dup 0)
4271           (const_int 1)))]
4272   "TARGET_SSE && reload_completed"
4273   [(const_int 0)]
4274 {
4275   emit_move_insn (adjust_address (operands[0], <ssescalarmode>mode, 0),
4276                   operands[1]);
4277   DONE;
4278 })
4279
4280 (define_expand "vec_set<mode>"
4281   [(match_operand:V 0 "register_operand")
4282    (match_operand:<ssescalarmode> 1 "register_operand")
4283    (match_operand 2 "const_int_operand")]
4284   "TARGET_SSE"
4285 {
4286   ix86_expand_vector_set (false, operands[0], operands[1],
4287                           INTVAL (operands[2]));
4288   DONE;
4289 })
4290
4291 (define_insn_and_split "*vec_extractv4sf_0"
4292   [(set (match_operand:SF 0 "nonimmediate_operand" "=x,m,f,r")
4293         (vec_select:SF
4294           (match_operand:V4SF 1 "nonimmediate_operand" "xm,x,m,m")
4295           (parallel [(const_int 0)])))]
4296   "TARGET_SSE && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4297   "#"
4298   "&& reload_completed"
4299   [(const_int 0)]
4300 {
4301   rtx op1 = operands[1];
4302   if (REG_P (op1))
4303     op1 = gen_rtx_REG (SFmode, REGNO (op1));
4304   else
4305     op1 = gen_lowpart (SFmode, op1);
4306   emit_move_insn (operands[0], op1);
4307   DONE;
4308 })
4309
4310 (define_insn_and_split "*sse4_1_extractps"
4311   [(set (match_operand:SF 0 "nonimmediate_operand" "=rm,x,x")
4312         (vec_select:SF
4313           (match_operand:V4SF 1 "register_operand" "x,0,x")
4314           (parallel [(match_operand:SI 2 "const_0_to_3_operand" "n,n,n")])))]
4315   "TARGET_SSE4_1"
4316   "@
4317    %vextractps\t{%2, %1, %0|%0, %1, %2}
4318    #
4319    #"
4320   "&& reload_completed && SSE_REG_P (operands[0])"
4321   [(const_int 0)]
4322 {
4323   rtx dest = gen_rtx_REG (V4SFmode, REGNO (operands[0]));
4324   switch (INTVAL (operands[2]))
4325     {
4326     case 1:
4327     case 3:
4328       emit_insn (gen_sse_shufps_v4sf (dest, operands[1], operands[1],
4329                                       operands[2], operands[2],
4330                                       GEN_INT (INTVAL (operands[2]) + 4),
4331                                       GEN_INT (INTVAL (operands[2]) + 4)));
4332       break;
4333     case 2:
4334       emit_insn (gen_vec_interleave_highv4sf (dest, operands[1], operands[1]));
4335       break;
4336     default:
4337       /* 0 should be handled by the *vec_extractv4sf_0 pattern above.  */
4338       gcc_unreachable ();
4339     }
4340   DONE;
4341 }
4342   [(set_attr "isa" "*,noavx,avx")
4343    (set_attr "type" "sselog,*,*")
4344    (set_attr "prefix_data16" "1,*,*")
4345    (set_attr "prefix_extra" "1,*,*")
4346    (set_attr "length_immediate" "1,*,*")
4347    (set_attr "prefix" "maybe_vex,*,*")
4348    (set_attr "mode" "V4SF,*,*")])
4349
4350 (define_insn_and_split "*vec_extract_v4sf_mem"
4351   [(set (match_operand:SF 0 "register_operand" "=x,*r,f")
4352        (vec_select:SF
4353          (match_operand:V4SF 1 "memory_operand" "o,o,o")
4354          (parallel [(match_operand 2 "const_0_to_3_operand" "n,n,n")])))]
4355   "TARGET_SSE"
4356   "#"
4357   "&& reload_completed"
4358   [(const_int 0)]
4359 {
4360   int i = INTVAL (operands[2]);
4361
4362   emit_move_insn (operands[0], adjust_address (operands[1], SFmode, i*4));
4363   DONE;
4364 })
4365
4366 (define_expand "avx_vextractf128<mode>"
4367   [(match_operand:<ssehalfvecmode> 0 "nonimmediate_operand")
4368    (match_operand:V_256 1 "register_operand")
4369    (match_operand:SI 2 "const_0_to_1_operand")]
4370   "TARGET_AVX"
4371 {
4372   rtx (*insn)(rtx, rtx);
4373
4374   switch (INTVAL (operands[2]))
4375     {
4376     case 0:
4377       insn = gen_vec_extract_lo_<mode>;
4378       break;
4379     case 1:
4380       insn = gen_vec_extract_hi_<mode>;
4381       break;
4382     default:
4383       gcc_unreachable ();
4384     }
4385
4386   emit_insn (insn (operands[0], operands[1]));
4387   DONE;
4388 })
4389
4390 (define_insn_and_split "vec_extract_lo_<mode>"
4391   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "=x,m")
4392         (vec_select:<ssehalfvecmode>
4393           (match_operand:VI8F_256 1 "nonimmediate_operand" "xm,x")
4394           (parallel [(const_int 0) (const_int 1)])))]
4395   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4396   "#"
4397   "&& reload_completed"
4398   [(const_int 0)]
4399 {
4400   rtx op1 = operands[1];
4401   if (REG_P (op1))
4402     op1 = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (op1));
4403   else
4404     op1 = gen_lowpart (<ssehalfvecmode>mode, op1);
4405   emit_move_insn (operands[0], op1);
4406   DONE;
4407 })
4408
4409 (define_insn "vec_extract_hi_<mode>"
4410   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "=x,m")
4411         (vec_select:<ssehalfvecmode>
4412           (match_operand:VI8F_256 1 "register_operand" "x,x")
4413           (parallel [(const_int 2) (const_int 3)])))]
4414   "TARGET_AVX"
4415   "vextract<i128>\t{$0x1, %1, %0|%0, %1, 0x1}"
4416   [(set_attr "type" "sselog")
4417    (set_attr "prefix_extra" "1")
4418    (set_attr "length_immediate" "1")
4419    (set_attr "memory" "none,store")
4420    (set_attr "prefix" "vex")
4421    (set_attr "mode" "<sseinsnmode>")])
4422
4423 (define_insn_and_split "vec_extract_lo_<mode>"
4424   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "=x,m")
4425         (vec_select:<ssehalfvecmode>
4426           (match_operand:VI4F_256 1 "nonimmediate_operand" "xm,x")
4427           (parallel [(const_int 0) (const_int 1)
4428                      (const_int 2) (const_int 3)])))]
4429   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4430   "#"
4431   "&& reload_completed"
4432   [(const_int 0)]
4433 {
4434   rtx op1 = operands[1];
4435   if (REG_P (op1))
4436     op1 = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (op1));
4437   else
4438     op1 = gen_lowpart (<ssehalfvecmode>mode, op1);
4439   emit_move_insn (operands[0], op1);
4440   DONE;
4441 })
4442
4443 (define_insn "vec_extract_hi_<mode>"
4444   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "=x,m")
4445         (vec_select:<ssehalfvecmode>
4446           (match_operand:VI4F_256 1 "register_operand" "x,x")
4447           (parallel [(const_int 4) (const_int 5)
4448                      (const_int 6) (const_int 7)])))]
4449   "TARGET_AVX"
4450   "vextract<i128>\t{$0x1, %1, %0|%0, %1, 0x1}"
4451   [(set_attr "type" "sselog")
4452    (set_attr "prefix_extra" "1")
4453    (set_attr "length_immediate" "1")
4454    (set_attr "memory" "none,store")
4455    (set_attr "prefix" "vex")
4456    (set_attr "mode" "<sseinsnmode>")])
4457
4458 (define_insn_and_split "vec_extract_lo_v16hi"
4459   [(set (match_operand:V8HI 0 "nonimmediate_operand" "=x,m")
4460         (vec_select:V8HI
4461           (match_operand:V16HI 1 "nonimmediate_operand" "xm,x")
4462           (parallel [(const_int 0) (const_int 1)
4463                      (const_int 2) (const_int 3)
4464                      (const_int 4) (const_int 5)
4465                      (const_int 6) (const_int 7)])))]
4466   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4467   "#"
4468   "&& reload_completed"
4469   [(const_int 0)]
4470 {
4471   rtx op1 = operands[1];
4472   if (REG_P (op1))
4473     op1 = gen_rtx_REG (V8HImode, REGNO (op1));
4474   else
4475     op1 = gen_lowpart (V8HImode, op1);
4476   emit_move_insn (operands[0], op1);
4477   DONE;
4478 })
4479
4480 (define_insn "vec_extract_hi_v16hi"
4481   [(set (match_operand:V8HI 0 "nonimmediate_operand" "=x,m")
4482         (vec_select:V8HI
4483           (match_operand:V16HI 1 "register_operand" "x,x")
4484           (parallel [(const_int 8) (const_int 9)
4485                      (const_int 10) (const_int 11)
4486                      (const_int 12) (const_int 13)
4487                      (const_int 14) (const_int 15)])))]
4488   "TARGET_AVX"
4489   "vextract%~128\t{$0x1, %1, %0|%0, %1, 0x1}"
4490   [(set_attr "type" "sselog")
4491    (set_attr "prefix_extra" "1")
4492    (set_attr "length_immediate" "1")
4493    (set_attr "memory" "none,store")
4494    (set_attr "prefix" "vex")
4495    (set_attr "mode" "OI")])
4496
4497 (define_insn_and_split "vec_extract_lo_v32qi"
4498   [(set (match_operand:V16QI 0 "nonimmediate_operand" "=x,m")
4499         (vec_select:V16QI
4500           (match_operand:V32QI 1 "nonimmediate_operand" "xm,x")
4501           (parallel [(const_int 0) (const_int 1)
4502                      (const_int 2) (const_int 3)
4503                      (const_int 4) (const_int 5)
4504                      (const_int 6) (const_int 7)
4505                      (const_int 8) (const_int 9)
4506                      (const_int 10) (const_int 11)
4507                      (const_int 12) (const_int 13)
4508                      (const_int 14) (const_int 15)])))]
4509   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4510   "#"
4511   "&& reload_completed"
4512   [(const_int 0)]
4513 {
4514   rtx op1 = operands[1];
4515   if (REG_P (op1))
4516     op1 = gen_rtx_REG (V16QImode, REGNO (op1));
4517   else
4518     op1 = gen_lowpart (V16QImode, op1);
4519   emit_move_insn (operands[0], op1);
4520   DONE;
4521 })
4522
4523 (define_insn "vec_extract_hi_v32qi"
4524   [(set (match_operand:V16QI 0 "nonimmediate_operand" "=x,m")
4525         (vec_select:V16QI
4526           (match_operand:V32QI 1 "register_operand" "x,x")
4527           (parallel [(const_int 16) (const_int 17)
4528                      (const_int 18) (const_int 19)
4529                      (const_int 20) (const_int 21)
4530                      (const_int 22) (const_int 23)
4531                      (const_int 24) (const_int 25)
4532                      (const_int 26) (const_int 27)
4533                      (const_int 28) (const_int 29)
4534                      (const_int 30) (const_int 31)])))]
4535   "TARGET_AVX"
4536   "vextract%~128\t{$0x1, %1, %0|%0, %1, 0x1}"
4537   [(set_attr "type" "sselog")
4538    (set_attr "prefix_extra" "1")
4539    (set_attr "length_immediate" "1")
4540    (set_attr "memory" "none,store")
4541    (set_attr "prefix" "vex")
4542    (set_attr "mode" "OI")])
4543
4544 ;; Modes handled by vec_extract patterns.
4545 (define_mode_iterator VEC_EXTRACT_MODE
4546   [(V32QI "TARGET_AVX") V16QI
4547    (V16HI "TARGET_AVX") V8HI
4548    (V8SI "TARGET_AVX") V4SI
4549    (V4DI "TARGET_AVX") V2DI
4550    (V8SF "TARGET_AVX") V4SF
4551    (V4DF "TARGET_AVX") V2DF])
4552
4553 (define_expand "vec_extract<mode>"
4554   [(match_operand:<ssescalarmode> 0 "register_operand")
4555    (match_operand:VEC_EXTRACT_MODE 1 "register_operand")
4556    (match_operand 2 "const_int_operand")]
4557   "TARGET_SSE"
4558 {
4559   ix86_expand_vector_extract (false, operands[0], operands[1],
4560                               INTVAL (operands[2]));
4561   DONE;
4562 })
4563
4564 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4565 ;;
4566 ;; Parallel double-precision floating point element swizzling
4567 ;;
4568 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4569
4570 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
4571 (define_insn "avx_unpckhpd256"
4572   [(set (match_operand:V4DF 0 "register_operand" "=x")
4573         (vec_select:V4DF
4574           (vec_concat:V8DF
4575             (match_operand:V4DF 1 "register_operand" "x")
4576             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
4577           (parallel [(const_int 1) (const_int 5)
4578                      (const_int 3) (const_int 7)])))]
4579   "TARGET_AVX"
4580   "vunpckhpd\t{%2, %1, %0|%0, %1, %2}"
4581   [(set_attr "type" "sselog")
4582    (set_attr "prefix" "vex")
4583    (set_attr "mode" "V4DF")])
4584
4585 (define_expand "vec_interleave_highv4df"
4586   [(set (match_dup 3)
4587         (vec_select:V4DF
4588           (vec_concat:V8DF
4589             (match_operand:V4DF 1 "register_operand" "x")
4590             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
4591           (parallel [(const_int 0) (const_int 4)
4592                      (const_int 2) (const_int 6)])))
4593    (set (match_dup 4)
4594         (vec_select:V4DF
4595           (vec_concat:V8DF
4596             (match_dup 1)
4597             (match_dup 2))
4598           (parallel [(const_int 1) (const_int 5)
4599                      (const_int 3) (const_int 7)])))
4600    (set (match_operand:V4DF 0 "register_operand")
4601         (vec_select:V4DF
4602           (vec_concat:V8DF
4603             (match_dup 3)
4604             (match_dup 4))
4605           (parallel [(const_int 2) (const_int 3)
4606                      (const_int 6) (const_int 7)])))]
4607  "TARGET_AVX"
4608 {
4609   operands[3] = gen_reg_rtx (V4DFmode);
4610   operands[4] = gen_reg_rtx (V4DFmode);
4611 })
4612
4613
4614 (define_expand "vec_interleave_highv2df"
4615   [(set (match_operand:V2DF 0 "register_operand")
4616         (vec_select:V2DF
4617           (vec_concat:V4DF
4618             (match_operand:V2DF 1 "nonimmediate_operand")
4619             (match_operand:V2DF 2 "nonimmediate_operand"))
4620           (parallel [(const_int 1)
4621                      (const_int 3)])))]
4622   "TARGET_SSE2"
4623 {
4624   if (!ix86_vec_interleave_v2df_operator_ok (operands, 1))
4625     operands[2] = force_reg (V2DFmode, operands[2]);
4626 })
4627
4628 (define_insn "*vec_interleave_highv2df"
4629   [(set (match_operand:V2DF 0 "nonimmediate_operand"     "=x,x,x,x,x,m")
4630         (vec_select:V2DF
4631           (vec_concat:V4DF
4632             (match_operand:V2DF 1 "nonimmediate_operand" " 0,x,o,o,o,x")
4633             (match_operand:V2DF 2 "nonimmediate_operand" " x,x,1,0,x,0"))
4634           (parallel [(const_int 1)
4635                      (const_int 3)])))]
4636   "TARGET_SSE2 && ix86_vec_interleave_v2df_operator_ok (operands, 1)"
4637   "@
4638    unpckhpd\t{%2, %0|%0, %2}
4639    vunpckhpd\t{%2, %1, %0|%0, %1, %2}
4640    %vmovddup\t{%H1, %0|%0, %H1}
4641    movlpd\t{%H1, %0|%0, %H1}
4642    vmovlpd\t{%H1, %2, %0|%0, %2, %H1}
4643    %vmovhpd\t{%1, %0|%0, %1}"
4644   [(set_attr "isa" "noavx,avx,sse3,noavx,avx,*")
4645   (set_attr "type" "sselog,sselog,sselog,ssemov,ssemov,ssemov")
4646    (set_attr "prefix_data16" "*,*,*,1,*,1")
4647    (set_attr "prefix" "orig,vex,maybe_vex,orig,vex,maybe_vex")
4648    (set_attr "mode" "V2DF,V2DF,DF,V1DF,V1DF,V1DF")])
4649
4650 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
4651 (define_expand "avx_movddup256"
4652   [(set (match_operand:V4DF 0 "register_operand")
4653         (vec_select:V4DF
4654           (vec_concat:V8DF
4655             (match_operand:V4DF 1 "nonimmediate_operand")
4656             (match_dup 1))
4657           (parallel [(const_int 0) (const_int 4)
4658                      (const_int 2) (const_int 6)])))]
4659   "TARGET_AVX")
4660
4661 (define_expand "avx_unpcklpd256"
4662   [(set (match_operand:V4DF 0 "register_operand")
4663         (vec_select:V4DF
4664           (vec_concat:V8DF
4665             (match_operand:V4DF 1 "register_operand")
4666             (match_operand:V4DF 2 "nonimmediate_operand"))
4667           (parallel [(const_int 0) (const_int 4)
4668                      (const_int 2) (const_int 6)])))]
4669   "TARGET_AVX")
4670
4671 (define_insn "*avx_unpcklpd256"
4672   [(set (match_operand:V4DF 0 "register_operand"         "=x,x")
4673         (vec_select:V4DF
4674           (vec_concat:V8DF
4675             (match_operand:V4DF 1 "nonimmediate_operand" " x,m")
4676             (match_operand:V4DF 2 "nonimmediate_operand" "xm,1"))
4677           (parallel [(const_int 0) (const_int 4)
4678                      (const_int 2) (const_int 6)])))]
4679   "TARGET_AVX"
4680   "@
4681    vunpcklpd\t{%2, %1, %0|%0, %1, %2}
4682    vmovddup\t{%1, %0|%0, %1}"
4683   [(set_attr "type" "sselog")
4684    (set_attr "prefix" "vex")
4685    (set_attr "mode" "V4DF")])
4686
4687 (define_expand "vec_interleave_lowv4df"
4688   [(set (match_dup 3)
4689         (vec_select:V4DF
4690           (vec_concat:V8DF
4691             (match_operand:V4DF 1 "register_operand" "x")
4692             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
4693           (parallel [(const_int 0) (const_int 4)
4694                      (const_int 2) (const_int 6)])))
4695    (set (match_dup 4)
4696         (vec_select:V4DF
4697           (vec_concat:V8DF
4698             (match_dup 1)
4699             (match_dup 2))
4700           (parallel [(const_int 1) (const_int 5)
4701                      (const_int 3) (const_int 7)])))
4702    (set (match_operand:V4DF 0 "register_operand")
4703         (vec_select:V4DF
4704           (vec_concat:V8DF
4705             (match_dup 3)
4706             (match_dup 4))
4707           (parallel [(const_int 0) (const_int 1)
4708                      (const_int 4) (const_int 5)])))]
4709  "TARGET_AVX"
4710 {
4711   operands[3] = gen_reg_rtx (V4DFmode);
4712   operands[4] = gen_reg_rtx (V4DFmode);
4713 })
4714
4715 (define_expand "vec_interleave_lowv2df"
4716   [(set (match_operand:V2DF 0 "register_operand")
4717         (vec_select:V2DF
4718           (vec_concat:V4DF
4719             (match_operand:V2DF 1 "nonimmediate_operand")
4720             (match_operand:V2DF 2 "nonimmediate_operand"))
4721           (parallel [(const_int 0)
4722                      (const_int 2)])))]
4723   "TARGET_SSE2"
4724 {
4725   if (!ix86_vec_interleave_v2df_operator_ok (operands, 0))
4726     operands[1] = force_reg (V2DFmode, operands[1]);
4727 })
4728
4729 (define_insn "*vec_interleave_lowv2df"
4730   [(set (match_operand:V2DF 0 "nonimmediate_operand"     "=x,x,x,x,x,o")
4731         (vec_select:V2DF
4732           (vec_concat:V4DF
4733             (match_operand:V2DF 1 "nonimmediate_operand" " 0,x,m,0,x,0")
4734             (match_operand:V2DF 2 "nonimmediate_operand" " x,x,1,m,m,x"))
4735           (parallel [(const_int 0)
4736                      (const_int 2)])))]
4737   "TARGET_SSE2 && ix86_vec_interleave_v2df_operator_ok (operands, 0)"
4738   "@
4739    unpcklpd\t{%2, %0|%0, %2}
4740    vunpcklpd\t{%2, %1, %0|%0, %1, %2}
4741    %vmovddup\t{%1, %0|%0, %1}
4742    movhpd\t{%2, %0|%0, %2}
4743    vmovhpd\t{%2, %1, %0|%0, %1, %2}
4744    %vmovlpd\t{%2, %H0|%H0, %2}"
4745   [(set_attr "isa" "noavx,avx,sse3,noavx,avx,*")
4746    (set_attr "type" "sselog,sselog,sselog,ssemov,ssemov,ssemov")
4747    (set_attr "prefix_data16" "*,*,*,1,*,1")
4748    (set_attr "prefix" "orig,vex,maybe_vex,orig,vex,maybe_vex")
4749    (set_attr "mode" "V2DF,V2DF,DF,V1DF,V1DF,V1DF")])
4750
4751 (define_split
4752   [(set (match_operand:V2DF 0 "memory_operand")
4753         (vec_select:V2DF
4754           (vec_concat:V4DF
4755             (match_operand:V2DF 1 "register_operand")
4756             (match_dup 1))
4757           (parallel [(const_int 0)
4758                      (const_int 2)])))]
4759   "TARGET_SSE3 && reload_completed"
4760   [(const_int 0)]
4761 {
4762   rtx low = gen_rtx_REG (DFmode, REGNO (operands[1]));
4763   emit_move_insn (adjust_address (operands[0], DFmode, 0), low);
4764   emit_move_insn (adjust_address (operands[0], DFmode, 8), low);
4765   DONE;
4766 })
4767
4768 (define_split
4769   [(set (match_operand:V2DF 0 "register_operand")
4770         (vec_select:V2DF
4771           (vec_concat:V4DF
4772             (match_operand:V2DF 1 "memory_operand")
4773             (match_dup 1))
4774           (parallel [(match_operand:SI 2 "const_0_to_1_operand")
4775                      (match_operand:SI 3 "const_int_operand")])))]
4776   "TARGET_SSE3 && INTVAL (operands[2]) + 2 == INTVAL (operands[3])"
4777   [(set (match_dup 0) (vec_duplicate:V2DF (match_dup 1)))]
4778 {
4779   operands[1] = adjust_address (operands[1], DFmode, INTVAL (operands[2]) * 8);
4780 })
4781
4782 (define_expand "avx_shufpd256"
4783   [(match_operand:V4DF 0 "register_operand")
4784    (match_operand:V4DF 1 "register_operand")
4785    (match_operand:V4DF 2 "nonimmediate_operand")
4786    (match_operand:SI 3 "const_int_operand")]
4787   "TARGET_AVX"
4788 {
4789   int mask = INTVAL (operands[3]);
4790   emit_insn (gen_avx_shufpd256_1 (operands[0], operands[1], operands[2],
4791                                    GEN_INT (mask & 1),
4792                                    GEN_INT (mask & 2 ? 5 : 4),
4793                                    GEN_INT (mask & 4 ? 3 : 2),
4794                                    GEN_INT (mask & 8 ? 7 : 6)));
4795   DONE;
4796 })
4797
4798 (define_insn "avx_shufpd256_1"
4799   [(set (match_operand:V4DF 0 "register_operand" "=x")
4800         (vec_select:V4DF
4801           (vec_concat:V8DF
4802             (match_operand:V4DF 1 "register_operand" "x")
4803             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
4804           (parallel [(match_operand 3 "const_0_to_1_operand")
4805                      (match_operand 4 "const_4_to_5_operand")
4806                      (match_operand 5 "const_2_to_3_operand")
4807                      (match_operand 6 "const_6_to_7_operand")])))]
4808   "TARGET_AVX"
4809 {
4810   int mask;
4811   mask = INTVAL (operands[3]);
4812   mask |= (INTVAL (operands[4]) - 4) << 1;
4813   mask |= (INTVAL (operands[5]) - 2) << 2;
4814   mask |= (INTVAL (operands[6]) - 6) << 3;
4815   operands[3] = GEN_INT (mask);
4816
4817   return "vshufpd\t{%3, %2, %1, %0|%0, %1, %2, %3}";
4818 }
4819   [(set_attr "type" "sseshuf")
4820    (set_attr "length_immediate" "1")
4821    (set_attr "prefix" "vex")
4822    (set_attr "mode" "V4DF")])
4823
4824 (define_expand "sse2_shufpd"
4825   [(match_operand:V2DF 0 "register_operand")
4826    (match_operand:V2DF 1 "register_operand")
4827    (match_operand:V2DF 2 "nonimmediate_operand")
4828    (match_operand:SI 3 "const_int_operand")]
4829   "TARGET_SSE2"
4830 {
4831   int mask = INTVAL (operands[3]);
4832   emit_insn (gen_sse2_shufpd_v2df (operands[0], operands[1], operands[2],
4833                                 GEN_INT (mask & 1),
4834                                 GEN_INT (mask & 2 ? 3 : 2)));
4835   DONE;
4836 })
4837
4838 ;; punpcklqdq and punpckhqdq are shorter than shufpd.
4839 (define_insn "avx2_interleave_highv4di"
4840   [(set (match_operand:V4DI 0 "register_operand" "=x")
4841         (vec_select:V4DI
4842           (vec_concat:V8DI
4843             (match_operand:V4DI 1 "register_operand" "x")
4844             (match_operand:V4DI 2 "nonimmediate_operand" "xm"))
4845           (parallel [(const_int 1)
4846                      (const_int 5)
4847                      (const_int 3)
4848                      (const_int 7)])))]
4849   "TARGET_AVX2"
4850   "vpunpckhqdq\t{%2, %1, %0|%0, %1, %2}"
4851   [(set_attr "type" "sselog")
4852    (set_attr "prefix" "vex")
4853    (set_attr "mode" "OI")])
4854
4855 (define_insn "vec_interleave_highv2di"
4856   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
4857         (vec_select:V2DI
4858           (vec_concat:V4DI
4859             (match_operand:V2DI 1 "register_operand" "0,x")
4860             (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm"))
4861           (parallel [(const_int 1)
4862                      (const_int 3)])))]
4863   "TARGET_SSE2"
4864   "@
4865    punpckhqdq\t{%2, %0|%0, %2}
4866    vpunpckhqdq\t{%2, %1, %0|%0, %1, %2}"
4867   [(set_attr "isa" "noavx,avx")
4868    (set_attr "type" "sselog")
4869    (set_attr "prefix_data16" "1,*")
4870    (set_attr "prefix" "orig,vex")
4871    (set_attr "mode" "TI")])
4872
4873 (define_insn "avx2_interleave_lowv4di"
4874   [(set (match_operand:V4DI 0 "register_operand" "=x")
4875         (vec_select:V4DI
4876           (vec_concat:V8DI
4877             (match_operand:V4DI 1 "register_operand" "x")
4878             (match_operand:V4DI 2 "nonimmediate_operand" "xm"))
4879           (parallel [(const_int 0)
4880                      (const_int 4)
4881                      (const_int 2)
4882                      (const_int 6)])))]
4883   "TARGET_AVX2"
4884   "vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}"
4885   [(set_attr "type" "sselog")
4886    (set_attr "prefix" "vex")
4887    (set_attr "mode" "OI")])
4888
4889 (define_insn "vec_interleave_lowv2di"
4890   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
4891         (vec_select:V2DI
4892           (vec_concat:V4DI
4893             (match_operand:V2DI 1 "register_operand" "0,x")
4894             (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm"))
4895           (parallel [(const_int 0)
4896                      (const_int 2)])))]
4897   "TARGET_SSE2"
4898   "@
4899    punpcklqdq\t{%2, %0|%0, %2}
4900    vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}"
4901   [(set_attr "isa" "noavx,avx")
4902    (set_attr "type" "sselog")
4903    (set_attr "prefix_data16" "1,*")
4904    (set_attr "prefix" "orig,vex")
4905    (set_attr "mode" "TI")])
4906
4907 (define_insn "sse2_shufpd_<mode>"
4908   [(set (match_operand:VI8F_128 0 "register_operand" "=x,x")
4909         (vec_select:VI8F_128
4910           (vec_concat:<ssedoublevecmode>
4911             (match_operand:VI8F_128 1 "register_operand" "0,x")
4912             (match_operand:VI8F_128 2 "nonimmediate_operand" "xm,xm"))
4913           (parallel [(match_operand 3 "const_0_to_1_operand")
4914                      (match_operand 4 "const_2_to_3_operand")])))]
4915   "TARGET_SSE2"
4916 {
4917   int mask;
4918   mask = INTVAL (operands[3]);
4919   mask |= (INTVAL (operands[4]) - 2) << 1;
4920   operands[3] = GEN_INT (mask);
4921
4922   switch (which_alternative)
4923     {
4924     case 0:
4925       return "shufpd\t{%3, %2, %0|%0, %2, %3}";
4926     case 1:
4927       return "vshufpd\t{%3, %2, %1, %0|%0, %1, %2, %3}";
4928     default:
4929       gcc_unreachable ();
4930     }
4931 }
4932   [(set_attr "isa" "noavx,avx")
4933    (set_attr "type" "sseshuf")
4934    (set_attr "length_immediate" "1")
4935    (set_attr "prefix" "orig,vex")
4936    (set_attr "mode" "V2DF")])
4937
4938 ;; Avoid combining registers from different units in a single alternative,
4939 ;; see comment above inline_secondary_memory_needed function in i386.c
4940 (define_insn "sse2_storehpd"
4941   [(set (match_operand:DF 0 "nonimmediate_operand"     "=m,x,x,x,*f,r")
4942         (vec_select:DF
4943           (match_operand:V2DF 1 "nonimmediate_operand" " x,0,x,o,o,o")
4944           (parallel [(const_int 1)])))]
4945   "TARGET_SSE2 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4946   "@
4947    %vmovhpd\t{%1, %0|%0, %1}
4948    unpckhpd\t%0, %0
4949    vunpckhpd\t{%d1, %0|%0, %d1}
4950    #
4951    #
4952    #"
4953   [(set_attr "isa" "*,noavx,avx,*,*,*")
4954    (set_attr "type" "ssemov,sselog1,sselog1,ssemov,fmov,imov")
4955    (set (attr "prefix_data16")
4956      (if_then_else
4957        (and (eq_attr "alternative" "0")
4958             (not (match_test "TARGET_AVX")))
4959        (const_string "1")
4960        (const_string "*")))
4961    (set_attr "prefix" "maybe_vex,orig,vex,*,*,*")
4962    (set_attr "mode" "V1DF,V1DF,V2DF,DF,DF,DF")])
4963
4964 (define_split
4965   [(set (match_operand:DF 0 "register_operand")
4966         (vec_select:DF
4967           (match_operand:V2DF 1 "memory_operand")
4968           (parallel [(const_int 1)])))]
4969   "TARGET_SSE2 && reload_completed"
4970   [(set (match_dup 0) (match_dup 1))]
4971   "operands[1] = adjust_address (operands[1], DFmode, 8);")
4972
4973 (define_insn "*vec_extractv2df_1_sse"
4974   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,x,x")
4975         (vec_select:DF
4976           (match_operand:V2DF 1 "nonimmediate_operand" "x,x,o")
4977           (parallel [(const_int 1)])))]
4978   "!TARGET_SSE2 && TARGET_SSE
4979    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4980   "@
4981    movhps\t{%1, %0|%0, %1}
4982    movhlps\t{%1, %0|%0, %1}
4983    movlps\t{%H1, %0|%0, %H1}"
4984   [(set_attr "type" "ssemov")
4985    (set_attr "mode" "V2SF,V4SF,V2SF")])
4986
4987 ;; Avoid combining registers from different units in a single alternative,
4988 ;; see comment above inline_secondary_memory_needed function in i386.c
4989 (define_insn "sse2_storelpd"
4990   [(set (match_operand:DF 0 "nonimmediate_operand"     "=m,x,x,*f,r")
4991         (vec_select:DF
4992           (match_operand:V2DF 1 "nonimmediate_operand" " x,x,m,m,m")
4993           (parallel [(const_int 0)])))]
4994   "TARGET_SSE2 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4995   "@
4996    %vmovlpd\t{%1, %0|%0, %1}
4997    #
4998    #
4999    #
5000    #"
5001   [(set_attr "type" "ssemov,ssemov,ssemov,fmov,imov")
5002    (set_attr "prefix_data16" "1,*,*,*,*")
5003    (set_attr "prefix" "maybe_vex")
5004    (set_attr "mode" "V1DF,DF,DF,DF,DF")])
5005
5006 (define_split
5007   [(set (match_operand:DF 0 "register_operand")
5008         (vec_select:DF
5009           (match_operand:V2DF 1 "nonimmediate_operand")
5010           (parallel [(const_int 0)])))]
5011   "TARGET_SSE2 && reload_completed"
5012   [(const_int 0)]
5013 {
5014   rtx op1 = operands[1];
5015   if (REG_P (op1))
5016     op1 = gen_rtx_REG (DFmode, REGNO (op1));
5017   else
5018     op1 = gen_lowpart (DFmode, op1);
5019   emit_move_insn (operands[0], op1);
5020   DONE;
5021 })
5022
5023 (define_insn "*vec_extractv2df_0_sse"
5024   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,x,x")
5025         (vec_select:DF
5026           (match_operand:V2DF 1 "nonimmediate_operand" "x,x,m")
5027           (parallel [(const_int 0)])))]
5028   "!TARGET_SSE2 && TARGET_SSE
5029    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
5030   "@
5031    movlps\t{%1, %0|%0, %1}
5032    movaps\t{%1, %0|%0, %1}
5033    movlps\t{%1, %0|%0, %1}"
5034   [(set_attr "type" "ssemov")
5035    (set_attr "mode" "V2SF,V4SF,V2SF")])
5036
5037 (define_expand "sse2_loadhpd_exp"
5038   [(set (match_operand:V2DF 0 "nonimmediate_operand")
5039         (vec_concat:V2DF
5040           (vec_select:DF
5041             (match_operand:V2DF 1 "nonimmediate_operand")
5042             (parallel [(const_int 0)]))
5043           (match_operand:DF 2 "nonimmediate_operand")))]
5044   "TARGET_SSE2"
5045 {
5046   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V2DFmode, operands);
5047
5048   emit_insn (gen_sse2_loadhpd (dst, operands[1], operands[2]));
5049
5050   /* Fix up the destination if needed.  */
5051   if (dst != operands[0])
5052     emit_move_insn (operands[0], dst);
5053
5054   DONE;
5055 })
5056
5057 ;; Avoid combining registers from different units in a single alternative,
5058 ;; see comment above inline_secondary_memory_needed function in i386.c
5059 (define_insn "sse2_loadhpd"
5060   [(set (match_operand:V2DF 0 "nonimmediate_operand"
5061           "=x,x,x,x,o,o ,o")
5062         (vec_concat:V2DF
5063           (vec_select:DF
5064             (match_operand:V2DF 1 "nonimmediate_operand"
5065           " 0,x,0,x,0,0 ,0")
5066             (parallel [(const_int 0)]))
5067           (match_operand:DF 2 "nonimmediate_operand"
5068           " m,m,x,x,x,*f,r")))]
5069   "TARGET_SSE2 && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
5070   "@
5071    movhpd\t{%2, %0|%0, %2}
5072    vmovhpd\t{%2, %1, %0|%0, %1, %2}
5073    unpcklpd\t{%2, %0|%0, %2}
5074    vunpcklpd\t{%2, %1, %0|%0, %1, %2}
5075    #
5076    #
5077    #"
5078   [(set_attr "isa" "noavx,avx,noavx,avx,*,*,*")
5079    (set_attr "type" "ssemov,ssemov,sselog,sselog,ssemov,fmov,imov")
5080    (set_attr "prefix_data16" "1,*,*,*,*,*,*")
5081    (set_attr "prefix" "orig,vex,orig,vex,*,*,*")
5082    (set_attr "mode" "V1DF,V1DF,V2DF,V2DF,DF,DF,DF")])
5083
5084 (define_split
5085   [(set (match_operand:V2DF 0 "memory_operand")
5086         (vec_concat:V2DF
5087           (vec_select:DF (match_dup 0) (parallel [(const_int 0)]))
5088           (match_operand:DF 1 "register_operand")))]
5089   "TARGET_SSE2 && reload_completed"
5090   [(set (match_dup 0) (match_dup 1))]
5091   "operands[0] = adjust_address (operands[0], DFmode, 8);")
5092
5093 (define_expand "sse2_loadlpd_exp"
5094   [(set (match_operand:V2DF 0 "nonimmediate_operand")
5095         (vec_concat:V2DF
5096           (match_operand:DF 2 "nonimmediate_operand")
5097           (vec_select:DF
5098             (match_operand:V2DF 1 "nonimmediate_operand")
5099             (parallel [(const_int 1)]))))]
5100   "TARGET_SSE2"
5101 {
5102   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V2DFmode, operands);
5103
5104   emit_insn (gen_sse2_loadlpd (dst, operands[1], operands[2]));
5105
5106   /* Fix up the destination if needed.  */
5107   if (dst != operands[0])
5108     emit_move_insn (operands[0], dst);
5109
5110   DONE;
5111 })
5112
5113 ;; Avoid combining registers from different units in a single alternative,
5114 ;; see comment above inline_secondary_memory_needed function in i386.c
5115 (define_insn "sse2_loadlpd"
5116   [(set (match_operand:V2DF 0 "nonimmediate_operand"
5117           "=x,x,x,x,x,x,x,x,m,m ,m")
5118         (vec_concat:V2DF
5119           (match_operand:DF 2 "nonimmediate_operand"
5120           " m,m,m,x,x,0,0,x,x,*f,r")
5121           (vec_select:DF
5122             (match_operand:V2DF 1 "vector_move_operand"
5123           " C,0,x,0,x,x,o,o,0,0 ,0")
5124             (parallel [(const_int 1)]))))]
5125   "TARGET_SSE2 && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
5126   "@
5127    %vmovsd\t{%2, %0|%0, %2}
5128    movlpd\t{%2, %0|%0, %2}
5129    vmovlpd\t{%2, %1, %0|%0, %1, %2}
5130    movsd\t{%2, %0|%0, %2}
5131    vmovsd\t{%2, %1, %0|%0, %1, %2}
5132    shufpd\t{$2, %1, %0|%0, %1, 2}
5133    movhpd\t{%H1, %0|%0, %H1}
5134    vmovhpd\t{%H1, %2, %0|%0, %2, %H1}
5135    #
5136    #
5137    #"
5138   [(set_attr "isa" "*,noavx,avx,noavx,avx,noavx,noavx,avx,*,*,*")
5139    (set (attr "type")
5140      (cond [(eq_attr "alternative" "5")
5141               (const_string "sselog")
5142             (eq_attr "alternative" "9")
5143               (const_string "fmov")
5144             (eq_attr "alternative" "10")
5145               (const_string "imov")
5146            ]
5147            (const_string "ssemov")))
5148    (set_attr "prefix_data16" "*,1,*,*,*,*,1,*,*,*,*")
5149    (set_attr "length_immediate" "*,*,*,*,*,1,*,*,*,*,*")
5150    (set_attr "prefix" "maybe_vex,orig,vex,orig,vex,orig,orig,vex,*,*,*")
5151    (set_attr "mode" "DF,V1DF,V1DF,V1DF,V1DF,V2DF,V1DF,V1DF,DF,DF,DF")])
5152
5153 (define_split
5154   [(set (match_operand:V2DF 0 "memory_operand")
5155         (vec_concat:V2DF
5156           (match_operand:DF 1 "register_operand")
5157           (vec_select:DF (match_dup 0) (parallel [(const_int 1)]))))]
5158   "TARGET_SSE2 && reload_completed"
5159   [(set (match_dup 0) (match_dup 1))]
5160   "operands[0] = adjust_address (operands[0], DFmode, 0);")
5161
5162 (define_insn "sse2_movsd"
5163   [(set (match_operand:V2DF 0 "nonimmediate_operand"   "=x,x,x,x,m,x,x,x,o")
5164         (vec_merge:V2DF
5165           (match_operand:V2DF 2 "nonimmediate_operand" " x,x,m,m,x,0,0,x,0")
5166           (match_operand:V2DF 1 "nonimmediate_operand" " 0,x,0,x,0,x,o,o,x")
5167           (const_int 1)))]
5168   "TARGET_SSE2"
5169   "@
5170    movsd\t{%2, %0|%0, %2}
5171    vmovsd\t{%2, %1, %0|%0, %1, %2}
5172    movlpd\t{%2, %0|%0, %2}
5173    vmovlpd\t{%2, %1, %0|%0, %1, %2}
5174    %vmovlpd\t{%2, %0|%0, %2}
5175    shufpd\t{$2, %1, %0|%0, %1, 2}
5176    movhps\t{%H1, %0|%0, %H1}
5177    vmovhps\t{%H1, %2, %0|%0, %2, %H1}
5178    %vmovhps\t{%1, %H0|%H0, %1}"
5179   [(set_attr "isa" "noavx,avx,noavx,avx,*,noavx,noavx,avx,*")
5180    (set (attr "type")
5181      (if_then_else
5182        (eq_attr "alternative" "5")
5183        (const_string "sselog")
5184        (const_string "ssemov")))
5185    (set (attr "prefix_data16")
5186      (if_then_else
5187        (and (eq_attr "alternative" "2,4")
5188             (not (match_test "TARGET_AVX")))
5189        (const_string "1")
5190        (const_string "*")))
5191    (set_attr "length_immediate" "*,*,*,*,*,1,*,*,*")
5192    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex,orig,orig,vex,maybe_vex")
5193    (set_attr "mode" "DF,DF,V1DF,V1DF,V1DF,V2DF,V1DF,V1DF,V1DF")])
5194
5195 (define_insn "vec_dupv2df"
5196   [(set (match_operand:V2DF 0 "register_operand"     "=x,x")
5197         (vec_duplicate:V2DF
5198           (match_operand:DF 1 "nonimmediate_operand" " 0,xm")))]
5199   "TARGET_SSE2"
5200   "@
5201    unpcklpd\t%0, %0
5202    %vmovddup\t{%1, %0|%0, %1}"
5203   [(set_attr "isa" "noavx,sse3")
5204    (set_attr "type" "sselog1")
5205    (set_attr "prefix" "orig,maybe_vex")
5206    (set_attr "mode" "V2DF,DF")])
5207
5208 (define_insn "*vec_concatv2df"
5209   [(set (match_operand:V2DF 0 "register_operand"     "=x,x,x,x,x,x,x,x")
5210         (vec_concat:V2DF
5211           (match_operand:DF 1 "nonimmediate_operand" " 0,x,m,0,x,m,0,0")
5212           (match_operand:DF 2 "vector_move_operand"  " x,x,1,m,m,C,x,m")))]
5213   "TARGET_SSE"
5214   "@
5215    unpcklpd\t{%2, %0|%0, %2}
5216    vunpcklpd\t{%2, %1, %0|%0, %1, %2}
5217    %vmovddup\t{%1, %0|%0, %1}
5218    movhpd\t{%2, %0|%0, %2}
5219    vmovhpd\t{%2, %1, %0|%0, %1, %2}
5220    %vmovsd\t{%1, %0|%0, %1}
5221    movlhps\t{%2, %0|%0, %2}
5222    movhps\t{%2, %0|%0, %2}"
5223   [(set_attr "isa" "sse2_noavx,avx,sse3,sse2_noavx,avx,sse2,noavx,noavx")
5224    (set (attr "type")
5225      (if_then_else
5226        (eq_attr "alternative" "0,1,2")
5227        (const_string "sselog")
5228        (const_string "ssemov")))
5229    (set_attr "prefix_data16" "*,*,*,1,*,*,*,*")
5230    (set_attr "prefix" "orig,vex,maybe_vex,orig,vex,maybe_vex,orig,orig")
5231    (set_attr "mode" "V2DF,V2DF,DF,V1DF,V1DF,DF,V4SF,V2SF")])
5232
5233 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5234 ;;
5235 ;; Parallel integral arithmetic
5236 ;;
5237 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5238
5239 (define_expand "neg<mode>2"
5240   [(set (match_operand:VI_AVX2 0 "register_operand")
5241         (minus:VI_AVX2
5242           (match_dup 2)
5243           (match_operand:VI_AVX2 1 "nonimmediate_operand")))]
5244   "TARGET_SSE2"
5245   "operands[2] = force_reg (<MODE>mode, CONST0_RTX (<MODE>mode));")
5246
5247 (define_expand "<plusminus_insn><mode>3"
5248   [(set (match_operand:VI_AVX2 0 "register_operand")
5249         (plusminus:VI_AVX2
5250           (match_operand:VI_AVX2 1 "nonimmediate_operand")
5251           (match_operand:VI_AVX2 2 "nonimmediate_operand")))]
5252   "TARGET_SSE2"
5253   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
5254
5255 (define_insn "*<plusminus_insn><mode>3"
5256   [(set (match_operand:VI_AVX2 0 "register_operand" "=x,x")
5257         (plusminus:VI_AVX2
5258           (match_operand:VI_AVX2 1 "nonimmediate_operand" "<comm>0,x")
5259           (match_operand:VI_AVX2 2 "nonimmediate_operand" "xm,xm")))]
5260   "TARGET_SSE2 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
5261   "@
5262    p<plusminus_mnemonic><ssemodesuffix>\t{%2, %0|%0, %2}
5263    vp<plusminus_mnemonic><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5264   [(set_attr "isa" "noavx,avx")
5265    (set_attr "type" "sseiadd")
5266    (set_attr "prefix_data16" "1,*")
5267    (set_attr "prefix" "orig,vex")
5268    (set_attr "mode" "<sseinsnmode>")])
5269
5270 (define_expand "<sse2_avx2>_<plusminus_insn><mode>3"
5271   [(set (match_operand:VI12_AVX2 0 "register_operand")
5272         (sat_plusminus:VI12_AVX2
5273           (match_operand:VI12_AVX2 1 "nonimmediate_operand")
5274           (match_operand:VI12_AVX2 2 "nonimmediate_operand")))]
5275   "TARGET_SSE2"
5276   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
5277
5278 (define_insn "*<sse2_avx2>_<plusminus_insn><mode>3"
5279   [(set (match_operand:VI12_AVX2 0 "register_operand" "=x,x")
5280         (sat_plusminus:VI12_AVX2
5281           (match_operand:VI12_AVX2 1 "nonimmediate_operand" "<comm>0,x")
5282           (match_operand:VI12_AVX2 2 "nonimmediate_operand" "xm,xm")))]
5283   "TARGET_SSE2 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
5284   "@
5285    p<plusminus_mnemonic><ssemodesuffix>\t{%2, %0|%0, %2}
5286    vp<plusminus_mnemonic><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5287   [(set_attr "isa" "noavx,avx")
5288    (set_attr "type" "sseiadd")
5289    (set_attr "prefix_data16" "1,*")
5290    (set_attr "prefix" "orig,vex")
5291    (set_attr "mode" "TI")])
5292
5293 (define_expand "mul<mode>3"
5294   [(set (match_operand:VI1_AVX2 0 "register_operand")
5295         (mult:VI1_AVX2 (match_operand:VI1_AVX2 1 "register_operand")
5296                        (match_operand:VI1_AVX2 2 "register_operand")))]
5297   "TARGET_SSE2"
5298 {
5299   ix86_expand_vecop_qihi (MULT, operands[0], operands[1], operands[2]);
5300   DONE;
5301 })
5302
5303 (define_expand "mul<mode>3"
5304   [(set (match_operand:VI2_AVX2 0 "register_operand")
5305         (mult:VI2_AVX2 (match_operand:VI2_AVX2 1 "nonimmediate_operand")
5306                        (match_operand:VI2_AVX2 2 "nonimmediate_operand")))]
5307   "TARGET_SSE2"
5308   "ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);")
5309
5310 (define_insn "*mul<mode>3"
5311   [(set (match_operand:VI2_AVX2 0 "register_operand" "=x,x")
5312         (mult:VI2_AVX2 (match_operand:VI2_AVX2 1 "nonimmediate_operand" "%0,x")
5313                        (match_operand:VI2_AVX2 2 "nonimmediate_operand" "xm,xm")))]
5314   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, <MODE>mode, operands)"
5315   "@
5316    pmullw\t{%2, %0|%0, %2}
5317    vpmullw\t{%2, %1, %0|%0, %1, %2}"
5318   [(set_attr "isa" "noavx,avx")
5319    (set_attr "type" "sseimul")
5320    (set_attr "prefix_data16" "1,*")
5321    (set_attr "prefix" "orig,vex")
5322    (set_attr "mode" "<sseinsnmode>")])
5323
5324 (define_expand "<s>mul<mode>3_highpart"
5325   [(set (match_operand:VI2_AVX2 0 "register_operand")
5326         (truncate:VI2_AVX2
5327           (lshiftrt:<ssedoublemode>
5328             (mult:<ssedoublemode>
5329               (any_extend:<ssedoublemode>
5330                 (match_operand:VI2_AVX2 1 "nonimmediate_operand"))
5331               (any_extend:<ssedoublemode>
5332                 (match_operand:VI2_AVX2 2 "nonimmediate_operand")))
5333             (const_int 16))))]
5334   "TARGET_SSE2"
5335   "ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);")
5336
5337 (define_insn "*<s>mul<mode>3_highpart"
5338   [(set (match_operand:VI2_AVX2 0 "register_operand" "=x,x")
5339         (truncate:VI2_AVX2
5340           (lshiftrt:<ssedoublemode>
5341             (mult:<ssedoublemode>
5342               (any_extend:<ssedoublemode>
5343                 (match_operand:VI2_AVX2 1 "nonimmediate_operand" "%0,x"))
5344               (any_extend:<ssedoublemode>
5345                 (match_operand:VI2_AVX2 2 "nonimmediate_operand" "xm,xm")))
5346             (const_int 16))))]
5347   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, <MODE>mode, operands)"
5348   "@
5349    pmulh<u>w\t{%2, %0|%0, %2}
5350    vpmulh<u>w\t{%2, %1, %0|%0, %1, %2}"
5351   [(set_attr "isa" "noavx,avx")
5352    (set_attr "type" "sseimul")
5353    (set_attr "prefix_data16" "1,*")
5354    (set_attr "prefix" "orig,vex")
5355    (set_attr "mode" "<sseinsnmode>")])
5356
5357 (define_expand "vec_widen_umult_even_v8si"
5358   [(set (match_operand:V4DI 0 "register_operand")
5359         (mult:V4DI
5360           (zero_extend:V4DI
5361             (vec_select:V4SI
5362               (match_operand:V8SI 1 "nonimmediate_operand")
5363               (parallel [(const_int 0) (const_int 2)
5364                          (const_int 4) (const_int 6)])))
5365           (zero_extend:V4DI
5366             (vec_select:V4SI
5367               (match_operand:V8SI 2 "nonimmediate_operand")
5368               (parallel [(const_int 0) (const_int 2)
5369                          (const_int 4) (const_int 6)])))))]
5370   "TARGET_AVX2"
5371   "ix86_fixup_binary_operands_no_copy (MULT, V8SImode, operands);")
5372
5373 (define_insn "*vec_widen_umult_even_v8si"
5374   [(set (match_operand:V4DI 0 "register_operand" "=x")
5375         (mult:V4DI
5376           (zero_extend:V4DI
5377             (vec_select:V4SI
5378               (match_operand:V8SI 1 "nonimmediate_operand" "%x")
5379               (parallel [(const_int 0) (const_int 2)
5380                          (const_int 4) (const_int 6)])))
5381           (zero_extend:V4DI
5382             (vec_select:V4SI
5383               (match_operand:V8SI 2 "nonimmediate_operand" "xm")
5384               (parallel [(const_int 0) (const_int 2)
5385                          (const_int 4) (const_int 6)])))))]
5386   "TARGET_AVX2 && ix86_binary_operator_ok (MULT, V8SImode, operands)"
5387   "vpmuludq\t{%2, %1, %0|%0, %1, %2}"
5388   [(set_attr "type" "sseimul")
5389    (set_attr "prefix" "vex")
5390    (set_attr "mode" "OI")])
5391
5392 (define_expand "vec_widen_umult_even_v4si"
5393   [(set (match_operand:V2DI 0 "register_operand")
5394         (mult:V2DI
5395           (zero_extend:V2DI
5396             (vec_select:V2SI
5397               (match_operand:V4SI 1 "nonimmediate_operand")
5398               (parallel [(const_int 0) (const_int 2)])))
5399           (zero_extend:V2DI
5400             (vec_select:V2SI
5401               (match_operand:V4SI 2 "nonimmediate_operand")
5402               (parallel [(const_int 0) (const_int 2)])))))]
5403   "TARGET_SSE2"
5404   "ix86_fixup_binary_operands_no_copy (MULT, V4SImode, operands);")
5405
5406 (define_insn "*vec_widen_umult_even_v4si"
5407   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
5408         (mult:V2DI
5409           (zero_extend:V2DI
5410             (vec_select:V2SI
5411               (match_operand:V4SI 1 "nonimmediate_operand" "%0,x")
5412               (parallel [(const_int 0) (const_int 2)])))
5413           (zero_extend:V2DI
5414             (vec_select:V2SI
5415               (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm")
5416               (parallel [(const_int 0) (const_int 2)])))))]
5417   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, V4SImode, operands)"
5418   "@
5419    pmuludq\t{%2, %0|%0, %2}
5420    vpmuludq\t{%2, %1, %0|%0, %1, %2}"
5421   [(set_attr "isa" "noavx,avx")
5422    (set_attr "type" "sseimul")
5423    (set_attr "prefix_data16" "1,*")
5424    (set_attr "prefix" "orig,vex")
5425    (set_attr "mode" "TI")])
5426
5427 (define_expand "vec_widen_smult_even_v8si"
5428   [(set (match_operand:V4DI 0 "register_operand")
5429         (mult:V4DI
5430           (sign_extend:V4DI
5431             (vec_select:V4SI
5432               (match_operand:V8SI 1 "nonimmediate_operand")
5433               (parallel [(const_int 0) (const_int 2)
5434                          (const_int 4) (const_int 6)])))
5435           (sign_extend:V4DI
5436             (vec_select:V4SI
5437               (match_operand:V8SI 2 "nonimmediate_operand")
5438               (parallel [(const_int 0) (const_int 2)
5439                          (const_int 4) (const_int 6)])))))]
5440   "TARGET_AVX2"
5441   "ix86_fixup_binary_operands_no_copy (MULT, V8SImode, operands);")
5442
5443 (define_insn "*vec_widen_smult_even_v8si"
5444   [(set (match_operand:V4DI 0 "register_operand" "=x")
5445         (mult:V4DI
5446           (sign_extend:V4DI
5447             (vec_select:V4SI
5448               (match_operand:V8SI 1 "nonimmediate_operand" "x")
5449               (parallel [(const_int 0) (const_int 2)
5450                          (const_int 4) (const_int 6)])))
5451           (sign_extend:V4DI
5452             (vec_select:V4SI
5453               (match_operand:V8SI 2 "nonimmediate_operand" "xm")
5454               (parallel [(const_int 0) (const_int 2)
5455                          (const_int 4) (const_int 6)])))))]
5456   "TARGET_AVX2 && ix86_binary_operator_ok (MULT, V8SImode, operands)"
5457   "vpmuldq\t{%2, %1, %0|%0, %1, %2}"
5458   [(set_attr "isa" "avx")
5459    (set_attr "type" "sseimul")
5460    (set_attr "prefix_extra" "1")
5461    (set_attr "prefix" "vex")
5462    (set_attr "mode" "OI")])
5463
5464 (define_expand "sse4_1_mulv2siv2di3"
5465   [(set (match_operand:V2DI 0 "register_operand")
5466         (mult:V2DI
5467           (sign_extend:V2DI
5468             (vec_select:V2SI
5469               (match_operand:V4SI 1 "nonimmediate_operand")
5470               (parallel [(const_int 0) (const_int 2)])))
5471           (sign_extend:V2DI
5472             (vec_select:V2SI
5473               (match_operand:V4SI 2 "nonimmediate_operand")
5474               (parallel [(const_int 0) (const_int 2)])))))]
5475   "TARGET_SSE4_1"
5476   "ix86_fixup_binary_operands_no_copy (MULT, V4SImode, operands);")
5477
5478 (define_insn "*sse4_1_mulv2siv2di3"
5479   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
5480         (mult:V2DI
5481           (sign_extend:V2DI
5482             (vec_select:V2SI
5483               (match_operand:V4SI 1 "nonimmediate_operand" "%0,x")
5484               (parallel [(const_int 0) (const_int 2)])))
5485           (sign_extend:V2DI
5486             (vec_select:V2SI
5487               (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm")
5488               (parallel [(const_int 0) (const_int 2)])))))]
5489   "TARGET_SSE4_1 && ix86_binary_operator_ok (MULT, V4SImode, operands)"
5490   "@
5491    pmuldq\t{%2, %0|%0, %2}
5492    vpmuldq\t{%2, %1, %0|%0, %1, %2}"
5493   [(set_attr "isa" "noavx,avx")
5494    (set_attr "type" "sseimul")
5495    (set_attr "prefix_data16" "1,*")
5496    (set_attr "prefix_extra" "1")
5497    (set_attr "prefix" "orig,vex")
5498    (set_attr "mode" "TI")])
5499
5500 (define_expand "avx2_pmaddwd"
5501   [(set (match_operand:V8SI 0 "register_operand")
5502         (plus:V8SI
5503           (mult:V8SI
5504             (sign_extend:V8SI
5505               (vec_select:V8HI
5506                 (match_operand:V16HI 1 "nonimmediate_operand")
5507                 (parallel [(const_int 0) (const_int 2)
5508                            (const_int 4) (const_int 6)
5509                            (const_int 8) (const_int 10)
5510                            (const_int 12) (const_int 14)])))
5511             (sign_extend:V8SI
5512               (vec_select:V8HI
5513                 (match_operand:V16HI 2 "nonimmediate_operand")
5514                 (parallel [(const_int 0) (const_int 2)
5515                            (const_int 4) (const_int 6)
5516                            (const_int 8) (const_int 10)
5517                            (const_int 12) (const_int 14)]))))
5518           (mult:V8SI
5519             (sign_extend:V8SI
5520               (vec_select:V8HI (match_dup 1)
5521                 (parallel [(const_int 1) (const_int 3)
5522                            (const_int 5) (const_int 7)
5523                            (const_int 9) (const_int 11)
5524                            (const_int 13) (const_int 15)])))
5525             (sign_extend:V8SI
5526               (vec_select:V8HI (match_dup 2)
5527                 (parallel [(const_int 1) (const_int 3)
5528                            (const_int 5) (const_int 7)
5529                            (const_int 9) (const_int 11)
5530                            (const_int 13) (const_int 15)]))))))]
5531   "TARGET_AVX2"
5532   "ix86_fixup_binary_operands_no_copy (MULT, V16HImode, operands);")
5533
5534 (define_insn "*avx2_pmaddwd"
5535   [(set (match_operand:V8SI 0 "register_operand" "=x")
5536         (plus:V8SI
5537           (mult:V8SI
5538             (sign_extend:V8SI
5539               (vec_select:V8HI
5540                 (match_operand:V16HI 1 "nonimmediate_operand" "%x")
5541                 (parallel [(const_int 0) (const_int 2)
5542                            (const_int 4) (const_int 6)
5543                            (const_int 8) (const_int 10)
5544                            (const_int 12) (const_int 14)])))
5545             (sign_extend:V8SI
5546               (vec_select:V8HI
5547                 (match_operand:V16HI 2 "nonimmediate_operand" "xm")
5548                 (parallel [(const_int 0) (const_int 2)
5549                            (const_int 4) (const_int 6)
5550                            (const_int 8) (const_int 10)
5551                            (const_int 12) (const_int 14)]))))
5552           (mult:V8SI
5553             (sign_extend:V8SI
5554               (vec_select:V8HI (match_dup 1)
5555                 (parallel [(const_int 1) (const_int 3)
5556                            (const_int 5) (const_int 7)
5557                            (const_int 9) (const_int 11)
5558                            (const_int 13) (const_int 15)])))
5559             (sign_extend:V8SI
5560               (vec_select:V8HI (match_dup 2)
5561                 (parallel [(const_int 1) (const_int 3)
5562                            (const_int 5) (const_int 7)
5563                            (const_int 9) (const_int 11)
5564                            (const_int 13) (const_int 15)]))))))]
5565   "TARGET_AVX2 && ix86_binary_operator_ok (MULT, V16HImode, operands)"
5566   "vpmaddwd\t{%2, %1, %0|%0, %1, %2}"
5567   [(set_attr "type" "sseiadd")
5568    (set_attr "prefix" "vex")
5569    (set_attr "mode" "OI")])
5570
5571 (define_expand "sse2_pmaddwd"
5572   [(set (match_operand:V4SI 0 "register_operand")
5573         (plus:V4SI
5574           (mult:V4SI
5575             (sign_extend:V4SI
5576               (vec_select:V4HI
5577                 (match_operand:V8HI 1 "nonimmediate_operand")
5578                 (parallel [(const_int 0) (const_int 2)
5579                            (const_int 4) (const_int 6)])))
5580             (sign_extend:V4SI
5581               (vec_select:V4HI
5582                 (match_operand:V8HI 2 "nonimmediate_operand")
5583                 (parallel [(const_int 0) (const_int 2)
5584                            (const_int 4) (const_int 6)]))))
5585           (mult:V4SI
5586             (sign_extend:V4SI
5587               (vec_select:V4HI (match_dup 1)
5588                 (parallel [(const_int 1) (const_int 3)
5589                            (const_int 5) (const_int 7)])))
5590             (sign_extend:V4SI
5591               (vec_select:V4HI (match_dup 2)
5592                 (parallel [(const_int 1) (const_int 3)
5593                            (const_int 5) (const_int 7)]))))))]
5594   "TARGET_SSE2"
5595   "ix86_fixup_binary_operands_no_copy (MULT, V8HImode, operands);")
5596
5597 (define_insn "*sse2_pmaddwd"
5598   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
5599         (plus:V4SI
5600           (mult:V4SI
5601             (sign_extend:V4SI
5602               (vec_select:V4HI
5603                 (match_operand:V8HI 1 "nonimmediate_operand" "%0,x")
5604                 (parallel [(const_int 0) (const_int 2)
5605                            (const_int 4) (const_int 6)])))
5606             (sign_extend:V4SI
5607               (vec_select:V4HI
5608                 (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
5609                 (parallel [(const_int 0) (const_int 2)
5610                            (const_int 4) (const_int 6)]))))
5611           (mult:V4SI
5612             (sign_extend:V4SI
5613               (vec_select:V4HI (match_dup 1)
5614                 (parallel [(const_int 1) (const_int 3)
5615                            (const_int 5) (const_int 7)])))
5616             (sign_extend:V4SI
5617               (vec_select:V4HI (match_dup 2)
5618                 (parallel [(const_int 1) (const_int 3)
5619                            (const_int 5) (const_int 7)]))))))]
5620   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, V8HImode, operands)"
5621   "@
5622    pmaddwd\t{%2, %0|%0, %2}
5623    vpmaddwd\t{%2, %1, %0|%0, %1, %2}"
5624   [(set_attr "isa" "noavx,avx")
5625    (set_attr "type" "sseiadd")
5626    (set_attr "atom_unit" "simul")
5627    (set_attr "prefix_data16" "1,*")
5628    (set_attr "prefix" "orig,vex")
5629    (set_attr "mode" "TI")])
5630
5631 (define_expand "mul<mode>3"
5632   [(set (match_operand:VI4_AVX2 0 "register_operand")
5633         (mult:VI4_AVX2
5634           (match_operand:VI4_AVX2 1 "nonimmediate_operand")
5635           (match_operand:VI4_AVX2 2 "nonimmediate_operand")))]
5636   "TARGET_SSE2"
5637 {
5638   if (TARGET_SSE4_1)
5639     {
5640       if (CONSTANT_P (operands[2]))
5641         operands[2] = validize_mem (force_const_mem (<MODE>mode, operands[2]));
5642       ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);
5643     }
5644   else
5645     {
5646       ix86_expand_sse2_mulv4si3 (operands[0], operands[1], operands[2]);
5647       DONE;
5648     }
5649 })
5650
5651 (define_insn "*<sse4_1_avx2>_mul<mode>3"
5652   [(set (match_operand:VI4_AVX2 0 "register_operand" "=x,x")
5653         (mult:VI4_AVX2
5654           (match_operand:VI4_AVX2 1 "nonimmediate_operand" "%0,x")
5655           (match_operand:VI4_AVX2 2 "nonimmediate_operand" "xm,xm")))]
5656   "TARGET_SSE4_1 && ix86_binary_operator_ok (MULT, <MODE>mode, operands)"
5657   "@
5658    pmulld\t{%2, %0|%0, %2}
5659    vpmulld\t{%2, %1, %0|%0, %1, %2}"
5660   [(set_attr "isa" "noavx,avx")
5661    (set_attr "type" "sseimul")
5662    (set_attr "prefix_extra" "1")
5663    (set_attr "prefix" "orig,vex")
5664    (set_attr "btver2_decode" "vector,vector")
5665    (set_attr "mode" "<sseinsnmode>")])
5666
5667 (define_expand "mul<mode>3"
5668   [(set (match_operand:VI8_AVX2 0 "register_operand")
5669         (mult:VI8_AVX2 (match_operand:VI8_AVX2 1 "register_operand")
5670                        (match_operand:VI8_AVX2 2 "register_operand")))]
5671   "TARGET_SSE2"
5672 {
5673   ix86_expand_sse2_mulvxdi3 (operands[0], operands[1], operands[2]);
5674   DONE;
5675 })
5676
5677 (define_expand "vec_widen_<s>mult_hi_<mode>"
5678   [(match_operand:<sseunpackmode> 0 "register_operand")
5679    (any_extend:<sseunpackmode>
5680      (match_operand:VI124_AVX2 1 "register_operand"))
5681    (match_operand:VI124_AVX2 2 "register_operand")]
5682   "TARGET_SSE2"
5683 {
5684   ix86_expand_mul_widen_hilo (operands[0], operands[1], operands[2],
5685                               <u_bool>, true);
5686   DONE;
5687 })
5688
5689 (define_expand "vec_widen_<s>mult_lo_<mode>"
5690   [(match_operand:<sseunpackmode> 0 "register_operand")
5691    (any_extend:<sseunpackmode>
5692      (match_operand:VI124_AVX2 1 "register_operand"))
5693    (match_operand:VI124_AVX2 2 "register_operand")]
5694   "TARGET_SSE2"
5695 {
5696   ix86_expand_mul_widen_hilo (operands[0], operands[1], operands[2],
5697                               <u_bool>, false);
5698   DONE;
5699 })
5700
5701 ;; Most widen_<s>mult_even_<mode> can be handled directly from other
5702 ;; named patterns, but signed V4SI needs special help for plain SSE2.
5703 (define_expand "vec_widen_smult_even_v4si"
5704   [(match_operand:V2DI 0 "register_operand")
5705    (match_operand:V4SI 1 "register_operand")
5706    (match_operand:V4SI 2 "register_operand")]
5707   "TARGET_SSE2"
5708 {
5709   ix86_expand_mul_widen_evenodd (operands[0], operands[1], operands[2],
5710                                  false, false);
5711   DONE;
5712 })
5713
5714 (define_expand "vec_widen_<s>mult_odd_<mode>"
5715   [(match_operand:<sseunpackmode> 0 "register_operand")
5716    (any_extend:<sseunpackmode>
5717      (match_operand:VI4_AVX2 1 "register_operand"))
5718    (match_operand:VI4_AVX2 2 "register_operand")]
5719   "TARGET_SSE2"
5720 {
5721   ix86_expand_mul_widen_evenodd (operands[0], operands[1], operands[2],
5722                                  <u_bool>, true);
5723   DONE;
5724 })
5725
5726 (define_expand "sdot_prod<mode>"
5727   [(match_operand:<sseunpackmode> 0 "register_operand")
5728    (match_operand:VI2_AVX2 1 "register_operand")
5729    (match_operand:VI2_AVX2 2 "register_operand")
5730    (match_operand:<sseunpackmode> 3 "register_operand")]
5731   "TARGET_SSE2"
5732 {
5733   rtx t = gen_reg_rtx (<sseunpackmode>mode);
5734   emit_insn (gen_<sse2_avx2>_pmaddwd (t, operands[1], operands[2]));
5735   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
5736                           gen_rtx_PLUS (<sseunpackmode>mode,
5737                                         operands[3], t)));
5738   DONE;
5739 })
5740
5741 ;; Normally we use widen_mul_even/odd, but combine can't quite get it all
5742 ;; back together when madd is available.
5743 (define_expand "sdot_prodv4si"
5744   [(match_operand:V2DI 0 "register_operand")
5745    (match_operand:V4SI 1 "register_operand")
5746    (match_operand:V4SI 2 "register_operand")
5747    (match_operand:V2DI 3 "register_operand")]
5748   "TARGET_XOP"
5749 {
5750   rtx t = gen_reg_rtx (V2DImode);
5751   emit_insn (gen_xop_pmacsdqh (t, operands[1], operands[2], operands[3]));
5752   emit_insn (gen_xop_pmacsdql (operands[0], operands[1], operands[2], t));
5753   DONE;
5754 })
5755
5756 (define_insn "ashr<mode>3"
5757   [(set (match_operand:VI24_AVX2 0 "register_operand" "=x,x")
5758         (ashiftrt:VI24_AVX2
5759           (match_operand:VI24_AVX2 1 "register_operand" "0,x")
5760           (match_operand:SI 2 "nonmemory_operand" "xN,xN")))]
5761   "TARGET_SSE2"
5762   "@
5763    psra<ssemodesuffix>\t{%2, %0|%0, %2}
5764    vpsra<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5765   [(set_attr "isa" "noavx,avx")
5766    (set_attr "type" "sseishft")
5767    (set (attr "length_immediate")
5768      (if_then_else (match_operand 2 "const_int_operand")
5769        (const_string "1")
5770        (const_string "0")))
5771    (set_attr "prefix_data16" "1,*")
5772    (set_attr "prefix" "orig,vex")
5773    (set_attr "mode" "<sseinsnmode>")])
5774
5775 (define_insn "<shift_insn><mode>3"
5776   [(set (match_operand:VI248_AVX2 0 "register_operand" "=x,x")
5777         (any_lshift:VI248_AVX2
5778           (match_operand:VI248_AVX2 1 "register_operand" "0,x")
5779           (match_operand:SI 2 "nonmemory_operand" "xN,xN")))]
5780   "TARGET_SSE2"
5781   "@
5782    p<vshift><ssemodesuffix>\t{%2, %0|%0, %2}
5783    vp<vshift><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5784   [(set_attr "isa" "noavx,avx")
5785    (set_attr "type" "sseishft")
5786    (set (attr "length_immediate")
5787      (if_then_else (match_operand 2 "const_int_operand")
5788        (const_string "1")
5789        (const_string "0")))
5790    (set_attr "prefix_data16" "1,*")
5791    (set_attr "prefix" "orig,vex")
5792    (set_attr "mode" "<sseinsnmode>")])
5793
5794 (define_expand "vec_shl_<mode>"
5795   [(set (match_operand:VI_128 0 "register_operand")
5796         (ashift:V1TI
5797          (match_operand:VI_128 1 "register_operand")
5798          (match_operand:SI 2 "const_0_to_255_mul_8_operand")))]
5799   "TARGET_SSE2"
5800 {
5801   operands[0] = gen_lowpart (V1TImode, operands[0]);
5802   operands[1] = gen_lowpart (V1TImode, operands[1]);
5803 })
5804
5805 (define_insn "<sse2_avx2>_ashl<mode>3"
5806   [(set (match_operand:VIMAX_AVX2 0 "register_operand" "=x,x")
5807         (ashift:VIMAX_AVX2
5808          (match_operand:VIMAX_AVX2 1 "register_operand" "0,x")
5809          (match_operand:SI 2 "const_0_to_255_mul_8_operand" "n,n")))]
5810   "TARGET_SSE2"
5811 {
5812   operands[2] = GEN_INT (INTVAL (operands[2]) / 8);
5813
5814   switch (which_alternative)
5815     {
5816     case 0:
5817       return "pslldq\t{%2, %0|%0, %2}";
5818     case 1:
5819       return "vpslldq\t{%2, %1, %0|%0, %1, %2}";
5820     default:
5821       gcc_unreachable ();
5822     }
5823 }
5824   [(set_attr "isa" "noavx,avx")
5825    (set_attr "type" "sseishft")
5826    (set_attr "length_immediate" "1")
5827    (set_attr "prefix_data16" "1,*")
5828    (set_attr "prefix" "orig,vex")
5829    (set_attr "mode" "<sseinsnmode>")])
5830
5831 (define_expand "vec_shr_<mode>"
5832   [(set (match_operand:VI_128 0 "register_operand")
5833         (lshiftrt:V1TI
5834          (match_operand:VI_128 1 "register_operand")
5835          (match_operand:SI 2 "const_0_to_255_mul_8_operand")))]
5836   "TARGET_SSE2"
5837 {
5838   operands[0] = gen_lowpart (V1TImode, operands[0]);
5839   operands[1] = gen_lowpart (V1TImode, operands[1]);
5840 })
5841
5842 (define_insn "<sse2_avx2>_lshr<mode>3"
5843   [(set (match_operand:VIMAX_AVX2 0 "register_operand" "=x,x")
5844         (lshiftrt:VIMAX_AVX2
5845          (match_operand:VIMAX_AVX2 1 "register_operand" "0,x")
5846          (match_operand:SI 2 "const_0_to_255_mul_8_operand" "n,n")))]
5847   "TARGET_SSE2"
5848 {
5849   operands[2] = GEN_INT (INTVAL (operands[2]) / 8);
5850
5851   switch (which_alternative)
5852     {
5853     case 0:
5854       return "psrldq\t{%2, %0|%0, %2}";
5855     case 1:
5856       return "vpsrldq\t{%2, %1, %0|%0, %1, %2}";
5857     default:
5858       gcc_unreachable ();
5859     }
5860 }
5861   [(set_attr "isa" "noavx,avx")
5862    (set_attr "type" "sseishft")
5863    (set_attr "length_immediate" "1")
5864    (set_attr "atom_unit" "sishuf")
5865    (set_attr "prefix_data16" "1,*")
5866    (set_attr "prefix" "orig,vex")
5867    (set_attr "mode" "<sseinsnmode>")])
5868
5869
5870 (define_expand "<code><mode>3"
5871   [(set (match_operand:VI124_256 0 "register_operand")
5872         (maxmin:VI124_256
5873           (match_operand:VI124_256 1 "nonimmediate_operand")
5874           (match_operand:VI124_256 2 "nonimmediate_operand")))]
5875   "TARGET_AVX2"
5876   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
5877
5878 (define_insn "*avx2_<code><mode>3"
5879   [(set (match_operand:VI124_256 0 "register_operand" "=x")
5880         (maxmin:VI124_256
5881           (match_operand:VI124_256 1 "nonimmediate_operand" "%x")
5882           (match_operand:VI124_256 2 "nonimmediate_operand" "xm")))]
5883   "TARGET_AVX2 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
5884   "vp<maxmin_int><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5885   [(set_attr "type" "sseiadd")
5886    (set_attr "prefix_extra" "1")
5887    (set_attr "prefix" "vex")
5888    (set_attr "mode" "OI")])
5889
5890 (define_expand "<code><mode>3"
5891   [(set (match_operand:VI8_AVX2 0 "register_operand")
5892         (maxmin:VI8_AVX2
5893           (match_operand:VI8_AVX2 1 "register_operand")
5894           (match_operand:VI8_AVX2 2 "register_operand")))]
5895   "TARGET_SSE4_2"
5896 {
5897   enum rtx_code code;
5898   rtx xops[6];
5899   bool ok;
5900
5901   xops[0] = operands[0];
5902
5903   if (<CODE> == SMAX || <CODE> == UMAX)
5904     {
5905       xops[1] = operands[1];
5906       xops[2] = operands[2];
5907     }
5908   else
5909     {
5910       xops[1] = operands[2];
5911       xops[2] = operands[1];
5912     }
5913
5914   code = (<CODE> == UMAX || <CODE> == UMIN) ? GTU : GT;
5915
5916   xops[3] = gen_rtx_fmt_ee (code, VOIDmode, operands[1], operands[2]);
5917   xops[4] = operands[1];
5918   xops[5] = operands[2];
5919
5920   ok = ix86_expand_int_vcond (xops);
5921   gcc_assert (ok);
5922   DONE;
5923 })
5924
5925 (define_expand "<code><mode>3"
5926   [(set (match_operand:VI124_128 0 "register_operand")
5927         (smaxmin:VI124_128
5928           (match_operand:VI124_128 1 "nonimmediate_operand")
5929           (match_operand:VI124_128 2 "nonimmediate_operand")))]
5930   "TARGET_SSE2"
5931 {
5932   if (TARGET_SSE4_1 || <MODE>mode == V8HImode)
5933     ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);
5934   else
5935     {
5936       rtx xops[6];
5937       bool ok;
5938
5939       xops[0] = operands[0];
5940       operands[1] = force_reg (<MODE>mode, operands[1]);
5941       operands[2] = force_reg (<MODE>mode, operands[2]);
5942
5943       if (<CODE> == SMAX)
5944         {
5945           xops[1] = operands[1];
5946           xops[2] = operands[2];
5947         }
5948       else
5949         {
5950           xops[1] = operands[2];
5951           xops[2] = operands[1];
5952         }
5953
5954       xops[3] = gen_rtx_GT (VOIDmode, operands[1], operands[2]);
5955       xops[4] = operands[1];
5956       xops[5] = operands[2];
5957
5958       ok = ix86_expand_int_vcond (xops);
5959       gcc_assert (ok);
5960       DONE;
5961     }
5962 })
5963
5964 (define_insn "*sse4_1_<code><mode>3"
5965   [(set (match_operand:VI14_128 0 "register_operand" "=x,x")
5966         (smaxmin:VI14_128
5967           (match_operand:VI14_128 1 "nonimmediate_operand" "%0,x")
5968           (match_operand:VI14_128 2 "nonimmediate_operand" "xm,xm")))]
5969   "TARGET_SSE4_1 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
5970   "@
5971    p<maxmin_int><ssemodesuffix>\t{%2, %0|%0, %2}
5972    vp<maxmin_int><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5973   [(set_attr "isa" "noavx,avx")
5974    (set_attr "type" "sseiadd")
5975    (set_attr "prefix_extra" "1,*")
5976    (set_attr "prefix" "orig,vex")
5977    (set_attr "mode" "TI")])
5978
5979 (define_insn "*<code>v8hi3"
5980   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
5981         (smaxmin:V8HI
5982           (match_operand:V8HI 1 "nonimmediate_operand" "%0,x")
5983           (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")))]
5984   "TARGET_SSE2 && ix86_binary_operator_ok (<CODE>, V8HImode, operands)"
5985   "@
5986    p<maxmin_int>w\t{%2, %0|%0, %2}
5987    vp<maxmin_int>w\t{%2, %1, %0|%0, %1, %2}"
5988   [(set_attr "isa" "noavx,avx")
5989    (set_attr "type" "sseiadd")
5990    (set_attr "prefix_data16" "1,*")
5991    (set_attr "prefix_extra" "*,1")
5992    (set_attr "prefix" "orig,vex")
5993    (set_attr "mode" "TI")])
5994
5995 (define_expand "<code><mode>3"
5996   [(set (match_operand:VI124_128 0 "register_operand")
5997         (umaxmin:VI124_128
5998           (match_operand:VI124_128 1 "nonimmediate_operand")
5999           (match_operand:VI124_128 2 "nonimmediate_operand")))]
6000   "TARGET_SSE2"
6001 {
6002   if (TARGET_SSE4_1 || <MODE>mode == V16QImode)
6003     ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);
6004   else if (<CODE> == UMAX && <MODE>mode == V8HImode)
6005     {
6006       rtx op0 = operands[0], op2 = operands[2], op3 = op0;
6007       operands[1] = force_reg (<MODE>mode, operands[1]);
6008       if (rtx_equal_p (op3, op2))
6009         op3 = gen_reg_rtx (V8HImode);
6010       emit_insn (gen_sse2_ussubv8hi3 (op3, operands[1], op2));
6011       emit_insn (gen_addv8hi3 (op0, op3, op2));
6012       DONE;
6013     }
6014   else
6015     {
6016       rtx xops[6];
6017       bool ok;
6018
6019       operands[1] = force_reg (<MODE>mode, operands[1]);
6020       operands[2] = force_reg (<MODE>mode, operands[2]);
6021
6022       xops[0] = operands[0];
6023
6024       if (<CODE> == UMAX)
6025         {
6026           xops[1] = operands[1];
6027           xops[2] = operands[2];
6028         }
6029       else
6030         {
6031           xops[1] = operands[2];
6032           xops[2] = operands[1];
6033         }
6034
6035       xops[3] = gen_rtx_GTU (VOIDmode, operands[1], operands[2]);
6036       xops[4] = operands[1];
6037       xops[5] = operands[2];
6038
6039       ok = ix86_expand_int_vcond (xops);
6040       gcc_assert (ok);
6041       DONE;
6042     }
6043 })
6044
6045 (define_insn "*sse4_1_<code><mode>3"
6046   [(set (match_operand:VI24_128 0 "register_operand" "=x,x")
6047         (umaxmin:VI24_128
6048           (match_operand:VI24_128 1 "nonimmediate_operand" "%0,x")
6049           (match_operand:VI24_128 2 "nonimmediate_operand" "xm,xm")))]
6050   "TARGET_SSE4_1 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
6051   "@
6052    p<maxmin_int><ssemodesuffix>\t{%2, %0|%0, %2}
6053    vp<maxmin_int><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6054   [(set_attr "isa" "noavx,avx")
6055    (set_attr "type" "sseiadd")
6056    (set_attr "prefix_extra" "1,*")
6057    (set_attr "prefix" "orig,vex")
6058    (set_attr "mode" "TI")])
6059
6060 (define_insn "*<code>v16qi3"
6061   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
6062         (umaxmin:V16QI
6063           (match_operand:V16QI 1 "nonimmediate_operand" "%0,x")
6064           (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm")))]
6065   "TARGET_SSE2 && ix86_binary_operator_ok (<CODE>, V16QImode, operands)"
6066   "@
6067    p<maxmin_int>b\t{%2, %0|%0, %2}
6068    vp<maxmin_int>b\t{%2, %1, %0|%0, %1, %2}"
6069   [(set_attr "isa" "noavx,avx")
6070    (set_attr "type" "sseiadd")
6071    (set_attr "prefix_data16" "1,*")
6072    (set_attr "prefix_extra" "*,1")
6073    (set_attr "prefix" "orig,vex")
6074    (set_attr "mode" "TI")])
6075
6076 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6077 ;;
6078 ;; Parallel integral comparisons
6079 ;;
6080 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6081
6082 (define_expand "avx2_eq<mode>3"
6083   [(set (match_operand:VI_256 0 "register_operand")
6084         (eq:VI_256
6085           (match_operand:VI_256 1 "nonimmediate_operand")
6086           (match_operand:VI_256 2 "nonimmediate_operand")))]
6087   "TARGET_AVX2"
6088   "ix86_fixup_binary_operands_no_copy (EQ, <MODE>mode, operands);")
6089
6090 (define_insn "*avx2_eq<mode>3"
6091   [(set (match_operand:VI_256 0 "register_operand" "=x")
6092         (eq:VI_256
6093           (match_operand:VI_256 1 "nonimmediate_operand" "%x")
6094           (match_operand:VI_256 2 "nonimmediate_operand" "xm")))]
6095   "TARGET_AVX2 && ix86_binary_operator_ok (EQ, <MODE>mode, operands)"
6096   "vpcmpeq<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6097   [(set_attr "type" "ssecmp")
6098    (set_attr "prefix_extra" "1")
6099    (set_attr "prefix" "vex")
6100    (set_attr "mode" "OI")])
6101
6102 (define_insn "*sse4_1_eqv2di3"
6103   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
6104         (eq:V2DI
6105           (match_operand:V2DI 1 "nonimmediate_operand" "%0,x")
6106           (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")))]
6107   "TARGET_SSE4_1 && ix86_binary_operator_ok (EQ, V2DImode, operands)"
6108   "@
6109    pcmpeqq\t{%2, %0|%0, %2}
6110    vpcmpeqq\t{%2, %1, %0|%0, %1, %2}"
6111   [(set_attr "isa" "noavx,avx")
6112    (set_attr "type" "ssecmp")
6113    (set_attr "prefix_extra" "1")
6114    (set_attr "prefix" "orig,vex")
6115    (set_attr "mode" "TI")])
6116
6117 (define_insn "*sse2_eq<mode>3"
6118   [(set (match_operand:VI124_128 0 "register_operand" "=x,x")
6119         (eq:VI124_128
6120           (match_operand:VI124_128 1 "nonimmediate_operand" "%0,x")
6121           (match_operand:VI124_128 2 "nonimmediate_operand" "xm,xm")))]
6122   "TARGET_SSE2 && !TARGET_XOP
6123    && ix86_binary_operator_ok (EQ, <MODE>mode, operands)"
6124   "@
6125    pcmpeq<ssemodesuffix>\t{%2, %0|%0, %2}
6126    vpcmpeq<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6127   [(set_attr "isa" "noavx,avx")
6128    (set_attr "type" "ssecmp")
6129    (set_attr "prefix_data16" "1,*")
6130    (set_attr "prefix" "orig,vex")
6131    (set_attr "mode" "TI")])
6132
6133 (define_expand "sse2_eq<mode>3"
6134   [(set (match_operand:VI124_128 0 "register_operand")
6135         (eq:VI124_128
6136           (match_operand:VI124_128 1 "nonimmediate_operand")
6137           (match_operand:VI124_128 2 "nonimmediate_operand")))]
6138   "TARGET_SSE2 && !TARGET_XOP "
6139   "ix86_fixup_binary_operands_no_copy (EQ, <MODE>mode, operands);")
6140
6141 (define_expand "sse4_1_eqv2di3"
6142   [(set (match_operand:V2DI 0 "register_operand")
6143         (eq:V2DI
6144           (match_operand:V2DI 1 "nonimmediate_operand")
6145           (match_operand:V2DI 2 "nonimmediate_operand")))]
6146   "TARGET_SSE4_1"
6147   "ix86_fixup_binary_operands_no_copy (EQ, V2DImode, operands);")
6148
6149 (define_insn "sse4_2_gtv2di3"
6150   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
6151         (gt:V2DI
6152           (match_operand:V2DI 1 "register_operand" "0,x")
6153           (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")))]
6154   "TARGET_SSE4_2"
6155   "@
6156    pcmpgtq\t{%2, %0|%0, %2}
6157    vpcmpgtq\t{%2, %1, %0|%0, %1, %2}"
6158   [(set_attr "isa" "noavx,avx")
6159    (set_attr "type" "ssecmp")
6160    (set_attr "prefix_extra" "1")
6161    (set_attr "prefix" "orig,vex")
6162    (set_attr "mode" "TI")])
6163
6164 (define_insn "avx2_gt<mode>3"
6165   [(set (match_operand:VI_256 0 "register_operand" "=x")
6166         (gt:VI_256
6167           (match_operand:VI_256 1 "register_operand" "x")
6168           (match_operand:VI_256 2 "nonimmediate_operand" "xm")))]
6169   "TARGET_AVX2"
6170   "vpcmpgt<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6171   [(set_attr "type" "ssecmp")
6172    (set_attr "prefix_extra" "1")
6173    (set_attr "prefix" "vex")
6174    (set_attr "mode" "OI")])
6175
6176 (define_insn "sse2_gt<mode>3"
6177   [(set (match_operand:VI124_128 0 "register_operand" "=x,x")
6178         (gt:VI124_128
6179           (match_operand:VI124_128 1 "register_operand" "0,x")
6180           (match_operand:VI124_128 2 "nonimmediate_operand" "xm,xm")))]
6181   "TARGET_SSE2 && !TARGET_XOP"
6182   "@
6183    pcmpgt<ssemodesuffix>\t{%2, %0|%0, %2}
6184    vpcmpgt<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6185   [(set_attr "isa" "noavx,avx")
6186    (set_attr "type" "ssecmp")
6187    (set_attr "prefix_data16" "1,*")
6188    (set_attr "prefix" "orig,vex")
6189    (set_attr "mode" "TI")])
6190
6191 (define_expand "vcond<V_256:mode><VI_256:mode>"
6192   [(set (match_operand:V_256 0 "register_operand")
6193         (if_then_else:V_256
6194           (match_operator 3 ""
6195             [(match_operand:VI_256 4 "nonimmediate_operand")
6196              (match_operand:VI_256 5 "general_operand")])
6197           (match_operand:V_256 1)
6198           (match_operand:V_256 2)))]
6199   "TARGET_AVX2
6200    && (GET_MODE_NUNITS (<V_256:MODE>mode)
6201        == GET_MODE_NUNITS (<VI_256:MODE>mode))"
6202 {
6203   bool ok = ix86_expand_int_vcond (operands);
6204   gcc_assert (ok);
6205   DONE;
6206 })
6207
6208 (define_expand "vcond<V_128:mode><VI124_128:mode>"
6209   [(set (match_operand:V_128 0 "register_operand")
6210         (if_then_else:V_128
6211           (match_operator 3 ""
6212             [(match_operand:VI124_128 4 "nonimmediate_operand")
6213              (match_operand:VI124_128 5 "general_operand")])
6214           (match_operand:V_128 1)
6215           (match_operand:V_128 2)))]
6216   "TARGET_SSE2
6217    && (GET_MODE_NUNITS (<V_128:MODE>mode)
6218        == GET_MODE_NUNITS (<VI124_128:MODE>mode))"
6219 {
6220   bool ok = ix86_expand_int_vcond (operands);
6221   gcc_assert (ok);
6222   DONE;
6223 })
6224
6225 (define_expand "vcond<VI8F_128:mode>v2di"
6226   [(set (match_operand:VI8F_128 0 "register_operand")
6227         (if_then_else:VI8F_128
6228           (match_operator 3 ""
6229             [(match_operand:V2DI 4 "nonimmediate_operand")
6230              (match_operand:V2DI 5 "general_operand")])
6231           (match_operand:VI8F_128 1)
6232           (match_operand:VI8F_128 2)))]
6233   "TARGET_SSE4_2"
6234 {
6235   bool ok = ix86_expand_int_vcond (operands);
6236   gcc_assert (ok);
6237   DONE;
6238 })
6239
6240 (define_expand "vcondu<V_256:mode><VI_256:mode>"
6241   [(set (match_operand:V_256 0 "register_operand")
6242         (if_then_else:V_256
6243           (match_operator 3 ""
6244             [(match_operand:VI_256 4 "nonimmediate_operand")
6245              (match_operand:VI_256 5 "nonimmediate_operand")])
6246           (match_operand:V_256 1 "general_operand")
6247           (match_operand:V_256 2 "general_operand")))]
6248   "TARGET_AVX2
6249    && (GET_MODE_NUNITS (<V_256:MODE>mode)
6250        == GET_MODE_NUNITS (<VI_256:MODE>mode))"
6251 {
6252   bool ok = ix86_expand_int_vcond (operands);
6253   gcc_assert (ok);
6254   DONE;
6255 })
6256
6257 (define_expand "vcondu<V_128:mode><VI124_128:mode>"
6258   [(set (match_operand:V_128 0 "register_operand")
6259         (if_then_else:V_128
6260           (match_operator 3 ""
6261             [(match_operand:VI124_128 4 "nonimmediate_operand")
6262              (match_operand:VI124_128 5 "nonimmediate_operand")])
6263           (match_operand:V_128 1 "general_operand")
6264           (match_operand:V_128 2 "general_operand")))]
6265   "TARGET_SSE2
6266    && (GET_MODE_NUNITS (<V_128:MODE>mode)
6267        == GET_MODE_NUNITS (<VI124_128:MODE>mode))"
6268 {
6269   bool ok = ix86_expand_int_vcond (operands);
6270   gcc_assert (ok);
6271   DONE;
6272 })
6273
6274 (define_expand "vcondu<VI8F_128:mode>v2di"
6275   [(set (match_operand:VI8F_128 0 "register_operand")
6276         (if_then_else:VI8F_128
6277           (match_operator 3 ""
6278             [(match_operand:V2DI 4 "nonimmediate_operand")
6279              (match_operand:V2DI 5 "nonimmediate_operand")])
6280           (match_operand:VI8F_128 1 "general_operand")
6281           (match_operand:VI8F_128 2 "general_operand")))]
6282   "TARGET_SSE4_2"
6283 {
6284   bool ok = ix86_expand_int_vcond (operands);
6285   gcc_assert (ok);
6286   DONE;
6287 })
6288
6289 (define_mode_iterator VEC_PERM_AVX2
6290   [V16QI V8HI V4SI V2DI V4SF V2DF
6291    (V32QI "TARGET_AVX2") (V16HI "TARGET_AVX2")
6292    (V8SI "TARGET_AVX2") (V4DI "TARGET_AVX2")
6293    (V8SF "TARGET_AVX2") (V4DF "TARGET_AVX2")])
6294
6295 (define_expand "vec_perm<mode>"
6296   [(match_operand:VEC_PERM_AVX2 0 "register_operand")
6297    (match_operand:VEC_PERM_AVX2 1 "register_operand")
6298    (match_operand:VEC_PERM_AVX2 2 "register_operand")
6299    (match_operand:<sseintvecmode> 3 "register_operand")]
6300   "TARGET_SSSE3 || TARGET_AVX || TARGET_XOP"
6301 {
6302   ix86_expand_vec_perm (operands);
6303   DONE;
6304 })
6305
6306 (define_mode_iterator VEC_PERM_CONST
6307   [(V4SF "TARGET_SSE") (V4SI "TARGET_SSE")
6308    (V2DF "TARGET_SSE") (V2DI "TARGET_SSE")
6309    (V16QI "TARGET_SSE2") (V8HI "TARGET_SSE2")
6310    (V8SF "TARGET_AVX") (V4DF "TARGET_AVX")
6311    (V8SI "TARGET_AVX") (V4DI "TARGET_AVX")
6312    (V32QI "TARGET_AVX2") (V16HI "TARGET_AVX2")])
6313
6314 (define_expand "vec_perm_const<mode>"
6315   [(match_operand:VEC_PERM_CONST 0 "register_operand")
6316    (match_operand:VEC_PERM_CONST 1 "register_operand")
6317    (match_operand:VEC_PERM_CONST 2 "register_operand")
6318    (match_operand:<sseintvecmode> 3)]
6319   ""
6320 {
6321   if (ix86_expand_vec_perm_const (operands))
6322     DONE;
6323   else
6324     FAIL;
6325 })
6326
6327 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6328 ;;
6329 ;; Parallel bitwise logical operations
6330 ;;
6331 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6332
6333 (define_expand "one_cmpl<mode>2"
6334   [(set (match_operand:VI 0 "register_operand")
6335         (xor:VI (match_operand:VI 1 "nonimmediate_operand")
6336                 (match_dup 2)))]
6337   "TARGET_SSE"
6338 {
6339   int i, n = GET_MODE_NUNITS (<MODE>mode);
6340   rtvec v = rtvec_alloc (n);
6341
6342   for (i = 0; i < n; ++i)
6343     RTVEC_ELT (v, i) = constm1_rtx;
6344
6345   operands[2] = force_reg (<MODE>mode, gen_rtx_CONST_VECTOR (<MODE>mode, v));
6346 })
6347
6348 (define_expand "<sse2_avx2>_andnot<mode>3"
6349   [(set (match_operand:VI_AVX2 0 "register_operand")
6350         (and:VI_AVX2
6351           (not:VI_AVX2 (match_operand:VI_AVX2 1 "register_operand"))
6352           (match_operand:VI_AVX2 2 "nonimmediate_operand")))]
6353   "TARGET_SSE2")
6354
6355 (define_insn "*andnot<mode>3"
6356   [(set (match_operand:VI 0 "register_operand" "=x,x")
6357         (and:VI
6358           (not:VI (match_operand:VI 1 "register_operand" "0,x"))
6359           (match_operand:VI 2 "nonimmediate_operand" "xm,xm")))]
6360   "TARGET_SSE"
6361 {
6362   static char buf[32];
6363   const char *ops;
6364   const char *tmp;
6365
6366   switch (get_attr_mode (insn))
6367     {
6368     case MODE_OI:
6369       gcc_assert (TARGET_AVX2);
6370     case MODE_TI:
6371       gcc_assert (TARGET_SSE2);
6372
6373       tmp = "pandn";
6374       break;
6375
6376    case MODE_V8SF:
6377       gcc_assert (TARGET_AVX);
6378    case MODE_V4SF:
6379       gcc_assert (TARGET_SSE);
6380
6381       tmp = "andnps";
6382       break;
6383
6384    default:
6385       gcc_unreachable ();
6386    }
6387
6388   switch (which_alternative)
6389     {
6390     case 0:
6391       ops = "%s\t{%%2, %%0|%%0, %%2}";
6392       break;
6393     case 1:
6394       ops = "v%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
6395       break;
6396     default:
6397       gcc_unreachable ();
6398     }
6399
6400   snprintf (buf, sizeof (buf), ops, tmp);
6401   return buf;
6402 }
6403   [(set_attr "isa" "noavx,avx")
6404    (set_attr "type" "sselog")
6405    (set (attr "prefix_data16")
6406      (if_then_else
6407        (and (eq_attr "alternative" "0")
6408             (eq_attr "mode" "TI"))
6409        (const_string "1")
6410        (const_string "*")))
6411    (set_attr "prefix" "orig,vex")
6412    (set (attr "mode")
6413         (cond [(match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
6414                  (const_string "<ssePSmode>")
6415                (match_test "TARGET_AVX2")
6416                  (const_string "<sseinsnmode>")
6417                (match_test "TARGET_AVX")
6418                  (if_then_else
6419                    (match_test "GET_MODE_SIZE (<MODE>mode) > 16")
6420                    (const_string "V8SF")
6421                    (const_string "<sseinsnmode>"))
6422                (ior (not (match_test "TARGET_SSE2"))
6423                     (match_test "optimize_function_for_size_p (cfun)"))
6424                  (const_string "V4SF")
6425               ]
6426               (const_string "<sseinsnmode>")))])
6427
6428 (define_expand "<code><mode>3"
6429   [(set (match_operand:VI 0 "register_operand")
6430         (any_logic:VI
6431           (match_operand:VI 1 "nonimmediate_or_const_vector_operand")
6432           (match_operand:VI 2 "nonimmediate_or_const_vector_operand")))]
6433   "TARGET_SSE"
6434 {
6435   ix86_expand_vector_logical_operator (<CODE>, <MODE>mode, operands);
6436   DONE;
6437 })
6438
6439 (define_insn "*<code><mode>3"
6440   [(set (match_operand:VI 0 "register_operand" "=x,x")
6441         (any_logic:VI
6442           (match_operand:VI 1 "nonimmediate_operand" "%0,x")
6443           (match_operand:VI 2 "nonimmediate_operand" "xm,xm")))]
6444   "TARGET_SSE
6445    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
6446 {
6447   static char buf[32];
6448   const char *ops;
6449   const char *tmp;
6450
6451   switch (get_attr_mode (insn))
6452     {
6453     case MODE_OI:
6454       gcc_assert (TARGET_AVX2);
6455     case MODE_TI:
6456       gcc_assert (TARGET_SSE2);
6457
6458       tmp = "p<logic>";
6459       break;
6460
6461    case MODE_V8SF:
6462       gcc_assert (TARGET_AVX);
6463    case MODE_V4SF:
6464       gcc_assert (TARGET_SSE);
6465
6466       tmp = "<logic>ps";
6467       break;
6468
6469    default:
6470       gcc_unreachable ();
6471    }
6472
6473   switch (which_alternative)
6474     {
6475     case 0:
6476       ops = "%s\t{%%2, %%0|%%0, %%2}";
6477       break;
6478     case 1:
6479       ops = "v%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
6480       break;
6481     default:
6482       gcc_unreachable ();
6483     }
6484
6485   snprintf (buf, sizeof (buf), ops, tmp);
6486   return buf;
6487 }
6488   [(set_attr "isa" "noavx,avx")
6489    (set_attr "type" "sselog")
6490    (set (attr "prefix_data16")
6491      (if_then_else
6492        (and (eq_attr "alternative" "0")
6493             (eq_attr "mode" "TI"))
6494        (const_string "1")
6495        (const_string "*")))
6496    (set_attr "prefix" "orig,vex")
6497    (set (attr "mode")
6498         (cond [(match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
6499                  (const_string "<ssePSmode>")
6500                (match_test "TARGET_AVX2")
6501                  (const_string "<sseinsnmode>")
6502                (match_test "TARGET_AVX")
6503                  (if_then_else
6504                    (match_test "GET_MODE_SIZE (<MODE>mode) > 16")
6505                    (const_string "V8SF")
6506                    (const_string "<sseinsnmode>"))
6507                (ior (not (match_test "TARGET_SSE2"))
6508                     (match_test "optimize_function_for_size_p (cfun)"))
6509                  (const_string "V4SF")
6510               ]
6511               (const_string "<sseinsnmode>")))])
6512
6513 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6514 ;;
6515 ;; Parallel integral element swizzling
6516 ;;
6517 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6518
6519 (define_expand "vec_pack_trunc_<mode>"
6520   [(match_operand:<ssepackmode> 0 "register_operand")
6521    (match_operand:VI248_AVX2 1 "register_operand")
6522    (match_operand:VI248_AVX2 2 "register_operand")]
6523   "TARGET_SSE2"
6524 {
6525   rtx op1 = gen_lowpart (<ssepackmode>mode, operands[1]);
6526   rtx op2 = gen_lowpart (<ssepackmode>mode, operands[2]);
6527   ix86_expand_vec_extract_even_odd (operands[0], op1, op2, 0);
6528   DONE;
6529 })
6530
6531 (define_insn "<sse2_avx2>_packsswb"
6532   [(set (match_operand:VI1_AVX2 0 "register_operand" "=x,x")
6533         (vec_concat:VI1_AVX2
6534           (ss_truncate:<ssehalfvecmode>
6535             (match_operand:<sseunpackmode> 1 "register_operand" "0,x"))
6536           (ss_truncate:<ssehalfvecmode>
6537             (match_operand:<sseunpackmode> 2 "nonimmediate_operand" "xm,xm"))))]
6538   "TARGET_SSE2"
6539   "@
6540    packsswb\t{%2, %0|%0, %2}
6541    vpacksswb\t{%2, %1, %0|%0, %1, %2}"
6542   [(set_attr "isa" "noavx,avx")
6543    (set_attr "type" "sselog")
6544    (set_attr "prefix_data16" "1,*")
6545    (set_attr "prefix" "orig,vex")
6546    (set_attr "mode" "<sseinsnmode>")])
6547
6548 (define_insn "<sse2_avx2>_packssdw"
6549   [(set (match_operand:VI2_AVX2 0 "register_operand" "=x,x")
6550         (vec_concat:VI2_AVX2
6551           (ss_truncate:<ssehalfvecmode>
6552             (match_operand:<sseunpackmode> 1 "register_operand" "0,x"))
6553           (ss_truncate:<ssehalfvecmode>
6554             (match_operand:<sseunpackmode> 2 "nonimmediate_operand" "xm,xm"))))]
6555   "TARGET_SSE2"
6556   "@
6557    packssdw\t{%2, %0|%0, %2}
6558    vpackssdw\t{%2, %1, %0|%0, %1, %2}"
6559   [(set_attr "isa" "noavx,avx")
6560    (set_attr "type" "sselog")
6561    (set_attr "prefix_data16" "1,*")
6562    (set_attr "prefix" "orig,vex")
6563    (set_attr "mode" "<sseinsnmode>")])
6564
6565 (define_insn "<sse2_avx2>_packuswb"
6566   [(set (match_operand:VI1_AVX2 0 "register_operand" "=x,x")
6567         (vec_concat:VI1_AVX2
6568           (us_truncate:<ssehalfvecmode>
6569             (match_operand:<sseunpackmode> 1 "register_operand" "0,x"))
6570           (us_truncate:<ssehalfvecmode>
6571             (match_operand:<sseunpackmode> 2 "nonimmediate_operand" "xm,xm"))))]
6572   "TARGET_SSE2"
6573   "@
6574    packuswb\t{%2, %0|%0, %2}
6575    vpackuswb\t{%2, %1, %0|%0, %1, %2}"
6576   [(set_attr "isa" "noavx,avx")
6577    (set_attr "type" "sselog")
6578    (set_attr "prefix_data16" "1,*")
6579    (set_attr "prefix" "orig,vex")
6580    (set_attr "mode" "<sseinsnmode>")])
6581
6582 (define_insn "avx2_interleave_highv32qi"
6583   [(set (match_operand:V32QI 0 "register_operand" "=x")
6584         (vec_select:V32QI
6585           (vec_concat:V64QI
6586             (match_operand:V32QI 1 "register_operand" "x")
6587             (match_operand:V32QI 2 "nonimmediate_operand" "xm"))
6588           (parallel [(const_int 8)  (const_int 40)
6589                      (const_int 9)  (const_int 41)
6590                      (const_int 10) (const_int 42)
6591                      (const_int 11) (const_int 43)
6592                      (const_int 12) (const_int 44)
6593                      (const_int 13) (const_int 45)
6594                      (const_int 14) (const_int 46)
6595                      (const_int 15) (const_int 47)
6596                      (const_int 24) (const_int 56)
6597                      (const_int 25) (const_int 57)
6598                      (const_int 26) (const_int 58)
6599                      (const_int 27) (const_int 59)
6600                      (const_int 28) (const_int 60)
6601                      (const_int 29) (const_int 61)
6602                      (const_int 30) (const_int 62)
6603                      (const_int 31) (const_int 63)])))]
6604   "TARGET_AVX2"
6605   "vpunpckhbw\t{%2, %1, %0|%0, %1, %2}"
6606   [(set_attr "type" "sselog")
6607    (set_attr "prefix" "vex")
6608    (set_attr "mode" "OI")])
6609
6610 (define_insn "vec_interleave_highv16qi"
6611   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
6612         (vec_select:V16QI
6613           (vec_concat:V32QI
6614             (match_operand:V16QI 1 "register_operand" "0,x")
6615             (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm"))
6616           (parallel [(const_int 8)  (const_int 24)
6617                      (const_int 9)  (const_int 25)
6618                      (const_int 10) (const_int 26)
6619                      (const_int 11) (const_int 27)
6620                      (const_int 12) (const_int 28)
6621                      (const_int 13) (const_int 29)
6622                      (const_int 14) (const_int 30)
6623                      (const_int 15) (const_int 31)])))]
6624   "TARGET_SSE2"
6625   "@
6626    punpckhbw\t{%2, %0|%0, %2}
6627    vpunpckhbw\t{%2, %1, %0|%0, %1, %2}"
6628   [(set_attr "isa" "noavx,avx")
6629    (set_attr "type" "sselog")
6630    (set_attr "prefix_data16" "1,*")
6631    (set_attr "prefix" "orig,vex")
6632    (set_attr "mode" "TI")])
6633
6634 (define_insn "avx2_interleave_lowv32qi"
6635   [(set (match_operand:V32QI 0 "register_operand" "=x")
6636         (vec_select:V32QI
6637           (vec_concat:V64QI
6638             (match_operand:V32QI 1 "register_operand" "x")
6639             (match_operand:V32QI 2 "nonimmediate_operand" "xm"))
6640           (parallel [(const_int 0) (const_int 32)
6641                      (const_int 1) (const_int 33)
6642                      (const_int 2) (const_int 34)
6643                      (const_int 3) (const_int 35)
6644                      (const_int 4) (const_int 36)
6645                      (const_int 5) (const_int 37)
6646                      (const_int 6) (const_int 38)
6647                      (const_int 7) (const_int 39)
6648                      (const_int 16) (const_int 48)
6649                      (const_int 17) (const_int 49)
6650                      (const_int 18) (const_int 50)
6651                      (const_int 19) (const_int 51)
6652                      (const_int 20) (const_int 52)
6653                      (const_int 21) (const_int 53)
6654                      (const_int 22) (const_int 54)
6655                      (const_int 23) (const_int 55)])))]
6656   "TARGET_AVX2"
6657   "vpunpcklbw\t{%2, %1, %0|%0, %1, %2}"
6658   [(set_attr "type" "sselog")
6659    (set_attr "prefix" "vex")
6660    (set_attr "mode" "OI")])
6661
6662 (define_insn "vec_interleave_lowv16qi"
6663   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
6664         (vec_select:V16QI
6665           (vec_concat:V32QI
6666             (match_operand:V16QI 1 "register_operand" "0,x")
6667             (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm"))
6668           (parallel [(const_int 0) (const_int 16)
6669                      (const_int 1) (const_int 17)
6670                      (const_int 2) (const_int 18)
6671                      (const_int 3) (const_int 19)
6672                      (const_int 4) (const_int 20)
6673                      (const_int 5) (const_int 21)
6674                      (const_int 6) (const_int 22)
6675                      (const_int 7) (const_int 23)])))]
6676   "TARGET_SSE2"
6677   "@
6678    punpcklbw\t{%2, %0|%0, %2}
6679    vpunpcklbw\t{%2, %1, %0|%0, %1, %2}"
6680   [(set_attr "isa" "noavx,avx")
6681    (set_attr "type" "sselog")
6682    (set_attr "prefix_data16" "1,*")
6683    (set_attr "prefix" "orig,vex")
6684    (set_attr "mode" "TI")])
6685
6686 (define_insn "avx2_interleave_highv16hi"
6687   [(set (match_operand:V16HI 0 "register_operand" "=x")
6688         (vec_select:V16HI
6689           (vec_concat:V32HI
6690             (match_operand:V16HI 1 "register_operand" "x")
6691             (match_operand:V16HI 2 "nonimmediate_operand" "xm"))
6692           (parallel [(const_int 4) (const_int 20)
6693                      (const_int 5) (const_int 21)
6694                      (const_int 6) (const_int 22)
6695                      (const_int 7) (const_int 23)
6696                      (const_int 12) (const_int 28)
6697                      (const_int 13) (const_int 29)
6698                      (const_int 14) (const_int 30)
6699                      (const_int 15) (const_int 31)])))]
6700   "TARGET_AVX2"
6701   "vpunpckhwd\t{%2, %1, %0|%0, %1, %2}"
6702   [(set_attr "type" "sselog")
6703    (set_attr "prefix" "vex")
6704    (set_attr "mode" "OI")])
6705
6706 (define_insn "vec_interleave_highv8hi"
6707   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
6708         (vec_select:V8HI
6709           (vec_concat:V16HI
6710             (match_operand:V8HI 1 "register_operand" "0,x")
6711             (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm"))
6712           (parallel [(const_int 4) (const_int 12)
6713                      (const_int 5) (const_int 13)
6714                      (const_int 6) (const_int 14)
6715                      (const_int 7) (const_int 15)])))]
6716   "TARGET_SSE2"
6717   "@
6718    punpckhwd\t{%2, %0|%0, %2}
6719    vpunpckhwd\t{%2, %1, %0|%0, %1, %2}"
6720   [(set_attr "isa" "noavx,avx")
6721    (set_attr "type" "sselog")
6722    (set_attr "prefix_data16" "1,*")
6723    (set_attr "prefix" "orig,vex")
6724    (set_attr "mode" "TI")])
6725
6726 (define_insn "avx2_interleave_lowv16hi"
6727   [(set (match_operand:V16HI 0 "register_operand" "=x")
6728         (vec_select:V16HI
6729           (vec_concat:V32HI
6730             (match_operand:V16HI 1 "register_operand" "x")
6731             (match_operand:V16HI 2 "nonimmediate_operand" "xm"))
6732           (parallel [(const_int 0) (const_int 16)
6733                      (const_int 1) (const_int 17)
6734                      (const_int 2) (const_int 18)
6735                      (const_int 3) (const_int 19)
6736                      (const_int 8) (const_int 24)
6737                      (const_int 9) (const_int 25)
6738                      (const_int 10) (const_int 26)
6739                      (const_int 11) (const_int 27)])))]
6740   "TARGET_AVX2"
6741   "vpunpcklwd\t{%2, %1, %0|%0, %1, %2}"
6742   [(set_attr "type" "sselog")
6743    (set_attr "prefix" "vex")
6744    (set_attr "mode" "OI")])
6745
6746 (define_insn "vec_interleave_lowv8hi"
6747   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
6748         (vec_select:V8HI
6749           (vec_concat:V16HI
6750             (match_operand:V8HI 1 "register_operand" "0,x")
6751             (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm"))
6752           (parallel [(const_int 0) (const_int 8)
6753                      (const_int 1) (const_int 9)
6754                      (const_int 2) (const_int 10)
6755                      (const_int 3) (const_int 11)])))]
6756   "TARGET_SSE2"
6757   "@
6758    punpcklwd\t{%2, %0|%0, %2}
6759    vpunpcklwd\t{%2, %1, %0|%0, %1, %2}"
6760   [(set_attr "isa" "noavx,avx")
6761    (set_attr "type" "sselog")
6762    (set_attr "prefix_data16" "1,*")
6763    (set_attr "prefix" "orig,vex")
6764    (set_attr "mode" "TI")])
6765
6766 (define_insn "avx2_interleave_highv8si"
6767   [(set (match_operand:V8SI 0 "register_operand" "=x")
6768         (vec_select:V8SI
6769           (vec_concat:V16SI
6770             (match_operand:V8SI 1 "register_operand" "x")
6771             (match_operand:V8SI 2 "nonimmediate_operand" "xm"))
6772           (parallel [(const_int 2) (const_int 10)
6773                      (const_int 3) (const_int 11)
6774                      (const_int 6) (const_int 14)
6775                      (const_int 7) (const_int 15)])))]
6776   "TARGET_AVX2"
6777   "vpunpckhdq\t{%2, %1, %0|%0, %1, %2}"
6778   [(set_attr "type" "sselog")
6779    (set_attr "prefix" "vex")
6780    (set_attr "mode" "OI")])
6781
6782 (define_insn "vec_interleave_highv4si"
6783   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
6784         (vec_select:V4SI
6785           (vec_concat:V8SI
6786             (match_operand:V4SI 1 "register_operand" "0,x")
6787             (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm"))
6788           (parallel [(const_int 2) (const_int 6)
6789                      (const_int 3) (const_int 7)])))]
6790   "TARGET_SSE2"
6791   "@
6792    punpckhdq\t{%2, %0|%0, %2}
6793    vpunpckhdq\t{%2, %1, %0|%0, %1, %2}"
6794   [(set_attr "isa" "noavx,avx")
6795    (set_attr "type" "sselog")
6796    (set_attr "prefix_data16" "1,*")
6797    (set_attr "prefix" "orig,vex")
6798    (set_attr "mode" "TI")])
6799
6800 (define_insn "avx2_interleave_lowv8si"
6801   [(set (match_operand:V8SI 0 "register_operand" "=x")
6802         (vec_select:V8SI
6803           (vec_concat:V16SI
6804             (match_operand:V8SI 1 "register_operand" "x")
6805             (match_operand:V8SI 2 "nonimmediate_operand" "xm"))
6806           (parallel [(const_int 0) (const_int 8)
6807                      (const_int 1) (const_int 9)
6808                      (const_int 4) (const_int 12)
6809                      (const_int 5) (const_int 13)])))]
6810   "TARGET_AVX2"
6811   "vpunpckldq\t{%2, %1, %0|%0, %1, %2}"
6812   [(set_attr "type" "sselog")
6813    (set_attr "prefix" "vex")
6814    (set_attr "mode" "OI")])
6815
6816 (define_insn "vec_interleave_lowv4si"
6817   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
6818         (vec_select:V4SI
6819           (vec_concat:V8SI
6820             (match_operand:V4SI 1 "register_operand" "0,x")
6821             (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm"))
6822           (parallel [(const_int 0) (const_int 4)
6823                      (const_int 1) (const_int 5)])))]
6824   "TARGET_SSE2"
6825   "@
6826    punpckldq\t{%2, %0|%0, %2}
6827    vpunpckldq\t{%2, %1, %0|%0, %1, %2}"
6828   [(set_attr "isa" "noavx,avx")
6829    (set_attr "type" "sselog")
6830    (set_attr "prefix_data16" "1,*")
6831    (set_attr "prefix" "orig,vex")
6832    (set_attr "mode" "TI")])
6833
6834 (define_expand "vec_interleave_high<mode>"
6835   [(match_operand:VI_256 0 "register_operand" "=x")
6836    (match_operand:VI_256 1 "register_operand" "x")
6837    (match_operand:VI_256 2 "nonimmediate_operand" "xm")]
6838  "TARGET_AVX2"
6839 {
6840   rtx t1 = gen_reg_rtx (<MODE>mode);
6841   rtx t2 = gen_reg_rtx (<MODE>mode);
6842   emit_insn (gen_avx2_interleave_low<mode> (t1, operands[1], operands[2]));
6843   emit_insn (gen_avx2_interleave_high<mode> (t2,  operands[1], operands[2]));
6844   emit_insn (gen_avx2_permv2ti
6845              (gen_lowpart (V4DImode, operands[0]),
6846               gen_lowpart (V4DImode, t1),
6847               gen_lowpart (V4DImode, t2), GEN_INT (1 + (3 << 4))));
6848   DONE;
6849 })
6850
6851 (define_expand "vec_interleave_low<mode>"
6852   [(match_operand:VI_256 0 "register_operand" "=x")
6853    (match_operand:VI_256 1 "register_operand" "x")
6854    (match_operand:VI_256 2 "nonimmediate_operand" "xm")]
6855  "TARGET_AVX2"
6856 {
6857   rtx t1 = gen_reg_rtx (<MODE>mode);
6858   rtx t2 = gen_reg_rtx (<MODE>mode);
6859   emit_insn (gen_avx2_interleave_low<mode> (t1, operands[1], operands[2]));
6860   emit_insn (gen_avx2_interleave_high<mode> (t2, operands[1], operands[2]));
6861   emit_insn (gen_avx2_permv2ti
6862              (gen_lowpart (V4DImode, operands[0]),
6863               gen_lowpart (V4DImode, t1),
6864               gen_lowpart (V4DImode, t2), GEN_INT (0 + (2 << 4))));
6865   DONE;
6866 })
6867
6868 ;; Modes handled by pinsr patterns.
6869 (define_mode_iterator PINSR_MODE
6870   [(V16QI "TARGET_SSE4_1") V8HI
6871    (V4SI "TARGET_SSE4_1")
6872    (V2DI "TARGET_SSE4_1 && TARGET_64BIT")])
6873
6874 (define_mode_attr sse2p4_1
6875   [(V16QI "sse4_1") (V8HI "sse2")
6876    (V4SI "sse4_1") (V2DI "sse4_1")])
6877
6878 ;; sse4_1_pinsrd must come before sse2_loadld since it is preferred.
6879 (define_insn "<sse2p4_1>_pinsr<ssemodesuffix>"
6880   [(set (match_operand:PINSR_MODE 0 "register_operand" "=x,x,x,x")
6881         (vec_merge:PINSR_MODE
6882           (vec_duplicate:PINSR_MODE
6883             (match_operand:<ssescalarmode> 2 "nonimmediate_operand" "r,m,r,m"))
6884           (match_operand:PINSR_MODE 1 "register_operand" "0,0,x,x")
6885           (match_operand:SI 3 "const_int_operand")))]
6886   "TARGET_SSE2
6887    && ((unsigned) exact_log2 (INTVAL (operands[3]))
6888        < GET_MODE_NUNITS (<MODE>mode))"
6889 {
6890   operands[3] = GEN_INT (exact_log2 (INTVAL (operands[3])));
6891
6892   switch (which_alternative)
6893     {
6894     case 0:
6895       if (GET_MODE_SIZE (<ssescalarmode>mode) < GET_MODE_SIZE (SImode))
6896         return "pinsr<ssemodesuffix>\t{%3, %k2, %0|%0, %k2, %3}";
6897       /* FALLTHRU */
6898     case 1:
6899       return "pinsr<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}";
6900     case 2:
6901       if (GET_MODE_SIZE (<ssescalarmode>mode) < GET_MODE_SIZE (SImode))
6902         return "vpinsr<ssemodesuffix>\t{%3, %k2, %1, %0|%0, %1, %k2, %3}";
6903       /* FALLTHRU */
6904     case 3:
6905       return "vpinsr<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}";
6906     default:
6907       gcc_unreachable ();
6908     }
6909 }
6910   [(set_attr "isa" "noavx,noavx,avx,avx")
6911    (set_attr "type" "sselog")
6912    (set (attr "prefix_rex")
6913      (if_then_else
6914        (and (not (match_test "TARGET_AVX"))
6915             (eq (const_string "<MODE>mode") (const_string "V2DImode")))
6916        (const_string "1")
6917        (const_string "*")))
6918    (set (attr "prefix_data16")
6919      (if_then_else
6920        (and (not (match_test "TARGET_AVX"))
6921             (eq (const_string "<MODE>mode") (const_string "V8HImode")))
6922        (const_string "1")
6923        (const_string "*")))
6924    (set (attr "prefix_extra")
6925      (if_then_else
6926        (and (not (match_test "TARGET_AVX"))
6927             (eq (const_string "<MODE>mode") (const_string "V8HImode")))
6928        (const_string "*")
6929        (const_string "1")))
6930    (set_attr "length_immediate" "1")
6931    (set_attr "prefix" "orig,orig,vex,vex")
6932    (set_attr "mode" "TI")])
6933
6934 (define_insn "*sse4_1_pextrb_<mode>"
6935   [(set (match_operand:SWI48 0 "register_operand" "=r")
6936         (zero_extend:SWI48
6937           (vec_select:QI
6938             (match_operand:V16QI 1 "register_operand" "x")
6939             (parallel [(match_operand:SI 2 "const_0_to_15_operand" "n")]))))]
6940   "TARGET_SSE4_1"
6941   "%vpextrb\t{%2, %1, %k0|%k0, %1, %2}"
6942   [(set_attr "type" "sselog")
6943    (set_attr "prefix_extra" "1")
6944    (set_attr "length_immediate" "1")
6945    (set_attr "prefix" "maybe_vex")
6946    (set_attr "mode" "TI")])
6947
6948 (define_insn "*sse4_1_pextrb_memory"
6949   [(set (match_operand:QI 0 "memory_operand" "=m")
6950         (vec_select:QI
6951           (match_operand:V16QI 1 "register_operand" "x")
6952           (parallel [(match_operand:SI 2 "const_0_to_15_operand" "n")])))]
6953   "TARGET_SSE4_1"
6954   "%vpextrb\t{%2, %1, %0|%0, %1, %2}"
6955   [(set_attr "type" "sselog")
6956    (set_attr "prefix_extra" "1")
6957    (set_attr "length_immediate" "1")
6958    (set_attr "prefix" "maybe_vex")
6959    (set_attr "mode" "TI")])
6960
6961 (define_insn "*sse2_pextrw_<mode>"
6962   [(set (match_operand:SWI48 0 "register_operand" "=r")
6963         (zero_extend:SWI48
6964           (vec_select:HI
6965             (match_operand:V8HI 1 "register_operand" "x")
6966             (parallel [(match_operand:SI 2 "const_0_to_7_operand" "n")]))))]
6967   "TARGET_SSE2"
6968   "%vpextrw\t{%2, %1, %k0|%k0, %1, %2}"
6969   [(set_attr "type" "sselog")
6970    (set_attr "prefix_data16" "1")
6971    (set_attr "length_immediate" "1")
6972    (set_attr "prefix" "maybe_vex")
6973    (set_attr "mode" "TI")])
6974
6975 (define_insn "*sse4_1_pextrw_memory"
6976   [(set (match_operand:HI 0 "memory_operand" "=m")
6977         (vec_select:HI
6978           (match_operand:V8HI 1 "register_operand" "x")
6979           (parallel [(match_operand:SI 2 "const_0_to_7_operand" "n")])))]
6980   "TARGET_SSE4_1"
6981   "%vpextrw\t{%2, %1, %0|%0, %1, %2}"
6982   [(set_attr "type" "sselog")
6983    (set_attr "prefix_extra" "1")
6984    (set_attr "length_immediate" "1")
6985    (set_attr "prefix" "maybe_vex")
6986    (set_attr "mode" "TI")])
6987
6988 (define_insn "*sse4_1_pextrd"
6989   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
6990         (vec_select:SI
6991           (match_operand:V4SI 1 "register_operand" "x")
6992           (parallel [(match_operand:SI 2 "const_0_to_3_operand" "n")])))]
6993   "TARGET_SSE4_1"
6994   "%vpextrd\t{%2, %1, %0|%0, %1, %2}"
6995   [(set_attr "type" "sselog")
6996    (set_attr "prefix_extra" "1")
6997    (set_attr "length_immediate" "1")
6998    (set_attr "prefix" "maybe_vex")
6999    (set_attr "mode" "TI")])
7000
7001 (define_insn "*sse4_1_pextrd_zext"
7002   [(set (match_operand:DI 0 "register_operand" "=r")
7003         (zero_extend:DI
7004           (vec_select:SI
7005             (match_operand:V4SI 1 "register_operand" "x")
7006             (parallel [(match_operand:SI 2 "const_0_to_3_operand" "n")]))))]
7007   "TARGET_64BIT && TARGET_SSE4_1"
7008   "%vpextrd\t{%2, %1, %k0|%k0, %1, %2}"
7009   [(set_attr "type" "sselog")
7010    (set_attr "prefix_extra" "1")
7011    (set_attr "length_immediate" "1")
7012    (set_attr "prefix" "maybe_vex")
7013    (set_attr "mode" "TI")])
7014
7015 ;; It must come before *vec_extractv2di_1_rex64 since it is preferred.
7016 (define_insn "*sse4_1_pextrq"
7017   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
7018         (vec_select:DI
7019           (match_operand:V2DI 1 "register_operand" "x")
7020           (parallel [(match_operand:SI 2 "const_0_to_1_operand" "n")])))]
7021   "TARGET_SSE4_1 && TARGET_64BIT"
7022   "%vpextrq\t{%2, %1, %0|%0, %1, %2}"
7023   [(set_attr "type" "sselog")
7024    (set_attr "prefix_rex" "1")
7025    (set_attr "prefix_extra" "1")
7026    (set_attr "length_immediate" "1")
7027    (set_attr "prefix" "maybe_vex")
7028    (set_attr "mode" "TI")])
7029
7030 (define_expand "avx2_pshufdv3"
7031   [(match_operand:V8SI 0 "register_operand")
7032    (match_operand:V8SI 1 "nonimmediate_operand")
7033    (match_operand:SI 2 "const_0_to_255_operand")]
7034   "TARGET_AVX2"
7035 {
7036   int mask = INTVAL (operands[2]);
7037   emit_insn (gen_avx2_pshufd_1 (operands[0], operands[1],
7038                                 GEN_INT ((mask >> 0) & 3),
7039                                 GEN_INT ((mask >> 2) & 3),
7040                                 GEN_INT ((mask >> 4) & 3),
7041                                 GEN_INT ((mask >> 6) & 3),
7042                                 GEN_INT (((mask >> 0) & 3) + 4),
7043                                 GEN_INT (((mask >> 2) & 3) + 4),
7044                                 GEN_INT (((mask >> 4) & 3) + 4),
7045                                 GEN_INT (((mask >> 6) & 3) + 4)));
7046   DONE;
7047 })
7048
7049 (define_insn "avx2_pshufd_1"
7050   [(set (match_operand:V8SI 0 "register_operand" "=x")
7051         (vec_select:V8SI
7052           (match_operand:V8SI 1 "nonimmediate_operand" "xm")
7053           (parallel [(match_operand 2 "const_0_to_3_operand")
7054                      (match_operand 3 "const_0_to_3_operand")
7055                      (match_operand 4 "const_0_to_3_operand")
7056                      (match_operand 5 "const_0_to_3_operand")
7057                      (match_operand 6 "const_4_to_7_operand")
7058                      (match_operand 7 "const_4_to_7_operand")
7059                      (match_operand 8 "const_4_to_7_operand")
7060                      (match_operand 9 "const_4_to_7_operand")])))]
7061   "TARGET_AVX2
7062    && INTVAL (operands[2]) + 4 == INTVAL (operands[6])
7063    && INTVAL (operands[3]) + 4 == INTVAL (operands[7])
7064    && INTVAL (operands[4]) + 4 == INTVAL (operands[8])
7065    && INTVAL (operands[5]) + 4 == INTVAL (operands[9])"
7066 {
7067   int mask = 0;
7068   mask |= INTVAL (operands[2]) << 0;
7069   mask |= INTVAL (operands[3]) << 2;
7070   mask |= INTVAL (operands[4]) << 4;
7071   mask |= INTVAL (operands[5]) << 6;
7072   operands[2] = GEN_INT (mask);
7073
7074   return "vpshufd\t{%2, %1, %0|%0, %1, %2}";
7075 }
7076   [(set_attr "type" "sselog1")
7077    (set_attr "prefix" "vex")
7078    (set_attr "length_immediate" "1")
7079    (set_attr "mode" "OI")])
7080
7081 (define_expand "sse2_pshufd"
7082   [(match_operand:V4SI 0 "register_operand")
7083    (match_operand:V4SI 1 "nonimmediate_operand")
7084    (match_operand:SI 2 "const_int_operand")]
7085   "TARGET_SSE2"
7086 {
7087   int mask = INTVAL (operands[2]);
7088   emit_insn (gen_sse2_pshufd_1 (operands[0], operands[1],
7089                                 GEN_INT ((mask >> 0) & 3),
7090                                 GEN_INT ((mask >> 2) & 3),
7091                                 GEN_INT ((mask >> 4) & 3),
7092                                 GEN_INT ((mask >> 6) & 3)));
7093   DONE;
7094 })
7095
7096 (define_insn "sse2_pshufd_1"
7097   [(set (match_operand:V4SI 0 "register_operand" "=x")
7098         (vec_select:V4SI
7099           (match_operand:V4SI 1 "nonimmediate_operand" "xm")
7100           (parallel [(match_operand 2 "const_0_to_3_operand")
7101                      (match_operand 3 "const_0_to_3_operand")
7102                      (match_operand 4 "const_0_to_3_operand")
7103                      (match_operand 5 "const_0_to_3_operand")])))]
7104   "TARGET_SSE2"
7105 {
7106   int mask = 0;
7107   mask |= INTVAL (operands[2]) << 0;
7108   mask |= INTVAL (operands[3]) << 2;
7109   mask |= INTVAL (operands[4]) << 4;
7110   mask |= INTVAL (operands[5]) << 6;
7111   operands[2] = GEN_INT (mask);
7112
7113   return "%vpshufd\t{%2, %1, %0|%0, %1, %2}";
7114 }
7115   [(set_attr "type" "sselog1")
7116    (set_attr "prefix_data16" "1")
7117    (set_attr "prefix" "maybe_vex")
7118    (set_attr "length_immediate" "1")
7119    (set_attr "mode" "TI")])
7120
7121 (define_expand "avx2_pshuflwv3"
7122   [(match_operand:V16HI 0 "register_operand")
7123    (match_operand:V16HI 1 "nonimmediate_operand")
7124    (match_operand:SI 2 "const_0_to_255_operand")]
7125   "TARGET_AVX2"
7126 {
7127   int mask = INTVAL (operands[2]);
7128   emit_insn (gen_avx2_pshuflw_1 (operands[0], operands[1],
7129                                  GEN_INT ((mask >> 0) & 3),
7130                                  GEN_INT ((mask >> 2) & 3),
7131                                  GEN_INT ((mask >> 4) & 3),
7132                                  GEN_INT ((mask >> 6) & 3),
7133                                  GEN_INT (((mask >> 0) & 3) + 8),
7134                                  GEN_INT (((mask >> 2) & 3) + 8),
7135                                  GEN_INT (((mask >> 4) & 3) + 8),
7136                                  GEN_INT (((mask >> 6) & 3) + 8)));
7137   DONE;
7138 })
7139
7140 (define_insn "avx2_pshuflw_1"
7141   [(set (match_operand:V16HI 0 "register_operand" "=x")
7142         (vec_select:V16HI
7143           (match_operand:V16HI 1 "nonimmediate_operand" "xm")
7144           (parallel [(match_operand 2 "const_0_to_3_operand")
7145                      (match_operand 3 "const_0_to_3_operand")
7146                      (match_operand 4 "const_0_to_3_operand")
7147                      (match_operand 5 "const_0_to_3_operand")
7148                      (const_int 4)
7149                      (const_int 5)
7150                      (const_int 6)
7151                      (const_int 7)
7152                      (match_operand 6 "const_8_to_11_operand")
7153                      (match_operand 7 "const_8_to_11_operand")
7154                      (match_operand 8 "const_8_to_11_operand")
7155                      (match_operand 9 "const_8_to_11_operand")
7156                      (const_int 12)
7157                      (const_int 13)
7158                      (const_int 14)
7159                      (const_int 15)])))]
7160   "TARGET_AVX2
7161    && INTVAL (operands[2]) + 8 == INTVAL (operands[6])
7162    && INTVAL (operands[3]) + 8 == INTVAL (operands[7])
7163    && INTVAL (operands[4]) + 8 == INTVAL (operands[8])
7164    && INTVAL (operands[5]) + 8 == INTVAL (operands[9])"
7165 {
7166   int mask = 0;
7167   mask |= INTVAL (operands[2]) << 0;
7168   mask |= INTVAL (operands[3]) << 2;
7169   mask |= INTVAL (operands[4]) << 4;
7170   mask |= INTVAL (operands[5]) << 6;
7171   operands[2] = GEN_INT (mask);
7172
7173   return "vpshuflw\t{%2, %1, %0|%0, %1, %2}";
7174 }
7175   [(set_attr "type" "sselog")
7176    (set_attr "prefix" "vex")
7177    (set_attr "length_immediate" "1")
7178    (set_attr "mode" "OI")])
7179
7180 (define_expand "sse2_pshuflw"
7181   [(match_operand:V8HI 0 "register_operand")
7182    (match_operand:V8HI 1 "nonimmediate_operand")
7183    (match_operand:SI 2 "const_int_operand")]
7184   "TARGET_SSE2"
7185 {
7186   int mask = INTVAL (operands[2]);
7187   emit_insn (gen_sse2_pshuflw_1 (operands[0], operands[1],
7188                                  GEN_INT ((mask >> 0) & 3),
7189                                  GEN_INT ((mask >> 2) & 3),
7190                                  GEN_INT ((mask >> 4) & 3),
7191                                  GEN_INT ((mask >> 6) & 3)));
7192   DONE;
7193 })
7194
7195 (define_insn "sse2_pshuflw_1"
7196   [(set (match_operand:V8HI 0 "register_operand" "=x")
7197         (vec_select:V8HI
7198           (match_operand:V8HI 1 "nonimmediate_operand" "xm")
7199           (parallel [(match_operand 2 "const_0_to_3_operand")
7200                      (match_operand 3 "const_0_to_3_operand")
7201                      (match_operand 4 "const_0_to_3_operand")
7202                      (match_operand 5 "const_0_to_3_operand")
7203                      (const_int 4)
7204                      (const_int 5)
7205                      (const_int 6)
7206                      (const_int 7)])))]
7207   "TARGET_SSE2"
7208 {
7209   int mask = 0;
7210   mask |= INTVAL (operands[2]) << 0;
7211   mask |= INTVAL (operands[3]) << 2;
7212   mask |= INTVAL (operands[4]) << 4;
7213   mask |= INTVAL (operands[5]) << 6;
7214   operands[2] = GEN_INT (mask);
7215
7216   return "%vpshuflw\t{%2, %1, %0|%0, %1, %2}";
7217 }
7218   [(set_attr "type" "sselog")
7219    (set_attr "prefix_data16" "0")
7220    (set_attr "prefix_rep" "1")
7221    (set_attr "prefix" "maybe_vex")
7222    (set_attr "length_immediate" "1")
7223    (set_attr "mode" "TI")])
7224
7225 (define_expand "avx2_pshufhwv3"
7226   [(match_operand:V16HI 0 "register_operand")
7227    (match_operand:V16HI 1 "nonimmediate_operand")
7228    (match_operand:SI 2 "const_0_to_255_operand")]
7229   "TARGET_AVX2"
7230 {
7231   int mask = INTVAL (operands[2]);
7232   emit_insn (gen_avx2_pshufhw_1 (operands[0], operands[1],
7233                                  GEN_INT (((mask >> 0) & 3) + 4),
7234                                  GEN_INT (((mask >> 2) & 3) + 4),
7235                                  GEN_INT (((mask >> 4) & 3) + 4),
7236                                  GEN_INT (((mask >> 6) & 3) + 4),
7237                                  GEN_INT (((mask >> 0) & 3) + 12),
7238                                  GEN_INT (((mask >> 2) & 3) + 12),
7239                                  GEN_INT (((mask >> 4) & 3) + 12),
7240                                  GEN_INT (((mask >> 6) & 3) + 12)));
7241   DONE;
7242 })
7243
7244 (define_insn "avx2_pshufhw_1"
7245   [(set (match_operand:V16HI 0 "register_operand" "=x")
7246         (vec_select:V16HI
7247           (match_operand:V16HI 1 "nonimmediate_operand" "xm")
7248           (parallel [(const_int 0)
7249                      (const_int 1)
7250                      (const_int 2)
7251                      (const_int 3)
7252                      (match_operand 2 "const_4_to_7_operand")
7253                      (match_operand 3 "const_4_to_7_operand")
7254                      (match_operand 4 "const_4_to_7_operand")
7255                      (match_operand 5 "const_4_to_7_operand")
7256                      (const_int 8)
7257                      (const_int 9)
7258                      (const_int 10)
7259                      (const_int 11)
7260                      (match_operand 6 "const_12_to_15_operand")
7261                      (match_operand 7 "const_12_to_15_operand")
7262                      (match_operand 8 "const_12_to_15_operand")
7263                      (match_operand 9 "const_12_to_15_operand")])))]
7264   "TARGET_AVX2
7265    && INTVAL (operands[2]) + 8 == INTVAL (operands[6])
7266    && INTVAL (operands[3]) + 8 == INTVAL (operands[7])
7267    && INTVAL (operands[4]) + 8 == INTVAL (operands[8])
7268    && INTVAL (operands[5]) + 8 == INTVAL (operands[9])"
7269 {
7270   int mask = 0;
7271   mask |= (INTVAL (operands[2]) - 4) << 0;
7272   mask |= (INTVAL (operands[3]) - 4) << 2;
7273   mask |= (INTVAL (operands[4]) - 4) << 4;
7274   mask |= (INTVAL (operands[5]) - 4) << 6;
7275   operands[2] = GEN_INT (mask);
7276
7277   return "vpshufhw\t{%2, %1, %0|%0, %1, %2}";
7278 }
7279   [(set_attr "type" "sselog")
7280    (set_attr "prefix" "vex")
7281    (set_attr "length_immediate" "1")
7282    (set_attr "mode" "OI")])
7283
7284 (define_expand "sse2_pshufhw"
7285   [(match_operand:V8HI 0 "register_operand")
7286    (match_operand:V8HI 1 "nonimmediate_operand")
7287    (match_operand:SI 2 "const_int_operand")]
7288   "TARGET_SSE2"
7289 {
7290   int mask = INTVAL (operands[2]);
7291   emit_insn (gen_sse2_pshufhw_1 (operands[0], operands[1],
7292                                  GEN_INT (((mask >> 0) & 3) + 4),
7293                                  GEN_INT (((mask >> 2) & 3) + 4),
7294                                  GEN_INT (((mask >> 4) & 3) + 4),
7295                                  GEN_INT (((mask >> 6) & 3) + 4)));
7296   DONE;
7297 })
7298
7299 (define_insn "sse2_pshufhw_1"
7300   [(set (match_operand:V8HI 0 "register_operand" "=x")
7301         (vec_select:V8HI
7302           (match_operand:V8HI 1 "nonimmediate_operand" "xm")
7303           (parallel [(const_int 0)
7304                      (const_int 1)
7305                      (const_int 2)
7306                      (const_int 3)
7307                      (match_operand 2 "const_4_to_7_operand")
7308                      (match_operand 3 "const_4_to_7_operand")
7309                      (match_operand 4 "const_4_to_7_operand")
7310                      (match_operand 5 "const_4_to_7_operand")])))]
7311   "TARGET_SSE2"
7312 {
7313   int mask = 0;
7314   mask |= (INTVAL (operands[2]) - 4) << 0;
7315   mask |= (INTVAL (operands[3]) - 4) << 2;
7316   mask |= (INTVAL (operands[4]) - 4) << 4;
7317   mask |= (INTVAL (operands[5]) - 4) << 6;
7318   operands[2] = GEN_INT (mask);
7319
7320   return "%vpshufhw\t{%2, %1, %0|%0, %1, %2}";
7321 }
7322   [(set_attr "type" "sselog")
7323    (set_attr "prefix_rep" "1")
7324    (set_attr "prefix_data16" "0")
7325    (set_attr "prefix" "maybe_vex")
7326    (set_attr "length_immediate" "1")
7327    (set_attr "mode" "TI")])
7328
7329 (define_expand "sse2_loadd"
7330   [(set (match_operand:V4SI 0 "register_operand")
7331         (vec_merge:V4SI
7332           (vec_duplicate:V4SI
7333             (match_operand:SI 1 "nonimmediate_operand"))
7334           (match_dup 2)
7335           (const_int 1)))]
7336   "TARGET_SSE"
7337   "operands[2] = CONST0_RTX (V4SImode);")
7338
7339 (define_insn "sse2_loadld"
7340   [(set (match_operand:V4SI 0 "register_operand"       "=x,Yi,x,x,x")
7341         (vec_merge:V4SI
7342           (vec_duplicate:V4SI
7343             (match_operand:SI 2 "nonimmediate_operand" "m ,r ,m,x,x"))
7344           (match_operand:V4SI 1 "reg_or_0_operand"     "C ,C ,C,0,x")
7345           (const_int 1)))]
7346   "TARGET_SSE"
7347   "@
7348    %vmovd\t{%2, %0|%0, %2}
7349    %vmovd\t{%2, %0|%0, %2}
7350    movss\t{%2, %0|%0, %2}
7351    movss\t{%2, %0|%0, %2}
7352    vmovss\t{%2, %1, %0|%0, %1, %2}"
7353   [(set_attr "isa" "sse2,*,noavx,noavx,avx")
7354    (set_attr "type" "ssemov")
7355    (set_attr "prefix" "maybe_vex,maybe_vex,orig,orig,vex")
7356    (set_attr "mode" "TI,TI,V4SF,SF,SF")])
7357
7358 (define_insn_and_split "sse2_stored"
7359   [(set (match_operand:SI 0 "nonimmediate_operand" "=xm,r")
7360         (vec_select:SI
7361           (match_operand:V4SI 1 "register_operand" "x,Yi")
7362           (parallel [(const_int 0)])))]
7363   "TARGET_SSE"
7364   "#"
7365   "&& reload_completed
7366    && (TARGET_INTER_UNIT_MOVES
7367        || MEM_P (operands [0])
7368        || !GENERAL_REGNO_P (true_regnum (operands [0])))"
7369   [(set (match_dup 0) (match_dup 1))]
7370   "operands[1] = gen_rtx_REG (SImode, REGNO (operands[1]));")
7371
7372 (define_insn_and_split "*vec_ext_v4si_mem"
7373   [(set (match_operand:SI 0 "register_operand" "=r")
7374         (vec_select:SI
7375           (match_operand:V4SI 1 "memory_operand" "o")
7376           (parallel [(match_operand 2 "const_0_to_3_operand")])))]
7377   ""
7378   "#"
7379   "reload_completed"
7380   [(const_int 0)]
7381 {
7382   int i = INTVAL (operands[2]);
7383
7384   emit_move_insn (operands[0], adjust_address (operands[1], SImode, i*4));
7385   DONE;
7386 })
7387
7388 (define_expand "sse_storeq"
7389   [(set (match_operand:DI 0 "nonimmediate_operand")
7390         (vec_select:DI
7391           (match_operand:V2DI 1 "register_operand")
7392           (parallel [(const_int 0)])))]
7393   "TARGET_SSE")
7394
7395 (define_insn "*sse2_storeq_rex64"
7396   [(set (match_operand:DI 0 "nonimmediate_operand" "=xm,*r,r")
7397         (vec_select:DI
7398           (match_operand:V2DI 1 "nonimmediate_operand" "x,Yi,o")
7399           (parallel [(const_int 0)])))]
7400   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7401   "@
7402    #
7403    #
7404    mov{q}\t{%1, %0|%0, %1}"
7405   [(set_attr "type" "*,*,imov")
7406    (set_attr "mode" "*,*,DI")])
7407
7408 (define_insn "*sse2_storeq"
7409   [(set (match_operand:DI 0 "nonimmediate_operand" "=xm")
7410         (vec_select:DI
7411           (match_operand:V2DI 1 "register_operand" "x")
7412           (parallel [(const_int 0)])))]
7413   "TARGET_SSE"
7414   "#")
7415
7416 (define_split
7417   [(set (match_operand:DI 0 "nonimmediate_operand")
7418         (vec_select:DI
7419           (match_operand:V2DI 1 "register_operand")
7420           (parallel [(const_int 0)])))]
7421   "TARGET_SSE
7422    && reload_completed
7423    && (TARGET_INTER_UNIT_MOVES
7424        || MEM_P (operands [0])
7425        || !GENERAL_REGNO_P (true_regnum (operands [0])))"
7426   [(set (match_dup 0) (match_dup 1))]
7427   "operands[1] = gen_rtx_REG (DImode, REGNO (operands[1]));")
7428
7429 (define_insn "*vec_extractv2di_1_rex64"
7430   [(set (match_operand:DI 0 "nonimmediate_operand"     "=m,x,x,x,r")
7431         (vec_select:DI
7432           (match_operand:V2DI 1 "nonimmediate_operand" " x,0,x,o,o")
7433           (parallel [(const_int 1)])))]
7434   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7435   "@
7436    %vmovhps\t{%1, %0|%0, %1}
7437    psrldq\t{$8, %0|%0, 8}
7438    vpsrldq\t{$8, %1, %0|%0, %1, 8}
7439    %vmovq\t{%H1, %0|%0, %H1}
7440    mov{q}\t{%H1, %0|%0, %H1}"
7441   [(set_attr "isa" "*,noavx,avx,*,*")
7442    (set_attr "type" "ssemov,sseishft1,sseishft1,ssemov,imov")
7443    (set_attr "length_immediate" "*,1,1,*,*")
7444    (set_attr "memory" "*,none,none,*,*")
7445    (set_attr "prefix" "maybe_vex,orig,vex,maybe_vex,orig")
7446    (set_attr "mode" "V2SF,TI,TI,TI,DI")])
7447
7448 (define_insn "*vec_extractv2di_1"
7449   [(set (match_operand:DI 0 "nonimmediate_operand"     "=m,x,x,x,x,x")
7450         (vec_select:DI
7451           (match_operand:V2DI 1 "nonimmediate_operand" " x,0,x,o,x,o")
7452           (parallel [(const_int 1)])))]
7453   "!TARGET_64BIT && TARGET_SSE
7454    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7455   "@
7456    %vmovhps\t{%1, %0|%0, %1}
7457    psrldq\t{$8, %0|%0, 8}
7458    vpsrldq\t{$8, %1, %0|%0, %1, 8}
7459    %vmovq\t{%H1, %0|%0, %H1}
7460    movhlps\t{%1, %0|%0, %1}
7461    movlps\t{%H1, %0|%0, %H1}"
7462   [(set_attr "isa" "*,sse2_noavx,avx,sse2,noavx,noavx")
7463    (set_attr "type" "ssemov,sseishft1,sseishft1,ssemov,ssemov,ssemov")
7464    (set_attr "length_immediate" "*,1,1,*,*,*")
7465    (set_attr "memory" "*,none,none,*,*,*")
7466    (set_attr "prefix" "maybe_vex,orig,vex,maybe_vex,orig,orig")
7467    (set_attr "mode" "V2SF,TI,TI,TI,V4SF,V2SF")])
7468
7469 (define_insn "*vec_dupv4si"
7470   [(set (match_operand:V4SI 0 "register_operand"     "=x,x,x")
7471         (vec_duplicate:V4SI
7472           (match_operand:SI 1 "nonimmediate_operand" " x,m,0")))]
7473   "TARGET_SSE"
7474   "@
7475    %vpshufd\t{$0, %1, %0|%0, %1, 0}
7476    vbroadcastss\t{%1, %0|%0, %1}
7477    shufps\t{$0, %0, %0|%0, %0, 0}"
7478   [(set_attr "isa" "sse2,avx,noavx")
7479    (set_attr "type" "sselog1,ssemov,sselog1")
7480    (set_attr "length_immediate" "1,0,1")
7481    (set_attr "prefix_extra" "0,1,*")
7482    (set_attr "prefix" "maybe_vex,vex,orig")
7483    (set_attr "mode" "TI,V4SF,V4SF")])
7484
7485 (define_insn "*vec_dupv2di"
7486   [(set (match_operand:V2DI 0 "register_operand"     "=x,x,x,x")
7487         (vec_duplicate:V2DI
7488           (match_operand:DI 1 "nonimmediate_operand" " 0,x,m,0")))]
7489   "TARGET_SSE"
7490   "@
7491    punpcklqdq\t%0, %0
7492    vpunpcklqdq\t{%d1, %0|%0, %d1}
7493    %vmovddup\t{%1, %0|%0, %1}
7494    movlhps\t%0, %0"
7495   [(set_attr "isa" "sse2_noavx,avx,sse3,noavx")
7496    (set_attr "type" "sselog1,sselog1,sselog1,ssemov")
7497    (set_attr "prefix" "orig,vex,maybe_vex,orig")
7498    (set_attr "mode" "TI,TI,DF,V4SF")])
7499
7500 (define_insn "*vec_concatv2si_sse4_1"
7501   [(set (match_operand:V2SI 0 "register_operand"     "=x, x,x,x, x, *y,*y")
7502         (vec_concat:V2SI
7503           (match_operand:SI 1 "nonimmediate_operand" " 0, x,0,x,rm,  0,rm")
7504           (match_operand:SI 2 "vector_move_operand"  "rm,rm,x,x, C,*ym, C")))]
7505   "TARGET_SSE4_1"
7506   "@
7507    pinsrd\t{$1, %2, %0|%0, %2, 1}
7508    vpinsrd\t{$1, %2, %1, %0|%0, %1, %2, 1}
7509    punpckldq\t{%2, %0|%0, %2}
7510    vpunpckldq\t{%2, %1, %0|%0, %1, %2}
7511    %vmovd\t{%1, %0|%0, %1}
7512    punpckldq\t{%2, %0|%0, %2}
7513    movd\t{%1, %0|%0, %1}"
7514   [(set_attr "isa" "noavx,avx,noavx,avx,*,*,*")
7515    (set_attr "type" "sselog,sselog,sselog,sselog,ssemov,mmxcvt,mmxmov")
7516    (set_attr "prefix_extra" "1,1,*,*,*,*,*")
7517    (set_attr "length_immediate" "1,1,*,*,*,*,*")
7518    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex,orig,orig")
7519    (set_attr "mode" "TI,TI,TI,TI,TI,DI,DI")])
7520
7521 ;; ??? In theory we can match memory for the MMX alternative, but allowing
7522 ;; nonimmediate_operand for operand 2 and *not* allowing memory for the SSE
7523 ;; alternatives pretty much forces the MMX alternative to be chosen.
7524 (define_insn "*vec_concatv2si_sse2"
7525   [(set (match_operand:V2SI 0 "register_operand"     "=x,x ,*y,*y")
7526         (vec_concat:V2SI
7527           (match_operand:SI 1 "nonimmediate_operand" " 0,rm, 0,rm")
7528           (match_operand:SI 2 "reg_or_0_operand"     " x,C ,*y, C")))]
7529   "TARGET_SSE2"
7530   "@
7531    punpckldq\t{%2, %0|%0, %2}
7532    movd\t{%1, %0|%0, %1}
7533    punpckldq\t{%2, %0|%0, %2}
7534    movd\t{%1, %0|%0, %1}"
7535   [(set_attr "type" "sselog,ssemov,mmxcvt,mmxmov")
7536    (set_attr "mode" "TI,TI,DI,DI")])
7537
7538 (define_insn "*vec_concatv2si_sse"
7539   [(set (match_operand:V2SI 0 "register_operand"     "=x,x,*y,*y")
7540         (vec_concat:V2SI
7541           (match_operand:SI 1 "nonimmediate_operand" " 0,m, 0,*rm")
7542           (match_operand:SI 2 "reg_or_0_operand"     " x,C,*y,C")))]
7543   "TARGET_SSE"
7544   "@
7545    unpcklps\t{%2, %0|%0, %2}
7546    movss\t{%1, %0|%0, %1}
7547    punpckldq\t{%2, %0|%0, %2}
7548    movd\t{%1, %0|%0, %1}"
7549   [(set_attr "type" "sselog,ssemov,mmxcvt,mmxmov")
7550    (set_attr "mode" "V4SF,V4SF,DI,DI")])
7551
7552 (define_insn "*vec_concatv4si"
7553   [(set (match_operand:V4SI 0 "register_operand"       "=x,x,x,x,x")
7554         (vec_concat:V4SI
7555           (match_operand:V2SI 1 "register_operand"     " 0,x,0,0,x")
7556           (match_operand:V2SI 2 "nonimmediate_operand" " x,x,x,m,m")))]
7557   "TARGET_SSE"
7558   "@
7559    punpcklqdq\t{%2, %0|%0, %2}
7560    vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}
7561    movlhps\t{%2, %0|%0, %2}
7562    movhps\t{%2, %0|%0, %2}
7563    vmovhps\t{%2, %1, %0|%0, %1, %2}"
7564   [(set_attr "isa" "sse2_noavx,avx,noavx,noavx,avx")
7565    (set_attr "type" "sselog,sselog,ssemov,ssemov,ssemov")
7566    (set_attr "prefix" "orig,vex,orig,orig,vex")
7567    (set_attr "mode" "TI,TI,V4SF,V2SF,V2SF")])
7568
7569 ;; movd instead of movq is required to handle broken assemblers.
7570 (define_insn "*vec_concatv2di_rex64"
7571   [(set (match_operand:V2DI 0 "register_operand"
7572           "=x,x ,x ,Yi,!x,x,x,x,x")
7573         (vec_concat:V2DI
7574           (match_operand:DI 1 "nonimmediate_operand"
7575           " 0,x ,xm,r ,*y,0,x,0,x")
7576           (match_operand:DI 2 "vector_move_operand"
7577           "rm,rm,C ,C ,C ,x,x,m,m")))]
7578   "TARGET_64BIT"
7579   "@
7580    pinsrq\t{$1, %2, %0|%0, %2, 1}
7581    vpinsrq\t{$1, %2, %1, %0|%0, %1, %2, 1}
7582    %vmovq\t{%1, %0|%0, %1}
7583    %vmovd\t{%1, %0|%0, %1}
7584    movq2dq\t{%1, %0|%0, %1}
7585    punpcklqdq\t{%2, %0|%0, %2}
7586    vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}
7587    movhps\t{%2, %0|%0, %2}
7588    vmovhps\t{%2, %1, %0|%0, %1, %2}"
7589   [(set_attr "isa" "sse4_noavx,avx,*,*,*,noavx,avx,noavx,avx")
7590    (set (attr "type")
7591      (if_then_else
7592        (eq_attr "alternative" "0,1,5,6")
7593        (const_string "sselog")
7594        (const_string "ssemov")))
7595    (set (attr "prefix_rex")
7596      (if_then_else
7597        (and (eq_attr "alternative" "0,3")
7598             (not (match_test "TARGET_AVX")))
7599        (const_string "1")
7600        (const_string "*")))
7601    (set_attr "prefix_extra" "1,1,*,*,*,*,*,*,*")
7602    (set_attr "length_immediate" "1,1,*,*,*,*,*,*,*")
7603    (set_attr "prefix" "orig,vex,maybe_vex,maybe_vex,orig,orig,vex,orig,vex")
7604    (set_attr "mode" "TI,TI,TI,TI,TI,TI,TI,V2SF,V2SF")])
7605
7606 (define_insn "vec_concatv2di"
7607   [(set (match_operand:V2DI 0 "register_operand"     "=x,?x,x,x,x,x,x")
7608         (vec_concat:V2DI
7609           (match_operand:DI 1 "nonimmediate_operand" "xm,*y,0,x,0,0,x")
7610           (match_operand:DI 2 "vector_move_operand"  " C, C,x,x,x,m,m")))]
7611   "!TARGET_64BIT && TARGET_SSE"
7612   "@
7613    %vmovq\t{%1, %0|%0, %1}
7614    movq2dq\t{%1, %0|%0, %1}
7615    punpcklqdq\t{%2, %0|%0, %2}
7616    vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}
7617    movlhps\t{%2, %0|%0, %2}
7618    movhps\t{%2, %0|%0, %2}
7619    vmovhps\t{%2, %1, %0|%0, %1, %2}"
7620   [(set_attr "isa" "sse2,sse2,sse2_noavx,avx,noavx,noavx,avx")
7621    (set_attr "type" "ssemov,ssemov,sselog,sselog,ssemov,ssemov,ssemov")
7622    (set_attr "prefix" "maybe_vex,orig,orig,vex,orig,orig,vex")
7623    (set_attr "mode" "TI,TI,TI,TI,V4SF,V2SF,V2SF")])
7624
7625 (define_expand "vec_unpacks_lo_<mode>"
7626   [(match_operand:<sseunpackmode> 0 "register_operand")
7627    (match_operand:VI124_AVX2 1 "register_operand")]
7628   "TARGET_SSE2"
7629   "ix86_expand_sse_unpack (operands[0], operands[1], false, false); DONE;")
7630
7631 (define_expand "vec_unpacks_hi_<mode>"
7632   [(match_operand:<sseunpackmode> 0 "register_operand")
7633    (match_operand:VI124_AVX2 1 "register_operand")]
7634   "TARGET_SSE2"
7635   "ix86_expand_sse_unpack (operands[0], operands[1], false, true); DONE;")
7636
7637 (define_expand "vec_unpacku_lo_<mode>"
7638   [(match_operand:<sseunpackmode> 0 "register_operand")
7639    (match_operand:VI124_AVX2 1 "register_operand")]
7640   "TARGET_SSE2"
7641   "ix86_expand_sse_unpack (operands[0], operands[1], true, false); DONE;")
7642
7643 (define_expand "vec_unpacku_hi_<mode>"
7644   [(match_operand:<sseunpackmode> 0 "register_operand")
7645    (match_operand:VI124_AVX2 1 "register_operand")]
7646   "TARGET_SSE2"
7647   "ix86_expand_sse_unpack (operands[0], operands[1], true, true); DONE;")
7648
7649 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7650 ;;
7651 ;; Miscellaneous
7652 ;;
7653 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7654
7655 (define_expand "<sse2_avx2>_uavg<mode>3"
7656   [(set (match_operand:VI12_AVX2 0 "register_operand")
7657         (truncate:VI12_AVX2
7658           (lshiftrt:<ssedoublemode>
7659             (plus:<ssedoublemode>
7660               (plus:<ssedoublemode>
7661                 (zero_extend:<ssedoublemode>
7662                   (match_operand:VI12_AVX2 1 "nonimmediate_operand"))
7663                 (zero_extend:<ssedoublemode>
7664                   (match_operand:VI12_AVX2 2 "nonimmediate_operand")))
7665               (match_dup 3))
7666             (const_int 1))))]
7667   "TARGET_SSE2"
7668 {
7669   operands[3] = CONST1_RTX(<MODE>mode);
7670   ix86_fixup_binary_operands_no_copy (PLUS, <MODE>mode, operands);
7671 })
7672
7673 (define_insn "*<sse2_avx2>_uavg<mode>3"
7674   [(set (match_operand:VI12_AVX2 0 "register_operand" "=x,x")
7675         (truncate:VI12_AVX2
7676           (lshiftrt:<ssedoublemode>
7677             (plus:<ssedoublemode>
7678               (plus:<ssedoublemode>
7679                 (zero_extend:<ssedoublemode>
7680                   (match_operand:VI12_AVX2 1 "nonimmediate_operand" "%0,x"))
7681                 (zero_extend:<ssedoublemode>
7682                   (match_operand:VI12_AVX2 2 "nonimmediate_operand" "xm,xm")))
7683               (match_operand:VI12_AVX2 3 "const1_operand"))
7684             (const_int 1))))]
7685   "TARGET_SSE2 && ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
7686   "@
7687    pavg<ssemodesuffix>\t{%2, %0|%0, %2}
7688    vpavg<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
7689   [(set_attr "isa" "noavx,avx")
7690    (set_attr "type" "sseiadd")
7691    (set_attr "prefix_data16" "1,*")
7692    (set_attr "prefix" "orig,vex")
7693    (set_attr "mode" "<sseinsnmode>")])
7694
7695 ;; The correct representation for this is absolutely enormous, and
7696 ;; surely not generally useful.
7697 (define_insn "<sse2_avx2>_psadbw"
7698   [(set (match_operand:VI8_AVX2 0 "register_operand" "=x,x")
7699         (unspec:VI8_AVX2
7700           [(match_operand:<ssebytemode> 1 "register_operand" "0,x")
7701            (match_operand:<ssebytemode> 2 "nonimmediate_operand" "xm,xm")]
7702           UNSPEC_PSADBW))]
7703   "TARGET_SSE2"
7704   "@
7705    psadbw\t{%2, %0|%0, %2}
7706    vpsadbw\t{%2, %1, %0|%0, %1, %2}"
7707   [(set_attr "isa" "noavx,avx")
7708    (set_attr "type" "sseiadd")
7709    (set_attr "atom_unit" "simul")
7710    (set_attr "prefix_data16" "1,*")
7711    (set_attr "prefix" "orig,vex")
7712    (set_attr "mode" "<sseinsnmode>")])
7713
7714 (define_insn "<sse>_movmsk<ssemodesuffix><avxsizesuffix>"
7715   [(set (match_operand:SI 0 "register_operand" "=r")
7716         (unspec:SI
7717           [(match_operand:VF 1 "register_operand" "x")]
7718           UNSPEC_MOVMSK))]
7719   "TARGET_SSE"
7720   "%vmovmsk<ssemodesuffix>\t{%1, %0|%0, %1}"
7721   [(set_attr "type" "ssemov")
7722    (set_attr "prefix" "maybe_vex")
7723    (set_attr "mode" "<MODE>")])
7724
7725 (define_insn "avx2_pmovmskb"
7726   [(set (match_operand:SI 0 "register_operand" "=r")
7727         (unspec:SI [(match_operand:V32QI 1 "register_operand" "x")]
7728                    UNSPEC_MOVMSK))]
7729   "TARGET_AVX2"
7730   "vpmovmskb\t{%1, %0|%0, %1}"
7731   [(set_attr "type" "ssemov")
7732    (set_attr "prefix" "vex")
7733    (set_attr "mode" "DI")])
7734
7735 (define_insn "sse2_pmovmskb"
7736   [(set (match_operand:SI 0 "register_operand" "=r")
7737         (unspec:SI [(match_operand:V16QI 1 "register_operand" "x")]
7738                    UNSPEC_MOVMSK))]
7739   "TARGET_SSE2"
7740   "%vpmovmskb\t{%1, %0|%0, %1}"
7741   [(set_attr "type" "ssemov")
7742    (set_attr "prefix_data16" "1")
7743    (set_attr "prefix" "maybe_vex")
7744    (set_attr "mode" "SI")])
7745
7746 (define_expand "sse2_maskmovdqu"
7747   [(set (match_operand:V16QI 0 "memory_operand")
7748         (unspec:V16QI [(match_operand:V16QI 1 "register_operand")
7749                        (match_operand:V16QI 2 "register_operand")
7750                        (match_dup 0)]
7751                       UNSPEC_MASKMOV))]
7752   "TARGET_SSE2")
7753
7754 (define_insn "*sse2_maskmovdqu"
7755   [(set (mem:V16QI (match_operand:P 0 "register_operand" "D"))
7756         (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "x")
7757                        (match_operand:V16QI 2 "register_operand" "x")
7758                        (mem:V16QI (match_dup 0))]
7759                       UNSPEC_MASKMOV))]
7760   "TARGET_SSE2"
7761   "%vmaskmovdqu\t{%2, %1|%1, %2}"
7762   [(set_attr "type" "ssemov")
7763    (set_attr "prefix_data16" "1")
7764    ;; The implicit %rdi operand confuses default length_vex computation.
7765    (set (attr "length_vex")
7766      (symbol_ref ("3 + REX_SSE_REGNO_P (REGNO (operands[2]))")))
7767    (set_attr "prefix" "maybe_vex")
7768    (set_attr "mode" "TI")])
7769
7770 (define_insn "sse_ldmxcsr"
7771   [(unspec_volatile [(match_operand:SI 0 "memory_operand" "m")]
7772                     UNSPECV_LDMXCSR)]
7773   "TARGET_SSE"
7774   "%vldmxcsr\t%0"
7775   [(set_attr "type" "sse")
7776    (set_attr "atom_sse_attr" "mxcsr")
7777    (set_attr "prefix" "maybe_vex")
7778    (set_attr "memory" "load")])
7779
7780 (define_insn "sse_stmxcsr"
7781   [(set (match_operand:SI 0 "memory_operand" "=m")
7782         (unspec_volatile:SI [(const_int 0)] UNSPECV_STMXCSR))]
7783   "TARGET_SSE"
7784   "%vstmxcsr\t%0"
7785   [(set_attr "type" "sse")
7786    (set_attr "atom_sse_attr" "mxcsr")
7787    (set_attr "prefix" "maybe_vex")
7788    (set_attr "memory" "store")])
7789
7790 (define_insn "sse2_clflush"
7791   [(unspec_volatile [(match_operand 0 "address_operand" "p")]
7792                     UNSPECV_CLFLUSH)]
7793   "TARGET_SSE2"
7794   "clflush\t%a0"
7795   [(set_attr "type" "sse")
7796    (set_attr "atom_sse_attr" "fence")
7797    (set_attr "memory" "unknown")])
7798
7799
7800 (define_insn "sse3_mwait"
7801   [(unspec_volatile [(match_operand:SI 0 "register_operand" "a")
7802                      (match_operand:SI 1 "register_operand" "c")]
7803                     UNSPECV_MWAIT)]
7804   "TARGET_SSE3"
7805 ;; 64bit version is "mwait %rax,%rcx". But only lower 32bits are used.
7806 ;; Since 32bit register operands are implicitly zero extended to 64bit,
7807 ;; we only need to set up 32bit registers.
7808   "mwait"
7809   [(set_attr "length" "3")])
7810
7811 (define_insn "sse3_monitor"
7812   [(unspec_volatile [(match_operand:SI 0 "register_operand" "a")
7813                      (match_operand:SI 1 "register_operand" "c")
7814                      (match_operand:SI 2 "register_operand" "d")]
7815                     UNSPECV_MONITOR)]
7816   "TARGET_SSE3 && !TARGET_64BIT"
7817   "monitor\t%0, %1, %2"
7818   [(set_attr "length" "3")])
7819
7820 (define_insn "sse3_monitor64_<mode>"
7821   [(unspec_volatile [(match_operand:P 0 "register_operand" "a")
7822                      (match_operand:SI 1 "register_operand" "c")
7823                      (match_operand:SI 2 "register_operand" "d")]
7824                     UNSPECV_MONITOR)]
7825   "TARGET_SSE3 && TARGET_64BIT"
7826 ;; 64bit version is "monitor %rax,%rcx,%rdx". But only lower 32bits in
7827 ;; RCX and RDX are used.  Since 32bit register operands are implicitly
7828 ;; zero extended to 64bit, we only need to set up 32bit registers.
7829   "monitor"
7830   [(set_attr "length" "3")])
7831
7832 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7833 ;;
7834 ;; SSSE3 instructions
7835 ;;
7836 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7837
7838 (define_code_iterator ssse3_plusminus [plus ss_plus minus ss_minus])
7839
7840 (define_insn "avx2_ph<plusminus_mnemonic>wv16hi3"
7841   [(set (match_operand:V16HI 0 "register_operand" "=x")
7842         (vec_concat:V16HI
7843           (vec_concat:V8HI
7844             (vec_concat:V4HI
7845               (vec_concat:V2HI
7846                 (ssse3_plusminus:HI
7847                   (vec_select:HI
7848                     (match_operand:V16HI 1 "register_operand" "x")
7849                     (parallel [(const_int 0)]))
7850                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
7851                 (ssse3_plusminus:HI
7852                   (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
7853                   (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
7854               (vec_concat:V2HI
7855                 (ssse3_plusminus:HI
7856                   (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
7857                   (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
7858                 (ssse3_plusminus:HI
7859                   (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
7860                   (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
7861             (vec_concat:V4HI
7862               (vec_concat:V2HI
7863                 (ssse3_plusminus:HI
7864                   (vec_select:HI (match_dup 1) (parallel [(const_int 8)]))
7865                   (vec_select:HI (match_dup 1) (parallel [(const_int 9)])))
7866                 (ssse3_plusminus:HI
7867                   (vec_select:HI (match_dup 1) (parallel [(const_int 10)]))
7868                   (vec_select:HI (match_dup 1) (parallel [(const_int 11)]))))
7869               (vec_concat:V2HI
7870                 (ssse3_plusminus:HI
7871                   (vec_select:HI (match_dup 1) (parallel [(const_int 12)]))
7872                   (vec_select:HI (match_dup 1) (parallel [(const_int 13)])))
7873                 (ssse3_plusminus:HI
7874                   (vec_select:HI (match_dup 1) (parallel [(const_int 14)]))
7875                   (vec_select:HI (match_dup 1) (parallel [(const_int 15)]))))))
7876           (vec_concat:V8HI
7877             (vec_concat:V4HI
7878               (vec_concat:V2HI
7879                 (ssse3_plusminus:HI
7880                   (vec_select:HI
7881                     (match_operand:V16HI 2 "nonimmediate_operand" "xm")
7882                     (parallel [(const_int 0)]))
7883                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
7884                 (ssse3_plusminus:HI
7885                   (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
7886                   (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
7887               (vec_concat:V2HI
7888                 (ssse3_plusminus:HI
7889                   (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
7890                   (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
7891                 (ssse3_plusminus:HI
7892                   (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
7893                   (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))
7894             (vec_concat:V4HI
7895               (vec_concat:V2HI
7896                 (ssse3_plusminus:HI
7897                   (vec_select:HI (match_dup 2) (parallel [(const_int 8)]))
7898                   (vec_select:HI (match_dup 2) (parallel [(const_int 9)])))
7899                 (ssse3_plusminus:HI
7900                   (vec_select:HI (match_dup 2) (parallel [(const_int 10)]))
7901                   (vec_select:HI (match_dup 2) (parallel [(const_int 11)]))))
7902               (vec_concat:V2HI
7903                 (ssse3_plusminus:HI
7904                   (vec_select:HI (match_dup 2) (parallel [(const_int 12)]))
7905                   (vec_select:HI (match_dup 2) (parallel [(const_int 13)])))
7906                 (ssse3_plusminus:HI
7907                   (vec_select:HI (match_dup 2) (parallel [(const_int 14)]))
7908                   (vec_select:HI (match_dup 2) (parallel [(const_int 15)]))))))))]
7909   "TARGET_AVX2"
7910   "vph<plusminus_mnemonic>w\t{%2, %1, %0|%0, %1, %2}"
7911   [(set_attr "type" "sseiadd")
7912    (set_attr "prefix_extra" "1")
7913    (set_attr "prefix" "vex")
7914    (set_attr "mode" "OI")])
7915
7916 (define_insn "ssse3_ph<plusminus_mnemonic>wv8hi3"
7917   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
7918         (vec_concat:V8HI
7919           (vec_concat:V4HI
7920             (vec_concat:V2HI
7921               (ssse3_plusminus:HI
7922                 (vec_select:HI
7923                   (match_operand:V8HI 1 "register_operand" "0,x")
7924                   (parallel [(const_int 0)]))
7925                 (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
7926               (ssse3_plusminus:HI
7927                 (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
7928                 (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
7929             (vec_concat:V2HI
7930               (ssse3_plusminus:HI
7931                 (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
7932                 (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
7933               (ssse3_plusminus:HI
7934                 (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
7935                 (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
7936           (vec_concat:V4HI
7937             (vec_concat:V2HI
7938               (ssse3_plusminus:HI
7939                 (vec_select:HI
7940                   (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
7941                   (parallel [(const_int 0)]))
7942                 (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
7943               (ssse3_plusminus:HI
7944                 (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
7945                 (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
7946             (vec_concat:V2HI
7947               (ssse3_plusminus:HI
7948                 (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
7949                 (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
7950               (ssse3_plusminus:HI
7951                 (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
7952                 (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))))]
7953   "TARGET_SSSE3"
7954   "@
7955    ph<plusminus_mnemonic>w\t{%2, %0|%0, %2}
7956    vph<plusminus_mnemonic>w\t{%2, %1, %0|%0, %1, %2}"
7957   [(set_attr "isa" "noavx,avx")
7958    (set_attr "type" "sseiadd")
7959    (set_attr "atom_unit" "complex")
7960    (set_attr "prefix_data16" "1,*")
7961    (set_attr "prefix_extra" "1")
7962    (set_attr "prefix" "orig,vex")
7963    (set_attr "mode" "TI")])
7964
7965 (define_insn "ssse3_ph<plusminus_mnemonic>wv4hi3"
7966   [(set (match_operand:V4HI 0 "register_operand" "=y")
7967         (vec_concat:V4HI
7968           (vec_concat:V2HI
7969             (ssse3_plusminus:HI
7970               (vec_select:HI
7971                 (match_operand:V4HI 1 "register_operand" "0")
7972                 (parallel [(const_int 0)]))
7973               (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
7974             (ssse3_plusminus:HI
7975               (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
7976               (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
7977           (vec_concat:V2HI
7978             (ssse3_plusminus:HI
7979               (vec_select:HI
7980                 (match_operand:V4HI 2 "nonimmediate_operand" "ym")
7981                 (parallel [(const_int 0)]))
7982               (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
7983             (ssse3_plusminus:HI
7984               (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
7985               (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))))]
7986   "TARGET_SSSE3"
7987   "ph<plusminus_mnemonic>w\t{%2, %0|%0, %2}"
7988   [(set_attr "type" "sseiadd")
7989    (set_attr "atom_unit" "complex")
7990    (set_attr "prefix_extra" "1")
7991    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
7992    (set_attr "mode" "DI")])
7993
7994 (define_insn "avx2_ph<plusminus_mnemonic>dv8si3"
7995   [(set (match_operand:V8SI 0 "register_operand" "=x")
7996         (vec_concat:V8SI
7997           (vec_concat:V4SI
7998             (vec_concat:V2SI
7999               (plusminus:SI
8000                 (vec_select:SI
8001                   (match_operand:V8SI 1 "register_operand" "x")
8002                   (parallel [(const_int 0)]))
8003                 (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8004               (plusminus:SI
8005                 (vec_select:SI (match_dup 1) (parallel [(const_int 2)]))
8006                 (vec_select:SI (match_dup 1) (parallel [(const_int 3)]))))
8007             (vec_concat:V2SI
8008               (plusminus:SI
8009                 (vec_select:SI (match_dup 1) (parallel [(const_int 4)]))
8010                 (vec_select:SI (match_dup 1) (parallel [(const_int 5)])))
8011               (plusminus:SI
8012                 (vec_select:SI (match_dup 1) (parallel [(const_int 6)]))
8013                 (vec_select:SI (match_dup 1) (parallel [(const_int 7)])))))
8014           (vec_concat:V4SI
8015             (vec_concat:V2SI
8016               (plusminus:SI
8017                 (vec_select:SI
8018                   (match_operand:V8SI 2 "nonimmediate_operand" "xm")
8019                   (parallel [(const_int 0)]))
8020                 (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))
8021               (plusminus:SI
8022                 (vec_select:SI (match_dup 2) (parallel [(const_int 2)]))
8023                 (vec_select:SI (match_dup 2) (parallel [(const_int 3)]))))
8024             (vec_concat:V2SI
8025               (plusminus:SI
8026                 (vec_select:SI (match_dup 2) (parallel [(const_int 4)]))
8027                 (vec_select:SI (match_dup 2) (parallel [(const_int 5)])))
8028               (plusminus:SI
8029                 (vec_select:SI (match_dup 2) (parallel [(const_int 6)]))
8030                 (vec_select:SI (match_dup 2) (parallel [(const_int 7)])))))))]
8031   "TARGET_AVX2"
8032   "vph<plusminus_mnemonic>d\t{%2, %1, %0|%0, %1, %2}"
8033   [(set_attr "type" "sseiadd")
8034    (set_attr "prefix_extra" "1")
8035    (set_attr "prefix" "vex")
8036    (set_attr "mode" "OI")])
8037
8038 (define_insn "ssse3_ph<plusminus_mnemonic>dv4si3"
8039   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
8040         (vec_concat:V4SI
8041           (vec_concat:V2SI
8042             (plusminus:SI
8043               (vec_select:SI
8044                 (match_operand:V4SI 1 "register_operand" "0,x")
8045                 (parallel [(const_int 0)]))
8046               (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8047             (plusminus:SI
8048               (vec_select:SI (match_dup 1) (parallel [(const_int 2)]))
8049               (vec_select:SI (match_dup 1) (parallel [(const_int 3)]))))
8050           (vec_concat:V2SI
8051             (plusminus:SI
8052               (vec_select:SI
8053                 (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm")
8054                 (parallel [(const_int 0)]))
8055               (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))
8056             (plusminus:SI
8057               (vec_select:SI (match_dup 2) (parallel [(const_int 2)]))
8058               (vec_select:SI (match_dup 2) (parallel [(const_int 3)]))))))]
8059   "TARGET_SSSE3"
8060   "@
8061    ph<plusminus_mnemonic>d\t{%2, %0|%0, %2}
8062    vph<plusminus_mnemonic>d\t{%2, %1, %0|%0, %1, %2}"
8063   [(set_attr "isa" "noavx,avx")
8064    (set_attr "type" "sseiadd")
8065    (set_attr "atom_unit" "complex")
8066    (set_attr "prefix_data16" "1,*")
8067    (set_attr "prefix_extra" "1")
8068    (set_attr "prefix" "orig,vex")
8069    (set_attr "mode" "TI")])
8070
8071 (define_insn "ssse3_ph<plusminus_mnemonic>dv2si3"
8072   [(set (match_operand:V2SI 0 "register_operand" "=y")
8073         (vec_concat:V2SI
8074           (plusminus:SI
8075             (vec_select:SI
8076               (match_operand:V2SI 1 "register_operand" "0")
8077               (parallel [(const_int 0)]))
8078             (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8079           (plusminus:SI
8080             (vec_select:SI
8081               (match_operand:V2SI 2 "nonimmediate_operand" "ym")
8082               (parallel [(const_int 0)]))
8083             (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))))]
8084   "TARGET_SSSE3"
8085   "ph<plusminus_mnemonic>d\t{%2, %0|%0, %2}"
8086   [(set_attr "type" "sseiadd")
8087    (set_attr "atom_unit" "complex")
8088    (set_attr "prefix_extra" "1")
8089    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8090    (set_attr "mode" "DI")])
8091
8092 (define_insn "avx2_pmaddubsw256"
8093   [(set (match_operand:V16HI 0 "register_operand" "=x")
8094         (ss_plus:V16HI
8095           (mult:V16HI
8096             (zero_extend:V16HI
8097               (vec_select:V16QI
8098                 (match_operand:V32QI 1 "register_operand" "x")
8099                 (parallel [(const_int 0) (const_int 2)
8100                            (const_int 4) (const_int 6)
8101                            (const_int 8) (const_int 10)
8102                            (const_int 12) (const_int 14)
8103                            (const_int 16) (const_int 18)
8104                            (const_int 20) (const_int 22)
8105                            (const_int 24) (const_int 26)
8106                            (const_int 28) (const_int 30)])))
8107             (sign_extend:V16HI
8108               (vec_select:V16QI
8109                 (match_operand:V32QI 2 "nonimmediate_operand" "xm")
8110                 (parallel [(const_int 0) (const_int 2)
8111                            (const_int 4) (const_int 6)
8112                            (const_int 8) (const_int 10)
8113                            (const_int 12) (const_int 14)
8114                            (const_int 16) (const_int 18)
8115                            (const_int 20) (const_int 22)
8116                            (const_int 24) (const_int 26)
8117                            (const_int 28) (const_int 30)]))))
8118           (mult:V16HI
8119             (zero_extend:V16HI
8120               (vec_select:V16QI (match_dup 1)
8121                 (parallel [(const_int 1) (const_int 3)
8122                            (const_int 5) (const_int 7)
8123                            (const_int 9) (const_int 11)
8124                            (const_int 13) (const_int 15)
8125                            (const_int 17) (const_int 19)
8126                            (const_int 21) (const_int 23)
8127                            (const_int 25) (const_int 27)
8128                            (const_int 29) (const_int 31)])))
8129             (sign_extend:V16HI
8130               (vec_select:V16QI (match_dup 2)
8131                 (parallel [(const_int 1) (const_int 3)
8132                            (const_int 5) (const_int 7)
8133                            (const_int 9) (const_int 11)
8134                            (const_int 13) (const_int 15)
8135                            (const_int 17) (const_int 19)
8136                            (const_int 21) (const_int 23)
8137                            (const_int 25) (const_int 27)
8138                            (const_int 29) (const_int 31)]))))))]
8139   "TARGET_AVX2"
8140   "vpmaddubsw\t{%2, %1, %0|%0, %1, %2}"
8141   [(set_attr "type" "sseiadd")
8142    (set_attr "prefix_extra" "1")
8143    (set_attr "prefix" "vex")
8144    (set_attr "mode" "OI")])
8145
8146 (define_insn "ssse3_pmaddubsw128"
8147   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
8148         (ss_plus:V8HI
8149           (mult:V8HI
8150             (zero_extend:V8HI
8151               (vec_select:V8QI
8152                 (match_operand:V16QI 1 "register_operand" "0,x")
8153                 (parallel [(const_int 0) (const_int 2)
8154                            (const_int 4) (const_int 6)
8155                            (const_int 8) (const_int 10)
8156                            (const_int 12) (const_int 14)])))
8157             (sign_extend:V8HI
8158               (vec_select:V8QI
8159                 (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm")
8160                 (parallel [(const_int 0) (const_int 2)
8161                            (const_int 4) (const_int 6)
8162                            (const_int 8) (const_int 10)
8163                            (const_int 12) (const_int 14)]))))
8164           (mult:V8HI
8165             (zero_extend:V8HI
8166               (vec_select:V8QI (match_dup 1)
8167                 (parallel [(const_int 1) (const_int 3)
8168                            (const_int 5) (const_int 7)
8169                            (const_int 9) (const_int 11)
8170                            (const_int 13) (const_int 15)])))
8171             (sign_extend:V8HI
8172               (vec_select:V8QI (match_dup 2)
8173                 (parallel [(const_int 1) (const_int 3)
8174                            (const_int 5) (const_int 7)
8175                            (const_int 9) (const_int 11)
8176                            (const_int 13) (const_int 15)]))))))]
8177   "TARGET_SSSE3"
8178   "@
8179    pmaddubsw\t{%2, %0|%0, %2}
8180    vpmaddubsw\t{%2, %1, %0|%0, %1, %2}"
8181   [(set_attr "isa" "noavx,avx")
8182    (set_attr "type" "sseiadd")
8183    (set_attr "atom_unit" "simul")
8184    (set_attr "prefix_data16" "1,*")
8185    (set_attr "prefix_extra" "1")
8186    (set_attr "prefix" "orig,vex")
8187    (set_attr "mode" "TI")])
8188
8189 (define_insn "ssse3_pmaddubsw"
8190   [(set (match_operand:V4HI 0 "register_operand" "=y")
8191         (ss_plus:V4HI
8192           (mult:V4HI
8193             (zero_extend:V4HI
8194               (vec_select:V4QI
8195                 (match_operand:V8QI 1 "register_operand" "0")
8196                 (parallel [(const_int 0) (const_int 2)
8197                            (const_int 4) (const_int 6)])))
8198             (sign_extend:V4HI
8199               (vec_select:V4QI
8200                 (match_operand:V8QI 2 "nonimmediate_operand" "ym")
8201                 (parallel [(const_int 0) (const_int 2)
8202                            (const_int 4) (const_int 6)]))))
8203           (mult:V4HI
8204             (zero_extend:V4HI
8205               (vec_select:V4QI (match_dup 1)
8206                 (parallel [(const_int 1) (const_int 3)
8207                            (const_int 5) (const_int 7)])))
8208             (sign_extend:V4HI
8209               (vec_select:V4QI (match_dup 2)
8210                 (parallel [(const_int 1) (const_int 3)
8211                            (const_int 5) (const_int 7)]))))))]
8212   "TARGET_SSSE3"
8213   "pmaddubsw\t{%2, %0|%0, %2}"
8214   [(set_attr "type" "sseiadd")
8215    (set_attr "atom_unit" "simul")
8216    (set_attr "prefix_extra" "1")
8217    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8218    (set_attr "mode" "DI")])
8219
8220 (define_mode_iterator PMULHRSW
8221   [V4HI V8HI (V16HI "TARGET_AVX2")])
8222
8223 (define_expand "<ssse3_avx2>_pmulhrsw<mode>3"
8224   [(set (match_operand:PMULHRSW 0 "register_operand")
8225         (truncate:PMULHRSW
8226           (lshiftrt:<ssedoublemode>
8227             (plus:<ssedoublemode>
8228               (lshiftrt:<ssedoublemode>
8229                 (mult:<ssedoublemode>
8230                   (sign_extend:<ssedoublemode>
8231                     (match_operand:PMULHRSW 1 "nonimmediate_operand"))
8232                   (sign_extend:<ssedoublemode>
8233                     (match_operand:PMULHRSW 2 "nonimmediate_operand")))
8234                 (const_int 14))
8235               (match_dup 3))
8236             (const_int 1))))]
8237   "TARGET_AVX2"
8238 {
8239   operands[3] = CONST1_RTX(<MODE>mode);
8240   ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);
8241 })
8242
8243 (define_insn "*<ssse3_avx2>_pmulhrsw<mode>3"
8244   [(set (match_operand:VI2_AVX2 0 "register_operand" "=x,x")
8245         (truncate:VI2_AVX2
8246           (lshiftrt:<ssedoublemode>
8247             (plus:<ssedoublemode>
8248               (lshiftrt:<ssedoublemode>
8249                 (mult:<ssedoublemode>
8250                   (sign_extend:<ssedoublemode>
8251                     (match_operand:VI2_AVX2 1 "nonimmediate_operand" "%0,x"))
8252                   (sign_extend:<ssedoublemode>
8253                     (match_operand:VI2_AVX2 2 "nonimmediate_operand" "xm,xm")))
8254                 (const_int 14))
8255               (match_operand:VI2_AVX2 3 "const1_operand"))
8256             (const_int 1))))]
8257   "TARGET_SSSE3 && ix86_binary_operator_ok (MULT, <MODE>mode, operands)"
8258   "@
8259    pmulhrsw\t{%2, %0|%0, %2}
8260    vpmulhrsw\t{%2, %1, %0|%0, %1, %2}"
8261   [(set_attr "isa" "noavx,avx")
8262    (set_attr "type" "sseimul")
8263    (set_attr "prefix_data16" "1,*")
8264    (set_attr "prefix_extra" "1")
8265    (set_attr "prefix" "orig,vex")
8266    (set_attr "mode" "<sseinsnmode>")])
8267
8268 (define_insn "*ssse3_pmulhrswv4hi3"
8269   [(set (match_operand:V4HI 0 "register_operand" "=y")
8270         (truncate:V4HI
8271           (lshiftrt:V4SI
8272             (plus:V4SI
8273               (lshiftrt:V4SI
8274                 (mult:V4SI
8275                   (sign_extend:V4SI
8276                     (match_operand:V4HI 1 "nonimmediate_operand" "%0"))
8277                   (sign_extend:V4SI
8278                     (match_operand:V4HI 2 "nonimmediate_operand" "ym")))
8279                 (const_int 14))
8280               (match_operand:V4HI 3 "const1_operand"))
8281             (const_int 1))))]
8282   "TARGET_SSSE3 && ix86_binary_operator_ok (MULT, V4HImode, operands)"
8283   "pmulhrsw\t{%2, %0|%0, %2}"
8284   [(set_attr "type" "sseimul")
8285    (set_attr "prefix_extra" "1")
8286    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8287    (set_attr "mode" "DI")])
8288
8289 (define_insn "<ssse3_avx2>_pshufb<mode>3"
8290   [(set (match_operand:VI1_AVX2 0 "register_operand" "=x,x")
8291         (unspec:VI1_AVX2
8292           [(match_operand:VI1_AVX2 1 "register_operand" "0,x")
8293            (match_operand:VI1_AVX2 2 "nonimmediate_operand" "xm,xm")]
8294           UNSPEC_PSHUFB))]
8295   "TARGET_SSSE3"
8296   "@
8297    pshufb\t{%2, %0|%0, %2}
8298    vpshufb\t{%2, %1, %0|%0, %1, %2}"
8299   [(set_attr "isa" "noavx,avx")
8300    (set_attr "type" "sselog1")
8301    (set_attr "prefix_data16" "1,*")
8302    (set_attr "prefix_extra" "1")
8303    (set_attr "prefix" "orig,vex")
8304    (set_attr "btver2_decode" "vector,vector")
8305    (set_attr "mode" "<sseinsnmode>")])
8306
8307 (define_insn "ssse3_pshufbv8qi3"
8308   [(set (match_operand:V8QI 0 "register_operand" "=y")
8309         (unspec:V8QI [(match_operand:V8QI 1 "register_operand" "0")
8310                       (match_operand:V8QI 2 "nonimmediate_operand" "ym")]
8311                      UNSPEC_PSHUFB))]
8312   "TARGET_SSSE3"
8313   "pshufb\t{%2, %0|%0, %2}";
8314   [(set_attr "type" "sselog1")
8315    (set_attr "prefix_extra" "1")
8316    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8317    (set_attr "mode" "DI")])
8318
8319 (define_insn "<ssse3_avx2>_psign<mode>3"
8320   [(set (match_operand:VI124_AVX2 0 "register_operand" "=x,x")
8321         (unspec:VI124_AVX2
8322           [(match_operand:VI124_AVX2 1 "register_operand" "0,x")
8323            (match_operand:VI124_AVX2 2 "nonimmediate_operand" "xm,xm")]
8324           UNSPEC_PSIGN))]
8325   "TARGET_SSSE3"
8326   "@
8327    psign<ssemodesuffix>\t{%2, %0|%0, %2}
8328    vpsign<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
8329   [(set_attr "isa" "noavx,avx")
8330    (set_attr "type" "sselog1")
8331    (set_attr "prefix_data16" "1,*")
8332    (set_attr "prefix_extra" "1")
8333    (set_attr "prefix" "orig,vex")
8334    (set_attr "mode" "<sseinsnmode>")])
8335
8336 (define_insn "ssse3_psign<mode>3"
8337   [(set (match_operand:MMXMODEI 0 "register_operand" "=y")
8338         (unspec:MMXMODEI
8339           [(match_operand:MMXMODEI 1 "register_operand" "0")
8340            (match_operand:MMXMODEI 2 "nonimmediate_operand" "ym")]
8341           UNSPEC_PSIGN))]
8342   "TARGET_SSSE3"
8343   "psign<mmxvecsize>\t{%2, %0|%0, %2}";
8344   [(set_attr "type" "sselog1")
8345    (set_attr "prefix_extra" "1")
8346    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8347    (set_attr "mode" "DI")])
8348
8349 (define_insn "<ssse3_avx2>_palignr<mode>"
8350   [(set (match_operand:SSESCALARMODE 0 "register_operand" "=x,x")
8351         (unspec:SSESCALARMODE
8352           [(match_operand:SSESCALARMODE 1 "register_operand" "0,x")
8353            (match_operand:SSESCALARMODE 2 "nonimmediate_operand" "xm,xm")
8354            (match_operand:SI 3 "const_0_to_255_mul_8_operand" "n,n")]
8355           UNSPEC_PALIGNR))]
8356   "TARGET_SSSE3"
8357 {
8358   operands[3] = GEN_INT (INTVAL (operands[3]) / 8);
8359
8360   switch (which_alternative)
8361     {
8362     case 0:
8363       return "palignr\t{%3, %2, %0|%0, %2, %3}";
8364     case 1:
8365       return "vpalignr\t{%3, %2, %1, %0|%0, %1, %2, %3}";
8366     default:
8367       gcc_unreachable ();
8368     }
8369 }
8370   [(set_attr "isa" "noavx,avx")
8371    (set_attr "type" "sseishft")
8372    (set_attr "atom_unit" "sishuf")
8373    (set_attr "prefix_data16" "1,*")
8374    (set_attr "prefix_extra" "1")
8375    (set_attr "length_immediate" "1")
8376    (set_attr "prefix" "orig,vex")
8377    (set_attr "mode" "<sseinsnmode>")])
8378
8379 (define_insn "ssse3_palignrdi"
8380   [(set (match_operand:DI 0 "register_operand" "=y")
8381         (unspec:DI [(match_operand:DI 1 "register_operand" "0")
8382                     (match_operand:DI 2 "nonimmediate_operand" "ym")
8383                     (match_operand:SI 3 "const_0_to_255_mul_8_operand" "n")]
8384                    UNSPEC_PALIGNR))]
8385   "TARGET_SSSE3"
8386 {
8387   operands[3] = GEN_INT (INTVAL (operands[3]) / 8);
8388   return "palignr\t{%3, %2, %0|%0, %2, %3}";
8389 }
8390   [(set_attr "type" "sseishft")
8391    (set_attr "atom_unit" "sishuf")
8392    (set_attr "prefix_extra" "1")
8393    (set_attr "length_immediate" "1")
8394    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8395    (set_attr "mode" "DI")])
8396
8397 (define_insn "abs<mode>2"
8398   [(set (match_operand:VI124_AVX2 0 "register_operand" "=x")
8399         (abs:VI124_AVX2
8400           (match_operand:VI124_AVX2 1 "nonimmediate_operand" "xm")))]
8401   "TARGET_SSSE3"
8402   "%vpabs<ssemodesuffix>\t{%1, %0|%0, %1}"
8403   [(set_attr "type" "sselog1")
8404    (set_attr "prefix_data16" "1")
8405    (set_attr "prefix_extra" "1")
8406    (set_attr "prefix" "maybe_vex")
8407    (set_attr "mode" "<sseinsnmode>")])
8408
8409 (define_insn "abs<mode>2"
8410   [(set (match_operand:MMXMODEI 0 "register_operand" "=y")
8411         (abs:MMXMODEI
8412           (match_operand:MMXMODEI 1 "nonimmediate_operand" "ym")))]
8413   "TARGET_SSSE3"
8414   "pabs<mmxvecsize>\t{%1, %0|%0, %1}";
8415   [(set_attr "type" "sselog1")
8416    (set_attr "prefix_rep" "0")
8417    (set_attr "prefix_extra" "1")
8418    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8419    (set_attr "mode" "DI")])
8420
8421 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8422 ;;
8423 ;; AMD SSE4A instructions
8424 ;;
8425 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8426
8427 (define_insn "sse4a_movnt<mode>"
8428   [(set (match_operand:MODEF 0 "memory_operand" "=m")
8429         (unspec:MODEF
8430           [(match_operand:MODEF 1 "register_operand" "x")]
8431           UNSPEC_MOVNT))]
8432   "TARGET_SSE4A"
8433   "movnt<ssemodesuffix>\t{%1, %0|%0, %1}"
8434   [(set_attr "type" "ssemov")
8435    (set_attr "mode" "<MODE>")])
8436
8437 (define_insn "sse4a_vmmovnt<mode>"
8438   [(set (match_operand:<ssescalarmode> 0 "memory_operand" "=m")
8439         (unspec:<ssescalarmode>
8440           [(vec_select:<ssescalarmode>
8441              (match_operand:VF_128 1 "register_operand" "x")
8442              (parallel [(const_int 0)]))]
8443           UNSPEC_MOVNT))]
8444   "TARGET_SSE4A"
8445   "movnt<ssescalarmodesuffix>\t{%1, %0|%0, %1}"
8446   [(set_attr "type" "ssemov")
8447    (set_attr "mode" "<ssescalarmode>")])
8448
8449 (define_insn "sse4a_extrqi"
8450   [(set (match_operand:V2DI 0 "register_operand" "=x")
8451         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
8452                       (match_operand 2 "const_0_to_255_operand")
8453                       (match_operand 3 "const_0_to_255_operand")]
8454                      UNSPEC_EXTRQI))]
8455   "TARGET_SSE4A"
8456   "extrq\t{%3, %2, %0|%0, %2, %3}"
8457   [(set_attr "type" "sse")
8458    (set_attr "prefix_data16" "1")
8459    (set_attr "length_immediate" "2")
8460    (set_attr "mode" "TI")])
8461
8462 (define_insn "sse4a_extrq"
8463   [(set (match_operand:V2DI 0 "register_operand" "=x")
8464         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
8465                       (match_operand:V16QI 2 "register_operand" "x")]
8466                      UNSPEC_EXTRQ))]
8467   "TARGET_SSE4A"
8468   "extrq\t{%2, %0|%0, %2}"
8469   [(set_attr "type" "sse")
8470    (set_attr "prefix_data16" "1")
8471    (set_attr "mode" "TI")])
8472
8473 (define_insn "sse4a_insertqi"
8474   [(set (match_operand:V2DI 0 "register_operand" "=x")
8475         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
8476                       (match_operand:V2DI 2 "register_operand" "x")
8477                       (match_operand 3 "const_0_to_255_operand")
8478                       (match_operand 4 "const_0_to_255_operand")]
8479                      UNSPEC_INSERTQI))]
8480   "TARGET_SSE4A"
8481   "insertq\t{%4, %3, %2, %0|%0, %2, %3, %4}"
8482   [(set_attr "type" "sseins")
8483    (set_attr "prefix_data16" "0")
8484    (set_attr "prefix_rep" "1")
8485    (set_attr "length_immediate" "2")
8486    (set_attr "mode" "TI")])
8487
8488 (define_insn "sse4a_insertq"
8489   [(set (match_operand:V2DI 0 "register_operand" "=x")
8490         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
8491                       (match_operand:V2DI 2 "register_operand" "x")]
8492                      UNSPEC_INSERTQ))]
8493   "TARGET_SSE4A"
8494   "insertq\t{%2, %0|%0, %2}"
8495   [(set_attr "type" "sseins")
8496    (set_attr "prefix_data16" "0")
8497    (set_attr "prefix_rep" "1")
8498    (set_attr "mode" "TI")])
8499
8500 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8501 ;;
8502 ;; Intel SSE4.1 instructions
8503 ;;
8504 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8505
8506 (define_insn "<sse4_1>_blend<ssemodesuffix><avxsizesuffix>"
8507   [(set (match_operand:VF 0 "register_operand" "=x,x")
8508         (vec_merge:VF
8509           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")
8510           (match_operand:VF 1 "register_operand" "0,x")
8511           (match_operand:SI 3 "const_0_to_<blendbits>_operand")))]
8512   "TARGET_SSE4_1"
8513   "@
8514    blend<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
8515    vblend<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
8516   [(set_attr "isa" "noavx,avx")
8517    (set_attr "type" "ssemov")
8518    (set_attr "length_immediate" "1")
8519    (set_attr "prefix_data16" "1,*")
8520    (set_attr "prefix_extra" "1")
8521    (set_attr "prefix" "orig,vex")
8522    (set_attr "mode" "<MODE>")])
8523
8524 (define_insn "<sse4_1>_blendv<ssemodesuffix><avxsizesuffix>"
8525   [(set (match_operand:VF 0 "register_operand" "=x,x")
8526         (unspec:VF
8527           [(match_operand:VF 1 "register_operand" "0,x")
8528            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")
8529            (match_operand:VF 3 "register_operand" "Yz,x")]
8530           UNSPEC_BLENDV))]
8531   "TARGET_SSE4_1"
8532   "@
8533    blendv<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
8534    vblendv<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
8535   [(set_attr "isa" "noavx,avx")
8536    (set_attr "type" "ssemov")
8537    (set_attr "length_immediate" "1")
8538    (set_attr "prefix_data16" "1,*")
8539    (set_attr "prefix_extra" "1")
8540    (set_attr "prefix" "orig,vex")
8541    (set_attr "btver2_decode" "vector,vector") 
8542    (set_attr "mode" "<MODE>")])
8543
8544 (define_insn "<sse4_1>_dp<ssemodesuffix><avxsizesuffix>"
8545   [(set (match_operand:VF 0 "register_operand" "=x,x")
8546         (unspec:VF
8547           [(match_operand:VF 1 "nonimmediate_operand" "%0,x")
8548            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")
8549            (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
8550           UNSPEC_DP))]
8551   "TARGET_SSE4_1"
8552   "@
8553    dp<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
8554    vdp<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
8555   [(set_attr "isa" "noavx,avx")
8556    (set_attr "type" "ssemul")
8557    (set_attr "length_immediate" "1")
8558    (set_attr "prefix_data16" "1,*")
8559    (set_attr "prefix_extra" "1")
8560    (set_attr "prefix" "orig,vex")
8561    (set_attr "btver2_decode" "vector,vector")
8562    (set_attr "mode" "<MODE>")])
8563
8564 (define_insn "<sse4_1_avx2>_movntdqa"
8565   [(set (match_operand:VI8_AVX2 0 "register_operand" "=x")
8566         (unspec:VI8_AVX2 [(match_operand:VI8_AVX2 1 "memory_operand" "m")]
8567                      UNSPEC_MOVNTDQA))]
8568   "TARGET_SSE4_1"
8569   "%vmovntdqa\t{%1, %0|%0, %1}"
8570   [(set_attr "type" "ssemov")
8571    (set_attr "prefix_extra" "1")
8572    (set_attr "prefix" "maybe_vex")
8573    (set_attr "mode" "<sseinsnmode>")])
8574
8575 (define_insn "<sse4_1_avx2>_mpsadbw"
8576   [(set (match_operand:VI1_AVX2 0 "register_operand" "=x,x")
8577         (unspec:VI1_AVX2
8578           [(match_operand:VI1_AVX2 1 "register_operand" "0,x")
8579            (match_operand:VI1_AVX2 2 "nonimmediate_operand" "xm,xm")
8580            (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
8581           UNSPEC_MPSADBW))]
8582   "TARGET_SSE4_1"
8583   "@
8584    mpsadbw\t{%3, %2, %0|%0, %2, %3}
8585    vmpsadbw\t{%3, %2, %1, %0|%0, %1, %2, %3}"
8586   [(set_attr "isa" "noavx,avx")
8587    (set_attr "type" "sselog1")
8588    (set_attr "length_immediate" "1")
8589    (set_attr "prefix_extra" "1")
8590    (set_attr "prefix" "orig,vex")
8591    (set_attr "btver2_decode" "vector,vector")
8592    (set_attr "mode" "<sseinsnmode>")])
8593
8594 (define_insn "avx2_packusdw"
8595   [(set (match_operand:V16HI 0 "register_operand" "=x")
8596         (vec_concat:V16HI
8597           (us_truncate:V8HI
8598             (match_operand:V8SI 1 "register_operand" "x"))
8599           (us_truncate:V8HI
8600             (match_operand:V8SI 2 "nonimmediate_operand" "xm"))))]
8601   "TARGET_AVX2"
8602   "vpackusdw\t{%2, %1, %0|%0, %1, %2}"
8603   [(set_attr "type" "sselog")
8604    (set_attr "prefix_extra" "1")
8605    (set_attr "prefix" "vex")
8606    (set_attr "mode" "OI")])
8607
8608 (define_insn "sse4_1_packusdw"
8609   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
8610         (vec_concat:V8HI
8611           (us_truncate:V4HI
8612             (match_operand:V4SI 1 "register_operand" "0,x"))
8613           (us_truncate:V4HI
8614             (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm"))))]
8615   "TARGET_SSE4_1"
8616   "@
8617    packusdw\t{%2, %0|%0, %2}
8618    vpackusdw\t{%2, %1, %0|%0, %1, %2}"
8619   [(set_attr "isa" "noavx,avx")
8620    (set_attr "type" "sselog")
8621    (set_attr "prefix_extra" "1")
8622    (set_attr "prefix" "orig,vex")
8623    (set_attr "mode" "TI")])
8624
8625 (define_insn "<sse4_1_avx2>_pblendvb"
8626   [(set (match_operand:VI1_AVX2 0 "register_operand" "=x,x")
8627         (unspec:VI1_AVX2
8628           [(match_operand:VI1_AVX2 1 "register_operand"  "0,x")
8629            (match_operand:VI1_AVX2 2 "nonimmediate_operand" "xm,xm")
8630            (match_operand:VI1_AVX2 3 "register_operand" "Yz,x")]
8631           UNSPEC_BLENDV))]
8632   "TARGET_SSE4_1"
8633   "@
8634    pblendvb\t{%3, %2, %0|%0, %2, %3}
8635    vpblendvb\t{%3, %2, %1, %0|%0, %1, %2, %3}"
8636   [(set_attr "isa" "noavx,avx")
8637    (set_attr "type" "ssemov")
8638    (set_attr "prefix_extra" "1")
8639    (set_attr "length_immediate" "*,1")
8640    (set_attr "prefix" "orig,vex")
8641    (set_attr "btver2_decode" "vector,vector")
8642    (set_attr "mode" "<sseinsnmode>")])
8643
8644 (define_insn "sse4_1_pblendw"
8645   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
8646         (vec_merge:V8HI
8647           (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
8648           (match_operand:V8HI 1 "register_operand" "0,x")
8649           (match_operand:SI 3 "const_0_to_255_operand" "n,n")))]
8650   "TARGET_SSE4_1"
8651   "@
8652    pblendw\t{%3, %2, %0|%0, %2, %3}
8653    vpblendw\t{%3, %2, %1, %0|%0, %1, %2, %3}"
8654   [(set_attr "isa" "noavx,avx")
8655    (set_attr "type" "ssemov")
8656    (set_attr "prefix_extra" "1")
8657    (set_attr "length_immediate" "1")
8658    (set_attr "prefix" "orig,vex")
8659    (set_attr "mode" "TI")])
8660
8661 ;; The builtin uses an 8-bit immediate.  Expand that.
8662 (define_expand "avx2_pblendw"
8663   [(set (match_operand:V16HI 0 "register_operand")
8664         (vec_merge:V16HI
8665           (match_operand:V16HI 2 "nonimmediate_operand")
8666           (match_operand:V16HI 1 "register_operand")
8667           (match_operand:SI 3 "const_0_to_255_operand")))]
8668   "TARGET_AVX2"
8669 {
8670   HOST_WIDE_INT val = INTVAL (operands[3]) & 0xff;
8671   operands[3] = GEN_INT (val << 8 | val);
8672 })
8673
8674 (define_insn "*avx2_pblendw"
8675   [(set (match_operand:V16HI 0 "register_operand" "=x")
8676         (vec_merge:V16HI
8677           (match_operand:V16HI 2 "nonimmediate_operand" "xm")
8678           (match_operand:V16HI 1 "register_operand" "x")
8679           (match_operand:SI 3 "avx2_pblendw_operand" "n")))]
8680   "TARGET_AVX2"
8681 {
8682   operands[3] = GEN_INT (INTVAL (operands[3]) & 0xff);
8683   return "vpblendw\t{%3, %2, %1, %0|%0, %1, %2, %3}";
8684 }
8685   [(set_attr "type" "ssemov")
8686    (set_attr "prefix_extra" "1")
8687    (set_attr "length_immediate" "1")
8688    (set_attr "prefix" "vex")
8689    (set_attr "mode" "OI")])
8690
8691 (define_insn "avx2_pblendd<mode>"
8692   [(set (match_operand:VI4_AVX2 0 "register_operand" "=x")
8693         (vec_merge:VI4_AVX2
8694           (match_operand:VI4_AVX2 2 "nonimmediate_operand" "xm")
8695           (match_operand:VI4_AVX2 1 "register_operand" "x")
8696           (match_operand:SI 3 "const_0_to_255_operand" "n")))]
8697   "TARGET_AVX2"
8698   "vpblendd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
8699   [(set_attr "type" "ssemov")
8700    (set_attr "prefix_extra" "1")
8701    (set_attr "length_immediate" "1")
8702    (set_attr "prefix" "vex")
8703    (set_attr "mode" "<sseinsnmode>")])
8704
8705 (define_insn "sse4_1_phminposuw"
8706   [(set (match_operand:V8HI 0 "register_operand" "=x")
8707         (unspec:V8HI [(match_operand:V8HI 1 "nonimmediate_operand" "xm")]
8708                      UNSPEC_PHMINPOSUW))]
8709   "TARGET_SSE4_1"
8710   "%vphminposuw\t{%1, %0|%0, %1}"
8711   [(set_attr "type" "sselog1")
8712    (set_attr "prefix_extra" "1")
8713    (set_attr "prefix" "maybe_vex")
8714    (set_attr "mode" "TI")])
8715
8716 (define_insn "avx2_<code>v16qiv16hi2"
8717   [(set (match_operand:V16HI 0 "register_operand" "=x")
8718         (any_extend:V16HI
8719           (match_operand:V16QI 1 "nonimmediate_operand" "xm")))]
8720   "TARGET_AVX2"
8721   "vpmov<extsuffix>bw\t{%1, %0|%0, %1}"
8722   [(set_attr "type" "ssemov")
8723    (set_attr "prefix_extra" "1")
8724    (set_attr "prefix" "vex")
8725    (set_attr "mode" "OI")])
8726
8727 (define_insn "sse4_1_<code>v8qiv8hi2"
8728   [(set (match_operand:V8HI 0 "register_operand" "=x")
8729         (any_extend:V8HI
8730           (vec_select:V8QI
8731             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
8732             (parallel [(const_int 0) (const_int 1)
8733                        (const_int 2) (const_int 3)
8734                        (const_int 4) (const_int 5)
8735                        (const_int 6) (const_int 7)]))))]
8736   "TARGET_SSE4_1"
8737   "%vpmov<extsuffix>bw\t{%1, %0|%0, %q1}"
8738   [(set_attr "type" "ssemov")
8739    (set_attr "prefix_extra" "1")
8740    (set_attr "prefix" "maybe_vex")
8741    (set_attr "mode" "TI")])
8742
8743 (define_insn "avx2_<code>v8qiv8si2"
8744   [(set (match_operand:V8SI 0 "register_operand" "=x")
8745         (any_extend:V8SI
8746           (vec_select:V8QI
8747             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
8748             (parallel [(const_int 0) (const_int 1)
8749                        (const_int 2) (const_int 3)
8750                        (const_int 4) (const_int 5)
8751                        (const_int 6) (const_int 7)]))))]
8752   "TARGET_AVX2"
8753   "vpmov<extsuffix>bd\t{%1, %0|%0, %q1}"
8754   [(set_attr "type" "ssemov")
8755    (set_attr "prefix_extra" "1")
8756    (set_attr "prefix" "vex")
8757    (set_attr "mode" "OI")])
8758
8759 (define_insn "sse4_1_<code>v4qiv4si2"
8760   [(set (match_operand:V4SI 0 "register_operand" "=x")
8761         (any_extend:V4SI
8762           (vec_select:V4QI
8763             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
8764             (parallel [(const_int 0) (const_int 1)
8765                        (const_int 2) (const_int 3)]))))]
8766   "TARGET_SSE4_1"
8767   "%vpmov<extsuffix>bd\t{%1, %0|%0, %k1}"
8768   [(set_attr "type" "ssemov")
8769    (set_attr "prefix_extra" "1")
8770    (set_attr "prefix" "maybe_vex")
8771    (set_attr "mode" "TI")])
8772
8773 (define_insn "avx2_<code>v8hiv8si2"
8774   [(set (match_operand:V8SI 0 "register_operand" "=x")
8775         (any_extend:V8SI
8776             (match_operand:V8HI 1 "nonimmediate_operand" "xm")))]
8777   "TARGET_AVX2"
8778   "vpmov<extsuffix>wd\t{%1, %0|%0, %1}"
8779   [(set_attr "type" "ssemov")
8780    (set_attr "prefix_extra" "1")
8781    (set_attr "prefix" "vex")
8782    (set_attr "mode" "OI")])
8783
8784 (define_insn "sse4_1_<code>v4hiv4si2"
8785   [(set (match_operand:V4SI 0 "register_operand" "=x")
8786         (any_extend:V4SI
8787           (vec_select:V4HI
8788             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
8789             (parallel [(const_int 0) (const_int 1)
8790                        (const_int 2) (const_int 3)]))))]
8791   "TARGET_SSE4_1"
8792   "%vpmov<extsuffix>wd\t{%1, %0|%0, %q1}"
8793   [(set_attr "type" "ssemov")
8794    (set_attr "prefix_extra" "1")
8795    (set_attr "prefix" "maybe_vex")
8796    (set_attr "mode" "TI")])
8797
8798 (define_insn "avx2_<code>v4qiv4di2"
8799   [(set (match_operand:V4DI 0 "register_operand" "=x")
8800         (any_extend:V4DI
8801           (vec_select:V4QI
8802             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
8803             (parallel [(const_int 0) (const_int 1)
8804                        (const_int 2) (const_int 3)]))))]
8805   "TARGET_AVX2"
8806   "vpmov<extsuffix>bq\t{%1, %0|%0, %k1}"
8807   [(set_attr "type" "ssemov")
8808    (set_attr "prefix_extra" "1")
8809    (set_attr "prefix" "vex")
8810    (set_attr "mode" "OI")])
8811
8812 (define_insn "sse4_1_<code>v2qiv2di2"
8813   [(set (match_operand:V2DI 0 "register_operand" "=x")
8814         (any_extend:V2DI
8815           (vec_select:V2QI
8816             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
8817             (parallel [(const_int 0) (const_int 1)]))))]
8818   "TARGET_SSE4_1"
8819   "%vpmov<extsuffix>bq\t{%1, %0|%0, %w1}"
8820   [(set_attr "type" "ssemov")
8821    (set_attr "prefix_extra" "1")
8822    (set_attr "prefix" "maybe_vex")
8823    (set_attr "mode" "TI")])
8824
8825 (define_insn "avx2_<code>v4hiv4di2"
8826   [(set (match_operand:V4DI 0 "register_operand" "=x")
8827         (any_extend:V4DI
8828           (vec_select:V4HI
8829             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
8830             (parallel [(const_int 0) (const_int 1)
8831                        (const_int 2) (const_int 3)]))))]
8832   "TARGET_AVX2"
8833   "vpmov<extsuffix>wq\t{%1, %0|%0, %q1}"
8834   [(set_attr "type" "ssemov")
8835    (set_attr "prefix_extra" "1")
8836    (set_attr "prefix" "vex")
8837    (set_attr "mode" "OI")])
8838
8839 (define_insn "sse4_1_<code>v2hiv2di2"
8840   [(set (match_operand:V2DI 0 "register_operand" "=x")
8841         (any_extend:V2DI
8842           (vec_select:V2HI
8843             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
8844             (parallel [(const_int 0) (const_int 1)]))))]
8845   "TARGET_SSE4_1"
8846   "%vpmov<extsuffix>wq\t{%1, %0|%0, %k1}"
8847   [(set_attr "type" "ssemov")
8848    (set_attr "prefix_extra" "1")
8849    (set_attr "prefix" "maybe_vex")
8850    (set_attr "mode" "TI")])
8851
8852 (define_insn "avx2_<code>v4siv4di2"
8853   [(set (match_operand:V4DI 0 "register_operand" "=x")
8854         (any_extend:V4DI
8855             (match_operand:V4SI 1 "nonimmediate_operand" "xm")))]
8856   "TARGET_AVX2"
8857   "vpmov<extsuffix>dq\t{%1, %0|%0, %1}"
8858   [(set_attr "type" "ssemov")
8859    (set_attr "prefix_extra" "1")
8860    (set_attr "mode" "OI")])
8861
8862 (define_insn "sse4_1_<code>v2siv2di2"
8863   [(set (match_operand:V2DI 0 "register_operand" "=x")
8864         (any_extend:V2DI
8865           (vec_select:V2SI
8866             (match_operand:V4SI 1 "nonimmediate_operand" "xm")
8867             (parallel [(const_int 0) (const_int 1)]))))]
8868   "TARGET_SSE4_1"
8869   "%vpmov<extsuffix>dq\t{%1, %0|%0, %q1}"
8870   [(set_attr "type" "ssemov")
8871    (set_attr "prefix_extra" "1")
8872    (set_attr "prefix" "maybe_vex")
8873    (set_attr "mode" "TI")])
8874
8875 ;; ptestps/ptestpd are very similar to comiss and ucomiss when
8876 ;; setting FLAGS_REG. But it is not a really compare instruction.
8877 (define_insn "avx_vtest<ssemodesuffix><avxsizesuffix>"
8878   [(set (reg:CC FLAGS_REG)
8879         (unspec:CC [(match_operand:VF 0 "register_operand" "x")
8880                     (match_operand:VF 1 "nonimmediate_operand" "xm")]
8881                    UNSPEC_VTESTP))]
8882   "TARGET_AVX"
8883   "vtest<ssemodesuffix>\t{%1, %0|%0, %1}"
8884   [(set_attr "type" "ssecomi")
8885    (set_attr "prefix_extra" "1")
8886    (set_attr "prefix" "vex")
8887    (set_attr "mode" "<MODE>")])
8888
8889 ;; ptest is very similar to comiss and ucomiss when setting FLAGS_REG.
8890 ;; But it is not a really compare instruction.
8891 (define_insn "avx_ptest256"
8892   [(set (reg:CC FLAGS_REG)
8893         (unspec:CC [(match_operand:V4DI 0 "register_operand" "x")
8894                     (match_operand:V4DI 1 "nonimmediate_operand" "xm")]
8895                    UNSPEC_PTEST))]
8896   "TARGET_AVX"
8897   "vptest\t{%1, %0|%0, %1}"
8898   [(set_attr "type" "ssecomi")
8899    (set_attr "prefix_extra" "1")
8900    (set_attr "prefix" "vex")
8901    (set_attr "btver2_decode" "vector")
8902    (set_attr "mode" "OI")])
8903
8904 (define_insn "sse4_1_ptest"
8905   [(set (reg:CC FLAGS_REG)
8906         (unspec:CC [(match_operand:V2DI 0 "register_operand" "x")
8907                     (match_operand:V2DI 1 "nonimmediate_operand" "xm")]
8908                    UNSPEC_PTEST))]
8909   "TARGET_SSE4_1"
8910   "%vptest\t{%1, %0|%0, %1}"
8911   [(set_attr "type" "ssecomi")
8912    (set_attr "prefix_extra" "1")
8913    (set_attr "prefix" "maybe_vex")
8914    (set_attr "mode" "TI")])
8915
8916 (define_insn "<sse4_1>_round<ssemodesuffix><avxsizesuffix>"
8917   [(set (match_operand:VF 0 "register_operand" "=x")
8918         (unspec:VF
8919           [(match_operand:VF 1 "nonimmediate_operand" "xm")
8920            (match_operand:SI 2 "const_0_to_15_operand" "n")]
8921           UNSPEC_ROUND))]
8922   "TARGET_ROUND"
8923   "%vround<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
8924   [(set_attr "type" "ssecvt")
8925    (set (attr "prefix_data16")
8926      (if_then_else
8927        (match_test "TARGET_AVX")
8928      (const_string "*")
8929      (const_string "1")))
8930    (set_attr "prefix_extra" "1")
8931    (set_attr "length_immediate" "1")
8932    (set_attr "prefix" "maybe_vex")
8933    (set_attr "mode" "<MODE>")])
8934
8935 (define_expand "<sse4_1>_round<ssemodesuffix>_sfix<avxsizesuffix>"
8936   [(match_operand:<sseintvecmode> 0 "register_operand")
8937    (match_operand:VF1 1 "nonimmediate_operand")
8938    (match_operand:SI 2 "const_0_to_15_operand")]
8939   "TARGET_ROUND"
8940 {
8941   rtx tmp = gen_reg_rtx (<MODE>mode);
8942
8943   emit_insn
8944     (gen_<sse4_1>_round<ssemodesuffix><avxsizesuffix> (tmp, operands[1],
8945                                                        operands[2]));
8946   emit_insn
8947     (gen_fix_trunc<mode><sseintvecmodelower>2 (operands[0], tmp));
8948   DONE;
8949 })
8950
8951 (define_expand "<sse4_1>_round<ssemodesuffix>_vec_pack_sfix<avxsizesuffix>"
8952   [(match_operand:<ssepackfltmode> 0 "register_operand")
8953    (match_operand:VF2 1 "nonimmediate_operand")
8954    (match_operand:VF2 2 "nonimmediate_operand")
8955    (match_operand:SI 3 "const_0_to_15_operand")]
8956   "TARGET_ROUND"
8957 {
8958   rtx tmp0, tmp1;
8959
8960   if (<MODE>mode == V2DFmode
8961       && TARGET_AVX && !TARGET_PREFER_AVX128)
8962     {
8963       rtx tmp2 = gen_reg_rtx (V4DFmode);
8964
8965       tmp0 = gen_reg_rtx (V4DFmode);
8966       tmp1 = force_reg (V2DFmode, operands[1]);
8967
8968       emit_insn (gen_avx_vec_concatv4df (tmp0, tmp1, operands[2]));
8969       emit_insn (gen_avx_roundpd256 (tmp2, tmp0, operands[3]));
8970       emit_insn (gen_fix_truncv4dfv4si2 (operands[0], tmp2));
8971     }
8972   else
8973     {
8974       tmp0 = gen_reg_rtx (<MODE>mode);
8975       tmp1 = gen_reg_rtx (<MODE>mode);
8976
8977       emit_insn
8978        (gen_<sse4_1>_round<ssemodesuffix><avxsizesuffix> (tmp0, operands[1],
8979                                                           operands[3]));
8980       emit_insn
8981        (gen_<sse4_1>_round<ssemodesuffix><avxsizesuffix> (tmp1, operands[2],
8982                                                           operands[3]));
8983       emit_insn
8984        (gen_vec_pack_sfix_trunc_<mode> (operands[0], tmp0, tmp1));
8985     }
8986   DONE;
8987 })
8988
8989 (define_insn "sse4_1_round<ssescalarmodesuffix>"
8990   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
8991         (vec_merge:VF_128
8992           (unspec:VF_128
8993             [(match_operand:VF_128 2 "register_operand" "x,x")
8994              (match_operand:SI 3 "const_0_to_15_operand" "n,n")]
8995             UNSPEC_ROUND)
8996           (match_operand:VF_128 1 "register_operand" "0,x")
8997           (const_int 1)))]
8998   "TARGET_ROUND"
8999   "@
9000    round<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}
9001    vround<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9002   [(set_attr "isa" "noavx,avx")
9003    (set_attr "type" "ssecvt")
9004    (set_attr "length_immediate" "1")
9005    (set_attr "prefix_data16" "1,*")
9006    (set_attr "prefix_extra" "1")
9007    (set_attr "prefix" "orig,vex")
9008    (set_attr "mode" "<MODE>")])
9009
9010 (define_expand "round<mode>2"
9011   [(set (match_dup 4)
9012         (plus:VF
9013           (match_operand:VF 1 "register_operand")
9014           (match_dup 3)))
9015    (set (match_operand:VF 0 "register_operand")
9016         (unspec:VF
9017           [(match_dup 4) (match_dup 5)]
9018           UNSPEC_ROUND))]
9019   "TARGET_ROUND && !flag_trapping_math"
9020 {
9021   enum machine_mode scalar_mode;
9022   const struct real_format *fmt;
9023   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
9024   rtx half, vec_half;
9025
9026   scalar_mode = GET_MODE_INNER (<MODE>mode);
9027
9028   /* load nextafter (0.5, 0.0) */
9029   fmt = REAL_MODE_FORMAT (scalar_mode);
9030   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, scalar_mode);
9031   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
9032   half = const_double_from_real_value (pred_half, scalar_mode);
9033
9034   vec_half = ix86_build_const_vector (<MODE>mode, true, half);
9035   vec_half = force_reg (<MODE>mode, vec_half);
9036
9037   operands[3] = gen_reg_rtx (<MODE>mode);
9038   emit_insn (gen_copysign<mode>3 (operands[3], vec_half, operands[1]));
9039
9040   operands[4] = gen_reg_rtx (<MODE>mode);
9041   operands[5] = GEN_INT (ROUND_TRUNC);
9042 })
9043
9044 (define_expand "round<mode>2_sfix"
9045   [(match_operand:<sseintvecmode> 0 "register_operand")
9046    (match_operand:VF1 1 "register_operand")]
9047   "TARGET_ROUND && !flag_trapping_math"
9048 {
9049   rtx tmp = gen_reg_rtx (<MODE>mode);
9050
9051   emit_insn (gen_round<mode>2 (tmp, operands[1]));
9052
9053   emit_insn
9054     (gen_fix_trunc<mode><sseintvecmodelower>2 (operands[0], tmp));
9055   DONE;
9056 })
9057
9058 (define_expand "round<mode>2_vec_pack_sfix"
9059   [(match_operand:<ssepackfltmode> 0 "register_operand")
9060    (match_operand:VF2 1 "register_operand")
9061    (match_operand:VF2 2 "register_operand")]
9062   "TARGET_ROUND && !flag_trapping_math"
9063 {
9064   rtx tmp0, tmp1;
9065
9066   if (<MODE>mode == V2DFmode
9067       && TARGET_AVX && !TARGET_PREFER_AVX128)
9068     {
9069       rtx tmp2 = gen_reg_rtx (V4DFmode);
9070
9071       tmp0 = gen_reg_rtx (V4DFmode);
9072       tmp1 = force_reg (V2DFmode, operands[1]);
9073
9074       emit_insn (gen_avx_vec_concatv4df (tmp0, tmp1, operands[2]));
9075       emit_insn (gen_roundv4df2 (tmp2, tmp0));
9076       emit_insn (gen_fix_truncv4dfv4si2 (operands[0], tmp2));
9077     }
9078   else
9079     {
9080       tmp0 = gen_reg_rtx (<MODE>mode);
9081       tmp1 = gen_reg_rtx (<MODE>mode);
9082
9083       emit_insn (gen_round<mode>2 (tmp0, operands[1]));
9084       emit_insn (gen_round<mode>2 (tmp1, operands[2]));
9085
9086       emit_insn
9087        (gen_vec_pack_sfix_trunc_<mode> (operands[0], tmp0, tmp1));
9088     }
9089   DONE;
9090 })
9091
9092 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9093 ;;
9094 ;; Intel SSE4.2 string/text processing instructions
9095 ;;
9096 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9097
9098 (define_insn_and_split "sse4_2_pcmpestr"
9099   [(set (match_operand:SI 0 "register_operand" "=c,c")
9100         (unspec:SI
9101           [(match_operand:V16QI 2 "register_operand" "x,x")
9102            (match_operand:SI 3 "register_operand" "a,a")
9103            (match_operand:V16QI 4 "nonimmediate_operand" "x,m")
9104            (match_operand:SI 5 "register_operand" "d,d")
9105            (match_operand:SI 6 "const_0_to_255_operand" "n,n")]
9106           UNSPEC_PCMPESTR))
9107    (set (match_operand:V16QI 1 "register_operand" "=Yz,Yz")
9108         (unspec:V16QI
9109           [(match_dup 2)
9110            (match_dup 3)
9111            (match_dup 4)
9112            (match_dup 5)
9113            (match_dup 6)]
9114           UNSPEC_PCMPESTR))
9115    (set (reg:CC FLAGS_REG)
9116         (unspec:CC
9117           [(match_dup 2)
9118            (match_dup 3)
9119            (match_dup 4)
9120            (match_dup 5)
9121            (match_dup 6)]
9122           UNSPEC_PCMPESTR))]
9123   "TARGET_SSE4_2
9124    && can_create_pseudo_p ()"
9125   "#"
9126   "&& 1"
9127   [(const_int 0)]
9128 {
9129   int ecx = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[0]));
9130   int xmm0 = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[1]));
9131   int flags = !find_regno_note (curr_insn, REG_UNUSED, FLAGS_REG);
9132
9133   if (ecx)
9134     emit_insn (gen_sse4_2_pcmpestri (operands[0], operands[2],
9135                                      operands[3], operands[4],
9136                                      operands[5], operands[6]));
9137   if (xmm0)
9138     emit_insn (gen_sse4_2_pcmpestrm (operands[1], operands[2],
9139                                      operands[3], operands[4],
9140                                      operands[5], operands[6]));
9141   if (flags && !(ecx || xmm0))
9142     emit_insn (gen_sse4_2_pcmpestr_cconly (NULL, NULL,
9143                                            operands[2], operands[3],
9144                                            operands[4], operands[5],
9145                                            operands[6]));
9146   if (!(flags || ecx || xmm0))
9147     emit_note (NOTE_INSN_DELETED);
9148
9149   DONE;
9150 }
9151   [(set_attr "type" "sselog")
9152    (set_attr "prefix_data16" "1")
9153    (set_attr "prefix_extra" "1")
9154    (set_attr "length_immediate" "1")
9155    (set_attr "memory" "none,load")
9156    (set_attr "mode" "TI")])
9157
9158 (define_insn_and_split "*sse4_2_pcmpestr_unaligned"
9159   [(set (match_operand:SI 0 "register_operand" "=c")
9160         (unspec:SI
9161           [(match_operand:V16QI 2 "register_operand" "x")
9162            (match_operand:SI 3 "register_operand" "a")
9163            (unspec:V16QI
9164              [(match_operand:V16QI 4 "memory_operand" "m")]
9165              UNSPEC_LOADU)
9166            (match_operand:SI 5 "register_operand" "d")
9167            (match_operand:SI 6 "const_0_to_255_operand" "n")]
9168           UNSPEC_PCMPESTR))
9169    (set (match_operand:V16QI 1 "register_operand" "=Yz")
9170         (unspec:V16QI
9171           [(match_dup 2)
9172            (match_dup 3)
9173            (unspec:V16QI [(match_dup 4)] UNSPEC_LOADU)
9174            (match_dup 5)
9175            (match_dup 6)]
9176           UNSPEC_PCMPESTR))
9177    (set (reg:CC FLAGS_REG)
9178         (unspec:CC
9179           [(match_dup 2)
9180            (match_dup 3)
9181            (unspec:V16QI [(match_dup 4)] UNSPEC_LOADU)
9182            (match_dup 5)
9183            (match_dup 6)]
9184           UNSPEC_PCMPESTR))]
9185   "TARGET_SSE4_2
9186    && can_create_pseudo_p ()"
9187   "#"
9188   "&& 1"
9189   [(const_int 0)]
9190 {
9191   int ecx = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[0]));
9192   int xmm0 = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[1]));
9193   int flags = !find_regno_note (curr_insn, REG_UNUSED, FLAGS_REG);
9194
9195   if (ecx)
9196     emit_insn (gen_sse4_2_pcmpestri (operands[0], operands[2],
9197                                      operands[3], operands[4],
9198                                      operands[5], operands[6]));
9199   if (xmm0)
9200     emit_insn (gen_sse4_2_pcmpestrm (operands[1], operands[2],
9201                                      operands[3], operands[4],
9202                                      operands[5], operands[6]));
9203   if (flags && !(ecx || xmm0))
9204     emit_insn (gen_sse4_2_pcmpestr_cconly (NULL, NULL,
9205                                            operands[2], operands[3],
9206                                            operands[4], operands[5],
9207                                            operands[6]));
9208   if (!(flags || ecx || xmm0))
9209     emit_note (NOTE_INSN_DELETED);
9210
9211   DONE;
9212 }
9213   [(set_attr "type" "sselog")
9214    (set_attr "prefix_data16" "1")
9215    (set_attr "prefix_extra" "1")
9216    (set_attr "length_immediate" "1")
9217    (set_attr "memory" "load")
9218    (set_attr "mode" "TI")])
9219
9220 (define_insn "sse4_2_pcmpestri"
9221   [(set (match_operand:SI 0 "register_operand" "=c,c")
9222         (unspec:SI
9223           [(match_operand:V16QI 1 "register_operand" "x,x")
9224            (match_operand:SI 2 "register_operand" "a,a")
9225            (match_operand:V16QI 3 "nonimmediate_operand" "x,m")
9226            (match_operand:SI 4 "register_operand" "d,d")
9227            (match_operand:SI 5 "const_0_to_255_operand" "n,n")]
9228           UNSPEC_PCMPESTR))
9229    (set (reg:CC FLAGS_REG)
9230         (unspec:CC
9231           [(match_dup 1)
9232            (match_dup 2)
9233            (match_dup 3)
9234            (match_dup 4)
9235            (match_dup 5)]
9236           UNSPEC_PCMPESTR))]
9237   "TARGET_SSE4_2"
9238   "%vpcmpestri\t{%5, %3, %1|%1, %3, %5}"
9239   [(set_attr "type" "sselog")
9240    (set_attr "prefix_data16" "1")
9241    (set_attr "prefix_extra" "1")
9242    (set_attr "prefix" "maybe_vex")
9243    (set_attr "length_immediate" "1")
9244    (set_attr "btver2_decode" "vector")
9245    (set_attr "memory" "none,load")
9246    (set_attr "mode" "TI")])
9247
9248 (define_insn "sse4_2_pcmpestrm"
9249   [(set (match_operand:V16QI 0 "register_operand" "=Yz,Yz")
9250         (unspec:V16QI
9251           [(match_operand:V16QI 1 "register_operand" "x,x")
9252            (match_operand:SI 2 "register_operand" "a,a")
9253            (match_operand:V16QI 3 "nonimmediate_operand" "x,m")
9254            (match_operand:SI 4 "register_operand" "d,d")
9255            (match_operand:SI 5 "const_0_to_255_operand" "n,n")]
9256           UNSPEC_PCMPESTR))
9257    (set (reg:CC FLAGS_REG)
9258         (unspec:CC
9259           [(match_dup 1)
9260            (match_dup 2)
9261            (match_dup 3)
9262            (match_dup 4)
9263            (match_dup 5)]
9264           UNSPEC_PCMPESTR))]
9265   "TARGET_SSE4_2"
9266   "%vpcmpestrm\t{%5, %3, %1|%1, %3, %5}"
9267   [(set_attr "type" "sselog")
9268    (set_attr "prefix_data16" "1")
9269    (set_attr "prefix_extra" "1")
9270    (set_attr "length_immediate" "1")
9271    (set_attr "prefix" "maybe_vex")
9272    (set_attr "btver2_decode" "vector")
9273    (set_attr "memory" "none,load")
9274    (set_attr "mode" "TI")])
9275
9276 (define_insn "sse4_2_pcmpestr_cconly"
9277   [(set (reg:CC FLAGS_REG)
9278         (unspec:CC
9279           [(match_operand:V16QI 2 "register_operand" "x,x,x,x")
9280            (match_operand:SI 3 "register_operand" "a,a,a,a")
9281            (match_operand:V16QI 4 "nonimmediate_operand" "x,m,x,m")
9282            (match_operand:SI 5 "register_operand" "d,d,d,d")
9283            (match_operand:SI 6 "const_0_to_255_operand" "n,n,n,n")]
9284           UNSPEC_PCMPESTR))
9285    (clobber (match_scratch:V16QI 0 "=Yz,Yz,X,X"))
9286    (clobber (match_scratch:SI    1 "= X, X,c,c"))]
9287   "TARGET_SSE4_2"
9288   "@
9289    %vpcmpestrm\t{%6, %4, %2|%2, %4, %6}
9290    %vpcmpestrm\t{%6, %4, %2|%2, %4, %6}
9291    %vpcmpestri\t{%6, %4, %2|%2, %4, %6}
9292    %vpcmpestri\t{%6, %4, %2|%2, %4, %6}"
9293   [(set_attr "type" "sselog")
9294    (set_attr "prefix_data16" "1")
9295    (set_attr "prefix_extra" "1")
9296    (set_attr "length_immediate" "1")
9297    (set_attr "memory" "none,load,none,load")
9298    (set_attr "btver2_decode" "vector,vector,vector,vector") 
9299    (set_attr "prefix" "maybe_vex")
9300    (set_attr "mode" "TI")])
9301
9302 (define_insn_and_split "sse4_2_pcmpistr"
9303   [(set (match_operand:SI 0 "register_operand" "=c,c")
9304         (unspec:SI
9305           [(match_operand:V16QI 2 "register_operand" "x,x")
9306            (match_operand:V16QI 3 "nonimmediate_operand" "x,m")
9307            (match_operand:SI 4 "const_0_to_255_operand" "n,n")]
9308           UNSPEC_PCMPISTR))
9309    (set (match_operand:V16QI 1 "register_operand" "=Yz,Yz")
9310         (unspec:V16QI
9311           [(match_dup 2)
9312            (match_dup 3)
9313            (match_dup 4)]
9314           UNSPEC_PCMPISTR))
9315    (set (reg:CC FLAGS_REG)
9316         (unspec:CC
9317           [(match_dup 2)
9318            (match_dup 3)
9319            (match_dup 4)]
9320           UNSPEC_PCMPISTR))]
9321   "TARGET_SSE4_2
9322    && can_create_pseudo_p ()"
9323   "#"
9324   "&& 1"
9325   [(const_int 0)]
9326 {
9327   int ecx = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[0]));
9328   int xmm0 = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[1]));
9329   int flags = !find_regno_note (curr_insn, REG_UNUSED, FLAGS_REG);
9330
9331   if (ecx)
9332     emit_insn (gen_sse4_2_pcmpistri (operands[0], operands[2],
9333                                      operands[3], operands[4]));
9334   if (xmm0)
9335     emit_insn (gen_sse4_2_pcmpistrm (operands[1], operands[2],
9336                                      operands[3], operands[4]));
9337   if (flags && !(ecx || xmm0))
9338     emit_insn (gen_sse4_2_pcmpistr_cconly (NULL, NULL,
9339                                            operands[2], operands[3],
9340                                            operands[4]));
9341   if (!(flags || ecx || xmm0))
9342     emit_note (NOTE_INSN_DELETED);
9343
9344   DONE;
9345 }
9346   [(set_attr "type" "sselog")
9347    (set_attr "prefix_data16" "1")
9348    (set_attr "prefix_extra" "1")
9349    (set_attr "length_immediate" "1")
9350    (set_attr "memory" "none,load")
9351    (set_attr "mode" "TI")])
9352
9353 (define_insn_and_split "*sse4_2_pcmpistr_unaligned"
9354   [(set (match_operand:SI 0 "register_operand" "=c")
9355         (unspec:SI
9356           [(match_operand:V16QI 2 "register_operand" "x")
9357            (unspec:V16QI
9358              [(match_operand:V16QI 3 "memory_operand" "m")]
9359              UNSPEC_LOADU)
9360            (match_operand:SI 4 "const_0_to_255_operand" "n")]
9361           UNSPEC_PCMPISTR))
9362    (set (match_operand:V16QI 1 "register_operand" "=Yz")
9363         (unspec:V16QI
9364           [(match_dup 2)
9365            (unspec:V16QI [(match_dup 3)] UNSPEC_LOADU)
9366            (match_dup 4)]
9367           UNSPEC_PCMPISTR))
9368    (set (reg:CC FLAGS_REG)
9369         (unspec:CC
9370           [(match_dup 2)
9371            (unspec:V16QI [(match_dup 3)] UNSPEC_LOADU)
9372            (match_dup 4)]
9373           UNSPEC_PCMPISTR))]
9374   "TARGET_SSE4_2
9375    && can_create_pseudo_p ()"
9376   "#"
9377   "&& 1"
9378   [(const_int 0)]
9379 {
9380   int ecx = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[0]));
9381   int xmm0 = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[1]));
9382   int flags = !find_regno_note (curr_insn, REG_UNUSED, FLAGS_REG);
9383
9384   if (ecx)
9385     emit_insn (gen_sse4_2_pcmpistri (operands[0], operands[2],
9386                                      operands[3], operands[4]));
9387   if (xmm0)
9388     emit_insn (gen_sse4_2_pcmpistrm (operands[1], operands[2],
9389                                      operands[3], operands[4]));
9390   if (flags && !(ecx || xmm0))
9391     emit_insn (gen_sse4_2_pcmpistr_cconly (NULL, NULL,
9392                                            operands[2], operands[3],
9393                                            operands[4]));
9394   if (!(flags || ecx || xmm0))
9395     emit_note (NOTE_INSN_DELETED);
9396
9397   DONE;
9398 }
9399   [(set_attr "type" "sselog")
9400    (set_attr "prefix_data16" "1")
9401    (set_attr "prefix_extra" "1")
9402    (set_attr "length_immediate" "1")
9403    (set_attr "memory" "load")
9404    (set_attr "mode" "TI")])
9405
9406 (define_insn "sse4_2_pcmpistri"
9407   [(set (match_operand:SI 0 "register_operand" "=c,c")
9408         (unspec:SI
9409           [(match_operand:V16QI 1 "register_operand" "x,x")
9410            (match_operand:V16QI 2 "nonimmediate_operand" "x,m")
9411            (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
9412           UNSPEC_PCMPISTR))
9413    (set (reg:CC FLAGS_REG)
9414         (unspec:CC
9415           [(match_dup 1)
9416            (match_dup 2)
9417            (match_dup 3)]
9418           UNSPEC_PCMPISTR))]
9419   "TARGET_SSE4_2"
9420   "%vpcmpistri\t{%3, %2, %1|%1, %2, %3}"
9421   [(set_attr "type" "sselog")
9422    (set_attr "prefix_data16" "1")
9423    (set_attr "prefix_extra" "1")
9424    (set_attr "length_immediate" "1")
9425    (set_attr "prefix" "maybe_vex")
9426    (set_attr "memory" "none,load")
9427    (set_attr "btver2_decode" "vector")
9428    (set_attr "mode" "TI")])
9429
9430 (define_insn "sse4_2_pcmpistrm"
9431   [(set (match_operand:V16QI 0 "register_operand" "=Yz,Yz")
9432         (unspec:V16QI
9433           [(match_operand:V16QI 1 "register_operand" "x,x")
9434            (match_operand:V16QI 2 "nonimmediate_operand" "x,m")
9435            (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
9436           UNSPEC_PCMPISTR))
9437    (set (reg:CC FLAGS_REG)
9438         (unspec:CC
9439           [(match_dup 1)
9440            (match_dup 2)
9441            (match_dup 3)]
9442           UNSPEC_PCMPISTR))]
9443   "TARGET_SSE4_2"
9444   "%vpcmpistrm\t{%3, %2, %1|%1, %2, %3}"
9445   [(set_attr "type" "sselog")
9446    (set_attr "prefix_data16" "1")
9447    (set_attr "prefix_extra" "1")
9448    (set_attr "length_immediate" "1")
9449    (set_attr "prefix" "maybe_vex")
9450    (set_attr "memory" "none,load")
9451    (set_attr "btver2_decode" "vector")
9452    (set_attr "mode" "TI")])
9453
9454 (define_insn "sse4_2_pcmpistr_cconly"
9455   [(set (reg:CC FLAGS_REG)
9456         (unspec:CC
9457           [(match_operand:V16QI 2 "register_operand" "x,x,x,x")
9458            (match_operand:V16QI 3 "nonimmediate_operand" "x,m,x,m")
9459            (match_operand:SI 4 "const_0_to_255_operand" "n,n,n,n")]
9460           UNSPEC_PCMPISTR))
9461    (clobber (match_scratch:V16QI 0 "=Yz,Yz,X,X"))
9462    (clobber (match_scratch:SI    1 "= X, X,c,c"))]
9463   "TARGET_SSE4_2"
9464   "@
9465    %vpcmpistrm\t{%4, %3, %2|%2, %3, %4}
9466    %vpcmpistrm\t{%4, %3, %2|%2, %3, %4}
9467    %vpcmpistri\t{%4, %3, %2|%2, %3, %4}
9468    %vpcmpistri\t{%4, %3, %2|%2, %3, %4}"
9469   [(set_attr "type" "sselog")
9470    (set_attr "prefix_data16" "1")
9471    (set_attr "prefix_extra" "1")
9472    (set_attr "length_immediate" "1")
9473    (set_attr "memory" "none,load,none,load")
9474    (set_attr "prefix" "maybe_vex")
9475    (set_attr "btver2_decode" "vector,vector,vector,vector")
9476    (set_attr "mode" "TI")])
9477
9478 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9479 ;;
9480 ;; XOP instructions
9481 ;;
9482 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9483
9484 (define_code_iterator xop_plus [plus ss_plus])
9485
9486 (define_code_attr macs [(plus "macs") (ss_plus "macss")])
9487 (define_code_attr madcs [(plus "madcs") (ss_plus "madcss")])
9488
9489 ;; XOP parallel integer multiply/add instructions.
9490
9491 (define_insn "xop_p<macs><ssemodesuffix><ssemodesuffix>"
9492   [(set (match_operand:VI24_128 0 "register_operand" "=x")
9493         (xop_plus:VI24_128
9494          (mult:VI24_128
9495           (match_operand:VI24_128 1 "nonimmediate_operand" "%x")
9496           (match_operand:VI24_128 2 "nonimmediate_operand" "xm"))
9497          (match_operand:VI24_128 3 "register_operand" "x")))]
9498   "TARGET_XOP"
9499   "vp<macs><ssemodesuffix><ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9500   [(set_attr "type" "ssemuladd")
9501    (set_attr "mode" "TI")])
9502
9503 (define_insn "xop_p<macs>dql"
9504   [(set (match_operand:V2DI 0 "register_operand" "=x")
9505         (xop_plus:V2DI
9506          (mult:V2DI
9507           (sign_extend:V2DI
9508            (vec_select:V2SI
9509             (match_operand:V4SI 1 "nonimmediate_operand" "%x")
9510             (parallel [(const_int 0) (const_int 2)])))
9511           (sign_extend:V2DI
9512            (vec_select:V2SI
9513             (match_operand:V4SI 2 "nonimmediate_operand" "xm")
9514             (parallel [(const_int 0) (const_int 2)]))))
9515          (match_operand:V2DI 3 "register_operand" "x")))]
9516   "TARGET_XOP"
9517   "vp<macs>dql\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9518   [(set_attr "type" "ssemuladd")
9519    (set_attr "mode" "TI")])
9520
9521 (define_insn "xop_p<macs>dqh"
9522   [(set (match_operand:V2DI 0 "register_operand" "=x")
9523         (xop_plus:V2DI
9524          (mult:V2DI
9525           (sign_extend:V2DI
9526            (vec_select:V2SI
9527             (match_operand:V4SI 1 "nonimmediate_operand" "%x")
9528             (parallel [(const_int 1) (const_int 3)])))
9529           (sign_extend:V2DI
9530            (vec_select:V2SI
9531             (match_operand:V4SI 2 "nonimmediate_operand" "xm")
9532             (parallel [(const_int 1) (const_int 3)]))))
9533          (match_operand:V2DI 3 "register_operand" "x")))]
9534   "TARGET_XOP"
9535   "vp<macs>dqh\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9536   [(set_attr "type" "ssemuladd")
9537    (set_attr "mode" "TI")])
9538
9539 ;; XOP parallel integer multiply/add instructions for the intrinisics
9540 (define_insn "xop_p<macs>wd"
9541   [(set (match_operand:V4SI 0 "register_operand" "=x")
9542         (xop_plus:V4SI
9543          (mult:V4SI
9544           (sign_extend:V4SI
9545            (vec_select:V4HI
9546             (match_operand:V8HI 1 "nonimmediate_operand" "%x")
9547             (parallel [(const_int 1) (const_int 3)
9548                        (const_int 5) (const_int 7)])))
9549           (sign_extend:V4SI
9550            (vec_select:V4HI
9551             (match_operand:V8HI 2 "nonimmediate_operand" "xm")
9552             (parallel [(const_int 1) (const_int 3)
9553                        (const_int 5) (const_int 7)]))))
9554          (match_operand:V4SI 3 "register_operand" "x")))]
9555   "TARGET_XOP"
9556   "vp<macs>wd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9557   [(set_attr "type" "ssemuladd")
9558    (set_attr "mode" "TI")])
9559
9560 (define_insn "xop_p<madcs>wd"
9561   [(set (match_operand:V4SI 0 "register_operand" "=x")
9562         (xop_plus:V4SI
9563          (plus:V4SI
9564           (mult:V4SI
9565            (sign_extend:V4SI
9566             (vec_select:V4HI
9567              (match_operand:V8HI 1 "nonimmediate_operand" "%x")
9568              (parallel [(const_int 0) (const_int 2)
9569                         (const_int 4) (const_int 6)])))
9570            (sign_extend:V4SI
9571             (vec_select:V4HI
9572              (match_operand:V8HI 2 "nonimmediate_operand" "xm")
9573              (parallel [(const_int 0) (const_int 2)
9574                         (const_int 4) (const_int 6)]))))
9575           (mult:V4SI
9576            (sign_extend:V4SI
9577             (vec_select:V4HI
9578              (match_dup 1)
9579              (parallel [(const_int 1) (const_int 3)
9580                         (const_int 5) (const_int 7)])))
9581            (sign_extend:V4SI
9582             (vec_select:V4HI
9583              (match_dup 2)
9584              (parallel [(const_int 1) (const_int 3)
9585                         (const_int 5) (const_int 7)])))))
9586          (match_operand:V4SI 3 "register_operand" "x")))]
9587   "TARGET_XOP"
9588   "vp<madcs>wd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9589   [(set_attr "type" "ssemuladd")
9590    (set_attr "mode" "TI")])
9591
9592 ;; XOP parallel XMM conditional moves
9593 (define_insn "xop_pcmov_<mode><avxsizesuffix>"
9594   [(set (match_operand:V 0 "register_operand" "=x,x")
9595         (if_then_else:V
9596           (match_operand:V 3 "nonimmediate_operand" "x,m")
9597           (match_operand:V 1 "register_operand" "x,x")
9598           (match_operand:V 2 "nonimmediate_operand" "xm,x")))]
9599   "TARGET_XOP"
9600   "vpcmov\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9601   [(set_attr "type" "sse4arg")])
9602
9603 ;; XOP horizontal add/subtract instructions
9604 (define_insn "xop_phadd<u>bw"
9605   [(set (match_operand:V8HI 0 "register_operand" "=x")
9606         (plus:V8HI
9607          (any_extend:V8HI
9608           (vec_select:V8QI
9609            (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9610            (parallel [(const_int 0) (const_int 2)
9611                       (const_int 4) (const_int 6)
9612                       (const_int 8) (const_int 10)
9613                       (const_int 12) (const_int 14)])))
9614          (any_extend:V8HI
9615           (vec_select:V8QI
9616            (match_dup 1)
9617            (parallel [(const_int 1) (const_int 3)
9618                       (const_int 5) (const_int 7)
9619                       (const_int 9) (const_int 11)
9620                       (const_int 13) (const_int 15)])))))]
9621   "TARGET_XOP"
9622   "vphadd<u>bw\t{%1, %0|%0, %1}"
9623   [(set_attr "type" "sseiadd1")])
9624
9625 (define_insn "xop_phadd<u>bd"
9626   [(set (match_operand:V4SI 0 "register_operand" "=x")
9627         (plus:V4SI
9628          (plus:V4SI
9629           (any_extend:V4SI
9630            (vec_select:V4QI
9631             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9632             (parallel [(const_int 0) (const_int 4)
9633                        (const_int 8) (const_int 12)])))
9634           (any_extend:V4SI
9635            (vec_select:V4QI
9636             (match_dup 1)
9637             (parallel [(const_int 1) (const_int 5)
9638                        (const_int 9) (const_int 13)]))))
9639          (plus:V4SI
9640           (any_extend:V4SI
9641            (vec_select:V4QI
9642             (match_dup 1)
9643             (parallel [(const_int 2) (const_int 6)
9644                        (const_int 10) (const_int 14)])))
9645           (any_extend:V4SI
9646            (vec_select:V4QI
9647             (match_dup 1)
9648             (parallel [(const_int 3) (const_int 7)
9649                        (const_int 11) (const_int 15)]))))))]
9650   "TARGET_XOP"
9651   "vphadd<u>bd\t{%1, %0|%0, %1}"
9652   [(set_attr "type" "sseiadd1")])
9653
9654 (define_insn "xop_phadd<u>bq"
9655   [(set (match_operand:V2DI 0 "register_operand" "=x")
9656         (plus:V2DI
9657          (plus:V2DI
9658           (plus:V2DI
9659            (any_extend:V2DI
9660             (vec_select:V2QI
9661              (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9662              (parallel [(const_int 0) (const_int 8)])))
9663            (any_extend:V2DI
9664             (vec_select:V2QI
9665              (match_dup 1)
9666              (parallel [(const_int 1) (const_int 9)]))))
9667           (plus:V2DI
9668            (any_extend:V2DI
9669             (vec_select:V2QI
9670              (match_dup 1)
9671              (parallel [(const_int 2) (const_int 10)])))
9672            (any_extend:V2DI
9673             (vec_select:V2QI
9674              (match_dup 1)
9675              (parallel [(const_int 3) (const_int 11)])))))
9676          (plus:V2DI
9677           (plus:V2DI
9678            (any_extend:V2DI
9679             (vec_select:V2QI
9680              (match_dup 1)
9681              (parallel [(const_int 4) (const_int 12)])))
9682            (any_extend:V2DI
9683             (vec_select:V2QI
9684              (match_dup 1)
9685              (parallel [(const_int 5) (const_int 13)]))))
9686           (plus:V2DI
9687            (any_extend:V2DI
9688             (vec_select:V2QI
9689              (match_dup 1)
9690              (parallel [(const_int 6) (const_int 14)])))
9691            (any_extend:V2DI
9692             (vec_select:V2QI
9693              (match_dup 1)
9694              (parallel [(const_int 7) (const_int 15)])))))))]
9695   "TARGET_XOP"
9696   "vphadd<u>bq\t{%1, %0|%0, %1}"
9697   [(set_attr "type" "sseiadd1")])
9698
9699 (define_insn "xop_phadd<u>wd"
9700   [(set (match_operand:V4SI 0 "register_operand" "=x")
9701         (plus:V4SI
9702          (any_extend:V4SI
9703           (vec_select:V4HI
9704            (match_operand:V8HI 1 "nonimmediate_operand" "xm")
9705            (parallel [(const_int 0) (const_int 2)
9706                       (const_int 4) (const_int 6)])))
9707          (any_extend:V4SI
9708           (vec_select:V4HI
9709            (match_dup 1)
9710            (parallel [(const_int 1) (const_int 3)
9711                       (const_int 5) (const_int 7)])))))]
9712   "TARGET_XOP"
9713   "vphadd<u>wd\t{%1, %0|%0, %1}"
9714   [(set_attr "type" "sseiadd1")])
9715
9716 (define_insn "xop_phadd<u>wq"
9717   [(set (match_operand:V2DI 0 "register_operand" "=x")
9718         (plus:V2DI
9719          (plus:V2DI
9720           (any_extend:V2DI
9721            (vec_select:V2HI
9722             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
9723             (parallel [(const_int 0) (const_int 4)])))
9724           (any_extend:V2DI
9725            (vec_select:V2HI
9726             (match_dup 1)
9727             (parallel [(const_int 1) (const_int 5)]))))
9728          (plus:V2DI
9729           (any_extend:V2DI
9730            (vec_select:V2HI
9731             (match_dup 1)
9732             (parallel [(const_int 2) (const_int 6)])))
9733           (any_extend:V2DI
9734            (vec_select:V2HI
9735             (match_dup 1)
9736             (parallel [(const_int 3) (const_int 7)]))))))]
9737   "TARGET_XOP"
9738   "vphadd<u>wq\t{%1, %0|%0, %1}"
9739   [(set_attr "type" "sseiadd1")])
9740
9741 (define_insn "xop_phadd<u>dq"
9742   [(set (match_operand:V2DI 0 "register_operand" "=x")
9743         (plus:V2DI
9744          (any_extend:V2DI
9745           (vec_select:V2SI
9746            (match_operand:V4SI 1 "nonimmediate_operand" "xm")
9747            (parallel [(const_int 0) (const_int 2)])))
9748          (any_extend:V2DI
9749           (vec_select:V2SI
9750            (match_dup 1)
9751            (parallel [(const_int 1) (const_int 3)])))))]
9752   "TARGET_XOP"
9753   "vphadd<u>dq\t{%1, %0|%0, %1}"
9754   [(set_attr "type" "sseiadd1")])
9755
9756 (define_insn "xop_phsubbw"
9757   [(set (match_operand:V8HI 0 "register_operand" "=x")
9758         (minus:V8HI
9759          (sign_extend:V8HI
9760           (vec_select:V8QI
9761            (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9762            (parallel [(const_int 0) (const_int 2)
9763                       (const_int 4) (const_int 6)
9764                       (const_int 8) (const_int 10)
9765                       (const_int 12) (const_int 14)])))
9766          (sign_extend:V8HI
9767           (vec_select:V8QI
9768            (match_dup 1)
9769            (parallel [(const_int 1) (const_int 3)
9770                       (const_int 5) (const_int 7)
9771                       (const_int 9) (const_int 11)
9772                       (const_int 13) (const_int 15)])))))]
9773   "TARGET_XOP"
9774   "vphsubbw\t{%1, %0|%0, %1}"
9775   [(set_attr "type" "sseiadd1")])
9776
9777 (define_insn "xop_phsubwd"
9778   [(set (match_operand:V4SI 0 "register_operand" "=x")
9779         (minus:V4SI
9780          (sign_extend:V4SI
9781           (vec_select:V4HI
9782            (match_operand:V8HI 1 "nonimmediate_operand" "xm")
9783            (parallel [(const_int 0) (const_int 2)
9784                       (const_int 4) (const_int 6)])))
9785          (sign_extend:V4SI
9786           (vec_select:V4HI
9787            (match_dup 1)
9788            (parallel [(const_int 1) (const_int 3)
9789                       (const_int 5) (const_int 7)])))))]
9790   "TARGET_XOP"
9791   "vphsubwd\t{%1, %0|%0, %1}"
9792   [(set_attr "type" "sseiadd1")])
9793
9794 (define_insn "xop_phsubdq"
9795   [(set (match_operand:V2DI 0 "register_operand" "=x")
9796         (minus:V2DI
9797          (sign_extend:V2DI
9798           (vec_select:V2SI
9799            (match_operand:V4SI 1 "nonimmediate_operand" "xm")
9800            (parallel [(const_int 0) (const_int 2)])))
9801          (sign_extend:V2DI
9802           (vec_select:V2SI
9803            (match_dup 1)
9804            (parallel [(const_int 1) (const_int 3)])))))]
9805   "TARGET_XOP"
9806   "vphsubdq\t{%1, %0|%0, %1}"
9807   [(set_attr "type" "sseiadd1")])
9808
9809 ;; XOP permute instructions
9810 (define_insn "xop_pperm"
9811   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
9812         (unspec:V16QI
9813           [(match_operand:V16QI 1 "register_operand" "x,x")
9814            (match_operand:V16QI 2 "nonimmediate_operand" "x,m")
9815            (match_operand:V16QI 3 "nonimmediate_operand" "xm,x")]
9816           UNSPEC_XOP_PERMUTE))]
9817   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
9818   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9819   [(set_attr "type" "sse4arg")
9820    (set_attr "mode" "TI")])
9821
9822 ;; XOP pack instructions that combine two vectors into a smaller vector
9823 (define_insn "xop_pperm_pack_v2di_v4si"
9824   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
9825         (vec_concat:V4SI
9826          (truncate:V2SI
9827           (match_operand:V2DI 1 "register_operand" "x,x"))
9828          (truncate:V2SI
9829           (match_operand:V2DI 2 "nonimmediate_operand" "x,m"))))
9830    (use (match_operand:V16QI 3 "nonimmediate_operand" "xm,x"))]
9831   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
9832   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9833   [(set_attr "type" "sse4arg")
9834    (set_attr "mode" "TI")])
9835
9836 (define_insn "xop_pperm_pack_v4si_v8hi"
9837   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
9838         (vec_concat:V8HI
9839          (truncate:V4HI
9840           (match_operand:V4SI 1 "register_operand" "x,x"))
9841          (truncate:V4HI
9842           (match_operand:V4SI 2 "nonimmediate_operand" "x,m"))))
9843    (use (match_operand:V16QI 3 "nonimmediate_operand" "xm,x"))]
9844   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
9845   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9846   [(set_attr "type" "sse4arg")
9847    (set_attr "mode" "TI")])
9848
9849 (define_insn "xop_pperm_pack_v8hi_v16qi"
9850   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
9851         (vec_concat:V16QI
9852          (truncate:V8QI
9853           (match_operand:V8HI 1 "register_operand" "x,x"))
9854          (truncate:V8QI
9855           (match_operand:V8HI 2 "nonimmediate_operand" "x,m"))))
9856    (use (match_operand:V16QI 3 "nonimmediate_operand" "xm,x"))]
9857   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
9858   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9859   [(set_attr "type" "sse4arg")
9860    (set_attr "mode" "TI")])
9861
9862 ;; XOP packed rotate instructions
9863 (define_expand "rotl<mode>3"
9864   [(set (match_operand:VI_128 0 "register_operand")
9865         (rotate:VI_128
9866          (match_operand:VI_128 1 "nonimmediate_operand")
9867          (match_operand:SI 2 "general_operand")))]
9868   "TARGET_XOP"
9869 {
9870   /* If we were given a scalar, convert it to parallel */
9871   if (! const_0_to_<sserotatemax>_operand (operands[2], SImode))
9872     {
9873       rtvec vs = rtvec_alloc (<ssescalarnum>);
9874       rtx par = gen_rtx_PARALLEL (<MODE>mode, vs);
9875       rtx reg = gen_reg_rtx (<MODE>mode);
9876       rtx op2 = operands[2];
9877       int i;
9878
9879       if (GET_MODE (op2) != <ssescalarmode>mode)
9880         {
9881           op2 = gen_reg_rtx (<ssescalarmode>mode);
9882           convert_move (op2, operands[2], false);
9883         }
9884
9885       for (i = 0; i < <ssescalarnum>; i++)
9886         RTVEC_ELT (vs, i) = op2;
9887
9888       emit_insn (gen_vec_init<mode> (reg, par));
9889       emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], reg));
9890       DONE;
9891     }
9892 })
9893
9894 (define_expand "rotr<mode>3"
9895   [(set (match_operand:VI_128 0 "register_operand")
9896         (rotatert:VI_128
9897          (match_operand:VI_128 1 "nonimmediate_operand")
9898          (match_operand:SI 2 "general_operand")))]
9899   "TARGET_XOP"
9900 {
9901   /* If we were given a scalar, convert it to parallel */
9902   if (! const_0_to_<sserotatemax>_operand (operands[2], SImode))
9903     {
9904       rtvec vs = rtvec_alloc (<ssescalarnum>);
9905       rtx par = gen_rtx_PARALLEL (<MODE>mode, vs);
9906       rtx neg = gen_reg_rtx (<MODE>mode);
9907       rtx reg = gen_reg_rtx (<MODE>mode);
9908       rtx op2 = operands[2];
9909       int i;
9910
9911       if (GET_MODE (op2) != <ssescalarmode>mode)
9912         {
9913           op2 = gen_reg_rtx (<ssescalarmode>mode);
9914           convert_move (op2, operands[2], false);
9915         }
9916
9917       for (i = 0; i < <ssescalarnum>; i++)
9918         RTVEC_ELT (vs, i) = op2;
9919
9920       emit_insn (gen_vec_init<mode> (reg, par));
9921       emit_insn (gen_neg<mode>2 (neg, reg));
9922       emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], neg));
9923       DONE;
9924     }
9925 })
9926
9927 (define_insn "xop_rotl<mode>3"
9928   [(set (match_operand:VI_128 0 "register_operand" "=x")
9929         (rotate:VI_128
9930          (match_operand:VI_128 1 "nonimmediate_operand" "xm")
9931          (match_operand:SI 2 "const_0_to_<sserotatemax>_operand" "n")))]
9932   "TARGET_XOP"
9933   "vprot<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
9934   [(set_attr "type" "sseishft")
9935    (set_attr "length_immediate" "1")
9936    (set_attr "mode" "TI")])
9937
9938 (define_insn "xop_rotr<mode>3"
9939   [(set (match_operand:VI_128 0 "register_operand" "=x")
9940         (rotatert:VI_128
9941          (match_operand:VI_128 1 "nonimmediate_operand" "xm")
9942          (match_operand:SI 2 "const_0_to_<sserotatemax>_operand" "n")))]
9943   "TARGET_XOP"
9944 {
9945   operands[3]
9946     = GEN_INT (GET_MODE_BITSIZE (<ssescalarmode>mode) - INTVAL (operands[2]));
9947   return \"vprot<ssemodesuffix>\t{%3, %1, %0|%0, %1, %3}\";
9948 }
9949   [(set_attr "type" "sseishft")
9950    (set_attr "length_immediate" "1")
9951    (set_attr "mode" "TI")])
9952
9953 (define_expand "vrotr<mode>3"
9954   [(match_operand:VI_128 0 "register_operand")
9955    (match_operand:VI_128 1 "register_operand")
9956    (match_operand:VI_128 2 "register_operand")]
9957   "TARGET_XOP"
9958 {
9959   rtx reg = gen_reg_rtx (<MODE>mode);
9960   emit_insn (gen_neg<mode>2 (reg, operands[2]));
9961   emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], reg));
9962   DONE;
9963 })
9964
9965 (define_expand "vrotl<mode>3"
9966   [(match_operand:VI_128 0 "register_operand")
9967    (match_operand:VI_128 1 "register_operand")
9968    (match_operand:VI_128 2 "register_operand")]
9969   "TARGET_XOP"
9970 {
9971   emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], operands[2]));
9972   DONE;
9973 })
9974
9975 (define_insn "xop_vrotl<mode>3"
9976   [(set (match_operand:VI_128 0 "register_operand" "=x,x")
9977         (if_then_else:VI_128
9978          (ge:VI_128
9979           (match_operand:VI_128 2 "nonimmediate_operand" "x,m")
9980           (const_int 0))
9981          (rotate:VI_128
9982           (match_operand:VI_128 1 "nonimmediate_operand" "xm,x")
9983           (match_dup 2))
9984          (rotatert:VI_128
9985           (match_dup 1)
9986           (neg:VI_128 (match_dup 2)))))]
9987   "TARGET_XOP && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
9988   "vprot<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
9989   [(set_attr "type" "sseishft")
9990    (set_attr "prefix_data16" "0")
9991    (set_attr "prefix_extra" "2")
9992    (set_attr "mode" "TI")])
9993
9994 ;; XOP packed shift instructions.
9995 (define_expand "vlshr<mode>3"
9996   [(set (match_operand:VI12_128 0 "register_operand")
9997         (lshiftrt:VI12_128
9998           (match_operand:VI12_128 1 "register_operand")
9999           (match_operand:VI12_128 2 "nonimmediate_operand")))]
10000   "TARGET_XOP"
10001 {
10002   rtx neg = gen_reg_rtx (<MODE>mode);
10003   emit_insn (gen_neg<mode>2 (neg, operands[2]));
10004   emit_insn (gen_xop_shl<mode>3 (operands[0], operands[1], neg));
10005   DONE;
10006 })
10007
10008 (define_expand "vlshr<mode>3"
10009   [(set (match_operand:VI48_128 0 "register_operand")
10010         (lshiftrt:VI48_128
10011           (match_operand:VI48_128 1 "register_operand")
10012           (match_operand:VI48_128 2 "nonimmediate_operand")))]
10013   "TARGET_AVX2 || TARGET_XOP"
10014 {
10015   if (!TARGET_AVX2)
10016     {
10017       rtx neg = gen_reg_rtx (<MODE>mode);
10018       emit_insn (gen_neg<mode>2 (neg, operands[2]));
10019       emit_insn (gen_xop_shl<mode>3 (operands[0], operands[1], neg));
10020       DONE;
10021     }
10022 })
10023
10024 (define_expand "vlshr<mode>3"
10025   [(set (match_operand:VI48_256 0 "register_operand")
10026         (lshiftrt:VI48_256
10027           (match_operand:VI48_256 1 "register_operand")
10028           (match_operand:VI48_256 2 "nonimmediate_operand")))]
10029   "TARGET_AVX2")
10030
10031 (define_expand "vashr<mode>3"
10032   [(set (match_operand:VI128_128 0 "register_operand")
10033         (ashiftrt:VI128_128
10034           (match_operand:VI128_128 1 "register_operand")
10035           (match_operand:VI128_128 2 "nonimmediate_operand")))]
10036   "TARGET_XOP"
10037 {
10038   rtx neg = gen_reg_rtx (<MODE>mode);
10039   emit_insn (gen_neg<mode>2 (neg, operands[2]));
10040   emit_insn (gen_xop_sha<mode>3 (operands[0], operands[1], neg));
10041   DONE;
10042 })
10043
10044 (define_expand "vashrv4si3"
10045   [(set (match_operand:V4SI 0 "register_operand")
10046         (ashiftrt:V4SI (match_operand:V4SI 1 "register_operand")
10047                        (match_operand:V4SI 2 "nonimmediate_operand")))]
10048   "TARGET_AVX2 || TARGET_XOP"
10049 {
10050   if (!TARGET_AVX2)
10051     {
10052       rtx neg = gen_reg_rtx (V4SImode);
10053       emit_insn (gen_negv4si2 (neg, operands[2]));
10054       emit_insn (gen_xop_shav4si3 (operands[0], operands[1], neg));
10055       DONE;
10056     }
10057 })
10058
10059 (define_expand "vashrv8si3"
10060   [(set (match_operand:V8SI 0 "register_operand")
10061         (ashiftrt:V8SI (match_operand:V8SI 1 "register_operand")
10062                        (match_operand:V8SI 2 "nonimmediate_operand")))]
10063   "TARGET_AVX2")
10064
10065 (define_expand "vashl<mode>3"
10066   [(set (match_operand:VI12_128 0 "register_operand")
10067         (ashift:VI12_128
10068           (match_operand:VI12_128 1 "register_operand")
10069           (match_operand:VI12_128 2 "nonimmediate_operand")))]
10070   "TARGET_XOP"
10071 {
10072   emit_insn (gen_xop_sha<mode>3 (operands[0], operands[1], operands[2]));
10073   DONE;
10074 })
10075
10076 (define_expand "vashl<mode>3"
10077   [(set (match_operand:VI48_128 0 "register_operand")
10078         (ashift:VI48_128
10079           (match_operand:VI48_128 1 "register_operand")
10080           (match_operand:VI48_128 2 "nonimmediate_operand")))]
10081   "TARGET_AVX2 || TARGET_XOP"
10082 {
10083   if (!TARGET_AVX2)
10084     {
10085       operands[2] = force_reg (<MODE>mode, operands[2]);
10086       emit_insn (gen_xop_sha<mode>3 (operands[0], operands[1], operands[2]));
10087       DONE;
10088     }
10089 })
10090
10091 (define_expand "vashl<mode>3"
10092   [(set (match_operand:VI48_256 0 "register_operand")
10093         (ashift:VI48_256
10094           (match_operand:VI48_256 1 "register_operand")
10095           (match_operand:VI48_256 2 "nonimmediate_operand")))]
10096   "TARGET_AVX2")
10097
10098 (define_insn "xop_sha<mode>3"
10099   [(set (match_operand:VI_128 0 "register_operand" "=x,x")
10100         (if_then_else:VI_128
10101          (ge:VI_128
10102           (match_operand:VI_128 2 "nonimmediate_operand" "x,m")
10103           (const_int 0))
10104          (ashift:VI_128
10105           (match_operand:VI_128 1 "nonimmediate_operand" "xm,x")
10106           (match_dup 2))
10107          (ashiftrt:VI_128
10108           (match_dup 1)
10109           (neg:VI_128 (match_dup 2)))))]
10110   "TARGET_XOP && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
10111   "vpsha<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
10112   [(set_attr "type" "sseishft")
10113    (set_attr "prefix_data16" "0")
10114    (set_attr "prefix_extra" "2")
10115    (set_attr "mode" "TI")])
10116
10117 (define_insn "xop_shl<mode>3"
10118   [(set (match_operand:VI_128 0 "register_operand" "=x,x")
10119         (if_then_else:VI_128
10120          (ge:VI_128
10121           (match_operand:VI_128 2 "nonimmediate_operand" "x,m")
10122           (const_int 0))
10123          (ashift:VI_128
10124           (match_operand:VI_128 1 "nonimmediate_operand" "xm,x")
10125           (match_dup 2))
10126          (lshiftrt:VI_128
10127           (match_dup 1)
10128           (neg:VI_128 (match_dup 2)))))]
10129   "TARGET_XOP && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
10130   "vpshl<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
10131   [(set_attr "type" "sseishft")
10132    (set_attr "prefix_data16" "0")
10133    (set_attr "prefix_extra" "2")
10134    (set_attr "mode" "TI")])
10135
10136 (define_expand "<shift_insn><mode>3"
10137   [(set (match_operand:VI1_AVX2 0 "register_operand")
10138         (any_shift:VI1_AVX2
10139           (match_operand:VI1_AVX2 1 "register_operand")
10140           (match_operand:SI 2 "nonmemory_operand")))]
10141   "TARGET_SSE2"
10142 {
10143   if (TARGET_XOP && <MODE>mode == V16QImode)
10144     {
10145       bool negate = false;
10146       rtx (*gen) (rtx, rtx, rtx);
10147       rtx tmp, par;
10148       int i;
10149
10150       if (<CODE> != ASHIFT)
10151         {
10152           if (CONST_INT_P (operands[2]))
10153             operands[2] = GEN_INT (-INTVAL (operands[2]));
10154           else
10155             negate = true;
10156         }
10157       par = gen_rtx_PARALLEL (V16QImode, rtvec_alloc (16));
10158       for (i = 0; i < 16; i++)
10159         XVECEXP (par, 0, i) = operands[2];
10160
10161       tmp = gen_reg_rtx (V16QImode);
10162       emit_insn (gen_vec_initv16qi (tmp, par));
10163
10164       if (negate)
10165         emit_insn (gen_negv16qi2 (tmp, tmp));
10166
10167       gen = (<CODE> == LSHIFTRT ? gen_xop_shlv16qi3 : gen_xop_shav16qi3);
10168       emit_insn (gen (operands[0], operands[1], tmp));
10169     }
10170   else
10171     ix86_expand_vecop_qihi (<CODE>, operands[0], operands[1], operands[2]);
10172   DONE;
10173 })
10174
10175 (define_expand "ashrv2di3"
10176   [(set (match_operand:V2DI 0 "register_operand")
10177         (ashiftrt:V2DI
10178           (match_operand:V2DI 1 "register_operand")
10179           (match_operand:DI 2 "nonmemory_operand")))]
10180   "TARGET_XOP"
10181 {
10182   rtx reg = gen_reg_rtx (V2DImode);
10183   rtx par;
10184   bool negate = false;
10185   int i;
10186
10187   if (CONST_INT_P (operands[2]))
10188     operands[2] = GEN_INT (-INTVAL (operands[2]));
10189   else
10190     negate = true;
10191
10192   par = gen_rtx_PARALLEL (V2DImode, rtvec_alloc (2));
10193   for (i = 0; i < 2; i++)
10194     XVECEXP (par, 0, i) = operands[2];
10195
10196   emit_insn (gen_vec_initv2di (reg, par));
10197
10198   if (negate)
10199     emit_insn (gen_negv2di2 (reg, reg));
10200
10201   emit_insn (gen_xop_shav2di3 (operands[0], operands[1], reg));
10202   DONE;
10203 })
10204
10205 ;; XOP FRCZ support
10206 (define_insn "xop_frcz<mode>2"
10207   [(set (match_operand:FMAMODE 0 "register_operand" "=x")
10208         (unspec:FMAMODE
10209          [(match_operand:FMAMODE 1 "nonimmediate_operand" "xm")]
10210          UNSPEC_FRCZ))]
10211   "TARGET_XOP"
10212   "vfrcz<ssemodesuffix>\t{%1, %0|%0, %1}"
10213   [(set_attr "type" "ssecvt1")
10214    (set_attr "mode" "<MODE>")])
10215
10216 ;; scalar insns
10217 (define_expand "xop_vmfrcz<mode>2"
10218   [(set (match_operand:VF_128 0 "register_operand")
10219         (vec_merge:VF_128
10220           (unspec:VF_128
10221            [(match_operand:VF_128 1 "nonimmediate_operand")]
10222            UNSPEC_FRCZ)
10223           (match_dup 3)
10224           (const_int 1)))]
10225   "TARGET_XOP"
10226 {
10227   operands[3] = CONST0_RTX (<MODE>mode);
10228 })
10229
10230 (define_insn "*xop_vmfrcz_<mode>"
10231   [(set (match_operand:VF_128 0 "register_operand" "=x")
10232         (vec_merge:VF_128
10233           (unspec:VF_128
10234            [(match_operand:VF_128 1 "nonimmediate_operand" "xm")]
10235            UNSPEC_FRCZ)
10236           (match_operand:VF_128 2 "const0_operand")
10237           (const_int 1)))]
10238   "TARGET_XOP"
10239   "vfrcz<ssescalarmodesuffix>\t{%1, %0|%0, %1}"
10240   [(set_attr "type" "ssecvt1")
10241    (set_attr "mode" "<MODE>")])
10242
10243 (define_insn "xop_maskcmp<mode>3"
10244   [(set (match_operand:VI_128 0 "register_operand" "=x")
10245         (match_operator:VI_128 1 "ix86_comparison_int_operator"
10246          [(match_operand:VI_128 2 "register_operand" "x")
10247           (match_operand:VI_128 3 "nonimmediate_operand" "xm")]))]
10248   "TARGET_XOP"
10249   "vpcom%Y1<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}"
10250   [(set_attr "type" "sse4arg")
10251    (set_attr "prefix_data16" "0")
10252    (set_attr "prefix_rep" "0")
10253    (set_attr "prefix_extra" "2")
10254    (set_attr "length_immediate" "1")
10255    (set_attr "mode" "TI")])
10256
10257 (define_insn "xop_maskcmp_uns<mode>3"
10258   [(set (match_operand:VI_128 0 "register_operand" "=x")
10259         (match_operator:VI_128 1 "ix86_comparison_uns_operator"
10260          [(match_operand:VI_128 2 "register_operand" "x")
10261           (match_operand:VI_128 3 "nonimmediate_operand" "xm")]))]
10262   "TARGET_XOP"
10263   "vpcom%Y1u<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}"
10264   [(set_attr "type" "ssecmp")
10265    (set_attr "prefix_data16" "0")
10266    (set_attr "prefix_rep" "0")
10267    (set_attr "prefix_extra" "2")
10268    (set_attr "length_immediate" "1")
10269    (set_attr "mode" "TI")])
10270
10271 ;; Version of pcom*u* that is called from the intrinsics that allows pcomequ*
10272 ;; and pcomneu* not to be converted to the signed ones in case somebody needs
10273 ;; the exact instruction generated for the intrinsic.
10274 (define_insn "xop_maskcmp_uns2<mode>3"
10275   [(set (match_operand:VI_128 0 "register_operand" "=x")
10276         (unspec:VI_128
10277          [(match_operator:VI_128 1 "ix86_comparison_uns_operator"
10278           [(match_operand:VI_128 2 "register_operand" "x")
10279            (match_operand:VI_128 3 "nonimmediate_operand" "xm")])]
10280          UNSPEC_XOP_UNSIGNED_CMP))]
10281   "TARGET_XOP"
10282   "vpcom%Y1u<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}"
10283   [(set_attr "type" "ssecmp")
10284    (set_attr "prefix_data16" "0")
10285    (set_attr "prefix_extra" "2")
10286    (set_attr "length_immediate" "1")
10287    (set_attr "mode" "TI")])
10288
10289 ;; Pcomtrue and pcomfalse support.  These are useless instructions, but are
10290 ;; being added here to be complete.
10291 (define_insn "xop_pcom_tf<mode>3"
10292   [(set (match_operand:VI_128 0 "register_operand" "=x")
10293         (unspec:VI_128
10294           [(match_operand:VI_128 1 "register_operand" "x")
10295            (match_operand:VI_128 2 "nonimmediate_operand" "xm")
10296            (match_operand:SI 3 "const_int_operand" "n")]
10297           UNSPEC_XOP_TRUEFALSE))]
10298   "TARGET_XOP"
10299 {
10300   return ((INTVAL (operands[3]) != 0)
10301           ? "vpcomtrue<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
10302           : "vpcomfalse<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}");
10303 }
10304   [(set_attr "type" "ssecmp")
10305    (set_attr "prefix_data16" "0")
10306    (set_attr "prefix_extra" "2")
10307    (set_attr "length_immediate" "1")
10308    (set_attr "mode" "TI")])
10309
10310 (define_insn "xop_vpermil2<mode>3"
10311   [(set (match_operand:VF 0 "register_operand" "=x")
10312         (unspec:VF
10313           [(match_operand:VF 1 "register_operand" "x")
10314            (match_operand:VF 2 "nonimmediate_operand" "%x")
10315            (match_operand:<sseintvecmode> 3 "nonimmediate_operand" "xm")
10316            (match_operand:SI 4 "const_0_to_3_operand" "n")]
10317           UNSPEC_VPERMIL2))]
10318   "TARGET_XOP"
10319   "vpermil2<ssemodesuffix>\t{%4, %3, %2, %1, %0|%0, %1, %2, %3, %4}"
10320   [(set_attr "type" "sse4arg")
10321    (set_attr "length_immediate" "1")
10322    (set_attr "mode" "<MODE>")])
10323
10324 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10325
10326 (define_insn "aesenc"
10327   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
10328         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
10329                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
10330                       UNSPEC_AESENC))]
10331   "TARGET_AES"
10332   "@
10333    aesenc\t{%2, %0|%0, %2}
10334    vaesenc\t{%2, %1, %0|%0, %1, %2}"
10335   [(set_attr "isa" "noavx,avx")
10336    (set_attr "type" "sselog1")
10337    (set_attr "prefix_extra" "1")
10338    (set_attr "prefix" "orig,vex")
10339    (set_attr "btver2_decode" "double,double")
10340    (set_attr "mode" "TI")])
10341
10342 (define_insn "aesenclast"
10343   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
10344         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
10345                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
10346                       UNSPEC_AESENCLAST))]
10347   "TARGET_AES"
10348   "@
10349    aesenclast\t{%2, %0|%0, %2}
10350    vaesenclast\t{%2, %1, %0|%0, %1, %2}"
10351   [(set_attr "isa" "noavx,avx")
10352    (set_attr "type" "sselog1")
10353    (set_attr "prefix_extra" "1")
10354    (set_attr "prefix" "orig,vex")
10355    (set_attr "btver2_decode" "double,double") 
10356    (set_attr "mode" "TI")])
10357
10358 (define_insn "aesdec"
10359   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
10360         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
10361                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
10362                       UNSPEC_AESDEC))]
10363   "TARGET_AES"
10364   "@
10365    aesdec\t{%2, %0|%0, %2}
10366    vaesdec\t{%2, %1, %0|%0, %1, %2}"
10367   [(set_attr "isa" "noavx,avx")
10368    (set_attr "type" "sselog1")
10369    (set_attr "prefix_extra" "1")
10370    (set_attr "prefix" "orig,vex")
10371    (set_attr "btver2_decode" "double,double") 
10372    (set_attr "mode" "TI")])
10373
10374 (define_insn "aesdeclast"
10375   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
10376         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
10377                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
10378                       UNSPEC_AESDECLAST))]
10379   "TARGET_AES"
10380   "@
10381    aesdeclast\t{%2, %0|%0, %2}
10382    vaesdeclast\t{%2, %1, %0|%0, %1, %2}"
10383   [(set_attr "isa" "noavx,avx")
10384    (set_attr "type" "sselog1")
10385    (set_attr "prefix_extra" "1")
10386    (set_attr "prefix" "orig,vex")
10387    (set_attr "btver2_decode" "double,double")
10388    (set_attr "mode" "TI")])
10389
10390 (define_insn "aesimc"
10391   [(set (match_operand:V2DI 0 "register_operand" "=x")
10392         (unspec:V2DI [(match_operand:V2DI 1 "nonimmediate_operand" "xm")]
10393                       UNSPEC_AESIMC))]
10394   "TARGET_AES"
10395   "%vaesimc\t{%1, %0|%0, %1}"
10396   [(set_attr "type" "sselog1")
10397    (set_attr "prefix_extra" "1")
10398    (set_attr "prefix" "maybe_vex")
10399    (set_attr "mode" "TI")])
10400
10401 (define_insn "aeskeygenassist"
10402   [(set (match_operand:V2DI 0 "register_operand" "=x")
10403         (unspec:V2DI [(match_operand:V2DI 1 "nonimmediate_operand" "xm")
10404                       (match_operand:SI 2 "const_0_to_255_operand" "n")]
10405                      UNSPEC_AESKEYGENASSIST))]
10406   "TARGET_AES"
10407   "%vaeskeygenassist\t{%2, %1, %0|%0, %1, %2}"
10408   [(set_attr "type" "sselog1")
10409    (set_attr "prefix_extra" "1")
10410    (set_attr "length_immediate" "1")
10411    (set_attr "prefix" "maybe_vex")
10412    (set_attr "mode" "TI")])
10413
10414 (define_insn "pclmulqdq"
10415   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
10416         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
10417                       (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")
10418                       (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
10419                      UNSPEC_PCLMUL))]
10420   "TARGET_PCLMUL"
10421   "@
10422    pclmulqdq\t{%3, %2, %0|%0, %2, %3}
10423    vpclmulqdq\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10424   [(set_attr "isa" "noavx,avx")
10425    (set_attr "type" "sselog1")
10426    (set_attr "prefix_extra" "1")
10427    (set_attr "length_immediate" "1")
10428    (set_attr "prefix" "orig,vex")
10429    (set_attr "mode" "TI")])
10430
10431 (define_expand "avx_vzeroall"
10432   [(match_par_dup 0 [(const_int 0)])]
10433   "TARGET_AVX"
10434 {
10435   int nregs = TARGET_64BIT ? 16 : 8;
10436   int regno;
10437
10438   operands[0] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nregs + 1));
10439
10440   XVECEXP (operands[0], 0, 0)
10441     = gen_rtx_UNSPEC_VOLATILE (VOIDmode, gen_rtvec (1, const0_rtx),
10442                                UNSPECV_VZEROALL);
10443
10444   for (regno = 0; regno < nregs; regno++)
10445     XVECEXP (operands[0], 0, regno + 1)
10446       = gen_rtx_SET (VOIDmode,
10447                      gen_rtx_REG (V8SImode, SSE_REGNO (regno)),
10448                      CONST0_RTX (V8SImode));
10449 })
10450
10451 (define_insn "*avx_vzeroall"
10452   [(match_parallel 0 "vzeroall_operation"
10453     [(unspec_volatile [(const_int 0)] UNSPECV_VZEROALL)])]
10454   "TARGET_AVX"
10455   "vzeroall"
10456   [(set_attr "type" "sse")
10457    (set_attr "modrm" "0")
10458    (set_attr "memory" "none")
10459    (set_attr "prefix" "vex")
10460    (set_attr "btver2_decode" "vector")
10461    (set_attr "mode" "OI")])
10462
10463 ;; Clear the upper 128bits of AVX registers, equivalent to a NOP
10464 ;; if the upper 128bits are unused.
10465 (define_insn "avx_vzeroupper"
10466   [(unspec_volatile [(const_int 0)] UNSPECV_VZEROUPPER)]
10467   "TARGET_AVX"
10468   "vzeroupper"
10469   [(set_attr "type" "sse")
10470    (set_attr "modrm" "0")
10471    (set_attr "memory" "none")
10472    (set_attr "prefix" "vex")
10473    (set_attr "btver2_decode" "vector")
10474    (set_attr "mode" "OI")])
10475
10476 (define_mode_attr AVXTOSSEMODE
10477   [(V4DI "V2DI") (V2DI "V2DI")
10478    (V8SI "V4SI") (V4SI "V4SI")
10479    (V16HI "V8HI") (V8HI "V8HI")
10480    (V32QI "V16QI") (V16QI "V16QI")])
10481
10482 (define_insn "avx2_pbroadcast<mode>"
10483   [(set (match_operand:VI 0 "register_operand" "=x")
10484         (vec_duplicate:VI
10485           (vec_select:<ssescalarmode>
10486             (match_operand:<AVXTOSSEMODE> 1 "nonimmediate_operand" "xm")
10487             (parallel [(const_int 0)]))))]
10488   "TARGET_AVX2"
10489   "vpbroadcast<ssemodesuffix>\t{%1, %0|%0, %1}"
10490   [(set_attr "type" "ssemov")
10491    (set_attr "prefix_extra" "1")
10492    (set_attr "prefix" "vex")
10493    (set_attr "mode" "<sseinsnmode>")])
10494
10495 (define_insn "avx2_pbroadcast<mode>_1"
10496   [(set (match_operand:VI_256 0 "register_operand" "=x")
10497         (vec_duplicate:VI_256
10498           (vec_select:<ssescalarmode>
10499             (match_operand:VI_256 1 "nonimmediate_operand" "xm")
10500             (parallel [(const_int 0)]))))]
10501   "TARGET_AVX2"
10502   "vpbroadcast<ssemodesuffix>\t{%x1, %0|%0, %x1}"
10503   [(set_attr "type" "ssemov")
10504    (set_attr "prefix_extra" "1")
10505    (set_attr "prefix" "vex")
10506    (set_attr "mode" "<sseinsnmode>")])
10507
10508 (define_insn "avx2_permvar<mode>"
10509   [(set (match_operand:VI4F_256 0 "register_operand" "=x")
10510         (unspec:VI4F_256
10511           [(match_operand:VI4F_256 1 "nonimmediate_operand" "xm")
10512            (match_operand:V8SI 2 "register_operand" "x")]
10513           UNSPEC_VPERMVAR))]
10514   "TARGET_AVX2"
10515   "vperm<ssemodesuffix>\t{%1, %2, %0|%0, %2, %1}"
10516   [(set_attr "type" "sselog")
10517    (set_attr "prefix" "vex")
10518    (set_attr "mode" "OI")])
10519
10520 (define_expand "avx2_perm<mode>"
10521   [(match_operand:VI8F_256 0 "register_operand")
10522    (match_operand:VI8F_256 1 "nonimmediate_operand")
10523    (match_operand:SI 2 "const_0_to_255_operand")]
10524   "TARGET_AVX2"
10525 {
10526   int mask = INTVAL (operands[2]);
10527   emit_insn (gen_avx2_perm<mode>_1 (operands[0], operands[1],
10528                                     GEN_INT ((mask >> 0) & 3),
10529                                     GEN_INT ((mask >> 2) & 3),
10530                                     GEN_INT ((mask >> 4) & 3),
10531                                     GEN_INT ((mask >> 6) & 3)));
10532   DONE;
10533 })
10534
10535 (define_insn "avx2_perm<mode>_1"
10536   [(set (match_operand:VI8F_256 0 "register_operand" "=x")
10537         (vec_select:VI8F_256
10538           (match_operand:VI8F_256 1 "nonimmediate_operand" "xm")
10539           (parallel [(match_operand 2 "const_0_to_3_operand")
10540                      (match_operand 3 "const_0_to_3_operand")
10541                      (match_operand 4 "const_0_to_3_operand")
10542                      (match_operand 5 "const_0_to_3_operand")])))]
10543   "TARGET_AVX2"
10544 {
10545   int mask = 0;
10546   mask |= INTVAL (operands[2]) << 0;
10547   mask |= INTVAL (operands[3]) << 2;
10548   mask |= INTVAL (operands[4]) << 4;
10549   mask |= INTVAL (operands[5]) << 6;
10550   operands[2] = GEN_INT (mask);
10551   return "vperm<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}";
10552 }
10553   [(set_attr "type" "sselog")
10554    (set_attr "prefix" "vex")
10555    (set_attr "mode" "<sseinsnmode>")])
10556
10557 (define_insn "avx2_permv2ti"
10558   [(set (match_operand:V4DI 0 "register_operand" "=x")
10559         (unspec:V4DI
10560           [(match_operand:V4DI 1 "register_operand" "x")
10561            (match_operand:V4DI 2 "nonimmediate_operand" "xm")
10562            (match_operand:SI 3 "const_0_to_255_operand" "n")]
10563           UNSPEC_VPERMTI))]
10564   "TARGET_AVX2"
10565   "vperm2i128\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10566   [(set_attr "type" "sselog")
10567    (set_attr "prefix" "vex")
10568    (set_attr "mode" "OI")])
10569
10570 (define_insn "avx2_vec_dupv4df"
10571   [(set (match_operand:V4DF 0 "register_operand" "=x")
10572         (vec_duplicate:V4DF
10573           (vec_select:DF
10574             (match_operand:V2DF 1 "register_operand" "x")
10575             (parallel [(const_int 0)]))))]
10576   "TARGET_AVX2"
10577   "vbroadcastsd\t{%1, %0|%0, %1}"
10578   [(set_attr "type" "sselog1")
10579    (set_attr "prefix" "vex")
10580    (set_attr "mode" "V4DF")])
10581
10582 ;; Modes handled by AVX vec_dup patterns.
10583 (define_mode_iterator AVX_VEC_DUP_MODE
10584   [V8SI V8SF V4DI V4DF])
10585
10586 (define_insn "vec_dup<mode>"
10587   [(set (match_operand:AVX_VEC_DUP_MODE 0 "register_operand" "=x,x,x")
10588         (vec_duplicate:AVX_VEC_DUP_MODE
10589           (match_operand:<ssescalarmode> 1 "nonimmediate_operand" "m,x,?x")))]
10590   "TARGET_AVX"
10591   "@
10592    vbroadcast<ssescalarmodesuffix>\t{%1, %0|%0, %1}
10593    vbroadcast<ssescalarmodesuffix>\t{%x1, %0|%0, %x1}
10594    #"
10595   [(set_attr "type" "ssemov")
10596    (set_attr "prefix_extra" "1")
10597    (set_attr "prefix" "vex")
10598    (set_attr "isa" "*,avx2,noavx2")
10599    (set_attr "mode" "V8SF")])
10600
10601 (define_insn "avx2_vbroadcasti128_<mode>"
10602   [(set (match_operand:VI_256 0 "register_operand" "=x")
10603         (vec_concat:VI_256
10604           (match_operand:<ssehalfvecmode> 1 "memory_operand" "m")
10605           (match_dup 1)))]
10606   "TARGET_AVX2"
10607   "vbroadcasti128\t{%1, %0|%0, %1}"
10608   [(set_attr "type" "ssemov")
10609    (set_attr "prefix_extra" "1")
10610    (set_attr "prefix" "vex")
10611    (set_attr "mode" "OI")])
10612
10613 (define_split
10614   [(set (match_operand:AVX_VEC_DUP_MODE 0 "register_operand")
10615         (vec_duplicate:AVX_VEC_DUP_MODE
10616           (match_operand:<ssescalarmode> 1 "register_operand")))]
10617   "TARGET_AVX && !TARGET_AVX2 && reload_completed"
10618   [(set (match_dup 2)
10619         (vec_duplicate:<ssehalfvecmode> (match_dup 1)))
10620    (set (match_dup 0)
10621         (vec_concat:AVX_VEC_DUP_MODE (match_dup 2) (match_dup 2)))]
10622   "operands[2] = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (operands[0]));")
10623
10624 (define_insn "avx_vbroadcastf128_<mode>"
10625   [(set (match_operand:V_256 0 "register_operand" "=x,x,x")
10626         (vec_concat:V_256
10627           (match_operand:<ssehalfvecmode> 1 "nonimmediate_operand" "m,0,?x")
10628           (match_dup 1)))]
10629   "TARGET_AVX"
10630   "@
10631    vbroadcast<i128>\t{%1, %0|%0, %1}
10632    vinsert<i128>\t{$1, %1, %0, %0|%0, %0, %1, 1}
10633    vperm2<i128>\t{$0, %t1, %t1, %0|%0, %t1, %t1, 0}"
10634   [(set_attr "type" "ssemov,sselog1,sselog1")
10635    (set_attr "prefix_extra" "1")
10636    (set_attr "length_immediate" "0,1,1")
10637    (set_attr "prefix" "vex")
10638    (set_attr "mode" "<sseinsnmode>")])
10639
10640 ;; Recognize broadcast as a vec_select as produced by builtin_vec_perm.
10641 ;; If it so happens that the input is in memory, use vbroadcast.
10642 ;; Otherwise use vpermilp (and in the case of 256-bit modes, vperm2f128).
10643 (define_insn "*avx_vperm_broadcast_v4sf"
10644   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
10645         (vec_select:V4SF
10646           (match_operand:V4SF 1 "nonimmediate_operand" "m,o,x")
10647           (match_parallel 2 "avx_vbroadcast_operand"
10648             [(match_operand 3 "const_int_operand" "C,n,n")])))]
10649   "TARGET_AVX"
10650 {
10651   int elt = INTVAL (operands[3]);
10652   switch (which_alternative)
10653     {
10654     case 0:
10655     case 1:
10656       operands[1] = adjust_address_nv (operands[1], SFmode, elt * 4);
10657       return "vbroadcastss\t{%1, %0|%0, %1}";
10658     case 2:
10659       operands[2] = GEN_INT (elt * 0x55);
10660       return "vpermilps\t{%2, %1, %0|%0, %1, %2}";
10661     default:
10662       gcc_unreachable ();
10663     }
10664 }
10665   [(set_attr "type" "ssemov,ssemov,sselog1")
10666    (set_attr "prefix_extra" "1")
10667    (set_attr "length_immediate" "0,0,1")
10668    (set_attr "prefix" "vex")
10669    (set_attr "mode" "SF,SF,V4SF")])
10670
10671 (define_insn_and_split "*avx_vperm_broadcast_<mode>"
10672   [(set (match_operand:VF_256 0 "register_operand" "=x,x,x")
10673         (vec_select:VF_256
10674           (match_operand:VF_256 1 "nonimmediate_operand" "m,o,?x")
10675           (match_parallel 2 "avx_vbroadcast_operand"
10676             [(match_operand 3 "const_int_operand" "C,n,n")])))]
10677   "TARGET_AVX"
10678   "#"
10679   "&& reload_completed && (<MODE>mode != V4DFmode || !TARGET_AVX2)"
10680   [(set (match_dup 0) (vec_duplicate:VF_256 (match_dup 1)))]
10681 {
10682   rtx op0 = operands[0], op1 = operands[1];
10683   int elt = INTVAL (operands[3]);
10684
10685   if (REG_P (op1))
10686     {
10687       int mask;
10688
10689       if (TARGET_AVX2 && elt == 0)
10690         {
10691           emit_insn (gen_vec_dup<mode> (op0, gen_lowpart (<ssescalarmode>mode,
10692                                                           op1)));
10693           DONE;
10694         }
10695
10696       /* Shuffle element we care about into all elements of the 128-bit lane.
10697          The other lane gets shuffled too, but we don't care.  */
10698       if (<MODE>mode == V4DFmode)
10699         mask = (elt & 1 ? 15 : 0);
10700       else
10701         mask = (elt & 3) * 0x55;
10702       emit_insn (gen_avx_vpermil<mode> (op0, op1, GEN_INT (mask)));
10703
10704       /* Shuffle the lane we care about into both lanes of the dest.  */
10705       mask = (elt / (<ssescalarnum> / 2)) * 0x11;
10706       emit_insn (gen_avx_vperm2f128<mode>3 (op0, op0, op0, GEN_INT (mask)));
10707       DONE;
10708     }
10709
10710   operands[1] = adjust_address_nv (op1, <ssescalarmode>mode,
10711                                    elt * GET_MODE_SIZE (<ssescalarmode>mode));
10712 })
10713
10714 (define_expand "avx_vpermil<mode>"
10715   [(set (match_operand:VF2 0 "register_operand")
10716         (vec_select:VF2
10717           (match_operand:VF2 1 "nonimmediate_operand")
10718           (match_operand:SI 2 "const_0_to_255_operand")))]
10719   "TARGET_AVX"
10720 {
10721   int mask = INTVAL (operands[2]);
10722   rtx perm[<ssescalarnum>];
10723
10724   perm[0] = GEN_INT (mask & 1);
10725   perm[1] = GEN_INT ((mask >> 1) & 1);
10726   if (<MODE>mode == V4DFmode)
10727     {
10728       perm[2] = GEN_INT (((mask >> 2) & 1) + 2);
10729       perm[3] = GEN_INT (((mask >> 3) & 1) + 2);
10730     }
10731
10732   operands[2]
10733     = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (<ssescalarnum>, perm));
10734 })
10735
10736 (define_expand "avx_vpermil<mode>"
10737   [(set (match_operand:VF1 0 "register_operand")
10738         (vec_select:VF1
10739           (match_operand:VF1 1 "nonimmediate_operand")
10740           (match_operand:SI 2 "const_0_to_255_operand")))]
10741   "TARGET_AVX"
10742 {
10743   int mask = INTVAL (operands[2]);
10744   rtx perm[<ssescalarnum>];
10745
10746   perm[0] = GEN_INT (mask & 3);
10747   perm[1] = GEN_INT ((mask >> 2) & 3);
10748   perm[2] = GEN_INT ((mask >> 4) & 3);
10749   perm[3] = GEN_INT ((mask >> 6) & 3);
10750   if (<MODE>mode == V8SFmode)
10751     {
10752       perm[4] = GEN_INT ((mask & 3) + 4);
10753       perm[5] = GEN_INT (((mask >> 2) & 3) + 4);
10754       perm[6] = GEN_INT (((mask >> 4) & 3) + 4);
10755       perm[7] = GEN_INT (((mask >> 6) & 3) + 4);
10756     }
10757
10758   operands[2]
10759     = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (<ssescalarnum>, perm));
10760 })
10761
10762 (define_insn "*avx_vpermilp<mode>"
10763   [(set (match_operand:VF 0 "register_operand" "=x")
10764         (vec_select:VF
10765           (match_operand:VF 1 "nonimmediate_operand" "xm")
10766           (match_parallel 2 ""
10767             [(match_operand 3 "const_int_operand")])))]
10768   "TARGET_AVX
10769    && avx_vpermilp_parallel (operands[2], <MODE>mode)"
10770 {
10771   int mask = avx_vpermilp_parallel (operands[2], <MODE>mode) - 1;
10772   operands[2] = GEN_INT (mask);
10773   return "vpermil<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}";
10774 }
10775   [(set_attr "type" "sselog")
10776    (set_attr "prefix_extra" "1")
10777    (set_attr "length_immediate" "1")
10778    (set_attr "prefix" "vex")
10779    (set_attr "mode" "<MODE>")])
10780
10781 (define_insn "avx_vpermilvar<mode>3"
10782   [(set (match_operand:VF 0 "register_operand" "=x")
10783         (unspec:VF
10784           [(match_operand:VF 1 "register_operand" "x")
10785            (match_operand:<sseintvecmode> 2 "nonimmediate_operand" "xm")]
10786           UNSPEC_VPERMIL))]
10787   "TARGET_AVX"
10788   "vpermil<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
10789   [(set_attr "type" "sselog")
10790    (set_attr "prefix_extra" "1")
10791    (set_attr "prefix" "vex")
10792    (set_attr "btver2_decode" "vector")
10793    (set_attr "mode" "<MODE>")])
10794
10795 (define_expand "avx_vperm2f128<mode>3"
10796   [(set (match_operand:AVX256MODE2P 0 "register_operand")
10797         (unspec:AVX256MODE2P
10798           [(match_operand:AVX256MODE2P 1 "register_operand")
10799            (match_operand:AVX256MODE2P 2 "nonimmediate_operand")
10800            (match_operand:SI 3 "const_0_to_255_operand")]
10801           UNSPEC_VPERMIL2F128))]
10802   "TARGET_AVX"
10803 {
10804   int mask = INTVAL (operands[3]);
10805   if ((mask & 0x88) == 0)
10806     {
10807       rtx perm[<ssescalarnum>], t1, t2;
10808       int i, base, nelt = <ssescalarnum>, nelt2 = nelt / 2;
10809
10810       base = (mask & 3) * nelt2;
10811       for (i = 0; i < nelt2; ++i)
10812         perm[i] = GEN_INT (base + i);
10813
10814       base = ((mask >> 4) & 3) * nelt2;
10815       for (i = 0; i < nelt2; ++i)
10816         perm[i + nelt2] = GEN_INT (base + i);
10817
10818       t2 = gen_rtx_VEC_CONCAT (<ssedoublevecmode>mode,
10819                                operands[1], operands[2]);
10820       t1 = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nelt, perm));
10821       t2 = gen_rtx_VEC_SELECT (<MODE>mode, t2, t1);
10822       t2 = gen_rtx_SET (VOIDmode, operands[0], t2);
10823       emit_insn (t2);
10824       DONE;
10825     }
10826 })
10827
10828 ;; Note that bits 7 and 3 of the imm8 allow lanes to be zeroed, which
10829 ;; means that in order to represent this properly in rtl we'd have to
10830 ;; nest *another* vec_concat with a zero operand and do the select from
10831 ;; a 4x wide vector.  That doesn't seem very nice.
10832 (define_insn "*avx_vperm2f128<mode>_full"
10833   [(set (match_operand:AVX256MODE2P 0 "register_operand" "=x")
10834         (unspec:AVX256MODE2P
10835           [(match_operand:AVX256MODE2P 1 "register_operand" "x")
10836            (match_operand:AVX256MODE2P 2 "nonimmediate_operand" "xm")
10837            (match_operand:SI 3 "const_0_to_255_operand" "n")]
10838           UNSPEC_VPERMIL2F128))]
10839   "TARGET_AVX"
10840   "vperm2<i128>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10841   [(set_attr "type" "sselog")
10842    (set_attr "prefix_extra" "1")
10843    (set_attr "length_immediate" "1")
10844    (set_attr "prefix" "vex")
10845    (set_attr "mode" "<sseinsnmode>")])
10846
10847 (define_insn "*avx_vperm2f128<mode>_nozero"
10848   [(set (match_operand:AVX256MODE2P 0 "register_operand" "=x")
10849         (vec_select:AVX256MODE2P
10850           (vec_concat:<ssedoublevecmode>
10851             (match_operand:AVX256MODE2P 1 "register_operand" "x")
10852             (match_operand:AVX256MODE2P 2 "nonimmediate_operand" "xm"))
10853           (match_parallel 3 ""
10854             [(match_operand 4 "const_int_operand")])))]
10855   "TARGET_AVX
10856    && avx_vperm2f128_parallel (operands[3], <MODE>mode)"
10857 {
10858   int mask = avx_vperm2f128_parallel (operands[3], <MODE>mode) - 1;
10859   if (mask == 0x12)
10860     return "vinsert<i128>\t{$0, %x2, %1, %0|%0, %1, %x2, 0}";
10861   if (mask == 0x20)
10862     return "vinsert<i128>\t{$1, %x2, %1, %0|%0, %1, %x2, 1}";
10863   operands[3] = GEN_INT (mask);
10864   return "vperm2<i128>\t{%3, %2, %1, %0|%0, %1, %2, %3}";
10865 }
10866   [(set_attr "type" "sselog")
10867    (set_attr "prefix_extra" "1")
10868    (set_attr "length_immediate" "1")
10869    (set_attr "prefix" "vex")
10870    (set_attr "mode" "<sseinsnmode>")])
10871
10872 (define_expand "avx_vinsertf128<mode>"
10873   [(match_operand:V_256 0 "register_operand")
10874    (match_operand:V_256 1 "register_operand")
10875    (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand")
10876    (match_operand:SI 3 "const_0_to_1_operand")]
10877   "TARGET_AVX"
10878 {
10879   rtx (*insn)(rtx, rtx, rtx);
10880
10881   switch (INTVAL (operands[3]))
10882     {
10883     case 0:
10884       insn = gen_vec_set_lo_<mode>;
10885       break;
10886     case 1:
10887       insn = gen_vec_set_hi_<mode>;
10888       break;
10889     default:
10890       gcc_unreachable ();
10891     }
10892
10893   emit_insn (insn (operands[0], operands[1], operands[2]));
10894   DONE;
10895 })
10896
10897 (define_insn "avx2_vec_set_lo_v4di"
10898   [(set (match_operand:V4DI 0 "register_operand" "=x")
10899         (vec_concat:V4DI
10900           (match_operand:V2DI 2 "nonimmediate_operand" "xm")
10901           (vec_select:V2DI
10902             (match_operand:V4DI 1 "register_operand" "x")
10903             (parallel [(const_int 2) (const_int 3)]))))]
10904   "TARGET_AVX2"
10905   "vinserti128\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
10906   [(set_attr "type" "sselog")
10907    (set_attr "prefix_extra" "1")
10908    (set_attr "length_immediate" "1")
10909    (set_attr "prefix" "vex")
10910    (set_attr "mode" "OI")])
10911
10912 (define_insn "avx2_vec_set_hi_v4di"
10913   [(set (match_operand:V4DI 0 "register_operand" "=x")
10914         (vec_concat:V4DI
10915           (vec_select:V2DI
10916             (match_operand:V4DI 1 "register_operand" "x")
10917             (parallel [(const_int 0) (const_int 1)]))
10918           (match_operand:V2DI 2 "nonimmediate_operand" "xm")))]
10919   "TARGET_AVX2"
10920   "vinserti128\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
10921   [(set_attr "type" "sselog")
10922    (set_attr "prefix_extra" "1")
10923    (set_attr "length_immediate" "1")
10924    (set_attr "prefix" "vex")
10925    (set_attr "mode" "OI")])
10926
10927 (define_insn "vec_set_lo_<mode>"
10928   [(set (match_operand:VI8F_256 0 "register_operand" "=x")
10929         (vec_concat:VI8F_256
10930           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "xm")
10931           (vec_select:<ssehalfvecmode>
10932             (match_operand:VI8F_256 1 "register_operand" "x")
10933             (parallel [(const_int 2) (const_int 3)]))))]
10934   "TARGET_AVX"
10935   "vinsert<i128>\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
10936   [(set_attr "type" "sselog")
10937    (set_attr "prefix_extra" "1")
10938    (set_attr "length_immediate" "1")
10939    (set_attr "prefix" "vex")
10940    (set_attr "mode" "<sseinsnmode>")])
10941
10942 (define_insn "vec_set_hi_<mode>"
10943   [(set (match_operand:VI8F_256 0 "register_operand" "=x")
10944         (vec_concat:VI8F_256
10945           (vec_select:<ssehalfvecmode>
10946             (match_operand:VI8F_256 1 "register_operand" "x")
10947             (parallel [(const_int 0) (const_int 1)]))
10948           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "xm")))]
10949   "TARGET_AVX"
10950   "vinsert<i128>\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
10951   [(set_attr "type" "sselog")
10952    (set_attr "prefix_extra" "1")
10953    (set_attr "length_immediate" "1")
10954    (set_attr "prefix" "vex")
10955    (set_attr "mode" "<sseinsnmode>")])
10956
10957 (define_insn "vec_set_lo_<mode>"
10958   [(set (match_operand:VI4F_256 0 "register_operand" "=x")
10959         (vec_concat:VI4F_256
10960           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "xm")
10961           (vec_select:<ssehalfvecmode>
10962             (match_operand:VI4F_256 1 "register_operand" "x")
10963             (parallel [(const_int 4) (const_int 5)
10964                        (const_int 6) (const_int 7)]))))]
10965   "TARGET_AVX"
10966   "vinsert<i128>\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
10967   [(set_attr "type" "sselog")
10968    (set_attr "prefix_extra" "1")
10969    (set_attr "length_immediate" "1")
10970    (set_attr "prefix" "vex")
10971    (set_attr "mode" "<sseinsnmode>")])
10972
10973 (define_insn "vec_set_hi_<mode>"
10974   [(set (match_operand:VI4F_256 0 "register_operand" "=x")
10975         (vec_concat:VI4F_256
10976           (vec_select:<ssehalfvecmode>
10977             (match_operand:VI4F_256 1 "register_operand" "x")
10978             (parallel [(const_int 0) (const_int 1)
10979                        (const_int 2) (const_int 3)]))
10980           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "xm")))]
10981   "TARGET_AVX"
10982   "vinsert<i128>\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
10983   [(set_attr "type" "sselog")
10984    (set_attr "prefix_extra" "1")
10985    (set_attr "length_immediate" "1")
10986    (set_attr "prefix" "vex")
10987    (set_attr "mode" "<sseinsnmode>")])
10988
10989 (define_insn "vec_set_lo_v16hi"
10990   [(set (match_operand:V16HI 0 "register_operand" "=x")
10991         (vec_concat:V16HI
10992           (match_operand:V8HI 2 "nonimmediate_operand" "xm")
10993           (vec_select:V8HI
10994             (match_operand:V16HI 1 "register_operand" "x")
10995             (parallel [(const_int 8) (const_int 9)
10996                        (const_int 10) (const_int 11)
10997                        (const_int 12) (const_int 13)
10998                        (const_int 14) (const_int 15)]))))]
10999   "TARGET_AVX"
11000   "vinsert%~128\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
11001   [(set_attr "type" "sselog")
11002    (set_attr "prefix_extra" "1")
11003    (set_attr "length_immediate" "1")
11004    (set_attr "prefix" "vex")
11005    (set_attr "mode" "OI")])
11006
11007 (define_insn "vec_set_hi_v16hi"
11008   [(set (match_operand:V16HI 0 "register_operand" "=x")
11009         (vec_concat:V16HI
11010           (vec_select:V8HI
11011             (match_operand:V16HI 1 "register_operand" "x")
11012             (parallel [(const_int 0) (const_int 1)
11013                        (const_int 2) (const_int 3)
11014                        (const_int 4) (const_int 5)
11015                        (const_int 6) (const_int 7)]))
11016           (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
11017   "TARGET_AVX"
11018   "vinsert%~128\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
11019   [(set_attr "type" "sselog")
11020    (set_attr "prefix_extra" "1")
11021    (set_attr "length_immediate" "1")
11022    (set_attr "prefix" "vex")
11023    (set_attr "mode" "OI")])
11024
11025 (define_insn "vec_set_lo_v32qi"
11026   [(set (match_operand:V32QI 0 "register_operand" "=x")
11027         (vec_concat:V32QI
11028           (match_operand:V16QI 2 "nonimmediate_operand" "xm")
11029           (vec_select:V16QI
11030             (match_operand:V32QI 1 "register_operand" "x")
11031             (parallel [(const_int 16) (const_int 17)
11032                        (const_int 18) (const_int 19)
11033                        (const_int 20) (const_int 21)
11034                        (const_int 22) (const_int 23)
11035                        (const_int 24) (const_int 25)
11036                        (const_int 26) (const_int 27)
11037                        (const_int 28) (const_int 29)
11038                        (const_int 30) (const_int 31)]))))]
11039   "TARGET_AVX"
11040   "vinsert%~128\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
11041   [(set_attr "type" "sselog")
11042    (set_attr "prefix_extra" "1")
11043    (set_attr "length_immediate" "1")
11044    (set_attr "prefix" "vex")
11045    (set_attr "mode" "OI")])
11046
11047 (define_insn "vec_set_hi_v32qi"
11048   [(set (match_operand:V32QI 0 "register_operand" "=x")
11049         (vec_concat:V32QI
11050           (vec_select:V16QI
11051             (match_operand:V32QI 1 "register_operand" "x")
11052             (parallel [(const_int 0) (const_int 1)
11053                        (const_int 2) (const_int 3)
11054                        (const_int 4) (const_int 5)
11055                        (const_int 6) (const_int 7)
11056                        (const_int 8) (const_int 9)
11057                        (const_int 10) (const_int 11)
11058                        (const_int 12) (const_int 13)
11059                        (const_int 14) (const_int 15)]))
11060           (match_operand:V16QI 2 "nonimmediate_operand" "xm")))]
11061   "TARGET_AVX"
11062   "vinsert%~128\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
11063   [(set_attr "type" "sselog")
11064    (set_attr "prefix_extra" "1")
11065    (set_attr "length_immediate" "1")
11066    (set_attr "prefix" "vex")
11067    (set_attr "mode" "OI")])
11068
11069 (define_insn "<avx_avx2>_maskload<ssemodesuffix><avxsizesuffix>"
11070   [(set (match_operand:V48_AVX2 0 "register_operand" "=x")
11071         (unspec:V48_AVX2
11072           [(match_operand:<sseintvecmode> 2 "register_operand" "x")
11073            (match_operand:V48_AVX2 1 "memory_operand" "m")]
11074           UNSPEC_MASKMOV))]
11075   "TARGET_AVX"
11076   "v<sseintprefix>maskmov<ssemodesuffix>\t{%1, %2, %0|%0, %2, %1}"
11077   [(set_attr "type" "sselog1")
11078    (set_attr "prefix_extra" "1")
11079    (set_attr "prefix" "vex")
11080    (set_attr "btver2_decode" "vector")
11081    (set_attr "mode" "<sseinsnmode>")])
11082
11083 (define_insn "<avx_avx2>_maskstore<ssemodesuffix><avxsizesuffix>"
11084   [(set (match_operand:V48_AVX2 0 "memory_operand" "+m")
11085         (unspec:V48_AVX2
11086           [(match_operand:<sseintvecmode> 1 "register_operand" "x")
11087            (match_operand:V48_AVX2 2 "register_operand" "x")
11088            (match_dup 0)]
11089           UNSPEC_MASKMOV))]
11090   "TARGET_AVX"
11091   "v<sseintprefix>maskmov<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11092   [(set_attr "type" "sselog1")
11093    (set_attr "prefix_extra" "1")
11094    (set_attr "prefix" "vex")
11095    (set_attr "btver2_decode" "vector") 
11096    (set_attr "mode" "<sseinsnmode>")])
11097
11098 (define_insn_and_split "avx_<castmode><avxsizesuffix>_<castmode>"
11099   [(set (match_operand:AVX256MODE2P 0 "nonimmediate_operand" "=x,m")
11100         (unspec:AVX256MODE2P
11101           [(match_operand:<ssehalfvecmode> 1 "nonimmediate_operand" "xm,x")]
11102           UNSPEC_CAST))]
11103   "TARGET_AVX"
11104   "#"
11105   "&& reload_completed"
11106   [(const_int 0)]
11107 {
11108   rtx op0 = operands[0];
11109   rtx op1 = operands[1];
11110   if (REG_P (op0))
11111     op0 = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (op0));
11112   else
11113     op1 = gen_rtx_REG (<MODE>mode, REGNO (op1));
11114   emit_move_insn (op0, op1);
11115   DONE;
11116 })
11117
11118 (define_expand "vec_init<mode>"
11119   [(match_operand:V_256 0 "register_operand")
11120    (match_operand 1)]
11121   "TARGET_AVX"
11122 {
11123   ix86_expand_vector_init (false, operands[0], operands[1]);
11124   DONE;
11125 })
11126
11127 (define_expand "avx2_extracti128"
11128   [(match_operand:V2DI 0 "nonimmediate_operand")
11129    (match_operand:V4DI 1 "register_operand")
11130    (match_operand:SI 2 "const_0_to_1_operand")]
11131   "TARGET_AVX2"
11132 {
11133   rtx (*insn)(rtx, rtx);
11134
11135   switch (INTVAL (operands[2]))
11136     {
11137     case 0:
11138       insn = gen_vec_extract_lo_v4di;
11139       break;
11140     case 1:
11141       insn = gen_vec_extract_hi_v4di;
11142       break;
11143     default:
11144       gcc_unreachable ();
11145     }
11146
11147   emit_insn (insn (operands[0], operands[1]));
11148   DONE;
11149 })
11150
11151 (define_expand "avx2_inserti128"
11152   [(match_operand:V4DI 0 "register_operand")
11153    (match_operand:V4DI 1 "register_operand")
11154    (match_operand:V2DI 2 "nonimmediate_operand")
11155    (match_operand:SI 3 "const_0_to_1_operand")]
11156   "TARGET_AVX2"
11157 {
11158   rtx (*insn)(rtx, rtx, rtx);
11159
11160   switch (INTVAL (operands[3]))
11161     {
11162     case 0:
11163       insn = gen_avx2_vec_set_lo_v4di;
11164       break;
11165     case 1:
11166       insn = gen_avx2_vec_set_hi_v4di;
11167       break;
11168     default:
11169       gcc_unreachable ();
11170     }
11171
11172   emit_insn (insn (operands[0], operands[1], operands[2]));
11173   DONE;
11174 })
11175
11176 (define_insn "avx2_ashrv<mode>"
11177   [(set (match_operand:VI4_AVX2 0 "register_operand" "=x")
11178         (ashiftrt:VI4_AVX2
11179           (match_operand:VI4_AVX2 1 "register_operand" "x")
11180           (match_operand:VI4_AVX2 2 "nonimmediate_operand" "xm")))]
11181   "TARGET_AVX2"
11182   "vpsravd\t{%2, %1, %0|%0, %1, %2}"
11183   [(set_attr "type" "sseishft")
11184    (set_attr "prefix" "vex")
11185    (set_attr "mode" "<sseinsnmode>")])
11186
11187 (define_insn "avx2_<shift_insn>v<mode>"
11188   [(set (match_operand:VI48_AVX2 0 "register_operand" "=x")
11189         (any_lshift:VI48_AVX2
11190           (match_operand:VI48_AVX2 1 "register_operand" "x")
11191           (match_operand:VI48_AVX2 2 "nonimmediate_operand" "xm")))]
11192   "TARGET_AVX2"
11193   "vp<vshift>v<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11194   [(set_attr "type" "sseishft")
11195    (set_attr "prefix" "vex")
11196    (set_attr "mode" "<sseinsnmode>")])
11197
11198 (define_insn "avx_vec_concat<mode>"
11199   [(set (match_operand:V_256 0 "register_operand" "=x,x")
11200         (vec_concat:V_256
11201           (match_operand:<ssehalfvecmode> 1 "register_operand" "x,x")
11202           (match_operand:<ssehalfvecmode> 2 "vector_move_operand" "xm,C")))]
11203   "TARGET_AVX"
11204 {
11205   switch (which_alternative)
11206     {
11207     case 0:
11208       return "vinsert<i128>\t{$0x1, %2, %t1, %0|%0, %t1, %2, 0x1}";
11209     case 1:
11210       switch (get_attr_mode (insn))
11211         {
11212         case MODE_V8SF:
11213           return "vmovaps\t{%1, %x0|%x0, %1}";
11214         case MODE_V4DF:
11215           return "vmovapd\t{%1, %x0|%x0, %1}";
11216         default:
11217           return "vmovdqa\t{%1, %x0|%x0, %1}";
11218         }
11219     default:
11220       gcc_unreachable ();
11221     }
11222 }
11223   [(set_attr "type" "sselog,ssemov")
11224    (set_attr "prefix_extra" "1,*")
11225    (set_attr "length_immediate" "1,*")
11226    (set_attr "prefix" "vex")
11227    (set_attr "mode" "<sseinsnmode>")])
11228
11229 (define_insn "vcvtph2ps"
11230   [(set (match_operand:V4SF 0 "register_operand" "=x")
11231         (vec_select:V4SF
11232           (unspec:V8SF [(match_operand:V8HI 1 "register_operand" "x")]
11233                        UNSPEC_VCVTPH2PS)
11234           (parallel [(const_int 0) (const_int 1)
11235                      (const_int 2) (const_int 3)])))]
11236   "TARGET_F16C"
11237   "vcvtph2ps\t{%1, %0|%0, %1}"
11238   [(set_attr "type" "ssecvt")
11239    (set_attr "prefix" "vex")
11240    (set_attr "mode" "V4SF")])
11241
11242 (define_insn "*vcvtph2ps_load"
11243   [(set (match_operand:V4SF 0 "register_operand" "=x")
11244         (unspec:V4SF [(match_operand:V4HI 1 "memory_operand" "m")]
11245                      UNSPEC_VCVTPH2PS))]
11246   "TARGET_F16C"
11247   "vcvtph2ps\t{%1, %0|%0, %1}"
11248   [(set_attr "type" "ssecvt")
11249    (set_attr "prefix" "vex")
11250    (set_attr "mode" "V8SF")])
11251
11252 (define_insn "vcvtph2ps256"
11253   [(set (match_operand:V8SF 0 "register_operand" "=x")
11254         (unspec:V8SF [(match_operand:V8HI 1 "nonimmediate_operand" "xm")]
11255                      UNSPEC_VCVTPH2PS))]
11256   "TARGET_F16C"
11257   "vcvtph2ps\t{%1, %0|%0, %1}"
11258   [(set_attr "type" "ssecvt")
11259    (set_attr "prefix" "vex")
11260    (set_attr "btver2_decode" "double")
11261    (set_attr "mode" "V8SF")])
11262
11263 (define_expand "vcvtps2ph"
11264   [(set (match_operand:V8HI 0 "register_operand")
11265         (vec_concat:V8HI
11266           (unspec:V4HI [(match_operand:V4SF 1 "register_operand")
11267                         (match_operand:SI 2 "const_0_to_255_operand")]
11268                        UNSPEC_VCVTPS2PH)
11269           (match_dup 3)))]
11270   "TARGET_F16C"
11271   "operands[3] = CONST0_RTX (V4HImode);")
11272
11273 (define_insn "*vcvtps2ph"
11274   [(set (match_operand:V8HI 0 "register_operand" "=x")
11275         (vec_concat:V8HI
11276           (unspec:V4HI [(match_operand:V4SF 1 "register_operand" "x")
11277                         (match_operand:SI 2 "const_0_to_255_operand" "N")]
11278                        UNSPEC_VCVTPS2PH)
11279           (match_operand:V4HI 3 "const0_operand")))]
11280   "TARGET_F16C"
11281   "vcvtps2ph\t{%2, %1, %0|%0, %1, %2}"
11282   [(set_attr "type" "ssecvt")
11283    (set_attr "prefix" "vex")
11284    (set_attr "mode" "V4SF")])
11285
11286 (define_insn "*vcvtps2ph_store"
11287   [(set (match_operand:V4HI 0 "memory_operand" "=m")
11288         (unspec:V4HI [(match_operand:V4SF 1 "register_operand" "x")
11289                       (match_operand:SI 2 "const_0_to_255_operand" "N")]
11290                      UNSPEC_VCVTPS2PH))]
11291   "TARGET_F16C"
11292   "vcvtps2ph\t{%2, %1, %0|%0, %1, %2}"
11293   [(set_attr "type" "ssecvt")
11294    (set_attr "prefix" "vex")
11295    (set_attr "mode" "V4SF")])
11296
11297 (define_insn "vcvtps2ph256"
11298   [(set (match_operand:V8HI 0 "nonimmediate_operand" "=xm")
11299         (unspec:V8HI [(match_operand:V8SF 1 "register_operand" "x")
11300                       (match_operand:SI 2 "const_0_to_255_operand" "N")]
11301                      UNSPEC_VCVTPS2PH))]
11302   "TARGET_F16C"
11303   "vcvtps2ph\t{%2, %1, %0|%0, %1, %2}"
11304   [(set_attr "type" "ssecvt")
11305    (set_attr "prefix" "vex")
11306    (set_attr "btver2_decode" "vector")
11307    (set_attr "mode" "V8SF")])
11308
11309 ;; For gather* insn patterns
11310 (define_mode_iterator VEC_GATHER_MODE
11311                       [V2DI V2DF V4DI V4DF V4SI V4SF V8SI V8SF])
11312 (define_mode_attr VEC_GATHER_IDXSI
11313                       [(V2DI "V4SI") (V2DF "V4SI")
11314                        (V4DI "V4SI") (V4DF "V4SI")
11315                        (V4SI "V4SI") (V4SF "V4SI")
11316                        (V8SI "V8SI") (V8SF "V8SI")])
11317 (define_mode_attr VEC_GATHER_IDXDI
11318                       [(V2DI "V2DI") (V2DF "V2DI")
11319                        (V4DI "V4DI") (V4DF "V4DI")
11320                        (V4SI "V2DI") (V4SF "V2DI")
11321                        (V8SI "V4DI") (V8SF "V4DI")])
11322 (define_mode_attr VEC_GATHER_SRCDI
11323                       [(V2DI "V2DI") (V2DF "V2DF")
11324                        (V4DI "V4DI") (V4DF "V4DF")
11325                        (V4SI "V4SI") (V4SF "V4SF")
11326                        (V8SI "V4SI") (V8SF "V4SF")])
11327
11328 (define_expand "avx2_gathersi<mode>"
11329   [(parallel [(set (match_operand:VEC_GATHER_MODE 0 "register_operand")
11330                    (unspec:VEC_GATHER_MODE
11331                      [(match_operand:VEC_GATHER_MODE 1 "register_operand")
11332                       (mem:<ssescalarmode>
11333                         (match_par_dup 7
11334                           [(match_operand 2 "vsib_address_operand")
11335                            (match_operand:<VEC_GATHER_IDXSI>
11336                               3 "register_operand")
11337                            (match_operand:SI 5 "const1248_operand ")]))
11338                       (mem:BLK (scratch))
11339                       (match_operand:VEC_GATHER_MODE 4 "register_operand")]
11340                      UNSPEC_GATHER))
11341               (clobber (match_scratch:VEC_GATHER_MODE 6))])]
11342   "TARGET_AVX2"
11343 {
11344   operands[7]
11345     = gen_rtx_UNSPEC (Pmode, gen_rtvec (3, operands[2], operands[3],
11346                                         operands[5]), UNSPEC_VSIBADDR);
11347 })
11348
11349 (define_insn "*avx2_gathersi<mode>"
11350   [(set (match_operand:VEC_GATHER_MODE 0 "register_operand" "=&x")
11351         (unspec:VEC_GATHER_MODE
11352           [(match_operand:VEC_GATHER_MODE 2 "register_operand" "0")
11353            (match_operator:<ssescalarmode> 7 "vsib_mem_operator"
11354              [(unspec:P
11355                 [(match_operand:P 3 "vsib_address_operand" "p")
11356                  (match_operand:<VEC_GATHER_IDXSI> 4 "register_operand" "x")
11357                  (match_operand:SI 6 "const1248_operand" "n")]
11358                 UNSPEC_VSIBADDR)])
11359            (mem:BLK (scratch))
11360            (match_operand:VEC_GATHER_MODE 5 "register_operand" "1")]
11361           UNSPEC_GATHER))
11362    (clobber (match_scratch:VEC_GATHER_MODE 1 "=&x"))]
11363   "TARGET_AVX2"
11364   "v<sseintprefix>gatherd<ssemodesuffix>\t{%1, %7, %0|%0, %7, %1}"
11365   [(set_attr "type" "ssemov")
11366    (set_attr "prefix" "vex")
11367    (set_attr "mode" "<sseinsnmode>")])
11368
11369 (define_insn "*avx2_gathersi<mode>_2"
11370   [(set (match_operand:VEC_GATHER_MODE 0 "register_operand" "=&x")
11371         (unspec:VEC_GATHER_MODE
11372           [(pc)
11373            (match_operator:<ssescalarmode> 6 "vsib_mem_operator"
11374              [(unspec:P
11375                 [(match_operand:P 2 "vsib_address_operand" "p")
11376                  (match_operand:<VEC_GATHER_IDXSI> 3 "register_operand" "x")
11377                  (match_operand:SI 5 "const1248_operand" "n")]
11378                 UNSPEC_VSIBADDR)])
11379            (mem:BLK (scratch))
11380            (match_operand:VEC_GATHER_MODE 4 "register_operand" "1")]
11381           UNSPEC_GATHER))
11382    (clobber (match_scratch:VEC_GATHER_MODE 1 "=&x"))]
11383   "TARGET_AVX2"
11384   "v<sseintprefix>gatherd<ssemodesuffix>\t{%1, %6, %0|%0, %6, %1}"
11385   [(set_attr "type" "ssemov")
11386    (set_attr "prefix" "vex")
11387    (set_attr "mode" "<sseinsnmode>")])
11388
11389 (define_expand "avx2_gatherdi<mode>"
11390   [(parallel [(set (match_operand:VEC_GATHER_MODE 0 "register_operand")
11391                    (unspec:VEC_GATHER_MODE
11392                      [(match_operand:<VEC_GATHER_SRCDI> 1 "register_operand")
11393                       (mem:<ssescalarmode>
11394                         (match_par_dup 7
11395                           [(match_operand 2 "vsib_address_operand")
11396                            (match_operand:<VEC_GATHER_IDXDI>
11397                               3 "register_operand")
11398                            (match_operand:SI 5 "const1248_operand ")]))
11399                       (mem:BLK (scratch))
11400                       (match_operand:<VEC_GATHER_SRCDI>
11401                         4 "register_operand")]
11402                      UNSPEC_GATHER))
11403               (clobber (match_scratch:VEC_GATHER_MODE 6))])]
11404   "TARGET_AVX2"
11405 {
11406   operands[7]
11407     = gen_rtx_UNSPEC (Pmode, gen_rtvec (3, operands[2], operands[3],
11408                                         operands[5]), UNSPEC_VSIBADDR);
11409 })
11410
11411 (define_insn "*avx2_gatherdi<mode>"
11412   [(set (match_operand:VEC_GATHER_MODE 0 "register_operand" "=&x")
11413         (unspec:VEC_GATHER_MODE
11414           [(match_operand:<VEC_GATHER_SRCDI> 2 "register_operand" "0")
11415            (match_operator:<ssescalarmode> 7 "vsib_mem_operator"
11416              [(unspec:P
11417                 [(match_operand:P 3 "vsib_address_operand" "p")
11418                  (match_operand:<VEC_GATHER_IDXDI> 4 "register_operand" "x")
11419                  (match_operand:SI 6 "const1248_operand" "n")]
11420                 UNSPEC_VSIBADDR)])
11421            (mem:BLK (scratch))
11422            (match_operand:<VEC_GATHER_SRCDI> 5 "register_operand" "1")]
11423           UNSPEC_GATHER))
11424    (clobber (match_scratch:VEC_GATHER_MODE 1 "=&x"))]
11425   "TARGET_AVX2"
11426   "v<sseintprefix>gatherq<ssemodesuffix>\t{%5, %7, %2|%2, %7, %5}"
11427   [(set_attr "type" "ssemov")
11428    (set_attr "prefix" "vex")
11429    (set_attr "mode" "<sseinsnmode>")])
11430
11431 (define_insn "*avx2_gatherdi<mode>_2"
11432   [(set (match_operand:VEC_GATHER_MODE 0 "register_operand" "=&x")
11433         (unspec:VEC_GATHER_MODE
11434           [(pc)
11435            (match_operator:<ssescalarmode> 6 "vsib_mem_operator"
11436              [(unspec:P
11437                 [(match_operand:P 2 "vsib_address_operand" "p")
11438                  (match_operand:<VEC_GATHER_IDXDI> 3 "register_operand" "x")
11439                  (match_operand:SI 5 "const1248_operand" "n")]
11440                 UNSPEC_VSIBADDR)])
11441            (mem:BLK (scratch))
11442            (match_operand:<VEC_GATHER_SRCDI> 4 "register_operand" "1")]
11443           UNSPEC_GATHER))
11444    (clobber (match_scratch:VEC_GATHER_MODE 1 "=&x"))]
11445   "TARGET_AVX2"
11446 {
11447   if (<MODE>mode != <VEC_GATHER_SRCDI>mode)
11448     return "v<sseintprefix>gatherq<ssemodesuffix>\t{%4, %6, %x0|%x0, %6, %4}";
11449   return "v<sseintprefix>gatherq<ssemodesuffix>\t{%4, %6, %0|%0, %6, %4}";
11450 }
11451   [(set_attr "type" "ssemov")
11452    (set_attr "prefix" "vex")
11453    (set_attr "mode" "<sseinsnmode>")])
11454
11455 (define_insn "*avx2_gatherdi<mode>_3"
11456   [(set (match_operand:<VEC_GATHER_SRCDI> 0 "register_operand" "=&x")
11457         (vec_select:<VEC_GATHER_SRCDI>
11458           (unspec:VI4F_256
11459             [(match_operand:<VEC_GATHER_SRCDI> 2 "register_operand" "0")
11460              (match_operator:<ssescalarmode> 7 "vsib_mem_operator"
11461                [(unspec:P
11462                   [(match_operand:P 3 "vsib_address_operand" "p")
11463                    (match_operand:<VEC_GATHER_IDXDI> 4 "register_operand" "x")
11464                    (match_operand:SI 6 "const1248_operand" "n")]
11465                   UNSPEC_VSIBADDR)])
11466              (mem:BLK (scratch))
11467              (match_operand:<VEC_GATHER_SRCDI> 5 "register_operand" "1")]
11468              UNSPEC_GATHER)
11469           (parallel [(const_int 0) (const_int 1)
11470                      (const_int 2) (const_int 3)])))
11471    (clobber (match_scratch:VI4F_256 1 "=&x"))]
11472   "TARGET_AVX2"
11473   "v<sseintprefix>gatherq<ssemodesuffix>\t{%5, %7, %0|%0, %7, %5}"
11474   [(set_attr "type" "ssemov")
11475    (set_attr "prefix" "vex")
11476    (set_attr "mode" "<sseinsnmode>")])
11477
11478 (define_insn "*avx2_gatherdi<mode>_4"
11479   [(set (match_operand:<VEC_GATHER_SRCDI> 0 "register_operand" "=&x")
11480         (vec_select:<VEC_GATHER_SRCDI>
11481           (unspec:VI4F_256
11482             [(pc)
11483              (match_operator:<ssescalarmode> 6 "vsib_mem_operator"
11484                [(unspec:P
11485                   [(match_operand:P 2 "vsib_address_operand" "p")
11486                    (match_operand:<VEC_GATHER_IDXDI> 3 "register_operand" "x")
11487                    (match_operand:SI 5 "const1248_operand" "n")]
11488                   UNSPEC_VSIBADDR)])
11489              (mem:BLK (scratch))
11490              (match_operand:<VEC_GATHER_SRCDI> 4 "register_operand" "1")]
11491             UNSPEC_GATHER)
11492           (parallel [(const_int 0) (const_int 1)
11493                      (const_int 2) (const_int 3)])))
11494    (clobber (match_scratch:VI4F_256 1 "=&x"))]
11495   "TARGET_AVX2"
11496   "v<sseintprefix>gatherq<ssemodesuffix>\t{%4, %6, %0|%0, %6, %4}"
11497   [(set_attr "type" "ssemov")
11498    (set_attr "prefix" "vex")
11499    (set_attr "mode" "<sseinsnmode>")])