Merge branch 'vendor/MDOCML'
[dragonfly.git] / contrib / gcc-4.4 / gcc / config / i386 / i386.c
1 /* Subroutines used for code generation on IA-32.
2    Copyright (C) 1988, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3    2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4    Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "rtl.h"
27 #include "tree.h"
28 #include "tm_p.h"
29 #include "regs.h"
30 #include "hard-reg-set.h"
31 #include "real.h"
32 #include "insn-config.h"
33 #include "conditions.h"
34 #include "output.h"
35 #include "insn-codes.h"
36 #include "insn-attr.h"
37 #include "flags.h"
38 #include "c-common.h"
39 #include "except.h"
40 #include "function.h"
41 #include "recog.h"
42 #include "expr.h"
43 #include "optabs.h"
44 #include "toplev.h"
45 #include "basic-block.h"
46 #include "ggc.h"
47 #include "target.h"
48 #include "target-def.h"
49 #include "langhooks.h"
50 #include "cgraph.h"
51 #include "gimple.h"
52 #include "dwarf2.h"
53 #include "df.h"
54 #include "tm-constrs.h"
55 #include "params.h"
56 #include "cselib.h"
57
58 static int x86_builtin_vectorization_cost (bool);
59 static rtx legitimize_dllimport_symbol (rtx, bool);
60
61 #ifndef CHECK_STACK_LIMIT
62 #define CHECK_STACK_LIMIT (-1)
63 #endif
64
65 /* Return index of given mode in mult and division cost tables.  */
66 #define MODE_INDEX(mode)                                        \
67   ((mode) == QImode ? 0                                         \
68    : (mode) == HImode ? 1                                       \
69    : (mode) == SImode ? 2                                       \
70    : (mode) == DImode ? 3                                       \
71    : 4)
72
73 /* Processor costs (relative to an add) */
74 /* We assume COSTS_N_INSNS is defined as (N)*4 and an addition is 2 bytes.  */
75 #define COSTS_N_BYTES(N) ((N) * 2)
76
77 #define DUMMY_STRINGOP_ALGS {libcall, {{-1, libcall}}}
78
79 const
80 struct processor_costs ix86_size_cost = {/* costs for tuning for size */
81   COSTS_N_BYTES (2),                    /* cost of an add instruction */
82   COSTS_N_BYTES (3),                    /* cost of a lea instruction */
83   COSTS_N_BYTES (2),                    /* variable shift costs */
84   COSTS_N_BYTES (3),                    /* constant shift costs */
85   {COSTS_N_BYTES (3),                   /* cost of starting multiply for QI */
86    COSTS_N_BYTES (3),                   /*                               HI */
87    COSTS_N_BYTES (3),                   /*                               SI */
88    COSTS_N_BYTES (3),                   /*                               DI */
89    COSTS_N_BYTES (5)},                  /*                            other */
90   0,                                    /* cost of multiply per each bit set */
91   {COSTS_N_BYTES (3),                   /* cost of a divide/mod for QI */
92    COSTS_N_BYTES (3),                   /*                          HI */
93    COSTS_N_BYTES (3),                   /*                          SI */
94    COSTS_N_BYTES (3),                   /*                          DI */
95    COSTS_N_BYTES (5)},                  /*                       other */
96   COSTS_N_BYTES (3),                    /* cost of movsx */
97   COSTS_N_BYTES (3),                    /* cost of movzx */
98   0,                                    /* "large" insn */
99   2,                                    /* MOVE_RATIO */
100   2,                                    /* cost for loading QImode using movzbl */
101   {2, 2, 2},                            /* cost of loading integer registers
102                                            in QImode, HImode and SImode.
103                                            Relative to reg-reg move (2).  */
104   {2, 2, 2},                            /* cost of storing integer registers */
105   2,                                    /* cost of reg,reg fld/fst */
106   {2, 2, 2},                            /* cost of loading fp registers
107                                            in SFmode, DFmode and XFmode */
108   {2, 2, 2},                            /* cost of storing fp registers
109                                            in SFmode, DFmode and XFmode */
110   3,                                    /* cost of moving MMX register */
111   {3, 3},                               /* cost of loading MMX registers
112                                            in SImode and DImode */
113   {3, 3},                               /* cost of storing MMX registers
114                                            in SImode and DImode */
115   3,                                    /* cost of moving SSE register */
116   {3, 3, 3},                            /* cost of loading SSE registers
117                                            in SImode, DImode and TImode */
118   {3, 3, 3},                            /* cost of storing SSE registers
119                                            in SImode, DImode and TImode */
120   3,                                    /* MMX or SSE register to integer */
121   0,                                    /* size of l1 cache  */
122   0,                                    /* size of l2 cache  */
123   0,                                    /* size of prefetch block */
124   0,                                    /* number of parallel prefetches */
125   2,                                    /* Branch cost */
126   COSTS_N_BYTES (2),                    /* cost of FADD and FSUB insns.  */
127   COSTS_N_BYTES (2),                    /* cost of FMUL instruction.  */
128   COSTS_N_BYTES (2),                    /* cost of FDIV instruction.  */
129   COSTS_N_BYTES (2),                    /* cost of FABS instruction.  */
130   COSTS_N_BYTES (2),                    /* cost of FCHS instruction.  */
131   COSTS_N_BYTES (2),                    /* cost of FSQRT instruction.  */
132   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
133    {rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}}},
134   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
135    {rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}}},
136   1,                                    /* scalar_stmt_cost.  */
137   1,                                    /* scalar load_cost.  */
138   1,                                    /* scalar_store_cost.  */
139   1,                                    /* vec_stmt_cost.  */
140   1,                                    /* vec_to_scalar_cost.  */
141   1,                                    /* scalar_to_vec_cost.  */
142   1,                                    /* vec_align_load_cost.  */
143   1,                                    /* vec_unalign_load_cost.  */
144   1,                                    /* vec_store_cost.  */
145   1,                                    /* cond_taken_branch_cost.  */
146   1,                                    /* cond_not_taken_branch_cost.  */
147 };
148
149 /* Processor costs (relative to an add) */
150 static const
151 struct processor_costs i386_cost = {    /* 386 specific costs */
152   COSTS_N_INSNS (1),                    /* cost of an add instruction */
153   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
154   COSTS_N_INSNS (3),                    /* variable shift costs */
155   COSTS_N_INSNS (2),                    /* constant shift costs */
156   {COSTS_N_INSNS (6),                   /* cost of starting multiply for QI */
157    COSTS_N_INSNS (6),                   /*                               HI */
158    COSTS_N_INSNS (6),                   /*                               SI */
159    COSTS_N_INSNS (6),                   /*                               DI */
160    COSTS_N_INSNS (6)},                  /*                               other */
161   COSTS_N_INSNS (1),                    /* cost of multiply per each bit set */
162   {COSTS_N_INSNS (23),                  /* cost of a divide/mod for QI */
163    COSTS_N_INSNS (23),                  /*                          HI */
164    COSTS_N_INSNS (23),                  /*                          SI */
165    COSTS_N_INSNS (23),                  /*                          DI */
166    COSTS_N_INSNS (23)},                 /*                          other */
167   COSTS_N_INSNS (3),                    /* cost of movsx */
168   COSTS_N_INSNS (2),                    /* cost of movzx */
169   15,                                   /* "large" insn */
170   3,                                    /* MOVE_RATIO */
171   4,                                    /* cost for loading QImode using movzbl */
172   {2, 4, 2},                            /* cost of loading integer registers
173                                            in QImode, HImode and SImode.
174                                            Relative to reg-reg move (2).  */
175   {2, 4, 2},                            /* cost of storing integer registers */
176   2,                                    /* cost of reg,reg fld/fst */
177   {8, 8, 8},                            /* cost of loading fp registers
178                                            in SFmode, DFmode and XFmode */
179   {8, 8, 8},                            /* cost of storing fp registers
180                                            in SFmode, DFmode and XFmode */
181   2,                                    /* cost of moving MMX register */
182   {4, 8},                               /* cost of loading MMX registers
183                                            in SImode and DImode */
184   {4, 8},                               /* cost of storing MMX registers
185                                            in SImode and DImode */
186   2,                                    /* cost of moving SSE register */
187   {4, 8, 16},                           /* cost of loading SSE registers
188                                            in SImode, DImode and TImode */
189   {4, 8, 16},                           /* cost of storing SSE registers
190                                            in SImode, DImode and TImode */
191   3,                                    /* MMX or SSE register to integer */
192   0,                                    /* size of l1 cache  */
193   0,                                    /* size of l2 cache  */
194   0,                                    /* size of prefetch block */
195   0,                                    /* number of parallel prefetches */
196   1,                                    /* Branch cost */
197   COSTS_N_INSNS (23),                   /* cost of FADD and FSUB insns.  */
198   COSTS_N_INSNS (27),                   /* cost of FMUL instruction.  */
199   COSTS_N_INSNS (88),                   /* cost of FDIV instruction.  */
200   COSTS_N_INSNS (22),                   /* cost of FABS instruction.  */
201   COSTS_N_INSNS (24),                   /* cost of FCHS instruction.  */
202   COSTS_N_INSNS (122),                  /* cost of FSQRT instruction.  */
203   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
204    DUMMY_STRINGOP_ALGS},
205   {{rep_prefix_1_byte, {{-1, rep_prefix_1_byte}}},
206    DUMMY_STRINGOP_ALGS},
207   1,                                    /* scalar_stmt_cost.  */
208   1,                                    /* scalar load_cost.  */
209   1,                                    /* scalar_store_cost.  */
210   1,                                    /* vec_stmt_cost.  */
211   1,                                    /* vec_to_scalar_cost.  */
212   1,                                    /* scalar_to_vec_cost.  */
213   1,                                    /* vec_align_load_cost.  */
214   2,                                    /* vec_unalign_load_cost.  */
215   1,                                    /* vec_store_cost.  */
216   3,                                    /* cond_taken_branch_cost.  */
217   1,                                    /* cond_not_taken_branch_cost.  */
218 };
219
220 static const
221 struct processor_costs i486_cost = {    /* 486 specific costs */
222   COSTS_N_INSNS (1),                    /* cost of an add instruction */
223   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
224   COSTS_N_INSNS (3),                    /* variable shift costs */
225   COSTS_N_INSNS (2),                    /* constant shift costs */
226   {COSTS_N_INSNS (12),                  /* cost of starting multiply for QI */
227    COSTS_N_INSNS (12),                  /*                               HI */
228    COSTS_N_INSNS (12),                  /*                               SI */
229    COSTS_N_INSNS (12),                  /*                               DI */
230    COSTS_N_INSNS (12)},                 /*                               other */
231   1,                                    /* cost of multiply per each bit set */
232   {COSTS_N_INSNS (40),                  /* cost of a divide/mod for QI */
233    COSTS_N_INSNS (40),                  /*                          HI */
234    COSTS_N_INSNS (40),                  /*                          SI */
235    COSTS_N_INSNS (40),                  /*                          DI */
236    COSTS_N_INSNS (40)},                 /*                          other */
237   COSTS_N_INSNS (3),                    /* cost of movsx */
238   COSTS_N_INSNS (2),                    /* cost of movzx */
239   15,                                   /* "large" insn */
240   3,                                    /* MOVE_RATIO */
241   4,                                    /* cost for loading QImode using movzbl */
242   {2, 4, 2},                            /* cost of loading integer registers
243                                            in QImode, HImode and SImode.
244                                            Relative to reg-reg move (2).  */
245   {2, 4, 2},                            /* cost of storing integer registers */
246   2,                                    /* cost of reg,reg fld/fst */
247   {8, 8, 8},                            /* cost of loading fp registers
248                                            in SFmode, DFmode and XFmode */
249   {8, 8, 8},                            /* cost of storing fp registers
250                                            in SFmode, DFmode and XFmode */
251   2,                                    /* cost of moving MMX register */
252   {4, 8},                               /* cost of loading MMX registers
253                                            in SImode and DImode */
254   {4, 8},                               /* cost of storing MMX registers
255                                            in SImode and DImode */
256   2,                                    /* cost of moving SSE register */
257   {4, 8, 16},                           /* cost of loading SSE registers
258                                            in SImode, DImode and TImode */
259   {4, 8, 16},                           /* cost of storing SSE registers
260                                            in SImode, DImode and TImode */
261   3,                                    /* MMX or SSE register to integer */
262   4,                                    /* size of l1 cache.  486 has 8kB cache
263                                            shared for code and data, so 4kB is
264                                            not really precise.  */
265   4,                                    /* size of l2 cache  */
266   0,                                    /* size of prefetch block */
267   0,                                    /* number of parallel prefetches */
268   1,                                    /* Branch cost */
269   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
270   COSTS_N_INSNS (16),                   /* cost of FMUL instruction.  */
271   COSTS_N_INSNS (73),                   /* cost of FDIV instruction.  */
272   COSTS_N_INSNS (3),                    /* cost of FABS instruction.  */
273   COSTS_N_INSNS (3),                    /* cost of FCHS instruction.  */
274   COSTS_N_INSNS (83),                   /* cost of FSQRT instruction.  */
275   {{rep_prefix_4_byte, {{-1, rep_prefix_4_byte}}},
276    DUMMY_STRINGOP_ALGS},
277   {{rep_prefix_4_byte, {{-1, rep_prefix_4_byte}}},
278    DUMMY_STRINGOP_ALGS},
279   1,                                    /* scalar_stmt_cost.  */
280   1,                                    /* scalar load_cost.  */
281   1,                                    /* scalar_store_cost.  */
282   1,                                    /* vec_stmt_cost.  */
283   1,                                    /* vec_to_scalar_cost.  */
284   1,                                    /* scalar_to_vec_cost.  */
285   1,                                    /* vec_align_load_cost.  */
286   2,                                    /* vec_unalign_load_cost.  */
287   1,                                    /* vec_store_cost.  */
288   3,                                    /* cond_taken_branch_cost.  */
289   1,                                    /* cond_not_taken_branch_cost.  */
290 };
291
292 static const
293 struct processor_costs pentium_cost = {
294   COSTS_N_INSNS (1),                    /* cost of an add instruction */
295   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
296   COSTS_N_INSNS (4),                    /* variable shift costs */
297   COSTS_N_INSNS (1),                    /* constant shift costs */
298   {COSTS_N_INSNS (11),                  /* cost of starting multiply for QI */
299    COSTS_N_INSNS (11),                  /*                               HI */
300    COSTS_N_INSNS (11),                  /*                               SI */
301    COSTS_N_INSNS (11),                  /*                               DI */
302    COSTS_N_INSNS (11)},                 /*                               other */
303   0,                                    /* cost of multiply per each bit set */
304   {COSTS_N_INSNS (25),                  /* cost of a divide/mod for QI */
305    COSTS_N_INSNS (25),                  /*                          HI */
306    COSTS_N_INSNS (25),                  /*                          SI */
307    COSTS_N_INSNS (25),                  /*                          DI */
308    COSTS_N_INSNS (25)},                 /*                          other */
309   COSTS_N_INSNS (3),                    /* cost of movsx */
310   COSTS_N_INSNS (2),                    /* cost of movzx */
311   8,                                    /* "large" insn */
312   6,                                    /* MOVE_RATIO */
313   6,                                    /* cost for loading QImode using movzbl */
314   {2, 4, 2},                            /* cost of loading integer registers
315                                            in QImode, HImode and SImode.
316                                            Relative to reg-reg move (2).  */
317   {2, 4, 2},                            /* cost of storing integer registers */
318   2,                                    /* cost of reg,reg fld/fst */
319   {2, 2, 6},                            /* cost of loading fp registers
320                                            in SFmode, DFmode and XFmode */
321   {4, 4, 6},                            /* cost of storing fp registers
322                                            in SFmode, DFmode and XFmode */
323   8,                                    /* cost of moving MMX register */
324   {8, 8},                               /* cost of loading MMX registers
325                                            in SImode and DImode */
326   {8, 8},                               /* cost of storing MMX registers
327                                            in SImode and DImode */
328   2,                                    /* cost of moving SSE register */
329   {4, 8, 16},                           /* cost of loading SSE registers
330                                            in SImode, DImode and TImode */
331   {4, 8, 16},                           /* cost of storing SSE registers
332                                            in SImode, DImode and TImode */
333   3,                                    /* MMX or SSE register to integer */
334   8,                                    /* size of l1 cache.  */
335   8,                                    /* size of l2 cache  */
336   0,                                    /* size of prefetch block */
337   0,                                    /* number of parallel prefetches */
338   2,                                    /* Branch cost */
339   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
340   COSTS_N_INSNS (3),                    /* cost of FMUL instruction.  */
341   COSTS_N_INSNS (39),                   /* cost of FDIV instruction.  */
342   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
343   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
344   COSTS_N_INSNS (70),                   /* cost of FSQRT instruction.  */
345   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
346    DUMMY_STRINGOP_ALGS},
347   {{libcall, {{-1, rep_prefix_4_byte}}},
348    DUMMY_STRINGOP_ALGS},
349   1,                                    /* scalar_stmt_cost.  */
350   1,                                    /* scalar load_cost.  */
351   1,                                    /* scalar_store_cost.  */
352   1,                                    /* vec_stmt_cost.  */
353   1,                                    /* vec_to_scalar_cost.  */
354   1,                                    /* scalar_to_vec_cost.  */
355   1,                                    /* vec_align_load_cost.  */
356   2,                                    /* vec_unalign_load_cost.  */
357   1,                                    /* vec_store_cost.  */
358   3,                                    /* cond_taken_branch_cost.  */
359   1,                                    /* cond_not_taken_branch_cost.  */
360 };
361
362 static const
363 struct processor_costs pentiumpro_cost = {
364   COSTS_N_INSNS (1),                    /* cost of an add instruction */
365   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
366   COSTS_N_INSNS (1),                    /* variable shift costs */
367   COSTS_N_INSNS (1),                    /* constant shift costs */
368   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
369    COSTS_N_INSNS (4),                   /*                               HI */
370    COSTS_N_INSNS (4),                   /*                               SI */
371    COSTS_N_INSNS (4),                   /*                               DI */
372    COSTS_N_INSNS (4)},                  /*                               other */
373   0,                                    /* cost of multiply per each bit set */
374   {COSTS_N_INSNS (17),                  /* cost of a divide/mod for QI */
375    COSTS_N_INSNS (17),                  /*                          HI */
376    COSTS_N_INSNS (17),                  /*                          SI */
377    COSTS_N_INSNS (17),                  /*                          DI */
378    COSTS_N_INSNS (17)},                 /*                          other */
379   COSTS_N_INSNS (1),                    /* cost of movsx */
380   COSTS_N_INSNS (1),                    /* cost of movzx */
381   8,                                    /* "large" insn */
382   6,                                    /* MOVE_RATIO */
383   2,                                    /* cost for loading QImode using movzbl */
384   {4, 4, 4},                            /* cost of loading integer registers
385                                            in QImode, HImode and SImode.
386                                            Relative to reg-reg move (2).  */
387   {2, 2, 2},                            /* cost of storing integer registers */
388   2,                                    /* cost of reg,reg fld/fst */
389   {2, 2, 6},                            /* cost of loading fp registers
390                                            in SFmode, DFmode and XFmode */
391   {4, 4, 6},                            /* cost of storing fp registers
392                                            in SFmode, DFmode and XFmode */
393   2,                                    /* cost of moving MMX register */
394   {2, 2},                               /* cost of loading MMX registers
395                                            in SImode and DImode */
396   {2, 2},                               /* cost of storing MMX registers
397                                            in SImode and DImode */
398   2,                                    /* cost of moving SSE register */
399   {2, 2, 8},                            /* cost of loading SSE registers
400                                            in SImode, DImode and TImode */
401   {2, 2, 8},                            /* cost of storing SSE registers
402                                            in SImode, DImode and TImode */
403   3,                                    /* MMX or SSE register to integer */
404   8,                                    /* size of l1 cache.  */
405   256,                                  /* size of l2 cache  */
406   32,                                   /* size of prefetch block */
407   6,                                    /* number of parallel prefetches */
408   2,                                    /* Branch cost */
409   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
410   COSTS_N_INSNS (5),                    /* cost of FMUL instruction.  */
411   COSTS_N_INSNS (56),                   /* cost of FDIV instruction.  */
412   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
413   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
414   COSTS_N_INSNS (56),                   /* cost of FSQRT instruction.  */
415   /* PentiumPro has optimized rep instructions for blocks aligned by 8 bytes (we ensure
416      the alignment).  For small blocks inline loop is still a noticeable win, for bigger
417      blocks either rep movsl or rep movsb is way to go.  Rep movsb has apparently
418      more expensive startup time in CPU, but after 4K the difference is down in the noise.
419    */
420   {{rep_prefix_4_byte, {{128, loop}, {1024, unrolled_loop},
421                         {8192, rep_prefix_4_byte}, {-1, rep_prefix_1_byte}}},
422    DUMMY_STRINGOP_ALGS},
423   {{rep_prefix_4_byte, {{1024, unrolled_loop},
424                         {8192, rep_prefix_4_byte}, {-1, libcall}}},
425    DUMMY_STRINGOP_ALGS},
426   1,                                    /* scalar_stmt_cost.  */
427   1,                                    /* scalar load_cost.  */
428   1,                                    /* scalar_store_cost.  */
429   1,                                    /* vec_stmt_cost.  */
430   1,                                    /* vec_to_scalar_cost.  */
431   1,                                    /* scalar_to_vec_cost.  */
432   1,                                    /* vec_align_load_cost.  */
433   2,                                    /* vec_unalign_load_cost.  */
434   1,                                    /* vec_store_cost.  */
435   3,                                    /* cond_taken_branch_cost.  */
436   1,                                    /* cond_not_taken_branch_cost.  */
437 };
438
439 static const
440 struct processor_costs geode_cost = {
441   COSTS_N_INSNS (1),                    /* cost of an add instruction */
442   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
443   COSTS_N_INSNS (2),                    /* variable shift costs */
444   COSTS_N_INSNS (1),                    /* constant shift costs */
445   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
446    COSTS_N_INSNS (4),                   /*                               HI */
447    COSTS_N_INSNS (7),                   /*                               SI */
448    COSTS_N_INSNS (7),                   /*                               DI */
449    COSTS_N_INSNS (7)},                  /*                               other */
450   0,                                    /* cost of multiply per each bit set */
451   {COSTS_N_INSNS (15),                  /* cost of a divide/mod for QI */
452    COSTS_N_INSNS (23),                  /*                          HI */
453    COSTS_N_INSNS (39),                  /*                          SI */
454    COSTS_N_INSNS (39),                  /*                          DI */
455    COSTS_N_INSNS (39)},                 /*                          other */
456   COSTS_N_INSNS (1),                    /* cost of movsx */
457   COSTS_N_INSNS (1),                    /* cost of movzx */
458   8,                                    /* "large" insn */
459   4,                                    /* MOVE_RATIO */
460   1,                                    /* cost for loading QImode using movzbl */
461   {1, 1, 1},                            /* cost of loading integer registers
462                                            in QImode, HImode and SImode.
463                                            Relative to reg-reg move (2).  */
464   {1, 1, 1},                            /* cost of storing integer registers */
465   1,                                    /* cost of reg,reg fld/fst */
466   {1, 1, 1},                            /* cost of loading fp registers
467                                            in SFmode, DFmode and XFmode */
468   {4, 6, 6},                            /* cost of storing fp registers
469                                            in SFmode, DFmode and XFmode */
470
471   1,                                    /* cost of moving MMX register */
472   {1, 1},                               /* cost of loading MMX registers
473                                            in SImode and DImode */
474   {1, 1},                               /* cost of storing MMX registers
475                                            in SImode and DImode */
476   1,                                    /* cost of moving SSE register */
477   {1, 1, 1},                            /* cost of loading SSE registers
478                                            in SImode, DImode and TImode */
479   {1, 1, 1},                            /* cost of storing SSE registers
480                                            in SImode, DImode and TImode */
481   1,                                    /* MMX or SSE register to integer */
482   64,                                   /* size of l1 cache.  */
483   128,                                  /* size of l2 cache.  */
484   32,                                   /* size of prefetch block */
485   1,                                    /* number of parallel prefetches */
486   1,                                    /* Branch cost */
487   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
488   COSTS_N_INSNS (11),                   /* cost of FMUL instruction.  */
489   COSTS_N_INSNS (47),                   /* cost of FDIV instruction.  */
490   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
491   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
492   COSTS_N_INSNS (54),                   /* cost of FSQRT instruction.  */
493   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
494    DUMMY_STRINGOP_ALGS},
495   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
496    DUMMY_STRINGOP_ALGS},
497   1,                                    /* scalar_stmt_cost.  */
498   1,                                    /* scalar load_cost.  */
499   1,                                    /* scalar_store_cost.  */
500   1,                                    /* vec_stmt_cost.  */
501   1,                                    /* vec_to_scalar_cost.  */
502   1,                                    /* scalar_to_vec_cost.  */
503   1,                                    /* vec_align_load_cost.  */
504   2,                                    /* vec_unalign_load_cost.  */
505   1,                                    /* vec_store_cost.  */
506   3,                                    /* cond_taken_branch_cost.  */
507   1,                                    /* cond_not_taken_branch_cost.  */
508 };
509
510 static const
511 struct processor_costs k6_cost = {
512   COSTS_N_INSNS (1),                    /* cost of an add instruction */
513   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
514   COSTS_N_INSNS (1),                    /* variable shift costs */
515   COSTS_N_INSNS (1),                    /* constant shift costs */
516   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
517    COSTS_N_INSNS (3),                   /*                               HI */
518    COSTS_N_INSNS (3),                   /*                               SI */
519    COSTS_N_INSNS (3),                   /*                               DI */
520    COSTS_N_INSNS (3)},                  /*                               other */
521   0,                                    /* cost of multiply per each bit set */
522   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
523    COSTS_N_INSNS (18),                  /*                          HI */
524    COSTS_N_INSNS (18),                  /*                          SI */
525    COSTS_N_INSNS (18),                  /*                          DI */
526    COSTS_N_INSNS (18)},                 /*                          other */
527   COSTS_N_INSNS (2),                    /* cost of movsx */
528   COSTS_N_INSNS (2),                    /* cost of movzx */
529   8,                                    /* "large" insn */
530   4,                                    /* MOVE_RATIO */
531   3,                                    /* cost for loading QImode using movzbl */
532   {4, 5, 4},                            /* cost of loading integer registers
533                                            in QImode, HImode and SImode.
534                                            Relative to reg-reg move (2).  */
535   {2, 3, 2},                            /* cost of storing integer registers */
536   4,                                    /* cost of reg,reg fld/fst */
537   {6, 6, 6},                            /* cost of loading fp registers
538                                            in SFmode, DFmode and XFmode */
539   {4, 4, 4},                            /* cost of storing fp registers
540                                            in SFmode, DFmode and XFmode */
541   2,                                    /* cost of moving MMX register */
542   {2, 2},                               /* cost of loading MMX registers
543                                            in SImode and DImode */
544   {2, 2},                               /* cost of storing MMX registers
545                                            in SImode and DImode */
546   2,                                    /* cost of moving SSE register */
547   {2, 2, 8},                            /* cost of loading SSE registers
548                                            in SImode, DImode and TImode */
549   {2, 2, 8},                            /* cost of storing SSE registers
550                                            in SImode, DImode and TImode */
551   6,                                    /* MMX or SSE register to integer */
552   32,                                   /* size of l1 cache.  */
553   32,                                   /* size of l2 cache.  Some models
554                                            have integrated l2 cache, but
555                                            optimizing for k6 is not important
556                                            enough to worry about that.  */
557   32,                                   /* size of prefetch block */
558   1,                                    /* number of parallel prefetches */
559   1,                                    /* Branch cost */
560   COSTS_N_INSNS (2),                    /* cost of FADD and FSUB insns.  */
561   COSTS_N_INSNS (2),                    /* cost of FMUL instruction.  */
562   COSTS_N_INSNS (56),                   /* cost of FDIV instruction.  */
563   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
564   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
565   COSTS_N_INSNS (56),                   /* cost of FSQRT instruction.  */
566   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
567    DUMMY_STRINGOP_ALGS},
568   {{libcall, {{256, rep_prefix_4_byte}, {-1, libcall}}},
569    DUMMY_STRINGOP_ALGS},
570   1,                                    /* scalar_stmt_cost.  */
571   1,                                    /* scalar load_cost.  */
572   1,                                    /* scalar_store_cost.  */
573   1,                                    /* vec_stmt_cost.  */
574   1,                                    /* vec_to_scalar_cost.  */
575   1,                                    /* scalar_to_vec_cost.  */
576   1,                                    /* vec_align_load_cost.  */
577   2,                                    /* vec_unalign_load_cost.  */
578   1,                                    /* vec_store_cost.  */
579   3,                                    /* cond_taken_branch_cost.  */
580   1,                                    /* cond_not_taken_branch_cost.  */
581 };
582
583 static const
584 struct processor_costs athlon_cost = {
585   COSTS_N_INSNS (1),                    /* cost of an add instruction */
586   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
587   COSTS_N_INSNS (1),                    /* variable shift costs */
588   COSTS_N_INSNS (1),                    /* constant shift costs */
589   {COSTS_N_INSNS (5),                   /* cost of starting multiply for QI */
590    COSTS_N_INSNS (5),                   /*                               HI */
591    COSTS_N_INSNS (5),                   /*                               SI */
592    COSTS_N_INSNS (5),                   /*                               DI */
593    COSTS_N_INSNS (5)},                  /*                               other */
594   0,                                    /* cost of multiply per each bit set */
595   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
596    COSTS_N_INSNS (26),                  /*                          HI */
597    COSTS_N_INSNS (42),                  /*                          SI */
598    COSTS_N_INSNS (74),                  /*                          DI */
599    COSTS_N_INSNS (74)},                 /*                          other */
600   COSTS_N_INSNS (1),                    /* cost of movsx */
601   COSTS_N_INSNS (1),                    /* cost of movzx */
602   8,                                    /* "large" insn */
603   9,                                    /* MOVE_RATIO */
604   4,                                    /* cost for loading QImode using movzbl */
605   {3, 4, 3},                            /* cost of loading integer registers
606                                            in QImode, HImode and SImode.
607                                            Relative to reg-reg move (2).  */
608   {3, 4, 3},                            /* cost of storing integer registers */
609   4,                                    /* cost of reg,reg fld/fst */
610   {4, 4, 12},                           /* cost of loading fp registers
611                                            in SFmode, DFmode and XFmode */
612   {6, 6, 8},                            /* cost of storing fp registers
613                                            in SFmode, DFmode and XFmode */
614   2,                                    /* cost of moving MMX register */
615   {4, 4},                               /* cost of loading MMX registers
616                                            in SImode and DImode */
617   {4, 4},                               /* cost of storing MMX registers
618                                            in SImode and DImode */
619   2,                                    /* cost of moving SSE register */
620   {4, 4, 6},                            /* cost of loading SSE registers
621                                            in SImode, DImode and TImode */
622   {4, 4, 5},                            /* cost of storing SSE registers
623                                            in SImode, DImode and TImode */
624   5,                                    /* MMX or SSE register to integer */
625   64,                                   /* size of l1 cache.  */
626   256,                                  /* size of l2 cache.  */
627   64,                                   /* size of prefetch block */
628   6,                                    /* number of parallel prefetches */
629   5,                                    /* Branch cost */
630   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
631   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
632   COSTS_N_INSNS (24),                   /* cost of FDIV instruction.  */
633   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
634   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
635   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
636   /* For some reason, Athlon deals better with REP prefix (relative to loops)
637      compared to K8. Alignment becomes important after 8 bytes for memcpy and
638      128 bytes for memset.  */
639   {{libcall, {{2048, rep_prefix_4_byte}, {-1, libcall}}},
640    DUMMY_STRINGOP_ALGS},
641   {{libcall, {{2048, rep_prefix_4_byte}, {-1, libcall}}},
642    DUMMY_STRINGOP_ALGS},
643   1,                                    /* scalar_stmt_cost.  */
644   1,                                    /* scalar load_cost.  */
645   1,                                    /* scalar_store_cost.  */
646   1,                                    /* vec_stmt_cost.  */
647   1,                                    /* vec_to_scalar_cost.  */
648   1,                                    /* scalar_to_vec_cost.  */
649   1,                                    /* vec_align_load_cost.  */
650   2,                                    /* vec_unalign_load_cost.  */
651   1,                                    /* vec_store_cost.  */
652   3,                                    /* cond_taken_branch_cost.  */
653   1,                                    /* cond_not_taken_branch_cost.  */
654 };
655
656 static const
657 struct processor_costs k8_cost = {
658   COSTS_N_INSNS (1),                    /* cost of an add instruction */
659   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
660   COSTS_N_INSNS (1),                    /* variable shift costs */
661   COSTS_N_INSNS (1),                    /* constant shift costs */
662   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
663    COSTS_N_INSNS (4),                   /*                               HI */
664    COSTS_N_INSNS (3),                   /*                               SI */
665    COSTS_N_INSNS (4),                   /*                               DI */
666    COSTS_N_INSNS (5)},                  /*                               other */
667   0,                                    /* cost of multiply per each bit set */
668   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
669    COSTS_N_INSNS (26),                  /*                          HI */
670    COSTS_N_INSNS (42),                  /*                          SI */
671    COSTS_N_INSNS (74),                  /*                          DI */
672    COSTS_N_INSNS (74)},                 /*                          other */
673   COSTS_N_INSNS (1),                    /* cost of movsx */
674   COSTS_N_INSNS (1),                    /* cost of movzx */
675   8,                                    /* "large" insn */
676   9,                                    /* MOVE_RATIO */
677   4,                                    /* cost for loading QImode using movzbl */
678   {3, 4, 3},                            /* cost of loading integer registers
679                                            in QImode, HImode and SImode.
680                                            Relative to reg-reg move (2).  */
681   {3, 4, 3},                            /* cost of storing integer registers */
682   4,                                    /* cost of reg,reg fld/fst */
683   {4, 4, 12},                           /* cost of loading fp registers
684                                            in SFmode, DFmode and XFmode */
685   {6, 6, 8},                            /* cost of storing fp registers
686                                            in SFmode, DFmode and XFmode */
687   2,                                    /* cost of moving MMX register */
688   {3, 3},                               /* cost of loading MMX registers
689                                            in SImode and DImode */
690   {4, 4},                               /* cost of storing MMX registers
691                                            in SImode and DImode */
692   2,                                    /* cost of moving SSE register */
693   {4, 3, 6},                            /* cost of loading SSE registers
694                                            in SImode, DImode and TImode */
695   {4, 4, 5},                            /* cost of storing SSE registers
696                                            in SImode, DImode and TImode */
697   5,                                    /* MMX or SSE register to integer */
698   64,                                   /* size of l1 cache.  */
699   512,                                  /* size of l2 cache.  */
700   64,                                   /* size of prefetch block */
701   /* New AMD processors never drop prefetches; if they cannot be performed
702      immediately, they are queued.  We set number of simultaneous prefetches
703      to a large constant to reflect this (it probably is not a good idea not
704      to limit number of prefetches at all, as their execution also takes some
705      time).  */
706   100,                                  /* number of parallel prefetches */
707   3,                                    /* Branch cost */
708   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
709   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
710   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
711   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
712   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
713   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
714   /* K8 has optimized REP instruction for medium sized blocks, but for very small
715      blocks it is better to use loop. For large blocks, libcall can do
716      nontemporary accesses and beat inline considerably.  */
717   {{libcall, {{6, loop}, {14, unrolled_loop}, {-1, rep_prefix_4_byte}}},
718    {libcall, {{16, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
719   {{libcall, {{8, loop}, {24, unrolled_loop},
720               {2048, rep_prefix_4_byte}, {-1, libcall}}},
721    {libcall, {{48, unrolled_loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
722   4,                                    /* scalar_stmt_cost.  */
723   2,                                    /* scalar load_cost.  */
724   2,                                    /* scalar_store_cost.  */
725   5,                                    /* vec_stmt_cost.  */
726   0,                                    /* vec_to_scalar_cost.  */
727   2,                                    /* scalar_to_vec_cost.  */
728   2,                                    /* vec_align_load_cost.  */
729   3,                                    /* vec_unalign_load_cost.  */
730   3,                                    /* vec_store_cost.  */
731   3,                                    /* cond_taken_branch_cost.  */
732   2,                                    /* cond_not_taken_branch_cost.  */
733 };
734
735 struct processor_costs amdfam10_cost = {
736   COSTS_N_INSNS (1),                    /* cost of an add instruction */
737   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
738   COSTS_N_INSNS (1),                    /* variable shift costs */
739   COSTS_N_INSNS (1),                    /* constant shift costs */
740   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
741    COSTS_N_INSNS (4),                   /*                               HI */
742    COSTS_N_INSNS (3),                   /*                               SI */
743    COSTS_N_INSNS (4),                   /*                               DI */
744    COSTS_N_INSNS (5)},                  /*                               other */
745   0,                                    /* cost of multiply per each bit set */
746   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
747    COSTS_N_INSNS (35),                  /*                          HI */
748    COSTS_N_INSNS (51),                  /*                          SI */
749    COSTS_N_INSNS (83),                  /*                          DI */
750    COSTS_N_INSNS (83)},                 /*                          other */
751   COSTS_N_INSNS (1),                    /* cost of movsx */
752   COSTS_N_INSNS (1),                    /* cost of movzx */
753   8,                                    /* "large" insn */
754   9,                                    /* MOVE_RATIO */
755   4,                                    /* cost for loading QImode using movzbl */
756   {3, 4, 3},                            /* cost of loading integer registers
757                                            in QImode, HImode and SImode.
758                                            Relative to reg-reg move (2).  */
759   {3, 4, 3},                            /* cost of storing integer registers */
760   4,                                    /* cost of reg,reg fld/fst */
761   {4, 4, 12},                           /* cost of loading fp registers
762                                            in SFmode, DFmode and XFmode */
763   {6, 6, 8},                            /* cost of storing fp registers
764                                            in SFmode, DFmode and XFmode */
765   2,                                    /* cost of moving MMX register */
766   {3, 3},                               /* cost of loading MMX registers
767                                            in SImode and DImode */
768   {4, 4},                               /* cost of storing MMX registers
769                                            in SImode and DImode */
770   2,                                    /* cost of moving SSE register */
771   {4, 4, 3},                            /* cost of loading SSE registers
772                                            in SImode, DImode and TImode */
773   {4, 4, 5},                            /* cost of storing SSE registers
774                                            in SImode, DImode and TImode */
775   3,                                    /* MMX or SSE register to integer */
776                                         /* On K8
777                                             MOVD reg64, xmmreg  Double  FSTORE 4
778                                             MOVD reg32, xmmreg  Double  FSTORE 4
779                                            On AMDFAM10
780                                             MOVD reg64, xmmreg  Double  FADD 3
781                                                                 1/1  1/1
782                                             MOVD reg32, xmmreg  Double  FADD 3
783                                                                 1/1  1/1 */
784   64,                                   /* size of l1 cache.  */
785   512,                                  /* size of l2 cache.  */
786   64,                                   /* size of prefetch block */
787   /* New AMD processors never drop prefetches; if they cannot be performed
788      immediately, they are queued.  We set number of simultaneous prefetches
789      to a large constant to reflect this (it probably is not a good idea not
790      to limit number of prefetches at all, as their execution also takes some
791      time).  */
792   100,                                  /* number of parallel prefetches */
793   2,                                    /* Branch cost */
794   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
795   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
796   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
797   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
798   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
799   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
800
801   /* AMDFAM10 has optimized REP instruction for medium sized blocks, but for
802      very small blocks it is better to use loop. For large blocks, libcall can
803      do nontemporary accesses and beat inline considerably.  */
804   {{libcall, {{6, loop}, {14, unrolled_loop}, {-1, rep_prefix_4_byte}}},
805    {libcall, {{16, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
806   {{libcall, {{8, loop}, {24, unrolled_loop},
807               {2048, rep_prefix_4_byte}, {-1, libcall}}},
808    {libcall, {{48, unrolled_loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
809   4,                                    /* scalar_stmt_cost.  */
810   2,                                    /* scalar load_cost.  */
811   2,                                    /* scalar_store_cost.  */
812   6,                                    /* vec_stmt_cost.  */
813   0,                                    /* vec_to_scalar_cost.  */
814   2,                                    /* scalar_to_vec_cost.  */
815   2,                                    /* vec_align_load_cost.  */
816   2,                                    /* vec_unalign_load_cost.  */
817   2,                                    /* vec_store_cost.  */
818   2,                                    /* cond_taken_branch_cost.  */
819   1,                                    /* cond_not_taken_branch_cost.  */
820 };
821
822 static const
823 struct processor_costs pentium4_cost = {
824   COSTS_N_INSNS (1),                    /* cost of an add instruction */
825   COSTS_N_INSNS (3),                    /* cost of a lea instruction */
826   COSTS_N_INSNS (4),                    /* variable shift costs */
827   COSTS_N_INSNS (4),                    /* constant shift costs */
828   {COSTS_N_INSNS (15),                  /* cost of starting multiply for QI */
829    COSTS_N_INSNS (15),                  /*                               HI */
830    COSTS_N_INSNS (15),                  /*                               SI */
831    COSTS_N_INSNS (15),                  /*                               DI */
832    COSTS_N_INSNS (15)},                 /*                               other */
833   0,                                    /* cost of multiply per each bit set */
834   {COSTS_N_INSNS (56),                  /* cost of a divide/mod for QI */
835    COSTS_N_INSNS (56),                  /*                          HI */
836    COSTS_N_INSNS (56),                  /*                          SI */
837    COSTS_N_INSNS (56),                  /*                          DI */
838    COSTS_N_INSNS (56)},                 /*                          other */
839   COSTS_N_INSNS (1),                    /* cost of movsx */
840   COSTS_N_INSNS (1),                    /* cost of movzx */
841   16,                                   /* "large" insn */
842   6,                                    /* MOVE_RATIO */
843   2,                                    /* cost for loading QImode using movzbl */
844   {4, 5, 4},                            /* cost of loading integer registers
845                                            in QImode, HImode and SImode.
846                                            Relative to reg-reg move (2).  */
847   {2, 3, 2},                            /* cost of storing integer registers */
848   2,                                    /* cost of reg,reg fld/fst */
849   {2, 2, 6},                            /* cost of loading fp registers
850                                            in SFmode, DFmode and XFmode */
851   {4, 4, 6},                            /* cost of storing fp registers
852                                            in SFmode, DFmode and XFmode */
853   2,                                    /* cost of moving MMX register */
854   {2, 2},                               /* cost of loading MMX registers
855                                            in SImode and DImode */
856   {2, 2},                               /* cost of storing MMX registers
857                                            in SImode and DImode */
858   12,                                   /* cost of moving SSE register */
859   {12, 12, 12},                         /* cost of loading SSE registers
860                                            in SImode, DImode and TImode */
861   {2, 2, 8},                            /* cost of storing SSE registers
862                                            in SImode, DImode and TImode */
863   10,                                   /* MMX or SSE register to integer */
864   8,                                    /* size of l1 cache.  */
865   256,                                  /* size of l2 cache.  */
866   64,                                   /* size of prefetch block */
867   6,                                    /* number of parallel prefetches */
868   2,                                    /* Branch cost */
869   COSTS_N_INSNS (5),                    /* cost of FADD and FSUB insns.  */
870   COSTS_N_INSNS (7),                    /* cost of FMUL instruction.  */
871   COSTS_N_INSNS (43),                   /* cost of FDIV instruction.  */
872   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
873   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
874   COSTS_N_INSNS (43),                   /* cost of FSQRT instruction.  */
875   {{libcall, {{12, loop_1_byte}, {-1, rep_prefix_4_byte}}},
876    DUMMY_STRINGOP_ALGS},
877   {{libcall, {{6, loop_1_byte}, {48, loop}, {20480, rep_prefix_4_byte},
878    {-1, libcall}}},
879    DUMMY_STRINGOP_ALGS},
880   1,                                    /* scalar_stmt_cost.  */
881   1,                                    /* scalar load_cost.  */
882   1,                                    /* scalar_store_cost.  */
883   1,                                    /* vec_stmt_cost.  */
884   1,                                    /* vec_to_scalar_cost.  */
885   1,                                    /* scalar_to_vec_cost.  */
886   1,                                    /* vec_align_load_cost.  */
887   2,                                    /* vec_unalign_load_cost.  */
888   1,                                    /* vec_store_cost.  */
889   3,                                    /* cond_taken_branch_cost.  */
890   1,                                    /* cond_not_taken_branch_cost.  */
891 };
892
893 static const
894 struct processor_costs nocona_cost = {
895   COSTS_N_INSNS (1),                    /* cost of an add instruction */
896   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
897   COSTS_N_INSNS (1),                    /* variable shift costs */
898   COSTS_N_INSNS (1),                    /* constant shift costs */
899   {COSTS_N_INSNS (10),                  /* cost of starting multiply for QI */
900    COSTS_N_INSNS (10),                  /*                               HI */
901    COSTS_N_INSNS (10),                  /*                               SI */
902    COSTS_N_INSNS (10),                  /*                               DI */
903    COSTS_N_INSNS (10)},                 /*                               other */
904   0,                                    /* cost of multiply per each bit set */
905   {COSTS_N_INSNS (66),                  /* cost of a divide/mod for QI */
906    COSTS_N_INSNS (66),                  /*                          HI */
907    COSTS_N_INSNS (66),                  /*                          SI */
908    COSTS_N_INSNS (66),                  /*                          DI */
909    COSTS_N_INSNS (66)},                 /*                          other */
910   COSTS_N_INSNS (1),                    /* cost of movsx */
911   COSTS_N_INSNS (1),                    /* cost of movzx */
912   16,                                   /* "large" insn */
913   17,                                   /* MOVE_RATIO */
914   4,                                    /* cost for loading QImode using movzbl */
915   {4, 4, 4},                            /* cost of loading integer registers
916                                            in QImode, HImode and SImode.
917                                            Relative to reg-reg move (2).  */
918   {4, 4, 4},                            /* cost of storing integer registers */
919   3,                                    /* cost of reg,reg fld/fst */
920   {12, 12, 12},                         /* cost of loading fp registers
921                                            in SFmode, DFmode and XFmode */
922   {4, 4, 4},                            /* cost of storing fp registers
923                                            in SFmode, DFmode and XFmode */
924   6,                                    /* cost of moving MMX register */
925   {12, 12},                             /* cost of loading MMX registers
926                                            in SImode and DImode */
927   {12, 12},                             /* cost of storing MMX registers
928                                            in SImode and DImode */
929   6,                                    /* cost of moving SSE register */
930   {12, 12, 12},                         /* cost of loading SSE registers
931                                            in SImode, DImode and TImode */
932   {12, 12, 12},                         /* cost of storing SSE registers
933                                            in SImode, DImode and TImode */
934   8,                                    /* MMX or SSE register to integer */
935   8,                                    /* size of l1 cache.  */
936   1024,                                 /* size of l2 cache.  */
937   128,                                  /* size of prefetch block */
938   8,                                    /* number of parallel prefetches */
939   1,                                    /* Branch cost */
940   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
941   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
942   COSTS_N_INSNS (40),                   /* cost of FDIV instruction.  */
943   COSTS_N_INSNS (3),                    /* cost of FABS instruction.  */
944   COSTS_N_INSNS (3),                    /* cost of FCHS instruction.  */
945   COSTS_N_INSNS (44),                   /* cost of FSQRT instruction.  */
946   {{libcall, {{12, loop_1_byte}, {-1, rep_prefix_4_byte}}},
947    {libcall, {{32, loop}, {20000, rep_prefix_8_byte},
948               {100000, unrolled_loop}, {-1, libcall}}}},
949   {{libcall, {{6, loop_1_byte}, {48, loop}, {20480, rep_prefix_4_byte},
950    {-1, libcall}}},
951    {libcall, {{24, loop}, {64, unrolled_loop},
952               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
953   1,                                    /* scalar_stmt_cost.  */
954   1,                                    /* scalar load_cost.  */
955   1,                                    /* scalar_store_cost.  */
956   1,                                    /* vec_stmt_cost.  */
957   1,                                    /* vec_to_scalar_cost.  */
958   1,                                    /* scalar_to_vec_cost.  */
959   1,                                    /* vec_align_load_cost.  */
960   2,                                    /* vec_unalign_load_cost.  */
961   1,                                    /* vec_store_cost.  */
962   3,                                    /* cond_taken_branch_cost.  */
963   1,                                    /* cond_not_taken_branch_cost.  */
964 };
965
966 static const
967 struct processor_costs core2_cost = {
968   COSTS_N_INSNS (1),                    /* cost of an add instruction */
969   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
970   COSTS_N_INSNS (1),                    /* variable shift costs */
971   COSTS_N_INSNS (1),                    /* constant shift costs */
972   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
973    COSTS_N_INSNS (3),                   /*                               HI */
974    COSTS_N_INSNS (3),                   /*                               SI */
975    COSTS_N_INSNS (3),                   /*                               DI */
976    COSTS_N_INSNS (3)},                  /*                               other */
977   0,                                    /* cost of multiply per each bit set */
978   {COSTS_N_INSNS (22),                  /* cost of a divide/mod for QI */
979    COSTS_N_INSNS (22),                  /*                          HI */
980    COSTS_N_INSNS (22),                  /*                          SI */
981    COSTS_N_INSNS (22),                  /*                          DI */
982    COSTS_N_INSNS (22)},                 /*                          other */
983   COSTS_N_INSNS (1),                    /* cost of movsx */
984   COSTS_N_INSNS (1),                    /* cost of movzx */
985   8,                                    /* "large" insn */
986   16,                                   /* MOVE_RATIO */
987   2,                                    /* cost for loading QImode using movzbl */
988   {6, 6, 6},                            /* cost of loading integer registers
989                                            in QImode, HImode and SImode.
990                                            Relative to reg-reg move (2).  */
991   {4, 4, 4},                            /* cost of storing integer registers */
992   2,                                    /* cost of reg,reg fld/fst */
993   {6, 6, 6},                            /* cost of loading fp registers
994                                            in SFmode, DFmode and XFmode */
995   {4, 4, 4},                            /* cost of storing fp registers
996                                            in SFmode, DFmode and XFmode */
997   2,                                    /* cost of moving MMX register */
998   {6, 6},                               /* cost of loading MMX registers
999                                            in SImode and DImode */
1000   {4, 4},                               /* cost of storing MMX registers
1001                                            in SImode and DImode */
1002   2,                                    /* cost of moving SSE register */
1003   {6, 6, 6},                            /* cost of loading SSE registers
1004                                            in SImode, DImode and TImode */
1005   {4, 4, 4},                            /* cost of storing SSE registers
1006                                            in SImode, DImode and TImode */
1007   2,                                    /* MMX or SSE register to integer */
1008   32,                                   /* size of l1 cache.  */
1009   2048,                                 /* size of l2 cache.  */
1010   128,                                  /* size of prefetch block */
1011   8,                                    /* number of parallel prefetches */
1012   3,                                    /* Branch cost */
1013   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
1014   COSTS_N_INSNS (5),                    /* cost of FMUL instruction.  */
1015   COSTS_N_INSNS (32),                   /* cost of FDIV instruction.  */
1016   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
1017   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
1018   COSTS_N_INSNS (58),                   /* cost of FSQRT instruction.  */
1019   {{libcall, {{11, loop}, {-1, rep_prefix_4_byte}}},
1020    {libcall, {{32, loop}, {64, rep_prefix_4_byte},
1021               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1022   {{libcall, {{8, loop}, {15, unrolled_loop},
1023               {2048, rep_prefix_4_byte}, {-1, libcall}}},
1024    {libcall, {{24, loop}, {32, unrolled_loop},
1025               {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1026   1,                                    /* scalar_stmt_cost.  */
1027   1,                                    /* scalar load_cost.  */
1028   1,                                    /* scalar_store_cost.  */
1029   1,                                    /* vec_stmt_cost.  */
1030   1,                                    /* vec_to_scalar_cost.  */
1031   1,                                    /* scalar_to_vec_cost.  */
1032   1,                                    /* vec_align_load_cost.  */
1033   2,                                    /* vec_unalign_load_cost.  */
1034   1,                                    /* vec_store_cost.  */
1035   3,                                    /* cond_taken_branch_cost.  */
1036   1,                                    /* cond_not_taken_branch_cost.  */
1037 };
1038
1039 /* Generic64 should produce code tuned for Nocona and K8.  */
1040 static const
1041 struct processor_costs generic64_cost = {
1042   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1043   /* On all chips taken into consideration lea is 2 cycles and more.  With
1044      this cost however our current implementation of synth_mult results in
1045      use of unnecessary temporary registers causing regression on several
1046      SPECfp benchmarks.  */
1047   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1048   COSTS_N_INSNS (1),                    /* variable shift costs */
1049   COSTS_N_INSNS (1),                    /* constant shift costs */
1050   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1051    COSTS_N_INSNS (4),                   /*                               HI */
1052    COSTS_N_INSNS (3),                   /*                               SI */
1053    COSTS_N_INSNS (4),                   /*                               DI */
1054    COSTS_N_INSNS (2)},                  /*                               other */
1055   0,                                    /* cost of multiply per each bit set */
1056   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1057    COSTS_N_INSNS (26),                  /*                          HI */
1058    COSTS_N_INSNS (42),                  /*                          SI */
1059    COSTS_N_INSNS (74),                  /*                          DI */
1060    COSTS_N_INSNS (74)},                 /*                          other */
1061   COSTS_N_INSNS (1),                    /* cost of movsx */
1062   COSTS_N_INSNS (1),                    /* cost of movzx */
1063   8,                                    /* "large" insn */
1064   17,                                   /* MOVE_RATIO */
1065   4,                                    /* cost for loading QImode using movzbl */
1066   {4, 4, 4},                            /* cost of loading integer registers
1067                                            in QImode, HImode and SImode.
1068                                            Relative to reg-reg move (2).  */
1069   {4, 4, 4},                            /* cost of storing integer registers */
1070   4,                                    /* cost of reg,reg fld/fst */
1071   {12, 12, 12},                         /* cost of loading fp registers
1072                                            in SFmode, DFmode and XFmode */
1073   {6, 6, 8},                            /* cost of storing fp registers
1074                                            in SFmode, DFmode and XFmode */
1075   2,                                    /* cost of moving MMX register */
1076   {8, 8},                               /* cost of loading MMX registers
1077                                            in SImode and DImode */
1078   {8, 8},                               /* cost of storing MMX registers
1079                                            in SImode and DImode */
1080   2,                                    /* cost of moving SSE register */
1081   {8, 8, 8},                            /* cost of loading SSE registers
1082                                            in SImode, DImode and TImode */
1083   {8, 8, 8},                            /* cost of storing SSE registers
1084                                            in SImode, DImode and TImode */
1085   5,                                    /* MMX or SSE register to integer */
1086   32,                                   /* size of l1 cache.  */
1087   512,                                  /* size of l2 cache.  */
1088   64,                                   /* size of prefetch block */
1089   6,                                    /* number of parallel prefetches */
1090   /* Benchmarks shows large regressions on K8 sixtrack benchmark when this value
1091      is increased to perhaps more appropriate value of 5.  */
1092   3,                                    /* Branch cost */
1093   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1094   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1095   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1096   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1097   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1098   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1099   {DUMMY_STRINGOP_ALGS,
1100    {libcall, {{32, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1101   {DUMMY_STRINGOP_ALGS,
1102    {libcall, {{32, loop}, {8192, rep_prefix_8_byte}, {-1, libcall}}}},
1103   1,                                    /* scalar_stmt_cost.  */
1104   1,                                    /* scalar load_cost.  */
1105   1,                                    /* scalar_store_cost.  */
1106   1,                                    /* vec_stmt_cost.  */
1107   1,                                    /* vec_to_scalar_cost.  */
1108   1,                                    /* scalar_to_vec_cost.  */
1109   1,                                    /* vec_align_load_cost.  */
1110   2,                                    /* vec_unalign_load_cost.  */
1111   1,                                    /* vec_store_cost.  */
1112   3,                                    /* cond_taken_branch_cost.  */
1113   1,                                    /* cond_not_taken_branch_cost.  */
1114 };
1115
1116 /* Generic32 should produce code tuned for Athlon, PPro, Pentium4, Nocona and K8.  */
1117 static const
1118 struct processor_costs generic32_cost = {
1119   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1120   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1121   COSTS_N_INSNS (1),                    /* variable shift costs */
1122   COSTS_N_INSNS (1),                    /* constant shift costs */
1123   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1124    COSTS_N_INSNS (4),                   /*                               HI */
1125    COSTS_N_INSNS (3),                   /*                               SI */
1126    COSTS_N_INSNS (4),                   /*                               DI */
1127    COSTS_N_INSNS (2)},                  /*                               other */
1128   0,                                    /* cost of multiply per each bit set */
1129   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1130    COSTS_N_INSNS (26),                  /*                          HI */
1131    COSTS_N_INSNS (42),                  /*                          SI */
1132    COSTS_N_INSNS (74),                  /*                          DI */
1133    COSTS_N_INSNS (74)},                 /*                          other */
1134   COSTS_N_INSNS (1),                    /* cost of movsx */
1135   COSTS_N_INSNS (1),                    /* cost of movzx */
1136   8,                                    /* "large" insn */
1137   17,                                   /* MOVE_RATIO */
1138   4,                                    /* cost for loading QImode using movzbl */
1139   {4, 4, 4},                            /* cost of loading integer registers
1140                                            in QImode, HImode and SImode.
1141                                            Relative to reg-reg move (2).  */
1142   {4, 4, 4},                            /* cost of storing integer registers */
1143   4,                                    /* cost of reg,reg fld/fst */
1144   {12, 12, 12},                         /* cost of loading fp registers
1145                                            in SFmode, DFmode and XFmode */
1146   {6, 6, 8},                            /* cost of storing fp registers
1147                                            in SFmode, DFmode and XFmode */
1148   2,                                    /* cost of moving MMX register */
1149   {8, 8},                               /* cost of loading MMX registers
1150                                            in SImode and DImode */
1151   {8, 8},                               /* cost of storing MMX registers
1152                                            in SImode and DImode */
1153   2,                                    /* cost of moving SSE register */
1154   {8, 8, 8},                            /* cost of loading SSE registers
1155                                            in SImode, DImode and TImode */
1156   {8, 8, 8},                            /* cost of storing SSE registers
1157                                            in SImode, DImode and TImode */
1158   5,                                    /* MMX or SSE register to integer */
1159   32,                                   /* size of l1 cache.  */
1160   256,                                  /* size of l2 cache.  */
1161   64,                                   /* size of prefetch block */
1162   6,                                    /* number of parallel prefetches */
1163   3,                                    /* Branch cost */
1164   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1165   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1166   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1167   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1168   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1169   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1170   {{libcall, {{32, loop}, {8192, rep_prefix_4_byte}, {-1, libcall}}},
1171    DUMMY_STRINGOP_ALGS},
1172   {{libcall, {{32, loop}, {8192, rep_prefix_4_byte}, {-1, libcall}}},
1173    DUMMY_STRINGOP_ALGS},
1174   1,                                    /* scalar_stmt_cost.  */
1175   1,                                    /* scalar load_cost.  */
1176   1,                                    /* scalar_store_cost.  */
1177   1,                                    /* vec_stmt_cost.  */
1178   1,                                    /* vec_to_scalar_cost.  */
1179   1,                                    /* scalar_to_vec_cost.  */
1180   1,                                    /* vec_align_load_cost.  */
1181   2,                                    /* vec_unalign_load_cost.  */
1182   1,                                    /* vec_store_cost.  */
1183   3,                                    /* cond_taken_branch_cost.  */
1184   1,                                    /* cond_not_taken_branch_cost.  */
1185 };
1186
1187 const struct processor_costs *ix86_cost = &pentium_cost;
1188
1189 /* Processor feature/optimization bitmasks.  */
1190 #define m_386 (1<<PROCESSOR_I386)
1191 #define m_486 (1<<PROCESSOR_I486)
1192 #define m_PENT (1<<PROCESSOR_PENTIUM)
1193 #define m_PPRO (1<<PROCESSOR_PENTIUMPRO)
1194 #define m_PENT4  (1<<PROCESSOR_PENTIUM4)
1195 #define m_NOCONA  (1<<PROCESSOR_NOCONA)
1196 #define m_CORE2  (1<<PROCESSOR_CORE2)
1197
1198 #define m_GEODE  (1<<PROCESSOR_GEODE)
1199 #define m_K6  (1<<PROCESSOR_K6)
1200 #define m_K6_GEODE  (m_K6 | m_GEODE)
1201 #define m_K8  (1<<PROCESSOR_K8)
1202 #define m_ATHLON  (1<<PROCESSOR_ATHLON)
1203 #define m_ATHLON_K8  (m_K8 | m_ATHLON)
1204 #define m_AMDFAM10  (1<<PROCESSOR_AMDFAM10)
1205 #define m_AMD_MULTIPLE  (m_K8 | m_ATHLON | m_AMDFAM10)
1206
1207 #define m_GENERIC32 (1<<PROCESSOR_GENERIC32)
1208 #define m_GENERIC64 (1<<PROCESSOR_GENERIC64)
1209
1210 /* Generic instruction choice should be common subset of supported CPUs
1211    (PPro/PENT4/NOCONA/CORE2/Athlon/K8).  */
1212 #define m_GENERIC (m_GENERIC32 | m_GENERIC64)
1213
1214 /* Feature tests against the various tunings.  */
1215 unsigned char ix86_tune_features[X86_TUNE_LAST];
1216
1217 /* Feature tests against the various tunings used to create ix86_tune_features
1218    based on the processor mask.  */
1219 static unsigned int initial_ix86_tune_features[X86_TUNE_LAST] = {
1220   /* X86_TUNE_USE_LEAVE: Leave does not affect Nocona SPEC2000 results
1221      negatively, so enabling for Generic64 seems like good code size
1222      tradeoff.  We can't enable it for 32bit generic because it does not
1223      work well with PPro base chips.  */
1224   m_386 | m_K6_GEODE | m_AMD_MULTIPLE | m_CORE2 | m_GENERIC64,
1225
1226   /* X86_TUNE_PUSH_MEMORY */
1227   m_386 | m_K6_GEODE | m_AMD_MULTIPLE | m_PENT4
1228   | m_NOCONA | m_CORE2 | m_GENERIC,
1229
1230   /* X86_TUNE_ZERO_EXTEND_WITH_AND */
1231   m_486 | m_PENT,
1232
1233   /* X86_TUNE_UNROLL_STRLEN */
1234   m_486 | m_PENT | m_PPRO | m_AMD_MULTIPLE | m_K6 | m_CORE2 | m_GENERIC,
1235
1236   /* X86_TUNE_DEEP_BRANCH_PREDICTION */
1237   m_PPRO | m_K6_GEODE | m_AMD_MULTIPLE | m_PENT4 | m_GENERIC,
1238
1239   /* X86_TUNE_BRANCH_PREDICTION_HINTS: Branch hints were put in P4 based
1240      on simulation result. But after P4 was made, no performance benefit
1241      was observed with branch hints.  It also increases the code size.
1242      As a result, icc never generates branch hints.  */
1243   0,
1244
1245   /* X86_TUNE_DOUBLE_WITH_ADD */
1246   ~m_386,
1247
1248   /* X86_TUNE_USE_SAHF */
1249   m_PPRO | m_K6_GEODE | m_K8 | m_AMDFAM10 | m_PENT4
1250   | m_NOCONA | m_CORE2 | m_GENERIC,
1251
1252   /* X86_TUNE_MOVX: Enable to zero extend integer registers to avoid
1253      partial dependencies.  */
1254   m_AMD_MULTIPLE | m_PPRO | m_PENT4 | m_NOCONA
1255   | m_CORE2 | m_GENERIC | m_GEODE /* m_386 | m_K6 */,
1256
1257   /* X86_TUNE_PARTIAL_REG_STALL: We probably ought to watch for partial
1258      register stalls on Generic32 compilation setting as well.  However
1259      in current implementation the partial register stalls are not eliminated
1260      very well - they can be introduced via subregs synthesized by combine
1261      and can happen in caller/callee saving sequences.  Because this option
1262      pays back little on PPro based chips and is in conflict with partial reg
1263      dependencies used by Athlon/P4 based chips, it is better to leave it off
1264      for generic32 for now.  */
1265   m_PPRO,
1266
1267   /* X86_TUNE_PARTIAL_FLAG_REG_STALL */
1268   m_CORE2 | m_GENERIC,
1269
1270   /* X86_TUNE_USE_HIMODE_FIOP */
1271   m_386 | m_486 | m_K6_GEODE,
1272
1273   /* X86_TUNE_USE_SIMODE_FIOP */
1274   ~(m_PPRO | m_AMD_MULTIPLE | m_PENT | m_CORE2 | m_GENERIC),
1275
1276   /* X86_TUNE_USE_MOV0 */
1277   m_K6,
1278
1279   /* X86_TUNE_USE_CLTD */
1280   ~(m_PENT | m_K6 | m_CORE2 | m_GENERIC),
1281
1282   /* X86_TUNE_USE_XCHGB: Use xchgb %rh,%rl instead of rolw/rorw $8,rx.  */
1283   m_PENT4,
1284
1285   /* X86_TUNE_SPLIT_LONG_MOVES */
1286   m_PPRO,
1287
1288   /* X86_TUNE_READ_MODIFY_WRITE */
1289   ~m_PENT,
1290
1291   /* X86_TUNE_READ_MODIFY */
1292   ~(m_PENT | m_PPRO),
1293
1294   /* X86_TUNE_PROMOTE_QIMODE */
1295   m_K6_GEODE | m_PENT | m_386 | m_486 | m_AMD_MULTIPLE | m_CORE2
1296   | m_GENERIC /* | m_PENT4 ? */,
1297
1298   /* X86_TUNE_FAST_PREFIX */
1299   ~(m_PENT | m_486 | m_386),
1300
1301   /* X86_TUNE_SINGLE_STRINGOP */
1302   m_386 | m_PENT4 | m_NOCONA,
1303
1304   /* X86_TUNE_QIMODE_MATH */
1305   ~0,
1306
1307   /* X86_TUNE_HIMODE_MATH: On PPro this flag is meant to avoid partial
1308      register stalls.  Just like X86_TUNE_PARTIAL_REG_STALL this option
1309      might be considered for Generic32 if our scheme for avoiding partial
1310      stalls was more effective.  */
1311   ~m_PPRO,
1312
1313   /* X86_TUNE_PROMOTE_QI_REGS */
1314   0,
1315
1316   /* X86_TUNE_PROMOTE_HI_REGS */
1317   m_PPRO,
1318
1319   /* X86_TUNE_ADD_ESP_4: Enable if add/sub is preferred over 1/2 push/pop.  */
1320   m_AMD_MULTIPLE | m_K6_GEODE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1321
1322   /* X86_TUNE_ADD_ESP_8 */
1323   m_AMD_MULTIPLE | m_PPRO | m_K6_GEODE | m_386
1324   | m_486 | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1325
1326   /* X86_TUNE_SUB_ESP_4 */
1327   m_AMD_MULTIPLE | m_PPRO | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1328
1329   /* X86_TUNE_SUB_ESP_8 */
1330   m_AMD_MULTIPLE | m_PPRO | m_386 | m_486
1331   | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1332
1333   /* X86_TUNE_INTEGER_DFMODE_MOVES: Enable if integer moves are preferred
1334      for DFmode copies */
1335   ~(m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2
1336     | m_GENERIC | m_GEODE),
1337
1338   /* X86_TUNE_PARTIAL_REG_DEPENDENCY */
1339   m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1340
1341   /* X86_TUNE_SSE_PARTIAL_REG_DEPENDENCY: In the Generic model we have a
1342      conflict here in between PPro/Pentium4 based chips that thread 128bit
1343      SSE registers as single units versus K8 based chips that divide SSE
1344      registers to two 64bit halves.  This knob promotes all store destinations
1345      to be 128bit to allow register renaming on 128bit SSE units, but usually
1346      results in one extra microop on 64bit SSE units.  Experimental results
1347      shows that disabling this option on P4 brings over 20% SPECfp regression,
1348      while enabling it on K8 brings roughly 2.4% regression that can be partly
1349      masked by careful scheduling of moves.  */
1350   m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC | m_AMDFAM10,
1351
1352   /* X86_TUNE_SSE_UNALIGNED_MOVE_OPTIMAL */
1353   m_AMDFAM10,
1354
1355   /* X86_TUNE_SSE_SPLIT_REGS: Set for machines where the type and dependencies
1356      are resolved on SSE register parts instead of whole registers, so we may
1357      maintain just lower part of scalar values in proper format leaving the
1358      upper part undefined.  */
1359   m_ATHLON_K8,
1360
1361   /* X86_TUNE_SSE_TYPELESS_STORES */
1362   m_AMD_MULTIPLE,
1363
1364   /* X86_TUNE_SSE_LOAD0_BY_PXOR */
1365   m_PPRO | m_PENT4 | m_NOCONA,
1366
1367   /* X86_TUNE_MEMORY_MISMATCH_STALL */
1368   m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1369
1370   /* X86_TUNE_PROLOGUE_USING_MOVE */
1371   m_ATHLON_K8 | m_PPRO | m_CORE2 | m_GENERIC,
1372
1373   /* X86_TUNE_EPILOGUE_USING_MOVE */
1374   m_ATHLON_K8 | m_PPRO | m_CORE2 | m_GENERIC,
1375
1376   /* X86_TUNE_SHIFT1 */
1377   ~m_486,
1378
1379   /* X86_TUNE_USE_FFREEP */
1380   m_AMD_MULTIPLE,
1381
1382   /* X86_TUNE_INTER_UNIT_MOVES */
1383   ~(m_AMD_MULTIPLE | m_GENERIC),
1384
1385   /* X86_TUNE_INTER_UNIT_CONVERSIONS */
1386   ~(m_AMDFAM10),
1387
1388   /* X86_TUNE_FOUR_JUMP_LIMIT: Some CPU cores are not able to predict more
1389      than 4 branch instructions in the 16 byte window.  */
1390   m_PPRO | m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_CORE2 | m_GENERIC,
1391
1392   /* X86_TUNE_SCHEDULE */
1393   m_PPRO | m_AMD_MULTIPLE | m_K6_GEODE | m_PENT | m_CORE2 | m_GENERIC,
1394
1395   /* X86_TUNE_USE_BT */
1396   m_AMD_MULTIPLE | m_CORE2 | m_GENERIC,
1397
1398   /* X86_TUNE_USE_INCDEC */
1399   ~(m_PENT4 | m_NOCONA | m_GENERIC),
1400
1401   /* X86_TUNE_PAD_RETURNS */
1402   m_AMD_MULTIPLE | m_CORE2 | m_GENERIC,
1403
1404   /* X86_TUNE_EXT_80387_CONSTANTS */
1405   m_K6_GEODE | m_ATHLON_K8 | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC,
1406
1407   /* X86_TUNE_SHORTEN_X87_SSE */
1408   ~m_K8,
1409
1410   /* X86_TUNE_AVOID_VECTOR_DECODE */
1411   m_K8 | m_GENERIC64,
1412
1413   /* X86_TUNE_PROMOTE_HIMODE_IMUL: Modern CPUs have same latency for HImode
1414      and SImode multiply, but 386 and 486 do HImode multiply faster.  */
1415   ~(m_386 | m_486),
1416
1417   /* X86_TUNE_SLOW_IMUL_IMM32_MEM: Imul of 32-bit constant and memory is
1418      vector path on AMD machines.  */
1419   m_K8 | m_GENERIC64 | m_AMDFAM10,
1420
1421   /* X86_TUNE_SLOW_IMUL_IMM8: Imul of 8-bit constant is vector path on AMD
1422      machines.  */
1423   m_K8 | m_GENERIC64 | m_AMDFAM10,
1424
1425   /* X86_TUNE_MOVE_M1_VIA_OR: On pentiums, it is faster to load -1 via OR
1426      than a MOV.  */
1427   m_PENT,
1428
1429   /* X86_TUNE_NOT_UNPAIRABLE: NOT is not pairable on Pentium, while XOR is,
1430      but one byte longer.  */
1431   m_PENT,
1432
1433   /* X86_TUNE_NOT_VECTORMODE: On AMD K6, NOT is vector decoded with memory
1434      operand that cannot be represented using a modRM byte.  The XOR
1435      replacement is long decoded, so this split helps here as well.  */
1436   m_K6,
1437
1438   /* X86_TUNE_USE_VECTOR_FP_CONVERTS: Prefer vector packed SSE conversion
1439      from FP to FP. */
1440   m_AMDFAM10 | m_GENERIC,
1441
1442   /* X86_TUNE_USE_VECTOR_CONVERTS: Prefer vector packed SSE conversion
1443      from integer to FP. */
1444   m_AMDFAM10,
1445
1446   /* X86_TUNE_FUSE_CMP_AND_BRANCH: Fuse a compare or test instruction
1447      with a subsequent conditional jump instruction into a single
1448      compare-and-branch uop.  */
1449   m_CORE2,
1450 };
1451
1452 /* Feature tests against the various architecture variations.  */
1453 unsigned char ix86_arch_features[X86_ARCH_LAST];
1454
1455 /* Feature tests against the various architecture variations, used to create
1456    ix86_arch_features based on the processor mask.  */
1457 static unsigned int initial_ix86_arch_features[X86_ARCH_LAST] = {
1458   /* X86_ARCH_CMOVE: Conditional move was added for pentiumpro.  */
1459   ~(m_386 | m_486 | m_PENT | m_K6),
1460
1461   /* X86_ARCH_CMPXCHG: Compare and exchange was added for 80486.  */
1462   ~m_386,
1463
1464   /* X86_ARCH_CMPXCHG8B: Compare and exchange 8 bytes was added for pentium. */
1465   ~(m_386 | m_486),
1466
1467   /* X86_ARCH_XADD: Exchange and add was added for 80486.  */
1468   ~m_386,
1469
1470   /* X86_ARCH_BSWAP: Byteswap was added for 80486.  */
1471   ~m_386,
1472 };
1473
1474 static const unsigned int x86_accumulate_outgoing_args
1475   = m_AMD_MULTIPLE | m_PENT4 | m_NOCONA | m_PPRO | m_CORE2 | m_GENERIC;
1476
1477 static const unsigned int x86_arch_always_fancy_math_387
1478   = m_PENT | m_PPRO | m_AMD_MULTIPLE | m_PENT4
1479     | m_NOCONA | m_CORE2 | m_GENERIC;
1480
1481 static enum stringop_alg stringop_alg = no_stringop;
1482
1483 /* In case the average insn count for single function invocation is
1484    lower than this constant, emit fast (but longer) prologue and
1485    epilogue code.  */
1486 #define FAST_PROLOGUE_INSN_COUNT 20
1487
1488 /* Names for 8 (low), 8 (high), and 16-bit registers, respectively.  */
1489 static const char *const qi_reg_name[] = QI_REGISTER_NAMES;
1490 static const char *const qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES;
1491 static const char *const hi_reg_name[] = HI_REGISTER_NAMES;
1492
1493 /* Array of the smallest class containing reg number REGNO, indexed by
1494    REGNO.  Used by REGNO_REG_CLASS in i386.h.  */
1495
1496 enum reg_class const regclass_map[FIRST_PSEUDO_REGISTER] =
1497 {
1498   /* ax, dx, cx, bx */
1499   AREG, DREG, CREG, BREG,
1500   /* si, di, bp, sp */
1501   SIREG, DIREG, NON_Q_REGS, NON_Q_REGS,
1502   /* FP registers */
1503   FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS,
1504   FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS,
1505   /* arg pointer */
1506   NON_Q_REGS,
1507   /* flags, fpsr, fpcr, frame */
1508   NO_REGS, NO_REGS, NO_REGS, NON_Q_REGS,
1509   /* SSE registers */
1510   SSE_FIRST_REG, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
1511   SSE_REGS, SSE_REGS,
1512   /* MMX registers */
1513   MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS,
1514   MMX_REGS, MMX_REGS,
1515   /* REX registers */
1516   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
1517   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
1518   /* SSE REX registers */
1519   SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
1520   SSE_REGS, SSE_REGS,
1521 };
1522
1523 /* The "default" register map used in 32bit mode.  */
1524
1525 int const dbx_register_map[FIRST_PSEUDO_REGISTER] =
1526 {
1527   0, 2, 1, 3, 6, 7, 4, 5,               /* general regs */
1528   12, 13, 14, 15, 16, 17, 18, 19,       /* fp regs */
1529   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
1530   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE */
1531   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX */
1532   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
1533   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
1534 };
1535
1536 /* The "default" register map used in 64bit mode.  */
1537
1538 int const dbx64_register_map[FIRST_PSEUDO_REGISTER] =
1539 {
1540   0, 1, 2, 3, 4, 5, 6, 7,               /* general regs */
1541   33, 34, 35, 36, 37, 38, 39, 40,       /* fp regs */
1542   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
1543   17, 18, 19, 20, 21, 22, 23, 24,       /* SSE */
1544   41, 42, 43, 44, 45, 46, 47, 48,       /* MMX */
1545   8,9,10,11,12,13,14,15,                /* extended integer registers */
1546   25, 26, 27, 28, 29, 30, 31, 32,       /* extended SSE registers */
1547 };
1548
1549 /* Define the register numbers to be used in Dwarf debugging information.
1550    The SVR4 reference port C compiler uses the following register numbers
1551    in its Dwarf output code:
1552         0 for %eax (gcc regno = 0)
1553         1 for %ecx (gcc regno = 2)
1554         2 for %edx (gcc regno = 1)
1555         3 for %ebx (gcc regno = 3)
1556         4 for %esp (gcc regno = 7)
1557         5 for %ebp (gcc regno = 6)
1558         6 for %esi (gcc regno = 4)
1559         7 for %edi (gcc regno = 5)
1560    The following three DWARF register numbers are never generated by
1561    the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4
1562    believes these numbers have these meanings.
1563         8  for %eip    (no gcc equivalent)
1564         9  for %eflags (gcc regno = 17)
1565         10 for %trapno (no gcc equivalent)
1566    It is not at all clear how we should number the FP stack registers
1567    for the x86 architecture.  If the version of SDB on x86/svr4 were
1568    a bit less brain dead with respect to floating-point then we would
1569    have a precedent to follow with respect to DWARF register numbers
1570    for x86 FP registers, but the SDB on x86/svr4 is so completely
1571    broken with respect to FP registers that it is hardly worth thinking
1572    of it as something to strive for compatibility with.
1573    The version of x86/svr4 SDB I have at the moment does (partially)
1574    seem to believe that DWARF register number 11 is associated with
1575    the x86 register %st(0), but that's about all.  Higher DWARF
1576    register numbers don't seem to be associated with anything in
1577    particular, and even for DWARF regno 11, SDB only seems to under-
1578    stand that it should say that a variable lives in %st(0) (when
1579    asked via an `=' command) if we said it was in DWARF regno 11,
1580    but SDB still prints garbage when asked for the value of the
1581    variable in question (via a `/' command).
1582    (Also note that the labels SDB prints for various FP stack regs
1583    when doing an `x' command are all wrong.)
1584    Note that these problems generally don't affect the native SVR4
1585    C compiler because it doesn't allow the use of -O with -g and
1586    because when it is *not* optimizing, it allocates a memory
1587    location for each floating-point variable, and the memory
1588    location is what gets described in the DWARF AT_location
1589    attribute for the variable in question.
1590    Regardless of the severe mental illness of the x86/svr4 SDB, we
1591    do something sensible here and we use the following DWARF
1592    register numbers.  Note that these are all stack-top-relative
1593    numbers.
1594         11 for %st(0) (gcc regno = 8)
1595         12 for %st(1) (gcc regno = 9)
1596         13 for %st(2) (gcc regno = 10)
1597         14 for %st(3) (gcc regno = 11)
1598         15 for %st(4) (gcc regno = 12)
1599         16 for %st(5) (gcc regno = 13)
1600         17 for %st(6) (gcc regno = 14)
1601         18 for %st(7) (gcc regno = 15)
1602 */
1603 int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER] =
1604 {
1605   0, 2, 1, 3, 6, 7, 5, 4,               /* general regs */
1606   11, 12, 13, 14, 15, 16, 17, 18,       /* fp regs */
1607   -1, 9, -1, -1, -1,                    /* arg, flags, fpsr, fpcr, frame */
1608   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE registers */
1609   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX registers */
1610   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
1611   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
1612 };
1613
1614 /* Test and compare insns in i386.md store the information needed to
1615    generate branch and scc insns here.  */
1616
1617 rtx ix86_compare_op0 = NULL_RTX;
1618 rtx ix86_compare_op1 = NULL_RTX;
1619 rtx ix86_compare_emitted = NULL_RTX;
1620
1621 /* Define parameter passing and return registers.  */
1622
1623 static int const x86_64_int_parameter_registers[6] =
1624 {
1625   DI_REG, SI_REG, DX_REG, CX_REG, R8_REG, R9_REG
1626 };
1627
1628 static int const x86_64_ms_abi_int_parameter_registers[4] =
1629 {
1630   CX_REG, DX_REG, R8_REG, R9_REG
1631 };
1632
1633 static int const x86_64_int_return_registers[4] =
1634 {
1635   AX_REG, DX_REG, DI_REG, SI_REG
1636 };
1637
1638 /* Define the structure for the machine field in struct function.  */
1639
1640 struct stack_local_entry GTY(())
1641 {
1642   unsigned short mode;
1643   unsigned short n;
1644   rtx rtl;
1645   struct stack_local_entry *next;
1646 };
1647
1648 /* Structure describing stack frame layout.
1649    Stack grows downward:
1650
1651    [arguments]
1652                                               <- ARG_POINTER
1653    saved pc
1654
1655    saved frame pointer if frame_pointer_needed
1656                                               <- HARD_FRAME_POINTER
1657    [saved regs]
1658
1659    [padding0]
1660
1661    [saved SSE regs]
1662
1663    [padding1]          \
1664                         )
1665    [va_arg registers]  (
1666                         > to_allocate         <- FRAME_POINTER
1667    [frame]             (
1668                         )
1669    [padding2]          /
1670   */
1671 struct ix86_frame
1672 {
1673   int padding0;
1674   int nsseregs;
1675   int nregs;
1676   int padding1;
1677   int va_arg_size;
1678   HOST_WIDE_INT frame;
1679   int padding2;
1680   int outgoing_arguments_size;
1681   int red_zone_size;
1682
1683   HOST_WIDE_INT to_allocate;
1684   /* The offsets relative to ARG_POINTER.  */
1685   HOST_WIDE_INT frame_pointer_offset;
1686   HOST_WIDE_INT hard_frame_pointer_offset;
1687   HOST_WIDE_INT stack_pointer_offset;
1688
1689   /* When save_regs_using_mov is set, emit prologue using
1690      move instead of push instructions.  */
1691   bool save_regs_using_mov;
1692 };
1693
1694 /* Code model option.  */
1695 enum cmodel ix86_cmodel;
1696 /* Asm dialect.  */
1697 enum asm_dialect ix86_asm_dialect = ASM_ATT;
1698 /* TLS dialects.  */
1699 enum tls_dialect ix86_tls_dialect = TLS_DIALECT_GNU;
1700
1701 /* Which unit we are generating floating point math for.  */
1702 enum fpmath_unit ix86_fpmath;
1703
1704 /* Which cpu are we scheduling for.  */
1705 enum attr_cpu ix86_schedule;
1706
1707 /* Which cpu are we optimizing for.  */
1708 enum processor_type ix86_tune;
1709
1710 /* Which instruction set architecture to use.  */
1711 enum processor_type ix86_arch;
1712
1713 /* true if sse prefetch instruction is not NOOP.  */
1714 int x86_prefetch_sse;
1715
1716 /* ix86_regparm_string as a number */
1717 static int ix86_regparm;
1718
1719 /* -mstackrealign option */
1720 extern int ix86_force_align_arg_pointer;
1721 static const char ix86_force_align_arg_pointer_string[]
1722   = "force_align_arg_pointer";
1723
1724 static rtx (*ix86_gen_leave) (void);
1725 static rtx (*ix86_gen_pop1) (rtx);
1726 static rtx (*ix86_gen_add3) (rtx, rtx, rtx);
1727 static rtx (*ix86_gen_sub3) (rtx, rtx, rtx);
1728 static rtx (*ix86_gen_sub3_carry) (rtx, rtx, rtx, rtx);
1729 static rtx (*ix86_gen_one_cmpl2) (rtx, rtx);
1730 static rtx (*ix86_gen_monitor) (rtx, rtx, rtx);
1731 static rtx (*ix86_gen_andsp) (rtx, rtx, rtx);
1732
1733 /* Preferred alignment for stack boundary in bits.  */
1734 unsigned int ix86_preferred_stack_boundary;
1735
1736 /* Alignment for incoming stack boundary in bits specified at
1737    command line.  */
1738 static unsigned int ix86_user_incoming_stack_boundary;
1739
1740 /* Default alignment for incoming stack boundary in bits.  */
1741 static unsigned int ix86_default_incoming_stack_boundary;
1742
1743 /* Alignment for incoming stack boundary in bits.  */
1744 unsigned int ix86_incoming_stack_boundary;
1745
1746 /* Values 1-5: see jump.c */
1747 int ix86_branch_cost;
1748
1749 /* Calling abi specific va_list type nodes.  */
1750 static GTY(()) tree sysv_va_list_type_node;
1751 static GTY(()) tree ms_va_list_type_node;
1752
1753 /* Variables which are this size or smaller are put in the data/bss
1754    or ldata/lbss sections.  */
1755
1756 int ix86_section_threshold = 65536;
1757
1758 /* Prefix built by ASM_GENERATE_INTERNAL_LABEL.  */
1759 char internal_label_prefix[16];
1760 int internal_label_prefix_len;
1761
1762 /* Fence to use after loop using movnt.  */
1763 tree x86_mfence;
1764
1765 /* Register class used for passing given 64bit part of the argument.
1766    These represent classes as documented by the PS ABI, with the exception
1767    of SSESF, SSEDF classes, that are basically SSE class, just gcc will
1768    use SF or DFmode move instead of DImode to avoid reformatting penalties.
1769
1770    Similarly we play games with INTEGERSI_CLASS to use cheaper SImode moves
1771    whenever possible (upper half does contain padding).  */
1772 enum x86_64_reg_class
1773   {
1774     X86_64_NO_CLASS,
1775     X86_64_INTEGER_CLASS,
1776     X86_64_INTEGERSI_CLASS,
1777     X86_64_SSE_CLASS,
1778     X86_64_SSESF_CLASS,
1779     X86_64_SSEDF_CLASS,
1780     X86_64_SSEUP_CLASS,
1781     X86_64_X87_CLASS,
1782     X86_64_X87UP_CLASS,
1783     X86_64_COMPLEX_X87_CLASS,
1784     X86_64_MEMORY_CLASS
1785   };
1786
1787 #define MAX_CLASSES 4
1788
1789 /* Table of constants used by fldpi, fldln2, etc....  */
1790 static REAL_VALUE_TYPE ext_80387_constants_table [5];
1791 static bool ext_80387_constants_init = 0;
1792
1793 \f
1794 static struct machine_function * ix86_init_machine_status (void);
1795 static rtx ix86_function_value (const_tree, const_tree, bool);
1796 static int ix86_function_regparm (const_tree, const_tree);
1797 static void ix86_compute_frame_layout (struct ix86_frame *);
1798 static bool ix86_expand_vector_init_one_nonzero (bool, enum machine_mode,
1799                                                  rtx, rtx, int);
1800 static void ix86_add_new_builtins (int);
1801
1802 enum ix86_function_specific_strings
1803 {
1804   IX86_FUNCTION_SPECIFIC_ARCH,
1805   IX86_FUNCTION_SPECIFIC_TUNE,
1806   IX86_FUNCTION_SPECIFIC_FPMATH,
1807   IX86_FUNCTION_SPECIFIC_MAX
1808 };
1809
1810 static char *ix86_target_string (int, int, const char *, const char *,
1811                                  const char *, bool);
1812 static void ix86_debug_options (void) ATTRIBUTE_UNUSED;
1813 static void ix86_function_specific_save (struct cl_target_option *);
1814 static void ix86_function_specific_restore (struct cl_target_option *);
1815 static void ix86_function_specific_print (FILE *, int,
1816                                           struct cl_target_option *);
1817 static bool ix86_valid_target_attribute_p (tree, tree, tree, int);
1818 static bool ix86_valid_target_attribute_inner_p (tree, char *[]);
1819 static bool ix86_can_inline_p (tree, tree);
1820 static void ix86_set_current_function (tree);
1821
1822 \f
1823 /* The svr4 ABI for the i386 says that records and unions are returned
1824    in memory.  */
1825 #ifndef DEFAULT_PCC_STRUCT_RETURN
1826 #define DEFAULT_PCC_STRUCT_RETURN 1
1827 #endif
1828
1829 /* Whether -mtune= or -march= were specified */
1830 static int ix86_tune_defaulted;
1831 static int ix86_arch_specified;
1832
1833 /* Bit flags that specify the ISA we are compiling for.  */
1834 int ix86_isa_flags = TARGET_64BIT_DEFAULT | TARGET_SUBTARGET_ISA_DEFAULT;
1835
1836 /* A mask of ix86_isa_flags that includes bit X if X
1837    was set or cleared on the command line.  */
1838 static int ix86_isa_flags_explicit;
1839
1840 /* Define a set of ISAs which are available when a given ISA is
1841    enabled.  MMX and SSE ISAs are handled separately.  */
1842
1843 #define OPTION_MASK_ISA_MMX_SET OPTION_MASK_ISA_MMX
1844 #define OPTION_MASK_ISA_3DNOW_SET \
1845   (OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_MMX_SET)
1846
1847 #define OPTION_MASK_ISA_SSE_SET OPTION_MASK_ISA_SSE
1848 #define OPTION_MASK_ISA_SSE2_SET \
1849   (OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE_SET)
1850 #define OPTION_MASK_ISA_SSE3_SET \
1851   (OPTION_MASK_ISA_SSE3 | OPTION_MASK_ISA_SSE2_SET)
1852 #define OPTION_MASK_ISA_SSSE3_SET \
1853   (OPTION_MASK_ISA_SSSE3 | OPTION_MASK_ISA_SSE3_SET)
1854 #define OPTION_MASK_ISA_SSE4_1_SET \
1855   (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_SSSE3_SET)
1856 #define OPTION_MASK_ISA_SSE4_2_SET \
1857   (OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_SSE4_1_SET)
1858 #define OPTION_MASK_ISA_AVX_SET \
1859   (OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_SSE4_2_SET)
1860 #define OPTION_MASK_ISA_FMA_SET \
1861   (OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_AVX_SET)
1862
1863 /* SSE4 includes both SSE4.1 and SSE4.2. -msse4 should be the same
1864    as -msse4.2.  */
1865 #define OPTION_MASK_ISA_SSE4_SET OPTION_MASK_ISA_SSE4_2_SET
1866
1867 #define OPTION_MASK_ISA_SSE4A_SET \
1868   (OPTION_MASK_ISA_SSE4A | OPTION_MASK_ISA_SSE3_SET)
1869 #define OPTION_MASK_ISA_SSE5_SET \
1870   (OPTION_MASK_ISA_SSE5 | OPTION_MASK_ISA_SSE4A_SET)
1871
1872 /* AES and PCLMUL need SSE2 because they use xmm registers */
1873 #define OPTION_MASK_ISA_AES_SET \
1874   (OPTION_MASK_ISA_AES | OPTION_MASK_ISA_SSE2_SET)
1875 #define OPTION_MASK_ISA_PCLMUL_SET \
1876   (OPTION_MASK_ISA_PCLMUL | OPTION_MASK_ISA_SSE2_SET)
1877
1878 #define OPTION_MASK_ISA_ABM_SET \
1879   (OPTION_MASK_ISA_ABM | OPTION_MASK_ISA_POPCNT)
1880 #define OPTION_MASK_ISA_POPCNT_SET OPTION_MASK_ISA_POPCNT
1881 #define OPTION_MASK_ISA_CX16_SET OPTION_MASK_ISA_CX16
1882 #define OPTION_MASK_ISA_SAHF_SET OPTION_MASK_ISA_SAHF
1883
1884 /* Define a set of ISAs which aren't available when a given ISA is
1885    disabled.  MMX and SSE ISAs are handled separately.  */
1886
1887 #define OPTION_MASK_ISA_MMX_UNSET \
1888   (OPTION_MASK_ISA_MMX | OPTION_MASK_ISA_3DNOW_UNSET)
1889 #define OPTION_MASK_ISA_3DNOW_UNSET \
1890   (OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_3DNOW_A_UNSET)
1891 #define OPTION_MASK_ISA_3DNOW_A_UNSET OPTION_MASK_ISA_3DNOW_A
1892
1893 #define OPTION_MASK_ISA_SSE_UNSET \
1894   (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_SSE2_UNSET)
1895 #define OPTION_MASK_ISA_SSE2_UNSET \
1896   (OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE3_UNSET)
1897 #define OPTION_MASK_ISA_SSE3_UNSET \
1898   (OPTION_MASK_ISA_SSE3 \
1899    | OPTION_MASK_ISA_SSSE3_UNSET \
1900    | OPTION_MASK_ISA_SSE4A_UNSET )
1901 #define OPTION_MASK_ISA_SSSE3_UNSET \
1902   (OPTION_MASK_ISA_SSSE3 | OPTION_MASK_ISA_SSE4_1_UNSET)
1903 #define OPTION_MASK_ISA_SSE4_1_UNSET \
1904   (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_SSE4_2_UNSET)
1905 #define OPTION_MASK_ISA_SSE4_2_UNSET \
1906   (OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_AVX_UNSET )
1907 #define OPTION_MASK_ISA_AVX_UNSET \
1908   (OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_FMA_UNSET)
1909 #define OPTION_MASK_ISA_FMA_UNSET OPTION_MASK_ISA_FMA
1910
1911 /* SSE4 includes both SSE4.1 and SSE4.2.  -mno-sse4 should the same
1912    as -mno-sse4.1. */
1913 #define OPTION_MASK_ISA_SSE4_UNSET OPTION_MASK_ISA_SSE4_1_UNSET
1914
1915 #define OPTION_MASK_ISA_SSE4A_UNSET \
1916   (OPTION_MASK_ISA_SSE4A | OPTION_MASK_ISA_SSE5_UNSET)
1917 #define OPTION_MASK_ISA_SSE5_UNSET OPTION_MASK_ISA_SSE5
1918 #define OPTION_MASK_ISA_AES_UNSET OPTION_MASK_ISA_AES
1919 #define OPTION_MASK_ISA_PCLMUL_UNSET OPTION_MASK_ISA_PCLMUL
1920 #define OPTION_MASK_ISA_ABM_UNSET OPTION_MASK_ISA_ABM
1921 #define OPTION_MASK_ISA_POPCNT_UNSET OPTION_MASK_ISA_POPCNT
1922 #define OPTION_MASK_ISA_CX16_UNSET OPTION_MASK_ISA_CX16
1923 #define OPTION_MASK_ISA_SAHF_UNSET OPTION_MASK_ISA_SAHF
1924
1925 /* Vectorization library interface and handlers.  */
1926 tree (*ix86_veclib_handler)(enum built_in_function, tree, tree) = NULL;
1927 static tree ix86_veclibabi_svml (enum built_in_function, tree, tree);
1928 static tree ix86_veclibabi_acml (enum built_in_function, tree, tree);
1929
1930 /* Processor target table, indexed by processor number */
1931 struct ptt
1932 {
1933   const struct processor_costs *cost;           /* Processor costs */
1934   const int align_loop;                         /* Default alignments.  */
1935   const int align_loop_max_skip;
1936   const int align_jump;
1937   const int align_jump_max_skip;
1938   const int align_func;
1939 };
1940
1941 static const struct ptt processor_target_table[PROCESSOR_max] =
1942 {
1943   {&i386_cost, 4, 3, 4, 3, 4},
1944   {&i486_cost, 16, 15, 16, 15, 16},
1945   {&pentium_cost, 16, 7, 16, 7, 16},
1946   {&pentiumpro_cost, 16, 15, 16, 10, 16},
1947   {&geode_cost, 0, 0, 0, 0, 0},
1948   {&k6_cost, 32, 7, 32, 7, 32},
1949   {&athlon_cost, 16, 7, 16, 7, 16},
1950   {&pentium4_cost, 0, 0, 0, 0, 0},
1951   {&k8_cost, 16, 7, 16, 7, 16},
1952   {&nocona_cost, 0, 0, 0, 0, 0},
1953   {&core2_cost, 16, 10, 16, 10, 16},
1954   {&generic32_cost, 16, 7, 16, 7, 16},
1955   {&generic64_cost, 16, 10, 16, 10, 16},
1956   {&amdfam10_cost, 32, 24, 32, 7, 32}
1957 };
1958
1959 static const char *const cpu_names[TARGET_CPU_DEFAULT_max] =
1960 {
1961   "generic",
1962   "i386",
1963   "i486",
1964   "pentium",
1965   "pentium-mmx",
1966   "pentiumpro",
1967   "pentium2",
1968   "pentium3",
1969   "pentium4",
1970   "pentium-m",
1971   "prescott",
1972   "nocona",
1973   "core2",
1974   "geode",
1975   "k6",
1976   "k6-2",
1977   "k6-3",
1978   "athlon",
1979   "athlon-4",
1980   "k8",
1981   "amdfam10"
1982 };
1983 \f
1984 /* Implement TARGET_HANDLE_OPTION.  */
1985
1986 static bool
1987 ix86_handle_option (size_t code, const char *arg ATTRIBUTE_UNUSED, int value)
1988 {
1989   switch (code)
1990     {
1991     case OPT_mmmx:
1992       if (value)
1993         {
1994           ix86_isa_flags |= OPTION_MASK_ISA_MMX_SET;
1995           ix86_isa_flags_explicit |= OPTION_MASK_ISA_MMX_SET;
1996         }
1997       else
1998         {
1999           ix86_isa_flags &= ~OPTION_MASK_ISA_MMX_UNSET;
2000           ix86_isa_flags_explicit |= OPTION_MASK_ISA_MMX_UNSET;
2001         }
2002       return true;
2003
2004     case OPT_m3dnow:
2005       if (value)
2006         {
2007           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_SET;
2008           ix86_isa_flags_explicit |= OPTION_MASK_ISA_3DNOW_SET;
2009         }
2010       else
2011         {
2012           ix86_isa_flags &= ~OPTION_MASK_ISA_3DNOW_UNSET;
2013           ix86_isa_flags_explicit |= OPTION_MASK_ISA_3DNOW_UNSET;
2014         }
2015       return true;
2016
2017     case OPT_m3dnowa:
2018       return false;
2019
2020     case OPT_msse:
2021       if (value)
2022         {
2023           ix86_isa_flags |= OPTION_MASK_ISA_SSE_SET;
2024           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE_SET;
2025         }
2026       else
2027         {
2028           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE_UNSET;
2029           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE_UNSET;
2030         }
2031       return true;
2032
2033     case OPT_msse2:
2034       if (value)
2035         {
2036           ix86_isa_flags |= OPTION_MASK_ISA_SSE2_SET;
2037           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE2_SET;
2038         }
2039       else
2040         {
2041           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE2_UNSET;
2042           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE2_UNSET;
2043         }
2044       return true;
2045
2046     case OPT_msse3:
2047       if (value)
2048         {
2049           ix86_isa_flags |= OPTION_MASK_ISA_SSE3_SET;
2050           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE3_SET;
2051         }
2052       else
2053         {
2054           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE3_UNSET;
2055           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE3_UNSET;
2056         }
2057       return true;
2058
2059     case OPT_mssse3:
2060       if (value)
2061         {
2062           ix86_isa_flags |= OPTION_MASK_ISA_SSSE3_SET;
2063           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSSE3_SET;
2064         }
2065       else
2066         {
2067           ix86_isa_flags &= ~OPTION_MASK_ISA_SSSE3_UNSET;
2068           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSSE3_UNSET;
2069         }
2070       return true;
2071
2072     case OPT_msse4_1:
2073       if (value)
2074         {
2075           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1_SET;
2076           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_1_SET;
2077         }
2078       else
2079         {
2080           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_1_UNSET;
2081           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_1_UNSET;
2082         }
2083       return true;
2084
2085     case OPT_msse4_2:
2086       if (value)
2087         {
2088           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2_SET;
2089           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_2_SET;
2090         }
2091       else
2092         {
2093           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_2_UNSET;
2094           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_2_UNSET;
2095         }
2096       return true;
2097
2098     case OPT_mavx:
2099       if (value)
2100         {
2101           ix86_isa_flags |= OPTION_MASK_ISA_AVX_SET;
2102           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AVX_SET;
2103         }
2104       else
2105         {
2106           ix86_isa_flags &= ~OPTION_MASK_ISA_AVX_UNSET;
2107           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AVX_UNSET;
2108         }
2109       return true;
2110
2111     case OPT_mfma:
2112       if (value)
2113         {
2114           ix86_isa_flags |= OPTION_MASK_ISA_FMA_SET;
2115           ix86_isa_flags_explicit |= OPTION_MASK_ISA_FMA_SET;
2116         }
2117       else
2118         {
2119           ix86_isa_flags &= ~OPTION_MASK_ISA_FMA_UNSET;
2120           ix86_isa_flags_explicit |= OPTION_MASK_ISA_FMA_UNSET;
2121         }
2122       return true;
2123
2124     case OPT_msse4:
2125       ix86_isa_flags |= OPTION_MASK_ISA_SSE4_SET;
2126       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_SET;
2127       return true;
2128
2129     case OPT_mno_sse4:
2130       ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_UNSET;
2131       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_UNSET;
2132       return true;
2133
2134     case OPT_msse4a:
2135       if (value)
2136         {
2137           ix86_isa_flags |= OPTION_MASK_ISA_SSE4A_SET;
2138           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4A_SET;
2139         }
2140       else
2141         {
2142           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4A_UNSET;
2143           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4A_UNSET;
2144         }
2145       return true;
2146
2147     case OPT_msse5:
2148       if (value)
2149         {
2150           ix86_isa_flags |= OPTION_MASK_ISA_SSE5_SET;
2151           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE5_SET;
2152         }
2153       else
2154         {
2155           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE5_UNSET;
2156           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE5_UNSET;
2157         }
2158       return true;
2159
2160     case OPT_mabm:
2161       if (value)
2162         {
2163           ix86_isa_flags |= OPTION_MASK_ISA_ABM_SET;
2164           ix86_isa_flags_explicit |= OPTION_MASK_ISA_ABM_SET;
2165         }
2166       else
2167         {
2168           ix86_isa_flags &= ~OPTION_MASK_ISA_ABM_UNSET;
2169           ix86_isa_flags_explicit |= OPTION_MASK_ISA_ABM_UNSET;
2170         }
2171       return true;
2172
2173     case OPT_mpopcnt:
2174       if (value)
2175         {
2176           ix86_isa_flags |= OPTION_MASK_ISA_POPCNT_SET;
2177           ix86_isa_flags_explicit |= OPTION_MASK_ISA_POPCNT_SET;
2178         }
2179       else
2180         {
2181           ix86_isa_flags &= ~OPTION_MASK_ISA_POPCNT_UNSET;
2182           ix86_isa_flags_explicit |= OPTION_MASK_ISA_POPCNT_UNSET;
2183         }
2184       return true;
2185
2186     case OPT_msahf:
2187       if (value)
2188         {
2189           ix86_isa_flags |= OPTION_MASK_ISA_SAHF_SET;
2190           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SAHF_SET;
2191         }
2192       else
2193         {
2194           ix86_isa_flags &= ~OPTION_MASK_ISA_SAHF_UNSET;
2195           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SAHF_UNSET;
2196         }
2197       return true;
2198
2199     case OPT_mcx16:
2200       if (value)
2201         {
2202           ix86_isa_flags |= OPTION_MASK_ISA_CX16_SET;
2203           ix86_isa_flags_explicit |= OPTION_MASK_ISA_CX16_SET;
2204         }
2205       else
2206         {
2207           ix86_isa_flags &= ~OPTION_MASK_ISA_CX16_UNSET;
2208           ix86_isa_flags_explicit |= OPTION_MASK_ISA_CX16_UNSET;
2209         }
2210       return true;
2211
2212     case OPT_maes:
2213       if (value)
2214         {
2215           ix86_isa_flags |= OPTION_MASK_ISA_AES_SET;
2216           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AES_SET;
2217         }
2218       else
2219         {
2220           ix86_isa_flags &= ~OPTION_MASK_ISA_AES_UNSET;
2221           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AES_UNSET;
2222         }
2223       return true;
2224
2225     case OPT_mpclmul:
2226       if (value)
2227         {
2228           ix86_isa_flags |= OPTION_MASK_ISA_PCLMUL_SET;
2229           ix86_isa_flags_explicit |= OPTION_MASK_ISA_PCLMUL_SET;
2230         }
2231       else
2232         {
2233           ix86_isa_flags &= ~OPTION_MASK_ISA_PCLMUL_UNSET;
2234           ix86_isa_flags_explicit |= OPTION_MASK_ISA_PCLMUL_UNSET;
2235         }
2236       return true;
2237
2238     default:
2239       return true;
2240     }
2241 }
2242 \f
2243 /* Return a string the documents the current -m options.  The caller is
2244    responsible for freeing the string.  */
2245
2246 static char *
2247 ix86_target_string (int isa, int flags, const char *arch, const char *tune,
2248                     const char *fpmath, bool add_nl_p)
2249 {
2250   struct ix86_target_opts
2251   {
2252     const char *option;         /* option string */
2253     int mask;                   /* isa mask options */
2254   };
2255
2256   /* This table is ordered so that options like -msse5 or -msse4.2 that imply
2257      preceding options while match those first.  */
2258   static struct ix86_target_opts isa_opts[] =
2259   {
2260     { "-m64",           OPTION_MASK_ISA_64BIT },
2261     { "-msse5",         OPTION_MASK_ISA_SSE5 },
2262     { "-msse4a",        OPTION_MASK_ISA_SSE4A },
2263     { "-msse4.2",       OPTION_MASK_ISA_SSE4_2 },
2264     { "-msse4.1",       OPTION_MASK_ISA_SSE4_1 },
2265     { "-mssse3",        OPTION_MASK_ISA_SSSE3 },
2266     { "-msse3",         OPTION_MASK_ISA_SSE3 },
2267     { "-msse2",         OPTION_MASK_ISA_SSE2 },
2268     { "-msse",          OPTION_MASK_ISA_SSE },
2269     { "-m3dnow",        OPTION_MASK_ISA_3DNOW },
2270     { "-m3dnowa",       OPTION_MASK_ISA_3DNOW_A },
2271     { "-mmmx",          OPTION_MASK_ISA_MMX },
2272     { "-mabm",          OPTION_MASK_ISA_ABM },
2273     { "-mpopcnt",       OPTION_MASK_ISA_POPCNT },
2274     { "-maes",          OPTION_MASK_ISA_AES },
2275     { "-mpclmul",       OPTION_MASK_ISA_PCLMUL },
2276   };
2277
2278   /* Flag options.  */
2279   static struct ix86_target_opts flag_opts[] =
2280   {
2281     { "-m128bit-long-double",           MASK_128BIT_LONG_DOUBLE },
2282     { "-m80387",                        MASK_80387 },
2283     { "-maccumulate-outgoing-args",     MASK_ACCUMULATE_OUTGOING_ARGS },
2284     { "-malign-double",                 MASK_ALIGN_DOUBLE },
2285     { "-mcld",                          MASK_CLD },
2286     { "-mfp-ret-in-387",                MASK_FLOAT_RETURNS },
2287     { "-mieee-fp",                      MASK_IEEE_FP },
2288     { "-minline-all-stringops",         MASK_INLINE_ALL_STRINGOPS },
2289     { "-minline-stringops-dynamically", MASK_INLINE_STRINGOPS_DYNAMICALLY },
2290     { "-mms-bitfields",                 MASK_MS_BITFIELD_LAYOUT },
2291     { "-mno-align-stringops",           MASK_NO_ALIGN_STRINGOPS },
2292     { "-mno-fancy-math-387",            MASK_NO_FANCY_MATH_387 },
2293     { "-mno-fused-madd",                MASK_NO_FUSED_MADD },
2294     { "-mno-push-args",                 MASK_NO_PUSH_ARGS },
2295     { "-mno-red-zone",                  MASK_NO_RED_ZONE },
2296     { "-momit-leaf-frame-pointer",      MASK_OMIT_LEAF_FRAME_POINTER },
2297     { "-mrecip",                        MASK_RECIP },
2298     { "-mrtd",                          MASK_RTD },
2299     { "-msseregparm",                   MASK_SSEREGPARM },
2300     { "-mstack-arg-probe",              MASK_STACK_PROBE },
2301     { "-mtls-direct-seg-refs",          MASK_TLS_DIRECT_SEG_REFS },
2302   };
2303
2304   const char *opts[ARRAY_SIZE (isa_opts) + ARRAY_SIZE (flag_opts) + 6][2];
2305
2306   char isa_other[40];
2307   char target_other[40];
2308   unsigned num = 0;
2309   unsigned i, j;
2310   char *ret;
2311   char *ptr;
2312   size_t len;
2313   size_t line_len;
2314   size_t sep_len;
2315
2316   memset (opts, '\0', sizeof (opts));
2317
2318   /* Add -march= option.  */
2319   if (arch)
2320     {
2321       opts[num][0] = "-march=";
2322       opts[num++][1] = arch;
2323     }
2324
2325   /* Add -mtune= option.  */
2326   if (tune)
2327     {
2328       opts[num][0] = "-mtune=";
2329       opts[num++][1] = tune;
2330     }
2331
2332   /* Pick out the options in isa options.  */
2333   for (i = 0; i < ARRAY_SIZE (isa_opts); i++)
2334     {
2335       if ((isa & isa_opts[i].mask) != 0)
2336         {
2337           opts[num++][0] = isa_opts[i].option;
2338           isa &= ~ isa_opts[i].mask;
2339         }
2340     }
2341
2342   if (isa && add_nl_p)
2343     {
2344       opts[num++][0] = isa_other;
2345       sprintf (isa_other, "(other isa: 0x%x)", isa);
2346     }
2347
2348   /* Add flag options.  */
2349   for (i = 0; i < ARRAY_SIZE (flag_opts); i++)
2350     {
2351       if ((flags & flag_opts[i].mask) != 0)
2352         {
2353           opts[num++][0] = flag_opts[i].option;
2354           flags &= ~ flag_opts[i].mask;
2355         }
2356     }
2357
2358   if (flags && add_nl_p)
2359     {
2360       opts[num++][0] = target_other;
2361       sprintf (target_other, "(other flags: 0x%x)", flags);
2362     }
2363
2364   /* Add -fpmath= option.  */
2365   if (fpmath)
2366     {
2367       opts[num][0] = "-mfpmath=";
2368       opts[num++][1] = fpmath;
2369     }
2370
2371   /* Any options?  */
2372   if (num == 0)
2373     return NULL;
2374
2375   gcc_assert (num < ARRAY_SIZE (opts));
2376
2377   /* Size the string.  */
2378   len = 0;
2379   sep_len = (add_nl_p) ? 3 : 1;
2380   for (i = 0; i < num; i++)
2381     {
2382       len += sep_len;
2383       for (j = 0; j < 2; j++)
2384         if (opts[i][j])
2385           len += strlen (opts[i][j]);
2386     }
2387
2388   /* Build the string.  */
2389   ret = ptr = (char *) xmalloc (len);
2390   line_len = 0;
2391
2392   for (i = 0; i < num; i++)
2393     {
2394       size_t len2[2];
2395
2396       for (j = 0; j < 2; j++)
2397         len2[j] = (opts[i][j]) ? strlen (opts[i][j]) : 0;
2398
2399       if (i != 0)
2400         {
2401           *ptr++ = ' ';
2402           line_len++;
2403
2404           if (add_nl_p && line_len + len2[0] + len2[1] > 70)
2405             {
2406               *ptr++ = '\\';
2407               *ptr++ = '\n';
2408               line_len = 0;
2409             }
2410         }
2411
2412       for (j = 0; j < 2; j++)
2413         if (opts[i][j])
2414           {
2415             memcpy (ptr, opts[i][j], len2[j]);
2416             ptr += len2[j];
2417             line_len += len2[j];
2418           }
2419     }
2420
2421   *ptr = '\0';
2422   gcc_assert (ret + len >= ptr);
2423
2424   return ret;
2425 }
2426
2427 /* Function that is callable from the debugger to print the current
2428    options.  */
2429 void
2430 ix86_debug_options (void)
2431 {
2432   char *opts = ix86_target_string (ix86_isa_flags, target_flags,
2433                                    ix86_arch_string, ix86_tune_string,
2434                                    ix86_fpmath_string, true);
2435
2436   if (opts)
2437     {
2438       fprintf (stderr, "%s\n\n", opts);
2439       free (opts);
2440     }
2441   else
2442     fprintf (stderr, "<no options>\n\n");
2443
2444   return;
2445 }
2446 \f
2447 /* Sometimes certain combinations of command options do not make
2448    sense on a particular target machine.  You can define a macro
2449    `OVERRIDE_OPTIONS' to take account of this.  This macro, if
2450    defined, is executed once just after all the command options have
2451    been parsed.
2452
2453    Don't use this macro to turn on various extra optimizations for
2454    `-O'.  That is what `OPTIMIZATION_OPTIONS' is for.  */
2455
2456 void
2457 override_options (bool main_args_p)
2458 {
2459   int i;
2460   unsigned int ix86_arch_mask, ix86_tune_mask;
2461   const char *prefix;
2462   const char *suffix;
2463   const char *sw;
2464
2465   /* Comes from final.c -- no real reason to change it.  */
2466 #define MAX_CODE_ALIGN 16
2467
2468   enum pta_flags
2469     {
2470       PTA_SSE = 1 << 0,
2471       PTA_SSE2 = 1 << 1,
2472       PTA_SSE3 = 1 << 2,
2473       PTA_MMX = 1 << 3,
2474       PTA_PREFETCH_SSE = 1 << 4,
2475       PTA_3DNOW = 1 << 5,
2476       PTA_3DNOW_A = 1 << 6,
2477       PTA_64BIT = 1 << 7,
2478       PTA_SSSE3 = 1 << 8,
2479       PTA_CX16 = 1 << 9,
2480       PTA_POPCNT = 1 << 10,
2481       PTA_ABM = 1 << 11,
2482       PTA_SSE4A = 1 << 12,
2483       PTA_NO_SAHF = 1 << 13,
2484       PTA_SSE4_1 = 1 << 14,
2485       PTA_SSE4_2 = 1 << 15,
2486       PTA_SSE5 = 1 << 16,
2487       PTA_AES = 1 << 17,
2488       PTA_PCLMUL = 1 << 18,
2489       PTA_AVX = 1 << 19,
2490       PTA_FMA = 1 << 20 
2491     };
2492
2493   static struct pta
2494     {
2495       const char *const name;           /* processor name or nickname.  */
2496       const enum processor_type processor;
2497       const enum attr_cpu schedule;
2498       const unsigned /*enum pta_flags*/ flags;
2499     }
2500   const processor_alias_table[] =
2501     {
2502       {"i386", PROCESSOR_I386, CPU_NONE, 0},
2503       {"i486", PROCESSOR_I486, CPU_NONE, 0},
2504       {"i586", PROCESSOR_PENTIUM, CPU_PENTIUM, 0},
2505       {"pentium", PROCESSOR_PENTIUM, CPU_PENTIUM, 0},
2506       {"pentium-mmx", PROCESSOR_PENTIUM, CPU_PENTIUM, PTA_MMX},
2507       {"winchip-c6", PROCESSOR_I486, CPU_NONE, PTA_MMX},
2508       {"winchip2", PROCESSOR_I486, CPU_NONE, PTA_MMX | PTA_3DNOW},
2509       {"c3", PROCESSOR_I486, CPU_NONE, PTA_MMX | PTA_3DNOW},
2510       {"c3-2", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, PTA_MMX | PTA_SSE},
2511       {"i686", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, 0},
2512       {"pentiumpro", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, 0},
2513       {"pentium2", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, PTA_MMX},
2514       {"pentium3", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
2515         PTA_MMX | PTA_SSE},
2516       {"pentium3m", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
2517         PTA_MMX | PTA_SSE},
2518       {"pentium-m", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
2519         PTA_MMX | PTA_SSE | PTA_SSE2},
2520       {"pentium4", PROCESSOR_PENTIUM4, CPU_NONE,
2521         PTA_MMX |PTA_SSE | PTA_SSE2},
2522       {"pentium4m", PROCESSOR_PENTIUM4, CPU_NONE,
2523         PTA_MMX | PTA_SSE | PTA_SSE2},
2524       {"prescott", PROCESSOR_NOCONA, CPU_NONE,
2525         PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3},
2526       {"nocona", PROCESSOR_NOCONA, CPU_NONE,
2527         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
2528         | PTA_CX16 | PTA_NO_SAHF},
2529       {"core2", PROCESSOR_CORE2, CPU_CORE2,
2530         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
2531         | PTA_SSSE3 | PTA_CX16},
2532       {"geode", PROCESSOR_GEODE, CPU_GEODE,
2533         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A |PTA_PREFETCH_SSE},
2534       {"k6", PROCESSOR_K6, CPU_K6, PTA_MMX},
2535       {"k6-2", PROCESSOR_K6, CPU_K6, PTA_MMX | PTA_3DNOW},
2536       {"k6-3", PROCESSOR_K6, CPU_K6, PTA_MMX | PTA_3DNOW},
2537       {"athlon", PROCESSOR_ATHLON, CPU_ATHLON,
2538         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_PREFETCH_SSE},
2539       {"athlon-tbird", PROCESSOR_ATHLON, CPU_ATHLON,
2540         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_PREFETCH_SSE},
2541       {"athlon-4", PROCESSOR_ATHLON, CPU_ATHLON,
2542         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE},
2543       {"athlon-xp", PROCESSOR_ATHLON, CPU_ATHLON,
2544         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE},
2545       {"athlon-mp", PROCESSOR_ATHLON, CPU_ATHLON,
2546         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE},
2547       {"x86-64", PROCESSOR_K8, CPU_K8,
2548         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_NO_SAHF},
2549       {"k8", PROCESSOR_K8, CPU_K8,
2550         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2551         | PTA_SSE2 | PTA_NO_SAHF},
2552       {"k8-sse3", PROCESSOR_K8, CPU_K8,
2553         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2554         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF},
2555       {"opteron", PROCESSOR_K8, CPU_K8,
2556         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2557         | PTA_SSE2 | PTA_NO_SAHF},
2558       {"opteron-sse3", PROCESSOR_K8, CPU_K8,
2559         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2560         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF},
2561       {"athlon64", PROCESSOR_K8, CPU_K8,
2562         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2563         | PTA_SSE2 | PTA_NO_SAHF},
2564       {"athlon64-sse3", PROCESSOR_K8, CPU_K8,
2565         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2566         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF},
2567       {"athlon-fx", PROCESSOR_K8, CPU_K8,
2568         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2569         | PTA_SSE2 | PTA_NO_SAHF},
2570       {"amdfam10", PROCESSOR_AMDFAM10, CPU_AMDFAM10,
2571         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2572         | PTA_SSE2 | PTA_SSE3 | PTA_SSE4A | PTA_CX16 | PTA_ABM},
2573       {"barcelona", PROCESSOR_AMDFAM10, CPU_AMDFAM10,
2574         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2575         | PTA_SSE2 | PTA_SSE3 | PTA_SSE4A | PTA_CX16 | PTA_ABM},
2576       {"generic32", PROCESSOR_GENERIC32, CPU_PENTIUMPRO,
2577         0 /* flags are only used for -march switch.  */ },
2578       {"generic64", PROCESSOR_GENERIC64, CPU_GENERIC64,
2579         PTA_64BIT /* flags are only used for -march switch.  */ },
2580     };
2581
2582   int const pta_size = ARRAY_SIZE (processor_alias_table);
2583
2584   /* Set up prefix/suffix so the error messages refer to either the command
2585      line argument, or the attribute(target).  */
2586   if (main_args_p)
2587     {
2588       prefix = "-m";
2589       suffix = "";
2590       sw = "switch";
2591     }
2592   else
2593     {
2594       prefix = "option(\"";
2595       suffix = "\")";
2596       sw = "attribute";
2597     }
2598
2599 #ifdef SUBTARGET_OVERRIDE_OPTIONS
2600   SUBTARGET_OVERRIDE_OPTIONS;
2601 #endif
2602
2603 #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
2604   SUBSUBTARGET_OVERRIDE_OPTIONS;
2605 #endif
2606
2607   /* -fPIC is the default for x86_64.  */
2608   if (TARGET_MACHO && TARGET_64BIT)
2609     flag_pic = 2;
2610
2611   /* Set the default values for switches whose default depends on TARGET_64BIT
2612      in case they weren't overwritten by command line options.  */
2613   if (TARGET_64BIT)
2614     {
2615       /* Mach-O doesn't support omitting the frame pointer for now.  */
2616       if (flag_omit_frame_pointer == 2)
2617         flag_omit_frame_pointer = (TARGET_MACHO ? 0 : 1);
2618       if (flag_asynchronous_unwind_tables == 2)
2619         flag_asynchronous_unwind_tables = 1;
2620       if (flag_pcc_struct_return == 2)
2621         flag_pcc_struct_return = 0;
2622     }
2623   else
2624     {
2625       if (flag_omit_frame_pointer == 2)
2626         flag_omit_frame_pointer = 0;
2627       if (flag_asynchronous_unwind_tables == 2)
2628         flag_asynchronous_unwind_tables = 0;
2629       if (flag_pcc_struct_return == 2)
2630         flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
2631     }
2632
2633   /* Need to check -mtune=generic first.  */
2634   if (ix86_tune_string)
2635     {
2636       if (!strcmp (ix86_tune_string, "generic")
2637           || !strcmp (ix86_tune_string, "i686")
2638           /* As special support for cross compilers we read -mtune=native
2639              as -mtune=generic.  With native compilers we won't see the
2640              -mtune=native, as it was changed by the driver.  */
2641           || !strcmp (ix86_tune_string, "native"))
2642         {
2643           if (TARGET_64BIT)
2644             ix86_tune_string = "generic64";
2645           else
2646             ix86_tune_string = "generic32";
2647         }
2648       /* If this call is for setting the option attribute, allow the
2649          generic32/generic64 that was previously set.  */
2650       else if (!main_args_p
2651                && (!strcmp (ix86_tune_string, "generic32")
2652                    || !strcmp (ix86_tune_string, "generic64")))
2653         ;
2654       else if (!strncmp (ix86_tune_string, "generic", 7))
2655         error ("bad value (%s) for %stune=%s %s",
2656                ix86_tune_string, prefix, suffix, sw);
2657     }
2658   else
2659     {
2660       if (ix86_arch_string)
2661         ix86_tune_string = ix86_arch_string;
2662       if (!ix86_tune_string)
2663         {
2664           ix86_tune_string = cpu_names[TARGET_CPU_DEFAULT];
2665           ix86_tune_defaulted = 1;
2666         }
2667
2668       /* ix86_tune_string is set to ix86_arch_string or defaulted.  We
2669          need to use a sensible tune option.  */
2670       if (!strcmp (ix86_tune_string, "generic")
2671           || !strcmp (ix86_tune_string, "x86-64")
2672           || !strcmp (ix86_tune_string, "i686"))
2673         {
2674           if (TARGET_64BIT)
2675             ix86_tune_string = "generic64";
2676           else
2677             ix86_tune_string = "generic32";
2678         }
2679     }
2680   if (ix86_stringop_string)
2681     {
2682       if (!strcmp (ix86_stringop_string, "rep_byte"))
2683         stringop_alg = rep_prefix_1_byte;
2684       else if (!strcmp (ix86_stringop_string, "libcall"))
2685         stringop_alg = libcall;
2686       else if (!strcmp (ix86_stringop_string, "rep_4byte"))
2687         stringop_alg = rep_prefix_4_byte;
2688       else if (!strcmp (ix86_stringop_string, "rep_8byte")
2689                && TARGET_64BIT)
2690         /* rep; movq isn't available in 32-bit code.  */
2691         stringop_alg = rep_prefix_8_byte;
2692       else if (!strcmp (ix86_stringop_string, "byte_loop"))
2693         stringop_alg = loop_1_byte;
2694       else if (!strcmp (ix86_stringop_string, "loop"))
2695         stringop_alg = loop;
2696       else if (!strcmp (ix86_stringop_string, "unrolled_loop"))
2697         stringop_alg = unrolled_loop;
2698       else
2699         error ("bad value (%s) for %sstringop-strategy=%s %s",
2700                ix86_stringop_string, prefix, suffix, sw);
2701     }
2702   if (!strcmp (ix86_tune_string, "x86-64"))
2703     warning (OPT_Wdeprecated, "%stune=x86-64%s is deprecated.  Use "
2704              "%stune=k8%s or %stune=generic%s instead as appropriate.",
2705              prefix, suffix, prefix, suffix, prefix, suffix);
2706
2707   if (!ix86_arch_string)
2708     ix86_arch_string = TARGET_64BIT ? "x86-64" : "i486";
2709   else
2710     ix86_arch_specified = 1;
2711
2712   if (!strcmp (ix86_arch_string, "generic"))
2713     error ("generic CPU can be used only for %stune=%s %s",
2714            prefix, suffix, sw);
2715   if (!strncmp (ix86_arch_string, "generic", 7))
2716     error ("bad value (%s) for %sarch=%s %s",
2717            ix86_arch_string, prefix, suffix, sw);
2718
2719   if (ix86_cmodel_string != 0)
2720     {
2721       if (!strcmp (ix86_cmodel_string, "small"))
2722         ix86_cmodel = flag_pic ? CM_SMALL_PIC : CM_SMALL;
2723       else if (!strcmp (ix86_cmodel_string, "medium"))
2724         ix86_cmodel = flag_pic ? CM_MEDIUM_PIC : CM_MEDIUM;
2725       else if (!strcmp (ix86_cmodel_string, "large"))
2726         ix86_cmodel = flag_pic ? CM_LARGE_PIC : CM_LARGE;
2727       else if (flag_pic)
2728         error ("code model %s does not support PIC mode", ix86_cmodel_string);
2729       else if (!strcmp (ix86_cmodel_string, "32"))
2730         ix86_cmodel = CM_32;
2731       else if (!strcmp (ix86_cmodel_string, "kernel") && !flag_pic)
2732         ix86_cmodel = CM_KERNEL;
2733       else
2734         error ("bad value (%s) for %scmodel=%s %s",
2735                ix86_cmodel_string, prefix, suffix, sw);
2736     }
2737   else
2738     {
2739       /* For TARGET_64BIT and MS_ABI, force pic on, in order to enable the
2740          use of rip-relative addressing.  This eliminates fixups that
2741          would otherwise be needed if this object is to be placed in a
2742          DLL, and is essentially just as efficient as direct addressing.  */
2743       if (TARGET_64BIT && DEFAULT_ABI == MS_ABI)
2744         ix86_cmodel = CM_SMALL_PIC, flag_pic = 1;
2745       else if (TARGET_64BIT)
2746         ix86_cmodel = flag_pic ? CM_SMALL_PIC : CM_SMALL;
2747       else
2748         ix86_cmodel = CM_32;
2749     }
2750   if (ix86_asm_string != 0)
2751     {
2752       if (! TARGET_MACHO
2753           && !strcmp (ix86_asm_string, "intel"))
2754         ix86_asm_dialect = ASM_INTEL;
2755       else if (!strcmp (ix86_asm_string, "att"))
2756         ix86_asm_dialect = ASM_ATT;
2757       else
2758         error ("bad value (%s) for %sasm=%s %s",
2759                ix86_asm_string, prefix, suffix, sw);
2760     }
2761   if ((TARGET_64BIT == 0) != (ix86_cmodel == CM_32))
2762     error ("code model %qs not supported in the %s bit mode",
2763            ix86_cmodel_string, TARGET_64BIT ? "64" : "32");
2764   if ((TARGET_64BIT != 0) != ((ix86_isa_flags & OPTION_MASK_ISA_64BIT) != 0))
2765     sorry ("%i-bit mode not compiled in",
2766            (ix86_isa_flags & OPTION_MASK_ISA_64BIT) ? 64 : 32);
2767
2768   for (i = 0; i < pta_size; i++)
2769     if (! strcmp (ix86_arch_string, processor_alias_table[i].name))
2770       {
2771         ix86_schedule = processor_alias_table[i].schedule;
2772         ix86_arch = processor_alias_table[i].processor;
2773         /* Default cpu tuning to the architecture.  */
2774         ix86_tune = ix86_arch;
2775
2776         if (TARGET_64BIT && !(processor_alias_table[i].flags & PTA_64BIT))
2777           error ("CPU you selected does not support x86-64 "
2778                  "instruction set");
2779
2780         if (processor_alias_table[i].flags & PTA_MMX
2781             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_MMX))
2782           ix86_isa_flags |= OPTION_MASK_ISA_MMX;
2783         if (processor_alias_table[i].flags & PTA_3DNOW
2784             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW))
2785           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW;
2786         if (processor_alias_table[i].flags & PTA_3DNOW_A
2787             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW_A))
2788           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_A;
2789         if (processor_alias_table[i].flags & PTA_SSE
2790             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE))
2791           ix86_isa_flags |= OPTION_MASK_ISA_SSE;
2792         if (processor_alias_table[i].flags & PTA_SSE2
2793             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE2))
2794           ix86_isa_flags |= OPTION_MASK_ISA_SSE2;
2795         if (processor_alias_table[i].flags & PTA_SSE3
2796             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE3))
2797           ix86_isa_flags |= OPTION_MASK_ISA_SSE3;
2798         if (processor_alias_table[i].flags & PTA_SSSE3
2799             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSSE3))
2800           ix86_isa_flags |= OPTION_MASK_ISA_SSSE3;
2801         if (processor_alias_table[i].flags & PTA_SSE4_1
2802             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_1))
2803           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1;
2804         if (processor_alias_table[i].flags & PTA_SSE4_2
2805             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_2))
2806           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2;
2807         if (processor_alias_table[i].flags & PTA_AVX
2808             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX))
2809           ix86_isa_flags |= OPTION_MASK_ISA_AVX;
2810         if (processor_alias_table[i].flags & PTA_FMA
2811             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_FMA))
2812           ix86_isa_flags |= OPTION_MASK_ISA_FMA;
2813         if (processor_alias_table[i].flags & PTA_SSE4A
2814             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4A))
2815           ix86_isa_flags |= OPTION_MASK_ISA_SSE4A;
2816         if (processor_alias_table[i].flags & PTA_SSE5
2817             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE5))
2818           ix86_isa_flags |= OPTION_MASK_ISA_SSE5;
2819         if (processor_alias_table[i].flags & PTA_ABM
2820             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_ABM))
2821           ix86_isa_flags |= OPTION_MASK_ISA_ABM;
2822         if (processor_alias_table[i].flags & PTA_CX16
2823             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_CX16))
2824           ix86_isa_flags |= OPTION_MASK_ISA_CX16;
2825         if (processor_alias_table[i].flags & (PTA_POPCNT | PTA_ABM)
2826             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_POPCNT))
2827           ix86_isa_flags |= OPTION_MASK_ISA_POPCNT;
2828         if (!(TARGET_64BIT && (processor_alias_table[i].flags & PTA_NO_SAHF))
2829             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SAHF))
2830           ix86_isa_flags |= OPTION_MASK_ISA_SAHF;
2831         if (processor_alias_table[i].flags & PTA_AES
2832             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_AES))
2833           ix86_isa_flags |= OPTION_MASK_ISA_AES;
2834         if (processor_alias_table[i].flags & PTA_PCLMUL
2835             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_PCLMUL))
2836           ix86_isa_flags |= OPTION_MASK_ISA_PCLMUL;
2837         if (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE))
2838           x86_prefetch_sse = true;
2839
2840         break;
2841       }
2842
2843   if (i == pta_size)
2844     error ("bad value (%s) for %sarch=%s %s",
2845            ix86_arch_string, prefix, suffix, sw);
2846
2847   ix86_arch_mask = 1u << ix86_arch;
2848   for (i = 0; i < X86_ARCH_LAST; ++i)
2849     ix86_arch_features[i] = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
2850
2851   for (i = 0; i < pta_size; i++)
2852     if (! strcmp (ix86_tune_string, processor_alias_table[i].name))
2853       {
2854         ix86_schedule = processor_alias_table[i].schedule;
2855         ix86_tune = processor_alias_table[i].processor;
2856         if (TARGET_64BIT && !(processor_alias_table[i].flags & PTA_64BIT))
2857           {
2858             if (ix86_tune_defaulted)
2859               {
2860                 ix86_tune_string = "x86-64";
2861                 for (i = 0; i < pta_size; i++)
2862                   if (! strcmp (ix86_tune_string,
2863                                 processor_alias_table[i].name))
2864                     break;
2865                 ix86_schedule = processor_alias_table[i].schedule;
2866                 ix86_tune = processor_alias_table[i].processor;
2867               }
2868             else
2869               error ("CPU you selected does not support x86-64 "
2870                      "instruction set");
2871           }
2872         /* Intel CPUs have always interpreted SSE prefetch instructions as
2873            NOPs; so, we can enable SSE prefetch instructions even when
2874            -mtune (rather than -march) points us to a processor that has them.
2875            However, the VIA C3 gives a SIGILL, so we only do that for i686 and
2876            higher processors.  */
2877         if (TARGET_CMOVE
2878             && (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE)))
2879           x86_prefetch_sse = true;
2880         break;
2881       }
2882   if (i == pta_size)
2883     error ("bad value (%s) for %stune=%s %s",
2884            ix86_tune_string, prefix, suffix, sw);
2885
2886   ix86_tune_mask = 1u << ix86_tune;
2887   for (i = 0; i < X86_TUNE_LAST; ++i)
2888     ix86_tune_features[i] = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
2889
2890   if (optimize_size)
2891     ix86_cost = &ix86_size_cost;
2892   else
2893     ix86_cost = processor_target_table[ix86_tune].cost;
2894
2895   /* Arrange to set up i386_stack_locals for all functions.  */
2896   init_machine_status = ix86_init_machine_status;
2897
2898   /* Validate -mregparm= value.  */
2899   if (ix86_regparm_string)
2900     {
2901       if (TARGET_64BIT)
2902         warning (0, "%sregparm%s is ignored in 64-bit mode", prefix, suffix);
2903       i = atoi (ix86_regparm_string);
2904       if (i < 0 || i > REGPARM_MAX)
2905         error ("%sregparm=%d%s is not between 0 and %d",
2906                prefix, i, suffix, REGPARM_MAX);
2907       else
2908         ix86_regparm = i;
2909     }
2910   if (TARGET_64BIT)
2911     ix86_regparm = REGPARM_MAX;
2912
2913   /* If the user has provided any of the -malign-* options,
2914      warn and use that value only if -falign-* is not set.
2915      Remove this code in GCC 3.2 or later.  */
2916   if (ix86_align_loops_string)
2917     {
2918       warning (0, "%salign-loops%s is obsolete, use -falign-loops%s",
2919                prefix, suffix, suffix);
2920       if (align_loops == 0)
2921         {
2922           i = atoi (ix86_align_loops_string);
2923           if (i < 0 || i > MAX_CODE_ALIGN)
2924             error ("%salign-loops=%d%s is not between 0 and %d",
2925                    prefix, i, suffix, MAX_CODE_ALIGN);
2926           else
2927             align_loops = 1 << i;
2928         }
2929     }
2930
2931   if (ix86_align_jumps_string)
2932     {
2933       warning (0, "%salign-jumps%s is obsolete, use -falign-jumps%s",
2934                prefix, suffix, suffix);
2935       if (align_jumps == 0)
2936         {
2937           i = atoi (ix86_align_jumps_string);
2938           if (i < 0 || i > MAX_CODE_ALIGN)
2939             error ("%salign-loops=%d%s is not between 0 and %d",
2940                    prefix, i, suffix, MAX_CODE_ALIGN);
2941           else
2942             align_jumps = 1 << i;
2943         }
2944     }
2945
2946   if (ix86_align_funcs_string)
2947     {
2948       warning (0, "%salign-functions%s is obsolete, use -falign-functions%s",
2949                prefix, suffix, suffix);
2950       if (align_functions == 0)
2951         {
2952           i = atoi (ix86_align_funcs_string);
2953           if (i < 0 || i > MAX_CODE_ALIGN)
2954             error ("%salign-loops=%d%s is not between 0 and %d",
2955                    prefix, i, suffix, MAX_CODE_ALIGN);
2956           else
2957             align_functions = 1 << i;
2958         }
2959     }
2960
2961   /* Default align_* from the processor table.  */
2962   if (align_loops == 0)
2963     {
2964       align_loops = processor_target_table[ix86_tune].align_loop;
2965       align_loops_max_skip = processor_target_table[ix86_tune].align_loop_max_skip;
2966     }
2967   if (align_jumps == 0)
2968     {
2969       align_jumps = processor_target_table[ix86_tune].align_jump;
2970       align_jumps_max_skip = processor_target_table[ix86_tune].align_jump_max_skip;
2971     }
2972   if (align_functions == 0)
2973     {
2974       align_functions = processor_target_table[ix86_tune].align_func;
2975     }
2976
2977   /* Validate -mbranch-cost= value, or provide default.  */
2978   ix86_branch_cost = ix86_cost->branch_cost;
2979   if (ix86_branch_cost_string)
2980     {
2981       i = atoi (ix86_branch_cost_string);
2982       if (i < 0 || i > 5)
2983         error ("%sbranch-cost=%d%s is not between 0 and 5", prefix, i, suffix);
2984       else
2985         ix86_branch_cost = i;
2986     }
2987   if (ix86_section_threshold_string)
2988     {
2989       i = atoi (ix86_section_threshold_string);
2990       if (i < 0)
2991         error ("%slarge-data-threshold=%d%s is negative", prefix, i, suffix);
2992       else
2993         ix86_section_threshold = i;
2994     }
2995
2996   if (ix86_tls_dialect_string)
2997     {
2998       if (strcmp (ix86_tls_dialect_string, "gnu") == 0)
2999         ix86_tls_dialect = TLS_DIALECT_GNU;
3000       else if (strcmp (ix86_tls_dialect_string, "gnu2") == 0)
3001         ix86_tls_dialect = TLS_DIALECT_GNU2;
3002       else if (strcmp (ix86_tls_dialect_string, "sun") == 0)
3003         ix86_tls_dialect = TLS_DIALECT_SUN;
3004       else
3005         error ("bad value (%s) for %stls-dialect=%s %s",
3006                ix86_tls_dialect_string, prefix, suffix, sw);
3007     }
3008
3009   if (ix87_precision_string)
3010     {
3011       i = atoi (ix87_precision_string);
3012       if (i != 32 && i != 64 && i != 80)
3013         error ("pc%d is not valid precision setting (32, 64 or 80)", i);
3014     }
3015
3016   if (TARGET_64BIT)
3017     {
3018       target_flags |= TARGET_SUBTARGET64_DEFAULT & ~target_flags_explicit;
3019
3020       /* Enable by default the SSE and MMX builtins.  Do allow the user to
3021          explicitly disable any of these.  In particular, disabling SSE and
3022          MMX for kernel code is extremely useful.  */
3023       if (!ix86_arch_specified)
3024       ix86_isa_flags
3025         |= ((OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_MMX
3026              | TARGET_SUBTARGET64_ISA_DEFAULT) & ~ix86_isa_flags_explicit);
3027
3028       if (TARGET_RTD)
3029         warning (0, "%srtd%s is ignored in 64bit mode", prefix, suffix);
3030     }
3031   else
3032     {
3033       target_flags |= TARGET_SUBTARGET32_DEFAULT & ~target_flags_explicit;
3034
3035       if (!ix86_arch_specified)
3036       ix86_isa_flags
3037         |= TARGET_SUBTARGET32_ISA_DEFAULT & ~ix86_isa_flags_explicit;
3038
3039       /* i386 ABI does not specify red zone.  It still makes sense to use it
3040          when programmer takes care to stack from being destroyed.  */
3041       if (!(target_flags_explicit & MASK_NO_RED_ZONE))
3042         target_flags |= MASK_NO_RED_ZONE;
3043     }
3044
3045   /* Keep nonleaf frame pointers.  */
3046   if (flag_omit_frame_pointer)
3047     target_flags &= ~MASK_OMIT_LEAF_FRAME_POINTER;
3048   else if (TARGET_OMIT_LEAF_FRAME_POINTER)
3049     flag_omit_frame_pointer = 1;
3050
3051   /* If we're doing fast math, we don't care about comparison order
3052      wrt NaNs.  This lets us use a shorter comparison sequence.  */
3053   if (flag_finite_math_only)
3054     target_flags &= ~MASK_IEEE_FP;
3055
3056   /* If the architecture always has an FPU, turn off NO_FANCY_MATH_387,
3057      since the insns won't need emulation.  */
3058   if (x86_arch_always_fancy_math_387 & ix86_arch_mask)
3059     target_flags &= ~MASK_NO_FANCY_MATH_387;
3060
3061   /* Likewise, if the target doesn't have a 387, or we've specified
3062      software floating point, don't use 387 inline intrinsics.  */
3063   if (!TARGET_80387)
3064     target_flags |= MASK_NO_FANCY_MATH_387;
3065
3066   /* Turn on MMX builtins for -msse.  */
3067   if (TARGET_SSE)
3068     {
3069       ix86_isa_flags |= OPTION_MASK_ISA_MMX & ~ix86_isa_flags_explicit;
3070       x86_prefetch_sse = true;
3071     }
3072
3073   /* Turn on popcnt instruction for -msse4.2 or -mabm.  */
3074   if (TARGET_SSE4_2 || TARGET_ABM)
3075     ix86_isa_flags |= OPTION_MASK_ISA_POPCNT & ~ix86_isa_flags_explicit;
3076
3077   /* Validate -mpreferred-stack-boundary= value or default it to
3078      PREFERRED_STACK_BOUNDARY_DEFAULT.  */
3079   ix86_preferred_stack_boundary = PREFERRED_STACK_BOUNDARY_DEFAULT;
3080   if (ix86_preferred_stack_boundary_string)
3081     {
3082       i = atoi (ix86_preferred_stack_boundary_string);
3083       if (i < (TARGET_64BIT ? 4 : 2) || i > 12)
3084         error ("%spreferred-stack-boundary=%d%s is not between %d and 12",
3085                prefix, i, suffix, TARGET_64BIT ? 4 : 2);
3086       else
3087         ix86_preferred_stack_boundary = (1 << i) * BITS_PER_UNIT;
3088     }
3089
3090   /* Set the default value for -mstackrealign.  */
3091   if (ix86_force_align_arg_pointer == -1)
3092     ix86_force_align_arg_pointer = STACK_REALIGN_DEFAULT;
3093
3094   /* Validate -mincoming-stack-boundary= value or default it to
3095      MIN_STACK_BOUNDARY/PREFERRED_STACK_BOUNDARY.  */
3096   if (ix86_force_align_arg_pointer)
3097     ix86_default_incoming_stack_boundary = MIN_STACK_BOUNDARY;
3098   else
3099     ix86_default_incoming_stack_boundary = PREFERRED_STACK_BOUNDARY;
3100   ix86_incoming_stack_boundary = ix86_default_incoming_stack_boundary;
3101   if (ix86_incoming_stack_boundary_string)
3102     {
3103       i = atoi (ix86_incoming_stack_boundary_string);
3104       if (i < (TARGET_64BIT ? 4 : 2) || i > 12)
3105         error ("-mincoming-stack-boundary=%d is not between %d and 12",
3106                i, TARGET_64BIT ? 4 : 2);
3107       else
3108         {
3109           ix86_user_incoming_stack_boundary = (1 << i) * BITS_PER_UNIT;
3110           ix86_incoming_stack_boundary
3111             = ix86_user_incoming_stack_boundary;
3112         }
3113     }
3114
3115   /* Accept -msseregparm only if at least SSE support is enabled.  */
3116   if (TARGET_SSEREGPARM
3117       && ! TARGET_SSE)
3118     error ("%ssseregparm%s used without SSE enabled", prefix, suffix);
3119
3120   ix86_fpmath = TARGET_FPMATH_DEFAULT;
3121   if (ix86_fpmath_string != 0)
3122     {
3123       if (! strcmp (ix86_fpmath_string, "387"))
3124         ix86_fpmath = FPMATH_387;
3125       else if (! strcmp (ix86_fpmath_string, "sse"))
3126         {
3127           if (!TARGET_SSE)
3128             {
3129               warning (0, "SSE instruction set disabled, using 387 arithmetics");
3130               ix86_fpmath = FPMATH_387;
3131             }
3132           else
3133             ix86_fpmath = FPMATH_SSE;
3134         }
3135       else if (! strcmp (ix86_fpmath_string, "387,sse")
3136                || ! strcmp (ix86_fpmath_string, "387+sse")
3137                || ! strcmp (ix86_fpmath_string, "sse,387")
3138                || ! strcmp (ix86_fpmath_string, "sse+387")
3139                || ! strcmp (ix86_fpmath_string, "both"))
3140         {
3141           if (!TARGET_SSE)
3142             {
3143               warning (0, "SSE instruction set disabled, using 387 arithmetics");
3144               ix86_fpmath = FPMATH_387;
3145             }
3146           else if (!TARGET_80387)
3147             {
3148               warning (0, "387 instruction set disabled, using SSE arithmetics");
3149               ix86_fpmath = FPMATH_SSE;
3150             }
3151           else
3152             ix86_fpmath = (enum fpmath_unit) (FPMATH_SSE | FPMATH_387);
3153         }
3154       else
3155         error ("bad value (%s) for %sfpmath=%s %s",
3156                ix86_fpmath_string, prefix, suffix, sw);
3157     }
3158
3159   /* If the i387 is disabled, then do not return values in it. */
3160   if (!TARGET_80387)
3161     target_flags &= ~MASK_FLOAT_RETURNS;
3162
3163   /* Use external vectorized library in vectorizing intrinsics.  */
3164   if (ix86_veclibabi_string)
3165     {
3166       if (strcmp (ix86_veclibabi_string, "svml") == 0)
3167         ix86_veclib_handler = ix86_veclibabi_svml;
3168       else if (strcmp (ix86_veclibabi_string, "acml") == 0)
3169         ix86_veclib_handler = ix86_veclibabi_acml;
3170       else
3171         error ("unknown vectorization library ABI type (%s) for "
3172                "%sveclibabi=%s %s", ix86_veclibabi_string,
3173                prefix, suffix, sw);
3174     }
3175
3176   if ((x86_accumulate_outgoing_args & ix86_tune_mask)
3177       && !(target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3178       && !optimize_size)
3179     target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3180
3181   /* ??? Unwind info is not correct around the CFG unless either a frame
3182      pointer is present or M_A_O_A is set.  Fixing this requires rewriting
3183      unwind info generation to be aware of the CFG and propagating states
3184      around edges.  */
3185   if ((flag_unwind_tables || flag_asynchronous_unwind_tables
3186        || flag_exceptions || flag_non_call_exceptions)
3187       && flag_omit_frame_pointer
3188       && !(target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
3189     {
3190       if (target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3191         warning (0, "unwind tables currently require either a frame pointer "
3192                  "or %saccumulate-outgoing-args%s for correctness",
3193                  prefix, suffix);
3194       target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3195     }
3196
3197   /* If stack probes are required, the space used for large function
3198      arguments on the stack must also be probed, so enable
3199      -maccumulate-outgoing-args so this happens in the prologue.  */
3200   if (TARGET_STACK_PROBE
3201       && !(target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
3202     {
3203       if (target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3204         warning (0, "stack probing requires %saccumulate-outgoing-args%s "
3205                  "for correctness", prefix, suffix);
3206       target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3207     }
3208
3209   /* For sane SSE instruction set generation we need fcomi instruction.
3210      It is safe to enable all CMOVE instructions.  */
3211   if (TARGET_SSE)
3212     TARGET_CMOVE = 1;
3213
3214   /* Figure out what ASM_GENERATE_INTERNAL_LABEL builds as a prefix.  */
3215   {
3216     char *p;
3217     ASM_GENERATE_INTERNAL_LABEL (internal_label_prefix, "LX", 0);
3218     p = strchr (internal_label_prefix, 'X');
3219     internal_label_prefix_len = p - internal_label_prefix;
3220     *p = '\0';
3221   }
3222
3223   /* When scheduling description is not available, disable scheduler pass
3224      so it won't slow down the compilation and make x87 code slower.  */
3225   if (!TARGET_SCHEDULE)
3226     flag_schedule_insns_after_reload = flag_schedule_insns = 0;
3227
3228   if (!PARAM_SET_P (PARAM_SIMULTANEOUS_PREFETCHES))
3229     set_param_value ("simultaneous-prefetches",
3230                      ix86_cost->simultaneous_prefetches);
3231   if (!PARAM_SET_P (PARAM_L1_CACHE_LINE_SIZE))
3232     set_param_value ("l1-cache-line-size", ix86_cost->prefetch_block);
3233   if (!PARAM_SET_P (PARAM_L1_CACHE_SIZE))
3234     set_param_value ("l1-cache-size", ix86_cost->l1_cache_size);
3235   if (!PARAM_SET_P (PARAM_L2_CACHE_SIZE))
3236     set_param_value ("l2-cache-size", ix86_cost->l2_cache_size);
3237
3238   /* If using typedef char *va_list, signal that __builtin_va_start (&ap, 0)
3239      can be optimized to ap = __builtin_next_arg (0).  */
3240   if (!TARGET_64BIT)
3241     targetm.expand_builtin_va_start = NULL;
3242
3243   if (TARGET_64BIT)
3244     {
3245       ix86_gen_leave = gen_leave_rex64;
3246       ix86_gen_pop1 = gen_popdi1;
3247       ix86_gen_add3 = gen_adddi3;
3248       ix86_gen_sub3 = gen_subdi3;
3249       ix86_gen_sub3_carry = gen_subdi3_carry_rex64;
3250       ix86_gen_one_cmpl2 = gen_one_cmpldi2;
3251       ix86_gen_monitor = gen_sse3_monitor64;
3252       ix86_gen_andsp = gen_anddi3;
3253     }
3254   else
3255     {
3256       ix86_gen_leave = gen_leave;
3257       ix86_gen_pop1 = gen_popsi1;
3258       ix86_gen_add3 = gen_addsi3;
3259       ix86_gen_sub3 = gen_subsi3;
3260       ix86_gen_sub3_carry = gen_subsi3_carry;
3261       ix86_gen_one_cmpl2 = gen_one_cmplsi2;
3262       ix86_gen_monitor = gen_sse3_monitor;
3263       ix86_gen_andsp = gen_andsi3;
3264     }
3265
3266 #ifdef USE_IX86_CLD
3267   /* Use -mcld by default for 32-bit code if configured with --enable-cld.  */
3268   if (!TARGET_64BIT)
3269     target_flags |= MASK_CLD & ~target_flags_explicit;
3270 #endif
3271
3272   /* Save the initial options in case the user does function specific options */
3273   if (main_args_p)
3274     target_option_default_node = target_option_current_node
3275       = build_target_option_node ();
3276 }
3277
3278 /* Update register usage after having seen the compiler flags.  */
3279
3280 void
3281 ix86_conditional_register_usage (void)
3282 {
3283   int i;
3284   unsigned int j;
3285
3286   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3287     {
3288       if (fixed_regs[i] > 1)
3289         fixed_regs[i] = (fixed_regs[i] == (TARGET_64BIT ? 3 : 2));
3290       if (call_used_regs[i] > 1)
3291         call_used_regs[i] = (call_used_regs[i] == (TARGET_64BIT ? 3 : 2));
3292     }
3293
3294   /* The PIC register, if it exists, is fixed.  */
3295   j = PIC_OFFSET_TABLE_REGNUM;
3296   if (j != INVALID_REGNUM)
3297     fixed_regs[j] = call_used_regs[j] = 1;
3298
3299   /* The MS_ABI changes the set of call-used registers.  */
3300   if (TARGET_64BIT && ix86_cfun_abi () == MS_ABI)
3301     {
3302       call_used_regs[SI_REG] = 0;
3303       call_used_regs[DI_REG] = 0;
3304       call_used_regs[XMM6_REG] = 0;
3305       call_used_regs[XMM7_REG] = 0;
3306       for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
3307         call_used_regs[i] = 0;
3308     }
3309
3310   /* The default setting of CLOBBERED_REGS is for 32-bit; add in the
3311      other call-clobbered regs for 64-bit.  */
3312   if (TARGET_64BIT)
3313     {
3314       CLEAR_HARD_REG_SET (reg_class_contents[(int)CLOBBERED_REGS]);
3315
3316       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3317         if (TEST_HARD_REG_BIT (reg_class_contents[(int)GENERAL_REGS], i)
3318             && call_used_regs[i])
3319           SET_HARD_REG_BIT (reg_class_contents[(int)CLOBBERED_REGS], i);
3320     }
3321
3322   /* If MMX is disabled, squash the registers.  */
3323   if (! TARGET_MMX)
3324     for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3325       if (TEST_HARD_REG_BIT (reg_class_contents[(int)MMX_REGS], i))
3326         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
3327
3328   /* If SSE is disabled, squash the registers.  */
3329   if (! TARGET_SSE)
3330     for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3331       if (TEST_HARD_REG_BIT (reg_class_contents[(int)SSE_REGS], i))
3332         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
3333
3334   /* If the FPU is disabled, squash the registers.  */
3335   if (! (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387))
3336     for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3337       if (TEST_HARD_REG_BIT (reg_class_contents[(int)FLOAT_REGS], i))
3338         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
3339
3340   /* If 32-bit, squash the 64-bit registers.  */
3341   if (! TARGET_64BIT)
3342     {
3343       for (i = FIRST_REX_INT_REG; i <= LAST_REX_INT_REG; i++)
3344         reg_names[i] = "";
3345       for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
3346         reg_names[i] = "";
3347     }
3348 }
3349
3350 \f
3351 /* Save the current options */
3352
3353 static void
3354 ix86_function_specific_save (struct cl_target_option *ptr)
3355 {
3356   gcc_assert (IN_RANGE (ix86_arch, 0, 255));
3357   gcc_assert (IN_RANGE (ix86_schedule, 0, 255));
3358   gcc_assert (IN_RANGE (ix86_tune, 0, 255));
3359   gcc_assert (IN_RANGE (ix86_fpmath, 0, 255));
3360   gcc_assert (IN_RANGE (ix86_branch_cost, 0, 255));
3361
3362   ptr->arch = ix86_arch;
3363   ptr->schedule = ix86_schedule;
3364   ptr->tune = ix86_tune;
3365   ptr->fpmath = ix86_fpmath;
3366   ptr->branch_cost = ix86_branch_cost;
3367   ptr->tune_defaulted = ix86_tune_defaulted;
3368   ptr->arch_specified = ix86_arch_specified;
3369   ptr->ix86_isa_flags_explicit = ix86_isa_flags_explicit;
3370   ptr->target_flags_explicit = target_flags_explicit;
3371 }
3372
3373 /* Restore the current options */
3374
3375 static void
3376 ix86_function_specific_restore (struct cl_target_option *ptr)
3377 {
3378   enum processor_type old_tune = ix86_tune;
3379   enum processor_type old_arch = ix86_arch;
3380   unsigned int ix86_arch_mask, ix86_tune_mask;
3381   int i;
3382
3383   ix86_arch = ptr->arch;
3384   ix86_schedule = ptr->schedule;
3385   ix86_tune = ptr->tune;
3386   ix86_fpmath = ptr->fpmath;
3387   ix86_branch_cost = ptr->branch_cost;
3388   ix86_tune_defaulted = ptr->tune_defaulted;
3389   ix86_arch_specified = ptr->arch_specified;
3390   ix86_isa_flags_explicit = ptr->ix86_isa_flags_explicit;
3391   target_flags_explicit = ptr->target_flags_explicit;
3392
3393   /* Recreate the arch feature tests if the arch changed */
3394   if (old_arch != ix86_arch)
3395     {
3396       ix86_arch_mask = 1u << ix86_arch;
3397       for (i = 0; i < X86_ARCH_LAST; ++i)
3398         ix86_arch_features[i]
3399           = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
3400     }
3401
3402   /* Recreate the tune optimization tests */
3403   if (old_tune != ix86_tune)
3404     {
3405       ix86_tune_mask = 1u << ix86_tune;
3406       for (i = 0; i < X86_TUNE_LAST; ++i)
3407         ix86_tune_features[i]
3408           = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
3409     }
3410 }
3411
3412 /* Print the current options */
3413
3414 static void
3415 ix86_function_specific_print (FILE *file, int indent,
3416                               struct cl_target_option *ptr)
3417 {
3418   char *target_string
3419     = ix86_target_string (ptr->ix86_isa_flags, ptr->target_flags,
3420                           NULL, NULL, NULL, false);
3421
3422   fprintf (file, "%*sarch = %d (%s)\n",
3423            indent, "",
3424            ptr->arch,
3425            ((ptr->arch < TARGET_CPU_DEFAULT_max)
3426             ? cpu_names[ptr->arch]
3427             : "<unknown>"));
3428
3429   fprintf (file, "%*stune = %d (%s)\n",
3430            indent, "",
3431            ptr->tune,
3432            ((ptr->tune < TARGET_CPU_DEFAULT_max)
3433             ? cpu_names[ptr->tune]
3434             : "<unknown>"));
3435
3436   fprintf (file, "%*sfpmath = %d%s%s\n", indent, "", ptr->fpmath,
3437            (ptr->fpmath & FPMATH_387) ? ", 387" : "",
3438            (ptr->fpmath & FPMATH_SSE) ? ", sse" : "");
3439   fprintf (file, "%*sbranch_cost = %d\n", indent, "", ptr->branch_cost);
3440
3441   if (target_string)
3442     {
3443       fprintf (file, "%*s%s\n", indent, "", target_string);
3444       free (target_string);
3445     }
3446 }
3447
3448 \f
3449 /* Inner function to process the attribute((target(...))), take an argument and
3450    set the current options from the argument. If we have a list, recursively go
3451    over the list.  */
3452
3453 static bool
3454 ix86_valid_target_attribute_inner_p (tree args, char *p_strings[])
3455 {
3456   char *next_optstr;
3457   bool ret = true;
3458
3459 #define IX86_ATTR_ISA(S,O)   { S, sizeof (S)-1, ix86_opt_isa, O, 0 }
3460 #define IX86_ATTR_STR(S,O)   { S, sizeof (S)-1, ix86_opt_str, O, 0 }
3461 #define IX86_ATTR_YES(S,O,M) { S, sizeof (S)-1, ix86_opt_yes, O, M }
3462 #define IX86_ATTR_NO(S,O,M)  { S, sizeof (S)-1, ix86_opt_no,  O, M }
3463
3464   enum ix86_opt_type
3465   {
3466     ix86_opt_unknown,
3467     ix86_opt_yes,
3468     ix86_opt_no,
3469     ix86_opt_str,
3470     ix86_opt_isa
3471   };
3472
3473   static const struct
3474   {
3475     const char *string;
3476     size_t len;
3477     enum ix86_opt_type type;
3478     int opt;
3479     int mask;
3480   } attrs[] = {
3481     /* isa options */
3482     IX86_ATTR_ISA ("3dnow",     OPT_m3dnow),
3483     IX86_ATTR_ISA ("abm",       OPT_mabm),
3484     IX86_ATTR_ISA ("aes",       OPT_maes),
3485     IX86_ATTR_ISA ("avx",       OPT_mavx),
3486     IX86_ATTR_ISA ("mmx",       OPT_mmmx),
3487     IX86_ATTR_ISA ("pclmul",    OPT_mpclmul),
3488     IX86_ATTR_ISA ("popcnt",    OPT_mpopcnt),
3489     IX86_ATTR_ISA ("sse",       OPT_msse),
3490     IX86_ATTR_ISA ("sse2",      OPT_msse2),
3491     IX86_ATTR_ISA ("sse3",      OPT_msse3),
3492     IX86_ATTR_ISA ("sse4",      OPT_msse4),
3493     IX86_ATTR_ISA ("sse4.1",    OPT_msse4_1),
3494     IX86_ATTR_ISA ("sse4.2",    OPT_msse4_2),
3495     IX86_ATTR_ISA ("sse4a",     OPT_msse4a),
3496     IX86_ATTR_ISA ("sse5",      OPT_msse5),
3497     IX86_ATTR_ISA ("ssse3",     OPT_mssse3),
3498
3499     /* string options */
3500     IX86_ATTR_STR ("arch=",     IX86_FUNCTION_SPECIFIC_ARCH),
3501     IX86_ATTR_STR ("fpmath=",   IX86_FUNCTION_SPECIFIC_FPMATH),
3502     IX86_ATTR_STR ("tune=",     IX86_FUNCTION_SPECIFIC_TUNE),
3503
3504     /* flag options */
3505     IX86_ATTR_YES ("cld",
3506                    OPT_mcld,
3507                    MASK_CLD),
3508
3509     IX86_ATTR_NO ("fancy-math-387",
3510                   OPT_mfancy_math_387,
3511                   MASK_NO_FANCY_MATH_387),
3512
3513     IX86_ATTR_NO ("fused-madd",
3514                   OPT_mfused_madd,
3515                   MASK_NO_FUSED_MADD),
3516
3517     IX86_ATTR_YES ("ieee-fp",
3518                    OPT_mieee_fp,
3519                    MASK_IEEE_FP),
3520
3521     IX86_ATTR_YES ("inline-all-stringops",
3522                    OPT_minline_all_stringops,
3523                    MASK_INLINE_ALL_STRINGOPS),
3524
3525     IX86_ATTR_YES ("inline-stringops-dynamically",
3526                    OPT_minline_stringops_dynamically,
3527                    MASK_INLINE_STRINGOPS_DYNAMICALLY),
3528
3529     IX86_ATTR_NO ("align-stringops",
3530                   OPT_mno_align_stringops,
3531                   MASK_NO_ALIGN_STRINGOPS),
3532
3533     IX86_ATTR_YES ("recip",
3534                    OPT_mrecip,
3535                    MASK_RECIP),
3536
3537   };
3538
3539   /* If this is a list, recurse to get the options.  */
3540   if (TREE_CODE (args) == TREE_LIST)
3541     {
3542       bool ret = true;
3543
3544       for (; args; args = TREE_CHAIN (args))
3545         if (TREE_VALUE (args)
3546             && !ix86_valid_target_attribute_inner_p (TREE_VALUE (args), p_strings))
3547           ret = false;
3548
3549       return ret;
3550     }
3551
3552   else if (TREE_CODE (args) != STRING_CST)
3553     gcc_unreachable ();
3554
3555   /* Handle multiple arguments separated by commas.  */
3556   next_optstr = ASTRDUP (TREE_STRING_POINTER (args));
3557
3558   while (next_optstr && *next_optstr != '\0')
3559     {
3560       char *p = next_optstr;
3561       char *orig_p = p;
3562       char *comma = strchr (next_optstr, ',');
3563       const char *opt_string;
3564       size_t len, opt_len;
3565       int opt;
3566       bool opt_set_p;
3567       char ch;
3568       unsigned i;
3569       enum ix86_opt_type type = ix86_opt_unknown;
3570       int mask = 0;
3571
3572       if (comma)
3573         {
3574           *comma = '\0';
3575           len = comma - next_optstr;
3576           next_optstr = comma + 1;
3577         }
3578       else
3579         {
3580           len = strlen (p);
3581           next_optstr = NULL;
3582         }
3583
3584       /* Recognize no-xxx.  */
3585       if (len > 3 && p[0] == 'n' && p[1] == 'o' && p[2] == '-')
3586         {
3587           opt_set_p = false;
3588           p += 3;
3589           len -= 3;
3590         }
3591       else
3592         opt_set_p = true;
3593
3594       /* Find the option.  */
3595       ch = *p;
3596       opt = N_OPTS;
3597       for (i = 0; i < ARRAY_SIZE (attrs); i++)
3598         {
3599           type = attrs[i].type;
3600           opt_len = attrs[i].len;
3601           if (ch == attrs[i].string[0]
3602               && ((type != ix86_opt_str) ? len == opt_len : len > opt_len)
3603               && memcmp (p, attrs[i].string, opt_len) == 0)
3604             {
3605               opt = attrs[i].opt;
3606               mask = attrs[i].mask;
3607               opt_string = attrs[i].string;
3608               break;
3609             }
3610         }
3611
3612       /* Process the option.  */
3613       if (opt == N_OPTS)
3614         {
3615           error ("attribute(target(\"%s\")) is unknown", orig_p);
3616           ret = false;
3617         }
3618
3619       else if (type == ix86_opt_isa)
3620         ix86_handle_option (opt, p, opt_set_p);
3621
3622       else if (type == ix86_opt_yes || type == ix86_opt_no)
3623         {
3624           if (type == ix86_opt_no)
3625             opt_set_p = !opt_set_p;
3626
3627           if (opt_set_p)
3628             target_flags |= mask;
3629           else
3630             target_flags &= ~mask;
3631         }
3632
3633       else if (type == ix86_opt_str)
3634         {
3635           if (p_strings[opt])
3636             {
3637               error ("option(\"%s\") was already specified", opt_string);
3638               ret = false;
3639             }
3640           else
3641             p_strings[opt] = xstrdup (p + opt_len);
3642         }
3643
3644       else
3645         gcc_unreachable ();
3646     }
3647
3648   return ret;
3649 }
3650
3651 /* Return a TARGET_OPTION_NODE tree of the target options listed or NULL.  */
3652
3653 tree
3654 ix86_valid_target_attribute_tree (tree args)
3655 {
3656   const char *orig_arch_string = ix86_arch_string;
3657   const char *orig_tune_string = ix86_tune_string;
3658   const char *orig_fpmath_string = ix86_fpmath_string;
3659   int orig_tune_defaulted = ix86_tune_defaulted;
3660   int orig_arch_specified = ix86_arch_specified;
3661   char *option_strings[IX86_FUNCTION_SPECIFIC_MAX] = { NULL, NULL, NULL };
3662   tree t = NULL_TREE;
3663   int i;
3664   struct cl_target_option *def
3665     = TREE_TARGET_OPTION (target_option_default_node);
3666
3667   /* Process each of the options on the chain.  */
3668   if (! ix86_valid_target_attribute_inner_p (args, option_strings))
3669     return NULL_TREE;
3670
3671   /* If the changed options are different from the default, rerun override_options,
3672      and then save the options away.  The string options are are attribute options,
3673      and will be undone when we copy the save structure.  */
3674   if (ix86_isa_flags != def->ix86_isa_flags
3675       || target_flags != def->target_flags
3676       || option_strings[IX86_FUNCTION_SPECIFIC_ARCH]
3677       || option_strings[IX86_FUNCTION_SPECIFIC_TUNE]
3678       || option_strings[IX86_FUNCTION_SPECIFIC_FPMATH])
3679     {
3680       /* If we are using the default tune= or arch=, undo the string assigned,
3681          and use the default.  */
3682       if (option_strings[IX86_FUNCTION_SPECIFIC_ARCH])
3683         ix86_arch_string = option_strings[IX86_FUNCTION_SPECIFIC_ARCH];
3684       else if (!orig_arch_specified)
3685         ix86_arch_string = NULL;
3686
3687       if (option_strings[IX86_FUNCTION_SPECIFIC_TUNE])
3688         ix86_tune_string = option_strings[IX86_FUNCTION_SPECIFIC_TUNE];
3689       else if (orig_tune_defaulted)
3690         ix86_tune_string = NULL;
3691
3692       /* If fpmath= is not set, and we now have sse2 on 32-bit, use it.  */
3693       if (option_strings[IX86_FUNCTION_SPECIFIC_FPMATH])
3694         ix86_fpmath_string = option_strings[IX86_FUNCTION_SPECIFIC_FPMATH];
3695       else if (!TARGET_64BIT && TARGET_SSE)
3696         ix86_fpmath_string = "sse,387";
3697
3698       /* Do any overrides, such as arch=xxx, or tune=xxx support.  */
3699       override_options (false);
3700
3701       /* Add any builtin functions with the new isa if any.  */
3702       ix86_add_new_builtins (ix86_isa_flags);
3703
3704       /* Save the current options unless we are validating options for
3705          #pragma.  */
3706       t = build_target_option_node ();
3707
3708       ix86_arch_string = orig_arch_string;
3709       ix86_tune_string = orig_tune_string;
3710       ix86_fpmath_string = orig_fpmath_string;
3711
3712       /* Free up memory allocated to hold the strings */
3713       for (i = 0; i < IX86_FUNCTION_SPECIFIC_MAX; i++)
3714         if (option_strings[i])
3715           free (option_strings[i]);
3716     }
3717
3718   return t;
3719 }
3720
3721 /* Hook to validate attribute((target("string"))).  */
3722
3723 static bool
3724 ix86_valid_target_attribute_p (tree fndecl,
3725                                tree ARG_UNUSED (name),
3726                                tree args,
3727                                int ARG_UNUSED (flags))
3728 {
3729   struct cl_target_option cur_target;
3730   bool ret = true;
3731   tree old_optimize = build_optimization_node ();
3732   tree new_target, new_optimize;
3733   tree func_optimize = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl);
3734
3735   /* If the function changed the optimization levels as well as setting target
3736      options, start with the optimizations specified.  */
3737   if (func_optimize && func_optimize != old_optimize)
3738     cl_optimization_restore (TREE_OPTIMIZATION (func_optimize));
3739
3740   /* The target attributes may also change some optimization flags, so update
3741      the optimization options if necessary.  */
3742   cl_target_option_save (&cur_target);
3743   new_target = ix86_valid_target_attribute_tree (args);
3744   new_optimize = build_optimization_node ();
3745
3746   if (!new_target)
3747     ret = false;
3748
3749   else if (fndecl)
3750     {
3751       DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_target;
3752
3753       if (old_optimize != new_optimize)
3754         DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize;
3755     }
3756
3757   cl_target_option_restore (&cur_target);
3758
3759   if (old_optimize != new_optimize)
3760     cl_optimization_restore (TREE_OPTIMIZATION (old_optimize));
3761
3762   return ret;
3763 }
3764
3765 \f
3766 /* Hook to determine if one function can safely inline another.  */
3767
3768 static bool
3769 ix86_can_inline_p (tree caller, tree callee)
3770 {
3771   bool ret = false;
3772   tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller);
3773   tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee);
3774
3775   /* If callee has no option attributes, then it is ok to inline.  */
3776   if (!callee_tree)
3777     ret = true;
3778
3779   /* If caller has no option attributes, but callee does then it is not ok to
3780      inline.  */
3781   else if (!caller_tree)
3782     ret = false;
3783
3784   else
3785     {
3786       struct cl_target_option *caller_opts = TREE_TARGET_OPTION (caller_tree);
3787       struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree);
3788
3789       /* Callee's isa options should a subset of the caller's, i.e. a SSE5 function
3790          can inline a SSE2 function but a SSE2 function can't inline a SSE5
3791          function.  */
3792       if ((caller_opts->ix86_isa_flags & callee_opts->ix86_isa_flags)
3793           != callee_opts->ix86_isa_flags)
3794         ret = false;
3795
3796       /* See if we have the same non-isa options.  */
3797       else if (caller_opts->target_flags != callee_opts->target_flags)
3798         ret = false;
3799
3800       /* See if arch, tune, etc. are the same.  */
3801       else if (caller_opts->arch != callee_opts->arch)
3802         ret = false;
3803
3804       else if (caller_opts->tune != callee_opts->tune)
3805         ret = false;
3806
3807       else if (caller_opts->fpmath != callee_opts->fpmath)
3808         ret = false;
3809
3810       else if (caller_opts->branch_cost != callee_opts->branch_cost)
3811         ret = false;
3812
3813       else
3814         ret = true;
3815     }
3816
3817   return ret;
3818 }
3819
3820 \f
3821 /* Remember the last target of ix86_set_current_function.  */
3822 static GTY(()) tree ix86_previous_fndecl;
3823
3824 /* Establish appropriate back-end context for processing the function
3825    FNDECL.  The argument might be NULL to indicate processing at top
3826    level, outside of any function scope.  */
3827 static void
3828 ix86_set_current_function (tree fndecl)
3829 {
3830   /* Only change the context if the function changes.  This hook is called
3831      several times in the course of compiling a function, and we don't want to
3832      slow things down too much or call target_reinit when it isn't safe.  */
3833   if (fndecl && fndecl != ix86_previous_fndecl)
3834     {
3835       tree old_tree = (ix86_previous_fndecl
3836                        ? DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl)
3837                        : NULL_TREE);
3838
3839       tree new_tree = (fndecl
3840                        ? DECL_FUNCTION_SPECIFIC_TARGET (fndecl)
3841                        : NULL_TREE);
3842
3843       ix86_previous_fndecl = fndecl;
3844       if (old_tree == new_tree)
3845         ;
3846
3847       else if (new_tree)
3848         {
3849           cl_target_option_restore (TREE_TARGET_OPTION (new_tree));
3850           target_reinit ();
3851         }
3852
3853       else if (old_tree)
3854         {
3855           struct cl_target_option *def
3856             = TREE_TARGET_OPTION (target_option_current_node);
3857
3858           cl_target_option_restore (def);
3859           target_reinit ();
3860         }
3861     }
3862 }
3863
3864 \f
3865 /* Return true if this goes in large data/bss.  */
3866
3867 static bool
3868 ix86_in_large_data_p (tree exp)
3869 {
3870   if (ix86_cmodel != CM_MEDIUM && ix86_cmodel != CM_MEDIUM_PIC)
3871     return false;
3872
3873   /* Functions are never large data.  */
3874   if (TREE_CODE (exp) == FUNCTION_DECL)
3875     return false;
3876
3877   if (TREE_CODE (exp) == VAR_DECL && DECL_SECTION_NAME (exp))
3878     {
3879       const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (exp));
3880       if (strcmp (section, ".ldata") == 0
3881           || strcmp (section, ".lbss") == 0)
3882         return true;
3883       return false;
3884     }
3885   else
3886     {
3887       HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
3888
3889       /* If this is an incomplete type with size 0, then we can't put it
3890          in data because it might be too big when completed.  */
3891       if (!size || size > ix86_section_threshold)
3892         return true;
3893     }
3894
3895   return false;
3896 }
3897
3898 /* Switch to the appropriate section for output of DECL.
3899    DECL is either a `VAR_DECL' node or a constant of some sort.
3900    RELOC indicates whether forming the initial value of DECL requires
3901    link-time relocations.  */
3902
3903 static section * x86_64_elf_select_section (tree, int, unsigned HOST_WIDE_INT)
3904         ATTRIBUTE_UNUSED;
3905
3906 static section *
3907 x86_64_elf_select_section (tree decl, int reloc,
3908                            unsigned HOST_WIDE_INT align)
3909 {
3910   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3911       && ix86_in_large_data_p (decl))
3912     {
3913       const char *sname = NULL;
3914       unsigned int flags = SECTION_WRITE;
3915       switch (categorize_decl_for_section (decl, reloc))
3916         {
3917         case SECCAT_DATA:
3918           sname = ".ldata";
3919           break;
3920         case SECCAT_DATA_REL:
3921           sname = ".ldata.rel";
3922           break;
3923         case SECCAT_DATA_REL_LOCAL:
3924           sname = ".ldata.rel.local";
3925           break;
3926         case SECCAT_DATA_REL_RO:
3927           sname = ".ldata.rel.ro";
3928           break;
3929         case SECCAT_DATA_REL_RO_LOCAL:
3930           sname = ".ldata.rel.ro.local";
3931           break;
3932         case SECCAT_BSS:
3933           sname = ".lbss";
3934           flags |= SECTION_BSS;
3935           break;
3936         case SECCAT_RODATA:
3937         case SECCAT_RODATA_MERGE_STR:
3938         case SECCAT_RODATA_MERGE_STR_INIT:
3939         case SECCAT_RODATA_MERGE_CONST:
3940           sname = ".lrodata";
3941           flags = 0;
3942           break;
3943         case SECCAT_SRODATA:
3944         case SECCAT_SDATA:
3945         case SECCAT_SBSS:
3946           gcc_unreachable ();
3947         case SECCAT_TEXT:
3948         case SECCAT_TDATA:
3949         case SECCAT_TBSS:
3950           /* We don't split these for medium model.  Place them into
3951              default sections and hope for best.  */
3952           break;
3953         case SECCAT_EMUTLS_VAR:
3954         case SECCAT_EMUTLS_TMPL:
3955           gcc_unreachable ();
3956         }
3957       if (sname)
3958         {
3959           /* We might get called with string constants, but get_named_section
3960              doesn't like them as they are not DECLs.  Also, we need to set
3961              flags in that case.  */
3962           if (!DECL_P (decl))
3963             return get_section (sname, flags, NULL);
3964           return get_named_section (decl, sname, reloc);
3965         }
3966     }
3967   return default_elf_select_section (decl, reloc, align);
3968 }
3969
3970 /* Build up a unique section name, expressed as a
3971    STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
3972    RELOC indicates whether the initial value of EXP requires
3973    link-time relocations.  */
3974
3975 static void ATTRIBUTE_UNUSED
3976 x86_64_elf_unique_section (tree decl, int reloc)
3977 {
3978   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3979       && ix86_in_large_data_p (decl))
3980     {
3981       const char *prefix = NULL;
3982       /* We only need to use .gnu.linkonce if we don't have COMDAT groups.  */
3983       bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
3984
3985       switch (categorize_decl_for_section (decl, reloc))
3986         {
3987         case SECCAT_DATA:
3988         case SECCAT_DATA_REL:
3989         case SECCAT_DATA_REL_LOCAL:
3990         case SECCAT_DATA_REL_RO:
3991         case SECCAT_DATA_REL_RO_LOCAL:
3992           prefix = one_only ? ".ld" : ".ldata";
3993           break;
3994         case SECCAT_BSS:
3995           prefix = one_only ? ".lb" : ".lbss";
3996           break;
3997         case SECCAT_RODATA:
3998         case SECCAT_RODATA_MERGE_STR:
3999         case SECCAT_RODATA_MERGE_STR_INIT:
4000         case SECCAT_RODATA_MERGE_CONST:
4001           prefix = one_only ? ".lr" : ".lrodata";
4002           break;
4003         case SECCAT_SRODATA:
4004         case SECCAT_SDATA:
4005         case SECCAT_SBSS:
4006           gcc_unreachable ();
4007         case SECCAT_TEXT:
4008         case SECCAT_TDATA:
4009         case SECCAT_TBSS:
4010           /* We don't split these for medium model.  Place them into
4011              default sections and hope for best.  */
4012           break;
4013         case SECCAT_EMUTLS_VAR:
4014           prefix = targetm.emutls.var_section;
4015           break;
4016         case SECCAT_EMUTLS_TMPL:
4017           prefix = targetm.emutls.tmpl_section;
4018           break;
4019         }
4020       if (prefix)
4021         {
4022           const char *name, *linkonce;
4023           char *string;
4024
4025           name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4026           name = targetm.strip_name_encoding (name);
4027           
4028           /* If we're using one_only, then there needs to be a .gnu.linkonce
4029              prefix to the section name.  */
4030           linkonce = one_only ? ".gnu.linkonce" : "";
4031   
4032           string = ACONCAT ((linkonce, prefix, ".", name, NULL));
4033           
4034           DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
4035           return;
4036         }
4037     }
4038   default_unique_section (decl, reloc);
4039 }
4040
4041 #ifdef COMMON_ASM_OP
4042 /* This says how to output assembler code to declare an
4043    uninitialized external linkage data object.
4044
4045    For medium model x86-64 we need to use .largecomm opcode for
4046    large objects.  */
4047 void
4048 x86_elf_aligned_common (FILE *file,
4049                         const char *name, unsigned HOST_WIDE_INT size,
4050                         int align)
4051 {
4052   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
4053       && size > (unsigned int)ix86_section_threshold)
4054     fprintf (file, ".largecomm\t");
4055   else
4056     fprintf (file, "%s", COMMON_ASM_OP);
4057   assemble_name (file, name);
4058   fprintf (file, ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n",
4059            size, align / BITS_PER_UNIT);
4060 }
4061 #endif
4062
4063 /* Utility function for targets to use in implementing
4064    ASM_OUTPUT_ALIGNED_BSS.  */
4065
4066 void
4067 x86_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
4068                         const char *name, unsigned HOST_WIDE_INT size,
4069                         int align)
4070 {
4071   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
4072       && size > (unsigned int)ix86_section_threshold)
4073     switch_to_section (get_named_section (decl, ".lbss", 0));
4074   else
4075     switch_to_section (bss_section);
4076   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
4077 #ifdef ASM_DECLARE_OBJECT_NAME
4078   last_assemble_variable_decl = decl;
4079   ASM_DECLARE_OBJECT_NAME (file, name, decl);
4080 #else
4081   /* Standard thing is just output label for the object.  */
4082   ASM_OUTPUT_LABEL (file, name);
4083 #endif /* ASM_DECLARE_OBJECT_NAME */
4084   ASM_OUTPUT_SKIP (file, size ? size : 1);
4085 }
4086 \f
4087 void
4088 optimization_options (int level, int size ATTRIBUTE_UNUSED)
4089 {
4090   /* For -O2 and beyond, turn off -fschedule-insns by default.  It tends to
4091      make the problem with not enough registers even worse.  */
4092 #ifdef INSN_SCHEDULING
4093   if (level > 1)
4094     flag_schedule_insns = 0;
4095 #endif
4096
4097   if (TARGET_MACHO)
4098     /* The Darwin libraries never set errno, so we might as well
4099        avoid calling them when that's the only reason we would.  */
4100     flag_errno_math = 0;
4101
4102   /* The default values of these switches depend on the TARGET_64BIT
4103      that is not known at this moment.  Mark these values with 2 and
4104      let user the to override these.  In case there is no command line option
4105      specifying them, we will set the defaults in override_options.  */
4106   if (optimize >= 1)
4107     flag_omit_frame_pointer = 2;
4108   flag_pcc_struct_return = 2;
4109   flag_asynchronous_unwind_tables = 2;
4110   flag_vect_cost_model = 1;
4111 #ifdef SUBTARGET_OPTIMIZATION_OPTIONS
4112   SUBTARGET_OPTIMIZATION_OPTIONS;
4113 #endif
4114 }
4115 \f
4116 /* Decide whether we can make a sibling call to a function.  DECL is the
4117    declaration of the function being targeted by the call and EXP is the
4118    CALL_EXPR representing the call.  */
4119
4120 static bool
4121 ix86_function_ok_for_sibcall (tree decl, tree exp)
4122 {
4123   tree type, decl_or_type;
4124   rtx a, b;
4125
4126   /* If we are generating position-independent code, we cannot sibcall
4127      optimize any indirect call, or a direct call to a global function,
4128      as the PLT requires %ebx be live.  */
4129   if (!TARGET_64BIT && flag_pic && (!decl || !targetm.binds_local_p (decl)))
4130     return false;
4131
4132   /* If we need to align the outgoing stack, then sibcalling would
4133      unalign the stack, which may break the called function.  */
4134   if (ix86_incoming_stack_boundary < PREFERRED_STACK_BOUNDARY)
4135     return false;
4136
4137   if (decl)
4138     {
4139       decl_or_type = decl;
4140       type = TREE_TYPE (decl);
4141     }
4142   else
4143     {
4144       /* We're looking at the CALL_EXPR, we need the type of the function.  */
4145       type = CALL_EXPR_FN (exp);                /* pointer expression */
4146       type = TREE_TYPE (type);                  /* pointer type */
4147       type = TREE_TYPE (type);                  /* function type */
4148       decl_or_type = type;
4149     }
4150
4151   /* Check that the return value locations are the same.  Like
4152      if we are returning floats on the 80387 register stack, we cannot
4153      make a sibcall from a function that doesn't return a float to a
4154      function that does or, conversely, from a function that does return
4155      a float to a function that doesn't; the necessary stack adjustment
4156      would not be executed.  This is also the place we notice
4157      differences in the return value ABI.  Note that it is ok for one
4158      of the functions to have void return type as long as the return
4159      value of the other is passed in a register.  */
4160   a = ix86_function_value (TREE_TYPE (exp), decl_or_type, false);
4161   b = ix86_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)),
4162                            cfun->decl, false);
4163   if (STACK_REG_P (a) || STACK_REG_P (b))
4164     {
4165       if (!rtx_equal_p (a, b))
4166         return false;
4167     }
4168   else if (VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl))))
4169     ;
4170   else if (!rtx_equal_p (a, b))
4171     return false;
4172
4173   if (TARGET_64BIT)
4174     {
4175       /* The SYSV ABI has more call-clobbered registers;
4176          disallow sibcalls from MS to SYSV.  */
4177       if (cfun->machine->call_abi == MS_ABI
4178           && ix86_function_type_abi (type) == SYSV_ABI)
4179         return false;
4180     }
4181   else
4182     {
4183       /* If this call is indirect, we'll need to be able to use a
4184          call-clobbered register for the address of the target function.
4185          Make sure that all such registers are not used for passing
4186          parameters.  Note that DLLIMPORT functions are indirect.  */
4187       if (!decl
4188           || (TARGET_DLLIMPORT_DECL_ATTRIBUTES && DECL_DLLIMPORT_P (decl)))
4189         {
4190           if (ix86_function_regparm (type, NULL) >= 3)
4191             {
4192               /* ??? Need to count the actual number of registers to be used,
4193                  not the possible number of registers.  Fix later.  */
4194               return false;
4195             }
4196         }
4197     }
4198
4199   /* Otherwise okay.  That also includes certain types of indirect calls.  */
4200   return true;
4201 }
4202
4203 /* Handle "cdecl", "stdcall", "fastcall", "regparm" and "sseregparm"
4204    calling convention attributes;
4205    arguments as in struct attribute_spec.handler.  */
4206
4207 static tree
4208 ix86_handle_cconv_attribute (tree *node, tree name,
4209                                    tree args,
4210                                    int flags ATTRIBUTE_UNUSED,
4211                                    bool *no_add_attrs)
4212 {
4213   if (TREE_CODE (*node) != FUNCTION_TYPE
4214       && TREE_CODE (*node) != METHOD_TYPE
4215       && TREE_CODE (*node) != FIELD_DECL
4216       && TREE_CODE (*node) != TYPE_DECL)
4217     {
4218       warning (OPT_Wattributes, "%qs attribute only applies to functions",
4219                IDENTIFIER_POINTER (name));
4220       *no_add_attrs = true;
4221       return NULL_TREE;
4222     }
4223
4224   /* Can combine regparm with all attributes but fastcall.  */
4225   if (is_attribute_p ("regparm", name))
4226     {
4227       tree cst;
4228
4229       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4230         {
4231           error ("fastcall and regparm attributes are not compatible");
4232         }
4233
4234       cst = TREE_VALUE (args);
4235       if (TREE_CODE (cst) != INTEGER_CST)
4236         {
4237           warning (OPT_Wattributes,
4238                    "%qs attribute requires an integer constant argument",
4239                    IDENTIFIER_POINTER (name));
4240           *no_add_attrs = true;
4241         }
4242       else if (compare_tree_int (cst, REGPARM_MAX) > 0)
4243         {
4244           warning (OPT_Wattributes, "argument to %qs attribute larger than %d",
4245                    IDENTIFIER_POINTER (name), REGPARM_MAX);
4246           *no_add_attrs = true;
4247         }
4248
4249       return NULL_TREE;
4250     }
4251
4252   if (TARGET_64BIT)
4253     {
4254       /* Do not warn when emulating the MS ABI.  */
4255       if (TREE_CODE (*node) != FUNCTION_TYPE || ix86_function_type_abi (*node)!=MS_ABI)
4256         warning (OPT_Wattributes, "%qs attribute ignored",
4257                  IDENTIFIER_POINTER (name));
4258       *no_add_attrs = true;
4259       return NULL_TREE;
4260     }
4261
4262   /* Can combine fastcall with stdcall (redundant) and sseregparm.  */
4263   if (is_attribute_p ("fastcall", name))
4264     {
4265       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
4266         {
4267           error ("fastcall and cdecl attributes are not compatible");
4268         }
4269       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
4270         {
4271           error ("fastcall and stdcall attributes are not compatible");
4272         }
4273       if (lookup_attribute ("regparm", TYPE_ATTRIBUTES (*node)))
4274         {
4275           error ("fastcall and regparm attributes are not compatible");
4276         }
4277     }
4278
4279   /* Can combine stdcall with fastcall (redundant), regparm and
4280      sseregparm.  */
4281   else if (is_attribute_p ("stdcall", name))
4282     {
4283       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
4284         {
4285           error ("stdcall and cdecl attributes are not compatible");
4286         }
4287       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4288         {
4289           error ("stdcall and fastcall attributes are not compatible");
4290         }
4291     }
4292
4293   /* Can combine cdecl with regparm and sseregparm.  */
4294   else if (is_attribute_p ("cdecl", name))
4295     {
4296       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
4297         {
4298           error ("stdcall and cdecl attributes are not compatible");
4299         }
4300       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4301         {
4302           error ("fastcall and cdecl attributes are not compatible");
4303         }
4304     }
4305
4306   /* Can combine sseregparm with all attributes.  */
4307
4308   return NULL_TREE;
4309 }
4310
4311 /* Return 0 if the attributes for two types are incompatible, 1 if they
4312    are compatible, and 2 if they are nearly compatible (which causes a
4313    warning to be generated).  */
4314
4315 static int
4316 ix86_comp_type_attributes (const_tree type1, const_tree type2)
4317 {
4318   /* Check for mismatch of non-default calling convention.  */
4319   const char *const rtdstr = TARGET_RTD ? "cdecl" : "stdcall";
4320
4321   if (TREE_CODE (type1) != FUNCTION_TYPE
4322       && TREE_CODE (type1) != METHOD_TYPE)
4323     return 1;
4324
4325   /* Check for mismatched fastcall/regparm types.  */
4326   if ((!lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type1))
4327        != !lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type2)))
4328       || (ix86_function_regparm (type1, NULL)
4329           != ix86_function_regparm (type2, NULL)))
4330     return 0;
4331
4332   /* Check for mismatched sseregparm types.  */
4333   if (!lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type1))
4334       != !lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type2)))
4335     return 0;
4336
4337   /* Check for mismatched return types (cdecl vs stdcall).  */
4338   if (!lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type1))
4339       != !lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type2)))
4340     return 0;
4341
4342   return 1;
4343 }
4344 \f
4345 /* Return the regparm value for a function with the indicated TYPE and DECL.
4346    DECL may be NULL when calling function indirectly
4347    or considering a libcall.  */
4348
4349 static int
4350 ix86_function_regparm (const_tree type, const_tree decl)
4351 {
4352   tree attr;
4353   int regparm;
4354
4355   static bool error_issued;
4356
4357   if (TARGET_64BIT)
4358     return (ix86_function_type_abi (type) == SYSV_ABI
4359             ? X86_64_REGPARM_MAX : X64_REGPARM_MAX);
4360
4361   regparm = ix86_regparm;
4362   attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (type));
4363   if (attr)
4364     {
4365       regparm
4366         = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
4367
4368       if (decl && TREE_CODE (decl) == FUNCTION_DECL)
4369         {
4370           /* We can't use regparm(3) for nested functions because
4371              these pass static chain pointer in %ecx register.  */
4372           if (!error_issued && regparm == 3
4373               && decl_function_context (decl)
4374               && !DECL_NO_STATIC_CHAIN (decl))
4375             {
4376               error ("nested functions are limited to 2 register parameters");
4377               error_issued = true;
4378               return 0;
4379             }
4380         }
4381
4382       return regparm;
4383     }
4384
4385   if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
4386     return 2;
4387
4388   /* Use register calling convention for local functions when possible.  */
4389   if (decl
4390       && TREE_CODE (decl) == FUNCTION_DECL
4391       && optimize
4392       && !profile_flag)
4393     {
4394       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
4395       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
4396       if (i && i->local)
4397         {
4398           int local_regparm, globals = 0, regno;
4399           struct function *f;
4400
4401           /* Make sure no regparm register is taken by a
4402              fixed register variable.  */
4403           for (local_regparm = 0; local_regparm < REGPARM_MAX; local_regparm++)
4404             if (fixed_regs[local_regparm])
4405               break;
4406
4407           /* We can't use regparm(3) for nested functions as these use
4408              static chain pointer in third argument.  */
4409           if (local_regparm == 3
4410               && decl_function_context (decl)
4411               && !DECL_NO_STATIC_CHAIN (decl))
4412             local_regparm = 2;
4413
4414           /* If the function realigns its stackpointer, the prologue will
4415              clobber %ecx.  If we've already generated code for the callee,
4416              the callee DECL_STRUCT_FUNCTION is gone, so we fall back to
4417              scanning the attributes for the self-realigning property.  */
4418           f = DECL_STRUCT_FUNCTION (decl);
4419           /* Since current internal arg pointer won't conflict with
4420              parameter passing regs, so no need to change stack
4421              realignment and adjust regparm number.
4422
4423              Each fixed register usage increases register pressure,
4424              so less registers should be used for argument passing.
4425              This functionality can be overriden by an explicit
4426              regparm value.  */
4427           for (regno = 0; regno <= DI_REG; regno++)
4428             if (fixed_regs[regno])
4429               globals++;
4430
4431           local_regparm
4432             = globals < local_regparm ? local_regparm - globals : 0;
4433
4434           if (local_regparm > regparm)
4435             regparm = local_regparm;
4436         }
4437     }
4438
4439   return regparm;
4440 }
4441
4442 /* Return 1 or 2, if we can pass up to SSE_REGPARM_MAX SFmode (1) and
4443    DFmode (2) arguments in SSE registers for a function with the
4444    indicated TYPE and DECL.  DECL may be NULL when calling function
4445    indirectly or considering a libcall.  Otherwise return 0.  */
4446
4447 static int
4448 ix86_function_sseregparm (const_tree type, const_tree decl, bool warn)
4449 {
4450   gcc_assert (!TARGET_64BIT);
4451
4452   /* Use SSE registers to pass SFmode and DFmode arguments if requested
4453      by the sseregparm attribute.  */
4454   if (TARGET_SSEREGPARM
4455       || (type && lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type))))
4456     {
4457       if (!TARGET_SSE)
4458         {
4459           if (warn)
4460             {
4461               if (decl)
4462                 error ("Calling %qD with attribute sseregparm without "
4463                        "SSE/SSE2 enabled", decl);
4464               else
4465                 error ("Calling %qT with attribute sseregparm without "
4466                        "SSE/SSE2 enabled", type);
4467             }
4468           return 0;
4469         }
4470
4471       return 2;
4472     }
4473
4474   /* For local functions, pass up to SSE_REGPARM_MAX SFmode
4475      (and DFmode for SSE2) arguments in SSE registers.  */
4476   if (decl && TARGET_SSE_MATH && optimize && !profile_flag)
4477     {
4478       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
4479       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
4480       if (i && i->local)
4481         return TARGET_SSE2 ? 2 : 1;
4482     }
4483
4484   return 0;
4485 }
4486
4487 /* Return true if EAX is live at the start of the function.  Used by
4488    ix86_expand_prologue to determine if we need special help before
4489    calling allocate_stack_worker.  */
4490
4491 static bool
4492 ix86_eax_live_at_start_p (void)
4493 {
4494   /* Cheat.  Don't bother working forward from ix86_function_regparm
4495      to the function type to whether an actual argument is located in
4496      eax.  Instead just look at cfg info, which is still close enough
4497      to correct at this point.  This gives false positives for broken
4498      functions that might use uninitialized data that happens to be
4499      allocated in eax, but who cares?  */
4500   return REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR), 0);
4501 }
4502
4503 /* Value is the number of bytes of arguments automatically
4504    popped when returning from a subroutine call.
4505    FUNDECL is the declaration node of the function (as a tree),
4506    FUNTYPE is the data type of the function (as a tree),
4507    or for a library call it is an identifier node for the subroutine name.
4508    SIZE is the number of bytes of arguments passed on the stack.
4509
4510    On the 80386, the RTD insn may be used to pop them if the number
4511      of args is fixed, but if the number is variable then the caller
4512      must pop them all.  RTD can't be used for library calls now
4513      because the library is compiled with the Unix compiler.
4514    Use of RTD is a selectable option, since it is incompatible with
4515    standard Unix calling sequences.  If the option is not selected,
4516    the caller must always pop the args.
4517
4518    The attribute stdcall is equivalent to RTD on a per module basis.  */
4519
4520 int
4521 ix86_return_pops_args (tree fundecl, tree funtype, int size)
4522 {
4523   int rtd;
4524
4525   /* None of the 64-bit ABIs pop arguments.  */
4526   if (TARGET_64BIT)
4527     return 0;
4528
4529   rtd = TARGET_RTD && (!fundecl || TREE_CODE (fundecl) != IDENTIFIER_NODE);
4530
4531   /* Cdecl functions override -mrtd, and never pop the stack.  */
4532   if (! lookup_attribute ("cdecl", TYPE_ATTRIBUTES (funtype)))
4533     {
4534       /* Stdcall and fastcall functions will pop the stack if not
4535          variable args.  */
4536       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype))
4537           || lookup_attribute ("fastcall", TYPE_ATTRIBUTES (funtype)))
4538         rtd = 1;
4539
4540       if (rtd && ! stdarg_p (funtype))
4541         return size;
4542     }
4543
4544   /* Lose any fake structure return argument if it is passed on the stack.  */
4545   if (aggregate_value_p (TREE_TYPE (funtype), fundecl)
4546       && !KEEP_AGGREGATE_RETURN_POINTER)
4547     {
4548       int nregs = ix86_function_regparm (funtype, fundecl);
4549       if (nregs == 0)
4550         return GET_MODE_SIZE (Pmode);
4551     }
4552
4553   return 0;
4554 }
4555 \f
4556 /* Argument support functions.  */
4557
4558 /* Return true when register may be used to pass function parameters.  */
4559 bool
4560 ix86_function_arg_regno_p (int regno)
4561 {
4562   int i;
4563   const int *parm_regs;
4564
4565   if (!TARGET_64BIT)
4566     {
4567       if (TARGET_MACHO)
4568         return (regno < REGPARM_MAX
4569                 || (TARGET_SSE && SSE_REGNO_P (regno) && !fixed_regs[regno]));
4570       else
4571         return (regno < REGPARM_MAX
4572                 || (TARGET_MMX && MMX_REGNO_P (regno)
4573                     && (regno < FIRST_MMX_REG + MMX_REGPARM_MAX))
4574                 || (TARGET_SSE && SSE_REGNO_P (regno)
4575                     && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX)));
4576     }
4577
4578   if (TARGET_MACHO)
4579     {
4580       if (SSE_REGNO_P (regno) && TARGET_SSE)
4581         return true;
4582     }
4583   else
4584     {
4585       if (TARGET_SSE && SSE_REGNO_P (regno)
4586           && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX))
4587         return true;
4588     }
4589
4590   /* TODO: The function should depend on current function ABI but
4591      builtins.c would need updating then. Therefore we use the
4592      default ABI.  */
4593
4594   /* RAX is used as hidden argument to va_arg functions.  */
4595   if (DEFAULT_ABI == SYSV_ABI && regno == AX_REG)
4596     return true;
4597
4598   if (DEFAULT_ABI == MS_ABI)
4599     parm_regs = x86_64_ms_abi_int_parameter_registers;
4600   else
4601     parm_regs = x86_64_int_parameter_registers;
4602   for (i = 0; i < (DEFAULT_ABI == MS_ABI ? X64_REGPARM_MAX
4603                                          : X86_64_REGPARM_MAX); i++)
4604     if (regno == parm_regs[i])
4605       return true;
4606   return false;
4607 }
4608
4609 /* Return if we do not know how to pass TYPE solely in registers.  */
4610
4611 static bool
4612 ix86_must_pass_in_stack (enum machine_mode mode, const_tree type)
4613 {
4614   if (must_pass_in_stack_var_size_or_pad (mode, type))
4615     return true;
4616
4617   /* For 32-bit, we want TImode aggregates to go on the stack.  But watch out!
4618      The layout_type routine is crafty and tries to trick us into passing
4619      currently unsupported vector types on the stack by using TImode.  */
4620   return (!TARGET_64BIT && mode == TImode
4621           && type && TREE_CODE (type) != VECTOR_TYPE);
4622 }
4623
4624 /* It returns the size, in bytes, of the area reserved for arguments passed
4625    in registers for the function represented by fndecl dependent to the used
4626    abi format.  */
4627 int
4628 ix86_reg_parm_stack_space (const_tree fndecl)
4629 {
4630   int call_abi = SYSV_ABI;
4631   if (fndecl != NULL_TREE && TREE_CODE (fndecl) == FUNCTION_DECL)
4632     call_abi = ix86_function_abi (fndecl);
4633   else
4634     call_abi = ix86_function_type_abi (fndecl);
4635   if (call_abi == MS_ABI)
4636     return 32;
4637   return 0;
4638 }
4639
4640 /* Returns value SYSV_ABI, MS_ABI dependent on fntype, specifying the
4641    call abi used.  */
4642 int
4643 ix86_function_type_abi (const_tree fntype)
4644 {
4645   if (TARGET_64BIT && fntype != NULL)
4646     {
4647       int abi;
4648       if (DEFAULT_ABI == SYSV_ABI)
4649         abi = lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (fntype)) ? MS_ABI : SYSV_ABI;
4650       else
4651         abi = lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (fntype)) ? SYSV_ABI : MS_ABI;
4652
4653       return abi;
4654     }
4655   return DEFAULT_ABI;
4656 }
4657
4658 int
4659 ix86_function_abi (const_tree fndecl)
4660 {
4661   if (! fndecl)
4662     return DEFAULT_ABI;
4663   return ix86_function_type_abi (TREE_TYPE (fndecl));
4664 }
4665
4666 /* Returns value SYSV_ABI, MS_ABI dependent on cfun, specifying the
4667    call abi used.  */
4668 int
4669 ix86_cfun_abi (void)
4670 {
4671   if (! cfun || ! TARGET_64BIT)
4672     return DEFAULT_ABI;
4673   return cfun->machine->call_abi;
4674 }
4675
4676 /* regclass.c  */
4677 extern void init_regs (void);
4678
4679 /* Implementation of call abi switching target hook. Specific to FNDECL
4680    the specific call register sets are set. See also CONDITIONAL_REGISTER_USAGE
4681    for more details.  */
4682 void
4683 ix86_call_abi_override (const_tree fndecl)
4684 {
4685   if (fndecl == NULL_TREE)
4686     cfun->machine->call_abi = DEFAULT_ABI;
4687   else
4688     cfun->machine->call_abi = ix86_function_type_abi (TREE_TYPE (fndecl));
4689 }
4690
4691 /* MS and SYSV ABI have different set of call used registers.  Avoid expensive
4692    re-initialization of init_regs each time we switch function context since
4693    this is needed only during RTL expansion.  */
4694 static void
4695 ix86_maybe_switch_abi (void)
4696 {
4697   if (TARGET_64BIT &&
4698       call_used_regs[SI_REG] == (cfun->machine->call_abi == MS_ABI))
4699     reinit_regs ();
4700 }
4701
4702 /* Initialize a variable CUM of type CUMULATIVE_ARGS
4703    for a call to a function whose data type is FNTYPE.
4704    For a library call, FNTYPE is 0.  */
4705
4706 void
4707 init_cumulative_args (CUMULATIVE_ARGS *cum,  /* Argument info to initialize */
4708                       tree fntype,      /* tree ptr for function decl */
4709                       rtx libname,      /* SYMBOL_REF of library name or 0 */
4710                       tree fndecl)
4711 {
4712   struct cgraph_local_info *i = fndecl ? cgraph_local_info (fndecl) : NULL;
4713   memset (cum, 0, sizeof (*cum));
4714
4715   if (fndecl)
4716    cum->call_abi = ix86_function_abi (fndecl);
4717   else
4718    cum->call_abi = ix86_function_type_abi (fntype);
4719   /* Set up the number of registers to use for passing arguments.  */
4720
4721   if (cum->call_abi == MS_ABI && !ACCUMULATE_OUTGOING_ARGS)
4722     sorry ("ms_abi attribute requires -maccumulate-outgoing-args "
4723            "or subtarget optimization implying it");
4724   cum->nregs = ix86_regparm;
4725   if (TARGET_64BIT)
4726     {
4727       if (cum->call_abi != DEFAULT_ABI)
4728         cum->nregs = DEFAULT_ABI != SYSV_ABI ? X86_64_REGPARM_MAX
4729                                              : X64_REGPARM_MAX;
4730     }
4731   if (TARGET_SSE)
4732     {
4733       cum->sse_nregs = SSE_REGPARM_MAX;
4734       if (TARGET_64BIT)
4735         {
4736           if (cum->call_abi != DEFAULT_ABI)
4737             cum->sse_nregs = DEFAULT_ABI != SYSV_ABI ? X86_64_SSE_REGPARM_MAX
4738                                                      : X64_SSE_REGPARM_MAX;
4739         }
4740     }
4741   if (TARGET_MMX)
4742     cum->mmx_nregs = MMX_REGPARM_MAX;
4743   cum->warn_avx = true;
4744   cum->warn_sse = true;
4745   cum->warn_mmx = true;
4746
4747   /* Because type might mismatch in between caller and callee, we need to
4748      use actual type of function for local calls.
4749      FIXME: cgraph_analyze can be told to actually record if function uses
4750      va_start so for local functions maybe_vaarg can be made aggressive
4751      helping K&R code.
4752      FIXME: once typesytem is fixed, we won't need this code anymore.  */
4753   if (i && i->local)
4754     fntype = TREE_TYPE (fndecl);
4755   cum->maybe_vaarg = (fntype
4756                       ? (!prototype_p (fntype) || stdarg_p (fntype))
4757                       : !libname);
4758
4759   if (!TARGET_64BIT)
4760     {
4761       /* If there are variable arguments, then we won't pass anything
4762          in registers in 32-bit mode. */
4763       if (stdarg_p (fntype))
4764         {
4765           cum->nregs = 0;
4766           cum->sse_nregs = 0;
4767           cum->mmx_nregs = 0;
4768           cum->warn_avx = 0;
4769           cum->warn_sse = 0;
4770           cum->warn_mmx = 0;
4771           return;
4772         }
4773
4774       /* Use ecx and edx registers if function has fastcall attribute,
4775          else look for regparm information.  */
4776       if (fntype)
4777         {
4778           if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)))
4779             {
4780               cum->nregs = 2;
4781               cum->fastcall = 1;
4782             }
4783           else
4784             cum->nregs = ix86_function_regparm (fntype, fndecl);
4785         }
4786
4787       /* Set up the number of SSE registers used for passing SFmode
4788          and DFmode arguments.  Warn for mismatching ABI.  */
4789       cum->float_in_sse = ix86_function_sseregparm (fntype, fndecl, true);
4790     }
4791 }
4792
4793 /* Return the "natural" mode for TYPE.  In most cases, this is just TYPE_MODE.
4794    But in the case of vector types, it is some vector mode.
4795
4796    When we have only some of our vector isa extensions enabled, then there
4797    are some modes for which vector_mode_supported_p is false.  For these
4798    modes, the generic vector support in gcc will choose some non-vector mode
4799    in order to implement the type.  By computing the natural mode, we'll
4800    select the proper ABI location for the operand and not depend on whatever
4801    the middle-end decides to do with these vector types.
4802
4803    The midde-end can't deal with the vector types > 16 bytes.  In this
4804    case, we return the original mode and warn ABI change if CUM isn't
4805    NULL.  */
4806
4807 static enum machine_mode
4808 type_natural_mode (const_tree type, CUMULATIVE_ARGS *cum)
4809 {
4810   enum machine_mode mode = TYPE_MODE (type);
4811
4812   if (TREE_CODE (type) == VECTOR_TYPE && !VECTOR_MODE_P (mode))
4813     {
4814       HOST_WIDE_INT size = int_size_in_bytes (type);
4815       if ((size == 8 || size == 16 || size == 32)
4816           /* ??? Generic code allows us to create width 1 vectors.  Ignore.  */
4817           && TYPE_VECTOR_SUBPARTS (type) > 1)
4818         {
4819           enum machine_mode innermode = TYPE_MODE (TREE_TYPE (type));
4820
4821           if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
4822             mode = MIN_MODE_VECTOR_FLOAT;
4823           else
4824             mode = MIN_MODE_VECTOR_INT;
4825
4826           /* Get the mode which has this inner mode and number of units.  */
4827           for (; mode != VOIDmode; mode = GET_MODE_WIDER_MODE (mode))
4828             if (GET_MODE_NUNITS (mode) == TYPE_VECTOR_SUBPARTS (type)
4829                 && GET_MODE_INNER (mode) == innermode)
4830               {
4831                 if (size == 32 && !TARGET_AVX)
4832                   {
4833                     static bool warnedavx;
4834
4835                     if (cum
4836                         && !warnedavx 
4837                         && cum->warn_avx)
4838                       {
4839                         warnedavx = true;
4840                         warning (0, "AVX vector argument without AVX "
4841                                  "enabled changes the ABI");
4842                       }
4843                     return TYPE_MODE (type);
4844                   }
4845                 else
4846                   return mode;
4847               }
4848
4849           gcc_unreachable ();
4850         }
4851     }
4852
4853   return mode;
4854 }
4855
4856 /* We want to pass a value in REGNO whose "natural" mode is MODE.  However,
4857    this may not agree with the mode that the type system has chosen for the
4858    register, which is ORIG_MODE.  If ORIG_MODE is not BLKmode, then we can
4859    go ahead and use it.  Otherwise we have to build a PARALLEL instead.  */
4860
4861 static rtx
4862 gen_reg_or_parallel (enum machine_mode mode, enum machine_mode orig_mode,
4863                      unsigned int regno)
4864 {
4865   rtx tmp;
4866
4867   if (orig_mode != BLKmode)
4868     tmp = gen_rtx_REG (orig_mode, regno);
4869   else
4870     {
4871       tmp = gen_rtx_REG (mode, regno);
4872       tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp, const0_rtx);
4873       tmp = gen_rtx_PARALLEL (orig_mode, gen_rtvec (1, tmp));
4874     }
4875
4876   return tmp;
4877 }
4878
4879 /* x86-64 register passing implementation.  See x86-64 ABI for details.  Goal
4880    of this code is to classify each 8bytes of incoming argument by the register
4881    class and assign registers accordingly.  */
4882
4883 /* Return the union class of CLASS1 and CLASS2.
4884    See the x86-64 PS ABI for details.  */
4885
4886 static enum x86_64_reg_class
4887 merge_classes (enum x86_64_reg_class class1, enum x86_64_reg_class class2)
4888 {
4889   /* Rule #1: If both classes are equal, this is the resulting class.  */
4890   if (class1 == class2)
4891     return class1;
4892
4893   /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
4894      the other class.  */
4895   if (class1 == X86_64_NO_CLASS)
4896     return class2;
4897   if (class2 == X86_64_NO_CLASS)
4898     return class1;
4899
4900   /* Rule #3: If one of the classes is MEMORY, the result is MEMORY.  */
4901   if (class1 == X86_64_MEMORY_CLASS || class2 == X86_64_MEMORY_CLASS)
4902     return X86_64_MEMORY_CLASS;
4903
4904   /* Rule #4: If one of the classes is INTEGER, the result is INTEGER.  */
4905   if ((class1 == X86_64_INTEGERSI_CLASS && class2 == X86_64_SSESF_CLASS)
4906       || (class2 == X86_64_INTEGERSI_CLASS && class1 == X86_64_SSESF_CLASS))
4907     return X86_64_INTEGERSI_CLASS;
4908   if (class1 == X86_64_INTEGER_CLASS || class1 == X86_64_INTEGERSI_CLASS
4909       || class2 == X86_64_INTEGER_CLASS || class2 == X86_64_INTEGERSI_CLASS)
4910     return X86_64_INTEGER_CLASS;
4911
4912   /* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class,
4913      MEMORY is used.  */
4914   if (class1 == X86_64_X87_CLASS
4915       || class1 == X86_64_X87UP_CLASS
4916       || class1 == X86_64_COMPLEX_X87_CLASS
4917       || class2 == X86_64_X87_CLASS
4918       || class2 == X86_64_X87UP_CLASS
4919       || class2 == X86_64_COMPLEX_X87_CLASS)
4920     return X86_64_MEMORY_CLASS;
4921
4922   /* Rule #6: Otherwise class SSE is used.  */
4923   return X86_64_SSE_CLASS;
4924 }
4925
4926 /* Classify the argument of type TYPE and mode MODE.
4927    CLASSES will be filled by the register class used to pass each word
4928    of the operand.  The number of words is returned.  In case the parameter
4929    should be passed in memory, 0 is returned. As a special case for zero
4930    sized containers, classes[0] will be NO_CLASS and 1 is returned.
4931
4932    BIT_OFFSET is used internally for handling records and specifies offset
4933    of the offset in bits modulo 256 to avoid overflow cases.
4934
4935    See the x86-64 PS ABI for details.
4936 */
4937
4938 static int
4939 classify_argument (enum machine_mode mode, const_tree type,
4940                    enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset)
4941 {
4942   HOST_WIDE_INT bytes =
4943     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
4944   int words = (bytes + (bit_offset % 64) / 8 + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4945
4946   /* Variable sized entities are always passed/returned in memory.  */
4947   if (bytes < 0)
4948     return 0;
4949
4950   if (mode != VOIDmode
4951       && targetm.calls.must_pass_in_stack (mode, type))
4952     return 0;
4953
4954   if (type && AGGREGATE_TYPE_P (type))
4955     {
4956       int i;
4957       tree field;
4958       enum x86_64_reg_class subclasses[MAX_CLASSES];
4959
4960       /* On x86-64 we pass structures larger than 32 bytes on the stack.  */
4961       if (bytes > 32)
4962         return 0;
4963
4964       for (i = 0; i < words; i++)
4965         classes[i] = X86_64_NO_CLASS;
4966
4967       /* Zero sized arrays or structures are NO_CLASS.  We return 0 to
4968          signalize memory class, so handle it as special case.  */
4969       if (!words)
4970         {
4971           classes[0] = X86_64_NO_CLASS;
4972           return 1;
4973         }
4974
4975       /* Classify each field of record and merge classes.  */
4976       switch (TREE_CODE (type))
4977         {
4978         case RECORD_TYPE:
4979           /* And now merge the fields of structure.  */
4980           for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4981             {
4982               if (TREE_CODE (field) == FIELD_DECL)
4983                 {
4984                   int num;
4985
4986                   if (TREE_TYPE (field) == error_mark_node)
4987                     continue;
4988
4989                   /* Bitfields are always classified as integer.  Handle them
4990                      early, since later code would consider them to be
4991                      misaligned integers.  */
4992                   if (DECL_BIT_FIELD (field))
4993                     {
4994                       for (i = (int_bit_position (field) + (bit_offset % 64)) / 8 / 8;
4995                            i < ((int_bit_position (field) + (bit_offset % 64))
4996                                 + tree_low_cst (DECL_SIZE (field), 0)
4997                                 + 63) / 8 / 8; i++)
4998                         classes[i] =
4999                           merge_classes (X86_64_INTEGER_CLASS,
5000                                          classes[i]);
5001                     }
5002                   else
5003                     {
5004                       type = TREE_TYPE (field);
5005
5006                       /* Flexible array member is ignored.  */
5007                       if (TYPE_MODE (type) == BLKmode
5008                           && TREE_CODE (type) == ARRAY_TYPE
5009                           && TYPE_SIZE (type) == NULL_TREE
5010                           && TYPE_DOMAIN (type) != NULL_TREE
5011                           && (TYPE_MAX_VALUE (TYPE_DOMAIN (type))
5012                               == NULL_TREE))
5013                         {
5014                           static bool warned;
5015                           
5016                           if (!warned && warn_psabi)
5017                             {
5018                               warned = true;
5019                               inform (input_location,
5020                                       "The ABI of passing struct with"
5021                                       " a flexible array member has"
5022                                       " changed in GCC 4.4");
5023                             }
5024                           continue;
5025                         }
5026                       num = classify_argument (TYPE_MODE (type), type,
5027                                                subclasses,
5028                                                (int_bit_position (field)
5029                                                 + bit_offset) % 256);
5030                       if (!num)
5031                         return 0;
5032                       for (i = 0; i < num; i++)
5033                         {
5034                           int pos =
5035                             (int_bit_position (field) + (bit_offset % 64)) / 8 / 8;
5036                           classes[i + pos] =
5037                             merge_classes (subclasses[i], classes[i + pos]);
5038                         }
5039                     }
5040                 }
5041             }
5042           break;
5043
5044         case ARRAY_TYPE:
5045           /* Arrays are handled as small records.  */
5046           {
5047             int num;
5048             num = classify_argument (TYPE_MODE (TREE_TYPE (type)),
5049                                      TREE_TYPE (type), subclasses, bit_offset);
5050             if (!num)
5051               return 0;
5052
5053             /* The partial classes are now full classes.  */
5054             if (subclasses[0] == X86_64_SSESF_CLASS && bytes != 4)
5055               subclasses[0] = X86_64_SSE_CLASS;
5056             if (subclasses[0] == X86_64_INTEGERSI_CLASS
5057                 && !((bit_offset % 64) == 0 && bytes == 4))
5058               subclasses[0] = X86_64_INTEGER_CLASS;
5059
5060             for (i = 0; i < words; i++)
5061               classes[i] = subclasses[i % num];
5062
5063             break;
5064           }
5065         case UNION_TYPE:
5066         case QUAL_UNION_TYPE:
5067           /* Unions are similar to RECORD_TYPE but offset is always 0.
5068              */
5069           for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5070             {
5071               if (TREE_CODE (field) == FIELD_DECL)
5072                 {
5073                   int num;
5074
5075                   if (TREE_TYPE (field) == error_mark_node)
5076                     continue;
5077
5078                   num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
5079                                            TREE_TYPE (field), subclasses,
5080                                            bit_offset);
5081                   if (!num)
5082                     return 0;
5083                   for (i = 0; i < num; i++)
5084                     classes[i] = merge_classes (subclasses[i], classes[i]);
5085                 }
5086             }
5087           break;
5088
5089         default:
5090           gcc_unreachable ();
5091         }
5092
5093       if (words > 2)
5094         {
5095           /* When size > 16 bytes, if the first one isn't
5096              X86_64_SSE_CLASS or any other ones aren't
5097              X86_64_SSEUP_CLASS, everything should be passed in
5098              memory.  */
5099           if (classes[0] != X86_64_SSE_CLASS)
5100               return 0;
5101
5102           for (i = 1; i < words; i++)
5103             if (classes[i] != X86_64_SSEUP_CLASS)
5104               return 0;
5105         }
5106
5107       /* Final merger cleanup.  */
5108       for (i = 0; i < words; i++)
5109         {
5110           /* If one class is MEMORY, everything should be passed in
5111              memory.  */
5112           if (classes[i] == X86_64_MEMORY_CLASS)
5113             return 0;
5114
5115           /* The X86_64_SSEUP_CLASS should be always preceded by
5116              X86_64_SSE_CLASS or X86_64_SSEUP_CLASS.  */
5117           if (classes[i] == X86_64_SSEUP_CLASS
5118               && classes[i - 1] != X86_64_SSE_CLASS
5119               && classes[i - 1] != X86_64_SSEUP_CLASS)
5120             {
5121               /* The first one should never be X86_64_SSEUP_CLASS.  */
5122               gcc_assert (i != 0);
5123               classes[i] = X86_64_SSE_CLASS;
5124             }
5125
5126           /*  If X86_64_X87UP_CLASS isn't preceded by X86_64_X87_CLASS,
5127                everything should be passed in memory.  */
5128           if (classes[i] == X86_64_X87UP_CLASS
5129               && (classes[i - 1] != X86_64_X87_CLASS))
5130             {
5131               static bool warned;
5132
5133               /* The first one should never be X86_64_X87UP_CLASS.  */
5134               gcc_assert (i != 0);
5135               if (!warned && warn_psabi)
5136                 {
5137                   warned = true;
5138                   inform (input_location,
5139                           "The ABI of passing union with long double"
5140                           " has changed in GCC 4.4");
5141                 }
5142               return 0;
5143             }
5144         }
5145       return words;
5146     }
5147
5148   /* Compute alignment needed.  We align all types to natural boundaries with
5149      exception of XFmode that is aligned to 64bits.  */
5150   if (mode != VOIDmode && mode != BLKmode)
5151     {
5152       int mode_alignment = GET_MODE_BITSIZE (mode);
5153
5154       if (mode == XFmode)
5155         mode_alignment = 128;
5156       else if (mode == XCmode)
5157         mode_alignment = 256;
5158       if (COMPLEX_MODE_P (mode))
5159         mode_alignment /= 2;
5160       /* Misaligned fields are always returned in memory.  */
5161       if (bit_offset % mode_alignment)
5162         return 0;
5163     }
5164
5165   /* for V1xx modes, just use the base mode */
5166   if (VECTOR_MODE_P (mode) && mode != V1DImode
5167       && GET_MODE_SIZE (GET_MODE_INNER (mode)) == bytes)
5168     mode = GET_MODE_INNER (mode);
5169
5170   /* Classification of atomic types.  */
5171   switch (mode)
5172     {
5173     case SDmode:
5174     case DDmode:
5175       classes[0] = X86_64_SSE_CLASS;
5176       return 1;
5177     case TDmode:
5178       classes[0] = X86_64_SSE_CLASS;
5179       classes[1] = X86_64_SSEUP_CLASS;
5180       return 2;
5181     case DImode:
5182     case SImode:
5183     case HImode:
5184     case QImode:
5185     case CSImode:
5186     case CHImode:
5187     case CQImode:
5188       {
5189         int size = (bit_offset % 64)+ (int) GET_MODE_BITSIZE (mode);
5190
5191         if (size <= 32)
5192           {
5193             classes[0] = X86_64_INTEGERSI_CLASS;
5194             return 1;
5195           }
5196         else if (size <= 64)
5197           {
5198             classes[0] = X86_64_INTEGER_CLASS;
5199             return 1;
5200           }
5201         else if (size <= 64+32)
5202           {
5203             classes[0] = X86_64_INTEGER_CLASS;
5204             classes[1] = X86_64_INTEGERSI_CLASS;
5205             return 2;
5206           }
5207         else if (size <= 64+64)
5208           {
5209             classes[0] = classes[1] = X86_64_INTEGER_CLASS;
5210             return 2;
5211           }
5212         else
5213           gcc_unreachable ();
5214       }
5215     case CDImode:
5216     case TImode:
5217       classes[0] = classes[1] = X86_64_INTEGER_CLASS;
5218       return 2;
5219     case COImode:
5220     case OImode:
5221       /* OImode shouldn't be used directly.  */
5222       gcc_unreachable ();
5223     case CTImode:
5224       return 0;
5225     case SFmode:
5226       if (!(bit_offset % 64))
5227         classes[0] = X86_64_SSESF_CLASS;
5228       else
5229         classes[0] = X86_64_SSE_CLASS;
5230       return 1;
5231     case DFmode:
5232       classes[0] = X86_64_SSEDF_CLASS;
5233       return 1;
5234     case XFmode:
5235       classes[0] = X86_64_X87_CLASS;
5236       classes[1] = X86_64_X87UP_CLASS;
5237       return 2;
5238     case TFmode:
5239       classes[0] = X86_64_SSE_CLASS;
5240       classes[1] = X86_64_SSEUP_CLASS;
5241       return 2;
5242     case SCmode:
5243       classes[0] = X86_64_SSE_CLASS;
5244       if (!(bit_offset % 64))
5245         return 1;
5246       else
5247         {
5248           static bool warned;
5249
5250           if (!warned && warn_psabi)
5251             {
5252               warned = true;
5253               inform (input_location,
5254                       "The ABI of passing structure with complex float"
5255                       " member has changed in GCC 4.4");
5256             }
5257           classes[1] = X86_64_SSESF_CLASS;
5258           return 2;
5259         }
5260     case DCmode:
5261       classes[0] = X86_64_SSEDF_CLASS;
5262       classes[1] = X86_64_SSEDF_CLASS;
5263       return 2;
5264     case XCmode:
5265       classes[0] = X86_64_COMPLEX_X87_CLASS;
5266       return 1;
5267     case TCmode:
5268       /* This modes is larger than 16 bytes.  */
5269       return 0;
5270     case V8SFmode:
5271     case V8SImode:
5272     case V32QImode:
5273     case V16HImode:
5274     case V4DFmode:
5275     case V4DImode:
5276       classes[0] = X86_64_SSE_CLASS;
5277       classes[1] = X86_64_SSEUP_CLASS;
5278       classes[2] = X86_64_SSEUP_CLASS;
5279       classes[3] = X86_64_SSEUP_CLASS;
5280       return 4;
5281     case V4SFmode:
5282     case V4SImode:
5283     case V16QImode:
5284     case V8HImode:
5285     case V2DFmode:
5286     case V2DImode:
5287       classes[0] = X86_64_SSE_CLASS;
5288       classes[1] = X86_64_SSEUP_CLASS;
5289       return 2;
5290     case V1DImode:
5291     case V2SFmode:
5292     case V2SImode:
5293     case V4HImode:
5294     case V8QImode:
5295       classes[0] = X86_64_SSE_CLASS;
5296       return 1;
5297     case BLKmode:
5298     case VOIDmode:
5299       return 0;
5300     default:
5301       gcc_assert (VECTOR_MODE_P (mode));
5302
5303       if (bytes > 16)
5304         return 0;
5305
5306       gcc_assert (GET_MODE_CLASS (GET_MODE_INNER (mode)) == MODE_INT);
5307
5308       if (bit_offset + GET_MODE_BITSIZE (mode) <= 32)
5309         classes[0] = X86_64_INTEGERSI_CLASS;
5310       else
5311         classes[0] = X86_64_INTEGER_CLASS;
5312       classes[1] = X86_64_INTEGER_CLASS;
5313       return 1 + (bytes > 8);
5314     }
5315 }
5316
5317 /* Examine the argument and return set number of register required in each
5318    class.  Return 0 iff parameter should be passed in memory.  */
5319 static int
5320 examine_argument (enum machine_mode mode, const_tree type, int in_return,
5321                   int *int_nregs, int *sse_nregs)
5322 {
5323   enum x86_64_reg_class regclass[MAX_CLASSES];
5324   int n = classify_argument (mode, type, regclass, 0);
5325
5326   *int_nregs = 0;
5327   *sse_nregs = 0;
5328   if (!n)
5329     return 0;
5330   for (n--; n >= 0; n--)
5331     switch (regclass[n])
5332       {
5333       case X86_64_INTEGER_CLASS:
5334       case X86_64_INTEGERSI_CLASS:
5335         (*int_nregs)++;
5336         break;
5337       case X86_64_SSE_CLASS:
5338       case X86_64_SSESF_CLASS:
5339       case X86_64_SSEDF_CLASS:
5340         (*sse_nregs)++;
5341         break;
5342       case X86_64_NO_CLASS:
5343       case X86_64_SSEUP_CLASS:
5344         break;
5345       case X86_64_X87_CLASS:
5346       case X86_64_X87UP_CLASS:
5347         if (!in_return)
5348           return 0;
5349         break;
5350       case X86_64_COMPLEX_X87_CLASS:
5351         return in_return ? 2 : 0;
5352       case X86_64_MEMORY_CLASS:
5353         gcc_unreachable ();
5354       }
5355   return 1;
5356 }
5357
5358 /* Construct container for the argument used by GCC interface.  See
5359    FUNCTION_ARG for the detailed description.  */
5360
5361 static rtx
5362 construct_container (enum machine_mode mode, enum machine_mode orig_mode,
5363                      const_tree type, int in_return, int nintregs, int nsseregs,
5364                      const int *intreg, int sse_regno)
5365 {
5366   /* The following variables hold the static issued_error state.  */
5367   static bool issued_sse_arg_error;
5368   static bool issued_sse_ret_error;
5369   static bool issued_x87_ret_error;
5370
5371   enum machine_mode tmpmode;
5372   int bytes =
5373     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
5374   enum x86_64_reg_class regclass[MAX_CLASSES];
5375   int n;
5376   int i;
5377   int nexps = 0;
5378   int needed_sseregs, needed_intregs;
5379   rtx exp[MAX_CLASSES];
5380   rtx ret;
5381
5382   n = classify_argument (mode, type, regclass, 0);
5383   if (!n)
5384     return NULL;
5385   if (!examine_argument (mode, type, in_return, &needed_intregs,
5386                          &needed_sseregs))
5387     return NULL;
5388   if (needed_intregs > nintregs || needed_sseregs > nsseregs)
5389     return NULL;
5390
5391   /* We allowed the user to turn off SSE for kernel mode.  Don't crash if
5392      some less clueful developer tries to use floating-point anyway.  */
5393   if (needed_sseregs && !TARGET_SSE)
5394     {
5395       if (in_return)
5396         {
5397           if (!issued_sse_ret_error)
5398             {
5399               error ("SSE register return with SSE disabled");
5400               issued_sse_ret_error = true;
5401             }
5402         }
5403       else if (!issued_sse_arg_error)
5404         {
5405           error ("SSE register argument with SSE disabled");
5406           issued_sse_arg_error = true;
5407         }
5408       return NULL;
5409     }
5410
5411   /* Likewise, error if the ABI requires us to return values in the
5412      x87 registers and the user specified -mno-80387.  */
5413   if (!TARGET_80387 && in_return)
5414     for (i = 0; i < n; i++)
5415       if (regclass[i] == X86_64_X87_CLASS
5416           || regclass[i] == X86_64_X87UP_CLASS
5417           || regclass[i] == X86_64_COMPLEX_X87_CLASS)
5418         {
5419           if (!issued_x87_ret_error)
5420             {
5421               error ("x87 register return with x87 disabled");
5422               issued_x87_ret_error = true;
5423             }
5424           return NULL;
5425         }
5426
5427   /* First construct simple cases.  Avoid SCmode, since we want to use
5428      single register to pass this type.  */
5429   if (n == 1 && mode != SCmode)
5430     switch (regclass[0])
5431       {
5432       case X86_64_INTEGER_CLASS:
5433       case X86_64_INTEGERSI_CLASS:
5434         return gen_rtx_REG (mode, intreg[0]);
5435       case X86_64_SSE_CLASS:
5436       case X86_64_SSESF_CLASS:
5437       case X86_64_SSEDF_CLASS:
5438         if (mode != BLKmode)
5439           return gen_reg_or_parallel (mode, orig_mode, 
5440                                       SSE_REGNO (sse_regno));
5441         break;
5442       case X86_64_X87_CLASS:
5443       case X86_64_COMPLEX_X87_CLASS:
5444         return gen_rtx_REG (mode, FIRST_STACK_REG);
5445       case X86_64_NO_CLASS:
5446         /* Zero sized array, struct or class.  */
5447         return NULL;
5448       default:
5449         gcc_unreachable ();
5450       }
5451   if (n == 2 && regclass[0] == X86_64_SSE_CLASS
5452       && regclass[1] == X86_64_SSEUP_CLASS && mode != BLKmode)
5453     return gen_rtx_REG (mode, SSE_REGNO (sse_regno));
5454   if (n == 4
5455       && regclass[0] == X86_64_SSE_CLASS
5456       && regclass[1] == X86_64_SSEUP_CLASS
5457       && regclass[2] == X86_64_SSEUP_CLASS
5458       && regclass[3] == X86_64_SSEUP_CLASS
5459       && mode != BLKmode)
5460     return gen_rtx_REG (mode, SSE_REGNO (sse_regno));
5461
5462   if (n == 2
5463       && regclass[0] == X86_64_X87_CLASS && regclass[1] == X86_64_X87UP_CLASS)
5464     return gen_rtx_REG (XFmode, FIRST_STACK_REG);
5465   if (n == 2 && regclass[0] == X86_64_INTEGER_CLASS
5466       && regclass[1] == X86_64_INTEGER_CLASS
5467       && (mode == CDImode || mode == TImode || mode == TFmode)
5468       && intreg[0] + 1 == intreg[1])
5469     return gen_rtx_REG (mode, intreg[0]);
5470
5471   /* Otherwise figure out the entries of the PARALLEL.  */
5472   for (i = 0; i < n; i++)
5473     {
5474       int pos;
5475
5476       switch (regclass[i])
5477         {
5478           case X86_64_NO_CLASS:
5479             break;
5480           case X86_64_INTEGER_CLASS:
5481           case X86_64_INTEGERSI_CLASS:
5482             /* Merge TImodes on aligned occasions here too.  */
5483             if (i * 8 + 8 > bytes)
5484               tmpmode = mode_for_size ((bytes - i * 8) * BITS_PER_UNIT, MODE_INT, 0);
5485             else if (regclass[i] == X86_64_INTEGERSI_CLASS)
5486               tmpmode = SImode;
5487             else
5488               tmpmode = DImode;
5489             /* We've requested 24 bytes we don't have mode for.  Use DImode.  */
5490             if (tmpmode == BLKmode)
5491               tmpmode = DImode;
5492             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5493                                                gen_rtx_REG (tmpmode, *intreg),
5494                                                GEN_INT (i*8));
5495             intreg++;
5496             break;
5497           case X86_64_SSESF_CLASS:
5498             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5499                                                gen_rtx_REG (SFmode,
5500                                                             SSE_REGNO (sse_regno)),
5501                                                GEN_INT (i*8));
5502             sse_regno++;
5503             break;
5504           case X86_64_SSEDF_CLASS:
5505             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5506                                                gen_rtx_REG (DFmode,
5507                                                             SSE_REGNO (sse_regno)),
5508                                                GEN_INT (i*8));
5509             sse_regno++;
5510             break;
5511           case X86_64_SSE_CLASS:
5512             pos = i;
5513             switch (n)
5514               {
5515               case 1:
5516                 tmpmode = DImode;
5517                 break;
5518               case 2:
5519                 if (i == 0 && regclass[1] == X86_64_SSEUP_CLASS)
5520                   {
5521                     tmpmode = TImode;
5522                     i++;
5523                   }
5524                 else
5525                   tmpmode = DImode;
5526                 break;
5527               case 4:
5528                 gcc_assert (i == 0
5529                             && regclass[1] == X86_64_SSEUP_CLASS
5530                             && regclass[2] == X86_64_SSEUP_CLASS
5531                             && regclass[3] == X86_64_SSEUP_CLASS);
5532                 tmpmode = OImode;
5533                 i += 3;
5534                 break;
5535               default:
5536                 gcc_unreachable ();
5537               }
5538             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5539                                                gen_rtx_REG (tmpmode,
5540                                                             SSE_REGNO (sse_regno)),
5541                                                GEN_INT (pos*8));
5542             sse_regno++;
5543             break;
5544           default:
5545             gcc_unreachable ();
5546         }
5547     }
5548
5549   /* Empty aligned struct, union or class.  */
5550   if (nexps == 0)
5551     return NULL;
5552
5553   ret =  gen_rtx_PARALLEL (mode, rtvec_alloc (nexps));
5554   for (i = 0; i < nexps; i++)
5555     XVECEXP (ret, 0, i) = exp [i];
5556   return ret;
5557 }
5558
5559 /* Update the data in CUM to advance over an argument of mode MODE
5560    and data type TYPE.  (TYPE is null for libcalls where that information
5561    may not be available.)  */
5562
5563 static void
5564 function_arg_advance_32 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5565                          tree type, HOST_WIDE_INT bytes, HOST_WIDE_INT words)
5566 {
5567   switch (mode)
5568     {
5569     default:
5570       break;
5571
5572     case BLKmode:
5573       if (bytes < 0)
5574         break;
5575       /* FALLTHRU */
5576
5577     case DImode:
5578     case SImode:
5579     case HImode:
5580     case QImode:
5581       cum->words += words;
5582       cum->nregs -= words;
5583       cum->regno += words;
5584
5585       if (cum->nregs <= 0)
5586         {
5587           cum->nregs = 0;
5588           cum->regno = 0;
5589         }
5590       break;
5591
5592     case OImode:
5593       /* OImode shouldn't be used directly.  */
5594       gcc_unreachable ();
5595
5596     case DFmode:
5597       if (cum->float_in_sse < 2)
5598         break;
5599     case SFmode:
5600       if (cum->float_in_sse < 1)
5601         break;
5602       /* FALLTHRU */
5603
5604     case V8SFmode:
5605     case V8SImode:
5606     case V32QImode:
5607     case V16HImode:
5608     case V4DFmode:
5609     case V4DImode:
5610     case TImode:
5611     case V16QImode:
5612     case V8HImode:
5613     case V4SImode:
5614     case V2DImode:
5615     case V4SFmode:
5616     case V2DFmode:
5617       if (!type || !AGGREGATE_TYPE_P (type))
5618         {
5619           cum->sse_words += words;
5620           cum->sse_nregs -= 1;
5621           cum->sse_regno += 1;
5622           if (cum->sse_nregs <= 0)
5623             {
5624               cum->sse_nregs = 0;
5625               cum->sse_regno = 0;
5626             }
5627         }
5628       break;
5629
5630     case V8QImode:
5631     case V4HImode:
5632     case V2SImode:
5633     case V2SFmode:
5634     case V1DImode:
5635       if (!type || !AGGREGATE_TYPE_P (type))
5636         {
5637           cum->mmx_words += words;
5638           cum->mmx_nregs -= 1;
5639           cum->mmx_regno += 1;
5640           if (cum->mmx_nregs <= 0)
5641             {
5642               cum->mmx_nregs = 0;
5643               cum->mmx_regno = 0;
5644             }
5645         }
5646       break;
5647     }
5648 }
5649
5650 static void
5651 function_arg_advance_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5652                          tree type, HOST_WIDE_INT words, int named)
5653 {
5654   int int_nregs, sse_nregs;
5655
5656   /* Unnamed 256bit vector mode parameters are passed on stack.  */
5657   if (!named && VALID_AVX256_REG_MODE (mode))
5658     return;
5659
5660   if (examine_argument (mode, type, 0, &int_nregs, &sse_nregs)
5661       && sse_nregs <= cum->sse_nregs && int_nregs <= cum->nregs)
5662     {
5663       cum->nregs -= int_nregs;
5664       cum->sse_nregs -= sse_nregs;
5665       cum->regno += int_nregs;
5666       cum->sse_regno += sse_nregs;
5667     }
5668   else
5669     {
5670       int align = ix86_function_arg_boundary (mode, type) / BITS_PER_WORD;
5671       cum->words = (cum->words + align - 1) & ~(align - 1);
5672       cum->words += words;
5673     }
5674 }
5675
5676 static void
5677 function_arg_advance_ms_64 (CUMULATIVE_ARGS *cum, HOST_WIDE_INT bytes,
5678                             HOST_WIDE_INT words)
5679 {
5680   /* Otherwise, this should be passed indirect.  */
5681   gcc_assert (bytes == 1 || bytes == 2 || bytes == 4 || bytes == 8);
5682
5683   cum->words += words;
5684   if (cum->nregs > 0)
5685     {
5686       cum->nregs -= 1;
5687       cum->regno += 1;
5688     }
5689 }
5690
5691 void
5692 function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5693                       tree type, int named)
5694 {
5695   HOST_WIDE_INT bytes, words;
5696
5697   if (mode == BLKmode)
5698     bytes = int_size_in_bytes (type);
5699   else
5700     bytes = GET_MODE_SIZE (mode);
5701   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5702
5703   if (type)
5704     mode = type_natural_mode (type, NULL);
5705
5706   if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
5707     function_arg_advance_ms_64 (cum, bytes, words);
5708   else if (TARGET_64BIT)
5709     function_arg_advance_64 (cum, mode, type, words, named);
5710   else
5711     function_arg_advance_32 (cum, mode, type, bytes, words);
5712 }
5713
5714 /* Define where to put the arguments to a function.
5715    Value is zero to push the argument on the stack,
5716    or a hard register in which to store the argument.
5717
5718    MODE is the argument's machine mode.
5719    TYPE is the data type of the argument (as a tree).
5720     This is null for libcalls where that information may
5721     not be available.
5722    CUM is a variable of type CUMULATIVE_ARGS which gives info about
5723     the preceding args and about the function being called.
5724    NAMED is nonzero if this argument is a named parameter
5725     (otherwise it is an extra parameter matching an ellipsis).  */
5726
5727 static rtx
5728 function_arg_32 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5729                  enum machine_mode orig_mode, tree type,
5730                  HOST_WIDE_INT bytes, HOST_WIDE_INT words)
5731 {
5732   static bool warnedsse, warnedmmx;
5733
5734   /* Avoid the AL settings for the Unix64 ABI.  */
5735   if (mode == VOIDmode)
5736     return constm1_rtx;
5737
5738   switch (mode)
5739     {
5740     default:
5741       break;
5742
5743     case BLKmode:
5744       if (bytes < 0)
5745         break;
5746       /* FALLTHRU */
5747     case DImode:
5748     case SImode:
5749     case HImode:
5750     case QImode:
5751       if (words <= cum->nregs)
5752         {
5753           int regno = cum->regno;
5754
5755           /* Fastcall allocates the first two DWORD (SImode) or
5756             smaller arguments to ECX and EDX if it isn't an
5757             aggregate type .  */
5758           if (cum->fastcall)
5759             {
5760               if (mode == BLKmode
5761                   || mode == DImode
5762                   || (type && AGGREGATE_TYPE_P (type)))
5763                 break;
5764
5765               /* ECX not EAX is the first allocated register.  */
5766               if (regno == AX_REG)
5767                 regno = CX_REG;
5768             }
5769           return gen_rtx_REG (mode, regno);
5770         }
5771       break;
5772
5773     case DFmode:
5774       if (cum->float_in_sse < 2)
5775         break;
5776     case SFmode:
5777       if (cum->float_in_sse < 1)
5778         break;
5779       /* FALLTHRU */
5780     case TImode:
5781       /* In 32bit, we pass TImode in xmm registers.  */
5782     case V16QImode:
5783     case V8HImode:
5784     case V4SImode:
5785     case V2DImode:
5786     case V4SFmode:
5787     case V2DFmode:
5788       if (!type || !AGGREGATE_TYPE_P (type))
5789         {
5790           if (!TARGET_SSE && !warnedsse && cum->warn_sse)
5791             {
5792               warnedsse = true;
5793               warning (0, "SSE vector argument without SSE enabled "
5794                        "changes the ABI");
5795             }
5796           if (cum->sse_nregs)
5797             return gen_reg_or_parallel (mode, orig_mode,
5798                                         cum->sse_regno + FIRST_SSE_REG);
5799         }
5800       break;
5801
5802     case OImode:
5803       /* OImode shouldn't be used directly.  */
5804       gcc_unreachable ();
5805
5806     case V8SFmode:
5807     case V8SImode:
5808     case V32QImode:
5809     case V16HImode:
5810     case V4DFmode:
5811     case V4DImode:
5812       if (!type || !AGGREGATE_TYPE_P (type))
5813         {
5814           if (cum->sse_nregs)
5815             return gen_reg_or_parallel (mode, orig_mode,
5816                                         cum->sse_regno + FIRST_SSE_REG);
5817         }
5818       break;
5819
5820     case V8QImode:
5821     case V4HImode:
5822     case V2SImode:
5823     case V2SFmode:
5824     case V1DImode:
5825       if (!type || !AGGREGATE_TYPE_P (type))
5826         {
5827           if (!TARGET_MMX && !warnedmmx && cum->warn_mmx)
5828             {
5829               warnedmmx = true;
5830               warning (0, "MMX vector argument without MMX enabled "
5831                        "changes the ABI");
5832             }
5833           if (cum->mmx_nregs)
5834             return gen_reg_or_parallel (mode, orig_mode,
5835                                         cum->mmx_regno + FIRST_MMX_REG);
5836         }
5837       break;
5838     }
5839
5840   return NULL_RTX;
5841 }
5842
5843 static rtx
5844 function_arg_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5845                  enum machine_mode orig_mode, tree type, int named)
5846 {
5847   /* Handle a hidden AL argument containing number of registers
5848      for varargs x86-64 functions.  */
5849   if (mode == VOIDmode)
5850     return GEN_INT (cum->maybe_vaarg
5851                     ? (cum->sse_nregs < 0
5852                        ? (cum->call_abi == DEFAULT_ABI
5853                           ? SSE_REGPARM_MAX
5854                           : (DEFAULT_ABI != SYSV_ABI ? X86_64_SSE_REGPARM_MAX
5855                                                      : X64_SSE_REGPARM_MAX))
5856                : cum->sse_regno)
5857                     : -1);
5858
5859   switch (mode)
5860     {
5861     default:
5862       break;
5863
5864     case V8SFmode:
5865     case V8SImode:
5866     case V32QImode:
5867     case V16HImode:
5868     case V4DFmode:
5869     case V4DImode:
5870       /* Unnamed 256bit vector mode parameters are passed on stack.  */
5871       if (!named)
5872         return NULL;
5873       break;
5874     }
5875
5876   return construct_container (mode, orig_mode, type, 0, cum->nregs,
5877                               cum->sse_nregs,
5878                               &x86_64_int_parameter_registers [cum->regno],
5879                               cum->sse_regno);
5880 }
5881
5882 static rtx
5883 function_arg_ms_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5884                     enum machine_mode orig_mode, int named,
5885                     HOST_WIDE_INT bytes)
5886 {
5887   unsigned int regno;
5888
5889   /* We need to add clobber for MS_ABI->SYSV ABI calls in expand_call.
5890      We use value of -2 to specify that current function call is MSABI.  */
5891   if (mode == VOIDmode)
5892     return GEN_INT (-2);
5893
5894   /* If we've run out of registers, it goes on the stack.  */
5895   if (cum->nregs == 0)
5896     return NULL_RTX;
5897
5898   regno = x86_64_ms_abi_int_parameter_registers[cum->regno];
5899
5900   /* Only floating point modes are passed in anything but integer regs.  */
5901   if (TARGET_SSE && (mode == SFmode || mode == DFmode))
5902     {
5903       if (named)
5904         regno = cum->regno + FIRST_SSE_REG;
5905       else
5906         {
5907           rtx t1, t2;
5908
5909           /* Unnamed floating parameters are passed in both the
5910              SSE and integer registers.  */
5911           t1 = gen_rtx_REG (mode, cum->regno + FIRST_SSE_REG);
5912           t2 = gen_rtx_REG (mode, regno);
5913           t1 = gen_rtx_EXPR_LIST (VOIDmode, t1, const0_rtx);
5914           t2 = gen_rtx_EXPR_LIST (VOIDmode, t2, const0_rtx);
5915           return gen_rtx_PARALLEL (mode, gen_rtvec (2, t1, t2));
5916         }
5917     }
5918   /* Handle aggregated types passed in register.  */
5919   if (orig_mode == BLKmode)
5920     {
5921       if (bytes > 0 && bytes <= 8)
5922         mode = (bytes > 4 ? DImode : SImode);
5923       if (mode == BLKmode)
5924         mode = DImode;
5925     }
5926
5927   return gen_reg_or_parallel (mode, orig_mode, regno);
5928 }
5929
5930 rtx
5931 function_arg (CUMULATIVE_ARGS *cum, enum machine_mode omode,
5932               tree type, int named)
5933 {
5934   enum machine_mode mode = omode;
5935   HOST_WIDE_INT bytes, words;
5936
5937   if (mode == BLKmode)
5938     bytes = int_size_in_bytes (type);
5939   else
5940     bytes = GET_MODE_SIZE (mode);
5941   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5942
5943   /* To simplify the code below, represent vector types with a vector mode
5944      even if MMX/SSE are not active.  */
5945   if (type && TREE_CODE (type) == VECTOR_TYPE)
5946     mode = type_natural_mode (type, cum);
5947
5948   if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
5949     return function_arg_ms_64 (cum, mode, omode, named, bytes);
5950   else if (TARGET_64BIT)
5951     return function_arg_64 (cum, mode, omode, type, named);
5952   else
5953     return function_arg_32 (cum, mode, omode, type, bytes, words);
5954 }
5955
5956 /* A C expression that indicates when an argument must be passed by
5957    reference.  If nonzero for an argument, a copy of that argument is
5958    made in memory and a pointer to the argument is passed instead of
5959    the argument itself.  The pointer is passed in whatever way is
5960    appropriate for passing a pointer to that type.  */
5961
5962 static bool
5963 ix86_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
5964                         enum machine_mode mode ATTRIBUTE_UNUSED,
5965                         const_tree type, bool named ATTRIBUTE_UNUSED)
5966 {
5967   /* See Windows x64 Software Convention.  */
5968   if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
5969     {
5970       int msize = (int) GET_MODE_SIZE (mode);
5971       if (type)
5972         {
5973           /* Arrays are passed by reference.  */
5974           if (TREE_CODE (type) == ARRAY_TYPE)
5975             return true;
5976
5977           if (AGGREGATE_TYPE_P (type))
5978             {
5979               /* Structs/unions of sizes other than 8, 16, 32, or 64 bits
5980                  are passed by reference.  */
5981               msize = int_size_in_bytes (type);
5982             }
5983         }
5984
5985       /* __m128 is passed by reference.  */
5986       switch (msize) {
5987       case 1: case 2: case 4: case 8:
5988         break;
5989       default:
5990         return true;
5991       }
5992     }
5993   else if (TARGET_64BIT && type && int_size_in_bytes (type) == -1)
5994     return 1;
5995
5996   return 0;
5997 }
5998
5999 /* Return true when TYPE should be 128bit aligned for 32bit argument passing
6000    ABI.  */
6001 static bool
6002 contains_aligned_value_p (const_tree type)
6003 {
6004   enum machine_mode mode = TYPE_MODE (type);
6005   if (((TARGET_SSE && SSE_REG_MODE_P (mode))
6006        || mode == TDmode
6007        || mode == TFmode
6008        || mode == TCmode)
6009       && (!TYPE_USER_ALIGN (type) || TYPE_ALIGN (type) > 128))
6010     return true;
6011   if (TYPE_ALIGN (type) < 128)
6012     return false;
6013
6014   if (AGGREGATE_TYPE_P (type))
6015     {
6016       /* Walk the aggregates recursively.  */
6017       switch (TREE_CODE (type))
6018         {
6019         case RECORD_TYPE:
6020         case UNION_TYPE:
6021         case QUAL_UNION_TYPE:
6022           {
6023             tree field;
6024
6025             /* Walk all the structure fields.  */
6026             for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
6027               {
6028                 if (TREE_CODE (field) == FIELD_DECL
6029                     && contains_aligned_value_p (TREE_TYPE (field)))
6030                   return true;
6031               }
6032             break;
6033           }
6034
6035         case ARRAY_TYPE:
6036           /* Just for use if some languages passes arrays by value.  */
6037           if (contains_aligned_value_p (TREE_TYPE (type)))
6038             return true;
6039           break;
6040
6041         default:
6042           gcc_unreachable ();
6043         }
6044     }
6045   return false;
6046 }
6047
6048 /* Gives the alignment boundary, in bits, of an argument with the
6049    specified mode and type.  */
6050
6051 int
6052 ix86_function_arg_boundary (enum machine_mode mode, const_tree type)
6053 {
6054   int align;
6055   if (type)
6056     {
6057       /* Since canonical type is used for call, we convert it to
6058          canonical type if needed.  */
6059       if (!TYPE_STRUCTURAL_EQUALITY_P (type))
6060         type = TYPE_CANONICAL (type);
6061       align = TYPE_ALIGN (type);
6062     }
6063   else
6064     align = GET_MODE_ALIGNMENT (mode);
6065   if (align < PARM_BOUNDARY)
6066     align = PARM_BOUNDARY;
6067   /* In 32bit, only _Decimal128 and __float128 are aligned to their
6068      natural boundaries.  */
6069   if (!TARGET_64BIT && mode != TDmode && mode != TFmode)
6070     {
6071       /* i386 ABI defines all arguments to be 4 byte aligned.  We have to
6072          make an exception for SSE modes since these require 128bit
6073          alignment.
6074
6075          The handling here differs from field_alignment.  ICC aligns MMX
6076          arguments to 4 byte boundaries, while structure fields are aligned
6077          to 8 byte boundaries.  */
6078       if (!type)
6079         {
6080           if (!(TARGET_SSE && SSE_REG_MODE_P (mode)))
6081             align = PARM_BOUNDARY;
6082         }
6083       else
6084         {
6085           if (!contains_aligned_value_p (type))
6086             align = PARM_BOUNDARY;
6087         }
6088     }
6089   if (align > BIGGEST_ALIGNMENT)
6090     align = BIGGEST_ALIGNMENT;
6091   return align;
6092 }
6093
6094 /* Return true if N is a possible register number of function value.  */
6095
6096 bool
6097 ix86_function_value_regno_p (int regno)
6098 {
6099   switch (regno)
6100     {
6101     case 0:
6102       return true;
6103
6104     case FIRST_FLOAT_REG:
6105       /* TODO: The function should depend on current function ABI but
6106        builtins.c would need updating then. Therefore we use the
6107        default ABI.  */
6108       if (TARGET_64BIT && DEFAULT_ABI == MS_ABI)
6109         return false;
6110       return TARGET_FLOAT_RETURNS_IN_80387;
6111
6112     case FIRST_SSE_REG:
6113       return TARGET_SSE;
6114
6115     case FIRST_MMX_REG:
6116       if (TARGET_MACHO || TARGET_64BIT)
6117         return false;
6118       return TARGET_MMX;
6119     }
6120
6121   return false;
6122 }
6123
6124 /* Define how to find the value returned by a function.
6125    VALTYPE is the data type of the value (as a tree).
6126    If the precise function being called is known, FUNC is its FUNCTION_DECL;
6127    otherwise, FUNC is 0.  */
6128
6129 static rtx
6130 function_value_32 (enum machine_mode orig_mode, enum machine_mode mode,
6131                    const_tree fntype, const_tree fn)
6132 {
6133   unsigned int regno;
6134
6135   /* 8-byte vector modes in %mm0. See ix86_return_in_memory for where
6136      we normally prevent this case when mmx is not available.  However
6137      some ABIs may require the result to be returned like DImode.  */
6138   if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
6139     regno = TARGET_MMX ? FIRST_MMX_REG : 0;
6140
6141   /* 16-byte vector modes in %xmm0.  See ix86_return_in_memory for where
6142      we prevent this case when sse is not available.  However some ABIs
6143      may require the result to be returned like integer TImode.  */
6144   else if (mode == TImode
6145            || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
6146     regno = TARGET_SSE ? FIRST_SSE_REG : 0;
6147
6148   /* 32-byte vector modes in %ymm0.   */
6149   else if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 32)
6150     regno = TARGET_AVX ? FIRST_SSE_REG : 0;
6151
6152   /* Floating point return values in %st(0) (unless -mno-fp-ret-in-387).  */
6153   else if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387)
6154     regno = FIRST_FLOAT_REG;
6155   else
6156     /* Most things go in %eax.  */
6157     regno = AX_REG;
6158
6159   /* Override FP return register with %xmm0 for local functions when
6160      SSE math is enabled or for functions with sseregparm attribute.  */
6161   if ((fn || fntype) && (mode == SFmode || mode == DFmode))
6162     {
6163       int sse_level = ix86_function_sseregparm (fntype, fn, false);
6164       if ((sse_level >= 1 && mode == SFmode)
6165           || (sse_level == 2 && mode == DFmode))
6166         regno = FIRST_SSE_REG;
6167     }
6168
6169   /* OImode shouldn't be used directly.  */
6170   gcc_assert (mode != OImode);
6171
6172   return gen_rtx_REG (orig_mode, regno);
6173 }
6174
6175 static rtx
6176 function_value_64 (enum machine_mode orig_mode, enum machine_mode mode,
6177                    const_tree valtype)
6178 {
6179   rtx ret;
6180
6181   /* Handle libcalls, which don't provide a type node.  */
6182   if (valtype == NULL)
6183     {
6184       switch (mode)
6185         {
6186         case SFmode:
6187         case SCmode:
6188         case DFmode:
6189         case DCmode:
6190         case TFmode:
6191         case SDmode:
6192         case DDmode:
6193         case TDmode:
6194           return gen_rtx_REG (mode, FIRST_SSE_REG);
6195         case XFmode:
6196         case XCmode:
6197           return gen_rtx_REG (mode, FIRST_FLOAT_REG);
6198         case TCmode:
6199           return NULL;
6200         default:
6201           return gen_rtx_REG (mode, AX_REG);
6202         }
6203     }
6204
6205   ret = construct_container (mode, orig_mode, valtype, 1,
6206                              X86_64_REGPARM_MAX, X86_64_SSE_REGPARM_MAX,
6207                              x86_64_int_return_registers, 0);
6208
6209   /* For zero sized structures, construct_container returns NULL, but we
6210      need to keep rest of compiler happy by returning meaningful value.  */
6211   if (!ret)
6212     ret = gen_rtx_REG (orig_mode, AX_REG);
6213
6214   return ret;
6215 }
6216
6217 static rtx
6218 function_value_ms_64 (enum machine_mode orig_mode, enum machine_mode mode)
6219 {
6220   unsigned int regno = AX_REG;
6221
6222   if (TARGET_SSE)
6223     {
6224       switch (GET_MODE_SIZE (mode))
6225         {
6226         case 16:
6227           if((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
6228              && !COMPLEX_MODE_P (mode))
6229             regno = FIRST_SSE_REG;
6230           break;
6231         case 8:
6232         case 4:
6233           if (mode == SFmode || mode == DFmode)
6234             regno = FIRST_SSE_REG;
6235           break;
6236         default:
6237           break;
6238         }
6239     }
6240   return gen_rtx_REG (orig_mode, regno);
6241 }
6242
6243 static rtx
6244 ix86_function_value_1 (const_tree valtype, const_tree fntype_or_decl,
6245                        enum machine_mode orig_mode, enum machine_mode mode)
6246 {
6247   const_tree fn, fntype;
6248
6249   fn = NULL_TREE;
6250   if (fntype_or_decl && DECL_P (fntype_or_decl))
6251     fn = fntype_or_decl;
6252   fntype = fn ? TREE_TYPE (fn) : fntype_or_decl;
6253
6254   if (TARGET_64BIT && ix86_function_type_abi (fntype) == MS_ABI)
6255     return function_value_ms_64 (orig_mode, mode);
6256   else if (TARGET_64BIT)
6257     return function_value_64 (orig_mode, mode, valtype);
6258   else
6259     return function_value_32 (orig_mode, mode, fntype, fn);
6260 }
6261
6262 static rtx
6263 ix86_function_value (const_tree valtype, const_tree fntype_or_decl,
6264                      bool outgoing ATTRIBUTE_UNUSED)
6265 {
6266   enum machine_mode mode, orig_mode;
6267
6268   orig_mode = TYPE_MODE (valtype);
6269   mode = type_natural_mode (valtype, NULL);
6270   return ix86_function_value_1 (valtype, fntype_or_decl, orig_mode, mode);
6271 }
6272
6273 rtx
6274 ix86_libcall_value (enum machine_mode mode)
6275 {
6276   return ix86_function_value_1 (NULL, NULL, mode, mode);
6277 }
6278
6279 /* Return true iff type is returned in memory.  */
6280
6281 static int ATTRIBUTE_UNUSED
6282 return_in_memory_32 (const_tree type, enum machine_mode mode)
6283 {
6284   HOST_WIDE_INT size;
6285
6286   if (mode == BLKmode)
6287     return 1;
6288
6289   size = int_size_in_bytes (type);
6290
6291   if (MS_AGGREGATE_RETURN && AGGREGATE_TYPE_P (type) && size <= 8)
6292     return 0;
6293
6294   if (VECTOR_MODE_P (mode) || mode == TImode)
6295     {
6296       /* User-created vectors small enough to fit in EAX.  */
6297       if (size < 8)
6298         return 0;
6299
6300       /* MMX/3dNow values are returned in MM0,
6301          except when it doesn't exits.  */
6302       if (size == 8)
6303         return (TARGET_MMX ? 0 : 1);
6304
6305       /* SSE values are returned in XMM0, except when it doesn't exist.  */
6306       if (size == 16)
6307         return (TARGET_SSE ? 0 : 1);
6308
6309       /* AVX values are returned in YMM0, except when it doesn't exist.  */
6310       if (size == 32)
6311         return TARGET_AVX ? 0 : 1;
6312     }
6313
6314   if (mode == XFmode)
6315     return 0;
6316
6317   if (size > 12)
6318     return 1;
6319
6320   /* OImode shouldn't be used directly.  */
6321   gcc_assert (mode != OImode);
6322
6323   return 0;
6324 }
6325
6326 static int ATTRIBUTE_UNUSED
6327 return_in_memory_64 (const_tree type, enum machine_mode mode)
6328 {
6329   int needed_intregs, needed_sseregs;
6330   return !examine_argument (mode, type, 1, &needed_intregs, &needed_sseregs);
6331 }
6332
6333 static int ATTRIBUTE_UNUSED
6334 return_in_memory_ms_64 (const_tree type, enum machine_mode mode)
6335 {
6336   HOST_WIDE_INT size = int_size_in_bytes (type);
6337
6338   /* __m128 is returned in xmm0.  */
6339   if ((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
6340       && !COMPLEX_MODE_P (mode) && (GET_MODE_SIZE (mode) == 16 || size == 16))
6341     return 0;
6342
6343   /* Otherwise, the size must be exactly in [1248]. */
6344   return (size != 1 && size != 2 && size != 4 && size != 8);
6345 }
6346
6347 static bool
6348 ix86_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
6349 {
6350 #ifdef SUBTARGET_RETURN_IN_MEMORY
6351   return SUBTARGET_RETURN_IN_MEMORY (type, fntype);
6352 #else
6353   const enum machine_mode mode = type_natural_mode (type, NULL);
6354  
6355   if (TARGET_64BIT)
6356     {
6357       if (ix86_function_type_abi (fntype) == MS_ABI)
6358         return return_in_memory_ms_64 (type, mode);
6359       else
6360         return return_in_memory_64 (type, mode);
6361     }
6362   else
6363     return return_in_memory_32 (type, mode);
6364 #endif
6365 }
6366
6367 /* Return false iff TYPE is returned in memory.  This version is used
6368    on Solaris 2.  It is similar to the generic ix86_return_in_memory,
6369    but differs notably in that when MMX is available, 8-byte vectors
6370    are returned in memory, rather than in MMX registers.  */
6371
6372 bool
6373 ix86_solaris_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
6374 {
6375   int size;
6376   enum machine_mode mode = type_natural_mode (type, NULL);
6377
6378   if (TARGET_64BIT)
6379     return return_in_memory_64 (type, mode);
6380
6381   if (mode == BLKmode)
6382     return 1;
6383
6384   size = int_size_in_bytes (type);
6385
6386   if (VECTOR_MODE_P (mode))
6387     {
6388       /* Return in memory only if MMX registers *are* available.  This
6389          seems backwards, but it is consistent with the existing
6390          Solaris x86 ABI.  */
6391       if (size == 8)
6392         return TARGET_MMX;
6393       if (size == 16)
6394         return !TARGET_SSE;
6395     }
6396   else if (mode == TImode)
6397     return !TARGET_SSE;
6398   else if (mode == XFmode)
6399     return 0;
6400
6401   return size > 12;
6402 }
6403
6404 /* When returning SSE vector types, we have a choice of either
6405      (1) being abi incompatible with a -march switch, or
6406      (2) generating an error.
6407    Given no good solution, I think the safest thing is one warning.
6408    The user won't be able to use -Werror, but....
6409
6410    Choose the STRUCT_VALUE_RTX hook because that's (at present) only
6411    called in response to actually generating a caller or callee that
6412    uses such a type.  As opposed to TARGET_RETURN_IN_MEMORY, which is called
6413    via aggregate_value_p for general type probing from tree-ssa.  */
6414
6415 static rtx
6416 ix86_struct_value_rtx (tree type, int incoming ATTRIBUTE_UNUSED)
6417 {
6418   static bool warnedsse, warnedmmx;
6419
6420   if (!TARGET_64BIT && type)
6421     {
6422       /* Look at the return type of the function, not the function type.  */
6423       enum machine_mode mode = TYPE_MODE (TREE_TYPE (type));
6424
6425       if (!TARGET_SSE && !warnedsse)
6426         {
6427           if (mode == TImode
6428               || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
6429             {
6430               warnedsse = true;
6431               warning (0, "SSE vector return without SSE enabled "
6432                        "changes the ABI");
6433             }
6434         }
6435
6436       if (!TARGET_MMX && !warnedmmx)
6437         {
6438           if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
6439             {
6440               warnedmmx = true;
6441               warning (0, "MMX vector return without MMX enabled "
6442                        "changes the ABI");
6443             }
6444         }
6445     }
6446
6447   return NULL;
6448 }
6449
6450 \f
6451 /* Create the va_list data type.  */
6452
6453 /* Returns the calling convention specific va_list date type.
6454    The argument ABI can be DEFAULT_ABI, MS_ABI, or SYSV_ABI.  */
6455
6456 static tree
6457 ix86_build_builtin_va_list_abi (enum calling_abi abi)
6458 {
6459   tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
6460
6461   /* For i386 we use plain pointer to argument area.  */
6462   if (!TARGET_64BIT || abi == MS_ABI)
6463     return build_pointer_type (char_type_node);
6464
6465   record = (*lang_hooks.types.make_type) (RECORD_TYPE);
6466   type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
6467
6468   f_gpr = build_decl (FIELD_DECL, get_identifier ("gp_offset"),
6469                       unsigned_type_node);
6470   f_fpr = build_decl (FIELD_DECL, get_identifier ("fp_offset"),
6471                       unsigned_type_node);
6472   f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
6473                       ptr_type_node);
6474   f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
6475                       ptr_type_node);
6476
6477   va_list_gpr_counter_field = f_gpr;
6478   va_list_fpr_counter_field = f_fpr;
6479
6480   DECL_FIELD_CONTEXT (f_gpr) = record;
6481   DECL_FIELD_CONTEXT (f_fpr) = record;
6482   DECL_FIELD_CONTEXT (f_ovf) = record;
6483   DECL_FIELD_CONTEXT (f_sav) = record;
6484
6485   TREE_CHAIN (record) = type_decl;
6486   TYPE_NAME (record) = type_decl;
6487   TYPE_FIELDS (record) = f_gpr;
6488   TREE_CHAIN (f_gpr) = f_fpr;
6489   TREE_CHAIN (f_fpr) = f_ovf;
6490   TREE_CHAIN (f_ovf) = f_sav;
6491
6492   layout_type (record);
6493
6494   /* The correct type is an array type of one element.  */
6495   return build_array_type (record, build_index_type (size_zero_node));
6496 }
6497
6498 /* Setup the builtin va_list data type and for 64-bit the additional
6499    calling convention specific va_list data types.  */
6500
6501 static tree
6502 ix86_build_builtin_va_list (void)
6503 {
6504   tree ret = ix86_build_builtin_va_list_abi (DEFAULT_ABI);
6505
6506   /* Initialize abi specific va_list builtin types.  */
6507   if (TARGET_64BIT)
6508     {
6509       tree t;
6510       if (DEFAULT_ABI == MS_ABI)
6511         {
6512           t = ix86_build_builtin_va_list_abi (SYSV_ABI);
6513           if (TREE_CODE (t) != RECORD_TYPE)
6514             t = build_variant_type_copy (t);
6515           sysv_va_list_type_node = t;
6516         }
6517       else
6518         {
6519           t = ret;
6520           if (TREE_CODE (t) != RECORD_TYPE)
6521             t = build_variant_type_copy (t);
6522           sysv_va_list_type_node = t;
6523         }
6524       if (DEFAULT_ABI != MS_ABI)
6525         {
6526           t = ix86_build_builtin_va_list_abi (MS_ABI);
6527           if (TREE_CODE (t) != RECORD_TYPE)
6528             t = build_variant_type_copy (t);
6529           ms_va_list_type_node = t;
6530         }
6531       else
6532         {
6533           t = ret;
6534           if (TREE_CODE (t) != RECORD_TYPE)
6535             t = build_variant_type_copy (t);
6536           ms_va_list_type_node = t;
6537         }
6538     }
6539
6540   return ret;
6541 }
6542
6543 /* Worker function for TARGET_SETUP_INCOMING_VARARGS.  */
6544
6545 static void
6546 setup_incoming_varargs_64 (CUMULATIVE_ARGS *cum)
6547 {
6548   rtx save_area, mem;
6549   rtx label;
6550   rtx label_ref;
6551   rtx tmp_reg;
6552   rtx nsse_reg;
6553   alias_set_type set;
6554   int i;
6555   int regparm = ix86_regparm;
6556
6557   if (cum->call_abi != DEFAULT_ABI)
6558     regparm = DEFAULT_ABI != SYSV_ABI ? X86_64_REGPARM_MAX : X64_REGPARM_MAX;
6559
6560   /* GPR size of varargs save area.  */
6561   if (cfun->va_list_gpr_size)
6562     ix86_varargs_gpr_size = X86_64_REGPARM_MAX * UNITS_PER_WORD;
6563   else
6564     ix86_varargs_gpr_size = 0;
6565
6566   /* FPR size of varargs save area.  We don't need it if we don't pass
6567      anything in SSE registers.  */
6568   if (cum->sse_nregs && cfun->va_list_fpr_size)
6569     ix86_varargs_fpr_size = X86_64_SSE_REGPARM_MAX * 16;
6570   else
6571     ix86_varargs_fpr_size = 0;
6572
6573   if (! ix86_varargs_gpr_size && ! ix86_varargs_fpr_size)
6574     return;
6575
6576   save_area = frame_pointer_rtx;
6577   set = get_varargs_alias_set ();
6578
6579   for (i = cum->regno;
6580        i < regparm
6581        && i < cum->regno + cfun->va_list_gpr_size / UNITS_PER_WORD;
6582        i++)
6583     {
6584       mem = gen_rtx_MEM (Pmode,
6585                          plus_constant (save_area, i * UNITS_PER_WORD));
6586       MEM_NOTRAP_P (mem) = 1;
6587       set_mem_alias_set (mem, set);
6588       emit_move_insn (mem, gen_rtx_REG (Pmode,
6589                                         x86_64_int_parameter_registers[i]));
6590     }
6591
6592   if (ix86_varargs_fpr_size)
6593     {
6594       /* Stack must be aligned to 16byte for FP register save area.  */
6595       if (crtl->stack_alignment_needed < 128)
6596         crtl->stack_alignment_needed = 128;
6597
6598       /* Now emit code to save SSE registers.  The AX parameter contains number
6599          of SSE parameter registers used to call this function.  We use
6600          sse_prologue_save insn template that produces computed jump across
6601          SSE saves.  We need some preparation work to get this working.  */
6602
6603       label = gen_label_rtx ();
6604       label_ref = gen_rtx_LABEL_REF (Pmode, label);
6605
6606       /* Compute address to jump to :
6607          label - eax*4 + nnamed_sse_arguments*4 Or
6608          label - eax*5 + nnamed_sse_arguments*5 for AVX.  */
6609       tmp_reg = gen_reg_rtx (Pmode);
6610       nsse_reg = gen_reg_rtx (Pmode);
6611       emit_insn (gen_zero_extendqidi2 (nsse_reg, gen_rtx_REG (QImode, AX_REG)));
6612       emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6613                               gen_rtx_MULT (Pmode, nsse_reg,
6614                                             GEN_INT (4))));
6615
6616       /* vmovaps is one byte longer than movaps.  */
6617       if (TARGET_AVX)
6618         emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6619                                 gen_rtx_PLUS (Pmode, tmp_reg,
6620                                               nsse_reg)));
6621
6622       if (cum->sse_regno)
6623         emit_move_insn
6624           (nsse_reg,
6625            gen_rtx_CONST (DImode,
6626                           gen_rtx_PLUS (DImode,
6627                                         label_ref,
6628                                         GEN_INT (cum->sse_regno
6629                                                  * (TARGET_AVX ? 5 : 4)))));
6630       else
6631         emit_move_insn (nsse_reg, label_ref);
6632       emit_insn (gen_subdi3 (nsse_reg, nsse_reg, tmp_reg));
6633
6634       /* Compute address of memory block we save into.  We always use pointer
6635          pointing 127 bytes after first byte to store - this is needed to keep
6636          instruction size limited by 4 bytes (5 bytes for AVX) with one
6637          byte displacement.  */
6638       tmp_reg = gen_reg_rtx (Pmode);
6639       emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6640                               plus_constant (save_area,
6641                                              ix86_varargs_gpr_size + 127)));
6642       mem = gen_rtx_MEM (BLKmode, plus_constant (tmp_reg, -127));
6643       MEM_NOTRAP_P (mem) = 1;
6644       set_mem_alias_set (mem, set);
6645       set_mem_align (mem, BITS_PER_WORD);
6646
6647       /* And finally do the dirty job!  */
6648       emit_insn (gen_sse_prologue_save (mem, nsse_reg,
6649                                         GEN_INT (cum->sse_regno), label));
6650     }
6651 }
6652
6653 static void
6654 setup_incoming_varargs_ms_64 (CUMULATIVE_ARGS *cum)
6655 {
6656   alias_set_type set = get_varargs_alias_set ();
6657   int i;
6658
6659   for (i = cum->regno; i < X64_REGPARM_MAX; i++)
6660     {
6661       rtx reg, mem;
6662
6663       mem = gen_rtx_MEM (Pmode,
6664                          plus_constant (virtual_incoming_args_rtx,
6665                                         i * UNITS_PER_WORD));
6666       MEM_NOTRAP_P (mem) = 1;
6667       set_mem_alias_set (mem, set);
6668
6669       reg = gen_rtx_REG (Pmode, x86_64_ms_abi_int_parameter_registers[i]);
6670       emit_move_insn (mem, reg);
6671     }
6672 }
6673
6674 static void
6675 ix86_setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
6676                              tree type, int *pretend_size ATTRIBUTE_UNUSED,
6677                              int no_rtl)
6678 {
6679   CUMULATIVE_ARGS next_cum;
6680   tree fntype;
6681
6682   /* This argument doesn't appear to be used anymore.  Which is good,
6683      because the old code here didn't suppress rtl generation.  */
6684   gcc_assert (!no_rtl);
6685
6686   if (!TARGET_64BIT)
6687     return;
6688
6689   fntype = TREE_TYPE (current_function_decl);
6690
6691   /* For varargs, we do not want to skip the dummy va_dcl argument.
6692      For stdargs, we do want to skip the last named argument.  */
6693   next_cum = *cum;
6694   if (stdarg_p (fntype))
6695     function_arg_advance (&next_cum, mode, type, 1);
6696
6697   if (cum->call_abi == MS_ABI)
6698     setup_incoming_varargs_ms_64 (&next_cum);
6699   else
6700     setup_incoming_varargs_64 (&next_cum);
6701 }
6702
6703 /* Checks if TYPE is of kind va_list char *.  */
6704
6705 static bool
6706 is_va_list_char_pointer (tree type)
6707 {
6708   tree canonic;
6709
6710   /* For 32-bit it is always true.  */
6711   if (!TARGET_64BIT)
6712     return true;
6713   canonic = ix86_canonical_va_list_type (type);
6714   return (canonic == ms_va_list_type_node
6715           || (DEFAULT_ABI == MS_ABI && canonic == va_list_type_node));
6716 }
6717
6718 /* Implement va_start.  */
6719
6720 static void
6721 ix86_va_start (tree valist, rtx nextarg)
6722 {
6723   HOST_WIDE_INT words, n_gpr, n_fpr;
6724   tree f_gpr, f_fpr, f_ovf, f_sav;
6725   tree gpr, fpr, ovf, sav, t;
6726   tree type;
6727
6728   /* Only 64bit target needs something special.  */
6729   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
6730     {
6731       std_expand_builtin_va_start (valist, nextarg);
6732       return;
6733     }
6734
6735   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
6736   f_fpr = TREE_CHAIN (f_gpr);
6737   f_ovf = TREE_CHAIN (f_fpr);
6738   f_sav = TREE_CHAIN (f_ovf);
6739
6740   valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
6741   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
6742   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
6743   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
6744   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
6745
6746   /* Count number of gp and fp argument registers used.  */
6747   words = crtl->args.info.words;
6748   n_gpr = crtl->args.info.regno;
6749   n_fpr = crtl->args.info.sse_regno;
6750
6751   if (cfun->va_list_gpr_size)
6752     {
6753       type = TREE_TYPE (gpr);
6754       t = build2 (MODIFY_EXPR, type,
6755                   gpr, build_int_cst (type, n_gpr * 8));
6756       TREE_SIDE_EFFECTS (t) = 1;
6757       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6758     }
6759
6760   if (TARGET_SSE && cfun->va_list_fpr_size)
6761     {
6762       type = TREE_TYPE (fpr);
6763       t = build2 (MODIFY_EXPR, type, fpr,
6764                   build_int_cst (type, n_fpr * 16 + 8*X86_64_REGPARM_MAX));
6765       TREE_SIDE_EFFECTS (t) = 1;
6766       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6767     }
6768
6769   /* Find the overflow area.  */
6770   type = TREE_TYPE (ovf);
6771   t = make_tree (type, crtl->args.internal_arg_pointer);
6772   if (words != 0)
6773     t = build2 (POINTER_PLUS_EXPR, type, t,
6774                 size_int (words * UNITS_PER_WORD));
6775   t = build2 (MODIFY_EXPR, type, ovf, t);
6776   TREE_SIDE_EFFECTS (t) = 1;
6777   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6778
6779   if (ix86_varargs_gpr_size || ix86_varargs_fpr_size)
6780     {
6781       /* Find the register save area.
6782          Prologue of the function save it right above stack frame.  */
6783       type = TREE_TYPE (sav);
6784       t = make_tree (type, frame_pointer_rtx);
6785       if (!ix86_varargs_gpr_size)
6786         t = build2 (POINTER_PLUS_EXPR, type, t,
6787                     size_int (-8 * X86_64_REGPARM_MAX));
6788       t = build2 (MODIFY_EXPR, type, sav, t);
6789       TREE_SIDE_EFFECTS (t) = 1;
6790       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6791     }
6792 }
6793
6794 /* Implement va_arg.  */
6795
6796 static tree
6797 ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
6798                       gimple_seq *post_p)
6799 {
6800   static const int intreg[6] = { 0, 1, 2, 3, 4, 5 };
6801   tree f_gpr, f_fpr, f_ovf, f_sav;
6802   tree gpr, fpr, ovf, sav, t;
6803   int size, rsize;
6804   tree lab_false, lab_over = NULL_TREE;
6805   tree addr, t2;
6806   rtx container;
6807   int indirect_p = 0;
6808   tree ptrtype;
6809   enum machine_mode nat_mode;
6810   int arg_boundary;
6811
6812   /* Only 64bit target needs something special.  */
6813   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
6814     return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
6815
6816   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
6817   f_fpr = TREE_CHAIN (f_gpr);
6818   f_ovf = TREE_CHAIN (f_fpr);
6819   f_sav = TREE_CHAIN (f_ovf);
6820
6821   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr),
6822                 build_va_arg_indirect_ref (valist), f_gpr, NULL_TREE);
6823   valist = build_va_arg_indirect_ref (valist);
6824   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
6825   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
6826   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
6827
6828   indirect_p = pass_by_reference (NULL, TYPE_MODE (type), type, false);
6829   if (indirect_p)
6830     type = build_pointer_type (type);
6831   size = int_size_in_bytes (type);
6832   rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
6833
6834   nat_mode = type_natural_mode (type, NULL);
6835   switch (nat_mode)
6836     {
6837     case V8SFmode:
6838     case V8SImode:
6839     case V32QImode:
6840     case V16HImode:
6841     case V4DFmode:
6842     case V4DImode:
6843       /* Unnamed 256bit vector mode parameters are passed on stack.  */
6844       if (ix86_cfun_abi () == SYSV_ABI)
6845         {
6846           container = NULL;
6847           break;
6848         }
6849
6850     default:
6851       container = construct_container (nat_mode, TYPE_MODE (type),
6852                                        type, 0, X86_64_REGPARM_MAX,
6853                                        X86_64_SSE_REGPARM_MAX, intreg,
6854                                        0);
6855       break;
6856     }
6857
6858   /* Pull the value out of the saved registers.  */
6859
6860   addr = create_tmp_var (ptr_type_node, "addr");
6861   DECL_POINTER_ALIAS_SET (addr) = get_varargs_alias_set ();
6862
6863   if (container)
6864     {
6865       int needed_intregs, needed_sseregs;
6866       bool need_temp;
6867       tree int_addr, sse_addr;
6868
6869       lab_false = create_artificial_label ();
6870       lab_over = create_artificial_label ();
6871
6872       examine_argument (nat_mode, type, 0, &needed_intregs, &needed_sseregs);
6873
6874       need_temp = (!REG_P (container)
6875                    && ((needed_intregs && TYPE_ALIGN (type) > 64)
6876                        || TYPE_ALIGN (type) > 128));
6877
6878       /* In case we are passing structure, verify that it is consecutive block
6879          on the register save area.  If not we need to do moves.  */
6880       if (!need_temp && !REG_P (container))
6881         {
6882           /* Verify that all registers are strictly consecutive  */
6883           if (SSE_REGNO_P (REGNO (XEXP (XVECEXP (container, 0, 0), 0))))
6884             {
6885               int i;
6886
6887               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
6888                 {
6889                   rtx slot = XVECEXP (container, 0, i);
6890                   if (REGNO (XEXP (slot, 0)) != FIRST_SSE_REG + (unsigned int) i
6891                       || INTVAL (XEXP (slot, 1)) != i * 16)
6892                     need_temp = 1;
6893                 }
6894             }
6895           else
6896             {
6897               int i;
6898
6899               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
6900                 {
6901                   rtx slot = XVECEXP (container, 0, i);
6902                   if (REGNO (XEXP (slot, 0)) != (unsigned int) i
6903                       || INTVAL (XEXP (slot, 1)) != i * 8)
6904                     need_temp = 1;
6905                 }
6906             }
6907         }
6908       if (!need_temp)
6909         {
6910           int_addr = addr;
6911           sse_addr = addr;
6912         }
6913       else
6914         {
6915           int_addr = create_tmp_var (ptr_type_node, "int_addr");
6916           DECL_POINTER_ALIAS_SET (int_addr) = get_varargs_alias_set ();
6917           sse_addr = create_tmp_var (ptr_type_node, "sse_addr");
6918           DECL_POINTER_ALIAS_SET (sse_addr) = get_varargs_alias_set ();
6919         }
6920
6921       /* First ensure that we fit completely in registers.  */
6922       if (needed_intregs)
6923         {
6924           t = build_int_cst (TREE_TYPE (gpr),
6925                              (X86_64_REGPARM_MAX - needed_intregs + 1) * 8);
6926           t = build2 (GE_EXPR, boolean_type_node, gpr, t);
6927           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
6928           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
6929           gimplify_and_add (t, pre_p);
6930         }
6931       if (needed_sseregs)
6932         {
6933           t = build_int_cst (TREE_TYPE (fpr),
6934                              (X86_64_SSE_REGPARM_MAX - needed_sseregs + 1) * 16
6935                              + X86_64_REGPARM_MAX * 8);
6936           t = build2 (GE_EXPR, boolean_type_node, fpr, t);
6937           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
6938           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
6939           gimplify_and_add (t, pre_p);
6940         }
6941
6942       /* Compute index to start of area used for integer regs.  */
6943       if (needed_intregs)
6944         {
6945           /* int_addr = gpr + sav; */
6946           t = fold_convert (sizetype, gpr);
6947           t = build2 (POINTER_PLUS_EXPR, ptr_type_node, sav, t);
6948           gimplify_assign (int_addr, t, pre_p);
6949         }
6950       if (needed_sseregs)
6951         {
6952           /* sse_addr = fpr + sav; */
6953           t = fold_convert (sizetype, fpr);
6954           t = build2 (POINTER_PLUS_EXPR, ptr_type_node, sav, t);
6955           gimplify_assign (sse_addr, t, pre_p);
6956         }
6957       if (need_temp)
6958         {
6959           int i;
6960           tree temp = create_tmp_var (type, "va_arg_tmp");
6961
6962           /* addr = &temp; */
6963           t = build1 (ADDR_EXPR, build_pointer_type (type), temp);
6964           gimplify_assign (addr, t, pre_p);
6965
6966           for (i = 0; i < XVECLEN (container, 0); i++)
6967             {
6968               rtx slot = XVECEXP (container, 0, i);
6969               rtx reg = XEXP (slot, 0);
6970               enum machine_mode mode = GET_MODE (reg);
6971               tree piece_type = lang_hooks.types.type_for_mode (mode, 1);
6972               tree addr_type = build_pointer_type (piece_type);
6973               tree daddr_type = build_pointer_type_for_mode (piece_type,
6974                                                              ptr_mode, true);
6975               tree src_addr, src;
6976               int src_offset;
6977               tree dest_addr, dest;
6978
6979               if (SSE_REGNO_P (REGNO (reg)))
6980                 {
6981                   src_addr = sse_addr;
6982                   src_offset = (REGNO (reg) - FIRST_SSE_REG) * 16;
6983                 }
6984               else
6985                 {
6986                   src_addr = int_addr;
6987                   src_offset = REGNO (reg) * 8;
6988                 }
6989               src_addr = fold_convert (addr_type, src_addr);
6990               src_addr = fold_build2 (POINTER_PLUS_EXPR, addr_type, src_addr,
6991                                       size_int (src_offset));
6992               src = build_va_arg_indirect_ref (src_addr);
6993
6994               dest_addr = fold_convert (daddr_type, addr);
6995               dest_addr = fold_build2 (POINTER_PLUS_EXPR, daddr_type, dest_addr,
6996                                        size_int (INTVAL (XEXP (slot, 1))));
6997               dest = build_va_arg_indirect_ref (dest_addr);
6998
6999               gimplify_assign (dest, src, pre_p);
7000             }
7001         }
7002
7003       if (needed_intregs)
7004         {
7005           t = build2 (PLUS_EXPR, TREE_TYPE (gpr), gpr,
7006                       build_int_cst (TREE_TYPE (gpr), needed_intregs * 8));
7007           gimplify_assign (gpr, t, pre_p);
7008         }
7009
7010       if (needed_sseregs)
7011         {
7012           t = build2 (PLUS_EXPR, TREE_TYPE (fpr), fpr,
7013                       build_int_cst (TREE_TYPE (fpr), needed_sseregs * 16));
7014           gimplify_assign (fpr, t, pre_p);
7015         }
7016
7017       gimple_seq_add_stmt (pre_p, gimple_build_goto (lab_over));
7018
7019       gimple_seq_add_stmt (pre_p, gimple_build_label (lab_false));
7020     }
7021
7022   /* ... otherwise out of the overflow area.  */
7023
7024   /* When we align parameter on stack for caller, if the parameter
7025      alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be
7026      aligned at MAX_SUPPORTED_STACK_ALIGNMENT.  We will match callee
7027      here with caller.  */
7028   arg_boundary = FUNCTION_ARG_BOUNDARY (VOIDmode, type);
7029   if ((unsigned int) arg_boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
7030     arg_boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
7031
7032   /* Care for on-stack alignment if needed.  */
7033   if (arg_boundary <= 64
7034       || integer_zerop (TYPE_SIZE (type)))
7035     t = ovf;
7036  else
7037     {
7038       HOST_WIDE_INT align = arg_boundary / 8;
7039       t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (ovf), ovf,
7040                   size_int (align - 1));
7041       t = fold_convert (sizetype, t);
7042       t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
7043                   size_int (-align));
7044       t = fold_convert (TREE_TYPE (ovf), t);
7045     }
7046   gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
7047   gimplify_assign (addr, t, pre_p);
7048
7049   t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (t), t,
7050               size_int (rsize * UNITS_PER_WORD));
7051   gimplify_assign (unshare_expr (ovf), t, pre_p);
7052
7053   if (container)
7054     gimple_seq_add_stmt (pre_p, gimple_build_label (lab_over));
7055
7056   ptrtype = build_pointer_type (type);
7057   addr = fold_convert (ptrtype, addr);
7058
7059   if (indirect_p)
7060     addr = build_va_arg_indirect_ref (addr);
7061   return build_va_arg_indirect_ref (addr);
7062 }
7063 \f
7064 /* Return nonzero if OPNUM's MEM should be matched
7065    in movabs* patterns.  */
7066
7067 int
7068 ix86_check_movabs (rtx insn, int opnum)
7069 {
7070   rtx set, mem;
7071
7072   set = PATTERN (insn);
7073   if (GET_CODE (set) == PARALLEL)
7074     set = XVECEXP (set, 0, 0);
7075   gcc_assert (GET_CODE (set) == SET);
7076   mem = XEXP (set, opnum);
7077   while (GET_CODE (mem) == SUBREG)
7078     mem = SUBREG_REG (mem);
7079   gcc_assert (MEM_P (mem));
7080   return (volatile_ok || !MEM_VOLATILE_P (mem));
7081 }
7082 \f
7083 /* Initialize the table of extra 80387 mathematical constants.  */
7084
7085 static void
7086 init_ext_80387_constants (void)
7087 {
7088   static const char * cst[5] =
7089   {
7090     "0.3010299956639811952256464283594894482",  /* 0: fldlg2  */
7091     "0.6931471805599453094286904741849753009",  /* 1: fldln2  */
7092     "1.4426950408889634073876517827983434472",  /* 2: fldl2e  */
7093     "3.3219280948873623478083405569094566090",  /* 3: fldl2t  */
7094     "3.1415926535897932385128089594061862044",  /* 4: fldpi   */
7095   };
7096   int i;
7097
7098   for (i = 0; i < 5; i++)
7099     {
7100       real_from_string (&ext_80387_constants_table[i], cst[i]);
7101       /* Ensure each constant is rounded to XFmode precision.  */
7102       real_convert (&ext_80387_constants_table[i],
7103                     XFmode, &ext_80387_constants_table[i]);
7104     }
7105
7106   ext_80387_constants_init = 1;
7107 }
7108
7109 /* Return true if the constant is something that can be loaded with
7110    a special instruction.  */
7111
7112 int
7113 standard_80387_constant_p (rtx x)
7114 {
7115   enum machine_mode mode = GET_MODE (x);
7116
7117   REAL_VALUE_TYPE r;
7118
7119   if (!(X87_FLOAT_MODE_P (mode) && (GET_CODE (x) == CONST_DOUBLE)))
7120     return -1;
7121
7122   if (x == CONST0_RTX (mode))
7123     return 1;
7124   if (x == CONST1_RTX (mode))
7125     return 2;
7126
7127   REAL_VALUE_FROM_CONST_DOUBLE (r, x);
7128
7129   /* For XFmode constants, try to find a special 80387 instruction when
7130      optimizing for size or on those CPUs that benefit from them.  */
7131   if (mode == XFmode
7132       && (optimize_function_for_size_p (cfun) || TARGET_EXT_80387_CONSTANTS))
7133     {
7134       int i;
7135
7136       if (! ext_80387_constants_init)
7137         init_ext_80387_constants ();
7138
7139       for (i = 0; i < 5; i++)
7140         if (real_identical (&r, &ext_80387_constants_table[i]))
7141           return i + 3;
7142     }
7143
7144   /* Load of the constant -0.0 or -1.0 will be split as
7145      fldz;fchs or fld1;fchs sequence.  */
7146   if (real_isnegzero (&r))
7147     return 8;
7148   if (real_identical (&r, &dconstm1))
7149     return 9;
7150
7151   return 0;
7152 }
7153
7154 /* Return the opcode of the special instruction to be used to load
7155    the constant X.  */
7156
7157 const char *
7158 standard_80387_constant_opcode (rtx x)
7159 {
7160   switch (standard_80387_constant_p (x))
7161     {
7162     case 1:
7163       return "fldz";
7164     case 2:
7165       return "fld1";
7166     case 3:
7167       return "fldlg2";
7168     case 4:
7169       return "fldln2";
7170     case 5:
7171       return "fldl2e";
7172     case 6:
7173       return "fldl2t";
7174     case 7:
7175       return "fldpi";
7176     case 8:
7177     case 9:
7178       return "#";
7179     default:
7180       gcc_unreachable ();
7181     }
7182 }
7183
7184 /* Return the CONST_DOUBLE representing the 80387 constant that is
7185    loaded by the specified special instruction.  The argument IDX
7186    matches the return value from standard_80387_constant_p.  */
7187
7188 rtx
7189 standard_80387_constant_rtx (int idx)
7190 {
7191   int i;
7192
7193   if (! ext_80387_constants_init)
7194     init_ext_80387_constants ();
7195
7196   switch (idx)
7197     {
7198     case 3:
7199     case 4:
7200     case 5:
7201     case 6:
7202     case 7:
7203       i = idx - 3;
7204       break;
7205
7206     default:
7207       gcc_unreachable ();
7208     }
7209
7210   return CONST_DOUBLE_FROM_REAL_VALUE (ext_80387_constants_table[i],
7211                                        XFmode);
7212 }
7213
7214 /* Return 1 if mode is a valid mode for sse.  */
7215 static int
7216 standard_sse_mode_p (enum machine_mode mode)
7217 {
7218   switch (mode)
7219     {
7220     case V16QImode:
7221     case V8HImode:
7222     case V4SImode:
7223     case V2DImode:
7224     case V4SFmode:
7225     case V2DFmode:
7226       return 1;
7227
7228     default:
7229       return 0;
7230     }
7231 }
7232
7233 /* Return 1 if X is all 0s.  For all 1s, return 2 if X is in 128bit
7234    SSE modes and SSE2 is enabled,  return 3 if X is in 256bit AVX
7235    modes and AVX is enabled.  */
7236
7237 int
7238 standard_sse_constant_p (rtx x)
7239 {
7240   enum machine_mode mode = GET_MODE (x);
7241
7242   if (x == const0_rtx || x == CONST0_RTX (GET_MODE (x)))
7243     return 1;
7244   if (vector_all_ones_operand (x, mode))
7245     {
7246       if (standard_sse_mode_p (mode))
7247         return TARGET_SSE2 ? 2 : -2;
7248       else if (VALID_AVX256_REG_MODE (mode))
7249         return TARGET_AVX ? 3 : -3;
7250     }
7251
7252   return 0;
7253 }
7254
7255 /* Return the opcode of the special instruction to be used to load
7256    the constant X.  */
7257
7258 const char *
7259 standard_sse_constant_opcode (rtx insn, rtx x)
7260 {
7261   switch (standard_sse_constant_p (x))
7262     {
7263     case 1:
7264       switch (get_attr_mode (insn))
7265         {
7266         case MODE_V4SF:
7267           return TARGET_AVX ? "vxorps\t%0, %0, %0" : "xorps\t%0, %0";
7268         case MODE_V2DF:
7269           return TARGET_AVX ? "vxorpd\t%0, %0, %0" : "xorpd\t%0, %0";
7270         case MODE_TI:
7271           return TARGET_AVX ? "vpxor\t%0, %0, %0" : "pxor\t%0, %0";
7272         case MODE_V8SF:
7273           return "vxorps\t%x0, %x0, %x0";
7274         case MODE_V4DF:
7275           return "vxorpd\t%x0, %x0, %x0";
7276         case MODE_OI:
7277           return "vpxor\t%x0, %x0, %x0";
7278         default:
7279           gcc_unreachable ();
7280         }
7281     case 2:
7282       if (TARGET_AVX)
7283         switch (get_attr_mode (insn))
7284           {
7285           case MODE_V4SF:
7286           case MODE_V2DF:
7287           case MODE_TI:
7288             return "vpcmpeqd\t%0, %0, %0";
7289             break;
7290           default:
7291             gcc_unreachable ();
7292         }
7293       else
7294         return "pcmpeqd\t%0, %0";
7295     }
7296   gcc_unreachable ();
7297 }
7298
7299 /* Returns 1 if OP contains a symbol reference */
7300
7301 int
7302 symbolic_reference_mentioned_p (rtx op)
7303 {
7304   const char *fmt;
7305   int i;
7306
7307   if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
7308     return 1;
7309
7310   fmt = GET_RTX_FORMAT (GET_CODE (op));
7311   for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
7312     {
7313       if (fmt[i] == 'E')
7314         {
7315           int j;
7316
7317           for (j = XVECLEN (op, i) - 1; j >= 0; j--)
7318             if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
7319               return 1;
7320         }
7321
7322       else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
7323         return 1;
7324     }
7325
7326   return 0;
7327 }
7328
7329 /* Return 1 if it is appropriate to emit `ret' instructions in the
7330    body of a function.  Do this only if the epilogue is simple, needing a
7331    couple of insns.  Prior to reloading, we can't tell how many registers
7332    must be saved, so return 0 then.  Return 0 if there is no frame
7333    marker to de-allocate.  */
7334
7335 int
7336 ix86_can_use_return_insn_p (void)
7337 {
7338   struct ix86_frame frame;
7339
7340   if (! reload_completed || frame_pointer_needed)
7341     return 0;
7342
7343   /* Don't allow more than 32 pop, since that's all we can do
7344      with one instruction.  */
7345   if (crtl->args.pops_args
7346       && crtl->args.size >= 32768)
7347     return 0;
7348
7349   ix86_compute_frame_layout (&frame);
7350   return frame.to_allocate == 0 && frame.padding0 == 0
7351          && (frame.nregs + frame.nsseregs) == 0;
7352 }
7353 \f
7354 /* Value should be nonzero if functions must have frame pointers.
7355    Zero means the frame pointer need not be set up (and parms may
7356    be accessed via the stack pointer) in functions that seem suitable.  */
7357
7358 int
7359 ix86_frame_pointer_required (void)
7360 {
7361   /* If we accessed previous frames, then the generated code expects
7362      to be able to access the saved ebp value in our frame.  */
7363   if (cfun->machine->accesses_prev_frame)
7364     return 1;
7365
7366   /* Several x86 os'es need a frame pointer for other reasons,
7367      usually pertaining to setjmp.  */
7368   if (SUBTARGET_FRAME_POINTER_REQUIRED)
7369     return 1;
7370
7371   /* In override_options, TARGET_OMIT_LEAF_FRAME_POINTER turns off
7372      the frame pointer by default.  Turn it back on now if we've not
7373      got a leaf function.  */
7374   if (TARGET_OMIT_LEAF_FRAME_POINTER
7375       && (!current_function_is_leaf
7376           || ix86_current_function_calls_tls_descriptor))
7377     return 1;
7378
7379   if (crtl->profile)
7380     return 1;
7381
7382   return 0;
7383 }
7384
7385 /* Record that the current function accesses previous call frames.  */
7386
7387 void
7388 ix86_setup_frame_addresses (void)
7389 {
7390   cfun->machine->accesses_prev_frame = 1;
7391 }
7392 \f
7393 #ifndef USE_HIDDEN_LINKONCE
7394 # if (defined(HAVE_GAS_HIDDEN) && (SUPPORTS_ONE_ONLY - 0)) || TARGET_MACHO
7395 #  define USE_HIDDEN_LINKONCE 1
7396 # else
7397 #  define USE_HIDDEN_LINKONCE 0
7398 # endif
7399 #endif
7400
7401 static int pic_labels_used;
7402
7403 /* Fills in the label name that should be used for a pc thunk for
7404    the given register.  */
7405
7406 static void
7407 get_pc_thunk_name (char name[32], unsigned int regno)
7408 {
7409   gcc_assert (!TARGET_64BIT);
7410
7411   if (USE_HIDDEN_LINKONCE)
7412     sprintf (name, "__i686.get_pc_thunk.%s", reg_names[regno]);
7413   else
7414     ASM_GENERATE_INTERNAL_LABEL (name, "LPR", regno);
7415 }
7416
7417
7418 /* This function generates code for -fpic that loads %ebx with
7419    the return address of the caller and then returns.  */
7420
7421 void
7422 ix86_file_end (void)
7423 {
7424   rtx xops[2];
7425   int regno;
7426
7427   for (regno = 0; regno < 8; ++regno)
7428     {
7429       char name[32];
7430
7431       if (! ((pic_labels_used >> regno) & 1))
7432         continue;
7433
7434       get_pc_thunk_name (name, regno);
7435
7436 #if TARGET_MACHO
7437       if (TARGET_MACHO)
7438         {
7439           switch_to_section (darwin_sections[text_coal_section]);
7440           fputs ("\t.weak_definition\t", asm_out_file);
7441           assemble_name (asm_out_file, name);
7442           fputs ("\n\t.private_extern\t", asm_out_file);
7443           assemble_name (asm_out_file, name);
7444           fputs ("\n", asm_out_file);
7445           ASM_OUTPUT_LABEL (asm_out_file, name);
7446         }
7447       else
7448 #endif
7449       if (USE_HIDDEN_LINKONCE)
7450         {
7451           tree decl;
7452
7453           decl = build_decl (FUNCTION_DECL, get_identifier (name),
7454                              error_mark_node);
7455           TREE_PUBLIC (decl) = 1;
7456           TREE_STATIC (decl) = 1;
7457           DECL_ONE_ONLY (decl) = 1;
7458
7459           (*targetm.asm_out.unique_section) (decl, 0);
7460           switch_to_section (get_named_section (decl, NULL, 0));
7461
7462           (*targetm.asm_out.globalize_label) (asm_out_file, name);
7463           fputs ("\t.hidden\t", asm_out_file);
7464           assemble_name (asm_out_file, name);
7465           fputc ('\n', asm_out_file);
7466           ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl);
7467         }
7468       else
7469         {
7470           switch_to_section (text_section);
7471           ASM_OUTPUT_LABEL (asm_out_file, name);
7472         }
7473
7474       xops[0] = gen_rtx_REG (Pmode, regno);
7475       xops[1] = gen_rtx_MEM (Pmode, stack_pointer_rtx);
7476       output_asm_insn ("mov%z0\t{%1, %0|%0, %1}", xops);
7477       output_asm_insn ("ret", xops);
7478     }
7479
7480   if (NEED_INDICATE_EXEC_STACK)
7481     file_end_indicate_exec_stack ();
7482 }
7483
7484 /* Emit code for the SET_GOT patterns.  */
7485
7486 const char *
7487 output_set_got (rtx dest, rtx label ATTRIBUTE_UNUSED)
7488 {
7489   rtx xops[3];
7490
7491   xops[0] = dest;
7492
7493   if (TARGET_VXWORKS_RTP && flag_pic)
7494     {
7495       /* Load (*VXWORKS_GOTT_BASE) into the PIC register.  */
7496       xops[2] = gen_rtx_MEM (Pmode,
7497                              gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE));
7498       output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops);
7499
7500       /* Load (*VXWORKS_GOTT_BASE)[VXWORKS_GOTT_INDEX] into the PIC register.
7501          Use %P and a local symbol in order to print VXWORKS_GOTT_INDEX as
7502          an unadorned address.  */
7503       xops[2] = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX);
7504       SYMBOL_REF_FLAGS (xops[2]) |= SYMBOL_FLAG_LOCAL;
7505       output_asm_insn ("mov{l}\t{%P2(%0), %0|%0, DWORD PTR %P2[%0]}", xops);
7506       return "";
7507     }
7508
7509   xops[1] = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
7510
7511   if (! TARGET_DEEP_BRANCH_PREDICTION || !flag_pic)
7512     {
7513       xops[2] = gen_rtx_LABEL_REF (Pmode, label ? label : gen_label_rtx ());
7514
7515       if (!flag_pic)
7516         output_asm_insn ("mov%z0\t{%2, %0|%0, %2}", xops);
7517       else
7518         output_asm_insn ("call\t%a2", xops);
7519
7520 #if TARGET_MACHO
7521       /* Output the Mach-O "canonical" label name ("Lxx$pb") here too.  This
7522          is what will be referenced by the Mach-O PIC subsystem.  */
7523       if (!label)
7524         ASM_OUTPUT_LABEL (asm_out_file, MACHOPIC_FUNCTION_BASE_NAME);
7525 #endif
7526
7527       (*targetm.asm_out.internal_label) (asm_out_file, "L",
7528                                  CODE_LABEL_NUMBER (XEXP (xops[2], 0)));
7529
7530       if (flag_pic)
7531         output_asm_insn ("pop%z0\t%0", xops);
7532     }
7533   else
7534     {
7535       char name[32];
7536       get_pc_thunk_name (name, REGNO (dest));
7537       pic_labels_used |= 1 << REGNO (dest);
7538
7539       xops[2] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
7540       xops[2] = gen_rtx_MEM (QImode, xops[2]);
7541       output_asm_insn ("call\t%X2", xops);
7542       /* Output the Mach-O "canonical" label name ("Lxx$pb") here too.  This
7543          is what will be referenced by the Mach-O PIC subsystem.  */
7544 #if TARGET_MACHO
7545       if (!label)
7546         ASM_OUTPUT_LABEL (asm_out_file, MACHOPIC_FUNCTION_BASE_NAME);
7547       else
7548         targetm.asm_out.internal_label (asm_out_file, "L",
7549                                            CODE_LABEL_NUMBER (label));
7550 #endif
7551     }
7552
7553   if (TARGET_MACHO)
7554     return "";
7555
7556   if (!flag_pic || TARGET_DEEP_BRANCH_PREDICTION)
7557     output_asm_insn ("add%z0\t{%1, %0|%0, %1}", xops);
7558   else
7559     output_asm_insn ("add%z0\t{%1+[.-%a2], %0|%0, %1+(.-%a2)}", xops);
7560
7561   return "";
7562 }
7563
7564 /* Generate an "push" pattern for input ARG.  */
7565
7566 static rtx
7567 gen_push (rtx arg)
7568 {
7569   return gen_rtx_SET (VOIDmode,
7570                       gen_rtx_MEM (Pmode,
7571                                    gen_rtx_PRE_DEC (Pmode,
7572                                                     stack_pointer_rtx)),
7573                       arg);
7574 }
7575
7576 /* Return >= 0 if there is an unused call-clobbered register available
7577    for the entire function.  */
7578
7579 static unsigned int
7580 ix86_select_alt_pic_regnum (void)
7581 {
7582   if (current_function_is_leaf && !crtl->profile
7583       && !ix86_current_function_calls_tls_descriptor)
7584     {
7585       int i, drap;
7586       /* Can't use the same register for both PIC and DRAP.  */
7587       if (crtl->drap_reg)
7588         drap = REGNO (crtl->drap_reg);
7589       else
7590         drap = -1;
7591       for (i = 2; i >= 0; --i)
7592         if (i != drap && !df_regs_ever_live_p (i))
7593           return i;
7594     }
7595
7596   return INVALID_REGNUM;
7597 }
7598
7599 /* Return 1 if we need to save REGNO.  */
7600 static int
7601 ix86_save_reg (unsigned int regno, int maybe_eh_return)
7602 {
7603   if (pic_offset_table_rtx
7604       && regno == REAL_PIC_OFFSET_TABLE_REGNUM
7605       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
7606           || crtl->profile
7607           || crtl->calls_eh_return
7608           || crtl->uses_const_pool))
7609     {
7610       if (ix86_select_alt_pic_regnum () != INVALID_REGNUM)
7611         return 0;
7612       return 1;
7613     }
7614
7615   if (crtl->calls_eh_return && maybe_eh_return)
7616     {
7617       unsigned i;
7618       for (i = 0; ; i++)
7619         {
7620           unsigned test = EH_RETURN_DATA_REGNO (i);
7621           if (test == INVALID_REGNUM)
7622             break;
7623           if (test == regno)
7624             return 1;
7625         }
7626     }
7627
7628   if (crtl->drap_reg
7629       && regno == REGNO (crtl->drap_reg))
7630     return 1;
7631
7632   return (df_regs_ever_live_p (regno)
7633           && !call_used_regs[regno]
7634           && !fixed_regs[regno]
7635           && (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed));
7636 }
7637
7638 /* Return number of saved general prupose registers.  */
7639
7640 static int
7641 ix86_nsaved_regs (void)
7642 {
7643   int nregs = 0;
7644   int regno;
7645
7646   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7647     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
7648       nregs ++;
7649   return nregs;
7650 }
7651
7652 /* Return number of saved SSE registrers.  */
7653
7654 static int
7655 ix86_nsaved_sseregs (void)
7656 {
7657   int nregs = 0;
7658   int regno;
7659
7660   if (ix86_cfun_abi () != MS_ABI)
7661     return 0;
7662   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7663     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
7664       nregs ++;
7665   return nregs;
7666 }
7667
7668 /* Given FROM and TO register numbers, say whether this elimination is
7669    allowed.  If stack alignment is needed, we can only replace argument
7670    pointer with hard frame pointer, or replace frame pointer with stack
7671    pointer.  Otherwise, frame pointer elimination is automatically
7672    handled and all other eliminations are valid.  */
7673
7674 int
7675 ix86_can_eliminate (int from, int to)
7676 {
7677   if (stack_realign_fp)
7678     return ((from == ARG_POINTER_REGNUM
7679              && to == HARD_FRAME_POINTER_REGNUM)
7680             || (from == FRAME_POINTER_REGNUM
7681                 && to == STACK_POINTER_REGNUM));
7682   else
7683     return to == STACK_POINTER_REGNUM ? !frame_pointer_needed : 1;
7684 }
7685
7686 /* Return the offset between two registers, one to be eliminated, and the other
7687    its replacement, at the start of a routine.  */
7688
7689 HOST_WIDE_INT
7690 ix86_initial_elimination_offset (int from, int to)
7691 {
7692   struct ix86_frame frame;
7693   ix86_compute_frame_layout (&frame);
7694
7695   if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
7696     return frame.hard_frame_pointer_offset;
7697   else if (from == FRAME_POINTER_REGNUM
7698            && to == HARD_FRAME_POINTER_REGNUM)
7699     return frame.hard_frame_pointer_offset - frame.frame_pointer_offset;
7700   else
7701     {
7702       gcc_assert (to == STACK_POINTER_REGNUM);
7703
7704       if (from == ARG_POINTER_REGNUM)
7705         return frame.stack_pointer_offset;
7706
7707       gcc_assert (from == FRAME_POINTER_REGNUM);
7708       return frame.stack_pointer_offset - frame.frame_pointer_offset;
7709     }
7710 }
7711
7712 /* In a dynamically-aligned function, we can't know the offset from
7713    stack pointer to frame pointer, so we must ensure that setjmp
7714    eliminates fp against the hard fp (%ebp) rather than trying to
7715    index from %esp up to the top of the frame across a gap that is
7716    of unknown (at compile-time) size.  */
7717 static rtx
7718 ix86_builtin_setjmp_frame_value (void)
7719 {
7720   return stack_realign_fp ? hard_frame_pointer_rtx : virtual_stack_vars_rtx;
7721 }
7722
7723 /* Fill structure ix86_frame about frame of currently computed function.  */
7724
7725 static void
7726 ix86_compute_frame_layout (struct ix86_frame *frame)
7727 {
7728   HOST_WIDE_INT total_size;
7729   unsigned int stack_alignment_needed;
7730   HOST_WIDE_INT offset;
7731   unsigned int preferred_alignment;
7732   HOST_WIDE_INT size = get_frame_size ();
7733
7734   frame->nregs = ix86_nsaved_regs ();
7735   frame->nsseregs = ix86_nsaved_sseregs ();
7736   total_size = size;
7737
7738   stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT;
7739   preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT;
7740
7741   /* MS ABI seem to require stack alignment to be always 16 except for function
7742      prologues.  */
7743   if (ix86_cfun_abi () == MS_ABI && preferred_alignment < 16)
7744     {
7745       preferred_alignment = 16;
7746       stack_alignment_needed = 16;
7747       crtl->preferred_stack_boundary = 128;
7748       crtl->stack_alignment_needed = 128;
7749     }
7750
7751   gcc_assert (!size || stack_alignment_needed);
7752   gcc_assert (preferred_alignment >= STACK_BOUNDARY / BITS_PER_UNIT);
7753   gcc_assert (preferred_alignment <= stack_alignment_needed);
7754
7755   /* During reload iteration the amount of registers saved can change.
7756      Recompute the value as needed.  Do not recompute when amount of registers
7757      didn't change as reload does multiple calls to the function and does not
7758      expect the decision to change within single iteration.  */
7759   if (!optimize_function_for_size_p (cfun)
7760       && cfun->machine->use_fast_prologue_epilogue_nregs != frame->nregs)
7761     {
7762       int count = frame->nregs;
7763
7764       cfun->machine->use_fast_prologue_epilogue_nregs = count;
7765       /* The fast prologue uses move instead of push to save registers.  This
7766          is significantly longer, but also executes faster as modern hardware
7767          can execute the moves in parallel, but can't do that for push/pop.
7768
7769          Be careful about choosing what prologue to emit:  When function takes
7770          many instructions to execute we may use slow version as well as in
7771          case function is known to be outside hot spot (this is known with
7772          feedback only).  Weight the size of function by number of registers
7773          to save as it is cheap to use one or two push instructions but very
7774          slow to use many of them.  */
7775       if (count)
7776         count = (count - 1) * FAST_PROLOGUE_INSN_COUNT;
7777       if (cfun->function_frequency < FUNCTION_FREQUENCY_NORMAL
7778           || (flag_branch_probabilities
7779               && cfun->function_frequency < FUNCTION_FREQUENCY_HOT))
7780         cfun->machine->use_fast_prologue_epilogue = false;
7781       else
7782         cfun->machine->use_fast_prologue_epilogue
7783            = !expensive_function_p (count);
7784     }
7785   if (TARGET_PROLOGUE_USING_MOVE
7786       && cfun->machine->use_fast_prologue_epilogue)
7787     frame->save_regs_using_mov = true;
7788   else
7789     frame->save_regs_using_mov = false;
7790
7791
7792   /* Skip return address and saved base pointer.  */
7793   offset = frame_pointer_needed ? UNITS_PER_WORD * 2 : UNITS_PER_WORD;
7794
7795   frame->hard_frame_pointer_offset = offset;
7796
7797   /* Set offset to aligned because the realigned frame starts from
7798      here.  */
7799   if (stack_realign_fp)
7800     offset = (offset + stack_alignment_needed -1) & -stack_alignment_needed;
7801
7802   /* Register save area */
7803   offset += frame->nregs * UNITS_PER_WORD;
7804
7805   /* Align SSE reg save area.  */
7806   if (frame->nsseregs)
7807     frame->padding0 = ((offset + 16 - 1) & -16) - offset;
7808   else
7809     frame->padding0 = 0;
7810   
7811   /* SSE register save area.  */
7812   offset += frame->padding0 + frame->nsseregs * 16;
7813
7814   /* Va-arg area */
7815   frame->va_arg_size = ix86_varargs_gpr_size + ix86_varargs_fpr_size;
7816   offset += frame->va_arg_size;
7817
7818   /* Align start of frame for local function.  */
7819   frame->padding1 = ((offset + stack_alignment_needed - 1)
7820                      & -stack_alignment_needed) - offset;
7821
7822   offset += frame->padding1;
7823
7824   /* Frame pointer points here.  */
7825   frame->frame_pointer_offset = offset;
7826
7827   offset += size;
7828
7829   /* Add outgoing arguments area.  Can be skipped if we eliminated
7830      all the function calls as dead code.
7831      Skipping is however impossible when function calls alloca.  Alloca
7832      expander assumes that last crtl->outgoing_args_size
7833      of stack frame are unused.  */
7834   if (ACCUMULATE_OUTGOING_ARGS
7835       && (!current_function_is_leaf || cfun->calls_alloca
7836           || ix86_current_function_calls_tls_descriptor))
7837     {
7838       offset += crtl->outgoing_args_size;
7839       frame->outgoing_arguments_size = crtl->outgoing_args_size;
7840     }
7841   else
7842     frame->outgoing_arguments_size = 0;
7843
7844   /* Align stack boundary.  Only needed if we're calling another function
7845      or using alloca.  */
7846   if (!current_function_is_leaf || cfun->calls_alloca
7847       || ix86_current_function_calls_tls_descriptor)
7848     frame->padding2 = ((offset + preferred_alignment - 1)
7849                        & -preferred_alignment) - offset;
7850   else
7851     frame->padding2 = 0;
7852
7853   offset += frame->padding2;
7854
7855   /* We've reached end of stack frame.  */
7856   frame->stack_pointer_offset = offset;
7857
7858   /* Size prologue needs to allocate.  */
7859   frame->to_allocate =
7860     (size + frame->padding1 + frame->padding2
7861      + frame->outgoing_arguments_size + frame->va_arg_size);
7862
7863   if ((!frame->to_allocate && frame->nregs <= 1)
7864       || (TARGET_64BIT && frame->to_allocate >= (HOST_WIDE_INT) 0x80000000))
7865     frame->save_regs_using_mov = false;
7866
7867   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE
7868       && current_function_sp_is_unchanging
7869       && current_function_is_leaf
7870       && !ix86_current_function_calls_tls_descriptor)
7871     {
7872       frame->red_zone_size = frame->to_allocate;
7873       if (frame->save_regs_using_mov)
7874         frame->red_zone_size += frame->nregs * UNITS_PER_WORD;
7875       if (frame->red_zone_size > RED_ZONE_SIZE - RED_ZONE_RESERVE)
7876         frame->red_zone_size = RED_ZONE_SIZE - RED_ZONE_RESERVE;
7877     }
7878   else
7879     frame->red_zone_size = 0;
7880   frame->to_allocate -= frame->red_zone_size;
7881   frame->stack_pointer_offset -= frame->red_zone_size;
7882 #if 0
7883   fprintf (stderr, "\n");
7884   fprintf (stderr, "size: %ld\n", (long)size);
7885   fprintf (stderr, "nregs: %ld\n", (long)frame->nregs);
7886   fprintf (stderr, "nsseregs: %ld\n", (long)frame->nsseregs);
7887   fprintf (stderr, "padding0: %ld\n", (long)frame->padding0);
7888   fprintf (stderr, "alignment1: %ld\n", (long)stack_alignment_needed);
7889   fprintf (stderr, "padding1: %ld\n", (long)frame->padding1);
7890   fprintf (stderr, "va_arg: %ld\n", (long)frame->va_arg_size);
7891   fprintf (stderr, "padding2: %ld\n", (long)frame->padding2);
7892   fprintf (stderr, "to_allocate: %ld\n", (long)frame->to_allocate);
7893   fprintf (stderr, "red_zone_size: %ld\n", (long)frame->red_zone_size);
7894   fprintf (stderr, "frame_pointer_offset: %ld\n", (long)frame->frame_pointer_offset);
7895   fprintf (stderr, "hard_frame_pointer_offset: %ld\n",
7896            (long)frame->hard_frame_pointer_offset);
7897   fprintf (stderr, "stack_pointer_offset: %ld\n", (long)frame->stack_pointer_offset);
7898   fprintf (stderr, "current_function_is_leaf: %ld\n", (long)current_function_is_leaf);
7899   fprintf (stderr, "cfun->calls_alloca: %ld\n", (long)cfun->calls_alloca);
7900   fprintf (stderr, "x86_current_function_calls_tls_descriptor: %ld\n", (long)ix86_current_function_calls_tls_descriptor);
7901 #endif
7902 }
7903
7904 /* Emit code to save registers in the prologue.  */
7905
7906 static void
7907 ix86_emit_save_regs (void)
7908 {
7909   unsigned int regno;
7910   rtx insn;
7911
7912   for (regno = FIRST_PSEUDO_REGISTER - 1; regno-- > 0; )
7913     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
7914       {
7915         insn = emit_insn (gen_push (gen_rtx_REG (Pmode, regno)));
7916         RTX_FRAME_RELATED_P (insn) = 1;
7917       }
7918 }
7919
7920 /* Emit code to save registers using MOV insns.  First register
7921    is restored from POINTER + OFFSET.  */
7922 static void
7923 ix86_emit_save_regs_using_mov (rtx pointer, HOST_WIDE_INT offset)
7924 {
7925   unsigned int regno;
7926   rtx insn;
7927
7928   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7929     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
7930       {
7931         insn = emit_move_insn (adjust_address (gen_rtx_MEM (Pmode, pointer),
7932                                                Pmode, offset),
7933                                gen_rtx_REG (Pmode, regno));
7934         RTX_FRAME_RELATED_P (insn) = 1;
7935         offset += UNITS_PER_WORD;
7936       }
7937 }
7938
7939 /* Emit code to save registers using MOV insns.  First register
7940    is restored from POINTER + OFFSET.  */
7941 static void
7942 ix86_emit_save_sse_regs_using_mov (rtx pointer, HOST_WIDE_INT offset)
7943 {
7944   unsigned int regno;
7945   rtx insn;
7946   rtx mem;
7947
7948   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7949     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
7950       {
7951         mem = adjust_address (gen_rtx_MEM (TImode, pointer), TImode, offset);
7952         set_mem_align (mem, 128);
7953         insn = emit_move_insn (mem, gen_rtx_REG (TImode, regno));
7954         RTX_FRAME_RELATED_P (insn) = 1;
7955         offset += 16;
7956       }
7957 }
7958
7959 /* Expand prologue or epilogue stack adjustment.
7960    The pattern exist to put a dependency on all ebp-based memory accesses.
7961    STYLE should be negative if instructions should be marked as frame related,
7962    zero if %r11 register is live and cannot be freely used and positive
7963    otherwise.  */
7964
7965 static void
7966 pro_epilogue_adjust_stack (rtx dest, rtx src, rtx offset, int style)
7967 {
7968   rtx insn;
7969
7970   if (! TARGET_64BIT)
7971     insn = emit_insn (gen_pro_epilogue_adjust_stack_1 (dest, src, offset));
7972   else if (x86_64_immediate_operand (offset, DImode))
7973     insn = emit_insn (gen_pro_epilogue_adjust_stack_rex64 (dest, src, offset));
7974   else
7975     {
7976       rtx r11;
7977       /* r11 is used by indirect sibcall return as well, set before the
7978          epilogue and used after the epilogue.  ATM indirect sibcall
7979          shouldn't be used together with huge frame sizes in one
7980          function because of the frame_size check in sibcall.c.  */
7981       gcc_assert (style);
7982       r11 = gen_rtx_REG (DImode, R11_REG);
7983       insn = emit_insn (gen_rtx_SET (DImode, r11, offset));
7984       if (style < 0)
7985         RTX_FRAME_RELATED_P (insn) = 1;
7986       insn = emit_insn (gen_pro_epilogue_adjust_stack_rex64_2 (dest, src, r11,
7987                                                                offset));
7988     }
7989   if (style < 0)
7990     RTX_FRAME_RELATED_P (insn) = 1;
7991 }
7992
7993 /* Find an available register to be used as dynamic realign argument
7994    pointer regsiter.  Such a register will be written in prologue and
7995    used in begin of body, so it must not be
7996         1. parameter passing register.
7997         2. GOT pointer.
7998    We reuse static-chain register if it is available.  Otherwise, we
7999    use DI for i386 and R13 for x86-64.  We chose R13 since it has
8000    shorter encoding.
8001
8002    Return: the regno of chosen register.  */
8003
8004 static unsigned int 
8005 find_drap_reg (void)
8006 {
8007   tree decl = cfun->decl;
8008
8009   if (TARGET_64BIT)
8010     {
8011       /* Use R13 for nested function or function need static chain.
8012          Since function with tail call may use any caller-saved
8013          registers in epilogue, DRAP must not use caller-saved
8014          register in such case.  */
8015       if ((decl_function_context (decl)
8016            && !DECL_NO_STATIC_CHAIN (decl))
8017           || crtl->tail_call_emit)
8018         return R13_REG;
8019
8020       return R10_REG;
8021     }
8022   else
8023     {
8024       /* Use DI for nested function or function need static chain.
8025          Since function with tail call may use any caller-saved
8026          registers in epilogue, DRAP must not use caller-saved
8027          register in such case.  */
8028       if ((decl_function_context (decl)
8029            && !DECL_NO_STATIC_CHAIN (decl))
8030           || crtl->tail_call_emit)
8031         return DI_REG;
8032     
8033       /* Reuse static chain register if it isn't used for parameter
8034          passing.  */
8035       if (ix86_function_regparm (TREE_TYPE (decl), decl) <= 2
8036           && !lookup_attribute ("fastcall",
8037                                 TYPE_ATTRIBUTES (TREE_TYPE (decl))))
8038         return CX_REG;
8039       else
8040         return DI_REG;
8041     }
8042 }
8043
8044 /* Update incoming stack boundary and estimated stack alignment.  */
8045
8046 static void
8047 ix86_update_stack_boundary (void)
8048 {
8049   /* Prefer the one specified at command line. */
8050   ix86_incoming_stack_boundary 
8051     = (ix86_user_incoming_stack_boundary
8052        ? ix86_user_incoming_stack_boundary
8053        : ix86_default_incoming_stack_boundary);
8054
8055   /* Incoming stack alignment can be changed on individual functions
8056      via force_align_arg_pointer attribute.  We use the smallest
8057      incoming stack boundary.  */
8058   if (ix86_incoming_stack_boundary > MIN_STACK_BOUNDARY
8059       && lookup_attribute (ix86_force_align_arg_pointer_string,
8060                            TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
8061     ix86_incoming_stack_boundary = MIN_STACK_BOUNDARY;
8062
8063   /* The incoming stack frame has to be aligned at least at
8064      parm_stack_boundary.  */
8065   if (ix86_incoming_stack_boundary < crtl->parm_stack_boundary)
8066     ix86_incoming_stack_boundary = crtl->parm_stack_boundary;
8067
8068   /* Stack at entrance of main is aligned by runtime.  We use the
8069      smallest incoming stack boundary. */
8070   if (ix86_incoming_stack_boundary > MAIN_STACK_BOUNDARY
8071       && DECL_NAME (current_function_decl)
8072       && MAIN_NAME_P (DECL_NAME (current_function_decl))
8073       && DECL_FILE_SCOPE_P (current_function_decl))
8074     ix86_incoming_stack_boundary = MAIN_STACK_BOUNDARY;
8075
8076   /* x86_64 vararg needs 16byte stack alignment for register save
8077      area.  */
8078   if (TARGET_64BIT
8079       && cfun->stdarg
8080       && crtl->stack_alignment_estimated < 128)
8081     crtl->stack_alignment_estimated = 128;
8082 }
8083
8084 /* Handle the TARGET_GET_DRAP_RTX hook.  Return NULL if no DRAP is
8085    needed or an rtx for DRAP otherwise.  */
8086
8087 static rtx
8088 ix86_get_drap_rtx (void)
8089 {
8090   if (ix86_force_drap || !ACCUMULATE_OUTGOING_ARGS)
8091     crtl->need_drap = true;
8092
8093   if (stack_realign_drap)
8094     {
8095       /* Assign DRAP to vDRAP and returns vDRAP */
8096       unsigned int regno = find_drap_reg ();
8097       rtx drap_vreg;
8098       rtx arg_ptr;
8099       rtx seq, insn;
8100
8101       arg_ptr = gen_rtx_REG (Pmode, regno);
8102       crtl->drap_reg = arg_ptr;
8103
8104       start_sequence ();
8105       drap_vreg = copy_to_reg (arg_ptr);
8106       seq = get_insns ();
8107       end_sequence ();
8108       
8109       insn = emit_insn_before (seq, NEXT_INSN (entry_of_function ()));
8110       RTX_FRAME_RELATED_P (insn) = 1;
8111       return drap_vreg;
8112     }
8113   else
8114     return NULL;
8115 }
8116
8117 /* Handle the TARGET_INTERNAL_ARG_POINTER hook.  */
8118
8119 static rtx
8120 ix86_internal_arg_pointer (void)
8121 {
8122   return virtual_incoming_args_rtx;
8123 }
8124
8125 /* Handle the TARGET_DWARF_HANDLE_FRAME_UNSPEC hook.
8126    This is called from dwarf2out.c to emit call frame instructions
8127    for frame-related insns containing UNSPECs and UNSPEC_VOLATILEs. */
8128 static void
8129 ix86_dwarf_handle_frame_unspec (const char *label, rtx pattern, int index)
8130 {
8131   rtx unspec = SET_SRC (pattern);
8132   gcc_assert (GET_CODE (unspec) == UNSPEC);
8133
8134   switch (index)
8135     {
8136     case UNSPEC_REG_SAVE:
8137       dwarf2out_reg_save_reg (label, XVECEXP (unspec, 0, 0),
8138                               SET_DEST (pattern));
8139       break;
8140     case UNSPEC_DEF_CFA:
8141       dwarf2out_def_cfa (label, REGNO (SET_DEST (pattern)),
8142                          INTVAL (XVECEXP (unspec, 0, 0)));
8143       break;
8144     default:
8145       gcc_unreachable ();
8146     }
8147 }
8148
8149 /* Finalize stack_realign_needed flag, which will guide prologue/epilogue
8150    to be generated in correct form.  */
8151 static void 
8152 ix86_finalize_stack_realign_flags (void)
8153 {
8154   /* Check if stack realign is really needed after reload, and 
8155      stores result in cfun */
8156   unsigned int incoming_stack_boundary
8157     = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
8158        ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
8159   unsigned int stack_realign = (incoming_stack_boundary
8160                                 < (current_function_is_leaf
8161                                    ? crtl->max_used_stack_slot_alignment
8162                                    : crtl->stack_alignment_needed));
8163
8164   if (crtl->stack_realign_finalized)
8165     {
8166       /* After stack_realign_needed is finalized, we can't no longer
8167          change it.  */
8168       gcc_assert (crtl->stack_realign_needed == stack_realign);
8169     }
8170   else
8171     {
8172       crtl->stack_realign_needed = stack_realign;
8173       crtl->stack_realign_finalized = true;
8174     }
8175 }
8176
8177 /* Expand the prologue into a bunch of separate insns.  */
8178
8179 void
8180 ix86_expand_prologue (void)
8181 {
8182   rtx insn;
8183   bool pic_reg_used;
8184   struct ix86_frame frame;
8185   HOST_WIDE_INT allocate;
8186
8187   ix86_finalize_stack_realign_flags ();
8188
8189   /* DRAP should not coexist with stack_realign_fp */
8190   gcc_assert (!(crtl->drap_reg && stack_realign_fp));
8191
8192   ix86_compute_frame_layout (&frame);
8193
8194   /* Emit prologue code to adjust stack alignment and setup DRAP, in case
8195      of DRAP is needed and stack realignment is really needed after reload */
8196   if (crtl->drap_reg && crtl->stack_realign_needed)
8197     {
8198       rtx x, y;
8199       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
8200       int param_ptr_offset = (call_used_regs[REGNO (crtl->drap_reg)]
8201                               ? 0 : UNITS_PER_WORD);
8202
8203       gcc_assert (stack_realign_drap);
8204
8205       /* Grab the argument pointer.  */
8206       x = plus_constant (stack_pointer_rtx, 
8207                          (UNITS_PER_WORD + param_ptr_offset));
8208       y = crtl->drap_reg;
8209
8210       /* Only need to push parameter pointer reg if it is caller
8211          saved reg */
8212       if (!call_used_regs[REGNO (crtl->drap_reg)])
8213         {
8214           /* Push arg pointer reg */
8215           insn = emit_insn (gen_push (y));
8216           RTX_FRAME_RELATED_P (insn) = 1;
8217         }
8218
8219       insn = emit_insn (gen_rtx_SET (VOIDmode, y, x));
8220       RTX_FRAME_RELATED_P (insn) = 1; 
8221
8222       /* Align the stack.  */
8223       insn = emit_insn ((*ix86_gen_andsp) (stack_pointer_rtx,
8224                                            stack_pointer_rtx,
8225                                            GEN_INT (-align_bytes)));
8226       RTX_FRAME_RELATED_P (insn) = 1;
8227
8228       /* Replicate the return address on the stack so that return
8229          address can be reached via (argp - 1) slot.  This is needed
8230          to implement macro RETURN_ADDR_RTX and intrinsic function
8231          expand_builtin_return_addr etc.  */
8232       x = crtl->drap_reg;
8233       x = gen_frame_mem (Pmode,
8234                          plus_constant (x, -UNITS_PER_WORD));
8235       insn = emit_insn (gen_push (x));
8236       RTX_FRAME_RELATED_P (insn) = 1;
8237     }
8238
8239   /* Note: AT&T enter does NOT have reversed args.  Enter is probably
8240      slower on all targets.  Also sdb doesn't like it.  */
8241
8242   if (frame_pointer_needed)
8243     {
8244       insn = emit_insn (gen_push (hard_frame_pointer_rtx));
8245       RTX_FRAME_RELATED_P (insn) = 1;
8246
8247       insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
8248       RTX_FRAME_RELATED_P (insn) = 1;
8249     }
8250
8251   if (stack_realign_fp)
8252     {
8253       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
8254       gcc_assert (align_bytes > MIN_STACK_BOUNDARY / BITS_PER_UNIT);
8255
8256       /* Align the stack.  */
8257       insn = emit_insn ((*ix86_gen_andsp) (stack_pointer_rtx,
8258                                            stack_pointer_rtx,
8259                                            GEN_INT (-align_bytes)));
8260       RTX_FRAME_RELATED_P (insn) = 1;
8261     }
8262
8263   allocate = frame.to_allocate + frame.nsseregs * 16 + frame.padding0;
8264
8265   if (!frame.save_regs_using_mov)
8266     ix86_emit_save_regs ();
8267   else
8268     allocate += frame.nregs * UNITS_PER_WORD;
8269
8270   /* When using red zone we may start register saving before allocating
8271      the stack frame saving one cycle of the prologue. However I will
8272      avoid doing this if I am going to have to probe the stack since
8273      at least on x86_64 the stack probe can turn into a call that clobbers
8274      a red zone location */
8275   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE && frame.save_regs_using_mov
8276       && (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT))
8277     ix86_emit_save_regs_using_mov ((frame_pointer_needed
8278                                      && !crtl->stack_realign_needed) 
8279                                    ? hard_frame_pointer_rtx
8280                                    : stack_pointer_rtx,
8281                                    -frame.nregs * UNITS_PER_WORD);
8282
8283   if (allocate == 0)
8284     ;
8285   else if (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT)
8286     pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8287                                GEN_INT (-allocate), -1);
8288   else
8289     {
8290       rtx eax = gen_rtx_REG (Pmode, AX_REG);
8291       bool eax_live;
8292       rtx t;
8293
8294       if (cfun->machine->call_abi == MS_ABI)
8295         eax_live = false;
8296       else
8297         eax_live = ix86_eax_live_at_start_p ();
8298
8299       if (eax_live)
8300         {
8301           emit_insn (gen_push (eax));
8302           allocate -= UNITS_PER_WORD;
8303         }
8304
8305       emit_move_insn (eax, GEN_INT (allocate));
8306
8307       if (TARGET_64BIT)
8308         insn = gen_allocate_stack_worker_64 (eax, eax);
8309       else
8310         insn = gen_allocate_stack_worker_32 (eax, eax);
8311       insn = emit_insn (insn);
8312       RTX_FRAME_RELATED_P (insn) = 1;
8313       t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (-allocate));
8314       t = gen_rtx_SET (VOIDmode, stack_pointer_rtx, t);
8315       REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
8316                                             t, REG_NOTES (insn));
8317
8318       if (eax_live)
8319         {
8320           if (frame_pointer_needed)
8321             t = plus_constant (hard_frame_pointer_rtx,
8322                                allocate
8323                                - frame.to_allocate
8324                                - frame.nregs * UNITS_PER_WORD);
8325           else
8326             t = plus_constant (stack_pointer_rtx, allocate);
8327           emit_move_insn (eax, gen_rtx_MEM (Pmode, t));
8328         }
8329     }
8330
8331   if (frame.save_regs_using_mov
8332       && !(!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE
8333          && (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT)))
8334     {
8335       if (!frame_pointer_needed
8336           || !(frame.to_allocate + frame.padding0)
8337           || crtl->stack_realign_needed)
8338         ix86_emit_save_regs_using_mov (stack_pointer_rtx,
8339                                        frame.to_allocate
8340                                        + frame.nsseregs * 16 + frame.padding0);
8341       else
8342         ix86_emit_save_regs_using_mov (hard_frame_pointer_rtx,
8343                                        -frame.nregs * UNITS_PER_WORD);
8344     }
8345   if (!frame_pointer_needed
8346       || !(frame.to_allocate + frame.padding0)
8347       || crtl->stack_realign_needed)
8348     ix86_emit_save_sse_regs_using_mov (stack_pointer_rtx,
8349                                        frame.to_allocate);
8350   else
8351     ix86_emit_save_sse_regs_using_mov (hard_frame_pointer_rtx,
8352                                        - frame.nregs * UNITS_PER_WORD
8353                                        - frame.nsseregs * 16
8354                                        - frame.padding0);
8355
8356   pic_reg_used = false;
8357   if (pic_offset_table_rtx
8358       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
8359           || crtl->profile))
8360     {
8361       unsigned int alt_pic_reg_used = ix86_select_alt_pic_regnum ();
8362
8363       if (alt_pic_reg_used != INVALID_REGNUM)
8364         SET_REGNO (pic_offset_table_rtx, alt_pic_reg_used);
8365
8366       pic_reg_used = true;
8367     }
8368
8369   if (pic_reg_used)
8370     {
8371       if (TARGET_64BIT)
8372         {
8373           if (ix86_cmodel == CM_LARGE_PIC)
8374             {
8375               rtx tmp_reg = gen_rtx_REG (DImode, R11_REG);
8376               rtx label = gen_label_rtx ();
8377               emit_label (label);
8378               LABEL_PRESERVE_P (label) = 1;
8379               gcc_assert (REGNO (pic_offset_table_rtx) != REGNO (tmp_reg));
8380               insn = emit_insn (gen_set_rip_rex64 (pic_offset_table_rtx, label));
8381               insn = emit_insn (gen_set_got_offset_rex64 (tmp_reg, label));
8382               insn = emit_insn (gen_adddi3 (pic_offset_table_rtx,
8383                                             pic_offset_table_rtx, tmp_reg));
8384             }
8385           else
8386             insn = emit_insn (gen_set_got_rex64 (pic_offset_table_rtx));
8387         }
8388       else
8389         insn = emit_insn (gen_set_got (pic_offset_table_rtx));
8390     }
8391
8392   /* In the pic_reg_used case, make sure that the got load isn't deleted
8393      when mcount needs it.  Blockage to avoid call movement across mcount
8394      call is emitted in generic code after the NOTE_INSN_PROLOGUE_END
8395      note.  */
8396   if (crtl->profile && pic_reg_used)
8397     emit_insn (gen_prologue_use (pic_offset_table_rtx));
8398
8399   if (crtl->drap_reg && !crtl->stack_realign_needed)
8400     {
8401       /* vDRAP is setup but after reload it turns out stack realign
8402          isn't necessary, here we will emit prologue to setup DRAP
8403          without stack realign adjustment */
8404       int drap_bp_offset = UNITS_PER_WORD * 2;
8405       rtx x = plus_constant (hard_frame_pointer_rtx, drap_bp_offset);
8406       insn = emit_insn (gen_rtx_SET (VOIDmode, crtl->drap_reg, x));
8407     }
8408
8409   /* Prevent instructions from being scheduled into register save push
8410      sequence when access to the redzone area is done through frame pointer.
8411      The offset betweeh the frame pointer and the stack pointer is calculated
8412      relative to the value of the stack pointer at the end of the function
8413      prologue, and moving instructions that access redzone area via frame
8414      pointer inside push sequence violates this assumption.  */
8415   if (frame_pointer_needed && frame.red_zone_size)
8416     emit_insn (gen_memory_blockage ());
8417
8418   /* Emit cld instruction if stringops are used in the function.  */
8419   if (TARGET_CLD && ix86_current_function_needs_cld)
8420     emit_insn (gen_cld ());
8421 }
8422
8423 /* Emit code to restore saved registers using MOV insns.  First register
8424    is restored from POINTER + OFFSET.  */
8425 static void
8426 ix86_emit_restore_regs_using_mov (rtx pointer, HOST_WIDE_INT offset,
8427                                   int maybe_eh_return)
8428 {
8429   int regno;
8430   rtx base_address = gen_rtx_MEM (Pmode, pointer);
8431
8432   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8433     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return))
8434       {
8435         /* Ensure that adjust_address won't be forced to produce pointer
8436            out of range allowed by x86-64 instruction set.  */
8437         if (TARGET_64BIT && offset != trunc_int_for_mode (offset, SImode))
8438           {
8439             rtx r11;
8440
8441             r11 = gen_rtx_REG (DImode, R11_REG);
8442             emit_move_insn (r11, GEN_INT (offset));
8443             emit_insn (gen_adddi3 (r11, r11, pointer));
8444             base_address = gen_rtx_MEM (Pmode, r11);
8445             offset = 0;
8446           }
8447         emit_move_insn (gen_rtx_REG (Pmode, regno),
8448                         adjust_address (base_address, Pmode, offset));
8449         offset += UNITS_PER_WORD;
8450       }
8451 }
8452
8453 /* Emit code to restore saved registers using MOV insns.  First register
8454    is restored from POINTER + OFFSET.  */
8455 static void
8456 ix86_emit_restore_sse_regs_using_mov (rtx pointer, HOST_WIDE_INT offset,
8457                                       int maybe_eh_return)
8458 {
8459   int regno;
8460   rtx base_address = gen_rtx_MEM (TImode, pointer);
8461   rtx mem;
8462
8463   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8464     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return))
8465       {
8466         /* Ensure that adjust_address won't be forced to produce pointer
8467            out of range allowed by x86-64 instruction set.  */
8468         if (TARGET_64BIT && offset != trunc_int_for_mode (offset, SImode))
8469           {
8470             rtx r11;
8471
8472             r11 = gen_rtx_REG (DImode, R11_REG);
8473             emit_move_insn (r11, GEN_INT (offset));
8474             emit_insn (gen_adddi3 (r11, r11, pointer));
8475             base_address = gen_rtx_MEM (TImode, r11);
8476             offset = 0;
8477           }
8478         mem = adjust_address (base_address, TImode, offset);
8479         set_mem_align (mem, 128);
8480         emit_move_insn (gen_rtx_REG (TImode, regno), mem);
8481         offset += 16;
8482       }
8483 }
8484
8485 /* Restore function stack, frame, and registers.  */
8486
8487 void
8488 ix86_expand_epilogue (int style)
8489 {
8490   int regno;
8491   int sp_valid;
8492   struct ix86_frame frame;
8493   HOST_WIDE_INT offset;
8494
8495   ix86_finalize_stack_realign_flags ();
8496
8497  /* When stack is realigned, SP must be valid.  */
8498   sp_valid = (!frame_pointer_needed
8499               || current_function_sp_is_unchanging
8500               || stack_realign_fp);
8501
8502   ix86_compute_frame_layout (&frame);
8503
8504   /* See the comment about red zone and frame
8505      pointer usage in ix86_expand_prologue.  */
8506   if (frame_pointer_needed && frame.red_zone_size)
8507     emit_insn (gen_memory_blockage ()); 
8508
8509   /* Calculate start of saved registers relative to ebp.  Special care
8510      must be taken for the normal return case of a function using
8511      eh_return: the eax and edx registers are marked as saved, but not
8512      restored along this path.  */
8513   offset = frame.nregs;
8514   if (crtl->calls_eh_return && style != 2)
8515     offset -= 2;
8516   offset *= -UNITS_PER_WORD;
8517   offset -= frame.nsseregs * 16 + frame.padding0;
8518
8519   /* If we're only restoring one register and sp is not valid then
8520      using a move instruction to restore the register since it's
8521      less work than reloading sp and popping the register.
8522
8523      The default code result in stack adjustment using add/lea instruction,
8524      while this code results in LEAVE instruction (or discrete equivalent),
8525      so it is profitable in some other cases as well.  Especially when there
8526      are no registers to restore.  We also use this code when TARGET_USE_LEAVE
8527      and there is exactly one register to pop. This heuristic may need some
8528      tuning in future.  */
8529   if ((!sp_valid && (frame.nregs + frame.nsseregs) <= 1)
8530       || (TARGET_EPILOGUE_USING_MOVE
8531           && cfun->machine->use_fast_prologue_epilogue
8532           && ((frame.nregs + frame.nsseregs) > 1
8533               || (frame.to_allocate + frame.padding0) != 0))
8534       || (frame_pointer_needed && !(frame.nregs + frame.nsseregs)
8535           && (frame.to_allocate + frame.padding0) != 0)
8536       || (frame_pointer_needed && TARGET_USE_LEAVE
8537           && cfun->machine->use_fast_prologue_epilogue
8538           && (frame.nregs + frame.nsseregs) == 1)
8539       || crtl->calls_eh_return)
8540     {
8541       /* Restore registers.  We can use ebp or esp to address the memory
8542          locations.  If both are available, default to ebp, since offsets
8543          are known to be small.  Only exception is esp pointing directly
8544          to the end of block of saved registers, where we may simplify
8545          addressing mode.
8546
8547          If we are realigning stack with bp and sp, regs restore can't
8548          be addressed by bp. sp must be used instead.  */
8549
8550       if (!frame_pointer_needed
8551           || (sp_valid && !(frame.to_allocate + frame.padding0))
8552           || stack_realign_fp)
8553         {
8554           ix86_emit_restore_sse_regs_using_mov (stack_pointer_rtx,
8555                                                 frame.to_allocate, style == 2);
8556           ix86_emit_restore_regs_using_mov (stack_pointer_rtx,
8557                                             frame.to_allocate
8558                                             + frame.nsseregs * 16
8559                                             + frame.padding0, style == 2);
8560         }
8561       else
8562         {
8563           ix86_emit_restore_sse_regs_using_mov (hard_frame_pointer_rtx,
8564                                                 offset, style == 2);
8565           ix86_emit_restore_regs_using_mov (hard_frame_pointer_rtx,
8566                                             offset
8567                                             + frame.nsseregs * 16
8568                                             + frame.padding0, style == 2);
8569         }
8570
8571       /* eh_return epilogues need %ecx added to the stack pointer.  */
8572       if (style == 2)
8573         {
8574           rtx tmp, sa = EH_RETURN_STACKADJ_RTX;
8575
8576           /* Stack align doesn't work with eh_return.  */
8577           gcc_assert (!crtl->stack_realign_needed);
8578
8579           if (frame_pointer_needed)
8580             {
8581               tmp = gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx, sa);
8582               tmp = plus_constant (tmp, UNITS_PER_WORD);
8583               emit_insn (gen_rtx_SET (VOIDmode, sa, tmp));
8584
8585               tmp = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
8586               emit_move_insn (hard_frame_pointer_rtx, tmp);
8587
8588               pro_epilogue_adjust_stack (stack_pointer_rtx, sa,
8589                                          const0_rtx, style);
8590             }
8591           else
8592             {
8593               tmp = gen_rtx_PLUS (Pmode, stack_pointer_rtx, sa);
8594               tmp = plus_constant (tmp, (frame.to_allocate
8595                                          + frame.nregs * UNITS_PER_WORD
8596                                          + frame.nsseregs * 16
8597                                          + frame.padding0));
8598               emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx, tmp));
8599             }
8600         }
8601       else if (!frame_pointer_needed)
8602         pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8603                                    GEN_INT (frame.to_allocate
8604                                             + frame.nregs * UNITS_PER_WORD
8605                                             + frame.nsseregs * 16
8606                                             + frame.padding0),
8607                                    style);
8608       /* If not an i386, mov & pop is faster than "leave".  */
8609       else if (TARGET_USE_LEAVE || optimize_function_for_size_p (cfun)
8610                || !cfun->machine->use_fast_prologue_epilogue)
8611         emit_insn ((*ix86_gen_leave) ());
8612       else
8613         {
8614           pro_epilogue_adjust_stack (stack_pointer_rtx,
8615                                      hard_frame_pointer_rtx,
8616                                      const0_rtx, style);
8617
8618           emit_insn ((*ix86_gen_pop1) (hard_frame_pointer_rtx));
8619         }
8620     }
8621   else
8622     {
8623       /* First step is to deallocate the stack frame so that we can
8624          pop the registers.
8625
8626          If we realign stack with frame pointer, then stack pointer
8627          won't be able to recover via lea $offset(%bp), %sp, because
8628          there is a padding area between bp and sp for realign. 
8629          "add $to_allocate, %sp" must be used instead.  */
8630       if (!sp_valid)
8631         {
8632           gcc_assert (frame_pointer_needed);
8633           gcc_assert (!stack_realign_fp);
8634           pro_epilogue_adjust_stack (stack_pointer_rtx,
8635                                      hard_frame_pointer_rtx,
8636                                      GEN_INT (offset), style);
8637           ix86_emit_restore_sse_regs_using_mov (stack_pointer_rtx,
8638                                                 0, style == 2);
8639           pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8640                                      GEN_INT (frame.nsseregs * 16 +
8641                                        frame.padding0), style);
8642         }
8643       else if (frame.to_allocate || frame.padding0 || frame.nsseregs)
8644         {
8645           ix86_emit_restore_sse_regs_using_mov (stack_pointer_rtx,
8646                                                 frame.to_allocate,
8647                                                 style == 2);
8648           pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8649                                      GEN_INT (frame.to_allocate
8650                                               + frame.nsseregs * 16
8651                                               + frame.padding0), style);
8652         }
8653
8654       for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8655         if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, false))
8656           emit_insn ((*ix86_gen_pop1) (gen_rtx_REG (Pmode, regno)));
8657       if (frame_pointer_needed)
8658         {
8659           /* Leave results in shorter dependency chains on CPUs that are
8660              able to grok it fast.  */
8661           if (TARGET_USE_LEAVE)
8662             emit_insn ((*ix86_gen_leave) ());
8663           else
8664             {
8665               /* For stack realigned really happens, recover stack 
8666                  pointer to hard frame pointer is a must, if not using 
8667                  leave.  */
8668               if (stack_realign_fp)
8669                 pro_epilogue_adjust_stack (stack_pointer_rtx,
8670                                            hard_frame_pointer_rtx,
8671                                            const0_rtx, style);
8672               emit_insn ((*ix86_gen_pop1) (hard_frame_pointer_rtx));
8673             }
8674         }
8675     }
8676
8677   if (crtl->drap_reg && crtl->stack_realign_needed)
8678     {
8679       int param_ptr_offset = (call_used_regs[REGNO (crtl->drap_reg)]
8680                               ? 0 : UNITS_PER_WORD);
8681       gcc_assert (stack_realign_drap);
8682       emit_insn (gen_rtx_SET
8683                  (VOIDmode, stack_pointer_rtx,
8684                   gen_rtx_PLUS (Pmode,
8685                                 crtl->drap_reg,
8686                                 GEN_INT (-(UNITS_PER_WORD
8687                                            + param_ptr_offset)))));
8688       if (!call_used_regs[REGNO (crtl->drap_reg)])
8689         emit_insn ((*ix86_gen_pop1) (crtl->drap_reg));
8690       
8691     }
8692
8693   /* Sibcall epilogues don't want a return instruction.  */
8694   if (style == 0)
8695     return;
8696
8697   if (crtl->args.pops_args && crtl->args.size)
8698     {
8699       rtx popc = GEN_INT (crtl->args.pops_args);
8700
8701       /* i386 can only pop 64K bytes.  If asked to pop more, pop
8702          return address, do explicit add, and jump indirectly to the
8703          caller.  */
8704
8705       if (crtl->args.pops_args >= 65536)
8706         {
8707           rtx ecx = gen_rtx_REG (SImode, CX_REG);
8708
8709           /* There is no "pascal" calling convention in any 64bit ABI.  */
8710           gcc_assert (!TARGET_64BIT);
8711
8712           emit_insn (gen_popsi1 (ecx));
8713           emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, popc));
8714           emit_jump_insn (gen_return_indirect_internal (ecx));
8715         }
8716       else
8717         emit_jump_insn (gen_return_pop_internal (popc));
8718     }
8719   else
8720     emit_jump_insn (gen_return_internal ());
8721 }
8722
8723 /* Reset from the function's potential modifications.  */
8724
8725 static void
8726 ix86_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED,
8727                                HOST_WIDE_INT size ATTRIBUTE_UNUSED)
8728 {
8729   if (pic_offset_table_rtx)
8730     SET_REGNO (pic_offset_table_rtx, REAL_PIC_OFFSET_TABLE_REGNUM);
8731 #if TARGET_MACHO
8732   /* Mach-O doesn't support labels at the end of objects, so if
8733      it looks like we might want one, insert a NOP.  */
8734   {
8735     rtx insn = get_last_insn ();
8736     while (insn
8737            && NOTE_P (insn)
8738            && NOTE_KIND (insn) != NOTE_INSN_DELETED_LABEL)
8739       insn = PREV_INSN (insn);
8740     if (insn
8741         && (LABEL_P (insn)
8742             || (NOTE_P (insn)
8743                 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL)))
8744       fputs ("\tnop\n", file);
8745   }
8746 #endif
8747
8748 }
8749 \f
8750 /* Extract the parts of an RTL expression that is a valid memory address
8751    for an instruction.  Return 0 if the structure of the address is
8752    grossly off.  Return -1 if the address contains ASHIFT, so it is not
8753    strictly valid, but still used for computing length of lea instruction.  */
8754
8755 int
8756 ix86_decompose_address (rtx addr, struct ix86_address *out)
8757 {
8758   rtx base = NULL_RTX, index = NULL_RTX, disp = NULL_RTX;
8759   rtx base_reg, index_reg;
8760   HOST_WIDE_INT scale = 1;
8761   rtx scale_rtx = NULL_RTX;
8762   int retval = 1;
8763   enum ix86_address_seg seg = SEG_DEFAULT;
8764
8765   if (REG_P (addr) || GET_CODE (addr) == SUBREG)
8766     base = addr;
8767   else if (GET_CODE (addr) == PLUS)
8768     {
8769       rtx addends[4], op;
8770       int n = 0, i;
8771
8772       op = addr;
8773       do
8774         {
8775           if (n >= 4)
8776             return 0;
8777           addends[n++] = XEXP (op, 1);
8778           op = XEXP (op, 0);
8779         }
8780       while (GET_CODE (op) == PLUS);
8781       if (n >= 4)
8782         return 0;
8783       addends[n] = op;
8784
8785       for (i = n; i >= 0; --i)
8786         {
8787           op = addends[i];
8788           switch (GET_CODE (op))
8789             {
8790             case MULT:
8791               if (index)
8792                 return 0;
8793               index = XEXP (op, 0);
8794               scale_rtx = XEXP (op, 1);
8795               break;
8796
8797             case UNSPEC:
8798               if (XINT (op, 1) == UNSPEC_TP
8799                   && TARGET_TLS_DIRECT_SEG_REFS
8800                   && seg == SEG_DEFAULT)
8801                 seg = TARGET_64BIT ? SEG_FS : SEG_GS;
8802               else
8803                 return 0;
8804               break;
8805
8806             case REG:
8807             case SUBREG:
8808               if (!base)
8809                 base = op;
8810               else if (!index)
8811                 index = op;
8812               else
8813                 return 0;
8814               break;
8815
8816             case CONST:
8817             case CONST_INT:
8818             case SYMBOL_REF:
8819             case LABEL_REF:
8820               if (disp)
8821                 return 0;
8822               disp = op;
8823               break;
8824
8825             default:
8826               return 0;
8827             }
8828         }
8829     }
8830   else if (GET_CODE (addr) == MULT)
8831     {
8832       index = XEXP (addr, 0);           /* index*scale */
8833       scale_rtx = XEXP (addr, 1);
8834     }
8835   else if (GET_CODE (addr) == ASHIFT)
8836     {
8837       rtx tmp;
8838
8839       /* We're called for lea too, which implements ashift on occasion.  */
8840       index = XEXP (addr, 0);
8841       tmp = XEXP (addr, 1);
8842       if (!CONST_INT_P (tmp))
8843         return 0;
8844       scale = INTVAL (tmp);
8845       if ((unsigned HOST_WIDE_INT) scale > 3)
8846         return 0;
8847       scale = 1 << scale;
8848       retval = -1;
8849     }
8850   else
8851     disp = addr;                        /* displacement */
8852
8853   /* Extract the integral value of scale.  */
8854   if (scale_rtx)
8855     {
8856       if (!CONST_INT_P (scale_rtx))
8857         return 0;
8858       scale = INTVAL (scale_rtx);
8859     }
8860
8861   base_reg = base && GET_CODE (base) == SUBREG ? SUBREG_REG (base) : base;
8862   index_reg = index && GET_CODE (index) == SUBREG ? SUBREG_REG (index) : index;
8863
8864   /* Allow arg pointer and stack pointer as index if there is not scaling.  */
8865   if (base_reg && index_reg && scale == 1
8866       && (index_reg == arg_pointer_rtx
8867           || index_reg == frame_pointer_rtx
8868           || (REG_P (index_reg) && REGNO (index_reg) == STACK_POINTER_REGNUM)))
8869     {
8870       rtx tmp;
8871       tmp = base, base = index, index = tmp;
8872       tmp = base_reg, base_reg = index_reg, index_reg = tmp;
8873     }
8874
8875   /* Special case: %ebp cannot be encoded as a base without a displacement.  */
8876   if ((base_reg == hard_frame_pointer_rtx
8877        || base_reg == frame_pointer_rtx
8878        || base_reg == arg_pointer_rtx) && !disp)
8879     disp = const0_rtx;
8880
8881   /* Special case: on K6, [%esi] makes the instruction vector decoded.
8882      Avoid this by transforming to [%esi+0].
8883      Reload calls address legitimization without cfun defined, so we need
8884      to test cfun for being non-NULL. */
8885   if (TARGET_K6 && cfun && optimize_function_for_speed_p (cfun)
8886       && base_reg && !index_reg && !disp
8887       && REG_P (base_reg) && REGNO (base_reg) == SI_REG)
8888     disp = const0_rtx;
8889
8890   /* Special case: encode reg+reg instead of reg*2.  */
8891   if (!base && index && scale && scale == 2)
8892     base = index, base_reg = index_reg, scale = 1;
8893
8894   /* Special case: scaling cannot be encoded without base or displacement.  */
8895   if (!base && !disp && index && scale != 1)
8896     disp = const0_rtx;
8897
8898   out->base = base;
8899   out->index = index;
8900   out->disp = disp;
8901   out->scale = scale;
8902   out->seg = seg;
8903
8904   return retval;
8905 }
8906 \f
8907 /* Return cost of the memory address x.
8908    For i386, it is better to use a complex address than let gcc copy
8909    the address into a reg and make a new pseudo.  But not if the address
8910    requires to two regs - that would mean more pseudos with longer
8911    lifetimes.  */
8912 static int
8913 ix86_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED)
8914 {
8915   struct ix86_address parts;
8916   int cost = 1;
8917   int ok = ix86_decompose_address (x, &parts);
8918
8919   gcc_assert (ok);
8920
8921   if (parts.base && GET_CODE (parts.base) == SUBREG)
8922     parts.base = SUBREG_REG (parts.base);
8923   if (parts.index && GET_CODE (parts.index) == SUBREG)
8924     parts.index = SUBREG_REG (parts.index);
8925
8926   /* Attempt to minimize number of registers in the address.  */
8927   if ((parts.base
8928        && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER))
8929       || (parts.index
8930           && (!REG_P (parts.index)
8931               || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)))
8932     cost++;
8933
8934   if (parts.base
8935       && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER)
8936       && parts.index
8937       && (!REG_P (parts.index) || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)
8938       && parts.base != parts.index)
8939     cost++;
8940
8941   /* AMD-K6 don't like addresses with ModR/M set to 00_xxx_100b,
8942      since it's predecode logic can't detect the length of instructions
8943      and it degenerates to vector decoded.  Increase cost of such
8944      addresses here.  The penalty is minimally 2 cycles.  It may be worthwhile
8945      to split such addresses or even refuse such addresses at all.
8946
8947      Following addressing modes are affected:
8948       [base+scale*index]
8949       [scale*index+disp]
8950       [base+index]
8951
8952      The first and last case  may be avoidable by explicitly coding the zero in
8953      memory address, but I don't have AMD-K6 machine handy to check this
8954      theory.  */
8955
8956   if (TARGET_K6
8957       && ((!parts.disp && parts.base && parts.index && parts.scale != 1)
8958           || (parts.disp && !parts.base && parts.index && parts.scale != 1)
8959           || (!parts.disp && parts.base && parts.index && parts.scale == 1)))
8960     cost += 10;
8961
8962   return cost;
8963 }
8964 \f
8965 /* Allow {LABEL | SYMBOL}_REF - SYMBOL_REF-FOR-PICBASE for Mach-O as
8966    this is used for to form addresses to local data when -fPIC is in
8967    use.  */
8968
8969 static bool
8970 darwin_local_data_pic (rtx disp)
8971 {
8972   return (GET_CODE (disp) == UNSPEC
8973           && XINT (disp, 1) == UNSPEC_MACHOPIC_OFFSET);
8974 }
8975
8976 /* Determine if a given RTX is a valid constant.  We already know this
8977    satisfies CONSTANT_P.  */
8978
8979 bool
8980 legitimate_constant_p (rtx x)
8981 {
8982   switch (GET_CODE (x))
8983     {
8984     case CONST:
8985       x = XEXP (x, 0);
8986
8987       if (GET_CODE (x) == PLUS)
8988         {
8989           if (!CONST_INT_P (XEXP (x, 1)))
8990             return false;
8991           x = XEXP (x, 0);
8992         }
8993
8994       if (TARGET_MACHO && darwin_local_data_pic (x))
8995         return true;
8996
8997       /* Only some unspecs are valid as "constants".  */
8998       if (GET_CODE (x) == UNSPEC)
8999         switch (XINT (x, 1))
9000           {
9001           case UNSPEC_GOT:
9002           case UNSPEC_GOTOFF:
9003           case UNSPEC_PLTOFF:
9004             return TARGET_64BIT;
9005           case UNSPEC_TPOFF:
9006           case UNSPEC_NTPOFF:
9007             x = XVECEXP (x, 0, 0);
9008             return (GET_CODE (x) == SYMBOL_REF
9009                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
9010           case UNSPEC_DTPOFF:
9011             x = XVECEXP (x, 0, 0);
9012             return (GET_CODE (x) == SYMBOL_REF
9013                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC);
9014           default:
9015             return false;
9016           }
9017
9018       /* We must have drilled down to a symbol.  */
9019       if (GET_CODE (x) == LABEL_REF)
9020         return true;
9021       if (GET_CODE (x) != SYMBOL_REF)
9022         return false;
9023       /* FALLTHRU */
9024
9025     case SYMBOL_REF:
9026       /* TLS symbols are never valid.  */
9027       if (SYMBOL_REF_TLS_MODEL (x))
9028         return false;
9029
9030       /* DLLIMPORT symbols are never valid.  */
9031       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
9032           && SYMBOL_REF_DLLIMPORT_P (x))
9033         return false;
9034       break;
9035
9036     case CONST_DOUBLE:
9037       if (GET_MODE (x) == TImode
9038           && x != CONST0_RTX (TImode)
9039           && !TARGET_64BIT)
9040         return false;
9041       break;
9042
9043     case CONST_VECTOR:
9044       if (x == CONST0_RTX (GET_MODE (x)))
9045         return true;
9046       return false;
9047
9048     default:
9049       break;
9050     }
9051
9052   /* Otherwise we handle everything else in the move patterns.  */
9053   return true;
9054 }
9055
9056 /* Determine if it's legal to put X into the constant pool.  This
9057    is not possible for the address of thread-local symbols, which
9058    is checked above.  */
9059
9060 static bool
9061 ix86_cannot_force_const_mem (rtx x)
9062 {
9063   /* We can always put integral constants and vectors in memory.  */
9064   switch (GET_CODE (x))
9065     {
9066     case CONST_INT:
9067     case CONST_DOUBLE:
9068     case CONST_VECTOR:
9069       return false;
9070
9071     default:
9072       break;
9073     }
9074   return !legitimate_constant_p (x);
9075 }
9076
9077 /* Determine if a given RTX is a valid constant address.  */
9078
9079 bool
9080 constant_address_p (rtx x)
9081 {
9082   return CONSTANT_P (x) && legitimate_address_p (Pmode, x, 1);
9083 }
9084
9085 /* Nonzero if the constant value X is a legitimate general operand
9086    when generating PIC code.  It is given that flag_pic is on and
9087    that X satisfies CONSTANT_P or is a CONST_DOUBLE.  */
9088
9089 bool
9090 legitimate_pic_operand_p (rtx x)
9091 {
9092   rtx inner;
9093
9094   switch (GET_CODE (x))
9095     {
9096     case CONST:
9097       inner = XEXP (x, 0);
9098       if (GET_CODE (inner) == PLUS
9099           && CONST_INT_P (XEXP (inner, 1)))
9100         inner = XEXP (inner, 0);
9101
9102       /* Only some unspecs are valid as "constants".  */
9103       if (GET_CODE (inner) == UNSPEC)
9104         switch (XINT (inner, 1))
9105           {
9106           case UNSPEC_GOT:
9107           case UNSPEC_GOTOFF:
9108           case UNSPEC_PLTOFF:
9109             return TARGET_64BIT;
9110           case UNSPEC_TPOFF:
9111             x = XVECEXP (inner, 0, 0);
9112             return (GET_CODE (x) == SYMBOL_REF
9113                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
9114           case UNSPEC_MACHOPIC_OFFSET:
9115             return legitimate_pic_address_disp_p (x);
9116           default:
9117             return false;
9118           }
9119       /* FALLTHRU */
9120
9121     case SYMBOL_REF:
9122     case LABEL_REF:
9123       return legitimate_pic_address_disp_p (x);
9124
9125     default:
9126       return true;
9127     }
9128 }
9129
9130 /* Determine if a given CONST RTX is a valid memory displacement
9131    in PIC mode.  */
9132
9133 int
9134 legitimate_pic_address_disp_p (rtx disp)
9135 {
9136   bool saw_plus;
9137
9138   /* In 64bit mode we can allow direct addresses of symbols and labels
9139      when they are not dynamic symbols.  */
9140   if (TARGET_64BIT)
9141     {
9142       rtx op0 = disp, op1;
9143
9144       switch (GET_CODE (disp))
9145         {
9146         case LABEL_REF:
9147           return true;
9148
9149         case CONST:
9150           if (GET_CODE (XEXP (disp, 0)) != PLUS)
9151             break;
9152           op0 = XEXP (XEXP (disp, 0), 0);
9153           op1 = XEXP (XEXP (disp, 0), 1);
9154           if (!CONST_INT_P (op1)
9155               || INTVAL (op1) >= 16*1024*1024
9156               || INTVAL (op1) < -16*1024*1024)
9157             break;
9158           if (GET_CODE (op0) == LABEL_REF)
9159             return true;
9160           if (GET_CODE (op0) != SYMBOL_REF)
9161             break;
9162           /* FALLTHRU */
9163
9164         case SYMBOL_REF:
9165           /* TLS references should always be enclosed in UNSPEC.  */
9166           if (SYMBOL_REF_TLS_MODEL (op0))
9167             return false;
9168           if (!SYMBOL_REF_FAR_ADDR_P (op0) && SYMBOL_REF_LOCAL_P (op0)
9169               && ix86_cmodel != CM_LARGE_PIC)
9170             return true;
9171           break;
9172
9173         default:
9174           break;
9175         }
9176     }
9177   if (GET_CODE (disp) != CONST)
9178     return 0;
9179   disp = XEXP (disp, 0);
9180
9181   if (TARGET_64BIT)
9182     {
9183       /* We are unsafe to allow PLUS expressions.  This limit allowed distance
9184          of GOT tables.  We should not need these anyway.  */
9185       if (GET_CODE (disp) != UNSPEC
9186           || (XINT (disp, 1) != UNSPEC_GOTPCREL
9187               && XINT (disp, 1) != UNSPEC_GOTOFF
9188               && XINT (disp, 1) != UNSPEC_PLTOFF))
9189         return 0;
9190
9191       if (GET_CODE (XVECEXP (disp, 0, 0)) != SYMBOL_REF
9192           && GET_CODE (XVECEXP (disp, 0, 0)) != LABEL_REF)
9193         return 0;
9194       return 1;
9195     }
9196
9197   saw_plus = false;
9198   if (GET_CODE (disp) == PLUS)
9199     {
9200       if (!CONST_INT_P (XEXP (disp, 1)))
9201         return 0;
9202       disp = XEXP (disp, 0);
9203       saw_plus = true;
9204     }
9205
9206   if (TARGET_MACHO && darwin_local_data_pic (disp))
9207     return 1;
9208
9209   if (GET_CODE (disp) != UNSPEC)
9210     return 0;
9211
9212   switch (XINT (disp, 1))
9213     {
9214     case UNSPEC_GOT:
9215       if (saw_plus)
9216         return false;
9217       /* We need to check for both symbols and labels because VxWorks loads
9218          text labels with @GOT rather than @GOTOFF.  See gotoff_operand for
9219          details.  */
9220       return (GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
9221               || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF);
9222     case UNSPEC_GOTOFF:
9223       /* Refuse GOTOFF in 64bit mode since it is always 64bit when used.
9224          While ABI specify also 32bit relocation but we don't produce it in
9225          small PIC model at all.  */
9226       if ((GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
9227            || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF)
9228           && !TARGET_64BIT)
9229         return gotoff_operand (XVECEXP (disp, 0, 0), Pmode);
9230       return false;
9231     case UNSPEC_GOTTPOFF:
9232     case UNSPEC_GOTNTPOFF:
9233     case UNSPEC_INDNTPOFF:
9234       if (saw_plus)
9235         return false;
9236       disp = XVECEXP (disp, 0, 0);
9237       return (GET_CODE (disp) == SYMBOL_REF
9238               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_INITIAL_EXEC);
9239     case UNSPEC_NTPOFF:
9240       disp = XVECEXP (disp, 0, 0);
9241       return (GET_CODE (disp) == SYMBOL_REF
9242               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_EXEC);
9243     case UNSPEC_DTPOFF:
9244       disp = XVECEXP (disp, 0, 0);
9245       return (GET_CODE (disp) == SYMBOL_REF
9246               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_DYNAMIC);
9247     }
9248
9249   return 0;
9250 }
9251
9252 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression that is a valid
9253    memory address for an instruction.  The MODE argument is the machine mode
9254    for the MEM expression that wants to use this address.
9255
9256    It only recognizes address in canonical form.  LEGITIMIZE_ADDRESS should
9257    convert common non-canonical forms to canonical form so that they will
9258    be recognized.  */
9259
9260 int
9261 legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
9262                       rtx addr, int strict)
9263 {
9264   struct ix86_address parts;
9265   rtx base, index, disp;
9266   HOST_WIDE_INT scale;
9267   const char *reason = NULL;
9268   rtx reason_rtx = NULL_RTX;
9269
9270   if (ix86_decompose_address (addr, &parts) <= 0)
9271     {
9272       reason = "decomposition failed";
9273       goto report_error;
9274     }
9275
9276   base = parts.base;
9277   index = parts.index;
9278   disp = parts.disp;
9279   scale = parts.scale;
9280
9281   /* Validate base register.
9282
9283      Don't allow SUBREG's that span more than a word here.  It can lead to spill
9284      failures when the base is one word out of a two word structure, which is
9285      represented internally as a DImode int.  */
9286
9287   if (base)
9288     {
9289       rtx reg;
9290       reason_rtx = base;
9291
9292       if (REG_P (base))
9293         reg = base;
9294       else if (GET_CODE (base) == SUBREG
9295                && REG_P (SUBREG_REG (base))
9296                && GET_MODE_SIZE (GET_MODE (SUBREG_REG (base)))
9297                   <= UNITS_PER_WORD)
9298         reg = SUBREG_REG (base);
9299       else
9300         {
9301           reason = "base is not a register";
9302           goto report_error;
9303         }
9304
9305       if (GET_MODE (base) != Pmode)
9306         {
9307           reason = "base is not in Pmode";
9308           goto report_error;
9309         }
9310
9311       if ((strict && ! REG_OK_FOR_BASE_STRICT_P (reg))
9312           || (! strict && ! REG_OK_FOR_BASE_NONSTRICT_P (reg)))
9313         {
9314           reason = "base is not valid";
9315           goto report_error;
9316         }
9317     }
9318
9319   /* Validate index register.
9320
9321      Don't allow SUBREG's that span more than a word here -- same as above.  */
9322
9323   if (index)
9324     {
9325       rtx reg;
9326       reason_rtx = index;
9327
9328       if (REG_P (index))
9329         reg = index;
9330       else if (GET_CODE (index) == SUBREG
9331                && REG_P (SUBREG_REG (index))
9332                && GET_MODE_SIZE (GET_MODE (SUBREG_REG (index)))
9333                   <= UNITS_PER_WORD)
9334         reg = SUBREG_REG (index);
9335       else
9336         {
9337           reason = "index is not a register";
9338           goto report_error;
9339         }
9340
9341       if (GET_MODE (index) != Pmode)
9342         {
9343           reason = "index is not in Pmode";
9344           goto report_error;
9345         }
9346
9347       if ((strict && ! REG_OK_FOR_INDEX_STRICT_P (reg))
9348           || (! strict && ! REG_OK_FOR_INDEX_NONSTRICT_P (reg)))
9349         {
9350           reason = "index is not valid";
9351           goto report_error;
9352         }
9353     }
9354
9355   /* Validate scale factor.  */
9356   if (scale != 1)
9357     {
9358       reason_rtx = GEN_INT (scale);
9359       if (!index)
9360         {
9361           reason = "scale without index";
9362           goto report_error;
9363         }
9364
9365       if (scale != 2 && scale != 4 && scale != 8)
9366         {
9367           reason = "scale is not a valid multiplier";
9368           goto report_error;
9369         }
9370     }
9371
9372   /* Validate displacement.  */
9373   if (disp)
9374     {
9375       reason_rtx = disp;
9376
9377       if (GET_CODE (disp) == CONST
9378           && GET_CODE (XEXP (disp, 0)) == UNSPEC
9379           && XINT (XEXP (disp, 0), 1) != UNSPEC_MACHOPIC_OFFSET)
9380         switch (XINT (XEXP (disp, 0), 1))
9381           {
9382           /* Refuse GOTOFF and GOT in 64bit mode since it is always 64bit when
9383              used.  While ABI specify also 32bit relocations, we don't produce
9384              them at all and use IP relative instead.  */
9385           case UNSPEC_GOT:
9386           case UNSPEC_GOTOFF:
9387             gcc_assert (flag_pic);
9388             if (!TARGET_64BIT)
9389               goto is_legitimate_pic;
9390             reason = "64bit address unspec";
9391             goto report_error;
9392
9393           case UNSPEC_GOTPCREL:
9394             gcc_assert (flag_pic);
9395             goto is_legitimate_pic;
9396
9397           case UNSPEC_GOTTPOFF:
9398           case UNSPEC_GOTNTPOFF:
9399           case UNSPEC_INDNTPOFF:
9400           case UNSPEC_NTPOFF:
9401           case UNSPEC_DTPOFF:
9402             break;
9403
9404           default:
9405             reason = "invalid address unspec";
9406             goto report_error;
9407           }
9408
9409       else if (SYMBOLIC_CONST (disp)
9410                && (flag_pic
9411                    || (TARGET_MACHO
9412 #if TARGET_MACHO
9413                        && MACHOPIC_INDIRECT
9414                        && !machopic_operand_p (disp)
9415 #endif
9416                )))
9417         {
9418
9419         is_legitimate_pic:
9420           if (TARGET_64BIT && (index || base))
9421             {
9422               /* foo@dtpoff(%rX) is ok.  */
9423               if (GET_CODE (disp) != CONST
9424                   || GET_CODE (XEXP (disp, 0)) != PLUS
9425                   || GET_CODE (XEXP (XEXP (disp, 0), 0)) != UNSPEC
9426                   || !CONST_INT_P (XEXP (XEXP (disp, 0), 1))
9427                   || (XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_DTPOFF
9428                       && XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_NTPOFF))
9429                 {
9430                   reason = "non-constant pic memory reference";
9431                   goto report_error;
9432                 }
9433             }
9434           else if (! legitimate_pic_address_disp_p (disp))
9435             {
9436               reason = "displacement is an invalid pic construct";
9437               goto report_error;
9438             }
9439
9440           /* This code used to verify that a symbolic pic displacement
9441              includes the pic_offset_table_rtx register.
9442
9443              While this is good idea, unfortunately these constructs may
9444              be created by "adds using lea" optimization for incorrect
9445              code like:
9446
9447              int a;
9448              int foo(int i)
9449                {
9450                  return *(&a+i);
9451                }
9452
9453              This code is nonsensical, but results in addressing
9454              GOT table with pic_offset_table_rtx base.  We can't
9455              just refuse it easily, since it gets matched by
9456              "addsi3" pattern, that later gets split to lea in the
9457              case output register differs from input.  While this
9458              can be handled by separate addsi pattern for this case
9459              that never results in lea, this seems to be easier and
9460              correct fix for crash to disable this test.  */
9461         }
9462       else if (GET_CODE (disp) != LABEL_REF
9463                && !CONST_INT_P (disp)
9464                && (GET_CODE (disp) != CONST
9465                    || !legitimate_constant_p (disp))
9466                && (GET_CODE (disp) != SYMBOL_REF
9467                    || !legitimate_constant_p (disp)))
9468         {
9469           reason = "displacement is not constant";
9470           goto report_error;
9471         }
9472       else if (TARGET_64BIT
9473                && !x86_64_immediate_operand (disp, VOIDmode))
9474         {
9475           reason = "displacement is out of range";
9476           goto report_error;
9477         }
9478     }
9479
9480   /* Everything looks valid.  */
9481   return TRUE;
9482
9483  report_error:
9484   return FALSE;
9485 }
9486 \f
9487 /* Return a unique alias set for the GOT.  */
9488
9489 static alias_set_type
9490 ix86_GOT_alias_set (void)
9491 {
9492   static alias_set_type set = -1;
9493   if (set == -1)
9494     set = new_alias_set ();
9495   return set;
9496 }
9497
9498 /* Return a legitimate reference for ORIG (an address) using the
9499    register REG.  If REG is 0, a new pseudo is generated.
9500
9501    There are two types of references that must be handled:
9502
9503    1. Global data references must load the address from the GOT, via
9504       the PIC reg.  An insn is emitted to do this load, and the reg is
9505       returned.
9506
9507    2. Static data references, constant pool addresses, and code labels
9508       compute the address as an offset from the GOT, whose base is in
9509       the PIC reg.  Static data objects have SYMBOL_FLAG_LOCAL set to
9510       differentiate them from global data objects.  The returned
9511       address is the PIC reg + an unspec constant.
9512
9513    GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
9514    reg also appears in the address.  */
9515
9516 static rtx
9517 legitimize_pic_address (rtx orig, rtx reg)
9518 {
9519   rtx addr = orig;
9520   rtx new_rtx = orig;
9521   rtx base;
9522
9523 #if TARGET_MACHO
9524   if (TARGET_MACHO && !TARGET_64BIT)
9525     {
9526       if (reg == 0)
9527         reg = gen_reg_rtx (Pmode);
9528       /* Use the generic Mach-O PIC machinery.  */
9529       return machopic_legitimize_pic_address (orig, GET_MODE (orig), reg);
9530     }
9531 #endif
9532
9533   if (TARGET_64BIT && legitimate_pic_address_disp_p (addr))
9534     new_rtx = addr;
9535   else if (TARGET_64BIT
9536            && ix86_cmodel != CM_SMALL_PIC
9537            && gotoff_operand (addr, Pmode))
9538     {
9539       rtx tmpreg;
9540       /* This symbol may be referenced via a displacement from the PIC
9541          base address (@GOTOFF).  */
9542
9543       if (reload_in_progress)
9544         df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9545       if (GET_CODE (addr) == CONST)
9546         addr = XEXP (addr, 0);
9547       if (GET_CODE (addr) == PLUS)
9548           {
9549             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
9550                                       UNSPEC_GOTOFF);
9551             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
9552           }
9553         else
9554           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
9555       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9556       if (!reg)
9557         tmpreg = gen_reg_rtx (Pmode);
9558       else
9559         tmpreg = reg;
9560       emit_move_insn (tmpreg, new_rtx);
9561
9562       if (reg != 0)
9563         {
9564           new_rtx = expand_simple_binop (Pmode, PLUS, reg, pic_offset_table_rtx,
9565                                          tmpreg, 1, OPTAB_DIRECT);
9566           new_rtx = reg;
9567         }
9568       else new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, tmpreg);
9569     }
9570   else if (!TARGET_64BIT && gotoff_operand (addr, Pmode))
9571     {
9572       /* This symbol may be referenced via a displacement from the PIC
9573          base address (@GOTOFF).  */
9574
9575       if (reload_in_progress)
9576         df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9577       if (GET_CODE (addr) == CONST)
9578         addr = XEXP (addr, 0);
9579       if (GET_CODE (addr) == PLUS)
9580           {
9581             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
9582                                       UNSPEC_GOTOFF);
9583             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
9584           }
9585         else
9586           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
9587       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9588       new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
9589
9590       if (reg != 0)
9591         {
9592           emit_move_insn (reg, new_rtx);
9593           new_rtx = reg;
9594         }
9595     }
9596   else if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (addr) == 0)
9597            /* We can't use @GOTOFF for text labels on VxWorks;
9598               see gotoff_operand.  */
9599            || (TARGET_VXWORKS_RTP && GET_CODE (addr) == LABEL_REF))
9600     {
9601       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
9602         {
9603           if (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (addr))
9604             return legitimize_dllimport_symbol (addr, true);
9605           if (GET_CODE (addr) == CONST && GET_CODE (XEXP (addr, 0)) == PLUS
9606               && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF
9607               && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (addr, 0), 0)))
9608             {
9609               rtx t = legitimize_dllimport_symbol (XEXP (XEXP (addr, 0), 0), true);
9610               return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1));
9611             }
9612         }
9613
9614       if (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC)
9615         {
9616           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTPCREL);
9617           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9618           new_rtx = gen_const_mem (Pmode, new_rtx);
9619           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
9620
9621           if (reg == 0)
9622             reg = gen_reg_rtx (Pmode);
9623           /* Use directly gen_movsi, otherwise the address is loaded
9624              into register for CSE.  We don't want to CSE this addresses,
9625              instead we CSE addresses from the GOT table, so skip this.  */
9626           emit_insn (gen_movsi (reg, new_rtx));
9627           new_rtx = reg;
9628         }
9629       else
9630         {
9631           /* This symbol must be referenced via a load from the
9632              Global Offset Table (@GOT).  */
9633
9634           if (reload_in_progress)
9635             df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9636           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT);
9637           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9638           if (TARGET_64BIT)
9639             new_rtx = force_reg (Pmode, new_rtx);
9640           new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
9641           new_rtx = gen_const_mem (Pmode, new_rtx);
9642           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
9643
9644           if (reg == 0)
9645             reg = gen_reg_rtx (Pmode);
9646           emit_move_insn (reg, new_rtx);
9647           new_rtx = reg;
9648         }
9649     }
9650   else
9651     {
9652       if (CONST_INT_P (addr)
9653           && !x86_64_immediate_operand (addr, VOIDmode))
9654         {
9655           if (reg)
9656             {
9657               emit_move_insn (reg, addr);
9658               new_rtx = reg;
9659             }
9660           else
9661             new_rtx = force_reg (Pmode, addr);
9662         }
9663       else if (GET_CODE (addr) == CONST)
9664         {
9665           addr = XEXP (addr, 0);
9666
9667           /* We must match stuff we generate before.  Assume the only
9668              unspecs that can get here are ours.  Not that we could do
9669              anything with them anyway....  */
9670           if (GET_CODE (addr) == UNSPEC
9671               || (GET_CODE (addr) == PLUS
9672                   && GET_CODE (XEXP (addr, 0)) == UNSPEC))
9673             return orig;
9674           gcc_assert (GET_CODE (addr) == PLUS);
9675         }
9676       if (GET_CODE (addr) == PLUS)
9677         {
9678           rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1);
9679
9680           /* Check first to see if this is a constant offset from a @GOTOFF
9681              symbol reference.  */
9682           if (gotoff_operand (op0, Pmode)
9683               && CONST_INT_P (op1))
9684             {
9685               if (!TARGET_64BIT)
9686                 {
9687                   if (reload_in_progress)
9688                     df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9689                   new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op0),
9690                                             UNSPEC_GOTOFF);
9691                   new_rtx = gen_rtx_PLUS (Pmode, new_rtx, op1);
9692                   new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9693                   new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
9694
9695                   if (reg != 0)
9696                     {
9697                       emit_move_insn (reg, new_rtx);
9698                       new_rtx = reg;
9699                     }
9700                 }
9701               else
9702                 {
9703                   if (INTVAL (op1) < -16*1024*1024
9704                       || INTVAL (op1) >= 16*1024*1024)
9705                     {
9706                       if (!x86_64_immediate_operand (op1, Pmode))
9707                         op1 = force_reg (Pmode, op1);
9708                       new_rtx = gen_rtx_PLUS (Pmode, force_reg (Pmode, op0), op1);
9709                     }
9710                 }
9711             }
9712           else
9713             {
9714               base = legitimize_pic_address (XEXP (addr, 0), reg);
9715               new_rtx  = legitimize_pic_address (XEXP (addr, 1),
9716                                                  base == reg ? NULL_RTX : reg);
9717
9718               if (CONST_INT_P (new_rtx))
9719                 new_rtx = plus_constant (base, INTVAL (new_rtx));
9720               else
9721                 {
9722                   if (GET_CODE (new_rtx) == PLUS && CONSTANT_P (XEXP (new_rtx, 1)))
9723                     {
9724                       base = gen_rtx_PLUS (Pmode, base, XEXP (new_rtx, 0));
9725                       new_rtx = XEXP (new_rtx, 1);
9726                     }
9727                   new_rtx = gen_rtx_PLUS (Pmode, base, new_rtx);
9728                 }
9729             }
9730         }
9731     }
9732   return new_rtx;
9733 }
9734 \f
9735 /* Load the thread pointer.  If TO_REG is true, force it into a register.  */
9736
9737 static rtx
9738 get_thread_pointer (int to_reg)
9739 {
9740   rtx tp, reg, insn;
9741
9742   tp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), UNSPEC_TP);
9743   if (!to_reg)
9744     return tp;
9745
9746   reg = gen_reg_rtx (Pmode);
9747   insn = gen_rtx_SET (VOIDmode, reg, tp);
9748   insn = emit_insn (insn);
9749
9750   return reg;
9751 }
9752
9753 /* A subroutine of legitimize_address and ix86_expand_move.  FOR_MOV is
9754    false if we expect this to be used for a memory address and true if
9755    we expect to load the address into a register.  */
9756
9757 static rtx
9758 legitimize_tls_address (rtx x, enum tls_model model, int for_mov)
9759 {
9760   rtx dest, base, off, pic, tp;
9761   int type;
9762
9763   switch (model)
9764     {
9765     case TLS_MODEL_GLOBAL_DYNAMIC:
9766       dest = gen_reg_rtx (Pmode);
9767       tp = TARGET_GNU2_TLS ? get_thread_pointer (1) : 0;
9768
9769       if (TARGET_64BIT && ! TARGET_GNU2_TLS)
9770         {
9771           rtx rax = gen_rtx_REG (Pmode, AX_REG), insns;
9772
9773           start_sequence ();
9774           emit_call_insn (gen_tls_global_dynamic_64 (rax, x));
9775           insns = get_insns ();
9776           end_sequence ();
9777
9778           RTL_CONST_CALL_P (insns) = 1;
9779           emit_libcall_block (insns, dest, rax, x);
9780         }
9781       else if (TARGET_64BIT && TARGET_GNU2_TLS)
9782         emit_insn (gen_tls_global_dynamic_64 (dest, x));
9783       else
9784         emit_insn (gen_tls_global_dynamic_32 (dest, x));
9785
9786       if (TARGET_GNU2_TLS)
9787         {
9788           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, tp, dest));
9789
9790           set_unique_reg_note (get_last_insn (), REG_EQUIV, x);
9791         }
9792       break;
9793
9794     case TLS_MODEL_LOCAL_DYNAMIC:
9795       base = gen_reg_rtx (Pmode);
9796       tp = TARGET_GNU2_TLS ? get_thread_pointer (1) : 0;
9797
9798       if (TARGET_64BIT && ! TARGET_GNU2_TLS)
9799         {
9800           rtx rax = gen_rtx_REG (Pmode, AX_REG), insns, note;
9801
9802           start_sequence ();
9803           emit_call_insn (gen_tls_local_dynamic_base_64 (rax));
9804           insns = get_insns ();
9805           end_sequence ();
9806
9807           note = gen_rtx_EXPR_LIST (VOIDmode, const0_rtx, NULL);
9808           note = gen_rtx_EXPR_LIST (VOIDmode, ix86_tls_get_addr (), note);
9809           RTL_CONST_CALL_P (insns) = 1;
9810           emit_libcall_block (insns, base, rax, note);
9811         }
9812       else if (TARGET_64BIT && TARGET_GNU2_TLS)
9813         emit_insn (gen_tls_local_dynamic_base_64 (base));
9814       else
9815         emit_insn (gen_tls_local_dynamic_base_32 (base));
9816
9817       if (TARGET_GNU2_TLS)
9818         {
9819           rtx x = ix86_tls_module_base ();
9820
9821           set_unique_reg_note (get_last_insn (), REG_EQUIV,
9822                                gen_rtx_MINUS (Pmode, x, tp));
9823         }
9824
9825       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPOFF);
9826       off = gen_rtx_CONST (Pmode, off);
9827
9828       dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, off));
9829
9830       if (TARGET_GNU2_TLS)
9831         {
9832           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, dest, tp));
9833
9834           set_unique_reg_note (get_last_insn (), REG_EQUIV, x);
9835         }
9836
9837       break;
9838
9839     case TLS_MODEL_INITIAL_EXEC:
9840       if (TARGET_64BIT)
9841         {
9842           pic = NULL;
9843           type = UNSPEC_GOTNTPOFF;
9844         }
9845       else if (flag_pic)
9846         {
9847           if (reload_in_progress)
9848             df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9849           pic = pic_offset_table_rtx;
9850           type = TARGET_ANY_GNU_TLS ? UNSPEC_GOTNTPOFF : UNSPEC_GOTTPOFF;
9851         }
9852       else if (!TARGET_ANY_GNU_TLS)
9853         {
9854           pic = gen_reg_rtx (Pmode);
9855           emit_insn (gen_set_got (pic));
9856           type = UNSPEC_GOTTPOFF;
9857         }
9858       else
9859         {
9860           pic = NULL;
9861           type = UNSPEC_INDNTPOFF;
9862         }
9863
9864       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), type);
9865       off = gen_rtx_CONST (Pmode, off);
9866       if (pic)
9867         off = gen_rtx_PLUS (Pmode, pic, off);
9868       off = gen_const_mem (Pmode, off);
9869       set_mem_alias_set (off, ix86_GOT_alias_set ());
9870
9871       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
9872         {
9873           base = get_thread_pointer (for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
9874           off = force_reg (Pmode, off);
9875           return gen_rtx_PLUS (Pmode, base, off);
9876         }
9877       else
9878         {
9879           base = get_thread_pointer (true);
9880           dest = gen_reg_rtx (Pmode);
9881           emit_insn (gen_subsi3 (dest, base, off));
9882         }
9883       break;
9884
9885     case TLS_MODEL_LOCAL_EXEC:
9886       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x),
9887                             (TARGET_64BIT || TARGET_ANY_GNU_TLS)
9888                             ? UNSPEC_NTPOFF : UNSPEC_TPOFF);
9889       off = gen_rtx_CONST (Pmode, off);
9890
9891       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
9892         {
9893           base = get_thread_pointer (for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
9894           return gen_rtx_PLUS (Pmode, base, off);
9895         }
9896       else
9897         {
9898           base = get_thread_pointer (true);
9899           dest = gen_reg_rtx (Pmode);
9900           emit_insn (gen_subsi3 (dest, base, off));
9901         }
9902       break;
9903
9904     default:
9905       gcc_unreachable ();
9906     }
9907
9908   return dest;
9909 }
9910
9911 /* Create or return the unique __imp_DECL dllimport symbol corresponding
9912    to symbol DECL.  */
9913
9914 static GTY((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
9915   htab_t dllimport_map;
9916
9917 static tree
9918 get_dllimport_decl (tree decl)
9919 {
9920   struct tree_map *h, in;
9921   void **loc;
9922   const char *name;
9923   const char *prefix;
9924   size_t namelen, prefixlen;
9925   char *imp_name;
9926   tree to;
9927   rtx rtl;
9928
9929   if (!dllimport_map)
9930     dllimport_map = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
9931
9932   in.hash = htab_hash_pointer (decl);
9933   in.base.from = decl;
9934   loc = htab_find_slot_with_hash (dllimport_map, &in, in.hash, INSERT);
9935   h = (struct tree_map *) *loc;
9936   if (h)
9937     return h->to;
9938
9939   *loc = h = GGC_NEW (struct tree_map);
9940   h->hash = in.hash;
9941   h->base.from = decl;
9942   h->to = to = build_decl (VAR_DECL, NULL, ptr_type_node);
9943   DECL_ARTIFICIAL (to) = 1;
9944   DECL_IGNORED_P (to) = 1;
9945   DECL_EXTERNAL (to) = 1;
9946   TREE_READONLY (to) = 1;
9947
9948   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
9949   name = targetm.strip_name_encoding (name);
9950   prefix = name[0] == FASTCALL_PREFIX || user_label_prefix[0] == 0
9951     ? "*__imp_" : "*__imp__";
9952   namelen = strlen (name);
9953   prefixlen = strlen (prefix);
9954   imp_name = (char *) alloca (namelen + prefixlen + 1);
9955   memcpy (imp_name, prefix, prefixlen);
9956   memcpy (imp_name + prefixlen, name, namelen + 1);
9957
9958   name = ggc_alloc_string (imp_name, namelen + prefixlen);
9959   rtl = gen_rtx_SYMBOL_REF (Pmode, name);
9960   SET_SYMBOL_REF_DECL (rtl, to);
9961   SYMBOL_REF_FLAGS (rtl) = SYMBOL_FLAG_LOCAL;
9962
9963   rtl = gen_const_mem (Pmode, rtl);
9964   set_mem_alias_set (rtl, ix86_GOT_alias_set ());
9965
9966   SET_DECL_RTL (to, rtl);
9967   SET_DECL_ASSEMBLER_NAME (to, get_identifier (name));
9968
9969   return to;
9970 }
9971
9972 /* Expand SYMBOL into its corresponding dllimport symbol.  WANT_REG is
9973    true if we require the result be a register.  */
9974
9975 static rtx
9976 legitimize_dllimport_symbol (rtx symbol, bool want_reg)
9977 {
9978   tree imp_decl;
9979   rtx x;
9980
9981   gcc_assert (SYMBOL_REF_DECL (symbol));
9982   imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol));
9983
9984   x = DECL_RTL (imp_decl);
9985   if (want_reg)
9986     x = force_reg (Pmode, x);
9987   return x;
9988 }
9989
9990 /* Try machine-dependent ways of modifying an illegitimate address
9991    to be legitimate.  If we find one, return the new, valid address.
9992    This macro is used in only one place: `memory_address' in explow.c.
9993
9994    OLDX is the address as it was before break_out_memory_refs was called.
9995    In some cases it is useful to look at this to decide what needs to be done.
9996
9997    MODE and WIN are passed so that this macro can use
9998    GO_IF_LEGITIMATE_ADDRESS.
9999
10000    It is always safe for this macro to do nothing.  It exists to recognize
10001    opportunities to optimize the output.
10002
10003    For the 80386, we handle X+REG by loading X into a register R and
10004    using R+REG.  R will go in a general reg and indexing will be used.
10005    However, if REG is a broken-out memory address or multiplication,
10006    nothing needs to be done because REG can certainly go in a general reg.
10007
10008    When -fpic is used, special handling is needed for symbolic references.
10009    See comments by legitimize_pic_address in i386.c for details.  */
10010
10011 rtx
10012 legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, enum machine_mode mode)
10013 {
10014   int changed = 0;
10015   unsigned log;
10016
10017   log = GET_CODE (x) == SYMBOL_REF ? SYMBOL_REF_TLS_MODEL (x) : 0;
10018   if (log)
10019     return legitimize_tls_address (x, (enum tls_model) log, false);
10020   if (GET_CODE (x) == CONST
10021       && GET_CODE (XEXP (x, 0)) == PLUS
10022       && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
10023       && (log = SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0))))
10024     {
10025       rtx t = legitimize_tls_address (XEXP (XEXP (x, 0), 0),
10026                                       (enum tls_model) log, false);
10027       return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
10028     }
10029
10030   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
10031     {
10032       if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (x))
10033         return legitimize_dllimport_symbol (x, true);
10034       if (GET_CODE (x) == CONST
10035           && GET_CODE (XEXP (x, 0)) == PLUS
10036           && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
10037           && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (x, 0), 0)))
10038         {
10039           rtx t = legitimize_dllimport_symbol (XEXP (XEXP (x, 0), 0), true);
10040           return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
10041         }
10042     }
10043
10044   if (flag_pic && SYMBOLIC_CONST (x))
10045     return legitimize_pic_address (x, 0);
10046
10047   /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
10048   if (GET_CODE (x) == ASHIFT
10049       && CONST_INT_P (XEXP (x, 1))
10050       && (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) < 4)
10051     {
10052       changed = 1;
10053       log = INTVAL (XEXP (x, 1));
10054       x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)),
10055                         GEN_INT (1 << log));
10056     }
10057
10058   if (GET_CODE (x) == PLUS)
10059     {
10060       /* Canonicalize shifts by 0, 1, 2, 3 into multiply.  */
10061
10062       if (GET_CODE (XEXP (x, 0)) == ASHIFT
10063           && CONST_INT_P (XEXP (XEXP (x, 0), 1))
10064           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 0), 1)) < 4)
10065         {
10066           changed = 1;
10067           log = INTVAL (XEXP (XEXP (x, 0), 1));
10068           XEXP (x, 0) = gen_rtx_MULT (Pmode,
10069                                       force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
10070                                       GEN_INT (1 << log));
10071         }
10072
10073       if (GET_CODE (XEXP (x, 1)) == ASHIFT
10074           && CONST_INT_P (XEXP (XEXP (x, 1), 1))
10075           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 1), 1)) < 4)
10076         {
10077           changed = 1;
10078           log = INTVAL (XEXP (XEXP (x, 1), 1));
10079           XEXP (x, 1) = gen_rtx_MULT (Pmode,
10080                                       force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
10081                                       GEN_INT (1 << log));
10082         }
10083
10084       /* Put multiply first if it isn't already.  */
10085       if (GET_CODE (XEXP (x, 1)) == MULT)
10086         {
10087           rtx tmp = XEXP (x, 0);
10088           XEXP (x, 0) = XEXP (x, 1);
10089           XEXP (x, 1) = tmp;
10090           changed = 1;
10091         }
10092
10093       /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
10094          into (plus (plus (mult (reg) (const)) (reg)) (const)).  This can be
10095          created by virtual register instantiation, register elimination, and
10096          similar optimizations.  */
10097       if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS)
10098         {
10099           changed = 1;
10100           x = gen_rtx_PLUS (Pmode,
10101                             gen_rtx_PLUS (Pmode, XEXP (x, 0),
10102                                           XEXP (XEXP (x, 1), 0)),
10103                             XEXP (XEXP (x, 1), 1));
10104         }
10105
10106       /* Canonicalize
10107          (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
10108          into (plus (plus (mult (reg) (const)) (reg)) (const)).  */
10109       else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
10110                && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
10111                && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
10112                && CONSTANT_P (XEXP (x, 1)))
10113         {
10114           rtx constant;
10115           rtx other = NULL_RTX;
10116
10117           if (CONST_INT_P (XEXP (x, 1)))
10118             {
10119               constant = XEXP (x, 1);
10120               other = XEXP (XEXP (XEXP (x, 0), 1), 1);
10121             }
10122           else if (CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 1), 1)))
10123             {
10124               constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
10125               other = XEXP (x, 1);
10126             }
10127           else
10128             constant = 0;
10129
10130           if (constant)
10131             {
10132               changed = 1;
10133               x = gen_rtx_PLUS (Pmode,
10134                                 gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 0),
10135                                               XEXP (XEXP (XEXP (x, 0), 1), 0)),
10136                                 plus_constant (other, INTVAL (constant)));
10137             }
10138         }
10139
10140       if (changed && legitimate_address_p (mode, x, FALSE))
10141         return x;
10142
10143       if (GET_CODE (XEXP (x, 0)) == MULT)
10144         {
10145           changed = 1;
10146           XEXP (x, 0) = force_operand (XEXP (x, 0), 0);
10147         }
10148
10149       if (GET_CODE (XEXP (x, 1)) == MULT)
10150         {
10151           changed = 1;
10152           XEXP (x, 1) = force_operand (XEXP (x, 1), 0);
10153         }
10154
10155       if (changed
10156           && REG_P (XEXP (x, 1))
10157           && REG_P (XEXP (x, 0)))
10158         return x;
10159
10160       if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1)))
10161         {
10162           changed = 1;
10163           x = legitimize_pic_address (x, 0);
10164         }
10165
10166       if (changed && legitimate_address_p (mode, x, FALSE))
10167         return x;
10168
10169       if (REG_P (XEXP (x, 0)))
10170         {
10171           rtx temp = gen_reg_rtx (Pmode);
10172           rtx val  = force_operand (XEXP (x, 1), temp);
10173           if (val != temp)
10174             emit_move_insn (temp, val);
10175
10176           XEXP (x, 1) = temp;
10177           return x;
10178         }
10179
10180       else if (REG_P (XEXP (x, 1)))
10181         {
10182           rtx temp = gen_reg_rtx (Pmode);
10183           rtx val  = force_operand (XEXP (x, 0), temp);
10184           if (val != temp)
10185             emit_move_insn (temp, val);
10186
10187           XEXP (x, 0) = temp;
10188           return x;
10189         }
10190     }
10191
10192   return x;
10193 }
10194 \f
10195 /* Print an integer constant expression in assembler syntax.  Addition
10196    and subtraction are the only arithmetic that may appear in these
10197    expressions.  FILE is the stdio stream to write to, X is the rtx, and
10198    CODE is the operand print code from the output string.  */
10199
10200 static void
10201 output_pic_addr_const (FILE *file, rtx x, int code)
10202 {
10203   char buf[256];
10204
10205   switch (GET_CODE (x))
10206     {
10207     case PC:
10208       gcc_assert (flag_pic);
10209       putc ('.', file);
10210       break;
10211
10212     case SYMBOL_REF:
10213       if (! TARGET_MACHO || TARGET_64BIT)
10214         output_addr_const (file, x);
10215       else
10216         {
10217           const char *name = XSTR (x, 0);
10218
10219           /* Mark the decl as referenced so that cgraph will
10220              output the function.  */
10221           if (SYMBOL_REF_DECL (x))
10222             mark_decl_referenced (SYMBOL_REF_DECL (x));
10223
10224 #if TARGET_MACHO
10225           if (MACHOPIC_INDIRECT
10226               && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
10227             name = machopic_indirection_name (x, /*stub_p=*/true);
10228 #endif
10229           assemble_name (file, name);
10230         }
10231       if (!TARGET_MACHO && !(TARGET_64BIT && DEFAULT_ABI == MS_ABI)
10232           && code == 'P' && ! SYMBOL_REF_LOCAL_P (x))
10233         fputs ("@PLT", file);
10234       break;
10235
10236     case LABEL_REF:
10237       x = XEXP (x, 0);
10238       /* FALLTHRU */
10239     case CODE_LABEL:
10240       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
10241       assemble_name (asm_out_file, buf);
10242       break;
10243
10244     case CONST_INT:
10245       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
10246       break;
10247
10248     case CONST:
10249       /* This used to output parentheses around the expression,
10250          but that does not work on the 386 (either ATT or BSD assembler).  */
10251       output_pic_addr_const (file, XEXP (x, 0), code);
10252       break;
10253
10254     case CONST_DOUBLE:
10255       if (GET_MODE (x) == VOIDmode)
10256         {
10257           /* We can use %d if the number is <32 bits and positive.  */
10258           if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
10259             fprintf (file, "0x%lx%08lx",
10260                      (unsigned long) CONST_DOUBLE_HIGH (x),
10261                      (unsigned long) CONST_DOUBLE_LOW (x));
10262           else
10263             fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
10264         }
10265       else
10266         /* We can't handle floating point constants;
10267            PRINT_OPERAND must handle them.  */
10268         output_operand_lossage ("floating constant misused");
10269       break;
10270
10271     case PLUS:
10272       /* Some assemblers need integer constants to appear first.  */
10273       if (CONST_INT_P (XEXP (x, 0)))
10274         {
10275           output_pic_addr_const (file, XEXP (x, 0), code);
10276           putc ('+', file);
10277           output_pic_addr_const (file, XEXP (x, 1), code);
10278         }
10279       else
10280         {
10281           gcc_assert (CONST_INT_P (XEXP (x, 1)));
10282           output_pic_addr_const (file, XEXP (x, 1), code);
10283           putc ('+', file);
10284           output_pic_addr_const (file, XEXP (x, 0), code);
10285         }
10286       break;
10287
10288     case MINUS:
10289       if (!TARGET_MACHO)
10290         putc (ASSEMBLER_DIALECT == ASM_INTEL ? '(' : '[', file);
10291       output_pic_addr_const (file, XEXP (x, 0), code);
10292       putc ('-', file);
10293       output_pic_addr_const (file, XEXP (x, 1), code);
10294       if (!TARGET_MACHO)
10295         putc (ASSEMBLER_DIALECT == ASM_INTEL ? ')' : ']', file);
10296       break;
10297
10298      case UNSPEC:
10299        gcc_assert (XVECLEN (x, 0) == 1);
10300        output_pic_addr_const (file, XVECEXP (x, 0, 0), code);
10301        switch (XINT (x, 1))
10302         {
10303         case UNSPEC_GOT:
10304           fputs ("@GOT", file);
10305           break;
10306         case UNSPEC_GOTOFF:
10307           fputs ("@GOTOFF", file);
10308           break;
10309         case UNSPEC_PLTOFF:
10310           fputs ("@PLTOFF", file);
10311           break;
10312         case UNSPEC_GOTPCREL:
10313           fputs (ASSEMBLER_DIALECT == ASM_ATT ?
10314                  "@GOTPCREL(%rip)" : "@GOTPCREL[rip]", file);
10315           break;
10316         case UNSPEC_GOTTPOFF:
10317           /* FIXME: This might be @TPOFF in Sun ld too.  */
10318           fputs ("@GOTTPOFF", file);
10319           break;
10320         case UNSPEC_TPOFF:
10321           fputs ("@TPOFF", file);
10322           break;
10323         case UNSPEC_NTPOFF:
10324           if (TARGET_64BIT)
10325             fputs ("@TPOFF", file);
10326           else
10327             fputs ("@NTPOFF", file);
10328           break;
10329         case UNSPEC_DTPOFF:
10330           fputs ("@DTPOFF", file);
10331           break;
10332         case UNSPEC_GOTNTPOFF:
10333           if (TARGET_64BIT)
10334             fputs (ASSEMBLER_DIALECT == ASM_ATT ?
10335                    "@GOTTPOFF(%rip)": "@GOTTPOFF[rip]", file);
10336           else
10337             fputs ("@GOTNTPOFF", file);
10338           break;
10339         case UNSPEC_INDNTPOFF:
10340           fputs ("@INDNTPOFF", file);
10341           break;
10342 #if TARGET_MACHO
10343         case UNSPEC_MACHOPIC_OFFSET:
10344           putc ('-', file);
10345           machopic_output_function_base_name (file);
10346           break;
10347 #endif
10348         default:
10349           output_operand_lossage ("invalid UNSPEC as operand");
10350           break;
10351         }
10352        break;
10353
10354     default:
10355       output_operand_lossage ("invalid expression as operand");
10356     }
10357 }
10358
10359 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
10360    We need to emit DTP-relative relocations.  */
10361
10362 static void ATTRIBUTE_UNUSED
10363 i386_output_dwarf_dtprel (FILE *file, int size, rtx x)
10364 {
10365   fputs (ASM_LONG, file);
10366   output_addr_const (file, x);
10367   fputs ("@DTPOFF", file);
10368   switch (size)
10369     {
10370     case 4:
10371       break;
10372     case 8:
10373       fputs (", 0", file);
10374       break;
10375     default:
10376       gcc_unreachable ();
10377    }
10378 }
10379
10380 /* Return true if X is a representation of the PIC register.  This copes
10381    with calls from ix86_find_base_term, where the register might have
10382    been replaced by a cselib value.  */
10383
10384 static bool
10385 ix86_pic_register_p (rtx x)
10386 {
10387   if (GET_CODE (x) == VALUE && CSELIB_VAL_PTR (x))
10388     return (pic_offset_table_rtx
10389             && rtx_equal_for_cselib_p (x, pic_offset_table_rtx));
10390   else
10391     return REG_P (x) && REGNO (x) == PIC_OFFSET_TABLE_REGNUM;
10392 }
10393
10394 /* In the name of slightly smaller debug output, and to cater to
10395    general assembler lossage, recognize PIC+GOTOFF and turn it back
10396    into a direct symbol reference.
10397
10398    On Darwin, this is necessary to avoid a crash, because Darwin
10399    has a different PIC label for each routine but the DWARF debugging
10400    information is not associated with any particular routine, so it's
10401    necessary to remove references to the PIC label from RTL stored by
10402    the DWARF output code.  */
10403
10404 static rtx
10405 ix86_delegitimize_address (rtx orig_x)
10406 {
10407   rtx x = orig_x;
10408   /* reg_addend is NULL or a multiple of some register.  */
10409   rtx reg_addend = NULL_RTX;
10410   /* const_addend is NULL or a const_int.  */
10411   rtx const_addend = NULL_RTX;
10412   /* This is the result, or NULL.  */
10413   rtx result = NULL_RTX;
10414
10415   if (MEM_P (x))
10416     x = XEXP (x, 0);
10417
10418   if (TARGET_64BIT)
10419     {
10420       if (GET_CODE (x) != CONST
10421           || GET_CODE (XEXP (x, 0)) != UNSPEC
10422           || XINT (XEXP (x, 0), 1) != UNSPEC_GOTPCREL
10423           || !MEM_P (orig_x))
10424         return orig_x;
10425       return XVECEXP (XEXP (x, 0), 0, 0);
10426     }
10427
10428   if (GET_CODE (x) != PLUS
10429       || GET_CODE (XEXP (x, 1)) != CONST)
10430     return orig_x;
10431
10432   if (ix86_pic_register_p (XEXP (x, 0)))
10433     /* %ebx + GOT/GOTOFF */
10434     ;
10435   else if (GET_CODE (XEXP (x, 0)) == PLUS)
10436     {
10437       /* %ebx + %reg * scale + GOT/GOTOFF */
10438       reg_addend = XEXP (x, 0);
10439       if (ix86_pic_register_p (XEXP (reg_addend, 0)))
10440         reg_addend = XEXP (reg_addend, 1);
10441       else if (ix86_pic_register_p (XEXP (reg_addend, 1)))
10442         reg_addend = XEXP (reg_addend, 0);
10443       else
10444         return orig_x;
10445       if (!REG_P (reg_addend)
10446           && GET_CODE (reg_addend) != MULT
10447           && GET_CODE (reg_addend) != ASHIFT)
10448         return orig_x;
10449     }
10450   else
10451     return orig_x;
10452
10453   x = XEXP (XEXP (x, 1), 0);
10454   if (GET_CODE (x) == PLUS
10455       && CONST_INT_P (XEXP (x, 1)))
10456     {
10457       const_addend = XEXP (x, 1);
10458       x = XEXP (x, 0);
10459     }
10460
10461   if (GET_CODE (x) == UNSPEC
10462       && ((XINT (x, 1) == UNSPEC_GOT && MEM_P (orig_x))
10463           || (XINT (x, 1) == UNSPEC_GOTOFF && !MEM_P (orig_x))))
10464     result = XVECEXP (x, 0, 0);
10465
10466   if (TARGET_MACHO && darwin_local_data_pic (x)
10467       && !MEM_P (orig_x))
10468     result = XVECEXP (x, 0, 0);
10469
10470   if (! result)
10471     return orig_x;
10472
10473   if (const_addend)
10474     result = gen_rtx_CONST (Pmode, gen_rtx_PLUS (Pmode, result, const_addend));
10475   if (reg_addend)
10476     result = gen_rtx_PLUS (Pmode, reg_addend, result);
10477   return result;
10478 }
10479
10480 /* If X is a machine specific address (i.e. a symbol or label being
10481    referenced as a displacement from the GOT implemented using an
10482    UNSPEC), then return the base term.  Otherwise return X.  */
10483
10484 rtx
10485 ix86_find_base_term (rtx x)
10486 {
10487   rtx term;
10488
10489   if (TARGET_64BIT)
10490     {
10491       if (GET_CODE (x) != CONST)
10492         return x;
10493       term = XEXP (x, 0);
10494       if (GET_CODE (term) == PLUS
10495           && (CONST_INT_P (XEXP (term, 1))
10496               || GET_CODE (XEXP (term, 1)) == CONST_DOUBLE))
10497         term = XEXP (term, 0);
10498       if (GET_CODE (term) != UNSPEC
10499           || XINT (term, 1) != UNSPEC_GOTPCREL)
10500         return x;
10501
10502       return XVECEXP (term, 0, 0);
10503     }
10504
10505   return ix86_delegitimize_address (x);
10506 }
10507 \f
10508 static void
10509 put_condition_code (enum rtx_code code, enum machine_mode mode, int reverse,
10510                     int fp, FILE *file)
10511 {
10512   const char *suffix;
10513
10514   if (mode == CCFPmode || mode == CCFPUmode)
10515     {
10516       enum rtx_code second_code, bypass_code;
10517       ix86_fp_comparison_codes (code, &bypass_code, &code, &second_code);
10518       gcc_assert (bypass_code == UNKNOWN && second_code == UNKNOWN);
10519       code = ix86_fp_compare_code_to_integer (code);
10520       mode = CCmode;
10521     }
10522   if (reverse)
10523     code = reverse_condition (code);
10524
10525   switch (code)
10526     {
10527     case EQ:
10528       switch (mode)
10529         {
10530         case CCAmode:
10531           suffix = "a";
10532           break;
10533
10534         case CCCmode:
10535           suffix = "c";
10536           break;
10537
10538         case CCOmode:
10539           suffix = "o";
10540           break;
10541
10542         case CCSmode:
10543           suffix = "s";
10544           break;
10545
10546         default:
10547           suffix = "e";
10548         }
10549       break;
10550     case NE:
10551       switch (mode)
10552         {
10553         case CCAmode:
10554           suffix = "na";
10555           break;
10556
10557         case CCCmode:
10558           suffix = "nc";
10559           break;
10560
10561         case CCOmode:
10562           suffix = "no";
10563           break;
10564
10565         case CCSmode:
10566           suffix = "ns";
10567           break;
10568
10569         default:
10570           suffix = "ne";
10571         }
10572       break;
10573     case GT:
10574       gcc_assert (mode == CCmode || mode == CCNOmode || mode == CCGCmode);
10575       suffix = "g";
10576       break;
10577     case GTU:
10578       /* ??? Use "nbe" instead of "a" for fcmov lossage on some assemblers.
10579          Those same assemblers have the same but opposite lossage on cmov.  */
10580       if (mode == CCmode)
10581         suffix = fp ? "nbe" : "a";
10582       else if (mode == CCCmode)
10583         suffix = "b";
10584       else
10585         gcc_unreachable ();
10586       break;
10587     case LT:
10588       switch (mode)
10589         {
10590         case CCNOmode:
10591         case CCGOCmode:
10592           suffix = "s";
10593           break;
10594
10595         case CCmode:
10596         case CCGCmode:
10597           suffix = "l";
10598           break;
10599
10600         default:
10601           gcc_unreachable ();
10602         }
10603       break;
10604     case LTU:
10605       gcc_assert (mode == CCmode || mode == CCCmode);
10606       suffix = "b";
10607       break;
10608     case GE:
10609       switch (mode)
10610         {
10611         case CCNOmode:
10612         case CCGOCmode:
10613           suffix = "ns";
10614           break;
10615
10616         case CCmode:
10617         case CCGCmode:
10618           suffix = "ge";
10619           break;
10620
10621         default:
10622           gcc_unreachable ();
10623         }
10624       break;
10625     case GEU:
10626       /* ??? As above.  */
10627       gcc_assert (mode == CCmode || mode == CCCmode);
10628       suffix = fp ? "nb" : "ae";
10629       break;
10630     case LE:
10631       gcc_assert (mode == CCmode || mode == CCGCmode || mode == CCNOmode);
10632       suffix = "le";
10633       break;
10634     case LEU:
10635       /* ??? As above.  */
10636       if (mode == CCmode)
10637         suffix = "be";
10638       else if (mode == CCCmode)
10639         suffix = fp ? "nb" : "ae";
10640       else
10641         gcc_unreachable ();
10642       break;
10643     case UNORDERED:
10644       suffix = fp ? "u" : "p";
10645       break;
10646     case ORDERED:
10647       suffix = fp ? "nu" : "np";
10648       break;
10649     default:
10650       gcc_unreachable ();
10651     }
10652   fputs (suffix, file);
10653 }
10654
10655 /* Print the name of register X to FILE based on its machine mode and number.
10656    If CODE is 'w', pretend the mode is HImode.
10657    If CODE is 'b', pretend the mode is QImode.
10658    If CODE is 'k', pretend the mode is SImode.
10659    If CODE is 'q', pretend the mode is DImode.
10660    If CODE is 'x', pretend the mode is V4SFmode.
10661    If CODE is 't', pretend the mode is V8SFmode.
10662    If CODE is 'h', pretend the reg is the 'high' byte register.
10663    If CODE is 'y', print "st(0)" instead of "st", if the reg is stack op.
10664    If CODE is 'd', duplicate the operand for AVX instruction.
10665  */
10666
10667 void
10668 print_reg (rtx x, int code, FILE *file)
10669 {
10670   const char *reg;
10671   bool duplicated = code == 'd' && TARGET_AVX;
10672
10673   gcc_assert (x == pc_rtx
10674               || (REGNO (x) != ARG_POINTER_REGNUM
10675                   && REGNO (x) != FRAME_POINTER_REGNUM
10676                   && REGNO (x) != FLAGS_REG
10677                   && REGNO (x) != FPSR_REG
10678                   && REGNO (x) != FPCR_REG));
10679
10680   if (ASSEMBLER_DIALECT == ASM_ATT)
10681     putc ('%', file);
10682
10683   if (x == pc_rtx)
10684     {
10685       gcc_assert (TARGET_64BIT);
10686       fputs ("rip", file);
10687       return;
10688     }
10689
10690   if (code == 'w' || MMX_REG_P (x))
10691     code = 2;
10692   else if (code == 'b')
10693     code = 1;
10694   else if (code == 'k')
10695     code = 4;
10696   else if (code == 'q')
10697     code = 8;
10698   else if (code == 'y')
10699     code = 3;
10700   else if (code == 'h')
10701     code = 0;
10702   else if (code == 'x')
10703     code = 16;
10704   else if (code == 't')
10705     code = 32;
10706   else
10707     code = GET_MODE_SIZE (GET_MODE (x));
10708
10709   /* Irritatingly, AMD extended registers use different naming convention
10710      from the normal registers.  */
10711   if (REX_INT_REG_P (x))
10712     {
10713       gcc_assert (TARGET_64BIT);
10714       switch (code)
10715         {
10716           case 0:
10717             error ("extended registers have no high halves");
10718             break;
10719           case 1:
10720             fprintf (file, "r%ib", REGNO (x) - FIRST_REX_INT_REG + 8);
10721             break;
10722           case 2:
10723             fprintf (file, "r%iw", REGNO (x) - FIRST_REX_INT_REG + 8);
10724             break;
10725           case 4:
10726             fprintf (file, "r%id", REGNO (x) - FIRST_REX_INT_REG + 8);
10727             break;
10728           case 8:
10729             fprintf (file, "r%i", REGNO (x) - FIRST_REX_INT_REG + 8);
10730             break;
10731           default:
10732             error ("unsupported operand size for extended register");
10733             break;
10734         }
10735       return;
10736     }
10737
10738   reg = NULL;
10739   switch (code)
10740     {
10741     case 3:
10742       if (STACK_TOP_P (x))
10743         {
10744           reg = "st(0)";
10745           break;
10746         }
10747       /* FALLTHRU */
10748     case 8:
10749     case 4:
10750     case 12:
10751       if (! ANY_FP_REG_P (x))
10752         putc (code == 8 && TARGET_64BIT ? 'r' : 'e', file);
10753       /* FALLTHRU */
10754     case 16:
10755     case 2:
10756     normal:
10757       reg = hi_reg_name[REGNO (x)];
10758       break;
10759     case 1:
10760       if (REGNO (x) >= ARRAY_SIZE (qi_reg_name))
10761         goto normal;
10762       reg = qi_reg_name[REGNO (x)];
10763       break;
10764     case 0:
10765       if (REGNO (x) >= ARRAY_SIZE (qi_high_reg_name))
10766         goto normal;
10767       reg = qi_high_reg_name[REGNO (x)];
10768       break;
10769     case 32:
10770       if (SSE_REG_P (x))
10771         {
10772           gcc_assert (!duplicated);
10773           putc ('y', file);
10774           fputs (hi_reg_name[REGNO (x)] + 1, file);
10775           return;
10776         }
10777       break;
10778     default:
10779       gcc_unreachable ();
10780     }
10781
10782   fputs (reg, file);
10783   if (duplicated)
10784     {
10785       if (ASSEMBLER_DIALECT == ASM_ATT)
10786         fprintf (file, ", %%%s", reg);
10787       else
10788         fprintf (file, ", %s", reg);
10789     }
10790 }
10791
10792 /* Locate some local-dynamic symbol still in use by this function
10793    so that we can print its name in some tls_local_dynamic_base
10794    pattern.  */
10795
10796 static int
10797 get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
10798 {
10799   rtx x = *px;
10800
10801   if (GET_CODE (x) == SYMBOL_REF
10802       && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
10803     {
10804       cfun->machine->some_ld_name = XSTR (x, 0);
10805       return 1;
10806     }
10807
10808   return 0;
10809 }
10810
10811 static const char *
10812 get_some_local_dynamic_name (void)
10813 {
10814   rtx insn;
10815
10816   if (cfun->machine->some_ld_name)
10817     return cfun->machine->some_ld_name;
10818
10819   for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
10820     if (INSN_P (insn)
10821         && for_each_rtx (&PATTERN (insn), get_some_local_dynamic_name_1, 0))
10822       return cfun->machine->some_ld_name;
10823
10824   gcc_unreachable ();
10825 }
10826
10827 /* Meaning of CODE:
10828    L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
10829    C -- print opcode suffix for set/cmov insn.
10830    c -- like C, but print reversed condition
10831    F,f -- likewise, but for floating-point.
10832    O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
10833         otherwise nothing
10834    R -- print the prefix for register names.
10835    z -- print the opcode suffix for the size of the current operand.
10836    * -- print a star (in certain assembler syntax)
10837    A -- print an absolute memory reference.
10838    w -- print the operand as if it's a "word" (HImode) even if it isn't.
10839    s -- print a shift double count, followed by the assemblers argument
10840         delimiter.
10841    b -- print the QImode name of the register for the indicated operand.
10842         %b0 would print %al if operands[0] is reg 0.
10843    w --  likewise, print the HImode name of the register.
10844    k --  likewise, print the SImode name of the register.
10845    q --  likewise, print the DImode name of the register.
10846    x --  likewise, print the V4SFmode name of the register.
10847    t --  likewise, print the V8SFmode name of the register.
10848    h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
10849    y -- print "st(0)" instead of "st" as a register.
10850    d -- print duplicated register operand for AVX instruction.
10851    D -- print condition for SSE cmp instruction.
10852    P -- if PIC, print an @PLT suffix.
10853    X -- don't print any sort of PIC '@' suffix for a symbol.
10854    & -- print some in-use local-dynamic symbol name.
10855    H -- print a memory address offset by 8; used for sse high-parts
10856    Y -- print condition for SSE5 com* instruction.
10857    + -- print a branch hint as 'cs' or 'ds' prefix
10858    ; -- print a semicolon (after prefixes due to bug in older gas).
10859  */
10860
10861 void
10862 print_operand (FILE *file, rtx x, int code)
10863 {
10864   if (code)
10865     {
10866       switch (code)
10867         {
10868         case '*':
10869           if (ASSEMBLER_DIALECT == ASM_ATT)
10870             putc ('*', file);
10871           return;
10872
10873         case '&':
10874           assemble_name (file, get_some_local_dynamic_name ());
10875           return;
10876
10877         case 'A':
10878           switch (ASSEMBLER_DIALECT)
10879             {
10880             case ASM_ATT:
10881               putc ('*', file);
10882               break;
10883
10884             case ASM_INTEL:
10885               /* Intel syntax. For absolute addresses, registers should not
10886                  be surrounded by braces.  */
10887               if (!REG_P (x))
10888                 {
10889                   putc ('[', file);
10890                   PRINT_OPERAND (file, x, 0);
10891                   putc (']', file);
10892                   return;
10893                 }
10894               break;
10895
10896             default:
10897               gcc_unreachable ();
10898             }
10899
10900           PRINT_OPERAND (file, x, 0);
10901           return;
10902
10903
10904         case 'L':
10905           if (ASSEMBLER_DIALECT == ASM_ATT)
10906             putc ('l', file);
10907           return;
10908
10909         case 'W':
10910           if (ASSEMBLER_DIALECT == ASM_ATT)
10911             putc ('w', file);
10912           return;
10913
10914         case 'B':
10915           if (ASSEMBLER_DIALECT == ASM_ATT)
10916             putc ('b', file);
10917           return;
10918
10919         case 'Q':
10920           if (ASSEMBLER_DIALECT == ASM_ATT)
10921             putc ('l', file);
10922           return;
10923
10924         case 'S':
10925           if (ASSEMBLER_DIALECT == ASM_ATT)
10926             putc ('s', file);
10927           return;
10928
10929         case 'T':
10930           if (ASSEMBLER_DIALECT == ASM_ATT)
10931             putc ('t', file);
10932           return;
10933
10934         case 'z':
10935           /* 387 opcodes don't get size suffixes if the operands are
10936              registers.  */
10937           if (STACK_REG_P (x))
10938             return;
10939
10940           /* Likewise if using Intel opcodes.  */
10941           if (ASSEMBLER_DIALECT == ASM_INTEL)
10942             return;
10943
10944           /* This is the size of op from size of operand.  */
10945           switch (GET_MODE_SIZE (GET_MODE (x)))
10946             {
10947             case 1:
10948               putc ('b', file);
10949               return;
10950
10951             case 2:
10952               if (MEM_P (x))
10953                 {
10954 #ifdef HAVE_GAS_FILDS_FISTS
10955                   putc ('s', file);
10956 #endif
10957                   return;
10958                 }
10959               else
10960                 putc ('w', file);
10961               return;
10962
10963             case 4:
10964               if (GET_MODE (x) == SFmode)
10965                 {
10966                   putc ('s', file);
10967                   return;
10968                 }
10969               else
10970                 putc ('l', file);
10971               return;
10972
10973             case 12:
10974             case 16:
10975               putc ('t', file);
10976               return;
10977
10978             case 8:
10979               if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
10980                 {
10981                   if (MEM_P (x))
10982                     {
10983 #ifdef GAS_MNEMONICS
10984                       putc ('q', file);
10985 #else
10986                       putc ('l', file);
10987                       putc ('l', file);
10988 #endif
10989                     }
10990                   else
10991                     putc ('q', file);
10992                 }
10993               else
10994                 putc ('l', file);
10995               return;
10996
10997             default:
10998               gcc_unreachable ();
10999             }
11000
11001         case 'd':
11002         case 'b':
11003         case 'w':
11004         case 'k':
11005         case 'q':
11006         case 'h':
11007         case 't':
11008         case 'y':
11009         case 'x':
11010         case 'X':
11011         case 'P':
11012           break;
11013
11014         case 's':
11015           if (CONST_INT_P (x) || ! SHIFT_DOUBLE_OMITS_COUNT)
11016             {
11017               PRINT_OPERAND (file, x, 0);
11018               fputs (", ", file);
11019             }
11020           return;
11021
11022         case 'D':
11023           /* Little bit of braindamage here.  The SSE compare instructions
11024              does use completely different names for the comparisons that the
11025              fp conditional moves.  */
11026           if (TARGET_AVX)
11027             {
11028               switch (GET_CODE (x))
11029                 {
11030                 case EQ:
11031                   fputs ("eq", file);
11032                   break;
11033                 case UNEQ:
11034                   fputs ("eq_us", file);
11035                   break;
11036                 case LT:
11037                   fputs ("lt", file);
11038                   break;
11039                 case UNLT:
11040                   fputs ("nge", file);
11041                   break;
11042                 case LE:
11043                   fputs ("le", file);
11044                   break;
11045                 case UNLE:
11046                   fputs ("ngt", file);
11047                   break;
11048                 case UNORDERED:
11049                   fputs ("unord", file);
11050                   break;
11051                 case NE:
11052                   fputs ("neq", file);
11053                   break;
11054                 case LTGT:
11055                   fputs ("neq_oq", file);
11056                   break;
11057                 case GE:
11058                   fputs ("ge", file);
11059                   break;
11060                 case UNGE:
11061                   fputs ("nlt", file);
11062                   break;
11063                 case GT:
11064                   fputs ("gt", file);
11065                   break;
11066                 case UNGT:
11067                   fputs ("nle", file);
11068                   break;
11069                 case ORDERED:
11070                   fputs ("ord", file);
11071                   break;
11072                 default:
11073                   output_operand_lossage ("operand is not a condition code, invalid operand code 'D'");
11074                   return;
11075                 }
11076             }
11077           else
11078             {
11079               switch (GET_CODE (x))
11080                 {
11081                 case EQ:
11082                 case UNEQ:
11083                   fputs ("eq", file);
11084                   break;
11085                 case LT:
11086                 case UNLT:
11087                   fputs ("lt", file);
11088                   break;
11089                 case LE:
11090                 case UNLE:
11091                   fputs ("le", file);
11092                   break;
11093                 case UNORDERED:
11094                   fputs ("unord", file);
11095                   break;
11096                 case NE:
11097                 case LTGT:
11098                   fputs ("neq", file);
11099                   break;
11100                 case UNGE:
11101                 case GE:
11102                   fputs ("nlt", file);
11103                   break;
11104                 case UNGT:
11105                 case GT:
11106                   fputs ("nle", file);
11107                   break;
11108                 case ORDERED:
11109                   fputs ("ord", file);
11110                   break;
11111                 default:
11112                   output_operand_lossage ("operand is not a condition code, invalid operand code 'D'");
11113                   return;
11114                 }
11115             }
11116           return;
11117         case 'O':
11118 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
11119           if (ASSEMBLER_DIALECT == ASM_ATT)
11120             {
11121               switch (GET_MODE (x))
11122                 {
11123                 case HImode: putc ('w', file); break;
11124                 case SImode:
11125                 case SFmode: putc ('l', file); break;
11126                 case DImode:
11127                 case DFmode: putc ('q', file); break;
11128                 default: gcc_unreachable ();
11129                 }
11130               putc ('.', file);
11131             }
11132 #endif
11133           return;
11134         case 'C':
11135           if (!COMPARISON_P (x))
11136             {
11137               output_operand_lossage ("operand is neither a constant nor a "
11138                                       "condition code, invalid operand code "
11139                                       "'C'");
11140               return;
11141             }
11142           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 0, file);
11143           return;
11144         case 'F':
11145           if (!COMPARISON_P (x))
11146             {
11147               output_operand_lossage ("operand is neither a constant nor a "
11148                                       "condition code, invalid operand code "
11149                                       "'F'");
11150               return;
11151             }
11152 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
11153           if (ASSEMBLER_DIALECT == ASM_ATT)
11154             putc ('.', file);
11155 #endif
11156           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 1, file);
11157           return;
11158
11159           /* Like above, but reverse condition */
11160         case 'c':
11161           /* Check to see if argument to %c is really a constant
11162              and not a condition code which needs to be reversed.  */
11163           if (!COMPARISON_P (x))
11164             {
11165               output_operand_lossage ("operand is neither a constant nor a "
11166                                       "condition code, invalid operand "
11167                                       "code 'c'");
11168               return;
11169             }
11170           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 0, file);
11171           return;
11172         case 'f':
11173           if (!COMPARISON_P (x))
11174             {
11175               output_operand_lossage ("operand is neither a constant nor a "
11176                                       "condition code, invalid operand "
11177                                       "code 'f'");
11178               return;
11179             }
11180 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
11181           if (ASSEMBLER_DIALECT == ASM_ATT)
11182             putc ('.', file);
11183 #endif
11184           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 1, file);
11185           return;
11186
11187         case 'H':
11188           /* It doesn't actually matter what mode we use here, as we're
11189              only going to use this for printing.  */
11190           x = adjust_address_nv (x, DImode, 8);
11191           break;
11192
11193         case '+':
11194           {
11195             rtx x;
11196
11197             if (!optimize
11198                 || optimize_function_for_size_p (cfun) || !TARGET_BRANCH_PREDICTION_HINTS)
11199               return;
11200
11201             x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
11202             if (x)
11203               {
11204                 int pred_val = INTVAL (XEXP (x, 0));
11205
11206                 if (pred_val < REG_BR_PROB_BASE * 45 / 100
11207                     || pred_val > REG_BR_PROB_BASE * 55 / 100)
11208                   {
11209                     int taken = pred_val > REG_BR_PROB_BASE / 2;
11210                     int cputaken = final_forward_branch_p (current_output_insn) == 0;
11211
11212                     /* Emit hints only in the case default branch prediction
11213                        heuristics would fail.  */
11214                     if (taken != cputaken)
11215                       {
11216                         /* We use 3e (DS) prefix for taken branches and
11217                            2e (CS) prefix for not taken branches.  */
11218                         if (taken)
11219                           fputs ("ds ; ", file);
11220                         else
11221                           fputs ("cs ; ", file);
11222                       }
11223                   }
11224               }
11225             return;
11226           }
11227
11228         case 'Y':
11229           switch (GET_CODE (x))
11230             {
11231             case NE:
11232               fputs ("neq", file);
11233               break;
11234             case EQ:
11235               fputs ("eq", file);
11236               break;
11237             case GE:
11238             case GEU:
11239               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "ge" : "unlt", file);
11240               break;
11241             case GT:
11242             case GTU:
11243               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "gt" : "unle", file);
11244               break;
11245             case LE:
11246             case LEU:
11247               fputs ("le", file);
11248               break;
11249             case LT:
11250             case LTU:
11251               fputs ("lt", file);
11252               break;
11253             case UNORDERED:
11254               fputs ("unord", file);
11255               break;
11256             case ORDERED:
11257               fputs ("ord", file);
11258               break;
11259             case UNEQ:
11260               fputs ("ueq", file);
11261               break;
11262             case UNGE:
11263               fputs ("nlt", file);
11264               break;
11265             case UNGT:
11266               fputs ("nle", file);
11267               break;
11268             case UNLE:
11269               fputs ("ule", file);
11270               break;
11271             case UNLT:
11272               fputs ("ult", file);
11273               break;
11274             case LTGT:
11275               fputs ("une", file);
11276               break;
11277             default:
11278               output_operand_lossage ("operand is not a condition code, invalid operand code 'D'");
11279               return;
11280             }
11281           return;
11282
11283         case ';':
11284 #if TARGET_MACHO || !HAVE_AS_IX86_REP_LOCK_PREFIX
11285           fputs (";", file);
11286 #endif
11287           return;
11288
11289         default:
11290             output_operand_lossage ("invalid operand code '%c'", code);
11291         }
11292     }
11293
11294   if (REG_P (x))
11295     print_reg (x, code, file);
11296
11297   else if (MEM_P (x))
11298     {
11299       /* No `byte ptr' prefix for call instructions or BLKmode operands.  */
11300       if (ASSEMBLER_DIALECT == ASM_INTEL && code != 'X' && code != 'P'
11301           && GET_MODE (x) != BLKmode)
11302         {
11303           const char * size;
11304           switch (GET_MODE_SIZE (GET_MODE (x)))
11305             {
11306             case 1: size = "BYTE"; break;
11307             case 2: size = "WORD"; break;
11308             case 4: size = "DWORD"; break;
11309             case 8: size = "QWORD"; break;
11310             case 12: size = "TBYTE"; break;
11311             case 16:
11312               if (GET_MODE (x) == XFmode)
11313                 size = "TBYTE";
11314               else
11315                 size = "XMMWORD";
11316               break;
11317             case 32: size = "YMMWORD"; break;
11318             default:
11319               gcc_unreachable ();
11320             }
11321
11322           /* Check for explicit size override (codes 'b', 'w' and 'k')  */
11323           if (code == 'b')
11324             size = "BYTE";
11325           else if (code == 'w')
11326             size = "WORD";
11327           else if (code == 'k')
11328             size = "DWORD";
11329
11330           fputs (size, file);
11331           fputs (" PTR ", file);
11332         }
11333
11334       x = XEXP (x, 0);
11335       /* Avoid (%rip) for call operands.  */
11336       if (CONSTANT_ADDRESS_P (x) && code == 'P'
11337           && !CONST_INT_P (x))
11338         output_addr_const (file, x);
11339       else if (this_is_asm_operands && ! address_operand (x, VOIDmode))
11340         output_operand_lossage ("invalid constraints for operand");
11341       else
11342         output_address (x);
11343     }
11344
11345   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
11346     {
11347       REAL_VALUE_TYPE r;
11348       long l;
11349
11350       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
11351       REAL_VALUE_TO_TARGET_SINGLE (r, l);
11352
11353       if (ASSEMBLER_DIALECT == ASM_ATT)
11354         putc ('$', file);
11355       fprintf (file, "0x%08lx", (long unsigned int) l);
11356     }
11357
11358   /* These float cases don't actually occur as immediate operands.  */
11359   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
11360     {
11361       char dstr[30];
11362
11363       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
11364       fprintf (file, "%s", dstr);
11365     }
11366
11367   else if (GET_CODE (x) == CONST_DOUBLE
11368            && GET_MODE (x) == XFmode)
11369     {
11370       char dstr[30];
11371
11372       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
11373       fprintf (file, "%s", dstr);
11374     }
11375
11376   else
11377     {
11378       /* We have patterns that allow zero sets of memory, for instance.
11379          In 64-bit mode, we should probably support all 8-byte vectors,
11380          since we can in fact encode that into an immediate.  */
11381       if (GET_CODE (x) == CONST_VECTOR)
11382         {
11383           gcc_assert (x == CONST0_RTX (GET_MODE (x)));
11384           x = const0_rtx;
11385         }
11386
11387       if (code != 'P')
11388         {
11389           if (CONST_INT_P (x) || GET_CODE (x) == CONST_DOUBLE)
11390             {
11391               if (ASSEMBLER_DIALECT == ASM_ATT)
11392                 putc ('$', file);
11393             }
11394           else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF
11395                    || GET_CODE (x) == LABEL_REF)
11396             {
11397               if (ASSEMBLER_DIALECT == ASM_ATT)
11398                 putc ('$', file);
11399               else
11400                 fputs ("OFFSET FLAT:", file);
11401             }
11402         }
11403       if (CONST_INT_P (x))
11404         fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
11405       else if (flag_pic)
11406         output_pic_addr_const (file, x, code);
11407       else
11408         output_addr_const (file, x);
11409     }
11410 }
11411 \f
11412 /* Print a memory operand whose address is ADDR.  */
11413
11414 void
11415 print_operand_address (FILE *file, rtx addr)
11416 {
11417   struct ix86_address parts;
11418   rtx base, index, disp;
11419   int scale;
11420   int ok = ix86_decompose_address (addr, &parts);
11421
11422   gcc_assert (ok);
11423
11424   base = parts.base;
11425   index = parts.index;
11426   disp = parts.disp;
11427   scale = parts.scale;
11428
11429   switch (parts.seg)
11430     {
11431     case SEG_DEFAULT:
11432       break;
11433     case SEG_FS:
11434     case SEG_GS:
11435       if (ASSEMBLER_DIALECT == ASM_ATT)
11436         putc ('%', file);
11437       fputs ((parts.seg == SEG_FS ? "fs:" : "gs:"), file);
11438       break;
11439     default:
11440       gcc_unreachable ();
11441     }
11442
11443   /* Use one byte shorter RIP relative addressing for 64bit mode.  */
11444   if (TARGET_64BIT && !base && !index)
11445     {
11446       rtx symbol = disp;
11447
11448       if (GET_CODE (disp) == CONST
11449           && GET_CODE (XEXP (disp, 0)) == PLUS
11450           && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
11451         symbol = XEXP (XEXP (disp, 0), 0);
11452
11453       if (GET_CODE (symbol) == LABEL_REF
11454           || (GET_CODE (symbol) == SYMBOL_REF
11455               && SYMBOL_REF_TLS_MODEL (symbol) == 0))
11456         base = pc_rtx;
11457     }
11458   if (!base && !index)
11459     {
11460       /* Displacement only requires special attention.  */
11461
11462       if (CONST_INT_P (disp))
11463         {
11464           if (ASSEMBLER_DIALECT == ASM_INTEL && parts.seg == SEG_DEFAULT)
11465             fputs ("ds:", file);
11466           fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (disp));
11467         }
11468       else if (flag_pic)
11469         output_pic_addr_const (file, disp, 0);
11470       else
11471         output_addr_const (file, disp);
11472     }
11473   else
11474     {
11475       if (ASSEMBLER_DIALECT == ASM_ATT)
11476         {
11477           if (disp)
11478             {
11479               if (flag_pic)
11480                 output_pic_addr_const (file, disp, 0);
11481               else if (GET_CODE (disp) == LABEL_REF)
11482                 output_asm_label (disp);
11483               else
11484                 output_addr_const (file, disp);
11485             }
11486
11487           putc ('(', file);
11488           if (base)
11489             print_reg (base, 0, file);
11490           if (index)
11491             {
11492               putc (',', file);
11493               print_reg (index, 0, file);
11494               if (scale != 1)
11495                 fprintf (file, ",%d", scale);
11496             }
11497           putc (')', file);
11498         }
11499       else
11500         {
11501           rtx offset = NULL_RTX;
11502
11503           if (disp)
11504             {
11505               /* Pull out the offset of a symbol; print any symbol itself.  */
11506               if (GET_CODE (disp) == CONST
11507                   && GET_CODE (XEXP (disp, 0)) == PLUS
11508                   && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
11509                 {
11510                   offset = XEXP (XEXP (disp, 0), 1);
11511                   disp = gen_rtx_CONST (VOIDmode,
11512                                         XEXP (XEXP (disp, 0), 0));
11513                 }
11514
11515               if (flag_pic)
11516                 output_pic_addr_const (file, disp, 0);
11517               else if (GET_CODE (disp) == LABEL_REF)
11518                 output_asm_label (disp);
11519               else if (CONST_INT_P (disp))
11520                 offset = disp;
11521               else
11522                 output_addr_const (file, disp);
11523             }
11524
11525           putc ('[', file);
11526           if (base)
11527             {
11528               print_reg (base, 0, file);
11529               if (offset)
11530                 {
11531                   if (INTVAL (offset) >= 0)
11532                     putc ('+', file);
11533                   fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
11534                 }
11535             }
11536           else if (offset)
11537             fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
11538           else
11539             putc ('0', file);
11540
11541           if (index)
11542             {
11543               putc ('+', file);
11544               print_reg (index, 0, file);
11545               if (scale != 1)
11546                 fprintf (file, "*%d", scale);
11547             }
11548           putc (']', file);
11549         }
11550     }
11551 }
11552
11553 bool
11554 output_addr_const_extra (FILE *file, rtx x)
11555 {
11556   rtx op;
11557
11558   if (GET_CODE (x) != UNSPEC)
11559     return false;
11560
11561   op = XVECEXP (x, 0, 0);
11562   switch (XINT (x, 1))
11563     {
11564     case UNSPEC_GOTTPOFF:
11565       output_addr_const (file, op);
11566       /* FIXME: This might be @TPOFF in Sun ld.  */
11567       fputs ("@GOTTPOFF", file);
11568       break;
11569     case UNSPEC_TPOFF:
11570       output_addr_const (file, op);
11571       fputs ("@TPOFF", file);
11572       break;
11573     case UNSPEC_NTPOFF:
11574       output_addr_const (file, op);
11575       if (TARGET_64BIT)
11576         fputs ("@TPOFF", file);
11577       else
11578         fputs ("@NTPOFF", file);
11579       break;
11580     case UNSPEC_DTPOFF:
11581       output_addr_const (file, op);
11582       fputs ("@DTPOFF", file);
11583       break;
11584     case UNSPEC_GOTNTPOFF:
11585       output_addr_const (file, op);
11586       if (TARGET_64BIT)
11587         fputs (ASSEMBLER_DIALECT == ASM_ATT ?
11588                "@GOTTPOFF(%rip)" : "@GOTTPOFF[rip]", file);
11589       else
11590         fputs ("@GOTNTPOFF", file);
11591       break;
11592     case UNSPEC_INDNTPOFF:
11593       output_addr_const (file, op);
11594       fputs ("@INDNTPOFF", file);
11595       break;
11596 #if TARGET_MACHO
11597     case UNSPEC_MACHOPIC_OFFSET:
11598       output_addr_const (file, op);
11599       putc ('-', file);
11600       machopic_output_function_base_name (file);
11601       break;
11602 #endif
11603
11604     default:
11605       return false;
11606     }
11607
11608   return true;
11609 }
11610 \f
11611 /* Split one or more DImode RTL references into pairs of SImode
11612    references.  The RTL can be REG, offsettable MEM, integer constant, or
11613    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
11614    split and "num" is its length.  lo_half and hi_half are output arrays
11615    that parallel "operands".  */
11616
11617 void
11618 split_di (rtx operands[], int num, rtx lo_half[], rtx hi_half[])
11619 {
11620   while (num--)
11621     {
11622       rtx op = operands[num];
11623
11624       /* simplify_subreg refuse to split volatile memory addresses,
11625          but we still have to handle it.  */
11626       if (MEM_P (op))
11627         {
11628           lo_half[num] = adjust_address (op, SImode, 0);
11629           hi_half[num] = adjust_address (op, SImode, 4);
11630         }
11631       else
11632         {
11633           lo_half[num] = simplify_gen_subreg (SImode, op,
11634                                               GET_MODE (op) == VOIDmode
11635                                               ? DImode : GET_MODE (op), 0);
11636           hi_half[num] = simplify_gen_subreg (SImode, op,
11637                                               GET_MODE (op) == VOIDmode
11638                                               ? DImode : GET_MODE (op), 4);
11639         }
11640     }
11641 }
11642 /* Split one or more TImode RTL references into pairs of DImode
11643    references.  The RTL can be REG, offsettable MEM, integer constant, or
11644    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
11645    split and "num" is its length.  lo_half and hi_half are output arrays
11646    that parallel "operands".  */
11647
11648 void
11649 split_ti (rtx operands[], int num, rtx lo_half[], rtx hi_half[])
11650 {
11651   while (num--)
11652     {
11653       rtx op = operands[num];
11654
11655       /* simplify_subreg refuse to split volatile memory addresses, but we
11656          still have to handle it.  */
11657       if (MEM_P (op))
11658         {
11659           lo_half[num] = adjust_address (op, DImode, 0);
11660           hi_half[num] = adjust_address (op, DImode, 8);
11661         }
11662       else
11663         {
11664           lo_half[num] = simplify_gen_subreg (DImode, op, TImode, 0);
11665           hi_half[num] = simplify_gen_subreg (DImode, op, TImode, 8);
11666         }
11667     }
11668 }
11669 \f
11670 /* Output code to perform a 387 binary operation in INSN, one of PLUS,
11671    MINUS, MULT or DIV.  OPERANDS are the insn operands, where operands[3]
11672    is the expression of the binary operation.  The output may either be
11673    emitted here, or returned to the caller, like all output_* functions.
11674
11675    There is no guarantee that the operands are the same mode, as they
11676    might be within FLOAT or FLOAT_EXTEND expressions.  */
11677
11678 #ifndef SYSV386_COMPAT
11679 /* Set to 1 for compatibility with brain-damaged assemblers.  No-one
11680    wants to fix the assemblers because that causes incompatibility
11681    with gcc.  No-one wants to fix gcc because that causes
11682    incompatibility with assemblers...  You can use the option of
11683    -DSYSV386_COMPAT=0 if you recompile both gcc and gas this way.  */
11684 #define SYSV386_COMPAT 1
11685 #endif
11686
11687 const char *
11688 output_387_binary_op (rtx insn, rtx *operands)
11689 {
11690   static char buf[40];
11691   const char *p;
11692   const char *ssep;
11693   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]) || SSE_REG_P (operands[2]);
11694
11695 #ifdef ENABLE_CHECKING
11696   /* Even if we do not want to check the inputs, this documents input
11697      constraints.  Which helps in understanding the following code.  */
11698   if (STACK_REG_P (operands[0])
11699       && ((REG_P (operands[1])
11700            && REGNO (operands[0]) == REGNO (operands[1])
11701            && (STACK_REG_P (operands[2]) || MEM_P (operands[2])))
11702           || (REG_P (operands[2])
11703               && REGNO (operands[0]) == REGNO (operands[2])
11704               && (STACK_REG_P (operands[1]) || MEM_P (operands[1]))))
11705       && (STACK_TOP_P (operands[1]) || STACK_TOP_P (operands[2])))
11706     ; /* ok */
11707   else
11708     gcc_assert (is_sse);
11709 #endif
11710
11711   switch (GET_CODE (operands[3]))
11712     {
11713     case PLUS:
11714       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11715           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11716         p = "fiadd";
11717       else
11718         p = "fadd";
11719       ssep = "vadd";
11720       break;
11721
11722     case MINUS:
11723       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11724           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11725         p = "fisub";
11726       else
11727         p = "fsub";
11728       ssep = "vsub";
11729       break;
11730
11731     case MULT:
11732       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11733           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11734         p = "fimul";
11735       else
11736         p = "fmul";
11737       ssep = "vmul";
11738       break;
11739
11740     case DIV:
11741       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11742           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11743         p = "fidiv";
11744       else
11745         p = "fdiv";
11746       ssep = "vdiv";
11747       break;
11748
11749     default:
11750       gcc_unreachable ();
11751     }
11752
11753   if (is_sse)
11754    {
11755      if (TARGET_AVX)
11756        {
11757          strcpy (buf, ssep);
11758          if (GET_MODE (operands[0]) == SFmode)
11759            strcat (buf, "ss\t{%2, %1, %0|%0, %1, %2}");
11760          else
11761            strcat (buf, "sd\t{%2, %1, %0|%0, %1, %2}");
11762        }
11763      else
11764        {
11765          strcpy (buf, ssep + 1);
11766          if (GET_MODE (operands[0]) == SFmode)
11767            strcat (buf, "ss\t{%2, %0|%0, %2}");
11768          else
11769            strcat (buf, "sd\t{%2, %0|%0, %2}");
11770        }
11771       return buf;
11772    }
11773   strcpy (buf, p);
11774
11775   switch (GET_CODE (operands[3]))
11776     {
11777     case MULT:
11778     case PLUS:
11779       if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2]))
11780         {
11781           rtx temp = operands[2];
11782           operands[2] = operands[1];
11783           operands[1] = temp;
11784         }
11785
11786       /* know operands[0] == operands[1].  */
11787
11788       if (MEM_P (operands[2]))
11789         {
11790           p = "%z2\t%2";
11791           break;
11792         }
11793
11794       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
11795         {
11796           if (STACK_TOP_P (operands[0]))
11797             /* How is it that we are storing to a dead operand[2]?
11798                Well, presumably operands[1] is dead too.  We can't
11799                store the result to st(0) as st(0) gets popped on this
11800                instruction.  Instead store to operands[2] (which I
11801                think has to be st(1)).  st(1) will be popped later.
11802                gcc <= 2.8.1 didn't have this check and generated
11803                assembly code that the Unixware assembler rejected.  */
11804             p = "p\t{%0, %2|%2, %0}";   /* st(1) = st(0) op st(1); pop */
11805           else
11806             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
11807           break;
11808         }
11809
11810       if (STACK_TOP_P (operands[0]))
11811         p = "\t{%y2, %0|%0, %y2}";      /* st(0) = st(0) op st(r2) */
11812       else
11813         p = "\t{%2, %0|%0, %2}";        /* st(r1) = st(r1) op st(0) */
11814       break;
11815
11816     case MINUS:
11817     case DIV:
11818       if (MEM_P (operands[1]))
11819         {
11820           p = "r%z1\t%1";
11821           break;
11822         }
11823
11824       if (MEM_P (operands[2]))
11825         {
11826           p = "%z2\t%2";
11827           break;
11828         }
11829
11830       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
11831         {
11832 #if SYSV386_COMPAT
11833           /* The SystemV/386 SVR3.2 assembler, and probably all AT&T
11834              derived assemblers, confusingly reverse the direction of
11835              the operation for fsub{r} and fdiv{r} when the
11836              destination register is not st(0).  The Intel assembler
11837              doesn't have this brain damage.  Read !SYSV386_COMPAT to
11838              figure out what the hardware really does.  */
11839           if (STACK_TOP_P (operands[0]))
11840             p = "{p\t%0, %2|rp\t%2, %0}";
11841           else
11842             p = "{rp\t%2, %0|p\t%0, %2}";
11843 #else
11844           if (STACK_TOP_P (operands[0]))
11845             /* As above for fmul/fadd, we can't store to st(0).  */
11846             p = "rp\t{%0, %2|%2, %0}";  /* st(1) = st(0) op st(1); pop */
11847           else
11848             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
11849 #endif
11850           break;
11851         }
11852
11853       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
11854         {
11855 #if SYSV386_COMPAT
11856           if (STACK_TOP_P (operands[0]))
11857             p = "{rp\t%0, %1|p\t%1, %0}";
11858           else
11859             p = "{p\t%1, %0|rp\t%0, %1}";
11860 #else
11861           if (STACK_TOP_P (operands[0]))
11862             p = "p\t{%0, %1|%1, %0}";   /* st(1) = st(1) op st(0); pop */
11863           else
11864             p = "rp\t{%1, %0|%0, %1}";  /* st(r2) = st(0) op st(r2); pop */
11865 #endif
11866           break;
11867         }
11868
11869       if (STACK_TOP_P (operands[0]))
11870         {
11871           if (STACK_TOP_P (operands[1]))
11872             p = "\t{%y2, %0|%0, %y2}";  /* st(0) = st(0) op st(r2) */
11873           else
11874             p = "r\t{%y1, %0|%0, %y1}"; /* st(0) = st(r1) op st(0) */
11875           break;
11876         }
11877       else if (STACK_TOP_P (operands[1]))
11878         {
11879 #if SYSV386_COMPAT
11880           p = "{\t%1, %0|r\t%0, %1}";
11881 #else
11882           p = "r\t{%1, %0|%0, %1}";     /* st(r2) = st(0) op st(r2) */
11883 #endif
11884         }
11885       else
11886         {
11887 #if SYSV386_COMPAT
11888           p = "{r\t%2, %0|\t%0, %2}";
11889 #else
11890           p = "\t{%2, %0|%0, %2}";      /* st(r1) = st(r1) op st(0) */
11891 #endif
11892         }
11893       break;
11894
11895     default:
11896       gcc_unreachable ();
11897     }
11898
11899   strcat (buf, p);
11900   return buf;
11901 }
11902
11903 /* Return needed mode for entity in optimize_mode_switching pass.  */
11904
11905 int
11906 ix86_mode_needed (int entity, rtx insn)
11907 {
11908   enum attr_i387_cw mode;
11909
11910   /* The mode UNINITIALIZED is used to store control word after a
11911      function call or ASM pattern.  The mode ANY specify that function
11912      has no requirements on the control word and make no changes in the
11913      bits we are interested in.  */
11914
11915   if (CALL_P (insn)
11916       || (NONJUMP_INSN_P (insn)
11917           && (asm_noperands (PATTERN (insn)) >= 0
11918               || GET_CODE (PATTERN (insn)) == ASM_INPUT)))
11919     return I387_CW_UNINITIALIZED;
11920
11921   if (recog_memoized (insn) < 0)
11922     return I387_CW_ANY;
11923
11924   mode = get_attr_i387_cw (insn);
11925
11926   switch (entity)
11927     {
11928     case I387_TRUNC:
11929       if (mode == I387_CW_TRUNC)
11930         return mode;
11931       break;
11932
11933     case I387_FLOOR:
11934       if (mode == I387_CW_FLOOR)
11935         return mode;
11936       break;
11937
11938     case I387_CEIL:
11939       if (mode == I387_CW_CEIL)
11940         return mode;
11941       break;
11942
11943     case I387_MASK_PM:
11944       if (mode == I387_CW_MASK_PM)
11945         return mode;
11946       break;
11947
11948     default:
11949       gcc_unreachable ();
11950     }
11951
11952   return I387_CW_ANY;
11953 }
11954
11955 /* Output code to initialize control word copies used by trunc?f?i and
11956    rounding patterns.  CURRENT_MODE is set to current control word,
11957    while NEW_MODE is set to new control word.  */
11958
11959 void
11960 emit_i387_cw_initialization (int mode)
11961 {
11962   rtx stored_mode = assign_386_stack_local (HImode, SLOT_CW_STORED);
11963   rtx new_mode;
11964
11965   enum ix86_stack_slot slot;
11966
11967   rtx reg = gen_reg_rtx (HImode);
11968
11969   emit_insn (gen_x86_fnstcw_1 (stored_mode));
11970   emit_move_insn (reg, copy_rtx (stored_mode));
11971
11972   if (TARGET_64BIT || TARGET_PARTIAL_REG_STALL
11973       || optimize_function_for_size_p (cfun))
11974     {
11975       switch (mode)
11976         {
11977         case I387_CW_TRUNC:
11978           /* round toward zero (truncate) */
11979           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0c00)));
11980           slot = SLOT_CW_TRUNC;
11981           break;
11982
11983         case I387_CW_FLOOR:
11984           /* round down toward -oo */
11985           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
11986           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0400)));
11987           slot = SLOT_CW_FLOOR;
11988           break;
11989
11990         case I387_CW_CEIL:
11991           /* round up toward +oo */
11992           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
11993           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0800)));
11994           slot = SLOT_CW_CEIL;
11995           break;
11996
11997         case I387_CW_MASK_PM:
11998           /* mask precision exception for nearbyint() */
11999           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
12000           slot = SLOT_CW_MASK_PM;
12001           break;
12002
12003         default:
12004           gcc_unreachable ();
12005         }
12006     }
12007   else
12008     {
12009       switch (mode)
12010         {
12011         case I387_CW_TRUNC:
12012           /* round toward zero (truncate) */
12013           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0xc)));
12014           slot = SLOT_CW_TRUNC;
12015           break;
12016
12017         case I387_CW_FLOOR:
12018           /* round down toward -oo */
12019           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x4)));
12020           slot = SLOT_CW_FLOOR;
12021           break;
12022
12023         case I387_CW_CEIL:
12024           /* round up toward +oo */
12025           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x8)));
12026           slot = SLOT_CW_CEIL;
12027           break;
12028
12029         case I387_CW_MASK_PM:
12030           /* mask precision exception for nearbyint() */
12031           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
12032           slot = SLOT_CW_MASK_PM;
12033           break;
12034
12035         default:
12036           gcc_unreachable ();
12037         }
12038     }
12039
12040   gcc_assert (slot < MAX_386_STACK_LOCALS);
12041
12042   new_mode = assign_386_stack_local (HImode, slot);
12043   emit_move_insn (new_mode, reg);
12044 }
12045
12046 /* Output code for INSN to convert a float to a signed int.  OPERANDS
12047    are the insn operands.  The output may be [HSD]Imode and the input
12048    operand may be [SDX]Fmode.  */
12049
12050 const char *
12051 output_fix_trunc (rtx insn, rtx *operands, int fisttp)
12052 {
12053   int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
12054   int dimode_p = GET_MODE (operands[0]) == DImode;
12055   int round_mode = get_attr_i387_cw (insn);
12056
12057   /* Jump through a hoop or two for DImode, since the hardware has no
12058      non-popping instruction.  We used to do this a different way, but
12059      that was somewhat fragile and broke with post-reload splitters.  */
12060   if ((dimode_p || fisttp) && !stack_top_dies)
12061     output_asm_insn ("fld\t%y1", operands);
12062
12063   gcc_assert (STACK_TOP_P (operands[1]));
12064   gcc_assert (MEM_P (operands[0]));
12065   gcc_assert (GET_MODE (operands[1]) != TFmode);
12066
12067   if (fisttp)
12068       output_asm_insn ("fisttp%z0\t%0", operands);
12069   else
12070     {
12071       if (round_mode != I387_CW_ANY)
12072         output_asm_insn ("fldcw\t%3", operands);
12073       if (stack_top_dies || dimode_p)
12074         output_asm_insn ("fistp%z0\t%0", operands);
12075       else
12076         output_asm_insn ("fist%z0\t%0", operands);
12077       if (round_mode != I387_CW_ANY)
12078         output_asm_insn ("fldcw\t%2", operands);
12079     }
12080
12081   return "";
12082 }
12083
12084 /* Output code for x87 ffreep insn.  The OPNO argument, which may only
12085    have the values zero or one, indicates the ffreep insn's operand
12086    from the OPERANDS array.  */
12087
12088 static const char *
12089 output_387_ffreep (rtx *operands ATTRIBUTE_UNUSED, int opno)
12090 {
12091   if (TARGET_USE_FFREEP)
12092 #ifdef HAVE_AS_IX86_FFREEP
12093     return opno ? "ffreep\t%y1" : "ffreep\t%y0";
12094 #else
12095     {
12096       static char retval[32];
12097       int regno = REGNO (operands[opno]);
12098
12099       gcc_assert (FP_REGNO_P (regno));
12100
12101       regno -= FIRST_STACK_REG;
12102
12103       snprintf (retval, sizeof (retval), ASM_SHORT "0xc%ddf", regno);
12104       return retval;
12105     }
12106 #endif
12107
12108   return opno ? "fstp\t%y1" : "fstp\t%y0";
12109 }
12110
12111
12112 /* Output code for INSN to compare OPERANDS.  EFLAGS_P is 1 when fcomi
12113    should be used.  UNORDERED_P is true when fucom should be used.  */
12114
12115 const char *
12116 output_fp_compare (rtx insn, rtx *operands, int eflags_p, int unordered_p)
12117 {
12118   int stack_top_dies;
12119   rtx cmp_op0, cmp_op1;
12120   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]);
12121
12122   if (eflags_p)
12123     {
12124       cmp_op0 = operands[0];
12125       cmp_op1 = operands[1];
12126     }
12127   else
12128     {
12129       cmp_op0 = operands[1];
12130       cmp_op1 = operands[2];
12131     }
12132
12133   if (is_sse)
12134     {
12135       static const char ucomiss[] = "vucomiss\t{%1, %0|%0, %1}";
12136       static const char ucomisd[] = "vucomisd\t{%1, %0|%0, %1}";
12137       static const char comiss[] = "vcomiss\t{%1, %0|%0, %1}";
12138       static const char comisd[] = "vcomisd\t{%1, %0|%0, %1}";
12139
12140       if (GET_MODE (operands[0]) == SFmode)
12141         if (unordered_p)
12142           return &ucomiss[TARGET_AVX ? 0 : 1];
12143         else
12144           return &comiss[TARGET_AVX ? 0 : 1];
12145       else
12146         if (unordered_p)
12147           return &ucomisd[TARGET_AVX ? 0 : 1];
12148         else
12149           return &comisd[TARGET_AVX ? 0 : 1];
12150     }
12151
12152   gcc_assert (STACK_TOP_P (cmp_op0));
12153
12154   stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
12155
12156   if (cmp_op1 == CONST0_RTX (GET_MODE (cmp_op1)))
12157     {
12158       if (stack_top_dies)
12159         {
12160           output_asm_insn ("ftst\n\tfnstsw\t%0", operands);
12161           return output_387_ffreep (operands, 1);
12162         }
12163       else
12164         return "ftst\n\tfnstsw\t%0";
12165     }
12166
12167   if (STACK_REG_P (cmp_op1)
12168       && stack_top_dies
12169       && find_regno_note (insn, REG_DEAD, REGNO (cmp_op1))
12170       && REGNO (cmp_op1) != FIRST_STACK_REG)
12171     {
12172       /* If both the top of the 387 stack dies, and the other operand
12173          is also a stack register that dies, then this must be a
12174          `fcompp' float compare */
12175
12176       if (eflags_p)
12177         {
12178           /* There is no double popping fcomi variant.  Fortunately,
12179              eflags is immune from the fstp's cc clobbering.  */
12180           if (unordered_p)
12181             output_asm_insn ("fucomip\t{%y1, %0|%0, %y1}", operands);
12182           else
12183             output_asm_insn ("fcomip\t{%y1, %0|%0, %y1}", operands);
12184           return output_387_ffreep (operands, 0);
12185         }
12186       else
12187         {
12188           if (unordered_p)
12189             return "fucompp\n\tfnstsw\t%0";
12190           else
12191             return "fcompp\n\tfnstsw\t%0";
12192         }
12193     }
12194   else
12195     {
12196       /* Encoded here as eflags_p | intmode | unordered_p | stack_top_dies.  */
12197
12198       static const char * const alt[16] =
12199       {
12200         "fcom%z2\t%y2\n\tfnstsw\t%0",
12201         "fcomp%z2\t%y2\n\tfnstsw\t%0",
12202         "fucom%z2\t%y2\n\tfnstsw\t%0",
12203         "fucomp%z2\t%y2\n\tfnstsw\t%0",
12204
12205         "ficom%z2\t%y2\n\tfnstsw\t%0",
12206         "ficomp%z2\t%y2\n\tfnstsw\t%0",
12207         NULL,
12208         NULL,
12209
12210         "fcomi\t{%y1, %0|%0, %y1}",
12211         "fcomip\t{%y1, %0|%0, %y1}",
12212         "fucomi\t{%y1, %0|%0, %y1}",
12213         "fucomip\t{%y1, %0|%0, %y1}",
12214
12215         NULL,
12216         NULL,
12217         NULL,
12218         NULL
12219       };
12220
12221       int mask;
12222       const char *ret;
12223
12224       mask  = eflags_p << 3;
12225       mask |= (GET_MODE_CLASS (GET_MODE (cmp_op1)) == MODE_INT) << 2;
12226       mask |= unordered_p << 1;
12227       mask |= stack_top_dies;
12228
12229       gcc_assert (mask < 16);
12230       ret = alt[mask];
12231       gcc_assert (ret);
12232
12233       return ret;
12234     }
12235 }
12236
12237 void
12238 ix86_output_addr_vec_elt (FILE *file, int value)
12239 {
12240   const char *directive = ASM_LONG;
12241
12242 #ifdef ASM_QUAD
12243   if (TARGET_64BIT)
12244     directive = ASM_QUAD;
12245 #else
12246   gcc_assert (!TARGET_64BIT);
12247 #endif
12248
12249   fprintf (file, "%s%s%d\n", directive, LPREFIX, value);
12250 }
12251
12252 void
12253 ix86_output_addr_diff_elt (FILE *file, int value, int rel)
12254 {
12255   const char *directive = ASM_LONG;
12256
12257 #ifdef ASM_QUAD
12258   if (TARGET_64BIT && CASE_VECTOR_MODE == DImode)
12259     directive = ASM_QUAD;
12260 #else
12261   gcc_assert (!TARGET_64BIT);
12262 #endif
12263   /* We can't use @GOTOFF for text labels on VxWorks; see gotoff_operand.  */
12264   if (TARGET_64BIT || TARGET_VXWORKS_RTP)
12265     fprintf (file, "%s%s%d-%s%d\n",
12266              directive, LPREFIX, value, LPREFIX, rel);
12267   else if (HAVE_AS_GOTOFF_IN_DATA)
12268     fprintf (file, "%s%s%d@GOTOFF\n", ASM_LONG, LPREFIX, value);
12269 #if TARGET_MACHO
12270   else if (TARGET_MACHO)
12271     {
12272       fprintf (file, "%s%s%d-", ASM_LONG, LPREFIX, value);
12273       machopic_output_function_base_name (file);
12274       fprintf(file, "\n");
12275     }
12276 #endif
12277   else
12278     asm_fprintf (file, "%s%U%s+[.-%s%d]\n",
12279                  ASM_LONG, GOT_SYMBOL_NAME, LPREFIX, value);
12280 }
12281 \f
12282 /* Generate either "mov $0, reg" or "xor reg, reg", as appropriate
12283    for the target.  */
12284
12285 void
12286 ix86_expand_clear (rtx dest)
12287 {
12288   rtx tmp;
12289
12290   /* We play register width games, which are only valid after reload.  */
12291   gcc_assert (reload_completed);
12292
12293   /* Avoid HImode and its attendant prefix byte.  */
12294   if (GET_MODE_SIZE (GET_MODE (dest)) < 4)
12295     dest = gen_rtx_REG (SImode, REGNO (dest));
12296   tmp = gen_rtx_SET (VOIDmode, dest, const0_rtx);
12297
12298   /* This predicate should match that for movsi_xor and movdi_xor_rex64.  */
12299   if (reload_completed && (!TARGET_USE_MOV0 || optimize_insn_for_speed_p ()))
12300     {
12301       rtx clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12302       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob));
12303     }
12304
12305   emit_insn (tmp);
12306 }
12307
12308 /* X is an unchanging MEM.  If it is a constant pool reference, return
12309    the constant pool rtx, else NULL.  */
12310
12311 rtx
12312 maybe_get_pool_constant (rtx x)
12313 {
12314   x = ix86_delegitimize_address (XEXP (x, 0));
12315
12316   if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x))
12317     return get_pool_constant (x);
12318
12319   return NULL_RTX;
12320 }
12321
12322 void
12323 ix86_expand_move (enum machine_mode mode, rtx operands[])
12324 {
12325   rtx op0, op1;
12326   enum tls_model model;
12327
12328   op0 = operands[0];
12329   op1 = operands[1];
12330
12331   if (GET_CODE (op1) == SYMBOL_REF)
12332     {
12333       model = SYMBOL_REF_TLS_MODEL (op1);
12334       if (model)
12335         {
12336           op1 = legitimize_tls_address (op1, model, true);
12337           op1 = force_operand (op1, op0);
12338           if (op1 == op0)
12339             return;
12340         }
12341       else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
12342                && SYMBOL_REF_DLLIMPORT_P (op1))
12343         op1 = legitimize_dllimport_symbol (op1, false);
12344     }
12345   else if (GET_CODE (op1) == CONST
12346            && GET_CODE (XEXP (op1, 0)) == PLUS
12347            && GET_CODE (XEXP (XEXP (op1, 0), 0)) == SYMBOL_REF)
12348     {
12349       rtx addend = XEXP (XEXP (op1, 0), 1);
12350       rtx symbol = XEXP (XEXP (op1, 0), 0);
12351       rtx tmp = NULL;
12352
12353       model = SYMBOL_REF_TLS_MODEL (symbol);
12354       if (model)
12355         tmp = legitimize_tls_address (symbol, model, true);
12356       else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
12357                && SYMBOL_REF_DLLIMPORT_P (symbol))
12358         tmp = legitimize_dllimport_symbol (symbol, true);
12359
12360       if (tmp)
12361         {
12362           tmp = force_operand (tmp, NULL);
12363           tmp = expand_simple_binop (Pmode, PLUS, tmp, addend,
12364                                      op0, 1, OPTAB_DIRECT);
12365           if (tmp == op0)
12366             return;
12367         }
12368     }
12369
12370   if (flag_pic && mode == Pmode && symbolic_operand (op1, Pmode))
12371     {
12372       if (TARGET_MACHO && !TARGET_64BIT)
12373         {
12374 #if TARGET_MACHO
12375           if (MACHOPIC_PURE)
12376             {
12377               rtx temp = ((reload_in_progress
12378                            || ((op0 && REG_P (op0))
12379                                && mode == Pmode))
12380                           ? op0 : gen_reg_rtx (Pmode));
12381               op1 = machopic_indirect_data_reference (op1, temp);
12382               op1 = machopic_legitimize_pic_address (op1, mode,
12383                                                      temp == op1 ? 0 : temp);
12384             }
12385           else if (MACHOPIC_INDIRECT)
12386             op1 = machopic_indirect_data_reference (op1, 0);
12387           if (op0 == op1)
12388             return;
12389 #endif
12390         }
12391       else
12392         {
12393           if (MEM_P (op0))
12394             op1 = force_reg (Pmode, op1);
12395           else if (!TARGET_64BIT || !x86_64_movabs_operand (op1, Pmode))
12396             {
12397               rtx reg = !can_create_pseudo_p () ? op0 : NULL_RTX;
12398               op1 = legitimize_pic_address (op1, reg);
12399               if (op0 == op1)
12400                 return;
12401             }
12402         }
12403     }
12404   else
12405     {
12406       if (MEM_P (op0)
12407           && (PUSH_ROUNDING (GET_MODE_SIZE (mode)) != GET_MODE_SIZE (mode)
12408               || !push_operand (op0, mode))
12409           && MEM_P (op1))
12410         op1 = force_reg (mode, op1);
12411
12412       if (push_operand (op0, mode)
12413           && ! general_no_elim_operand (op1, mode))
12414         op1 = copy_to_mode_reg (mode, op1);
12415
12416       /* Force large constants in 64bit compilation into register
12417          to get them CSEed.  */
12418       if (can_create_pseudo_p ()
12419           && (mode == DImode) && TARGET_64BIT
12420           && immediate_operand (op1, mode)
12421           && !x86_64_zext_immediate_operand (op1, VOIDmode)
12422           && !register_operand (op0, mode)
12423           && optimize)
12424         op1 = copy_to_mode_reg (mode, op1);
12425
12426       if (can_create_pseudo_p ()
12427           && FLOAT_MODE_P (mode)
12428           && GET_CODE (op1) == CONST_DOUBLE)
12429         {
12430           /* If we are loading a floating point constant to a register,
12431              force the value to memory now, since we'll get better code
12432              out the back end.  */
12433
12434           op1 = validize_mem (force_const_mem (mode, op1));
12435           if (!register_operand (op0, mode))
12436             {
12437               rtx temp = gen_reg_rtx (mode);
12438               emit_insn (gen_rtx_SET (VOIDmode, temp, op1));
12439               emit_move_insn (op0, temp);
12440               return;
12441             }
12442         }
12443     }
12444
12445   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
12446 }
12447
12448 void
12449 ix86_expand_vector_move (enum machine_mode mode, rtx operands[])
12450 {
12451   rtx op0 = operands[0], op1 = operands[1];
12452   unsigned int align = GET_MODE_ALIGNMENT (mode);
12453
12454   /* Force constants other than zero into memory.  We do not know how
12455      the instructions used to build constants modify the upper 64 bits
12456      of the register, once we have that information we may be able
12457      to handle some of them more efficiently.  */
12458   if (can_create_pseudo_p ()
12459       && register_operand (op0, mode)
12460       && (CONSTANT_P (op1)
12461           || (GET_CODE (op1) == SUBREG
12462               && CONSTANT_P (SUBREG_REG (op1))))
12463       && standard_sse_constant_p (op1) <= 0)
12464     op1 = validize_mem (force_const_mem (mode, op1));
12465
12466   /* We need to check memory alignment for SSE mode since attribute
12467      can make operands unaligned.  */
12468   if (can_create_pseudo_p ()
12469       && SSE_REG_MODE_P (mode)
12470       && ((MEM_P (op0) && (MEM_ALIGN (op0) < align))
12471           || (MEM_P (op1) && (MEM_ALIGN (op1) < align))))
12472     {
12473       rtx tmp[2];
12474
12475       /* ix86_expand_vector_move_misalign() does not like constants ... */
12476       if (CONSTANT_P (op1)
12477           || (GET_CODE (op1) == SUBREG
12478               && CONSTANT_P (SUBREG_REG (op1))))
12479         op1 = validize_mem (force_const_mem (mode, op1));
12480
12481       /* ... nor both arguments in memory.  */
12482       if (!register_operand (op0, mode)
12483           && !register_operand (op1, mode))
12484         op1 = force_reg (mode, op1);
12485
12486       tmp[0] = op0; tmp[1] = op1;
12487       ix86_expand_vector_move_misalign (mode, tmp);
12488       return;
12489     }
12490
12491   /* Make operand1 a register if it isn't already.  */
12492   if (can_create_pseudo_p ()
12493       && !register_operand (op0, mode)
12494       && !register_operand (op1, mode))
12495     {
12496       emit_move_insn (op0, force_reg (GET_MODE (op0), op1));
12497       return;
12498     }
12499
12500   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
12501 }
12502
12503 /* Implement the movmisalign patterns for SSE.  Non-SSE modes go
12504    straight to ix86_expand_vector_move.  */
12505 /* Code generation for scalar reg-reg moves of single and double precision data:
12506      if (x86_sse_partial_reg_dependency == true | x86_sse_split_regs == true)
12507        movaps reg, reg
12508      else
12509        movss reg, reg
12510      if (x86_sse_partial_reg_dependency == true)
12511        movapd reg, reg
12512      else
12513        movsd reg, reg
12514
12515    Code generation for scalar loads of double precision data:
12516      if (x86_sse_split_regs == true)
12517        movlpd mem, reg      (gas syntax)
12518      else
12519        movsd mem, reg
12520
12521    Code generation for unaligned packed loads of single precision data
12522    (x86_sse_unaligned_move_optimal overrides x86_sse_partial_reg_dependency):
12523      if (x86_sse_unaligned_move_optimal)
12524        movups mem, reg
12525
12526      if (x86_sse_partial_reg_dependency == true)
12527        {
12528          xorps  reg, reg
12529          movlps mem, reg
12530          movhps mem+8, reg
12531        }
12532      else
12533        {
12534          movlps mem, reg
12535          movhps mem+8, reg
12536        }
12537
12538    Code generation for unaligned packed loads of double precision data
12539    (x86_sse_unaligned_move_optimal overrides x86_sse_split_regs):
12540      if (x86_sse_unaligned_move_optimal)
12541        movupd mem, reg
12542
12543      if (x86_sse_split_regs == true)
12544        {
12545          movlpd mem, reg
12546          movhpd mem+8, reg
12547        }
12548      else
12549        {
12550          movsd  mem, reg
12551          movhpd mem+8, reg
12552        }
12553  */
12554
12555 void
12556 ix86_expand_vector_move_misalign (enum machine_mode mode, rtx operands[])
12557 {
12558   rtx op0, op1, m;
12559
12560   op0 = operands[0];
12561   op1 = operands[1];
12562
12563   if (TARGET_AVX)
12564     {
12565       switch (GET_MODE_CLASS (mode))
12566         {
12567         case MODE_VECTOR_INT:
12568         case MODE_INT:
12569           switch (GET_MODE_SIZE (mode))
12570             {
12571             case 16:
12572               op0 = gen_lowpart (V16QImode, op0);
12573               op1 = gen_lowpart (V16QImode, op1);
12574               emit_insn (gen_avx_movdqu (op0, op1));
12575               break;
12576             case 32:
12577               op0 = gen_lowpart (V32QImode, op0);
12578               op1 = gen_lowpart (V32QImode, op1);
12579               emit_insn (gen_avx_movdqu256 (op0, op1));
12580               break;
12581             default:
12582               gcc_unreachable ();
12583             }
12584           break;
12585         case MODE_VECTOR_FLOAT:
12586           op0 = gen_lowpart (mode, op0);
12587           op1 = gen_lowpart (mode, op1);
12588
12589           switch (mode)
12590             { 
12591             case V4SFmode:
12592               emit_insn (gen_avx_movups (op0, op1));
12593               break;
12594             case V8SFmode:
12595               emit_insn (gen_avx_movups256 (op0, op1));
12596               break;
12597             case V2DFmode:
12598               emit_insn (gen_avx_movupd (op0, op1));
12599               break;
12600             case V4DFmode:
12601               emit_insn (gen_avx_movupd256 (op0, op1));
12602               break;
12603             default:
12604               gcc_unreachable ();
12605             }
12606           break;
12607
12608         default:
12609           gcc_unreachable ();
12610         }
12611
12612       return;
12613     }
12614
12615   if (MEM_P (op1))
12616     {
12617       /* If we're optimizing for size, movups is the smallest.  */
12618       if (optimize_insn_for_size_p ())
12619         {
12620           op0 = gen_lowpart (V4SFmode, op0);
12621           op1 = gen_lowpart (V4SFmode, op1);
12622           emit_insn (gen_sse_movups (op0, op1));
12623           return;
12624         }
12625
12626       /* ??? If we have typed data, then it would appear that using
12627          movdqu is the only way to get unaligned data loaded with
12628          integer type.  */
12629       if (TARGET_SSE2 && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
12630         {
12631           op0 = gen_lowpart (V16QImode, op0);
12632           op1 = gen_lowpart (V16QImode, op1);
12633           emit_insn (gen_sse2_movdqu (op0, op1));
12634           return;
12635         }
12636
12637       if (TARGET_SSE2 && mode == V2DFmode)
12638         {
12639           rtx zero;
12640
12641           if (TARGET_SSE_UNALIGNED_MOVE_OPTIMAL)
12642             {
12643               op0 = gen_lowpart (V2DFmode, op0);
12644               op1 = gen_lowpart (V2DFmode, op1);
12645               emit_insn (gen_sse2_movupd (op0, op1));
12646               return;
12647             }
12648
12649           /* When SSE registers are split into halves, we can avoid
12650              writing to the top half twice.  */
12651           if (TARGET_SSE_SPLIT_REGS)
12652             {
12653               emit_clobber (op0);
12654               zero = op0;
12655             }
12656           else
12657             {
12658               /* ??? Not sure about the best option for the Intel chips.
12659                  The following would seem to satisfy; the register is
12660                  entirely cleared, breaking the dependency chain.  We
12661                  then store to the upper half, with a dependency depth
12662                  of one.  A rumor has it that Intel recommends two movsd
12663                  followed by an unpacklpd, but this is unconfirmed.  And
12664                  given that the dependency depth of the unpacklpd would
12665                  still be one, I'm not sure why this would be better.  */
12666               zero = CONST0_RTX (V2DFmode);
12667             }
12668
12669           m = adjust_address (op1, DFmode, 0);
12670           emit_insn (gen_sse2_loadlpd (op0, zero, m));
12671           m = adjust_address (op1, DFmode, 8);
12672           emit_insn (gen_sse2_loadhpd (op0, op0, m));
12673         }
12674       else
12675         {
12676           if (TARGET_SSE_UNALIGNED_MOVE_OPTIMAL)
12677             {
12678               op0 = gen_lowpart (V4SFmode, op0);
12679               op1 = gen_lowpart (V4SFmode, op1);
12680               emit_insn (gen_sse_movups (op0, op1));
12681               return;
12682             }
12683
12684           if (TARGET_SSE_PARTIAL_REG_DEPENDENCY)
12685             emit_move_insn (op0, CONST0_RTX (mode));
12686           else
12687             emit_clobber (op0);
12688
12689           if (mode != V4SFmode)
12690             op0 = gen_lowpart (V4SFmode, op0);
12691           m = adjust_address (op1, V2SFmode, 0);
12692           emit_insn (gen_sse_loadlps (op0, op0, m));
12693           m = adjust_address (op1, V2SFmode, 8);
12694           emit_insn (gen_sse_loadhps (op0, op0, m));
12695         }
12696     }
12697   else if (MEM_P (op0))
12698     {
12699       /* If we're optimizing for size, movups is the smallest.  */
12700       if (optimize_insn_for_size_p ())
12701         {
12702           op0 = gen_lowpart (V4SFmode, op0);
12703           op1 = gen_lowpart (V4SFmode, op1);
12704           emit_insn (gen_sse_movups (op0, op1));
12705           return;
12706         }
12707
12708       /* ??? Similar to above, only less clear because of quote
12709          typeless stores unquote.  */
12710       if (TARGET_SSE2 && !TARGET_SSE_TYPELESS_STORES
12711           && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
12712         {
12713           op0 = gen_lowpart (V16QImode, op0);
12714           op1 = gen_lowpart (V16QImode, op1);
12715           emit_insn (gen_sse2_movdqu (op0, op1));
12716           return;
12717         }
12718
12719       if (TARGET_SSE2 && mode == V2DFmode)
12720         {
12721           m = adjust_address (op0, DFmode, 0);
12722           emit_insn (gen_sse2_storelpd (m, op1));
12723           m = adjust_address (op0, DFmode, 8);
12724           emit_insn (gen_sse2_storehpd (m, op1));
12725         }
12726       else
12727         {
12728           if (mode != V4SFmode)
12729             op1 = gen_lowpart (V4SFmode, op1);
12730           m = adjust_address (op0, V2SFmode, 0);
12731           emit_insn (gen_sse_storelps (m, op1));
12732           m = adjust_address (op0, V2SFmode, 8);
12733           emit_insn (gen_sse_storehps (m, op1));
12734         }
12735     }
12736   else
12737     gcc_unreachable ();
12738 }
12739
12740 /* Expand a push in MODE.  This is some mode for which we do not support
12741    proper push instructions, at least from the registers that we expect
12742    the value to live in.  */
12743
12744 void
12745 ix86_expand_push (enum machine_mode mode, rtx x)
12746 {
12747   rtx tmp;
12748
12749   tmp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
12750                              GEN_INT (-GET_MODE_SIZE (mode)),
12751                              stack_pointer_rtx, 1, OPTAB_DIRECT);
12752   if (tmp != stack_pointer_rtx)
12753     emit_move_insn (stack_pointer_rtx, tmp);
12754
12755   tmp = gen_rtx_MEM (mode, stack_pointer_rtx);
12756
12757   /* When we push an operand onto stack, it has to be aligned at least
12758      at the function argument boundary.  However since we don't have
12759      the argument type, we can't determine the actual argument
12760      boundary.  */
12761   emit_move_insn (tmp, x);
12762 }
12763
12764 /* Helper function of ix86_fixup_binary_operands to canonicalize
12765    operand order.  Returns true if the operands should be swapped.  */
12766
12767 static bool
12768 ix86_swap_binary_operands_p (enum rtx_code code, enum machine_mode mode,
12769                              rtx operands[])
12770 {
12771   rtx dst = operands[0];
12772   rtx src1 = operands[1];
12773   rtx src2 = operands[2];
12774
12775   /* If the operation is not commutative, we can't do anything.  */
12776   if (GET_RTX_CLASS (code) != RTX_COMM_ARITH)
12777     return false;
12778
12779   /* Highest priority is that src1 should match dst.  */
12780   if (rtx_equal_p (dst, src1))
12781     return false;
12782   if (rtx_equal_p (dst, src2))
12783     return true;
12784
12785   /* Next highest priority is that immediate constants come second.  */
12786   if (immediate_operand (src2, mode))
12787     return false;
12788   if (immediate_operand (src1, mode))
12789     return true;
12790
12791   /* Lowest priority is that memory references should come second.  */
12792   if (MEM_P (src2))
12793     return false;
12794   if (MEM_P (src1))
12795     return true;
12796
12797   return false;
12798 }
12799
12800
12801 /* Fix up OPERANDS to satisfy ix86_binary_operator_ok.  Return the
12802    destination to use for the operation.  If different from the true
12803    destination in operands[0], a copy operation will be required.  */
12804
12805 rtx
12806 ix86_fixup_binary_operands (enum rtx_code code, enum machine_mode mode,
12807                             rtx operands[])
12808 {
12809   rtx dst = operands[0];
12810   rtx src1 = operands[1];
12811   rtx src2 = operands[2];
12812
12813   /* Canonicalize operand order.  */
12814   if (ix86_swap_binary_operands_p (code, mode, operands))
12815     {
12816       rtx temp;
12817
12818       /* It is invalid to swap operands of different modes.  */
12819       gcc_assert (GET_MODE (src1) == GET_MODE (src2));
12820
12821       temp = src1;
12822       src1 = src2;
12823       src2 = temp;
12824     }
12825
12826   /* Both source operands cannot be in memory.  */
12827   if (MEM_P (src1) && MEM_P (src2))
12828     {
12829       /* Optimization: Only read from memory once.  */
12830       if (rtx_equal_p (src1, src2))
12831         {
12832           src2 = force_reg (mode, src2);
12833           src1 = src2;
12834         }
12835       else
12836         src2 = force_reg (mode, src2);
12837     }
12838
12839   /* If the destination is memory, and we do not have matching source
12840      operands, do things in registers.  */
12841   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
12842     dst = gen_reg_rtx (mode);
12843
12844   /* Source 1 cannot be a constant.  */
12845   if (CONSTANT_P (src1))
12846     src1 = force_reg (mode, src1);
12847
12848   /* Source 1 cannot be a non-matching memory.  */
12849   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
12850     src1 = force_reg (mode, src1);
12851
12852   operands[1] = src1;
12853   operands[2] = src2;
12854   return dst;
12855 }
12856
12857 /* Similarly, but assume that the destination has already been
12858    set up properly.  */
12859
12860 void
12861 ix86_fixup_binary_operands_no_copy (enum rtx_code code,
12862                                     enum machine_mode mode, rtx operands[])
12863 {
12864   rtx dst = ix86_fixup_binary_operands (code, mode, operands);
12865   gcc_assert (dst == operands[0]);
12866 }
12867
12868 /* Attempt to expand a binary operator.  Make the expansion closer to the
12869    actual machine, then just general_operand, which will allow 3 separate
12870    memory references (one output, two input) in a single insn.  */
12871
12872 void
12873 ix86_expand_binary_operator (enum rtx_code code, enum machine_mode mode,
12874                              rtx operands[])
12875 {
12876   rtx src1, src2, dst, op, clob;
12877
12878   dst = ix86_fixup_binary_operands (code, mode, operands);
12879   src1 = operands[1];
12880   src2 = operands[2];
12881
12882  /* Emit the instruction.  */
12883
12884   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_ee (code, mode, src1, src2));
12885   if (reload_in_progress)
12886     {
12887       /* Reload doesn't know about the flags register, and doesn't know that
12888          it doesn't want to clobber it.  We can only do this with PLUS.  */
12889       gcc_assert (code == PLUS);
12890       emit_insn (op);
12891     }
12892   else
12893     {
12894       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12895       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
12896     }
12897
12898   /* Fix up the destination if needed.  */
12899   if (dst != operands[0])
12900     emit_move_insn (operands[0], dst);
12901 }
12902
12903 /* Return TRUE or FALSE depending on whether the binary operator meets the
12904    appropriate constraints.  */
12905
12906 int
12907 ix86_binary_operator_ok (enum rtx_code code, enum machine_mode mode,
12908                          rtx operands[3])
12909 {
12910   rtx dst = operands[0];
12911   rtx src1 = operands[1];
12912   rtx src2 = operands[2];
12913
12914   /* Both source operands cannot be in memory.  */
12915   if (MEM_P (src1) && MEM_P (src2))
12916     return 0;
12917
12918   /* Canonicalize operand order for commutative operators.  */
12919   if (ix86_swap_binary_operands_p (code, mode, operands))
12920     {
12921       rtx temp = src1;
12922       src1 = src2;
12923       src2 = temp;
12924     }
12925
12926   /* If the destination is memory, we must have a matching source operand.  */
12927   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
12928       return 0;
12929
12930   /* Source 1 cannot be a constant.  */
12931   if (CONSTANT_P (src1))
12932     return 0;
12933
12934   /* Source 1 cannot be a non-matching memory.  */
12935   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
12936     return 0;
12937
12938   return 1;
12939 }
12940
12941 /* Attempt to expand a unary operator.  Make the expansion closer to the
12942    actual machine, then just general_operand, which will allow 2 separate
12943    memory references (one output, one input) in a single insn.  */
12944
12945 void
12946 ix86_expand_unary_operator (enum rtx_code code, enum machine_mode mode,
12947                             rtx operands[])
12948 {
12949   int matching_memory;
12950   rtx src, dst, op, clob;
12951
12952   dst = operands[0];
12953   src = operands[1];
12954
12955   /* If the destination is memory, and we do not have matching source
12956      operands, do things in registers.  */
12957   matching_memory = 0;
12958   if (MEM_P (dst))
12959     {
12960       if (rtx_equal_p (dst, src))
12961         matching_memory = 1;
12962       else
12963         dst = gen_reg_rtx (mode);
12964     }
12965
12966   /* When source operand is memory, destination must match.  */
12967   if (MEM_P (src) && !matching_memory)
12968     src = force_reg (mode, src);
12969
12970   /* Emit the instruction.  */
12971
12972   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_e (code, mode, src));
12973   if (reload_in_progress || code == NOT)
12974     {
12975       /* Reload doesn't know about the flags register, and doesn't know that
12976          it doesn't want to clobber it.  */
12977       gcc_assert (code == NOT);
12978       emit_insn (op);
12979     }
12980   else
12981     {
12982       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12983       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
12984     }
12985
12986   /* Fix up the destination if needed.  */
12987   if (dst != operands[0])
12988     emit_move_insn (operands[0], dst);
12989 }
12990
12991 /* Return TRUE or FALSE depending on whether the unary operator meets the
12992    appropriate constraints.  */
12993
12994 int
12995 ix86_unary_operator_ok (enum rtx_code code ATTRIBUTE_UNUSED,
12996                         enum machine_mode mode ATTRIBUTE_UNUSED,
12997                         rtx operands[2] ATTRIBUTE_UNUSED)
12998 {
12999   /* If one of operands is memory, source and destination must match.  */
13000   if ((MEM_P (operands[0])
13001        || MEM_P (operands[1]))
13002       && ! rtx_equal_p (operands[0], operands[1]))
13003     return FALSE;
13004   return TRUE;
13005 }
13006
13007 /* Post-reload splitter for converting an SF or DFmode value in an
13008    SSE register into an unsigned SImode.  */
13009
13010 void
13011 ix86_split_convert_uns_si_sse (rtx operands[])
13012 {
13013   enum machine_mode vecmode;
13014   rtx value, large, zero_or_two31, input, two31, x;
13015
13016   large = operands[1];
13017   zero_or_two31 = operands[2];
13018   input = operands[3];
13019   two31 = operands[4];
13020   vecmode = GET_MODE (large);
13021   value = gen_rtx_REG (vecmode, REGNO (operands[0]));
13022
13023   /* Load up the value into the low element.  We must ensure that the other
13024      elements are valid floats -- zero is the easiest such value.  */
13025   if (MEM_P (input))
13026     {
13027       if (vecmode == V4SFmode)
13028         emit_insn (gen_vec_setv4sf_0 (value, CONST0_RTX (V4SFmode), input));
13029       else
13030         emit_insn (gen_sse2_loadlpd (value, CONST0_RTX (V2DFmode), input));
13031     }
13032   else
13033     {
13034       input = gen_rtx_REG (vecmode, REGNO (input));
13035       emit_move_insn (value, CONST0_RTX (vecmode));
13036       if (vecmode == V4SFmode)
13037         emit_insn (gen_sse_movss (value, value, input));
13038       else
13039         emit_insn (gen_sse2_movsd (value, value, input));
13040     }
13041
13042   emit_move_insn (large, two31);
13043   emit_move_insn (zero_or_two31, MEM_P (two31) ? large : two31);
13044
13045   x = gen_rtx_fmt_ee (LE, vecmode, large, value);
13046   emit_insn (gen_rtx_SET (VOIDmode, large, x));
13047
13048   x = gen_rtx_AND (vecmode, zero_or_two31, large);
13049   emit_insn (gen_rtx_SET (VOIDmode, zero_or_two31, x));
13050
13051   x = gen_rtx_MINUS (vecmode, value, zero_or_two31);
13052   emit_insn (gen_rtx_SET (VOIDmode, value, x));
13053
13054   large = gen_rtx_REG (V4SImode, REGNO (large));
13055   emit_insn (gen_ashlv4si3 (large, large, GEN_INT (31)));
13056
13057   x = gen_rtx_REG (V4SImode, REGNO (value));
13058   if (vecmode == V4SFmode)
13059     emit_insn (gen_sse2_cvttps2dq (x, value));
13060   else
13061     emit_insn (gen_sse2_cvttpd2dq (x, value));
13062   value = x;
13063
13064   emit_insn (gen_xorv4si3 (value, value, large));
13065 }
13066
13067 /* Convert an unsigned DImode value into a DFmode, using only SSE.
13068    Expects the 64-bit DImode to be supplied in a pair of integral
13069    registers.  Requires SSE2; will use SSE3 if available.  For x86_32,
13070    -mfpmath=sse, !optimize_size only.  */
13071
13072 void
13073 ix86_expand_convert_uns_didf_sse (rtx target, rtx input)
13074 {
13075   REAL_VALUE_TYPE bias_lo_rvt, bias_hi_rvt;
13076   rtx int_xmm, fp_xmm;
13077   rtx biases, exponents;
13078   rtx x;
13079
13080   int_xmm = gen_reg_rtx (V4SImode);
13081   if (TARGET_INTER_UNIT_MOVES)
13082     emit_insn (gen_movdi_to_sse (int_xmm, input));
13083   else if (TARGET_SSE_SPLIT_REGS)
13084     {
13085       emit_clobber (int_xmm);
13086       emit_move_insn (gen_lowpart (DImode, int_xmm), input);
13087     }
13088   else
13089     {
13090       x = gen_reg_rtx (V2DImode);
13091       ix86_expand_vector_init_one_nonzero (false, V2DImode, x, input, 0);
13092       emit_move_insn (int_xmm, gen_lowpart (V4SImode, x));
13093     }
13094
13095   x = gen_rtx_CONST_VECTOR (V4SImode,
13096                             gen_rtvec (4, GEN_INT (0x43300000UL),
13097                                        GEN_INT (0x45300000UL),
13098                                        const0_rtx, const0_rtx));
13099   exponents = validize_mem (force_const_mem (V4SImode, x));
13100
13101   /* int_xmm = {0x45300000UL, fp_xmm/hi, 0x43300000, fp_xmm/lo } */
13102   emit_insn (gen_sse2_punpckldq (int_xmm, int_xmm, exponents));
13103
13104   /* Concatenating (juxtaposing) (0x43300000UL ## fp_value_low_xmm)
13105      yields a valid DF value equal to (0x1.0p52 + double(fp_value_lo_xmm)).
13106      Similarly (0x45300000UL ## fp_value_hi_xmm) yields
13107      (0x1.0p84 + double(fp_value_hi_xmm)).
13108      Note these exponents differ by 32.  */
13109
13110   fp_xmm = copy_to_mode_reg (V2DFmode, gen_lowpart (V2DFmode, int_xmm));
13111
13112   /* Subtract off those 0x1.0p52 and 0x1.0p84 biases, to produce values
13113      in [0,2**32-1] and [0]+[2**32,2**64-1] respectively.  */
13114   real_ldexp (&bias_lo_rvt, &dconst1, 52);
13115   real_ldexp (&bias_hi_rvt, &dconst1, 84);
13116   biases = const_double_from_real_value (bias_lo_rvt, DFmode);
13117   x = const_double_from_real_value (bias_hi_rvt, DFmode);
13118   biases = gen_rtx_CONST_VECTOR (V2DFmode, gen_rtvec (2, biases, x));
13119   biases = validize_mem (force_const_mem (V2DFmode, biases));
13120   emit_insn (gen_subv2df3 (fp_xmm, fp_xmm, biases));
13121
13122   /* Add the upper and lower DFmode values together.  */
13123   if (TARGET_SSE3)
13124     emit_insn (gen_sse3_haddv2df3 (fp_xmm, fp_xmm, fp_xmm));
13125   else
13126     {
13127       x = copy_to_mode_reg (V2DFmode, fp_xmm);
13128       emit_insn (gen_sse2_unpckhpd (fp_xmm, fp_xmm, fp_xmm));
13129       emit_insn (gen_addv2df3 (fp_xmm, fp_xmm, x));
13130     }
13131
13132   ix86_expand_vector_extract (false, target, fp_xmm, 0);
13133 }
13134
13135 /* Not used, but eases macroization of patterns.  */
13136 void
13137 ix86_expand_convert_uns_sixf_sse (rtx target ATTRIBUTE_UNUSED,
13138                                   rtx input ATTRIBUTE_UNUSED)
13139 {
13140   gcc_unreachable ();
13141 }
13142
13143 /* Convert an unsigned SImode value into a DFmode.  Only currently used
13144    for SSE, but applicable anywhere.  */
13145
13146 void
13147 ix86_expand_convert_uns_sidf_sse (rtx target, rtx input)
13148 {
13149   REAL_VALUE_TYPE TWO31r;
13150   rtx x, fp;
13151
13152   x = expand_simple_binop (SImode, PLUS, input, GEN_INT (-2147483647 - 1),
13153                            NULL, 1, OPTAB_DIRECT);
13154
13155   fp = gen_reg_rtx (DFmode);
13156   emit_insn (gen_floatsidf2 (fp, x));
13157
13158   real_ldexp (&TWO31r, &dconst1, 31);
13159   x = const_double_from_real_value (TWO31r, DFmode);
13160
13161   x = expand_simple_binop (DFmode, PLUS, fp, x, target, 0, OPTAB_DIRECT);
13162   if (x != target)
13163     emit_move_insn (target, x);
13164 }
13165
13166 /* Convert a signed DImode value into a DFmode.  Only used for SSE in
13167    32-bit mode; otherwise we have a direct convert instruction.  */
13168
13169 void
13170 ix86_expand_convert_sign_didf_sse (rtx target, rtx input)
13171 {
13172   REAL_VALUE_TYPE TWO32r;
13173   rtx fp_lo, fp_hi, x;
13174
13175   fp_lo = gen_reg_rtx (DFmode);
13176   fp_hi = gen_reg_rtx (DFmode);
13177
13178   emit_insn (gen_floatsidf2 (fp_hi, gen_highpart (SImode, input)));
13179
13180   real_ldexp (&TWO32r, &dconst1, 32);
13181   x = const_double_from_real_value (TWO32r, DFmode);
13182   fp_hi = expand_simple_binop (DFmode, MULT, fp_hi, x, fp_hi, 0, OPTAB_DIRECT);
13183
13184   ix86_expand_convert_uns_sidf_sse (fp_lo, gen_lowpart (SImode, input));
13185
13186   x = expand_simple_binop (DFmode, PLUS, fp_hi, fp_lo, target,
13187                            0, OPTAB_DIRECT);
13188   if (x != target)
13189     emit_move_insn (target, x);
13190 }
13191
13192 /* Convert an unsigned SImode value into a SFmode, using only SSE.
13193    For x86_32, -mfpmath=sse, !optimize_size only.  */
13194 void
13195 ix86_expand_convert_uns_sisf_sse (rtx target, rtx input)
13196 {
13197   REAL_VALUE_TYPE ONE16r;
13198   rtx fp_hi, fp_lo, int_hi, int_lo, x;
13199
13200   real_ldexp (&ONE16r, &dconst1, 16);
13201   x = const_double_from_real_value (ONE16r, SFmode);
13202   int_lo = expand_simple_binop (SImode, AND, input, GEN_INT(0xffff),
13203                                       NULL, 0, OPTAB_DIRECT);
13204   int_hi = expand_simple_binop (SImode, LSHIFTRT, input, GEN_INT(16),
13205                                       NULL, 0, OPTAB_DIRECT);
13206   fp_hi = gen_reg_rtx (SFmode);
13207   fp_lo = gen_reg_rtx (SFmode);
13208   emit_insn (gen_floatsisf2 (fp_hi, int_hi));
13209   emit_insn (gen_floatsisf2 (fp_lo, int_lo));
13210   fp_hi = expand_simple_binop (SFmode, MULT, fp_hi, x, fp_hi,
13211                                0, OPTAB_DIRECT);
13212   fp_hi = expand_simple_binop (SFmode, PLUS, fp_hi, fp_lo, target,
13213                                0, OPTAB_DIRECT);
13214   if (!rtx_equal_p (target, fp_hi))
13215     emit_move_insn (target, fp_hi);
13216 }
13217
13218 /* A subroutine of ix86_build_signbit_mask_vector.  If VECT is true,
13219    then replicate the value for all elements of the vector
13220    register.  */
13221
13222 rtx
13223 ix86_build_const_vector (enum machine_mode mode, bool vect, rtx value)
13224 {
13225   rtvec v;
13226   switch (mode)
13227     {
13228     case SImode:
13229       gcc_assert (vect);
13230       v = gen_rtvec (4, value, value, value, value);
13231       return gen_rtx_CONST_VECTOR (V4SImode, v);
13232
13233     case DImode:
13234       gcc_assert (vect);
13235       v = gen_rtvec (2, value, value);
13236       return gen_rtx_CONST_VECTOR (V2DImode, v);
13237
13238     case SFmode:
13239       if (vect)
13240         v = gen_rtvec (4, value, value, value, value);
13241       else
13242         v = gen_rtvec (4, value, CONST0_RTX (SFmode),
13243                        CONST0_RTX (SFmode), CONST0_RTX (SFmode));
13244       return gen_rtx_CONST_VECTOR (V4SFmode, v);
13245
13246     case DFmode:
13247       if (vect)
13248         v = gen_rtvec (2, value, value);
13249       else
13250         v = gen_rtvec (2, value, CONST0_RTX (DFmode));
13251       return gen_rtx_CONST_VECTOR (V2DFmode, v);
13252
13253     default:
13254       gcc_unreachable ();
13255     }
13256 }
13257
13258 /* A subroutine of ix86_expand_fp_absneg_operator, copysign expanders
13259    and ix86_expand_int_vcond.  Create a mask for the sign bit in MODE
13260    for an SSE register.  If VECT is true, then replicate the mask for
13261    all elements of the vector register.  If INVERT is true, then create
13262    a mask excluding the sign bit.  */
13263
13264 rtx
13265 ix86_build_signbit_mask (enum machine_mode mode, bool vect, bool invert)
13266 {
13267   enum machine_mode vec_mode, imode;
13268   HOST_WIDE_INT hi, lo;
13269   int shift = 63;
13270   rtx v;
13271   rtx mask;
13272
13273   /* Find the sign bit, sign extended to 2*HWI.  */
13274   switch (mode)
13275     {
13276     case SImode:
13277     case SFmode:
13278       imode = SImode;
13279       vec_mode = (mode == SImode) ? V4SImode : V4SFmode;
13280       lo = 0x80000000, hi = lo < 0;
13281       break;
13282
13283     case DImode:
13284     case DFmode:
13285       imode = DImode;
13286       vec_mode = (mode == DImode) ? V2DImode : V2DFmode;
13287       if (HOST_BITS_PER_WIDE_INT >= 64)
13288         lo = (HOST_WIDE_INT)1 << shift, hi = -1;
13289       else
13290         lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
13291       break;
13292
13293     case TImode:
13294     case TFmode:
13295       vec_mode = VOIDmode;
13296       if (HOST_BITS_PER_WIDE_INT >= 64)
13297         {
13298           imode = TImode;
13299           lo = 0, hi = (HOST_WIDE_INT)1 << shift;
13300         }
13301       else
13302         {
13303           rtvec vec;
13304
13305           imode = DImode;
13306           lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
13307
13308           if (invert)
13309             {
13310               lo = ~lo, hi = ~hi;
13311               v = constm1_rtx;
13312             }
13313           else
13314             v = const0_rtx;
13315
13316           mask = immed_double_const (lo, hi, imode);
13317
13318           vec = gen_rtvec (2, v, mask);
13319           v = gen_rtx_CONST_VECTOR (V2DImode, vec);
13320           v = copy_to_mode_reg (mode, gen_lowpart (mode, v));
13321
13322           return v;
13323         }
13324      break;
13325
13326     default:
13327       gcc_unreachable ();
13328     }
13329
13330   if (invert)
13331     lo = ~lo, hi = ~hi;
13332
13333   /* Force this value into the low part of a fp vector constant.  */
13334   mask = immed_double_const (lo, hi, imode);
13335   mask = gen_lowpart (mode, mask);
13336
13337   if (vec_mode == VOIDmode)
13338     return force_reg (mode, mask);
13339
13340   v = ix86_build_const_vector (mode, vect, mask);
13341   return force_reg (vec_mode, v);
13342 }
13343
13344 /* Generate code for floating point ABS or NEG.  */
13345
13346 void
13347 ix86_expand_fp_absneg_operator (enum rtx_code code, enum machine_mode mode,
13348                                 rtx operands[])
13349 {
13350   rtx mask, set, use, clob, dst, src;
13351   bool use_sse = false;
13352   bool vector_mode = VECTOR_MODE_P (mode);
13353   enum machine_mode elt_mode = mode;
13354
13355   if (vector_mode)
13356     {
13357       elt_mode = GET_MODE_INNER (mode);
13358       use_sse = true;
13359     }
13360   else if (mode == TFmode)
13361     use_sse = true;
13362   else if (TARGET_SSE_MATH)
13363     use_sse = SSE_FLOAT_MODE_P (mode);
13364
13365   /* NEG and ABS performed with SSE use bitwise mask operations.
13366      Create the appropriate mask now.  */
13367   if (use_sse)
13368     mask = ix86_build_signbit_mask (elt_mode, vector_mode, code == ABS);
13369   else
13370     mask = NULL_RTX;
13371
13372   dst = operands[0];
13373   src = operands[1];
13374
13375   if (vector_mode)
13376     {
13377       set = gen_rtx_fmt_ee (code == NEG ? XOR : AND, mode, src, mask);
13378       set = gen_rtx_SET (VOIDmode, dst, set);
13379       emit_insn (set);
13380     }
13381   else
13382     {
13383       set = gen_rtx_fmt_e (code, mode, src);
13384       set = gen_rtx_SET (VOIDmode, dst, set);
13385       if (mask)
13386         {
13387           use = gen_rtx_USE (VOIDmode, mask);
13388           clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
13389           emit_insn (gen_rtx_PARALLEL (VOIDmode,
13390                                        gen_rtvec (3, set, use, clob)));
13391         }
13392       else
13393         emit_insn (set);
13394     }
13395 }
13396
13397 /* Expand a copysign operation.  Special case operand 0 being a constant.  */
13398
13399 void
13400 ix86_expand_copysign (rtx operands[])
13401 {
13402   enum machine_mode mode;
13403   rtx dest, op0, op1, mask, nmask;
13404
13405   dest = operands[0];
13406   op0 = operands[1];
13407   op1 = operands[2];
13408
13409   mode = GET_MODE (dest);
13410
13411   if (GET_CODE (op0) == CONST_DOUBLE)
13412     {
13413       rtx (*copysign_insn)(rtx, rtx, rtx, rtx);
13414
13415       if (real_isneg (CONST_DOUBLE_REAL_VALUE (op0)))
13416         op0 = simplify_unary_operation (ABS, mode, op0, mode);
13417
13418       if (mode == SFmode || mode == DFmode)
13419         {
13420           enum machine_mode vmode;
13421
13422           vmode = mode == SFmode ? V4SFmode : V2DFmode;
13423
13424           if (op0 == CONST0_RTX (mode))
13425             op0 = CONST0_RTX (vmode);
13426           else
13427             {
13428               rtvec v;
13429
13430               if (mode == SFmode)
13431                 v = gen_rtvec (4, op0, CONST0_RTX (SFmode),
13432                                CONST0_RTX (SFmode), CONST0_RTX (SFmode));
13433               else
13434                 v = gen_rtvec (2, op0, CONST0_RTX (DFmode));
13435
13436               op0 = force_reg (vmode, gen_rtx_CONST_VECTOR (vmode, v));
13437             }
13438         }
13439       else if (op0 != CONST0_RTX (mode))
13440         op0 = force_reg (mode, op0);
13441
13442       mask = ix86_build_signbit_mask (mode, 0, 0);
13443
13444       if (mode == SFmode)
13445         copysign_insn = gen_copysignsf3_const;
13446       else if (mode == DFmode)
13447         copysign_insn = gen_copysigndf3_const;
13448       else
13449         copysign_insn = gen_copysigntf3_const;
13450
13451         emit_insn (copysign_insn (dest, op0, op1, mask));
13452     }
13453   else
13454     {
13455       rtx (*copysign_insn)(rtx, rtx, rtx, rtx, rtx, rtx);
13456
13457       nmask = ix86_build_signbit_mask (mode, 0, 1);
13458       mask = ix86_build_signbit_mask (mode, 0, 0);
13459
13460       if (mode == SFmode)
13461         copysign_insn = gen_copysignsf3_var;
13462       else if (mode == DFmode)
13463         copysign_insn = gen_copysigndf3_var;
13464       else
13465         copysign_insn = gen_copysigntf3_var;
13466
13467       emit_insn (copysign_insn (dest, NULL_RTX, op0, op1, nmask, mask));
13468     }
13469 }
13470
13471 /* Deconstruct a copysign operation into bit masks.  Operand 0 is known to
13472    be a constant, and so has already been expanded into a vector constant.  */
13473
13474 void
13475 ix86_split_copysign_const (rtx operands[])
13476 {
13477   enum machine_mode mode, vmode;
13478   rtx dest, op0, op1, mask, x;
13479
13480   dest = operands[0];
13481   op0 = operands[1];
13482   op1 = operands[2];
13483   mask = operands[3];
13484
13485   mode = GET_MODE (dest);
13486   vmode = GET_MODE (mask);
13487
13488   dest = simplify_gen_subreg (vmode, dest, mode, 0);
13489   x = gen_rtx_AND (vmode, dest, mask);
13490   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13491
13492   if (op0 != CONST0_RTX (vmode))
13493     {
13494       x = gen_rtx_IOR (vmode, dest, op0);
13495       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13496     }
13497 }
13498
13499 /* Deconstruct a copysign operation into bit masks.  Operand 0 is variable,
13500    so we have to do two masks.  */
13501
13502 void
13503 ix86_split_copysign_var (rtx operands[])
13504 {
13505   enum machine_mode mode, vmode;
13506   rtx dest, scratch, op0, op1, mask, nmask, x;
13507
13508   dest = operands[0];
13509   scratch = operands[1];
13510   op0 = operands[2];
13511   op1 = operands[3];
13512   nmask = operands[4];
13513   mask = operands[5];
13514
13515   mode = GET_MODE (dest);
13516   vmode = GET_MODE (mask);
13517
13518   if (rtx_equal_p (op0, op1))
13519     {
13520       /* Shouldn't happen often (it's useless, obviously), but when it does
13521          we'd generate incorrect code if we continue below.  */
13522       emit_move_insn (dest, op0);
13523       return;
13524     }
13525
13526   if (REG_P (mask) && REGNO (dest) == REGNO (mask))     /* alternative 0 */
13527     {
13528       gcc_assert (REGNO (op1) == REGNO (scratch));
13529
13530       x = gen_rtx_AND (vmode, scratch, mask);
13531       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
13532
13533       dest = mask;
13534       op0 = simplify_gen_subreg (vmode, op0, mode, 0);
13535       x = gen_rtx_NOT (vmode, dest);
13536       x = gen_rtx_AND (vmode, x, op0);
13537       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13538     }
13539   else
13540     {
13541       if (REGNO (op1) == REGNO (scratch))               /* alternative 1,3 */
13542         {
13543           x = gen_rtx_AND (vmode, scratch, mask);
13544         }
13545       else                                              /* alternative 2,4 */
13546         {
13547           gcc_assert (REGNO (mask) == REGNO (scratch));
13548           op1 = simplify_gen_subreg (vmode, op1, mode, 0);
13549           x = gen_rtx_AND (vmode, scratch, op1);
13550         }
13551       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
13552
13553       if (REGNO (op0) == REGNO (dest))                  /* alternative 1,2 */
13554         {
13555           dest = simplify_gen_subreg (vmode, op0, mode, 0);
13556           x = gen_rtx_AND (vmode, dest, nmask);
13557         }
13558       else                                              /* alternative 3,4 */
13559         {
13560           gcc_assert (REGNO (nmask) == REGNO (dest));
13561           dest = nmask;
13562           op0 = simplify_gen_subreg (vmode, op0, mode, 0);
13563           x = gen_rtx_AND (vmode, dest, op0);
13564         }
13565       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13566     }
13567
13568   x = gen_rtx_IOR (vmode, dest, scratch);
13569   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13570 }
13571
13572 /* Return TRUE or FALSE depending on whether the first SET in INSN
13573    has source and destination with matching CC modes, and that the
13574    CC mode is at least as constrained as REQ_MODE.  */
13575
13576 int
13577 ix86_match_ccmode (rtx insn, enum machine_mode req_mode)
13578 {
13579   rtx set;
13580   enum machine_mode set_mode;
13581
13582   set = PATTERN (insn);
13583   if (GET_CODE (set) == PARALLEL)
13584     set = XVECEXP (set, 0, 0);
13585   gcc_assert (GET_CODE (set) == SET);
13586   gcc_assert (GET_CODE (SET_SRC (set)) == COMPARE);
13587
13588   set_mode = GET_MODE (SET_DEST (set));
13589   switch (set_mode)
13590     {
13591     case CCNOmode:
13592       if (req_mode != CCNOmode
13593           && (req_mode != CCmode
13594               || XEXP (SET_SRC (set), 1) != const0_rtx))
13595         return 0;
13596       break;
13597     case CCmode:
13598       if (req_mode == CCGCmode)
13599         return 0;
13600       /* FALLTHRU */
13601     case CCGCmode:
13602       if (req_mode == CCGOCmode || req_mode == CCNOmode)
13603         return 0;
13604       /* FALLTHRU */
13605     case CCGOCmode:
13606       if (req_mode == CCZmode)
13607         return 0;
13608       /* FALLTHRU */
13609     case CCAmode:
13610     case CCCmode:
13611     case CCOmode:
13612     case CCSmode:
13613     case CCZmode:
13614       break;
13615
13616     default:
13617       gcc_unreachable ();
13618     }
13619
13620   return (GET_MODE (SET_SRC (set)) == set_mode);
13621 }
13622
13623 /* Generate insn patterns to do an integer compare of OPERANDS.  */
13624
13625 static rtx
13626 ix86_expand_int_compare (enum rtx_code code, rtx op0, rtx op1)
13627 {
13628   enum machine_mode cmpmode;
13629   rtx tmp, flags;
13630
13631   cmpmode = SELECT_CC_MODE (code, op0, op1);
13632   flags = gen_rtx_REG (cmpmode, FLAGS_REG);
13633
13634   /* This is very simple, but making the interface the same as in the
13635      FP case makes the rest of the code easier.  */
13636   tmp = gen_rtx_COMPARE (cmpmode, op0, op1);
13637   emit_insn (gen_rtx_SET (VOIDmode, flags, tmp));
13638
13639   /* Return the test that should be put into the flags user, i.e.
13640      the bcc, scc, or cmov instruction.  */
13641   return gen_rtx_fmt_ee (code, VOIDmode, flags, const0_rtx);
13642 }
13643
13644 /* Figure out whether to use ordered or unordered fp comparisons.
13645    Return the appropriate mode to use.  */
13646
13647 enum machine_mode
13648 ix86_fp_compare_mode (enum rtx_code code ATTRIBUTE_UNUSED)
13649 {
13650   /* ??? In order to make all comparisons reversible, we do all comparisons
13651      non-trapping when compiling for IEEE.  Once gcc is able to distinguish
13652      all forms trapping and nontrapping comparisons, we can make inequality
13653      comparisons trapping again, since it results in better code when using
13654      FCOM based compares.  */
13655   return TARGET_IEEE_FP ? CCFPUmode : CCFPmode;
13656 }
13657
13658 enum machine_mode
13659 ix86_cc_mode (enum rtx_code code, rtx op0, rtx op1)
13660 {
13661   enum machine_mode mode = GET_MODE (op0);
13662
13663   if (SCALAR_FLOAT_MODE_P (mode))
13664     {
13665       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
13666       return ix86_fp_compare_mode (code);
13667     }
13668
13669   switch (code)
13670     {
13671       /* Only zero flag is needed.  */
13672     case EQ:                    /* ZF=0 */
13673     case NE:                    /* ZF!=0 */
13674       return CCZmode;
13675       /* Codes needing carry flag.  */
13676     case GEU:                   /* CF=0 */
13677     case LTU:                   /* CF=1 */
13678       /* Detect overflow checks.  They need just the carry flag.  */
13679       if (GET_CODE (op0) == PLUS
13680           && rtx_equal_p (op1, XEXP (op0, 0)))
13681         return CCCmode;
13682       else
13683         return CCmode;
13684     case GTU:                   /* CF=0 & ZF=0 */
13685     case LEU:                   /* CF=1 | ZF=1 */
13686       /* Detect overflow checks.  They need just the carry flag.  */
13687       if (GET_CODE (op0) == MINUS
13688           && rtx_equal_p (op1, XEXP (op0, 0)))
13689         return CCCmode;
13690       else
13691         return CCmode;
13692       /* Codes possibly doable only with sign flag when
13693          comparing against zero.  */
13694     case GE:                    /* SF=OF   or   SF=0 */
13695     case LT:                    /* SF<>OF  or   SF=1 */
13696       if (op1 == const0_rtx)
13697         return CCGOCmode;
13698       else
13699         /* For other cases Carry flag is not required.  */
13700         return CCGCmode;
13701       /* Codes doable only with sign flag when comparing
13702          against zero, but we miss jump instruction for it
13703          so we need to use relational tests against overflow
13704          that thus needs to be zero.  */
13705     case GT:                    /* ZF=0 & SF=OF */
13706     case LE:                    /* ZF=1 | SF<>OF */
13707       if (op1 == const0_rtx)
13708         return CCNOmode;
13709       else
13710         return CCGCmode;
13711       /* strcmp pattern do (use flags) and combine may ask us for proper
13712          mode.  */
13713     case USE:
13714       return CCmode;
13715     default:
13716       gcc_unreachable ();
13717     }
13718 }
13719
13720 /* Return the fixed registers used for condition codes.  */
13721
13722 static bool
13723 ix86_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
13724 {
13725   *p1 = FLAGS_REG;
13726   *p2 = FPSR_REG;
13727   return true;
13728 }
13729
13730 /* If two condition code modes are compatible, return a condition code
13731    mode which is compatible with both.  Otherwise, return
13732    VOIDmode.  */
13733
13734 static enum machine_mode
13735 ix86_cc_modes_compatible (enum machine_mode m1, enum machine_mode m2)
13736 {
13737   if (m1 == m2)
13738     return m1;
13739
13740   if (GET_MODE_CLASS (m1) != MODE_CC || GET_MODE_CLASS (m2) != MODE_CC)
13741     return VOIDmode;
13742
13743   if ((m1 == CCGCmode && m2 == CCGOCmode)
13744       || (m1 == CCGOCmode && m2 == CCGCmode))
13745     return CCGCmode;
13746
13747   switch (m1)
13748     {
13749     default:
13750       gcc_unreachable ();
13751
13752     case CCmode:
13753     case CCGCmode:
13754     case CCGOCmode:
13755     case CCNOmode:
13756     case CCAmode:
13757     case CCCmode:
13758     case CCOmode:
13759     case CCSmode:
13760     case CCZmode:
13761       switch (m2)
13762         {
13763         default:
13764           return VOIDmode;
13765
13766         case CCmode:
13767         case CCGCmode:
13768         case CCGOCmode:
13769         case CCNOmode:
13770         case CCAmode:
13771         case CCCmode:
13772         case CCOmode:
13773         case CCSmode:
13774         case CCZmode:
13775           return CCmode;
13776         }
13777
13778     case CCFPmode:
13779     case CCFPUmode:
13780       /* These are only compatible with themselves, which we already
13781          checked above.  */
13782       return VOIDmode;
13783     }
13784 }
13785
13786 /* Split comparison code CODE into comparisons we can do using branch
13787    instructions.  BYPASS_CODE is comparison code for branch that will
13788    branch around FIRST_CODE and SECOND_CODE.  If some of branches
13789    is not required, set value to UNKNOWN.
13790    We never require more than two branches.  */
13791
13792 void
13793 ix86_fp_comparison_codes (enum rtx_code code, enum rtx_code *bypass_code,
13794                           enum rtx_code *first_code,
13795                           enum rtx_code *second_code)
13796 {
13797   *first_code = code;
13798   *bypass_code = UNKNOWN;
13799   *second_code = UNKNOWN;
13800
13801   /* The fcomi comparison sets flags as follows:
13802
13803      cmp    ZF PF CF
13804      >      0  0  0
13805      <      0  0  1
13806      =      1  0  0
13807      un     1  1  1 */
13808
13809   switch (code)
13810     {
13811     case GT:                    /* GTU - CF=0 & ZF=0 */
13812     case GE:                    /* GEU - CF=0 */
13813     case ORDERED:               /* PF=0 */
13814     case UNORDERED:             /* PF=1 */
13815     case UNEQ:                  /* EQ - ZF=1 */
13816     case UNLT:                  /* LTU - CF=1 */
13817     case UNLE:                  /* LEU - CF=1 | ZF=1 */
13818     case LTGT:                  /* EQ - ZF=0 */
13819       break;
13820     case LT:                    /* LTU - CF=1 - fails on unordered */
13821       *first_code = UNLT;
13822       *bypass_code = UNORDERED;
13823       break;
13824     case LE:                    /* LEU - CF=1 | ZF=1 - fails on unordered */
13825       *first_code = UNLE;
13826       *bypass_code = UNORDERED;
13827       break;
13828     case EQ:                    /* EQ - ZF=1 - fails on unordered */
13829       *first_code = UNEQ;
13830       *bypass_code = UNORDERED;
13831       break;
13832     case NE:                    /* NE - ZF=0 - fails on unordered */
13833       *first_code = LTGT;
13834       *second_code = UNORDERED;
13835       break;
13836     case UNGE:                  /* GEU - CF=0 - fails on unordered */
13837       *first_code = GE;
13838       *second_code = UNORDERED;
13839       break;
13840     case UNGT:                  /* GTU - CF=0 & ZF=0 - fails on unordered */
13841       *first_code = GT;
13842       *second_code = UNORDERED;
13843       break;
13844     default:
13845       gcc_unreachable ();
13846     }
13847   if (!TARGET_IEEE_FP)
13848     {
13849       *second_code = UNKNOWN;
13850       *bypass_code = UNKNOWN;
13851     }
13852 }
13853
13854 /* Return cost of comparison done fcom + arithmetics operations on AX.
13855    All following functions do use number of instructions as a cost metrics.
13856    In future this should be tweaked to compute bytes for optimize_size and
13857    take into account performance of various instructions on various CPUs.  */
13858 static int
13859 ix86_fp_comparison_arithmetics_cost (enum rtx_code code)
13860 {
13861   if (!TARGET_IEEE_FP)
13862     return 4;
13863   /* The cost of code output by ix86_expand_fp_compare.  */
13864   switch (code)
13865     {
13866     case UNLE:
13867     case UNLT:
13868     case LTGT:
13869     case GT:
13870     case GE:
13871     case UNORDERED:
13872     case ORDERED:
13873     case UNEQ:
13874       return 4;
13875       break;
13876     case LT:
13877     case NE:
13878     case EQ:
13879     case UNGE:
13880       return 5;
13881       break;
13882     case LE:
13883     case UNGT:
13884       return 6;
13885       break;
13886     default:
13887       gcc_unreachable ();
13888     }
13889 }
13890
13891 /* Return cost of comparison done using fcomi operation.
13892    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
13893 static int
13894 ix86_fp_comparison_fcomi_cost (enum rtx_code code)
13895 {
13896   enum rtx_code bypass_code, first_code, second_code;
13897   /* Return arbitrarily high cost when instruction is not supported - this
13898      prevents gcc from using it.  */
13899   if (!TARGET_CMOVE)
13900     return 1024;
13901   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13902   return (bypass_code != UNKNOWN || second_code != UNKNOWN) + 2;
13903 }
13904
13905 /* Return cost of comparison done using sahf operation.
13906    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
13907 static int
13908 ix86_fp_comparison_sahf_cost (enum rtx_code code)
13909 {
13910   enum rtx_code bypass_code, first_code, second_code;
13911   /* Return arbitrarily high cost when instruction is not preferred - this
13912      avoids gcc from using it.  */
13913   if (!(TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ())))
13914     return 1024;
13915   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13916   return (bypass_code != UNKNOWN || second_code != UNKNOWN) + 3;
13917 }
13918
13919 /* Compute cost of the comparison done using any method.
13920    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
13921 static int
13922 ix86_fp_comparison_cost (enum rtx_code code)
13923 {
13924   int fcomi_cost, sahf_cost, arithmetics_cost = 1024;
13925   int min;
13926
13927   fcomi_cost = ix86_fp_comparison_fcomi_cost (code);
13928   sahf_cost = ix86_fp_comparison_sahf_cost (code);
13929
13930   min = arithmetics_cost = ix86_fp_comparison_arithmetics_cost (code);
13931   if (min > sahf_cost)
13932     min = sahf_cost;
13933   if (min > fcomi_cost)
13934     min = fcomi_cost;
13935   return min;
13936 }
13937
13938 /* Return true if we should use an FCOMI instruction for this
13939    fp comparison.  */
13940
13941 int
13942 ix86_use_fcomi_compare (enum rtx_code code ATTRIBUTE_UNUSED)
13943 {
13944   enum rtx_code swapped_code = swap_condition (code);
13945
13946   return ((ix86_fp_comparison_cost (code)
13947            == ix86_fp_comparison_fcomi_cost (code))
13948           || (ix86_fp_comparison_cost (swapped_code)
13949               == ix86_fp_comparison_fcomi_cost (swapped_code)));
13950 }
13951
13952 /* Swap, force into registers, or otherwise massage the two operands
13953    to a fp comparison.  The operands are updated in place; the new
13954    comparison code is returned.  */
13955
13956 static enum rtx_code
13957 ix86_prepare_fp_compare_args (enum rtx_code code, rtx *pop0, rtx *pop1)
13958 {
13959   enum machine_mode fpcmp_mode = ix86_fp_compare_mode (code);
13960   rtx op0 = *pop0, op1 = *pop1;
13961   enum machine_mode op_mode = GET_MODE (op0);
13962   int is_sse = TARGET_SSE_MATH && SSE_FLOAT_MODE_P (op_mode);
13963
13964   /* All of the unordered compare instructions only work on registers.
13965      The same is true of the fcomi compare instructions.  The XFmode
13966      compare instructions require registers except when comparing
13967      against zero or when converting operand 1 from fixed point to
13968      floating point.  */
13969
13970   if (!is_sse
13971       && (fpcmp_mode == CCFPUmode
13972           || (op_mode == XFmode
13973               && ! (standard_80387_constant_p (op0) == 1
13974                     || standard_80387_constant_p (op1) == 1)
13975               && GET_CODE (op1) != FLOAT)
13976           || ix86_use_fcomi_compare (code)))
13977     {
13978       op0 = force_reg (op_mode, op0);
13979       op1 = force_reg (op_mode, op1);
13980     }
13981   else
13982     {
13983       /* %%% We only allow op1 in memory; op0 must be st(0).  So swap
13984          things around if they appear profitable, otherwise force op0
13985          into a register.  */
13986
13987       if (standard_80387_constant_p (op0) == 0
13988           || (MEM_P (op0)
13989               && ! (standard_80387_constant_p (op1) == 0
13990                     || MEM_P (op1))))
13991         {
13992           rtx tmp;
13993           tmp = op0, op0 = op1, op1 = tmp;
13994           code = swap_condition (code);
13995         }
13996
13997       if (!REG_P (op0))
13998         op0 = force_reg (op_mode, op0);
13999
14000       if (CONSTANT_P (op1))
14001         {
14002           int tmp = standard_80387_constant_p (op1);
14003           if (tmp == 0)
14004             op1 = validize_mem (force_const_mem (op_mode, op1));
14005           else if (tmp == 1)
14006             {
14007               if (TARGET_CMOVE)
14008                 op1 = force_reg (op_mode, op1);
14009             }
14010           else
14011             op1 = force_reg (op_mode, op1);
14012         }
14013     }
14014
14015   /* Try to rearrange the comparison to make it cheaper.  */
14016   if (ix86_fp_comparison_cost (code)
14017       > ix86_fp_comparison_cost (swap_condition (code))
14018       && (REG_P (op1) || can_create_pseudo_p ()))
14019     {
14020       rtx tmp;
14021       tmp = op0, op0 = op1, op1 = tmp;
14022       code = swap_condition (code);
14023       if (!REG_P (op0))
14024         op0 = force_reg (op_mode, op0);
14025     }
14026
14027   *pop0 = op0;
14028   *pop1 = op1;
14029   return code;
14030 }
14031
14032 /* Convert comparison codes we use to represent FP comparison to integer
14033    code that will result in proper branch.  Return UNKNOWN if no such code
14034    is available.  */
14035
14036 enum rtx_code
14037 ix86_fp_compare_code_to_integer (enum rtx_code code)
14038 {
14039   switch (code)
14040     {
14041     case GT:
14042       return GTU;
14043     case GE:
14044       return GEU;
14045     case ORDERED:
14046     case UNORDERED:
14047       return code;
14048       break;
14049     case UNEQ:
14050       return EQ;
14051       break;
14052     case UNLT:
14053       return LTU;
14054       break;
14055     case UNLE:
14056       return LEU;
14057       break;
14058     case LTGT:
14059       return NE;
14060       break;
14061     default:
14062       return UNKNOWN;
14063     }
14064 }
14065
14066 /* Generate insn patterns to do a floating point compare of OPERANDS.  */
14067
14068 static rtx
14069 ix86_expand_fp_compare (enum rtx_code code, rtx op0, rtx op1, rtx scratch,
14070                         rtx *second_test, rtx *bypass_test)
14071 {
14072   enum machine_mode fpcmp_mode, intcmp_mode;
14073   rtx tmp, tmp2;
14074   int cost = ix86_fp_comparison_cost (code);
14075   enum rtx_code bypass_code, first_code, second_code;
14076
14077   fpcmp_mode = ix86_fp_compare_mode (code);
14078   code = ix86_prepare_fp_compare_args (code, &op0, &op1);
14079
14080   if (second_test)
14081     *second_test = NULL_RTX;
14082   if (bypass_test)
14083     *bypass_test = NULL_RTX;
14084
14085   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
14086
14087   /* Do fcomi/sahf based test when profitable.  */
14088   if (ix86_fp_comparison_arithmetics_cost (code) > cost
14089       && (bypass_code == UNKNOWN || bypass_test)
14090       && (second_code == UNKNOWN || second_test))
14091     {
14092       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
14093       tmp = gen_rtx_SET (VOIDmode, gen_rtx_REG (fpcmp_mode, FLAGS_REG),
14094                          tmp);
14095       if (TARGET_CMOVE)
14096         emit_insn (tmp);
14097       else
14098         {
14099           gcc_assert (TARGET_SAHF);
14100
14101           if (!scratch)
14102             scratch = gen_reg_rtx (HImode);
14103           tmp2 = gen_rtx_CLOBBER (VOIDmode, scratch);
14104
14105           emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, tmp2)));
14106         }
14107
14108       /* The FP codes work out to act like unsigned.  */
14109       intcmp_mode = fpcmp_mode;
14110       code = first_code;
14111       if (bypass_code != UNKNOWN)
14112         *bypass_test = gen_rtx_fmt_ee (bypass_code, VOIDmode,
14113                                        gen_rtx_REG (intcmp_mode, FLAGS_REG),
14114                                        const0_rtx);
14115       if (second_code != UNKNOWN)
14116         *second_test = gen_rtx_fmt_ee (second_code, VOIDmode,
14117                                        gen_rtx_REG (intcmp_mode, FLAGS_REG),
14118                                        const0_rtx);
14119     }
14120   else
14121     {
14122       /* Sadness wrt reg-stack pops killing fpsr -- gotta get fnstsw first.  */
14123       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
14124       tmp2 = gen_rtx_UNSPEC (HImode, gen_rtvec (1, tmp), UNSPEC_FNSTSW);
14125       if (!scratch)
14126         scratch = gen_reg_rtx (HImode);
14127       emit_insn (gen_rtx_SET (VOIDmode, scratch, tmp2));
14128
14129       /* In the unordered case, we have to check C2 for NaN's, which
14130          doesn't happen to work out to anything nice combination-wise.
14131          So do some bit twiddling on the value we've got in AH to come
14132          up with an appropriate set of condition codes.  */
14133
14134       intcmp_mode = CCNOmode;
14135       switch (code)
14136         {
14137         case GT:
14138         case UNGT:
14139           if (code == GT || !TARGET_IEEE_FP)
14140             {
14141               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
14142               code = EQ;
14143             }
14144           else
14145             {
14146               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
14147               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
14148               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x44)));
14149               intcmp_mode = CCmode;
14150               code = GEU;
14151             }
14152           break;
14153         case LT:
14154         case UNLT:
14155           if (code == LT && TARGET_IEEE_FP)
14156             {
14157               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
14158               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x01)));
14159               intcmp_mode = CCmode;
14160               code = EQ;
14161             }
14162           else
14163             {
14164               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x01)));
14165               code = NE;
14166             }
14167           break;
14168         case GE:
14169         case UNGE:
14170           if (code == GE || !TARGET_IEEE_FP)
14171             {
14172               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x05)));
14173               code = EQ;
14174             }
14175           else
14176             {
14177               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
14178               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch,
14179                                              GEN_INT (0x01)));
14180               code = NE;
14181             }
14182           break;
14183         case LE:
14184         case UNLE:
14185           if (code == LE && TARGET_IEEE_FP)
14186             {
14187               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
14188               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
14189               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
14190               intcmp_mode = CCmode;
14191               code = LTU;
14192             }
14193           else
14194             {
14195               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
14196               code = NE;
14197             }
14198           break;
14199         case EQ:
14200         case UNEQ:
14201           if (code == EQ && TARGET_IEEE_FP)
14202             {
14203               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
14204               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
14205               intcmp_mode = CCmode;
14206               code = EQ;
14207             }
14208           else
14209             {
14210               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
14211               code = NE;
14212               break;
14213             }
14214           break;
14215         case NE:
14216         case LTGT:
14217           if (code == NE && TARGET_IEEE_FP)
14218             {
14219               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
14220               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch,
14221                                              GEN_INT (0x40)));
14222               code = NE;
14223             }
14224           else
14225             {
14226               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
14227               code = EQ;
14228             }
14229           break;
14230
14231         case UNORDERED:
14232           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
14233           code = NE;
14234           break;
14235         case ORDERED:
14236           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
14237           code = EQ;
14238           break;
14239
14240         default:
14241           gcc_unreachable ();
14242         }
14243     }
14244
14245   /* Return the test that should be put into the flags user, i.e.
14246      the bcc, scc, or cmov instruction.  */
14247   return gen_rtx_fmt_ee (code, VOIDmode,
14248                          gen_rtx_REG (intcmp_mode, FLAGS_REG),
14249                          const0_rtx);
14250 }
14251
14252 rtx
14253 ix86_expand_compare (enum rtx_code code, rtx *second_test, rtx *bypass_test)
14254 {
14255   rtx op0, op1, ret;
14256   op0 = ix86_compare_op0;
14257   op1 = ix86_compare_op1;
14258
14259   if (second_test)
14260     *second_test = NULL_RTX;
14261   if (bypass_test)
14262     *bypass_test = NULL_RTX;
14263
14264   if (ix86_compare_emitted)
14265     {
14266       ret = gen_rtx_fmt_ee (code, VOIDmode, ix86_compare_emitted, const0_rtx);
14267       ix86_compare_emitted = NULL_RTX;
14268     }
14269   else if (SCALAR_FLOAT_MODE_P (GET_MODE (op0)))
14270     {
14271       gcc_assert (!DECIMAL_FLOAT_MODE_P (GET_MODE (op0)));
14272       ret = ix86_expand_fp_compare (code, op0, op1, NULL_RTX,
14273                                     second_test, bypass_test);
14274     }
14275   else
14276     ret = ix86_expand_int_compare (code, op0, op1);
14277
14278   return ret;
14279 }
14280
14281 /* Return true if the CODE will result in nontrivial jump sequence.  */
14282 bool
14283 ix86_fp_jump_nontrivial_p (enum rtx_code code)
14284 {
14285   enum rtx_code bypass_code, first_code, second_code;
14286   if (!TARGET_CMOVE)
14287     return true;
14288   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
14289   return bypass_code != UNKNOWN || second_code != UNKNOWN;
14290 }
14291
14292 void
14293 ix86_expand_branch (enum rtx_code code, rtx label)
14294 {
14295   rtx tmp;
14296
14297   /* If we have emitted a compare insn, go straight to simple.
14298      ix86_expand_compare won't emit anything if ix86_compare_emitted
14299      is non NULL.  */
14300   if (ix86_compare_emitted)
14301     goto simple;
14302
14303   switch (GET_MODE (ix86_compare_op0))
14304     {
14305     case QImode:
14306     case HImode:
14307     case SImode:
14308       simple:
14309       tmp = ix86_expand_compare (code, NULL, NULL);
14310       tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
14311                                   gen_rtx_LABEL_REF (VOIDmode, label),
14312                                   pc_rtx);
14313       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
14314       return;
14315
14316     case SFmode:
14317     case DFmode:
14318     case XFmode:
14319       {
14320         rtvec vec;
14321         int use_fcomi;
14322         enum rtx_code bypass_code, first_code, second_code;
14323
14324         code = ix86_prepare_fp_compare_args (code, &ix86_compare_op0,
14325                                              &ix86_compare_op1);
14326
14327         ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
14328
14329         /* Check whether we will use the natural sequence with one jump.  If
14330            so, we can expand jump early.  Otherwise delay expansion by
14331            creating compound insn to not confuse optimizers.  */
14332         if (bypass_code == UNKNOWN && second_code == UNKNOWN)
14333           {
14334             ix86_split_fp_branch (code, ix86_compare_op0, ix86_compare_op1,
14335                                   gen_rtx_LABEL_REF (VOIDmode, label),
14336                                   pc_rtx, NULL_RTX, NULL_RTX);
14337           }
14338         else
14339           {
14340             tmp = gen_rtx_fmt_ee (code, VOIDmode,
14341                                   ix86_compare_op0, ix86_compare_op1);
14342             tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
14343                                         gen_rtx_LABEL_REF (VOIDmode, label),
14344                                         pc_rtx);
14345             tmp = gen_rtx_SET (VOIDmode, pc_rtx, tmp);
14346
14347             use_fcomi = ix86_use_fcomi_compare (code);
14348             vec = rtvec_alloc (3 + !use_fcomi);
14349             RTVEC_ELT (vec, 0) = tmp;
14350             RTVEC_ELT (vec, 1)
14351               = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCFPmode, FPSR_REG));
14352             RTVEC_ELT (vec, 2)
14353               = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCFPmode, FLAGS_REG));
14354             if (! use_fcomi)
14355               RTVEC_ELT (vec, 3)
14356                 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (HImode));
14357
14358             emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, vec));
14359           }
14360         return;
14361       }
14362
14363     case DImode:
14364       if (TARGET_64BIT)
14365         goto simple;
14366     case TImode:
14367       /* Expand DImode branch into multiple compare+branch.  */
14368       {
14369         rtx lo[2], hi[2], label2;
14370         enum rtx_code code1, code2, code3;
14371         enum machine_mode submode;
14372
14373         if (CONSTANT_P (ix86_compare_op0) && ! CONSTANT_P (ix86_compare_op1))
14374           {
14375             tmp = ix86_compare_op0;
14376             ix86_compare_op0 = ix86_compare_op1;
14377             ix86_compare_op1 = tmp;
14378             code = swap_condition (code);
14379           }
14380         if (GET_MODE (ix86_compare_op0) == DImode)
14381           {
14382             split_di (&ix86_compare_op0, 1, lo+0, hi+0);
14383             split_di (&ix86_compare_op1, 1, lo+1, hi+1);
14384             submode = SImode;
14385           }
14386         else
14387           {
14388             split_ti (&ix86_compare_op0, 1, lo+0, hi+0);
14389             split_ti (&ix86_compare_op1, 1, lo+1, hi+1);
14390             submode = DImode;
14391           }
14392
14393         /* When comparing for equality, we can use (hi0^hi1)|(lo0^lo1) to
14394            avoid two branches.  This costs one extra insn, so disable when
14395            optimizing for size.  */
14396
14397         if ((code == EQ || code == NE)
14398             && (!optimize_insn_for_size_p ()
14399                 || hi[1] == const0_rtx || lo[1] == const0_rtx))
14400           {
14401             rtx xor0, xor1;
14402
14403             xor1 = hi[0];
14404             if (hi[1] != const0_rtx)
14405               xor1 = expand_binop (submode, xor_optab, xor1, hi[1],
14406                                    NULL_RTX, 0, OPTAB_WIDEN);
14407
14408             xor0 = lo[0];
14409             if (lo[1] != const0_rtx)
14410               xor0 = expand_binop (submode, xor_optab, xor0, lo[1],
14411                                    NULL_RTX, 0, OPTAB_WIDEN);
14412
14413             tmp = expand_binop (submode, ior_optab, xor1, xor0,
14414                                 NULL_RTX, 0, OPTAB_WIDEN);
14415
14416             ix86_compare_op0 = tmp;
14417             ix86_compare_op1 = const0_rtx;
14418             ix86_expand_branch (code, label);
14419             return;
14420           }
14421
14422         /* Otherwise, if we are doing less-than or greater-or-equal-than,
14423            op1 is a constant and the low word is zero, then we can just
14424            examine the high word.  Similarly for low word -1 and
14425            less-or-equal-than or greater-than.  */
14426
14427         if (CONST_INT_P (hi[1]))
14428           switch (code)
14429             {
14430             case LT: case LTU: case GE: case GEU:
14431               if (lo[1] == const0_rtx)
14432                 {
14433                   ix86_compare_op0 = hi[0];
14434                   ix86_compare_op1 = hi[1];
14435                   ix86_expand_branch (code, label);
14436                   return;
14437                 }
14438               break;
14439             case LE: case LEU: case GT: case GTU:
14440               if (lo[1] == constm1_rtx)
14441                 {
14442                   ix86_compare_op0 = hi[0];
14443                   ix86_compare_op1 = hi[1];
14444                   ix86_expand_branch (code, label);
14445                   return;
14446                 }
14447               break;
14448             default:
14449               break;
14450             }
14451
14452         /* Otherwise, we need two or three jumps.  */
14453
14454         label2 = gen_label_rtx ();
14455
14456         code1 = code;
14457         code2 = swap_condition (code);
14458         code3 = unsigned_condition (code);
14459
14460         switch (code)
14461           {
14462           case LT: case GT: case LTU: case GTU:
14463             break;
14464
14465           case LE:   code1 = LT;  code2 = GT;  break;
14466           case GE:   code1 = GT;  code2 = LT;  break;
14467           case LEU:  code1 = LTU; code2 = GTU; break;
14468           case GEU:  code1 = GTU; code2 = LTU; break;
14469
14470           case EQ:   code1 = UNKNOWN; code2 = NE;  break;
14471           case NE:   code2 = UNKNOWN; break;
14472
14473           default:
14474             gcc_unreachable ();
14475           }
14476
14477         /*
14478          * a < b =>
14479          *    if (hi(a) < hi(b)) goto true;
14480          *    if (hi(a) > hi(b)) goto false;
14481          *    if (lo(a) < lo(b)) goto true;
14482          *  false:
14483          */
14484
14485         ix86_compare_op0 = hi[0];
14486         ix86_compare_op1 = hi[1];
14487
14488         if (code1 != UNKNOWN)
14489           ix86_expand_branch (code1, label);
14490         if (code2 != UNKNOWN)
14491           ix86_expand_branch (code2, label2);
14492
14493         ix86_compare_op0 = lo[0];
14494         ix86_compare_op1 = lo[1];
14495         ix86_expand_branch (code3, label);
14496
14497         if (code2 != UNKNOWN)
14498           emit_label (label2);
14499         return;
14500       }
14501
14502     default:
14503       gcc_unreachable ();
14504     }
14505 }
14506
14507 /* Split branch based on floating point condition.  */
14508 void
14509 ix86_split_fp_branch (enum rtx_code code, rtx op1, rtx op2,
14510                       rtx target1, rtx target2, rtx tmp, rtx pushed)
14511 {
14512   rtx second, bypass;
14513   rtx label = NULL_RTX;
14514   rtx condition;
14515   int bypass_probability = -1, second_probability = -1, probability = -1;
14516   rtx i;
14517
14518   if (target2 != pc_rtx)
14519     {
14520       rtx tmp = target2;
14521       code = reverse_condition_maybe_unordered (code);
14522       target2 = target1;
14523       target1 = tmp;
14524     }
14525
14526   condition = ix86_expand_fp_compare (code, op1, op2,
14527                                       tmp, &second, &bypass);
14528
14529   /* Remove pushed operand from stack.  */
14530   if (pushed)
14531     ix86_free_from_memory (GET_MODE (pushed));
14532
14533   if (split_branch_probability >= 0)
14534     {
14535       /* Distribute the probabilities across the jumps.
14536          Assume the BYPASS and SECOND to be always test
14537          for UNORDERED.  */
14538       probability = split_branch_probability;
14539
14540       /* Value of 1 is low enough to make no need for probability
14541          to be updated.  Later we may run some experiments and see
14542          if unordered values are more frequent in practice.  */
14543       if (bypass)
14544         bypass_probability = 1;
14545       if (second)
14546         second_probability = 1;
14547     }
14548   if (bypass != NULL_RTX)
14549     {
14550       label = gen_label_rtx ();
14551       i = emit_jump_insn (gen_rtx_SET
14552                           (VOIDmode, pc_rtx,
14553                            gen_rtx_IF_THEN_ELSE (VOIDmode,
14554                                                  bypass,
14555                                                  gen_rtx_LABEL_REF (VOIDmode,
14556                                                                     label),
14557                                                  pc_rtx)));
14558       if (bypass_probability >= 0)
14559         REG_NOTES (i)
14560           = gen_rtx_EXPR_LIST (REG_BR_PROB,
14561                                GEN_INT (bypass_probability),
14562                                REG_NOTES (i));
14563     }
14564   i = emit_jump_insn (gen_rtx_SET
14565                       (VOIDmode, pc_rtx,
14566                        gen_rtx_IF_THEN_ELSE (VOIDmode,
14567                                              condition, target1, target2)));
14568   if (probability >= 0)
14569     REG_NOTES (i)
14570       = gen_rtx_EXPR_LIST (REG_BR_PROB,
14571                            GEN_INT (probability),
14572                            REG_NOTES (i));
14573   if (second != NULL_RTX)
14574     {
14575       i = emit_jump_insn (gen_rtx_SET
14576                           (VOIDmode, pc_rtx,
14577                            gen_rtx_IF_THEN_ELSE (VOIDmode, second, target1,
14578                                                  target2)));
14579       if (second_probability >= 0)
14580         REG_NOTES (i)
14581           = gen_rtx_EXPR_LIST (REG_BR_PROB,
14582                                GEN_INT (second_probability),
14583                                REG_NOTES (i));
14584     }
14585   if (label != NULL_RTX)
14586     emit_label (label);
14587 }
14588
14589 int
14590 ix86_expand_setcc (enum rtx_code code, rtx dest)
14591 {
14592   rtx ret, tmp, tmpreg, equiv;
14593   rtx second_test, bypass_test;
14594
14595   if (GET_MODE (ix86_compare_op0) == (TARGET_64BIT ? TImode : DImode))
14596     return 0; /* FAIL */
14597
14598   gcc_assert (GET_MODE (dest) == QImode);
14599
14600   ret = ix86_expand_compare (code, &second_test, &bypass_test);
14601   PUT_MODE (ret, QImode);
14602
14603   tmp = dest;
14604   tmpreg = dest;
14605
14606   emit_insn (gen_rtx_SET (VOIDmode, tmp, ret));
14607   if (bypass_test || second_test)
14608     {
14609       rtx test = second_test;
14610       int bypass = 0;
14611       rtx tmp2 = gen_reg_rtx (QImode);
14612       if (bypass_test)
14613         {
14614           gcc_assert (!second_test);
14615           test = bypass_test;
14616           bypass = 1;
14617           PUT_CODE (test, reverse_condition_maybe_unordered (GET_CODE (test)));
14618         }
14619       PUT_MODE (test, QImode);
14620       emit_insn (gen_rtx_SET (VOIDmode, tmp2, test));
14621
14622       if (bypass)
14623         emit_insn (gen_andqi3 (tmp, tmpreg, tmp2));
14624       else
14625         emit_insn (gen_iorqi3 (tmp, tmpreg, tmp2));
14626     }
14627
14628   /* Attach a REG_EQUAL note describing the comparison result.  */
14629   if (ix86_compare_op0 && ix86_compare_op1)
14630     {
14631       equiv = simplify_gen_relational (code, QImode,
14632                                        GET_MODE (ix86_compare_op0),
14633                                        ix86_compare_op0, ix86_compare_op1);
14634       set_unique_reg_note (get_last_insn (), REG_EQUAL, equiv);
14635     }
14636
14637   return 1; /* DONE */
14638 }
14639
14640 /* Expand comparison setting or clearing carry flag.  Return true when
14641    successful and set pop for the operation.  */
14642 static bool
14643 ix86_expand_carry_flag_compare (enum rtx_code code, rtx op0, rtx op1, rtx *pop)
14644 {
14645   enum machine_mode mode =
14646     GET_MODE (op0) != VOIDmode ? GET_MODE (op0) : GET_MODE (op1);
14647
14648   /* Do not handle DImode compares that go through special path.  */
14649   if (mode == (TARGET_64BIT ? TImode : DImode))
14650     return false;
14651
14652   if (SCALAR_FLOAT_MODE_P (mode))
14653     {
14654       rtx second_test = NULL, bypass_test = NULL;
14655       rtx compare_op, compare_seq;
14656
14657       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
14658
14659       /* Shortcut:  following common codes never translate
14660          into carry flag compares.  */
14661       if (code == EQ || code == NE || code == UNEQ || code == LTGT
14662           || code == ORDERED || code == UNORDERED)
14663         return false;
14664
14665       /* These comparisons require zero flag; swap operands so they won't.  */
14666       if ((code == GT || code == UNLE || code == LE || code == UNGT)
14667           && !TARGET_IEEE_FP)
14668         {
14669           rtx tmp = op0;
14670           op0 = op1;
14671           op1 = tmp;
14672           code = swap_condition (code);
14673         }
14674
14675       /* Try to expand the comparison and verify that we end up with
14676          carry flag based comparison.  This fails to be true only when
14677          we decide to expand comparison using arithmetic that is not
14678          too common scenario.  */
14679       start_sequence ();
14680       compare_op = ix86_expand_fp_compare (code, op0, op1, NULL_RTX,
14681                                            &second_test, &bypass_test);
14682       compare_seq = get_insns ();
14683       end_sequence ();
14684
14685       if (second_test || bypass_test)
14686         return false;
14687
14688       if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
14689           || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
14690         code = ix86_fp_compare_code_to_integer (GET_CODE (compare_op));
14691       else
14692         code = GET_CODE (compare_op);
14693
14694       if (code != LTU && code != GEU)
14695         return false;
14696
14697       emit_insn (compare_seq);
14698       *pop = compare_op;
14699       return true;
14700     }
14701
14702   if (!INTEGRAL_MODE_P (mode))
14703     return false;
14704
14705   switch (code)
14706     {
14707     case LTU:
14708     case GEU:
14709       break;
14710
14711     /* Convert a==0 into (unsigned)a<1.  */
14712     case EQ:
14713     case NE:
14714       if (op1 != const0_rtx)
14715         return false;
14716       op1 = const1_rtx;
14717       code = (code == EQ ? LTU : GEU);
14718       break;
14719
14720     /* Convert a>b into b<a or a>=b-1.  */
14721     case GTU:
14722     case LEU:
14723       if (CONST_INT_P (op1))
14724         {
14725           op1 = gen_int_mode (INTVAL (op1) + 1, GET_MODE (op0));
14726           /* Bail out on overflow.  We still can swap operands but that
14727              would force loading of the constant into register.  */
14728           if (op1 == const0_rtx
14729               || !x86_64_immediate_operand (op1, GET_MODE (op1)))
14730             return false;
14731           code = (code == GTU ? GEU : LTU);
14732         }
14733       else
14734         {
14735           rtx tmp = op1;
14736           op1 = op0;
14737           op0 = tmp;
14738           code = (code == GTU ? LTU : GEU);
14739         }
14740       break;
14741
14742     /* Convert a>=0 into (unsigned)a<0x80000000.  */
14743     case LT:
14744     case GE:
14745       if (mode == DImode || op1 != const0_rtx)
14746         return false;
14747       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
14748       code = (code == LT ? GEU : LTU);
14749       break;
14750     case LE:
14751     case GT:
14752       if (mode == DImode || op1 != constm1_rtx)
14753         return false;
14754       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
14755       code = (code == LE ? GEU : LTU);
14756       break;
14757
14758     default:
14759       return false;
14760     }
14761   /* Swapping operands may cause constant to appear as first operand.  */
14762   if (!nonimmediate_operand (op0, VOIDmode))
14763     {
14764       if (!can_create_pseudo_p ())
14765         return false;
14766       op0 = force_reg (mode, op0);
14767     }
14768   ix86_compare_op0 = op0;
14769   ix86_compare_op1 = op1;
14770   *pop = ix86_expand_compare (code, NULL, NULL);
14771   gcc_assert (GET_CODE (*pop) == LTU || GET_CODE (*pop) == GEU);
14772   return true;
14773 }
14774
14775 int
14776 ix86_expand_int_movcc (rtx operands[])
14777 {
14778   enum rtx_code code = GET_CODE (operands[1]), compare_code;
14779   rtx compare_seq, compare_op;
14780   rtx second_test, bypass_test;
14781   enum machine_mode mode = GET_MODE (operands[0]);
14782   bool sign_bit_compare_p = false;;
14783
14784   start_sequence ();
14785   compare_op = ix86_expand_compare (code, &second_test, &bypass_test);
14786   compare_seq = get_insns ();
14787   end_sequence ();
14788
14789   compare_code = GET_CODE (compare_op);
14790
14791   if ((ix86_compare_op1 == const0_rtx && (code == GE || code == LT))
14792       || (ix86_compare_op1 == constm1_rtx && (code == GT || code == LE)))
14793     sign_bit_compare_p = true;
14794
14795   /* Don't attempt mode expansion here -- if we had to expand 5 or 6
14796      HImode insns, we'd be swallowed in word prefix ops.  */
14797
14798   if ((mode != HImode || TARGET_FAST_PREFIX)
14799       && (mode != (TARGET_64BIT ? TImode : DImode))
14800       && CONST_INT_P (operands[2])
14801       && CONST_INT_P (operands[3]))
14802     {
14803       rtx out = operands[0];
14804       HOST_WIDE_INT ct = INTVAL (operands[2]);
14805       HOST_WIDE_INT cf = INTVAL (operands[3]);
14806       HOST_WIDE_INT diff;
14807
14808       diff = ct - cf;
14809       /*  Sign bit compares are better done using shifts than we do by using
14810           sbb.  */
14811       if (sign_bit_compare_p
14812           || ix86_expand_carry_flag_compare (code, ix86_compare_op0,
14813                                              ix86_compare_op1, &compare_op))
14814         {
14815           /* Detect overlap between destination and compare sources.  */
14816           rtx tmp = out;
14817
14818           if (!sign_bit_compare_p)
14819             {
14820               bool fpcmp = false;
14821
14822               compare_code = GET_CODE (compare_op);
14823
14824               if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
14825                   || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
14826                 {
14827                   fpcmp = true;
14828                   compare_code = ix86_fp_compare_code_to_integer (compare_code);
14829                 }
14830
14831               /* To simplify rest of code, restrict to the GEU case.  */
14832               if (compare_code == LTU)
14833                 {
14834                   HOST_WIDE_INT tmp = ct;
14835                   ct = cf;
14836                   cf = tmp;
14837                   compare_code = reverse_condition (compare_code);
14838                   code = reverse_condition (code);
14839                 }
14840               else
14841                 {
14842                   if (fpcmp)
14843                     PUT_CODE (compare_op,
14844                               reverse_condition_maybe_unordered
14845                                 (GET_CODE (compare_op)));
14846                   else
14847                     PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
14848                 }
14849               diff = ct - cf;
14850
14851               if (reg_overlap_mentioned_p (out, ix86_compare_op0)
14852                   || reg_overlap_mentioned_p (out, ix86_compare_op1))
14853                 tmp = gen_reg_rtx (mode);
14854
14855               if (mode == DImode)
14856                 emit_insn (gen_x86_movdicc_0_m1_rex64 (tmp, compare_op));
14857               else
14858                 emit_insn (gen_x86_movsicc_0_m1 (gen_lowpart (SImode, tmp), compare_op));
14859             }
14860           else
14861             {
14862               if (code == GT || code == GE)
14863                 code = reverse_condition (code);
14864               else
14865                 {
14866                   HOST_WIDE_INT tmp = ct;
14867                   ct = cf;
14868                   cf = tmp;
14869                   diff = ct - cf;
14870                 }
14871               tmp = emit_store_flag (tmp, code, ix86_compare_op0,
14872                                      ix86_compare_op1, VOIDmode, 0, -1);
14873             }
14874
14875           if (diff == 1)
14876             {
14877               /*
14878                * cmpl op0,op1
14879                * sbbl dest,dest
14880                * [addl dest, ct]
14881                *
14882                * Size 5 - 8.
14883                */
14884               if (ct)
14885                 tmp = expand_simple_binop (mode, PLUS,
14886                                            tmp, GEN_INT (ct),
14887                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
14888             }
14889           else if (cf == -1)
14890             {
14891               /*
14892                * cmpl op0,op1
14893                * sbbl dest,dest
14894                * orl $ct, dest
14895                *
14896                * Size 8.
14897                */
14898               tmp = expand_simple_binop (mode, IOR,
14899                                          tmp, GEN_INT (ct),
14900                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
14901             }
14902           else if (diff == -1 && ct)
14903             {
14904               /*
14905                * cmpl op0,op1
14906                * sbbl dest,dest
14907                * notl dest
14908                * [addl dest, cf]
14909                *
14910                * Size 8 - 11.
14911                */
14912               tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
14913               if (cf)
14914                 tmp = expand_simple_binop (mode, PLUS,
14915                                            copy_rtx (tmp), GEN_INT (cf),
14916                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
14917             }
14918           else
14919             {
14920               /*
14921                * cmpl op0,op1
14922                * sbbl dest,dest
14923                * [notl dest]
14924                * andl cf - ct, dest
14925                * [addl dest, ct]
14926                *
14927                * Size 8 - 11.
14928                */
14929
14930               if (cf == 0)
14931                 {
14932                   cf = ct;
14933                   ct = 0;
14934                   tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
14935                 }
14936
14937               tmp = expand_simple_binop (mode, AND,
14938                                          copy_rtx (tmp),
14939                                          gen_int_mode (cf - ct, mode),
14940                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
14941               if (ct)
14942                 tmp = expand_simple_binop (mode, PLUS,
14943                                            copy_rtx (tmp), GEN_INT (ct),
14944                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
14945             }
14946
14947           if (!rtx_equal_p (tmp, out))
14948             emit_move_insn (copy_rtx (out), copy_rtx (tmp));
14949
14950           return 1; /* DONE */
14951         }
14952
14953       if (diff < 0)
14954         {
14955           enum machine_mode cmp_mode = GET_MODE (ix86_compare_op0);
14956
14957           HOST_WIDE_INT tmp;
14958           tmp = ct, ct = cf, cf = tmp;
14959           diff = -diff;
14960
14961           if (SCALAR_FLOAT_MODE_P (cmp_mode))
14962             {
14963               gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
14964
14965               /* We may be reversing unordered compare to normal compare, that
14966                  is not valid in general (we may convert non-trapping condition
14967                  to trapping one), however on i386 we currently emit all
14968                  comparisons unordered.  */
14969               compare_code = reverse_condition_maybe_unordered (compare_code);
14970               code = reverse_condition_maybe_unordered (code);
14971             }
14972           else
14973             {
14974               compare_code = reverse_condition (compare_code);
14975               code = reverse_condition (code);
14976             }
14977         }
14978
14979       compare_code = UNKNOWN;
14980       if (GET_MODE_CLASS (GET_MODE (ix86_compare_op0)) == MODE_INT
14981           && CONST_INT_P (ix86_compare_op1))
14982         {
14983           if (ix86_compare_op1 == const0_rtx
14984               && (code == LT || code == GE))
14985             compare_code = code;
14986           else if (ix86_compare_op1 == constm1_rtx)
14987             {
14988               if (code == LE)
14989                 compare_code = LT;
14990               else if (code == GT)
14991                 compare_code = GE;
14992             }
14993         }
14994
14995       /* Optimize dest = (op0 < 0) ? -1 : cf.  */
14996       if (compare_code != UNKNOWN
14997           && GET_MODE (ix86_compare_op0) == GET_MODE (out)
14998           && (cf == -1 || ct == -1))
14999         {
15000           /* If lea code below could be used, only optimize
15001              if it results in a 2 insn sequence.  */
15002
15003           if (! (diff == 1 || diff == 2 || diff == 4 || diff == 8
15004                  || diff == 3 || diff == 5 || diff == 9)
15005               || (compare_code == LT && ct == -1)
15006               || (compare_code == GE && cf == -1))
15007             {
15008               /*
15009                * notl op1       (if necessary)
15010                * sarl $31, op1
15011                * orl cf, op1
15012                */
15013               if (ct != -1)
15014                 {
15015                   cf = ct;
15016                   ct = -1;
15017                   code = reverse_condition (code);
15018                 }
15019
15020               out = emit_store_flag (out, code, ix86_compare_op0,
15021                                      ix86_compare_op1, VOIDmode, 0, -1);
15022
15023               out = expand_simple_binop (mode, IOR,
15024                                          out, GEN_INT (cf),
15025                                          out, 1, OPTAB_DIRECT);
15026               if (out != operands[0])
15027                 emit_move_insn (operands[0], out);
15028
15029               return 1; /* DONE */
15030             }
15031         }
15032
15033
15034       if ((diff == 1 || diff == 2 || diff == 4 || diff == 8
15035            || diff == 3 || diff == 5 || diff == 9)
15036           && ((mode != QImode && mode != HImode) || !TARGET_PARTIAL_REG_STALL)
15037           && (mode != DImode
15038               || x86_64_immediate_operand (GEN_INT (cf), VOIDmode)))
15039         {
15040           /*
15041            * xorl dest,dest
15042            * cmpl op1,op2
15043            * setcc dest
15044            * lea cf(dest*(ct-cf)),dest
15045            *
15046            * Size 14.
15047            *
15048            * This also catches the degenerate setcc-only case.
15049            */
15050
15051           rtx tmp;
15052           int nops;
15053
15054           out = emit_store_flag (out, code, ix86_compare_op0,
15055                                  ix86_compare_op1, VOIDmode, 0, 1);
15056
15057           nops = 0;
15058           /* On x86_64 the lea instruction operates on Pmode, so we need
15059              to get arithmetics done in proper mode to match.  */
15060           if (diff == 1)
15061             tmp = copy_rtx (out);
15062           else
15063             {
15064               rtx out1;
15065               out1 = copy_rtx (out);
15066               tmp = gen_rtx_MULT (mode, out1, GEN_INT (diff & ~1));
15067               nops++;
15068               if (diff & 1)
15069                 {
15070                   tmp = gen_rtx_PLUS (mode, tmp, out1);
15071                   nops++;
15072                 }
15073             }
15074           if (cf != 0)
15075             {
15076               tmp = gen_rtx_PLUS (mode, tmp, GEN_INT (cf));
15077               nops++;
15078             }
15079           if (!rtx_equal_p (tmp, out))
15080             {
15081               if (nops == 1)
15082                 out = force_operand (tmp, copy_rtx (out));
15083               else
15084                 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (out), copy_rtx (tmp)));
15085             }
15086           if (!rtx_equal_p (out, operands[0]))
15087             emit_move_insn (operands[0], copy_rtx (out));
15088
15089           return 1; /* DONE */
15090         }
15091
15092       /*
15093        * General case:                  Jumpful:
15094        *   xorl dest,dest               cmpl op1, op2
15095        *   cmpl op1, op2                movl ct, dest
15096        *   setcc dest                   jcc 1f
15097        *   decl dest                    movl cf, dest
15098        *   andl (cf-ct),dest            1:
15099        *   addl ct,dest
15100        *
15101        * Size 20.                       Size 14.
15102        *
15103        * This is reasonably steep, but branch mispredict costs are
15104        * high on modern cpus, so consider failing only if optimizing
15105        * for space.
15106        */
15107
15108       if ((!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
15109           && BRANCH_COST (optimize_insn_for_speed_p (),
15110                           false) >= 2)
15111         {
15112           if (cf == 0)
15113             {
15114               enum machine_mode cmp_mode = GET_MODE (ix86_compare_op0);
15115
15116               cf = ct;
15117               ct = 0;
15118
15119               if (SCALAR_FLOAT_MODE_P (cmp_mode))
15120                 {
15121                   gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
15122
15123                   /* We may be reversing unordered compare to normal compare,
15124                      that is not valid in general (we may convert non-trapping
15125                      condition to trapping one), however on i386 we currently
15126                      emit all comparisons unordered.  */
15127                   code = reverse_condition_maybe_unordered (code);
15128                 }
15129               else
15130                 {
15131                   code = reverse_condition (code);
15132                   if (compare_code != UNKNOWN)
15133                     compare_code = reverse_condition (compare_code);
15134                 }
15135             }
15136
15137           if (compare_code != UNKNOWN)
15138             {
15139               /* notl op1       (if needed)
15140                  sarl $31, op1
15141                  andl (cf-ct), op1
15142                  addl ct, op1
15143
15144                  For x < 0 (resp. x <= -1) there will be no notl,
15145                  so if possible swap the constants to get rid of the
15146                  complement.
15147                  True/false will be -1/0 while code below (store flag
15148                  followed by decrement) is 0/-1, so the constants need
15149                  to be exchanged once more.  */
15150
15151               if (compare_code == GE || !cf)
15152                 {
15153                   code = reverse_condition (code);
15154                   compare_code = LT;
15155                 }
15156               else
15157                 {
15158                   HOST_WIDE_INT tmp = cf;
15159                   cf = ct;
15160                   ct = tmp;
15161                 }
15162
15163               out = emit_store_flag (out, code, ix86_compare_op0,
15164                                      ix86_compare_op1, VOIDmode, 0, -1);
15165             }
15166           else
15167             {
15168               out = emit_store_flag (out, code, ix86_compare_op0,
15169                                      ix86_compare_op1, VOIDmode, 0, 1);
15170
15171               out = expand_simple_binop (mode, PLUS, copy_rtx (out), constm1_rtx,
15172                                          copy_rtx (out), 1, OPTAB_DIRECT);
15173             }
15174
15175           out = expand_simple_binop (mode, AND, copy_rtx (out),
15176                                      gen_int_mode (cf - ct, mode),
15177                                      copy_rtx (out), 1, OPTAB_DIRECT);
15178           if (ct)
15179             out = expand_simple_binop (mode, PLUS, copy_rtx (out), GEN_INT (ct),
15180                                        copy_rtx (out), 1, OPTAB_DIRECT);
15181           if (!rtx_equal_p (out, operands[0]))
15182             emit_move_insn (operands[0], copy_rtx (out));
15183
15184           return 1; /* DONE */
15185         }
15186     }
15187
15188   if (!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
15189     {
15190       /* Try a few things more with specific constants and a variable.  */
15191
15192       optab op;
15193       rtx var, orig_out, out, tmp;
15194
15195       if (BRANCH_COST (optimize_insn_for_speed_p (), false) <= 2)
15196         return 0; /* FAIL */
15197
15198       /* If one of the two operands is an interesting constant, load a
15199          constant with the above and mask it in with a logical operation.  */
15200
15201       if (CONST_INT_P (operands[2]))
15202         {
15203           var = operands[3];
15204           if (INTVAL (operands[2]) == 0 && operands[3] != constm1_rtx)
15205             operands[3] = constm1_rtx, op = and_optab;
15206           else if (INTVAL (operands[2]) == -1 && operands[3] != const0_rtx)
15207             operands[3] = const0_rtx, op = ior_optab;
15208           else
15209             return 0; /* FAIL */
15210         }
15211       else if (CONST_INT_P (operands[3]))
15212         {
15213           var = operands[2];
15214           if (INTVAL (operands[3]) == 0 && operands[2] != constm1_rtx)
15215             operands[2] = constm1_rtx, op = and_optab;
15216           else if (INTVAL (operands[3]) == -1 && operands[3] != const0_rtx)
15217             operands[2] = const0_rtx, op = ior_optab;
15218           else
15219             return 0; /* FAIL */
15220         }
15221       else
15222         return 0; /* FAIL */
15223
15224       orig_out = operands[0];
15225       tmp = gen_reg_rtx (mode);
15226       operands[0] = tmp;
15227
15228       /* Recurse to get the constant loaded.  */
15229       if (ix86_expand_int_movcc (operands) == 0)
15230         return 0; /* FAIL */
15231
15232       /* Mask in the interesting variable.  */
15233       out = expand_binop (mode, op, var, tmp, orig_out, 0,
15234                           OPTAB_WIDEN);
15235       if (!rtx_equal_p (out, orig_out))
15236         emit_move_insn (copy_rtx (orig_out), copy_rtx (out));
15237
15238       return 1; /* DONE */
15239     }
15240
15241   /*
15242    * For comparison with above,
15243    *
15244    * movl cf,dest
15245    * movl ct,tmp
15246    * cmpl op1,op2
15247    * cmovcc tmp,dest
15248    *
15249    * Size 15.
15250    */
15251
15252   if (! nonimmediate_operand (operands[2], mode))
15253     operands[2] = force_reg (mode, operands[2]);
15254   if (! nonimmediate_operand (operands[3], mode))
15255     operands[3] = force_reg (mode, operands[3]);
15256
15257   if (bypass_test && reg_overlap_mentioned_p (operands[0], operands[3]))
15258     {
15259       rtx tmp = gen_reg_rtx (mode);
15260       emit_move_insn (tmp, operands[3]);
15261       operands[3] = tmp;
15262     }
15263   if (second_test && reg_overlap_mentioned_p (operands[0], operands[2]))
15264     {
15265       rtx tmp = gen_reg_rtx (mode);
15266       emit_move_insn (tmp, operands[2]);
15267       operands[2] = tmp;
15268     }
15269
15270   if (! register_operand (operands[2], VOIDmode)
15271       && (mode == QImode
15272           || ! register_operand (operands[3], VOIDmode)))
15273     operands[2] = force_reg (mode, operands[2]);
15274
15275   if (mode == QImode
15276       && ! register_operand (operands[3], VOIDmode))
15277     operands[3] = force_reg (mode, operands[3]);
15278
15279   emit_insn (compare_seq);
15280   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15281                           gen_rtx_IF_THEN_ELSE (mode,
15282                                                 compare_op, operands[2],
15283                                                 operands[3])));
15284   if (bypass_test)
15285     emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (operands[0]),
15286                             gen_rtx_IF_THEN_ELSE (mode,
15287                                   bypass_test,
15288                                   copy_rtx (operands[3]),
15289                                   copy_rtx (operands[0]))));
15290   if (second_test)
15291     emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (operands[0]),
15292                             gen_rtx_IF_THEN_ELSE (mode,
15293                                   second_test,
15294                                   copy_rtx (operands[2]),
15295                                   copy_rtx (operands[0]))));
15296
15297   return 1; /* DONE */
15298 }
15299
15300 /* Swap, force into registers, or otherwise massage the two operands
15301    to an sse comparison with a mask result.  Thus we differ a bit from
15302    ix86_prepare_fp_compare_args which expects to produce a flags result.
15303
15304    The DEST operand exists to help determine whether to commute commutative
15305    operators.  The POP0/POP1 operands are updated in place.  The new
15306    comparison code is returned, or UNKNOWN if not implementable.  */
15307
15308 static enum rtx_code
15309 ix86_prepare_sse_fp_compare_args (rtx dest, enum rtx_code code,
15310                                   rtx *pop0, rtx *pop1)
15311 {
15312   rtx tmp;
15313
15314   switch (code)
15315     {
15316     case LTGT:
15317     case UNEQ:
15318       /* We have no LTGT as an operator.  We could implement it with
15319          NE & ORDERED, but this requires an extra temporary.  It's
15320          not clear that it's worth it.  */
15321       return UNKNOWN;
15322
15323     case LT:
15324     case LE:
15325     case UNGT:
15326     case UNGE:
15327       /* These are supported directly.  */
15328       break;
15329
15330     case EQ:
15331     case NE:
15332     case UNORDERED:
15333     case ORDERED:
15334       /* For commutative operators, try to canonicalize the destination
15335          operand to be first in the comparison - this helps reload to
15336          avoid extra moves.  */
15337       if (!dest || !rtx_equal_p (dest, *pop1))
15338         break;
15339       /* FALLTHRU */
15340
15341     case GE:
15342     case GT:
15343     case UNLE:
15344     case UNLT:
15345       /* These are not supported directly.  Swap the comparison operands
15346          to transform into something that is supported.  */
15347       tmp = *pop0;
15348       *pop0 = *pop1;
15349       *pop1 = tmp;
15350       code = swap_condition (code);
15351       break;
15352
15353     default:
15354       gcc_unreachable ();
15355     }
15356
15357   return code;
15358 }
15359
15360 /* Detect conditional moves that exactly match min/max operational
15361    semantics.  Note that this is IEEE safe, as long as we don't
15362    interchange the operands.
15363
15364    Returns FALSE if this conditional move doesn't match a MIN/MAX,
15365    and TRUE if the operation is successful and instructions are emitted.  */
15366
15367 static bool
15368 ix86_expand_sse_fp_minmax (rtx dest, enum rtx_code code, rtx cmp_op0,
15369                            rtx cmp_op1, rtx if_true, rtx if_false)
15370 {
15371   enum machine_mode mode;
15372   bool is_min;
15373   rtx tmp;
15374
15375   if (code == LT)
15376     ;
15377   else if (code == UNGE)
15378     {
15379       tmp = if_true;
15380       if_true = if_false;
15381       if_false = tmp;
15382     }
15383   else
15384     return false;
15385
15386   if (rtx_equal_p (cmp_op0, if_true) && rtx_equal_p (cmp_op1, if_false))
15387     is_min = true;
15388   else if (rtx_equal_p (cmp_op1, if_true) && rtx_equal_p (cmp_op0, if_false))
15389     is_min = false;
15390   else
15391     return false;
15392
15393   mode = GET_MODE (dest);
15394
15395   /* We want to check HONOR_NANS and HONOR_SIGNED_ZEROS here,
15396      but MODE may be a vector mode and thus not appropriate.  */
15397   if (!flag_finite_math_only || !flag_unsafe_math_optimizations)
15398     {
15399       int u = is_min ? UNSPEC_IEEE_MIN : UNSPEC_IEEE_MAX;
15400       rtvec v;
15401
15402       if_true = force_reg (mode, if_true);
15403       v = gen_rtvec (2, if_true, if_false);
15404       tmp = gen_rtx_UNSPEC (mode, v, u);
15405     }
15406   else
15407     {
15408       code = is_min ? SMIN : SMAX;
15409       tmp = gen_rtx_fmt_ee (code, mode, if_true, if_false);
15410     }
15411
15412   emit_insn (gen_rtx_SET (VOIDmode, dest, tmp));
15413   return true;
15414 }
15415
15416 /* Expand an sse vector comparison.  Return the register with the result.  */
15417
15418 static rtx
15419 ix86_expand_sse_cmp (rtx dest, enum rtx_code code, rtx cmp_op0, rtx cmp_op1,
15420                      rtx op_true, rtx op_false)
15421 {
15422   enum machine_mode mode = GET_MODE (dest);
15423   rtx x;
15424
15425   cmp_op0 = force_reg (mode, cmp_op0);
15426   if (!nonimmediate_operand (cmp_op1, mode))
15427     cmp_op1 = force_reg (mode, cmp_op1);
15428
15429   if (optimize
15430       || reg_overlap_mentioned_p (dest, op_true)
15431       || reg_overlap_mentioned_p (dest, op_false))
15432     dest = gen_reg_rtx (mode);
15433
15434   x = gen_rtx_fmt_ee (code, mode, cmp_op0, cmp_op1);
15435   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15436
15437   return dest;
15438 }
15439
15440 /* Expand DEST = CMP ? OP_TRUE : OP_FALSE into a sequence of logical
15441    operations.  This is used for both scalar and vector conditional moves.  */
15442
15443 static void
15444 ix86_expand_sse_movcc (rtx dest, rtx cmp, rtx op_true, rtx op_false)
15445 {
15446   enum machine_mode mode = GET_MODE (dest);
15447   rtx t2, t3, x;
15448
15449   if (op_false == CONST0_RTX (mode))
15450     {
15451       op_true = force_reg (mode, op_true);
15452       x = gen_rtx_AND (mode, cmp, op_true);
15453       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15454     }
15455   else if (op_true == CONST0_RTX (mode))
15456     {
15457       op_false = force_reg (mode, op_false);
15458       x = gen_rtx_NOT (mode, cmp);
15459       x = gen_rtx_AND (mode, x, op_false);
15460       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15461     }
15462   else if (TARGET_SSE5)
15463     {
15464       rtx pcmov = gen_rtx_SET (mode, dest,
15465                                gen_rtx_IF_THEN_ELSE (mode, cmp,
15466                                                      op_true,
15467                                                      op_false));
15468       emit_insn (pcmov);
15469     }
15470   else
15471     {
15472       op_true = force_reg (mode, op_true);
15473       op_false = force_reg (mode, op_false);
15474
15475       t2 = gen_reg_rtx (mode);
15476       if (optimize)
15477         t3 = gen_reg_rtx (mode);
15478       else
15479         t3 = dest;
15480
15481       x = gen_rtx_AND (mode, op_true, cmp);
15482       emit_insn (gen_rtx_SET (VOIDmode, t2, x));
15483
15484       x = gen_rtx_NOT (mode, cmp);
15485       x = gen_rtx_AND (mode, x, op_false);
15486       emit_insn (gen_rtx_SET (VOIDmode, t3, x));
15487
15488       x = gen_rtx_IOR (mode, t3, t2);
15489       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15490     }
15491 }
15492
15493 /* Expand a floating-point conditional move.  Return true if successful.  */
15494
15495 int
15496 ix86_expand_fp_movcc (rtx operands[])
15497 {
15498   enum machine_mode mode = GET_MODE (operands[0]);
15499   enum rtx_code code = GET_CODE (operands[1]);
15500   rtx tmp, compare_op, second_test, bypass_test;
15501
15502   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
15503     {
15504       enum machine_mode cmode;
15505
15506       /* Since we've no cmove for sse registers, don't force bad register
15507          allocation just to gain access to it.  Deny movcc when the
15508          comparison mode doesn't match the move mode.  */
15509       cmode = GET_MODE (ix86_compare_op0);
15510       if (cmode == VOIDmode)
15511         cmode = GET_MODE (ix86_compare_op1);
15512       if (cmode != mode)
15513         return 0;
15514
15515       code = ix86_prepare_sse_fp_compare_args (operands[0], code,
15516                                                &ix86_compare_op0,
15517                                                &ix86_compare_op1);
15518       if (code == UNKNOWN)
15519         return 0;
15520
15521       if (ix86_expand_sse_fp_minmax (operands[0], code, ix86_compare_op0,
15522                                      ix86_compare_op1, operands[2],
15523                                      operands[3]))
15524         return 1;
15525
15526       tmp = ix86_expand_sse_cmp (operands[0], code, ix86_compare_op0,
15527                                  ix86_compare_op1, operands[2], operands[3]);
15528       ix86_expand_sse_movcc (operands[0], tmp, operands[2], operands[3]);
15529       return 1;
15530     }
15531
15532   /* The floating point conditional move instructions don't directly
15533      support conditions resulting from a signed integer comparison.  */
15534
15535   compare_op = ix86_expand_compare (code, &second_test, &bypass_test);
15536
15537   /* The floating point conditional move instructions don't directly
15538      support signed integer comparisons.  */
15539
15540   if (!fcmov_comparison_operator (compare_op, VOIDmode))
15541     {
15542       gcc_assert (!second_test && !bypass_test);
15543       tmp = gen_reg_rtx (QImode);
15544       ix86_expand_setcc (code, tmp);
15545       code = NE;
15546       ix86_compare_op0 = tmp;
15547       ix86_compare_op1 = const0_rtx;
15548       compare_op = ix86_expand_compare (code,  &second_test, &bypass_test);
15549     }
15550   if (bypass_test && reg_overlap_mentioned_p (operands[0], operands[3]))
15551     {
15552       tmp = gen_reg_rtx (mode);
15553       emit_move_insn (tmp, operands[3]);
15554       operands[3] = tmp;
15555     }
15556   if (second_test && reg_overlap_mentioned_p (operands[0], operands[2]))
15557     {
15558       tmp = gen_reg_rtx (mode);
15559       emit_move_insn (tmp, operands[2]);
15560       operands[2] = tmp;
15561     }
15562
15563   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15564                           gen_rtx_IF_THEN_ELSE (mode, compare_op,
15565                                                 operands[2], operands[3])));
15566   if (bypass_test)
15567     emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15568                             gen_rtx_IF_THEN_ELSE (mode, bypass_test,
15569                                                   operands[3], operands[0])));
15570   if (second_test)
15571     emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15572                             gen_rtx_IF_THEN_ELSE (mode, second_test,
15573                                                   operands[2], operands[0])));
15574
15575   return 1;
15576 }
15577
15578 /* Expand a floating-point vector conditional move; a vcond operation
15579    rather than a movcc operation.  */
15580
15581 bool
15582 ix86_expand_fp_vcond (rtx operands[])
15583 {
15584   enum rtx_code code = GET_CODE (operands[3]);
15585   rtx cmp;
15586
15587   code = ix86_prepare_sse_fp_compare_args (operands[0], code,
15588                                            &operands[4], &operands[5]);
15589   if (code == UNKNOWN)
15590     return false;
15591
15592   if (ix86_expand_sse_fp_minmax (operands[0], code, operands[4],
15593                                  operands[5], operands[1], operands[2]))
15594     return true;
15595
15596   cmp = ix86_expand_sse_cmp (operands[0], code, operands[4], operands[5],
15597                              operands[1], operands[2]);
15598   ix86_expand_sse_movcc (operands[0], cmp, operands[1], operands[2]);
15599   return true;
15600 }
15601
15602 /* Expand a signed/unsigned integral vector conditional move.  */
15603
15604 bool
15605 ix86_expand_int_vcond (rtx operands[])
15606 {
15607   enum machine_mode mode = GET_MODE (operands[0]);
15608   enum rtx_code code = GET_CODE (operands[3]);
15609   bool negate = false;
15610   rtx x, cop0, cop1;
15611
15612   cop0 = operands[4];
15613   cop1 = operands[5];
15614
15615   /* SSE5 supports all of the comparisons on all vector int types.  */
15616   if (!TARGET_SSE5)
15617     {
15618       /* Canonicalize the comparison to EQ, GT, GTU.  */
15619       switch (code)
15620         {
15621         case EQ:
15622         case GT:
15623         case GTU:
15624           break;
15625
15626         case NE:
15627         case LE:
15628         case LEU:
15629           code = reverse_condition (code);
15630           negate = true;
15631           break;
15632
15633         case GE:
15634         case GEU:
15635           code = reverse_condition (code);
15636           negate = true;
15637           /* FALLTHRU */
15638
15639         case LT:
15640         case LTU:
15641           code = swap_condition (code);
15642           x = cop0, cop0 = cop1, cop1 = x;
15643           break;
15644
15645         default:
15646           gcc_unreachable ();
15647         }
15648
15649       /* Only SSE4.1/SSE4.2 supports V2DImode.  */
15650       if (mode == V2DImode)
15651         {
15652           switch (code)
15653             {
15654             case EQ:
15655               /* SSE4.1 supports EQ.  */
15656               if (!TARGET_SSE4_1)
15657                 return false;
15658               break;
15659
15660             case GT:
15661             case GTU:
15662               /* SSE4.2 supports GT/GTU.  */
15663               if (!TARGET_SSE4_2)
15664                 return false;
15665               break;
15666
15667             default:
15668               gcc_unreachable ();
15669             }
15670         }
15671
15672       /* Unsigned parallel compare is not supported by the hardware.
15673          Play some tricks to turn this into a signed comparison
15674          against 0.  */
15675       if (code == GTU)
15676         {
15677           cop0 = force_reg (mode, cop0);
15678
15679           switch (mode)
15680             {
15681             case V4SImode:
15682             case V2DImode:
15683                 {
15684                   rtx t1, t2, mask;
15685                   rtx (*gen_sub3) (rtx, rtx, rtx);
15686
15687                   /* Subtract (-(INT MAX) - 1) from both operands to make
15688                      them signed.  */
15689                   mask = ix86_build_signbit_mask (GET_MODE_INNER (mode),
15690                                                   true, false);
15691                   gen_sub3 = (mode == V4SImode
15692                               ? gen_subv4si3 : gen_subv2di3);
15693                   t1 = gen_reg_rtx (mode);
15694                   emit_insn (gen_sub3 (t1, cop0, mask));
15695
15696                   t2 = gen_reg_rtx (mode);
15697                   emit_insn (gen_sub3 (t2, cop1, mask));
15698
15699                   cop0 = t1;
15700                   cop1 = t2;
15701                   code = GT;
15702                 }
15703               break;
15704
15705             case V16QImode:
15706             case V8HImode:
15707               /* Perform a parallel unsigned saturating subtraction.  */
15708               x = gen_reg_rtx (mode);
15709               emit_insn (gen_rtx_SET (VOIDmode, x,
15710                                       gen_rtx_US_MINUS (mode, cop0, cop1)));
15711
15712               cop0 = x;
15713               cop1 = CONST0_RTX (mode);
15714               code = EQ;
15715               negate = !negate;
15716               break;
15717
15718             default:
15719               gcc_unreachable ();
15720             }
15721         }
15722     }
15723
15724   x = ix86_expand_sse_cmp (operands[0], code, cop0, cop1,
15725                            operands[1+negate], operands[2-negate]);
15726
15727   ix86_expand_sse_movcc (operands[0], x, operands[1+negate],
15728                          operands[2-negate]);
15729   return true;
15730 }
15731
15732 /* Unpack OP[1] into the next wider integer vector type.  UNSIGNED_P is
15733    true if we should do zero extension, else sign extension.  HIGH_P is
15734    true if we want the N/2 high elements, else the low elements.  */
15735
15736 void
15737 ix86_expand_sse_unpack (rtx operands[2], bool unsigned_p, bool high_p)
15738 {
15739   enum machine_mode imode = GET_MODE (operands[1]);
15740   rtx (*unpack)(rtx, rtx, rtx);
15741   rtx se, dest;
15742
15743   switch (imode)
15744     {
15745     case V16QImode:
15746       if (high_p)
15747         unpack = gen_vec_interleave_highv16qi;
15748       else
15749         unpack = gen_vec_interleave_lowv16qi;
15750       break;
15751     case V8HImode:
15752       if (high_p)
15753         unpack = gen_vec_interleave_highv8hi;
15754       else
15755         unpack = gen_vec_interleave_lowv8hi;
15756       break;
15757     case V4SImode:
15758       if (high_p)
15759         unpack = gen_vec_interleave_highv4si;
15760       else
15761         unpack = gen_vec_interleave_lowv4si;
15762       break;
15763     default:
15764       gcc_unreachable ();
15765     }
15766
15767   dest = gen_lowpart (imode, operands[0]);
15768
15769   if (unsigned_p)
15770     se = force_reg (imode, CONST0_RTX (imode));
15771   else
15772     se = ix86_expand_sse_cmp (gen_reg_rtx (imode), GT, CONST0_RTX (imode),
15773                               operands[1], pc_rtx, pc_rtx);
15774
15775   emit_insn (unpack (dest, operands[1], se));
15776 }
15777
15778 /* This function performs the same task as ix86_expand_sse_unpack,
15779    but with SSE4.1 instructions.  */
15780
15781 void
15782 ix86_expand_sse4_unpack (rtx operands[2], bool unsigned_p, bool high_p)
15783 {
15784   enum machine_mode imode = GET_MODE (operands[1]);
15785   rtx (*unpack)(rtx, rtx);
15786   rtx src, dest;
15787
15788   switch (imode)
15789     {
15790     case V16QImode:
15791       if (unsigned_p)
15792         unpack = gen_sse4_1_zero_extendv8qiv8hi2;
15793       else
15794         unpack = gen_sse4_1_extendv8qiv8hi2;
15795       break;
15796     case V8HImode:
15797       if (unsigned_p)
15798         unpack = gen_sse4_1_zero_extendv4hiv4si2;
15799       else
15800         unpack = gen_sse4_1_extendv4hiv4si2;
15801       break;
15802     case V4SImode:
15803       if (unsigned_p)
15804         unpack = gen_sse4_1_zero_extendv2siv2di2;
15805       else
15806         unpack = gen_sse4_1_extendv2siv2di2;
15807       break;
15808     default:
15809       gcc_unreachable ();
15810     }
15811
15812   dest = operands[0];
15813   if (high_p)
15814     {
15815       /* Shift higher 8 bytes to lower 8 bytes.  */
15816       src = gen_reg_rtx (imode);
15817       emit_insn (gen_sse2_lshrti3 (gen_lowpart (TImode, src),
15818                                    gen_lowpart (TImode, operands[1]),
15819                                    GEN_INT (64)));
15820     }
15821   else
15822     src = operands[1];
15823
15824   emit_insn (unpack (dest, src));
15825 }
15826
15827 /* This function performs the same task as ix86_expand_sse_unpack,
15828    but with sse5 instructions.  */
15829
15830 void
15831 ix86_expand_sse5_unpack (rtx operands[2], bool unsigned_p, bool high_p)
15832 {
15833   enum machine_mode imode = GET_MODE (operands[1]);
15834   int pperm_bytes[16];
15835   int i;
15836   int h = (high_p) ? 8 : 0;
15837   int h2;
15838   int sign_extend;
15839   rtvec v = rtvec_alloc (16);
15840   rtvec vs;
15841   rtx x, p;
15842   rtx op0 = operands[0], op1 = operands[1];
15843
15844   switch (imode)
15845     {
15846     case V16QImode:
15847       vs = rtvec_alloc (8);
15848       h2 = (high_p) ? 8 : 0;
15849       for (i = 0; i < 8; i++)
15850         {
15851           pperm_bytes[2*i+0] = PPERM_SRC | PPERM_SRC2 | i | h;
15852           pperm_bytes[2*i+1] = ((unsigned_p)
15853                                 ? PPERM_ZERO
15854                                 : PPERM_SIGN | PPERM_SRC2 | i | h);
15855         }
15856
15857       for (i = 0; i < 16; i++)
15858         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15859
15860       for (i = 0; i < 8; i++)
15861         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
15862
15863       p = gen_rtx_PARALLEL (VOIDmode, vs);
15864       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15865       if (unsigned_p)
15866         emit_insn (gen_sse5_pperm_zero_v16qi_v8hi (op0, op1, p, x));
15867       else
15868         emit_insn (gen_sse5_pperm_sign_v16qi_v8hi (op0, op1, p, x));
15869       break;
15870
15871     case V8HImode:
15872       vs = rtvec_alloc (4);
15873       h2 = (high_p) ? 4 : 0;
15874       for (i = 0; i < 4; i++)
15875         {
15876           sign_extend = ((unsigned_p)
15877                          ? PPERM_ZERO
15878                          : PPERM_SIGN | PPERM_SRC2 | ((2*i) + 1 + h));
15879           pperm_bytes[4*i+0] = PPERM_SRC | PPERM_SRC2 | ((2*i) + 0 + h);
15880           pperm_bytes[4*i+1] = PPERM_SRC | PPERM_SRC2 | ((2*i) + 1 + h);
15881           pperm_bytes[4*i+2] = sign_extend;
15882           pperm_bytes[4*i+3] = sign_extend;
15883         }
15884
15885       for (i = 0; i < 16; i++)
15886         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15887
15888       for (i = 0; i < 4; i++)
15889         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
15890
15891       p = gen_rtx_PARALLEL (VOIDmode, vs);
15892       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15893       if (unsigned_p)
15894         emit_insn (gen_sse5_pperm_zero_v8hi_v4si (op0, op1, p, x));
15895       else
15896         emit_insn (gen_sse5_pperm_sign_v8hi_v4si (op0, op1, p, x));
15897       break;
15898
15899     case V4SImode:
15900       vs = rtvec_alloc (2);
15901       h2 = (high_p) ? 2 : 0;
15902       for (i = 0; i < 2; i++)
15903         {
15904           sign_extend = ((unsigned_p)
15905                          ? PPERM_ZERO
15906                          : PPERM_SIGN | PPERM_SRC2 | ((4*i) + 3 + h));
15907           pperm_bytes[8*i+0] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 0 + h);
15908           pperm_bytes[8*i+1] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 1 + h);
15909           pperm_bytes[8*i+2] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 2 + h);
15910           pperm_bytes[8*i+3] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 3 + h);
15911           pperm_bytes[8*i+4] = sign_extend;
15912           pperm_bytes[8*i+5] = sign_extend;
15913           pperm_bytes[8*i+6] = sign_extend;
15914           pperm_bytes[8*i+7] = sign_extend;
15915         }
15916
15917       for (i = 0; i < 16; i++)
15918         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15919
15920       for (i = 0; i < 2; i++)
15921         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
15922
15923       p = gen_rtx_PARALLEL (VOIDmode, vs);
15924       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15925       if (unsigned_p)
15926         emit_insn (gen_sse5_pperm_zero_v4si_v2di (op0, op1, p, x));
15927       else
15928         emit_insn (gen_sse5_pperm_sign_v4si_v2di (op0, op1, p, x));
15929       break;
15930
15931     default:
15932       gcc_unreachable ();
15933     }
15934
15935   return;
15936 }
15937
15938 /* Pack the high bits from OPERANDS[1] and low bits from OPERANDS[2] into the
15939    next narrower integer vector type */
15940 void
15941 ix86_expand_sse5_pack (rtx operands[3])
15942 {
15943   enum machine_mode imode = GET_MODE (operands[0]);
15944   int pperm_bytes[16];
15945   int i;
15946   rtvec v = rtvec_alloc (16);
15947   rtx x;
15948   rtx op0 = operands[0];
15949   rtx op1 = operands[1];
15950   rtx op2 = operands[2];
15951
15952   switch (imode)
15953     {
15954     case V16QImode:
15955       for (i = 0; i < 8; i++)
15956         {
15957           pperm_bytes[i+0] = PPERM_SRC | PPERM_SRC1 | (i*2);
15958           pperm_bytes[i+8] = PPERM_SRC | PPERM_SRC2 | (i*2);
15959         }
15960
15961       for (i = 0; i < 16; i++)
15962         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15963
15964       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15965       emit_insn (gen_sse5_pperm_pack_v8hi_v16qi (op0, op1, op2, x));
15966       break;
15967
15968     case V8HImode:
15969       for (i = 0; i < 4; i++)
15970         {
15971           pperm_bytes[(2*i)+0] = PPERM_SRC | PPERM_SRC1 | ((i*4) + 0);
15972           pperm_bytes[(2*i)+1] = PPERM_SRC | PPERM_SRC1 | ((i*4) + 1);
15973           pperm_bytes[(2*i)+8] = PPERM_SRC | PPERM_SRC2 | ((i*4) + 0);
15974           pperm_bytes[(2*i)+9] = PPERM_SRC | PPERM_SRC2 | ((i*4) + 1);
15975         }
15976
15977       for (i = 0; i < 16; i++)
15978         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15979
15980       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15981       emit_insn (gen_sse5_pperm_pack_v4si_v8hi (op0, op1, op2, x));
15982       break;
15983
15984     case V4SImode:
15985       for (i = 0; i < 2; i++)
15986         {
15987           pperm_bytes[(4*i)+0]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 0);
15988           pperm_bytes[(4*i)+1]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 1);
15989           pperm_bytes[(4*i)+2]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 2);
15990           pperm_bytes[(4*i)+3]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 3);
15991           pperm_bytes[(4*i)+8]  = PPERM_SRC | PPERM_SRC2 | ((i*8) + 0);
15992           pperm_bytes[(4*i)+9]  = PPERM_SRC | PPERM_SRC2 | ((i*8) + 1);
15993           pperm_bytes[(4*i)+10] = PPERM_SRC | PPERM_SRC2 | ((i*8) + 2);
15994           pperm_bytes[(4*i)+11] = PPERM_SRC | PPERM_SRC2 | ((i*8) + 3);
15995         }
15996
15997       for (i = 0; i < 16; i++)
15998         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15999
16000       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
16001       emit_insn (gen_sse5_pperm_pack_v2di_v4si (op0, op1, op2, x));
16002       break;
16003
16004     default:
16005       gcc_unreachable ();
16006     }
16007
16008   return;
16009 }
16010
16011 /* Expand conditional increment or decrement using adb/sbb instructions.
16012    The default case using setcc followed by the conditional move can be
16013    done by generic code.  */
16014 int
16015 ix86_expand_int_addcc (rtx operands[])
16016 {
16017   enum rtx_code code = GET_CODE (operands[1]);
16018   rtx compare_op;
16019   rtx val = const0_rtx;
16020   bool fpcmp = false;
16021   enum machine_mode mode = GET_MODE (operands[0]);
16022
16023   if (operands[3] != const1_rtx
16024       && operands[3] != constm1_rtx)
16025     return 0;
16026   if (!ix86_expand_carry_flag_compare (code, ix86_compare_op0,
16027                                        ix86_compare_op1, &compare_op))
16028      return 0;
16029   code = GET_CODE (compare_op);
16030
16031   if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
16032       || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
16033     {
16034       fpcmp = true;
16035       code = ix86_fp_compare_code_to_integer (code);
16036     }
16037
16038   if (code != LTU)
16039     {
16040       val = constm1_rtx;
16041       if (fpcmp)
16042         PUT_CODE (compare_op,
16043                   reverse_condition_maybe_unordered
16044                     (GET_CODE (compare_op)));
16045       else
16046         PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
16047     }
16048   PUT_MODE (compare_op, mode);
16049
16050   /* Construct either adc or sbb insn.  */
16051   if ((code == LTU) == (operands[3] == constm1_rtx))
16052     {
16053       switch (GET_MODE (operands[0]))
16054         {
16055           case QImode:
16056             emit_insn (gen_subqi3_carry (operands[0], operands[2], val, compare_op));
16057             break;
16058           case HImode:
16059             emit_insn (gen_subhi3_carry (operands[0], operands[2], val, compare_op));
16060             break;
16061           case SImode:
16062             emit_insn (gen_subsi3_carry (operands[0], operands[2], val, compare_op));
16063             break;
16064           case DImode:
16065             emit_insn (gen_subdi3_carry_rex64 (operands[0], operands[2], val, compare_op));
16066             break;
16067           default:
16068             gcc_unreachable ();
16069         }
16070     }
16071   else
16072     {
16073       switch (GET_MODE (operands[0]))
16074         {
16075           case QImode:
16076             emit_insn (gen_addqi3_carry (operands[0], operands[2], val, compare_op));
16077             break;
16078           case HImode:
16079             emit_insn (gen_addhi3_carry (operands[0], operands[2], val, compare_op));
16080             break;
16081           case SImode:
16082             emit_insn (gen_addsi3_carry (operands[0], operands[2], val, compare_op));
16083             break;
16084           case DImode:
16085             emit_insn (gen_adddi3_carry_rex64 (operands[0], operands[2], val, compare_op));
16086             break;
16087           default:
16088             gcc_unreachable ();
16089         }
16090     }
16091   return 1; /* DONE */
16092 }
16093
16094
16095 /* Split operands 0 and 1 into SImode parts.  Similar to split_di, but
16096    works for floating pointer parameters and nonoffsetable memories.
16097    For pushes, it returns just stack offsets; the values will be saved
16098    in the right order.  Maximally three parts are generated.  */
16099
16100 static int
16101 ix86_split_to_parts (rtx operand, rtx *parts, enum machine_mode mode)
16102 {
16103   int size;
16104
16105   if (!TARGET_64BIT)
16106     size = mode==XFmode ? 3 : GET_MODE_SIZE (mode) / 4;
16107   else
16108     size = (GET_MODE_SIZE (mode) + 4) / 8;
16109
16110   gcc_assert (!REG_P (operand) || !MMX_REGNO_P (REGNO (operand)));
16111   gcc_assert (size >= 2 && size <= 4);
16112
16113   /* Optimize constant pool reference to immediates.  This is used by fp
16114      moves, that force all constants to memory to allow combining.  */
16115   if (MEM_P (operand) && MEM_READONLY_P (operand))
16116     {
16117       rtx tmp = maybe_get_pool_constant (operand);
16118       if (tmp)
16119         operand = tmp;
16120     }
16121
16122   if (MEM_P (operand) && !offsettable_memref_p (operand))
16123     {
16124       /* The only non-offsetable memories we handle are pushes.  */
16125       int ok = push_operand (operand, VOIDmode);
16126
16127       gcc_assert (ok);
16128
16129       operand = copy_rtx (operand);
16130       PUT_MODE (operand, Pmode);
16131       parts[0] = parts[1] = parts[2] = parts[3] = operand;
16132       return size;
16133     }
16134
16135   if (GET_CODE (operand) == CONST_VECTOR)
16136     {
16137       enum machine_mode imode = int_mode_for_mode (mode);
16138       /* Caution: if we looked through a constant pool memory above,
16139          the operand may actually have a different mode now.  That's
16140          ok, since we want to pun this all the way back to an integer.  */
16141       operand = simplify_subreg (imode, operand, GET_MODE (operand), 0);
16142       gcc_assert (operand != NULL);
16143       mode = imode;
16144     }
16145
16146   if (!TARGET_64BIT)
16147     {
16148       if (mode == DImode)
16149         split_di (&operand, 1, &parts[0], &parts[1]);
16150       else
16151         {
16152           int i;
16153
16154           if (REG_P (operand))
16155             {
16156               gcc_assert (reload_completed);
16157               for (i = 0; i < size; i++)
16158                 parts[i] = gen_rtx_REG (SImode, REGNO (operand) + i);
16159             }
16160           else if (offsettable_memref_p (operand))
16161             {
16162               operand = adjust_address (operand, SImode, 0);
16163               parts[0] = operand;
16164               for (i = 1; i < size; i++)
16165                 parts[i] = adjust_address (operand, SImode, 4 * i);
16166             }
16167           else if (GET_CODE (operand) == CONST_DOUBLE)
16168             {
16169               REAL_VALUE_TYPE r;
16170               long l[4];
16171
16172               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
16173               switch (mode)
16174                 {
16175                 case TFmode:
16176                   real_to_target (l, &r, mode);
16177                   parts[3] = gen_int_mode (l[3], SImode);
16178                   parts[2] = gen_int_mode (l[2], SImode);
16179                   break;
16180                 case XFmode:
16181                   REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
16182                   parts[2] = gen_int_mode (l[2], SImode);
16183                   break;
16184                 case DFmode:
16185                   REAL_VALUE_TO_TARGET_DOUBLE (r, l);
16186                   break;
16187                 default:
16188                   gcc_unreachable ();
16189                 }
16190               parts[1] = gen_int_mode (l[1], SImode);
16191               parts[0] = gen_int_mode (l[0], SImode);
16192             }
16193           else
16194             gcc_unreachable ();
16195         }
16196     }
16197   else
16198     {
16199       if (mode == TImode)
16200         split_ti (&operand, 1, &parts[0], &parts[1]);
16201       if (mode == XFmode || mode == TFmode)
16202         {
16203           enum machine_mode upper_mode = mode==XFmode ? SImode : DImode;
16204           if (REG_P (operand))
16205             {
16206               gcc_assert (reload_completed);
16207               parts[0] = gen_rtx_REG (DImode, REGNO (operand) + 0);
16208               parts[1] = gen_rtx_REG (upper_mode, REGNO (operand) + 1);
16209             }
16210           else if (offsettable_memref_p (operand))
16211             {
16212               operand = adjust_address (operand, DImode, 0);
16213               parts[0] = operand;
16214               parts[1] = adjust_address (operand, upper_mode, 8);
16215             }
16216           else if (GET_CODE (operand) == CONST_DOUBLE)
16217             {
16218               REAL_VALUE_TYPE r;
16219               long l[4];
16220
16221               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
16222               real_to_target (l, &r, mode);
16223
16224               /* Do not use shift by 32 to avoid warning on 32bit systems.  */
16225               if (HOST_BITS_PER_WIDE_INT >= 64)
16226                 parts[0]
16227                   = gen_int_mode
16228                       ((l[0] & (((HOST_WIDE_INT) 2 << 31) - 1))
16229                        + ((((HOST_WIDE_INT) l[1]) << 31) << 1),
16230                        DImode);
16231               else
16232                 parts[0] = immed_double_const (l[0], l[1], DImode);
16233
16234               if (upper_mode == SImode)
16235                 parts[1] = gen_int_mode (l[2], SImode);
16236               else if (HOST_BITS_PER_WIDE_INT >= 64)
16237                 parts[1]
16238                   = gen_int_mode
16239                       ((l[2] & (((HOST_WIDE_INT) 2 << 31) - 1))
16240                        + ((((HOST_WIDE_INT) l[3]) << 31) << 1),
16241                        DImode);
16242               else
16243                 parts[1] = immed_double_const (l[2], l[3], DImode);
16244             }
16245           else
16246             gcc_unreachable ();
16247         }
16248     }
16249
16250   return size;
16251 }
16252
16253 /* Emit insns to perform a move or push of DI, DF, XF, and TF values.
16254    Return false when normal moves are needed; true when all required
16255    insns have been emitted.  Operands 2-4 contain the input values
16256    int the correct order; operands 5-7 contain the output values.  */
16257
16258 void
16259 ix86_split_long_move (rtx operands[])
16260 {
16261   rtx part[2][4];
16262   int nparts, i, j;
16263   int push = 0;
16264   int collisions = 0;
16265   enum machine_mode mode = GET_MODE (operands[0]);
16266   bool collisionparts[4];
16267
16268   /* The DFmode expanders may ask us to move double.
16269      For 64bit target this is single move.  By hiding the fact
16270      here we simplify i386.md splitters.  */
16271   if (GET_MODE_SIZE (GET_MODE (operands[0])) == 8 && TARGET_64BIT)
16272     {
16273       /* Optimize constant pool reference to immediates.  This is used by
16274          fp moves, that force all constants to memory to allow combining.  */
16275
16276       if (MEM_P (operands[1])
16277           && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
16278           && CONSTANT_POOL_ADDRESS_P (XEXP (operands[1], 0)))
16279         operands[1] = get_pool_constant (XEXP (operands[1], 0));
16280       if (push_operand (operands[0], VOIDmode))
16281         {
16282           operands[0] = copy_rtx (operands[0]);
16283           PUT_MODE (operands[0], Pmode);
16284         }
16285       else
16286         operands[0] = gen_lowpart (DImode, operands[0]);
16287       operands[1] = gen_lowpart (DImode, operands[1]);
16288       emit_move_insn (operands[0], operands[1]);
16289       return;
16290     }
16291
16292   /* The only non-offsettable memory we handle is push.  */
16293   if (push_operand (operands[0], VOIDmode))
16294     push = 1;
16295   else
16296     gcc_assert (!MEM_P (operands[0])
16297                 || offsettable_memref_p (operands[0]));
16298
16299   nparts = ix86_split_to_parts (operands[1], part[1], GET_MODE (operands[0]));
16300   ix86_split_to_parts (operands[0], part[0], GET_MODE (operands[0]));
16301
16302   /* When emitting push, take care for source operands on the stack.  */
16303   if (push && MEM_P (operands[1])
16304       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
16305     {
16306       rtx src_base = XEXP (part[1][nparts - 1], 0);
16307
16308       /* Compensate for the stack decrement by 4.  */
16309       if (!TARGET_64BIT && nparts == 3
16310           && mode == XFmode && TARGET_128BIT_LONG_DOUBLE)
16311         src_base = plus_constant (src_base, 4);
16312
16313       /* src_base refers to the stack pointer and is
16314          automatically decreased by emitted push.  */
16315       for (i = 0; i < nparts; i++)
16316         part[1][i] = change_address (part[1][i],
16317                                      GET_MODE (part[1][i]), src_base);
16318     }
16319
16320   /* We need to do copy in the right order in case an address register
16321      of the source overlaps the destination.  */
16322   if (REG_P (part[0][0]) && MEM_P (part[1][0]))
16323     {
16324       rtx tmp;
16325
16326       for (i = 0; i < nparts; i++)
16327         {
16328           collisionparts[i]
16329             = reg_overlap_mentioned_p (part[0][i], XEXP (part[1][0], 0));
16330           if (collisionparts[i])
16331             collisions++;
16332         }
16333
16334       /* Collision in the middle part can be handled by reordering.  */
16335       if (collisions == 1 && nparts == 3 && collisionparts [1])
16336         {
16337           tmp = part[0][1]; part[0][1] = part[0][2]; part[0][2] = tmp;
16338           tmp = part[1][1]; part[1][1] = part[1][2]; part[1][2] = tmp;
16339         }
16340       else if (collisions == 1
16341                && nparts == 4
16342                && (collisionparts [1] || collisionparts [2]))
16343         {
16344           if (collisionparts [1])
16345             {
16346               tmp = part[0][1]; part[0][1] = part[0][2]; part[0][2] = tmp;
16347               tmp = part[1][1]; part[1][1] = part[1][2]; part[1][2] = tmp;
16348             }
16349           else
16350             {
16351               tmp = part[0][2]; part[0][2] = part[0][3]; part[0][3] = tmp;
16352               tmp = part[1][2]; part[1][2] = part[1][3]; part[1][3] = tmp;
16353             }
16354         }
16355
16356       /* If there are more collisions, we can't handle it by reordering.
16357          Do an lea to the last part and use only one colliding move.  */
16358       else if (collisions > 1)
16359         {
16360           rtx base;
16361
16362           collisions = 1;
16363
16364           base = part[0][nparts - 1];
16365
16366           /* Handle the case when the last part isn't valid for lea.
16367              Happens in 64-bit mode storing the 12-byte XFmode.  */
16368           if (GET_MODE (base) != Pmode)
16369             base = gen_rtx_REG (Pmode, REGNO (base));
16370
16371           emit_insn (gen_rtx_SET (VOIDmode, base, XEXP (part[1][0], 0)));
16372           part[1][0] = replace_equiv_address (part[1][0], base);
16373           for (i = 1; i < nparts; i++)
16374             {
16375               tmp = plus_constant (base, UNITS_PER_WORD * i);
16376               part[1][i] = replace_equiv_address (part[1][i], tmp);
16377             }
16378         }
16379     }
16380
16381   if (push)
16382     {
16383       if (!TARGET_64BIT)
16384         {
16385           if (nparts == 3)
16386             {
16387               if (TARGET_128BIT_LONG_DOUBLE && mode == XFmode)
16388                 emit_insn (gen_addsi3 (stack_pointer_rtx,
16389                                        stack_pointer_rtx, GEN_INT (-4)));
16390               emit_move_insn (part[0][2], part[1][2]);
16391             }
16392           else if (nparts == 4)
16393             {
16394               emit_move_insn (part[0][3], part[1][3]);
16395               emit_move_insn (part[0][2], part[1][2]);
16396             }
16397         }
16398       else
16399         {
16400           /* In 64bit mode we don't have 32bit push available.  In case this is
16401              register, it is OK - we will just use larger counterpart.  We also
16402              retype memory - these comes from attempt to avoid REX prefix on
16403              moving of second half of TFmode value.  */
16404           if (GET_MODE (part[1][1]) == SImode)
16405             {
16406               switch (GET_CODE (part[1][1]))
16407                 {
16408                 case MEM:
16409                   part[1][1] = adjust_address (part[1][1], DImode, 0);
16410                   break;
16411
16412                 case REG:
16413                   part[1][1] = gen_rtx_REG (DImode, REGNO (part[1][1]));
16414                   break;
16415
16416                 default:
16417                   gcc_unreachable ();
16418                 }
16419
16420               if (GET_MODE (part[1][0]) == SImode)
16421                 part[1][0] = part[1][1];
16422             }
16423         }
16424       emit_move_insn (part[0][1], part[1][1]);
16425       emit_move_insn (part[0][0], part[1][0]);
16426       return;
16427     }
16428
16429   /* Choose correct order to not overwrite the source before it is copied.  */
16430   if ((REG_P (part[0][0])
16431        && REG_P (part[1][1])
16432        && (REGNO (part[0][0]) == REGNO (part[1][1])
16433            || (nparts == 3
16434                && REGNO (part[0][0]) == REGNO (part[1][2]))
16435            || (nparts == 4
16436                && REGNO (part[0][0]) == REGNO (part[1][3]))))
16437       || (collisions > 0
16438           && reg_overlap_mentioned_p (part[0][0], XEXP (part[1][0], 0))))
16439     {
16440       for (i = 0, j = nparts - 1; i < nparts; i++, j--)
16441         {
16442           operands[2 + i] = part[0][j];
16443           operands[6 + i] = part[1][j];
16444         }
16445     }
16446   else
16447     {
16448       for (i = 0; i < nparts; i++)
16449         {
16450           operands[2 + i] = part[0][i];
16451           operands[6 + i] = part[1][i];
16452         }
16453     }
16454
16455   /* If optimizing for size, attempt to locally unCSE nonzero constants.  */
16456   if (optimize_insn_for_size_p ())
16457     {
16458       for (j = 0; j < nparts - 1; j++)
16459         if (CONST_INT_P (operands[6 + j])
16460             && operands[6 + j] != const0_rtx
16461             && REG_P (operands[2 + j]))
16462           for (i = j; i < nparts - 1; i++)
16463             if (CONST_INT_P (operands[7 + i])
16464                 && INTVAL (operands[7 + i]) == INTVAL (operands[6 + j]))
16465               operands[7 + i] = operands[2 + j];
16466     }
16467
16468   for (i = 0; i < nparts; i++)
16469     emit_move_insn (operands[2 + i], operands[6 + i]);
16470
16471   return;
16472 }
16473
16474 /* Helper function of ix86_split_ashl used to generate an SImode/DImode
16475    left shift by a constant, either using a single shift or
16476    a sequence of add instructions.  */
16477
16478 static void
16479 ix86_expand_ashl_const (rtx operand, int count, enum machine_mode mode)
16480 {
16481   if (count == 1)
16482     {
16483       emit_insn ((mode == DImode
16484                   ? gen_addsi3
16485                   : gen_adddi3) (operand, operand, operand));
16486     }
16487   else if (!optimize_insn_for_size_p ()
16488            && count * ix86_cost->add <= ix86_cost->shift_const)
16489     {
16490       int i;
16491       for (i=0; i<count; i++)
16492         {
16493           emit_insn ((mode == DImode
16494                       ? gen_addsi3
16495                       : gen_adddi3) (operand, operand, operand));
16496         }
16497     }
16498   else
16499     emit_insn ((mode == DImode
16500                 ? gen_ashlsi3
16501                 : gen_ashldi3) (operand, operand, GEN_INT (count)));
16502 }
16503
16504 void
16505 ix86_split_ashl (rtx *operands, rtx scratch, enum machine_mode mode)
16506 {
16507   rtx low[2], high[2];
16508   int count;
16509   const int single_width = mode == DImode ? 32 : 64;
16510
16511   if (CONST_INT_P (operands[2]))
16512     {
16513       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
16514       count = INTVAL (operands[2]) & (single_width * 2 - 1);
16515
16516       if (count >= single_width)
16517         {
16518           emit_move_insn (high[0], low[1]);
16519           emit_move_insn (low[0], const0_rtx);
16520
16521           if (count > single_width)
16522             ix86_expand_ashl_const (high[0], count - single_width, mode);
16523         }
16524       else
16525         {
16526           if (!rtx_equal_p (operands[0], operands[1]))
16527             emit_move_insn (operands[0], operands[1]);
16528           emit_insn ((mode == DImode
16529                      ? gen_x86_shld
16530                      : gen_x86_64_shld) (high[0], low[0], GEN_INT (count)));
16531           ix86_expand_ashl_const (low[0], count, mode);
16532         }
16533       return;
16534     }
16535
16536   (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16537
16538   if (operands[1] == const1_rtx)
16539     {
16540       /* Assuming we've chosen a QImode capable registers, then 1 << N
16541          can be done with two 32/64-bit shifts, no branches, no cmoves.  */
16542       if (ANY_QI_REG_P (low[0]) && ANY_QI_REG_P (high[0]))
16543         {
16544           rtx s, d, flags = gen_rtx_REG (CCZmode, FLAGS_REG);
16545
16546           ix86_expand_clear (low[0]);
16547           ix86_expand_clear (high[0]);
16548           emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (single_width)));
16549
16550           d = gen_lowpart (QImode, low[0]);
16551           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
16552           s = gen_rtx_EQ (QImode, flags, const0_rtx);
16553           emit_insn (gen_rtx_SET (VOIDmode, d, s));
16554
16555           d = gen_lowpart (QImode, high[0]);
16556           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
16557           s = gen_rtx_NE (QImode, flags, const0_rtx);
16558           emit_insn (gen_rtx_SET (VOIDmode, d, s));
16559         }
16560
16561       /* Otherwise, we can get the same results by manually performing
16562          a bit extract operation on bit 5/6, and then performing the two
16563          shifts.  The two methods of getting 0/1 into low/high are exactly
16564          the same size.  Avoiding the shift in the bit extract case helps
16565          pentium4 a bit; no one else seems to care much either way.  */
16566       else
16567         {
16568           rtx x;
16569
16570           if (TARGET_PARTIAL_REG_STALL && !optimize_insn_for_size_p ())
16571             x = gen_rtx_ZERO_EXTEND (mode == DImode ? SImode : DImode, operands[2]);
16572           else
16573             x = gen_lowpart (mode == DImode ? SImode : DImode, operands[2]);
16574           emit_insn (gen_rtx_SET (VOIDmode, high[0], x));
16575
16576           emit_insn ((mode == DImode
16577                       ? gen_lshrsi3
16578                       : gen_lshrdi3) (high[0], high[0], GEN_INT (mode == DImode ? 5 : 6)));
16579           emit_insn ((mode == DImode
16580                       ? gen_andsi3
16581                       : gen_anddi3) (high[0], high[0], GEN_INT (1)));
16582           emit_move_insn (low[0], high[0]);
16583           emit_insn ((mode == DImode
16584                       ? gen_xorsi3
16585                       : gen_xordi3) (low[0], low[0], GEN_INT (1)));
16586         }
16587
16588       emit_insn ((mode == DImode
16589                     ? gen_ashlsi3
16590                     : gen_ashldi3) (low[0], low[0], operands[2]));
16591       emit_insn ((mode == DImode
16592                     ? gen_ashlsi3
16593                     : gen_ashldi3) (high[0], high[0], operands[2]));
16594       return;
16595     }
16596
16597   if (operands[1] == constm1_rtx)
16598     {
16599       /* For -1 << N, we can avoid the shld instruction, because we
16600          know that we're shifting 0...31/63 ones into a -1.  */
16601       emit_move_insn (low[0], constm1_rtx);
16602       if (optimize_insn_for_size_p ())
16603         emit_move_insn (high[0], low[0]);
16604       else
16605         emit_move_insn (high[0], constm1_rtx);
16606     }
16607   else
16608     {
16609       if (!rtx_equal_p (operands[0], operands[1]))
16610         emit_move_insn (operands[0], operands[1]);
16611
16612       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16613       emit_insn ((mode == DImode
16614                   ? gen_x86_shld
16615                   : gen_x86_64_shld) (high[0], low[0], operands[2]));
16616     }
16617
16618   emit_insn ((mode == DImode ? gen_ashlsi3 : gen_ashldi3) (low[0], low[0], operands[2]));
16619
16620   if (TARGET_CMOVE && scratch)
16621     {
16622       ix86_expand_clear (scratch);
16623       emit_insn ((mode == DImode
16624                   ? gen_x86_shift_adj_1
16625                   : gen_x86_64_shift_adj_1) (high[0], low[0], operands[2],
16626                                              scratch));
16627     }
16628   else
16629     emit_insn ((mode == DImode
16630                 ? gen_x86_shift_adj_2
16631                 : gen_x86_64_shift_adj_2) (high[0], low[0], operands[2]));
16632 }
16633
16634 void
16635 ix86_split_ashr (rtx *operands, rtx scratch, enum machine_mode mode)
16636 {
16637   rtx low[2], high[2];
16638   int count;
16639   const int single_width = mode == DImode ? 32 : 64;
16640
16641   if (CONST_INT_P (operands[2]))
16642     {
16643       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
16644       count = INTVAL (operands[2]) & (single_width * 2 - 1);
16645
16646       if (count == single_width * 2 - 1)
16647         {
16648           emit_move_insn (high[0], high[1]);
16649           emit_insn ((mode == DImode
16650                       ? gen_ashrsi3
16651                       : gen_ashrdi3) (high[0], high[0],
16652                                       GEN_INT (single_width - 1)));
16653           emit_move_insn (low[0], high[0]);
16654
16655         }
16656       else if (count >= single_width)
16657         {
16658           emit_move_insn (low[0], high[1]);
16659           emit_move_insn (high[0], low[0]);
16660           emit_insn ((mode == DImode
16661                       ? gen_ashrsi3
16662                       : gen_ashrdi3) (high[0], high[0],
16663                                       GEN_INT (single_width - 1)));
16664           if (count > single_width)
16665             emit_insn ((mode == DImode
16666                         ? gen_ashrsi3
16667                         : gen_ashrdi3) (low[0], low[0],
16668                                         GEN_INT (count - single_width)));
16669         }
16670       else
16671         {
16672           if (!rtx_equal_p (operands[0], operands[1]))
16673             emit_move_insn (operands[0], operands[1]);
16674           emit_insn ((mode == DImode
16675                       ? gen_x86_shrd
16676                       : gen_x86_64_shrd) (low[0], high[0], GEN_INT (count)));
16677           emit_insn ((mode == DImode
16678                       ? gen_ashrsi3
16679                       : gen_ashrdi3) (high[0], high[0], GEN_INT (count)));
16680         }
16681     }
16682   else
16683     {
16684       if (!rtx_equal_p (operands[0], operands[1]))
16685         emit_move_insn (operands[0], operands[1]);
16686
16687       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16688
16689       emit_insn ((mode == DImode
16690                   ? gen_x86_shrd
16691                   : gen_x86_64_shrd) (low[0], high[0], operands[2]));
16692       emit_insn ((mode == DImode
16693                   ? gen_ashrsi3
16694                   : gen_ashrdi3)  (high[0], high[0], operands[2]));
16695
16696       if (TARGET_CMOVE && scratch)
16697         {
16698           emit_move_insn (scratch, high[0]);
16699           emit_insn ((mode == DImode
16700                       ? gen_ashrsi3
16701                       : gen_ashrdi3) (scratch, scratch,
16702                                       GEN_INT (single_width - 1)));
16703           emit_insn ((mode == DImode
16704                       ? gen_x86_shift_adj_1
16705                       : gen_x86_64_shift_adj_1) (low[0], high[0], operands[2],
16706                                                  scratch));
16707         }
16708       else
16709         emit_insn ((mode == DImode
16710                     ? gen_x86_shift_adj_3
16711                     : gen_x86_64_shift_adj_3) (low[0], high[0], operands[2]));
16712     }
16713 }
16714
16715 void
16716 ix86_split_lshr (rtx *operands, rtx scratch, enum machine_mode mode)
16717 {
16718   rtx low[2], high[2];
16719   int count;
16720   const int single_width = mode == DImode ? 32 : 64;
16721
16722   if (CONST_INT_P (operands[2]))
16723     {
16724       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
16725       count = INTVAL (operands[2]) & (single_width * 2 - 1);
16726
16727       if (count >= single_width)
16728         {
16729           emit_move_insn (low[0], high[1]);
16730           ix86_expand_clear (high[0]);
16731
16732           if (count > single_width)
16733             emit_insn ((mode == DImode
16734                         ? gen_lshrsi3
16735                         : gen_lshrdi3) (low[0], low[0],
16736                                         GEN_INT (count - single_width)));
16737         }
16738       else
16739         {
16740           if (!rtx_equal_p (operands[0], operands[1]))
16741             emit_move_insn (operands[0], operands[1]);
16742           emit_insn ((mode == DImode
16743                       ? gen_x86_shrd
16744                       : gen_x86_64_shrd) (low[0], high[0], GEN_INT (count)));
16745           emit_insn ((mode == DImode
16746                       ? gen_lshrsi3
16747                       : gen_lshrdi3) (high[0], high[0], GEN_INT (count)));
16748         }
16749     }
16750   else
16751     {
16752       if (!rtx_equal_p (operands[0], operands[1]))
16753         emit_move_insn (operands[0], operands[1]);
16754
16755       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16756
16757       emit_insn ((mode == DImode
16758                   ? gen_x86_shrd
16759                   : gen_x86_64_shrd) (low[0], high[0], operands[2]));
16760       emit_insn ((mode == DImode
16761                   ? gen_lshrsi3
16762                   : gen_lshrdi3) (high[0], high[0], operands[2]));
16763
16764       /* Heh.  By reversing the arguments, we can reuse this pattern.  */
16765       if (TARGET_CMOVE && scratch)
16766         {
16767           ix86_expand_clear (scratch);
16768           emit_insn ((mode == DImode
16769                       ? gen_x86_shift_adj_1
16770                       : gen_x86_64_shift_adj_1) (low[0], high[0], operands[2],
16771                                                  scratch));
16772         }
16773       else
16774         emit_insn ((mode == DImode
16775                     ? gen_x86_shift_adj_2
16776                     : gen_x86_64_shift_adj_2) (low[0], high[0], operands[2]));
16777     }
16778 }
16779
16780 /* Predict just emitted jump instruction to be taken with probability PROB.  */
16781 static void
16782 predict_jump (int prob)
16783 {
16784   rtx insn = get_last_insn ();
16785   gcc_assert (JUMP_P (insn));
16786   REG_NOTES (insn)
16787     = gen_rtx_EXPR_LIST (REG_BR_PROB,
16788                          GEN_INT (prob),
16789                          REG_NOTES (insn));
16790 }
16791
16792 /* Helper function for the string operations below.  Dest VARIABLE whether
16793    it is aligned to VALUE bytes.  If true, jump to the label.  */
16794 static rtx
16795 ix86_expand_aligntest (rtx variable, int value, bool epilogue)
16796 {
16797   rtx label = gen_label_rtx ();
16798   rtx tmpcount = gen_reg_rtx (GET_MODE (variable));
16799   if (GET_MODE (variable) == DImode)
16800     emit_insn (gen_anddi3 (tmpcount, variable, GEN_INT (value)));
16801   else
16802     emit_insn (gen_andsi3 (tmpcount, variable, GEN_INT (value)));
16803   emit_cmp_and_jump_insns (tmpcount, const0_rtx, EQ, 0, GET_MODE (variable),
16804                            1, label);
16805   if (epilogue)
16806     predict_jump (REG_BR_PROB_BASE * 50 / 100);
16807   else
16808     predict_jump (REG_BR_PROB_BASE * 90 / 100);
16809   return label;
16810 }
16811
16812 /* Adjust COUNTER by the VALUE.  */
16813 static void
16814 ix86_adjust_counter (rtx countreg, HOST_WIDE_INT value)
16815 {
16816   if (GET_MODE (countreg) == DImode)
16817     emit_insn (gen_adddi3 (countreg, countreg, GEN_INT (-value)));
16818   else
16819     emit_insn (gen_addsi3 (countreg, countreg, GEN_INT (-value)));
16820 }
16821
16822 /* Zero extend possibly SImode EXP to Pmode register.  */
16823 rtx
16824 ix86_zero_extend_to_Pmode (rtx exp)
16825 {
16826   rtx r;
16827   if (GET_MODE (exp) == VOIDmode)
16828     return force_reg (Pmode, exp);
16829   if (GET_MODE (exp) == Pmode)
16830     return copy_to_mode_reg (Pmode, exp);
16831   r = gen_reg_rtx (Pmode);
16832   emit_insn (gen_zero_extendsidi2 (r, exp));
16833   return r;
16834 }
16835
16836 /* Divide COUNTREG by SCALE.  */
16837 static rtx
16838 scale_counter (rtx countreg, int scale)
16839 {
16840   rtx sc;
16841   rtx piece_size_mask;
16842
16843   if (scale == 1)
16844     return countreg;
16845   if (CONST_INT_P (countreg))
16846     return GEN_INT (INTVAL (countreg) / scale);
16847   gcc_assert (REG_P (countreg));
16848
16849   piece_size_mask = GEN_INT (scale - 1);
16850   sc = expand_simple_binop (GET_MODE (countreg), LSHIFTRT, countreg,
16851                             GEN_INT (exact_log2 (scale)),
16852                             NULL, 1, OPTAB_DIRECT);
16853   return sc;
16854 }
16855
16856 /* Return mode for the memcpy/memset loop counter.  Prefer SImode over
16857    DImode for constant loop counts.  */
16858
16859 static enum machine_mode
16860 counter_mode (rtx count_exp)
16861 {
16862   if (GET_MODE (count_exp) != VOIDmode)
16863     return GET_MODE (count_exp);
16864   if (GET_CODE (count_exp) != CONST_INT)
16865     return Pmode;
16866   if (TARGET_64BIT && (INTVAL (count_exp) & ~0xffffffff))
16867     return DImode;
16868   return SImode;
16869 }
16870
16871 /* When SRCPTR is non-NULL, output simple loop to move memory
16872    pointer to SRCPTR to DESTPTR via chunks of MODE unrolled UNROLL times,
16873    overall size is COUNT specified in bytes.  When SRCPTR is NULL, output the
16874    equivalent loop to set memory by VALUE (supposed to be in MODE).
16875
16876    The size is rounded down to whole number of chunk size moved at once.
16877    SRCMEM and DESTMEM provide MEMrtx to feed proper aliasing info.  */
16878
16879
16880 static void
16881 expand_set_or_movmem_via_loop (rtx destmem, rtx srcmem,
16882                                rtx destptr, rtx srcptr, rtx value,
16883                                rtx count, enum machine_mode mode, int unroll,
16884                                int expected_size)
16885 {
16886   rtx out_label, top_label, iter, tmp;
16887   enum machine_mode iter_mode = counter_mode (count);
16888   rtx piece_size = GEN_INT (GET_MODE_SIZE (mode) * unroll);
16889   rtx piece_size_mask = GEN_INT (~((GET_MODE_SIZE (mode) * unroll) - 1));
16890   rtx size;
16891   rtx x_addr;
16892   rtx y_addr;
16893   int i;
16894
16895   top_label = gen_label_rtx ();
16896   out_label = gen_label_rtx ();
16897   iter = gen_reg_rtx (iter_mode);
16898
16899   size = expand_simple_binop (iter_mode, AND, count, piece_size_mask,
16900                               NULL, 1, OPTAB_DIRECT);
16901   /* Those two should combine.  */
16902   if (piece_size == const1_rtx)
16903     {
16904       emit_cmp_and_jump_insns (size, const0_rtx, EQ, NULL_RTX, iter_mode,
16905                                true, out_label);
16906       predict_jump (REG_BR_PROB_BASE * 10 / 100);
16907     }
16908   emit_move_insn (iter, const0_rtx);
16909
16910   emit_label (top_label);
16911
16912   tmp = convert_modes (Pmode, iter_mode, iter, true);
16913   x_addr = gen_rtx_PLUS (Pmode, destptr, tmp);
16914   destmem = change_address (destmem, mode, x_addr);
16915
16916   if (srcmem)
16917     {
16918       y_addr = gen_rtx_PLUS (Pmode, srcptr, copy_rtx (tmp));
16919       srcmem = change_address (srcmem, mode, y_addr);
16920
16921       /* When unrolling for chips that reorder memory reads and writes,
16922          we can save registers by using single temporary.
16923          Also using 4 temporaries is overkill in 32bit mode.  */
16924       if (!TARGET_64BIT && 0)
16925         {
16926           for (i = 0; i < unroll; i++)
16927             {
16928               if (i)
16929                 {
16930                   destmem =
16931                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
16932                   srcmem =
16933                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
16934                 }
16935               emit_move_insn (destmem, srcmem);
16936             }
16937         }
16938       else
16939         {
16940           rtx tmpreg[4];
16941           gcc_assert (unroll <= 4);
16942           for (i = 0; i < unroll; i++)
16943             {
16944               tmpreg[i] = gen_reg_rtx (mode);
16945               if (i)
16946                 {
16947                   srcmem =
16948                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
16949                 }
16950               emit_move_insn (tmpreg[i], srcmem);
16951             }
16952           for (i = 0; i < unroll; i++)
16953             {
16954               if (i)
16955                 {
16956                   destmem =
16957                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
16958                 }
16959               emit_move_insn (destmem, tmpreg[i]);
16960             }
16961         }
16962     }
16963   else
16964     for (i = 0; i < unroll; i++)
16965       {
16966         if (i)
16967           destmem =
16968             adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
16969         emit_move_insn (destmem, value);
16970       }
16971
16972   tmp = expand_simple_binop (iter_mode, PLUS, iter, piece_size, iter,
16973                              true, OPTAB_LIB_WIDEN);
16974   if (tmp != iter)
16975     emit_move_insn (iter, tmp);
16976
16977   emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
16978                            true, top_label);
16979   if (expected_size != -1)
16980     {
16981       expected_size /= GET_MODE_SIZE (mode) * unroll;
16982       if (expected_size == 0)
16983         predict_jump (0);
16984       else if (expected_size > REG_BR_PROB_BASE)
16985         predict_jump (REG_BR_PROB_BASE - 1);
16986       else
16987         predict_jump (REG_BR_PROB_BASE - (REG_BR_PROB_BASE + expected_size / 2) / expected_size);
16988     }
16989   else
16990     predict_jump (REG_BR_PROB_BASE * 80 / 100);
16991   iter = ix86_zero_extend_to_Pmode (iter);
16992   tmp = expand_simple_binop (Pmode, PLUS, destptr, iter, destptr,
16993                              true, OPTAB_LIB_WIDEN);
16994   if (tmp != destptr)
16995     emit_move_insn (destptr, tmp);
16996   if (srcptr)
16997     {
16998       tmp = expand_simple_binop (Pmode, PLUS, srcptr, iter, srcptr,
16999                                  true, OPTAB_LIB_WIDEN);
17000       if (tmp != srcptr)
17001         emit_move_insn (srcptr, tmp);
17002     }
17003   emit_label (out_label);
17004 }
17005
17006 /* Output "rep; mov" instruction.
17007    Arguments have same meaning as for previous function */
17008 static void
17009 expand_movmem_via_rep_mov (rtx destmem, rtx srcmem,
17010                            rtx destptr, rtx srcptr,
17011                            rtx count,
17012                            enum machine_mode mode)
17013 {
17014   rtx destexp;
17015   rtx srcexp;
17016   rtx countreg;
17017
17018   /* If the size is known, it is shorter to use rep movs.  */
17019   if (mode == QImode && CONST_INT_P (count)
17020       && !(INTVAL (count) & 3))
17021     mode = SImode;
17022
17023   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
17024     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
17025   if (srcptr != XEXP (srcmem, 0) || GET_MODE (srcmem) != BLKmode)
17026     srcmem = adjust_automodify_address_nv (srcmem, BLKmode, srcptr, 0);
17027   countreg = ix86_zero_extend_to_Pmode (scale_counter (count, GET_MODE_SIZE (mode)));
17028   if (mode != QImode)
17029     {
17030       destexp = gen_rtx_ASHIFT (Pmode, countreg,
17031                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
17032       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
17033       srcexp = gen_rtx_ASHIFT (Pmode, countreg,
17034                                GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
17035       srcexp = gen_rtx_PLUS (Pmode, srcexp, srcptr);
17036     }
17037   else
17038     {
17039       destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
17040       srcexp = gen_rtx_PLUS (Pmode, srcptr, countreg);
17041     }
17042   if (CONST_INT_P (count))
17043     {
17044       count = GEN_INT (INTVAL (count)
17045                        & ~((HOST_WIDE_INT) GET_MODE_SIZE (mode) - 1));
17046       destmem = shallow_copy_rtx (destmem);
17047       srcmem = shallow_copy_rtx (srcmem);
17048       set_mem_size (destmem, count);
17049       set_mem_size (srcmem, count);
17050     }
17051   else
17052     {
17053       if (MEM_SIZE (destmem))
17054         set_mem_size (destmem, NULL_RTX);
17055       if (MEM_SIZE (srcmem))
17056         set_mem_size (srcmem, NULL_RTX);
17057     }
17058   emit_insn (gen_rep_mov (destptr, destmem, srcptr, srcmem, countreg,
17059                           destexp, srcexp));
17060 }
17061
17062 /* Output "rep; stos" instruction.
17063    Arguments have same meaning as for previous function */
17064 static void
17065 expand_setmem_via_rep_stos (rtx destmem, rtx destptr, rtx value,
17066                             rtx count, enum machine_mode mode,
17067                             rtx orig_value)
17068 {
17069   rtx destexp;
17070   rtx countreg;
17071
17072   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
17073     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
17074   value = force_reg (mode, gen_lowpart (mode, value));
17075   countreg = ix86_zero_extend_to_Pmode (scale_counter (count, GET_MODE_SIZE (mode)));
17076   if (mode != QImode)
17077     {
17078       destexp = gen_rtx_ASHIFT (Pmode, countreg,
17079                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
17080       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
17081     }
17082   else
17083     destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
17084   if (orig_value == const0_rtx && CONST_INT_P (count))
17085     {
17086       count = GEN_INT (INTVAL (count)
17087                        & ~((HOST_WIDE_INT) GET_MODE_SIZE (mode) - 1));
17088       destmem = shallow_copy_rtx (destmem);
17089       set_mem_size (destmem, count);
17090     }
17091   else if (MEM_SIZE (destmem))
17092     set_mem_size (destmem, NULL_RTX);
17093   emit_insn (gen_rep_stos (destptr, countreg, destmem, value, destexp));
17094 }
17095
17096 static void
17097 emit_strmov (rtx destmem, rtx srcmem,
17098              rtx destptr, rtx srcptr, enum machine_mode mode, int offset)
17099 {
17100   rtx src = adjust_automodify_address_nv (srcmem, mode, srcptr, offset);
17101   rtx dest = adjust_automodify_address_nv (destmem, mode, destptr, offset);
17102   emit_insn (gen_strmov (destptr, dest, srcptr, src));
17103 }
17104
17105 /* Output code to copy at most count & (max_size - 1) bytes from SRC to DEST.  */
17106 static void
17107 expand_movmem_epilogue (rtx destmem, rtx srcmem,
17108                         rtx destptr, rtx srcptr, rtx count, int max_size)
17109 {
17110   rtx src, dest;
17111   if (CONST_INT_P (count))
17112     {
17113       HOST_WIDE_INT countval = INTVAL (count);
17114       int offset = 0;
17115
17116       if ((countval & 0x10) && max_size > 16)
17117         {
17118           if (TARGET_64BIT)
17119             {
17120               emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset);
17121               emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset + 8);
17122             }
17123           else
17124             gcc_unreachable ();
17125           offset += 16;
17126         }
17127       if ((countval & 0x08) && max_size > 8)
17128         {
17129           if (TARGET_64BIT)
17130             emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset);
17131           else
17132             {
17133               emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset);
17134               emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset + 4);
17135             }
17136           offset += 8;
17137         }
17138       if ((countval & 0x04) && max_size > 4)
17139         {
17140           emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset);
17141           offset += 4;
17142         }
17143       if ((countval & 0x02) && max_size > 2)
17144         {
17145           emit_strmov (destmem, srcmem, destptr, srcptr, HImode, offset);
17146           offset += 2;
17147         }
17148       if ((countval & 0x01) && max_size > 1)
17149         {
17150           emit_strmov (destmem, srcmem, destptr, srcptr, QImode, offset);
17151           offset += 1;
17152         }
17153       return;
17154     }
17155   if (max_size > 8)
17156     {
17157       count = expand_simple_binop (GET_MODE (count), AND, count, GEN_INT (max_size - 1),
17158                                     count, 1, OPTAB_DIRECT);
17159       expand_set_or_movmem_via_loop (destmem, srcmem, destptr, srcptr, NULL,
17160                                      count, QImode, 1, 4);
17161       return;
17162     }
17163
17164   /* When there are stringops, we can cheaply increase dest and src pointers.
17165      Otherwise we save code size by maintaining offset (zero is readily
17166      available from preceding rep operation) and using x86 addressing modes.
17167    */
17168   if (TARGET_SINGLE_STRINGOP)
17169     {
17170       if (max_size > 4)
17171         {
17172           rtx label = ix86_expand_aligntest (count, 4, true);
17173           src = change_address (srcmem, SImode, srcptr);
17174           dest = change_address (destmem, SImode, destptr);
17175           emit_insn (gen_strmov (destptr, dest, srcptr, src));
17176           emit_label (label);
17177           LABEL_NUSES (label) = 1;
17178         }
17179       if (max_size > 2)
17180         {
17181           rtx label = ix86_expand_aligntest (count, 2, true);
17182           src = change_address (srcmem, HImode, srcptr);
17183           dest = change_address (destmem, HImode, destptr);
17184           emit_insn (gen_strmov (destptr, dest, srcptr, src));
17185           emit_label (label);
17186           LABEL_NUSES (label) = 1;
17187         }
17188       if (max_size > 1)
17189         {
17190           rtx label = ix86_expand_aligntest (count, 1, true);
17191           src = change_address (srcmem, QImode, srcptr);
17192           dest = change_address (destmem, QImode, destptr);
17193           emit_insn (gen_strmov (destptr, dest, srcptr, src));
17194           emit_label (label);
17195           LABEL_NUSES (label) = 1;
17196         }
17197     }
17198   else
17199     {
17200       rtx offset = force_reg (Pmode, const0_rtx);
17201       rtx tmp;
17202
17203       if (max_size > 4)
17204         {
17205           rtx label = ix86_expand_aligntest (count, 4, true);
17206           src = change_address (srcmem, SImode, srcptr);
17207           dest = change_address (destmem, SImode, destptr);
17208           emit_move_insn (dest, src);
17209           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (4), NULL,
17210                                      true, OPTAB_LIB_WIDEN);
17211           if (tmp != offset)
17212             emit_move_insn (offset, tmp);
17213           emit_label (label);
17214           LABEL_NUSES (label) = 1;
17215         }
17216       if (max_size > 2)
17217         {
17218           rtx label = ix86_expand_aligntest (count, 2, true);
17219           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
17220           src = change_address (srcmem, HImode, tmp);
17221           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
17222           dest = change_address (destmem, HImode, tmp);
17223           emit_move_insn (dest, src);
17224           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (2), tmp,
17225                                      true, OPTAB_LIB_WIDEN);
17226           if (tmp != offset)
17227             emit_move_insn (offset, tmp);
17228           emit_label (label);
17229           LABEL_NUSES (label) = 1;
17230         }
17231       if (max_size > 1)
17232         {
17233           rtx label = ix86_expand_aligntest (count, 1, true);
17234           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
17235           src = change_address (srcmem, QImode, tmp);
17236           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
17237           dest = change_address (destmem, QImode, tmp);
17238           emit_move_insn (dest, src);
17239           emit_label (label);
17240           LABEL_NUSES (label) = 1;
17241         }
17242     }
17243 }
17244
17245 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
17246 static void
17247 expand_setmem_epilogue_via_loop (rtx destmem, rtx destptr, rtx value,
17248                                  rtx count, int max_size)
17249 {
17250   count =
17251     expand_simple_binop (counter_mode (count), AND, count,
17252                          GEN_INT (max_size - 1), count, 1, OPTAB_DIRECT);
17253   expand_set_or_movmem_via_loop (destmem, NULL, destptr, NULL,
17254                                  gen_lowpart (QImode, value), count, QImode,
17255                                  1, max_size / 2);
17256 }
17257
17258 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
17259 static void
17260 expand_setmem_epilogue (rtx destmem, rtx destptr, rtx value, rtx count, int max_size)
17261 {
17262   rtx dest;
17263
17264   if (CONST_INT_P (count))
17265     {
17266       HOST_WIDE_INT countval = INTVAL (count);
17267       int offset = 0;
17268
17269       if ((countval & 0x10) && max_size > 16)
17270         {
17271           if (TARGET_64BIT)
17272             {
17273               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset);
17274               emit_insn (gen_strset (destptr, dest, value));
17275               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset + 8);
17276               emit_insn (gen_strset (destptr, dest, value));
17277             }
17278           else
17279             gcc_unreachable ();
17280           offset += 16;
17281         }
17282       if ((countval & 0x08) && max_size > 8)
17283         {
17284           if (TARGET_64BIT)
17285             {
17286               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset);
17287               emit_insn (gen_strset (destptr, dest, value));
17288             }
17289           else
17290             {
17291               dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset);
17292               emit_insn (gen_strset (destptr, dest, value));
17293               dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset + 4);
17294               emit_insn (gen_strset (destptr, dest, value));
17295             }
17296           offset += 8;
17297         }
17298       if ((countval & 0x04) && max_size > 4)
17299         {
17300           dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset);
17301           emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
17302           offset += 4;
17303         }
17304       if ((countval & 0x02) && max_size > 2)
17305         {
17306           dest = adjust_automodify_address_nv (destmem, HImode, destptr, offset);
17307           emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
17308           offset += 2;
17309         }
17310       if ((countval & 0x01) && max_size > 1)
17311         {
17312           dest = adjust_automodify_address_nv (destmem, QImode, destptr, offset);
17313           emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
17314           offset += 1;
17315         }
17316       return;
17317     }
17318   if (max_size > 32)
17319     {
17320       expand_setmem_epilogue_via_loop (destmem, destptr, value, count, max_size);
17321       return;
17322     }
17323   if (max_size > 16)
17324     {
17325       rtx label = ix86_expand_aligntest (count, 16, true);
17326       if (TARGET_64BIT)
17327         {
17328           dest = change_address (destmem, DImode, destptr);
17329           emit_insn (gen_strset (destptr, dest, value));
17330           emit_insn (gen_strset (destptr, dest, value));
17331         }
17332       else
17333         {
17334           dest = change_address (destmem, SImode, destptr);
17335           emit_insn (gen_strset (destptr, dest, value));
17336           emit_insn (gen_strset (destptr, dest, value));
17337           emit_insn (gen_strset (destptr, dest, value));
17338           emit_insn (gen_strset (destptr, dest, value));
17339         }
17340       emit_label (label);
17341       LABEL_NUSES (label) = 1;
17342     }
17343   if (max_size > 8)
17344     {
17345       rtx label = ix86_expand_aligntest (count, 8, true);
17346       if (TARGET_64BIT)
17347         {
17348           dest = change_address (destmem, DImode, destptr);
17349           emit_insn (gen_strset (destptr, dest, value));
17350         }
17351       else
17352         {
17353           dest = change_address (destmem, SImode, destptr);
17354           emit_insn (gen_strset (destptr, dest, value));
17355           emit_insn (gen_strset (destptr, dest, value));
17356         }
17357       emit_label (label);
17358       LABEL_NUSES (label) = 1;
17359     }
17360   if (max_size > 4)
17361     {
17362       rtx label = ix86_expand_aligntest (count, 4, true);
17363       dest = change_address (destmem, SImode, destptr);
17364       emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
17365       emit_label (label);
17366       LABEL_NUSES (label) = 1;
17367     }
17368   if (max_size > 2)
17369     {
17370       rtx label = ix86_expand_aligntest (count, 2, true);
17371       dest = change_address (destmem, HImode, destptr);
17372       emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
17373       emit_label (label);
17374       LABEL_NUSES (label) = 1;
17375     }
17376   if (max_size > 1)
17377     {
17378       rtx label = ix86_expand_aligntest (count, 1, true);
17379       dest = change_address (destmem, QImode, destptr);
17380       emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
17381       emit_label (label);
17382       LABEL_NUSES (label) = 1;
17383     }
17384 }
17385
17386 /* Copy enough from DEST to SRC to align DEST known to by aligned by ALIGN to
17387    DESIRED_ALIGNMENT.  */
17388 static void
17389 expand_movmem_prologue (rtx destmem, rtx srcmem,
17390                         rtx destptr, rtx srcptr, rtx count,
17391                         int align, int desired_alignment)
17392 {
17393   if (align <= 1 && desired_alignment > 1)
17394     {
17395       rtx label = ix86_expand_aligntest (destptr, 1, false);
17396       srcmem = change_address (srcmem, QImode, srcptr);
17397       destmem = change_address (destmem, QImode, destptr);
17398       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
17399       ix86_adjust_counter (count, 1);
17400       emit_label (label);
17401       LABEL_NUSES (label) = 1;
17402     }
17403   if (align <= 2 && desired_alignment > 2)
17404     {
17405       rtx label = ix86_expand_aligntest (destptr, 2, false);
17406       srcmem = change_address (srcmem, HImode, srcptr);
17407       destmem = change_address (destmem, HImode, destptr);
17408       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
17409       ix86_adjust_counter (count, 2);
17410       emit_label (label);
17411       LABEL_NUSES (label) = 1;
17412     }
17413   if (align <= 4 && desired_alignment > 4)
17414     {
17415       rtx label = ix86_expand_aligntest (destptr, 4, false);
17416       srcmem = change_address (srcmem, SImode, srcptr);
17417       destmem = change_address (destmem, SImode, destptr);
17418       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
17419       ix86_adjust_counter (count, 4);
17420       emit_label (label);
17421       LABEL_NUSES (label) = 1;
17422     }
17423   gcc_assert (desired_alignment <= 8);
17424 }
17425
17426 /* Copy enough from DST to SRC to align DST known to DESIRED_ALIGN.
17427    ALIGN_BYTES is how many bytes need to be copied.  */
17428 static rtx
17429 expand_constant_movmem_prologue (rtx dst, rtx *srcp, rtx destreg, rtx srcreg,
17430                                  int desired_align, int align_bytes)
17431 {
17432   rtx src = *srcp;
17433   rtx src_size, dst_size;
17434   int off = 0;
17435   int src_align_bytes = get_mem_align_offset (src, desired_align * BITS_PER_UNIT);
17436   if (src_align_bytes >= 0)
17437     src_align_bytes = desired_align - src_align_bytes;
17438   src_size = MEM_SIZE (src);
17439   dst_size = MEM_SIZE (dst);
17440   if (align_bytes & 1)
17441     {
17442       dst = adjust_automodify_address_nv (dst, QImode, destreg, 0);
17443       src = adjust_automodify_address_nv (src, QImode, srcreg, 0);
17444       off = 1;
17445       emit_insn (gen_strmov (destreg, dst, srcreg, src));
17446     }
17447   if (align_bytes & 2)
17448     {
17449       dst = adjust_automodify_address_nv (dst, HImode, destreg, off);
17450       src = adjust_automodify_address_nv (src, HImode, srcreg, off);
17451       if (MEM_ALIGN (dst) < 2 * BITS_PER_UNIT)
17452         set_mem_align (dst, 2 * BITS_PER_UNIT);
17453       if (src_align_bytes >= 0
17454           && (src_align_bytes & 1) == (align_bytes & 1)
17455           && MEM_ALIGN (src) < 2 * BITS_PER_UNIT)
17456         set_mem_align (src, 2 * BITS_PER_UNIT);
17457       off = 2;
17458       emit_insn (gen_strmov (destreg, dst, srcreg, src));
17459     }
17460   if (align_bytes & 4)
17461     {
17462       dst = adjust_automodify_address_nv (dst, SImode, destreg, off);
17463       src = adjust_automodify_address_nv (src, SImode, srcreg, off);
17464       if (MEM_ALIGN (dst) < 4 * BITS_PER_UNIT)
17465         set_mem_align (dst, 4 * BITS_PER_UNIT);
17466       if (src_align_bytes >= 0)
17467         {
17468           unsigned int src_align = 0;
17469           if ((src_align_bytes & 3) == (align_bytes & 3))
17470             src_align = 4;
17471           else if ((src_align_bytes & 1) == (align_bytes & 1))
17472             src_align = 2;
17473           if (MEM_ALIGN (src) < src_align * BITS_PER_UNIT)
17474             set_mem_align (src, src_align * BITS_PER_UNIT);
17475         }
17476       off = 4;
17477       emit_insn (gen_strmov (destreg, dst, srcreg, src));
17478     }
17479   dst = adjust_automodify_address_nv (dst, BLKmode, destreg, off);
17480   src = adjust_automodify_address_nv (src, BLKmode, srcreg, off);
17481   if (MEM_ALIGN (dst) < (unsigned int) desired_align * BITS_PER_UNIT)
17482     set_mem_align (dst, desired_align * BITS_PER_UNIT);
17483   if (src_align_bytes >= 0)
17484     {
17485       unsigned int src_align = 0;
17486       if ((src_align_bytes & 7) == (align_bytes & 7))
17487         src_align = 8;
17488       else if ((src_align_bytes & 3) == (align_bytes & 3))
17489         src_align = 4;
17490       else if ((src_align_bytes & 1) == (align_bytes & 1))
17491         src_align = 2;
17492       if (src_align > (unsigned int) desired_align)
17493         src_align = desired_align;
17494       if (MEM_ALIGN (src) < src_align * BITS_PER_UNIT)
17495         set_mem_align (src, src_align * BITS_PER_UNIT);
17496     }
17497   if (dst_size)
17498     set_mem_size (dst, GEN_INT (INTVAL (dst_size) - align_bytes));
17499   if (src_size)
17500     set_mem_size (dst, GEN_INT (INTVAL (src_size) - align_bytes));
17501   *srcp = src;
17502   return dst;
17503 }
17504
17505 /* Set enough from DEST to align DEST known to by aligned by ALIGN to
17506    DESIRED_ALIGNMENT.  */
17507 static void
17508 expand_setmem_prologue (rtx destmem, rtx destptr, rtx value, rtx count,
17509                         int align, int desired_alignment)
17510 {
17511   if (align <= 1 && desired_alignment > 1)
17512     {
17513       rtx label = ix86_expand_aligntest (destptr, 1, false);
17514       destmem = change_address (destmem, QImode, destptr);
17515       emit_insn (gen_strset (destptr, destmem, gen_lowpart (QImode, value)));
17516       ix86_adjust_counter (count, 1);
17517       emit_label (label);
17518       LABEL_NUSES (label) = 1;
17519     }
17520   if (align <= 2 && desired_alignment > 2)
17521     {
17522       rtx label = ix86_expand_aligntest (destptr, 2, false);
17523       destmem = change_address (destmem, HImode, destptr);
17524       emit_insn (gen_strset (destptr, destmem, gen_lowpart (HImode, value)));
17525       ix86_adjust_counter (count, 2);
17526       emit_label (label);
17527       LABEL_NUSES (label) = 1;
17528     }
17529   if (align <= 4 && desired_alignment > 4)
17530     {
17531       rtx label = ix86_expand_aligntest (destptr, 4, false);
17532       destmem = change_address (destmem, SImode, destptr);
17533       emit_insn (gen_strset (destptr, destmem, gen_lowpart (SImode, value)));
17534       ix86_adjust_counter (count, 4);
17535       emit_label (label);
17536       LABEL_NUSES (label) = 1;
17537     }
17538   gcc_assert (desired_alignment <= 8);
17539 }
17540
17541 /* Set enough from DST to align DST known to by aligned by ALIGN to
17542    DESIRED_ALIGN.  ALIGN_BYTES is how many bytes need to be stored.  */
17543 static rtx
17544 expand_constant_setmem_prologue (rtx dst, rtx destreg, rtx value,
17545                                  int desired_align, int align_bytes)
17546 {
17547   int off = 0;
17548   rtx dst_size = MEM_SIZE (dst);
17549   if (align_bytes & 1)
17550     {
17551       dst = adjust_automodify_address_nv (dst, QImode, destreg, 0);
17552       off = 1;
17553       emit_insn (gen_strset (destreg, dst,
17554                              gen_lowpart (QImode, value)));
17555     }
17556   if (align_bytes & 2)
17557     {
17558       dst = adjust_automodify_address_nv (dst, HImode, destreg, off);
17559       if (MEM_ALIGN (dst) < 2 * BITS_PER_UNIT)
17560         set_mem_align (dst, 2 * BITS_PER_UNIT);
17561       off = 2;
17562       emit_insn (gen_strset (destreg, dst,
17563                              gen_lowpart (HImode, value)));
17564     }
17565   if (align_bytes & 4)
17566     {
17567       dst = adjust_automodify_address_nv (dst, SImode, destreg, off);
17568       if (MEM_ALIGN (dst) < 4 * BITS_PER_UNIT)
17569         set_mem_align (dst, 4 * BITS_PER_UNIT);
17570       off = 4;
17571       emit_insn (gen_strset (destreg, dst,
17572                              gen_lowpart (SImode, value)));
17573     }
17574   dst = adjust_automodify_address_nv (dst, BLKmode, destreg, off);
17575   if (MEM_ALIGN (dst) < (unsigned int) desired_align * BITS_PER_UNIT)
17576     set_mem_align (dst, desired_align * BITS_PER_UNIT);
17577   if (dst_size)
17578     set_mem_size (dst, GEN_INT (INTVAL (dst_size) - align_bytes));
17579   return dst;
17580 }
17581
17582 /* Given COUNT and EXPECTED_SIZE, decide on codegen of string operation.  */
17583 static enum stringop_alg
17584 decide_alg (HOST_WIDE_INT count, HOST_WIDE_INT expected_size, bool memset,
17585             int *dynamic_check)
17586 {
17587   const struct stringop_algs * algs;
17588   bool optimize_for_speed;
17589   /* Algorithms using the rep prefix want at least edi and ecx;
17590      additionally, memset wants eax and memcpy wants esi.  Don't
17591      consider such algorithms if the user has appropriated those
17592      registers for their own purposes.  */
17593   bool rep_prefix_usable = !(fixed_regs[CX_REG] || fixed_regs[DI_REG]
17594                              || (memset
17595                                  ? fixed_regs[AX_REG] : fixed_regs[SI_REG]));
17596
17597 #define ALG_USABLE_P(alg) (rep_prefix_usable                    \
17598                            || (alg != rep_prefix_1_byte         \
17599                                && alg != rep_prefix_4_byte      \
17600                                && alg != rep_prefix_8_byte))
17601   const struct processor_costs *cost;
17602   
17603   /* Even if the string operation call is cold, we still might spend a lot
17604      of time processing large blocks.  */
17605   if (optimize_function_for_size_p (cfun)
17606       || (optimize_insn_for_size_p ()
17607           && expected_size != -1 && expected_size < 256))
17608     optimize_for_speed = false;
17609   else
17610     optimize_for_speed = true;
17611
17612   cost = optimize_for_speed ? ix86_cost : &ix86_size_cost;
17613
17614   *dynamic_check = -1;
17615   if (memset)
17616     algs = &cost->memset[TARGET_64BIT != 0];
17617   else
17618     algs = &cost->memcpy[TARGET_64BIT != 0];
17619   if (stringop_alg != no_stringop && ALG_USABLE_P (stringop_alg))
17620     return stringop_alg;
17621   /* rep; movq or rep; movl is the smallest variant.  */
17622   else if (!optimize_for_speed)
17623     {
17624       if (!count || (count & 3))
17625         return rep_prefix_usable ? rep_prefix_1_byte : loop_1_byte;
17626       else
17627         return rep_prefix_usable ? rep_prefix_4_byte : loop;
17628     }
17629   /* Very tiny blocks are best handled via the loop, REP is expensive to setup.
17630    */
17631   else if (expected_size != -1 && expected_size < 4)
17632     return loop_1_byte;
17633   else if (expected_size != -1)
17634     {
17635       unsigned int i;
17636       enum stringop_alg alg = libcall;
17637       for (i = 0; i < NAX_STRINGOP_ALGS; i++)
17638         {
17639           /* We get here if the algorithms that were not libcall-based
17640              were rep-prefix based and we are unable to use rep prefixes
17641              based on global register usage.  Break out of the loop and
17642              use the heuristic below.  */
17643           if (algs->size[i].max == 0)
17644             break;
17645           if (algs->size[i].max >= expected_size || algs->size[i].max == -1)
17646             {
17647               enum stringop_alg candidate = algs->size[i].alg;
17648
17649               if (candidate != libcall && ALG_USABLE_P (candidate))
17650                 alg = candidate;
17651               /* Honor TARGET_INLINE_ALL_STRINGOPS by picking
17652                  last non-libcall inline algorithm.  */
17653               if (TARGET_INLINE_ALL_STRINGOPS)
17654                 {
17655                   /* When the current size is best to be copied by a libcall,
17656                      but we are still forced to inline, run the heuristic below
17657                      that will pick code for medium sized blocks.  */
17658                   if (alg != libcall)
17659                     return alg;
17660                   break;
17661                 }
17662               else if (ALG_USABLE_P (candidate))
17663                 return candidate;
17664             }
17665         }
17666       gcc_assert (TARGET_INLINE_ALL_STRINGOPS || !rep_prefix_usable);
17667     }
17668   /* When asked to inline the call anyway, try to pick meaningful choice.
17669      We look for maximal size of block that is faster to copy by hand and
17670      take blocks of at most of that size guessing that average size will
17671      be roughly half of the block.
17672
17673      If this turns out to be bad, we might simply specify the preferred
17674      choice in ix86_costs.  */
17675   if ((TARGET_INLINE_ALL_STRINGOPS || TARGET_INLINE_STRINGOPS_DYNAMICALLY)
17676       && (algs->unknown_size == libcall || !ALG_USABLE_P (algs->unknown_size)))
17677     {
17678       int max = -1;
17679       enum stringop_alg alg;
17680       int i;
17681       bool any_alg_usable_p = true;
17682
17683       for (i = 0; i < NAX_STRINGOP_ALGS; i++)
17684         {
17685           enum stringop_alg candidate = algs->size[i].alg;
17686           any_alg_usable_p = any_alg_usable_p && ALG_USABLE_P (candidate);
17687
17688           if (candidate != libcall && candidate
17689               && ALG_USABLE_P (candidate))
17690               max = algs->size[i].max;
17691         }
17692       /* If there aren't any usable algorithms, then recursing on
17693          smaller sizes isn't going to find anything.  Just return the
17694          simple byte-at-a-time copy loop.  */
17695       if (!any_alg_usable_p)
17696         {
17697           /* Pick something reasonable.  */
17698           if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
17699             *dynamic_check = 128;
17700           return loop_1_byte;
17701         }
17702       if (max == -1)
17703         max = 4096;
17704       alg = decide_alg (count, max / 2, memset, dynamic_check);
17705       gcc_assert (*dynamic_check == -1);
17706       gcc_assert (alg != libcall);
17707       if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
17708         *dynamic_check = max;
17709       return alg;
17710     }
17711   return ALG_USABLE_P (algs->unknown_size) ? algs->unknown_size : libcall;
17712 #undef ALG_USABLE_P
17713 }
17714
17715 /* Decide on alignment.  We know that the operand is already aligned to ALIGN
17716    (ALIGN can be based on profile feedback and thus it is not 100% guaranteed).  */
17717 static int
17718 decide_alignment (int align,
17719                   enum stringop_alg alg,
17720                   int expected_size)
17721 {
17722   int desired_align = 0;
17723   switch (alg)
17724     {
17725       case no_stringop:
17726         gcc_unreachable ();
17727       case loop:
17728       case unrolled_loop:
17729         desired_align = GET_MODE_SIZE (Pmode);
17730         break;
17731       case rep_prefix_8_byte:
17732         desired_align = 8;
17733         break;
17734       case rep_prefix_4_byte:
17735         /* PentiumPro has special logic triggering for 8 byte aligned blocks.
17736            copying whole cacheline at once.  */
17737         if (TARGET_PENTIUMPRO)
17738           desired_align = 8;
17739         else
17740           desired_align = 4;
17741         break;
17742       case rep_prefix_1_byte:
17743         /* PentiumPro has special logic triggering for 8 byte aligned blocks.
17744            copying whole cacheline at once.  */
17745         if (TARGET_PENTIUMPRO)
17746           desired_align = 8;
17747         else
17748           desired_align = 1;
17749         break;
17750       case loop_1_byte:
17751         desired_align = 1;
17752         break;
17753       case libcall:
17754         return 0;
17755     }
17756
17757   if (optimize_size)
17758     desired_align = 1;
17759   if (desired_align < align)
17760     desired_align = align;
17761   if (expected_size != -1 && expected_size < 4)
17762     desired_align = align;
17763   return desired_align;
17764 }
17765
17766 /* Return the smallest power of 2 greater than VAL.  */
17767 static int
17768 smallest_pow2_greater_than (int val)
17769 {
17770   int ret = 1;
17771   while (ret <= val)
17772     ret <<= 1;
17773   return ret;
17774 }
17775
17776 /* Expand string move (memcpy) operation.  Use i386 string operations when
17777    profitable.  expand_setmem contains similar code.  The code depends upon
17778    architecture, block size and alignment, but always has the same
17779    overall structure:
17780
17781    1) Prologue guard: Conditional that jumps up to epilogues for small
17782       blocks that can be handled by epilogue alone.  This is faster but
17783       also needed for correctness, since prologue assume the block is larger
17784       than the desired alignment.
17785
17786       Optional dynamic check for size and libcall for large
17787       blocks is emitted here too, with -minline-stringops-dynamically.
17788
17789    2) Prologue: copy first few bytes in order to get destination aligned
17790       to DESIRED_ALIGN.  It is emitted only when ALIGN is less than
17791       DESIRED_ALIGN and and up to DESIRED_ALIGN - ALIGN bytes can be copied.
17792       We emit either a jump tree on power of two sized blocks, or a byte loop.
17793
17794    3) Main body: the copying loop itself, copying in SIZE_NEEDED chunks
17795       with specified algorithm.
17796
17797    4) Epilogue: code copying tail of the block that is too small to be
17798       handled by main body (or up to size guarded by prologue guard).  */
17799
17800 int
17801 ix86_expand_movmem (rtx dst, rtx src, rtx count_exp, rtx align_exp,
17802                     rtx expected_align_exp, rtx expected_size_exp)
17803 {
17804   rtx destreg;
17805   rtx srcreg;
17806   rtx label = NULL;
17807   rtx tmp;
17808   rtx jump_around_label = NULL;
17809   HOST_WIDE_INT align = 1;
17810   unsigned HOST_WIDE_INT count = 0;
17811   HOST_WIDE_INT expected_size = -1;
17812   int size_needed = 0, epilogue_size_needed;
17813   int desired_align = 0, align_bytes = 0;
17814   enum stringop_alg alg;
17815   int dynamic_check;
17816   bool need_zero_guard = false;
17817
17818   if (CONST_INT_P (align_exp))
17819     align = INTVAL (align_exp);
17820   /* i386 can do misaligned access on reasonably increased cost.  */
17821   if (CONST_INT_P (expected_align_exp)
17822       && INTVAL (expected_align_exp) > align)
17823     align = INTVAL (expected_align_exp);
17824   /* ALIGN is the minimum of destination and source alignment, but we care here
17825      just about destination alignment.  */
17826   else if (MEM_ALIGN (dst) > (unsigned HOST_WIDE_INT) align * BITS_PER_UNIT)
17827     align = MEM_ALIGN (dst) / BITS_PER_UNIT;
17828
17829   if (CONST_INT_P (count_exp))
17830     count = expected_size = INTVAL (count_exp);
17831   if (CONST_INT_P (expected_size_exp) && count == 0)
17832     expected_size = INTVAL (expected_size_exp);
17833
17834   /* Make sure we don't need to care about overflow later on.  */
17835   if (count > ((unsigned HOST_WIDE_INT) 1 << 30))
17836     return 0;
17837
17838   /* Step 0: Decide on preferred algorithm, desired alignment and
17839      size of chunks to be copied by main loop.  */
17840
17841   alg = decide_alg (count, expected_size, false, &dynamic_check);
17842   desired_align = decide_alignment (align, alg, expected_size);
17843
17844   if (!TARGET_ALIGN_STRINGOPS)
17845     align = desired_align;
17846
17847   if (alg == libcall)
17848     return 0;
17849   gcc_assert (alg != no_stringop);
17850   if (!count)
17851     count_exp = copy_to_mode_reg (GET_MODE (count_exp), count_exp);
17852   destreg = copy_to_mode_reg (Pmode, XEXP (dst, 0));
17853   srcreg = copy_to_mode_reg (Pmode, XEXP (src, 0));
17854   switch (alg)
17855     {
17856     case libcall:
17857     case no_stringop:
17858       gcc_unreachable ();
17859     case loop:
17860       need_zero_guard = true;
17861       size_needed = GET_MODE_SIZE (Pmode);
17862       break;
17863     case unrolled_loop:
17864       need_zero_guard = true;
17865       size_needed = GET_MODE_SIZE (Pmode) * (TARGET_64BIT ? 4 : 2);
17866       break;
17867     case rep_prefix_8_byte:
17868       size_needed = 8;
17869       break;
17870     case rep_prefix_4_byte:
17871       size_needed = 4;
17872       break;
17873     case rep_prefix_1_byte:
17874       size_needed = 1;
17875       break;
17876     case loop_1_byte:
17877       need_zero_guard = true;
17878       size_needed = 1;
17879       break;
17880     }
17881
17882   epilogue_size_needed = size_needed;
17883
17884   /* Step 1: Prologue guard.  */
17885
17886   /* Alignment code needs count to be in register.  */
17887   if (CONST_INT_P (count_exp) && desired_align > align)
17888     {
17889       if (INTVAL (count_exp) > desired_align
17890           && INTVAL (count_exp) > size_needed)
17891         {
17892           align_bytes
17893             = get_mem_align_offset (dst, desired_align * BITS_PER_UNIT);
17894           if (align_bytes <= 0)
17895             align_bytes = 0;
17896           else
17897             align_bytes = desired_align - align_bytes;
17898         }
17899       if (align_bytes == 0)
17900         count_exp = force_reg (counter_mode (count_exp), count_exp);
17901     }
17902   gcc_assert (desired_align >= 1 && align >= 1);
17903
17904   /* Ensure that alignment prologue won't copy past end of block.  */
17905   if (size_needed > 1 || (desired_align > 1 && desired_align > align))
17906     {
17907       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
17908       /* Epilogue always copies COUNT_EXP & EPILOGUE_SIZE_NEEDED bytes.
17909          Make sure it is power of 2.  */
17910       epilogue_size_needed = smallest_pow2_greater_than (epilogue_size_needed);
17911
17912       if (count)
17913         {
17914           if (count < (unsigned HOST_WIDE_INT)epilogue_size_needed)
17915             {
17916               /* If main algorithm works on QImode, no epilogue is needed.
17917                  For small sizes just don't align anything.  */
17918               if (size_needed == 1)
17919                 desired_align = align;
17920               else
17921                 goto epilogue;
17922             }
17923         }
17924       else
17925         {
17926           label = gen_label_rtx ();
17927           emit_cmp_and_jump_insns (count_exp,
17928                                    GEN_INT (epilogue_size_needed),
17929                                    LTU, 0, counter_mode (count_exp), 1, label);
17930           if (expected_size == -1 || expected_size < epilogue_size_needed)
17931             predict_jump (REG_BR_PROB_BASE * 60 / 100);
17932           else
17933             predict_jump (REG_BR_PROB_BASE * 20 / 100);
17934         }
17935     }
17936
17937   /* Emit code to decide on runtime whether library call or inline should be
17938      used.  */
17939   if (dynamic_check != -1)
17940     {
17941       if (CONST_INT_P (count_exp))
17942         {
17943           if (UINTVAL (count_exp) >= (unsigned HOST_WIDE_INT)dynamic_check)
17944             {
17945               emit_block_move_via_libcall (dst, src, count_exp, false);
17946               count_exp = const0_rtx;
17947               goto epilogue;
17948             }
17949         }
17950       else
17951         {
17952           rtx hot_label = gen_label_rtx ();
17953           jump_around_label = gen_label_rtx ();
17954           emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
17955                                    LEU, 0, GET_MODE (count_exp), 1, hot_label);
17956           predict_jump (REG_BR_PROB_BASE * 90 / 100);
17957           emit_block_move_via_libcall (dst, src, count_exp, false);
17958           emit_jump (jump_around_label);
17959           emit_label (hot_label);
17960         }
17961     }
17962
17963   /* Step 2: Alignment prologue.  */
17964
17965   if (desired_align > align)
17966     {
17967       if (align_bytes == 0)
17968         {
17969           /* Except for the first move in epilogue, we no longer know
17970              constant offset in aliasing info.  It don't seems to worth
17971              the pain to maintain it for the first move, so throw away
17972              the info early.  */
17973           src = change_address (src, BLKmode, srcreg);
17974           dst = change_address (dst, BLKmode, destreg);
17975           expand_movmem_prologue (dst, src, destreg, srcreg, count_exp, align,
17976                                   desired_align);
17977         }
17978       else
17979         {
17980           /* If we know how many bytes need to be stored before dst is
17981              sufficiently aligned, maintain aliasing info accurately.  */
17982           dst = expand_constant_movmem_prologue (dst, &src, destreg, srcreg,
17983                                                  desired_align, align_bytes);
17984           count_exp = plus_constant (count_exp, -align_bytes);
17985           count -= align_bytes;
17986         }
17987       if (need_zero_guard
17988           && (count < (unsigned HOST_WIDE_INT) size_needed
17989               || (align_bytes == 0
17990                   && count < ((unsigned HOST_WIDE_INT) size_needed
17991                               + desired_align - align))))
17992         {
17993           /* It is possible that we copied enough so the main loop will not
17994              execute.  */
17995           gcc_assert (size_needed > 1);
17996           if (label == NULL_RTX)
17997             label = gen_label_rtx ();
17998           emit_cmp_and_jump_insns (count_exp,
17999                                    GEN_INT (size_needed),
18000                                    LTU, 0, counter_mode (count_exp), 1, label);
18001           if (expected_size == -1
18002               || expected_size < (desired_align - align) / 2 + size_needed)
18003             predict_jump (REG_BR_PROB_BASE * 20 / 100);
18004           else
18005             predict_jump (REG_BR_PROB_BASE * 60 / 100);
18006         }
18007     }
18008   if (label && size_needed == 1)
18009     {
18010       emit_label (label);
18011       LABEL_NUSES (label) = 1;
18012       label = NULL;
18013       epilogue_size_needed = 1;
18014     }
18015   else if (label == NULL_RTX)
18016     epilogue_size_needed = size_needed;
18017
18018   /* Step 3: Main loop.  */
18019
18020   switch (alg)
18021     {
18022     case libcall:
18023     case no_stringop:
18024       gcc_unreachable ();
18025     case loop_1_byte:
18026       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
18027                                      count_exp, QImode, 1, expected_size);
18028       break;
18029     case loop:
18030       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
18031                                      count_exp, Pmode, 1, expected_size);
18032       break;
18033     case unrolled_loop:
18034       /* Unroll only by factor of 2 in 32bit mode, since we don't have enough
18035          registers for 4 temporaries anyway.  */
18036       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
18037                                      count_exp, Pmode, TARGET_64BIT ? 4 : 2,
18038                                      expected_size);
18039       break;
18040     case rep_prefix_8_byte:
18041       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
18042                                  DImode);
18043       break;
18044     case rep_prefix_4_byte:
18045       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
18046                                  SImode);
18047       break;
18048     case rep_prefix_1_byte:
18049       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
18050                                  QImode);
18051       break;
18052     }
18053   /* Adjust properly the offset of src and dest memory for aliasing.  */
18054   if (CONST_INT_P (count_exp))
18055     {
18056       src = adjust_automodify_address_nv (src, BLKmode, srcreg,
18057                                           (count / size_needed) * size_needed);
18058       dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
18059                                           (count / size_needed) * size_needed);
18060     }
18061   else
18062     {
18063       src = change_address (src, BLKmode, srcreg);
18064       dst = change_address (dst, BLKmode, destreg);
18065     }
18066
18067   /* Step 4: Epilogue to copy the remaining bytes.  */
18068  epilogue:
18069   if (label)
18070     {
18071       /* When the main loop is done, COUNT_EXP might hold original count,
18072          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
18073          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
18074          bytes. Compensate if needed.  */
18075
18076       if (size_needed < epilogue_size_needed)
18077         {
18078           tmp =
18079             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
18080                                  GEN_INT (size_needed - 1), count_exp, 1,
18081                                  OPTAB_DIRECT);
18082           if (tmp != count_exp)
18083             emit_move_insn (count_exp, tmp);
18084         }
18085       emit_label (label);
18086       LABEL_NUSES (label) = 1;
18087     }
18088
18089   if (count_exp != const0_rtx && epilogue_size_needed > 1)
18090     expand_movmem_epilogue (dst, src, destreg, srcreg, count_exp,
18091                             epilogue_size_needed);
18092   if (jump_around_label)
18093     emit_label (jump_around_label);
18094   return 1;
18095 }
18096
18097 /* Helper function for memcpy.  For QImode value 0xXY produce
18098    0xXYXYXYXY of wide specified by MODE.  This is essentially
18099    a * 0x10101010, but we can do slightly better than
18100    synth_mult by unwinding the sequence by hand on CPUs with
18101    slow multiply.  */
18102 static rtx
18103 promote_duplicated_reg (enum machine_mode mode, rtx val)
18104 {
18105   enum machine_mode valmode = GET_MODE (val);
18106   rtx tmp;
18107   int nops = mode == DImode ? 3 : 2;
18108
18109   gcc_assert (mode == SImode || mode == DImode);
18110   if (val == const0_rtx)
18111     return copy_to_mode_reg (mode, const0_rtx);
18112   if (CONST_INT_P (val))
18113     {
18114       HOST_WIDE_INT v = INTVAL (val) & 255;
18115
18116       v |= v << 8;
18117       v |= v << 16;
18118       if (mode == DImode)
18119         v |= (v << 16) << 16;
18120       return copy_to_mode_reg (mode, gen_int_mode (v, mode));
18121     }
18122
18123   if (valmode == VOIDmode)
18124     valmode = QImode;
18125   if (valmode != QImode)
18126     val = gen_lowpart (QImode, val);
18127   if (mode == QImode)
18128     return val;
18129   if (!TARGET_PARTIAL_REG_STALL)
18130     nops--;
18131   if (ix86_cost->mult_init[mode == DImode ? 3 : 2]
18132       + ix86_cost->mult_bit * (mode == DImode ? 8 : 4)
18133       <= (ix86_cost->shift_const + ix86_cost->add) * nops
18134           + (COSTS_N_INSNS (TARGET_PARTIAL_REG_STALL == 0)))
18135     {
18136       rtx reg = convert_modes (mode, QImode, val, true);
18137       tmp = promote_duplicated_reg (mode, const1_rtx);
18138       return expand_simple_binop (mode, MULT, reg, tmp, NULL, 1,
18139                                   OPTAB_DIRECT);
18140     }
18141   else
18142     {
18143       rtx reg = convert_modes (mode, QImode, val, true);
18144
18145       if (!TARGET_PARTIAL_REG_STALL)
18146         if (mode == SImode)
18147           emit_insn (gen_movsi_insv_1 (reg, reg));
18148         else
18149           emit_insn (gen_movdi_insv_1_rex64 (reg, reg));
18150       else
18151         {
18152           tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (8),
18153                                      NULL, 1, OPTAB_DIRECT);
18154           reg =
18155             expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
18156         }
18157       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (16),
18158                                  NULL, 1, OPTAB_DIRECT);
18159       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
18160       if (mode == SImode)
18161         return reg;
18162       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (32),
18163                                  NULL, 1, OPTAB_DIRECT);
18164       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
18165       return reg;
18166     }
18167 }
18168
18169 /* Duplicate value VAL using promote_duplicated_reg into maximal size that will
18170    be needed by main loop copying SIZE_NEEDED chunks and prologue getting
18171    alignment from ALIGN to DESIRED_ALIGN.  */
18172 static rtx
18173 promote_duplicated_reg_to_size (rtx val, int size_needed, int desired_align, int align)
18174 {
18175   rtx promoted_val;
18176
18177   if (TARGET_64BIT
18178       && (size_needed > 4 || (desired_align > align && desired_align > 4)))
18179     promoted_val = promote_duplicated_reg (DImode, val);
18180   else if (size_needed > 2 || (desired_align > align && desired_align > 2))
18181     promoted_val = promote_duplicated_reg (SImode, val);
18182   else if (size_needed > 1 || (desired_align > align && desired_align > 1))
18183     promoted_val = promote_duplicated_reg (HImode, val);
18184   else
18185     promoted_val = val;
18186
18187   return promoted_val;
18188 }
18189
18190 /* Expand string clear operation (bzero).  Use i386 string operations when
18191    profitable.  See expand_movmem comment for explanation of individual
18192    steps performed.  */
18193 int
18194 ix86_expand_setmem (rtx dst, rtx count_exp, rtx val_exp, rtx align_exp,
18195                     rtx expected_align_exp, rtx expected_size_exp)
18196 {
18197   rtx destreg;
18198   rtx label = NULL;
18199   rtx tmp;
18200   rtx jump_around_label = NULL;
18201   HOST_WIDE_INT align = 1;
18202   unsigned HOST_WIDE_INT count = 0;
18203   HOST_WIDE_INT expected_size = -1;
18204   int size_needed = 0, epilogue_size_needed;
18205   int desired_align = 0, align_bytes = 0;
18206   enum stringop_alg alg;
18207   rtx promoted_val = NULL;
18208   bool force_loopy_epilogue = false;
18209   int dynamic_check;
18210   bool need_zero_guard = false;
18211
18212   if (CONST_INT_P (align_exp))
18213     align = INTVAL (align_exp);
18214   /* i386 can do misaligned access on reasonably increased cost.  */
18215   if (CONST_INT_P (expected_align_exp)
18216       && INTVAL (expected_align_exp) > align)
18217     align = INTVAL (expected_align_exp);
18218   if (CONST_INT_P (count_exp))
18219     count = expected_size = INTVAL (count_exp);
18220   if (CONST_INT_P (expected_size_exp) && count == 0)
18221     expected_size = INTVAL (expected_size_exp);
18222
18223   /* Make sure we don't need to care about overflow later on.  */
18224   if (count > ((unsigned HOST_WIDE_INT) 1 << 30))
18225     return 0;
18226
18227   /* Step 0: Decide on preferred algorithm, desired alignment and
18228      size of chunks to be copied by main loop.  */
18229
18230   alg = decide_alg (count, expected_size, true, &dynamic_check);
18231   desired_align = decide_alignment (align, alg, expected_size);
18232
18233   if (!TARGET_ALIGN_STRINGOPS)
18234     align = desired_align;
18235
18236   if (alg == libcall)
18237     return 0;
18238   gcc_assert (alg != no_stringop);
18239   if (!count)
18240     count_exp = copy_to_mode_reg (counter_mode (count_exp), count_exp);
18241   destreg = copy_to_mode_reg (Pmode, XEXP (dst, 0));
18242   switch (alg)
18243     {
18244     case libcall:
18245     case no_stringop:
18246       gcc_unreachable ();
18247     case loop:
18248       need_zero_guard = true;
18249       size_needed = GET_MODE_SIZE (Pmode);
18250       break;
18251     case unrolled_loop:
18252       need_zero_guard = true;
18253       size_needed = GET_MODE_SIZE (Pmode) * 4;
18254       break;
18255     case rep_prefix_8_byte:
18256       size_needed = 8;
18257       break;
18258     case rep_prefix_4_byte:
18259       size_needed = 4;
18260       break;
18261     case rep_prefix_1_byte:
18262       size_needed = 1;
18263       break;
18264     case loop_1_byte:
18265       need_zero_guard = true;
18266       size_needed = 1;
18267       break;
18268     }
18269   epilogue_size_needed = size_needed;
18270
18271   /* Step 1: Prologue guard.  */
18272
18273   /* Alignment code needs count to be in register.  */
18274   if (CONST_INT_P (count_exp) && desired_align > align)
18275     {
18276       if (INTVAL (count_exp) > desired_align
18277           && INTVAL (count_exp) > size_needed)
18278         {
18279           align_bytes
18280             = get_mem_align_offset (dst, desired_align * BITS_PER_UNIT);
18281           if (align_bytes <= 0)
18282             align_bytes = 0;
18283           else
18284             align_bytes = desired_align - align_bytes;
18285         }
18286       if (align_bytes == 0)
18287         {
18288           enum machine_mode mode = SImode;
18289           if (TARGET_64BIT && (count & ~0xffffffff))
18290             mode = DImode;
18291           count_exp = force_reg (mode, count_exp);
18292         }
18293     }
18294   /* Do the cheap promotion to allow better CSE across the
18295      main loop and epilogue (ie one load of the big constant in the
18296      front of all code.  */
18297   if (CONST_INT_P (val_exp))
18298     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
18299                                                    desired_align, align);
18300   /* Ensure that alignment prologue won't copy past end of block.  */
18301   if (size_needed > 1 || (desired_align > 1 && desired_align > align))
18302     {
18303       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
18304       /* Epilogue always copies COUNT_EXP & (EPILOGUE_SIZE_NEEDED - 1) bytes.
18305          Make sure it is power of 2.  */
18306       epilogue_size_needed = smallest_pow2_greater_than (epilogue_size_needed);
18307
18308       /* To improve performance of small blocks, we jump around the VAL
18309          promoting mode.  This mean that if the promoted VAL is not constant,
18310          we might not use it in the epilogue and have to use byte
18311          loop variant.  */
18312       if (epilogue_size_needed > 2 && !promoted_val)
18313         force_loopy_epilogue = true;
18314       if (count)
18315         {
18316           if (count < (unsigned HOST_WIDE_INT)epilogue_size_needed)
18317             {
18318               /* If main algorithm works on QImode, no epilogue is needed.
18319                  For small sizes just don't align anything.  */
18320               if (size_needed == 1)
18321                 desired_align = align;
18322               else
18323                 goto epilogue;
18324             }
18325         }
18326       else
18327         {
18328           label = gen_label_rtx ();
18329           emit_cmp_and_jump_insns (count_exp,
18330                                    GEN_INT (epilogue_size_needed),
18331                                    LTU, 0, counter_mode (count_exp), 1, label);
18332           if (expected_size == -1 || expected_size <= epilogue_size_needed)
18333             predict_jump (REG_BR_PROB_BASE * 60 / 100);
18334           else
18335             predict_jump (REG_BR_PROB_BASE * 20 / 100);
18336         }
18337     }
18338   if (dynamic_check != -1)
18339     {
18340       rtx hot_label = gen_label_rtx ();
18341       jump_around_label = gen_label_rtx ();
18342       emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
18343                                LEU, 0, counter_mode (count_exp), 1, hot_label);
18344       predict_jump (REG_BR_PROB_BASE * 90 / 100);
18345       set_storage_via_libcall (dst, count_exp, val_exp, false);
18346       emit_jump (jump_around_label);
18347       emit_label (hot_label);
18348     }
18349
18350   /* Step 2: Alignment prologue.  */
18351
18352   /* Do the expensive promotion once we branched off the small blocks.  */
18353   if (!promoted_val)
18354     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
18355                                                    desired_align, align);
18356   gcc_assert (desired_align >= 1 && align >= 1);
18357
18358   if (desired_align > align)
18359     {
18360       if (align_bytes == 0)
18361         {
18362           /* Except for the first move in epilogue, we no longer know
18363              constant offset in aliasing info.  It don't seems to worth
18364              the pain to maintain it for the first move, so throw away
18365              the info early.  */
18366           dst = change_address (dst, BLKmode, destreg);
18367           expand_setmem_prologue (dst, destreg, promoted_val, count_exp, align,
18368                                   desired_align);
18369         }
18370       else
18371         {
18372           /* If we know how many bytes need to be stored before dst is
18373              sufficiently aligned, maintain aliasing info accurately.  */
18374           dst = expand_constant_setmem_prologue (dst, destreg, promoted_val,
18375                                                  desired_align, align_bytes);
18376           count_exp = plus_constant (count_exp, -align_bytes);
18377           count -= align_bytes;
18378         }
18379       if (need_zero_guard
18380           && (count < (unsigned HOST_WIDE_INT) size_needed
18381               || (align_bytes == 0
18382                   && count < ((unsigned HOST_WIDE_INT) size_needed
18383                               + desired_align - align))))
18384         {
18385           /* It is possible that we copied enough so the main loop will not
18386              execute.  */
18387           gcc_assert (size_needed > 1);
18388           if (label == NULL_RTX)
18389             label = gen_label_rtx ();
18390           emit_cmp_and_jump_insns (count_exp,
18391                                    GEN_INT (size_needed),
18392                                    LTU, 0, counter_mode (count_exp), 1, label);
18393           if (expected_size == -1
18394               || expected_size < (desired_align - align) / 2 + size_needed)
18395             predict_jump (REG_BR_PROB_BASE * 20 / 100);
18396           else
18397             predict_jump (REG_BR_PROB_BASE * 60 / 100);
18398         }
18399     }
18400   if (label && size_needed == 1)
18401     {
18402       emit_label (label);
18403       LABEL_NUSES (label) = 1;
18404       label = NULL;
18405       promoted_val = val_exp;
18406       epilogue_size_needed = 1;
18407     }
18408   else if (label == NULL_RTX)
18409     epilogue_size_needed = size_needed;
18410
18411   /* Step 3: Main loop.  */
18412
18413   switch (alg)
18414     {
18415     case libcall:
18416     case no_stringop:
18417       gcc_unreachable ();
18418     case loop_1_byte:
18419       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
18420                                      count_exp, QImode, 1, expected_size);
18421       break;
18422     case loop:
18423       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
18424                                      count_exp, Pmode, 1, expected_size);
18425       break;
18426     case unrolled_loop:
18427       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
18428                                      count_exp, Pmode, 4, expected_size);
18429       break;
18430     case rep_prefix_8_byte:
18431       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
18432                                   DImode, val_exp);
18433       break;
18434     case rep_prefix_4_byte:
18435       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
18436                                   SImode, val_exp);
18437       break;
18438     case rep_prefix_1_byte:
18439       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
18440                                   QImode, val_exp);
18441       break;
18442     }
18443   /* Adjust properly the offset of src and dest memory for aliasing.  */
18444   if (CONST_INT_P (count_exp))
18445     dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
18446                                         (count / size_needed) * size_needed);
18447   else
18448     dst = change_address (dst, BLKmode, destreg);
18449
18450   /* Step 4: Epilogue to copy the remaining bytes.  */
18451
18452   if (label)
18453     {
18454       /* When the main loop is done, COUNT_EXP might hold original count,
18455          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
18456          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
18457          bytes. Compensate if needed.  */
18458
18459       if (size_needed < epilogue_size_needed)
18460         {
18461           tmp =
18462             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
18463                                  GEN_INT (size_needed - 1), count_exp, 1,
18464                                  OPTAB_DIRECT);
18465           if (tmp != count_exp)
18466             emit_move_insn (count_exp, tmp);
18467         }
18468       emit_label (label);
18469       LABEL_NUSES (label) = 1;
18470     }
18471  epilogue:
18472   if (count_exp != const0_rtx && epilogue_size_needed > 1)
18473     {
18474       if (force_loopy_epilogue)
18475         expand_setmem_epilogue_via_loop (dst, destreg, val_exp, count_exp,
18476                                          epilogue_size_needed);
18477       else
18478         expand_setmem_epilogue (dst, destreg, promoted_val, count_exp,
18479                                 epilogue_size_needed);
18480     }
18481   if (jump_around_label)
18482     emit_label (jump_around_label);
18483   return 1;
18484 }
18485
18486 /* Expand the appropriate insns for doing strlen if not just doing
18487    repnz; scasb
18488
18489    out = result, initialized with the start address
18490    align_rtx = alignment of the address.
18491    scratch = scratch register, initialized with the startaddress when
18492         not aligned, otherwise undefined
18493
18494    This is just the body. It needs the initializations mentioned above and
18495    some address computing at the end.  These things are done in i386.md.  */
18496
18497 static void
18498 ix86_expand_strlensi_unroll_1 (rtx out, rtx src, rtx align_rtx)
18499 {
18500   int align;
18501   rtx tmp;
18502   rtx align_2_label = NULL_RTX;
18503   rtx align_3_label = NULL_RTX;
18504   rtx align_4_label = gen_label_rtx ();
18505   rtx end_0_label = gen_label_rtx ();
18506   rtx mem;
18507   rtx tmpreg = gen_reg_rtx (SImode);
18508   rtx scratch = gen_reg_rtx (SImode);
18509   rtx cmp;
18510
18511   align = 0;
18512   if (CONST_INT_P (align_rtx))
18513     align = INTVAL (align_rtx);
18514
18515   /* Loop to check 1..3 bytes for null to get an aligned pointer.  */
18516
18517   /* Is there a known alignment and is it less than 4?  */
18518   if (align < 4)
18519     {
18520       rtx scratch1 = gen_reg_rtx (Pmode);
18521       emit_move_insn (scratch1, out);
18522       /* Is there a known alignment and is it not 2? */
18523       if (align != 2)
18524         {
18525           align_3_label = gen_label_rtx (); /* Label when aligned to 3-byte */
18526           align_2_label = gen_label_rtx (); /* Label when aligned to 2-byte */
18527
18528           /* Leave just the 3 lower bits.  */
18529           align_rtx = expand_binop (Pmode, and_optab, scratch1, GEN_INT (3),
18530                                     NULL_RTX, 0, OPTAB_WIDEN);
18531
18532           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
18533                                    Pmode, 1, align_4_label);
18534           emit_cmp_and_jump_insns (align_rtx, const2_rtx, EQ, NULL,
18535                                    Pmode, 1, align_2_label);
18536           emit_cmp_and_jump_insns (align_rtx, const2_rtx, GTU, NULL,
18537                                    Pmode, 1, align_3_label);
18538         }
18539       else
18540         {
18541           /* Since the alignment is 2, we have to check 2 or 0 bytes;
18542              check if is aligned to 4 - byte.  */
18543
18544           align_rtx = expand_binop (Pmode, and_optab, scratch1, const2_rtx,
18545                                     NULL_RTX, 0, OPTAB_WIDEN);
18546
18547           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
18548                                    Pmode, 1, align_4_label);
18549         }
18550
18551       mem = change_address (src, QImode, out);
18552
18553       /* Now compare the bytes.  */
18554
18555       /* Compare the first n unaligned byte on a byte per byte basis.  */
18556       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL,
18557                                QImode, 1, end_0_label);
18558
18559       /* Increment the address.  */
18560       emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
18561
18562       /* Not needed with an alignment of 2 */
18563       if (align != 2)
18564         {
18565           emit_label (align_2_label);
18566
18567           emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
18568                                    end_0_label);
18569
18570           emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
18571
18572           emit_label (align_3_label);
18573         }
18574
18575       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
18576                                end_0_label);
18577
18578       emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
18579     }
18580
18581   /* Generate loop to check 4 bytes at a time.  It is not a good idea to
18582      align this loop.  It gives only huge programs, but does not help to
18583      speed up.  */
18584   emit_label (align_4_label);
18585
18586   mem = change_address (src, SImode, out);
18587   emit_move_insn (scratch, mem);
18588   emit_insn ((*ix86_gen_add3) (out, out, GEN_INT (4)));
18589
18590   /* This formula yields a nonzero result iff one of the bytes is zero.
18591      This saves three branches inside loop and many cycles.  */
18592
18593   emit_insn (gen_addsi3 (tmpreg, scratch, GEN_INT (-0x01010101)));
18594   emit_insn (gen_one_cmplsi2 (scratch, scratch));
18595   emit_insn (gen_andsi3 (tmpreg, tmpreg, scratch));
18596   emit_insn (gen_andsi3 (tmpreg, tmpreg,
18597                          gen_int_mode (0x80808080, SImode)));
18598   emit_cmp_and_jump_insns (tmpreg, const0_rtx, EQ, 0, SImode, 1,
18599                            align_4_label);
18600
18601   if (TARGET_CMOVE)
18602     {
18603        rtx reg = gen_reg_rtx (SImode);
18604        rtx reg2 = gen_reg_rtx (Pmode);
18605        emit_move_insn (reg, tmpreg);
18606        emit_insn (gen_lshrsi3 (reg, reg, GEN_INT (16)));
18607
18608        /* If zero is not in the first two bytes, move two bytes forward.  */
18609        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
18610        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
18611        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
18612        emit_insn (gen_rtx_SET (VOIDmode, tmpreg,
18613                                gen_rtx_IF_THEN_ELSE (SImode, tmp,
18614                                                      reg,
18615                                                      tmpreg)));
18616        /* Emit lea manually to avoid clobbering of flags.  */
18617        emit_insn (gen_rtx_SET (SImode, reg2,
18618                                gen_rtx_PLUS (Pmode, out, const2_rtx)));
18619
18620        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
18621        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
18622        emit_insn (gen_rtx_SET (VOIDmode, out,
18623                                gen_rtx_IF_THEN_ELSE (Pmode, tmp,
18624                                                      reg2,
18625                                                      out)));
18626
18627     }
18628   else
18629     {
18630        rtx end_2_label = gen_label_rtx ();
18631        /* Is zero in the first two bytes? */
18632
18633        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
18634        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
18635        tmp = gen_rtx_NE (VOIDmode, tmp, const0_rtx);
18636        tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
18637                             gen_rtx_LABEL_REF (VOIDmode, end_2_label),
18638                             pc_rtx);
18639        tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
18640        JUMP_LABEL (tmp) = end_2_label;
18641
18642        /* Not in the first two.  Move two bytes forward.  */
18643        emit_insn (gen_lshrsi3 (tmpreg, tmpreg, GEN_INT (16)));
18644        emit_insn ((*ix86_gen_add3) (out, out, const2_rtx));
18645
18646        emit_label (end_2_label);
18647
18648     }
18649
18650   /* Avoid branch in fixing the byte.  */
18651   tmpreg = gen_lowpart (QImode, tmpreg);
18652   emit_insn (gen_addqi3_cc (tmpreg, tmpreg, tmpreg));
18653   cmp = gen_rtx_LTU (Pmode, gen_rtx_REG (CCmode, FLAGS_REG), const0_rtx);
18654   emit_insn ((*ix86_gen_sub3_carry) (out, out, GEN_INT (3), cmp));
18655
18656   emit_label (end_0_label);
18657 }
18658
18659 /* Expand strlen.  */
18660
18661 int
18662 ix86_expand_strlen (rtx out, rtx src, rtx eoschar, rtx align)
18663 {
18664   rtx addr, scratch1, scratch2, scratch3, scratch4;
18665
18666   /* The generic case of strlen expander is long.  Avoid it's
18667      expanding unless TARGET_INLINE_ALL_STRINGOPS.  */
18668
18669   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
18670       && !TARGET_INLINE_ALL_STRINGOPS
18671       && !optimize_insn_for_size_p ()
18672       && (!CONST_INT_P (align) || INTVAL (align) < 4))
18673     return 0;
18674
18675   addr = force_reg (Pmode, XEXP (src, 0));
18676   scratch1 = gen_reg_rtx (Pmode);
18677
18678   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
18679       && !optimize_insn_for_size_p ())
18680     {
18681       /* Well it seems that some optimizer does not combine a call like
18682          foo(strlen(bar), strlen(bar));
18683          when the move and the subtraction is done here.  It does calculate
18684          the length just once when these instructions are done inside of
18685          output_strlen_unroll().  But I think since &bar[strlen(bar)] is
18686          often used and I use one fewer register for the lifetime of
18687          output_strlen_unroll() this is better.  */
18688
18689       emit_move_insn (out, addr);
18690
18691       ix86_expand_strlensi_unroll_1 (out, src, align);
18692
18693       /* strlensi_unroll_1 returns the address of the zero at the end of
18694          the string, like memchr(), so compute the length by subtracting
18695          the start address.  */
18696       emit_insn ((*ix86_gen_sub3) (out, out, addr));
18697     }
18698   else
18699     {
18700       rtx unspec;
18701
18702       /* Can't use this if the user has appropriated eax, ecx, or edi.  */
18703       if (fixed_regs[AX_REG] || fixed_regs[CX_REG] || fixed_regs[DI_REG])
18704         return false;
18705
18706       scratch2 = gen_reg_rtx (Pmode);
18707       scratch3 = gen_reg_rtx (Pmode);
18708       scratch4 = force_reg (Pmode, constm1_rtx);
18709
18710       emit_move_insn (scratch3, addr);
18711       eoschar = force_reg (QImode, eoschar);
18712
18713       src = replace_equiv_address_nv (src, scratch3);
18714
18715       /* If .md starts supporting :P, this can be done in .md.  */
18716       unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (4, src, eoschar, align,
18717                                                  scratch4), UNSPEC_SCAS);
18718       emit_insn (gen_strlenqi_1 (scratch1, scratch3, unspec));
18719       emit_insn ((*ix86_gen_one_cmpl2) (scratch2, scratch1));
18720       emit_insn ((*ix86_gen_add3) (out, scratch2, constm1_rtx));
18721     }
18722   return 1;
18723 }
18724
18725 /* For given symbol (function) construct code to compute address of it's PLT
18726    entry in large x86-64 PIC model.  */
18727 rtx
18728 construct_plt_address (rtx symbol)
18729 {
18730   rtx tmp = gen_reg_rtx (Pmode);
18731   rtx unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, symbol), UNSPEC_PLTOFF);
18732
18733   gcc_assert (GET_CODE (symbol) == SYMBOL_REF);
18734   gcc_assert (ix86_cmodel == CM_LARGE_PIC);
18735
18736   emit_move_insn (tmp, gen_rtx_CONST (Pmode, unspec));
18737   emit_insn (gen_adddi3 (tmp, tmp, pic_offset_table_rtx));
18738   return tmp;
18739 }
18740
18741 void
18742 ix86_expand_call (rtx retval, rtx fnaddr, rtx callarg1,
18743                   rtx callarg2,
18744                   rtx pop, int sibcall)
18745 {
18746   rtx use = NULL, call;
18747
18748   if (pop == const0_rtx)
18749     pop = NULL;
18750   gcc_assert (!TARGET_64BIT || !pop);
18751
18752   if (TARGET_MACHO && !TARGET_64BIT)
18753     {
18754 #if TARGET_MACHO
18755       if (flag_pic && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF)
18756         fnaddr = machopic_indirect_call_target (fnaddr);
18757 #endif
18758     }
18759   else
18760     {
18761       /* Static functions and indirect calls don't need the pic register.  */
18762       if (flag_pic && (!TARGET_64BIT || ix86_cmodel == CM_LARGE_PIC)
18763           && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
18764           && ! SYMBOL_REF_LOCAL_P (XEXP (fnaddr, 0)))
18765         use_reg (&use, pic_offset_table_rtx);
18766     }
18767
18768   if (TARGET_64BIT && INTVAL (callarg2) >= 0)
18769     {
18770       rtx al = gen_rtx_REG (QImode, AX_REG);
18771       emit_move_insn (al, callarg2);
18772       use_reg (&use, al);
18773     }
18774
18775   if (ix86_cmodel == CM_LARGE_PIC
18776       && GET_CODE (fnaddr) == MEM
18777       && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
18778       && !local_symbolic_operand (XEXP (fnaddr, 0), VOIDmode))
18779     fnaddr = gen_rtx_MEM (QImode, construct_plt_address (XEXP (fnaddr, 0)));
18780   else if (sibcall
18781            ? !sibcall_insn_operand (XEXP (fnaddr, 0), Pmode)
18782            : !call_insn_operand (XEXP (fnaddr, 0), Pmode))
18783     {
18784       fnaddr = copy_to_mode_reg (Pmode, XEXP (fnaddr, 0));
18785       fnaddr = gen_rtx_MEM (QImode, fnaddr);
18786     }
18787
18788   call = gen_rtx_CALL (VOIDmode, fnaddr, callarg1);
18789   if (retval)
18790     call = gen_rtx_SET (VOIDmode, retval, call);
18791   if (pop)
18792     {
18793       pop = gen_rtx_PLUS (Pmode, stack_pointer_rtx, pop);
18794       pop = gen_rtx_SET (VOIDmode, stack_pointer_rtx, pop);
18795       call = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, call, pop));
18796     }
18797   if (TARGET_64BIT
18798       && ix86_cfun_abi () == MS_ABI
18799       && (!callarg2 || INTVAL (callarg2) != -2))
18800     {
18801       /* We need to represent that SI and DI registers are clobbered
18802          by SYSV calls.  */
18803       static int clobbered_registers[] = {
18804         XMM6_REG, XMM7_REG, XMM8_REG,
18805         XMM9_REG, XMM10_REG, XMM11_REG,
18806         XMM12_REG, XMM13_REG, XMM14_REG,
18807         XMM15_REG, SI_REG, DI_REG
18808       };
18809       unsigned int i;
18810       rtx vec[ARRAY_SIZE (clobbered_registers) + 2];
18811       rtx unspec = gen_rtx_UNSPEC (VOIDmode, gen_rtvec (1, const0_rtx),
18812                                    UNSPEC_MS_TO_SYSV_CALL);
18813
18814       vec[0] = call;
18815       vec[1] = unspec;
18816       for (i = 0; i < ARRAY_SIZE (clobbered_registers); i++)
18817         vec[i + 2] = gen_rtx_CLOBBER (SSE_REGNO_P (clobbered_registers[i])
18818                                       ? TImode : DImode,
18819                                       gen_rtx_REG
18820                                         (SSE_REGNO_P (clobbered_registers[i])
18821                                                       ? TImode : DImode,
18822                                          clobbered_registers[i]));
18823
18824       call = gen_rtx_PARALLEL (VOIDmode,
18825                                gen_rtvec_v (ARRAY_SIZE (clobbered_registers)
18826                                + 2, vec));
18827     }
18828
18829   call = emit_call_insn (call);
18830   if (use)
18831     CALL_INSN_FUNCTION_USAGE (call) = use;
18832 }
18833
18834 \f
18835 /* Clear stack slot assignments remembered from previous functions.
18836    This is called from INIT_EXPANDERS once before RTL is emitted for each
18837    function.  */
18838
18839 static struct machine_function *
18840 ix86_init_machine_status (void)
18841 {
18842   struct machine_function *f;
18843
18844   f = GGC_CNEW (struct machine_function);
18845   f->use_fast_prologue_epilogue_nregs = -1;
18846   f->tls_descriptor_call_expanded_p = 0;
18847   f->call_abi = DEFAULT_ABI;
18848
18849   return f;
18850 }
18851
18852 /* Return a MEM corresponding to a stack slot with mode MODE.
18853    Allocate a new slot if necessary.
18854
18855    The RTL for a function can have several slots available: N is
18856    which slot to use.  */
18857
18858 rtx
18859 assign_386_stack_local (enum machine_mode mode, enum ix86_stack_slot n)
18860 {
18861   struct stack_local_entry *s;
18862
18863   gcc_assert (n < MAX_386_STACK_LOCALS);
18864
18865   /* Virtual slot is valid only before vregs are instantiated.  */
18866   gcc_assert ((n == SLOT_VIRTUAL) == !virtuals_instantiated);
18867
18868   for (s = ix86_stack_locals; s; s = s->next)
18869     if (s->mode == mode && s->n == n)
18870       return copy_rtx (s->rtl);
18871
18872   s = (struct stack_local_entry *)
18873     ggc_alloc (sizeof (struct stack_local_entry));
18874   s->n = n;
18875   s->mode = mode;
18876   s->rtl = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
18877
18878   s->next = ix86_stack_locals;
18879   ix86_stack_locals = s;
18880   return s->rtl;
18881 }
18882
18883 /* Construct the SYMBOL_REF for the tls_get_addr function.  */
18884
18885 static GTY(()) rtx ix86_tls_symbol;
18886 rtx
18887 ix86_tls_get_addr (void)
18888 {
18889
18890   if (!ix86_tls_symbol)
18891     {
18892       ix86_tls_symbol = gen_rtx_SYMBOL_REF (Pmode,
18893                                             (TARGET_ANY_GNU_TLS
18894                                              && !TARGET_64BIT)
18895                                             ? "___tls_get_addr"
18896                                             : "__tls_get_addr");
18897     }
18898
18899   return ix86_tls_symbol;
18900 }
18901
18902 /* Construct the SYMBOL_REF for the _TLS_MODULE_BASE_ symbol.  */
18903
18904 static GTY(()) rtx ix86_tls_module_base_symbol;
18905 rtx
18906 ix86_tls_module_base (void)
18907 {
18908
18909   if (!ix86_tls_module_base_symbol)
18910     {
18911       ix86_tls_module_base_symbol = gen_rtx_SYMBOL_REF (Pmode,
18912                                                         "_TLS_MODULE_BASE_");
18913       SYMBOL_REF_FLAGS (ix86_tls_module_base_symbol)
18914         |= TLS_MODEL_GLOBAL_DYNAMIC << SYMBOL_FLAG_TLS_SHIFT;
18915     }
18916
18917   return ix86_tls_module_base_symbol;
18918 }
18919 \f
18920 /* Calculate the length of the memory address in the instruction
18921    encoding.  Does not include the one-byte modrm, opcode, or prefix.  */
18922
18923 int
18924 memory_address_length (rtx addr)
18925 {
18926   struct ix86_address parts;
18927   rtx base, index, disp;
18928   int len;
18929   int ok;
18930
18931   if (GET_CODE (addr) == PRE_DEC
18932       || GET_CODE (addr) == POST_INC
18933       || GET_CODE (addr) == PRE_MODIFY
18934       || GET_CODE (addr) == POST_MODIFY)
18935     return 0;
18936
18937   ok = ix86_decompose_address (addr, &parts);
18938   gcc_assert (ok);
18939
18940   if (parts.base && GET_CODE (parts.base) == SUBREG)
18941     parts.base = SUBREG_REG (parts.base);
18942   if (parts.index && GET_CODE (parts.index) == SUBREG)
18943     parts.index = SUBREG_REG (parts.index);
18944
18945   base = parts.base;
18946   index = parts.index;
18947   disp = parts.disp;
18948   len = 0;
18949
18950   /* Rule of thumb:
18951        - esp as the base always wants an index,
18952        - ebp as the base always wants a displacement.  */
18953
18954   /* Register Indirect.  */
18955   if (base && !index && !disp)
18956     {
18957       /* esp (for its index) and ebp (for its displacement) need
18958          the two-byte modrm form.  */
18959       if (addr == stack_pointer_rtx
18960           || addr == arg_pointer_rtx
18961           || addr == frame_pointer_rtx
18962           || addr == hard_frame_pointer_rtx)
18963         len = 1;
18964     }
18965
18966   /* Direct Addressing.  */
18967   else if (disp && !base && !index)
18968     len = 4;
18969
18970   else
18971     {
18972       /* Find the length of the displacement constant.  */
18973       if (disp)
18974         {
18975           if (base && satisfies_constraint_K (disp))
18976             len = 1;
18977           else
18978             len = 4;
18979         }
18980       /* ebp always wants a displacement.  */
18981       else if (base == hard_frame_pointer_rtx)
18982         len = 1;
18983
18984       /* An index requires the two-byte modrm form....  */
18985       if (index
18986           /* ...like esp, which always wants an index.  */
18987           || base == stack_pointer_rtx
18988           || base == arg_pointer_rtx
18989           || base == frame_pointer_rtx)
18990         len += 1;
18991     }
18992
18993   return len;
18994 }
18995
18996 /* Compute default value for "length_immediate" attribute.  When SHORTFORM
18997    is set, expect that insn have 8bit immediate alternative.  */
18998 int
18999 ix86_attr_length_immediate_default (rtx insn, int shortform)
19000 {
19001   int len = 0;
19002   int i;
19003   extract_insn_cached (insn);
19004   for (i = recog_data.n_operands - 1; i >= 0; --i)
19005     if (CONSTANT_P (recog_data.operand[i]))
19006       {
19007         gcc_assert (!len);
19008         if (shortform && satisfies_constraint_K (recog_data.operand[i]))
19009           len = 1;
19010         else
19011           {
19012             switch (get_attr_mode (insn))
19013               {
19014                 case MODE_QI:
19015                   len+=1;
19016                   break;
19017                 case MODE_HI:
19018                   len+=2;
19019                   break;
19020                 case MODE_SI:
19021                   len+=4;
19022                   break;
19023                 /* Immediates for DImode instructions are encoded as 32bit sign extended values.  */
19024                 case MODE_DI:
19025                   len+=4;
19026                   break;
19027                 default:
19028                   fatal_insn ("unknown insn mode", insn);
19029               }
19030           }
19031       }
19032   return len;
19033 }
19034 /* Compute default value for "length_address" attribute.  */
19035 int
19036 ix86_attr_length_address_default (rtx insn)
19037 {
19038   int i;
19039
19040   if (get_attr_type (insn) == TYPE_LEA)
19041     {
19042       rtx set = PATTERN (insn);
19043
19044       if (GET_CODE (set) == PARALLEL)
19045         set = XVECEXP (set, 0, 0);
19046
19047       gcc_assert (GET_CODE (set) == SET);
19048
19049       return memory_address_length (SET_SRC (set));
19050     }
19051
19052   extract_insn_cached (insn);
19053   for (i = recog_data.n_operands - 1; i >= 0; --i)
19054     if (MEM_P (recog_data.operand[i]))
19055       {
19056         return memory_address_length (XEXP (recog_data.operand[i], 0));
19057         break;
19058       }
19059   return 0;
19060 }
19061
19062 /* Compute default value for "length_vex" attribute. It includes
19063    2 or 3 byte VEX prefix and 1 opcode byte.  */
19064
19065 int
19066 ix86_attr_length_vex_default (rtx insn, int has_0f_opcode,
19067                               int has_vex_w)
19068 {
19069   int i;
19070
19071   /* Only 0f opcode can use 2 byte VEX prefix and  VEX W bit uses 3
19072      byte VEX prefix.  */
19073   if (!has_0f_opcode || has_vex_w)
19074     return 3 + 1;
19075
19076  /* We can always use 2 byte VEX prefix in 32bit.  */
19077   if (!TARGET_64BIT)
19078     return 2 + 1;
19079
19080   extract_insn_cached (insn);
19081
19082   for (i = recog_data.n_operands - 1; i >= 0; --i)
19083     if (REG_P (recog_data.operand[i]))
19084       {
19085         /* REX.W bit uses 3 byte VEX prefix.  */
19086         if (GET_MODE (recog_data.operand[i]) == DImode)
19087           return 3 + 1;
19088       }
19089     else
19090       {
19091         /* REX.X or REX.B bits use 3 byte VEX prefix.  */
19092         if (MEM_P (recog_data.operand[i])
19093             && x86_extended_reg_mentioned_p (recog_data.operand[i]))
19094           return 3 + 1;
19095       }
19096
19097   return 2 + 1;
19098 }
19099 \f
19100 /* Return the maximum number of instructions a cpu can issue.  */
19101
19102 static int
19103 ix86_issue_rate (void)
19104 {
19105   switch (ix86_tune)
19106     {
19107     case PROCESSOR_PENTIUM:
19108     case PROCESSOR_K6:
19109       return 2;
19110
19111     case PROCESSOR_PENTIUMPRO:
19112     case PROCESSOR_PENTIUM4:
19113     case PROCESSOR_ATHLON:
19114     case PROCESSOR_K8:
19115     case PROCESSOR_AMDFAM10:
19116     case PROCESSOR_NOCONA:
19117     case PROCESSOR_GENERIC32:
19118     case PROCESSOR_GENERIC64:
19119       return 3;
19120
19121     case PROCESSOR_CORE2:
19122       return 4;
19123
19124     default:
19125       return 1;
19126     }
19127 }
19128
19129 /* A subroutine of ix86_adjust_cost -- return true iff INSN reads flags set
19130    by DEP_INSN and nothing set by DEP_INSN.  */
19131
19132 static int
19133 ix86_flags_dependent (rtx insn, rtx dep_insn, enum attr_type insn_type)
19134 {
19135   rtx set, set2;
19136
19137   /* Simplify the test for uninteresting insns.  */
19138   if (insn_type != TYPE_SETCC
19139       && insn_type != TYPE_ICMOV
19140       && insn_type != TYPE_FCMOV
19141       && insn_type != TYPE_IBR)
19142     return 0;
19143
19144   if ((set = single_set (dep_insn)) != 0)
19145     {
19146       set = SET_DEST (set);
19147       set2 = NULL_RTX;
19148     }
19149   else if (GET_CODE (PATTERN (dep_insn)) == PARALLEL
19150            && XVECLEN (PATTERN (dep_insn), 0) == 2
19151            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 0)) == SET
19152            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 1)) == SET)
19153     {
19154       set = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
19155       set2 = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
19156     }
19157   else
19158     return 0;
19159
19160   if (!REG_P (set) || REGNO (set) != FLAGS_REG)
19161     return 0;
19162
19163   /* This test is true if the dependent insn reads the flags but
19164      not any other potentially set register.  */
19165   if (!reg_overlap_mentioned_p (set, PATTERN (insn)))
19166     return 0;
19167
19168   if (set2 && reg_overlap_mentioned_p (set2, PATTERN (insn)))
19169     return 0;
19170
19171   return 1;
19172 }
19173
19174 /* A subroutine of ix86_adjust_cost -- return true iff INSN has a memory
19175    address with operands set by DEP_INSN.  */
19176
19177 static int
19178 ix86_agi_dependent (rtx insn, rtx dep_insn, enum attr_type insn_type)
19179 {
19180   rtx addr;
19181
19182   if (insn_type == TYPE_LEA
19183       && TARGET_PENTIUM)
19184     {
19185       addr = PATTERN (insn);
19186
19187       if (GET_CODE (addr) == PARALLEL)
19188         addr = XVECEXP (addr, 0, 0);
19189
19190       gcc_assert (GET_CODE (addr) == SET);
19191
19192       addr = SET_SRC (addr);
19193     }
19194   else
19195     {
19196       int i;
19197       extract_insn_cached (insn);
19198       for (i = recog_data.n_operands - 1; i >= 0; --i)
19199         if (MEM_P (recog_data.operand[i]))
19200           {
19201             addr = XEXP (recog_data.operand[i], 0);
19202             goto found;
19203           }
19204       return 0;
19205     found:;
19206     }
19207
19208   return modified_in_p (addr, dep_insn);
19209 }
19210
19211 static int
19212 ix86_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
19213 {
19214   enum attr_type insn_type, dep_insn_type;
19215   enum attr_memory memory;
19216   rtx set, set2;
19217   int dep_insn_code_number;
19218
19219   /* Anti and output dependencies have zero cost on all CPUs.  */
19220   if (REG_NOTE_KIND (link) != 0)
19221     return 0;
19222
19223   dep_insn_code_number = recog_memoized (dep_insn);
19224
19225   /* If we can't recognize the insns, we can't really do anything.  */
19226   if (dep_insn_code_number < 0 || recog_memoized (insn) < 0)
19227     return cost;
19228
19229   insn_type = get_attr_type (insn);
19230   dep_insn_type = get_attr_type (dep_insn);
19231
19232   switch (ix86_tune)
19233     {
19234     case PROCESSOR_PENTIUM:
19235       /* Address Generation Interlock adds a cycle of latency.  */
19236       if (ix86_agi_dependent (insn, dep_insn, insn_type))
19237         cost += 1;
19238
19239       /* ??? Compares pair with jump/setcc.  */
19240       if (ix86_flags_dependent (insn, dep_insn, insn_type))
19241         cost = 0;
19242
19243       /* Floating point stores require value to be ready one cycle earlier.  */
19244       if (insn_type == TYPE_FMOV
19245           && get_attr_memory (insn) == MEMORY_STORE
19246           && !ix86_agi_dependent (insn, dep_insn, insn_type))
19247         cost += 1;
19248       break;
19249
19250     case PROCESSOR_PENTIUMPRO:
19251       memory = get_attr_memory (insn);
19252
19253       /* INT->FP conversion is expensive.  */
19254       if (get_attr_fp_int_src (dep_insn))
19255         cost += 5;
19256
19257       /* There is one cycle extra latency between an FP op and a store.  */
19258       if (insn_type == TYPE_FMOV
19259           && (set = single_set (dep_insn)) != NULL_RTX
19260           && (set2 = single_set (insn)) != NULL_RTX
19261           && rtx_equal_p (SET_DEST (set), SET_SRC (set2))
19262           && MEM_P (SET_DEST (set2)))
19263         cost += 1;
19264
19265       /* Show ability of reorder buffer to hide latency of load by executing
19266          in parallel with previous instruction in case
19267          previous instruction is not needed to compute the address.  */
19268       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
19269           && !ix86_agi_dependent (insn, dep_insn, insn_type))
19270         {
19271           /* Claim moves to take one cycle, as core can issue one load
19272              at time and the next load can start cycle later.  */
19273           if (dep_insn_type == TYPE_IMOV
19274               || dep_insn_type == TYPE_FMOV)
19275             cost = 1;
19276           else if (cost > 1)
19277             cost--;
19278         }
19279       break;
19280
19281     case PROCESSOR_K6:
19282       memory = get_attr_memory (insn);
19283
19284       /* The esp dependency is resolved before the instruction is really
19285          finished.  */
19286       if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP)
19287           && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP))
19288         return 1;
19289
19290       /* INT->FP conversion is expensive.  */
19291       if (get_attr_fp_int_src (dep_insn))
19292         cost += 5;
19293
19294       /* Show ability of reorder buffer to hide latency of load by executing
19295          in parallel with previous instruction in case
19296          previous instruction is not needed to compute the address.  */
19297       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
19298           && !ix86_agi_dependent (insn, dep_insn, insn_type))
19299         {
19300           /* Claim moves to take one cycle, as core can issue one load
19301              at time and the next load can start cycle later.  */
19302           if (dep_insn_type == TYPE_IMOV
19303               || dep_insn_type == TYPE_FMOV)
19304             cost = 1;
19305           else if (cost > 2)
19306             cost -= 2;
19307           else
19308             cost = 1;
19309         }
19310       break;
19311
19312     case PROCESSOR_ATHLON:
19313     case PROCESSOR_K8:
19314     case PROCESSOR_AMDFAM10:
19315     case PROCESSOR_GENERIC32:
19316     case PROCESSOR_GENERIC64:
19317       memory = get_attr_memory (insn);
19318
19319       /* Show ability of reorder buffer to hide latency of load by executing
19320          in parallel with previous instruction in case
19321          previous instruction is not needed to compute the address.  */
19322       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
19323           && !ix86_agi_dependent (insn, dep_insn, insn_type))
19324         {
19325           enum attr_unit unit = get_attr_unit (insn);
19326           int loadcost = 3;
19327
19328           /* Because of the difference between the length of integer and
19329              floating unit pipeline preparation stages, the memory operands
19330              for floating point are cheaper.
19331
19332              ??? For Athlon it the difference is most probably 2.  */
19333           if (unit == UNIT_INTEGER || unit == UNIT_UNKNOWN)
19334             loadcost = 3;
19335           else
19336             loadcost = TARGET_ATHLON ? 2 : 0;
19337
19338           if (cost >= loadcost)
19339             cost -= loadcost;
19340           else
19341             cost = 0;
19342         }
19343
19344     default:
19345       break;
19346     }
19347
19348   return cost;
19349 }
19350
19351 /* How many alternative schedules to try.  This should be as wide as the
19352    scheduling freedom in the DFA, but no wider.  Making this value too
19353    large results extra work for the scheduler.  */
19354
19355 static int
19356 ia32_multipass_dfa_lookahead (void)
19357 {
19358   switch (ix86_tune)
19359     {
19360     case PROCESSOR_PENTIUM:
19361       return 2;
19362
19363     case PROCESSOR_PENTIUMPRO:
19364     case PROCESSOR_K6:
19365       return 1;
19366
19367     default:
19368       return 0;
19369     }
19370 }
19371
19372 \f
19373 /* Compute the alignment given to a constant that is being placed in memory.
19374    EXP is the constant and ALIGN is the alignment that the object would
19375    ordinarily have.
19376    The value of this function is used instead of that alignment to align
19377    the object.  */
19378
19379 int
19380 ix86_constant_alignment (tree exp, int align)
19381 {
19382   if (TREE_CODE (exp) == REAL_CST || TREE_CODE (exp) == VECTOR_CST
19383       || TREE_CODE (exp) == INTEGER_CST)
19384     {
19385       if (TYPE_MODE (TREE_TYPE (exp)) == DFmode && align < 64)
19386         return 64;
19387       else if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (exp))) && align < 128)
19388         return 128;
19389     }
19390   else if (!optimize_size && TREE_CODE (exp) == STRING_CST
19391            && TREE_STRING_LENGTH (exp) >= 31 && align < BITS_PER_WORD)
19392     return BITS_PER_WORD;
19393
19394   return align;
19395 }
19396
19397 /* Compute the alignment for a static variable.
19398    TYPE is the data type, and ALIGN is the alignment that
19399    the object would ordinarily have.  The value of this function is used
19400    instead of that alignment to align the object.  */
19401
19402 int
19403 ix86_data_alignment (tree type, int align)
19404 {
19405   int max_align = optimize_size ? BITS_PER_WORD : MIN (256, MAX_OFILE_ALIGNMENT);
19406
19407   if (AGGREGATE_TYPE_P (type)
19408       && TYPE_SIZE (type)
19409       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
19410       && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= (unsigned) max_align
19411           || TREE_INT_CST_HIGH (TYPE_SIZE (type)))
19412       && align < max_align)
19413     align = max_align;
19414
19415   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
19416      to 16byte boundary.  */
19417   if (TARGET_64BIT)
19418     {
19419       if (AGGREGATE_TYPE_P (type)
19420            && TYPE_SIZE (type)
19421            && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
19422            && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 128
19423                || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 128)
19424         return 128;
19425     }
19426
19427   if (TREE_CODE (type) == ARRAY_TYPE)
19428     {
19429       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
19430         return 64;
19431       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
19432         return 128;
19433     }
19434   else if (TREE_CODE (type) == COMPLEX_TYPE)
19435     {
19436
19437       if (TYPE_MODE (type) == DCmode && align < 64)
19438         return 64;
19439       if ((TYPE_MODE (type) == XCmode
19440            || TYPE_MODE (type) == TCmode) && align < 128)
19441         return 128;
19442     }
19443   else if ((TREE_CODE (type) == RECORD_TYPE
19444             || TREE_CODE (type) == UNION_TYPE
19445             || TREE_CODE (type) == QUAL_UNION_TYPE)
19446            && TYPE_FIELDS (type))
19447     {
19448       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
19449         return 64;
19450       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
19451         return 128;
19452     }
19453   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
19454            || TREE_CODE (type) == INTEGER_TYPE)
19455     {
19456       if (TYPE_MODE (type) == DFmode && align < 64)
19457         return 64;
19458       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
19459         return 128;
19460     }
19461
19462   return align;
19463 }
19464
19465 /* Compute the alignment for a local variable or a stack slot.  EXP is
19466    the data type or decl itself, MODE is the widest mode available and
19467    ALIGN is the alignment that the object would ordinarily have.  The
19468    value of this macro is used instead of that alignment to align the
19469    object.  */
19470
19471 unsigned int
19472 ix86_local_alignment (tree exp, enum machine_mode mode,
19473                       unsigned int align)
19474 {
19475   tree type, decl;
19476
19477   if (exp && DECL_P (exp))
19478     {
19479       type = TREE_TYPE (exp);
19480       decl = exp;
19481     }
19482   else
19483     {
19484       type = exp;
19485       decl = NULL;
19486     }
19487
19488   /* Don't do dynamic stack realignment for long long objects with
19489      -mpreferred-stack-boundary=2.  */
19490   if (!TARGET_64BIT
19491       && align == 64
19492       && ix86_preferred_stack_boundary < 64
19493       && (mode == DImode || (type && TYPE_MODE (type) == DImode))
19494       && (!type || !TYPE_USER_ALIGN (type))
19495       && (!decl || !DECL_USER_ALIGN (decl)))
19496     align = 32;
19497
19498   /* If TYPE is NULL, we are allocating a stack slot for caller-save
19499      register in MODE.  We will return the largest alignment of XF
19500      and DF.  */
19501   if (!type)
19502     {
19503       if (mode == XFmode && align < GET_MODE_ALIGNMENT (DFmode))
19504         align = GET_MODE_ALIGNMENT (DFmode);
19505       return align;
19506     }
19507
19508   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
19509      to 16byte boundary.  */
19510   if (TARGET_64BIT)
19511     {
19512       if (AGGREGATE_TYPE_P (type)
19513            && TYPE_SIZE (type)
19514            && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
19515            && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 16
19516                || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 128)
19517         return 128;
19518     }
19519   if (TREE_CODE (type) == ARRAY_TYPE)
19520     {
19521       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
19522         return 64;
19523       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
19524         return 128;
19525     }
19526   else if (TREE_CODE (type) == COMPLEX_TYPE)
19527     {
19528       if (TYPE_MODE (type) == DCmode && align < 64)
19529         return 64;
19530       if ((TYPE_MODE (type) == XCmode
19531            || TYPE_MODE (type) == TCmode) && align < 128)
19532         return 128;
19533     }
19534   else if ((TREE_CODE (type) == RECORD_TYPE
19535             || TREE_CODE (type) == UNION_TYPE
19536             || TREE_CODE (type) == QUAL_UNION_TYPE)
19537            && TYPE_FIELDS (type))
19538     {
19539       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
19540         return 64;
19541       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
19542         return 128;
19543     }
19544   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
19545            || TREE_CODE (type) == INTEGER_TYPE)
19546     {
19547
19548       if (TYPE_MODE (type) == DFmode && align < 64)
19549         return 64;
19550       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
19551         return 128;
19552     }
19553   return align;
19554 }
19555
19556 /* Compute the minimum required alignment for dynamic stack realignment
19557    purposes for a local variable, parameter or a stack slot.  EXP is
19558    the data type or decl itself, MODE is its mode and ALIGN is the
19559    alignment that the object would ordinarily have.  */
19560
19561 unsigned int
19562 ix86_minimum_alignment (tree exp, enum machine_mode mode,
19563                         unsigned int align)
19564 {
19565   tree type, decl;
19566
19567   if (TARGET_64BIT || align != 64 || ix86_preferred_stack_boundary >= 64)
19568     return align;
19569
19570   if (exp && DECL_P (exp))
19571     {
19572       type = TREE_TYPE (exp);
19573       decl = exp;
19574     }
19575   else
19576     {
19577       type = exp;
19578       decl = NULL;
19579     }
19580
19581   /* Don't do dynamic stack realignment for long long objects with
19582      -mpreferred-stack-boundary=2.  */
19583   if ((mode == DImode || (type && TYPE_MODE (type) == DImode))
19584       && (!type || !TYPE_USER_ALIGN (type))
19585       && (!decl || !DECL_USER_ALIGN (decl)))
19586     return 32;
19587
19588   return align;
19589 }
19590 \f
19591 /* Emit RTL insns to initialize the variable parts of a trampoline.
19592    FNADDR is an RTX for the address of the function's pure code.
19593    CXT is an RTX for the static chain value for the function.  */
19594 void
19595 x86_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
19596 {
19597   if (!TARGET_64BIT)
19598     {
19599       /* Compute offset from the end of the jmp to the target function.  */
19600       rtx disp = expand_binop (SImode, sub_optab, fnaddr,
19601                                plus_constant (tramp, 10),
19602                                NULL_RTX, 1, OPTAB_DIRECT);
19603       emit_move_insn (gen_rtx_MEM (QImode, tramp),
19604                       gen_int_mode (0xb9, QImode));
19605       emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 1)), cxt);
19606       emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, 5)),
19607                       gen_int_mode (0xe9, QImode));
19608       emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 6)), disp);
19609     }
19610   else
19611     {
19612       int offset = 0;
19613       /* Try to load address using shorter movl instead of movabs.
19614          We may want to support movq for kernel mode, but kernel does not use
19615          trampolines at the moment.  */
19616       if (x86_64_zext_immediate_operand (fnaddr, VOIDmode))
19617         {
19618           fnaddr = copy_to_mode_reg (DImode, fnaddr);
19619           emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
19620                           gen_int_mode (0xbb41, HImode));
19621           emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, offset + 2)),
19622                           gen_lowpart (SImode, fnaddr));
19623           offset += 6;
19624         }
19625       else
19626         {
19627           emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
19628                           gen_int_mode (0xbb49, HImode));
19629           emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, offset + 2)),
19630                           fnaddr);
19631           offset += 10;
19632         }
19633       /* Load static chain using movabs to r10.  */
19634       emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
19635                       gen_int_mode (0xba49, HImode));
19636       emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, offset + 2)),
19637                       cxt);
19638       offset += 10;
19639       /* Jump to the r11 */
19640       emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
19641                       gen_int_mode (0xff49, HImode));
19642       emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, offset+2)),
19643                       gen_int_mode (0xe3, QImode));
19644       offset += 3;
19645       gcc_assert (offset <= TRAMPOLINE_SIZE);
19646     }
19647
19648 #ifdef ENABLE_EXECUTE_STACK
19649   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
19650                      LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
19651 #endif
19652 }
19653 \f
19654 /* Codes for all the SSE/MMX builtins.  */
19655 enum ix86_builtins
19656 {
19657   IX86_BUILTIN_ADDPS,
19658   IX86_BUILTIN_ADDSS,
19659   IX86_BUILTIN_DIVPS,
19660   IX86_BUILTIN_DIVSS,
19661   IX86_BUILTIN_MULPS,
19662   IX86_BUILTIN_MULSS,
19663   IX86_BUILTIN_SUBPS,
19664   IX86_BUILTIN_SUBSS,
19665
19666   IX86_BUILTIN_CMPEQPS,
19667   IX86_BUILTIN_CMPLTPS,
19668   IX86_BUILTIN_CMPLEPS,
19669   IX86_BUILTIN_CMPGTPS,
19670   IX86_BUILTIN_CMPGEPS,
19671   IX86_BUILTIN_CMPNEQPS,
19672   IX86_BUILTIN_CMPNLTPS,
19673   IX86_BUILTIN_CMPNLEPS,
19674   IX86_BUILTIN_CMPNGTPS,
19675   IX86_BUILTIN_CMPNGEPS,
19676   IX86_BUILTIN_CMPORDPS,
19677   IX86_BUILTIN_CMPUNORDPS,
19678   IX86_BUILTIN_CMPEQSS,
19679   IX86_BUILTIN_CMPLTSS,
19680   IX86_BUILTIN_CMPLESS,
19681   IX86_BUILTIN_CMPNEQSS,
19682   IX86_BUILTIN_CMPNLTSS,
19683   IX86_BUILTIN_CMPNLESS,
19684   IX86_BUILTIN_CMPNGTSS,
19685   IX86_BUILTIN_CMPNGESS,
19686   IX86_BUILTIN_CMPORDSS,
19687   IX86_BUILTIN_CMPUNORDSS,
19688
19689   IX86_BUILTIN_COMIEQSS,
19690   IX86_BUILTIN_COMILTSS,
19691   IX86_BUILTIN_COMILESS,
19692   IX86_BUILTIN_COMIGTSS,
19693   IX86_BUILTIN_COMIGESS,
19694   IX86_BUILTIN_COMINEQSS,
19695   IX86_BUILTIN_UCOMIEQSS,
19696   IX86_BUILTIN_UCOMILTSS,
19697   IX86_BUILTIN_UCOMILESS,
19698   IX86_BUILTIN_UCOMIGTSS,
19699   IX86_BUILTIN_UCOMIGESS,
19700   IX86_BUILTIN_UCOMINEQSS,
19701
19702   IX86_BUILTIN_CVTPI2PS,
19703   IX86_BUILTIN_CVTPS2PI,
19704   IX86_BUILTIN_CVTSI2SS,
19705   IX86_BUILTIN_CVTSI642SS,
19706   IX86_BUILTIN_CVTSS2SI,
19707   IX86_BUILTIN_CVTSS2SI64,
19708   IX86_BUILTIN_CVTTPS2PI,
19709   IX86_BUILTIN_CVTTSS2SI,
19710   IX86_BUILTIN_CVTTSS2SI64,
19711
19712   IX86_BUILTIN_MAXPS,
19713   IX86_BUILTIN_MAXSS,
19714   IX86_BUILTIN_MINPS,
19715   IX86_BUILTIN_MINSS,
19716
19717   IX86_BUILTIN_LOADUPS,
19718   IX86_BUILTIN_STOREUPS,
19719   IX86_BUILTIN_MOVSS,
19720
19721   IX86_BUILTIN_MOVHLPS,
19722   IX86_BUILTIN_MOVLHPS,
19723   IX86_BUILTIN_LOADHPS,
19724   IX86_BUILTIN_LOADLPS,
19725   IX86_BUILTIN_STOREHPS,
19726   IX86_BUILTIN_STORELPS,
19727
19728   IX86_BUILTIN_MASKMOVQ,
19729   IX86_BUILTIN_MOVMSKPS,
19730   IX86_BUILTIN_PMOVMSKB,
19731
19732   IX86_BUILTIN_MOVNTPS,
19733   IX86_BUILTIN_MOVNTQ,
19734
19735   IX86_BUILTIN_LOADDQU,
19736   IX86_BUILTIN_STOREDQU,
19737
19738   IX86_BUILTIN_PACKSSWB,
19739   IX86_BUILTIN_PACKSSDW,
19740   IX86_BUILTIN_PACKUSWB,
19741
19742   IX86_BUILTIN_PADDB,
19743   IX86_BUILTIN_PADDW,
19744   IX86_BUILTIN_PADDD,
19745   IX86_BUILTIN_PADDQ,
19746   IX86_BUILTIN_PADDSB,
19747   IX86_BUILTIN_PADDSW,
19748   IX86_BUILTIN_PADDUSB,
19749   IX86_BUILTIN_PADDUSW,
19750   IX86_BUILTIN_PSUBB,
19751   IX86_BUILTIN_PSUBW,
19752   IX86_BUILTIN_PSUBD,
19753   IX86_BUILTIN_PSUBQ,
19754   IX86_BUILTIN_PSUBSB,
19755   IX86_BUILTIN_PSUBSW,
19756   IX86_BUILTIN_PSUBUSB,
19757   IX86_BUILTIN_PSUBUSW,
19758
19759   IX86_BUILTIN_PAND,
19760   IX86_BUILTIN_PANDN,
19761   IX86_BUILTIN_POR,
19762   IX86_BUILTIN_PXOR,
19763
19764   IX86_BUILTIN_PAVGB,
19765   IX86_BUILTIN_PAVGW,
19766
19767   IX86_BUILTIN_PCMPEQB,
19768   IX86_BUILTIN_PCMPEQW,
19769   IX86_BUILTIN_PCMPEQD,
19770   IX86_BUILTIN_PCMPGTB,
19771   IX86_BUILTIN_PCMPGTW,
19772   IX86_BUILTIN_PCMPGTD,
19773
19774   IX86_BUILTIN_PMADDWD,
19775
19776   IX86_BUILTIN_PMAXSW,
19777   IX86_BUILTIN_PMAXUB,
19778   IX86_BUILTIN_PMINSW,
19779   IX86_BUILTIN_PMINUB,
19780
19781   IX86_BUILTIN_PMULHUW,
19782   IX86_BUILTIN_PMULHW,
19783   IX86_BUILTIN_PMULLW,
19784
19785   IX86_BUILTIN_PSADBW,
19786   IX86_BUILTIN_PSHUFW,
19787
19788   IX86_BUILTIN_PSLLW,
19789   IX86_BUILTIN_PSLLD,
19790   IX86_BUILTIN_PSLLQ,
19791   IX86_BUILTIN_PSRAW,
19792   IX86_BUILTIN_PSRAD,
19793   IX86_BUILTIN_PSRLW,
19794   IX86_BUILTIN_PSRLD,
19795   IX86_BUILTIN_PSRLQ,
19796   IX86_BUILTIN_PSLLWI,
19797   IX86_BUILTIN_PSLLDI,
19798   IX86_BUILTIN_PSLLQI,
19799   IX86_BUILTIN_PSRAWI,
19800   IX86_BUILTIN_PSRADI,
19801   IX86_BUILTIN_PSRLWI,
19802   IX86_BUILTIN_PSRLDI,
19803   IX86_BUILTIN_PSRLQI,
19804
19805   IX86_BUILTIN_PUNPCKHBW,
19806   IX86_BUILTIN_PUNPCKHWD,
19807   IX86_BUILTIN_PUNPCKHDQ,
19808   IX86_BUILTIN_PUNPCKLBW,
19809   IX86_BUILTIN_PUNPCKLWD,
19810   IX86_BUILTIN_PUNPCKLDQ,
19811
19812   IX86_BUILTIN_SHUFPS,
19813
19814   IX86_BUILTIN_RCPPS,
19815   IX86_BUILTIN_RCPSS,
19816   IX86_BUILTIN_RSQRTPS,
19817   IX86_BUILTIN_RSQRTPS_NR,
19818   IX86_BUILTIN_RSQRTSS,
19819   IX86_BUILTIN_RSQRTF,
19820   IX86_BUILTIN_SQRTPS,
19821   IX86_BUILTIN_SQRTPS_NR,
19822   IX86_BUILTIN_SQRTSS,
19823
19824   IX86_BUILTIN_UNPCKHPS,
19825   IX86_BUILTIN_UNPCKLPS,
19826
19827   IX86_BUILTIN_ANDPS,
19828   IX86_BUILTIN_ANDNPS,
19829   IX86_BUILTIN_ORPS,
19830   IX86_BUILTIN_XORPS,
19831
19832   IX86_BUILTIN_EMMS,
19833   IX86_BUILTIN_LDMXCSR,
19834   IX86_BUILTIN_STMXCSR,
19835   IX86_BUILTIN_SFENCE,
19836
19837   /* 3DNow! Original */
19838   IX86_BUILTIN_FEMMS,
19839   IX86_BUILTIN_PAVGUSB,
19840   IX86_BUILTIN_PF2ID,
19841   IX86_BUILTIN_PFACC,
19842   IX86_BUILTIN_PFADD,
19843   IX86_BUILTIN_PFCMPEQ,
19844   IX86_BUILTIN_PFCMPGE,
19845   IX86_BUILTIN_PFCMPGT,
19846   IX86_BUILTIN_PFMAX,
19847   IX86_BUILTIN_PFMIN,
19848   IX86_BUILTIN_PFMUL,
19849   IX86_BUILTIN_PFRCP,
19850   IX86_BUILTIN_PFRCPIT1,
19851   IX86_BUILTIN_PFRCPIT2,
19852   IX86_BUILTIN_PFRSQIT1,
19853   IX86_BUILTIN_PFRSQRT,
19854   IX86_BUILTIN_PFSUB,
19855   IX86_BUILTIN_PFSUBR,
19856   IX86_BUILTIN_PI2FD,
19857   IX86_BUILTIN_PMULHRW,
19858
19859   /* 3DNow! Athlon Extensions */
19860   IX86_BUILTIN_PF2IW,
19861   IX86_BUILTIN_PFNACC,
19862   IX86_BUILTIN_PFPNACC,
19863   IX86_BUILTIN_PI2FW,
19864   IX86_BUILTIN_PSWAPDSI,
19865   IX86_BUILTIN_PSWAPDSF,
19866
19867   /* SSE2 */
19868   IX86_BUILTIN_ADDPD,
19869   IX86_BUILTIN_ADDSD,
19870   IX86_BUILTIN_DIVPD,
19871   IX86_BUILTIN_DIVSD,
19872   IX86_BUILTIN_MULPD,
19873   IX86_BUILTIN_MULSD,
19874   IX86_BUILTIN_SUBPD,
19875   IX86_BUILTIN_SUBSD,
19876
19877   IX86_BUILTIN_CMPEQPD,
19878   IX86_BUILTIN_CMPLTPD,
19879   IX86_BUILTIN_CMPLEPD,
19880   IX86_BUILTIN_CMPGTPD,
19881   IX86_BUILTIN_CMPGEPD,
19882   IX86_BUILTIN_CMPNEQPD,
19883   IX86_BUILTIN_CMPNLTPD,
19884   IX86_BUILTIN_CMPNLEPD,
19885   IX86_BUILTIN_CMPNGTPD,
19886   IX86_BUILTIN_CMPNGEPD,
19887   IX86_BUILTIN_CMPORDPD,
19888   IX86_BUILTIN_CMPUNORDPD,
19889   IX86_BUILTIN_CMPEQSD,
19890   IX86_BUILTIN_CMPLTSD,
19891   IX86_BUILTIN_CMPLESD,
19892   IX86_BUILTIN_CMPNEQSD,
19893   IX86_BUILTIN_CMPNLTSD,
19894   IX86_BUILTIN_CMPNLESD,
19895   IX86_BUILTIN_CMPORDSD,
19896   IX86_BUILTIN_CMPUNORDSD,
19897
19898   IX86_BUILTIN_COMIEQSD,
19899   IX86_BUILTIN_COMILTSD,
19900   IX86_BUILTIN_COMILESD,
19901   IX86_BUILTIN_COMIGTSD,
19902   IX86_BUILTIN_COMIGESD,
19903   IX86_BUILTIN_COMINEQSD,
19904   IX86_BUILTIN_UCOMIEQSD,
19905   IX86_BUILTIN_UCOMILTSD,
19906   IX86_BUILTIN_UCOMILESD,
19907   IX86_BUILTIN_UCOMIGTSD,
19908   IX86_BUILTIN_UCOMIGESD,
19909   IX86_BUILTIN_UCOMINEQSD,
19910
19911   IX86_BUILTIN_MAXPD,
19912   IX86_BUILTIN_MAXSD,
19913   IX86_BUILTIN_MINPD,
19914   IX86_BUILTIN_MINSD,
19915
19916   IX86_BUILTIN_ANDPD,
19917   IX86_BUILTIN_ANDNPD,
19918   IX86_BUILTIN_ORPD,
19919   IX86_BUILTIN_XORPD,
19920
19921   IX86_BUILTIN_SQRTPD,
19922   IX86_BUILTIN_SQRTSD,
19923
19924   IX86_BUILTIN_UNPCKHPD,
19925   IX86_BUILTIN_UNPCKLPD,
19926
19927   IX86_BUILTIN_SHUFPD,
19928
19929   IX86_BUILTIN_LOADUPD,
19930   IX86_BUILTIN_STOREUPD,
19931   IX86_BUILTIN_MOVSD,
19932
19933   IX86_BUILTIN_LOADHPD,
19934   IX86_BUILTIN_LOADLPD,
19935
19936   IX86_BUILTIN_CVTDQ2PD,
19937   IX86_BUILTIN_CVTDQ2PS,
19938
19939   IX86_BUILTIN_CVTPD2DQ,
19940   IX86_BUILTIN_CVTPD2PI,
19941   IX86_BUILTIN_CVTPD2PS,
19942   IX86_BUILTIN_CVTTPD2DQ,
19943   IX86_BUILTIN_CVTTPD2PI,
19944
19945   IX86_BUILTIN_CVTPI2PD,
19946   IX86_BUILTIN_CVTSI2SD,
19947   IX86_BUILTIN_CVTSI642SD,
19948
19949   IX86_BUILTIN_CVTSD2SI,
19950   IX86_BUILTIN_CVTSD2SI64,
19951   IX86_BUILTIN_CVTSD2SS,
19952   IX86_BUILTIN_CVTSS2SD,
19953   IX86_BUILTIN_CVTTSD2SI,
19954   IX86_BUILTIN_CVTTSD2SI64,
19955
19956   IX86_BUILTIN_CVTPS2DQ,
19957   IX86_BUILTIN_CVTPS2PD,
19958   IX86_BUILTIN_CVTTPS2DQ,
19959
19960   IX86_BUILTIN_MOVNTI,
19961   IX86_BUILTIN_MOVNTPD,
19962   IX86_BUILTIN_MOVNTDQ,
19963
19964   IX86_BUILTIN_MOVQ128,
19965
19966   /* SSE2 MMX */
19967   IX86_BUILTIN_MASKMOVDQU,
19968   IX86_BUILTIN_MOVMSKPD,
19969   IX86_BUILTIN_PMOVMSKB128,
19970
19971   IX86_BUILTIN_PACKSSWB128,
19972   IX86_BUILTIN_PACKSSDW128,
19973   IX86_BUILTIN_PACKUSWB128,
19974
19975   IX86_BUILTIN_PADDB128,
19976   IX86_BUILTIN_PADDW128,
19977   IX86_BUILTIN_PADDD128,
19978   IX86_BUILTIN_PADDQ128,
19979   IX86_BUILTIN_PADDSB128,
19980   IX86_BUILTIN_PADDSW128,
19981   IX86_BUILTIN_PADDUSB128,
19982   IX86_BUILTIN_PADDUSW128,
19983   IX86_BUILTIN_PSUBB128,
19984   IX86_BUILTIN_PSUBW128,
19985   IX86_BUILTIN_PSUBD128,
19986   IX86_BUILTIN_PSUBQ128,
19987   IX86_BUILTIN_PSUBSB128,
19988   IX86_BUILTIN_PSUBSW128,
19989   IX86_BUILTIN_PSUBUSB128,
19990   IX86_BUILTIN_PSUBUSW128,
19991
19992   IX86_BUILTIN_PAND128,
19993   IX86_BUILTIN_PANDN128,
19994   IX86_BUILTIN_POR128,
19995   IX86_BUILTIN_PXOR128,
19996
19997   IX86_BUILTIN_PAVGB128,
19998   IX86_BUILTIN_PAVGW128,
19999
20000   IX86_BUILTIN_PCMPEQB128,
20001   IX86_BUILTIN_PCMPEQW128,
20002   IX86_BUILTIN_PCMPEQD128,
20003   IX86_BUILTIN_PCMPGTB128,
20004   IX86_BUILTIN_PCMPGTW128,
20005   IX86_BUILTIN_PCMPGTD128,
20006
20007   IX86_BUILTIN_PMADDWD128,
20008
20009   IX86_BUILTIN_PMAXSW128,
20010   IX86_BUILTIN_PMAXUB128,
20011   IX86_BUILTIN_PMINSW128,
20012   IX86_BUILTIN_PMINUB128,
20013
20014   IX86_BUILTIN_PMULUDQ,
20015   IX86_BUILTIN_PMULUDQ128,
20016   IX86_BUILTIN_PMULHUW128,
20017   IX86_BUILTIN_PMULHW128,
20018   IX86_BUILTIN_PMULLW128,
20019
20020   IX86_BUILTIN_PSADBW128,
20021   IX86_BUILTIN_PSHUFHW,
20022   IX86_BUILTIN_PSHUFLW,
20023   IX86_BUILTIN_PSHUFD,
20024
20025   IX86_BUILTIN_PSLLDQI128,
20026   IX86_BUILTIN_PSLLWI128,
20027   IX86_BUILTIN_PSLLDI128,
20028   IX86_BUILTIN_PSLLQI128,
20029   IX86_BUILTIN_PSRAWI128,
20030   IX86_BUILTIN_PSRADI128,
20031   IX86_BUILTIN_PSRLDQI128,
20032   IX86_BUILTIN_PSRLWI128,
20033   IX86_BUILTIN_PSRLDI128,
20034   IX86_BUILTIN_PSRLQI128,
20035
20036   IX86_BUILTIN_PSLLDQ128,
20037   IX86_BUILTIN_PSLLW128,
20038   IX86_BUILTIN_PSLLD128,
20039   IX86_BUILTIN_PSLLQ128,
20040   IX86_BUILTIN_PSRAW128,
20041   IX86_BUILTIN_PSRAD128,
20042   IX86_BUILTIN_PSRLW128,
20043   IX86_BUILTIN_PSRLD128,
20044   IX86_BUILTIN_PSRLQ128,
20045
20046   IX86_BUILTIN_PUNPCKHBW128,
20047   IX86_BUILTIN_PUNPCKHWD128,
20048   IX86_BUILTIN_PUNPCKHDQ128,
20049   IX86_BUILTIN_PUNPCKHQDQ128,
20050   IX86_BUILTIN_PUNPCKLBW128,
20051   IX86_BUILTIN_PUNPCKLWD128,
20052   IX86_BUILTIN_PUNPCKLDQ128,
20053   IX86_BUILTIN_PUNPCKLQDQ128,
20054
20055   IX86_BUILTIN_CLFLUSH,
20056   IX86_BUILTIN_MFENCE,
20057   IX86_BUILTIN_LFENCE,
20058
20059   /* SSE3.  */
20060   IX86_BUILTIN_ADDSUBPS,
20061   IX86_BUILTIN_HADDPS,
20062   IX86_BUILTIN_HSUBPS,
20063   IX86_BUILTIN_MOVSHDUP,
20064   IX86_BUILTIN_MOVSLDUP,
20065   IX86_BUILTIN_ADDSUBPD,
20066   IX86_BUILTIN_HADDPD,
20067   IX86_BUILTIN_HSUBPD,
20068   IX86_BUILTIN_LDDQU,
20069
20070   IX86_BUILTIN_MONITOR,
20071   IX86_BUILTIN_MWAIT,
20072
20073   /* SSSE3.  */
20074   IX86_BUILTIN_PHADDW,
20075   IX86_BUILTIN_PHADDD,
20076   IX86_BUILTIN_PHADDSW,
20077   IX86_BUILTIN_PHSUBW,
20078   IX86_BUILTIN_PHSUBD,
20079   IX86_BUILTIN_PHSUBSW,
20080   IX86_BUILTIN_PMADDUBSW,
20081   IX86_BUILTIN_PMULHRSW,
20082   IX86_BUILTIN_PSHUFB,
20083   IX86_BUILTIN_PSIGNB,
20084   IX86_BUILTIN_PSIGNW,
20085   IX86_BUILTIN_PSIGND,
20086   IX86_BUILTIN_PALIGNR,
20087   IX86_BUILTIN_PABSB,
20088   IX86_BUILTIN_PABSW,
20089   IX86_BUILTIN_PABSD,
20090
20091   IX86_BUILTIN_PHADDW128,
20092   IX86_BUILTIN_PHADDD128,
20093   IX86_BUILTIN_PHADDSW128,
20094   IX86_BUILTIN_PHSUBW128,
20095   IX86_BUILTIN_PHSUBD128,
20096   IX86_BUILTIN_PHSUBSW128,
20097   IX86_BUILTIN_PMADDUBSW128,
20098   IX86_BUILTIN_PMULHRSW128,
20099   IX86_BUILTIN_PSHUFB128,
20100   IX86_BUILTIN_PSIGNB128,
20101   IX86_BUILTIN_PSIGNW128,
20102   IX86_BUILTIN_PSIGND128,
20103   IX86_BUILTIN_PALIGNR128,
20104   IX86_BUILTIN_PABSB128,
20105   IX86_BUILTIN_PABSW128,
20106   IX86_BUILTIN_PABSD128,
20107
20108   /* AMDFAM10 - SSE4A New Instructions.  */
20109   IX86_BUILTIN_MOVNTSD,
20110   IX86_BUILTIN_MOVNTSS,
20111   IX86_BUILTIN_EXTRQI,
20112   IX86_BUILTIN_EXTRQ,
20113   IX86_BUILTIN_INSERTQI,
20114   IX86_BUILTIN_INSERTQ,
20115
20116   /* SSE4.1.  */
20117   IX86_BUILTIN_BLENDPD,
20118   IX86_BUILTIN_BLENDPS,
20119   IX86_BUILTIN_BLENDVPD,
20120   IX86_BUILTIN_BLENDVPS,
20121   IX86_BUILTIN_PBLENDVB128,
20122   IX86_BUILTIN_PBLENDW128,
20123
20124   IX86_BUILTIN_DPPD,
20125   IX86_BUILTIN_DPPS,
20126
20127   IX86_BUILTIN_INSERTPS128,
20128
20129   IX86_BUILTIN_MOVNTDQA,
20130   IX86_BUILTIN_MPSADBW128,
20131   IX86_BUILTIN_PACKUSDW128,
20132   IX86_BUILTIN_PCMPEQQ,
20133   IX86_BUILTIN_PHMINPOSUW128,
20134
20135   IX86_BUILTIN_PMAXSB128,
20136   IX86_BUILTIN_PMAXSD128,
20137   IX86_BUILTIN_PMAXUD128,
20138   IX86_BUILTIN_PMAXUW128,
20139
20140   IX86_BUILTIN_PMINSB128,
20141   IX86_BUILTIN_PMINSD128,
20142   IX86_BUILTIN_PMINUD128,
20143   IX86_BUILTIN_PMINUW128,
20144
20145   IX86_BUILTIN_PMOVSXBW128,
20146   IX86_BUILTIN_PMOVSXBD128,
20147   IX86_BUILTIN_PMOVSXBQ128,
20148   IX86_BUILTIN_PMOVSXWD128,
20149   IX86_BUILTIN_PMOVSXWQ128,
20150   IX86_BUILTIN_PMOVSXDQ128,
20151
20152   IX86_BUILTIN_PMOVZXBW128,
20153   IX86_BUILTIN_PMOVZXBD128,
20154   IX86_BUILTIN_PMOVZXBQ128,
20155   IX86_BUILTIN_PMOVZXWD128,
20156   IX86_BUILTIN_PMOVZXWQ128,
20157   IX86_BUILTIN_PMOVZXDQ128,
20158
20159   IX86_BUILTIN_PMULDQ128,
20160   IX86_BUILTIN_PMULLD128,
20161
20162   IX86_BUILTIN_ROUNDPD,
20163   IX86_BUILTIN_ROUNDPS,
20164   IX86_BUILTIN_ROUNDSD,
20165   IX86_BUILTIN_ROUNDSS,
20166
20167   IX86_BUILTIN_PTESTZ,
20168   IX86_BUILTIN_PTESTC,
20169   IX86_BUILTIN_PTESTNZC,
20170
20171   IX86_BUILTIN_VEC_INIT_V2SI,
20172   IX86_BUILTIN_VEC_INIT_V4HI,
20173   IX86_BUILTIN_VEC_INIT_V8QI,
20174   IX86_BUILTIN_VEC_EXT_V2DF,
20175   IX86_BUILTIN_VEC_EXT_V2DI,
20176   IX86_BUILTIN_VEC_EXT_V4SF,
20177   IX86_BUILTIN_VEC_EXT_V4SI,
20178   IX86_BUILTIN_VEC_EXT_V8HI,
20179   IX86_BUILTIN_VEC_EXT_V2SI,
20180   IX86_BUILTIN_VEC_EXT_V4HI,
20181   IX86_BUILTIN_VEC_EXT_V16QI,
20182   IX86_BUILTIN_VEC_SET_V2DI,
20183   IX86_BUILTIN_VEC_SET_V4SF,
20184   IX86_BUILTIN_VEC_SET_V4SI,
20185   IX86_BUILTIN_VEC_SET_V8HI,
20186   IX86_BUILTIN_VEC_SET_V4HI,
20187   IX86_BUILTIN_VEC_SET_V16QI,
20188
20189   IX86_BUILTIN_VEC_PACK_SFIX,
20190
20191   /* SSE4.2.  */
20192   IX86_BUILTIN_CRC32QI,
20193   IX86_BUILTIN_CRC32HI,
20194   IX86_BUILTIN_CRC32SI,
20195   IX86_BUILTIN_CRC32DI,
20196
20197   IX86_BUILTIN_PCMPESTRI128,
20198   IX86_BUILTIN_PCMPESTRM128,
20199   IX86_BUILTIN_PCMPESTRA128,
20200   IX86_BUILTIN_PCMPESTRC128,
20201   IX86_BUILTIN_PCMPESTRO128,
20202   IX86_BUILTIN_PCMPESTRS128,
20203   IX86_BUILTIN_PCMPESTRZ128,
20204   IX86_BUILTIN_PCMPISTRI128,
20205   IX86_BUILTIN_PCMPISTRM128,
20206   IX86_BUILTIN_PCMPISTRA128,
20207   IX86_BUILTIN_PCMPISTRC128,
20208   IX86_BUILTIN_PCMPISTRO128,
20209   IX86_BUILTIN_PCMPISTRS128,
20210   IX86_BUILTIN_PCMPISTRZ128,
20211
20212   IX86_BUILTIN_PCMPGTQ,
20213
20214   /* AES instructions */
20215   IX86_BUILTIN_AESENC128,
20216   IX86_BUILTIN_AESENCLAST128,
20217   IX86_BUILTIN_AESDEC128,
20218   IX86_BUILTIN_AESDECLAST128,
20219   IX86_BUILTIN_AESIMC128,
20220   IX86_BUILTIN_AESKEYGENASSIST128,
20221
20222   /* PCLMUL instruction */
20223   IX86_BUILTIN_PCLMULQDQ128,
20224
20225   /* AVX */
20226   IX86_BUILTIN_ADDPD256,
20227   IX86_BUILTIN_ADDPS256,
20228   IX86_BUILTIN_ADDSUBPD256,
20229   IX86_BUILTIN_ADDSUBPS256,
20230   IX86_BUILTIN_ANDPD256,
20231   IX86_BUILTIN_ANDPS256,
20232   IX86_BUILTIN_ANDNPD256,
20233   IX86_BUILTIN_ANDNPS256,
20234   IX86_BUILTIN_BLENDPD256,
20235   IX86_BUILTIN_BLENDPS256,
20236   IX86_BUILTIN_BLENDVPD256,
20237   IX86_BUILTIN_BLENDVPS256,
20238   IX86_BUILTIN_DIVPD256,
20239   IX86_BUILTIN_DIVPS256,
20240   IX86_BUILTIN_DPPS256,
20241   IX86_BUILTIN_HADDPD256,
20242   IX86_BUILTIN_HADDPS256,
20243   IX86_BUILTIN_HSUBPD256,
20244   IX86_BUILTIN_HSUBPS256,
20245   IX86_BUILTIN_MAXPD256,
20246   IX86_BUILTIN_MAXPS256,
20247   IX86_BUILTIN_MINPD256,
20248   IX86_BUILTIN_MINPS256,
20249   IX86_BUILTIN_MULPD256,
20250   IX86_BUILTIN_MULPS256,
20251   IX86_BUILTIN_ORPD256,
20252   IX86_BUILTIN_ORPS256,
20253   IX86_BUILTIN_SHUFPD256,
20254   IX86_BUILTIN_SHUFPS256,
20255   IX86_BUILTIN_SUBPD256,
20256   IX86_BUILTIN_SUBPS256,
20257   IX86_BUILTIN_XORPD256,
20258   IX86_BUILTIN_XORPS256,
20259   IX86_BUILTIN_CMPSD,
20260   IX86_BUILTIN_CMPSS,
20261   IX86_BUILTIN_CMPPD,
20262   IX86_BUILTIN_CMPPS,
20263   IX86_BUILTIN_CMPPD256,
20264   IX86_BUILTIN_CMPPS256,
20265   IX86_BUILTIN_CVTDQ2PD256,
20266   IX86_BUILTIN_CVTDQ2PS256,
20267   IX86_BUILTIN_CVTPD2PS256,
20268   IX86_BUILTIN_CVTPS2DQ256,
20269   IX86_BUILTIN_CVTPS2PD256,
20270   IX86_BUILTIN_CVTTPD2DQ256,
20271   IX86_BUILTIN_CVTPD2DQ256,
20272   IX86_BUILTIN_CVTTPS2DQ256,
20273   IX86_BUILTIN_EXTRACTF128PD256,
20274   IX86_BUILTIN_EXTRACTF128PS256,
20275   IX86_BUILTIN_EXTRACTF128SI256,
20276   IX86_BUILTIN_VZEROALL,
20277   IX86_BUILTIN_VZEROUPPER,
20278   IX86_BUILTIN_VZEROUPPER_REX64,
20279   IX86_BUILTIN_VPERMILVARPD,
20280   IX86_BUILTIN_VPERMILVARPS,
20281   IX86_BUILTIN_VPERMILVARPD256,
20282   IX86_BUILTIN_VPERMILVARPS256,
20283   IX86_BUILTIN_VPERMILPD,
20284   IX86_BUILTIN_VPERMILPS,
20285   IX86_BUILTIN_VPERMILPD256,
20286   IX86_BUILTIN_VPERMILPS256,
20287   IX86_BUILTIN_VPERM2F128PD256,
20288   IX86_BUILTIN_VPERM2F128PS256,
20289   IX86_BUILTIN_VPERM2F128SI256,
20290   IX86_BUILTIN_VBROADCASTSS,
20291   IX86_BUILTIN_VBROADCASTSD256,
20292   IX86_BUILTIN_VBROADCASTSS256,
20293   IX86_BUILTIN_VBROADCASTPD256,
20294   IX86_BUILTIN_VBROADCASTPS256,
20295   IX86_BUILTIN_VINSERTF128PD256,
20296   IX86_BUILTIN_VINSERTF128PS256,
20297   IX86_BUILTIN_VINSERTF128SI256,
20298   IX86_BUILTIN_LOADUPD256,
20299   IX86_BUILTIN_LOADUPS256,
20300   IX86_BUILTIN_STOREUPD256,
20301   IX86_BUILTIN_STOREUPS256,
20302   IX86_BUILTIN_LDDQU256,
20303   IX86_BUILTIN_MOVNTDQ256,
20304   IX86_BUILTIN_MOVNTPD256,
20305   IX86_BUILTIN_MOVNTPS256,
20306   IX86_BUILTIN_LOADDQU256,
20307   IX86_BUILTIN_STOREDQU256,
20308   IX86_BUILTIN_MASKLOADPD,
20309   IX86_BUILTIN_MASKLOADPS,
20310   IX86_BUILTIN_MASKSTOREPD,
20311   IX86_BUILTIN_MASKSTOREPS,
20312   IX86_BUILTIN_MASKLOADPD256,
20313   IX86_BUILTIN_MASKLOADPS256,
20314   IX86_BUILTIN_MASKSTOREPD256,
20315   IX86_BUILTIN_MASKSTOREPS256,
20316   IX86_BUILTIN_MOVSHDUP256,
20317   IX86_BUILTIN_MOVSLDUP256,
20318   IX86_BUILTIN_MOVDDUP256,
20319
20320   IX86_BUILTIN_SQRTPD256,
20321   IX86_BUILTIN_SQRTPS256,
20322   IX86_BUILTIN_SQRTPS_NR256,
20323   IX86_BUILTIN_RSQRTPS256,
20324   IX86_BUILTIN_RSQRTPS_NR256,
20325
20326   IX86_BUILTIN_RCPPS256,
20327
20328   IX86_BUILTIN_ROUNDPD256,
20329   IX86_BUILTIN_ROUNDPS256,
20330
20331   IX86_BUILTIN_UNPCKHPD256,
20332   IX86_BUILTIN_UNPCKLPD256,
20333   IX86_BUILTIN_UNPCKHPS256,
20334   IX86_BUILTIN_UNPCKLPS256,
20335
20336   IX86_BUILTIN_SI256_SI,
20337   IX86_BUILTIN_PS256_PS,
20338   IX86_BUILTIN_PD256_PD,
20339   IX86_BUILTIN_SI_SI256,
20340   IX86_BUILTIN_PS_PS256,
20341   IX86_BUILTIN_PD_PD256,
20342
20343   IX86_BUILTIN_VTESTZPD,
20344   IX86_BUILTIN_VTESTCPD,
20345   IX86_BUILTIN_VTESTNZCPD,
20346   IX86_BUILTIN_VTESTZPS,
20347   IX86_BUILTIN_VTESTCPS,
20348   IX86_BUILTIN_VTESTNZCPS,
20349   IX86_BUILTIN_VTESTZPD256,
20350   IX86_BUILTIN_VTESTCPD256,
20351   IX86_BUILTIN_VTESTNZCPD256,
20352   IX86_BUILTIN_VTESTZPS256,
20353   IX86_BUILTIN_VTESTCPS256,
20354   IX86_BUILTIN_VTESTNZCPS256,
20355   IX86_BUILTIN_PTESTZ256,
20356   IX86_BUILTIN_PTESTC256,
20357   IX86_BUILTIN_PTESTNZC256,
20358
20359   IX86_BUILTIN_MOVMSKPD256,
20360   IX86_BUILTIN_MOVMSKPS256,
20361
20362   /* TFmode support builtins.  */
20363   IX86_BUILTIN_INFQ,
20364   IX86_BUILTIN_FABSQ,
20365   IX86_BUILTIN_COPYSIGNQ,
20366
20367   /* SSE5 instructions */
20368   IX86_BUILTIN_FMADDSS,
20369   IX86_BUILTIN_FMADDSD,
20370   IX86_BUILTIN_FMADDPS,
20371   IX86_BUILTIN_FMADDPD,
20372   IX86_BUILTIN_FMSUBSS,
20373   IX86_BUILTIN_FMSUBSD,
20374   IX86_BUILTIN_FMSUBPS,
20375   IX86_BUILTIN_FMSUBPD,
20376   IX86_BUILTIN_FNMADDSS,
20377   IX86_BUILTIN_FNMADDSD,
20378   IX86_BUILTIN_FNMADDPS,
20379   IX86_BUILTIN_FNMADDPD,
20380   IX86_BUILTIN_FNMSUBSS,
20381   IX86_BUILTIN_FNMSUBSD,
20382   IX86_BUILTIN_FNMSUBPS,
20383   IX86_BUILTIN_FNMSUBPD,
20384   IX86_BUILTIN_PCMOV,
20385   IX86_BUILTIN_PCMOV_V2DI,
20386   IX86_BUILTIN_PCMOV_V4SI,
20387   IX86_BUILTIN_PCMOV_V8HI,
20388   IX86_BUILTIN_PCMOV_V16QI,
20389   IX86_BUILTIN_PCMOV_V4SF,
20390   IX86_BUILTIN_PCMOV_V2DF,
20391   IX86_BUILTIN_PPERM,
20392   IX86_BUILTIN_PERMPS,
20393   IX86_BUILTIN_PERMPD,
20394   IX86_BUILTIN_PMACSSWW,
20395   IX86_BUILTIN_PMACSWW,
20396   IX86_BUILTIN_PMACSSWD,
20397   IX86_BUILTIN_PMACSWD,
20398   IX86_BUILTIN_PMACSSDD,
20399   IX86_BUILTIN_PMACSDD,
20400   IX86_BUILTIN_PMACSSDQL,
20401   IX86_BUILTIN_PMACSSDQH,
20402   IX86_BUILTIN_PMACSDQL,
20403   IX86_BUILTIN_PMACSDQH,
20404   IX86_BUILTIN_PMADCSSWD,
20405   IX86_BUILTIN_PMADCSWD,
20406   IX86_BUILTIN_PHADDBW,
20407   IX86_BUILTIN_PHADDBD,
20408   IX86_BUILTIN_PHADDBQ,
20409   IX86_BUILTIN_PHADDWD,
20410   IX86_BUILTIN_PHADDWQ,
20411   IX86_BUILTIN_PHADDDQ,
20412   IX86_BUILTIN_PHADDUBW,
20413   IX86_BUILTIN_PHADDUBD,
20414   IX86_BUILTIN_PHADDUBQ,
20415   IX86_BUILTIN_PHADDUWD,
20416   IX86_BUILTIN_PHADDUWQ,
20417   IX86_BUILTIN_PHADDUDQ,
20418   IX86_BUILTIN_PHSUBBW,
20419   IX86_BUILTIN_PHSUBWD,
20420   IX86_BUILTIN_PHSUBDQ,
20421   IX86_BUILTIN_PROTB,
20422   IX86_BUILTIN_PROTW,
20423   IX86_BUILTIN_PROTD,
20424   IX86_BUILTIN_PROTQ,
20425   IX86_BUILTIN_PROTB_IMM,
20426   IX86_BUILTIN_PROTW_IMM,
20427   IX86_BUILTIN_PROTD_IMM,
20428   IX86_BUILTIN_PROTQ_IMM,
20429   IX86_BUILTIN_PSHLB,
20430   IX86_BUILTIN_PSHLW,
20431   IX86_BUILTIN_PSHLD,
20432   IX86_BUILTIN_PSHLQ,
20433   IX86_BUILTIN_PSHAB,
20434   IX86_BUILTIN_PSHAW,
20435   IX86_BUILTIN_PSHAD,
20436   IX86_BUILTIN_PSHAQ,
20437   IX86_BUILTIN_FRCZSS,
20438   IX86_BUILTIN_FRCZSD,
20439   IX86_BUILTIN_FRCZPS,
20440   IX86_BUILTIN_FRCZPD,
20441   IX86_BUILTIN_CVTPH2PS,
20442   IX86_BUILTIN_CVTPS2PH,
20443
20444   IX86_BUILTIN_COMEQSS,
20445   IX86_BUILTIN_COMNESS,
20446   IX86_BUILTIN_COMLTSS,
20447   IX86_BUILTIN_COMLESS,
20448   IX86_BUILTIN_COMGTSS,
20449   IX86_BUILTIN_COMGESS,
20450   IX86_BUILTIN_COMUEQSS,
20451   IX86_BUILTIN_COMUNESS,
20452   IX86_BUILTIN_COMULTSS,
20453   IX86_BUILTIN_COMULESS,
20454   IX86_BUILTIN_COMUGTSS,
20455   IX86_BUILTIN_COMUGESS,
20456   IX86_BUILTIN_COMORDSS,
20457   IX86_BUILTIN_COMUNORDSS,
20458   IX86_BUILTIN_COMFALSESS,
20459   IX86_BUILTIN_COMTRUESS,
20460
20461   IX86_BUILTIN_COMEQSD,
20462   IX86_BUILTIN_COMNESD,
20463   IX86_BUILTIN_COMLTSD,
20464   IX86_BUILTIN_COMLESD,
20465   IX86_BUILTIN_COMGTSD,
20466   IX86_BUILTIN_COMGESD,
20467   IX86_BUILTIN_COMUEQSD,
20468   IX86_BUILTIN_COMUNESD,
20469   IX86_BUILTIN_COMULTSD,
20470   IX86_BUILTIN_COMULESD,
20471   IX86_BUILTIN_COMUGTSD,
20472   IX86_BUILTIN_COMUGESD,
20473   IX86_BUILTIN_COMORDSD,
20474   IX86_BUILTIN_COMUNORDSD,
20475   IX86_BUILTIN_COMFALSESD,
20476   IX86_BUILTIN_COMTRUESD,
20477
20478   IX86_BUILTIN_COMEQPS,
20479   IX86_BUILTIN_COMNEPS,
20480   IX86_BUILTIN_COMLTPS,
20481   IX86_BUILTIN_COMLEPS,
20482   IX86_BUILTIN_COMGTPS,
20483   IX86_BUILTIN_COMGEPS,
20484   IX86_BUILTIN_COMUEQPS,
20485   IX86_BUILTIN_COMUNEPS,
20486   IX86_BUILTIN_COMULTPS,
20487   IX86_BUILTIN_COMULEPS,
20488   IX86_BUILTIN_COMUGTPS,
20489   IX86_BUILTIN_COMUGEPS,
20490   IX86_BUILTIN_COMORDPS,
20491   IX86_BUILTIN_COMUNORDPS,
20492   IX86_BUILTIN_COMFALSEPS,
20493   IX86_BUILTIN_COMTRUEPS,
20494
20495   IX86_BUILTIN_COMEQPD,
20496   IX86_BUILTIN_COMNEPD,
20497   IX86_BUILTIN_COMLTPD,
20498   IX86_BUILTIN_COMLEPD,
20499   IX86_BUILTIN_COMGTPD,
20500   IX86_BUILTIN_COMGEPD,
20501   IX86_BUILTIN_COMUEQPD,
20502   IX86_BUILTIN_COMUNEPD,
20503   IX86_BUILTIN_COMULTPD,
20504   IX86_BUILTIN_COMULEPD,
20505   IX86_BUILTIN_COMUGTPD,
20506   IX86_BUILTIN_COMUGEPD,
20507   IX86_BUILTIN_COMORDPD,
20508   IX86_BUILTIN_COMUNORDPD,
20509   IX86_BUILTIN_COMFALSEPD,
20510   IX86_BUILTIN_COMTRUEPD,
20511
20512   IX86_BUILTIN_PCOMEQUB,
20513   IX86_BUILTIN_PCOMNEUB,
20514   IX86_BUILTIN_PCOMLTUB,
20515   IX86_BUILTIN_PCOMLEUB,
20516   IX86_BUILTIN_PCOMGTUB,
20517   IX86_BUILTIN_PCOMGEUB,
20518   IX86_BUILTIN_PCOMFALSEUB,
20519   IX86_BUILTIN_PCOMTRUEUB,
20520   IX86_BUILTIN_PCOMEQUW,
20521   IX86_BUILTIN_PCOMNEUW,
20522   IX86_BUILTIN_PCOMLTUW,
20523   IX86_BUILTIN_PCOMLEUW,
20524   IX86_BUILTIN_PCOMGTUW,
20525   IX86_BUILTIN_PCOMGEUW,
20526   IX86_BUILTIN_PCOMFALSEUW,
20527   IX86_BUILTIN_PCOMTRUEUW,
20528   IX86_BUILTIN_PCOMEQUD,
20529   IX86_BUILTIN_PCOMNEUD,
20530   IX86_BUILTIN_PCOMLTUD,
20531   IX86_BUILTIN_PCOMLEUD,
20532   IX86_BUILTIN_PCOMGTUD,
20533   IX86_BUILTIN_PCOMGEUD,
20534   IX86_BUILTIN_PCOMFALSEUD,
20535   IX86_BUILTIN_PCOMTRUEUD,
20536   IX86_BUILTIN_PCOMEQUQ,
20537   IX86_BUILTIN_PCOMNEUQ,
20538   IX86_BUILTIN_PCOMLTUQ,
20539   IX86_BUILTIN_PCOMLEUQ,
20540   IX86_BUILTIN_PCOMGTUQ,
20541   IX86_BUILTIN_PCOMGEUQ,
20542   IX86_BUILTIN_PCOMFALSEUQ,
20543   IX86_BUILTIN_PCOMTRUEUQ,
20544
20545   IX86_BUILTIN_PCOMEQB,
20546   IX86_BUILTIN_PCOMNEB,
20547   IX86_BUILTIN_PCOMLTB,
20548   IX86_BUILTIN_PCOMLEB,
20549   IX86_BUILTIN_PCOMGTB,
20550   IX86_BUILTIN_PCOMGEB,
20551   IX86_BUILTIN_PCOMFALSEB,
20552   IX86_BUILTIN_PCOMTRUEB,
20553   IX86_BUILTIN_PCOMEQW,
20554   IX86_BUILTIN_PCOMNEW,
20555   IX86_BUILTIN_PCOMLTW,
20556   IX86_BUILTIN_PCOMLEW,
20557   IX86_BUILTIN_PCOMGTW,
20558   IX86_BUILTIN_PCOMGEW,
20559   IX86_BUILTIN_PCOMFALSEW,
20560   IX86_BUILTIN_PCOMTRUEW,
20561   IX86_BUILTIN_PCOMEQD,
20562   IX86_BUILTIN_PCOMNED,
20563   IX86_BUILTIN_PCOMLTD,
20564   IX86_BUILTIN_PCOMLED,
20565   IX86_BUILTIN_PCOMGTD,
20566   IX86_BUILTIN_PCOMGED,
20567   IX86_BUILTIN_PCOMFALSED,
20568   IX86_BUILTIN_PCOMTRUED,
20569   IX86_BUILTIN_PCOMEQQ,
20570   IX86_BUILTIN_PCOMNEQ,
20571   IX86_BUILTIN_PCOMLTQ,
20572   IX86_BUILTIN_PCOMLEQ,
20573   IX86_BUILTIN_PCOMGTQ,
20574   IX86_BUILTIN_PCOMGEQ,
20575   IX86_BUILTIN_PCOMFALSEQ,
20576   IX86_BUILTIN_PCOMTRUEQ,
20577
20578   IX86_BUILTIN_MAX
20579 };
20580
20581 /* Table for the ix86 builtin decls.  */
20582 static GTY(()) tree ix86_builtins[(int) IX86_BUILTIN_MAX];
20583
20584 /* Table of all of the builtin functions that are possible with different ISA's
20585    but are waiting to be built until a function is declared to use that
20586    ISA.  */
20587 struct builtin_isa GTY(())
20588 {
20589   tree type;                    /* builtin type to use in the declaration */
20590   const char *name;             /* function name */
20591   int isa;                      /* isa_flags this builtin is defined for */
20592   bool const_p;                 /* true if the declaration is constant */
20593 };
20594
20595 static GTY(()) struct builtin_isa ix86_builtins_isa[(int) IX86_BUILTIN_MAX];
20596
20597
20598 /* Add an ix86 target builtin function with CODE, NAME and TYPE.  Save the MASK
20599  * of which isa_flags to use in the ix86_builtins_isa array.  Stores the
20600  * function decl in the ix86_builtins array.  Returns the function decl or
20601  * NULL_TREE, if the builtin was not added.
20602  *
20603  * If the front end has a special hook for builtin functions, delay adding
20604  * builtin functions that aren't in the current ISA until the ISA is changed
20605  * with function specific optimization.  Doing so, can save about 300K for the
20606  * default compiler.  When the builtin is expanded, check at that time whether
20607  * it is valid.
20608  *
20609  * If the front end doesn't have a special hook, record all builtins, even if
20610  * it isn't an instruction set in the current ISA in case the user uses
20611  * function specific options for a different ISA, so that we don't get scope
20612  * errors if a builtin is added in the middle of a function scope.  */
20613
20614 static inline tree
20615 def_builtin (int mask, const char *name, tree type, enum ix86_builtins code)
20616 {
20617   tree decl = NULL_TREE;
20618
20619   if (!(mask & OPTION_MASK_ISA_64BIT) || TARGET_64BIT)
20620     {
20621       ix86_builtins_isa[(int) code].isa = mask;
20622
20623       mask &= ~OPTION_MASK_ISA_64BIT;
20624       if ((mask & ix86_isa_flags) != 0
20625           || (lang_hooks.builtin_function
20626               == lang_hooks.builtin_function_ext_scope))
20627
20628         {
20629           decl = add_builtin_function (name, type, code, BUILT_IN_MD, NULL,
20630                                        NULL_TREE);
20631           ix86_builtins[(int) code] = decl;
20632           ix86_builtins_isa[(int) code].type = NULL_TREE;
20633         }
20634       else
20635         {
20636           ix86_builtins[(int) code] = NULL_TREE;
20637           ix86_builtins_isa[(int) code].const_p = false;
20638           ix86_builtins_isa[(int) code].type = type;
20639           ix86_builtins_isa[(int) code].name = name;
20640         }
20641     }
20642
20643   return decl;
20644 }
20645
20646 /* Like def_builtin, but also marks the function decl "const".  */
20647
20648 static inline tree
20649 def_builtin_const (int mask, const char *name, tree type,
20650                    enum ix86_builtins code)
20651 {
20652   tree decl = def_builtin (mask, name, type, code);
20653   if (decl)
20654     TREE_READONLY (decl) = 1;
20655   else
20656     ix86_builtins_isa[(int) code].const_p = true;
20657
20658   return decl;
20659 }
20660
20661 /* Add any new builtin functions for a given ISA that may not have been
20662    declared.  This saves a bit of space compared to adding all of the
20663    declarations to the tree, even if we didn't use them.  */
20664
20665 static void
20666 ix86_add_new_builtins (int isa)
20667 {
20668   int i;
20669   tree decl;
20670
20671   for (i = 0; i < (int)IX86_BUILTIN_MAX; i++)
20672     {
20673       if ((ix86_builtins_isa[i].isa & isa) != 0
20674           && ix86_builtins_isa[i].type != NULL_TREE)
20675         {
20676           decl = add_builtin_function_ext_scope (ix86_builtins_isa[i].name,
20677                                                  ix86_builtins_isa[i].type,
20678                                                  i, BUILT_IN_MD, NULL,
20679                                                  NULL_TREE);
20680
20681           ix86_builtins[i] = decl;
20682           ix86_builtins_isa[i].type = NULL_TREE;
20683           if (ix86_builtins_isa[i].const_p)
20684             TREE_READONLY (decl) = 1;
20685         }
20686     }
20687 }
20688
20689 /* Bits for builtin_description.flag.  */
20690
20691 /* Set when we don't support the comparison natively, and should
20692    swap_comparison in order to support it.  */
20693 #define BUILTIN_DESC_SWAP_OPERANDS      1
20694
20695 struct builtin_description
20696 {
20697   const unsigned int mask;
20698   const enum insn_code icode;
20699   const char *const name;
20700   const enum ix86_builtins code;
20701   const enum rtx_code comparison;
20702   const int flag;
20703 };
20704
20705 static const struct builtin_description bdesc_comi[] =
20706 {
20707   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comieq", IX86_BUILTIN_COMIEQSS, UNEQ, 0 },
20708   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comilt", IX86_BUILTIN_COMILTSS, UNLT, 0 },
20709   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comile", IX86_BUILTIN_COMILESS, UNLE, 0 },
20710   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comigt", IX86_BUILTIN_COMIGTSS, GT, 0 },
20711   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comige", IX86_BUILTIN_COMIGESS, GE, 0 },
20712   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comineq", IX86_BUILTIN_COMINEQSS, LTGT, 0 },
20713   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomieq", IX86_BUILTIN_UCOMIEQSS, UNEQ, 0 },
20714   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomilt", IX86_BUILTIN_UCOMILTSS, UNLT, 0 },
20715   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomile", IX86_BUILTIN_UCOMILESS, UNLE, 0 },
20716   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomigt", IX86_BUILTIN_UCOMIGTSS, GT, 0 },
20717   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomige", IX86_BUILTIN_UCOMIGESS, GE, 0 },
20718   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomineq", IX86_BUILTIN_UCOMINEQSS, LTGT, 0 },
20719   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdeq", IX86_BUILTIN_COMIEQSD, UNEQ, 0 },
20720   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdlt", IX86_BUILTIN_COMILTSD, UNLT, 0 },
20721   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdle", IX86_BUILTIN_COMILESD, UNLE, 0 },
20722   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdgt", IX86_BUILTIN_COMIGTSD, GT, 0 },
20723   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdge", IX86_BUILTIN_COMIGESD, GE, 0 },
20724   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdneq", IX86_BUILTIN_COMINEQSD, LTGT, 0 },
20725   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdeq", IX86_BUILTIN_UCOMIEQSD, UNEQ, 0 },
20726   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdlt", IX86_BUILTIN_UCOMILTSD, UNLT, 0 },
20727   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdle", IX86_BUILTIN_UCOMILESD, UNLE, 0 },
20728   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdgt", IX86_BUILTIN_UCOMIGTSD, GT, 0 },
20729   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdge", IX86_BUILTIN_UCOMIGESD, GE, 0 },
20730   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdneq", IX86_BUILTIN_UCOMINEQSD, LTGT, 0 },
20731 };
20732
20733 static const struct builtin_description bdesc_pcmpestr[] =
20734 {
20735   /* SSE4.2 */
20736   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestri128", IX86_BUILTIN_PCMPESTRI128, UNKNOWN, 0 },
20737   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrm128", IX86_BUILTIN_PCMPESTRM128, UNKNOWN, 0 },
20738   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestria128", IX86_BUILTIN_PCMPESTRA128, UNKNOWN, (int) CCAmode },
20739   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestric128", IX86_BUILTIN_PCMPESTRC128, UNKNOWN, (int) CCCmode },
20740   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrio128", IX86_BUILTIN_PCMPESTRO128, UNKNOWN, (int) CCOmode },
20741   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestris128", IX86_BUILTIN_PCMPESTRS128, UNKNOWN, (int) CCSmode },
20742   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestriz128", IX86_BUILTIN_PCMPESTRZ128, UNKNOWN, (int) CCZmode },
20743 };
20744
20745 static const struct builtin_description bdesc_pcmpistr[] =
20746 {
20747   /* SSE4.2 */
20748   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistri128", IX86_BUILTIN_PCMPISTRI128, UNKNOWN, 0 },
20749   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrm128", IX86_BUILTIN_PCMPISTRM128, UNKNOWN, 0 },
20750   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistria128", IX86_BUILTIN_PCMPISTRA128, UNKNOWN, (int) CCAmode },
20751   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistric128", IX86_BUILTIN_PCMPISTRC128, UNKNOWN, (int) CCCmode },
20752   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrio128", IX86_BUILTIN_PCMPISTRO128, UNKNOWN, (int) CCOmode },
20753   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistris128", IX86_BUILTIN_PCMPISTRS128, UNKNOWN, (int) CCSmode },
20754   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistriz128", IX86_BUILTIN_PCMPISTRZ128, UNKNOWN, (int) CCZmode },
20755 };
20756
20757 /* Special builtin types */
20758 enum ix86_special_builtin_type
20759 {
20760   SPECIAL_FTYPE_UNKNOWN,
20761   VOID_FTYPE_VOID,
20762   V32QI_FTYPE_PCCHAR,
20763   V16QI_FTYPE_PCCHAR,
20764   V8SF_FTYPE_PCV4SF,
20765   V8SF_FTYPE_PCFLOAT,
20766   V4DF_FTYPE_PCV2DF,
20767   V4DF_FTYPE_PCDOUBLE,
20768   V4SF_FTYPE_PCFLOAT,
20769   V2DF_FTYPE_PCDOUBLE,
20770   V8SF_FTYPE_PCV8SF_V8SF,
20771   V4DF_FTYPE_PCV4DF_V4DF,
20772   V4SF_FTYPE_V4SF_PCV2SF,
20773   V4SF_FTYPE_PCV4SF_V4SF,
20774   V2DF_FTYPE_V2DF_PCDOUBLE,
20775   V2DF_FTYPE_PCV2DF_V2DF,
20776   V2DI_FTYPE_PV2DI,
20777   VOID_FTYPE_PV2SF_V4SF,
20778   VOID_FTYPE_PV4DI_V4DI,
20779   VOID_FTYPE_PV2DI_V2DI,
20780   VOID_FTYPE_PCHAR_V32QI,
20781   VOID_FTYPE_PCHAR_V16QI,
20782   VOID_FTYPE_PFLOAT_V8SF,
20783   VOID_FTYPE_PFLOAT_V4SF,
20784   VOID_FTYPE_PDOUBLE_V4DF,
20785   VOID_FTYPE_PDOUBLE_V2DF,
20786   VOID_FTYPE_PDI_DI,
20787   VOID_FTYPE_PINT_INT,
20788   VOID_FTYPE_PV8SF_V8SF_V8SF,
20789   VOID_FTYPE_PV4DF_V4DF_V4DF,
20790   VOID_FTYPE_PV4SF_V4SF_V4SF,
20791   VOID_FTYPE_PV2DF_V2DF_V2DF
20792 };
20793
20794 /* Builtin types */
20795 enum ix86_builtin_type
20796 {
20797   FTYPE_UNKNOWN,
20798   FLOAT128_FTYPE_FLOAT128,
20799   FLOAT_FTYPE_FLOAT,
20800   FLOAT128_FTYPE_FLOAT128_FLOAT128,
20801   INT_FTYPE_V8SF_V8SF_PTEST,
20802   INT_FTYPE_V4DI_V4DI_PTEST,
20803   INT_FTYPE_V4DF_V4DF_PTEST,
20804   INT_FTYPE_V4SF_V4SF_PTEST,
20805   INT_FTYPE_V2DI_V2DI_PTEST,
20806   INT_FTYPE_V2DF_V2DF_PTEST,
20807   INT64_FTYPE_V4SF,
20808   INT64_FTYPE_V2DF,
20809   INT_FTYPE_V16QI,
20810   INT_FTYPE_V8QI,
20811   INT_FTYPE_V8SF,
20812   INT_FTYPE_V4DF,
20813   INT_FTYPE_V4SF,
20814   INT_FTYPE_V2DF,
20815   V16QI_FTYPE_V16QI,
20816   V8SI_FTYPE_V8SF,
20817   V8SI_FTYPE_V4SI,
20818   V8HI_FTYPE_V8HI,
20819   V8HI_FTYPE_V16QI,
20820   V8QI_FTYPE_V8QI,
20821   V8SF_FTYPE_V8SF,
20822   V8SF_FTYPE_V8SI,
20823   V8SF_FTYPE_V4SF,
20824   V4SI_FTYPE_V4SI,
20825   V4SI_FTYPE_V16QI,
20826   V4SI_FTYPE_V8SI,
20827   V4SI_FTYPE_V8HI,
20828   V4SI_FTYPE_V4DF,
20829   V4SI_FTYPE_V4SF,
20830   V4SI_FTYPE_V2DF,
20831   V4HI_FTYPE_V4HI,
20832   V4DF_FTYPE_V4DF,
20833   V4DF_FTYPE_V4SI,
20834   V4DF_FTYPE_V4SF,
20835   V4DF_FTYPE_V2DF,
20836   V4SF_FTYPE_V4DF,
20837   V4SF_FTYPE_V4SF,
20838   V4SF_FTYPE_V4SF_VEC_MERGE,
20839   V4SF_FTYPE_V8SF,
20840   V4SF_FTYPE_V4SI,
20841   V4SF_FTYPE_V2DF,
20842   V2DI_FTYPE_V2DI,
20843   V2DI_FTYPE_V16QI,
20844   V2DI_FTYPE_V8HI,
20845   V2DI_FTYPE_V4SI,
20846   V2DF_FTYPE_V2DF,
20847   V2DF_FTYPE_V2DF_VEC_MERGE,
20848   V2DF_FTYPE_V4SI,
20849   V2DF_FTYPE_V4DF,
20850   V2DF_FTYPE_V4SF,
20851   V2DF_FTYPE_V2SI,
20852   V2SI_FTYPE_V2SI,
20853   V2SI_FTYPE_V4SF,
20854   V2SI_FTYPE_V2SF,
20855   V2SI_FTYPE_V2DF,
20856   V2SF_FTYPE_V2SF,
20857   V2SF_FTYPE_V2SI,
20858   V16QI_FTYPE_V16QI_V16QI,
20859   V16QI_FTYPE_V8HI_V8HI,
20860   V8QI_FTYPE_V8QI_V8QI,
20861   V8QI_FTYPE_V4HI_V4HI,
20862   V8HI_FTYPE_V8HI_V8HI,
20863   V8HI_FTYPE_V8HI_V8HI_COUNT,
20864   V8HI_FTYPE_V16QI_V16QI,
20865   V8HI_FTYPE_V4SI_V4SI,
20866   V8HI_FTYPE_V8HI_SI_COUNT,
20867   V8SF_FTYPE_V8SF_V8SF,
20868   V8SF_FTYPE_V8SF_V8SI,
20869   V4SI_FTYPE_V4SI_V4SI,
20870   V4SI_FTYPE_V4SI_V4SI_COUNT,
20871   V4SI_FTYPE_V8HI_V8HI,
20872   V4SI_FTYPE_V4SF_V4SF,
20873   V4SI_FTYPE_V2DF_V2DF,
20874   V4SI_FTYPE_V4SI_SI_COUNT,
20875   V4HI_FTYPE_V4HI_V4HI,
20876   V4HI_FTYPE_V4HI_V4HI_COUNT,
20877   V4HI_FTYPE_V8QI_V8QI,
20878   V4HI_FTYPE_V2SI_V2SI,
20879   V4HI_FTYPE_V4HI_SI_COUNT,
20880   V4DF_FTYPE_V4DF_V4DF,
20881   V4DF_FTYPE_V4DF_V4DI,
20882   V4SF_FTYPE_V4SF_V4SF,
20883   V4SF_FTYPE_V4SF_V4SF_SWAP,
20884   V4SF_FTYPE_V4SF_V4SI,
20885   V4SF_FTYPE_V4SF_V2SI,
20886   V4SF_FTYPE_V4SF_V2DF,
20887   V4SF_FTYPE_V4SF_DI,
20888   V4SF_FTYPE_V4SF_SI,
20889   V2DI_FTYPE_V2DI_V2DI,
20890   V2DI_FTYPE_V2DI_V2DI_COUNT,
20891   V2DI_FTYPE_V16QI_V16QI,
20892   V2DI_FTYPE_V4SI_V4SI,
20893   V2DI_FTYPE_V2DI_V16QI,
20894   V2DI_FTYPE_V2DF_V2DF,
20895   V2DI_FTYPE_V2DI_SI_COUNT,
20896   V2SI_FTYPE_V2SI_V2SI,
20897   V2SI_FTYPE_V2SI_V2SI_COUNT,
20898   V2SI_FTYPE_V4HI_V4HI,
20899   V2SI_FTYPE_V2SF_V2SF,
20900   V2SI_FTYPE_V2SI_SI_COUNT,
20901   V2DF_FTYPE_V2DF_V2DF,
20902   V2DF_FTYPE_V2DF_V2DF_SWAP,
20903   V2DF_FTYPE_V2DF_V4SF,
20904   V2DF_FTYPE_V2DF_V2DI,
20905   V2DF_FTYPE_V2DF_DI,
20906   V2DF_FTYPE_V2DF_SI,
20907   V2SF_FTYPE_V2SF_V2SF,
20908   V1DI_FTYPE_V1DI_V1DI,
20909   V1DI_FTYPE_V1DI_V1DI_COUNT,
20910   V1DI_FTYPE_V8QI_V8QI,
20911   V1DI_FTYPE_V2SI_V2SI,
20912   V1DI_FTYPE_V1DI_SI_COUNT,
20913   UINT64_FTYPE_UINT64_UINT64,
20914   UINT_FTYPE_UINT_UINT,
20915   UINT_FTYPE_UINT_USHORT,
20916   UINT_FTYPE_UINT_UCHAR,
20917   V8HI_FTYPE_V8HI_INT,
20918   V4SI_FTYPE_V4SI_INT,
20919   V4HI_FTYPE_V4HI_INT,
20920   V8SF_FTYPE_V8SF_INT,
20921   V4SI_FTYPE_V8SI_INT,
20922   V4SF_FTYPE_V8SF_INT,
20923   V2DF_FTYPE_V4DF_INT,
20924   V4DF_FTYPE_V4DF_INT,
20925   V4SF_FTYPE_V4SF_INT,
20926   V2DI_FTYPE_V2DI_INT,
20927   V2DI2TI_FTYPE_V2DI_INT,
20928   V2DF_FTYPE_V2DF_INT,
20929   V16QI_FTYPE_V16QI_V16QI_V16QI,
20930   V8SF_FTYPE_V8SF_V8SF_V8SF,
20931   V4DF_FTYPE_V4DF_V4DF_V4DF,
20932   V4SF_FTYPE_V4SF_V4SF_V4SF,
20933   V2DF_FTYPE_V2DF_V2DF_V2DF,
20934   V16QI_FTYPE_V16QI_V16QI_INT,
20935   V8SI_FTYPE_V8SI_V8SI_INT,
20936   V8SI_FTYPE_V8SI_V4SI_INT,
20937   V8HI_FTYPE_V8HI_V8HI_INT,
20938   V8SF_FTYPE_V8SF_V8SF_INT,
20939   V8SF_FTYPE_V8SF_V4SF_INT,
20940   V4SI_FTYPE_V4SI_V4SI_INT,
20941   V4DF_FTYPE_V4DF_V4DF_INT,
20942   V4DF_FTYPE_V4DF_V2DF_INT,
20943   V4SF_FTYPE_V4SF_V4SF_INT,
20944   V2DI_FTYPE_V2DI_V2DI_INT,
20945   V2DI2TI_FTYPE_V2DI_V2DI_INT,
20946   V1DI2DI_FTYPE_V1DI_V1DI_INT,
20947   V2DF_FTYPE_V2DF_V2DF_INT,
20948   V2DI_FTYPE_V2DI_UINT_UINT,
20949   V2DI_FTYPE_V2DI_V2DI_UINT_UINT
20950 };
20951
20952 /* Special builtins with variable number of arguments.  */
20953 static const struct builtin_description bdesc_special_args[] =
20954 {
20955   /* MMX */
20956   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_emms, "__builtin_ia32_emms", IX86_BUILTIN_EMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
20957
20958   /* 3DNow! */
20959   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_femms, "__builtin_ia32_femms", IX86_BUILTIN_FEMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
20960
20961   /* SSE */
20962   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movups, "__builtin_ia32_storeups", IX86_BUILTIN_STOREUPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
20963   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movntv4sf, "__builtin_ia32_movntps", IX86_BUILTIN_MOVNTPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
20964   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movups, "__builtin_ia32_loadups", IX86_BUILTIN_LOADUPS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
20965
20966   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadhps_exp, "__builtin_ia32_loadhps", IX86_BUILTIN_LOADHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
20967   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadlps_exp, "__builtin_ia32_loadlps", IX86_BUILTIN_LOADLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
20968   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storehps, "__builtin_ia32_storehps", IX86_BUILTIN_STOREHPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
20969   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storelps, "__builtin_ia32_storelps", IX86_BUILTIN_STORELPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
20970
20971   /* SSE or 3DNow!A  */
20972   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_sse_sfence, "__builtin_ia32_sfence", IX86_BUILTIN_SFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
20973   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_sse_movntdi, "__builtin_ia32_movntq", IX86_BUILTIN_MOVNTQ, UNKNOWN, (int) VOID_FTYPE_PDI_DI },
20974
20975   /* SSE2 */
20976   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lfence, "__builtin_ia32_lfence", IX86_BUILTIN_LFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
20977   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_mfence, 0, IX86_BUILTIN_MFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
20978   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movupd, "__builtin_ia32_storeupd", IX86_BUILTIN_STOREUPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
20979   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movdqu, "__builtin_ia32_storedqu", IX86_BUILTIN_STOREDQU, UNKNOWN, (int) VOID_FTYPE_PCHAR_V16QI },
20980   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2df, "__builtin_ia32_movntpd", IX86_BUILTIN_MOVNTPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
20981   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2di, "__builtin_ia32_movntdq", IX86_BUILTIN_MOVNTDQ, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI },
20982   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntsi, "__builtin_ia32_movnti", IX86_BUILTIN_MOVNTI, UNKNOWN, (int) VOID_FTYPE_PINT_INT },
20983   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movupd, "__builtin_ia32_loadupd", IX86_BUILTIN_LOADUPD, UNKNOWN, (int) V2DF_FTYPE_PCDOUBLE },
20984   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movdqu, "__builtin_ia32_loaddqu", IX86_BUILTIN_LOADDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
20985
20986   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadhpd_exp, "__builtin_ia32_loadhpd", IX86_BUILTIN_LOADHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
20987   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadlpd_exp, "__builtin_ia32_loadlpd", IX86_BUILTIN_LOADLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
20988
20989   /* SSE3 */
20990   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_lddqu, "__builtin_ia32_lddqu", IX86_BUILTIN_LDDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
20991
20992   /* SSE4.1 */
20993   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_movntdqa, "__builtin_ia32_movntdqa", IX86_BUILTIN_MOVNTDQA, UNKNOWN, (int) V2DI_FTYPE_PV2DI },
20994
20995   /* SSE4A */
20996   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv2df, "__builtin_ia32_movntsd", IX86_BUILTIN_MOVNTSD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
20997   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv4sf, "__builtin_ia32_movntss", IX86_BUILTIN_MOVNTSS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
20998
20999   /* AVX */
21000   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vzeroall, "__builtin_ia32_vzeroall", IX86_BUILTIN_VZEROALL, UNKNOWN, (int) VOID_FTYPE_VOID },
21001   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vzeroupper, 0, IX86_BUILTIN_VZEROUPPER, UNKNOWN, (int) VOID_FTYPE_VOID },
21002   { OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_64BIT, CODE_FOR_avx_vzeroupper_rex64, 0, IX86_BUILTIN_VZEROUPPER_REX64, UNKNOWN, (int) VOID_FTYPE_VOID },
21003
21004   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastss, "__builtin_ia32_vbroadcastss", IX86_BUILTIN_VBROADCASTSS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
21005   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastsd256, "__builtin_ia32_vbroadcastsd256", IX86_BUILTIN_VBROADCASTSD256, UNKNOWN, (int) V4DF_FTYPE_PCDOUBLE },
21006   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastss256, "__builtin_ia32_vbroadcastss256", IX86_BUILTIN_VBROADCASTSS256, UNKNOWN, (int) V8SF_FTYPE_PCFLOAT },
21007   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastf128_pd256, "__builtin_ia32_vbroadcastf128_pd256", IX86_BUILTIN_VBROADCASTPD256, UNKNOWN, (int) V4DF_FTYPE_PCV2DF },
21008   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastf128_ps256, "__builtin_ia32_vbroadcastf128_ps256", IX86_BUILTIN_VBROADCASTPS256, UNKNOWN, (int) V8SF_FTYPE_PCV4SF },
21009
21010   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movupd256, "__builtin_ia32_loadupd256", IX86_BUILTIN_LOADUPD256, UNKNOWN, (int) V4DF_FTYPE_PCDOUBLE },
21011   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movups256, "__builtin_ia32_loadups256", IX86_BUILTIN_LOADUPS256, UNKNOWN, (int) V8SF_FTYPE_PCFLOAT },
21012   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movupd256, "__builtin_ia32_storeupd256", IX86_BUILTIN_STOREUPD256, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V4DF },
21013   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movups256, "__builtin_ia32_storeups256", IX86_BUILTIN_STOREUPS256, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V8SF },
21014   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movdqu256, "__builtin_ia32_loaddqu256", IX86_BUILTIN_LOADDQU256, UNKNOWN, (int) V32QI_FTYPE_PCCHAR },
21015   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movdqu256, "__builtin_ia32_storedqu256", IX86_BUILTIN_STOREDQU256, UNKNOWN, (int) VOID_FTYPE_PCHAR_V32QI },
21016   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_lddqu256, "__builtin_ia32_lddqu256", IX86_BUILTIN_LDDQU256, UNKNOWN, (int) V32QI_FTYPE_PCCHAR },
21017
21018   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv4di, "__builtin_ia32_movntdq256", IX86_BUILTIN_MOVNTDQ256, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI },
21019   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv4df, "__builtin_ia32_movntpd256", IX86_BUILTIN_MOVNTPD256, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V4DF },
21020   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv8sf, "__builtin_ia32_movntps256", IX86_BUILTIN_MOVNTPS256, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V8SF },
21021
21022   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadpd, "__builtin_ia32_maskloadpd", IX86_BUILTIN_MASKLOADPD, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DF },
21023   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadps, "__builtin_ia32_maskloadps", IX86_BUILTIN_MASKLOADPS, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SF },
21024   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadpd256, "__builtin_ia32_maskloadpd256", IX86_BUILTIN_MASKLOADPD256, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DF },
21025   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadps256, "__builtin_ia32_maskloadps256", IX86_BUILTIN_MASKLOADPS256, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SF },
21026   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstorepd, "__builtin_ia32_maskstorepd", IX86_BUILTIN_MASKSTOREPD, UNKNOWN, (int) VOID_FTYPE_PV2DF_V2DF_V2DF },
21027   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstoreps, "__builtin_ia32_maskstoreps", IX86_BUILTIN_MASKSTOREPS, UNKNOWN, (int) VOID_FTYPE_PV4SF_V4SF_V4SF },
21028   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstorepd256, "__builtin_ia32_maskstorepd256", IX86_BUILTIN_MASKSTOREPD256, UNKNOWN, (int) VOID_FTYPE_PV4DF_V4DF_V4DF },
21029   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstoreps256, "__builtin_ia32_maskstoreps256", IX86_BUILTIN_MASKSTOREPS256, UNKNOWN, (int) VOID_FTYPE_PV8SF_V8SF_V8SF },
21030 };
21031
21032 /* Builtins with variable number of arguments.  */
21033 static const struct builtin_description bdesc_args[] =
21034 {
21035   /* MMX */
21036   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv8qi3, "__builtin_ia32_paddb", IX86_BUILTIN_PADDB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21037   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv4hi3, "__builtin_ia32_paddw", IX86_BUILTIN_PADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21038   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv2si3, "__builtin_ia32_paddd", IX86_BUILTIN_PADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21039   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv8qi3, "__builtin_ia32_psubb", IX86_BUILTIN_PSUBB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21040   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv4hi3, "__builtin_ia32_psubw", IX86_BUILTIN_PSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21041   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv2si3, "__builtin_ia32_psubd", IX86_BUILTIN_PSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21042
21043   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv8qi3, "__builtin_ia32_paddsb", IX86_BUILTIN_PADDSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21044   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv4hi3, "__builtin_ia32_paddsw", IX86_BUILTIN_PADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21045   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv8qi3, "__builtin_ia32_psubsb", IX86_BUILTIN_PSUBSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21046   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv4hi3, "__builtin_ia32_psubsw", IX86_BUILTIN_PSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21047   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv8qi3, "__builtin_ia32_paddusb", IX86_BUILTIN_PADDUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21048   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv4hi3, "__builtin_ia32_paddusw", IX86_BUILTIN_PADDUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21049   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv8qi3, "__builtin_ia32_psubusb", IX86_BUILTIN_PSUBUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21050   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv4hi3, "__builtin_ia32_psubusw", IX86_BUILTIN_PSUBUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21051
21052   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_mulv4hi3, "__builtin_ia32_pmullw", IX86_BUILTIN_PMULLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21053   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_smulv4hi3_highpart, "__builtin_ia32_pmulhw", IX86_BUILTIN_PMULHW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21054
21055   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_andv2si3, "__builtin_ia32_pand", IX86_BUILTIN_PAND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21056   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_andnotv2si3, "__builtin_ia32_pandn", IX86_BUILTIN_PANDN, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21057   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_iorv2si3, "__builtin_ia32_por", IX86_BUILTIN_POR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21058   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_xorv2si3, "__builtin_ia32_pxor", IX86_BUILTIN_PXOR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21059
21060   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv8qi3, "__builtin_ia32_pcmpeqb", IX86_BUILTIN_PCMPEQB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21061   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv4hi3, "__builtin_ia32_pcmpeqw", IX86_BUILTIN_PCMPEQW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21062   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv2si3, "__builtin_ia32_pcmpeqd", IX86_BUILTIN_PCMPEQD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21063   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv8qi3, "__builtin_ia32_pcmpgtb", IX86_BUILTIN_PCMPGTB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21064   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv4hi3, "__builtin_ia32_pcmpgtw", IX86_BUILTIN_PCMPGTW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21065   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv2si3, "__builtin_ia32_pcmpgtd", IX86_BUILTIN_PCMPGTD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21066
21067   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhbw, "__builtin_ia32_punpckhbw", IX86_BUILTIN_PUNPCKHBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21068   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhwd, "__builtin_ia32_punpckhwd", IX86_BUILTIN_PUNPCKHWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21069   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhdq, "__builtin_ia32_punpckhdq", IX86_BUILTIN_PUNPCKHDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21070   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklbw, "__builtin_ia32_punpcklbw", IX86_BUILTIN_PUNPCKLBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21071   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklwd, "__builtin_ia32_punpcklwd", IX86_BUILTIN_PUNPCKLWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI},
21072   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckldq, "__builtin_ia32_punpckldq", IX86_BUILTIN_PUNPCKLDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI},
21073
21074   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packsswb, "__builtin_ia32_packsswb", IX86_BUILTIN_PACKSSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
21075   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packssdw, "__builtin_ia32_packssdw", IX86_BUILTIN_PACKSSDW, UNKNOWN, (int) V4HI_FTYPE_V2SI_V2SI },
21076   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packuswb, "__builtin_ia32_packuswb", IX86_BUILTIN_PACKUSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
21077
21078   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_pmaddwd, "__builtin_ia32_pmaddwd", IX86_BUILTIN_PMADDWD, UNKNOWN, (int) V2SI_FTYPE_V4HI_V4HI },
21079
21080   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllwi", IX86_BUILTIN_PSLLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
21081   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslldi", IX86_BUILTIN_PSLLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
21082   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllqi", IX86_BUILTIN_PSLLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
21083   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllw", IX86_BUILTIN_PSLLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
21084   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslld", IX86_BUILTIN_PSLLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
21085   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllq", IX86_BUILTIN_PSLLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
21086
21087   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlwi", IX86_BUILTIN_PSRLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
21088   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrldi", IX86_BUILTIN_PSRLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
21089   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlqi", IX86_BUILTIN_PSRLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
21090   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlw", IX86_BUILTIN_PSRLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
21091   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrld", IX86_BUILTIN_PSRLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
21092   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlq", IX86_BUILTIN_PSRLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
21093
21094   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psrawi", IX86_BUILTIN_PSRAWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
21095   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psradi", IX86_BUILTIN_PSRADI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
21096   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psraw", IX86_BUILTIN_PSRAW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
21097   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psrad", IX86_BUILTIN_PSRAD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
21098
21099   /* 3DNow! */
21100   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pf2id, "__builtin_ia32_pf2id", IX86_BUILTIN_PF2ID, UNKNOWN, (int) V2SI_FTYPE_V2SF },
21101   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_floatv2si2, "__builtin_ia32_pi2fd", IX86_BUILTIN_PI2FD, UNKNOWN, (int) V2SF_FTYPE_V2SI },
21102   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpv2sf2, "__builtin_ia32_pfrcp", IX86_BUILTIN_PFRCP, UNKNOWN, (int) V2SF_FTYPE_V2SF },
21103   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqrtv2sf2, "__builtin_ia32_pfrsqrt", IX86_BUILTIN_PFRSQRT, UNKNOWN, (int) V2SF_FTYPE_V2SF },
21104
21105   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_uavgv8qi3, "__builtin_ia32_pavgusb", IX86_BUILTIN_PAVGUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21106   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_haddv2sf3, "__builtin_ia32_pfacc", IX86_BUILTIN_PFACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21107   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_addv2sf3, "__builtin_ia32_pfadd", IX86_BUILTIN_PFADD, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21108   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_eqv2sf3, "__builtin_ia32_pfcmpeq", IX86_BUILTIN_PFCMPEQ, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
21109   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gev2sf3, "__builtin_ia32_pfcmpge", IX86_BUILTIN_PFCMPGE, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
21110   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gtv2sf3, "__builtin_ia32_pfcmpgt", IX86_BUILTIN_PFCMPGT, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
21111   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_smaxv2sf3, "__builtin_ia32_pfmax", IX86_BUILTIN_PFMAX, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21112   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_sminv2sf3, "__builtin_ia32_pfmin", IX86_BUILTIN_PFMIN, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21113   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_mulv2sf3, "__builtin_ia32_pfmul", IX86_BUILTIN_PFMUL, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21114   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit1v2sf3, "__builtin_ia32_pfrcpit1", IX86_BUILTIN_PFRCPIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21115   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit2v2sf3, "__builtin_ia32_pfrcpit2", IX86_BUILTIN_PFRCPIT2, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21116   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqit1v2sf3, "__builtin_ia32_pfrsqit1", IX86_BUILTIN_PFRSQIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21117   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subv2sf3, "__builtin_ia32_pfsub", IX86_BUILTIN_PFSUB, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21118   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subrv2sf3, "__builtin_ia32_pfsubr", IX86_BUILTIN_PFSUBR, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21119   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pmulhrwv4hi3, "__builtin_ia32_pmulhrw", IX86_BUILTIN_PMULHRW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21120
21121   /* 3DNow!A */
21122   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pf2iw, "__builtin_ia32_pf2iw", IX86_BUILTIN_PF2IW, UNKNOWN, (int) V2SI_FTYPE_V2SF },
21123   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pi2fw, "__builtin_ia32_pi2fw", IX86_BUILTIN_PI2FW, UNKNOWN, (int) V2SF_FTYPE_V2SI },
21124   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2si2, "__builtin_ia32_pswapdsi", IX86_BUILTIN_PSWAPDSI, UNKNOWN, (int) V2SI_FTYPE_V2SI },
21125   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2sf2, "__builtin_ia32_pswapdsf", IX86_BUILTIN_PSWAPDSF, UNKNOWN, (int) V2SF_FTYPE_V2SF },
21126   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_hsubv2sf3, "__builtin_ia32_pfnacc", IX86_BUILTIN_PFNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21127   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_addsubv2sf3, "__builtin_ia32_pfpnacc", IX86_BUILTIN_PFPNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
21128
21129   /* SSE */
21130   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movmskps, "__builtin_ia32_movmskps", IX86_BUILTIN_MOVMSKPS, UNKNOWN, (int) INT_FTYPE_V4SF },
21131   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_sqrtv4sf2, "__builtin_ia32_sqrtps", IX86_BUILTIN_SQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
21132   { OPTION_MASK_ISA_SSE, CODE_FOR_sqrtv4sf2, "__builtin_ia32_sqrtps_nr", IX86_BUILTIN_SQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
21133   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rsqrtv4sf2, "__builtin_ia32_rsqrtps", IX86_BUILTIN_RSQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
21134   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtv4sf2, "__builtin_ia32_rsqrtps_nr", IX86_BUILTIN_RSQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
21135   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rcpv4sf2, "__builtin_ia32_rcpps", IX86_BUILTIN_RCPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
21136   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtps2pi, "__builtin_ia32_cvtps2pi", IX86_BUILTIN_CVTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
21137   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtss2si, "__builtin_ia32_cvtss2si", IX86_BUILTIN_CVTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
21138   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtss2siq, "__builtin_ia32_cvtss2si64", IX86_BUILTIN_CVTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
21139   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttps2pi, "__builtin_ia32_cvttps2pi", IX86_BUILTIN_CVTTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
21140   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttss2si, "__builtin_ia32_cvttss2si", IX86_BUILTIN_CVTTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
21141   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvttss2siq, "__builtin_ia32_cvttss2si64", IX86_BUILTIN_CVTTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
21142
21143   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_shufps, "__builtin_ia32_shufps", IX86_BUILTIN_SHUFPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21144
21145   { OPTION_MASK_ISA_SSE, CODE_FOR_addv4sf3, "__builtin_ia32_addps", IX86_BUILTIN_ADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21146   { OPTION_MASK_ISA_SSE, CODE_FOR_subv4sf3, "__builtin_ia32_subps", IX86_BUILTIN_SUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21147   { OPTION_MASK_ISA_SSE, CODE_FOR_mulv4sf3, "__builtin_ia32_mulps", IX86_BUILTIN_MULPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21148   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_divv4sf3, "__builtin_ia32_divps", IX86_BUILTIN_DIVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21149   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmaddv4sf3,  "__builtin_ia32_addss", IX86_BUILTIN_ADDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21150   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsubv4sf3,  "__builtin_ia32_subss", IX86_BUILTIN_SUBSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21151   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmulv4sf3,  "__builtin_ia32_mulss", IX86_BUILTIN_MULSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21152   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmdivv4sf3,  "__builtin_ia32_divss", IX86_BUILTIN_DIVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21153
21154   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpeqps", IX86_BUILTIN_CMPEQPS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
21155   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpltps", IX86_BUILTIN_CMPLTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
21156   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpleps", IX86_BUILTIN_CMPLEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
21157   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgtps", IX86_BUILTIN_CMPGTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
21158   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgeps", IX86_BUILTIN_CMPGEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
21159   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpunordps", IX86_BUILTIN_CMPUNORDPS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
21160   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpneqps", IX86_BUILTIN_CMPNEQPS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
21161   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnltps", IX86_BUILTIN_CMPNLTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
21162   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnleps", IX86_BUILTIN_CMPNLEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
21163   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngtps", IX86_BUILTIN_CMPNGTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
21164   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngeps", IX86_BUILTIN_CMPNGEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP},
21165   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpordps", IX86_BUILTIN_CMPORDPS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
21166   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpeqss", IX86_BUILTIN_CMPEQSS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
21167   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpltss", IX86_BUILTIN_CMPLTSS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
21168   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpless", IX86_BUILTIN_CMPLESS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
21169   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpunordss", IX86_BUILTIN_CMPUNORDSS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
21170   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpneqss", IX86_BUILTIN_CMPNEQSS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
21171   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnltss", IX86_BUILTIN_CMPNLTSS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
21172   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnless", IX86_BUILTIN_CMPNLESS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
21173   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpngtss", IX86_BUILTIN_CMPNGTSS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
21174   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpngess", IX86_BUILTIN_CMPNGESS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
21175   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpordss", IX86_BUILTIN_CMPORDSS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
21176
21177   { OPTION_MASK_ISA_SSE, CODE_FOR_sminv4sf3, "__builtin_ia32_minps", IX86_BUILTIN_MINPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21178   { OPTION_MASK_ISA_SSE, CODE_FOR_smaxv4sf3, "__builtin_ia32_maxps", IX86_BUILTIN_MAXPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21179   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsminv4sf3, "__builtin_ia32_minss", IX86_BUILTIN_MINSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21180   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsmaxv4sf3, "__builtin_ia32_maxss", IX86_BUILTIN_MAXSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21181
21182   { OPTION_MASK_ISA_SSE, CODE_FOR_andv4sf3, "__builtin_ia32_andps", IX86_BUILTIN_ANDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21183   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_andnotv4sf3,  "__builtin_ia32_andnps", IX86_BUILTIN_ANDNPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21184   { OPTION_MASK_ISA_SSE, CODE_FOR_iorv4sf3, "__builtin_ia32_orps", IX86_BUILTIN_ORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21185   { OPTION_MASK_ISA_SSE, CODE_FOR_xorv4sf3,  "__builtin_ia32_xorps", IX86_BUILTIN_XORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21186
21187   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movss,  "__builtin_ia32_movss", IX86_BUILTIN_MOVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21188   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movhlps_exp,  "__builtin_ia32_movhlps", IX86_BUILTIN_MOVHLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21189   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movlhps_exp,  "__builtin_ia32_movlhps", IX86_BUILTIN_MOVLHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21190   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_unpckhps, "__builtin_ia32_unpckhps", IX86_BUILTIN_UNPCKHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21191   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_unpcklps, "__builtin_ia32_unpcklps", IX86_BUILTIN_UNPCKLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21192
21193   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtpi2ps, "__builtin_ia32_cvtpi2ps", IX86_BUILTIN_CVTPI2PS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2SI },
21194   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtsi2ss, "__builtin_ia32_cvtsi2ss", IX86_BUILTIN_CVTSI2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_SI },
21195   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtsi2ssq, "__builtin_ia32_cvtsi642ss", IX86_BUILTIN_CVTSI642SS, UNKNOWN, V4SF_FTYPE_V4SF_DI },
21196
21197   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtsf2, "__builtin_ia32_rsqrtf", IX86_BUILTIN_RSQRTF, UNKNOWN, (int) FLOAT_FTYPE_FLOAT },
21198
21199   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsqrtv4sf2, "__builtin_ia32_sqrtss", IX86_BUILTIN_SQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
21200   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrsqrtv4sf2, "__builtin_ia32_rsqrtss", IX86_BUILTIN_RSQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
21201   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrcpv4sf2, "__builtin_ia32_rcpss", IX86_BUILTIN_RCPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
21202
21203   /* SSE MMX or 3Dnow!A */
21204   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_uavgv8qi3, "__builtin_ia32_pavgb", IX86_BUILTIN_PAVGB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21205   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_uavgv4hi3, "__builtin_ia32_pavgw", IX86_BUILTIN_PAVGW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21206   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_umulv4hi3_highpart, "__builtin_ia32_pmulhuw", IX86_BUILTIN_PMULHUW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21207
21208   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_umaxv8qi3, "__builtin_ia32_pmaxub", IX86_BUILTIN_PMAXUB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21209   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_smaxv4hi3, "__builtin_ia32_pmaxsw", IX86_BUILTIN_PMAXSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21210   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_uminv8qi3, "__builtin_ia32_pminub", IX86_BUILTIN_PMINUB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21211   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_sminv4hi3, "__builtin_ia32_pminsw", IX86_BUILTIN_PMINSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21212
21213   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_psadbw, "__builtin_ia32_psadbw", IX86_BUILTIN_PSADBW, UNKNOWN, (int) V1DI_FTYPE_V8QI_V8QI },
21214   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pmovmskb, "__builtin_ia32_pmovmskb", IX86_BUILTIN_PMOVMSKB, UNKNOWN, (int) INT_FTYPE_V8QI },
21215
21216   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pshufw, "__builtin_ia32_pshufw", IX86_BUILTIN_PSHUFW, UNKNOWN, (int) V4HI_FTYPE_V4HI_INT },
21217
21218   /* SSE2 */
21219   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_shufpd, "__builtin_ia32_shufpd", IX86_BUILTIN_SHUFPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21220
21221   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movmskpd, "__builtin_ia32_movmskpd", IX86_BUILTIN_MOVMSKPD, UNKNOWN, (int) INT_FTYPE_V2DF  },
21222   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmovmskb, "__builtin_ia32_pmovmskb128", IX86_BUILTIN_PMOVMSKB128, UNKNOWN, (int) INT_FTYPE_V16QI },
21223   { OPTION_MASK_ISA_SSE2, CODE_FOR_sqrtv2df2, "__builtin_ia32_sqrtpd", IX86_BUILTIN_SQRTPD, UNKNOWN, (int) V2DF_FTYPE_V2DF },
21224   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2pd, "__builtin_ia32_cvtdq2pd", IX86_BUILTIN_CVTDQ2PD, UNKNOWN, (int) V2DF_FTYPE_V4SI },
21225   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2ps, "__builtin_ia32_cvtdq2ps", IX86_BUILTIN_CVTDQ2PS, UNKNOWN, (int) V4SF_FTYPE_V4SI },
21226
21227   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2dq, "__builtin_ia32_cvtpd2dq", IX86_BUILTIN_CVTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
21228   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2pi, "__builtin_ia32_cvtpd2pi", IX86_BUILTIN_CVTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
21229   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2ps, "__builtin_ia32_cvtpd2ps", IX86_BUILTIN_CVTPD2PS, UNKNOWN, (int) V4SF_FTYPE_V2DF },
21230   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2dq, "__builtin_ia32_cvttpd2dq", IX86_BUILTIN_CVTTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
21231   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2pi, "__builtin_ia32_cvttpd2pi", IX86_BUILTIN_CVTTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
21232
21233   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpi2pd, "__builtin_ia32_cvtpi2pd", IX86_BUILTIN_CVTPI2PD, UNKNOWN, (int) V2DF_FTYPE_V2SI },
21234
21235   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2si, "__builtin_ia32_cvtsd2si", IX86_BUILTIN_CVTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
21236   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttsd2si, "__builtin_ia32_cvttsd2si", IX86_BUILTIN_CVTTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
21237   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsd2siq, "__builtin_ia32_cvtsd2si64", IX86_BUILTIN_CVTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
21238   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvttsd2siq, "__builtin_ia32_cvttsd2si64", IX86_BUILTIN_CVTTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
21239
21240   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2dq, "__builtin_ia32_cvtps2dq", IX86_BUILTIN_CVTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
21241   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2pd, "__builtin_ia32_cvtps2pd", IX86_BUILTIN_CVTPS2PD, UNKNOWN, (int) V2DF_FTYPE_V4SF },
21242   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttps2dq, "__builtin_ia32_cvttps2dq", IX86_BUILTIN_CVTTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
21243
21244   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2df3, "__builtin_ia32_addpd", IX86_BUILTIN_ADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21245   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2df3, "__builtin_ia32_subpd", IX86_BUILTIN_SUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21246   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv2df3, "__builtin_ia32_mulpd", IX86_BUILTIN_MULPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21247   { OPTION_MASK_ISA_SSE2, CODE_FOR_divv2df3, "__builtin_ia32_divpd", IX86_BUILTIN_DIVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21248   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmaddv2df3,  "__builtin_ia32_addsd", IX86_BUILTIN_ADDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21249   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsubv2df3,  "__builtin_ia32_subsd", IX86_BUILTIN_SUBSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21250   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmulv2df3,  "__builtin_ia32_mulsd", IX86_BUILTIN_MULSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21251   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmdivv2df3,  "__builtin_ia32_divsd", IX86_BUILTIN_DIVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21252
21253   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpeqpd", IX86_BUILTIN_CMPEQPD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
21254   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpltpd", IX86_BUILTIN_CMPLTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
21255   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmplepd", IX86_BUILTIN_CMPLEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
21256   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgtpd", IX86_BUILTIN_CMPGTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
21257   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgepd", IX86_BUILTIN_CMPGEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP},
21258   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpunordpd", IX86_BUILTIN_CMPUNORDPD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
21259   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpneqpd", IX86_BUILTIN_CMPNEQPD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
21260   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnltpd", IX86_BUILTIN_CMPNLTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
21261   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnlepd", IX86_BUILTIN_CMPNLEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
21262   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngtpd", IX86_BUILTIN_CMPNGTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
21263   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngepd", IX86_BUILTIN_CMPNGEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
21264   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpordpd", IX86_BUILTIN_CMPORDPD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
21265   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpeqsd", IX86_BUILTIN_CMPEQSD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
21266   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpltsd", IX86_BUILTIN_CMPLTSD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
21267   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmplesd", IX86_BUILTIN_CMPLESD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
21268   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpunordsd", IX86_BUILTIN_CMPUNORDSD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
21269   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpneqsd", IX86_BUILTIN_CMPNEQSD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
21270   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnltsd", IX86_BUILTIN_CMPNLTSD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
21271   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnlesd", IX86_BUILTIN_CMPNLESD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
21272   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpordsd", IX86_BUILTIN_CMPORDSD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
21273
21274   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv2df3, "__builtin_ia32_minpd", IX86_BUILTIN_MINPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21275   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv2df3, "__builtin_ia32_maxpd", IX86_BUILTIN_MAXPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21276   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsminv2df3, "__builtin_ia32_minsd", IX86_BUILTIN_MINSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21277   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsmaxv2df3, "__builtin_ia32_maxsd", IX86_BUILTIN_MAXSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21278
21279   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2df3, "__builtin_ia32_andpd", IX86_BUILTIN_ANDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21280   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_andnotv2df3,  "__builtin_ia32_andnpd", IX86_BUILTIN_ANDNPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21281   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2df3, "__builtin_ia32_orpd", IX86_BUILTIN_ORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21282   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2df3,  "__builtin_ia32_xorpd", IX86_BUILTIN_XORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21283
21284   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movsd,  "__builtin_ia32_movsd", IX86_BUILTIN_MOVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21285   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_unpckhpd_exp, "__builtin_ia32_unpckhpd", IX86_BUILTIN_UNPCKHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21286   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_unpcklpd_exp, "__builtin_ia32_unpcklpd", IX86_BUILTIN_UNPCKLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21287
21288   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_pack_sfix_v2df, "__builtin_ia32_vec_pack_sfix", IX86_BUILTIN_VEC_PACK_SFIX, UNKNOWN, (int) V4SI_FTYPE_V2DF_V2DF },
21289
21290   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv16qi3, "__builtin_ia32_paddb128", IX86_BUILTIN_PADDB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21291   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv8hi3, "__builtin_ia32_paddw128", IX86_BUILTIN_PADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21292   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv4si3, "__builtin_ia32_paddd128", IX86_BUILTIN_PADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21293   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2di3, "__builtin_ia32_paddq128", IX86_BUILTIN_PADDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21294   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv16qi3, "__builtin_ia32_psubb128", IX86_BUILTIN_PSUBB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21295   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv8hi3, "__builtin_ia32_psubw128", IX86_BUILTIN_PSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21296   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv4si3, "__builtin_ia32_psubd128", IX86_BUILTIN_PSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21297   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2di3, "__builtin_ia32_psubq128", IX86_BUILTIN_PSUBQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21298
21299   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv16qi3, "__builtin_ia32_paddsb128", IX86_BUILTIN_PADDSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21300   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv8hi3, "__builtin_ia32_paddsw128", IX86_BUILTIN_PADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21301   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv16qi3, "__builtin_ia32_psubsb128", IX86_BUILTIN_PSUBSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21302   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv8hi3, "__builtin_ia32_psubsw128", IX86_BUILTIN_PSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21303   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv16qi3, "__builtin_ia32_paddusb128", IX86_BUILTIN_PADDUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21304   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv8hi3, "__builtin_ia32_paddusw128", IX86_BUILTIN_PADDUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21305   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv16qi3, "__builtin_ia32_psubusb128", IX86_BUILTIN_PSUBUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21306   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv8hi3, "__builtin_ia32_psubusw128", IX86_BUILTIN_PSUBUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21307
21308   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv8hi3, "__builtin_ia32_pmullw128", IX86_BUILTIN_PMULLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21309   { OPTION_MASK_ISA_SSE2, CODE_FOR_smulv8hi3_highpart, "__builtin_ia32_pmulhw128", IX86_BUILTIN_PMULHW128, UNKNOWN,(int) V8HI_FTYPE_V8HI_V8HI },
21310
21311   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2di3, "__builtin_ia32_pand128", IX86_BUILTIN_PAND128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21312   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_andnotv2di3, "__builtin_ia32_pandn128", IX86_BUILTIN_PANDN128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21313   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2di3, "__builtin_ia32_por128", IX86_BUILTIN_POR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21314   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2di3, "__builtin_ia32_pxor128", IX86_BUILTIN_PXOR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21315
21316   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv16qi3, "__builtin_ia32_pavgb128", IX86_BUILTIN_PAVGB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21317   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv8hi3, "__builtin_ia32_pavgw128", IX86_BUILTIN_PAVGW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21318
21319   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv16qi3, "__builtin_ia32_pcmpeqb128", IX86_BUILTIN_PCMPEQB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21320   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv8hi3, "__builtin_ia32_pcmpeqw128", IX86_BUILTIN_PCMPEQW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21321   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv4si3, "__builtin_ia32_pcmpeqd128", IX86_BUILTIN_PCMPEQD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
21322   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv16qi3, "__builtin_ia32_pcmpgtb128", IX86_BUILTIN_PCMPGTB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21323   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv8hi3, "__builtin_ia32_pcmpgtw128", IX86_BUILTIN_PCMPGTW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21324   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv4si3, "__builtin_ia32_pcmpgtd128", IX86_BUILTIN_PCMPGTD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
21325
21326   { OPTION_MASK_ISA_SSE2, CODE_FOR_umaxv16qi3, "__builtin_ia32_pmaxub128", IX86_BUILTIN_PMAXUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21327   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv8hi3, "__builtin_ia32_pmaxsw128", IX86_BUILTIN_PMAXSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21328   { OPTION_MASK_ISA_SSE2, CODE_FOR_uminv16qi3, "__builtin_ia32_pminub128", IX86_BUILTIN_PMINUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21329   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv8hi3, "__builtin_ia32_pminsw128", IX86_BUILTIN_PMINSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21330
21331   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhbw, "__builtin_ia32_punpckhbw128", IX86_BUILTIN_PUNPCKHBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21332   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhwd, "__builtin_ia32_punpckhwd128", IX86_BUILTIN_PUNPCKHWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI  },
21333   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhdq, "__builtin_ia32_punpckhdq128", IX86_BUILTIN_PUNPCKHDQ128, UNKNOWN,  (int) V4SI_FTYPE_V4SI_V4SI },
21334   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhqdq, "__builtin_ia32_punpckhqdq128", IX86_BUILTIN_PUNPCKHQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21335   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklbw, "__builtin_ia32_punpcklbw128", IX86_BUILTIN_PUNPCKLBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21336   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklwd, "__builtin_ia32_punpcklwd128", IX86_BUILTIN_PUNPCKLWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21337   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckldq, "__builtin_ia32_punpckldq128", IX86_BUILTIN_PUNPCKLDQ128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21338   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklqdq, "__builtin_ia32_punpcklqdq128", IX86_BUILTIN_PUNPCKLQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21339
21340   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packsswb, "__builtin_ia32_packsswb128", IX86_BUILTIN_PACKSSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
21341   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packssdw, "__builtin_ia32_packssdw128", IX86_BUILTIN_PACKSSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
21342   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packuswb, "__builtin_ia32_packuswb128", IX86_BUILTIN_PACKUSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
21343
21344   { OPTION_MASK_ISA_SSE2, CODE_FOR_umulv8hi3_highpart, "__builtin_ia32_pmulhuw128", IX86_BUILTIN_PMULHUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21345   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_psadbw, "__builtin_ia32_psadbw128", IX86_BUILTIN_PSADBW128, UNKNOWN, (int) V2DI_FTYPE_V16QI_V16QI },
21346
21347   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulv1siv1di3, "__builtin_ia32_pmuludq", IX86_BUILTIN_PMULUDQ, UNKNOWN, (int) V1DI_FTYPE_V2SI_V2SI },
21348   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulv2siv2di3, "__builtin_ia32_pmuludq128", IX86_BUILTIN_PMULUDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
21349
21350   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmaddwd, "__builtin_ia32_pmaddwd128", IX86_BUILTIN_PMADDWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI_V8HI },
21351
21352   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsi2sd, "__builtin_ia32_cvtsi2sd", IX86_BUILTIN_CVTSI2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_SI },
21353   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsi2sdq, "__builtin_ia32_cvtsi642sd", IX86_BUILTIN_CVTSI642SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_DI },
21354   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2ss, "__builtin_ia32_cvtsd2ss", IX86_BUILTIN_CVTSD2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2DF },
21355   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtss2sd, "__builtin_ia32_cvtss2sd", IX86_BUILTIN_CVTSS2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V4SF },
21356
21357   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ashlti3, "__builtin_ia32_pslldqi128", IX86_BUILTIN_PSLLDQI128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_INT },
21358   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllwi128", IX86_BUILTIN_PSLLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
21359   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslldi128", IX86_BUILTIN_PSLLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
21360   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllqi128", IX86_BUILTIN_PSLLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
21361   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllw128", IX86_BUILTIN_PSLLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
21362   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslld128", IX86_BUILTIN_PSLLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
21363   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllq128", IX86_BUILTIN_PSLLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
21364
21365   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lshrti3, "__builtin_ia32_psrldqi128", IX86_BUILTIN_PSRLDQI128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_INT },
21366   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlwi128", IX86_BUILTIN_PSRLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
21367   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrldi128", IX86_BUILTIN_PSRLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
21368   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlqi128", IX86_BUILTIN_PSRLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
21369   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlw128", IX86_BUILTIN_PSRLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
21370   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrld128", IX86_BUILTIN_PSRLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
21371   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlq128", IX86_BUILTIN_PSRLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
21372
21373   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psrawi128", IX86_BUILTIN_PSRAWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
21374   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psradi128", IX86_BUILTIN_PSRADI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
21375   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psraw128", IX86_BUILTIN_PSRAW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
21376   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psrad128", IX86_BUILTIN_PSRAD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
21377
21378   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufd, "__builtin_ia32_pshufd", IX86_BUILTIN_PSHUFD, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT },
21379   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshuflw, "__builtin_ia32_pshuflw", IX86_BUILTIN_PSHUFLW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
21380   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufhw, "__builtin_ia32_pshufhw", IX86_BUILTIN_PSHUFHW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
21381
21382   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsqrtv2df2, "__builtin_ia32_sqrtsd", IX86_BUILTIN_SQRTSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_VEC_MERGE },
21383
21384   { OPTION_MASK_ISA_SSE2, CODE_FOR_abstf2, 0, IX86_BUILTIN_FABSQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128 },
21385   { OPTION_MASK_ISA_SSE2, CODE_FOR_copysigntf3, 0, IX86_BUILTIN_COPYSIGNQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128_FLOAT128 },
21386
21387   { OPTION_MASK_ISA_SSE, CODE_FOR_sse2_movq128, "__builtin_ia32_movq128", IX86_BUILTIN_MOVQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
21388
21389   /* SSE2 MMX */
21390   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_addv1di3, "__builtin_ia32_paddq", IX86_BUILTIN_PADDQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
21391   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_subv1di3, "__builtin_ia32_psubq", IX86_BUILTIN_PSUBQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
21392
21393   /* SSE3 */
21394   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movshdup, "__builtin_ia32_movshdup", IX86_BUILTIN_MOVSHDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF},
21395   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movsldup, "__builtin_ia32_movsldup", IX86_BUILTIN_MOVSLDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF },
21396
21397   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv4sf3, "__builtin_ia32_addsubps", IX86_BUILTIN_ADDSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21398   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv2df3, "__builtin_ia32_addsubpd", IX86_BUILTIN_ADDSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21399   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv4sf3, "__builtin_ia32_haddps", IX86_BUILTIN_HADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21400   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv2df3, "__builtin_ia32_haddpd", IX86_BUILTIN_HADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21401   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv4sf3, "__builtin_ia32_hsubps", IX86_BUILTIN_HSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21402   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv2df3, "__builtin_ia32_hsubpd", IX86_BUILTIN_HSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21403
21404   /* SSSE3 */
21405   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv16qi2, "__builtin_ia32_pabsb128", IX86_BUILTIN_PABSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI },
21406   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8qi2, "__builtin_ia32_pabsb", IX86_BUILTIN_PABSB, UNKNOWN, (int) V8QI_FTYPE_V8QI },
21407   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8hi2, "__builtin_ia32_pabsw128", IX86_BUILTIN_PABSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
21408   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4hi2, "__builtin_ia32_pabsw", IX86_BUILTIN_PABSW, UNKNOWN, (int) V4HI_FTYPE_V4HI },
21409   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4si2, "__builtin_ia32_pabsd128", IX86_BUILTIN_PABSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI },
21410   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv2si2, "__builtin_ia32_pabsd", IX86_BUILTIN_PABSD, UNKNOWN, (int) V2SI_FTYPE_V2SI },
21411
21412   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv8hi3, "__builtin_ia32_phaddw128", IX86_BUILTIN_PHADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21413   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv4hi3, "__builtin_ia32_phaddw", IX86_BUILTIN_PHADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21414   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv4si3, "__builtin_ia32_phaddd128", IX86_BUILTIN_PHADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21415   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv2si3, "__builtin_ia32_phaddd", IX86_BUILTIN_PHADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21416   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv8hi3, "__builtin_ia32_phaddsw128", IX86_BUILTIN_PHADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21417   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv4hi3, "__builtin_ia32_phaddsw", IX86_BUILTIN_PHADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21418   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv8hi3, "__builtin_ia32_phsubw128", IX86_BUILTIN_PHSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21419   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv4hi3, "__builtin_ia32_phsubw", IX86_BUILTIN_PHSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21420   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv4si3, "__builtin_ia32_phsubd128", IX86_BUILTIN_PHSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21421   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv2si3, "__builtin_ia32_phsubd", IX86_BUILTIN_PHSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21422   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv8hi3, "__builtin_ia32_phsubsw128", IX86_BUILTIN_PHSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21423   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv4hi3, "__builtin_ia32_phsubsw", IX86_BUILTIN_PHSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21424   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw128, "__builtin_ia32_pmaddubsw128", IX86_BUILTIN_PMADDUBSW128, UNKNOWN, (int) V8HI_FTYPE_V16QI_V16QI },
21425   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw, "__builtin_ia32_pmaddubsw", IX86_BUILTIN_PMADDUBSW, UNKNOWN, (int) V4HI_FTYPE_V8QI_V8QI },
21426   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv8hi3, "__builtin_ia32_pmulhrsw128", IX86_BUILTIN_PMULHRSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21427   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv4hi3, "__builtin_ia32_pmulhrsw", IX86_BUILTIN_PMULHRSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21428   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv16qi3, "__builtin_ia32_pshufb128", IX86_BUILTIN_PSHUFB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21429   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv8qi3, "__builtin_ia32_pshufb", IX86_BUILTIN_PSHUFB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21430   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv16qi3, "__builtin_ia32_psignb128", IX86_BUILTIN_PSIGNB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21431   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8qi3, "__builtin_ia32_psignb", IX86_BUILTIN_PSIGNB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21432   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8hi3, "__builtin_ia32_psignw128", IX86_BUILTIN_PSIGNW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21433   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4hi3, "__builtin_ia32_psignw", IX86_BUILTIN_PSIGNW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21434   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4si3, "__builtin_ia32_psignd128", IX86_BUILTIN_PSIGND128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21435   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv2si3, "__builtin_ia32_psignd", IX86_BUILTIN_PSIGND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21436
21437   /* SSSE3.  */
21438   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrti, "__builtin_ia32_palignr128", IX86_BUILTIN_PALIGNR128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_V2DI_INT },
21439   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrdi, "__builtin_ia32_palignr", IX86_BUILTIN_PALIGNR, UNKNOWN, (int) V1DI2DI_FTYPE_V1DI_V1DI_INT },
21440
21441   /* SSE4.1 */
21442   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendpd, "__builtin_ia32_blendpd", IX86_BUILTIN_BLENDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21443   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendps, "__builtin_ia32_blendps", IX86_BUILTIN_BLENDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21444   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvpd, "__builtin_ia32_blendvpd", IX86_BUILTIN_BLENDVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF },
21445   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvps, "__builtin_ia32_blendvps", IX86_BUILTIN_BLENDVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF },
21446   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dppd, "__builtin_ia32_dppd", IX86_BUILTIN_DPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21447   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dpps, "__builtin_ia32_dpps", IX86_BUILTIN_DPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21448   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_insertps, "__builtin_ia32_insertps128", IX86_BUILTIN_INSERTPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21449   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mpsadbw, "__builtin_ia32_mpsadbw128", IX86_BUILTIN_MPSADBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_INT },
21450   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendvb, "__builtin_ia32_pblendvb128", IX86_BUILTIN_PBLENDVB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI },
21451   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendw, "__builtin_ia32_pblendw128", IX86_BUILTIN_PBLENDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_INT },
21452
21453   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv8qiv8hi2, "__builtin_ia32_pmovsxbw128", IX86_BUILTIN_PMOVSXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
21454   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv4qiv4si2, "__builtin_ia32_pmovsxbd128", IX86_BUILTIN_PMOVSXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
21455   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2qiv2di2, "__builtin_ia32_pmovsxbq128", IX86_BUILTIN_PMOVSXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
21456   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv4hiv4si2, "__builtin_ia32_pmovsxwd128", IX86_BUILTIN_PMOVSXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
21457   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2hiv2di2, "__builtin_ia32_pmovsxwq128", IX86_BUILTIN_PMOVSXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
21458   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2siv2di2, "__builtin_ia32_pmovsxdq128", IX86_BUILTIN_PMOVSXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
21459   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv8qiv8hi2, "__builtin_ia32_pmovzxbw128", IX86_BUILTIN_PMOVZXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
21460   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4qiv4si2, "__builtin_ia32_pmovzxbd128", IX86_BUILTIN_PMOVZXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
21461   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2qiv2di2, "__builtin_ia32_pmovzxbq128", IX86_BUILTIN_PMOVZXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
21462   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4hiv4si2, "__builtin_ia32_pmovzxwd128", IX86_BUILTIN_PMOVZXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
21463   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2hiv2di2, "__builtin_ia32_pmovzxwq128", IX86_BUILTIN_PMOVZXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
21464   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2siv2di2, "__builtin_ia32_pmovzxdq128", IX86_BUILTIN_PMOVZXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
21465   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_phminposuw, "__builtin_ia32_phminposuw128", IX86_BUILTIN_PHMINPOSUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
21466
21467   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_packusdw, "__builtin_ia32_packusdw128", IX86_BUILTIN_PACKUSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
21468   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_eqv2di3, "__builtin_ia32_pcmpeqq", IX86_BUILTIN_PCMPEQQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21469   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv16qi3, "__builtin_ia32_pmaxsb128", IX86_BUILTIN_PMAXSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21470   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv4si3, "__builtin_ia32_pmaxsd128", IX86_BUILTIN_PMAXSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21471   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv4si3, "__builtin_ia32_pmaxud128", IX86_BUILTIN_PMAXUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21472   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv8hi3, "__builtin_ia32_pmaxuw128", IX86_BUILTIN_PMAXUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21473   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv16qi3, "__builtin_ia32_pminsb128", IX86_BUILTIN_PMINSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21474   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv4si3, "__builtin_ia32_pminsd128", IX86_BUILTIN_PMINSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21475   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv4si3, "__builtin_ia32_pminud128", IX86_BUILTIN_PMINUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21476   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv8hi3, "__builtin_ia32_pminuw128", IX86_BUILTIN_PMINUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21477   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mulv2siv2di3, "__builtin_ia32_pmuldq128", IX86_BUILTIN_PMULDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
21478   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_mulv4si3, "__builtin_ia32_pmulld128", IX86_BUILTIN_PMULLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21479
21480   /* SSE4.1 and SSE5 */
21481   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundpd, "__builtin_ia32_roundpd", IX86_BUILTIN_ROUNDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
21482   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundps, "__builtin_ia32_roundps", IX86_BUILTIN_ROUNDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
21483   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundsd, "__builtin_ia32_roundsd", IX86_BUILTIN_ROUNDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21484   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundss, "__builtin_ia32_roundss", IX86_BUILTIN_ROUNDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21485
21486   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestz128", IX86_BUILTIN_PTESTZ, EQ, (int) INT_FTYPE_V2DI_V2DI_PTEST },
21487   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestc128", IX86_BUILTIN_PTESTC, LTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
21488   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestnzc128", IX86_BUILTIN_PTESTNZC, GTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
21489
21490   /* SSE4.2 */
21491   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_gtv2di3, "__builtin_ia32_pcmpgtq", IX86_BUILTIN_PCMPGTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21492   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32qi, "__builtin_ia32_crc32qi", IX86_BUILTIN_CRC32QI, UNKNOWN, (int) UINT_FTYPE_UINT_UCHAR },
21493   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32hi, "__builtin_ia32_crc32hi", IX86_BUILTIN_CRC32HI, UNKNOWN, (int) UINT_FTYPE_UINT_USHORT },
21494   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32si, "__builtin_ia32_crc32si", IX86_BUILTIN_CRC32SI, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
21495   { OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse4_2_crc32di, "__builtin_ia32_crc32di", IX86_BUILTIN_CRC32DI, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
21496
21497   /* SSE4A */
21498   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrqi, "__builtin_ia32_extrqi", IX86_BUILTIN_EXTRQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_UINT_UINT },
21499   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrq, "__builtin_ia32_extrq", IX86_BUILTIN_EXTRQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V16QI },
21500   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertqi, "__builtin_ia32_insertqi", IX86_BUILTIN_INSERTQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_UINT_UINT },
21501   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertq, "__builtin_ia32_insertq", IX86_BUILTIN_INSERTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21502
21503   /* AES */
21504   { OPTION_MASK_ISA_SSE2, CODE_FOR_aeskeygenassist, 0, IX86_BUILTIN_AESKEYGENASSIST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT },
21505   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesimc, 0, IX86_BUILTIN_AESIMC128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
21506
21507   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenc, 0, IX86_BUILTIN_AESENC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21508   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenclast, 0, IX86_BUILTIN_AESENCLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21509   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdec, 0, IX86_BUILTIN_AESDEC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21510   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdeclast, 0, IX86_BUILTIN_AESDECLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21511
21512   /* PCLMUL */
21513   { OPTION_MASK_ISA_SSE2, CODE_FOR_pclmulqdq, 0, IX86_BUILTIN_PCLMULQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_INT },
21514
21515   /* AVX */
21516   { OPTION_MASK_ISA_AVX, CODE_FOR_addv4df3, "__builtin_ia32_addpd256", IX86_BUILTIN_ADDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21517   { OPTION_MASK_ISA_AVX, CODE_FOR_addv8sf3, "__builtin_ia32_addps256", IX86_BUILTIN_ADDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21518   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_addsubv4df3, "__builtin_ia32_addsubpd256", IX86_BUILTIN_ADDSUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21519   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_addsubv8sf3, "__builtin_ia32_addsubps256", IX86_BUILTIN_ADDSUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21520   { OPTION_MASK_ISA_AVX, CODE_FOR_andv4df3, "__builtin_ia32_andpd256", IX86_BUILTIN_ANDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21521   { OPTION_MASK_ISA_AVX, CODE_FOR_andv8sf3, "__builtin_ia32_andps256", IX86_BUILTIN_ANDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21522   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_andnotv4df3, "__builtin_ia32_andnpd256", IX86_BUILTIN_ANDNPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21523   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_andnotv8sf3, "__builtin_ia32_andnps256", IX86_BUILTIN_ANDNPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21524   { OPTION_MASK_ISA_AVX, CODE_FOR_divv4df3, "__builtin_ia32_divpd256", IX86_BUILTIN_DIVPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21525   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_divv8sf3, "__builtin_ia32_divps256", IX86_BUILTIN_DIVPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21526   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_haddv4df3, "__builtin_ia32_haddpd256", IX86_BUILTIN_HADDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21527   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_hsubv8sf3, "__builtin_ia32_hsubps256", IX86_BUILTIN_HSUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21528   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_hsubv4df3, "__builtin_ia32_hsubpd256", IX86_BUILTIN_HSUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21529   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_haddv8sf3, "__builtin_ia32_haddps256", IX86_BUILTIN_HADDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21530   { OPTION_MASK_ISA_AVX, CODE_FOR_smaxv4df3, "__builtin_ia32_maxpd256", IX86_BUILTIN_MAXPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21531   { OPTION_MASK_ISA_AVX, CODE_FOR_smaxv8sf3, "__builtin_ia32_maxps256", IX86_BUILTIN_MAXPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21532   { OPTION_MASK_ISA_AVX, CODE_FOR_sminv4df3, "__builtin_ia32_minpd256", IX86_BUILTIN_MINPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21533   { OPTION_MASK_ISA_AVX, CODE_FOR_sminv8sf3, "__builtin_ia32_minps256", IX86_BUILTIN_MINPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21534   { OPTION_MASK_ISA_AVX, CODE_FOR_mulv4df3, "__builtin_ia32_mulpd256", IX86_BUILTIN_MULPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21535   { OPTION_MASK_ISA_AVX, CODE_FOR_mulv8sf3, "__builtin_ia32_mulps256", IX86_BUILTIN_MULPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21536   { OPTION_MASK_ISA_AVX, CODE_FOR_iorv4df3, "__builtin_ia32_orpd256", IX86_BUILTIN_ORPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21537   { OPTION_MASK_ISA_AVX, CODE_FOR_iorv8sf3, "__builtin_ia32_orps256", IX86_BUILTIN_ORPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21538   { OPTION_MASK_ISA_AVX, CODE_FOR_subv4df3, "__builtin_ia32_subpd256", IX86_BUILTIN_SUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21539   { OPTION_MASK_ISA_AVX, CODE_FOR_subv8sf3, "__builtin_ia32_subps256", IX86_BUILTIN_SUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21540   { OPTION_MASK_ISA_AVX, CODE_FOR_xorv4df3, "__builtin_ia32_xorpd256", IX86_BUILTIN_XORPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21541   { OPTION_MASK_ISA_AVX, CODE_FOR_xorv8sf3, "__builtin_ia32_xorps256", IX86_BUILTIN_XORPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21542
21543   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv2df3, "__builtin_ia32_vpermilvarpd", IX86_BUILTIN_VPERMILVARPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DI },
21544   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv4sf3, "__builtin_ia32_vpermilvarps", IX86_BUILTIN_VPERMILVARPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SI },
21545   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv4df3, "__builtin_ia32_vpermilvarpd256", IX86_BUILTIN_VPERMILVARPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DI },
21546   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv8sf3, "__builtin_ia32_vpermilvarps256", IX86_BUILTIN_VPERMILVARPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SI },
21547
21548   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendpd256, "__builtin_ia32_blendpd256", IX86_BUILTIN_BLENDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
21549   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendps256, "__builtin_ia32_blendps256", IX86_BUILTIN_BLENDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
21550   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendvpd256, "__builtin_ia32_blendvpd256", IX86_BUILTIN_BLENDVPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF },
21551   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendvps256, "__builtin_ia32_blendvps256", IX86_BUILTIN_BLENDVPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF },
21552   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_dpps256, "__builtin_ia32_dpps256", IX86_BUILTIN_DPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
21553   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_shufpd256, "__builtin_ia32_shufpd256", IX86_BUILTIN_SHUFPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
21554   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_shufps256, "__builtin_ia32_shufps256", IX86_BUILTIN_SHUFPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
21555   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpsdv2df3, "__builtin_ia32_cmpsd", IX86_BUILTIN_CMPSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21556   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpssv4sf3, "__builtin_ia32_cmpss", IX86_BUILTIN_CMPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21557   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppdv2df3, "__builtin_ia32_cmppd", IX86_BUILTIN_CMPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21558   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppsv4sf3, "__builtin_ia32_cmpps", IX86_BUILTIN_CMPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21559   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppdv4df3, "__builtin_ia32_cmppd256", IX86_BUILTIN_CMPPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
21560   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppsv8sf3, "__builtin_ia32_cmpps256", IX86_BUILTIN_CMPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
21561   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v4df, "__builtin_ia32_vextractf128_pd256", IX86_BUILTIN_EXTRACTF128PD256, UNKNOWN, (int) V2DF_FTYPE_V4DF_INT },
21562   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v8sf, "__builtin_ia32_vextractf128_ps256", IX86_BUILTIN_EXTRACTF128PS256, UNKNOWN, (int) V4SF_FTYPE_V8SF_INT },
21563   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v8si, "__builtin_ia32_vextractf128_si256", IX86_BUILTIN_EXTRACTF128SI256, UNKNOWN, (int) V4SI_FTYPE_V8SI_INT },
21564   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtdq2pd256, "__builtin_ia32_cvtdq2pd256", IX86_BUILTIN_CVTDQ2PD256, UNKNOWN, (int) V4DF_FTYPE_V4SI },
21565   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtdq2ps256, "__builtin_ia32_cvtdq2ps256", IX86_BUILTIN_CVTDQ2PS256, UNKNOWN, (int) V8SF_FTYPE_V8SI },
21566   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtpd2ps256, "__builtin_ia32_cvtpd2ps256", IX86_BUILTIN_CVTPD2PS256, UNKNOWN, (int) V4SF_FTYPE_V4DF },
21567   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtps2dq256, "__builtin_ia32_cvtps2dq256", IX86_BUILTIN_CVTPS2DQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
21568   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtps2pd256, "__builtin_ia32_cvtps2pd256", IX86_BUILTIN_CVTPS2PD256, UNKNOWN, (int) V4DF_FTYPE_V4SF },
21569   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvttpd2dq256, "__builtin_ia32_cvttpd2dq256", IX86_BUILTIN_CVTTPD2DQ256, UNKNOWN, (int) V4SI_FTYPE_V4DF },
21570   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtpd2dq256, "__builtin_ia32_cvtpd2dq256", IX86_BUILTIN_CVTPD2DQ256, UNKNOWN, (int) V4SI_FTYPE_V4DF },
21571   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvttps2dq256, "__builtin_ia32_cvttps2dq256", IX86_BUILTIN_CVTTPS2DQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
21572   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v4df3, "__builtin_ia32_vperm2f128_pd256", IX86_BUILTIN_VPERM2F128PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
21573   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v8sf3, "__builtin_ia32_vperm2f128_ps256", IX86_BUILTIN_VPERM2F128PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
21574   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v8si3, "__builtin_ia32_vperm2f128_si256", IX86_BUILTIN_VPERM2F128SI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_INT },
21575   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv2df, "__builtin_ia32_vpermilpd", IX86_BUILTIN_VPERMILPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
21576   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv4sf, "__builtin_ia32_vpermilps", IX86_BUILTIN_VPERMILPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
21577   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv4df, "__builtin_ia32_vpermilpd256", IX86_BUILTIN_VPERMILPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
21578   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv8sf, "__builtin_ia32_vpermilps256", IX86_BUILTIN_VPERMILPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT },
21579   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v4df, "__builtin_ia32_vinsertf128_pd256", IX86_BUILTIN_VINSERTF128PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V2DF_INT },
21580   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v8sf, "__builtin_ia32_vinsertf128_ps256", IX86_BUILTIN_VINSERTF128PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V4SF_INT },
21581   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v8si, "__builtin_ia32_vinsertf128_si256", IX86_BUILTIN_VINSERTF128SI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_INT },
21582
21583   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movshdup256, "__builtin_ia32_movshdup256", IX86_BUILTIN_MOVSHDUP256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21584   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movsldup256, "__builtin_ia32_movsldup256", IX86_BUILTIN_MOVSLDUP256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21585   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movddup256, "__builtin_ia32_movddup256", IX86_BUILTIN_MOVDDUP256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
21586
21587   { OPTION_MASK_ISA_AVX, CODE_FOR_sqrtv4df2, "__builtin_ia32_sqrtpd256", IX86_BUILTIN_SQRTPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
21588   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_sqrtv8sf2, "__builtin_ia32_sqrtps256", IX86_BUILTIN_SQRTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21589   { OPTION_MASK_ISA_AVX, CODE_FOR_sqrtv8sf2, "__builtin_ia32_sqrtps_nr256", IX86_BUILTIN_SQRTPS_NR256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21590   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_rsqrtv8sf2, "__builtin_ia32_rsqrtps256", IX86_BUILTIN_RSQRTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21591   { OPTION_MASK_ISA_AVX, CODE_FOR_rsqrtv8sf2, "__builtin_ia32_rsqrtps_nr256", IX86_BUILTIN_RSQRTPS_NR256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21592
21593   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_rcpv8sf2, "__builtin_ia32_rcpps256", IX86_BUILTIN_RCPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21594
21595   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_roundpd256", IX86_BUILTIN_ROUNDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
21596   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_roundps256", IX86_BUILTIN_ROUNDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT },
21597
21598   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpckhpd256,  "__builtin_ia32_unpckhpd256", IX86_BUILTIN_UNPCKHPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21599   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpcklpd256,  "__builtin_ia32_unpcklpd256", IX86_BUILTIN_UNPCKLPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21600   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpckhps256,  "__builtin_ia32_unpckhps256", IX86_BUILTIN_UNPCKHPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21601   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpcklps256,  "__builtin_ia32_unpcklps256", IX86_BUILTIN_UNPCKLPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21602
21603   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_si256_si, "__builtin_ia32_si256_si", IX86_BUILTIN_SI256_SI, UNKNOWN, (int) V8SI_FTYPE_V4SI },
21604   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ps256_ps, "__builtin_ia32_ps256_ps", IX86_BUILTIN_PS256_PS, UNKNOWN, (int) V8SF_FTYPE_V4SF },
21605   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_pd256_pd, "__builtin_ia32_pd256_pd", IX86_BUILTIN_PD256_PD, UNKNOWN, (int) V4DF_FTYPE_V2DF },
21606   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_si_si256, "__builtin_ia32_si_si256", IX86_BUILTIN_SI_SI256, UNKNOWN, (int) V4SI_FTYPE_V8SI },
21607   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ps_ps256, "__builtin_ia32_ps_ps256", IX86_BUILTIN_PS_PS256, UNKNOWN, (int) V4SF_FTYPE_V8SF },
21608   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_pd_pd256, "__builtin_ia32_pd_pd256", IX86_BUILTIN_PD_PD256, UNKNOWN, (int) V2DF_FTYPE_V4DF },
21609
21610   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestzpd", IX86_BUILTIN_VTESTZPD, EQ, (int) INT_FTYPE_V2DF_V2DF_PTEST },
21611   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestcpd", IX86_BUILTIN_VTESTCPD, LTU, (int) INT_FTYPE_V2DF_V2DF_PTEST },
21612   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestnzcpd", IX86_BUILTIN_VTESTNZCPD, GTU, (int) INT_FTYPE_V2DF_V2DF_PTEST },
21613   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestzps", IX86_BUILTIN_VTESTZPS, EQ, (int) INT_FTYPE_V4SF_V4SF_PTEST },
21614   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestcps", IX86_BUILTIN_VTESTCPS, LTU, (int) INT_FTYPE_V4SF_V4SF_PTEST },
21615   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestnzcps", IX86_BUILTIN_VTESTNZCPS, GTU, (int) INT_FTYPE_V4SF_V4SF_PTEST },
21616   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestzpd256", IX86_BUILTIN_VTESTZPD256, EQ, (int) INT_FTYPE_V4DF_V4DF_PTEST },
21617   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestcpd256", IX86_BUILTIN_VTESTCPD256, LTU, (int) INT_FTYPE_V4DF_V4DF_PTEST },
21618   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestnzcpd256", IX86_BUILTIN_VTESTNZCPD256, GTU, (int) INT_FTYPE_V4DF_V4DF_PTEST },
21619   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestzps256", IX86_BUILTIN_VTESTZPS256, EQ, (int) INT_FTYPE_V8SF_V8SF_PTEST },
21620   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestcps256", IX86_BUILTIN_VTESTCPS256, LTU, (int) INT_FTYPE_V8SF_V8SF_PTEST },
21621   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestnzcps256", IX86_BUILTIN_VTESTNZCPS256, GTU, (int) INT_FTYPE_V8SF_V8SF_PTEST },
21622   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestz256", IX86_BUILTIN_PTESTZ256, EQ, (int) INT_FTYPE_V4DI_V4DI_PTEST },
21623   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestc256", IX86_BUILTIN_PTESTC256, LTU, (int) INT_FTYPE_V4DI_V4DI_PTEST },
21624   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestnzc256", IX86_BUILTIN_PTESTNZC256, GTU, (int) INT_FTYPE_V4DI_V4DI_PTEST },
21625
21626   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movmskpd256, "__builtin_ia32_movmskpd256", IX86_BUILTIN_MOVMSKPD256, UNKNOWN, (int) INT_FTYPE_V4DF  },
21627   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movmskps256, "__builtin_ia32_movmskps256", IX86_BUILTIN_MOVMSKPS256, UNKNOWN, (int) INT_FTYPE_V8SF },
21628 };
21629
21630 /* SSE5 */
21631 enum multi_arg_type {
21632   MULTI_ARG_UNKNOWN,
21633   MULTI_ARG_3_SF,
21634   MULTI_ARG_3_DF,
21635   MULTI_ARG_3_DI,
21636   MULTI_ARG_3_SI,
21637   MULTI_ARG_3_SI_DI,
21638   MULTI_ARG_3_HI,
21639   MULTI_ARG_3_HI_SI,
21640   MULTI_ARG_3_QI,
21641   MULTI_ARG_3_PERMPS,
21642   MULTI_ARG_3_PERMPD,
21643   MULTI_ARG_2_SF,
21644   MULTI_ARG_2_DF,
21645   MULTI_ARG_2_DI,
21646   MULTI_ARG_2_SI,
21647   MULTI_ARG_2_HI,
21648   MULTI_ARG_2_QI,
21649   MULTI_ARG_2_DI_IMM,
21650   MULTI_ARG_2_SI_IMM,
21651   MULTI_ARG_2_HI_IMM,
21652   MULTI_ARG_2_QI_IMM,
21653   MULTI_ARG_2_SF_CMP,
21654   MULTI_ARG_2_DF_CMP,
21655   MULTI_ARG_2_DI_CMP,
21656   MULTI_ARG_2_SI_CMP,
21657   MULTI_ARG_2_HI_CMP,
21658   MULTI_ARG_2_QI_CMP,
21659   MULTI_ARG_2_DI_TF,
21660   MULTI_ARG_2_SI_TF,
21661   MULTI_ARG_2_HI_TF,
21662   MULTI_ARG_2_QI_TF,
21663   MULTI_ARG_2_SF_TF,
21664   MULTI_ARG_2_DF_TF,
21665   MULTI_ARG_1_SF,
21666   MULTI_ARG_1_DF,
21667   MULTI_ARG_1_DI,
21668   MULTI_ARG_1_SI,
21669   MULTI_ARG_1_HI,
21670   MULTI_ARG_1_QI,
21671   MULTI_ARG_1_SI_DI,
21672   MULTI_ARG_1_HI_DI,
21673   MULTI_ARG_1_HI_SI,
21674   MULTI_ARG_1_QI_DI,
21675   MULTI_ARG_1_QI_SI,
21676   MULTI_ARG_1_QI_HI,
21677   MULTI_ARG_1_PH2PS,
21678   MULTI_ARG_1_PS2PH
21679 };
21680
21681 static const struct builtin_description bdesc_multi_arg[] =
21682 {
21683   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmaddv4sf4,     "__builtin_ia32_fmaddss",    IX86_BUILTIN_FMADDSS,    0,            (int)MULTI_ARG_3_SF },
21684   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmaddv2df4,     "__builtin_ia32_fmaddsd",    IX86_BUILTIN_FMADDSD,    0,            (int)MULTI_ARG_3_DF },
21685   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmaddv4sf4,       "__builtin_ia32_fmaddps",    IX86_BUILTIN_FMADDPS,    0,            (int)MULTI_ARG_3_SF },
21686   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmaddv2df4,       "__builtin_ia32_fmaddpd",    IX86_BUILTIN_FMADDPD,    0,            (int)MULTI_ARG_3_DF },
21687   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmsubv4sf4,     "__builtin_ia32_fmsubss",    IX86_BUILTIN_FMSUBSS,    0,            (int)MULTI_ARG_3_SF },
21688   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmsubv2df4,     "__builtin_ia32_fmsubsd",    IX86_BUILTIN_FMSUBSD,    0,            (int)MULTI_ARG_3_DF },
21689   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmsubv4sf4,       "__builtin_ia32_fmsubps",    IX86_BUILTIN_FMSUBPS,    0,            (int)MULTI_ARG_3_SF },
21690   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmsubv2df4,       "__builtin_ia32_fmsubpd",    IX86_BUILTIN_FMSUBPD,    0,            (int)MULTI_ARG_3_DF },
21691   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmaddv4sf4,    "__builtin_ia32_fnmaddss",   IX86_BUILTIN_FNMADDSS,   0,            (int)MULTI_ARG_3_SF },
21692   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmaddv2df4,    "__builtin_ia32_fnmaddsd",   IX86_BUILTIN_FNMADDSD,   0,            (int)MULTI_ARG_3_DF },
21693   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmaddv4sf4,      "__builtin_ia32_fnmaddps",   IX86_BUILTIN_FNMADDPS,   0,            (int)MULTI_ARG_3_SF },
21694   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmaddv2df4,      "__builtin_ia32_fnmaddpd",   IX86_BUILTIN_FNMADDPD,   0,            (int)MULTI_ARG_3_DF },
21695   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmsubv4sf4,    "__builtin_ia32_fnmsubss",   IX86_BUILTIN_FNMSUBSS,   0,            (int)MULTI_ARG_3_SF },
21696   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmsubv2df4,    "__builtin_ia32_fnmsubsd",   IX86_BUILTIN_FNMSUBSD,   0,            (int)MULTI_ARG_3_DF },
21697   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmsubv4sf4,      "__builtin_ia32_fnmsubps",   IX86_BUILTIN_FNMSUBPS,   0,            (int)MULTI_ARG_3_SF },
21698   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmsubv2df4,      "__builtin_ia32_fnmsubpd",   IX86_BUILTIN_FNMSUBPD,   0,            (int)MULTI_ARG_3_DF },
21699   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2di,        "__builtin_ia32_pcmov",      IX86_BUILTIN_PCMOV,      0,            (int)MULTI_ARG_3_DI },
21700   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2di,        "__builtin_ia32_pcmov_v2di", IX86_BUILTIN_PCMOV_V2DI, 0,            (int)MULTI_ARG_3_DI },
21701   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v4si,        "__builtin_ia32_pcmov_v4si", IX86_BUILTIN_PCMOV_V4SI, 0,            (int)MULTI_ARG_3_SI },
21702   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v8hi,        "__builtin_ia32_pcmov_v8hi", IX86_BUILTIN_PCMOV_V8HI, 0,            (int)MULTI_ARG_3_HI },
21703   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v16qi,       "__builtin_ia32_pcmov_v16qi",IX86_BUILTIN_PCMOV_V16QI,0,            (int)MULTI_ARG_3_QI },
21704   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2df,        "__builtin_ia32_pcmov_v2df", IX86_BUILTIN_PCMOV_V2DF, 0,            (int)MULTI_ARG_3_DF },
21705   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v4sf,        "__builtin_ia32_pcmov_v4sf", IX86_BUILTIN_PCMOV_V4SF, 0,            (int)MULTI_ARG_3_SF },
21706   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pperm,             "__builtin_ia32_pperm",      IX86_BUILTIN_PPERM,      0,            (int)MULTI_ARG_3_QI },
21707   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_permv4sf,          "__builtin_ia32_permps",     IX86_BUILTIN_PERMPS,     0,            (int)MULTI_ARG_3_PERMPS },
21708   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_permv2df,          "__builtin_ia32_permpd",     IX86_BUILTIN_PERMPD,     0,            (int)MULTI_ARG_3_PERMPD },
21709   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssww,          "__builtin_ia32_pmacssww",   IX86_BUILTIN_PMACSSWW,   0,            (int)MULTI_ARG_3_HI },
21710   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsww,           "__builtin_ia32_pmacsww",    IX86_BUILTIN_PMACSWW,    0,            (int)MULTI_ARG_3_HI },
21711   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsswd,          "__builtin_ia32_pmacsswd",   IX86_BUILTIN_PMACSSWD,   0,            (int)MULTI_ARG_3_HI_SI },
21712   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacswd,           "__builtin_ia32_pmacswd",    IX86_BUILTIN_PMACSWD,    0,            (int)MULTI_ARG_3_HI_SI },
21713   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdd,          "__builtin_ia32_pmacssdd",   IX86_BUILTIN_PMACSSDD,   0,            (int)MULTI_ARG_3_SI },
21714   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdd,           "__builtin_ia32_pmacsdd",    IX86_BUILTIN_PMACSDD,    0,            (int)MULTI_ARG_3_SI },
21715   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdql,         "__builtin_ia32_pmacssdql",  IX86_BUILTIN_PMACSSDQL,  0,            (int)MULTI_ARG_3_SI_DI },
21716   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdqh,         "__builtin_ia32_pmacssdqh",  IX86_BUILTIN_PMACSSDQH,  0,            (int)MULTI_ARG_3_SI_DI },
21717   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdql,          "__builtin_ia32_pmacsdql",   IX86_BUILTIN_PMACSDQL,   0,            (int)MULTI_ARG_3_SI_DI },
21718   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdqh,          "__builtin_ia32_pmacsdqh",   IX86_BUILTIN_PMACSDQH,   0,            (int)MULTI_ARG_3_SI_DI },
21719   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmadcsswd,         "__builtin_ia32_pmadcsswd",  IX86_BUILTIN_PMADCSSWD,  0,            (int)MULTI_ARG_3_HI_SI },
21720   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmadcswd,          "__builtin_ia32_pmadcswd",   IX86_BUILTIN_PMADCSWD,   0,            (int)MULTI_ARG_3_HI_SI },
21721   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv2di3,        "__builtin_ia32_protq",      IX86_BUILTIN_PROTQ,      0,            (int)MULTI_ARG_2_DI },
21722   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv4si3,        "__builtin_ia32_protd",      IX86_BUILTIN_PROTD,      0,            (int)MULTI_ARG_2_SI },
21723   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv8hi3,        "__builtin_ia32_protw",      IX86_BUILTIN_PROTW,      0,            (int)MULTI_ARG_2_HI },
21724   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv16qi3,       "__builtin_ia32_protb",      IX86_BUILTIN_PROTB,      0,            (int)MULTI_ARG_2_QI },
21725   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv2di3,         "__builtin_ia32_protqi",     IX86_BUILTIN_PROTQ_IMM,  0,            (int)MULTI_ARG_2_DI_IMM },
21726   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv4si3,         "__builtin_ia32_protdi",     IX86_BUILTIN_PROTD_IMM,  0,            (int)MULTI_ARG_2_SI_IMM },
21727   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv8hi3,         "__builtin_ia32_protwi",     IX86_BUILTIN_PROTW_IMM,  0,            (int)MULTI_ARG_2_HI_IMM },
21728   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv16qi3,        "__builtin_ia32_protbi",     IX86_BUILTIN_PROTB_IMM,  0,            (int)MULTI_ARG_2_QI_IMM },
21729   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv2di3,         "__builtin_ia32_pshaq",      IX86_BUILTIN_PSHAQ,      0,            (int)MULTI_ARG_2_DI },
21730   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv4si3,         "__builtin_ia32_pshad",      IX86_BUILTIN_PSHAD,      0,            (int)MULTI_ARG_2_SI },
21731   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv8hi3,         "__builtin_ia32_pshaw",      IX86_BUILTIN_PSHAW,      0,            (int)MULTI_ARG_2_HI },
21732   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv16qi3,        "__builtin_ia32_pshab",      IX86_BUILTIN_PSHAB,      0,            (int)MULTI_ARG_2_QI },
21733   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv2di3,         "__builtin_ia32_pshlq",      IX86_BUILTIN_PSHLQ,      0,            (int)MULTI_ARG_2_DI },
21734   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv4si3,         "__builtin_ia32_pshld",      IX86_BUILTIN_PSHLD,      0,            (int)MULTI_ARG_2_SI },
21735   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv8hi3,         "__builtin_ia32_pshlw",      IX86_BUILTIN_PSHLW,      0,            (int)MULTI_ARG_2_HI },
21736   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv16qi3,        "__builtin_ia32_pshlb",      IX86_BUILTIN_PSHLB,      0,            (int)MULTI_ARG_2_QI },
21737   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmfrczv4sf2,       "__builtin_ia32_frczss",     IX86_BUILTIN_FRCZSS,     0,            (int)MULTI_ARG_2_SF },
21738   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmfrczv2df2,       "__builtin_ia32_frczsd",     IX86_BUILTIN_FRCZSD,     0,            (int)MULTI_ARG_2_DF },
21739   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_frczv4sf2,         "__builtin_ia32_frczps",     IX86_BUILTIN_FRCZPS,     0,            (int)MULTI_ARG_1_SF },
21740   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_frczv2df2,         "__builtin_ia32_frczpd",     IX86_BUILTIN_FRCZPD,     0,            (int)MULTI_ARG_1_DF },
21741   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_cvtph2ps,          "__builtin_ia32_cvtph2ps",   IX86_BUILTIN_CVTPH2PS,   0,            (int)MULTI_ARG_1_PH2PS },
21742   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_cvtps2ph,          "__builtin_ia32_cvtps2ph",   IX86_BUILTIN_CVTPS2PH,   0,            (int)MULTI_ARG_1_PS2PH },
21743   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbw,           "__builtin_ia32_phaddbw",    IX86_BUILTIN_PHADDBW,    0,            (int)MULTI_ARG_1_QI_HI },
21744   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbd,           "__builtin_ia32_phaddbd",    IX86_BUILTIN_PHADDBD,    0,            (int)MULTI_ARG_1_QI_SI },
21745   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbq,           "__builtin_ia32_phaddbq",    IX86_BUILTIN_PHADDBQ,    0,            (int)MULTI_ARG_1_QI_DI },
21746   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddwd,           "__builtin_ia32_phaddwd",    IX86_BUILTIN_PHADDWD,    0,            (int)MULTI_ARG_1_HI_SI },
21747   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddwq,           "__builtin_ia32_phaddwq",    IX86_BUILTIN_PHADDWQ,    0,            (int)MULTI_ARG_1_HI_DI },
21748   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadddq,           "__builtin_ia32_phadddq",    IX86_BUILTIN_PHADDDQ,    0,            (int)MULTI_ARG_1_SI_DI },
21749   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubw,          "__builtin_ia32_phaddubw",   IX86_BUILTIN_PHADDUBW,   0,            (int)MULTI_ARG_1_QI_HI },
21750   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubd,          "__builtin_ia32_phaddubd",   IX86_BUILTIN_PHADDUBD,   0,            (int)MULTI_ARG_1_QI_SI },
21751   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubq,          "__builtin_ia32_phaddubq",   IX86_BUILTIN_PHADDUBQ,   0,            (int)MULTI_ARG_1_QI_DI },
21752   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadduwd,          "__builtin_ia32_phadduwd",   IX86_BUILTIN_PHADDUWD,   0,            (int)MULTI_ARG_1_HI_SI },
21753   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadduwq,          "__builtin_ia32_phadduwq",   IX86_BUILTIN_PHADDUWQ,   0,            (int)MULTI_ARG_1_HI_DI },
21754   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddudq,          "__builtin_ia32_phaddudq",   IX86_BUILTIN_PHADDUDQ,   0,            (int)MULTI_ARG_1_SI_DI },
21755   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubbw,           "__builtin_ia32_phsubbw",    IX86_BUILTIN_PHSUBBW,    0,            (int)MULTI_ARG_1_QI_HI },
21756   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubwd,           "__builtin_ia32_phsubwd",    IX86_BUILTIN_PHSUBWD,    0,            (int)MULTI_ARG_1_HI_SI },
21757   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubdq,           "__builtin_ia32_phsubdq",    IX86_BUILTIN_PHSUBDQ,    0,            (int)MULTI_ARG_1_SI_DI },
21758
21759   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comeqss",    IX86_BUILTIN_COMEQSS,    EQ,           (int)MULTI_ARG_2_SF_CMP },
21760   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comness",    IX86_BUILTIN_COMNESS,    NE,           (int)MULTI_ARG_2_SF_CMP },
21761   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comneqss",   IX86_BUILTIN_COMNESS,    NE,           (int)MULTI_ARG_2_SF_CMP },
21762   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comltss",    IX86_BUILTIN_COMLTSS,    LT,           (int)MULTI_ARG_2_SF_CMP },
21763   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comless",    IX86_BUILTIN_COMLESS,    LE,           (int)MULTI_ARG_2_SF_CMP },
21764   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comgtss",    IX86_BUILTIN_COMGTSS,    GT,           (int)MULTI_ARG_2_SF_CMP },
21765   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comgess",    IX86_BUILTIN_COMGESS,    GE,           (int)MULTI_ARG_2_SF_CMP },
21766   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comueqss",   IX86_BUILTIN_COMUEQSS,   UNEQ,         (int)MULTI_ARG_2_SF_CMP },
21767   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comuness",   IX86_BUILTIN_COMUNESS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21768   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comuneqss",  IX86_BUILTIN_COMUNESS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21769   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunltss",  IX86_BUILTIN_COMULTSS,   UNLT,         (int)MULTI_ARG_2_SF_CMP },
21770   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunless",  IX86_BUILTIN_COMULESS,   UNLE,         (int)MULTI_ARG_2_SF_CMP },
21771   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comungtss",  IX86_BUILTIN_COMUGTSS,   UNGT,         (int)MULTI_ARG_2_SF_CMP },
21772   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comungess",  IX86_BUILTIN_COMUGESS,   UNGE,         (int)MULTI_ARG_2_SF_CMP },
21773   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comordss",   IX86_BUILTIN_COMORDSS,   ORDERED,      (int)MULTI_ARG_2_SF_CMP },
21774   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunordss", IX86_BUILTIN_COMUNORDSS, UNORDERED,    (int)MULTI_ARG_2_SF_CMP },
21775
21776   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comeqsd",    IX86_BUILTIN_COMEQSD,    EQ,           (int)MULTI_ARG_2_DF_CMP },
21777   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comnesd",    IX86_BUILTIN_COMNESD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21778   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comneqsd",   IX86_BUILTIN_COMNESD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21779   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comltsd",    IX86_BUILTIN_COMLTSD,    LT,           (int)MULTI_ARG_2_DF_CMP },
21780   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comlesd",    IX86_BUILTIN_COMLESD,    LE,           (int)MULTI_ARG_2_DF_CMP },
21781   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comgtsd",    IX86_BUILTIN_COMGTSD,    GT,           (int)MULTI_ARG_2_DF_CMP },
21782   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comgesd",    IX86_BUILTIN_COMGESD,    GE,           (int)MULTI_ARG_2_DF_CMP },
21783   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comueqsd",   IX86_BUILTIN_COMUEQSD,   UNEQ,         (int)MULTI_ARG_2_DF_CMP },
21784   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunesd",   IX86_BUILTIN_COMUNESD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21785   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comuneqsd",  IX86_BUILTIN_COMUNESD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21786   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunltsd",  IX86_BUILTIN_COMULTSD,   UNLT,         (int)MULTI_ARG_2_DF_CMP },
21787   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunlesd",  IX86_BUILTIN_COMULESD,   UNLE,         (int)MULTI_ARG_2_DF_CMP },
21788   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comungtsd",  IX86_BUILTIN_COMUGTSD,   UNGT,         (int)MULTI_ARG_2_DF_CMP },
21789   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comungesd",  IX86_BUILTIN_COMUGESD,   UNGE,         (int)MULTI_ARG_2_DF_CMP },
21790   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comordsd",   IX86_BUILTIN_COMORDSD,   ORDERED,      (int)MULTI_ARG_2_DF_CMP },
21791   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunordsd", IX86_BUILTIN_COMUNORDSD, UNORDERED,    (int)MULTI_ARG_2_DF_CMP },
21792
21793   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comeqps",    IX86_BUILTIN_COMEQPS,    EQ,           (int)MULTI_ARG_2_SF_CMP },
21794   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comneps",    IX86_BUILTIN_COMNEPS,    NE,           (int)MULTI_ARG_2_SF_CMP },
21795   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comneqps",   IX86_BUILTIN_COMNEPS,    NE,           (int)MULTI_ARG_2_SF_CMP },
21796   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comltps",    IX86_BUILTIN_COMLTPS,    LT,           (int)MULTI_ARG_2_SF_CMP },
21797   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comleps",    IX86_BUILTIN_COMLEPS,    LE,           (int)MULTI_ARG_2_SF_CMP },
21798   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comgtps",    IX86_BUILTIN_COMGTPS,    GT,           (int)MULTI_ARG_2_SF_CMP },
21799   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comgeps",    IX86_BUILTIN_COMGEPS,    GE,           (int)MULTI_ARG_2_SF_CMP },
21800   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comueqps",   IX86_BUILTIN_COMUEQPS,   UNEQ,         (int)MULTI_ARG_2_SF_CMP },
21801   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comuneps",   IX86_BUILTIN_COMUNEPS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21802   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comuneqps",  IX86_BUILTIN_COMUNEPS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21803   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunltps",  IX86_BUILTIN_COMULTPS,   UNLT,         (int)MULTI_ARG_2_SF_CMP },
21804   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunleps",  IX86_BUILTIN_COMULEPS,   UNLE,         (int)MULTI_ARG_2_SF_CMP },
21805   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comungtps",  IX86_BUILTIN_COMUGTPS,   UNGT,         (int)MULTI_ARG_2_SF_CMP },
21806   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comungeps",  IX86_BUILTIN_COMUGEPS,   UNGE,         (int)MULTI_ARG_2_SF_CMP },
21807   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comordps",   IX86_BUILTIN_COMORDPS,   ORDERED,      (int)MULTI_ARG_2_SF_CMP },
21808   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunordps", IX86_BUILTIN_COMUNORDPS, UNORDERED,    (int)MULTI_ARG_2_SF_CMP },
21809
21810   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comeqpd",    IX86_BUILTIN_COMEQPD,    EQ,           (int)MULTI_ARG_2_DF_CMP },
21811   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comnepd",    IX86_BUILTIN_COMNEPD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21812   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comneqpd",   IX86_BUILTIN_COMNEPD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21813   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comltpd",    IX86_BUILTIN_COMLTPD,    LT,           (int)MULTI_ARG_2_DF_CMP },
21814   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comlepd",    IX86_BUILTIN_COMLEPD,    LE,           (int)MULTI_ARG_2_DF_CMP },
21815   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comgtpd",    IX86_BUILTIN_COMGTPD,    GT,           (int)MULTI_ARG_2_DF_CMP },
21816   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comgepd",    IX86_BUILTIN_COMGEPD,    GE,           (int)MULTI_ARG_2_DF_CMP },
21817   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comueqpd",   IX86_BUILTIN_COMUEQPD,   UNEQ,         (int)MULTI_ARG_2_DF_CMP },
21818   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunepd",   IX86_BUILTIN_COMUNEPD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21819   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comuneqpd",  IX86_BUILTIN_COMUNEPD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21820   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunltpd",  IX86_BUILTIN_COMULTPD,   UNLT,         (int)MULTI_ARG_2_DF_CMP },
21821   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunlepd",  IX86_BUILTIN_COMULEPD,   UNLE,         (int)MULTI_ARG_2_DF_CMP },
21822   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comungtpd",  IX86_BUILTIN_COMUGTPD,   UNGT,         (int)MULTI_ARG_2_DF_CMP },
21823   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comungepd",  IX86_BUILTIN_COMUGEPD,   UNGE,         (int)MULTI_ARG_2_DF_CMP },
21824   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comordpd",   IX86_BUILTIN_COMORDPD,   ORDERED,      (int)MULTI_ARG_2_DF_CMP },
21825   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunordpd", IX86_BUILTIN_COMUNORDPD, UNORDERED,    (int)MULTI_ARG_2_DF_CMP },
21826
21827   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomeqb",    IX86_BUILTIN_PCOMEQB,    EQ,           (int)MULTI_ARG_2_QI_CMP },
21828   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomneb",    IX86_BUILTIN_PCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
21829   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomneqb",   IX86_BUILTIN_PCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
21830   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomltb",    IX86_BUILTIN_PCOMLTB,    LT,           (int)MULTI_ARG_2_QI_CMP },
21831   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomleb",    IX86_BUILTIN_PCOMLEB,    LE,           (int)MULTI_ARG_2_QI_CMP },
21832   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomgtb",    IX86_BUILTIN_PCOMGTB,    GT,           (int)MULTI_ARG_2_QI_CMP },
21833   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomgeb",    IX86_BUILTIN_PCOMGEB,    GE,           (int)MULTI_ARG_2_QI_CMP },
21834
21835   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomeqw",    IX86_BUILTIN_PCOMEQW,    EQ,           (int)MULTI_ARG_2_HI_CMP },
21836   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomnew",    IX86_BUILTIN_PCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
21837   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomneqw",   IX86_BUILTIN_PCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
21838   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomltw",    IX86_BUILTIN_PCOMLTW,    LT,           (int)MULTI_ARG_2_HI_CMP },
21839   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomlew",    IX86_BUILTIN_PCOMLEW,    LE,           (int)MULTI_ARG_2_HI_CMP },
21840   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomgtw",    IX86_BUILTIN_PCOMGTW,    GT,           (int)MULTI_ARG_2_HI_CMP },
21841   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomgew",    IX86_BUILTIN_PCOMGEW,    GE,           (int)MULTI_ARG_2_HI_CMP },
21842
21843   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomeqd",    IX86_BUILTIN_PCOMEQD,    EQ,           (int)MULTI_ARG_2_SI_CMP },
21844   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomned",    IX86_BUILTIN_PCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
21845   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomneqd",   IX86_BUILTIN_PCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
21846   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomltd",    IX86_BUILTIN_PCOMLTD,    LT,           (int)MULTI_ARG_2_SI_CMP },
21847   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomled",    IX86_BUILTIN_PCOMLED,    LE,           (int)MULTI_ARG_2_SI_CMP },
21848   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomgtd",    IX86_BUILTIN_PCOMGTD,    GT,           (int)MULTI_ARG_2_SI_CMP },
21849   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomged",    IX86_BUILTIN_PCOMGED,    GE,           (int)MULTI_ARG_2_SI_CMP },
21850
21851   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomeqq",    IX86_BUILTIN_PCOMEQQ,    EQ,           (int)MULTI_ARG_2_DI_CMP },
21852   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomneq",    IX86_BUILTIN_PCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
21853   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomneqq",   IX86_BUILTIN_PCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
21854   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomltq",    IX86_BUILTIN_PCOMLTQ,    LT,           (int)MULTI_ARG_2_DI_CMP },
21855   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomleq",    IX86_BUILTIN_PCOMLEQ,    LE,           (int)MULTI_ARG_2_DI_CMP },
21856   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomgtq",    IX86_BUILTIN_PCOMGTQ,    GT,           (int)MULTI_ARG_2_DI_CMP },
21857   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomgeq",    IX86_BUILTIN_PCOMGEQ,    GE,           (int)MULTI_ARG_2_DI_CMP },
21858
21859   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomequb",   IX86_BUILTIN_PCOMEQUB,   EQ,           (int)MULTI_ARG_2_QI_CMP },
21860   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomneub",   IX86_BUILTIN_PCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
21861   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomnequb",  IX86_BUILTIN_PCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
21862   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomltub",   IX86_BUILTIN_PCOMLTUB,   LTU,          (int)MULTI_ARG_2_QI_CMP },
21863   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomleub",   IX86_BUILTIN_PCOMLEUB,   LEU,          (int)MULTI_ARG_2_QI_CMP },
21864   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomgtub",   IX86_BUILTIN_PCOMGTUB,   GTU,          (int)MULTI_ARG_2_QI_CMP },
21865   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomgeub",   IX86_BUILTIN_PCOMGEUB,   GEU,          (int)MULTI_ARG_2_QI_CMP },
21866
21867   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomequw",   IX86_BUILTIN_PCOMEQUW,   EQ,           (int)MULTI_ARG_2_HI_CMP },
21868   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomneuw",   IX86_BUILTIN_PCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
21869   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomnequw",  IX86_BUILTIN_PCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
21870   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomltuw",   IX86_BUILTIN_PCOMLTUW,   LTU,          (int)MULTI_ARG_2_HI_CMP },
21871   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomleuw",   IX86_BUILTIN_PCOMLEUW,   LEU,          (int)MULTI_ARG_2_HI_CMP },
21872   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomgtuw",   IX86_BUILTIN_PCOMGTUW,   GTU,          (int)MULTI_ARG_2_HI_CMP },
21873   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomgeuw",   IX86_BUILTIN_PCOMGEUW,   GEU,          (int)MULTI_ARG_2_HI_CMP },
21874
21875   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomequd",   IX86_BUILTIN_PCOMEQUD,   EQ,           (int)MULTI_ARG_2_SI_CMP },
21876   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomneud",   IX86_BUILTIN_PCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
21877   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomnequd",  IX86_BUILTIN_PCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
21878   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomltud",   IX86_BUILTIN_PCOMLTUD,   LTU,          (int)MULTI_ARG_2_SI_CMP },
21879   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomleud",   IX86_BUILTIN_PCOMLEUD,   LEU,          (int)MULTI_ARG_2_SI_CMP },
21880   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomgtud",   IX86_BUILTIN_PCOMGTUD,   GTU,          (int)MULTI_ARG_2_SI_CMP },
21881   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomgeud",   IX86_BUILTIN_PCOMGEUD,   GEU,          (int)MULTI_ARG_2_SI_CMP },
21882
21883   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomequq",   IX86_BUILTIN_PCOMEQUQ,   EQ,           (int)MULTI_ARG_2_DI_CMP },
21884   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomneuq",   IX86_BUILTIN_PCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
21885   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomnequq",  IX86_BUILTIN_PCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
21886   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomltuq",   IX86_BUILTIN_PCOMLTUQ,   LTU,          (int)MULTI_ARG_2_DI_CMP },
21887   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomleuq",   IX86_BUILTIN_PCOMLEUQ,   LEU,          (int)MULTI_ARG_2_DI_CMP },
21888   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomgtuq",   IX86_BUILTIN_PCOMGTUQ,   GTU,          (int)MULTI_ARG_2_DI_CMP },
21889   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomgeuq",   IX86_BUILTIN_PCOMGEUQ,   GEU,          (int)MULTI_ARG_2_DI_CMP },
21890
21891   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comfalsess", IX86_BUILTIN_COMFALSESS, COM_FALSE_S,  (int)MULTI_ARG_2_SF_TF },
21892   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comtruess",  IX86_BUILTIN_COMTRUESS,  COM_TRUE_S,   (int)MULTI_ARG_2_SF_TF },
21893   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comfalseps", IX86_BUILTIN_COMFALSEPS, COM_FALSE_P,  (int)MULTI_ARG_2_SF_TF },
21894   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comtrueps",  IX86_BUILTIN_COMTRUEPS,  COM_TRUE_P,   (int)MULTI_ARG_2_SF_TF },
21895   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comfalsesd", IX86_BUILTIN_COMFALSESD, COM_FALSE_S,  (int)MULTI_ARG_2_DF_TF },
21896   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comtruesd",  IX86_BUILTIN_COMTRUESD,  COM_TRUE_S,   (int)MULTI_ARG_2_DF_TF },
21897   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comfalsepd", IX86_BUILTIN_COMFALSEPD, COM_FALSE_P,  (int)MULTI_ARG_2_DF_TF },
21898   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comtruepd",  IX86_BUILTIN_COMTRUEPD,  COM_TRUE_P,   (int)MULTI_ARG_2_DF_TF },
21899
21900   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomfalseb", IX86_BUILTIN_PCOMFALSEB, PCOM_FALSE,   (int)MULTI_ARG_2_QI_TF },
21901   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomfalsew", IX86_BUILTIN_PCOMFALSEW, PCOM_FALSE,   (int)MULTI_ARG_2_HI_TF },
21902   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomfalsed", IX86_BUILTIN_PCOMFALSED, PCOM_FALSE,   (int)MULTI_ARG_2_SI_TF },
21903   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomfalseq", IX86_BUILTIN_PCOMFALSEQ, PCOM_FALSE,   (int)MULTI_ARG_2_DI_TF },
21904   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomfalseub",IX86_BUILTIN_PCOMFALSEUB,PCOM_FALSE,   (int)MULTI_ARG_2_QI_TF },
21905   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomfalseuw",IX86_BUILTIN_PCOMFALSEUW,PCOM_FALSE,   (int)MULTI_ARG_2_HI_TF },
21906   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomfalseud",IX86_BUILTIN_PCOMFALSEUD,PCOM_FALSE,   (int)MULTI_ARG_2_SI_TF },
21907   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomfalseuq",IX86_BUILTIN_PCOMFALSEUQ,PCOM_FALSE,   (int)MULTI_ARG_2_DI_TF },
21908
21909   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomtrueb",  IX86_BUILTIN_PCOMTRUEB,  PCOM_TRUE,    (int)MULTI_ARG_2_QI_TF },
21910   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomtruew",  IX86_BUILTIN_PCOMTRUEW,  PCOM_TRUE,    (int)MULTI_ARG_2_HI_TF },
21911   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomtrued",  IX86_BUILTIN_PCOMTRUED,  PCOM_TRUE,    (int)MULTI_ARG_2_SI_TF },
21912   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomtrueq",  IX86_BUILTIN_PCOMTRUEQ,  PCOM_TRUE,    (int)MULTI_ARG_2_DI_TF },
21913   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomtrueub", IX86_BUILTIN_PCOMTRUEUB, PCOM_TRUE,    (int)MULTI_ARG_2_QI_TF },
21914   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomtrueuw", IX86_BUILTIN_PCOMTRUEUW, PCOM_TRUE,    (int)MULTI_ARG_2_HI_TF },
21915   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomtrueud", IX86_BUILTIN_PCOMTRUEUD, PCOM_TRUE,    (int)MULTI_ARG_2_SI_TF },
21916   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomtrueuq", IX86_BUILTIN_PCOMTRUEUQ, PCOM_TRUE,    (int)MULTI_ARG_2_DI_TF },
21917 };
21918
21919 /* Set up all the MMX/SSE builtins, even builtins for instructions that are not
21920    in the current target ISA to allow the user to compile particular modules
21921    with different target specific options that differ from the command line
21922    options.  */
21923 static void
21924 ix86_init_mmx_sse_builtins (void)
21925 {
21926   const struct builtin_description * d;
21927   size_t i;
21928
21929   tree V16QI_type_node = build_vector_type_for_mode (char_type_node, V16QImode);
21930   tree V2SI_type_node = build_vector_type_for_mode (intSI_type_node, V2SImode);
21931   tree V1DI_type_node
21932     = build_vector_type_for_mode (long_long_integer_type_node, V1DImode);
21933   tree V2SF_type_node = build_vector_type_for_mode (float_type_node, V2SFmode);
21934   tree V2DI_type_node
21935     = build_vector_type_for_mode (long_long_integer_type_node, V2DImode);
21936   tree V2DF_type_node = build_vector_type_for_mode (double_type_node, V2DFmode);
21937   tree V4SF_type_node = build_vector_type_for_mode (float_type_node, V4SFmode);
21938   tree V4SI_type_node = build_vector_type_for_mode (intSI_type_node, V4SImode);
21939   tree V4HI_type_node = build_vector_type_for_mode (intHI_type_node, V4HImode);
21940   tree V8QI_type_node = build_vector_type_for_mode (char_type_node, V8QImode);
21941   tree V8HI_type_node = build_vector_type_for_mode (intHI_type_node, V8HImode);
21942
21943   tree pchar_type_node = build_pointer_type (char_type_node);
21944   tree pcchar_type_node
21945     = build_pointer_type (build_type_variant (char_type_node, 1, 0));
21946   tree pfloat_type_node = build_pointer_type (float_type_node);
21947   tree pcfloat_type_node
21948     = build_pointer_type (build_type_variant (float_type_node, 1, 0));
21949   tree pv2sf_type_node = build_pointer_type (V2SF_type_node);
21950   tree pcv2sf_type_node
21951     = build_pointer_type (build_type_variant (V2SF_type_node, 1, 0));
21952   tree pv2di_type_node = build_pointer_type (V2DI_type_node);
21953   tree pdi_type_node = build_pointer_type (long_long_unsigned_type_node);
21954
21955   /* Comparisons.  */
21956   tree int_ftype_v4sf_v4sf
21957     = build_function_type_list (integer_type_node,
21958                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
21959   tree v4si_ftype_v4sf_v4sf
21960     = build_function_type_list (V4SI_type_node,
21961                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
21962   /* MMX/SSE/integer conversions.  */
21963   tree int_ftype_v4sf
21964     = build_function_type_list (integer_type_node,
21965                                 V4SF_type_node, NULL_TREE);
21966   tree int64_ftype_v4sf
21967     = build_function_type_list (long_long_integer_type_node,
21968                                 V4SF_type_node, NULL_TREE);
21969   tree int_ftype_v8qi
21970     = build_function_type_list (integer_type_node, V8QI_type_node, NULL_TREE);
21971   tree v4sf_ftype_v4sf_int
21972     = build_function_type_list (V4SF_type_node,
21973                                 V4SF_type_node, integer_type_node, NULL_TREE);
21974   tree v4sf_ftype_v4sf_int64
21975     = build_function_type_list (V4SF_type_node,
21976                                 V4SF_type_node, long_long_integer_type_node,
21977                                 NULL_TREE);
21978   tree v4sf_ftype_v4sf_v2si
21979     = build_function_type_list (V4SF_type_node,
21980                                 V4SF_type_node, V2SI_type_node, NULL_TREE);
21981
21982   /* Miscellaneous.  */
21983   tree v8qi_ftype_v4hi_v4hi
21984     = build_function_type_list (V8QI_type_node,
21985                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
21986   tree v4hi_ftype_v2si_v2si
21987     = build_function_type_list (V4HI_type_node,
21988                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
21989   tree v4sf_ftype_v4sf_v4sf_int
21990     = build_function_type_list (V4SF_type_node,
21991                                 V4SF_type_node, V4SF_type_node,
21992                                 integer_type_node, NULL_TREE);
21993   tree v2si_ftype_v4hi_v4hi
21994     = build_function_type_list (V2SI_type_node,
21995                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
21996   tree v4hi_ftype_v4hi_int
21997     = build_function_type_list (V4HI_type_node,
21998                                 V4HI_type_node, integer_type_node, NULL_TREE);
21999   tree v2si_ftype_v2si_int
22000     = build_function_type_list (V2SI_type_node,
22001                                 V2SI_type_node, integer_type_node, NULL_TREE);
22002   tree v1di_ftype_v1di_int
22003     = build_function_type_list (V1DI_type_node,
22004                                 V1DI_type_node, integer_type_node, NULL_TREE);
22005
22006   tree void_ftype_void
22007     = build_function_type (void_type_node, void_list_node);
22008   tree void_ftype_unsigned
22009     = build_function_type_list (void_type_node, unsigned_type_node, NULL_TREE);
22010   tree void_ftype_unsigned_unsigned
22011     = build_function_type_list (void_type_node, unsigned_type_node,
22012                                 unsigned_type_node, NULL_TREE);
22013   tree void_ftype_pcvoid_unsigned_unsigned
22014     = build_function_type_list (void_type_node, const_ptr_type_node,
22015                                 unsigned_type_node, unsigned_type_node,
22016                                 NULL_TREE);
22017   tree unsigned_ftype_void
22018     = build_function_type (unsigned_type_node, void_list_node);
22019   tree v2si_ftype_v4sf
22020     = build_function_type_list (V2SI_type_node, V4SF_type_node, NULL_TREE);
22021   /* Loads/stores.  */
22022   tree void_ftype_v8qi_v8qi_pchar
22023     = build_function_type_list (void_type_node,
22024                                 V8QI_type_node, V8QI_type_node,
22025                                 pchar_type_node, NULL_TREE);
22026   tree v4sf_ftype_pcfloat
22027     = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
22028   tree v4sf_ftype_v4sf_pcv2sf
22029     = build_function_type_list (V4SF_type_node,
22030                                 V4SF_type_node, pcv2sf_type_node, NULL_TREE);
22031   tree void_ftype_pv2sf_v4sf
22032     = build_function_type_list (void_type_node,
22033                                 pv2sf_type_node, V4SF_type_node, NULL_TREE);
22034   tree void_ftype_pfloat_v4sf
22035     = build_function_type_list (void_type_node,
22036                                 pfloat_type_node, V4SF_type_node, NULL_TREE);
22037   tree void_ftype_pdi_di
22038     = build_function_type_list (void_type_node,
22039                                 pdi_type_node, long_long_unsigned_type_node,
22040                                 NULL_TREE);
22041   tree void_ftype_pv2di_v2di
22042     = build_function_type_list (void_type_node,
22043                                 pv2di_type_node, V2DI_type_node, NULL_TREE);
22044   /* Normal vector unops.  */
22045   tree v4sf_ftype_v4sf
22046     = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
22047   tree v16qi_ftype_v16qi
22048     = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
22049   tree v8hi_ftype_v8hi
22050     = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
22051   tree v4si_ftype_v4si
22052     = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
22053   tree v8qi_ftype_v8qi
22054     = build_function_type_list (V8QI_type_node, V8QI_type_node, NULL_TREE);
22055   tree v4hi_ftype_v4hi
22056     = build_function_type_list (V4HI_type_node, V4HI_type_node, NULL_TREE);
22057
22058   /* Normal vector binops.  */
22059   tree v4sf_ftype_v4sf_v4sf
22060     = build_function_type_list (V4SF_type_node,
22061                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
22062   tree v8qi_ftype_v8qi_v8qi
22063     = build_function_type_list (V8QI_type_node,
22064                                 V8QI_type_node, V8QI_type_node, NULL_TREE);
22065   tree v4hi_ftype_v4hi_v4hi
22066     = build_function_type_list (V4HI_type_node,
22067                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
22068   tree v2si_ftype_v2si_v2si
22069     = build_function_type_list (V2SI_type_node,
22070                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
22071   tree v1di_ftype_v1di_v1di
22072     = build_function_type_list (V1DI_type_node,
22073                                 V1DI_type_node, V1DI_type_node, NULL_TREE);
22074   tree v1di_ftype_v1di_v1di_int
22075     = build_function_type_list (V1DI_type_node,
22076                                 V1DI_type_node, V1DI_type_node,
22077                                 integer_type_node, NULL_TREE);
22078   tree v2si_ftype_v2sf
22079     = build_function_type_list (V2SI_type_node, V2SF_type_node, NULL_TREE);
22080   tree v2sf_ftype_v2si
22081     = build_function_type_list (V2SF_type_node, V2SI_type_node, NULL_TREE);
22082   tree v2si_ftype_v2si
22083     = build_function_type_list (V2SI_type_node, V2SI_type_node, NULL_TREE);
22084   tree v2sf_ftype_v2sf
22085     = build_function_type_list (V2SF_type_node, V2SF_type_node, NULL_TREE);
22086   tree v2sf_ftype_v2sf_v2sf
22087     = build_function_type_list (V2SF_type_node,
22088                                 V2SF_type_node, V2SF_type_node, NULL_TREE);
22089   tree v2si_ftype_v2sf_v2sf
22090     = build_function_type_list (V2SI_type_node,
22091                                 V2SF_type_node, V2SF_type_node, NULL_TREE);
22092   tree pint_type_node    = build_pointer_type (integer_type_node);
22093   tree pdouble_type_node = build_pointer_type (double_type_node);
22094   tree pcdouble_type_node = build_pointer_type (
22095                                 build_type_variant (double_type_node, 1, 0));
22096   tree int_ftype_v2df_v2df
22097     = build_function_type_list (integer_type_node,
22098                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
22099
22100   tree void_ftype_pcvoid
22101     = build_function_type_list (void_type_node, const_ptr_type_node, NULL_TREE);
22102   tree v4sf_ftype_v4si
22103     = build_function_type_list (V4SF_type_node, V4SI_type_node, NULL_TREE);
22104   tree v4si_ftype_v4sf
22105     = build_function_type_list (V4SI_type_node, V4SF_type_node, NULL_TREE);
22106   tree v2df_ftype_v4si
22107     = build_function_type_list (V2DF_type_node, V4SI_type_node, NULL_TREE);
22108   tree v4si_ftype_v2df
22109     = build_function_type_list (V4SI_type_node, V2DF_type_node, NULL_TREE);
22110   tree v4si_ftype_v2df_v2df
22111     = build_function_type_list (V4SI_type_node,
22112                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
22113   tree v2si_ftype_v2df
22114     = build_function_type_list (V2SI_type_node, V2DF_type_node, NULL_TREE);
22115   tree v4sf_ftype_v2df
22116     = build_function_type_list (V4SF_type_node, V2DF_type_node, NULL_TREE);
22117   tree v2df_ftype_v2si
22118     = build_function_type_list (V2DF_type_node, V2SI_type_node, NULL_TREE);
22119   tree v2df_ftype_v4sf
22120     = build_function_type_list (V2DF_type_node, V4SF_type_node, NULL_TREE);
22121   tree int_ftype_v2df
22122     = build_function_type_list (integer_type_node, V2DF_type_node, NULL_TREE);
22123   tree int64_ftype_v2df
22124     = build_function_type_list (long_long_integer_type_node,
22125                                 V2DF_type_node, NULL_TREE);
22126   tree v2df_ftype_v2df_int
22127     = build_function_type_list (V2DF_type_node,
22128                                 V2DF_type_node, integer_type_node, NULL_TREE);
22129   tree v2df_ftype_v2df_int64
22130     = build_function_type_list (V2DF_type_node,
22131                                 V2DF_type_node, long_long_integer_type_node,
22132                                 NULL_TREE);
22133   tree v4sf_ftype_v4sf_v2df
22134     = build_function_type_list (V4SF_type_node,
22135                                 V4SF_type_node, V2DF_type_node, NULL_TREE);
22136   tree v2df_ftype_v2df_v4sf
22137     = build_function_type_list (V2DF_type_node,
22138                                 V2DF_type_node, V4SF_type_node, NULL_TREE);
22139   tree v2df_ftype_v2df_v2df_int
22140     = build_function_type_list (V2DF_type_node,
22141                                 V2DF_type_node, V2DF_type_node,
22142                                 integer_type_node,
22143                                 NULL_TREE);
22144   tree v2df_ftype_v2df_pcdouble
22145     = build_function_type_list (V2DF_type_node,
22146                                 V2DF_type_node, pcdouble_type_node, NULL_TREE);
22147   tree void_ftype_pdouble_v2df
22148     = build_function_type_list (void_type_node,
22149                                 pdouble_type_node, V2DF_type_node, NULL_TREE);
22150   tree void_ftype_pint_int
22151     = build_function_type_list (void_type_node,
22152                                 pint_type_node, integer_type_node, NULL_TREE);
22153   tree void_ftype_v16qi_v16qi_pchar
22154     = build_function_type_list (void_type_node,
22155                                 V16QI_type_node, V16QI_type_node,
22156                                 pchar_type_node, NULL_TREE);
22157   tree v2df_ftype_pcdouble
22158     = build_function_type_list (V2DF_type_node, pcdouble_type_node, NULL_TREE);
22159   tree v2df_ftype_v2df_v2df
22160     = build_function_type_list (V2DF_type_node,
22161                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
22162   tree v16qi_ftype_v16qi_v16qi
22163     = build_function_type_list (V16QI_type_node,
22164                                 V16QI_type_node, V16QI_type_node, NULL_TREE);
22165   tree v8hi_ftype_v8hi_v8hi
22166     = build_function_type_list (V8HI_type_node,
22167                                 V8HI_type_node, V8HI_type_node, NULL_TREE);
22168   tree v4si_ftype_v4si_v4si
22169     = build_function_type_list (V4SI_type_node,
22170                                 V4SI_type_node, V4SI_type_node, NULL_TREE);
22171   tree v2di_ftype_v2di_v2di
22172     = build_function_type_list (V2DI_type_node,
22173                                 V2DI_type_node, V2DI_type_node, NULL_TREE);
22174   tree v2di_ftype_v2df_v2df
22175     = build_function_type_list (V2DI_type_node,
22176                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
22177   tree v2df_ftype_v2df
22178     = build_function_type_list (V2DF_type_node, V2DF_type_node, NULL_TREE);
22179   tree v2di_ftype_v2di_int
22180     = build_function_type_list (V2DI_type_node,
22181                                 V2DI_type_node, integer_type_node, NULL_TREE);
22182   tree v2di_ftype_v2di_v2di_int
22183     = build_function_type_list (V2DI_type_node, V2DI_type_node,
22184                                 V2DI_type_node, integer_type_node, NULL_TREE);
22185   tree v4si_ftype_v4si_int
22186     = build_function_type_list (V4SI_type_node,
22187                                 V4SI_type_node, integer_type_node, NULL_TREE);
22188   tree v8hi_ftype_v8hi_int
22189     = build_function_type_list (V8HI_type_node,
22190                                 V8HI_type_node, integer_type_node, NULL_TREE);
22191   tree v4si_ftype_v8hi_v8hi
22192     = build_function_type_list (V4SI_type_node,
22193                                 V8HI_type_node, V8HI_type_node, NULL_TREE);
22194   tree v1di_ftype_v8qi_v8qi
22195     = build_function_type_list (V1DI_type_node,
22196                                 V8QI_type_node, V8QI_type_node, NULL_TREE);
22197   tree v1di_ftype_v2si_v2si
22198     = build_function_type_list (V1DI_type_node,
22199                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
22200   tree v2di_ftype_v16qi_v16qi
22201     = build_function_type_list (V2DI_type_node,
22202                                 V16QI_type_node, V16QI_type_node, NULL_TREE);
22203   tree v2di_ftype_v4si_v4si
22204     = build_function_type_list (V2DI_type_node,
22205                                 V4SI_type_node, V4SI_type_node, NULL_TREE);
22206   tree int_ftype_v16qi
22207     = build_function_type_list (integer_type_node, V16QI_type_node, NULL_TREE);
22208   tree v16qi_ftype_pcchar
22209     = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
22210   tree void_ftype_pchar_v16qi
22211     = build_function_type_list (void_type_node,
22212                                 pchar_type_node, V16QI_type_node, NULL_TREE);
22213
22214   tree v2di_ftype_v2di_unsigned_unsigned
22215     = build_function_type_list (V2DI_type_node, V2DI_type_node,
22216                                 unsigned_type_node, unsigned_type_node,
22217                                 NULL_TREE);
22218   tree v2di_ftype_v2di_v2di_unsigned_unsigned
22219     = build_function_type_list (V2DI_type_node, V2DI_type_node, V2DI_type_node,
22220                                 unsigned_type_node, unsigned_type_node,
22221                                 NULL_TREE);
22222   tree v2di_ftype_v2di_v16qi
22223     = build_function_type_list (V2DI_type_node, V2DI_type_node, V16QI_type_node,
22224                                 NULL_TREE);
22225   tree v2df_ftype_v2df_v2df_v2df
22226     = build_function_type_list (V2DF_type_node,
22227                                 V2DF_type_node, V2DF_type_node,
22228                                 V2DF_type_node, NULL_TREE);
22229   tree v4sf_ftype_v4sf_v4sf_v4sf
22230     = build_function_type_list (V4SF_type_node,
22231                                 V4SF_type_node, V4SF_type_node,
22232                                 V4SF_type_node, NULL_TREE);
22233   tree v8hi_ftype_v16qi
22234     = build_function_type_list (V8HI_type_node, V16QI_type_node,
22235                                 NULL_TREE);
22236   tree v4si_ftype_v16qi
22237     = build_function_type_list (V4SI_type_node, V16QI_type_node,
22238                                 NULL_TREE);
22239   tree v2di_ftype_v16qi
22240     = build_function_type_list (V2DI_type_node, V16QI_type_node,
22241                                 NULL_TREE);
22242   tree v4si_ftype_v8hi
22243     = build_function_type_list (V4SI_type_node, V8HI_type_node,
22244                                 NULL_TREE);
22245   tree v2di_ftype_v8hi
22246     = build_function_type_list (V2DI_type_node, V8HI_type_node,
22247                                 NULL_TREE);
22248   tree v2di_ftype_v4si
22249     = build_function_type_list (V2DI_type_node, V4SI_type_node,
22250                                 NULL_TREE);
22251   tree v2di_ftype_pv2di
22252     = build_function_type_list (V2DI_type_node, pv2di_type_node,
22253                                 NULL_TREE);
22254   tree v16qi_ftype_v16qi_v16qi_int
22255     = build_function_type_list (V16QI_type_node, V16QI_type_node,
22256                                 V16QI_type_node, integer_type_node,
22257                                 NULL_TREE);
22258   tree v16qi_ftype_v16qi_v16qi_v16qi
22259     = build_function_type_list (V16QI_type_node, V16QI_type_node,
22260                                 V16QI_type_node, V16QI_type_node,
22261                                 NULL_TREE);
22262   tree v8hi_ftype_v8hi_v8hi_int
22263     = build_function_type_list (V8HI_type_node, V8HI_type_node,
22264                                 V8HI_type_node, integer_type_node,
22265                                 NULL_TREE);
22266   tree v4si_ftype_v4si_v4si_int
22267     = build_function_type_list (V4SI_type_node, V4SI_type_node,
22268                                 V4SI_type_node, integer_type_node,
22269                                 NULL_TREE);
22270   tree int_ftype_v2di_v2di
22271     = build_function_type_list (integer_type_node,
22272                                 V2DI_type_node, V2DI_type_node,
22273                                 NULL_TREE);
22274   tree int_ftype_v16qi_int_v16qi_int_int
22275     = build_function_type_list (integer_type_node,
22276                                 V16QI_type_node,
22277                                 integer_type_node,
22278                                 V16QI_type_node,
22279                                 integer_type_node,
22280                                 integer_type_node,
22281                                 NULL_TREE);
22282   tree v16qi_ftype_v16qi_int_v16qi_int_int
22283     = build_function_type_list (V16QI_type_node,
22284                                 V16QI_type_node,
22285                                 integer_type_node,
22286                                 V16QI_type_node,
22287                                 integer_type_node,
22288                                 integer_type_node,
22289                                 NULL_TREE);
22290   tree int_ftype_v16qi_v16qi_int
22291     = build_function_type_list (integer_type_node,
22292                                 V16QI_type_node,
22293                                 V16QI_type_node,
22294                                 integer_type_node,
22295                                 NULL_TREE);
22296
22297   /* SSE5 instructions */
22298   tree v2di_ftype_v2di_v2di_v2di
22299     = build_function_type_list (V2DI_type_node,
22300                                 V2DI_type_node,
22301                                 V2DI_type_node,
22302                                 V2DI_type_node,
22303                                 NULL_TREE);
22304
22305   tree v4si_ftype_v4si_v4si_v4si
22306     = build_function_type_list (V4SI_type_node,
22307                                 V4SI_type_node,
22308                                 V4SI_type_node,
22309                                 V4SI_type_node,
22310                                 NULL_TREE);
22311
22312   tree v4si_ftype_v4si_v4si_v2di
22313     = build_function_type_list (V4SI_type_node,
22314                                 V4SI_type_node,
22315                                 V4SI_type_node,
22316                                 V2DI_type_node,
22317                                 NULL_TREE);
22318
22319   tree v8hi_ftype_v8hi_v8hi_v8hi
22320     = build_function_type_list (V8HI_type_node,
22321                                 V8HI_type_node,
22322                                 V8HI_type_node,
22323                                 V8HI_type_node,
22324                                 NULL_TREE);
22325
22326   tree v8hi_ftype_v8hi_v8hi_v4si
22327     = build_function_type_list (V8HI_type_node,
22328                                 V8HI_type_node,
22329                                 V8HI_type_node,
22330                                 V4SI_type_node,
22331                                 NULL_TREE);
22332
22333   tree v2df_ftype_v2df_v2df_v16qi
22334     = build_function_type_list (V2DF_type_node,
22335                                 V2DF_type_node,
22336                                 V2DF_type_node,
22337                                 V16QI_type_node,
22338                                 NULL_TREE);
22339
22340   tree v4sf_ftype_v4sf_v4sf_v16qi
22341     = build_function_type_list (V4SF_type_node,
22342                                 V4SF_type_node,
22343                                 V4SF_type_node,
22344                                 V16QI_type_node,
22345                                 NULL_TREE);
22346
22347   tree v2di_ftype_v2di_si
22348     = build_function_type_list (V2DI_type_node,
22349                                 V2DI_type_node,
22350                                 integer_type_node,
22351                                 NULL_TREE);
22352
22353   tree v4si_ftype_v4si_si
22354     = build_function_type_list (V4SI_type_node,
22355                                 V4SI_type_node,
22356                                 integer_type_node,
22357                                 NULL_TREE);
22358
22359   tree v8hi_ftype_v8hi_si
22360     = build_function_type_list (V8HI_type_node,
22361                                 V8HI_type_node,
22362                                 integer_type_node,
22363                                 NULL_TREE);
22364
22365   tree v16qi_ftype_v16qi_si
22366     = build_function_type_list (V16QI_type_node,
22367                                 V16QI_type_node,
22368                                 integer_type_node,
22369                                 NULL_TREE);
22370   tree v4sf_ftype_v4hi
22371     = build_function_type_list (V4SF_type_node,
22372                                 V4HI_type_node,
22373                                 NULL_TREE);
22374
22375   tree v4hi_ftype_v4sf
22376     = build_function_type_list (V4HI_type_node,
22377                                 V4SF_type_node,
22378                                 NULL_TREE);
22379
22380   tree v2di_ftype_v2di
22381     = build_function_type_list (V2DI_type_node, V2DI_type_node, NULL_TREE);
22382
22383   tree v16qi_ftype_v8hi_v8hi
22384     = build_function_type_list (V16QI_type_node,
22385                                 V8HI_type_node, V8HI_type_node,
22386                                 NULL_TREE);
22387   tree v8hi_ftype_v4si_v4si
22388     = build_function_type_list (V8HI_type_node,
22389                                 V4SI_type_node, V4SI_type_node,
22390                                 NULL_TREE);
22391   tree v8hi_ftype_v16qi_v16qi 
22392     = build_function_type_list (V8HI_type_node,
22393                                 V16QI_type_node, V16QI_type_node,
22394                                 NULL_TREE);
22395   tree v4hi_ftype_v8qi_v8qi 
22396     = build_function_type_list (V4HI_type_node,
22397                                 V8QI_type_node, V8QI_type_node,
22398                                 NULL_TREE);
22399   tree unsigned_ftype_unsigned_uchar
22400     = build_function_type_list (unsigned_type_node,
22401                                 unsigned_type_node,
22402                                 unsigned_char_type_node,
22403                                 NULL_TREE);
22404   tree unsigned_ftype_unsigned_ushort
22405     = build_function_type_list (unsigned_type_node,
22406                                 unsigned_type_node,
22407                                 short_unsigned_type_node,
22408                                 NULL_TREE);
22409   tree unsigned_ftype_unsigned_unsigned
22410     = build_function_type_list (unsigned_type_node,
22411                                 unsigned_type_node,
22412                                 unsigned_type_node,
22413                                 NULL_TREE);
22414   tree uint64_ftype_uint64_uint64
22415     = build_function_type_list (long_long_unsigned_type_node,
22416                                 long_long_unsigned_type_node,
22417                                 long_long_unsigned_type_node,
22418                                 NULL_TREE);
22419   tree float_ftype_float
22420     = build_function_type_list (float_type_node,
22421                                 float_type_node,
22422                                 NULL_TREE);
22423
22424   /* AVX builtins  */
22425   tree V32QI_type_node = build_vector_type_for_mode (char_type_node,
22426                                                      V32QImode);
22427   tree V8SI_type_node = build_vector_type_for_mode (intSI_type_node,
22428                                                     V8SImode);
22429   tree V8SF_type_node = build_vector_type_for_mode (float_type_node,
22430                                                     V8SFmode);
22431   tree V4DI_type_node = build_vector_type_for_mode (long_long_integer_type_node,
22432                                                     V4DImode);
22433   tree V4DF_type_node = build_vector_type_for_mode (double_type_node,
22434                                                     V4DFmode);
22435   tree v8sf_ftype_v8sf
22436     = build_function_type_list (V8SF_type_node,
22437                                 V8SF_type_node,
22438                                 NULL_TREE);
22439   tree v8si_ftype_v8sf
22440     = build_function_type_list (V8SI_type_node,
22441                                 V8SF_type_node,
22442                                 NULL_TREE);
22443   tree v8sf_ftype_v8si
22444     = build_function_type_list (V8SF_type_node,
22445                                 V8SI_type_node,
22446                                 NULL_TREE);
22447   tree v4si_ftype_v4df
22448     = build_function_type_list (V4SI_type_node,
22449                                 V4DF_type_node,
22450                                 NULL_TREE);
22451   tree v4df_ftype_v4df
22452     = build_function_type_list (V4DF_type_node,
22453                                 V4DF_type_node,
22454                                 NULL_TREE);
22455   tree v4df_ftype_v4si
22456     = build_function_type_list (V4DF_type_node,
22457                                 V4SI_type_node,
22458                                 NULL_TREE);
22459   tree v4df_ftype_v4sf
22460     = build_function_type_list (V4DF_type_node,
22461                                 V4SF_type_node,
22462                                 NULL_TREE);
22463   tree v4sf_ftype_v4df
22464     = build_function_type_list (V4SF_type_node,
22465                                 V4DF_type_node,
22466                                 NULL_TREE);
22467   tree v8sf_ftype_v8sf_v8sf
22468     = build_function_type_list (V8SF_type_node,
22469                                 V8SF_type_node, V8SF_type_node,
22470                                 NULL_TREE);
22471   tree v4df_ftype_v4df_v4df
22472     = build_function_type_list (V4DF_type_node,
22473                                 V4DF_type_node, V4DF_type_node,
22474                                 NULL_TREE);
22475   tree v8sf_ftype_v8sf_int
22476     = build_function_type_list (V8SF_type_node,
22477                                 V8SF_type_node, integer_type_node,
22478                                 NULL_TREE);
22479   tree v4si_ftype_v8si_int
22480     = build_function_type_list (V4SI_type_node,
22481                                 V8SI_type_node, integer_type_node,
22482                                 NULL_TREE);
22483   tree v4df_ftype_v4df_int
22484     = build_function_type_list (V4DF_type_node,
22485                                 V4DF_type_node, integer_type_node,
22486                                 NULL_TREE);
22487   tree v4sf_ftype_v8sf_int
22488     = build_function_type_list (V4SF_type_node,
22489                                 V8SF_type_node, integer_type_node,
22490                                 NULL_TREE);
22491   tree v2df_ftype_v4df_int
22492     = build_function_type_list (V2DF_type_node,
22493                                 V4DF_type_node, integer_type_node,
22494                                 NULL_TREE);
22495   tree v8sf_ftype_v8sf_v8sf_int
22496     = build_function_type_list (V8SF_type_node,
22497                                 V8SF_type_node, V8SF_type_node,
22498                                 integer_type_node,
22499                                 NULL_TREE);
22500   tree v8sf_ftype_v8sf_v8sf_v8sf
22501     = build_function_type_list (V8SF_type_node,
22502                                 V8SF_type_node, V8SF_type_node,
22503                                 V8SF_type_node,
22504                                 NULL_TREE);
22505   tree v4df_ftype_v4df_v4df_v4df
22506     = build_function_type_list (V4DF_type_node,
22507                                 V4DF_type_node, V4DF_type_node,
22508                                 V4DF_type_node,
22509                                 NULL_TREE);
22510   tree v8si_ftype_v8si_v8si_int
22511     = build_function_type_list (V8SI_type_node,
22512                                 V8SI_type_node, V8SI_type_node,
22513                                 integer_type_node,
22514                                 NULL_TREE);
22515   tree v4df_ftype_v4df_v4df_int
22516     = build_function_type_list (V4DF_type_node,
22517                                 V4DF_type_node, V4DF_type_node,
22518                                 integer_type_node,
22519                                 NULL_TREE);
22520   tree v8sf_ftype_pcfloat
22521     = build_function_type_list (V8SF_type_node,
22522                                 pcfloat_type_node,
22523                                 NULL_TREE);
22524   tree v4df_ftype_pcdouble
22525     = build_function_type_list (V4DF_type_node,
22526                                 pcdouble_type_node,
22527                                 NULL_TREE);
22528   tree pcv4sf_type_node
22529     = build_pointer_type (build_type_variant (V4SF_type_node, 1, 0));
22530   tree pcv2df_type_node
22531     = build_pointer_type (build_type_variant (V2DF_type_node, 1, 0));
22532   tree v8sf_ftype_pcv4sf
22533     = build_function_type_list (V8SF_type_node,
22534                                 pcv4sf_type_node,
22535                                 NULL_TREE);
22536   tree v4df_ftype_pcv2df
22537     = build_function_type_list (V4DF_type_node,
22538                                 pcv2df_type_node,
22539                                 NULL_TREE);
22540   tree v32qi_ftype_pcchar
22541     = build_function_type_list (V32QI_type_node,
22542                                 pcchar_type_node,
22543                                 NULL_TREE);
22544   tree void_ftype_pchar_v32qi
22545     = build_function_type_list (void_type_node,
22546                                 pchar_type_node, V32QI_type_node,
22547                                 NULL_TREE);
22548   tree v8si_ftype_v8si_v4si_int
22549     = build_function_type_list (V8SI_type_node,
22550                                 V8SI_type_node, V4SI_type_node,
22551                                 integer_type_node,
22552                                 NULL_TREE);
22553   tree pv4di_type_node = build_pointer_type (V4DI_type_node);
22554   tree void_ftype_pv4di_v4di
22555     = build_function_type_list (void_type_node,
22556                                 pv4di_type_node, V4DI_type_node,
22557                                 NULL_TREE);
22558   tree v8sf_ftype_v8sf_v4sf_int
22559     = build_function_type_list (V8SF_type_node,
22560                                 V8SF_type_node, V4SF_type_node,
22561                                 integer_type_node,
22562                                 NULL_TREE);
22563   tree v4df_ftype_v4df_v2df_int
22564     = build_function_type_list (V4DF_type_node,
22565                                 V4DF_type_node, V2DF_type_node,
22566                                 integer_type_node,
22567                                 NULL_TREE);
22568   tree void_ftype_pfloat_v8sf
22569     = build_function_type_list (void_type_node,
22570                                 pfloat_type_node, V8SF_type_node,
22571                                 NULL_TREE);
22572   tree void_ftype_pdouble_v4df
22573     = build_function_type_list (void_type_node,
22574                                 pdouble_type_node, V4DF_type_node,
22575                                 NULL_TREE);
22576   tree pv8sf_type_node = build_pointer_type (V8SF_type_node);
22577   tree pv4sf_type_node = build_pointer_type (V4SF_type_node);
22578   tree pv4df_type_node = build_pointer_type (V4DF_type_node);
22579   tree pv2df_type_node = build_pointer_type (V2DF_type_node);
22580   tree pcv8sf_type_node
22581     = build_pointer_type (build_type_variant (V8SF_type_node, 1, 0));
22582   tree pcv4df_type_node
22583     = build_pointer_type (build_type_variant (V4DF_type_node, 1, 0));
22584   tree v8sf_ftype_pcv8sf_v8sf
22585     = build_function_type_list (V8SF_type_node,
22586                                 pcv8sf_type_node, V8SF_type_node,
22587                                 NULL_TREE);
22588   tree v4df_ftype_pcv4df_v4df
22589     = build_function_type_list (V4DF_type_node,
22590                                 pcv4df_type_node, V4DF_type_node,
22591                                 NULL_TREE);
22592   tree v4sf_ftype_pcv4sf_v4sf
22593     = build_function_type_list (V4SF_type_node,
22594                                 pcv4sf_type_node, V4SF_type_node,
22595                                 NULL_TREE);
22596   tree v2df_ftype_pcv2df_v2df
22597     = build_function_type_list (V2DF_type_node,
22598                                 pcv2df_type_node, V2DF_type_node,
22599                                 NULL_TREE);
22600   tree void_ftype_pv8sf_v8sf_v8sf
22601     = build_function_type_list (void_type_node,
22602                                 pv8sf_type_node, V8SF_type_node,
22603                                 V8SF_type_node,
22604                                 NULL_TREE);
22605   tree void_ftype_pv4df_v4df_v4df
22606     = build_function_type_list (void_type_node,
22607                                 pv4df_type_node, V4DF_type_node,
22608                                 V4DF_type_node,
22609                                 NULL_TREE);
22610   tree void_ftype_pv4sf_v4sf_v4sf
22611     = build_function_type_list (void_type_node,
22612                                 pv4sf_type_node, V4SF_type_node,
22613                                 V4SF_type_node,
22614                                 NULL_TREE);
22615   tree void_ftype_pv2df_v2df_v2df
22616     = build_function_type_list (void_type_node,
22617                                 pv2df_type_node, V2DF_type_node,
22618                                 V2DF_type_node,
22619                                 NULL_TREE);
22620   tree v4df_ftype_v2df
22621     = build_function_type_list (V4DF_type_node,
22622                                 V2DF_type_node,
22623                                 NULL_TREE);
22624   tree v8sf_ftype_v4sf
22625     = build_function_type_list (V8SF_type_node,
22626                                 V4SF_type_node,
22627                                 NULL_TREE);
22628   tree v8si_ftype_v4si
22629     = build_function_type_list (V8SI_type_node,
22630                                 V4SI_type_node,
22631                                 NULL_TREE);
22632   tree v2df_ftype_v4df
22633     = build_function_type_list (V2DF_type_node,
22634                                 V4DF_type_node,
22635                                 NULL_TREE);
22636   tree v4sf_ftype_v8sf
22637     = build_function_type_list (V4SF_type_node,
22638                                 V8SF_type_node,
22639                                 NULL_TREE);
22640   tree v4si_ftype_v8si
22641     = build_function_type_list (V4SI_type_node,
22642                                 V8SI_type_node,
22643                                 NULL_TREE);
22644   tree int_ftype_v4df
22645     = build_function_type_list (integer_type_node,
22646                                 V4DF_type_node,
22647                                 NULL_TREE);
22648   tree int_ftype_v8sf
22649     = build_function_type_list (integer_type_node,
22650                                 V8SF_type_node,
22651                                 NULL_TREE);
22652   tree int_ftype_v8sf_v8sf
22653     = build_function_type_list (integer_type_node,
22654                                 V8SF_type_node, V8SF_type_node,
22655                                 NULL_TREE);
22656   tree int_ftype_v4di_v4di
22657     = build_function_type_list (integer_type_node,
22658                                 V4DI_type_node, V4DI_type_node,
22659                                 NULL_TREE);
22660   tree int_ftype_v4df_v4df
22661     = build_function_type_list (integer_type_node,
22662                                 V4DF_type_node, V4DF_type_node,
22663                                 NULL_TREE);
22664   tree v8sf_ftype_v8sf_v8si
22665     = build_function_type_list (V8SF_type_node,
22666                                 V8SF_type_node, V8SI_type_node,
22667                                 NULL_TREE);
22668   tree v4df_ftype_v4df_v4di
22669     = build_function_type_list (V4DF_type_node,
22670                                 V4DF_type_node, V4DI_type_node,
22671                                 NULL_TREE);
22672   tree v4sf_ftype_v4sf_v4si
22673     = build_function_type_list (V4SF_type_node,
22674                                 V4SF_type_node, V4SI_type_node, NULL_TREE);
22675   tree v2df_ftype_v2df_v2di
22676     = build_function_type_list (V2DF_type_node,
22677                                 V2DF_type_node, V2DI_type_node, NULL_TREE);
22678
22679   tree ftype;
22680
22681   /* Add all special builtins with variable number of operands.  */
22682   for (i = 0, d = bdesc_special_args;
22683        i < ARRAY_SIZE (bdesc_special_args);
22684        i++, d++)
22685     {
22686       tree type;
22687
22688       if (d->name == 0)
22689         continue;
22690
22691       switch ((enum ix86_special_builtin_type) d->flag)
22692         {
22693         case VOID_FTYPE_VOID:
22694           type = void_ftype_void;
22695           break;
22696         case V32QI_FTYPE_PCCHAR:
22697           type = v32qi_ftype_pcchar;
22698           break;
22699         case V16QI_FTYPE_PCCHAR:
22700           type = v16qi_ftype_pcchar;
22701           break;
22702         case V8SF_FTYPE_PCV4SF:
22703           type = v8sf_ftype_pcv4sf;
22704           break;
22705         case V8SF_FTYPE_PCFLOAT:
22706           type = v8sf_ftype_pcfloat;
22707           break;
22708         case V4DF_FTYPE_PCV2DF:
22709           type = v4df_ftype_pcv2df;
22710           break;
22711         case V4DF_FTYPE_PCDOUBLE:
22712           type = v4df_ftype_pcdouble;
22713           break;
22714         case V4SF_FTYPE_PCFLOAT:
22715           type = v4sf_ftype_pcfloat;
22716           break;
22717         case V2DI_FTYPE_PV2DI:
22718           type = v2di_ftype_pv2di;
22719           break;
22720         case V2DF_FTYPE_PCDOUBLE:
22721           type = v2df_ftype_pcdouble;
22722           break;
22723         case V8SF_FTYPE_PCV8SF_V8SF:
22724           type = v8sf_ftype_pcv8sf_v8sf;
22725           break;
22726         case V4DF_FTYPE_PCV4DF_V4DF:
22727           type = v4df_ftype_pcv4df_v4df;
22728           break;
22729         case V4SF_FTYPE_V4SF_PCV2SF:
22730           type = v4sf_ftype_v4sf_pcv2sf;
22731           break;
22732         case V4SF_FTYPE_PCV4SF_V4SF:
22733           type = v4sf_ftype_pcv4sf_v4sf;
22734           break;
22735         case V2DF_FTYPE_V2DF_PCDOUBLE:
22736           type = v2df_ftype_v2df_pcdouble;
22737           break;
22738         case V2DF_FTYPE_PCV2DF_V2DF:
22739           type = v2df_ftype_pcv2df_v2df;
22740           break;
22741         case VOID_FTYPE_PV2SF_V4SF:
22742           type = void_ftype_pv2sf_v4sf;
22743           break;
22744         case VOID_FTYPE_PV4DI_V4DI:
22745           type = void_ftype_pv4di_v4di;
22746           break;
22747         case VOID_FTYPE_PV2DI_V2DI:
22748           type = void_ftype_pv2di_v2di;
22749           break;
22750         case VOID_FTYPE_PCHAR_V32QI:
22751           type = void_ftype_pchar_v32qi;
22752           break;
22753         case VOID_FTYPE_PCHAR_V16QI:
22754           type = void_ftype_pchar_v16qi;
22755           break;
22756         case VOID_FTYPE_PFLOAT_V8SF:
22757           type = void_ftype_pfloat_v8sf;
22758           break;
22759         case VOID_FTYPE_PFLOAT_V4SF:
22760           type = void_ftype_pfloat_v4sf;
22761           break;
22762         case VOID_FTYPE_PDOUBLE_V4DF:
22763           type = void_ftype_pdouble_v4df;
22764           break;
22765         case VOID_FTYPE_PDOUBLE_V2DF:
22766           type = void_ftype_pdouble_v2df;
22767           break;
22768         case VOID_FTYPE_PDI_DI:
22769           type = void_ftype_pdi_di;
22770           break;
22771         case VOID_FTYPE_PINT_INT:
22772           type = void_ftype_pint_int;
22773           break;
22774         case VOID_FTYPE_PV8SF_V8SF_V8SF:
22775           type = void_ftype_pv8sf_v8sf_v8sf;
22776           break;
22777         case VOID_FTYPE_PV4DF_V4DF_V4DF:
22778           type = void_ftype_pv4df_v4df_v4df;
22779           break;
22780         case VOID_FTYPE_PV4SF_V4SF_V4SF:
22781           type = void_ftype_pv4sf_v4sf_v4sf;
22782           break;
22783         case VOID_FTYPE_PV2DF_V2DF_V2DF:
22784           type = void_ftype_pv2df_v2df_v2df;
22785           break;
22786         default:
22787           gcc_unreachable ();
22788         }
22789
22790       def_builtin (d->mask, d->name, type, d->code);
22791     }
22792
22793   /* Add all builtins with variable number of operands.  */
22794   for (i = 0, d = bdesc_args;
22795        i < ARRAY_SIZE (bdesc_args);
22796        i++, d++)
22797     {
22798       tree type;
22799
22800       if (d->name == 0)
22801         continue;
22802
22803       switch ((enum ix86_builtin_type) d->flag)
22804         {
22805         case FLOAT_FTYPE_FLOAT:
22806           type = float_ftype_float;
22807           break;
22808         case INT_FTYPE_V8SF_V8SF_PTEST:
22809           type = int_ftype_v8sf_v8sf;
22810           break;
22811         case INT_FTYPE_V4DI_V4DI_PTEST:
22812           type = int_ftype_v4di_v4di;
22813           break;
22814         case INT_FTYPE_V4DF_V4DF_PTEST:
22815           type = int_ftype_v4df_v4df;
22816           break;
22817         case INT_FTYPE_V4SF_V4SF_PTEST:
22818           type = int_ftype_v4sf_v4sf;
22819           break;
22820         case INT_FTYPE_V2DI_V2DI_PTEST:
22821           type = int_ftype_v2di_v2di;
22822           break;
22823         case INT_FTYPE_V2DF_V2DF_PTEST:
22824           type = int_ftype_v2df_v2df;
22825           break;
22826         case INT64_FTYPE_V4SF:
22827           type = int64_ftype_v4sf;
22828           break;
22829         case INT64_FTYPE_V2DF:
22830           type = int64_ftype_v2df;
22831           break;
22832         case INT_FTYPE_V16QI:
22833           type = int_ftype_v16qi;
22834           break;
22835         case INT_FTYPE_V8QI:
22836           type = int_ftype_v8qi;
22837           break;
22838         case INT_FTYPE_V8SF:
22839           type = int_ftype_v8sf;
22840           break;
22841         case INT_FTYPE_V4DF:
22842           type = int_ftype_v4df;
22843           break;
22844         case INT_FTYPE_V4SF:
22845           type = int_ftype_v4sf;
22846           break;
22847         case INT_FTYPE_V2DF:
22848           type = int_ftype_v2df;
22849           break;
22850         case V16QI_FTYPE_V16QI:
22851           type = v16qi_ftype_v16qi;
22852           break;
22853         case V8SI_FTYPE_V8SF:
22854           type = v8si_ftype_v8sf;
22855           break;
22856         case V8SI_FTYPE_V4SI:
22857           type = v8si_ftype_v4si;
22858           break;
22859         case V8HI_FTYPE_V8HI:
22860           type = v8hi_ftype_v8hi;
22861           break;
22862         case V8HI_FTYPE_V16QI:
22863           type = v8hi_ftype_v16qi;
22864           break;
22865         case V8QI_FTYPE_V8QI:
22866           type = v8qi_ftype_v8qi;
22867           break;
22868         case V8SF_FTYPE_V8SF:
22869           type = v8sf_ftype_v8sf;
22870           break;
22871         case V8SF_FTYPE_V8SI:
22872           type = v8sf_ftype_v8si;
22873           break;
22874         case V8SF_FTYPE_V4SF:
22875           type = v8sf_ftype_v4sf;
22876           break;
22877         case V4SI_FTYPE_V4DF:
22878           type = v4si_ftype_v4df;
22879           break;
22880         case V4SI_FTYPE_V4SI:
22881           type = v4si_ftype_v4si;
22882           break;
22883         case V4SI_FTYPE_V16QI:
22884           type = v4si_ftype_v16qi;
22885           break;
22886         case V4SI_FTYPE_V8SI:
22887           type = v4si_ftype_v8si;
22888           break;
22889         case V4SI_FTYPE_V8HI:
22890           type = v4si_ftype_v8hi;
22891           break;
22892         case V4SI_FTYPE_V4SF:
22893           type = v4si_ftype_v4sf;
22894           break;
22895         case V4SI_FTYPE_V2DF:
22896           type = v4si_ftype_v2df;
22897           break;
22898         case V4HI_FTYPE_V4HI:
22899           type = v4hi_ftype_v4hi;
22900           break;
22901         case V4DF_FTYPE_V4DF:
22902           type = v4df_ftype_v4df;
22903           break;
22904         case V4DF_FTYPE_V4SI:
22905           type = v4df_ftype_v4si;
22906           break;
22907         case V4DF_FTYPE_V4SF:
22908           type = v4df_ftype_v4sf;
22909           break;
22910         case V4DF_FTYPE_V2DF:
22911           type = v4df_ftype_v2df;
22912           break;
22913         case V4SF_FTYPE_V4SF:
22914         case V4SF_FTYPE_V4SF_VEC_MERGE:
22915           type = v4sf_ftype_v4sf;
22916           break;
22917         case V4SF_FTYPE_V8SF:
22918           type = v4sf_ftype_v8sf;
22919           break;
22920         case V4SF_FTYPE_V4SI:
22921           type = v4sf_ftype_v4si;
22922           break;
22923         case V4SF_FTYPE_V4DF:
22924           type = v4sf_ftype_v4df;
22925           break;
22926         case V4SF_FTYPE_V2DF:
22927           type = v4sf_ftype_v2df;
22928           break;
22929         case V2DI_FTYPE_V2DI:
22930           type = v2di_ftype_v2di;
22931           break;
22932         case V2DI_FTYPE_V16QI:
22933           type = v2di_ftype_v16qi;
22934           break;
22935         case V2DI_FTYPE_V8HI:
22936           type = v2di_ftype_v8hi;
22937           break;
22938         case V2DI_FTYPE_V4SI:
22939           type = v2di_ftype_v4si;
22940           break;
22941         case V2SI_FTYPE_V2SI:
22942           type = v2si_ftype_v2si;
22943           break;
22944         case V2SI_FTYPE_V4SF:
22945           type = v2si_ftype_v4sf;
22946           break;
22947         case V2SI_FTYPE_V2DF:
22948           type = v2si_ftype_v2df;
22949           break;
22950         case V2SI_FTYPE_V2SF:
22951           type = v2si_ftype_v2sf;
22952           break;
22953         case V2DF_FTYPE_V4DF:
22954           type = v2df_ftype_v4df;
22955           break;
22956         case V2DF_FTYPE_V4SF:
22957           type = v2df_ftype_v4sf;
22958           break;
22959         case V2DF_FTYPE_V2DF:
22960         case V2DF_FTYPE_V2DF_VEC_MERGE:
22961           type = v2df_ftype_v2df;
22962           break;
22963         case V2DF_FTYPE_V2SI:
22964           type = v2df_ftype_v2si;
22965           break;
22966         case V2DF_FTYPE_V4SI:
22967           type = v2df_ftype_v4si;
22968           break;
22969         case V2SF_FTYPE_V2SF:
22970           type = v2sf_ftype_v2sf;
22971           break;
22972         case V2SF_FTYPE_V2SI:
22973           type = v2sf_ftype_v2si;
22974           break;
22975         case V16QI_FTYPE_V16QI_V16QI:
22976           type = v16qi_ftype_v16qi_v16qi;
22977           break;
22978         case V16QI_FTYPE_V8HI_V8HI:
22979           type = v16qi_ftype_v8hi_v8hi;
22980           break;
22981         case V8QI_FTYPE_V8QI_V8QI:
22982           type = v8qi_ftype_v8qi_v8qi;
22983           break;
22984         case V8QI_FTYPE_V4HI_V4HI:
22985           type = v8qi_ftype_v4hi_v4hi;
22986           break;
22987         case V8HI_FTYPE_V8HI_V8HI:
22988         case V8HI_FTYPE_V8HI_V8HI_COUNT:
22989           type = v8hi_ftype_v8hi_v8hi;
22990           break;
22991         case V8HI_FTYPE_V16QI_V16QI:
22992           type = v8hi_ftype_v16qi_v16qi;
22993           break;
22994         case V8HI_FTYPE_V4SI_V4SI:
22995           type = v8hi_ftype_v4si_v4si;
22996           break;
22997         case V8HI_FTYPE_V8HI_SI_COUNT:
22998           type = v8hi_ftype_v8hi_int;
22999           break;
23000         case V8SF_FTYPE_V8SF_V8SF:
23001           type = v8sf_ftype_v8sf_v8sf;
23002           break;
23003         case V8SF_FTYPE_V8SF_V8SI:
23004           type = v8sf_ftype_v8sf_v8si;
23005           break;
23006         case V4SI_FTYPE_V4SI_V4SI:
23007         case V4SI_FTYPE_V4SI_V4SI_COUNT:
23008           type = v4si_ftype_v4si_v4si;
23009           break;
23010         case V4SI_FTYPE_V8HI_V8HI:
23011           type = v4si_ftype_v8hi_v8hi;
23012           break;
23013         case V4SI_FTYPE_V4SF_V4SF:
23014           type = v4si_ftype_v4sf_v4sf;
23015           break;
23016         case V4SI_FTYPE_V2DF_V2DF:
23017           type = v4si_ftype_v2df_v2df;
23018           break;
23019         case V4SI_FTYPE_V4SI_SI_COUNT:
23020           type = v4si_ftype_v4si_int;
23021           break;
23022         case V4HI_FTYPE_V4HI_V4HI:
23023         case V4HI_FTYPE_V4HI_V4HI_COUNT:
23024           type = v4hi_ftype_v4hi_v4hi;
23025           break;
23026         case V4HI_FTYPE_V8QI_V8QI:
23027           type = v4hi_ftype_v8qi_v8qi;
23028           break;
23029         case V4HI_FTYPE_V2SI_V2SI:
23030           type = v4hi_ftype_v2si_v2si;
23031           break;
23032         case V4HI_FTYPE_V4HI_SI_COUNT:
23033           type = v4hi_ftype_v4hi_int;
23034           break;
23035         case V4DF_FTYPE_V4DF_V4DF:
23036           type = v4df_ftype_v4df_v4df;
23037           break;
23038         case V4DF_FTYPE_V4DF_V4DI:
23039           type = v4df_ftype_v4df_v4di;
23040           break;
23041         case V4SF_FTYPE_V4SF_V4SF:
23042         case V4SF_FTYPE_V4SF_V4SF_SWAP:
23043           type = v4sf_ftype_v4sf_v4sf;
23044           break;
23045         case V4SF_FTYPE_V4SF_V4SI:
23046           type = v4sf_ftype_v4sf_v4si;
23047           break;
23048         case V4SF_FTYPE_V4SF_V2SI:
23049           type = v4sf_ftype_v4sf_v2si;
23050           break;
23051         case V4SF_FTYPE_V4SF_V2DF:
23052           type = v4sf_ftype_v4sf_v2df;
23053           break;
23054         case V4SF_FTYPE_V4SF_DI:
23055           type = v4sf_ftype_v4sf_int64;
23056           break;
23057         case V4SF_FTYPE_V4SF_SI:
23058           type = v4sf_ftype_v4sf_int;
23059           break;
23060         case V2DI_FTYPE_V2DI_V2DI:
23061         case V2DI_FTYPE_V2DI_V2DI_COUNT:
23062           type = v2di_ftype_v2di_v2di;
23063           break;
23064         case V2DI_FTYPE_V16QI_V16QI:
23065           type = v2di_ftype_v16qi_v16qi;
23066           break;
23067         case V2DI_FTYPE_V4SI_V4SI:
23068           type = v2di_ftype_v4si_v4si;
23069           break;
23070         case V2DI_FTYPE_V2DI_V16QI:
23071           type = v2di_ftype_v2di_v16qi;
23072           break;
23073         case V2DI_FTYPE_V2DF_V2DF:
23074           type = v2di_ftype_v2df_v2df;
23075           break;
23076         case V2DI_FTYPE_V2DI_SI_COUNT:
23077           type = v2di_ftype_v2di_int;
23078           break;
23079         case V2SI_FTYPE_V2SI_V2SI:
23080         case V2SI_FTYPE_V2SI_V2SI_COUNT:
23081           type = v2si_ftype_v2si_v2si;
23082           break;
23083         case V2SI_FTYPE_V4HI_V4HI:
23084           type = v2si_ftype_v4hi_v4hi;
23085           break;
23086         case V2SI_FTYPE_V2SF_V2SF:
23087           type = v2si_ftype_v2sf_v2sf;
23088           break;
23089         case V2SI_FTYPE_V2SI_SI_COUNT:
23090           type = v2si_ftype_v2si_int;
23091           break;
23092         case V2DF_FTYPE_V2DF_V2DF:
23093         case V2DF_FTYPE_V2DF_V2DF_SWAP:
23094           type = v2df_ftype_v2df_v2df;
23095           break;
23096         case V2DF_FTYPE_V2DF_V4SF:
23097           type = v2df_ftype_v2df_v4sf;
23098           break;
23099         case V2DF_FTYPE_V2DF_V2DI:
23100           type = v2df_ftype_v2df_v2di;
23101           break;
23102         case V2DF_FTYPE_V2DF_DI:
23103           type = v2df_ftype_v2df_int64;
23104           break;
23105         case V2DF_FTYPE_V2DF_SI:
23106           type = v2df_ftype_v2df_int;
23107           break;
23108         case V2SF_FTYPE_V2SF_V2SF:
23109           type = v2sf_ftype_v2sf_v2sf;
23110           break;
23111         case V1DI_FTYPE_V1DI_V1DI:
23112         case V1DI_FTYPE_V1DI_V1DI_COUNT:
23113           type = v1di_ftype_v1di_v1di;
23114           break;
23115         case V1DI_FTYPE_V8QI_V8QI:
23116           type = v1di_ftype_v8qi_v8qi;
23117           break;
23118         case V1DI_FTYPE_V2SI_V2SI:
23119           type = v1di_ftype_v2si_v2si;
23120           break;
23121         case V1DI_FTYPE_V1DI_SI_COUNT:
23122           type = v1di_ftype_v1di_int;
23123           break;
23124         case UINT64_FTYPE_UINT64_UINT64:
23125           type = uint64_ftype_uint64_uint64;
23126           break;
23127         case UINT_FTYPE_UINT_UINT:
23128           type = unsigned_ftype_unsigned_unsigned;
23129           break;
23130         case UINT_FTYPE_UINT_USHORT:
23131           type = unsigned_ftype_unsigned_ushort;
23132           break;
23133         case UINT_FTYPE_UINT_UCHAR:
23134           type = unsigned_ftype_unsigned_uchar;
23135           break;
23136         case V8HI_FTYPE_V8HI_INT:
23137           type = v8hi_ftype_v8hi_int;
23138           break;
23139         case V8SF_FTYPE_V8SF_INT:
23140           type = v8sf_ftype_v8sf_int;
23141           break;
23142         case V4SI_FTYPE_V4SI_INT:
23143           type = v4si_ftype_v4si_int;
23144           break;
23145         case V4SI_FTYPE_V8SI_INT:
23146           type = v4si_ftype_v8si_int;
23147           break;
23148         case V4HI_FTYPE_V4HI_INT:
23149           type = v4hi_ftype_v4hi_int;
23150           break;
23151         case V4DF_FTYPE_V4DF_INT:
23152           type = v4df_ftype_v4df_int;
23153           break;
23154         case V4SF_FTYPE_V4SF_INT:
23155           type = v4sf_ftype_v4sf_int;
23156           break;
23157         case V4SF_FTYPE_V8SF_INT:
23158           type = v4sf_ftype_v8sf_int;
23159           break;
23160         case V2DI_FTYPE_V2DI_INT:
23161         case V2DI2TI_FTYPE_V2DI_INT:
23162           type = v2di_ftype_v2di_int;
23163           break;
23164         case V2DF_FTYPE_V2DF_INT:
23165           type = v2df_ftype_v2df_int;
23166           break;
23167         case V2DF_FTYPE_V4DF_INT:
23168           type = v2df_ftype_v4df_int;
23169           break;
23170         case V16QI_FTYPE_V16QI_V16QI_V16QI:
23171           type = v16qi_ftype_v16qi_v16qi_v16qi;
23172           break;
23173         case V8SF_FTYPE_V8SF_V8SF_V8SF:
23174           type = v8sf_ftype_v8sf_v8sf_v8sf;
23175           break;
23176         case V4DF_FTYPE_V4DF_V4DF_V4DF:
23177           type = v4df_ftype_v4df_v4df_v4df;
23178           break;
23179         case V4SF_FTYPE_V4SF_V4SF_V4SF:
23180           type = v4sf_ftype_v4sf_v4sf_v4sf;
23181           break;
23182         case V2DF_FTYPE_V2DF_V2DF_V2DF:
23183           type = v2df_ftype_v2df_v2df_v2df;
23184           break;
23185         case V16QI_FTYPE_V16QI_V16QI_INT:
23186           type = v16qi_ftype_v16qi_v16qi_int;
23187           break;
23188         case V8SI_FTYPE_V8SI_V8SI_INT:
23189           type = v8si_ftype_v8si_v8si_int;
23190           break;
23191         case V8SI_FTYPE_V8SI_V4SI_INT:
23192           type = v8si_ftype_v8si_v4si_int;
23193           break;
23194         case V8HI_FTYPE_V8HI_V8HI_INT:
23195           type = v8hi_ftype_v8hi_v8hi_int;
23196           break;
23197         case V8SF_FTYPE_V8SF_V8SF_INT:
23198           type = v8sf_ftype_v8sf_v8sf_int;
23199           break;
23200         case V8SF_FTYPE_V8SF_V4SF_INT:
23201           type = v8sf_ftype_v8sf_v4sf_int;
23202           break;
23203         case V4SI_FTYPE_V4SI_V4SI_INT:
23204           type = v4si_ftype_v4si_v4si_int;
23205           break;
23206         case V4DF_FTYPE_V4DF_V4DF_INT:
23207           type = v4df_ftype_v4df_v4df_int;
23208           break;
23209         case V4DF_FTYPE_V4DF_V2DF_INT:
23210           type = v4df_ftype_v4df_v2df_int;
23211           break;
23212         case V4SF_FTYPE_V4SF_V4SF_INT:
23213           type = v4sf_ftype_v4sf_v4sf_int;
23214           break;
23215         case V2DI_FTYPE_V2DI_V2DI_INT:
23216         case V2DI2TI_FTYPE_V2DI_V2DI_INT:
23217           type = v2di_ftype_v2di_v2di_int;
23218           break;
23219         case V2DF_FTYPE_V2DF_V2DF_INT:
23220           type = v2df_ftype_v2df_v2df_int;
23221           break;
23222         case V2DI_FTYPE_V2DI_UINT_UINT:
23223           type = v2di_ftype_v2di_unsigned_unsigned;
23224           break;
23225         case V2DI_FTYPE_V2DI_V2DI_UINT_UINT:
23226           type = v2di_ftype_v2di_v2di_unsigned_unsigned;
23227           break;
23228         case V1DI2DI_FTYPE_V1DI_V1DI_INT:
23229           type = v1di_ftype_v1di_v1di_int;
23230           break;
23231         default:
23232           gcc_unreachable ();
23233         }
23234
23235       def_builtin_const (d->mask, d->name, type, d->code);
23236     }
23237
23238   /* pcmpestr[im] insns.  */
23239   for (i = 0, d = bdesc_pcmpestr;
23240        i < ARRAY_SIZE (bdesc_pcmpestr);
23241        i++, d++)
23242     {
23243       if (d->code == IX86_BUILTIN_PCMPESTRM128)
23244         ftype = v16qi_ftype_v16qi_int_v16qi_int_int;
23245       else
23246         ftype = int_ftype_v16qi_int_v16qi_int_int;
23247       def_builtin_const (d->mask, d->name, ftype, d->code);
23248     }
23249
23250   /* pcmpistr[im] insns.  */
23251   for (i = 0, d = bdesc_pcmpistr;
23252        i < ARRAY_SIZE (bdesc_pcmpistr);
23253        i++, d++)
23254     {
23255       if (d->code == IX86_BUILTIN_PCMPISTRM128)
23256         ftype = v16qi_ftype_v16qi_v16qi_int;
23257       else
23258         ftype = int_ftype_v16qi_v16qi_int;
23259       def_builtin_const (d->mask, d->name, ftype, d->code);
23260     }
23261
23262   /* comi/ucomi insns.  */
23263   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
23264     if (d->mask == OPTION_MASK_ISA_SSE2)
23265       def_builtin_const (d->mask, d->name, int_ftype_v2df_v2df, d->code);
23266     else
23267       def_builtin_const (d->mask, d->name, int_ftype_v4sf_v4sf, d->code);
23268
23269   /* SSE */
23270   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_ldmxcsr", void_ftype_unsigned, IX86_BUILTIN_LDMXCSR);
23271   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_stmxcsr", unsigned_ftype_void, IX86_BUILTIN_STMXCSR);
23272
23273   /* SSE or 3DNow!A */
23274   def_builtin (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_maskmovq", void_ftype_v8qi_v8qi_pchar, IX86_BUILTIN_MASKMOVQ);
23275
23276   /* SSE2 */
23277   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_maskmovdqu", void_ftype_v16qi_v16qi_pchar, IX86_BUILTIN_MASKMOVDQU);
23278
23279   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_clflush", void_ftype_pcvoid, IX86_BUILTIN_CLFLUSH);
23280   x86_mfence = def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_mfence", void_ftype_void, IX86_BUILTIN_MFENCE);
23281
23282   /* SSE3.  */
23283   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_monitor", void_ftype_pcvoid_unsigned_unsigned, IX86_BUILTIN_MONITOR);
23284   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_mwait", void_ftype_unsigned_unsigned, IX86_BUILTIN_MWAIT);
23285
23286   /* AES */
23287   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenc128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESENC128);
23288   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenclast128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESENCLAST128);
23289   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdec128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESDEC128);
23290   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdeclast128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESDECLAST128);
23291   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesimc128", v2di_ftype_v2di, IX86_BUILTIN_AESIMC128);
23292   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aeskeygenassist128", v2di_ftype_v2di_int, IX86_BUILTIN_AESKEYGENASSIST128);
23293
23294   /* PCLMUL */
23295   def_builtin_const (OPTION_MASK_ISA_PCLMUL, "__builtin_ia32_pclmulqdq128", v2di_ftype_v2di_v2di_int, IX86_BUILTIN_PCLMULQDQ128);
23296
23297   /* AVX */
23298   def_builtin (OPTION_MASK_ISA_AVX, "__builtin_ia32_vzeroupper", void_ftype_void,
23299                TARGET_64BIT ? IX86_BUILTIN_VZEROUPPER_REX64 : IX86_BUILTIN_VZEROUPPER);
23300
23301   /* Access to the vec_init patterns.  */
23302   ftype = build_function_type_list (V2SI_type_node, integer_type_node,
23303                                     integer_type_node, NULL_TREE);
23304   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v2si", ftype, IX86_BUILTIN_VEC_INIT_V2SI);
23305
23306   ftype = build_function_type_list (V4HI_type_node, short_integer_type_node,
23307                                     short_integer_type_node,
23308                                     short_integer_type_node,
23309                                     short_integer_type_node, NULL_TREE);
23310   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v4hi", ftype, IX86_BUILTIN_VEC_INIT_V4HI);
23311
23312   ftype = build_function_type_list (V8QI_type_node, char_type_node,
23313                                     char_type_node, char_type_node,
23314                                     char_type_node, char_type_node,
23315                                     char_type_node, char_type_node,
23316                                     char_type_node, NULL_TREE);
23317   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v8qi", ftype, IX86_BUILTIN_VEC_INIT_V8QI);
23318
23319   /* Access to the vec_extract patterns.  */
23320   ftype = build_function_type_list (double_type_node, V2DF_type_node,
23321                                     integer_type_node, NULL_TREE);
23322   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2df", ftype, IX86_BUILTIN_VEC_EXT_V2DF);
23323
23324   ftype = build_function_type_list (long_long_integer_type_node,
23325                                     V2DI_type_node, integer_type_node,
23326                                     NULL_TREE);
23327   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2di", ftype, IX86_BUILTIN_VEC_EXT_V2DI);
23328
23329   ftype = build_function_type_list (float_type_node, V4SF_type_node,
23330                                     integer_type_node, NULL_TREE);
23331   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_vec_ext_v4sf", ftype, IX86_BUILTIN_VEC_EXT_V4SF);
23332
23333   ftype = build_function_type_list (intSI_type_node, V4SI_type_node,
23334                                     integer_type_node, NULL_TREE);
23335   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v4si", ftype, IX86_BUILTIN_VEC_EXT_V4SI);
23336
23337   ftype = build_function_type_list (intHI_type_node, V8HI_type_node,
23338                                     integer_type_node, NULL_TREE);
23339   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v8hi", ftype, IX86_BUILTIN_VEC_EXT_V8HI);
23340
23341   ftype = build_function_type_list (intHI_type_node, V4HI_type_node,
23342                                     integer_type_node, NULL_TREE);
23343   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_vec_ext_v4hi", ftype, IX86_BUILTIN_VEC_EXT_V4HI);
23344
23345   ftype = build_function_type_list (intSI_type_node, V2SI_type_node,
23346                                     integer_type_node, NULL_TREE);
23347   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_ext_v2si", ftype, IX86_BUILTIN_VEC_EXT_V2SI);
23348
23349   ftype = build_function_type_list (intQI_type_node, V16QI_type_node,
23350                                     integer_type_node, NULL_TREE);
23351   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v16qi", ftype, IX86_BUILTIN_VEC_EXT_V16QI);
23352
23353   /* Access to the vec_set patterns.  */
23354   ftype = build_function_type_list (V2DI_type_node, V2DI_type_node,
23355                                     intDI_type_node,
23356                                     integer_type_node, NULL_TREE);
23357   def_builtin_const (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_64BIT, "__builtin_ia32_vec_set_v2di", ftype, IX86_BUILTIN_VEC_SET_V2DI);
23358
23359   ftype = build_function_type_list (V4SF_type_node, V4SF_type_node,
23360                                     float_type_node,
23361                                     integer_type_node, NULL_TREE);
23362   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4sf", ftype, IX86_BUILTIN_VEC_SET_V4SF);
23363
23364   ftype = build_function_type_list (V4SI_type_node, V4SI_type_node,
23365                                     intSI_type_node,
23366                                     integer_type_node, NULL_TREE);
23367   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4si", ftype, IX86_BUILTIN_VEC_SET_V4SI);
23368
23369   ftype = build_function_type_list (V8HI_type_node, V8HI_type_node,
23370                                     intHI_type_node,
23371                                     integer_type_node, NULL_TREE);
23372   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_set_v8hi", ftype, IX86_BUILTIN_VEC_SET_V8HI);
23373
23374   ftype = build_function_type_list (V4HI_type_node, V4HI_type_node,
23375                                     intHI_type_node,
23376                                     integer_type_node, NULL_TREE);
23377   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_vec_set_v4hi", ftype, IX86_BUILTIN_VEC_SET_V4HI);
23378
23379   ftype = build_function_type_list (V16QI_type_node, V16QI_type_node,
23380                                     intQI_type_node,
23381                                     integer_type_node, NULL_TREE);
23382   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v16qi", ftype, IX86_BUILTIN_VEC_SET_V16QI);
23383
23384   /* Add SSE5 multi-arg argument instructions */
23385   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
23386     {
23387       tree mtype = NULL_TREE;
23388
23389       if (d->name == 0)
23390         continue;
23391
23392       switch ((enum multi_arg_type)d->flag)
23393         {
23394         case MULTI_ARG_3_SF:     mtype = v4sf_ftype_v4sf_v4sf_v4sf;     break;
23395         case MULTI_ARG_3_DF:     mtype = v2df_ftype_v2df_v2df_v2df;     break;
23396         case MULTI_ARG_3_DI:     mtype = v2di_ftype_v2di_v2di_v2di;     break;
23397         case MULTI_ARG_3_SI:     mtype = v4si_ftype_v4si_v4si_v4si;     break;
23398         case MULTI_ARG_3_SI_DI:  mtype = v4si_ftype_v4si_v4si_v2di;     break;
23399         case MULTI_ARG_3_HI:     mtype = v8hi_ftype_v8hi_v8hi_v8hi;     break;
23400         case MULTI_ARG_3_HI_SI:  mtype = v8hi_ftype_v8hi_v8hi_v4si;     break;
23401         case MULTI_ARG_3_QI:     mtype = v16qi_ftype_v16qi_v16qi_v16qi; break;
23402         case MULTI_ARG_3_PERMPS: mtype = v4sf_ftype_v4sf_v4sf_v16qi;    break;
23403         case MULTI_ARG_3_PERMPD: mtype = v2df_ftype_v2df_v2df_v16qi;    break;
23404         case MULTI_ARG_2_SF:     mtype = v4sf_ftype_v4sf_v4sf;          break;
23405         case MULTI_ARG_2_DF:     mtype = v2df_ftype_v2df_v2df;          break;
23406         case MULTI_ARG_2_DI:     mtype = v2di_ftype_v2di_v2di;          break;
23407         case MULTI_ARG_2_SI:     mtype = v4si_ftype_v4si_v4si;          break;
23408         case MULTI_ARG_2_HI:     mtype = v8hi_ftype_v8hi_v8hi;          break;
23409         case MULTI_ARG_2_QI:     mtype = v16qi_ftype_v16qi_v16qi;       break;
23410         case MULTI_ARG_2_DI_IMM: mtype = v2di_ftype_v2di_si;            break;
23411         case MULTI_ARG_2_SI_IMM: mtype = v4si_ftype_v4si_si;            break;
23412         case MULTI_ARG_2_HI_IMM: mtype = v8hi_ftype_v8hi_si;            break;
23413         case MULTI_ARG_2_QI_IMM: mtype = v16qi_ftype_v16qi_si;          break;
23414         case MULTI_ARG_2_SF_CMP: mtype = v4sf_ftype_v4sf_v4sf;          break;
23415         case MULTI_ARG_2_DF_CMP: mtype = v2df_ftype_v2df_v2df;          break;
23416         case MULTI_ARG_2_DI_CMP: mtype = v2di_ftype_v2di_v2di;          break;
23417         case MULTI_ARG_2_SI_CMP: mtype = v4si_ftype_v4si_v4si;          break;
23418         case MULTI_ARG_2_HI_CMP: mtype = v8hi_ftype_v8hi_v8hi;          break;
23419         case MULTI_ARG_2_QI_CMP: mtype = v16qi_ftype_v16qi_v16qi;       break;
23420         case MULTI_ARG_2_SF_TF:  mtype = v4sf_ftype_v4sf_v4sf;          break;
23421         case MULTI_ARG_2_DF_TF:  mtype = v2df_ftype_v2df_v2df;          break;
23422         case MULTI_ARG_2_DI_TF:  mtype = v2di_ftype_v2di_v2di;          break;
23423         case MULTI_ARG_2_SI_TF:  mtype = v4si_ftype_v4si_v4si;          break;
23424         case MULTI_ARG_2_HI_TF:  mtype = v8hi_ftype_v8hi_v8hi;          break;
23425         case MULTI_ARG_2_QI_TF:  mtype = v16qi_ftype_v16qi_v16qi;       break;
23426         case MULTI_ARG_1_SF:     mtype = v4sf_ftype_v4sf;               break;
23427         case MULTI_ARG_1_DF:     mtype = v2df_ftype_v2df;               break;
23428         case MULTI_ARG_1_DI:     mtype = v2di_ftype_v2di;               break;
23429         case MULTI_ARG_1_SI:     mtype = v4si_ftype_v4si;               break;
23430         case MULTI_ARG_1_HI:     mtype = v8hi_ftype_v8hi;               break;
23431         case MULTI_ARG_1_QI:     mtype = v16qi_ftype_v16qi;             break;
23432         case MULTI_ARG_1_SI_DI:  mtype = v2di_ftype_v4si;               break;
23433         case MULTI_ARG_1_HI_DI:  mtype = v2di_ftype_v8hi;               break;
23434         case MULTI_ARG_1_HI_SI:  mtype = v4si_ftype_v8hi;               break;
23435         case MULTI_ARG_1_QI_DI:  mtype = v2di_ftype_v16qi;              break;
23436         case MULTI_ARG_1_QI_SI:  mtype = v4si_ftype_v16qi;              break;
23437         case MULTI_ARG_1_QI_HI:  mtype = v8hi_ftype_v16qi;              break;
23438         case MULTI_ARG_1_PH2PS:  mtype = v4sf_ftype_v4hi;               break;
23439         case MULTI_ARG_1_PS2PH:  mtype = v4hi_ftype_v4sf;               break;
23440         case MULTI_ARG_UNKNOWN:
23441         default:
23442           gcc_unreachable ();
23443         }
23444
23445       if (mtype)
23446         def_builtin_const (d->mask, d->name, mtype, d->code);
23447     }
23448 }
23449
23450 /* Internal method for ix86_init_builtins.  */
23451
23452 static void
23453 ix86_init_builtins_va_builtins_abi (void)
23454 {
23455   tree ms_va_ref, sysv_va_ref;
23456   tree fnvoid_va_end_ms, fnvoid_va_end_sysv;
23457   tree fnvoid_va_start_ms, fnvoid_va_start_sysv;
23458   tree fnvoid_va_copy_ms, fnvoid_va_copy_sysv;
23459   tree fnattr_ms = NULL_TREE, fnattr_sysv = NULL_TREE;
23460
23461   if (!TARGET_64BIT)
23462     return;
23463   fnattr_ms = build_tree_list (get_identifier ("ms_abi"), NULL_TREE);
23464   fnattr_sysv = build_tree_list (get_identifier ("sysv_abi"), NULL_TREE);
23465   ms_va_ref = build_reference_type (ms_va_list_type_node);
23466   sysv_va_ref =
23467     build_pointer_type (TREE_TYPE (sysv_va_list_type_node));
23468
23469   fnvoid_va_end_ms =
23470     build_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
23471   fnvoid_va_start_ms =
23472     build_varargs_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
23473   fnvoid_va_end_sysv =
23474     build_function_type_list (void_type_node, sysv_va_ref, NULL_TREE);
23475   fnvoid_va_start_sysv =
23476     build_varargs_function_type_list (void_type_node, sysv_va_ref,
23477                                        NULL_TREE);
23478   fnvoid_va_copy_ms =
23479     build_function_type_list (void_type_node, ms_va_ref, ms_va_list_type_node,
23480                               NULL_TREE);
23481   fnvoid_va_copy_sysv =
23482     build_function_type_list (void_type_node, sysv_va_ref,
23483                               sysv_va_ref, NULL_TREE);
23484
23485   add_builtin_function ("__builtin_ms_va_start", fnvoid_va_start_ms,
23486                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_ms);
23487   add_builtin_function ("__builtin_ms_va_end", fnvoid_va_end_ms,
23488                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_ms);
23489   add_builtin_function ("__builtin_ms_va_copy", fnvoid_va_copy_ms,
23490                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_ms);
23491   add_builtin_function ("__builtin_sysv_va_start", fnvoid_va_start_sysv,
23492                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_sysv);
23493   add_builtin_function ("__builtin_sysv_va_end", fnvoid_va_end_sysv,
23494                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_sysv);
23495   add_builtin_function ("__builtin_sysv_va_copy", fnvoid_va_copy_sysv,
23496                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_sysv);
23497 }
23498
23499 static void
23500 ix86_init_builtins (void)
23501 {
23502   tree float128_type_node = make_node (REAL_TYPE);
23503   tree ftype, decl;
23504
23505   /* The __float80 type.  */
23506   if (TYPE_MODE (long_double_type_node) == XFmode)
23507     (*lang_hooks.types.register_builtin_type) (long_double_type_node,
23508                                                "__float80");
23509   else
23510     {
23511       /* The __float80 type.  */
23512       tree float80_type_node = make_node (REAL_TYPE);
23513
23514       TYPE_PRECISION (float80_type_node) = 80;
23515       layout_type (float80_type_node);
23516       (*lang_hooks.types.register_builtin_type) (float80_type_node,
23517                                                  "__float80");
23518     }
23519
23520   /* The __float128 type.  */
23521   TYPE_PRECISION (float128_type_node) = 128;
23522   layout_type (float128_type_node);
23523   (*lang_hooks.types.register_builtin_type) (float128_type_node,
23524                                              "__float128");
23525
23526   /* TFmode support builtins.  */
23527   ftype = build_function_type (float128_type_node, void_list_node);
23528   decl = add_builtin_function ("__builtin_infq", ftype,
23529                                IX86_BUILTIN_INFQ, BUILT_IN_MD,
23530                                NULL, NULL_TREE);
23531   ix86_builtins[(int) IX86_BUILTIN_INFQ] = decl;
23532
23533   /* We will expand them to normal call if SSE2 isn't available since
23534      they are used by libgcc. */
23535   ftype = build_function_type_list (float128_type_node,
23536                                     float128_type_node,
23537                                     NULL_TREE);
23538   decl = add_builtin_function ("__builtin_fabsq", ftype,
23539                                IX86_BUILTIN_FABSQ, BUILT_IN_MD,
23540                                "__fabstf2", NULL_TREE);
23541   ix86_builtins[(int) IX86_BUILTIN_FABSQ] = decl;
23542   TREE_READONLY (decl) = 1;
23543
23544   ftype = build_function_type_list (float128_type_node,
23545                                     float128_type_node,
23546                                     float128_type_node,
23547                                     NULL_TREE);
23548   decl = add_builtin_function ("__builtin_copysignq", ftype,
23549                                IX86_BUILTIN_COPYSIGNQ, BUILT_IN_MD,
23550                                "__copysigntf3", NULL_TREE);
23551   ix86_builtins[(int) IX86_BUILTIN_COPYSIGNQ] = decl;
23552   TREE_READONLY (decl) = 1;
23553
23554   ix86_init_mmx_sse_builtins ();
23555   if (TARGET_64BIT)
23556     ix86_init_builtins_va_builtins_abi ();
23557 }
23558
23559 /* Errors in the source file can cause expand_expr to return const0_rtx
23560    where we expect a vector.  To avoid crashing, use one of the vector
23561    clear instructions.  */
23562 static rtx
23563 safe_vector_operand (rtx x, enum machine_mode mode)
23564 {
23565   if (x == const0_rtx)
23566     x = CONST0_RTX (mode);
23567   return x;
23568 }
23569
23570 /* Subroutine of ix86_expand_builtin to take care of binop insns.  */
23571
23572 static rtx
23573 ix86_expand_binop_builtin (enum insn_code icode, tree exp, rtx target)
23574 {
23575   rtx pat;
23576   tree arg0 = CALL_EXPR_ARG (exp, 0);
23577   tree arg1 = CALL_EXPR_ARG (exp, 1);
23578   rtx op0 = expand_normal (arg0);
23579   rtx op1 = expand_normal (arg1);
23580   enum machine_mode tmode = insn_data[icode].operand[0].mode;
23581   enum machine_mode mode0 = insn_data[icode].operand[1].mode;
23582   enum machine_mode mode1 = insn_data[icode].operand[2].mode;
23583
23584   if (VECTOR_MODE_P (mode0))
23585     op0 = safe_vector_operand (op0, mode0);
23586   if (VECTOR_MODE_P (mode1))
23587     op1 = safe_vector_operand (op1, mode1);
23588
23589   if (optimize || !target
23590       || GET_MODE (target) != tmode
23591       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
23592     target = gen_reg_rtx (tmode);
23593
23594   if (GET_MODE (op1) == SImode && mode1 == TImode)
23595     {
23596       rtx x = gen_reg_rtx (V4SImode);
23597       emit_insn (gen_sse2_loadd (x, op1));
23598       op1 = gen_lowpart (TImode, x);
23599     }
23600
23601   if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
23602     op0 = copy_to_mode_reg (mode0, op0);
23603   if (!(*insn_data[icode].operand[2].predicate) (op1, mode1))
23604     op1 = copy_to_mode_reg (mode1, op1);
23605
23606   pat = GEN_FCN (icode) (target, op0, op1);
23607   if (! pat)
23608     return 0;
23609
23610   emit_insn (pat);
23611
23612   return target;
23613 }
23614
23615 /* Subroutine of ix86_expand_builtin to take care of 2-4 argument insns.  */
23616
23617 static rtx
23618 ix86_expand_multi_arg_builtin (enum insn_code icode, tree exp, rtx target,
23619                                enum multi_arg_type m_type,
23620                                enum insn_code sub_code)
23621 {
23622   rtx pat;
23623   int i;
23624   int nargs;
23625   bool comparison_p = false;
23626   bool tf_p = false;
23627   bool last_arg_constant = false;
23628   int num_memory = 0;
23629   struct {
23630     rtx op;
23631     enum machine_mode mode;
23632   } args[4];
23633
23634   enum machine_mode tmode = insn_data[icode].operand[0].mode;
23635
23636   switch (m_type)
23637     {
23638     case MULTI_ARG_3_SF:
23639     case MULTI_ARG_3_DF:
23640     case MULTI_ARG_3_DI:
23641     case MULTI_ARG_3_SI:
23642     case MULTI_ARG_3_SI_DI:
23643     case MULTI_ARG_3_HI:
23644     case MULTI_ARG_3_HI_SI:
23645     case MULTI_ARG_3_QI:
23646     case MULTI_ARG_3_PERMPS:
23647     case MULTI_ARG_3_PERMPD:
23648       nargs = 3;
23649       break;
23650
23651     case MULTI_ARG_2_SF:
23652     case MULTI_ARG_2_DF:
23653     case MULTI_ARG_2_DI:
23654     case MULTI_ARG_2_SI:
23655     case MULTI_ARG_2_HI:
23656     case MULTI_ARG_2_QI:
23657       nargs = 2;
23658       break;
23659
23660     case MULTI_ARG_2_DI_IMM:
23661     case MULTI_ARG_2_SI_IMM:
23662     case MULTI_ARG_2_HI_IMM:
23663     case MULTI_ARG_2_QI_IMM:
23664       nargs = 2;
23665       last_arg_constant = true;
23666       break;
23667
23668     case MULTI_ARG_1_SF:
23669     case MULTI_ARG_1_DF:
23670     case MULTI_ARG_1_DI:
23671     case MULTI_ARG_1_SI:
23672     case MULTI_ARG_1_HI:
23673     case MULTI_ARG_1_QI:
23674     case MULTI_ARG_1_SI_DI:
23675     case MULTI_ARG_1_HI_DI:
23676     case MULTI_ARG_1_HI_SI:
23677     case MULTI_ARG_1_QI_DI:
23678     case MULTI_ARG_1_QI_SI:
23679     case MULTI_ARG_1_QI_HI:
23680     case MULTI_ARG_1_PH2PS:
23681     case MULTI_ARG_1_PS2PH:
23682       nargs = 1;
23683       break;
23684
23685     case MULTI_ARG_2_SF_CMP:
23686     case MULTI_ARG_2_DF_CMP:
23687     case MULTI_ARG_2_DI_CMP:
23688     case MULTI_ARG_2_SI_CMP:
23689     case MULTI_ARG_2_HI_CMP:
23690     case MULTI_ARG_2_QI_CMP:
23691       nargs = 2;
23692       comparison_p = true;
23693       break;
23694
23695     case MULTI_ARG_2_SF_TF:
23696     case MULTI_ARG_2_DF_TF:
23697     case MULTI_ARG_2_DI_TF:
23698     case MULTI_ARG_2_SI_TF:
23699     case MULTI_ARG_2_HI_TF:
23700     case MULTI_ARG_2_QI_TF:
23701       nargs = 2;
23702       tf_p = true;
23703       break;
23704
23705     case MULTI_ARG_UNKNOWN:
23706     default:
23707       gcc_unreachable ();
23708     }
23709
23710   if (optimize || !target
23711       || GET_MODE (target) != tmode
23712       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
23713     target = gen_reg_rtx (tmode);
23714
23715   gcc_assert (nargs <= 4);
23716
23717   for (i = 0; i < nargs; i++)
23718     {
23719       tree arg = CALL_EXPR_ARG (exp, i);
23720       rtx op = expand_normal (arg);
23721       int adjust = (comparison_p) ? 1 : 0;
23722       enum machine_mode mode = insn_data[icode].operand[i+adjust+1].mode;
23723
23724       if (last_arg_constant && i == nargs-1)
23725         {
23726           if (GET_CODE (op) != CONST_INT)
23727             {
23728               error ("last argument must be an immediate");
23729               return gen_reg_rtx (tmode);
23730             }
23731         }
23732       else
23733         {
23734           if (VECTOR_MODE_P (mode))
23735             op = safe_vector_operand (op, mode);
23736
23737           /* If we aren't optimizing, only allow one memory operand to be
23738              generated.  */
23739           if (memory_operand (op, mode))
23740             num_memory++;
23741
23742           gcc_assert (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode);
23743
23744           if (optimize
23745               || ! (*insn_data[icode].operand[i+adjust+1].predicate) (op, mode)
23746               || num_memory > 1)
23747             op = force_reg (mode, op);
23748         }
23749
23750       args[i].op = op;
23751       args[i].mode = mode;
23752     }
23753
23754   switch (nargs)
23755     {
23756     case 1:
23757       pat = GEN_FCN (icode) (target, args[0].op);
23758       break;
23759
23760     case 2:
23761       if (tf_p)
23762         pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
23763                                GEN_INT ((int)sub_code));
23764       else if (! comparison_p)
23765         pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
23766       else
23767         {
23768           rtx cmp_op = gen_rtx_fmt_ee (sub_code, GET_MODE (target),
23769                                        args[0].op,
23770                                        args[1].op);
23771
23772           pat = GEN_FCN (icode) (target, cmp_op, args[0].op, args[1].op);
23773         }
23774       break;
23775
23776     case 3:
23777       pat = GEN_FCN (icode) (target, args[0].op, args[1].op, args[2].op);
23778       break;
23779
23780     default:
23781       gcc_unreachable ();
23782     }
23783
23784   if (! pat)
23785     return 0;
23786
23787   emit_insn (pat);
23788   return target;
23789 }
23790
23791 /* Subroutine of ix86_expand_args_builtin to take care of scalar unop
23792    insns with vec_merge.  */
23793
23794 static rtx
23795 ix86_expand_unop_vec_merge_builtin (enum insn_code icode, tree exp,
23796                                     rtx target)
23797 {
23798   rtx pat;
23799   tree arg0 = CALL_EXPR_ARG (exp, 0);
23800   rtx op1, op0 = expand_normal (arg0);
23801   enum machine_mode tmode = insn_data[icode].operand[0].mode;
23802   enum machine_mode mode0 = insn_data[icode].operand[1].mode;
23803
23804   if (optimize || !target
23805       || GET_MODE (target) != tmode
23806       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
23807     target = gen_reg_rtx (tmode);
23808
23809   if (VECTOR_MODE_P (mode0))
23810     op0 = safe_vector_operand (op0, mode0);
23811
23812   if ((optimize && !register_operand (op0, mode0))
23813       || ! (*insn_data[icode].operand[1].predicate) (op0, mode0))
23814     op0 = copy_to_mode_reg (mode0, op0);
23815
23816   op1 = op0;
23817   if (! (*insn_data[icode].operand[2].predicate) (op1, mode0))
23818     op1 = copy_to_mode_reg (mode0, op1);
23819
23820   pat = GEN_FCN (icode) (target, op0, op1);
23821   if (! pat)
23822     return 0;
23823   emit_insn (pat);
23824   return target;
23825 }
23826
23827 /* Subroutine of ix86_expand_builtin to take care of comparison insns.  */
23828
23829 static rtx
23830 ix86_expand_sse_compare (const struct builtin_description *d,
23831                          tree exp, rtx target, bool swap)
23832 {
23833   rtx pat;
23834   tree arg0 = CALL_EXPR_ARG (exp, 0);
23835   tree arg1 = CALL_EXPR_ARG (exp, 1);
23836   rtx op0 = expand_normal (arg0);
23837   rtx op1 = expand_normal (arg1);
23838   rtx op2;
23839   enum machine_mode tmode = insn_data[d->icode].operand[0].mode;
23840   enum machine_mode mode0 = insn_data[d->icode].operand[1].mode;
23841   enum machine_mode mode1 = insn_data[d->icode].operand[2].mode;
23842   enum rtx_code comparison = d->comparison;
23843
23844   if (VECTOR_MODE_P (mode0))
23845     op0 = safe_vector_operand (op0, mode0);
23846   if (VECTOR_MODE_P (mode1))
23847     op1 = safe_vector_operand (op1, mode1);
23848
23849   /* Swap operands if we have a comparison that isn't available in
23850      hardware.  */
23851   if (swap)
23852     {
23853       rtx tmp = gen_reg_rtx (mode1);
23854       emit_move_insn (tmp, op1);
23855       op1 = op0;
23856       op0 = tmp;
23857     }
23858
23859   if (optimize || !target
23860       || GET_MODE (target) != tmode
23861       || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode))
23862     target = gen_reg_rtx (tmode);
23863
23864   if ((optimize && !register_operand (op0, mode0))
23865       || ! (*insn_data[d->icode].operand[1].predicate) (op0, mode0))
23866     op0 = copy_to_mode_reg (mode0, op0);
23867   if ((optimize && !register_operand (op1, mode1))
23868       || ! (*insn_data[d->icode].operand[2].predicate) (op1, mode1))
23869     op1 = copy_to_mode_reg (mode1, op1);
23870
23871   op2 = gen_rtx_fmt_ee (comparison, mode0, op0, op1);
23872   pat = GEN_FCN (d->icode) (target, op0, op1, op2);
23873   if (! pat)
23874     return 0;
23875   emit_insn (pat);
23876   return target;
23877 }
23878
23879 /* Subroutine of ix86_expand_builtin to take care of comi insns.  */
23880
23881 static rtx
23882 ix86_expand_sse_comi (const struct builtin_description *d, tree exp,
23883                       rtx target)
23884 {
23885   rtx pat;
23886   tree arg0 = CALL_EXPR_ARG (exp, 0);
23887   tree arg1 = CALL_EXPR_ARG (exp, 1);
23888   rtx op0 = expand_normal (arg0);
23889   rtx op1 = expand_normal (arg1);
23890   enum machine_mode mode0 = insn_data[d->icode].operand[0].mode;
23891   enum machine_mode mode1 = insn_data[d->icode].operand[1].mode;
23892   enum rtx_code comparison = d->comparison;
23893
23894   if (VECTOR_MODE_P (mode0))
23895     op0 = safe_vector_operand (op0, mode0);
23896   if (VECTOR_MODE_P (mode1))
23897     op1 = safe_vector_operand (op1, mode1);
23898
23899   /* Swap operands if we have a comparison that isn't available in
23900      hardware.  */
23901   if (d->flag & BUILTIN_DESC_SWAP_OPERANDS)
23902     {
23903       rtx tmp = op1;
23904       op1 = op0;
23905       op0 = tmp;
23906     }
23907
23908   target = gen_reg_rtx (SImode);
23909   emit_move_insn (target, const0_rtx);
23910   target = gen_rtx_SUBREG (QImode, target, 0);
23911
23912   if ((optimize && !register_operand (op0, mode0))
23913       || !(*insn_data[d->icode].operand[0].predicate) (op0, mode0))
23914     op0 = copy_to_mode_reg (mode0, op0);
23915   if ((optimize && !register_operand (op1, mode1))
23916       || !(*insn_data[d->icode].operand[1].predicate) (op1, mode1))
23917     op1 = copy_to_mode_reg (mode1, op1);
23918
23919   pat = GEN_FCN (d->icode) (op0, op1);
23920   if (! pat)
23921     return 0;
23922   emit_insn (pat);
23923   emit_insn (gen_rtx_SET (VOIDmode,
23924                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
23925                           gen_rtx_fmt_ee (comparison, QImode,
23926                                           SET_DEST (pat),
23927                                           const0_rtx)));
23928
23929   return SUBREG_REG (target);
23930 }
23931
23932 /* Subroutine of ix86_expand_builtin to take care of ptest insns.  */
23933
23934 static rtx
23935 ix86_expand_sse_ptest (const struct builtin_description *d, tree exp,
23936                        rtx target)
23937 {
23938   rtx pat;
23939   tree arg0 = CALL_EXPR_ARG (exp, 0);
23940   tree arg1 = CALL_EXPR_ARG (exp, 1);
23941   rtx op0 = expand_normal (arg0);
23942   rtx op1 = expand_normal (arg1);
23943   enum machine_mode mode0 = insn_data[d->icode].operand[0].mode;
23944   enum machine_mode mode1 = insn_data[d->icode].operand[1].mode;
23945   enum rtx_code comparison = d->comparison;
23946
23947   if (VECTOR_MODE_P (mode0))
23948     op0 = safe_vector_operand (op0, mode0);
23949   if (VECTOR_MODE_P (mode1))
23950     op1 = safe_vector_operand (op1, mode1);
23951
23952   target = gen_reg_rtx (SImode);
23953   emit_move_insn (target, const0_rtx);
23954   target = gen_rtx_SUBREG (QImode, target, 0);
23955
23956   if ((optimize && !register_operand (op0, mode0))
23957       || !(*insn_data[d->icode].operand[0].predicate) (op0, mode0))
23958     op0 = copy_to_mode_reg (mode0, op0);
23959   if ((optimize && !register_operand (op1, mode1))
23960       || !(*insn_data[d->icode].operand[1].predicate) (op1, mode1))
23961     op1 = copy_to_mode_reg (mode1, op1);
23962
23963   pat = GEN_FCN (d->icode) (op0, op1);
23964   if (! pat)
23965     return 0;
23966   emit_insn (pat);
23967   emit_insn (gen_rtx_SET (VOIDmode,
23968                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
23969                           gen_rtx_fmt_ee (comparison, QImode,
23970                                           SET_DEST (pat),
23971                                           const0_rtx)));
23972
23973   return SUBREG_REG (target);
23974 }
23975
23976 /* Subroutine of ix86_expand_builtin to take care of pcmpestr[im] insns.  */
23977
23978 static rtx
23979 ix86_expand_sse_pcmpestr (const struct builtin_description *d,
23980                           tree exp, rtx target)
23981 {
23982   rtx pat;
23983   tree arg0 = CALL_EXPR_ARG (exp, 0);
23984   tree arg1 = CALL_EXPR_ARG (exp, 1);
23985   tree arg2 = CALL_EXPR_ARG (exp, 2);
23986   tree arg3 = CALL_EXPR_ARG (exp, 3);
23987   tree arg4 = CALL_EXPR_ARG (exp, 4);
23988   rtx scratch0, scratch1;
23989   rtx op0 = expand_normal (arg0);
23990   rtx op1 = expand_normal (arg1);
23991   rtx op2 = expand_normal (arg2);
23992   rtx op3 = expand_normal (arg3);
23993   rtx op4 = expand_normal (arg4);
23994   enum machine_mode tmode0, tmode1, modev2, modei3, modev4, modei5, modeimm;
23995
23996   tmode0 = insn_data[d->icode].operand[0].mode;
23997   tmode1 = insn_data[d->icode].operand[1].mode;
23998   modev2 = insn_data[d->icode].operand[2].mode;
23999   modei3 = insn_data[d->icode].operand[3].mode;
24000   modev4 = insn_data[d->icode].operand[4].mode;
24001   modei5 = insn_data[d->icode].operand[5].mode;
24002   modeimm = insn_data[d->icode].operand[6].mode;
24003
24004   if (VECTOR_MODE_P (modev2))
24005     op0 = safe_vector_operand (op0, modev2);
24006   if (VECTOR_MODE_P (modev4))
24007     op2 = safe_vector_operand (op2, modev4);
24008
24009   if (! (*insn_data[d->icode].operand[2].predicate) (op0, modev2))
24010     op0 = copy_to_mode_reg (modev2, op0);
24011   if (! (*insn_data[d->icode].operand[3].predicate) (op1, modei3))
24012     op1 = copy_to_mode_reg (modei3, op1);
24013   if ((optimize && !register_operand (op2, modev4))
24014       || !(*insn_data[d->icode].operand[4].predicate) (op2, modev4))
24015     op2 = copy_to_mode_reg (modev4, op2);
24016   if (! (*insn_data[d->icode].operand[5].predicate) (op3, modei5))
24017     op3 = copy_to_mode_reg (modei5, op3);
24018
24019   if (! (*insn_data[d->icode].operand[6].predicate) (op4, modeimm))
24020     {
24021       error ("the fifth argument must be a 8-bit immediate");
24022       return const0_rtx;
24023     }
24024
24025   if (d->code == IX86_BUILTIN_PCMPESTRI128)
24026     {
24027       if (optimize || !target
24028           || GET_MODE (target) != tmode0
24029           || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode0))
24030         target = gen_reg_rtx (tmode0);
24031
24032       scratch1 = gen_reg_rtx (tmode1);
24033
24034       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2, op3, op4);
24035     }
24036   else if (d->code == IX86_BUILTIN_PCMPESTRM128)
24037     {
24038       if (optimize || !target
24039           || GET_MODE (target) != tmode1
24040           || ! (*insn_data[d->icode].operand[1].predicate) (target, tmode1))
24041         target = gen_reg_rtx (tmode1);
24042
24043       scratch0 = gen_reg_rtx (tmode0);
24044
24045       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2, op3, op4);
24046     }
24047   else
24048     {
24049       gcc_assert (d->flag);
24050
24051       scratch0 = gen_reg_rtx (tmode0);
24052       scratch1 = gen_reg_rtx (tmode1);
24053
24054       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2, op3, op4);
24055     }
24056
24057   if (! pat)
24058     return 0;
24059
24060   emit_insn (pat);
24061
24062   if (d->flag)
24063     {
24064       target = gen_reg_rtx (SImode);
24065       emit_move_insn (target, const0_rtx);
24066       target = gen_rtx_SUBREG (QImode, target, 0);
24067
24068       emit_insn
24069         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
24070                       gen_rtx_fmt_ee (EQ, QImode,
24071                                       gen_rtx_REG ((enum machine_mode) d->flag,
24072                                                    FLAGS_REG),
24073                                       const0_rtx)));
24074       return SUBREG_REG (target);
24075     }
24076   else
24077     return target;
24078 }
24079
24080
24081 /* Subroutine of ix86_expand_builtin to take care of pcmpistr[im] insns.  */
24082
24083 static rtx
24084 ix86_expand_sse_pcmpistr (const struct builtin_description *d,
24085                           tree exp, rtx target)
24086 {
24087   rtx pat;
24088   tree arg0 = CALL_EXPR_ARG (exp, 0);
24089   tree arg1 = CALL_EXPR_ARG (exp, 1);
24090   tree arg2 = CALL_EXPR_ARG (exp, 2);
24091   rtx scratch0, scratch1;
24092   rtx op0 = expand_normal (arg0);
24093   rtx op1 = expand_normal (arg1);
24094   rtx op2 = expand_normal (arg2);
24095   enum machine_mode tmode0, tmode1, modev2, modev3, modeimm;
24096
24097   tmode0 = insn_data[d->icode].operand[0].mode;
24098   tmode1 = insn_data[d->icode].operand[1].mode;
24099   modev2 = insn_data[d->icode].operand[2].mode;
24100   modev3 = insn_data[d->icode].operand[3].mode;
24101   modeimm = insn_data[d->icode].operand[4].mode;
24102
24103   if (VECTOR_MODE_P (modev2))
24104     op0 = safe_vector_operand (op0, modev2);
24105   if (VECTOR_MODE_P (modev3))
24106     op1 = safe_vector_operand (op1, modev3);
24107
24108   if (! (*insn_data[d->icode].operand[2].predicate) (op0, modev2))
24109     op0 = copy_to_mode_reg (modev2, op0);
24110   if ((optimize && !register_operand (op1, modev3))
24111       || !(*insn_data[d->icode].operand[3].predicate) (op1, modev3))
24112     op1 = copy_to_mode_reg (modev3, op1);
24113
24114   if (! (*insn_data[d->icode].operand[4].predicate) (op2, modeimm))
24115     {
24116       error ("the third argument must be a 8-bit immediate");
24117       return const0_rtx;
24118     }
24119
24120   if (d->code == IX86_BUILTIN_PCMPISTRI128)
24121     {
24122       if (optimize || !target
24123           || GET_MODE (target) != tmode0
24124           || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode0))
24125         target = gen_reg_rtx (tmode0);
24126
24127       scratch1 = gen_reg_rtx (tmode1);
24128
24129       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2);
24130     }
24131   else if (d->code == IX86_BUILTIN_PCMPISTRM128)
24132     {
24133       if (optimize || !target
24134           || GET_MODE (target) != tmode1
24135           || ! (*insn_data[d->icode].operand[1].predicate) (target, tmode1))
24136         target = gen_reg_rtx (tmode1);
24137
24138       scratch0 = gen_reg_rtx (tmode0);
24139
24140       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2);
24141     }
24142   else
24143     {
24144       gcc_assert (d->flag);
24145
24146       scratch0 = gen_reg_rtx (tmode0);
24147       scratch1 = gen_reg_rtx (tmode1);
24148
24149       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2);
24150     }
24151
24152   if (! pat)
24153     return 0;
24154
24155   emit_insn (pat);
24156
24157   if (d->flag)
24158     {
24159       target = gen_reg_rtx (SImode);
24160       emit_move_insn (target, const0_rtx);
24161       target = gen_rtx_SUBREG (QImode, target, 0);
24162
24163       emit_insn
24164         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
24165                       gen_rtx_fmt_ee (EQ, QImode,
24166                                       gen_rtx_REG ((enum machine_mode) d->flag,
24167                                                    FLAGS_REG),
24168                                       const0_rtx)));
24169       return SUBREG_REG (target);
24170     }
24171   else
24172     return target;
24173 }
24174
24175 /* Subroutine of ix86_expand_builtin to take care of insns with
24176    variable number of operands.  */
24177
24178 static rtx
24179 ix86_expand_args_builtin (const struct builtin_description *d,
24180                           tree exp, rtx target)
24181 {
24182   rtx pat, real_target;
24183   unsigned int i, nargs;
24184   unsigned int nargs_constant = 0;
24185   int num_memory = 0;
24186   struct
24187     {
24188       rtx op;
24189       enum machine_mode mode;
24190     } args[4];
24191   bool last_arg_count = false;
24192   enum insn_code icode = d->icode;
24193   const struct insn_data *insn_p = &insn_data[icode];
24194   enum machine_mode tmode = insn_p->operand[0].mode;
24195   enum machine_mode rmode = VOIDmode;
24196   bool swap = false;
24197   enum rtx_code comparison = d->comparison;
24198
24199   switch ((enum ix86_builtin_type) d->flag)
24200     {
24201     case INT_FTYPE_V8SF_V8SF_PTEST:
24202     case INT_FTYPE_V4DI_V4DI_PTEST:
24203     case INT_FTYPE_V4DF_V4DF_PTEST:
24204     case INT_FTYPE_V4SF_V4SF_PTEST:
24205     case INT_FTYPE_V2DI_V2DI_PTEST:
24206     case INT_FTYPE_V2DF_V2DF_PTEST:
24207       return ix86_expand_sse_ptest (d, exp, target);
24208     case FLOAT128_FTYPE_FLOAT128:
24209     case FLOAT_FTYPE_FLOAT:
24210     case INT64_FTYPE_V4SF:
24211     case INT64_FTYPE_V2DF:
24212     case INT_FTYPE_V16QI:
24213     case INT_FTYPE_V8QI:
24214     case INT_FTYPE_V8SF:
24215     case INT_FTYPE_V4DF:
24216     case INT_FTYPE_V4SF:
24217     case INT_FTYPE_V2DF:
24218     case V16QI_FTYPE_V16QI:
24219     case V8SI_FTYPE_V8SF:
24220     case V8SI_FTYPE_V4SI:
24221     case V8HI_FTYPE_V8HI:
24222     case V8HI_FTYPE_V16QI:
24223     case V8QI_FTYPE_V8QI:
24224     case V8SF_FTYPE_V8SF:
24225     case V8SF_FTYPE_V8SI:
24226     case V8SF_FTYPE_V4SF:
24227     case V4SI_FTYPE_V4SI:
24228     case V4SI_FTYPE_V16QI:
24229     case V4SI_FTYPE_V4SF:
24230     case V4SI_FTYPE_V8SI:
24231     case V4SI_FTYPE_V8HI:
24232     case V4SI_FTYPE_V4DF:
24233     case V4SI_FTYPE_V2DF:
24234     case V4HI_FTYPE_V4HI:
24235     case V4DF_FTYPE_V4DF:
24236     case V4DF_FTYPE_V4SI:
24237     case V4DF_FTYPE_V4SF:
24238     case V4DF_FTYPE_V2DF:
24239     case V4SF_FTYPE_V4SF:
24240     case V4SF_FTYPE_V4SI:
24241     case V4SF_FTYPE_V8SF:
24242     case V4SF_FTYPE_V4DF:
24243     case V4SF_FTYPE_V2DF:
24244     case V2DI_FTYPE_V2DI:
24245     case V2DI_FTYPE_V16QI:
24246     case V2DI_FTYPE_V8HI:
24247     case V2DI_FTYPE_V4SI:
24248     case V2DF_FTYPE_V2DF:
24249     case V2DF_FTYPE_V4SI:
24250     case V2DF_FTYPE_V4DF:
24251     case V2DF_FTYPE_V4SF:
24252     case V2DF_FTYPE_V2SI:
24253     case V2SI_FTYPE_V2SI:
24254     case V2SI_FTYPE_V4SF:
24255     case V2SI_FTYPE_V2SF:
24256     case V2SI_FTYPE_V2DF:
24257     case V2SF_FTYPE_V2SF:
24258     case V2SF_FTYPE_V2SI:
24259       nargs = 1;
24260       break;
24261     case V4SF_FTYPE_V4SF_VEC_MERGE:
24262     case V2DF_FTYPE_V2DF_VEC_MERGE:
24263       return ix86_expand_unop_vec_merge_builtin (icode, exp, target);
24264     case FLOAT128_FTYPE_FLOAT128_FLOAT128:
24265     case V16QI_FTYPE_V16QI_V16QI:
24266     case V16QI_FTYPE_V8HI_V8HI:
24267     case V8QI_FTYPE_V8QI_V8QI:
24268     case V8QI_FTYPE_V4HI_V4HI:
24269     case V8HI_FTYPE_V8HI_V8HI:
24270     case V8HI_FTYPE_V16QI_V16QI:
24271     case V8HI_FTYPE_V4SI_V4SI:
24272     case V8SF_FTYPE_V8SF_V8SF:
24273     case V8SF_FTYPE_V8SF_V8SI:
24274     case V4SI_FTYPE_V4SI_V4SI:
24275     case V4SI_FTYPE_V8HI_V8HI:
24276     case V4SI_FTYPE_V4SF_V4SF:
24277     case V4SI_FTYPE_V2DF_V2DF:
24278     case V4HI_FTYPE_V4HI_V4HI:
24279     case V4HI_FTYPE_V8QI_V8QI:
24280     case V4HI_FTYPE_V2SI_V2SI:
24281     case V4DF_FTYPE_V4DF_V4DF:
24282     case V4DF_FTYPE_V4DF_V4DI:
24283     case V4SF_FTYPE_V4SF_V4SF:
24284     case V4SF_FTYPE_V4SF_V4SI:
24285     case V4SF_FTYPE_V4SF_V2SI:
24286     case V4SF_FTYPE_V4SF_V2DF:
24287     case V4SF_FTYPE_V4SF_DI:
24288     case V4SF_FTYPE_V4SF_SI:
24289     case V2DI_FTYPE_V2DI_V2DI:
24290     case V2DI_FTYPE_V16QI_V16QI:
24291     case V2DI_FTYPE_V4SI_V4SI:
24292     case V2DI_FTYPE_V2DI_V16QI:
24293     case V2DI_FTYPE_V2DF_V2DF:
24294     case V2SI_FTYPE_V2SI_V2SI:
24295     case V2SI_FTYPE_V4HI_V4HI:
24296     case V2SI_FTYPE_V2SF_V2SF:
24297     case V2DF_FTYPE_V2DF_V2DF:
24298     case V2DF_FTYPE_V2DF_V4SF:
24299     case V2DF_FTYPE_V2DF_V2DI:
24300     case V2DF_FTYPE_V2DF_DI:
24301     case V2DF_FTYPE_V2DF_SI:
24302     case V2SF_FTYPE_V2SF_V2SF:
24303     case V1DI_FTYPE_V1DI_V1DI:
24304     case V1DI_FTYPE_V8QI_V8QI:
24305     case V1DI_FTYPE_V2SI_V2SI:
24306       if (comparison == UNKNOWN)
24307         return ix86_expand_binop_builtin (icode, exp, target);
24308       nargs = 2;
24309       break;
24310     case V4SF_FTYPE_V4SF_V4SF_SWAP:
24311     case V2DF_FTYPE_V2DF_V2DF_SWAP:
24312       gcc_assert (comparison != UNKNOWN);
24313       nargs = 2;
24314       swap = true;
24315       break;
24316     case V8HI_FTYPE_V8HI_V8HI_COUNT:
24317     case V8HI_FTYPE_V8HI_SI_COUNT:
24318     case V4SI_FTYPE_V4SI_V4SI_COUNT:
24319     case V4SI_FTYPE_V4SI_SI_COUNT:
24320     case V4HI_FTYPE_V4HI_V4HI_COUNT:
24321     case V4HI_FTYPE_V4HI_SI_COUNT:
24322     case V2DI_FTYPE_V2DI_V2DI_COUNT:
24323     case V2DI_FTYPE_V2DI_SI_COUNT:
24324     case V2SI_FTYPE_V2SI_V2SI_COUNT:
24325     case V2SI_FTYPE_V2SI_SI_COUNT:
24326     case V1DI_FTYPE_V1DI_V1DI_COUNT:
24327     case V1DI_FTYPE_V1DI_SI_COUNT:
24328       nargs = 2;
24329       last_arg_count = true;
24330       break;
24331     case UINT64_FTYPE_UINT64_UINT64:
24332     case UINT_FTYPE_UINT_UINT:
24333     case UINT_FTYPE_UINT_USHORT:
24334     case UINT_FTYPE_UINT_UCHAR:
24335       nargs = 2;
24336       break;
24337     case V2DI2TI_FTYPE_V2DI_INT:
24338       nargs = 2;
24339       rmode = V2DImode;
24340       nargs_constant = 1;
24341       break;
24342     case V8HI_FTYPE_V8HI_INT:
24343     case V8SF_FTYPE_V8SF_INT:
24344     case V4SI_FTYPE_V4SI_INT:
24345     case V4SI_FTYPE_V8SI_INT:
24346     case V4HI_FTYPE_V4HI_INT:
24347     case V4DF_FTYPE_V4DF_INT:
24348     case V4SF_FTYPE_V4SF_INT:
24349     case V4SF_FTYPE_V8SF_INT:
24350     case V2DI_FTYPE_V2DI_INT:
24351     case V2DF_FTYPE_V2DF_INT:
24352     case V2DF_FTYPE_V4DF_INT:
24353       nargs = 2;
24354       nargs_constant = 1;
24355       break;
24356     case V16QI_FTYPE_V16QI_V16QI_V16QI:
24357     case V8SF_FTYPE_V8SF_V8SF_V8SF:
24358     case V4DF_FTYPE_V4DF_V4DF_V4DF:
24359     case V4SF_FTYPE_V4SF_V4SF_V4SF:
24360     case V2DF_FTYPE_V2DF_V2DF_V2DF:
24361       nargs = 3;
24362       break;
24363     case V16QI_FTYPE_V16QI_V16QI_INT:
24364     case V8HI_FTYPE_V8HI_V8HI_INT:
24365     case V8SI_FTYPE_V8SI_V8SI_INT:
24366     case V8SI_FTYPE_V8SI_V4SI_INT:
24367     case V8SF_FTYPE_V8SF_V8SF_INT: 
24368     case V8SF_FTYPE_V8SF_V4SF_INT: 
24369     case V4SI_FTYPE_V4SI_V4SI_INT:
24370     case V4DF_FTYPE_V4DF_V4DF_INT:
24371     case V4DF_FTYPE_V4DF_V2DF_INT:
24372     case V4SF_FTYPE_V4SF_V4SF_INT:
24373     case V2DI_FTYPE_V2DI_V2DI_INT:
24374     case V2DF_FTYPE_V2DF_V2DF_INT:
24375       nargs = 3;
24376       nargs_constant = 1;
24377       break;
24378     case V2DI2TI_FTYPE_V2DI_V2DI_INT:
24379       nargs = 3;
24380       rmode = V2DImode;
24381       nargs_constant = 1;
24382       break;
24383     case V1DI2DI_FTYPE_V1DI_V1DI_INT:
24384       nargs = 3;
24385       rmode = DImode;
24386       nargs_constant = 1;
24387       break;
24388     case V2DI_FTYPE_V2DI_UINT_UINT:
24389       nargs = 3;
24390       nargs_constant = 2;
24391       break;
24392     case V2DI_FTYPE_V2DI_V2DI_UINT_UINT:
24393       nargs = 4;
24394       nargs_constant = 2;
24395       break;
24396     default:
24397       gcc_unreachable ();
24398     }
24399
24400   gcc_assert (nargs <= ARRAY_SIZE (args));
24401
24402   if (comparison != UNKNOWN)
24403     {
24404       gcc_assert (nargs == 2);
24405       return ix86_expand_sse_compare (d, exp, target, swap);
24406     }
24407
24408   if (rmode == VOIDmode || rmode == tmode)
24409     {
24410       if (optimize
24411           || target == 0
24412           || GET_MODE (target) != tmode
24413           || ! (*insn_p->operand[0].predicate) (target, tmode))
24414         target = gen_reg_rtx (tmode);
24415       real_target = target;
24416     }
24417   else
24418     {
24419       target = gen_reg_rtx (rmode);
24420       real_target = simplify_gen_subreg (tmode, target, rmode, 0);
24421     }
24422
24423   for (i = 0; i < nargs; i++)
24424     {
24425       tree arg = CALL_EXPR_ARG (exp, i);
24426       rtx op = expand_normal (arg);
24427       enum machine_mode mode = insn_p->operand[i + 1].mode;
24428       bool match = (*insn_p->operand[i + 1].predicate) (op, mode);
24429
24430       if (last_arg_count && (i + 1) == nargs)
24431         {
24432           /* SIMD shift insns take either an 8-bit immediate or
24433              register as count.  But builtin functions take int as
24434              count.  If count doesn't match, we put it in register.  */
24435           if (!match)
24436             {
24437               op = simplify_gen_subreg (SImode, op, GET_MODE (op), 0);
24438               if (!(*insn_p->operand[i + 1].predicate) (op, mode))
24439                 op = copy_to_reg (op);
24440             }
24441         }
24442       else if ((nargs - i) <= nargs_constant)
24443         {
24444           if (!match)
24445             switch (icode)
24446               {
24447               case CODE_FOR_sse4_1_roundpd:
24448               case CODE_FOR_sse4_1_roundps:
24449               case CODE_FOR_sse4_1_roundsd:
24450               case CODE_FOR_sse4_1_roundss:
24451               case CODE_FOR_sse4_1_blendps:
24452               case CODE_FOR_avx_blendpd256:
24453               case CODE_FOR_avx_vpermilv4df:
24454               case CODE_FOR_avx_roundpd256:
24455               case CODE_FOR_avx_roundps256:
24456                 error ("the last argument must be a 4-bit immediate");
24457                 return const0_rtx;
24458
24459               case CODE_FOR_sse4_1_blendpd:
24460               case CODE_FOR_avx_vpermilv2df:
24461                 error ("the last argument must be a 2-bit immediate");
24462                 return const0_rtx;
24463
24464               case CODE_FOR_avx_vextractf128v4df:
24465               case CODE_FOR_avx_vextractf128v8sf:
24466               case CODE_FOR_avx_vextractf128v8si:
24467               case CODE_FOR_avx_vinsertf128v4df:
24468               case CODE_FOR_avx_vinsertf128v8sf:
24469               case CODE_FOR_avx_vinsertf128v8si:
24470                 error ("the last argument must be a 1-bit immediate");
24471                 return const0_rtx;
24472
24473               case CODE_FOR_avx_cmpsdv2df3:
24474               case CODE_FOR_avx_cmpssv4sf3:
24475               case CODE_FOR_avx_cmppdv2df3:
24476               case CODE_FOR_avx_cmppsv4sf3:
24477               case CODE_FOR_avx_cmppdv4df3:
24478               case CODE_FOR_avx_cmppsv8sf3:
24479                 error ("the last argument must be a 5-bit immediate");
24480                 return const0_rtx;
24481
24482              default:
24483                 switch (nargs_constant)
24484                   {
24485                   case 2:
24486                     if ((nargs - i) == nargs_constant)
24487                       {
24488                         error ("the next to last argument must be an 8-bit immediate");
24489                         break;
24490                       }
24491                   case 1:
24492                     error ("the last argument must be an 8-bit immediate");
24493                     break;
24494                   default:
24495                     gcc_unreachable ();
24496                   }
24497                 return const0_rtx;
24498               }
24499         }
24500       else
24501         {
24502           if (VECTOR_MODE_P (mode))
24503             op = safe_vector_operand (op, mode);
24504
24505           /* If we aren't optimizing, only allow one memory operand to
24506              be generated.  */
24507           if (memory_operand (op, mode))
24508             num_memory++;
24509
24510           if (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
24511             {
24512               if (optimize || !match || num_memory > 1)
24513                 op = copy_to_mode_reg (mode, op);
24514             }
24515           else
24516             {
24517               op = copy_to_reg (op);
24518               op = simplify_gen_subreg (mode, op, GET_MODE (op), 0);
24519             }
24520         }
24521
24522       args[i].op = op;
24523       args[i].mode = mode;
24524     }
24525
24526   switch (nargs)
24527     {
24528     case 1:
24529       pat = GEN_FCN (icode) (real_target, args[0].op);
24530       break;
24531     case 2:
24532       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op);
24533       break;
24534     case 3:
24535       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
24536                              args[2].op);
24537       break;
24538     case 4:
24539       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
24540                              args[2].op, args[3].op);
24541       break;
24542     default:
24543       gcc_unreachable ();
24544     }
24545
24546   if (! pat)
24547     return 0;
24548
24549   emit_insn (pat);
24550   return target;
24551 }
24552
24553 /* Subroutine of ix86_expand_builtin to take care of special insns
24554    with variable number of operands.  */
24555
24556 static rtx
24557 ix86_expand_special_args_builtin (const struct builtin_description *d,
24558                                     tree exp, rtx target)
24559 {
24560   tree arg;
24561   rtx pat, op;
24562   unsigned int i, nargs, arg_adjust, memory;
24563   struct
24564     {
24565       rtx op;
24566       enum machine_mode mode;
24567     } args[2];
24568   enum insn_code icode = d->icode;
24569   bool last_arg_constant = false;
24570   const struct insn_data *insn_p = &insn_data[icode];
24571   enum machine_mode tmode = insn_p->operand[0].mode;
24572   enum { load, store } klass;
24573
24574   switch ((enum ix86_special_builtin_type) d->flag)
24575     {
24576     case VOID_FTYPE_VOID:
24577       emit_insn (GEN_FCN (icode) (target));
24578       return 0;
24579     case V2DI_FTYPE_PV2DI:
24580     case V32QI_FTYPE_PCCHAR:
24581     case V16QI_FTYPE_PCCHAR:
24582     case V8SF_FTYPE_PCV4SF:
24583     case V8SF_FTYPE_PCFLOAT:
24584     case V4SF_FTYPE_PCFLOAT:
24585     case V4DF_FTYPE_PCV2DF:
24586     case V4DF_FTYPE_PCDOUBLE:
24587     case V2DF_FTYPE_PCDOUBLE:
24588       nargs = 1;
24589       klass = load;
24590       memory = 0;
24591       break;
24592     case VOID_FTYPE_PV2SF_V4SF:
24593     case VOID_FTYPE_PV4DI_V4DI:
24594     case VOID_FTYPE_PV2DI_V2DI:
24595     case VOID_FTYPE_PCHAR_V32QI:
24596     case VOID_FTYPE_PCHAR_V16QI:
24597     case VOID_FTYPE_PFLOAT_V8SF:
24598     case VOID_FTYPE_PFLOAT_V4SF:
24599     case VOID_FTYPE_PDOUBLE_V4DF:
24600     case VOID_FTYPE_PDOUBLE_V2DF:
24601     case VOID_FTYPE_PDI_DI:
24602     case VOID_FTYPE_PINT_INT:
24603       nargs = 1;
24604       klass = store;
24605       /* Reserve memory operand for target.  */
24606       memory = ARRAY_SIZE (args);
24607       break;
24608     case V4SF_FTYPE_V4SF_PCV2SF:
24609     case V2DF_FTYPE_V2DF_PCDOUBLE:
24610       nargs = 2;
24611       klass = load;
24612       memory = 1;
24613       break;
24614     case V8SF_FTYPE_PCV8SF_V8SF:
24615     case V4DF_FTYPE_PCV4DF_V4DF:
24616     case V4SF_FTYPE_PCV4SF_V4SF:
24617     case V2DF_FTYPE_PCV2DF_V2DF:
24618       nargs = 2;
24619       klass = load;
24620       memory = 0;
24621       break;
24622     case VOID_FTYPE_PV8SF_V8SF_V8SF:
24623     case VOID_FTYPE_PV4DF_V4DF_V4DF:
24624     case VOID_FTYPE_PV4SF_V4SF_V4SF:
24625     case VOID_FTYPE_PV2DF_V2DF_V2DF:
24626       nargs = 2;
24627       klass = store;
24628       /* Reserve memory operand for target.  */
24629       memory = ARRAY_SIZE (args);
24630       break;
24631     default:
24632       gcc_unreachable ();
24633     }
24634
24635   gcc_assert (nargs <= ARRAY_SIZE (args));
24636
24637   if (klass == store)
24638     {
24639       arg = CALL_EXPR_ARG (exp, 0);
24640       op = expand_normal (arg);
24641       gcc_assert (target == 0);
24642       target = gen_rtx_MEM (tmode, copy_to_mode_reg (Pmode, op));
24643       arg_adjust = 1;
24644     }
24645   else
24646     {
24647       arg_adjust = 0;
24648       if (optimize
24649           || target == 0
24650           || GET_MODE (target) != tmode
24651           || ! (*insn_p->operand[0].predicate) (target, tmode))
24652         target = gen_reg_rtx (tmode);
24653     }
24654
24655   for (i = 0; i < nargs; i++)
24656     {
24657       enum machine_mode mode = insn_p->operand[i + 1].mode;
24658       bool match;
24659
24660       arg = CALL_EXPR_ARG (exp, i + arg_adjust);
24661       op = expand_normal (arg);
24662       match = (*insn_p->operand[i + 1].predicate) (op, mode);
24663
24664       if (last_arg_constant && (i + 1) == nargs)
24665         {
24666           if (!match)
24667             switch (icode)
24668               {
24669              default:
24670                 error ("the last argument must be an 8-bit immediate");
24671                 return const0_rtx;
24672               }
24673         }
24674       else
24675         {
24676           if (i == memory)
24677             {
24678               /* This must be the memory operand.  */
24679               op = gen_rtx_MEM (mode, copy_to_mode_reg (Pmode, op));
24680               gcc_assert (GET_MODE (op) == mode
24681                           || GET_MODE (op) == VOIDmode);
24682             }
24683           else
24684             {
24685               /* This must be register.  */
24686               if (VECTOR_MODE_P (mode))
24687                 op = safe_vector_operand (op, mode);
24688
24689               gcc_assert (GET_MODE (op) == mode
24690                           || GET_MODE (op) == VOIDmode);
24691               op = copy_to_mode_reg (mode, op);
24692             }
24693         }
24694
24695       args[i].op = op;
24696       args[i].mode = mode;
24697     }
24698
24699   switch (nargs)
24700     {
24701     case 1:
24702       pat = GEN_FCN (icode) (target, args[0].op);
24703       break;
24704     case 2:
24705       pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
24706       break;
24707     default:
24708       gcc_unreachable ();
24709     }
24710
24711   if (! pat)
24712     return 0;
24713   emit_insn (pat);
24714   return klass == store ? 0 : target;
24715 }
24716
24717 /* Return the integer constant in ARG.  Constrain it to be in the range
24718    of the subparts of VEC_TYPE; issue an error if not.  */
24719
24720 static int
24721 get_element_number (tree vec_type, tree arg)
24722 {
24723   unsigned HOST_WIDE_INT elt, max = TYPE_VECTOR_SUBPARTS (vec_type) - 1;
24724
24725   if (!host_integerp (arg, 1)
24726       || (elt = tree_low_cst (arg, 1), elt > max))
24727     {
24728       error ("selector must be an integer constant in the range 0..%wi", max);
24729       return 0;
24730     }
24731
24732   return elt;
24733 }
24734
24735 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
24736    ix86_expand_vector_init.  We DO have language-level syntax for this, in
24737    the form of  (type){ init-list }.  Except that since we can't place emms
24738    instructions from inside the compiler, we can't allow the use of MMX
24739    registers unless the user explicitly asks for it.  So we do *not* define
24740    vec_set/vec_extract/vec_init patterns for MMX modes in mmx.md.  Instead
24741    we have builtins invoked by mmintrin.h that gives us license to emit
24742    these sorts of instructions.  */
24743
24744 static rtx
24745 ix86_expand_vec_init_builtin (tree type, tree exp, rtx target)
24746 {
24747   enum machine_mode tmode = TYPE_MODE (type);
24748   enum machine_mode inner_mode = GET_MODE_INNER (tmode);
24749   int i, n_elt = GET_MODE_NUNITS (tmode);
24750   rtvec v = rtvec_alloc (n_elt);
24751
24752   gcc_assert (VECTOR_MODE_P (tmode));
24753   gcc_assert (call_expr_nargs (exp) == n_elt);
24754
24755   for (i = 0; i < n_elt; ++i)
24756     {
24757       rtx x = expand_normal (CALL_EXPR_ARG (exp, i));
24758       RTVEC_ELT (v, i) = gen_lowpart (inner_mode, x);
24759     }
24760
24761   if (!target || !register_operand (target, tmode))
24762     target = gen_reg_rtx (tmode);
24763
24764   ix86_expand_vector_init (true, target, gen_rtx_PARALLEL (tmode, v));
24765   return target;
24766 }
24767
24768 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
24769    ix86_expand_vector_extract.  They would be redundant (for non-MMX) if we
24770    had a language-level syntax for referencing vector elements.  */
24771
24772 static rtx
24773 ix86_expand_vec_ext_builtin (tree exp, rtx target)
24774 {
24775   enum machine_mode tmode, mode0;
24776   tree arg0, arg1;
24777   int elt;
24778   rtx op0;
24779
24780   arg0 = CALL_EXPR_ARG (exp, 0);
24781   arg1 = CALL_EXPR_ARG (exp, 1);
24782
24783   op0 = expand_normal (arg0);
24784   elt = get_element_number (TREE_TYPE (arg0), arg1);
24785
24786   tmode = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
24787   mode0 = TYPE_MODE (TREE_TYPE (arg0));
24788   gcc_assert (VECTOR_MODE_P (mode0));
24789
24790   op0 = force_reg (mode0, op0);
24791
24792   if (optimize || !target || !register_operand (target, tmode))
24793     target = gen_reg_rtx (tmode);
24794
24795   ix86_expand_vector_extract (true, target, op0, elt);
24796
24797   return target;
24798 }
24799
24800 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
24801    ix86_expand_vector_set.  They would be redundant (for non-MMX) if we had
24802    a language-level syntax for referencing vector elements.  */
24803
24804 static rtx
24805 ix86_expand_vec_set_builtin (tree exp)
24806 {
24807   enum machine_mode tmode, mode1;
24808   tree arg0, arg1, arg2;
24809   int elt;
24810   rtx op0, op1, target;
24811
24812   arg0 = CALL_EXPR_ARG (exp, 0);
24813   arg1 = CALL_EXPR_ARG (exp, 1);
24814   arg2 = CALL_EXPR_ARG (exp, 2);
24815
24816   tmode = TYPE_MODE (TREE_TYPE (arg0));
24817   mode1 = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
24818   gcc_assert (VECTOR_MODE_P (tmode));
24819
24820   op0 = expand_expr (arg0, NULL_RTX, tmode, EXPAND_NORMAL);
24821   op1 = expand_expr (arg1, NULL_RTX, mode1, EXPAND_NORMAL);
24822   elt = get_element_number (TREE_TYPE (arg0), arg2);
24823
24824   if (GET_MODE (op1) != mode1 && GET_MODE (op1) != VOIDmode)
24825     op1 = convert_modes (mode1, GET_MODE (op1), op1, true);
24826
24827   op0 = force_reg (tmode, op0);
24828   op1 = force_reg (mode1, op1);
24829
24830   /* OP0 is the source of these builtin functions and shouldn't be
24831      modified.  Create a copy, use it and return it as target.  */
24832   target = gen_reg_rtx (tmode);
24833   emit_move_insn (target, op0);
24834   ix86_expand_vector_set (true, target, op1, elt);
24835
24836   return target;
24837 }
24838
24839 /* Expand an expression EXP that calls a built-in function,
24840    with result going to TARGET if that's convenient
24841    (and in mode MODE if that's convenient).
24842    SUBTARGET may be used as the target for computing one of EXP's operands.
24843    IGNORE is nonzero if the value is to be ignored.  */
24844
24845 static rtx
24846 ix86_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
24847                      enum machine_mode mode ATTRIBUTE_UNUSED,
24848                      int ignore ATTRIBUTE_UNUSED)
24849 {
24850   const struct builtin_description *d;
24851   size_t i;
24852   enum insn_code icode;
24853   tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
24854   tree arg0, arg1, arg2;
24855   rtx op0, op1, op2, pat;
24856   enum machine_mode mode0, mode1, mode2;
24857   unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
24858
24859   /* Determine whether the builtin function is available under the current ISA.
24860      Originally the builtin was not created if it wasn't applicable to the
24861      current ISA based on the command line switches.  With function specific
24862      options, we need to check in the context of the function making the call
24863      whether it is supported.  */
24864   if (ix86_builtins_isa[fcode].isa
24865       && !(ix86_builtins_isa[fcode].isa & ix86_isa_flags))
24866     {
24867       char *opts = ix86_target_string (ix86_builtins_isa[fcode].isa, 0, NULL,
24868                                        NULL, NULL, false);
24869
24870       if (!opts)
24871         error ("%qE needs unknown isa option", fndecl);
24872       else
24873         {
24874           gcc_assert (opts != NULL);
24875           error ("%qE needs isa option %s", fndecl, opts);
24876           free (opts);
24877         }
24878       return const0_rtx;
24879     }
24880
24881   switch (fcode)
24882     {
24883     case IX86_BUILTIN_MASKMOVQ:
24884     case IX86_BUILTIN_MASKMOVDQU:
24885       icode = (fcode == IX86_BUILTIN_MASKMOVQ
24886                ? CODE_FOR_mmx_maskmovq
24887                : CODE_FOR_sse2_maskmovdqu);
24888       /* Note the arg order is different from the operand order.  */
24889       arg1 = CALL_EXPR_ARG (exp, 0);
24890       arg2 = CALL_EXPR_ARG (exp, 1);
24891       arg0 = CALL_EXPR_ARG (exp, 2);
24892       op0 = expand_normal (arg0);
24893       op1 = expand_normal (arg1);
24894       op2 = expand_normal (arg2);
24895       mode0 = insn_data[icode].operand[0].mode;
24896       mode1 = insn_data[icode].operand[1].mode;
24897       mode2 = insn_data[icode].operand[2].mode;
24898
24899       op0 = force_reg (Pmode, op0);
24900       op0 = gen_rtx_MEM (mode1, op0);
24901
24902       if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
24903         op0 = copy_to_mode_reg (mode0, op0);
24904       if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
24905         op1 = copy_to_mode_reg (mode1, op1);
24906       if (! (*insn_data[icode].operand[2].predicate) (op2, mode2))
24907         op2 = copy_to_mode_reg (mode2, op2);
24908       pat = GEN_FCN (icode) (op0, op1, op2);
24909       if (! pat)
24910         return 0;
24911       emit_insn (pat);
24912       return 0;
24913
24914     case IX86_BUILTIN_LDMXCSR:
24915       op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
24916       target = assign_386_stack_local (SImode, SLOT_VIRTUAL);
24917       emit_move_insn (target, op0);
24918       emit_insn (gen_sse_ldmxcsr (target));
24919       return 0;
24920
24921     case IX86_BUILTIN_STMXCSR:
24922       target = assign_386_stack_local (SImode, SLOT_VIRTUAL);
24923       emit_insn (gen_sse_stmxcsr (target));
24924       return copy_to_mode_reg (SImode, target);
24925
24926     case IX86_BUILTIN_CLFLUSH:
24927         arg0 = CALL_EXPR_ARG (exp, 0);
24928         op0 = expand_normal (arg0);
24929         icode = CODE_FOR_sse2_clflush;
24930         if (! (*insn_data[icode].operand[0].predicate) (op0, Pmode))
24931             op0 = copy_to_mode_reg (Pmode, op0);
24932
24933         emit_insn (gen_sse2_clflush (op0));
24934         return 0;
24935
24936     case IX86_BUILTIN_MONITOR:
24937       arg0 = CALL_EXPR_ARG (exp, 0);
24938       arg1 = CALL_EXPR_ARG (exp, 1);
24939       arg2 = CALL_EXPR_ARG (exp, 2);
24940       op0 = expand_normal (arg0);
24941       op1 = expand_normal (arg1);
24942       op2 = expand_normal (arg2);
24943       if (!REG_P (op0))
24944         op0 = copy_to_mode_reg (Pmode, op0);
24945       if (!REG_P (op1))
24946         op1 = copy_to_mode_reg (SImode, op1);
24947       if (!REG_P (op2))
24948         op2 = copy_to_mode_reg (SImode, op2);
24949       emit_insn ((*ix86_gen_monitor) (op0, op1, op2));
24950       return 0;
24951
24952     case IX86_BUILTIN_MWAIT:
24953       arg0 = CALL_EXPR_ARG (exp, 0);
24954       arg1 = CALL_EXPR_ARG (exp, 1);
24955       op0 = expand_normal (arg0);
24956       op1 = expand_normal (arg1);
24957       if (!REG_P (op0))
24958         op0 = copy_to_mode_reg (SImode, op0);
24959       if (!REG_P (op1))
24960         op1 = copy_to_mode_reg (SImode, op1);
24961       emit_insn (gen_sse3_mwait (op0, op1));
24962       return 0;
24963
24964     case IX86_BUILTIN_VEC_INIT_V2SI:
24965     case IX86_BUILTIN_VEC_INIT_V4HI:
24966     case IX86_BUILTIN_VEC_INIT_V8QI:
24967       return ix86_expand_vec_init_builtin (TREE_TYPE (exp), exp, target);
24968
24969     case IX86_BUILTIN_VEC_EXT_V2DF:
24970     case IX86_BUILTIN_VEC_EXT_V2DI:
24971     case IX86_BUILTIN_VEC_EXT_V4SF:
24972     case IX86_BUILTIN_VEC_EXT_V4SI:
24973     case IX86_BUILTIN_VEC_EXT_V8HI:
24974     case IX86_BUILTIN_VEC_EXT_V2SI:
24975     case IX86_BUILTIN_VEC_EXT_V4HI:
24976     case IX86_BUILTIN_VEC_EXT_V16QI:
24977       return ix86_expand_vec_ext_builtin (exp, target);
24978
24979     case IX86_BUILTIN_VEC_SET_V2DI:
24980     case IX86_BUILTIN_VEC_SET_V4SF:
24981     case IX86_BUILTIN_VEC_SET_V4SI:
24982     case IX86_BUILTIN_VEC_SET_V8HI:
24983     case IX86_BUILTIN_VEC_SET_V4HI:
24984     case IX86_BUILTIN_VEC_SET_V16QI:
24985       return ix86_expand_vec_set_builtin (exp);
24986
24987     case IX86_BUILTIN_INFQ:
24988       {
24989         REAL_VALUE_TYPE inf;
24990         rtx tmp;
24991
24992         real_inf (&inf);
24993         tmp = CONST_DOUBLE_FROM_REAL_VALUE (inf, mode);
24994
24995         tmp = validize_mem (force_const_mem (mode, tmp));
24996
24997         if (target == 0)
24998           target = gen_reg_rtx (mode);
24999
25000         emit_move_insn (target, tmp);
25001         return target;
25002       }
25003
25004     default:
25005       break;
25006     }
25007
25008   for (i = 0, d = bdesc_special_args;
25009        i < ARRAY_SIZE (bdesc_special_args);
25010        i++, d++)
25011     if (d->code == fcode)
25012       return ix86_expand_special_args_builtin (d, exp, target);
25013
25014   for (i = 0, d = bdesc_args;
25015        i < ARRAY_SIZE (bdesc_args);
25016        i++, d++)
25017     if (d->code == fcode)
25018       switch (fcode)
25019         {
25020         case IX86_BUILTIN_FABSQ:
25021         case IX86_BUILTIN_COPYSIGNQ:
25022           if (!TARGET_SSE2)
25023             /* Emit a normal call if SSE2 isn't available.  */
25024             return expand_call (exp, target, ignore);
25025         default:
25026           return ix86_expand_args_builtin (d, exp, target);
25027         }
25028
25029   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
25030     if (d->code == fcode)
25031       return ix86_expand_sse_comi (d, exp, target);
25032
25033   for (i = 0, d = bdesc_pcmpestr;
25034        i < ARRAY_SIZE (bdesc_pcmpestr);
25035        i++, d++)
25036     if (d->code == fcode)
25037       return ix86_expand_sse_pcmpestr (d, exp, target);
25038
25039   for (i = 0, d = bdesc_pcmpistr;
25040        i < ARRAY_SIZE (bdesc_pcmpistr);
25041        i++, d++)
25042     if (d->code == fcode)
25043       return ix86_expand_sse_pcmpistr (d, exp, target);
25044
25045   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
25046     if (d->code == fcode)
25047       return ix86_expand_multi_arg_builtin (d->icode, exp, target,
25048                                             (enum multi_arg_type)d->flag,
25049                                             d->comparison);
25050
25051   gcc_unreachable ();
25052 }
25053
25054 /* Returns a function decl for a vectorized version of the builtin function
25055    with builtin function code FN and the result vector type TYPE, or NULL_TREE
25056    if it is not available.  */
25057
25058 static tree
25059 ix86_builtin_vectorized_function (unsigned int fn, tree type_out,
25060                                   tree type_in)
25061 {
25062   enum machine_mode in_mode, out_mode;
25063   int in_n, out_n;
25064
25065   if (TREE_CODE (type_out) != VECTOR_TYPE
25066       || TREE_CODE (type_in) != VECTOR_TYPE)
25067     return NULL_TREE;
25068
25069   out_mode = TYPE_MODE (TREE_TYPE (type_out));
25070   out_n = TYPE_VECTOR_SUBPARTS (type_out);
25071   in_mode = TYPE_MODE (TREE_TYPE (type_in));
25072   in_n = TYPE_VECTOR_SUBPARTS (type_in);
25073
25074   switch (fn)
25075     {
25076     case BUILT_IN_SQRT:
25077       if (out_mode == DFmode && out_n == 2
25078           && in_mode == DFmode && in_n == 2)
25079         return ix86_builtins[IX86_BUILTIN_SQRTPD];
25080       break;
25081
25082     case BUILT_IN_SQRTF:
25083       if (out_mode == SFmode && out_n == 4
25084           && in_mode == SFmode && in_n == 4)
25085         return ix86_builtins[IX86_BUILTIN_SQRTPS_NR];
25086       break;
25087
25088     case BUILT_IN_LRINT:
25089       if (out_mode == SImode && out_n == 4
25090           && in_mode == DFmode && in_n == 2)
25091         return ix86_builtins[IX86_BUILTIN_VEC_PACK_SFIX];
25092       break;
25093
25094     case BUILT_IN_LRINTF:
25095       if (out_mode == SImode && out_n == 4
25096           && in_mode == SFmode && in_n == 4)
25097         return ix86_builtins[IX86_BUILTIN_CVTPS2DQ];
25098       break;
25099
25100     default:
25101       ;
25102     }
25103
25104   /* Dispatch to a handler for a vectorization library.  */
25105   if (ix86_veclib_handler)
25106     return (*ix86_veclib_handler)(fn, type_out, type_in);
25107
25108   return NULL_TREE;
25109 }
25110
25111 /* Handler for an SVML-style interface to
25112    a library with vectorized intrinsics.  */
25113
25114 static tree
25115 ix86_veclibabi_svml (enum built_in_function fn, tree type_out, tree type_in)
25116 {
25117   char name[20];
25118   tree fntype, new_fndecl, args;
25119   unsigned arity;
25120   const char *bname;
25121   enum machine_mode el_mode, in_mode;
25122   int n, in_n;
25123
25124   /* The SVML is suitable for unsafe math only.  */
25125   if (!flag_unsafe_math_optimizations)
25126     return NULL_TREE;
25127
25128   el_mode = TYPE_MODE (TREE_TYPE (type_out));
25129   n = TYPE_VECTOR_SUBPARTS (type_out);
25130   in_mode = TYPE_MODE (TREE_TYPE (type_in));
25131   in_n = TYPE_VECTOR_SUBPARTS (type_in);
25132   if (el_mode != in_mode
25133       || n != in_n)
25134     return NULL_TREE;
25135
25136   switch (fn)
25137     {
25138     case BUILT_IN_EXP:
25139     case BUILT_IN_LOG:
25140     case BUILT_IN_LOG10:
25141     case BUILT_IN_POW:
25142     case BUILT_IN_TANH:
25143     case BUILT_IN_TAN:
25144     case BUILT_IN_ATAN:
25145     case BUILT_IN_ATAN2:
25146     case BUILT_IN_ATANH:
25147     case BUILT_IN_CBRT:
25148     case BUILT_IN_SINH:
25149     case BUILT_IN_SIN:
25150     case BUILT_IN_ASINH:
25151     case BUILT_IN_ASIN:
25152     case BUILT_IN_COSH:
25153     case BUILT_IN_COS:
25154     case BUILT_IN_ACOSH:
25155     case BUILT_IN_ACOS:
25156       if (el_mode != DFmode || n != 2)
25157         return NULL_TREE;
25158       break;
25159
25160     case BUILT_IN_EXPF:
25161     case BUILT_IN_LOGF:
25162     case BUILT_IN_LOG10F:
25163     case BUILT_IN_POWF:
25164     case BUILT_IN_TANHF:
25165     case BUILT_IN_TANF:
25166     case BUILT_IN_ATANF:
25167     case BUILT_IN_ATAN2F:
25168     case BUILT_IN_ATANHF:
25169     case BUILT_IN_CBRTF:
25170     case BUILT_IN_SINHF:
25171     case BUILT_IN_SINF:
25172     case BUILT_IN_ASINHF:
25173     case BUILT_IN_ASINF:
25174     case BUILT_IN_COSHF:
25175     case BUILT_IN_COSF:
25176     case BUILT_IN_ACOSHF:
25177     case BUILT_IN_ACOSF:
25178       if (el_mode != SFmode || n != 4)
25179         return NULL_TREE;
25180       break;
25181
25182     default:
25183       return NULL_TREE;
25184     }
25185
25186   bname = IDENTIFIER_POINTER (DECL_NAME (implicit_built_in_decls[fn]));
25187
25188   if (fn == BUILT_IN_LOGF)
25189     strcpy (name, "vmlsLn4");
25190   else if (fn == BUILT_IN_LOG)
25191     strcpy (name, "vmldLn2");
25192   else if (n == 4)
25193     {
25194       sprintf (name, "vmls%s", bname+10);
25195       name[strlen (name)-1] = '4';
25196     }
25197   else
25198     sprintf (name, "vmld%s2", bname+10);
25199
25200   /* Convert to uppercase. */
25201   name[4] &= ~0x20;
25202
25203   arity = 0;
25204   for (args = DECL_ARGUMENTS (implicit_built_in_decls[fn]); args;
25205        args = TREE_CHAIN (args))
25206     arity++;
25207
25208   if (arity == 1)
25209     fntype = build_function_type_list (type_out, type_in, NULL);
25210   else
25211     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
25212
25213   /* Build a function declaration for the vectorized function.  */
25214   new_fndecl = build_decl (FUNCTION_DECL, get_identifier (name), fntype);
25215   TREE_PUBLIC (new_fndecl) = 1;
25216   DECL_EXTERNAL (new_fndecl) = 1;
25217   DECL_IS_NOVOPS (new_fndecl) = 1;
25218   TREE_READONLY (new_fndecl) = 1;
25219
25220   return new_fndecl;
25221 }
25222
25223 /* Handler for an ACML-style interface to
25224    a library with vectorized intrinsics.  */
25225
25226 static tree
25227 ix86_veclibabi_acml (enum built_in_function fn, tree type_out, tree type_in)
25228 {
25229   char name[20] = "__vr.._";
25230   tree fntype, new_fndecl, args;
25231   unsigned arity;
25232   const char *bname;
25233   enum machine_mode el_mode, in_mode;
25234   int n, in_n;
25235
25236   /* The ACML is 64bits only and suitable for unsafe math only as
25237      it does not correctly support parts of IEEE with the required
25238      precision such as denormals.  */
25239   if (!TARGET_64BIT
25240       || !flag_unsafe_math_optimizations)
25241     return NULL_TREE;
25242
25243   el_mode = TYPE_MODE (TREE_TYPE (type_out));
25244   n = TYPE_VECTOR_SUBPARTS (type_out);
25245   in_mode = TYPE_MODE (TREE_TYPE (type_in));
25246   in_n = TYPE_VECTOR_SUBPARTS (type_in);
25247   if (el_mode != in_mode
25248       || n != in_n)
25249     return NULL_TREE;
25250
25251   switch (fn)
25252     {
25253     case BUILT_IN_SIN:
25254     case BUILT_IN_COS:
25255     case BUILT_IN_EXP:
25256     case BUILT_IN_LOG:
25257     case BUILT_IN_LOG2:
25258     case BUILT_IN_LOG10:
25259       name[4] = 'd';
25260       name[5] = '2';
25261       if (el_mode != DFmode
25262           || n != 2)
25263         return NULL_TREE;
25264       break;
25265
25266     case BUILT_IN_SINF:
25267     case BUILT_IN_COSF:
25268     case BUILT_IN_EXPF:
25269     case BUILT_IN_POWF:
25270     case BUILT_IN_LOGF:
25271     case BUILT_IN_LOG2F:
25272     case BUILT_IN_LOG10F:
25273       name[4] = 's';
25274       name[5] = '4';
25275       if (el_mode != SFmode
25276           || n != 4)
25277         return NULL_TREE;
25278       break;
25279
25280     default:
25281       return NULL_TREE;
25282     }
25283
25284   bname = IDENTIFIER_POINTER (DECL_NAME (implicit_built_in_decls[fn]));
25285   sprintf (name + 7, "%s", bname+10);
25286
25287   arity = 0;
25288   for (args = DECL_ARGUMENTS (implicit_built_in_decls[fn]); args;
25289        args = TREE_CHAIN (args))
25290     arity++;
25291
25292   if (arity == 1)
25293     fntype = build_function_type_list (type_out, type_in, NULL);
25294   else
25295     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
25296
25297   /* Build a function declaration for the vectorized function.  */
25298   new_fndecl = build_decl (FUNCTION_DECL, get_identifier (name), fntype);
25299   TREE_PUBLIC (new_fndecl) = 1;
25300   DECL_EXTERNAL (new_fndecl) = 1;
25301   DECL_IS_NOVOPS (new_fndecl) = 1;
25302   TREE_READONLY (new_fndecl) = 1;
25303
25304   return new_fndecl;
25305 }
25306
25307
25308 /* Returns a decl of a function that implements conversion of an integer vector
25309    into a floating-point vector, or vice-versa. TYPE is the type of the integer
25310    side of the conversion.
25311    Return NULL_TREE if it is not available.  */
25312
25313 static tree
25314 ix86_vectorize_builtin_conversion (unsigned int code, tree type)
25315 {
25316   if (!TARGET_SSE2 || TREE_CODE (type) != VECTOR_TYPE
25317       /* There are only conversions from/to signed integers.  */
25318       || TYPE_UNSIGNED (TREE_TYPE (type)))
25319     return NULL_TREE;
25320
25321   switch (code)
25322     {
25323     case FLOAT_EXPR:
25324       switch (TYPE_MODE (type))
25325         {
25326         case V4SImode:
25327           return ix86_builtins[IX86_BUILTIN_CVTDQ2PS];
25328         default:
25329           return NULL_TREE;
25330         }
25331
25332     case FIX_TRUNC_EXPR:
25333       switch (TYPE_MODE (type))
25334         {
25335         case V4SImode:
25336           return ix86_builtins[IX86_BUILTIN_CVTTPS2DQ];
25337         default:
25338           return NULL_TREE;
25339         }
25340     default:
25341       return NULL_TREE;
25342
25343     }
25344 }
25345
25346 /* Returns a code for a target-specific builtin that implements
25347    reciprocal of the function, or NULL_TREE if not available.  */
25348
25349 static tree
25350 ix86_builtin_reciprocal (unsigned int fn, bool md_fn,
25351                          bool sqrt ATTRIBUTE_UNUSED)
25352 {
25353   if (! (TARGET_SSE_MATH && TARGET_RECIP && !optimize_insn_for_size_p ()
25354          && flag_finite_math_only && !flag_trapping_math
25355          && flag_unsafe_math_optimizations))
25356     return NULL_TREE;
25357
25358   if (md_fn)
25359     /* Machine dependent builtins.  */
25360     switch (fn)
25361       {
25362         /* Vectorized version of sqrt to rsqrt conversion.  */
25363       case IX86_BUILTIN_SQRTPS_NR:
25364         return ix86_builtins[IX86_BUILTIN_RSQRTPS_NR];
25365
25366       default:
25367         return NULL_TREE;
25368       }
25369   else
25370     /* Normal builtins.  */
25371     switch (fn)
25372       {
25373         /* Sqrt to rsqrt conversion.  */
25374       case BUILT_IN_SQRTF:
25375         return ix86_builtins[IX86_BUILTIN_RSQRTF];
25376
25377       default:
25378         return NULL_TREE;
25379       }
25380 }
25381
25382 /* Store OPERAND to the memory after reload is completed.  This means
25383    that we can't easily use assign_stack_local.  */
25384 rtx
25385 ix86_force_to_memory (enum machine_mode mode, rtx operand)
25386 {
25387   rtx result;
25388
25389   gcc_assert (reload_completed);
25390   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE)
25391     {
25392       result = gen_rtx_MEM (mode,
25393                             gen_rtx_PLUS (Pmode,
25394                                           stack_pointer_rtx,
25395                                           GEN_INT (-RED_ZONE_SIZE)));
25396       emit_move_insn (result, operand);
25397     }
25398   else if ((TARGET_64BIT_MS_ABI || !TARGET_RED_ZONE) && TARGET_64BIT)
25399     {
25400       switch (mode)
25401         {
25402         case HImode:
25403         case SImode:
25404           operand = gen_lowpart (DImode, operand);
25405           /* FALLTHRU */
25406         case DImode:
25407           emit_insn (
25408                       gen_rtx_SET (VOIDmode,
25409                                    gen_rtx_MEM (DImode,
25410                                                 gen_rtx_PRE_DEC (DImode,
25411                                                         stack_pointer_rtx)),
25412                                    operand));
25413           break;
25414         default:
25415           gcc_unreachable ();
25416         }
25417       result = gen_rtx_MEM (mode, stack_pointer_rtx);
25418     }
25419   else
25420     {
25421       switch (mode)
25422         {
25423         case DImode:
25424           {
25425             rtx operands[2];
25426             split_di (&operand, 1, operands, operands + 1);
25427             emit_insn (
25428                         gen_rtx_SET (VOIDmode,
25429                                      gen_rtx_MEM (SImode,
25430                                                   gen_rtx_PRE_DEC (Pmode,
25431                                                         stack_pointer_rtx)),
25432                                      operands[1]));
25433             emit_insn (
25434                         gen_rtx_SET (VOIDmode,
25435                                      gen_rtx_MEM (SImode,
25436                                                   gen_rtx_PRE_DEC (Pmode,
25437                                                         stack_pointer_rtx)),
25438                                      operands[0]));
25439           }
25440           break;
25441         case HImode:
25442           /* Store HImodes as SImodes.  */
25443           operand = gen_lowpart (SImode, operand);
25444           /* FALLTHRU */
25445         case SImode:
25446           emit_insn (
25447                       gen_rtx_SET (VOIDmode,
25448                                    gen_rtx_MEM (GET_MODE (operand),
25449                                                 gen_rtx_PRE_DEC (SImode,
25450                                                         stack_pointer_rtx)),
25451                                    operand));
25452           break;
25453         default:
25454           gcc_unreachable ();
25455         }
25456       result = gen_rtx_MEM (mode, stack_pointer_rtx);
25457     }
25458   return result;
25459 }
25460
25461 /* Free operand from the memory.  */
25462 void
25463 ix86_free_from_memory (enum machine_mode mode)
25464 {
25465   if (!TARGET_RED_ZONE || TARGET_64BIT_MS_ABI)
25466     {
25467       int size;
25468
25469       if (mode == DImode || TARGET_64BIT)
25470         size = 8;
25471       else
25472         size = 4;
25473       /* Use LEA to deallocate stack space.  In peephole2 it will be converted
25474          to pop or add instruction if registers are available.  */
25475       emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
25476                               gen_rtx_PLUS (Pmode, stack_pointer_rtx,
25477                                             GEN_INT (size))));
25478     }
25479 }
25480
25481 /* Put float CONST_DOUBLE in the constant pool instead of fp regs.
25482    QImode must go into class Q_REGS.
25483    Narrow ALL_REGS to GENERAL_REGS.  This supports allowing movsf and
25484    movdf to do mem-to-mem moves through integer regs.  */
25485 enum reg_class
25486 ix86_preferred_reload_class (rtx x, enum reg_class regclass)
25487 {
25488   enum machine_mode mode = GET_MODE (x);
25489
25490   /* We're only allowed to return a subclass of CLASS.  Many of the
25491      following checks fail for NO_REGS, so eliminate that early.  */
25492   if (regclass == NO_REGS)
25493     return NO_REGS;
25494
25495   /* All classes can load zeros.  */
25496   if (x == CONST0_RTX (mode))
25497     return regclass;
25498
25499   /* Force constants into memory if we are loading a (nonzero) constant into
25500      an MMX or SSE register.  This is because there are no MMX/SSE instructions
25501      to load from a constant.  */
25502   if (CONSTANT_P (x)
25503       && (MAYBE_MMX_CLASS_P (regclass) || MAYBE_SSE_CLASS_P (regclass)))
25504     return NO_REGS;
25505
25506   /* Prefer SSE regs only, if we can use them for math.  */
25507   if (TARGET_SSE_MATH && !TARGET_MIX_SSE_I387 && SSE_FLOAT_MODE_P (mode))
25508     return SSE_CLASS_P (regclass) ? regclass : NO_REGS;
25509
25510   /* Floating-point constants need more complex checks.  */
25511   if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) != VOIDmode)
25512     {
25513       /* General regs can load everything.  */
25514       if (reg_class_subset_p (regclass, GENERAL_REGS))
25515         return regclass;
25516
25517       /* Floats can load 0 and 1 plus some others.  Note that we eliminated
25518          zero above.  We only want to wind up preferring 80387 registers if
25519          we plan on doing computation with them.  */
25520       if (TARGET_80387
25521           && standard_80387_constant_p (x))
25522         {
25523           /* Limit class to non-sse.  */
25524           if (regclass == FLOAT_SSE_REGS)
25525             return FLOAT_REGS;
25526           if (regclass == FP_TOP_SSE_REGS)
25527             return FP_TOP_REG;
25528           if (regclass == FP_SECOND_SSE_REGS)
25529             return FP_SECOND_REG;
25530           if (regclass == FLOAT_INT_REGS || regclass == FLOAT_REGS)
25531             return regclass;
25532         }
25533
25534       return NO_REGS;
25535     }
25536
25537   /* Generally when we see PLUS here, it's the function invariant
25538      (plus soft-fp const_int).  Which can only be computed into general
25539      regs.  */
25540   if (GET_CODE (x) == PLUS)
25541     return reg_class_subset_p (regclass, GENERAL_REGS) ? regclass : NO_REGS;
25542
25543   /* QImode constants are easy to load, but non-constant QImode data
25544      must go into Q_REGS.  */
25545   if (GET_MODE (x) == QImode && !CONSTANT_P (x))
25546     {
25547       if (reg_class_subset_p (regclass, Q_REGS))
25548         return regclass;
25549       if (reg_class_subset_p (Q_REGS, regclass))
25550         return Q_REGS;
25551       return NO_REGS;
25552     }
25553
25554   return regclass;
25555 }
25556
25557 /* Discourage putting floating-point values in SSE registers unless
25558    SSE math is being used, and likewise for the 387 registers.  */
25559 enum reg_class
25560 ix86_preferred_output_reload_class (rtx x, enum reg_class regclass)
25561 {
25562   enum machine_mode mode = GET_MODE (x);
25563
25564   /* Restrict the output reload class to the register bank that we are doing
25565      math on.  If we would like not to return a subset of CLASS, reject this
25566      alternative: if reload cannot do this, it will still use its choice.  */
25567   mode = GET_MODE (x);
25568   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
25569     return MAYBE_SSE_CLASS_P (regclass) ? SSE_REGS : NO_REGS;
25570
25571   if (X87_FLOAT_MODE_P (mode))
25572     {
25573       if (regclass == FP_TOP_SSE_REGS)
25574         return FP_TOP_REG;
25575       else if (regclass == FP_SECOND_SSE_REGS)
25576         return FP_SECOND_REG;
25577       else
25578         return FLOAT_CLASS_P (regclass) ? regclass : NO_REGS;
25579     }
25580
25581   return regclass;
25582 }
25583
25584 static enum reg_class
25585 ix86_secondary_reload (bool in_p, rtx x, enum reg_class rclass,
25586                        enum machine_mode mode,
25587                        secondary_reload_info *sri ATTRIBUTE_UNUSED)
25588 {
25589   /* QImode spills from non-QI registers require
25590      intermediate register on 32bit targets.  */
25591   if (!in_p && mode == QImode && !TARGET_64BIT
25592       && (rclass == GENERAL_REGS
25593           || rclass == LEGACY_REGS
25594           || rclass == INDEX_REGS))
25595     {
25596       int regno;
25597
25598       if (REG_P (x))
25599         regno = REGNO (x);
25600       else
25601         regno = -1;
25602
25603       if (regno >= FIRST_PSEUDO_REGISTER || GET_CODE (x) == SUBREG)
25604         regno = true_regnum (x);
25605
25606       /* Return Q_REGS if the operand is in memory.  */
25607       if (regno == -1)
25608         return Q_REGS;
25609     }
25610
25611   return NO_REGS;
25612 }
25613
25614 /* If we are copying between general and FP registers, we need a memory
25615    location. The same is true for SSE and MMX registers.
25616
25617    To optimize register_move_cost performance, allow inline variant.
25618
25619    The macro can't work reliably when one of the CLASSES is class containing
25620    registers from multiple units (SSE, MMX, integer).  We avoid this by never
25621    combining those units in single alternative in the machine description.
25622    Ensure that this constraint holds to avoid unexpected surprises.
25623
25624    When STRICT is false, we are being called from REGISTER_MOVE_COST, so do not
25625    enforce these sanity checks.  */
25626
25627 static inline int
25628 inline_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
25629                               enum machine_mode mode, int strict)
25630 {
25631   if (MAYBE_FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class1)
25632       || MAYBE_FLOAT_CLASS_P (class2) != FLOAT_CLASS_P (class2)
25633       || MAYBE_SSE_CLASS_P (class1) != SSE_CLASS_P (class1)
25634       || MAYBE_SSE_CLASS_P (class2) != SSE_CLASS_P (class2)
25635       || MAYBE_MMX_CLASS_P (class1) != MMX_CLASS_P (class1)
25636       || MAYBE_MMX_CLASS_P (class2) != MMX_CLASS_P (class2))
25637     {
25638       gcc_assert (!strict);
25639       return true;
25640     }
25641
25642   if (FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class2))
25643     return true;
25644
25645   /* ??? This is a lie.  We do have moves between mmx/general, and for
25646      mmx/sse2.  But by saying we need secondary memory we discourage the
25647      register allocator from using the mmx registers unless needed.  */
25648   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2))
25649     return true;
25650
25651   if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
25652     {
25653       /* SSE1 doesn't have any direct moves from other classes.  */
25654       if (!TARGET_SSE2)
25655         return true;
25656
25657       /* If the target says that inter-unit moves are more expensive
25658          than moving through memory, then don't generate them.  */
25659       if (!TARGET_INTER_UNIT_MOVES)
25660         return true;
25661
25662       /* Between SSE and general, we have moves no larger than word size.  */
25663       if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
25664         return true;
25665     }
25666
25667   return false;
25668 }
25669
25670 int
25671 ix86_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
25672                               enum machine_mode mode, int strict)
25673 {
25674   return inline_secondary_memory_needed (class1, class2, mode, strict);
25675 }
25676
25677 /* Return true if the registers in CLASS cannot represent the change from
25678    modes FROM to TO.  */
25679
25680 bool
25681 ix86_cannot_change_mode_class (enum machine_mode from, enum machine_mode to,
25682                                enum reg_class regclass)
25683 {
25684   if (from == to)
25685     return false;
25686
25687   /* x87 registers can't do subreg at all, as all values are reformatted
25688      to extended precision.  */
25689   if (MAYBE_FLOAT_CLASS_P (regclass))
25690     return true;
25691
25692   if (MAYBE_SSE_CLASS_P (regclass) || MAYBE_MMX_CLASS_P (regclass))
25693     {
25694       /* Vector registers do not support QI or HImode loads.  If we don't
25695          disallow a change to these modes, reload will assume it's ok to
25696          drop the subreg from (subreg:SI (reg:HI 100) 0).  This affects
25697          the vec_dupv4hi pattern.  */
25698       if (GET_MODE_SIZE (from) < 4)
25699         return true;
25700
25701       /* Vector registers do not support subreg with nonzero offsets, which
25702          are otherwise valid for integer registers.  Since we can't see
25703          whether we have a nonzero offset from here, prohibit all
25704          nonparadoxical subregs changing size.  */
25705       if (GET_MODE_SIZE (to) < GET_MODE_SIZE (from))
25706         return true;
25707     }
25708
25709   return false;
25710 }
25711
25712 /* Return the cost of moving data of mode M between a
25713    register and memory.  A value of 2 is the default; this cost is
25714    relative to those in `REGISTER_MOVE_COST'.
25715
25716    This function is used extensively by register_move_cost that is used to
25717    build tables at startup.  Make it inline in this case.
25718    When IN is 2, return maximum of in and out move cost.
25719
25720    If moving between registers and memory is more expensive than
25721    between two registers, you should define this macro to express the
25722    relative cost.
25723
25724    Model also increased moving costs of QImode registers in non
25725    Q_REGS classes.
25726  */
25727 static inline int
25728 inline_memory_move_cost (enum machine_mode mode, enum reg_class regclass,
25729                          int in)
25730 {
25731   int cost;
25732   if (FLOAT_CLASS_P (regclass))
25733     {
25734       int index;
25735       switch (mode)
25736         {
25737           case SFmode:
25738             index = 0;
25739             break;
25740           case DFmode:
25741             index = 1;
25742             break;
25743           case XFmode:
25744             index = 2;
25745             break;
25746           default:
25747             return 100;
25748         }
25749       if (in == 2)
25750         return MAX (ix86_cost->fp_load [index], ix86_cost->fp_store [index]);
25751       return in ? ix86_cost->fp_load [index] : ix86_cost->fp_store [index];
25752     }
25753   if (SSE_CLASS_P (regclass))
25754     {
25755       int index;
25756       switch (GET_MODE_SIZE (mode))
25757         {
25758           case 4:
25759             index = 0;
25760             break;
25761           case 8:
25762             index = 1;
25763             break;
25764           case 16:
25765             index = 2;
25766             break;
25767           default:
25768             return 100;
25769         }
25770       if (in == 2)
25771         return MAX (ix86_cost->sse_load [index], ix86_cost->sse_store [index]);
25772       return in ? ix86_cost->sse_load [index] : ix86_cost->sse_store [index];
25773     }
25774   if (MMX_CLASS_P (regclass))
25775     {
25776       int index;
25777       switch (GET_MODE_SIZE (mode))
25778         {
25779           case 4:
25780             index = 0;
25781             break;
25782           case 8:
25783             index = 1;
25784             break;
25785           default:
25786             return 100;
25787         }
25788       if (in)
25789         return MAX (ix86_cost->mmx_load [index], ix86_cost->mmx_store [index]);
25790       return in ? ix86_cost->mmx_load [index] : ix86_cost->mmx_store [index];
25791     }
25792   switch (GET_MODE_SIZE (mode))
25793     {
25794       case 1:
25795         if (Q_CLASS_P (regclass) || TARGET_64BIT)
25796           {
25797             if (!in)
25798               return ix86_cost->int_store[0];
25799             if (TARGET_PARTIAL_REG_DEPENDENCY
25800                 && optimize_function_for_speed_p (cfun))
25801               cost = ix86_cost->movzbl_load;
25802             else
25803               cost = ix86_cost->int_load[0];
25804             if (in == 2)
25805               return MAX (cost, ix86_cost->int_store[0]);
25806             return cost;
25807           }
25808         else
25809           {
25810            if (in == 2)
25811              return MAX (ix86_cost->movzbl_load, ix86_cost->int_store[0] + 4);
25812            if (in)
25813              return ix86_cost->movzbl_load;
25814            else
25815              return ix86_cost->int_store[0] + 4;
25816           }
25817         break;
25818       case 2:
25819         if (in == 2)
25820           return MAX (ix86_cost->int_load[1], ix86_cost->int_store[1]);
25821         return in ? ix86_cost->int_load[1] : ix86_cost->int_store[1];
25822       default:
25823         /* Compute number of 32bit moves needed.  TFmode is moved as XFmode.  */
25824         if (mode == TFmode)
25825           mode = XFmode;
25826         if (in == 2)
25827           cost = MAX (ix86_cost->int_load[2] , ix86_cost->int_store[2]);
25828         else if (in)
25829           cost = ix86_cost->int_load[2];
25830         else
25831           cost = ix86_cost->int_store[2];
25832         return (cost * (((int) GET_MODE_SIZE (mode)
25833                         + UNITS_PER_WORD - 1) / UNITS_PER_WORD));
25834     }
25835 }
25836
25837 int
25838 ix86_memory_move_cost (enum machine_mode mode, enum reg_class regclass, int in)
25839 {
25840   return inline_memory_move_cost (mode, regclass, in);
25841 }
25842
25843
25844 /* Return the cost of moving data from a register in class CLASS1 to
25845    one in class CLASS2.
25846
25847    It is not required that the cost always equal 2 when FROM is the same as TO;
25848    on some machines it is expensive to move between registers if they are not
25849    general registers.  */
25850
25851 int
25852 ix86_register_move_cost (enum machine_mode mode, enum reg_class class1,
25853                          enum reg_class class2)
25854 {
25855   /* In case we require secondary memory, compute cost of the store followed
25856      by load.  In order to avoid bad register allocation choices, we need
25857      for this to be *at least* as high as the symmetric MEMORY_MOVE_COST.  */
25858
25859   if (inline_secondary_memory_needed (class1, class2, mode, 0))
25860     {
25861       int cost = 1;
25862
25863       cost += inline_memory_move_cost (mode, class1, 2);
25864       cost += inline_memory_move_cost (mode, class2, 2);
25865
25866       /* In case of copying from general_purpose_register we may emit multiple
25867          stores followed by single load causing memory size mismatch stall.
25868          Count this as arbitrarily high cost of 20.  */
25869       if (CLASS_MAX_NREGS (class1, mode) > CLASS_MAX_NREGS (class2, mode))
25870         cost += 20;
25871
25872       /* In the case of FP/MMX moves, the registers actually overlap, and we
25873          have to switch modes in order to treat them differently.  */
25874       if ((MMX_CLASS_P (class1) && MAYBE_FLOAT_CLASS_P (class2))
25875           || (MMX_CLASS_P (class2) && MAYBE_FLOAT_CLASS_P (class1)))
25876         cost += 20;
25877
25878       return cost;
25879     }
25880
25881   /* Moves between SSE/MMX and integer unit are expensive.  */
25882   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2)
25883       || SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
25884
25885     /* ??? By keeping returned value relatively high, we limit the number
25886        of moves between integer and MMX/SSE registers for all targets.
25887        Additionally, high value prevents problem with x86_modes_tieable_p(),
25888        where integer modes in MMX/SSE registers are not tieable
25889        because of missing QImode and HImode moves to, from or between
25890        MMX/SSE registers.  */
25891     return MAX (8, ix86_cost->mmxsse_to_integer);
25892
25893   if (MAYBE_FLOAT_CLASS_P (class1))
25894     return ix86_cost->fp_move;
25895   if (MAYBE_SSE_CLASS_P (class1))
25896     return ix86_cost->sse_move;
25897   if (MAYBE_MMX_CLASS_P (class1))
25898     return ix86_cost->mmx_move;
25899   return 2;
25900 }
25901
25902 /* Return 1 if hard register REGNO can hold a value of machine-mode MODE.  */
25903
25904 bool
25905 ix86_hard_regno_mode_ok (int regno, enum machine_mode mode)
25906 {
25907   /* Flags and only flags can only hold CCmode values.  */
25908   if (CC_REGNO_P (regno))
25909     return GET_MODE_CLASS (mode) == MODE_CC;
25910   if (GET_MODE_CLASS (mode) == MODE_CC
25911       || GET_MODE_CLASS (mode) == MODE_RANDOM
25912       || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
25913     return 0;
25914   if (FP_REGNO_P (regno))
25915     return VALID_FP_MODE_P (mode);
25916   if (SSE_REGNO_P (regno))
25917     {
25918       /* We implement the move patterns for all vector modes into and
25919          out of SSE registers, even when no operation instructions
25920          are available.  OImode move is available only when AVX is
25921          enabled.  */
25922       return ((TARGET_AVX && mode == OImode)
25923               || VALID_AVX256_REG_MODE (mode)
25924               || VALID_SSE_REG_MODE (mode)
25925               || VALID_SSE2_REG_MODE (mode)
25926               || VALID_MMX_REG_MODE (mode)
25927               || VALID_MMX_REG_MODE_3DNOW (mode));
25928     }
25929   if (MMX_REGNO_P (regno))
25930     {
25931       /* We implement the move patterns for 3DNOW modes even in MMX mode,
25932          so if the register is available at all, then we can move data of
25933          the given mode into or out of it.  */
25934       return (VALID_MMX_REG_MODE (mode)
25935               || VALID_MMX_REG_MODE_3DNOW (mode));
25936     }
25937
25938   if (mode == QImode)
25939     {
25940       /* Take care for QImode values - they can be in non-QI regs,
25941          but then they do cause partial register stalls.  */
25942       if (regno <= BX_REG || TARGET_64BIT)
25943         return 1;
25944       if (!TARGET_PARTIAL_REG_STALL)
25945         return 1;
25946       return reload_in_progress || reload_completed;
25947     }
25948   /* We handle both integer and floats in the general purpose registers.  */
25949   else if (VALID_INT_MODE_P (mode))
25950     return 1;
25951   else if (VALID_FP_MODE_P (mode))
25952     return 1;
25953   else if (VALID_DFP_MODE_P (mode))
25954     return 1;
25955   /* Lots of MMX code casts 8 byte vector modes to DImode.  If we then go
25956      on to use that value in smaller contexts, this can easily force a
25957      pseudo to be allocated to GENERAL_REGS.  Since this is no worse than
25958      supporting DImode, allow it.  */
25959   else if (VALID_MMX_REG_MODE_3DNOW (mode) || VALID_MMX_REG_MODE (mode))
25960     return 1;
25961
25962   return 0;
25963 }
25964
25965 /* A subroutine of ix86_modes_tieable_p.  Return true if MODE is a
25966    tieable integer mode.  */
25967
25968 static bool
25969 ix86_tieable_integer_mode_p (enum machine_mode mode)
25970 {
25971   switch (mode)
25972     {
25973     case HImode:
25974     case SImode:
25975       return true;
25976
25977     case QImode:
25978       return TARGET_64BIT || !TARGET_PARTIAL_REG_STALL;
25979
25980     case DImode:
25981       return TARGET_64BIT;
25982
25983     default:
25984       return false;
25985     }
25986 }
25987
25988 /* Return true if MODE1 is accessible in a register that can hold MODE2
25989    without copying.  That is, all register classes that can hold MODE2
25990    can also hold MODE1.  */
25991
25992 bool
25993 ix86_modes_tieable_p (enum machine_mode mode1, enum machine_mode mode2)
25994 {
25995   if (mode1 == mode2)
25996     return true;
25997
25998   if (ix86_tieable_integer_mode_p (mode1)
25999       && ix86_tieable_integer_mode_p (mode2))
26000     return true;
26001
26002   /* MODE2 being XFmode implies fp stack or general regs, which means we
26003      can tie any smaller floating point modes to it.  Note that we do not
26004      tie this with TFmode.  */
26005   if (mode2 == XFmode)
26006     return mode1 == SFmode || mode1 == DFmode;
26007
26008   /* MODE2 being DFmode implies fp stack, general or sse regs, which means
26009      that we can tie it with SFmode.  */
26010   if (mode2 == DFmode)
26011     return mode1 == SFmode;
26012
26013   /* If MODE2 is only appropriate for an SSE register, then tie with
26014      any other mode acceptable to SSE registers.  */
26015   if (GET_MODE_SIZE (mode2) == 16
26016       && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
26017     return (GET_MODE_SIZE (mode1) == 16
26018             && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1));
26019
26020   /* If MODE2 is appropriate for an MMX register, then tie
26021      with any other mode acceptable to MMX registers.  */
26022   if (GET_MODE_SIZE (mode2) == 8
26023       && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode2))
26024     return (GET_MODE_SIZE (mode1) == 8
26025             && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode1));
26026
26027   return false;
26028 }
26029
26030 /* Compute a (partial) cost for rtx X.  Return true if the complete
26031    cost has been computed, and false if subexpressions should be
26032    scanned.  In either case, *TOTAL contains the cost result.  */
26033
26034 static bool
26035 ix86_rtx_costs (rtx x, int code, int outer_code_i, int *total, bool speed)
26036 {
26037   enum rtx_code outer_code = (enum rtx_code) outer_code_i;
26038   enum machine_mode mode = GET_MODE (x);
26039   const struct processor_costs *cost = speed ? ix86_cost : &ix86_size_cost;
26040
26041   switch (code)
26042     {
26043     case CONST_INT:
26044     case CONST:
26045     case LABEL_REF:
26046     case SYMBOL_REF:
26047       if (TARGET_64BIT && !x86_64_immediate_operand (x, VOIDmode))
26048         *total = 3;
26049       else if (TARGET_64BIT && !x86_64_zext_immediate_operand (x, VOIDmode))
26050         *total = 2;
26051       else if (flag_pic && SYMBOLIC_CONST (x)
26052                && (!TARGET_64BIT
26053                    || (!GET_CODE (x) != LABEL_REF
26054                        && (GET_CODE (x) != SYMBOL_REF
26055                            || !SYMBOL_REF_LOCAL_P (x)))))
26056         *total = 1;
26057       else
26058         *total = 0;
26059       return true;
26060
26061     case CONST_DOUBLE:
26062       if (mode == VOIDmode)
26063         *total = 0;
26064       else
26065         switch (standard_80387_constant_p (x))
26066           {
26067           case 1: /* 0.0 */
26068             *total = 1;
26069             break;
26070           default: /* Other constants */
26071             *total = 2;
26072             break;
26073           case 0:
26074           case -1:
26075             /* Start with (MEM (SYMBOL_REF)), since that's where
26076                it'll probably end up.  Add a penalty for size.  */
26077             *total = (COSTS_N_INSNS (1)
26078                       + (flag_pic != 0 && !TARGET_64BIT)
26079                       + (mode == SFmode ? 0 : mode == DFmode ? 1 : 2));
26080             break;
26081           }
26082       return true;
26083
26084     case ZERO_EXTEND:
26085       /* The zero extensions is often completely free on x86_64, so make
26086          it as cheap as possible.  */
26087       if (TARGET_64BIT && mode == DImode
26088           && GET_MODE (XEXP (x, 0)) == SImode)
26089         *total = 1;
26090       else if (TARGET_ZERO_EXTEND_WITH_AND)
26091         *total = cost->add;
26092       else
26093         *total = cost->movzx;
26094       return false;
26095
26096     case SIGN_EXTEND:
26097       *total = cost->movsx;
26098       return false;
26099
26100     case ASHIFT:
26101       if (CONST_INT_P (XEXP (x, 1))
26102           && (GET_MODE (XEXP (x, 0)) != DImode || TARGET_64BIT))
26103         {
26104           HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
26105           if (value == 1)
26106             {
26107               *total = cost->add;
26108               return false;
26109             }
26110           if ((value == 2 || value == 3)
26111               && cost->lea <= cost->shift_const)
26112             {
26113               *total = cost->lea;
26114               return false;
26115             }
26116         }
26117       /* FALLTHRU */
26118
26119     case ROTATE:
26120     case ASHIFTRT:
26121     case LSHIFTRT:
26122     case ROTATERT:
26123       if (!TARGET_64BIT && GET_MODE (XEXP (x, 0)) == DImode)
26124         {
26125           if (CONST_INT_P (XEXP (x, 1)))
26126             {
26127               if (INTVAL (XEXP (x, 1)) > 32)
26128                 *total = cost->shift_const + COSTS_N_INSNS (2);
26129               else
26130                 *total = cost->shift_const * 2;
26131             }
26132           else
26133             {
26134               if (GET_CODE (XEXP (x, 1)) == AND)
26135                 *total = cost->shift_var * 2;
26136               else
26137                 *total = cost->shift_var * 6 + COSTS_N_INSNS (2);
26138             }
26139         }
26140       else
26141         {
26142           if (CONST_INT_P (XEXP (x, 1)))
26143             *total = cost->shift_const;
26144           else
26145             *total = cost->shift_var;
26146         }
26147       return false;
26148
26149     case MULT:
26150       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
26151         {
26152           /* ??? SSE scalar cost should be used here.  */
26153           *total = cost->fmul;
26154           return false;
26155         }
26156       else if (X87_FLOAT_MODE_P (mode))
26157         {
26158           *total = cost->fmul;
26159           return false;
26160         }
26161       else if (FLOAT_MODE_P (mode))
26162         {
26163           /* ??? SSE vector cost should be used here.  */
26164           *total = cost->fmul;
26165           return false;
26166         }
26167       else
26168         {
26169           rtx op0 = XEXP (x, 0);
26170           rtx op1 = XEXP (x, 1);
26171           int nbits;
26172           if (CONST_INT_P (XEXP (x, 1)))
26173             {
26174               unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
26175               for (nbits = 0; value != 0; value &= value - 1)
26176                 nbits++;
26177             }
26178           else
26179             /* This is arbitrary.  */
26180             nbits = 7;
26181
26182           /* Compute costs correctly for widening multiplication.  */
26183           if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
26184               && GET_MODE_SIZE (GET_MODE (XEXP (op0, 0))) * 2
26185                  == GET_MODE_SIZE (mode))
26186             {
26187               int is_mulwiden = 0;
26188               enum machine_mode inner_mode = GET_MODE (op0);
26189
26190               if (GET_CODE (op0) == GET_CODE (op1))
26191                 is_mulwiden = 1, op1 = XEXP (op1, 0);
26192               else if (CONST_INT_P (op1))
26193                 {
26194                   if (GET_CODE (op0) == SIGN_EXTEND)
26195                     is_mulwiden = trunc_int_for_mode (INTVAL (op1), inner_mode)
26196                                   == INTVAL (op1);
26197                   else
26198                     is_mulwiden = !(INTVAL (op1) & ~GET_MODE_MASK (inner_mode));
26199                 }
26200
26201               if (is_mulwiden)
26202                 op0 = XEXP (op0, 0), mode = GET_MODE (op0);
26203             }
26204
26205           *total = (cost->mult_init[MODE_INDEX (mode)]
26206                     + nbits * cost->mult_bit
26207                     + rtx_cost (op0, outer_code, speed) + rtx_cost (op1, outer_code, speed));
26208
26209           return true;
26210         }
26211
26212     case DIV:
26213     case UDIV:
26214     case MOD:
26215     case UMOD:
26216       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
26217         /* ??? SSE cost should be used here.  */
26218         *total = cost->fdiv;
26219       else if (X87_FLOAT_MODE_P (mode))
26220         *total = cost->fdiv;
26221       else if (FLOAT_MODE_P (mode))
26222         /* ??? SSE vector cost should be used here.  */
26223         *total = cost->fdiv;
26224       else
26225         *total = cost->divide[MODE_INDEX (mode)];
26226       return false;
26227
26228     case PLUS:
26229       if (GET_MODE_CLASS (mode) == MODE_INT
26230                && GET_MODE_BITSIZE (mode) <= GET_MODE_BITSIZE (Pmode))
26231         {
26232           if (GET_CODE (XEXP (x, 0)) == PLUS
26233               && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
26234               && CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 0), 1))
26235               && CONSTANT_P (XEXP (x, 1)))
26236             {
26237               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1));
26238               if (val == 2 || val == 4 || val == 8)
26239                 {
26240                   *total = cost->lea;
26241                   *total += rtx_cost (XEXP (XEXP (x, 0), 1), outer_code, speed);
26242                   *total += rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0),
26243                                       outer_code, speed);
26244                   *total += rtx_cost (XEXP (x, 1), outer_code, speed);
26245                   return true;
26246                 }
26247             }
26248           else if (GET_CODE (XEXP (x, 0)) == MULT
26249                    && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
26250             {
26251               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (x, 0), 1));
26252               if (val == 2 || val == 4 || val == 8)
26253                 {
26254                   *total = cost->lea;
26255                   *total += rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, speed);
26256                   *total += rtx_cost (XEXP (x, 1), outer_code, speed);
26257                   return true;
26258                 }
26259             }
26260           else if (GET_CODE (XEXP (x, 0)) == PLUS)
26261             {
26262               *total = cost->lea;
26263               *total += rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, speed);
26264               *total += rtx_cost (XEXP (XEXP (x, 0), 1), outer_code, speed);
26265               *total += rtx_cost (XEXP (x, 1), outer_code, speed);
26266               return true;
26267             }
26268         }
26269       /* FALLTHRU */
26270
26271     case MINUS:
26272       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
26273         {
26274           /* ??? SSE cost should be used here.  */
26275           *total = cost->fadd;
26276           return false;
26277         }
26278       else if (X87_FLOAT_MODE_P (mode))
26279         {
26280           *total = cost->fadd;
26281           return false;
26282         }
26283       else if (FLOAT_MODE_P (mode))
26284         {
26285           /* ??? SSE vector cost should be used here.  */
26286           *total = cost->fadd;
26287           return false;
26288         }
26289       /* FALLTHRU */
26290
26291     case AND:
26292     case IOR:
26293     case XOR:
26294       if (!TARGET_64BIT && mode == DImode)
26295         {
26296           *total = (cost->add * 2
26297                     + (rtx_cost (XEXP (x, 0), outer_code, speed)
26298                        << (GET_MODE (XEXP (x, 0)) != DImode))
26299                     + (rtx_cost (XEXP (x, 1), outer_code, speed)
26300                        << (GET_MODE (XEXP (x, 1)) != DImode)));
26301           return true;
26302         }
26303       /* FALLTHRU */
26304
26305     case NEG:
26306       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
26307         {
26308           /* ??? SSE cost should be used here.  */
26309           *total = cost->fchs;
26310           return false;
26311         }
26312       else if (X87_FLOAT_MODE_P (mode))
26313         {
26314           *total = cost->fchs;
26315           return false;
26316         }
26317       else if (FLOAT_MODE_P (mode))
26318         {
26319           /* ??? SSE vector cost should be used here.  */
26320           *total = cost->fchs;
26321           return false;
26322         }
26323       /* FALLTHRU */
26324
26325     case NOT:
26326       if (!TARGET_64BIT && mode == DImode)
26327         *total = cost->add * 2;
26328       else
26329         *total = cost->add;
26330       return false;
26331
26332     case COMPARE:
26333       if (GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT
26334           && XEXP (XEXP (x, 0), 1) == const1_rtx
26335           && CONST_INT_P (XEXP (XEXP (x, 0), 2))
26336           && XEXP (x, 1) == const0_rtx)
26337         {
26338           /* This kind of construct is implemented using test[bwl].
26339              Treat it as if we had an AND.  */
26340           *total = (cost->add
26341                     + rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, speed)
26342                     + rtx_cost (const1_rtx, outer_code, speed));
26343           return true;
26344         }
26345       return false;
26346
26347     case FLOAT_EXTEND:
26348       if (!(SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH))
26349         *total = 0;
26350       return false;
26351
26352     case ABS:
26353       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
26354         /* ??? SSE cost should be used here.  */
26355         *total = cost->fabs;
26356       else if (X87_FLOAT_MODE_P (mode))
26357         *total = cost->fabs;
26358       else if (FLOAT_MODE_P (mode))
26359         /* ??? SSE vector cost should be used here.  */
26360         *total = cost->fabs;
26361       return false;
26362
26363     case SQRT:
26364       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
26365         /* ??? SSE cost should be used here.  */
26366         *total = cost->fsqrt;
26367       else if (X87_FLOAT_MODE_P (mode))
26368         *total = cost->fsqrt;
26369       else if (FLOAT_MODE_P (mode))
26370         /* ??? SSE vector cost should be used here.  */
26371         *total = cost->fsqrt;
26372       return false;
26373
26374     case UNSPEC:
26375       if (XINT (x, 1) == UNSPEC_TP)
26376         *total = 0;
26377       return false;
26378
26379     default:
26380       return false;
26381     }
26382 }
26383
26384 #if TARGET_MACHO
26385
26386 static int current_machopic_label_num;
26387
26388 /* Given a symbol name and its associated stub, write out the
26389    definition of the stub.  */
26390
26391 void
26392 machopic_output_stub (FILE *file, const char *symb, const char *stub)
26393 {
26394   unsigned int length;
26395   char *binder_name, *symbol_name, lazy_ptr_name[32];
26396   int label = ++current_machopic_label_num;
26397
26398   /* For 64-bit we shouldn't get here.  */
26399   gcc_assert (!TARGET_64BIT);
26400
26401   /* Lose our funky encoding stuff so it doesn't contaminate the stub.  */
26402   symb = (*targetm.strip_name_encoding) (symb);
26403
26404   length = strlen (stub);
26405   binder_name = XALLOCAVEC (char, length + 32);
26406   GEN_BINDER_NAME_FOR_STUB (binder_name, stub, length);
26407
26408   length = strlen (symb);
26409   symbol_name = XALLOCAVEC (char, length + 32);
26410   GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
26411
26412   sprintf (lazy_ptr_name, "L%d$lz", label);
26413
26414   if (MACHOPIC_PURE)
26415     switch_to_section (darwin_sections[machopic_picsymbol_stub_section]);
26416   else
26417     switch_to_section (darwin_sections[machopic_symbol_stub_section]);
26418
26419   fprintf (file, "%s:\n", stub);
26420   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
26421
26422   if (MACHOPIC_PURE)
26423     {
26424       fprintf (file, "\tcall\tLPC$%d\nLPC$%d:\tpopl\t%%eax\n", label, label);
26425       fprintf (file, "\tmovl\t%s-LPC$%d(%%eax),%%edx\n", lazy_ptr_name, label);
26426       fprintf (file, "\tjmp\t*%%edx\n");
26427     }
26428   else
26429     fprintf (file, "\tjmp\t*%s\n", lazy_ptr_name);
26430
26431   fprintf (file, "%s:\n", binder_name);
26432
26433   if (MACHOPIC_PURE)
26434     {
26435       fprintf (file, "\tlea\t%s-LPC$%d(%%eax),%%eax\n", lazy_ptr_name, label);
26436       fprintf (file, "\tpushl\t%%eax\n");
26437     }
26438   else
26439     fprintf (file, "\tpushl\t$%s\n", lazy_ptr_name);
26440
26441   fprintf (file, "\tjmp\tdyld_stub_binding_helper\n");
26442
26443   switch_to_section (darwin_sections[machopic_lazy_symbol_ptr_section]);
26444   fprintf (file, "%s:\n", lazy_ptr_name);
26445   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
26446   fprintf (file, "\t.long %s\n", binder_name);
26447 }
26448
26449 void
26450 darwin_x86_file_end (void)
26451 {
26452   darwin_file_end ();
26453   ix86_file_end ();
26454 }
26455 #endif /* TARGET_MACHO */
26456
26457 /* Order the registers for register allocator.  */
26458
26459 void
26460 x86_order_regs_for_local_alloc (void)
26461 {
26462    int pos = 0;
26463    int i;
26464
26465    /* First allocate the local general purpose registers.  */
26466    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
26467      if (GENERAL_REGNO_P (i) && call_used_regs[i])
26468         reg_alloc_order [pos++] = i;
26469
26470    /* Global general purpose registers.  */
26471    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
26472      if (GENERAL_REGNO_P (i) && !call_used_regs[i])
26473         reg_alloc_order [pos++] = i;
26474
26475    /* x87 registers come first in case we are doing FP math
26476       using them.  */
26477    if (!TARGET_SSE_MATH)
26478      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
26479        reg_alloc_order [pos++] = i;
26480
26481    /* SSE registers.  */
26482    for (i = FIRST_SSE_REG; i <= LAST_SSE_REG; i++)
26483      reg_alloc_order [pos++] = i;
26484    for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
26485      reg_alloc_order [pos++] = i;
26486
26487    /* x87 registers.  */
26488    if (TARGET_SSE_MATH)
26489      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
26490        reg_alloc_order [pos++] = i;
26491
26492    for (i = FIRST_MMX_REG; i <= LAST_MMX_REG; i++)
26493      reg_alloc_order [pos++] = i;
26494
26495    /* Initialize the rest of array as we do not allocate some registers
26496       at all.  */
26497    while (pos < FIRST_PSEUDO_REGISTER)
26498      reg_alloc_order [pos++] = 0;
26499 }
26500
26501 /* Handle a "ms_abi" or "sysv" attribute; arguments as in
26502    struct attribute_spec.handler.  */
26503 static tree
26504 ix86_handle_abi_attribute (tree *node, tree name,
26505                               tree args ATTRIBUTE_UNUSED,
26506                               int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
26507 {
26508   if (TREE_CODE (*node) != FUNCTION_TYPE
26509       && TREE_CODE (*node) != METHOD_TYPE
26510       && TREE_CODE (*node) != FIELD_DECL
26511       && TREE_CODE (*node) != TYPE_DECL)
26512     {
26513       warning (OPT_Wattributes, "%qs attribute only applies to functions",
26514                IDENTIFIER_POINTER (name));
26515       *no_add_attrs = true;
26516       return NULL_TREE;
26517     }
26518   if (!TARGET_64BIT)
26519     {
26520       warning (OPT_Wattributes, "%qs attribute only available for 64-bit",
26521                IDENTIFIER_POINTER (name));
26522       *no_add_attrs = true;
26523       return NULL_TREE;
26524     }
26525
26526   /* Can combine regparm with all attributes but fastcall.  */
26527   if (is_attribute_p ("ms_abi", name))
26528     {
26529       if (lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (*node)))
26530         {
26531           error ("ms_abi and sysv_abi attributes are not compatible");
26532         }
26533
26534       return NULL_TREE;
26535     }
26536   else if (is_attribute_p ("sysv_abi", name))
26537     {
26538       if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (*node)))
26539         {
26540           error ("ms_abi and sysv_abi attributes are not compatible");
26541         }
26542
26543       return NULL_TREE;
26544     }
26545
26546   return NULL_TREE;
26547 }
26548
26549 /* Handle a "ms_struct" or "gcc_struct" attribute; arguments as in
26550    struct attribute_spec.handler.  */
26551 static tree
26552 ix86_handle_struct_attribute (tree *node, tree name,
26553                               tree args ATTRIBUTE_UNUSED,
26554                               int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
26555 {
26556   tree *type = NULL;
26557   if (DECL_P (*node))
26558     {
26559       if (TREE_CODE (*node) == TYPE_DECL)
26560         type = &TREE_TYPE (*node);
26561     }
26562   else
26563     type = node;
26564
26565   if (!(type && (TREE_CODE (*type) == RECORD_TYPE
26566                  || TREE_CODE (*type) == UNION_TYPE)))
26567     {
26568       warning (OPT_Wattributes, "%qs attribute ignored",
26569                IDENTIFIER_POINTER (name));
26570       *no_add_attrs = true;
26571     }
26572
26573   else if ((is_attribute_p ("ms_struct", name)
26574             && lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (*type)))
26575            || ((is_attribute_p ("gcc_struct", name)
26576                 && lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (*type)))))
26577     {
26578       warning (OPT_Wattributes, "%qs incompatible attribute ignored",
26579                IDENTIFIER_POINTER (name));
26580       *no_add_attrs = true;
26581     }
26582
26583   return NULL_TREE;
26584 }
26585
26586 static bool
26587 ix86_ms_bitfield_layout_p (const_tree record_type)
26588 {
26589   return (TARGET_MS_BITFIELD_LAYOUT &&
26590           !lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (record_type)))
26591     || lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (record_type));
26592 }
26593
26594 /* Returns an expression indicating where the this parameter is
26595    located on entry to the FUNCTION.  */
26596
26597 static rtx
26598 x86_this_parameter (tree function)
26599 {
26600   tree type = TREE_TYPE (function);
26601   bool aggr = aggregate_value_p (TREE_TYPE (type), type) != 0;
26602   int nregs;
26603
26604   if (TARGET_64BIT)
26605     {
26606       const int *parm_regs;
26607
26608       if (ix86_function_type_abi (type) == MS_ABI)
26609         parm_regs = x86_64_ms_abi_int_parameter_registers;
26610       else
26611         parm_regs = x86_64_int_parameter_registers;
26612       return gen_rtx_REG (DImode, parm_regs[aggr]);
26613     }
26614
26615   nregs = ix86_function_regparm (type, function);
26616
26617   if (nregs > 0 && !stdarg_p (type))
26618     {
26619       int regno;
26620
26621       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
26622         regno = aggr ? DX_REG : CX_REG;
26623       else
26624         {
26625           regno = AX_REG;
26626           if (aggr)
26627             {
26628               regno = DX_REG;
26629               if (nregs == 1)
26630                 return gen_rtx_MEM (SImode,
26631                                     plus_constant (stack_pointer_rtx, 4));
26632             }
26633         }
26634       return gen_rtx_REG (SImode, regno);
26635     }
26636
26637   return gen_rtx_MEM (SImode, plus_constant (stack_pointer_rtx, aggr ? 8 : 4));
26638 }
26639
26640 /* Determine whether x86_output_mi_thunk can succeed.  */
26641
26642 static bool
26643 x86_can_output_mi_thunk (const_tree thunk ATTRIBUTE_UNUSED,
26644                          HOST_WIDE_INT delta ATTRIBUTE_UNUSED,
26645                          HOST_WIDE_INT vcall_offset, const_tree function)
26646 {
26647   /* 64-bit can handle anything.  */
26648   if (TARGET_64BIT)
26649     return true;
26650
26651   /* For 32-bit, everything's fine if we have one free register.  */
26652   if (ix86_function_regparm (TREE_TYPE (function), function) < 3)
26653     return true;
26654
26655   /* Need a free register for vcall_offset.  */
26656   if (vcall_offset)
26657     return false;
26658
26659   /* Need a free register for GOT references.  */
26660   if (flag_pic && !(*targetm.binds_local_p) (function))
26661     return false;
26662
26663   /* Otherwise ok.  */
26664   return true;
26665 }
26666
26667 /* Output the assembler code for a thunk function.  THUNK_DECL is the
26668    declaration for the thunk function itself, FUNCTION is the decl for
26669    the target function.  DELTA is an immediate constant offset to be
26670    added to THIS.  If VCALL_OFFSET is nonzero, the word at
26671    *(*this + vcall_offset) should be added to THIS.  */
26672
26673 static void
26674 x86_output_mi_thunk (FILE *file ATTRIBUTE_UNUSED,
26675                      tree thunk ATTRIBUTE_UNUSED, HOST_WIDE_INT delta,
26676                      HOST_WIDE_INT vcall_offset, tree function)
26677 {
26678   rtx xops[3];
26679   rtx this_param = x86_this_parameter (function);
26680   rtx this_reg, tmp;
26681
26682   /* If VCALL_OFFSET, we'll need THIS in a register.  Might as well
26683      pull it in now and let DELTA benefit.  */
26684   if (REG_P (this_param))
26685     this_reg = this_param;
26686   else if (vcall_offset)
26687     {
26688       /* Put the this parameter into %eax.  */
26689       xops[0] = this_param;
26690       xops[1] = this_reg = gen_rtx_REG (Pmode, AX_REG);
26691       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
26692     }
26693   else
26694     this_reg = NULL_RTX;
26695
26696   /* Adjust the this parameter by a fixed constant.  */
26697   if (delta)
26698     {
26699       xops[0] = GEN_INT (delta);
26700       xops[1] = this_reg ? this_reg : this_param;
26701       if (TARGET_64BIT)
26702         {
26703           if (!x86_64_general_operand (xops[0], DImode))
26704             {
26705               tmp = gen_rtx_REG (DImode, R10_REG);
26706               xops[1] = tmp;
26707               output_asm_insn ("mov{q}\t{%1, %0|%0, %1}", xops);
26708               xops[0] = tmp;
26709               xops[1] = this_param;
26710             }
26711           output_asm_insn ("add{q}\t{%0, %1|%1, %0}", xops);
26712         }
26713       else
26714         output_asm_insn ("add{l}\t{%0, %1|%1, %0}", xops);
26715     }
26716
26717   /* Adjust the this parameter by a value stored in the vtable.  */
26718   if (vcall_offset)
26719     {
26720       if (TARGET_64BIT)
26721         tmp = gen_rtx_REG (DImode, R10_REG);
26722       else
26723         {
26724           int tmp_regno = CX_REG;
26725           if (lookup_attribute ("fastcall",
26726                                 TYPE_ATTRIBUTES (TREE_TYPE (function))))
26727             tmp_regno = AX_REG;
26728           tmp = gen_rtx_REG (SImode, tmp_regno);
26729         }
26730
26731       xops[0] = gen_rtx_MEM (Pmode, this_reg);
26732       xops[1] = tmp;
26733       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
26734
26735       /* Adjust the this parameter.  */
26736       xops[0] = gen_rtx_MEM (Pmode, plus_constant (tmp, vcall_offset));
26737       if (TARGET_64BIT && !memory_operand (xops[0], Pmode))
26738         {
26739           rtx tmp2 = gen_rtx_REG (DImode, R11_REG);
26740           xops[0] = GEN_INT (vcall_offset);
26741           xops[1] = tmp2;
26742           output_asm_insn ("mov{q}\t{%0, %1|%1, %0}", xops);
26743           xops[0] = gen_rtx_MEM (Pmode, gen_rtx_PLUS (Pmode, tmp, tmp2));
26744         }
26745       xops[1] = this_reg;
26746       output_asm_insn ("add%z1\t{%0, %1|%1, %0}", xops);
26747     }
26748
26749   /* If necessary, drop THIS back to its stack slot.  */
26750   if (this_reg && this_reg != this_param)
26751     {
26752       xops[0] = this_reg;
26753       xops[1] = this_param;
26754       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
26755     }
26756
26757   xops[0] = XEXP (DECL_RTL (function), 0);
26758   if (TARGET_64BIT)
26759     {
26760       if (!flag_pic || (*targetm.binds_local_p) (function))
26761         output_asm_insn ("jmp\t%P0", xops);
26762       /* All thunks should be in the same object as their target,
26763          and thus binds_local_p should be true.  */
26764       else if (TARGET_64BIT && cfun->machine->call_abi == MS_ABI)
26765         gcc_unreachable ();
26766       else
26767         {
26768           tmp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, xops[0]), UNSPEC_GOTPCREL);
26769           tmp = gen_rtx_CONST (Pmode, tmp);
26770           tmp = gen_rtx_MEM (QImode, tmp);
26771           xops[0] = tmp;
26772           output_asm_insn ("jmp\t%A0", xops);
26773         }
26774     }
26775   else
26776     {
26777       if (!flag_pic || (*targetm.binds_local_p) (function))
26778         output_asm_insn ("jmp\t%P0", xops);
26779       else
26780 #if TARGET_MACHO
26781         if (TARGET_MACHO)
26782           {
26783             rtx sym_ref = XEXP (DECL_RTL (function), 0);
26784             tmp = (gen_rtx_SYMBOL_REF
26785                    (Pmode,
26786                     machopic_indirection_name (sym_ref, /*stub_p=*/true)));
26787             tmp = gen_rtx_MEM (QImode, tmp);
26788             xops[0] = tmp;
26789             output_asm_insn ("jmp\t%0", xops);
26790           }
26791         else
26792 #endif /* TARGET_MACHO */
26793         {
26794           tmp = gen_rtx_REG (SImode, CX_REG);
26795           output_set_got (tmp, NULL_RTX);
26796
26797           xops[1] = tmp;
26798           output_asm_insn ("mov{l}\t{%0@GOT(%1), %1|%1, %0@GOT[%1]}", xops);
26799           output_asm_insn ("jmp\t{*}%1", xops);
26800         }
26801     }
26802 }
26803
26804 static void
26805 x86_file_start (void)
26806 {
26807   default_file_start ();
26808 #if TARGET_MACHO
26809   darwin_file_start ();
26810 #endif
26811   if (X86_FILE_START_VERSION_DIRECTIVE)
26812     fputs ("\t.version\t\"01.01\"\n", asm_out_file);
26813   if (X86_FILE_START_FLTUSED)
26814     fputs ("\t.global\t__fltused\n", asm_out_file);
26815   if (ix86_asm_dialect == ASM_INTEL)
26816     fputs ("\t.intel_syntax noprefix\n", asm_out_file);
26817 }
26818
26819 int
26820 x86_field_alignment (tree field, int computed)
26821 {
26822   enum machine_mode mode;
26823   tree type = TREE_TYPE (field);
26824
26825   if (TARGET_64BIT || TARGET_ALIGN_DOUBLE)
26826     return computed;
26827   mode = TYPE_MODE (strip_array_types (type));
26828   if (mode == DFmode || mode == DCmode
26829       || GET_MODE_CLASS (mode) == MODE_INT
26830       || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
26831     return MIN (32, computed);
26832   return computed;
26833 }
26834
26835 /* Output assembler code to FILE to increment profiler label # LABELNO
26836    for profiling a function entry.  */
26837 void
26838 x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
26839 {
26840   if (TARGET_64BIT)
26841     {
26842 #ifndef NO_PROFILE_COUNTERS
26843       fprintf (file, "\tleaq\t%sP%d(%%rip),%%r11\n", LPREFIX, labelno);
26844 #endif
26845
26846       if (DEFAULT_ABI == SYSV_ABI && flag_pic)
26847         fprintf (file, "\tcall\t*%s@GOTPCREL(%%rip)\n", MCOUNT_NAME);
26848       else
26849         fprintf (file, "\tcall\t%s\n", MCOUNT_NAME);
26850     }
26851   else if (flag_pic)
26852     {
26853 #ifndef NO_PROFILE_COUNTERS
26854       fprintf (file, "\tleal\t%sP%d@GOTOFF(%%ebx),%%%s\n",
26855                LPREFIX, labelno, PROFILE_COUNT_REGISTER);
26856 #endif
26857       fprintf (file, "\tcall\t*%s@GOT(%%ebx)\n", MCOUNT_NAME);
26858     }
26859   else
26860     {
26861 #ifndef NO_PROFILE_COUNTERS
26862       fprintf (file, "\tmovl\t$%sP%d,%%%s\n", LPREFIX, labelno,
26863                PROFILE_COUNT_REGISTER);
26864 #endif
26865       fprintf (file, "\tcall\t%s\n", MCOUNT_NAME);
26866     }
26867 }
26868
26869 /* We don't have exact information about the insn sizes, but we may assume
26870    quite safely that we are informed about all 1 byte insns and memory
26871    address sizes.  This is enough to eliminate unnecessary padding in
26872    99% of cases.  */
26873
26874 static int
26875 min_insn_size (rtx insn)
26876 {
26877   int l = 0;
26878
26879   if (!INSN_P (insn) || !active_insn_p (insn))
26880     return 0;
26881
26882   /* Discard alignments we've emit and jump instructions.  */
26883   if (GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE
26884       && XINT (PATTERN (insn), 1) == UNSPECV_ALIGN)
26885     return 0;
26886   if (JUMP_P (insn)
26887       && (GET_CODE (PATTERN (insn)) == ADDR_VEC
26888           || GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC))
26889     return 0;
26890
26891   /* Important case - calls are always 5 bytes.
26892      It is common to have many calls in the row.  */
26893   if (CALL_P (insn)
26894       && symbolic_reference_mentioned_p (PATTERN (insn))
26895       && !SIBLING_CALL_P (insn))
26896     return 5;
26897   if (get_attr_length (insn) <= 1)
26898     return 1;
26899
26900   /* For normal instructions we may rely on the sizes of addresses
26901      and the presence of symbol to require 4 bytes of encoding.
26902      This is not the case for jumps where references are PC relative.  */
26903   if (!JUMP_P (insn))
26904     {
26905       l = get_attr_length_address (insn);
26906       if (l < 4 && symbolic_reference_mentioned_p (PATTERN (insn)))
26907         l = 4;
26908     }
26909   if (l)
26910     return 1+l;
26911   else
26912     return 2;
26913 }
26914
26915 /* AMD K8 core mispredicts jumps when there are more than 3 jumps in 16 byte
26916    window.  */
26917
26918 static void
26919 ix86_avoid_jump_misspredicts (void)
26920 {
26921   rtx insn, start = get_insns ();
26922   int nbytes = 0, njumps = 0;
26923   int isjump = 0;
26924
26925   /* Look for all minimal intervals of instructions containing 4 jumps.
26926      The intervals are bounded by START and INSN.  NBYTES is the total
26927      size of instructions in the interval including INSN and not including
26928      START.  When the NBYTES is smaller than 16 bytes, it is possible
26929      that the end of START and INSN ends up in the same 16byte page.
26930
26931      The smallest offset in the page INSN can start is the case where START
26932      ends on the offset 0.  Offset of INSN is then NBYTES - sizeof (INSN).
26933      We add p2align to 16byte window with maxskip 17 - NBYTES + sizeof (INSN).
26934      */
26935   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
26936     {
26937
26938       nbytes += min_insn_size (insn);
26939       if (dump_file)
26940         fprintf(dump_file, "Insn %i estimated to %i bytes\n",
26941                 INSN_UID (insn), min_insn_size (insn));
26942       if ((JUMP_P (insn)
26943            && GET_CODE (PATTERN (insn)) != ADDR_VEC
26944            && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
26945           || CALL_P (insn))
26946         njumps++;
26947       else
26948         continue;
26949
26950       while (njumps > 3)
26951         {
26952           start = NEXT_INSN (start);
26953           if ((JUMP_P (start)
26954                && GET_CODE (PATTERN (start)) != ADDR_VEC
26955                && GET_CODE (PATTERN (start)) != ADDR_DIFF_VEC)
26956               || CALL_P (start))
26957             njumps--, isjump = 1;
26958           else
26959             isjump = 0;
26960           nbytes -= min_insn_size (start);
26961         }
26962       gcc_assert (njumps >= 0);
26963       if (dump_file)
26964         fprintf (dump_file, "Interval %i to %i has %i bytes\n",
26965                 INSN_UID (start), INSN_UID (insn), nbytes);
26966
26967       if (njumps == 3 && isjump && nbytes < 16)
26968         {
26969           int padsize = 15 - nbytes + min_insn_size (insn);
26970
26971           if (dump_file)
26972             fprintf (dump_file, "Padding insn %i by %i bytes!\n",
26973                      INSN_UID (insn), padsize);
26974           emit_insn_before (gen_align (GEN_INT (padsize)), insn);
26975         }
26976     }
26977 }
26978
26979 /* AMD Athlon works faster
26980    when RET is not destination of conditional jump or directly preceded
26981    by other jump instruction.  We avoid the penalty by inserting NOP just
26982    before the RET instructions in such cases.  */
26983 static void
26984 ix86_pad_returns (void)
26985 {
26986   edge e;
26987   edge_iterator ei;
26988
26989   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
26990     {
26991       basic_block bb = e->src;
26992       rtx ret = BB_END (bb);
26993       rtx prev;
26994       bool replace = false;
26995
26996       if (!JUMP_P (ret) || GET_CODE (PATTERN (ret)) != RETURN
26997           || optimize_bb_for_size_p (bb))
26998         continue;
26999       for (prev = PREV_INSN (ret); prev; prev = PREV_INSN (prev))
27000         if (active_insn_p (prev) || LABEL_P (prev))
27001           break;
27002       if (prev && LABEL_P (prev))
27003         {
27004           edge e;
27005           edge_iterator ei;
27006
27007           FOR_EACH_EDGE (e, ei, bb->preds)
27008             if (EDGE_FREQUENCY (e) && e->src->index >= 0
27009                 && !(e->flags & EDGE_FALLTHRU))
27010               replace = true;
27011         }
27012       if (!replace)
27013         {
27014           prev = prev_active_insn (ret);
27015           if (prev
27016               && ((JUMP_P (prev) && any_condjump_p (prev))
27017                   || CALL_P (prev)))
27018             replace = true;
27019           /* Empty functions get branch mispredict even when the jump destination
27020              is not visible to us.  */
27021           if (!prev && cfun->function_frequency > FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
27022             replace = true;
27023         }
27024       if (replace)
27025         {
27026           emit_insn_before (gen_return_internal_long (), ret);
27027           delete_insn (ret);
27028         }
27029     }
27030 }
27031
27032 /* Implement machine specific optimizations.  We implement padding of returns
27033    for K8 CPUs and pass to avoid 4 jumps in the single 16 byte window.  */
27034 static void
27035 ix86_reorg (void)
27036 {
27037   if (TARGET_PAD_RETURNS && optimize
27038       && optimize_function_for_speed_p (cfun))
27039     ix86_pad_returns ();
27040   if (TARGET_FOUR_JUMP_LIMIT && optimize
27041       && optimize_function_for_speed_p (cfun))
27042     ix86_avoid_jump_misspredicts ();
27043 }
27044
27045 /* Return nonzero when QImode register that must be represented via REX prefix
27046    is used.  */
27047 bool
27048 x86_extended_QIreg_mentioned_p (rtx insn)
27049 {
27050   int i;
27051   extract_insn_cached (insn);
27052   for (i = 0; i < recog_data.n_operands; i++)
27053     if (REG_P (recog_data.operand[i])
27054         && REGNO (recog_data.operand[i]) > BX_REG)
27055        return true;
27056   return false;
27057 }
27058
27059 /* Return nonzero when P points to register encoded via REX prefix.
27060    Called via for_each_rtx.  */
27061 static int
27062 extended_reg_mentioned_1 (rtx *p, void *data ATTRIBUTE_UNUSED)
27063 {
27064    unsigned int regno;
27065    if (!REG_P (*p))
27066      return 0;
27067    regno = REGNO (*p);
27068    return REX_INT_REGNO_P (regno) || REX_SSE_REGNO_P (regno);
27069 }
27070
27071 /* Return true when INSN mentions register that must be encoded using REX
27072    prefix.  */
27073 bool
27074 x86_extended_reg_mentioned_p (rtx insn)
27075 {
27076   return for_each_rtx (INSN_P (insn) ? &PATTERN (insn) : &insn,
27077                        extended_reg_mentioned_1, NULL);
27078 }
27079
27080 /* Generate an unsigned DImode/SImode to FP conversion.  This is the same code
27081    optabs would emit if we didn't have TFmode patterns.  */
27082
27083 void
27084 x86_emit_floatuns (rtx operands[2])
27085 {
27086   rtx neglab, donelab, i0, i1, f0, in, out;
27087   enum machine_mode mode, inmode;
27088
27089   inmode = GET_MODE (operands[1]);
27090   gcc_assert (inmode == SImode || inmode == DImode);
27091
27092   out = operands[0];
27093   in = force_reg (inmode, operands[1]);
27094   mode = GET_MODE (out);
27095   neglab = gen_label_rtx ();
27096   donelab = gen_label_rtx ();
27097   f0 = gen_reg_rtx (mode);
27098
27099   emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, inmode, 0, neglab);
27100
27101   expand_float (out, in, 0);
27102
27103   emit_jump_insn (gen_jump (donelab));
27104   emit_barrier ();
27105
27106   emit_label (neglab);
27107
27108   i0 = expand_simple_binop (inmode, LSHIFTRT, in, const1_rtx, NULL,
27109                             1, OPTAB_DIRECT);
27110   i1 = expand_simple_binop (inmode, AND, in, const1_rtx, NULL,
27111                             1, OPTAB_DIRECT);
27112   i0 = expand_simple_binop (inmode, IOR, i0, i1, i0, 1, OPTAB_DIRECT);
27113
27114   expand_float (f0, i0, 0);
27115
27116   emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
27117
27118   emit_label (donelab);
27119 }
27120 \f
27121 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
27122    with all elements equal to VAR.  Return true if successful.  */
27123
27124 static bool
27125 ix86_expand_vector_init_duplicate (bool mmx_ok, enum machine_mode mode,
27126                                    rtx target, rtx val)
27127 {
27128   enum machine_mode hmode, smode, wsmode, wvmode;
27129   rtx x;
27130
27131   switch (mode)
27132     {
27133     case V2SImode:
27134     case V2SFmode:
27135       if (!mmx_ok)
27136         return false;
27137       /* FALLTHRU */
27138
27139     case V2DFmode:
27140     case V2DImode:
27141     case V4SFmode:
27142     case V4SImode:
27143       val = force_reg (GET_MODE_INNER (mode), val);
27144       x = gen_rtx_VEC_DUPLICATE (mode, val);
27145       emit_insn (gen_rtx_SET (VOIDmode, target, x));
27146       return true;
27147
27148     case V4HImode:
27149       if (!mmx_ok)
27150         return false;
27151       if (TARGET_SSE || TARGET_3DNOW_A)
27152         {
27153           val = gen_lowpart (SImode, val);
27154           x = gen_rtx_TRUNCATE (HImode, val);
27155           x = gen_rtx_VEC_DUPLICATE (mode, x);
27156           emit_insn (gen_rtx_SET (VOIDmode, target, x));
27157           return true;
27158         }
27159       else
27160         {
27161           smode = HImode;
27162           wsmode = SImode;
27163           wvmode = V2SImode;
27164           goto widen;
27165         }
27166
27167     case V8QImode:
27168       if (!mmx_ok)
27169         return false;
27170       smode = QImode;
27171       wsmode = HImode;
27172       wvmode = V4HImode;
27173       goto widen;
27174     case V8HImode:
27175       if (TARGET_SSE2)
27176         {
27177           rtx tmp1, tmp2;
27178           /* Extend HImode to SImode using a paradoxical SUBREG.  */
27179           tmp1 = gen_reg_rtx (SImode);
27180           emit_move_insn (tmp1, gen_lowpart (SImode, val));
27181           /* Insert the SImode value as low element of V4SImode vector. */
27182           tmp2 = gen_reg_rtx (V4SImode);
27183           tmp1 = gen_rtx_VEC_MERGE (V4SImode,
27184                                     gen_rtx_VEC_DUPLICATE (V4SImode, tmp1),
27185                                     CONST0_RTX (V4SImode),
27186                                     const1_rtx);
27187           emit_insn (gen_rtx_SET (VOIDmode, tmp2, tmp1));
27188           /* Cast the V4SImode vector back to a V8HImode vector.  */
27189           tmp1 = gen_reg_rtx (V8HImode);
27190           emit_move_insn (tmp1, gen_lowpart (V8HImode, tmp2));
27191           /* Duplicate the low short through the whole low SImode word.  */
27192           emit_insn (gen_sse2_punpcklwd (tmp1, tmp1, tmp1));
27193           /* Cast the V8HImode vector back to a V4SImode vector.  */
27194           tmp2 = gen_reg_rtx (V4SImode);
27195           emit_move_insn (tmp2, gen_lowpart (V4SImode, tmp1));
27196           /* Replicate the low element of the V4SImode vector.  */
27197           emit_insn (gen_sse2_pshufd (tmp2, tmp2, const0_rtx));
27198           /* Cast the V2SImode back to V8HImode, and store in target.  */
27199           emit_move_insn (target, gen_lowpart (V8HImode, tmp2));
27200           return true;
27201         }
27202       smode = HImode;
27203       wsmode = SImode;
27204       wvmode = V4SImode;
27205       goto widen;
27206     case V16QImode:
27207       if (TARGET_SSE2)
27208         {
27209           rtx tmp1, tmp2;
27210           /* Extend QImode to SImode using a paradoxical SUBREG.  */
27211           tmp1 = gen_reg_rtx (SImode);
27212           emit_move_insn (tmp1, gen_lowpart (SImode, val));
27213           /* Insert the SImode value as low element of V4SImode vector. */
27214           tmp2 = gen_reg_rtx (V4SImode);
27215           tmp1 = gen_rtx_VEC_MERGE (V4SImode,
27216                                     gen_rtx_VEC_DUPLICATE (V4SImode, tmp1),
27217                                     CONST0_RTX (V4SImode),
27218                                     const1_rtx);
27219           emit_insn (gen_rtx_SET (VOIDmode, tmp2, tmp1));
27220           /* Cast the V4SImode vector back to a V16QImode vector.  */
27221           tmp1 = gen_reg_rtx (V16QImode);
27222           emit_move_insn (tmp1, gen_lowpart (V16QImode, tmp2));
27223           /* Duplicate the low byte through the whole low SImode word.  */
27224           emit_insn (gen_sse2_punpcklbw (tmp1, tmp1, tmp1));
27225           emit_insn (gen_sse2_punpcklbw (tmp1, tmp1, tmp1));
27226           /* Cast the V16QImode vector back to a V4SImode vector.  */
27227           tmp2 = gen_reg_rtx (V4SImode);
27228           emit_move_insn (tmp2, gen_lowpart (V4SImode, tmp1));
27229           /* Replicate the low element of the V4SImode vector.  */
27230           emit_insn (gen_sse2_pshufd (tmp2, tmp2, const0_rtx));
27231           /* Cast the V2SImode back to V16QImode, and store in target.  */
27232           emit_move_insn (target, gen_lowpart (V16QImode, tmp2));
27233           return true;
27234         }
27235       smode = QImode;
27236       wsmode = HImode;
27237       wvmode = V8HImode;
27238       goto widen;
27239     widen:
27240       /* Replicate the value once into the next wider mode and recurse.  */
27241       val = convert_modes (wsmode, smode, val, true);
27242       x = expand_simple_binop (wsmode, ASHIFT, val,
27243                                GEN_INT (GET_MODE_BITSIZE (smode)),
27244                                NULL_RTX, 1, OPTAB_LIB_WIDEN);
27245       val = expand_simple_binop (wsmode, IOR, val, x, x, 1, OPTAB_LIB_WIDEN);
27246
27247       x = gen_reg_rtx (wvmode);
27248       if (!ix86_expand_vector_init_duplicate (mmx_ok, wvmode, x, val))
27249         gcc_unreachable ();
27250       emit_move_insn (target, gen_lowpart (mode, x));
27251       return true;
27252
27253     case V4DFmode:
27254       hmode = V2DFmode;
27255       goto half;
27256     case V4DImode:
27257       hmode = V2DImode;
27258       goto half;
27259     case V8SFmode:
27260       hmode = V4SFmode;
27261       goto half;
27262     case V8SImode:
27263       hmode = V4SImode;
27264       goto half;
27265     case V16HImode:
27266       hmode = V8HImode;
27267       goto half;
27268     case V32QImode:
27269       hmode = V16QImode;
27270       goto half;
27271 half:
27272       {
27273         rtx tmp = gen_reg_rtx (hmode);
27274         ix86_expand_vector_init_duplicate (mmx_ok, hmode, tmp, val);
27275         emit_insn (gen_rtx_SET (VOIDmode, target,
27276                                 gen_rtx_VEC_CONCAT (mode, tmp, tmp)));
27277       }
27278       return true;
27279
27280     default:
27281       return false;
27282     }
27283 }
27284
27285 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
27286    whose ONE_VAR element is VAR, and other elements are zero.  Return true
27287    if successful.  */
27288
27289 static bool
27290 ix86_expand_vector_init_one_nonzero (bool mmx_ok, enum machine_mode mode,
27291                                      rtx target, rtx var, int one_var)
27292 {
27293   enum machine_mode vsimode;
27294   rtx new_target;
27295   rtx x, tmp;
27296   bool use_vector_set = false;
27297
27298   switch (mode)
27299     {
27300     case V2DImode:
27301       /* For SSE4.1, we normally use vector set.  But if the second
27302          element is zero and inter-unit moves are OK, we use movq
27303          instead.  */
27304       use_vector_set = (TARGET_64BIT
27305                         && TARGET_SSE4_1
27306                         && !(TARGET_INTER_UNIT_MOVES
27307                              && one_var == 0));
27308       break;
27309     case V16QImode:
27310     case V4SImode:
27311     case V4SFmode:
27312       use_vector_set = TARGET_SSE4_1;
27313       break;
27314     case V8HImode:
27315       use_vector_set = TARGET_SSE2;
27316       break;
27317     case V4HImode:
27318       use_vector_set = TARGET_SSE || TARGET_3DNOW_A;
27319       break;
27320     case V32QImode:
27321     case V16HImode:
27322     case V8SImode:
27323     case V8SFmode:
27324     case V4DFmode:
27325       use_vector_set = TARGET_AVX;
27326       break;
27327     case V4DImode:
27328       /* Use ix86_expand_vector_set in 64bit mode only.  */
27329       use_vector_set = TARGET_AVX && TARGET_64BIT;
27330       break;
27331     default:
27332       break;
27333     }
27334
27335   if (use_vector_set)
27336     {
27337       emit_insn (gen_rtx_SET (VOIDmode, target, CONST0_RTX (mode)));
27338       var = force_reg (GET_MODE_INNER (mode), var);
27339       ix86_expand_vector_set (mmx_ok, target, var, one_var);
27340       return true; 
27341     }
27342
27343   switch (mode)
27344     {
27345     case V2SFmode:
27346     case V2SImode:
27347       if (!mmx_ok)
27348         return false;
27349       /* FALLTHRU */
27350
27351     case V2DFmode:
27352     case V2DImode:
27353       if (one_var != 0)
27354         return false;
27355       var = force_reg (GET_MODE_INNER (mode), var);
27356       x = gen_rtx_VEC_CONCAT (mode, var, CONST0_RTX (GET_MODE_INNER (mode)));
27357       emit_insn (gen_rtx_SET (VOIDmode, target, x));
27358       return true;
27359
27360     case V4SFmode:
27361     case V4SImode:
27362       if (!REG_P (target) || REGNO (target) < FIRST_PSEUDO_REGISTER)
27363         new_target = gen_reg_rtx (mode);
27364       else
27365         new_target = target;
27366       var = force_reg (GET_MODE_INNER (mode), var);
27367       x = gen_rtx_VEC_DUPLICATE (mode, var);
27368       x = gen_rtx_VEC_MERGE (mode, x, CONST0_RTX (mode), const1_rtx);
27369       emit_insn (gen_rtx_SET (VOIDmode, new_target, x));
27370       if (one_var != 0)
27371         {
27372           /* We need to shuffle the value to the correct position, so
27373              create a new pseudo to store the intermediate result.  */
27374
27375           /* With SSE2, we can use the integer shuffle insns.  */
27376           if (mode != V4SFmode && TARGET_SSE2)
27377             {
27378               emit_insn (gen_sse2_pshufd_1 (new_target, new_target,
27379                                             GEN_INT (1),
27380                                             GEN_INT (one_var == 1 ? 0 : 1),
27381                                             GEN_INT (one_var == 2 ? 0 : 1),
27382                                             GEN_INT (one_var == 3 ? 0 : 1)));
27383               if (target != new_target)
27384                 emit_move_insn (target, new_target);
27385               return true;
27386             }
27387
27388           /* Otherwise convert the intermediate result to V4SFmode and
27389              use the SSE1 shuffle instructions.  */
27390           if (mode != V4SFmode)
27391             {
27392               tmp = gen_reg_rtx (V4SFmode);
27393               emit_move_insn (tmp, gen_lowpart (V4SFmode, new_target));
27394             }
27395           else
27396             tmp = new_target;
27397
27398           emit_insn (gen_sse_shufps_v4sf (tmp, tmp, tmp,
27399                                        GEN_INT (1),
27400                                        GEN_INT (one_var == 1 ? 0 : 1),
27401                                        GEN_INT (one_var == 2 ? 0+4 : 1+4),
27402                                        GEN_INT (one_var == 3 ? 0+4 : 1+4)));
27403
27404           if (mode != V4SFmode)
27405             emit_move_insn (target, gen_lowpart (V4SImode, tmp));
27406           else if (tmp != target)
27407             emit_move_insn (target, tmp);
27408         }
27409       else if (target != new_target)
27410         emit_move_insn (target, new_target);
27411       return true;
27412
27413     case V8HImode:
27414     case V16QImode:
27415       vsimode = V4SImode;
27416       goto widen;
27417     case V4HImode:
27418     case V8QImode:
27419       if (!mmx_ok)
27420         return false;
27421       vsimode = V2SImode;
27422       goto widen;
27423     widen:
27424       if (one_var != 0)
27425         return false;
27426
27427       /* Zero extend the variable element to SImode and recurse.  */
27428       var = convert_modes (SImode, GET_MODE_INNER (mode), var, true);
27429
27430       x = gen_reg_rtx (vsimode);
27431       if (!ix86_expand_vector_init_one_nonzero (mmx_ok, vsimode, x,
27432                                                 var, one_var))
27433         gcc_unreachable ();
27434
27435       emit_move_insn (target, gen_lowpart (mode, x));
27436       return true;
27437
27438     default:
27439       return false;
27440     }
27441 }
27442
27443 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
27444    consisting of the values in VALS.  It is known that all elements
27445    except ONE_VAR are constants.  Return true if successful.  */
27446
27447 static bool
27448 ix86_expand_vector_init_one_var (bool mmx_ok, enum machine_mode mode,
27449                                  rtx target, rtx vals, int one_var)
27450 {
27451   rtx var = XVECEXP (vals, 0, one_var);
27452   enum machine_mode wmode;
27453   rtx const_vec, x;
27454
27455   const_vec = copy_rtx (vals);
27456   XVECEXP (const_vec, 0, one_var) = CONST0_RTX (GET_MODE_INNER (mode));
27457   const_vec = gen_rtx_CONST_VECTOR (mode, XVEC (const_vec, 0));
27458
27459   switch (mode)
27460     {
27461     case V2DFmode:
27462     case V2DImode:
27463     case V2SFmode:
27464     case V2SImode:
27465       /* For the two element vectors, it's just as easy to use
27466          the general case.  */
27467       return false;
27468
27469     case V4DImode:
27470       /* Use ix86_expand_vector_set in 64bit mode only.  */
27471       if (!TARGET_64BIT)
27472         return false;
27473     case V4DFmode:
27474     case V8SFmode:
27475     case V8SImode:
27476     case V16HImode:
27477     case V32QImode:
27478     case V4SFmode:
27479     case V4SImode:
27480     case V8HImode:
27481     case V4HImode:
27482       break;
27483
27484     case V16QImode:
27485       if (TARGET_SSE4_1)
27486         break;
27487       wmode = V8HImode;
27488       goto widen;
27489     case V8QImode:
27490       wmode = V4HImode;
27491       goto widen;
27492     widen:
27493       /* There's no way to set one QImode entry easily.  Combine
27494          the variable value with its adjacent constant value, and
27495          promote to an HImode set.  */
27496       x = XVECEXP (vals, 0, one_var ^ 1);
27497       if (one_var & 1)
27498         {
27499           var = convert_modes (HImode, QImode, var, true);
27500           var = expand_simple_binop (HImode, ASHIFT, var, GEN_INT (8),
27501                                      NULL_RTX, 1, OPTAB_LIB_WIDEN);
27502           x = GEN_INT (INTVAL (x) & 0xff);
27503         }
27504       else
27505         {
27506           var = convert_modes (HImode, QImode, var, true);
27507           x = gen_int_mode (INTVAL (x) << 8, HImode);
27508         }
27509       if (x != const0_rtx)
27510         var = expand_simple_binop (HImode, IOR, var, x, var,
27511                                    1, OPTAB_LIB_WIDEN);
27512
27513       x = gen_reg_rtx (wmode);
27514       emit_move_insn (x, gen_lowpart (wmode, const_vec));
27515       ix86_expand_vector_set (mmx_ok, x, var, one_var >> 1);
27516
27517       emit_move_insn (target, gen_lowpart (mode, x));
27518       return true;
27519
27520     default:
27521       return false;
27522     }
27523
27524   emit_move_insn (target, const_vec);
27525   ix86_expand_vector_set (mmx_ok, target, var, one_var);
27526   return true;
27527 }
27528
27529 /* A subroutine of ix86_expand_vector_init_general.  Use vector
27530    concatenate to handle the most general case: all values variable,
27531    and none identical.  */
27532
27533 static void
27534 ix86_expand_vector_init_concat (enum machine_mode mode,
27535                                 rtx target, rtx *ops, int n)
27536 {
27537   enum machine_mode cmode, hmode = VOIDmode;
27538   rtx first[8], second[4];
27539   rtvec v;
27540   int i, j;
27541
27542   switch (n)
27543     {
27544     case 2:
27545       switch (mode)
27546         {
27547         case V8SImode:
27548           cmode = V4SImode;
27549           break;
27550         case V8SFmode:
27551           cmode = V4SFmode;
27552           break;
27553         case V4DImode:
27554           cmode = V2DImode;
27555           break;
27556         case V4DFmode:
27557           cmode = V2DFmode;
27558           break;
27559         case V4SImode:
27560           cmode = V2SImode;
27561           break;
27562         case V4SFmode:
27563           cmode = V2SFmode;
27564           break;
27565         case V2DImode:
27566           cmode = DImode;
27567           break;
27568         case V2SImode:
27569           cmode = SImode;
27570           break;
27571         case V2DFmode:
27572           cmode = DFmode;
27573           break;
27574         case V2SFmode:
27575           cmode = SFmode;
27576           break;
27577         default:
27578           gcc_unreachable ();
27579         }
27580
27581       if (!register_operand (ops[1], cmode))
27582         ops[1] = force_reg (cmode, ops[1]);
27583       if (!register_operand (ops[0], cmode))
27584         ops[0] = force_reg (cmode, ops[0]);
27585       emit_insn (gen_rtx_SET (VOIDmode, target,
27586                               gen_rtx_VEC_CONCAT (mode, ops[0],
27587                                                   ops[1])));
27588       break;
27589
27590     case 4:
27591       switch (mode)
27592         {
27593         case V4DImode:
27594           cmode = V2DImode;
27595           break;
27596         case V4DFmode:
27597           cmode = V2DFmode;
27598           break;
27599         case V4SImode:
27600           cmode = V2SImode;
27601           break;
27602         case V4SFmode:
27603           cmode = V2SFmode;
27604           break;
27605         default:
27606           gcc_unreachable ();
27607         }
27608       goto half;
27609
27610     case 8:
27611       switch (mode)
27612         {
27613         case V8SImode:
27614           cmode = V2SImode;
27615           hmode = V4SImode;
27616           break;
27617         case V8SFmode:
27618           cmode = V2SFmode;
27619           hmode = V4SFmode;
27620           break;
27621         default:
27622           gcc_unreachable ();
27623         }
27624       goto half;
27625
27626 half:
27627       /* FIXME: We process inputs backward to help RA.  PR 36222.  */
27628       i = n - 1;
27629       j = (n >> 1) - 1;
27630       for (; i > 0; i -= 2, j--)
27631         {
27632           first[j] = gen_reg_rtx (cmode);
27633           v = gen_rtvec (2, ops[i - 1], ops[i]);
27634           ix86_expand_vector_init (false, first[j],
27635                                    gen_rtx_PARALLEL (cmode, v));
27636         }
27637
27638       n >>= 1;
27639       if (n > 2)
27640         {
27641           gcc_assert (hmode != VOIDmode);
27642           for (i = j = 0; i < n; i += 2, j++)
27643             {
27644               second[j] = gen_reg_rtx (hmode);
27645               ix86_expand_vector_init_concat (hmode, second [j],
27646                                               &first [i], 2);
27647             }
27648           n >>= 1;
27649           ix86_expand_vector_init_concat (mode, target, second, n);
27650         }
27651       else
27652         ix86_expand_vector_init_concat (mode, target, first, n);
27653       break;
27654
27655     default:
27656       gcc_unreachable ();
27657     }
27658 }
27659
27660 /* A subroutine of ix86_expand_vector_init_general.  Use vector
27661    interleave to handle the most general case: all values variable,
27662    and none identical.  */
27663
27664 static void
27665 ix86_expand_vector_init_interleave (enum machine_mode mode,
27666                                     rtx target, rtx *ops, int n)
27667 {
27668   enum machine_mode first_imode, second_imode, third_imode, inner_mode;
27669   int i, j;
27670   rtx op0, op1;
27671   rtx (*gen_load_even) (rtx, rtx, rtx);
27672   rtx (*gen_interleave_first_low) (rtx, rtx, rtx);
27673   rtx (*gen_interleave_second_low) (rtx, rtx, rtx);
27674   
27675   switch (mode)
27676     {
27677     case V8HImode:
27678       gen_load_even = gen_vec_setv8hi;
27679       gen_interleave_first_low = gen_vec_interleave_lowv4si;
27680       gen_interleave_second_low = gen_vec_interleave_lowv2di;
27681       inner_mode = HImode;
27682       first_imode = V4SImode;
27683       second_imode = V2DImode;
27684       third_imode = VOIDmode;
27685       break;
27686     case V16QImode:
27687       gen_load_even = gen_vec_setv16qi;
27688       gen_interleave_first_low = gen_vec_interleave_lowv8hi;
27689       gen_interleave_second_low = gen_vec_interleave_lowv4si;
27690       inner_mode = QImode;
27691       first_imode = V8HImode;
27692       second_imode = V4SImode;
27693       third_imode = V2DImode;
27694       break;
27695     default:
27696       gcc_unreachable ();
27697     }
27698      
27699   for (i = 0; i < n; i++)
27700     {
27701       /* Extend the odd elment to SImode using a paradoxical SUBREG.  */
27702       op0 = gen_reg_rtx (SImode);
27703       emit_move_insn (op0, gen_lowpart (SImode, ops [i + i]));
27704
27705       /* Insert the SImode value as low element of V4SImode vector. */
27706       op1 = gen_reg_rtx (V4SImode);
27707       op0 = gen_rtx_VEC_MERGE (V4SImode,
27708                                gen_rtx_VEC_DUPLICATE (V4SImode,
27709                                                       op0),
27710                                CONST0_RTX (V4SImode),
27711                                const1_rtx);
27712       emit_insn (gen_rtx_SET (VOIDmode, op1, op0));
27713
27714       /* Cast the V4SImode vector back to a vector in orignal mode.  */
27715       op0 = gen_reg_rtx (mode);
27716       emit_move_insn (op0, gen_lowpart (mode, op1));
27717       
27718       /* Load even elements into the second positon.  */
27719       emit_insn ((*gen_load_even) (op0,
27720                                    force_reg (inner_mode,
27721                                               ops [i + i + 1]),
27722                                    const1_rtx));
27723
27724       /* Cast vector to FIRST_IMODE vector.  */
27725       ops[i] = gen_reg_rtx (first_imode);
27726       emit_move_insn (ops[i], gen_lowpart (first_imode, op0));
27727     }
27728
27729   /* Interleave low FIRST_IMODE vectors.  */
27730   for (i = j = 0; i < n; i += 2, j++)
27731     {
27732       op0 = gen_reg_rtx (first_imode);
27733       emit_insn ((*gen_interleave_first_low) (op0, ops[i], ops[i + 1]));
27734
27735       /* Cast FIRST_IMODE vector to SECOND_IMODE vector.  */
27736       ops[j] = gen_reg_rtx (second_imode);
27737       emit_move_insn (ops[j], gen_lowpart (second_imode, op0));
27738     }
27739
27740   /* Interleave low SECOND_IMODE vectors.  */
27741   switch (second_imode)
27742     {
27743     case V4SImode:
27744       for (i = j = 0; i < n / 2; i += 2, j++)
27745         {
27746           op0 = gen_reg_rtx (second_imode);
27747           emit_insn ((*gen_interleave_second_low) (op0, ops[i],
27748                                                    ops[i + 1]));
27749
27750           /* Cast the SECOND_IMODE vector to the THIRD_IMODE
27751              vector.  */
27752           ops[j] = gen_reg_rtx (third_imode);
27753           emit_move_insn (ops[j], gen_lowpart (third_imode, op0));
27754         }
27755       second_imode = V2DImode;
27756       gen_interleave_second_low = gen_vec_interleave_lowv2di;
27757       /* FALLTHRU */
27758
27759     case V2DImode:
27760       op0 = gen_reg_rtx (second_imode);
27761       emit_insn ((*gen_interleave_second_low) (op0, ops[0],
27762                                                ops[1]));
27763
27764       /* Cast the SECOND_IMODE vector back to a vector on original
27765          mode.  */
27766       emit_insn (gen_rtx_SET (VOIDmode, target,
27767                               gen_lowpart (mode, op0)));
27768       break;
27769
27770     default:
27771       gcc_unreachable ();
27772     }
27773 }
27774
27775 /* A subroutine of ix86_expand_vector_init.  Handle the most general case:
27776    all values variable, and none identical.  */
27777
27778 static void
27779 ix86_expand_vector_init_general (bool mmx_ok, enum machine_mode mode,
27780                                  rtx target, rtx vals)
27781 {
27782   rtx ops[32], op0, op1;
27783   enum machine_mode half_mode = VOIDmode;
27784   int n, i;
27785
27786   switch (mode)
27787     {
27788     case V2SFmode:
27789     case V2SImode:
27790       if (!mmx_ok && !TARGET_SSE)
27791         break;
27792       /* FALLTHRU */
27793
27794     case V8SFmode:
27795     case V8SImode:
27796     case V4DFmode:
27797     case V4DImode:
27798     case V4SFmode:
27799     case V4SImode:
27800     case V2DFmode:
27801     case V2DImode:
27802       n = GET_MODE_NUNITS (mode);
27803       for (i = 0; i < n; i++)
27804         ops[i] = XVECEXP (vals, 0, i);
27805       ix86_expand_vector_init_concat (mode, target, ops, n);
27806       return;
27807
27808     case V32QImode:
27809       half_mode = V16QImode;
27810       goto half;
27811
27812     case V16HImode:
27813       half_mode = V8HImode;
27814       goto half;
27815
27816 half:
27817       n = GET_MODE_NUNITS (mode);
27818       for (i = 0; i < n; i++)
27819         ops[i] = XVECEXP (vals, 0, i);
27820       op0 = gen_reg_rtx (half_mode);
27821       op1 = gen_reg_rtx (half_mode);
27822       ix86_expand_vector_init_interleave (half_mode, op0, ops,
27823                                           n >> 2);
27824       ix86_expand_vector_init_interleave (half_mode, op1,
27825                                           &ops [n >> 1], n >> 2);
27826       emit_insn (gen_rtx_SET (VOIDmode, target,
27827                               gen_rtx_VEC_CONCAT (mode, op0, op1)));
27828       return;
27829
27830     case V16QImode:
27831       if (!TARGET_SSE4_1)
27832         break;
27833       /* FALLTHRU */
27834
27835     case V8HImode:
27836       if (!TARGET_SSE2)
27837         break;
27838
27839       /* Don't use ix86_expand_vector_init_interleave if we can't
27840          move from GPR to SSE register directly.  */ 
27841       if (!TARGET_INTER_UNIT_MOVES)
27842         break;
27843
27844       n = GET_MODE_NUNITS (mode);
27845       for (i = 0; i < n; i++)
27846         ops[i] = XVECEXP (vals, 0, i);
27847       ix86_expand_vector_init_interleave (mode, target, ops, n >> 1);
27848       return;
27849
27850     case V4HImode:
27851     case V8QImode:
27852       break;
27853
27854     default:
27855       gcc_unreachable ();
27856     }
27857
27858     {
27859       int i, j, n_elts, n_words, n_elt_per_word;
27860       enum machine_mode inner_mode;
27861       rtx words[4], shift;
27862
27863       inner_mode = GET_MODE_INNER (mode);
27864       n_elts = GET_MODE_NUNITS (mode);
27865       n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
27866       n_elt_per_word = n_elts / n_words;
27867       shift = GEN_INT (GET_MODE_BITSIZE (inner_mode));
27868
27869       for (i = 0; i < n_words; ++i)
27870         {
27871           rtx word = NULL_RTX;
27872
27873           for (j = 0; j < n_elt_per_word; ++j)
27874             {
27875               rtx elt = XVECEXP (vals, 0, (i+1)*n_elt_per_word - j - 1);
27876               elt = convert_modes (word_mode, inner_mode, elt, true);
27877
27878               if (j == 0)
27879                 word = elt;
27880               else
27881                 {
27882                   word = expand_simple_binop (word_mode, ASHIFT, word, shift,
27883                                               word, 1, OPTAB_LIB_WIDEN);
27884                   word = expand_simple_binop (word_mode, IOR, word, elt,
27885                                               word, 1, OPTAB_LIB_WIDEN);
27886                 }
27887             }
27888
27889           words[i] = word;
27890         }
27891
27892       if (n_words == 1)
27893         emit_move_insn (target, gen_lowpart (mode, words[0]));
27894       else if (n_words == 2)
27895         {
27896           rtx tmp = gen_reg_rtx (mode);
27897           emit_clobber (tmp);
27898           emit_move_insn (gen_lowpart (word_mode, tmp), words[0]);
27899           emit_move_insn (gen_highpart (word_mode, tmp), words[1]);
27900           emit_move_insn (target, tmp);
27901         }
27902       else if (n_words == 4)
27903         {
27904           rtx tmp = gen_reg_rtx (V4SImode);
27905           gcc_assert (word_mode == SImode);
27906           vals = gen_rtx_PARALLEL (V4SImode, gen_rtvec_v (4, words));
27907           ix86_expand_vector_init_general (false, V4SImode, tmp, vals);
27908           emit_move_insn (target, gen_lowpart (mode, tmp));
27909         }
27910       else
27911         gcc_unreachable ();
27912     }
27913 }
27914
27915 /* Initialize vector TARGET via VALS.  Suppress the use of MMX
27916    instructions unless MMX_OK is true.  */
27917
27918 void
27919 ix86_expand_vector_init (bool mmx_ok, rtx target, rtx vals)
27920 {
27921   enum machine_mode mode = GET_MODE (target);
27922   enum machine_mode inner_mode = GET_MODE_INNER (mode);
27923   int n_elts = GET_MODE_NUNITS (mode);
27924   int n_var = 0, one_var = -1;
27925   bool all_same = true, all_const_zero = true;
27926   int i;
27927   rtx x;
27928
27929   for (i = 0; i < n_elts; ++i)
27930     {
27931       x = XVECEXP (vals, 0, i);
27932       if (!(CONST_INT_P (x)
27933             || GET_CODE (x) == CONST_DOUBLE
27934             || GET_CODE (x) == CONST_FIXED))
27935         n_var++, one_var = i;
27936       else if (x != CONST0_RTX (inner_mode))
27937         all_const_zero = false;
27938       if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0)))
27939         all_same = false;
27940     }
27941
27942   /* Constants are best loaded from the constant pool.  */
27943   if (n_var == 0)
27944     {
27945       emit_move_insn (target, gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)));
27946       return;
27947     }
27948
27949   /* If all values are identical, broadcast the value.  */
27950   if (all_same
27951       && ix86_expand_vector_init_duplicate (mmx_ok, mode, target,
27952                                             XVECEXP (vals, 0, 0)))
27953     return;
27954
27955   /* Values where only one field is non-constant are best loaded from
27956      the pool and overwritten via move later.  */
27957   if (n_var == 1)
27958     {
27959       if (all_const_zero
27960           && ix86_expand_vector_init_one_nonzero (mmx_ok, mode, target,
27961                                                   XVECEXP (vals, 0, one_var),
27962                                                   one_var))
27963         return;
27964
27965       if (ix86_expand_vector_init_one_var (mmx_ok, mode, target, vals, one_var))
27966         return;
27967     }
27968
27969   ix86_expand_vector_init_general (mmx_ok, mode, target, vals);
27970 }
27971
27972 void
27973 ix86_expand_vector_set (bool mmx_ok, rtx target, rtx val, int elt)
27974 {
27975   enum machine_mode mode = GET_MODE (target);
27976   enum machine_mode inner_mode = GET_MODE_INNER (mode);
27977   enum machine_mode half_mode;
27978   bool use_vec_merge = false;
27979   rtx tmp;
27980   static rtx (*gen_extract[6][2]) (rtx, rtx)
27981     = {
27982         { gen_vec_extract_lo_v32qi, gen_vec_extract_hi_v32qi },
27983         { gen_vec_extract_lo_v16hi, gen_vec_extract_hi_v16hi },
27984         { gen_vec_extract_lo_v8si, gen_vec_extract_hi_v8si },
27985         { gen_vec_extract_lo_v4di, gen_vec_extract_hi_v4di },
27986         { gen_vec_extract_lo_v8sf, gen_vec_extract_hi_v8sf },
27987         { gen_vec_extract_lo_v4df, gen_vec_extract_hi_v4df }
27988       };
27989   static rtx (*gen_insert[6][2]) (rtx, rtx, rtx)
27990     = {
27991         { gen_vec_set_lo_v32qi, gen_vec_set_hi_v32qi },
27992         { gen_vec_set_lo_v16hi, gen_vec_set_hi_v16hi },
27993         { gen_vec_set_lo_v8si, gen_vec_set_hi_v8si },
27994         { gen_vec_set_lo_v4di, gen_vec_set_hi_v4di },
27995         { gen_vec_set_lo_v8sf, gen_vec_set_hi_v8sf },
27996         { gen_vec_set_lo_v4df, gen_vec_set_hi_v4df }
27997       };
27998   int i, j, n;
27999
28000   switch (mode)
28001     {
28002     case V2SFmode:
28003     case V2SImode:
28004       if (mmx_ok)
28005         {
28006           tmp = gen_reg_rtx (GET_MODE_INNER (mode));
28007           ix86_expand_vector_extract (true, tmp, target, 1 - elt);
28008           if (elt == 0)
28009             tmp = gen_rtx_VEC_CONCAT (mode, tmp, val);
28010           else
28011             tmp = gen_rtx_VEC_CONCAT (mode, val, tmp);
28012           emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
28013           return;
28014         }
28015       break;
28016
28017     case V2DImode:
28018       use_vec_merge = TARGET_SSE4_1;
28019       if (use_vec_merge)
28020         break;
28021
28022     case V2DFmode:
28023       {
28024         rtx op0, op1;
28025
28026         /* For the two element vectors, we implement a VEC_CONCAT with
28027            the extraction of the other element.  */
28028
28029         tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (1 - elt)));
28030         tmp = gen_rtx_VEC_SELECT (inner_mode, target, tmp);
28031
28032         if (elt == 0)
28033           op0 = val, op1 = tmp;
28034         else
28035           op0 = tmp, op1 = val;
28036
28037         tmp = gen_rtx_VEC_CONCAT (mode, op0, op1);
28038         emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
28039       }
28040       return;
28041
28042     case V4SFmode:
28043       use_vec_merge = TARGET_SSE4_1;
28044       if (use_vec_merge)
28045         break;
28046
28047       switch (elt)
28048         {
28049         case 0:
28050           use_vec_merge = true;
28051           break;
28052
28053         case 1:
28054           /* tmp = target = A B C D */
28055           tmp = copy_to_reg (target);
28056           /* target = A A B B */
28057           emit_insn (gen_sse_unpcklps (target, target, target));
28058           /* target = X A B B */
28059           ix86_expand_vector_set (false, target, val, 0);
28060           /* target = A X C D  */
28061           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
28062                                        GEN_INT (1), GEN_INT (0),
28063                                        GEN_INT (2+4), GEN_INT (3+4)));
28064           return;
28065
28066         case 2:
28067           /* tmp = target = A B C D */
28068           tmp = copy_to_reg (target);
28069           /* tmp = X B C D */
28070           ix86_expand_vector_set (false, tmp, val, 0);
28071           /* target = A B X D */
28072           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
28073                                        GEN_INT (0), GEN_INT (1),
28074                                        GEN_INT (0+4), GEN_INT (3+4)));
28075           return;
28076
28077         case 3:
28078           /* tmp = target = A B C D */
28079           tmp = copy_to_reg (target);
28080           /* tmp = X B C D */
28081           ix86_expand_vector_set (false, tmp, val, 0);
28082           /* target = A B X D */
28083           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
28084                                        GEN_INT (0), GEN_INT (1),
28085                                        GEN_INT (2+4), GEN_INT (0+4)));
28086           return;
28087
28088         default:
28089           gcc_unreachable ();
28090         }
28091       break;
28092
28093     case V4SImode:
28094       use_vec_merge = TARGET_SSE4_1;
28095       if (use_vec_merge)
28096         break;
28097
28098       /* Element 0 handled by vec_merge below.  */
28099       if (elt == 0)
28100         {
28101           use_vec_merge = true;
28102           break;
28103         }
28104
28105       if (TARGET_SSE2)
28106         {
28107           /* With SSE2, use integer shuffles to swap element 0 and ELT,
28108              store into element 0, then shuffle them back.  */
28109
28110           rtx order[4];
28111
28112           order[0] = GEN_INT (elt);
28113           order[1] = const1_rtx;
28114           order[2] = const2_rtx;
28115           order[3] = GEN_INT (3);
28116           order[elt] = const0_rtx;
28117
28118           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
28119                                         order[1], order[2], order[3]));
28120
28121           ix86_expand_vector_set (false, target, val, 0);
28122
28123           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
28124                                         order[1], order[2], order[3]));
28125         }
28126       else
28127         {
28128           /* For SSE1, we have to reuse the V4SF code.  */
28129           ix86_expand_vector_set (false, gen_lowpart (V4SFmode, target),
28130                                   gen_lowpart (SFmode, val), elt);
28131         }
28132       return;
28133
28134     case V8HImode:
28135       use_vec_merge = TARGET_SSE2;
28136       break;
28137     case V4HImode:
28138       use_vec_merge = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
28139       break;
28140
28141     case V16QImode:
28142       use_vec_merge = TARGET_SSE4_1;
28143       break;
28144
28145     case V8QImode:
28146       break;
28147
28148     case V32QImode:
28149       half_mode = V16QImode;
28150       j = 0;
28151       n = 16;
28152       goto half;
28153
28154     case V16HImode:
28155       half_mode = V8HImode;
28156       j = 1;
28157       n = 8;
28158       goto half;
28159
28160     case V8SImode:
28161       half_mode = V4SImode;
28162       j = 2;
28163       n = 4;
28164       goto half;
28165
28166     case V4DImode:
28167       half_mode = V2DImode;
28168       j = 3;
28169       n = 2;
28170       goto half;
28171
28172     case V8SFmode:
28173       half_mode = V4SFmode;
28174       j = 4;
28175       n = 4;
28176       goto half;
28177
28178     case V4DFmode:
28179       half_mode = V2DFmode;
28180       j = 5;
28181       n = 2;
28182       goto half;
28183
28184 half:
28185       /* Compute offset.  */
28186       i = elt / n;
28187       elt %= n;
28188
28189       gcc_assert (i <= 1);
28190
28191       /* Extract the half.  */
28192       tmp = gen_reg_rtx (half_mode);
28193       emit_insn ((*gen_extract[j][i]) (tmp, target));
28194
28195       /* Put val in tmp at elt.  */
28196       ix86_expand_vector_set (false, tmp, val, elt);
28197
28198       /* Put it back.  */
28199       emit_insn ((*gen_insert[j][i]) (target, target, tmp));
28200       return;
28201
28202     default:
28203       break;
28204     }
28205
28206   if (use_vec_merge)
28207     {
28208       tmp = gen_rtx_VEC_DUPLICATE (mode, val);
28209       tmp = gen_rtx_VEC_MERGE (mode, tmp, target, GEN_INT (1 << elt));
28210       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
28211     }
28212   else
28213     {
28214       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), false);
28215
28216       emit_move_insn (mem, target);
28217
28218       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
28219       emit_move_insn (tmp, val);
28220
28221       emit_move_insn (target, mem);
28222     }
28223 }
28224
28225 void
28226 ix86_expand_vector_extract (bool mmx_ok, rtx target, rtx vec, int elt)
28227 {
28228   enum machine_mode mode = GET_MODE (vec);
28229   enum machine_mode inner_mode = GET_MODE_INNER (mode);
28230   bool use_vec_extr = false;
28231   rtx tmp;
28232
28233   switch (mode)
28234     {
28235     case V2SImode:
28236     case V2SFmode:
28237       if (!mmx_ok)
28238         break;
28239       /* FALLTHRU */
28240
28241     case V2DFmode:
28242     case V2DImode:
28243       use_vec_extr = true;
28244       break;
28245
28246     case V4SFmode:
28247       use_vec_extr = TARGET_SSE4_1;
28248       if (use_vec_extr)
28249         break;
28250
28251       switch (elt)
28252         {
28253         case 0:
28254           tmp = vec;
28255           break;
28256
28257         case 1:
28258         case 3:
28259           tmp = gen_reg_rtx (mode);
28260           emit_insn (gen_sse_shufps_v4sf (tmp, vec, vec,
28261                                        GEN_INT (elt), GEN_INT (elt),
28262                                        GEN_INT (elt+4), GEN_INT (elt+4)));
28263           break;
28264
28265         case 2:
28266           tmp = gen_reg_rtx (mode);
28267           emit_insn (gen_sse_unpckhps (tmp, vec, vec));
28268           break;
28269
28270         default:
28271           gcc_unreachable ();
28272         }
28273       vec = tmp;
28274       use_vec_extr = true;
28275       elt = 0;
28276       break;
28277
28278     case V4SImode:
28279       use_vec_extr = TARGET_SSE4_1;
28280       if (use_vec_extr)
28281         break;
28282
28283       if (TARGET_SSE2)
28284         {
28285           switch (elt)
28286             {
28287             case 0:
28288               tmp = vec;
28289               break;
28290
28291             case 1:
28292             case 3:
28293               tmp = gen_reg_rtx (mode);
28294               emit_insn (gen_sse2_pshufd_1 (tmp, vec,
28295                                             GEN_INT (elt), GEN_INT (elt),
28296                                             GEN_INT (elt), GEN_INT (elt)));
28297               break;
28298
28299             case 2:
28300               tmp = gen_reg_rtx (mode);
28301               emit_insn (gen_sse2_punpckhdq (tmp, vec, vec));
28302               break;
28303
28304             default:
28305               gcc_unreachable ();
28306             }
28307           vec = tmp;
28308           use_vec_extr = true;
28309           elt = 0;
28310         }
28311       else
28312         {
28313           /* For SSE1, we have to reuse the V4SF code.  */
28314           ix86_expand_vector_extract (false, gen_lowpart (SFmode, target),
28315                                       gen_lowpart (V4SFmode, vec), elt);
28316           return;
28317         }
28318       break;
28319
28320     case V8HImode:
28321       use_vec_extr = TARGET_SSE2;
28322       break;
28323     case V4HImode:
28324       use_vec_extr = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
28325       break;
28326
28327     case V16QImode:
28328       use_vec_extr = TARGET_SSE4_1;
28329       break;
28330
28331     case V8QImode:
28332       /* ??? Could extract the appropriate HImode element and shift.  */
28333     default:
28334       break;
28335     }
28336
28337   if (use_vec_extr)
28338     {
28339       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (elt)));
28340       tmp = gen_rtx_VEC_SELECT (inner_mode, vec, tmp);
28341
28342       /* Let the rtl optimizers know about the zero extension performed.  */
28343       if (inner_mode == QImode || inner_mode == HImode)
28344         {
28345           tmp = gen_rtx_ZERO_EXTEND (SImode, tmp);
28346           target = gen_lowpart (SImode, target);
28347         }
28348
28349       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
28350     }
28351   else
28352     {
28353       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), false);
28354
28355       emit_move_insn (mem, vec);
28356
28357       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
28358       emit_move_insn (target, tmp);
28359     }
28360 }
28361
28362 /* Expand a vector reduction on V4SFmode for SSE1.  FN is the binary
28363    pattern to reduce; DEST is the destination; IN is the input vector.  */
28364
28365 void
28366 ix86_expand_reduc_v4sf (rtx (*fn) (rtx, rtx, rtx), rtx dest, rtx in)
28367 {
28368   rtx tmp1, tmp2, tmp3;
28369
28370   tmp1 = gen_reg_rtx (V4SFmode);
28371   tmp2 = gen_reg_rtx (V4SFmode);
28372   tmp3 = gen_reg_rtx (V4SFmode);
28373
28374   emit_insn (gen_sse_movhlps (tmp1, in, in));
28375   emit_insn (fn (tmp2, tmp1, in));
28376
28377   emit_insn (gen_sse_shufps_v4sf (tmp3, tmp2, tmp2,
28378                                GEN_INT (1), GEN_INT (1),
28379                                GEN_INT (1+4), GEN_INT (1+4)));
28380   emit_insn (fn (dest, tmp2, tmp3));
28381 }
28382 \f
28383 /* Target hook for scalar_mode_supported_p.  */
28384 static bool
28385 ix86_scalar_mode_supported_p (enum machine_mode mode)
28386 {
28387   if (DECIMAL_FLOAT_MODE_P (mode))
28388     return true;
28389   else if (mode == TFmode)
28390     return true;
28391   else
28392     return default_scalar_mode_supported_p (mode);
28393 }
28394
28395 /* Implements target hook vector_mode_supported_p.  */
28396 static bool
28397 ix86_vector_mode_supported_p (enum machine_mode mode)
28398 {
28399   if (TARGET_SSE && VALID_SSE_REG_MODE (mode))
28400     return true;
28401   if (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
28402     return true;
28403   if (TARGET_AVX && VALID_AVX256_REG_MODE (mode))
28404     return true;
28405   if (TARGET_MMX && VALID_MMX_REG_MODE (mode))
28406     return true;
28407   if (TARGET_3DNOW && VALID_MMX_REG_MODE_3DNOW (mode))
28408     return true;
28409   return false;
28410 }
28411
28412 /* Target hook for c_mode_for_suffix.  */
28413 static enum machine_mode
28414 ix86_c_mode_for_suffix (char suffix)
28415 {
28416   if (suffix == 'q')
28417     return TFmode;
28418   if (suffix == 'w')
28419     return XFmode;
28420
28421   return VOIDmode;
28422 }
28423
28424 /* Worker function for TARGET_MD_ASM_CLOBBERS.
28425
28426    We do this in the new i386 backend to maintain source compatibility
28427    with the old cc0-based compiler.  */
28428
28429 static tree
28430 ix86_md_asm_clobbers (tree outputs ATTRIBUTE_UNUSED,
28431                       tree inputs ATTRIBUTE_UNUSED,
28432                       tree clobbers)
28433 {
28434   clobbers = tree_cons (NULL_TREE, build_string (5, "flags"),
28435                         clobbers);
28436   clobbers = tree_cons (NULL_TREE, build_string (4, "fpsr"),
28437                         clobbers);
28438   return clobbers;
28439 }
28440
28441 /* Implements target vector targetm.asm.encode_section_info.  This
28442    is not used by netware.  */
28443
28444 static void ATTRIBUTE_UNUSED
28445 ix86_encode_section_info (tree decl, rtx rtl, int first)
28446 {
28447   default_encode_section_info (decl, rtl, first);
28448
28449   if (TREE_CODE (decl) == VAR_DECL
28450       && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
28451       && ix86_in_large_data_p (decl))
28452     SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= SYMBOL_FLAG_FAR_ADDR;
28453 }
28454
28455 /* Worker function for REVERSE_CONDITION.  */
28456
28457 enum rtx_code
28458 ix86_reverse_condition (enum rtx_code code, enum machine_mode mode)
28459 {
28460   return (mode != CCFPmode && mode != CCFPUmode
28461           ? reverse_condition (code)
28462           : reverse_condition_maybe_unordered (code));
28463 }
28464
28465 /* Output code to perform an x87 FP register move, from OPERANDS[1]
28466    to OPERANDS[0].  */
28467
28468 const char *
28469 output_387_reg_move (rtx insn, rtx *operands)
28470 {
28471   if (REG_P (operands[0]))
28472     {
28473       if (REG_P (operands[1])
28474           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
28475         {
28476           if (REGNO (operands[0]) == FIRST_STACK_REG)
28477             return output_387_ffreep (operands, 0);
28478           return "fstp\t%y0";
28479         }
28480       if (STACK_TOP_P (operands[0]))
28481         return "fld%z1\t%y1";
28482       return "fst\t%y0";
28483     }
28484   else if (MEM_P (operands[0]))
28485     {
28486       gcc_assert (REG_P (operands[1]));
28487       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
28488         return "fstp%z0\t%y0";
28489       else
28490         {
28491           /* There is no non-popping store to memory for XFmode.
28492              So if we need one, follow the store with a load.  */
28493           if (GET_MODE (operands[0]) == XFmode)
28494             return "fstp%z0\t%y0\n\tfld%z0\t%y0";
28495           else
28496             return "fst%z0\t%y0";
28497         }
28498     }
28499   else
28500     gcc_unreachable();
28501 }
28502
28503 /* Output code to perform a conditional jump to LABEL, if C2 flag in
28504    FP status register is set.  */
28505
28506 void
28507 ix86_emit_fp_unordered_jump (rtx label)
28508 {
28509   rtx reg = gen_reg_rtx (HImode);
28510   rtx temp;
28511
28512   emit_insn (gen_x86_fnstsw_1 (reg));
28513
28514   if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ()))
28515     {
28516       emit_insn (gen_x86_sahf_1 (reg));
28517
28518       temp = gen_rtx_REG (CCmode, FLAGS_REG);
28519       temp = gen_rtx_UNORDERED (VOIDmode, temp, const0_rtx);
28520     }
28521   else
28522     {
28523       emit_insn (gen_testqi_ext_ccno_0 (reg, GEN_INT (0x04)));
28524
28525       temp = gen_rtx_REG (CCNOmode, FLAGS_REG);
28526       temp = gen_rtx_NE (VOIDmode, temp, const0_rtx);
28527     }
28528
28529   temp = gen_rtx_IF_THEN_ELSE (VOIDmode, temp,
28530                               gen_rtx_LABEL_REF (VOIDmode, label),
28531                               pc_rtx);
28532   temp = gen_rtx_SET (VOIDmode, pc_rtx, temp);
28533
28534   emit_jump_insn (temp);
28535   predict_jump (REG_BR_PROB_BASE * 10 / 100);
28536 }
28537
28538 /* Output code to perform a log1p XFmode calculation.  */
28539
28540 void ix86_emit_i387_log1p (rtx op0, rtx op1)
28541 {
28542   rtx label1 = gen_label_rtx ();
28543   rtx label2 = gen_label_rtx ();
28544
28545   rtx tmp = gen_reg_rtx (XFmode);
28546   rtx tmp2 = gen_reg_rtx (XFmode);
28547
28548   emit_insn (gen_absxf2 (tmp, op1));
28549   emit_insn (gen_cmpxf (tmp,
28550     CONST_DOUBLE_FROM_REAL_VALUE (
28551        REAL_VALUE_ATOF ("0.29289321881345247561810596348408353", XFmode),
28552        XFmode)));
28553   emit_jump_insn (gen_bge (label1));
28554
28555   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
28556   emit_insn (gen_fyl2xp1xf3_i387 (op0, op1, tmp2));
28557   emit_jump (label2);
28558
28559   emit_label (label1);
28560   emit_move_insn (tmp, CONST1_RTX (XFmode));
28561   emit_insn (gen_addxf3 (tmp, op1, tmp));
28562   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
28563   emit_insn (gen_fyl2xxf3_i387 (op0, tmp, tmp2));
28564
28565   emit_label (label2);
28566 }
28567
28568 /* Output code to perform a Newton-Rhapson approximation of a single precision
28569    floating point divide [http://en.wikipedia.org/wiki/N-th_root_algorithm].  */
28570
28571 void ix86_emit_swdivsf (rtx res, rtx a, rtx b, enum machine_mode mode)
28572 {
28573   rtx x0, x1, e0, e1, two;
28574
28575   x0 = gen_reg_rtx (mode);
28576   e0 = gen_reg_rtx (mode);
28577   e1 = gen_reg_rtx (mode);
28578   x1 = gen_reg_rtx (mode);
28579
28580   two = CONST_DOUBLE_FROM_REAL_VALUE (dconst2, SFmode);
28581
28582   if (VECTOR_MODE_P (mode))
28583     two = ix86_build_const_vector (SFmode, true, two);
28584
28585   two = force_reg (mode, two);
28586
28587   /* a / b = a * rcp(b) * (2.0 - b * rcp(b)) */
28588
28589   /* x0 = rcp(b) estimate */
28590   emit_insn (gen_rtx_SET (VOIDmode, x0,
28591                           gen_rtx_UNSPEC (mode, gen_rtvec (1, b),
28592                                           UNSPEC_RCP)));
28593   /* e0 = x0 * b */
28594   emit_insn (gen_rtx_SET (VOIDmode, e0,
28595                           gen_rtx_MULT (mode, x0, b)));
28596   /* e1 = 2. - e0 */
28597   emit_insn (gen_rtx_SET (VOIDmode, e1,
28598                           gen_rtx_MINUS (mode, two, e0)));
28599   /* x1 = x0 * e1 */
28600   emit_insn (gen_rtx_SET (VOIDmode, x1,
28601                           gen_rtx_MULT (mode, x0, e1)));
28602   /* res = a * x1 */
28603   emit_insn (gen_rtx_SET (VOIDmode, res,
28604                           gen_rtx_MULT (mode, a, x1)));
28605 }
28606
28607 /* Output code to perform a Newton-Rhapson approximation of a
28608    single precision floating point [reciprocal] square root.  */
28609
28610 void ix86_emit_swsqrtsf (rtx res, rtx a, enum machine_mode mode,
28611                          bool recip)
28612 {
28613   rtx x0, e0, e1, e2, e3, mthree, mhalf;
28614   REAL_VALUE_TYPE r;
28615
28616   x0 = gen_reg_rtx (mode);
28617   e0 = gen_reg_rtx (mode);
28618   e1 = gen_reg_rtx (mode);
28619   e2 = gen_reg_rtx (mode);
28620   e3 = gen_reg_rtx (mode);
28621
28622   real_from_integer (&r, VOIDmode, -3, -1, 0);
28623   mthree = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
28624
28625   real_arithmetic (&r, NEGATE_EXPR, &dconsthalf, NULL);
28626   mhalf = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
28627
28628   if (VECTOR_MODE_P (mode))
28629     {
28630       mthree = ix86_build_const_vector (SFmode, true, mthree);
28631       mhalf = ix86_build_const_vector (SFmode, true, mhalf);
28632     }
28633
28634   /* sqrt(a)  = -0.5 * a * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0)
28635      rsqrt(a) = -0.5     * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0) */
28636
28637   /* x0 = rsqrt(a) estimate */
28638   emit_insn (gen_rtx_SET (VOIDmode, x0,
28639                           gen_rtx_UNSPEC (mode, gen_rtvec (1, a),
28640                                           UNSPEC_RSQRT)));
28641
28642   /* If (a == 0.0) Filter out infinity to prevent NaN for sqrt(0.0).  */
28643   if (!recip)
28644     {
28645       rtx zero, mask;
28646
28647       zero = gen_reg_rtx (mode);
28648       mask = gen_reg_rtx (mode);
28649
28650       zero = force_reg (mode, CONST0_RTX(mode));
28651       emit_insn (gen_rtx_SET (VOIDmode, mask,
28652                               gen_rtx_NE (mode, zero, a)));
28653
28654       emit_insn (gen_rtx_SET (VOIDmode, x0,
28655                               gen_rtx_AND (mode, x0, mask)));
28656     }
28657
28658   /* e0 = x0 * a */
28659   emit_insn (gen_rtx_SET (VOIDmode, e0,
28660                           gen_rtx_MULT (mode, x0, a)));
28661   /* e1 = e0 * x0 */
28662   emit_insn (gen_rtx_SET (VOIDmode, e1,
28663                           gen_rtx_MULT (mode, e0, x0)));
28664
28665   /* e2 = e1 - 3. */
28666   mthree = force_reg (mode, mthree);
28667   emit_insn (gen_rtx_SET (VOIDmode, e2,
28668                           gen_rtx_PLUS (mode, e1, mthree)));
28669
28670   mhalf = force_reg (mode, mhalf);
28671   if (recip)
28672     /* e3 = -.5 * x0 */
28673     emit_insn (gen_rtx_SET (VOIDmode, e3,
28674                             gen_rtx_MULT (mode, x0, mhalf)));
28675   else
28676     /* e3 = -.5 * e0 */
28677     emit_insn (gen_rtx_SET (VOIDmode, e3,
28678                             gen_rtx_MULT (mode, e0, mhalf)));
28679   /* ret = e2 * e3 */
28680   emit_insn (gen_rtx_SET (VOIDmode, res,
28681                           gen_rtx_MULT (mode, e2, e3)));
28682 }
28683
28684 /* Solaris implementation of TARGET_ASM_NAMED_SECTION.  */
28685
28686 static void ATTRIBUTE_UNUSED
28687 i386_solaris_elf_named_section (const char *name, unsigned int flags,
28688                                 tree decl)
28689 {
28690   /* With Binutils 2.15, the "@unwind" marker must be specified on
28691      every occurrence of the ".eh_frame" section, not just the first
28692      one.  */
28693   if (TARGET_64BIT
28694       && strcmp (name, ".eh_frame") == 0)
28695     {
28696       fprintf (asm_out_file, "\t.section\t%s,\"%s\",@unwind\n", name,
28697                flags & SECTION_WRITE ? "aw" : "a");
28698       return;
28699     }
28700   default_elf_asm_named_section (name, flags, decl);
28701 }
28702
28703 /* Return the mangling of TYPE if it is an extended fundamental type.  */
28704
28705 static const char *
28706 ix86_mangle_type (const_tree type)
28707 {
28708   type = TYPE_MAIN_VARIANT (type);
28709
28710   if (TREE_CODE (type) != VOID_TYPE && TREE_CODE (type) != BOOLEAN_TYPE
28711       && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
28712     return NULL;
28713
28714   switch (TYPE_MODE (type))
28715     {
28716     case TFmode:
28717       /* __float128 is "g".  */
28718       return "g";
28719     case XFmode:
28720       /* "long double" or __float80 is "e".  */
28721       return "e";
28722     default:
28723       return NULL;
28724     }
28725 }
28726
28727 /* For 32-bit code we can save PIC register setup by using
28728    __stack_chk_fail_local hidden function instead of calling
28729    __stack_chk_fail directly.  64-bit code doesn't need to setup any PIC
28730    register, so it is better to call __stack_chk_fail directly.  */
28731
28732 static tree
28733 ix86_stack_protect_fail (void)
28734 {
28735 #if 0 /* XXX swildner */
28736   return TARGET_64BIT
28737          ? default_external_stack_protect_fail ()
28738          : default_hidden_stack_protect_fail ();
28739 #else
28740   return default_external_stack_protect_fail ();
28741 #endif
28742 }
28743
28744 /* Select a format to encode pointers in exception handling data.  CODE
28745    is 0 for data, 1 for code labels, 2 for function pointers.  GLOBAL is
28746    true if the symbol may be affected by dynamic relocations.
28747
28748    ??? All x86 object file formats are capable of representing this.
28749    After all, the relocation needed is the same as for the call insn.
28750    Whether or not a particular assembler allows us to enter such, I
28751    guess we'll have to see.  */
28752 int
28753 asm_preferred_eh_data_format (int code, int global)
28754 {
28755   if (flag_pic)
28756     {
28757       int type = DW_EH_PE_sdata8;
28758       if (!TARGET_64BIT
28759           || ix86_cmodel == CM_SMALL_PIC
28760           || (ix86_cmodel == CM_MEDIUM_PIC && (global || code)))
28761         type = DW_EH_PE_sdata4;
28762       return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type;
28763     }
28764   if (ix86_cmodel == CM_SMALL
28765       || (ix86_cmodel == CM_MEDIUM && code))
28766     return DW_EH_PE_udata4;
28767   return DW_EH_PE_absptr;
28768 }
28769 \f
28770 /* Expand copysign from SIGN to the positive value ABS_VALUE
28771    storing in RESULT.  If MASK is non-null, it shall be a mask to mask out
28772    the sign-bit.  */
28773 static void
28774 ix86_sse_copysign_to_positive (rtx result, rtx abs_value, rtx sign, rtx mask)
28775 {
28776   enum machine_mode mode = GET_MODE (sign);
28777   rtx sgn = gen_reg_rtx (mode);
28778   if (mask == NULL_RTX)
28779     {
28780       mask = ix86_build_signbit_mask (mode, VECTOR_MODE_P (mode), false);
28781       if (!VECTOR_MODE_P (mode))
28782         {
28783           /* We need to generate a scalar mode mask in this case.  */
28784           rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
28785           tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
28786           mask = gen_reg_rtx (mode);
28787           emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
28788         }
28789     }
28790   else
28791     mask = gen_rtx_NOT (mode, mask);
28792   emit_insn (gen_rtx_SET (VOIDmode, sgn,
28793                           gen_rtx_AND (mode, mask, sign)));
28794   emit_insn (gen_rtx_SET (VOIDmode, result,
28795                           gen_rtx_IOR (mode, abs_value, sgn)));
28796 }
28797
28798 /* Expand fabs (OP0) and return a new rtx that holds the result.  The
28799    mask for masking out the sign-bit is stored in *SMASK, if that is
28800    non-null.  */
28801 static rtx
28802 ix86_expand_sse_fabs (rtx op0, rtx *smask)
28803 {
28804   enum machine_mode mode = GET_MODE (op0);
28805   rtx xa, mask;
28806
28807   xa = gen_reg_rtx (mode);
28808   mask = ix86_build_signbit_mask (mode, VECTOR_MODE_P (mode), true);
28809   if (!VECTOR_MODE_P (mode))
28810     {
28811       /* We need to generate a scalar mode mask in this case.  */
28812       rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
28813       tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
28814       mask = gen_reg_rtx (mode);
28815       emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
28816     }
28817   emit_insn (gen_rtx_SET (VOIDmode, xa,
28818                           gen_rtx_AND (mode, op0, mask)));
28819
28820   if (smask)
28821     *smask = mask;
28822
28823   return xa;
28824 }
28825
28826 /* Expands a comparison of OP0 with OP1 using comparison code CODE,
28827    swapping the operands if SWAP_OPERANDS is true.  The expanded
28828    code is a forward jump to a newly created label in case the
28829    comparison is true.  The generated label rtx is returned.  */
28830 static rtx
28831 ix86_expand_sse_compare_and_jump (enum rtx_code code, rtx op0, rtx op1,
28832                                   bool swap_operands)
28833 {
28834   rtx label, tmp;
28835
28836   if (swap_operands)
28837     {
28838       tmp = op0;
28839       op0 = op1;
28840       op1 = tmp;
28841     }
28842
28843   label = gen_label_rtx ();
28844   tmp = gen_rtx_REG (CCFPUmode, FLAGS_REG);
28845   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28846                           gen_rtx_COMPARE (CCFPUmode, op0, op1)));
28847   tmp = gen_rtx_fmt_ee (code, VOIDmode, tmp, const0_rtx);
28848   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
28849                               gen_rtx_LABEL_REF (VOIDmode, label), pc_rtx);
28850   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
28851   JUMP_LABEL (tmp) = label;
28852
28853   return label;
28854 }
28855
28856 /* Expand a mask generating SSE comparison instruction comparing OP0 with OP1
28857    using comparison code CODE.  Operands are swapped for the comparison if
28858    SWAP_OPERANDS is true.  Returns a rtx for the generated mask.  */
28859 static rtx
28860 ix86_expand_sse_compare_mask (enum rtx_code code, rtx op0, rtx op1,
28861                               bool swap_operands)
28862 {
28863   enum machine_mode mode = GET_MODE (op0);
28864   rtx mask = gen_reg_rtx (mode);
28865
28866   if (swap_operands)
28867     {
28868       rtx tmp = op0;
28869       op0 = op1;
28870       op1 = tmp;
28871     }
28872
28873   if (mode == DFmode)
28874     emit_insn (gen_sse2_maskcmpdf3 (mask, op0, op1,
28875                                     gen_rtx_fmt_ee (code, mode, op0, op1)));
28876   else
28877     emit_insn (gen_sse_maskcmpsf3 (mask, op0, op1,
28878                                    gen_rtx_fmt_ee (code, mode, op0, op1)));
28879
28880   return mask;
28881 }
28882
28883 /* Generate and return a rtx of mode MODE for 2**n where n is the number
28884    of bits of the mantissa of MODE, which must be one of DFmode or SFmode.  */
28885 static rtx
28886 ix86_gen_TWO52 (enum machine_mode mode)
28887 {
28888   REAL_VALUE_TYPE TWO52r;
28889   rtx TWO52;
28890
28891   real_ldexp (&TWO52r, &dconst1, mode == DFmode ? 52 : 23);
28892   TWO52 = const_double_from_real_value (TWO52r, mode);
28893   TWO52 = force_reg (mode, TWO52);
28894
28895   return TWO52;
28896 }
28897
28898 /* Expand SSE sequence for computing lround from OP1 storing
28899    into OP0.  */
28900 void
28901 ix86_expand_lround (rtx op0, rtx op1)
28902 {
28903   /* C code for the stuff we're doing below:
28904        tmp = op1 + copysign (nextafter (0.5, 0.0), op1)
28905        return (long)tmp;
28906    */
28907   enum machine_mode mode = GET_MODE (op1);
28908   const struct real_format *fmt;
28909   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
28910   rtx adj;
28911
28912   /* load nextafter (0.5, 0.0) */
28913   fmt = REAL_MODE_FORMAT (mode);
28914   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
28915   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
28916
28917   /* adj = copysign (0.5, op1) */
28918   adj = force_reg (mode, const_double_from_real_value (pred_half, mode));
28919   ix86_sse_copysign_to_positive (adj, adj, force_reg (mode, op1), NULL_RTX);
28920
28921   /* adj = op1 + adj */
28922   adj = expand_simple_binop (mode, PLUS, adj, op1, NULL_RTX, 0, OPTAB_DIRECT);
28923
28924   /* op0 = (imode)adj */
28925   expand_fix (op0, adj, 0);
28926 }
28927
28928 /* Expand SSE2 sequence for computing lround from OPERAND1 storing
28929    into OPERAND0.  */
28930 void
28931 ix86_expand_lfloorceil (rtx op0, rtx op1, bool do_floor)
28932 {
28933   /* C code for the stuff we're doing below (for do_floor):
28934         xi = (long)op1;
28935         xi -= (double)xi > op1 ? 1 : 0;
28936         return xi;
28937    */
28938   enum machine_mode fmode = GET_MODE (op1);
28939   enum machine_mode imode = GET_MODE (op0);
28940   rtx ireg, freg, label, tmp;
28941
28942   /* reg = (long)op1 */
28943   ireg = gen_reg_rtx (imode);
28944   expand_fix (ireg, op1, 0);
28945
28946   /* freg = (double)reg */
28947   freg = gen_reg_rtx (fmode);
28948   expand_float (freg, ireg, 0);
28949
28950   /* ireg = (freg > op1) ? ireg - 1 : ireg */
28951   label = ix86_expand_sse_compare_and_jump (UNLE,
28952                                             freg, op1, !do_floor);
28953   tmp = expand_simple_binop (imode, do_floor ? MINUS : PLUS,
28954                              ireg, const1_rtx, NULL_RTX, 0, OPTAB_DIRECT);
28955   emit_move_insn (ireg, tmp);
28956
28957   emit_label (label);
28958   LABEL_NUSES (label) = 1;
28959
28960   emit_move_insn (op0, ireg);
28961 }
28962
28963 /* Expand rint (IEEE round to nearest) rounding OPERAND1 and storing the
28964    result in OPERAND0.  */
28965 void
28966 ix86_expand_rint (rtx operand0, rtx operand1)
28967 {
28968   /* C code for the stuff we're doing below:
28969         xa = fabs (operand1);
28970         if (!isless (xa, 2**52))
28971           return operand1;
28972         xa = xa + 2**52 - 2**52;
28973         return copysign (xa, operand1);
28974    */
28975   enum machine_mode mode = GET_MODE (operand0);
28976   rtx res, xa, label, TWO52, mask;
28977
28978   res = gen_reg_rtx (mode);
28979   emit_move_insn (res, operand1);
28980
28981   /* xa = abs (operand1) */
28982   xa = ix86_expand_sse_fabs (res, &mask);
28983
28984   /* if (!isless (xa, TWO52)) goto label; */
28985   TWO52 = ix86_gen_TWO52 (mode);
28986   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28987
28988   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
28989   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
28990
28991   ix86_sse_copysign_to_positive (res, xa, res, mask);
28992
28993   emit_label (label);
28994   LABEL_NUSES (label) = 1;
28995
28996   emit_move_insn (operand0, res);
28997 }
28998
28999 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
29000    into OPERAND0.  */
29001 void
29002 ix86_expand_floorceildf_32 (rtx operand0, rtx operand1, bool do_floor)
29003 {
29004   /* C code for the stuff we expand below.
29005         double xa = fabs (x), x2;
29006         if (!isless (xa, TWO52))
29007           return x;
29008         xa = xa + TWO52 - TWO52;
29009         x2 = copysign (xa, x);
29010      Compensate.  Floor:
29011         if (x2 > x)
29012           x2 -= 1;
29013      Compensate.  Ceil:
29014         if (x2 < x)
29015           x2 -= -1;
29016         return x2;
29017    */
29018   enum machine_mode mode = GET_MODE (operand0);
29019   rtx xa, TWO52, tmp, label, one, res, mask;
29020
29021   TWO52 = ix86_gen_TWO52 (mode);
29022
29023   /* Temporary for holding the result, initialized to the input
29024      operand to ease control flow.  */
29025   res = gen_reg_rtx (mode);
29026   emit_move_insn (res, operand1);
29027
29028   /* xa = abs (operand1) */
29029   xa = ix86_expand_sse_fabs (res, &mask);
29030
29031   /* if (!isless (xa, TWO52)) goto label; */
29032   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
29033
29034   /* xa = xa + TWO52 - TWO52; */
29035   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
29036   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
29037
29038   /* xa = copysign (xa, operand1) */
29039   ix86_sse_copysign_to_positive (xa, xa, res, mask);
29040
29041   /* generate 1.0 or -1.0 */
29042   one = force_reg (mode,
29043                    const_double_from_real_value (do_floor
29044                                                  ? dconst1 : dconstm1, mode));
29045
29046   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
29047   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
29048   emit_insn (gen_rtx_SET (VOIDmode, tmp,
29049                           gen_rtx_AND (mode, one, tmp)));
29050   /* We always need to subtract here to preserve signed zero.  */
29051   tmp = expand_simple_binop (mode, MINUS,
29052                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
29053   emit_move_insn (res, tmp);
29054
29055   emit_label (label);
29056   LABEL_NUSES (label) = 1;
29057
29058   emit_move_insn (operand0, res);
29059 }
29060
29061 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
29062    into OPERAND0.  */
29063 void
29064 ix86_expand_floorceil (rtx operand0, rtx operand1, bool do_floor)
29065 {
29066   /* C code for the stuff we expand below.
29067         double xa = fabs (x), x2;
29068         if (!isless (xa, TWO52))
29069           return x;
29070         x2 = (double)(long)x;
29071      Compensate.  Floor:
29072         if (x2 > x)
29073           x2 -= 1;
29074      Compensate.  Ceil:
29075         if (x2 < x)
29076           x2 += 1;
29077         if (HONOR_SIGNED_ZEROS (mode))
29078           return copysign (x2, x);
29079         return x2;
29080    */
29081   enum machine_mode mode = GET_MODE (operand0);
29082   rtx xa, xi, TWO52, tmp, label, one, res, mask;
29083
29084   TWO52 = ix86_gen_TWO52 (mode);
29085
29086   /* Temporary for holding the result, initialized to the input
29087      operand to ease control flow.  */
29088   res = gen_reg_rtx (mode);
29089   emit_move_insn (res, operand1);
29090
29091   /* xa = abs (operand1) */
29092   xa = ix86_expand_sse_fabs (res, &mask);
29093
29094   /* if (!isless (xa, TWO52)) goto label; */
29095   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
29096
29097   /* xa = (double)(long)x */
29098   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
29099   expand_fix (xi, res, 0);
29100   expand_float (xa, xi, 0);
29101
29102   /* generate 1.0 */
29103   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
29104
29105   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
29106   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
29107   emit_insn (gen_rtx_SET (VOIDmode, tmp,
29108                           gen_rtx_AND (mode, one, tmp)));
29109   tmp = expand_simple_binop (mode, do_floor ? MINUS : PLUS,
29110                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
29111   emit_move_insn (res, tmp);
29112
29113   if (HONOR_SIGNED_ZEROS (mode))
29114     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
29115
29116   emit_label (label);
29117   LABEL_NUSES (label) = 1;
29118
29119   emit_move_insn (operand0, res);
29120 }
29121
29122 /* Expand SSE sequence for computing round from OPERAND1 storing
29123    into OPERAND0.  Sequence that works without relying on DImode truncation
29124    via cvttsd2siq that is only available on 64bit targets.  */
29125 void
29126 ix86_expand_rounddf_32 (rtx operand0, rtx operand1)
29127 {
29128   /* C code for the stuff we expand below.
29129         double xa = fabs (x), xa2, x2;
29130         if (!isless (xa, TWO52))
29131           return x;
29132      Using the absolute value and copying back sign makes
29133      -0.0 -> -0.0 correct.
29134         xa2 = xa + TWO52 - TWO52;
29135      Compensate.
29136         dxa = xa2 - xa;
29137         if (dxa <= -0.5)
29138           xa2 += 1;
29139         else if (dxa > 0.5)
29140           xa2 -= 1;
29141         x2 = copysign (xa2, x);
29142         return x2;
29143    */
29144   enum machine_mode mode = GET_MODE (operand0);
29145   rtx xa, xa2, dxa, TWO52, tmp, label, half, mhalf, one, res, mask;
29146
29147   TWO52 = ix86_gen_TWO52 (mode);
29148
29149   /* Temporary for holding the result, initialized to the input
29150      operand to ease control flow.  */
29151   res = gen_reg_rtx (mode);
29152   emit_move_insn (res, operand1);
29153
29154   /* xa = abs (operand1) */
29155   xa = ix86_expand_sse_fabs (res, &mask);
29156
29157   /* if (!isless (xa, TWO52)) goto label; */
29158   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
29159
29160   /* xa2 = xa + TWO52 - TWO52; */
29161   xa2 = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
29162   xa2 = expand_simple_binop (mode, MINUS, xa2, TWO52, xa2, 0, OPTAB_DIRECT);
29163
29164   /* dxa = xa2 - xa; */
29165   dxa = expand_simple_binop (mode, MINUS, xa2, xa, NULL_RTX, 0, OPTAB_DIRECT);
29166
29167   /* generate 0.5, 1.0 and -0.5 */
29168   half = force_reg (mode, const_double_from_real_value (dconsthalf, mode));
29169   one = expand_simple_binop (mode, PLUS, half, half, NULL_RTX, 0, OPTAB_DIRECT);
29170   mhalf = expand_simple_binop (mode, MINUS, half, one, NULL_RTX,
29171                                0, OPTAB_DIRECT);
29172
29173   /* Compensate.  */
29174   tmp = gen_reg_rtx (mode);
29175   /* xa2 = xa2 - (dxa > 0.5 ? 1 : 0) */
29176   tmp = ix86_expand_sse_compare_mask (UNGT, dxa, half, false);
29177   emit_insn (gen_rtx_SET (VOIDmode, tmp,
29178                           gen_rtx_AND (mode, one, tmp)));
29179   xa2 = expand_simple_binop (mode, MINUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
29180   /* xa2 = xa2 + (dxa <= -0.5 ? 1 : 0) */
29181   tmp = ix86_expand_sse_compare_mask (UNGE, mhalf, dxa, false);
29182   emit_insn (gen_rtx_SET (VOIDmode, tmp,
29183                           gen_rtx_AND (mode, one, tmp)));
29184   xa2 = expand_simple_binop (mode, PLUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
29185
29186   /* res = copysign (xa2, operand1) */
29187   ix86_sse_copysign_to_positive (res, xa2, force_reg (mode, operand1), mask);
29188
29189   emit_label (label);
29190   LABEL_NUSES (label) = 1;
29191
29192   emit_move_insn (operand0, res);
29193 }
29194
29195 /* Expand SSE sequence for computing trunc from OPERAND1 storing
29196    into OPERAND0.  */
29197 void
29198 ix86_expand_trunc (rtx operand0, rtx operand1)
29199 {
29200   /* C code for SSE variant we expand below.
29201         double xa = fabs (x), x2;
29202         if (!isless (xa, TWO52))
29203           return x;
29204         x2 = (double)(long)x;
29205         if (HONOR_SIGNED_ZEROS (mode))
29206           return copysign (x2, x);
29207         return x2;
29208    */
29209   enum machine_mode mode = GET_MODE (operand0);
29210   rtx xa, xi, TWO52, label, res, mask;
29211
29212   TWO52 = ix86_gen_TWO52 (mode);
29213
29214   /* Temporary for holding the result, initialized to the input
29215      operand to ease control flow.  */
29216   res = gen_reg_rtx (mode);
29217   emit_move_insn (res, operand1);
29218
29219   /* xa = abs (operand1) */
29220   xa = ix86_expand_sse_fabs (res, &mask);
29221
29222   /* if (!isless (xa, TWO52)) goto label; */
29223   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
29224
29225   /* x = (double)(long)x */
29226   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
29227   expand_fix (xi, res, 0);
29228   expand_float (res, xi, 0);
29229
29230   if (HONOR_SIGNED_ZEROS (mode))
29231     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
29232
29233   emit_label (label);
29234   LABEL_NUSES (label) = 1;
29235
29236   emit_move_insn (operand0, res);
29237 }
29238
29239 /* Expand SSE sequence for computing trunc from OPERAND1 storing
29240    into OPERAND0.  */
29241 void
29242 ix86_expand_truncdf_32 (rtx operand0, rtx operand1)
29243 {
29244   enum machine_mode mode = GET_MODE (operand0);
29245   rtx xa, mask, TWO52, label, one, res, smask, tmp;
29246
29247   /* C code for SSE variant we expand below.
29248         double xa = fabs (x), x2;
29249         if (!isless (xa, TWO52))
29250           return x;
29251         xa2 = xa + TWO52 - TWO52;
29252      Compensate:
29253         if (xa2 > xa)
29254           xa2 -= 1.0;
29255         x2 = copysign (xa2, x);
29256         return x2;
29257    */
29258
29259   TWO52 = ix86_gen_TWO52 (mode);
29260
29261   /* Temporary for holding the result, initialized to the input
29262      operand to ease control flow.  */
29263   res = gen_reg_rtx (mode);
29264   emit_move_insn (res, operand1);
29265
29266   /* xa = abs (operand1) */
29267   xa = ix86_expand_sse_fabs (res, &smask);
29268
29269   /* if (!isless (xa, TWO52)) goto label; */
29270   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
29271
29272   /* res = xa + TWO52 - TWO52; */
29273   tmp = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
29274   tmp = expand_simple_binop (mode, MINUS, tmp, TWO52, tmp, 0, OPTAB_DIRECT);
29275   emit_move_insn (res, tmp);
29276
29277   /* generate 1.0 */
29278   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
29279
29280   /* Compensate: res = xa2 - (res > xa ? 1 : 0)  */
29281   mask = ix86_expand_sse_compare_mask (UNGT, res, xa, false);
29282   emit_insn (gen_rtx_SET (VOIDmode, mask,
29283                           gen_rtx_AND (mode, mask, one)));
29284   tmp = expand_simple_binop (mode, MINUS,
29285                              res, mask, NULL_RTX, 0, OPTAB_DIRECT);
29286   emit_move_insn (res, tmp);
29287
29288   /* res = copysign (res, operand1) */
29289   ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), smask);
29290
29291   emit_label (label);
29292   LABEL_NUSES (label) = 1;
29293
29294   emit_move_insn (operand0, res);
29295 }
29296
29297 /* Expand SSE sequence for computing round from OPERAND1 storing
29298    into OPERAND0.  */
29299 void
29300 ix86_expand_round (rtx operand0, rtx operand1)
29301 {
29302   /* C code for the stuff we're doing below:
29303         double xa = fabs (x);
29304         if (!isless (xa, TWO52))
29305           return x;
29306         xa = (double)(long)(xa + nextafter (0.5, 0.0));
29307         return copysign (xa, x);
29308    */
29309   enum machine_mode mode = GET_MODE (operand0);
29310   rtx res, TWO52, xa, label, xi, half, mask;
29311   const struct real_format *fmt;
29312   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
29313
29314   /* Temporary for holding the result, initialized to the input
29315      operand to ease control flow.  */
29316   res = gen_reg_rtx (mode);
29317   emit_move_insn (res, operand1);
29318
29319   TWO52 = ix86_gen_TWO52 (mode);
29320   xa = ix86_expand_sse_fabs (res, &mask);
29321   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
29322
29323   /* load nextafter (0.5, 0.0) */
29324   fmt = REAL_MODE_FORMAT (mode);
29325   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
29326   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
29327
29328   /* xa = xa + 0.5 */
29329   half = force_reg (mode, const_double_from_real_value (pred_half, mode));
29330   xa = expand_simple_binop (mode, PLUS, xa, half, NULL_RTX, 0, OPTAB_DIRECT);
29331
29332   /* xa = (double)(int64_t)xa */
29333   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
29334   expand_fix (xi, xa, 0);
29335   expand_float (xa, xi, 0);
29336
29337   /* res = copysign (xa, operand1) */
29338   ix86_sse_copysign_to_positive (res, xa, force_reg (mode, operand1), mask);
29339
29340   emit_label (label);
29341   LABEL_NUSES (label) = 1;
29342
29343   emit_move_insn (operand0, res);
29344 }
29345
29346 \f
29347 /* Validate whether a SSE5 instruction is valid or not.
29348    OPERANDS is the array of operands.
29349    NUM is the number of operands.
29350    USES_OC0 is true if the instruction uses OC0 and provides 4 variants.
29351    NUM_MEMORY is the maximum number of memory operands to accept.  
29352    when COMMUTATIVE is set, operand 1 and 2 can be swapped.  */
29353
29354 bool
29355 ix86_sse5_valid_op_p (rtx operands[], rtx insn ATTRIBUTE_UNUSED, int num,
29356                       bool uses_oc0, int num_memory, bool commutative)
29357 {
29358   int mem_mask;
29359   int mem_count;
29360   int i;
29361
29362   /* Count the number of memory arguments */
29363   mem_mask = 0;
29364   mem_count = 0;
29365   for (i = 0; i < num; i++)
29366     {
29367       enum machine_mode mode = GET_MODE (operands[i]);
29368       if (register_operand (operands[i], mode))
29369         ;
29370
29371       else if (memory_operand (operands[i], mode))
29372         {
29373           mem_mask |= (1 << i);
29374           mem_count++;
29375         }
29376
29377       else
29378         {
29379           rtx pattern = PATTERN (insn);
29380
29381           /* allow 0 for pcmov */
29382           if (GET_CODE (pattern) != SET
29383               || GET_CODE (SET_SRC (pattern)) != IF_THEN_ELSE
29384               || i < 2
29385               || operands[i] != CONST0_RTX (mode))
29386             return false;
29387         }
29388     }
29389
29390   /* Special case pmacsdq{l,h} where we allow the 3rd argument to be
29391      a memory operation.  */
29392   if (num_memory < 0)
29393     {
29394       num_memory = -num_memory;
29395       if ((mem_mask & (1 << (num-1))) != 0)
29396         {
29397           mem_mask &= ~(1 << (num-1));
29398           mem_count--;
29399         }
29400     }
29401
29402   /* If there were no memory operations, allow the insn */
29403   if (mem_mask == 0)
29404     return true;
29405
29406   /* Do not allow the destination register to be a memory operand.  */
29407   else if (mem_mask & (1 << 0))
29408     return false;
29409
29410   /* If there are too many memory operations, disallow the instruction.  While
29411      the hardware only allows 1 memory reference, before register allocation
29412      for some insns, we allow two memory operations sometimes in order to allow
29413      code like the following to be optimized:
29414
29415         float fmadd (float *a, float *b, float *c) { return (*a * *b) + *c; }
29416
29417     or similar cases that are vectorized into using the fmaddss
29418     instruction.  */
29419   else if (mem_count > num_memory)
29420     return false;
29421
29422   /* Don't allow more than one memory operation if not optimizing.  */
29423   else if (mem_count > 1 && !optimize)
29424     return false;
29425
29426   else if (num == 4 && mem_count == 1)
29427     {
29428       /* formats (destination is the first argument), example fmaddss:
29429          xmm1, xmm1, xmm2, xmm3/mem
29430          xmm1, xmm1, xmm2/mem, xmm3
29431          xmm1, xmm2, xmm3/mem, xmm1
29432          xmm1, xmm2/mem, xmm3, xmm1 */
29433       if (uses_oc0)
29434         return ((mem_mask == (1 << 1))
29435                 || (mem_mask == (1 << 2))
29436                 || (mem_mask == (1 << 3)));
29437
29438       /* format, example pmacsdd:
29439          xmm1, xmm2, xmm3/mem, xmm1 */
29440       if (commutative)
29441         return (mem_mask == (1 << 2) || mem_mask == (1 << 1));
29442       else
29443         return (mem_mask == (1 << 2));
29444     }
29445
29446   else if (num == 4 && num_memory == 2)
29447     {
29448       /* If there are two memory operations, we can load one of the memory ops
29449          into the destination register.  This is for optimizing the
29450          multiply/add ops, which the combiner has optimized both the multiply
29451          and the add insns to have a memory operation.  We have to be careful
29452          that the destination doesn't overlap with the inputs.  */
29453       rtx op0 = operands[0];
29454
29455       if (reg_mentioned_p (op0, operands[1])
29456           || reg_mentioned_p (op0, operands[2])
29457           || reg_mentioned_p (op0, operands[3]))
29458         return false;
29459
29460       /* formats (destination is the first argument), example fmaddss:
29461          xmm1, xmm1, xmm2, xmm3/mem
29462          xmm1, xmm1, xmm2/mem, xmm3
29463          xmm1, xmm2, xmm3/mem, xmm1
29464          xmm1, xmm2/mem, xmm3, xmm1
29465
29466          For the oc0 case, we will load either operands[1] or operands[3] into
29467          operands[0], so any combination of 2 memory operands is ok.  */
29468       if (uses_oc0)
29469         return true;
29470
29471       /* format, example pmacsdd:
29472          xmm1, xmm2, xmm3/mem, xmm1
29473
29474          For the integer multiply/add instructions be more restrictive and
29475          require operands[2] and operands[3] to be the memory operands.  */
29476       if (commutative)
29477         return (mem_mask == ((1 << 1) | (1 << 3)) ||
29478                 mem_mask == ((1 << 2) | (1 << 3)));
29479       else
29480         return (mem_mask == ((1 << 2) | (1 << 3)));
29481     }
29482
29483   else if (num == 3 && num_memory == 1)
29484     {
29485       /* formats, example protb:
29486          xmm1, xmm2, xmm3/mem
29487          xmm1, xmm2/mem, xmm3 */
29488       if (uses_oc0)
29489         return ((mem_mask == (1 << 1)) || (mem_mask == (1 << 2)));
29490
29491       /* format, example comeq:
29492          xmm1, xmm2, xmm3/mem */
29493       else
29494         return (mem_mask == (1 << 2));
29495     }
29496
29497   else
29498     gcc_unreachable ();
29499
29500   return false;
29501 }
29502
29503 \f
29504 /* Fixup an SSE5 instruction that has 2 memory input references into a form the
29505    hardware will allow by using the destination register to load one of the
29506    memory operations.  Presently this is used by the multiply/add routines to
29507    allow 2 memory references.  */
29508
29509 void
29510 ix86_expand_sse5_multiple_memory (rtx operands[],
29511                                   int num,
29512                                   enum machine_mode mode)
29513 {
29514   rtx op0 = operands[0];
29515   if (num != 4
29516       || memory_operand (op0, mode)
29517       || reg_mentioned_p (op0, operands[1])
29518       || reg_mentioned_p (op0, operands[2])
29519       || reg_mentioned_p (op0, operands[3]))
29520     gcc_unreachable ();
29521
29522   /* For 2 memory operands, pick either operands[1] or operands[3] to move into
29523      the destination register.  */
29524   if (memory_operand (operands[1], mode))
29525     {
29526       emit_move_insn (op0, operands[1]);
29527       operands[1] = op0;
29528     }
29529   else if (memory_operand (operands[3], mode))
29530     {
29531       emit_move_insn (op0, operands[3]);
29532       operands[3] = op0;
29533     }
29534   else
29535     gcc_unreachable ();
29536
29537   return;
29538 }
29539
29540 \f
29541 /* Table of valid machine attributes.  */
29542 static const struct attribute_spec ix86_attribute_table[] =
29543 {
29544   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
29545   /* Stdcall attribute says callee is responsible for popping arguments
29546      if they are not variable.  */
29547   { "stdcall",   0, 0, false, true,  true,  ix86_handle_cconv_attribute },
29548   /* Fastcall attribute says callee is responsible for popping arguments
29549      if they are not variable.  */
29550   { "fastcall",  0, 0, false, true,  true,  ix86_handle_cconv_attribute },
29551   /* Cdecl attribute says the callee is a normal C declaration */
29552   { "cdecl",     0, 0, false, true,  true,  ix86_handle_cconv_attribute },
29553   /* Regparm attribute specifies how many integer arguments are to be
29554      passed in registers.  */
29555   { "regparm",   1, 1, false, true,  true,  ix86_handle_cconv_attribute },
29556   /* Sseregparm attribute says we are using x86_64 calling conventions
29557      for FP arguments.  */
29558   { "sseregparm", 0, 0, false, true, true, ix86_handle_cconv_attribute },
29559   /* force_align_arg_pointer says this function realigns the stack at entry.  */
29560   { (const char *)&ix86_force_align_arg_pointer_string, 0, 0,
29561     false, true,  true, ix86_handle_cconv_attribute },
29562 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
29563   { "dllimport", 0, 0, false, false, false, handle_dll_attribute },
29564   { "dllexport", 0, 0, false, false, false, handle_dll_attribute },
29565   { "shared",    0, 0, true,  false, false, ix86_handle_shared_attribute },
29566 #endif
29567   { "ms_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute },
29568   { "gcc_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute },
29569 #ifdef SUBTARGET_ATTRIBUTE_TABLE
29570   SUBTARGET_ATTRIBUTE_TABLE,
29571 #endif
29572   /* ms_abi and sysv_abi calling convention function attributes.  */
29573   { "ms_abi", 0, 0, false, true, true, ix86_handle_abi_attribute },
29574   { "sysv_abi", 0, 0, false, true, true, ix86_handle_abi_attribute },
29575   /* End element.  */
29576   { NULL,        0, 0, false, false, false, NULL }
29577 };
29578
29579 /* Implement targetm.vectorize.builtin_vectorization_cost.  */
29580 static int
29581 x86_builtin_vectorization_cost (bool runtime_test)
29582 {
29583   /* If the branch of the runtime test is taken - i.e. - the vectorized
29584      version is skipped - this incurs a misprediction cost (because the
29585      vectorized version is expected to be the fall-through).  So we subtract
29586      the latency of a mispredicted branch from the costs that are incured
29587      when the vectorized version is executed.
29588
29589      TODO: The values in individual target tables have to be tuned or new
29590      fields may be needed. For eg. on K8, the default branch path is the
29591      not-taken path. If the taken path is predicted correctly, the minimum
29592      penalty of going down the taken-path is 1 cycle. If the taken-path is
29593      not predicted correctly, then the minimum penalty is 10 cycles.  */
29594
29595   if (runtime_test)
29596     {
29597       return (-(ix86_cost->cond_taken_branch_cost));
29598     }
29599   else
29600     return 0;
29601 }
29602
29603 /* This function returns the calling abi specific va_list type node.
29604    It returns  the FNDECL specific va_list type.  */
29605
29606 tree
29607 ix86_fn_abi_va_list (tree fndecl)
29608 {
29609   int abi;
29610
29611   if (!TARGET_64BIT)
29612     return va_list_type_node;
29613   gcc_assert (fndecl != NULL_TREE);
29614   abi = ix86_function_abi ((const_tree) fndecl);
29615
29616   if (abi == MS_ABI)
29617     return ms_va_list_type_node;
29618   else
29619     return sysv_va_list_type_node;
29620 }
29621
29622 /* Returns the canonical va_list type specified by TYPE. If there
29623    is no valid TYPE provided, it return NULL_TREE.  */
29624
29625 tree
29626 ix86_canonical_va_list_type (tree type)
29627 {
29628   tree wtype, htype;
29629
29630   /* Resolve references and pointers to va_list type.  */
29631   if (INDIRECT_REF_P (type))
29632     type = TREE_TYPE (type);
29633   else if (POINTER_TYPE_P (type) && POINTER_TYPE_P (TREE_TYPE(type)))
29634     type = TREE_TYPE (type);
29635
29636   if (TARGET_64BIT)
29637     {
29638       wtype = va_list_type_node;
29639           gcc_assert (wtype != NULL_TREE);
29640       htype = type;
29641       if (TREE_CODE (wtype) == ARRAY_TYPE)
29642         {
29643           /* If va_list is an array type, the argument may have decayed
29644              to a pointer type, e.g. by being passed to another function.
29645              In that case, unwrap both types so that we can compare the
29646              underlying records.  */
29647           if (TREE_CODE (htype) == ARRAY_TYPE
29648               || POINTER_TYPE_P (htype))
29649             {
29650               wtype = TREE_TYPE (wtype);
29651               htype = TREE_TYPE (htype);
29652             }
29653         }
29654       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
29655         return va_list_type_node;
29656       wtype = sysv_va_list_type_node;
29657           gcc_assert (wtype != NULL_TREE);
29658       htype = type;
29659       if (TREE_CODE (wtype) == ARRAY_TYPE)
29660         {
29661           /* If va_list is an array type, the argument may have decayed
29662              to a pointer type, e.g. by being passed to another function.
29663              In that case, unwrap both types so that we can compare the
29664              underlying records.  */
29665           if (TREE_CODE (htype) == ARRAY_TYPE
29666               || POINTER_TYPE_P (htype))
29667             {
29668               wtype = TREE_TYPE (wtype);
29669               htype = TREE_TYPE (htype);
29670             }
29671         }
29672       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
29673         return sysv_va_list_type_node;
29674       wtype = ms_va_list_type_node;
29675           gcc_assert (wtype != NULL_TREE);
29676       htype = type;
29677       if (TREE_CODE (wtype) == ARRAY_TYPE)
29678         {
29679           /* If va_list is an array type, the argument may have decayed
29680              to a pointer type, e.g. by being passed to another function.
29681              In that case, unwrap both types so that we can compare the
29682              underlying records.  */
29683           if (TREE_CODE (htype) == ARRAY_TYPE
29684               || POINTER_TYPE_P (htype))
29685             {
29686               wtype = TREE_TYPE (wtype);
29687               htype = TREE_TYPE (htype);
29688             }
29689         }
29690       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
29691         return ms_va_list_type_node;
29692       return NULL_TREE;
29693     }
29694   return std_canonical_va_list_type (type);
29695 }
29696
29697 /* Iterate through the target-specific builtin types for va_list.
29698     IDX denotes the iterator, *PTREE is set to the result type of
29699     the va_list builtin, and *PNAME to its internal type.
29700     Returns zero if there is no element for this index, otherwise
29701     IDX should be increased upon the next call.
29702     Note, do not iterate a base builtin's name like __builtin_va_list.
29703     Used from c_common_nodes_and_builtins.  */
29704
29705 int
29706 ix86_enum_va_list (int idx, const char **pname, tree *ptree)
29707 {
29708   if (!TARGET_64BIT)
29709     return 0;
29710   switch (idx) {
29711   case 0:
29712     *ptree = ms_va_list_type_node;
29713     *pname = "__builtin_ms_va_list";
29714     break;
29715   case 1:
29716     *ptree = sysv_va_list_type_node;
29717     *pname = "__builtin_sysv_va_list";
29718     break;
29719   default:
29720     return 0;
29721   }
29722   return 1;
29723 }
29724
29725 /* Initialize the GCC target structure.  */
29726 #undef TARGET_RETURN_IN_MEMORY
29727 #define TARGET_RETURN_IN_MEMORY ix86_return_in_memory
29728
29729 #undef TARGET_ATTRIBUTE_TABLE
29730 #define TARGET_ATTRIBUTE_TABLE ix86_attribute_table
29731 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
29732 #  undef TARGET_MERGE_DECL_ATTRIBUTES
29733 #  define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
29734 #endif
29735
29736 #undef TARGET_COMP_TYPE_ATTRIBUTES
29737 #define TARGET_COMP_TYPE_ATTRIBUTES ix86_comp_type_attributes
29738
29739 #undef TARGET_INIT_BUILTINS
29740 #define TARGET_INIT_BUILTINS ix86_init_builtins
29741 #undef TARGET_EXPAND_BUILTIN
29742 #define TARGET_EXPAND_BUILTIN ix86_expand_builtin
29743
29744 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
29745 #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
29746   ix86_builtin_vectorized_function
29747
29748 #undef TARGET_VECTORIZE_BUILTIN_CONVERSION
29749 #define TARGET_VECTORIZE_BUILTIN_CONVERSION ix86_vectorize_builtin_conversion
29750
29751 #undef TARGET_BUILTIN_RECIPROCAL
29752 #define TARGET_BUILTIN_RECIPROCAL ix86_builtin_reciprocal
29753
29754 #undef TARGET_ASM_FUNCTION_EPILOGUE
29755 #define TARGET_ASM_FUNCTION_EPILOGUE ix86_output_function_epilogue
29756
29757 #undef TARGET_ENCODE_SECTION_INFO
29758 #ifndef SUBTARGET_ENCODE_SECTION_INFO
29759 #define TARGET_ENCODE_SECTION_INFO ix86_encode_section_info
29760 #else
29761 #define TARGET_ENCODE_SECTION_INFO SUBTARGET_ENCODE_SECTION_INFO
29762 #endif
29763
29764 #undef TARGET_ASM_OPEN_PAREN
29765 #define TARGET_ASM_OPEN_PAREN ""
29766 #undef TARGET_ASM_CLOSE_PAREN
29767 #define TARGET_ASM_CLOSE_PAREN ""
29768
29769 #undef TARGET_ASM_ALIGNED_HI_OP
29770 #define TARGET_ASM_ALIGNED_HI_OP ASM_SHORT
29771 #undef TARGET_ASM_ALIGNED_SI_OP
29772 #define TARGET_ASM_ALIGNED_SI_OP ASM_LONG
29773 #ifdef ASM_QUAD
29774 #undef TARGET_ASM_ALIGNED_DI_OP
29775 #define TARGET_ASM_ALIGNED_DI_OP ASM_QUAD
29776 #endif
29777
29778 #undef TARGET_ASM_UNALIGNED_HI_OP
29779 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
29780 #undef TARGET_ASM_UNALIGNED_SI_OP
29781 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
29782 #undef TARGET_ASM_UNALIGNED_DI_OP
29783 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
29784
29785 #undef TARGET_SCHED_ADJUST_COST
29786 #define TARGET_SCHED_ADJUST_COST ix86_adjust_cost
29787 #undef TARGET_SCHED_ISSUE_RATE
29788 #define TARGET_SCHED_ISSUE_RATE ix86_issue_rate
29789 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
29790 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
29791   ia32_multipass_dfa_lookahead
29792
29793 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
29794 #define TARGET_FUNCTION_OK_FOR_SIBCALL ix86_function_ok_for_sibcall
29795
29796 #ifdef HAVE_AS_TLS
29797 #undef TARGET_HAVE_TLS
29798 #define TARGET_HAVE_TLS true
29799 #endif
29800 #undef TARGET_CANNOT_FORCE_CONST_MEM
29801 #define TARGET_CANNOT_FORCE_CONST_MEM ix86_cannot_force_const_mem
29802 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
29803 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P hook_bool_mode_const_rtx_true
29804
29805 #undef TARGET_DELEGITIMIZE_ADDRESS
29806 #define TARGET_DELEGITIMIZE_ADDRESS ix86_delegitimize_address
29807
29808 #undef TARGET_MS_BITFIELD_LAYOUT_P
29809 #define TARGET_MS_BITFIELD_LAYOUT_P ix86_ms_bitfield_layout_p
29810
29811 #if TARGET_MACHO
29812 #undef TARGET_BINDS_LOCAL_P
29813 #define TARGET_BINDS_LOCAL_P darwin_binds_local_p
29814 #endif
29815 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
29816 #undef TARGET_BINDS_LOCAL_P
29817 #define TARGET_BINDS_LOCAL_P i386_pe_binds_local_p
29818 #endif
29819
29820 #undef TARGET_ASM_OUTPUT_MI_THUNK
29821 #define TARGET_ASM_OUTPUT_MI_THUNK x86_output_mi_thunk
29822 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
29823 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK x86_can_output_mi_thunk
29824
29825 #undef TARGET_ASM_FILE_START
29826 #define TARGET_ASM_FILE_START x86_file_start
29827
29828 #undef TARGET_DEFAULT_TARGET_FLAGS
29829 #define TARGET_DEFAULT_TARGET_FLAGS     \
29830   (TARGET_DEFAULT                       \
29831    | TARGET_SUBTARGET_DEFAULT           \
29832    | TARGET_TLS_DIRECT_SEG_REFS_DEFAULT)
29833
29834 #undef TARGET_HANDLE_OPTION
29835 #define TARGET_HANDLE_OPTION ix86_handle_option
29836
29837 #undef TARGET_RTX_COSTS
29838 #define TARGET_RTX_COSTS ix86_rtx_costs
29839 #undef TARGET_ADDRESS_COST
29840 #define TARGET_ADDRESS_COST ix86_address_cost
29841
29842 #undef TARGET_FIXED_CONDITION_CODE_REGS
29843 #define TARGET_FIXED_CONDITION_CODE_REGS ix86_fixed_condition_code_regs
29844 #undef TARGET_CC_MODES_COMPATIBLE
29845 #define TARGET_CC_MODES_COMPATIBLE ix86_cc_modes_compatible
29846
29847 #undef TARGET_MACHINE_DEPENDENT_REORG
29848 #define TARGET_MACHINE_DEPENDENT_REORG ix86_reorg
29849
29850 #undef TARGET_BUILTIN_SETJMP_FRAME_VALUE
29851 #define TARGET_BUILTIN_SETJMP_FRAME_VALUE ix86_builtin_setjmp_frame_value
29852
29853 #undef TARGET_BUILD_BUILTIN_VA_LIST
29854 #define TARGET_BUILD_BUILTIN_VA_LIST ix86_build_builtin_va_list
29855
29856 #undef TARGET_FN_ABI_VA_LIST
29857 #define TARGET_FN_ABI_VA_LIST ix86_fn_abi_va_list
29858
29859 #undef TARGET_CANONICAL_VA_LIST_TYPE
29860 #define TARGET_CANONICAL_VA_LIST_TYPE ix86_canonical_va_list_type
29861
29862 #undef TARGET_EXPAND_BUILTIN_VA_START
29863 #define TARGET_EXPAND_BUILTIN_VA_START ix86_va_start
29864
29865 #undef TARGET_MD_ASM_CLOBBERS
29866 #define TARGET_MD_ASM_CLOBBERS ix86_md_asm_clobbers
29867
29868 #undef TARGET_PROMOTE_PROTOTYPES
29869 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
29870 #undef TARGET_STRUCT_VALUE_RTX
29871 #define TARGET_STRUCT_VALUE_RTX ix86_struct_value_rtx
29872 #undef TARGET_SETUP_INCOMING_VARARGS
29873 #define TARGET_SETUP_INCOMING_VARARGS ix86_setup_incoming_varargs
29874 #undef TARGET_MUST_PASS_IN_STACK
29875 #define TARGET_MUST_PASS_IN_STACK ix86_must_pass_in_stack
29876 #undef TARGET_PASS_BY_REFERENCE
29877 #define TARGET_PASS_BY_REFERENCE ix86_pass_by_reference
29878 #undef TARGET_INTERNAL_ARG_POINTER
29879 #define TARGET_INTERNAL_ARG_POINTER ix86_internal_arg_pointer
29880 #undef TARGET_UPDATE_STACK_BOUNDARY
29881 #define TARGET_UPDATE_STACK_BOUNDARY ix86_update_stack_boundary
29882 #undef TARGET_GET_DRAP_RTX
29883 #define TARGET_GET_DRAP_RTX ix86_get_drap_rtx
29884 #undef TARGET_DWARF_HANDLE_FRAME_UNSPEC
29885 #define TARGET_DWARF_HANDLE_FRAME_UNSPEC ix86_dwarf_handle_frame_unspec
29886 #undef TARGET_STRICT_ARGUMENT_NAMING
29887 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
29888
29889 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
29890 #define TARGET_GIMPLIFY_VA_ARG_EXPR ix86_gimplify_va_arg
29891
29892 #undef TARGET_SCALAR_MODE_SUPPORTED_P
29893 #define TARGET_SCALAR_MODE_SUPPORTED_P ix86_scalar_mode_supported_p
29894
29895 #undef TARGET_VECTOR_MODE_SUPPORTED_P
29896 #define TARGET_VECTOR_MODE_SUPPORTED_P ix86_vector_mode_supported_p
29897
29898 #undef TARGET_C_MODE_FOR_SUFFIX
29899 #define TARGET_C_MODE_FOR_SUFFIX ix86_c_mode_for_suffix
29900
29901 #ifdef HAVE_AS_TLS
29902 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
29903 #define TARGET_ASM_OUTPUT_DWARF_DTPREL i386_output_dwarf_dtprel
29904 #endif
29905
29906 #ifdef SUBTARGET_INSERT_ATTRIBUTES
29907 #undef TARGET_INSERT_ATTRIBUTES
29908 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
29909 #endif
29910
29911 #undef TARGET_MANGLE_TYPE
29912 #define TARGET_MANGLE_TYPE ix86_mangle_type
29913
29914 #undef TARGET_STACK_PROTECT_FAIL
29915 #define TARGET_STACK_PROTECT_FAIL ix86_stack_protect_fail
29916
29917 #undef TARGET_FUNCTION_VALUE
29918 #define TARGET_FUNCTION_VALUE ix86_function_value
29919
29920 #undef TARGET_SECONDARY_RELOAD
29921 #define TARGET_SECONDARY_RELOAD ix86_secondary_reload
29922
29923 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST
29924 #define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST x86_builtin_vectorization_cost
29925
29926 #undef TARGET_SET_CURRENT_FUNCTION
29927 #define TARGET_SET_CURRENT_FUNCTION ix86_set_current_function
29928
29929 #undef TARGET_OPTION_VALID_ATTRIBUTE_P
29930 #define TARGET_OPTION_VALID_ATTRIBUTE_P ix86_valid_target_attribute_p
29931
29932 #undef TARGET_OPTION_SAVE
29933 #define TARGET_OPTION_SAVE ix86_function_specific_save
29934
29935 #undef TARGET_OPTION_RESTORE
29936 #define TARGET_OPTION_RESTORE ix86_function_specific_restore
29937
29938 #undef TARGET_OPTION_PRINT
29939 #define TARGET_OPTION_PRINT ix86_function_specific_print
29940
29941 #undef TARGET_OPTION_CAN_INLINE_P
29942 #define TARGET_OPTION_CAN_INLINE_P ix86_can_inline_p
29943
29944 #undef TARGET_EXPAND_TO_RTL_HOOK
29945 #define TARGET_EXPAND_TO_RTL_HOOK ix86_maybe_switch_abi
29946
29947 struct gcc_target targetm = TARGET_INITIALIZER;
29948 \f
29949 #include "gt-i386.h"