OSDN Git Service

2009-02-18 H.J. Lu <hongjiu.lu@intel.com>
[pf3gnuchains/gcc-fork.git] / 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
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 static int const x86_64_int_parameter_registers[6] =
1537 {
1538   5 /*RDI*/, 4 /*RSI*/, 1 /*RDX*/, 2 /*RCX*/,
1539   FIRST_REX_INT_REG /*R8 */, FIRST_REX_INT_REG + 1 /*R9 */
1540 };
1541
1542 static int const x86_64_ms_abi_int_parameter_registers[4] =
1543 {
1544   2 /*RCX*/, 1 /*RDX*/,
1545   FIRST_REX_INT_REG /*R8 */, FIRST_REX_INT_REG + 1 /*R9 */
1546 };
1547
1548 static int const x86_64_int_return_registers[4] =
1549 {
1550   0 /*RAX*/, 1 /*RDX*/, 5 /*RDI*/, 4 /*RSI*/
1551 };
1552
1553 /* The "default" register map used in 64bit mode.  */
1554 int const dbx64_register_map[FIRST_PSEUDO_REGISTER] =
1555 {
1556   0, 1, 2, 3, 4, 5, 6, 7,               /* general regs */
1557   33, 34, 35, 36, 37, 38, 39, 40,       /* fp regs */
1558   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
1559   17, 18, 19, 20, 21, 22, 23, 24,       /* SSE */
1560   41, 42, 43, 44, 45, 46, 47, 48,       /* MMX */
1561   8,9,10,11,12,13,14,15,                /* extended integer registers */
1562   25, 26, 27, 28, 29, 30, 31, 32,       /* extended SSE registers */
1563 };
1564
1565 /* Define the register numbers to be used in Dwarf debugging information.
1566    The SVR4 reference port C compiler uses the following register numbers
1567    in its Dwarf output code:
1568         0 for %eax (gcc regno = 0)
1569         1 for %ecx (gcc regno = 2)
1570         2 for %edx (gcc regno = 1)
1571         3 for %ebx (gcc regno = 3)
1572         4 for %esp (gcc regno = 7)
1573         5 for %ebp (gcc regno = 6)
1574         6 for %esi (gcc regno = 4)
1575         7 for %edi (gcc regno = 5)
1576    The following three DWARF register numbers are never generated by
1577    the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4
1578    believes these numbers have these meanings.
1579         8  for %eip    (no gcc equivalent)
1580         9  for %eflags (gcc regno = 17)
1581         10 for %trapno (no gcc equivalent)
1582    It is not at all clear how we should number the FP stack registers
1583    for the x86 architecture.  If the version of SDB on x86/svr4 were
1584    a bit less brain dead with respect to floating-point then we would
1585    have a precedent to follow with respect to DWARF register numbers
1586    for x86 FP registers, but the SDB on x86/svr4 is so completely
1587    broken with respect to FP registers that it is hardly worth thinking
1588    of it as something to strive for compatibility with.
1589    The version of x86/svr4 SDB I have at the moment does (partially)
1590    seem to believe that DWARF register number 11 is associated with
1591    the x86 register %st(0), but that's about all.  Higher DWARF
1592    register numbers don't seem to be associated with anything in
1593    particular, and even for DWARF regno 11, SDB only seems to under-
1594    stand that it should say that a variable lives in %st(0) (when
1595    asked via an `=' command) if we said it was in DWARF regno 11,
1596    but SDB still prints garbage when asked for the value of the
1597    variable in question (via a `/' command).
1598    (Also note that the labels SDB prints for various FP stack regs
1599    when doing an `x' command are all wrong.)
1600    Note that these problems generally don't affect the native SVR4
1601    C compiler because it doesn't allow the use of -O with -g and
1602    because when it is *not* optimizing, it allocates a memory
1603    location for each floating-point variable, and the memory
1604    location is what gets described in the DWARF AT_location
1605    attribute for the variable in question.
1606    Regardless of the severe mental illness of the x86/svr4 SDB, we
1607    do something sensible here and we use the following DWARF
1608    register numbers.  Note that these are all stack-top-relative
1609    numbers.
1610         11 for %st(0) (gcc regno = 8)
1611         12 for %st(1) (gcc regno = 9)
1612         13 for %st(2) (gcc regno = 10)
1613         14 for %st(3) (gcc regno = 11)
1614         15 for %st(4) (gcc regno = 12)
1615         16 for %st(5) (gcc regno = 13)
1616         17 for %st(6) (gcc regno = 14)
1617         18 for %st(7) (gcc regno = 15)
1618 */
1619 int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER] =
1620 {
1621   0, 2, 1, 3, 6, 7, 5, 4,               /* general regs */
1622   11, 12, 13, 14, 15, 16, 17, 18,       /* fp regs */
1623   -1, 9, -1, -1, -1,                    /* arg, flags, fpsr, fpcr, frame */
1624   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE registers */
1625   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX registers */
1626   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
1627   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
1628 };
1629
1630 /* Test and compare insns in i386.md store the information needed to
1631    generate branch and scc insns here.  */
1632
1633 rtx ix86_compare_op0 = NULL_RTX;
1634 rtx ix86_compare_op1 = NULL_RTX;
1635 rtx ix86_compare_emitted = NULL_RTX;
1636
1637 /* Define the structure for the machine field in struct function.  */
1638
1639 struct stack_local_entry GTY(())
1640 {
1641   unsigned short mode;
1642   unsigned short n;
1643   rtx rtl;
1644   struct stack_local_entry *next;
1645 };
1646
1647 /* Structure describing stack frame layout.
1648    Stack grows downward:
1649
1650    [arguments]
1651                                               <- ARG_POINTER
1652    saved pc
1653
1654    saved frame pointer if frame_pointer_needed
1655                                               <- HARD_FRAME_POINTER
1656    [saved regs]
1657
1658    [padding0]
1659
1660    [saved SSE regs]
1661
1662    [padding1]          \
1663                         )
1664    [va_arg registers]  (
1665                         > to_allocate         <- FRAME_POINTER
1666    [frame]             (
1667                         )
1668    [padding2]          /
1669   */
1670 struct ix86_frame
1671 {
1672   int padding0;
1673   int nsseregs;
1674   int nregs;
1675   int padding1;
1676   int va_arg_size;
1677   HOST_WIDE_INT frame;
1678   int padding2;
1679   int outgoing_arguments_size;
1680   int red_zone_size;
1681
1682   HOST_WIDE_INT to_allocate;
1683   /* The offsets relative to ARG_POINTER.  */
1684   HOST_WIDE_INT frame_pointer_offset;
1685   HOST_WIDE_INT hard_frame_pointer_offset;
1686   HOST_WIDE_INT stack_pointer_offset;
1687
1688   /* When save_regs_using_mov is set, emit prologue using
1689      move instead of push instructions.  */
1690   bool save_regs_using_mov;
1691 };
1692
1693 /* Code model option.  */
1694 enum cmodel ix86_cmodel;
1695 /* Asm dialect.  */
1696 enum asm_dialect ix86_asm_dialect = ASM_ATT;
1697 /* TLS dialects.  */
1698 enum tls_dialect ix86_tls_dialect = TLS_DIALECT_GNU;
1699
1700 /* Which unit we are generating floating point math for.  */
1701 enum fpmath_unit ix86_fpmath;
1702
1703 /* Which cpu are we scheduling for.  */
1704 enum attr_cpu ix86_schedule;
1705
1706 /* Which cpu are we optimizing for.  */
1707 enum processor_type ix86_tune;
1708
1709 /* Which instruction set architecture to use.  */
1710 enum processor_type ix86_arch;
1711
1712 /* true if sse prefetch instruction is not NOOP.  */
1713 int x86_prefetch_sse;
1714
1715 /* ix86_regparm_string as a number */
1716 static int ix86_regparm;
1717
1718 /* -mstackrealign option */
1719 extern int ix86_force_align_arg_pointer;
1720 static const char ix86_force_align_arg_pointer_string[]
1721   = "force_align_arg_pointer";
1722
1723 static rtx (*ix86_gen_leave) (void);
1724 static rtx (*ix86_gen_pop1) (rtx);
1725 static rtx (*ix86_gen_add3) (rtx, rtx, rtx);
1726 static rtx (*ix86_gen_sub3) (rtx, rtx, rtx);
1727 static rtx (*ix86_gen_sub3_carry) (rtx, rtx, rtx, rtx);
1728 static rtx (*ix86_gen_one_cmpl2) (rtx, rtx);
1729 static rtx (*ix86_gen_monitor) (rtx, rtx, rtx);
1730 static rtx (*ix86_gen_andsp) (rtx, rtx, rtx);
1731
1732 /* Preferred alignment for stack boundary in bits.  */
1733 unsigned int ix86_preferred_stack_boundary;
1734
1735 /* Alignment for incoming stack boundary in bits specified at
1736    command line.  */
1737 static unsigned int ix86_user_incoming_stack_boundary;
1738
1739 /* Default alignment for incoming stack boundary in bits.  */
1740 static unsigned int ix86_default_incoming_stack_boundary;
1741
1742 /* Alignment for incoming stack boundary in bits.  */
1743 unsigned int ix86_incoming_stack_boundary;
1744
1745 /* Values 1-5: see jump.c */
1746 int ix86_branch_cost;
1747
1748 /* Calling abi specific va_list type nodes.  */
1749 static GTY(()) tree sysv_va_list_type_node;
1750 static GTY(()) tree ms_va_list_type_node;
1751
1752 /* Variables which are this size or smaller are put in the data/bss
1753    or ldata/lbss sections.  */
1754
1755 int ix86_section_threshold = 65536;
1756
1757 /* Prefix built by ASM_GENERATE_INTERNAL_LABEL.  */
1758 char internal_label_prefix[16];
1759 int internal_label_prefix_len;
1760
1761 /* Fence to use after loop using movnt.  */
1762 tree x86_mfence;
1763
1764 /* Register class used for passing given 64bit part of the argument.
1765    These represent classes as documented by the PS ABI, with the exception
1766    of SSESF, SSEDF classes, that are basically SSE class, just gcc will
1767    use SF or DFmode move instead of DImode to avoid reformatting penalties.
1768
1769    Similarly we play games with INTEGERSI_CLASS to use cheaper SImode moves
1770    whenever possible (upper half does contain padding).  */
1771 enum x86_64_reg_class
1772   {
1773     X86_64_NO_CLASS,
1774     X86_64_INTEGER_CLASS,
1775     X86_64_INTEGERSI_CLASS,
1776     X86_64_SSE_CLASS,
1777     X86_64_SSESF_CLASS,
1778     X86_64_SSEDF_CLASS,
1779     X86_64_SSEUP_CLASS,
1780     X86_64_X87_CLASS,
1781     X86_64_X87UP_CLASS,
1782     X86_64_COMPLEX_X87_CLASS,
1783     X86_64_MEMORY_CLASS
1784   };
1785
1786 #define MAX_CLASSES 4
1787
1788 /* Table of constants used by fldpi, fldln2, etc....  */
1789 static REAL_VALUE_TYPE ext_80387_constants_table [5];
1790 static bool ext_80387_constants_init = 0;
1791
1792 \f
1793 static struct machine_function * ix86_init_machine_status (void);
1794 static rtx ix86_function_value (const_tree, const_tree, bool);
1795 static int ix86_function_regparm (const_tree, const_tree);
1796 static void ix86_compute_frame_layout (struct ix86_frame *);
1797 static bool ix86_expand_vector_init_one_nonzero (bool, enum machine_mode,
1798                                                  rtx, rtx, int);
1799 static void ix86_add_new_builtins (int);
1800
1801 enum ix86_function_specific_strings
1802 {
1803   IX86_FUNCTION_SPECIFIC_ARCH,
1804   IX86_FUNCTION_SPECIFIC_TUNE,
1805   IX86_FUNCTION_SPECIFIC_FPMATH,
1806   IX86_FUNCTION_SPECIFIC_MAX
1807 };
1808
1809 static char *ix86_target_string (int, int, const char *, const char *,
1810                                  const char *, bool);
1811 static void ix86_debug_options (void) ATTRIBUTE_UNUSED;
1812 static void ix86_function_specific_save (struct cl_target_option *);
1813 static void ix86_function_specific_restore (struct cl_target_option *);
1814 static void ix86_function_specific_print (FILE *, int,
1815                                           struct cl_target_option *);
1816 static bool ix86_valid_target_attribute_p (tree, tree, tree, int);
1817 static bool ix86_valid_target_attribute_inner_p (tree, char *[]);
1818 static bool ix86_can_inline_p (tree, tree);
1819 static void ix86_set_current_function (tree);
1820
1821 \f
1822 /* The svr4 ABI for the i386 says that records and unions are returned
1823    in memory.  */
1824 #ifndef DEFAULT_PCC_STRUCT_RETURN
1825 #define DEFAULT_PCC_STRUCT_RETURN 1
1826 #endif
1827
1828 /* Whether -mtune= or -march= were specified */
1829 static int ix86_tune_defaulted;
1830 static int ix86_arch_specified;
1831
1832 /* Bit flags that specify the ISA we are compiling for.  */
1833 int ix86_isa_flags = TARGET_64BIT_DEFAULT | TARGET_SUBTARGET_ISA_DEFAULT;
1834
1835 /* A mask of ix86_isa_flags that includes bit X if X
1836    was set or cleared on the command line.  */
1837 static int ix86_isa_flags_explicit;
1838
1839 /* Define a set of ISAs which are available when a given ISA is
1840    enabled.  MMX and SSE ISAs are handled separately.  */
1841
1842 #define OPTION_MASK_ISA_MMX_SET OPTION_MASK_ISA_MMX
1843 #define OPTION_MASK_ISA_3DNOW_SET \
1844   (OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_MMX_SET)
1845
1846 #define OPTION_MASK_ISA_SSE_SET OPTION_MASK_ISA_SSE
1847 #define OPTION_MASK_ISA_SSE2_SET \
1848   (OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE_SET)
1849 #define OPTION_MASK_ISA_SSE3_SET \
1850   (OPTION_MASK_ISA_SSE3 | OPTION_MASK_ISA_SSE2_SET)
1851 #define OPTION_MASK_ISA_SSSE3_SET \
1852   (OPTION_MASK_ISA_SSSE3 | OPTION_MASK_ISA_SSE3_SET)
1853 #define OPTION_MASK_ISA_SSE4_1_SET \
1854   (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_SSSE3_SET)
1855 #define OPTION_MASK_ISA_SSE4_2_SET \
1856   (OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_SSE4_1_SET)
1857 #define OPTION_MASK_ISA_AVX_SET \
1858   (OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_SSE4_2_SET)
1859 #define OPTION_MASK_ISA_FMA_SET \
1860   (OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_AVX_SET)
1861
1862 /* SSE4 includes both SSE4.1 and SSE4.2. -msse4 should be the same
1863    as -msse4.2.  */
1864 #define OPTION_MASK_ISA_SSE4_SET OPTION_MASK_ISA_SSE4_2_SET
1865
1866 #define OPTION_MASK_ISA_SSE4A_SET \
1867   (OPTION_MASK_ISA_SSE4A | OPTION_MASK_ISA_SSE3_SET)
1868 #define OPTION_MASK_ISA_SSE5_SET \
1869   (OPTION_MASK_ISA_SSE5 | OPTION_MASK_ISA_SSE4A_SET)
1870
1871 /* AES and PCLMUL need SSE2 because they use xmm registers */
1872 #define OPTION_MASK_ISA_AES_SET \
1873   (OPTION_MASK_ISA_AES | OPTION_MASK_ISA_SSE2_SET)
1874 #define OPTION_MASK_ISA_PCLMUL_SET \
1875   (OPTION_MASK_ISA_PCLMUL | OPTION_MASK_ISA_SSE2_SET)
1876
1877 #define OPTION_MASK_ISA_ABM_SET \
1878   (OPTION_MASK_ISA_ABM | OPTION_MASK_ISA_POPCNT)
1879 #define OPTION_MASK_ISA_POPCNT_SET OPTION_MASK_ISA_POPCNT
1880 #define OPTION_MASK_ISA_CX16_SET OPTION_MASK_ISA_CX16
1881 #define OPTION_MASK_ISA_SAHF_SET OPTION_MASK_ISA_SAHF
1882
1883 /* Define a set of ISAs which aren't available when a given ISA is
1884    disabled.  MMX and SSE ISAs are handled separately.  */
1885
1886 #define OPTION_MASK_ISA_MMX_UNSET \
1887   (OPTION_MASK_ISA_MMX | OPTION_MASK_ISA_3DNOW_UNSET)
1888 #define OPTION_MASK_ISA_3DNOW_UNSET \
1889   (OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_3DNOW_A_UNSET)
1890 #define OPTION_MASK_ISA_3DNOW_A_UNSET OPTION_MASK_ISA_3DNOW_A
1891
1892 #define OPTION_MASK_ISA_SSE_UNSET \
1893   (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_SSE2_UNSET)
1894 #define OPTION_MASK_ISA_SSE2_UNSET \
1895   (OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE3_UNSET)
1896 #define OPTION_MASK_ISA_SSE3_UNSET \
1897   (OPTION_MASK_ISA_SSE3 \
1898    | OPTION_MASK_ISA_SSSE3_UNSET \
1899    | OPTION_MASK_ISA_SSE4A_UNSET )
1900 #define OPTION_MASK_ISA_SSSE3_UNSET \
1901   (OPTION_MASK_ISA_SSSE3 | OPTION_MASK_ISA_SSE4_1_UNSET)
1902 #define OPTION_MASK_ISA_SSE4_1_UNSET \
1903   (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_SSE4_2_UNSET)
1904 #define OPTION_MASK_ISA_SSE4_2_UNSET \
1905   (OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_AVX_UNSET )
1906 #define OPTION_MASK_ISA_AVX_UNSET \
1907   (OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_FMA_UNSET)
1908 #define OPTION_MASK_ISA_FMA_UNSET OPTION_MASK_ISA_FMA
1909
1910 /* SSE4 includes both SSE4.1 and SSE4.2.  -mno-sse4 should the same
1911    as -mno-sse4.1. */
1912 #define OPTION_MASK_ISA_SSE4_UNSET OPTION_MASK_ISA_SSE4_1_UNSET
1913
1914 #define OPTION_MASK_ISA_SSE4A_UNSET \
1915   (OPTION_MASK_ISA_SSE4A | OPTION_MASK_ISA_SSE5_UNSET)
1916 #define OPTION_MASK_ISA_SSE5_UNSET OPTION_MASK_ISA_SSE5
1917 #define OPTION_MASK_ISA_AES_UNSET OPTION_MASK_ISA_AES
1918 #define OPTION_MASK_ISA_PCLMUL_UNSET OPTION_MASK_ISA_PCLMUL
1919 #define OPTION_MASK_ISA_ABM_UNSET OPTION_MASK_ISA_ABM
1920 #define OPTION_MASK_ISA_POPCNT_UNSET OPTION_MASK_ISA_POPCNT
1921 #define OPTION_MASK_ISA_CX16_UNSET OPTION_MASK_ISA_CX16
1922 #define OPTION_MASK_ISA_SAHF_UNSET OPTION_MASK_ISA_SAHF
1923
1924 /* Vectorization library interface and handlers.  */
1925 tree (*ix86_veclib_handler)(enum built_in_function, tree, tree) = NULL;
1926 static tree ix86_veclibabi_svml (enum built_in_function, tree, tree);
1927 static tree ix86_veclibabi_acml (enum built_in_function, tree, tree);
1928
1929 /* Processor target table, indexed by processor number */
1930 struct ptt
1931 {
1932   const struct processor_costs *cost;           /* Processor costs */
1933   const int align_loop;                         /* Default alignments.  */
1934   const int align_loop_max_skip;
1935   const int align_jump;
1936   const int align_jump_max_skip;
1937   const int align_func;
1938 };
1939
1940 static const struct ptt processor_target_table[PROCESSOR_max] =
1941 {
1942   {&i386_cost, 4, 3, 4, 3, 4},
1943   {&i486_cost, 16, 15, 16, 15, 16},
1944   {&pentium_cost, 16, 7, 16, 7, 16},
1945   {&pentiumpro_cost, 16, 15, 16, 10, 16},
1946   {&geode_cost, 0, 0, 0, 0, 0},
1947   {&k6_cost, 32, 7, 32, 7, 32},
1948   {&athlon_cost, 16, 7, 16, 7, 16},
1949   {&pentium4_cost, 0, 0, 0, 0, 0},
1950   {&k8_cost, 16, 7, 16, 7, 16},
1951   {&nocona_cost, 0, 0, 0, 0, 0},
1952   {&core2_cost, 16, 10, 16, 10, 16},
1953   {&generic32_cost, 16, 7, 16, 7, 16},
1954   {&generic64_cost, 16, 10, 16, 10, 16},
1955   {&amdfam10_cost, 32, 24, 32, 7, 32}
1956 };
1957
1958 static const char *const cpu_names[TARGET_CPU_DEFAULT_max] =
1959 {
1960   "generic",
1961   "i386",
1962   "i486",
1963   "pentium",
1964   "pentium-mmx",
1965   "pentiumpro",
1966   "pentium2",
1967   "pentium3",
1968   "pentium4",
1969   "pentium-m",
1970   "prescott",
1971   "nocona",
1972   "core2",
1973   "geode",
1974   "k6",
1975   "k6-2",
1976   "k6-3",
1977   "athlon",
1978   "athlon-4",
1979   "k8",
1980   "amdfam10"
1981 };
1982 \f
1983 /* Implement TARGET_HANDLE_OPTION.  */
1984
1985 static bool
1986 ix86_handle_option (size_t code, const char *arg ATTRIBUTE_UNUSED, int value)
1987 {
1988   switch (code)
1989     {
1990     case OPT_mmmx:
1991       if (value)
1992         {
1993           ix86_isa_flags |= OPTION_MASK_ISA_MMX_SET;
1994           ix86_isa_flags_explicit |= OPTION_MASK_ISA_MMX_SET;
1995         }
1996       else
1997         {
1998           ix86_isa_flags &= ~OPTION_MASK_ISA_MMX_UNSET;
1999           ix86_isa_flags_explicit |= OPTION_MASK_ISA_MMX_UNSET;
2000         }
2001       return true;
2002
2003     case OPT_m3dnow:
2004       if (value)
2005         {
2006           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_SET;
2007           ix86_isa_flags_explicit |= OPTION_MASK_ISA_3DNOW_SET;
2008         }
2009       else
2010         {
2011           ix86_isa_flags &= ~OPTION_MASK_ISA_3DNOW_UNSET;
2012           ix86_isa_flags_explicit |= OPTION_MASK_ISA_3DNOW_UNSET;
2013         }
2014       return true;
2015
2016     case OPT_m3dnowa:
2017       return false;
2018
2019     case OPT_msse:
2020       if (value)
2021         {
2022           ix86_isa_flags |= OPTION_MASK_ISA_SSE_SET;
2023           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE_SET;
2024         }
2025       else
2026         {
2027           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE_UNSET;
2028           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE_UNSET;
2029         }
2030       return true;
2031
2032     case OPT_msse2:
2033       if (value)
2034         {
2035           ix86_isa_flags |= OPTION_MASK_ISA_SSE2_SET;
2036           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE2_SET;
2037         }
2038       else
2039         {
2040           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE2_UNSET;
2041           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE2_UNSET;
2042         }
2043       return true;
2044
2045     case OPT_msse3:
2046       if (value)
2047         {
2048           ix86_isa_flags |= OPTION_MASK_ISA_SSE3_SET;
2049           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE3_SET;
2050         }
2051       else
2052         {
2053           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE3_UNSET;
2054           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE3_UNSET;
2055         }
2056       return true;
2057
2058     case OPT_mssse3:
2059       if (value)
2060         {
2061           ix86_isa_flags |= OPTION_MASK_ISA_SSSE3_SET;
2062           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSSE3_SET;
2063         }
2064       else
2065         {
2066           ix86_isa_flags &= ~OPTION_MASK_ISA_SSSE3_UNSET;
2067           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSSE3_UNSET;
2068         }
2069       return true;
2070
2071     case OPT_msse4_1:
2072       if (value)
2073         {
2074           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1_SET;
2075           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_1_SET;
2076         }
2077       else
2078         {
2079           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_1_UNSET;
2080           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_1_UNSET;
2081         }
2082       return true;
2083
2084     case OPT_msse4_2:
2085       if (value)
2086         {
2087           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2_SET;
2088           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_2_SET;
2089         }
2090       else
2091         {
2092           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_2_UNSET;
2093           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_2_UNSET;
2094         }
2095       return true;
2096
2097     case OPT_mavx:
2098       if (value)
2099         {
2100           ix86_isa_flags |= OPTION_MASK_ISA_AVX_SET;
2101           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AVX_SET;
2102         }
2103       else
2104         {
2105           ix86_isa_flags &= ~OPTION_MASK_ISA_AVX_UNSET;
2106           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AVX_UNSET;
2107         }
2108       return true;
2109
2110     case OPT_mfma:
2111       if (value)
2112         {
2113           ix86_isa_flags |= OPTION_MASK_ISA_FMA_SET;
2114           ix86_isa_flags_explicit |= OPTION_MASK_ISA_FMA_SET;
2115         }
2116       else
2117         {
2118           ix86_isa_flags &= ~OPTION_MASK_ISA_FMA_UNSET;
2119           ix86_isa_flags_explicit |= OPTION_MASK_ISA_FMA_UNSET;
2120         }
2121       return true;
2122
2123     case OPT_msse4:
2124       ix86_isa_flags |= OPTION_MASK_ISA_SSE4_SET;
2125       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_SET;
2126       return true;
2127
2128     case OPT_mno_sse4:
2129       ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_UNSET;
2130       ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_UNSET;
2131       return true;
2132
2133     case OPT_msse4a:
2134       if (value)
2135         {
2136           ix86_isa_flags |= OPTION_MASK_ISA_SSE4A_SET;
2137           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4A_SET;
2138         }
2139       else
2140         {
2141           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4A_UNSET;
2142           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4A_UNSET;
2143         }
2144       return true;
2145
2146     case OPT_msse5:
2147       if (value)
2148         {
2149           ix86_isa_flags |= OPTION_MASK_ISA_SSE5_SET;
2150           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE5_SET;
2151         }
2152       else
2153         {
2154           ix86_isa_flags &= ~OPTION_MASK_ISA_SSE5_UNSET;
2155           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE5_UNSET;
2156         }
2157       return true;
2158
2159     case OPT_mabm:
2160       if (value)
2161         {
2162           ix86_isa_flags |= OPTION_MASK_ISA_ABM_SET;
2163           ix86_isa_flags_explicit |= OPTION_MASK_ISA_ABM_SET;
2164         }
2165       else
2166         {
2167           ix86_isa_flags &= ~OPTION_MASK_ISA_ABM_UNSET;
2168           ix86_isa_flags_explicit |= OPTION_MASK_ISA_ABM_UNSET;
2169         }
2170       return true;
2171
2172     case OPT_mpopcnt:
2173       if (value)
2174         {
2175           ix86_isa_flags |= OPTION_MASK_ISA_POPCNT_SET;
2176           ix86_isa_flags_explicit |= OPTION_MASK_ISA_POPCNT_SET;
2177         }
2178       else
2179         {
2180           ix86_isa_flags &= ~OPTION_MASK_ISA_POPCNT_UNSET;
2181           ix86_isa_flags_explicit |= OPTION_MASK_ISA_POPCNT_UNSET;
2182         }
2183       return true;
2184
2185     case OPT_msahf:
2186       if (value)
2187         {
2188           ix86_isa_flags |= OPTION_MASK_ISA_SAHF_SET;
2189           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SAHF_SET;
2190         }
2191       else
2192         {
2193           ix86_isa_flags &= ~OPTION_MASK_ISA_SAHF_UNSET;
2194           ix86_isa_flags_explicit |= OPTION_MASK_ISA_SAHF_UNSET;
2195         }
2196       return true;
2197
2198     case OPT_mcx16:
2199       if (value)
2200         {
2201           ix86_isa_flags |= OPTION_MASK_ISA_CX16_SET;
2202           ix86_isa_flags_explicit |= OPTION_MASK_ISA_CX16_SET;
2203         }
2204       else
2205         {
2206           ix86_isa_flags &= ~OPTION_MASK_ISA_CX16_UNSET;
2207           ix86_isa_flags_explicit |= OPTION_MASK_ISA_CX16_UNSET;
2208         }
2209       return true;
2210
2211     case OPT_maes:
2212       if (value)
2213         {
2214           ix86_isa_flags |= OPTION_MASK_ISA_AES_SET;
2215           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AES_SET;
2216         }
2217       else
2218         {
2219           ix86_isa_flags &= ~OPTION_MASK_ISA_AES_UNSET;
2220           ix86_isa_flags_explicit |= OPTION_MASK_ISA_AES_UNSET;
2221         }
2222       return true;
2223
2224     case OPT_mpclmul:
2225       if (value)
2226         {
2227           ix86_isa_flags |= OPTION_MASK_ISA_PCLMUL_SET;
2228           ix86_isa_flags_explicit |= OPTION_MASK_ISA_PCLMUL_SET;
2229         }
2230       else
2231         {
2232           ix86_isa_flags &= ~OPTION_MASK_ISA_PCLMUL_UNSET;
2233           ix86_isa_flags_explicit |= OPTION_MASK_ISA_PCLMUL_UNSET;
2234         }
2235       return true;
2236
2237     default:
2238       return true;
2239     }
2240 }
2241 \f
2242 /* Return a string the documents the current -m options.  The caller is
2243    responsible for freeing the string.  */
2244
2245 static char *
2246 ix86_target_string (int isa, int flags, const char *arch, const char *tune,
2247                     const char *fpmath, bool add_nl_p)
2248 {
2249   struct ix86_target_opts
2250   {
2251     const char *option;         /* option string */
2252     int mask;                   /* isa mask options */
2253   };
2254
2255   /* This table is ordered so that options like -msse5 or -msse4.2 that imply
2256      preceding options while match those first.  */
2257   static struct ix86_target_opts isa_opts[] =
2258   {
2259     { "-m64",           OPTION_MASK_ISA_64BIT },
2260     { "-msse5",         OPTION_MASK_ISA_SSE5 },
2261     { "-msse4a",        OPTION_MASK_ISA_SSE4A },
2262     { "-msse4.2",       OPTION_MASK_ISA_SSE4_2 },
2263     { "-msse4.1",       OPTION_MASK_ISA_SSE4_1 },
2264     { "-mssse3",        OPTION_MASK_ISA_SSSE3 },
2265     { "-msse3",         OPTION_MASK_ISA_SSE3 },
2266     { "-msse2",         OPTION_MASK_ISA_SSE2 },
2267     { "-msse",          OPTION_MASK_ISA_SSE },
2268     { "-m3dnow",        OPTION_MASK_ISA_3DNOW },
2269     { "-m3dnowa",       OPTION_MASK_ISA_3DNOW_A },
2270     { "-mmmx",          OPTION_MASK_ISA_MMX },
2271     { "-mabm",          OPTION_MASK_ISA_ABM },
2272     { "-mpopcnt",       OPTION_MASK_ISA_POPCNT },
2273     { "-maes",          OPTION_MASK_ISA_AES },
2274     { "-mpclmul",       OPTION_MASK_ISA_PCLMUL },
2275   };
2276
2277   /* Flag options.  */
2278   static struct ix86_target_opts flag_opts[] =
2279   {
2280     { "-m128bit-long-double",           MASK_128BIT_LONG_DOUBLE },
2281     { "-m80387",                        MASK_80387 },
2282     { "-maccumulate-outgoing-args",     MASK_ACCUMULATE_OUTGOING_ARGS },
2283     { "-malign-double",                 MASK_ALIGN_DOUBLE },
2284     { "-mcld",                          MASK_CLD },
2285     { "-mfp-ret-in-387",                MASK_FLOAT_RETURNS },
2286     { "-mieee-fp",                      MASK_IEEE_FP },
2287     { "-minline-all-stringops",         MASK_INLINE_ALL_STRINGOPS },
2288     { "-minline-stringops-dynamically", MASK_INLINE_STRINGOPS_DYNAMICALLY },
2289     { "-mms-bitfields",                 MASK_MS_BITFIELD_LAYOUT },
2290     { "-mno-align-stringops",           MASK_NO_ALIGN_STRINGOPS },
2291     { "-mno-fancy-math-387",            MASK_NO_FANCY_MATH_387 },
2292     { "-mno-fused-madd",                MASK_NO_FUSED_MADD },
2293     { "-mno-push-args",                 MASK_NO_PUSH_ARGS },
2294     { "-mno-red-zone",                  MASK_NO_RED_ZONE },
2295     { "-momit-leaf-frame-pointer",      MASK_OMIT_LEAF_FRAME_POINTER },
2296     { "-mrecip",                        MASK_RECIP },
2297     { "-mrtd",                          MASK_RTD },
2298     { "-msseregparm",                   MASK_SSEREGPARM },
2299     { "-mstack-arg-probe",              MASK_STACK_PROBE },
2300     { "-mtls-direct-seg-refs",          MASK_TLS_DIRECT_SEG_REFS },
2301   };
2302
2303   const char *opts[ARRAY_SIZE (isa_opts) + ARRAY_SIZE (flag_opts) + 6][2];
2304
2305   char isa_other[40];
2306   char target_other[40];
2307   unsigned num = 0;
2308   unsigned i, j;
2309   char *ret;
2310   char *ptr;
2311   size_t len;
2312   size_t line_len;
2313   size_t sep_len;
2314
2315   memset (opts, '\0', sizeof (opts));
2316
2317   /* Add -march= option.  */
2318   if (arch)
2319     {
2320       opts[num][0] = "-march=";
2321       opts[num++][1] = arch;
2322     }
2323
2324   /* Add -mtune= option.  */
2325   if (tune)
2326     {
2327       opts[num][0] = "-mtune=";
2328       opts[num++][1] = tune;
2329     }
2330
2331   /* Pick out the options in isa options.  */
2332   for (i = 0; i < ARRAY_SIZE (isa_opts); i++)
2333     {
2334       if ((isa & isa_opts[i].mask) != 0)
2335         {
2336           opts[num++][0] = isa_opts[i].option;
2337           isa &= ~ isa_opts[i].mask;
2338         }
2339     }
2340
2341   if (isa && add_nl_p)
2342     {
2343       opts[num++][0] = isa_other;
2344       sprintf (isa_other, "(other isa: 0x%x)", isa);
2345     }
2346
2347   /* Add flag options.  */
2348   for (i = 0; i < ARRAY_SIZE (flag_opts); i++)
2349     {
2350       if ((flags & flag_opts[i].mask) != 0)
2351         {
2352           opts[num++][0] = flag_opts[i].option;
2353           flags &= ~ flag_opts[i].mask;
2354         }
2355     }
2356
2357   if (flags && add_nl_p)
2358     {
2359       opts[num++][0] = target_other;
2360       sprintf (target_other, "(other flags: 0x%x)", isa);
2361     }
2362
2363   /* Add -fpmath= option.  */
2364   if (fpmath)
2365     {
2366       opts[num][0] = "-mfpmath=";
2367       opts[num++][1] = fpmath;
2368     }
2369
2370   /* Any options?  */
2371   if (num == 0)
2372     return NULL;
2373
2374   gcc_assert (num < ARRAY_SIZE (opts));
2375
2376   /* Size the string.  */
2377   len = 0;
2378   sep_len = (add_nl_p) ? 3 : 1;
2379   for (i = 0; i < num; i++)
2380     {
2381       len += sep_len;
2382       for (j = 0; j < 2; j++)
2383         if (opts[i][j])
2384           len += strlen (opts[i][j]);
2385     }
2386
2387   /* Build the string.  */
2388   ret = ptr = (char *) xmalloc (len);
2389   line_len = 0;
2390
2391   for (i = 0; i < num; i++)
2392     {
2393       size_t len2[2];
2394
2395       for (j = 0; j < 2; j++)
2396         len2[j] = (opts[i][j]) ? strlen (opts[i][j]) : 0;
2397
2398       if (i != 0)
2399         {
2400           *ptr++ = ' ';
2401           line_len++;
2402
2403           if (add_nl_p && line_len + len2[0] + len2[1] > 70)
2404             {
2405               *ptr++ = '\\';
2406               *ptr++ = '\n';
2407               line_len = 0;
2408             }
2409         }
2410
2411       for (j = 0; j < 2; j++)
2412         if (opts[i][j])
2413           {
2414             memcpy (ptr, opts[i][j], len2[j]);
2415             ptr += len2[j];
2416             line_len += len2[j];
2417           }
2418     }
2419
2420   *ptr = '\0';
2421   gcc_assert (ret + len >= ptr);
2422
2423   return ret;
2424 }
2425
2426 /* Function that is callable from the debugger to print the current
2427    options.  */
2428 void
2429 ix86_debug_options (void)
2430 {
2431   char *opts = ix86_target_string (ix86_isa_flags, target_flags,
2432                                    ix86_arch_string, ix86_tune_string,
2433                                    ix86_fpmath_string, true);
2434
2435   if (opts)
2436     {
2437       fprintf (stderr, "%s\n\n", opts);
2438       free (opts);
2439     }
2440   else
2441     fprintf (stderr, "<no options>\n\n");
2442
2443   return;
2444 }
2445 \f
2446 /* Sometimes certain combinations of command options do not make
2447    sense on a particular target machine.  You can define a macro
2448    `OVERRIDE_OPTIONS' to take account of this.  This macro, if
2449    defined, is executed once just after all the command options have
2450    been parsed.
2451
2452    Don't use this macro to turn on various extra optimizations for
2453    `-O'.  That is what `OPTIMIZATION_OPTIONS' is for.  */
2454
2455 void
2456 override_options (bool main_args_p)
2457 {
2458   int i;
2459   unsigned int ix86_arch_mask, ix86_tune_mask;
2460   const char *prefix;
2461   const char *suffix;
2462   const char *sw;
2463
2464   /* Comes from final.c -- no real reason to change it.  */
2465 #define MAX_CODE_ALIGN 16
2466
2467   enum pta_flags
2468     {
2469       PTA_SSE = 1 << 0,
2470       PTA_SSE2 = 1 << 1,
2471       PTA_SSE3 = 1 << 2,
2472       PTA_MMX = 1 << 3,
2473       PTA_PREFETCH_SSE = 1 << 4,
2474       PTA_3DNOW = 1 << 5,
2475       PTA_3DNOW_A = 1 << 6,
2476       PTA_64BIT = 1 << 7,
2477       PTA_SSSE3 = 1 << 8,
2478       PTA_CX16 = 1 << 9,
2479       PTA_POPCNT = 1 << 10,
2480       PTA_ABM = 1 << 11,
2481       PTA_SSE4A = 1 << 12,
2482       PTA_NO_SAHF = 1 << 13,
2483       PTA_SSE4_1 = 1 << 14,
2484       PTA_SSE4_2 = 1 << 15,
2485       PTA_SSE5 = 1 << 16,
2486       PTA_AES = 1 << 17,
2487       PTA_PCLMUL = 1 << 18,
2488       PTA_AVX = 1 << 19,
2489       PTA_FMA = 1 << 20 
2490     };
2491
2492   static struct pta
2493     {
2494       const char *const name;           /* processor name or nickname.  */
2495       const enum processor_type processor;
2496       const enum attr_cpu schedule;
2497       const unsigned /*enum pta_flags*/ flags;
2498     }
2499   const processor_alias_table[] =
2500     {
2501       {"i386", PROCESSOR_I386, CPU_NONE, 0},
2502       {"i486", PROCESSOR_I486, CPU_NONE, 0},
2503       {"i586", PROCESSOR_PENTIUM, CPU_PENTIUM, 0},
2504       {"pentium", PROCESSOR_PENTIUM, CPU_PENTIUM, 0},
2505       {"pentium-mmx", PROCESSOR_PENTIUM, CPU_PENTIUM, PTA_MMX},
2506       {"winchip-c6", PROCESSOR_I486, CPU_NONE, PTA_MMX},
2507       {"winchip2", PROCESSOR_I486, CPU_NONE, PTA_MMX | PTA_3DNOW},
2508       {"c3", PROCESSOR_I486, CPU_NONE, PTA_MMX | PTA_3DNOW},
2509       {"c3-2", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, PTA_MMX | PTA_SSE},
2510       {"i686", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, 0},
2511       {"pentiumpro", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, 0},
2512       {"pentium2", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, PTA_MMX},
2513       {"pentium3", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
2514         PTA_MMX | PTA_SSE},
2515       {"pentium3m", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
2516         PTA_MMX | PTA_SSE},
2517       {"pentium-m", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
2518         PTA_MMX | PTA_SSE | PTA_SSE2},
2519       {"pentium4", PROCESSOR_PENTIUM4, CPU_NONE,
2520         PTA_MMX |PTA_SSE | PTA_SSE2},
2521       {"pentium4m", PROCESSOR_PENTIUM4, CPU_NONE,
2522         PTA_MMX | PTA_SSE | PTA_SSE2},
2523       {"prescott", PROCESSOR_NOCONA, CPU_NONE,
2524         PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3},
2525       {"nocona", PROCESSOR_NOCONA, CPU_NONE,
2526         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
2527         | PTA_CX16 | PTA_NO_SAHF},
2528       {"core2", PROCESSOR_CORE2, CPU_CORE2,
2529         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
2530         | PTA_SSSE3 | PTA_CX16},
2531       {"geode", PROCESSOR_GEODE, CPU_GEODE,
2532         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A |PTA_PREFETCH_SSE},
2533       {"k6", PROCESSOR_K6, CPU_K6, PTA_MMX},
2534       {"k6-2", PROCESSOR_K6, CPU_K6, PTA_MMX | PTA_3DNOW},
2535       {"k6-3", PROCESSOR_K6, CPU_K6, PTA_MMX | PTA_3DNOW},
2536       {"athlon", PROCESSOR_ATHLON, CPU_ATHLON,
2537         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_PREFETCH_SSE},
2538       {"athlon-tbird", PROCESSOR_ATHLON, CPU_ATHLON,
2539         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_PREFETCH_SSE},
2540       {"athlon-4", PROCESSOR_ATHLON, CPU_ATHLON,
2541         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE},
2542       {"athlon-xp", PROCESSOR_ATHLON, CPU_ATHLON,
2543         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE},
2544       {"athlon-mp", PROCESSOR_ATHLON, CPU_ATHLON,
2545         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE},
2546       {"x86-64", PROCESSOR_K8, CPU_K8,
2547         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_NO_SAHF},
2548       {"k8", PROCESSOR_K8, CPU_K8,
2549         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2550         | PTA_SSE2 | PTA_NO_SAHF},
2551       {"k8-sse3", PROCESSOR_K8, CPU_K8,
2552         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2553         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF},
2554       {"opteron", PROCESSOR_K8, CPU_K8,
2555         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2556         | PTA_SSE2 | PTA_NO_SAHF},
2557       {"opteron-sse3", PROCESSOR_K8, CPU_K8,
2558         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2559         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF},
2560       {"athlon64", PROCESSOR_K8, CPU_K8,
2561         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2562         | PTA_SSE2 | PTA_NO_SAHF},
2563       {"athlon64-sse3", PROCESSOR_K8, CPU_K8,
2564         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2565         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF},
2566       {"athlon-fx", PROCESSOR_K8, CPU_K8,
2567         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2568         | PTA_SSE2 | PTA_NO_SAHF},
2569       {"amdfam10", PROCESSOR_AMDFAM10, CPU_AMDFAM10,
2570         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2571         | PTA_SSE2 | PTA_SSE3 | PTA_SSE4A | PTA_CX16 | PTA_ABM},
2572       {"barcelona", PROCESSOR_AMDFAM10, CPU_AMDFAM10,
2573         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
2574         | PTA_SSE2 | PTA_SSE3 | PTA_SSE4A | PTA_CX16 | PTA_ABM},
2575       {"generic32", PROCESSOR_GENERIC32, CPU_PENTIUMPRO,
2576         0 /* flags are only used for -march switch.  */ },
2577       {"generic64", PROCESSOR_GENERIC64, CPU_GENERIC64,
2578         PTA_64BIT /* flags are only used for -march switch.  */ },
2579     };
2580
2581   int const pta_size = ARRAY_SIZE (processor_alias_table);
2582
2583   /* Set up prefix/suffix so the error messages refer to either the command
2584      line argument, or the attribute(target).  */
2585   if (main_args_p)
2586     {
2587       prefix = "-m";
2588       suffix = "";
2589       sw = "switch";
2590     }
2591   else
2592     {
2593       prefix = "option(\"";
2594       suffix = "\")";
2595       sw = "attribute";
2596     }
2597
2598 #ifdef SUBTARGET_OVERRIDE_OPTIONS
2599   SUBTARGET_OVERRIDE_OPTIONS;
2600 #endif
2601
2602 #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
2603   SUBSUBTARGET_OVERRIDE_OPTIONS;
2604 #endif
2605
2606   /* -fPIC is the default for x86_64.  */
2607   if (TARGET_MACHO && TARGET_64BIT)
2608     flag_pic = 2;
2609
2610   /* Set the default values for switches whose default depends on TARGET_64BIT
2611      in case they weren't overwritten by command line options.  */
2612   if (TARGET_64BIT)
2613     {
2614       /* Mach-O doesn't support omitting the frame pointer for now.  */
2615       if (flag_omit_frame_pointer == 2)
2616         flag_omit_frame_pointer = (TARGET_MACHO ? 0 : 1);
2617       if (flag_asynchronous_unwind_tables == 2)
2618         flag_asynchronous_unwind_tables = 1;
2619       if (flag_pcc_struct_return == 2)
2620         flag_pcc_struct_return = 0;
2621     }
2622   else
2623     {
2624       if (flag_omit_frame_pointer == 2)
2625         flag_omit_frame_pointer = 0;
2626       if (flag_asynchronous_unwind_tables == 2)
2627         flag_asynchronous_unwind_tables = 0;
2628       if (flag_pcc_struct_return == 2)
2629         flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
2630     }
2631
2632   /* Need to check -mtune=generic first.  */
2633   if (ix86_tune_string)
2634     {
2635       if (!strcmp (ix86_tune_string, "generic")
2636           || !strcmp (ix86_tune_string, "i686")
2637           /* As special support for cross compilers we read -mtune=native
2638              as -mtune=generic.  With native compilers we won't see the
2639              -mtune=native, as it was changed by the driver.  */
2640           || !strcmp (ix86_tune_string, "native"))
2641         {
2642           if (TARGET_64BIT)
2643             ix86_tune_string = "generic64";
2644           else
2645             ix86_tune_string = "generic32";
2646         }
2647       /* If this call is for setting the option attribute, allow the
2648          generic32/generic64 that was previously set.  */
2649       else if (!main_args_p
2650                && (!strcmp (ix86_tune_string, "generic32")
2651                    || !strcmp (ix86_tune_string, "generic64")))
2652         ;
2653       else if (!strncmp (ix86_tune_string, "generic", 7))
2654         error ("bad value (%s) for %stune=%s %s",
2655                ix86_tune_string, prefix, suffix, sw);
2656     }
2657   else
2658     {
2659       if (ix86_arch_string)
2660         ix86_tune_string = ix86_arch_string;
2661       if (!ix86_tune_string)
2662         {
2663           ix86_tune_string = cpu_names[TARGET_CPU_DEFAULT];
2664           ix86_tune_defaulted = 1;
2665         }
2666
2667       /* ix86_tune_string is set to ix86_arch_string or defaulted.  We
2668          need to use a sensible tune option.  */
2669       if (!strcmp (ix86_tune_string, "generic")
2670           || !strcmp (ix86_tune_string, "x86-64")
2671           || !strcmp (ix86_tune_string, "i686"))
2672         {
2673           if (TARGET_64BIT)
2674             ix86_tune_string = "generic64";
2675           else
2676             ix86_tune_string = "generic32";
2677         }
2678     }
2679   if (ix86_stringop_string)
2680     {
2681       if (!strcmp (ix86_stringop_string, "rep_byte"))
2682         stringop_alg = rep_prefix_1_byte;
2683       else if (!strcmp (ix86_stringop_string, "libcall"))
2684         stringop_alg = libcall;
2685       else if (!strcmp (ix86_stringop_string, "rep_4byte"))
2686         stringop_alg = rep_prefix_4_byte;
2687       else if (!strcmp (ix86_stringop_string, "rep_8byte")
2688                && TARGET_64BIT)
2689         /* rep; movq isn't available in 32-bit code.  */
2690         stringop_alg = rep_prefix_8_byte;
2691       else if (!strcmp (ix86_stringop_string, "byte_loop"))
2692         stringop_alg = loop_1_byte;
2693       else if (!strcmp (ix86_stringop_string, "loop"))
2694         stringop_alg = loop;
2695       else if (!strcmp (ix86_stringop_string, "unrolled_loop"))
2696         stringop_alg = unrolled_loop;
2697       else
2698         error ("bad value (%s) for %sstringop-strategy=%s %s",
2699                ix86_stringop_string, prefix, suffix, sw);
2700     }
2701   if (!strcmp (ix86_tune_string, "x86-64"))
2702     warning (OPT_Wdeprecated, "%stune=x86-64%s is deprecated.  Use "
2703              "%stune=k8%s or %stune=generic%s instead as appropriate.",
2704              prefix, suffix, prefix, suffix, prefix, suffix);
2705
2706   if (!ix86_arch_string)
2707     ix86_arch_string = TARGET_64BIT ? "x86-64" : "i386";
2708   else
2709     ix86_arch_specified = 1;
2710
2711   if (!strcmp (ix86_arch_string, "generic"))
2712     error ("generic CPU can be used only for %stune=%s %s",
2713            prefix, suffix, sw);
2714   if (!strncmp (ix86_arch_string, "generic", 7))
2715     error ("bad value (%s) for %sarch=%s %s",
2716            ix86_arch_string, prefix, suffix, sw);
2717
2718   if (ix86_cmodel_string != 0)
2719     {
2720       if (!strcmp (ix86_cmodel_string, "small"))
2721         ix86_cmodel = flag_pic ? CM_SMALL_PIC : CM_SMALL;
2722       else if (!strcmp (ix86_cmodel_string, "medium"))
2723         ix86_cmodel = flag_pic ? CM_MEDIUM_PIC : CM_MEDIUM;
2724       else if (!strcmp (ix86_cmodel_string, "large"))
2725         ix86_cmodel = flag_pic ? CM_LARGE_PIC : CM_LARGE;
2726       else if (flag_pic)
2727         error ("code model %s does not support PIC mode", ix86_cmodel_string);
2728       else if (!strcmp (ix86_cmodel_string, "32"))
2729         ix86_cmodel = CM_32;
2730       else if (!strcmp (ix86_cmodel_string, "kernel") && !flag_pic)
2731         ix86_cmodel = CM_KERNEL;
2732       else
2733         error ("bad value (%s) for %scmodel=%s %s",
2734                ix86_cmodel_string, prefix, suffix, sw);
2735     }
2736   else
2737     {
2738       /* For TARGET_64BIT and MS_ABI, force pic on, in order to enable the
2739          use of rip-relative addressing.  This eliminates fixups that
2740          would otherwise be needed if this object is to be placed in a
2741          DLL, and is essentially just as efficient as direct addressing.  */
2742       if (TARGET_64BIT && DEFAULT_ABI == MS_ABI)
2743         ix86_cmodel = CM_SMALL_PIC, flag_pic = 1;
2744       else if (TARGET_64BIT)
2745         ix86_cmodel = flag_pic ? CM_SMALL_PIC : CM_SMALL;
2746       else
2747         ix86_cmodel = CM_32;
2748     }
2749   if (ix86_asm_string != 0)
2750     {
2751       if (! TARGET_MACHO
2752           && !strcmp (ix86_asm_string, "intel"))
2753         ix86_asm_dialect = ASM_INTEL;
2754       else if (!strcmp (ix86_asm_string, "att"))
2755         ix86_asm_dialect = ASM_ATT;
2756       else
2757         error ("bad value (%s) for %sasm=%s %s",
2758                ix86_asm_string, prefix, suffix, sw);
2759     }
2760   if ((TARGET_64BIT == 0) != (ix86_cmodel == CM_32))
2761     error ("code model %qs not supported in the %s bit mode",
2762            ix86_cmodel_string, TARGET_64BIT ? "64" : "32");
2763   if ((TARGET_64BIT != 0) != ((ix86_isa_flags & OPTION_MASK_ISA_64BIT) != 0))
2764     sorry ("%i-bit mode not compiled in",
2765            (ix86_isa_flags & OPTION_MASK_ISA_64BIT) ? 64 : 32);
2766
2767   for (i = 0; i < pta_size; i++)
2768     if (! strcmp (ix86_arch_string, processor_alias_table[i].name))
2769       {
2770         ix86_schedule = processor_alias_table[i].schedule;
2771         ix86_arch = processor_alias_table[i].processor;
2772         /* Default cpu tuning to the architecture.  */
2773         ix86_tune = ix86_arch;
2774
2775         if (TARGET_64BIT && !(processor_alias_table[i].flags & PTA_64BIT))
2776           error ("CPU you selected does not support x86-64 "
2777                  "instruction set");
2778
2779         if (processor_alias_table[i].flags & PTA_MMX
2780             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_MMX))
2781           ix86_isa_flags |= OPTION_MASK_ISA_MMX;
2782         if (processor_alias_table[i].flags & PTA_3DNOW
2783             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW))
2784           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW;
2785         if (processor_alias_table[i].flags & PTA_3DNOW_A
2786             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW_A))
2787           ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_A;
2788         if (processor_alias_table[i].flags & PTA_SSE
2789             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE))
2790           ix86_isa_flags |= OPTION_MASK_ISA_SSE;
2791         if (processor_alias_table[i].flags & PTA_SSE2
2792             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE2))
2793           ix86_isa_flags |= OPTION_MASK_ISA_SSE2;
2794         if (processor_alias_table[i].flags & PTA_SSE3
2795             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE3))
2796           ix86_isa_flags |= OPTION_MASK_ISA_SSE3;
2797         if (processor_alias_table[i].flags & PTA_SSSE3
2798             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSSE3))
2799           ix86_isa_flags |= OPTION_MASK_ISA_SSSE3;
2800         if (processor_alias_table[i].flags & PTA_SSE4_1
2801             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_1))
2802           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1;
2803         if (processor_alias_table[i].flags & PTA_SSE4_2
2804             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_2))
2805           ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2;
2806         if (processor_alias_table[i].flags & PTA_AVX
2807             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX))
2808           ix86_isa_flags |= OPTION_MASK_ISA_AVX;
2809         if (processor_alias_table[i].flags & PTA_FMA
2810             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_FMA))
2811           ix86_isa_flags |= OPTION_MASK_ISA_FMA;
2812         if (processor_alias_table[i].flags & PTA_SSE4A
2813             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4A))
2814           ix86_isa_flags |= OPTION_MASK_ISA_SSE4A;
2815         if (processor_alias_table[i].flags & PTA_SSE5
2816             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE5))
2817           ix86_isa_flags |= OPTION_MASK_ISA_SSE5;
2818         if (processor_alias_table[i].flags & PTA_ABM
2819             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_ABM))
2820           ix86_isa_flags |= OPTION_MASK_ISA_ABM;
2821         if (processor_alias_table[i].flags & PTA_CX16
2822             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_CX16))
2823           ix86_isa_flags |= OPTION_MASK_ISA_CX16;
2824         if (processor_alias_table[i].flags & (PTA_POPCNT | PTA_ABM)
2825             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_POPCNT))
2826           ix86_isa_flags |= OPTION_MASK_ISA_POPCNT;
2827         if (!(TARGET_64BIT && (processor_alias_table[i].flags & PTA_NO_SAHF))
2828             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SAHF))
2829           ix86_isa_flags |= OPTION_MASK_ISA_SAHF;
2830         if (processor_alias_table[i].flags & PTA_AES
2831             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_AES))
2832           ix86_isa_flags |= OPTION_MASK_ISA_AES;
2833         if (processor_alias_table[i].flags & PTA_PCLMUL
2834             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_PCLMUL))
2835           ix86_isa_flags |= OPTION_MASK_ISA_PCLMUL;
2836         if (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE))
2837           x86_prefetch_sse = true;
2838
2839         break;
2840       }
2841
2842   if (i == pta_size)
2843     error ("bad value (%s) for %sarch=%s %s",
2844            ix86_arch_string, prefix, suffix, sw);
2845
2846   ix86_arch_mask = 1u << ix86_arch;
2847   for (i = 0; i < X86_ARCH_LAST; ++i)
2848     ix86_arch_features[i] = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
2849
2850   for (i = 0; i < pta_size; i++)
2851     if (! strcmp (ix86_tune_string, processor_alias_table[i].name))
2852       {
2853         ix86_schedule = processor_alias_table[i].schedule;
2854         ix86_tune = processor_alias_table[i].processor;
2855         if (TARGET_64BIT && !(processor_alias_table[i].flags & PTA_64BIT))
2856           {
2857             if (ix86_tune_defaulted)
2858               {
2859                 ix86_tune_string = "x86-64";
2860                 for (i = 0; i < pta_size; i++)
2861                   if (! strcmp (ix86_tune_string,
2862                                 processor_alias_table[i].name))
2863                     break;
2864                 ix86_schedule = processor_alias_table[i].schedule;
2865                 ix86_tune = processor_alias_table[i].processor;
2866               }
2867             else
2868               error ("CPU you selected does not support x86-64 "
2869                      "instruction set");
2870           }
2871         /* Intel CPUs have always interpreted SSE prefetch instructions as
2872            NOPs; so, we can enable SSE prefetch instructions even when
2873            -mtune (rather than -march) points us to a processor that has them.
2874            However, the VIA C3 gives a SIGILL, so we only do that for i686 and
2875            higher processors.  */
2876         if (TARGET_CMOVE
2877             && (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE)))
2878           x86_prefetch_sse = true;
2879         break;
2880       }
2881   if (i == pta_size)
2882     error ("bad value (%s) for %stune=%s %s",
2883            ix86_tune_string, prefix, suffix, sw);
2884
2885   ix86_tune_mask = 1u << ix86_tune;
2886   for (i = 0; i < X86_TUNE_LAST; ++i)
2887     ix86_tune_features[i] = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
2888
2889   if (optimize_size)
2890     ix86_cost = &ix86_size_cost;
2891   else
2892     ix86_cost = processor_target_table[ix86_tune].cost;
2893
2894   /* Arrange to set up i386_stack_locals for all functions.  */
2895   init_machine_status = ix86_init_machine_status;
2896
2897   /* Validate -mregparm= value.  */
2898   if (ix86_regparm_string)
2899     {
2900       if (TARGET_64BIT)
2901         warning (0, "%sregparm%s is ignored in 64-bit mode", prefix, suffix);
2902       i = atoi (ix86_regparm_string);
2903       if (i < 0 || i > REGPARM_MAX)
2904         error ("%sregparm=%d%s is not between 0 and %d",
2905                prefix, i, suffix, REGPARM_MAX);
2906       else
2907         ix86_regparm = i;
2908     }
2909   if (TARGET_64BIT)
2910     ix86_regparm = REGPARM_MAX;
2911
2912   /* If the user has provided any of the -malign-* options,
2913      warn and use that value only if -falign-* is not set.
2914      Remove this code in GCC 3.2 or later.  */
2915   if (ix86_align_loops_string)
2916     {
2917       warning (0, "%salign-loops%s is obsolete, use -falign-loops%s",
2918                prefix, suffix, suffix);
2919       if (align_loops == 0)
2920         {
2921           i = atoi (ix86_align_loops_string);
2922           if (i < 0 || i > MAX_CODE_ALIGN)
2923             error ("%salign-loops=%d%s is not between 0 and %d",
2924                    prefix, i, suffix, MAX_CODE_ALIGN);
2925           else
2926             align_loops = 1 << i;
2927         }
2928     }
2929
2930   if (ix86_align_jumps_string)
2931     {
2932       warning (0, "%salign-jumps%s is obsolete, use -falign-jumps%s",
2933                prefix, suffix, suffix);
2934       if (align_jumps == 0)
2935         {
2936           i = atoi (ix86_align_jumps_string);
2937           if (i < 0 || i > MAX_CODE_ALIGN)
2938             error ("%salign-loops=%d%s is not between 0 and %d",
2939                    prefix, i, suffix, MAX_CODE_ALIGN);
2940           else
2941             align_jumps = 1 << i;
2942         }
2943     }
2944
2945   if (ix86_align_funcs_string)
2946     {
2947       warning (0, "%salign-functions%s is obsolete, use -falign-functions%s",
2948                prefix, suffix, suffix);
2949       if (align_functions == 0)
2950         {
2951           i = atoi (ix86_align_funcs_string);
2952           if (i < 0 || i > MAX_CODE_ALIGN)
2953             error ("%salign-loops=%d%s is not between 0 and %d",
2954                    prefix, i, suffix, MAX_CODE_ALIGN);
2955           else
2956             align_functions = 1 << i;
2957         }
2958     }
2959
2960   /* Default align_* from the processor table.  */
2961   if (align_loops == 0)
2962     {
2963       align_loops = processor_target_table[ix86_tune].align_loop;
2964       align_loops_max_skip = processor_target_table[ix86_tune].align_loop_max_skip;
2965     }
2966   if (align_jumps == 0)
2967     {
2968       align_jumps = processor_target_table[ix86_tune].align_jump;
2969       align_jumps_max_skip = processor_target_table[ix86_tune].align_jump_max_skip;
2970     }
2971   if (align_functions == 0)
2972     {
2973       align_functions = processor_target_table[ix86_tune].align_func;
2974     }
2975
2976   /* Validate -mbranch-cost= value, or provide default.  */
2977   ix86_branch_cost = ix86_cost->branch_cost;
2978   if (ix86_branch_cost_string)
2979     {
2980       i = atoi (ix86_branch_cost_string);
2981       if (i < 0 || i > 5)
2982         error ("%sbranch-cost=%d%s is not between 0 and 5", prefix, i, suffix);
2983       else
2984         ix86_branch_cost = i;
2985     }
2986   if (ix86_section_threshold_string)
2987     {
2988       i = atoi (ix86_section_threshold_string);
2989       if (i < 0)
2990         error ("%slarge-data-threshold=%d%s is negative", prefix, i, suffix);
2991       else
2992         ix86_section_threshold = i;
2993     }
2994
2995   if (ix86_tls_dialect_string)
2996     {
2997       if (strcmp (ix86_tls_dialect_string, "gnu") == 0)
2998         ix86_tls_dialect = TLS_DIALECT_GNU;
2999       else if (strcmp (ix86_tls_dialect_string, "gnu2") == 0)
3000         ix86_tls_dialect = TLS_DIALECT_GNU2;
3001       else if (strcmp (ix86_tls_dialect_string, "sun") == 0)
3002         ix86_tls_dialect = TLS_DIALECT_SUN;
3003       else
3004         error ("bad value (%s) for %stls-dialect=%s %s",
3005                ix86_tls_dialect_string, prefix, suffix, sw);
3006     }
3007
3008   if (ix87_precision_string)
3009     {
3010       i = atoi (ix87_precision_string);
3011       if (i != 32 && i != 64 && i != 80)
3012         error ("pc%d is not valid precision setting (32, 64 or 80)", i);
3013     }
3014
3015   if (TARGET_64BIT)
3016     {
3017       target_flags |= TARGET_SUBTARGET64_DEFAULT & ~target_flags_explicit;
3018
3019       /* Enable by default the SSE and MMX builtins.  Do allow the user to
3020          explicitly disable any of these.  In particular, disabling SSE and
3021          MMX for kernel code is extremely useful.  */
3022       if (!ix86_arch_specified)
3023       ix86_isa_flags
3024         |= ((OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_MMX
3025              | TARGET_SUBTARGET64_ISA_DEFAULT) & ~ix86_isa_flags_explicit);
3026
3027       if (TARGET_RTD)
3028         warning (0, "%srtd%s is ignored in 64bit mode", prefix, suffix);
3029     }
3030   else
3031     {
3032       target_flags |= TARGET_SUBTARGET32_DEFAULT & ~target_flags_explicit;
3033
3034       if (!ix86_arch_specified)
3035       ix86_isa_flags
3036         |= TARGET_SUBTARGET32_ISA_DEFAULT & ~ix86_isa_flags_explicit;
3037
3038       /* i386 ABI does not specify red zone.  It still makes sense to use it
3039          when programmer takes care to stack from being destroyed.  */
3040       if (!(target_flags_explicit & MASK_NO_RED_ZONE))
3041         target_flags |= MASK_NO_RED_ZONE;
3042     }
3043
3044   /* Keep nonleaf frame pointers.  */
3045   if (flag_omit_frame_pointer)
3046     target_flags &= ~MASK_OMIT_LEAF_FRAME_POINTER;
3047   else if (TARGET_OMIT_LEAF_FRAME_POINTER)
3048     flag_omit_frame_pointer = 1;
3049
3050   /* If we're doing fast math, we don't care about comparison order
3051      wrt NaNs.  This lets us use a shorter comparison sequence.  */
3052   if (flag_finite_math_only)
3053     target_flags &= ~MASK_IEEE_FP;
3054
3055   /* If the architecture always has an FPU, turn off NO_FANCY_MATH_387,
3056      since the insns won't need emulation.  */
3057   if (x86_arch_always_fancy_math_387 & ix86_arch_mask)
3058     target_flags &= ~MASK_NO_FANCY_MATH_387;
3059
3060   /* Likewise, if the target doesn't have a 387, or we've specified
3061      software floating point, don't use 387 inline intrinsics.  */
3062   if (!TARGET_80387)
3063     target_flags |= MASK_NO_FANCY_MATH_387;
3064
3065   /* Turn on MMX builtins for -msse.  */
3066   if (TARGET_SSE)
3067     {
3068       ix86_isa_flags |= OPTION_MASK_ISA_MMX & ~ix86_isa_flags_explicit;
3069       x86_prefetch_sse = true;
3070     }
3071
3072   /* Turn on popcnt instruction for -msse4.2 or -mabm.  */
3073   if (TARGET_SSE4_2 || TARGET_ABM)
3074     ix86_isa_flags |= OPTION_MASK_ISA_POPCNT & ~ix86_isa_flags_explicit;
3075
3076   /* Validate -mpreferred-stack-boundary= value or default it to
3077      PREFERRED_STACK_BOUNDARY_DEFAULT.  */
3078   ix86_preferred_stack_boundary = PREFERRED_STACK_BOUNDARY_DEFAULT;
3079   if (ix86_preferred_stack_boundary_string)
3080     {
3081       i = atoi (ix86_preferred_stack_boundary_string);
3082       if (i < (TARGET_64BIT ? 4 : 2) || i > 12)
3083         error ("%spreferred-stack-boundary=%d%s is not between %d and 12",
3084                prefix, i, suffix, TARGET_64BIT ? 4 : 2);
3085       else
3086         ix86_preferred_stack_boundary = (1 << i) * BITS_PER_UNIT;
3087     }
3088
3089   /* Set the default value for -mstackrealign.  */
3090   if (ix86_force_align_arg_pointer == -1)
3091     ix86_force_align_arg_pointer = STACK_REALIGN_DEFAULT;
3092
3093   /* Validate -mincoming-stack-boundary= value or default it to
3094      MIN_STACK_BOUNDARY/PREFERRED_STACK_BOUNDARY.  */
3095   if (ix86_force_align_arg_pointer)
3096     ix86_default_incoming_stack_boundary = MIN_STACK_BOUNDARY;
3097   else
3098     ix86_default_incoming_stack_boundary = PREFERRED_STACK_BOUNDARY;
3099   ix86_incoming_stack_boundary = ix86_default_incoming_stack_boundary;
3100   if (ix86_incoming_stack_boundary_string)
3101     {
3102       i = atoi (ix86_incoming_stack_boundary_string);
3103       if (i < (TARGET_64BIT ? 4 : 2) || i > 12)
3104         error ("-mincoming-stack-boundary=%d is not between %d and 12",
3105                i, TARGET_64BIT ? 4 : 2);
3106       else
3107         {
3108           ix86_user_incoming_stack_boundary = (1 << i) * BITS_PER_UNIT;
3109           ix86_incoming_stack_boundary
3110             = ix86_user_incoming_stack_boundary;
3111         }
3112     }
3113
3114   /* Accept -msseregparm only if at least SSE support is enabled.  */
3115   if (TARGET_SSEREGPARM
3116       && ! TARGET_SSE)
3117     error ("%ssseregparm%s used without SSE enabled", prefix, suffix);
3118
3119   ix86_fpmath = TARGET_FPMATH_DEFAULT;
3120   if (ix86_fpmath_string != 0)
3121     {
3122       if (! strcmp (ix86_fpmath_string, "387"))
3123         ix86_fpmath = FPMATH_387;
3124       else if (! strcmp (ix86_fpmath_string, "sse"))
3125         {
3126           if (!TARGET_SSE)
3127             {
3128               warning (0, "SSE instruction set disabled, using 387 arithmetics");
3129               ix86_fpmath = FPMATH_387;
3130             }
3131           else
3132             ix86_fpmath = FPMATH_SSE;
3133         }
3134       else if (! strcmp (ix86_fpmath_string, "387,sse")
3135                || ! strcmp (ix86_fpmath_string, "387+sse")
3136                || ! strcmp (ix86_fpmath_string, "sse,387")
3137                || ! strcmp (ix86_fpmath_string, "sse+387")
3138                || ! strcmp (ix86_fpmath_string, "both"))
3139         {
3140           if (!TARGET_SSE)
3141             {
3142               warning (0, "SSE instruction set disabled, using 387 arithmetics");
3143               ix86_fpmath = FPMATH_387;
3144             }
3145           else if (!TARGET_80387)
3146             {
3147               warning (0, "387 instruction set disabled, using SSE arithmetics");
3148               ix86_fpmath = FPMATH_SSE;
3149             }
3150           else
3151             ix86_fpmath = (enum fpmath_unit) (FPMATH_SSE | FPMATH_387);
3152         }
3153       else
3154         error ("bad value (%s) for %sfpmath=%s %s",
3155                ix86_fpmath_string, prefix, suffix, sw);
3156     }
3157
3158   /* If the i387 is disabled, then do not return values in it. */
3159   if (!TARGET_80387)
3160     target_flags &= ~MASK_FLOAT_RETURNS;
3161
3162   /* Use external vectorized library in vectorizing intrinsics.  */
3163   if (ix86_veclibabi_string)
3164     {
3165       if (strcmp (ix86_veclibabi_string, "svml") == 0)
3166         ix86_veclib_handler = ix86_veclibabi_svml;
3167       else if (strcmp (ix86_veclibabi_string, "acml") == 0)
3168         ix86_veclib_handler = ix86_veclibabi_acml;
3169       else
3170         error ("unknown vectorization library ABI type (%s) for "
3171                "%sveclibabi=%s %s", ix86_veclibabi_string,
3172                prefix, suffix, sw);
3173     }
3174
3175   if ((x86_accumulate_outgoing_args & ix86_tune_mask)
3176       && !(target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3177       && !optimize_size)
3178     target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3179
3180   /* ??? Unwind info is not correct around the CFG unless either a frame
3181      pointer is present or M_A_O_A is set.  Fixing this requires rewriting
3182      unwind info generation to be aware of the CFG and propagating states
3183      around edges.  */
3184   if ((flag_unwind_tables || flag_asynchronous_unwind_tables
3185        || flag_exceptions || flag_non_call_exceptions)
3186       && flag_omit_frame_pointer
3187       && !(target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
3188     {
3189       if (target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3190         warning (0, "unwind tables currently require either a frame pointer "
3191                  "or %saccumulate-outgoing-args%s for correctness",
3192                  prefix, suffix);
3193       target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3194     }
3195
3196   /* If stack probes are required, the space used for large function
3197      arguments on the stack must also be probed, so enable
3198      -maccumulate-outgoing-args so this happens in the prologue.  */
3199   if (TARGET_STACK_PROBE
3200       && !(target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
3201     {
3202       if (target_flags_explicit & MASK_ACCUMULATE_OUTGOING_ARGS)
3203         warning (0, "stack probing requires %saccumulate-outgoing-args%s "
3204                  "for correctness", prefix, suffix);
3205       target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
3206     }
3207
3208   /* For sane SSE instruction set generation we need fcomi instruction.
3209      It is safe to enable all CMOVE instructions.  */
3210   if (TARGET_SSE)
3211     TARGET_CMOVE = 1;
3212
3213   /* Figure out what ASM_GENERATE_INTERNAL_LABEL builds as a prefix.  */
3214   {
3215     char *p;
3216     ASM_GENERATE_INTERNAL_LABEL (internal_label_prefix, "LX", 0);
3217     p = strchr (internal_label_prefix, 'X');
3218     internal_label_prefix_len = p - internal_label_prefix;
3219     *p = '\0';
3220   }
3221
3222   /* When scheduling description is not available, disable scheduler pass
3223      so it won't slow down the compilation and make x87 code slower.  */
3224   if (!TARGET_SCHEDULE)
3225     flag_schedule_insns_after_reload = flag_schedule_insns = 0;
3226
3227   if (!PARAM_SET_P (PARAM_SIMULTANEOUS_PREFETCHES))
3228     set_param_value ("simultaneous-prefetches",
3229                      ix86_cost->simultaneous_prefetches);
3230   if (!PARAM_SET_P (PARAM_L1_CACHE_LINE_SIZE))
3231     set_param_value ("l1-cache-line-size", ix86_cost->prefetch_block);
3232   if (!PARAM_SET_P (PARAM_L1_CACHE_SIZE))
3233     set_param_value ("l1-cache-size", ix86_cost->l1_cache_size);
3234   if (!PARAM_SET_P (PARAM_L2_CACHE_SIZE))
3235     set_param_value ("l2-cache-size", ix86_cost->l2_cache_size);
3236
3237   /* If using typedef char *va_list, signal that __builtin_va_start (&ap, 0)
3238      can be optimized to ap = __builtin_next_arg (0).  */
3239   if (!TARGET_64BIT)
3240     targetm.expand_builtin_va_start = NULL;
3241
3242   if (TARGET_64BIT)
3243     {
3244       ix86_gen_leave = gen_leave_rex64;
3245       ix86_gen_pop1 = gen_popdi1;
3246       ix86_gen_add3 = gen_adddi3;
3247       ix86_gen_sub3 = gen_subdi3;
3248       ix86_gen_sub3_carry = gen_subdi3_carry_rex64;
3249       ix86_gen_one_cmpl2 = gen_one_cmpldi2;
3250       ix86_gen_monitor = gen_sse3_monitor64;
3251       ix86_gen_andsp = gen_anddi3;
3252     }
3253   else
3254     {
3255       ix86_gen_leave = gen_leave;
3256       ix86_gen_pop1 = gen_popsi1;
3257       ix86_gen_add3 = gen_addsi3;
3258       ix86_gen_sub3 = gen_subsi3;
3259       ix86_gen_sub3_carry = gen_subsi3_carry;
3260       ix86_gen_one_cmpl2 = gen_one_cmplsi2;
3261       ix86_gen_monitor = gen_sse3_monitor;
3262       ix86_gen_andsp = gen_andsi3;
3263     }
3264
3265 #ifdef USE_IX86_CLD
3266   /* Use -mcld by default for 32-bit code if configured with --enable-cld.  */
3267   if (!TARGET_64BIT)
3268     target_flags |= MASK_CLD & ~target_flags_explicit;
3269 #endif
3270
3271   /* Save the initial options in case the user does function specific options */
3272   if (main_args_p)
3273     target_option_default_node = target_option_current_node
3274       = build_target_option_node ();
3275 }
3276 \f
3277 /* Save the current options */
3278
3279 static void
3280 ix86_function_specific_save (struct cl_target_option *ptr)
3281 {
3282   gcc_assert (IN_RANGE (ix86_arch, 0, 255));
3283   gcc_assert (IN_RANGE (ix86_schedule, 0, 255));
3284   gcc_assert (IN_RANGE (ix86_tune, 0, 255));
3285   gcc_assert (IN_RANGE (ix86_fpmath, 0, 255));
3286   gcc_assert (IN_RANGE (ix86_branch_cost, 0, 255));
3287
3288   ptr->arch = ix86_arch;
3289   ptr->schedule = ix86_schedule;
3290   ptr->tune = ix86_tune;
3291   ptr->fpmath = ix86_fpmath;
3292   ptr->branch_cost = ix86_branch_cost;
3293   ptr->tune_defaulted = ix86_tune_defaulted;
3294   ptr->arch_specified = ix86_arch_specified;
3295   ptr->ix86_isa_flags_explicit = ix86_isa_flags_explicit;
3296   ptr->target_flags_explicit = target_flags_explicit;
3297 }
3298
3299 /* Restore the current options */
3300
3301 static void
3302 ix86_function_specific_restore (struct cl_target_option *ptr)
3303 {
3304   enum processor_type old_tune = ix86_tune;
3305   enum processor_type old_arch = ix86_arch;
3306   unsigned int ix86_arch_mask, ix86_tune_mask;
3307   int i;
3308
3309   ix86_arch = ptr->arch;
3310   ix86_schedule = ptr->schedule;
3311   ix86_tune = ptr->tune;
3312   ix86_fpmath = ptr->fpmath;
3313   ix86_branch_cost = ptr->branch_cost;
3314   ix86_tune_defaulted = ptr->tune_defaulted;
3315   ix86_arch_specified = ptr->arch_specified;
3316   ix86_isa_flags_explicit = ptr->ix86_isa_flags_explicit;
3317   target_flags_explicit = ptr->target_flags_explicit;
3318
3319   /* Recreate the arch feature tests if the arch changed */
3320   if (old_arch != ix86_arch)
3321     {
3322       ix86_arch_mask = 1u << ix86_arch;
3323       for (i = 0; i < X86_ARCH_LAST; ++i)
3324         ix86_arch_features[i]
3325           = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
3326     }
3327
3328   /* Recreate the tune optimization tests */
3329   if (old_tune != ix86_tune)
3330     {
3331       ix86_tune_mask = 1u << ix86_tune;
3332       for (i = 0; i < X86_TUNE_LAST; ++i)
3333         ix86_tune_features[i]
3334           = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
3335     }
3336 }
3337
3338 /* Print the current options */
3339
3340 static void
3341 ix86_function_specific_print (FILE *file, int indent,
3342                               struct cl_target_option *ptr)
3343 {
3344   char *target_string
3345     = ix86_target_string (ptr->ix86_isa_flags, ptr->target_flags,
3346                           NULL, NULL, NULL, false);
3347
3348   fprintf (file, "%*sarch = %d (%s)\n",
3349            indent, "",
3350            ptr->arch,
3351            ((ptr->arch < TARGET_CPU_DEFAULT_max)
3352             ? cpu_names[ptr->arch]
3353             : "<unknown>"));
3354
3355   fprintf (file, "%*stune = %d (%s)\n",
3356            indent, "",
3357            ptr->tune,
3358            ((ptr->tune < TARGET_CPU_DEFAULT_max)
3359             ? cpu_names[ptr->tune]
3360             : "<unknown>"));
3361
3362   fprintf (file, "%*sfpmath = %d%s%s\n", indent, "", ptr->fpmath,
3363            (ptr->fpmath & FPMATH_387) ? ", 387" : "",
3364            (ptr->fpmath & FPMATH_SSE) ? ", sse" : "");
3365   fprintf (file, "%*sbranch_cost = %d\n", indent, "", ptr->branch_cost);
3366
3367   if (target_string)
3368     {
3369       fprintf (file, "%*s%s\n", indent, "", target_string);
3370       free (target_string);
3371     }
3372 }
3373
3374 \f
3375 /* Inner function to process the attribute((target(...))), take an argument and
3376    set the current options from the argument. If we have a list, recursively go
3377    over the list.  */
3378
3379 static bool
3380 ix86_valid_target_attribute_inner_p (tree args, char *p_strings[])
3381 {
3382   char *next_optstr;
3383   bool ret = true;
3384
3385 #define IX86_ATTR_ISA(S,O)   { S, sizeof (S)-1, ix86_opt_isa, O, 0 }
3386 #define IX86_ATTR_STR(S,O)   { S, sizeof (S)-1, ix86_opt_str, O, 0 }
3387 #define IX86_ATTR_YES(S,O,M) { S, sizeof (S)-1, ix86_opt_yes, O, M }
3388 #define IX86_ATTR_NO(S,O,M)  { S, sizeof (S)-1, ix86_opt_no,  O, M }
3389
3390   enum ix86_opt_type
3391   {
3392     ix86_opt_unknown,
3393     ix86_opt_yes,
3394     ix86_opt_no,
3395     ix86_opt_str,
3396     ix86_opt_isa
3397   };
3398
3399   static const struct
3400   {
3401     const char *string;
3402     size_t len;
3403     enum ix86_opt_type type;
3404     int opt;
3405     int mask;
3406   } attrs[] = {
3407     /* isa options */
3408     IX86_ATTR_ISA ("3dnow",     OPT_m3dnow),
3409     IX86_ATTR_ISA ("abm",       OPT_mabm),
3410     IX86_ATTR_ISA ("aes",       OPT_maes),
3411     IX86_ATTR_ISA ("avx",       OPT_mavx),
3412     IX86_ATTR_ISA ("mmx",       OPT_mmmx),
3413     IX86_ATTR_ISA ("pclmul",    OPT_mpclmul),
3414     IX86_ATTR_ISA ("popcnt",    OPT_mpopcnt),
3415     IX86_ATTR_ISA ("sse",       OPT_msse),
3416     IX86_ATTR_ISA ("sse2",      OPT_msse2),
3417     IX86_ATTR_ISA ("sse3",      OPT_msse3),
3418     IX86_ATTR_ISA ("sse4",      OPT_msse4),
3419     IX86_ATTR_ISA ("sse4.1",    OPT_msse4_1),
3420     IX86_ATTR_ISA ("sse4.2",    OPT_msse4_2),
3421     IX86_ATTR_ISA ("sse4a",     OPT_msse4a),
3422     IX86_ATTR_ISA ("sse5",      OPT_msse5),
3423     IX86_ATTR_ISA ("ssse3",     OPT_mssse3),
3424
3425     /* string options */
3426     IX86_ATTR_STR ("arch=",     IX86_FUNCTION_SPECIFIC_ARCH),
3427     IX86_ATTR_STR ("fpmath=",   IX86_FUNCTION_SPECIFIC_FPMATH),
3428     IX86_ATTR_STR ("tune=",     IX86_FUNCTION_SPECIFIC_TUNE),
3429
3430     /* flag options */
3431     IX86_ATTR_YES ("cld",
3432                    OPT_mcld,
3433                    MASK_CLD),
3434
3435     IX86_ATTR_NO ("fancy-math-387",
3436                   OPT_mfancy_math_387,
3437                   MASK_NO_FANCY_MATH_387),
3438
3439     IX86_ATTR_NO ("fused-madd",
3440                   OPT_mfused_madd,
3441                   MASK_NO_FUSED_MADD),
3442
3443     IX86_ATTR_YES ("ieee-fp",
3444                    OPT_mieee_fp,
3445                    MASK_IEEE_FP),
3446
3447     IX86_ATTR_YES ("inline-all-stringops",
3448                    OPT_minline_all_stringops,
3449                    MASK_INLINE_ALL_STRINGOPS),
3450
3451     IX86_ATTR_YES ("inline-stringops-dynamically",
3452                    OPT_minline_stringops_dynamically,
3453                    MASK_INLINE_STRINGOPS_DYNAMICALLY),
3454
3455     IX86_ATTR_NO ("align-stringops",
3456                   OPT_mno_align_stringops,
3457                   MASK_NO_ALIGN_STRINGOPS),
3458
3459     IX86_ATTR_YES ("recip",
3460                    OPT_mrecip,
3461                    MASK_RECIP),
3462
3463   };
3464
3465   /* If this is a list, recurse to get the options.  */
3466   if (TREE_CODE (args) == TREE_LIST)
3467     {
3468       bool ret = true;
3469
3470       for (; args; args = TREE_CHAIN (args))
3471         if (TREE_VALUE (args)
3472             && !ix86_valid_target_attribute_inner_p (TREE_VALUE (args), p_strings))
3473           ret = false;
3474
3475       return ret;
3476     }
3477
3478   else if (TREE_CODE (args) != STRING_CST)
3479     gcc_unreachable ();
3480
3481   /* Handle multiple arguments separated by commas.  */
3482   next_optstr = ASTRDUP (TREE_STRING_POINTER (args));
3483
3484   while (next_optstr && *next_optstr != '\0')
3485     {
3486       char *p = next_optstr;
3487       char *orig_p = p;
3488       char *comma = strchr (next_optstr, ',');
3489       const char *opt_string;
3490       size_t len, opt_len;
3491       int opt;
3492       bool opt_set_p;
3493       char ch;
3494       unsigned i;
3495       enum ix86_opt_type type = ix86_opt_unknown;
3496       int mask = 0;
3497
3498       if (comma)
3499         {
3500           *comma = '\0';
3501           len = comma - next_optstr;
3502           next_optstr = comma + 1;
3503         }
3504       else
3505         {
3506           len = strlen (p);
3507           next_optstr = NULL;
3508         }
3509
3510       /* Recognize no-xxx.  */
3511       if (len > 3 && p[0] == 'n' && p[1] == 'o' && p[2] == '-')
3512         {
3513           opt_set_p = false;
3514           p += 3;
3515           len -= 3;
3516         }
3517       else
3518         opt_set_p = true;
3519
3520       /* Find the option.  */
3521       ch = *p;
3522       opt = N_OPTS;
3523       for (i = 0; i < ARRAY_SIZE (attrs); i++)
3524         {
3525           type = attrs[i].type;
3526           opt_len = attrs[i].len;
3527           if (ch == attrs[i].string[0]
3528               && ((type != ix86_opt_str) ? len == opt_len : len > opt_len)
3529               && memcmp (p, attrs[i].string, opt_len) == 0)
3530             {
3531               opt = attrs[i].opt;
3532               mask = attrs[i].mask;
3533               opt_string = attrs[i].string;
3534               break;
3535             }
3536         }
3537
3538       /* Process the option.  */
3539       if (opt == N_OPTS)
3540         {
3541           error ("attribute(target(\"%s\")) is unknown", orig_p);
3542           ret = false;
3543         }
3544
3545       else if (type == ix86_opt_isa)
3546         ix86_handle_option (opt, p, opt_set_p);
3547
3548       else if (type == ix86_opt_yes || type == ix86_opt_no)
3549         {
3550           if (type == ix86_opt_no)
3551             opt_set_p = !opt_set_p;
3552
3553           if (opt_set_p)
3554             target_flags |= mask;
3555           else
3556             target_flags &= ~mask;
3557         }
3558
3559       else if (type == ix86_opt_str)
3560         {
3561           if (p_strings[opt])
3562             {
3563               error ("option(\"%s\") was already specified", opt_string);
3564               ret = false;
3565             }
3566           else
3567             p_strings[opt] = xstrdup (p + opt_len);
3568         }
3569
3570       else
3571         gcc_unreachable ();
3572     }
3573
3574   return ret;
3575 }
3576
3577 /* Return a TARGET_OPTION_NODE tree of the target options listed or NULL.  */
3578
3579 tree
3580 ix86_valid_target_attribute_tree (tree args)
3581 {
3582   const char *orig_arch_string = ix86_arch_string;
3583   const char *orig_tune_string = ix86_tune_string;
3584   const char *orig_fpmath_string = ix86_fpmath_string;
3585   int orig_tune_defaulted = ix86_tune_defaulted;
3586   int orig_arch_specified = ix86_arch_specified;
3587   char *option_strings[IX86_FUNCTION_SPECIFIC_MAX] = { NULL, NULL, NULL };
3588   tree t = NULL_TREE;
3589   int i;
3590   struct cl_target_option *def
3591     = TREE_TARGET_OPTION (target_option_default_node);
3592
3593   /* Process each of the options on the chain.  */
3594   if (! ix86_valid_target_attribute_inner_p (args, option_strings))
3595     return NULL_TREE;
3596
3597   /* If the changed options are different from the default, rerun override_options,
3598      and then save the options away.  The string options are are attribute options,
3599      and will be undone when we copy the save structure.  */
3600   if (ix86_isa_flags != def->ix86_isa_flags
3601       || target_flags != def->target_flags
3602       || option_strings[IX86_FUNCTION_SPECIFIC_ARCH]
3603       || option_strings[IX86_FUNCTION_SPECIFIC_TUNE]
3604       || option_strings[IX86_FUNCTION_SPECIFIC_FPMATH])
3605     {
3606       /* If we are using the default tune= or arch=, undo the string assigned,
3607          and use the default.  */
3608       if (option_strings[IX86_FUNCTION_SPECIFIC_ARCH])
3609         ix86_arch_string = option_strings[IX86_FUNCTION_SPECIFIC_ARCH];
3610       else if (!orig_arch_specified)
3611         ix86_arch_string = NULL;
3612
3613       if (option_strings[IX86_FUNCTION_SPECIFIC_TUNE])
3614         ix86_tune_string = option_strings[IX86_FUNCTION_SPECIFIC_TUNE];
3615       else if (orig_tune_defaulted)
3616         ix86_tune_string = NULL;
3617
3618       /* If fpmath= is not set, and we now have sse2 on 32-bit, use it.  */
3619       if (option_strings[IX86_FUNCTION_SPECIFIC_FPMATH])
3620         ix86_fpmath_string = option_strings[IX86_FUNCTION_SPECIFIC_FPMATH];
3621       else if (!TARGET_64BIT && TARGET_SSE)
3622         ix86_fpmath_string = "sse,387";
3623
3624       /* Do any overrides, such as arch=xxx, or tune=xxx support.  */
3625       override_options (false);
3626
3627       /* Add any builtin functions with the new isa if any.  */
3628       ix86_add_new_builtins (ix86_isa_flags);
3629
3630       /* Save the current options unless we are validating options for
3631          #pragma.  */
3632       t = build_target_option_node ();
3633
3634       ix86_arch_string = orig_arch_string;
3635       ix86_tune_string = orig_tune_string;
3636       ix86_fpmath_string = orig_fpmath_string;
3637
3638       /* Free up memory allocated to hold the strings */
3639       for (i = 0; i < IX86_FUNCTION_SPECIFIC_MAX; i++)
3640         if (option_strings[i])
3641           free (option_strings[i]);
3642     }
3643
3644   return t;
3645 }
3646
3647 /* Hook to validate attribute((target("string"))).  */
3648
3649 static bool
3650 ix86_valid_target_attribute_p (tree fndecl,
3651                                tree ARG_UNUSED (name),
3652                                tree args,
3653                                int ARG_UNUSED (flags))
3654 {
3655   struct cl_target_option cur_target;
3656   bool ret = true;
3657   tree old_optimize = build_optimization_node ();
3658   tree new_target, new_optimize;
3659   tree func_optimize = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl);
3660
3661   /* If the function changed the optimization levels as well as setting target
3662      options, start with the optimizations specified.  */
3663   if (func_optimize && func_optimize != old_optimize)
3664     cl_optimization_restore (TREE_OPTIMIZATION (func_optimize));
3665
3666   /* The target attributes may also change some optimization flags, so update
3667      the optimization options if necessary.  */
3668   cl_target_option_save (&cur_target);
3669   new_target = ix86_valid_target_attribute_tree (args);
3670   new_optimize = build_optimization_node ();
3671
3672   if (!new_target)
3673     ret = false;
3674
3675   else if (fndecl)
3676     {
3677       DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_target;
3678
3679       if (old_optimize != new_optimize)
3680         DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize;
3681     }
3682
3683   cl_target_option_restore (&cur_target);
3684
3685   if (old_optimize != new_optimize)
3686     cl_optimization_restore (TREE_OPTIMIZATION (old_optimize));
3687
3688   return ret;
3689 }
3690
3691 \f
3692 /* Hook to determine if one function can safely inline another.  */
3693
3694 static bool
3695 ix86_can_inline_p (tree caller, tree callee)
3696 {
3697   bool ret = false;
3698   tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller);
3699   tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee);
3700
3701   /* If callee has no option attributes, then it is ok to inline.  */
3702   if (!callee_tree)
3703     ret = true;
3704
3705   /* If caller has no option attributes, but callee does then it is not ok to
3706      inline.  */
3707   else if (!caller_tree)
3708     ret = false;
3709
3710   else
3711     {
3712       struct cl_target_option *caller_opts = TREE_TARGET_OPTION (caller_tree);
3713       struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree);
3714
3715       /* Callee's isa options should a subset of the caller's, i.e. a SSE5 function
3716          can inline a SSE2 function but a SSE2 function can't inline a SSE5
3717          function.  */
3718       if ((caller_opts->ix86_isa_flags & callee_opts->ix86_isa_flags)
3719           != callee_opts->ix86_isa_flags)
3720         ret = false;
3721
3722       /* See if we have the same non-isa options.  */
3723       else if (caller_opts->target_flags != callee_opts->target_flags)
3724         ret = false;
3725
3726       /* See if arch, tune, etc. are the same.  */
3727       else if (caller_opts->arch != callee_opts->arch)
3728         ret = false;
3729
3730       else if (caller_opts->tune != callee_opts->tune)
3731         ret = false;
3732
3733       else if (caller_opts->fpmath != callee_opts->fpmath)
3734         ret = false;
3735
3736       else if (caller_opts->branch_cost != callee_opts->branch_cost)
3737         ret = false;
3738
3739       else
3740         ret = true;
3741     }
3742
3743   return ret;
3744 }
3745
3746 \f
3747 /* Remember the last target of ix86_set_current_function.  */
3748 static GTY(()) tree ix86_previous_fndecl;
3749
3750 /* Establish appropriate back-end context for processing the function
3751    FNDECL.  The argument might be NULL to indicate processing at top
3752    level, outside of any function scope.  */
3753 static void
3754 ix86_set_current_function (tree fndecl)
3755 {
3756   /* Only change the context if the function changes.  This hook is called
3757      several times in the course of compiling a function, and we don't want to
3758      slow things down too much or call target_reinit when it isn't safe.  */
3759   if (fndecl && fndecl != ix86_previous_fndecl)
3760     {
3761       tree old_tree = (ix86_previous_fndecl
3762                        ? DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl)
3763                        : NULL_TREE);
3764
3765       tree new_tree = (fndecl
3766                        ? DECL_FUNCTION_SPECIFIC_TARGET (fndecl)
3767                        : NULL_TREE);
3768
3769       ix86_previous_fndecl = fndecl;
3770       if (old_tree == new_tree)
3771         ;
3772
3773       else if (new_tree)
3774         {
3775           cl_target_option_restore (TREE_TARGET_OPTION (new_tree));
3776           target_reinit ();
3777         }
3778
3779       else if (old_tree)
3780         {
3781           struct cl_target_option *def
3782             = TREE_TARGET_OPTION (target_option_current_node);
3783
3784           cl_target_option_restore (def);
3785           target_reinit ();
3786         }
3787     }
3788 }
3789
3790 \f
3791 /* Return true if this goes in large data/bss.  */
3792
3793 static bool
3794 ix86_in_large_data_p (tree exp)
3795 {
3796   if (ix86_cmodel != CM_MEDIUM && ix86_cmodel != CM_MEDIUM_PIC)
3797     return false;
3798
3799   /* Functions are never large data.  */
3800   if (TREE_CODE (exp) == FUNCTION_DECL)
3801     return false;
3802
3803   if (TREE_CODE (exp) == VAR_DECL && DECL_SECTION_NAME (exp))
3804     {
3805       const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (exp));
3806       if (strcmp (section, ".ldata") == 0
3807           || strcmp (section, ".lbss") == 0)
3808         return true;
3809       return false;
3810     }
3811   else
3812     {
3813       HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
3814
3815       /* If this is an incomplete type with size 0, then we can't put it
3816          in data because it might be too big when completed.  */
3817       if (!size || size > ix86_section_threshold)
3818         return true;
3819     }
3820
3821   return false;
3822 }
3823
3824 /* Switch to the appropriate section for output of DECL.
3825    DECL is either a `VAR_DECL' node or a constant of some sort.
3826    RELOC indicates whether forming the initial value of DECL requires
3827    link-time relocations.  */
3828
3829 static section * x86_64_elf_select_section (tree, int, unsigned HOST_WIDE_INT)
3830         ATTRIBUTE_UNUSED;
3831
3832 static section *
3833 x86_64_elf_select_section (tree decl, int reloc,
3834                            unsigned HOST_WIDE_INT align)
3835 {
3836   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3837       && ix86_in_large_data_p (decl))
3838     {
3839       const char *sname = NULL;
3840       unsigned int flags = SECTION_WRITE;
3841       switch (categorize_decl_for_section (decl, reloc))
3842         {
3843         case SECCAT_DATA:
3844           sname = ".ldata";
3845           break;
3846         case SECCAT_DATA_REL:
3847           sname = ".ldata.rel";
3848           break;
3849         case SECCAT_DATA_REL_LOCAL:
3850           sname = ".ldata.rel.local";
3851           break;
3852         case SECCAT_DATA_REL_RO:
3853           sname = ".ldata.rel.ro";
3854           break;
3855         case SECCAT_DATA_REL_RO_LOCAL:
3856           sname = ".ldata.rel.ro.local";
3857           break;
3858         case SECCAT_BSS:
3859           sname = ".lbss";
3860           flags |= SECTION_BSS;
3861           break;
3862         case SECCAT_RODATA:
3863         case SECCAT_RODATA_MERGE_STR:
3864         case SECCAT_RODATA_MERGE_STR_INIT:
3865         case SECCAT_RODATA_MERGE_CONST:
3866           sname = ".lrodata";
3867           flags = 0;
3868           break;
3869         case SECCAT_SRODATA:
3870         case SECCAT_SDATA:
3871         case SECCAT_SBSS:
3872           gcc_unreachable ();
3873         case SECCAT_TEXT:
3874         case SECCAT_TDATA:
3875         case SECCAT_TBSS:
3876           /* We don't split these for medium model.  Place them into
3877              default sections and hope for best.  */
3878           break;
3879         case SECCAT_EMUTLS_VAR:
3880         case SECCAT_EMUTLS_TMPL:
3881           gcc_unreachable ();
3882         }
3883       if (sname)
3884         {
3885           /* We might get called with string constants, but get_named_section
3886              doesn't like them as they are not DECLs.  Also, we need to set
3887              flags in that case.  */
3888           if (!DECL_P (decl))
3889             return get_section (sname, flags, NULL);
3890           return get_named_section (decl, sname, reloc);
3891         }
3892     }
3893   return default_elf_select_section (decl, reloc, align);
3894 }
3895
3896 /* Build up a unique section name, expressed as a
3897    STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
3898    RELOC indicates whether the initial value of EXP requires
3899    link-time relocations.  */
3900
3901 static void ATTRIBUTE_UNUSED
3902 x86_64_elf_unique_section (tree decl, int reloc)
3903 {
3904   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3905       && ix86_in_large_data_p (decl))
3906     {
3907       const char *prefix = NULL;
3908       /* We only need to use .gnu.linkonce if we don't have COMDAT groups.  */
3909       bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
3910
3911       switch (categorize_decl_for_section (decl, reloc))
3912         {
3913         case SECCAT_DATA:
3914         case SECCAT_DATA_REL:
3915         case SECCAT_DATA_REL_LOCAL:
3916         case SECCAT_DATA_REL_RO:
3917         case SECCAT_DATA_REL_RO_LOCAL:
3918           prefix = one_only ? ".ld" : ".ldata";
3919           break;
3920         case SECCAT_BSS:
3921           prefix = one_only ? ".lb" : ".lbss";
3922           break;
3923         case SECCAT_RODATA:
3924         case SECCAT_RODATA_MERGE_STR:
3925         case SECCAT_RODATA_MERGE_STR_INIT:
3926         case SECCAT_RODATA_MERGE_CONST:
3927           prefix = one_only ? ".lr" : ".lrodata";
3928           break;
3929         case SECCAT_SRODATA:
3930         case SECCAT_SDATA:
3931         case SECCAT_SBSS:
3932           gcc_unreachable ();
3933         case SECCAT_TEXT:
3934         case SECCAT_TDATA:
3935         case SECCAT_TBSS:
3936           /* We don't split these for medium model.  Place them into
3937              default sections and hope for best.  */
3938           break;
3939         case SECCAT_EMUTLS_VAR:
3940           prefix = targetm.emutls.var_section;
3941           break;
3942         case SECCAT_EMUTLS_TMPL:
3943           prefix = targetm.emutls.tmpl_section;
3944           break;
3945         }
3946       if (prefix)
3947         {
3948           const char *name, *linkonce;
3949           char *string;
3950
3951           name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
3952           name = targetm.strip_name_encoding (name);
3953           
3954           /* If we're using one_only, then there needs to be a .gnu.linkonce
3955              prefix to the section name.  */
3956           linkonce = one_only ? ".gnu.linkonce" : "";
3957   
3958           string = ACONCAT ((linkonce, prefix, ".", name, NULL));
3959           
3960           DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
3961           return;
3962         }
3963     }
3964   default_unique_section (decl, reloc);
3965 }
3966
3967 #ifdef COMMON_ASM_OP
3968 /* This says how to output assembler code to declare an
3969    uninitialized external linkage data object.
3970
3971    For medium model x86-64 we need to use .largecomm opcode for
3972    large objects.  */
3973 void
3974 x86_elf_aligned_common (FILE *file,
3975                         const char *name, unsigned HOST_WIDE_INT size,
3976                         int align)
3977 {
3978   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3979       && size > (unsigned int)ix86_section_threshold)
3980     fprintf (file, ".largecomm\t");
3981   else
3982     fprintf (file, "%s", COMMON_ASM_OP);
3983   assemble_name (file, name);
3984   fprintf (file, ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n",
3985            size, align / BITS_PER_UNIT);
3986 }
3987 #endif
3988
3989 /* Utility function for targets to use in implementing
3990    ASM_OUTPUT_ALIGNED_BSS.  */
3991
3992 void
3993 x86_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
3994                         const char *name, unsigned HOST_WIDE_INT size,
3995                         int align)
3996 {
3997   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
3998       && size > (unsigned int)ix86_section_threshold)
3999     switch_to_section (get_named_section (decl, ".lbss", 0));
4000   else
4001     switch_to_section (bss_section);
4002   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
4003 #ifdef ASM_DECLARE_OBJECT_NAME
4004   last_assemble_variable_decl = decl;
4005   ASM_DECLARE_OBJECT_NAME (file, name, decl);
4006 #else
4007   /* Standard thing is just output label for the object.  */
4008   ASM_OUTPUT_LABEL (file, name);
4009 #endif /* ASM_DECLARE_OBJECT_NAME */
4010   ASM_OUTPUT_SKIP (file, size ? size : 1);
4011 }
4012 \f
4013 void
4014 optimization_options (int level, int size ATTRIBUTE_UNUSED)
4015 {
4016   /* For -O2 and beyond, turn off -fschedule-insns by default.  It tends to
4017      make the problem with not enough registers even worse.  */
4018 #ifdef INSN_SCHEDULING
4019   if (level > 1)
4020     flag_schedule_insns = 0;
4021 #endif
4022
4023   if (TARGET_MACHO)
4024     /* The Darwin libraries never set errno, so we might as well
4025        avoid calling them when that's the only reason we would.  */
4026     flag_errno_math = 0;
4027
4028   /* The default values of these switches depend on the TARGET_64BIT
4029      that is not known at this moment.  Mark these values with 2 and
4030      let user the to override these.  In case there is no command line option
4031      specifying them, we will set the defaults in override_options.  */
4032   if (optimize >= 1)
4033     flag_omit_frame_pointer = 2;
4034   flag_pcc_struct_return = 2;
4035   flag_asynchronous_unwind_tables = 2;
4036   flag_vect_cost_model = 1;
4037 #ifdef SUBTARGET_OPTIMIZATION_OPTIONS
4038   SUBTARGET_OPTIMIZATION_OPTIONS;
4039 #endif
4040 }
4041 \f
4042 /* Decide whether we can make a sibling call to a function.  DECL is the
4043    declaration of the function being targeted by the call and EXP is the
4044    CALL_EXPR representing the call.  */
4045
4046 static bool
4047 ix86_function_ok_for_sibcall (tree decl, tree exp)
4048 {
4049   tree func;
4050   rtx a, b;
4051
4052   /* If we are generating position-independent code, we cannot sibcall
4053      optimize any indirect call, or a direct call to a global function,
4054      as the PLT requires %ebx be live.  */
4055   if (!TARGET_64BIT && flag_pic && (!decl || !targetm.binds_local_p (decl)))
4056     return false;
4057
4058   if (decl)
4059     func = decl;
4060   else
4061     {
4062       func = TREE_TYPE (CALL_EXPR_FN (exp));
4063       if (POINTER_TYPE_P (func))
4064         func = TREE_TYPE (func);
4065     }
4066
4067   /* Check that the return value locations are the same.  Like
4068      if we are returning floats on the 80387 register stack, we cannot
4069      make a sibcall from a function that doesn't return a float to a
4070      function that does or, conversely, from a function that does return
4071      a float to a function that doesn't; the necessary stack adjustment
4072      would not be executed.  This is also the place we notice
4073      differences in the return value ABI.  Note that it is ok for one
4074      of the functions to have void return type as long as the return
4075      value of the other is passed in a register.  */
4076   a = ix86_function_value (TREE_TYPE (exp), func, false);
4077   b = ix86_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)),
4078                            cfun->decl, false);
4079   if (STACK_REG_P (a) || STACK_REG_P (b))
4080     {
4081       if (!rtx_equal_p (a, b))
4082         return false;
4083     }
4084   else if (VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl))))
4085     ;
4086   else if (!rtx_equal_p (a, b))
4087     return false;
4088
4089   /* If this call is indirect, we'll need to be able to use a call-clobbered
4090      register for the address of the target function.  Make sure that all
4091      such registers are not used for passing parameters.  */
4092   if (!decl && !TARGET_64BIT)
4093     {
4094       tree type;
4095
4096       /* We're looking at the CALL_EXPR, we need the type of the function.  */
4097       type = CALL_EXPR_FN (exp);                /* pointer expression */
4098       type = TREE_TYPE (type);                  /* pointer type */
4099       type = TREE_TYPE (type);                  /* function type */
4100
4101       if (ix86_function_regparm (type, NULL) >= 3)
4102         {
4103           /* ??? Need to count the actual number of registers to be used,
4104              not the possible number of registers.  Fix later.  */
4105           return false;
4106         }
4107     }
4108
4109   /* Dllimport'd functions are also called indirectly.  */
4110   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
4111       && !TARGET_64BIT
4112       && decl && DECL_DLLIMPORT_P (decl)
4113       && ix86_function_regparm (TREE_TYPE (decl), NULL) >= 3)
4114     return false;
4115
4116   /* If we need to align the outgoing stack, then sibcalling would
4117      unalign the stack, which may break the called function.  */
4118   if (ix86_incoming_stack_boundary < PREFERRED_STACK_BOUNDARY)
4119     return false;
4120
4121   /* Otherwise okay.  That also includes certain types of indirect calls.  */
4122   return true;
4123 }
4124
4125 /* Handle "cdecl", "stdcall", "fastcall", "regparm" and "sseregparm"
4126    calling convention attributes;
4127    arguments as in struct attribute_spec.handler.  */
4128
4129 static tree
4130 ix86_handle_cconv_attribute (tree *node, tree name,
4131                                    tree args,
4132                                    int flags ATTRIBUTE_UNUSED,
4133                                    bool *no_add_attrs)
4134 {
4135   if (TREE_CODE (*node) != FUNCTION_TYPE
4136       && TREE_CODE (*node) != METHOD_TYPE
4137       && TREE_CODE (*node) != FIELD_DECL
4138       && TREE_CODE (*node) != TYPE_DECL)
4139     {
4140       warning (OPT_Wattributes, "%qs attribute only applies to functions",
4141                IDENTIFIER_POINTER (name));
4142       *no_add_attrs = true;
4143       return NULL_TREE;
4144     }
4145
4146   /* Can combine regparm with all attributes but fastcall.  */
4147   if (is_attribute_p ("regparm", name))
4148     {
4149       tree cst;
4150
4151       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4152         {
4153           error ("fastcall and regparm attributes are not compatible");
4154         }
4155
4156       cst = TREE_VALUE (args);
4157       if (TREE_CODE (cst) != INTEGER_CST)
4158         {
4159           warning (OPT_Wattributes,
4160                    "%qs attribute requires an integer constant argument",
4161                    IDENTIFIER_POINTER (name));
4162           *no_add_attrs = true;
4163         }
4164       else if (compare_tree_int (cst, REGPARM_MAX) > 0)
4165         {
4166           warning (OPT_Wattributes, "argument to %qs attribute larger than %d",
4167                    IDENTIFIER_POINTER (name), REGPARM_MAX);
4168           *no_add_attrs = true;
4169         }
4170
4171       return NULL_TREE;
4172     }
4173
4174   if (TARGET_64BIT)
4175     {
4176       /* Do not warn when emulating the MS ABI.  */
4177       if (TREE_CODE (*node) != FUNCTION_TYPE || ix86_function_type_abi (*node)!=MS_ABI)
4178         warning (OPT_Wattributes, "%qs attribute ignored",
4179                  IDENTIFIER_POINTER (name));
4180       *no_add_attrs = true;
4181       return NULL_TREE;
4182     }
4183
4184   /* Can combine fastcall with stdcall (redundant) and sseregparm.  */
4185   if (is_attribute_p ("fastcall", name))
4186     {
4187       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
4188         {
4189           error ("fastcall and cdecl attributes are not compatible");
4190         }
4191       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
4192         {
4193           error ("fastcall and stdcall attributes are not compatible");
4194         }
4195       if (lookup_attribute ("regparm", TYPE_ATTRIBUTES (*node)))
4196         {
4197           error ("fastcall and regparm attributes are not compatible");
4198         }
4199     }
4200
4201   /* Can combine stdcall with fastcall (redundant), regparm and
4202      sseregparm.  */
4203   else if (is_attribute_p ("stdcall", name))
4204     {
4205       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
4206         {
4207           error ("stdcall and cdecl attributes are not compatible");
4208         }
4209       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4210         {
4211           error ("stdcall and fastcall attributes are not compatible");
4212         }
4213     }
4214
4215   /* Can combine cdecl with regparm and sseregparm.  */
4216   else if (is_attribute_p ("cdecl", name))
4217     {
4218       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
4219         {
4220           error ("stdcall and cdecl attributes are not compatible");
4221         }
4222       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
4223         {
4224           error ("fastcall and cdecl attributes are not compatible");
4225         }
4226     }
4227
4228   /* Can combine sseregparm with all attributes.  */
4229
4230   return NULL_TREE;
4231 }
4232
4233 /* Return 0 if the attributes for two types are incompatible, 1 if they
4234    are compatible, and 2 if they are nearly compatible (which causes a
4235    warning to be generated).  */
4236
4237 static int
4238 ix86_comp_type_attributes (const_tree type1, const_tree type2)
4239 {
4240   /* Check for mismatch of non-default calling convention.  */
4241   const char *const rtdstr = TARGET_RTD ? "cdecl" : "stdcall";
4242
4243   if (TREE_CODE (type1) != FUNCTION_TYPE
4244       && TREE_CODE (type1) != METHOD_TYPE)
4245     return 1;
4246
4247   /* Check for mismatched fastcall/regparm types.  */
4248   if ((!lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type1))
4249        != !lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type2)))
4250       || (ix86_function_regparm (type1, NULL)
4251           != ix86_function_regparm (type2, NULL)))
4252     return 0;
4253
4254   /* Check for mismatched sseregparm types.  */
4255   if (!lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type1))
4256       != !lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type2)))
4257     return 0;
4258
4259   /* Check for mismatched return types (cdecl vs stdcall).  */
4260   if (!lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type1))
4261       != !lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type2)))
4262     return 0;
4263
4264   return 1;
4265 }
4266 \f
4267 /* Return the regparm value for a function with the indicated TYPE and DECL.
4268    DECL may be NULL when calling function indirectly
4269    or considering a libcall.  */
4270
4271 static int
4272 ix86_function_regparm (const_tree type, const_tree decl)
4273 {
4274   tree attr;
4275   int regparm = ix86_regparm;
4276
4277   static bool error_issued;
4278
4279   if (TARGET_64BIT)
4280     {
4281       if (ix86_function_type_abi (type) == DEFAULT_ABI)
4282         return regparm;
4283       return DEFAULT_ABI != SYSV_ABI ? X86_64_REGPARM_MAX : X64_REGPARM_MAX;
4284     }
4285
4286   attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (type));
4287   if (attr)
4288     {
4289       regparm
4290         = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
4291
4292       if (decl && TREE_CODE (decl) == FUNCTION_DECL)
4293         {
4294           /* We can't use regparm(3) for nested functions because
4295              these pass static chain pointer in %ecx register.  */
4296           if (!error_issued && regparm == 3
4297               && decl_function_context (decl)
4298               && !DECL_NO_STATIC_CHAIN (decl))
4299             {
4300               error ("nested functions are limited to 2 register parameters");
4301               error_issued = true;
4302               return 0;
4303             }
4304         }
4305
4306       return regparm;
4307     }
4308
4309   if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
4310     return 2;
4311
4312   /* Use register calling convention for local functions when possible.  */
4313   if (decl && TREE_CODE (decl) == FUNCTION_DECL
4314       && !profile_flag)
4315     {
4316       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
4317       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
4318       if (i && i->local)
4319         {
4320           int local_regparm, globals = 0, regno;
4321           struct function *f;
4322
4323           /* Make sure no regparm register is taken by a
4324              fixed register variable.  */
4325           for (local_regparm = 0; local_regparm < REGPARM_MAX; local_regparm++)
4326             if (fixed_regs[local_regparm])
4327               break;
4328
4329           /* We can't use regparm(3) for nested functions as these use
4330              static chain pointer in third argument.  */
4331           if (local_regparm == 3
4332               && decl_function_context (decl)
4333               && !DECL_NO_STATIC_CHAIN (decl))
4334             local_regparm = 2;
4335
4336           /* If the function realigns its stackpointer, the prologue will
4337              clobber %ecx.  If we've already generated code for the callee,
4338              the callee DECL_STRUCT_FUNCTION is gone, so we fall back to
4339              scanning the attributes for the self-realigning property.  */
4340           f = DECL_STRUCT_FUNCTION (decl);
4341           /* Since current internal arg pointer won't conflict with
4342              parameter passing regs, so no need to change stack
4343              realignment and adjust regparm number.
4344
4345              Each fixed register usage increases register pressure,
4346              so less registers should be used for argument passing.
4347              This functionality can be overriden by an explicit
4348              regparm value.  */
4349           for (regno = 0; regno <= DI_REG; regno++)
4350             if (fixed_regs[regno])
4351               globals++;
4352
4353           local_regparm
4354             = globals < local_regparm ? local_regparm - globals : 0;
4355
4356           if (local_regparm > regparm)
4357             regparm = local_regparm;
4358         }
4359     }
4360
4361   return regparm;
4362 }
4363
4364 /* Return 1 or 2, if we can pass up to SSE_REGPARM_MAX SFmode (1) and
4365    DFmode (2) arguments in SSE registers for a function with the
4366    indicated TYPE and DECL.  DECL may be NULL when calling function
4367    indirectly or considering a libcall.  Otherwise return 0.  */
4368
4369 static int
4370 ix86_function_sseregparm (const_tree type, const_tree decl, bool warn)
4371 {
4372   gcc_assert (!TARGET_64BIT);
4373
4374   /* Use SSE registers to pass SFmode and DFmode arguments if requested
4375      by the sseregparm attribute.  */
4376   if (TARGET_SSEREGPARM
4377       || (type && lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type))))
4378     {
4379       if (!TARGET_SSE)
4380         {
4381           if (warn)
4382             {
4383               if (decl)
4384                 error ("Calling %qD with attribute sseregparm without "
4385                        "SSE/SSE2 enabled", decl);
4386               else
4387                 error ("Calling %qT with attribute sseregparm without "
4388                        "SSE/SSE2 enabled", type);
4389             }
4390           return 0;
4391         }
4392
4393       return 2;
4394     }
4395
4396   /* For local functions, pass up to SSE_REGPARM_MAX SFmode
4397      (and DFmode for SSE2) arguments in SSE registers.  */
4398   if (decl && TARGET_SSE_MATH && !profile_flag)
4399     {
4400       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
4401       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
4402       if (i && i->local)
4403         return TARGET_SSE2 ? 2 : 1;
4404     }
4405
4406   return 0;
4407 }
4408
4409 /* Return true if EAX is live at the start of the function.  Used by
4410    ix86_expand_prologue to determine if we need special help before
4411    calling allocate_stack_worker.  */
4412
4413 static bool
4414 ix86_eax_live_at_start_p (void)
4415 {
4416   /* Cheat.  Don't bother working forward from ix86_function_regparm
4417      to the function type to whether an actual argument is located in
4418      eax.  Instead just look at cfg info, which is still close enough
4419      to correct at this point.  This gives false positives for broken
4420      functions that might use uninitialized data that happens to be
4421      allocated in eax, but who cares?  */
4422   return REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR), 0);
4423 }
4424
4425 /* Value is the number of bytes of arguments automatically
4426    popped when returning from a subroutine call.
4427    FUNDECL is the declaration node of the function (as a tree),
4428    FUNTYPE is the data type of the function (as a tree),
4429    or for a library call it is an identifier node for the subroutine name.
4430    SIZE is the number of bytes of arguments passed on the stack.
4431
4432    On the 80386, the RTD insn may be used to pop them if the number
4433      of args is fixed, but if the number is variable then the caller
4434      must pop them all.  RTD can't be used for library calls now
4435      because the library is compiled with the Unix compiler.
4436    Use of RTD is a selectable option, since it is incompatible with
4437    standard Unix calling sequences.  If the option is not selected,
4438    the caller must always pop the args.
4439
4440    The attribute stdcall is equivalent to RTD on a per module basis.  */
4441
4442 int
4443 ix86_return_pops_args (tree fundecl, tree funtype, int size)
4444 {
4445   int rtd;
4446
4447   /* None of the 64-bit ABIs pop arguments.  */
4448   if (TARGET_64BIT)
4449     return 0;
4450
4451   rtd = TARGET_RTD && (!fundecl || TREE_CODE (fundecl) != IDENTIFIER_NODE);
4452
4453   /* Cdecl functions override -mrtd, and never pop the stack.  */
4454   if (! lookup_attribute ("cdecl", TYPE_ATTRIBUTES (funtype)))
4455     {
4456       /* Stdcall and fastcall functions will pop the stack if not
4457          variable args.  */
4458       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype))
4459           || lookup_attribute ("fastcall", TYPE_ATTRIBUTES (funtype)))
4460         rtd = 1;
4461
4462       if (rtd && ! stdarg_p (funtype))
4463         return size;
4464     }
4465
4466   /* Lose any fake structure return argument if it is passed on the stack.  */
4467   if (aggregate_value_p (TREE_TYPE (funtype), fundecl)
4468       && !KEEP_AGGREGATE_RETURN_POINTER)
4469     {
4470       int nregs = ix86_function_regparm (funtype, fundecl);
4471       if (nregs == 0)
4472         return GET_MODE_SIZE (Pmode);
4473     }
4474
4475   return 0;
4476 }
4477 \f
4478 /* Argument support functions.  */
4479
4480 /* Return true when register may be used to pass function parameters.  */
4481 bool
4482 ix86_function_arg_regno_p (int regno)
4483 {
4484   int i;
4485   const int *parm_regs;
4486
4487   if (!TARGET_64BIT)
4488     {
4489       if (TARGET_MACHO)
4490         return (regno < REGPARM_MAX
4491                 || (TARGET_SSE && SSE_REGNO_P (regno) && !fixed_regs[regno]));
4492       else
4493         return (regno < REGPARM_MAX
4494                 || (TARGET_MMX && MMX_REGNO_P (regno)
4495                     && (regno < FIRST_MMX_REG + MMX_REGPARM_MAX))
4496                 || (TARGET_SSE && SSE_REGNO_P (regno)
4497                     && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX)));
4498     }
4499
4500   if (TARGET_MACHO)
4501     {
4502       if (SSE_REGNO_P (regno) && TARGET_SSE)
4503         return true;
4504     }
4505   else
4506     {
4507       if (TARGET_SSE && SSE_REGNO_P (regno)
4508           && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX))
4509         return true;
4510     }
4511
4512   /* TODO: The function should depend on current function ABI but
4513      builtins.c would need updating then. Therefore we use the
4514      default ABI.  */
4515
4516   /* RAX is used as hidden argument to va_arg functions.  */
4517   if (DEFAULT_ABI == SYSV_ABI && regno == AX_REG)
4518     return true;
4519
4520   if (DEFAULT_ABI == MS_ABI)
4521     parm_regs = x86_64_ms_abi_int_parameter_registers;
4522   else
4523     parm_regs = x86_64_int_parameter_registers;
4524   for (i = 0; i < (DEFAULT_ABI == MS_ABI ? X64_REGPARM_MAX
4525                                          : X86_64_REGPARM_MAX); i++)
4526     if (regno == parm_regs[i])
4527       return true;
4528   return false;
4529 }
4530
4531 /* Return if we do not know how to pass TYPE solely in registers.  */
4532
4533 static bool
4534 ix86_must_pass_in_stack (enum machine_mode mode, const_tree type)
4535 {
4536   if (must_pass_in_stack_var_size_or_pad (mode, type))
4537     return true;
4538
4539   /* For 32-bit, we want TImode aggregates to go on the stack.  But watch out!
4540      The layout_type routine is crafty and tries to trick us into passing
4541      currently unsupported vector types on the stack by using TImode.  */
4542   return (!TARGET_64BIT && mode == TImode
4543           && type && TREE_CODE (type) != VECTOR_TYPE);
4544 }
4545
4546 /* It returns the size, in bytes, of the area reserved for arguments passed
4547    in registers for the function represented by fndecl dependent to the used
4548    abi format.  */
4549 int
4550 ix86_reg_parm_stack_space (const_tree fndecl)
4551 {
4552   int call_abi = SYSV_ABI;
4553   if (fndecl != NULL_TREE && TREE_CODE (fndecl) == FUNCTION_DECL)
4554     call_abi = ix86_function_abi (fndecl);
4555   else
4556     call_abi = ix86_function_type_abi (fndecl);
4557   if (call_abi == MS_ABI)
4558     return 32;
4559   return 0;
4560 }
4561
4562 /* Returns value SYSV_ABI, MS_ABI dependent on fntype, specifying the
4563    call abi used.  */
4564 int
4565 ix86_function_type_abi (const_tree fntype)
4566 {
4567   if (TARGET_64BIT && fntype != NULL)
4568     {
4569       int abi;
4570       if (DEFAULT_ABI == SYSV_ABI)
4571         abi = lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (fntype)) ? MS_ABI : SYSV_ABI;
4572       else
4573         abi = lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (fntype)) ? SYSV_ABI : MS_ABI;
4574
4575       return abi;
4576     }
4577   return DEFAULT_ABI;
4578 }
4579
4580 int
4581 ix86_function_abi (const_tree fndecl)
4582 {
4583   if (! fndecl)
4584     return DEFAULT_ABI;
4585   return ix86_function_type_abi (TREE_TYPE (fndecl));
4586 }
4587
4588 /* Returns value SYSV_ABI, MS_ABI dependent on cfun, specifying the
4589    call abi used.  */
4590 int
4591 ix86_cfun_abi (void)
4592 {
4593   if (! cfun || ! TARGET_64BIT)
4594     return DEFAULT_ABI;
4595   return cfun->machine->call_abi;
4596 }
4597
4598 /* regclass.c  */
4599 extern void init_regs (void);
4600
4601 /* Implementation of call abi switching target hook. Specific to FNDECL
4602    the specific call register sets are set. See also CONDITIONAL_REGISTER_USAGE
4603    for more details.  */
4604 void
4605 ix86_call_abi_override (const_tree fndecl)
4606 {
4607   if (fndecl == NULL_TREE)
4608     cfun->machine->call_abi = DEFAULT_ABI;
4609   else
4610     cfun->machine->call_abi = ix86_function_type_abi (TREE_TYPE (fndecl));
4611 }
4612
4613 /* MS and SYSV ABI have different set of call used registers.  Avoid expensive
4614    re-initialization of init_regs each time we switch function context since
4615    this is needed only during RTL expansion.  */
4616 static void
4617 ix86_maybe_switch_abi (void)
4618 {
4619   if (TARGET_64BIT &&
4620       call_used_regs[4 /*RSI*/] ==  (cfun->machine->call_abi == MS_ABI))
4621     reinit_regs ();
4622 }
4623
4624 /* Initialize a variable CUM of type CUMULATIVE_ARGS
4625    for a call to a function whose data type is FNTYPE.
4626    For a library call, FNTYPE is 0.  */
4627
4628 void
4629 init_cumulative_args (CUMULATIVE_ARGS *cum,  /* Argument info to initialize */
4630                       tree fntype,      /* tree ptr for function decl */
4631                       rtx libname,      /* SYMBOL_REF of library name or 0 */
4632                       tree fndecl)
4633 {
4634   struct cgraph_local_info *i = fndecl ? cgraph_local_info (fndecl) : NULL;
4635   memset (cum, 0, sizeof (*cum));
4636
4637   if (fndecl)
4638    cum->call_abi = ix86_function_abi (fndecl);
4639   else
4640    cum->call_abi = ix86_function_type_abi (fntype);
4641   /* Set up the number of registers to use for passing arguments.  */
4642
4643   if (cum->call_abi == MS_ABI && !ACCUMULATE_OUTGOING_ARGS)
4644     sorry ("ms_abi attribute require -maccumulate-outgoing-args or subtarget optimization implying it");
4645   cum->nregs = ix86_regparm;
4646   if (TARGET_64BIT)
4647     {
4648       if (cum->call_abi != DEFAULT_ABI)
4649         cum->nregs = DEFAULT_ABI != SYSV_ABI ? X86_64_REGPARM_MAX
4650                                              : X64_REGPARM_MAX;
4651     }
4652   if (TARGET_SSE)
4653     {
4654       cum->sse_nregs = SSE_REGPARM_MAX;
4655       if (TARGET_64BIT)
4656         {
4657           if (cum->call_abi != DEFAULT_ABI)
4658             cum->sse_nregs = DEFAULT_ABI != SYSV_ABI ? X86_64_SSE_REGPARM_MAX
4659                                                      : X64_SSE_REGPARM_MAX;
4660         }
4661     }
4662   if (TARGET_MMX)
4663     cum->mmx_nregs = MMX_REGPARM_MAX;
4664   cum->warn_avx = true;
4665   cum->warn_sse = true;
4666   cum->warn_mmx = true;
4667
4668   /* Because type might mismatch in between caller and callee, we need to
4669      use actual type of function for local calls.
4670      FIXME: cgraph_analyze can be told to actually record if function uses
4671      va_start so for local functions maybe_vaarg can be made aggressive
4672      helping K&R code.
4673      FIXME: once typesytem is fixed, we won't need this code anymore.  */
4674   if (i && i->local)
4675     fntype = TREE_TYPE (fndecl);
4676   cum->maybe_vaarg = (fntype
4677                       ? (!prototype_p (fntype) || stdarg_p (fntype))
4678                       : !libname);
4679
4680   if (!TARGET_64BIT)
4681     {
4682       /* If there are variable arguments, then we won't pass anything
4683          in registers in 32-bit mode. */
4684       if (stdarg_p (fntype))
4685         {
4686           cum->nregs = 0;
4687           cum->sse_nregs = 0;
4688           cum->mmx_nregs = 0;
4689           cum->warn_avx = 0;
4690           cum->warn_sse = 0;
4691           cum->warn_mmx = 0;
4692           return;
4693         }
4694
4695       /* Use ecx and edx registers if function has fastcall attribute,
4696          else look for regparm information.  */
4697       if (fntype)
4698         {
4699           if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)))
4700             {
4701               cum->nregs = 2;
4702               cum->fastcall = 1;
4703             }
4704           else
4705             cum->nregs = ix86_function_regparm (fntype, fndecl);
4706         }
4707
4708       /* Set up the number of SSE registers used for passing SFmode
4709          and DFmode arguments.  Warn for mismatching ABI.  */
4710       cum->float_in_sse = ix86_function_sseregparm (fntype, fndecl, true);
4711     }
4712 }
4713
4714 /* Return the "natural" mode for TYPE.  In most cases, this is just TYPE_MODE.
4715    But in the case of vector types, it is some vector mode.
4716
4717    When we have only some of our vector isa extensions enabled, then there
4718    are some modes for which vector_mode_supported_p is false.  For these
4719    modes, the generic vector support in gcc will choose some non-vector mode
4720    in order to implement the type.  By computing the natural mode, we'll
4721    select the proper ABI location for the operand and not depend on whatever
4722    the middle-end decides to do with these vector types.
4723
4724    The midde-end can't deal with the vector types > 16 bytes.  In this
4725    case, we return the original mode and warn ABI change if CUM isn't
4726    NULL.  */
4727
4728 static enum machine_mode
4729 type_natural_mode (const_tree type, CUMULATIVE_ARGS *cum)
4730 {
4731   enum machine_mode mode = TYPE_MODE (type);
4732
4733   if (TREE_CODE (type) == VECTOR_TYPE && !VECTOR_MODE_P (mode))
4734     {
4735       HOST_WIDE_INT size = int_size_in_bytes (type);
4736       if ((size == 8 || size == 16 || size == 32)
4737           /* ??? Generic code allows us to create width 1 vectors.  Ignore.  */
4738           && TYPE_VECTOR_SUBPARTS (type) > 1)
4739         {
4740           enum machine_mode innermode = TYPE_MODE (TREE_TYPE (type));
4741
4742           if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
4743             mode = MIN_MODE_VECTOR_FLOAT;
4744           else
4745             mode = MIN_MODE_VECTOR_INT;
4746
4747           /* Get the mode which has this inner mode and number of units.  */
4748           for (; mode != VOIDmode; mode = GET_MODE_WIDER_MODE (mode))
4749             if (GET_MODE_NUNITS (mode) == TYPE_VECTOR_SUBPARTS (type)
4750                 && GET_MODE_INNER (mode) == innermode)
4751               {
4752                 if (size == 32 && !TARGET_AVX)
4753                   {
4754                     static bool warnedavx;
4755
4756                     if (cum
4757                         && !warnedavx 
4758                         && cum->warn_avx)
4759                       {
4760                         warnedavx = true;
4761                         warning (0, "AVX vector argument without AVX "
4762                                  " enabled changes the ABI");
4763                       }
4764                     return TYPE_MODE (type);
4765                   }
4766                 else
4767                   return mode;
4768               }
4769
4770           gcc_unreachable ();
4771         }
4772     }
4773
4774   return mode;
4775 }
4776
4777 /* We want to pass a value in REGNO whose "natural" mode is MODE.  However,
4778    this may not agree with the mode that the type system has chosen for the
4779    register, which is ORIG_MODE.  If ORIG_MODE is not BLKmode, then we can
4780    go ahead and use it.  Otherwise we have to build a PARALLEL instead.  */
4781
4782 static rtx
4783 gen_reg_or_parallel (enum machine_mode mode, enum machine_mode orig_mode,
4784                      unsigned int regno)
4785 {
4786   rtx tmp;
4787
4788   if (orig_mode != BLKmode)
4789     tmp = gen_rtx_REG (orig_mode, regno);
4790   else
4791     {
4792       tmp = gen_rtx_REG (mode, regno);
4793       tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp, const0_rtx);
4794       tmp = gen_rtx_PARALLEL (orig_mode, gen_rtvec (1, tmp));
4795     }
4796
4797   return tmp;
4798 }
4799
4800 /* x86-64 register passing implementation.  See x86-64 ABI for details.  Goal
4801    of this code is to classify each 8bytes of incoming argument by the register
4802    class and assign registers accordingly.  */
4803
4804 /* Return the union class of CLASS1 and CLASS2.
4805    See the x86-64 PS ABI for details.  */
4806
4807 static enum x86_64_reg_class
4808 merge_classes (enum x86_64_reg_class class1, enum x86_64_reg_class class2)
4809 {
4810   /* Rule #1: If both classes are equal, this is the resulting class.  */
4811   if (class1 == class2)
4812     return class1;
4813
4814   /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
4815      the other class.  */
4816   if (class1 == X86_64_NO_CLASS)
4817     return class2;
4818   if (class2 == X86_64_NO_CLASS)
4819     return class1;
4820
4821   /* Rule #3: If one of the classes is MEMORY, the result is MEMORY.  */
4822   if (class1 == X86_64_MEMORY_CLASS || class2 == X86_64_MEMORY_CLASS)
4823     return X86_64_MEMORY_CLASS;
4824
4825   /* Rule #4: If one of the classes is INTEGER, the result is INTEGER.  */
4826   if ((class1 == X86_64_INTEGERSI_CLASS && class2 == X86_64_SSESF_CLASS)
4827       || (class2 == X86_64_INTEGERSI_CLASS && class1 == X86_64_SSESF_CLASS))
4828     return X86_64_INTEGERSI_CLASS;
4829   if (class1 == X86_64_INTEGER_CLASS || class1 == X86_64_INTEGERSI_CLASS
4830       || class2 == X86_64_INTEGER_CLASS || class2 == X86_64_INTEGERSI_CLASS)
4831     return X86_64_INTEGER_CLASS;
4832
4833   /* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class,
4834      MEMORY is used.  */
4835   if (class1 == X86_64_X87_CLASS
4836       || class1 == X86_64_X87UP_CLASS
4837       || class1 == X86_64_COMPLEX_X87_CLASS
4838       || class2 == X86_64_X87_CLASS
4839       || class2 == X86_64_X87UP_CLASS
4840       || class2 == X86_64_COMPLEX_X87_CLASS)
4841     return X86_64_MEMORY_CLASS;
4842
4843   /* Rule #6: Otherwise class SSE is used.  */
4844   return X86_64_SSE_CLASS;
4845 }
4846
4847 /* Classify the argument of type TYPE and mode MODE.
4848    CLASSES will be filled by the register class used to pass each word
4849    of the operand.  The number of words is returned.  In case the parameter
4850    should be passed in memory, 0 is returned. As a special case for zero
4851    sized containers, classes[0] will be NO_CLASS and 1 is returned.
4852
4853    BIT_OFFSET is used internally for handling records and specifies offset
4854    of the offset in bits modulo 256 to avoid overflow cases.
4855
4856    See the x86-64 PS ABI for details.
4857 */
4858
4859 static int
4860 classify_argument (enum machine_mode mode, const_tree type,
4861                    enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset)
4862 {
4863   HOST_WIDE_INT bytes =
4864     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
4865   int words = (bytes + (bit_offset % 64) / 8 + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4866
4867   /* Variable sized entities are always passed/returned in memory.  */
4868   if (bytes < 0)
4869     return 0;
4870
4871   if (mode != VOIDmode
4872       && targetm.calls.must_pass_in_stack (mode, type))
4873     return 0;
4874
4875   if (type && AGGREGATE_TYPE_P (type))
4876     {
4877       int i;
4878       tree field;
4879       enum x86_64_reg_class subclasses[MAX_CLASSES];
4880
4881       /* On x86-64 we pass structures larger than 32 bytes on the stack.  */
4882       if (bytes > 32)
4883         return 0;
4884
4885       for (i = 0; i < words; i++)
4886         classes[i] = X86_64_NO_CLASS;
4887
4888       /* Zero sized arrays or structures are NO_CLASS.  We return 0 to
4889          signalize memory class, so handle it as special case.  */
4890       if (!words)
4891         {
4892           classes[0] = X86_64_NO_CLASS;
4893           return 1;
4894         }
4895
4896       /* Classify each field of record and merge classes.  */
4897       switch (TREE_CODE (type))
4898         {
4899         case RECORD_TYPE:
4900           /* And now merge the fields of structure.  */
4901           for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4902             {
4903               if (TREE_CODE (field) == FIELD_DECL)
4904                 {
4905                   int num;
4906
4907                   if (TREE_TYPE (field) == error_mark_node)
4908                     continue;
4909
4910                   /* Bitfields are always classified as integer.  Handle them
4911                      early, since later code would consider them to be
4912                      misaligned integers.  */
4913                   if (DECL_BIT_FIELD (field))
4914                     {
4915                       for (i = (int_bit_position (field) + (bit_offset % 64)) / 8 / 8;
4916                            i < ((int_bit_position (field) + (bit_offset % 64))
4917                                 + tree_low_cst (DECL_SIZE (field), 0)
4918                                 + 63) / 8 / 8; i++)
4919                         classes[i] =
4920                           merge_classes (X86_64_INTEGER_CLASS,
4921                                          classes[i]);
4922                     }
4923                   else
4924                     {
4925                       num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
4926                                                TREE_TYPE (field), subclasses,
4927                                                (int_bit_position (field)
4928                                                 + bit_offset) % 256);
4929                       if (!num)
4930                         return 0;
4931                       for (i = 0; i < num; i++)
4932                         {
4933                           int pos =
4934                             (int_bit_position (field) + (bit_offset % 64)) / 8 / 8;
4935                           classes[i + pos] =
4936                             merge_classes (subclasses[i], classes[i + pos]);
4937                         }
4938                     }
4939                 }
4940             }
4941           break;
4942
4943         case ARRAY_TYPE:
4944           /* Arrays are handled as small records.  */
4945           {
4946             int num;
4947             num = classify_argument (TYPE_MODE (TREE_TYPE (type)),
4948                                      TREE_TYPE (type), subclasses, bit_offset);
4949             if (!num)
4950               return 0;
4951
4952             /* The partial classes are now full classes.  */
4953             if (subclasses[0] == X86_64_SSESF_CLASS && bytes != 4)
4954               subclasses[0] = X86_64_SSE_CLASS;
4955             if (subclasses[0] == X86_64_INTEGERSI_CLASS
4956                 && !((bit_offset % 64) == 0 && bytes == 4))
4957               subclasses[0] = X86_64_INTEGER_CLASS;
4958
4959             for (i = 0; i < words; i++)
4960               classes[i] = subclasses[i % num];
4961
4962             break;
4963           }
4964         case UNION_TYPE:
4965         case QUAL_UNION_TYPE:
4966           /* Unions are similar to RECORD_TYPE but offset is always 0.
4967              */
4968           for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4969             {
4970               if (TREE_CODE (field) == FIELD_DECL)
4971                 {
4972                   int num;
4973
4974                   if (TREE_TYPE (field) == error_mark_node)
4975                     continue;
4976
4977                   num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
4978                                            TREE_TYPE (field), subclasses,
4979                                            bit_offset);
4980                   if (!num)
4981                     return 0;
4982                   for (i = 0; i < num; i++)
4983                     classes[i] = merge_classes (subclasses[i], classes[i]);
4984                 }
4985             }
4986           break;
4987
4988         default:
4989           gcc_unreachable ();
4990         }
4991
4992       if (words > 2)
4993         {
4994           /* When size > 16 bytes, if the first one isn't
4995              X86_64_SSE_CLASS or any other ones aren't
4996              X86_64_SSEUP_CLASS, everything should be passed in
4997              memory.  */
4998           if (classes[0] != X86_64_SSE_CLASS)
4999               return 0;
5000
5001           for (i = 1; i < words; i++)
5002             if (classes[i] != X86_64_SSEUP_CLASS)
5003               return 0;
5004         }
5005
5006       /* Final merger cleanup.  */
5007       for (i = 0; i < words; i++)
5008         {
5009           /* If one class is MEMORY, everything should be passed in
5010              memory.  */
5011           if (classes[i] == X86_64_MEMORY_CLASS)
5012             return 0;
5013
5014           /* The X86_64_SSEUP_CLASS should be always preceded by
5015              X86_64_SSE_CLASS or X86_64_SSEUP_CLASS.  */
5016           if (classes[i] == X86_64_SSEUP_CLASS
5017               && classes[i - 1] != X86_64_SSE_CLASS
5018               && classes[i - 1] != X86_64_SSEUP_CLASS)
5019             {
5020               /* The first one should never be X86_64_SSEUP_CLASS.  */
5021               gcc_assert (i != 0);
5022               classes[i] = X86_64_SSE_CLASS;
5023             }
5024
5025           /*  If X86_64_X87UP_CLASS isn't preceded by X86_64_X87_CLASS,
5026                everything should be passed in memory.  */
5027           if (classes[i] == X86_64_X87UP_CLASS
5028               && (classes[i - 1] != X86_64_X87_CLASS))
5029             {
5030               static bool warned;
5031
5032               /* The first one should never be X86_64_X87UP_CLASS.  */
5033               gcc_assert (i != 0);
5034               if (!warned && warn_psabi)
5035                 {
5036                   warned = true;
5037                   inform (input_location,
5038                           "The ABI of passing union with long double"
5039                           " has changed in GCC 4.4");
5040                 }
5041               return 0;
5042             }
5043         }
5044       return words;
5045     }
5046
5047   /* Compute alignment needed.  We align all types to natural boundaries with
5048      exception of XFmode that is aligned to 64bits.  */
5049   if (mode != VOIDmode && mode != BLKmode)
5050     {
5051       int mode_alignment = GET_MODE_BITSIZE (mode);
5052
5053       if (mode == XFmode)
5054         mode_alignment = 128;
5055       else if (mode == XCmode)
5056         mode_alignment = 256;
5057       if (COMPLEX_MODE_P (mode))
5058         mode_alignment /= 2;
5059       /* Misaligned fields are always returned in memory.  */
5060       if (bit_offset % mode_alignment)
5061         return 0;
5062     }
5063
5064   /* for V1xx modes, just use the base mode */
5065   if (VECTOR_MODE_P (mode) && mode != V1DImode
5066       && GET_MODE_SIZE (GET_MODE_INNER (mode)) == bytes)
5067     mode = GET_MODE_INNER (mode);
5068
5069   /* Classification of atomic types.  */
5070   switch (mode)
5071     {
5072     case SDmode:
5073     case DDmode:
5074       classes[0] = X86_64_SSE_CLASS;
5075       return 1;
5076     case TDmode:
5077       classes[0] = X86_64_SSE_CLASS;
5078       classes[1] = X86_64_SSEUP_CLASS;
5079       return 2;
5080     case DImode:
5081     case SImode:
5082     case HImode:
5083     case QImode:
5084     case CSImode:
5085     case CHImode:
5086     case CQImode:
5087       {
5088         int size = (bit_offset % 64)+ (int) GET_MODE_BITSIZE (mode);
5089
5090         if (size <= 32)
5091           {
5092             classes[0] = X86_64_INTEGERSI_CLASS;
5093             return 1;
5094           }
5095         else if (size <= 64)
5096           {
5097             classes[0] = X86_64_INTEGER_CLASS;
5098             return 1;
5099           }
5100         else if (size <= 64+32)
5101           {
5102             classes[0] = X86_64_INTEGER_CLASS;
5103             classes[1] = X86_64_INTEGERSI_CLASS;
5104             return 2;
5105           }
5106         else if (size <= 64+64)
5107           {
5108             classes[0] = classes[1] = X86_64_INTEGER_CLASS;
5109             return 2;
5110           }
5111         else
5112           gcc_unreachable ();
5113       }
5114     case CDImode:
5115     case TImode:
5116       classes[0] = classes[1] = X86_64_INTEGER_CLASS;
5117       return 2;
5118     case CTImode:
5119     case COImode:
5120     case OImode:
5121       return 0;
5122     case SFmode:
5123       if (!(bit_offset % 64))
5124         classes[0] = X86_64_SSESF_CLASS;
5125       else
5126         classes[0] = X86_64_SSE_CLASS;
5127       return 1;
5128     case DFmode:
5129       classes[0] = X86_64_SSEDF_CLASS;
5130       return 1;
5131     case XFmode:
5132       classes[0] = X86_64_X87_CLASS;
5133       classes[1] = X86_64_X87UP_CLASS;
5134       return 2;
5135     case TFmode:
5136       classes[0] = X86_64_SSE_CLASS;
5137       classes[1] = X86_64_SSEUP_CLASS;
5138       return 2;
5139     case SCmode:
5140       classes[0] = X86_64_SSE_CLASS;
5141       return 1;
5142     case DCmode:
5143       classes[0] = X86_64_SSEDF_CLASS;
5144       classes[1] = X86_64_SSEDF_CLASS;
5145       return 2;
5146     case XCmode:
5147       classes[0] = X86_64_COMPLEX_X87_CLASS;
5148       return 1;
5149     case TCmode:
5150       /* This modes is larger than 16 bytes.  */
5151       return 0;
5152     case V8SFmode:
5153     case V8SImode:
5154     case V32QImode:
5155     case V16HImode:
5156     case V4DFmode:
5157     case V4DImode:
5158       classes[0] = X86_64_SSE_CLASS;
5159       classes[1] = X86_64_SSEUP_CLASS;
5160       classes[2] = X86_64_SSEUP_CLASS;
5161       classes[3] = X86_64_SSEUP_CLASS;
5162       return 4;
5163     case V4SFmode:
5164     case V4SImode:
5165     case V16QImode:
5166     case V8HImode:
5167     case V2DFmode:
5168     case V2DImode:
5169       classes[0] = X86_64_SSE_CLASS;
5170       classes[1] = X86_64_SSEUP_CLASS;
5171       return 2;
5172     case V1DImode:
5173     case V2SFmode:
5174     case V2SImode:
5175     case V4HImode:
5176     case V8QImode:
5177       classes[0] = X86_64_SSE_CLASS;
5178       return 1;
5179     case BLKmode:
5180     case VOIDmode:
5181       return 0;
5182     default:
5183       gcc_assert (VECTOR_MODE_P (mode));
5184
5185       if (bytes > 16)
5186         return 0;
5187
5188       gcc_assert (GET_MODE_CLASS (GET_MODE_INNER (mode)) == MODE_INT);
5189
5190       if (bit_offset + GET_MODE_BITSIZE (mode) <= 32)
5191         classes[0] = X86_64_INTEGERSI_CLASS;
5192       else
5193         classes[0] = X86_64_INTEGER_CLASS;
5194       classes[1] = X86_64_INTEGER_CLASS;
5195       return 1 + (bytes > 8);
5196     }
5197 }
5198
5199 /* Examine the argument and return set number of register required in each
5200    class.  Return 0 iff parameter should be passed in memory.  */
5201 static int
5202 examine_argument (enum machine_mode mode, const_tree type, int in_return,
5203                   int *int_nregs, int *sse_nregs)
5204 {
5205   enum x86_64_reg_class regclass[MAX_CLASSES];
5206   int n = classify_argument (mode, type, regclass, 0);
5207
5208   *int_nregs = 0;
5209   *sse_nregs = 0;
5210   if (!n)
5211     return 0;
5212   for (n--; n >= 0; n--)
5213     switch (regclass[n])
5214       {
5215       case X86_64_INTEGER_CLASS:
5216       case X86_64_INTEGERSI_CLASS:
5217         (*int_nregs)++;
5218         break;
5219       case X86_64_SSE_CLASS:
5220       case X86_64_SSESF_CLASS:
5221       case X86_64_SSEDF_CLASS:
5222         (*sse_nregs)++;
5223         break;
5224       case X86_64_NO_CLASS:
5225       case X86_64_SSEUP_CLASS:
5226         break;
5227       case X86_64_X87_CLASS:
5228       case X86_64_X87UP_CLASS:
5229         if (!in_return)
5230           return 0;
5231         break;
5232       case X86_64_COMPLEX_X87_CLASS:
5233         return in_return ? 2 : 0;
5234       case X86_64_MEMORY_CLASS:
5235         gcc_unreachable ();
5236       }
5237   return 1;
5238 }
5239
5240 /* Construct container for the argument used by GCC interface.  See
5241    FUNCTION_ARG for the detailed description.  */
5242
5243 static rtx
5244 construct_container (enum machine_mode mode, enum machine_mode orig_mode,
5245                      const_tree type, int in_return, int nintregs, int nsseregs,
5246                      const int *intreg, int sse_regno)
5247 {
5248   /* The following variables hold the static issued_error state.  */
5249   static bool issued_sse_arg_error;
5250   static bool issued_sse_ret_error;
5251   static bool issued_x87_ret_error;
5252
5253   enum machine_mode tmpmode;
5254   int bytes =
5255     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
5256   enum x86_64_reg_class regclass[MAX_CLASSES];
5257   int n;
5258   int i;
5259   int nexps = 0;
5260   int needed_sseregs, needed_intregs;
5261   rtx exp[MAX_CLASSES];
5262   rtx ret;
5263
5264   n = classify_argument (mode, type, regclass, 0);
5265   if (!n)
5266     return NULL;
5267   if (!examine_argument (mode, type, in_return, &needed_intregs,
5268                          &needed_sseregs))
5269     return NULL;
5270   if (needed_intregs > nintregs || needed_sseregs > nsseregs)
5271     return NULL;
5272
5273   /* We allowed the user to turn off SSE for kernel mode.  Don't crash if
5274      some less clueful developer tries to use floating-point anyway.  */
5275   if (needed_sseregs && !TARGET_SSE)
5276     {
5277       if (in_return)
5278         {
5279           if (!issued_sse_ret_error)
5280             {
5281               error ("SSE register return with SSE disabled");
5282               issued_sse_ret_error = true;
5283             }
5284         }
5285       else if (!issued_sse_arg_error)
5286         {
5287           error ("SSE register argument with SSE disabled");
5288           issued_sse_arg_error = true;
5289         }
5290       return NULL;
5291     }
5292
5293   /* Likewise, error if the ABI requires us to return values in the
5294      x87 registers and the user specified -mno-80387.  */
5295   if (!TARGET_80387 && in_return)
5296     for (i = 0; i < n; i++)
5297       if (regclass[i] == X86_64_X87_CLASS
5298           || regclass[i] == X86_64_X87UP_CLASS
5299           || regclass[i] == X86_64_COMPLEX_X87_CLASS)
5300         {
5301           if (!issued_x87_ret_error)
5302             {
5303               error ("x87 register return with x87 disabled");
5304               issued_x87_ret_error = true;
5305             }
5306           return NULL;
5307         }
5308
5309   /* First construct simple cases.  Avoid SCmode, since we want to use
5310      single register to pass this type.  */
5311   if (n == 1 && mode != SCmode)
5312     switch (regclass[0])
5313       {
5314       case X86_64_INTEGER_CLASS:
5315       case X86_64_INTEGERSI_CLASS:
5316         return gen_rtx_REG (mode, intreg[0]);
5317       case X86_64_SSE_CLASS:
5318       case X86_64_SSESF_CLASS:
5319       case X86_64_SSEDF_CLASS:
5320         return gen_reg_or_parallel (mode, orig_mode, SSE_REGNO (sse_regno));
5321       case X86_64_X87_CLASS:
5322       case X86_64_COMPLEX_X87_CLASS:
5323         return gen_rtx_REG (mode, FIRST_STACK_REG);
5324       case X86_64_NO_CLASS:
5325         /* Zero sized array, struct or class.  */
5326         return NULL;
5327       default:
5328         gcc_unreachable ();
5329       }
5330   if (n == 2 && regclass[0] == X86_64_SSE_CLASS
5331       && regclass[1] == X86_64_SSEUP_CLASS && mode != BLKmode)
5332     return gen_rtx_REG (mode, SSE_REGNO (sse_regno));
5333   if (n == 4
5334       && regclass[0] == X86_64_SSE_CLASS
5335       && regclass[1] == X86_64_SSEUP_CLASS
5336       && regclass[2] == X86_64_SSEUP_CLASS
5337       && regclass[3] == X86_64_SSEUP_CLASS
5338       && mode != BLKmode)
5339     return gen_rtx_REG (mode, SSE_REGNO (sse_regno));
5340
5341   if (n == 2
5342       && regclass[0] == X86_64_X87_CLASS && regclass[1] == X86_64_X87UP_CLASS)
5343     return gen_rtx_REG (XFmode, FIRST_STACK_REG);
5344   if (n == 2 && regclass[0] == X86_64_INTEGER_CLASS
5345       && regclass[1] == X86_64_INTEGER_CLASS
5346       && (mode == CDImode || mode == TImode || mode == TFmode)
5347       && intreg[0] + 1 == intreg[1])
5348     return gen_rtx_REG (mode, intreg[0]);
5349
5350   /* Otherwise figure out the entries of the PARALLEL.  */
5351   for (i = 0; i < n; i++)
5352     {
5353       int pos;
5354
5355       switch (regclass[i])
5356         {
5357           case X86_64_NO_CLASS:
5358             break;
5359           case X86_64_INTEGER_CLASS:
5360           case X86_64_INTEGERSI_CLASS:
5361             /* Merge TImodes on aligned occasions here too.  */
5362             if (i * 8 + 8 > bytes)
5363               tmpmode = mode_for_size ((bytes - i * 8) * BITS_PER_UNIT, MODE_INT, 0);
5364             else if (regclass[i] == X86_64_INTEGERSI_CLASS)
5365               tmpmode = SImode;
5366             else
5367               tmpmode = DImode;
5368             /* We've requested 24 bytes we don't have mode for.  Use DImode.  */
5369             if (tmpmode == BLKmode)
5370               tmpmode = DImode;
5371             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5372                                                gen_rtx_REG (tmpmode, *intreg),
5373                                                GEN_INT (i*8));
5374             intreg++;
5375             break;
5376           case X86_64_SSESF_CLASS:
5377             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5378                                                gen_rtx_REG (SFmode,
5379                                                             SSE_REGNO (sse_regno)),
5380                                                GEN_INT (i*8));
5381             sse_regno++;
5382             break;
5383           case X86_64_SSEDF_CLASS:
5384             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5385                                                gen_rtx_REG (DFmode,
5386                                                             SSE_REGNO (sse_regno)),
5387                                                GEN_INT (i*8));
5388             sse_regno++;
5389             break;
5390           case X86_64_SSE_CLASS:
5391             pos = i;
5392             switch (n)
5393               {
5394               case 1:
5395                 tmpmode = DImode;
5396                 break;
5397               case 2:
5398                 if (i == 0 && regclass[1] == X86_64_SSEUP_CLASS)
5399                   {
5400                     tmpmode = TImode;
5401                     i++;
5402                   }
5403                 else
5404                   tmpmode = DImode;
5405                 break;
5406               case 4:
5407                 gcc_assert (i == 0
5408                             && regclass[1] == X86_64_SSEUP_CLASS
5409                             && regclass[2] == X86_64_SSEUP_CLASS
5410                             && regclass[3] == X86_64_SSEUP_CLASS);
5411                 tmpmode = OImode;
5412                 i += 3;
5413                 break;
5414               default:
5415                 gcc_unreachable ();
5416               }
5417             exp [nexps++] = gen_rtx_EXPR_LIST (VOIDmode,
5418                                                gen_rtx_REG (tmpmode,
5419                                                             SSE_REGNO (sse_regno)),
5420                                                GEN_INT (pos*8));
5421             sse_regno++;
5422             break;
5423           default:
5424             gcc_unreachable ();
5425         }
5426     }
5427
5428   /* Empty aligned struct, union or class.  */
5429   if (nexps == 0)
5430     return NULL;
5431
5432   ret =  gen_rtx_PARALLEL (mode, rtvec_alloc (nexps));
5433   for (i = 0; i < nexps; i++)
5434     XVECEXP (ret, 0, i) = exp [i];
5435   return ret;
5436 }
5437
5438 /* Update the data in CUM to advance over an argument of mode MODE
5439    and data type TYPE.  (TYPE is null for libcalls where that information
5440    may not be available.)  */
5441
5442 static void
5443 function_arg_advance_32 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5444                          tree type, HOST_WIDE_INT bytes, HOST_WIDE_INT words)
5445 {
5446   switch (mode)
5447     {
5448     default:
5449       break;
5450
5451     case BLKmode:
5452       if (bytes < 0)
5453         break;
5454       /* FALLTHRU */
5455
5456     case DImode:
5457     case SImode:
5458     case HImode:
5459     case QImode:
5460       cum->words += words;
5461       cum->nregs -= words;
5462       cum->regno += words;
5463
5464       if (cum->nregs <= 0)
5465         {
5466           cum->nregs = 0;
5467           cum->regno = 0;
5468         }
5469       break;
5470
5471     case DFmode:
5472       if (cum->float_in_sse < 2)
5473         break;
5474     case SFmode:
5475       if (cum->float_in_sse < 1)
5476         break;
5477       /* FALLTHRU */
5478
5479     case OImode:
5480     case V8SFmode:
5481     case V8SImode:
5482     case V32QImode:
5483     case V16HImode:
5484     case V4DFmode:
5485     case V4DImode:
5486     case TImode:
5487     case V16QImode:
5488     case V8HImode:
5489     case V4SImode:
5490     case V2DImode:
5491     case V4SFmode:
5492     case V2DFmode:
5493       if (!type || !AGGREGATE_TYPE_P (type))
5494         {
5495           cum->sse_words += words;
5496           cum->sse_nregs -= 1;
5497           cum->sse_regno += 1;
5498           if (cum->sse_nregs <= 0)
5499             {
5500               cum->sse_nregs = 0;
5501               cum->sse_regno = 0;
5502             }
5503         }
5504       break;
5505
5506     case V8QImode:
5507     case V4HImode:
5508     case V2SImode:
5509     case V2SFmode:
5510     case V1DImode:
5511       if (!type || !AGGREGATE_TYPE_P (type))
5512         {
5513           cum->mmx_words += words;
5514           cum->mmx_nregs -= 1;
5515           cum->mmx_regno += 1;
5516           if (cum->mmx_nregs <= 0)
5517             {
5518               cum->mmx_nregs = 0;
5519               cum->mmx_regno = 0;
5520             }
5521         }
5522       break;
5523     }
5524 }
5525
5526 static void
5527 function_arg_advance_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5528                          tree type, HOST_WIDE_INT words, int named)
5529 {
5530   int int_nregs, sse_nregs;
5531
5532   /* Unnamed 256bit vector mode parameters are passed on stack.  */
5533   if (!named && VALID_AVX256_REG_MODE (mode))
5534     return;
5535
5536   if (!examine_argument (mode, type, 0, &int_nregs, &sse_nregs))
5537     cum->words += words;
5538   else if (sse_nregs <= cum->sse_nregs && int_nregs <= cum->nregs)
5539     {
5540       cum->nregs -= int_nregs;
5541       cum->sse_nregs -= sse_nregs;
5542       cum->regno += int_nregs;
5543       cum->sse_regno += sse_nregs;
5544     }
5545   else
5546     cum->words += words;
5547 }
5548
5549 static void
5550 function_arg_advance_ms_64 (CUMULATIVE_ARGS *cum, HOST_WIDE_INT bytes,
5551                             HOST_WIDE_INT words)
5552 {
5553   /* Otherwise, this should be passed indirect.  */
5554   gcc_assert (bytes == 1 || bytes == 2 || bytes == 4 || bytes == 8);
5555
5556   cum->words += words;
5557   if (cum->nregs > 0)
5558     {
5559       cum->nregs -= 1;
5560       cum->regno += 1;
5561     }
5562 }
5563
5564 void
5565 function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5566                       tree type, int named)
5567 {
5568   HOST_WIDE_INT bytes, words;
5569
5570   if (mode == BLKmode)
5571     bytes = int_size_in_bytes (type);
5572   else
5573     bytes = GET_MODE_SIZE (mode);
5574   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5575
5576   if (type)
5577     mode = type_natural_mode (type, NULL);
5578
5579   if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
5580     function_arg_advance_ms_64 (cum, bytes, words);
5581   else if (TARGET_64BIT)
5582     function_arg_advance_64 (cum, mode, type, words, named);
5583   else
5584     function_arg_advance_32 (cum, mode, type, bytes, words);
5585 }
5586
5587 /* Define where to put the arguments to a function.
5588    Value is zero to push the argument on the stack,
5589    or a hard register in which to store the argument.
5590
5591    MODE is the argument's machine mode.
5592    TYPE is the data type of the argument (as a tree).
5593     This is null for libcalls where that information may
5594     not be available.
5595    CUM is a variable of type CUMULATIVE_ARGS which gives info about
5596     the preceding args and about the function being called.
5597    NAMED is nonzero if this argument is a named parameter
5598     (otherwise it is an extra parameter matching an ellipsis).  */
5599
5600 static rtx
5601 function_arg_32 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5602                  enum machine_mode orig_mode, tree type,
5603                  HOST_WIDE_INT bytes, HOST_WIDE_INT words)
5604 {
5605   static bool warnedsse, warnedmmx;
5606
5607   /* Avoid the AL settings for the Unix64 ABI.  */
5608   if (mode == VOIDmode)
5609     return constm1_rtx;
5610
5611   switch (mode)
5612     {
5613     default:
5614       break;
5615
5616     case BLKmode:
5617       if (bytes < 0)
5618         break;
5619       /* FALLTHRU */
5620     case DImode:
5621     case SImode:
5622     case HImode:
5623     case QImode:
5624       if (words <= cum->nregs)
5625         {
5626           int regno = cum->regno;
5627
5628           /* Fastcall allocates the first two DWORD (SImode) or
5629             smaller arguments to ECX and EDX if it isn't an
5630             aggregate type .  */
5631           if (cum->fastcall)
5632             {
5633               if (mode == BLKmode
5634                   || mode == DImode
5635                   || (type && AGGREGATE_TYPE_P (type)))
5636                 break;
5637
5638               /* ECX not EAX is the first allocated register.  */
5639               if (regno == AX_REG)
5640                 regno = CX_REG;
5641             }
5642           return gen_rtx_REG (mode, regno);
5643         }
5644       break;
5645
5646     case DFmode:
5647       if (cum->float_in_sse < 2)
5648         break;
5649     case SFmode:
5650       if (cum->float_in_sse < 1)
5651         break;
5652       /* FALLTHRU */
5653     case TImode:
5654       /* In 32bit, we pass TImode in xmm registers.  */
5655     case V16QImode:
5656     case V8HImode:
5657     case V4SImode:
5658     case V2DImode:
5659     case V4SFmode:
5660     case V2DFmode:
5661       if (!type || !AGGREGATE_TYPE_P (type))
5662         {
5663           if (!TARGET_SSE && !warnedsse && cum->warn_sse)
5664             {
5665               warnedsse = true;
5666               warning (0, "SSE vector argument without SSE enabled "
5667                        "changes the ABI");
5668             }
5669           if (cum->sse_nregs)
5670             return gen_reg_or_parallel (mode, orig_mode,
5671                                         cum->sse_regno + FIRST_SSE_REG);
5672         }
5673       break;
5674
5675     case OImode:
5676       /* In 32bit, we pass OImode in ymm registers.  */
5677     case V8SFmode:
5678     case V8SImode:
5679     case V32QImode:
5680     case V16HImode:
5681     case V4DFmode:
5682     case V4DImode:
5683       if (!type || !AGGREGATE_TYPE_P (type))
5684         {
5685           if (cum->sse_nregs)
5686             return gen_reg_or_parallel (mode, orig_mode,
5687                                         cum->sse_regno + FIRST_SSE_REG);
5688         }
5689       break;
5690
5691     case V8QImode:
5692     case V4HImode:
5693     case V2SImode:
5694     case V2SFmode:
5695     case V1DImode:
5696       if (!type || !AGGREGATE_TYPE_P (type))
5697         {
5698           if (!TARGET_MMX && !warnedmmx && cum->warn_mmx)
5699             {
5700               warnedmmx = true;
5701               warning (0, "MMX vector argument without MMX enabled "
5702                        "changes the ABI");
5703             }
5704           if (cum->mmx_nregs)
5705             return gen_reg_or_parallel (mode, orig_mode,
5706                                         cum->mmx_regno + FIRST_MMX_REG);
5707         }
5708       break;
5709     }
5710
5711   return NULL_RTX;
5712 }
5713
5714 static rtx
5715 function_arg_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5716                  enum machine_mode orig_mode, tree type, int named)
5717 {
5718   /* Handle a hidden AL argument containing number of registers
5719      for varargs x86-64 functions.  */
5720   if (mode == VOIDmode)
5721     return GEN_INT (cum->maybe_vaarg
5722                     ? (cum->sse_nregs < 0
5723                        ? (cum->call_abi == DEFAULT_ABI
5724                           ? SSE_REGPARM_MAX
5725                           : (DEFAULT_ABI != SYSV_ABI ? X86_64_SSE_REGPARM_MAX
5726                                                      : X64_SSE_REGPARM_MAX))
5727                : cum->sse_regno)
5728                     : -1);
5729
5730   switch (mode)
5731     {
5732     default:
5733       break;
5734
5735     case V8SFmode:
5736     case V8SImode:
5737     case V32QImode:
5738     case V16HImode:
5739     case V4DFmode:
5740     case V4DImode:
5741       /* In 64bit, we pass TImode in interger registers and OImode on
5742          stack.  */
5743
5744       /* Unnamed 256bit vector mode parameters are passed on stack.  */
5745       if (!named)
5746         return NULL;
5747       break;
5748     }
5749
5750   return construct_container (mode, orig_mode, type, 0, cum->nregs,
5751                               cum->sse_nregs,
5752                               &x86_64_int_parameter_registers [cum->regno],
5753                               cum->sse_regno);
5754 }
5755
5756 static rtx
5757 function_arg_ms_64 (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5758                     enum machine_mode orig_mode, int named,
5759                     HOST_WIDE_INT bytes)
5760 {
5761   unsigned int regno;
5762
5763   /* We need to add clobber for MS_ABI->SYSV ABI calls in expand_call.
5764      We use value of -2 to specify that current function call is MSABI.  */
5765   if (mode == VOIDmode)
5766     return GEN_INT (-2);
5767
5768   /* If we've run out of registers, it goes on the stack.  */
5769   if (cum->nregs == 0)
5770     return NULL_RTX;
5771
5772   regno = x86_64_ms_abi_int_parameter_registers[cum->regno];
5773
5774   /* Only floating point modes are passed in anything but integer regs.  */
5775   if (TARGET_SSE && (mode == SFmode || mode == DFmode))
5776     {
5777       if (named)
5778         regno = cum->regno + FIRST_SSE_REG;
5779       else
5780         {
5781           rtx t1, t2;
5782
5783           /* Unnamed floating parameters are passed in both the
5784              SSE and integer registers.  */
5785           t1 = gen_rtx_REG (mode, cum->regno + FIRST_SSE_REG);
5786           t2 = gen_rtx_REG (mode, regno);
5787           t1 = gen_rtx_EXPR_LIST (VOIDmode, t1, const0_rtx);
5788           t2 = gen_rtx_EXPR_LIST (VOIDmode, t2, const0_rtx);
5789           return gen_rtx_PARALLEL (mode, gen_rtvec (2, t1, t2));
5790         }
5791     }
5792   /* Handle aggregated types passed in register.  */
5793   if (orig_mode == BLKmode)
5794     {
5795       if (bytes > 0 && bytes <= 8)
5796         mode = (bytes > 4 ? DImode : SImode);
5797       if (mode == BLKmode)
5798         mode = DImode;
5799     }
5800
5801   return gen_reg_or_parallel (mode, orig_mode, regno);
5802 }
5803
5804 rtx
5805 function_arg (CUMULATIVE_ARGS *cum, enum machine_mode omode,
5806               tree type, int named)
5807 {
5808   enum machine_mode mode = omode;
5809   HOST_WIDE_INT bytes, words;
5810
5811   if (mode == BLKmode)
5812     bytes = int_size_in_bytes (type);
5813   else
5814     bytes = GET_MODE_SIZE (mode);
5815   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5816
5817   /* To simplify the code below, represent vector types with a vector mode
5818      even if MMX/SSE are not active.  */
5819   if (type && TREE_CODE (type) == VECTOR_TYPE)
5820     mode = type_natural_mode (type, cum);
5821
5822   if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
5823     return function_arg_ms_64 (cum, mode, omode, named, bytes);
5824   else if (TARGET_64BIT)
5825     return function_arg_64 (cum, mode, omode, type, named);
5826   else
5827     return function_arg_32 (cum, mode, omode, type, bytes, words);
5828 }
5829
5830 /* A C expression that indicates when an argument must be passed by
5831    reference.  If nonzero for an argument, a copy of that argument is
5832    made in memory and a pointer to the argument is passed instead of
5833    the argument itself.  The pointer is passed in whatever way is
5834    appropriate for passing a pointer to that type.  */
5835
5836 static bool
5837 ix86_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
5838                         enum machine_mode mode ATTRIBUTE_UNUSED,
5839                         const_tree type, bool named ATTRIBUTE_UNUSED)
5840 {
5841   /* See Windows x64 Software Convention.  */
5842   if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
5843     {
5844       int msize = (int) GET_MODE_SIZE (mode);
5845       if (type)
5846         {
5847           /* Arrays are passed by reference.  */
5848           if (TREE_CODE (type) == ARRAY_TYPE)
5849             return true;
5850
5851           if (AGGREGATE_TYPE_P (type))
5852             {
5853               /* Structs/unions of sizes other than 8, 16, 32, or 64 bits
5854                  are passed by reference.  */
5855               msize = int_size_in_bytes (type);
5856             }
5857         }
5858
5859       /* __m128 is passed by reference.  */
5860       switch (msize) {
5861       case 1: case 2: case 4: case 8:
5862         break;
5863       default:
5864         return true;
5865       }
5866     }
5867   else if (TARGET_64BIT && type && int_size_in_bytes (type) == -1)
5868     return 1;
5869
5870   return 0;
5871 }
5872
5873 /* Return true when TYPE should be 128bit aligned for 32bit argument passing
5874    ABI.  */
5875 static bool
5876 contains_aligned_value_p (tree type)
5877 {
5878   enum machine_mode mode = TYPE_MODE (type);
5879   if (((TARGET_SSE && SSE_REG_MODE_P (mode))
5880        || mode == TDmode
5881        || mode == TFmode
5882        || mode == TCmode)
5883       && (!TYPE_USER_ALIGN (type) || TYPE_ALIGN (type) > 128))
5884     return true;
5885   if (TYPE_ALIGN (type) < 128)
5886     return false;
5887
5888   if (AGGREGATE_TYPE_P (type))
5889     {
5890       /* Walk the aggregates recursively.  */
5891       switch (TREE_CODE (type))
5892         {
5893         case RECORD_TYPE:
5894         case UNION_TYPE:
5895         case QUAL_UNION_TYPE:
5896           {
5897             tree field;
5898
5899             /* Walk all the structure fields.  */
5900             for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5901               {
5902                 if (TREE_CODE (field) == FIELD_DECL
5903                     && contains_aligned_value_p (TREE_TYPE (field)))
5904                   return true;
5905               }
5906             break;
5907           }
5908
5909         case ARRAY_TYPE:
5910           /* Just for use if some languages passes arrays by value.  */
5911           if (contains_aligned_value_p (TREE_TYPE (type)))
5912             return true;
5913           break;
5914
5915         default:
5916           gcc_unreachable ();
5917         }
5918     }
5919   return false;
5920 }
5921
5922 /* Gives the alignment boundary, in bits, of an argument with the
5923    specified mode and type.  */
5924
5925 int
5926 ix86_function_arg_boundary (enum machine_mode mode, tree type)
5927 {
5928   int align;
5929   if (type)
5930     {
5931       /* Since canonical type is used for call, we convert it to
5932          canonical type if needed.  */
5933       if (!TYPE_STRUCTURAL_EQUALITY_P (type))
5934         type = TYPE_CANONICAL (type);
5935       align = TYPE_ALIGN (type);
5936     }
5937   else
5938     align = GET_MODE_ALIGNMENT (mode);
5939   if (align < PARM_BOUNDARY)
5940     align = PARM_BOUNDARY;
5941   /* In 32bit, only _Decimal128 and __float128 are aligned to their
5942      natural boundaries.  */
5943   if (!TARGET_64BIT && mode != TDmode && mode != TFmode)
5944     {
5945       /* i386 ABI defines all arguments to be 4 byte aligned.  We have to
5946          make an exception for SSE modes since these require 128bit
5947          alignment.
5948
5949          The handling here differs from field_alignment.  ICC aligns MMX
5950          arguments to 4 byte boundaries, while structure fields are aligned
5951          to 8 byte boundaries.  */
5952       if (!type)
5953         {
5954           if (!(TARGET_SSE && SSE_REG_MODE_P (mode)))
5955             align = PARM_BOUNDARY;
5956         }
5957       else
5958         {
5959           if (!contains_aligned_value_p (type))
5960             align = PARM_BOUNDARY;
5961         }
5962     }
5963   if (align > BIGGEST_ALIGNMENT)
5964     align = BIGGEST_ALIGNMENT;
5965   return align;
5966 }
5967
5968 /* Return true if N is a possible register number of function value.  */
5969
5970 bool
5971 ix86_function_value_regno_p (int regno)
5972 {
5973   switch (regno)
5974     {
5975     case 0:
5976       return true;
5977
5978     case FIRST_FLOAT_REG:
5979       /* TODO: The function should depend on current function ABI but
5980        builtins.c would need updating then. Therefore we use the
5981        default ABI.  */
5982       if (TARGET_64BIT && DEFAULT_ABI == MS_ABI)
5983         return false;
5984       return TARGET_FLOAT_RETURNS_IN_80387;
5985
5986     case FIRST_SSE_REG:
5987       return TARGET_SSE;
5988
5989     case FIRST_MMX_REG:
5990       if (TARGET_MACHO || TARGET_64BIT)
5991         return false;
5992       return TARGET_MMX;
5993     }
5994
5995   return false;
5996 }
5997
5998 /* Define how to find the value returned by a function.
5999    VALTYPE is the data type of the value (as a tree).
6000    If the precise function being called is known, FUNC is its FUNCTION_DECL;
6001    otherwise, FUNC is 0.  */
6002
6003 static rtx
6004 function_value_32 (enum machine_mode orig_mode, enum machine_mode mode,
6005                    const_tree fntype, const_tree fn)
6006 {
6007   unsigned int regno;
6008
6009   /* 8-byte vector modes in %mm0. See ix86_return_in_memory for where
6010      we normally prevent this case when mmx is not available.  However
6011      some ABIs may require the result to be returned like DImode.  */
6012   if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
6013     regno = TARGET_MMX ? FIRST_MMX_REG : 0;
6014
6015   /* 16-byte vector modes in %xmm0.  See ix86_return_in_memory for where
6016      we prevent this case when sse is not available.  However some ABIs
6017      may require the result to be returned like integer TImode.  */
6018   else if (mode == TImode
6019            || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
6020     regno = TARGET_SSE ? FIRST_SSE_REG : 0;
6021
6022   /* Floating point return values in %st(0) (unless -mno-fp-ret-in-387).  */
6023   else if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387)
6024     regno = FIRST_FLOAT_REG;
6025   else
6026     /* Most things go in %eax.  */
6027     regno = AX_REG;
6028
6029   /* Override FP return register with %xmm0 for local functions when
6030      SSE math is enabled or for functions with sseregparm attribute.  */
6031   if ((fn || fntype) && (mode == SFmode || mode == DFmode))
6032     {
6033       int sse_level = ix86_function_sseregparm (fntype, fn, false);
6034       if ((sse_level >= 1 && mode == SFmode)
6035           || (sse_level == 2 && mode == DFmode))
6036         regno = FIRST_SSE_REG;
6037     }
6038
6039   return gen_rtx_REG (orig_mode, regno);
6040 }
6041
6042 static rtx
6043 function_value_64 (enum machine_mode orig_mode, enum machine_mode mode,
6044                    const_tree valtype)
6045 {
6046   rtx ret;
6047
6048   /* Handle libcalls, which don't provide a type node.  */
6049   if (valtype == NULL)
6050     {
6051       switch (mode)
6052         {
6053         case SFmode:
6054         case SCmode:
6055         case DFmode:
6056         case DCmode:
6057         case TFmode:
6058         case SDmode:
6059         case DDmode:
6060         case TDmode:
6061           return gen_rtx_REG (mode, FIRST_SSE_REG);
6062         case XFmode:
6063         case XCmode:
6064           return gen_rtx_REG (mode, FIRST_FLOAT_REG);
6065         case TCmode:
6066           return NULL;
6067         default:
6068           return gen_rtx_REG (mode, AX_REG);
6069         }
6070     }
6071
6072   ret = construct_container (mode, orig_mode, valtype, 1,
6073                              X86_64_REGPARM_MAX, X86_64_SSE_REGPARM_MAX,
6074                              x86_64_int_return_registers, 0);
6075
6076   /* For zero sized structures, construct_container returns NULL, but we
6077      need to keep rest of compiler happy by returning meaningful value.  */
6078   if (!ret)
6079     ret = gen_rtx_REG (orig_mode, AX_REG);
6080
6081   return ret;
6082 }
6083
6084 static rtx
6085 function_value_ms_64 (enum machine_mode orig_mode, enum machine_mode mode)
6086 {
6087   unsigned int regno = AX_REG;
6088
6089   if (TARGET_SSE)
6090     {
6091       switch (GET_MODE_SIZE (mode))
6092         {
6093         case 16:
6094           if((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
6095              && !COMPLEX_MODE_P (mode))
6096             regno = FIRST_SSE_REG;
6097           break;
6098         case 8:
6099         case 4:
6100           if (mode == SFmode || mode == DFmode)
6101             regno = FIRST_SSE_REG;
6102           break;
6103         default:
6104           break;
6105         }
6106     }
6107   return gen_rtx_REG (orig_mode, regno);
6108 }
6109
6110 static rtx
6111 ix86_function_value_1 (const_tree valtype, const_tree fntype_or_decl,
6112                        enum machine_mode orig_mode, enum machine_mode mode)
6113 {
6114   const_tree fn, fntype;
6115
6116   fn = NULL_TREE;
6117   if (fntype_or_decl && DECL_P (fntype_or_decl))
6118     fn = fntype_or_decl;
6119   fntype = fn ? TREE_TYPE (fn) : fntype_or_decl;
6120
6121   if (TARGET_64BIT && ix86_function_type_abi (fntype) == MS_ABI)
6122     return function_value_ms_64 (orig_mode, mode);
6123   else if (TARGET_64BIT)
6124     return function_value_64 (orig_mode, mode, valtype);
6125   else
6126     return function_value_32 (orig_mode, mode, fntype, fn);
6127 }
6128
6129 static rtx
6130 ix86_function_value (const_tree valtype, const_tree fntype_or_decl,
6131                      bool outgoing ATTRIBUTE_UNUSED)
6132 {
6133   enum machine_mode mode, orig_mode;
6134
6135   orig_mode = TYPE_MODE (valtype);
6136   mode = type_natural_mode (valtype, NULL);
6137   return ix86_function_value_1 (valtype, fntype_or_decl, orig_mode, mode);
6138 }
6139
6140 rtx
6141 ix86_libcall_value (enum machine_mode mode)
6142 {
6143   return ix86_function_value_1 (NULL, NULL, mode, mode);
6144 }
6145
6146 /* Return true iff type is returned in memory.  */
6147
6148 static int ATTRIBUTE_UNUSED
6149 return_in_memory_32 (const_tree type, enum machine_mode mode)
6150 {
6151   HOST_WIDE_INT size;
6152
6153   if (mode == BLKmode)
6154     return 1;
6155
6156   size = int_size_in_bytes (type);
6157
6158   if (MS_AGGREGATE_RETURN && AGGREGATE_TYPE_P (type) && size <= 8)
6159     return 0;
6160
6161   if (VECTOR_MODE_P (mode) || mode == TImode)
6162     {
6163       /* User-created vectors small enough to fit in EAX.  */
6164       if (size < 8)
6165         return 0;
6166
6167       /* MMX/3dNow values are returned in MM0,
6168          except when it doesn't exits.  */
6169       if (size == 8)
6170         return (TARGET_MMX ? 0 : 1);
6171
6172       /* SSE values are returned in XMM0, except when it doesn't exist.  */
6173       if (size == 16)
6174         return (TARGET_SSE ? 0 : 1);
6175     }
6176
6177   if (mode == XFmode)
6178     return 0;
6179
6180   if (size > 12)
6181     return 1;
6182   return 0;
6183 }
6184
6185 static int ATTRIBUTE_UNUSED
6186 return_in_memory_64 (const_tree type, enum machine_mode mode)
6187 {
6188   int needed_intregs, needed_sseregs;
6189   return !examine_argument (mode, type, 1, &needed_intregs, &needed_sseregs);
6190 }
6191
6192 static int ATTRIBUTE_UNUSED
6193 return_in_memory_ms_64 (const_tree type, enum machine_mode mode)
6194 {
6195   HOST_WIDE_INT size = int_size_in_bytes (type);
6196
6197   /* __m128 is returned in xmm0.  */
6198   if ((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
6199       && !COMPLEX_MODE_P (mode) && (GET_MODE_SIZE (mode) == 16 || size == 16))
6200     return 0;
6201
6202   /* Otherwise, the size must be exactly in [1248]. */
6203   return (size != 1 && size != 2 && size != 4 && size != 8);
6204 }
6205
6206 static bool
6207 ix86_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
6208 {
6209 #ifdef SUBTARGET_RETURN_IN_MEMORY
6210   return SUBTARGET_RETURN_IN_MEMORY (type, fntype);
6211 #else
6212   const enum machine_mode mode = type_natural_mode (type, NULL);
6213  
6214   if (TARGET_64BIT)
6215     {
6216       if (ix86_function_type_abi (fntype) == MS_ABI)
6217         return return_in_memory_ms_64 (type, mode);
6218       else
6219         return return_in_memory_64 (type, mode);
6220     }
6221   else
6222     return return_in_memory_32 (type, mode);
6223 #endif
6224 }
6225
6226 /* Return false iff TYPE is returned in memory.  This version is used
6227    on Solaris 10.  It is similar to the generic ix86_return_in_memory,
6228    but differs notably in that when MMX is available, 8-byte vectors
6229    are returned in memory, rather than in MMX registers.  */
6230
6231 bool
6232 ix86_sol10_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
6233 {
6234   int size;
6235   enum machine_mode mode = type_natural_mode (type, NULL);
6236
6237   if (TARGET_64BIT)
6238     return return_in_memory_64 (type, mode);
6239
6240   if (mode == BLKmode)
6241     return 1;
6242
6243   size = int_size_in_bytes (type);
6244
6245   if (VECTOR_MODE_P (mode))
6246     {
6247       /* Return in memory only if MMX registers *are* available.  This
6248          seems backwards, but it is consistent with the existing
6249          Solaris x86 ABI.  */
6250       if (size == 8)
6251         return TARGET_MMX;
6252       if (size == 16)
6253         return !TARGET_SSE;
6254     }
6255   else if (mode == TImode)
6256     return !TARGET_SSE;
6257   else if (mode == XFmode)
6258     return 0;
6259
6260   return size > 12;
6261 }
6262
6263 /* When returning SSE vector types, we have a choice of either
6264      (1) being abi incompatible with a -march switch, or
6265      (2) generating an error.
6266    Given no good solution, I think the safest thing is one warning.
6267    The user won't be able to use -Werror, but....
6268
6269    Choose the STRUCT_VALUE_RTX hook because that's (at present) only
6270    called in response to actually generating a caller or callee that
6271    uses such a type.  As opposed to TARGET_RETURN_IN_MEMORY, which is called
6272    via aggregate_value_p for general type probing from tree-ssa.  */
6273
6274 static rtx
6275 ix86_struct_value_rtx (tree type, int incoming ATTRIBUTE_UNUSED)
6276 {
6277   static bool warnedsse, warnedmmx;
6278
6279   if (!TARGET_64BIT && type)
6280     {
6281       /* Look at the return type of the function, not the function type.  */
6282       enum machine_mode mode = TYPE_MODE (TREE_TYPE (type));
6283
6284       if (!TARGET_SSE && !warnedsse)
6285         {
6286           if (mode == TImode
6287               || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
6288             {
6289               warnedsse = true;
6290               warning (0, "SSE vector return without SSE enabled "
6291                        "changes the ABI");
6292             }
6293         }
6294
6295       if (!TARGET_MMX && !warnedmmx)
6296         {
6297           if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
6298             {
6299               warnedmmx = true;
6300               warning (0, "MMX vector return without MMX enabled "
6301                        "changes the ABI");
6302             }
6303         }
6304     }
6305
6306   return NULL;
6307 }
6308
6309 \f
6310 /* Create the va_list data type.  */
6311
6312 /* Returns the calling convention specific va_list date type.
6313    The argument ABI can be DEFAULT_ABI, MS_ABI, or SYSV_ABI.  */
6314
6315 static tree
6316 ix86_build_builtin_va_list_abi (enum calling_abi abi)
6317 {
6318   tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
6319
6320   /* For i386 we use plain pointer to argument area.  */
6321   if (!TARGET_64BIT || abi == MS_ABI)
6322     return build_pointer_type (char_type_node);
6323
6324   record = (*lang_hooks.types.make_type) (RECORD_TYPE);
6325   type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
6326
6327   f_gpr = build_decl (FIELD_DECL, get_identifier ("gp_offset"),
6328                       unsigned_type_node);
6329   f_fpr = build_decl (FIELD_DECL, get_identifier ("fp_offset"),
6330                       unsigned_type_node);
6331   f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
6332                       ptr_type_node);
6333   f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
6334                       ptr_type_node);
6335
6336   va_list_gpr_counter_field = f_gpr;
6337   va_list_fpr_counter_field = f_fpr;
6338
6339   DECL_FIELD_CONTEXT (f_gpr) = record;
6340   DECL_FIELD_CONTEXT (f_fpr) = record;
6341   DECL_FIELD_CONTEXT (f_ovf) = record;
6342   DECL_FIELD_CONTEXT (f_sav) = record;
6343
6344   TREE_CHAIN (record) = type_decl;
6345   TYPE_NAME (record) = type_decl;
6346   TYPE_FIELDS (record) = f_gpr;
6347   TREE_CHAIN (f_gpr) = f_fpr;
6348   TREE_CHAIN (f_fpr) = f_ovf;
6349   TREE_CHAIN (f_ovf) = f_sav;
6350
6351   layout_type (record);
6352
6353   /* The correct type is an array type of one element.  */
6354   return build_array_type (record, build_index_type (size_zero_node));
6355 }
6356
6357 /* Setup the builtin va_list data type and for 64-bit the additional
6358    calling convention specific va_list data types.  */
6359
6360 static tree
6361 ix86_build_builtin_va_list (void)
6362 {
6363   tree ret = ix86_build_builtin_va_list_abi (DEFAULT_ABI);
6364
6365   /* Initialize abi specific va_list builtin types.  */
6366   if (TARGET_64BIT)
6367     {
6368       tree t;
6369       if (DEFAULT_ABI == MS_ABI)
6370         {
6371           t = ix86_build_builtin_va_list_abi (SYSV_ABI);
6372           if (TREE_CODE (t) != RECORD_TYPE)
6373             t = build_variant_type_copy (t);
6374           sysv_va_list_type_node = t;
6375         }
6376       else
6377         {
6378           t = ret;
6379           if (TREE_CODE (t) != RECORD_TYPE)
6380             t = build_variant_type_copy (t);
6381           sysv_va_list_type_node = t;
6382         }
6383       if (DEFAULT_ABI != MS_ABI)
6384         {
6385           t = ix86_build_builtin_va_list_abi (MS_ABI);
6386           if (TREE_CODE (t) != RECORD_TYPE)
6387             t = build_variant_type_copy (t);
6388           ms_va_list_type_node = t;
6389         }
6390       else
6391         {
6392           t = ret;
6393           if (TREE_CODE (t) != RECORD_TYPE)
6394             t = build_variant_type_copy (t);
6395           ms_va_list_type_node = t;
6396         }
6397     }
6398
6399   return ret;
6400 }
6401
6402 /* Worker function for TARGET_SETUP_INCOMING_VARARGS.  */
6403
6404 static void
6405 setup_incoming_varargs_64 (CUMULATIVE_ARGS *cum)
6406 {
6407   rtx save_area, mem;
6408   rtx label;
6409   rtx label_ref;
6410   rtx tmp_reg;
6411   rtx nsse_reg;
6412   alias_set_type set;
6413   int i;
6414   int regparm = ix86_regparm;
6415
6416   if (cum->call_abi != DEFAULT_ABI)
6417     regparm = DEFAULT_ABI != SYSV_ABI ? X86_64_REGPARM_MAX : X64_REGPARM_MAX;
6418
6419   /* GPR size of varargs save area.  */
6420   if (cfun->va_list_gpr_size)
6421     ix86_varargs_gpr_size = X86_64_REGPARM_MAX * UNITS_PER_WORD;
6422   else
6423     ix86_varargs_gpr_size = 0;
6424
6425   /* FPR size of varargs save area.  We don't need it if we don't pass
6426      anything in SSE registers.  */
6427   if (cum->sse_nregs && cfun->va_list_fpr_size)
6428     ix86_varargs_fpr_size = X86_64_SSE_REGPARM_MAX * 16;
6429   else
6430     ix86_varargs_fpr_size = 0;
6431
6432   if (! ix86_varargs_gpr_size && ! ix86_varargs_fpr_size)
6433     return;
6434
6435   save_area = frame_pointer_rtx;
6436   set = get_varargs_alias_set ();
6437
6438   for (i = cum->regno;
6439        i < regparm
6440        && i < cum->regno + cfun->va_list_gpr_size / UNITS_PER_WORD;
6441        i++)
6442     {
6443       mem = gen_rtx_MEM (Pmode,
6444                          plus_constant (save_area, i * UNITS_PER_WORD));
6445       MEM_NOTRAP_P (mem) = 1;
6446       set_mem_alias_set (mem, set);
6447       emit_move_insn (mem, gen_rtx_REG (Pmode,
6448                                         x86_64_int_parameter_registers[i]));
6449     }
6450
6451   if (ix86_varargs_fpr_size)
6452     {
6453       /* Now emit code to save SSE registers.  The AX parameter contains number
6454          of SSE parameter registers used to call this function.  We use
6455          sse_prologue_save insn template that produces computed jump across
6456          SSE saves.  We need some preparation work to get this working.  */
6457
6458       label = gen_label_rtx ();
6459       label_ref = gen_rtx_LABEL_REF (Pmode, label);
6460
6461       /* Compute address to jump to :
6462          label - eax*4 + nnamed_sse_arguments*4 Or
6463          label - eax*5 + nnamed_sse_arguments*5 for AVX.  */
6464       tmp_reg = gen_reg_rtx (Pmode);
6465       nsse_reg = gen_reg_rtx (Pmode);
6466       emit_insn (gen_zero_extendqidi2 (nsse_reg, gen_rtx_REG (QImode, AX_REG)));
6467       emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6468                               gen_rtx_MULT (Pmode, nsse_reg,
6469                                             GEN_INT (4))));
6470
6471       /* vmovaps is one byte longer than movaps.  */
6472       if (TARGET_AVX)
6473         emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6474                                 gen_rtx_PLUS (Pmode, tmp_reg,
6475                                               nsse_reg)));
6476
6477       if (cum->sse_regno)
6478         emit_move_insn
6479           (nsse_reg,
6480            gen_rtx_CONST (DImode,
6481                           gen_rtx_PLUS (DImode,
6482                                         label_ref,
6483                                         GEN_INT (cum->sse_regno
6484                                                  * (TARGET_AVX ? 5 : 4)))));
6485       else
6486         emit_move_insn (nsse_reg, label_ref);
6487       emit_insn (gen_subdi3 (nsse_reg, nsse_reg, tmp_reg));
6488
6489       /* Compute address of memory block we save into.  We always use pointer
6490          pointing 127 bytes after first byte to store - this is needed to keep
6491          instruction size limited by 4 bytes (5 bytes for AVX) with one
6492          byte displacement.  */
6493       tmp_reg = gen_reg_rtx (Pmode);
6494       emit_insn (gen_rtx_SET (VOIDmode, tmp_reg,
6495                               plus_constant (save_area,
6496                                              ix86_varargs_gpr_size + 127)));
6497       mem = gen_rtx_MEM (BLKmode, plus_constant (tmp_reg, -127));
6498       MEM_NOTRAP_P (mem) = 1;
6499       set_mem_alias_set (mem, set);
6500       set_mem_align (mem, BITS_PER_WORD);
6501
6502       /* And finally do the dirty job!  */
6503       emit_insn (gen_sse_prologue_save (mem, nsse_reg,
6504                                         GEN_INT (cum->sse_regno), label));
6505     }
6506 }
6507
6508 static void
6509 setup_incoming_varargs_ms_64 (CUMULATIVE_ARGS *cum)
6510 {
6511   alias_set_type set = get_varargs_alias_set ();
6512   int i;
6513
6514   for (i = cum->regno; i < X64_REGPARM_MAX; i++)
6515     {
6516       rtx reg, mem;
6517
6518       mem = gen_rtx_MEM (Pmode,
6519                          plus_constant (virtual_incoming_args_rtx,
6520                                         i * UNITS_PER_WORD));
6521       MEM_NOTRAP_P (mem) = 1;
6522       set_mem_alias_set (mem, set);
6523
6524       reg = gen_rtx_REG (Pmode, x86_64_ms_abi_int_parameter_registers[i]);
6525       emit_move_insn (mem, reg);
6526     }
6527 }
6528
6529 static void
6530 ix86_setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
6531                              tree type, int *pretend_size ATTRIBUTE_UNUSED,
6532                              int no_rtl)
6533 {
6534   CUMULATIVE_ARGS next_cum;
6535   tree fntype;
6536
6537   /* This argument doesn't appear to be used anymore.  Which is good,
6538      because the old code here didn't suppress rtl generation.  */
6539   gcc_assert (!no_rtl);
6540
6541   if (!TARGET_64BIT)
6542     return;
6543
6544   fntype = TREE_TYPE (current_function_decl);
6545
6546   /* For varargs, we do not want to skip the dummy va_dcl argument.
6547      For stdargs, we do want to skip the last named argument.  */
6548   next_cum = *cum;
6549   if (stdarg_p (fntype))
6550     function_arg_advance (&next_cum, mode, type, 1);
6551
6552   if (cum->call_abi == MS_ABI)
6553     setup_incoming_varargs_ms_64 (&next_cum);
6554   else
6555     setup_incoming_varargs_64 (&next_cum);
6556 }
6557
6558 /* Checks if TYPE is of kind va_list char *.  */
6559
6560 static bool
6561 is_va_list_char_pointer (tree type)
6562 {
6563   tree canonic;
6564
6565   /* For 32-bit it is always true.  */
6566   if (!TARGET_64BIT)
6567     return true;
6568   canonic = ix86_canonical_va_list_type (type);
6569   return (canonic == ms_va_list_type_node
6570           || (DEFAULT_ABI == MS_ABI && canonic == va_list_type_node));
6571 }
6572
6573 /* Implement va_start.  */
6574
6575 static void
6576 ix86_va_start (tree valist, rtx nextarg)
6577 {
6578   HOST_WIDE_INT words, n_gpr, n_fpr;
6579   tree f_gpr, f_fpr, f_ovf, f_sav;
6580   tree gpr, fpr, ovf, sav, t;
6581   tree type;
6582
6583   /* Only 64bit target needs something special.  */
6584   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
6585     {
6586       std_expand_builtin_va_start (valist, nextarg);
6587       return;
6588     }
6589
6590   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
6591   f_fpr = TREE_CHAIN (f_gpr);
6592   f_ovf = TREE_CHAIN (f_fpr);
6593   f_sav = TREE_CHAIN (f_ovf);
6594
6595   valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
6596   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
6597   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
6598   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
6599   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
6600
6601   /* Count number of gp and fp argument registers used.  */
6602   words = crtl->args.info.words;
6603   n_gpr = crtl->args.info.regno;
6604   n_fpr = crtl->args.info.sse_regno;
6605
6606   if (cfun->va_list_gpr_size)
6607     {
6608       type = TREE_TYPE (gpr);
6609       t = build2 (MODIFY_EXPR, type,
6610                   gpr, build_int_cst (type, n_gpr * 8));
6611       TREE_SIDE_EFFECTS (t) = 1;
6612       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6613     }
6614
6615   if (TARGET_SSE && cfun->va_list_fpr_size)
6616     {
6617       type = TREE_TYPE (fpr);
6618       t = build2 (MODIFY_EXPR, type, fpr,
6619                   build_int_cst (type, n_fpr * 16 + 8*X86_64_REGPARM_MAX));
6620       TREE_SIDE_EFFECTS (t) = 1;
6621       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6622     }
6623
6624   /* Find the overflow area.  */
6625   type = TREE_TYPE (ovf);
6626   t = make_tree (type, crtl->args.internal_arg_pointer);
6627   if (words != 0)
6628     t = build2 (POINTER_PLUS_EXPR, type, t,
6629                 size_int (words * UNITS_PER_WORD));
6630   t = build2 (MODIFY_EXPR, type, ovf, t);
6631   TREE_SIDE_EFFECTS (t) = 1;
6632   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6633
6634   if (ix86_varargs_gpr_size || ix86_varargs_fpr_size)
6635     {
6636       /* Find the register save area.
6637          Prologue of the function save it right above stack frame.  */
6638       type = TREE_TYPE (sav);
6639       t = make_tree (type, frame_pointer_rtx);
6640       if (!ix86_varargs_gpr_size)
6641         t = build2 (POINTER_PLUS_EXPR, type, t,
6642                     size_int (-8 * X86_64_REGPARM_MAX));
6643       t = build2 (MODIFY_EXPR, type, sav, t);
6644       TREE_SIDE_EFFECTS (t) = 1;
6645       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6646     }
6647 }
6648
6649 /* Implement va_arg.  */
6650
6651 static tree
6652 ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
6653                       gimple_seq *post_p)
6654 {
6655   static const int intreg[6] = { 0, 1, 2, 3, 4, 5 };
6656   tree f_gpr, f_fpr, f_ovf, f_sav;
6657   tree gpr, fpr, ovf, sav, t;
6658   int size, rsize;
6659   tree lab_false, lab_over = NULL_TREE;
6660   tree addr, t2;
6661   rtx container;
6662   int indirect_p = 0;
6663   tree ptrtype;
6664   enum machine_mode nat_mode;
6665   int arg_boundary;
6666
6667   /* Only 64bit target needs something special.  */
6668   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
6669     return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
6670
6671   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
6672   f_fpr = TREE_CHAIN (f_gpr);
6673   f_ovf = TREE_CHAIN (f_fpr);
6674   f_sav = TREE_CHAIN (f_ovf);
6675
6676   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr),
6677                 build_va_arg_indirect_ref (valist), f_gpr, NULL_TREE);
6678   valist = build_va_arg_indirect_ref (valist);
6679   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
6680   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
6681   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
6682
6683   indirect_p = pass_by_reference (NULL, TYPE_MODE (type), type, false);
6684   if (indirect_p)
6685     type = build_pointer_type (type);
6686   size = int_size_in_bytes (type);
6687   rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
6688
6689   nat_mode = type_natural_mode (type, NULL);
6690   switch (nat_mode)
6691     {
6692     case V8SFmode:
6693     case V8SImode:
6694     case V32QImode:
6695     case V16HImode:
6696     case V4DFmode:
6697     case V4DImode:
6698       /* Unnamed 256bit vector mode parameters are passed on stack.  */
6699       if (ix86_cfun_abi () == SYSV_ABI)
6700         {
6701           container = NULL;
6702           break;
6703         }
6704
6705     default:
6706       container = construct_container (nat_mode, TYPE_MODE (type),
6707                                        type, 0, X86_64_REGPARM_MAX,
6708                                        X86_64_SSE_REGPARM_MAX, intreg,
6709                                        0);
6710       break;
6711     }
6712
6713   /* Pull the value out of the saved registers.  */
6714
6715   addr = create_tmp_var (ptr_type_node, "addr");
6716   DECL_POINTER_ALIAS_SET (addr) = get_varargs_alias_set ();
6717
6718   if (container)
6719     {
6720       int needed_intregs, needed_sseregs;
6721       bool need_temp;
6722       tree int_addr, sse_addr;
6723
6724       lab_false = create_artificial_label ();
6725       lab_over = create_artificial_label ();
6726
6727       examine_argument (nat_mode, type, 0, &needed_intregs, &needed_sseregs);
6728
6729       need_temp = (!REG_P (container)
6730                    && ((needed_intregs && TYPE_ALIGN (type) > 64)
6731                        || TYPE_ALIGN (type) > 128));
6732
6733       /* In case we are passing structure, verify that it is consecutive block
6734          on the register save area.  If not we need to do moves.  */
6735       if (!need_temp && !REG_P (container))
6736         {
6737           /* Verify that all registers are strictly consecutive  */
6738           if (SSE_REGNO_P (REGNO (XEXP (XVECEXP (container, 0, 0), 0))))
6739             {
6740               int i;
6741
6742               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
6743                 {
6744                   rtx slot = XVECEXP (container, 0, i);
6745                   if (REGNO (XEXP (slot, 0)) != FIRST_SSE_REG + (unsigned int) i
6746                       || INTVAL (XEXP (slot, 1)) != i * 16)
6747                     need_temp = 1;
6748                 }
6749             }
6750           else
6751             {
6752               int i;
6753
6754               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
6755                 {
6756                   rtx slot = XVECEXP (container, 0, i);
6757                   if (REGNO (XEXP (slot, 0)) != (unsigned int) i
6758                       || INTVAL (XEXP (slot, 1)) != i * 8)
6759                     need_temp = 1;
6760                 }
6761             }
6762         }
6763       if (!need_temp)
6764         {
6765           int_addr = addr;
6766           sse_addr = addr;
6767         }
6768       else
6769         {
6770           int_addr = create_tmp_var (ptr_type_node, "int_addr");
6771           DECL_POINTER_ALIAS_SET (int_addr) = get_varargs_alias_set ();
6772           sse_addr = create_tmp_var (ptr_type_node, "sse_addr");
6773           DECL_POINTER_ALIAS_SET (sse_addr) = get_varargs_alias_set ();
6774         }
6775
6776       /* First ensure that we fit completely in registers.  */
6777       if (needed_intregs)
6778         {
6779           t = build_int_cst (TREE_TYPE (gpr),
6780                              (X86_64_REGPARM_MAX - needed_intregs + 1) * 8);
6781           t = build2 (GE_EXPR, boolean_type_node, gpr, t);
6782           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
6783           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
6784           gimplify_and_add (t, pre_p);
6785         }
6786       if (needed_sseregs)
6787         {
6788           t = build_int_cst (TREE_TYPE (fpr),
6789                              (X86_64_SSE_REGPARM_MAX - needed_sseregs + 1) * 16
6790                              + X86_64_REGPARM_MAX * 8);
6791           t = build2 (GE_EXPR, boolean_type_node, fpr, t);
6792           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
6793           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
6794           gimplify_and_add (t, pre_p);
6795         }
6796
6797       /* Compute index to start of area used for integer regs.  */
6798       if (needed_intregs)
6799         {
6800           /* int_addr = gpr + sav; */
6801           t = fold_convert (sizetype, gpr);
6802           t = build2 (POINTER_PLUS_EXPR, ptr_type_node, sav, t);
6803           gimplify_assign (int_addr, t, pre_p);
6804         }
6805       if (needed_sseregs)
6806         {
6807           /* sse_addr = fpr + sav; */
6808           t = fold_convert (sizetype, fpr);
6809           t = build2 (POINTER_PLUS_EXPR, ptr_type_node, sav, t);
6810           gimplify_assign (sse_addr, t, pre_p);
6811         }
6812       if (need_temp)
6813         {
6814           int i;
6815           tree temp = create_tmp_var (type, "va_arg_tmp");
6816
6817           /* addr = &temp; */
6818           t = build1 (ADDR_EXPR, build_pointer_type (type), temp);
6819           gimplify_assign (addr, t, pre_p);
6820
6821           for (i = 0; i < XVECLEN (container, 0); i++)
6822             {
6823               rtx slot = XVECEXP (container, 0, i);
6824               rtx reg = XEXP (slot, 0);
6825               enum machine_mode mode = GET_MODE (reg);
6826               tree piece_type = lang_hooks.types.type_for_mode (mode, 1);
6827               tree addr_type = build_pointer_type (piece_type);
6828               tree daddr_type = build_pointer_type_for_mode (piece_type,
6829                                                              ptr_mode, true);
6830               tree src_addr, src;
6831               int src_offset;
6832               tree dest_addr, dest;
6833
6834               if (SSE_REGNO_P (REGNO (reg)))
6835                 {
6836                   src_addr = sse_addr;
6837                   src_offset = (REGNO (reg) - FIRST_SSE_REG) * 16;
6838                 }
6839               else
6840                 {
6841                   src_addr = int_addr;
6842                   src_offset = REGNO (reg) * 8;
6843                 }
6844               src_addr = fold_convert (addr_type, src_addr);
6845               src_addr = fold_build2 (POINTER_PLUS_EXPR, addr_type, src_addr,
6846                                       size_int (src_offset));
6847               src = build_va_arg_indirect_ref (src_addr);
6848
6849               dest_addr = fold_convert (daddr_type, addr);
6850               dest_addr = fold_build2 (POINTER_PLUS_EXPR, daddr_type, dest_addr,
6851                                        size_int (INTVAL (XEXP (slot, 1))));
6852               dest = build_va_arg_indirect_ref (dest_addr);
6853
6854               gimplify_assign (dest, src, pre_p);
6855             }
6856         }
6857
6858       if (needed_intregs)
6859         {
6860           t = build2 (PLUS_EXPR, TREE_TYPE (gpr), gpr,
6861                       build_int_cst (TREE_TYPE (gpr), needed_intregs * 8));
6862           gimplify_assign (gpr, t, pre_p);
6863         }
6864
6865       if (needed_sseregs)
6866         {
6867           t = build2 (PLUS_EXPR, TREE_TYPE (fpr), fpr,
6868                       build_int_cst (TREE_TYPE (fpr), needed_sseregs * 16));
6869           gimplify_assign (fpr, t, pre_p);
6870         }
6871
6872       gimple_seq_add_stmt (pre_p, gimple_build_goto (lab_over));
6873
6874       gimple_seq_add_stmt (pre_p, gimple_build_label (lab_false));
6875     }
6876
6877   /* ... otherwise out of the overflow area.  */
6878
6879   /* When we align parameter on stack for caller, if the parameter
6880      alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be
6881      aligned at MAX_SUPPORTED_STACK_ALIGNMENT.  We will match callee
6882      here with caller.  */
6883   arg_boundary = FUNCTION_ARG_BOUNDARY (VOIDmode, type);
6884   if ((unsigned int) arg_boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
6885     arg_boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
6886
6887   /* Care for on-stack alignment if needed.  */
6888   if (arg_boundary <= 64
6889       || integer_zerop (TYPE_SIZE (type)))
6890     t = ovf;
6891  else
6892     {
6893       HOST_WIDE_INT align = arg_boundary / 8;
6894       t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (ovf), ovf,
6895                   size_int (align - 1));
6896       t = fold_convert (sizetype, t);
6897       t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
6898                   size_int (-align));
6899       t = fold_convert (TREE_TYPE (ovf), t);
6900     }
6901   gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
6902   gimplify_assign (addr, t, pre_p);
6903
6904   t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (t), t,
6905               size_int (rsize * UNITS_PER_WORD));
6906   gimplify_assign (unshare_expr (ovf), t, pre_p);
6907
6908   if (container)
6909     gimple_seq_add_stmt (pre_p, gimple_build_label (lab_over));
6910
6911   ptrtype = build_pointer_type (type);
6912   addr = fold_convert (ptrtype, addr);
6913
6914   if (indirect_p)
6915     addr = build_va_arg_indirect_ref (addr);
6916   return build_va_arg_indirect_ref (addr);
6917 }
6918 \f
6919 /* Return nonzero if OPNUM's MEM should be matched
6920    in movabs* patterns.  */
6921
6922 int
6923 ix86_check_movabs (rtx insn, int opnum)
6924 {
6925   rtx set, mem;
6926
6927   set = PATTERN (insn);
6928   if (GET_CODE (set) == PARALLEL)
6929     set = XVECEXP (set, 0, 0);
6930   gcc_assert (GET_CODE (set) == SET);
6931   mem = XEXP (set, opnum);
6932   while (GET_CODE (mem) == SUBREG)
6933     mem = SUBREG_REG (mem);
6934   gcc_assert (MEM_P (mem));
6935   return (volatile_ok || !MEM_VOLATILE_P (mem));
6936 }
6937 \f
6938 /* Initialize the table of extra 80387 mathematical constants.  */
6939
6940 static void
6941 init_ext_80387_constants (void)
6942 {
6943   static const char * cst[5] =
6944   {
6945     "0.3010299956639811952256464283594894482",  /* 0: fldlg2  */
6946     "0.6931471805599453094286904741849753009",  /* 1: fldln2  */
6947     "1.4426950408889634073876517827983434472",  /* 2: fldl2e  */
6948     "3.3219280948873623478083405569094566090",  /* 3: fldl2t  */
6949     "3.1415926535897932385128089594061862044",  /* 4: fldpi   */
6950   };
6951   int i;
6952
6953   for (i = 0; i < 5; i++)
6954     {
6955       real_from_string (&ext_80387_constants_table[i], cst[i]);
6956       /* Ensure each constant is rounded to XFmode precision.  */
6957       real_convert (&ext_80387_constants_table[i],
6958                     XFmode, &ext_80387_constants_table[i]);
6959     }
6960
6961   ext_80387_constants_init = 1;
6962 }
6963
6964 /* Return true if the constant is something that can be loaded with
6965    a special instruction.  */
6966
6967 int
6968 standard_80387_constant_p (rtx x)
6969 {
6970   enum machine_mode mode = GET_MODE (x);
6971
6972   REAL_VALUE_TYPE r;
6973
6974   if (!(X87_FLOAT_MODE_P (mode) && (GET_CODE (x) == CONST_DOUBLE)))
6975     return -1;
6976
6977   if (x == CONST0_RTX (mode))
6978     return 1;
6979   if (x == CONST1_RTX (mode))
6980     return 2;
6981
6982   REAL_VALUE_FROM_CONST_DOUBLE (r, x);
6983
6984   /* For XFmode constants, try to find a special 80387 instruction when
6985      optimizing for size or on those CPUs that benefit from them.  */
6986   if (mode == XFmode
6987       && (optimize_function_for_size_p (cfun) || TARGET_EXT_80387_CONSTANTS))
6988     {
6989       int i;
6990
6991       if (! ext_80387_constants_init)
6992         init_ext_80387_constants ();
6993
6994       for (i = 0; i < 5; i++)
6995         if (real_identical (&r, &ext_80387_constants_table[i]))
6996           return i + 3;
6997     }
6998
6999   /* Load of the constant -0.0 or -1.0 will be split as
7000      fldz;fchs or fld1;fchs sequence.  */
7001   if (real_isnegzero (&r))
7002     return 8;
7003   if (real_identical (&r, &dconstm1))
7004     return 9;
7005
7006   return 0;
7007 }
7008
7009 /* Return the opcode of the special instruction to be used to load
7010    the constant X.  */
7011
7012 const char *
7013 standard_80387_constant_opcode (rtx x)
7014 {
7015   switch (standard_80387_constant_p (x))
7016     {
7017     case 1:
7018       return "fldz";
7019     case 2:
7020       return "fld1";
7021     case 3:
7022       return "fldlg2";
7023     case 4:
7024       return "fldln2";
7025     case 5:
7026       return "fldl2e";
7027     case 6:
7028       return "fldl2t";
7029     case 7:
7030       return "fldpi";
7031     case 8:
7032     case 9:
7033       return "#";
7034     default:
7035       gcc_unreachable ();
7036     }
7037 }
7038
7039 /* Return the CONST_DOUBLE representing the 80387 constant that is
7040    loaded by the specified special instruction.  The argument IDX
7041    matches the return value from standard_80387_constant_p.  */
7042
7043 rtx
7044 standard_80387_constant_rtx (int idx)
7045 {
7046   int i;
7047
7048   if (! ext_80387_constants_init)
7049     init_ext_80387_constants ();
7050
7051   switch (idx)
7052     {
7053     case 3:
7054     case 4:
7055     case 5:
7056     case 6:
7057     case 7:
7058       i = idx - 3;
7059       break;
7060
7061     default:
7062       gcc_unreachable ();
7063     }
7064
7065   return CONST_DOUBLE_FROM_REAL_VALUE (ext_80387_constants_table[i],
7066                                        XFmode);
7067 }
7068
7069 /* Return 1 if mode is a valid mode for sse.  */
7070 static int
7071 standard_sse_mode_p (enum machine_mode mode)
7072 {
7073   switch (mode)
7074     {
7075     case V16QImode:
7076     case V8HImode:
7077     case V4SImode:
7078     case V2DImode:
7079     case V4SFmode:
7080     case V2DFmode:
7081       return 1;
7082
7083     default:
7084       return 0;
7085     }
7086 }
7087
7088 /* Return 1 if X is all 0s.  For all 1s, return 2 if X is in 128bit
7089    SSE modes and SSE2 is enabled,  return 3 if X is in 256bit AVX
7090    modes and AVX is enabled.  */
7091
7092 int
7093 standard_sse_constant_p (rtx x)
7094 {
7095   enum machine_mode mode = GET_MODE (x);
7096
7097   if (x == const0_rtx || x == CONST0_RTX (GET_MODE (x)))
7098     return 1;
7099   if (vector_all_ones_operand (x, mode))
7100     {
7101       if (standard_sse_mode_p (mode))
7102         return TARGET_SSE2 ? 2 : -2;
7103       else if (VALID_AVX256_REG_MODE (mode))
7104         return TARGET_AVX ? 3 : -3;
7105     }
7106
7107   return 0;
7108 }
7109
7110 /* Return the opcode of the special instruction to be used to load
7111    the constant X.  */
7112
7113 const char *
7114 standard_sse_constant_opcode (rtx insn, rtx x)
7115 {
7116   switch (standard_sse_constant_p (x))
7117     {
7118     case 1:
7119       switch (get_attr_mode (insn))
7120         {
7121         case MODE_V4SF:
7122           return TARGET_AVX ? "vxorps\t%0, %0, %0" : "xorps\t%0, %0";
7123         case MODE_V2DF:
7124           return TARGET_AVX ? "vxorpd\t%0, %0, %0" : "xorpd\t%0, %0";
7125         case MODE_TI:
7126           return TARGET_AVX ? "vpxor\t%0, %0, %0" : "pxor\t%0, %0";
7127         case MODE_V8SF:
7128           return "vxorps\t%x0, %x0, %x0";
7129         case MODE_V4DF:
7130           return "vxorpd\t%x0, %x0, %x0";
7131         case MODE_OI:
7132           return "vpxor\t%x0, %x0, %x0";
7133         default:
7134           gcc_unreachable ();
7135         }
7136     case 2:
7137       if (TARGET_AVX)
7138         switch (get_attr_mode (insn))
7139           {
7140           case MODE_V4SF:
7141           case MODE_V2DF:
7142           case MODE_TI:
7143             return "vpcmpeqd\t%0, %0, %0";
7144             break;
7145           default:
7146             gcc_unreachable ();
7147         }
7148       else
7149         return "pcmpeqd\t%0, %0";
7150     }
7151   gcc_unreachable ();
7152 }
7153
7154 /* Returns 1 if OP contains a symbol reference */
7155
7156 int
7157 symbolic_reference_mentioned_p (rtx op)
7158 {
7159   const char *fmt;
7160   int i;
7161
7162   if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
7163     return 1;
7164
7165   fmt = GET_RTX_FORMAT (GET_CODE (op));
7166   for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
7167     {
7168       if (fmt[i] == 'E')
7169         {
7170           int j;
7171
7172           for (j = XVECLEN (op, i) - 1; j >= 0; j--)
7173             if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
7174               return 1;
7175         }
7176
7177       else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
7178         return 1;
7179     }
7180
7181   return 0;
7182 }
7183
7184 /* Return 1 if it is appropriate to emit `ret' instructions in the
7185    body of a function.  Do this only if the epilogue is simple, needing a
7186    couple of insns.  Prior to reloading, we can't tell how many registers
7187    must be saved, so return 0 then.  Return 0 if there is no frame
7188    marker to de-allocate.  */
7189
7190 int
7191 ix86_can_use_return_insn_p (void)
7192 {
7193   struct ix86_frame frame;
7194
7195   if (! reload_completed || frame_pointer_needed)
7196     return 0;
7197
7198   /* Don't allow more than 32 pop, since that's all we can do
7199      with one instruction.  */
7200   if (crtl->args.pops_args
7201       && crtl->args.size >= 32768)
7202     return 0;
7203
7204   ix86_compute_frame_layout (&frame);
7205   return frame.to_allocate == 0 && (frame.nregs + frame.nsseregs) == 0;
7206 }
7207 \f
7208 /* Value should be nonzero if functions must have frame pointers.
7209    Zero means the frame pointer need not be set up (and parms may
7210    be accessed via the stack pointer) in functions that seem suitable.  */
7211
7212 int
7213 ix86_frame_pointer_required (void)
7214 {
7215   /* If we accessed previous frames, then the generated code expects
7216      to be able to access the saved ebp value in our frame.  */
7217   if (cfun->machine->accesses_prev_frame)
7218     return 1;
7219
7220   /* Several x86 os'es need a frame pointer for other reasons,
7221      usually pertaining to setjmp.  */
7222   if (SUBTARGET_FRAME_POINTER_REQUIRED)
7223     return 1;
7224
7225   /* In override_options, TARGET_OMIT_LEAF_FRAME_POINTER turns off
7226      the frame pointer by default.  Turn it back on now if we've not
7227      got a leaf function.  */
7228   if (TARGET_OMIT_LEAF_FRAME_POINTER
7229       && (!current_function_is_leaf
7230           || ix86_current_function_calls_tls_descriptor))
7231     return 1;
7232
7233   if (crtl->profile)
7234     return 1;
7235
7236   return 0;
7237 }
7238
7239 /* Record that the current function accesses previous call frames.  */
7240
7241 void
7242 ix86_setup_frame_addresses (void)
7243 {
7244   cfun->machine->accesses_prev_frame = 1;
7245 }
7246 \f
7247 #if (defined(HAVE_GAS_HIDDEN) && (SUPPORTS_ONE_ONLY - 0)) || TARGET_MACHO
7248 # define USE_HIDDEN_LINKONCE 1
7249 #else
7250 # define USE_HIDDEN_LINKONCE 0
7251 #endif
7252
7253 static int pic_labels_used;
7254
7255 /* Fills in the label name that should be used for a pc thunk for
7256    the given register.  */
7257
7258 static void
7259 get_pc_thunk_name (char name[32], unsigned int regno)
7260 {
7261   gcc_assert (!TARGET_64BIT);
7262
7263   if (USE_HIDDEN_LINKONCE)
7264     sprintf (name, "__i686.get_pc_thunk.%s", reg_names[regno]);
7265   else
7266     ASM_GENERATE_INTERNAL_LABEL (name, "LPR", regno);
7267 }
7268
7269
7270 /* This function generates code for -fpic that loads %ebx with
7271    the return address of the caller and then returns.  */
7272
7273 void
7274 ix86_file_end (void)
7275 {
7276   rtx xops[2];
7277   int regno;
7278
7279   for (regno = 0; regno < 8; ++regno)
7280     {
7281       char name[32];
7282
7283       if (! ((pic_labels_used >> regno) & 1))
7284         continue;
7285
7286       get_pc_thunk_name (name, regno);
7287
7288 #if TARGET_MACHO
7289       if (TARGET_MACHO)
7290         {
7291           switch_to_section (darwin_sections[text_coal_section]);
7292           fputs ("\t.weak_definition\t", asm_out_file);
7293           assemble_name (asm_out_file, name);
7294           fputs ("\n\t.private_extern\t", asm_out_file);
7295           assemble_name (asm_out_file, name);
7296           fputs ("\n", asm_out_file);
7297           ASM_OUTPUT_LABEL (asm_out_file, name);
7298         }
7299       else
7300 #endif
7301       if (USE_HIDDEN_LINKONCE)
7302         {
7303           tree decl;
7304
7305           decl = build_decl (FUNCTION_DECL, get_identifier (name),
7306                              error_mark_node);
7307           TREE_PUBLIC (decl) = 1;
7308           TREE_STATIC (decl) = 1;
7309           DECL_ONE_ONLY (decl) = 1;
7310
7311           (*targetm.asm_out.unique_section) (decl, 0);
7312           switch_to_section (get_named_section (decl, NULL, 0));
7313
7314           (*targetm.asm_out.globalize_label) (asm_out_file, name);
7315           fputs ("\t.hidden\t", asm_out_file);
7316           assemble_name (asm_out_file, name);
7317           fputc ('\n', asm_out_file);
7318           ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl);
7319         }
7320       else
7321         {
7322           switch_to_section (text_section);
7323           ASM_OUTPUT_LABEL (asm_out_file, name);
7324         }
7325
7326       xops[0] = gen_rtx_REG (Pmode, regno);
7327       xops[1] = gen_rtx_MEM (Pmode, stack_pointer_rtx);
7328       output_asm_insn ("mov%z0\t{%1, %0|%0, %1}", xops);
7329       output_asm_insn ("ret", xops);
7330     }
7331
7332   if (NEED_INDICATE_EXEC_STACK)
7333     file_end_indicate_exec_stack ();
7334 }
7335
7336 /* Emit code for the SET_GOT patterns.  */
7337
7338 const char *
7339 output_set_got (rtx dest, rtx label ATTRIBUTE_UNUSED)
7340 {
7341   rtx xops[3];
7342
7343   xops[0] = dest;
7344
7345   if (TARGET_VXWORKS_RTP && flag_pic)
7346     {
7347       /* Load (*VXWORKS_GOTT_BASE) into the PIC register.  */
7348       xops[2] = gen_rtx_MEM (Pmode,
7349                              gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE));
7350       output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops);
7351
7352       /* Load (*VXWORKS_GOTT_BASE)[VXWORKS_GOTT_INDEX] into the PIC register.
7353          Use %P and a local symbol in order to print VXWORKS_GOTT_INDEX as
7354          an unadorned address.  */
7355       xops[2] = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX);
7356       SYMBOL_REF_FLAGS (xops[2]) |= SYMBOL_FLAG_LOCAL;
7357       output_asm_insn ("mov{l}\t{%P2(%0), %0|%0, DWORD PTR %P2[%0]}", xops);
7358       return "";
7359     }
7360
7361   xops[1] = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
7362
7363   if (! TARGET_DEEP_BRANCH_PREDICTION || !flag_pic)
7364     {
7365       xops[2] = gen_rtx_LABEL_REF (Pmode, label ? label : gen_label_rtx ());
7366
7367       if (!flag_pic)
7368         output_asm_insn ("mov%z0\t{%2, %0|%0, %2}", xops);
7369       else
7370         output_asm_insn ("call\t%a2", xops);
7371
7372 #if TARGET_MACHO
7373       /* Output the Mach-O "canonical" label name ("Lxx$pb") here too.  This
7374          is what will be referenced by the Mach-O PIC subsystem.  */
7375       if (!label)
7376         ASM_OUTPUT_LABEL (asm_out_file, MACHOPIC_FUNCTION_BASE_NAME);
7377 #endif
7378
7379       (*targetm.asm_out.internal_label) (asm_out_file, "L",
7380                                  CODE_LABEL_NUMBER (XEXP (xops[2], 0)));
7381
7382       if (flag_pic)
7383         output_asm_insn ("pop%z0\t%0", xops);
7384     }
7385   else
7386     {
7387       char name[32];
7388       get_pc_thunk_name (name, REGNO (dest));
7389       pic_labels_used |= 1 << REGNO (dest);
7390
7391       xops[2] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
7392       xops[2] = gen_rtx_MEM (QImode, xops[2]);
7393       output_asm_insn ("call\t%X2", xops);
7394       /* Output the Mach-O "canonical" label name ("Lxx$pb") here too.  This
7395          is what will be referenced by the Mach-O PIC subsystem.  */
7396 #if TARGET_MACHO
7397       if (!label)
7398         ASM_OUTPUT_LABEL (asm_out_file, MACHOPIC_FUNCTION_BASE_NAME);
7399       else
7400         targetm.asm_out.internal_label (asm_out_file, "L",
7401                                            CODE_LABEL_NUMBER (label));
7402 #endif
7403     }
7404
7405   if (TARGET_MACHO)
7406     return "";
7407
7408   if (!flag_pic || TARGET_DEEP_BRANCH_PREDICTION)
7409     output_asm_insn ("add%z0\t{%1, %0|%0, %1}", xops);
7410   else
7411     output_asm_insn ("add%z0\t{%1+[.-%a2], %0|%0, %1+(.-%a2)}", xops);
7412
7413   return "";
7414 }
7415
7416 /* Generate an "push" pattern for input ARG.  */
7417
7418 static rtx
7419 gen_push (rtx arg)
7420 {
7421   return gen_rtx_SET (VOIDmode,
7422                       gen_rtx_MEM (Pmode,
7423                                    gen_rtx_PRE_DEC (Pmode,
7424                                                     stack_pointer_rtx)),
7425                       arg);
7426 }
7427
7428 /* Return >= 0 if there is an unused call-clobbered register available
7429    for the entire function.  */
7430
7431 static unsigned int
7432 ix86_select_alt_pic_regnum (void)
7433 {
7434   if (current_function_is_leaf && !crtl->profile
7435       && !ix86_current_function_calls_tls_descriptor)
7436     {
7437       int i, drap;
7438       /* Can't use the same register for both PIC and DRAP.  */
7439       if (crtl->drap_reg)
7440         drap = REGNO (crtl->drap_reg);
7441       else
7442         drap = -1;
7443       for (i = 2; i >= 0; --i)
7444         if (i != drap && !df_regs_ever_live_p (i))
7445           return i;
7446     }
7447
7448   return INVALID_REGNUM;
7449 }
7450
7451 /* Return 1 if we need to save REGNO.  */
7452 static int
7453 ix86_save_reg (unsigned int regno, int maybe_eh_return)
7454 {
7455   if (pic_offset_table_rtx
7456       && regno == REAL_PIC_OFFSET_TABLE_REGNUM
7457       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
7458           || crtl->profile
7459           || crtl->calls_eh_return
7460           || crtl->uses_const_pool))
7461     {
7462       if (ix86_select_alt_pic_regnum () != INVALID_REGNUM)
7463         return 0;
7464       return 1;
7465     }
7466
7467   if (crtl->calls_eh_return && maybe_eh_return)
7468     {
7469       unsigned i;
7470       for (i = 0; ; i++)
7471         {
7472           unsigned test = EH_RETURN_DATA_REGNO (i);
7473           if (test == INVALID_REGNUM)
7474             break;
7475           if (test == regno)
7476             return 1;
7477         }
7478     }
7479
7480   if (crtl->drap_reg
7481       && regno == REGNO (crtl->drap_reg))
7482     return 1;
7483
7484   return (df_regs_ever_live_p (regno)
7485           && !call_used_regs[regno]
7486           && !fixed_regs[regno]
7487           && (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed));
7488 }
7489
7490 /* Return number of saved general prupose registers.  */
7491
7492 static int
7493 ix86_nsaved_regs (void)
7494 {
7495   int nregs = 0;
7496   int regno;
7497
7498   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7499     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
7500       nregs ++;
7501   return nregs;
7502 }
7503
7504 /* Return number of saved SSE registrers.  */
7505
7506 static int
7507 ix86_nsaved_sseregs (void)
7508 {
7509   int nregs = 0;
7510   int regno;
7511
7512   if (ix86_cfun_abi () != MS_ABI)
7513     return 0;
7514   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7515     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
7516       nregs ++;
7517   return nregs;
7518 }
7519
7520 /* Given FROM and TO register numbers, say whether this elimination is
7521    allowed.  If stack alignment is needed, we can only replace argument
7522    pointer with hard frame pointer, or replace frame pointer with stack
7523    pointer.  Otherwise, frame pointer elimination is automatically
7524    handled and all other eliminations are valid.  */
7525
7526 int
7527 ix86_can_eliminate (int from, int to)
7528 {
7529   if (stack_realign_fp)
7530     return ((from == ARG_POINTER_REGNUM
7531              && to == HARD_FRAME_POINTER_REGNUM)
7532             || (from == FRAME_POINTER_REGNUM
7533                 && to == STACK_POINTER_REGNUM));
7534   else
7535     return to == STACK_POINTER_REGNUM ? !frame_pointer_needed : 1;
7536 }
7537
7538 /* Return the offset between two registers, one to be eliminated, and the other
7539    its replacement, at the start of a routine.  */
7540
7541 HOST_WIDE_INT
7542 ix86_initial_elimination_offset (int from, int to)
7543 {
7544   struct ix86_frame frame;
7545   ix86_compute_frame_layout (&frame);
7546
7547   if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
7548     return frame.hard_frame_pointer_offset;
7549   else if (from == FRAME_POINTER_REGNUM
7550            && to == HARD_FRAME_POINTER_REGNUM)
7551     return frame.hard_frame_pointer_offset - frame.frame_pointer_offset;
7552   else
7553     {
7554       gcc_assert (to == STACK_POINTER_REGNUM);
7555
7556       if (from == ARG_POINTER_REGNUM)
7557         return frame.stack_pointer_offset;
7558
7559       gcc_assert (from == FRAME_POINTER_REGNUM);
7560       return frame.stack_pointer_offset - frame.frame_pointer_offset;
7561     }
7562 }
7563
7564 /* In a dynamically-aligned function, we can't know the offset from
7565    stack pointer to frame pointer, so we must ensure that setjmp
7566    eliminates fp against the hard fp (%ebp) rather than trying to
7567    index from %esp up to the top of the frame across a gap that is
7568    of unknown (at compile-time) size.  */
7569 static rtx
7570 ix86_builtin_setjmp_frame_value (void)
7571 {
7572   return stack_realign_fp ? hard_frame_pointer_rtx : virtual_stack_vars_rtx;
7573 }
7574
7575 /* Fill structure ix86_frame about frame of currently computed function.  */
7576
7577 static void
7578 ix86_compute_frame_layout (struct ix86_frame *frame)
7579 {
7580   HOST_WIDE_INT total_size;
7581   unsigned int stack_alignment_needed;
7582   HOST_WIDE_INT offset;
7583   unsigned int preferred_alignment;
7584   HOST_WIDE_INT size = get_frame_size ();
7585
7586   frame->nregs = ix86_nsaved_regs ();
7587   frame->nsseregs = ix86_nsaved_sseregs ();
7588   total_size = size;
7589
7590   stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT;
7591   preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT;
7592
7593   /* MS ABI seem to require stack alignment to be always 16 except for function
7594      prologues.  */
7595   if (ix86_cfun_abi () == MS_ABI && preferred_alignment < 16)
7596     {
7597       preferred_alignment = 16;
7598       stack_alignment_needed = 16;
7599       crtl->preferred_stack_boundary = 128;
7600       crtl->stack_alignment_needed = 128;
7601     }
7602
7603   gcc_assert (!size || stack_alignment_needed);
7604   gcc_assert (preferred_alignment >= STACK_BOUNDARY / BITS_PER_UNIT);
7605   gcc_assert (preferred_alignment <= stack_alignment_needed);
7606
7607   /* During reload iteration the amount of registers saved can change.
7608      Recompute the value as needed.  Do not recompute when amount of registers
7609      didn't change as reload does multiple calls to the function and does not
7610      expect the decision to change within single iteration.  */
7611   if (!optimize_function_for_size_p (cfun)
7612       && cfun->machine->use_fast_prologue_epilogue_nregs != frame->nregs)
7613     {
7614       int count = frame->nregs;
7615
7616       cfun->machine->use_fast_prologue_epilogue_nregs = count;
7617       /* The fast prologue uses move instead of push to save registers.  This
7618          is significantly longer, but also executes faster as modern hardware
7619          can execute the moves in parallel, but can't do that for push/pop.
7620
7621          Be careful about choosing what prologue to emit:  When function takes
7622          many instructions to execute we may use slow version as well as in
7623          case function is known to be outside hot spot (this is known with
7624          feedback only).  Weight the size of function by number of registers
7625          to save as it is cheap to use one or two push instructions but very
7626          slow to use many of them.  */
7627       if (count)
7628         count = (count - 1) * FAST_PROLOGUE_INSN_COUNT;
7629       if (cfun->function_frequency < FUNCTION_FREQUENCY_NORMAL
7630           || (flag_branch_probabilities
7631               && cfun->function_frequency < FUNCTION_FREQUENCY_HOT))
7632         cfun->machine->use_fast_prologue_epilogue = false;
7633       else
7634         cfun->machine->use_fast_prologue_epilogue
7635            = !expensive_function_p (count);
7636     }
7637   if (TARGET_PROLOGUE_USING_MOVE
7638       && cfun->machine->use_fast_prologue_epilogue)
7639     frame->save_regs_using_mov = true;
7640   else
7641     frame->save_regs_using_mov = false;
7642
7643
7644   /* Skip return address and saved base pointer.  */
7645   offset = frame_pointer_needed ? UNITS_PER_WORD * 2 : UNITS_PER_WORD;
7646
7647   frame->hard_frame_pointer_offset = offset;
7648
7649   /* Set offset to aligned because the realigned frame starts from
7650      here.  */
7651   if (stack_realign_fp)
7652     offset = (offset + stack_alignment_needed -1) & -stack_alignment_needed;
7653
7654   /* Register save area */
7655   offset += frame->nregs * UNITS_PER_WORD;
7656
7657   /* Align SSE reg save area.  */
7658   if (frame->nsseregs)
7659     frame->padding0 = ((offset + 16 - 1) & -16) - offset;
7660   else
7661     frame->padding0 = 0;
7662   
7663   /* SSE register save area.  */
7664   offset += frame->padding0 + frame->nsseregs * 16;
7665
7666   /* Va-arg area */
7667   frame->va_arg_size = ix86_varargs_gpr_size + ix86_varargs_fpr_size;
7668   offset += frame->va_arg_size;
7669
7670   /* Align start of frame for local function.  */
7671   frame->padding1 = ((offset + stack_alignment_needed - 1)
7672                      & -stack_alignment_needed) - offset;
7673
7674   offset += frame->padding1;
7675
7676   /* Frame pointer points here.  */
7677   frame->frame_pointer_offset = offset;
7678
7679   offset += size;
7680
7681   /* Add outgoing arguments area.  Can be skipped if we eliminated
7682      all the function calls as dead code.
7683      Skipping is however impossible when function calls alloca.  Alloca
7684      expander assumes that last crtl->outgoing_args_size
7685      of stack frame are unused.  */
7686   if (ACCUMULATE_OUTGOING_ARGS
7687       && (!current_function_is_leaf || cfun->calls_alloca
7688           || ix86_current_function_calls_tls_descriptor))
7689     {
7690       offset += crtl->outgoing_args_size;
7691       frame->outgoing_arguments_size = crtl->outgoing_args_size;
7692     }
7693   else
7694     frame->outgoing_arguments_size = 0;
7695
7696   /* Align stack boundary.  Only needed if we're calling another function
7697      or using alloca.  */
7698   if (!current_function_is_leaf || cfun->calls_alloca
7699       || ix86_current_function_calls_tls_descriptor)
7700     frame->padding2 = ((offset + preferred_alignment - 1)
7701                        & -preferred_alignment) - offset;
7702   else
7703     frame->padding2 = 0;
7704
7705   offset += frame->padding2;
7706
7707   /* We've reached end of stack frame.  */
7708   frame->stack_pointer_offset = offset;
7709
7710   /* Size prologue needs to allocate.  */
7711   frame->to_allocate =
7712     (size + frame->padding1 + frame->padding2
7713      + frame->outgoing_arguments_size + frame->va_arg_size);
7714
7715   if ((!frame->to_allocate && frame->nregs <= 1)
7716       || (TARGET_64BIT && frame->to_allocate >= (HOST_WIDE_INT) 0x80000000))
7717     frame->save_regs_using_mov = false;
7718
7719   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE && current_function_sp_is_unchanging
7720       && current_function_is_leaf
7721       && !ix86_current_function_calls_tls_descriptor)
7722     {
7723       frame->red_zone_size = frame->to_allocate;
7724       if (frame->save_regs_using_mov)
7725         frame->red_zone_size += frame->nregs * UNITS_PER_WORD;
7726       if (frame->red_zone_size > RED_ZONE_SIZE - RED_ZONE_RESERVE)
7727         frame->red_zone_size = RED_ZONE_SIZE - RED_ZONE_RESERVE;
7728     }
7729   else
7730     frame->red_zone_size = 0;
7731   frame->to_allocate -= frame->red_zone_size;
7732   frame->stack_pointer_offset -= frame->red_zone_size;
7733 #if 0
7734   fprintf (stderr, "\n");
7735   fprintf (stderr, "size: %ld\n", (long)size);
7736   fprintf (stderr, "nregs: %ld\n", (long)frame->nregs);
7737   fprintf (stderr, "nsseregs: %ld\n", (long)frame->nsseregs);
7738   fprintf (stderr, "padding0: %ld\n", (long)frame->padding0);
7739   fprintf (stderr, "alignment1: %ld\n", (long)stack_alignment_needed);
7740   fprintf (stderr, "padding1: %ld\n", (long)frame->padding1);
7741   fprintf (stderr, "va_arg: %ld\n", (long)frame->va_arg_size);
7742   fprintf (stderr, "padding2: %ld\n", (long)frame->padding2);
7743   fprintf (stderr, "to_allocate: %ld\n", (long)frame->to_allocate);
7744   fprintf (stderr, "red_zone_size: %ld\n", (long)frame->red_zone_size);
7745   fprintf (stderr, "frame_pointer_offset: %ld\n", (long)frame->frame_pointer_offset);
7746   fprintf (stderr, "hard_frame_pointer_offset: %ld\n",
7747            (long)frame->hard_frame_pointer_offset);
7748   fprintf (stderr, "stack_pointer_offset: %ld\n", (long)frame->stack_pointer_offset);
7749   fprintf (stderr, "current_function_is_leaf: %ld\n", (long)current_function_is_leaf);
7750   fprintf (stderr, "cfun->calls_alloca: %ld\n", (long)cfun->calls_alloca);
7751   fprintf (stderr, "x86_current_function_calls_tls_descriptor: %ld\n", (long)ix86_current_function_calls_tls_descriptor);
7752 #endif
7753 }
7754
7755 /* Emit code to save registers in the prologue.  */
7756
7757 static void
7758 ix86_emit_save_regs (void)
7759 {
7760   unsigned int regno;
7761   rtx insn;
7762
7763   for (regno = FIRST_PSEUDO_REGISTER - 1; regno-- > 0; )
7764     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
7765       {
7766         insn = emit_insn (gen_push (gen_rtx_REG (Pmode, regno)));
7767         RTX_FRAME_RELATED_P (insn) = 1;
7768       }
7769 }
7770
7771 /* Emit code to save registers using MOV insns.  First register
7772    is restored from POINTER + OFFSET.  */
7773 static void
7774 ix86_emit_save_regs_using_mov (rtx pointer, HOST_WIDE_INT offset)
7775 {
7776   unsigned int regno;
7777   rtx insn;
7778
7779   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7780     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
7781       {
7782         insn = emit_move_insn (adjust_address (gen_rtx_MEM (Pmode, pointer),
7783                                                Pmode, offset),
7784                                gen_rtx_REG (Pmode, regno));
7785         RTX_FRAME_RELATED_P (insn) = 1;
7786         offset += UNITS_PER_WORD;
7787       }
7788 }
7789
7790 /* Emit code to save registers using MOV insns.  First register
7791    is restored from POINTER + OFFSET.  */
7792 static void
7793 ix86_emit_save_sse_regs_using_mov (rtx pointer, HOST_WIDE_INT offset)
7794 {
7795   unsigned int regno;
7796   rtx insn;
7797   rtx mem;
7798
7799   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7800     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
7801       {
7802         mem = adjust_address (gen_rtx_MEM (TImode, pointer), TImode, offset);
7803         set_mem_align (mem, 128);
7804         insn = emit_move_insn (mem, gen_rtx_REG (TImode, regno));
7805         RTX_FRAME_RELATED_P (insn) = 1;
7806         offset += 16;
7807       }
7808 }
7809
7810 /* Expand prologue or epilogue stack adjustment.
7811    The pattern exist to put a dependency on all ebp-based memory accesses.
7812    STYLE should be negative if instructions should be marked as frame related,
7813    zero if %r11 register is live and cannot be freely used and positive
7814    otherwise.  */
7815
7816 static void
7817 pro_epilogue_adjust_stack (rtx dest, rtx src, rtx offset, int style)
7818 {
7819   rtx insn;
7820
7821   if (! TARGET_64BIT)
7822     insn = emit_insn (gen_pro_epilogue_adjust_stack_1 (dest, src, offset));
7823   else if (x86_64_immediate_operand (offset, DImode))
7824     insn = emit_insn (gen_pro_epilogue_adjust_stack_rex64 (dest, src, offset));
7825   else
7826     {
7827       rtx r11;
7828       /* r11 is used by indirect sibcall return as well, set before the
7829          epilogue and used after the epilogue.  ATM indirect sibcall
7830          shouldn't be used together with huge frame sizes in one
7831          function because of the frame_size check in sibcall.c.  */
7832       gcc_assert (style);
7833       r11 = gen_rtx_REG (DImode, R11_REG);
7834       insn = emit_insn (gen_rtx_SET (DImode, r11, offset));
7835       if (style < 0)
7836         RTX_FRAME_RELATED_P (insn) = 1;
7837       insn = emit_insn (gen_pro_epilogue_adjust_stack_rex64_2 (dest, src, r11,
7838                                                                offset));
7839     }
7840   if (style < 0)
7841     RTX_FRAME_RELATED_P (insn) = 1;
7842 }
7843
7844 /* Find an available register to be used as dynamic realign argument
7845    pointer regsiter.  Such a register will be written in prologue and
7846    used in begin of body, so it must not be
7847         1. parameter passing register.
7848         2. GOT pointer.
7849    We reuse static-chain register if it is available.  Otherwise, we
7850    use DI for i386 and R13 for x86-64.  We chose R13 since it has
7851    shorter encoding.
7852
7853    Return: the regno of chosen register.  */
7854
7855 static unsigned int 
7856 find_drap_reg (void)
7857 {
7858   tree decl = cfun->decl;
7859
7860   if (TARGET_64BIT)
7861     {
7862       /* Use R13 for nested function or function need static chain.
7863          Since function with tail call may use any caller-saved
7864          registers in epilogue, DRAP must not use caller-saved
7865          register in such case.  */
7866       if ((decl_function_context (decl)
7867            && !DECL_NO_STATIC_CHAIN (decl))
7868           || crtl->tail_call_emit)
7869         return R13_REG;
7870
7871       return R10_REG;
7872     }
7873   else
7874     {
7875       /* Use DI for nested function or function need static chain.
7876          Since function with tail call may use any caller-saved
7877          registers in epilogue, DRAP must not use caller-saved
7878          register in such case.  */
7879       if ((decl_function_context (decl)
7880            && !DECL_NO_STATIC_CHAIN (decl))
7881           || crtl->tail_call_emit)
7882         return DI_REG;
7883     
7884       /* Reuse static chain register if it isn't used for parameter
7885          passing.  */
7886       if (ix86_function_regparm (TREE_TYPE (decl), decl) <= 2
7887           && !lookup_attribute ("fastcall",
7888                                 TYPE_ATTRIBUTES (TREE_TYPE (decl))))
7889         return CX_REG;
7890       else
7891         return DI_REG;
7892     }
7893 }
7894
7895 /* Update incoming stack boundary and estimated stack alignment.  */
7896
7897 static void
7898 ix86_update_stack_boundary (void)
7899 {
7900   /* Prefer the one specified at command line. */
7901   ix86_incoming_stack_boundary 
7902     = (ix86_user_incoming_stack_boundary
7903        ? ix86_user_incoming_stack_boundary
7904        : ix86_default_incoming_stack_boundary);
7905
7906   /* Incoming stack alignment can be changed on individual functions
7907      via force_align_arg_pointer attribute.  We use the smallest
7908      incoming stack boundary.  */
7909   if (ix86_incoming_stack_boundary > MIN_STACK_BOUNDARY
7910       && lookup_attribute (ix86_force_align_arg_pointer_string,
7911                            TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
7912     ix86_incoming_stack_boundary = MIN_STACK_BOUNDARY;
7913
7914   /* The incoming stack frame has to be aligned at least at
7915      parm_stack_boundary.  */
7916   if (ix86_incoming_stack_boundary < crtl->parm_stack_boundary)
7917     ix86_incoming_stack_boundary = crtl->parm_stack_boundary;
7918
7919   /* Stack at entrance of main is aligned by runtime.  We use the
7920      smallest incoming stack boundary. */
7921   if (ix86_incoming_stack_boundary > MAIN_STACK_BOUNDARY
7922       && DECL_NAME (current_function_decl)
7923       && MAIN_NAME_P (DECL_NAME (current_function_decl))
7924       && DECL_FILE_SCOPE_P (current_function_decl))
7925     ix86_incoming_stack_boundary = MAIN_STACK_BOUNDARY;
7926
7927   /* x86_64 vararg needs 16byte stack alignment for register save
7928      area.  */
7929   if (TARGET_64BIT
7930       && cfun->stdarg
7931       && crtl->stack_alignment_estimated < 128)
7932     crtl->stack_alignment_estimated = 128;
7933 }
7934
7935 /* Handle the TARGET_GET_DRAP_RTX hook.  Return NULL if no DRAP is
7936    needed or an rtx for DRAP otherwise.  */
7937
7938 static rtx
7939 ix86_get_drap_rtx (void)
7940 {
7941   if (ix86_force_drap || !ACCUMULATE_OUTGOING_ARGS)
7942     crtl->need_drap = true;
7943
7944   if (stack_realign_drap)
7945     {
7946       /* Assign DRAP to vDRAP and returns vDRAP */
7947       unsigned int regno = find_drap_reg ();
7948       rtx drap_vreg;
7949       rtx arg_ptr;
7950       rtx seq, insn;
7951
7952       arg_ptr = gen_rtx_REG (Pmode, regno);
7953       crtl->drap_reg = arg_ptr;
7954
7955       start_sequence ();
7956       drap_vreg = copy_to_reg (arg_ptr);
7957       seq = get_insns ();
7958       end_sequence ();
7959       
7960       insn = emit_insn_before (seq, NEXT_INSN (entry_of_function ()));
7961       RTX_FRAME_RELATED_P (insn) = 1;
7962       return drap_vreg;
7963     }
7964   else
7965     return NULL;
7966 }
7967
7968 /* Handle the TARGET_INTERNAL_ARG_POINTER hook.  */
7969
7970 static rtx
7971 ix86_internal_arg_pointer (void)
7972 {
7973   return virtual_incoming_args_rtx;
7974 }
7975
7976 /* Handle the TARGET_DWARF_HANDLE_FRAME_UNSPEC hook.
7977    This is called from dwarf2out.c to emit call frame instructions
7978    for frame-related insns containing UNSPECs and UNSPEC_VOLATILEs. */
7979 static void
7980 ix86_dwarf_handle_frame_unspec (const char *label, rtx pattern, int index)
7981 {
7982   rtx unspec = SET_SRC (pattern);
7983   gcc_assert (GET_CODE (unspec) == UNSPEC);
7984
7985   switch (index)
7986     {
7987     case UNSPEC_REG_SAVE:
7988       dwarf2out_reg_save_reg (label, XVECEXP (unspec, 0, 0),
7989                               SET_DEST (pattern));
7990       break;
7991     case UNSPEC_DEF_CFA:
7992       dwarf2out_def_cfa (label, REGNO (SET_DEST (pattern)),
7993                          INTVAL (XVECEXP (unspec, 0, 0)));
7994       break;
7995     default:
7996       gcc_unreachable ();
7997     }
7998 }
7999
8000 /* Finalize stack_realign_needed flag, which will guide prologue/epilogue
8001    to be generated in correct form.  */
8002 static void 
8003 ix86_finalize_stack_realign_flags (void)
8004 {
8005   /* Check if stack realign is really needed after reload, and 
8006      stores result in cfun */
8007   unsigned int incoming_stack_boundary
8008     = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
8009        ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
8010   unsigned int stack_realign = (incoming_stack_boundary
8011                                 < (current_function_is_leaf
8012                                    ? crtl->max_used_stack_slot_alignment
8013                                    : crtl->stack_alignment_needed));
8014
8015   if (crtl->stack_realign_finalized)
8016     {
8017       /* After stack_realign_needed is finalized, we can't no longer
8018          change it.  */
8019       gcc_assert (crtl->stack_realign_needed == stack_realign);
8020     }
8021   else
8022     {
8023       crtl->stack_realign_needed = stack_realign;
8024       crtl->stack_realign_finalized = true;
8025     }
8026 }
8027
8028 /* Expand the prologue into a bunch of separate insns.  */
8029
8030 void
8031 ix86_expand_prologue (void)
8032 {
8033   rtx insn;
8034   bool pic_reg_used;
8035   struct ix86_frame frame;
8036   HOST_WIDE_INT allocate;
8037
8038   ix86_finalize_stack_realign_flags ();
8039
8040   /* DRAP should not coexist with stack_realign_fp */
8041   gcc_assert (!(crtl->drap_reg && stack_realign_fp));
8042
8043   ix86_compute_frame_layout (&frame);
8044
8045   /* Emit prologue code to adjust stack alignment and setup DRAP, in case
8046      of DRAP is needed and stack realignment is really needed after reload */
8047   if (crtl->drap_reg && crtl->stack_realign_needed)
8048     {
8049       rtx x, y;
8050       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
8051       int param_ptr_offset = (call_used_regs[REGNO (crtl->drap_reg)]
8052                               ? 0 : UNITS_PER_WORD);
8053
8054       gcc_assert (stack_realign_drap);
8055
8056       /* Grab the argument pointer.  */
8057       x = plus_constant (stack_pointer_rtx, 
8058                          (UNITS_PER_WORD + param_ptr_offset));
8059       y = crtl->drap_reg;
8060
8061       /* Only need to push parameter pointer reg if it is caller
8062          saved reg */
8063       if (!call_used_regs[REGNO (crtl->drap_reg)])
8064         {
8065           /* Push arg pointer reg */
8066           insn = emit_insn (gen_push (y));
8067           RTX_FRAME_RELATED_P (insn) = 1;
8068         }
8069
8070       insn = emit_insn (gen_rtx_SET (VOIDmode, y, x));
8071       RTX_FRAME_RELATED_P (insn) = 1; 
8072
8073       /* Align the stack.  */
8074       insn = emit_insn ((*ix86_gen_andsp) (stack_pointer_rtx,
8075                                            stack_pointer_rtx,
8076                                            GEN_INT (-align_bytes)));
8077       RTX_FRAME_RELATED_P (insn) = 1;
8078
8079       /* Replicate the return address on the stack so that return
8080          address can be reached via (argp - 1) slot.  This is needed
8081          to implement macro RETURN_ADDR_RTX and intrinsic function
8082          expand_builtin_return_addr etc.  */
8083       x = crtl->drap_reg;
8084       x = gen_frame_mem (Pmode,
8085                          plus_constant (x, -UNITS_PER_WORD));
8086       insn = emit_insn (gen_push (x));
8087       RTX_FRAME_RELATED_P (insn) = 1;
8088     }
8089
8090   /* Note: AT&T enter does NOT have reversed args.  Enter is probably
8091      slower on all targets.  Also sdb doesn't like it.  */
8092
8093   if (frame_pointer_needed)
8094     {
8095       insn = emit_insn (gen_push (hard_frame_pointer_rtx));
8096       RTX_FRAME_RELATED_P (insn) = 1;
8097
8098       insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
8099       RTX_FRAME_RELATED_P (insn) = 1;
8100     }
8101
8102   if (stack_realign_fp)
8103     {
8104       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
8105       gcc_assert (align_bytes > MIN_STACK_BOUNDARY / BITS_PER_UNIT);
8106
8107       /* Align the stack.  */
8108       insn = emit_insn ((*ix86_gen_andsp) (stack_pointer_rtx,
8109                                            stack_pointer_rtx,
8110                                            GEN_INT (-align_bytes)));
8111       RTX_FRAME_RELATED_P (insn) = 1;
8112     }
8113
8114   allocate = frame.to_allocate + frame.nsseregs * 16 + frame.padding0;
8115
8116   if (!frame.save_regs_using_mov)
8117     ix86_emit_save_regs ();
8118   else
8119     allocate += frame.nregs * UNITS_PER_WORD;
8120
8121   /* When using red zone we may start register saving before allocating
8122      the stack frame saving one cycle of the prologue. However I will
8123      avoid doing this if I am going to have to probe the stack since
8124      at least on x86_64 the stack probe can turn into a call that clobbers
8125      a red zone location */
8126   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE && frame.save_regs_using_mov
8127       && (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT))
8128     ix86_emit_save_regs_using_mov ((frame_pointer_needed
8129                                      && !crtl->stack_realign_needed) 
8130                                    ? hard_frame_pointer_rtx
8131                                    : stack_pointer_rtx,
8132                                    -frame.nregs * UNITS_PER_WORD);
8133
8134   if (allocate == 0)
8135     ;
8136   else if (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT)
8137     pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8138                                GEN_INT (-allocate), -1);
8139   else
8140     {
8141       /* Only valid for Win32.  */
8142       rtx eax = gen_rtx_REG (Pmode, AX_REG);
8143       bool eax_live;
8144       rtx t;
8145
8146       gcc_assert (!TARGET_64BIT || cfun->machine->call_abi == MS_ABI);
8147
8148       if (cfun->machine->call_abi == MS_ABI)
8149         eax_live = false;
8150       else
8151         eax_live = ix86_eax_live_at_start_p ();
8152
8153       if (eax_live)
8154         {
8155           emit_insn (gen_push (eax));
8156           allocate -= UNITS_PER_WORD;
8157         }
8158
8159       emit_move_insn (eax, GEN_INT (allocate));
8160
8161       if (TARGET_64BIT)
8162         insn = gen_allocate_stack_worker_64 (eax, eax);
8163       else
8164         insn = gen_allocate_stack_worker_32 (eax, eax);
8165       insn = emit_insn (insn);
8166       RTX_FRAME_RELATED_P (insn) = 1;
8167       t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (-allocate));
8168       t = gen_rtx_SET (VOIDmode, stack_pointer_rtx, t);
8169       REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
8170                                             t, REG_NOTES (insn));
8171
8172       if (eax_live)
8173         {
8174           if (frame_pointer_needed)
8175             t = plus_constant (hard_frame_pointer_rtx,
8176                                allocate
8177                                - frame.to_allocate
8178                                - frame.nregs * UNITS_PER_WORD);
8179           else
8180             t = plus_constant (stack_pointer_rtx, allocate);
8181           emit_move_insn (eax, gen_rtx_MEM (Pmode, t));
8182         }
8183     }
8184
8185   if (frame.save_regs_using_mov
8186       && !(!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE
8187          && (! TARGET_STACK_PROBE || allocate < CHECK_STACK_LIMIT)))
8188     {
8189       if (!frame_pointer_needed
8190           || !frame.to_allocate
8191           || crtl->stack_realign_needed)
8192         ix86_emit_save_regs_using_mov (stack_pointer_rtx,
8193                                        frame.to_allocate
8194                                        + frame.nsseregs * 16 + frame.padding0);
8195       else
8196         ix86_emit_save_regs_using_mov (hard_frame_pointer_rtx,
8197                                        -frame.nregs * UNITS_PER_WORD);
8198     }
8199   if (!frame_pointer_needed
8200       || !frame.to_allocate
8201       || crtl->stack_realign_needed)
8202     ix86_emit_save_sse_regs_using_mov (stack_pointer_rtx,
8203                                        frame.to_allocate);
8204   else
8205     ix86_emit_save_sse_regs_using_mov (hard_frame_pointer_rtx,
8206                                        - frame.nregs * UNITS_PER_WORD
8207                                        - frame.nsseregs * 16
8208                                        - frame.padding0);
8209
8210   pic_reg_used = false;
8211   if (pic_offset_table_rtx
8212       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
8213           || crtl->profile))
8214     {
8215       unsigned int alt_pic_reg_used = ix86_select_alt_pic_regnum ();
8216
8217       if (alt_pic_reg_used != INVALID_REGNUM)
8218         SET_REGNO (pic_offset_table_rtx, alt_pic_reg_used);
8219
8220       pic_reg_used = true;
8221     }
8222
8223   if (pic_reg_used)
8224     {
8225       if (TARGET_64BIT)
8226         {
8227           if (ix86_cmodel == CM_LARGE_PIC)
8228             {
8229               rtx tmp_reg = gen_rtx_REG (DImode, R11_REG);
8230               rtx label = gen_label_rtx ();
8231               emit_label (label);
8232               LABEL_PRESERVE_P (label) = 1;
8233               gcc_assert (REGNO (pic_offset_table_rtx) != REGNO (tmp_reg));
8234               insn = emit_insn (gen_set_rip_rex64 (pic_offset_table_rtx, label));
8235               insn = emit_insn (gen_set_got_offset_rex64 (tmp_reg, label));
8236               insn = emit_insn (gen_adddi3 (pic_offset_table_rtx,
8237                                             pic_offset_table_rtx, tmp_reg));
8238             }
8239           else
8240             insn = emit_insn (gen_set_got_rex64 (pic_offset_table_rtx));
8241         }
8242       else
8243         insn = emit_insn (gen_set_got (pic_offset_table_rtx));
8244     }
8245
8246   /* In the pic_reg_used case, make sure that the got load isn't deleted
8247      when mcount needs it.  Blockage to avoid call movement across mcount
8248      call is emitted in generic code after the NOTE_INSN_PROLOGUE_END
8249      note.  */
8250   if (crtl->profile && pic_reg_used)
8251     emit_insn (gen_prologue_use (pic_offset_table_rtx));
8252
8253   if (crtl->drap_reg && !crtl->stack_realign_needed)
8254     {
8255       /* vDRAP is setup but after reload it turns out stack realign
8256          isn't necessary, here we will emit prologue to setup DRAP
8257          without stack realign adjustment */
8258       int drap_bp_offset = UNITS_PER_WORD * 2;
8259       rtx x = plus_constant (hard_frame_pointer_rtx, drap_bp_offset);
8260       insn = emit_insn (gen_rtx_SET (VOIDmode, crtl->drap_reg, x));
8261     }
8262
8263   /* Prevent instructions from being scheduled into register save push
8264      sequence when access to the redzone area is done through frame pointer.
8265      The offset betweeh the frame pointer and the stack pointer is calculated
8266      relative to the value of the stack pointer at the end of the function
8267      prologue, and moving instructions that access redzone area via frame
8268      pointer inside push sequence violates this assumption.  */
8269   if (frame_pointer_needed && frame.red_zone_size)
8270     emit_insn (gen_memory_blockage ());
8271
8272   /* Emit cld instruction if stringops are used in the function.  */
8273   if (TARGET_CLD && ix86_current_function_needs_cld)
8274     emit_insn (gen_cld ());
8275 }
8276
8277 /* Emit code to restore saved registers using MOV insns.  First register
8278    is restored from POINTER + OFFSET.  */
8279 static void
8280 ix86_emit_restore_regs_using_mov (rtx pointer, HOST_WIDE_INT offset,
8281                                   int maybe_eh_return)
8282 {
8283   int regno;
8284   rtx base_address = gen_rtx_MEM (Pmode, pointer);
8285
8286   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8287     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return))
8288       {
8289         /* Ensure that adjust_address won't be forced to produce pointer
8290            out of range allowed by x86-64 instruction set.  */
8291         if (TARGET_64BIT && offset != trunc_int_for_mode (offset, SImode))
8292           {
8293             rtx r11;
8294
8295             r11 = gen_rtx_REG (DImode, R11_REG);
8296             emit_move_insn (r11, GEN_INT (offset));
8297             emit_insn (gen_adddi3 (r11, r11, pointer));
8298             base_address = gen_rtx_MEM (Pmode, r11);
8299             offset = 0;
8300           }
8301         emit_move_insn (gen_rtx_REG (Pmode, regno),
8302                         adjust_address (base_address, Pmode, offset));
8303         offset += UNITS_PER_WORD;
8304       }
8305 }
8306
8307 /* Emit code to restore saved registers using MOV insns.  First register
8308    is restored from POINTER + OFFSET.  */
8309 static void
8310 ix86_emit_restore_sse_regs_using_mov (rtx pointer, HOST_WIDE_INT offset,
8311                                       int maybe_eh_return)
8312 {
8313   int regno;
8314   rtx base_address = gen_rtx_MEM (TImode, pointer);
8315   rtx mem;
8316
8317   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8318     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return))
8319       {
8320         /* Ensure that adjust_address won't be forced to produce pointer
8321            out of range allowed by x86-64 instruction set.  */
8322         if (TARGET_64BIT && offset != trunc_int_for_mode (offset, SImode))
8323           {
8324             rtx r11;
8325
8326             r11 = gen_rtx_REG (DImode, R11_REG);
8327             emit_move_insn (r11, GEN_INT (offset));
8328             emit_insn (gen_adddi3 (r11, r11, pointer));
8329             base_address = gen_rtx_MEM (TImode, r11);
8330             offset = 0;
8331           }
8332         mem = adjust_address (base_address, TImode, offset);
8333         set_mem_align (mem, 128);
8334         emit_move_insn (gen_rtx_REG (TImode, regno), mem);
8335         offset += 16;
8336       }
8337 }
8338
8339 /* Restore function stack, frame, and registers.  */
8340
8341 void
8342 ix86_expand_epilogue (int style)
8343 {
8344   int regno;
8345   int sp_valid;
8346   struct ix86_frame frame;
8347   HOST_WIDE_INT offset;
8348
8349   ix86_finalize_stack_realign_flags ();
8350
8351  /* When stack is realigned, SP must be valid.  */
8352   sp_valid = (!frame_pointer_needed
8353               || current_function_sp_is_unchanging
8354               || stack_realign_fp);
8355
8356   ix86_compute_frame_layout (&frame);
8357
8358   /* See the comment about red zone and frame
8359      pointer usage in ix86_expand_prologue.  */
8360   if (frame_pointer_needed && frame.red_zone_size)
8361     emit_insn (gen_memory_blockage ()); 
8362
8363   /* Calculate start of saved registers relative to ebp.  Special care
8364      must be taken for the normal return case of a function using
8365      eh_return: the eax and edx registers are marked as saved, but not
8366      restored along this path.  */
8367   offset = frame.nregs;
8368   if (crtl->calls_eh_return && style != 2)
8369     offset -= 2;
8370   offset *= -UNITS_PER_WORD;
8371   offset -= frame.nsseregs * 16 + frame.padding0;
8372
8373   /* If we're only restoring one register and sp is not valid then
8374      using a move instruction to restore the register since it's
8375      less work than reloading sp and popping the register.
8376
8377      The default code result in stack adjustment using add/lea instruction,
8378      while this code results in LEAVE instruction (or discrete equivalent),
8379      so it is profitable in some other cases as well.  Especially when there
8380      are no registers to restore.  We also use this code when TARGET_USE_LEAVE
8381      and there is exactly one register to pop. This heuristic may need some
8382      tuning in future.  */
8383   if ((!sp_valid && (frame.nregs + frame.nsseregs) <= 1)
8384       || (TARGET_EPILOGUE_USING_MOVE
8385           && cfun->machine->use_fast_prologue_epilogue
8386           && ((frame.nregs + frame.nsseregs) > 1 || frame.to_allocate))
8387       || (frame_pointer_needed && !(frame.nregs + frame.nsseregs) && frame.to_allocate)
8388       || (frame_pointer_needed && TARGET_USE_LEAVE
8389           && cfun->machine->use_fast_prologue_epilogue
8390           && (frame.nregs + frame.nsseregs) == 1)
8391       || crtl->calls_eh_return)
8392     {
8393       /* Restore registers.  We can use ebp or esp to address the memory
8394          locations.  If both are available, default to ebp, since offsets
8395          are known to be small.  Only exception is esp pointing directly
8396          to the end of block of saved registers, where we may simplify
8397          addressing mode.  
8398
8399          If we are realigning stack with bp and sp, regs restore can't
8400          be addressed by bp. sp must be used instead.  */
8401
8402       if (!frame_pointer_needed
8403           || (sp_valid && !frame.to_allocate) 
8404           || stack_realign_fp)
8405         {
8406           ix86_emit_restore_sse_regs_using_mov (stack_pointer_rtx,
8407                                                 frame.to_allocate, style == 2);
8408           ix86_emit_restore_regs_using_mov (stack_pointer_rtx,
8409                                             frame.to_allocate
8410                                             + frame.nsseregs * 16
8411                                             + frame.padding0, style == 2);
8412         }
8413       else
8414         {
8415           ix86_emit_restore_sse_regs_using_mov (hard_frame_pointer_rtx,
8416                                                 offset, style == 2);
8417           ix86_emit_restore_regs_using_mov (hard_frame_pointer_rtx,
8418                                             offset
8419                                             + frame.nsseregs * 16
8420                                             + frame.padding0, style == 2);
8421         }
8422
8423       /* eh_return epilogues need %ecx added to the stack pointer.  */
8424       if (style == 2)
8425         {
8426           rtx tmp, sa = EH_RETURN_STACKADJ_RTX;
8427
8428           /* Stack align doesn't work with eh_return.  */
8429           gcc_assert (!crtl->stack_realign_needed);
8430
8431           if (frame_pointer_needed)
8432             {
8433               tmp = gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx, sa);
8434               tmp = plus_constant (tmp, UNITS_PER_WORD);
8435               emit_insn (gen_rtx_SET (VOIDmode, sa, tmp));
8436
8437               tmp = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
8438               emit_move_insn (hard_frame_pointer_rtx, tmp);
8439
8440               pro_epilogue_adjust_stack (stack_pointer_rtx, sa,
8441                                          const0_rtx, style);
8442             }
8443           else
8444             {
8445               tmp = gen_rtx_PLUS (Pmode, stack_pointer_rtx, sa);
8446               tmp = plus_constant (tmp, (frame.to_allocate
8447                                          + frame.nregs * UNITS_PER_WORD
8448                                          + frame.nsseregs * 16
8449                                          + frame.padding0));
8450               emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx, tmp));
8451             }
8452         }
8453       else if (!frame_pointer_needed)
8454         pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8455                                    GEN_INT (frame.to_allocate
8456                                             + frame.nregs * UNITS_PER_WORD
8457                                             + frame.nsseregs * 16
8458                                             + frame.padding0),
8459                                    style);
8460       /* If not an i386, mov & pop is faster than "leave".  */
8461       else if (TARGET_USE_LEAVE || optimize_function_for_size_p (cfun)
8462                || !cfun->machine->use_fast_prologue_epilogue)
8463         emit_insn ((*ix86_gen_leave) ());
8464       else
8465         {
8466           pro_epilogue_adjust_stack (stack_pointer_rtx,
8467                                      hard_frame_pointer_rtx,
8468                                      const0_rtx, style);
8469
8470           emit_insn ((*ix86_gen_pop1) (hard_frame_pointer_rtx));
8471         }
8472     }
8473   else
8474     {
8475       /* First step is to deallocate the stack frame so that we can
8476          pop the registers.
8477
8478          If we realign stack with frame pointer, then stack pointer
8479          won't be able to recover via lea $offset(%bp), %sp, because
8480          there is a padding area between bp and sp for realign. 
8481          "add $to_allocate, %sp" must be used instead.  */
8482       if (!sp_valid)
8483         {
8484           gcc_assert (frame_pointer_needed);
8485           gcc_assert (!stack_realign_fp);
8486           pro_epilogue_adjust_stack (stack_pointer_rtx,
8487                                      hard_frame_pointer_rtx,
8488                                      GEN_INT (offset), style);
8489           ix86_emit_restore_sse_regs_using_mov (stack_pointer_rtx,
8490                                                 frame.to_allocate, style == 2);
8491           pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8492                                      GEN_INT (frame.nsseregs * 16), style);
8493         }
8494       else if (frame.to_allocate || frame.nsseregs)
8495         {
8496           ix86_emit_restore_sse_regs_using_mov (stack_pointer_rtx,
8497                                                 frame.to_allocate,
8498                                                 style == 2);
8499           pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
8500                                      GEN_INT (frame.to_allocate
8501                                               + frame.nsseregs * 16
8502                                               + frame.padding0), style);
8503         }
8504
8505       for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
8506         if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, false))
8507           emit_insn ((*ix86_gen_pop1) (gen_rtx_REG (Pmode, regno)));
8508       if (frame_pointer_needed)
8509         {
8510           /* Leave results in shorter dependency chains on CPUs that are
8511              able to grok it fast.  */
8512           if (TARGET_USE_LEAVE)
8513             emit_insn ((*ix86_gen_leave) ());
8514           else
8515             {
8516               /* For stack realigned really happens, recover stack 
8517                  pointer to hard frame pointer is a must, if not using 
8518                  leave.  */
8519               if (stack_realign_fp)
8520                 pro_epilogue_adjust_stack (stack_pointer_rtx,
8521                                            hard_frame_pointer_rtx,
8522                                            const0_rtx, style);
8523               emit_insn ((*ix86_gen_pop1) (hard_frame_pointer_rtx));
8524             }
8525         }
8526     }
8527
8528   if (crtl->drap_reg && crtl->stack_realign_needed)
8529     {
8530       int param_ptr_offset = (call_used_regs[REGNO (crtl->drap_reg)]
8531                               ? 0 : UNITS_PER_WORD);
8532       gcc_assert (stack_realign_drap);
8533       emit_insn ((*ix86_gen_add3) (stack_pointer_rtx,
8534                                    crtl->drap_reg,
8535                                    GEN_INT (-(UNITS_PER_WORD
8536                                               + param_ptr_offset))));
8537       if (!call_used_regs[REGNO (crtl->drap_reg)])
8538         emit_insn ((*ix86_gen_pop1) (crtl->drap_reg));
8539       
8540     }
8541
8542   /* Sibcall epilogues don't want a return instruction.  */
8543   if (style == 0)
8544     return;
8545
8546   if (crtl->args.pops_args && crtl->args.size)
8547     {
8548       rtx popc = GEN_INT (crtl->args.pops_args);
8549
8550       /* i386 can only pop 64K bytes.  If asked to pop more, pop
8551          return address, do explicit add, and jump indirectly to the
8552          caller.  */
8553
8554       if (crtl->args.pops_args >= 65536)
8555         {
8556           rtx ecx = gen_rtx_REG (SImode, CX_REG);
8557
8558           /* There is no "pascal" calling convention in any 64bit ABI.  */
8559           gcc_assert (!TARGET_64BIT);
8560
8561           emit_insn (gen_popsi1 (ecx));
8562           emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, popc));
8563           emit_jump_insn (gen_return_indirect_internal (ecx));
8564         }
8565       else
8566         emit_jump_insn (gen_return_pop_internal (popc));
8567     }
8568   else
8569     emit_jump_insn (gen_return_internal ());
8570 }
8571
8572 /* Reset from the function's potential modifications.  */
8573
8574 static void
8575 ix86_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED,
8576                                HOST_WIDE_INT size ATTRIBUTE_UNUSED)
8577 {
8578   if (pic_offset_table_rtx)
8579     SET_REGNO (pic_offset_table_rtx, REAL_PIC_OFFSET_TABLE_REGNUM);
8580 #if TARGET_MACHO
8581   /* Mach-O doesn't support labels at the end of objects, so if
8582      it looks like we might want one, insert a NOP.  */
8583   {
8584     rtx insn = get_last_insn ();
8585     while (insn
8586            && NOTE_P (insn)
8587            && NOTE_KIND (insn) != NOTE_INSN_DELETED_LABEL)
8588       insn = PREV_INSN (insn);
8589     if (insn
8590         && (LABEL_P (insn)
8591             || (NOTE_P (insn)
8592                 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL)))
8593       fputs ("\tnop\n", file);
8594   }
8595 #endif
8596
8597 }
8598 \f
8599 /* Extract the parts of an RTL expression that is a valid memory address
8600    for an instruction.  Return 0 if the structure of the address is
8601    grossly off.  Return -1 if the address contains ASHIFT, so it is not
8602    strictly valid, but still used for computing length of lea instruction.  */
8603
8604 int
8605 ix86_decompose_address (rtx addr, struct ix86_address *out)
8606 {
8607   rtx base = NULL_RTX, index = NULL_RTX, disp = NULL_RTX;
8608   rtx base_reg, index_reg;
8609   HOST_WIDE_INT scale = 1;
8610   rtx scale_rtx = NULL_RTX;
8611   int retval = 1;
8612   enum ix86_address_seg seg = SEG_DEFAULT;
8613
8614   if (REG_P (addr) || GET_CODE (addr) == SUBREG)
8615     base = addr;
8616   else if (GET_CODE (addr) == PLUS)
8617     {
8618       rtx addends[4], op;
8619       int n = 0, i;
8620
8621       op = addr;
8622       do
8623         {
8624           if (n >= 4)
8625             return 0;
8626           addends[n++] = XEXP (op, 1);
8627           op = XEXP (op, 0);
8628         }
8629       while (GET_CODE (op) == PLUS);
8630       if (n >= 4)
8631         return 0;
8632       addends[n] = op;
8633
8634       for (i = n; i >= 0; --i)
8635         {
8636           op = addends[i];
8637           switch (GET_CODE (op))
8638             {
8639             case MULT:
8640               if (index)
8641                 return 0;
8642               index = XEXP (op, 0);
8643               scale_rtx = XEXP (op, 1);
8644               break;
8645
8646             case UNSPEC:
8647               if (XINT (op, 1) == UNSPEC_TP
8648                   && TARGET_TLS_DIRECT_SEG_REFS
8649                   && seg == SEG_DEFAULT)
8650                 seg = TARGET_64BIT ? SEG_FS : SEG_GS;
8651               else
8652                 return 0;
8653               break;
8654
8655             case REG:
8656             case SUBREG:
8657               if (!base)
8658                 base = op;
8659               else if (!index)
8660                 index = op;
8661               else
8662                 return 0;
8663               break;
8664
8665             case CONST:
8666             case CONST_INT:
8667             case SYMBOL_REF:
8668             case LABEL_REF:
8669               if (disp)
8670                 return 0;
8671               disp = op;
8672               break;
8673
8674             default:
8675               return 0;
8676             }
8677         }
8678     }
8679   else if (GET_CODE (addr) == MULT)
8680     {
8681       index = XEXP (addr, 0);           /* index*scale */
8682       scale_rtx = XEXP (addr, 1);
8683     }
8684   else if (GET_CODE (addr) == ASHIFT)
8685     {
8686       rtx tmp;
8687
8688       /* We're called for lea too, which implements ashift on occasion.  */
8689       index = XEXP (addr, 0);
8690       tmp = XEXP (addr, 1);
8691       if (!CONST_INT_P (tmp))
8692         return 0;
8693       scale = INTVAL (tmp);
8694       if ((unsigned HOST_WIDE_INT) scale > 3)
8695         return 0;
8696       scale = 1 << scale;
8697       retval = -1;
8698     }
8699   else
8700     disp = addr;                        /* displacement */
8701
8702   /* Extract the integral value of scale.  */
8703   if (scale_rtx)
8704     {
8705       if (!CONST_INT_P (scale_rtx))
8706         return 0;
8707       scale = INTVAL (scale_rtx);
8708     }
8709
8710   base_reg = base && GET_CODE (base) == SUBREG ? SUBREG_REG (base) : base;
8711   index_reg = index && GET_CODE (index) == SUBREG ? SUBREG_REG (index) : index;
8712
8713   /* Allow arg pointer and stack pointer as index if there is not scaling.  */
8714   if (base_reg && index_reg && scale == 1
8715       && (index_reg == arg_pointer_rtx
8716           || index_reg == frame_pointer_rtx
8717           || (REG_P (index_reg) && REGNO (index_reg) == STACK_POINTER_REGNUM)))
8718     {
8719       rtx tmp;
8720       tmp = base, base = index, index = tmp;
8721       tmp = base_reg, base_reg = index_reg, index_reg = tmp;
8722     }
8723
8724   /* Special case: %ebp cannot be encoded as a base without a displacement.  */
8725   if ((base_reg == hard_frame_pointer_rtx
8726        || base_reg == frame_pointer_rtx
8727        || base_reg == arg_pointer_rtx) && !disp)
8728     disp = const0_rtx;
8729
8730   /* Special case: on K6, [%esi] makes the instruction vector decoded.
8731      Avoid this by transforming to [%esi+0].
8732      Reload calls address legitimization without cfun defined, so we need
8733      to test cfun for being non-NULL. */
8734   if (TARGET_K6 && cfun && optimize_function_for_speed_p (cfun)
8735       && base_reg && !index_reg && !disp
8736       && REG_P (base_reg)
8737       && REGNO_REG_CLASS (REGNO (base_reg)) == SIREG)
8738     disp = const0_rtx;
8739
8740   /* Special case: encode reg+reg instead of reg*2.  */
8741   if (!base && index && scale && scale == 2)
8742     base = index, base_reg = index_reg, scale = 1;
8743
8744   /* Special case: scaling cannot be encoded without base or displacement.  */
8745   if (!base && !disp && index && scale != 1)
8746     disp = const0_rtx;
8747
8748   out->base = base;
8749   out->index = index;
8750   out->disp = disp;
8751   out->scale = scale;
8752   out->seg = seg;
8753
8754   return retval;
8755 }
8756 \f
8757 /* Return cost of the memory address x.
8758    For i386, it is better to use a complex address than let gcc copy
8759    the address into a reg and make a new pseudo.  But not if the address
8760    requires to two regs - that would mean more pseudos with longer
8761    lifetimes.  */
8762 static int
8763 ix86_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED)
8764 {
8765   struct ix86_address parts;
8766   int cost = 1;
8767   int ok = ix86_decompose_address (x, &parts);
8768
8769   gcc_assert (ok);
8770
8771   if (parts.base && GET_CODE (parts.base) == SUBREG)
8772     parts.base = SUBREG_REG (parts.base);
8773   if (parts.index && GET_CODE (parts.index) == SUBREG)
8774     parts.index = SUBREG_REG (parts.index);
8775
8776   /* Attempt to minimize number of registers in the address.  */
8777   if ((parts.base
8778        && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER))
8779       || (parts.index
8780           && (!REG_P (parts.index)
8781               || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)))
8782     cost++;
8783
8784   if (parts.base
8785       && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER)
8786       && parts.index
8787       && (!REG_P (parts.index) || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)
8788       && parts.base != parts.index)
8789     cost++;
8790
8791   /* AMD-K6 don't like addresses with ModR/M set to 00_xxx_100b,
8792      since it's predecode logic can't detect the length of instructions
8793      and it degenerates to vector decoded.  Increase cost of such
8794      addresses here.  The penalty is minimally 2 cycles.  It may be worthwhile
8795      to split such addresses or even refuse such addresses at all.
8796
8797      Following addressing modes are affected:
8798       [base+scale*index]
8799       [scale*index+disp]
8800       [base+index]
8801
8802      The first and last case  may be avoidable by explicitly coding the zero in
8803      memory address, but I don't have AMD-K6 machine handy to check this
8804      theory.  */
8805
8806   if (TARGET_K6
8807       && ((!parts.disp && parts.base && parts.index && parts.scale != 1)
8808           || (parts.disp && !parts.base && parts.index && parts.scale != 1)
8809           || (!parts.disp && parts.base && parts.index && parts.scale == 1)))
8810     cost += 10;
8811
8812   return cost;
8813 }
8814 \f
8815 /* Allow {LABEL | SYMBOL}_REF - SYMBOL_REF-FOR-PICBASE for Mach-O as
8816    this is used for to form addresses to local data when -fPIC is in
8817    use.  */
8818
8819 static bool
8820 darwin_local_data_pic (rtx disp)
8821 {
8822   return (GET_CODE (disp) == UNSPEC
8823           && XINT (disp, 1) == UNSPEC_MACHOPIC_OFFSET);
8824 }
8825
8826 /* Determine if a given RTX is a valid constant.  We already know this
8827    satisfies CONSTANT_P.  */
8828
8829 bool
8830 legitimate_constant_p (rtx x)
8831 {
8832   switch (GET_CODE (x))
8833     {
8834     case CONST:
8835       x = XEXP (x, 0);
8836
8837       if (GET_CODE (x) == PLUS)
8838         {
8839           if (!CONST_INT_P (XEXP (x, 1)))
8840             return false;
8841           x = XEXP (x, 0);
8842         }
8843
8844       if (TARGET_MACHO && darwin_local_data_pic (x))
8845         return true;
8846
8847       /* Only some unspecs are valid as "constants".  */
8848       if (GET_CODE (x) == UNSPEC)
8849         switch (XINT (x, 1))
8850           {
8851           case UNSPEC_GOT:
8852           case UNSPEC_GOTOFF:
8853           case UNSPEC_PLTOFF:
8854             return TARGET_64BIT;
8855           case UNSPEC_TPOFF:
8856           case UNSPEC_NTPOFF:
8857             x = XVECEXP (x, 0, 0);
8858             return (GET_CODE (x) == SYMBOL_REF
8859                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
8860           case UNSPEC_DTPOFF:
8861             x = XVECEXP (x, 0, 0);
8862             return (GET_CODE (x) == SYMBOL_REF
8863                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC);
8864           default:
8865             return false;
8866           }
8867
8868       /* We must have drilled down to a symbol.  */
8869       if (GET_CODE (x) == LABEL_REF)
8870         return true;
8871       if (GET_CODE (x) != SYMBOL_REF)
8872         return false;
8873       /* FALLTHRU */
8874
8875     case SYMBOL_REF:
8876       /* TLS symbols are never valid.  */
8877       if (SYMBOL_REF_TLS_MODEL (x))
8878         return false;
8879
8880       /* DLLIMPORT symbols are never valid.  */
8881       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
8882           && SYMBOL_REF_DLLIMPORT_P (x))
8883         return false;
8884       break;
8885
8886     case CONST_DOUBLE:
8887       if (GET_MODE (x) == TImode
8888           && x != CONST0_RTX (TImode)
8889           && !TARGET_64BIT)
8890         return false;
8891       break;
8892
8893     case CONST_VECTOR:
8894       if (x == CONST0_RTX (GET_MODE (x)))
8895         return true;
8896       return false;
8897
8898     default:
8899       break;
8900     }
8901
8902   /* Otherwise we handle everything else in the move patterns.  */
8903   return true;
8904 }
8905
8906 /* Determine if it's legal to put X into the constant pool.  This
8907    is not possible for the address of thread-local symbols, which
8908    is checked above.  */
8909
8910 static bool
8911 ix86_cannot_force_const_mem (rtx x)
8912 {
8913   /* We can always put integral constants and vectors in memory.  */
8914   switch (GET_CODE (x))
8915     {
8916     case CONST_INT:
8917     case CONST_DOUBLE:
8918     case CONST_VECTOR:
8919       return false;
8920
8921     default:
8922       break;
8923     }
8924   return !legitimate_constant_p (x);
8925 }
8926
8927 /* Determine if a given RTX is a valid constant address.  */
8928
8929 bool
8930 constant_address_p (rtx x)
8931 {
8932   return CONSTANT_P (x) && legitimate_address_p (Pmode, x, 1);
8933 }
8934
8935 /* Nonzero if the constant value X is a legitimate general operand
8936    when generating PIC code.  It is given that flag_pic is on and
8937    that X satisfies CONSTANT_P or is a CONST_DOUBLE.  */
8938
8939 bool
8940 legitimate_pic_operand_p (rtx x)
8941 {
8942   rtx inner;
8943
8944   switch (GET_CODE (x))
8945     {
8946     case CONST:
8947       inner = XEXP (x, 0);
8948       if (GET_CODE (inner) == PLUS
8949           && CONST_INT_P (XEXP (inner, 1)))
8950         inner = XEXP (inner, 0);
8951
8952       /* Only some unspecs are valid as "constants".  */
8953       if (GET_CODE (inner) == UNSPEC)
8954         switch (XINT (inner, 1))
8955           {
8956           case UNSPEC_GOT:
8957           case UNSPEC_GOTOFF:
8958           case UNSPEC_PLTOFF:
8959             return TARGET_64BIT;
8960           case UNSPEC_TPOFF:
8961             x = XVECEXP (inner, 0, 0);
8962             return (GET_CODE (x) == SYMBOL_REF
8963                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
8964           case UNSPEC_MACHOPIC_OFFSET:
8965             return legitimate_pic_address_disp_p (x);
8966           default:
8967             return false;
8968           }
8969       /* FALLTHRU */
8970
8971     case SYMBOL_REF:
8972     case LABEL_REF:
8973       return legitimate_pic_address_disp_p (x);
8974
8975     default:
8976       return true;
8977     }
8978 }
8979
8980 /* Determine if a given CONST RTX is a valid memory displacement
8981    in PIC mode.  */
8982
8983 int
8984 legitimate_pic_address_disp_p (rtx disp)
8985 {
8986   bool saw_plus;
8987
8988   /* In 64bit mode we can allow direct addresses of symbols and labels
8989      when they are not dynamic symbols.  */
8990   if (TARGET_64BIT)
8991     {
8992       rtx op0 = disp, op1;
8993
8994       switch (GET_CODE (disp))
8995         {
8996         case LABEL_REF:
8997           return true;
8998
8999         case CONST:
9000           if (GET_CODE (XEXP (disp, 0)) != PLUS)
9001             break;
9002           op0 = XEXP (XEXP (disp, 0), 0);
9003           op1 = XEXP (XEXP (disp, 0), 1);
9004           if (!CONST_INT_P (op1)
9005               || INTVAL (op1) >= 16*1024*1024
9006               || INTVAL (op1) < -16*1024*1024)
9007             break;
9008           if (GET_CODE (op0) == LABEL_REF)
9009             return true;
9010           if (GET_CODE (op0) != SYMBOL_REF)
9011             break;
9012           /* FALLTHRU */
9013
9014         case SYMBOL_REF:
9015           /* TLS references should always be enclosed in UNSPEC.  */
9016           if (SYMBOL_REF_TLS_MODEL (op0))
9017             return false;
9018           if (!SYMBOL_REF_FAR_ADDR_P (op0) && SYMBOL_REF_LOCAL_P (op0)
9019               && ix86_cmodel != CM_LARGE_PIC)
9020             return true;
9021           break;
9022
9023         default:
9024           break;
9025         }
9026     }
9027   if (GET_CODE (disp) != CONST)
9028     return 0;
9029   disp = XEXP (disp, 0);
9030
9031   if (TARGET_64BIT)
9032     {
9033       /* We are unsafe to allow PLUS expressions.  This limit allowed distance
9034          of GOT tables.  We should not need these anyway.  */
9035       if (GET_CODE (disp) != UNSPEC
9036           || (XINT (disp, 1) != UNSPEC_GOTPCREL
9037               && XINT (disp, 1) != UNSPEC_GOTOFF
9038               && XINT (disp, 1) != UNSPEC_PLTOFF))
9039         return 0;
9040
9041       if (GET_CODE (XVECEXP (disp, 0, 0)) != SYMBOL_REF
9042           && GET_CODE (XVECEXP (disp, 0, 0)) != LABEL_REF)
9043         return 0;
9044       return 1;
9045     }
9046
9047   saw_plus = false;
9048   if (GET_CODE (disp) == PLUS)
9049     {
9050       if (!CONST_INT_P (XEXP (disp, 1)))
9051         return 0;
9052       disp = XEXP (disp, 0);
9053       saw_plus = true;
9054     }
9055
9056   if (TARGET_MACHO && darwin_local_data_pic (disp))
9057     return 1;
9058
9059   if (GET_CODE (disp) != UNSPEC)
9060     return 0;
9061
9062   switch (XINT (disp, 1))
9063     {
9064     case UNSPEC_GOT:
9065       if (saw_plus)
9066         return false;
9067       /* We need to check for both symbols and labels because VxWorks loads
9068          text labels with @GOT rather than @GOTOFF.  See gotoff_operand for
9069          details.  */
9070       return (GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
9071               || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF);
9072     case UNSPEC_GOTOFF:
9073       /* Refuse GOTOFF in 64bit mode since it is always 64bit when used.
9074          While ABI specify also 32bit relocation but we don't produce it in
9075          small PIC model at all.  */
9076       if ((GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
9077            || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF)
9078           && !TARGET_64BIT)
9079         return gotoff_operand (XVECEXP (disp, 0, 0), Pmode);
9080       return false;
9081     case UNSPEC_GOTTPOFF:
9082     case UNSPEC_GOTNTPOFF:
9083     case UNSPEC_INDNTPOFF:
9084       if (saw_plus)
9085         return false;
9086       disp = XVECEXP (disp, 0, 0);
9087       return (GET_CODE (disp) == SYMBOL_REF
9088               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_INITIAL_EXEC);
9089     case UNSPEC_NTPOFF:
9090       disp = XVECEXP (disp, 0, 0);
9091       return (GET_CODE (disp) == SYMBOL_REF
9092               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_EXEC);
9093     case UNSPEC_DTPOFF:
9094       disp = XVECEXP (disp, 0, 0);
9095       return (GET_CODE (disp) == SYMBOL_REF
9096               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_DYNAMIC);
9097     }
9098
9099   return 0;
9100 }
9101
9102 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression that is a valid
9103    memory address for an instruction.  The MODE argument is the machine mode
9104    for the MEM expression that wants to use this address.
9105
9106    It only recognizes address in canonical form.  LEGITIMIZE_ADDRESS should
9107    convert common non-canonical forms to canonical form so that they will
9108    be recognized.  */
9109
9110 int
9111 legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
9112                       rtx addr, int strict)
9113 {
9114   struct ix86_address parts;
9115   rtx base, index, disp;
9116   HOST_WIDE_INT scale;
9117   const char *reason = NULL;
9118   rtx reason_rtx = NULL_RTX;
9119
9120   if (ix86_decompose_address (addr, &parts) <= 0)
9121     {
9122       reason = "decomposition failed";
9123       goto report_error;
9124     }
9125
9126   base = parts.base;
9127   index = parts.index;
9128   disp = parts.disp;
9129   scale = parts.scale;
9130
9131   /* Validate base register.
9132
9133      Don't allow SUBREG's that span more than a word here.  It can lead to spill
9134      failures when the base is one word out of a two word structure, which is
9135      represented internally as a DImode int.  */
9136
9137   if (base)
9138     {
9139       rtx reg;
9140       reason_rtx = base;
9141
9142       if (REG_P (base))
9143         reg = base;
9144       else if (GET_CODE (base) == SUBREG
9145                && REG_P (SUBREG_REG (base))
9146                && GET_MODE_SIZE (GET_MODE (SUBREG_REG (base)))
9147                   <= UNITS_PER_WORD)
9148         reg = SUBREG_REG (base);
9149       else
9150         {
9151           reason = "base is not a register";
9152           goto report_error;
9153         }
9154
9155       if (GET_MODE (base) != Pmode)
9156         {
9157           reason = "base is not in Pmode";
9158           goto report_error;
9159         }
9160
9161       if ((strict && ! REG_OK_FOR_BASE_STRICT_P (reg))
9162           || (! strict && ! REG_OK_FOR_BASE_NONSTRICT_P (reg)))
9163         {
9164           reason = "base is not valid";
9165           goto report_error;
9166         }
9167     }
9168
9169   /* Validate index register.
9170
9171      Don't allow SUBREG's that span more than a word here -- same as above.  */
9172
9173   if (index)
9174     {
9175       rtx reg;
9176       reason_rtx = index;
9177
9178       if (REG_P (index))
9179         reg = index;
9180       else if (GET_CODE (index) == SUBREG
9181                && REG_P (SUBREG_REG (index))
9182                && GET_MODE_SIZE (GET_MODE (SUBREG_REG (index)))
9183                   <= UNITS_PER_WORD)
9184         reg = SUBREG_REG (index);
9185       else
9186         {
9187           reason = "index is not a register";
9188           goto report_error;
9189         }
9190
9191       if (GET_MODE (index) != Pmode)
9192         {
9193           reason = "index is not in Pmode";
9194           goto report_error;
9195         }
9196
9197       if ((strict && ! REG_OK_FOR_INDEX_STRICT_P (reg))
9198           || (! strict && ! REG_OK_FOR_INDEX_NONSTRICT_P (reg)))
9199         {
9200           reason = "index is not valid";
9201           goto report_error;
9202         }
9203     }
9204
9205   /* Validate scale factor.  */
9206   if (scale != 1)
9207     {
9208       reason_rtx = GEN_INT (scale);
9209       if (!index)
9210         {
9211           reason = "scale without index";
9212           goto report_error;
9213         }
9214
9215       if (scale != 2 && scale != 4 && scale != 8)
9216         {
9217           reason = "scale is not a valid multiplier";
9218           goto report_error;
9219         }
9220     }
9221
9222   /* Validate displacement.  */
9223   if (disp)
9224     {
9225       reason_rtx = disp;
9226
9227       if (GET_CODE (disp) == CONST
9228           && GET_CODE (XEXP (disp, 0)) == UNSPEC
9229           && XINT (XEXP (disp, 0), 1) != UNSPEC_MACHOPIC_OFFSET)
9230         switch (XINT (XEXP (disp, 0), 1))
9231           {
9232           /* Refuse GOTOFF and GOT in 64bit mode since it is always 64bit when
9233              used.  While ABI specify also 32bit relocations, we don't produce
9234              them at all and use IP relative instead.  */
9235           case UNSPEC_GOT:
9236           case UNSPEC_GOTOFF:
9237             gcc_assert (flag_pic);
9238             if (!TARGET_64BIT)
9239               goto is_legitimate_pic;
9240             reason = "64bit address unspec";
9241             goto report_error;
9242
9243           case UNSPEC_GOTPCREL:
9244             gcc_assert (flag_pic);
9245             goto is_legitimate_pic;
9246
9247           case UNSPEC_GOTTPOFF:
9248           case UNSPEC_GOTNTPOFF:
9249           case UNSPEC_INDNTPOFF:
9250           case UNSPEC_NTPOFF:
9251           case UNSPEC_DTPOFF:
9252             break;
9253
9254           default:
9255             reason = "invalid address unspec";
9256             goto report_error;
9257           }
9258
9259       else if (SYMBOLIC_CONST (disp)
9260                && (flag_pic
9261                    || (TARGET_MACHO
9262 #if TARGET_MACHO
9263                        && MACHOPIC_INDIRECT
9264                        && !machopic_operand_p (disp)
9265 #endif
9266                )))
9267         {
9268
9269         is_legitimate_pic:
9270           if (TARGET_64BIT && (index || base))
9271             {
9272               /* foo@dtpoff(%rX) is ok.  */
9273               if (GET_CODE (disp) != CONST
9274                   || GET_CODE (XEXP (disp, 0)) != PLUS
9275                   || GET_CODE (XEXP (XEXP (disp, 0), 0)) != UNSPEC
9276                   || !CONST_INT_P (XEXP (XEXP (disp, 0), 1))
9277                   || (XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_DTPOFF
9278                       && XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_NTPOFF))
9279                 {
9280                   reason = "non-constant pic memory reference";
9281                   goto report_error;
9282                 }
9283             }
9284           else if (! legitimate_pic_address_disp_p (disp))
9285             {
9286               reason = "displacement is an invalid pic construct";
9287               goto report_error;
9288             }
9289
9290           /* This code used to verify that a symbolic pic displacement
9291              includes the pic_offset_table_rtx register.
9292
9293              While this is good idea, unfortunately these constructs may
9294              be created by "adds using lea" optimization for incorrect
9295              code like:
9296
9297              int a;
9298              int foo(int i)
9299                {
9300                  return *(&a+i);
9301                }
9302
9303              This code is nonsensical, but results in addressing
9304              GOT table with pic_offset_table_rtx base.  We can't
9305              just refuse it easily, since it gets matched by
9306              "addsi3" pattern, that later gets split to lea in the
9307              case output register differs from input.  While this
9308              can be handled by separate addsi pattern for this case
9309              that never results in lea, this seems to be easier and
9310              correct fix for crash to disable this test.  */
9311         }
9312       else if (GET_CODE (disp) != LABEL_REF
9313                && !CONST_INT_P (disp)
9314                && (GET_CODE (disp) != CONST
9315                    || !legitimate_constant_p (disp))
9316                && (GET_CODE (disp) != SYMBOL_REF
9317                    || !legitimate_constant_p (disp)))
9318         {
9319           reason = "displacement is not constant";
9320           goto report_error;
9321         }
9322       else if (TARGET_64BIT
9323                && !x86_64_immediate_operand (disp, VOIDmode))
9324         {
9325           reason = "displacement is out of range";
9326           goto report_error;
9327         }
9328     }
9329
9330   /* Everything looks valid.  */
9331   return TRUE;
9332
9333  report_error:
9334   return FALSE;
9335 }
9336 \f
9337 /* Return a unique alias set for the GOT.  */
9338
9339 static alias_set_type
9340 ix86_GOT_alias_set (void)
9341 {
9342   static alias_set_type set = -1;
9343   if (set == -1)
9344     set = new_alias_set ();
9345   return set;
9346 }
9347
9348 /* Return a legitimate reference for ORIG (an address) using the
9349    register REG.  If REG is 0, a new pseudo is generated.
9350
9351    There are two types of references that must be handled:
9352
9353    1. Global data references must load the address from the GOT, via
9354       the PIC reg.  An insn is emitted to do this load, and the reg is
9355       returned.
9356
9357    2. Static data references, constant pool addresses, and code labels
9358       compute the address as an offset from the GOT, whose base is in
9359       the PIC reg.  Static data objects have SYMBOL_FLAG_LOCAL set to
9360       differentiate them from global data objects.  The returned
9361       address is the PIC reg + an unspec constant.
9362
9363    GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
9364    reg also appears in the address.  */
9365
9366 static rtx
9367 legitimize_pic_address (rtx orig, rtx reg)
9368 {
9369   rtx addr = orig;
9370   rtx new_rtx = orig;
9371   rtx base;
9372
9373 #if TARGET_MACHO
9374   if (TARGET_MACHO && !TARGET_64BIT)
9375     {
9376       if (reg == 0)
9377         reg = gen_reg_rtx (Pmode);
9378       /* Use the generic Mach-O PIC machinery.  */
9379       return machopic_legitimize_pic_address (orig, GET_MODE (orig), reg);
9380     }
9381 #endif
9382
9383   if (TARGET_64BIT && legitimate_pic_address_disp_p (addr))
9384     new_rtx = addr;
9385   else if (TARGET_64BIT
9386            && ix86_cmodel != CM_SMALL_PIC
9387            && gotoff_operand (addr, Pmode))
9388     {
9389       rtx tmpreg;
9390       /* This symbol may be referenced via a displacement from the PIC
9391          base address (@GOTOFF).  */
9392
9393       if (reload_in_progress)
9394         df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9395       if (GET_CODE (addr) == CONST)
9396         addr = XEXP (addr, 0);
9397       if (GET_CODE (addr) == PLUS)
9398           {
9399             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
9400                                       UNSPEC_GOTOFF);
9401             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
9402           }
9403         else
9404           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
9405       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9406       if (!reg)
9407         tmpreg = gen_reg_rtx (Pmode);
9408       else
9409         tmpreg = reg;
9410       emit_move_insn (tmpreg, new_rtx);
9411
9412       if (reg != 0)
9413         {
9414           new_rtx = expand_simple_binop (Pmode, PLUS, reg, pic_offset_table_rtx,
9415                                          tmpreg, 1, OPTAB_DIRECT);
9416           new_rtx = reg;
9417         }
9418       else new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, tmpreg);
9419     }
9420   else if (!TARGET_64BIT && gotoff_operand (addr, Pmode))
9421     {
9422       /* This symbol may be referenced via a displacement from the PIC
9423          base address (@GOTOFF).  */
9424
9425       if (reload_in_progress)
9426         df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9427       if (GET_CODE (addr) == CONST)
9428         addr = XEXP (addr, 0);
9429       if (GET_CODE (addr) == PLUS)
9430           {
9431             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
9432                                       UNSPEC_GOTOFF);
9433             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
9434           }
9435         else
9436           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
9437       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9438       new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
9439
9440       if (reg != 0)
9441         {
9442           emit_move_insn (reg, new_rtx);
9443           new_rtx = reg;
9444         }
9445     }
9446   else if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (addr) == 0)
9447            /* We can't use @GOTOFF for text labels on VxWorks;
9448               see gotoff_operand.  */
9449            || (TARGET_VXWORKS_RTP && GET_CODE (addr) == LABEL_REF))
9450     {
9451       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
9452         {
9453           if (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (addr))
9454             return legitimize_dllimport_symbol (addr, true);
9455           if (GET_CODE (addr) == CONST && GET_CODE (XEXP (addr, 0)) == PLUS
9456               && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF
9457               && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (addr, 0), 0)))
9458             {
9459               rtx t = legitimize_dllimport_symbol (XEXP (XEXP (addr, 0), 0), true);
9460               return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1));
9461             }
9462         }
9463
9464       if (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC)
9465         {
9466           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTPCREL);
9467           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9468           new_rtx = gen_const_mem (Pmode, new_rtx);
9469           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
9470
9471           if (reg == 0)
9472             reg = gen_reg_rtx (Pmode);
9473           /* Use directly gen_movsi, otherwise the address is loaded
9474              into register for CSE.  We don't want to CSE this addresses,
9475              instead we CSE addresses from the GOT table, so skip this.  */
9476           emit_insn (gen_movsi (reg, new_rtx));
9477           new_rtx = reg;
9478         }
9479       else
9480         {
9481           /* This symbol must be referenced via a load from the
9482              Global Offset Table (@GOT).  */
9483
9484           if (reload_in_progress)
9485             df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9486           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT);
9487           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9488           if (TARGET_64BIT)
9489             new_rtx = force_reg (Pmode, new_rtx);
9490           new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
9491           new_rtx = gen_const_mem (Pmode, new_rtx);
9492           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
9493
9494           if (reg == 0)
9495             reg = gen_reg_rtx (Pmode);
9496           emit_move_insn (reg, new_rtx);
9497           new_rtx = reg;
9498         }
9499     }
9500   else
9501     {
9502       if (CONST_INT_P (addr)
9503           && !x86_64_immediate_operand (addr, VOIDmode))
9504         {
9505           if (reg)
9506             {
9507               emit_move_insn (reg, addr);
9508               new_rtx = reg;
9509             }
9510           else
9511             new_rtx = force_reg (Pmode, addr);
9512         }
9513       else if (GET_CODE (addr) == CONST)
9514         {
9515           addr = XEXP (addr, 0);
9516
9517           /* We must match stuff we generate before.  Assume the only
9518              unspecs that can get here are ours.  Not that we could do
9519              anything with them anyway....  */
9520           if (GET_CODE (addr) == UNSPEC
9521               || (GET_CODE (addr) == PLUS
9522                   && GET_CODE (XEXP (addr, 0)) == UNSPEC))
9523             return orig;
9524           gcc_assert (GET_CODE (addr) == PLUS);
9525         }
9526       if (GET_CODE (addr) == PLUS)
9527         {
9528           rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1);
9529
9530           /* Check first to see if this is a constant offset from a @GOTOFF
9531              symbol reference.  */
9532           if (gotoff_operand (op0, Pmode)
9533               && CONST_INT_P (op1))
9534             {
9535               if (!TARGET_64BIT)
9536                 {
9537                   if (reload_in_progress)
9538                     df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9539                   new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op0),
9540                                             UNSPEC_GOTOFF);
9541                   new_rtx = gen_rtx_PLUS (Pmode, new_rtx, op1);
9542                   new_rtx = gen_rtx_CONST (Pmode, new_rtx);
9543                   new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
9544
9545                   if (reg != 0)
9546                     {
9547                       emit_move_insn (reg, new_rtx);
9548                       new_rtx = reg;
9549                     }
9550                 }
9551               else
9552                 {
9553                   if (INTVAL (op1) < -16*1024*1024
9554                       || INTVAL (op1) >= 16*1024*1024)
9555                     {
9556                       if (!x86_64_immediate_operand (op1, Pmode))
9557                         op1 = force_reg (Pmode, op1);
9558                       new_rtx = gen_rtx_PLUS (Pmode, force_reg (Pmode, op0), op1);
9559                     }
9560                 }
9561             }
9562           else
9563             {
9564               base = legitimize_pic_address (XEXP (addr, 0), reg);
9565               new_rtx  = legitimize_pic_address (XEXP (addr, 1),
9566                                                  base == reg ? NULL_RTX : reg);
9567
9568               if (CONST_INT_P (new_rtx))
9569                 new_rtx = plus_constant (base, INTVAL (new_rtx));
9570               else
9571                 {
9572                   if (GET_CODE (new_rtx) == PLUS && CONSTANT_P (XEXP (new_rtx, 1)))
9573                     {
9574                       base = gen_rtx_PLUS (Pmode, base, XEXP (new_rtx, 0));
9575                       new_rtx = XEXP (new_rtx, 1);
9576                     }
9577                   new_rtx = gen_rtx_PLUS (Pmode, base, new_rtx);
9578                 }
9579             }
9580         }
9581     }
9582   return new_rtx;
9583 }
9584 \f
9585 /* Load the thread pointer.  If TO_REG is true, force it into a register.  */
9586
9587 static rtx
9588 get_thread_pointer (int to_reg)
9589 {
9590   rtx tp, reg, insn;
9591
9592   tp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), UNSPEC_TP);
9593   if (!to_reg)
9594     return tp;
9595
9596   reg = gen_reg_rtx (Pmode);
9597   insn = gen_rtx_SET (VOIDmode, reg, tp);
9598   insn = emit_insn (insn);
9599
9600   return reg;
9601 }
9602
9603 /* A subroutine of legitimize_address and ix86_expand_move.  FOR_MOV is
9604    false if we expect this to be used for a memory address and true if
9605    we expect to load the address into a register.  */
9606
9607 static rtx
9608 legitimize_tls_address (rtx x, enum tls_model model, int for_mov)
9609 {
9610   rtx dest, base, off, pic, tp;
9611   int type;
9612
9613   switch (model)
9614     {
9615     case TLS_MODEL_GLOBAL_DYNAMIC:
9616       dest = gen_reg_rtx (Pmode);
9617       tp = TARGET_GNU2_TLS ? get_thread_pointer (1) : 0;
9618
9619       if (TARGET_64BIT && ! TARGET_GNU2_TLS)
9620         {
9621           rtx rax = gen_rtx_REG (Pmode, AX_REG), insns;
9622
9623           start_sequence ();
9624           emit_call_insn (gen_tls_global_dynamic_64 (rax, x));
9625           insns = get_insns ();
9626           end_sequence ();
9627
9628           RTL_CONST_CALL_P (insns) = 1;
9629           emit_libcall_block (insns, dest, rax, x);
9630         }
9631       else if (TARGET_64BIT && TARGET_GNU2_TLS)
9632         emit_insn (gen_tls_global_dynamic_64 (dest, x));
9633       else
9634         emit_insn (gen_tls_global_dynamic_32 (dest, x));
9635
9636       if (TARGET_GNU2_TLS)
9637         {
9638           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, tp, dest));
9639
9640           set_unique_reg_note (get_last_insn (), REG_EQUIV, x);
9641         }
9642       break;
9643
9644     case TLS_MODEL_LOCAL_DYNAMIC:
9645       base = gen_reg_rtx (Pmode);
9646       tp = TARGET_GNU2_TLS ? get_thread_pointer (1) : 0;
9647
9648       if (TARGET_64BIT && ! TARGET_GNU2_TLS)
9649         {
9650           rtx rax = gen_rtx_REG (Pmode, AX_REG), insns, note;
9651
9652           start_sequence ();
9653           emit_call_insn (gen_tls_local_dynamic_base_64 (rax));
9654           insns = get_insns ();
9655           end_sequence ();
9656
9657           note = gen_rtx_EXPR_LIST (VOIDmode, const0_rtx, NULL);
9658           note = gen_rtx_EXPR_LIST (VOIDmode, ix86_tls_get_addr (), note);
9659           RTL_CONST_CALL_P (insns) = 1;
9660           emit_libcall_block (insns, base, rax, note);
9661         }
9662       else if (TARGET_64BIT && TARGET_GNU2_TLS)
9663         emit_insn (gen_tls_local_dynamic_base_64 (base));
9664       else
9665         emit_insn (gen_tls_local_dynamic_base_32 (base));
9666
9667       if (TARGET_GNU2_TLS)
9668         {
9669           rtx x = ix86_tls_module_base ();
9670
9671           set_unique_reg_note (get_last_insn (), REG_EQUIV,
9672                                gen_rtx_MINUS (Pmode, x, tp));
9673         }
9674
9675       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPOFF);
9676       off = gen_rtx_CONST (Pmode, off);
9677
9678       dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, off));
9679
9680       if (TARGET_GNU2_TLS)
9681         {
9682           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, dest, tp));
9683
9684           set_unique_reg_note (get_last_insn (), REG_EQUIV, x);
9685         }
9686
9687       break;
9688
9689     case TLS_MODEL_INITIAL_EXEC:
9690       if (TARGET_64BIT)
9691         {
9692           pic = NULL;
9693           type = UNSPEC_GOTNTPOFF;
9694         }
9695       else if (flag_pic)
9696         {
9697           if (reload_in_progress)
9698             df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
9699           pic = pic_offset_table_rtx;
9700           type = TARGET_ANY_GNU_TLS ? UNSPEC_GOTNTPOFF : UNSPEC_GOTTPOFF;
9701         }
9702       else if (!TARGET_ANY_GNU_TLS)
9703         {
9704           pic = gen_reg_rtx (Pmode);
9705           emit_insn (gen_set_got (pic));
9706           type = UNSPEC_GOTTPOFF;
9707         }
9708       else
9709         {
9710           pic = NULL;
9711           type = UNSPEC_INDNTPOFF;
9712         }
9713
9714       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), type);
9715       off = gen_rtx_CONST (Pmode, off);
9716       if (pic)
9717         off = gen_rtx_PLUS (Pmode, pic, off);
9718       off = gen_const_mem (Pmode, off);
9719       set_mem_alias_set (off, ix86_GOT_alias_set ());
9720
9721       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
9722         {
9723           base = get_thread_pointer (for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
9724           off = force_reg (Pmode, off);
9725           return gen_rtx_PLUS (Pmode, base, off);
9726         }
9727       else
9728         {
9729           base = get_thread_pointer (true);
9730           dest = gen_reg_rtx (Pmode);
9731           emit_insn (gen_subsi3 (dest, base, off));
9732         }
9733       break;
9734
9735     case TLS_MODEL_LOCAL_EXEC:
9736       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x),
9737                             (TARGET_64BIT || TARGET_ANY_GNU_TLS)
9738                             ? UNSPEC_NTPOFF : UNSPEC_TPOFF);
9739       off = gen_rtx_CONST (Pmode, off);
9740
9741       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
9742         {
9743           base = get_thread_pointer (for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
9744           return gen_rtx_PLUS (Pmode, base, off);
9745         }
9746       else
9747         {
9748           base = get_thread_pointer (true);
9749           dest = gen_reg_rtx (Pmode);
9750           emit_insn (gen_subsi3 (dest, base, off));
9751         }
9752       break;
9753
9754     default:
9755       gcc_unreachable ();
9756     }
9757
9758   return dest;
9759 }
9760
9761 /* Create or return the unique __imp_DECL dllimport symbol corresponding
9762    to symbol DECL.  */
9763
9764 static GTY((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
9765   htab_t dllimport_map;
9766
9767 static tree
9768 get_dllimport_decl (tree decl)
9769 {
9770   struct tree_map *h, in;
9771   void **loc;
9772   const char *name;
9773   const char *prefix;
9774   size_t namelen, prefixlen;
9775   char *imp_name;
9776   tree to;
9777   rtx rtl;
9778
9779   if (!dllimport_map)
9780     dllimport_map = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
9781
9782   in.hash = htab_hash_pointer (decl);
9783   in.base.from = decl;
9784   loc = htab_find_slot_with_hash (dllimport_map, &in, in.hash, INSERT);
9785   h = (struct tree_map *) *loc;
9786   if (h)
9787     return h->to;
9788
9789   *loc = h = GGC_NEW (struct tree_map);
9790   h->hash = in.hash;
9791   h->base.from = decl;
9792   h->to = to = build_decl (VAR_DECL, NULL, ptr_type_node);
9793   DECL_ARTIFICIAL (to) = 1;
9794   DECL_IGNORED_P (to) = 1;
9795   DECL_EXTERNAL (to) = 1;
9796   TREE_READONLY (to) = 1;
9797
9798   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
9799   name = targetm.strip_name_encoding (name);
9800   prefix = name[0] == FASTCALL_PREFIX || user_label_prefix[0] == 0
9801     ? "*__imp_" : "*__imp__";
9802   namelen = strlen (name);
9803   prefixlen = strlen (prefix);
9804   imp_name = (char *) alloca (namelen + prefixlen + 1);
9805   memcpy (imp_name, prefix, prefixlen);
9806   memcpy (imp_name + prefixlen, name, namelen + 1);
9807
9808   name = ggc_alloc_string (imp_name, namelen + prefixlen);
9809   rtl = gen_rtx_SYMBOL_REF (Pmode, name);
9810   SET_SYMBOL_REF_DECL (rtl, to);
9811   SYMBOL_REF_FLAGS (rtl) = SYMBOL_FLAG_LOCAL;
9812
9813   rtl = gen_const_mem (Pmode, rtl);
9814   set_mem_alias_set (rtl, ix86_GOT_alias_set ());
9815
9816   SET_DECL_RTL (to, rtl);
9817   SET_DECL_ASSEMBLER_NAME (to, get_identifier (name));
9818
9819   return to;
9820 }
9821
9822 /* Expand SYMBOL into its corresponding dllimport symbol.  WANT_REG is
9823    true if we require the result be a register.  */
9824
9825 static rtx
9826 legitimize_dllimport_symbol (rtx symbol, bool want_reg)
9827 {
9828   tree imp_decl;
9829   rtx x;
9830
9831   gcc_assert (SYMBOL_REF_DECL (symbol));
9832   imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol));
9833
9834   x = DECL_RTL (imp_decl);
9835   if (want_reg)
9836     x = force_reg (Pmode, x);
9837   return x;
9838 }
9839
9840 /* Try machine-dependent ways of modifying an illegitimate address
9841    to be legitimate.  If we find one, return the new, valid address.
9842    This macro is used in only one place: `memory_address' in explow.c.
9843
9844    OLDX is the address as it was before break_out_memory_refs was called.
9845    In some cases it is useful to look at this to decide what needs to be done.
9846
9847    MODE and WIN are passed so that this macro can use
9848    GO_IF_LEGITIMATE_ADDRESS.
9849
9850    It is always safe for this macro to do nothing.  It exists to recognize
9851    opportunities to optimize the output.
9852
9853    For the 80386, we handle X+REG by loading X into a register R and
9854    using R+REG.  R will go in a general reg and indexing will be used.
9855    However, if REG is a broken-out memory address or multiplication,
9856    nothing needs to be done because REG can certainly go in a general reg.
9857
9858    When -fpic is used, special handling is needed for symbolic references.
9859    See comments by legitimize_pic_address in i386.c for details.  */
9860
9861 rtx
9862 legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, enum machine_mode mode)
9863 {
9864   int changed = 0;
9865   unsigned log;
9866
9867   log = GET_CODE (x) == SYMBOL_REF ? SYMBOL_REF_TLS_MODEL (x) : 0;
9868   if (log)
9869     return legitimize_tls_address (x, (enum tls_model) log, false);
9870   if (GET_CODE (x) == CONST
9871       && GET_CODE (XEXP (x, 0)) == PLUS
9872       && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
9873       && (log = SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0))))
9874     {
9875       rtx t = legitimize_tls_address (XEXP (XEXP (x, 0), 0),
9876                                       (enum tls_model) log, false);
9877       return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
9878     }
9879
9880   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
9881     {
9882       if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (x))
9883         return legitimize_dllimport_symbol (x, true);
9884       if (GET_CODE (x) == CONST
9885           && GET_CODE (XEXP (x, 0)) == PLUS
9886           && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
9887           && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (x, 0), 0)))
9888         {
9889           rtx t = legitimize_dllimport_symbol (XEXP (XEXP (x, 0), 0), true);
9890           return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
9891         }
9892     }
9893
9894   if (flag_pic && SYMBOLIC_CONST (x))
9895     return legitimize_pic_address (x, 0);
9896
9897   /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
9898   if (GET_CODE (x) == ASHIFT
9899       && CONST_INT_P (XEXP (x, 1))
9900       && (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) < 4)
9901     {
9902       changed = 1;
9903       log = INTVAL (XEXP (x, 1));
9904       x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)),
9905                         GEN_INT (1 << log));
9906     }
9907
9908   if (GET_CODE (x) == PLUS)
9909     {
9910       /* Canonicalize shifts by 0, 1, 2, 3 into multiply.  */
9911
9912       if (GET_CODE (XEXP (x, 0)) == ASHIFT
9913           && CONST_INT_P (XEXP (XEXP (x, 0), 1))
9914           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 0), 1)) < 4)
9915         {
9916           changed = 1;
9917           log = INTVAL (XEXP (XEXP (x, 0), 1));
9918           XEXP (x, 0) = gen_rtx_MULT (Pmode,
9919                                       force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
9920                                       GEN_INT (1 << log));
9921         }
9922
9923       if (GET_CODE (XEXP (x, 1)) == ASHIFT
9924           && CONST_INT_P (XEXP (XEXP (x, 1), 1))
9925           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 1), 1)) < 4)
9926         {
9927           changed = 1;
9928           log = INTVAL (XEXP (XEXP (x, 1), 1));
9929           XEXP (x, 1) = gen_rtx_MULT (Pmode,
9930                                       force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
9931                                       GEN_INT (1 << log));
9932         }
9933
9934       /* Put multiply first if it isn't already.  */
9935       if (GET_CODE (XEXP (x, 1)) == MULT)
9936         {
9937           rtx tmp = XEXP (x, 0);
9938           XEXP (x, 0) = XEXP (x, 1);
9939           XEXP (x, 1) = tmp;
9940           changed = 1;
9941         }
9942
9943       /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
9944          into (plus (plus (mult (reg) (const)) (reg)) (const)).  This can be
9945          created by virtual register instantiation, register elimination, and
9946          similar optimizations.  */
9947       if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS)
9948         {
9949           changed = 1;
9950           x = gen_rtx_PLUS (Pmode,
9951                             gen_rtx_PLUS (Pmode, XEXP (x, 0),
9952                                           XEXP (XEXP (x, 1), 0)),
9953                             XEXP (XEXP (x, 1), 1));
9954         }
9955
9956       /* Canonicalize
9957          (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
9958          into (plus (plus (mult (reg) (const)) (reg)) (const)).  */
9959       else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
9960                && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
9961                && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
9962                && CONSTANT_P (XEXP (x, 1)))
9963         {
9964           rtx constant;
9965           rtx other = NULL_RTX;
9966
9967           if (CONST_INT_P (XEXP (x, 1)))
9968             {
9969               constant = XEXP (x, 1);
9970               other = XEXP (XEXP (XEXP (x, 0), 1), 1);
9971             }
9972           else if (CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 1), 1)))
9973             {
9974               constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
9975               other = XEXP (x, 1);
9976             }
9977           else
9978             constant = 0;
9979
9980           if (constant)
9981             {
9982               changed = 1;
9983               x = gen_rtx_PLUS (Pmode,
9984                                 gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 0),
9985                                               XEXP (XEXP (XEXP (x, 0), 1), 0)),
9986                                 plus_constant (other, INTVAL (constant)));
9987             }
9988         }
9989
9990       if (changed && legitimate_address_p (mode, x, FALSE))
9991         return x;
9992
9993       if (GET_CODE (XEXP (x, 0)) == MULT)
9994         {
9995           changed = 1;
9996           XEXP (x, 0) = force_operand (XEXP (x, 0), 0);
9997         }
9998
9999       if (GET_CODE (XEXP (x, 1)) == MULT)
10000         {
10001           changed = 1;
10002           XEXP (x, 1) = force_operand (XEXP (x, 1), 0);
10003         }
10004
10005       if (changed
10006           && REG_P (XEXP (x, 1))
10007           && REG_P (XEXP (x, 0)))
10008         return x;
10009
10010       if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1)))
10011         {
10012           changed = 1;
10013           x = legitimize_pic_address (x, 0);
10014         }
10015
10016       if (changed && legitimate_address_p (mode, x, FALSE))
10017         return x;
10018
10019       if (REG_P (XEXP (x, 0)))
10020         {
10021           rtx temp = gen_reg_rtx (Pmode);
10022           rtx val  = force_operand (XEXP (x, 1), temp);
10023           if (val != temp)
10024             emit_move_insn (temp, val);
10025
10026           XEXP (x, 1) = temp;
10027           return x;
10028         }
10029
10030       else if (REG_P (XEXP (x, 1)))
10031         {
10032           rtx temp = gen_reg_rtx (Pmode);
10033           rtx val  = force_operand (XEXP (x, 0), temp);
10034           if (val != temp)
10035             emit_move_insn (temp, val);
10036
10037           XEXP (x, 0) = temp;
10038           return x;
10039         }
10040     }
10041
10042   return x;
10043 }
10044 \f
10045 /* Print an integer constant expression in assembler syntax.  Addition
10046    and subtraction are the only arithmetic that may appear in these
10047    expressions.  FILE is the stdio stream to write to, X is the rtx, and
10048    CODE is the operand print code from the output string.  */
10049
10050 static void
10051 output_pic_addr_const (FILE *file, rtx x, int code)
10052 {
10053   char buf[256];
10054
10055   switch (GET_CODE (x))
10056     {
10057     case PC:
10058       gcc_assert (flag_pic);
10059       putc ('.', file);
10060       break;
10061
10062     case SYMBOL_REF:
10063       if (! TARGET_MACHO || TARGET_64BIT)
10064         output_addr_const (file, x);
10065       else
10066         {
10067           const char *name = XSTR (x, 0);
10068
10069           /* Mark the decl as referenced so that cgraph will
10070              output the function.  */
10071           if (SYMBOL_REF_DECL (x))
10072             mark_decl_referenced (SYMBOL_REF_DECL (x));
10073
10074 #if TARGET_MACHO
10075           if (MACHOPIC_INDIRECT
10076               && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
10077             name = machopic_indirection_name (x, /*stub_p=*/true);
10078 #endif
10079           assemble_name (file, name);
10080         }
10081       if (!TARGET_MACHO && !(TARGET_64BIT && DEFAULT_ABI == MS_ABI)
10082           && code == 'P' && ! SYMBOL_REF_LOCAL_P (x))
10083         fputs ("@PLT", file);
10084       break;
10085
10086     case LABEL_REF:
10087       x = XEXP (x, 0);
10088       /* FALLTHRU */
10089     case CODE_LABEL:
10090       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
10091       assemble_name (asm_out_file, buf);
10092       break;
10093
10094     case CONST_INT:
10095       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
10096       break;
10097
10098     case CONST:
10099       /* This used to output parentheses around the expression,
10100          but that does not work on the 386 (either ATT or BSD assembler).  */
10101       output_pic_addr_const (file, XEXP (x, 0), code);
10102       break;
10103
10104     case CONST_DOUBLE:
10105       if (GET_MODE (x) == VOIDmode)
10106         {
10107           /* We can use %d if the number is <32 bits and positive.  */
10108           if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
10109             fprintf (file, "0x%lx%08lx",
10110                      (unsigned long) CONST_DOUBLE_HIGH (x),
10111                      (unsigned long) CONST_DOUBLE_LOW (x));
10112           else
10113             fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
10114         }
10115       else
10116         /* We can't handle floating point constants;
10117            PRINT_OPERAND must handle them.  */
10118         output_operand_lossage ("floating constant misused");
10119       break;
10120
10121     case PLUS:
10122       /* Some assemblers need integer constants to appear first.  */
10123       if (CONST_INT_P (XEXP (x, 0)))
10124         {
10125           output_pic_addr_const (file, XEXP (x, 0), code);
10126           putc ('+', file);
10127           output_pic_addr_const (file, XEXP (x, 1), code);
10128         }
10129       else
10130         {
10131           gcc_assert (CONST_INT_P (XEXP (x, 1)));
10132           output_pic_addr_const (file, XEXP (x, 1), code);
10133           putc ('+', file);
10134           output_pic_addr_const (file, XEXP (x, 0), code);
10135         }
10136       break;
10137
10138     case MINUS:
10139       if (!TARGET_MACHO)
10140         putc (ASSEMBLER_DIALECT == ASM_INTEL ? '(' : '[', file);
10141       output_pic_addr_const (file, XEXP (x, 0), code);
10142       putc ('-', file);
10143       output_pic_addr_const (file, XEXP (x, 1), code);
10144       if (!TARGET_MACHO)
10145         putc (ASSEMBLER_DIALECT == ASM_INTEL ? ')' : ']', file);
10146       break;
10147
10148      case UNSPEC:
10149        gcc_assert (XVECLEN (x, 0) == 1);
10150        output_pic_addr_const (file, XVECEXP (x, 0, 0), code);
10151        switch (XINT (x, 1))
10152         {
10153         case UNSPEC_GOT:
10154           fputs ("@GOT", file);
10155           break;
10156         case UNSPEC_GOTOFF:
10157           fputs ("@GOTOFF", file);
10158           break;
10159         case UNSPEC_PLTOFF:
10160           fputs ("@PLTOFF", file);
10161           break;
10162         case UNSPEC_GOTPCREL:
10163           fputs (ASSEMBLER_DIALECT == ASM_ATT ?
10164                  "@GOTPCREL(%rip)" : "@GOTPCREL[rip]", file);
10165           break;
10166         case UNSPEC_GOTTPOFF:
10167           /* FIXME: This might be @TPOFF in Sun ld too.  */
10168           fputs ("@GOTTPOFF", file);
10169           break;
10170         case UNSPEC_TPOFF:
10171           fputs ("@TPOFF", file);
10172           break;
10173         case UNSPEC_NTPOFF:
10174           if (TARGET_64BIT)
10175             fputs ("@TPOFF", file);
10176           else
10177             fputs ("@NTPOFF", file);
10178           break;
10179         case UNSPEC_DTPOFF:
10180           fputs ("@DTPOFF", file);
10181           break;
10182         case UNSPEC_GOTNTPOFF:
10183           if (TARGET_64BIT)
10184             fputs (ASSEMBLER_DIALECT == ASM_ATT ?
10185                    "@GOTTPOFF(%rip)": "@GOTTPOFF[rip]", file);
10186           else
10187             fputs ("@GOTNTPOFF", file);
10188           break;
10189         case UNSPEC_INDNTPOFF:
10190           fputs ("@INDNTPOFF", file);
10191           break;
10192 #if TARGET_MACHO
10193         case UNSPEC_MACHOPIC_OFFSET:
10194           putc ('-', file);
10195           machopic_output_function_base_name (file);
10196           break;
10197 #endif
10198         default:
10199           output_operand_lossage ("invalid UNSPEC as operand");
10200           break;
10201         }
10202        break;
10203
10204     default:
10205       output_operand_lossage ("invalid expression as operand");
10206     }
10207 }
10208
10209 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
10210    We need to emit DTP-relative relocations.  */
10211
10212 static void ATTRIBUTE_UNUSED
10213 i386_output_dwarf_dtprel (FILE *file, int size, rtx x)
10214 {
10215   fputs (ASM_LONG, file);
10216   output_addr_const (file, x);
10217   fputs ("@DTPOFF", file);
10218   switch (size)
10219     {
10220     case 4:
10221       break;
10222     case 8:
10223       fputs (", 0", file);
10224       break;
10225     default:
10226       gcc_unreachable ();
10227    }
10228 }
10229
10230 /* Return true if X is a representation of the PIC register.  This copes
10231    with calls from ix86_find_base_term, where the register might have
10232    been replaced by a cselib value.  */
10233
10234 static bool
10235 ix86_pic_register_p (rtx x)
10236 {
10237   if (GET_CODE (x) == VALUE)
10238     return (pic_offset_table_rtx
10239             && rtx_equal_for_cselib_p (x, pic_offset_table_rtx));
10240   else
10241     return REG_P (x) && REGNO (x) == PIC_OFFSET_TABLE_REGNUM;
10242 }
10243
10244 /* In the name of slightly smaller debug output, and to cater to
10245    general assembler lossage, recognize PIC+GOTOFF and turn it back
10246    into a direct symbol reference.
10247
10248    On Darwin, this is necessary to avoid a crash, because Darwin
10249    has a different PIC label for each routine but the DWARF debugging
10250    information is not associated with any particular routine, so it's
10251    necessary to remove references to the PIC label from RTL stored by
10252    the DWARF output code.  */
10253
10254 static rtx
10255 ix86_delegitimize_address (rtx orig_x)
10256 {
10257   rtx x = orig_x;
10258   /* reg_addend is NULL or a multiple of some register.  */
10259   rtx reg_addend = NULL_RTX;
10260   /* const_addend is NULL or a const_int.  */
10261   rtx const_addend = NULL_RTX;
10262   /* This is the result, or NULL.  */
10263   rtx result = NULL_RTX;
10264
10265   if (MEM_P (x))
10266     x = XEXP (x, 0);
10267
10268   if (TARGET_64BIT)
10269     {
10270       if (GET_CODE (x) != CONST
10271           || GET_CODE (XEXP (x, 0)) != UNSPEC
10272           || XINT (XEXP (x, 0), 1) != UNSPEC_GOTPCREL
10273           || !MEM_P (orig_x))
10274         return orig_x;
10275       return XVECEXP (XEXP (x, 0), 0, 0);
10276     }
10277
10278   if (GET_CODE (x) != PLUS
10279       || GET_CODE (XEXP (x, 1)) != CONST)
10280     return orig_x;
10281
10282   if (ix86_pic_register_p (XEXP (x, 0)))
10283     /* %ebx + GOT/GOTOFF */
10284     ;
10285   else if (GET_CODE (XEXP (x, 0)) == PLUS)
10286     {
10287       /* %ebx + %reg * scale + GOT/GOTOFF */
10288       reg_addend = XEXP (x, 0);
10289       if (ix86_pic_register_p (XEXP (reg_addend, 0)))
10290         reg_addend = XEXP (reg_addend, 1);
10291       else if (ix86_pic_register_p (XEXP (reg_addend, 1)))
10292         reg_addend = XEXP (reg_addend, 0);
10293       else
10294         return orig_x;
10295       if (!REG_P (reg_addend)
10296           && GET_CODE (reg_addend) != MULT
10297           && GET_CODE (reg_addend) != ASHIFT)
10298         return orig_x;
10299     }
10300   else
10301     return orig_x;
10302
10303   x = XEXP (XEXP (x, 1), 0);
10304   if (GET_CODE (x) == PLUS
10305       && CONST_INT_P (XEXP (x, 1)))
10306     {
10307       const_addend = XEXP (x, 1);
10308       x = XEXP (x, 0);
10309     }
10310
10311   if (GET_CODE (x) == UNSPEC
10312       && ((XINT (x, 1) == UNSPEC_GOT && MEM_P (orig_x))
10313           || (XINT (x, 1) == UNSPEC_GOTOFF && !MEM_P (orig_x))))
10314     result = XVECEXP (x, 0, 0);
10315
10316   if (TARGET_MACHO && darwin_local_data_pic (x)
10317       && !MEM_P (orig_x))
10318     result = XVECEXP (x, 0, 0);
10319
10320   if (! result)
10321     return orig_x;
10322
10323   if (const_addend)
10324     result = gen_rtx_CONST (Pmode, gen_rtx_PLUS (Pmode, result, const_addend));
10325   if (reg_addend)
10326     result = gen_rtx_PLUS (Pmode, reg_addend, result);
10327   return result;
10328 }
10329
10330 /* If X is a machine specific address (i.e. a symbol or label being
10331    referenced as a displacement from the GOT implemented using an
10332    UNSPEC), then return the base term.  Otherwise return X.  */
10333
10334 rtx
10335 ix86_find_base_term (rtx x)
10336 {
10337   rtx term;
10338
10339   if (TARGET_64BIT)
10340     {
10341       if (GET_CODE (x) != CONST)
10342         return x;
10343       term = XEXP (x, 0);
10344       if (GET_CODE (term) == PLUS
10345           && (CONST_INT_P (XEXP (term, 1))
10346               || GET_CODE (XEXP (term, 1)) == CONST_DOUBLE))
10347         term = XEXP (term, 0);
10348       if (GET_CODE (term) != UNSPEC
10349           || XINT (term, 1) != UNSPEC_GOTPCREL)
10350         return x;
10351
10352       return XVECEXP (term, 0, 0);
10353     }
10354
10355   return ix86_delegitimize_address (x);
10356 }
10357 \f
10358 static void
10359 put_condition_code (enum rtx_code code, enum machine_mode mode, int reverse,
10360                     int fp, FILE *file)
10361 {
10362   const char *suffix;
10363
10364   if (mode == CCFPmode || mode == CCFPUmode)
10365     {
10366       enum rtx_code second_code, bypass_code;
10367       ix86_fp_comparison_codes (code, &bypass_code, &code, &second_code);
10368       gcc_assert (bypass_code == UNKNOWN && second_code == UNKNOWN);
10369       code = ix86_fp_compare_code_to_integer (code);
10370       mode = CCmode;
10371     }
10372   if (reverse)
10373     code = reverse_condition (code);
10374
10375   switch (code)
10376     {
10377     case EQ:
10378       switch (mode)
10379         {
10380         case CCAmode:
10381           suffix = "a";
10382           break;
10383
10384         case CCCmode:
10385           suffix = "c";
10386           break;
10387
10388         case CCOmode:
10389           suffix = "o";
10390           break;
10391
10392         case CCSmode:
10393           suffix = "s";
10394           break;
10395
10396         default:
10397           suffix = "e";
10398         }
10399       break;
10400     case NE:
10401       switch (mode)
10402         {
10403         case CCAmode:
10404           suffix = "na";
10405           break;
10406
10407         case CCCmode:
10408           suffix = "nc";
10409           break;
10410
10411         case CCOmode:
10412           suffix = "no";
10413           break;
10414
10415         case CCSmode:
10416           suffix = "ns";
10417           break;
10418
10419         default:
10420           suffix = "ne";
10421         }
10422       break;
10423     case GT:
10424       gcc_assert (mode == CCmode || mode == CCNOmode || mode == CCGCmode);
10425       suffix = "g";
10426       break;
10427     case GTU:
10428       /* ??? Use "nbe" instead of "a" for fcmov lossage on some assemblers.
10429          Those same assemblers have the same but opposite lossage on cmov.  */
10430       if (mode == CCmode)
10431         suffix = fp ? "nbe" : "a";
10432       else if (mode == CCCmode)
10433         suffix = "b";
10434       else
10435         gcc_unreachable ();
10436       break;
10437     case LT:
10438       switch (mode)
10439         {
10440         case CCNOmode:
10441         case CCGOCmode:
10442           suffix = "s";
10443           break;
10444
10445         case CCmode:
10446         case CCGCmode:
10447           suffix = "l";
10448           break;
10449
10450         default:
10451           gcc_unreachable ();
10452         }
10453       break;
10454     case LTU:
10455       gcc_assert (mode == CCmode || mode == CCCmode);
10456       suffix = "b";
10457       break;
10458     case GE:
10459       switch (mode)
10460         {
10461         case CCNOmode:
10462         case CCGOCmode:
10463           suffix = "ns";
10464           break;
10465
10466         case CCmode:
10467         case CCGCmode:
10468           suffix = "ge";
10469           break;
10470
10471         default:
10472           gcc_unreachable ();
10473         }
10474       break;
10475     case GEU:
10476       /* ??? As above.  */
10477       gcc_assert (mode == CCmode || mode == CCCmode);
10478       suffix = fp ? "nb" : "ae";
10479       break;
10480     case LE:
10481       gcc_assert (mode == CCmode || mode == CCGCmode || mode == CCNOmode);
10482       suffix = "le";
10483       break;
10484     case LEU:
10485       /* ??? As above.  */
10486       if (mode == CCmode)
10487         suffix = "be";
10488       else if (mode == CCCmode)
10489         suffix = fp ? "nb" : "ae";
10490       else
10491         gcc_unreachable ();
10492       break;
10493     case UNORDERED:
10494       suffix = fp ? "u" : "p";
10495       break;
10496     case ORDERED:
10497       suffix = fp ? "nu" : "np";
10498       break;
10499     default:
10500       gcc_unreachable ();
10501     }
10502   fputs (suffix, file);
10503 }
10504
10505 /* Print the name of register X to FILE based on its machine mode and number.
10506    If CODE is 'w', pretend the mode is HImode.
10507    If CODE is 'b', pretend the mode is QImode.
10508    If CODE is 'k', pretend the mode is SImode.
10509    If CODE is 'q', pretend the mode is DImode.
10510    If CODE is 'x', pretend the mode is V4SFmode.
10511    If CODE is 't', pretend the mode is V8SFmode.
10512    If CODE is 'h', pretend the reg is the 'high' byte register.
10513    If CODE is 'y', print "st(0)" instead of "st", if the reg is stack op.
10514    If CODE is 'd', duplicate the operand for AVX instruction.
10515  */
10516
10517 void
10518 print_reg (rtx x, int code, FILE *file)
10519 {
10520   const char *reg;
10521   bool duplicated = code == 'd' && TARGET_AVX;
10522
10523   gcc_assert (x == pc_rtx
10524               || (REGNO (x) != ARG_POINTER_REGNUM
10525                   && REGNO (x) != FRAME_POINTER_REGNUM
10526                   && REGNO (x) != FLAGS_REG
10527                   && REGNO (x) != FPSR_REG
10528                   && REGNO (x) != FPCR_REG));
10529
10530   if (ASSEMBLER_DIALECT == ASM_ATT)
10531     putc ('%', file);
10532
10533   if (x == pc_rtx)
10534     {
10535       gcc_assert (TARGET_64BIT);
10536       fputs ("rip", file);
10537       return;
10538     }
10539
10540   if (code == 'w' || MMX_REG_P (x))
10541     code = 2;
10542   else if (code == 'b')
10543     code = 1;
10544   else if (code == 'k')
10545     code = 4;
10546   else if (code == 'q')
10547     code = 8;
10548   else if (code == 'y')
10549     code = 3;
10550   else if (code == 'h')
10551     code = 0;
10552   else if (code == 'x')
10553     code = 16;
10554   else if (code == 't')
10555     code = 32;
10556   else
10557     code = GET_MODE_SIZE (GET_MODE (x));
10558
10559   /* Irritatingly, AMD extended registers use different naming convention
10560      from the normal registers.  */
10561   if (REX_INT_REG_P (x))
10562     {
10563       gcc_assert (TARGET_64BIT);
10564       switch (code)
10565         {
10566           case 0:
10567             error ("extended registers have no high halves");
10568             break;
10569           case 1:
10570             fprintf (file, "r%ib", REGNO (x) - FIRST_REX_INT_REG + 8);
10571             break;
10572           case 2:
10573             fprintf (file, "r%iw", REGNO (x) - FIRST_REX_INT_REG + 8);
10574             break;
10575           case 4:
10576             fprintf (file, "r%id", REGNO (x) - FIRST_REX_INT_REG + 8);
10577             break;
10578           case 8:
10579             fprintf (file, "r%i", REGNO (x) - FIRST_REX_INT_REG + 8);
10580             break;
10581           default:
10582             error ("unsupported operand size for extended register");
10583             break;
10584         }
10585       return;
10586     }
10587
10588   reg = NULL;
10589   switch (code)
10590     {
10591     case 3:
10592       if (STACK_TOP_P (x))
10593         {
10594           reg = "st(0)";
10595           break;
10596         }
10597       /* FALLTHRU */
10598     case 8:
10599     case 4:
10600     case 12:
10601       if (! ANY_FP_REG_P (x))
10602         putc (code == 8 && TARGET_64BIT ? 'r' : 'e', file);
10603       /* FALLTHRU */
10604     case 16:
10605     case 2:
10606     normal:
10607       reg = hi_reg_name[REGNO (x)];
10608       break;
10609     case 1:
10610       if (REGNO (x) >= ARRAY_SIZE (qi_reg_name))
10611         goto normal;
10612       reg = qi_reg_name[REGNO (x)];
10613       break;
10614     case 0:
10615       if (REGNO (x) >= ARRAY_SIZE (qi_high_reg_name))
10616         goto normal;
10617       reg = qi_high_reg_name[REGNO (x)];
10618       break;
10619     case 32:
10620       if (SSE_REG_P (x))
10621         {
10622           gcc_assert (!duplicated);
10623           putc ('y', file);
10624           fputs (hi_reg_name[REGNO (x)] + 1, file);
10625           return;
10626         }
10627       break;
10628     default:
10629       gcc_unreachable ();
10630     }
10631
10632   fputs (reg, file);
10633   if (duplicated)
10634     {
10635       if (ASSEMBLER_DIALECT == ASM_ATT)
10636         fprintf (file, ", %%%s", reg);
10637       else
10638         fprintf (file, ", %s", reg);
10639     }
10640 }
10641
10642 /* Locate some local-dynamic symbol still in use by this function
10643    so that we can print its name in some tls_local_dynamic_base
10644    pattern.  */
10645
10646 static int
10647 get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
10648 {
10649   rtx x = *px;
10650
10651   if (GET_CODE (x) == SYMBOL_REF
10652       && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
10653     {
10654       cfun->machine->some_ld_name = XSTR (x, 0);
10655       return 1;
10656     }
10657
10658   return 0;
10659 }
10660
10661 static const char *
10662 get_some_local_dynamic_name (void)
10663 {
10664   rtx insn;
10665
10666   if (cfun->machine->some_ld_name)
10667     return cfun->machine->some_ld_name;
10668
10669   for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
10670     if (INSN_P (insn)
10671         && for_each_rtx (&PATTERN (insn), get_some_local_dynamic_name_1, 0))
10672       return cfun->machine->some_ld_name;
10673
10674   gcc_unreachable ();
10675 }
10676
10677 /* Meaning of CODE:
10678    L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
10679    C -- print opcode suffix for set/cmov insn.
10680    c -- like C, but print reversed condition
10681    E,e -- likewise, but for compare-and-branch fused insn.
10682    F,f -- likewise, but for floating-point.
10683    O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
10684         otherwise nothing
10685    R -- print the prefix for register names.
10686    z -- print the opcode suffix for the size of the current operand.
10687    * -- print a star (in certain assembler syntax)
10688    A -- print an absolute memory reference.
10689    w -- print the operand as if it's a "word" (HImode) even if it isn't.
10690    s -- print a shift double count, followed by the assemblers argument
10691         delimiter.
10692    b -- print the QImode name of the register for the indicated operand.
10693         %b0 would print %al if operands[0] is reg 0.
10694    w --  likewise, print the HImode name of the register.
10695    k --  likewise, print the SImode name of the register.
10696    q --  likewise, print the DImode name of the register.
10697    x --  likewise, print the V4SFmode name of the register.
10698    t --  likewise, print the V8SFmode name of the register.
10699    h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
10700    y -- print "st(0)" instead of "st" as a register.
10701    d -- print duplicated register operand for AVX instruction.
10702    D -- print condition for SSE cmp instruction.
10703    P -- if PIC, print an @PLT suffix.
10704    X -- don't print any sort of PIC '@' suffix for a symbol.
10705    & -- print some in-use local-dynamic symbol name.
10706    H -- print a memory address offset by 8; used for sse high-parts
10707    Y -- print condition for SSE5 com* instruction.
10708    + -- print a branch hint as 'cs' or 'ds' prefix
10709    ; -- print a semicolon (after prefixes due to bug in older gas).
10710  */
10711
10712 void
10713 print_operand (FILE *file, rtx x, int code)
10714 {
10715   if (code)
10716     {
10717       switch (code)
10718         {
10719         case '*':
10720           if (ASSEMBLER_DIALECT == ASM_ATT)
10721             putc ('*', file);
10722           return;
10723
10724         case '&':
10725           assemble_name (file, get_some_local_dynamic_name ());
10726           return;
10727
10728         case 'A':
10729           switch (ASSEMBLER_DIALECT)
10730             {
10731             case ASM_ATT:
10732               putc ('*', file);
10733               break;
10734
10735             case ASM_INTEL:
10736               /* Intel syntax. For absolute addresses, registers should not
10737                  be surrounded by braces.  */
10738               if (!REG_P (x))
10739                 {
10740                   putc ('[', file);
10741                   PRINT_OPERAND (file, x, 0);
10742                   putc (']', file);
10743                   return;
10744                 }
10745               break;
10746
10747             default:
10748               gcc_unreachable ();
10749             }
10750
10751           PRINT_OPERAND (file, x, 0);
10752           return;
10753
10754
10755         case 'L':
10756           if (ASSEMBLER_DIALECT == ASM_ATT)
10757             putc ('l', file);
10758           return;
10759
10760         case 'W':
10761           if (ASSEMBLER_DIALECT == ASM_ATT)
10762             putc ('w', file);
10763           return;
10764
10765         case 'B':
10766           if (ASSEMBLER_DIALECT == ASM_ATT)
10767             putc ('b', file);
10768           return;
10769
10770         case 'Q':
10771           if (ASSEMBLER_DIALECT == ASM_ATT)
10772             putc ('l', file);
10773           return;
10774
10775         case 'S':
10776           if (ASSEMBLER_DIALECT == ASM_ATT)
10777             putc ('s', file);
10778           return;
10779
10780         case 'T':
10781           if (ASSEMBLER_DIALECT == ASM_ATT)
10782             putc ('t', file);
10783           return;
10784
10785         case 'z':
10786           /* 387 opcodes don't get size suffixes if the operands are
10787              registers.  */
10788           if (STACK_REG_P (x))
10789             return;
10790
10791           /* Likewise if using Intel opcodes.  */
10792           if (ASSEMBLER_DIALECT == ASM_INTEL)
10793             return;
10794
10795           /* This is the size of op from size of operand.  */
10796           switch (GET_MODE_SIZE (GET_MODE (x)))
10797             {
10798             case 1:
10799               putc ('b', file);
10800               return;
10801
10802             case 2:
10803               if (MEM_P (x))
10804                 {
10805 #ifdef HAVE_GAS_FILDS_FISTS
10806                   putc ('s', file);
10807 #endif
10808                   return;
10809                 }
10810               else
10811                 putc ('w', file);
10812               return;
10813
10814             case 4:
10815               if (GET_MODE (x) == SFmode)
10816                 {
10817                   putc ('s', file);
10818                   return;
10819                 }
10820               else
10821                 putc ('l', file);
10822               return;
10823
10824             case 12:
10825             case 16:
10826               putc ('t', file);
10827               return;
10828
10829             case 8:
10830               if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
10831                 {
10832                   if (MEM_P (x))
10833                     {
10834 #ifdef GAS_MNEMONICS
10835                       putc ('q', file);
10836 #else
10837                       putc ('l', file);
10838                       putc ('l', file);
10839 #endif
10840                     }
10841                   else
10842                     putc ('q', file);
10843                 }
10844               else
10845                 putc ('l', file);
10846               return;
10847
10848             default:
10849               gcc_unreachable ();
10850             }
10851
10852         case 'd':
10853         case 'b':
10854         case 'w':
10855         case 'k':
10856         case 'q':
10857         case 'h':
10858         case 't':
10859         case 'y':
10860         case 'x':
10861         case 'X':
10862         case 'P':
10863           break;
10864
10865         case 's':
10866           if (CONST_INT_P (x) || ! SHIFT_DOUBLE_OMITS_COUNT)
10867             {
10868               PRINT_OPERAND (file, x, 0);
10869               fputs (", ", file);
10870             }
10871           return;
10872
10873         case 'D':
10874           /* Little bit of braindamage here.  The SSE compare instructions
10875              does use completely different names for the comparisons that the
10876              fp conditional moves.  */
10877           if (TARGET_AVX)
10878             {
10879               switch (GET_CODE (x))
10880                 {
10881                 case EQ:
10882                   fputs ("eq", file);
10883                   break;
10884                 case UNEQ:
10885                   fputs ("eq_us", file);
10886                   break;
10887                 case LT:
10888                   fputs ("lt", file);
10889                   break;
10890                 case UNLT:
10891                   fputs ("nge", file);
10892                   break;
10893                 case LE:
10894                   fputs ("le", file);
10895                   break;
10896                 case UNLE:
10897                   fputs ("ngt", file);
10898                   break;
10899                 case UNORDERED:
10900                   fputs ("unord", file);
10901                   break;
10902                 case NE:
10903                   fputs ("neq", file);
10904                   break;
10905                 case LTGT:
10906                   fputs ("neq_oq", file);
10907                   break;
10908                 case GE:
10909                   fputs ("ge", file);
10910                   break;
10911                 case UNGE:
10912                   fputs ("nlt", file);
10913                   break;
10914                 case GT:
10915                   fputs ("gt", file);
10916                   break;
10917                 case UNGT:
10918                   fputs ("nle", file);
10919                   break;
10920                 case ORDERED:
10921                   fputs ("ord", file);
10922                   break;
10923                 default:
10924                   output_operand_lossage ("operand is not a condition code, invalid operand code 'D'");
10925                   return;
10926                 }
10927             }
10928           else
10929             {
10930               switch (GET_CODE (x))
10931                 {
10932                 case EQ:
10933                 case UNEQ:
10934                   fputs ("eq", file);
10935                   break;
10936                 case LT:
10937                 case UNLT:
10938                   fputs ("lt", file);
10939                   break;
10940                 case LE:
10941                 case UNLE:
10942                   fputs ("le", file);
10943                   break;
10944                 case UNORDERED:
10945                   fputs ("unord", file);
10946                   break;
10947                 case NE:
10948                 case LTGT:
10949                   fputs ("neq", file);
10950                   break;
10951                 case UNGE:
10952                 case GE:
10953                   fputs ("nlt", file);
10954                   break;
10955                 case UNGT:
10956                 case GT:
10957                   fputs ("nle", file);
10958                   break;
10959                 case ORDERED:
10960                   fputs ("ord", file);
10961                   break;
10962                 default:
10963                   output_operand_lossage ("operand is not a condition code, invalid operand code 'D'");
10964                   return;
10965                 }
10966             }
10967           return;
10968         case 'O':
10969 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
10970           if (ASSEMBLER_DIALECT == ASM_ATT)
10971             {
10972               switch (GET_MODE (x))
10973                 {
10974                 case HImode: putc ('w', file); break;
10975                 case SImode:
10976                 case SFmode: putc ('l', file); break;
10977                 case DImode:
10978                 case DFmode: putc ('q', file); break;
10979                 default: gcc_unreachable ();
10980                 }
10981               putc ('.', file);
10982             }
10983 #endif
10984           return;
10985         case 'C':
10986           if (!COMPARISON_P (x))
10987             {
10988               output_operand_lossage ("operand is neither a constant nor a "
10989                                       "condition code, invalid operand code "
10990                                       "'C'");
10991               return;
10992             }
10993           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 0, file);
10994           return;
10995         case 'F':
10996           if (!COMPARISON_P (x))
10997             {
10998               output_operand_lossage ("operand is neither a constant nor a "
10999                                       "condition code, invalid operand code "
11000                                       "'F'");
11001               return;
11002             }
11003 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
11004           if (ASSEMBLER_DIALECT == ASM_ATT)
11005             putc ('.', file);
11006 #endif
11007           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 1, file);
11008           return;
11009
11010           /* Like above, but reverse condition */
11011         case 'c':
11012           /* Check to see if argument to %c is really a constant
11013              and not a condition code which needs to be reversed.  */
11014           if (!COMPARISON_P (x))
11015             {
11016               output_operand_lossage ("operand is neither a constant nor a "
11017                                       "condition code, invalid operand "
11018                                       "code 'c'");
11019               return;
11020             }
11021           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 0, file);
11022           return;
11023         case 'f':
11024           if (!COMPARISON_P (x))
11025             {
11026               output_operand_lossage ("operand is neither a constant nor a "
11027                                       "condition code, invalid operand "
11028                                       "code 'f'");
11029               return;
11030             }
11031 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
11032           if (ASSEMBLER_DIALECT == ASM_ATT)
11033             putc ('.', file);
11034 #endif
11035           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 1, file);
11036           return;
11037
11038         case 'E':
11039           put_condition_code (GET_CODE (x), CCmode, 0, 0, file);
11040           return;
11041
11042         case 'e':
11043           put_condition_code (GET_CODE (x), CCmode, 1, 0, file);
11044           return;
11045
11046         case 'H':
11047           /* It doesn't actually matter what mode we use here, as we're
11048              only going to use this for printing.  */
11049           x = adjust_address_nv (x, DImode, 8);
11050           break;
11051
11052         case '+':
11053           {
11054             rtx x;
11055
11056             if (!optimize
11057                 || optimize_function_for_size_p (cfun) || !TARGET_BRANCH_PREDICTION_HINTS)
11058               return;
11059
11060             x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
11061             if (x)
11062               {
11063                 int pred_val = INTVAL (XEXP (x, 0));
11064
11065                 if (pred_val < REG_BR_PROB_BASE * 45 / 100
11066                     || pred_val > REG_BR_PROB_BASE * 55 / 100)
11067                   {
11068                     int taken = pred_val > REG_BR_PROB_BASE / 2;
11069                     int cputaken = final_forward_branch_p (current_output_insn) == 0;
11070
11071                     /* Emit hints only in the case default branch prediction
11072                        heuristics would fail.  */
11073                     if (taken != cputaken)
11074                       {
11075                         /* We use 3e (DS) prefix for taken branches and
11076                            2e (CS) prefix for not taken branches.  */
11077                         if (taken)
11078                           fputs ("ds ; ", file);
11079                         else
11080                           fputs ("cs ; ", file);
11081                       }
11082                   }
11083               }
11084             return;
11085           }
11086
11087         case 'Y':
11088           switch (GET_CODE (x))
11089             {
11090             case NE:
11091               fputs ("neq", file);
11092               break;
11093             case EQ:
11094               fputs ("eq", file);
11095               break;
11096             case GE:
11097             case GEU:
11098               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "ge" : "unlt", file);
11099               break;
11100             case GT:
11101             case GTU:
11102               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "gt" : "unle", file);
11103               break;
11104             case LE:
11105             case LEU:
11106               fputs ("le", file);
11107               break;
11108             case LT:
11109             case LTU:
11110               fputs ("lt", file);
11111               break;
11112             case UNORDERED:
11113               fputs ("unord", file);
11114               break;
11115             case ORDERED:
11116               fputs ("ord", file);
11117               break;
11118             case UNEQ:
11119               fputs ("ueq", file);
11120               break;
11121             case UNGE:
11122               fputs ("nlt", file);
11123               break;
11124             case UNGT:
11125               fputs ("nle", file);
11126               break;
11127             case UNLE:
11128               fputs ("ule", file);
11129               break;
11130             case UNLT:
11131               fputs ("ult", file);
11132               break;
11133             case LTGT:
11134               fputs ("une", file);
11135               break;
11136             default:
11137               output_operand_lossage ("operand is not a condition code, invalid operand code 'D'");
11138               return;
11139             }
11140           return;
11141
11142         case ';':
11143 #if TARGET_MACHO
11144           fputs (" ; ", file);
11145 #else
11146           fputc (' ', file);
11147 #endif
11148           return;
11149
11150         default:
11151             output_operand_lossage ("invalid operand code '%c'", code);
11152         }
11153     }
11154
11155   if (REG_P (x))
11156     print_reg (x, code, file);
11157
11158   else if (MEM_P (x))
11159     {
11160       /* No `byte ptr' prefix for call instructions or BLKmode operands.  */
11161       if (ASSEMBLER_DIALECT == ASM_INTEL && code != 'X' && code != 'P'
11162           && GET_MODE (x) != BLKmode)
11163         {
11164           const char * size;
11165           switch (GET_MODE_SIZE (GET_MODE (x)))
11166             {
11167             case 1: size = "BYTE"; break;
11168             case 2: size = "WORD"; break;
11169             case 4: size = "DWORD"; break;
11170             case 8: size = "QWORD"; break;
11171             case 12: size = "XWORD"; break;
11172             case 16:
11173               if (GET_MODE (x) == XFmode)
11174                 size = "XWORD";
11175               else
11176                 size = "XMMWORD";
11177               break;
11178             default:
11179               gcc_unreachable ();
11180             }
11181
11182           /* Check for explicit size override (codes 'b', 'w' and 'k')  */
11183           if (code == 'b')
11184             size = "BYTE";
11185           else if (code == 'w')
11186             size = "WORD";
11187           else if (code == 'k')
11188             size = "DWORD";
11189
11190           fputs (size, file);
11191           fputs (" PTR ", file);
11192         }
11193
11194       x = XEXP (x, 0);
11195       /* Avoid (%rip) for call operands.  */
11196       if (CONSTANT_ADDRESS_P (x) && code == 'P'
11197           && !CONST_INT_P (x))
11198         output_addr_const (file, x);
11199       else if (this_is_asm_operands && ! address_operand (x, VOIDmode))
11200         output_operand_lossage ("invalid constraints for operand");
11201       else
11202         output_address (x);
11203     }
11204
11205   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
11206     {
11207       REAL_VALUE_TYPE r;
11208       long l;
11209
11210       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
11211       REAL_VALUE_TO_TARGET_SINGLE (r, l);
11212
11213       if (ASSEMBLER_DIALECT == ASM_ATT)
11214         putc ('$', file);
11215       fprintf (file, "0x%08lx", (long unsigned int) l);
11216     }
11217
11218   /* These float cases don't actually occur as immediate operands.  */
11219   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
11220     {
11221       char dstr[30];
11222
11223       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
11224       fprintf (file, "%s", dstr);
11225     }
11226
11227   else if (GET_CODE (x) == CONST_DOUBLE
11228            && GET_MODE (x) == XFmode)
11229     {
11230       char dstr[30];
11231
11232       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
11233       fprintf (file, "%s", dstr);
11234     }
11235
11236   else
11237     {
11238       /* We have patterns that allow zero sets of memory, for instance.
11239          In 64-bit mode, we should probably support all 8-byte vectors,
11240          since we can in fact encode that into an immediate.  */
11241       if (GET_CODE (x) == CONST_VECTOR)
11242         {
11243           gcc_assert (x == CONST0_RTX (GET_MODE (x)));
11244           x = const0_rtx;
11245         }
11246
11247       if (code != 'P')
11248         {
11249           if (CONST_INT_P (x) || GET_CODE (x) == CONST_DOUBLE)
11250             {
11251               if (ASSEMBLER_DIALECT == ASM_ATT)
11252                 putc ('$', file);
11253             }
11254           else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF
11255                    || GET_CODE (x) == LABEL_REF)
11256             {
11257               if (ASSEMBLER_DIALECT == ASM_ATT)
11258                 putc ('$', file);
11259               else
11260                 fputs ("OFFSET FLAT:", file);
11261             }
11262         }
11263       if (CONST_INT_P (x))
11264         fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
11265       else if (flag_pic)
11266         output_pic_addr_const (file, x, code);
11267       else
11268         output_addr_const (file, x);
11269     }
11270 }
11271 \f
11272 /* Print a memory operand whose address is ADDR.  */
11273
11274 void
11275 print_operand_address (FILE *file, rtx addr)
11276 {
11277   struct ix86_address parts;
11278   rtx base, index, disp;
11279   int scale;
11280   int ok = ix86_decompose_address (addr, &parts);
11281
11282   gcc_assert (ok);
11283
11284   base = parts.base;
11285   index = parts.index;
11286   disp = parts.disp;
11287   scale = parts.scale;
11288
11289   switch (parts.seg)
11290     {
11291     case SEG_DEFAULT:
11292       break;
11293     case SEG_FS:
11294     case SEG_GS:
11295       if (ASSEMBLER_DIALECT == ASM_ATT)
11296         putc ('%', file);
11297       fputs ((parts.seg == SEG_FS ? "fs:" : "gs:"), file);
11298       break;
11299     default:
11300       gcc_unreachable ();
11301     }
11302
11303   /* Use one byte shorter RIP relative addressing for 64bit mode.  */
11304   if (TARGET_64BIT && !base && !index)
11305     {
11306       rtx symbol = disp;
11307
11308       if (GET_CODE (disp) == CONST
11309           && GET_CODE (XEXP (disp, 0)) == PLUS
11310           && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
11311         symbol = XEXP (XEXP (disp, 0), 0);
11312
11313       if (GET_CODE (symbol) == LABEL_REF
11314           || (GET_CODE (symbol) == SYMBOL_REF
11315               && SYMBOL_REF_TLS_MODEL (symbol) == 0))
11316         base = pc_rtx;
11317     }
11318   if (!base && !index)
11319     {
11320       /* Displacement only requires special attention.  */
11321
11322       if (CONST_INT_P (disp))
11323         {
11324           if (ASSEMBLER_DIALECT == ASM_INTEL && parts.seg == SEG_DEFAULT)
11325             fputs ("ds:", file);
11326           fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (disp));
11327         }
11328       else if (flag_pic)
11329         output_pic_addr_const (file, disp, 0);
11330       else
11331         output_addr_const (file, disp);
11332     }
11333   else
11334     {
11335       if (ASSEMBLER_DIALECT == ASM_ATT)
11336         {
11337           if (disp)
11338             {
11339               if (flag_pic)
11340                 output_pic_addr_const (file, disp, 0);
11341               else if (GET_CODE (disp) == LABEL_REF)
11342                 output_asm_label (disp);
11343               else
11344                 output_addr_const (file, disp);
11345             }
11346
11347           putc ('(', file);
11348           if (base)
11349             print_reg (base, 0, file);
11350           if (index)
11351             {
11352               putc (',', file);
11353               print_reg (index, 0, file);
11354               if (scale != 1)
11355                 fprintf (file, ",%d", scale);
11356             }
11357           putc (')', file);
11358         }
11359       else
11360         {
11361           rtx offset = NULL_RTX;
11362
11363           if (disp)
11364             {
11365               /* Pull out the offset of a symbol; print any symbol itself.  */
11366               if (GET_CODE (disp) == CONST
11367                   && GET_CODE (XEXP (disp, 0)) == PLUS
11368                   && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
11369                 {
11370                   offset = XEXP (XEXP (disp, 0), 1);
11371                   disp = gen_rtx_CONST (VOIDmode,
11372                                         XEXP (XEXP (disp, 0), 0));
11373                 }
11374
11375               if (flag_pic)
11376                 output_pic_addr_const (file, disp, 0);
11377               else if (GET_CODE (disp) == LABEL_REF)
11378                 output_asm_label (disp);
11379               else if (CONST_INT_P (disp))
11380                 offset = disp;
11381               else
11382                 output_addr_const (file, disp);
11383             }
11384
11385           putc ('[', file);
11386           if (base)
11387             {
11388               print_reg (base, 0, file);
11389               if (offset)
11390                 {
11391                   if (INTVAL (offset) >= 0)
11392                     putc ('+', file);
11393                   fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
11394                 }
11395             }
11396           else if (offset)
11397             fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
11398           else
11399             putc ('0', file);
11400
11401           if (index)
11402             {
11403               putc ('+', file);
11404               print_reg (index, 0, file);
11405               if (scale != 1)
11406                 fprintf (file, "*%d", scale);
11407             }
11408           putc (']', file);
11409         }
11410     }
11411 }
11412
11413 bool
11414 output_addr_const_extra (FILE *file, rtx x)
11415 {
11416   rtx op;
11417
11418   if (GET_CODE (x) != UNSPEC)
11419     return false;
11420
11421   op = XVECEXP (x, 0, 0);
11422   switch (XINT (x, 1))
11423     {
11424     case UNSPEC_GOTTPOFF:
11425       output_addr_const (file, op);
11426       /* FIXME: This might be @TPOFF in Sun ld.  */
11427       fputs ("@GOTTPOFF", file);
11428       break;
11429     case UNSPEC_TPOFF:
11430       output_addr_const (file, op);
11431       fputs ("@TPOFF", file);
11432       break;
11433     case UNSPEC_NTPOFF:
11434       output_addr_const (file, op);
11435       if (TARGET_64BIT)
11436         fputs ("@TPOFF", file);
11437       else
11438         fputs ("@NTPOFF", file);
11439       break;
11440     case UNSPEC_DTPOFF:
11441       output_addr_const (file, op);
11442       fputs ("@DTPOFF", file);
11443       break;
11444     case UNSPEC_GOTNTPOFF:
11445       output_addr_const (file, op);
11446       if (TARGET_64BIT)
11447         fputs (ASSEMBLER_DIALECT == ASM_ATT ?
11448                "@GOTTPOFF(%rip)" : "@GOTTPOFF[rip]", file);
11449       else
11450         fputs ("@GOTNTPOFF", file);
11451       break;
11452     case UNSPEC_INDNTPOFF:
11453       output_addr_const (file, op);
11454       fputs ("@INDNTPOFF", file);
11455       break;
11456 #if TARGET_MACHO
11457     case UNSPEC_MACHOPIC_OFFSET:
11458       output_addr_const (file, op);
11459       putc ('-', file);
11460       machopic_output_function_base_name (file);
11461       break;
11462 #endif
11463
11464     default:
11465       return false;
11466     }
11467
11468   return true;
11469 }
11470 \f
11471 /* Split one or more DImode RTL references into pairs of SImode
11472    references.  The RTL can be REG, offsettable MEM, integer constant, or
11473    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
11474    split and "num" is its length.  lo_half and hi_half are output arrays
11475    that parallel "operands".  */
11476
11477 void
11478 split_di (rtx operands[], int num, rtx lo_half[], rtx hi_half[])
11479 {
11480   while (num--)
11481     {
11482       rtx op = operands[num];
11483
11484       /* simplify_subreg refuse to split volatile memory addresses,
11485          but we still have to handle it.  */
11486       if (MEM_P (op))
11487         {
11488           lo_half[num] = adjust_address (op, SImode, 0);
11489           hi_half[num] = adjust_address (op, SImode, 4);
11490         }
11491       else
11492         {
11493           lo_half[num] = simplify_gen_subreg (SImode, op,
11494                                               GET_MODE (op) == VOIDmode
11495                                               ? DImode : GET_MODE (op), 0);
11496           hi_half[num] = simplify_gen_subreg (SImode, op,
11497                                               GET_MODE (op) == VOIDmode
11498                                               ? DImode : GET_MODE (op), 4);
11499         }
11500     }
11501 }
11502 /* Split one or more TImode RTL references into pairs of DImode
11503    references.  The RTL can be REG, offsettable MEM, integer constant, or
11504    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
11505    split and "num" is its length.  lo_half and hi_half are output arrays
11506    that parallel "operands".  */
11507
11508 void
11509 split_ti (rtx operands[], int num, rtx lo_half[], rtx hi_half[])
11510 {
11511   while (num--)
11512     {
11513       rtx op = operands[num];
11514
11515       /* simplify_subreg refuse to split volatile memory addresses, but we
11516          still have to handle it.  */
11517       if (MEM_P (op))
11518         {
11519           lo_half[num] = adjust_address (op, DImode, 0);
11520           hi_half[num] = adjust_address (op, DImode, 8);
11521         }
11522       else
11523         {
11524           lo_half[num] = simplify_gen_subreg (DImode, op, TImode, 0);
11525           hi_half[num] = simplify_gen_subreg (DImode, op, TImode, 8);
11526         }
11527     }
11528 }
11529 \f
11530 /* Output code to perform a 387 binary operation in INSN, one of PLUS,
11531    MINUS, MULT or DIV.  OPERANDS are the insn operands, where operands[3]
11532    is the expression of the binary operation.  The output may either be
11533    emitted here, or returned to the caller, like all output_* functions.
11534
11535    There is no guarantee that the operands are the same mode, as they
11536    might be within FLOAT or FLOAT_EXTEND expressions.  */
11537
11538 #ifndef SYSV386_COMPAT
11539 /* Set to 1 for compatibility with brain-damaged assemblers.  No-one
11540    wants to fix the assemblers because that causes incompatibility
11541    with gcc.  No-one wants to fix gcc because that causes
11542    incompatibility with assemblers...  You can use the option of
11543    -DSYSV386_COMPAT=0 if you recompile both gcc and gas this way.  */
11544 #define SYSV386_COMPAT 1
11545 #endif
11546
11547 const char *
11548 output_387_binary_op (rtx insn, rtx *operands)
11549 {
11550   static char buf[40];
11551   const char *p;
11552   const char *ssep;
11553   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]) || SSE_REG_P (operands[2]);
11554
11555 #ifdef ENABLE_CHECKING
11556   /* Even if we do not want to check the inputs, this documents input
11557      constraints.  Which helps in understanding the following code.  */
11558   if (STACK_REG_P (operands[0])
11559       && ((REG_P (operands[1])
11560            && REGNO (operands[0]) == REGNO (operands[1])
11561            && (STACK_REG_P (operands[2]) || MEM_P (operands[2])))
11562           || (REG_P (operands[2])
11563               && REGNO (operands[0]) == REGNO (operands[2])
11564               && (STACK_REG_P (operands[1]) || MEM_P (operands[1]))))
11565       && (STACK_TOP_P (operands[1]) || STACK_TOP_P (operands[2])))
11566     ; /* ok */
11567   else
11568     gcc_assert (is_sse);
11569 #endif
11570
11571   switch (GET_CODE (operands[3]))
11572     {
11573     case PLUS:
11574       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11575           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11576         p = "fiadd";
11577       else
11578         p = "fadd";
11579       ssep = "vadd";
11580       break;
11581
11582     case MINUS:
11583       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11584           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11585         p = "fisub";
11586       else
11587         p = "fsub";
11588       ssep = "vsub";
11589       break;
11590
11591     case MULT:
11592       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11593           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11594         p = "fimul";
11595       else
11596         p = "fmul";
11597       ssep = "vmul";
11598       break;
11599
11600     case DIV:
11601       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
11602           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
11603         p = "fidiv";
11604       else
11605         p = "fdiv";
11606       ssep = "vdiv";
11607       break;
11608
11609     default:
11610       gcc_unreachable ();
11611     }
11612
11613   if (is_sse)
11614    {
11615      if (TARGET_AVX)
11616        {
11617          strcpy (buf, ssep);
11618          if (GET_MODE (operands[0]) == SFmode)
11619            strcat (buf, "ss\t{%2, %1, %0|%0, %1, %2}");
11620          else
11621            strcat (buf, "sd\t{%2, %1, %0|%0, %1, %2}");
11622        }
11623      else
11624        {
11625          strcpy (buf, ssep + 1);
11626          if (GET_MODE (operands[0]) == SFmode)
11627            strcat (buf, "ss\t{%2, %0|%0, %2}");
11628          else
11629            strcat (buf, "sd\t{%2, %0|%0, %2}");
11630        }
11631       return buf;
11632    }
11633   strcpy (buf, p);
11634
11635   switch (GET_CODE (operands[3]))
11636     {
11637     case MULT:
11638     case PLUS:
11639       if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2]))
11640         {
11641           rtx temp = operands[2];
11642           operands[2] = operands[1];
11643           operands[1] = temp;
11644         }
11645
11646       /* know operands[0] == operands[1].  */
11647
11648       if (MEM_P (operands[2]))
11649         {
11650           p = "%z2\t%2";
11651           break;
11652         }
11653
11654       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
11655         {
11656           if (STACK_TOP_P (operands[0]))
11657             /* How is it that we are storing to a dead operand[2]?
11658                Well, presumably operands[1] is dead too.  We can't
11659                store the result to st(0) as st(0) gets popped on this
11660                instruction.  Instead store to operands[2] (which I
11661                think has to be st(1)).  st(1) will be popped later.
11662                gcc <= 2.8.1 didn't have this check and generated
11663                assembly code that the Unixware assembler rejected.  */
11664             p = "p\t{%0, %2|%2, %0}";   /* st(1) = st(0) op st(1); pop */
11665           else
11666             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
11667           break;
11668         }
11669
11670       if (STACK_TOP_P (operands[0]))
11671         p = "\t{%y2, %0|%0, %y2}";      /* st(0) = st(0) op st(r2) */
11672       else
11673         p = "\t{%2, %0|%0, %2}";        /* st(r1) = st(r1) op st(0) */
11674       break;
11675
11676     case MINUS:
11677     case DIV:
11678       if (MEM_P (operands[1]))
11679         {
11680           p = "r%z1\t%1";
11681           break;
11682         }
11683
11684       if (MEM_P (operands[2]))
11685         {
11686           p = "%z2\t%2";
11687           break;
11688         }
11689
11690       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
11691         {
11692 #if SYSV386_COMPAT
11693           /* The SystemV/386 SVR3.2 assembler, and probably all AT&T
11694              derived assemblers, confusingly reverse the direction of
11695              the operation for fsub{r} and fdiv{r} when the
11696              destination register is not st(0).  The Intel assembler
11697              doesn't have this brain damage.  Read !SYSV386_COMPAT to
11698              figure out what the hardware really does.  */
11699           if (STACK_TOP_P (operands[0]))
11700             p = "{p\t%0, %2|rp\t%2, %0}";
11701           else
11702             p = "{rp\t%2, %0|p\t%0, %2}";
11703 #else
11704           if (STACK_TOP_P (operands[0]))
11705             /* As above for fmul/fadd, we can't store to st(0).  */
11706             p = "rp\t{%0, %2|%2, %0}";  /* st(1) = st(0) op st(1); pop */
11707           else
11708             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
11709 #endif
11710           break;
11711         }
11712
11713       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
11714         {
11715 #if SYSV386_COMPAT
11716           if (STACK_TOP_P (operands[0]))
11717             p = "{rp\t%0, %1|p\t%1, %0}";
11718           else
11719             p = "{p\t%1, %0|rp\t%0, %1}";
11720 #else
11721           if (STACK_TOP_P (operands[0]))
11722             p = "p\t{%0, %1|%1, %0}";   /* st(1) = st(1) op st(0); pop */
11723           else
11724             p = "rp\t{%1, %0|%0, %1}";  /* st(r2) = st(0) op st(r2); pop */
11725 #endif
11726           break;
11727         }
11728
11729       if (STACK_TOP_P (operands[0]))
11730         {
11731           if (STACK_TOP_P (operands[1]))
11732             p = "\t{%y2, %0|%0, %y2}";  /* st(0) = st(0) op st(r2) */
11733           else
11734             p = "r\t{%y1, %0|%0, %y1}"; /* st(0) = st(r1) op st(0) */
11735           break;
11736         }
11737       else if (STACK_TOP_P (operands[1]))
11738         {
11739 #if SYSV386_COMPAT
11740           p = "{\t%1, %0|r\t%0, %1}";
11741 #else
11742           p = "r\t{%1, %0|%0, %1}";     /* st(r2) = st(0) op st(r2) */
11743 #endif
11744         }
11745       else
11746         {
11747 #if SYSV386_COMPAT
11748           p = "{r\t%2, %0|\t%0, %2}";
11749 #else
11750           p = "\t{%2, %0|%0, %2}";      /* st(r1) = st(r1) op st(0) */
11751 #endif
11752         }
11753       break;
11754
11755     default:
11756       gcc_unreachable ();
11757     }
11758
11759   strcat (buf, p);
11760   return buf;
11761 }
11762
11763 /* Return needed mode for entity in optimize_mode_switching pass.  */
11764
11765 int
11766 ix86_mode_needed (int entity, rtx insn)
11767 {
11768   enum attr_i387_cw mode;
11769
11770   /* The mode UNINITIALIZED is used to store control word after a
11771      function call or ASM pattern.  The mode ANY specify that function
11772      has no requirements on the control word and make no changes in the
11773      bits we are interested in.  */
11774
11775   if (CALL_P (insn)
11776       || (NONJUMP_INSN_P (insn)
11777           && (asm_noperands (PATTERN (insn)) >= 0
11778               || GET_CODE (PATTERN (insn)) == ASM_INPUT)))
11779     return I387_CW_UNINITIALIZED;
11780
11781   if (recog_memoized (insn) < 0)
11782     return I387_CW_ANY;
11783
11784   mode = get_attr_i387_cw (insn);
11785
11786   switch (entity)
11787     {
11788     case I387_TRUNC:
11789       if (mode == I387_CW_TRUNC)
11790         return mode;
11791       break;
11792
11793     case I387_FLOOR:
11794       if (mode == I387_CW_FLOOR)
11795         return mode;
11796       break;
11797
11798     case I387_CEIL:
11799       if (mode == I387_CW_CEIL)
11800         return mode;
11801       break;
11802
11803     case I387_MASK_PM:
11804       if (mode == I387_CW_MASK_PM)
11805         return mode;
11806       break;
11807
11808     default:
11809       gcc_unreachable ();
11810     }
11811
11812   return I387_CW_ANY;
11813 }
11814
11815 /* Output code to initialize control word copies used by trunc?f?i and
11816    rounding patterns.  CURRENT_MODE is set to current control word,
11817    while NEW_MODE is set to new control word.  */
11818
11819 void
11820 emit_i387_cw_initialization (int mode)
11821 {
11822   rtx stored_mode = assign_386_stack_local (HImode, SLOT_CW_STORED);
11823   rtx new_mode;
11824
11825   enum ix86_stack_slot slot;
11826
11827   rtx reg = gen_reg_rtx (HImode);
11828
11829   emit_insn (gen_x86_fnstcw_1 (stored_mode));
11830   emit_move_insn (reg, copy_rtx (stored_mode));
11831
11832   if (TARGET_64BIT || TARGET_PARTIAL_REG_STALL
11833       || optimize_function_for_size_p (cfun))
11834     {
11835       switch (mode)
11836         {
11837         case I387_CW_TRUNC:
11838           /* round toward zero (truncate) */
11839           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0c00)));
11840           slot = SLOT_CW_TRUNC;
11841           break;
11842
11843         case I387_CW_FLOOR:
11844           /* round down toward -oo */
11845           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
11846           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0400)));
11847           slot = SLOT_CW_FLOOR;
11848           break;
11849
11850         case I387_CW_CEIL:
11851           /* round up toward +oo */
11852           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
11853           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0800)));
11854           slot = SLOT_CW_CEIL;
11855           break;
11856
11857         case I387_CW_MASK_PM:
11858           /* mask precision exception for nearbyint() */
11859           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
11860           slot = SLOT_CW_MASK_PM;
11861           break;
11862
11863         default:
11864           gcc_unreachable ();
11865         }
11866     }
11867   else
11868     {
11869       switch (mode)
11870         {
11871         case I387_CW_TRUNC:
11872           /* round toward zero (truncate) */
11873           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0xc)));
11874           slot = SLOT_CW_TRUNC;
11875           break;
11876
11877         case I387_CW_FLOOR:
11878           /* round down toward -oo */
11879           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x4)));
11880           slot = SLOT_CW_FLOOR;
11881           break;
11882
11883         case I387_CW_CEIL:
11884           /* round up toward +oo */
11885           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x8)));
11886           slot = SLOT_CW_CEIL;
11887           break;
11888
11889         case I387_CW_MASK_PM:
11890           /* mask precision exception for nearbyint() */
11891           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
11892           slot = SLOT_CW_MASK_PM;
11893           break;
11894
11895         default:
11896           gcc_unreachable ();
11897         }
11898     }
11899
11900   gcc_assert (slot < MAX_386_STACK_LOCALS);
11901
11902   new_mode = assign_386_stack_local (HImode, slot);
11903   emit_move_insn (new_mode, reg);
11904 }
11905
11906 /* Output code for INSN to convert a float to a signed int.  OPERANDS
11907    are the insn operands.  The output may be [HSD]Imode and the input
11908    operand may be [SDX]Fmode.  */
11909
11910 const char *
11911 output_fix_trunc (rtx insn, rtx *operands, int fisttp)
11912 {
11913   int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
11914   int dimode_p = GET_MODE (operands[0]) == DImode;
11915   int round_mode = get_attr_i387_cw (insn);
11916
11917   /* Jump through a hoop or two for DImode, since the hardware has no
11918      non-popping instruction.  We used to do this a different way, but
11919      that was somewhat fragile and broke with post-reload splitters.  */
11920   if ((dimode_p || fisttp) && !stack_top_dies)
11921     output_asm_insn ("fld\t%y1", operands);
11922
11923   gcc_assert (STACK_TOP_P (operands[1]));
11924   gcc_assert (MEM_P (operands[0]));
11925   gcc_assert (GET_MODE (operands[1]) != TFmode);
11926
11927   if (fisttp)
11928       output_asm_insn ("fisttp%z0\t%0", operands);
11929   else
11930     {
11931       if (round_mode != I387_CW_ANY)
11932         output_asm_insn ("fldcw\t%3", operands);
11933       if (stack_top_dies || dimode_p)
11934         output_asm_insn ("fistp%z0\t%0", operands);
11935       else
11936         output_asm_insn ("fist%z0\t%0", operands);
11937       if (round_mode != I387_CW_ANY)
11938         output_asm_insn ("fldcw\t%2", operands);
11939     }
11940
11941   return "";
11942 }
11943
11944 /* Output code for x87 ffreep insn.  The OPNO argument, which may only
11945    have the values zero or one, indicates the ffreep insn's operand
11946    from the OPERANDS array.  */
11947
11948 static const char *
11949 output_387_ffreep (rtx *operands ATTRIBUTE_UNUSED, int opno)
11950 {
11951   if (TARGET_USE_FFREEP)
11952 #if HAVE_AS_IX86_FFREEP
11953     return opno ? "ffreep\t%y1" : "ffreep\t%y0";
11954 #else
11955     {
11956       static char retval[] = ".word\t0xc_df";
11957       int regno = REGNO (operands[opno]);
11958
11959       gcc_assert (FP_REGNO_P (regno));
11960
11961       retval[9] = '0' + (regno - FIRST_STACK_REG);
11962       return retval;
11963     }
11964 #endif
11965
11966   return opno ? "fstp\t%y1" : "fstp\t%y0";
11967 }
11968
11969
11970 /* Output code for INSN to compare OPERANDS.  EFLAGS_P is 1 when fcomi
11971    should be used.  UNORDERED_P is true when fucom should be used.  */
11972
11973 const char *
11974 output_fp_compare (rtx insn, rtx *operands, int eflags_p, int unordered_p)
11975 {
11976   int stack_top_dies;
11977   rtx cmp_op0, cmp_op1;
11978   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]);
11979
11980   if (eflags_p)
11981     {
11982       cmp_op0 = operands[0];
11983       cmp_op1 = operands[1];
11984     }
11985   else
11986     {
11987       cmp_op0 = operands[1];
11988       cmp_op1 = operands[2];
11989     }
11990
11991   if (is_sse)
11992     {
11993       static const char ucomiss[] = "vucomiss\t{%1, %0|%0, %1}";
11994       static const char ucomisd[] = "vucomisd\t{%1, %0|%0, %1}";
11995       static const char comiss[] = "vcomiss\t{%1, %0|%0, %1}";
11996       static const char comisd[] = "vcomisd\t{%1, %0|%0, %1}";
11997
11998       if (GET_MODE (operands[0]) == SFmode)
11999         if (unordered_p)
12000           return &ucomiss[TARGET_AVX ? 0 : 1];
12001         else
12002           return &comiss[TARGET_AVX ? 0 : 1];
12003       else
12004         if (unordered_p)
12005           return &ucomisd[TARGET_AVX ? 0 : 1];
12006         else
12007           return &comisd[TARGET_AVX ? 0 : 1];
12008     }
12009
12010   gcc_assert (STACK_TOP_P (cmp_op0));
12011
12012   stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
12013
12014   if (cmp_op1 == CONST0_RTX (GET_MODE (cmp_op1)))
12015     {
12016       if (stack_top_dies)
12017         {
12018           output_asm_insn ("ftst\n\tfnstsw\t%0", operands);
12019           return output_387_ffreep (operands, 1);
12020         }
12021       else
12022         return "ftst\n\tfnstsw\t%0";
12023     }
12024
12025   if (STACK_REG_P (cmp_op1)
12026       && stack_top_dies
12027       && find_regno_note (insn, REG_DEAD, REGNO (cmp_op1))
12028       && REGNO (cmp_op1) != FIRST_STACK_REG)
12029     {
12030       /* If both the top of the 387 stack dies, and the other operand
12031          is also a stack register that dies, then this must be a
12032          `fcompp' float compare */
12033
12034       if (eflags_p)
12035         {
12036           /* There is no double popping fcomi variant.  Fortunately,
12037              eflags is immune from the fstp's cc clobbering.  */
12038           if (unordered_p)
12039             output_asm_insn ("fucomip\t{%y1, %0|%0, %y1}", operands);
12040           else
12041             output_asm_insn ("fcomip\t{%y1, %0|%0, %y1}", operands);
12042           return output_387_ffreep (operands, 0);
12043         }
12044       else
12045         {
12046           if (unordered_p)
12047             return "fucompp\n\tfnstsw\t%0";
12048           else
12049             return "fcompp\n\tfnstsw\t%0";
12050         }
12051     }
12052   else
12053     {
12054       /* Encoded here as eflags_p | intmode | unordered_p | stack_top_dies.  */
12055
12056       static const char * const alt[16] =
12057       {
12058         "fcom%z2\t%y2\n\tfnstsw\t%0",
12059         "fcomp%z2\t%y2\n\tfnstsw\t%0",
12060         "fucom%z2\t%y2\n\tfnstsw\t%0",
12061         "fucomp%z2\t%y2\n\tfnstsw\t%0",
12062
12063         "ficom%z2\t%y2\n\tfnstsw\t%0",
12064         "ficomp%z2\t%y2\n\tfnstsw\t%0",
12065         NULL,
12066         NULL,
12067
12068         "fcomi\t{%y1, %0|%0, %y1}",
12069         "fcomip\t{%y1, %0|%0, %y1}",
12070         "fucomi\t{%y1, %0|%0, %y1}",
12071         "fucomip\t{%y1, %0|%0, %y1}",
12072
12073         NULL,
12074         NULL,
12075         NULL,
12076         NULL
12077       };
12078
12079       int mask;
12080       const char *ret;
12081
12082       mask  = eflags_p << 3;
12083       mask |= (GET_MODE_CLASS (GET_MODE (cmp_op1)) == MODE_INT) << 2;
12084       mask |= unordered_p << 1;
12085       mask |= stack_top_dies;
12086
12087       gcc_assert (mask < 16);
12088       ret = alt[mask];
12089       gcc_assert (ret);
12090
12091       return ret;
12092     }
12093 }
12094
12095 void
12096 ix86_output_addr_vec_elt (FILE *file, int value)
12097 {
12098   const char *directive = ASM_LONG;
12099
12100 #ifdef ASM_QUAD
12101   if (TARGET_64BIT)
12102     directive = ASM_QUAD;
12103 #else
12104   gcc_assert (!TARGET_64BIT);
12105 #endif
12106
12107   fprintf (file, "%s%s%d\n", directive, LPREFIX, value);
12108 }
12109
12110 void
12111 ix86_output_addr_diff_elt (FILE *file, int value, int rel)
12112 {
12113   const char *directive = ASM_LONG;
12114
12115 #ifdef ASM_QUAD
12116   if (TARGET_64BIT && CASE_VECTOR_MODE == DImode)
12117     directive = ASM_QUAD;
12118 #else
12119   gcc_assert (!TARGET_64BIT);
12120 #endif
12121   /* We can't use @GOTOFF for text labels on VxWorks; see gotoff_operand.  */
12122   if (TARGET_64BIT || TARGET_VXWORKS_RTP)
12123     fprintf (file, "%s%s%d-%s%d\n",
12124              directive, LPREFIX, value, LPREFIX, rel);
12125   else if (HAVE_AS_GOTOFF_IN_DATA)
12126     fprintf (file, "%s%s%d@GOTOFF\n", ASM_LONG, LPREFIX, value);
12127 #if TARGET_MACHO
12128   else if (TARGET_MACHO)
12129     {
12130       fprintf (file, "%s%s%d-", ASM_LONG, LPREFIX, value);
12131       machopic_output_function_base_name (file);
12132       fprintf(file, "\n");
12133     }
12134 #endif
12135   else
12136     asm_fprintf (file, "%s%U%s+[.-%s%d]\n",
12137                  ASM_LONG, GOT_SYMBOL_NAME, LPREFIX, value);
12138 }
12139 \f
12140 /* Generate either "mov $0, reg" or "xor reg, reg", as appropriate
12141    for the target.  */
12142
12143 void
12144 ix86_expand_clear (rtx dest)
12145 {
12146   rtx tmp;
12147
12148   /* We play register width games, which are only valid after reload.  */
12149   gcc_assert (reload_completed);
12150
12151   /* Avoid HImode and its attendant prefix byte.  */
12152   if (GET_MODE_SIZE (GET_MODE (dest)) < 4)
12153     dest = gen_rtx_REG (SImode, REGNO (dest));
12154   tmp = gen_rtx_SET (VOIDmode, dest, const0_rtx);
12155
12156   /* This predicate should match that for movsi_xor and movdi_xor_rex64.  */
12157   if (reload_completed && (!TARGET_USE_MOV0 || optimize_insn_for_speed_p ()))
12158     {
12159       rtx clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12160       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob));
12161     }
12162
12163   emit_insn (tmp);
12164 }
12165
12166 /* X is an unchanging MEM.  If it is a constant pool reference, return
12167    the constant pool rtx, else NULL.  */
12168
12169 rtx
12170 maybe_get_pool_constant (rtx x)
12171 {
12172   x = ix86_delegitimize_address (XEXP (x, 0));
12173
12174   if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x))
12175     return get_pool_constant (x);
12176
12177   return NULL_RTX;
12178 }
12179
12180 void
12181 ix86_expand_move (enum machine_mode mode, rtx operands[])
12182 {
12183   rtx op0, op1;
12184   enum tls_model model;
12185
12186   op0 = operands[0];
12187   op1 = operands[1];
12188
12189   if (GET_CODE (op1) == SYMBOL_REF)
12190     {
12191       model = SYMBOL_REF_TLS_MODEL (op1);
12192       if (model)
12193         {
12194           op1 = legitimize_tls_address (op1, model, true);
12195           op1 = force_operand (op1, op0);
12196           if (op1 == op0)
12197             return;
12198         }
12199       else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
12200                && SYMBOL_REF_DLLIMPORT_P (op1))
12201         op1 = legitimize_dllimport_symbol (op1, false);
12202     }
12203   else if (GET_CODE (op1) == CONST
12204            && GET_CODE (XEXP (op1, 0)) == PLUS
12205            && GET_CODE (XEXP (XEXP (op1, 0), 0)) == SYMBOL_REF)
12206     {
12207       rtx addend = XEXP (XEXP (op1, 0), 1);
12208       rtx symbol = XEXP (XEXP (op1, 0), 0);
12209       rtx tmp = NULL;
12210
12211       model = SYMBOL_REF_TLS_MODEL (symbol);
12212       if (model)
12213         tmp = legitimize_tls_address (symbol, model, true);
12214       else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
12215                && SYMBOL_REF_DLLIMPORT_P (symbol))
12216         tmp = legitimize_dllimport_symbol (symbol, true);
12217
12218       if (tmp)
12219         {
12220           tmp = force_operand (tmp, NULL);
12221           tmp = expand_simple_binop (Pmode, PLUS, tmp, addend,
12222                                      op0, 1, OPTAB_DIRECT);
12223           if (tmp == op0)
12224             return;
12225         }
12226     }
12227
12228   if (flag_pic && mode == Pmode && symbolic_operand (op1, Pmode))
12229     {
12230       if (TARGET_MACHO && !TARGET_64BIT)
12231         {
12232 #if TARGET_MACHO
12233           if (MACHOPIC_PURE)
12234             {
12235               rtx temp = ((reload_in_progress
12236                            || ((op0 && REG_P (op0))
12237                                && mode == Pmode))
12238                           ? op0 : gen_reg_rtx (Pmode));
12239               op1 = machopic_indirect_data_reference (op1, temp);
12240               op1 = machopic_legitimize_pic_address (op1, mode,
12241                                                      temp == op1 ? 0 : temp);
12242             }
12243           else if (MACHOPIC_INDIRECT)
12244             op1 = machopic_indirect_data_reference (op1, 0);
12245           if (op0 == op1)
12246             return;
12247 #endif
12248         }
12249       else
12250         {
12251           if (MEM_P (op0))
12252             op1 = force_reg (Pmode, op1);
12253           else if (!TARGET_64BIT || !x86_64_movabs_operand (op1, Pmode))
12254             {
12255               rtx reg = !can_create_pseudo_p () ? op0 : NULL_RTX;
12256               op1 = legitimize_pic_address (op1, reg);
12257               if (op0 == op1)
12258                 return;
12259             }
12260         }
12261     }
12262   else
12263     {
12264       if (MEM_P (op0)
12265           && (PUSH_ROUNDING (GET_MODE_SIZE (mode)) != GET_MODE_SIZE (mode)
12266               || !push_operand (op0, mode))
12267           && MEM_P (op1))
12268         op1 = force_reg (mode, op1);
12269
12270       if (push_operand (op0, mode)
12271           && ! general_no_elim_operand (op1, mode))
12272         op1 = copy_to_mode_reg (mode, op1);
12273
12274       /* Force large constants in 64bit compilation into register
12275          to get them CSEed.  */
12276       if (can_create_pseudo_p ()
12277           && (mode == DImode) && TARGET_64BIT
12278           && immediate_operand (op1, mode)
12279           && !x86_64_zext_immediate_operand (op1, VOIDmode)
12280           && !register_operand (op0, mode)
12281           && optimize)
12282         op1 = copy_to_mode_reg (mode, op1);
12283
12284       if (can_create_pseudo_p ()
12285           && FLOAT_MODE_P (mode)
12286           && GET_CODE (op1) == CONST_DOUBLE)
12287         {
12288           /* If we are loading a floating point constant to a register,
12289              force the value to memory now, since we'll get better code
12290              out the back end.  */
12291
12292           op1 = validize_mem (force_const_mem (mode, op1));
12293           if (!register_operand (op0, mode))
12294             {
12295               rtx temp = gen_reg_rtx (mode);
12296               emit_insn (gen_rtx_SET (VOIDmode, temp, op1));
12297               emit_move_insn (op0, temp);
12298               return;
12299             }
12300         }
12301     }
12302
12303   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
12304 }
12305
12306 void
12307 ix86_expand_vector_move (enum machine_mode mode, rtx operands[])
12308 {
12309   rtx op0 = operands[0], op1 = operands[1];
12310   unsigned int align = GET_MODE_ALIGNMENT (mode);
12311
12312   /* Force constants other than zero into memory.  We do not know how
12313      the instructions used to build constants modify the upper 64 bits
12314      of the register, once we have that information we may be able
12315      to handle some of them more efficiently.  */
12316   if (can_create_pseudo_p ()
12317       && register_operand (op0, mode)
12318       && (CONSTANT_P (op1)
12319           || (GET_CODE (op1) == SUBREG
12320               && CONSTANT_P (SUBREG_REG (op1))))
12321       && standard_sse_constant_p (op1) <= 0)
12322     op1 = validize_mem (force_const_mem (mode, op1));
12323
12324   /* We need to check memory alignment for SSE mode since attribute
12325      can make operands unaligned.  */
12326   if (can_create_pseudo_p ()
12327       && SSE_REG_MODE_P (mode)
12328       && ((MEM_P (op0) && (MEM_ALIGN (op0) < align))
12329           || (MEM_P (op1) && (MEM_ALIGN (op1) < align))))
12330     {
12331       rtx tmp[2];
12332
12333       /* ix86_expand_vector_move_misalign() does not like constants ... */
12334       if (CONSTANT_P (op1)
12335           || (GET_CODE (op1) == SUBREG
12336               && CONSTANT_P (SUBREG_REG (op1))))
12337         op1 = validize_mem (force_const_mem (mode, op1));
12338
12339       /* ... nor both arguments in memory.  */
12340       if (!register_operand (op0, mode)
12341           && !register_operand (op1, mode))
12342         op1 = force_reg (mode, op1);
12343
12344       tmp[0] = op0; tmp[1] = op1;
12345       ix86_expand_vector_move_misalign (mode, tmp);
12346       return;
12347     }
12348
12349   /* Make operand1 a register if it isn't already.  */
12350   if (can_create_pseudo_p ()
12351       && !register_operand (op0, mode)
12352       && !register_operand (op1, mode))
12353     {
12354       emit_move_insn (op0, force_reg (GET_MODE (op0), op1));
12355       return;
12356     }
12357
12358   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
12359 }
12360
12361 /* Implement the movmisalign patterns for SSE.  Non-SSE modes go
12362    straight to ix86_expand_vector_move.  */
12363 /* Code generation for scalar reg-reg moves of single and double precision data:
12364      if (x86_sse_partial_reg_dependency == true | x86_sse_split_regs == true)
12365        movaps reg, reg
12366      else
12367        movss reg, reg
12368      if (x86_sse_partial_reg_dependency == true)
12369        movapd reg, reg
12370      else
12371        movsd reg, reg
12372
12373    Code generation for scalar loads of double precision data:
12374      if (x86_sse_split_regs == true)
12375        movlpd mem, reg      (gas syntax)
12376      else
12377        movsd mem, reg
12378
12379    Code generation for unaligned packed loads of single precision data
12380    (x86_sse_unaligned_move_optimal overrides x86_sse_partial_reg_dependency):
12381      if (x86_sse_unaligned_move_optimal)
12382        movups mem, reg
12383
12384      if (x86_sse_partial_reg_dependency == true)
12385        {
12386          xorps  reg, reg
12387          movlps mem, reg
12388          movhps mem+8, reg
12389        }
12390      else
12391        {
12392          movlps mem, reg
12393          movhps mem+8, reg
12394        }
12395
12396    Code generation for unaligned packed loads of double precision data
12397    (x86_sse_unaligned_move_optimal overrides x86_sse_split_regs):
12398      if (x86_sse_unaligned_move_optimal)
12399        movupd mem, reg
12400
12401      if (x86_sse_split_regs == true)
12402        {
12403          movlpd mem, reg
12404          movhpd mem+8, reg
12405        }
12406      else
12407        {
12408          movsd  mem, reg
12409          movhpd mem+8, reg
12410        }
12411  */
12412
12413 void
12414 ix86_expand_vector_move_misalign (enum machine_mode mode, rtx operands[])
12415 {
12416   rtx op0, op1, m;
12417
12418   op0 = operands[0];
12419   op1 = operands[1];
12420
12421   if (TARGET_AVX)
12422     {
12423       switch (GET_MODE_CLASS (mode))
12424         {
12425         case MODE_VECTOR_INT:
12426         case MODE_INT:
12427           switch (GET_MODE_SIZE (mode))
12428             {
12429             case 16:
12430               op0 = gen_lowpart (V16QImode, op0);
12431               op1 = gen_lowpart (V16QImode, op1);
12432               emit_insn (gen_avx_movdqu (op0, op1));
12433               break;
12434             case 32:
12435               op0 = gen_lowpart (V32QImode, op0);
12436               op1 = gen_lowpart (V32QImode, op1);
12437               emit_insn (gen_avx_movdqu256 (op0, op1));
12438               break;
12439             default:
12440               gcc_unreachable ();
12441             }
12442           break;
12443         case MODE_VECTOR_FLOAT:
12444           op0 = gen_lowpart (mode, op0);
12445           op1 = gen_lowpart (mode, op1);
12446
12447           switch (mode)
12448             { 
12449             case V4SFmode:
12450               emit_insn (gen_avx_movups (op0, op1));
12451               break;
12452             case V8SFmode:
12453               emit_insn (gen_avx_movups256 (op0, op1));
12454               break;
12455             case V2DFmode:
12456               emit_insn (gen_avx_movupd (op0, op1));
12457               break;
12458             case V4DFmode:
12459               emit_insn (gen_avx_movupd256 (op0, op1));
12460               break;
12461             default:
12462               gcc_unreachable ();
12463             }
12464           break;
12465
12466         default:
12467           gcc_unreachable ();
12468         }
12469
12470       return;
12471     }
12472
12473   if (MEM_P (op1))
12474     {
12475       /* If we're optimizing for size, movups is the smallest.  */
12476       if (optimize_insn_for_size_p ())
12477         {
12478           op0 = gen_lowpart (V4SFmode, op0);
12479           op1 = gen_lowpart (V4SFmode, op1);
12480           emit_insn (gen_sse_movups (op0, op1));
12481           return;
12482         }
12483
12484       /* ??? If we have typed data, then it would appear that using
12485          movdqu is the only way to get unaligned data loaded with
12486          integer type.  */
12487       if (TARGET_SSE2 && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
12488         {
12489           op0 = gen_lowpart (V16QImode, op0);
12490           op1 = gen_lowpart (V16QImode, op1);
12491           emit_insn (gen_sse2_movdqu (op0, op1));
12492           return;
12493         }
12494
12495       if (TARGET_SSE2 && mode == V2DFmode)
12496         {
12497           rtx zero;
12498
12499           if (TARGET_SSE_UNALIGNED_MOVE_OPTIMAL)
12500             {
12501               op0 = gen_lowpart (V2DFmode, op0);
12502               op1 = gen_lowpart (V2DFmode, op1);
12503               emit_insn (gen_sse2_movupd (op0, op1));
12504               return;
12505             }
12506
12507           /* When SSE registers are split into halves, we can avoid
12508              writing to the top half twice.  */
12509           if (TARGET_SSE_SPLIT_REGS)
12510             {
12511               emit_clobber (op0);
12512               zero = op0;
12513             }
12514           else
12515             {
12516               /* ??? Not sure about the best option for the Intel chips.
12517                  The following would seem to satisfy; the register is
12518                  entirely cleared, breaking the dependency chain.  We
12519                  then store to the upper half, with a dependency depth
12520                  of one.  A rumor has it that Intel recommends two movsd
12521                  followed by an unpacklpd, but this is unconfirmed.  And
12522                  given that the dependency depth of the unpacklpd would
12523                  still be one, I'm not sure why this would be better.  */
12524               zero = CONST0_RTX (V2DFmode);
12525             }
12526
12527           m = adjust_address (op1, DFmode, 0);
12528           emit_insn (gen_sse2_loadlpd (op0, zero, m));
12529           m = adjust_address (op1, DFmode, 8);
12530           emit_insn (gen_sse2_loadhpd (op0, op0, m));
12531         }
12532       else
12533         {
12534           if (TARGET_SSE_UNALIGNED_MOVE_OPTIMAL)
12535             {
12536               op0 = gen_lowpart (V4SFmode, op0);
12537               op1 = gen_lowpart (V4SFmode, op1);
12538               emit_insn (gen_sse_movups (op0, op1));
12539               return;
12540             }
12541
12542           if (TARGET_SSE_PARTIAL_REG_DEPENDENCY)
12543             emit_move_insn (op0, CONST0_RTX (mode));
12544           else
12545             emit_clobber (op0);
12546
12547           if (mode != V4SFmode)
12548             op0 = gen_lowpart (V4SFmode, op0);
12549           m = adjust_address (op1, V2SFmode, 0);
12550           emit_insn (gen_sse_loadlps (op0, op0, m));
12551           m = adjust_address (op1, V2SFmode, 8);
12552           emit_insn (gen_sse_loadhps (op0, op0, m));
12553         }
12554     }
12555   else if (MEM_P (op0))
12556     {
12557       /* If we're optimizing for size, movups is the smallest.  */
12558       if (optimize_insn_for_size_p ())
12559         {
12560           op0 = gen_lowpart (V4SFmode, op0);
12561           op1 = gen_lowpart (V4SFmode, op1);
12562           emit_insn (gen_sse_movups (op0, op1));
12563           return;
12564         }
12565
12566       /* ??? Similar to above, only less clear because of quote
12567          typeless stores unquote.  */
12568       if (TARGET_SSE2 && !TARGET_SSE_TYPELESS_STORES
12569           && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
12570         {
12571           op0 = gen_lowpart (V16QImode, op0);
12572           op1 = gen_lowpart (V16QImode, op1);
12573           emit_insn (gen_sse2_movdqu (op0, op1));
12574           return;
12575         }
12576
12577       if (TARGET_SSE2 && mode == V2DFmode)
12578         {
12579           m = adjust_address (op0, DFmode, 0);
12580           emit_insn (gen_sse2_storelpd (m, op1));
12581           m = adjust_address (op0, DFmode, 8);
12582           emit_insn (gen_sse2_storehpd (m, op1));
12583         }
12584       else
12585         {
12586           if (mode != V4SFmode)
12587             op1 = gen_lowpart (V4SFmode, op1);
12588           m = adjust_address (op0, V2SFmode, 0);
12589           emit_insn (gen_sse_storelps (m, op1));
12590           m = adjust_address (op0, V2SFmode, 8);
12591           emit_insn (gen_sse_storehps (m, op1));
12592         }
12593     }
12594   else
12595     gcc_unreachable ();
12596 }
12597
12598 /* Expand a push in MODE.  This is some mode for which we do not support
12599    proper push instructions, at least from the registers that we expect
12600    the value to live in.  */
12601
12602 void
12603 ix86_expand_push (enum machine_mode mode, rtx x)
12604 {
12605   rtx tmp;
12606
12607   tmp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
12608                              GEN_INT (-GET_MODE_SIZE (mode)),
12609                              stack_pointer_rtx, 1, OPTAB_DIRECT);
12610   if (tmp != stack_pointer_rtx)
12611     emit_move_insn (stack_pointer_rtx, tmp);
12612
12613   tmp = gen_rtx_MEM (mode, stack_pointer_rtx);
12614
12615   /* When we push an operand onto stack, it has to be aligned at least
12616      at the function argument boundary.  */
12617   set_mem_align (tmp,
12618                  ix86_function_arg_boundary (mode, NULL_TREE));
12619
12620   emit_move_insn (tmp, x);
12621 }
12622
12623 /* Helper function of ix86_fixup_binary_operands to canonicalize
12624    operand order.  Returns true if the operands should be swapped.  */
12625
12626 static bool
12627 ix86_swap_binary_operands_p (enum rtx_code code, enum machine_mode mode,
12628                              rtx operands[])
12629 {
12630   rtx dst = operands[0];
12631   rtx src1 = operands[1];
12632   rtx src2 = operands[2];
12633
12634   /* If the operation is not commutative, we can't do anything.  */
12635   if (GET_RTX_CLASS (code) != RTX_COMM_ARITH)
12636     return false;
12637
12638   /* Highest priority is that src1 should match dst.  */
12639   if (rtx_equal_p (dst, src1))
12640     return false;
12641   if (rtx_equal_p (dst, src2))
12642     return true;
12643
12644   /* Next highest priority is that immediate constants come second.  */
12645   if (immediate_operand (src2, mode))
12646     return false;
12647   if (immediate_operand (src1, mode))
12648     return true;
12649
12650   /* Lowest priority is that memory references should come second.  */
12651   if (MEM_P (src2))
12652     return false;
12653   if (MEM_P (src1))
12654     return true;
12655
12656   return false;
12657 }
12658
12659
12660 /* Fix up OPERANDS to satisfy ix86_binary_operator_ok.  Return the
12661    destination to use for the operation.  If different from the true
12662    destination in operands[0], a copy operation will be required.  */
12663
12664 rtx
12665 ix86_fixup_binary_operands (enum rtx_code code, enum machine_mode mode,
12666                             rtx operands[])
12667 {
12668   rtx dst = operands[0];
12669   rtx src1 = operands[1];
12670   rtx src2 = operands[2];
12671
12672   /* Canonicalize operand order.  */
12673   if (ix86_swap_binary_operands_p (code, mode, operands))
12674     {
12675       rtx temp;
12676
12677       /* It is invalid to swap operands of different modes.  */
12678       gcc_assert (GET_MODE (src1) == GET_MODE (src2));
12679
12680       temp = src1;
12681       src1 = src2;
12682       src2 = temp;
12683     }
12684
12685   /* Both source operands cannot be in memory.  */
12686   if (MEM_P (src1) && MEM_P (src2))
12687     {
12688       /* Optimization: Only read from memory once.  */
12689       if (rtx_equal_p (src1, src2))
12690         {
12691           src2 = force_reg (mode, src2);
12692           src1 = src2;
12693         }
12694       else
12695         src2 = force_reg (mode, src2);
12696     }
12697
12698   /* If the destination is memory, and we do not have matching source
12699      operands, do things in registers.  */
12700   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
12701     dst = gen_reg_rtx (mode);
12702
12703   /* Source 1 cannot be a constant.  */
12704   if (CONSTANT_P (src1))
12705     src1 = force_reg (mode, src1);
12706
12707   /* Source 1 cannot be a non-matching memory.  */
12708   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
12709     src1 = force_reg (mode, src1);
12710
12711   operands[1] = src1;
12712   operands[2] = src2;
12713   return dst;
12714 }
12715
12716 /* Similarly, but assume that the destination has already been
12717    set up properly.  */
12718
12719 void
12720 ix86_fixup_binary_operands_no_copy (enum rtx_code code,
12721                                     enum machine_mode mode, rtx operands[])
12722 {
12723   rtx dst = ix86_fixup_binary_operands (code, mode, operands);
12724   gcc_assert (dst == operands[0]);
12725 }
12726
12727 /* Attempt to expand a binary operator.  Make the expansion closer to the
12728    actual machine, then just general_operand, which will allow 3 separate
12729    memory references (one output, two input) in a single insn.  */
12730
12731 void
12732 ix86_expand_binary_operator (enum rtx_code code, enum machine_mode mode,
12733                              rtx operands[])
12734 {
12735   rtx src1, src2, dst, op, clob;
12736
12737   dst = ix86_fixup_binary_operands (code, mode, operands);
12738   src1 = operands[1];
12739   src2 = operands[2];
12740
12741  /* Emit the instruction.  */
12742
12743   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_ee (code, mode, src1, src2));
12744   if (reload_in_progress)
12745     {
12746       /* Reload doesn't know about the flags register, and doesn't know that
12747          it doesn't want to clobber it.  We can only do this with PLUS.  */
12748       gcc_assert (code == PLUS);
12749       emit_insn (op);
12750     }
12751   else
12752     {
12753       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12754       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
12755     }
12756
12757   /* Fix up the destination if needed.  */
12758   if (dst != operands[0])
12759     emit_move_insn (operands[0], dst);
12760 }
12761
12762 /* Return TRUE or FALSE depending on whether the binary operator meets the
12763    appropriate constraints.  */
12764
12765 int
12766 ix86_binary_operator_ok (enum rtx_code code, enum machine_mode mode,
12767                          rtx operands[3])
12768 {
12769   rtx dst = operands[0];
12770   rtx src1 = operands[1];
12771   rtx src2 = operands[2];
12772
12773   /* Both source operands cannot be in memory.  */
12774   if (MEM_P (src1) && MEM_P (src2))
12775     return 0;
12776
12777   /* Canonicalize operand order for commutative operators.  */
12778   if (ix86_swap_binary_operands_p (code, mode, operands))
12779     {
12780       rtx temp = src1;
12781       src1 = src2;
12782       src2 = temp;
12783     }
12784
12785   /* If the destination is memory, we must have a matching source operand.  */
12786   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
12787       return 0;
12788
12789   /* Source 1 cannot be a constant.  */
12790   if (CONSTANT_P (src1))
12791     return 0;
12792
12793   /* Source 1 cannot be a non-matching memory.  */
12794   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
12795     return 0;
12796
12797   return 1;
12798 }
12799
12800 /* Attempt to expand a unary operator.  Make the expansion closer to the
12801    actual machine, then just general_operand, which will allow 2 separate
12802    memory references (one output, one input) in a single insn.  */
12803
12804 void
12805 ix86_expand_unary_operator (enum rtx_code code, enum machine_mode mode,
12806                             rtx operands[])
12807 {
12808   int matching_memory;
12809   rtx src, dst, op, clob;
12810
12811   dst = operands[0];
12812   src = operands[1];
12813
12814   /* If the destination is memory, and we do not have matching source
12815      operands, do things in registers.  */
12816   matching_memory = 0;
12817   if (MEM_P (dst))
12818     {
12819       if (rtx_equal_p (dst, src))
12820         matching_memory = 1;
12821       else
12822         dst = gen_reg_rtx (mode);
12823     }
12824
12825   /* When source operand is memory, destination must match.  */
12826   if (MEM_P (src) && !matching_memory)
12827     src = force_reg (mode, src);
12828
12829   /* Emit the instruction.  */
12830
12831   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_e (code, mode, src));
12832   if (reload_in_progress || code == NOT)
12833     {
12834       /* Reload doesn't know about the flags register, and doesn't know that
12835          it doesn't want to clobber it.  */
12836       gcc_assert (code == NOT);
12837       emit_insn (op);
12838     }
12839   else
12840     {
12841       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
12842       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
12843     }
12844
12845   /* Fix up the destination if needed.  */
12846   if (dst != operands[0])
12847     emit_move_insn (operands[0], dst);
12848 }
12849
12850 /* Return TRUE or FALSE depending on whether the unary operator meets the
12851    appropriate constraints.  */
12852
12853 int
12854 ix86_unary_operator_ok (enum rtx_code code ATTRIBUTE_UNUSED,
12855                         enum machine_mode mode ATTRIBUTE_UNUSED,
12856                         rtx operands[2] ATTRIBUTE_UNUSED)
12857 {
12858   /* If one of operands is memory, source and destination must match.  */
12859   if ((MEM_P (operands[0])
12860        || MEM_P (operands[1]))
12861       && ! rtx_equal_p (operands[0], operands[1]))
12862     return FALSE;
12863   return TRUE;
12864 }
12865
12866 /* Post-reload splitter for converting an SF or DFmode value in an
12867    SSE register into an unsigned SImode.  */
12868
12869 void
12870 ix86_split_convert_uns_si_sse (rtx operands[])
12871 {
12872   enum machine_mode vecmode;
12873   rtx value, large, zero_or_two31, input, two31, x;
12874
12875   large = operands[1];
12876   zero_or_two31 = operands[2];
12877   input = operands[3];
12878   two31 = operands[4];
12879   vecmode = GET_MODE (large);
12880   value = gen_rtx_REG (vecmode, REGNO (operands[0]));
12881
12882   /* Load up the value into the low element.  We must ensure that the other
12883      elements are valid floats -- zero is the easiest such value.  */
12884   if (MEM_P (input))
12885     {
12886       if (vecmode == V4SFmode)
12887         emit_insn (gen_vec_setv4sf_0 (value, CONST0_RTX (V4SFmode), input));
12888       else
12889         emit_insn (gen_sse2_loadlpd (value, CONST0_RTX (V2DFmode), input));
12890     }
12891   else
12892     {
12893       input = gen_rtx_REG (vecmode, REGNO (input));
12894       emit_move_insn (value, CONST0_RTX (vecmode));
12895       if (vecmode == V4SFmode)
12896         emit_insn (gen_sse_movss (value, value, input));
12897       else
12898         emit_insn (gen_sse2_movsd (value, value, input));
12899     }
12900
12901   emit_move_insn (large, two31);
12902   emit_move_insn (zero_or_two31, MEM_P (two31) ? large : two31);
12903
12904   x = gen_rtx_fmt_ee (LE, vecmode, large, value);
12905   emit_insn (gen_rtx_SET (VOIDmode, large, x));
12906
12907   x = gen_rtx_AND (vecmode, zero_or_two31, large);
12908   emit_insn (gen_rtx_SET (VOIDmode, zero_or_two31, x));
12909
12910   x = gen_rtx_MINUS (vecmode, value, zero_or_two31);
12911   emit_insn (gen_rtx_SET (VOIDmode, value, x));
12912
12913   large = gen_rtx_REG (V4SImode, REGNO (large));
12914   emit_insn (gen_ashlv4si3 (large, large, GEN_INT (31)));
12915
12916   x = gen_rtx_REG (V4SImode, REGNO (value));
12917   if (vecmode == V4SFmode)
12918     emit_insn (gen_sse2_cvttps2dq (x, value));
12919   else
12920     emit_insn (gen_sse2_cvttpd2dq (x, value));
12921   value = x;
12922
12923   emit_insn (gen_xorv4si3 (value, value, large));
12924 }
12925
12926 /* Convert an unsigned DImode value into a DFmode, using only SSE.
12927    Expects the 64-bit DImode to be supplied in a pair of integral
12928    registers.  Requires SSE2; will use SSE3 if available.  For x86_32,
12929    -mfpmath=sse, !optimize_size only.  */
12930
12931 void
12932 ix86_expand_convert_uns_didf_sse (rtx target, rtx input)
12933 {
12934   REAL_VALUE_TYPE bias_lo_rvt, bias_hi_rvt;
12935   rtx int_xmm, fp_xmm;
12936   rtx biases, exponents;
12937   rtx x;
12938
12939   int_xmm = gen_reg_rtx (V4SImode);
12940   if (TARGET_INTER_UNIT_MOVES)
12941     emit_insn (gen_movdi_to_sse (int_xmm, input));
12942   else if (TARGET_SSE_SPLIT_REGS)
12943     {
12944       emit_clobber (int_xmm);
12945       emit_move_insn (gen_lowpart (DImode, int_xmm), input);
12946     }
12947   else
12948     {
12949       x = gen_reg_rtx (V2DImode);
12950       ix86_expand_vector_init_one_nonzero (false, V2DImode, x, input, 0);
12951       emit_move_insn (int_xmm, gen_lowpart (V4SImode, x));
12952     }
12953
12954   x = gen_rtx_CONST_VECTOR (V4SImode,
12955                             gen_rtvec (4, GEN_INT (0x43300000UL),
12956                                        GEN_INT (0x45300000UL),
12957                                        const0_rtx, const0_rtx));
12958   exponents = validize_mem (force_const_mem (V4SImode, x));
12959
12960   /* int_xmm = {0x45300000UL, fp_xmm/hi, 0x43300000, fp_xmm/lo } */
12961   emit_insn (gen_sse2_punpckldq (int_xmm, int_xmm, exponents));
12962
12963   /* Concatenating (juxtaposing) (0x43300000UL ## fp_value_low_xmm)
12964      yields a valid DF value equal to (0x1.0p52 + double(fp_value_lo_xmm)).
12965      Similarly (0x45300000UL ## fp_value_hi_xmm) yields
12966      (0x1.0p84 + double(fp_value_hi_xmm)).
12967      Note these exponents differ by 32.  */
12968
12969   fp_xmm = copy_to_mode_reg (V2DFmode, gen_lowpart (V2DFmode, int_xmm));
12970
12971   /* Subtract off those 0x1.0p52 and 0x1.0p84 biases, to produce values
12972      in [0,2**32-1] and [0]+[2**32,2**64-1] respectively.  */
12973   real_ldexp (&bias_lo_rvt, &dconst1, 52);
12974   real_ldexp (&bias_hi_rvt, &dconst1, 84);
12975   biases = const_double_from_real_value (bias_lo_rvt, DFmode);
12976   x = const_double_from_real_value (bias_hi_rvt, DFmode);
12977   biases = gen_rtx_CONST_VECTOR (V2DFmode, gen_rtvec (2, biases, x));
12978   biases = validize_mem (force_const_mem (V2DFmode, biases));
12979   emit_insn (gen_subv2df3 (fp_xmm, fp_xmm, biases));
12980
12981   /* Add the upper and lower DFmode values together.  */
12982   if (TARGET_SSE3)
12983     emit_insn (gen_sse3_haddv2df3 (fp_xmm, fp_xmm, fp_xmm));
12984   else
12985     {
12986       x = copy_to_mode_reg (V2DFmode, fp_xmm);
12987       emit_insn (gen_sse2_unpckhpd (fp_xmm, fp_xmm, fp_xmm));
12988       emit_insn (gen_addv2df3 (fp_xmm, fp_xmm, x));
12989     }
12990
12991   ix86_expand_vector_extract (false, target, fp_xmm, 0);
12992 }
12993
12994 /* Not used, but eases macroization of patterns.  */
12995 void
12996 ix86_expand_convert_uns_sixf_sse (rtx target ATTRIBUTE_UNUSED,
12997                                   rtx input ATTRIBUTE_UNUSED)
12998 {
12999   gcc_unreachable ();
13000 }
13001
13002 /* Convert an unsigned SImode value into a DFmode.  Only currently used
13003    for SSE, but applicable anywhere.  */
13004
13005 void
13006 ix86_expand_convert_uns_sidf_sse (rtx target, rtx input)
13007 {
13008   REAL_VALUE_TYPE TWO31r;
13009   rtx x, fp;
13010
13011   x = expand_simple_binop (SImode, PLUS, input, GEN_INT (-2147483647 - 1),
13012                            NULL, 1, OPTAB_DIRECT);
13013
13014   fp = gen_reg_rtx (DFmode);
13015   emit_insn (gen_floatsidf2 (fp, x));
13016
13017   real_ldexp (&TWO31r, &dconst1, 31);
13018   x = const_double_from_real_value (TWO31r, DFmode);
13019
13020   x = expand_simple_binop (DFmode, PLUS, fp, x, target, 0, OPTAB_DIRECT);
13021   if (x != target)
13022     emit_move_insn (target, x);
13023 }
13024
13025 /* Convert a signed DImode value into a DFmode.  Only used for SSE in
13026    32-bit mode; otherwise we have a direct convert instruction.  */
13027
13028 void
13029 ix86_expand_convert_sign_didf_sse (rtx target, rtx input)
13030 {
13031   REAL_VALUE_TYPE TWO32r;
13032   rtx fp_lo, fp_hi, x;
13033
13034   fp_lo = gen_reg_rtx (DFmode);
13035   fp_hi = gen_reg_rtx (DFmode);
13036
13037   emit_insn (gen_floatsidf2 (fp_hi, gen_highpart (SImode, input)));
13038
13039   real_ldexp (&TWO32r, &dconst1, 32);
13040   x = const_double_from_real_value (TWO32r, DFmode);
13041   fp_hi = expand_simple_binop (DFmode, MULT, fp_hi, x, fp_hi, 0, OPTAB_DIRECT);
13042
13043   ix86_expand_convert_uns_sidf_sse (fp_lo, gen_lowpart (SImode, input));
13044
13045   x = expand_simple_binop (DFmode, PLUS, fp_hi, fp_lo, target,
13046                            0, OPTAB_DIRECT);
13047   if (x != target)
13048     emit_move_insn (target, x);
13049 }
13050
13051 /* Convert an unsigned SImode value into a SFmode, using only SSE.
13052    For x86_32, -mfpmath=sse, !optimize_size only.  */
13053 void
13054 ix86_expand_convert_uns_sisf_sse (rtx target, rtx input)
13055 {
13056   REAL_VALUE_TYPE ONE16r;
13057   rtx fp_hi, fp_lo, int_hi, int_lo, x;
13058
13059   real_ldexp (&ONE16r, &dconst1, 16);
13060   x = const_double_from_real_value (ONE16r, SFmode);
13061   int_lo = expand_simple_binop (SImode, AND, input, GEN_INT(0xffff),
13062                                       NULL, 0, OPTAB_DIRECT);
13063   int_hi = expand_simple_binop (SImode, LSHIFTRT, input, GEN_INT(16),
13064                                       NULL, 0, OPTAB_DIRECT);
13065   fp_hi = gen_reg_rtx (SFmode);
13066   fp_lo = gen_reg_rtx (SFmode);
13067   emit_insn (gen_floatsisf2 (fp_hi, int_hi));
13068   emit_insn (gen_floatsisf2 (fp_lo, int_lo));
13069   fp_hi = expand_simple_binop (SFmode, MULT, fp_hi, x, fp_hi,
13070                                0, OPTAB_DIRECT);
13071   fp_hi = expand_simple_binop (SFmode, PLUS, fp_hi, fp_lo, target,
13072                                0, OPTAB_DIRECT);
13073   if (!rtx_equal_p (target, fp_hi))
13074     emit_move_insn (target, fp_hi);
13075 }
13076
13077 /* A subroutine of ix86_build_signbit_mask_vector.  If VECT is true,
13078    then replicate the value for all elements of the vector
13079    register.  */
13080
13081 rtx
13082 ix86_build_const_vector (enum machine_mode mode, bool vect, rtx value)
13083 {
13084   rtvec v;
13085   switch (mode)
13086     {
13087     case SImode:
13088       gcc_assert (vect);
13089       v = gen_rtvec (4, value, value, value, value);
13090       return gen_rtx_CONST_VECTOR (V4SImode, v);
13091
13092     case DImode:
13093       gcc_assert (vect);
13094       v = gen_rtvec (2, value, value);
13095       return gen_rtx_CONST_VECTOR (V2DImode, v);
13096
13097     case SFmode:
13098       if (vect)
13099         v = gen_rtvec (4, value, value, value, value);
13100       else
13101         v = gen_rtvec (4, value, CONST0_RTX (SFmode),
13102                        CONST0_RTX (SFmode), CONST0_RTX (SFmode));
13103       return gen_rtx_CONST_VECTOR (V4SFmode, v);
13104
13105     case DFmode:
13106       if (vect)
13107         v = gen_rtvec (2, value, value);
13108       else
13109         v = gen_rtvec (2, value, CONST0_RTX (DFmode));
13110       return gen_rtx_CONST_VECTOR (V2DFmode, v);
13111
13112     default:
13113       gcc_unreachable ();
13114     }
13115 }
13116
13117 /* A subroutine of ix86_expand_fp_absneg_operator, copysign expanders
13118    and ix86_expand_int_vcond.  Create a mask for the sign bit in MODE
13119    for an SSE register.  If VECT is true, then replicate the mask for
13120    all elements of the vector register.  If INVERT is true, then create
13121    a mask excluding the sign bit.  */
13122
13123 rtx
13124 ix86_build_signbit_mask (enum machine_mode mode, bool vect, bool invert)
13125 {
13126   enum machine_mode vec_mode, imode;
13127   HOST_WIDE_INT hi, lo;
13128   int shift = 63;
13129   rtx v;
13130   rtx mask;
13131
13132   /* Find the sign bit, sign extended to 2*HWI.  */
13133   switch (mode)
13134     {
13135     case SImode:
13136     case SFmode:
13137       imode = SImode;
13138       vec_mode = (mode == SImode) ? V4SImode : V4SFmode;
13139       lo = 0x80000000, hi = lo < 0;
13140       break;
13141
13142     case DImode:
13143     case DFmode:
13144       imode = DImode;
13145       vec_mode = (mode == DImode) ? V2DImode : V2DFmode;
13146       if (HOST_BITS_PER_WIDE_INT >= 64)
13147         lo = (HOST_WIDE_INT)1 << shift, hi = -1;
13148       else
13149         lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
13150       break;
13151
13152     case TImode:
13153     case TFmode:
13154       vec_mode = VOIDmode;
13155       if (HOST_BITS_PER_WIDE_INT >= 64)
13156         {
13157           imode = TImode;
13158           lo = 0, hi = (HOST_WIDE_INT)1 << shift;
13159         }
13160       else
13161         {
13162           rtvec vec;
13163
13164           imode = DImode;
13165           lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
13166
13167           if (invert)
13168             {
13169               lo = ~lo, hi = ~hi;
13170               v = constm1_rtx;
13171             }
13172           else
13173             v = const0_rtx;
13174
13175           mask = immed_double_const (lo, hi, imode);
13176
13177           vec = gen_rtvec (2, v, mask);
13178           v = gen_rtx_CONST_VECTOR (V2DImode, vec);
13179           v = copy_to_mode_reg (mode, gen_lowpart (mode, v));
13180
13181           return v;
13182         }
13183      break;
13184
13185     default:
13186       gcc_unreachable ();
13187     }
13188
13189   if (invert)
13190     lo = ~lo, hi = ~hi;
13191
13192   /* Force this value into the low part of a fp vector constant.  */
13193   mask = immed_double_const (lo, hi, imode);
13194   mask = gen_lowpart (mode, mask);
13195
13196   if (vec_mode == VOIDmode)
13197     return force_reg (mode, mask);
13198
13199   v = ix86_build_const_vector (mode, vect, mask);
13200   return force_reg (vec_mode, v);
13201 }
13202
13203 /* Generate code for floating point ABS or NEG.  */
13204
13205 void
13206 ix86_expand_fp_absneg_operator (enum rtx_code code, enum machine_mode mode,
13207                                 rtx operands[])
13208 {
13209   rtx mask, set, use, clob, dst, src;
13210   bool use_sse = false;
13211   bool vector_mode = VECTOR_MODE_P (mode);
13212   enum machine_mode elt_mode = mode;
13213
13214   if (vector_mode)
13215     {
13216       elt_mode = GET_MODE_INNER (mode);
13217       use_sse = true;
13218     }
13219   else if (mode == TFmode)
13220     use_sse = true;
13221   else if (TARGET_SSE_MATH)
13222     use_sse = SSE_FLOAT_MODE_P (mode);
13223
13224   /* NEG and ABS performed with SSE use bitwise mask operations.
13225      Create the appropriate mask now.  */
13226   if (use_sse)
13227     mask = ix86_build_signbit_mask (elt_mode, vector_mode, code == ABS);
13228   else
13229     mask = NULL_RTX;
13230
13231   dst = operands[0];
13232   src = operands[1];
13233
13234   if (vector_mode)
13235     {
13236       set = gen_rtx_fmt_ee (code == NEG ? XOR : AND, mode, src, mask);
13237       set = gen_rtx_SET (VOIDmode, dst, set);
13238       emit_insn (set);
13239     }
13240   else
13241     {
13242       set = gen_rtx_fmt_e (code, mode, src);
13243       set = gen_rtx_SET (VOIDmode, dst, set);
13244       if (mask)
13245         {
13246           use = gen_rtx_USE (VOIDmode, mask);
13247           clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
13248           emit_insn (gen_rtx_PARALLEL (VOIDmode,
13249                                        gen_rtvec (3, set, use, clob)));
13250         }
13251       else
13252         emit_insn (set);
13253     }
13254 }
13255
13256 /* Expand a copysign operation.  Special case operand 0 being a constant.  */
13257
13258 void
13259 ix86_expand_copysign (rtx operands[])
13260 {
13261   enum machine_mode mode;
13262   rtx dest, op0, op1, mask, nmask;
13263
13264   dest = operands[0];
13265   op0 = operands[1];
13266   op1 = operands[2];
13267
13268   mode = GET_MODE (dest);
13269
13270   if (GET_CODE (op0) == CONST_DOUBLE)
13271     {
13272       rtx (*copysign_insn)(rtx, rtx, rtx, rtx);
13273
13274       if (real_isneg (CONST_DOUBLE_REAL_VALUE (op0)))
13275         op0 = simplify_unary_operation (ABS, mode, op0, mode);
13276
13277       if (mode == SFmode || mode == DFmode)
13278         {
13279           enum machine_mode vmode;
13280
13281           vmode = mode == SFmode ? V4SFmode : V2DFmode;
13282
13283           if (op0 == CONST0_RTX (mode))
13284             op0 = CONST0_RTX (vmode);
13285           else
13286             {
13287               rtvec v;
13288
13289               if (mode == SFmode)
13290                 v = gen_rtvec (4, op0, CONST0_RTX (SFmode),
13291                                CONST0_RTX (SFmode), CONST0_RTX (SFmode));
13292               else
13293                 v = gen_rtvec (2, op0, CONST0_RTX (DFmode));
13294
13295               op0 = force_reg (vmode, gen_rtx_CONST_VECTOR (vmode, v));
13296             }
13297         }
13298       else if (op0 != CONST0_RTX (mode))
13299         op0 = force_reg (mode, op0);
13300
13301       mask = ix86_build_signbit_mask (mode, 0, 0);
13302
13303       if (mode == SFmode)
13304         copysign_insn = gen_copysignsf3_const;
13305       else if (mode == DFmode)
13306         copysign_insn = gen_copysigndf3_const;
13307       else
13308         copysign_insn = gen_copysigntf3_const;
13309
13310         emit_insn (copysign_insn (dest, op0, op1, mask));
13311     }
13312   else
13313     {
13314       rtx (*copysign_insn)(rtx, rtx, rtx, rtx, rtx, rtx);
13315
13316       nmask = ix86_build_signbit_mask (mode, 0, 1);
13317       mask = ix86_build_signbit_mask (mode, 0, 0);
13318
13319       if (mode == SFmode)
13320         copysign_insn = gen_copysignsf3_var;
13321       else if (mode == DFmode)
13322         copysign_insn = gen_copysigndf3_var;
13323       else
13324         copysign_insn = gen_copysigntf3_var;
13325
13326       emit_insn (copysign_insn (dest, NULL_RTX, op0, op1, nmask, mask));
13327     }
13328 }
13329
13330 /* Deconstruct a copysign operation into bit masks.  Operand 0 is known to
13331    be a constant, and so has already been expanded into a vector constant.  */
13332
13333 void
13334 ix86_split_copysign_const (rtx operands[])
13335 {
13336   enum machine_mode mode, vmode;
13337   rtx dest, op0, op1, mask, x;
13338
13339   dest = operands[0];
13340   op0 = operands[1];
13341   op1 = operands[2];
13342   mask = operands[3];
13343
13344   mode = GET_MODE (dest);
13345   vmode = GET_MODE (mask);
13346
13347   dest = simplify_gen_subreg (vmode, dest, mode, 0);
13348   x = gen_rtx_AND (vmode, dest, mask);
13349   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13350
13351   if (op0 != CONST0_RTX (vmode))
13352     {
13353       x = gen_rtx_IOR (vmode, dest, op0);
13354       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13355     }
13356 }
13357
13358 /* Deconstruct a copysign operation into bit masks.  Operand 0 is variable,
13359    so we have to do two masks.  */
13360
13361 void
13362 ix86_split_copysign_var (rtx operands[])
13363 {
13364   enum machine_mode mode, vmode;
13365   rtx dest, scratch, op0, op1, mask, nmask, x;
13366
13367   dest = operands[0];
13368   scratch = operands[1];
13369   op0 = operands[2];
13370   op1 = operands[3];
13371   nmask = operands[4];
13372   mask = operands[5];
13373
13374   mode = GET_MODE (dest);
13375   vmode = GET_MODE (mask);
13376
13377   if (rtx_equal_p (op0, op1))
13378     {
13379       /* Shouldn't happen often (it's useless, obviously), but when it does
13380          we'd generate incorrect code if we continue below.  */
13381       emit_move_insn (dest, op0);
13382       return;
13383     }
13384
13385   if (REG_P (mask) && REGNO (dest) == REGNO (mask))     /* alternative 0 */
13386     {
13387       gcc_assert (REGNO (op1) == REGNO (scratch));
13388
13389       x = gen_rtx_AND (vmode, scratch, mask);
13390       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
13391
13392       dest = mask;
13393       op0 = simplify_gen_subreg (vmode, op0, mode, 0);
13394       x = gen_rtx_NOT (vmode, dest);
13395       x = gen_rtx_AND (vmode, x, op0);
13396       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13397     }
13398   else
13399     {
13400       if (REGNO (op1) == REGNO (scratch))               /* alternative 1,3 */
13401         {
13402           x = gen_rtx_AND (vmode, scratch, mask);
13403         }
13404       else                                              /* alternative 2,4 */
13405         {
13406           gcc_assert (REGNO (mask) == REGNO (scratch));
13407           op1 = simplify_gen_subreg (vmode, op1, mode, 0);
13408           x = gen_rtx_AND (vmode, scratch, op1);
13409         }
13410       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
13411
13412       if (REGNO (op0) == REGNO (dest))                  /* alternative 1,2 */
13413         {
13414           dest = simplify_gen_subreg (vmode, op0, mode, 0);
13415           x = gen_rtx_AND (vmode, dest, nmask);
13416         }
13417       else                                              /* alternative 3,4 */
13418         {
13419           gcc_assert (REGNO (nmask) == REGNO (dest));
13420           dest = nmask;
13421           op0 = simplify_gen_subreg (vmode, op0, mode, 0);
13422           x = gen_rtx_AND (vmode, dest, op0);
13423         }
13424       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13425     }
13426
13427   x = gen_rtx_IOR (vmode, dest, scratch);
13428   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
13429 }
13430
13431 /* Return TRUE or FALSE depending on whether the first SET in INSN
13432    has source and destination with matching CC modes, and that the
13433    CC mode is at least as constrained as REQ_MODE.  */
13434
13435 int
13436 ix86_match_ccmode (rtx insn, enum machine_mode req_mode)
13437 {
13438   rtx set;
13439   enum machine_mode set_mode;
13440
13441   set = PATTERN (insn);
13442   if (GET_CODE (set) == PARALLEL)
13443     set = XVECEXP (set, 0, 0);
13444   gcc_assert (GET_CODE (set) == SET);
13445   gcc_assert (GET_CODE (SET_SRC (set)) == COMPARE);
13446
13447   set_mode = GET_MODE (SET_DEST (set));
13448   switch (set_mode)
13449     {
13450     case CCNOmode:
13451       if (req_mode != CCNOmode
13452           && (req_mode != CCmode
13453               || XEXP (SET_SRC (set), 1) != const0_rtx))
13454         return 0;
13455       break;
13456     case CCmode:
13457       if (req_mode == CCGCmode)
13458         return 0;
13459       /* FALLTHRU */
13460     case CCGCmode:
13461       if (req_mode == CCGOCmode || req_mode == CCNOmode)
13462         return 0;
13463       /* FALLTHRU */
13464     case CCGOCmode:
13465       if (req_mode == CCZmode)
13466         return 0;
13467       /* FALLTHRU */
13468     case CCAmode:
13469     case CCCmode:
13470     case CCOmode:
13471     case CCSmode:
13472     case CCZmode:
13473       break;
13474
13475     default:
13476       gcc_unreachable ();
13477     }
13478
13479   return (GET_MODE (SET_SRC (set)) == set_mode);
13480 }
13481
13482 /* Generate insn patterns to do an integer compare of OPERANDS.  */
13483
13484 static rtx
13485 ix86_expand_int_compare (enum rtx_code code, rtx op0, rtx op1)
13486 {
13487   enum machine_mode cmpmode;
13488   rtx tmp, flags;
13489
13490   cmpmode = SELECT_CC_MODE (code, op0, op1);
13491   flags = gen_rtx_REG (cmpmode, FLAGS_REG);
13492
13493   /* This is very simple, but making the interface the same as in the
13494      FP case makes the rest of the code easier.  */
13495   tmp = gen_rtx_COMPARE (cmpmode, op0, op1);
13496   emit_insn (gen_rtx_SET (VOIDmode, flags, tmp));
13497
13498   /* Return the test that should be put into the flags user, i.e.
13499      the bcc, scc, or cmov instruction.  */
13500   return gen_rtx_fmt_ee (code, VOIDmode, flags, const0_rtx);
13501 }
13502
13503 /* Figure out whether to use ordered or unordered fp comparisons.
13504    Return the appropriate mode to use.  */
13505
13506 enum machine_mode
13507 ix86_fp_compare_mode (enum rtx_code code ATTRIBUTE_UNUSED)
13508 {
13509   /* ??? In order to make all comparisons reversible, we do all comparisons
13510      non-trapping when compiling for IEEE.  Once gcc is able to distinguish
13511      all forms trapping and nontrapping comparisons, we can make inequality
13512      comparisons trapping again, since it results in better code when using
13513      FCOM based compares.  */
13514   return TARGET_IEEE_FP ? CCFPUmode : CCFPmode;
13515 }
13516
13517 enum machine_mode
13518 ix86_cc_mode (enum rtx_code code, rtx op0, rtx op1)
13519 {
13520   enum machine_mode mode = GET_MODE (op0);
13521
13522   if (SCALAR_FLOAT_MODE_P (mode))
13523     {
13524       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
13525       return ix86_fp_compare_mode (code);
13526     }
13527
13528   switch (code)
13529     {
13530       /* Only zero flag is needed.  */
13531     case EQ:                    /* ZF=0 */
13532     case NE:                    /* ZF!=0 */
13533       return CCZmode;
13534       /* Codes needing carry flag.  */
13535     case GEU:                   /* CF=0 */
13536     case LTU:                   /* CF=1 */
13537       /* Detect overflow checks.  They need just the carry flag.  */
13538       if (GET_CODE (op0) == PLUS
13539           && rtx_equal_p (op1, XEXP (op0, 0)))
13540         return CCCmode;
13541       else
13542         return CCmode;
13543     case GTU:                   /* CF=0 & ZF=0 */
13544     case LEU:                   /* CF=1 | ZF=1 */
13545       /* Detect overflow checks.  They need just the carry flag.  */
13546       if (GET_CODE (op0) == MINUS
13547           && rtx_equal_p (op1, XEXP (op0, 0)))
13548         return CCCmode;
13549       else
13550         return CCmode;
13551       /* Codes possibly doable only with sign flag when
13552          comparing against zero.  */
13553     case GE:                    /* SF=OF   or   SF=0 */
13554     case LT:                    /* SF<>OF  or   SF=1 */
13555       if (op1 == const0_rtx)
13556         return CCGOCmode;
13557       else
13558         /* For other cases Carry flag is not required.  */
13559         return CCGCmode;
13560       /* Codes doable only with sign flag when comparing
13561          against zero, but we miss jump instruction for it
13562          so we need to use relational tests against overflow
13563          that thus needs to be zero.  */
13564     case GT:                    /* ZF=0 & SF=OF */
13565     case LE:                    /* ZF=1 | SF<>OF */
13566       if (op1 == const0_rtx)
13567         return CCNOmode;
13568       else
13569         return CCGCmode;
13570       /* strcmp pattern do (use flags) and combine may ask us for proper
13571          mode.  */
13572     case USE:
13573       return CCmode;
13574     default:
13575       gcc_unreachable ();
13576     }
13577 }
13578
13579 /* Return the fixed registers used for condition codes.  */
13580
13581 static bool
13582 ix86_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
13583 {
13584   *p1 = FLAGS_REG;
13585   *p2 = FPSR_REG;
13586   return true;
13587 }
13588
13589 /* If two condition code modes are compatible, return a condition code
13590    mode which is compatible with both.  Otherwise, return
13591    VOIDmode.  */
13592
13593 static enum machine_mode
13594 ix86_cc_modes_compatible (enum machine_mode m1, enum machine_mode m2)
13595 {
13596   if (m1 == m2)
13597     return m1;
13598
13599   if (GET_MODE_CLASS (m1) != MODE_CC || GET_MODE_CLASS (m2) != MODE_CC)
13600     return VOIDmode;
13601
13602   if ((m1 == CCGCmode && m2 == CCGOCmode)
13603       || (m1 == CCGOCmode && m2 == CCGCmode))
13604     return CCGCmode;
13605
13606   switch (m1)
13607     {
13608     default:
13609       gcc_unreachable ();
13610
13611     case CCmode:
13612     case CCGCmode:
13613     case CCGOCmode:
13614     case CCNOmode:
13615     case CCAmode:
13616     case CCCmode:
13617     case CCOmode:
13618     case CCSmode:
13619     case CCZmode:
13620       switch (m2)
13621         {
13622         default:
13623           return VOIDmode;
13624
13625         case CCmode:
13626         case CCGCmode:
13627         case CCGOCmode:
13628         case CCNOmode:
13629         case CCAmode:
13630         case CCCmode:
13631         case CCOmode:
13632         case CCSmode:
13633         case CCZmode:
13634           return CCmode;
13635         }
13636
13637     case CCFPmode:
13638     case CCFPUmode:
13639       /* These are only compatible with themselves, which we already
13640          checked above.  */
13641       return VOIDmode;
13642     }
13643 }
13644
13645 /* Split comparison code CODE into comparisons we can do using branch
13646    instructions.  BYPASS_CODE is comparison code for branch that will
13647    branch around FIRST_CODE and SECOND_CODE.  If some of branches
13648    is not required, set value to UNKNOWN.
13649    We never require more than two branches.  */
13650
13651 void
13652 ix86_fp_comparison_codes (enum rtx_code code, enum rtx_code *bypass_code,
13653                           enum rtx_code *first_code,
13654                           enum rtx_code *second_code)
13655 {
13656   *first_code = code;
13657   *bypass_code = UNKNOWN;
13658   *second_code = UNKNOWN;
13659
13660   /* The fcomi comparison sets flags as follows:
13661
13662      cmp    ZF PF CF
13663      >      0  0  0
13664      <      0  0  1
13665      =      1  0  0
13666      un     1  1  1 */
13667
13668   switch (code)
13669     {
13670     case GT:                    /* GTU - CF=0 & ZF=0 */
13671     case GE:                    /* GEU - CF=0 */
13672     case ORDERED:               /* PF=0 */
13673     case UNORDERED:             /* PF=1 */
13674     case UNEQ:                  /* EQ - ZF=1 */
13675     case UNLT:                  /* LTU - CF=1 */
13676     case UNLE:                  /* LEU - CF=1 | ZF=1 */
13677     case LTGT:                  /* EQ - ZF=0 */
13678       break;
13679     case LT:                    /* LTU - CF=1 - fails on unordered */
13680       *first_code = UNLT;
13681       *bypass_code = UNORDERED;
13682       break;
13683     case LE:                    /* LEU - CF=1 | ZF=1 - fails on unordered */
13684       *first_code = UNLE;
13685       *bypass_code = UNORDERED;
13686       break;
13687     case EQ:                    /* EQ - ZF=1 - fails on unordered */
13688       *first_code = UNEQ;
13689       *bypass_code = UNORDERED;
13690       break;
13691     case NE:                    /* NE - ZF=0 - fails on unordered */
13692       *first_code = LTGT;
13693       *second_code = UNORDERED;
13694       break;
13695     case UNGE:                  /* GEU - CF=0 - fails on unordered */
13696       *first_code = GE;
13697       *second_code = UNORDERED;
13698       break;
13699     case UNGT:                  /* GTU - CF=0 & ZF=0 - fails on unordered */
13700       *first_code = GT;
13701       *second_code = UNORDERED;
13702       break;
13703     default:
13704       gcc_unreachable ();
13705     }
13706   if (!TARGET_IEEE_FP)
13707     {
13708       *second_code = UNKNOWN;
13709       *bypass_code = UNKNOWN;
13710     }
13711 }
13712
13713 /* Return cost of comparison done fcom + arithmetics operations on AX.
13714    All following functions do use number of instructions as a cost metrics.
13715    In future this should be tweaked to compute bytes for optimize_size and
13716    take into account performance of various instructions on various CPUs.  */
13717 static int
13718 ix86_fp_comparison_arithmetics_cost (enum rtx_code code)
13719 {
13720   if (!TARGET_IEEE_FP)
13721     return 4;
13722   /* The cost of code output by ix86_expand_fp_compare.  */
13723   switch (code)
13724     {
13725     case UNLE:
13726     case UNLT:
13727     case LTGT:
13728     case GT:
13729     case GE:
13730     case UNORDERED:
13731     case ORDERED:
13732     case UNEQ:
13733       return 4;
13734       break;
13735     case LT:
13736     case NE:
13737     case EQ:
13738     case UNGE:
13739       return 5;
13740       break;
13741     case LE:
13742     case UNGT:
13743       return 6;
13744       break;
13745     default:
13746       gcc_unreachable ();
13747     }
13748 }
13749
13750 /* Return cost of comparison done using fcomi operation.
13751    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
13752 static int
13753 ix86_fp_comparison_fcomi_cost (enum rtx_code code)
13754 {
13755   enum rtx_code bypass_code, first_code, second_code;
13756   /* Return arbitrarily high cost when instruction is not supported - this
13757      prevents gcc from using it.  */
13758   if (!TARGET_CMOVE)
13759     return 1024;
13760   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13761   return (bypass_code != UNKNOWN || second_code != UNKNOWN) + 2;
13762 }
13763
13764 /* Return cost of comparison done using sahf operation.
13765    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
13766 static int
13767 ix86_fp_comparison_sahf_cost (enum rtx_code code)
13768 {
13769   enum rtx_code bypass_code, first_code, second_code;
13770   /* Return arbitrarily high cost when instruction is not preferred - this
13771      avoids gcc from using it.  */
13772   if (!(TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ())))
13773     return 1024;
13774   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13775   return (bypass_code != UNKNOWN || second_code != UNKNOWN) + 3;
13776 }
13777
13778 /* Compute cost of the comparison done using any method.
13779    See ix86_fp_comparison_arithmetics_cost for the metrics.  */
13780 static int
13781 ix86_fp_comparison_cost (enum rtx_code code)
13782 {
13783   int fcomi_cost, sahf_cost, arithmetics_cost = 1024;
13784   int min;
13785
13786   fcomi_cost = ix86_fp_comparison_fcomi_cost (code);
13787   sahf_cost = ix86_fp_comparison_sahf_cost (code);
13788
13789   min = arithmetics_cost = ix86_fp_comparison_arithmetics_cost (code);
13790   if (min > sahf_cost)
13791     min = sahf_cost;
13792   if (min > fcomi_cost)
13793     min = fcomi_cost;
13794   return min;
13795 }
13796
13797 /* Return true if we should use an FCOMI instruction for this
13798    fp comparison.  */
13799
13800 int
13801 ix86_use_fcomi_compare (enum rtx_code code ATTRIBUTE_UNUSED)
13802 {
13803   enum rtx_code swapped_code = swap_condition (code);
13804
13805   return ((ix86_fp_comparison_cost (code)
13806            == ix86_fp_comparison_fcomi_cost (code))
13807           || (ix86_fp_comparison_cost (swapped_code)
13808               == ix86_fp_comparison_fcomi_cost (swapped_code)));
13809 }
13810
13811 /* Swap, force into registers, or otherwise massage the two operands
13812    to a fp comparison.  The operands are updated in place; the new
13813    comparison code is returned.  */
13814
13815 static enum rtx_code
13816 ix86_prepare_fp_compare_args (enum rtx_code code, rtx *pop0, rtx *pop1)
13817 {
13818   enum machine_mode fpcmp_mode = ix86_fp_compare_mode (code);
13819   rtx op0 = *pop0, op1 = *pop1;
13820   enum machine_mode op_mode = GET_MODE (op0);
13821   int is_sse = TARGET_SSE_MATH && SSE_FLOAT_MODE_P (op_mode);
13822
13823   /* All of the unordered compare instructions only work on registers.
13824      The same is true of the fcomi compare instructions.  The XFmode
13825      compare instructions require registers except when comparing
13826      against zero or when converting operand 1 from fixed point to
13827      floating point.  */
13828
13829   if (!is_sse
13830       && (fpcmp_mode == CCFPUmode
13831           || (op_mode == XFmode
13832               && ! (standard_80387_constant_p (op0) == 1
13833                     || standard_80387_constant_p (op1) == 1)
13834               && GET_CODE (op1) != FLOAT)
13835           || ix86_use_fcomi_compare (code)))
13836     {
13837       op0 = force_reg (op_mode, op0);
13838       op1 = force_reg (op_mode, op1);
13839     }
13840   else
13841     {
13842       /* %%% We only allow op1 in memory; op0 must be st(0).  So swap
13843          things around if they appear profitable, otherwise force op0
13844          into a register.  */
13845
13846       if (standard_80387_constant_p (op0) == 0
13847           || (MEM_P (op0)
13848               && ! (standard_80387_constant_p (op1) == 0
13849                     || MEM_P (op1))))
13850         {
13851           rtx tmp;
13852           tmp = op0, op0 = op1, op1 = tmp;
13853           code = swap_condition (code);
13854         }
13855
13856       if (!REG_P (op0))
13857         op0 = force_reg (op_mode, op0);
13858
13859       if (CONSTANT_P (op1))
13860         {
13861           int tmp = standard_80387_constant_p (op1);
13862           if (tmp == 0)
13863             op1 = validize_mem (force_const_mem (op_mode, op1));
13864           else if (tmp == 1)
13865             {
13866               if (TARGET_CMOVE)
13867                 op1 = force_reg (op_mode, op1);
13868             }
13869           else
13870             op1 = force_reg (op_mode, op1);
13871         }
13872     }
13873
13874   /* Try to rearrange the comparison to make it cheaper.  */
13875   if (ix86_fp_comparison_cost (code)
13876       > ix86_fp_comparison_cost (swap_condition (code))
13877       && (REG_P (op1) || can_create_pseudo_p ()))
13878     {
13879       rtx tmp;
13880       tmp = op0, op0 = op1, op1 = tmp;
13881       code = swap_condition (code);
13882       if (!REG_P (op0))
13883         op0 = force_reg (op_mode, op0);
13884     }
13885
13886   *pop0 = op0;
13887   *pop1 = op1;
13888   return code;
13889 }
13890
13891 /* Convert comparison codes we use to represent FP comparison to integer
13892    code that will result in proper branch.  Return UNKNOWN if no such code
13893    is available.  */
13894
13895 enum rtx_code
13896 ix86_fp_compare_code_to_integer (enum rtx_code code)
13897 {
13898   switch (code)
13899     {
13900     case GT:
13901       return GTU;
13902     case GE:
13903       return GEU;
13904     case ORDERED:
13905     case UNORDERED:
13906       return code;
13907       break;
13908     case UNEQ:
13909       return EQ;
13910       break;
13911     case UNLT:
13912       return LTU;
13913       break;
13914     case UNLE:
13915       return LEU;
13916       break;
13917     case LTGT:
13918       return NE;
13919       break;
13920     default:
13921       return UNKNOWN;
13922     }
13923 }
13924
13925 /* Generate insn patterns to do a floating point compare of OPERANDS.  */
13926
13927 static rtx
13928 ix86_expand_fp_compare (enum rtx_code code, rtx op0, rtx op1, rtx scratch,
13929                         rtx *second_test, rtx *bypass_test)
13930 {
13931   enum machine_mode fpcmp_mode, intcmp_mode;
13932   rtx tmp, tmp2;
13933   int cost = ix86_fp_comparison_cost (code);
13934   enum rtx_code bypass_code, first_code, second_code;
13935
13936   fpcmp_mode = ix86_fp_compare_mode (code);
13937   code = ix86_prepare_fp_compare_args (code, &op0, &op1);
13938
13939   if (second_test)
13940     *second_test = NULL_RTX;
13941   if (bypass_test)
13942     *bypass_test = NULL_RTX;
13943
13944   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
13945
13946   /* Do fcomi/sahf based test when profitable.  */
13947   if (ix86_fp_comparison_arithmetics_cost (code) > cost
13948       && (bypass_code == UNKNOWN || bypass_test)
13949       && (second_code == UNKNOWN || second_test))
13950     {
13951       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
13952       tmp = gen_rtx_SET (VOIDmode, gen_rtx_REG (fpcmp_mode, FLAGS_REG),
13953                          tmp);
13954       if (TARGET_CMOVE)
13955         emit_insn (tmp);
13956       else
13957         {
13958           gcc_assert (TARGET_SAHF);
13959
13960           if (!scratch)
13961             scratch = gen_reg_rtx (HImode);
13962           tmp2 = gen_rtx_CLOBBER (VOIDmode, scratch);
13963
13964           emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, tmp2)));
13965         }
13966
13967       /* The FP codes work out to act like unsigned.  */
13968       intcmp_mode = fpcmp_mode;
13969       code = first_code;
13970       if (bypass_code != UNKNOWN)
13971         *bypass_test = gen_rtx_fmt_ee (bypass_code, VOIDmode,
13972                                        gen_rtx_REG (intcmp_mode, FLAGS_REG),
13973                                        const0_rtx);
13974       if (second_code != UNKNOWN)
13975         *second_test = gen_rtx_fmt_ee (second_code, VOIDmode,
13976                                        gen_rtx_REG (intcmp_mode, FLAGS_REG),
13977                                        const0_rtx);
13978     }
13979   else
13980     {
13981       /* Sadness wrt reg-stack pops killing fpsr -- gotta get fnstsw first.  */
13982       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
13983       tmp2 = gen_rtx_UNSPEC (HImode, gen_rtvec (1, tmp), UNSPEC_FNSTSW);
13984       if (!scratch)
13985         scratch = gen_reg_rtx (HImode);
13986       emit_insn (gen_rtx_SET (VOIDmode, scratch, tmp2));
13987
13988       /* In the unordered case, we have to check C2 for NaN's, which
13989          doesn't happen to work out to anything nice combination-wise.
13990          So do some bit twiddling on the value we've got in AH to come
13991          up with an appropriate set of condition codes.  */
13992
13993       intcmp_mode = CCNOmode;
13994       switch (code)
13995         {
13996         case GT:
13997         case UNGT:
13998           if (code == GT || !TARGET_IEEE_FP)
13999             {
14000               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
14001               code = EQ;
14002             }
14003           else
14004             {
14005               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
14006               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
14007               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x44)));
14008               intcmp_mode = CCmode;
14009               code = GEU;
14010             }
14011           break;
14012         case LT:
14013         case UNLT:
14014           if (code == LT && TARGET_IEEE_FP)
14015             {
14016               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
14017               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x01)));
14018               intcmp_mode = CCmode;
14019               code = EQ;
14020             }
14021           else
14022             {
14023               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x01)));
14024               code = NE;
14025             }
14026           break;
14027         case GE:
14028         case UNGE:
14029           if (code == GE || !TARGET_IEEE_FP)
14030             {
14031               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x05)));
14032               code = EQ;
14033             }
14034           else
14035             {
14036               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
14037               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch,
14038                                              GEN_INT (0x01)));
14039               code = NE;
14040             }
14041           break;
14042         case LE:
14043         case UNLE:
14044           if (code == LE && TARGET_IEEE_FP)
14045             {
14046               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
14047               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
14048               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
14049               intcmp_mode = CCmode;
14050               code = LTU;
14051             }
14052           else
14053             {
14054               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
14055               code = NE;
14056             }
14057           break;
14058         case EQ:
14059         case UNEQ:
14060           if (code == EQ && TARGET_IEEE_FP)
14061             {
14062               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
14063               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
14064               intcmp_mode = CCmode;
14065               code = EQ;
14066             }
14067           else
14068             {
14069               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
14070               code = NE;
14071               break;
14072             }
14073           break;
14074         case NE:
14075         case LTGT:
14076           if (code == NE && TARGET_IEEE_FP)
14077             {
14078               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
14079               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch,
14080                                              GEN_INT (0x40)));
14081               code = NE;
14082             }
14083           else
14084             {
14085               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
14086               code = EQ;
14087             }
14088           break;
14089
14090         case UNORDERED:
14091           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
14092           code = NE;
14093           break;
14094         case ORDERED:
14095           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
14096           code = EQ;
14097           break;
14098
14099         default:
14100           gcc_unreachable ();
14101         }
14102     }
14103
14104   /* Return the test that should be put into the flags user, i.e.
14105      the bcc, scc, or cmov instruction.  */
14106   return gen_rtx_fmt_ee (code, VOIDmode,
14107                          gen_rtx_REG (intcmp_mode, FLAGS_REG),
14108                          const0_rtx);
14109 }
14110
14111 rtx
14112 ix86_expand_compare (enum rtx_code code, rtx *second_test, rtx *bypass_test)
14113 {
14114   rtx op0, op1, ret;
14115   op0 = ix86_compare_op0;
14116   op1 = ix86_compare_op1;
14117
14118   if (second_test)
14119     *second_test = NULL_RTX;
14120   if (bypass_test)
14121     *bypass_test = NULL_RTX;
14122
14123   if (ix86_compare_emitted)
14124     {
14125       ret = gen_rtx_fmt_ee (code, VOIDmode, ix86_compare_emitted, const0_rtx);
14126       ix86_compare_emitted = NULL_RTX;
14127     }
14128   else if (SCALAR_FLOAT_MODE_P (GET_MODE (op0)))
14129     {
14130       gcc_assert (!DECIMAL_FLOAT_MODE_P (GET_MODE (op0)));
14131       ret = ix86_expand_fp_compare (code, op0, op1, NULL_RTX,
14132                                     second_test, bypass_test);
14133     }
14134   else
14135     ret = ix86_expand_int_compare (code, op0, op1);
14136
14137   return ret;
14138 }
14139
14140 /* Return true if the CODE will result in nontrivial jump sequence.  */
14141 bool
14142 ix86_fp_jump_nontrivial_p (enum rtx_code code)
14143 {
14144   enum rtx_code bypass_code, first_code, second_code;
14145   if (!TARGET_CMOVE)
14146     return true;
14147   ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
14148   return bypass_code != UNKNOWN || second_code != UNKNOWN;
14149 }
14150
14151 void
14152 ix86_expand_branch (enum rtx_code code, rtx label)
14153 {
14154   rtx tmp;
14155
14156   /* If we have emitted a compare insn, go straight to simple.
14157      ix86_expand_compare won't emit anything if ix86_compare_emitted
14158      is non NULL.  */
14159   if (ix86_compare_emitted)
14160     goto simple;
14161
14162   switch (GET_MODE (ix86_compare_op0))
14163     {
14164     case QImode:
14165     case HImode:
14166     case SImode:
14167       simple:
14168       tmp = ix86_expand_compare (code, NULL, NULL);
14169       tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
14170                                   gen_rtx_LABEL_REF (VOIDmode, label),
14171                                   pc_rtx);
14172       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
14173       return;
14174
14175     case SFmode:
14176     case DFmode:
14177     case XFmode:
14178       {
14179         rtvec vec;
14180         int use_fcomi;
14181         enum rtx_code bypass_code, first_code, second_code;
14182
14183         code = ix86_prepare_fp_compare_args (code, &ix86_compare_op0,
14184                                              &ix86_compare_op1);
14185
14186         ix86_fp_comparison_codes (code, &bypass_code, &first_code, &second_code);
14187
14188         /* Check whether we will use the natural sequence with one jump.  If
14189            so, we can expand jump early.  Otherwise delay expansion by
14190            creating compound insn to not confuse optimizers.  */
14191         if (bypass_code == UNKNOWN && second_code == UNKNOWN)
14192           {
14193             ix86_split_fp_branch (code, ix86_compare_op0, ix86_compare_op1,
14194                                   gen_rtx_LABEL_REF (VOIDmode, label),
14195                                   pc_rtx, NULL_RTX, NULL_RTX);
14196           }
14197         else
14198           {
14199             tmp = gen_rtx_fmt_ee (code, VOIDmode,
14200                                   ix86_compare_op0, ix86_compare_op1);
14201             tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
14202                                         gen_rtx_LABEL_REF (VOIDmode, label),
14203                                         pc_rtx);
14204             tmp = gen_rtx_SET (VOIDmode, pc_rtx, tmp);
14205
14206             use_fcomi = ix86_use_fcomi_compare (code);
14207             vec = rtvec_alloc (3 + !use_fcomi);
14208             RTVEC_ELT (vec, 0) = tmp;
14209             RTVEC_ELT (vec, 1)
14210               = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCFPmode, FPSR_REG));
14211             RTVEC_ELT (vec, 2)
14212               = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCFPmode, FLAGS_REG));
14213             if (! use_fcomi)
14214               RTVEC_ELT (vec, 3)
14215                 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (HImode));
14216
14217             emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, vec));
14218           }
14219         return;
14220       }
14221
14222     case DImode:
14223       if (TARGET_64BIT)
14224         goto simple;
14225     case TImode:
14226       /* Expand DImode branch into multiple compare+branch.  */
14227       {
14228         rtx lo[2], hi[2], label2;
14229         enum rtx_code code1, code2, code3;
14230         enum machine_mode submode;
14231
14232         if (CONSTANT_P (ix86_compare_op0) && ! CONSTANT_P (ix86_compare_op1))
14233           {
14234             tmp = ix86_compare_op0;
14235             ix86_compare_op0 = ix86_compare_op1;
14236             ix86_compare_op1 = tmp;
14237             code = swap_condition (code);
14238           }
14239         if (GET_MODE (ix86_compare_op0) == DImode)
14240           {
14241             split_di (&ix86_compare_op0, 1, lo+0, hi+0);
14242             split_di (&ix86_compare_op1, 1, lo+1, hi+1);
14243             submode = SImode;
14244           }
14245         else
14246           {
14247             split_ti (&ix86_compare_op0, 1, lo+0, hi+0);
14248             split_ti (&ix86_compare_op1, 1, lo+1, hi+1);
14249             submode = DImode;
14250           }
14251
14252         /* When comparing for equality, we can use (hi0^hi1)|(lo0^lo1) to
14253            avoid two branches.  This costs one extra insn, so disable when
14254            optimizing for size.  */
14255
14256         if ((code == EQ || code == NE)
14257             && (!optimize_insn_for_size_p ()
14258                 || hi[1] == const0_rtx || lo[1] == const0_rtx))
14259           {
14260             rtx xor0, xor1;
14261
14262             xor1 = hi[0];
14263             if (hi[1] != const0_rtx)
14264               xor1 = expand_binop (submode, xor_optab, xor1, hi[1],
14265                                    NULL_RTX, 0, OPTAB_WIDEN);
14266
14267             xor0 = lo[0];
14268             if (lo[1] != const0_rtx)
14269               xor0 = expand_binop (submode, xor_optab, xor0, lo[1],
14270                                    NULL_RTX, 0, OPTAB_WIDEN);
14271
14272             tmp = expand_binop (submode, ior_optab, xor1, xor0,
14273                                 NULL_RTX, 0, OPTAB_WIDEN);
14274
14275             ix86_compare_op0 = tmp;
14276             ix86_compare_op1 = const0_rtx;
14277             ix86_expand_branch (code, label);
14278             return;
14279           }
14280
14281         /* Otherwise, if we are doing less-than or greater-or-equal-than,
14282            op1 is a constant and the low word is zero, then we can just
14283            examine the high word.  Similarly for low word -1 and
14284            less-or-equal-than or greater-than.  */
14285
14286         if (CONST_INT_P (hi[1]))
14287           switch (code)
14288             {
14289             case LT: case LTU: case GE: case GEU:
14290               if (lo[1] == const0_rtx)
14291                 {
14292                   ix86_compare_op0 = hi[0];
14293                   ix86_compare_op1 = hi[1];
14294                   ix86_expand_branch (code, label);
14295                   return;
14296                 }
14297               break;
14298             case LE: case LEU: case GT: case GTU:
14299               if (lo[1] == constm1_rtx)
14300                 {
14301                   ix86_compare_op0 = hi[0];
14302                   ix86_compare_op1 = hi[1];
14303                   ix86_expand_branch (code, label);
14304                   return;
14305                 }
14306               break;
14307             default:
14308               break;
14309             }
14310
14311         /* Otherwise, we need two or three jumps.  */
14312
14313         label2 = gen_label_rtx ();
14314
14315         code1 = code;
14316         code2 = swap_condition (code);
14317         code3 = unsigned_condition (code);
14318
14319         switch (code)
14320           {
14321           case LT: case GT: case LTU: case GTU:
14322             break;
14323
14324           case LE:   code1 = LT;  code2 = GT;  break;
14325           case GE:   code1 = GT;  code2 = LT;  break;
14326           case LEU:  code1 = LTU; code2 = GTU; break;
14327           case GEU:  code1 = GTU; code2 = LTU; break;
14328
14329           case EQ:   code1 = UNKNOWN; code2 = NE;  break;
14330           case NE:   code2 = UNKNOWN; break;
14331
14332           default:
14333             gcc_unreachable ();
14334           }
14335
14336         /*
14337          * a < b =>
14338          *    if (hi(a) < hi(b)) goto true;
14339          *    if (hi(a) > hi(b)) goto false;
14340          *    if (lo(a) < lo(b)) goto true;
14341          *  false:
14342          */
14343
14344         ix86_compare_op0 = hi[0];
14345         ix86_compare_op1 = hi[1];
14346
14347         if (code1 != UNKNOWN)
14348           ix86_expand_branch (code1, label);
14349         if (code2 != UNKNOWN)
14350           ix86_expand_branch (code2, label2);
14351
14352         ix86_compare_op0 = lo[0];
14353         ix86_compare_op1 = lo[1];
14354         ix86_expand_branch (code3, label);
14355
14356         if (code2 != UNKNOWN)
14357           emit_label (label2);
14358         return;
14359       }
14360
14361     default:
14362       gcc_unreachable ();
14363     }
14364 }
14365
14366 /* Split branch based on floating point condition.  */
14367 void
14368 ix86_split_fp_branch (enum rtx_code code, rtx op1, rtx op2,
14369                       rtx target1, rtx target2, rtx tmp, rtx pushed)
14370 {
14371   rtx second, bypass;
14372   rtx label = NULL_RTX;
14373   rtx condition;
14374   int bypass_probability = -1, second_probability = -1, probability = -1;
14375   rtx i;
14376
14377   if (target2 != pc_rtx)
14378     {
14379       rtx tmp = target2;
14380       code = reverse_condition_maybe_unordered (code);
14381       target2 = target1;
14382       target1 = tmp;
14383     }
14384
14385   condition = ix86_expand_fp_compare (code, op1, op2,
14386                                       tmp, &second, &bypass);
14387
14388   /* Remove pushed operand from stack.  */
14389   if (pushed)
14390     ix86_free_from_memory (GET_MODE (pushed));
14391
14392   if (split_branch_probability >= 0)
14393     {
14394       /* Distribute the probabilities across the jumps.
14395          Assume the BYPASS and SECOND to be always test
14396          for UNORDERED.  */
14397       probability = split_branch_probability;
14398
14399       /* Value of 1 is low enough to make no need for probability
14400          to be updated.  Later we may run some experiments and see
14401          if unordered values are more frequent in practice.  */
14402       if (bypass)
14403         bypass_probability = 1;
14404       if (second)
14405         second_probability = 1;
14406     }
14407   if (bypass != NULL_RTX)
14408     {
14409       label = gen_label_rtx ();
14410       i = emit_jump_insn (gen_rtx_SET
14411                           (VOIDmode, pc_rtx,
14412                            gen_rtx_IF_THEN_ELSE (VOIDmode,
14413                                                  bypass,
14414                                                  gen_rtx_LABEL_REF (VOIDmode,
14415                                                                     label),
14416                                                  pc_rtx)));
14417       if (bypass_probability >= 0)
14418         REG_NOTES (i)
14419           = gen_rtx_EXPR_LIST (REG_BR_PROB,
14420                                GEN_INT (bypass_probability),
14421                                REG_NOTES (i));
14422     }
14423   i = emit_jump_insn (gen_rtx_SET
14424                       (VOIDmode, pc_rtx,
14425                        gen_rtx_IF_THEN_ELSE (VOIDmode,
14426                                              condition, target1, target2)));
14427   if (probability >= 0)
14428     REG_NOTES (i)
14429       = gen_rtx_EXPR_LIST (REG_BR_PROB,
14430                            GEN_INT (probability),
14431                            REG_NOTES (i));
14432   if (second != NULL_RTX)
14433     {
14434       i = emit_jump_insn (gen_rtx_SET
14435                           (VOIDmode, pc_rtx,
14436                            gen_rtx_IF_THEN_ELSE (VOIDmode, second, target1,
14437                                                  target2)));
14438       if (second_probability >= 0)
14439         REG_NOTES (i)
14440           = gen_rtx_EXPR_LIST (REG_BR_PROB,
14441                                GEN_INT (second_probability),
14442                                REG_NOTES (i));
14443     }
14444   if (label != NULL_RTX)
14445     emit_label (label);
14446 }
14447
14448 int
14449 ix86_expand_setcc (enum rtx_code code, rtx dest)
14450 {
14451   rtx ret, tmp, tmpreg, equiv;
14452   rtx second_test, bypass_test;
14453
14454   if (GET_MODE (ix86_compare_op0) == (TARGET_64BIT ? TImode : DImode))
14455     return 0; /* FAIL */
14456
14457   gcc_assert (GET_MODE (dest) == QImode);
14458
14459   ret = ix86_expand_compare (code, &second_test, &bypass_test);
14460   PUT_MODE (ret, QImode);
14461
14462   tmp = dest;
14463   tmpreg = dest;
14464
14465   emit_insn (gen_rtx_SET (VOIDmode, tmp, ret));
14466   if (bypass_test || second_test)
14467     {
14468       rtx test = second_test;
14469       int bypass = 0;
14470       rtx tmp2 = gen_reg_rtx (QImode);
14471       if (bypass_test)
14472         {
14473           gcc_assert (!second_test);
14474           test = bypass_test;
14475           bypass = 1;
14476           PUT_CODE (test, reverse_condition_maybe_unordered (GET_CODE (test)));
14477         }
14478       PUT_MODE (test, QImode);
14479       emit_insn (gen_rtx_SET (VOIDmode, tmp2, test));
14480
14481       if (bypass)
14482         emit_insn (gen_andqi3 (tmp, tmpreg, tmp2));
14483       else
14484         emit_insn (gen_iorqi3 (tmp, tmpreg, tmp2));
14485     }
14486
14487   /* Attach a REG_EQUAL note describing the comparison result.  */
14488   if (ix86_compare_op0 && ix86_compare_op1)
14489     {
14490       equiv = simplify_gen_relational (code, QImode,
14491                                        GET_MODE (ix86_compare_op0),
14492                                        ix86_compare_op0, ix86_compare_op1);
14493       set_unique_reg_note (get_last_insn (), REG_EQUAL, equiv);
14494     }
14495
14496   return 1; /* DONE */
14497 }
14498
14499 /* Expand comparison setting or clearing carry flag.  Return true when
14500    successful and set pop for the operation.  */
14501 static bool
14502 ix86_expand_carry_flag_compare (enum rtx_code code, rtx op0, rtx op1, rtx *pop)
14503 {
14504   enum machine_mode mode =
14505     GET_MODE (op0) != VOIDmode ? GET_MODE (op0) : GET_MODE (op1);
14506
14507   /* Do not handle DImode compares that go through special path.  */
14508   if (mode == (TARGET_64BIT ? TImode : DImode))
14509     return false;
14510
14511   if (SCALAR_FLOAT_MODE_P (mode))
14512     {
14513       rtx second_test = NULL, bypass_test = NULL;
14514       rtx compare_op, compare_seq;
14515
14516       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
14517
14518       /* Shortcut:  following common codes never translate
14519          into carry flag compares.  */
14520       if (code == EQ || code == NE || code == UNEQ || code == LTGT
14521           || code == ORDERED || code == UNORDERED)
14522         return false;
14523
14524       /* These comparisons require zero flag; swap operands so they won't.  */
14525       if ((code == GT || code == UNLE || code == LE || code == UNGT)
14526           && !TARGET_IEEE_FP)
14527         {
14528           rtx tmp = op0;
14529           op0 = op1;
14530           op1 = tmp;
14531           code = swap_condition (code);
14532         }
14533
14534       /* Try to expand the comparison and verify that we end up with
14535          carry flag based comparison.  This fails to be true only when
14536          we decide to expand comparison using arithmetic that is not
14537          too common scenario.  */
14538       start_sequence ();
14539       compare_op = ix86_expand_fp_compare (code, op0, op1, NULL_RTX,
14540                                            &second_test, &bypass_test);
14541       compare_seq = get_insns ();
14542       end_sequence ();
14543
14544       if (second_test || bypass_test)
14545         return false;
14546
14547       if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
14548           || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
14549         code = ix86_fp_compare_code_to_integer (GET_CODE (compare_op));
14550       else
14551         code = GET_CODE (compare_op);
14552
14553       if (code != LTU && code != GEU)
14554         return false;
14555
14556       emit_insn (compare_seq);
14557       *pop = compare_op;
14558       return true;
14559     }
14560
14561   if (!INTEGRAL_MODE_P (mode))
14562     return false;
14563
14564   switch (code)
14565     {
14566     case LTU:
14567     case GEU:
14568       break;
14569
14570     /* Convert a==0 into (unsigned)a<1.  */
14571     case EQ:
14572     case NE:
14573       if (op1 != const0_rtx)
14574         return false;
14575       op1 = const1_rtx;
14576       code = (code == EQ ? LTU : GEU);
14577       break;
14578
14579     /* Convert a>b into b<a or a>=b-1.  */
14580     case GTU:
14581     case LEU:
14582       if (CONST_INT_P (op1))
14583         {
14584           op1 = gen_int_mode (INTVAL (op1) + 1, GET_MODE (op0));
14585           /* Bail out on overflow.  We still can swap operands but that
14586              would force loading of the constant into register.  */
14587           if (op1 == const0_rtx
14588               || !x86_64_immediate_operand (op1, GET_MODE (op1)))
14589             return false;
14590           code = (code == GTU ? GEU : LTU);
14591         }
14592       else
14593         {
14594           rtx tmp = op1;
14595           op1 = op0;
14596           op0 = tmp;
14597           code = (code == GTU ? LTU : GEU);
14598         }
14599       break;
14600
14601     /* Convert a>=0 into (unsigned)a<0x80000000.  */
14602     case LT:
14603     case GE:
14604       if (mode == DImode || op1 != const0_rtx)
14605         return false;
14606       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
14607       code = (code == LT ? GEU : LTU);
14608       break;
14609     case LE:
14610     case GT:
14611       if (mode == DImode || op1 != constm1_rtx)
14612         return false;
14613       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
14614       code = (code == LE ? GEU : LTU);
14615       break;
14616
14617     default:
14618       return false;
14619     }
14620   /* Swapping operands may cause constant to appear as first operand.  */
14621   if (!nonimmediate_operand (op0, VOIDmode))
14622     {
14623       if (!can_create_pseudo_p ())
14624         return false;
14625       op0 = force_reg (mode, op0);
14626     }
14627   ix86_compare_op0 = op0;
14628   ix86_compare_op1 = op1;
14629   *pop = ix86_expand_compare (code, NULL, NULL);
14630   gcc_assert (GET_CODE (*pop) == LTU || GET_CODE (*pop) == GEU);
14631   return true;
14632 }
14633
14634 int
14635 ix86_expand_int_movcc (rtx operands[])
14636 {
14637   enum rtx_code code = GET_CODE (operands[1]), compare_code;
14638   rtx compare_seq, compare_op;
14639   rtx second_test, bypass_test;
14640   enum machine_mode mode = GET_MODE (operands[0]);
14641   bool sign_bit_compare_p = false;;
14642
14643   start_sequence ();
14644   compare_op = ix86_expand_compare (code, &second_test, &bypass_test);
14645   compare_seq = get_insns ();
14646   end_sequence ();
14647
14648   compare_code = GET_CODE (compare_op);
14649
14650   if ((ix86_compare_op1 == const0_rtx && (code == GE || code == LT))
14651       || (ix86_compare_op1 == constm1_rtx && (code == GT || code == LE)))
14652     sign_bit_compare_p = true;
14653
14654   /* Don't attempt mode expansion here -- if we had to expand 5 or 6
14655      HImode insns, we'd be swallowed in word prefix ops.  */
14656
14657   if ((mode != HImode || TARGET_FAST_PREFIX)
14658       && (mode != (TARGET_64BIT ? TImode : DImode))
14659       && CONST_INT_P (operands[2])
14660       && CONST_INT_P (operands[3]))
14661     {
14662       rtx out = operands[0];
14663       HOST_WIDE_INT ct = INTVAL (operands[2]);
14664       HOST_WIDE_INT cf = INTVAL (operands[3]);
14665       HOST_WIDE_INT diff;
14666
14667       diff = ct - cf;
14668       /*  Sign bit compares are better done using shifts than we do by using
14669           sbb.  */
14670       if (sign_bit_compare_p
14671           || ix86_expand_carry_flag_compare (code, ix86_compare_op0,
14672                                              ix86_compare_op1, &compare_op))
14673         {
14674           /* Detect overlap between destination and compare sources.  */
14675           rtx tmp = out;
14676
14677           if (!sign_bit_compare_p)
14678             {
14679               bool fpcmp = false;
14680
14681               compare_code = GET_CODE (compare_op);
14682
14683               if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
14684                   || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
14685                 {
14686                   fpcmp = true;
14687                   compare_code = ix86_fp_compare_code_to_integer (compare_code);
14688                 }
14689
14690               /* To simplify rest of code, restrict to the GEU case.  */
14691               if (compare_code == LTU)
14692                 {
14693                   HOST_WIDE_INT tmp = ct;
14694                   ct = cf;
14695                   cf = tmp;
14696                   compare_code = reverse_condition (compare_code);
14697                   code = reverse_condition (code);
14698                 }
14699               else
14700                 {
14701                   if (fpcmp)
14702                     PUT_CODE (compare_op,
14703                               reverse_condition_maybe_unordered
14704                                 (GET_CODE (compare_op)));
14705                   else
14706                     PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
14707                 }
14708               diff = ct - cf;
14709
14710               if (reg_overlap_mentioned_p (out, ix86_compare_op0)
14711                   || reg_overlap_mentioned_p (out, ix86_compare_op1))
14712                 tmp = gen_reg_rtx (mode);
14713
14714               if (mode == DImode)
14715                 emit_insn (gen_x86_movdicc_0_m1_rex64 (tmp, compare_op));
14716               else
14717                 emit_insn (gen_x86_movsicc_0_m1 (gen_lowpart (SImode, tmp), compare_op));
14718             }
14719           else
14720             {
14721               if (code == GT || code == GE)
14722                 code = reverse_condition (code);
14723               else
14724                 {
14725                   HOST_WIDE_INT tmp = ct;
14726                   ct = cf;
14727                   cf = tmp;
14728                   diff = ct - cf;
14729                 }
14730               tmp = emit_store_flag (tmp, code, ix86_compare_op0,
14731                                      ix86_compare_op1, VOIDmode, 0, -1);
14732             }
14733
14734           if (diff == 1)
14735             {
14736               /*
14737                * cmpl op0,op1
14738                * sbbl dest,dest
14739                * [addl dest, ct]
14740                *
14741                * Size 5 - 8.
14742                */
14743               if (ct)
14744                 tmp = expand_simple_binop (mode, PLUS,
14745                                            tmp, GEN_INT (ct),
14746                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
14747             }
14748           else if (cf == -1)
14749             {
14750               /*
14751                * cmpl op0,op1
14752                * sbbl dest,dest
14753                * orl $ct, dest
14754                *
14755                * Size 8.
14756                */
14757               tmp = expand_simple_binop (mode, IOR,
14758                                          tmp, GEN_INT (ct),
14759                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
14760             }
14761           else if (diff == -1 && ct)
14762             {
14763               /*
14764                * cmpl op0,op1
14765                * sbbl dest,dest
14766                * notl dest
14767                * [addl dest, cf]
14768                *
14769                * Size 8 - 11.
14770                */
14771               tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
14772               if (cf)
14773                 tmp = expand_simple_binop (mode, PLUS,
14774                                            copy_rtx (tmp), GEN_INT (cf),
14775                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
14776             }
14777           else
14778             {
14779               /*
14780                * cmpl op0,op1
14781                * sbbl dest,dest
14782                * [notl dest]
14783                * andl cf - ct, dest
14784                * [addl dest, ct]
14785                *
14786                * Size 8 - 11.
14787                */
14788
14789               if (cf == 0)
14790                 {
14791                   cf = ct;
14792                   ct = 0;
14793                   tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
14794                 }
14795
14796               tmp = expand_simple_binop (mode, AND,
14797                                          copy_rtx (tmp),
14798                                          gen_int_mode (cf - ct, mode),
14799                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
14800               if (ct)
14801                 tmp = expand_simple_binop (mode, PLUS,
14802                                            copy_rtx (tmp), GEN_INT (ct),
14803                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
14804             }
14805
14806           if (!rtx_equal_p (tmp, out))
14807             emit_move_insn (copy_rtx (out), copy_rtx (tmp));
14808
14809           return 1; /* DONE */
14810         }
14811
14812       if (diff < 0)
14813         {
14814           enum machine_mode cmp_mode = GET_MODE (ix86_compare_op0);
14815
14816           HOST_WIDE_INT tmp;
14817           tmp = ct, ct = cf, cf = tmp;
14818           diff = -diff;
14819
14820           if (SCALAR_FLOAT_MODE_P (cmp_mode))
14821             {
14822               gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
14823
14824               /* We may be reversing unordered compare to normal compare, that
14825                  is not valid in general (we may convert non-trapping condition
14826                  to trapping one), however on i386 we currently emit all
14827                  comparisons unordered.  */
14828               compare_code = reverse_condition_maybe_unordered (compare_code);
14829               code = reverse_condition_maybe_unordered (code);
14830             }
14831           else
14832             {
14833               compare_code = reverse_condition (compare_code);
14834               code = reverse_condition (code);
14835             }
14836         }
14837
14838       compare_code = UNKNOWN;
14839       if (GET_MODE_CLASS (GET_MODE (ix86_compare_op0)) == MODE_INT
14840           && CONST_INT_P (ix86_compare_op1))
14841         {
14842           if (ix86_compare_op1 == const0_rtx
14843               && (code == LT || code == GE))
14844             compare_code = code;
14845           else if (ix86_compare_op1 == constm1_rtx)
14846             {
14847               if (code == LE)
14848                 compare_code = LT;
14849               else if (code == GT)
14850                 compare_code = GE;
14851             }
14852         }
14853
14854       /* Optimize dest = (op0 < 0) ? -1 : cf.  */
14855       if (compare_code != UNKNOWN
14856           && GET_MODE (ix86_compare_op0) == GET_MODE (out)
14857           && (cf == -1 || ct == -1))
14858         {
14859           /* If lea code below could be used, only optimize
14860              if it results in a 2 insn sequence.  */
14861
14862           if (! (diff == 1 || diff == 2 || diff == 4 || diff == 8
14863                  || diff == 3 || diff == 5 || diff == 9)
14864               || (compare_code == LT && ct == -1)
14865               || (compare_code == GE && cf == -1))
14866             {
14867               /*
14868                * notl op1       (if necessary)
14869                * sarl $31, op1
14870                * orl cf, op1
14871                */
14872               if (ct != -1)
14873                 {
14874                   cf = ct;
14875                   ct = -1;
14876                   code = reverse_condition (code);
14877                 }
14878
14879               out = emit_store_flag (out, code, ix86_compare_op0,
14880                                      ix86_compare_op1, VOIDmode, 0, -1);
14881
14882               out = expand_simple_binop (mode, IOR,
14883                                          out, GEN_INT (cf),
14884                                          out, 1, OPTAB_DIRECT);
14885               if (out != operands[0])
14886                 emit_move_insn (operands[0], out);
14887
14888               return 1; /* DONE */
14889             }
14890         }
14891
14892
14893       if ((diff == 1 || diff == 2 || diff == 4 || diff == 8
14894            || diff == 3 || diff == 5 || diff == 9)
14895           && ((mode != QImode && mode != HImode) || !TARGET_PARTIAL_REG_STALL)
14896           && (mode != DImode
14897               || x86_64_immediate_operand (GEN_INT (cf), VOIDmode)))
14898         {
14899           /*
14900            * xorl dest,dest
14901            * cmpl op1,op2
14902            * setcc dest
14903            * lea cf(dest*(ct-cf)),dest
14904            *
14905            * Size 14.
14906            *
14907            * This also catches the degenerate setcc-only case.
14908            */
14909
14910           rtx tmp;
14911           int nops;
14912
14913           out = emit_store_flag (out, code, ix86_compare_op0,
14914                                  ix86_compare_op1, VOIDmode, 0, 1);
14915
14916           nops = 0;
14917           /* On x86_64 the lea instruction operates on Pmode, so we need
14918              to get arithmetics done in proper mode to match.  */
14919           if (diff == 1)
14920             tmp = copy_rtx (out);
14921           else
14922             {
14923               rtx out1;
14924               out1 = copy_rtx (out);
14925               tmp = gen_rtx_MULT (mode, out1, GEN_INT (diff & ~1));
14926               nops++;
14927               if (diff & 1)
14928                 {
14929                   tmp = gen_rtx_PLUS (mode, tmp, out1);
14930                   nops++;
14931                 }
14932             }
14933           if (cf != 0)
14934             {
14935               tmp = gen_rtx_PLUS (mode, tmp, GEN_INT (cf));
14936               nops++;
14937             }
14938           if (!rtx_equal_p (tmp, out))
14939             {
14940               if (nops == 1)
14941                 out = force_operand (tmp, copy_rtx (out));
14942               else
14943                 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (out), copy_rtx (tmp)));
14944             }
14945           if (!rtx_equal_p (out, operands[0]))
14946             emit_move_insn (operands[0], copy_rtx (out));
14947
14948           return 1; /* DONE */
14949         }
14950
14951       /*
14952        * General case:                  Jumpful:
14953        *   xorl dest,dest               cmpl op1, op2
14954        *   cmpl op1, op2                movl ct, dest
14955        *   setcc dest                   jcc 1f
14956        *   decl dest                    movl cf, dest
14957        *   andl (cf-ct),dest            1:
14958        *   addl ct,dest
14959        *
14960        * Size 20.                       Size 14.
14961        *
14962        * This is reasonably steep, but branch mispredict costs are
14963        * high on modern cpus, so consider failing only if optimizing
14964        * for space.
14965        */
14966
14967       if ((!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
14968           && BRANCH_COST (optimize_insn_for_speed_p (),
14969                           false) >= 2)
14970         {
14971           if (cf == 0)
14972             {
14973               enum machine_mode cmp_mode = GET_MODE (ix86_compare_op0);
14974
14975               cf = ct;
14976               ct = 0;
14977
14978               if (SCALAR_FLOAT_MODE_P (cmp_mode))
14979                 {
14980                   gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
14981
14982                   /* We may be reversing unordered compare to normal compare,
14983                      that is not valid in general (we may convert non-trapping
14984                      condition to trapping one), however on i386 we currently
14985                      emit all comparisons unordered.  */
14986                   code = reverse_condition_maybe_unordered (code);
14987                 }
14988               else
14989                 {
14990                   code = reverse_condition (code);
14991                   if (compare_code != UNKNOWN)
14992                     compare_code = reverse_condition (compare_code);
14993                 }
14994             }
14995
14996           if (compare_code != UNKNOWN)
14997             {
14998               /* notl op1       (if needed)
14999                  sarl $31, op1
15000                  andl (cf-ct), op1
15001                  addl ct, op1
15002
15003                  For x < 0 (resp. x <= -1) there will be no notl,
15004                  so if possible swap the constants to get rid of the
15005                  complement.
15006                  True/false will be -1/0 while code below (store flag
15007                  followed by decrement) is 0/-1, so the constants need
15008                  to be exchanged once more.  */
15009
15010               if (compare_code == GE || !cf)
15011                 {
15012                   code = reverse_condition (code);
15013                   compare_code = LT;
15014                 }
15015               else
15016                 {
15017                   HOST_WIDE_INT tmp = cf;
15018                   cf = ct;
15019                   ct = tmp;
15020                 }
15021
15022               out = emit_store_flag (out, code, ix86_compare_op0,
15023                                      ix86_compare_op1, VOIDmode, 0, -1);
15024             }
15025           else
15026             {
15027               out = emit_store_flag (out, code, ix86_compare_op0,
15028                                      ix86_compare_op1, VOIDmode, 0, 1);
15029
15030               out = expand_simple_binop (mode, PLUS, copy_rtx (out), constm1_rtx,
15031                                          copy_rtx (out), 1, OPTAB_DIRECT);
15032             }
15033
15034           out = expand_simple_binop (mode, AND, copy_rtx (out),
15035                                      gen_int_mode (cf - ct, mode),
15036                                      copy_rtx (out), 1, OPTAB_DIRECT);
15037           if (ct)
15038             out = expand_simple_binop (mode, PLUS, copy_rtx (out), GEN_INT (ct),
15039                                        copy_rtx (out), 1, OPTAB_DIRECT);
15040           if (!rtx_equal_p (out, operands[0]))
15041             emit_move_insn (operands[0], copy_rtx (out));
15042
15043           return 1; /* DONE */
15044         }
15045     }
15046
15047   if (!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
15048     {
15049       /* Try a few things more with specific constants and a variable.  */
15050
15051       optab op;
15052       rtx var, orig_out, out, tmp;
15053
15054       if (BRANCH_COST (optimize_insn_for_speed_p (), false) <= 2)
15055         return 0; /* FAIL */
15056
15057       /* If one of the two operands is an interesting constant, load a
15058          constant with the above and mask it in with a logical operation.  */
15059
15060       if (CONST_INT_P (operands[2]))
15061         {
15062           var = operands[3];
15063           if (INTVAL (operands[2]) == 0 && operands[3] != constm1_rtx)
15064             operands[3] = constm1_rtx, op = and_optab;
15065           else if (INTVAL (operands[2]) == -1 && operands[3] != const0_rtx)
15066             operands[3] = const0_rtx, op = ior_optab;
15067           else
15068             return 0; /* FAIL */
15069         }
15070       else if (CONST_INT_P (operands[3]))
15071         {
15072           var = operands[2];
15073           if (INTVAL (operands[3]) == 0 && operands[2] != constm1_rtx)
15074             operands[2] = constm1_rtx, op = and_optab;
15075           else if (INTVAL (operands[3]) == -1 && operands[3] != const0_rtx)
15076             operands[2] = const0_rtx, op = ior_optab;
15077           else
15078             return 0; /* FAIL */
15079         }
15080       else
15081         return 0; /* FAIL */
15082
15083       orig_out = operands[0];
15084       tmp = gen_reg_rtx (mode);
15085       operands[0] = tmp;
15086
15087       /* Recurse to get the constant loaded.  */
15088       if (ix86_expand_int_movcc (operands) == 0)
15089         return 0; /* FAIL */
15090
15091       /* Mask in the interesting variable.  */
15092       out = expand_binop (mode, op, var, tmp, orig_out, 0,
15093                           OPTAB_WIDEN);
15094       if (!rtx_equal_p (out, orig_out))
15095         emit_move_insn (copy_rtx (orig_out), copy_rtx (out));
15096
15097       return 1; /* DONE */
15098     }
15099
15100   /*
15101    * For comparison with above,
15102    *
15103    * movl cf,dest
15104    * movl ct,tmp
15105    * cmpl op1,op2
15106    * cmovcc tmp,dest
15107    *
15108    * Size 15.
15109    */
15110
15111   if (! nonimmediate_operand (operands[2], mode))
15112     operands[2] = force_reg (mode, operands[2]);
15113   if (! nonimmediate_operand (operands[3], mode))
15114     operands[3] = force_reg (mode, operands[3]);
15115
15116   if (bypass_test && reg_overlap_mentioned_p (operands[0], operands[3]))
15117     {
15118       rtx tmp = gen_reg_rtx (mode);
15119       emit_move_insn (tmp, operands[3]);
15120       operands[3] = tmp;
15121     }
15122   if (second_test && reg_overlap_mentioned_p (operands[0], operands[2]))
15123     {
15124       rtx tmp = gen_reg_rtx (mode);
15125       emit_move_insn (tmp, operands[2]);
15126       operands[2] = tmp;
15127     }
15128
15129   if (! register_operand (operands[2], VOIDmode)
15130       && (mode == QImode
15131           || ! register_operand (operands[3], VOIDmode)))
15132     operands[2] = force_reg (mode, operands[2]);
15133
15134   if (mode == QImode
15135       && ! register_operand (operands[3], VOIDmode))
15136     operands[3] = force_reg (mode, operands[3]);
15137
15138   emit_insn (compare_seq);
15139   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15140                           gen_rtx_IF_THEN_ELSE (mode,
15141                                                 compare_op, operands[2],
15142                                                 operands[3])));
15143   if (bypass_test)
15144     emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (operands[0]),
15145                             gen_rtx_IF_THEN_ELSE (mode,
15146                                   bypass_test,
15147                                   copy_rtx (operands[3]),
15148                                   copy_rtx (operands[0]))));
15149   if (second_test)
15150     emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (operands[0]),
15151                             gen_rtx_IF_THEN_ELSE (mode,
15152                                   second_test,
15153                                   copy_rtx (operands[2]),
15154                                   copy_rtx (operands[0]))));
15155
15156   return 1; /* DONE */
15157 }
15158
15159 /* Swap, force into registers, or otherwise massage the two operands
15160    to an sse comparison with a mask result.  Thus we differ a bit from
15161    ix86_prepare_fp_compare_args which expects to produce a flags result.
15162
15163    The DEST operand exists to help determine whether to commute commutative
15164    operators.  The POP0/POP1 operands are updated in place.  The new
15165    comparison code is returned, or UNKNOWN if not implementable.  */
15166
15167 static enum rtx_code
15168 ix86_prepare_sse_fp_compare_args (rtx dest, enum rtx_code code,
15169                                   rtx *pop0, rtx *pop1)
15170 {
15171   rtx tmp;
15172
15173   switch (code)
15174     {
15175     case LTGT:
15176     case UNEQ:
15177       /* We have no LTGT as an operator.  We could implement it with
15178          NE & ORDERED, but this requires an extra temporary.  It's
15179          not clear that it's worth it.  */
15180       return UNKNOWN;
15181
15182     case LT:
15183     case LE:
15184     case UNGT:
15185     case UNGE:
15186       /* These are supported directly.  */
15187       break;
15188
15189     case EQ:
15190     case NE:
15191     case UNORDERED:
15192     case ORDERED:
15193       /* For commutative operators, try to canonicalize the destination
15194          operand to be first in the comparison - this helps reload to
15195          avoid extra moves.  */
15196       if (!dest || !rtx_equal_p (dest, *pop1))
15197         break;
15198       /* FALLTHRU */
15199
15200     case GE:
15201     case GT:
15202     case UNLE:
15203     case UNLT:
15204       /* These are not supported directly.  Swap the comparison operands
15205          to transform into something that is supported.  */
15206       tmp = *pop0;
15207       *pop0 = *pop1;
15208       *pop1 = tmp;
15209       code = swap_condition (code);
15210       break;
15211
15212     default:
15213       gcc_unreachable ();
15214     }
15215
15216   return code;
15217 }
15218
15219 /* Detect conditional moves that exactly match min/max operational
15220    semantics.  Note that this is IEEE safe, as long as we don't
15221    interchange the operands.
15222
15223    Returns FALSE if this conditional move doesn't match a MIN/MAX,
15224    and TRUE if the operation is successful and instructions are emitted.  */
15225
15226 static bool
15227 ix86_expand_sse_fp_minmax (rtx dest, enum rtx_code code, rtx cmp_op0,
15228                            rtx cmp_op1, rtx if_true, rtx if_false)
15229 {
15230   enum machine_mode mode;
15231   bool is_min;
15232   rtx tmp;
15233
15234   if (code == LT)
15235     ;
15236   else if (code == UNGE)
15237     {
15238       tmp = if_true;
15239       if_true = if_false;
15240       if_false = tmp;
15241     }
15242   else
15243     return false;
15244
15245   if (rtx_equal_p (cmp_op0, if_true) && rtx_equal_p (cmp_op1, if_false))
15246     is_min = true;
15247   else if (rtx_equal_p (cmp_op1, if_true) && rtx_equal_p (cmp_op0, if_false))
15248     is_min = false;
15249   else
15250     return false;
15251
15252   mode = GET_MODE (dest);
15253
15254   /* We want to check HONOR_NANS and HONOR_SIGNED_ZEROS here,
15255      but MODE may be a vector mode and thus not appropriate.  */
15256   if (!flag_finite_math_only || !flag_unsafe_math_optimizations)
15257     {
15258       int u = is_min ? UNSPEC_IEEE_MIN : UNSPEC_IEEE_MAX;
15259       rtvec v;
15260
15261       if_true = force_reg (mode, if_true);
15262       v = gen_rtvec (2, if_true, if_false);
15263       tmp = gen_rtx_UNSPEC (mode, v, u);
15264     }
15265   else
15266     {
15267       code = is_min ? SMIN : SMAX;
15268       tmp = gen_rtx_fmt_ee (code, mode, if_true, if_false);
15269     }
15270
15271   emit_insn (gen_rtx_SET (VOIDmode, dest, tmp));
15272   return true;
15273 }
15274
15275 /* Expand an sse vector comparison.  Return the register with the result.  */
15276
15277 static rtx
15278 ix86_expand_sse_cmp (rtx dest, enum rtx_code code, rtx cmp_op0, rtx cmp_op1,
15279                      rtx op_true, rtx op_false)
15280 {
15281   enum machine_mode mode = GET_MODE (dest);
15282   rtx x;
15283
15284   cmp_op0 = force_reg (mode, cmp_op0);
15285   if (!nonimmediate_operand (cmp_op1, mode))
15286     cmp_op1 = force_reg (mode, cmp_op1);
15287
15288   if (optimize
15289       || reg_overlap_mentioned_p (dest, op_true)
15290       || reg_overlap_mentioned_p (dest, op_false))
15291     dest = gen_reg_rtx (mode);
15292
15293   x = gen_rtx_fmt_ee (code, mode, cmp_op0, cmp_op1);
15294   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15295
15296   return dest;
15297 }
15298
15299 /* Expand DEST = CMP ? OP_TRUE : OP_FALSE into a sequence of logical
15300    operations.  This is used for both scalar and vector conditional moves.  */
15301
15302 static void
15303 ix86_expand_sse_movcc (rtx dest, rtx cmp, rtx op_true, rtx op_false)
15304 {
15305   enum machine_mode mode = GET_MODE (dest);
15306   rtx t2, t3, x;
15307
15308   if (op_false == CONST0_RTX (mode))
15309     {
15310       op_true = force_reg (mode, op_true);
15311       x = gen_rtx_AND (mode, cmp, op_true);
15312       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15313     }
15314   else if (op_true == CONST0_RTX (mode))
15315     {
15316       op_false = force_reg (mode, op_false);
15317       x = gen_rtx_NOT (mode, cmp);
15318       x = gen_rtx_AND (mode, x, op_false);
15319       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15320     }
15321   else if (TARGET_SSE5)
15322     {
15323       rtx pcmov = gen_rtx_SET (mode, dest,
15324                                gen_rtx_IF_THEN_ELSE (mode, cmp,
15325                                                      op_true,
15326                                                      op_false));
15327       emit_insn (pcmov);
15328     }
15329   else
15330     {
15331       op_true = force_reg (mode, op_true);
15332       op_false = force_reg (mode, op_false);
15333
15334       t2 = gen_reg_rtx (mode);
15335       if (optimize)
15336         t3 = gen_reg_rtx (mode);
15337       else
15338         t3 = dest;
15339
15340       x = gen_rtx_AND (mode, op_true, cmp);
15341       emit_insn (gen_rtx_SET (VOIDmode, t2, x));
15342
15343       x = gen_rtx_NOT (mode, cmp);
15344       x = gen_rtx_AND (mode, x, op_false);
15345       emit_insn (gen_rtx_SET (VOIDmode, t3, x));
15346
15347       x = gen_rtx_IOR (mode, t3, t2);
15348       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
15349     }
15350 }
15351
15352 /* Expand a floating-point conditional move.  Return true if successful.  */
15353
15354 int
15355 ix86_expand_fp_movcc (rtx operands[])
15356 {
15357   enum machine_mode mode = GET_MODE (operands[0]);
15358   enum rtx_code code = GET_CODE (operands[1]);
15359   rtx tmp, compare_op, second_test, bypass_test;
15360
15361   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
15362     {
15363       enum machine_mode cmode;
15364
15365       /* Since we've no cmove for sse registers, don't force bad register
15366          allocation just to gain access to it.  Deny movcc when the
15367          comparison mode doesn't match the move mode.  */
15368       cmode = GET_MODE (ix86_compare_op0);
15369       if (cmode == VOIDmode)
15370         cmode = GET_MODE (ix86_compare_op1);
15371       if (cmode != mode)
15372         return 0;
15373
15374       code = ix86_prepare_sse_fp_compare_args (operands[0], code,
15375                                                &ix86_compare_op0,
15376                                                &ix86_compare_op1);
15377       if (code == UNKNOWN)
15378         return 0;
15379
15380       if (ix86_expand_sse_fp_minmax (operands[0], code, ix86_compare_op0,
15381                                      ix86_compare_op1, operands[2],
15382                                      operands[3]))
15383         return 1;
15384
15385       tmp = ix86_expand_sse_cmp (operands[0], code, ix86_compare_op0,
15386                                  ix86_compare_op1, operands[2], operands[3]);
15387       ix86_expand_sse_movcc (operands[0], tmp, operands[2], operands[3]);
15388       return 1;
15389     }
15390
15391   /* The floating point conditional move instructions don't directly
15392      support conditions resulting from a signed integer comparison.  */
15393
15394   compare_op = ix86_expand_compare (code, &second_test, &bypass_test);
15395
15396   /* The floating point conditional move instructions don't directly
15397      support signed integer comparisons.  */
15398
15399   if (!fcmov_comparison_operator (compare_op, VOIDmode))
15400     {
15401       gcc_assert (!second_test && !bypass_test);
15402       tmp = gen_reg_rtx (QImode);
15403       ix86_expand_setcc (code, tmp);
15404       code = NE;
15405       ix86_compare_op0 = tmp;
15406       ix86_compare_op1 = const0_rtx;
15407       compare_op = ix86_expand_compare (code,  &second_test, &bypass_test);
15408     }
15409   if (bypass_test && reg_overlap_mentioned_p (operands[0], operands[3]))
15410     {
15411       tmp = gen_reg_rtx (mode);
15412       emit_move_insn (tmp, operands[3]);
15413       operands[3] = tmp;
15414     }
15415   if (second_test && reg_overlap_mentioned_p (operands[0], operands[2]))
15416     {
15417       tmp = gen_reg_rtx (mode);
15418       emit_move_insn (tmp, operands[2]);
15419       operands[2] = tmp;
15420     }
15421
15422   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15423                           gen_rtx_IF_THEN_ELSE (mode, compare_op,
15424                                                 operands[2], operands[3])));
15425   if (bypass_test)
15426     emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15427                             gen_rtx_IF_THEN_ELSE (mode, bypass_test,
15428                                                   operands[3], operands[0])));
15429   if (second_test)
15430     emit_insn (gen_rtx_SET (VOIDmode, operands[0],
15431                             gen_rtx_IF_THEN_ELSE (mode, second_test,
15432                                                   operands[2], operands[0])));
15433
15434   return 1;
15435 }
15436
15437 /* Expand a floating-point vector conditional move; a vcond operation
15438    rather than a movcc operation.  */
15439
15440 bool
15441 ix86_expand_fp_vcond (rtx operands[])
15442 {
15443   enum rtx_code code = GET_CODE (operands[3]);
15444   rtx cmp;
15445
15446   code = ix86_prepare_sse_fp_compare_args (operands[0], code,
15447                                            &operands[4], &operands[5]);
15448   if (code == UNKNOWN)
15449     return false;
15450
15451   if (ix86_expand_sse_fp_minmax (operands[0], code, operands[4],
15452                                  operands[5], operands[1], operands[2]))
15453     return true;
15454
15455   cmp = ix86_expand_sse_cmp (operands[0], code, operands[4], operands[5],
15456                              operands[1], operands[2]);
15457   ix86_expand_sse_movcc (operands[0], cmp, operands[1], operands[2]);
15458   return true;
15459 }
15460
15461 /* Expand a signed/unsigned integral vector conditional move.  */
15462
15463 bool
15464 ix86_expand_int_vcond (rtx operands[])
15465 {
15466   enum machine_mode mode = GET_MODE (operands[0]);
15467   enum rtx_code code = GET_CODE (operands[3]);
15468   bool negate = false;
15469   rtx x, cop0, cop1;
15470
15471   cop0 = operands[4];
15472   cop1 = operands[5];
15473
15474   /* SSE5 supports all of the comparisons on all vector int types.  */
15475   if (!TARGET_SSE5)
15476     {
15477       /* Canonicalize the comparison to EQ, GT, GTU.  */
15478       switch (code)
15479         {
15480         case EQ:
15481         case GT:
15482         case GTU:
15483           break;
15484
15485         case NE:
15486         case LE:
15487         case LEU:
15488           code = reverse_condition (code);
15489           negate = true;
15490           break;
15491
15492         case GE:
15493         case GEU:
15494           code = reverse_condition (code);
15495           negate = true;
15496           /* FALLTHRU */
15497
15498         case LT:
15499         case LTU:
15500           code = swap_condition (code);
15501           x = cop0, cop0 = cop1, cop1 = x;
15502           break;
15503
15504         default:
15505           gcc_unreachable ();
15506         }
15507
15508       /* Only SSE4.1/SSE4.2 supports V2DImode.  */
15509       if (mode == V2DImode)
15510         {
15511           switch (code)
15512             {
15513             case EQ:
15514               /* SSE4.1 supports EQ.  */
15515               if (!TARGET_SSE4_1)
15516                 return false;
15517               break;
15518
15519             case GT:
15520             case GTU:
15521               /* SSE4.2 supports GT/GTU.  */
15522               if (!TARGET_SSE4_2)
15523                 return false;
15524               break;
15525
15526             default:
15527               gcc_unreachable ();
15528             }
15529         }
15530
15531       /* Unsigned parallel compare is not supported by the hardware.  Play some
15532          tricks to turn this into a signed comparison against 0.  */
15533       if (code == GTU)
15534         {
15535           cop0 = force_reg (mode, cop0);
15536
15537           switch (mode)
15538             {
15539             case V4SImode:
15540             case V2DImode:
15541               {
15542                 rtx t1, t2, mask;
15543
15544                 /* Perform a parallel modulo subtraction.  */
15545                 t1 = gen_reg_rtx (mode);
15546                 emit_insn ((mode == V4SImode
15547                             ? gen_subv4si3
15548                             : gen_subv2di3) (t1, cop0, cop1));
15549
15550                 /* Extract the original sign bit of op0.  */
15551                 mask = ix86_build_signbit_mask (GET_MODE_INNER (mode),
15552                                                 true, false);
15553                 t2 = gen_reg_rtx (mode);
15554                 emit_insn ((mode == V4SImode
15555                             ? gen_andv4si3
15556                             : gen_andv2di3) (t2, cop0, mask));
15557
15558                 /* XOR it back into the result of the subtraction.  This results
15559                    in the sign bit set iff we saw unsigned underflow.  */
15560                 x = gen_reg_rtx (mode);
15561                 emit_insn ((mode == V4SImode
15562                             ? gen_xorv4si3
15563                             : gen_xorv2di3) (x, t1, t2));
15564
15565                 code = GT;
15566               }
15567               break;
15568
15569             case V16QImode:
15570             case V8HImode:
15571               /* Perform a parallel unsigned saturating subtraction.  */
15572               x = gen_reg_rtx (mode);
15573               emit_insn (gen_rtx_SET (VOIDmode, x,
15574                                       gen_rtx_US_MINUS (mode, cop0, cop1)));
15575
15576               code = EQ;
15577               negate = !negate;
15578               break;
15579
15580             default:
15581               gcc_unreachable ();
15582             }
15583
15584           cop0 = x;
15585           cop1 = CONST0_RTX (mode);
15586         }
15587     }
15588
15589   x = ix86_expand_sse_cmp (operands[0], code, cop0, cop1,
15590                            operands[1+negate], operands[2-negate]);
15591
15592   ix86_expand_sse_movcc (operands[0], x, operands[1+negate],
15593                          operands[2-negate]);
15594   return true;
15595 }
15596
15597 /* Unpack OP[1] into the next wider integer vector type.  UNSIGNED_P is
15598    true if we should do zero extension, else sign extension.  HIGH_P is
15599    true if we want the N/2 high elements, else the low elements.  */
15600
15601 void
15602 ix86_expand_sse_unpack (rtx operands[2], bool unsigned_p, bool high_p)
15603 {
15604   enum machine_mode imode = GET_MODE (operands[1]);
15605   rtx (*unpack)(rtx, rtx, rtx);
15606   rtx se, dest;
15607
15608   switch (imode)
15609     {
15610     case V16QImode:
15611       if (high_p)
15612         unpack = gen_vec_interleave_highv16qi;
15613       else
15614         unpack = gen_vec_interleave_lowv16qi;
15615       break;
15616     case V8HImode:
15617       if (high_p)
15618         unpack = gen_vec_interleave_highv8hi;
15619       else
15620         unpack = gen_vec_interleave_lowv8hi;
15621       break;
15622     case V4SImode:
15623       if (high_p)
15624         unpack = gen_vec_interleave_highv4si;
15625       else
15626         unpack = gen_vec_interleave_lowv4si;
15627       break;
15628     default:
15629       gcc_unreachable ();
15630     }
15631
15632   dest = gen_lowpart (imode, operands[0]);
15633
15634   if (unsigned_p)
15635     se = force_reg (imode, CONST0_RTX (imode));
15636   else
15637     se = ix86_expand_sse_cmp (gen_reg_rtx (imode), GT, CONST0_RTX (imode),
15638                               operands[1], pc_rtx, pc_rtx);
15639
15640   emit_insn (unpack (dest, operands[1], se));
15641 }
15642
15643 /* This function performs the same task as ix86_expand_sse_unpack,
15644    but with SSE4.1 instructions.  */
15645
15646 void
15647 ix86_expand_sse4_unpack (rtx operands[2], bool unsigned_p, bool high_p)
15648 {
15649   enum machine_mode imode = GET_MODE (operands[1]);
15650   rtx (*unpack)(rtx, rtx);
15651   rtx src, dest;
15652
15653   switch (imode)
15654     {
15655     case V16QImode:
15656       if (unsigned_p)
15657         unpack = gen_sse4_1_zero_extendv8qiv8hi2;
15658       else
15659         unpack = gen_sse4_1_extendv8qiv8hi2;
15660       break;
15661     case V8HImode:
15662       if (unsigned_p)
15663         unpack = gen_sse4_1_zero_extendv4hiv4si2;
15664       else
15665         unpack = gen_sse4_1_extendv4hiv4si2;
15666       break;
15667     case V4SImode:
15668       if (unsigned_p)
15669         unpack = gen_sse4_1_zero_extendv2siv2di2;
15670       else
15671         unpack = gen_sse4_1_extendv2siv2di2;
15672       break;
15673     default:
15674       gcc_unreachable ();
15675     }
15676
15677   dest = operands[0];
15678   if (high_p)
15679     {
15680       /* Shift higher 8 bytes to lower 8 bytes.  */
15681       src = gen_reg_rtx (imode);
15682       emit_insn (gen_sse2_lshrti3 (gen_lowpart (TImode, src),
15683                                    gen_lowpart (TImode, operands[1]),
15684                                    GEN_INT (64)));
15685     }
15686   else
15687     src = operands[1];
15688
15689   emit_insn (unpack (dest, src));
15690 }
15691
15692 /* This function performs the same task as ix86_expand_sse_unpack,
15693    but with sse5 instructions.  */
15694
15695 void
15696 ix86_expand_sse5_unpack (rtx operands[2], bool unsigned_p, bool high_p)
15697 {
15698   enum machine_mode imode = GET_MODE (operands[1]);
15699   int pperm_bytes[16];
15700   int i;
15701   int h = (high_p) ? 8 : 0;
15702   int h2;
15703   int sign_extend;
15704   rtvec v = rtvec_alloc (16);
15705   rtvec vs;
15706   rtx x, p;
15707   rtx op0 = operands[0], op1 = operands[1];
15708
15709   switch (imode)
15710     {
15711     case V16QImode:
15712       vs = rtvec_alloc (8);
15713       h2 = (high_p) ? 8 : 0;
15714       for (i = 0; i < 8; i++)
15715         {
15716           pperm_bytes[2*i+0] = PPERM_SRC | PPERM_SRC2 | i | h;
15717           pperm_bytes[2*i+1] = ((unsigned_p)
15718                                 ? PPERM_ZERO
15719                                 : PPERM_SIGN | PPERM_SRC2 | i | h);
15720         }
15721
15722       for (i = 0; i < 16; i++)
15723         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15724
15725       for (i = 0; i < 8; i++)
15726         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
15727
15728       p = gen_rtx_PARALLEL (VOIDmode, vs);
15729       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15730       if (unsigned_p)
15731         emit_insn (gen_sse5_pperm_zero_v16qi_v8hi (op0, op1, p, x));
15732       else
15733         emit_insn (gen_sse5_pperm_sign_v16qi_v8hi (op0, op1, p, x));
15734       break;
15735
15736     case V8HImode:
15737       vs = rtvec_alloc (4);
15738       h2 = (high_p) ? 4 : 0;
15739       for (i = 0; i < 4; i++)
15740         {
15741           sign_extend = ((unsigned_p)
15742                          ? PPERM_ZERO
15743                          : PPERM_SIGN | PPERM_SRC2 | ((2*i) + 1 + h));
15744           pperm_bytes[4*i+0] = PPERM_SRC | PPERM_SRC2 | ((2*i) + 0 + h);
15745           pperm_bytes[4*i+1] = PPERM_SRC | PPERM_SRC2 | ((2*i) + 1 + h);
15746           pperm_bytes[4*i+2] = sign_extend;
15747           pperm_bytes[4*i+3] = sign_extend;
15748         }
15749
15750       for (i = 0; i < 16; i++)
15751         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15752
15753       for (i = 0; i < 4; i++)
15754         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
15755
15756       p = gen_rtx_PARALLEL (VOIDmode, vs);
15757       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15758       if (unsigned_p)
15759         emit_insn (gen_sse5_pperm_zero_v8hi_v4si (op0, op1, p, x));
15760       else
15761         emit_insn (gen_sse5_pperm_sign_v8hi_v4si (op0, op1, p, x));
15762       break;
15763
15764     case V4SImode:
15765       vs = rtvec_alloc (2);
15766       h2 = (high_p) ? 2 : 0;
15767       for (i = 0; i < 2; i++)
15768         {
15769           sign_extend = ((unsigned_p)
15770                          ? PPERM_ZERO
15771                          : PPERM_SIGN | PPERM_SRC2 | ((4*i) + 3 + h));
15772           pperm_bytes[8*i+0] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 0 + h);
15773           pperm_bytes[8*i+1] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 1 + h);
15774           pperm_bytes[8*i+2] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 2 + h);
15775           pperm_bytes[8*i+3] = PPERM_SRC | PPERM_SRC2 | ((4*i) + 3 + h);
15776           pperm_bytes[8*i+4] = sign_extend;
15777           pperm_bytes[8*i+5] = sign_extend;
15778           pperm_bytes[8*i+6] = sign_extend;
15779           pperm_bytes[8*i+7] = sign_extend;
15780         }
15781
15782       for (i = 0; i < 16; i++)
15783         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15784
15785       for (i = 0; i < 2; i++)
15786         RTVEC_ELT (vs, i) = GEN_INT (i + h2);
15787
15788       p = gen_rtx_PARALLEL (VOIDmode, vs);
15789       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15790       if (unsigned_p)
15791         emit_insn (gen_sse5_pperm_zero_v4si_v2di (op0, op1, p, x));
15792       else
15793         emit_insn (gen_sse5_pperm_sign_v4si_v2di (op0, op1, p, x));
15794       break;
15795
15796     default:
15797       gcc_unreachable ();
15798     }
15799
15800   return;
15801 }
15802
15803 /* Pack the high bits from OPERANDS[1] and low bits from OPERANDS[2] into the
15804    next narrower integer vector type */
15805 void
15806 ix86_expand_sse5_pack (rtx operands[3])
15807 {
15808   enum machine_mode imode = GET_MODE (operands[0]);
15809   int pperm_bytes[16];
15810   int i;
15811   rtvec v = rtvec_alloc (16);
15812   rtx x;
15813   rtx op0 = operands[0];
15814   rtx op1 = operands[1];
15815   rtx op2 = operands[2];
15816
15817   switch (imode)
15818     {
15819     case V16QImode:
15820       for (i = 0; i < 8; i++)
15821         {
15822           pperm_bytes[i+0] = PPERM_SRC | PPERM_SRC1 | (i*2);
15823           pperm_bytes[i+8] = PPERM_SRC | PPERM_SRC2 | (i*2);
15824         }
15825
15826       for (i = 0; i < 16; i++)
15827         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15828
15829       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15830       emit_insn (gen_sse5_pperm_pack_v8hi_v16qi (op0, op1, op2, x));
15831       break;
15832
15833     case V8HImode:
15834       for (i = 0; i < 4; i++)
15835         {
15836           pperm_bytes[(2*i)+0] = PPERM_SRC | PPERM_SRC1 | ((i*4) + 0);
15837           pperm_bytes[(2*i)+1] = PPERM_SRC | PPERM_SRC1 | ((i*4) + 1);
15838           pperm_bytes[(2*i)+8] = PPERM_SRC | PPERM_SRC2 | ((i*4) + 0);
15839           pperm_bytes[(2*i)+9] = PPERM_SRC | PPERM_SRC2 | ((i*4) + 1);
15840         }
15841
15842       for (i = 0; i < 16; i++)
15843         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15844
15845       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15846       emit_insn (gen_sse5_pperm_pack_v4si_v8hi (op0, op1, op2, x));
15847       break;
15848
15849     case V4SImode:
15850       for (i = 0; i < 2; i++)
15851         {
15852           pperm_bytes[(4*i)+0]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 0);
15853           pperm_bytes[(4*i)+1]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 1);
15854           pperm_bytes[(4*i)+2]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 2);
15855           pperm_bytes[(4*i)+3]  = PPERM_SRC | PPERM_SRC1 | ((i*8) + 3);
15856           pperm_bytes[(4*i)+8]  = PPERM_SRC | PPERM_SRC2 | ((i*8) + 0);
15857           pperm_bytes[(4*i)+9]  = PPERM_SRC | PPERM_SRC2 | ((i*8) + 1);
15858           pperm_bytes[(4*i)+10] = PPERM_SRC | PPERM_SRC2 | ((i*8) + 2);
15859           pperm_bytes[(4*i)+11] = PPERM_SRC | PPERM_SRC2 | ((i*8) + 3);
15860         }
15861
15862       for (i = 0; i < 16; i++)
15863         RTVEC_ELT (v, i) = GEN_INT (pperm_bytes[i]);
15864
15865       x = force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, v));
15866       emit_insn (gen_sse5_pperm_pack_v2di_v4si (op0, op1, op2, x));
15867       break;
15868
15869     default:
15870       gcc_unreachable ();
15871     }
15872
15873   return;
15874 }
15875
15876 /* Expand conditional increment or decrement using adb/sbb instructions.
15877    The default case using setcc followed by the conditional move can be
15878    done by generic code.  */
15879 int
15880 ix86_expand_int_addcc (rtx operands[])
15881 {
15882   enum rtx_code code = GET_CODE (operands[1]);
15883   rtx compare_op;
15884   rtx val = const0_rtx;
15885   bool fpcmp = false;
15886   enum machine_mode mode = GET_MODE (operands[0]);
15887
15888   if (operands[3] != const1_rtx
15889       && operands[3] != constm1_rtx)
15890     return 0;
15891   if (!ix86_expand_carry_flag_compare (code, ix86_compare_op0,
15892                                        ix86_compare_op1, &compare_op))
15893      return 0;
15894   code = GET_CODE (compare_op);
15895
15896   if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
15897       || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
15898     {
15899       fpcmp = true;
15900       code = ix86_fp_compare_code_to_integer (code);
15901     }
15902
15903   if (code != LTU)
15904     {
15905       val = constm1_rtx;
15906       if (fpcmp)
15907         PUT_CODE (compare_op,
15908                   reverse_condition_maybe_unordered
15909                     (GET_CODE (compare_op)));
15910       else
15911         PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
15912     }
15913   PUT_MODE (compare_op, mode);
15914
15915   /* Construct either adc or sbb insn.  */
15916   if ((code == LTU) == (operands[3] == constm1_rtx))
15917     {
15918       switch (GET_MODE (operands[0]))
15919         {
15920           case QImode:
15921             emit_insn (gen_subqi3_carry (operands[0], operands[2], val, compare_op));
15922             break;
15923           case HImode:
15924             emit_insn (gen_subhi3_carry (operands[0], operands[2], val, compare_op));
15925             break;
15926           case SImode:
15927             emit_insn (gen_subsi3_carry (operands[0], operands[2], val, compare_op));
15928             break;
15929           case DImode:
15930             emit_insn (gen_subdi3_carry_rex64 (operands[0], operands[2], val, compare_op));
15931             break;
15932           default:
15933             gcc_unreachable ();
15934         }
15935     }
15936   else
15937     {
15938       switch (GET_MODE (operands[0]))
15939         {
15940           case QImode:
15941             emit_insn (gen_addqi3_carry (operands[0], operands[2], val, compare_op));
15942             break;
15943           case HImode:
15944             emit_insn (gen_addhi3_carry (operands[0], operands[2], val, compare_op));
15945             break;
15946           case SImode:
15947             emit_insn (gen_addsi3_carry (operands[0], operands[2], val, compare_op));
15948             break;
15949           case DImode:
15950             emit_insn (gen_adddi3_carry_rex64 (operands[0], operands[2], val, compare_op));
15951             break;
15952           default:
15953             gcc_unreachable ();
15954         }
15955     }
15956   return 1; /* DONE */
15957 }
15958
15959
15960 /* Split operands 0 and 1 into SImode parts.  Similar to split_di, but
15961    works for floating pointer parameters and nonoffsetable memories.
15962    For pushes, it returns just stack offsets; the values will be saved
15963    in the right order.  Maximally three parts are generated.  */
15964
15965 static int
15966 ix86_split_to_parts (rtx operand, rtx *parts, enum machine_mode mode)
15967 {
15968   int size;
15969
15970   if (!TARGET_64BIT)
15971     size = mode==XFmode ? 3 : GET_MODE_SIZE (mode) / 4;
15972   else
15973     size = (GET_MODE_SIZE (mode) + 4) / 8;
15974
15975   gcc_assert (!REG_P (operand) || !MMX_REGNO_P (REGNO (operand)));
15976   gcc_assert (size >= 2 && size <= 4);
15977
15978   /* Optimize constant pool reference to immediates.  This is used by fp
15979      moves, that force all constants to memory to allow combining.  */
15980   if (MEM_P (operand) && MEM_READONLY_P (operand))
15981     {
15982       rtx tmp = maybe_get_pool_constant (operand);
15983       if (tmp)
15984         operand = tmp;
15985     }
15986
15987   if (MEM_P (operand) && !offsettable_memref_p (operand))
15988     {
15989       /* The only non-offsetable memories we handle are pushes.  */
15990       int ok = push_operand (operand, VOIDmode);
15991
15992       gcc_assert (ok);
15993
15994       operand = copy_rtx (operand);
15995       PUT_MODE (operand, Pmode);
15996       parts[0] = parts[1] = parts[2] = parts[3] = operand;
15997       return size;
15998     }
15999
16000   if (GET_CODE (operand) == CONST_VECTOR)
16001     {
16002       enum machine_mode imode = int_mode_for_mode (mode);
16003       /* Caution: if we looked through a constant pool memory above,
16004          the operand may actually have a different mode now.  That's
16005          ok, since we want to pun this all the way back to an integer.  */
16006       operand = simplify_subreg (imode, operand, GET_MODE (operand), 0);
16007       gcc_assert (operand != NULL);
16008       mode = imode;
16009     }
16010
16011   if (!TARGET_64BIT)
16012     {
16013       if (mode == DImode)
16014         split_di (&operand, 1, &parts[0], &parts[1]);
16015       else
16016         {
16017           int i;
16018
16019           if (REG_P (operand))
16020             {
16021               gcc_assert (reload_completed);
16022               for (i = 0; i < size; i++)
16023                 parts[i] = gen_rtx_REG (SImode, REGNO (operand) + i);
16024             }
16025           else if (offsettable_memref_p (operand))
16026             {
16027               operand = adjust_address (operand, SImode, 0);
16028               parts[0] = operand;
16029               for (i = 1; i < size; i++)
16030                 parts[i] = adjust_address (operand, SImode, 4 * i);
16031             }
16032           else if (GET_CODE (operand) == CONST_DOUBLE)
16033             {
16034               REAL_VALUE_TYPE r;
16035               long l[4];
16036
16037               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
16038               switch (mode)
16039                 {
16040                 case TFmode:
16041                   real_to_target (l, &r, mode);
16042                   parts[3] = gen_int_mode (l[3], SImode);
16043                   parts[2] = gen_int_mode (l[2], SImode);
16044                   break;
16045                 case XFmode:
16046                   REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
16047                   parts[2] = gen_int_mode (l[2], SImode);
16048                   break;
16049                 case DFmode:
16050                   REAL_VALUE_TO_TARGET_DOUBLE (r, l);
16051                   break;
16052                 default:
16053                   gcc_unreachable ();
16054                 }
16055               parts[1] = gen_int_mode (l[1], SImode);
16056               parts[0] = gen_int_mode (l[0], SImode);
16057             }
16058           else
16059             gcc_unreachable ();
16060         }
16061     }
16062   else
16063     {
16064       if (mode == TImode)
16065         split_ti (&operand, 1, &parts[0], &parts[1]);
16066       if (mode == XFmode || mode == TFmode)
16067         {
16068           enum machine_mode upper_mode = mode==XFmode ? SImode : DImode;
16069           if (REG_P (operand))
16070             {
16071               gcc_assert (reload_completed);
16072               parts[0] = gen_rtx_REG (DImode, REGNO (operand) + 0);
16073               parts[1] = gen_rtx_REG (upper_mode, REGNO (operand) + 1);
16074             }
16075           else if (offsettable_memref_p (operand))
16076             {
16077               operand = adjust_address (operand, DImode, 0);
16078               parts[0] = operand;
16079               parts[1] = adjust_address (operand, upper_mode, 8);
16080             }
16081           else if (GET_CODE (operand) == CONST_DOUBLE)
16082             {
16083               REAL_VALUE_TYPE r;
16084               long l[4];
16085
16086               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
16087               real_to_target (l, &r, mode);
16088
16089               /* Do not use shift by 32 to avoid warning on 32bit systems.  */
16090               if (HOST_BITS_PER_WIDE_INT >= 64)
16091                 parts[0]
16092                   = gen_int_mode
16093                       ((l[0] & (((HOST_WIDE_INT) 2 << 31) - 1))
16094                        + ((((HOST_WIDE_INT) l[1]) << 31) << 1),
16095                        DImode);
16096               else
16097                 parts[0] = immed_double_const (l[0], l[1], DImode);
16098
16099               if (upper_mode == SImode)
16100                 parts[1] = gen_int_mode (l[2], SImode);
16101               else if (HOST_BITS_PER_WIDE_INT >= 64)
16102                 parts[1]
16103                   = gen_int_mode
16104                       ((l[2] & (((HOST_WIDE_INT) 2 << 31) - 1))
16105                        + ((((HOST_WIDE_INT) l[3]) << 31) << 1),
16106                        DImode);
16107               else
16108                 parts[1] = immed_double_const (l[2], l[3], DImode);
16109             }
16110           else
16111             gcc_unreachable ();
16112         }
16113     }
16114
16115   return size;
16116 }
16117
16118 /* Emit insns to perform a move or push of DI, DF, XF, and TF values.
16119    Return false when normal moves are needed; true when all required
16120    insns have been emitted.  Operands 2-4 contain the input values
16121    int the correct order; operands 5-7 contain the output values.  */
16122
16123 void
16124 ix86_split_long_move (rtx operands[])
16125 {
16126   rtx part[2][4];
16127   int nparts, i, j;
16128   int push = 0;
16129   int collisions = 0;
16130   enum machine_mode mode = GET_MODE (operands[0]);
16131   bool collisionparts[4];
16132
16133   /* The DFmode expanders may ask us to move double.
16134      For 64bit target this is single move.  By hiding the fact
16135      here we simplify i386.md splitters.  */
16136   if (GET_MODE_SIZE (GET_MODE (operands[0])) == 8 && TARGET_64BIT)
16137     {
16138       /* Optimize constant pool reference to immediates.  This is used by
16139          fp moves, that force all constants to memory to allow combining.  */
16140
16141       if (MEM_P (operands[1])
16142           && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
16143           && CONSTANT_POOL_ADDRESS_P (XEXP (operands[1], 0)))
16144         operands[1] = get_pool_constant (XEXP (operands[1], 0));
16145       if (push_operand (operands[0], VOIDmode))
16146         {
16147           operands[0] = copy_rtx (operands[0]);
16148           PUT_MODE (operands[0], Pmode);
16149         }
16150       else
16151         operands[0] = gen_lowpart (DImode, operands[0]);
16152       operands[1] = gen_lowpart (DImode, operands[1]);
16153       emit_move_insn (operands[0], operands[1]);
16154       return;
16155     }
16156
16157   /* The only non-offsettable memory we handle is push.  */
16158   if (push_operand (operands[0], VOIDmode))
16159     push = 1;
16160   else
16161     gcc_assert (!MEM_P (operands[0])
16162                 || offsettable_memref_p (operands[0]));
16163
16164   nparts = ix86_split_to_parts (operands[1], part[1], GET_MODE (operands[0]));
16165   ix86_split_to_parts (operands[0], part[0], GET_MODE (operands[0]));
16166
16167   /* When emitting push, take care for source operands on the stack.  */
16168   if (push && MEM_P (operands[1])
16169       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
16170     for (i = 0; i < nparts - 1; i++)
16171       part[1][i] = change_address (part[1][i],
16172                                    GET_MODE (part[1][i]),
16173                                    XEXP (part[1][i + 1], 0));
16174
16175   /* We need to do copy in the right order in case an address register
16176      of the source overlaps the destination.  */
16177   if (REG_P (part[0][0]) && MEM_P (part[1][0]))
16178     {
16179       rtx tmp;
16180
16181       for (i = 0; i < nparts; i++)
16182         {
16183           collisionparts[i]
16184             = reg_overlap_mentioned_p (part[0][i], XEXP (part[1][0], 0));
16185           if (collisionparts[i])
16186             collisions++;
16187         }
16188
16189       /* Collision in the middle part can be handled by reordering.  */
16190       if (collisions == 1 && nparts == 3 && collisionparts [1])
16191         {
16192           tmp = part[0][1]; part[0][1] = part[0][2]; part[0][2] = tmp;
16193           tmp = part[1][1]; part[1][1] = part[1][2]; part[1][2] = tmp;
16194         }
16195       else if (collisions == 1
16196                && nparts == 4
16197                && (collisionparts [1] || collisionparts [2]))
16198         {
16199           if (collisionparts [1])
16200             {
16201               tmp = part[0][1]; part[0][1] = part[0][2]; part[0][2] = tmp;
16202               tmp = part[1][1]; part[1][1] = part[1][2]; part[1][2] = tmp;
16203             }
16204           else
16205             {
16206               tmp = part[0][2]; part[0][2] = part[0][3]; part[0][3] = tmp;
16207               tmp = part[1][2]; part[1][2] = part[1][3]; part[1][3] = tmp;
16208             }
16209         }
16210
16211       /* If there are more collisions, we can't handle it by reordering.
16212          Do an lea to the last part and use only one colliding move.  */
16213       else if (collisions > 1)
16214         {
16215           rtx base;
16216
16217           collisions = 1;
16218
16219           base = part[0][nparts - 1];
16220
16221           /* Handle the case when the last part isn't valid for lea.
16222              Happens in 64-bit mode storing the 12-byte XFmode.  */
16223           if (GET_MODE (base) != Pmode)
16224             base = gen_rtx_REG (Pmode, REGNO (base));
16225
16226           emit_insn (gen_rtx_SET (VOIDmode, base, XEXP (part[1][0], 0)));
16227           part[1][0] = replace_equiv_address (part[1][0], base);
16228           for (i = 1; i < nparts; i++)
16229             {
16230               tmp = plus_constant (base, UNITS_PER_WORD * i);
16231               part[1][i] = replace_equiv_address (part[1][i], tmp);
16232             }
16233         }
16234     }
16235
16236   if (push)
16237     {
16238       if (!TARGET_64BIT)
16239         {
16240           if (nparts == 3)
16241             {
16242               if (TARGET_128BIT_LONG_DOUBLE && mode == XFmode)
16243                 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, GEN_INT (-4)));
16244               emit_move_insn (part[0][2], part[1][2]);
16245             }
16246           else if (nparts == 4)
16247             {
16248               emit_move_insn (part[0][3], part[1][3]);
16249               emit_move_insn (part[0][2], part[1][2]);
16250             }
16251         }
16252       else
16253         {
16254           /* In 64bit mode we don't have 32bit push available.  In case this is
16255              register, it is OK - we will just use larger counterpart.  We also
16256              retype memory - these comes from attempt to avoid REX prefix on
16257              moving of second half of TFmode value.  */
16258           if (GET_MODE (part[1][1]) == SImode)
16259             {
16260               switch (GET_CODE (part[1][1]))
16261                 {
16262                 case MEM:
16263                   part[1][1] = adjust_address (part[1][1], DImode, 0);
16264                   break;
16265
16266                 case REG:
16267                   part[1][1] = gen_rtx_REG (DImode, REGNO (part[1][1]));
16268                   break;
16269
16270                 default:
16271                   gcc_unreachable ();
16272                 }
16273
16274               if (GET_MODE (part[1][0]) == SImode)
16275                 part[1][0] = part[1][1];
16276             }
16277         }
16278       emit_move_insn (part[0][1], part[1][1]);
16279       emit_move_insn (part[0][0], part[1][0]);
16280       return;
16281     }
16282
16283   /* Choose correct order to not overwrite the source before it is copied.  */
16284   if ((REG_P (part[0][0])
16285        && REG_P (part[1][1])
16286        && (REGNO (part[0][0]) == REGNO (part[1][1])
16287            || (nparts == 3
16288                && REGNO (part[0][0]) == REGNO (part[1][2]))
16289            || (nparts == 4
16290                && REGNO (part[0][0]) == REGNO (part[1][3]))))
16291       || (collisions > 0
16292           && reg_overlap_mentioned_p (part[0][0], XEXP (part[1][0], 0))))
16293     {
16294       for (i = 0, j = nparts - 1; i < nparts; i++, j--)
16295         {
16296           operands[2 + i] = part[0][j];
16297           operands[6 + i] = part[1][j];
16298         }
16299     }
16300   else
16301     {
16302       for (i = 0; i < nparts; i++)
16303         {
16304           operands[2 + i] = part[0][i];
16305           operands[6 + i] = part[1][i];
16306         }
16307     }
16308
16309   /* If optimizing for size, attempt to locally unCSE nonzero constants.  */
16310   if (optimize_insn_for_size_p ())
16311     {
16312       for (j = 0; j < nparts - 1; j++)
16313         if (CONST_INT_P (operands[6 + j])
16314             && operands[6 + j] != const0_rtx
16315             && REG_P (operands[2 + j]))
16316           for (i = j; i < nparts - 1; i++)
16317             if (CONST_INT_P (operands[7 + i])
16318                 && INTVAL (operands[7 + i]) == INTVAL (operands[6 + j]))
16319               operands[7 + i] = operands[2 + j];
16320     }
16321
16322   for (i = 0; i < nparts; i++)
16323     emit_move_insn (operands[2 + i], operands[6 + i]);
16324
16325   return;
16326 }
16327
16328 /* Helper function of ix86_split_ashl used to generate an SImode/DImode
16329    left shift by a constant, either using a single shift or
16330    a sequence of add instructions.  */
16331
16332 static void
16333 ix86_expand_ashl_const (rtx operand, int count, enum machine_mode mode)
16334 {
16335   if (count == 1)
16336     {
16337       emit_insn ((mode == DImode
16338                   ? gen_addsi3
16339                   : gen_adddi3) (operand, operand, operand));
16340     }
16341   else if (!optimize_insn_for_size_p ()
16342            && count * ix86_cost->add <= ix86_cost->shift_const)
16343     {
16344       int i;
16345       for (i=0; i<count; i++)
16346         {
16347           emit_insn ((mode == DImode
16348                       ? gen_addsi3
16349                       : gen_adddi3) (operand, operand, operand));
16350         }
16351     }
16352   else
16353     emit_insn ((mode == DImode
16354                 ? gen_ashlsi3
16355                 : gen_ashldi3) (operand, operand, GEN_INT (count)));
16356 }
16357
16358 void
16359 ix86_split_ashl (rtx *operands, rtx scratch, enum machine_mode mode)
16360 {
16361   rtx low[2], high[2];
16362   int count;
16363   const int single_width = mode == DImode ? 32 : 64;
16364
16365   if (CONST_INT_P (operands[2]))
16366     {
16367       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
16368       count = INTVAL (operands[2]) & (single_width * 2 - 1);
16369
16370       if (count >= single_width)
16371         {
16372           emit_move_insn (high[0], low[1]);
16373           emit_move_insn (low[0], const0_rtx);
16374
16375           if (count > single_width)
16376             ix86_expand_ashl_const (high[0], count - single_width, mode);
16377         }
16378       else
16379         {
16380           if (!rtx_equal_p (operands[0], operands[1]))
16381             emit_move_insn (operands[0], operands[1]);
16382           emit_insn ((mode == DImode
16383                      ? gen_x86_shld
16384                      : gen_x86_64_shld) (high[0], low[0], GEN_INT (count)));
16385           ix86_expand_ashl_const (low[0], count, mode);
16386         }
16387       return;
16388     }
16389
16390   (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16391
16392   if (operands[1] == const1_rtx)
16393     {
16394       /* Assuming we've chosen a QImode capable registers, then 1 << N
16395          can be done with two 32/64-bit shifts, no branches, no cmoves.  */
16396       if (ANY_QI_REG_P (low[0]) && ANY_QI_REG_P (high[0]))
16397         {
16398           rtx s, d, flags = gen_rtx_REG (CCZmode, FLAGS_REG);
16399
16400           ix86_expand_clear (low[0]);
16401           ix86_expand_clear (high[0]);
16402           emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (single_width)));
16403
16404           d = gen_lowpart (QImode, low[0]);
16405           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
16406           s = gen_rtx_EQ (QImode, flags, const0_rtx);
16407           emit_insn (gen_rtx_SET (VOIDmode, d, s));
16408
16409           d = gen_lowpart (QImode, high[0]);
16410           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
16411           s = gen_rtx_NE (QImode, flags, const0_rtx);
16412           emit_insn (gen_rtx_SET (VOIDmode, d, s));
16413         }
16414
16415       /* Otherwise, we can get the same results by manually performing
16416          a bit extract operation on bit 5/6, and then performing the two
16417          shifts.  The two methods of getting 0/1 into low/high are exactly
16418          the same size.  Avoiding the shift in the bit extract case helps
16419          pentium4 a bit; no one else seems to care much either way.  */
16420       else
16421         {
16422           rtx x;
16423
16424           if (TARGET_PARTIAL_REG_STALL && !optimize_insn_for_size_p ())
16425             x = gen_rtx_ZERO_EXTEND (mode == DImode ? SImode : DImode, operands[2]);
16426           else
16427             x = gen_lowpart (mode == DImode ? SImode : DImode, operands[2]);
16428           emit_insn (gen_rtx_SET (VOIDmode, high[0], x));
16429
16430           emit_insn ((mode == DImode
16431                       ? gen_lshrsi3
16432                       : gen_lshrdi3) (high[0], high[0], GEN_INT (mode == DImode ? 5 : 6)));
16433           emit_insn ((mode == DImode
16434                       ? gen_andsi3
16435                       : gen_anddi3) (high[0], high[0], GEN_INT (1)));
16436           emit_move_insn (low[0], high[0]);
16437           emit_insn ((mode == DImode
16438                       ? gen_xorsi3
16439                       : gen_xordi3) (low[0], low[0], GEN_INT (1)));
16440         }
16441
16442       emit_insn ((mode == DImode
16443                     ? gen_ashlsi3
16444                     : gen_ashldi3) (low[0], low[0], operands[2]));
16445       emit_insn ((mode == DImode
16446                     ? gen_ashlsi3
16447                     : gen_ashldi3) (high[0], high[0], operands[2]));
16448       return;
16449     }
16450
16451   if (operands[1] == constm1_rtx)
16452     {
16453       /* For -1 << N, we can avoid the shld instruction, because we
16454          know that we're shifting 0...31/63 ones into a -1.  */
16455       emit_move_insn (low[0], constm1_rtx);
16456       if (optimize_insn_for_size_p ())
16457         emit_move_insn (high[0], low[0]);
16458       else
16459         emit_move_insn (high[0], constm1_rtx);
16460     }
16461   else
16462     {
16463       if (!rtx_equal_p (operands[0], operands[1]))
16464         emit_move_insn (operands[0], operands[1]);
16465
16466       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16467       emit_insn ((mode == DImode
16468                   ? gen_x86_shld
16469                   : gen_x86_64_shld) (high[0], low[0], operands[2]));
16470     }
16471
16472   emit_insn ((mode == DImode ? gen_ashlsi3 : gen_ashldi3) (low[0], low[0], operands[2]));
16473
16474   if (TARGET_CMOVE && scratch)
16475     {
16476       ix86_expand_clear (scratch);
16477       emit_insn ((mode == DImode
16478                   ? gen_x86_shift_adj_1
16479                   : gen_x86_64_shift_adj_1) (high[0], low[0], operands[2],
16480                                              scratch));
16481     }
16482   else
16483     emit_insn ((mode == DImode
16484                 ? gen_x86_shift_adj_2
16485                 : gen_x86_64_shift_adj_2) (high[0], low[0], operands[2]));
16486 }
16487
16488 void
16489 ix86_split_ashr (rtx *operands, rtx scratch, enum machine_mode mode)
16490 {
16491   rtx low[2], high[2];
16492   int count;
16493   const int single_width = mode == DImode ? 32 : 64;
16494
16495   if (CONST_INT_P (operands[2]))
16496     {
16497       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
16498       count = INTVAL (operands[2]) & (single_width * 2 - 1);
16499
16500       if (count == single_width * 2 - 1)
16501         {
16502           emit_move_insn (high[0], high[1]);
16503           emit_insn ((mode == DImode
16504                       ? gen_ashrsi3
16505                       : gen_ashrdi3) (high[0], high[0],
16506                                       GEN_INT (single_width - 1)));
16507           emit_move_insn (low[0], high[0]);
16508
16509         }
16510       else if (count >= single_width)
16511         {
16512           emit_move_insn (low[0], high[1]);
16513           emit_move_insn (high[0], low[0]);
16514           emit_insn ((mode == DImode
16515                       ? gen_ashrsi3
16516                       : gen_ashrdi3) (high[0], high[0],
16517                                       GEN_INT (single_width - 1)));
16518           if (count > single_width)
16519             emit_insn ((mode == DImode
16520                         ? gen_ashrsi3
16521                         : gen_ashrdi3) (low[0], low[0],
16522                                         GEN_INT (count - single_width)));
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_shrd
16530                       : gen_x86_64_shrd) (low[0], high[0], GEN_INT (count)));
16531           emit_insn ((mode == DImode
16532                       ? gen_ashrsi3
16533                       : gen_ashrdi3) (high[0], high[0], GEN_INT (count)));
16534         }
16535     }
16536   else
16537     {
16538       if (!rtx_equal_p (operands[0], operands[1]))
16539         emit_move_insn (operands[0], operands[1]);
16540
16541       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16542
16543       emit_insn ((mode == DImode
16544                   ? gen_x86_shrd
16545                   : gen_x86_64_shrd) (low[0], high[0], operands[2]));
16546       emit_insn ((mode == DImode
16547                   ? gen_ashrsi3
16548                   : gen_ashrdi3)  (high[0], high[0], operands[2]));
16549
16550       if (TARGET_CMOVE && scratch)
16551         {
16552           emit_move_insn (scratch, high[0]);
16553           emit_insn ((mode == DImode
16554                       ? gen_ashrsi3
16555                       : gen_ashrdi3) (scratch, scratch,
16556                                       GEN_INT (single_width - 1)));
16557           emit_insn ((mode == DImode
16558                       ? gen_x86_shift_adj_1
16559                       : gen_x86_64_shift_adj_1) (low[0], high[0], operands[2],
16560                                                  scratch));
16561         }
16562       else
16563         emit_insn ((mode == DImode
16564                     ? gen_x86_shift_adj_3
16565                     : gen_x86_64_shift_adj_3) (low[0], high[0], operands[2]));
16566     }
16567 }
16568
16569 void
16570 ix86_split_lshr (rtx *operands, rtx scratch, enum machine_mode mode)
16571 {
16572   rtx low[2], high[2];
16573   int count;
16574   const int single_width = mode == DImode ? 32 : 64;
16575
16576   if (CONST_INT_P (operands[2]))
16577     {
16578       (mode == DImode ? split_di : split_ti) (operands, 2, low, high);
16579       count = INTVAL (operands[2]) & (single_width * 2 - 1);
16580
16581       if (count >= single_width)
16582         {
16583           emit_move_insn (low[0], high[1]);
16584           ix86_expand_clear (high[0]);
16585
16586           if (count > single_width)
16587             emit_insn ((mode == DImode
16588                         ? gen_lshrsi3
16589                         : gen_lshrdi3) (low[0], low[0],
16590                                         GEN_INT (count - single_width)));
16591         }
16592       else
16593         {
16594           if (!rtx_equal_p (operands[0], operands[1]))
16595             emit_move_insn (operands[0], operands[1]);
16596           emit_insn ((mode == DImode
16597                       ? gen_x86_shrd
16598                       : gen_x86_64_shrd) (low[0], high[0], GEN_INT (count)));
16599           emit_insn ((mode == DImode
16600                       ? gen_lshrsi3
16601                       : gen_lshrdi3) (high[0], high[0], GEN_INT (count)));
16602         }
16603     }
16604   else
16605     {
16606       if (!rtx_equal_p (operands[0], operands[1]))
16607         emit_move_insn (operands[0], operands[1]);
16608
16609       (mode == DImode ? split_di : split_ti) (operands, 1, low, high);
16610
16611       emit_insn ((mode == DImode
16612                   ? gen_x86_shrd
16613                   : gen_x86_64_shrd) (low[0], high[0], operands[2]));
16614       emit_insn ((mode == DImode
16615                   ? gen_lshrsi3
16616                   : gen_lshrdi3) (high[0], high[0], operands[2]));
16617
16618       /* Heh.  By reversing the arguments, we can reuse this pattern.  */
16619       if (TARGET_CMOVE && scratch)
16620         {
16621           ix86_expand_clear (scratch);
16622           emit_insn ((mode == DImode
16623                       ? gen_x86_shift_adj_1
16624                       : gen_x86_64_shift_adj_1) (low[0], high[0], operands[2],
16625                                                  scratch));
16626         }
16627       else
16628         emit_insn ((mode == DImode
16629                     ? gen_x86_shift_adj_2
16630                     : gen_x86_64_shift_adj_2) (low[0], high[0], operands[2]));
16631     }
16632 }
16633
16634 /* Predict just emitted jump instruction to be taken with probability PROB.  */
16635 static void
16636 predict_jump (int prob)
16637 {
16638   rtx insn = get_last_insn ();
16639   gcc_assert (JUMP_P (insn));
16640   REG_NOTES (insn)
16641     = gen_rtx_EXPR_LIST (REG_BR_PROB,
16642                          GEN_INT (prob),
16643                          REG_NOTES (insn));
16644 }
16645
16646 /* Helper function for the string operations below.  Dest VARIABLE whether
16647    it is aligned to VALUE bytes.  If true, jump to the label.  */
16648 static rtx
16649 ix86_expand_aligntest (rtx variable, int value, bool epilogue)
16650 {
16651   rtx label = gen_label_rtx ();
16652   rtx tmpcount = gen_reg_rtx (GET_MODE (variable));
16653   if (GET_MODE (variable) == DImode)
16654     emit_insn (gen_anddi3 (tmpcount, variable, GEN_INT (value)));
16655   else
16656     emit_insn (gen_andsi3 (tmpcount, variable, GEN_INT (value)));
16657   emit_cmp_and_jump_insns (tmpcount, const0_rtx, EQ, 0, GET_MODE (variable),
16658                            1, label);
16659   if (epilogue)
16660     predict_jump (REG_BR_PROB_BASE * 50 / 100);
16661   else
16662     predict_jump (REG_BR_PROB_BASE * 90 / 100);
16663   return label;
16664 }
16665
16666 /* Adjust COUNTER by the VALUE.  */
16667 static void
16668 ix86_adjust_counter (rtx countreg, HOST_WIDE_INT value)
16669 {
16670   if (GET_MODE (countreg) == DImode)
16671     emit_insn (gen_adddi3 (countreg, countreg, GEN_INT (-value)));
16672   else
16673     emit_insn (gen_addsi3 (countreg, countreg, GEN_INT (-value)));
16674 }
16675
16676 /* Zero extend possibly SImode EXP to Pmode register.  */
16677 rtx
16678 ix86_zero_extend_to_Pmode (rtx exp)
16679 {
16680   rtx r;
16681   if (GET_MODE (exp) == VOIDmode)
16682     return force_reg (Pmode, exp);
16683   if (GET_MODE (exp) == Pmode)
16684     return copy_to_mode_reg (Pmode, exp);
16685   r = gen_reg_rtx (Pmode);
16686   emit_insn (gen_zero_extendsidi2 (r, exp));
16687   return r;
16688 }
16689
16690 /* Divide COUNTREG by SCALE.  */
16691 static rtx
16692 scale_counter (rtx countreg, int scale)
16693 {
16694   rtx sc;
16695   rtx piece_size_mask;
16696
16697   if (scale == 1)
16698     return countreg;
16699   if (CONST_INT_P (countreg))
16700     return GEN_INT (INTVAL (countreg) / scale);
16701   gcc_assert (REG_P (countreg));
16702
16703   piece_size_mask = GEN_INT (scale - 1);
16704   sc = expand_simple_binop (GET_MODE (countreg), LSHIFTRT, countreg,
16705                             GEN_INT (exact_log2 (scale)),
16706                             NULL, 1, OPTAB_DIRECT);
16707   return sc;
16708 }
16709
16710 /* Return mode for the memcpy/memset loop counter.  Prefer SImode over
16711    DImode for constant loop counts.  */
16712
16713 static enum machine_mode
16714 counter_mode (rtx count_exp)
16715 {
16716   if (GET_MODE (count_exp) != VOIDmode)
16717     return GET_MODE (count_exp);
16718   if (GET_CODE (count_exp) != CONST_INT)
16719     return Pmode;
16720   if (TARGET_64BIT && (INTVAL (count_exp) & ~0xffffffff))
16721     return DImode;
16722   return SImode;
16723 }
16724
16725 /* When SRCPTR is non-NULL, output simple loop to move memory
16726    pointer to SRCPTR to DESTPTR via chunks of MODE unrolled UNROLL times,
16727    overall size is COUNT specified in bytes.  When SRCPTR is NULL, output the
16728    equivalent loop to set memory by VALUE (supposed to be in MODE).
16729
16730    The size is rounded down to whole number of chunk size moved at once.
16731    SRCMEM and DESTMEM provide MEMrtx to feed proper aliasing info.  */
16732
16733
16734 static void
16735 expand_set_or_movmem_via_loop (rtx destmem, rtx srcmem,
16736                                rtx destptr, rtx srcptr, rtx value,
16737                                rtx count, enum machine_mode mode, int unroll,
16738                                int expected_size)
16739 {
16740   rtx out_label, top_label, iter, tmp;
16741   enum machine_mode iter_mode = counter_mode (count);
16742   rtx piece_size = GEN_INT (GET_MODE_SIZE (mode) * unroll);
16743   rtx piece_size_mask = GEN_INT (~((GET_MODE_SIZE (mode) * unroll) - 1));
16744   rtx size;
16745   rtx x_addr;
16746   rtx y_addr;
16747   int i;
16748
16749   top_label = gen_label_rtx ();
16750   out_label = gen_label_rtx ();
16751   iter = gen_reg_rtx (iter_mode);
16752
16753   size = expand_simple_binop (iter_mode, AND, count, piece_size_mask,
16754                               NULL, 1, OPTAB_DIRECT);
16755   /* Those two should combine.  */
16756   if (piece_size == const1_rtx)
16757     {
16758       emit_cmp_and_jump_insns (size, const0_rtx, EQ, NULL_RTX, iter_mode,
16759                                true, out_label);
16760       predict_jump (REG_BR_PROB_BASE * 10 / 100);
16761     }
16762   emit_move_insn (iter, const0_rtx);
16763
16764   emit_label (top_label);
16765
16766   tmp = convert_modes (Pmode, iter_mode, iter, true);
16767   x_addr = gen_rtx_PLUS (Pmode, destptr, tmp);
16768   destmem = change_address (destmem, mode, x_addr);
16769
16770   if (srcmem)
16771     {
16772       y_addr = gen_rtx_PLUS (Pmode, srcptr, copy_rtx (tmp));
16773       srcmem = change_address (srcmem, mode, y_addr);
16774
16775       /* When unrolling for chips that reorder memory reads and writes,
16776          we can save registers by using single temporary.
16777          Also using 4 temporaries is overkill in 32bit mode.  */
16778       if (!TARGET_64BIT && 0)
16779         {
16780           for (i = 0; i < unroll; i++)
16781             {
16782               if (i)
16783                 {
16784                   destmem =
16785                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
16786                   srcmem =
16787                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
16788                 }
16789               emit_move_insn (destmem, srcmem);
16790             }
16791         }
16792       else
16793         {
16794           rtx tmpreg[4];
16795           gcc_assert (unroll <= 4);
16796           for (i = 0; i < unroll; i++)
16797             {
16798               tmpreg[i] = gen_reg_rtx (mode);
16799               if (i)
16800                 {
16801                   srcmem =
16802                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
16803                 }
16804               emit_move_insn (tmpreg[i], srcmem);
16805             }
16806           for (i = 0; i < unroll; i++)
16807             {
16808               if (i)
16809                 {
16810                   destmem =
16811                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
16812                 }
16813               emit_move_insn (destmem, tmpreg[i]);
16814             }
16815         }
16816     }
16817   else
16818     for (i = 0; i < unroll; i++)
16819       {
16820         if (i)
16821           destmem =
16822             adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
16823         emit_move_insn (destmem, value);
16824       }
16825
16826   tmp = expand_simple_binop (iter_mode, PLUS, iter, piece_size, iter,
16827                              true, OPTAB_LIB_WIDEN);
16828   if (tmp != iter)
16829     emit_move_insn (iter, tmp);
16830
16831   emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
16832                            true, top_label);
16833   if (expected_size != -1)
16834     {
16835       expected_size /= GET_MODE_SIZE (mode) * unroll;
16836       if (expected_size == 0)
16837         predict_jump (0);
16838       else if (expected_size > REG_BR_PROB_BASE)
16839         predict_jump (REG_BR_PROB_BASE - 1);
16840       else
16841         predict_jump (REG_BR_PROB_BASE - (REG_BR_PROB_BASE + expected_size / 2) / expected_size);
16842     }
16843   else
16844     predict_jump (REG_BR_PROB_BASE * 80 / 100);
16845   iter = ix86_zero_extend_to_Pmode (iter);
16846   tmp = expand_simple_binop (Pmode, PLUS, destptr, iter, destptr,
16847                              true, OPTAB_LIB_WIDEN);
16848   if (tmp != destptr)
16849     emit_move_insn (destptr, tmp);
16850   if (srcptr)
16851     {
16852       tmp = expand_simple_binop (Pmode, PLUS, srcptr, iter, srcptr,
16853                                  true, OPTAB_LIB_WIDEN);
16854       if (tmp != srcptr)
16855         emit_move_insn (srcptr, tmp);
16856     }
16857   emit_label (out_label);
16858 }
16859
16860 /* Output "rep; mov" instruction.
16861    Arguments have same meaning as for previous function */
16862 static void
16863 expand_movmem_via_rep_mov (rtx destmem, rtx srcmem,
16864                            rtx destptr, rtx srcptr,
16865                            rtx count,
16866                            enum machine_mode mode)
16867 {
16868   rtx destexp;
16869   rtx srcexp;
16870   rtx countreg;
16871
16872   /* If the size is known, it is shorter to use rep movs.  */
16873   if (mode == QImode && CONST_INT_P (count)
16874       && !(INTVAL (count) & 3))
16875     mode = SImode;
16876
16877   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
16878     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
16879   if (srcptr != XEXP (srcmem, 0) || GET_MODE (srcmem) != BLKmode)
16880     srcmem = adjust_automodify_address_nv (srcmem, BLKmode, srcptr, 0);
16881   countreg = ix86_zero_extend_to_Pmode (scale_counter (count, GET_MODE_SIZE (mode)));
16882   if (mode != QImode)
16883     {
16884       destexp = gen_rtx_ASHIFT (Pmode, countreg,
16885                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
16886       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
16887       srcexp = gen_rtx_ASHIFT (Pmode, countreg,
16888                                GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
16889       srcexp = gen_rtx_PLUS (Pmode, srcexp, srcptr);
16890     }
16891   else
16892     {
16893       destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
16894       srcexp = gen_rtx_PLUS (Pmode, srcptr, countreg);
16895     }
16896   if (CONST_INT_P (count))
16897     {
16898       count = GEN_INT (INTVAL (count)
16899                        & ~((HOST_WIDE_INT) GET_MODE_SIZE (mode) - 1));
16900       destmem = shallow_copy_rtx (destmem);
16901       srcmem = shallow_copy_rtx (srcmem);
16902       set_mem_size (destmem, count);
16903       set_mem_size (srcmem, count);
16904     }
16905   else
16906     {
16907       if (MEM_SIZE (destmem))
16908         set_mem_size (destmem, NULL_RTX);
16909       if (MEM_SIZE (srcmem))
16910         set_mem_size (srcmem, NULL_RTX);
16911     }
16912   emit_insn (gen_rep_mov (destptr, destmem, srcptr, srcmem, countreg,
16913                           destexp, srcexp));
16914 }
16915
16916 /* Output "rep; stos" instruction.
16917    Arguments have same meaning as for previous function */
16918 static void
16919 expand_setmem_via_rep_stos (rtx destmem, rtx destptr, rtx value,
16920                             rtx count, enum machine_mode mode,
16921                             rtx orig_value)
16922 {
16923   rtx destexp;
16924   rtx countreg;
16925
16926   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
16927     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
16928   value = force_reg (mode, gen_lowpart (mode, value));
16929   countreg = ix86_zero_extend_to_Pmode (scale_counter (count, GET_MODE_SIZE (mode)));
16930   if (mode != QImode)
16931     {
16932       destexp = gen_rtx_ASHIFT (Pmode, countreg,
16933                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
16934       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
16935     }
16936   else
16937     destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
16938   if (orig_value == const0_rtx && CONST_INT_P (count))
16939     {
16940       count = GEN_INT (INTVAL (count)
16941                        & ~((HOST_WIDE_INT) GET_MODE_SIZE (mode) - 1));
16942       destmem = shallow_copy_rtx (destmem);
16943       set_mem_size (destmem, count);
16944     }
16945   else if (MEM_SIZE (destmem))
16946     set_mem_size (destmem, NULL_RTX);
16947   emit_insn (gen_rep_stos (destptr, countreg, destmem, value, destexp));
16948 }
16949
16950 static void
16951 emit_strmov (rtx destmem, rtx srcmem,
16952              rtx destptr, rtx srcptr, enum machine_mode mode, int offset)
16953 {
16954   rtx src = adjust_automodify_address_nv (srcmem, mode, srcptr, offset);
16955   rtx dest = adjust_automodify_address_nv (destmem, mode, destptr, offset);
16956   emit_insn (gen_strmov (destptr, dest, srcptr, src));
16957 }
16958
16959 /* Output code to copy at most count & (max_size - 1) bytes from SRC to DEST.  */
16960 static void
16961 expand_movmem_epilogue (rtx destmem, rtx srcmem,
16962                         rtx destptr, rtx srcptr, rtx count, int max_size)
16963 {
16964   rtx src, dest;
16965   if (CONST_INT_P (count))
16966     {
16967       HOST_WIDE_INT countval = INTVAL (count);
16968       int offset = 0;
16969
16970       if ((countval & 0x10) && max_size > 16)
16971         {
16972           if (TARGET_64BIT)
16973             {
16974               emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset);
16975               emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset + 8);
16976             }
16977           else
16978             gcc_unreachable ();
16979           offset += 16;
16980         }
16981       if ((countval & 0x08) && max_size > 8)
16982         {
16983           if (TARGET_64BIT)
16984             emit_strmov (destmem, srcmem, destptr, srcptr, DImode, offset);
16985           else
16986             {
16987               emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset);
16988               emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset + 4);
16989             }
16990           offset += 8;
16991         }
16992       if ((countval & 0x04) && max_size > 4)
16993         {
16994           emit_strmov (destmem, srcmem, destptr, srcptr, SImode, offset);
16995           offset += 4;
16996         }
16997       if ((countval & 0x02) && max_size > 2)
16998         {
16999           emit_strmov (destmem, srcmem, destptr, srcptr, HImode, offset);
17000           offset += 2;
17001         }
17002       if ((countval & 0x01) && max_size > 1)
17003         {
17004           emit_strmov (destmem, srcmem, destptr, srcptr, QImode, offset);
17005           offset += 1;
17006         }
17007       return;
17008     }
17009   if (max_size > 8)
17010     {
17011       count = expand_simple_binop (GET_MODE (count), AND, count, GEN_INT (max_size - 1),
17012                                     count, 1, OPTAB_DIRECT);
17013       expand_set_or_movmem_via_loop (destmem, srcmem, destptr, srcptr, NULL,
17014                                      count, QImode, 1, 4);
17015       return;
17016     }
17017
17018   /* When there are stringops, we can cheaply increase dest and src pointers.
17019      Otherwise we save code size by maintaining offset (zero is readily
17020      available from preceding rep operation) and using x86 addressing modes.
17021    */
17022   if (TARGET_SINGLE_STRINGOP)
17023     {
17024       if (max_size > 4)
17025         {
17026           rtx label = ix86_expand_aligntest (count, 4, true);
17027           src = change_address (srcmem, SImode, srcptr);
17028           dest = change_address (destmem, SImode, destptr);
17029           emit_insn (gen_strmov (destptr, dest, srcptr, src));
17030           emit_label (label);
17031           LABEL_NUSES (label) = 1;
17032         }
17033       if (max_size > 2)
17034         {
17035           rtx label = ix86_expand_aligntest (count, 2, true);
17036           src = change_address (srcmem, HImode, srcptr);
17037           dest = change_address (destmem, HImode, destptr);
17038           emit_insn (gen_strmov (destptr, dest, srcptr, src));
17039           emit_label (label);
17040           LABEL_NUSES (label) = 1;
17041         }
17042       if (max_size > 1)
17043         {
17044           rtx label = ix86_expand_aligntest (count, 1, true);
17045           src = change_address (srcmem, QImode, srcptr);
17046           dest = change_address (destmem, QImode, destptr);
17047           emit_insn (gen_strmov (destptr, dest, srcptr, src));
17048           emit_label (label);
17049           LABEL_NUSES (label) = 1;
17050         }
17051     }
17052   else
17053     {
17054       rtx offset = force_reg (Pmode, const0_rtx);
17055       rtx tmp;
17056
17057       if (max_size > 4)
17058         {
17059           rtx label = ix86_expand_aligntest (count, 4, true);
17060           src = change_address (srcmem, SImode, srcptr);
17061           dest = change_address (destmem, SImode, destptr);
17062           emit_move_insn (dest, src);
17063           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (4), NULL,
17064                                      true, OPTAB_LIB_WIDEN);
17065           if (tmp != offset)
17066             emit_move_insn (offset, tmp);
17067           emit_label (label);
17068           LABEL_NUSES (label) = 1;
17069         }
17070       if (max_size > 2)
17071         {
17072           rtx label = ix86_expand_aligntest (count, 2, true);
17073           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
17074           src = change_address (srcmem, HImode, tmp);
17075           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
17076           dest = change_address (destmem, HImode, tmp);
17077           emit_move_insn (dest, src);
17078           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (2), tmp,
17079                                      true, OPTAB_LIB_WIDEN);
17080           if (tmp != offset)
17081             emit_move_insn (offset, tmp);
17082           emit_label (label);
17083           LABEL_NUSES (label) = 1;
17084         }
17085       if (max_size > 1)
17086         {
17087           rtx label = ix86_expand_aligntest (count, 1, true);
17088           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
17089           src = change_address (srcmem, QImode, tmp);
17090           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
17091           dest = change_address (destmem, QImode, tmp);
17092           emit_move_insn (dest, src);
17093           emit_label (label);
17094           LABEL_NUSES (label) = 1;
17095         }
17096     }
17097 }
17098
17099 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
17100 static void
17101 expand_setmem_epilogue_via_loop (rtx destmem, rtx destptr, rtx value,
17102                                  rtx count, int max_size)
17103 {
17104   count =
17105     expand_simple_binop (counter_mode (count), AND, count,
17106                          GEN_INT (max_size - 1), count, 1, OPTAB_DIRECT);
17107   expand_set_or_movmem_via_loop (destmem, NULL, destptr, NULL,
17108                                  gen_lowpart (QImode, value), count, QImode,
17109                                  1, max_size / 2);
17110 }
17111
17112 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
17113 static void
17114 expand_setmem_epilogue (rtx destmem, rtx destptr, rtx value, rtx count, int max_size)
17115 {
17116   rtx dest;
17117
17118   if (CONST_INT_P (count))
17119     {
17120       HOST_WIDE_INT countval = INTVAL (count);
17121       int offset = 0;
17122
17123       if ((countval & 0x10) && max_size > 16)
17124         {
17125           if (TARGET_64BIT)
17126             {
17127               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset);
17128               emit_insn (gen_strset (destptr, dest, value));
17129               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset + 8);
17130               emit_insn (gen_strset (destptr, dest, value));
17131             }
17132           else
17133             gcc_unreachable ();
17134           offset += 16;
17135         }
17136       if ((countval & 0x08) && max_size > 8)
17137         {
17138           if (TARGET_64BIT)
17139             {
17140               dest = adjust_automodify_address_nv (destmem, DImode, destptr, offset);
17141               emit_insn (gen_strset (destptr, dest, value));
17142             }
17143           else
17144             {
17145               dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset);
17146               emit_insn (gen_strset (destptr, dest, value));
17147               dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset + 4);
17148               emit_insn (gen_strset (destptr, dest, value));
17149             }
17150           offset += 8;
17151         }
17152       if ((countval & 0x04) && max_size > 4)
17153         {
17154           dest = adjust_automodify_address_nv (destmem, SImode, destptr, offset);
17155           emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
17156           offset += 4;
17157         }
17158       if ((countval & 0x02) && max_size > 2)
17159         {
17160           dest = adjust_automodify_address_nv (destmem, HImode, destptr, offset);
17161           emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
17162           offset += 2;
17163         }
17164       if ((countval & 0x01) && max_size > 1)
17165         {
17166           dest = adjust_automodify_address_nv (destmem, QImode, destptr, offset);
17167           emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
17168           offset += 1;
17169         }
17170       return;
17171     }
17172   if (max_size > 32)
17173     {
17174       expand_setmem_epilogue_via_loop (destmem, destptr, value, count, max_size);
17175       return;
17176     }
17177   if (max_size > 16)
17178     {
17179       rtx label = ix86_expand_aligntest (count, 16, true);
17180       if (TARGET_64BIT)
17181         {
17182           dest = change_address (destmem, DImode, destptr);
17183           emit_insn (gen_strset (destptr, dest, value));
17184           emit_insn (gen_strset (destptr, dest, value));
17185         }
17186       else
17187         {
17188           dest = change_address (destmem, SImode, destptr);
17189           emit_insn (gen_strset (destptr, dest, value));
17190           emit_insn (gen_strset (destptr, dest, value));
17191           emit_insn (gen_strset (destptr, dest, value));
17192           emit_insn (gen_strset (destptr, dest, value));
17193         }
17194       emit_label (label);
17195       LABEL_NUSES (label) = 1;
17196     }
17197   if (max_size > 8)
17198     {
17199       rtx label = ix86_expand_aligntest (count, 8, true);
17200       if (TARGET_64BIT)
17201         {
17202           dest = change_address (destmem, DImode, destptr);
17203           emit_insn (gen_strset (destptr, dest, value));
17204         }
17205       else
17206         {
17207           dest = change_address (destmem, SImode, destptr);
17208           emit_insn (gen_strset (destptr, dest, value));
17209           emit_insn (gen_strset (destptr, dest, value));
17210         }
17211       emit_label (label);
17212       LABEL_NUSES (label) = 1;
17213     }
17214   if (max_size > 4)
17215     {
17216       rtx label = ix86_expand_aligntest (count, 4, true);
17217       dest = change_address (destmem, SImode, destptr);
17218       emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
17219       emit_label (label);
17220       LABEL_NUSES (label) = 1;
17221     }
17222   if (max_size > 2)
17223     {
17224       rtx label = ix86_expand_aligntest (count, 2, true);
17225       dest = change_address (destmem, HImode, destptr);
17226       emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
17227       emit_label (label);
17228       LABEL_NUSES (label) = 1;
17229     }
17230   if (max_size > 1)
17231     {
17232       rtx label = ix86_expand_aligntest (count, 1, true);
17233       dest = change_address (destmem, QImode, destptr);
17234       emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
17235       emit_label (label);
17236       LABEL_NUSES (label) = 1;
17237     }
17238 }
17239
17240 /* Copy enough from DEST to SRC to align DEST known to by aligned by ALIGN to
17241    DESIRED_ALIGNMENT.  */
17242 static void
17243 expand_movmem_prologue (rtx destmem, rtx srcmem,
17244                         rtx destptr, rtx srcptr, rtx count,
17245                         int align, int desired_alignment)
17246 {
17247   if (align <= 1 && desired_alignment > 1)
17248     {
17249       rtx label = ix86_expand_aligntest (destptr, 1, false);
17250       srcmem = change_address (srcmem, QImode, srcptr);
17251       destmem = change_address (destmem, QImode, destptr);
17252       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
17253       ix86_adjust_counter (count, 1);
17254       emit_label (label);
17255       LABEL_NUSES (label) = 1;
17256     }
17257   if (align <= 2 && desired_alignment > 2)
17258     {
17259       rtx label = ix86_expand_aligntest (destptr, 2, false);
17260       srcmem = change_address (srcmem, HImode, srcptr);
17261       destmem = change_address (destmem, HImode, destptr);
17262       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
17263       ix86_adjust_counter (count, 2);
17264       emit_label (label);
17265       LABEL_NUSES (label) = 1;
17266     }
17267   if (align <= 4 && desired_alignment > 4)
17268     {
17269       rtx label = ix86_expand_aligntest (destptr, 4, false);
17270       srcmem = change_address (srcmem, SImode, srcptr);
17271       destmem = change_address (destmem, SImode, destptr);
17272       emit_insn (gen_strmov (destptr, destmem, srcptr, srcmem));
17273       ix86_adjust_counter (count, 4);
17274       emit_label (label);
17275       LABEL_NUSES (label) = 1;
17276     }
17277   gcc_assert (desired_alignment <= 8);
17278 }
17279
17280 /* Copy enough from DST to SRC to align DST known to DESIRED_ALIGN.
17281    ALIGN_BYTES is how many bytes need to be copied.  */
17282 static rtx
17283 expand_constant_movmem_prologue (rtx dst, rtx *srcp, rtx destreg, rtx srcreg,
17284                                  int desired_align, int align_bytes)
17285 {
17286   rtx src = *srcp;
17287   rtx src_size, dst_size;
17288   int off = 0;
17289   int src_align_bytes = get_mem_align_offset (src, desired_align * BITS_PER_UNIT);
17290   if (src_align_bytes >= 0)
17291     src_align_bytes = desired_align - src_align_bytes;
17292   src_size = MEM_SIZE (src);
17293   dst_size = MEM_SIZE (dst);
17294   if (align_bytes & 1)
17295     {
17296       dst = adjust_automodify_address_nv (dst, QImode, destreg, 0);
17297       src = adjust_automodify_address_nv (src, QImode, srcreg, 0);
17298       off = 1;
17299       emit_insn (gen_strmov (destreg, dst, srcreg, src));
17300     }
17301   if (align_bytes & 2)
17302     {
17303       dst = adjust_automodify_address_nv (dst, HImode, destreg, off);
17304       src = adjust_automodify_address_nv (src, HImode, srcreg, off);
17305       if (MEM_ALIGN (dst) < 2 * BITS_PER_UNIT)
17306         set_mem_align (dst, 2 * BITS_PER_UNIT);
17307       if (src_align_bytes >= 0
17308           && (src_align_bytes & 1) == (align_bytes & 1)
17309           && MEM_ALIGN (src) < 2 * BITS_PER_UNIT)
17310         set_mem_align (src, 2 * BITS_PER_UNIT);
17311       off = 2;
17312       emit_insn (gen_strmov (destreg, dst, srcreg, src));
17313     }
17314   if (align_bytes & 4)
17315     {
17316       dst = adjust_automodify_address_nv (dst, SImode, destreg, off);
17317       src = adjust_automodify_address_nv (src, SImode, srcreg, off);
17318       if (MEM_ALIGN (dst) < 4 * BITS_PER_UNIT)
17319         set_mem_align (dst, 4 * BITS_PER_UNIT);
17320       if (src_align_bytes >= 0)
17321         {
17322           unsigned int src_align = 0;
17323           if ((src_align_bytes & 3) == (align_bytes & 3))
17324             src_align = 4;
17325           else if ((src_align_bytes & 1) == (align_bytes & 1))
17326             src_align = 2;
17327           if (MEM_ALIGN (src) < src_align * BITS_PER_UNIT)
17328             set_mem_align (src, src_align * BITS_PER_UNIT);
17329         }
17330       off = 4;
17331       emit_insn (gen_strmov (destreg, dst, srcreg, src));
17332     }
17333   dst = adjust_automodify_address_nv (dst, BLKmode, destreg, off);
17334   src = adjust_automodify_address_nv (src, BLKmode, srcreg, off);
17335   if (MEM_ALIGN (dst) < (unsigned int) desired_align * BITS_PER_UNIT)
17336     set_mem_align (dst, desired_align * BITS_PER_UNIT);
17337   if (src_align_bytes >= 0)
17338     {
17339       unsigned int src_align = 0;
17340       if ((src_align_bytes & 7) == (align_bytes & 7))
17341         src_align = 8;
17342       else if ((src_align_bytes & 3) == (align_bytes & 3))
17343         src_align = 4;
17344       else if ((src_align_bytes & 1) == (align_bytes & 1))
17345         src_align = 2;
17346       if (src_align > (unsigned int) desired_align)
17347         src_align = desired_align;
17348       if (MEM_ALIGN (src) < src_align * BITS_PER_UNIT)
17349         set_mem_align (src, src_align * BITS_PER_UNIT);
17350     }
17351   if (dst_size)
17352     set_mem_size (dst, GEN_INT (INTVAL (dst_size) - align_bytes));
17353   if (src_size)
17354     set_mem_size (dst, GEN_INT (INTVAL (src_size) - align_bytes));
17355   *srcp = src;
17356   return dst;
17357 }
17358
17359 /* Set enough from DEST to align DEST known to by aligned by ALIGN to
17360    DESIRED_ALIGNMENT.  */
17361 static void
17362 expand_setmem_prologue (rtx destmem, rtx destptr, rtx value, rtx count,
17363                         int align, int desired_alignment)
17364 {
17365   if (align <= 1 && desired_alignment > 1)
17366     {
17367       rtx label = ix86_expand_aligntest (destptr, 1, false);
17368       destmem = change_address (destmem, QImode, destptr);
17369       emit_insn (gen_strset (destptr, destmem, gen_lowpart (QImode, value)));
17370       ix86_adjust_counter (count, 1);
17371       emit_label (label);
17372       LABEL_NUSES (label) = 1;
17373     }
17374   if (align <= 2 && desired_alignment > 2)
17375     {
17376       rtx label = ix86_expand_aligntest (destptr, 2, false);
17377       destmem = change_address (destmem, HImode, destptr);
17378       emit_insn (gen_strset (destptr, destmem, gen_lowpart (HImode, value)));
17379       ix86_adjust_counter (count, 2);
17380       emit_label (label);
17381       LABEL_NUSES (label) = 1;
17382     }
17383   if (align <= 4 && desired_alignment > 4)
17384     {
17385       rtx label = ix86_expand_aligntest (destptr, 4, false);
17386       destmem = change_address (destmem, SImode, destptr);
17387       emit_insn (gen_strset (destptr, destmem, gen_lowpart (SImode, value)));
17388       ix86_adjust_counter (count, 4);
17389       emit_label (label);
17390       LABEL_NUSES (label) = 1;
17391     }
17392   gcc_assert (desired_alignment <= 8);
17393 }
17394
17395 /* Set enough from DST to align DST known to by aligned by ALIGN to
17396    DESIRED_ALIGN.  ALIGN_BYTES is how many bytes need to be stored.  */
17397 static rtx
17398 expand_constant_setmem_prologue (rtx dst, rtx destreg, rtx value,
17399                                  int desired_align, int align_bytes)
17400 {
17401   int off = 0;
17402   rtx dst_size = MEM_SIZE (dst);
17403   if (align_bytes & 1)
17404     {
17405       dst = adjust_automodify_address_nv (dst, QImode, destreg, 0);
17406       off = 1;
17407       emit_insn (gen_strset (destreg, dst,
17408                              gen_lowpart (QImode, value)));
17409     }
17410   if (align_bytes & 2)
17411     {
17412       dst = adjust_automodify_address_nv (dst, HImode, destreg, off);
17413       if (MEM_ALIGN (dst) < 2 * BITS_PER_UNIT)
17414         set_mem_align (dst, 2 * BITS_PER_UNIT);
17415       off = 2;
17416       emit_insn (gen_strset (destreg, dst,
17417                              gen_lowpart (HImode, value)));
17418     }
17419   if (align_bytes & 4)
17420     {
17421       dst = adjust_automodify_address_nv (dst, SImode, destreg, off);
17422       if (MEM_ALIGN (dst) < 4 * BITS_PER_UNIT)
17423         set_mem_align (dst, 4 * BITS_PER_UNIT);
17424       off = 4;
17425       emit_insn (gen_strset (destreg, dst,
17426                              gen_lowpart (SImode, value)));
17427     }
17428   dst = adjust_automodify_address_nv (dst, BLKmode, destreg, off);
17429   if (MEM_ALIGN (dst) < (unsigned int) desired_align * BITS_PER_UNIT)
17430     set_mem_align (dst, desired_align * BITS_PER_UNIT);
17431   if (dst_size)
17432     set_mem_size (dst, GEN_INT (INTVAL (dst_size) - align_bytes));
17433   return dst;
17434 }
17435
17436 /* Given COUNT and EXPECTED_SIZE, decide on codegen of string operation.  */
17437 static enum stringop_alg
17438 decide_alg (HOST_WIDE_INT count, HOST_WIDE_INT expected_size, bool memset,
17439             int *dynamic_check)
17440 {
17441   const struct stringop_algs * algs;
17442   bool optimize_for_speed;
17443   /* Algorithms using the rep prefix want at least edi and ecx;
17444      additionally, memset wants eax and memcpy wants esi.  Don't
17445      consider such algorithms if the user has appropriated those
17446      registers for their own purposes.  */
17447   bool rep_prefix_usable = !(fixed_regs[CX_REG] || fixed_regs[DI_REG]
17448                              || (memset
17449                                  ? fixed_regs[AX_REG] : fixed_regs[SI_REG]));
17450
17451 #define ALG_USABLE_P(alg) (rep_prefix_usable                    \
17452                            || (alg != rep_prefix_1_byte         \
17453                                && alg != rep_prefix_4_byte      \
17454                                && alg != rep_prefix_8_byte))
17455   const struct processor_costs *cost;
17456   
17457   /* Even if the string operation call is cold, we still might spend a lot
17458      of time processing large blocks.  */
17459   if (optimize_function_for_size_p (cfun)
17460       || (optimize_insn_for_size_p ()
17461           && expected_size != -1 && expected_size < 256))
17462     optimize_for_speed = false;
17463   else
17464     optimize_for_speed = true;
17465
17466   cost = optimize_for_speed ? ix86_cost : &ix86_size_cost;
17467
17468   *dynamic_check = -1;
17469   if (memset)
17470     algs = &cost->memset[TARGET_64BIT != 0];
17471   else
17472     algs = &cost->memcpy[TARGET_64BIT != 0];
17473   if (stringop_alg != no_stringop && ALG_USABLE_P (stringop_alg))
17474     return stringop_alg;
17475   /* rep; movq or rep; movl is the smallest variant.  */
17476   else if (!optimize_for_speed)
17477     {
17478       if (!count || (count & 3))
17479         return rep_prefix_usable ? rep_prefix_1_byte : loop_1_byte;
17480       else
17481         return rep_prefix_usable ? rep_prefix_4_byte : loop;
17482     }
17483   /* Very tiny blocks are best handled via the loop, REP is expensive to setup.
17484    */
17485   else if (expected_size != -1 && expected_size < 4)
17486     return loop_1_byte;
17487   else if (expected_size != -1)
17488     {
17489       unsigned int i;
17490       enum stringop_alg alg = libcall;
17491       for (i = 0; i < NAX_STRINGOP_ALGS; i++)
17492         {
17493           /* We get here if the algorithms that were not libcall-based
17494              were rep-prefix based and we are unable to use rep prefixes
17495              based on global register usage.  Break out of the loop and
17496              use the heuristic below.  */
17497           if (algs->size[i].max == 0)
17498             break;
17499           if (algs->size[i].max >= expected_size || algs->size[i].max == -1)
17500             {
17501               enum stringop_alg candidate = algs->size[i].alg;
17502
17503               if (candidate != libcall && ALG_USABLE_P (candidate))
17504                 alg = candidate;
17505               /* Honor TARGET_INLINE_ALL_STRINGOPS by picking
17506                  last non-libcall inline algorithm.  */
17507               if (TARGET_INLINE_ALL_STRINGOPS)
17508                 {
17509                   /* When the current size is best to be copied by a libcall,
17510                      but we are still forced to inline, run the heuristic below
17511                      that will pick code for medium sized blocks.  */
17512                   if (alg != libcall)
17513                     return alg;
17514                   break;
17515                 }
17516               else if (ALG_USABLE_P (candidate))
17517                 return candidate;
17518             }
17519         }
17520       gcc_assert (TARGET_INLINE_ALL_STRINGOPS || !rep_prefix_usable);
17521     }
17522   /* When asked to inline the call anyway, try to pick meaningful choice.
17523      We look for maximal size of block that is faster to copy by hand and
17524      take blocks of at most of that size guessing that average size will
17525      be roughly half of the block.
17526
17527      If this turns out to be bad, we might simply specify the preferred
17528      choice in ix86_costs.  */
17529   if ((TARGET_INLINE_ALL_STRINGOPS || TARGET_INLINE_STRINGOPS_DYNAMICALLY)
17530       && (algs->unknown_size == libcall || !ALG_USABLE_P (algs->unknown_size)))
17531     {
17532       int max = -1;
17533       enum stringop_alg alg;
17534       int i;
17535       bool any_alg_usable_p = true;
17536
17537       for (i = 0; i < NAX_STRINGOP_ALGS; i++)
17538         {
17539           enum stringop_alg candidate = algs->size[i].alg;
17540           any_alg_usable_p = any_alg_usable_p && ALG_USABLE_P (candidate);
17541
17542           if (candidate != libcall && candidate
17543               && ALG_USABLE_P (candidate))
17544               max = algs->size[i].max;
17545         }
17546       /* If there aren't any usable algorithms, then recursing on
17547          smaller sizes isn't going to find anything.  Just return the
17548          simple byte-at-a-time copy loop.  */
17549       if (!any_alg_usable_p)
17550         {
17551           /* Pick something reasonable.  */
17552           if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
17553             *dynamic_check = 128;
17554           return loop_1_byte;
17555         }
17556       if (max == -1)
17557         max = 4096;
17558       alg = decide_alg (count, max / 2, memset, dynamic_check);
17559       gcc_assert (*dynamic_check == -1);
17560       gcc_assert (alg != libcall);
17561       if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
17562         *dynamic_check = max;
17563       return alg;
17564     }
17565   return ALG_USABLE_P (algs->unknown_size) ? algs->unknown_size : libcall;
17566 #undef ALG_USABLE_P
17567 }
17568
17569 /* Decide on alignment.  We know that the operand is already aligned to ALIGN
17570    (ALIGN can be based on profile feedback and thus it is not 100% guaranteed).  */
17571 static int
17572 decide_alignment (int align,
17573                   enum stringop_alg alg,
17574                   int expected_size)
17575 {
17576   int desired_align = 0;
17577   switch (alg)
17578     {
17579       case no_stringop:
17580         gcc_unreachable ();
17581       case loop:
17582       case unrolled_loop:
17583         desired_align = GET_MODE_SIZE (Pmode);
17584         break;
17585       case rep_prefix_8_byte:
17586         desired_align = 8;
17587         break;
17588       case rep_prefix_4_byte:
17589         /* PentiumPro has special logic triggering for 8 byte aligned blocks.
17590            copying whole cacheline at once.  */
17591         if (TARGET_PENTIUMPRO)
17592           desired_align = 8;
17593         else
17594           desired_align = 4;
17595         break;
17596       case rep_prefix_1_byte:
17597         /* PentiumPro has special logic triggering for 8 byte aligned blocks.
17598            copying whole cacheline at once.  */
17599         if (TARGET_PENTIUMPRO)
17600           desired_align = 8;
17601         else
17602           desired_align = 1;
17603         break;
17604       case loop_1_byte:
17605         desired_align = 1;
17606         break;
17607       case libcall:
17608         return 0;
17609     }
17610
17611   if (optimize_size)
17612     desired_align = 1;
17613   if (desired_align < align)
17614     desired_align = align;
17615   if (expected_size != -1 && expected_size < 4)
17616     desired_align = align;
17617   return desired_align;
17618 }
17619
17620 /* Return the smallest power of 2 greater than VAL.  */
17621 static int
17622 smallest_pow2_greater_than (int val)
17623 {
17624   int ret = 1;
17625   while (ret <= val)
17626     ret <<= 1;
17627   return ret;
17628 }
17629
17630 /* Expand string move (memcpy) operation.  Use i386 string operations when
17631    profitable.  expand_setmem contains similar code.  The code depends upon
17632    architecture, block size and alignment, but always has the same
17633    overall structure:
17634
17635    1) Prologue guard: Conditional that jumps up to epilogues for small
17636       blocks that can be handled by epilogue alone.  This is faster but
17637       also needed for correctness, since prologue assume the block is larger
17638       than the desired alignment.
17639
17640       Optional dynamic check for size and libcall for large
17641       blocks is emitted here too, with -minline-stringops-dynamically.
17642
17643    2) Prologue: copy first few bytes in order to get destination aligned
17644       to DESIRED_ALIGN.  It is emitted only when ALIGN is less than
17645       DESIRED_ALIGN and and up to DESIRED_ALIGN - ALIGN bytes can be copied.
17646       We emit either a jump tree on power of two sized blocks, or a byte loop.
17647
17648    3) Main body: the copying loop itself, copying in SIZE_NEEDED chunks
17649       with specified algorithm.
17650
17651    4) Epilogue: code copying tail of the block that is too small to be
17652       handled by main body (or up to size guarded by prologue guard).  */
17653
17654 int
17655 ix86_expand_movmem (rtx dst, rtx src, rtx count_exp, rtx align_exp,
17656                     rtx expected_align_exp, rtx expected_size_exp)
17657 {
17658   rtx destreg;
17659   rtx srcreg;
17660   rtx label = NULL;
17661   rtx tmp;
17662   rtx jump_around_label = NULL;
17663   HOST_WIDE_INT align = 1;
17664   unsigned HOST_WIDE_INT count = 0;
17665   HOST_WIDE_INT expected_size = -1;
17666   int size_needed = 0, epilogue_size_needed;
17667   int desired_align = 0, align_bytes = 0;
17668   enum stringop_alg alg;
17669   int dynamic_check;
17670   bool need_zero_guard = false;
17671
17672   if (CONST_INT_P (align_exp))
17673     align = INTVAL (align_exp);
17674   /* i386 can do misaligned access on reasonably increased cost.  */
17675   if (CONST_INT_P (expected_align_exp)
17676       && INTVAL (expected_align_exp) > align)
17677     align = INTVAL (expected_align_exp);
17678   /* ALIGN is the minimum of destination and source alignment, but we care here
17679      just about destination alignment.  */
17680   else if (MEM_ALIGN (dst) > (unsigned HOST_WIDE_INT) align * BITS_PER_UNIT)
17681     align = MEM_ALIGN (dst) / BITS_PER_UNIT;
17682
17683   if (CONST_INT_P (count_exp))
17684     count = expected_size = INTVAL (count_exp);
17685   if (CONST_INT_P (expected_size_exp) && count == 0)
17686     expected_size = INTVAL (expected_size_exp);
17687
17688   /* Make sure we don't need to care about overflow later on.  */
17689   if (count > ((unsigned HOST_WIDE_INT) 1 << 30))
17690     return 0;
17691
17692   /* Step 0: Decide on preferred algorithm, desired alignment and
17693      size of chunks to be copied by main loop.  */
17694
17695   alg = decide_alg (count, expected_size, false, &dynamic_check);
17696   desired_align = decide_alignment (align, alg, expected_size);
17697
17698   if (!TARGET_ALIGN_STRINGOPS)
17699     align = desired_align;
17700
17701   if (alg == libcall)
17702     return 0;
17703   gcc_assert (alg != no_stringop);
17704   if (!count)
17705     count_exp = copy_to_mode_reg (GET_MODE (count_exp), count_exp);
17706   destreg = copy_to_mode_reg (Pmode, XEXP (dst, 0));
17707   srcreg = copy_to_mode_reg (Pmode, XEXP (src, 0));
17708   switch (alg)
17709     {
17710     case libcall:
17711     case no_stringop:
17712       gcc_unreachable ();
17713     case loop:
17714       need_zero_guard = true;
17715       size_needed = GET_MODE_SIZE (Pmode);
17716       break;
17717     case unrolled_loop:
17718       need_zero_guard = true;
17719       size_needed = GET_MODE_SIZE (Pmode) * (TARGET_64BIT ? 4 : 2);
17720       break;
17721     case rep_prefix_8_byte:
17722       size_needed = 8;
17723       break;
17724     case rep_prefix_4_byte:
17725       size_needed = 4;
17726       break;
17727     case rep_prefix_1_byte:
17728       size_needed = 1;
17729       break;
17730     case loop_1_byte:
17731       need_zero_guard = true;
17732       size_needed = 1;
17733       break;
17734     }
17735
17736   epilogue_size_needed = size_needed;
17737
17738   /* Step 1: Prologue guard.  */
17739
17740   /* Alignment code needs count to be in register.  */
17741   if (CONST_INT_P (count_exp) && desired_align > align)
17742     {
17743       if (INTVAL (count_exp) > desired_align
17744           && INTVAL (count_exp) > size_needed)
17745         {
17746           align_bytes
17747             = get_mem_align_offset (dst, desired_align * BITS_PER_UNIT);
17748           if (align_bytes <= 0)
17749             align_bytes = 0;
17750           else
17751             align_bytes = desired_align - align_bytes;
17752         }
17753       if (align_bytes == 0)
17754         count_exp = force_reg (counter_mode (count_exp), count_exp);
17755     }
17756   gcc_assert (desired_align >= 1 && align >= 1);
17757
17758   /* Ensure that alignment prologue won't copy past end of block.  */
17759   if (size_needed > 1 || (desired_align > 1 && desired_align > align))
17760     {
17761       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
17762       /* Epilogue always copies COUNT_EXP & EPILOGUE_SIZE_NEEDED bytes.
17763          Make sure it is power of 2.  */
17764       epilogue_size_needed = smallest_pow2_greater_than (epilogue_size_needed);
17765
17766       if (count)
17767         {
17768           if (count < (unsigned HOST_WIDE_INT)epilogue_size_needed)
17769             {
17770               /* If main algorithm works on QImode, no epilogue is needed.
17771                  For small sizes just don't align anything.  */
17772               if (size_needed == 1)
17773                 desired_align = align;
17774               else
17775                 goto epilogue;
17776             }
17777         }
17778       else
17779         {
17780           label = gen_label_rtx ();
17781           emit_cmp_and_jump_insns (count_exp,
17782                                    GEN_INT (epilogue_size_needed),
17783                                    LTU, 0, counter_mode (count_exp), 1, label);
17784           if (expected_size == -1 || expected_size < epilogue_size_needed)
17785             predict_jump (REG_BR_PROB_BASE * 60 / 100);
17786           else
17787             predict_jump (REG_BR_PROB_BASE * 20 / 100);
17788         }
17789     }
17790
17791   /* Emit code to decide on runtime whether library call or inline should be
17792      used.  */
17793   if (dynamic_check != -1)
17794     {
17795       if (CONST_INT_P (count_exp))
17796         {
17797           if (UINTVAL (count_exp) >= (unsigned HOST_WIDE_INT)dynamic_check)
17798             {
17799               emit_block_move_via_libcall (dst, src, count_exp, false);
17800               count_exp = const0_rtx;
17801               goto epilogue;
17802             }
17803         }
17804       else
17805         {
17806           rtx hot_label = gen_label_rtx ();
17807           jump_around_label = gen_label_rtx ();
17808           emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
17809                                    LEU, 0, GET_MODE (count_exp), 1, hot_label);
17810           predict_jump (REG_BR_PROB_BASE * 90 / 100);
17811           emit_block_move_via_libcall (dst, src, count_exp, false);
17812           emit_jump (jump_around_label);
17813           emit_label (hot_label);
17814         }
17815     }
17816
17817   /* Step 2: Alignment prologue.  */
17818
17819   if (desired_align > align)
17820     {
17821       if (align_bytes == 0)
17822         {
17823           /* Except for the first move in epilogue, we no longer know
17824              constant offset in aliasing info.  It don't seems to worth
17825              the pain to maintain it for the first move, so throw away
17826              the info early.  */
17827           src = change_address (src, BLKmode, srcreg);
17828           dst = change_address (dst, BLKmode, destreg);
17829           expand_movmem_prologue (dst, src, destreg, srcreg, count_exp, align,
17830                                   desired_align);
17831         }
17832       else
17833         {
17834           /* If we know how many bytes need to be stored before dst is
17835              sufficiently aligned, maintain aliasing info accurately.  */
17836           dst = expand_constant_movmem_prologue (dst, &src, destreg, srcreg,
17837                                                  desired_align, align_bytes);
17838           count_exp = plus_constant (count_exp, -align_bytes);
17839           count -= align_bytes;
17840         }
17841       if (need_zero_guard
17842           && (count < (unsigned HOST_WIDE_INT) size_needed
17843               || (align_bytes == 0
17844                   && count < ((unsigned HOST_WIDE_INT) size_needed
17845                               + desired_align - align))))
17846         {
17847           /* It is possible that we copied enough so the main loop will not
17848              execute.  */
17849           gcc_assert (size_needed > 1);
17850           if (label == NULL_RTX)
17851             label = gen_label_rtx ();
17852           emit_cmp_and_jump_insns (count_exp,
17853                                    GEN_INT (size_needed),
17854                                    LTU, 0, counter_mode (count_exp), 1, label);
17855           if (expected_size == -1
17856               || expected_size < (desired_align - align) / 2 + size_needed)
17857             predict_jump (REG_BR_PROB_BASE * 20 / 100);
17858           else
17859             predict_jump (REG_BR_PROB_BASE * 60 / 100);
17860         }
17861     }
17862   if (label && size_needed == 1)
17863     {
17864       emit_label (label);
17865       LABEL_NUSES (label) = 1;
17866       label = NULL;
17867       epilogue_size_needed = 1;
17868     }
17869   else if (label == NULL_RTX)
17870     epilogue_size_needed = size_needed;
17871
17872   /* Step 3: Main loop.  */
17873
17874   switch (alg)
17875     {
17876     case libcall:
17877     case no_stringop:
17878       gcc_unreachable ();
17879     case loop_1_byte:
17880       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
17881                                      count_exp, QImode, 1, expected_size);
17882       break;
17883     case loop:
17884       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
17885                                      count_exp, Pmode, 1, expected_size);
17886       break;
17887     case unrolled_loop:
17888       /* Unroll only by factor of 2 in 32bit mode, since we don't have enough
17889          registers for 4 temporaries anyway.  */
17890       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, NULL,
17891                                      count_exp, Pmode, TARGET_64BIT ? 4 : 2,
17892                                      expected_size);
17893       break;
17894     case rep_prefix_8_byte:
17895       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
17896                                  DImode);
17897       break;
17898     case rep_prefix_4_byte:
17899       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
17900                                  SImode);
17901       break;
17902     case rep_prefix_1_byte:
17903       expand_movmem_via_rep_mov (dst, src, destreg, srcreg, count_exp,
17904                                  QImode);
17905       break;
17906     }
17907   /* Adjust properly the offset of src and dest memory for aliasing.  */
17908   if (CONST_INT_P (count_exp))
17909     {
17910       src = adjust_automodify_address_nv (src, BLKmode, srcreg,
17911                                           (count / size_needed) * size_needed);
17912       dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
17913                                           (count / size_needed) * size_needed);
17914     }
17915   else
17916     {
17917       src = change_address (src, BLKmode, srcreg);
17918       dst = change_address (dst, BLKmode, destreg);
17919     }
17920
17921   /* Step 4: Epilogue to copy the remaining bytes.  */
17922  epilogue:
17923   if (label)
17924     {
17925       /* When the main loop is done, COUNT_EXP might hold original count,
17926          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
17927          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
17928          bytes. Compensate if needed.  */
17929
17930       if (size_needed < epilogue_size_needed)
17931         {
17932           tmp =
17933             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
17934                                  GEN_INT (size_needed - 1), count_exp, 1,
17935                                  OPTAB_DIRECT);
17936           if (tmp != count_exp)
17937             emit_move_insn (count_exp, tmp);
17938         }
17939       emit_label (label);
17940       LABEL_NUSES (label) = 1;
17941     }
17942
17943   if (count_exp != const0_rtx && epilogue_size_needed > 1)
17944     expand_movmem_epilogue (dst, src, destreg, srcreg, count_exp,
17945                             epilogue_size_needed);
17946   if (jump_around_label)
17947     emit_label (jump_around_label);
17948   return 1;
17949 }
17950
17951 /* Helper function for memcpy.  For QImode value 0xXY produce
17952    0xXYXYXYXY of wide specified by MODE.  This is essentially
17953    a * 0x10101010, but we can do slightly better than
17954    synth_mult by unwinding the sequence by hand on CPUs with
17955    slow multiply.  */
17956 static rtx
17957 promote_duplicated_reg (enum machine_mode mode, rtx val)
17958 {
17959   enum machine_mode valmode = GET_MODE (val);
17960   rtx tmp;
17961   int nops = mode == DImode ? 3 : 2;
17962
17963   gcc_assert (mode == SImode || mode == DImode);
17964   if (val == const0_rtx)
17965     return copy_to_mode_reg (mode, const0_rtx);
17966   if (CONST_INT_P (val))
17967     {
17968       HOST_WIDE_INT v = INTVAL (val) & 255;
17969
17970       v |= v << 8;
17971       v |= v << 16;
17972       if (mode == DImode)
17973         v |= (v << 16) << 16;
17974       return copy_to_mode_reg (mode, gen_int_mode (v, mode));
17975     }
17976
17977   if (valmode == VOIDmode)
17978     valmode = QImode;
17979   if (valmode != QImode)
17980     val = gen_lowpart (QImode, val);
17981   if (mode == QImode)
17982     return val;
17983   if (!TARGET_PARTIAL_REG_STALL)
17984     nops--;
17985   if (ix86_cost->mult_init[mode == DImode ? 3 : 2]
17986       + ix86_cost->mult_bit * (mode == DImode ? 8 : 4)
17987       <= (ix86_cost->shift_const + ix86_cost->add) * nops
17988           + (COSTS_N_INSNS (TARGET_PARTIAL_REG_STALL == 0)))
17989     {
17990       rtx reg = convert_modes (mode, QImode, val, true);
17991       tmp = promote_duplicated_reg (mode, const1_rtx);
17992       return expand_simple_binop (mode, MULT, reg, tmp, NULL, 1,
17993                                   OPTAB_DIRECT);
17994     }
17995   else
17996     {
17997       rtx reg = convert_modes (mode, QImode, val, true);
17998
17999       if (!TARGET_PARTIAL_REG_STALL)
18000         if (mode == SImode)
18001           emit_insn (gen_movsi_insv_1 (reg, reg));
18002         else
18003           emit_insn (gen_movdi_insv_1_rex64 (reg, reg));
18004       else
18005         {
18006           tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (8),
18007                                      NULL, 1, OPTAB_DIRECT);
18008           reg =
18009             expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
18010         }
18011       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (16),
18012                                  NULL, 1, OPTAB_DIRECT);
18013       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
18014       if (mode == SImode)
18015         return reg;
18016       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (32),
18017                                  NULL, 1, OPTAB_DIRECT);
18018       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
18019       return reg;
18020     }
18021 }
18022
18023 /* Duplicate value VAL using promote_duplicated_reg into maximal size that will
18024    be needed by main loop copying SIZE_NEEDED chunks and prologue getting
18025    alignment from ALIGN to DESIRED_ALIGN.  */
18026 static rtx
18027 promote_duplicated_reg_to_size (rtx val, int size_needed, int desired_align, int align)
18028 {
18029   rtx promoted_val;
18030
18031   if (TARGET_64BIT
18032       && (size_needed > 4 || (desired_align > align && desired_align > 4)))
18033     promoted_val = promote_duplicated_reg (DImode, val);
18034   else if (size_needed > 2 || (desired_align > align && desired_align > 2))
18035     promoted_val = promote_duplicated_reg (SImode, val);
18036   else if (size_needed > 1 || (desired_align > align && desired_align > 1))
18037     promoted_val = promote_duplicated_reg (HImode, val);
18038   else
18039     promoted_val = val;
18040
18041   return promoted_val;
18042 }
18043
18044 /* Expand string clear operation (bzero).  Use i386 string operations when
18045    profitable.  See expand_movmem comment for explanation of individual
18046    steps performed.  */
18047 int
18048 ix86_expand_setmem (rtx dst, rtx count_exp, rtx val_exp, rtx align_exp,
18049                     rtx expected_align_exp, rtx expected_size_exp)
18050 {
18051   rtx destreg;
18052   rtx label = NULL;
18053   rtx tmp;
18054   rtx jump_around_label = NULL;
18055   HOST_WIDE_INT align = 1;
18056   unsigned HOST_WIDE_INT count = 0;
18057   HOST_WIDE_INT expected_size = -1;
18058   int size_needed = 0, epilogue_size_needed;
18059   int desired_align = 0, align_bytes = 0;
18060   enum stringop_alg alg;
18061   rtx promoted_val = NULL;
18062   bool force_loopy_epilogue = false;
18063   int dynamic_check;
18064   bool need_zero_guard = false;
18065
18066   if (CONST_INT_P (align_exp))
18067     align = INTVAL (align_exp);
18068   /* i386 can do misaligned access on reasonably increased cost.  */
18069   if (CONST_INT_P (expected_align_exp)
18070       && INTVAL (expected_align_exp) > align)
18071     align = INTVAL (expected_align_exp);
18072   if (CONST_INT_P (count_exp))
18073     count = expected_size = INTVAL (count_exp);
18074   if (CONST_INT_P (expected_size_exp) && count == 0)
18075     expected_size = INTVAL (expected_size_exp);
18076
18077   /* Make sure we don't need to care about overflow later on.  */
18078   if (count > ((unsigned HOST_WIDE_INT) 1 << 30))
18079     return 0;
18080
18081   /* Step 0: Decide on preferred algorithm, desired alignment and
18082      size of chunks to be copied by main loop.  */
18083
18084   alg = decide_alg (count, expected_size, true, &dynamic_check);
18085   desired_align = decide_alignment (align, alg, expected_size);
18086
18087   if (!TARGET_ALIGN_STRINGOPS)
18088     align = desired_align;
18089
18090   if (alg == libcall)
18091     return 0;
18092   gcc_assert (alg != no_stringop);
18093   if (!count)
18094     count_exp = copy_to_mode_reg (counter_mode (count_exp), count_exp);
18095   destreg = copy_to_mode_reg (Pmode, XEXP (dst, 0));
18096   switch (alg)
18097     {
18098     case libcall:
18099     case no_stringop:
18100       gcc_unreachable ();
18101     case loop:
18102       need_zero_guard = true;
18103       size_needed = GET_MODE_SIZE (Pmode);
18104       break;
18105     case unrolled_loop:
18106       need_zero_guard = true;
18107       size_needed = GET_MODE_SIZE (Pmode) * 4;
18108       break;
18109     case rep_prefix_8_byte:
18110       size_needed = 8;
18111       break;
18112     case rep_prefix_4_byte:
18113       size_needed = 4;
18114       break;
18115     case rep_prefix_1_byte:
18116       size_needed = 1;
18117       break;
18118     case loop_1_byte:
18119       need_zero_guard = true;
18120       size_needed = 1;
18121       break;
18122     }
18123   epilogue_size_needed = size_needed;
18124
18125   /* Step 1: Prologue guard.  */
18126
18127   /* Alignment code needs count to be in register.  */
18128   if (CONST_INT_P (count_exp) && desired_align > align)
18129     {
18130       if (INTVAL (count_exp) > desired_align
18131           && INTVAL (count_exp) > size_needed)
18132         {
18133           align_bytes
18134             = get_mem_align_offset (dst, desired_align * BITS_PER_UNIT);
18135           if (align_bytes <= 0)
18136             align_bytes = 0;
18137           else
18138             align_bytes = desired_align - align_bytes;
18139         }
18140       if (align_bytes == 0)
18141         {
18142           enum machine_mode mode = SImode;
18143           if (TARGET_64BIT && (count & ~0xffffffff))
18144             mode = DImode;
18145           count_exp = force_reg (mode, count_exp);
18146         }
18147     }
18148   /* Do the cheap promotion to allow better CSE across the
18149      main loop and epilogue (ie one load of the big constant in the
18150      front of all code.  */
18151   if (CONST_INT_P (val_exp))
18152     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
18153                                                    desired_align, align);
18154   /* Ensure that alignment prologue won't copy past end of block.  */
18155   if (size_needed > 1 || (desired_align > 1 && desired_align > align))
18156     {
18157       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
18158       /* Epilogue always copies COUNT_EXP & (EPILOGUE_SIZE_NEEDED - 1) bytes.
18159          Make sure it is power of 2.  */
18160       epilogue_size_needed = smallest_pow2_greater_than (epilogue_size_needed);
18161
18162       /* To improve performance of small blocks, we jump around the VAL
18163          promoting mode.  This mean that if the promoted VAL is not constant,
18164          we might not use it in the epilogue and have to use byte
18165          loop variant.  */
18166       if (epilogue_size_needed > 2 && !promoted_val)
18167         force_loopy_epilogue = true;
18168       if (count)
18169         {
18170           if (count < (unsigned HOST_WIDE_INT)epilogue_size_needed)
18171             {
18172               /* If main algorithm works on QImode, no epilogue is needed.
18173                  For small sizes just don't align anything.  */
18174               if (size_needed == 1)
18175                 desired_align = align;
18176               else
18177                 goto epilogue;
18178             }
18179         }
18180       else
18181         {
18182           label = gen_label_rtx ();
18183           emit_cmp_and_jump_insns (count_exp,
18184                                    GEN_INT (epilogue_size_needed),
18185                                    LTU, 0, counter_mode (count_exp), 1, label);
18186           if (expected_size == -1 || expected_size <= epilogue_size_needed)
18187             predict_jump (REG_BR_PROB_BASE * 60 / 100);
18188           else
18189             predict_jump (REG_BR_PROB_BASE * 20 / 100);
18190         }
18191     }
18192   if (dynamic_check != -1)
18193     {
18194       rtx hot_label = gen_label_rtx ();
18195       jump_around_label = gen_label_rtx ();
18196       emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
18197                                LEU, 0, counter_mode (count_exp), 1, hot_label);
18198       predict_jump (REG_BR_PROB_BASE * 90 / 100);
18199       set_storage_via_libcall (dst, count_exp, val_exp, false);
18200       emit_jump (jump_around_label);
18201       emit_label (hot_label);
18202     }
18203
18204   /* Step 2: Alignment prologue.  */
18205
18206   /* Do the expensive promotion once we branched off the small blocks.  */
18207   if (!promoted_val)
18208     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
18209                                                    desired_align, align);
18210   gcc_assert (desired_align >= 1 && align >= 1);
18211
18212   if (desired_align > align)
18213     {
18214       if (align_bytes == 0)
18215         {
18216           /* Except for the first move in epilogue, we no longer know
18217              constant offset in aliasing info.  It don't seems to worth
18218              the pain to maintain it for the first move, so throw away
18219              the info early.  */
18220           dst = change_address (dst, BLKmode, destreg);
18221           expand_setmem_prologue (dst, destreg, promoted_val, count_exp, align,
18222                                   desired_align);
18223         }
18224       else
18225         {
18226           /* If we know how many bytes need to be stored before dst is
18227              sufficiently aligned, maintain aliasing info accurately.  */
18228           dst = expand_constant_setmem_prologue (dst, destreg, promoted_val,
18229                                                  desired_align, align_bytes);
18230           count_exp = plus_constant (count_exp, -align_bytes);
18231           count -= align_bytes;
18232         }
18233       if (need_zero_guard
18234           && (count < (unsigned HOST_WIDE_INT) size_needed
18235               || (align_bytes == 0
18236                   && count < ((unsigned HOST_WIDE_INT) size_needed
18237                               + desired_align - align))))
18238         {
18239           /* It is possible that we copied enough so the main loop will not
18240              execute.  */
18241           gcc_assert (size_needed > 1);
18242           if (label == NULL_RTX)
18243             label = gen_label_rtx ();
18244           emit_cmp_and_jump_insns (count_exp,
18245                                    GEN_INT (size_needed),
18246                                    LTU, 0, counter_mode (count_exp), 1, label);
18247           if (expected_size == -1
18248               || expected_size < (desired_align - align) / 2 + size_needed)
18249             predict_jump (REG_BR_PROB_BASE * 20 / 100);
18250           else
18251             predict_jump (REG_BR_PROB_BASE * 60 / 100);
18252         }
18253     }
18254   if (label && size_needed == 1)
18255     {
18256       emit_label (label);
18257       LABEL_NUSES (label) = 1;
18258       label = NULL;
18259       promoted_val = val_exp;
18260       epilogue_size_needed = 1;
18261     }
18262   else if (label == NULL_RTX)
18263     epilogue_size_needed = size_needed;
18264
18265   /* Step 3: Main loop.  */
18266
18267   switch (alg)
18268     {
18269     case libcall:
18270     case no_stringop:
18271       gcc_unreachable ();
18272     case loop_1_byte:
18273       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
18274                                      count_exp, QImode, 1, expected_size);
18275       break;
18276     case loop:
18277       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
18278                                      count_exp, Pmode, 1, expected_size);
18279       break;
18280     case unrolled_loop:
18281       expand_set_or_movmem_via_loop (dst, NULL, destreg, NULL, promoted_val,
18282                                      count_exp, Pmode, 4, expected_size);
18283       break;
18284     case rep_prefix_8_byte:
18285       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
18286                                   DImode, val_exp);
18287       break;
18288     case rep_prefix_4_byte:
18289       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
18290                                   SImode, val_exp);
18291       break;
18292     case rep_prefix_1_byte:
18293       expand_setmem_via_rep_stos (dst, destreg, promoted_val, count_exp,
18294                                   QImode, val_exp);
18295       break;
18296     }
18297   /* Adjust properly the offset of src and dest memory for aliasing.  */
18298   if (CONST_INT_P (count_exp))
18299     dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
18300                                         (count / size_needed) * size_needed);
18301   else
18302     dst = change_address (dst, BLKmode, destreg);
18303
18304   /* Step 4: Epilogue to copy the remaining bytes.  */
18305
18306   if (label)
18307     {
18308       /* When the main loop is done, COUNT_EXP might hold original count,
18309          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
18310          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
18311          bytes. Compensate if needed.  */
18312
18313       if (size_needed < epilogue_size_needed)
18314         {
18315           tmp =
18316             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
18317                                  GEN_INT (size_needed - 1), count_exp, 1,
18318                                  OPTAB_DIRECT);
18319           if (tmp != count_exp)
18320             emit_move_insn (count_exp, tmp);
18321         }
18322       emit_label (label);
18323       LABEL_NUSES (label) = 1;
18324     }
18325  epilogue:
18326   if (count_exp != const0_rtx && epilogue_size_needed > 1)
18327     {
18328       if (force_loopy_epilogue)
18329         expand_setmem_epilogue_via_loop (dst, destreg, val_exp, count_exp,
18330                                          epilogue_size_needed);
18331       else
18332         expand_setmem_epilogue (dst, destreg, promoted_val, count_exp,
18333                                 epilogue_size_needed);
18334     }
18335   if (jump_around_label)
18336     emit_label (jump_around_label);
18337   return 1;
18338 }
18339
18340 /* Expand the appropriate insns for doing strlen if not just doing
18341    repnz; scasb
18342
18343    out = result, initialized with the start address
18344    align_rtx = alignment of the address.
18345    scratch = scratch register, initialized with the startaddress when
18346         not aligned, otherwise undefined
18347
18348    This is just the body. It needs the initializations mentioned above and
18349    some address computing at the end.  These things are done in i386.md.  */
18350
18351 static void
18352 ix86_expand_strlensi_unroll_1 (rtx out, rtx src, rtx align_rtx)
18353 {
18354   int align;
18355   rtx tmp;
18356   rtx align_2_label = NULL_RTX;
18357   rtx align_3_label = NULL_RTX;
18358   rtx align_4_label = gen_label_rtx ();
18359   rtx end_0_label = gen_label_rtx ();
18360   rtx mem;
18361   rtx tmpreg = gen_reg_rtx (SImode);
18362   rtx scratch = gen_reg_rtx (SImode);
18363   rtx cmp;
18364
18365   align = 0;
18366   if (CONST_INT_P (align_rtx))
18367     align = INTVAL (align_rtx);
18368
18369   /* Loop to check 1..3 bytes for null to get an aligned pointer.  */
18370
18371   /* Is there a known alignment and is it less than 4?  */
18372   if (align < 4)
18373     {
18374       rtx scratch1 = gen_reg_rtx (Pmode);
18375       emit_move_insn (scratch1, out);
18376       /* Is there a known alignment and is it not 2? */
18377       if (align != 2)
18378         {
18379           align_3_label = gen_label_rtx (); /* Label when aligned to 3-byte */
18380           align_2_label = gen_label_rtx (); /* Label when aligned to 2-byte */
18381
18382           /* Leave just the 3 lower bits.  */
18383           align_rtx = expand_binop (Pmode, and_optab, scratch1, GEN_INT (3),
18384                                     NULL_RTX, 0, OPTAB_WIDEN);
18385
18386           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
18387                                    Pmode, 1, align_4_label);
18388           emit_cmp_and_jump_insns (align_rtx, const2_rtx, EQ, NULL,
18389                                    Pmode, 1, align_2_label);
18390           emit_cmp_and_jump_insns (align_rtx, const2_rtx, GTU, NULL,
18391                                    Pmode, 1, align_3_label);
18392         }
18393       else
18394         {
18395           /* Since the alignment is 2, we have to check 2 or 0 bytes;
18396              check if is aligned to 4 - byte.  */
18397
18398           align_rtx = expand_binop (Pmode, and_optab, scratch1, const2_rtx,
18399                                     NULL_RTX, 0, OPTAB_WIDEN);
18400
18401           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
18402                                    Pmode, 1, align_4_label);
18403         }
18404
18405       mem = change_address (src, QImode, out);
18406
18407       /* Now compare the bytes.  */
18408
18409       /* Compare the first n unaligned byte on a byte per byte basis.  */
18410       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL,
18411                                QImode, 1, end_0_label);
18412
18413       /* Increment the address.  */
18414       emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
18415
18416       /* Not needed with an alignment of 2 */
18417       if (align != 2)
18418         {
18419           emit_label (align_2_label);
18420
18421           emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
18422                                    end_0_label);
18423
18424           emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
18425
18426           emit_label (align_3_label);
18427         }
18428
18429       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
18430                                end_0_label);
18431
18432       emit_insn ((*ix86_gen_add3) (out, out, const1_rtx));
18433     }
18434
18435   /* Generate loop to check 4 bytes at a time.  It is not a good idea to
18436      align this loop.  It gives only huge programs, but does not help to
18437      speed up.  */
18438   emit_label (align_4_label);
18439
18440   mem = change_address (src, SImode, out);
18441   emit_move_insn (scratch, mem);
18442   emit_insn ((*ix86_gen_add3) (out, out, GEN_INT (4)));
18443
18444   /* This formula yields a nonzero result iff one of the bytes is zero.
18445      This saves three branches inside loop and many cycles.  */
18446
18447   emit_insn (gen_addsi3 (tmpreg, scratch, GEN_INT (-0x01010101)));
18448   emit_insn (gen_one_cmplsi2 (scratch, scratch));
18449   emit_insn (gen_andsi3 (tmpreg, tmpreg, scratch));
18450   emit_insn (gen_andsi3 (tmpreg, tmpreg,
18451                          gen_int_mode (0x80808080, SImode)));
18452   emit_cmp_and_jump_insns (tmpreg, const0_rtx, EQ, 0, SImode, 1,
18453                            align_4_label);
18454
18455   if (TARGET_CMOVE)
18456     {
18457        rtx reg = gen_reg_rtx (SImode);
18458        rtx reg2 = gen_reg_rtx (Pmode);
18459        emit_move_insn (reg, tmpreg);
18460        emit_insn (gen_lshrsi3 (reg, reg, GEN_INT (16)));
18461
18462        /* If zero is not in the first two bytes, move two bytes forward.  */
18463        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
18464        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
18465        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
18466        emit_insn (gen_rtx_SET (VOIDmode, tmpreg,
18467                                gen_rtx_IF_THEN_ELSE (SImode, tmp,
18468                                                      reg,
18469                                                      tmpreg)));
18470        /* Emit lea manually to avoid clobbering of flags.  */
18471        emit_insn (gen_rtx_SET (SImode, reg2,
18472                                gen_rtx_PLUS (Pmode, out, const2_rtx)));
18473
18474        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
18475        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
18476        emit_insn (gen_rtx_SET (VOIDmode, out,
18477                                gen_rtx_IF_THEN_ELSE (Pmode, tmp,
18478                                                      reg2,
18479                                                      out)));
18480
18481     }
18482   else
18483     {
18484        rtx end_2_label = gen_label_rtx ();
18485        /* Is zero in the first two bytes? */
18486
18487        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
18488        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
18489        tmp = gen_rtx_NE (VOIDmode, tmp, const0_rtx);
18490        tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
18491                             gen_rtx_LABEL_REF (VOIDmode, end_2_label),
18492                             pc_rtx);
18493        tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
18494        JUMP_LABEL (tmp) = end_2_label;
18495
18496        /* Not in the first two.  Move two bytes forward.  */
18497        emit_insn (gen_lshrsi3 (tmpreg, tmpreg, GEN_INT (16)));
18498        emit_insn ((*ix86_gen_add3) (out, out, const2_rtx));
18499
18500        emit_label (end_2_label);
18501
18502     }
18503
18504   /* Avoid branch in fixing the byte.  */
18505   tmpreg = gen_lowpart (QImode, tmpreg);
18506   emit_insn (gen_addqi3_cc (tmpreg, tmpreg, tmpreg));
18507   cmp = gen_rtx_LTU (Pmode, gen_rtx_REG (CCmode, FLAGS_REG), const0_rtx);
18508   emit_insn ((*ix86_gen_sub3_carry) (out, out, GEN_INT (3), cmp));
18509
18510   emit_label (end_0_label);
18511 }
18512
18513 /* Expand strlen.  */
18514
18515 int
18516 ix86_expand_strlen (rtx out, rtx src, rtx eoschar, rtx align)
18517 {
18518   rtx addr, scratch1, scratch2, scratch3, scratch4;
18519
18520   /* The generic case of strlen expander is long.  Avoid it's
18521      expanding unless TARGET_INLINE_ALL_STRINGOPS.  */
18522
18523   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
18524       && !TARGET_INLINE_ALL_STRINGOPS
18525       && !optimize_insn_for_size_p ()
18526       && (!CONST_INT_P (align) || INTVAL (align) < 4))
18527     return 0;
18528
18529   addr = force_reg (Pmode, XEXP (src, 0));
18530   scratch1 = gen_reg_rtx (Pmode);
18531
18532   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
18533       && !optimize_insn_for_size_p ())
18534     {
18535       /* Well it seems that some optimizer does not combine a call like
18536          foo(strlen(bar), strlen(bar));
18537          when the move and the subtraction is done here.  It does calculate
18538          the length just once when these instructions are done inside of
18539          output_strlen_unroll().  But I think since &bar[strlen(bar)] is
18540          often used and I use one fewer register for the lifetime of
18541          output_strlen_unroll() this is better.  */
18542
18543       emit_move_insn (out, addr);
18544
18545       ix86_expand_strlensi_unroll_1 (out, src, align);
18546
18547       /* strlensi_unroll_1 returns the address of the zero at the end of
18548          the string, like memchr(), so compute the length by subtracting
18549          the start address.  */
18550       emit_insn ((*ix86_gen_sub3) (out, out, addr));
18551     }
18552   else
18553     {
18554       rtx unspec;
18555
18556       /* Can't use this if the user has appropriated eax, ecx, or edi.  */
18557       if (fixed_regs[AX_REG] || fixed_regs[CX_REG] || fixed_regs[DI_REG])
18558         return false;
18559
18560       scratch2 = gen_reg_rtx (Pmode);
18561       scratch3 = gen_reg_rtx (Pmode);
18562       scratch4 = force_reg (Pmode, constm1_rtx);
18563
18564       emit_move_insn (scratch3, addr);
18565       eoschar = force_reg (QImode, eoschar);
18566
18567       src = replace_equiv_address_nv (src, scratch3);
18568
18569       /* If .md starts supporting :P, this can be done in .md.  */
18570       unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (4, src, eoschar, align,
18571                                                  scratch4), UNSPEC_SCAS);
18572       emit_insn (gen_strlenqi_1 (scratch1, scratch3, unspec));
18573       emit_insn ((*ix86_gen_one_cmpl2) (scratch2, scratch1));
18574       emit_insn ((*ix86_gen_add3) (out, scratch2, constm1_rtx));
18575     }
18576   return 1;
18577 }
18578
18579 /* For given symbol (function) construct code to compute address of it's PLT
18580    entry in large x86-64 PIC model.  */
18581 rtx
18582 construct_plt_address (rtx symbol)
18583 {
18584   rtx tmp = gen_reg_rtx (Pmode);
18585   rtx unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, symbol), UNSPEC_PLTOFF);
18586
18587   gcc_assert (GET_CODE (symbol) == SYMBOL_REF);
18588   gcc_assert (ix86_cmodel == CM_LARGE_PIC);
18589
18590   emit_move_insn (tmp, gen_rtx_CONST (Pmode, unspec));
18591   emit_insn (gen_adddi3 (tmp, tmp, pic_offset_table_rtx));
18592   return tmp;
18593 }
18594
18595 void
18596 ix86_expand_call (rtx retval, rtx fnaddr, rtx callarg1,
18597                   rtx callarg2,
18598                   rtx pop, int sibcall)
18599 {
18600   rtx use = NULL, call;
18601   enum calling_abi function_call_abi;
18602
18603   if (callarg2 && INTVAL (callarg2) == -2)
18604     function_call_abi = MS_ABI;
18605   else
18606     function_call_abi = SYSV_ABI;
18607   if (pop == const0_rtx)
18608     pop = NULL;
18609   gcc_assert (!TARGET_64BIT || !pop);
18610
18611   if (TARGET_MACHO && !TARGET_64BIT)
18612     {
18613 #if TARGET_MACHO
18614       if (flag_pic && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF)
18615         fnaddr = machopic_indirect_call_target (fnaddr);
18616 #endif
18617     }
18618   else
18619     {
18620       /* Static functions and indirect calls don't need the pic register.  */
18621       if (flag_pic && (!TARGET_64BIT || ix86_cmodel == CM_LARGE_PIC)
18622           && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
18623           && ! SYMBOL_REF_LOCAL_P (XEXP (fnaddr, 0)))
18624         use_reg (&use, pic_offset_table_rtx);
18625     }
18626
18627   if (TARGET_64BIT && INTVAL (callarg2) >= 0)
18628     {
18629       rtx al = gen_rtx_REG (QImode, AX_REG);
18630       emit_move_insn (al, callarg2);
18631       use_reg (&use, al);
18632     }
18633
18634   if (ix86_cmodel == CM_LARGE_PIC
18635       && GET_CODE (fnaddr) == MEM
18636       && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
18637       && !local_symbolic_operand (XEXP (fnaddr, 0), VOIDmode))
18638     fnaddr = gen_rtx_MEM (QImode, construct_plt_address (XEXP (fnaddr, 0)));
18639   else if (! call_insn_operand (XEXP (fnaddr, 0), Pmode))
18640     {
18641       fnaddr = copy_to_mode_reg (Pmode, XEXP (fnaddr, 0));
18642       fnaddr = gen_rtx_MEM (QImode, fnaddr);
18643     }
18644   if (sibcall && TARGET_64BIT
18645       && !constant_call_address_operand (XEXP (fnaddr, 0), Pmode))
18646     {
18647       rtx addr;
18648       addr = copy_to_mode_reg (Pmode, XEXP (fnaddr, 0));
18649       fnaddr = gen_rtx_REG (Pmode, R11_REG);
18650       emit_move_insn (fnaddr, addr);
18651       fnaddr = gen_rtx_MEM (QImode, fnaddr);
18652     }
18653
18654   call = gen_rtx_CALL (VOIDmode, fnaddr, callarg1);
18655   if (retval)
18656     call = gen_rtx_SET (VOIDmode, retval, call);
18657   if (pop)
18658     {
18659       pop = gen_rtx_PLUS (Pmode, stack_pointer_rtx, pop);
18660       pop = gen_rtx_SET (VOIDmode, stack_pointer_rtx, pop);
18661       call = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, call, pop));
18662       gcc_assert (ix86_cfun_abi () != MS_ABI || function_call_abi != SYSV_ABI);
18663     }
18664   /* We need to represent that SI and DI registers are clobbered
18665      by SYSV calls.  */
18666   if (ix86_cfun_abi () == MS_ABI && function_call_abi == SYSV_ABI)
18667     {
18668       static int clobbered_registers[] = {27, 28, 45, 46, 47, 48, 49, 50, 51,
18669                                           52, SI_REG, DI_REG};
18670       unsigned int i;
18671       rtx vec[ARRAY_SIZE (clobbered_registers) + 2];
18672       rtx unspec = gen_rtx_UNSPEC (VOIDmode, gen_rtvec (1, const0_rtx),
18673                                    UNSPEC_MS_TO_SYSV_CALL);
18674
18675       vec[0] = call;
18676       vec[1] = unspec;
18677       for (i = 0; i < ARRAY_SIZE (clobbered_registers); i++)
18678         vec[i + 2] = gen_rtx_CLOBBER (SSE_REGNO_P (clobbered_registers[i])
18679                                       ? TImode : DImode,
18680                                       gen_rtx_REG
18681                                         (SSE_REGNO_P (clobbered_registers[i])
18682                                                       ? TImode : DImode,
18683                                          clobbered_registers[i]));
18684
18685       call = gen_rtx_PARALLEL (VOIDmode,
18686                                gen_rtvec_v (ARRAY_SIZE (clobbered_registers)
18687                                + 2, vec));
18688     }
18689
18690   call = emit_call_insn (call);
18691   if (use)
18692     CALL_INSN_FUNCTION_USAGE (call) = use;
18693 }
18694
18695 \f
18696 /* Clear stack slot assignments remembered from previous functions.
18697    This is called from INIT_EXPANDERS once before RTL is emitted for each
18698    function.  */
18699
18700 static struct machine_function *
18701 ix86_init_machine_status (void)
18702 {
18703   struct machine_function *f;
18704
18705   f = GGC_CNEW (struct machine_function);
18706   f->use_fast_prologue_epilogue_nregs = -1;
18707   f->tls_descriptor_call_expanded_p = 0;
18708   f->call_abi = DEFAULT_ABI;
18709
18710   return f;
18711 }
18712
18713 /* Return a MEM corresponding to a stack slot with mode MODE.
18714    Allocate a new slot if necessary.
18715
18716    The RTL for a function can have several slots available: N is
18717    which slot to use.  */
18718
18719 rtx
18720 assign_386_stack_local (enum machine_mode mode, enum ix86_stack_slot n)
18721 {
18722   struct stack_local_entry *s;
18723
18724   gcc_assert (n < MAX_386_STACK_LOCALS);
18725
18726   /* Virtual slot is valid only before vregs are instantiated.  */
18727   gcc_assert ((n == SLOT_VIRTUAL) == !virtuals_instantiated);
18728
18729   for (s = ix86_stack_locals; s; s = s->next)
18730     if (s->mode == mode && s->n == n)
18731       return copy_rtx (s->rtl);
18732
18733   s = (struct stack_local_entry *)
18734     ggc_alloc (sizeof (struct stack_local_entry));
18735   s->n = n;
18736   s->mode = mode;
18737   s->rtl = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
18738
18739   s->next = ix86_stack_locals;
18740   ix86_stack_locals = s;
18741   return s->rtl;
18742 }
18743
18744 /* Construct the SYMBOL_REF for the tls_get_addr function.  */
18745
18746 static GTY(()) rtx ix86_tls_symbol;
18747 rtx
18748 ix86_tls_get_addr (void)
18749 {
18750
18751   if (!ix86_tls_symbol)
18752     {
18753       ix86_tls_symbol = gen_rtx_SYMBOL_REF (Pmode,
18754                                             (TARGET_ANY_GNU_TLS
18755                                              && !TARGET_64BIT)
18756                                             ? "___tls_get_addr"
18757                                             : "__tls_get_addr");
18758     }
18759
18760   return ix86_tls_symbol;
18761 }
18762
18763 /* Construct the SYMBOL_REF for the _TLS_MODULE_BASE_ symbol.  */
18764
18765 static GTY(()) rtx ix86_tls_module_base_symbol;
18766 rtx
18767 ix86_tls_module_base (void)
18768 {
18769
18770   if (!ix86_tls_module_base_symbol)
18771     {
18772       ix86_tls_module_base_symbol = gen_rtx_SYMBOL_REF (Pmode,
18773                                                         "_TLS_MODULE_BASE_");
18774       SYMBOL_REF_FLAGS (ix86_tls_module_base_symbol)
18775         |= TLS_MODEL_GLOBAL_DYNAMIC << SYMBOL_FLAG_TLS_SHIFT;
18776     }
18777
18778   return ix86_tls_module_base_symbol;
18779 }
18780 \f
18781 /* Calculate the length of the memory address in the instruction
18782    encoding.  Does not include the one-byte modrm, opcode, or prefix.  */
18783
18784 int
18785 memory_address_length (rtx addr)
18786 {
18787   struct ix86_address parts;
18788   rtx base, index, disp;
18789   int len;
18790   int ok;
18791
18792   if (GET_CODE (addr) == PRE_DEC
18793       || GET_CODE (addr) == POST_INC
18794       || GET_CODE (addr) == PRE_MODIFY
18795       || GET_CODE (addr) == POST_MODIFY)
18796     return 0;
18797
18798   ok = ix86_decompose_address (addr, &parts);
18799   gcc_assert (ok);
18800
18801   if (parts.base && GET_CODE (parts.base) == SUBREG)
18802     parts.base = SUBREG_REG (parts.base);
18803   if (parts.index && GET_CODE (parts.index) == SUBREG)
18804     parts.index = SUBREG_REG (parts.index);
18805
18806   base = parts.base;
18807   index = parts.index;
18808   disp = parts.disp;
18809   len = 0;
18810
18811   /* Rule of thumb:
18812        - esp as the base always wants an index,
18813        - ebp as the base always wants a displacement.  */
18814
18815   /* Register Indirect.  */
18816   if (base && !index && !disp)
18817     {
18818       /* esp (for its index) and ebp (for its displacement) need
18819          the two-byte modrm form.  */
18820       if (addr == stack_pointer_rtx
18821           || addr == arg_pointer_rtx
18822           || addr == frame_pointer_rtx
18823           || addr == hard_frame_pointer_rtx)
18824         len = 1;
18825     }
18826
18827   /* Direct Addressing.  */
18828   else if (disp && !base && !index)
18829     len = 4;
18830
18831   else
18832     {
18833       /* Find the length of the displacement constant.  */
18834       if (disp)
18835         {
18836           if (base && satisfies_constraint_K (disp))
18837             len = 1;
18838           else
18839             len = 4;
18840         }
18841       /* ebp always wants a displacement.  */
18842       else if (base == hard_frame_pointer_rtx)
18843         len = 1;
18844
18845       /* An index requires the two-byte modrm form....  */
18846       if (index
18847           /* ...like esp, which always wants an index.  */
18848           || base == stack_pointer_rtx
18849           || base == arg_pointer_rtx
18850           || base == frame_pointer_rtx)
18851         len += 1;
18852     }
18853
18854   return len;
18855 }
18856
18857 /* Compute default value for "length_immediate" attribute.  When SHORTFORM
18858    is set, expect that insn have 8bit immediate alternative.  */
18859 int
18860 ix86_attr_length_immediate_default (rtx insn, int shortform)
18861 {
18862   int len = 0;
18863   int i;
18864   extract_insn_cached (insn);
18865   for (i = recog_data.n_operands - 1; i >= 0; --i)
18866     if (CONSTANT_P (recog_data.operand[i]))
18867       {
18868         gcc_assert (!len);
18869         if (shortform && satisfies_constraint_K (recog_data.operand[i]))
18870           len = 1;
18871         else
18872           {
18873             switch (get_attr_mode (insn))
18874               {
18875                 case MODE_QI:
18876                   len+=1;
18877                   break;
18878                 case MODE_HI:
18879                   len+=2;
18880                   break;
18881                 case MODE_SI:
18882                   len+=4;
18883                   break;
18884                 /* Immediates for DImode instructions are encoded as 32bit sign extended values.  */
18885                 case MODE_DI:
18886                   len+=4;
18887                   break;
18888                 default:
18889                   fatal_insn ("unknown insn mode", insn);
18890               }
18891           }
18892       }
18893   return len;
18894 }
18895 /* Compute default value for "length_address" attribute.  */
18896 int
18897 ix86_attr_length_address_default (rtx insn)
18898 {
18899   int i;
18900
18901   if (get_attr_type (insn) == TYPE_LEA)
18902     {
18903       rtx set = PATTERN (insn);
18904
18905       if (GET_CODE (set) == PARALLEL)
18906         set = XVECEXP (set, 0, 0);
18907
18908       gcc_assert (GET_CODE (set) == SET);
18909
18910       return memory_address_length (SET_SRC (set));
18911     }
18912
18913   extract_insn_cached (insn);
18914   for (i = recog_data.n_operands - 1; i >= 0; --i)
18915     if (MEM_P (recog_data.operand[i]))
18916       {
18917         return memory_address_length (XEXP (recog_data.operand[i], 0));
18918         break;
18919       }
18920   return 0;
18921 }
18922
18923 /* Compute default value for "length_vex" attribute. It includes
18924    2 or 3 byte VEX prefix and 1 opcode byte.  */
18925
18926 int
18927 ix86_attr_length_vex_default (rtx insn, int has_0f_opcode,
18928                               int has_vex_w)
18929 {
18930   int i;
18931
18932   /* Only 0f opcode can use 2 byte VEX prefix and  VEX W bit uses 3
18933      byte VEX prefix.  */
18934   if (!has_0f_opcode || has_vex_w)
18935     return 3 + 1;
18936
18937  /* We can always use 2 byte VEX prefix in 32bit.  */
18938   if (!TARGET_64BIT)
18939     return 2 + 1;
18940
18941   extract_insn_cached (insn);
18942
18943   for (i = recog_data.n_operands - 1; i >= 0; --i)
18944     if (REG_P (recog_data.operand[i]))
18945       {
18946         /* REX.W bit uses 3 byte VEX prefix.  */
18947         if (GET_MODE (recog_data.operand[i]) == DImode)
18948           return 3 + 1;
18949       }
18950     else
18951       {
18952         /* REX.X or REX.B bits use 3 byte VEX prefix.  */
18953         if (MEM_P (recog_data.operand[i])
18954             && x86_extended_reg_mentioned_p (recog_data.operand[i]))
18955           return 3 + 1;
18956       }
18957
18958   return 2 + 1;
18959 }
18960 \f
18961 /* Return the maximum number of instructions a cpu can issue.  */
18962
18963 static int
18964 ix86_issue_rate (void)
18965 {
18966   switch (ix86_tune)
18967     {
18968     case PROCESSOR_PENTIUM:
18969     case PROCESSOR_K6:
18970       return 2;
18971
18972     case PROCESSOR_PENTIUMPRO:
18973     case PROCESSOR_PENTIUM4:
18974     case PROCESSOR_ATHLON:
18975     case PROCESSOR_K8:
18976     case PROCESSOR_AMDFAM10:
18977     case PROCESSOR_NOCONA:
18978     case PROCESSOR_GENERIC32:
18979     case PROCESSOR_GENERIC64:
18980       return 3;
18981
18982     case PROCESSOR_CORE2:
18983       return 4;
18984
18985     default:
18986       return 1;
18987     }
18988 }
18989
18990 /* A subroutine of ix86_adjust_cost -- return true iff INSN reads flags set
18991    by DEP_INSN and nothing set by DEP_INSN.  */
18992
18993 static int
18994 ix86_flags_dependent (rtx insn, rtx dep_insn, enum attr_type insn_type)
18995 {
18996   rtx set, set2;
18997
18998   /* Simplify the test for uninteresting insns.  */
18999   if (insn_type != TYPE_SETCC
19000       && insn_type != TYPE_ICMOV
19001       && insn_type != TYPE_FCMOV
19002       && insn_type != TYPE_IBR)
19003     return 0;
19004
19005   if ((set = single_set (dep_insn)) != 0)
19006     {
19007       set = SET_DEST (set);
19008       set2 = NULL_RTX;
19009     }
19010   else if (GET_CODE (PATTERN (dep_insn)) == PARALLEL
19011            && XVECLEN (PATTERN (dep_insn), 0) == 2
19012            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 0)) == SET
19013            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 1)) == SET)
19014     {
19015       set = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
19016       set2 = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
19017     }
19018   else
19019     return 0;
19020
19021   if (!REG_P (set) || REGNO (set) != FLAGS_REG)
19022     return 0;
19023
19024   /* This test is true if the dependent insn reads the flags but
19025      not any other potentially set register.  */
19026   if (!reg_overlap_mentioned_p (set, PATTERN (insn)))
19027     return 0;
19028
19029   if (set2 && reg_overlap_mentioned_p (set2, PATTERN (insn)))
19030     return 0;
19031
19032   return 1;
19033 }
19034
19035 /* A subroutine of ix86_adjust_cost -- return true iff INSN has a memory
19036    address with operands set by DEP_INSN.  */
19037
19038 static int
19039 ix86_agi_dependent (rtx insn, rtx dep_insn, enum attr_type insn_type)
19040 {
19041   rtx addr;
19042
19043   if (insn_type == TYPE_LEA
19044       && TARGET_PENTIUM)
19045     {
19046       addr = PATTERN (insn);
19047
19048       if (GET_CODE (addr) == PARALLEL)
19049         addr = XVECEXP (addr, 0, 0);
19050
19051       gcc_assert (GET_CODE (addr) == SET);
19052
19053       addr = SET_SRC (addr);
19054     }
19055   else
19056     {
19057       int i;
19058       extract_insn_cached (insn);
19059       for (i = recog_data.n_operands - 1; i >= 0; --i)
19060         if (MEM_P (recog_data.operand[i]))
19061           {
19062             addr = XEXP (recog_data.operand[i], 0);
19063             goto found;
19064           }
19065       return 0;
19066     found:;
19067     }
19068
19069   return modified_in_p (addr, dep_insn);
19070 }
19071
19072 static int
19073 ix86_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
19074 {
19075   enum attr_type insn_type, dep_insn_type;
19076   enum attr_memory memory;
19077   rtx set, set2;
19078   int dep_insn_code_number;
19079
19080   /* Anti and output dependencies have zero cost on all CPUs.  */
19081   if (REG_NOTE_KIND (link) != 0)
19082     return 0;
19083
19084   dep_insn_code_number = recog_memoized (dep_insn);
19085
19086   /* If we can't recognize the insns, we can't really do anything.  */
19087   if (dep_insn_code_number < 0 || recog_memoized (insn) < 0)
19088     return cost;
19089
19090   insn_type = get_attr_type (insn);
19091   dep_insn_type = get_attr_type (dep_insn);
19092
19093   switch (ix86_tune)
19094     {
19095     case PROCESSOR_PENTIUM:
19096       /* Address Generation Interlock adds a cycle of latency.  */
19097       if (ix86_agi_dependent (insn, dep_insn, insn_type))
19098         cost += 1;
19099
19100       /* ??? Compares pair with jump/setcc.  */
19101       if (ix86_flags_dependent (insn, dep_insn, insn_type))
19102         cost = 0;
19103
19104       /* Floating point stores require value to be ready one cycle earlier.  */
19105       if (insn_type == TYPE_FMOV
19106           && get_attr_memory (insn) == MEMORY_STORE
19107           && !ix86_agi_dependent (insn, dep_insn, insn_type))
19108         cost += 1;
19109       break;
19110
19111     case PROCESSOR_PENTIUMPRO:
19112       memory = get_attr_memory (insn);
19113
19114       /* INT->FP conversion is expensive.  */
19115       if (get_attr_fp_int_src (dep_insn))
19116         cost += 5;
19117
19118       /* There is one cycle extra latency between an FP op and a store.  */
19119       if (insn_type == TYPE_FMOV
19120           && (set = single_set (dep_insn)) != NULL_RTX
19121           && (set2 = single_set (insn)) != NULL_RTX
19122           && rtx_equal_p (SET_DEST (set), SET_SRC (set2))
19123           && MEM_P (SET_DEST (set2)))
19124         cost += 1;
19125
19126       /* Show ability of reorder buffer to hide latency of load by executing
19127          in parallel with previous instruction in case
19128          previous instruction is not needed to compute the address.  */
19129       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
19130           && !ix86_agi_dependent (insn, dep_insn, insn_type))
19131         {
19132           /* Claim moves to take one cycle, as core can issue one load
19133              at time and the next load can start cycle later.  */
19134           if (dep_insn_type == TYPE_IMOV
19135               || dep_insn_type == TYPE_FMOV)
19136             cost = 1;
19137           else if (cost > 1)
19138             cost--;
19139         }
19140       break;
19141
19142     case PROCESSOR_K6:
19143       memory = get_attr_memory (insn);
19144
19145       /* The esp dependency is resolved before the instruction is really
19146          finished.  */
19147       if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP)
19148           && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP))
19149         return 1;
19150
19151       /* INT->FP conversion is expensive.  */
19152       if (get_attr_fp_int_src (dep_insn))
19153         cost += 5;
19154
19155       /* Show ability of reorder buffer to hide latency of load by executing
19156          in parallel with previous instruction in case
19157          previous instruction is not needed to compute the address.  */
19158       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
19159           && !ix86_agi_dependent (insn, dep_insn, insn_type))
19160         {
19161           /* Claim moves to take one cycle, as core can issue one load
19162              at time and the next load can start cycle later.  */
19163           if (dep_insn_type == TYPE_IMOV
19164               || dep_insn_type == TYPE_FMOV)
19165             cost = 1;
19166           else if (cost > 2)
19167             cost -= 2;
19168           else
19169             cost = 1;
19170         }
19171       break;
19172
19173     case PROCESSOR_ATHLON:
19174     case PROCESSOR_K8:
19175     case PROCESSOR_AMDFAM10:
19176     case PROCESSOR_GENERIC32:
19177     case PROCESSOR_GENERIC64:
19178       memory = get_attr_memory (insn);
19179
19180       /* Show ability of reorder buffer to hide latency of load by executing
19181          in parallel with previous instruction in case
19182          previous instruction is not needed to compute the address.  */
19183       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
19184           && !ix86_agi_dependent (insn, dep_insn, insn_type))
19185         {
19186           enum attr_unit unit = get_attr_unit (insn);
19187           int loadcost = 3;
19188
19189           /* Because of the difference between the length of integer and
19190              floating unit pipeline preparation stages, the memory operands
19191              for floating point are cheaper.
19192
19193              ??? For Athlon it the difference is most probably 2.  */
19194           if (unit == UNIT_INTEGER || unit == UNIT_UNKNOWN)
19195             loadcost = 3;
19196           else
19197             loadcost = TARGET_ATHLON ? 2 : 0;
19198
19199           if (cost >= loadcost)
19200             cost -= loadcost;
19201           else
19202             cost = 0;
19203         }
19204
19205     default:
19206       break;
19207     }
19208
19209   return cost;
19210 }
19211
19212 /* How many alternative schedules to try.  This should be as wide as the
19213    scheduling freedom in the DFA, but no wider.  Making this value too
19214    large results extra work for the scheduler.  */
19215
19216 static int
19217 ia32_multipass_dfa_lookahead (void)
19218 {
19219   switch (ix86_tune)
19220     {
19221     case PROCESSOR_PENTIUM:
19222       return 2;
19223
19224     case PROCESSOR_PENTIUMPRO:
19225     case PROCESSOR_K6:
19226       return 1;
19227
19228     default:
19229       return 0;
19230     }
19231 }
19232
19233 \f
19234 /* Compute the alignment given to a constant that is being placed in memory.
19235    EXP is the constant and ALIGN is the alignment that the object would
19236    ordinarily have.
19237    The value of this function is used instead of that alignment to align
19238    the object.  */
19239
19240 int
19241 ix86_constant_alignment (tree exp, int align)
19242 {
19243   if (TREE_CODE (exp) == REAL_CST || TREE_CODE (exp) == VECTOR_CST
19244       || TREE_CODE (exp) == INTEGER_CST)
19245     {
19246       if (TYPE_MODE (TREE_TYPE (exp)) == DFmode && align < 64)
19247         return 64;
19248       else if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (exp))) && align < 128)
19249         return 128;
19250     }
19251   else if (!optimize_size && TREE_CODE (exp) == STRING_CST
19252            && TREE_STRING_LENGTH (exp) >= 31 && align < BITS_PER_WORD)
19253     return BITS_PER_WORD;
19254
19255   return align;
19256 }
19257
19258 /* Compute the alignment for a static variable.
19259    TYPE is the data type, and ALIGN is the alignment that
19260    the object would ordinarily have.  The value of this function is used
19261    instead of that alignment to align the object.  */
19262
19263 int
19264 ix86_data_alignment (tree type, int align)
19265 {
19266   int max_align = optimize_size ? BITS_PER_WORD : MIN (256, MAX_OFILE_ALIGNMENT);
19267
19268   if (AGGREGATE_TYPE_P (type)
19269       && TYPE_SIZE (type)
19270       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
19271       && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= (unsigned) max_align
19272           || TREE_INT_CST_HIGH (TYPE_SIZE (type)))
19273       && align < max_align)
19274     align = max_align;
19275
19276   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
19277      to 16byte boundary.  */
19278   if (TARGET_64BIT)
19279     {
19280       if (AGGREGATE_TYPE_P (type)
19281            && TYPE_SIZE (type)
19282            && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
19283            && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 128
19284                || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 128)
19285         return 128;
19286     }
19287
19288   if (TREE_CODE (type) == ARRAY_TYPE)
19289     {
19290       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
19291         return 64;
19292       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
19293         return 128;
19294     }
19295   else if (TREE_CODE (type) == COMPLEX_TYPE)
19296     {
19297
19298       if (TYPE_MODE (type) == DCmode && align < 64)
19299         return 64;
19300       if ((TYPE_MODE (type) == XCmode
19301            || TYPE_MODE (type) == TCmode) && align < 128)
19302         return 128;
19303     }
19304   else if ((TREE_CODE (type) == RECORD_TYPE
19305             || TREE_CODE (type) == UNION_TYPE
19306             || TREE_CODE (type) == QUAL_UNION_TYPE)
19307            && TYPE_FIELDS (type))
19308     {
19309       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
19310         return 64;
19311       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
19312         return 128;
19313     }
19314   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
19315            || TREE_CODE (type) == INTEGER_TYPE)
19316     {
19317       if (TYPE_MODE (type) == DFmode && align < 64)
19318         return 64;
19319       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
19320         return 128;
19321     }
19322
19323   return align;
19324 }
19325
19326 /* Compute the alignment for a local variable or a stack slot.  TYPE is
19327    the data type, MODE is the widest mode available and ALIGN is the
19328    alignment that the object would ordinarily have.  The value of this
19329    macro is used instead of that alignment to align the object.  */
19330
19331 unsigned int
19332 ix86_local_alignment (tree type, enum machine_mode mode,
19333                       unsigned int align)
19334 {
19335   /* If TYPE is NULL, we are allocating a stack slot for caller-save
19336      register in MODE.  We will return the largest alignment of XF
19337      and DF.  */
19338   if (!type)
19339     {
19340       if (mode == XFmode && align < GET_MODE_ALIGNMENT (DFmode))
19341         align = GET_MODE_ALIGNMENT (DFmode);
19342       return align;
19343     }
19344
19345   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
19346      to 16byte boundary.  */
19347   if (TARGET_64BIT)
19348     {
19349       if (AGGREGATE_TYPE_P (type)
19350            && TYPE_SIZE (type)
19351            && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
19352            && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 16
19353                || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 128)
19354         return 128;
19355     }
19356   if (TREE_CODE (type) == ARRAY_TYPE)
19357     {
19358       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
19359         return 64;
19360       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
19361         return 128;
19362     }
19363   else if (TREE_CODE (type) == COMPLEX_TYPE)
19364     {
19365       if (TYPE_MODE (type) == DCmode && align < 64)
19366         return 64;
19367       if ((TYPE_MODE (type) == XCmode
19368            || TYPE_MODE (type) == TCmode) && align < 128)
19369         return 128;
19370     }
19371   else if ((TREE_CODE (type) == RECORD_TYPE
19372             || TREE_CODE (type) == UNION_TYPE
19373             || TREE_CODE (type) == QUAL_UNION_TYPE)
19374            && TYPE_FIELDS (type))
19375     {
19376       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
19377         return 64;
19378       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
19379         return 128;
19380     }
19381   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
19382            || TREE_CODE (type) == INTEGER_TYPE)
19383     {
19384
19385       if (TYPE_MODE (type) == DFmode && align < 64)
19386         return 64;
19387       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
19388         return 128;
19389     }
19390   return align;
19391 }
19392 \f
19393 /* Emit RTL insns to initialize the variable parts of a trampoline.
19394    FNADDR is an RTX for the address of the function's pure code.
19395    CXT is an RTX for the static chain value for the function.  */
19396 void
19397 x86_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
19398 {
19399   if (!TARGET_64BIT)
19400     {
19401       /* Compute offset from the end of the jmp to the target function.  */
19402       rtx disp = expand_binop (SImode, sub_optab, fnaddr,
19403                                plus_constant (tramp, 10),
19404                                NULL_RTX, 1, OPTAB_DIRECT);
19405       emit_move_insn (gen_rtx_MEM (QImode, tramp),
19406                       gen_int_mode (0xb9, QImode));
19407       emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 1)), cxt);
19408       emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, 5)),
19409                       gen_int_mode (0xe9, QImode));
19410       emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 6)), disp);
19411     }
19412   else
19413     {
19414       int offset = 0;
19415       /* Try to load address using shorter movl instead of movabs.
19416          We may want to support movq for kernel mode, but kernel does not use
19417          trampolines at the moment.  */
19418       if (x86_64_zext_immediate_operand (fnaddr, VOIDmode))
19419         {
19420           fnaddr = copy_to_mode_reg (DImode, fnaddr);
19421           emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
19422                           gen_int_mode (0xbb41, HImode));
19423           emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, offset + 2)),
19424                           gen_lowpart (SImode, fnaddr));
19425           offset += 6;
19426         }
19427       else
19428         {
19429           emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
19430                           gen_int_mode (0xbb49, HImode));
19431           emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, offset + 2)),
19432                           fnaddr);
19433           offset += 10;
19434         }
19435       /* Load static chain using movabs to r10.  */
19436       emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
19437                       gen_int_mode (0xba49, HImode));
19438       emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, offset + 2)),
19439                       cxt);
19440       offset += 10;
19441       /* Jump to the r11 */
19442       emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
19443                       gen_int_mode (0xff49, HImode));
19444       emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, offset+2)),
19445                       gen_int_mode (0xe3, QImode));
19446       offset += 3;
19447       gcc_assert (offset <= TRAMPOLINE_SIZE);
19448     }
19449
19450 #ifdef ENABLE_EXECUTE_STACK
19451   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
19452                      LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
19453 #endif
19454 }
19455 \f
19456 /* Codes for all the SSE/MMX builtins.  */
19457 enum ix86_builtins
19458 {
19459   IX86_BUILTIN_ADDPS,
19460   IX86_BUILTIN_ADDSS,
19461   IX86_BUILTIN_DIVPS,
19462   IX86_BUILTIN_DIVSS,
19463   IX86_BUILTIN_MULPS,
19464   IX86_BUILTIN_MULSS,
19465   IX86_BUILTIN_SUBPS,
19466   IX86_BUILTIN_SUBSS,
19467
19468   IX86_BUILTIN_CMPEQPS,
19469   IX86_BUILTIN_CMPLTPS,
19470   IX86_BUILTIN_CMPLEPS,
19471   IX86_BUILTIN_CMPGTPS,
19472   IX86_BUILTIN_CMPGEPS,
19473   IX86_BUILTIN_CMPNEQPS,
19474   IX86_BUILTIN_CMPNLTPS,
19475   IX86_BUILTIN_CMPNLEPS,
19476   IX86_BUILTIN_CMPNGTPS,
19477   IX86_BUILTIN_CMPNGEPS,
19478   IX86_BUILTIN_CMPORDPS,
19479   IX86_BUILTIN_CMPUNORDPS,
19480   IX86_BUILTIN_CMPEQSS,
19481   IX86_BUILTIN_CMPLTSS,
19482   IX86_BUILTIN_CMPLESS,
19483   IX86_BUILTIN_CMPNEQSS,
19484   IX86_BUILTIN_CMPNLTSS,
19485   IX86_BUILTIN_CMPNLESS,
19486   IX86_BUILTIN_CMPNGTSS,
19487   IX86_BUILTIN_CMPNGESS,
19488   IX86_BUILTIN_CMPORDSS,
19489   IX86_BUILTIN_CMPUNORDSS,
19490
19491   IX86_BUILTIN_COMIEQSS,
19492   IX86_BUILTIN_COMILTSS,
19493   IX86_BUILTIN_COMILESS,
19494   IX86_BUILTIN_COMIGTSS,
19495   IX86_BUILTIN_COMIGESS,
19496   IX86_BUILTIN_COMINEQSS,
19497   IX86_BUILTIN_UCOMIEQSS,
19498   IX86_BUILTIN_UCOMILTSS,
19499   IX86_BUILTIN_UCOMILESS,
19500   IX86_BUILTIN_UCOMIGTSS,
19501   IX86_BUILTIN_UCOMIGESS,
19502   IX86_BUILTIN_UCOMINEQSS,
19503
19504   IX86_BUILTIN_CVTPI2PS,
19505   IX86_BUILTIN_CVTPS2PI,
19506   IX86_BUILTIN_CVTSI2SS,
19507   IX86_BUILTIN_CVTSI642SS,
19508   IX86_BUILTIN_CVTSS2SI,
19509   IX86_BUILTIN_CVTSS2SI64,
19510   IX86_BUILTIN_CVTTPS2PI,
19511   IX86_BUILTIN_CVTTSS2SI,
19512   IX86_BUILTIN_CVTTSS2SI64,
19513
19514   IX86_BUILTIN_MAXPS,
19515   IX86_BUILTIN_MAXSS,
19516   IX86_BUILTIN_MINPS,
19517   IX86_BUILTIN_MINSS,
19518
19519   IX86_BUILTIN_LOADUPS,
19520   IX86_BUILTIN_STOREUPS,
19521   IX86_BUILTIN_MOVSS,
19522
19523   IX86_BUILTIN_MOVHLPS,
19524   IX86_BUILTIN_MOVLHPS,
19525   IX86_BUILTIN_LOADHPS,
19526   IX86_BUILTIN_LOADLPS,
19527   IX86_BUILTIN_STOREHPS,
19528   IX86_BUILTIN_STORELPS,
19529
19530   IX86_BUILTIN_MASKMOVQ,
19531   IX86_BUILTIN_MOVMSKPS,
19532   IX86_BUILTIN_PMOVMSKB,
19533
19534   IX86_BUILTIN_MOVNTPS,
19535   IX86_BUILTIN_MOVNTQ,
19536
19537   IX86_BUILTIN_LOADDQU,
19538   IX86_BUILTIN_STOREDQU,
19539
19540   IX86_BUILTIN_PACKSSWB,
19541   IX86_BUILTIN_PACKSSDW,
19542   IX86_BUILTIN_PACKUSWB,
19543
19544   IX86_BUILTIN_PADDB,
19545   IX86_BUILTIN_PADDW,
19546   IX86_BUILTIN_PADDD,
19547   IX86_BUILTIN_PADDQ,
19548   IX86_BUILTIN_PADDSB,
19549   IX86_BUILTIN_PADDSW,
19550   IX86_BUILTIN_PADDUSB,
19551   IX86_BUILTIN_PADDUSW,
19552   IX86_BUILTIN_PSUBB,
19553   IX86_BUILTIN_PSUBW,
19554   IX86_BUILTIN_PSUBD,
19555   IX86_BUILTIN_PSUBQ,
19556   IX86_BUILTIN_PSUBSB,
19557   IX86_BUILTIN_PSUBSW,
19558   IX86_BUILTIN_PSUBUSB,
19559   IX86_BUILTIN_PSUBUSW,
19560
19561   IX86_BUILTIN_PAND,
19562   IX86_BUILTIN_PANDN,
19563   IX86_BUILTIN_POR,
19564   IX86_BUILTIN_PXOR,
19565
19566   IX86_BUILTIN_PAVGB,
19567   IX86_BUILTIN_PAVGW,
19568
19569   IX86_BUILTIN_PCMPEQB,
19570   IX86_BUILTIN_PCMPEQW,
19571   IX86_BUILTIN_PCMPEQD,
19572   IX86_BUILTIN_PCMPGTB,
19573   IX86_BUILTIN_PCMPGTW,
19574   IX86_BUILTIN_PCMPGTD,
19575
19576   IX86_BUILTIN_PMADDWD,
19577
19578   IX86_BUILTIN_PMAXSW,
19579   IX86_BUILTIN_PMAXUB,
19580   IX86_BUILTIN_PMINSW,
19581   IX86_BUILTIN_PMINUB,
19582
19583   IX86_BUILTIN_PMULHUW,
19584   IX86_BUILTIN_PMULHW,
19585   IX86_BUILTIN_PMULLW,
19586
19587   IX86_BUILTIN_PSADBW,
19588   IX86_BUILTIN_PSHUFW,
19589
19590   IX86_BUILTIN_PSLLW,
19591   IX86_BUILTIN_PSLLD,
19592   IX86_BUILTIN_PSLLQ,
19593   IX86_BUILTIN_PSRAW,
19594   IX86_BUILTIN_PSRAD,
19595   IX86_BUILTIN_PSRLW,
19596   IX86_BUILTIN_PSRLD,
19597   IX86_BUILTIN_PSRLQ,
19598   IX86_BUILTIN_PSLLWI,
19599   IX86_BUILTIN_PSLLDI,
19600   IX86_BUILTIN_PSLLQI,
19601   IX86_BUILTIN_PSRAWI,
19602   IX86_BUILTIN_PSRADI,
19603   IX86_BUILTIN_PSRLWI,
19604   IX86_BUILTIN_PSRLDI,
19605   IX86_BUILTIN_PSRLQI,
19606
19607   IX86_BUILTIN_PUNPCKHBW,
19608   IX86_BUILTIN_PUNPCKHWD,
19609   IX86_BUILTIN_PUNPCKHDQ,
19610   IX86_BUILTIN_PUNPCKLBW,
19611   IX86_BUILTIN_PUNPCKLWD,
19612   IX86_BUILTIN_PUNPCKLDQ,
19613
19614   IX86_BUILTIN_SHUFPS,
19615
19616   IX86_BUILTIN_RCPPS,
19617   IX86_BUILTIN_RCPSS,
19618   IX86_BUILTIN_RSQRTPS,
19619   IX86_BUILTIN_RSQRTPS_NR,
19620   IX86_BUILTIN_RSQRTSS,
19621   IX86_BUILTIN_RSQRTF,
19622   IX86_BUILTIN_SQRTPS,
19623   IX86_BUILTIN_SQRTPS_NR,
19624   IX86_BUILTIN_SQRTSS,
19625
19626   IX86_BUILTIN_UNPCKHPS,
19627   IX86_BUILTIN_UNPCKLPS,
19628
19629   IX86_BUILTIN_ANDPS,
19630   IX86_BUILTIN_ANDNPS,
19631   IX86_BUILTIN_ORPS,
19632   IX86_BUILTIN_XORPS,
19633
19634   IX86_BUILTIN_EMMS,
19635   IX86_BUILTIN_LDMXCSR,
19636   IX86_BUILTIN_STMXCSR,
19637   IX86_BUILTIN_SFENCE,
19638
19639   /* 3DNow! Original */
19640   IX86_BUILTIN_FEMMS,
19641   IX86_BUILTIN_PAVGUSB,
19642   IX86_BUILTIN_PF2ID,
19643   IX86_BUILTIN_PFACC,
19644   IX86_BUILTIN_PFADD,
19645   IX86_BUILTIN_PFCMPEQ,
19646   IX86_BUILTIN_PFCMPGE,
19647   IX86_BUILTIN_PFCMPGT,
19648   IX86_BUILTIN_PFMAX,
19649   IX86_BUILTIN_PFMIN,
19650   IX86_BUILTIN_PFMUL,
19651   IX86_BUILTIN_PFRCP,
19652   IX86_BUILTIN_PFRCPIT1,
19653   IX86_BUILTIN_PFRCPIT2,
19654   IX86_BUILTIN_PFRSQIT1,
19655   IX86_BUILTIN_PFRSQRT,
19656   IX86_BUILTIN_PFSUB,
19657   IX86_BUILTIN_PFSUBR,
19658   IX86_BUILTIN_PI2FD,
19659   IX86_BUILTIN_PMULHRW,
19660
19661   /* 3DNow! Athlon Extensions */
19662   IX86_BUILTIN_PF2IW,
19663   IX86_BUILTIN_PFNACC,
19664   IX86_BUILTIN_PFPNACC,
19665   IX86_BUILTIN_PI2FW,
19666   IX86_BUILTIN_PSWAPDSI,
19667   IX86_BUILTIN_PSWAPDSF,
19668
19669   /* SSE2 */
19670   IX86_BUILTIN_ADDPD,
19671   IX86_BUILTIN_ADDSD,
19672   IX86_BUILTIN_DIVPD,
19673   IX86_BUILTIN_DIVSD,
19674   IX86_BUILTIN_MULPD,
19675   IX86_BUILTIN_MULSD,
19676   IX86_BUILTIN_SUBPD,
19677   IX86_BUILTIN_SUBSD,
19678
19679   IX86_BUILTIN_CMPEQPD,
19680   IX86_BUILTIN_CMPLTPD,
19681   IX86_BUILTIN_CMPLEPD,
19682   IX86_BUILTIN_CMPGTPD,
19683   IX86_BUILTIN_CMPGEPD,
19684   IX86_BUILTIN_CMPNEQPD,
19685   IX86_BUILTIN_CMPNLTPD,
19686   IX86_BUILTIN_CMPNLEPD,
19687   IX86_BUILTIN_CMPNGTPD,
19688   IX86_BUILTIN_CMPNGEPD,
19689   IX86_BUILTIN_CMPORDPD,
19690   IX86_BUILTIN_CMPUNORDPD,
19691   IX86_BUILTIN_CMPEQSD,
19692   IX86_BUILTIN_CMPLTSD,
19693   IX86_BUILTIN_CMPLESD,
19694   IX86_BUILTIN_CMPNEQSD,
19695   IX86_BUILTIN_CMPNLTSD,
19696   IX86_BUILTIN_CMPNLESD,
19697   IX86_BUILTIN_CMPORDSD,
19698   IX86_BUILTIN_CMPUNORDSD,
19699
19700   IX86_BUILTIN_COMIEQSD,
19701   IX86_BUILTIN_COMILTSD,
19702   IX86_BUILTIN_COMILESD,
19703   IX86_BUILTIN_COMIGTSD,
19704   IX86_BUILTIN_COMIGESD,
19705   IX86_BUILTIN_COMINEQSD,
19706   IX86_BUILTIN_UCOMIEQSD,
19707   IX86_BUILTIN_UCOMILTSD,
19708   IX86_BUILTIN_UCOMILESD,
19709   IX86_BUILTIN_UCOMIGTSD,
19710   IX86_BUILTIN_UCOMIGESD,
19711   IX86_BUILTIN_UCOMINEQSD,
19712
19713   IX86_BUILTIN_MAXPD,
19714   IX86_BUILTIN_MAXSD,
19715   IX86_BUILTIN_MINPD,
19716   IX86_BUILTIN_MINSD,
19717
19718   IX86_BUILTIN_ANDPD,
19719   IX86_BUILTIN_ANDNPD,
19720   IX86_BUILTIN_ORPD,
19721   IX86_BUILTIN_XORPD,
19722
19723   IX86_BUILTIN_SQRTPD,
19724   IX86_BUILTIN_SQRTSD,
19725
19726   IX86_BUILTIN_UNPCKHPD,
19727   IX86_BUILTIN_UNPCKLPD,
19728
19729   IX86_BUILTIN_SHUFPD,
19730
19731   IX86_BUILTIN_LOADUPD,
19732   IX86_BUILTIN_STOREUPD,
19733   IX86_BUILTIN_MOVSD,
19734
19735   IX86_BUILTIN_LOADHPD,
19736   IX86_BUILTIN_LOADLPD,
19737
19738   IX86_BUILTIN_CVTDQ2PD,
19739   IX86_BUILTIN_CVTDQ2PS,
19740
19741   IX86_BUILTIN_CVTPD2DQ,
19742   IX86_BUILTIN_CVTPD2PI,
19743   IX86_BUILTIN_CVTPD2PS,
19744   IX86_BUILTIN_CVTTPD2DQ,
19745   IX86_BUILTIN_CVTTPD2PI,
19746
19747   IX86_BUILTIN_CVTPI2PD,
19748   IX86_BUILTIN_CVTSI2SD,
19749   IX86_BUILTIN_CVTSI642SD,
19750
19751   IX86_BUILTIN_CVTSD2SI,
19752   IX86_BUILTIN_CVTSD2SI64,
19753   IX86_BUILTIN_CVTSD2SS,
19754   IX86_BUILTIN_CVTSS2SD,
19755   IX86_BUILTIN_CVTTSD2SI,
19756   IX86_BUILTIN_CVTTSD2SI64,
19757
19758   IX86_BUILTIN_CVTPS2DQ,
19759   IX86_BUILTIN_CVTPS2PD,
19760   IX86_BUILTIN_CVTTPS2DQ,
19761
19762   IX86_BUILTIN_MOVNTI,
19763   IX86_BUILTIN_MOVNTPD,
19764   IX86_BUILTIN_MOVNTDQ,
19765
19766   IX86_BUILTIN_MOVQ128,
19767
19768   /* SSE2 MMX */
19769   IX86_BUILTIN_MASKMOVDQU,
19770   IX86_BUILTIN_MOVMSKPD,
19771   IX86_BUILTIN_PMOVMSKB128,
19772
19773   IX86_BUILTIN_PACKSSWB128,
19774   IX86_BUILTIN_PACKSSDW128,
19775   IX86_BUILTIN_PACKUSWB128,
19776
19777   IX86_BUILTIN_PADDB128,
19778   IX86_BUILTIN_PADDW128,
19779   IX86_BUILTIN_PADDD128,
19780   IX86_BUILTIN_PADDQ128,
19781   IX86_BUILTIN_PADDSB128,
19782   IX86_BUILTIN_PADDSW128,
19783   IX86_BUILTIN_PADDUSB128,
19784   IX86_BUILTIN_PADDUSW128,
19785   IX86_BUILTIN_PSUBB128,
19786   IX86_BUILTIN_PSUBW128,
19787   IX86_BUILTIN_PSUBD128,
19788   IX86_BUILTIN_PSUBQ128,
19789   IX86_BUILTIN_PSUBSB128,
19790   IX86_BUILTIN_PSUBSW128,
19791   IX86_BUILTIN_PSUBUSB128,
19792   IX86_BUILTIN_PSUBUSW128,
19793
19794   IX86_BUILTIN_PAND128,
19795   IX86_BUILTIN_PANDN128,
19796   IX86_BUILTIN_POR128,
19797   IX86_BUILTIN_PXOR128,
19798
19799   IX86_BUILTIN_PAVGB128,
19800   IX86_BUILTIN_PAVGW128,
19801
19802   IX86_BUILTIN_PCMPEQB128,
19803   IX86_BUILTIN_PCMPEQW128,
19804   IX86_BUILTIN_PCMPEQD128,
19805   IX86_BUILTIN_PCMPGTB128,
19806   IX86_BUILTIN_PCMPGTW128,
19807   IX86_BUILTIN_PCMPGTD128,
19808
19809   IX86_BUILTIN_PMADDWD128,
19810
19811   IX86_BUILTIN_PMAXSW128,
19812   IX86_BUILTIN_PMAXUB128,
19813   IX86_BUILTIN_PMINSW128,
19814   IX86_BUILTIN_PMINUB128,
19815
19816   IX86_BUILTIN_PMULUDQ,
19817   IX86_BUILTIN_PMULUDQ128,
19818   IX86_BUILTIN_PMULHUW128,
19819   IX86_BUILTIN_PMULHW128,
19820   IX86_BUILTIN_PMULLW128,
19821
19822   IX86_BUILTIN_PSADBW128,
19823   IX86_BUILTIN_PSHUFHW,
19824   IX86_BUILTIN_PSHUFLW,
19825   IX86_BUILTIN_PSHUFD,
19826
19827   IX86_BUILTIN_PSLLDQI128,
19828   IX86_BUILTIN_PSLLWI128,
19829   IX86_BUILTIN_PSLLDI128,
19830   IX86_BUILTIN_PSLLQI128,
19831   IX86_BUILTIN_PSRAWI128,
19832   IX86_BUILTIN_PSRADI128,
19833   IX86_BUILTIN_PSRLDQI128,
19834   IX86_BUILTIN_PSRLWI128,
19835   IX86_BUILTIN_PSRLDI128,
19836   IX86_BUILTIN_PSRLQI128,
19837
19838   IX86_BUILTIN_PSLLDQ128,
19839   IX86_BUILTIN_PSLLW128,
19840   IX86_BUILTIN_PSLLD128,
19841   IX86_BUILTIN_PSLLQ128,
19842   IX86_BUILTIN_PSRAW128,
19843   IX86_BUILTIN_PSRAD128,
19844   IX86_BUILTIN_PSRLW128,
19845   IX86_BUILTIN_PSRLD128,
19846   IX86_BUILTIN_PSRLQ128,
19847
19848   IX86_BUILTIN_PUNPCKHBW128,
19849   IX86_BUILTIN_PUNPCKHWD128,
19850   IX86_BUILTIN_PUNPCKHDQ128,
19851   IX86_BUILTIN_PUNPCKHQDQ128,
19852   IX86_BUILTIN_PUNPCKLBW128,
19853   IX86_BUILTIN_PUNPCKLWD128,
19854   IX86_BUILTIN_PUNPCKLDQ128,
19855   IX86_BUILTIN_PUNPCKLQDQ128,
19856
19857   IX86_BUILTIN_CLFLUSH,
19858   IX86_BUILTIN_MFENCE,
19859   IX86_BUILTIN_LFENCE,
19860
19861   /* SSE3.  */
19862   IX86_BUILTIN_ADDSUBPS,
19863   IX86_BUILTIN_HADDPS,
19864   IX86_BUILTIN_HSUBPS,
19865   IX86_BUILTIN_MOVSHDUP,
19866   IX86_BUILTIN_MOVSLDUP,
19867   IX86_BUILTIN_ADDSUBPD,
19868   IX86_BUILTIN_HADDPD,
19869   IX86_BUILTIN_HSUBPD,
19870   IX86_BUILTIN_LDDQU,
19871
19872   IX86_BUILTIN_MONITOR,
19873   IX86_BUILTIN_MWAIT,
19874
19875   /* SSSE3.  */
19876   IX86_BUILTIN_PHADDW,
19877   IX86_BUILTIN_PHADDD,
19878   IX86_BUILTIN_PHADDSW,
19879   IX86_BUILTIN_PHSUBW,
19880   IX86_BUILTIN_PHSUBD,
19881   IX86_BUILTIN_PHSUBSW,
19882   IX86_BUILTIN_PMADDUBSW,
19883   IX86_BUILTIN_PMULHRSW,
19884   IX86_BUILTIN_PSHUFB,
19885   IX86_BUILTIN_PSIGNB,
19886   IX86_BUILTIN_PSIGNW,
19887   IX86_BUILTIN_PSIGND,
19888   IX86_BUILTIN_PALIGNR,
19889   IX86_BUILTIN_PABSB,
19890   IX86_BUILTIN_PABSW,
19891   IX86_BUILTIN_PABSD,
19892
19893   IX86_BUILTIN_PHADDW128,
19894   IX86_BUILTIN_PHADDD128,
19895   IX86_BUILTIN_PHADDSW128,
19896   IX86_BUILTIN_PHSUBW128,
19897   IX86_BUILTIN_PHSUBD128,
19898   IX86_BUILTIN_PHSUBSW128,
19899   IX86_BUILTIN_PMADDUBSW128,
19900   IX86_BUILTIN_PMULHRSW128,
19901   IX86_BUILTIN_PSHUFB128,
19902   IX86_BUILTIN_PSIGNB128,
19903   IX86_BUILTIN_PSIGNW128,
19904   IX86_BUILTIN_PSIGND128,
19905   IX86_BUILTIN_PALIGNR128,
19906   IX86_BUILTIN_PABSB128,
19907   IX86_BUILTIN_PABSW128,
19908   IX86_BUILTIN_PABSD128,
19909
19910   /* AMDFAM10 - SSE4A New Instructions.  */
19911   IX86_BUILTIN_MOVNTSD,
19912   IX86_BUILTIN_MOVNTSS,
19913   IX86_BUILTIN_EXTRQI,
19914   IX86_BUILTIN_EXTRQ,
19915   IX86_BUILTIN_INSERTQI,
19916   IX86_BUILTIN_INSERTQ,
19917
19918   /* SSE4.1.  */
19919   IX86_BUILTIN_BLENDPD,
19920   IX86_BUILTIN_BLENDPS,
19921   IX86_BUILTIN_BLENDVPD,
19922   IX86_BUILTIN_BLENDVPS,
19923   IX86_BUILTIN_PBLENDVB128,
19924   IX86_BUILTIN_PBLENDW128,
19925
19926   IX86_BUILTIN_DPPD,
19927   IX86_BUILTIN_DPPS,
19928
19929   IX86_BUILTIN_INSERTPS128,
19930
19931   IX86_BUILTIN_MOVNTDQA,
19932   IX86_BUILTIN_MPSADBW128,
19933   IX86_BUILTIN_PACKUSDW128,
19934   IX86_BUILTIN_PCMPEQQ,
19935   IX86_BUILTIN_PHMINPOSUW128,
19936
19937   IX86_BUILTIN_PMAXSB128,
19938   IX86_BUILTIN_PMAXSD128,
19939   IX86_BUILTIN_PMAXUD128,
19940   IX86_BUILTIN_PMAXUW128,
19941
19942   IX86_BUILTIN_PMINSB128,
19943   IX86_BUILTIN_PMINSD128,
19944   IX86_BUILTIN_PMINUD128,
19945   IX86_BUILTIN_PMINUW128,
19946
19947   IX86_BUILTIN_PMOVSXBW128,
19948   IX86_BUILTIN_PMOVSXBD128,
19949   IX86_BUILTIN_PMOVSXBQ128,
19950   IX86_BUILTIN_PMOVSXWD128,
19951   IX86_BUILTIN_PMOVSXWQ128,
19952   IX86_BUILTIN_PMOVSXDQ128,
19953
19954   IX86_BUILTIN_PMOVZXBW128,
19955   IX86_BUILTIN_PMOVZXBD128,
19956   IX86_BUILTIN_PMOVZXBQ128,
19957   IX86_BUILTIN_PMOVZXWD128,
19958   IX86_BUILTIN_PMOVZXWQ128,
19959   IX86_BUILTIN_PMOVZXDQ128,
19960
19961   IX86_BUILTIN_PMULDQ128,
19962   IX86_BUILTIN_PMULLD128,
19963
19964   IX86_BUILTIN_ROUNDPD,
19965   IX86_BUILTIN_ROUNDPS,
19966   IX86_BUILTIN_ROUNDSD,
19967   IX86_BUILTIN_ROUNDSS,
19968
19969   IX86_BUILTIN_PTESTZ,
19970   IX86_BUILTIN_PTESTC,
19971   IX86_BUILTIN_PTESTNZC,
19972
19973   IX86_BUILTIN_VEC_INIT_V2SI,
19974   IX86_BUILTIN_VEC_INIT_V4HI,
19975   IX86_BUILTIN_VEC_INIT_V8QI,
19976   IX86_BUILTIN_VEC_EXT_V2DF,
19977   IX86_BUILTIN_VEC_EXT_V2DI,
19978   IX86_BUILTIN_VEC_EXT_V4SF,
19979   IX86_BUILTIN_VEC_EXT_V4SI,
19980   IX86_BUILTIN_VEC_EXT_V8HI,
19981   IX86_BUILTIN_VEC_EXT_V2SI,
19982   IX86_BUILTIN_VEC_EXT_V4HI,
19983   IX86_BUILTIN_VEC_EXT_V16QI,
19984   IX86_BUILTIN_VEC_SET_V2DI,
19985   IX86_BUILTIN_VEC_SET_V4SF,
19986   IX86_BUILTIN_VEC_SET_V4SI,
19987   IX86_BUILTIN_VEC_SET_V8HI,
19988   IX86_BUILTIN_VEC_SET_V4HI,
19989   IX86_BUILTIN_VEC_SET_V16QI,
19990
19991   IX86_BUILTIN_VEC_PACK_SFIX,
19992
19993   /* SSE4.2.  */
19994   IX86_BUILTIN_CRC32QI,
19995   IX86_BUILTIN_CRC32HI,
19996   IX86_BUILTIN_CRC32SI,
19997   IX86_BUILTIN_CRC32DI,
19998
19999   IX86_BUILTIN_PCMPESTRI128,
20000   IX86_BUILTIN_PCMPESTRM128,
20001   IX86_BUILTIN_PCMPESTRA128,
20002   IX86_BUILTIN_PCMPESTRC128,
20003   IX86_BUILTIN_PCMPESTRO128,
20004   IX86_BUILTIN_PCMPESTRS128,
20005   IX86_BUILTIN_PCMPESTRZ128,
20006   IX86_BUILTIN_PCMPISTRI128,
20007   IX86_BUILTIN_PCMPISTRM128,
20008   IX86_BUILTIN_PCMPISTRA128,
20009   IX86_BUILTIN_PCMPISTRC128,
20010   IX86_BUILTIN_PCMPISTRO128,
20011   IX86_BUILTIN_PCMPISTRS128,
20012   IX86_BUILTIN_PCMPISTRZ128,
20013
20014   IX86_BUILTIN_PCMPGTQ,
20015
20016   /* AES instructions */
20017   IX86_BUILTIN_AESENC128,
20018   IX86_BUILTIN_AESENCLAST128,
20019   IX86_BUILTIN_AESDEC128,
20020   IX86_BUILTIN_AESDECLAST128,
20021   IX86_BUILTIN_AESIMC128,
20022   IX86_BUILTIN_AESKEYGENASSIST128,
20023
20024   /* PCLMUL instruction */
20025   IX86_BUILTIN_PCLMULQDQ128,
20026
20027   /* AVX */
20028   IX86_BUILTIN_ADDPD256,
20029   IX86_BUILTIN_ADDPS256,
20030   IX86_BUILTIN_ADDSUBPD256,
20031   IX86_BUILTIN_ADDSUBPS256,
20032   IX86_BUILTIN_ANDPD256,
20033   IX86_BUILTIN_ANDPS256,
20034   IX86_BUILTIN_ANDNPD256,
20035   IX86_BUILTIN_ANDNPS256,
20036   IX86_BUILTIN_BLENDPD256,
20037   IX86_BUILTIN_BLENDPS256,
20038   IX86_BUILTIN_BLENDVPD256,
20039   IX86_BUILTIN_BLENDVPS256,
20040   IX86_BUILTIN_DIVPD256,
20041   IX86_BUILTIN_DIVPS256,
20042   IX86_BUILTIN_DPPS256,
20043   IX86_BUILTIN_HADDPD256,
20044   IX86_BUILTIN_HADDPS256,
20045   IX86_BUILTIN_HSUBPD256,
20046   IX86_BUILTIN_HSUBPS256,
20047   IX86_BUILTIN_MAXPD256,
20048   IX86_BUILTIN_MAXPS256,
20049   IX86_BUILTIN_MINPD256,
20050   IX86_BUILTIN_MINPS256,
20051   IX86_BUILTIN_MULPD256,
20052   IX86_BUILTIN_MULPS256,
20053   IX86_BUILTIN_ORPD256,
20054   IX86_BUILTIN_ORPS256,
20055   IX86_BUILTIN_SHUFPD256,
20056   IX86_BUILTIN_SHUFPS256,
20057   IX86_BUILTIN_SUBPD256,
20058   IX86_BUILTIN_SUBPS256,
20059   IX86_BUILTIN_XORPD256,
20060   IX86_BUILTIN_XORPS256,
20061   IX86_BUILTIN_CMPSD,
20062   IX86_BUILTIN_CMPSS,
20063   IX86_BUILTIN_CMPPD,
20064   IX86_BUILTIN_CMPPS,
20065   IX86_BUILTIN_CMPPD256,
20066   IX86_BUILTIN_CMPPS256,
20067   IX86_BUILTIN_CVTDQ2PD256,
20068   IX86_BUILTIN_CVTDQ2PS256,
20069   IX86_BUILTIN_CVTPD2PS256,
20070   IX86_BUILTIN_CVTPS2DQ256,
20071   IX86_BUILTIN_CVTPS2PD256,
20072   IX86_BUILTIN_CVTTPD2DQ256,
20073   IX86_BUILTIN_CVTPD2DQ256,
20074   IX86_BUILTIN_CVTTPS2DQ256,
20075   IX86_BUILTIN_EXTRACTF128PD256,
20076   IX86_BUILTIN_EXTRACTF128PS256,
20077   IX86_BUILTIN_EXTRACTF128SI256,
20078   IX86_BUILTIN_VZEROALL,
20079   IX86_BUILTIN_VZEROUPPER,
20080   IX86_BUILTIN_VZEROUPPER_REX64,
20081   IX86_BUILTIN_VPERMILVARPD,
20082   IX86_BUILTIN_VPERMILVARPS,
20083   IX86_BUILTIN_VPERMILVARPD256,
20084   IX86_BUILTIN_VPERMILVARPS256,
20085   IX86_BUILTIN_VPERMILPD,
20086   IX86_BUILTIN_VPERMILPS,
20087   IX86_BUILTIN_VPERMILPD256,
20088   IX86_BUILTIN_VPERMILPS256,
20089   IX86_BUILTIN_VPERM2F128PD256,
20090   IX86_BUILTIN_VPERM2F128PS256,
20091   IX86_BUILTIN_VPERM2F128SI256,
20092   IX86_BUILTIN_VBROADCASTSS,
20093   IX86_BUILTIN_VBROADCASTSD256,
20094   IX86_BUILTIN_VBROADCASTSS256,
20095   IX86_BUILTIN_VBROADCASTPD256,
20096   IX86_BUILTIN_VBROADCASTPS256,
20097   IX86_BUILTIN_VINSERTF128PD256,
20098   IX86_BUILTIN_VINSERTF128PS256,
20099   IX86_BUILTIN_VINSERTF128SI256,
20100   IX86_BUILTIN_LOADUPD256,
20101   IX86_BUILTIN_LOADUPS256,
20102   IX86_BUILTIN_STOREUPD256,
20103   IX86_BUILTIN_STOREUPS256,
20104   IX86_BUILTIN_LDDQU256,
20105   IX86_BUILTIN_MOVNTDQ256,
20106   IX86_BUILTIN_MOVNTPD256,
20107   IX86_BUILTIN_MOVNTPS256,
20108   IX86_BUILTIN_LOADDQU256,
20109   IX86_BUILTIN_STOREDQU256,
20110   IX86_BUILTIN_MASKLOADPD,
20111   IX86_BUILTIN_MASKLOADPS,
20112   IX86_BUILTIN_MASKSTOREPD,
20113   IX86_BUILTIN_MASKSTOREPS,
20114   IX86_BUILTIN_MASKLOADPD256,
20115   IX86_BUILTIN_MASKLOADPS256,
20116   IX86_BUILTIN_MASKSTOREPD256,
20117   IX86_BUILTIN_MASKSTOREPS256,
20118   IX86_BUILTIN_MOVSHDUP256,
20119   IX86_BUILTIN_MOVSLDUP256,
20120   IX86_BUILTIN_MOVDDUP256,
20121
20122   IX86_BUILTIN_SQRTPD256,
20123   IX86_BUILTIN_SQRTPS256,
20124   IX86_BUILTIN_SQRTPS_NR256,
20125   IX86_BUILTIN_RSQRTPS256,
20126   IX86_BUILTIN_RSQRTPS_NR256,
20127
20128   IX86_BUILTIN_RCPPS256,
20129
20130   IX86_BUILTIN_ROUNDPD256,
20131   IX86_BUILTIN_ROUNDPS256,
20132
20133   IX86_BUILTIN_UNPCKHPD256,
20134   IX86_BUILTIN_UNPCKLPD256,
20135   IX86_BUILTIN_UNPCKHPS256,
20136   IX86_BUILTIN_UNPCKLPS256,
20137
20138   IX86_BUILTIN_SI256_SI,
20139   IX86_BUILTIN_PS256_PS,
20140   IX86_BUILTIN_PD256_PD,
20141   IX86_BUILTIN_SI_SI256,
20142   IX86_BUILTIN_PS_PS256,
20143   IX86_BUILTIN_PD_PD256,
20144
20145   IX86_BUILTIN_VTESTZPD,
20146   IX86_BUILTIN_VTESTCPD,
20147   IX86_BUILTIN_VTESTNZCPD,
20148   IX86_BUILTIN_VTESTZPS,
20149   IX86_BUILTIN_VTESTCPS,
20150   IX86_BUILTIN_VTESTNZCPS,
20151   IX86_BUILTIN_VTESTZPD256,
20152   IX86_BUILTIN_VTESTCPD256,
20153   IX86_BUILTIN_VTESTNZCPD256,
20154   IX86_BUILTIN_VTESTZPS256,
20155   IX86_BUILTIN_VTESTCPS256,
20156   IX86_BUILTIN_VTESTNZCPS256,
20157   IX86_BUILTIN_PTESTZ256,
20158   IX86_BUILTIN_PTESTC256,
20159   IX86_BUILTIN_PTESTNZC256,
20160
20161   IX86_BUILTIN_MOVMSKPD256,
20162   IX86_BUILTIN_MOVMSKPS256,
20163
20164   /* TFmode support builtins.  */
20165   IX86_BUILTIN_INFQ,
20166   IX86_BUILTIN_FABSQ,
20167   IX86_BUILTIN_COPYSIGNQ,
20168
20169   /* SSE5 instructions */
20170   IX86_BUILTIN_FMADDSS,
20171   IX86_BUILTIN_FMADDSD,
20172   IX86_BUILTIN_FMADDPS,
20173   IX86_BUILTIN_FMADDPD,
20174   IX86_BUILTIN_FMSUBSS,
20175   IX86_BUILTIN_FMSUBSD,
20176   IX86_BUILTIN_FMSUBPS,
20177   IX86_BUILTIN_FMSUBPD,
20178   IX86_BUILTIN_FNMADDSS,
20179   IX86_BUILTIN_FNMADDSD,
20180   IX86_BUILTIN_FNMADDPS,
20181   IX86_BUILTIN_FNMADDPD,
20182   IX86_BUILTIN_FNMSUBSS,
20183   IX86_BUILTIN_FNMSUBSD,
20184   IX86_BUILTIN_FNMSUBPS,
20185   IX86_BUILTIN_FNMSUBPD,
20186   IX86_BUILTIN_PCMOV,
20187   IX86_BUILTIN_PCMOV_V2DI,
20188   IX86_BUILTIN_PCMOV_V4SI,
20189   IX86_BUILTIN_PCMOV_V8HI,
20190   IX86_BUILTIN_PCMOV_V16QI,
20191   IX86_BUILTIN_PCMOV_V4SF,
20192   IX86_BUILTIN_PCMOV_V2DF,
20193   IX86_BUILTIN_PPERM,
20194   IX86_BUILTIN_PERMPS,
20195   IX86_BUILTIN_PERMPD,
20196   IX86_BUILTIN_PMACSSWW,
20197   IX86_BUILTIN_PMACSWW,
20198   IX86_BUILTIN_PMACSSWD,
20199   IX86_BUILTIN_PMACSWD,
20200   IX86_BUILTIN_PMACSSDD,
20201   IX86_BUILTIN_PMACSDD,
20202   IX86_BUILTIN_PMACSSDQL,
20203   IX86_BUILTIN_PMACSSDQH,
20204   IX86_BUILTIN_PMACSDQL,
20205   IX86_BUILTIN_PMACSDQH,
20206   IX86_BUILTIN_PMADCSSWD,
20207   IX86_BUILTIN_PMADCSWD,
20208   IX86_BUILTIN_PHADDBW,
20209   IX86_BUILTIN_PHADDBD,
20210   IX86_BUILTIN_PHADDBQ,
20211   IX86_BUILTIN_PHADDWD,
20212   IX86_BUILTIN_PHADDWQ,
20213   IX86_BUILTIN_PHADDDQ,
20214   IX86_BUILTIN_PHADDUBW,
20215   IX86_BUILTIN_PHADDUBD,
20216   IX86_BUILTIN_PHADDUBQ,
20217   IX86_BUILTIN_PHADDUWD,
20218   IX86_BUILTIN_PHADDUWQ,
20219   IX86_BUILTIN_PHADDUDQ,
20220   IX86_BUILTIN_PHSUBBW,
20221   IX86_BUILTIN_PHSUBWD,
20222   IX86_BUILTIN_PHSUBDQ,
20223   IX86_BUILTIN_PROTB,
20224   IX86_BUILTIN_PROTW,
20225   IX86_BUILTIN_PROTD,
20226   IX86_BUILTIN_PROTQ,
20227   IX86_BUILTIN_PROTB_IMM,
20228   IX86_BUILTIN_PROTW_IMM,
20229   IX86_BUILTIN_PROTD_IMM,
20230   IX86_BUILTIN_PROTQ_IMM,
20231   IX86_BUILTIN_PSHLB,
20232   IX86_BUILTIN_PSHLW,
20233   IX86_BUILTIN_PSHLD,
20234   IX86_BUILTIN_PSHLQ,
20235   IX86_BUILTIN_PSHAB,
20236   IX86_BUILTIN_PSHAW,
20237   IX86_BUILTIN_PSHAD,
20238   IX86_BUILTIN_PSHAQ,
20239   IX86_BUILTIN_FRCZSS,
20240   IX86_BUILTIN_FRCZSD,
20241   IX86_BUILTIN_FRCZPS,
20242   IX86_BUILTIN_FRCZPD,
20243   IX86_BUILTIN_CVTPH2PS,
20244   IX86_BUILTIN_CVTPS2PH,
20245
20246   IX86_BUILTIN_COMEQSS,
20247   IX86_BUILTIN_COMNESS,
20248   IX86_BUILTIN_COMLTSS,
20249   IX86_BUILTIN_COMLESS,
20250   IX86_BUILTIN_COMGTSS,
20251   IX86_BUILTIN_COMGESS,
20252   IX86_BUILTIN_COMUEQSS,
20253   IX86_BUILTIN_COMUNESS,
20254   IX86_BUILTIN_COMULTSS,
20255   IX86_BUILTIN_COMULESS,
20256   IX86_BUILTIN_COMUGTSS,
20257   IX86_BUILTIN_COMUGESS,
20258   IX86_BUILTIN_COMORDSS,
20259   IX86_BUILTIN_COMUNORDSS,
20260   IX86_BUILTIN_COMFALSESS,
20261   IX86_BUILTIN_COMTRUESS,
20262
20263   IX86_BUILTIN_COMEQSD,
20264   IX86_BUILTIN_COMNESD,
20265   IX86_BUILTIN_COMLTSD,
20266   IX86_BUILTIN_COMLESD,
20267   IX86_BUILTIN_COMGTSD,
20268   IX86_BUILTIN_COMGESD,
20269   IX86_BUILTIN_COMUEQSD,
20270   IX86_BUILTIN_COMUNESD,
20271   IX86_BUILTIN_COMULTSD,
20272   IX86_BUILTIN_COMULESD,
20273   IX86_BUILTIN_COMUGTSD,
20274   IX86_BUILTIN_COMUGESD,
20275   IX86_BUILTIN_COMORDSD,
20276   IX86_BUILTIN_COMUNORDSD,
20277   IX86_BUILTIN_COMFALSESD,
20278   IX86_BUILTIN_COMTRUESD,
20279
20280   IX86_BUILTIN_COMEQPS,
20281   IX86_BUILTIN_COMNEPS,
20282   IX86_BUILTIN_COMLTPS,
20283   IX86_BUILTIN_COMLEPS,
20284   IX86_BUILTIN_COMGTPS,
20285   IX86_BUILTIN_COMGEPS,
20286   IX86_BUILTIN_COMUEQPS,
20287   IX86_BUILTIN_COMUNEPS,
20288   IX86_BUILTIN_COMULTPS,
20289   IX86_BUILTIN_COMULEPS,
20290   IX86_BUILTIN_COMUGTPS,
20291   IX86_BUILTIN_COMUGEPS,
20292   IX86_BUILTIN_COMORDPS,
20293   IX86_BUILTIN_COMUNORDPS,
20294   IX86_BUILTIN_COMFALSEPS,
20295   IX86_BUILTIN_COMTRUEPS,
20296
20297   IX86_BUILTIN_COMEQPD,
20298   IX86_BUILTIN_COMNEPD,
20299   IX86_BUILTIN_COMLTPD,
20300   IX86_BUILTIN_COMLEPD,
20301   IX86_BUILTIN_COMGTPD,
20302   IX86_BUILTIN_COMGEPD,
20303   IX86_BUILTIN_COMUEQPD,
20304   IX86_BUILTIN_COMUNEPD,
20305   IX86_BUILTIN_COMULTPD,
20306   IX86_BUILTIN_COMULEPD,
20307   IX86_BUILTIN_COMUGTPD,
20308   IX86_BUILTIN_COMUGEPD,
20309   IX86_BUILTIN_COMORDPD,
20310   IX86_BUILTIN_COMUNORDPD,
20311   IX86_BUILTIN_COMFALSEPD,
20312   IX86_BUILTIN_COMTRUEPD,
20313
20314   IX86_BUILTIN_PCOMEQUB,
20315   IX86_BUILTIN_PCOMNEUB,
20316   IX86_BUILTIN_PCOMLTUB,
20317   IX86_BUILTIN_PCOMLEUB,
20318   IX86_BUILTIN_PCOMGTUB,
20319   IX86_BUILTIN_PCOMGEUB,
20320   IX86_BUILTIN_PCOMFALSEUB,
20321   IX86_BUILTIN_PCOMTRUEUB,
20322   IX86_BUILTIN_PCOMEQUW,
20323   IX86_BUILTIN_PCOMNEUW,
20324   IX86_BUILTIN_PCOMLTUW,
20325   IX86_BUILTIN_PCOMLEUW,
20326   IX86_BUILTIN_PCOMGTUW,
20327   IX86_BUILTIN_PCOMGEUW,
20328   IX86_BUILTIN_PCOMFALSEUW,
20329   IX86_BUILTIN_PCOMTRUEUW,
20330   IX86_BUILTIN_PCOMEQUD,
20331   IX86_BUILTIN_PCOMNEUD,
20332   IX86_BUILTIN_PCOMLTUD,
20333   IX86_BUILTIN_PCOMLEUD,
20334   IX86_BUILTIN_PCOMGTUD,
20335   IX86_BUILTIN_PCOMGEUD,
20336   IX86_BUILTIN_PCOMFALSEUD,
20337   IX86_BUILTIN_PCOMTRUEUD,
20338   IX86_BUILTIN_PCOMEQUQ,
20339   IX86_BUILTIN_PCOMNEUQ,
20340   IX86_BUILTIN_PCOMLTUQ,
20341   IX86_BUILTIN_PCOMLEUQ,
20342   IX86_BUILTIN_PCOMGTUQ,
20343   IX86_BUILTIN_PCOMGEUQ,
20344   IX86_BUILTIN_PCOMFALSEUQ,
20345   IX86_BUILTIN_PCOMTRUEUQ,
20346
20347   IX86_BUILTIN_PCOMEQB,
20348   IX86_BUILTIN_PCOMNEB,
20349   IX86_BUILTIN_PCOMLTB,
20350   IX86_BUILTIN_PCOMLEB,
20351   IX86_BUILTIN_PCOMGTB,
20352   IX86_BUILTIN_PCOMGEB,
20353   IX86_BUILTIN_PCOMFALSEB,
20354   IX86_BUILTIN_PCOMTRUEB,
20355   IX86_BUILTIN_PCOMEQW,
20356   IX86_BUILTIN_PCOMNEW,
20357   IX86_BUILTIN_PCOMLTW,
20358   IX86_BUILTIN_PCOMLEW,
20359   IX86_BUILTIN_PCOMGTW,
20360   IX86_BUILTIN_PCOMGEW,
20361   IX86_BUILTIN_PCOMFALSEW,
20362   IX86_BUILTIN_PCOMTRUEW,
20363   IX86_BUILTIN_PCOMEQD,
20364   IX86_BUILTIN_PCOMNED,
20365   IX86_BUILTIN_PCOMLTD,
20366   IX86_BUILTIN_PCOMLED,
20367   IX86_BUILTIN_PCOMGTD,
20368   IX86_BUILTIN_PCOMGED,
20369   IX86_BUILTIN_PCOMFALSED,
20370   IX86_BUILTIN_PCOMTRUED,
20371   IX86_BUILTIN_PCOMEQQ,
20372   IX86_BUILTIN_PCOMNEQ,
20373   IX86_BUILTIN_PCOMLTQ,
20374   IX86_BUILTIN_PCOMLEQ,
20375   IX86_BUILTIN_PCOMGTQ,
20376   IX86_BUILTIN_PCOMGEQ,
20377   IX86_BUILTIN_PCOMFALSEQ,
20378   IX86_BUILTIN_PCOMTRUEQ,
20379
20380   IX86_BUILTIN_MAX
20381 };
20382
20383 /* Table for the ix86 builtin decls.  */
20384 static GTY(()) tree ix86_builtins[(int) IX86_BUILTIN_MAX];
20385
20386 /* Table of all of the builtin functions that are possible with different ISA's
20387    but are waiting to be built until a function is declared to use that
20388    ISA.  */
20389 struct builtin_isa GTY(())
20390 {
20391   tree type;                    /* builtin type to use in the declaration */
20392   const char *name;             /* function name */
20393   int isa;                      /* isa_flags this builtin is defined for */
20394   bool const_p;                 /* true if the declaration is constant */
20395 };
20396
20397 static GTY(()) struct builtin_isa ix86_builtins_isa[(int) IX86_BUILTIN_MAX];
20398
20399
20400 /* Add an ix86 target builtin function with CODE, NAME and TYPE.  Save the MASK
20401  * of which isa_flags to use in the ix86_builtins_isa array.  Stores the
20402  * function decl in the ix86_builtins array.  Returns the function decl or
20403  * NULL_TREE, if the builtin was not added.
20404  *
20405  * If the front end has a special hook for builtin functions, delay adding
20406  * builtin functions that aren't in the current ISA until the ISA is changed
20407  * with function specific optimization.  Doing so, can save about 300K for the
20408  * default compiler.  When the builtin is expanded, check at that time whether
20409  * it is valid.
20410  *
20411  * If the front end doesn't have a special hook, record all builtins, even if
20412  * it isn't an instruction set in the current ISA in case the user uses
20413  * function specific options for a different ISA, so that we don't get scope
20414  * errors if a builtin is added in the middle of a function scope.  */
20415
20416 static inline tree
20417 def_builtin (int mask, const char *name, tree type, enum ix86_builtins code)
20418 {
20419   tree decl = NULL_TREE;
20420
20421   if (!(mask & OPTION_MASK_ISA_64BIT) || TARGET_64BIT)
20422     {
20423       ix86_builtins_isa[(int) code].isa = mask;
20424
20425       if ((mask & ix86_isa_flags) != 0
20426           || (lang_hooks.builtin_function
20427               == lang_hooks.builtin_function_ext_scope))
20428
20429         {
20430           decl = add_builtin_function (name, type, code, BUILT_IN_MD, NULL,
20431                                        NULL_TREE);
20432           ix86_builtins[(int) code] = decl;
20433           ix86_builtins_isa[(int) code].type = NULL_TREE;
20434         }
20435       else
20436         {
20437           ix86_builtins[(int) code] = NULL_TREE;
20438           ix86_builtins_isa[(int) code].const_p = false;
20439           ix86_builtins_isa[(int) code].type = type;
20440           ix86_builtins_isa[(int) code].name = name;
20441         }
20442     }
20443
20444   return decl;
20445 }
20446
20447 /* Like def_builtin, but also marks the function decl "const".  */
20448
20449 static inline tree
20450 def_builtin_const (int mask, const char *name, tree type,
20451                    enum ix86_builtins code)
20452 {
20453   tree decl = def_builtin (mask, name, type, code);
20454   if (decl)
20455     TREE_READONLY (decl) = 1;
20456   else
20457     ix86_builtins_isa[(int) code].const_p = true;
20458
20459   return decl;
20460 }
20461
20462 /* Add any new builtin functions for a given ISA that may not have been
20463    declared.  This saves a bit of space compared to adding all of the
20464    declarations to the tree, even if we didn't use them.  */
20465
20466 static void
20467 ix86_add_new_builtins (int isa)
20468 {
20469   int i;
20470   tree decl;
20471
20472   for (i = 0; i < (int)IX86_BUILTIN_MAX; i++)
20473     {
20474       if ((ix86_builtins_isa[i].isa & isa) != 0
20475           && ix86_builtins_isa[i].type != NULL_TREE)
20476         {
20477           decl = add_builtin_function_ext_scope (ix86_builtins_isa[i].name,
20478                                                  ix86_builtins_isa[i].type,
20479                                                  i, BUILT_IN_MD, NULL,
20480                                                  NULL_TREE);
20481
20482           ix86_builtins[i] = decl;
20483           ix86_builtins_isa[i].type = NULL_TREE;
20484           if (ix86_builtins_isa[i].const_p)
20485             TREE_READONLY (decl) = 1;
20486         }
20487     }
20488 }
20489
20490 /* Bits for builtin_description.flag.  */
20491
20492 /* Set when we don't support the comparison natively, and should
20493    swap_comparison in order to support it.  */
20494 #define BUILTIN_DESC_SWAP_OPERANDS      1
20495
20496 struct builtin_description
20497 {
20498   const unsigned int mask;
20499   const enum insn_code icode;
20500   const char *const name;
20501   const enum ix86_builtins code;
20502   const enum rtx_code comparison;
20503   const int flag;
20504 };
20505
20506 static const struct builtin_description bdesc_comi[] =
20507 {
20508   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comieq", IX86_BUILTIN_COMIEQSS, UNEQ, 0 },
20509   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comilt", IX86_BUILTIN_COMILTSS, UNLT, 0 },
20510   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comile", IX86_BUILTIN_COMILESS, UNLE, 0 },
20511   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comigt", IX86_BUILTIN_COMIGTSS, GT, 0 },
20512   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comige", IX86_BUILTIN_COMIGESS, GE, 0 },
20513   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comineq", IX86_BUILTIN_COMINEQSS, LTGT, 0 },
20514   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomieq", IX86_BUILTIN_UCOMIEQSS, UNEQ, 0 },
20515   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomilt", IX86_BUILTIN_UCOMILTSS, UNLT, 0 },
20516   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomile", IX86_BUILTIN_UCOMILESS, UNLE, 0 },
20517   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomigt", IX86_BUILTIN_UCOMIGTSS, GT, 0 },
20518   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomige", IX86_BUILTIN_UCOMIGESS, GE, 0 },
20519   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomineq", IX86_BUILTIN_UCOMINEQSS, LTGT, 0 },
20520   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdeq", IX86_BUILTIN_COMIEQSD, UNEQ, 0 },
20521   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdlt", IX86_BUILTIN_COMILTSD, UNLT, 0 },
20522   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdle", IX86_BUILTIN_COMILESD, UNLE, 0 },
20523   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdgt", IX86_BUILTIN_COMIGTSD, GT, 0 },
20524   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdge", IX86_BUILTIN_COMIGESD, GE, 0 },
20525   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdneq", IX86_BUILTIN_COMINEQSD, LTGT, 0 },
20526   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdeq", IX86_BUILTIN_UCOMIEQSD, UNEQ, 0 },
20527   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdlt", IX86_BUILTIN_UCOMILTSD, UNLT, 0 },
20528   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdle", IX86_BUILTIN_UCOMILESD, UNLE, 0 },
20529   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdgt", IX86_BUILTIN_UCOMIGTSD, GT, 0 },
20530   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdge", IX86_BUILTIN_UCOMIGESD, GE, 0 },
20531   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdneq", IX86_BUILTIN_UCOMINEQSD, LTGT, 0 },
20532 };
20533
20534 static const struct builtin_description bdesc_pcmpestr[] =
20535 {
20536   /* SSE4.2 */
20537   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestri128", IX86_BUILTIN_PCMPESTRI128, UNKNOWN, 0 },
20538   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrm128", IX86_BUILTIN_PCMPESTRM128, UNKNOWN, 0 },
20539   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestria128", IX86_BUILTIN_PCMPESTRA128, UNKNOWN, (int) CCAmode },
20540   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestric128", IX86_BUILTIN_PCMPESTRC128, UNKNOWN, (int) CCCmode },
20541   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrio128", IX86_BUILTIN_PCMPESTRO128, UNKNOWN, (int) CCOmode },
20542   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestris128", IX86_BUILTIN_PCMPESTRS128, UNKNOWN, (int) CCSmode },
20543   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestriz128", IX86_BUILTIN_PCMPESTRZ128, UNKNOWN, (int) CCZmode },
20544 };
20545
20546 static const struct builtin_description bdesc_pcmpistr[] =
20547 {
20548   /* SSE4.2 */
20549   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistri128", IX86_BUILTIN_PCMPISTRI128, UNKNOWN, 0 },
20550   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrm128", IX86_BUILTIN_PCMPISTRM128, UNKNOWN, 0 },
20551   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistria128", IX86_BUILTIN_PCMPISTRA128, UNKNOWN, (int) CCAmode },
20552   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistric128", IX86_BUILTIN_PCMPISTRC128, UNKNOWN, (int) CCCmode },
20553   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrio128", IX86_BUILTIN_PCMPISTRO128, UNKNOWN, (int) CCOmode },
20554   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistris128", IX86_BUILTIN_PCMPISTRS128, UNKNOWN, (int) CCSmode },
20555   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistriz128", IX86_BUILTIN_PCMPISTRZ128, UNKNOWN, (int) CCZmode },
20556 };
20557
20558 /* Special builtin types */
20559 enum ix86_special_builtin_type
20560 {
20561   SPECIAL_FTYPE_UNKNOWN,
20562   VOID_FTYPE_VOID,
20563   V32QI_FTYPE_PCCHAR,
20564   V16QI_FTYPE_PCCHAR,
20565   V8SF_FTYPE_PCV4SF,
20566   V8SF_FTYPE_PCFLOAT,
20567   V4DF_FTYPE_PCV2DF,
20568   V4DF_FTYPE_PCDOUBLE,
20569   V4SF_FTYPE_PCFLOAT,
20570   V2DF_FTYPE_PCDOUBLE,
20571   V8SF_FTYPE_PCV8SF_V8SF,
20572   V4DF_FTYPE_PCV4DF_V4DF,
20573   V4SF_FTYPE_V4SF_PCV2SF,
20574   V4SF_FTYPE_PCV4SF_V4SF,
20575   V2DF_FTYPE_V2DF_PCDOUBLE,
20576   V2DF_FTYPE_PCV2DF_V2DF,
20577   V2DI_FTYPE_PV2DI,
20578   VOID_FTYPE_PV2SF_V4SF,
20579   VOID_FTYPE_PV4DI_V4DI,
20580   VOID_FTYPE_PV2DI_V2DI,
20581   VOID_FTYPE_PCHAR_V32QI,
20582   VOID_FTYPE_PCHAR_V16QI,
20583   VOID_FTYPE_PFLOAT_V8SF,
20584   VOID_FTYPE_PFLOAT_V4SF,
20585   VOID_FTYPE_PDOUBLE_V4DF,
20586   VOID_FTYPE_PDOUBLE_V2DF,
20587   VOID_FTYPE_PDI_DI,
20588   VOID_FTYPE_PINT_INT,
20589   VOID_FTYPE_PV8SF_V8SF_V8SF,
20590   VOID_FTYPE_PV4DF_V4DF_V4DF,
20591   VOID_FTYPE_PV4SF_V4SF_V4SF,
20592   VOID_FTYPE_PV2DF_V2DF_V2DF
20593 };
20594
20595 /* Builtin types */
20596 enum ix86_builtin_type
20597 {
20598   FTYPE_UNKNOWN,
20599   FLOAT128_FTYPE_FLOAT128,
20600   FLOAT_FTYPE_FLOAT,
20601   FLOAT128_FTYPE_FLOAT128_FLOAT128,
20602   INT_FTYPE_V8SF_V8SF_PTEST,
20603   INT_FTYPE_V4DI_V4DI_PTEST,
20604   INT_FTYPE_V4DF_V4DF_PTEST,
20605   INT_FTYPE_V4SF_V4SF_PTEST,
20606   INT_FTYPE_V2DI_V2DI_PTEST,
20607   INT_FTYPE_V2DF_V2DF_PTEST,
20608   INT64_FTYPE_V4SF,
20609   INT64_FTYPE_V2DF,
20610   INT_FTYPE_V16QI,
20611   INT_FTYPE_V8QI,
20612   INT_FTYPE_V8SF,
20613   INT_FTYPE_V4DF,
20614   INT_FTYPE_V4SF,
20615   INT_FTYPE_V2DF,
20616   V16QI_FTYPE_V16QI,
20617   V8SI_FTYPE_V8SF,
20618   V8SI_FTYPE_V4SI,
20619   V8HI_FTYPE_V8HI,
20620   V8HI_FTYPE_V16QI,
20621   V8QI_FTYPE_V8QI,
20622   V8SF_FTYPE_V8SF,
20623   V8SF_FTYPE_V8SI,
20624   V8SF_FTYPE_V4SF,
20625   V4SI_FTYPE_V4SI,
20626   V4SI_FTYPE_V16QI,
20627   V4SI_FTYPE_V8SI,
20628   V4SI_FTYPE_V8HI,
20629   V4SI_FTYPE_V4DF,
20630   V4SI_FTYPE_V4SF,
20631   V4SI_FTYPE_V2DF,
20632   V4HI_FTYPE_V4HI,
20633   V4DF_FTYPE_V4DF,
20634   V4DF_FTYPE_V4SI,
20635   V4DF_FTYPE_V4SF,
20636   V4DF_FTYPE_V2DF,
20637   V4SF_FTYPE_V4DF,
20638   V4SF_FTYPE_V4SF,
20639   V4SF_FTYPE_V4SF_VEC_MERGE,
20640   V4SF_FTYPE_V8SF,
20641   V4SF_FTYPE_V4SI,
20642   V4SF_FTYPE_V2DF,
20643   V2DI_FTYPE_V2DI,
20644   V2DI_FTYPE_V16QI,
20645   V2DI_FTYPE_V8HI,
20646   V2DI_FTYPE_V4SI,
20647   V2DF_FTYPE_V2DF,
20648   V2DF_FTYPE_V2DF_VEC_MERGE,
20649   V2DF_FTYPE_V4SI,
20650   V2DF_FTYPE_V4DF,
20651   V2DF_FTYPE_V4SF,
20652   V2DF_FTYPE_V2SI,
20653   V2SI_FTYPE_V2SI,
20654   V2SI_FTYPE_V4SF,
20655   V2SI_FTYPE_V2SF,
20656   V2SI_FTYPE_V2DF,
20657   V2SF_FTYPE_V2SF,
20658   V2SF_FTYPE_V2SI,
20659   V16QI_FTYPE_V16QI_V16QI,
20660   V16QI_FTYPE_V8HI_V8HI,
20661   V8QI_FTYPE_V8QI_V8QI,
20662   V8QI_FTYPE_V4HI_V4HI,
20663   V8HI_FTYPE_V8HI_V8HI,
20664   V8HI_FTYPE_V8HI_V8HI_COUNT,
20665   V8HI_FTYPE_V16QI_V16QI,
20666   V8HI_FTYPE_V4SI_V4SI,
20667   V8HI_FTYPE_V8HI_SI_COUNT,
20668   V8SF_FTYPE_V8SF_V8SF,
20669   V8SF_FTYPE_V8SF_V8SI,
20670   V4SI_FTYPE_V4SI_V4SI,
20671   V4SI_FTYPE_V4SI_V4SI_COUNT,
20672   V4SI_FTYPE_V8HI_V8HI,
20673   V4SI_FTYPE_V4SF_V4SF,
20674   V4SI_FTYPE_V2DF_V2DF,
20675   V4SI_FTYPE_V4SI_SI_COUNT,
20676   V4HI_FTYPE_V4HI_V4HI,
20677   V4HI_FTYPE_V4HI_V4HI_COUNT,
20678   V4HI_FTYPE_V8QI_V8QI,
20679   V4HI_FTYPE_V2SI_V2SI,
20680   V4HI_FTYPE_V4HI_SI_COUNT,
20681   V4DF_FTYPE_V4DF_V4DF,
20682   V4DF_FTYPE_V4DF_V4DI,
20683   V4SF_FTYPE_V4SF_V4SF,
20684   V4SF_FTYPE_V4SF_V4SF_SWAP,
20685   V4SF_FTYPE_V4SF_V4SI,
20686   V4SF_FTYPE_V4SF_V2SI,
20687   V4SF_FTYPE_V4SF_V2DF,
20688   V4SF_FTYPE_V4SF_DI,
20689   V4SF_FTYPE_V4SF_SI,
20690   V2DI_FTYPE_V2DI_V2DI,
20691   V2DI_FTYPE_V2DI_V2DI_COUNT,
20692   V2DI_FTYPE_V16QI_V16QI,
20693   V2DI_FTYPE_V4SI_V4SI,
20694   V2DI_FTYPE_V2DI_V16QI,
20695   V2DI_FTYPE_V2DF_V2DF,
20696   V2DI_FTYPE_V2DI_SI_COUNT,
20697   V2SI_FTYPE_V2SI_V2SI,
20698   V2SI_FTYPE_V2SI_V2SI_COUNT,
20699   V2SI_FTYPE_V4HI_V4HI,
20700   V2SI_FTYPE_V2SF_V2SF,
20701   V2SI_FTYPE_V2SI_SI_COUNT,
20702   V2DF_FTYPE_V2DF_V2DF,
20703   V2DF_FTYPE_V2DF_V2DF_SWAP,
20704   V2DF_FTYPE_V2DF_V4SF,
20705   V2DF_FTYPE_V2DF_V2DI,
20706   V2DF_FTYPE_V2DF_DI,
20707   V2DF_FTYPE_V2DF_SI,
20708   V2SF_FTYPE_V2SF_V2SF,
20709   V1DI_FTYPE_V1DI_V1DI,
20710   V1DI_FTYPE_V1DI_V1DI_COUNT,
20711   V1DI_FTYPE_V8QI_V8QI,
20712   V1DI_FTYPE_V2SI_V2SI,
20713   V1DI_FTYPE_V1DI_SI_COUNT,
20714   UINT64_FTYPE_UINT64_UINT64,
20715   UINT_FTYPE_UINT_UINT,
20716   UINT_FTYPE_UINT_USHORT,
20717   UINT_FTYPE_UINT_UCHAR,
20718   V8HI_FTYPE_V8HI_INT,
20719   V4SI_FTYPE_V4SI_INT,
20720   V4HI_FTYPE_V4HI_INT,
20721   V8SF_FTYPE_V8SF_INT,
20722   V4SI_FTYPE_V8SI_INT,
20723   V4SF_FTYPE_V8SF_INT,
20724   V2DF_FTYPE_V4DF_INT,
20725   V4DF_FTYPE_V4DF_INT,
20726   V4SF_FTYPE_V4SF_INT,
20727   V2DI_FTYPE_V2DI_INT,
20728   V2DI2TI_FTYPE_V2DI_INT,
20729   V2DF_FTYPE_V2DF_INT,
20730   V16QI_FTYPE_V16QI_V16QI_V16QI,
20731   V8SF_FTYPE_V8SF_V8SF_V8SF,
20732   V4DF_FTYPE_V4DF_V4DF_V4DF,
20733   V4SF_FTYPE_V4SF_V4SF_V4SF,
20734   V2DF_FTYPE_V2DF_V2DF_V2DF,
20735   V16QI_FTYPE_V16QI_V16QI_INT,
20736   V8SI_FTYPE_V8SI_V8SI_INT,
20737   V8SI_FTYPE_V8SI_V4SI_INT,
20738   V8HI_FTYPE_V8HI_V8HI_INT,
20739   V8SF_FTYPE_V8SF_V8SF_INT,
20740   V8SF_FTYPE_V8SF_V4SF_INT,
20741   V4SI_FTYPE_V4SI_V4SI_INT,
20742   V4DF_FTYPE_V4DF_V4DF_INT,
20743   V4DF_FTYPE_V4DF_V2DF_INT,
20744   V4SF_FTYPE_V4SF_V4SF_INT,
20745   V2DI_FTYPE_V2DI_V2DI_INT,
20746   V2DI2TI_FTYPE_V2DI_V2DI_INT,
20747   V1DI2DI_FTYPE_V1DI_V1DI_INT,
20748   V2DF_FTYPE_V2DF_V2DF_INT,
20749   V2DI_FTYPE_V2DI_UINT_UINT,
20750   V2DI_FTYPE_V2DI_V2DI_UINT_UINT
20751 };
20752
20753 /* Special builtins with variable number of arguments.  */
20754 static const struct builtin_description bdesc_special_args[] =
20755 {
20756   /* MMX */
20757   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_emms, "__builtin_ia32_emms", IX86_BUILTIN_EMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
20758
20759   /* 3DNow! */
20760   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_femms, "__builtin_ia32_femms", IX86_BUILTIN_FEMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
20761
20762   /* SSE */
20763   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movups, "__builtin_ia32_storeups", IX86_BUILTIN_STOREUPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
20764   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movntv4sf, "__builtin_ia32_movntps", IX86_BUILTIN_MOVNTPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
20765   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movups, "__builtin_ia32_loadups", IX86_BUILTIN_LOADUPS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
20766
20767   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadhps_exp, "__builtin_ia32_loadhps", IX86_BUILTIN_LOADHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
20768   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadlps_exp, "__builtin_ia32_loadlps", IX86_BUILTIN_LOADLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
20769   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storehps, "__builtin_ia32_storehps", IX86_BUILTIN_STOREHPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
20770   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storelps, "__builtin_ia32_storelps", IX86_BUILTIN_STORELPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
20771
20772   /* SSE or 3DNow!A  */
20773   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_sse_sfence, "__builtin_ia32_sfence", IX86_BUILTIN_SFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
20774   { 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 },
20775
20776   /* SSE2 */
20777   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lfence, "__builtin_ia32_lfence", IX86_BUILTIN_LFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
20778   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_mfence, 0, IX86_BUILTIN_MFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
20779   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movupd, "__builtin_ia32_storeupd", IX86_BUILTIN_STOREUPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
20780   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movdqu, "__builtin_ia32_storedqu", IX86_BUILTIN_STOREDQU, UNKNOWN, (int) VOID_FTYPE_PCHAR_V16QI },
20781   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2df, "__builtin_ia32_movntpd", IX86_BUILTIN_MOVNTPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
20782   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2di, "__builtin_ia32_movntdq", IX86_BUILTIN_MOVNTDQ, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI },
20783   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntsi, "__builtin_ia32_movnti", IX86_BUILTIN_MOVNTI, UNKNOWN, (int) VOID_FTYPE_PINT_INT },
20784   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movupd, "__builtin_ia32_loadupd", IX86_BUILTIN_LOADUPD, UNKNOWN, (int) V2DF_FTYPE_PCDOUBLE },
20785   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movdqu, "__builtin_ia32_loaddqu", IX86_BUILTIN_LOADDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
20786
20787   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadhpd_exp, "__builtin_ia32_loadhpd", IX86_BUILTIN_LOADHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
20788   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadlpd_exp, "__builtin_ia32_loadlpd", IX86_BUILTIN_LOADLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
20789
20790   /* SSE3 */
20791   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_lddqu, "__builtin_ia32_lddqu", IX86_BUILTIN_LDDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
20792
20793   /* SSE4.1 */
20794   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_movntdqa, "__builtin_ia32_movntdqa", IX86_BUILTIN_MOVNTDQA, UNKNOWN, (int) V2DI_FTYPE_PV2DI },
20795
20796   /* SSE4A */
20797   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv2df, "__builtin_ia32_movntsd", IX86_BUILTIN_MOVNTSD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
20798   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv4sf, "__builtin_ia32_movntss", IX86_BUILTIN_MOVNTSS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
20799
20800   /* AVX */
20801   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vzeroall, "__builtin_ia32_vzeroall", IX86_BUILTIN_VZEROALL, UNKNOWN, (int) VOID_FTYPE_VOID },
20802   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vzeroupper, 0, IX86_BUILTIN_VZEROUPPER, UNKNOWN, (int) VOID_FTYPE_VOID },
20803   { OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_64BIT, CODE_FOR_avx_vzeroupper_rex64, 0, IX86_BUILTIN_VZEROUPPER_REX64, UNKNOWN, (int) VOID_FTYPE_VOID },
20804
20805   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastss, "__builtin_ia32_vbroadcastss", IX86_BUILTIN_VBROADCASTSS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
20806   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastsd256, "__builtin_ia32_vbroadcastsd256", IX86_BUILTIN_VBROADCASTSD256, UNKNOWN, (int) V4DF_FTYPE_PCDOUBLE },
20807   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastss256, "__builtin_ia32_vbroadcastss256", IX86_BUILTIN_VBROADCASTSS256, UNKNOWN, (int) V8SF_FTYPE_PCFLOAT },
20808   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastf128_pd256, "__builtin_ia32_vbroadcastf128_pd256", IX86_BUILTIN_VBROADCASTPD256, UNKNOWN, (int) V4DF_FTYPE_PCV2DF },
20809   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastf128_ps256, "__builtin_ia32_vbroadcastf128_ps256", IX86_BUILTIN_VBROADCASTPS256, UNKNOWN, (int) V8SF_FTYPE_PCV4SF },
20810
20811   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movupd256, "__builtin_ia32_loadupd256", IX86_BUILTIN_LOADUPD256, UNKNOWN, (int) V4DF_FTYPE_PCDOUBLE },
20812   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movups256, "__builtin_ia32_loadups256", IX86_BUILTIN_LOADUPS256, UNKNOWN, (int) V8SF_FTYPE_PCFLOAT },
20813   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movupd256, "__builtin_ia32_storeupd256", IX86_BUILTIN_STOREUPD256, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V4DF },
20814   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movups256, "__builtin_ia32_storeups256", IX86_BUILTIN_STOREUPS256, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V8SF },
20815   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movdqu256, "__builtin_ia32_loaddqu256", IX86_BUILTIN_LOADDQU256, UNKNOWN, (int) V32QI_FTYPE_PCCHAR },
20816   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movdqu256, "__builtin_ia32_storedqu256", IX86_BUILTIN_STOREDQU256, UNKNOWN, (int) VOID_FTYPE_PCHAR_V32QI },
20817   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_lddqu256, "__builtin_ia32_lddqu256", IX86_BUILTIN_LDDQU256, UNKNOWN, (int) V32QI_FTYPE_PCCHAR },
20818
20819   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv4di, "__builtin_ia32_movntdq256", IX86_BUILTIN_MOVNTDQ256, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI },
20820   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv4df, "__builtin_ia32_movntpd256", IX86_BUILTIN_MOVNTPD256, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V4DF },
20821   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv8sf, "__builtin_ia32_movntps256", IX86_BUILTIN_MOVNTPS256, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V8SF },
20822
20823   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadpd, "__builtin_ia32_maskloadpd", IX86_BUILTIN_MASKLOADPD, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DF },
20824   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadps, "__builtin_ia32_maskloadps", IX86_BUILTIN_MASKLOADPS, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SF },
20825   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadpd256, "__builtin_ia32_maskloadpd256", IX86_BUILTIN_MASKLOADPD256, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DF },
20826   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadps256, "__builtin_ia32_maskloadps256", IX86_BUILTIN_MASKLOADPS256, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SF },
20827   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstorepd, "__builtin_ia32_maskstorepd", IX86_BUILTIN_MASKSTOREPD, UNKNOWN, (int) VOID_FTYPE_PV2DF_V2DF_V2DF },
20828   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstoreps, "__builtin_ia32_maskstoreps", IX86_BUILTIN_MASKSTOREPS, UNKNOWN, (int) VOID_FTYPE_PV4SF_V4SF_V4SF },
20829   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstorepd256, "__builtin_ia32_maskstorepd256", IX86_BUILTIN_MASKSTOREPD256, UNKNOWN, (int) VOID_FTYPE_PV4DF_V4DF_V4DF },
20830   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstoreps256, "__builtin_ia32_maskstoreps256", IX86_BUILTIN_MASKSTOREPS256, UNKNOWN, (int) VOID_FTYPE_PV8SF_V8SF_V8SF },
20831 };
20832
20833 /* Builtins with variable number of arguments.  */
20834 static const struct builtin_description bdesc_args[] =
20835 {
20836   /* MMX */
20837   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv8qi3, "__builtin_ia32_paddb", IX86_BUILTIN_PADDB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20838   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv4hi3, "__builtin_ia32_paddw", IX86_BUILTIN_PADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20839   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv2si3, "__builtin_ia32_paddd", IX86_BUILTIN_PADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20840   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv8qi3, "__builtin_ia32_psubb", IX86_BUILTIN_PSUBB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20841   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv4hi3, "__builtin_ia32_psubw", IX86_BUILTIN_PSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20842   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv2si3, "__builtin_ia32_psubd", IX86_BUILTIN_PSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20843
20844   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv8qi3, "__builtin_ia32_paddsb", IX86_BUILTIN_PADDSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20845   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv4hi3, "__builtin_ia32_paddsw", IX86_BUILTIN_PADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20846   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv8qi3, "__builtin_ia32_psubsb", IX86_BUILTIN_PSUBSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20847   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv4hi3, "__builtin_ia32_psubsw", IX86_BUILTIN_PSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20848   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv8qi3, "__builtin_ia32_paddusb", IX86_BUILTIN_PADDUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20849   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv4hi3, "__builtin_ia32_paddusw", IX86_BUILTIN_PADDUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20850   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv8qi3, "__builtin_ia32_psubusb", IX86_BUILTIN_PSUBUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20851   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv4hi3, "__builtin_ia32_psubusw", IX86_BUILTIN_PSUBUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20852
20853   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_mulv4hi3, "__builtin_ia32_pmullw", IX86_BUILTIN_PMULLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20854   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_smulv4hi3_highpart, "__builtin_ia32_pmulhw", IX86_BUILTIN_PMULHW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20855
20856   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_andv2si3, "__builtin_ia32_pand", IX86_BUILTIN_PAND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20857   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_andnotv2si3, "__builtin_ia32_pandn", IX86_BUILTIN_PANDN, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20858   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_iorv2si3, "__builtin_ia32_por", IX86_BUILTIN_POR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20859   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_xorv2si3, "__builtin_ia32_pxor", IX86_BUILTIN_PXOR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20860
20861   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv8qi3, "__builtin_ia32_pcmpeqb", IX86_BUILTIN_PCMPEQB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20862   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv4hi3, "__builtin_ia32_pcmpeqw", IX86_BUILTIN_PCMPEQW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20863   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv2si3, "__builtin_ia32_pcmpeqd", IX86_BUILTIN_PCMPEQD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20864   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv8qi3, "__builtin_ia32_pcmpgtb", IX86_BUILTIN_PCMPGTB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20865   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv4hi3, "__builtin_ia32_pcmpgtw", IX86_BUILTIN_PCMPGTW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20866   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv2si3, "__builtin_ia32_pcmpgtd", IX86_BUILTIN_PCMPGTD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20867
20868   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhbw, "__builtin_ia32_punpckhbw", IX86_BUILTIN_PUNPCKHBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20869   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhwd, "__builtin_ia32_punpckhwd", IX86_BUILTIN_PUNPCKHWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20870   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhdq, "__builtin_ia32_punpckhdq", IX86_BUILTIN_PUNPCKHDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
20871   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklbw, "__builtin_ia32_punpcklbw", IX86_BUILTIN_PUNPCKLBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20872   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklwd, "__builtin_ia32_punpcklwd", IX86_BUILTIN_PUNPCKLWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI},
20873   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckldq, "__builtin_ia32_punpckldq", IX86_BUILTIN_PUNPCKLDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI},
20874
20875   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packsswb, "__builtin_ia32_packsswb", IX86_BUILTIN_PACKSSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
20876   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packssdw, "__builtin_ia32_packssdw", IX86_BUILTIN_PACKSSDW, UNKNOWN, (int) V4HI_FTYPE_V2SI_V2SI },
20877   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packuswb, "__builtin_ia32_packuswb", IX86_BUILTIN_PACKUSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
20878
20879   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_pmaddwd, "__builtin_ia32_pmaddwd", IX86_BUILTIN_PMADDWD, UNKNOWN, (int) V2SI_FTYPE_V4HI_V4HI },
20880
20881   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllwi", IX86_BUILTIN_PSLLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
20882   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslldi", IX86_BUILTIN_PSLLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
20883   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllqi", IX86_BUILTIN_PSLLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
20884   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllw", IX86_BUILTIN_PSLLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
20885   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslld", IX86_BUILTIN_PSLLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
20886   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllq", IX86_BUILTIN_PSLLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
20887
20888   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlwi", IX86_BUILTIN_PSRLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
20889   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrldi", IX86_BUILTIN_PSRLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
20890   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlqi", IX86_BUILTIN_PSRLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
20891   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlw", IX86_BUILTIN_PSRLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
20892   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrld", IX86_BUILTIN_PSRLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
20893   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlq", IX86_BUILTIN_PSRLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
20894
20895   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psrawi", IX86_BUILTIN_PSRAWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
20896   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psradi", IX86_BUILTIN_PSRADI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
20897   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psraw", IX86_BUILTIN_PSRAW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
20898   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psrad", IX86_BUILTIN_PSRAD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
20899
20900   /* 3DNow! */
20901   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pf2id, "__builtin_ia32_pf2id", IX86_BUILTIN_PF2ID, UNKNOWN, (int) V2SI_FTYPE_V2SF },
20902   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_floatv2si2, "__builtin_ia32_pi2fd", IX86_BUILTIN_PI2FD, UNKNOWN, (int) V2SF_FTYPE_V2SI },
20903   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpv2sf2, "__builtin_ia32_pfrcp", IX86_BUILTIN_PFRCP, UNKNOWN, (int) V2SF_FTYPE_V2SF },
20904   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqrtv2sf2, "__builtin_ia32_pfrsqrt", IX86_BUILTIN_PFRSQRT, UNKNOWN, (int) V2SF_FTYPE_V2SF },
20905
20906   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_uavgv8qi3, "__builtin_ia32_pavgusb", IX86_BUILTIN_PAVGUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
20907   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_haddv2sf3, "__builtin_ia32_pfacc", IX86_BUILTIN_PFACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20908   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_addv2sf3, "__builtin_ia32_pfadd", IX86_BUILTIN_PFADD, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20909   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_eqv2sf3, "__builtin_ia32_pfcmpeq", IX86_BUILTIN_PFCMPEQ, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
20910   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gev2sf3, "__builtin_ia32_pfcmpge", IX86_BUILTIN_PFCMPGE, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
20911   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gtv2sf3, "__builtin_ia32_pfcmpgt", IX86_BUILTIN_PFCMPGT, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
20912   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_smaxv2sf3, "__builtin_ia32_pfmax", IX86_BUILTIN_PFMAX, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20913   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_sminv2sf3, "__builtin_ia32_pfmin", IX86_BUILTIN_PFMIN, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20914   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_mulv2sf3, "__builtin_ia32_pfmul", IX86_BUILTIN_PFMUL, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20915   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit1v2sf3, "__builtin_ia32_pfrcpit1", IX86_BUILTIN_PFRCPIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20916   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit2v2sf3, "__builtin_ia32_pfrcpit2", IX86_BUILTIN_PFRCPIT2, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20917   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqit1v2sf3, "__builtin_ia32_pfrsqit1", IX86_BUILTIN_PFRSQIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20918   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subv2sf3, "__builtin_ia32_pfsub", IX86_BUILTIN_PFSUB, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20919   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subrv2sf3, "__builtin_ia32_pfsubr", IX86_BUILTIN_PFSUBR, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20920   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pmulhrwv4hi3, "__builtin_ia32_pmulhrw", IX86_BUILTIN_PMULHRW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
20921
20922   /* 3DNow!A */
20923   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pf2iw, "__builtin_ia32_pf2iw", IX86_BUILTIN_PF2IW, UNKNOWN, (int) V2SI_FTYPE_V2SF },
20924   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pi2fw, "__builtin_ia32_pi2fw", IX86_BUILTIN_PI2FW, UNKNOWN, (int) V2SF_FTYPE_V2SI },
20925   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2si2, "__builtin_ia32_pswapdsi", IX86_BUILTIN_PSWAPDSI, UNKNOWN, (int) V2SI_FTYPE_V2SI },
20926   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2sf2, "__builtin_ia32_pswapdsf", IX86_BUILTIN_PSWAPDSF, UNKNOWN, (int) V2SF_FTYPE_V2SF },
20927   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_hsubv2sf3, "__builtin_ia32_pfnacc", IX86_BUILTIN_PFNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20928   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_addsubv2sf3, "__builtin_ia32_pfpnacc", IX86_BUILTIN_PFPNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
20929
20930   /* SSE */
20931   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movmskps, "__builtin_ia32_movmskps", IX86_BUILTIN_MOVMSKPS, UNKNOWN, (int) INT_FTYPE_V4SF },
20932   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_sqrtv4sf2, "__builtin_ia32_sqrtps", IX86_BUILTIN_SQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20933   { OPTION_MASK_ISA_SSE, CODE_FOR_sqrtv4sf2, "__builtin_ia32_sqrtps_nr", IX86_BUILTIN_SQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20934   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rsqrtv4sf2, "__builtin_ia32_rsqrtps", IX86_BUILTIN_RSQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20935   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtv4sf2, "__builtin_ia32_rsqrtps_nr", IX86_BUILTIN_RSQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20936   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rcpv4sf2, "__builtin_ia32_rcpps", IX86_BUILTIN_RCPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
20937   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtps2pi, "__builtin_ia32_cvtps2pi", IX86_BUILTIN_CVTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
20938   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtss2si, "__builtin_ia32_cvtss2si", IX86_BUILTIN_CVTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
20939   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtss2siq, "__builtin_ia32_cvtss2si64", IX86_BUILTIN_CVTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
20940   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttps2pi, "__builtin_ia32_cvttps2pi", IX86_BUILTIN_CVTTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
20941   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttss2si, "__builtin_ia32_cvttss2si", IX86_BUILTIN_CVTTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
20942   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvttss2siq, "__builtin_ia32_cvttss2si64", IX86_BUILTIN_CVTTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
20943
20944   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_shufps, "__builtin_ia32_shufps", IX86_BUILTIN_SHUFPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
20945
20946   { OPTION_MASK_ISA_SSE, CODE_FOR_addv4sf3, "__builtin_ia32_addps", IX86_BUILTIN_ADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20947   { OPTION_MASK_ISA_SSE, CODE_FOR_subv4sf3, "__builtin_ia32_subps", IX86_BUILTIN_SUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20948   { OPTION_MASK_ISA_SSE, CODE_FOR_mulv4sf3, "__builtin_ia32_mulps", IX86_BUILTIN_MULPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20949   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_divv4sf3, "__builtin_ia32_divps", IX86_BUILTIN_DIVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20950   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmaddv4sf3,  "__builtin_ia32_addss", IX86_BUILTIN_ADDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20951   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsubv4sf3,  "__builtin_ia32_subss", IX86_BUILTIN_SUBSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20952   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmulv4sf3,  "__builtin_ia32_mulss", IX86_BUILTIN_MULSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20953   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmdivv4sf3,  "__builtin_ia32_divss", IX86_BUILTIN_DIVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20954
20955   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpeqps", IX86_BUILTIN_CMPEQPS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
20956   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpltps", IX86_BUILTIN_CMPLTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
20957   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpleps", IX86_BUILTIN_CMPLEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
20958   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgtps", IX86_BUILTIN_CMPGTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20959   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgeps", IX86_BUILTIN_CMPGEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20960   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpunordps", IX86_BUILTIN_CMPUNORDPS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
20961   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpneqps", IX86_BUILTIN_CMPNEQPS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
20962   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnltps", IX86_BUILTIN_CMPNLTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
20963   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnleps", IX86_BUILTIN_CMPNLEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
20964   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngtps", IX86_BUILTIN_CMPNGTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20965   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngeps", IX86_BUILTIN_CMPNGEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP},
20966   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpordps", IX86_BUILTIN_CMPORDPS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
20967   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpeqss", IX86_BUILTIN_CMPEQSS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
20968   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpltss", IX86_BUILTIN_CMPLTSS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
20969   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpless", IX86_BUILTIN_CMPLESS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
20970   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpunordss", IX86_BUILTIN_CMPUNORDSS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
20971   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpneqss", IX86_BUILTIN_CMPNEQSS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
20972   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnltss", IX86_BUILTIN_CMPNLTSS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
20973   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnless", IX86_BUILTIN_CMPNLESS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
20974   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpngtss", IX86_BUILTIN_CMPNGTSS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20975   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpngess", IX86_BUILTIN_CMPNGESS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
20976   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpordss", IX86_BUILTIN_CMPORDSS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
20977
20978   { OPTION_MASK_ISA_SSE, CODE_FOR_sminv4sf3, "__builtin_ia32_minps", IX86_BUILTIN_MINPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20979   { OPTION_MASK_ISA_SSE, CODE_FOR_smaxv4sf3, "__builtin_ia32_maxps", IX86_BUILTIN_MAXPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20980   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsminv4sf3, "__builtin_ia32_minss", IX86_BUILTIN_MINSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20981   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsmaxv4sf3, "__builtin_ia32_maxss", IX86_BUILTIN_MAXSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20982
20983   { OPTION_MASK_ISA_SSE, CODE_FOR_andv4sf3, "__builtin_ia32_andps", IX86_BUILTIN_ANDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20984   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_andnotv4sf3,  "__builtin_ia32_andnps", IX86_BUILTIN_ANDNPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20985   { OPTION_MASK_ISA_SSE, CODE_FOR_iorv4sf3, "__builtin_ia32_orps", IX86_BUILTIN_ORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20986   { OPTION_MASK_ISA_SSE, CODE_FOR_xorv4sf3,  "__builtin_ia32_xorps", IX86_BUILTIN_XORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20987
20988   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movss,  "__builtin_ia32_movss", IX86_BUILTIN_MOVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20989   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movhlps_exp,  "__builtin_ia32_movhlps", IX86_BUILTIN_MOVHLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20990   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movlhps_exp,  "__builtin_ia32_movlhps", IX86_BUILTIN_MOVLHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20991   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_unpckhps, "__builtin_ia32_unpckhps", IX86_BUILTIN_UNPCKHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20992   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_unpcklps, "__builtin_ia32_unpcklps", IX86_BUILTIN_UNPCKLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
20993
20994   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtpi2ps, "__builtin_ia32_cvtpi2ps", IX86_BUILTIN_CVTPI2PS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2SI },
20995   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtsi2ss, "__builtin_ia32_cvtsi2ss", IX86_BUILTIN_CVTSI2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_SI },
20996   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtsi2ssq, "__builtin_ia32_cvtsi642ss", IX86_BUILTIN_CVTSI642SS, UNKNOWN, V4SF_FTYPE_V4SF_DI },
20997
20998   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtsf2, "__builtin_ia32_rsqrtf", IX86_BUILTIN_RSQRTF, UNKNOWN, (int) FLOAT_FTYPE_FLOAT },
20999
21000   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsqrtv4sf2, "__builtin_ia32_sqrtss", IX86_BUILTIN_SQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
21001   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrsqrtv4sf2, "__builtin_ia32_rsqrtss", IX86_BUILTIN_RSQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
21002   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrcpv4sf2, "__builtin_ia32_rcpss", IX86_BUILTIN_RCPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
21003
21004   /* SSE MMX or 3Dnow!A */
21005   { 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 },
21006   { 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 },
21007   { 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 },
21008
21009   { 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 },
21010   { 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 },
21011   { 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 },
21012   { 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 },
21013
21014   { 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 },
21015   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pmovmskb, "__builtin_ia32_pmovmskb", IX86_BUILTIN_PMOVMSKB, UNKNOWN, (int) INT_FTYPE_V8QI },
21016
21017   { 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 },
21018
21019   /* SSE2 */
21020   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_shufpd, "__builtin_ia32_shufpd", IX86_BUILTIN_SHUFPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21021
21022   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movmskpd, "__builtin_ia32_movmskpd", IX86_BUILTIN_MOVMSKPD, UNKNOWN, (int) INT_FTYPE_V2DF  },
21023   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmovmskb, "__builtin_ia32_pmovmskb128", IX86_BUILTIN_PMOVMSKB128, UNKNOWN, (int) INT_FTYPE_V16QI },
21024   { OPTION_MASK_ISA_SSE2, CODE_FOR_sqrtv2df2, "__builtin_ia32_sqrtpd", IX86_BUILTIN_SQRTPD, UNKNOWN, (int) V2DF_FTYPE_V2DF },
21025   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2pd, "__builtin_ia32_cvtdq2pd", IX86_BUILTIN_CVTDQ2PD, UNKNOWN, (int) V2DF_FTYPE_V4SI },
21026   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2ps, "__builtin_ia32_cvtdq2ps", IX86_BUILTIN_CVTDQ2PS, UNKNOWN, (int) V4SF_FTYPE_V4SI },
21027
21028   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2dq, "__builtin_ia32_cvtpd2dq", IX86_BUILTIN_CVTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
21029   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2pi, "__builtin_ia32_cvtpd2pi", IX86_BUILTIN_CVTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
21030   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2ps, "__builtin_ia32_cvtpd2ps", IX86_BUILTIN_CVTPD2PS, UNKNOWN, (int) V4SF_FTYPE_V2DF },
21031   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2dq, "__builtin_ia32_cvttpd2dq", IX86_BUILTIN_CVTTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
21032   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2pi, "__builtin_ia32_cvttpd2pi", IX86_BUILTIN_CVTTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
21033
21034   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpi2pd, "__builtin_ia32_cvtpi2pd", IX86_BUILTIN_CVTPI2PD, UNKNOWN, (int) V2DF_FTYPE_V2SI },
21035
21036   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2si, "__builtin_ia32_cvtsd2si", IX86_BUILTIN_CVTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
21037   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttsd2si, "__builtin_ia32_cvttsd2si", IX86_BUILTIN_CVTTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
21038   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsd2siq, "__builtin_ia32_cvtsd2si64", IX86_BUILTIN_CVTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
21039   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvttsd2siq, "__builtin_ia32_cvttsd2si64", IX86_BUILTIN_CVTTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
21040
21041   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2dq, "__builtin_ia32_cvtps2dq", IX86_BUILTIN_CVTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
21042   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2pd, "__builtin_ia32_cvtps2pd", IX86_BUILTIN_CVTPS2PD, UNKNOWN, (int) V2DF_FTYPE_V4SF },
21043   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttps2dq, "__builtin_ia32_cvttps2dq", IX86_BUILTIN_CVTTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
21044
21045   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2df3, "__builtin_ia32_addpd", IX86_BUILTIN_ADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21046   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2df3, "__builtin_ia32_subpd", IX86_BUILTIN_SUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21047   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv2df3, "__builtin_ia32_mulpd", IX86_BUILTIN_MULPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21048   { OPTION_MASK_ISA_SSE2, CODE_FOR_divv2df3, "__builtin_ia32_divpd", IX86_BUILTIN_DIVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21049   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmaddv2df3,  "__builtin_ia32_addsd", IX86_BUILTIN_ADDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21050   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsubv2df3,  "__builtin_ia32_subsd", IX86_BUILTIN_SUBSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21051   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmulv2df3,  "__builtin_ia32_mulsd", IX86_BUILTIN_MULSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21052   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmdivv2df3,  "__builtin_ia32_divsd", IX86_BUILTIN_DIVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21053
21054   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpeqpd", IX86_BUILTIN_CMPEQPD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
21055   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpltpd", IX86_BUILTIN_CMPLTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
21056   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmplepd", IX86_BUILTIN_CMPLEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
21057   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgtpd", IX86_BUILTIN_CMPGTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
21058   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgepd", IX86_BUILTIN_CMPGEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP},
21059   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpunordpd", IX86_BUILTIN_CMPUNORDPD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
21060   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpneqpd", IX86_BUILTIN_CMPNEQPD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
21061   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnltpd", IX86_BUILTIN_CMPNLTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
21062   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnlepd", IX86_BUILTIN_CMPNLEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
21063   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngtpd", IX86_BUILTIN_CMPNGTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
21064   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngepd", IX86_BUILTIN_CMPNGEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
21065   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpordpd", IX86_BUILTIN_CMPORDPD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
21066   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpeqsd", IX86_BUILTIN_CMPEQSD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
21067   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpltsd", IX86_BUILTIN_CMPLTSD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
21068   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmplesd", IX86_BUILTIN_CMPLESD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
21069   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpunordsd", IX86_BUILTIN_CMPUNORDSD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
21070   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpneqsd", IX86_BUILTIN_CMPNEQSD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
21071   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnltsd", IX86_BUILTIN_CMPNLTSD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
21072   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnlesd", IX86_BUILTIN_CMPNLESD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
21073   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpordsd", IX86_BUILTIN_CMPORDSD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
21074
21075   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv2df3, "__builtin_ia32_minpd", IX86_BUILTIN_MINPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21076   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv2df3, "__builtin_ia32_maxpd", IX86_BUILTIN_MAXPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21077   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsminv2df3, "__builtin_ia32_minsd", IX86_BUILTIN_MINSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21078   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsmaxv2df3, "__builtin_ia32_maxsd", IX86_BUILTIN_MAXSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21079
21080   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2df3, "__builtin_ia32_andpd", IX86_BUILTIN_ANDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21081   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_andnotv2df3,  "__builtin_ia32_andnpd", IX86_BUILTIN_ANDNPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21082   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2df3, "__builtin_ia32_orpd", IX86_BUILTIN_ORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21083   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2df3,  "__builtin_ia32_xorpd", IX86_BUILTIN_XORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21084
21085   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movsd,  "__builtin_ia32_movsd", IX86_BUILTIN_MOVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21086   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_unpckhpd_exp, "__builtin_ia32_unpckhpd", IX86_BUILTIN_UNPCKHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21087   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_unpcklpd_exp, "__builtin_ia32_unpcklpd", IX86_BUILTIN_UNPCKLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21088
21089   { 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 },
21090
21091   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv16qi3, "__builtin_ia32_paddb128", IX86_BUILTIN_PADDB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21092   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv8hi3, "__builtin_ia32_paddw128", IX86_BUILTIN_PADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21093   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv4si3, "__builtin_ia32_paddd128", IX86_BUILTIN_PADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21094   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2di3, "__builtin_ia32_paddq128", IX86_BUILTIN_PADDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21095   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv16qi3, "__builtin_ia32_psubb128", IX86_BUILTIN_PSUBB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21096   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv8hi3, "__builtin_ia32_psubw128", IX86_BUILTIN_PSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21097   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv4si3, "__builtin_ia32_psubd128", IX86_BUILTIN_PSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21098   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2di3, "__builtin_ia32_psubq128", IX86_BUILTIN_PSUBQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21099
21100   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv16qi3, "__builtin_ia32_paddsb128", IX86_BUILTIN_PADDSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21101   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv8hi3, "__builtin_ia32_paddsw128", IX86_BUILTIN_PADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21102   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv16qi3, "__builtin_ia32_psubsb128", IX86_BUILTIN_PSUBSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21103   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv8hi3, "__builtin_ia32_psubsw128", IX86_BUILTIN_PSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21104   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv16qi3, "__builtin_ia32_paddusb128", IX86_BUILTIN_PADDUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21105   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv8hi3, "__builtin_ia32_paddusw128", IX86_BUILTIN_PADDUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21106   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv16qi3, "__builtin_ia32_psubusb128", IX86_BUILTIN_PSUBUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21107   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv8hi3, "__builtin_ia32_psubusw128", IX86_BUILTIN_PSUBUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21108
21109   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv8hi3, "__builtin_ia32_pmullw128", IX86_BUILTIN_PMULLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21110   { OPTION_MASK_ISA_SSE2, CODE_FOR_smulv8hi3_highpart, "__builtin_ia32_pmulhw128", IX86_BUILTIN_PMULHW128, UNKNOWN,(int) V8HI_FTYPE_V8HI_V8HI },
21111
21112   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2di3, "__builtin_ia32_pand128", IX86_BUILTIN_PAND128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21113   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_andnotv2di3, "__builtin_ia32_pandn128", IX86_BUILTIN_PANDN128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21114   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2di3, "__builtin_ia32_por128", IX86_BUILTIN_POR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21115   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2di3, "__builtin_ia32_pxor128", IX86_BUILTIN_PXOR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21116
21117   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv16qi3, "__builtin_ia32_pavgb128", IX86_BUILTIN_PAVGB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21118   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv8hi3, "__builtin_ia32_pavgw128", IX86_BUILTIN_PAVGW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21119
21120   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv16qi3, "__builtin_ia32_pcmpeqb128", IX86_BUILTIN_PCMPEQB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21121   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv8hi3, "__builtin_ia32_pcmpeqw128", IX86_BUILTIN_PCMPEQW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21122   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv4si3, "__builtin_ia32_pcmpeqd128", IX86_BUILTIN_PCMPEQD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
21123   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv16qi3, "__builtin_ia32_pcmpgtb128", IX86_BUILTIN_PCMPGTB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21124   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv8hi3, "__builtin_ia32_pcmpgtw128", IX86_BUILTIN_PCMPGTW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21125   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv4si3, "__builtin_ia32_pcmpgtd128", IX86_BUILTIN_PCMPGTD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
21126
21127   { OPTION_MASK_ISA_SSE2, CODE_FOR_umaxv16qi3, "__builtin_ia32_pmaxub128", IX86_BUILTIN_PMAXUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21128   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv8hi3, "__builtin_ia32_pmaxsw128", IX86_BUILTIN_PMAXSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21129   { OPTION_MASK_ISA_SSE2, CODE_FOR_uminv16qi3, "__builtin_ia32_pminub128", IX86_BUILTIN_PMINUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21130   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv8hi3, "__builtin_ia32_pminsw128", IX86_BUILTIN_PMINSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21131
21132   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhbw, "__builtin_ia32_punpckhbw128", IX86_BUILTIN_PUNPCKHBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21133   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhwd, "__builtin_ia32_punpckhwd128", IX86_BUILTIN_PUNPCKHWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI  },
21134   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhdq, "__builtin_ia32_punpckhdq128", IX86_BUILTIN_PUNPCKHDQ128, UNKNOWN,  (int) V4SI_FTYPE_V4SI_V4SI },
21135   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckhqdq, "__builtin_ia32_punpckhqdq128", IX86_BUILTIN_PUNPCKHQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21136   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklbw, "__builtin_ia32_punpcklbw128", IX86_BUILTIN_PUNPCKLBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21137   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklwd, "__builtin_ia32_punpcklwd128", IX86_BUILTIN_PUNPCKLWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21138   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpckldq, "__builtin_ia32_punpckldq128", IX86_BUILTIN_PUNPCKLDQ128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21139   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_punpcklqdq, "__builtin_ia32_punpcklqdq128", IX86_BUILTIN_PUNPCKLQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21140
21141   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packsswb, "__builtin_ia32_packsswb128", IX86_BUILTIN_PACKSSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
21142   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packssdw, "__builtin_ia32_packssdw128", IX86_BUILTIN_PACKSSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
21143   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packuswb, "__builtin_ia32_packuswb128", IX86_BUILTIN_PACKUSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
21144
21145   { OPTION_MASK_ISA_SSE2, CODE_FOR_umulv8hi3_highpart, "__builtin_ia32_pmulhuw128", IX86_BUILTIN_PMULHUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21146   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_psadbw, "__builtin_ia32_psadbw128", IX86_BUILTIN_PSADBW128, UNKNOWN, (int) V2DI_FTYPE_V16QI_V16QI },
21147
21148   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulv1siv1di3, "__builtin_ia32_pmuludq", IX86_BUILTIN_PMULUDQ, UNKNOWN, (int) V1DI_FTYPE_V2SI_V2SI },
21149   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulv2siv2di3, "__builtin_ia32_pmuludq128", IX86_BUILTIN_PMULUDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
21150
21151   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmaddwd, "__builtin_ia32_pmaddwd128", IX86_BUILTIN_PMADDWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI_V8HI },
21152
21153   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsi2sd, "__builtin_ia32_cvtsi2sd", IX86_BUILTIN_CVTSI2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_SI },
21154   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsi2sdq, "__builtin_ia32_cvtsi642sd", IX86_BUILTIN_CVTSI642SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_DI },
21155   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2ss, "__builtin_ia32_cvtsd2ss", IX86_BUILTIN_CVTSD2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2DF },
21156   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtss2sd, "__builtin_ia32_cvtss2sd", IX86_BUILTIN_CVTSS2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V4SF },
21157
21158   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ashlti3, "__builtin_ia32_pslldqi128", IX86_BUILTIN_PSLLDQI128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_INT },
21159   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllwi128", IX86_BUILTIN_PSLLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
21160   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslldi128", IX86_BUILTIN_PSLLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
21161   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllqi128", IX86_BUILTIN_PSLLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
21162   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllw128", IX86_BUILTIN_PSLLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
21163   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslld128", IX86_BUILTIN_PSLLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
21164   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllq128", IX86_BUILTIN_PSLLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
21165
21166   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lshrti3, "__builtin_ia32_psrldqi128", IX86_BUILTIN_PSRLDQI128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_INT },
21167   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlwi128", IX86_BUILTIN_PSRLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
21168   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrldi128", IX86_BUILTIN_PSRLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
21169   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlqi128", IX86_BUILTIN_PSRLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
21170   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlw128", IX86_BUILTIN_PSRLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
21171   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrld128", IX86_BUILTIN_PSRLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
21172   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlq128", IX86_BUILTIN_PSRLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
21173
21174   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psrawi128", IX86_BUILTIN_PSRAWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
21175   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psradi128", IX86_BUILTIN_PSRADI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
21176   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psraw128", IX86_BUILTIN_PSRAW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
21177   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psrad128", IX86_BUILTIN_PSRAD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
21178
21179   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufd, "__builtin_ia32_pshufd", IX86_BUILTIN_PSHUFD, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT },
21180   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshuflw, "__builtin_ia32_pshuflw", IX86_BUILTIN_PSHUFLW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
21181   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufhw, "__builtin_ia32_pshufhw", IX86_BUILTIN_PSHUFHW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
21182
21183   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsqrtv2df2, "__builtin_ia32_sqrtsd", IX86_BUILTIN_SQRTSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_VEC_MERGE },
21184
21185   { OPTION_MASK_ISA_SSE2, CODE_FOR_abstf2, 0, IX86_BUILTIN_FABSQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128 },
21186   { OPTION_MASK_ISA_SSE2, CODE_FOR_copysigntf3, 0, IX86_BUILTIN_COPYSIGNQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128_FLOAT128 },
21187
21188   { OPTION_MASK_ISA_SSE, CODE_FOR_sse2_movq128, "__builtin_ia32_movq128", IX86_BUILTIN_MOVQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
21189
21190   /* SSE2 MMX */
21191   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_addv1di3, "__builtin_ia32_paddq", IX86_BUILTIN_PADDQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
21192   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_subv1di3, "__builtin_ia32_psubq", IX86_BUILTIN_PSUBQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
21193
21194   /* SSE3 */
21195   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movshdup, "__builtin_ia32_movshdup", IX86_BUILTIN_MOVSHDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF},
21196   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movsldup, "__builtin_ia32_movsldup", IX86_BUILTIN_MOVSLDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF },
21197
21198   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv4sf3, "__builtin_ia32_addsubps", IX86_BUILTIN_ADDSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21199   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv2df3, "__builtin_ia32_addsubpd", IX86_BUILTIN_ADDSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21200   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv4sf3, "__builtin_ia32_haddps", IX86_BUILTIN_HADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21201   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv2df3, "__builtin_ia32_haddpd", IX86_BUILTIN_HADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21202   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv4sf3, "__builtin_ia32_hsubps", IX86_BUILTIN_HSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
21203   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv2df3, "__builtin_ia32_hsubpd", IX86_BUILTIN_HSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
21204
21205   /* SSSE3 */
21206   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv16qi2, "__builtin_ia32_pabsb128", IX86_BUILTIN_PABSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI },
21207   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8qi2, "__builtin_ia32_pabsb", IX86_BUILTIN_PABSB, UNKNOWN, (int) V8QI_FTYPE_V8QI },
21208   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8hi2, "__builtin_ia32_pabsw128", IX86_BUILTIN_PABSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
21209   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4hi2, "__builtin_ia32_pabsw", IX86_BUILTIN_PABSW, UNKNOWN, (int) V4HI_FTYPE_V4HI },
21210   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4si2, "__builtin_ia32_pabsd128", IX86_BUILTIN_PABSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI },
21211   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv2si2, "__builtin_ia32_pabsd", IX86_BUILTIN_PABSD, UNKNOWN, (int) V2SI_FTYPE_V2SI },
21212
21213   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv8hi3, "__builtin_ia32_phaddw128", IX86_BUILTIN_PHADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21214   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv4hi3, "__builtin_ia32_phaddw", IX86_BUILTIN_PHADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21215   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv4si3, "__builtin_ia32_phaddd128", IX86_BUILTIN_PHADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21216   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv2si3, "__builtin_ia32_phaddd", IX86_BUILTIN_PHADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21217   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv8hi3, "__builtin_ia32_phaddsw128", IX86_BUILTIN_PHADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21218   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv4hi3, "__builtin_ia32_phaddsw", IX86_BUILTIN_PHADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21219   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv8hi3, "__builtin_ia32_phsubw128", IX86_BUILTIN_PHSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21220   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv4hi3, "__builtin_ia32_phsubw", IX86_BUILTIN_PHSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21221   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv4si3, "__builtin_ia32_phsubd128", IX86_BUILTIN_PHSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21222   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv2si3, "__builtin_ia32_phsubd", IX86_BUILTIN_PHSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21223   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv8hi3, "__builtin_ia32_phsubsw128", IX86_BUILTIN_PHSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21224   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv4hi3, "__builtin_ia32_phsubsw", IX86_BUILTIN_PHSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21225   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw128, "__builtin_ia32_pmaddubsw128", IX86_BUILTIN_PMADDUBSW128, UNKNOWN, (int) V8HI_FTYPE_V16QI_V16QI },
21226   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw, "__builtin_ia32_pmaddubsw", IX86_BUILTIN_PMADDUBSW, UNKNOWN, (int) V4HI_FTYPE_V8QI_V8QI },
21227   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv8hi3, "__builtin_ia32_pmulhrsw128", IX86_BUILTIN_PMULHRSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21228   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv4hi3, "__builtin_ia32_pmulhrsw", IX86_BUILTIN_PMULHRSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21229   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv16qi3, "__builtin_ia32_pshufb128", IX86_BUILTIN_PSHUFB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21230   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv8qi3, "__builtin_ia32_pshufb", IX86_BUILTIN_PSHUFB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21231   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv16qi3, "__builtin_ia32_psignb128", IX86_BUILTIN_PSIGNB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21232   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8qi3, "__builtin_ia32_psignb", IX86_BUILTIN_PSIGNB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
21233   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8hi3, "__builtin_ia32_psignw128", IX86_BUILTIN_PSIGNW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21234   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4hi3, "__builtin_ia32_psignw", IX86_BUILTIN_PSIGNW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
21235   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4si3, "__builtin_ia32_psignd128", IX86_BUILTIN_PSIGND128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21236   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv2si3, "__builtin_ia32_psignd", IX86_BUILTIN_PSIGND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
21237
21238   /* SSSE3.  */
21239   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrti, "__builtin_ia32_palignr128", IX86_BUILTIN_PALIGNR128, UNKNOWN, (int) V2DI2TI_FTYPE_V2DI_V2DI_INT },
21240   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrdi, "__builtin_ia32_palignr", IX86_BUILTIN_PALIGNR, UNKNOWN, (int) V1DI2DI_FTYPE_V1DI_V1DI_INT },
21241
21242   /* SSE4.1 */
21243   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendpd, "__builtin_ia32_blendpd", IX86_BUILTIN_BLENDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21244   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendps, "__builtin_ia32_blendps", IX86_BUILTIN_BLENDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21245   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvpd, "__builtin_ia32_blendvpd", IX86_BUILTIN_BLENDVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF },
21246   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvps, "__builtin_ia32_blendvps", IX86_BUILTIN_BLENDVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF },
21247   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dppd, "__builtin_ia32_dppd", IX86_BUILTIN_DPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21248   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dpps, "__builtin_ia32_dpps", IX86_BUILTIN_DPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21249   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_insertps, "__builtin_ia32_insertps128", IX86_BUILTIN_INSERTPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21250   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mpsadbw, "__builtin_ia32_mpsadbw128", IX86_BUILTIN_MPSADBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_INT },
21251   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendvb, "__builtin_ia32_pblendvb128", IX86_BUILTIN_PBLENDVB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI },
21252   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendw, "__builtin_ia32_pblendw128", IX86_BUILTIN_PBLENDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_INT },
21253
21254   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv8qiv8hi2, "__builtin_ia32_pmovsxbw128", IX86_BUILTIN_PMOVSXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
21255   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv4qiv4si2, "__builtin_ia32_pmovsxbd128", IX86_BUILTIN_PMOVSXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
21256   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2qiv2di2, "__builtin_ia32_pmovsxbq128", IX86_BUILTIN_PMOVSXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
21257   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv4hiv4si2, "__builtin_ia32_pmovsxwd128", IX86_BUILTIN_PMOVSXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
21258   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2hiv2di2, "__builtin_ia32_pmovsxwq128", IX86_BUILTIN_PMOVSXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
21259   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_extendv2siv2di2, "__builtin_ia32_pmovsxdq128", IX86_BUILTIN_PMOVSXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
21260   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv8qiv8hi2, "__builtin_ia32_pmovzxbw128", IX86_BUILTIN_PMOVZXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
21261   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4qiv4si2, "__builtin_ia32_pmovzxbd128", IX86_BUILTIN_PMOVZXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
21262   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2qiv2di2, "__builtin_ia32_pmovzxbq128", IX86_BUILTIN_PMOVZXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
21263   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4hiv4si2, "__builtin_ia32_pmovzxwd128", IX86_BUILTIN_PMOVZXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
21264   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2hiv2di2, "__builtin_ia32_pmovzxwq128", IX86_BUILTIN_PMOVZXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
21265   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2siv2di2, "__builtin_ia32_pmovzxdq128", IX86_BUILTIN_PMOVZXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
21266   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_phminposuw, "__builtin_ia32_phminposuw128", IX86_BUILTIN_PHMINPOSUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
21267
21268   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_packusdw, "__builtin_ia32_packusdw128", IX86_BUILTIN_PACKUSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
21269   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_eqv2di3, "__builtin_ia32_pcmpeqq", IX86_BUILTIN_PCMPEQQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21270   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv16qi3, "__builtin_ia32_pmaxsb128", IX86_BUILTIN_PMAXSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21271   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv4si3, "__builtin_ia32_pmaxsd128", IX86_BUILTIN_PMAXSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21272   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv4si3, "__builtin_ia32_pmaxud128", IX86_BUILTIN_PMAXUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21273   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv8hi3, "__builtin_ia32_pmaxuw128", IX86_BUILTIN_PMAXUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21274   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv16qi3, "__builtin_ia32_pminsb128", IX86_BUILTIN_PMINSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
21275   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv4si3, "__builtin_ia32_pminsd128", IX86_BUILTIN_PMINSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21276   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv4si3, "__builtin_ia32_pminud128", IX86_BUILTIN_PMINUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21277   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv8hi3, "__builtin_ia32_pminuw128", IX86_BUILTIN_PMINUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
21278   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mulv2siv2di3, "__builtin_ia32_pmuldq128", IX86_BUILTIN_PMULDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
21279   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_mulv4si3, "__builtin_ia32_pmulld128", IX86_BUILTIN_PMULLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
21280
21281   /* SSE4.1 and SSE5 */
21282   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundpd, "__builtin_ia32_roundpd", IX86_BUILTIN_ROUNDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
21283   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundps, "__builtin_ia32_roundps", IX86_BUILTIN_ROUNDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
21284   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundsd, "__builtin_ia32_roundsd", IX86_BUILTIN_ROUNDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21285   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundss, "__builtin_ia32_roundss", IX86_BUILTIN_ROUNDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21286
21287   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestz128", IX86_BUILTIN_PTESTZ, EQ, (int) INT_FTYPE_V2DI_V2DI_PTEST },
21288   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestc128", IX86_BUILTIN_PTESTC, LTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
21289   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestnzc128", IX86_BUILTIN_PTESTNZC, GTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
21290
21291   /* SSE4.2 */
21292   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_gtv2di3, "__builtin_ia32_pcmpgtq", IX86_BUILTIN_PCMPGTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21293   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32qi, "__builtin_ia32_crc32qi", IX86_BUILTIN_CRC32QI, UNKNOWN, (int) UINT_FTYPE_UINT_UCHAR },
21294   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32hi, "__builtin_ia32_crc32hi", IX86_BUILTIN_CRC32HI, UNKNOWN, (int) UINT_FTYPE_UINT_USHORT },
21295   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_crc32si, "__builtin_ia32_crc32si", IX86_BUILTIN_CRC32SI, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
21296   { 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 },
21297
21298   /* SSE4A */
21299   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrqi, "__builtin_ia32_extrqi", IX86_BUILTIN_EXTRQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_UINT_UINT },
21300   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrq, "__builtin_ia32_extrq", IX86_BUILTIN_EXTRQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V16QI },
21301   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertqi, "__builtin_ia32_insertqi", IX86_BUILTIN_INSERTQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_UINT_UINT },
21302   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertq, "__builtin_ia32_insertq", IX86_BUILTIN_INSERTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21303
21304   /* AES */
21305   { OPTION_MASK_ISA_SSE2, CODE_FOR_aeskeygenassist, 0, IX86_BUILTIN_AESKEYGENASSIST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT },
21306   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesimc, 0, IX86_BUILTIN_AESIMC128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
21307
21308   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenc, 0, IX86_BUILTIN_AESENC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21309   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenclast, 0, IX86_BUILTIN_AESENCLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21310   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdec, 0, IX86_BUILTIN_AESDEC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21311   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdeclast, 0, IX86_BUILTIN_AESDECLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
21312
21313   /* PCLMUL */
21314   { OPTION_MASK_ISA_SSE2, CODE_FOR_pclmulqdq, 0, IX86_BUILTIN_PCLMULQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_INT },
21315
21316   /* AVX */
21317   { OPTION_MASK_ISA_AVX, CODE_FOR_addv4df3, "__builtin_ia32_addpd256", IX86_BUILTIN_ADDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21318   { OPTION_MASK_ISA_AVX, CODE_FOR_addv8sf3, "__builtin_ia32_addps256", IX86_BUILTIN_ADDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21319   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_addsubv4df3, "__builtin_ia32_addsubpd256", IX86_BUILTIN_ADDSUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21320   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_addsubv8sf3, "__builtin_ia32_addsubps256", IX86_BUILTIN_ADDSUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21321   { OPTION_MASK_ISA_AVX, CODE_FOR_andv4df3, "__builtin_ia32_andpd256", IX86_BUILTIN_ANDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21322   { OPTION_MASK_ISA_AVX, CODE_FOR_andv8sf3, "__builtin_ia32_andps256", IX86_BUILTIN_ANDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21323   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_andnotv4df3, "__builtin_ia32_andnpd256", IX86_BUILTIN_ANDNPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21324   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_andnotv8sf3, "__builtin_ia32_andnps256", IX86_BUILTIN_ANDNPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21325   { OPTION_MASK_ISA_AVX, CODE_FOR_divv4df3, "__builtin_ia32_divpd256", IX86_BUILTIN_DIVPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21326   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_divv8sf3, "__builtin_ia32_divps256", IX86_BUILTIN_DIVPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21327   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_haddv4df3, "__builtin_ia32_haddpd256", IX86_BUILTIN_HADDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21328   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_hsubv8sf3, "__builtin_ia32_hsubps256", IX86_BUILTIN_HSUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21329   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_hsubv4df3, "__builtin_ia32_hsubpd256", IX86_BUILTIN_HSUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21330   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_haddv8sf3, "__builtin_ia32_haddps256", IX86_BUILTIN_HADDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21331   { OPTION_MASK_ISA_AVX, CODE_FOR_smaxv4df3, "__builtin_ia32_maxpd256", IX86_BUILTIN_MAXPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21332   { OPTION_MASK_ISA_AVX, CODE_FOR_smaxv8sf3, "__builtin_ia32_maxps256", IX86_BUILTIN_MAXPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21333   { OPTION_MASK_ISA_AVX, CODE_FOR_sminv4df3, "__builtin_ia32_minpd256", IX86_BUILTIN_MINPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21334   { OPTION_MASK_ISA_AVX, CODE_FOR_sminv8sf3, "__builtin_ia32_minps256", IX86_BUILTIN_MINPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21335   { OPTION_MASK_ISA_AVX, CODE_FOR_mulv4df3, "__builtin_ia32_mulpd256", IX86_BUILTIN_MULPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21336   { OPTION_MASK_ISA_AVX, CODE_FOR_mulv8sf3, "__builtin_ia32_mulps256", IX86_BUILTIN_MULPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21337   { OPTION_MASK_ISA_AVX, CODE_FOR_iorv4df3, "__builtin_ia32_orpd256", IX86_BUILTIN_ORPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21338   { OPTION_MASK_ISA_AVX, CODE_FOR_iorv8sf3, "__builtin_ia32_orps256", IX86_BUILTIN_ORPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21339   { OPTION_MASK_ISA_AVX, CODE_FOR_subv4df3, "__builtin_ia32_subpd256", IX86_BUILTIN_SUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21340   { OPTION_MASK_ISA_AVX, CODE_FOR_subv8sf3, "__builtin_ia32_subps256", IX86_BUILTIN_SUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21341   { OPTION_MASK_ISA_AVX, CODE_FOR_xorv4df3, "__builtin_ia32_xorpd256", IX86_BUILTIN_XORPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21342   { OPTION_MASK_ISA_AVX, CODE_FOR_xorv8sf3, "__builtin_ia32_xorps256", IX86_BUILTIN_XORPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21343
21344   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv2df3, "__builtin_ia32_vpermilvarpd", IX86_BUILTIN_VPERMILVARPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DI },
21345   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv4sf3, "__builtin_ia32_vpermilvarps", IX86_BUILTIN_VPERMILVARPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SI },
21346   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv4df3, "__builtin_ia32_vpermilvarpd256", IX86_BUILTIN_VPERMILVARPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DI },
21347   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv8sf3, "__builtin_ia32_vpermilvarps256", IX86_BUILTIN_VPERMILVARPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SI },
21348
21349   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendpd256, "__builtin_ia32_blendpd256", IX86_BUILTIN_BLENDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
21350   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendps256, "__builtin_ia32_blendps256", IX86_BUILTIN_BLENDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
21351   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendvpd256, "__builtin_ia32_blendvpd256", IX86_BUILTIN_BLENDVPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF },
21352   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendvps256, "__builtin_ia32_blendvps256", IX86_BUILTIN_BLENDVPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF },
21353   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_dpps256, "__builtin_ia32_dpps256", IX86_BUILTIN_DPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
21354   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_shufpd256, "__builtin_ia32_shufpd256", IX86_BUILTIN_SHUFPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
21355   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_shufps256, "__builtin_ia32_shufps256", IX86_BUILTIN_SHUFPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
21356   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpsdv2df3, "__builtin_ia32_cmpsd", IX86_BUILTIN_CMPSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21357   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpssv4sf3, "__builtin_ia32_cmpss", IX86_BUILTIN_CMPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21358   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppdv2df3, "__builtin_ia32_cmppd", IX86_BUILTIN_CMPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
21359   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppsv4sf3, "__builtin_ia32_cmpps", IX86_BUILTIN_CMPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
21360   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppdv4df3, "__builtin_ia32_cmppd256", IX86_BUILTIN_CMPPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
21361   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmppsv8sf3, "__builtin_ia32_cmpps256", IX86_BUILTIN_CMPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
21362   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v4df, "__builtin_ia32_vextractf128_pd256", IX86_BUILTIN_EXTRACTF128PD256, UNKNOWN, (int) V2DF_FTYPE_V4DF_INT },
21363   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v8sf, "__builtin_ia32_vextractf128_ps256", IX86_BUILTIN_EXTRACTF128PS256, UNKNOWN, (int) V4SF_FTYPE_V8SF_INT },
21364   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v8si, "__builtin_ia32_vextractf128_si256", IX86_BUILTIN_EXTRACTF128SI256, UNKNOWN, (int) V4SI_FTYPE_V8SI_INT },
21365   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtdq2pd256, "__builtin_ia32_cvtdq2pd256", IX86_BUILTIN_CVTDQ2PD256, UNKNOWN, (int) V4DF_FTYPE_V4SI },
21366   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtdq2ps256, "__builtin_ia32_cvtdq2ps256", IX86_BUILTIN_CVTDQ2PS256, UNKNOWN, (int) V8SF_FTYPE_V8SI },
21367   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtpd2ps256, "__builtin_ia32_cvtpd2ps256", IX86_BUILTIN_CVTPD2PS256, UNKNOWN, (int) V4SF_FTYPE_V4DF },
21368   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtps2dq256, "__builtin_ia32_cvtps2dq256", IX86_BUILTIN_CVTPS2DQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
21369   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtps2pd256, "__builtin_ia32_cvtps2pd256", IX86_BUILTIN_CVTPS2PD256, UNKNOWN, (int) V4DF_FTYPE_V4SF },
21370   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvttpd2dq256, "__builtin_ia32_cvttpd2dq256", IX86_BUILTIN_CVTTPD2DQ256, UNKNOWN, (int) V4SI_FTYPE_V4DF },
21371   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtpd2dq256, "__builtin_ia32_cvtpd2dq256", IX86_BUILTIN_CVTPD2DQ256, UNKNOWN, (int) V4SI_FTYPE_V4DF },
21372   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvttps2dq256, "__builtin_ia32_cvttps2dq256", IX86_BUILTIN_CVTTPS2DQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
21373   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v4df3, "__builtin_ia32_vperm2f128_pd256", IX86_BUILTIN_VPERM2F128PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
21374   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v8sf3, "__builtin_ia32_vperm2f128_ps256", IX86_BUILTIN_VPERM2F128PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
21375   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v8si3, "__builtin_ia32_vperm2f128_si256", IX86_BUILTIN_VPERM2F128SI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_INT },
21376   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv2df, "__builtin_ia32_vpermilpd", IX86_BUILTIN_VPERMILPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
21377   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv4sf, "__builtin_ia32_vpermilps", IX86_BUILTIN_VPERMILPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
21378   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv4df, "__builtin_ia32_vpermilpd256", IX86_BUILTIN_VPERMILPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
21379   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv8sf, "__builtin_ia32_vpermilps256", IX86_BUILTIN_VPERMILPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT },
21380   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v4df, "__builtin_ia32_vinsertf128_pd256", IX86_BUILTIN_VINSERTF128PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V2DF_INT },
21381   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v8sf, "__builtin_ia32_vinsertf128_ps256", IX86_BUILTIN_VINSERTF128PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V4SF_INT },
21382   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v8si, "__builtin_ia32_vinsertf128_si256", IX86_BUILTIN_VINSERTF128SI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_INT },
21383
21384   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movshdup256, "__builtin_ia32_movshdup256", IX86_BUILTIN_MOVSHDUP256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21385   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movsldup256, "__builtin_ia32_movsldup256", IX86_BUILTIN_MOVSLDUP256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21386   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movddup256, "__builtin_ia32_movddup256", IX86_BUILTIN_MOVDDUP256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
21387
21388   { OPTION_MASK_ISA_AVX, CODE_FOR_sqrtv4df2, "__builtin_ia32_sqrtpd256", IX86_BUILTIN_SQRTPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
21389   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_sqrtv8sf2, "__builtin_ia32_sqrtps256", IX86_BUILTIN_SQRTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21390   { OPTION_MASK_ISA_AVX, CODE_FOR_sqrtv8sf2, "__builtin_ia32_sqrtps_nr256", IX86_BUILTIN_SQRTPS_NR256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21391   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_rsqrtv8sf2, "__builtin_ia32_rsqrtps256", IX86_BUILTIN_RSQRTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21392   { OPTION_MASK_ISA_AVX, CODE_FOR_rsqrtv8sf2, "__builtin_ia32_rsqrtps_nr256", IX86_BUILTIN_RSQRTPS_NR256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21393
21394   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_rcpv8sf2, "__builtin_ia32_rcpps256", IX86_BUILTIN_RCPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
21395
21396   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_roundpd256", IX86_BUILTIN_ROUNDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
21397   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_roundps256", IX86_BUILTIN_ROUNDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT },
21398
21399   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpckhpd256,  "__builtin_ia32_unpckhpd256", IX86_BUILTIN_UNPCKHPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21400   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpcklpd256,  "__builtin_ia32_unpcklpd256", IX86_BUILTIN_UNPCKLPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
21401   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpckhps256,  "__builtin_ia32_unpckhps256", IX86_BUILTIN_UNPCKHPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21402   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpcklps256,  "__builtin_ia32_unpcklps256", IX86_BUILTIN_UNPCKLPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
21403
21404   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_si256_si, "__builtin_ia32_si256_si", IX86_BUILTIN_SI256_SI, UNKNOWN, (int) V8SI_FTYPE_V4SI },
21405   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ps256_ps, "__builtin_ia32_ps256_ps", IX86_BUILTIN_PS256_PS, UNKNOWN, (int) V8SF_FTYPE_V4SF },
21406   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_pd256_pd, "__builtin_ia32_pd256_pd", IX86_BUILTIN_PD256_PD, UNKNOWN, (int) V4DF_FTYPE_V2DF },
21407   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_si_si256, "__builtin_ia32_si_si256", IX86_BUILTIN_SI_SI256, UNKNOWN, (int) V4SI_FTYPE_V8SI },
21408   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ps_ps256, "__builtin_ia32_ps_ps256", IX86_BUILTIN_PS_PS256, UNKNOWN, (int) V4SF_FTYPE_V8SF },
21409   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_pd_pd256, "__builtin_ia32_pd_pd256", IX86_BUILTIN_PD_PD256, UNKNOWN, (int) V2DF_FTYPE_V4DF },
21410
21411   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestzpd", IX86_BUILTIN_VTESTZPD, EQ, (int) INT_FTYPE_V2DF_V2DF_PTEST },
21412   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestcpd", IX86_BUILTIN_VTESTCPD, LTU, (int) INT_FTYPE_V2DF_V2DF_PTEST },
21413   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestnzcpd", IX86_BUILTIN_VTESTNZCPD, GTU, (int) INT_FTYPE_V2DF_V2DF_PTEST },
21414   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestzps", IX86_BUILTIN_VTESTZPS, EQ, (int) INT_FTYPE_V4SF_V4SF_PTEST },
21415   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestcps", IX86_BUILTIN_VTESTCPS, LTU, (int) INT_FTYPE_V4SF_V4SF_PTEST },
21416   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestnzcps", IX86_BUILTIN_VTESTNZCPS, GTU, (int) INT_FTYPE_V4SF_V4SF_PTEST },
21417   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestzpd256", IX86_BUILTIN_VTESTZPD256, EQ, (int) INT_FTYPE_V4DF_V4DF_PTEST },
21418   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestcpd256", IX86_BUILTIN_VTESTCPD256, LTU, (int) INT_FTYPE_V4DF_V4DF_PTEST },
21419   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestnzcpd256", IX86_BUILTIN_VTESTNZCPD256, GTU, (int) INT_FTYPE_V4DF_V4DF_PTEST },
21420   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestzps256", IX86_BUILTIN_VTESTZPS256, EQ, (int) INT_FTYPE_V8SF_V8SF_PTEST },
21421   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestcps256", IX86_BUILTIN_VTESTCPS256, LTU, (int) INT_FTYPE_V8SF_V8SF_PTEST },
21422   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestnzcps256", IX86_BUILTIN_VTESTNZCPS256, GTU, (int) INT_FTYPE_V8SF_V8SF_PTEST },
21423   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestz256", IX86_BUILTIN_PTESTZ256, EQ, (int) INT_FTYPE_V4DI_V4DI_PTEST },
21424   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestc256", IX86_BUILTIN_PTESTC256, LTU, (int) INT_FTYPE_V4DI_V4DI_PTEST },
21425   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestnzc256", IX86_BUILTIN_PTESTNZC256, GTU, (int) INT_FTYPE_V4DI_V4DI_PTEST },
21426
21427   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movmskpd256, "__builtin_ia32_movmskpd256", IX86_BUILTIN_MOVMSKPD256, UNKNOWN, (int) INT_FTYPE_V4DF  },
21428   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movmskps256, "__builtin_ia32_movmskps256", IX86_BUILTIN_MOVMSKPS256, UNKNOWN, (int) INT_FTYPE_V8SF },
21429 };
21430
21431 /* SSE5 */
21432 enum multi_arg_type {
21433   MULTI_ARG_UNKNOWN,
21434   MULTI_ARG_3_SF,
21435   MULTI_ARG_3_DF,
21436   MULTI_ARG_3_DI,
21437   MULTI_ARG_3_SI,
21438   MULTI_ARG_3_SI_DI,
21439   MULTI_ARG_3_HI,
21440   MULTI_ARG_3_HI_SI,
21441   MULTI_ARG_3_QI,
21442   MULTI_ARG_3_PERMPS,
21443   MULTI_ARG_3_PERMPD,
21444   MULTI_ARG_2_SF,
21445   MULTI_ARG_2_DF,
21446   MULTI_ARG_2_DI,
21447   MULTI_ARG_2_SI,
21448   MULTI_ARG_2_HI,
21449   MULTI_ARG_2_QI,
21450   MULTI_ARG_2_DI_IMM,
21451   MULTI_ARG_2_SI_IMM,
21452   MULTI_ARG_2_HI_IMM,
21453   MULTI_ARG_2_QI_IMM,
21454   MULTI_ARG_2_SF_CMP,
21455   MULTI_ARG_2_DF_CMP,
21456   MULTI_ARG_2_DI_CMP,
21457   MULTI_ARG_2_SI_CMP,
21458   MULTI_ARG_2_HI_CMP,
21459   MULTI_ARG_2_QI_CMP,
21460   MULTI_ARG_2_DI_TF,
21461   MULTI_ARG_2_SI_TF,
21462   MULTI_ARG_2_HI_TF,
21463   MULTI_ARG_2_QI_TF,
21464   MULTI_ARG_2_SF_TF,
21465   MULTI_ARG_2_DF_TF,
21466   MULTI_ARG_1_SF,
21467   MULTI_ARG_1_DF,
21468   MULTI_ARG_1_DI,
21469   MULTI_ARG_1_SI,
21470   MULTI_ARG_1_HI,
21471   MULTI_ARG_1_QI,
21472   MULTI_ARG_1_SI_DI,
21473   MULTI_ARG_1_HI_DI,
21474   MULTI_ARG_1_HI_SI,
21475   MULTI_ARG_1_QI_DI,
21476   MULTI_ARG_1_QI_SI,
21477   MULTI_ARG_1_QI_HI,
21478   MULTI_ARG_1_PH2PS,
21479   MULTI_ARG_1_PS2PH
21480 };
21481
21482 static const struct builtin_description bdesc_multi_arg[] =
21483 {
21484   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmaddv4sf4,     "__builtin_ia32_fmaddss",    IX86_BUILTIN_FMADDSS,    0,            (int)MULTI_ARG_3_SF },
21485   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmaddv2df4,     "__builtin_ia32_fmaddsd",    IX86_BUILTIN_FMADDSD,    0,            (int)MULTI_ARG_3_DF },
21486   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmaddv4sf4,       "__builtin_ia32_fmaddps",    IX86_BUILTIN_FMADDPS,    0,            (int)MULTI_ARG_3_SF },
21487   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmaddv2df4,       "__builtin_ia32_fmaddpd",    IX86_BUILTIN_FMADDPD,    0,            (int)MULTI_ARG_3_DF },
21488   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmsubv4sf4,     "__builtin_ia32_fmsubss",    IX86_BUILTIN_FMSUBSS,    0,            (int)MULTI_ARG_3_SF },
21489   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfmsubv2df4,     "__builtin_ia32_fmsubsd",    IX86_BUILTIN_FMSUBSD,    0,            (int)MULTI_ARG_3_DF },
21490   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmsubv4sf4,       "__builtin_ia32_fmsubps",    IX86_BUILTIN_FMSUBPS,    0,            (int)MULTI_ARG_3_SF },
21491   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fmsubv2df4,       "__builtin_ia32_fmsubpd",    IX86_BUILTIN_FMSUBPD,    0,            (int)MULTI_ARG_3_DF },
21492   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmaddv4sf4,    "__builtin_ia32_fnmaddss",   IX86_BUILTIN_FNMADDSS,   0,            (int)MULTI_ARG_3_SF },
21493   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmaddv2df4,    "__builtin_ia32_fnmaddsd",   IX86_BUILTIN_FNMADDSD,   0,            (int)MULTI_ARG_3_DF },
21494   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmaddv4sf4,      "__builtin_ia32_fnmaddps",   IX86_BUILTIN_FNMADDPS,   0,            (int)MULTI_ARG_3_SF },
21495   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmaddv2df4,      "__builtin_ia32_fnmaddpd",   IX86_BUILTIN_FNMADDPD,   0,            (int)MULTI_ARG_3_DF },
21496   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmsubv4sf4,    "__builtin_ia32_fnmsubss",   IX86_BUILTIN_FNMSUBSS,   0,            (int)MULTI_ARG_3_SF },
21497   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_vmfnmsubv2df4,    "__builtin_ia32_fnmsubsd",   IX86_BUILTIN_FNMSUBSD,   0,            (int)MULTI_ARG_3_DF },
21498   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmsubv4sf4,      "__builtin_ia32_fnmsubps",   IX86_BUILTIN_FNMSUBPS,   0,            (int)MULTI_ARG_3_SF },
21499   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5i_fnmsubv2df4,      "__builtin_ia32_fnmsubpd",   IX86_BUILTIN_FNMSUBPD,   0,            (int)MULTI_ARG_3_DF },
21500   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2di,        "__builtin_ia32_pcmov",      IX86_BUILTIN_PCMOV,      0,            (int)MULTI_ARG_3_DI },
21501   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2di,        "__builtin_ia32_pcmov_v2di", IX86_BUILTIN_PCMOV_V2DI, 0,            (int)MULTI_ARG_3_DI },
21502   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v4si,        "__builtin_ia32_pcmov_v4si", IX86_BUILTIN_PCMOV_V4SI, 0,            (int)MULTI_ARG_3_SI },
21503   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v8hi,        "__builtin_ia32_pcmov_v8hi", IX86_BUILTIN_PCMOV_V8HI, 0,            (int)MULTI_ARG_3_HI },
21504   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v16qi,       "__builtin_ia32_pcmov_v16qi",IX86_BUILTIN_PCMOV_V16QI,0,            (int)MULTI_ARG_3_QI },
21505   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v2df,        "__builtin_ia32_pcmov_v2df", IX86_BUILTIN_PCMOV_V2DF, 0,            (int)MULTI_ARG_3_DF },
21506   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcmov_v4sf,        "__builtin_ia32_pcmov_v4sf", IX86_BUILTIN_PCMOV_V4SF, 0,            (int)MULTI_ARG_3_SF },
21507   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pperm,             "__builtin_ia32_pperm",      IX86_BUILTIN_PPERM,      0,            (int)MULTI_ARG_3_QI },
21508   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_permv4sf,          "__builtin_ia32_permps",     IX86_BUILTIN_PERMPS,     0,            (int)MULTI_ARG_3_PERMPS },
21509   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_permv2df,          "__builtin_ia32_permpd",     IX86_BUILTIN_PERMPD,     0,            (int)MULTI_ARG_3_PERMPD },
21510   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssww,          "__builtin_ia32_pmacssww",   IX86_BUILTIN_PMACSSWW,   0,            (int)MULTI_ARG_3_HI },
21511   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsww,           "__builtin_ia32_pmacsww",    IX86_BUILTIN_PMACSWW,    0,            (int)MULTI_ARG_3_HI },
21512   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsswd,          "__builtin_ia32_pmacsswd",   IX86_BUILTIN_PMACSSWD,   0,            (int)MULTI_ARG_3_HI_SI },
21513   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacswd,           "__builtin_ia32_pmacswd",    IX86_BUILTIN_PMACSWD,    0,            (int)MULTI_ARG_3_HI_SI },
21514   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdd,          "__builtin_ia32_pmacssdd",   IX86_BUILTIN_PMACSSDD,   0,            (int)MULTI_ARG_3_SI },
21515   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdd,           "__builtin_ia32_pmacsdd",    IX86_BUILTIN_PMACSDD,    0,            (int)MULTI_ARG_3_SI },
21516   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdql,         "__builtin_ia32_pmacssdql",  IX86_BUILTIN_PMACSSDQL,  0,            (int)MULTI_ARG_3_SI_DI },
21517   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacssdqh,         "__builtin_ia32_pmacssdqh",  IX86_BUILTIN_PMACSSDQH,  0,            (int)MULTI_ARG_3_SI_DI },
21518   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdql,          "__builtin_ia32_pmacsdql",   IX86_BUILTIN_PMACSDQL,   0,            (int)MULTI_ARG_3_SI_DI },
21519   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmacsdqh,          "__builtin_ia32_pmacsdqh",   IX86_BUILTIN_PMACSDQH,   0,            (int)MULTI_ARG_3_SI_DI },
21520   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmadcsswd,         "__builtin_ia32_pmadcsswd",  IX86_BUILTIN_PMADCSSWD,  0,            (int)MULTI_ARG_3_HI_SI },
21521   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pmadcswd,          "__builtin_ia32_pmadcswd",   IX86_BUILTIN_PMADCSWD,   0,            (int)MULTI_ARG_3_HI_SI },
21522   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv2di3,        "__builtin_ia32_protq",      IX86_BUILTIN_PROTQ,      0,            (int)MULTI_ARG_2_DI },
21523   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv4si3,        "__builtin_ia32_protd",      IX86_BUILTIN_PROTD,      0,            (int)MULTI_ARG_2_SI },
21524   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv8hi3,        "__builtin_ia32_protw",      IX86_BUILTIN_PROTW,      0,            (int)MULTI_ARG_2_HI },
21525   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vrotlv16qi3,       "__builtin_ia32_protb",      IX86_BUILTIN_PROTB,      0,            (int)MULTI_ARG_2_QI },
21526   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv2di3,         "__builtin_ia32_protqi",     IX86_BUILTIN_PROTQ_IMM,  0,            (int)MULTI_ARG_2_DI_IMM },
21527   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv4si3,         "__builtin_ia32_protdi",     IX86_BUILTIN_PROTD_IMM,  0,            (int)MULTI_ARG_2_SI_IMM },
21528   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv8hi3,         "__builtin_ia32_protwi",     IX86_BUILTIN_PROTW_IMM,  0,            (int)MULTI_ARG_2_HI_IMM },
21529   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_rotlv16qi3,        "__builtin_ia32_protbi",     IX86_BUILTIN_PROTB_IMM,  0,            (int)MULTI_ARG_2_QI_IMM },
21530   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv2di3,         "__builtin_ia32_pshaq",      IX86_BUILTIN_PSHAQ,      0,            (int)MULTI_ARG_2_DI },
21531   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv4si3,         "__builtin_ia32_pshad",      IX86_BUILTIN_PSHAD,      0,            (int)MULTI_ARG_2_SI },
21532   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv8hi3,         "__builtin_ia32_pshaw",      IX86_BUILTIN_PSHAW,      0,            (int)MULTI_ARG_2_HI },
21533   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_ashlv16qi3,        "__builtin_ia32_pshab",      IX86_BUILTIN_PSHAB,      0,            (int)MULTI_ARG_2_QI },
21534   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv2di3,         "__builtin_ia32_pshlq",      IX86_BUILTIN_PSHLQ,      0,            (int)MULTI_ARG_2_DI },
21535   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv4si3,         "__builtin_ia32_pshld",      IX86_BUILTIN_PSHLD,      0,            (int)MULTI_ARG_2_SI },
21536   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv8hi3,         "__builtin_ia32_pshlw",      IX86_BUILTIN_PSHLW,      0,            (int)MULTI_ARG_2_HI },
21537   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_lshlv16qi3,        "__builtin_ia32_pshlb",      IX86_BUILTIN_PSHLB,      0,            (int)MULTI_ARG_2_QI },
21538   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmfrczv4sf2,       "__builtin_ia32_frczss",     IX86_BUILTIN_FRCZSS,     0,            (int)MULTI_ARG_2_SF },
21539   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmfrczv2df2,       "__builtin_ia32_frczsd",     IX86_BUILTIN_FRCZSD,     0,            (int)MULTI_ARG_2_DF },
21540   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_frczv4sf2,         "__builtin_ia32_frczps",     IX86_BUILTIN_FRCZPS,     0,            (int)MULTI_ARG_1_SF },
21541   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_frczv2df2,         "__builtin_ia32_frczpd",     IX86_BUILTIN_FRCZPD,     0,            (int)MULTI_ARG_1_DF },
21542   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_cvtph2ps,          "__builtin_ia32_cvtph2ps",   IX86_BUILTIN_CVTPH2PS,   0,            (int)MULTI_ARG_1_PH2PS },
21543   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_cvtps2ph,          "__builtin_ia32_cvtps2ph",   IX86_BUILTIN_CVTPS2PH,   0,            (int)MULTI_ARG_1_PS2PH },
21544   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbw,           "__builtin_ia32_phaddbw",    IX86_BUILTIN_PHADDBW,    0,            (int)MULTI_ARG_1_QI_HI },
21545   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbd,           "__builtin_ia32_phaddbd",    IX86_BUILTIN_PHADDBD,    0,            (int)MULTI_ARG_1_QI_SI },
21546   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddbq,           "__builtin_ia32_phaddbq",    IX86_BUILTIN_PHADDBQ,    0,            (int)MULTI_ARG_1_QI_DI },
21547   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddwd,           "__builtin_ia32_phaddwd",    IX86_BUILTIN_PHADDWD,    0,            (int)MULTI_ARG_1_HI_SI },
21548   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddwq,           "__builtin_ia32_phaddwq",    IX86_BUILTIN_PHADDWQ,    0,            (int)MULTI_ARG_1_HI_DI },
21549   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadddq,           "__builtin_ia32_phadddq",    IX86_BUILTIN_PHADDDQ,    0,            (int)MULTI_ARG_1_SI_DI },
21550   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubw,          "__builtin_ia32_phaddubw",   IX86_BUILTIN_PHADDUBW,   0,            (int)MULTI_ARG_1_QI_HI },
21551   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubd,          "__builtin_ia32_phaddubd",   IX86_BUILTIN_PHADDUBD,   0,            (int)MULTI_ARG_1_QI_SI },
21552   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddubq,          "__builtin_ia32_phaddubq",   IX86_BUILTIN_PHADDUBQ,   0,            (int)MULTI_ARG_1_QI_DI },
21553   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadduwd,          "__builtin_ia32_phadduwd",   IX86_BUILTIN_PHADDUWD,   0,            (int)MULTI_ARG_1_HI_SI },
21554   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phadduwq,          "__builtin_ia32_phadduwq",   IX86_BUILTIN_PHADDUWQ,   0,            (int)MULTI_ARG_1_HI_DI },
21555   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phaddudq,          "__builtin_ia32_phaddudq",   IX86_BUILTIN_PHADDUDQ,   0,            (int)MULTI_ARG_1_SI_DI },
21556   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubbw,           "__builtin_ia32_phsubbw",    IX86_BUILTIN_PHSUBBW,    0,            (int)MULTI_ARG_1_QI_HI },
21557   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubwd,           "__builtin_ia32_phsubwd",    IX86_BUILTIN_PHSUBWD,    0,            (int)MULTI_ARG_1_HI_SI },
21558   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_phsubdq,           "__builtin_ia32_phsubdq",    IX86_BUILTIN_PHSUBDQ,    0,            (int)MULTI_ARG_1_SI_DI },
21559
21560   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comeqss",    IX86_BUILTIN_COMEQSS,    EQ,           (int)MULTI_ARG_2_SF_CMP },
21561   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comness",    IX86_BUILTIN_COMNESS,    NE,           (int)MULTI_ARG_2_SF_CMP },
21562   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comneqss",   IX86_BUILTIN_COMNESS,    NE,           (int)MULTI_ARG_2_SF_CMP },
21563   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comltss",    IX86_BUILTIN_COMLTSS,    LT,           (int)MULTI_ARG_2_SF_CMP },
21564   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comless",    IX86_BUILTIN_COMLESS,    LE,           (int)MULTI_ARG_2_SF_CMP },
21565   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comgtss",    IX86_BUILTIN_COMGTSS,    GT,           (int)MULTI_ARG_2_SF_CMP },
21566   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comgess",    IX86_BUILTIN_COMGESS,    GE,           (int)MULTI_ARG_2_SF_CMP },
21567   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comueqss",   IX86_BUILTIN_COMUEQSS,   UNEQ,         (int)MULTI_ARG_2_SF_CMP },
21568   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comuness",   IX86_BUILTIN_COMUNESS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21569   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comuneqss",  IX86_BUILTIN_COMUNESS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21570   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunltss",  IX86_BUILTIN_COMULTSS,   UNLT,         (int)MULTI_ARG_2_SF_CMP },
21571   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunless",  IX86_BUILTIN_COMULESS,   UNLE,         (int)MULTI_ARG_2_SF_CMP },
21572   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comungtss",  IX86_BUILTIN_COMUGTSS,   UNGT,         (int)MULTI_ARG_2_SF_CMP },
21573   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comungess",  IX86_BUILTIN_COMUGESS,   UNGE,         (int)MULTI_ARG_2_SF_CMP },
21574   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comordss",   IX86_BUILTIN_COMORDSS,   ORDERED,      (int)MULTI_ARG_2_SF_CMP },
21575   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv4sf3,    "__builtin_ia32_comunordss", IX86_BUILTIN_COMUNORDSS, UNORDERED,    (int)MULTI_ARG_2_SF_CMP },
21576
21577   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comeqsd",    IX86_BUILTIN_COMEQSD,    EQ,           (int)MULTI_ARG_2_DF_CMP },
21578   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comnesd",    IX86_BUILTIN_COMNESD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21579   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comneqsd",   IX86_BUILTIN_COMNESD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21580   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comltsd",    IX86_BUILTIN_COMLTSD,    LT,           (int)MULTI_ARG_2_DF_CMP },
21581   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comlesd",    IX86_BUILTIN_COMLESD,    LE,           (int)MULTI_ARG_2_DF_CMP },
21582   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comgtsd",    IX86_BUILTIN_COMGTSD,    GT,           (int)MULTI_ARG_2_DF_CMP },
21583   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comgesd",    IX86_BUILTIN_COMGESD,    GE,           (int)MULTI_ARG_2_DF_CMP },
21584   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comueqsd",   IX86_BUILTIN_COMUEQSD,   UNEQ,         (int)MULTI_ARG_2_DF_CMP },
21585   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunesd",   IX86_BUILTIN_COMUNESD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21586   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comuneqsd",  IX86_BUILTIN_COMUNESD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21587   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunltsd",  IX86_BUILTIN_COMULTSD,   UNLT,         (int)MULTI_ARG_2_DF_CMP },
21588   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunlesd",  IX86_BUILTIN_COMULESD,   UNLE,         (int)MULTI_ARG_2_DF_CMP },
21589   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comungtsd",  IX86_BUILTIN_COMUGTSD,   UNGT,         (int)MULTI_ARG_2_DF_CMP },
21590   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comungesd",  IX86_BUILTIN_COMUGESD,   UNGE,         (int)MULTI_ARG_2_DF_CMP },
21591   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comordsd",   IX86_BUILTIN_COMORDSD,   ORDERED,      (int)MULTI_ARG_2_DF_CMP },
21592   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_vmmaskcmpv2df3,    "__builtin_ia32_comunordsd", IX86_BUILTIN_COMUNORDSD, UNORDERED,    (int)MULTI_ARG_2_DF_CMP },
21593
21594   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comeqps",    IX86_BUILTIN_COMEQPS,    EQ,           (int)MULTI_ARG_2_SF_CMP },
21595   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comneps",    IX86_BUILTIN_COMNEPS,    NE,           (int)MULTI_ARG_2_SF_CMP },
21596   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comneqps",   IX86_BUILTIN_COMNEPS,    NE,           (int)MULTI_ARG_2_SF_CMP },
21597   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comltps",    IX86_BUILTIN_COMLTPS,    LT,           (int)MULTI_ARG_2_SF_CMP },
21598   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comleps",    IX86_BUILTIN_COMLEPS,    LE,           (int)MULTI_ARG_2_SF_CMP },
21599   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comgtps",    IX86_BUILTIN_COMGTPS,    GT,           (int)MULTI_ARG_2_SF_CMP },
21600   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comgeps",    IX86_BUILTIN_COMGEPS,    GE,           (int)MULTI_ARG_2_SF_CMP },
21601   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comueqps",   IX86_BUILTIN_COMUEQPS,   UNEQ,         (int)MULTI_ARG_2_SF_CMP },
21602   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comuneps",   IX86_BUILTIN_COMUNEPS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21603   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comuneqps",  IX86_BUILTIN_COMUNEPS,   LTGT,         (int)MULTI_ARG_2_SF_CMP },
21604   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunltps",  IX86_BUILTIN_COMULTPS,   UNLT,         (int)MULTI_ARG_2_SF_CMP },
21605   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunleps",  IX86_BUILTIN_COMULEPS,   UNLE,         (int)MULTI_ARG_2_SF_CMP },
21606   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comungtps",  IX86_BUILTIN_COMUGTPS,   UNGT,         (int)MULTI_ARG_2_SF_CMP },
21607   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comungeps",  IX86_BUILTIN_COMUGEPS,   UNGE,         (int)MULTI_ARG_2_SF_CMP },
21608   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comordps",   IX86_BUILTIN_COMORDPS,   ORDERED,      (int)MULTI_ARG_2_SF_CMP },
21609   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4sf3,      "__builtin_ia32_comunordps", IX86_BUILTIN_COMUNORDPS, UNORDERED,    (int)MULTI_ARG_2_SF_CMP },
21610
21611   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comeqpd",    IX86_BUILTIN_COMEQPD,    EQ,           (int)MULTI_ARG_2_DF_CMP },
21612   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comnepd",    IX86_BUILTIN_COMNEPD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21613   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comneqpd",   IX86_BUILTIN_COMNEPD,    NE,           (int)MULTI_ARG_2_DF_CMP },
21614   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comltpd",    IX86_BUILTIN_COMLTPD,    LT,           (int)MULTI_ARG_2_DF_CMP },
21615   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comlepd",    IX86_BUILTIN_COMLEPD,    LE,           (int)MULTI_ARG_2_DF_CMP },
21616   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comgtpd",    IX86_BUILTIN_COMGTPD,    GT,           (int)MULTI_ARG_2_DF_CMP },
21617   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comgepd",    IX86_BUILTIN_COMGEPD,    GE,           (int)MULTI_ARG_2_DF_CMP },
21618   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comueqpd",   IX86_BUILTIN_COMUEQPD,   UNEQ,         (int)MULTI_ARG_2_DF_CMP },
21619   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunepd",   IX86_BUILTIN_COMUNEPD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21620   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comuneqpd",  IX86_BUILTIN_COMUNEPD,   LTGT,         (int)MULTI_ARG_2_DF_CMP },
21621   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunltpd",  IX86_BUILTIN_COMULTPD,   UNLT,         (int)MULTI_ARG_2_DF_CMP },
21622   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunlepd",  IX86_BUILTIN_COMULEPD,   UNLE,         (int)MULTI_ARG_2_DF_CMP },
21623   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comungtpd",  IX86_BUILTIN_COMUGTPD,   UNGT,         (int)MULTI_ARG_2_DF_CMP },
21624   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comungepd",  IX86_BUILTIN_COMUGEPD,   UNGE,         (int)MULTI_ARG_2_DF_CMP },
21625   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comordpd",   IX86_BUILTIN_COMORDPD,   ORDERED,      (int)MULTI_ARG_2_DF_CMP },
21626   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2df3,      "__builtin_ia32_comunordpd", IX86_BUILTIN_COMUNORDPD, UNORDERED,    (int)MULTI_ARG_2_DF_CMP },
21627
21628   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomeqb",    IX86_BUILTIN_PCOMEQB,    EQ,           (int)MULTI_ARG_2_QI_CMP },
21629   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomneb",    IX86_BUILTIN_PCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
21630   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomneqb",   IX86_BUILTIN_PCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
21631   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomltb",    IX86_BUILTIN_PCOMLTB,    LT,           (int)MULTI_ARG_2_QI_CMP },
21632   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomleb",    IX86_BUILTIN_PCOMLEB,    LE,           (int)MULTI_ARG_2_QI_CMP },
21633   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomgtb",    IX86_BUILTIN_PCOMGTB,    GT,           (int)MULTI_ARG_2_QI_CMP },
21634   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv16qi3,     "__builtin_ia32_pcomgeb",    IX86_BUILTIN_PCOMGEB,    GE,           (int)MULTI_ARG_2_QI_CMP },
21635
21636   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomeqw",    IX86_BUILTIN_PCOMEQW,    EQ,           (int)MULTI_ARG_2_HI_CMP },
21637   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomnew",    IX86_BUILTIN_PCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
21638   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomneqw",   IX86_BUILTIN_PCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
21639   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomltw",    IX86_BUILTIN_PCOMLTW,    LT,           (int)MULTI_ARG_2_HI_CMP },
21640   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomlew",    IX86_BUILTIN_PCOMLEW,    LE,           (int)MULTI_ARG_2_HI_CMP },
21641   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomgtw",    IX86_BUILTIN_PCOMGTW,    GT,           (int)MULTI_ARG_2_HI_CMP },
21642   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv8hi3,      "__builtin_ia32_pcomgew",    IX86_BUILTIN_PCOMGEW,    GE,           (int)MULTI_ARG_2_HI_CMP },
21643
21644   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomeqd",    IX86_BUILTIN_PCOMEQD,    EQ,           (int)MULTI_ARG_2_SI_CMP },
21645   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomned",    IX86_BUILTIN_PCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
21646   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomneqd",   IX86_BUILTIN_PCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
21647   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomltd",    IX86_BUILTIN_PCOMLTD,    LT,           (int)MULTI_ARG_2_SI_CMP },
21648   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomled",    IX86_BUILTIN_PCOMLED,    LE,           (int)MULTI_ARG_2_SI_CMP },
21649   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomgtd",    IX86_BUILTIN_PCOMGTD,    GT,           (int)MULTI_ARG_2_SI_CMP },
21650   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv4si3,      "__builtin_ia32_pcomged",    IX86_BUILTIN_PCOMGED,    GE,           (int)MULTI_ARG_2_SI_CMP },
21651
21652   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomeqq",    IX86_BUILTIN_PCOMEQQ,    EQ,           (int)MULTI_ARG_2_DI_CMP },
21653   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomneq",    IX86_BUILTIN_PCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
21654   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomneqq",   IX86_BUILTIN_PCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
21655   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomltq",    IX86_BUILTIN_PCOMLTQ,    LT,           (int)MULTI_ARG_2_DI_CMP },
21656   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomleq",    IX86_BUILTIN_PCOMLEQ,    LE,           (int)MULTI_ARG_2_DI_CMP },
21657   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomgtq",    IX86_BUILTIN_PCOMGTQ,    GT,           (int)MULTI_ARG_2_DI_CMP },
21658   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmpv2di3,      "__builtin_ia32_pcomgeq",    IX86_BUILTIN_PCOMGEQ,    GE,           (int)MULTI_ARG_2_DI_CMP },
21659
21660   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomequb",   IX86_BUILTIN_PCOMEQUB,   EQ,           (int)MULTI_ARG_2_QI_CMP },
21661   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomneub",   IX86_BUILTIN_PCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
21662   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v16qi3,"__builtin_ia32_pcomnequb",  IX86_BUILTIN_PCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
21663   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomltub",   IX86_BUILTIN_PCOMLTUB,   LTU,          (int)MULTI_ARG_2_QI_CMP },
21664   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomleub",   IX86_BUILTIN_PCOMLEUB,   LEU,          (int)MULTI_ARG_2_QI_CMP },
21665   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomgtub",   IX86_BUILTIN_PCOMGTUB,   GTU,          (int)MULTI_ARG_2_QI_CMP },
21666   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv16qi3, "__builtin_ia32_pcomgeub",   IX86_BUILTIN_PCOMGEUB,   GEU,          (int)MULTI_ARG_2_QI_CMP },
21667
21668   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomequw",   IX86_BUILTIN_PCOMEQUW,   EQ,           (int)MULTI_ARG_2_HI_CMP },
21669   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomneuw",   IX86_BUILTIN_PCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
21670   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v8hi3, "__builtin_ia32_pcomnequw",  IX86_BUILTIN_PCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
21671   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomltuw",   IX86_BUILTIN_PCOMLTUW,   LTU,          (int)MULTI_ARG_2_HI_CMP },
21672   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomleuw",   IX86_BUILTIN_PCOMLEUW,   LEU,          (int)MULTI_ARG_2_HI_CMP },
21673   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomgtuw",   IX86_BUILTIN_PCOMGTUW,   GTU,          (int)MULTI_ARG_2_HI_CMP },
21674   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv8hi3,  "__builtin_ia32_pcomgeuw",   IX86_BUILTIN_PCOMGEUW,   GEU,          (int)MULTI_ARG_2_HI_CMP },
21675
21676   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomequd",   IX86_BUILTIN_PCOMEQUD,   EQ,           (int)MULTI_ARG_2_SI_CMP },
21677   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomneud",   IX86_BUILTIN_PCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
21678   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v4si3, "__builtin_ia32_pcomnequd",  IX86_BUILTIN_PCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
21679   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomltud",   IX86_BUILTIN_PCOMLTUD,   LTU,          (int)MULTI_ARG_2_SI_CMP },
21680   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomleud",   IX86_BUILTIN_PCOMLEUD,   LEU,          (int)MULTI_ARG_2_SI_CMP },
21681   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomgtud",   IX86_BUILTIN_PCOMGTUD,   GTU,          (int)MULTI_ARG_2_SI_CMP },
21682   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv4si3,  "__builtin_ia32_pcomgeud",   IX86_BUILTIN_PCOMGEUD,   GEU,          (int)MULTI_ARG_2_SI_CMP },
21683
21684   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomequq",   IX86_BUILTIN_PCOMEQUQ,   EQ,           (int)MULTI_ARG_2_DI_CMP },
21685   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomneuq",   IX86_BUILTIN_PCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
21686   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_uns2v2di3, "__builtin_ia32_pcomnequq",  IX86_BUILTIN_PCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
21687   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomltuq",   IX86_BUILTIN_PCOMLTUQ,   LTU,          (int)MULTI_ARG_2_DI_CMP },
21688   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomleuq",   IX86_BUILTIN_PCOMLEUQ,   LEU,          (int)MULTI_ARG_2_DI_CMP },
21689   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomgtuq",   IX86_BUILTIN_PCOMGTUQ,   GTU,          (int)MULTI_ARG_2_DI_CMP },
21690   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_maskcmp_unsv2di3,  "__builtin_ia32_pcomgeuq",   IX86_BUILTIN_PCOMGEUQ,   GEU,          (int)MULTI_ARG_2_DI_CMP },
21691
21692   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comfalsess", IX86_BUILTIN_COMFALSESS, COM_FALSE_S,  (int)MULTI_ARG_2_SF_TF },
21693   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comtruess",  IX86_BUILTIN_COMTRUESS,  COM_TRUE_S,   (int)MULTI_ARG_2_SF_TF },
21694   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comfalseps", IX86_BUILTIN_COMFALSEPS, COM_FALSE_P,  (int)MULTI_ARG_2_SF_TF },
21695   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv4sf3,       "__builtin_ia32_comtrueps",  IX86_BUILTIN_COMTRUEPS,  COM_TRUE_P,   (int)MULTI_ARG_2_SF_TF },
21696   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comfalsesd", IX86_BUILTIN_COMFALSESD, COM_FALSE_S,  (int)MULTI_ARG_2_DF_TF },
21697   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comtruesd",  IX86_BUILTIN_COMTRUESD,  COM_TRUE_S,   (int)MULTI_ARG_2_DF_TF },
21698   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comfalsepd", IX86_BUILTIN_COMFALSEPD, COM_FALSE_P,  (int)MULTI_ARG_2_DF_TF },
21699   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_com_tfv2df3,       "__builtin_ia32_comtruepd",  IX86_BUILTIN_COMTRUEPD,  COM_TRUE_P,   (int)MULTI_ARG_2_DF_TF },
21700
21701   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomfalseb", IX86_BUILTIN_PCOMFALSEB, PCOM_FALSE,   (int)MULTI_ARG_2_QI_TF },
21702   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomfalsew", IX86_BUILTIN_PCOMFALSEW, PCOM_FALSE,   (int)MULTI_ARG_2_HI_TF },
21703   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomfalsed", IX86_BUILTIN_PCOMFALSED, PCOM_FALSE,   (int)MULTI_ARG_2_SI_TF },
21704   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomfalseq", IX86_BUILTIN_PCOMFALSEQ, PCOM_FALSE,   (int)MULTI_ARG_2_DI_TF },
21705   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomfalseub",IX86_BUILTIN_PCOMFALSEUB,PCOM_FALSE,   (int)MULTI_ARG_2_QI_TF },
21706   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomfalseuw",IX86_BUILTIN_PCOMFALSEUW,PCOM_FALSE,   (int)MULTI_ARG_2_HI_TF },
21707   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomfalseud",IX86_BUILTIN_PCOMFALSEUD,PCOM_FALSE,   (int)MULTI_ARG_2_SI_TF },
21708   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomfalseuq",IX86_BUILTIN_PCOMFALSEUQ,PCOM_FALSE,   (int)MULTI_ARG_2_DI_TF },
21709
21710   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomtrueb",  IX86_BUILTIN_PCOMTRUEB,  PCOM_TRUE,    (int)MULTI_ARG_2_QI_TF },
21711   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomtruew",  IX86_BUILTIN_PCOMTRUEW,  PCOM_TRUE,    (int)MULTI_ARG_2_HI_TF },
21712   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomtrued",  IX86_BUILTIN_PCOMTRUED,  PCOM_TRUE,    (int)MULTI_ARG_2_SI_TF },
21713   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomtrueq",  IX86_BUILTIN_PCOMTRUEQ,  PCOM_TRUE,    (int)MULTI_ARG_2_DI_TF },
21714   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv16qi3,     "__builtin_ia32_pcomtrueub", IX86_BUILTIN_PCOMTRUEUB, PCOM_TRUE,    (int)MULTI_ARG_2_QI_TF },
21715   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv8hi3,      "__builtin_ia32_pcomtrueuw", IX86_BUILTIN_PCOMTRUEUW, PCOM_TRUE,    (int)MULTI_ARG_2_HI_TF },
21716   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv4si3,      "__builtin_ia32_pcomtrueud", IX86_BUILTIN_PCOMTRUEUD, PCOM_TRUE,    (int)MULTI_ARG_2_SI_TF },
21717   { OPTION_MASK_ISA_SSE5, CODE_FOR_sse5_pcom_tfv2di3,      "__builtin_ia32_pcomtrueuq", IX86_BUILTIN_PCOMTRUEUQ, PCOM_TRUE,    (int)MULTI_ARG_2_DI_TF },
21718 };
21719
21720 /* Set up all the MMX/SSE builtins, even builtins for instructions that are not
21721    in the current target ISA to allow the user to compile particular modules
21722    with different target specific options that differ from the command line
21723    options.  */
21724 static void
21725 ix86_init_mmx_sse_builtins (void)
21726 {
21727   const struct builtin_description * d;
21728   size_t i;
21729
21730   tree V16QI_type_node = build_vector_type_for_mode (char_type_node, V16QImode);
21731   tree V2SI_type_node = build_vector_type_for_mode (intSI_type_node, V2SImode);
21732   tree V1DI_type_node
21733     = build_vector_type_for_mode (long_long_integer_type_node, V1DImode);
21734   tree V2SF_type_node = build_vector_type_for_mode (float_type_node, V2SFmode);
21735   tree V2DI_type_node
21736     = build_vector_type_for_mode (long_long_integer_type_node, V2DImode);
21737   tree V2DF_type_node = build_vector_type_for_mode (double_type_node, V2DFmode);
21738   tree V4SF_type_node = build_vector_type_for_mode (float_type_node, V4SFmode);
21739   tree V4SI_type_node = build_vector_type_for_mode (intSI_type_node, V4SImode);
21740   tree V4HI_type_node = build_vector_type_for_mode (intHI_type_node, V4HImode);
21741   tree V8QI_type_node = build_vector_type_for_mode (char_type_node, V8QImode);
21742   tree V8HI_type_node = build_vector_type_for_mode (intHI_type_node, V8HImode);
21743
21744   tree pchar_type_node = build_pointer_type (char_type_node);
21745   tree pcchar_type_node
21746     = build_pointer_type (build_type_variant (char_type_node, 1, 0));
21747   tree pfloat_type_node = build_pointer_type (float_type_node);
21748   tree pcfloat_type_node
21749     = build_pointer_type (build_type_variant (float_type_node, 1, 0));
21750   tree pv2sf_type_node = build_pointer_type (V2SF_type_node);
21751   tree pcv2sf_type_node
21752     = build_pointer_type (build_type_variant (V2SF_type_node, 1, 0));
21753   tree pv2di_type_node = build_pointer_type (V2DI_type_node);
21754   tree pdi_type_node = build_pointer_type (long_long_unsigned_type_node);
21755
21756   /* Comparisons.  */
21757   tree int_ftype_v4sf_v4sf
21758     = build_function_type_list (integer_type_node,
21759                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
21760   tree v4si_ftype_v4sf_v4sf
21761     = build_function_type_list (V4SI_type_node,
21762                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
21763   /* MMX/SSE/integer conversions.  */
21764   tree int_ftype_v4sf
21765     = build_function_type_list (integer_type_node,
21766                                 V4SF_type_node, NULL_TREE);
21767   tree int64_ftype_v4sf
21768     = build_function_type_list (long_long_integer_type_node,
21769                                 V4SF_type_node, NULL_TREE);
21770   tree int_ftype_v8qi
21771     = build_function_type_list (integer_type_node, V8QI_type_node, NULL_TREE);
21772   tree v4sf_ftype_v4sf_int
21773     = build_function_type_list (V4SF_type_node,
21774                                 V4SF_type_node, integer_type_node, NULL_TREE);
21775   tree v4sf_ftype_v4sf_int64
21776     = build_function_type_list (V4SF_type_node,
21777                                 V4SF_type_node, long_long_integer_type_node,
21778                                 NULL_TREE);
21779   tree v4sf_ftype_v4sf_v2si
21780     = build_function_type_list (V4SF_type_node,
21781                                 V4SF_type_node, V2SI_type_node, NULL_TREE);
21782
21783   /* Miscellaneous.  */
21784   tree v8qi_ftype_v4hi_v4hi
21785     = build_function_type_list (V8QI_type_node,
21786                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
21787   tree v4hi_ftype_v2si_v2si
21788     = build_function_type_list (V4HI_type_node,
21789                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
21790   tree v4sf_ftype_v4sf_v4sf_int
21791     = build_function_type_list (V4SF_type_node,
21792                                 V4SF_type_node, V4SF_type_node,
21793                                 integer_type_node, NULL_TREE);
21794   tree v2si_ftype_v4hi_v4hi
21795     = build_function_type_list (V2SI_type_node,
21796                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
21797   tree v4hi_ftype_v4hi_int
21798     = build_function_type_list (V4HI_type_node,
21799                                 V4HI_type_node, integer_type_node, NULL_TREE);
21800   tree v2si_ftype_v2si_int
21801     = build_function_type_list (V2SI_type_node,
21802                                 V2SI_type_node, integer_type_node, NULL_TREE);
21803   tree v1di_ftype_v1di_int
21804     = build_function_type_list (V1DI_type_node,
21805                                 V1DI_type_node, integer_type_node, NULL_TREE);
21806
21807   tree void_ftype_void
21808     = build_function_type (void_type_node, void_list_node);
21809   tree void_ftype_unsigned
21810     = build_function_type_list (void_type_node, unsigned_type_node, NULL_TREE);
21811   tree void_ftype_unsigned_unsigned
21812     = build_function_type_list (void_type_node, unsigned_type_node,
21813                                 unsigned_type_node, NULL_TREE);
21814   tree void_ftype_pcvoid_unsigned_unsigned
21815     = build_function_type_list (void_type_node, const_ptr_type_node,
21816                                 unsigned_type_node, unsigned_type_node,
21817                                 NULL_TREE);
21818   tree unsigned_ftype_void
21819     = build_function_type (unsigned_type_node, void_list_node);
21820   tree v2si_ftype_v4sf
21821     = build_function_type_list (V2SI_type_node, V4SF_type_node, NULL_TREE);
21822   /* Loads/stores.  */
21823   tree void_ftype_v8qi_v8qi_pchar
21824     = build_function_type_list (void_type_node,
21825                                 V8QI_type_node, V8QI_type_node,
21826                                 pchar_type_node, NULL_TREE);
21827   tree v4sf_ftype_pcfloat
21828     = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
21829   tree v4sf_ftype_v4sf_pcv2sf
21830     = build_function_type_list (V4SF_type_node,
21831                                 V4SF_type_node, pcv2sf_type_node, NULL_TREE);
21832   tree void_ftype_pv2sf_v4sf
21833     = build_function_type_list (void_type_node,
21834                                 pv2sf_type_node, V4SF_type_node, NULL_TREE);
21835   tree void_ftype_pfloat_v4sf
21836     = build_function_type_list (void_type_node,
21837                                 pfloat_type_node, V4SF_type_node, NULL_TREE);
21838   tree void_ftype_pdi_di
21839     = build_function_type_list (void_type_node,
21840                                 pdi_type_node, long_long_unsigned_type_node,
21841                                 NULL_TREE);
21842   tree void_ftype_pv2di_v2di
21843     = build_function_type_list (void_type_node,
21844                                 pv2di_type_node, V2DI_type_node, NULL_TREE);
21845   /* Normal vector unops.  */
21846   tree v4sf_ftype_v4sf
21847     = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
21848   tree v16qi_ftype_v16qi
21849     = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
21850   tree v8hi_ftype_v8hi
21851     = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
21852   tree v4si_ftype_v4si
21853     = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
21854   tree v8qi_ftype_v8qi
21855     = build_function_type_list (V8QI_type_node, V8QI_type_node, NULL_TREE);
21856   tree v4hi_ftype_v4hi
21857     = build_function_type_list (V4HI_type_node, V4HI_type_node, NULL_TREE);
21858
21859   /* Normal vector binops.  */
21860   tree v4sf_ftype_v4sf_v4sf
21861     = build_function_type_list (V4SF_type_node,
21862                                 V4SF_type_node, V4SF_type_node, NULL_TREE);
21863   tree v8qi_ftype_v8qi_v8qi
21864     = build_function_type_list (V8QI_type_node,
21865                                 V8QI_type_node, V8QI_type_node, NULL_TREE);
21866   tree v4hi_ftype_v4hi_v4hi
21867     = build_function_type_list (V4HI_type_node,
21868                                 V4HI_type_node, V4HI_type_node, NULL_TREE);
21869   tree v2si_ftype_v2si_v2si
21870     = build_function_type_list (V2SI_type_node,
21871                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
21872   tree v1di_ftype_v1di_v1di
21873     = build_function_type_list (V1DI_type_node,
21874                                 V1DI_type_node, V1DI_type_node, NULL_TREE);
21875   tree v1di_ftype_v1di_v1di_int
21876     = build_function_type_list (V1DI_type_node,
21877                                 V1DI_type_node, V1DI_type_node,
21878                                 integer_type_node, NULL_TREE);
21879   tree v2si_ftype_v2sf
21880     = build_function_type_list (V2SI_type_node, V2SF_type_node, NULL_TREE);
21881   tree v2sf_ftype_v2si
21882     = build_function_type_list (V2SF_type_node, V2SI_type_node, NULL_TREE);
21883   tree v2si_ftype_v2si
21884     = build_function_type_list (V2SI_type_node, V2SI_type_node, NULL_TREE);
21885   tree v2sf_ftype_v2sf
21886     = build_function_type_list (V2SF_type_node, V2SF_type_node, NULL_TREE);
21887   tree v2sf_ftype_v2sf_v2sf
21888     = build_function_type_list (V2SF_type_node,
21889                                 V2SF_type_node, V2SF_type_node, NULL_TREE);
21890   tree v2si_ftype_v2sf_v2sf
21891     = build_function_type_list (V2SI_type_node,
21892                                 V2SF_type_node, V2SF_type_node, NULL_TREE);
21893   tree pint_type_node    = build_pointer_type (integer_type_node);
21894   tree pdouble_type_node = build_pointer_type (double_type_node);
21895   tree pcdouble_type_node = build_pointer_type (
21896                                 build_type_variant (double_type_node, 1, 0));
21897   tree int_ftype_v2df_v2df
21898     = build_function_type_list (integer_type_node,
21899                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
21900
21901   tree void_ftype_pcvoid
21902     = build_function_type_list (void_type_node, const_ptr_type_node, NULL_TREE);
21903   tree v4sf_ftype_v4si
21904     = build_function_type_list (V4SF_type_node, V4SI_type_node, NULL_TREE);
21905   tree v4si_ftype_v4sf
21906     = build_function_type_list (V4SI_type_node, V4SF_type_node, NULL_TREE);
21907   tree v2df_ftype_v4si
21908     = build_function_type_list (V2DF_type_node, V4SI_type_node, NULL_TREE);
21909   tree v4si_ftype_v2df
21910     = build_function_type_list (V4SI_type_node, V2DF_type_node, NULL_TREE);
21911   tree v4si_ftype_v2df_v2df
21912     = build_function_type_list (V4SI_type_node,
21913                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
21914   tree v2si_ftype_v2df
21915     = build_function_type_list (V2SI_type_node, V2DF_type_node, NULL_TREE);
21916   tree v4sf_ftype_v2df
21917     = build_function_type_list (V4SF_type_node, V2DF_type_node, NULL_TREE);
21918   tree v2df_ftype_v2si
21919     = build_function_type_list (V2DF_type_node, V2SI_type_node, NULL_TREE);
21920   tree v2df_ftype_v4sf
21921     = build_function_type_list (V2DF_type_node, V4SF_type_node, NULL_TREE);
21922   tree int_ftype_v2df
21923     = build_function_type_list (integer_type_node, V2DF_type_node, NULL_TREE);
21924   tree int64_ftype_v2df
21925     = build_function_type_list (long_long_integer_type_node,
21926                                 V2DF_type_node, NULL_TREE);
21927   tree v2df_ftype_v2df_int
21928     = build_function_type_list (V2DF_type_node,
21929                                 V2DF_type_node, integer_type_node, NULL_TREE);
21930   tree v2df_ftype_v2df_int64
21931     = build_function_type_list (V2DF_type_node,
21932                                 V2DF_type_node, long_long_integer_type_node,
21933                                 NULL_TREE);
21934   tree v4sf_ftype_v4sf_v2df
21935     = build_function_type_list (V4SF_type_node,
21936                                 V4SF_type_node, V2DF_type_node, NULL_TREE);
21937   tree v2df_ftype_v2df_v4sf
21938     = build_function_type_list (V2DF_type_node,
21939                                 V2DF_type_node, V4SF_type_node, NULL_TREE);
21940   tree v2df_ftype_v2df_v2df_int
21941     = build_function_type_list (V2DF_type_node,
21942                                 V2DF_type_node, V2DF_type_node,
21943                                 integer_type_node,
21944                                 NULL_TREE);
21945   tree v2df_ftype_v2df_pcdouble
21946     = build_function_type_list (V2DF_type_node,
21947                                 V2DF_type_node, pcdouble_type_node, NULL_TREE);
21948   tree void_ftype_pdouble_v2df
21949     = build_function_type_list (void_type_node,
21950                                 pdouble_type_node, V2DF_type_node, NULL_TREE);
21951   tree void_ftype_pint_int
21952     = build_function_type_list (void_type_node,
21953                                 pint_type_node, integer_type_node, NULL_TREE);
21954   tree void_ftype_v16qi_v16qi_pchar
21955     = build_function_type_list (void_type_node,
21956                                 V16QI_type_node, V16QI_type_node,
21957                                 pchar_type_node, NULL_TREE);
21958   tree v2df_ftype_pcdouble
21959     = build_function_type_list (V2DF_type_node, pcdouble_type_node, NULL_TREE);
21960   tree v2df_ftype_v2df_v2df
21961     = build_function_type_list (V2DF_type_node,
21962                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
21963   tree v16qi_ftype_v16qi_v16qi
21964     = build_function_type_list (V16QI_type_node,
21965                                 V16QI_type_node, V16QI_type_node, NULL_TREE);
21966   tree v8hi_ftype_v8hi_v8hi
21967     = build_function_type_list (V8HI_type_node,
21968                                 V8HI_type_node, V8HI_type_node, NULL_TREE);
21969   tree v4si_ftype_v4si_v4si
21970     = build_function_type_list (V4SI_type_node,
21971                                 V4SI_type_node, V4SI_type_node, NULL_TREE);
21972   tree v2di_ftype_v2di_v2di
21973     = build_function_type_list (V2DI_type_node,
21974                                 V2DI_type_node, V2DI_type_node, NULL_TREE);
21975   tree v2di_ftype_v2df_v2df
21976     = build_function_type_list (V2DI_type_node,
21977                                 V2DF_type_node, V2DF_type_node, NULL_TREE);
21978   tree v2df_ftype_v2df
21979     = build_function_type_list (V2DF_type_node, V2DF_type_node, NULL_TREE);
21980   tree v2di_ftype_v2di_int
21981     = build_function_type_list (V2DI_type_node,
21982                                 V2DI_type_node, integer_type_node, NULL_TREE);
21983   tree v2di_ftype_v2di_v2di_int
21984     = build_function_type_list (V2DI_type_node, V2DI_type_node,
21985                                 V2DI_type_node, integer_type_node, NULL_TREE);
21986   tree v4si_ftype_v4si_int
21987     = build_function_type_list (V4SI_type_node,
21988                                 V4SI_type_node, integer_type_node, NULL_TREE);
21989   tree v8hi_ftype_v8hi_int
21990     = build_function_type_list (V8HI_type_node,
21991                                 V8HI_type_node, integer_type_node, NULL_TREE);
21992   tree v4si_ftype_v8hi_v8hi
21993     = build_function_type_list (V4SI_type_node,
21994                                 V8HI_type_node, V8HI_type_node, NULL_TREE);
21995   tree v1di_ftype_v8qi_v8qi
21996     = build_function_type_list (V1DI_type_node,
21997                                 V8QI_type_node, V8QI_type_node, NULL_TREE);
21998   tree v1di_ftype_v2si_v2si
21999     = build_function_type_list (V1DI_type_node,
22000                                 V2SI_type_node, V2SI_type_node, NULL_TREE);
22001   tree v2di_ftype_v16qi_v16qi
22002     = build_function_type_list (V2DI_type_node,
22003                                 V16QI_type_node, V16QI_type_node, NULL_TREE);
22004   tree v2di_ftype_v4si_v4si
22005     = build_function_type_list (V2DI_type_node,
22006                                 V4SI_type_node, V4SI_type_node, NULL_TREE);
22007   tree int_ftype_v16qi
22008     = build_function_type_list (integer_type_node, V16QI_type_node, NULL_TREE);
22009   tree v16qi_ftype_pcchar
22010     = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
22011   tree void_ftype_pchar_v16qi
22012     = build_function_type_list (void_type_node,
22013                                 pchar_type_node, V16QI_type_node, NULL_TREE);
22014
22015   tree v2di_ftype_v2di_unsigned_unsigned
22016     = build_function_type_list (V2DI_type_node, V2DI_type_node,
22017                                 unsigned_type_node, unsigned_type_node,
22018                                 NULL_TREE);
22019   tree v2di_ftype_v2di_v2di_unsigned_unsigned
22020     = build_function_type_list (V2DI_type_node, V2DI_type_node, V2DI_type_node,
22021                                 unsigned_type_node, unsigned_type_node,
22022                                 NULL_TREE);
22023   tree v2di_ftype_v2di_v16qi
22024     = build_function_type_list (V2DI_type_node, V2DI_type_node, V16QI_type_node,
22025                                 NULL_TREE);
22026   tree v2df_ftype_v2df_v2df_v2df
22027     = build_function_type_list (V2DF_type_node,
22028                                 V2DF_type_node, V2DF_type_node,
22029                                 V2DF_type_node, NULL_TREE);
22030   tree v4sf_ftype_v4sf_v4sf_v4sf
22031     = build_function_type_list (V4SF_type_node,
22032                                 V4SF_type_node, V4SF_type_node,
22033                                 V4SF_type_node, NULL_TREE);
22034   tree v8hi_ftype_v16qi
22035     = build_function_type_list (V8HI_type_node, V16QI_type_node,
22036                                 NULL_TREE);
22037   tree v4si_ftype_v16qi
22038     = build_function_type_list (V4SI_type_node, V16QI_type_node,
22039                                 NULL_TREE);
22040   tree v2di_ftype_v16qi
22041     = build_function_type_list (V2DI_type_node, V16QI_type_node,
22042                                 NULL_TREE);
22043   tree v4si_ftype_v8hi
22044     = build_function_type_list (V4SI_type_node, V8HI_type_node,
22045                                 NULL_TREE);
22046   tree v2di_ftype_v8hi
22047     = build_function_type_list (V2DI_type_node, V8HI_type_node,
22048                                 NULL_TREE);
22049   tree v2di_ftype_v4si
22050     = build_function_type_list (V2DI_type_node, V4SI_type_node,
22051                                 NULL_TREE);
22052   tree v2di_ftype_pv2di
22053     = build_function_type_list (V2DI_type_node, pv2di_type_node,
22054                                 NULL_TREE);
22055   tree v16qi_ftype_v16qi_v16qi_int
22056     = build_function_type_list (V16QI_type_node, V16QI_type_node,
22057                                 V16QI_type_node, integer_type_node,
22058                                 NULL_TREE);
22059   tree v16qi_ftype_v16qi_v16qi_v16qi
22060     = build_function_type_list (V16QI_type_node, V16QI_type_node,
22061                                 V16QI_type_node, V16QI_type_node,
22062                                 NULL_TREE);
22063   tree v8hi_ftype_v8hi_v8hi_int
22064     = build_function_type_list (V8HI_type_node, V8HI_type_node,
22065                                 V8HI_type_node, integer_type_node,
22066                                 NULL_TREE);
22067   tree v4si_ftype_v4si_v4si_int
22068     = build_function_type_list (V4SI_type_node, V4SI_type_node,
22069                                 V4SI_type_node, integer_type_node,
22070                                 NULL_TREE);
22071   tree int_ftype_v2di_v2di
22072     = build_function_type_list (integer_type_node,
22073                                 V2DI_type_node, V2DI_type_node,
22074                                 NULL_TREE);
22075   tree int_ftype_v16qi_int_v16qi_int_int
22076     = build_function_type_list (integer_type_node,
22077                                 V16QI_type_node,
22078                                 integer_type_node,
22079                                 V16QI_type_node,
22080                                 integer_type_node,
22081                                 integer_type_node,
22082                                 NULL_TREE);
22083   tree v16qi_ftype_v16qi_int_v16qi_int_int
22084     = build_function_type_list (V16QI_type_node,
22085                                 V16QI_type_node,
22086                                 integer_type_node,
22087                                 V16QI_type_node,
22088                                 integer_type_node,
22089                                 integer_type_node,
22090                                 NULL_TREE);
22091   tree int_ftype_v16qi_v16qi_int
22092     = build_function_type_list (integer_type_node,
22093                                 V16QI_type_node,
22094                                 V16QI_type_node,
22095                                 integer_type_node,
22096                                 NULL_TREE);
22097
22098   /* SSE5 instructions */
22099   tree v2di_ftype_v2di_v2di_v2di
22100     = build_function_type_list (V2DI_type_node,
22101                                 V2DI_type_node,
22102                                 V2DI_type_node,
22103                                 V2DI_type_node,
22104                                 NULL_TREE);
22105
22106   tree v4si_ftype_v4si_v4si_v4si
22107     = build_function_type_list (V4SI_type_node,
22108                                 V4SI_type_node,
22109                                 V4SI_type_node,
22110                                 V4SI_type_node,
22111                                 NULL_TREE);
22112
22113   tree v4si_ftype_v4si_v4si_v2di
22114     = build_function_type_list (V4SI_type_node,
22115                                 V4SI_type_node,
22116                                 V4SI_type_node,
22117                                 V2DI_type_node,
22118                                 NULL_TREE);
22119
22120   tree v8hi_ftype_v8hi_v8hi_v8hi
22121     = build_function_type_list (V8HI_type_node,
22122                                 V8HI_type_node,
22123                                 V8HI_type_node,
22124                                 V8HI_type_node,
22125                                 NULL_TREE);
22126
22127   tree v8hi_ftype_v8hi_v8hi_v4si
22128     = build_function_type_list (V8HI_type_node,
22129                                 V8HI_type_node,
22130                                 V8HI_type_node,
22131                                 V4SI_type_node,
22132                                 NULL_TREE);
22133
22134   tree v2df_ftype_v2df_v2df_v16qi
22135     = build_function_type_list (V2DF_type_node,
22136                                 V2DF_type_node,
22137                                 V2DF_type_node,
22138                                 V16QI_type_node,
22139                                 NULL_TREE);
22140
22141   tree v4sf_ftype_v4sf_v4sf_v16qi
22142     = build_function_type_list (V4SF_type_node,
22143                                 V4SF_type_node,
22144                                 V4SF_type_node,
22145                                 V16QI_type_node,
22146                                 NULL_TREE);
22147
22148   tree v2di_ftype_v2di_si
22149     = build_function_type_list (V2DI_type_node,
22150                                 V2DI_type_node,
22151                                 integer_type_node,
22152                                 NULL_TREE);
22153
22154   tree v4si_ftype_v4si_si
22155     = build_function_type_list (V4SI_type_node,
22156                                 V4SI_type_node,
22157                                 integer_type_node,
22158                                 NULL_TREE);
22159
22160   tree v8hi_ftype_v8hi_si
22161     = build_function_type_list (V8HI_type_node,
22162                                 V8HI_type_node,
22163                                 integer_type_node,
22164                                 NULL_TREE);
22165
22166   tree v16qi_ftype_v16qi_si
22167     = build_function_type_list (V16QI_type_node,
22168                                 V16QI_type_node,
22169                                 integer_type_node,
22170                                 NULL_TREE);
22171   tree v4sf_ftype_v4hi
22172     = build_function_type_list (V4SF_type_node,
22173                                 V4HI_type_node,
22174                                 NULL_TREE);
22175
22176   tree v4hi_ftype_v4sf
22177     = build_function_type_list (V4HI_type_node,
22178                                 V4SF_type_node,
22179                                 NULL_TREE);
22180
22181   tree v2di_ftype_v2di
22182     = build_function_type_list (V2DI_type_node, V2DI_type_node, NULL_TREE);
22183
22184   tree v16qi_ftype_v8hi_v8hi
22185     = build_function_type_list (V16QI_type_node,
22186                                 V8HI_type_node, V8HI_type_node,
22187                                 NULL_TREE);
22188   tree v8hi_ftype_v4si_v4si
22189     = build_function_type_list (V8HI_type_node,
22190                                 V4SI_type_node, V4SI_type_node,
22191                                 NULL_TREE);
22192   tree v8hi_ftype_v16qi_v16qi 
22193     = build_function_type_list (V8HI_type_node,
22194                                 V16QI_type_node, V16QI_type_node,
22195                                 NULL_TREE);
22196   tree v4hi_ftype_v8qi_v8qi 
22197     = build_function_type_list (V4HI_type_node,
22198                                 V8QI_type_node, V8QI_type_node,
22199                                 NULL_TREE);
22200   tree unsigned_ftype_unsigned_uchar
22201     = build_function_type_list (unsigned_type_node,
22202                                 unsigned_type_node,
22203                                 unsigned_char_type_node,
22204                                 NULL_TREE);
22205   tree unsigned_ftype_unsigned_ushort
22206     = build_function_type_list (unsigned_type_node,
22207                                 unsigned_type_node,
22208                                 short_unsigned_type_node,
22209                                 NULL_TREE);
22210   tree unsigned_ftype_unsigned_unsigned
22211     = build_function_type_list (unsigned_type_node,
22212                                 unsigned_type_node,
22213                                 unsigned_type_node,
22214                                 NULL_TREE);
22215   tree uint64_ftype_uint64_uint64
22216     = build_function_type_list (long_long_unsigned_type_node,
22217                                 long_long_unsigned_type_node,
22218                                 long_long_unsigned_type_node,
22219                                 NULL_TREE);
22220   tree float_ftype_float
22221     = build_function_type_list (float_type_node,
22222                                 float_type_node,
22223                                 NULL_TREE);
22224
22225   /* AVX builtins  */
22226   tree V32QI_type_node = build_vector_type_for_mode (char_type_node,
22227                                                      V32QImode);
22228   tree V8SI_type_node = build_vector_type_for_mode (intSI_type_node,
22229                                                     V8SImode);
22230   tree V8SF_type_node = build_vector_type_for_mode (float_type_node,
22231                                                     V8SFmode);
22232   tree V4DI_type_node = build_vector_type_for_mode (long_long_integer_type_node,
22233                                                     V4DImode);
22234   tree V4DF_type_node = build_vector_type_for_mode (double_type_node,
22235                                                     V4DFmode);
22236   tree v8sf_ftype_v8sf
22237     = build_function_type_list (V8SF_type_node,
22238                                 V8SF_type_node,
22239                                 NULL_TREE);
22240   tree v8si_ftype_v8sf
22241     = build_function_type_list (V8SI_type_node,
22242                                 V8SF_type_node,
22243                                 NULL_TREE);
22244   tree v8sf_ftype_v8si
22245     = build_function_type_list (V8SF_type_node,
22246                                 V8SI_type_node,
22247                                 NULL_TREE);
22248   tree v4si_ftype_v4df
22249     = build_function_type_list (V4SI_type_node,
22250                                 V4DF_type_node,
22251                                 NULL_TREE);
22252   tree v4df_ftype_v4df
22253     = build_function_type_list (V4DF_type_node,
22254                                 V4DF_type_node,
22255                                 NULL_TREE);
22256   tree v4df_ftype_v4si
22257     = build_function_type_list (V4DF_type_node,
22258                                 V4SI_type_node,
22259                                 NULL_TREE);
22260   tree v4df_ftype_v4sf
22261     = build_function_type_list (V4DF_type_node,
22262                                 V4SF_type_node,
22263                                 NULL_TREE);
22264   tree v4sf_ftype_v4df
22265     = build_function_type_list (V4SF_type_node,
22266                                 V4DF_type_node,
22267                                 NULL_TREE);
22268   tree v8sf_ftype_v8sf_v8sf
22269     = build_function_type_list (V8SF_type_node,
22270                                 V8SF_type_node, V8SF_type_node,
22271                                 NULL_TREE);
22272   tree v4df_ftype_v4df_v4df
22273     = build_function_type_list (V4DF_type_node,
22274                                 V4DF_type_node, V4DF_type_node,
22275                                 NULL_TREE);
22276   tree v8sf_ftype_v8sf_int
22277     = build_function_type_list (V8SF_type_node,
22278                                 V8SF_type_node, integer_type_node,
22279                                 NULL_TREE);
22280   tree v4si_ftype_v8si_int
22281     = build_function_type_list (V4SI_type_node,
22282                                 V8SI_type_node, integer_type_node,
22283                                 NULL_TREE);
22284   tree v4df_ftype_v4df_int
22285     = build_function_type_list (V4DF_type_node,
22286                                 V4DF_type_node, integer_type_node,
22287                                 NULL_TREE);
22288   tree v4sf_ftype_v8sf_int
22289     = build_function_type_list (V4SF_type_node,
22290                                 V8SF_type_node, integer_type_node,
22291                                 NULL_TREE);
22292   tree v2df_ftype_v4df_int
22293     = build_function_type_list (V2DF_type_node,
22294                                 V4DF_type_node, integer_type_node,
22295                                 NULL_TREE);
22296   tree v8sf_ftype_v8sf_v8sf_int
22297     = build_function_type_list (V8SF_type_node,
22298                                 V8SF_type_node, V8SF_type_node,
22299                                 integer_type_node,
22300                                 NULL_TREE);
22301   tree v8sf_ftype_v8sf_v8sf_v8sf
22302     = build_function_type_list (V8SF_type_node,
22303                                 V8SF_type_node, V8SF_type_node,
22304                                 V8SF_type_node,
22305                                 NULL_TREE);
22306   tree v4df_ftype_v4df_v4df_v4df
22307     = build_function_type_list (V4DF_type_node,
22308                                 V4DF_type_node, V4DF_type_node,
22309                                 V4DF_type_node,
22310                                 NULL_TREE);
22311   tree v8si_ftype_v8si_v8si_int
22312     = build_function_type_list (V8SI_type_node,
22313                                 V8SI_type_node, V8SI_type_node,
22314                                 integer_type_node,
22315                                 NULL_TREE);
22316   tree v4df_ftype_v4df_v4df_int
22317     = build_function_type_list (V4DF_type_node,
22318                                 V4DF_type_node, V4DF_type_node,
22319                                 integer_type_node,
22320                                 NULL_TREE);
22321   tree v8sf_ftype_pcfloat
22322     = build_function_type_list (V8SF_type_node,
22323                                 pcfloat_type_node,
22324                                 NULL_TREE);
22325   tree v4df_ftype_pcdouble
22326     = build_function_type_list (V4DF_type_node,
22327                                 pcdouble_type_node,
22328                                 NULL_TREE);
22329   tree pcv4sf_type_node
22330     = build_pointer_type (build_type_variant (V4SF_type_node, 1, 0));
22331   tree pcv2df_type_node
22332     = build_pointer_type (build_type_variant (V2DF_type_node, 1, 0));
22333   tree v8sf_ftype_pcv4sf
22334     = build_function_type_list (V8SF_type_node,
22335                                 pcv4sf_type_node,
22336                                 NULL_TREE);
22337   tree v4df_ftype_pcv2df
22338     = build_function_type_list (V4DF_type_node,
22339                                 pcv2df_type_node,
22340                                 NULL_TREE);
22341   tree v32qi_ftype_pcchar
22342     = build_function_type_list (V32QI_type_node,
22343                                 pcchar_type_node,
22344                                 NULL_TREE);
22345   tree void_ftype_pchar_v32qi
22346     = build_function_type_list (void_type_node,
22347                                 pchar_type_node, V32QI_type_node,
22348                                 NULL_TREE);
22349   tree v8si_ftype_v8si_v4si_int
22350     = build_function_type_list (V8SI_type_node,
22351                                 V8SI_type_node, V4SI_type_node,
22352                                 integer_type_node,
22353                                 NULL_TREE);
22354   tree pv4di_type_node = build_pointer_type (V4DI_type_node);
22355   tree void_ftype_pv4di_v4di
22356     = build_function_type_list (void_type_node,
22357                                 pv4di_type_node, V4DI_type_node,
22358                                 NULL_TREE);
22359   tree v8sf_ftype_v8sf_v4sf_int
22360     = build_function_type_list (V8SF_type_node,
22361                                 V8SF_type_node, V4SF_type_node,
22362                                 integer_type_node,
22363                                 NULL_TREE);
22364   tree v4df_ftype_v4df_v2df_int
22365     = build_function_type_list (V4DF_type_node,
22366                                 V4DF_type_node, V2DF_type_node,
22367                                 integer_type_node,
22368                                 NULL_TREE);
22369   tree void_ftype_pfloat_v8sf
22370     = build_function_type_list (void_type_node,
22371                                 pfloat_type_node, V8SF_type_node,
22372                                 NULL_TREE);
22373   tree void_ftype_pdouble_v4df
22374     = build_function_type_list (void_type_node,
22375                                 pdouble_type_node, V4DF_type_node,
22376                                 NULL_TREE);
22377   tree pv8sf_type_node = build_pointer_type (V8SF_type_node);
22378   tree pv4sf_type_node = build_pointer_type (V4SF_type_node);
22379   tree pv4df_type_node = build_pointer_type (V4DF_type_node);
22380   tree pv2df_type_node = build_pointer_type (V2DF_type_node);
22381   tree pcv8sf_type_node
22382     = build_pointer_type (build_type_variant (V8SF_type_node, 1, 0));
22383   tree pcv4df_type_node
22384     = build_pointer_type (build_type_variant (V4DF_type_node, 1, 0));
22385   tree v8sf_ftype_pcv8sf_v8sf
22386     = build_function_type_list (V8SF_type_node,
22387                                 pcv8sf_type_node, V8SF_type_node,
22388                                 NULL_TREE);
22389   tree v4df_ftype_pcv4df_v4df
22390     = build_function_type_list (V4DF_type_node,
22391                                 pcv4df_type_node, V4DF_type_node,
22392                                 NULL_TREE);
22393   tree v4sf_ftype_pcv4sf_v4sf
22394     = build_function_type_list (V4SF_type_node,
22395                                 pcv4sf_type_node, V4SF_type_node,
22396                                 NULL_TREE);
22397   tree v2df_ftype_pcv2df_v2df
22398     = build_function_type_list (V2DF_type_node,
22399                                 pcv2df_type_node, V2DF_type_node,
22400                                 NULL_TREE);
22401   tree void_ftype_pv8sf_v8sf_v8sf
22402     = build_function_type_list (void_type_node,
22403                                 pv8sf_type_node, V8SF_type_node,
22404                                 V8SF_type_node,
22405                                 NULL_TREE);
22406   tree void_ftype_pv4df_v4df_v4df
22407     = build_function_type_list (void_type_node,
22408                                 pv4df_type_node, V4DF_type_node,
22409                                 V4DF_type_node,
22410                                 NULL_TREE);
22411   tree void_ftype_pv4sf_v4sf_v4sf
22412     = build_function_type_list (void_type_node,
22413                                 pv4sf_type_node, V4SF_type_node,
22414                                 V4SF_type_node,
22415                                 NULL_TREE);
22416   tree void_ftype_pv2df_v2df_v2df
22417     = build_function_type_list (void_type_node,
22418                                 pv2df_type_node, V2DF_type_node,
22419                                 V2DF_type_node,
22420                                 NULL_TREE);
22421   tree v4df_ftype_v2df
22422     = build_function_type_list (V4DF_type_node,
22423                                 V2DF_type_node,
22424                                 NULL_TREE);
22425   tree v8sf_ftype_v4sf
22426     = build_function_type_list (V8SF_type_node,
22427                                 V4SF_type_node,
22428                                 NULL_TREE);
22429   tree v8si_ftype_v4si
22430     = build_function_type_list (V8SI_type_node,
22431                                 V4SI_type_node,
22432                                 NULL_TREE);
22433   tree v2df_ftype_v4df
22434     = build_function_type_list (V2DF_type_node,
22435                                 V4DF_type_node,
22436                                 NULL_TREE);
22437   tree v4sf_ftype_v8sf
22438     = build_function_type_list (V4SF_type_node,
22439                                 V8SF_type_node,
22440                                 NULL_TREE);
22441   tree v4si_ftype_v8si
22442     = build_function_type_list (V4SI_type_node,
22443                                 V8SI_type_node,
22444                                 NULL_TREE);
22445   tree int_ftype_v4df
22446     = build_function_type_list (integer_type_node,
22447                                 V4DF_type_node,
22448                                 NULL_TREE);
22449   tree int_ftype_v8sf
22450     = build_function_type_list (integer_type_node,
22451                                 V8SF_type_node,
22452                                 NULL_TREE);
22453   tree int_ftype_v8sf_v8sf
22454     = build_function_type_list (integer_type_node,
22455                                 V8SF_type_node, V8SF_type_node,
22456                                 NULL_TREE);
22457   tree int_ftype_v4di_v4di
22458     = build_function_type_list (integer_type_node,
22459                                 V4DI_type_node, V4DI_type_node,
22460                                 NULL_TREE);
22461   tree int_ftype_v4df_v4df
22462     = build_function_type_list (integer_type_node,
22463                                 V4DF_type_node, V4DF_type_node,
22464                                 NULL_TREE);
22465   tree v8sf_ftype_v8sf_v8si
22466     = build_function_type_list (V8SF_type_node,
22467                                 V8SF_type_node, V8SI_type_node,
22468                                 NULL_TREE);
22469   tree v4df_ftype_v4df_v4di
22470     = build_function_type_list (V4DF_type_node,
22471                                 V4DF_type_node, V4DI_type_node,
22472                                 NULL_TREE);
22473   tree v4sf_ftype_v4sf_v4si
22474     = build_function_type_list (V4SF_type_node,
22475                                 V4SF_type_node, V4SI_type_node, NULL_TREE);
22476   tree v2df_ftype_v2df_v2di
22477     = build_function_type_list (V2DF_type_node,
22478                                 V2DF_type_node, V2DI_type_node, NULL_TREE);
22479
22480   tree ftype;
22481
22482   /* Add all special builtins with variable number of operands.  */
22483   for (i = 0, d = bdesc_special_args;
22484        i < ARRAY_SIZE (bdesc_special_args);
22485        i++, d++)
22486     {
22487       tree type;
22488
22489       if (d->name == 0)
22490         continue;
22491
22492       switch ((enum ix86_special_builtin_type) d->flag)
22493         {
22494         case VOID_FTYPE_VOID:
22495           type = void_ftype_void;
22496           break;
22497         case V32QI_FTYPE_PCCHAR:
22498           type = v32qi_ftype_pcchar;
22499           break;
22500         case V16QI_FTYPE_PCCHAR:
22501           type = v16qi_ftype_pcchar;
22502           break;
22503         case V8SF_FTYPE_PCV4SF:
22504           type = v8sf_ftype_pcv4sf;
22505           break;
22506         case V8SF_FTYPE_PCFLOAT:
22507           type = v8sf_ftype_pcfloat;
22508           break;
22509         case V4DF_FTYPE_PCV2DF:
22510           type = v4df_ftype_pcv2df;
22511           break;
22512         case V4DF_FTYPE_PCDOUBLE:
22513           type = v4df_ftype_pcdouble;
22514           break;
22515         case V4SF_FTYPE_PCFLOAT:
22516           type = v4sf_ftype_pcfloat;
22517           break;
22518         case V2DI_FTYPE_PV2DI:
22519           type = v2di_ftype_pv2di;
22520           break;
22521         case V2DF_FTYPE_PCDOUBLE:
22522           type = v2df_ftype_pcdouble;
22523           break;
22524         case V8SF_FTYPE_PCV8SF_V8SF:
22525           type = v8sf_ftype_pcv8sf_v8sf;
22526           break;
22527         case V4DF_FTYPE_PCV4DF_V4DF:
22528           type = v4df_ftype_pcv4df_v4df;
22529           break;
22530         case V4SF_FTYPE_V4SF_PCV2SF:
22531           type = v4sf_ftype_v4sf_pcv2sf;
22532           break;
22533         case V4SF_FTYPE_PCV4SF_V4SF:
22534           type = v4sf_ftype_pcv4sf_v4sf;
22535           break;
22536         case V2DF_FTYPE_V2DF_PCDOUBLE:
22537           type = v2df_ftype_v2df_pcdouble;
22538           break;
22539         case V2DF_FTYPE_PCV2DF_V2DF:
22540           type = v2df_ftype_pcv2df_v2df;
22541           break;
22542         case VOID_FTYPE_PV2SF_V4SF:
22543           type = void_ftype_pv2sf_v4sf;
22544           break;
22545         case VOID_FTYPE_PV4DI_V4DI:
22546           type = void_ftype_pv4di_v4di;
22547           break;
22548         case VOID_FTYPE_PV2DI_V2DI:
22549           type = void_ftype_pv2di_v2di;
22550           break;
22551         case VOID_FTYPE_PCHAR_V32QI:
22552           type = void_ftype_pchar_v32qi;
22553           break;
22554         case VOID_FTYPE_PCHAR_V16QI:
22555           type = void_ftype_pchar_v16qi;
22556           break;
22557         case VOID_FTYPE_PFLOAT_V8SF:
22558           type = void_ftype_pfloat_v8sf;
22559           break;
22560         case VOID_FTYPE_PFLOAT_V4SF:
22561           type = void_ftype_pfloat_v4sf;
22562           break;
22563         case VOID_FTYPE_PDOUBLE_V4DF:
22564           type = void_ftype_pdouble_v4df;
22565           break;
22566         case VOID_FTYPE_PDOUBLE_V2DF:
22567           type = void_ftype_pdouble_v2df;
22568           break;
22569         case VOID_FTYPE_PDI_DI:
22570           type = void_ftype_pdi_di;
22571           break;
22572         case VOID_FTYPE_PINT_INT:
22573           type = void_ftype_pint_int;
22574           break;
22575         case VOID_FTYPE_PV8SF_V8SF_V8SF:
22576           type = void_ftype_pv8sf_v8sf_v8sf;
22577           break;
22578         case VOID_FTYPE_PV4DF_V4DF_V4DF:
22579           type = void_ftype_pv4df_v4df_v4df;
22580           break;
22581         case VOID_FTYPE_PV4SF_V4SF_V4SF:
22582           type = void_ftype_pv4sf_v4sf_v4sf;
22583           break;
22584         case VOID_FTYPE_PV2DF_V2DF_V2DF:
22585           type = void_ftype_pv2df_v2df_v2df;
22586           break;
22587         default:
22588           gcc_unreachable ();
22589         }
22590
22591       def_builtin (d->mask, d->name, type, d->code);
22592     }
22593
22594   /* Add all builtins with variable number of operands.  */
22595   for (i = 0, d = bdesc_args;
22596        i < ARRAY_SIZE (bdesc_args);
22597        i++, d++)
22598     {
22599       tree type;
22600
22601       if (d->name == 0)
22602         continue;
22603
22604       switch ((enum ix86_builtin_type) d->flag)
22605         {
22606         case FLOAT_FTYPE_FLOAT:
22607           type = float_ftype_float;
22608           break;
22609         case INT_FTYPE_V8SF_V8SF_PTEST:
22610           type = int_ftype_v8sf_v8sf;
22611           break;
22612         case INT_FTYPE_V4DI_V4DI_PTEST:
22613           type = int_ftype_v4di_v4di;
22614           break;
22615         case INT_FTYPE_V4DF_V4DF_PTEST:
22616           type = int_ftype_v4df_v4df;
22617           break;
22618         case INT_FTYPE_V4SF_V4SF_PTEST:
22619           type = int_ftype_v4sf_v4sf;
22620           break;
22621         case INT_FTYPE_V2DI_V2DI_PTEST:
22622           type = int_ftype_v2di_v2di;
22623           break;
22624         case INT_FTYPE_V2DF_V2DF_PTEST:
22625           type = int_ftype_v2df_v2df;
22626           break;
22627         case INT64_FTYPE_V4SF:
22628           type = int64_ftype_v4sf;
22629           break;
22630         case INT64_FTYPE_V2DF:
22631           type = int64_ftype_v2df;
22632           break;
22633         case INT_FTYPE_V16QI:
22634           type = int_ftype_v16qi;
22635           break;
22636         case INT_FTYPE_V8QI:
22637           type = int_ftype_v8qi;
22638           break;
22639         case INT_FTYPE_V8SF:
22640           type = int_ftype_v8sf;
22641           break;
22642         case INT_FTYPE_V4DF:
22643           type = int_ftype_v4df;
22644           break;
22645         case INT_FTYPE_V4SF:
22646           type = int_ftype_v4sf;
22647           break;
22648         case INT_FTYPE_V2DF:
22649           type = int_ftype_v2df;
22650           break;
22651         case V16QI_FTYPE_V16QI:
22652           type = v16qi_ftype_v16qi;
22653           break;
22654         case V8SI_FTYPE_V8SF:
22655           type = v8si_ftype_v8sf;
22656           break;
22657         case V8SI_FTYPE_V4SI:
22658           type = v8si_ftype_v4si;
22659           break;
22660         case V8HI_FTYPE_V8HI:
22661           type = v8hi_ftype_v8hi;
22662           break;
22663         case V8HI_FTYPE_V16QI:
22664           type = v8hi_ftype_v16qi;
22665           break;
22666         case V8QI_FTYPE_V8QI:
22667           type = v8qi_ftype_v8qi;
22668           break;
22669         case V8SF_FTYPE_V8SF:
22670           type = v8sf_ftype_v8sf;
22671           break;
22672         case V8SF_FTYPE_V8SI:
22673           type = v8sf_ftype_v8si;
22674           break;
22675         case V8SF_FTYPE_V4SF:
22676           type = v8sf_ftype_v4sf;
22677           break;
22678         case V4SI_FTYPE_V4DF:
22679           type = v4si_ftype_v4df;
22680           break;
22681         case V4SI_FTYPE_V4SI:
22682           type = v4si_ftype_v4si;
22683           break;
22684         case V4SI_FTYPE_V16QI:
22685           type = v4si_ftype_v16qi;
22686           break;
22687         case V4SI_FTYPE_V8SI:
22688           type = v4si_ftype_v8si;
22689           break;
22690         case V4SI_FTYPE_V8HI:
22691           type = v4si_ftype_v8hi;
22692           break;
22693         case V4SI_FTYPE_V4SF:
22694           type = v4si_ftype_v4sf;
22695           break;
22696         case V4SI_FTYPE_V2DF:
22697           type = v4si_ftype_v2df;
22698           break;
22699         case V4HI_FTYPE_V4HI:
22700           type = v4hi_ftype_v4hi;
22701           break;
22702         case V4DF_FTYPE_V4DF:
22703           type = v4df_ftype_v4df;
22704           break;
22705         case V4DF_FTYPE_V4SI:
22706           type = v4df_ftype_v4si;
22707           break;
22708         case V4DF_FTYPE_V4SF:
22709           type = v4df_ftype_v4sf;
22710           break;
22711         case V4DF_FTYPE_V2DF:
22712           type = v4df_ftype_v2df;
22713           break;
22714         case V4SF_FTYPE_V4SF:
22715         case V4SF_FTYPE_V4SF_VEC_MERGE:
22716           type = v4sf_ftype_v4sf;
22717           break;
22718         case V4SF_FTYPE_V8SF:
22719           type = v4sf_ftype_v8sf;
22720           break;
22721         case V4SF_FTYPE_V4SI:
22722           type = v4sf_ftype_v4si;
22723           break;
22724         case V4SF_FTYPE_V4DF:
22725           type = v4sf_ftype_v4df;
22726           break;
22727         case V4SF_FTYPE_V2DF:
22728           type = v4sf_ftype_v2df;
22729           break;
22730         case V2DI_FTYPE_V2DI:
22731           type = v2di_ftype_v2di;
22732           break;
22733         case V2DI_FTYPE_V16QI:
22734           type = v2di_ftype_v16qi;
22735           break;
22736         case V2DI_FTYPE_V8HI:
22737           type = v2di_ftype_v8hi;
22738           break;
22739         case V2DI_FTYPE_V4SI:
22740           type = v2di_ftype_v4si;
22741           break;
22742         case V2SI_FTYPE_V2SI:
22743           type = v2si_ftype_v2si;
22744           break;
22745         case V2SI_FTYPE_V4SF:
22746           type = v2si_ftype_v4sf;
22747           break;
22748         case V2SI_FTYPE_V2DF:
22749           type = v2si_ftype_v2df;
22750           break;
22751         case V2SI_FTYPE_V2SF:
22752           type = v2si_ftype_v2sf;
22753           break;
22754         case V2DF_FTYPE_V4DF:
22755           type = v2df_ftype_v4df;
22756           break;
22757         case V2DF_FTYPE_V4SF:
22758           type = v2df_ftype_v4sf;
22759           break;
22760         case V2DF_FTYPE_V2DF:
22761         case V2DF_FTYPE_V2DF_VEC_MERGE:
22762           type = v2df_ftype_v2df;
22763           break;
22764         case V2DF_FTYPE_V2SI:
22765           type = v2df_ftype_v2si;
22766           break;
22767         case V2DF_FTYPE_V4SI:
22768           type = v2df_ftype_v4si;
22769           break;
22770         case V2SF_FTYPE_V2SF:
22771           type = v2sf_ftype_v2sf;
22772           break;
22773         case V2SF_FTYPE_V2SI:
22774           type = v2sf_ftype_v2si;
22775           break;
22776         case V16QI_FTYPE_V16QI_V16QI:
22777           type = v16qi_ftype_v16qi_v16qi;
22778           break;
22779         case V16QI_FTYPE_V8HI_V8HI:
22780           type = v16qi_ftype_v8hi_v8hi;
22781           break;
22782         case V8QI_FTYPE_V8QI_V8QI:
22783           type = v8qi_ftype_v8qi_v8qi;
22784           break;
22785         case V8QI_FTYPE_V4HI_V4HI:
22786           type = v8qi_ftype_v4hi_v4hi;
22787           break;
22788         case V8HI_FTYPE_V8HI_V8HI:
22789         case V8HI_FTYPE_V8HI_V8HI_COUNT:
22790           type = v8hi_ftype_v8hi_v8hi;
22791           break;
22792         case V8HI_FTYPE_V16QI_V16QI:
22793           type = v8hi_ftype_v16qi_v16qi;
22794           break;
22795         case V8HI_FTYPE_V4SI_V4SI:
22796           type = v8hi_ftype_v4si_v4si;
22797           break;
22798         case V8HI_FTYPE_V8HI_SI_COUNT:
22799           type = v8hi_ftype_v8hi_int;
22800           break;
22801         case V8SF_FTYPE_V8SF_V8SF:
22802           type = v8sf_ftype_v8sf_v8sf;
22803           break;
22804         case V8SF_FTYPE_V8SF_V8SI:
22805           type = v8sf_ftype_v8sf_v8si;
22806           break;
22807         case V4SI_FTYPE_V4SI_V4SI:
22808         case V4SI_FTYPE_V4SI_V4SI_COUNT:
22809           type = v4si_ftype_v4si_v4si;
22810           break;
22811         case V4SI_FTYPE_V8HI_V8HI:
22812           type = v4si_ftype_v8hi_v8hi;
22813           break;
22814         case V4SI_FTYPE_V4SF_V4SF:
22815           type = v4si_ftype_v4sf_v4sf;
22816           break;
22817         case V4SI_FTYPE_V2DF_V2DF:
22818           type = v4si_ftype_v2df_v2df;
22819           break;
22820         case V4SI_FTYPE_V4SI_SI_COUNT:
22821           type = v4si_ftype_v4si_int;
22822           break;
22823         case V4HI_FTYPE_V4HI_V4HI:
22824         case V4HI_FTYPE_V4HI_V4HI_COUNT:
22825           type = v4hi_ftype_v4hi_v4hi;
22826           break;
22827         case V4HI_FTYPE_V8QI_V8QI:
22828           type = v4hi_ftype_v8qi_v8qi;
22829           break;
22830         case V4HI_FTYPE_V2SI_V2SI:
22831           type = v4hi_ftype_v2si_v2si;
22832           break;
22833         case V4HI_FTYPE_V4HI_SI_COUNT:
22834           type = v4hi_ftype_v4hi_int;
22835           break;
22836         case V4DF_FTYPE_V4DF_V4DF:
22837           type = v4df_ftype_v4df_v4df;
22838           break;
22839         case V4DF_FTYPE_V4DF_V4DI:
22840           type = v4df_ftype_v4df_v4di;
22841           break;
22842         case V4SF_FTYPE_V4SF_V4SF:
22843         case V4SF_FTYPE_V4SF_V4SF_SWAP:
22844           type = v4sf_ftype_v4sf_v4sf;
22845           break;
22846         case V4SF_FTYPE_V4SF_V4SI:
22847           type = v4sf_ftype_v4sf_v4si;
22848           break;
22849         case V4SF_FTYPE_V4SF_V2SI:
22850           type = v4sf_ftype_v4sf_v2si;
22851           break;
22852         case V4SF_FTYPE_V4SF_V2DF:
22853           type = v4sf_ftype_v4sf_v2df;
22854           break;
22855         case V4SF_FTYPE_V4SF_DI:
22856           type = v4sf_ftype_v4sf_int64;
22857           break;
22858         case V4SF_FTYPE_V4SF_SI:
22859           type = v4sf_ftype_v4sf_int;
22860           break;
22861         case V2DI_FTYPE_V2DI_V2DI:
22862         case V2DI_FTYPE_V2DI_V2DI_COUNT:
22863           type = v2di_ftype_v2di_v2di;
22864           break;
22865         case V2DI_FTYPE_V16QI_V16QI:
22866           type = v2di_ftype_v16qi_v16qi;
22867           break;
22868         case V2DI_FTYPE_V4SI_V4SI:
22869           type = v2di_ftype_v4si_v4si;
22870           break;
22871         case V2DI_FTYPE_V2DI_V16QI:
22872           type = v2di_ftype_v2di_v16qi;
22873           break;
22874         case V2DI_FTYPE_V2DF_V2DF:
22875           type = v2di_ftype_v2df_v2df;
22876           break;
22877         case V2DI_FTYPE_V2DI_SI_COUNT:
22878           type = v2di_ftype_v2di_int;
22879           break;
22880         case V2SI_FTYPE_V2SI_V2SI:
22881         case V2SI_FTYPE_V2SI_V2SI_COUNT:
22882           type = v2si_ftype_v2si_v2si;
22883           break;
22884         case V2SI_FTYPE_V4HI_V4HI:
22885           type = v2si_ftype_v4hi_v4hi;
22886           break;
22887         case V2SI_FTYPE_V2SF_V2SF:
22888           type = v2si_ftype_v2sf_v2sf;
22889           break;
22890         case V2SI_FTYPE_V2SI_SI_COUNT:
22891           type = v2si_ftype_v2si_int;
22892           break;
22893         case V2DF_FTYPE_V2DF_V2DF:
22894         case V2DF_FTYPE_V2DF_V2DF_SWAP:
22895           type = v2df_ftype_v2df_v2df;
22896           break;
22897         case V2DF_FTYPE_V2DF_V4SF:
22898           type = v2df_ftype_v2df_v4sf;
22899           break;
22900         case V2DF_FTYPE_V2DF_V2DI:
22901           type = v2df_ftype_v2df_v2di;
22902           break;
22903         case V2DF_FTYPE_V2DF_DI:
22904           type = v2df_ftype_v2df_int64;
22905           break;
22906         case V2DF_FTYPE_V2DF_SI:
22907           type = v2df_ftype_v2df_int;
22908           break;
22909         case V2SF_FTYPE_V2SF_V2SF:
22910           type = v2sf_ftype_v2sf_v2sf;
22911           break;
22912         case V1DI_FTYPE_V1DI_V1DI:
22913         case V1DI_FTYPE_V1DI_V1DI_COUNT:
22914           type = v1di_ftype_v1di_v1di;
22915           break;
22916         case V1DI_FTYPE_V8QI_V8QI:
22917           type = v1di_ftype_v8qi_v8qi;
22918           break;
22919         case V1DI_FTYPE_V2SI_V2SI:
22920           type = v1di_ftype_v2si_v2si;
22921           break;
22922         case V1DI_FTYPE_V1DI_SI_COUNT:
22923           type = v1di_ftype_v1di_int;
22924           break;
22925         case UINT64_FTYPE_UINT64_UINT64:
22926           type = uint64_ftype_uint64_uint64;
22927           break;
22928         case UINT_FTYPE_UINT_UINT:
22929           type = unsigned_ftype_unsigned_unsigned;
22930           break;
22931         case UINT_FTYPE_UINT_USHORT:
22932           type = unsigned_ftype_unsigned_ushort;
22933           break;
22934         case UINT_FTYPE_UINT_UCHAR:
22935           type = unsigned_ftype_unsigned_uchar;
22936           break;
22937         case V8HI_FTYPE_V8HI_INT:
22938           type = v8hi_ftype_v8hi_int;
22939           break;
22940         case V8SF_FTYPE_V8SF_INT:
22941           type = v8sf_ftype_v8sf_int;
22942           break;
22943         case V4SI_FTYPE_V4SI_INT:
22944           type = v4si_ftype_v4si_int;
22945           break;
22946         case V4SI_FTYPE_V8SI_INT:
22947           type = v4si_ftype_v8si_int;
22948           break;
22949         case V4HI_FTYPE_V4HI_INT:
22950           type = v4hi_ftype_v4hi_int;
22951           break;
22952         case V4DF_FTYPE_V4DF_INT:
22953           type = v4df_ftype_v4df_int;
22954           break;
22955         case V4SF_FTYPE_V4SF_INT:
22956           type = v4sf_ftype_v4sf_int;
22957           break;
22958         case V4SF_FTYPE_V8SF_INT:
22959           type = v4sf_ftype_v8sf_int;
22960           break;
22961         case V2DI_FTYPE_V2DI_INT:
22962         case V2DI2TI_FTYPE_V2DI_INT:
22963           type = v2di_ftype_v2di_int;
22964           break;
22965         case V2DF_FTYPE_V2DF_INT:
22966           type = v2df_ftype_v2df_int;
22967           break;
22968         case V2DF_FTYPE_V4DF_INT:
22969           type = v2df_ftype_v4df_int;
22970           break;
22971         case V16QI_FTYPE_V16QI_V16QI_V16QI:
22972           type = v16qi_ftype_v16qi_v16qi_v16qi;
22973           break;
22974         case V8SF_FTYPE_V8SF_V8SF_V8SF:
22975           type = v8sf_ftype_v8sf_v8sf_v8sf;
22976           break;
22977         case V4DF_FTYPE_V4DF_V4DF_V4DF:
22978           type = v4df_ftype_v4df_v4df_v4df;
22979           break;
22980         case V4SF_FTYPE_V4SF_V4SF_V4SF:
22981           type = v4sf_ftype_v4sf_v4sf_v4sf;
22982           break;
22983         case V2DF_FTYPE_V2DF_V2DF_V2DF:
22984           type = v2df_ftype_v2df_v2df_v2df;
22985           break;
22986         case V16QI_FTYPE_V16QI_V16QI_INT:
22987           type = v16qi_ftype_v16qi_v16qi_int;
22988           break;
22989         case V8SI_FTYPE_V8SI_V8SI_INT:
22990           type = v8si_ftype_v8si_v8si_int;
22991           break;
22992         case V8SI_FTYPE_V8SI_V4SI_INT:
22993           type = v8si_ftype_v8si_v4si_int;
22994           break;
22995         case V8HI_FTYPE_V8HI_V8HI_INT:
22996           type = v8hi_ftype_v8hi_v8hi_int;
22997           break;
22998         case V8SF_FTYPE_V8SF_V8SF_INT:
22999           type = v8sf_ftype_v8sf_v8sf_int;
23000           break;
23001         case V8SF_FTYPE_V8SF_V4SF_INT:
23002           type = v8sf_ftype_v8sf_v4sf_int;
23003           break;
23004         case V4SI_FTYPE_V4SI_V4SI_INT:
23005           type = v4si_ftype_v4si_v4si_int;
23006           break;
23007         case V4DF_FTYPE_V4DF_V4DF_INT:
23008           type = v4df_ftype_v4df_v4df_int;
23009           break;
23010         case V4DF_FTYPE_V4DF_V2DF_INT:
23011           type = v4df_ftype_v4df_v2df_int;
23012           break;
23013         case V4SF_FTYPE_V4SF_V4SF_INT:
23014           type = v4sf_ftype_v4sf_v4sf_int;
23015           break;
23016         case V2DI_FTYPE_V2DI_V2DI_INT:
23017         case V2DI2TI_FTYPE_V2DI_V2DI_INT:
23018           type = v2di_ftype_v2di_v2di_int;
23019           break;
23020         case V2DF_FTYPE_V2DF_V2DF_INT:
23021           type = v2df_ftype_v2df_v2df_int;
23022           break;
23023         case V2DI_FTYPE_V2DI_UINT_UINT:
23024           type = v2di_ftype_v2di_unsigned_unsigned;
23025           break;
23026         case V2DI_FTYPE_V2DI_V2DI_UINT_UINT:
23027           type = v2di_ftype_v2di_v2di_unsigned_unsigned;
23028           break;
23029         case V1DI2DI_FTYPE_V1DI_V1DI_INT:
23030           type = v1di_ftype_v1di_v1di_int;
23031           break;
23032         default:
23033           gcc_unreachable ();
23034         }
23035
23036       def_builtin_const (d->mask, d->name, type, d->code);
23037     }
23038
23039   /* pcmpestr[im] insns.  */
23040   for (i = 0, d = bdesc_pcmpestr;
23041        i < ARRAY_SIZE (bdesc_pcmpestr);
23042        i++, d++)
23043     {
23044       if (d->code == IX86_BUILTIN_PCMPESTRM128)
23045         ftype = v16qi_ftype_v16qi_int_v16qi_int_int;
23046       else
23047         ftype = int_ftype_v16qi_int_v16qi_int_int;
23048       def_builtin_const (d->mask, d->name, ftype, d->code);
23049     }
23050
23051   /* pcmpistr[im] insns.  */
23052   for (i = 0, d = bdesc_pcmpistr;
23053        i < ARRAY_SIZE (bdesc_pcmpistr);
23054        i++, d++)
23055     {
23056       if (d->code == IX86_BUILTIN_PCMPISTRM128)
23057         ftype = v16qi_ftype_v16qi_v16qi_int;
23058       else
23059         ftype = int_ftype_v16qi_v16qi_int;
23060       def_builtin_const (d->mask, d->name, ftype, d->code);
23061     }
23062
23063   /* comi/ucomi insns.  */
23064   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
23065     if (d->mask == OPTION_MASK_ISA_SSE2)
23066       def_builtin_const (d->mask, d->name, int_ftype_v2df_v2df, d->code);
23067     else
23068       def_builtin_const (d->mask, d->name, int_ftype_v4sf_v4sf, d->code);
23069
23070   /* SSE */
23071   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_ldmxcsr", void_ftype_unsigned, IX86_BUILTIN_LDMXCSR);
23072   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_stmxcsr", unsigned_ftype_void, IX86_BUILTIN_STMXCSR);
23073
23074   /* SSE or 3DNow!A */
23075   def_builtin (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_maskmovq", void_ftype_v8qi_v8qi_pchar, IX86_BUILTIN_MASKMOVQ);
23076
23077   /* SSE2 */
23078   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_maskmovdqu", void_ftype_v16qi_v16qi_pchar, IX86_BUILTIN_MASKMOVDQU);
23079
23080   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_clflush", void_ftype_pcvoid, IX86_BUILTIN_CLFLUSH);
23081   x86_mfence = def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_mfence", void_ftype_void, IX86_BUILTIN_MFENCE);
23082
23083   /* SSE3.  */
23084   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_monitor", void_ftype_pcvoid_unsigned_unsigned, IX86_BUILTIN_MONITOR);
23085   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_mwait", void_ftype_unsigned_unsigned, IX86_BUILTIN_MWAIT);
23086
23087   /* AES */
23088   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenc128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESENC128);
23089   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenclast128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESENCLAST128);
23090   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdec128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESDEC128);
23091   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdeclast128", v2di_ftype_v2di_v2di, IX86_BUILTIN_AESDECLAST128);
23092   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesimc128", v2di_ftype_v2di, IX86_BUILTIN_AESIMC128);
23093   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aeskeygenassist128", v2di_ftype_v2di_int, IX86_BUILTIN_AESKEYGENASSIST128);
23094
23095   /* PCLMUL */
23096   def_builtin_const (OPTION_MASK_ISA_PCLMUL, "__builtin_ia32_pclmulqdq128", v2di_ftype_v2di_v2di_int, IX86_BUILTIN_PCLMULQDQ128);
23097
23098   /* AVX */
23099   def_builtin (OPTION_MASK_ISA_AVX, "__builtin_ia32_vzeroupper", void_ftype_void,
23100                TARGET_64BIT ? IX86_BUILTIN_VZEROUPPER_REX64 : IX86_BUILTIN_VZEROUPPER);
23101
23102   /* Access to the vec_init patterns.  */
23103   ftype = build_function_type_list (V2SI_type_node, integer_type_node,
23104                                     integer_type_node, NULL_TREE);
23105   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v2si", ftype, IX86_BUILTIN_VEC_INIT_V2SI);
23106
23107   ftype = build_function_type_list (V4HI_type_node, short_integer_type_node,
23108                                     short_integer_type_node,
23109                                     short_integer_type_node,
23110                                     short_integer_type_node, NULL_TREE);
23111   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v4hi", ftype, IX86_BUILTIN_VEC_INIT_V4HI);
23112
23113   ftype = build_function_type_list (V8QI_type_node, char_type_node,
23114                                     char_type_node, char_type_node,
23115                                     char_type_node, char_type_node,
23116                                     char_type_node, char_type_node,
23117                                     char_type_node, NULL_TREE);
23118   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v8qi", ftype, IX86_BUILTIN_VEC_INIT_V8QI);
23119
23120   /* Access to the vec_extract patterns.  */
23121   ftype = build_function_type_list (double_type_node, V2DF_type_node,
23122                                     integer_type_node, NULL_TREE);
23123   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2df", ftype, IX86_BUILTIN_VEC_EXT_V2DF);
23124
23125   ftype = build_function_type_list (long_long_integer_type_node,
23126                                     V2DI_type_node, integer_type_node,
23127                                     NULL_TREE);
23128   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2di", ftype, IX86_BUILTIN_VEC_EXT_V2DI);
23129
23130   ftype = build_function_type_list (float_type_node, V4SF_type_node,
23131                                     integer_type_node, NULL_TREE);
23132   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_vec_ext_v4sf", ftype, IX86_BUILTIN_VEC_EXT_V4SF);
23133
23134   ftype = build_function_type_list (intSI_type_node, V4SI_type_node,
23135                                     integer_type_node, NULL_TREE);
23136   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v4si", ftype, IX86_BUILTIN_VEC_EXT_V4SI);
23137
23138   ftype = build_function_type_list (intHI_type_node, V8HI_type_node,
23139                                     integer_type_node, NULL_TREE);
23140   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v8hi", ftype, IX86_BUILTIN_VEC_EXT_V8HI);
23141
23142   ftype = build_function_type_list (intHI_type_node, V4HI_type_node,
23143                                     integer_type_node, NULL_TREE);
23144   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_vec_ext_v4hi", ftype, IX86_BUILTIN_VEC_EXT_V4HI);
23145
23146   ftype = build_function_type_list (intSI_type_node, V2SI_type_node,
23147                                     integer_type_node, NULL_TREE);
23148   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_ext_v2si", ftype, IX86_BUILTIN_VEC_EXT_V2SI);
23149
23150   ftype = build_function_type_list (intQI_type_node, V16QI_type_node,
23151                                     integer_type_node, NULL_TREE);
23152   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v16qi", ftype, IX86_BUILTIN_VEC_EXT_V16QI);
23153
23154   /* Access to the vec_set patterns.  */
23155   ftype = build_function_type_list (V2DI_type_node, V2DI_type_node,
23156                                     intDI_type_node,
23157                                     integer_type_node, NULL_TREE);
23158   def_builtin_const (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_64BIT, "__builtin_ia32_vec_set_v2di", ftype, IX86_BUILTIN_VEC_SET_V2DI);
23159
23160   ftype = build_function_type_list (V4SF_type_node, V4SF_type_node,
23161                                     float_type_node,
23162                                     integer_type_node, NULL_TREE);
23163   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4sf", ftype, IX86_BUILTIN_VEC_SET_V4SF);
23164
23165   ftype = build_function_type_list (V4SI_type_node, V4SI_type_node,
23166                                     intSI_type_node,
23167                                     integer_type_node, NULL_TREE);
23168   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4si", ftype, IX86_BUILTIN_VEC_SET_V4SI);
23169
23170   ftype = build_function_type_list (V8HI_type_node, V8HI_type_node,
23171                                     intHI_type_node,
23172                                     integer_type_node, NULL_TREE);
23173   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_set_v8hi", ftype, IX86_BUILTIN_VEC_SET_V8HI);
23174
23175   ftype = build_function_type_list (V4HI_type_node, V4HI_type_node,
23176                                     intHI_type_node,
23177                                     integer_type_node, NULL_TREE);
23178   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, "__builtin_ia32_vec_set_v4hi", ftype, IX86_BUILTIN_VEC_SET_V4HI);
23179
23180   ftype = build_function_type_list (V16QI_type_node, V16QI_type_node,
23181                                     intQI_type_node,
23182                                     integer_type_node, NULL_TREE);
23183   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v16qi", ftype, IX86_BUILTIN_VEC_SET_V16QI);
23184
23185   /* Add SSE5 multi-arg argument instructions */
23186   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
23187     {
23188       tree mtype = NULL_TREE;
23189
23190       if (d->name == 0)
23191         continue;
23192
23193       switch ((enum multi_arg_type)d->flag)
23194         {
23195         case MULTI_ARG_3_SF:     mtype = v4sf_ftype_v4sf_v4sf_v4sf;     break;
23196         case MULTI_ARG_3_DF:     mtype = v2df_ftype_v2df_v2df_v2df;     break;
23197         case MULTI_ARG_3_DI:     mtype = v2di_ftype_v2di_v2di_v2di;     break;
23198         case MULTI_ARG_3_SI:     mtype = v4si_ftype_v4si_v4si_v4si;     break;
23199         case MULTI_ARG_3_SI_DI:  mtype = v4si_ftype_v4si_v4si_v2di;     break;
23200         case MULTI_ARG_3_HI:     mtype = v8hi_ftype_v8hi_v8hi_v8hi;     break;
23201         case MULTI_ARG_3_HI_SI:  mtype = v8hi_ftype_v8hi_v8hi_v4si;     break;
23202         case MULTI_ARG_3_QI:     mtype = v16qi_ftype_v16qi_v16qi_v16qi; break;
23203         case MULTI_ARG_3_PERMPS: mtype = v4sf_ftype_v4sf_v4sf_v16qi;    break;
23204         case MULTI_ARG_3_PERMPD: mtype = v2df_ftype_v2df_v2df_v16qi;    break;
23205         case MULTI_ARG_2_SF:     mtype = v4sf_ftype_v4sf_v4sf;          break;
23206         case MULTI_ARG_2_DF:     mtype = v2df_ftype_v2df_v2df;          break;
23207         case MULTI_ARG_2_DI:     mtype = v2di_ftype_v2di_v2di;          break;
23208         case MULTI_ARG_2_SI:     mtype = v4si_ftype_v4si_v4si;          break;
23209         case MULTI_ARG_2_HI:     mtype = v8hi_ftype_v8hi_v8hi;          break;
23210         case MULTI_ARG_2_QI:     mtype = v16qi_ftype_v16qi_v16qi;       break;
23211         case MULTI_ARG_2_DI_IMM: mtype = v2di_ftype_v2di_si;            break;
23212         case MULTI_ARG_2_SI_IMM: mtype = v4si_ftype_v4si_si;            break;
23213         case MULTI_ARG_2_HI_IMM: mtype = v8hi_ftype_v8hi_si;            break;
23214         case MULTI_ARG_2_QI_IMM: mtype = v16qi_ftype_v16qi_si;          break;
23215         case MULTI_ARG_2_SF_CMP: mtype = v4sf_ftype_v4sf_v4sf;          break;
23216         case MULTI_ARG_2_DF_CMP: mtype = v2df_ftype_v2df_v2df;          break;
23217         case MULTI_ARG_2_DI_CMP: mtype = v2di_ftype_v2di_v2di;          break;
23218         case MULTI_ARG_2_SI_CMP: mtype = v4si_ftype_v4si_v4si;          break;
23219         case MULTI_ARG_2_HI_CMP: mtype = v8hi_ftype_v8hi_v8hi;          break;
23220         case MULTI_ARG_2_QI_CMP: mtype = v16qi_ftype_v16qi_v16qi;       break;
23221         case MULTI_ARG_2_SF_TF:  mtype = v4sf_ftype_v4sf_v4sf;          break;
23222         case MULTI_ARG_2_DF_TF:  mtype = v2df_ftype_v2df_v2df;          break;
23223         case MULTI_ARG_2_DI_TF:  mtype = v2di_ftype_v2di_v2di;          break;
23224         case MULTI_ARG_2_SI_TF:  mtype = v4si_ftype_v4si_v4si;          break;
23225         case MULTI_ARG_2_HI_TF:  mtype = v8hi_ftype_v8hi_v8hi;          break;
23226         case MULTI_ARG_2_QI_TF:  mtype = v16qi_ftype_v16qi_v16qi;       break;
23227         case MULTI_ARG_1_SF:     mtype = v4sf_ftype_v4sf;               break;
23228         case MULTI_ARG_1_DF:     mtype = v2df_ftype_v2df;               break;
23229         case MULTI_ARG_1_DI:     mtype = v2di_ftype_v2di;               break;
23230         case MULTI_ARG_1_SI:     mtype = v4si_ftype_v4si;               break;
23231         case MULTI_ARG_1_HI:     mtype = v8hi_ftype_v8hi;               break;
23232         case MULTI_ARG_1_QI:     mtype = v16qi_ftype_v16qi;             break;
23233         case MULTI_ARG_1_SI_DI:  mtype = v2di_ftype_v4si;               break;
23234         case MULTI_ARG_1_HI_DI:  mtype = v2di_ftype_v8hi;               break;
23235         case MULTI_ARG_1_HI_SI:  mtype = v4si_ftype_v8hi;               break;
23236         case MULTI_ARG_1_QI_DI:  mtype = v2di_ftype_v16qi;              break;
23237         case MULTI_ARG_1_QI_SI:  mtype = v4si_ftype_v16qi;              break;
23238         case MULTI_ARG_1_QI_HI:  mtype = v8hi_ftype_v16qi;              break;
23239         case MULTI_ARG_1_PH2PS:  mtype = v4sf_ftype_v4hi;               break;
23240         case MULTI_ARG_1_PS2PH:  mtype = v4hi_ftype_v4sf;               break;
23241         case MULTI_ARG_UNKNOWN:
23242         default:
23243           gcc_unreachable ();
23244         }
23245
23246       if (mtype)
23247         def_builtin_const (d->mask, d->name, mtype, d->code);
23248     }
23249 }
23250
23251 /* Internal method for ix86_init_builtins.  */
23252
23253 static void
23254 ix86_init_builtins_va_builtins_abi (void)
23255 {
23256   tree ms_va_ref, sysv_va_ref;
23257   tree fnvoid_va_end_ms, fnvoid_va_end_sysv;
23258   tree fnvoid_va_start_ms, fnvoid_va_start_sysv;
23259   tree fnvoid_va_copy_ms, fnvoid_va_copy_sysv;
23260   tree fnattr_ms = NULL_TREE, fnattr_sysv = NULL_TREE;
23261
23262   if (!TARGET_64BIT)
23263     return;
23264   fnattr_ms = build_tree_list (get_identifier ("ms_abi"), NULL_TREE);
23265   fnattr_sysv = build_tree_list (get_identifier ("sysv_abi"), NULL_TREE);
23266   ms_va_ref = build_reference_type (ms_va_list_type_node);
23267   sysv_va_ref =
23268     build_pointer_type (TREE_TYPE (sysv_va_list_type_node));
23269
23270   fnvoid_va_end_ms =
23271     build_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
23272   fnvoid_va_start_ms =
23273     build_varargs_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
23274   fnvoid_va_end_sysv =
23275     build_function_type_list (void_type_node, sysv_va_ref, NULL_TREE);
23276   fnvoid_va_start_sysv =
23277     build_varargs_function_type_list (void_type_node, sysv_va_ref,
23278                                        NULL_TREE);
23279   fnvoid_va_copy_ms =
23280     build_function_type_list (void_type_node, ms_va_ref, ms_va_list_type_node,
23281                               NULL_TREE);
23282   fnvoid_va_copy_sysv =
23283     build_function_type_list (void_type_node, sysv_va_ref,
23284                               sysv_va_ref, NULL_TREE);
23285
23286   add_builtin_function ("__builtin_ms_va_start", fnvoid_va_start_ms,
23287                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_ms);
23288   add_builtin_function ("__builtin_ms_va_end", fnvoid_va_end_ms,
23289                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_ms);
23290   add_builtin_function ("__builtin_ms_va_copy", fnvoid_va_copy_ms,
23291                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_ms);
23292   add_builtin_function ("__builtin_sysv_va_start", fnvoid_va_start_sysv,
23293                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_sysv);
23294   add_builtin_function ("__builtin_sysv_va_end", fnvoid_va_end_sysv,
23295                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_sysv);
23296   add_builtin_function ("__builtin_sysv_va_copy", fnvoid_va_copy_sysv,
23297                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_sysv);
23298 }
23299
23300 static void
23301 ix86_init_builtins (void)
23302 {
23303   tree float128_type_node = make_node (REAL_TYPE);
23304   tree ftype, decl;
23305
23306   /* The __float80 type.  */
23307   if (TYPE_MODE (long_double_type_node) == XFmode)
23308     (*lang_hooks.types.register_builtin_type) (long_double_type_node,
23309                                                "__float80");
23310   else
23311     {
23312       /* The __float80 type.  */
23313       tree float80_type_node = make_node (REAL_TYPE);
23314
23315       TYPE_PRECISION (float80_type_node) = 80;
23316       layout_type (float80_type_node);
23317       (*lang_hooks.types.register_builtin_type) (float80_type_node,
23318                                                  "__float80");
23319     }
23320
23321   /* The __float128 type.  */
23322   TYPE_PRECISION (float128_type_node) = 128;
23323   layout_type (float128_type_node);
23324   (*lang_hooks.types.register_builtin_type) (float128_type_node,
23325                                              "__float128");
23326
23327   /* TFmode support builtins.  */
23328   ftype = build_function_type (float128_type_node, void_list_node);
23329   decl = add_builtin_function ("__builtin_infq", ftype,
23330                                IX86_BUILTIN_INFQ, BUILT_IN_MD,
23331                                NULL, NULL_TREE);
23332   ix86_builtins[(int) IX86_BUILTIN_INFQ] = decl;
23333
23334   /* We will expand them to normal call if SSE2 isn't available since
23335      they are used by libgcc. */
23336   ftype = build_function_type_list (float128_type_node,
23337                                     float128_type_node,
23338                                     NULL_TREE);
23339   decl = add_builtin_function ("__builtin_fabsq", ftype,
23340                                IX86_BUILTIN_FABSQ, BUILT_IN_MD,
23341                                "__fabstf2", NULL_TREE);
23342   ix86_builtins[(int) IX86_BUILTIN_FABSQ] = decl;
23343   TREE_READONLY (decl) = 1;
23344
23345   ftype = build_function_type_list (float128_type_node,
23346                                     float128_type_node,
23347                                     float128_type_node,
23348                                     NULL_TREE);
23349   decl = add_builtin_function ("__builtin_copysignq", ftype,
23350                                IX86_BUILTIN_COPYSIGNQ, BUILT_IN_MD,
23351                                "__copysigntf3", NULL_TREE);
23352   ix86_builtins[(int) IX86_BUILTIN_COPYSIGNQ] = decl;
23353   TREE_READONLY (decl) = 1;
23354
23355   ix86_init_mmx_sse_builtins ();
23356   if (TARGET_64BIT)
23357     ix86_init_builtins_va_builtins_abi ();
23358 }
23359
23360 /* Errors in the source file can cause expand_expr to return const0_rtx
23361    where we expect a vector.  To avoid crashing, use one of the vector
23362    clear instructions.  */
23363 static rtx
23364 safe_vector_operand (rtx x, enum machine_mode mode)
23365 {
23366   if (x == const0_rtx)
23367     x = CONST0_RTX (mode);
23368   return x;
23369 }
23370
23371 /* Subroutine of ix86_expand_builtin to take care of binop insns.  */
23372
23373 static rtx
23374 ix86_expand_binop_builtin (enum insn_code icode, tree exp, rtx target)
23375 {
23376   rtx pat;
23377   tree arg0 = CALL_EXPR_ARG (exp, 0);
23378   tree arg1 = CALL_EXPR_ARG (exp, 1);
23379   rtx op0 = expand_normal (arg0);
23380   rtx op1 = expand_normal (arg1);
23381   enum machine_mode tmode = insn_data[icode].operand[0].mode;
23382   enum machine_mode mode0 = insn_data[icode].operand[1].mode;
23383   enum machine_mode mode1 = insn_data[icode].operand[2].mode;
23384
23385   if (VECTOR_MODE_P (mode0))
23386     op0 = safe_vector_operand (op0, mode0);
23387   if (VECTOR_MODE_P (mode1))
23388     op1 = safe_vector_operand (op1, mode1);
23389
23390   if (optimize || !target
23391       || GET_MODE (target) != tmode
23392       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
23393     target = gen_reg_rtx (tmode);
23394
23395   if (GET_MODE (op1) == SImode && mode1 == TImode)
23396     {
23397       rtx x = gen_reg_rtx (V4SImode);
23398       emit_insn (gen_sse2_loadd (x, op1));
23399       op1 = gen_lowpart (TImode, x);
23400     }
23401
23402   if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
23403     op0 = copy_to_mode_reg (mode0, op0);
23404   if (!(*insn_data[icode].operand[2].predicate) (op1, mode1))
23405     op1 = copy_to_mode_reg (mode1, op1);
23406
23407   pat = GEN_FCN (icode) (target, op0, op1);
23408   if (! pat)
23409     return 0;
23410
23411   emit_insn (pat);
23412
23413   return target;
23414 }
23415
23416 /* Subroutine of ix86_expand_builtin to take care of 2-4 argument insns.  */
23417
23418 static rtx
23419 ix86_expand_multi_arg_builtin (enum insn_code icode, tree exp, rtx target,
23420                                enum multi_arg_type m_type,
23421                                enum insn_code sub_code)
23422 {
23423   rtx pat;
23424   int i;
23425   int nargs;
23426   bool comparison_p = false;
23427   bool tf_p = false;
23428   bool last_arg_constant = false;
23429   int num_memory = 0;
23430   struct {
23431     rtx op;
23432     enum machine_mode mode;
23433   } args[4];
23434
23435   enum machine_mode tmode = insn_data[icode].operand[0].mode;
23436
23437   switch (m_type)
23438     {
23439     case MULTI_ARG_3_SF:
23440     case MULTI_ARG_3_DF:
23441     case MULTI_ARG_3_DI:
23442     case MULTI_ARG_3_SI:
23443     case MULTI_ARG_3_SI_DI:
23444     case MULTI_ARG_3_HI:
23445     case MULTI_ARG_3_HI_SI:
23446     case MULTI_ARG_3_QI:
23447     case MULTI_ARG_3_PERMPS:
23448     case MULTI_ARG_3_PERMPD:
23449       nargs = 3;
23450       break;
23451
23452     case MULTI_ARG_2_SF:
23453     case MULTI_ARG_2_DF:
23454     case MULTI_ARG_2_DI:
23455     case MULTI_ARG_2_SI:
23456     case MULTI_ARG_2_HI:
23457     case MULTI_ARG_2_QI:
23458       nargs = 2;
23459       break;
23460
23461     case MULTI_ARG_2_DI_IMM:
23462     case MULTI_ARG_2_SI_IMM:
23463     case MULTI_ARG_2_HI_IMM:
23464     case MULTI_ARG_2_QI_IMM:
23465       nargs = 2;
23466       last_arg_constant = true;
23467       break;
23468
23469     case MULTI_ARG_1_SF:
23470     case MULTI_ARG_1_DF:
23471     case MULTI_ARG_1_DI:
23472     case MULTI_ARG_1_SI:
23473     case MULTI_ARG_1_HI:
23474     case MULTI_ARG_1_QI:
23475     case MULTI_ARG_1_SI_DI:
23476     case MULTI_ARG_1_HI_DI:
23477     case MULTI_ARG_1_HI_SI:
23478     case MULTI_ARG_1_QI_DI:
23479     case MULTI_ARG_1_QI_SI:
23480     case MULTI_ARG_1_QI_HI:
23481     case MULTI_ARG_1_PH2PS:
23482     case MULTI_ARG_1_PS2PH:
23483       nargs = 1;
23484       break;
23485
23486     case MULTI_ARG_2_SF_CMP:
23487     case MULTI_ARG_2_DF_CMP:
23488     case MULTI_ARG_2_DI_CMP:
23489     case MULTI_ARG_2_SI_CMP:
23490     case MULTI_ARG_2_HI_CMP:
23491     case MULTI_ARG_2_QI_CMP:
23492       nargs = 2;
23493       comparison_p = true;
23494       break;
23495
23496     case MULTI_ARG_2_SF_TF:
23497     case MULTI_ARG_2_DF_TF:
23498     case MULTI_ARG_2_DI_TF:
23499     case MULTI_ARG_2_SI_TF:
23500     case MULTI_ARG_2_HI_TF:
23501     case MULTI_ARG_2_QI_TF:
23502       nargs = 2;
23503       tf_p = true;
23504       break;
23505
23506     case MULTI_ARG_UNKNOWN:
23507     default:
23508       gcc_unreachable ();
23509     }
23510
23511   if (optimize || !target
23512       || GET_MODE (target) != tmode
23513       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
23514     target = gen_reg_rtx (tmode);
23515
23516   gcc_assert (nargs <= 4);
23517
23518   for (i = 0; i < nargs; i++)
23519     {
23520       tree arg = CALL_EXPR_ARG (exp, i);
23521       rtx op = expand_normal (arg);
23522       int adjust = (comparison_p) ? 1 : 0;
23523       enum machine_mode mode = insn_data[icode].operand[i+adjust+1].mode;
23524
23525       if (last_arg_constant && i == nargs-1)
23526         {
23527           if (GET_CODE (op) != CONST_INT)
23528             {
23529               error ("last argument must be an immediate");
23530               return gen_reg_rtx (tmode);
23531             }
23532         }
23533       else
23534         {
23535           if (VECTOR_MODE_P (mode))
23536             op = safe_vector_operand (op, mode);
23537
23538           /* If we aren't optimizing, only allow one memory operand to be
23539              generated.  */
23540           if (memory_operand (op, mode))
23541             num_memory++;
23542
23543           gcc_assert (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode);
23544
23545           if (optimize
23546               || ! (*insn_data[icode].operand[i+adjust+1].predicate) (op, mode)
23547               || num_memory > 1)
23548             op = force_reg (mode, op);
23549         }
23550
23551       args[i].op = op;
23552       args[i].mode = mode;
23553     }
23554
23555   switch (nargs)
23556     {
23557     case 1:
23558       pat = GEN_FCN (icode) (target, args[0].op);
23559       break;
23560
23561     case 2:
23562       if (tf_p)
23563         pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
23564                                GEN_INT ((int)sub_code));
23565       else if (! comparison_p)
23566         pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
23567       else
23568         {
23569           rtx cmp_op = gen_rtx_fmt_ee (sub_code, GET_MODE (target),
23570                                        args[0].op,
23571                                        args[1].op);
23572
23573           pat = GEN_FCN (icode) (target, cmp_op, args[0].op, args[1].op);
23574         }
23575       break;
23576
23577     case 3:
23578       pat = GEN_FCN (icode) (target, args[0].op, args[1].op, args[2].op);
23579       break;
23580
23581     default:
23582       gcc_unreachable ();
23583     }
23584
23585   if (! pat)
23586     return 0;
23587
23588   emit_insn (pat);
23589   return target;
23590 }
23591
23592 /* Subroutine of ix86_expand_args_builtin to take care of scalar unop
23593    insns with vec_merge.  */
23594
23595 static rtx
23596 ix86_expand_unop_vec_merge_builtin (enum insn_code icode, tree exp,
23597                                     rtx target)
23598 {
23599   rtx pat;
23600   tree arg0 = CALL_EXPR_ARG (exp, 0);
23601   rtx op1, op0 = expand_normal (arg0);
23602   enum machine_mode tmode = insn_data[icode].operand[0].mode;
23603   enum machine_mode mode0 = insn_data[icode].operand[1].mode;
23604
23605   if (optimize || !target
23606       || GET_MODE (target) != tmode
23607       || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
23608     target = gen_reg_rtx (tmode);
23609
23610   if (VECTOR_MODE_P (mode0))
23611     op0 = safe_vector_operand (op0, mode0);
23612
23613   if ((optimize && !register_operand (op0, mode0))
23614       || ! (*insn_data[icode].operand[1].predicate) (op0, mode0))
23615     op0 = copy_to_mode_reg (mode0, op0);
23616
23617   op1 = op0;
23618   if (! (*insn_data[icode].operand[2].predicate) (op1, mode0))
23619     op1 = copy_to_mode_reg (mode0, op1);
23620
23621   pat = GEN_FCN (icode) (target, op0, op1);
23622   if (! pat)
23623     return 0;
23624   emit_insn (pat);
23625   return target;
23626 }
23627
23628 /* Subroutine of ix86_expand_builtin to take care of comparison insns.  */
23629
23630 static rtx
23631 ix86_expand_sse_compare (const struct builtin_description *d,
23632                          tree exp, rtx target, bool swap)
23633 {
23634   rtx pat;
23635   tree arg0 = CALL_EXPR_ARG (exp, 0);
23636   tree arg1 = CALL_EXPR_ARG (exp, 1);
23637   rtx op0 = expand_normal (arg0);
23638   rtx op1 = expand_normal (arg1);
23639   rtx op2;
23640   enum machine_mode tmode = insn_data[d->icode].operand[0].mode;
23641   enum machine_mode mode0 = insn_data[d->icode].operand[1].mode;
23642   enum machine_mode mode1 = insn_data[d->icode].operand[2].mode;
23643   enum rtx_code comparison = d->comparison;
23644
23645   if (VECTOR_MODE_P (mode0))
23646     op0 = safe_vector_operand (op0, mode0);
23647   if (VECTOR_MODE_P (mode1))
23648     op1 = safe_vector_operand (op1, mode1);
23649
23650   /* Swap operands if we have a comparison that isn't available in
23651      hardware.  */
23652   if (swap)
23653     {
23654       rtx tmp = gen_reg_rtx (mode1);
23655       emit_move_insn (tmp, op1);
23656       op1 = op0;
23657       op0 = tmp;
23658     }
23659
23660   if (optimize || !target
23661       || GET_MODE (target) != tmode
23662       || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode))
23663     target = gen_reg_rtx (tmode);
23664
23665   if ((optimize && !register_operand (op0, mode0))
23666       || ! (*insn_data[d->icode].operand[1].predicate) (op0, mode0))
23667     op0 = copy_to_mode_reg (mode0, op0);
23668   if ((optimize && !register_operand (op1, mode1))
23669       || ! (*insn_data[d->icode].operand[2].predicate) (op1, mode1))
23670     op1 = copy_to_mode_reg (mode1, op1);
23671
23672   op2 = gen_rtx_fmt_ee (comparison, mode0, op0, op1);
23673   pat = GEN_FCN (d->icode) (target, op0, op1, op2);
23674   if (! pat)
23675     return 0;
23676   emit_insn (pat);
23677   return target;
23678 }
23679
23680 /* Subroutine of ix86_expand_builtin to take care of comi insns.  */
23681
23682 static rtx
23683 ix86_expand_sse_comi (const struct builtin_description *d, tree exp,
23684                       rtx target)
23685 {
23686   rtx pat;
23687   tree arg0 = CALL_EXPR_ARG (exp, 0);
23688   tree arg1 = CALL_EXPR_ARG (exp, 1);
23689   rtx op0 = expand_normal (arg0);
23690   rtx op1 = expand_normal (arg1);
23691   enum machine_mode mode0 = insn_data[d->icode].operand[0].mode;
23692   enum machine_mode mode1 = insn_data[d->icode].operand[1].mode;
23693   enum rtx_code comparison = d->comparison;
23694
23695   if (VECTOR_MODE_P (mode0))
23696     op0 = safe_vector_operand (op0, mode0);
23697   if (VECTOR_MODE_P (mode1))
23698     op1 = safe_vector_operand (op1, mode1);
23699
23700   /* Swap operands if we have a comparison that isn't available in
23701      hardware.  */
23702   if (d->flag & BUILTIN_DESC_SWAP_OPERANDS)
23703     {
23704       rtx tmp = op1;
23705       op1 = op0;
23706       op0 = tmp;
23707     }
23708
23709   target = gen_reg_rtx (SImode);
23710   emit_move_insn (target, const0_rtx);
23711   target = gen_rtx_SUBREG (QImode, target, 0);
23712
23713   if ((optimize && !register_operand (op0, mode0))
23714       || !(*insn_data[d->icode].operand[0].predicate) (op0, mode0))
23715     op0 = copy_to_mode_reg (mode0, op0);
23716   if ((optimize && !register_operand (op1, mode1))
23717       || !(*insn_data[d->icode].operand[1].predicate) (op1, mode1))
23718     op1 = copy_to_mode_reg (mode1, op1);
23719
23720   pat = GEN_FCN (d->icode) (op0, op1);
23721   if (! pat)
23722     return 0;
23723   emit_insn (pat);
23724   emit_insn (gen_rtx_SET (VOIDmode,
23725                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
23726                           gen_rtx_fmt_ee (comparison, QImode,
23727                                           SET_DEST (pat),
23728                                           const0_rtx)));
23729
23730   return SUBREG_REG (target);
23731 }
23732
23733 /* Subroutine of ix86_expand_builtin to take care of ptest insns.  */
23734
23735 static rtx
23736 ix86_expand_sse_ptest (const struct builtin_description *d, tree exp,
23737                        rtx target)
23738 {
23739   rtx pat;
23740   tree arg0 = CALL_EXPR_ARG (exp, 0);
23741   tree arg1 = CALL_EXPR_ARG (exp, 1);
23742   rtx op0 = expand_normal (arg0);
23743   rtx op1 = expand_normal (arg1);
23744   enum machine_mode mode0 = insn_data[d->icode].operand[0].mode;
23745   enum machine_mode mode1 = insn_data[d->icode].operand[1].mode;
23746   enum rtx_code comparison = d->comparison;
23747
23748   if (VECTOR_MODE_P (mode0))
23749     op0 = safe_vector_operand (op0, mode0);
23750   if (VECTOR_MODE_P (mode1))
23751     op1 = safe_vector_operand (op1, mode1);
23752
23753   target = gen_reg_rtx (SImode);
23754   emit_move_insn (target, const0_rtx);
23755   target = gen_rtx_SUBREG (QImode, target, 0);
23756
23757   if ((optimize && !register_operand (op0, mode0))
23758       || !(*insn_data[d->icode].operand[0].predicate) (op0, mode0))
23759     op0 = copy_to_mode_reg (mode0, op0);
23760   if ((optimize && !register_operand (op1, mode1))
23761       || !(*insn_data[d->icode].operand[1].predicate) (op1, mode1))
23762     op1 = copy_to_mode_reg (mode1, op1);
23763
23764   pat = GEN_FCN (d->icode) (op0, op1);
23765   if (! pat)
23766     return 0;
23767   emit_insn (pat);
23768   emit_insn (gen_rtx_SET (VOIDmode,
23769                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
23770                           gen_rtx_fmt_ee (comparison, QImode,
23771                                           SET_DEST (pat),
23772                                           const0_rtx)));
23773
23774   return SUBREG_REG (target);
23775 }
23776
23777 /* Subroutine of ix86_expand_builtin to take care of pcmpestr[im] insns.  */
23778
23779 static rtx
23780 ix86_expand_sse_pcmpestr (const struct builtin_description *d,
23781                           tree exp, rtx target)
23782 {
23783   rtx pat;
23784   tree arg0 = CALL_EXPR_ARG (exp, 0);
23785   tree arg1 = CALL_EXPR_ARG (exp, 1);
23786   tree arg2 = CALL_EXPR_ARG (exp, 2);
23787   tree arg3 = CALL_EXPR_ARG (exp, 3);
23788   tree arg4 = CALL_EXPR_ARG (exp, 4);
23789   rtx scratch0, scratch1;
23790   rtx op0 = expand_normal (arg0);
23791   rtx op1 = expand_normal (arg1);
23792   rtx op2 = expand_normal (arg2);
23793   rtx op3 = expand_normal (arg3);
23794   rtx op4 = expand_normal (arg4);
23795   enum machine_mode tmode0, tmode1, modev2, modei3, modev4, modei5, modeimm;
23796
23797   tmode0 = insn_data[d->icode].operand[0].mode;
23798   tmode1 = insn_data[d->icode].operand[1].mode;
23799   modev2 = insn_data[d->icode].operand[2].mode;
23800   modei3 = insn_data[d->icode].operand[3].mode;
23801   modev4 = insn_data[d->icode].operand[4].mode;
23802   modei5 = insn_data[d->icode].operand[5].mode;
23803   modeimm = insn_data[d->icode].operand[6].mode;
23804
23805   if (VECTOR_MODE_P (modev2))
23806     op0 = safe_vector_operand (op0, modev2);
23807   if (VECTOR_MODE_P (modev4))
23808     op2 = safe_vector_operand (op2, modev4);
23809
23810   if (! (*insn_data[d->icode].operand[2].predicate) (op0, modev2))
23811     op0 = copy_to_mode_reg (modev2, op0);
23812   if (! (*insn_data[d->icode].operand[3].predicate) (op1, modei3))
23813     op1 = copy_to_mode_reg (modei3, op1);
23814   if ((optimize && !register_operand (op2, modev4))
23815       || !(*insn_data[d->icode].operand[4].predicate) (op2, modev4))
23816     op2 = copy_to_mode_reg (modev4, op2);
23817   if (! (*insn_data[d->icode].operand[5].predicate) (op3, modei5))
23818     op3 = copy_to_mode_reg (modei5, op3);
23819
23820   if (! (*insn_data[d->icode].operand[6].predicate) (op4, modeimm))
23821     {
23822       error ("the fifth argument must be a 8-bit immediate");
23823       return const0_rtx;
23824     }
23825
23826   if (d->code == IX86_BUILTIN_PCMPESTRI128)
23827     {
23828       if (optimize || !target
23829           || GET_MODE (target) != tmode0
23830           || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode0))
23831         target = gen_reg_rtx (tmode0);
23832
23833       scratch1 = gen_reg_rtx (tmode1);
23834
23835       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2, op3, op4);
23836     }
23837   else if (d->code == IX86_BUILTIN_PCMPESTRM128)
23838     {
23839       if (optimize || !target
23840           || GET_MODE (target) != tmode1
23841           || ! (*insn_data[d->icode].operand[1].predicate) (target, tmode1))
23842         target = gen_reg_rtx (tmode1);
23843
23844       scratch0 = gen_reg_rtx (tmode0);
23845
23846       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2, op3, op4);
23847     }
23848   else
23849     {
23850       gcc_assert (d->flag);
23851
23852       scratch0 = gen_reg_rtx (tmode0);
23853       scratch1 = gen_reg_rtx (tmode1);
23854
23855       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2, op3, op4);
23856     }
23857
23858   if (! pat)
23859     return 0;
23860
23861   emit_insn (pat);
23862
23863   if (d->flag)
23864     {
23865       target = gen_reg_rtx (SImode);
23866       emit_move_insn (target, const0_rtx);
23867       target = gen_rtx_SUBREG (QImode, target, 0);
23868
23869       emit_insn
23870         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
23871                       gen_rtx_fmt_ee (EQ, QImode,
23872                                       gen_rtx_REG ((enum machine_mode) d->flag,
23873                                                    FLAGS_REG),
23874                                       const0_rtx)));
23875       return SUBREG_REG (target);
23876     }
23877   else
23878     return target;
23879 }
23880
23881
23882 /* Subroutine of ix86_expand_builtin to take care of pcmpistr[im] insns.  */
23883
23884 static rtx
23885 ix86_expand_sse_pcmpistr (const struct builtin_description *d,
23886                           tree exp, rtx target)
23887 {
23888   rtx pat;
23889   tree arg0 = CALL_EXPR_ARG (exp, 0);
23890   tree arg1 = CALL_EXPR_ARG (exp, 1);
23891   tree arg2 = CALL_EXPR_ARG (exp, 2);
23892   rtx scratch0, scratch1;
23893   rtx op0 = expand_normal (arg0);
23894   rtx op1 = expand_normal (arg1);
23895   rtx op2 = expand_normal (arg2);
23896   enum machine_mode tmode0, tmode1, modev2, modev3, modeimm;
23897
23898   tmode0 = insn_data[d->icode].operand[0].mode;
23899   tmode1 = insn_data[d->icode].operand[1].mode;
23900   modev2 = insn_data[d->icode].operand[2].mode;
23901   modev3 = insn_data[d->icode].operand[3].mode;
23902   modeimm = insn_data[d->icode].operand[4].mode;
23903
23904   if (VECTOR_MODE_P (modev2))
23905     op0 = safe_vector_operand (op0, modev2);
23906   if (VECTOR_MODE_P (modev3))
23907     op1 = safe_vector_operand (op1, modev3);
23908
23909   if (! (*insn_data[d->icode].operand[2].predicate) (op0, modev2))
23910     op0 = copy_to_mode_reg (modev2, op0);
23911   if ((optimize && !register_operand (op1, modev3))
23912       || !(*insn_data[d->icode].operand[3].predicate) (op1, modev3))
23913     op1 = copy_to_mode_reg (modev3, op1);
23914
23915   if (! (*insn_data[d->icode].operand[4].predicate) (op2, modeimm))
23916     {
23917       error ("the third argument must be a 8-bit immediate");
23918       return const0_rtx;
23919     }
23920
23921   if (d->code == IX86_BUILTIN_PCMPISTRI128)
23922     {
23923       if (optimize || !target
23924           || GET_MODE (target) != tmode0
23925           || ! (*insn_data[d->icode].operand[0].predicate) (target, tmode0))
23926         target = gen_reg_rtx (tmode0);
23927
23928       scratch1 = gen_reg_rtx (tmode1);
23929
23930       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2);
23931     }
23932   else if (d->code == IX86_BUILTIN_PCMPISTRM128)
23933     {
23934       if (optimize || !target
23935           || GET_MODE (target) != tmode1
23936           || ! (*insn_data[d->icode].operand[1].predicate) (target, tmode1))
23937         target = gen_reg_rtx (tmode1);
23938
23939       scratch0 = gen_reg_rtx (tmode0);
23940
23941       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2);
23942     }
23943   else
23944     {
23945       gcc_assert (d->flag);
23946
23947       scratch0 = gen_reg_rtx (tmode0);
23948       scratch1 = gen_reg_rtx (tmode1);
23949
23950       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2);
23951     }
23952
23953   if (! pat)
23954     return 0;
23955
23956   emit_insn (pat);
23957
23958   if (d->flag)
23959     {
23960       target = gen_reg_rtx (SImode);
23961       emit_move_insn (target, const0_rtx);
23962       target = gen_rtx_SUBREG (QImode, target, 0);
23963
23964       emit_insn
23965         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
23966                       gen_rtx_fmt_ee (EQ, QImode,
23967                                       gen_rtx_REG ((enum machine_mode) d->flag,
23968                                                    FLAGS_REG),
23969                                       const0_rtx)));
23970       return SUBREG_REG (target);
23971     }
23972   else
23973     return target;
23974 }
23975
23976 /* Subroutine of ix86_expand_builtin to take care of insns with
23977    variable number of operands.  */
23978
23979 static rtx
23980 ix86_expand_args_builtin (const struct builtin_description *d,
23981                           tree exp, rtx target)
23982 {
23983   rtx pat, real_target;
23984   unsigned int i, nargs;
23985   unsigned int nargs_constant = 0;
23986   int num_memory = 0;
23987   struct
23988     {
23989       rtx op;
23990       enum machine_mode mode;
23991     } args[4];
23992   bool last_arg_count = false;
23993   enum insn_code icode = d->icode;
23994   const struct insn_data *insn_p = &insn_data[icode];
23995   enum machine_mode tmode = insn_p->operand[0].mode;
23996   enum machine_mode rmode = VOIDmode;
23997   bool swap = false;
23998   enum rtx_code comparison = d->comparison;
23999
24000   switch ((enum ix86_builtin_type) d->flag)
24001     {
24002     case INT_FTYPE_V8SF_V8SF_PTEST:
24003     case INT_FTYPE_V4DI_V4DI_PTEST:
24004     case INT_FTYPE_V4DF_V4DF_PTEST:
24005     case INT_FTYPE_V4SF_V4SF_PTEST:
24006     case INT_FTYPE_V2DI_V2DI_PTEST:
24007     case INT_FTYPE_V2DF_V2DF_PTEST:
24008       return ix86_expand_sse_ptest (d, exp, target);
24009     case FLOAT128_FTYPE_FLOAT128:
24010     case FLOAT_FTYPE_FLOAT:
24011     case INT64_FTYPE_V4SF:
24012     case INT64_FTYPE_V2DF:
24013     case INT_FTYPE_V16QI:
24014     case INT_FTYPE_V8QI:
24015     case INT_FTYPE_V8SF:
24016     case INT_FTYPE_V4DF:
24017     case INT_FTYPE_V4SF:
24018     case INT_FTYPE_V2DF:
24019     case V16QI_FTYPE_V16QI:
24020     case V8SI_FTYPE_V8SF:
24021     case V8SI_FTYPE_V4SI:
24022     case V8HI_FTYPE_V8HI:
24023     case V8HI_FTYPE_V16QI:
24024     case V8QI_FTYPE_V8QI:
24025     case V8SF_FTYPE_V8SF:
24026     case V8SF_FTYPE_V8SI:
24027     case V8SF_FTYPE_V4SF:
24028     case V4SI_FTYPE_V4SI:
24029     case V4SI_FTYPE_V16QI:
24030     case V4SI_FTYPE_V4SF:
24031     case V4SI_FTYPE_V8SI:
24032     case V4SI_FTYPE_V8HI:
24033     case V4SI_FTYPE_V4DF:
24034     case V4SI_FTYPE_V2DF:
24035     case V4HI_FTYPE_V4HI:
24036     case V4DF_FTYPE_V4DF:
24037     case V4DF_FTYPE_V4SI:
24038     case V4DF_FTYPE_V4SF:
24039     case V4DF_FTYPE_V2DF:
24040     case V4SF_FTYPE_V4SF:
24041     case V4SF_FTYPE_V4SI:
24042     case V4SF_FTYPE_V8SF:
24043     case V4SF_FTYPE_V4DF:
24044     case V4SF_FTYPE_V2DF:
24045     case V2DI_FTYPE_V2DI:
24046     case V2DI_FTYPE_V16QI:
24047     case V2DI_FTYPE_V8HI:
24048     case V2DI_FTYPE_V4SI:
24049     case V2DF_FTYPE_V2DF:
24050     case V2DF_FTYPE_V4SI:
24051     case V2DF_FTYPE_V4DF:
24052     case V2DF_FTYPE_V4SF:
24053     case V2DF_FTYPE_V2SI:
24054     case V2SI_FTYPE_V2SI:
24055     case V2SI_FTYPE_V4SF:
24056     case V2SI_FTYPE_V2SF:
24057     case V2SI_FTYPE_V2DF:
24058     case V2SF_FTYPE_V2SF:
24059     case V2SF_FTYPE_V2SI:
24060       nargs = 1;
24061       break;
24062     case V4SF_FTYPE_V4SF_VEC_MERGE:
24063     case V2DF_FTYPE_V2DF_VEC_MERGE:
24064       return ix86_expand_unop_vec_merge_builtin (icode, exp, target);
24065     case FLOAT128_FTYPE_FLOAT128_FLOAT128:
24066     case V16QI_FTYPE_V16QI_V16QI:
24067     case V16QI_FTYPE_V8HI_V8HI:
24068     case V8QI_FTYPE_V8QI_V8QI:
24069     case V8QI_FTYPE_V4HI_V4HI:
24070     case V8HI_FTYPE_V8HI_V8HI:
24071     case V8HI_FTYPE_V16QI_V16QI:
24072     case V8HI_FTYPE_V4SI_V4SI:
24073     case V8SF_FTYPE_V8SF_V8SF:
24074     case V8SF_FTYPE_V8SF_V8SI:
24075     case V4SI_FTYPE_V4SI_V4SI:
24076     case V4SI_FTYPE_V8HI_V8HI:
24077     case V4SI_FTYPE_V4SF_V4SF:
24078     case V4SI_FTYPE_V2DF_V2DF:
24079     case V4HI_FTYPE_V4HI_V4HI:
24080     case V4HI_FTYPE_V8QI_V8QI:
24081     case V4HI_FTYPE_V2SI_V2SI:
24082     case V4DF_FTYPE_V4DF_V4DF:
24083     case V4DF_FTYPE_V4DF_V4DI:
24084     case V4SF_FTYPE_V4SF_V4SF:
24085     case V4SF_FTYPE_V4SF_V4SI:
24086     case V4SF_FTYPE_V4SF_V2SI:
24087     case V4SF_FTYPE_V4SF_V2DF:
24088     case V4SF_FTYPE_V4SF_DI:
24089     case V4SF_FTYPE_V4SF_SI:
24090     case V2DI_FTYPE_V2DI_V2DI:
24091     case V2DI_FTYPE_V16QI_V16QI:
24092     case V2DI_FTYPE_V4SI_V4SI:
24093     case V2DI_FTYPE_V2DI_V16QI:
24094     case V2DI_FTYPE_V2DF_V2DF:
24095     case V2SI_FTYPE_V2SI_V2SI:
24096     case V2SI_FTYPE_V4HI_V4HI:
24097     case V2SI_FTYPE_V2SF_V2SF:
24098     case V2DF_FTYPE_V2DF_V2DF:
24099     case V2DF_FTYPE_V2DF_V4SF:
24100     case V2DF_FTYPE_V2DF_V2DI:
24101     case V2DF_FTYPE_V2DF_DI:
24102     case V2DF_FTYPE_V2DF_SI:
24103     case V2SF_FTYPE_V2SF_V2SF:
24104     case V1DI_FTYPE_V1DI_V1DI:
24105     case V1DI_FTYPE_V8QI_V8QI:
24106     case V1DI_FTYPE_V2SI_V2SI:
24107       if (comparison == UNKNOWN)
24108         return ix86_expand_binop_builtin (icode, exp, target);
24109       nargs = 2;
24110       break;
24111     case V4SF_FTYPE_V4SF_V4SF_SWAP:
24112     case V2DF_FTYPE_V2DF_V2DF_SWAP:
24113       gcc_assert (comparison != UNKNOWN);
24114       nargs = 2;
24115       swap = true;
24116       break;
24117     case V8HI_FTYPE_V8HI_V8HI_COUNT:
24118     case V8HI_FTYPE_V8HI_SI_COUNT:
24119     case V4SI_FTYPE_V4SI_V4SI_COUNT:
24120     case V4SI_FTYPE_V4SI_SI_COUNT:
24121     case V4HI_FTYPE_V4HI_V4HI_COUNT:
24122     case V4HI_FTYPE_V4HI_SI_COUNT:
24123     case V2DI_FTYPE_V2DI_V2DI_COUNT:
24124     case V2DI_FTYPE_V2DI_SI_COUNT:
24125     case V2SI_FTYPE_V2SI_V2SI_COUNT:
24126     case V2SI_FTYPE_V2SI_SI_COUNT:
24127     case V1DI_FTYPE_V1DI_V1DI_COUNT:
24128     case V1DI_FTYPE_V1DI_SI_COUNT:
24129       nargs = 2;
24130       last_arg_count = true;
24131       break;
24132     case UINT64_FTYPE_UINT64_UINT64:
24133     case UINT_FTYPE_UINT_UINT:
24134     case UINT_FTYPE_UINT_USHORT:
24135     case UINT_FTYPE_UINT_UCHAR:
24136       nargs = 2;
24137       break;
24138     case V2DI2TI_FTYPE_V2DI_INT:
24139       nargs = 2;
24140       rmode = V2DImode;
24141       nargs_constant = 1;
24142       break;
24143     case V8HI_FTYPE_V8HI_INT:
24144     case V8SF_FTYPE_V8SF_INT:
24145     case V4SI_FTYPE_V4SI_INT:
24146     case V4SI_FTYPE_V8SI_INT:
24147     case V4HI_FTYPE_V4HI_INT:
24148     case V4DF_FTYPE_V4DF_INT:
24149     case V4SF_FTYPE_V4SF_INT:
24150     case V4SF_FTYPE_V8SF_INT:
24151     case V2DI_FTYPE_V2DI_INT:
24152     case V2DF_FTYPE_V2DF_INT:
24153     case V2DF_FTYPE_V4DF_INT:
24154       nargs = 2;
24155       nargs_constant = 1;
24156       break;
24157     case V16QI_FTYPE_V16QI_V16QI_V16QI:
24158     case V8SF_FTYPE_V8SF_V8SF_V8SF:
24159     case V4DF_FTYPE_V4DF_V4DF_V4DF:
24160     case V4SF_FTYPE_V4SF_V4SF_V4SF:
24161     case V2DF_FTYPE_V2DF_V2DF_V2DF:
24162       nargs = 3;
24163       break;
24164     case V16QI_FTYPE_V16QI_V16QI_INT:
24165     case V8HI_FTYPE_V8HI_V8HI_INT:
24166     case V8SI_FTYPE_V8SI_V8SI_INT:
24167     case V8SI_FTYPE_V8SI_V4SI_INT:
24168     case V8SF_FTYPE_V8SF_V8SF_INT: 
24169     case V8SF_FTYPE_V8SF_V4SF_INT: 
24170     case V4SI_FTYPE_V4SI_V4SI_INT:
24171     case V4DF_FTYPE_V4DF_V4DF_INT:
24172     case V4DF_FTYPE_V4DF_V2DF_INT:
24173     case V4SF_FTYPE_V4SF_V4SF_INT:
24174     case V2DI_FTYPE_V2DI_V2DI_INT:
24175     case V2DF_FTYPE_V2DF_V2DF_INT:
24176       nargs = 3;
24177       nargs_constant = 1;
24178       break;
24179     case V2DI2TI_FTYPE_V2DI_V2DI_INT:
24180       nargs = 3;
24181       rmode = V2DImode;
24182       nargs_constant = 1;
24183       break;
24184     case V1DI2DI_FTYPE_V1DI_V1DI_INT:
24185       nargs = 3;
24186       rmode = DImode;
24187       nargs_constant = 1;
24188       break;
24189     case V2DI_FTYPE_V2DI_UINT_UINT:
24190       nargs = 3;
24191       nargs_constant = 2;
24192       break;
24193     case V2DI_FTYPE_V2DI_V2DI_UINT_UINT:
24194       nargs = 4;
24195       nargs_constant = 2;
24196       break;
24197     default:
24198       gcc_unreachable ();
24199     }
24200
24201   gcc_assert (nargs <= ARRAY_SIZE (args));
24202
24203   if (comparison != UNKNOWN)
24204     {
24205       gcc_assert (nargs == 2);
24206       return ix86_expand_sse_compare (d, exp, target, swap);
24207     }
24208
24209   if (rmode == VOIDmode || rmode == tmode)
24210     {
24211       if (optimize
24212           || target == 0
24213           || GET_MODE (target) != tmode
24214           || ! (*insn_p->operand[0].predicate) (target, tmode))
24215         target = gen_reg_rtx (tmode);
24216       real_target = target;
24217     }
24218   else
24219     {
24220       target = gen_reg_rtx (rmode);
24221       real_target = simplify_gen_subreg (tmode, target, rmode, 0);
24222     }
24223
24224   for (i = 0; i < nargs; i++)
24225     {
24226       tree arg = CALL_EXPR_ARG (exp, i);
24227       rtx op = expand_normal (arg);
24228       enum machine_mode mode = insn_p->operand[i + 1].mode;
24229       bool match = (*insn_p->operand[i + 1].predicate) (op, mode);
24230
24231       if (last_arg_count && (i + 1) == nargs)
24232         {
24233           /* SIMD shift insns take either an 8-bit immediate or
24234              register as count.  But builtin functions take int as
24235              count.  If count doesn't match, we put it in register.  */
24236           if (!match)
24237             {
24238               op = simplify_gen_subreg (SImode, op, GET_MODE (op), 0);
24239               if (!(*insn_p->operand[i + 1].predicate) (op, mode))
24240                 op = copy_to_reg (op);
24241             }
24242         }
24243       else if ((nargs - i) <= nargs_constant)
24244         {
24245           if (!match)
24246             switch (icode)
24247               {
24248               case CODE_FOR_sse4_1_roundpd:
24249               case CODE_FOR_sse4_1_roundps:
24250               case CODE_FOR_sse4_1_roundsd:
24251               case CODE_FOR_sse4_1_roundss:
24252               case CODE_FOR_sse4_1_blendps:
24253               case CODE_FOR_avx_blendpd256:
24254               case CODE_FOR_avx_vpermilv4df:
24255               case CODE_FOR_avx_roundpd256:
24256               case CODE_FOR_avx_roundps256:
24257                 error ("the last argument must be a 4-bit immediate");
24258                 return const0_rtx;
24259
24260               case CODE_FOR_sse4_1_blendpd:
24261               case CODE_FOR_avx_vpermilv2df:
24262                 error ("the last argument must be a 2-bit immediate");
24263                 return const0_rtx;
24264
24265               case CODE_FOR_avx_vextractf128v4df:
24266               case CODE_FOR_avx_vextractf128v8sf:
24267               case CODE_FOR_avx_vextractf128v8si:
24268               case CODE_FOR_avx_vinsertf128v4df:
24269               case CODE_FOR_avx_vinsertf128v8sf:
24270               case CODE_FOR_avx_vinsertf128v8si:
24271                 error ("the last argument must be a 1-bit immediate");
24272                 return const0_rtx;
24273
24274               case CODE_FOR_avx_cmpsdv2df3:
24275               case CODE_FOR_avx_cmpssv4sf3:
24276               case CODE_FOR_avx_cmppdv2df3:
24277               case CODE_FOR_avx_cmppsv4sf3:
24278               case CODE_FOR_avx_cmppdv4df3:
24279               case CODE_FOR_avx_cmppsv8sf3:
24280                 error ("the last argument must be a 5-bit immediate");
24281                 return const0_rtx;
24282
24283              default:
24284                 switch (nargs_constant)
24285                   {
24286                   case 2:
24287                     if ((nargs - i) == nargs_constant)
24288                       {
24289                         error ("the next to last argument must be an 8-bit immediate");
24290                         break;
24291                       }
24292                   case 1:
24293                     error ("the last argument must be an 8-bit immediate");
24294                     break;
24295                   default:
24296                     gcc_unreachable ();
24297                   }
24298                 return const0_rtx;
24299               }
24300         }
24301       else
24302         {
24303           if (VECTOR_MODE_P (mode))
24304             op = safe_vector_operand (op, mode);
24305
24306           /* If we aren't optimizing, only allow one memory operand to
24307              be generated.  */
24308           if (memory_operand (op, mode))
24309             num_memory++;
24310
24311           if (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
24312             {
24313               if (optimize || !match || num_memory > 1)
24314                 op = copy_to_mode_reg (mode, op);
24315             }
24316           else
24317             {
24318               op = copy_to_reg (op);
24319               op = simplify_gen_subreg (mode, op, GET_MODE (op), 0);
24320             }
24321         }
24322
24323       args[i].op = op;
24324       args[i].mode = mode;
24325     }
24326
24327   switch (nargs)
24328     {
24329     case 1:
24330       pat = GEN_FCN (icode) (real_target, args[0].op);
24331       break;
24332     case 2:
24333       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op);
24334       break;
24335     case 3:
24336       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
24337                              args[2].op);
24338       break;
24339     case 4:
24340       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
24341                              args[2].op, args[3].op);
24342       break;
24343     default:
24344       gcc_unreachable ();
24345     }
24346
24347   if (! pat)
24348     return 0;
24349
24350   emit_insn (pat);
24351   return target;
24352 }
24353
24354 /* Subroutine of ix86_expand_builtin to take care of special insns
24355    with variable number of operands.  */
24356
24357 static rtx
24358 ix86_expand_special_args_builtin (const struct builtin_description *d,
24359                                     tree exp, rtx target)
24360 {
24361   tree arg;
24362   rtx pat, op;
24363   unsigned int i, nargs, arg_adjust, memory;
24364   struct
24365     {
24366       rtx op;
24367       enum machine_mode mode;
24368     } args[2];
24369   enum insn_code icode = d->icode;
24370   bool last_arg_constant = false;
24371   const struct insn_data *insn_p = &insn_data[icode];
24372   enum machine_mode tmode = insn_p->operand[0].mode;
24373   enum { load, store } klass;
24374
24375   switch ((enum ix86_special_builtin_type) d->flag)
24376     {
24377     case VOID_FTYPE_VOID:
24378       emit_insn (GEN_FCN (icode) (target));
24379       return 0;
24380     case V2DI_FTYPE_PV2DI:
24381     case V32QI_FTYPE_PCCHAR:
24382     case V16QI_FTYPE_PCCHAR:
24383     case V8SF_FTYPE_PCV4SF:
24384     case V8SF_FTYPE_PCFLOAT:
24385     case V4SF_FTYPE_PCFLOAT:
24386     case V4DF_FTYPE_PCV2DF:
24387     case V4DF_FTYPE_PCDOUBLE:
24388     case V2DF_FTYPE_PCDOUBLE:
24389       nargs = 1;
24390       klass = load;
24391       memory = 0;
24392       break;
24393     case VOID_FTYPE_PV2SF_V4SF:
24394     case VOID_FTYPE_PV4DI_V4DI:
24395     case VOID_FTYPE_PV2DI_V2DI:
24396     case VOID_FTYPE_PCHAR_V32QI:
24397     case VOID_FTYPE_PCHAR_V16QI:
24398     case VOID_FTYPE_PFLOAT_V8SF:
24399     case VOID_FTYPE_PFLOAT_V4SF:
24400     case VOID_FTYPE_PDOUBLE_V4DF:
24401     case VOID_FTYPE_PDOUBLE_V2DF:
24402     case VOID_FTYPE_PDI_DI:
24403     case VOID_FTYPE_PINT_INT:
24404       nargs = 1;
24405       klass = store;
24406       /* Reserve memory operand for target.  */
24407       memory = ARRAY_SIZE (args);
24408       break;
24409     case V4SF_FTYPE_V4SF_PCV2SF:
24410     case V2DF_FTYPE_V2DF_PCDOUBLE:
24411       nargs = 2;
24412       klass = load;
24413       memory = 1;
24414       break;
24415     case V8SF_FTYPE_PCV8SF_V8SF:
24416     case V4DF_FTYPE_PCV4DF_V4DF:
24417     case V4SF_FTYPE_PCV4SF_V4SF:
24418     case V2DF_FTYPE_PCV2DF_V2DF:
24419       nargs = 2;
24420       klass = load;
24421       memory = 0;
24422       break;
24423     case VOID_FTYPE_PV8SF_V8SF_V8SF:
24424     case VOID_FTYPE_PV4DF_V4DF_V4DF:
24425     case VOID_FTYPE_PV4SF_V4SF_V4SF:
24426     case VOID_FTYPE_PV2DF_V2DF_V2DF:
24427       nargs = 2;
24428       klass = store;
24429       /* Reserve memory operand for target.  */
24430       memory = ARRAY_SIZE (args);
24431       break;
24432     default:
24433       gcc_unreachable ();
24434     }
24435
24436   gcc_assert (nargs <= ARRAY_SIZE (args));
24437
24438   if (klass == store)
24439     {
24440       arg = CALL_EXPR_ARG (exp, 0);
24441       op = expand_normal (arg);
24442       gcc_assert (target == 0);
24443       target = gen_rtx_MEM (tmode, copy_to_mode_reg (Pmode, op));
24444       arg_adjust = 1;
24445     }
24446   else
24447     {
24448       arg_adjust = 0;
24449       if (optimize
24450           || target == 0
24451           || GET_MODE (target) != tmode
24452           || ! (*insn_p->operand[0].predicate) (target, tmode))
24453         target = gen_reg_rtx (tmode);
24454     }
24455
24456   for (i = 0; i < nargs; i++)
24457     {
24458       enum machine_mode mode = insn_p->operand[i + 1].mode;
24459       bool match;
24460
24461       arg = CALL_EXPR_ARG (exp, i + arg_adjust);
24462       op = expand_normal (arg);
24463       match = (*insn_p->operand[i + 1].predicate) (op, mode);
24464
24465       if (last_arg_constant && (i + 1) == nargs)
24466         {
24467           if (!match)
24468             switch (icode)
24469               {
24470              default:
24471                 error ("the last argument must be an 8-bit immediate");
24472                 return const0_rtx;
24473               }
24474         }
24475       else
24476         {
24477           if (i == memory)
24478             {
24479               /* This must be the memory operand.  */
24480               op = gen_rtx_MEM (mode, copy_to_mode_reg (Pmode, op));
24481               gcc_assert (GET_MODE (op) == mode
24482                           || GET_MODE (op) == VOIDmode);
24483             }
24484           else
24485             {
24486               /* This must be register.  */
24487               if (VECTOR_MODE_P (mode))
24488                 op = safe_vector_operand (op, mode);
24489
24490               gcc_assert (GET_MODE (op) == mode
24491                           || GET_MODE (op) == VOIDmode);
24492               op = copy_to_mode_reg (mode, op);
24493             }
24494         }
24495
24496       args[i].op = op;
24497       args[i].mode = mode;
24498     }
24499
24500   switch (nargs)
24501     {
24502     case 1:
24503       pat = GEN_FCN (icode) (target, args[0].op);
24504       break;
24505     case 2:
24506       pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
24507       break;
24508     default:
24509       gcc_unreachable ();
24510     }
24511
24512   if (! pat)
24513     return 0;
24514   emit_insn (pat);
24515   return klass == store ? 0 : target;
24516 }
24517
24518 /* Return the integer constant in ARG.  Constrain it to be in the range
24519    of the subparts of VEC_TYPE; issue an error if not.  */
24520
24521 static int
24522 get_element_number (tree vec_type, tree arg)
24523 {
24524   unsigned HOST_WIDE_INT elt, max = TYPE_VECTOR_SUBPARTS (vec_type) - 1;
24525
24526   if (!host_integerp (arg, 1)
24527       || (elt = tree_low_cst (arg, 1), elt > max))
24528     {
24529       error ("selector must be an integer constant in the range 0..%wi", max);
24530       return 0;
24531     }
24532
24533   return elt;
24534 }
24535
24536 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
24537    ix86_expand_vector_init.  We DO have language-level syntax for this, in
24538    the form of  (type){ init-list }.  Except that since we can't place emms
24539    instructions from inside the compiler, we can't allow the use of MMX
24540    registers unless the user explicitly asks for it.  So we do *not* define
24541    vec_set/vec_extract/vec_init patterns for MMX modes in mmx.md.  Instead
24542    we have builtins invoked by mmintrin.h that gives us license to emit
24543    these sorts of instructions.  */
24544
24545 static rtx
24546 ix86_expand_vec_init_builtin (tree type, tree exp, rtx target)
24547 {
24548   enum machine_mode tmode = TYPE_MODE (type);
24549   enum machine_mode inner_mode = GET_MODE_INNER (tmode);
24550   int i, n_elt = GET_MODE_NUNITS (tmode);
24551   rtvec v = rtvec_alloc (n_elt);
24552
24553   gcc_assert (VECTOR_MODE_P (tmode));
24554   gcc_assert (call_expr_nargs (exp) == n_elt);
24555
24556   for (i = 0; i < n_elt; ++i)
24557     {
24558       rtx x = expand_normal (CALL_EXPR_ARG (exp, i));
24559       RTVEC_ELT (v, i) = gen_lowpart (inner_mode, x);
24560     }
24561
24562   if (!target || !register_operand (target, tmode))
24563     target = gen_reg_rtx (tmode);
24564
24565   ix86_expand_vector_init (true, target, gen_rtx_PARALLEL (tmode, v));
24566   return target;
24567 }
24568
24569 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
24570    ix86_expand_vector_extract.  They would be redundant (for non-MMX) if we
24571    had a language-level syntax for referencing vector elements.  */
24572
24573 static rtx
24574 ix86_expand_vec_ext_builtin (tree exp, rtx target)
24575 {
24576   enum machine_mode tmode, mode0;
24577   tree arg0, arg1;
24578   int elt;
24579   rtx op0;
24580
24581   arg0 = CALL_EXPR_ARG (exp, 0);
24582   arg1 = CALL_EXPR_ARG (exp, 1);
24583
24584   op0 = expand_normal (arg0);
24585   elt = get_element_number (TREE_TYPE (arg0), arg1);
24586
24587   tmode = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
24588   mode0 = TYPE_MODE (TREE_TYPE (arg0));
24589   gcc_assert (VECTOR_MODE_P (mode0));
24590
24591   op0 = force_reg (mode0, op0);
24592
24593   if (optimize || !target || !register_operand (target, tmode))
24594     target = gen_reg_rtx (tmode);
24595
24596   ix86_expand_vector_extract (true, target, op0, elt);
24597
24598   return target;
24599 }
24600
24601 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
24602    ix86_expand_vector_set.  They would be redundant (for non-MMX) if we had
24603    a language-level syntax for referencing vector elements.  */
24604
24605 static rtx
24606 ix86_expand_vec_set_builtin (tree exp)
24607 {
24608   enum machine_mode tmode, mode1;
24609   tree arg0, arg1, arg2;
24610   int elt;
24611   rtx op0, op1, target;
24612
24613   arg0 = CALL_EXPR_ARG (exp, 0);
24614   arg1 = CALL_EXPR_ARG (exp, 1);
24615   arg2 = CALL_EXPR_ARG (exp, 2);
24616
24617   tmode = TYPE_MODE (TREE_TYPE (arg0));
24618   mode1 = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
24619   gcc_assert (VECTOR_MODE_P (tmode));
24620
24621   op0 = expand_expr (arg0, NULL_RTX, tmode, EXPAND_NORMAL);
24622   op1 = expand_expr (arg1, NULL_RTX, mode1, EXPAND_NORMAL);
24623   elt = get_element_number (TREE_TYPE (arg0), arg2);
24624
24625   if (GET_MODE (op1) != mode1 && GET_MODE (op1) != VOIDmode)
24626     op1 = convert_modes (mode1, GET_MODE (op1), op1, true);
24627
24628   op0 = force_reg (tmode, op0);
24629   op1 = force_reg (mode1, op1);
24630
24631   /* OP0 is the source of these builtin functions and shouldn't be
24632      modified.  Create a copy, use it and return it as target.  */
24633   target = gen_reg_rtx (tmode);
24634   emit_move_insn (target, op0);
24635   ix86_expand_vector_set (true, target, op1, elt);
24636
24637   return target;
24638 }
24639
24640 /* Expand an expression EXP that calls a built-in function,
24641    with result going to TARGET if that's convenient
24642    (and in mode MODE if that's convenient).
24643    SUBTARGET may be used as the target for computing one of EXP's operands.
24644    IGNORE is nonzero if the value is to be ignored.  */
24645
24646 static rtx
24647 ix86_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
24648                      enum machine_mode mode ATTRIBUTE_UNUSED,
24649                      int ignore ATTRIBUTE_UNUSED)
24650 {
24651   const struct builtin_description *d;
24652   size_t i;
24653   enum insn_code icode;
24654   tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
24655   tree arg0, arg1, arg2;
24656   rtx op0, op1, op2, pat;
24657   enum machine_mode mode0, mode1, mode2;
24658   unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
24659
24660   /* Determine whether the builtin function is available under the current ISA.
24661      Originally the builtin was not created if it wasn't applicable to the
24662      current ISA based on the command line switches.  With function specific
24663      options, we need to check in the context of the function making the call
24664      whether it is supported.  */
24665   if (ix86_builtins_isa[fcode].isa
24666       && !(ix86_builtins_isa[fcode].isa & ix86_isa_flags))
24667     {
24668       char *opts = ix86_target_string (ix86_builtins_isa[fcode].isa, 0, NULL,
24669                                        NULL, NULL, false);
24670
24671       if (!opts)
24672         error ("%qE needs unknown isa option", fndecl);
24673       else
24674         {
24675           gcc_assert (opts != NULL);
24676           error ("%qE needs isa option %s", fndecl, opts);
24677           free (opts);
24678         }
24679       return const0_rtx;
24680     }
24681
24682   switch (fcode)
24683     {
24684     case IX86_BUILTIN_MASKMOVQ:
24685     case IX86_BUILTIN_MASKMOVDQU:
24686       icode = (fcode == IX86_BUILTIN_MASKMOVQ
24687                ? CODE_FOR_mmx_maskmovq
24688                : CODE_FOR_sse2_maskmovdqu);
24689       /* Note the arg order is different from the operand order.  */
24690       arg1 = CALL_EXPR_ARG (exp, 0);
24691       arg2 = CALL_EXPR_ARG (exp, 1);
24692       arg0 = CALL_EXPR_ARG (exp, 2);
24693       op0 = expand_normal (arg0);
24694       op1 = expand_normal (arg1);
24695       op2 = expand_normal (arg2);
24696       mode0 = insn_data[icode].operand[0].mode;
24697       mode1 = insn_data[icode].operand[1].mode;
24698       mode2 = insn_data[icode].operand[2].mode;
24699
24700       op0 = force_reg (Pmode, op0);
24701       op0 = gen_rtx_MEM (mode1, op0);
24702
24703       if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
24704         op0 = copy_to_mode_reg (mode0, op0);
24705       if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
24706         op1 = copy_to_mode_reg (mode1, op1);
24707       if (! (*insn_data[icode].operand[2].predicate) (op2, mode2))
24708         op2 = copy_to_mode_reg (mode2, op2);
24709       pat = GEN_FCN (icode) (op0, op1, op2);
24710       if (! pat)
24711         return 0;
24712       emit_insn (pat);
24713       return 0;
24714
24715     case IX86_BUILTIN_LDMXCSR:
24716       op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
24717       target = assign_386_stack_local (SImode, SLOT_VIRTUAL);
24718       emit_move_insn (target, op0);
24719       emit_insn (gen_sse_ldmxcsr (target));
24720       return 0;
24721
24722     case IX86_BUILTIN_STMXCSR:
24723       target = assign_386_stack_local (SImode, SLOT_VIRTUAL);
24724       emit_insn (gen_sse_stmxcsr (target));
24725       return copy_to_mode_reg (SImode, target);
24726
24727     case IX86_BUILTIN_CLFLUSH:
24728         arg0 = CALL_EXPR_ARG (exp, 0);
24729         op0 = expand_normal (arg0);
24730         icode = CODE_FOR_sse2_clflush;
24731         if (! (*insn_data[icode].operand[0].predicate) (op0, Pmode))
24732             op0 = copy_to_mode_reg (Pmode, op0);
24733
24734         emit_insn (gen_sse2_clflush (op0));
24735         return 0;
24736
24737     case IX86_BUILTIN_MONITOR:
24738       arg0 = CALL_EXPR_ARG (exp, 0);
24739       arg1 = CALL_EXPR_ARG (exp, 1);
24740       arg2 = CALL_EXPR_ARG (exp, 2);
24741       op0 = expand_normal (arg0);
24742       op1 = expand_normal (arg1);
24743       op2 = expand_normal (arg2);
24744       if (!REG_P (op0))
24745         op0 = copy_to_mode_reg (Pmode, op0);
24746       if (!REG_P (op1))
24747         op1 = copy_to_mode_reg (SImode, op1);
24748       if (!REG_P (op2))
24749         op2 = copy_to_mode_reg (SImode, op2);
24750       emit_insn ((*ix86_gen_monitor) (op0, op1, op2));
24751       return 0;
24752
24753     case IX86_BUILTIN_MWAIT:
24754       arg0 = CALL_EXPR_ARG (exp, 0);
24755       arg1 = CALL_EXPR_ARG (exp, 1);
24756       op0 = expand_normal (arg0);
24757       op1 = expand_normal (arg1);
24758       if (!REG_P (op0))
24759         op0 = copy_to_mode_reg (SImode, op0);
24760       if (!REG_P (op1))
24761         op1 = copy_to_mode_reg (SImode, op1);
24762       emit_insn (gen_sse3_mwait (op0, op1));
24763       return 0;
24764
24765     case IX86_BUILTIN_VEC_INIT_V2SI:
24766     case IX86_BUILTIN_VEC_INIT_V4HI:
24767     case IX86_BUILTIN_VEC_INIT_V8QI:
24768       return ix86_expand_vec_init_builtin (TREE_TYPE (exp), exp, target);
24769
24770     case IX86_BUILTIN_VEC_EXT_V2DF:
24771     case IX86_BUILTIN_VEC_EXT_V2DI:
24772     case IX86_BUILTIN_VEC_EXT_V4SF:
24773     case IX86_BUILTIN_VEC_EXT_V4SI:
24774     case IX86_BUILTIN_VEC_EXT_V8HI:
24775     case IX86_BUILTIN_VEC_EXT_V2SI:
24776     case IX86_BUILTIN_VEC_EXT_V4HI:
24777     case IX86_BUILTIN_VEC_EXT_V16QI:
24778       return ix86_expand_vec_ext_builtin (exp, target);
24779
24780     case IX86_BUILTIN_VEC_SET_V2DI:
24781     case IX86_BUILTIN_VEC_SET_V4SF:
24782     case IX86_BUILTIN_VEC_SET_V4SI:
24783     case IX86_BUILTIN_VEC_SET_V8HI:
24784     case IX86_BUILTIN_VEC_SET_V4HI:
24785     case IX86_BUILTIN_VEC_SET_V16QI:
24786       return ix86_expand_vec_set_builtin (exp);
24787
24788     case IX86_BUILTIN_INFQ:
24789       {
24790         REAL_VALUE_TYPE inf;
24791         rtx tmp;
24792
24793         real_inf (&inf);
24794         tmp = CONST_DOUBLE_FROM_REAL_VALUE (inf, mode);
24795
24796         tmp = validize_mem (force_const_mem (mode, tmp));
24797
24798         if (target == 0)
24799           target = gen_reg_rtx (mode);
24800
24801         emit_move_insn (target, tmp);
24802         return target;
24803       }
24804
24805     default:
24806       break;
24807     }
24808
24809   for (i = 0, d = bdesc_special_args;
24810        i < ARRAY_SIZE (bdesc_special_args);
24811        i++, d++)
24812     if (d->code == fcode)
24813       return ix86_expand_special_args_builtin (d, exp, target);
24814
24815   for (i = 0, d = bdesc_args;
24816        i < ARRAY_SIZE (bdesc_args);
24817        i++, d++)
24818     if (d->code == fcode)
24819       switch (fcode)
24820         {
24821         case IX86_BUILTIN_FABSQ:
24822         case IX86_BUILTIN_COPYSIGNQ:
24823           if (!TARGET_SSE2)
24824             /* Emit a normal call if SSE2 isn't available.  */
24825             return expand_call (exp, target, ignore);
24826         default:
24827           return ix86_expand_args_builtin (d, exp, target);
24828         }
24829
24830   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
24831     if (d->code == fcode)
24832       return ix86_expand_sse_comi (d, exp, target);
24833
24834   for (i = 0, d = bdesc_pcmpestr;
24835        i < ARRAY_SIZE (bdesc_pcmpestr);
24836        i++, d++)
24837     if (d->code == fcode)
24838       return ix86_expand_sse_pcmpestr (d, exp, target);
24839
24840   for (i = 0, d = bdesc_pcmpistr;
24841        i < ARRAY_SIZE (bdesc_pcmpistr);
24842        i++, d++)
24843     if (d->code == fcode)
24844       return ix86_expand_sse_pcmpistr (d, exp, target);
24845
24846   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
24847     if (d->code == fcode)
24848       return ix86_expand_multi_arg_builtin (d->icode, exp, target,
24849                                             (enum multi_arg_type)d->flag,
24850                                             d->comparison);
24851
24852   gcc_unreachable ();
24853 }
24854
24855 /* Returns a function decl for a vectorized version of the builtin function
24856    with builtin function code FN and the result vector type TYPE, or NULL_TREE
24857    if it is not available.  */
24858
24859 static tree
24860 ix86_builtin_vectorized_function (unsigned int fn, tree type_out,
24861                                   tree type_in)
24862 {
24863   enum machine_mode in_mode, out_mode;
24864   int in_n, out_n;
24865
24866   if (TREE_CODE (type_out) != VECTOR_TYPE
24867       || TREE_CODE (type_in) != VECTOR_TYPE)
24868     return NULL_TREE;
24869
24870   out_mode = TYPE_MODE (TREE_TYPE (type_out));
24871   out_n = TYPE_VECTOR_SUBPARTS (type_out);
24872   in_mode = TYPE_MODE (TREE_TYPE (type_in));
24873   in_n = TYPE_VECTOR_SUBPARTS (type_in);
24874
24875   switch (fn)
24876     {
24877     case BUILT_IN_SQRT:
24878       if (out_mode == DFmode && out_n == 2
24879           && in_mode == DFmode && in_n == 2)
24880         return ix86_builtins[IX86_BUILTIN_SQRTPD];
24881       break;
24882
24883     case BUILT_IN_SQRTF:
24884       if (out_mode == SFmode && out_n == 4
24885           && in_mode == SFmode && in_n == 4)
24886         return ix86_builtins[IX86_BUILTIN_SQRTPS_NR];
24887       break;
24888
24889     case BUILT_IN_LRINT:
24890       if (out_mode == SImode && out_n == 4
24891           && in_mode == DFmode && in_n == 2)
24892         return ix86_builtins[IX86_BUILTIN_VEC_PACK_SFIX];
24893       break;
24894
24895     case BUILT_IN_LRINTF:
24896       if (out_mode == SImode && out_n == 4
24897           && in_mode == SFmode && in_n == 4)
24898         return ix86_builtins[IX86_BUILTIN_CVTPS2DQ];
24899       break;
24900
24901     default:
24902       ;
24903     }
24904
24905   /* Dispatch to a handler for a vectorization library.  */
24906   if (ix86_veclib_handler)
24907     return (*ix86_veclib_handler)(fn, type_out, type_in);
24908
24909   return NULL_TREE;
24910 }
24911
24912 /* Handler for an SVML-style interface to
24913    a library with vectorized intrinsics.  */
24914
24915 static tree
24916 ix86_veclibabi_svml (enum built_in_function fn, tree type_out, tree type_in)
24917 {
24918   char name[20];
24919   tree fntype, new_fndecl, args;
24920   unsigned arity;
24921   const char *bname;
24922   enum machine_mode el_mode, in_mode;
24923   int n, in_n;
24924
24925   /* The SVML is suitable for unsafe math only.  */
24926   if (!flag_unsafe_math_optimizations)
24927     return NULL_TREE;
24928
24929   el_mode = TYPE_MODE (TREE_TYPE (type_out));
24930   n = TYPE_VECTOR_SUBPARTS (type_out);
24931   in_mode = TYPE_MODE (TREE_TYPE (type_in));
24932   in_n = TYPE_VECTOR_SUBPARTS (type_in);
24933   if (el_mode != in_mode
24934       || n != in_n)
24935     return NULL_TREE;
24936
24937   switch (fn)
24938     {
24939     case BUILT_IN_EXP:
24940     case BUILT_IN_LOG:
24941     case BUILT_IN_LOG10:
24942     case BUILT_IN_POW:
24943     case BUILT_IN_TANH:
24944     case BUILT_IN_TAN:
24945     case BUILT_IN_ATAN:
24946     case BUILT_IN_ATAN2:
24947     case BUILT_IN_ATANH:
24948     case BUILT_IN_CBRT:
24949     case BUILT_IN_SINH:
24950     case BUILT_IN_SIN:
24951     case BUILT_IN_ASINH:
24952     case BUILT_IN_ASIN:
24953     case BUILT_IN_COSH:
24954     case BUILT_IN_COS:
24955     case BUILT_IN_ACOSH:
24956     case BUILT_IN_ACOS:
24957       if (el_mode != DFmode || n != 2)
24958         return NULL_TREE;
24959       break;
24960
24961     case BUILT_IN_EXPF:
24962     case BUILT_IN_LOGF:
24963     case BUILT_IN_LOG10F:
24964     case BUILT_IN_POWF:
24965     case BUILT_IN_TANHF:
24966     case BUILT_IN_TANF:
24967     case BUILT_IN_ATANF:
24968     case BUILT_IN_ATAN2F:
24969     case BUILT_IN_ATANHF:
24970     case BUILT_IN_CBRTF:
24971     case BUILT_IN_SINHF:
24972     case BUILT_IN_SINF:
24973     case BUILT_IN_ASINHF:
24974     case BUILT_IN_ASINF:
24975     case BUILT_IN_COSHF:
24976     case BUILT_IN_COSF:
24977     case BUILT_IN_ACOSHF:
24978     case BUILT_IN_ACOSF:
24979       if (el_mode != SFmode || n != 4)
24980         return NULL_TREE;
24981       break;
24982
24983     default:
24984       return NULL_TREE;
24985     }
24986
24987   bname = IDENTIFIER_POINTER (DECL_NAME (implicit_built_in_decls[fn]));
24988
24989   if (fn == BUILT_IN_LOGF)
24990     strcpy (name, "vmlsLn4");
24991   else if (fn == BUILT_IN_LOG)
24992     strcpy (name, "vmldLn2");
24993   else if (n == 4)
24994     {
24995       sprintf (name, "vmls%s", bname+10);
24996       name[strlen (name)-1] = '4';
24997     }
24998   else
24999     sprintf (name, "vmld%s2", bname+10);
25000
25001   /* Convert to uppercase. */
25002   name[4] &= ~0x20;
25003
25004   arity = 0;
25005   for (args = DECL_ARGUMENTS (implicit_built_in_decls[fn]); args;
25006        args = TREE_CHAIN (args))
25007     arity++;
25008
25009   if (arity == 1)
25010     fntype = build_function_type_list (type_out, type_in, NULL);
25011   else
25012     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
25013
25014   /* Build a function declaration for the vectorized function.  */
25015   new_fndecl = build_decl (FUNCTION_DECL, get_identifier (name), fntype);
25016   TREE_PUBLIC (new_fndecl) = 1;
25017   DECL_EXTERNAL (new_fndecl) = 1;
25018   DECL_IS_NOVOPS (new_fndecl) = 1;
25019   TREE_READONLY (new_fndecl) = 1;
25020
25021   return new_fndecl;
25022 }
25023
25024 /* Handler for an ACML-style interface to
25025    a library with vectorized intrinsics.  */
25026
25027 static tree
25028 ix86_veclibabi_acml (enum built_in_function fn, tree type_out, tree type_in)
25029 {
25030   char name[20] = "__vr.._";
25031   tree fntype, new_fndecl, args;
25032   unsigned arity;
25033   const char *bname;
25034   enum machine_mode el_mode, in_mode;
25035   int n, in_n;
25036
25037   /* The ACML is 64bits only and suitable for unsafe math only as
25038      it does not correctly support parts of IEEE with the required
25039      precision such as denormals.  */
25040   if (!TARGET_64BIT
25041       || !flag_unsafe_math_optimizations)
25042     return NULL_TREE;
25043
25044   el_mode = TYPE_MODE (TREE_TYPE (type_out));
25045   n = TYPE_VECTOR_SUBPARTS (type_out);
25046   in_mode = TYPE_MODE (TREE_TYPE (type_in));
25047   in_n = TYPE_VECTOR_SUBPARTS (type_in);
25048   if (el_mode != in_mode
25049       || n != in_n)
25050     return NULL_TREE;
25051
25052   switch (fn)
25053     {
25054     case BUILT_IN_SIN:
25055     case BUILT_IN_COS:
25056     case BUILT_IN_EXP:
25057     case BUILT_IN_LOG:
25058     case BUILT_IN_LOG2:
25059     case BUILT_IN_LOG10:
25060       name[4] = 'd';
25061       name[5] = '2';
25062       if (el_mode != DFmode
25063           || n != 2)
25064         return NULL_TREE;
25065       break;
25066
25067     case BUILT_IN_SINF:
25068     case BUILT_IN_COSF:
25069     case BUILT_IN_EXPF:
25070     case BUILT_IN_POWF:
25071     case BUILT_IN_LOGF:
25072     case BUILT_IN_LOG2F:
25073     case BUILT_IN_LOG10F:
25074       name[4] = 's';
25075       name[5] = '4';
25076       if (el_mode != SFmode
25077           || n != 4)
25078         return NULL_TREE;
25079       break;
25080
25081     default:
25082       return NULL_TREE;
25083     }
25084
25085   bname = IDENTIFIER_POINTER (DECL_NAME (implicit_built_in_decls[fn]));
25086   sprintf (name + 7, "%s", bname+10);
25087
25088   arity = 0;
25089   for (args = DECL_ARGUMENTS (implicit_built_in_decls[fn]); args;
25090        args = TREE_CHAIN (args))
25091     arity++;
25092
25093   if (arity == 1)
25094     fntype = build_function_type_list (type_out, type_in, NULL);
25095   else
25096     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
25097
25098   /* Build a function declaration for the vectorized function.  */
25099   new_fndecl = build_decl (FUNCTION_DECL, get_identifier (name), fntype);
25100   TREE_PUBLIC (new_fndecl) = 1;
25101   DECL_EXTERNAL (new_fndecl) = 1;
25102   DECL_IS_NOVOPS (new_fndecl) = 1;
25103   TREE_READONLY (new_fndecl) = 1;
25104
25105   return new_fndecl;
25106 }
25107
25108
25109 /* Returns a decl of a function that implements conversion of an integer vector
25110    into a floating-point vector, or vice-versa. TYPE is the type of the integer
25111    side of the conversion.
25112    Return NULL_TREE if it is not available.  */
25113
25114 static tree
25115 ix86_vectorize_builtin_conversion (unsigned int code, tree type)
25116 {
25117   if (TREE_CODE (type) != VECTOR_TYPE)
25118     return NULL_TREE;
25119
25120   switch (code)
25121     {
25122     case FLOAT_EXPR:
25123       switch (TYPE_MODE (type))
25124         {
25125         case V4SImode:
25126           return ix86_builtins[IX86_BUILTIN_CVTDQ2PS];
25127         default:
25128           return NULL_TREE;
25129         }
25130
25131     case FIX_TRUNC_EXPR:
25132       switch (TYPE_MODE (type))
25133         {
25134         case V4SImode:
25135           return ix86_builtins[IX86_BUILTIN_CVTTPS2DQ];
25136         default:
25137           return NULL_TREE;
25138         }
25139     default:
25140       return NULL_TREE;
25141
25142     }
25143 }
25144
25145 /* Returns a code for a target-specific builtin that implements
25146    reciprocal of the function, or NULL_TREE if not available.  */
25147
25148 static tree
25149 ix86_builtin_reciprocal (unsigned int fn, bool md_fn,
25150                          bool sqrt ATTRIBUTE_UNUSED)
25151 {
25152   if (! (TARGET_SSE_MATH && TARGET_RECIP && !optimize_insn_for_size_p ()
25153          && flag_finite_math_only && !flag_trapping_math
25154          && flag_unsafe_math_optimizations))
25155     return NULL_TREE;
25156
25157   if (md_fn)
25158     /* Machine dependent builtins.  */
25159     switch (fn)
25160       {
25161         /* Vectorized version of sqrt to rsqrt conversion.  */
25162       case IX86_BUILTIN_SQRTPS_NR:
25163         return ix86_builtins[IX86_BUILTIN_RSQRTPS_NR];
25164
25165       default:
25166         return NULL_TREE;
25167       }
25168   else
25169     /* Normal builtins.  */
25170     switch (fn)
25171       {
25172         /* Sqrt to rsqrt conversion.  */
25173       case BUILT_IN_SQRTF:
25174         return ix86_builtins[IX86_BUILTIN_RSQRTF];
25175
25176       default:
25177         return NULL_TREE;
25178       }
25179 }
25180
25181 /* Store OPERAND to the memory after reload is completed.  This means
25182    that we can't easily use assign_stack_local.  */
25183 rtx
25184 ix86_force_to_memory (enum machine_mode mode, rtx operand)
25185 {
25186   rtx result;
25187
25188   gcc_assert (reload_completed);
25189   if (!TARGET_64BIT_MS_ABI && TARGET_RED_ZONE)
25190     {
25191       result = gen_rtx_MEM (mode,
25192                             gen_rtx_PLUS (Pmode,
25193                                           stack_pointer_rtx,
25194                                           GEN_INT (-RED_ZONE_SIZE)));
25195       emit_move_insn (result, operand);
25196     }
25197   else if ((TARGET_64BIT_MS_ABI || !TARGET_RED_ZONE) && TARGET_64BIT)
25198     {
25199       switch (mode)
25200         {
25201         case HImode:
25202         case SImode:
25203           operand = gen_lowpart (DImode, operand);
25204           /* FALLTHRU */
25205         case DImode:
25206           emit_insn (
25207                       gen_rtx_SET (VOIDmode,
25208                                    gen_rtx_MEM (DImode,
25209                                                 gen_rtx_PRE_DEC (DImode,
25210                                                         stack_pointer_rtx)),
25211                                    operand));
25212           break;
25213         default:
25214           gcc_unreachable ();
25215         }
25216       result = gen_rtx_MEM (mode, stack_pointer_rtx);
25217     }
25218   else
25219     {
25220       switch (mode)
25221         {
25222         case DImode:
25223           {
25224             rtx operands[2];
25225             split_di (&operand, 1, operands, operands + 1);
25226             emit_insn (
25227                         gen_rtx_SET (VOIDmode,
25228                                      gen_rtx_MEM (SImode,
25229                                                   gen_rtx_PRE_DEC (Pmode,
25230                                                         stack_pointer_rtx)),
25231                                      operands[1]));
25232             emit_insn (
25233                         gen_rtx_SET (VOIDmode,
25234                                      gen_rtx_MEM (SImode,
25235                                                   gen_rtx_PRE_DEC (Pmode,
25236                                                         stack_pointer_rtx)),
25237                                      operands[0]));
25238           }
25239           break;
25240         case HImode:
25241           /* Store HImodes as SImodes.  */
25242           operand = gen_lowpart (SImode, operand);
25243           /* FALLTHRU */
25244         case SImode:
25245           emit_insn (
25246                       gen_rtx_SET (VOIDmode,
25247                                    gen_rtx_MEM (GET_MODE (operand),
25248                                                 gen_rtx_PRE_DEC (SImode,
25249                                                         stack_pointer_rtx)),
25250                                    operand));
25251           break;
25252         default:
25253           gcc_unreachable ();
25254         }
25255       result = gen_rtx_MEM (mode, stack_pointer_rtx);
25256     }
25257   return result;
25258 }
25259
25260 /* Free operand from the memory.  */
25261 void
25262 ix86_free_from_memory (enum machine_mode mode)
25263 {
25264   if (!TARGET_RED_ZONE || TARGET_64BIT_MS_ABI)
25265     {
25266       int size;
25267
25268       if (mode == DImode || TARGET_64BIT)
25269         size = 8;
25270       else
25271         size = 4;
25272       /* Use LEA to deallocate stack space.  In peephole2 it will be converted
25273          to pop or add instruction if registers are available.  */
25274       emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
25275                               gen_rtx_PLUS (Pmode, stack_pointer_rtx,
25276                                             GEN_INT (size))));
25277     }
25278 }
25279
25280 /* Put float CONST_DOUBLE in the constant pool instead of fp regs.
25281    QImode must go into class Q_REGS.
25282    Narrow ALL_REGS to GENERAL_REGS.  This supports allowing movsf and
25283    movdf to do mem-to-mem moves through integer regs.  */
25284 enum reg_class
25285 ix86_preferred_reload_class (rtx x, enum reg_class regclass)
25286 {
25287   enum machine_mode mode = GET_MODE (x);
25288
25289   /* We're only allowed to return a subclass of CLASS.  Many of the
25290      following checks fail for NO_REGS, so eliminate that early.  */
25291   if (regclass == NO_REGS)
25292     return NO_REGS;
25293
25294   /* All classes can load zeros.  */
25295   if (x == CONST0_RTX (mode))
25296     return regclass;
25297
25298   /* Force constants into memory if we are loading a (nonzero) constant into
25299      an MMX or SSE register.  This is because there are no MMX/SSE instructions
25300      to load from a constant.  */
25301   if (CONSTANT_P (x)
25302       && (MAYBE_MMX_CLASS_P (regclass) || MAYBE_SSE_CLASS_P (regclass)))
25303     return NO_REGS;
25304
25305   /* Prefer SSE regs only, if we can use them for math.  */
25306   if (TARGET_SSE_MATH && !TARGET_MIX_SSE_I387 && SSE_FLOAT_MODE_P (mode))
25307     return SSE_CLASS_P (regclass) ? regclass : NO_REGS;
25308
25309   /* Floating-point constants need more complex checks.  */
25310   if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) != VOIDmode)
25311     {
25312       /* General regs can load everything.  */
25313       if (reg_class_subset_p (regclass, GENERAL_REGS))
25314         return regclass;
25315
25316       /* Floats can load 0 and 1 plus some others.  Note that we eliminated
25317          zero above.  We only want to wind up preferring 80387 registers if
25318          we plan on doing computation with them.  */
25319       if (TARGET_80387
25320           && standard_80387_constant_p (x))
25321         {
25322           /* Limit class to non-sse.  */
25323           if (regclass == FLOAT_SSE_REGS)
25324             return FLOAT_REGS;
25325           if (regclass == FP_TOP_SSE_REGS)
25326             return FP_TOP_REG;
25327           if (regclass == FP_SECOND_SSE_REGS)
25328             return FP_SECOND_REG;
25329           if (regclass == FLOAT_INT_REGS || regclass == FLOAT_REGS)
25330             return regclass;
25331         }
25332
25333       return NO_REGS;
25334     }
25335
25336   /* Generally when we see PLUS here, it's the function invariant
25337      (plus soft-fp const_int).  Which can only be computed into general
25338      regs.  */
25339   if (GET_CODE (x) == PLUS)
25340     return reg_class_subset_p (regclass, GENERAL_REGS) ? regclass : NO_REGS;
25341
25342   /* QImode constants are easy to load, but non-constant QImode data
25343      must go into Q_REGS.  */
25344   if (GET_MODE (x) == QImode && !CONSTANT_P (x))
25345     {
25346       if (reg_class_subset_p (regclass, Q_REGS))
25347         return regclass;
25348       if (reg_class_subset_p (Q_REGS, regclass))
25349         return Q_REGS;
25350       return NO_REGS;
25351     }
25352
25353   return regclass;
25354 }
25355
25356 /* Discourage putting floating-point values in SSE registers unless
25357    SSE math is being used, and likewise for the 387 registers.  */
25358 enum reg_class
25359 ix86_preferred_output_reload_class (rtx x, enum reg_class regclass)
25360 {
25361   enum machine_mode mode = GET_MODE (x);
25362
25363   /* Restrict the output reload class to the register bank that we are doing
25364      math on.  If we would like not to return a subset of CLASS, reject this
25365      alternative: if reload cannot do this, it will still use its choice.  */
25366   mode = GET_MODE (x);
25367   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
25368     return MAYBE_SSE_CLASS_P (regclass) ? SSE_REGS : NO_REGS;
25369
25370   if (X87_FLOAT_MODE_P (mode))
25371     {
25372       if (regclass == FP_TOP_SSE_REGS)
25373         return FP_TOP_REG;
25374       else if (regclass == FP_SECOND_SSE_REGS)
25375         return FP_SECOND_REG;
25376       else
25377         return FLOAT_CLASS_P (regclass) ? regclass : NO_REGS;
25378     }
25379
25380   return regclass;
25381 }
25382
25383 static enum reg_class
25384 ix86_secondary_reload (bool in_p, rtx x, enum reg_class rclass,
25385                        enum machine_mode mode,
25386                        secondary_reload_info *sri ATTRIBUTE_UNUSED)
25387 {
25388   /* QImode spills from non-QI registers require
25389      intermediate register on 32bit targets.  */
25390   if (!in_p && mode == QImode && !TARGET_64BIT
25391       && (rclass == GENERAL_REGS
25392           || rclass == LEGACY_REGS
25393           || rclass == INDEX_REGS))
25394     {
25395       int regno;
25396
25397       if (REG_P (x))
25398         regno = REGNO (x);
25399       else
25400         regno = -1;
25401
25402       if (regno >= FIRST_PSEUDO_REGISTER || GET_CODE (x) == SUBREG)
25403         regno = true_regnum (x);
25404
25405       /* Return Q_REGS if the operand is in memory.  */
25406       if (regno == -1)
25407         return Q_REGS;
25408     }
25409
25410   return NO_REGS;
25411 }
25412
25413 /* If we are copying between general and FP registers, we need a memory
25414    location. The same is true for SSE and MMX registers.
25415
25416    To optimize register_move_cost performance, allow inline variant.
25417
25418    The macro can't work reliably when one of the CLASSES is class containing
25419    registers from multiple units (SSE, MMX, integer).  We avoid this by never
25420    combining those units in single alternative in the machine description.
25421    Ensure that this constraint holds to avoid unexpected surprises.
25422
25423    When STRICT is false, we are being called from REGISTER_MOVE_COST, so do not
25424    enforce these sanity checks.  */
25425
25426 static inline int
25427 inline_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
25428                               enum machine_mode mode, int strict)
25429 {
25430   if (MAYBE_FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class1)
25431       || MAYBE_FLOAT_CLASS_P (class2) != FLOAT_CLASS_P (class2)
25432       || MAYBE_SSE_CLASS_P (class1) != SSE_CLASS_P (class1)
25433       || MAYBE_SSE_CLASS_P (class2) != SSE_CLASS_P (class2)
25434       || MAYBE_MMX_CLASS_P (class1) != MMX_CLASS_P (class1)
25435       || MAYBE_MMX_CLASS_P (class2) != MMX_CLASS_P (class2))
25436     {
25437       gcc_assert (!strict);
25438       return true;
25439     }
25440
25441   if (FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class2))
25442     return true;
25443
25444   /* ??? This is a lie.  We do have moves between mmx/general, and for
25445      mmx/sse2.  But by saying we need secondary memory we discourage the
25446      register allocator from using the mmx registers unless needed.  */
25447   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2))
25448     return true;
25449
25450   if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
25451     {
25452       /* SSE1 doesn't have any direct moves from other classes.  */
25453       if (!TARGET_SSE2)
25454         return true;
25455
25456       /* If the target says that inter-unit moves are more expensive
25457          than moving through memory, then don't generate them.  */
25458       if (!TARGET_INTER_UNIT_MOVES)
25459         return true;
25460
25461       /* Between SSE and general, we have moves no larger than word size.  */
25462       if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
25463         return true;
25464     }
25465
25466   return false;
25467 }
25468
25469 int
25470 ix86_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
25471                               enum machine_mode mode, int strict)
25472 {
25473   return inline_secondary_memory_needed (class1, class2, mode, strict);
25474 }
25475
25476 /* Return true if the registers in CLASS cannot represent the change from
25477    modes FROM to TO.  */
25478
25479 bool
25480 ix86_cannot_change_mode_class (enum machine_mode from, enum machine_mode to,
25481                                enum reg_class regclass)
25482 {
25483   if (from == to)
25484     return false;
25485
25486   /* x87 registers can't do subreg at all, as all values are reformatted
25487      to extended precision.  */
25488   if (MAYBE_FLOAT_CLASS_P (regclass))
25489     return true;
25490
25491   if (MAYBE_SSE_CLASS_P (regclass) || MAYBE_MMX_CLASS_P (regclass))
25492     {
25493       /* Vector registers do not support QI or HImode loads.  If we don't
25494          disallow a change to these modes, reload will assume it's ok to
25495          drop the subreg from (subreg:SI (reg:HI 100) 0).  This affects
25496          the vec_dupv4hi pattern.  */
25497       if (GET_MODE_SIZE (from) < 4)
25498         return true;
25499
25500       /* Vector registers do not support subreg with nonzero offsets, which
25501          are otherwise valid for integer registers.  Since we can't see
25502          whether we have a nonzero offset from here, prohibit all
25503          nonparadoxical subregs changing size.  */
25504       if (GET_MODE_SIZE (to) < GET_MODE_SIZE (from))
25505         return true;
25506     }
25507
25508   return false;
25509 }
25510
25511 /* Return the cost of moving data of mode M between a
25512    register and memory.  A value of 2 is the default; this cost is
25513    relative to those in `REGISTER_MOVE_COST'.
25514
25515    This function is used extensively by register_move_cost that is used to
25516    build tables at startup.  Make it inline in this case.
25517    When IN is 2, return maximum of in and out move cost.
25518
25519    If moving between registers and memory is more expensive than
25520    between two registers, you should define this macro to express the
25521    relative cost.
25522
25523    Model also increased moving costs of QImode registers in non
25524    Q_REGS classes.
25525  */
25526 static inline int
25527 inline_memory_move_cost (enum machine_mode mode, enum reg_class regclass,
25528                          int in)
25529 {
25530   int cost;
25531   if (FLOAT_CLASS_P (regclass))
25532     {
25533       int index;
25534       switch (mode)
25535         {
25536           case SFmode:
25537             index = 0;
25538             break;
25539           case DFmode:
25540             index = 1;
25541             break;
25542           case XFmode:
25543             index = 2;
25544             break;
25545           default:
25546             return 100;
25547         }
25548       if (in == 2)
25549         return MAX (ix86_cost->fp_load [index], ix86_cost->fp_store [index]);
25550       return in ? ix86_cost->fp_load [index] : ix86_cost->fp_store [index];
25551     }
25552   if (SSE_CLASS_P (regclass))
25553     {
25554       int index;
25555       switch (GET_MODE_SIZE (mode))
25556         {
25557           case 4:
25558             index = 0;
25559             break;
25560           case 8:
25561             index = 1;
25562             break;
25563           case 16:
25564             index = 2;
25565             break;
25566           default:
25567             return 100;
25568         }
25569       if (in == 2)
25570         return MAX (ix86_cost->sse_load [index], ix86_cost->sse_store [index]);
25571       return in ? ix86_cost->sse_load [index] : ix86_cost->sse_store [index];
25572     }
25573   if (MMX_CLASS_P (regclass))
25574     {
25575       int index;
25576       switch (GET_MODE_SIZE (mode))
25577         {
25578           case 4:
25579             index = 0;
25580             break;
25581           case 8:
25582             index = 1;
25583             break;
25584           default:
25585             return 100;
25586         }
25587       if (in)
25588         return MAX (ix86_cost->mmx_load [index], ix86_cost->mmx_store [index]);
25589       return in ? ix86_cost->mmx_load [index] : ix86_cost->mmx_store [index];
25590     }
25591   switch (GET_MODE_SIZE (mode))
25592     {
25593       case 1:
25594         if (Q_CLASS_P (regclass) || TARGET_64BIT)
25595           {
25596             if (!in)
25597               return ix86_cost->int_store[0];
25598             if (TARGET_PARTIAL_REG_DEPENDENCY
25599                 && optimize_function_for_speed_p (cfun))
25600               cost = ix86_cost->movzbl_load;
25601             else
25602               cost = ix86_cost->int_load[0];
25603             if (in == 2)
25604               return MAX (cost, ix86_cost->int_store[0]);
25605             return cost;
25606           }
25607         else
25608           {
25609            if (in == 2)
25610              return MAX (ix86_cost->movzbl_load, ix86_cost->int_store[0] + 4);
25611            if (in)
25612              return ix86_cost->movzbl_load;
25613            else
25614              return ix86_cost->int_store[0] + 4;
25615           }
25616         break;
25617       case 2:
25618         if (in == 2)
25619           return MAX (ix86_cost->int_load[1], ix86_cost->int_store[1]);
25620         return in ? ix86_cost->int_load[1] : ix86_cost->int_store[1];
25621       default:
25622         /* Compute number of 32bit moves needed.  TFmode is moved as XFmode.  */
25623         if (mode == TFmode)
25624           mode = XFmode;
25625         if (in == 2)
25626           cost = MAX (ix86_cost->int_load[2] , ix86_cost->int_store[2]);
25627         else if (in)
25628           cost = ix86_cost->int_load[2];
25629         else
25630           cost = ix86_cost->int_store[2];
25631         return (cost * (((int) GET_MODE_SIZE (mode)
25632                         + UNITS_PER_WORD - 1) / UNITS_PER_WORD));
25633     }
25634 }
25635
25636 int
25637 ix86_memory_move_cost (enum machine_mode mode, enum reg_class regclass, int in)
25638 {
25639   return inline_memory_move_cost (mode, regclass, in);
25640 }
25641
25642
25643 /* Return the cost of moving data from a register in class CLASS1 to
25644    one in class CLASS2.
25645
25646    It is not required that the cost always equal 2 when FROM is the same as TO;
25647    on some machines it is expensive to move between registers if they are not
25648    general registers.  */
25649
25650 int
25651 ix86_register_move_cost (enum machine_mode mode, enum reg_class class1,
25652                          enum reg_class class2)
25653 {
25654   /* In case we require secondary memory, compute cost of the store followed
25655      by load.  In order to avoid bad register allocation choices, we need
25656      for this to be *at least* as high as the symmetric MEMORY_MOVE_COST.  */
25657
25658   if (inline_secondary_memory_needed (class1, class2, mode, 0))
25659     {
25660       int cost = 1;
25661
25662       cost += inline_memory_move_cost (mode, class1, 2);
25663       cost += inline_memory_move_cost (mode, class2, 2);
25664
25665       /* In case of copying from general_purpose_register we may emit multiple
25666          stores followed by single load causing memory size mismatch stall.
25667          Count this as arbitrarily high cost of 20.  */
25668       if (CLASS_MAX_NREGS (class1, mode) > CLASS_MAX_NREGS (class2, mode))
25669         cost += 20;
25670
25671       /* In the case of FP/MMX moves, the registers actually overlap, and we
25672          have to switch modes in order to treat them differently.  */
25673       if ((MMX_CLASS_P (class1) && MAYBE_FLOAT_CLASS_P (class2))
25674           || (MMX_CLASS_P (class2) && MAYBE_FLOAT_CLASS_P (class1)))
25675         cost += 20;
25676
25677       return cost;
25678     }
25679
25680   /* Moves between SSE/MMX and integer unit are expensive.  */
25681   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2)
25682       || SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
25683
25684     /* ??? By keeping returned value relatively high, we limit the number
25685        of moves between integer and MMX/SSE registers for all targets.
25686        Additionally, high value prevents problem with x86_modes_tieable_p(),
25687        where integer modes in MMX/SSE registers are not tieable
25688        because of missing QImode and HImode moves to, from or between
25689        MMX/SSE registers.  */
25690     return MAX (8, ix86_cost->mmxsse_to_integer);
25691
25692   if (MAYBE_FLOAT_CLASS_P (class1))
25693     return ix86_cost->fp_move;
25694   if (MAYBE_SSE_CLASS_P (class1))
25695     return ix86_cost->sse_move;
25696   if (MAYBE_MMX_CLASS_P (class1))
25697     return ix86_cost->mmx_move;
25698   return 2;
25699 }
25700
25701 /* Return 1 if hard register REGNO can hold a value of machine-mode MODE.  */
25702
25703 bool
25704 ix86_hard_regno_mode_ok (int regno, enum machine_mode mode)
25705 {
25706   /* Flags and only flags can only hold CCmode values.  */
25707   if (CC_REGNO_P (regno))
25708     return GET_MODE_CLASS (mode) == MODE_CC;
25709   if (GET_MODE_CLASS (mode) == MODE_CC
25710       || GET_MODE_CLASS (mode) == MODE_RANDOM
25711       || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
25712     return 0;
25713   if (FP_REGNO_P (regno))
25714     return VALID_FP_MODE_P (mode);
25715   if (SSE_REGNO_P (regno))
25716     {
25717       /* We implement the move patterns for all vector modes into and
25718          out of SSE registers, even when no operation instructions
25719          are available.  OImode move is available only when AVX is
25720          enabled.  */
25721       return ((TARGET_AVX && mode == OImode)
25722               || VALID_AVX256_REG_MODE (mode)
25723               || VALID_SSE_REG_MODE (mode)
25724               || VALID_SSE2_REG_MODE (mode)
25725               || VALID_MMX_REG_MODE (mode)
25726               || VALID_MMX_REG_MODE_3DNOW (mode));
25727     }
25728   if (MMX_REGNO_P (regno))
25729     {
25730       /* We implement the move patterns for 3DNOW modes even in MMX mode,
25731          so if the register is available at all, then we can move data of
25732          the given mode into or out of it.  */
25733       return (VALID_MMX_REG_MODE (mode)
25734               || VALID_MMX_REG_MODE_3DNOW (mode));
25735     }
25736
25737   if (mode == QImode)
25738     {
25739       /* Take care for QImode values - they can be in non-QI regs,
25740          but then they do cause partial register stalls.  */
25741       if (regno < 4 || TARGET_64BIT)
25742         return 1;
25743       if (!TARGET_PARTIAL_REG_STALL)
25744         return 1;
25745       return reload_in_progress || reload_completed;
25746     }
25747   /* We handle both integer and floats in the general purpose registers.  */
25748   else if (VALID_INT_MODE_P (mode))
25749     return 1;
25750   else if (VALID_FP_MODE_P (mode))
25751     return 1;
25752   else if (VALID_DFP_MODE_P (mode))
25753     return 1;
25754   /* Lots of MMX code casts 8 byte vector modes to DImode.  If we then go
25755      on to use that value in smaller contexts, this can easily force a
25756      pseudo to be allocated to GENERAL_REGS.  Since this is no worse than
25757      supporting DImode, allow it.  */
25758   else if (VALID_MMX_REG_MODE_3DNOW (mode) || VALID_MMX_REG_MODE (mode))
25759     return 1;
25760
25761   return 0;
25762 }
25763
25764 /* A subroutine of ix86_modes_tieable_p.  Return true if MODE is a
25765    tieable integer mode.  */
25766
25767 static bool
25768 ix86_tieable_integer_mode_p (enum machine_mode mode)
25769 {
25770   switch (mode)
25771     {
25772     case HImode:
25773     case SImode:
25774       return true;
25775
25776     case QImode:
25777       return TARGET_64BIT || !TARGET_PARTIAL_REG_STALL;
25778
25779     case DImode:
25780       return TARGET_64BIT;
25781
25782     default:
25783       return false;
25784     }
25785 }
25786
25787 /* Return true if MODE1 is accessible in a register that can hold MODE2
25788    without copying.  That is, all register classes that can hold MODE2
25789    can also hold MODE1.  */
25790
25791 bool
25792 ix86_modes_tieable_p (enum machine_mode mode1, enum machine_mode mode2)
25793 {
25794   if (mode1 == mode2)
25795     return true;
25796
25797   if (ix86_tieable_integer_mode_p (mode1)
25798       && ix86_tieable_integer_mode_p (mode2))
25799     return true;
25800
25801   /* MODE2 being XFmode implies fp stack or general regs, which means we
25802      can tie any smaller floating point modes to it.  Note that we do not
25803      tie this with TFmode.  */
25804   if (mode2 == XFmode)
25805     return mode1 == SFmode || mode1 == DFmode;
25806
25807   /* MODE2 being DFmode implies fp stack, general or sse regs, which means
25808      that we can tie it with SFmode.  */
25809   if (mode2 == DFmode)
25810     return mode1 == SFmode;
25811
25812   /* If MODE2 is only appropriate for an SSE register, then tie with
25813      any other mode acceptable to SSE registers.  */
25814   if (GET_MODE_SIZE (mode2) == 16
25815       && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
25816     return (GET_MODE_SIZE (mode1) == 16
25817             && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1));
25818
25819   /* If MODE2 is appropriate for an MMX register, then tie
25820      with any other mode acceptable to MMX registers.  */
25821   if (GET_MODE_SIZE (mode2) == 8
25822       && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode2))
25823     return (GET_MODE_SIZE (mode1) == 8
25824             && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode1));
25825
25826   return false;
25827 }
25828
25829 /* Compute a (partial) cost for rtx X.  Return true if the complete
25830    cost has been computed, and false if subexpressions should be
25831    scanned.  In either case, *TOTAL contains the cost result.  */
25832
25833 static bool
25834 ix86_rtx_costs (rtx x, int code, int outer_code_i, int *total, bool speed)
25835 {
25836   enum rtx_code outer_code = (enum rtx_code) outer_code_i;
25837   enum machine_mode mode = GET_MODE (x);
25838   const struct processor_costs *cost = speed ? ix86_cost : &ix86_size_cost;
25839
25840   switch (code)
25841     {
25842     case CONST_INT:
25843     case CONST:
25844     case LABEL_REF:
25845     case SYMBOL_REF:
25846       if (TARGET_64BIT && !x86_64_immediate_operand (x, VOIDmode))
25847         *total = 3;
25848       else if (TARGET_64BIT && !x86_64_zext_immediate_operand (x, VOIDmode))
25849         *total = 2;
25850       else if (flag_pic && SYMBOLIC_CONST (x)
25851                && (!TARGET_64BIT
25852                    || (!GET_CODE (x) != LABEL_REF
25853                        && (GET_CODE (x) != SYMBOL_REF
25854                            || !SYMBOL_REF_LOCAL_P (x)))))
25855         *total = 1;
25856       else
25857         *total = 0;
25858       return true;
25859
25860     case CONST_DOUBLE:
25861       if (mode == VOIDmode)
25862         *total = 0;
25863       else
25864         switch (standard_80387_constant_p (x))
25865           {
25866           case 1: /* 0.0 */
25867             *total = 1;
25868             break;
25869           default: /* Other constants */
25870             *total = 2;
25871             break;
25872           case 0:
25873           case -1:
25874             /* Start with (MEM (SYMBOL_REF)), since that's where
25875                it'll probably end up.  Add a penalty for size.  */
25876             *total = (COSTS_N_INSNS (1)
25877                       + (flag_pic != 0 && !TARGET_64BIT)
25878                       + (mode == SFmode ? 0 : mode == DFmode ? 1 : 2));
25879             break;
25880           }
25881       return true;
25882
25883     case ZERO_EXTEND:
25884       /* The zero extensions is often completely free on x86_64, so make
25885          it as cheap as possible.  */
25886       if (TARGET_64BIT && mode == DImode
25887           && GET_MODE (XEXP (x, 0)) == SImode)
25888         *total = 1;
25889       else if (TARGET_ZERO_EXTEND_WITH_AND)
25890         *total = cost->add;
25891       else
25892         *total = cost->movzx;
25893       return false;
25894
25895     case SIGN_EXTEND:
25896       *total = cost->movsx;
25897       return false;
25898
25899     case ASHIFT:
25900       if (CONST_INT_P (XEXP (x, 1))
25901           && (GET_MODE (XEXP (x, 0)) != DImode || TARGET_64BIT))
25902         {
25903           HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
25904           if (value == 1)
25905             {
25906               *total = cost->add;
25907               return false;
25908             }
25909           if ((value == 2 || value == 3)
25910               && cost->lea <= cost->shift_const)
25911             {
25912               *total = cost->lea;
25913               return false;
25914             }
25915         }
25916       /* FALLTHRU */
25917
25918     case ROTATE:
25919     case ASHIFTRT:
25920     case LSHIFTRT:
25921     case ROTATERT:
25922       if (!TARGET_64BIT && GET_MODE (XEXP (x, 0)) == DImode)
25923         {
25924           if (CONST_INT_P (XEXP (x, 1)))
25925             {
25926               if (INTVAL (XEXP (x, 1)) > 32)
25927                 *total = cost->shift_const + COSTS_N_INSNS (2);
25928               else
25929                 *total = cost->shift_const * 2;
25930             }
25931           else
25932             {
25933               if (GET_CODE (XEXP (x, 1)) == AND)
25934                 *total = cost->shift_var * 2;
25935               else
25936                 *total = cost->shift_var * 6 + COSTS_N_INSNS (2);
25937             }
25938         }
25939       else
25940         {
25941           if (CONST_INT_P (XEXP (x, 1)))
25942             *total = cost->shift_const;
25943           else
25944             *total = cost->shift_var;
25945         }
25946       return false;
25947
25948     case MULT:
25949       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
25950         {
25951           /* ??? SSE scalar cost should be used here.  */
25952           *total = cost->fmul;
25953           return false;
25954         }
25955       else if (X87_FLOAT_MODE_P (mode))
25956         {
25957           *total = cost->fmul;
25958           return false;
25959         }
25960       else if (FLOAT_MODE_P (mode))
25961         {
25962           /* ??? SSE vector cost should be used here.  */
25963           *total = cost->fmul;
25964           return false;
25965         }
25966       else
25967         {
25968           rtx op0 = XEXP (x, 0);
25969           rtx op1 = XEXP (x, 1);
25970           int nbits;
25971           if (CONST_INT_P (XEXP (x, 1)))
25972             {
25973               unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
25974               for (nbits = 0; value != 0; value &= value - 1)
25975                 nbits++;
25976             }
25977           else
25978             /* This is arbitrary.  */
25979             nbits = 7;
25980
25981           /* Compute costs correctly for widening multiplication.  */
25982           if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
25983               && GET_MODE_SIZE (GET_MODE (XEXP (op0, 0))) * 2
25984                  == GET_MODE_SIZE (mode))
25985             {
25986               int is_mulwiden = 0;
25987               enum machine_mode inner_mode = GET_MODE (op0);
25988
25989               if (GET_CODE (op0) == GET_CODE (op1))
25990                 is_mulwiden = 1, op1 = XEXP (op1, 0);
25991               else if (CONST_INT_P (op1))
25992                 {
25993                   if (GET_CODE (op0) == SIGN_EXTEND)
25994                     is_mulwiden = trunc_int_for_mode (INTVAL (op1), inner_mode)
25995                                   == INTVAL (op1);
25996                   else
25997                     is_mulwiden = !(INTVAL (op1) & ~GET_MODE_MASK (inner_mode));
25998                 }
25999
26000               if (is_mulwiden)
26001                 op0 = XEXP (op0, 0), mode = GET_MODE (op0);
26002             }
26003
26004           *total = (cost->mult_init[MODE_INDEX (mode)]
26005                     + nbits * cost->mult_bit
26006                     + rtx_cost (op0, outer_code, speed) + rtx_cost (op1, outer_code, speed));
26007
26008           return true;
26009         }
26010
26011     case DIV:
26012     case UDIV:
26013     case MOD:
26014     case UMOD:
26015       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
26016         /* ??? SSE cost should be used here.  */
26017         *total = cost->fdiv;
26018       else if (X87_FLOAT_MODE_P (mode))
26019         *total = cost->fdiv;
26020       else if (FLOAT_MODE_P (mode))
26021         /* ??? SSE vector cost should be used here.  */
26022         *total = cost->fdiv;
26023       else
26024         *total = cost->divide[MODE_INDEX (mode)];
26025       return false;
26026
26027     case PLUS:
26028       if (GET_MODE_CLASS (mode) == MODE_INT
26029                && GET_MODE_BITSIZE (mode) <= GET_MODE_BITSIZE (Pmode))
26030         {
26031           if (GET_CODE (XEXP (x, 0)) == PLUS
26032               && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
26033               && CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 0), 1))
26034               && CONSTANT_P (XEXP (x, 1)))
26035             {
26036               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1));
26037               if (val == 2 || val == 4 || val == 8)
26038                 {
26039                   *total = cost->lea;
26040                   *total += rtx_cost (XEXP (XEXP (x, 0), 1), outer_code, speed);
26041                   *total += rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0),
26042                                       outer_code, speed);
26043                   *total += rtx_cost (XEXP (x, 1), outer_code, speed);
26044                   return true;
26045                 }
26046             }
26047           else if (GET_CODE (XEXP (x, 0)) == MULT
26048                    && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
26049             {
26050               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (x, 0), 1));
26051               if (val == 2 || val == 4 || val == 8)
26052                 {
26053                   *total = cost->lea;
26054                   *total += rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, speed);
26055                   *total += rtx_cost (XEXP (x, 1), outer_code, speed);
26056                   return true;
26057                 }
26058             }
26059           else if (GET_CODE (XEXP (x, 0)) == PLUS)
26060             {
26061               *total = cost->lea;
26062               *total += rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, speed);
26063               *total += rtx_cost (XEXP (XEXP (x, 0), 1), outer_code, speed);
26064               *total += rtx_cost (XEXP (x, 1), outer_code, speed);
26065               return true;
26066             }
26067         }
26068       /* FALLTHRU */
26069
26070     case MINUS:
26071       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
26072         {
26073           /* ??? SSE cost should be used here.  */
26074           *total = cost->fadd;
26075           return false;
26076         }
26077       else if (X87_FLOAT_MODE_P (mode))
26078         {
26079           *total = cost->fadd;
26080           return false;
26081         }
26082       else if (FLOAT_MODE_P (mode))
26083         {
26084           /* ??? SSE vector cost should be used here.  */
26085           *total = cost->fadd;
26086           return false;
26087         }
26088       /* FALLTHRU */
26089
26090     case AND:
26091     case IOR:
26092     case XOR:
26093       if (!TARGET_64BIT && mode == DImode)
26094         {
26095           *total = (cost->add * 2
26096                     + (rtx_cost (XEXP (x, 0), outer_code, speed)
26097                        << (GET_MODE (XEXP (x, 0)) != DImode))
26098                     + (rtx_cost (XEXP (x, 1), outer_code, speed)
26099                        << (GET_MODE (XEXP (x, 1)) != DImode)));
26100           return true;
26101         }
26102       /* FALLTHRU */
26103
26104     case NEG:
26105       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
26106         {
26107           /* ??? SSE cost should be used here.  */
26108           *total = cost->fchs;
26109           return false;
26110         }
26111       else if (X87_FLOAT_MODE_P (mode))
26112         {
26113           *total = cost->fchs;
26114           return false;
26115         }
26116       else if (FLOAT_MODE_P (mode))
26117         {
26118           /* ??? SSE vector cost should be used here.  */
26119           *total = cost->fchs;
26120           return false;
26121         }
26122       /* FALLTHRU */
26123
26124     case NOT:
26125       if (!TARGET_64BIT && mode == DImode)
26126         *total = cost->add * 2;
26127       else
26128         *total = cost->add;
26129       return false;
26130
26131     case COMPARE:
26132       if (GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT
26133           && XEXP (XEXP (x, 0), 1) == const1_rtx
26134           && CONST_INT_P (XEXP (XEXP (x, 0), 2))
26135           && XEXP (x, 1) == const0_rtx)
26136         {
26137           /* This kind of construct is implemented using test[bwl].
26138              Treat it as if we had an AND.  */
26139           *total = (cost->add
26140                     + rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, speed)
26141                     + rtx_cost (const1_rtx, outer_code, speed));
26142           return true;
26143         }
26144       return false;
26145
26146     case FLOAT_EXTEND:
26147       if (!(SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH))
26148         *total = 0;
26149       return false;
26150
26151     case ABS:
26152       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
26153         /* ??? SSE cost should be used here.  */
26154         *total = cost->fabs;
26155       else if (X87_FLOAT_MODE_P (mode))
26156         *total = cost->fabs;
26157       else if (FLOAT_MODE_P (mode))
26158         /* ??? SSE vector cost should be used here.  */
26159         *total = cost->fabs;
26160       return false;
26161
26162     case SQRT:
26163       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
26164         /* ??? SSE cost should be used here.  */
26165         *total = cost->fsqrt;
26166       else if (X87_FLOAT_MODE_P (mode))
26167         *total = cost->fsqrt;
26168       else if (FLOAT_MODE_P (mode))
26169         /* ??? SSE vector cost should be used here.  */
26170         *total = cost->fsqrt;
26171       return false;
26172
26173     case UNSPEC:
26174       if (XINT (x, 1) == UNSPEC_TP)
26175         *total = 0;
26176       return false;
26177
26178     default:
26179       return false;
26180     }
26181 }
26182
26183 #if TARGET_MACHO
26184
26185 static int current_machopic_label_num;
26186
26187 /* Given a symbol name and its associated stub, write out the
26188    definition of the stub.  */
26189
26190 void
26191 machopic_output_stub (FILE *file, const char *symb, const char *stub)
26192 {
26193   unsigned int length;
26194   char *binder_name, *symbol_name, lazy_ptr_name[32];
26195   int label = ++current_machopic_label_num;
26196
26197   /* For 64-bit we shouldn't get here.  */
26198   gcc_assert (!TARGET_64BIT);
26199
26200   /* Lose our funky encoding stuff so it doesn't contaminate the stub.  */
26201   symb = (*targetm.strip_name_encoding) (symb);
26202
26203   length = strlen (stub);
26204   binder_name = XALLOCAVEC (char, length + 32);
26205   GEN_BINDER_NAME_FOR_STUB (binder_name, stub, length);
26206
26207   length = strlen (symb);
26208   symbol_name = XALLOCAVEC (char, length + 32);
26209   GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
26210
26211   sprintf (lazy_ptr_name, "L%d$lz", label);
26212
26213   if (MACHOPIC_PURE)
26214     switch_to_section (darwin_sections[machopic_picsymbol_stub_section]);
26215   else
26216     switch_to_section (darwin_sections[machopic_symbol_stub_section]);
26217
26218   fprintf (file, "%s:\n", stub);
26219   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
26220
26221   if (MACHOPIC_PURE)
26222     {
26223       fprintf (file, "\tcall\tLPC$%d\nLPC$%d:\tpopl\t%%eax\n", label, label);
26224       fprintf (file, "\tmovl\t%s-LPC$%d(%%eax),%%edx\n", lazy_ptr_name, label);
26225       fprintf (file, "\tjmp\t*%%edx\n");
26226     }
26227   else
26228     fprintf (file, "\tjmp\t*%s\n", lazy_ptr_name);
26229
26230   fprintf (file, "%s:\n", binder_name);
26231
26232   if (MACHOPIC_PURE)
26233     {
26234       fprintf (file, "\tlea\t%s-LPC$%d(%%eax),%%eax\n", lazy_ptr_name, label);
26235       fprintf (file, "\tpushl\t%%eax\n");
26236     }
26237   else
26238     fprintf (file, "\tpushl\t$%s\n", lazy_ptr_name);
26239
26240   fprintf (file, "\tjmp\tdyld_stub_binding_helper\n");
26241
26242   switch_to_section (darwin_sections[machopic_lazy_symbol_ptr_section]);
26243   fprintf (file, "%s:\n", lazy_ptr_name);
26244   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
26245   fprintf (file, "\t.long %s\n", binder_name);
26246 }
26247
26248 void
26249 darwin_x86_file_end (void)
26250 {
26251   darwin_file_end ();
26252   ix86_file_end ();
26253 }
26254 #endif /* TARGET_MACHO */
26255
26256 /* Order the registers for register allocator.  */
26257
26258 void
26259 x86_order_regs_for_local_alloc (void)
26260 {
26261    int pos = 0;
26262    int i;
26263
26264    /* First allocate the local general purpose registers.  */
26265    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
26266      if (GENERAL_REGNO_P (i) && call_used_regs[i])
26267         reg_alloc_order [pos++] = i;
26268
26269    /* Global general purpose registers.  */
26270    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
26271      if (GENERAL_REGNO_P (i) && !call_used_regs[i])
26272         reg_alloc_order [pos++] = i;
26273
26274    /* x87 registers come first in case we are doing FP math
26275       using them.  */
26276    if (!TARGET_SSE_MATH)
26277      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
26278        reg_alloc_order [pos++] = i;
26279
26280    /* SSE registers.  */
26281    for (i = FIRST_SSE_REG; i <= LAST_SSE_REG; i++)
26282      reg_alloc_order [pos++] = i;
26283    for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
26284      reg_alloc_order [pos++] = i;
26285
26286    /* x87 registers.  */
26287    if (TARGET_SSE_MATH)
26288      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
26289        reg_alloc_order [pos++] = i;
26290
26291    for (i = FIRST_MMX_REG; i <= LAST_MMX_REG; i++)
26292      reg_alloc_order [pos++] = i;
26293
26294    /* Initialize the rest of array as we do not allocate some registers
26295       at all.  */
26296    while (pos < FIRST_PSEUDO_REGISTER)
26297      reg_alloc_order [pos++] = 0;
26298 }
26299
26300 /* Handle a "ms_abi" or "sysv" attribute; arguments as in
26301    struct attribute_spec.handler.  */
26302 static tree
26303 ix86_handle_abi_attribute (tree *node, tree name,
26304                               tree args ATTRIBUTE_UNUSED,
26305                               int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
26306 {
26307   if (TREE_CODE (*node) != FUNCTION_TYPE
26308       && TREE_CODE (*node) != METHOD_TYPE
26309       && TREE_CODE (*node) != FIELD_DECL
26310       && TREE_CODE (*node) != TYPE_DECL)
26311     {
26312       warning (OPT_Wattributes, "%qs attribute only applies to functions",
26313                IDENTIFIER_POINTER (name));
26314       *no_add_attrs = true;
26315       return NULL_TREE;
26316     }
26317   if (!TARGET_64BIT)
26318     {
26319       warning (OPT_Wattributes, "%qs attribute only available for 64-bit",
26320                IDENTIFIER_POINTER (name));
26321       *no_add_attrs = true;
26322       return NULL_TREE;
26323     }
26324
26325   /* Can combine regparm with all attributes but fastcall.  */
26326   if (is_attribute_p ("ms_abi", name))
26327     {
26328       if (lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (*node)))
26329         {
26330           error ("ms_abi and sysv_abi attributes are not compatible");
26331         }
26332
26333       return NULL_TREE;
26334     }
26335   else if (is_attribute_p ("sysv_abi", name))
26336     {
26337       if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (*node)))
26338         {
26339           error ("ms_abi and sysv_abi attributes are not compatible");
26340         }
26341
26342       return NULL_TREE;
26343     }
26344
26345   return NULL_TREE;
26346 }
26347
26348 /* Handle a "ms_struct" or "gcc_struct" attribute; arguments as in
26349    struct attribute_spec.handler.  */
26350 static tree
26351 ix86_handle_struct_attribute (tree *node, tree name,
26352                               tree args ATTRIBUTE_UNUSED,
26353                               int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
26354 {
26355   tree *type = NULL;
26356   if (DECL_P (*node))
26357     {
26358       if (TREE_CODE (*node) == TYPE_DECL)
26359         type = &TREE_TYPE (*node);
26360     }
26361   else
26362     type = node;
26363
26364   if (!(type && (TREE_CODE (*type) == RECORD_TYPE
26365                  || TREE_CODE (*type) == UNION_TYPE)))
26366     {
26367       warning (OPT_Wattributes, "%qs attribute ignored",
26368                IDENTIFIER_POINTER (name));
26369       *no_add_attrs = true;
26370     }
26371
26372   else if ((is_attribute_p ("ms_struct", name)
26373             && lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (*type)))
26374            || ((is_attribute_p ("gcc_struct", name)
26375                 && lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (*type)))))
26376     {
26377       warning (OPT_Wattributes, "%qs incompatible attribute ignored",
26378                IDENTIFIER_POINTER (name));
26379       *no_add_attrs = true;
26380     }
26381
26382   return NULL_TREE;
26383 }
26384
26385 static bool
26386 ix86_ms_bitfield_layout_p (const_tree record_type)
26387 {
26388   return (TARGET_MS_BITFIELD_LAYOUT &&
26389           !lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (record_type)))
26390     || lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (record_type));
26391 }
26392
26393 /* Returns an expression indicating where the this parameter is
26394    located on entry to the FUNCTION.  */
26395
26396 static rtx
26397 x86_this_parameter (tree function)
26398 {
26399   tree type = TREE_TYPE (function);
26400   bool aggr = aggregate_value_p (TREE_TYPE (type), type) != 0;
26401   int nregs;
26402
26403   if (TARGET_64BIT)
26404     {
26405       const int *parm_regs;
26406
26407       if (ix86_function_type_abi (type) == MS_ABI)
26408         parm_regs = x86_64_ms_abi_int_parameter_registers;
26409       else
26410         parm_regs = x86_64_int_parameter_registers;
26411       return gen_rtx_REG (DImode, parm_regs[aggr]);
26412     }
26413
26414   nregs = ix86_function_regparm (type, function);
26415
26416   if (nregs > 0 && !stdarg_p (type))
26417     {
26418       int regno;
26419
26420       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
26421         regno = aggr ? DX_REG : CX_REG;
26422       else
26423         {
26424           regno = AX_REG;
26425           if (aggr)
26426             {
26427               regno = DX_REG;
26428               if (nregs == 1)
26429                 return gen_rtx_MEM (SImode,
26430                                     plus_constant (stack_pointer_rtx, 4));
26431             }
26432         }
26433       return gen_rtx_REG (SImode, regno);
26434     }
26435
26436   return gen_rtx_MEM (SImode, plus_constant (stack_pointer_rtx, aggr ? 8 : 4));
26437 }
26438
26439 /* Determine whether x86_output_mi_thunk can succeed.  */
26440
26441 static bool
26442 x86_can_output_mi_thunk (const_tree thunk ATTRIBUTE_UNUSED,
26443                          HOST_WIDE_INT delta ATTRIBUTE_UNUSED,
26444                          HOST_WIDE_INT vcall_offset, const_tree function)
26445 {
26446   /* 64-bit can handle anything.  */
26447   if (TARGET_64BIT)
26448     return true;
26449
26450   /* For 32-bit, everything's fine if we have one free register.  */
26451   if (ix86_function_regparm (TREE_TYPE (function), function) < 3)
26452     return true;
26453
26454   /* Need a free register for vcall_offset.  */
26455   if (vcall_offset)
26456     return false;
26457
26458   /* Need a free register for GOT references.  */
26459   if (flag_pic && !(*targetm.binds_local_p) (function))
26460     return false;
26461
26462   /* Otherwise ok.  */
26463   return true;
26464 }
26465
26466 /* Output the assembler code for a thunk function.  THUNK_DECL is the
26467    declaration for the thunk function itself, FUNCTION is the decl for
26468    the target function.  DELTA is an immediate constant offset to be
26469    added to THIS.  If VCALL_OFFSET is nonzero, the word at
26470    *(*this + vcall_offset) should be added to THIS.  */
26471
26472 static void
26473 x86_output_mi_thunk (FILE *file ATTRIBUTE_UNUSED,
26474                      tree thunk ATTRIBUTE_UNUSED, HOST_WIDE_INT delta,
26475                      HOST_WIDE_INT vcall_offset, tree function)
26476 {
26477   rtx xops[3];
26478   rtx this_param = x86_this_parameter (function);
26479   rtx this_reg, tmp;
26480
26481   /* If VCALL_OFFSET, we'll need THIS in a register.  Might as well
26482      pull it in now and let DELTA benefit.  */
26483   if (REG_P (this_param))
26484     this_reg = this_param;
26485   else if (vcall_offset)
26486     {
26487       /* Put the this parameter into %eax.  */
26488       xops[0] = this_param;
26489       xops[1] = this_reg = gen_rtx_REG (Pmode, AX_REG);
26490       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
26491     }
26492   else
26493     this_reg = NULL_RTX;
26494
26495   /* Adjust the this parameter by a fixed constant.  */
26496   if (delta)
26497     {
26498       xops[0] = GEN_INT (delta);
26499       xops[1] = this_reg ? this_reg : this_param;
26500       if (TARGET_64BIT)
26501         {
26502           if (!x86_64_general_operand (xops[0], DImode))
26503             {
26504               tmp = gen_rtx_REG (DImode, R10_REG);
26505               xops[1] = tmp;
26506               output_asm_insn ("mov{q}\t{%1, %0|%0, %1}", xops);
26507               xops[0] = tmp;
26508               xops[1] = this_param;
26509             }
26510           output_asm_insn ("add{q}\t{%0, %1|%1, %0}", xops);
26511         }
26512       else
26513         output_asm_insn ("add{l}\t{%0, %1|%1, %0}", xops);
26514     }
26515
26516   /* Adjust the this parameter by a value stored in the vtable.  */
26517   if (vcall_offset)
26518     {
26519       if (TARGET_64BIT)
26520         tmp = gen_rtx_REG (DImode, R10_REG);
26521       else
26522         {
26523           int tmp_regno = CX_REG;
26524           if (lookup_attribute ("fastcall",
26525                                 TYPE_ATTRIBUTES (TREE_TYPE (function))))
26526             tmp_regno = AX_REG;
26527           tmp = gen_rtx_REG (SImode, tmp_regno);
26528         }
26529
26530       xops[0] = gen_rtx_MEM (Pmode, this_reg);
26531       xops[1] = tmp;
26532       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
26533
26534       /* Adjust the this parameter.  */
26535       xops[0] = gen_rtx_MEM (Pmode, plus_constant (tmp, vcall_offset));
26536       if (TARGET_64BIT && !memory_operand (xops[0], Pmode))
26537         {
26538           rtx tmp2 = gen_rtx_REG (DImode, R11_REG);
26539           xops[0] = GEN_INT (vcall_offset);
26540           xops[1] = tmp2;
26541           output_asm_insn ("mov{q}\t{%0, %1|%1, %0}", xops);
26542           xops[0] = gen_rtx_MEM (Pmode, gen_rtx_PLUS (Pmode, tmp, tmp2));
26543         }
26544       xops[1] = this_reg;
26545       output_asm_insn ("add%z1\t{%0, %1|%1, %0}", xops);
26546     }
26547
26548   /* If necessary, drop THIS back to its stack slot.  */
26549   if (this_reg && this_reg != this_param)
26550     {
26551       xops[0] = this_reg;
26552       xops[1] = this_param;
26553       output_asm_insn ("mov%z1\t{%0, %1|%1, %0}", xops);
26554     }
26555
26556   xops[0] = XEXP (DECL_RTL (function), 0);
26557   if (TARGET_64BIT)
26558     {
26559       if (!flag_pic || (*targetm.binds_local_p) (function))
26560         output_asm_insn ("jmp\t%P0", xops);
26561       /* All thunks should be in the same object as their target,
26562          and thus binds_local_p should be true.  */
26563       else if (TARGET_64BIT && cfun->machine->call_abi == MS_ABI)
26564         gcc_unreachable ();
26565       else
26566         {
26567           tmp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, xops[0]), UNSPEC_GOTPCREL);
26568           tmp = gen_rtx_CONST (Pmode, tmp);
26569           tmp = gen_rtx_MEM (QImode, tmp);
26570           xops[0] = tmp;
26571           output_asm_insn ("jmp\t%A0", xops);
26572         }
26573     }
26574   else
26575     {
26576       if (!flag_pic || (*targetm.binds_local_p) (function))
26577         output_asm_insn ("jmp\t%P0", xops);
26578       else
26579 #if TARGET_MACHO
26580         if (TARGET_MACHO)
26581           {
26582             rtx sym_ref = XEXP (DECL_RTL (function), 0);
26583             tmp = (gen_rtx_SYMBOL_REF
26584                    (Pmode,
26585                     machopic_indirection_name (sym_ref, /*stub_p=*/true)));
26586             tmp = gen_rtx_MEM (QImode, tmp);
26587             xops[0] = tmp;
26588             output_asm_insn ("jmp\t%0", xops);
26589           }
26590         else
26591 #endif /* TARGET_MACHO */
26592         {
26593           tmp = gen_rtx_REG (SImode, CX_REG);
26594           output_set_got (tmp, NULL_RTX);
26595
26596           xops[1] = tmp;
26597           output_asm_insn ("mov{l}\t{%0@GOT(%1), %1|%1, %0@GOT[%1]}", xops);
26598           output_asm_insn ("jmp\t{*}%1", xops);
26599         }
26600     }
26601 }
26602
26603 static void
26604 x86_file_start (void)
26605 {
26606   default_file_start ();
26607 #if TARGET_MACHO
26608   darwin_file_start ();
26609 #endif
26610   if (X86_FILE_START_VERSION_DIRECTIVE)
26611     fputs ("\t.version\t\"01.01\"\n", asm_out_file);
26612   if (X86_FILE_START_FLTUSED)
26613     fputs ("\t.global\t__fltused\n", asm_out_file);
26614   if (ix86_asm_dialect == ASM_INTEL)
26615     fputs ("\t.intel_syntax noprefix\n", asm_out_file);
26616 }
26617
26618 int
26619 x86_field_alignment (tree field, int computed)
26620 {
26621   enum machine_mode mode;
26622   tree type = TREE_TYPE (field);
26623
26624   if (TARGET_64BIT || TARGET_ALIGN_DOUBLE)
26625     return computed;
26626   mode = TYPE_MODE (strip_array_types (type));
26627   if (mode == DFmode || mode == DCmode
26628       || GET_MODE_CLASS (mode) == MODE_INT
26629       || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
26630     return MIN (32, computed);
26631   return computed;
26632 }
26633
26634 /* Output assembler code to FILE to increment profiler label # LABELNO
26635    for profiling a function entry.  */
26636 void
26637 x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
26638 {
26639   if (TARGET_64BIT)
26640     {
26641 #ifndef NO_PROFILE_COUNTERS
26642       fprintf (file, "\tleaq\t%sP%d@(%%rip),%%r11\n", LPREFIX, labelno);
26643 #endif
26644
26645       if (DEFAULT_ABI == SYSV_ABI && flag_pic)
26646         fprintf (file, "\tcall\t*%s@GOTPCREL(%%rip)\n", MCOUNT_NAME);
26647       else
26648         fprintf (file, "\tcall\t%s\n", MCOUNT_NAME);
26649     }
26650   else if (flag_pic)
26651     {
26652 #ifndef NO_PROFILE_COUNTERS
26653       fprintf (file, "\tleal\t%sP%d@GOTOFF(%%ebx),%%%s\n",
26654                LPREFIX, labelno, PROFILE_COUNT_REGISTER);
26655 #endif
26656       fprintf (file, "\tcall\t*%s@GOT(%%ebx)\n", MCOUNT_NAME);
26657     }
26658   else
26659     {
26660 #ifndef NO_PROFILE_COUNTERS
26661       fprintf (file, "\tmovl\t$%sP%d,%%%s\n", LPREFIX, labelno,
26662                PROFILE_COUNT_REGISTER);
26663 #endif
26664       fprintf (file, "\tcall\t%s\n", MCOUNT_NAME);
26665     }
26666 }
26667
26668 /* We don't have exact information about the insn sizes, but we may assume
26669    quite safely that we are informed about all 1 byte insns and memory
26670    address sizes.  This is enough to eliminate unnecessary padding in
26671    99% of cases.  */
26672
26673 static int
26674 min_insn_size (rtx insn)
26675 {
26676   int l = 0;
26677
26678   if (!INSN_P (insn) || !active_insn_p (insn))
26679     return 0;
26680
26681   /* Discard alignments we've emit and jump instructions.  */
26682   if (GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE
26683       && XINT (PATTERN (insn), 1) == UNSPECV_ALIGN)
26684     return 0;
26685   if (JUMP_P (insn)
26686       && (GET_CODE (PATTERN (insn)) == ADDR_VEC
26687           || GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC))
26688     return 0;
26689
26690   /* Important case - calls are always 5 bytes.
26691      It is common to have many calls in the row.  */
26692   if (CALL_P (insn)
26693       && symbolic_reference_mentioned_p (PATTERN (insn))
26694       && !SIBLING_CALL_P (insn))
26695     return 5;
26696   if (get_attr_length (insn) <= 1)
26697     return 1;
26698
26699   /* For normal instructions we may rely on the sizes of addresses
26700      and the presence of symbol to require 4 bytes of encoding.
26701      This is not the case for jumps where references are PC relative.  */
26702   if (!JUMP_P (insn))
26703     {
26704       l = get_attr_length_address (insn);
26705       if (l < 4 && symbolic_reference_mentioned_p (PATTERN (insn)))
26706         l = 4;
26707     }
26708   if (l)
26709     return 1+l;
26710   else
26711     return 2;
26712 }
26713
26714 /* AMD K8 core mispredicts jumps when there are more than 3 jumps in 16 byte
26715    window.  */
26716
26717 static void
26718 ix86_avoid_jump_misspredicts (void)
26719 {
26720   rtx insn, start = get_insns ();
26721   int nbytes = 0, njumps = 0;
26722   int isjump = 0;
26723
26724   /* Look for all minimal intervals of instructions containing 4 jumps.
26725      The intervals are bounded by START and INSN.  NBYTES is the total
26726      size of instructions in the interval including INSN and not including
26727      START.  When the NBYTES is smaller than 16 bytes, it is possible
26728      that the end of START and INSN ends up in the same 16byte page.
26729
26730      The smallest offset in the page INSN can start is the case where START
26731      ends on the offset 0.  Offset of INSN is then NBYTES - sizeof (INSN).
26732      We add p2align to 16byte window with maxskip 17 - NBYTES + sizeof (INSN).
26733      */
26734   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
26735     {
26736
26737       nbytes += min_insn_size (insn);
26738       if (dump_file)
26739         fprintf(dump_file, "Insn %i estimated to %i bytes\n",
26740                 INSN_UID (insn), min_insn_size (insn));
26741       if ((JUMP_P (insn)
26742            && GET_CODE (PATTERN (insn)) != ADDR_VEC
26743            && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
26744           || CALL_P (insn))
26745         njumps++;
26746       else
26747         continue;
26748
26749       while (njumps > 3)
26750         {
26751           start = NEXT_INSN (start);
26752           if ((JUMP_P (start)
26753                && GET_CODE (PATTERN (start)) != ADDR_VEC
26754                && GET_CODE (PATTERN (start)) != ADDR_DIFF_VEC)
26755               || CALL_P (start))
26756             njumps--, isjump = 1;
26757           else
26758             isjump = 0;
26759           nbytes -= min_insn_size (start);
26760         }
26761       gcc_assert (njumps >= 0);
26762       if (dump_file)
26763         fprintf (dump_file, "Interval %i to %i has %i bytes\n",
26764                 INSN_UID (start), INSN_UID (insn), nbytes);
26765
26766       if (njumps == 3 && isjump && nbytes < 16)
26767         {
26768           int padsize = 15 - nbytes + min_insn_size (insn);
26769
26770           if (dump_file)
26771             fprintf (dump_file, "Padding insn %i by %i bytes!\n",
26772                      INSN_UID (insn), padsize);
26773           emit_insn_before (gen_align (GEN_INT (padsize)), insn);
26774         }
26775     }
26776 }
26777
26778 /* AMD Athlon works faster
26779    when RET is not destination of conditional jump or directly preceded
26780    by other jump instruction.  We avoid the penalty by inserting NOP just
26781    before the RET instructions in such cases.  */
26782 static void
26783 ix86_pad_returns (void)
26784 {
26785   edge e;
26786   edge_iterator ei;
26787
26788   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
26789     {
26790       basic_block bb = e->src;
26791       rtx ret = BB_END (bb);
26792       rtx prev;
26793       bool replace = false;
26794
26795       if (!JUMP_P (ret) || GET_CODE (PATTERN (ret)) != RETURN
26796           || optimize_bb_for_size_p (bb))
26797         continue;
26798       for (prev = PREV_INSN (ret); prev; prev = PREV_INSN (prev))
26799         if (active_insn_p (prev) || LABEL_P (prev))
26800           break;
26801       if (prev && LABEL_P (prev))
26802         {
26803           edge e;
26804           edge_iterator ei;
26805
26806           FOR_EACH_EDGE (e, ei, bb->preds)
26807             if (EDGE_FREQUENCY (e) && e->src->index >= 0
26808                 && !(e->flags & EDGE_FALLTHRU))
26809               replace = true;
26810         }
26811       if (!replace)
26812         {
26813           prev = prev_active_insn (ret);
26814           if (prev
26815               && ((JUMP_P (prev) && any_condjump_p (prev))
26816                   || CALL_P (prev)))
26817             replace = true;
26818           /* Empty functions get branch mispredict even when the jump destination
26819              is not visible to us.  */
26820           if (!prev && cfun->function_frequency > FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
26821             replace = true;
26822         }
26823       if (replace)
26824         {
26825           emit_insn_before (gen_return_internal_long (), ret);
26826           delete_insn (ret);
26827         }
26828     }
26829 }
26830
26831 /* Implement machine specific optimizations.  We implement padding of returns
26832    for K8 CPUs and pass to avoid 4 jumps in the single 16 byte window.  */
26833 static void
26834 ix86_reorg (void)
26835 {
26836   if (TARGET_PAD_RETURNS && optimize
26837       && optimize_function_for_speed_p (cfun))
26838     ix86_pad_returns ();
26839   if (TARGET_FOUR_JUMP_LIMIT && optimize
26840       && optimize_function_for_speed_p (cfun))
26841     ix86_avoid_jump_misspredicts ();
26842 }
26843
26844 /* Return nonzero when QImode register that must be represented via REX prefix
26845    is used.  */
26846 bool
26847 x86_extended_QIreg_mentioned_p (rtx insn)
26848 {
26849   int i;
26850   extract_insn_cached (insn);
26851   for (i = 0; i < recog_data.n_operands; i++)
26852     if (REG_P (recog_data.operand[i])
26853         && REGNO (recog_data.operand[i]) >= 4)
26854        return true;
26855   return false;
26856 }
26857
26858 /* Return nonzero when P points to register encoded via REX prefix.
26859    Called via for_each_rtx.  */
26860 static int
26861 extended_reg_mentioned_1 (rtx *p, void *data ATTRIBUTE_UNUSED)
26862 {
26863    unsigned int regno;
26864    if (!REG_P (*p))
26865      return 0;
26866    regno = REGNO (*p);
26867    return REX_INT_REGNO_P (regno) || REX_SSE_REGNO_P (regno);
26868 }
26869
26870 /* Return true when INSN mentions register that must be encoded using REX
26871    prefix.  */
26872 bool
26873 x86_extended_reg_mentioned_p (rtx insn)
26874 {
26875   return for_each_rtx (INSN_P (insn) ? &PATTERN (insn) : &insn,
26876                        extended_reg_mentioned_1, NULL);
26877 }
26878
26879 /* Generate an unsigned DImode/SImode to FP conversion.  This is the same code
26880    optabs would emit if we didn't have TFmode patterns.  */
26881
26882 void
26883 x86_emit_floatuns (rtx operands[2])
26884 {
26885   rtx neglab, donelab, i0, i1, f0, in, out;
26886   enum machine_mode mode, inmode;
26887
26888   inmode = GET_MODE (operands[1]);
26889   gcc_assert (inmode == SImode || inmode == DImode);
26890
26891   out = operands[0];
26892   in = force_reg (inmode, operands[1]);
26893   mode = GET_MODE (out);
26894   neglab = gen_label_rtx ();
26895   donelab = gen_label_rtx ();
26896   f0 = gen_reg_rtx (mode);
26897
26898   emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, inmode, 0, neglab);
26899
26900   expand_float (out, in, 0);
26901
26902   emit_jump_insn (gen_jump (donelab));
26903   emit_barrier ();
26904
26905   emit_label (neglab);
26906
26907   i0 = expand_simple_binop (inmode, LSHIFTRT, in, const1_rtx, NULL,
26908                             1, OPTAB_DIRECT);
26909   i1 = expand_simple_binop (inmode, AND, in, const1_rtx, NULL,
26910                             1, OPTAB_DIRECT);
26911   i0 = expand_simple_binop (inmode, IOR, i0, i1, i0, 1, OPTAB_DIRECT);
26912
26913   expand_float (f0, i0, 0);
26914
26915   emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
26916
26917   emit_label (donelab);
26918 }
26919 \f
26920 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
26921    with all elements equal to VAR.  Return true if successful.  */
26922
26923 static bool
26924 ix86_expand_vector_init_duplicate (bool mmx_ok, enum machine_mode mode,
26925                                    rtx target, rtx val)
26926 {
26927   enum machine_mode hmode, smode, wsmode, wvmode;
26928   rtx x;
26929
26930   switch (mode)
26931     {
26932     case V2SImode:
26933     case V2SFmode:
26934       if (!mmx_ok)
26935         return false;
26936       /* FALLTHRU */
26937
26938     case V2DFmode:
26939     case V2DImode:
26940     case V4SFmode:
26941     case V4SImode:
26942       val = force_reg (GET_MODE_INNER (mode), val);
26943       x = gen_rtx_VEC_DUPLICATE (mode, val);
26944       emit_insn (gen_rtx_SET (VOIDmode, target, x));
26945       return true;
26946
26947     case V4HImode:
26948       if (!mmx_ok)
26949         return false;
26950       if (TARGET_SSE || TARGET_3DNOW_A)
26951         {
26952           val = gen_lowpart (SImode, val);
26953           x = gen_rtx_TRUNCATE (HImode, val);
26954           x = gen_rtx_VEC_DUPLICATE (mode, x);
26955           emit_insn (gen_rtx_SET (VOIDmode, target, x));
26956           return true;
26957         }
26958       else
26959         {
26960           smode = HImode;
26961           wsmode = SImode;
26962           wvmode = V2SImode;
26963           goto widen;
26964         }
26965
26966     case V8QImode:
26967       if (!mmx_ok)
26968         return false;
26969       smode = QImode;
26970       wsmode = HImode;
26971       wvmode = V4HImode;
26972       goto widen;
26973     case V8HImode:
26974       if (TARGET_SSE2)
26975         {
26976           rtx tmp1, tmp2;
26977           /* Extend HImode to SImode using a paradoxical SUBREG.  */
26978           tmp1 = gen_reg_rtx (SImode);
26979           emit_move_insn (tmp1, gen_lowpart (SImode, val));
26980           /* Insert the SImode value as low element of V4SImode vector. */
26981           tmp2 = gen_reg_rtx (V4SImode);
26982           tmp1 = gen_rtx_VEC_MERGE (V4SImode,
26983                                     gen_rtx_VEC_DUPLICATE (V4SImode, tmp1),
26984                                     CONST0_RTX (V4SImode),
26985                                     const1_rtx);
26986           emit_insn (gen_rtx_SET (VOIDmode, tmp2, tmp1));
26987           /* Cast the V4SImode vector back to a V8HImode vector.  */
26988           tmp1 = gen_reg_rtx (V8HImode);
26989           emit_move_insn (tmp1, gen_lowpart (V8HImode, tmp2));
26990           /* Duplicate the low short through the whole low SImode word.  */
26991           emit_insn (gen_sse2_punpcklwd (tmp1, tmp1, tmp1));
26992           /* Cast the V8HImode vector back to a V4SImode vector.  */
26993           tmp2 = gen_reg_rtx (V4SImode);
26994           emit_move_insn (tmp2, gen_lowpart (V4SImode, tmp1));
26995           /* Replicate the low element of the V4SImode vector.  */
26996           emit_insn (gen_sse2_pshufd (tmp2, tmp2, const0_rtx));
26997           /* Cast the V2SImode back to V8HImode, and store in target.  */
26998           emit_move_insn (target, gen_lowpart (V8HImode, tmp2));
26999           return true;
27000         }
27001       smode = HImode;
27002       wsmode = SImode;
27003       wvmode = V4SImode;
27004       goto widen;
27005     case V16QImode:
27006       if (TARGET_SSE2)
27007         {
27008           rtx tmp1, tmp2;
27009           /* Extend QImode to SImode using a paradoxical SUBREG.  */
27010           tmp1 = gen_reg_rtx (SImode);
27011           emit_move_insn (tmp1, gen_lowpart (SImode, val));
27012           /* Insert the SImode value as low element of V4SImode vector. */
27013           tmp2 = gen_reg_rtx (V4SImode);
27014           tmp1 = gen_rtx_VEC_MERGE (V4SImode,
27015                                     gen_rtx_VEC_DUPLICATE (V4SImode, tmp1),
27016                                     CONST0_RTX (V4SImode),
27017                                     const1_rtx);
27018           emit_insn (gen_rtx_SET (VOIDmode, tmp2, tmp1));
27019           /* Cast the V4SImode vector back to a V16QImode vector.  */
27020           tmp1 = gen_reg_rtx (V16QImode);
27021           emit_move_insn (tmp1, gen_lowpart (V16QImode, tmp2));
27022           /* Duplicate the low byte through the whole low SImode word.  */
27023           emit_insn (gen_sse2_punpcklbw (tmp1, tmp1, tmp1));
27024           emit_insn (gen_sse2_punpcklbw (tmp1, tmp1, tmp1));
27025           /* Cast the V16QImode vector back to a V4SImode vector.  */
27026           tmp2 = gen_reg_rtx (V4SImode);
27027           emit_move_insn (tmp2, gen_lowpart (V4SImode, tmp1));
27028           /* Replicate the low element of the V4SImode vector.  */
27029           emit_insn (gen_sse2_pshufd (tmp2, tmp2, const0_rtx));
27030           /* Cast the V2SImode back to V16QImode, and store in target.  */
27031           emit_move_insn (target, gen_lowpart (V16QImode, tmp2));
27032           return true;
27033         }
27034       smode = QImode;
27035       wsmode = HImode;
27036       wvmode = V8HImode;
27037       goto widen;
27038     widen:
27039       /* Replicate the value once into the next wider mode and recurse.  */
27040       val = convert_modes (wsmode, smode, val, true);
27041       x = expand_simple_binop (wsmode, ASHIFT, val,
27042                                GEN_INT (GET_MODE_BITSIZE (smode)),
27043                                NULL_RTX, 1, OPTAB_LIB_WIDEN);
27044       val = expand_simple_binop (wsmode, IOR, val, x, x, 1, OPTAB_LIB_WIDEN);
27045
27046       x = gen_reg_rtx (wvmode);
27047       if (!ix86_expand_vector_init_duplicate (mmx_ok, wvmode, x, val))
27048         gcc_unreachable ();
27049       emit_move_insn (target, gen_lowpart (mode, x));
27050       return true;
27051
27052     case V4DFmode:
27053       hmode = V2DFmode;
27054       goto half;
27055     case V4DImode:
27056       hmode = V2DImode;
27057       goto half;
27058     case V8SFmode:
27059       hmode = V4SFmode;
27060       goto half;
27061     case V8SImode:
27062       hmode = V4SImode;
27063       goto half;
27064     case V16HImode:
27065       hmode = V8HImode;
27066       goto half;
27067     case V32QImode:
27068       hmode = V16QImode;
27069       goto half;
27070 half:
27071       {
27072         rtx tmp = gen_reg_rtx (hmode);
27073         ix86_expand_vector_init_duplicate (mmx_ok, hmode, tmp, val);
27074         emit_insn (gen_rtx_SET (VOIDmode, target,
27075                                 gen_rtx_VEC_CONCAT (mode, tmp, tmp)));
27076       }
27077       return true;
27078
27079     default:
27080       return false;
27081     }
27082 }
27083
27084 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
27085    whose ONE_VAR element is VAR, and other elements are zero.  Return true
27086    if successful.  */
27087
27088 static bool
27089 ix86_expand_vector_init_one_nonzero (bool mmx_ok, enum machine_mode mode,
27090                                      rtx target, rtx var, int one_var)
27091 {
27092   enum machine_mode vsimode;
27093   rtx new_target;
27094   rtx x, tmp;
27095   bool use_vector_set = false;
27096
27097   switch (mode)
27098     {
27099     case V2DImode:
27100       /* For SSE4.1, we normally use vector set.  But if the second
27101          element is zero and inter-unit moves are OK, we use movq
27102          instead.  */
27103       use_vector_set = (TARGET_64BIT
27104                         && TARGET_SSE4_1
27105                         && !(TARGET_INTER_UNIT_MOVES
27106                              && one_var == 0));
27107       break;
27108     case V16QImode:
27109     case V4SImode:
27110     case V4SFmode:
27111       use_vector_set = TARGET_SSE4_1;
27112       break;
27113     case V8HImode:
27114       use_vector_set = TARGET_SSE2;
27115       break;
27116     case V4HImode:
27117       use_vector_set = TARGET_SSE || TARGET_3DNOW_A;
27118       break;
27119     case V32QImode:
27120     case V16HImode:
27121     case V8SImode:
27122     case V8SFmode:
27123     case V4DImode:
27124     case V4DFmode:
27125       use_vector_set = TARGET_AVX;
27126       break;
27127     default:
27128       break;
27129     }
27130
27131   if (use_vector_set)
27132     {
27133       emit_insn (gen_rtx_SET (VOIDmode, target, CONST0_RTX (mode)));
27134       var = force_reg (GET_MODE_INNER (mode), var);
27135       ix86_expand_vector_set (mmx_ok, target, var, one_var);
27136       return true; 
27137     }
27138
27139   switch (mode)
27140     {
27141     case V2SFmode:
27142     case V2SImode:
27143       if (!mmx_ok)
27144         return false;
27145       /* FALLTHRU */
27146
27147     case V2DFmode:
27148     case V2DImode:
27149       if (one_var != 0)
27150         return false;
27151       var = force_reg (GET_MODE_INNER (mode), var);
27152       x = gen_rtx_VEC_CONCAT (mode, var, CONST0_RTX (GET_MODE_INNER (mode)));
27153       emit_insn (gen_rtx_SET (VOIDmode, target, x));
27154       return true;
27155
27156     case V4SFmode:
27157     case V4SImode:
27158       if (!REG_P (target) || REGNO (target) < FIRST_PSEUDO_REGISTER)
27159         new_target = gen_reg_rtx (mode);
27160       else
27161         new_target = target;
27162       var = force_reg (GET_MODE_INNER (mode), var);
27163       x = gen_rtx_VEC_DUPLICATE (mode, var);
27164       x = gen_rtx_VEC_MERGE (mode, x, CONST0_RTX (mode), const1_rtx);
27165       emit_insn (gen_rtx_SET (VOIDmode, new_target, x));
27166       if (one_var != 0)
27167         {
27168           /* We need to shuffle the value to the correct position, so
27169              create a new pseudo to store the intermediate result.  */
27170
27171           /* With SSE2, we can use the integer shuffle insns.  */
27172           if (mode != V4SFmode && TARGET_SSE2)
27173             {
27174               emit_insn (gen_sse2_pshufd_1 (new_target, new_target,
27175                                             GEN_INT (1),
27176                                             GEN_INT (one_var == 1 ? 0 : 1),
27177                                             GEN_INT (one_var == 2 ? 0 : 1),
27178                                             GEN_INT (one_var == 3 ? 0 : 1)));
27179               if (target != new_target)
27180                 emit_move_insn (target, new_target);
27181               return true;
27182             }
27183
27184           /* Otherwise convert the intermediate result to V4SFmode and
27185              use the SSE1 shuffle instructions.  */
27186           if (mode != V4SFmode)
27187             {
27188               tmp = gen_reg_rtx (V4SFmode);
27189               emit_move_insn (tmp, gen_lowpart (V4SFmode, new_target));
27190             }
27191           else
27192             tmp = new_target;
27193
27194           emit_insn (gen_sse_shufps_v4sf (tmp, tmp, tmp,
27195                                        GEN_INT (1),
27196                                        GEN_INT (one_var == 1 ? 0 : 1),
27197                                        GEN_INT (one_var == 2 ? 0+4 : 1+4),
27198                                        GEN_INT (one_var == 3 ? 0+4 : 1+4)));
27199
27200           if (mode != V4SFmode)
27201             emit_move_insn (target, gen_lowpart (V4SImode, tmp));
27202           else if (tmp != target)
27203             emit_move_insn (target, tmp);
27204         }
27205       else if (target != new_target)
27206         emit_move_insn (target, new_target);
27207       return true;
27208
27209     case V8HImode:
27210     case V16QImode:
27211       vsimode = V4SImode;
27212       goto widen;
27213     case V4HImode:
27214     case V8QImode:
27215       if (!mmx_ok)
27216         return false;
27217       vsimode = V2SImode;
27218       goto widen;
27219     widen:
27220       if (one_var != 0)
27221         return false;
27222
27223       /* Zero extend the variable element to SImode and recurse.  */
27224       var = convert_modes (SImode, GET_MODE_INNER (mode), var, true);
27225
27226       x = gen_reg_rtx (vsimode);
27227       if (!ix86_expand_vector_init_one_nonzero (mmx_ok, vsimode, x,
27228                                                 var, one_var))
27229         gcc_unreachable ();
27230
27231       emit_move_insn (target, gen_lowpart (mode, x));
27232       return true;
27233
27234     default:
27235       return false;
27236     }
27237 }
27238
27239 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
27240    consisting of the values in VALS.  It is known that all elements
27241    except ONE_VAR are constants.  Return true if successful.  */
27242
27243 static bool
27244 ix86_expand_vector_init_one_var (bool mmx_ok, enum machine_mode mode,
27245                                  rtx target, rtx vals, int one_var)
27246 {
27247   rtx var = XVECEXP (vals, 0, one_var);
27248   enum machine_mode wmode;
27249   rtx const_vec, x;
27250
27251   const_vec = copy_rtx (vals);
27252   XVECEXP (const_vec, 0, one_var) = CONST0_RTX (GET_MODE_INNER (mode));
27253   const_vec = gen_rtx_CONST_VECTOR (mode, XVEC (const_vec, 0));
27254
27255   switch (mode)
27256     {
27257     case V2DFmode:
27258     case V2DImode:
27259     case V2SFmode:
27260     case V2SImode:
27261       /* For the two element vectors, it's just as easy to use
27262          the general case.  */
27263       return false;
27264
27265     case V4DFmode:
27266     case V4DImode:
27267     case V8SFmode:
27268     case V8SImode:
27269     case V16HImode:
27270     case V32QImode:
27271     case V4SFmode:
27272     case V4SImode:
27273     case V8HImode:
27274     case V4HImode:
27275       break;
27276
27277     case V16QImode:
27278       if (TARGET_SSE4_1)
27279         break;
27280       wmode = V8HImode;
27281       goto widen;
27282     case V8QImode:
27283       wmode = V4HImode;
27284       goto widen;
27285     widen:
27286       /* There's no way to set one QImode entry easily.  Combine
27287          the variable value with its adjacent constant value, and
27288          promote to an HImode set.  */
27289       x = XVECEXP (vals, 0, one_var ^ 1);
27290       if (one_var & 1)
27291         {
27292           var = convert_modes (HImode, QImode, var, true);
27293           var = expand_simple_binop (HImode, ASHIFT, var, GEN_INT (8),
27294                                      NULL_RTX, 1, OPTAB_LIB_WIDEN);
27295           x = GEN_INT (INTVAL (x) & 0xff);
27296         }
27297       else
27298         {
27299           var = convert_modes (HImode, QImode, var, true);
27300           x = gen_int_mode (INTVAL (x) << 8, HImode);
27301         }
27302       if (x != const0_rtx)
27303         var = expand_simple_binop (HImode, IOR, var, x, var,
27304                                    1, OPTAB_LIB_WIDEN);
27305
27306       x = gen_reg_rtx (wmode);
27307       emit_move_insn (x, gen_lowpart (wmode, const_vec));
27308       ix86_expand_vector_set (mmx_ok, x, var, one_var >> 1);
27309
27310       emit_move_insn (target, gen_lowpart (mode, x));
27311       return true;
27312
27313     default:
27314       return false;
27315     }
27316
27317   emit_move_insn (target, const_vec);
27318   ix86_expand_vector_set (mmx_ok, target, var, one_var);
27319   return true;
27320 }
27321
27322 /* A subroutine of ix86_expand_vector_init_general.  Use vector
27323    concatenate to handle the most general case: all values variable,
27324    and none identical.  */
27325
27326 static void
27327 ix86_expand_vector_init_concat (enum machine_mode mode,
27328                                 rtx target, rtx *ops, int n)
27329 {
27330   enum machine_mode cmode, hmode = VOIDmode;
27331   rtx first[8], second[4];
27332   rtvec v;
27333   int i, j;
27334
27335   switch (n)
27336     {
27337     case 2:
27338       switch (mode)
27339         {
27340         case V8SImode:
27341           cmode = V4SImode;
27342           break;
27343         case V8SFmode:
27344           cmode = V4SFmode;
27345           break;
27346         case V4DImode:
27347           cmode = V2DImode;
27348           break;
27349         case V4DFmode:
27350           cmode = V2DFmode;
27351           break;
27352         case V4SImode:
27353           cmode = V2SImode;
27354           break;
27355         case V4SFmode:
27356           cmode = V2SFmode;
27357           break;
27358         case V2DImode:
27359           cmode = DImode;
27360           break;
27361         case V2SImode:
27362           cmode = SImode;
27363           break;
27364         case V2DFmode:
27365           cmode = DFmode;
27366           break;
27367         case V2SFmode:
27368           cmode = SFmode;
27369           break;
27370         default:
27371           gcc_unreachable ();
27372         }
27373
27374       if (!register_operand (ops[1], cmode))
27375         ops[1] = force_reg (cmode, ops[1]);
27376       if (!register_operand (ops[0], cmode))
27377         ops[0] = force_reg (cmode, ops[0]);
27378       emit_insn (gen_rtx_SET (VOIDmode, target,
27379                               gen_rtx_VEC_CONCAT (mode, ops[0],
27380                                                   ops[1])));
27381       break;
27382
27383     case 4:
27384       switch (mode)
27385         {
27386         case V4DImode:
27387           cmode = V2DImode;
27388           break;
27389         case V4DFmode:
27390           cmode = V2DFmode;
27391           break;
27392         case V4SImode:
27393           cmode = V2SImode;
27394           break;
27395         case V4SFmode:
27396           cmode = V2SFmode;
27397           break;
27398         default:
27399           gcc_unreachable ();
27400         }
27401       goto half;
27402
27403     case 8:
27404       switch (mode)
27405         {
27406         case V8SImode:
27407           cmode = V2SImode;
27408           hmode = V4SImode;
27409           break;
27410         case V8SFmode:
27411           cmode = V2SFmode;
27412           hmode = V4SFmode;
27413           break;
27414         default:
27415           gcc_unreachable ();
27416         }
27417       goto half;
27418
27419 half:
27420       /* FIXME: We process inputs backward to help RA.  PR 36222.  */
27421       i = n - 1;
27422       j = (n >> 1) - 1;
27423       for (; i > 0; i -= 2, j--)
27424         {
27425           first[j] = gen_reg_rtx (cmode);
27426           v = gen_rtvec (2, ops[i - 1], ops[i]);
27427           ix86_expand_vector_init (false, first[j],
27428                                    gen_rtx_PARALLEL (cmode, v));
27429         }
27430
27431       n >>= 1;
27432       if (n > 2)
27433         {
27434           gcc_assert (hmode != VOIDmode);
27435           for (i = j = 0; i < n; i += 2, j++)
27436             {
27437               second[j] = gen_reg_rtx (hmode);
27438               ix86_expand_vector_init_concat (hmode, second [j],
27439                                               &first [i], 2);
27440             }
27441           n >>= 1;
27442           ix86_expand_vector_init_concat (mode, target, second, n);
27443         }
27444       else
27445         ix86_expand_vector_init_concat (mode, target, first, n);
27446       break;
27447
27448     default:
27449       gcc_unreachable ();
27450     }
27451 }
27452
27453 /* A subroutine of ix86_expand_vector_init_general.  Use vector
27454    interleave to handle the most general case: all values variable,
27455    and none identical.  */
27456
27457 static void
27458 ix86_expand_vector_init_interleave (enum machine_mode mode,
27459                                     rtx target, rtx *ops, int n)
27460 {
27461   enum machine_mode first_imode, second_imode, third_imode, inner_mode;
27462   int i, j;
27463   rtx op0, op1;
27464   rtx (*gen_load_even) (rtx, rtx, rtx);
27465   rtx (*gen_interleave_first_low) (rtx, rtx, rtx);
27466   rtx (*gen_interleave_second_low) (rtx, rtx, rtx);
27467   
27468   switch (mode)
27469     {
27470     case V8HImode:
27471       gen_load_even = gen_vec_setv8hi;
27472       gen_interleave_first_low = gen_vec_interleave_lowv4si;
27473       gen_interleave_second_low = gen_vec_interleave_lowv2di;
27474       inner_mode = HImode;
27475       first_imode = V4SImode;
27476       second_imode = V2DImode;
27477       third_imode = VOIDmode;
27478       break;
27479     case V16QImode:
27480       gen_load_even = gen_vec_setv16qi;
27481       gen_interleave_first_low = gen_vec_interleave_lowv8hi;
27482       gen_interleave_second_low = gen_vec_interleave_lowv4si;
27483       inner_mode = QImode;
27484       first_imode = V8HImode;
27485       second_imode = V4SImode;
27486       third_imode = V2DImode;
27487       break;
27488     default:
27489       gcc_unreachable ();
27490     }
27491      
27492   for (i = 0; i < n; i++)
27493     {
27494       /* Extend the odd elment to SImode using a paradoxical SUBREG.  */
27495       op0 = gen_reg_rtx (SImode);
27496       emit_move_insn (op0, gen_lowpart (SImode, ops [i + i]));
27497
27498       /* Insert the SImode value as low element of V4SImode vector. */
27499       op1 = gen_reg_rtx (V4SImode);
27500       op0 = gen_rtx_VEC_MERGE (V4SImode,
27501                                gen_rtx_VEC_DUPLICATE (V4SImode,
27502                                                       op0),
27503                                CONST0_RTX (V4SImode),
27504                                const1_rtx);
27505       emit_insn (gen_rtx_SET (VOIDmode, op1, op0));
27506
27507       /* Cast the V4SImode vector back to a vector in orignal mode.  */
27508       op0 = gen_reg_rtx (mode);
27509       emit_move_insn (op0, gen_lowpart (mode, op1));
27510       
27511       /* Load even elements into the second positon.  */
27512       emit_insn ((*gen_load_even) (op0,
27513                                    force_reg (inner_mode,
27514                                               ops [i + i + 1]),
27515                                    const1_rtx));
27516
27517       /* Cast vector to FIRST_IMODE vector.  */
27518       ops[i] = gen_reg_rtx (first_imode);
27519       emit_move_insn (ops[i], gen_lowpart (first_imode, op0));
27520     }
27521
27522   /* Interleave low FIRST_IMODE vectors.  */
27523   for (i = j = 0; i < n; i += 2, j++)
27524     {
27525       op0 = gen_reg_rtx (first_imode);
27526       emit_insn ((*gen_interleave_first_low) (op0, ops[i], ops[i + 1]));
27527
27528       /* Cast FIRST_IMODE vector to SECOND_IMODE vector.  */
27529       ops[j] = gen_reg_rtx (second_imode);
27530       emit_move_insn (ops[j], gen_lowpart (second_imode, op0));
27531     }
27532
27533   /* Interleave low SECOND_IMODE vectors.  */
27534   switch (second_imode)
27535     {
27536     case V4SImode:
27537       for (i = j = 0; i < n / 2; i += 2, j++)
27538         {
27539           op0 = gen_reg_rtx (second_imode);
27540           emit_insn ((*gen_interleave_second_low) (op0, ops[i],
27541                                                    ops[i + 1]));
27542
27543           /* Cast the SECOND_IMODE vector to the THIRD_IMODE
27544              vector.  */
27545           ops[j] = gen_reg_rtx (third_imode);
27546           emit_move_insn (ops[j], gen_lowpart (third_imode, op0));
27547         }
27548       second_imode = V2DImode;
27549       gen_interleave_second_low = gen_vec_interleave_lowv2di;
27550       /* FALLTHRU */
27551
27552     case V2DImode:
27553       op0 = gen_reg_rtx (second_imode);
27554       emit_insn ((*gen_interleave_second_low) (op0, ops[0],
27555                                                ops[1]));
27556
27557       /* Cast the SECOND_IMODE vector back to a vector on original
27558          mode.  */
27559       emit_insn (gen_rtx_SET (VOIDmode, target,
27560                               gen_lowpart (mode, op0)));
27561       break;
27562
27563     default:
27564       gcc_unreachable ();
27565     }
27566 }
27567
27568 /* A subroutine of ix86_expand_vector_init.  Handle the most general case:
27569    all values variable, and none identical.  */
27570
27571 static void
27572 ix86_expand_vector_init_general (bool mmx_ok, enum machine_mode mode,
27573                                  rtx target, rtx vals)
27574 {
27575   rtx ops[32], op0, op1;
27576   enum machine_mode half_mode = VOIDmode;
27577   int n, i;
27578
27579   switch (mode)
27580     {
27581     case V2SFmode:
27582     case V2SImode:
27583       if (!mmx_ok && !TARGET_SSE)
27584         break;
27585       /* FALLTHRU */
27586
27587     case V8SFmode:
27588     case V8SImode:
27589     case V4DFmode:
27590     case V4DImode:
27591     case V4SFmode:
27592     case V4SImode:
27593     case V2DFmode:
27594     case V2DImode:
27595       n = GET_MODE_NUNITS (mode);
27596       for (i = 0; i < n; i++)
27597         ops[i] = XVECEXP (vals, 0, i);
27598       ix86_expand_vector_init_concat (mode, target, ops, n);
27599       return;
27600
27601     case V32QImode:
27602       half_mode = V16QImode;
27603       goto half;
27604
27605     case V16HImode:
27606       half_mode = V8HImode;
27607       goto half;
27608
27609 half:
27610       n = GET_MODE_NUNITS (mode);
27611       for (i = 0; i < n; i++)
27612         ops[i] = XVECEXP (vals, 0, i);
27613       op0 = gen_reg_rtx (half_mode);
27614       op1 = gen_reg_rtx (half_mode);
27615       ix86_expand_vector_init_interleave (half_mode, op0, ops,
27616                                           n >> 2);
27617       ix86_expand_vector_init_interleave (half_mode, op1,
27618                                           &ops [n >> 1], n >> 2);
27619       emit_insn (gen_rtx_SET (VOIDmode, target,
27620                               gen_rtx_VEC_CONCAT (mode, op0, op1)));
27621       return;
27622
27623     case V16QImode:
27624       if (!TARGET_SSE4_1)
27625         break;
27626       /* FALLTHRU */
27627
27628     case V8HImode:
27629       if (!TARGET_SSE2)
27630         break;
27631
27632       /* Don't use ix86_expand_vector_init_interleave if we can't
27633          move from GPR to SSE register directly.  */ 
27634       if (!TARGET_INTER_UNIT_MOVES)
27635         break;
27636
27637       n = GET_MODE_NUNITS (mode);
27638       for (i = 0; i < n; i++)
27639         ops[i] = XVECEXP (vals, 0, i);
27640       ix86_expand_vector_init_interleave (mode, target, ops, n >> 1);
27641       return;
27642
27643     case V4HImode:
27644     case V8QImode:
27645       break;
27646
27647     default:
27648       gcc_unreachable ();
27649     }
27650
27651     {
27652       int i, j, n_elts, n_words, n_elt_per_word;
27653       enum machine_mode inner_mode;
27654       rtx words[4], shift;
27655
27656       inner_mode = GET_MODE_INNER (mode);
27657       n_elts = GET_MODE_NUNITS (mode);
27658       n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
27659       n_elt_per_word = n_elts / n_words;
27660       shift = GEN_INT (GET_MODE_BITSIZE (inner_mode));
27661
27662       for (i = 0; i < n_words; ++i)
27663         {
27664           rtx word = NULL_RTX;
27665
27666           for (j = 0; j < n_elt_per_word; ++j)
27667             {
27668               rtx elt = XVECEXP (vals, 0, (i+1)*n_elt_per_word - j - 1);
27669               elt = convert_modes (word_mode, inner_mode, elt, true);
27670
27671               if (j == 0)
27672                 word = elt;
27673               else
27674                 {
27675                   word = expand_simple_binop (word_mode, ASHIFT, word, shift,
27676                                               word, 1, OPTAB_LIB_WIDEN);
27677                   word = expand_simple_binop (word_mode, IOR, word, elt,
27678                                               word, 1, OPTAB_LIB_WIDEN);
27679                 }
27680             }
27681
27682           words[i] = word;
27683         }
27684
27685       if (n_words == 1)
27686         emit_move_insn (target, gen_lowpart (mode, words[0]));
27687       else if (n_words == 2)
27688         {
27689           rtx tmp = gen_reg_rtx (mode);
27690           emit_clobber (tmp);
27691           emit_move_insn (gen_lowpart (word_mode, tmp), words[0]);
27692           emit_move_insn (gen_highpart (word_mode, tmp), words[1]);
27693           emit_move_insn (target, tmp);
27694         }
27695       else if (n_words == 4)
27696         {
27697           rtx tmp = gen_reg_rtx (V4SImode);
27698           gcc_assert (word_mode == SImode);
27699           vals = gen_rtx_PARALLEL (V4SImode, gen_rtvec_v (4, words));
27700           ix86_expand_vector_init_general (false, V4SImode, tmp, vals);
27701           emit_move_insn (target, gen_lowpart (mode, tmp));
27702         }
27703       else
27704         gcc_unreachable ();
27705     }
27706 }
27707
27708 /* Initialize vector TARGET via VALS.  Suppress the use of MMX
27709    instructions unless MMX_OK is true.  */
27710
27711 void
27712 ix86_expand_vector_init (bool mmx_ok, rtx target, rtx vals)
27713 {
27714   enum machine_mode mode = GET_MODE (target);
27715   enum machine_mode inner_mode = GET_MODE_INNER (mode);
27716   int n_elts = GET_MODE_NUNITS (mode);
27717   int n_var = 0, one_var = -1;
27718   bool all_same = true, all_const_zero = true;
27719   int i;
27720   rtx x;
27721
27722   for (i = 0; i < n_elts; ++i)
27723     {
27724       x = XVECEXP (vals, 0, i);
27725       if (!(CONST_INT_P (x)
27726             || GET_CODE (x) == CONST_DOUBLE
27727             || GET_CODE (x) == CONST_FIXED))
27728         n_var++, one_var = i;
27729       else if (x != CONST0_RTX (inner_mode))
27730         all_const_zero = false;
27731       if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0)))
27732         all_same = false;
27733     }
27734
27735   /* Constants are best loaded from the constant pool.  */
27736   if (n_var == 0)
27737     {
27738       emit_move_insn (target, gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)));
27739       return;
27740     }
27741
27742   /* If all values are identical, broadcast the value.  */
27743   if (all_same
27744       && ix86_expand_vector_init_duplicate (mmx_ok, mode, target,
27745                                             XVECEXP (vals, 0, 0)))
27746     return;
27747
27748   /* Values where only one field is non-constant are best loaded from
27749      the pool and overwritten via move later.  */
27750   if (n_var == 1)
27751     {
27752       if (all_const_zero
27753           && ix86_expand_vector_init_one_nonzero (mmx_ok, mode, target,
27754                                                   XVECEXP (vals, 0, one_var),
27755                                                   one_var))
27756         return;
27757
27758       if (ix86_expand_vector_init_one_var (mmx_ok, mode, target, vals, one_var))
27759         return;
27760     }
27761
27762   ix86_expand_vector_init_general (mmx_ok, mode, target, vals);
27763 }
27764
27765 void
27766 ix86_expand_vector_set (bool mmx_ok, rtx target, rtx val, int elt)
27767 {
27768   enum machine_mode mode = GET_MODE (target);
27769   enum machine_mode inner_mode = GET_MODE_INNER (mode);
27770   enum machine_mode half_mode;
27771   bool use_vec_merge = false;
27772   rtx tmp;
27773   static rtx (*gen_extract[6][2]) (rtx, rtx)
27774     = {
27775         { gen_vec_extract_lo_v32qi, gen_vec_extract_hi_v32qi },
27776         { gen_vec_extract_lo_v16hi, gen_vec_extract_hi_v16hi },
27777         { gen_vec_extract_lo_v8si, gen_vec_extract_hi_v8si },
27778         { gen_vec_extract_lo_v4di, gen_vec_extract_hi_v4di },
27779         { gen_vec_extract_lo_v8sf, gen_vec_extract_hi_v8sf },
27780         { gen_vec_extract_lo_v4df, gen_vec_extract_hi_v4df }
27781       };
27782   static rtx (*gen_insert[6][2]) (rtx, rtx, rtx)
27783     = {
27784         { gen_vec_set_lo_v32qi, gen_vec_set_hi_v32qi },
27785         { gen_vec_set_lo_v16hi, gen_vec_set_hi_v16hi },
27786         { gen_vec_set_lo_v8si, gen_vec_set_hi_v8si },
27787         { gen_vec_set_lo_v4di, gen_vec_set_hi_v4di },
27788         { gen_vec_set_lo_v8sf, gen_vec_set_hi_v8sf },
27789         { gen_vec_set_lo_v4df, gen_vec_set_hi_v4df }
27790       };
27791   int i, j, n;
27792
27793   switch (mode)
27794     {
27795     case V2SFmode:
27796     case V2SImode:
27797       if (mmx_ok)
27798         {
27799           tmp = gen_reg_rtx (GET_MODE_INNER (mode));
27800           ix86_expand_vector_extract (true, tmp, target, 1 - elt);
27801           if (elt == 0)
27802             tmp = gen_rtx_VEC_CONCAT (mode, tmp, val);
27803           else
27804             tmp = gen_rtx_VEC_CONCAT (mode, val, tmp);
27805           emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
27806           return;
27807         }
27808       break;
27809
27810     case V2DImode:
27811       use_vec_merge = TARGET_SSE4_1;
27812       if (use_vec_merge)
27813         break;
27814
27815     case V2DFmode:
27816       {
27817         rtx op0, op1;
27818
27819         /* For the two element vectors, we implement a VEC_CONCAT with
27820            the extraction of the other element.  */
27821
27822         tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (1 - elt)));
27823         tmp = gen_rtx_VEC_SELECT (inner_mode, target, tmp);
27824
27825         if (elt == 0)
27826           op0 = val, op1 = tmp;
27827         else
27828           op0 = tmp, op1 = val;
27829
27830         tmp = gen_rtx_VEC_CONCAT (mode, op0, op1);
27831         emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
27832       }
27833       return;
27834
27835     case V4SFmode:
27836       use_vec_merge = TARGET_SSE4_1;
27837       if (use_vec_merge)
27838         break;
27839
27840       switch (elt)
27841         {
27842         case 0:
27843           use_vec_merge = true;
27844           break;
27845
27846         case 1:
27847           /* tmp = target = A B C D */
27848           tmp = copy_to_reg (target);
27849           /* target = A A B B */
27850           emit_insn (gen_sse_unpcklps (target, target, target));
27851           /* target = X A B B */
27852           ix86_expand_vector_set (false, target, val, 0);
27853           /* target = A X C D  */
27854           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
27855                                        GEN_INT (1), GEN_INT (0),
27856                                        GEN_INT (2+4), GEN_INT (3+4)));
27857           return;
27858
27859         case 2:
27860           /* tmp = target = A B C D */
27861           tmp = copy_to_reg (target);
27862           /* tmp = X B C D */
27863           ix86_expand_vector_set (false, tmp, val, 0);
27864           /* target = A B X D */
27865           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
27866                                        GEN_INT (0), GEN_INT (1),
27867                                        GEN_INT (0+4), GEN_INT (3+4)));
27868           return;
27869
27870         case 3:
27871           /* tmp = target = A B C D */
27872           tmp = copy_to_reg (target);
27873           /* tmp = X B C D */
27874           ix86_expand_vector_set (false, tmp, val, 0);
27875           /* target = A B X D */
27876           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
27877                                        GEN_INT (0), GEN_INT (1),
27878                                        GEN_INT (2+4), GEN_INT (0+4)));
27879           return;
27880
27881         default:
27882           gcc_unreachable ();
27883         }
27884       break;
27885
27886     case V4SImode:
27887       use_vec_merge = TARGET_SSE4_1;
27888       if (use_vec_merge)
27889         break;
27890
27891       /* Element 0 handled by vec_merge below.  */
27892       if (elt == 0)
27893         {
27894           use_vec_merge = true;
27895           break;
27896         }
27897
27898       if (TARGET_SSE2)
27899         {
27900           /* With SSE2, use integer shuffles to swap element 0 and ELT,
27901              store into element 0, then shuffle them back.  */
27902
27903           rtx order[4];
27904
27905           order[0] = GEN_INT (elt);
27906           order[1] = const1_rtx;
27907           order[2] = const2_rtx;
27908           order[3] = GEN_INT (3);
27909           order[elt] = const0_rtx;
27910
27911           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
27912                                         order[1], order[2], order[3]));
27913
27914           ix86_expand_vector_set (false, target, val, 0);
27915
27916           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
27917                                         order[1], order[2], order[3]));
27918         }
27919       else
27920         {
27921           /* For SSE1, we have to reuse the V4SF code.  */
27922           ix86_expand_vector_set (false, gen_lowpart (V4SFmode, target),
27923                                   gen_lowpart (SFmode, val), elt);
27924         }
27925       return;
27926
27927     case V8HImode:
27928       use_vec_merge = TARGET_SSE2;
27929       break;
27930     case V4HImode:
27931       use_vec_merge = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
27932       break;
27933
27934     case V16QImode:
27935       use_vec_merge = TARGET_SSE4_1;
27936       break;
27937
27938     case V8QImode:
27939       break;
27940
27941     case V32QImode:
27942       half_mode = V16QImode;
27943       j = 0;
27944       n = 16;
27945       goto half;
27946
27947     case V16HImode:
27948       half_mode = V8HImode;
27949       j = 1;
27950       n = 8;
27951       goto half;
27952
27953     case V8SImode:
27954       half_mode = V4SImode;
27955       j = 2;
27956       n = 4;
27957       goto half;
27958
27959     case V4DImode:
27960       half_mode = V2DImode;
27961       j = 3;
27962       n = 2;
27963       goto half;
27964
27965     case V8SFmode:
27966       half_mode = V4SFmode;
27967       j = 4;
27968       n = 4;
27969       goto half;
27970
27971     case V4DFmode:
27972       half_mode = V2DFmode;
27973       j = 5;
27974       n = 2;
27975       goto half;
27976
27977 half:
27978       /* Compute offset.  */
27979       i = elt / n;
27980       elt %= n;
27981
27982       gcc_assert (i <= 1);
27983
27984       /* Extract the half.  */
27985       tmp = gen_reg_rtx (half_mode);
27986       emit_insn ((*gen_extract[j][i]) (tmp, target));
27987
27988       /* Put val in tmp at elt.  */
27989       ix86_expand_vector_set (false, tmp, val, elt);
27990
27991       /* Put it back.  */
27992       emit_insn ((*gen_insert[j][i]) (target, target, tmp));
27993       return;
27994
27995     default:
27996       break;
27997     }
27998
27999   if (use_vec_merge)
28000     {
28001       tmp = gen_rtx_VEC_DUPLICATE (mode, val);
28002       tmp = gen_rtx_VEC_MERGE (mode, tmp, target, GEN_INT (1 << elt));
28003       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
28004     }
28005   else
28006     {
28007       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), false);
28008
28009       emit_move_insn (mem, target);
28010
28011       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
28012       emit_move_insn (tmp, val);
28013
28014       emit_move_insn (target, mem);
28015     }
28016 }
28017
28018 void
28019 ix86_expand_vector_extract (bool mmx_ok, rtx target, rtx vec, int elt)
28020 {
28021   enum machine_mode mode = GET_MODE (vec);
28022   enum machine_mode inner_mode = GET_MODE_INNER (mode);
28023   bool use_vec_extr = false;
28024   rtx tmp;
28025
28026   switch (mode)
28027     {
28028     case V2SImode:
28029     case V2SFmode:
28030       if (!mmx_ok)
28031         break;
28032       /* FALLTHRU */
28033
28034     case V2DFmode:
28035     case V2DImode:
28036       use_vec_extr = true;
28037       break;
28038
28039     case V4SFmode:
28040       use_vec_extr = TARGET_SSE4_1;
28041       if (use_vec_extr)
28042         break;
28043
28044       switch (elt)
28045         {
28046         case 0:
28047           tmp = vec;
28048           break;
28049
28050         case 1:
28051         case 3:
28052           tmp = gen_reg_rtx (mode);
28053           emit_insn (gen_sse_shufps_v4sf (tmp, vec, vec,
28054                                        GEN_INT (elt), GEN_INT (elt),
28055                                        GEN_INT (elt+4), GEN_INT (elt+4)));
28056           break;
28057
28058         case 2:
28059           tmp = gen_reg_rtx (mode);
28060           emit_insn (gen_sse_unpckhps (tmp, vec, vec));
28061           break;
28062
28063         default:
28064           gcc_unreachable ();
28065         }
28066       vec = tmp;
28067       use_vec_extr = true;
28068       elt = 0;
28069       break;
28070
28071     case V4SImode:
28072       use_vec_extr = TARGET_SSE4_1;
28073       if (use_vec_extr)
28074         break;
28075
28076       if (TARGET_SSE2)
28077         {
28078           switch (elt)
28079             {
28080             case 0:
28081               tmp = vec;
28082               break;
28083
28084             case 1:
28085             case 3:
28086               tmp = gen_reg_rtx (mode);
28087               emit_insn (gen_sse2_pshufd_1 (tmp, vec,
28088                                             GEN_INT (elt), GEN_INT (elt),
28089                                             GEN_INT (elt), GEN_INT (elt)));
28090               break;
28091
28092             case 2:
28093               tmp = gen_reg_rtx (mode);
28094               emit_insn (gen_sse2_punpckhdq (tmp, vec, vec));
28095               break;
28096
28097             default:
28098               gcc_unreachable ();
28099             }
28100           vec = tmp;
28101           use_vec_extr = true;
28102           elt = 0;
28103         }
28104       else
28105         {
28106           /* For SSE1, we have to reuse the V4SF code.  */
28107           ix86_expand_vector_extract (false, gen_lowpart (SFmode, target),
28108                                       gen_lowpart (V4SFmode, vec), elt);
28109           return;
28110         }
28111       break;
28112
28113     case V8HImode:
28114       use_vec_extr = TARGET_SSE2;
28115       break;
28116     case V4HImode:
28117       use_vec_extr = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
28118       break;
28119
28120     case V16QImode:
28121       use_vec_extr = TARGET_SSE4_1;
28122       break;
28123
28124     case V8QImode:
28125       /* ??? Could extract the appropriate HImode element and shift.  */
28126     default:
28127       break;
28128     }
28129
28130   if (use_vec_extr)
28131     {
28132       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (elt)));
28133       tmp = gen_rtx_VEC_SELECT (inner_mode, vec, tmp);
28134
28135       /* Let the rtl optimizers know about the zero extension performed.  */
28136       if (inner_mode == QImode || inner_mode == HImode)
28137         {
28138           tmp = gen_rtx_ZERO_EXTEND (SImode, tmp);
28139           target = gen_lowpart (SImode, target);
28140         }
28141
28142       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
28143     }
28144   else
28145     {
28146       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), false);
28147
28148       emit_move_insn (mem, vec);
28149
28150       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
28151       emit_move_insn (target, tmp);
28152     }
28153 }
28154
28155 /* Expand a vector reduction on V4SFmode for SSE1.  FN is the binary
28156    pattern to reduce; DEST is the destination; IN is the input vector.  */
28157
28158 void
28159 ix86_expand_reduc_v4sf (rtx (*fn) (rtx, rtx, rtx), rtx dest, rtx in)
28160 {
28161   rtx tmp1, tmp2, tmp3;
28162
28163   tmp1 = gen_reg_rtx (V4SFmode);
28164   tmp2 = gen_reg_rtx (V4SFmode);
28165   tmp3 = gen_reg_rtx (V4SFmode);
28166
28167   emit_insn (gen_sse_movhlps (tmp1, in, in));
28168   emit_insn (fn (tmp2, tmp1, in));
28169
28170   emit_insn (gen_sse_shufps_v4sf (tmp3, tmp2, tmp2,
28171                                GEN_INT (1), GEN_INT (1),
28172                                GEN_INT (1+4), GEN_INT (1+4)));
28173   emit_insn (fn (dest, tmp2, tmp3));
28174 }
28175 \f
28176 /* Target hook for scalar_mode_supported_p.  */
28177 static bool
28178 ix86_scalar_mode_supported_p (enum machine_mode mode)
28179 {
28180   if (DECIMAL_FLOAT_MODE_P (mode))
28181     return true;
28182   else if (mode == TFmode)
28183     return true;
28184   else
28185     return default_scalar_mode_supported_p (mode);
28186 }
28187
28188 /* Implements target hook vector_mode_supported_p.  */
28189 static bool
28190 ix86_vector_mode_supported_p (enum machine_mode mode)
28191 {
28192   if (TARGET_SSE && VALID_SSE_REG_MODE (mode))
28193     return true;
28194   if (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
28195     return true;
28196   if (TARGET_AVX && VALID_AVX256_REG_MODE (mode))
28197     return true;
28198   if (TARGET_MMX && VALID_MMX_REG_MODE (mode))
28199     return true;
28200   if (TARGET_3DNOW && VALID_MMX_REG_MODE_3DNOW (mode))
28201     return true;
28202   return false;
28203 }
28204
28205 /* Target hook for c_mode_for_suffix.  */
28206 static enum machine_mode
28207 ix86_c_mode_for_suffix (char suffix)
28208 {
28209   if (suffix == 'q')
28210     return TFmode;
28211   if (suffix == 'w')
28212     return XFmode;
28213
28214   return VOIDmode;
28215 }
28216
28217 /* Worker function for TARGET_MD_ASM_CLOBBERS.
28218
28219    We do this in the new i386 backend to maintain source compatibility
28220    with the old cc0-based compiler.  */
28221
28222 static tree
28223 ix86_md_asm_clobbers (tree outputs ATTRIBUTE_UNUSED,
28224                       tree inputs ATTRIBUTE_UNUSED,
28225                       tree clobbers)
28226 {
28227   clobbers = tree_cons (NULL_TREE, build_string (5, "flags"),
28228                         clobbers);
28229   clobbers = tree_cons (NULL_TREE, build_string (4, "fpsr"),
28230                         clobbers);
28231   return clobbers;
28232 }
28233
28234 /* Implements target vector targetm.asm.encode_section_info.  This
28235    is not used by netware.  */
28236
28237 static void ATTRIBUTE_UNUSED
28238 ix86_encode_section_info (tree decl, rtx rtl, int first)
28239 {
28240   default_encode_section_info (decl, rtl, first);
28241
28242   if (TREE_CODE (decl) == VAR_DECL
28243       && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
28244       && ix86_in_large_data_p (decl))
28245     SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= SYMBOL_FLAG_FAR_ADDR;
28246 }
28247
28248 /* Worker function for REVERSE_CONDITION.  */
28249
28250 enum rtx_code
28251 ix86_reverse_condition (enum rtx_code code, enum machine_mode mode)
28252 {
28253   return (mode != CCFPmode && mode != CCFPUmode
28254           ? reverse_condition (code)
28255           : reverse_condition_maybe_unordered (code));
28256 }
28257
28258 /* Output code to perform an x87 FP register move, from OPERANDS[1]
28259    to OPERANDS[0].  */
28260
28261 const char *
28262 output_387_reg_move (rtx insn, rtx *operands)
28263 {
28264   if (REG_P (operands[0]))
28265     {
28266       if (REG_P (operands[1])
28267           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
28268         {
28269           if (REGNO (operands[0]) == FIRST_STACK_REG)
28270             return output_387_ffreep (operands, 0);
28271           return "fstp\t%y0";
28272         }
28273       if (STACK_TOP_P (operands[0]))
28274         return "fld%z1\t%y1";
28275       return "fst\t%y0";
28276     }
28277   else if (MEM_P (operands[0]))
28278     {
28279       gcc_assert (REG_P (operands[1]));
28280       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
28281         return "fstp%z0\t%y0";
28282       else
28283         {
28284           /* There is no non-popping store to memory for XFmode.
28285              So if we need one, follow the store with a load.  */
28286           if (GET_MODE (operands[0]) == XFmode)
28287             return "fstp%z0\t%y0\n\tfld%z0\t%y0";
28288           else
28289             return "fst%z0\t%y0";
28290         }
28291     }
28292   else
28293     gcc_unreachable();
28294 }
28295
28296 /* Output code to perform a conditional jump to LABEL, if C2 flag in
28297    FP status register is set.  */
28298
28299 void
28300 ix86_emit_fp_unordered_jump (rtx label)
28301 {
28302   rtx reg = gen_reg_rtx (HImode);
28303   rtx temp;
28304
28305   emit_insn (gen_x86_fnstsw_1 (reg));
28306
28307   if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ()))
28308     {
28309       emit_insn (gen_x86_sahf_1 (reg));
28310
28311       temp = gen_rtx_REG (CCmode, FLAGS_REG);
28312       temp = gen_rtx_UNORDERED (VOIDmode, temp, const0_rtx);
28313     }
28314   else
28315     {
28316       emit_insn (gen_testqi_ext_ccno_0 (reg, GEN_INT (0x04)));
28317
28318       temp = gen_rtx_REG (CCNOmode, FLAGS_REG);
28319       temp = gen_rtx_NE (VOIDmode, temp, const0_rtx);
28320     }
28321
28322   temp = gen_rtx_IF_THEN_ELSE (VOIDmode, temp,
28323                               gen_rtx_LABEL_REF (VOIDmode, label),
28324                               pc_rtx);
28325   temp = gen_rtx_SET (VOIDmode, pc_rtx, temp);
28326
28327   emit_jump_insn (temp);
28328   predict_jump (REG_BR_PROB_BASE * 10 / 100);
28329 }
28330
28331 /* Output code to perform a log1p XFmode calculation.  */
28332
28333 void ix86_emit_i387_log1p (rtx op0, rtx op1)
28334 {
28335   rtx label1 = gen_label_rtx ();
28336   rtx label2 = gen_label_rtx ();
28337
28338   rtx tmp = gen_reg_rtx (XFmode);
28339   rtx tmp2 = gen_reg_rtx (XFmode);
28340
28341   emit_insn (gen_absxf2 (tmp, op1));
28342   emit_insn (gen_cmpxf (tmp,
28343     CONST_DOUBLE_FROM_REAL_VALUE (
28344        REAL_VALUE_ATOF ("0.29289321881345247561810596348408353", XFmode),
28345        XFmode)));
28346   emit_jump_insn (gen_bge (label1));
28347
28348   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
28349   emit_insn (gen_fyl2xp1xf3_i387 (op0, op1, tmp2));
28350   emit_jump (label2);
28351
28352   emit_label (label1);
28353   emit_move_insn (tmp, CONST1_RTX (XFmode));
28354   emit_insn (gen_addxf3 (tmp, op1, tmp));
28355   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
28356   emit_insn (gen_fyl2xxf3_i387 (op0, tmp, tmp2));
28357
28358   emit_label (label2);
28359 }
28360
28361 /* Output code to perform a Newton-Rhapson approximation of a single precision
28362    floating point divide [http://en.wikipedia.org/wiki/N-th_root_algorithm].  */
28363
28364 void ix86_emit_swdivsf (rtx res, rtx a, rtx b, enum machine_mode mode)
28365 {
28366   rtx x0, x1, e0, e1, two;
28367
28368   x0 = gen_reg_rtx (mode);
28369   e0 = gen_reg_rtx (mode);
28370   e1 = gen_reg_rtx (mode);
28371   x1 = gen_reg_rtx (mode);
28372
28373   two = CONST_DOUBLE_FROM_REAL_VALUE (dconst2, SFmode);
28374
28375   if (VECTOR_MODE_P (mode))
28376     two = ix86_build_const_vector (SFmode, true, two);
28377
28378   two = force_reg (mode, two);
28379
28380   /* a / b = a * rcp(b) * (2.0 - b * rcp(b)) */
28381
28382   /* x0 = rcp(b) estimate */
28383   emit_insn (gen_rtx_SET (VOIDmode, x0,
28384                           gen_rtx_UNSPEC (mode, gen_rtvec (1, b),
28385                                           UNSPEC_RCP)));
28386   /* e0 = x0 * b */
28387   emit_insn (gen_rtx_SET (VOIDmode, e0,
28388                           gen_rtx_MULT (mode, x0, b)));
28389   /* e1 = 2. - e0 */
28390   emit_insn (gen_rtx_SET (VOIDmode, e1,
28391                           gen_rtx_MINUS (mode, two, e0)));
28392   /* x1 = x0 * e1 */
28393   emit_insn (gen_rtx_SET (VOIDmode, x1,
28394                           gen_rtx_MULT (mode, x0, e1)));
28395   /* res = a * x1 */
28396   emit_insn (gen_rtx_SET (VOIDmode, res,
28397                           gen_rtx_MULT (mode, a, x1)));
28398 }
28399
28400 /* Output code to perform a Newton-Rhapson approximation of a
28401    single precision floating point [reciprocal] square root.  */
28402
28403 void ix86_emit_swsqrtsf (rtx res, rtx a, enum machine_mode mode,
28404                          bool recip)
28405 {
28406   rtx x0, e0, e1, e2, e3, mthree, mhalf;
28407   REAL_VALUE_TYPE r;
28408
28409   x0 = gen_reg_rtx (mode);
28410   e0 = gen_reg_rtx (mode);
28411   e1 = gen_reg_rtx (mode);
28412   e2 = gen_reg_rtx (mode);
28413   e3 = gen_reg_rtx (mode);
28414
28415   real_from_integer (&r, VOIDmode, -3, -1, 0);
28416   mthree = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
28417
28418   real_arithmetic (&r, NEGATE_EXPR, &dconsthalf, NULL);
28419   mhalf = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
28420
28421   if (VECTOR_MODE_P (mode))
28422     {
28423       mthree = ix86_build_const_vector (SFmode, true, mthree);
28424       mhalf = ix86_build_const_vector (SFmode, true, mhalf);
28425     }
28426
28427   /* sqrt(a)  = -0.5 * a * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0)
28428      rsqrt(a) = -0.5     * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0) */
28429
28430   /* x0 = rsqrt(a) estimate */
28431   emit_insn (gen_rtx_SET (VOIDmode, x0,
28432                           gen_rtx_UNSPEC (mode, gen_rtvec (1, a),
28433                                           UNSPEC_RSQRT)));
28434
28435   /* If (a == 0.0) Filter out infinity to prevent NaN for sqrt(0.0).  */
28436   if (!recip)
28437     {
28438       rtx zero, mask;
28439
28440       zero = gen_reg_rtx (mode);
28441       mask = gen_reg_rtx (mode);
28442
28443       zero = force_reg (mode, CONST0_RTX(mode));
28444       emit_insn (gen_rtx_SET (VOIDmode, mask,
28445                               gen_rtx_NE (mode, zero, a)));
28446
28447       emit_insn (gen_rtx_SET (VOIDmode, x0,
28448                               gen_rtx_AND (mode, x0, mask)));
28449     }
28450
28451   /* e0 = x0 * a */
28452   emit_insn (gen_rtx_SET (VOIDmode, e0,
28453                           gen_rtx_MULT (mode, x0, a)));
28454   /* e1 = e0 * x0 */
28455   emit_insn (gen_rtx_SET (VOIDmode, e1,
28456                           gen_rtx_MULT (mode, e0, x0)));
28457
28458   /* e2 = e1 - 3. */
28459   mthree = force_reg (mode, mthree);
28460   emit_insn (gen_rtx_SET (VOIDmode, e2,
28461                           gen_rtx_PLUS (mode, e1, mthree)));
28462
28463   mhalf = force_reg (mode, mhalf);
28464   if (recip)
28465     /* e3 = -.5 * x0 */
28466     emit_insn (gen_rtx_SET (VOIDmode, e3,
28467                             gen_rtx_MULT (mode, x0, mhalf)));
28468   else
28469     /* e3 = -.5 * e0 */
28470     emit_insn (gen_rtx_SET (VOIDmode, e3,
28471                             gen_rtx_MULT (mode, e0, mhalf)));
28472   /* ret = e2 * e3 */
28473   emit_insn (gen_rtx_SET (VOIDmode, res,
28474                           gen_rtx_MULT (mode, e2, e3)));
28475 }
28476
28477 /* Solaris implementation of TARGET_ASM_NAMED_SECTION.  */
28478
28479 static void ATTRIBUTE_UNUSED
28480 i386_solaris_elf_named_section (const char *name, unsigned int flags,
28481                                 tree decl)
28482 {
28483   /* With Binutils 2.15, the "@unwind" marker must be specified on
28484      every occurrence of the ".eh_frame" section, not just the first
28485      one.  */
28486   if (TARGET_64BIT
28487       && strcmp (name, ".eh_frame") == 0)
28488     {
28489       fprintf (asm_out_file, "\t.section\t%s,\"%s\",@unwind\n", name,
28490                flags & SECTION_WRITE ? "aw" : "a");
28491       return;
28492     }
28493   default_elf_asm_named_section (name, flags, decl);
28494 }
28495
28496 /* Return the mangling of TYPE if it is an extended fundamental type.  */
28497
28498 static const char *
28499 ix86_mangle_type (const_tree type)
28500 {
28501   type = TYPE_MAIN_VARIANT (type);
28502
28503   if (TREE_CODE (type) != VOID_TYPE && TREE_CODE (type) != BOOLEAN_TYPE
28504       && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
28505     return NULL;
28506
28507   switch (TYPE_MODE (type))
28508     {
28509     case TFmode:
28510       /* __float128 is "g".  */
28511       return "g";
28512     case XFmode:
28513       /* "long double" or __float80 is "e".  */
28514       return "e";
28515     default:
28516       return NULL;
28517     }
28518 }
28519
28520 /* For 32-bit code we can save PIC register setup by using
28521    __stack_chk_fail_local hidden function instead of calling
28522    __stack_chk_fail directly.  64-bit code doesn't need to setup any PIC
28523    register, so it is better to call __stack_chk_fail directly.  */
28524
28525 static tree
28526 ix86_stack_protect_fail (void)
28527 {
28528   return TARGET_64BIT
28529          ? default_external_stack_protect_fail ()
28530          : default_hidden_stack_protect_fail ();
28531 }
28532
28533 /* Select a format to encode pointers in exception handling data.  CODE
28534    is 0 for data, 1 for code labels, 2 for function pointers.  GLOBAL is
28535    true if the symbol may be affected by dynamic relocations.
28536
28537    ??? All x86 object file formats are capable of representing this.
28538    After all, the relocation needed is the same as for the call insn.
28539    Whether or not a particular assembler allows us to enter such, I
28540    guess we'll have to see.  */
28541 int
28542 asm_preferred_eh_data_format (int code, int global)
28543 {
28544   if (flag_pic)
28545     {
28546       int type = DW_EH_PE_sdata8;
28547       if (!TARGET_64BIT
28548           || ix86_cmodel == CM_SMALL_PIC
28549           || (ix86_cmodel == CM_MEDIUM_PIC && (global || code)))
28550         type = DW_EH_PE_sdata4;
28551       return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type;
28552     }
28553   if (ix86_cmodel == CM_SMALL
28554       || (ix86_cmodel == CM_MEDIUM && code))
28555     return DW_EH_PE_udata4;
28556   return DW_EH_PE_absptr;
28557 }
28558 \f
28559 /* Expand copysign from SIGN to the positive value ABS_VALUE
28560    storing in RESULT.  If MASK is non-null, it shall be a mask to mask out
28561    the sign-bit.  */
28562 static void
28563 ix86_sse_copysign_to_positive (rtx result, rtx abs_value, rtx sign, rtx mask)
28564 {
28565   enum machine_mode mode = GET_MODE (sign);
28566   rtx sgn = gen_reg_rtx (mode);
28567   if (mask == NULL_RTX)
28568     {
28569       mask = ix86_build_signbit_mask (mode, VECTOR_MODE_P (mode), false);
28570       if (!VECTOR_MODE_P (mode))
28571         {
28572           /* We need to generate a scalar mode mask in this case.  */
28573           rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
28574           tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
28575           mask = gen_reg_rtx (mode);
28576           emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
28577         }
28578     }
28579   else
28580     mask = gen_rtx_NOT (mode, mask);
28581   emit_insn (gen_rtx_SET (VOIDmode, sgn,
28582                           gen_rtx_AND (mode, mask, sign)));
28583   emit_insn (gen_rtx_SET (VOIDmode, result,
28584                           gen_rtx_IOR (mode, abs_value, sgn)));
28585 }
28586
28587 /* Expand fabs (OP0) and return a new rtx that holds the result.  The
28588    mask for masking out the sign-bit is stored in *SMASK, if that is
28589    non-null.  */
28590 static rtx
28591 ix86_expand_sse_fabs (rtx op0, rtx *smask)
28592 {
28593   enum machine_mode mode = GET_MODE (op0);
28594   rtx xa, mask;
28595
28596   xa = gen_reg_rtx (mode);
28597   mask = ix86_build_signbit_mask (mode, VECTOR_MODE_P (mode), true);
28598   if (!VECTOR_MODE_P (mode))
28599     {
28600       /* We need to generate a scalar mode mask in this case.  */
28601       rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
28602       tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
28603       mask = gen_reg_rtx (mode);
28604       emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
28605     }
28606   emit_insn (gen_rtx_SET (VOIDmode, xa,
28607                           gen_rtx_AND (mode, op0, mask)));
28608
28609   if (smask)
28610     *smask = mask;
28611
28612   return xa;
28613 }
28614
28615 /* Expands a comparison of OP0 with OP1 using comparison code CODE,
28616    swapping the operands if SWAP_OPERANDS is true.  The expanded
28617    code is a forward jump to a newly created label in case the
28618    comparison is true.  The generated label rtx is returned.  */
28619 static rtx
28620 ix86_expand_sse_compare_and_jump (enum rtx_code code, rtx op0, rtx op1,
28621                                   bool swap_operands)
28622 {
28623   rtx label, tmp;
28624
28625   if (swap_operands)
28626     {
28627       tmp = op0;
28628       op0 = op1;
28629       op1 = tmp;
28630     }
28631
28632   label = gen_label_rtx ();
28633   tmp = gen_rtx_REG (CCFPUmode, FLAGS_REG);
28634   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28635                           gen_rtx_COMPARE (CCFPUmode, op0, op1)));
28636   tmp = gen_rtx_fmt_ee (code, VOIDmode, tmp, const0_rtx);
28637   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
28638                               gen_rtx_LABEL_REF (VOIDmode, label), pc_rtx);
28639   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
28640   JUMP_LABEL (tmp) = label;
28641
28642   return label;
28643 }
28644
28645 /* Expand a mask generating SSE comparison instruction comparing OP0 with OP1
28646    using comparison code CODE.  Operands are swapped for the comparison if
28647    SWAP_OPERANDS is true.  Returns a rtx for the generated mask.  */
28648 static rtx
28649 ix86_expand_sse_compare_mask (enum rtx_code code, rtx op0, rtx op1,
28650                               bool swap_operands)
28651 {
28652   enum machine_mode mode = GET_MODE (op0);
28653   rtx mask = gen_reg_rtx (mode);
28654
28655   if (swap_operands)
28656     {
28657       rtx tmp = op0;
28658       op0 = op1;
28659       op1 = tmp;
28660     }
28661
28662   if (mode == DFmode)
28663     emit_insn (gen_sse2_maskcmpdf3 (mask, op0, op1,
28664                                     gen_rtx_fmt_ee (code, mode, op0, op1)));
28665   else
28666     emit_insn (gen_sse_maskcmpsf3 (mask, op0, op1,
28667                                    gen_rtx_fmt_ee (code, mode, op0, op1)));
28668
28669   return mask;
28670 }
28671
28672 /* Generate and return a rtx of mode MODE for 2**n where n is the number
28673    of bits of the mantissa of MODE, which must be one of DFmode or SFmode.  */
28674 static rtx
28675 ix86_gen_TWO52 (enum machine_mode mode)
28676 {
28677   REAL_VALUE_TYPE TWO52r;
28678   rtx TWO52;
28679
28680   real_ldexp (&TWO52r, &dconst1, mode == DFmode ? 52 : 23);
28681   TWO52 = const_double_from_real_value (TWO52r, mode);
28682   TWO52 = force_reg (mode, TWO52);
28683
28684   return TWO52;
28685 }
28686
28687 /* Expand SSE sequence for computing lround from OP1 storing
28688    into OP0.  */
28689 void
28690 ix86_expand_lround (rtx op0, rtx op1)
28691 {
28692   /* C code for the stuff we're doing below:
28693        tmp = op1 + copysign (nextafter (0.5, 0.0), op1)
28694        return (long)tmp;
28695    */
28696   enum machine_mode mode = GET_MODE (op1);
28697   const struct real_format *fmt;
28698   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
28699   rtx adj;
28700
28701   /* load nextafter (0.5, 0.0) */
28702   fmt = REAL_MODE_FORMAT (mode);
28703   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
28704   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
28705
28706   /* adj = copysign (0.5, op1) */
28707   adj = force_reg (mode, const_double_from_real_value (pred_half, mode));
28708   ix86_sse_copysign_to_positive (adj, adj, force_reg (mode, op1), NULL_RTX);
28709
28710   /* adj = op1 + adj */
28711   adj = expand_simple_binop (mode, PLUS, adj, op1, NULL_RTX, 0, OPTAB_DIRECT);
28712
28713   /* op0 = (imode)adj */
28714   expand_fix (op0, adj, 0);
28715 }
28716
28717 /* Expand SSE2 sequence for computing lround from OPERAND1 storing
28718    into OPERAND0.  */
28719 void
28720 ix86_expand_lfloorceil (rtx op0, rtx op1, bool do_floor)
28721 {
28722   /* C code for the stuff we're doing below (for do_floor):
28723         xi = (long)op1;
28724         xi -= (double)xi > op1 ? 1 : 0;
28725         return xi;
28726    */
28727   enum machine_mode fmode = GET_MODE (op1);
28728   enum machine_mode imode = GET_MODE (op0);
28729   rtx ireg, freg, label, tmp;
28730
28731   /* reg = (long)op1 */
28732   ireg = gen_reg_rtx (imode);
28733   expand_fix (ireg, op1, 0);
28734
28735   /* freg = (double)reg */
28736   freg = gen_reg_rtx (fmode);
28737   expand_float (freg, ireg, 0);
28738
28739   /* ireg = (freg > op1) ? ireg - 1 : ireg */
28740   label = ix86_expand_sse_compare_and_jump (UNLE,
28741                                             freg, op1, !do_floor);
28742   tmp = expand_simple_binop (imode, do_floor ? MINUS : PLUS,
28743                              ireg, const1_rtx, NULL_RTX, 0, OPTAB_DIRECT);
28744   emit_move_insn (ireg, tmp);
28745
28746   emit_label (label);
28747   LABEL_NUSES (label) = 1;
28748
28749   emit_move_insn (op0, ireg);
28750 }
28751
28752 /* Expand rint (IEEE round to nearest) rounding OPERAND1 and storing the
28753    result in OPERAND0.  */
28754 void
28755 ix86_expand_rint (rtx operand0, rtx operand1)
28756 {
28757   /* C code for the stuff we're doing below:
28758         xa = fabs (operand1);
28759         if (!isless (xa, 2**52))
28760           return operand1;
28761         xa = xa + 2**52 - 2**52;
28762         return copysign (xa, operand1);
28763    */
28764   enum machine_mode mode = GET_MODE (operand0);
28765   rtx res, xa, label, TWO52, mask;
28766
28767   res = gen_reg_rtx (mode);
28768   emit_move_insn (res, operand1);
28769
28770   /* xa = abs (operand1) */
28771   xa = ix86_expand_sse_fabs (res, &mask);
28772
28773   /* if (!isless (xa, TWO52)) goto label; */
28774   TWO52 = ix86_gen_TWO52 (mode);
28775   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28776
28777   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
28778   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
28779
28780   ix86_sse_copysign_to_positive (res, xa, res, mask);
28781
28782   emit_label (label);
28783   LABEL_NUSES (label) = 1;
28784
28785   emit_move_insn (operand0, res);
28786 }
28787
28788 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
28789    into OPERAND0.  */
28790 void
28791 ix86_expand_floorceildf_32 (rtx operand0, rtx operand1, bool do_floor)
28792 {
28793   /* C code for the stuff we expand below.
28794         double xa = fabs (x), x2;
28795         if (!isless (xa, TWO52))
28796           return x;
28797         xa = xa + TWO52 - TWO52;
28798         x2 = copysign (xa, x);
28799      Compensate.  Floor:
28800         if (x2 > x)
28801           x2 -= 1;
28802      Compensate.  Ceil:
28803         if (x2 < x)
28804           x2 -= -1;
28805         return x2;
28806    */
28807   enum machine_mode mode = GET_MODE (operand0);
28808   rtx xa, TWO52, tmp, label, one, res, mask;
28809
28810   TWO52 = ix86_gen_TWO52 (mode);
28811
28812   /* Temporary for holding the result, initialized to the input
28813      operand to ease control flow.  */
28814   res = gen_reg_rtx (mode);
28815   emit_move_insn (res, operand1);
28816
28817   /* xa = abs (operand1) */
28818   xa = ix86_expand_sse_fabs (res, &mask);
28819
28820   /* if (!isless (xa, TWO52)) goto label; */
28821   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28822
28823   /* xa = xa + TWO52 - TWO52; */
28824   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
28825   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
28826
28827   /* xa = copysign (xa, operand1) */
28828   ix86_sse_copysign_to_positive (xa, xa, res, mask);
28829
28830   /* generate 1.0 or -1.0 */
28831   one = force_reg (mode,
28832                    const_double_from_real_value (do_floor
28833                                                  ? dconst1 : dconstm1, mode));
28834
28835   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
28836   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
28837   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28838                           gen_rtx_AND (mode, one, tmp)));
28839   /* We always need to subtract here to preserve signed zero.  */
28840   tmp = expand_simple_binop (mode, MINUS,
28841                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
28842   emit_move_insn (res, tmp);
28843
28844   emit_label (label);
28845   LABEL_NUSES (label) = 1;
28846
28847   emit_move_insn (operand0, res);
28848 }
28849
28850 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
28851    into OPERAND0.  */
28852 void
28853 ix86_expand_floorceil (rtx operand0, rtx operand1, bool do_floor)
28854 {
28855   /* C code for the stuff we expand below.
28856         double xa = fabs (x), x2;
28857         if (!isless (xa, TWO52))
28858           return x;
28859         x2 = (double)(long)x;
28860      Compensate.  Floor:
28861         if (x2 > x)
28862           x2 -= 1;
28863      Compensate.  Ceil:
28864         if (x2 < x)
28865           x2 += 1;
28866         if (HONOR_SIGNED_ZEROS (mode))
28867           return copysign (x2, x);
28868         return x2;
28869    */
28870   enum machine_mode mode = GET_MODE (operand0);
28871   rtx xa, xi, TWO52, tmp, label, one, res, mask;
28872
28873   TWO52 = ix86_gen_TWO52 (mode);
28874
28875   /* Temporary for holding the result, initialized to the input
28876      operand to ease control flow.  */
28877   res = gen_reg_rtx (mode);
28878   emit_move_insn (res, operand1);
28879
28880   /* xa = abs (operand1) */
28881   xa = ix86_expand_sse_fabs (res, &mask);
28882
28883   /* if (!isless (xa, TWO52)) goto label; */
28884   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28885
28886   /* xa = (double)(long)x */
28887   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
28888   expand_fix (xi, res, 0);
28889   expand_float (xa, xi, 0);
28890
28891   /* generate 1.0 */
28892   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
28893
28894   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
28895   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
28896   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28897                           gen_rtx_AND (mode, one, tmp)));
28898   tmp = expand_simple_binop (mode, do_floor ? MINUS : PLUS,
28899                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
28900   emit_move_insn (res, tmp);
28901
28902   if (HONOR_SIGNED_ZEROS (mode))
28903     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
28904
28905   emit_label (label);
28906   LABEL_NUSES (label) = 1;
28907
28908   emit_move_insn (operand0, res);
28909 }
28910
28911 /* Expand SSE sequence for computing round from OPERAND1 storing
28912    into OPERAND0.  Sequence that works without relying on DImode truncation
28913    via cvttsd2siq that is only available on 64bit targets.  */
28914 void
28915 ix86_expand_rounddf_32 (rtx operand0, rtx operand1)
28916 {
28917   /* C code for the stuff we expand below.
28918         double xa = fabs (x), xa2, x2;
28919         if (!isless (xa, TWO52))
28920           return x;
28921      Using the absolute value and copying back sign makes
28922      -0.0 -> -0.0 correct.
28923         xa2 = xa + TWO52 - TWO52;
28924      Compensate.
28925         dxa = xa2 - xa;
28926         if (dxa <= -0.5)
28927           xa2 += 1;
28928         else if (dxa > 0.5)
28929           xa2 -= 1;
28930         x2 = copysign (xa2, x);
28931         return x2;
28932    */
28933   enum machine_mode mode = GET_MODE (operand0);
28934   rtx xa, xa2, dxa, TWO52, tmp, label, half, mhalf, one, res, mask;
28935
28936   TWO52 = ix86_gen_TWO52 (mode);
28937
28938   /* Temporary for holding the result, initialized to the input
28939      operand to ease control flow.  */
28940   res = gen_reg_rtx (mode);
28941   emit_move_insn (res, operand1);
28942
28943   /* xa = abs (operand1) */
28944   xa = ix86_expand_sse_fabs (res, &mask);
28945
28946   /* if (!isless (xa, TWO52)) goto label; */
28947   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
28948
28949   /* xa2 = xa + TWO52 - TWO52; */
28950   xa2 = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
28951   xa2 = expand_simple_binop (mode, MINUS, xa2, TWO52, xa2, 0, OPTAB_DIRECT);
28952
28953   /* dxa = xa2 - xa; */
28954   dxa = expand_simple_binop (mode, MINUS, xa2, xa, NULL_RTX, 0, OPTAB_DIRECT);
28955
28956   /* generate 0.5, 1.0 and -0.5 */
28957   half = force_reg (mode, const_double_from_real_value (dconsthalf, mode));
28958   one = expand_simple_binop (mode, PLUS, half, half, NULL_RTX, 0, OPTAB_DIRECT);
28959   mhalf = expand_simple_binop (mode, MINUS, half, one, NULL_RTX,
28960                                0, OPTAB_DIRECT);
28961
28962   /* Compensate.  */
28963   tmp = gen_reg_rtx (mode);
28964   /* xa2 = xa2 - (dxa > 0.5 ? 1 : 0) */
28965   tmp = ix86_expand_sse_compare_mask (UNGT, dxa, half, false);
28966   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28967                           gen_rtx_AND (mode, one, tmp)));
28968   xa2 = expand_simple_binop (mode, MINUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
28969   /* xa2 = xa2 + (dxa <= -0.5 ? 1 : 0) */
28970   tmp = ix86_expand_sse_compare_mask (UNGE, mhalf, dxa, false);
28971   emit_insn (gen_rtx_SET (VOIDmode, tmp,
28972                           gen_rtx_AND (mode, one, tmp)));
28973   xa2 = expand_simple_binop (mode, PLUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
28974
28975   /* res = copysign (xa2, operand1) */
28976   ix86_sse_copysign_to_positive (res, xa2, force_reg (mode, operand1), mask);
28977
28978   emit_label (label);
28979   LABEL_NUSES (label) = 1;
28980
28981   emit_move_insn (operand0, res);
28982 }
28983
28984 /* Expand SSE sequence for computing trunc from OPERAND1 storing
28985    into OPERAND0.  */
28986 void
28987 ix86_expand_trunc (rtx operand0, rtx operand1)
28988 {
28989   /* C code for SSE variant we expand below.
28990         double xa = fabs (x), x2;
28991         if (!isless (xa, TWO52))
28992           return x;
28993         x2 = (double)(long)x;
28994         if (HONOR_SIGNED_ZEROS (mode))
28995           return copysign (x2, x);
28996         return x2;
28997    */
28998   enum machine_mode mode = GET_MODE (operand0);
28999   rtx xa, xi, TWO52, label, res, mask;
29000
29001   TWO52 = ix86_gen_TWO52 (mode);
29002
29003   /* Temporary for holding the result, initialized to the input
29004      operand to ease control flow.  */
29005   res = gen_reg_rtx (mode);
29006   emit_move_insn (res, operand1);
29007
29008   /* xa = abs (operand1) */
29009   xa = ix86_expand_sse_fabs (res, &mask);
29010
29011   /* if (!isless (xa, TWO52)) goto label; */
29012   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
29013
29014   /* x = (double)(long)x */
29015   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
29016   expand_fix (xi, res, 0);
29017   expand_float (res, xi, 0);
29018
29019   if (HONOR_SIGNED_ZEROS (mode))
29020     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
29021
29022   emit_label (label);
29023   LABEL_NUSES (label) = 1;
29024
29025   emit_move_insn (operand0, res);
29026 }
29027
29028 /* Expand SSE sequence for computing trunc from OPERAND1 storing
29029    into OPERAND0.  */
29030 void
29031 ix86_expand_truncdf_32 (rtx operand0, rtx operand1)
29032 {
29033   enum machine_mode mode = GET_MODE (operand0);
29034   rtx xa, mask, TWO52, label, one, res, smask, tmp;
29035
29036   /* C code for SSE variant we expand below.
29037         double xa = fabs (x), x2;
29038         if (!isless (xa, TWO52))
29039           return x;
29040         xa2 = xa + TWO52 - TWO52;
29041      Compensate:
29042         if (xa2 > xa)
29043           xa2 -= 1.0;
29044         x2 = copysign (xa2, x);
29045         return x2;
29046    */
29047
29048   TWO52 = ix86_gen_TWO52 (mode);
29049
29050   /* Temporary for holding the result, initialized to the input
29051      operand to ease control flow.  */
29052   res = gen_reg_rtx (mode);
29053   emit_move_insn (res, operand1);
29054
29055   /* xa = abs (operand1) */
29056   xa = ix86_expand_sse_fabs (res, &smask);
29057
29058   /* if (!isless (xa, TWO52)) goto label; */
29059   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
29060
29061   /* res = xa + TWO52 - TWO52; */
29062   tmp = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
29063   tmp = expand_simple_binop (mode, MINUS, tmp, TWO52, tmp, 0, OPTAB_DIRECT);
29064   emit_move_insn (res, tmp);
29065
29066   /* generate 1.0 */
29067   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
29068
29069   /* Compensate: res = xa2 - (res > xa ? 1 : 0)  */
29070   mask = ix86_expand_sse_compare_mask (UNGT, res, xa, false);
29071   emit_insn (gen_rtx_SET (VOIDmode, mask,
29072                           gen_rtx_AND (mode, mask, one)));
29073   tmp = expand_simple_binop (mode, MINUS,
29074                              res, mask, NULL_RTX, 0, OPTAB_DIRECT);
29075   emit_move_insn (res, tmp);
29076
29077   /* res = copysign (res, operand1) */
29078   ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), smask);
29079
29080   emit_label (label);
29081   LABEL_NUSES (label) = 1;
29082
29083   emit_move_insn (operand0, res);
29084 }
29085
29086 /* Expand SSE sequence for computing round from OPERAND1 storing
29087    into OPERAND0.  */
29088 void
29089 ix86_expand_round (rtx operand0, rtx operand1)
29090 {
29091   /* C code for the stuff we're doing below:
29092         double xa = fabs (x);
29093         if (!isless (xa, TWO52))
29094           return x;
29095         xa = (double)(long)(xa + nextafter (0.5, 0.0));
29096         return copysign (xa, x);
29097    */
29098   enum machine_mode mode = GET_MODE (operand0);
29099   rtx res, TWO52, xa, label, xi, half, mask;
29100   const struct real_format *fmt;
29101   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
29102
29103   /* Temporary for holding the result, initialized to the input
29104      operand to ease control flow.  */
29105   res = gen_reg_rtx (mode);
29106   emit_move_insn (res, operand1);
29107
29108   TWO52 = ix86_gen_TWO52 (mode);
29109   xa = ix86_expand_sse_fabs (res, &mask);
29110   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
29111
29112   /* load nextafter (0.5, 0.0) */
29113   fmt = REAL_MODE_FORMAT (mode);
29114   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
29115   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
29116
29117   /* xa = xa + 0.5 */
29118   half = force_reg (mode, const_double_from_real_value (pred_half, mode));
29119   xa = expand_simple_binop (mode, PLUS, xa, half, NULL_RTX, 0, OPTAB_DIRECT);
29120
29121   /* xa = (double)(int64_t)xa */
29122   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
29123   expand_fix (xi, xa, 0);
29124   expand_float (xa, xi, 0);
29125
29126   /* res = copysign (xa, operand1) */
29127   ix86_sse_copysign_to_positive (res, xa, force_reg (mode, operand1), mask);
29128
29129   emit_label (label);
29130   LABEL_NUSES (label) = 1;
29131
29132   emit_move_insn (operand0, res);
29133 }
29134
29135 \f
29136 /* Validate whether a SSE5 instruction is valid or not.
29137    OPERANDS is the array of operands.
29138    NUM is the number of operands.
29139    USES_OC0 is true if the instruction uses OC0 and provides 4 variants.
29140    NUM_MEMORY is the maximum number of memory operands to accept.  
29141    when COMMUTATIVE is set, operand 1 and 2 can be swapped.  */
29142
29143 bool
29144 ix86_sse5_valid_op_p (rtx operands[], rtx insn ATTRIBUTE_UNUSED, int num,
29145                       bool uses_oc0, int num_memory, bool commutative)
29146 {
29147   int mem_mask;
29148   int mem_count;
29149   int i;
29150
29151   /* Count the number of memory arguments */
29152   mem_mask = 0;
29153   mem_count = 0;
29154   for (i = 0; i < num; i++)
29155     {
29156       enum machine_mode mode = GET_MODE (operands[i]);
29157       if (register_operand (operands[i], mode))
29158         ;
29159
29160       else if (memory_operand (operands[i], mode))
29161         {
29162           mem_mask |= (1 << i);
29163           mem_count++;
29164         }
29165
29166       else
29167         {
29168           rtx pattern = PATTERN (insn);
29169
29170           /* allow 0 for pcmov */
29171           if (GET_CODE (pattern) != SET
29172               || GET_CODE (SET_SRC (pattern)) != IF_THEN_ELSE
29173               || i < 2
29174               || operands[i] != CONST0_RTX (mode))
29175             return false;
29176         }
29177     }
29178
29179   /* Special case pmacsdq{l,h} where we allow the 3rd argument to be
29180      a memory operation.  */
29181   if (num_memory < 0)
29182     {
29183       num_memory = -num_memory;
29184       if ((mem_mask & (1 << (num-1))) != 0)
29185         {
29186           mem_mask &= ~(1 << (num-1));
29187           mem_count--;
29188         }
29189     }
29190
29191   /* If there were no memory operations, allow the insn */
29192   if (mem_mask == 0)
29193     return true;
29194
29195   /* Do not allow the destination register to be a memory operand.  */
29196   else if (mem_mask & (1 << 0))
29197     return false;
29198
29199   /* If there are too many memory operations, disallow the instruction.  While
29200      the hardware only allows 1 memory reference, before register allocation
29201      for some insns, we allow two memory operations sometimes in order to allow
29202      code like the following to be optimized:
29203
29204         float fmadd (float *a, float *b, float *c) { return (*a * *b) + *c; }
29205
29206     or similar cases that are vectorized into using the fmaddss
29207     instruction.  */
29208   else if (mem_count > num_memory)
29209     return false;
29210
29211   /* Don't allow more than one memory operation if not optimizing.  */
29212   else if (mem_count > 1 && !optimize)
29213     return false;
29214
29215   else if (num == 4 && mem_count == 1)
29216     {
29217       /* formats (destination is the first argument), example fmaddss:
29218          xmm1, xmm1, xmm2, xmm3/mem
29219          xmm1, xmm1, xmm2/mem, xmm3
29220          xmm1, xmm2, xmm3/mem, xmm1
29221          xmm1, xmm2/mem, xmm3, xmm1 */
29222       if (uses_oc0)
29223         return ((mem_mask == (1 << 1))
29224                 || (mem_mask == (1 << 2))
29225                 || (mem_mask == (1 << 3)));
29226
29227       /* format, example pmacsdd:
29228          xmm1, xmm2, xmm3/mem, xmm1 */
29229       if (commutative)
29230         return (mem_mask == (1 << 2) || mem_mask == (1 << 1));
29231       else
29232         return (mem_mask == (1 << 2));
29233     }
29234
29235   else if (num == 4 && num_memory == 2)
29236     {
29237       /* If there are two memory operations, we can load one of the memory ops
29238          into the destination register.  This is for optimizing the
29239          multiply/add ops, which the combiner has optimized both the multiply
29240          and the add insns to have a memory operation.  We have to be careful
29241          that the destination doesn't overlap with the inputs.  */
29242       rtx op0 = operands[0];
29243
29244       if (reg_mentioned_p (op0, operands[1])
29245           || reg_mentioned_p (op0, operands[2])
29246           || reg_mentioned_p (op0, operands[3]))
29247         return false;
29248
29249       /* formats (destination is the first argument), example fmaddss:
29250          xmm1, xmm1, xmm2, xmm3/mem
29251          xmm1, xmm1, xmm2/mem, xmm3
29252          xmm1, xmm2, xmm3/mem, xmm1
29253          xmm1, xmm2/mem, xmm3, xmm1
29254
29255          For the oc0 case, we will load either operands[1] or operands[3] into
29256          operands[0], so any combination of 2 memory operands is ok.  */
29257       if (uses_oc0)
29258         return true;
29259
29260       /* format, example pmacsdd:
29261          xmm1, xmm2, xmm3/mem, xmm1
29262
29263          For the integer multiply/add instructions be more restrictive and
29264          require operands[2] and operands[3] to be the memory operands.  */
29265       if (commutative)
29266         return (mem_mask == ((1 << 1) | (1 << 3)) || ((1 << 2) | (1 << 3)));
29267       else
29268         return (mem_mask == ((1 << 2) | (1 << 3)));
29269     }
29270
29271   else if (num == 3 && num_memory == 1)
29272     {
29273       /* formats, example protb:
29274          xmm1, xmm2, xmm3/mem
29275          xmm1, xmm2/mem, xmm3 */
29276       if (uses_oc0)
29277         return ((mem_mask == (1 << 1)) || (mem_mask == (1 << 2)));
29278
29279       /* format, example comeq:
29280          xmm1, xmm2, xmm3/mem */
29281       else
29282         return (mem_mask == (1 << 2));
29283     }
29284
29285   else
29286     gcc_unreachable ();
29287
29288   return false;
29289 }
29290
29291 \f
29292 /* Fixup an SSE5 instruction that has 2 memory input references into a form the
29293    hardware will allow by using the destination register to load one of the
29294    memory operations.  Presently this is used by the multiply/add routines to
29295    allow 2 memory references.  */
29296
29297 void
29298 ix86_expand_sse5_multiple_memory (rtx operands[],
29299                                   int num,
29300                                   enum machine_mode mode)
29301 {
29302   rtx op0 = operands[0];
29303   if (num != 4
29304       || memory_operand (op0, mode)
29305       || reg_mentioned_p (op0, operands[1])
29306       || reg_mentioned_p (op0, operands[2])
29307       || reg_mentioned_p (op0, operands[3]))
29308     gcc_unreachable ();
29309
29310   /* For 2 memory operands, pick either operands[1] or operands[3] to move into
29311      the destination register.  */
29312   if (memory_operand (operands[1], mode))
29313     {
29314       emit_move_insn (op0, operands[1]);
29315       operands[1] = op0;
29316     }
29317   else if (memory_operand (operands[3], mode))
29318     {
29319       emit_move_insn (op0, operands[3]);
29320       operands[3] = op0;
29321     }
29322   else
29323     gcc_unreachable ();
29324
29325   return;
29326 }
29327
29328 \f
29329 /* Table of valid machine attributes.  */
29330 static const struct attribute_spec ix86_attribute_table[] =
29331 {
29332   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
29333   /* Stdcall attribute says callee is responsible for popping arguments
29334      if they are not variable.  */
29335   { "stdcall",   0, 0, false, true,  true,  ix86_handle_cconv_attribute },
29336   /* Fastcall attribute says callee is responsible for popping arguments
29337      if they are not variable.  */
29338   { "fastcall",  0, 0, false, true,  true,  ix86_handle_cconv_attribute },
29339   /* Cdecl attribute says the callee is a normal C declaration */
29340   { "cdecl",     0, 0, false, true,  true,  ix86_handle_cconv_attribute },
29341   /* Regparm attribute specifies how many integer arguments are to be
29342      passed in registers.  */
29343   { "regparm",   1, 1, false, true,  true,  ix86_handle_cconv_attribute },
29344   /* Sseregparm attribute says we are using x86_64 calling conventions
29345      for FP arguments.  */
29346   { "sseregparm", 0, 0, false, true, true, ix86_handle_cconv_attribute },
29347   /* force_align_arg_pointer says this function realigns the stack at entry.  */
29348   { (const char *)&ix86_force_align_arg_pointer_string, 0, 0,
29349     false, true,  true, ix86_handle_cconv_attribute },
29350 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
29351   { "dllimport", 0, 0, false, false, false, handle_dll_attribute },
29352   { "dllexport", 0, 0, false, false, false, handle_dll_attribute },
29353   { "shared",    0, 0, true,  false, false, ix86_handle_shared_attribute },
29354 #endif
29355   { "ms_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute },
29356   { "gcc_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute },
29357 #ifdef SUBTARGET_ATTRIBUTE_TABLE
29358   SUBTARGET_ATTRIBUTE_TABLE,
29359 #endif
29360   /* ms_abi and sysv_abi calling convention function attributes.  */
29361   { "ms_abi", 0, 0, false, true, true, ix86_handle_abi_attribute },
29362   { "sysv_abi", 0, 0, false, true, true, ix86_handle_abi_attribute },
29363   /* End element.  */
29364   { NULL,        0, 0, false, false, false, NULL }
29365 };
29366
29367 /* Implement targetm.vectorize.builtin_vectorization_cost.  */
29368 static int
29369 x86_builtin_vectorization_cost (bool runtime_test)
29370 {
29371   /* If the branch of the runtime test is taken - i.e. - the vectorized
29372      version is skipped - this incurs a misprediction cost (because the
29373      vectorized version is expected to be the fall-through).  So we subtract
29374      the latency of a mispredicted branch from the costs that are incured
29375      when the vectorized version is executed.
29376
29377      TODO: The values in individual target tables have to be tuned or new
29378      fields may be needed. For eg. on K8, the default branch path is the
29379      not-taken path. If the taken path is predicted correctly, the minimum
29380      penalty of going down the taken-path is 1 cycle. If the taken-path is
29381      not predicted correctly, then the minimum penalty is 10 cycles.  */
29382
29383   if (runtime_test)
29384     {
29385       return (-(ix86_cost->cond_taken_branch_cost));
29386     }
29387   else
29388     return 0;
29389 }
29390
29391 /* This function returns the calling abi specific va_list type node.
29392    It returns  the FNDECL specific va_list type.  */
29393
29394 tree
29395 ix86_fn_abi_va_list (tree fndecl)
29396 {
29397   int abi;
29398
29399   if (!TARGET_64BIT)
29400     return va_list_type_node;
29401   gcc_assert (fndecl != NULL_TREE);
29402   abi = ix86_function_abi ((const_tree) fndecl);
29403
29404   if (abi == MS_ABI)
29405     return ms_va_list_type_node;
29406   else
29407     return sysv_va_list_type_node;
29408 }
29409
29410 /* Returns the canonical va_list type specified by TYPE. If there
29411    is no valid TYPE provided, it return NULL_TREE.  */
29412
29413 tree
29414 ix86_canonical_va_list_type (tree type)
29415 {
29416   tree wtype, htype;
29417
29418   /* Resolve references and pointers to va_list type.  */
29419   if (INDIRECT_REF_P (type))
29420     type = TREE_TYPE (type);
29421   else if (POINTER_TYPE_P (type) && POINTER_TYPE_P (TREE_TYPE(type)))
29422     type = TREE_TYPE (type);
29423
29424   if (TARGET_64BIT)
29425     {
29426       wtype = va_list_type_node;
29427           gcc_assert (wtype != NULL_TREE);
29428       htype = type;
29429       if (TREE_CODE (wtype) == ARRAY_TYPE)
29430         {
29431           /* If va_list is an array type, the argument may have decayed
29432              to a pointer type, e.g. by being passed to another function.
29433              In that case, unwrap both types so that we can compare the
29434              underlying records.  */
29435           if (TREE_CODE (htype) == ARRAY_TYPE
29436               || POINTER_TYPE_P (htype))
29437             {
29438               wtype = TREE_TYPE (wtype);
29439               htype = TREE_TYPE (htype);
29440             }
29441         }
29442       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
29443         return va_list_type_node;
29444       wtype = sysv_va_list_type_node;
29445           gcc_assert (wtype != NULL_TREE);
29446       htype = type;
29447       if (TREE_CODE (wtype) == ARRAY_TYPE)
29448         {
29449           /* If va_list is an array type, the argument may have decayed
29450              to a pointer type, e.g. by being passed to another function.
29451              In that case, unwrap both types so that we can compare the
29452              underlying records.  */
29453           if (TREE_CODE (htype) == ARRAY_TYPE
29454               || POINTER_TYPE_P (htype))
29455             {
29456               wtype = TREE_TYPE (wtype);
29457               htype = TREE_TYPE (htype);
29458             }
29459         }
29460       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
29461         return sysv_va_list_type_node;
29462       wtype = ms_va_list_type_node;
29463           gcc_assert (wtype != NULL_TREE);
29464       htype = type;
29465       if (TREE_CODE (wtype) == ARRAY_TYPE)
29466         {
29467           /* If va_list is an array type, the argument may have decayed
29468              to a pointer type, e.g. by being passed to another function.
29469              In that case, unwrap both types so that we can compare the
29470              underlying records.  */
29471           if (TREE_CODE (htype) == ARRAY_TYPE
29472               || POINTER_TYPE_P (htype))
29473             {
29474               wtype = TREE_TYPE (wtype);
29475               htype = TREE_TYPE (htype);
29476             }
29477         }
29478       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
29479         return ms_va_list_type_node;
29480       return NULL_TREE;
29481     }
29482   return std_canonical_va_list_type (type);
29483 }
29484
29485 /* Iterate through the target-specific builtin types for va_list.
29486     IDX denotes the iterator, *PTREE is set to the result type of
29487     the va_list builtin, and *PNAME to its internal type.
29488     Returns zero if there is no element for this index, otherwise
29489     IDX should be increased upon the next call.
29490     Note, do not iterate a base builtin's name like __builtin_va_list.
29491     Used from c_common_nodes_and_builtins.  */
29492
29493 int
29494 ix86_enum_va_list (int idx, const char **pname, tree *ptree)
29495 {
29496   if (!TARGET_64BIT)
29497     return 0;
29498   switch (idx) {
29499   case 0:
29500     *ptree = ms_va_list_type_node;
29501     *pname = "__builtin_ms_va_list";
29502     break;
29503   case 1:
29504     *ptree = sysv_va_list_type_node;
29505     *pname = "__builtin_sysv_va_list";
29506     break;
29507   default:
29508     return 0;
29509   }
29510   return 1;
29511 }
29512
29513 /* Initialize the GCC target structure.  */
29514 #undef TARGET_RETURN_IN_MEMORY
29515 #define TARGET_RETURN_IN_MEMORY ix86_return_in_memory
29516
29517 #undef TARGET_ATTRIBUTE_TABLE
29518 #define TARGET_ATTRIBUTE_TABLE ix86_attribute_table
29519 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
29520 #  undef TARGET_MERGE_DECL_ATTRIBUTES
29521 #  define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
29522 #endif
29523
29524 #undef TARGET_COMP_TYPE_ATTRIBUTES
29525 #define TARGET_COMP_TYPE_ATTRIBUTES ix86_comp_type_attributes
29526
29527 #undef TARGET_INIT_BUILTINS
29528 #define TARGET_INIT_BUILTINS ix86_init_builtins
29529 #undef TARGET_EXPAND_BUILTIN
29530 #define TARGET_EXPAND_BUILTIN ix86_expand_builtin
29531
29532 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
29533 #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
29534   ix86_builtin_vectorized_function
29535
29536 #undef TARGET_VECTORIZE_BUILTIN_CONVERSION
29537 #define TARGET_VECTORIZE_BUILTIN_CONVERSION ix86_vectorize_builtin_conversion
29538
29539 #undef TARGET_BUILTIN_RECIPROCAL
29540 #define TARGET_BUILTIN_RECIPROCAL ix86_builtin_reciprocal
29541
29542 #undef TARGET_ASM_FUNCTION_EPILOGUE
29543 #define TARGET_ASM_FUNCTION_EPILOGUE ix86_output_function_epilogue
29544
29545 #undef TARGET_ENCODE_SECTION_INFO
29546 #ifndef SUBTARGET_ENCODE_SECTION_INFO
29547 #define TARGET_ENCODE_SECTION_INFO ix86_encode_section_info
29548 #else
29549 #define TARGET_ENCODE_SECTION_INFO SUBTARGET_ENCODE_SECTION_INFO
29550 #endif
29551
29552 #undef TARGET_ASM_OPEN_PAREN
29553 #define TARGET_ASM_OPEN_PAREN ""
29554 #undef TARGET_ASM_CLOSE_PAREN
29555 #define TARGET_ASM_CLOSE_PAREN ""
29556
29557 #undef TARGET_ASM_ALIGNED_HI_OP
29558 #define TARGET_ASM_ALIGNED_HI_OP ASM_SHORT
29559 #undef TARGET_ASM_ALIGNED_SI_OP
29560 #define TARGET_ASM_ALIGNED_SI_OP ASM_LONG
29561 #ifdef ASM_QUAD
29562 #undef TARGET_ASM_ALIGNED_DI_OP
29563 #define TARGET_ASM_ALIGNED_DI_OP ASM_QUAD
29564 #endif
29565
29566 #undef TARGET_ASM_UNALIGNED_HI_OP
29567 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
29568 #undef TARGET_ASM_UNALIGNED_SI_OP
29569 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
29570 #undef TARGET_ASM_UNALIGNED_DI_OP
29571 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
29572
29573 #undef TARGET_SCHED_ADJUST_COST
29574 #define TARGET_SCHED_ADJUST_COST ix86_adjust_cost
29575 #undef TARGET_SCHED_ISSUE_RATE
29576 #define TARGET_SCHED_ISSUE_RATE ix86_issue_rate
29577 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
29578 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
29579   ia32_multipass_dfa_lookahead
29580
29581 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
29582 #define TARGET_FUNCTION_OK_FOR_SIBCALL ix86_function_ok_for_sibcall
29583
29584 #ifdef HAVE_AS_TLS
29585 #undef TARGET_HAVE_TLS
29586 #define TARGET_HAVE_TLS true
29587 #endif
29588 #undef TARGET_CANNOT_FORCE_CONST_MEM
29589 #define TARGET_CANNOT_FORCE_CONST_MEM ix86_cannot_force_const_mem
29590 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
29591 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P hook_bool_mode_const_rtx_true
29592
29593 #undef TARGET_DELEGITIMIZE_ADDRESS
29594 #define TARGET_DELEGITIMIZE_ADDRESS ix86_delegitimize_address
29595
29596 #undef TARGET_MS_BITFIELD_LAYOUT_P
29597 #define TARGET_MS_BITFIELD_LAYOUT_P ix86_ms_bitfield_layout_p
29598
29599 #if TARGET_MACHO
29600 #undef TARGET_BINDS_LOCAL_P
29601 #define TARGET_BINDS_LOCAL_P darwin_binds_local_p
29602 #endif
29603 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
29604 #undef TARGET_BINDS_LOCAL_P
29605 #define TARGET_BINDS_LOCAL_P i386_pe_binds_local_p
29606 #endif
29607
29608 #undef TARGET_ASM_OUTPUT_MI_THUNK
29609 #define TARGET_ASM_OUTPUT_MI_THUNK x86_output_mi_thunk
29610 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
29611 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK x86_can_output_mi_thunk
29612
29613 #undef TARGET_ASM_FILE_START
29614 #define TARGET_ASM_FILE_START x86_file_start
29615
29616 #undef TARGET_DEFAULT_TARGET_FLAGS
29617 #define TARGET_DEFAULT_TARGET_FLAGS     \
29618   (TARGET_DEFAULT                       \
29619    | TARGET_SUBTARGET_DEFAULT           \
29620    | TARGET_TLS_DIRECT_SEG_REFS_DEFAULT)
29621
29622 #undef TARGET_HANDLE_OPTION
29623 #define TARGET_HANDLE_OPTION ix86_handle_option
29624
29625 #undef TARGET_RTX_COSTS
29626 #define TARGET_RTX_COSTS ix86_rtx_costs
29627 #undef TARGET_ADDRESS_COST
29628 #define TARGET_ADDRESS_COST ix86_address_cost
29629
29630 #undef TARGET_FIXED_CONDITION_CODE_REGS
29631 #define TARGET_FIXED_CONDITION_CODE_REGS ix86_fixed_condition_code_regs
29632 #undef TARGET_CC_MODES_COMPATIBLE
29633 #define TARGET_CC_MODES_COMPATIBLE ix86_cc_modes_compatible
29634
29635 #undef TARGET_MACHINE_DEPENDENT_REORG
29636 #define TARGET_MACHINE_DEPENDENT_REORG ix86_reorg
29637
29638 #undef TARGET_BUILTIN_SETJMP_FRAME_VALUE
29639 #define TARGET_BUILTIN_SETJMP_FRAME_VALUE ix86_builtin_setjmp_frame_value
29640
29641 #undef TARGET_BUILD_BUILTIN_VA_LIST
29642 #define TARGET_BUILD_BUILTIN_VA_LIST ix86_build_builtin_va_list
29643
29644 #undef TARGET_FN_ABI_VA_LIST
29645 #define TARGET_FN_ABI_VA_LIST ix86_fn_abi_va_list
29646
29647 #undef TARGET_CANONICAL_VA_LIST_TYPE
29648 #define TARGET_CANONICAL_VA_LIST_TYPE ix86_canonical_va_list_type
29649
29650 #undef TARGET_EXPAND_BUILTIN_VA_START
29651 #define TARGET_EXPAND_BUILTIN_VA_START ix86_va_start
29652
29653 #undef TARGET_MD_ASM_CLOBBERS
29654 #define TARGET_MD_ASM_CLOBBERS ix86_md_asm_clobbers
29655
29656 #undef TARGET_PROMOTE_PROTOTYPES
29657 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
29658 #undef TARGET_STRUCT_VALUE_RTX
29659 #define TARGET_STRUCT_VALUE_RTX ix86_struct_value_rtx
29660 #undef TARGET_SETUP_INCOMING_VARARGS
29661 #define TARGET_SETUP_INCOMING_VARARGS ix86_setup_incoming_varargs
29662 #undef TARGET_MUST_PASS_IN_STACK
29663 #define TARGET_MUST_PASS_IN_STACK ix86_must_pass_in_stack
29664 #undef TARGET_PASS_BY_REFERENCE
29665 #define TARGET_PASS_BY_REFERENCE ix86_pass_by_reference
29666 #undef TARGET_INTERNAL_ARG_POINTER
29667 #define TARGET_INTERNAL_ARG_POINTER ix86_internal_arg_pointer
29668 #undef TARGET_UPDATE_STACK_BOUNDARY
29669 #define TARGET_UPDATE_STACK_BOUNDARY ix86_update_stack_boundary
29670 #undef TARGET_GET_DRAP_RTX
29671 #define TARGET_GET_DRAP_RTX ix86_get_drap_rtx
29672 #undef TARGET_DWARF_HANDLE_FRAME_UNSPEC
29673 #define TARGET_DWARF_HANDLE_FRAME_UNSPEC ix86_dwarf_handle_frame_unspec
29674 #undef TARGET_STRICT_ARGUMENT_NAMING
29675 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
29676
29677 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
29678 #define TARGET_GIMPLIFY_VA_ARG_EXPR ix86_gimplify_va_arg
29679
29680 #undef TARGET_SCALAR_MODE_SUPPORTED_P
29681 #define TARGET_SCALAR_MODE_SUPPORTED_P ix86_scalar_mode_supported_p
29682
29683 #undef TARGET_VECTOR_MODE_SUPPORTED_P
29684 #define TARGET_VECTOR_MODE_SUPPORTED_P ix86_vector_mode_supported_p
29685
29686 #undef TARGET_C_MODE_FOR_SUFFIX
29687 #define TARGET_C_MODE_FOR_SUFFIX ix86_c_mode_for_suffix
29688
29689 #ifdef HAVE_AS_TLS
29690 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
29691 #define TARGET_ASM_OUTPUT_DWARF_DTPREL i386_output_dwarf_dtprel
29692 #endif
29693
29694 #ifdef SUBTARGET_INSERT_ATTRIBUTES
29695 #undef TARGET_INSERT_ATTRIBUTES
29696 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
29697 #endif
29698
29699 #undef TARGET_MANGLE_TYPE
29700 #define TARGET_MANGLE_TYPE ix86_mangle_type
29701
29702 #undef TARGET_STACK_PROTECT_FAIL
29703 #define TARGET_STACK_PROTECT_FAIL ix86_stack_protect_fail
29704
29705 #undef TARGET_FUNCTION_VALUE
29706 #define TARGET_FUNCTION_VALUE ix86_function_value
29707
29708 #undef TARGET_SECONDARY_RELOAD
29709 #define TARGET_SECONDARY_RELOAD ix86_secondary_reload
29710
29711 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST
29712 #define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST x86_builtin_vectorization_cost
29713
29714 #undef TARGET_SET_CURRENT_FUNCTION
29715 #define TARGET_SET_CURRENT_FUNCTION ix86_set_current_function
29716
29717 #undef TARGET_OPTION_VALID_ATTRIBUTE_P
29718 #define TARGET_OPTION_VALID_ATTRIBUTE_P ix86_valid_target_attribute_p
29719
29720 #undef TARGET_OPTION_SAVE
29721 #define TARGET_OPTION_SAVE ix86_function_specific_save
29722
29723 #undef TARGET_OPTION_RESTORE
29724 #define TARGET_OPTION_RESTORE ix86_function_specific_restore
29725
29726 #undef TARGET_OPTION_PRINT
29727 #define TARGET_OPTION_PRINT ix86_function_specific_print
29728
29729 #undef TARGET_OPTION_CAN_INLINE_P
29730 #define TARGET_OPTION_CAN_INLINE_P ix86_can_inline_p
29731
29732 #undef TARGET_EXPAND_TO_RTL_HOOK
29733 #define TARGET_EXPAND_TO_RTL_HOOK ix86_maybe_switch_abi
29734
29735 struct gcc_target targetm = TARGET_INITIALIZER;
29736 \f
29737 #include "gt-i386.h"