OSDN Git Service

2009-10-14 Daniel Gutson <dgutson@codesourcery.com>
[pf3gnuchains/gcc-fork.git] / gcc / config / arm / neon.md
1 ;; ARM NEON coprocessor Machine Description
2 ;; Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
3 ;; Written by CodeSourcery.
4 ;;
5 ;; This file is part of GCC.
6 ;;
7 ;; GCC is free software; you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3, or (at your option)
10 ;; any later version.
11 ;;
12 ;; GCC is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 ;; General Public License for more details.
16 ;;
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3.  If not see
19 ;; <http://www.gnu.org/licenses/>.
20
21 ;; Constants for unspecs.
22 (define_constants
23   [(UNSPEC_ASHIFT_SIGNED        65)
24    (UNSPEC_ASHIFT_UNSIGNED      66)
25    (UNSPEC_VABA                 67)
26    (UNSPEC_VABAL                68)
27    (UNSPEC_VABD                 69)
28    (UNSPEC_VABDL                70)
29    (UNSPEC_VABS                 71)
30    (UNSPEC_VADD                 72)
31    (UNSPEC_VADDHN               73)
32    (UNSPEC_VADDL                74)
33    (UNSPEC_VADDW                75)
34    (UNSPEC_VAND                 76)
35    (UNSPEC_VBIC                 77)
36    (UNSPEC_VBSL                 78)
37    (UNSPEC_VCAGE                79)
38    (UNSPEC_VCAGT                80)
39    (UNSPEC_VCEQ                 81)
40    (UNSPEC_VCGE                 82)
41    (UNSPEC_VCGT                 83)
42    (UNSPEC_VCLS                 84)
43    (UNSPEC_VCLZ                 85)
44    (UNSPEC_VCNT                 86)
45    (UNSPEC_VCOMBINE             87)
46    (UNSPEC_VCVT                 88)
47    (UNSPEC_VCVT_N               89)
48    (UNSPEC_VDUP_LANE            90)
49    (UNSPEC_VDUP_N               91)
50    (UNSPEC_VEOR                 92)
51    (UNSPEC_VEXT                 93)
52    (UNSPEC_VGET_HIGH            94)
53    (UNSPEC_VGET_LANE            95)
54    (UNSPEC_VGET_LOW             96)
55    (UNSPEC_VHADD                97)
56    (UNSPEC_VHSUB                98)
57    (UNSPEC_VLD1                 99)
58    (UNSPEC_VLD1_DUP             100)
59    (UNSPEC_VLD1_LANE            101)
60    (UNSPEC_VLD2                 102)
61    (UNSPEC_VLD2_DUP             103)
62    (UNSPEC_VLD2_LANE            104)
63    (UNSPEC_VLD3                 105)
64    (UNSPEC_VLD3A                106)
65    (UNSPEC_VLD3B                107)
66    (UNSPEC_VLD3_DUP             108)
67    (UNSPEC_VLD3_LANE            109)
68    (UNSPEC_VLD4                 110)
69    (UNSPEC_VLD4A                111)
70    (UNSPEC_VLD4B                112)
71    (UNSPEC_VLD4_DUP             113)
72    (UNSPEC_VLD4_LANE            114)
73    (UNSPEC_VMAX                 115)
74    (UNSPEC_VMIN                 116)
75    (UNSPEC_VMLA                 117)
76    (UNSPEC_VMLAL                118)
77    (UNSPEC_VMLA_LANE            119)
78    (UNSPEC_VMLAL_LANE           120)
79    (UNSPEC_VMLS                 121)
80    (UNSPEC_VMLSL                122)
81    (UNSPEC_VMLS_LANE            123)
82    (UNSPEC_VMLSL_LANE           124)
83    (UNSPEC_VMOVL                125)
84    (UNSPEC_VMOVN                126)
85    (UNSPEC_VMUL                 127)
86    (UNSPEC_VMULL                128)
87    (UNSPEC_VMUL_LANE            129)
88    (UNSPEC_VMULL_LANE           130)
89    (UNSPEC_VMUL_N               131)
90    (UNSPEC_VMVN                 132)
91    (UNSPEC_VORN                 133)
92    (UNSPEC_VORR                 134)
93    (UNSPEC_VPADAL               135)
94    (UNSPEC_VPADD                136)
95    (UNSPEC_VPADDL               137)
96    (UNSPEC_VPMAX                138)
97    (UNSPEC_VPMIN                139)
98    (UNSPEC_VPSMAX               140)
99    (UNSPEC_VPSMIN               141)
100    (UNSPEC_VPUMAX               142)
101    (UNSPEC_VPUMIN               143)
102    (UNSPEC_VQABS                144)
103    (UNSPEC_VQADD                145)
104    (UNSPEC_VQDMLAL              146)
105    (UNSPEC_VQDMLAL_LANE         147)
106    (UNSPEC_VQDMLSL              148)
107    (UNSPEC_VQDMLSL_LANE         149)
108    (UNSPEC_VQDMULH              150)
109    (UNSPEC_VQDMULH_LANE         151)
110    (UNSPEC_VQDMULL              152)
111    (UNSPEC_VQDMULL_LANE         153)
112    (UNSPEC_VQMOVN               154)
113    (UNSPEC_VQMOVUN              155)
114    (UNSPEC_VQNEG                156)
115    (UNSPEC_VQSHL                157)
116    (UNSPEC_VQSHL_N              158)
117    (UNSPEC_VQSHLU_N             159)
118    (UNSPEC_VQSHRN_N             160)
119    (UNSPEC_VQSHRUN_N            161)
120    (UNSPEC_VQSUB                162)
121    (UNSPEC_VRECPE               163)
122    (UNSPEC_VRECPS               164)
123    (UNSPEC_VREV16               165)
124    (UNSPEC_VREV32               166)
125    (UNSPEC_VREV64               167)
126    (UNSPEC_VRSQRTE              168)
127    (UNSPEC_VRSQRTS              169)
128    (UNSPEC_VSET_LANE            170)
129    (UNSPEC_VSHL                 171)
130    (UNSPEC_VSHLL_N              172)
131    (UNSPEC_VSHL_N               173)
132    (UNSPEC_VSHR_N               174)
133    (UNSPEC_VSHRN_N              175)
134    (UNSPEC_VSLI                 176)
135    (UNSPEC_VSRA_N               177)
136    (UNSPEC_VSRI                 178)
137    (UNSPEC_VST1                 179)
138    (UNSPEC_VST1_LANE            180)
139    (UNSPEC_VST2                 181)
140    (UNSPEC_VST2_LANE            182)
141    (UNSPEC_VST3                 183)
142    (UNSPEC_VST3A                184)
143    (UNSPEC_VST3B                185)
144    (UNSPEC_VST3_LANE            186)
145    (UNSPEC_VST4                 187)
146    (UNSPEC_VST4A                188)
147    (UNSPEC_VST4B                189)
148    (UNSPEC_VST4_LANE            190)
149    (UNSPEC_VSTRUCTDUMMY         191)
150    (UNSPEC_VSUB                 192)
151    (UNSPEC_VSUBHN               193)
152    (UNSPEC_VSUBL                194)
153    (UNSPEC_VSUBW                195)
154    (UNSPEC_VTBL                 196)
155    (UNSPEC_VTBX                 197)
156    (UNSPEC_VTRN1                198)
157    (UNSPEC_VTRN2                199)
158    (UNSPEC_VTST                 200)
159    (UNSPEC_VUZP1                201)
160    (UNSPEC_VUZP2                202)
161    (UNSPEC_VZIP1                203)
162    (UNSPEC_VZIP2                204)])
163
164 ;; Double-width vector modes.
165 (define_mode_iterator VD [V8QI V4HI V2SI V2SF])
166
167 ;; Double-width vector modes plus 64-bit elements.
168 (define_mode_iterator VDX [V8QI V4HI V2SI V2SF DI])
169
170 ;; Same, without floating-point elements.
171 (define_mode_iterator VDI [V8QI V4HI V2SI])
172
173 ;; Quad-width vector modes.
174 (define_mode_iterator VQ [V16QI V8HI V4SI V4SF])
175
176 ;; Quad-width vector modes plus 64-bit elements.
177 (define_mode_iterator VQX [V16QI V8HI V4SI V4SF V2DI])
178
179 ;; Same, without floating-point elements.
180 (define_mode_iterator VQI [V16QI V8HI V4SI])
181
182 ;; Same, with TImode added, for moves.
183 (define_mode_iterator VQXMOV [V16QI V8HI V4SI V4SF V2DI TI])
184
185 ;; Opaque structure types wider than TImode.
186 (define_mode_iterator VSTRUCT [EI OI CI XI])
187
188 ;; Number of instructions needed to load/store struct elements. FIXME!
189 (define_mode_attr V_slen [(EI "2") (OI "2") (CI "3") (XI "4")])
190
191 ;; Opaque structure types used in table lookups (except vtbl1/vtbx1).
192 (define_mode_iterator VTAB [TI EI OI])
193
194 ;; vtbl<n> suffix for above modes.
195 (define_mode_attr VTAB_n [(TI "2") (EI "3") (OI "4")])
196
197 ;; Widenable modes.
198 (define_mode_iterator VW [V8QI V4HI V2SI])
199
200 ;; Narrowable modes.
201 (define_mode_iterator VN [V8HI V4SI V2DI])
202
203 ;; All supported vector modes (except singleton DImode).
204 (define_mode_iterator VDQ [V8QI V16QI V4HI V8HI V2SI V4SI V2SF V4SF V2DI])
205
206 ;; All supported vector modes (except those with 64-bit integer elements).
207 (define_mode_iterator VDQW [V8QI V16QI V4HI V8HI V2SI V4SI V2SF V4SF])
208
209 ;; Supported integer vector modes (not 64 bit elements).
210 (define_mode_iterator VDQIW [V8QI V16QI V4HI V8HI V2SI V4SI])
211
212 ;; Supported integer vector modes (not singleton DI)
213 (define_mode_iterator VDQI [V8QI V16QI V4HI V8HI V2SI V4SI V2DI])
214
215 ;; Vector modes, including 64-bit integer elements.
216 (define_mode_iterator VDQX [V8QI V16QI V4HI V8HI V2SI V4SI V2SF V4SF DI V2DI])
217
218 ;; Vector modes including 64-bit integer elements, but no floats.
219 (define_mode_iterator VDQIX [V8QI V16QI V4HI V8HI V2SI V4SI DI V2DI])
220
221 ;; Vector modes for float->int conversions.
222 (define_mode_iterator VCVTF [V2SF V4SF])
223
224 ;; Vector modes form int->float conversions.
225 (define_mode_iterator VCVTI [V2SI V4SI])
226
227 ;; Vector modes for doubleword multiply-accumulate, etc. insns.
228 (define_mode_iterator VMD [V4HI V2SI V2SF])
229
230 ;; Vector modes for quadword multiply-accumulate, etc. insns.
231 (define_mode_iterator VMQ [V8HI V4SI V4SF])
232
233 ;; Above modes combined.
234 (define_mode_iterator VMDQ [V4HI V2SI V2SF V8HI V4SI V4SF])
235
236 ;; As VMD, but integer modes only.
237 (define_mode_iterator VMDI [V4HI V2SI])
238
239 ;; As VMQ, but integer modes only.
240 (define_mode_iterator VMQI [V8HI V4SI])
241
242 ;; Above modes combined.
243 (define_mode_iterator VMDQI [V4HI V2SI V8HI V4SI])
244
245 ;; Modes with 8-bit and 16-bit elements.
246 (define_mode_iterator VX [V8QI V4HI V16QI V8HI])
247
248 ;; Modes with 8-bit elements.
249 (define_mode_iterator VE [V8QI V16QI])
250
251 ;; Modes with 64-bit elements only.
252 (define_mode_iterator V64 [DI V2DI])
253
254 ;; Modes with 32-bit elements only.
255 (define_mode_iterator V32 [V2SI V2SF V4SI V4SF])
256
257 ;; (Opposite) mode to convert to/from for above conversions.
258 (define_mode_attr V_CVTTO [(V2SI "V2SF") (V2SF "V2SI")
259                            (V4SI "V4SF") (V4SF "V4SI")])
260
261 ;; Define element mode for each vector mode.
262 (define_mode_attr V_elem [(V8QI "QI") (V16QI "QI")
263                           (V4HI "HI") (V8HI "HI")
264                           (V2SI "SI") (V4SI "SI")
265                           (V2SF "SF") (V4SF "SF")
266                           (DI "DI")   (V2DI "DI")])
267
268 ;; Element modes for vector extraction, padded up to register size.
269
270 (define_mode_attr V_ext [(V8QI "SI") (V16QI "SI")
271                          (V4HI "SI") (V8HI "SI")
272                          (V2SI "SI") (V4SI "SI")
273                          (V2SF "SF") (V4SF "SF")
274                          (DI "DI") (V2DI "DI")])
275
276 ;; Mode of pair of elements for each vector mode, to define transfer
277 ;; size for structure lane/dup loads and stores.
278 (define_mode_attr V_two_elem [(V8QI "HI") (V16QI "HI")
279                               (V4HI "SI") (V8HI "SI")
280                               (V2SI "V2SI") (V4SI "V2SI")
281                               (V2SF "V2SF") (V4SF "V2SF")
282                               (DI "V2DI")   (V2DI "V2DI")])
283
284 ;; Similar, for three elements.
285 ;; ??? Should we define extra modes so that sizes of all three-element
286 ;; accesses can be accurately represented?
287 (define_mode_attr V_three_elem [(V8QI "SI")   (V16QI "SI")
288                                 (V4HI "V4HI") (V8HI "V4HI")
289                                 (V2SI "V4SI") (V4SI "V4SI")
290                                 (V2SF "V4SF") (V4SF "V4SF")
291                                 (DI "EI")     (V2DI "EI")])
292
293 ;; Similar, for four elements.
294 (define_mode_attr V_four_elem [(V8QI "SI")   (V16QI "SI")
295                                (V4HI "V4HI") (V8HI "V4HI")
296                                (V2SI "V4SI") (V4SI "V4SI")
297                                (V2SF "V4SF") (V4SF "V4SF")
298                                (DI "OI")     (V2DI "OI")])
299
300 ;; Register width from element mode
301 (define_mode_attr V_reg [(V8QI "P") (V16QI "q")
302                          (V4HI "P") (V8HI  "q")
303                          (V2SI "P") (V4SI  "q")
304                          (V2SF "P") (V4SF  "q")
305                          (DI   "P") (V2DI  "q")])
306
307 ;; Wider modes with the same number of elements.
308 (define_mode_attr V_widen [(V8QI "V8HI") (V4HI "V4SI") (V2SI "V2DI")])
309
310 ;; Narrower modes with the same number of elements.
311 (define_mode_attr V_narrow [(V8HI "V8QI") (V4SI "V4HI") (V2DI "V2SI")])
312
313 ;; Modes with half the number of equal-sized elements.
314 (define_mode_attr V_HALF [(V16QI "V8QI") (V8HI "V4HI")
315                           (V4SI  "V2SI") (V4SF "V2SF")
316                           (V2DI "DI")])
317
318 ;; Same, but lower-case.
319 (define_mode_attr V_half [(V16QI "v8qi") (V8HI "v4hi")
320                           (V4SI  "v2si") (V4SF "v2sf")
321                           (V2DI "di")])
322
323 ;; Modes with twice the number of equal-sized elements.
324 (define_mode_attr V_DOUBLE [(V8QI "V16QI") (V4HI "V8HI")
325                             (V2SI "V4SI") (V2SF "V4SF")
326                             (DI "V2DI")])
327
328 ;; Same, but lower-case.
329 (define_mode_attr V_double [(V8QI "v16qi") (V4HI "v8hi")
330                             (V2SI "v4si") (V2SF "v4sf")
331                             (DI "v2di")])
332
333 ;; Modes with double-width elements.
334 (define_mode_attr V_double_width [(V8QI "V4HI") (V16QI "V8HI")
335                                   (V4HI "V2SI") (V8HI "V4SI")
336                                   (V2SI "DI")   (V4SI "V2DI")])
337
338 ;; Mode of result of comparison operations (and bit-select operand 1).
339 (define_mode_attr V_cmp_result [(V8QI "V8QI") (V16QI "V16QI")
340                                 (V4HI "V4HI") (V8HI  "V8HI")
341                                 (V2SI "V2SI") (V4SI  "V4SI")
342                                 (V2SF "V2SI") (V4SF  "V4SI")
343                                 (DI   "DI")   (V2DI  "V2DI")])
344
345 ;; Get element type from double-width mode, for operations where we don't care
346 ;; about signedness.
347 (define_mode_attr V_if_elem [(V8QI "i8")  (V16QI "i8")
348                              (V4HI "i16") (V8HI  "i16")
349                              (V2SI "i32") (V4SI  "i32")
350                              (DI   "i64") (V2DI  "i64")
351                              (V2SF "f32") (V4SF  "f32")])
352
353 ;; Same, but for operations which work on signed values.
354 (define_mode_attr V_s_elem [(V8QI "s8")  (V16QI "s8")
355                             (V4HI "s16") (V8HI  "s16")
356                             (V2SI "s32") (V4SI  "s32")
357                             (DI   "s64") (V2DI  "s64")
358                             (V2SF "f32") (V4SF  "f32")])
359
360 ;; Same, but for operations which work on unsigned values.
361 (define_mode_attr V_u_elem [(V8QI "u8")  (V16QI "u8")
362                             (V4HI "u16") (V8HI  "u16")
363                             (V2SI "u32") (V4SI  "u32")
364                             (DI   "u64") (V2DI  "u64")
365                             (V2SF "f32") (V4SF  "f32")])
366
367 ;; Element types for extraction of unsigned scalars.
368 (define_mode_attr V_uf_sclr [(V8QI "u8")  (V16QI "u8")
369                              (V4HI "u16") (V8HI "u16")
370                              (V2SI "32") (V4SI "32")
371                              (V2SF "32") (V4SF "32")])
372
373 (define_mode_attr V_sz_elem [(V8QI "8")  (V16QI "8")
374                              (V4HI "16") (V8HI  "16")
375                              (V2SI "32") (V4SI  "32")
376                              (DI   "64") (V2DI  "64")
377                              (V2SF "32") (V4SF  "32")])
378
379 ;; Element sizes for duplicating ARM registers to all elements of a vector.
380 (define_mode_attr VD_dup [(V8QI "8") (V4HI "16") (V2SI "32") (V2SF "32")])
381
382 ;; Opaque integer types for results of pair-forming intrinsics (vtrn, etc.)
383 (define_mode_attr V_PAIR [(V8QI "TI") (V16QI "OI")
384                           (V4HI "TI") (V8HI  "OI")
385                           (V2SI "TI") (V4SI  "OI")
386                           (V2SF "TI") (V4SF  "OI")
387                           (DI   "TI") (V2DI  "OI")])
388
389 ;; Same, but lower-case.
390 (define_mode_attr V_pair [(V8QI "ti") (V16QI "oi")
391                           (V4HI "ti") (V8HI  "oi")
392                           (V2SI "ti") (V4SI  "oi")
393                           (V2SF "ti") (V4SF  "oi")
394                           (DI   "ti") (V2DI  "oi")])
395
396 ;; Operations on two halves of a quadword vector.
397 (define_code_iterator vqh_ops [plus smin smax umin umax])
398
399 ;; Same, without unsigned variants (for use with *SFmode pattern).
400 (define_code_iterator vqhs_ops [plus smin smax])
401
402 ;; Assembler mnemonics for above codes.
403 (define_code_attr VQH_mnem [(plus "vadd") (smin "vmin") (smax "vmax")
404                             (umin "vmin") (umax "vmax")])
405
406 ;; Signs of above, where relevant.
407 (define_code_attr VQH_sign [(plus "i") (smin "s") (smax "s") (umin "u")
408                             (umax "u")])
409
410 ;; Extra suffix on some 64-bit insn names (to avoid collision with standard
411 ;; names which we don't want to define).
412 (define_mode_attr V_suf64 [(V8QI "") (V16QI "")
413                            (V4HI "") (V8HI "")
414                            (V2SI "") (V4SI "")
415                            (V2SF "") (V4SF "")
416                            (DI "_neon") (V2DI "")])
417
418 ;; Scalars to be presented to scalar multiplication instructions
419 ;; must satisfy the following constraints.
420 ;; 1. If the mode specifies 16-bit elements, the scalar must be in D0-D7.
421 ;; 2. If the mode specifies 32-bit elements, the scalar must be in D0-D15.
422 ;; This mode attribute is used to obtain the correct register constraints.
423 (define_mode_attr scalar_mul_constraint [(V4HI "x") (V2SI "t") (V2SF "t")
424                                          (V8HI "x") (V4SI "t") (V4SF "t")])
425
426 ;; Attribute used to permit string comparisons against <VQH_mnem> in
427 ;; neon_type attribute definitions.
428 (define_attr "vqh_mnem" "vadd,vmin,vmax" (const_string "vadd"))
429
430 ;; Predicates used for setting neon_type
431
432 (define_mode_attr Is_float_mode [(V8QI "false") (V16QI "false")
433                                  (V4HI "false") (V8HI "false")
434                                  (V2SI "false") (V4SI "false")
435                                  (V2SF "true") (V4SF "true")
436                                  (DI "false") (V2DI "false")])
437
438 (define_mode_attr Scalar_mul_8_16 [(V8QI "true") (V16QI "true")
439                                    (V4HI "true") (V8HI "true")
440                                    (V2SI "false") (V4SI "false")
441                                    (V2SF "false") (V4SF "false")
442                                    (DI "false") (V2DI "false")])
443
444
445 (define_mode_attr Is_d_reg [(V8QI "true") (V16QI "false")
446                             (V4HI "true") (V8HI  "false")
447                             (V2SI "true") (V4SI  "false")
448                             (V2SF "true") (V4SF  "false")
449                             (DI   "true") (V2DI  "false")])
450
451 (define_mode_attr V_mode_nunits [(V8QI "8") (V16QI "16")
452                                  (V4HI "4") (V8HI "8")
453                                  (V2SI "2") (V4SI "4")
454                                  (V2SF "2") (V4SF "4")
455                                  (DI "1")   (V2DI "2")])
456
457 (define_insn "*neon_mov<mode>"
458   [(set (match_operand:VD 0 "nonimmediate_operand"
459           "=w,Uv,w, w,  ?r,?w,?r,?r, ?Us")
460         (match_operand:VD 1 "general_operand"
461           " w,w, Dn,Uvi, w, r, r, Usi,r"))]
462   "TARGET_NEON"
463 {
464   if (which_alternative == 2)
465     {
466       int width, is_valid;
467       static char templ[40];
468
469       is_valid = neon_immediate_valid_for_move (operands[1], <MODE>mode,
470         &operands[1], &width);
471
472       gcc_assert (is_valid != 0);
473
474       if (width == 0)
475         return "vmov.f32\t%P0, %1  @ <mode>";
476       else
477         sprintf (templ, "vmov.i%d\t%%P0, %%1  @ <mode>", width);
478
479       return templ;
480     }
481
482   /* FIXME: If the memory layout is changed in big-endian mode, output_move_vfp
483      below must be changed to output_move_neon (which will use the
484      element/structure loads/stores), and the constraint changed to 'Um' instead
485      of 'Uv'.  */
486
487   switch (which_alternative)
488     {
489     case 0: return "vmov\t%P0, %P1  @ <mode>";
490     case 1: case 3: return output_move_vfp (operands);
491     case 2: gcc_unreachable ();
492     case 4: return "vmov\t%Q0, %R0, %P1  @ <mode>";
493     case 5: return "vmov\t%P0, %Q1, %R1  @ <mode>";
494     default: return output_move_double (operands);
495     }
496 }
497  [(set_attr "neon_type" "neon_int_1,*,neon_vmov,*,neon_mrrc,neon_mcr_2_mcrr,*,*,*")
498   (set_attr "type" "*,f_stored,*,f_loadd,*,*,alu,load2,store2")
499   (set_attr "insn" "*,*,*,*,*,*,mov,*,*")
500   (set_attr "length" "4,4,4,4,4,4,8,8,8")
501   (set_attr "pool_range"     "*,*,*,1020,*,*,*,1020,*")
502   (set_attr "neg_pool_range" "*,*,*,1008,*,*,*,1008,*")])
503
504 (define_insn "*neon_mov<mode>"
505   [(set (match_operand:VQXMOV 0 "nonimmediate_operand"
506           "=w,Un,w, w,  ?r,?w,?r,?r,  ?Us")
507         (match_operand:VQXMOV 1 "general_operand"
508           " w,w, Dn,Uni, w, r, r, Usi, r"))]
509   "TARGET_NEON"
510 {
511   if (which_alternative == 2)
512     {
513       int width, is_valid;
514       static char templ[40];
515
516       is_valid = neon_immediate_valid_for_move (operands[1], <MODE>mode,
517         &operands[1], &width);
518
519       gcc_assert (is_valid != 0);
520
521       if (width == 0)
522         return "vmov.f32\t%q0, %1  @ <mode>";
523       else
524         sprintf (templ, "vmov.i%d\t%%q0, %%1  @ <mode>", width);
525
526       return templ;
527     }
528
529   switch (which_alternative)
530     {
531     case 0: return "vmov\t%q0, %q1  @ <mode>";
532     case 1: case 3: return output_move_neon (operands);
533     case 2: gcc_unreachable ();
534     case 4: return "vmov\t%Q0, %R0, %e1  @ <mode>\;vmov\t%J0, %K0, %f1";
535     case 5: return "vmov\t%e0, %Q1, %R1  @ <mode>\;vmov\t%f0, %J1, %K1";
536     default: return output_move_quad (operands);
537     }
538 }
539   [(set_attr "neon_type" "neon_int_1,neon_stm_2,neon_vmov,neon_ldm_2,\
540                           neon_mrrc,neon_mcr_2_mcrr,*,*,*")
541    (set_attr "type" "*,*,*,*,*,*,alu,load4,store4")
542    (set_attr "insn" "*,*,*,*,*,*,mov,*,*")
543    (set_attr "length" "4,8,4,8,8,8,16,8,16")
544    (set_attr "pool_range" "*,*,*,1020,*,*,*,1020,*")
545    (set_attr "neg_pool_range" "*,*,*,1008,*,*,*,1008,*")])
546
547 (define_expand "movti"
548   [(set (match_operand:TI 0 "nonimmediate_operand" "")
549         (match_operand:TI 1 "general_operand" ""))]
550   "TARGET_NEON"
551 {
552 })
553
554 (define_expand "mov<mode>"
555   [(set (match_operand:VSTRUCT 0 "nonimmediate_operand" "")
556         (match_operand:VSTRUCT 1 "general_operand" ""))]
557   "TARGET_NEON"
558 {
559 })
560
561 (define_insn "*neon_mov<mode>"
562   [(set (match_operand:VSTRUCT 0 "nonimmediate_operand" "=w,Ut,w")
563         (match_operand:VSTRUCT 1 "general_operand"      " w,w, Ut"))]
564   "TARGET_NEON"
565 {
566   switch (which_alternative)
567     {
568     case 0: return "#";
569     case 1: case 2: return output_move_neon (operands);
570     default: gcc_unreachable ();
571     }
572 }
573   [(set_attr "neon_type" "neon_int_1,neon_stm_2,neon_ldm_2")
574    (set_attr "length" "<V_slen>,<V_slen>,<V_slen>")])
575
576 (define_split
577   [(set (match_operand:EI 0 "s_register_operand" "")
578         (match_operand:EI 1 "s_register_operand" ""))]
579   "TARGET_NEON && reload_completed"
580   [(set (match_dup 0) (match_dup 1))
581    (set (match_dup 2) (match_dup 3))]
582 {
583   int rdest = REGNO (operands[0]);
584   int rsrc = REGNO (operands[1]);
585   rtx dest[2], src[2];
586
587   dest[0] = gen_rtx_REG (TImode, rdest);
588   src[0] = gen_rtx_REG (TImode, rsrc);
589   dest[1] = gen_rtx_REG (DImode, rdest + 4);
590   src[1] = gen_rtx_REG (DImode, rsrc + 4);
591
592   neon_disambiguate_copy (operands, dest, src, 2);
593 })
594
595 (define_split
596   [(set (match_operand:OI 0 "s_register_operand" "")
597         (match_operand:OI 1 "s_register_operand" ""))]
598   "TARGET_NEON && reload_completed"
599   [(set (match_dup 0) (match_dup 1))
600    (set (match_dup 2) (match_dup 3))]
601 {
602   int rdest = REGNO (operands[0]);
603   int rsrc = REGNO (operands[1]);
604   rtx dest[2], src[2];
605
606   dest[0] = gen_rtx_REG (TImode, rdest);
607   src[0] = gen_rtx_REG (TImode, rsrc);
608   dest[1] = gen_rtx_REG (TImode, rdest + 4);
609   src[1] = gen_rtx_REG (TImode, rsrc + 4);
610
611   neon_disambiguate_copy (operands, dest, src, 2);
612 })
613
614 (define_split
615   [(set (match_operand:CI 0 "s_register_operand" "")
616         (match_operand:CI 1 "s_register_operand" ""))]
617   "TARGET_NEON && reload_completed"
618   [(set (match_dup 0) (match_dup 1))
619    (set (match_dup 2) (match_dup 3))
620    (set (match_dup 4) (match_dup 5))]
621 {
622   int rdest = REGNO (operands[0]);
623   int rsrc = REGNO (operands[1]);
624   rtx dest[3], src[3];
625
626   dest[0] = gen_rtx_REG (TImode, rdest);
627   src[0] = gen_rtx_REG (TImode, rsrc);
628   dest[1] = gen_rtx_REG (TImode, rdest + 4);
629   src[1] = gen_rtx_REG (TImode, rsrc + 4);
630   dest[2] = gen_rtx_REG (TImode, rdest + 8);
631   src[2] = gen_rtx_REG (TImode, rsrc + 8);
632
633   neon_disambiguate_copy (operands, dest, src, 3);
634 })
635
636 (define_split
637   [(set (match_operand:XI 0 "s_register_operand" "")
638         (match_operand:XI 1 "s_register_operand" ""))]
639   "TARGET_NEON && reload_completed"
640   [(set (match_dup 0) (match_dup 1))
641    (set (match_dup 2) (match_dup 3))
642    (set (match_dup 4) (match_dup 5))
643    (set (match_dup 6) (match_dup 7))]
644 {
645   int rdest = REGNO (operands[0]);
646   int rsrc = REGNO (operands[1]);
647   rtx dest[4], src[4];
648
649   dest[0] = gen_rtx_REG (TImode, rdest);
650   src[0] = gen_rtx_REG (TImode, rsrc);
651   dest[1] = gen_rtx_REG (TImode, rdest + 4);
652   src[1] = gen_rtx_REG (TImode, rsrc + 4);
653   dest[2] = gen_rtx_REG (TImode, rdest + 8);
654   src[2] = gen_rtx_REG (TImode, rsrc + 8);
655   dest[3] = gen_rtx_REG (TImode, rdest + 12);
656   src[3] = gen_rtx_REG (TImode, rsrc + 12);
657
658   neon_disambiguate_copy (operands, dest, src, 4);
659 })
660
661 (define_insn "vec_set<mode>_internal"
662   [(set (match_operand:VD 0 "s_register_operand" "=w")
663         (vec_merge:VD
664           (vec_duplicate:VD
665             (match_operand:<V_elem> 1 "s_register_operand" "r"))
666           (match_operand:VD 3 "s_register_operand" "0")
667           (match_operand:SI 2 "immediate_operand" "i")))]
668   "TARGET_NEON"
669 {
670   int elt = ffs ((int) INTVAL (operands[2]) - 1);
671   if (BYTES_BIG_ENDIAN)
672     elt = GET_MODE_NUNITS (<MODE>mode) - 1 - elt;
673   operands[2] = GEN_INT (elt);
674   
675   return "vmov%?.<V_uf_sclr>\t%P0[%c2], %1";
676 }
677   [(set_attr "predicable" "yes")
678    (set_attr "neon_type" "neon_mcr")])
679
680 (define_insn "vec_set<mode>_internal"
681   [(set (match_operand:VQ 0 "s_register_operand" "=w")
682         (vec_merge:VQ
683           (vec_duplicate:VQ
684             (match_operand:<V_elem> 1 "s_register_operand" "r"))
685           (match_operand:VQ 3 "s_register_operand" "0")
686           (match_operand:SI 2 "immediate_operand" "i")))]
687   "TARGET_NEON"
688 {
689   HOST_WIDE_INT elem = ffs ((int) INTVAL (operands[2])) - 1;
690   int half_elts = GET_MODE_NUNITS (<MODE>mode) / 2;
691   int elt = elem % half_elts;
692   int hi = (elem / half_elts) * 2;
693   int regno = REGNO (operands[0]);
694
695   if (BYTES_BIG_ENDIAN)
696     elt = half_elts - 1 - elt;
697
698   operands[0] = gen_rtx_REG (<V_HALF>mode, regno + hi);
699   operands[2] = GEN_INT (elt);
700
701   return "vmov%?.<V_uf_sclr>\t%P0[%c2], %1";
702 }
703   [(set_attr "predicable" "yes")
704    (set_attr "neon_type" "neon_mcr")]
705 )
706
707 (define_insn "vec_setv2di_internal"
708   [(set (match_operand:V2DI 0 "s_register_operand" "=w")
709         (vec_merge:V2DI
710           (vec_duplicate:V2DI
711             (match_operand:DI 1 "s_register_operand" "r"))
712           (match_operand:V2DI 3 "s_register_operand" "0")
713           (match_operand:SI 2 "immediate_operand" "i")))]
714   "TARGET_NEON"
715 {
716   HOST_WIDE_INT elem = ffs ((int) INTVAL (operands[2])) - 1;
717   int regno = REGNO (operands[0]) + 2 * elem;
718
719   operands[0] = gen_rtx_REG (DImode, regno);
720
721   return "vmov%?.64\t%P0, %Q1, %R1";
722 }
723   [(set_attr "predicable" "yes")
724    (set_attr "neon_type" "neon_mcr_2_mcrr")]
725 )
726
727 (define_expand "vec_set<mode>"
728   [(match_operand:VDQ 0 "s_register_operand" "")
729    (match_operand:<V_elem> 1 "s_register_operand" "")
730    (match_operand:SI 2 "immediate_operand" "")]
731   "TARGET_NEON"
732 {
733   HOST_WIDE_INT elem = (HOST_WIDE_INT) 1 << INTVAL (operands[2]);
734   emit_insn (gen_vec_set<mode>_internal (operands[0], operands[1],
735                                          GEN_INT (elem), operands[0]));
736   DONE;
737 })
738
739 (define_insn "vec_extract<mode>"
740   [(set (match_operand:<V_elem> 0 "s_register_operand" "=r")
741         (vec_select:<V_elem>
742           (match_operand:VD 1 "s_register_operand" "w")
743           (parallel [(match_operand:SI 2 "immediate_operand" "i")])))]
744   "TARGET_NEON"
745 {
746   if (BYTES_BIG_ENDIAN)
747     {
748       int elt = INTVAL (operands[2]);
749       elt = GET_MODE_NUNITS (<MODE>mode) - 1 - elt;
750       operands[2] = GEN_INT (elt);
751     }
752   return "vmov%?.<V_uf_sclr>\t%0, %P1[%c2]";
753 }
754   [(set_attr "predicable" "yes")
755    (set_attr "neon_type" "neon_bp_simple")]
756 )
757
758 (define_insn "vec_extract<mode>"
759   [(set (match_operand:<V_elem> 0 "s_register_operand" "=r")
760         (vec_select:<V_elem>
761           (match_operand:VQ 1 "s_register_operand" "w")
762           (parallel [(match_operand:SI 2 "immediate_operand" "i")])))]
763   "TARGET_NEON"
764 {
765   int half_elts = GET_MODE_NUNITS (<MODE>mode) / 2;
766   int elt = INTVAL (operands[2]) % half_elts;
767   int hi = (INTVAL (operands[2]) / half_elts) * 2;
768   int regno = REGNO (operands[1]);
769
770   if (BYTES_BIG_ENDIAN)
771     elt = half_elts - 1 - elt;
772
773   operands[1] = gen_rtx_REG (<V_HALF>mode, regno + hi);
774   operands[2] = GEN_INT (elt);
775
776   return "vmov%?.<V_uf_sclr>\t%0, %P1[%c2]";
777 }
778   [(set_attr "predicable" "yes")
779    (set_attr "neon_type" "neon_bp_simple")]
780 )
781
782 (define_insn "vec_extractv2di"
783   [(set (match_operand:DI 0 "s_register_operand" "=r")
784         (vec_select:DI
785           (match_operand:V2DI 1 "s_register_operand" "w")
786           (parallel [(match_operand:SI 2 "immediate_operand" "i")])))]
787   "TARGET_NEON"
788 {
789   int regno = REGNO (operands[1]) + INTVAL (operands[2]);
790
791   operands[1] = gen_rtx_REG (DImode, regno);
792
793   return "vmov%?.64\t%Q0, %R0, %P1";
794 }
795   [(set_attr "predicable" "yes")
796    (set_attr "neon_type" "neon_int_1")]
797 )
798
799 (define_expand "vec_init<mode>"
800   [(match_operand:VDQ 0 "s_register_operand" "")
801    (match_operand 1 "" "")]
802   "TARGET_NEON"
803 {
804   neon_expand_vector_init (operands[0], operands[1]);
805   DONE;
806 })
807
808 ;; Doubleword and quadword arithmetic.
809
810 ;; NOTE: vadd/vsub and some other instructions also support 64-bit integer
811 ;; element size, which we could potentially use for "long long" operations. We
812 ;; don't want to do this at present though, because moving values from the
813 ;; vector unit to the ARM core is currently slow and 64-bit addition (etc.) is
814 ;; easy to do with ARM instructions anyway.
815
816 (define_insn "*add<mode>3_neon"
817   [(set (match_operand:VDQ 0 "s_register_operand" "=w")
818         (plus:VDQ (match_operand:VDQ 1 "s_register_operand" "w")
819                   (match_operand:VDQ 2 "s_register_operand" "w")))]
820   "TARGET_NEON"
821   "vadd.<V_if_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
822   [(set (attr "neon_type")
823       (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
824                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
825                                   (const_string "neon_fp_vadd_ddd_vabs_dd")
826                                   (const_string "neon_fp_vadd_qqq_vabs_qq"))
827                     (const_string "neon_int_1")))]
828 )
829
830 (define_insn "*sub<mode>3_neon"
831   [(set (match_operand:VDQ 0 "s_register_operand" "=w")
832         (minus:VDQ (match_operand:VDQ 1 "s_register_operand" "w")
833                    (match_operand:VDQ 2 "s_register_operand" "w")))]
834   "TARGET_NEON"
835   "vsub.<V_if_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
836   [(set (attr "neon_type")
837       (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
838                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
839                                   (const_string "neon_fp_vadd_ddd_vabs_dd")
840                                   (const_string "neon_fp_vadd_qqq_vabs_qq"))
841                     (const_string "neon_int_2")))]
842 )
843
844 (define_insn "*mul<mode>3_neon"
845   [(set (match_operand:VDQ 0 "s_register_operand" "=w")
846         (mult:VDQ (match_operand:VDQ 1 "s_register_operand" "w")
847                   (match_operand:VDQ 2 "s_register_operand" "w")))]
848   "TARGET_NEON"
849   "vmul.<V_if_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
850   [(set (attr "neon_type")
851       (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
852                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
853                                   (const_string "neon_fp_vadd_ddd_vabs_dd")
854                                   (const_string "neon_fp_vadd_qqq_vabs_qq"))
855                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
856                                   (if_then_else
857                                     (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
858                                     (const_string "neon_mul_ddd_8_16_qdd_16_8_long_32_16_long")
859                                     (const_string "neon_mul_qqq_8_16_32_ddd_32"))
860                                   (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
861                                     (const_string "neon_mul_qqq_8_16_32_ddd_32")
862                                     (const_string "neon_mul_qqq_8_16_32_ddd_32")))))]
863 )
864
865 (define_insn "*mul<mode>3add<mode>_neon"
866   [(set (match_operand:VDQ 0 "s_register_operand" "=w")
867         (plus:VDQ (mult:VDQ (match_operand:VDQ 2 "s_register_operand" "w")
868                             (match_operand:VDQ 3 "s_register_operand" "w"))
869                   (match_operand:VDQ 1 "s_register_operand" "0")))]
870   "TARGET_NEON"
871   "vmla.<V_if_elem>\t%<V_reg>0, %<V_reg>2, %<V_reg>3"
872   [(set (attr "neon_type")
873       (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
874                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
875                                   (const_string "neon_fp_vmla_ddd")
876                                   (const_string "neon_fp_vmla_qqq"))
877                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
878                                   (if_then_else
879                                     (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
880                                     (const_string "neon_mla_ddd_8_16_qdd_16_8_long_32_16_long")
881                                     (const_string "neon_mla_ddd_32_qqd_16_ddd_32_scalar_qdd_64_32_long_scalar_qdd_64_32_long"))
882                                   (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
883                                     (const_string "neon_mla_qqq_8_16")
884                                     (const_string "neon_mla_qqq_32_qqd_32_scalar")))))]
885 )
886
887 (define_insn "*mul<mode>3neg<mode>add<mode>_neon"
888   [(set (match_operand:VDQ 0 "s_register_operand" "=w")
889         (minus:VDQ (match_operand:VDQ 1 "s_register_operand" "0")
890                    (mult:VDQ (match_operand:VDQ 2 "s_register_operand" "w")
891                              (match_operand:VDQ 3 "s_register_operand" "w"))))]
892   "TARGET_NEON"
893   "vmls.<V_if_elem>\t%<V_reg>0, %<V_reg>2, %<V_reg>3"
894   [(set (attr "neon_type")
895       (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
896                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
897                                   (const_string "neon_fp_vmla_ddd")
898                                   (const_string "neon_fp_vmla_qqq"))
899                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
900                                   (if_then_else
901                                     (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
902                                     (const_string "neon_mla_ddd_8_16_qdd_16_8_long_32_16_long")
903                                     (const_string "neon_mla_ddd_32_qqd_16_ddd_32_scalar_qdd_64_32_long_scalar_qdd_64_32_long"))
904                                   (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
905                                     (const_string "neon_mla_qqq_8_16")
906                                     (const_string "neon_mla_qqq_32_qqd_32_scalar")))))]
907 )
908
909 (define_insn "ior<mode>3"
910   [(set (match_operand:VDQ 0 "s_register_operand" "=w,w")
911         (ior:VDQ (match_operand:VDQ 1 "s_register_operand" "w,0")
912                  (match_operand:VDQ 2 "neon_logic_op2" "w,Dl")))]
913   "TARGET_NEON"
914 {
915   switch (which_alternative)
916     {
917     case 0: return "vorr\t%<V_reg>0, %<V_reg>1, %<V_reg>2";
918     case 1: return neon_output_logic_immediate ("vorr", &operands[2],
919                      <MODE>mode, 0, VALID_NEON_QREG_MODE (<MODE>mode));
920     default: gcc_unreachable ();
921     }
922 }
923   [(set_attr "neon_type" "neon_int_1")]
924 )
925
926 (define_insn "iordi3_neon"
927   [(set (match_operand:DI 0 "s_register_operand" "=w,w")
928         (unspec:DI [(match_operand:DI 1 "s_register_operand" "w,0")
929                     (match_operand:DI 2 "neon_logic_op2" "w,Dl")]
930                     UNSPEC_VORR))]
931   "TARGET_NEON"
932 {
933   switch (which_alternative)
934     {
935     case 0: return "vorr\t%P0, %P1, %P2";
936     case 1: return neon_output_logic_immediate ("vorr", &operands[2],
937                      DImode, 0, VALID_NEON_QREG_MODE (DImode));
938     default: gcc_unreachable ();
939     }
940 }
941   [(set_attr "neon_type" "neon_int_1")]
942 )
943
944 ;; The concrete forms of the Neon immediate-logic instructions are vbic and
945 ;; vorr. We support the pseudo-instruction vand instead, because that
946 ;; corresponds to the canonical form the middle-end expects to use for
947 ;; immediate bitwise-ANDs.
948
949 (define_insn "and<mode>3"
950   [(set (match_operand:VDQ 0 "s_register_operand" "=w,w")
951         (and:VDQ (match_operand:VDQ 1 "s_register_operand" "w,0")
952                  (match_operand:VDQ 2 "neon_inv_logic_op2" "w,DL")))]
953   "TARGET_NEON"
954 {
955   switch (which_alternative)
956     {
957     case 0: return "vand\t%<V_reg>0, %<V_reg>1, %<V_reg>2";
958     case 1: return neon_output_logic_immediate ("vand", &operands[2],
959                      <MODE>mode, 1, VALID_NEON_QREG_MODE (<MODE>mode));
960     default: gcc_unreachable ();
961     }
962 }
963   [(set_attr "neon_type" "neon_int_1")]
964 )
965
966 (define_insn "anddi3_neon"
967   [(set (match_operand:DI 0 "s_register_operand" "=w,w")
968         (unspec:DI [(match_operand:DI 1 "s_register_operand" "w,0")
969                     (match_operand:DI 2 "neon_inv_logic_op2" "w,DL")]
970                     UNSPEC_VAND))]
971   "TARGET_NEON"
972 {
973   switch (which_alternative)
974     {
975     case 0: return "vand\t%P0, %P1, %P2";
976     case 1: return neon_output_logic_immediate ("vand", &operands[2],
977                      DImode, 1, VALID_NEON_QREG_MODE (DImode));
978     default: gcc_unreachable ();
979     }
980 }
981   [(set_attr "neon_type" "neon_int_1")]
982 )
983
984 (define_insn "orn<mode>3_neon"
985   [(set (match_operand:VDQ 0 "s_register_operand" "=w")
986         (ior:VDQ (match_operand:VDQ 1 "s_register_operand" "w")
987                  (not:VDQ (match_operand:VDQ 2 "s_register_operand" "w"))))]
988   "TARGET_NEON"
989   "vorn\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
990   [(set_attr "neon_type" "neon_int_1")]
991 )
992
993 (define_insn "orndi3_neon"
994   [(set (match_operand:DI 0 "s_register_operand" "=w")
995         (unspec:DI [(match_operand:DI 1 "s_register_operand" "w")
996                     (match_operand:DI 2 "s_register_operand" "w")]
997                     UNSPEC_VORN))]
998   "TARGET_NEON"
999   "vorn\t%P0, %P1, %P2"
1000   [(set_attr "neon_type" "neon_int_1")]
1001 )
1002
1003 (define_insn "bic<mode>3_neon"
1004   [(set (match_operand:VDQ 0 "s_register_operand" "=w")
1005         (and:VDQ (match_operand:VDQ 1 "s_register_operand" "w")
1006                   (not:VDQ (match_operand:VDQ 2 "s_register_operand" "w"))))]
1007   "TARGET_NEON"
1008   "vbic\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
1009   [(set_attr "neon_type" "neon_int_1")]
1010 )
1011
1012 (define_insn "bicdi3_neon"
1013   [(set (match_operand:DI 0 "s_register_operand" "=w")
1014         (unspec:DI [(match_operand:DI 1 "s_register_operand" "w")
1015                      (match_operand:DI 2 "s_register_operand" "w")]
1016                     UNSPEC_VBIC))]
1017   "TARGET_NEON"
1018   "vbic\t%P0, %P1, %P2"
1019   [(set_attr "neon_type" "neon_int_1")]
1020 )
1021
1022 (define_insn "xor<mode>3"
1023   [(set (match_operand:VDQ 0 "s_register_operand" "=w")
1024         (xor:VDQ (match_operand:VDQ 1 "s_register_operand" "w")
1025                  (match_operand:VDQ 2 "s_register_operand" "w")))]
1026   "TARGET_NEON"
1027   "veor\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
1028   [(set_attr "neon_type" "neon_int_1")]
1029 )
1030
1031 (define_insn "xordi3_neon"
1032   [(set (match_operand:DI 0 "s_register_operand" "=w")
1033         (unspec:DI [(match_operand:DI 1 "s_register_operand" "w")
1034                      (match_operand:DI 2 "s_register_operand" "w")]
1035                     UNSPEC_VEOR))]
1036   "TARGET_NEON"
1037   "veor\t%P0, %P1, %P2"
1038   [(set_attr "neon_type" "neon_int_1")]
1039 )
1040
1041 (define_insn "one_cmpl<mode>2"
1042   [(set (match_operand:VDQ 0 "s_register_operand" "=w")
1043         (not:VDQ (match_operand:VDQ 1 "s_register_operand" "w")))]
1044   "TARGET_NEON"
1045   "vmvn\t%<V_reg>0, %<V_reg>1"
1046   [(set_attr "neon_type" "neon_int_1")]
1047 )
1048
1049 (define_insn "abs<mode>2"
1050   [(set (match_operand:VDQW 0 "s_register_operand" "=w")
1051         (abs:VDQW (match_operand:VDQW 1 "s_register_operand" "w")))]
1052   "TARGET_NEON"
1053   "vabs.<V_s_elem>\t%<V_reg>0, %<V_reg>1"
1054   [(set (attr "neon_type")
1055       (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
1056                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
1057                                   (const_string "neon_fp_vadd_ddd_vabs_dd")
1058                                   (const_string "neon_fp_vadd_qqq_vabs_qq"))
1059                     (const_string "neon_int_3")))]
1060 )
1061
1062 (define_insn "neg<mode>2"
1063   [(set (match_operand:VDQW 0 "s_register_operand" "=w")
1064         (neg:VDQW (match_operand:VDQW 1 "s_register_operand" "w")))]
1065   "TARGET_NEON"
1066   "vneg.<V_s_elem>\t%<V_reg>0, %<V_reg>1"
1067   [(set (attr "neon_type")
1068       (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
1069                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
1070                                   (const_string "neon_fp_vadd_ddd_vabs_dd")
1071                                   (const_string "neon_fp_vadd_qqq_vabs_qq"))
1072                     (const_string "neon_int_3")))]
1073 )
1074
1075 (define_insn "*umin<mode>3_neon"
1076   [(set (match_operand:VDQIW 0 "s_register_operand" "=w")
1077         (umin:VDQIW (match_operand:VDQIW 1 "s_register_operand" "w")
1078                     (match_operand:VDQIW 2 "s_register_operand" "w")))]
1079   "TARGET_NEON"
1080   "vmin.<V_u_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
1081   [(set_attr "neon_type" "neon_int_5")]
1082 )
1083
1084 (define_insn "*umax<mode>3_neon"
1085   [(set (match_operand:VDQIW 0 "s_register_operand" "=w")
1086         (umax:VDQIW (match_operand:VDQIW 1 "s_register_operand" "w")
1087                     (match_operand:VDQIW 2 "s_register_operand" "w")))]
1088   "TARGET_NEON"
1089   "vmax.<V_u_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
1090   [(set_attr "neon_type" "neon_int_5")]
1091 )
1092
1093 (define_insn "*smin<mode>3_neon"
1094   [(set (match_operand:VDQW 0 "s_register_operand" "=w")
1095         (smin:VDQW (match_operand:VDQW 1 "s_register_operand" "w")
1096                    (match_operand:VDQW 2 "s_register_operand" "w")))]
1097   "TARGET_NEON"
1098   "vmin.<V_s_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
1099   [(set (attr "neon_type")
1100       (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
1101                     (const_string "neon_fp_vadd_ddd_vabs_dd")
1102                     (const_string "neon_int_5")))]
1103 )
1104
1105 (define_insn "*smax<mode>3_neon"
1106   [(set (match_operand:VDQW 0 "s_register_operand" "=w")
1107         (smax:VDQW (match_operand:VDQW 1 "s_register_operand" "w")
1108                    (match_operand:VDQW 2 "s_register_operand" "w")))]
1109   "TARGET_NEON"
1110   "vmax.<V_s_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
1111   [(set (attr "neon_type")
1112       (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
1113                     (const_string "neon_fp_vadd_ddd_vabs_dd")
1114                     (const_string "neon_int_5")))]
1115 )
1116
1117 ; TODO: V2DI shifts are current disabled because there are bugs in the
1118 ; generic vectorizer code.  It ends up creating a V2DI constructor with
1119 ; SImode elements.
1120
1121 (define_insn "vashl<mode>3"
1122   [(set (match_operand:VDQIW 0 "s_register_operand" "=w")
1123         (ashift:VDQIW (match_operand:VDQIW 1 "s_register_operand" "w")
1124                       (match_operand:VDQIW 2 "s_register_operand" "w")))]
1125   "TARGET_NEON"
1126   "vshl.<V_s_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
1127   [(set (attr "neon_type")
1128       (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
1129                     (const_string "neon_vshl_ddd")
1130                     (const_string "neon_shift_3")))]
1131 )
1132
1133 ; Used for implementing logical shift-right, which is a left-shift by a negative
1134 ; amount, with signed operands. This is essentially the same as ashl<mode>3
1135 ; above, but using an unspec in case GCC tries anything tricky with negative
1136 ; shift amounts.
1137
1138 (define_insn "ashl<mode>3_signed"
1139   [(set (match_operand:VDQI 0 "s_register_operand" "=w")
1140         (unspec:VDQI [(match_operand:VDQI 1 "s_register_operand" "w")
1141                       (match_operand:VDQI 2 "s_register_operand" "w")]
1142                      UNSPEC_ASHIFT_SIGNED))]
1143   "TARGET_NEON"
1144   "vshl.<V_s_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
1145   [(set (attr "neon_type")
1146       (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
1147                     (const_string "neon_vshl_ddd")
1148                     (const_string "neon_shift_3")))]
1149 )
1150
1151 ; Used for implementing logical shift-right, which is a left-shift by a negative
1152 ; amount, with unsigned operands.
1153
1154 (define_insn "ashl<mode>3_unsigned"
1155   [(set (match_operand:VDQI 0 "s_register_operand" "=w")
1156         (unspec:VDQI [(match_operand:VDQI 1 "s_register_operand" "w")
1157                       (match_operand:VDQI 2 "s_register_operand" "w")]
1158                      UNSPEC_ASHIFT_UNSIGNED))]
1159   "TARGET_NEON"
1160   "vshl.<V_u_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
1161   [(set (attr "neon_type")
1162       (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
1163                     (const_string "neon_vshl_ddd")
1164                     (const_string "neon_shift_3")))]
1165 )
1166
1167 (define_expand "vashr<mode>3"
1168   [(set (match_operand:VDQIW 0 "s_register_operand" "")
1169         (ashiftrt:VDQIW (match_operand:VDQIW 1 "s_register_operand" "")
1170                         (match_operand:VDQIW 2 "s_register_operand" "")))]
1171   "TARGET_NEON"
1172 {
1173   rtx neg = gen_reg_rtx (<MODE>mode);
1174
1175   emit_insn (gen_neg<mode>2 (neg, operands[2]));
1176   emit_insn (gen_ashl<mode>3_signed (operands[0], operands[1], neg));
1177
1178   DONE;
1179 })
1180
1181 (define_expand "vlshr<mode>3"
1182   [(set (match_operand:VDQIW 0 "s_register_operand" "")
1183         (lshiftrt:VDQIW (match_operand:VDQIW 1 "s_register_operand" "")
1184                         (match_operand:VDQIW 2 "s_register_operand" "")))]
1185   "TARGET_NEON"
1186 {
1187   rtx neg = gen_reg_rtx (<MODE>mode);
1188
1189   emit_insn (gen_neg<mode>2 (neg, operands[2]));
1190   emit_insn (gen_ashl<mode>3_unsigned (operands[0], operands[1], neg));
1191
1192   DONE;
1193 })
1194
1195 ;; Widening operations
1196
1197 (define_insn "widen_ssum<mode>3"
1198   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
1199         (plus:<V_widen> (sign_extend:<V_widen>
1200                           (match_operand:VW 1 "s_register_operand" "%w"))
1201                         (match_operand:<V_widen> 2 "s_register_operand" "w")))]
1202   "TARGET_NEON"
1203   "vaddw.<V_s_elem>\t%q0, %q2, %P1"
1204   [(set_attr "neon_type" "neon_int_3")]
1205 )
1206
1207 (define_insn "widen_usum<mode>3"
1208   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
1209         (plus:<V_widen> (zero_extend:<V_widen>
1210                           (match_operand:VW 1 "s_register_operand" "%w"))
1211                         (match_operand:<V_widen> 2 "s_register_operand" "w")))]
1212   "TARGET_NEON"
1213   "vaddw.<V_u_elem>\t%q0, %q2, %P1"
1214   [(set_attr "neon_type" "neon_int_3")]
1215 )
1216
1217 ;; VEXT can be used to synthesize coarse whole-vector shifts with 8-bit
1218 ;; shift-count granularity. That's good enough for the middle-end's current
1219 ;; needs.
1220
1221 (define_expand "vec_shr_<mode>"
1222   [(match_operand:VDQ 0 "s_register_operand" "")
1223    (match_operand:VDQ 1 "s_register_operand" "")
1224    (match_operand:SI 2 "const_multiple_of_8_operand" "")]
1225   "TARGET_NEON"
1226 {
1227   rtx zero_reg;
1228   HOST_WIDE_INT num_bits = INTVAL (operands[2]);
1229   const int width = GET_MODE_BITSIZE (<MODE>mode);
1230   const enum machine_mode bvecmode = (width == 128) ? V16QImode : V8QImode;
1231   rtx (*gen_ext) (rtx, rtx, rtx, rtx) =
1232     (width == 128) ? gen_neon_vextv16qi : gen_neon_vextv8qi;
1233
1234   if (num_bits == width)
1235     {
1236       emit_move_insn (operands[0], operands[1]);
1237       DONE;
1238     }
1239
1240   zero_reg = force_reg (bvecmode, CONST0_RTX (bvecmode));
1241   operands[0] = gen_lowpart (bvecmode, operands[0]);
1242   operands[1] = gen_lowpart (bvecmode, operands[1]);
1243
1244   emit_insn (gen_ext (operands[0], operands[1], zero_reg,
1245                       GEN_INT (num_bits / BITS_PER_UNIT)));
1246   DONE;
1247 })
1248
1249 (define_expand "vec_shl_<mode>"
1250   [(match_operand:VDQ 0 "s_register_operand" "")
1251    (match_operand:VDQ 1 "s_register_operand" "")
1252    (match_operand:SI 2 "const_multiple_of_8_operand" "")]
1253   "TARGET_NEON"
1254 {
1255   rtx zero_reg;
1256   HOST_WIDE_INT num_bits = INTVAL (operands[2]);
1257   const int width = GET_MODE_BITSIZE (<MODE>mode);
1258   const enum machine_mode bvecmode = (width == 128) ? V16QImode : V8QImode;
1259   rtx (*gen_ext) (rtx, rtx, rtx, rtx) =
1260     (width == 128) ? gen_neon_vextv16qi : gen_neon_vextv8qi;
1261
1262   if (num_bits == 0)
1263     {
1264       emit_move_insn (operands[0], CONST0_RTX (<MODE>mode));
1265       DONE;
1266     }
1267
1268   num_bits = width - num_bits;
1269
1270   zero_reg = force_reg (bvecmode, CONST0_RTX (bvecmode));
1271   operands[0] = gen_lowpart (bvecmode, operands[0]);
1272   operands[1] = gen_lowpart (bvecmode, operands[1]);
1273
1274   emit_insn (gen_ext (operands[0], zero_reg, operands[1],
1275                       GEN_INT (num_bits / BITS_PER_UNIT)));
1276   DONE;
1277 })
1278
1279 ;; Helpers for quad-word reduction operations
1280
1281 ; Add (or smin, smax...) the low N/2 elements of the N-element vector
1282 ; operand[1] to the high N/2 elements of same. Put the result in operand[0], an
1283 ; N/2-element vector.
1284
1285 (define_insn "quad_halves_<code>v4si"
1286   [(set (match_operand:V2SI 0 "s_register_operand" "=w")
1287         (vqh_ops:V2SI
1288           (vec_select:V2SI (match_operand:V4SI 1 "s_register_operand" "w")
1289                            (parallel [(const_int 0) (const_int 1)]))
1290           (vec_select:V2SI (match_dup 1)
1291                            (parallel [(const_int 2) (const_int 3)]))))]
1292   "TARGET_NEON"
1293   "<VQH_mnem>.<VQH_sign>32\t%P0, %e1, %f1"
1294   [(set_attr "vqh_mnem" "<VQH_mnem>")
1295    (set (attr "neon_type")
1296       (if_then_else (eq_attr "vqh_mnem" "vadd")
1297                     (const_string "neon_int_1") (const_string "neon_int_5")))]
1298 )
1299
1300 (define_insn "quad_halves_<code>v4sf"
1301   [(set (match_operand:V2SF 0 "s_register_operand" "=w")
1302         (vqhs_ops:V2SF
1303           (vec_select:V2SF (match_operand:V4SF 1 "s_register_operand" "w")
1304                            (parallel [(const_int 0) (const_int 1)]))
1305           (vec_select:V2SF (match_dup 1)
1306                            (parallel [(const_int 2) (const_int 3)]))))]
1307   "TARGET_NEON"
1308   "<VQH_mnem>.f32\t%P0, %e1, %f1"
1309   [(set_attr "vqh_mnem" "<VQH_mnem>")
1310    (set (attr "neon_type")
1311       (if_then_else (eq_attr "vqh_mnem" "vadd")
1312                     (const_string "neon_int_1") (const_string "neon_int_5")))]
1313 )
1314
1315 (define_insn "quad_halves_<code>v8hi"
1316   [(set (match_operand:V4HI 0 "s_register_operand" "+w")
1317         (vqh_ops:V4HI
1318           (vec_select:V4HI (match_operand:V8HI 1 "s_register_operand" "w")
1319                            (parallel [(const_int 0) (const_int 1)
1320                                       (const_int 2) (const_int 3)]))
1321           (vec_select:V4HI (match_dup 1)
1322                            (parallel [(const_int 4) (const_int 5)
1323                                       (const_int 6) (const_int 7)]))))]
1324   "TARGET_NEON"
1325   "<VQH_mnem>.<VQH_sign>16\t%P0, %e1, %f1"
1326   [(set_attr "vqh_mnem" "<VQH_mnem>")
1327    (set (attr "neon_type")
1328       (if_then_else (eq_attr "vqh_mnem" "vadd")
1329                     (const_string "neon_int_1") (const_string "neon_int_5")))]
1330 )
1331
1332 (define_insn "quad_halves_<code>v16qi"
1333   [(set (match_operand:V8QI 0 "s_register_operand" "+w")
1334         (vqh_ops:V8QI
1335           (vec_select:V8QI (match_operand:V16QI 1 "s_register_operand" "w")
1336                            (parallel [(const_int 0) (const_int 1)
1337                                       (const_int 2) (const_int 3)
1338                                       (const_int 4) (const_int 5)
1339                                       (const_int 6) (const_int 7)]))
1340           (vec_select:V8QI (match_dup 1)
1341                            (parallel [(const_int 8) (const_int 9)
1342                                       (const_int 10) (const_int 11)
1343                                       (const_int 12) (const_int 13)
1344                                       (const_int 14) (const_int 15)]))))]
1345   "TARGET_NEON"
1346   "<VQH_mnem>.<VQH_sign>8\t%P0, %e1, %f1"
1347   [(set_attr "vqh_mnem" "<VQH_mnem>")
1348    (set (attr "neon_type")
1349       (if_then_else (eq_attr "vqh_mnem" "vadd")
1350                     (const_string "neon_int_1") (const_string "neon_int_5")))]
1351 )
1352
1353 ; FIXME: We wouldn't need the following insns if we could write subregs of
1354 ; vector registers. Make an attempt at removing unnecessary moves, though
1355 ; we're really at the mercy of the register allocator.
1356
1357 (define_insn "move_lo_quad_v4si"
1358   [(set (match_operand:V4SI 0 "s_register_operand" "+w")
1359         (vec_concat:V4SI
1360           (match_operand:V2SI 1 "s_register_operand" "w")
1361           (vec_select:V2SI (match_dup 0)
1362                            (parallel [(const_int 2) (const_int 3)]))))]
1363   "TARGET_NEON"
1364 {
1365   int dest = REGNO (operands[0]);
1366   int src = REGNO (operands[1]);
1367
1368   if (dest != src)
1369     return "vmov\t%e0, %P1";
1370   else
1371     return "";
1372 }
1373   [(set_attr "neon_type" "neon_bp_simple")]
1374 )
1375
1376 (define_insn "move_lo_quad_v4sf"
1377   [(set (match_operand:V4SF 0 "s_register_operand" "+w")
1378         (vec_concat:V4SF
1379           (match_operand:V2SF 1 "s_register_operand" "w")
1380           (vec_select:V2SF (match_dup 0)
1381                            (parallel [(const_int 2) (const_int 3)]))))]
1382   "TARGET_NEON"
1383 {
1384   int dest = REGNO (operands[0]);
1385   int src = REGNO (operands[1]);
1386
1387   if (dest != src)
1388     return "vmov\t%e0, %P1";
1389   else
1390     return "";
1391 }
1392   [(set_attr "neon_type" "neon_bp_simple")]
1393 )
1394
1395 (define_insn "move_lo_quad_v8hi"
1396   [(set (match_operand:V8HI 0 "s_register_operand" "+w")
1397         (vec_concat:V8HI
1398           (match_operand:V4HI 1 "s_register_operand" "w")
1399           (vec_select:V4HI (match_dup 0)
1400                            (parallel [(const_int 4) (const_int 5)
1401                                       (const_int 6) (const_int 7)]))))]
1402   "TARGET_NEON"
1403 {
1404   int dest = REGNO (operands[0]);
1405   int src = REGNO (operands[1]);
1406
1407   if (dest != src)
1408     return "vmov\t%e0, %P1";
1409   else
1410     return "";
1411 }
1412   [(set_attr "neon_type" "neon_bp_simple")]
1413 )
1414
1415 (define_insn "move_lo_quad_v16qi"
1416   [(set (match_operand:V16QI 0 "s_register_operand" "+w")
1417         (vec_concat:V16QI
1418           (match_operand:V8QI 1 "s_register_operand" "w")
1419           (vec_select:V8QI (match_dup 0)
1420                            (parallel [(const_int 8)  (const_int 9)
1421                                       (const_int 10) (const_int 11)
1422                                       (const_int 12) (const_int 13)
1423                                       (const_int 14) (const_int 15)]))))]
1424   "TARGET_NEON"
1425 {
1426   int dest = REGNO (operands[0]);
1427   int src = REGNO (operands[1]);
1428
1429   if (dest != src)
1430     return "vmov\t%e0, %P1";
1431   else
1432     return "";
1433 }
1434   [(set_attr "neon_type" "neon_bp_simple")]
1435 )
1436
1437 ;; Reduction operations
1438
1439 (define_expand "reduc_splus_<mode>"
1440   [(match_operand:VD 0 "s_register_operand" "")
1441    (match_operand:VD 1 "s_register_operand" "")]
1442   "TARGET_NEON"
1443 {
1444   neon_pairwise_reduce (operands[0], operands[1], <MODE>mode,
1445                         &gen_neon_vpadd_internal<mode>);
1446   DONE;
1447 })
1448
1449 (define_expand "reduc_splus_<mode>"
1450   [(match_operand:VQ 0 "s_register_operand" "")
1451    (match_operand:VQ 1 "s_register_operand" "")]
1452   "TARGET_NEON"
1453 {
1454   rtx step1 = gen_reg_rtx (<V_HALF>mode);
1455   rtx res_d = gen_reg_rtx (<V_HALF>mode);
1456
1457   emit_insn (gen_quad_halves_plus<mode> (step1, operands[1]));
1458   emit_insn (gen_reduc_splus_<V_half> (res_d, step1));
1459   emit_insn (gen_move_lo_quad_<mode> (operands[0], res_d));
1460
1461   DONE;
1462 })
1463
1464 (define_insn "reduc_splus_v2di"
1465   [(set (match_operand:V2DI 0 "s_register_operand" "=w")
1466         (unspec:V2DI [(match_operand:V2DI 1 "s_register_operand" "w")]
1467                      UNSPEC_VPADD))]
1468   "TARGET_NEON"
1469   "vadd.i64\t%e0, %e1, %f1"
1470   [(set_attr "neon_type" "neon_int_1")]
1471 )
1472
1473 ;; NEON does not distinguish between signed and unsigned addition except on
1474 ;; widening operations.
1475 (define_expand "reduc_uplus_<mode>"
1476   [(match_operand:VDQI 0 "s_register_operand" "")
1477    (match_operand:VDQI 1 "s_register_operand" "")]
1478   "TARGET_NEON"
1479 {
1480   emit_insn (gen_reduc_splus_<mode> (operands[0], operands[1]));
1481   DONE;
1482 })
1483
1484 (define_expand "reduc_smin_<mode>"
1485   [(match_operand:VD 0 "s_register_operand" "")
1486    (match_operand:VD 1 "s_register_operand" "")]
1487   "TARGET_NEON"
1488 {
1489   neon_pairwise_reduce (operands[0], operands[1], <MODE>mode,
1490                         &gen_neon_vpsmin<mode>);
1491   DONE;
1492 })
1493
1494 (define_expand "reduc_smin_<mode>"
1495   [(match_operand:VQ 0 "s_register_operand" "")
1496    (match_operand:VQ 1 "s_register_operand" "")]
1497   "TARGET_NEON"
1498 {
1499   rtx step1 = gen_reg_rtx (<V_HALF>mode);
1500   rtx res_d = gen_reg_rtx (<V_HALF>mode);
1501
1502   emit_insn (gen_quad_halves_smin<mode> (step1, operands[1]));
1503   emit_insn (gen_reduc_smin_<V_half> (res_d, step1));
1504   emit_insn (gen_move_lo_quad_<mode> (operands[0], res_d));
1505
1506   DONE;
1507 })
1508
1509 (define_expand "reduc_smax_<mode>"
1510   [(match_operand:VD 0 "s_register_operand" "")
1511    (match_operand:VD 1 "s_register_operand" "")]
1512   "TARGET_NEON"
1513 {
1514   neon_pairwise_reduce (operands[0], operands[1], <MODE>mode,
1515                         &gen_neon_vpsmax<mode>);
1516   DONE;
1517 })
1518
1519 (define_expand "reduc_smax_<mode>"
1520   [(match_operand:VQ 0 "s_register_operand" "")
1521    (match_operand:VQ 1 "s_register_operand" "")]
1522   "TARGET_NEON"
1523 {
1524   rtx step1 = gen_reg_rtx (<V_HALF>mode);
1525   rtx res_d = gen_reg_rtx (<V_HALF>mode);
1526
1527   emit_insn (gen_quad_halves_smax<mode> (step1, operands[1]));
1528   emit_insn (gen_reduc_smax_<V_half> (res_d, step1));
1529   emit_insn (gen_move_lo_quad_<mode> (operands[0], res_d));
1530
1531   DONE;
1532 })
1533
1534 (define_expand "reduc_umin_<mode>"
1535   [(match_operand:VDI 0 "s_register_operand" "")
1536    (match_operand:VDI 1 "s_register_operand" "")]
1537   "TARGET_NEON"
1538 {
1539   neon_pairwise_reduce (operands[0], operands[1], <MODE>mode,
1540                         &gen_neon_vpumin<mode>);
1541   DONE;
1542 })
1543
1544 (define_expand "reduc_umin_<mode>"
1545   [(match_operand:VQI 0 "s_register_operand" "")
1546    (match_operand:VQI 1 "s_register_operand" "")]
1547   "TARGET_NEON"
1548 {
1549   rtx step1 = gen_reg_rtx (<V_HALF>mode);
1550   rtx res_d = gen_reg_rtx (<V_HALF>mode);
1551
1552   emit_insn (gen_quad_halves_umin<mode> (step1, operands[1]));
1553   emit_insn (gen_reduc_umin_<V_half> (res_d, step1));
1554   emit_insn (gen_move_lo_quad_<mode> (operands[0], res_d));
1555
1556   DONE;
1557 })
1558
1559 (define_expand "reduc_umax_<mode>"
1560   [(match_operand:VDI 0 "s_register_operand" "")
1561    (match_operand:VDI 1 "s_register_operand" "")]
1562   "TARGET_NEON"
1563 {
1564   neon_pairwise_reduce (operands[0], operands[1], <MODE>mode,
1565                         &gen_neon_vpumax<mode>);
1566   DONE;
1567 })
1568
1569 (define_expand "reduc_umax_<mode>"
1570   [(match_operand:VQI 0 "s_register_operand" "")
1571    (match_operand:VQI 1 "s_register_operand" "")]
1572   "TARGET_NEON"
1573 {
1574   rtx step1 = gen_reg_rtx (<V_HALF>mode);
1575   rtx res_d = gen_reg_rtx (<V_HALF>mode);
1576
1577   emit_insn (gen_quad_halves_umax<mode> (step1, operands[1]));
1578   emit_insn (gen_reduc_umax_<V_half> (res_d, step1));
1579   emit_insn (gen_move_lo_quad_<mode> (operands[0], res_d));
1580
1581   DONE;
1582 })
1583
1584 (define_insn "neon_vpadd_internal<mode>"
1585   [(set (match_operand:VD 0 "s_register_operand" "=w")
1586         (unspec:VD [(match_operand:VD 1 "s_register_operand" "w")
1587                     (match_operand:VD 2 "s_register_operand" "w")]
1588                    UNSPEC_VPADD))]
1589   "TARGET_NEON"
1590   "vpadd.<V_if_elem>\t%P0, %P1, %P2"
1591   ;; Assume this schedules like vadd.
1592   [(set (attr "neon_type")
1593       (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
1594                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
1595                                   (const_string "neon_fp_vadd_ddd_vabs_dd")
1596                                   (const_string "neon_fp_vadd_qqq_vabs_qq"))
1597                     (const_string "neon_int_1")))]
1598 )
1599
1600 (define_insn "neon_vpsmin<mode>"
1601   [(set (match_operand:VD 0 "s_register_operand" "=w")
1602         (unspec:VD [(match_operand:VD 1 "s_register_operand" "w")
1603                     (match_operand:VD 2 "s_register_operand" "w")]
1604                    UNSPEC_VPSMIN))]
1605   "TARGET_NEON"
1606   "vpmin.<V_s_elem>\t%P0, %P1, %P2"
1607   ;; Assume this schedules like vmin.
1608   [(set (attr "neon_type")
1609       (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
1610                     (const_string "neon_fp_vadd_ddd_vabs_dd")
1611                     (const_string "neon_int_5")))]
1612 )
1613
1614 (define_insn "neon_vpsmax<mode>"
1615   [(set (match_operand:VD 0 "s_register_operand" "=w")
1616         (unspec:VD [(match_operand:VD 1 "s_register_operand" "w")
1617                     (match_operand:VD 2 "s_register_operand" "w")]
1618                    UNSPEC_VPSMAX))]
1619   "TARGET_NEON"
1620   "vpmax.<V_s_elem>\t%P0, %P1, %P2"
1621   ;; Assume this schedules like vmax.
1622   [(set (attr "neon_type")
1623       (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
1624                     (const_string "neon_fp_vadd_ddd_vabs_dd")
1625                     (const_string "neon_int_5")))]
1626 )
1627
1628 (define_insn "neon_vpumin<mode>"
1629   [(set (match_operand:VDI 0 "s_register_operand" "=w")
1630         (unspec:VDI [(match_operand:VDI 1 "s_register_operand" "w")
1631                      (match_operand:VDI 2 "s_register_operand" "w")]
1632                    UNSPEC_VPUMIN))]
1633   "TARGET_NEON"
1634   "vpmin.<V_u_elem>\t%P0, %P1, %P2"
1635   ;; Assume this schedules like umin.
1636   [(set_attr "neon_type" "neon_int_5")]
1637 )
1638
1639 (define_insn "neon_vpumax<mode>"
1640   [(set (match_operand:VDI 0 "s_register_operand" "=w")
1641         (unspec:VDI [(match_operand:VDI 1 "s_register_operand" "w")
1642                      (match_operand:VDI 2 "s_register_operand" "w")]
1643                    UNSPEC_VPUMAX))]
1644   "TARGET_NEON"
1645   "vpmax.<V_u_elem>\t%P0, %P1, %P2"
1646   ;; Assume this schedules like umax.
1647   [(set_attr "neon_type" "neon_int_5")]
1648 )
1649
1650 ;; Saturating arithmetic
1651
1652 ; NOTE: Neon supports many more saturating variants of instructions than the
1653 ; following, but these are all GCC currently understands.
1654 ; FIXME: Actually, GCC doesn't know how to create saturating add/sub by itself
1655 ; yet either, although these patterns may be used by intrinsics when they're
1656 ; added.
1657
1658 (define_insn "*ss_add<mode>_neon"
1659   [(set (match_operand:VD 0 "s_register_operand" "=w")
1660        (ss_plus:VD (match_operand:VD 1 "s_register_operand" "w")
1661                    (match_operand:VD 2 "s_register_operand" "w")))]
1662   "TARGET_NEON"
1663   "vqadd.<V_s_elem>\t%P0, %P1, %P2"
1664   [(set_attr "neon_type" "neon_int_4")]
1665 )
1666
1667 (define_insn "*us_add<mode>_neon"
1668   [(set (match_operand:VD 0 "s_register_operand" "=w")
1669        (us_plus:VD (match_operand:VD 1 "s_register_operand" "w")
1670                    (match_operand:VD 2 "s_register_operand" "w")))]
1671   "TARGET_NEON"
1672   "vqadd.<V_u_elem>\t%P0, %P1, %P2"
1673   [(set_attr "neon_type" "neon_int_4")]
1674 )
1675
1676 (define_insn "*ss_sub<mode>_neon"
1677   [(set (match_operand:VD 0 "s_register_operand" "=w")
1678        (ss_minus:VD (match_operand:VD 1 "s_register_operand" "w")
1679                     (match_operand:VD 2 "s_register_operand" "w")))]
1680   "TARGET_NEON"
1681   "vqsub.<V_s_elem>\t%P0, %P1, %P2"
1682   [(set_attr "neon_type" "neon_int_5")]
1683 )
1684
1685 (define_insn "*us_sub<mode>_neon"
1686   [(set (match_operand:VD 0 "s_register_operand" "=w")
1687        (us_minus:VD (match_operand:VD 1 "s_register_operand" "w")
1688                     (match_operand:VD 2 "s_register_operand" "w")))]
1689   "TARGET_NEON"
1690   "vqsub.<V_u_elem>\t%P0, %P1, %P2"
1691   [(set_attr "neon_type" "neon_int_5")]
1692 )
1693
1694 ;; Patterns for builtins.
1695
1696 ; good for plain vadd, vaddq.
1697
1698 (define_insn "neon_vadd<mode>"
1699   [(set (match_operand:VDQX 0 "s_register_operand" "=w")
1700         (unspec:VDQX [(match_operand:VDQX 1 "s_register_operand" "w")
1701                       (match_operand:VDQX 2 "s_register_operand" "w")
1702                       (match_operand:SI 3 "immediate_operand" "i")]
1703                      UNSPEC_VADD))]
1704   "TARGET_NEON"
1705   "vadd.<V_if_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
1706   [(set (attr "neon_type")
1707       (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
1708                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
1709                                   (const_string "neon_fp_vadd_ddd_vabs_dd")
1710                                   (const_string "neon_fp_vadd_qqq_vabs_qq"))
1711                     (const_string "neon_int_1")))]
1712 )
1713
1714 ; operand 3 represents in bits:
1715 ;  bit 0: signed (vs unsigned).
1716 ;  bit 1: rounding (vs none).
1717
1718 (define_insn "neon_vaddl<mode>"
1719   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
1720         (unspec:<V_widen> [(match_operand:VDI 1 "s_register_operand" "w")
1721                            (match_operand:VDI 2 "s_register_operand" "w")
1722                            (match_operand:SI 3 "immediate_operand" "i")]
1723                           UNSPEC_VADDL))]
1724   "TARGET_NEON"
1725   "vaddl.%T3%#<V_sz_elem>\t%q0, %P1, %P2"
1726   [(set_attr "neon_type" "neon_int_3")]
1727 )
1728
1729 (define_insn "neon_vaddw<mode>"
1730   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
1731         (unspec:<V_widen> [(match_operand:<V_widen> 1 "s_register_operand" "w")
1732                            (match_operand:VDI 2 "s_register_operand" "w")
1733                            (match_operand:SI 3 "immediate_operand" "i")]
1734                           UNSPEC_VADDW))]
1735   "TARGET_NEON"
1736   "vaddw.%T3%#<V_sz_elem>\t%q0, %q1, %P2"
1737   [(set_attr "neon_type" "neon_int_2")]
1738 )
1739
1740 ; vhadd and vrhadd.
1741
1742 (define_insn "neon_vhadd<mode>"
1743   [(set (match_operand:VDQIW 0 "s_register_operand" "=w")
1744         (unspec:VDQIW [(match_operand:VDQIW 1 "s_register_operand" "w")
1745                        (match_operand:VDQIW 2 "s_register_operand" "w")
1746                        (match_operand:SI 3 "immediate_operand" "i")]
1747                       UNSPEC_VHADD))]
1748   "TARGET_NEON"
1749   "v%O3hadd.%T3%#<V_sz_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
1750   [(set_attr "neon_type" "neon_int_4")]
1751 )
1752
1753 (define_insn "neon_vqadd<mode>"
1754   [(set (match_operand:VDQIX 0 "s_register_operand" "=w")
1755         (unspec:VDQIX [(match_operand:VDQIX 1 "s_register_operand" "w")
1756                        (match_operand:VDQIX 2 "s_register_operand" "w")
1757                        (match_operand:SI 3 "immediate_operand" "i")]
1758                      UNSPEC_VQADD))]
1759   "TARGET_NEON"
1760   "vqadd.%T3%#<V_sz_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
1761   [(set_attr "neon_type" "neon_int_4")]
1762 )
1763
1764 (define_insn "neon_vaddhn<mode>"
1765   [(set (match_operand:<V_narrow> 0 "s_register_operand" "=w")
1766         (unspec:<V_narrow> [(match_operand:VN 1 "s_register_operand" "w")
1767                             (match_operand:VN 2 "s_register_operand" "w")
1768                             (match_operand:SI 3 "immediate_operand" "i")]
1769                            UNSPEC_VADDHN))]
1770   "TARGET_NEON"
1771   "v%O3addhn.<V_if_elem>\t%P0, %q1, %q2"
1772   [(set_attr "neon_type" "neon_int_4")]
1773 )
1774
1775 (define_insn "neon_vmul<mode>"
1776   [(set (match_operand:VDQW 0 "s_register_operand" "=w")
1777         (unspec:VDQW [(match_operand:VDQW 1 "s_register_operand" "w")
1778                       (match_operand:VDQW 2 "s_register_operand" "w")
1779                       (match_operand:SI 3 "immediate_operand" "i")]
1780                      UNSPEC_VMUL))]
1781   "TARGET_NEON"
1782   "vmul.%F3%#<V_sz_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
1783   [(set (attr "neon_type")
1784       (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
1785                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
1786                                   (const_string "neon_fp_vadd_ddd_vabs_dd")
1787                                   (const_string "neon_fp_vadd_qqq_vabs_qq"))
1788                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
1789                                   (if_then_else
1790                                     (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
1791                                     (const_string "neon_mul_ddd_8_16_qdd_16_8_long_32_16_long")
1792                                     (const_string "neon_mul_qqq_8_16_32_ddd_32"))
1793                                   (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
1794                                     (const_string "neon_mul_qqq_8_16_32_ddd_32")
1795                                     (const_string "neon_mul_qqq_8_16_32_ddd_32")))))]
1796 )
1797
1798 (define_insn "neon_vmla<mode>"
1799   [(set (match_operand:VDQW 0 "s_register_operand" "=w")
1800         (unspec:VDQW [(match_operand:VDQW 1 "s_register_operand" "0")
1801                       (match_operand:VDQW 2 "s_register_operand" "w")
1802                       (match_operand:VDQW 3 "s_register_operand" "w")
1803                      (match_operand:SI 4 "immediate_operand" "i")]
1804                     UNSPEC_VMLA))]
1805   "TARGET_NEON"
1806   "vmla.<V_if_elem>\t%<V_reg>0, %<V_reg>2, %<V_reg>3"
1807   [(set (attr "neon_type")
1808       (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
1809                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
1810                                   (const_string "neon_fp_vmla_ddd")
1811                                   (const_string "neon_fp_vmla_qqq"))
1812                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
1813                                   (if_then_else
1814                                     (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
1815                                     (const_string "neon_mla_ddd_8_16_qdd_16_8_long_32_16_long")
1816                                     (const_string "neon_mla_ddd_32_qqd_16_ddd_32_scalar_qdd_64_32_long_scalar_qdd_64_32_long"))
1817                                   (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
1818                                     (const_string "neon_mla_qqq_8_16")
1819                                     (const_string "neon_mla_qqq_32_qqd_32_scalar")))))]
1820 )
1821
1822 (define_insn "neon_vmlal<mode>"
1823   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
1824         (unspec:<V_widen> [(match_operand:<V_widen> 1 "s_register_operand" "0")
1825                            (match_operand:VW 2 "s_register_operand" "w")
1826                            (match_operand:VW 3 "s_register_operand" "w")
1827                            (match_operand:SI 4 "immediate_operand" "i")]
1828                           UNSPEC_VMLAL))]
1829   "TARGET_NEON"
1830   "vmlal.%T4%#<V_sz_elem>\t%q0, %P2, %P3"
1831   [(set (attr "neon_type")
1832      (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
1833                    (const_string "neon_mla_ddd_8_16_qdd_16_8_long_32_16_long")
1834                    (const_string "neon_mla_ddd_32_qqd_16_ddd_32_scalar_qdd_64_32_long_scalar_qdd_64_32_long")))]
1835 )
1836
1837 (define_insn "neon_vmls<mode>"
1838   [(set (match_operand:VDQW 0 "s_register_operand" "=w")
1839         (unspec:VDQW [(match_operand:VDQW 1 "s_register_operand" "0")
1840                       (match_operand:VDQW 2 "s_register_operand" "w")
1841                       (match_operand:VDQW 3 "s_register_operand" "w")
1842                      (match_operand:SI 4 "immediate_operand" "i")]
1843                     UNSPEC_VMLS))]
1844   "TARGET_NEON"
1845   "vmls.<V_if_elem>\t%<V_reg>0, %<V_reg>2, %<V_reg>3"
1846   [(set (attr "neon_type")
1847       (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
1848                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
1849                                   (const_string "neon_fp_vmla_ddd")
1850                                   (const_string "neon_fp_vmla_qqq"))
1851                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
1852                                   (if_then_else
1853                                     (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
1854                                     (const_string "neon_mla_ddd_8_16_qdd_16_8_long_32_16_long")
1855                                     (const_string "neon_mla_ddd_32_qqd_16_ddd_32_scalar_qdd_64_32_long_scalar_qdd_64_32_long"))
1856                                   (if_then_else
1857                                     (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
1858                                     (const_string "neon_mla_qqq_8_16")
1859                                     (const_string "neon_mla_qqq_32_qqd_32_scalar")))))]
1860 )
1861
1862 (define_insn "neon_vmlsl<mode>"
1863   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
1864         (unspec:<V_widen> [(match_operand:<V_widen> 1 "s_register_operand" "0")
1865                            (match_operand:VW 2 "s_register_operand" "w")
1866                            (match_operand:VW 3 "s_register_operand" "w")
1867                            (match_operand:SI 4 "immediate_operand" "i")]
1868                           UNSPEC_VMLSL))]
1869   "TARGET_NEON"
1870   "vmlsl.%T4%#<V_sz_elem>\t%q0, %P2, %P3"
1871   [(set (attr "neon_type")
1872      (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
1873                    (const_string "neon_mla_ddd_8_16_qdd_16_8_long_32_16_long")
1874                    (const_string "neon_mla_ddd_32_qqd_16_ddd_32_scalar_qdd_64_32_long_scalar_qdd_64_32_long")))]
1875 )
1876
1877 (define_insn "neon_vqdmulh<mode>"
1878   [(set (match_operand:VMDQI 0 "s_register_operand" "=w")
1879         (unspec:VMDQI [(match_operand:VMDQI 1 "s_register_operand" "w")
1880                        (match_operand:VMDQI 2 "s_register_operand" "w")
1881                        (match_operand:SI 3 "immediate_operand" "i")]
1882                       UNSPEC_VQDMULH))]
1883   "TARGET_NEON"
1884   "vq%O3dmulh.<V_s_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
1885   [(set (attr "neon_type")
1886      (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
1887         (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
1888                       (const_string "neon_mul_ddd_8_16_qdd_16_8_long_32_16_long")
1889                       (const_string "neon_mul_qqq_8_16_32_ddd_32"))
1890         (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
1891                       (const_string "neon_mul_qqq_8_16_32_ddd_32")
1892                       (const_string "neon_mul_qqq_8_16_32_ddd_32"))))]
1893 )
1894
1895 (define_insn "neon_vqdmlal<mode>"
1896   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
1897         (unspec:<V_widen> [(match_operand:<V_widen> 1 "s_register_operand" "0")
1898                            (match_operand:VMDI 2 "s_register_operand" "w")
1899                            (match_operand:VMDI 3 "s_register_operand" "w")
1900                            (match_operand:SI 4 "immediate_operand" "i")]
1901                           UNSPEC_VQDMLAL))]
1902   "TARGET_NEON"
1903   "vqdmlal.<V_s_elem>\t%q0, %P2, %P3"
1904   [(set (attr "neon_type")
1905      (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
1906                    (const_string "neon_mla_ddd_8_16_qdd_16_8_long_32_16_long")
1907                    (const_string "neon_mla_ddd_32_qqd_16_ddd_32_scalar_qdd_64_32_long_scalar_qdd_64_32_long")))]
1908 )
1909
1910 (define_insn "neon_vqdmlsl<mode>"
1911   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
1912         (unspec:<V_widen> [(match_operand:<V_widen> 1 "s_register_operand" "0")
1913                            (match_operand:VMDI 2 "s_register_operand" "w")
1914                            (match_operand:VMDI 3 "s_register_operand" "w")
1915                            (match_operand:SI 4 "immediate_operand" "i")]
1916                           UNSPEC_VQDMLSL))]
1917   "TARGET_NEON"
1918   "vqdmlsl.<V_s_elem>\t%q0, %P2, %P3"
1919   [(set (attr "neon_type")
1920      (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
1921                    (const_string "neon_mla_ddd_8_16_qdd_16_8_long_32_16_long")
1922                    (const_string "neon_mla_ddd_32_qqd_16_ddd_32_scalar_qdd_64_32_long_scalar_qdd_64_32_long")))]
1923 )
1924
1925 (define_insn "neon_vmull<mode>"
1926   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
1927         (unspec:<V_widen> [(match_operand:VW 1 "s_register_operand" "w")
1928                            (match_operand:VW 2 "s_register_operand" "w")
1929                            (match_operand:SI 3 "immediate_operand" "i")]
1930                           UNSPEC_VMULL))]
1931   "TARGET_NEON"
1932   "vmull.%T3%#<V_sz_elem>\t%q0, %P1, %P2"
1933   [(set (attr "neon_type")
1934      (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
1935                    (const_string "neon_mul_ddd_8_16_qdd_16_8_long_32_16_long")
1936                    (const_string "neon_mul_qdd_64_32_long_qqd_16_ddd_32_scalar_64_32_long_scalar")))]
1937 )
1938
1939 (define_insn "neon_vqdmull<mode>"
1940   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
1941         (unspec:<V_widen> [(match_operand:VMDI 1 "s_register_operand" "w")
1942                            (match_operand:VMDI 2 "s_register_operand" "w")
1943                            (match_operand:SI 3 "immediate_operand" "i")]
1944                           UNSPEC_VQDMULL))]
1945   "TARGET_NEON"
1946   "vqdmull.<V_s_elem>\t%q0, %P1, %P2"
1947   [(set (attr "neon_type")
1948      (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
1949                    (const_string "neon_mul_ddd_8_16_qdd_16_8_long_32_16_long")
1950                    (const_string "neon_mul_qdd_64_32_long_qqd_16_ddd_32_scalar_64_32_long_scalar")))]
1951 )
1952
1953 (define_insn "neon_vsub<mode>"
1954   [(set (match_operand:VDQX 0 "s_register_operand" "=w")
1955         (unspec:VDQX [(match_operand:VDQX 1 "s_register_operand" "w")
1956                       (match_operand:VDQX 2 "s_register_operand" "w")
1957                       (match_operand:SI 3 "immediate_operand" "i")]
1958                      UNSPEC_VSUB))]
1959   "TARGET_NEON"
1960   "vsub.<V_if_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
1961   [(set (attr "neon_type")
1962       (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
1963                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
1964                                   (const_string "neon_fp_vadd_ddd_vabs_dd")
1965                                   (const_string "neon_fp_vadd_qqq_vabs_qq"))
1966                     (const_string "neon_int_2")))]
1967 )
1968
1969 (define_insn "neon_vsubl<mode>"
1970   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
1971         (unspec:<V_widen> [(match_operand:VDI 1 "s_register_operand" "w")
1972                            (match_operand:VDI 2 "s_register_operand" "w")
1973                            (match_operand:SI 3 "immediate_operand" "i")]
1974                           UNSPEC_VSUBL))]
1975   "TARGET_NEON"
1976   "vsubl.%T3%#<V_sz_elem>\t%q0, %P1, %P2"
1977   [(set_attr "neon_type" "neon_int_2")]
1978 )
1979
1980 (define_insn "neon_vsubw<mode>"
1981   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
1982         (unspec:<V_widen> [(match_operand:<V_widen> 1 "s_register_operand" "w")
1983                            (match_operand:VDI 2 "s_register_operand" "w")
1984                            (match_operand:SI 3 "immediate_operand" "i")]
1985                           UNSPEC_VSUBW))]
1986   "TARGET_NEON"
1987   "vsubw.%T3%#<V_sz_elem>\t%q0, %q1, %P2"
1988   [(set_attr "neon_type" "neon_int_2")]
1989 )
1990
1991 (define_insn "neon_vqsub<mode>"
1992   [(set (match_operand:VDQIX 0 "s_register_operand" "=w")
1993         (unspec:VDQIX [(match_operand:VDQIX 1 "s_register_operand" "w")
1994                        (match_operand:VDQIX 2 "s_register_operand" "w")
1995                        (match_operand:SI 3 "immediate_operand" "i")]
1996                       UNSPEC_VQSUB))]
1997   "TARGET_NEON"
1998   "vqsub.%T3%#<V_sz_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
1999   [(set_attr "neon_type" "neon_int_5")]
2000 )
2001
2002 (define_insn "neon_vhsub<mode>"
2003   [(set (match_operand:VDQIW 0 "s_register_operand" "=w")
2004         (unspec:VDQIW [(match_operand:VDQIW 1 "s_register_operand" "w")
2005                        (match_operand:VDQIW 2 "s_register_operand" "w")
2006                        (match_operand:SI 3 "immediate_operand" "i")]
2007                       UNSPEC_VHSUB))]
2008   "TARGET_NEON"
2009   "vhsub.%T3%#<V_sz_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
2010   [(set_attr "neon_type" "neon_int_5")]
2011 )
2012
2013 (define_insn "neon_vsubhn<mode>"
2014   [(set (match_operand:<V_narrow> 0 "s_register_operand" "=w")
2015         (unspec:<V_narrow> [(match_operand:VN 1 "s_register_operand" "w")
2016                             (match_operand:VN 2 "s_register_operand" "w")
2017                             (match_operand:SI 3 "immediate_operand" "i")]
2018                            UNSPEC_VSUBHN))]
2019   "TARGET_NEON"
2020   "v%O3subhn.<V_if_elem>\t%P0, %q1, %q2"
2021   [(set_attr "neon_type" "neon_int_4")]
2022 )
2023
2024 (define_insn "neon_vceq<mode>"
2025   [(set (match_operand:<V_cmp_result> 0 "s_register_operand" "=w")
2026         (unspec:<V_cmp_result> [(match_operand:VDQW 1 "s_register_operand" "w")
2027                                 (match_operand:VDQW 2 "s_register_operand" "w")
2028                                 (match_operand:SI 3 "immediate_operand" "i")]
2029                                UNSPEC_VCEQ))]
2030   "TARGET_NEON"
2031   "vceq.<V_if_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
2032   [(set (attr "neon_type")
2033       (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
2034                     (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
2035                                   (const_string "neon_fp_vadd_ddd_vabs_dd")
2036                                   (const_string "neon_fp_vadd_qqq_vabs_qq"))
2037                     (const_string "neon_int_5")))]
2038 )
2039
2040 (define_insn "neon_vcge<mode>"
2041   [(set (match_operand:<V_cmp_result> 0 "s_register_operand" "=w")
2042         (unspec:<V_cmp_result> [(match_operand:VDQW 1 "s_register_operand" "w")
2043                                 (match_operand:VDQW 2 "s_register_operand" "w")
2044                                 (match_operand:SI 3 "immediate_operand" "i")]
2045                                UNSPEC_VCGE))]
2046   "TARGET_NEON"
2047   "vcge.%T3%#<V_sz_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
2048   [(set (attr "neon_type")
2049      (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
2050                    (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
2051                                  (const_string "neon_fp_vadd_ddd_vabs_dd")
2052                                  (const_string "neon_fp_vadd_qqq_vabs_qq"))
2053                    (const_string "neon_int_5")))]
2054 )
2055
2056 (define_insn "neon_vcgt<mode>"
2057   [(set (match_operand:<V_cmp_result> 0 "s_register_operand" "=w")
2058         (unspec:<V_cmp_result> [(match_operand:VDQW 1 "s_register_operand" "w")
2059                                 (match_operand:VDQW 2 "s_register_operand" "w")
2060                                 (match_operand:SI 3 "immediate_operand" "i")]
2061                                UNSPEC_VCGT))]
2062   "TARGET_NEON"
2063   "vcgt.%T3%#<V_sz_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
2064   [(set (attr "neon_type")
2065      (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
2066                    (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
2067                                  (const_string "neon_fp_vadd_ddd_vabs_dd")
2068                                  (const_string "neon_fp_vadd_qqq_vabs_qq"))
2069                    (const_string "neon_int_5")))]
2070 )
2071
2072 (define_insn "neon_vcage<mode>"
2073   [(set (match_operand:<V_cmp_result> 0 "s_register_operand" "=w")
2074         (unspec:<V_cmp_result> [(match_operand:VCVTF 1 "s_register_operand" "w")
2075                                 (match_operand:VCVTF 2 "s_register_operand" "w")
2076                                 (match_operand:SI 3 "immediate_operand" "i")]
2077                                UNSPEC_VCAGE))]
2078   "TARGET_NEON"
2079   "vacge.<V_if_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
2080   [(set (attr "neon_type")
2081      (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
2082                    (const_string "neon_fp_vadd_ddd_vabs_dd")
2083                    (const_string "neon_fp_vadd_qqq_vabs_qq")))]
2084 )
2085
2086 (define_insn "neon_vcagt<mode>"
2087   [(set (match_operand:<V_cmp_result> 0 "s_register_operand" "=w")
2088         (unspec:<V_cmp_result> [(match_operand:VCVTF 1 "s_register_operand" "w")
2089                                 (match_operand:VCVTF 2 "s_register_operand" "w")
2090                                 (match_operand:SI 3 "immediate_operand" "i")]
2091                                UNSPEC_VCAGT))]
2092   "TARGET_NEON"
2093   "vacgt.<V_if_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
2094   [(set (attr "neon_type")
2095      (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
2096                    (const_string "neon_fp_vadd_ddd_vabs_dd")
2097                    (const_string "neon_fp_vadd_qqq_vabs_qq")))]
2098 )
2099
2100 (define_insn "neon_vtst<mode>"
2101   [(set (match_operand:VDQIW 0 "s_register_operand" "=w")
2102         (unspec:VDQIW [(match_operand:VDQIW 1 "s_register_operand" "w")
2103                        (match_operand:VDQIW 2 "s_register_operand" "w")
2104                        (match_operand:SI 3 "immediate_operand" "i")]
2105                       UNSPEC_VTST))]
2106   "TARGET_NEON"
2107   "vtst.<V_sz_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
2108   [(set_attr "neon_type" "neon_int_4")]
2109 )
2110
2111 (define_insn "neon_vabd<mode>"
2112   [(set (match_operand:VDQW 0 "s_register_operand" "=w")
2113         (unspec:VDQW [(match_operand:VDQW 1 "s_register_operand" "w")
2114                       (match_operand:VDQW 2 "s_register_operand" "w")
2115                       (match_operand:SI 3 "immediate_operand" "i")]
2116                      UNSPEC_VABD))]
2117   "TARGET_NEON"
2118   "vabd.%T3%#<V_sz_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
2119   [(set (attr "neon_type")
2120      (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
2121                    (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
2122                                  (const_string "neon_fp_vadd_ddd_vabs_dd")
2123                                  (const_string "neon_fp_vadd_qqq_vabs_qq"))
2124                    (const_string "neon_int_5")))]
2125 )
2126
2127 (define_insn "neon_vabdl<mode>"
2128   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
2129         (unspec:<V_widen> [(match_operand:VW 1 "s_register_operand" "w")
2130                            (match_operand:VW 2 "s_register_operand" "w")
2131                            (match_operand:SI 3 "immediate_operand" "i")]
2132                           UNSPEC_VABDL))]
2133   "TARGET_NEON"
2134   "vabdl.%T3%#<V_sz_elem>\t%q0, %P1, %P2"
2135   [(set_attr "neon_type" "neon_int_5")]
2136 )
2137
2138 (define_insn "neon_vaba<mode>"
2139   [(set (match_operand:VDQIW 0 "s_register_operand" "=w")
2140         (unspec:VDQIW [(match_operand:VDQIW 1 "s_register_operand" "0")
2141                        (match_operand:VDQIW 2 "s_register_operand" "w")
2142                        (match_operand:VDQIW 3 "s_register_operand" "w")
2143                        (match_operand:SI 4 "immediate_operand" "i")]
2144                       UNSPEC_VABA))]
2145   "TARGET_NEON"
2146   "vaba.%T4%#<V_sz_elem>\t%<V_reg>0, %<V_reg>2, %<V_reg>3"
2147   [(set (attr "neon_type")
2148      (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
2149                    (const_string "neon_vaba") (const_string "neon_vaba_qqq")))]
2150 )
2151
2152 (define_insn "neon_vabal<mode>"
2153   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
2154         (unspec:<V_widen> [(match_operand:<V_widen> 1 "s_register_operand" "0")
2155                            (match_operand:VW 2 "s_register_operand" "w")
2156                            (match_operand:VW 3 "s_register_operand" "w")
2157                            (match_operand:SI 4 "immediate_operand" "i")]
2158                           UNSPEC_VABAL))]
2159   "TARGET_NEON"
2160   "vabal.%T4%#<V_sz_elem>\t%q0, %P2, %P3"
2161   [(set_attr "neon_type" "neon_vaba")]
2162 )
2163
2164 (define_insn "neon_vmax<mode>"
2165   [(set (match_operand:VDQW 0 "s_register_operand" "=w")
2166         (unspec:VDQW [(match_operand:VDQW 1 "s_register_operand" "w")
2167                       (match_operand:VDQW 2 "s_register_operand" "w")
2168                       (match_operand:SI 3 "immediate_operand" "i")]
2169                      UNSPEC_VMAX))]
2170   "TARGET_NEON"
2171   "vmax.%T3%#<V_sz_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
2172   [(set (attr "neon_type")
2173     (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
2174                   (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
2175                                 (const_string "neon_fp_vadd_ddd_vabs_dd")
2176                                 (const_string "neon_fp_vadd_qqq_vabs_qq"))
2177                   (const_string "neon_int_5")))]
2178 )
2179
2180 (define_insn "neon_vmin<mode>"
2181   [(set (match_operand:VDQW 0 "s_register_operand" "=w")
2182         (unspec:VDQW [(match_operand:VDQW 1 "s_register_operand" "w")
2183                       (match_operand:VDQW 2 "s_register_operand" "w")
2184                       (match_operand:SI 3 "immediate_operand" "i")]
2185                      UNSPEC_VMIN))]
2186   "TARGET_NEON"
2187   "vmin.%T3%#<V_sz_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
2188   [(set (attr "neon_type")
2189     (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
2190                   (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
2191                                 (const_string "neon_fp_vadd_ddd_vabs_dd")
2192                                 (const_string "neon_fp_vadd_qqq_vabs_qq"))
2193                   (const_string "neon_int_5")))]
2194 )
2195
2196 (define_expand "neon_vpadd<mode>"
2197   [(match_operand:VD 0 "s_register_operand" "=w")
2198    (match_operand:VD 1 "s_register_operand" "w")
2199    (match_operand:VD 2 "s_register_operand" "w")
2200    (match_operand:SI 3 "immediate_operand" "i")]
2201   "TARGET_NEON"
2202 {
2203   emit_insn (gen_neon_vpadd_internal<mode> (operands[0], operands[1],
2204                                             operands[2]));
2205   DONE;
2206 })
2207
2208 (define_insn "neon_vpaddl<mode>"
2209   [(set (match_operand:<V_double_width> 0 "s_register_operand" "=w")
2210         (unspec:<V_double_width> [(match_operand:VDQIW 1 "s_register_operand" "w")
2211                                   (match_operand:SI 2 "immediate_operand" "i")]
2212                                  UNSPEC_VPADDL))]
2213   "TARGET_NEON"
2214   "vpaddl.%T2%#<V_sz_elem>\t%<V_reg>0, %<V_reg>1"
2215   ;; Assume this schedules like vaddl.
2216   [(set_attr "neon_type" "neon_int_3")]
2217 )
2218
2219 (define_insn "neon_vpadal<mode>"
2220   [(set (match_operand:<V_double_width> 0 "s_register_operand" "=w")
2221         (unspec:<V_double_width> [(match_operand:<V_double_width> 1 "s_register_operand" "0")
2222                                   (match_operand:VDQIW 2 "s_register_operand" "w")
2223                                   (match_operand:SI 3 "immediate_operand" "i")]
2224                                  UNSPEC_VPADAL))]
2225   "TARGET_NEON"
2226   "vpadal.%T3%#<V_sz_elem>\t%<V_reg>0, %<V_reg>2"
2227   ;; Assume this schedules like vpadd.
2228   [(set_attr "neon_type" "neon_int_1")]
2229 )
2230
2231 (define_insn "neon_vpmax<mode>"
2232   [(set (match_operand:VD 0 "s_register_operand" "=w")
2233         (unspec:VD [(match_operand:VD 1 "s_register_operand" "w")
2234                     (match_operand:VD 2 "s_register_operand" "w")
2235                     (match_operand:SI 3 "immediate_operand" "i")]
2236                    UNSPEC_VPMAX))]
2237   "TARGET_NEON"
2238   "vpmax.%T3%#<V_sz_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
2239   ;; Assume this schedules like vmax.
2240   [(set (attr "neon_type")
2241     (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
2242                   (const_string "neon_fp_vadd_ddd_vabs_dd")
2243                   (const_string "neon_int_5")))]
2244 )
2245
2246 (define_insn "neon_vpmin<mode>"
2247   [(set (match_operand:VD 0 "s_register_operand" "=w")
2248         (unspec:VD [(match_operand:VD 1 "s_register_operand" "w")
2249                     (match_operand:VD 2 "s_register_operand" "w")
2250                     (match_operand:SI 3 "immediate_operand" "i")]
2251                    UNSPEC_VPMIN))]
2252   "TARGET_NEON"
2253   "vpmin.%T3%#<V_sz_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
2254   ;; Assume this schedules like vmin.
2255   [(set (attr "neon_type")
2256     (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
2257                   (const_string "neon_fp_vadd_ddd_vabs_dd")
2258                   (const_string "neon_int_5")))]
2259 )
2260
2261 (define_insn "neon_vrecps<mode>"
2262   [(set (match_operand:VCVTF 0 "s_register_operand" "=w")
2263         (unspec:VCVTF [(match_operand:VCVTF 1 "s_register_operand" "w")
2264                        (match_operand:VCVTF 2 "s_register_operand" "w")
2265                        (match_operand:SI 3 "immediate_operand" "i")]
2266                       UNSPEC_VRECPS))]
2267   "TARGET_NEON"
2268   "vrecps.<V_if_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
2269   [(set (attr "neon_type")
2270       (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
2271                     (const_string "neon_fp_vrecps_vrsqrts_ddd")
2272                     (const_string "neon_fp_vrecps_vrsqrts_qqq")))]
2273 )
2274
2275 (define_insn "neon_vrsqrts<mode>"
2276   [(set (match_operand:VCVTF 0 "s_register_operand" "=w")
2277         (unspec:VCVTF [(match_operand:VCVTF 1 "s_register_operand" "w")
2278                        (match_operand:VCVTF 2 "s_register_operand" "w")
2279                        (match_operand:SI 3 "immediate_operand" "i")]
2280                       UNSPEC_VRSQRTS))]
2281   "TARGET_NEON"
2282   "vrsqrts.<V_if_elem>\t%<V_reg>0, %<V_reg>1, %<V_reg>2"
2283   [(set (attr "neon_type")
2284       (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
2285                     (const_string "neon_fp_vrecps_vrsqrts_ddd")
2286                     (const_string "neon_fp_vrecps_vrsqrts_qqq")))]
2287 )
2288
2289 (define_insn "neon_vabs<mode>"
2290   [(set (match_operand:VDQW 0 "s_register_operand" "=w")
2291         (unspec:VDQW [(match_operand:VDQW 1 "s_register_operand" "w")
2292                       (match_operand:SI 2 "immediate_operand" "i")]
2293                      UNSPEC_VABS))]
2294   "TARGET_NEON"
2295   "vabs.<V_s_elem>\t%<V_reg>0, %<V_reg>1"
2296   [(set (attr "neon_type")
2297      (if_then_else (ior (ne (symbol_ref "<Is_float_mode>") (const_int 0))
2298                         (ne (symbol_ref "<Is_float_mode>") (const_int 0)))
2299                    (if_then_else
2300                       (ne (symbol_ref "<Is_d_reg>") (const_int 0))
2301                       (const_string "neon_fp_vadd_ddd_vabs_dd")
2302                       (const_string "neon_fp_vadd_qqq_vabs_qq"))
2303                    (const_string "neon_vqneg_vqabs")))]
2304 )
2305
2306 (define_insn "neon_vqabs<mode>"
2307   [(set (match_operand:VDQIW 0 "s_register_operand" "=w")
2308         (unspec:VDQIW [(match_operand:VDQIW 1 "s_register_operand" "w")
2309                        (match_operand:SI 2 "immediate_operand" "i")]
2310                       UNSPEC_VQABS))]
2311   "TARGET_NEON"
2312   "vqabs.<V_s_elem>\t%<V_reg>0, %<V_reg>1"
2313   [(set_attr "neon_type" "neon_vqneg_vqabs")]
2314 )
2315
2316 (define_expand "neon_vneg<mode>"
2317   [(match_operand:VDQW 0 "s_register_operand" "")
2318    (match_operand:VDQW 1 "s_register_operand" "")
2319    (match_operand:SI 2 "immediate_operand" "")]
2320   "TARGET_NEON"
2321 {
2322   emit_insn (gen_neg<mode>2 (operands[0], operands[1]));
2323   DONE;
2324 })
2325
2326 (define_insn "neon_vqneg<mode>"
2327   [(set (match_operand:VDQIW 0 "s_register_operand" "=w")
2328         (unspec:VDQIW [(match_operand:VDQIW 1 "s_register_operand" "w")
2329                        (match_operand:SI 2 "immediate_operand" "i")]
2330                       UNSPEC_VQNEG))]
2331   "TARGET_NEON"
2332   "vqneg.<V_s_elem>\t%<V_reg>0, %<V_reg>1"
2333   [(set_attr "neon_type" "neon_vqneg_vqabs")]
2334 )
2335
2336 (define_insn "neon_vcls<mode>"
2337   [(set (match_operand:VDQIW 0 "s_register_operand" "=w")
2338         (unspec:VDQIW [(match_operand:VDQIW 1 "s_register_operand" "w")
2339                        (match_operand:SI 2 "immediate_operand" "i")]
2340                       UNSPEC_VCLS))]
2341   "TARGET_NEON"
2342   "vcls.<V_s_elem>\t%<V_reg>0, %<V_reg>1"
2343   [(set_attr "neon_type" "neon_int_1")]
2344 )
2345
2346 (define_insn "neon_vclz<mode>"
2347   [(set (match_operand:VDQIW 0 "s_register_operand" "=w")
2348         (unspec:VDQIW [(match_operand:VDQIW 1 "s_register_operand" "w")
2349                        (match_operand:SI 2 "immediate_operand" "i")]
2350                       UNSPEC_VCLZ))]
2351   "TARGET_NEON"
2352   "vclz.<V_if_elem>\t%<V_reg>0, %<V_reg>1"
2353   [(set_attr "neon_type" "neon_int_1")]
2354 )
2355
2356 (define_insn "neon_vcnt<mode>"
2357   [(set (match_operand:VE 0 "s_register_operand" "=w")
2358         (unspec:VE [(match_operand:VE 1 "s_register_operand" "w")
2359                     (match_operand:SI 2 "immediate_operand" "i")]
2360                    UNSPEC_VCNT))]
2361   "TARGET_NEON"
2362   "vcnt.<V_sz_elem>\t%<V_reg>0, %<V_reg>1"
2363   [(set_attr "neon_type" "neon_int_1")]
2364 )
2365
2366 (define_insn "neon_vrecpe<mode>"
2367   [(set (match_operand:V32 0 "s_register_operand" "=w")
2368         (unspec:V32 [(match_operand:V32 1 "s_register_operand" "w")
2369                      (match_operand:SI 2 "immediate_operand" "i")]
2370                     UNSPEC_VRECPE))]
2371   "TARGET_NEON"
2372   "vrecpe.<V_u_elem>\t%<V_reg>0, %<V_reg>1"
2373   [(set (attr "neon_type")
2374       (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
2375                     (const_string "neon_fp_vadd_ddd_vabs_dd")
2376                     (const_string "neon_fp_vadd_qqq_vabs_qq")))]
2377 )
2378
2379 (define_insn "neon_vrsqrte<mode>"
2380   [(set (match_operand:V32 0 "s_register_operand" "=w")
2381         (unspec:V32 [(match_operand:V32 1 "s_register_operand" "w")
2382                      (match_operand:SI 2 "immediate_operand" "i")]
2383                     UNSPEC_VRSQRTE))]
2384   "TARGET_NEON"
2385   "vrsqrte.<V_u_elem>\t%<V_reg>0, %<V_reg>1"
2386   [(set (attr "neon_type")
2387       (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
2388                     (const_string "neon_fp_vadd_ddd_vabs_dd")
2389                     (const_string "neon_fp_vadd_qqq_vabs_qq")))]
2390 )
2391
2392 (define_expand "neon_vmvn<mode>"
2393   [(match_operand:VDQIW 0 "s_register_operand" "")
2394    (match_operand:VDQIW 1 "s_register_operand" "")
2395    (match_operand:SI 2 "immediate_operand" "")]
2396   "TARGET_NEON"
2397 {
2398   emit_insn (gen_one_cmpl<mode>2 (operands[0], operands[1]));
2399   DONE;
2400 })
2401
2402 (define_insn "neon_vget_lane<mode>_sext_internal"
2403   [(set (match_operand:SI 0 "s_register_operand" "=r")
2404         (sign_extend:SI
2405           (vec_select:<V_elem>
2406             (match_operand:VD 1 "s_register_operand" "w")
2407             (parallel [(match_operand:SI 2 "immediate_operand" "i")]))))]
2408   "TARGET_NEON"
2409 {
2410   if (BYTES_BIG_ENDIAN)
2411     {
2412       int elt = INTVAL (operands[2]);
2413       elt = GET_MODE_NUNITS (<MODE>mode) - 1 - elt;
2414       operands[2] = GEN_INT (elt);
2415     }
2416   return "vmov%?.s<V_sz_elem>\t%0, %P1[%c2]";
2417 }
2418   [(set_attr "predicable" "yes")
2419    (set_attr "neon_type" "neon_bp_simple")]
2420 )
2421
2422 (define_insn "neon_vget_lane<mode>_zext_internal"
2423   [(set (match_operand:SI 0 "s_register_operand" "=r")
2424         (zero_extend:SI
2425           (vec_select:<V_elem>
2426             (match_operand:VD 1 "s_register_operand" "w")
2427             (parallel [(match_operand:SI 2 "immediate_operand" "i")]))))]
2428   "TARGET_NEON"
2429 {
2430   if (BYTES_BIG_ENDIAN)
2431     {
2432       int elt = INTVAL (operands[2]);
2433       elt = GET_MODE_NUNITS (<MODE>mode) - 1 - elt;
2434       operands[2] = GEN_INT (elt);
2435     }
2436   return "vmov%?.u<V_sz_elem>\t%0, %P1[%c2]";
2437 }
2438   [(set_attr "predicable" "yes")
2439    (set_attr "neon_type" "neon_bp_simple")]
2440 )
2441
2442 (define_insn "neon_vget_lane<mode>_sext_internal"
2443   [(set (match_operand:SI 0 "s_register_operand" "=r")
2444         (sign_extend:SI
2445           (vec_select:<V_elem>
2446             (match_operand:VQ 1 "s_register_operand" "w")
2447             (parallel [(match_operand:SI 2 "immediate_operand" "i")]))))]
2448   "TARGET_NEON"
2449 {
2450   rtx ops[3];
2451   int regno = REGNO (operands[1]);
2452   unsigned int halfelts = GET_MODE_NUNITS (<MODE>mode) / 2;
2453   unsigned int elt = INTVAL (operands[2]);
2454   unsigned int elt_adj = elt % halfelts;
2455
2456   if (BYTES_BIG_ENDIAN)
2457     elt_adj = halfelts - 1 - elt_adj;
2458
2459   ops[0] = operands[0];
2460   ops[1] = gen_rtx_REG (<V_HALF>mode, regno + 2 * (elt / halfelts));
2461   ops[2] = GEN_INT (elt_adj);
2462   output_asm_insn ("vmov%?.s<V_sz_elem>\t%0, %P1[%c2]", ops);
2463
2464   return "";
2465 }
2466   [(set_attr "predicable" "yes")
2467    (set_attr "neon_type" "neon_bp_simple")]
2468 )
2469
2470 (define_insn "neon_vget_lane<mode>_zext_internal"
2471   [(set (match_operand:SI 0 "s_register_operand" "=r")
2472         (zero_extend:SI
2473           (vec_select:<V_elem>
2474             (match_operand:VQ 1 "s_register_operand" "w")
2475             (parallel [(match_operand:SI 2 "immediate_operand" "i")]))))]
2476   "TARGET_NEON"
2477 {
2478   rtx ops[3];
2479   int regno = REGNO (operands[1]);
2480   unsigned int halfelts = GET_MODE_NUNITS (<MODE>mode) / 2;
2481   unsigned int elt = INTVAL (operands[2]);
2482   unsigned int elt_adj = elt % halfelts;
2483
2484   if (BYTES_BIG_ENDIAN)
2485     elt_adj = halfelts - 1 - elt_adj;
2486
2487   ops[0] = operands[0];
2488   ops[1] = gen_rtx_REG (<V_HALF>mode, regno + 2 * (elt / halfelts));
2489   ops[2] = GEN_INT (elt_adj);
2490   output_asm_insn ("vmov%?.u<V_sz_elem>\t%0, %P1[%c2]", ops);
2491
2492   return "";
2493 }
2494   [(set_attr "predicable" "yes")
2495    (set_attr "neon_type" "neon_bp_simple")]
2496 )
2497
2498 (define_expand "neon_vget_lane<mode>"
2499   [(match_operand:<V_ext> 0 "s_register_operand" "")
2500    (match_operand:VDQW 1 "s_register_operand" "")
2501    (match_operand:SI 2 "immediate_operand" "")
2502    (match_operand:SI 3 "immediate_operand" "")]
2503   "TARGET_NEON"
2504 {
2505   HOST_WIDE_INT magic = INTVAL (operands[3]);
2506   rtx insn;
2507
2508   neon_lane_bounds (operands[2], 0, GET_MODE_NUNITS (<MODE>mode));
2509
2510   if (BYTES_BIG_ENDIAN)
2511     {
2512       /* The intrinsics are defined in terms of a model where the
2513          element ordering in memory is vldm order, whereas the generic
2514          RTL is defined in terms of a model where the element ordering
2515          in memory is array order.  Convert the lane number to conform
2516          to this model.  */
2517       unsigned int elt = INTVAL (operands[2]);
2518       unsigned int reg_nelts
2519         = 64 / GET_MODE_BITSIZE (GET_MODE_INNER (<MODE>mode));
2520       elt ^= reg_nelts - 1;
2521       operands[2] = GEN_INT (elt);
2522     }
2523
2524   if ((magic & 3) == 3 || GET_MODE_BITSIZE (GET_MODE_INNER (<MODE>mode)) == 32)
2525     insn = gen_vec_extract<mode> (operands[0], operands[1], operands[2]);
2526   else
2527     {
2528       if ((magic & 1) != 0)
2529         insn = gen_neon_vget_lane<mode>_sext_internal (operands[0], operands[1],
2530                                                        operands[2]);
2531       else
2532         insn = gen_neon_vget_lane<mode>_zext_internal (operands[0], operands[1],
2533                                                        operands[2]);
2534     }
2535   emit_insn (insn);
2536   DONE;
2537 })
2538
2539 ; Operand 3 (info word) is ignored because it does nothing useful with 64-bit
2540 ; elements.
2541
2542 (define_insn "neon_vget_lanedi"
2543   [(set (match_operand:DI 0 "s_register_operand" "=r")
2544        (unspec:DI [(match_operand:DI 1 "s_register_operand" "w")
2545                    (match_operand:SI 2 "immediate_operand" "i")
2546                    (match_operand:SI 3 "immediate_operand" "i")]
2547                   UNSPEC_VGET_LANE))]
2548   "TARGET_NEON"
2549 {
2550   neon_lane_bounds (operands[2], 0, 1);
2551   return "vmov%?\t%Q0, %R0, %P1  @ di";
2552 }
2553   [(set_attr "predicable" "yes")
2554    (set_attr "neon_type" "neon_bp_simple")]
2555 )
2556
2557 (define_insn "neon_vget_lanev2di"
2558   [(set (match_operand:DI 0 "s_register_operand" "=r")
2559        (unspec:DI [(match_operand:V2DI 1 "s_register_operand" "w")
2560                    (match_operand:SI 2 "immediate_operand" "i")
2561                    (match_operand:SI 3 "immediate_operand" "i")]
2562                   UNSPEC_VGET_LANE))]
2563   "TARGET_NEON"
2564 {
2565   rtx ops[2];
2566   unsigned int regno = REGNO (operands[1]);
2567   unsigned int elt = INTVAL (operands[2]);
2568
2569   neon_lane_bounds (operands[2], 0, 2);
2570
2571   ops[0] = operands[0];
2572   ops[1] = gen_rtx_REG (DImode, regno + 2 * elt);
2573   output_asm_insn ("vmov%?\t%Q0, %R0, %P1  @ v2di", ops);
2574
2575   return "";
2576 }
2577   [(set_attr "predicable" "yes")
2578    (set_attr "neon_type" "neon_bp_simple")]
2579 )
2580
2581 (define_insn "neon_vset_lane<mode>"
2582   [(set (match_operand:VD 0 "s_register_operand" "=w")
2583         (unspec:VD [(match_operand:<V_elem> 1 "s_register_operand" "r")
2584                     (match_operand:VD 2 "s_register_operand" "0")
2585                     (match_operand:SI 3 "immediate_operand" "i")]
2586                    UNSPEC_VSET_LANE))]
2587   "TARGET_NEON"
2588 {
2589   neon_lane_bounds (operands[3], 0, GET_MODE_NUNITS (<MODE>mode));
2590   return "vmov%?.<V_sz_elem>\t%P0[%c3], %1";
2591 }
2592   [(set_attr "predicable" "yes")
2593    (set_attr "neon_type" "neon_bp_simple")]
2594 )
2595
2596 ; See neon_vget_lanedi comment for reasons operands 2 & 3 are ignored.
2597
2598 (define_insn "neon_vset_lanedi"
2599   [(set (match_operand:DI 0 "s_register_operand" "=w")
2600         (unspec:DI [(match_operand:DI 1 "s_register_operand" "r")
2601                     (match_operand:DI 2 "s_register_operand" "0")
2602                     (match_operand:SI 3 "immediate_operand" "i")]
2603                    UNSPEC_VSET_LANE))]
2604   "TARGET_NEON"
2605 {
2606   neon_lane_bounds (operands[3], 0, 1);
2607   return "vmov%?\t%P0, %Q1, %R1  @ di";
2608 }
2609   [(set_attr "predicable" "yes")
2610    (set_attr "neon_type" "neon_bp_simple")]
2611 )
2612
2613 (define_insn "neon_vset_lane<mode>"
2614   [(set (match_operand:VQ 0 "s_register_operand" "=w")
2615         (unspec:VQ [(match_operand:<V_elem> 1 "s_register_operand" "r")
2616                     (match_operand:VQ 2 "s_register_operand" "0")
2617                     (match_operand:SI 3 "immediate_operand" "i")]
2618                    UNSPEC_VSET_LANE))]
2619   "TARGET_NEON"
2620 {
2621   rtx ops[4];
2622   unsigned int regno = REGNO (operands[0]);
2623   unsigned int halfelts = GET_MODE_NUNITS (<MODE>mode) / 2;
2624   unsigned int elt = INTVAL (operands[3]);
2625
2626   neon_lane_bounds (operands[3], 0, halfelts * 2);
2627
2628   ops[0] = gen_rtx_REG (<V_HALF>mode, regno + 2 * (elt / halfelts));
2629   ops[1] = operands[1];
2630   ops[2] = GEN_INT (elt % halfelts);
2631   output_asm_insn ("vmov%?.<V_sz_elem>\t%P0[%c2], %1", ops);
2632
2633   return "";
2634 }
2635   [(set_attr "predicable" "yes")
2636    (set_attr "neon_type" "neon_bp_simple")]
2637 )
2638
2639 (define_insn "neon_vset_lanev2di"
2640   [(set (match_operand:V2DI 0 "s_register_operand" "=w")
2641         (unspec:V2DI [(match_operand:DI 1 "s_register_operand" "r")
2642                       (match_operand:V2DI 2 "s_register_operand" "0")
2643                       (match_operand:SI 3 "immediate_operand" "i")]
2644                    UNSPEC_VSET_LANE))]
2645   "TARGET_NEON"
2646 {
2647   rtx ops[2];
2648   unsigned int regno = REGNO (operands[0]);
2649   unsigned int elt = INTVAL (operands[3]);
2650
2651   neon_lane_bounds (operands[3], 0, 2);
2652
2653   ops[0] = gen_rtx_REG (DImode, regno + 2 * elt);
2654   ops[1] = operands[1];
2655   output_asm_insn ("vmov%?\t%P0, %Q1, %R1  @ v2di", ops);
2656
2657   return "";
2658 }
2659   [(set_attr "predicable" "yes")
2660    (set_attr "neon_type" "neon_bp_simple")]
2661 )
2662
2663 (define_expand "neon_vcreate<mode>"
2664   [(match_operand:VDX 0 "s_register_operand" "")
2665    (match_operand:DI 1 "general_operand" "")]
2666   "TARGET_NEON"
2667 {
2668   rtx src = gen_lowpart (<MODE>mode, operands[1]);
2669   emit_move_insn (operands[0], src);
2670   DONE;
2671 })
2672
2673 (define_insn "neon_vdup_n<mode>"
2674   [(set (match_operand:VDQW 0 "s_register_operand" "=w")
2675         (unspec:VDQW [(match_operand:<V_elem> 1 "s_register_operand" "r")]
2676                     UNSPEC_VDUP_N))]
2677   "TARGET_NEON"
2678   "vdup%?.<V_sz_elem>\t%<V_reg>0, %1"
2679   ;; Assume this schedules like vmov.
2680   [(set_attr "predicable" "yes")
2681    (set_attr "neon_type" "neon_bp_simple")]
2682 )
2683
2684 (define_insn "neon_vdup_ndi"
2685   [(set (match_operand:DI 0 "s_register_operand" "=w")
2686         (unspec:DI [(match_operand:DI 1 "s_register_operand" "r")]
2687                    UNSPEC_VDUP_N))]
2688   "TARGET_NEON"
2689   "vmov%?\t%P0, %Q1, %R1"
2690   [(set_attr "predicable" "yes")
2691    (set_attr "neon_type" "neon_bp_simple")]
2692 )
2693
2694 (define_insn "neon_vdup_nv2di"
2695   [(set (match_operand:V2DI 0 "s_register_operand" "=w")
2696         (unspec:V2DI [(match_operand:DI 1 "s_register_operand" "r")]
2697                      UNSPEC_VDUP_N))]
2698   "TARGET_NEON"
2699   "vmov%?\t%e0, %Q1, %R1\;vmov%?\t%f0, %Q1, %R1"
2700   [(set_attr "predicable" "yes")
2701    (set_attr "length" "8")
2702    (set_attr "neon_type" "neon_bp_simple")]
2703 )
2704
2705 (define_insn "neon_vdup_lane<mode>"
2706   [(set (match_operand:VD 0 "s_register_operand" "=w")
2707         (unspec:VD [(match_operand:VD 1 "s_register_operand" "w")
2708                     (match_operand:SI 2 "immediate_operand" "i")]
2709                    UNSPEC_VDUP_LANE))]
2710   "TARGET_NEON"
2711 {
2712   neon_lane_bounds (operands[2], 0, GET_MODE_NUNITS (<MODE>mode));
2713   return "vdup.<V_sz_elem>\t%P0, %P1[%c2]";
2714 }
2715   ;; Assume this schedules like vmov.
2716   [(set_attr "neon_type" "neon_bp_simple")]
2717 )
2718
2719 (define_insn "neon_vdup_lane<mode>"
2720   [(set (match_operand:VQ 0 "s_register_operand" "=w")
2721         (unspec:VQ [(match_operand:<V_HALF> 1 "s_register_operand" "w")
2722                     (match_operand:SI 2 "immediate_operand" "i")]
2723                    UNSPEC_VDUP_LANE))]
2724   "TARGET_NEON"
2725 {
2726   neon_lane_bounds (operands[2], 0, GET_MODE_NUNITS (<V_HALF>mode));
2727   return "vdup.<V_sz_elem>\t%q0, %P1[%c2]";
2728 }
2729   ;; Assume this schedules like vmov.
2730   [(set_attr "neon_type" "neon_bp_simple")]
2731 )
2732
2733 ; Scalar index is ignored, since only zero is valid here.
2734 (define_expand "neon_vdup_lanedi"
2735   [(set (match_operand:DI 0 "s_register_operand" "=w")
2736         (unspec:DI [(match_operand:DI 1 "s_register_operand" "w")
2737                     (match_operand:SI 2 "immediate_operand" "i")]
2738                    UNSPEC_VDUP_LANE))]
2739   "TARGET_NEON"
2740 {
2741   neon_lane_bounds (operands[2], 0, 1);
2742   emit_move_insn (operands[0], operands[1]);
2743   DONE;
2744 })
2745
2746 ; Likewise.
2747 (define_insn "neon_vdup_lanev2di"
2748   [(set (match_operand:V2DI 0 "s_register_operand" "=w")
2749         (unspec:V2DI [(match_operand:DI 1 "s_register_operand" "w")
2750                       (match_operand:SI 2 "immediate_operand" "i")]
2751                      UNSPEC_VDUP_LANE))]
2752   "TARGET_NEON"
2753 {
2754   neon_lane_bounds (operands[2], 0, 1);
2755   return "vmov\t%e0, %P1\;vmov\t%f0, %P1";
2756 }
2757   [(set_attr "length" "8")
2758    (set_attr "neon_type" "neon_bp_simple")]
2759 )
2760
2761 ;; In this insn, operand 1 should be low, and operand 2 the high part of the
2762 ;; dest vector.
2763 ;; FIXME: A different implementation of this builtin could make it much
2764 ;; more likely that we wouldn't actually need to output anything (we could make
2765 ;; it so that the reg allocator puts things in the right places magically
2766 ;; instead). Lack of subregs for vectors makes that tricky though, I think.
2767
2768 (define_insn "neon_vcombine<mode>"
2769   [(set (match_operand:<V_DOUBLE> 0 "s_register_operand" "=w")
2770         (unspec:<V_DOUBLE> [(match_operand:VDX 1 "s_register_operand" "w")
2771                             (match_operand:VDX 2 "s_register_operand" "w")]
2772                            UNSPEC_VCOMBINE))]
2773   "TARGET_NEON"
2774 {
2775   int dest = REGNO (operands[0]);
2776   int src1 = REGNO (operands[1]);
2777   int src2 = REGNO (operands[2]);
2778   rtx destlo;
2779
2780   if (src1 == dest && src2 == dest + 2)
2781     return "";
2782   else if (src2 == dest && src1 == dest + 2)
2783     /* Special case of reversed high/low parts.  */
2784     return "vswp\t%P1, %P2";
2785
2786   destlo = gen_rtx_REG (<MODE>mode, dest);
2787
2788   if (!reg_overlap_mentioned_p (operands[2], destlo))
2789     {
2790       /* Try to avoid unnecessary moves if part of the result is in the right
2791          place already.  */
2792       if (src1 != dest)
2793         output_asm_insn ("vmov\t%e0, %P1", operands);
2794       if (src2 != dest + 2)
2795         output_asm_insn ("vmov\t%f0, %P2", operands);
2796     }
2797   else
2798     {
2799       if (src2 != dest + 2)
2800         output_asm_insn ("vmov\t%f0, %P2", operands);
2801       if (src1 != dest)
2802         output_asm_insn ("vmov\t%e0, %P1", operands);
2803     }
2804
2805   return "";
2806 }
2807   ;; We set the neon_type attribute based on the vmov instructions above.
2808   [(set_attr "length" "8")
2809    (set_attr "neon_type" "neon_bp_simple")]
2810 )
2811
2812 (define_insn "neon_vget_high<mode>"
2813   [(set (match_operand:<V_HALF> 0 "s_register_operand" "=w")
2814         (unspec:<V_HALF> [(match_operand:VQX 1 "s_register_operand" "w")]
2815                          UNSPEC_VGET_HIGH))]
2816   "TARGET_NEON"
2817 {
2818   int dest = REGNO (operands[0]);
2819   int src = REGNO (operands[1]);
2820
2821   if (dest != src + 2)
2822     return "vmov\t%P0, %f1";
2823   else
2824     return "";
2825 }
2826   [(set_attr "neon_type" "neon_bp_simple")]
2827 )
2828
2829 (define_insn "neon_vget_low<mode>"
2830   [(set (match_operand:<V_HALF> 0 "s_register_operand" "=w")
2831         (unspec:<V_HALF> [(match_operand:VQX 1 "s_register_operand" "w")]
2832                          UNSPEC_VGET_LOW))]
2833   "TARGET_NEON"
2834 {
2835   int dest = REGNO (operands[0]);
2836   int src = REGNO (operands[1]);
2837
2838   if (dest != src)
2839     return "vmov\t%P0, %e1";
2840   else
2841     return "";
2842 }
2843   [(set_attr "neon_type" "neon_bp_simple")]
2844 )
2845
2846 (define_insn "neon_vcvt<mode>"
2847   [(set (match_operand:<V_CVTTO> 0 "s_register_operand" "=w")
2848         (unspec:<V_CVTTO> [(match_operand:VCVTF 1 "s_register_operand" "w")
2849                            (match_operand:SI 2 "immediate_operand" "i")]
2850                           UNSPEC_VCVT))]
2851   "TARGET_NEON"
2852   "vcvt.%T2%#32.f32\t%<V_reg>0, %<V_reg>1"
2853   [(set (attr "neon_type")
2854      (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
2855                    (const_string "neon_fp_vadd_ddd_vabs_dd")
2856                    (const_string "neon_fp_vadd_qqq_vabs_qq")))]
2857 )
2858
2859 (define_insn "neon_vcvt<mode>"
2860   [(set (match_operand:<V_CVTTO> 0 "s_register_operand" "=w")
2861         (unspec:<V_CVTTO> [(match_operand:VCVTI 1 "s_register_operand" "w")
2862                            (match_operand:SI 2 "immediate_operand" "i")]
2863                           UNSPEC_VCVT))]
2864   "TARGET_NEON"
2865   "vcvt.f32.%T2%#32\t%<V_reg>0, %<V_reg>1"
2866   [(set (attr "neon_type")
2867      (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
2868                    (const_string "neon_fp_vadd_ddd_vabs_dd")
2869                    (const_string "neon_fp_vadd_qqq_vabs_qq")))]
2870 )
2871
2872 (define_insn "neon_vcvt_n<mode>"
2873   [(set (match_operand:<V_CVTTO> 0 "s_register_operand" "=w")
2874         (unspec:<V_CVTTO> [(match_operand:VCVTF 1 "s_register_operand" "w")
2875                            (match_operand:SI 2 "immediate_operand" "i")
2876                            (match_operand:SI 3 "immediate_operand" "i")]
2877                           UNSPEC_VCVT_N))]
2878   "TARGET_NEON"
2879 {
2880   neon_const_bounds (operands[2], 1, 33);
2881   return "vcvt.%T3%#32.f32\t%<V_reg>0, %<V_reg>1, %2";
2882 }
2883   [(set (attr "neon_type")
2884      (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
2885                    (const_string "neon_fp_vadd_ddd_vabs_dd")
2886                    (const_string "neon_fp_vadd_qqq_vabs_qq")))]
2887 )
2888
2889 (define_insn "neon_vcvt_n<mode>"
2890   [(set (match_operand:<V_CVTTO> 0 "s_register_operand" "=w")
2891         (unspec:<V_CVTTO> [(match_operand:VCVTI 1 "s_register_operand" "w")
2892                            (match_operand:SI 2 "immediate_operand" "i")
2893                            (match_operand:SI 3 "immediate_operand" "i")]
2894                           UNSPEC_VCVT_N))]
2895   "TARGET_NEON"
2896 {
2897   neon_const_bounds (operands[2], 1, 33);
2898   return "vcvt.f32.%T3%#32\t%<V_reg>0, %<V_reg>1, %2";
2899 }
2900   [(set (attr "neon_type")
2901      (if_then_else (ne (symbol_ref "<Is_d_reg>") (const_int 0))
2902                    (const_string "neon_fp_vadd_ddd_vabs_dd")
2903                    (const_string "neon_fp_vadd_qqq_vabs_qq")))]
2904 )
2905
2906 (define_insn "neon_vmovn<mode>"
2907   [(set (match_operand:<V_narrow> 0 "s_register_operand" "=w")
2908         (unspec:<V_narrow> [(match_operand:VN 1 "s_register_operand" "w")
2909                             (match_operand:SI 2 "immediate_operand" "i")]
2910                            UNSPEC_VMOVN))]
2911   "TARGET_NEON"
2912   "vmovn.<V_if_elem>\t%P0, %q1"
2913   [(set_attr "neon_type" "neon_bp_simple")]
2914 )
2915
2916 (define_insn "neon_vqmovn<mode>"
2917   [(set (match_operand:<V_narrow> 0 "s_register_operand" "=w")
2918         (unspec:<V_narrow> [(match_operand:VN 1 "s_register_operand" "w")
2919                             (match_operand:SI 2 "immediate_operand" "i")]
2920                            UNSPEC_VQMOVN))]
2921   "TARGET_NEON"
2922   "vqmovn.%T2%#<V_sz_elem>\t%P0, %q1"
2923   [(set_attr "neon_type" "neon_shift_2")]
2924 )
2925
2926 (define_insn "neon_vqmovun<mode>"
2927   [(set (match_operand:<V_narrow> 0 "s_register_operand" "=w")
2928         (unspec:<V_narrow> [(match_operand:VN 1 "s_register_operand" "w")
2929                             (match_operand:SI 2 "immediate_operand" "i")]
2930                            UNSPEC_VQMOVUN))]
2931   "TARGET_NEON"
2932   "vqmovun.<V_s_elem>\t%P0, %q1"
2933   [(set_attr "neon_type" "neon_shift_2")]
2934 )
2935
2936 (define_insn "neon_vmovl<mode>"
2937   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
2938         (unspec:<V_widen> [(match_operand:VW 1 "s_register_operand" "w")
2939                            (match_operand:SI 2 "immediate_operand" "i")]
2940                           UNSPEC_VMOVL))]
2941   "TARGET_NEON"
2942   "vmovl.%T2%#<V_sz_elem>\t%q0, %P1"
2943   [(set_attr "neon_type" "neon_shift_1")]
2944 )
2945
2946 (define_insn "neon_vmul_lane<mode>"
2947   [(set (match_operand:VMD 0 "s_register_operand" "=w")
2948         (unspec:VMD [(match_operand:VMD 1 "s_register_operand" "w")
2949                      (match_operand:VMD 2 "s_register_operand"
2950                                         "<scalar_mul_constraint>")
2951                      (match_operand:SI 3 "immediate_operand" "i")
2952                      (match_operand:SI 4 "immediate_operand" "i")]
2953                     UNSPEC_VMUL_LANE))]
2954   "TARGET_NEON"
2955 {
2956   neon_lane_bounds (operands[3], 0, GET_MODE_NUNITS (<MODE>mode));
2957   return "vmul.<V_if_elem>\t%P0, %P1, %P2[%c3]";
2958 }
2959   [(set (attr "neon_type")
2960      (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
2961                    (const_string "neon_fp_vmul_ddd")
2962                    (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
2963                                  (const_string "neon_mul_ddd_16_scalar_32_16_long_scalar")
2964                                  (const_string "neon_mul_qdd_64_32_long_qqd_16_ddd_32_scalar_64_32_long_scalar"))))]
2965 )
2966
2967 (define_insn "neon_vmul_lane<mode>"
2968   [(set (match_operand:VMQ 0 "s_register_operand" "=w")
2969         (unspec:VMQ [(match_operand:VMQ 1 "s_register_operand" "w")
2970                      (match_operand:<V_HALF> 2 "s_register_operand"
2971                                              "<scalar_mul_constraint>")
2972                      (match_operand:SI 3 "immediate_operand" "i")
2973                      (match_operand:SI 4 "immediate_operand" "i")]
2974                     UNSPEC_VMUL_LANE))]
2975   "TARGET_NEON"
2976 {
2977   neon_lane_bounds (operands[3], 0, GET_MODE_NUNITS (<V_HALF>mode));
2978   return "vmul.<V_if_elem>\t%q0, %q1, %P2[%c3]";
2979 }
2980   [(set (attr "neon_type")
2981      (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
2982                    (const_string "neon_fp_vmul_qqd")
2983                    (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
2984                                  (const_string "neon_mul_qdd_64_32_long_qqd_16_ddd_32_scalar_64_32_long_scalar")
2985                                  (const_string "neon_mul_qqd_32_scalar"))))]
2986 )
2987
2988 (define_insn "neon_vmull_lane<mode>"
2989   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
2990         (unspec:<V_widen> [(match_operand:VMDI 1 "s_register_operand" "w")
2991                            (match_operand:VMDI 2 "s_register_operand"
2992                                                "<scalar_mul_constraint>")
2993                            (match_operand:SI 3 "immediate_operand" "i")
2994                            (match_operand:SI 4 "immediate_operand" "i")]
2995                           UNSPEC_VMULL_LANE))]
2996   "TARGET_NEON"
2997 {
2998   neon_lane_bounds (operands[3], 0, GET_MODE_NUNITS (<MODE>mode));
2999   return "vmull.%T4%#<V_sz_elem>\t%q0, %P1, %P2[%c3]";
3000 }
3001   [(set (attr "neon_type")
3002      (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
3003                    (const_string "neon_mul_ddd_16_scalar_32_16_long_scalar")
3004                    (const_string "neon_mul_qdd_64_32_long_qqd_16_ddd_32_scalar_64_32_long_scalar")))]
3005 )
3006
3007 (define_insn "neon_vqdmull_lane<mode>"
3008   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
3009         (unspec:<V_widen> [(match_operand:VMDI 1 "s_register_operand" "w")
3010                            (match_operand:VMDI 2 "s_register_operand"
3011                                                "<scalar_mul_constraint>")
3012                            (match_operand:SI 3 "immediate_operand" "i")
3013                            (match_operand:SI 4 "immediate_operand" "i")]
3014                           UNSPEC_VQDMULL_LANE))]
3015   "TARGET_NEON"
3016 {
3017   neon_lane_bounds (operands[3], 0, GET_MODE_NUNITS (<MODE>mode));
3018   return "vqdmull.<V_s_elem>\t%q0, %P1, %P2[%c3]";
3019 }
3020   [(set (attr "neon_type")
3021      (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
3022                    (const_string "neon_mul_ddd_16_scalar_32_16_long_scalar")
3023                    (const_string "neon_mul_qdd_64_32_long_qqd_16_ddd_32_scalar_64_32_long_scalar")))]
3024 )
3025
3026 (define_insn "neon_vqdmulh_lane<mode>"
3027   [(set (match_operand:VMQI 0 "s_register_operand" "=w")
3028         (unspec:VMQI [(match_operand:VMQI 1 "s_register_operand" "w")
3029                       (match_operand:<V_HALF> 2 "s_register_operand"
3030                                               "<scalar_mul_constraint>")
3031                       (match_operand:SI 3 "immediate_operand" "i")
3032                       (match_operand:SI 4 "immediate_operand" "i")]
3033                       UNSPEC_VQDMULH_LANE))]
3034   "TARGET_NEON"
3035 {
3036   neon_lane_bounds (operands[3], 0, GET_MODE_NUNITS (<MODE>mode));
3037   return "vq%O4dmulh.%T4%#<V_sz_elem>\t%q0, %q1, %P2[%c3]";
3038 }
3039   [(set (attr "neon_type")
3040      (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
3041                    (const_string "neon_mul_qdd_64_32_long_qqd_16_ddd_32_scalar_64_32_long_scalar")
3042                    (const_string "neon_mul_qqd_32_scalar")))]
3043 )
3044
3045 (define_insn "neon_vqdmulh_lane<mode>"
3046   [(set (match_operand:VMDI 0 "s_register_operand" "=w")
3047         (unspec:VMDI [(match_operand:VMDI 1 "s_register_operand" "w")
3048                       (match_operand:VMDI 2 "s_register_operand"
3049                                           "<scalar_mul_constraint>")
3050                       (match_operand:SI 3 "immediate_operand" "i")
3051                       (match_operand:SI 4 "immediate_operand" "i")]
3052                       UNSPEC_VQDMULH_LANE))]
3053   "TARGET_NEON"
3054 {
3055   neon_lane_bounds (operands[3], 0, GET_MODE_NUNITS (<MODE>mode));
3056   return "vq%O4dmulh.%T4%#<V_sz_elem>\t%P0, %P1, %P2[%c3]";
3057 }
3058   [(set (attr "neon_type")
3059      (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
3060                    (const_string "neon_mul_ddd_16_scalar_32_16_long_scalar")
3061                    (const_string "neon_mul_qdd_64_32_long_qqd_16_ddd_32_scalar_64_32_long_scalar")))]
3062 )
3063
3064 (define_insn "neon_vmla_lane<mode>"
3065   [(set (match_operand:VMD 0 "s_register_operand" "=w")
3066         (unspec:VMD [(match_operand:VMD 1 "s_register_operand" "0")
3067                      (match_operand:VMD 2 "s_register_operand" "w")
3068                      (match_operand:VMD 3 "s_register_operand"
3069                                         "<scalar_mul_constraint>")
3070                      (match_operand:SI 4 "immediate_operand" "i")
3071                      (match_operand:SI 5 "immediate_operand" "i")]
3072                      UNSPEC_VMLA_LANE))]
3073   "TARGET_NEON"
3074 {
3075   neon_lane_bounds (operands[4], 0, GET_MODE_NUNITS (<MODE>mode));
3076   return "vmla.<V_if_elem>\t%P0, %P2, %P3[%c4]";
3077 }
3078   [(set (attr "neon_type")
3079      (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
3080                    (const_string "neon_fp_vmla_ddd_scalar")
3081                    (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
3082                                  (const_string "neon_mla_ddd_16_scalar_qdd_32_16_long_scalar")
3083                                  (const_string "neon_mla_ddd_32_qqd_16_ddd_32_scalar_qdd_64_32_long_scalar_qdd_64_32_long"))))]
3084 )
3085
3086 (define_insn "neon_vmla_lane<mode>"
3087   [(set (match_operand:VMQ 0 "s_register_operand" "=w")
3088         (unspec:VMQ [(match_operand:VMQ 1 "s_register_operand" "0")
3089                      (match_operand:VMQ 2 "s_register_operand" "w")
3090                      (match_operand:<V_HALF> 3 "s_register_operand"
3091                                              "<scalar_mul_constraint>")
3092                      (match_operand:SI 4 "immediate_operand" "i")
3093                      (match_operand:SI 5 "immediate_operand" "i")]
3094                      UNSPEC_VMLA_LANE))]
3095   "TARGET_NEON"
3096 {
3097   neon_lane_bounds (operands[4], 0, GET_MODE_NUNITS (<MODE>mode));
3098   return "vmla.<V_if_elem>\t%q0, %q2, %P3[%c4]";
3099 }
3100   [(set (attr "neon_type")
3101      (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
3102                    (const_string "neon_fp_vmla_qqq_scalar")
3103                    (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
3104                                  (const_string "neon_mla_ddd_32_qqd_16_ddd_32_scalar_qdd_64_32_long_scalar_qdd_64_32_long")
3105                                  (const_string "neon_mla_qqq_32_qqd_32_scalar"))))]
3106 )
3107
3108 (define_insn "neon_vmlal_lane<mode>"
3109   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
3110         (unspec:<V_widen> [(match_operand:<V_widen> 1 "s_register_operand" "0")
3111                            (match_operand:VMDI 2 "s_register_operand" "w")
3112                            (match_operand:VMDI 3 "s_register_operand"
3113                                                "<scalar_mul_constraint>")
3114                            (match_operand:SI 4 "immediate_operand" "i")
3115                            (match_operand:SI 5 "immediate_operand" "i")]
3116                           UNSPEC_VMLAL_LANE))]
3117   "TARGET_NEON"
3118 {
3119   neon_lane_bounds (operands[4], 0, GET_MODE_NUNITS (<MODE>mode));
3120   return "vmlal.%T5%#<V_sz_elem>\t%q0, %P2, %P3[%c4]";
3121 }
3122   [(set (attr "neon_type")
3123      (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
3124                    (const_string "neon_mla_ddd_16_scalar_qdd_32_16_long_scalar")
3125                    (const_string "neon_mla_ddd_32_qqd_16_ddd_32_scalar_qdd_64_32_long_scalar_qdd_64_32_long")))]
3126 )
3127
3128 (define_insn "neon_vqdmlal_lane<mode>"
3129   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
3130         (unspec:<V_widen> [(match_operand:<V_widen> 1 "s_register_operand" "0")
3131                            (match_operand:VMDI 2 "s_register_operand" "w")
3132                            (match_operand:VMDI 3 "s_register_operand"
3133                                                "<scalar_mul_constraint>")
3134                            (match_operand:SI 4 "immediate_operand" "i")
3135                            (match_operand:SI 5 "immediate_operand" "i")]
3136                           UNSPEC_VQDMLAL_LANE))]
3137   "TARGET_NEON"
3138 {
3139   neon_lane_bounds (operands[4], 0, GET_MODE_NUNITS (<MODE>mode));
3140   return "vqdmlal.<V_s_elem>\t%q0, %P2, %P3[%c4]";
3141 }
3142   [(set (attr "neon_type")
3143      (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
3144                    (const_string "neon_mla_ddd_16_scalar_qdd_32_16_long_scalar")
3145                    (const_string "neon_mla_ddd_32_qqd_16_ddd_32_scalar_qdd_64_32_long_scalar_qdd_64_32_long")))]
3146 )
3147
3148 (define_insn "neon_vmls_lane<mode>"
3149   [(set (match_operand:VMD 0 "s_register_operand" "=w")
3150         (unspec:VMD [(match_operand:VMD 1 "s_register_operand" "0")
3151                      (match_operand:VMD 2 "s_register_operand" "w")
3152                      (match_operand:VMD 3 "s_register_operand"
3153                                         "<scalar_mul_constraint>")
3154                      (match_operand:SI 4 "immediate_operand" "i")
3155                      (match_operand:SI 5 "immediate_operand" "i")]
3156                     UNSPEC_VMLS_LANE))]
3157   "TARGET_NEON"
3158 {
3159   neon_lane_bounds (operands[4], 0, GET_MODE_NUNITS (<MODE>mode));
3160   return "vmls.<V_if_elem>\t%P0, %P2, %P3[%c4]";
3161 }
3162   [(set (attr "neon_type")
3163      (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
3164                    (const_string "neon_fp_vmla_ddd_scalar")
3165                    (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
3166                                  (const_string "neon_mla_ddd_16_scalar_qdd_32_16_long_scalar")
3167                                  (const_string "neon_mla_ddd_32_qqd_16_ddd_32_scalar_qdd_64_32_long_scalar_qdd_64_32_long"))))]
3168 )
3169
3170 (define_insn "neon_vmls_lane<mode>"
3171   [(set (match_operand:VMQ 0 "s_register_operand" "=w")
3172         (unspec:VMQ [(match_operand:VMQ 1 "s_register_operand" "0")
3173                      (match_operand:VMQ 2 "s_register_operand" "w")
3174                      (match_operand:<V_HALF> 3 "s_register_operand"
3175                                              "<scalar_mul_constraint>")
3176                      (match_operand:SI 4 "immediate_operand" "i")
3177                      (match_operand:SI 5 "immediate_operand" "i")]
3178                     UNSPEC_VMLS_LANE))]
3179   "TARGET_NEON"
3180 {
3181   neon_lane_bounds (operands[4], 0, GET_MODE_NUNITS (<MODE>mode));
3182   return "vmls.<V_if_elem>\t%q0, %q2, %P3[%c4]";
3183 }
3184   [(set (attr "neon_type")
3185      (if_then_else (ne (symbol_ref "<Is_float_mode>") (const_int 0))
3186                    (const_string "neon_fp_vmla_qqq_scalar")
3187                    (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
3188                                  (const_string "neon_mla_ddd_32_qqd_16_ddd_32_scalar_qdd_64_32_long_scalar_qdd_64_32_long")
3189                                  (const_string "neon_mla_qqq_32_qqd_32_scalar"))))]
3190 )
3191
3192 (define_insn "neon_vmlsl_lane<mode>"
3193   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
3194         (unspec:<V_widen> [(match_operand:<V_widen> 1 "s_register_operand" "0")
3195                            (match_operand:VMDI 2 "s_register_operand" "w")
3196                            (match_operand:VMDI 3 "s_register_operand"
3197                                                "<scalar_mul_constraint>")
3198                            (match_operand:SI 4 "immediate_operand" "i")
3199                            (match_operand:SI 5 "immediate_operand" "i")]
3200                           UNSPEC_VMLSL_LANE))]
3201   "TARGET_NEON"
3202 {
3203   neon_lane_bounds (operands[4], 0, GET_MODE_NUNITS (<MODE>mode));
3204   return "vmlsl.%T5%#<V_sz_elem>\t%q0, %P2, %P3[%c4]";
3205 }
3206   [(set (attr "neon_type")
3207      (if_then_else (ne (symbol_ref "<Scalar_mul_8_16>") (const_int 0))
3208                    (const_string "neon_mla_ddd_16_scalar_qdd_32_16_long_scalar")
3209                    (const_string "neon_mla_ddd_32_qqd_16_ddd_32_scalar_qdd_64_32_long_scalar_qdd_64_32_long")))]
3210 )
3211
3212 (define_insn "neon_vqdmlsl_lane<mode>"
3213   [(set (match_operand:<V_widen> 0 "s_register_operand" "=w")
3214         (unspec:<V_widen> [(match_operand:<V_widen> 1 "s_register_operand" "0")
3215                            (match_operand:VMDI 2 "s_register_operand" "w")
3216                            (match_operand:VMDI 3 "s_register_operand"
3217                                                "<scalar_mul_constraint>")